os apiwithdialog better types
This commit is contained in:
parent
5f98a810a9
commit
f6670da3f0
|
@ -52,7 +52,7 @@ watch(name, () => {
|
|||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
name: name.value || null,
|
||||
}, undefined, {
|
||||
'0b3f9f6a-2f4d-4b1f-9fb4-49d3a2fd7191': {
|
||||
'YOUR_NAME_CONTAINS_PROHIBITED_WORDS': {
|
||||
title: i18n.ts.yourNameContainsProhibitedWords,
|
||||
text: i18n.ts.yourNameContainsProhibitedWordsDescription,
|
||||
},
|
||||
|
|
|
@ -32,7 +32,7 @@ import { focusParent } from '@/scripts/focus.js';
|
|||
export const openingWindowsCount = ref(0);
|
||||
|
||||
type CustomErrorDef<T> = {
|
||||
[key in T extends { id: infer C; } ? C extends string ? C : string : string]?: { title?: string; text: string; };
|
||||
[key in T extends { code: infer C; } ? C extends string ? Exclude<C, keyof Misskey.entities.CommonErrorTypes> : string : string]?: { title?: string; text: string; };
|
||||
};
|
||||
|
||||
export function apiWithDialog<
|
||||
|
|
|
@ -207,7 +207,7 @@ function save() {
|
|||
isBot: !!profile.isBot,
|
||||
isCat: !!profile.isCat,
|
||||
}, undefined, {
|
||||
'0b3f9f6a-2f4d-4b1f-9fb4-49d3a2fd7191': {
|
||||
'YOUR_NAME_CONTAINS_PROHIBITED_WORDS': {
|
||||
title: i18n.ts.yourNameContainsProhibitedWords,
|
||||
text: i18n.ts.yourNameContainsProhibitedWordsDescription,
|
||||
},
|
||||
|
|
|
@ -246,7 +246,7 @@ export function getNoteMenu(props: {
|
|||
os.apiWithDialog(pin ? 'i/pin' : 'i/unpin', {
|
||||
noteId: appearNote.id,
|
||||
}, undefined, {
|
||||
'72dab508-c64d-498f-8740-a8eec1ba385a': {
|
||||
'PIN_LIMIT_EXCEEDED': {
|
||||
text: i18n.ts.pinLimitExceeded,
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1422,6 +1422,15 @@ type ClipsUpdateRequest = operations['clips___update']['requestBody']['content']
|
|||
// @public (undocumented)
|
||||
type ClipsUpdateResponse = operations['clips___update']['responses']['200']['content']['application/json'];
|
||||
|
||||
// @public (undocumented)
|
||||
type CommonErrorTypes = {
|
||||
'INVALID_PARAM': IdentifiableError['3d81ceae-475f-4600-b2a8-2bc116157532'];
|
||||
'CREDENTIAL_REQUIRED': IdentifiableError['1384574d-a912-4b81-8601-c7b1c4085df1'];
|
||||
'AUTHENTICATION_FAILED': IdentifiableError['b0a7f5f8-dc2f-4171-b91f-de88ad238e14'];
|
||||
'I_AM_AI': IdentifiableError['60c46cd1-f23a-46b1-bebe-5d2b73951a84'];
|
||||
'INTERNAL_ERROR': IdentifiableError['5d37dbcb-891e-41ca-a3d6-e690c97775ac'];
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
type DateString = string;
|
||||
|
||||
|
@ -1715,6 +1724,7 @@ type EndpointsResponse = operations['endpoints']['responses']['200']['content'][
|
|||
|
||||
declare namespace entities {
|
||||
export {
|
||||
CommonErrorTypes,
|
||||
ID,
|
||||
DateString,
|
||||
PureRenote,
|
||||
|
@ -4998,7 +5008,8 @@ type UsersUpdateMemoRequest = operations['users___update-memo']['requestBody']['
|
|||
|
||||
// Warnings were encountered during analysis:
|
||||
//
|
||||
// src/entities.ts:50:2 - (ae-forgotten-export) The symbol "ModerationLogPayloads" needs to be exported by the entry point index.d.ts
|
||||
// src/autogen/endpointErrors.ts:994:2 - (ae-forgotten-export) The symbol "IdentifiableError" needs to be exported by the entry point index.d.ts
|
||||
// src/entities.ts:51:2 - (ae-forgotten-export) The symbol "ModerationLogPayloads" needs to be exported by the entry point index.d.ts
|
||||
// src/streaming.types.ts:220:4 - (ae-forgotten-export) The symbol "ReversiUpdateKey" needs to be exported by the entry point index.d.ts
|
||||
// src/streaming.types.ts:230:4 - (ae-forgotten-export) The symbol "ReversiUpdateSettings" needs to be exported by the entry point index.d.ts
|
||||
|
||||
|
|
|
@ -9,6 +9,16 @@ const disabledLints = [
|
|||
'@typescript-eslint/no-explicit-any',
|
||||
];
|
||||
|
||||
const commonErrorNames = [
|
||||
'INVALID_PARAM',
|
||||
'CREDENTIAL_REQUIRED',
|
||||
'AUTHENTICATION_FAILED',
|
||||
'I_AM_AI',
|
||||
'INTERNAL_ERROR',
|
||||
];
|
||||
|
||||
const commonErrorTypesName = 'CommonErrorTypes';
|
||||
|
||||
async function generateBaseTypes(
|
||||
openApiDocs: OpenAPIV3_1.Document,
|
||||
openApiJsonPath: string,
|
||||
|
@ -84,6 +94,8 @@ async function generateEndpointErrors(
|
|||
|
||||
const errorWithIdTypes = new Map<string, string>();
|
||||
|
||||
const foundCommonErrorNamesAndErrorId = new Map<string, string>();
|
||||
|
||||
endpointsErrorsOutputLine.push('export type EndpointsErrors = {');
|
||||
|
||||
for (const operation of postPathItems) {
|
||||
|
@ -122,20 +134,33 @@ async function generateEndpointErrors(
|
|||
});
|
||||
|
||||
if (errorTypes.size > 0) {
|
||||
endpointsErrorsOutputLine.push(`\t'${operationId}': {`);
|
||||
const endpointErrorsLine: string[] = [];
|
||||
let hasCommonError = false;
|
||||
for (const [key, value] of errorTypes) {
|
||||
if ('error' in value && value.error != null) {
|
||||
let typeString = JSON.stringify(value.error);
|
||||
typeString = typeString.substring(0, typeString.length - 1) + ', [x: string]: any ' + typeString.substring(typeString.length - 1);
|
||||
if ('id' in value.error && value.error.id != null) {
|
||||
errorWithIdTypes.set(value.error.id, typeString);
|
||||
endpointsErrorsOutputLine.push(`\t\t'${key}': IdentifiableError['${value.error.id}'],`);
|
||||
if (commonErrorNames.includes(key)) {
|
||||
foundCommonErrorNamesAndErrorId.set(key, value.error.id);
|
||||
hasCommonError = true;
|
||||
} else {
|
||||
endpointErrorsLine.push(`\t\t'${key}': IdentifiableError['${value.error.id}'],`);
|
||||
}
|
||||
} else {
|
||||
endpointsErrorsOutputLine.push(`\t\t'${key}': ${typeString},`);
|
||||
endpointErrorsLine.push(`\t\t'${key}': ${typeString},`);
|
||||
}
|
||||
}
|
||||
}
|
||||
endpointsErrorsOutputLine.push('\t},');
|
||||
|
||||
if (endpointErrorsLine.length > 0) {
|
||||
endpointsErrorsOutputLine.push(`\t'${operationId}': {`);
|
||||
endpointsErrorsOutputLine.push(...endpointErrorsLine);
|
||||
endpointsErrorsOutputLine.push(hasCommonError ? `\t} & ${commonErrorTypesName},` : '\t},');
|
||||
} else if (hasCommonError) {
|
||||
endpointsErrorsOutputLine.push(`\t'${operationId}': ${commonErrorTypesName},`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,12 +168,18 @@ async function generateEndpointErrors(
|
|||
endpointsErrorsOutputLine.push('};');
|
||||
endpointsErrorsOutputLine.push('');
|
||||
|
||||
endpointsErrorsOutputLine.push(`export type ${commonErrorTypesName} = {`);
|
||||
for (const [key, value] of foundCommonErrorNamesAndErrorId) {
|
||||
endpointsErrorsOutputLine.push(`\t'${key}': IdentifiableError['${value}'],`);
|
||||
}
|
||||
endpointsErrorsOutputLine.push('};');
|
||||
endpointsErrorsOutputLine.push('');
|
||||
|
||||
endpointsErrorsOutputLine.push('export type IdentifiableError = {');
|
||||
for (const [key, value] of errorWithIdTypes) {
|
||||
endpointsErrorsOutputLine.push(`\t'${key}': ${value},`);
|
||||
}
|
||||
endpointsErrorsOutputLine.push('};');
|
||||
|
||||
await writeFile(endpointErrorsOutputPath, endpointsErrorsOutputLine.join('\n'));
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,6 +13,7 @@ import {
|
|||
import type { AuthenticationResponseJSON, PublicKeyCredentialRequestOptionsJSON } from '@simplewebauthn/types';
|
||||
|
||||
export * from './autogen/entities.js';
|
||||
export { CommonErrorTypes } from './autogen/endpointErrors.js';
|
||||
export * from './autogen/models.js';
|
||||
|
||||
export type ID = string;
|
||||
|
|
Loading…
Reference in New Issue