@twin.org/tools-core 0.0.3-next.2 → 0.0.3-next.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/es/index.js +20 -11
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/ITypeScriptToSchemaContext.js +2 -0
- package/dist/es/models/ITypeScriptToSchemaContext.js.map +1 -0
- package/dist/es/models/ITypeScriptToSchemaDiagnostics.js +4 -0
- package/dist/es/models/ITypeScriptToSchemaDiagnostics.js.map +1 -0
- package/dist/es/models/ITypeScriptToSchemaOptions.js +4 -0
- package/dist/es/models/ITypeScriptToSchemaOptions.js.map +1 -0
- package/dist/es/utils/constants.js +43 -0
- package/dist/es/utils/constants.js.map +1 -0
- package/dist/es/utils/diagnosticReporter.js +32 -0
- package/dist/es/utils/diagnosticReporter.js.map +1 -0
- package/dist/es/utils/disallowedTypeGuard.js +151 -0
- package/dist/es/utils/disallowedTypeGuard.js.map +1 -0
- package/dist/es/utils/enum.js +152 -0
- package/dist/es/utils/enum.js.map +1 -0
- package/dist/es/utils/fileUtils.js +130 -0
- package/dist/es/utils/fileUtils.js.map +1 -0
- package/dist/es/utils/importTypeQuerySchemaResolver.js +328 -0
- package/dist/es/utils/importTypeQuerySchemaResolver.js.map +1 -0
- package/dist/es/utils/indexSignaturePatternResolver.js +94 -0
- package/dist/es/utils/indexSignaturePatternResolver.js.map +1 -0
- package/dist/es/utils/intersectionSchemaMerger.js +85 -0
- package/dist/es/utils/intersectionSchemaMerger.js.map +1 -0
- package/dist/es/utils/jsDoc.js +120 -0
- package/dist/es/utils/jsDoc.js.map +1 -0
- package/dist/es/utils/jsonSchemaBuilder.js +3373 -0
- package/dist/es/utils/jsonSchemaBuilder.js.map +1 -0
- package/dist/es/utils/mappedTypeSchemaResolver.js +231 -0
- package/dist/es/utils/mappedTypeSchemaResolver.js.map +1 -0
- package/dist/es/utils/objectTransformer.js +162 -0
- package/dist/es/utils/objectTransformer.js.map +1 -0
- package/dist/es/utils/regEx.js +128 -0
- package/dist/es/utils/regEx.js.map +1 -0
- package/dist/es/utils/resolver.js +164 -0
- package/dist/es/utils/resolver.js.map +1 -0
- package/dist/es/utils/templateLiteralPatternBuilder.js +94 -0
- package/dist/es/utils/templateLiteralPatternBuilder.js.map +1 -0
- package/dist/es/utils/typeScriptToSchema.js +112 -0
- package/dist/es/utils/typeScriptToSchema.js.map +1 -0
- package/dist/es/utils/utilityTypeSchemaMapper.js +412 -0
- package/dist/es/utils/utilityTypeSchemaMapper.js.map +1 -0
- package/dist/types/index.d.ts +20 -11
- package/dist/types/models/ITypeScriptToSchemaContext.d.ts +64 -0
- package/dist/types/models/ITypeScriptToSchemaDiagnostics.d.ts +31 -0
- package/dist/types/models/ITypeScriptToSchemaOptions.d.ts +22 -0
- package/dist/types/utils/constants.d.ts +13 -0
- package/dist/types/utils/diagnosticReporter.d.ts +17 -0
- package/dist/types/utils/disallowedTypeGuard.d.ts +16 -0
- package/dist/types/utils/enum.d.ts +42 -0
- package/dist/types/utils/fileUtils.d.ts +66 -0
- package/dist/types/utils/importTypeQuerySchemaResolver.d.ts +52 -0
- package/dist/types/utils/indexSignaturePatternResolver.d.ts +21 -0
- package/dist/types/utils/intersectionSchemaMerger.d.ts +16 -0
- package/dist/types/utils/jsDoc.d.ts +46 -0
- package/dist/types/utils/jsonSchemaBuilder.d.ts +747 -0
- package/dist/types/utils/mappedTypeSchemaResolver.d.ts +46 -0
- package/dist/types/utils/objectTransformer.d.ts +33 -0
- package/dist/types/utils/regEx.d.ts +24 -0
- package/dist/types/utils/resolver.d.ts +16 -0
- package/dist/types/utils/templateLiteralPatternBuilder.d.ts +12 -0
- package/dist/types/utils/typeScriptToSchema.d.ts +31 -0
- package/dist/types/utils/utilityTypeSchemaMapper.d.ts +92 -0
- package/docs/changelog.md +176 -1
- package/docs/examples.md +87 -1
- package/docs/reference/classes/Constants.md +29 -0
- package/docs/reference/classes/DiagnosticReporter.md +49 -0
- package/docs/reference/classes/DisallowedTypeGuard.md +35 -0
- package/docs/reference/classes/Enum.md +93 -0
- package/docs/reference/classes/FileUtils.md +237 -0
- package/docs/reference/classes/ImportTypeQuerySchemaResolver.md +87 -0
- package/docs/reference/classes/IndexSignaturePatternResolver.md +69 -0
- package/docs/reference/classes/IntersectionSchemaMerger.md +48 -0
- package/docs/reference/classes/JsDoc.md +141 -0
- package/docs/reference/classes/JsonSchemaBuilder.md +2870 -0
- package/docs/reference/classes/MappedTypeSchemaResolver.md +211 -0
- package/docs/reference/classes/ObjectTransformer.md +119 -0
- package/docs/reference/classes/RegEx.md +99 -0
- package/docs/reference/classes/Resolver.md +41 -0
- package/docs/reference/classes/TemplateLiteralPatternBuilder.md +35 -0
- package/docs/reference/classes/TypeScriptToSchema.md +91 -0
- package/docs/reference/classes/UtilityTypeSchemaMapper.md +341 -0
- package/docs/reference/index.md +20 -14
- package/docs/reference/interfaces/ITypeScriptToSchemaContext.md +113 -0
- package/docs/reference/interfaces/ITypeScriptToSchemaDiagnostics.md +55 -0
- package/docs/reference/interfaces/ITypeScriptToSchemaOptions.md +44 -0
- package/locales/en.json +32 -1
- package/package.json +4 -3
- package/dist/es/models/IJsonSchema.js +0 -2
- package/dist/es/models/IJsonSchema.js.map +0 -1
- package/dist/es/models/IOpenApi.js +0 -2
- package/dist/es/models/IOpenApi.js.map +0 -1
- package/dist/es/models/IOpenApiExample.js +0 -4
- package/dist/es/models/IOpenApiExample.js.map +0 -1
- package/dist/es/models/IOpenApiHeader.js +0 -4
- package/dist/es/models/IOpenApiHeader.js.map +0 -1
- package/dist/es/models/IOpenApiPathMethod.js +0 -2
- package/dist/es/models/IOpenApiPathMethod.js.map +0 -1
- package/dist/es/models/IOpenApiResponse.js +0 -2
- package/dist/es/models/IOpenApiResponse.js.map +0 -1
- package/dist/es/models/IOpenApiSecurityScheme.js +0 -4
- package/dist/es/models/IOpenApiSecurityScheme.js.map +0 -1
- package/dist/es/models/IPackageJson.js +0 -4
- package/dist/es/models/IPackageJson.js.map +0 -1
- package/dist/es/models/jsonTypeName.js +0 -2
- package/dist/es/models/jsonTypeName.js.map +0 -1
- package/dist/es/utils/jsonSchemaHelper.js +0 -258
- package/dist/es/utils/jsonSchemaHelper.js.map +0 -1
- package/dist/es/utils/openApiHelper.js +0 -12
- package/dist/es/utils/openApiHelper.js.map +0 -1
- package/dist/types/models/IJsonSchema.d.ts +0 -5
- package/dist/types/models/IOpenApi.d.ts +0 -54
- package/dist/types/models/IOpenApiExample.d.ts +0 -13
- package/dist/types/models/IOpenApiHeader.d.ts +0 -19
- package/dist/types/models/IOpenApiPathMethod.d.ts +0 -65
- package/dist/types/models/IOpenApiResponse.d.ts +0 -32
- package/dist/types/models/IOpenApiSecurityScheme.d.ts +0 -25
- package/dist/types/models/IPackageJson.d.ts +0 -15
- package/dist/types/models/jsonTypeName.d.ts +0 -5
- package/dist/types/utils/jsonSchemaHelper.d.ts +0 -78
- package/dist/types/utils/openApiHelper.d.ts +0 -9
- package/docs/reference/classes/JsonSchemaHelper.md +0 -233
- package/docs/reference/classes/OpenApiHelper.md +0 -21
- package/docs/reference/interfaces/IOpenApi.md +0 -103
- package/docs/reference/interfaces/IOpenApiExample.md +0 -19
- package/docs/reference/interfaces/IOpenApiHeader.md +0 -31
- package/docs/reference/interfaces/IOpenApiPathMethod.md +0 -119
- package/docs/reference/interfaces/IOpenApiResponse.md +0 -35
- package/docs/reference/interfaces/IOpenApiSecurityScheme.md +0 -43
- package/docs/reference/interfaces/IPackageJson.md +0 -23
- package/docs/reference/type-aliases/IJsonSchema.md +0 -5
- package/docs/reference/type-aliases/JsonTypeName.md +0 -5
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/* eslint-disable jsdoc/require-param, jsdoc/require-returns */
|
|
4
|
+
import { JsonHelper, ObjectHelper } from "@twin.org/core";
|
|
5
|
+
import * as ts from "typescript";
|
|
6
|
+
import { ObjectTransformer } from "./objectTransformer.js";
|
|
7
|
+
/**
|
|
8
|
+
* Static utility-type schema mapping helpers.
|
|
9
|
+
*/
|
|
10
|
+
export class UtilityTypeSchemaMapper {
|
|
11
|
+
/**
|
|
12
|
+
* Map Partial<T> to an object schema with no required properties.
|
|
13
|
+
* @param context The generation context.
|
|
14
|
+
* @param typeNode The Partial type reference.
|
|
15
|
+
* @param resolveUtilityBaseObjectSchema Callback to resolve base object schemas.
|
|
16
|
+
* @returns The mapped schema.
|
|
17
|
+
*/
|
|
18
|
+
static mapPartialUtilityType(context, typeNode, resolveUtilityBaseObjectSchema) {
|
|
19
|
+
const baseTypeNode = typeNode.typeArguments?.[0];
|
|
20
|
+
if (!baseTypeNode) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const objectSchema = resolveUtilityBaseObjectSchema(context, baseTypeNode);
|
|
24
|
+
if (objectSchema) {
|
|
25
|
+
const partialSchema = ObjectTransformer.toInlineUtilityObjectSchema(objectSchema);
|
|
26
|
+
delete partialSchema.required;
|
|
27
|
+
return partialSchema;
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Map Required<T> to an object schema with all properties required.
|
|
33
|
+
* @param context The generation context.
|
|
34
|
+
* @param typeNode The Required type reference.
|
|
35
|
+
* @param resolveUtilityBaseObjectSchema Callback to resolve base object schemas.
|
|
36
|
+
* @returns The mapped schema.
|
|
37
|
+
*/
|
|
38
|
+
static mapRequiredUtilityType(context, typeNode, resolveUtilityBaseObjectSchema) {
|
|
39
|
+
const baseTypeNode = typeNode.typeArguments?.[0];
|
|
40
|
+
if (!baseTypeNode) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const objectSchema = resolveUtilityBaseObjectSchema(context, baseTypeNode);
|
|
44
|
+
if (objectSchema) {
|
|
45
|
+
const requiredSchema = ObjectTransformer.toInlineUtilityObjectSchema(objectSchema);
|
|
46
|
+
if (requiredSchema.properties) {
|
|
47
|
+
requiredSchema.required = Object.keys(requiredSchema.properties);
|
|
48
|
+
}
|
|
49
|
+
return requiredSchema;
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Map Pick<T, K> to an object schema with selected keys preserved.
|
|
55
|
+
*/
|
|
56
|
+
static mapPickUtilityType(context, typeNode, resolveUtilityBaseObjectSchema, extractUtilityTypeKeys) {
|
|
57
|
+
const baseTypeNode = typeNode.typeArguments?.[0];
|
|
58
|
+
const pickedKeys = extractUtilityTypeKeys(context, typeNode.typeArguments?.[1]);
|
|
59
|
+
if (!baseTypeNode || pickedKeys.length === 0) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
const baseSchema = resolveUtilityBaseObjectSchema(context, baseTypeNode);
|
|
63
|
+
if (baseSchema) {
|
|
64
|
+
return ObjectTransformer.pickKeysFromObjectSchema(baseSchema, pickedKeys);
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Map Omit<T, K> to an object schema with selected keys removed.
|
|
70
|
+
*/
|
|
71
|
+
static mapOmitUtilityType(context, typeNode, resolveUtilityBaseObjectSchema, extractUtilityTypeKeys) {
|
|
72
|
+
const baseTypeNode = typeNode.typeArguments?.[0];
|
|
73
|
+
const omittedKeys = extractUtilityTypeKeys(context, typeNode.typeArguments?.[1]);
|
|
74
|
+
if (!baseTypeNode || omittedKeys.length === 0) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
const baseSchema = resolveUtilityBaseObjectSchema(context, baseTypeNode);
|
|
78
|
+
if (baseSchema) {
|
|
79
|
+
return ObjectTransformer.omitKeysFromObjectSchema(baseSchema, omittedKeys);
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Map Exclude<T, U> to a schema that removes U members from T.
|
|
85
|
+
*/
|
|
86
|
+
static mapExcludeUtilityType(context, typeNode, mapTypeNodeToSchema) {
|
|
87
|
+
const sourceTypeNode = typeNode.typeArguments?.[0];
|
|
88
|
+
const excludedTypeNode = typeNode.typeArguments?.[1];
|
|
89
|
+
if (!sourceTypeNode || !excludedTypeNode) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
const sourceTypes = ts.isUnionTypeNode(sourceTypeNode)
|
|
93
|
+
? sourceTypeNode.types
|
|
94
|
+
: [sourceTypeNode];
|
|
95
|
+
const excludedTypes = ts.isUnionTypeNode(excludedTypeNode)
|
|
96
|
+
? excludedTypeNode.types
|
|
97
|
+
: [excludedTypeNode];
|
|
98
|
+
const sourceSchemas = sourceTypes
|
|
99
|
+
.map(sourceType => mapTypeNodeToSchema(context, sourceType))
|
|
100
|
+
.filter((schema) => schema !== undefined);
|
|
101
|
+
const excludedSchemas = excludedTypes
|
|
102
|
+
.map(excludedType => mapTypeNodeToSchema(context, excludedType))
|
|
103
|
+
.filter((schema) => schema !== undefined)
|
|
104
|
+
.map(schema => JsonHelper.canonicalize(schema));
|
|
105
|
+
if (sourceSchemas.length === 0) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
const excludedSchemaKeys = new Set(excludedSchemas);
|
|
109
|
+
const remainingSchemas = sourceSchemas.filter(schema => !excludedSchemaKeys.has(JsonHelper.canonicalize(schema)));
|
|
110
|
+
if (remainingSchemas.length === 0) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
if (remainingSchemas.length === 1) {
|
|
114
|
+
return remainingSchemas[0];
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
anyOf: remainingSchemas
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Map Extract<T, U> to a schema that keeps U members from T.
|
|
122
|
+
*/
|
|
123
|
+
static mapExtractUtilityType(context, typeNode, mapTypeNodeToSchema) {
|
|
124
|
+
const sourceTypeNode = typeNode.typeArguments?.[0];
|
|
125
|
+
const includedTypeNode = typeNode.typeArguments?.[1];
|
|
126
|
+
if (!sourceTypeNode || !includedTypeNode) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
const sourceTypes = ts.isUnionTypeNode(sourceTypeNode)
|
|
130
|
+
? sourceTypeNode.types
|
|
131
|
+
: [sourceTypeNode];
|
|
132
|
+
const includedTypes = ts.isUnionTypeNode(includedTypeNode)
|
|
133
|
+
? includedTypeNode.types
|
|
134
|
+
: [includedTypeNode];
|
|
135
|
+
const sourceSchemas = sourceTypes
|
|
136
|
+
.map(sourceType => mapTypeNodeToSchema(context, sourceType))
|
|
137
|
+
.filter((schema) => schema !== undefined);
|
|
138
|
+
const includedSchemaKeys = new Set(includedTypes
|
|
139
|
+
.map(includedType => mapTypeNodeToSchema(context, includedType))
|
|
140
|
+
.filter((schema) => schema !== undefined)
|
|
141
|
+
.map(schema => JsonHelper.canonicalize(schema)));
|
|
142
|
+
if (sourceSchemas.length === 0 || includedSchemaKeys.size === 0) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
const matchedSchemas = sourceSchemas.filter(schema => includedSchemaKeys.has(JsonHelper.canonicalize(schema)));
|
|
146
|
+
if (matchedSchemas.length === 0) {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
if (matchedSchemas.length === 1) {
|
|
150
|
+
return matchedSchemas[0];
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
anyOf: matchedSchemas
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Map NonNullable<T> by removing null and undefined branches from T.
|
|
158
|
+
*/
|
|
159
|
+
static mapNonNullableUtilityType(context, typeNode, mapTypeNodeToSchema) {
|
|
160
|
+
const sourceTypeNode = typeNode.typeArguments?.[0];
|
|
161
|
+
if (!sourceTypeNode) {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
const sourceTypes = ts.isUnionTypeNode(sourceTypeNode)
|
|
165
|
+
? sourceTypeNode.types
|
|
166
|
+
: [sourceTypeNode];
|
|
167
|
+
const nonNullableTypes = sourceTypes.filter(sourceType => !UtilityTypeSchemaMapper.isNullOrUndefinedTypeNode(sourceType));
|
|
168
|
+
if (nonNullableTypes.length === 0) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
const mappedSchemas = nonNullableTypes
|
|
172
|
+
.map(sourceType => mapTypeNodeToSchema(context, sourceType))
|
|
173
|
+
.filter((schema) => schema !== undefined);
|
|
174
|
+
if (mappedSchemas.length === 0) {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
if (mappedSchemas.length === 1) {
|
|
178
|
+
return mappedSchemas[0];
|
|
179
|
+
}
|
|
180
|
+
const uniqueSchemas = mappedSchemas.filter((schema, index, allSchemas) => {
|
|
181
|
+
const schemaKey = JsonHelper.canonicalize(schema);
|
|
182
|
+
return allSchemas.findIndex(s => JsonHelper.canonicalize(s) === schemaKey) === index;
|
|
183
|
+
});
|
|
184
|
+
if (uniqueSchemas.length === 1) {
|
|
185
|
+
return uniqueSchemas[0];
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
anyOf: uniqueSchemas
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Map Record<K, V> to an object schema with key constraints where possible.
|
|
193
|
+
*/
|
|
194
|
+
static mapRecordUtilityType(context, typeNode, mapTypeNodeToSchema) {
|
|
195
|
+
const keyTypeNode = typeNode.typeArguments?.[0];
|
|
196
|
+
const valueTypeNode = typeNode.typeArguments?.[1];
|
|
197
|
+
if (!keyTypeNode || !valueTypeNode) {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
const valueSchema = mapTypeNodeToSchema(context, valueTypeNode);
|
|
201
|
+
if (!valueSchema) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
const recordLiteralKeys = UtilityTypeSchemaMapper.extractRecordLiteralKeys(keyTypeNode);
|
|
205
|
+
if (recordLiteralKeys.length > 0) {
|
|
206
|
+
const properties = {};
|
|
207
|
+
for (const key of recordLiteralKeys) {
|
|
208
|
+
properties[key] = ObjectHelper.clone(valueSchema);
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
type: "object",
|
|
212
|
+
properties,
|
|
213
|
+
required: recordLiteralKeys
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
type: "object",
|
|
218
|
+
additionalProperties: valueSchema
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Map JsonLdObject utility types using key-removal and optional key-addition rules.
|
|
223
|
+
*/
|
|
224
|
+
static mapJsonLdObjectUtilityType(context, typeNode, options, resolveUtilityBaseObjectSchema, mapTypeNodeToSchema) {
|
|
225
|
+
const baseTypeNode = typeNode.typeArguments?.[0];
|
|
226
|
+
if (!baseTypeNode) {
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
const baseSchema = resolveUtilityBaseObjectSchema(context, baseTypeNode);
|
|
230
|
+
if (!baseSchema) {
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
const mappedSchema = ObjectTransformer.omitKeysFromObjectSchema(baseSchema, options.keysToRemove);
|
|
234
|
+
if (!options.keyToAdd) {
|
|
235
|
+
return mappedSchema;
|
|
236
|
+
}
|
|
237
|
+
const valueTypeNode = typeNode.typeArguments?.[1];
|
|
238
|
+
const valueSchema = valueTypeNode
|
|
239
|
+
? mapTypeNodeToSchema(context, valueTypeNode)
|
|
240
|
+
: UtilityTypeSchemaMapper.mapJsonLdObjectDefaultSchemaByKey(baseSchema, options.keyToAdd);
|
|
241
|
+
if (!valueSchema) {
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
mappedSchema.type = "object";
|
|
245
|
+
mappedSchema.properties ??= {};
|
|
246
|
+
mappedSchema.properties[options.keyToAdd] = valueSchema;
|
|
247
|
+
if (options.isAddedKeyRequired) {
|
|
248
|
+
const requiredKeys = new Set(mappedSchema.required ?? []);
|
|
249
|
+
requiredKeys.add(options.keyToAdd);
|
|
250
|
+
mappedSchema.required = [...requiredKeys];
|
|
251
|
+
}
|
|
252
|
+
return mappedSchema;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Map ObjectOrArray<T> to a schema accepting T or T[].
|
|
256
|
+
*/
|
|
257
|
+
static mapObjectOrArrayUtilityType(context, typeNode, mapTypeNodeToSchema) {
|
|
258
|
+
const baseTypeNode = typeNode.typeArguments?.[0];
|
|
259
|
+
if (!baseTypeNode) {
|
|
260
|
+
return undefined;
|
|
261
|
+
}
|
|
262
|
+
const itemSchema = mapTypeNodeToSchema(context, baseTypeNode);
|
|
263
|
+
if (!itemSchema) {
|
|
264
|
+
return undefined;
|
|
265
|
+
}
|
|
266
|
+
const scalarSchemas = Array.isArray(itemSchema.anyOf) && Object.keys(itemSchema).length === 1
|
|
267
|
+
? itemSchema.anyOf
|
|
268
|
+
: [itemSchema];
|
|
269
|
+
return {
|
|
270
|
+
anyOf: [...scalarSchemas, { type: "array", items: itemSchema }]
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Map SingleOccurrenceArray<T, U> to a non-empty array containing exactly one U.
|
|
275
|
+
*/
|
|
276
|
+
static mapSingleOccurrenceArrayUtilityType(context, typeNode, mapTypeNodeToSchema) {
|
|
277
|
+
const primaryTypeNode = typeNode.typeArguments?.[0];
|
|
278
|
+
if (!primaryTypeNode) {
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
const primarySchema = mapTypeNodeToSchema(context, primaryTypeNode);
|
|
282
|
+
if (!primarySchema) {
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
const singleOccurrenceTypeNode = typeNode.typeArguments?.[1];
|
|
286
|
+
if (!singleOccurrenceTypeNode) {
|
|
287
|
+
return {
|
|
288
|
+
type: "array",
|
|
289
|
+
items: primarySchema,
|
|
290
|
+
minItems: 1
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
const singleOccurrenceSchema = mapTypeNodeToSchema(context, singleOccurrenceTypeNode);
|
|
294
|
+
if (!singleOccurrenceSchema) {
|
|
295
|
+
return {
|
|
296
|
+
type: "array",
|
|
297
|
+
items: primarySchema,
|
|
298
|
+
minItems: 1
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
if (JsonHelper.canonicalize(primarySchema) === JsonHelper.canonicalize(singleOccurrenceSchema)) {
|
|
302
|
+
return {
|
|
303
|
+
type: "array",
|
|
304
|
+
items: primarySchema,
|
|
305
|
+
minItems: 1
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
const itemSchema = {
|
|
309
|
+
anyOf: [primarySchema, singleOccurrenceSchema]
|
|
310
|
+
};
|
|
311
|
+
return {
|
|
312
|
+
type: "array",
|
|
313
|
+
items: itemSchema,
|
|
314
|
+
contains: singleOccurrenceSchema,
|
|
315
|
+
minContains: 1,
|
|
316
|
+
maxContains: 1,
|
|
317
|
+
minItems: 1
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Determine whether a type node represents null or undefined.
|
|
322
|
+
*/
|
|
323
|
+
static isNullOrUndefinedTypeNode(typeNode) {
|
|
324
|
+
if (typeNode.kind === ts.SyntaxKind.NullKeyword ||
|
|
325
|
+
typeNode.kind === ts.SyntaxKind.UndefinedKeyword) {
|
|
326
|
+
return true;
|
|
327
|
+
}
|
|
328
|
+
if (ts.isLiteralTypeNode(typeNode)) {
|
|
329
|
+
return typeNode.literal.kind === ts.SyntaxKind.NullKeyword;
|
|
330
|
+
}
|
|
331
|
+
if (ts.isTypeReferenceNode(typeNode) && ts.isIdentifier(typeNode.typeName)) {
|
|
332
|
+
return typeNode.typeName.text === "undefined";
|
|
333
|
+
}
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Extract literal keys from a Record key type argument.
|
|
338
|
+
*/
|
|
339
|
+
static extractRecordLiteralKeys(keyTypeNode) {
|
|
340
|
+
if (ts.isLiteralTypeNode(keyTypeNode) && ts.isStringLiteral(keyTypeNode.literal)) {
|
|
341
|
+
return [keyTypeNode.literal.text];
|
|
342
|
+
}
|
|
343
|
+
if (ts.isUnionTypeNode(keyTypeNode)) {
|
|
344
|
+
const keys = keyTypeNode.types
|
|
345
|
+
.filter(type => ts.isLiteralTypeNode(type) && ts.isStringLiteral(type.literal))
|
|
346
|
+
.map(type => type.literal)
|
|
347
|
+
.map(literal => literal.text);
|
|
348
|
+
return keys.length === keyTypeNode.types.length ? keys : [];
|
|
349
|
+
}
|
|
350
|
+
return [];
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Resolve a default schema for JsonLdObject utility key additions when the type argument is omitted.
|
|
354
|
+
*/
|
|
355
|
+
static mapJsonLdObjectDefaultSchemaByKey(baseSchema, keyToAdd) {
|
|
356
|
+
if (keyToAdd === "id" || keyToAdd === "@id") {
|
|
357
|
+
return UtilityTypeSchemaMapper.mapJsonLdObjectWithIdDefaultIdSchema(baseSchema);
|
|
358
|
+
}
|
|
359
|
+
if (keyToAdd === "@context") {
|
|
360
|
+
return UtilityTypeSchemaMapper.mapJsonLdObjectWithContextDefaultContextSchema(baseSchema);
|
|
361
|
+
}
|
|
362
|
+
return UtilityTypeSchemaMapper.mapJsonLdObjectWithTypeDefaultTypeSchema(baseSchema);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Resolve default id schema for JsonLdObjectWithId when Id type argument is omitted.
|
|
366
|
+
*/
|
|
367
|
+
static mapJsonLdObjectWithIdDefaultIdSchema(baseSchema) {
|
|
368
|
+
return UtilityTypeSchemaMapper.mapJsonLdObjectDefaultEitherSchema(baseSchema, "id", "@id", {
|
|
369
|
+
type: "string"
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Resolve default type schema for JsonLdObjectWithType when Type argument is omitted.
|
|
374
|
+
*/
|
|
375
|
+
static mapJsonLdObjectWithTypeDefaultTypeSchema(baseSchema) {
|
|
376
|
+
return UtilityTypeSchemaMapper.mapJsonLdObjectDefaultEitherSchema(baseSchema, "type", "@type", {
|
|
377
|
+
anyOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Resolve default context schema for JsonLdObjectWithContext when Context argument is omitted.
|
|
382
|
+
*/
|
|
383
|
+
static mapJsonLdObjectWithContextDefaultContextSchema(baseSchema) {
|
|
384
|
+
return UtilityTypeSchemaMapper.mapJsonLdObjectDefaultEitherSchema(baseSchema, "@context", "@context", {
|
|
385
|
+
type: "array",
|
|
386
|
+
items: { type: "string" }
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Resolve default schema from either of two source keys, with fallback when both are absent.
|
|
391
|
+
*/
|
|
392
|
+
static mapJsonLdObjectDefaultEitherSchema(baseSchema, firstKey, secondKey, fallbackSchema) {
|
|
393
|
+
const firstSchema = ObjectTransformer.resolvePropertySchemaFromObjectSchema(baseSchema, firstKey);
|
|
394
|
+
const secondSchema = ObjectTransformer.resolvePropertySchemaFromObjectSchema(baseSchema, secondKey);
|
|
395
|
+
if (firstSchema && secondSchema) {
|
|
396
|
+
if (JsonHelper.canonicalize(firstSchema) === JsonHelper.canonicalize(secondSchema)) {
|
|
397
|
+
return firstSchema;
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
anyOf: [firstSchema, secondSchema]
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
if (firstSchema) {
|
|
404
|
+
return firstSchema;
|
|
405
|
+
}
|
|
406
|
+
if (secondSchema) {
|
|
407
|
+
return secondSchema;
|
|
408
|
+
}
|
|
409
|
+
return fallbackSchema;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
//# sourceMappingURL=utilityTypeSchemaMapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilityTypeSchemaMapper.js","sourceRoot":"","sources":["../../../src/utils/utilityTypeSchemaMapper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,+DAA+D;AAC/D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D;;GAEG;AACH,MAAM,OAAO,uBAAuB;IACnC;;;;;;OAMG;IACI,MAAM,CAAC,qBAAqB,CAClC,OAAmC,EACnC,QAA8B,EAC9B,8BAG4B;QAE5B,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,CAAC,YAAY,EAAE,CAAC;YACnB,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,MAAM,YAAY,GAAG,8BAA8B,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAC3E,IAAI,YAAY,EAAE,CAAC;YAClB,MAAM,aAAa,GAAG,iBAAiB,CAAC,2BAA2B,CAAC,YAAY,CAAC,CAAC;YAClF,OAAO,aAAa,CAAC,QAAQ,CAAC;YAC9B,OAAO,aAAa,CAAC;QACtB,CAAC;QAED,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,sBAAsB,CACnC,OAAmC,EACnC,QAA8B,EAC9B,8BAG4B;QAE5B,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,CAAC,YAAY,EAAE,CAAC;YACnB,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,MAAM,YAAY,GAAG,8BAA8B,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAC3E,IAA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C;YACpB,CAAC;YAED,OAAO;gBACN,KAAK,EAAE,CAAC,WAAW,EAAE,YAAY,CAAC;aAClC,CAAC;QACH,CAAC;QAED,IAAI,WAAW,EAAE,CAAC;YACjB,OAAO,WAAW,CAAC;QACpB,CAAC;QAED,IAAI,YAAY,EAAE,CAAC;YAClB,OAAO,YAAY,CAAC;QACrB,CAAC;QAED,OAAO,cAAc,CAAC;IACvB,CAAC;CACD","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/* eslint-disable jsdoc/require-param, jsdoc/require-returns */\nimport { JsonHelper, ObjectHelper } from \"@twin.org/core\";\nimport type { IJsonSchema } from \"@twin.org/tools-models\";\nimport * as ts from \"typescript\";\nimport { ObjectTransformer } from \"./objectTransformer.js\";\nimport type { ITypeScriptToSchemaContext } from \"../models/ITypeScriptToSchemaContext.js\";\n\n/**\n * Static utility-type schema mapping helpers.\n */\nexport class UtilityTypeSchemaMapper {\n\t/**\n\t * Map Partial<T> to an object schema with no required properties.\n\t * @param context The generation context.\n\t * @param typeNode The Partial type reference.\n\t * @param resolveUtilityBaseObjectSchema Callback to resolve base object schemas.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapPartialUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode,\n\t\tresolveUtilityBaseObjectSchema: (\n\t\t\tcontext: ITypeScriptToSchemaContext,\n\t\t\tbaseTypeNode: ts.TypeNode\n\t\t) => IJsonSchema | undefined\n\t): IJsonSchema | undefined {\n\t\tconst baseTypeNode = typeNode.typeArguments?.[0];\n\t\tif (!baseTypeNode) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst objectSchema = resolveUtilityBaseObjectSchema(context, baseTypeNode);\n\t\tif (objectSchema) {\n\t\t\tconst partialSchema = ObjectTransformer.toInlineUtilityObjectSchema(objectSchema);\n\t\t\tdelete partialSchema.required;\n\t\t\treturn partialSchema;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Map Required<T> to an object schema with all properties required.\n\t * @param context The generation context.\n\t * @param typeNode The Required type reference.\n\t * @param resolveUtilityBaseObjectSchema Callback to resolve base object schemas.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapRequiredUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode,\n\t\tresolveUtilityBaseObjectSchema: (\n\t\t\tcontext: ITypeScriptToSchemaContext,\n\t\t\tbaseTypeNode: ts.TypeNode\n\t\t) => IJsonSchema | undefined\n\t): IJsonSchema | undefined {\n\t\tconst baseTypeNode = typeNode.typeArguments?.[0];\n\t\tif (!baseTypeNode) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst objectSchema = resolveUtilityBaseObjectSchema(context, baseTypeNode);\n\t\tif (objectSchema) {\n\t\t\tconst requiredSchema = ObjectTransformer.toInlineUtilityObjectSchema(objectSchema);\n\t\t\tif (requiredSchema.properties) {\n\t\t\t\trequiredSchema.required = Object.keys(requiredSchema.properties);\n\t\t\t}\n\t\t\treturn requiredSchema;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Map Pick<T, K> to an object schema with selected keys preserved.\n\t */\n\tpublic static mapPickUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode,\n\t\tresolveUtilityBaseObjectSchema: (\n\t\t\tcontext: ITypeScriptToSchemaContext,\n\t\t\tbaseTypeNode: ts.TypeNode\n\t\t) => IJsonSchema | undefined,\n\t\textractUtilityTypeKeys: (\n\t\t\tcontext: ITypeScriptToSchemaContext,\n\t\t\tkeysNode: ts.TypeNode | undefined\n\t\t) => string[]\n\t): IJsonSchema | undefined {\n\t\tconst baseTypeNode = typeNode.typeArguments?.[0];\n\t\tconst pickedKeys = extractUtilityTypeKeys(context, typeNode.typeArguments?.[1]);\n\t\tif (!baseTypeNode || pickedKeys.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst baseSchema = resolveUtilityBaseObjectSchema(context, baseTypeNode);\n\t\tif (baseSchema) {\n\t\t\treturn ObjectTransformer.pickKeysFromObjectSchema(baseSchema, pickedKeys);\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Map Omit<T, K> to an object schema with selected keys removed.\n\t */\n\tpublic static mapOmitUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode,\n\t\tresolveUtilityBaseObjectSchema: (\n\t\t\tcontext: ITypeScriptToSchemaContext,\n\t\t\tbaseTypeNode: ts.TypeNode\n\t\t) => IJsonSchema | undefined,\n\t\textractUtilityTypeKeys: (\n\t\t\tcontext: ITypeScriptToSchemaContext,\n\t\t\tkeysNode: ts.TypeNode | undefined\n\t\t) => string[]\n\t): IJsonSchema | undefined {\n\t\tconst baseTypeNode = typeNode.typeArguments?.[0];\n\t\tconst omittedKeys = extractUtilityTypeKeys(context, typeNode.typeArguments?.[1]);\n\t\tif (!baseTypeNode || omittedKeys.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst baseSchema = resolveUtilityBaseObjectSchema(context, baseTypeNode);\n\t\tif (baseSchema) {\n\t\t\treturn ObjectTransformer.omitKeysFromObjectSchema(baseSchema, omittedKeys);\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Map Exclude<T, U> to a schema that removes U members from T.\n\t */\n\tpublic static mapExcludeUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode,\n\t\tmapTypeNodeToSchema: (\n\t\t\tcontext: ITypeScriptToSchemaContext,\n\t\t\ttypeNode: ts.TypeNode\n\t\t) => IJsonSchema | undefined\n\t): IJsonSchema | undefined {\n\t\tconst sourceTypeNode = typeNode.typeArguments?.[0];\n\t\tconst excludedTypeNode = typeNode.typeArguments?.[1];\n\t\tif (!sourceTypeNode || !excludedTypeNode) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst sourceTypes = ts.isUnionTypeNode(sourceTypeNode)\n\t\t\t? sourceTypeNode.types\n\t\t\t: [sourceTypeNode];\n\t\tconst excludedTypes = ts.isUnionTypeNode(excludedTypeNode)\n\t\t\t? excludedTypeNode.types\n\t\t\t: [excludedTypeNode];\n\n\t\tconst sourceSchemas = sourceTypes\n\t\t\t.map(sourceType => mapTypeNodeToSchema(context, sourceType))\n\t\t\t.filter((schema): schema is IJsonSchema => schema !== undefined);\n\t\tconst excludedSchemas = excludedTypes\n\t\t\t.map(excludedType => mapTypeNodeToSchema(context, excludedType))\n\t\t\t.filter((schema): schema is IJsonSchema => schema !== undefined)\n\t\t\t.map(schema => JsonHelper.canonicalize(schema));\n\n\t\tif (sourceSchemas.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst excludedSchemaKeys = new Set(excludedSchemas);\n\t\tconst remainingSchemas = sourceSchemas.filter(\n\t\t\tschema => !excludedSchemaKeys.has(JsonHelper.canonicalize(schema))\n\t\t);\n\n\t\tif (remainingSchemas.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (remainingSchemas.length === 1) {\n\t\t\treturn remainingSchemas[0];\n\t\t}\n\n\t\treturn {\n\t\t\tanyOf: remainingSchemas\n\t\t};\n\t}\n\n\t/**\n\t * Map Extract<T, U> to a schema that keeps U members from T.\n\t */\n\tpublic static mapExtractUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode,\n\t\tmapTypeNodeToSchema: (\n\t\t\tcontext: ITypeScriptToSchemaContext,\n\t\t\ttypeNode: ts.TypeNode\n\t\t) => IJsonSchema | undefined\n\t): IJsonSchema | undefined {\n\t\tconst sourceTypeNode = typeNode.typeArguments?.[0];\n\t\tconst includedTypeNode = typeNode.typeArguments?.[1];\n\t\tif (!sourceTypeNode || !includedTypeNode) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst sourceTypes = ts.isUnionTypeNode(sourceTypeNode)\n\t\t\t? sourceTypeNode.types\n\t\t\t: [sourceTypeNode];\n\t\tconst includedTypes = ts.isUnionTypeNode(includedTypeNode)\n\t\t\t? includedTypeNode.types\n\t\t\t: [includedTypeNode];\n\n\t\tconst sourceSchemas = sourceTypes\n\t\t\t.map(sourceType => mapTypeNodeToSchema(context, sourceType))\n\t\t\t.filter((schema): schema is IJsonSchema => schema !== undefined);\n\t\tconst includedSchemaKeys = new Set(\n\t\t\tincludedTypes\n\t\t\t\t.map(includedType => mapTypeNodeToSchema(context, includedType))\n\t\t\t\t.filter((schema): schema is IJsonSchema => schema !== undefined)\n\t\t\t\t.map(schema => JsonHelper.canonicalize(schema))\n\t\t);\n\n\t\tif (sourceSchemas.length === 0 || includedSchemaKeys.size === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst matchedSchemas = sourceSchemas.filter(schema =>\n\t\t\tincludedSchemaKeys.has(JsonHelper.canonicalize(schema))\n\t\t);\n\n\t\tif (matchedSchemas.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (matchedSchemas.length === 1) {\n\t\t\treturn matchedSchemas[0];\n\t\t}\n\n\t\treturn {\n\t\t\tanyOf: matchedSchemas\n\t\t};\n\t}\n\n\t/**\n\t * Map NonNullable<T> by removing null and undefined branches from T.\n\t */\n\tpublic static mapNonNullableUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode,\n\t\tmapTypeNodeToSchema: (\n\t\t\tcontext: ITypeScriptToSchemaContext,\n\t\t\ttypeNode: ts.TypeNode\n\t\t) => IJsonSchema | undefined\n\t): IJsonSchema | undefined {\n\t\tconst sourceTypeNode = typeNode.typeArguments?.[0];\n\t\tif (!sourceTypeNode) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst sourceTypes = ts.isUnionTypeNode(sourceTypeNode)\n\t\t\t? sourceTypeNode.types\n\t\t\t: [sourceTypeNode];\n\t\tconst nonNullableTypes = sourceTypes.filter(\n\t\t\tsourceType => !UtilityTypeSchemaMapper.isNullOrUndefinedTypeNode(sourceType)\n\t\t);\n\n\t\tif (nonNullableTypes.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst mappedSchemas = nonNullableTypes\n\t\t\t.map(sourceType => mapTypeNodeToSchema(context, sourceType))\n\t\t\t.filter((schema): schema is IJsonSchema => schema !== undefined);\n\n\t\tif (mappedSchemas.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (mappedSchemas.length === 1) {\n\t\t\treturn mappedSchemas[0];\n\t\t}\n\n\t\tconst uniqueSchemas = mappedSchemas.filter((schema, index, allSchemas) => {\n\t\t\tconst schemaKey = JsonHelper.canonicalize(schema);\n\t\t\treturn allSchemas.findIndex(s => JsonHelper.canonicalize(s) === schemaKey) === index;\n\t\t});\n\n\t\tif (uniqueSchemas.length === 1) {\n\t\t\treturn uniqueSchemas[0];\n\t\t}\n\n\t\treturn {\n\t\t\tanyOf: uniqueSchemas\n\t\t};\n\t}\n\n\t/**\n\t * Map Record<K, V> to an object schema with key constraints where possible.\n\t */\n\tpublic static mapRecordUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode,\n\t\tmapTypeNodeToSchema: (\n\t\t\tcontext: ITypeScriptToSchemaContext,\n\t\t\ttypeNode: ts.TypeNode\n\t\t) => IJsonSchema | undefined\n\t): IJsonSchema | undefined {\n\t\tconst keyTypeNode = typeNode.typeArguments?.[0];\n\t\tconst valueTypeNode = typeNode.typeArguments?.[1];\n\t\tif (!keyTypeNode || !valueTypeNode) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst valueSchema = mapTypeNodeToSchema(context, valueTypeNode);\n\t\tif (!valueSchema) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst recordLiteralKeys = UtilityTypeSchemaMapper.extractRecordLiteralKeys(keyTypeNode);\n\t\tif (recordLiteralKeys.length > 0) {\n\t\t\tconst properties: { [key: string]: IJsonSchema } = {};\n\t\t\tfor (const key of recordLiteralKeys) {\n\t\t\t\tproperties[key] = ObjectHelper.clone(valueSchema);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\ttype: \"object\",\n\t\t\t\tproperties,\n\t\t\t\trequired: recordLiteralKeys\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\ttype: \"object\",\n\t\t\tadditionalProperties: valueSchema\n\t\t};\n\t}\n\n\t/**\n\t * Map JsonLdObject utility types using key-removal and optional key-addition rules.\n\t */\n\tpublic static mapJsonLdObjectUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode,\n\t\toptions: {\n\t\t\tkeysToRemove: string[];\n\t\t\tkeyToAdd?: \"id\" | \"@id\" | \"type\" | \"@type\" | \"@context\";\n\t\t\tisAddedKeyRequired?: boolean;\n\t\t},\n\t\tresolveUtilityBaseObjectSchema: (\n\t\t\tcontext: ITypeScriptToSchemaContext,\n\t\t\tbaseTypeNode: ts.TypeNode\n\t\t) => IJsonSchema | undefined,\n\t\tmapTypeNodeToSchema: (\n\t\t\tcontext: ITypeScriptToSchemaContext,\n\t\t\ttypeNode: ts.TypeNode\n\t\t) => IJsonSchema | undefined\n\t): IJsonSchema | undefined {\n\t\tconst baseTypeNode = typeNode.typeArguments?.[0];\n\t\tif (!baseTypeNode) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst baseSchema = resolveUtilityBaseObjectSchema(context, baseTypeNode);\n\t\tif (!baseSchema) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst mappedSchema = ObjectTransformer.omitKeysFromObjectSchema(\n\t\t\tbaseSchema,\n\t\t\toptions.keysToRemove\n\t\t);\n\t\tif (!options.keyToAdd) {\n\t\t\treturn mappedSchema;\n\t\t}\n\n\t\tconst valueTypeNode = typeNode.typeArguments?.[1];\n\t\tconst valueSchema = valueTypeNode\n\t\t\t? mapTypeNodeToSchema(context, valueTypeNode)\n\t\t\t: UtilityTypeSchemaMapper.mapJsonLdObjectDefaultSchemaByKey(baseSchema, options.keyToAdd);\n\t\tif (!valueSchema) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tmappedSchema.type = \"object\";\n\t\tmappedSchema.properties ??= {};\n\t\tmappedSchema.properties[options.keyToAdd] = valueSchema;\n\n\t\tif (options.isAddedKeyRequired) {\n\t\t\tconst requiredKeys = new Set(mappedSchema.required ?? []);\n\t\t\trequiredKeys.add(options.keyToAdd);\n\t\t\tmappedSchema.required = [...requiredKeys];\n\t\t}\n\n\t\treturn mappedSchema;\n\t}\n\n\t/**\n\t * Map ObjectOrArray<T> to a schema accepting T or T[].\n\t */\n\tpublic static mapObjectOrArrayUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode,\n\t\tmapTypeNodeToSchema: (\n\t\t\tcontext: ITypeScriptToSchemaContext,\n\t\t\ttypeNode: ts.TypeNode\n\t\t) => IJsonSchema | undefined\n\t): IJsonSchema | undefined {\n\t\tconst baseTypeNode = typeNode.typeArguments?.[0];\n\t\tif (!baseTypeNode) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst itemSchema = mapTypeNodeToSchema(context, baseTypeNode);\n\t\tif (!itemSchema) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst scalarSchemas =\n\t\t\tArray.isArray(itemSchema.anyOf) && Object.keys(itemSchema).length === 1\n\t\t\t\t? itemSchema.anyOf\n\t\t\t\t: [itemSchema];\n\n\t\treturn {\n\t\t\tanyOf: [...scalarSchemas, { type: \"array\", items: itemSchema }]\n\t\t};\n\t}\n\n\t/**\n\t * Map SingleOccurrenceArray<T, U> to a non-empty array containing exactly one U.\n\t */\n\tpublic static mapSingleOccurrenceArrayUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode,\n\t\tmapTypeNodeToSchema: (\n\t\t\tcontext: ITypeScriptToSchemaContext,\n\t\t\ttypeNode: ts.TypeNode\n\t\t) => IJsonSchema | undefined\n\t): IJsonSchema | undefined {\n\t\tconst primaryTypeNode = typeNode.typeArguments?.[0];\n\t\tif (!primaryTypeNode) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst primarySchema = mapTypeNodeToSchema(context, primaryTypeNode);\n\t\tif (!primarySchema) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst singleOccurrenceTypeNode = typeNode.typeArguments?.[1];\n\t\tif (!singleOccurrenceTypeNode) {\n\t\t\treturn {\n\t\t\t\ttype: \"array\",\n\t\t\t\titems: primarySchema,\n\t\t\t\tminItems: 1\n\t\t\t};\n\t\t}\n\n\t\tconst singleOccurrenceSchema = mapTypeNodeToSchema(context, singleOccurrenceTypeNode);\n\t\tif (!singleOccurrenceSchema) {\n\t\t\treturn {\n\t\t\t\ttype: \"array\",\n\t\t\t\titems: primarySchema,\n\t\t\t\tminItems: 1\n\t\t\t};\n\t\t}\n\n\t\tif (\n\t\t\tJsonHelper.canonicalize(primarySchema) === JsonHelper.canonicalize(singleOccurrenceSchema)\n\t\t) {\n\t\t\treturn {\n\t\t\t\ttype: \"array\",\n\t\t\t\titems: primarySchema,\n\t\t\t\tminItems: 1\n\t\t\t};\n\t\t}\n\n\t\tconst itemSchema: IJsonSchema = {\n\t\t\tanyOf: [primarySchema, singleOccurrenceSchema]\n\t\t};\n\n\t\treturn {\n\t\t\ttype: \"array\",\n\t\t\titems: itemSchema,\n\t\t\tcontains: singleOccurrenceSchema,\n\t\t\tminContains: 1,\n\t\t\tmaxContains: 1,\n\t\t\tminItems: 1\n\t\t};\n\t}\n\n\t/**\n\t * Determine whether a type node represents null or undefined.\n\t */\n\tprivate static isNullOrUndefinedTypeNode(typeNode: ts.TypeNode): boolean {\n\t\tif (\n\t\t\ttypeNode.kind === ts.SyntaxKind.NullKeyword ||\n\t\t\ttypeNode.kind === ts.SyntaxKind.UndefinedKeyword\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (ts.isLiteralTypeNode(typeNode)) {\n\t\t\treturn typeNode.literal.kind === ts.SyntaxKind.NullKeyword;\n\t\t}\n\n\t\tif (ts.isTypeReferenceNode(typeNode) && ts.isIdentifier(typeNode.typeName)) {\n\t\t\treturn typeNode.typeName.text === \"undefined\";\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Extract literal keys from a Record key type argument.\n\t */\n\tprivate static extractRecordLiteralKeys(keyTypeNode: ts.TypeNode): string[] {\n\t\tif (ts.isLiteralTypeNode(keyTypeNode) && ts.isStringLiteral(keyTypeNode.literal)) {\n\t\t\treturn [keyTypeNode.literal.text];\n\t\t}\n\n\t\tif (ts.isUnionTypeNode(keyTypeNode)) {\n\t\t\tconst keys = keyTypeNode.types\n\t\t\t\t.filter(type => ts.isLiteralTypeNode(type) && ts.isStringLiteral(type.literal))\n\t\t\t\t.map(type => (type as ts.LiteralTypeNode).literal as ts.StringLiteral)\n\t\t\t\t.map(literal => literal.text);\n\t\t\treturn keys.length === keyTypeNode.types.length ? keys : [];\n\t\t}\n\n\t\treturn [];\n\t}\n\n\t/**\n\t * Resolve a default schema for JsonLdObject utility key additions when the type argument is omitted.\n\t */\n\tprivate static mapJsonLdObjectDefaultSchemaByKey(\n\t\tbaseSchema: IJsonSchema,\n\t\tkeyToAdd: \"id\" | \"@id\" | \"type\" | \"@type\" | \"@context\"\n\t): IJsonSchema {\n\t\tif (keyToAdd === \"id\" || keyToAdd === \"@id\") {\n\t\t\treturn UtilityTypeSchemaMapper.mapJsonLdObjectWithIdDefaultIdSchema(baseSchema);\n\t\t}\n\n\t\tif (keyToAdd === \"@context\") {\n\t\t\treturn UtilityTypeSchemaMapper.mapJsonLdObjectWithContextDefaultContextSchema(baseSchema);\n\t\t}\n\n\t\treturn UtilityTypeSchemaMapper.mapJsonLdObjectWithTypeDefaultTypeSchema(baseSchema);\n\t}\n\n\t/**\n\t * Resolve default id schema for JsonLdObjectWithId when Id type argument is omitted.\n\t */\n\tprivate static mapJsonLdObjectWithIdDefaultIdSchema(baseSchema: IJsonSchema): IJsonSchema {\n\t\treturn UtilityTypeSchemaMapper.mapJsonLdObjectDefaultEitherSchema(baseSchema, \"id\", \"@id\", {\n\t\t\ttype: \"string\"\n\t\t});\n\t}\n\n\t/**\n\t * Resolve default type schema for JsonLdObjectWithType when Type argument is omitted.\n\t */\n\tprivate static mapJsonLdObjectWithTypeDefaultTypeSchema(baseSchema: IJsonSchema): IJsonSchema {\n\t\treturn UtilityTypeSchemaMapper.mapJsonLdObjectDefaultEitherSchema(baseSchema, \"type\", \"@type\", {\n\t\t\tanyOf: [{ type: \"string\" }, { type: \"array\", items: { type: \"string\" } }]\n\t\t});\n\t}\n\n\t/**\n\t * Resolve default context schema for JsonLdObjectWithContext when Context argument is omitted.\n\t */\n\tprivate static mapJsonLdObjectWithContextDefaultContextSchema(\n\t\tbaseSchema: IJsonSchema\n\t): IJsonSchema {\n\t\treturn UtilityTypeSchemaMapper.mapJsonLdObjectDefaultEitherSchema(\n\t\t\tbaseSchema,\n\t\t\t\"@context\",\n\t\t\t\"@context\",\n\t\t\t{\n\t\t\t\ttype: \"array\",\n\t\t\t\titems: { type: \"string\" }\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Resolve default schema from either of two source keys, with fallback when both are absent.\n\t */\n\tprivate static mapJsonLdObjectDefaultEitherSchema(\n\t\tbaseSchema: IJsonSchema,\n\t\tfirstKey: string,\n\t\tsecondKey: string,\n\t\tfallbackSchema: IJsonSchema\n\t): IJsonSchema {\n\t\tconst firstSchema = ObjectTransformer.resolvePropertySchemaFromObjectSchema(\n\t\t\tbaseSchema,\n\t\t\tfirstKey\n\t\t);\n\t\tconst secondSchema = ObjectTransformer.resolvePropertySchemaFromObjectSchema(\n\t\t\tbaseSchema,\n\t\t\tsecondKey\n\t\t);\n\n\t\tif (firstSchema && secondSchema) {\n\t\t\tif (JsonHelper.canonicalize(firstSchema) === JsonHelper.canonicalize(secondSchema)) {\n\t\t\t\treturn firstSchema;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tanyOf: [firstSchema, secondSchema]\n\t\t\t};\n\t\t}\n\n\t\tif (firstSchema) {\n\t\t\treturn firstSchema;\n\t\t}\n\n\t\tif (secondSchema) {\n\t\t\treturn secondSchema;\n\t\t}\n\n\t\treturn fallbackSchema;\n\t}\n}\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
export * from "./models/
|
|
2
|
-
export * from "./models/
|
|
3
|
-
export * from "./models/
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./
|
|
8
|
-
export * from "./
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./utils/
|
|
11
|
-
export * from "./utils/
|
|
1
|
+
export * from "./models/ITypeScriptToSchemaContext.js";
|
|
2
|
+
export * from "./models/ITypeScriptToSchemaDiagnostics.js";
|
|
3
|
+
export * from "./models/ITypeScriptToSchemaOptions.js";
|
|
4
|
+
export * from "./utils/diagnosticReporter.js";
|
|
5
|
+
export * from "./utils/disallowedTypeGuard.js";
|
|
6
|
+
export * from "./utils/enum.js";
|
|
7
|
+
export * from "./utils/fileUtils.js";
|
|
8
|
+
export * from "./utils/importTypeQuerySchemaResolver.js";
|
|
9
|
+
export * from "./utils/indexSignaturePatternResolver.js";
|
|
10
|
+
export * from "./utils/intersectionSchemaMerger.js";
|
|
11
|
+
export * from "./utils/jsonSchemaBuilder.js";
|
|
12
|
+
export * from "./utils/constants.js";
|
|
13
|
+
export * from "./utils/mappedTypeSchemaResolver.js";
|
|
14
|
+
export * from "./utils/objectTransformer.js";
|
|
15
|
+
export * from "./utils/regEx.js";
|
|
16
|
+
export * from "./utils/resolver.js";
|
|
17
|
+
export * from "./utils/templateLiteralPatternBuilder.js";
|
|
18
|
+
export * from "./utils/typeScriptToSchema.js";
|
|
19
|
+
export * from "./utils/jsDoc.js";
|
|
20
|
+
export * from "./utils/utilityTypeSchemaMapper.js";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { IJsonSchema } from "@twin.org/tools-models";
|
|
2
|
+
import type * as ts from "typescript";
|
|
3
|
+
import type { ITypeScriptToSchemaOptions } from "./ITypeScriptToSchemaOptions.js";
|
|
4
|
+
/**
|
|
5
|
+
* Context for TypeScript to JSON schema generation.
|
|
6
|
+
*/
|
|
7
|
+
export interface ITypeScriptToSchemaContext {
|
|
8
|
+
/**
|
|
9
|
+
* The namespace for generated schema ids.
|
|
10
|
+
*/
|
|
11
|
+
namespace: string;
|
|
12
|
+
/**
|
|
13
|
+
* The package name for generated schema ids.
|
|
14
|
+
*/
|
|
15
|
+
packageName: string;
|
|
16
|
+
/**
|
|
17
|
+
* The schema cache indexed by package and title.
|
|
18
|
+
*/
|
|
19
|
+
schemas: {
|
|
20
|
+
[id: string]: {
|
|
21
|
+
[id: string]: IJsonSchema;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The currently active source file being mapped.
|
|
26
|
+
*/
|
|
27
|
+
activeSourceFile?: ts.SourceFile;
|
|
28
|
+
/**
|
|
29
|
+
* The currently active enclosing object (interface/type) being mapped.
|
|
30
|
+
*/
|
|
31
|
+
activeEnclosingObjectName?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The first disallowed type encountered while mapping the active enclosing object.
|
|
34
|
+
*/
|
|
35
|
+
activeDisallowedType?: {
|
|
36
|
+
disallowedTypeName: string;
|
|
37
|
+
propertyName: string;
|
|
38
|
+
enclosingObjectName: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Type names currently being resolved to avoid recursive local-type expansion loops.
|
|
42
|
+
*/
|
|
43
|
+
resolvingTypeNames?: Set<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Utility type names currently being processed to avoid infinite recursion cycles
|
|
46
|
+
* when encountering complex combinations of indexed access types, keyof, and utility types.
|
|
47
|
+
*/
|
|
48
|
+
resolvingUtilityTypes?: Set<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Imported utility base schemas currently being resolved to avoid recursive re-entry
|
|
51
|
+
* while parsing module graphs for utility type application.
|
|
52
|
+
*/
|
|
53
|
+
resolvingImportedObjectSchemas?: Set<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Generic type parameter bindings active for the current mapping scope.
|
|
56
|
+
*/
|
|
57
|
+
typeParameterBindings?: {
|
|
58
|
+
[id: string]: ts.TypeNode | null;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Optional schema generation options.
|
|
62
|
+
*/
|
|
63
|
+
options?: ITypeScriptToSchemaOptions;
|
|
64
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostic payload for non-fatal schema generation issues.
|
|
3
|
+
*/
|
|
4
|
+
export interface ITypeScriptToSchemaDiagnostics {
|
|
5
|
+
/**
|
|
6
|
+
* Stable diagnostic code identifying the issue type.
|
|
7
|
+
*/
|
|
8
|
+
code: string;
|
|
9
|
+
/**
|
|
10
|
+
* Additional structured metadata related to the diagnostic.
|
|
11
|
+
*/
|
|
12
|
+
properties?: {
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Schema path where the issue was detected.
|
|
17
|
+
*/
|
|
18
|
+
path: string;
|
|
19
|
+
/**
|
|
20
|
+
* Source file where the diagnostic originated, if available.
|
|
21
|
+
*/
|
|
22
|
+
fileName?: string;
|
|
23
|
+
/**
|
|
24
|
+
* One-based source line number, when available.
|
|
25
|
+
*/
|
|
26
|
+
line?: number;
|
|
27
|
+
/**
|
|
28
|
+
* One-based source column number, when available.
|
|
29
|
+
*/
|
|
30
|
+
column?: number;
|
|
31
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ITypeScriptToSchemaDiagnostics } from "./ITypeScriptToSchemaDiagnostics.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for TypeScript to JSON schema generation.
|
|
4
|
+
*/
|
|
5
|
+
export interface ITypeScriptToSchemaOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Mapping of package ids, type ids, wildcard patterns, or regex patterns to schema id prefixes
|
|
8
|
+
* or replacement templates for referenced schemas.
|
|
9
|
+
*/
|
|
10
|
+
externalReferences?: {
|
|
11
|
+
[id: string]: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Optional diagnostic callback for non-fatal generation issues.
|
|
15
|
+
* @param diagnostic The diagnostic details for the generation issue.
|
|
16
|
+
*/
|
|
17
|
+
onDiagnostic?: (diagnostic: ITypeScriptToSchemaDiagnostics) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Package names where diagnostics should be suppressed, e.g. jose.
|
|
20
|
+
*/
|
|
21
|
+
suppressPackageWarnings?: string[];
|
|
22
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared constants for TypeScript to JSON schema generation.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Constants {
|
|
5
|
+
/**
|
|
6
|
+
* Utility type names currently unsupported and mapped to open schemas with diagnostics.
|
|
7
|
+
*/
|
|
8
|
+
static readonly UNSUPPORTED_UTILITY_TYPE_NAMES: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Native typed-array and binary type names mapped to JSON number arrays.
|
|
11
|
+
*/
|
|
12
|
+
static readonly ARRAY_NUMBER_TYPE_NAMES: string[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type * as ts from "typescript";
|
|
2
|
+
import type { ITypeScriptToSchemaContext } from "../models/ITypeScriptToSchemaContext.js";
|
|
3
|
+
/**
|
|
4
|
+
* Emits non-fatal diagnostics during schema mapping.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DiagnosticReporter {
|
|
7
|
+
/**
|
|
8
|
+
* Emit an optional non-fatal schema generation diagnostic.
|
|
9
|
+
* @param context The generation context.
|
|
10
|
+
* @param node The related AST node.
|
|
11
|
+
* @param code The diagnostic code.
|
|
12
|
+
* @param properties The values to substitute into the localised message.
|
|
13
|
+
*/
|
|
14
|
+
static report(context: ITypeScriptToSchemaContext, node: ts.Node, code: string, properties?: {
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}): void;
|
|
17
|
+
}
|