@twin.org/tools-core 0.0.3-next.25 → 0.0.3-next.26
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/dist/es/index.js +3 -2
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/ITypeScriptToSchemaContext.js.map +1 -1
- package/dist/es/models/embeddedSchemaMode.js +17 -0
- package/dist/es/models/embeddedSchemaMode.js.map +1 -0
- package/dist/es/utils/importTypeQuerySchemaResolver.js +1 -0
- package/dist/es/utils/importTypeQuerySchemaResolver.js.map +1 -1
- package/dist/es/utils/jsDoc.js +1 -1
- package/dist/es/utils/jsDoc.js.map +1 -1
- package/dist/es/utils/jsonSchemaBuilder.js +35 -10
- package/dist/es/utils/jsonSchemaBuilder.js.map +1 -1
- package/dist/es/utils/typeScriptToSchema.js +208 -1
- package/dist/es/utils/typeScriptToSchema.js.map +1 -1
- package/dist/es/utils/utilityTypeSchemaMapper.js +21 -21
- package/dist/es/utils/utilityTypeSchemaMapper.js.map +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/models/ITypeScriptToSchemaContext.d.ts +7 -0
- package/dist/types/models/embeddedSchemaMode.d.ts +17 -0
- package/dist/types/utils/jsDoc.d.ts +1 -1
- package/dist/types/utils/typeScriptToSchema.d.ts +61 -0
- package/dist/types/utils/utilityTypeSchemaMapper.d.ts +21 -21
- package/docs/changelog.md +14 -0
- package/docs/reference/classes/JsDoc.md +1 -1
- package/docs/reference/classes/UtilityTypeSchemaMapper.md +21 -21
- package/docs/reference/index.md +8 -0
- package/docs/reference/interfaces/ITypeScriptToSchemaContext.md +12 -0
- package/docs/reference/type-aliases/EmbeddedSchemaMode.md +5 -0
- package/docs/reference/variables/EmbeddedSchemaMode.md +19 -0
- package/package.json +2 -2
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Copyright 2026 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
-
import { Is, StringHelper } from "@twin.org/core";
|
|
3
|
+
import { Is, ObjectHelper, StringHelper } from "@twin.org/core";
|
|
4
4
|
import { FileUtils } from "./fileUtils.js";
|
|
5
5
|
import { JsonSchemaBuilder } from "./jsonSchemaBuilder.js";
|
|
6
6
|
import { Resolver } from "./resolver.js";
|
|
7
|
+
import { EmbeddedSchemaMode } from "../models/embeddedSchemaMode.js";
|
|
7
8
|
/**
|
|
8
9
|
* Class for converting TypeScript types to JSON Schema.
|
|
9
10
|
*/
|
|
@@ -76,6 +77,9 @@ export class TypeScriptToSchema {
|
|
|
76
77
|
generatedSchemas[requestedTitle] = requestedSchema;
|
|
77
78
|
}
|
|
78
79
|
}
|
|
80
|
+
for (const [generatedTitle, generatedSchema] of Object.entries(generatedSchemas)) {
|
|
81
|
+
this.inlineEmbeddedSchemas(context, generatedSchema, generatedTitle);
|
|
82
|
+
}
|
|
79
83
|
return generatedSchemas;
|
|
80
84
|
}
|
|
81
85
|
/**
|
|
@@ -97,6 +101,209 @@ export class TypeScriptToSchema {
|
|
|
97
101
|
const packagePathNoTrailingSlash = `/node_modules/${normalisedPackageName}`;
|
|
98
102
|
return sourcePaths.some(sourcePath => sourcePath.includes(packagePath) || sourcePath.endsWith(packagePathNoTrailingSlash));
|
|
99
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Rewrite refs to @json-schema embedded local types into the current schema's $defs.
|
|
106
|
+
* @param context The generation context.
|
|
107
|
+
* @param schema The root schema to rewrite.
|
|
108
|
+
* @param rootTitle The title of the root schema.
|
|
109
|
+
*/
|
|
110
|
+
inlineEmbeddedSchemas(context, schema, rootTitle) {
|
|
111
|
+
this.inlineEmbeddedSchemasInNode(context, schema, schema, rootTitle, new Set([rootTitle]));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Traverse a schema tree and move embedded local refs into the root schema's $defs.
|
|
115
|
+
* @param context The generation context.
|
|
116
|
+
* @param rootSchema The root schema document being rewritten.
|
|
117
|
+
* @param currentNode The current schema node.
|
|
118
|
+
* @param rootTitle The title of the root schema.
|
|
119
|
+
* @param ancestry Titles currently being expanded to avoid recursion cycles.
|
|
120
|
+
* @returns True if inline embedding changed this node or a descendant.
|
|
121
|
+
*/
|
|
122
|
+
inlineEmbeddedSchemasInNode(context, rootSchema, currentNode, rootTitle, ancestry) {
|
|
123
|
+
let hasInlineReplacement = false;
|
|
124
|
+
if (Is.stringValue(currentNode.$ref)) {
|
|
125
|
+
const refId = currentNode.$ref;
|
|
126
|
+
const embeddedMode = context.embeddedSchemaModes?.[refId];
|
|
127
|
+
const embeddedSchema = this.findSchemaById(context, refId);
|
|
128
|
+
const defsKey = embeddedSchema
|
|
129
|
+
? this.getEmbeddedDefinitionKey(embeddedSchema, refId)
|
|
130
|
+
: undefined;
|
|
131
|
+
if (embeddedMode &&
|
|
132
|
+
embeddedSchema &&
|
|
133
|
+
defsKey &&
|
|
134
|
+
defsKey !== rootTitle &&
|
|
135
|
+
!ancestry.has(defsKey)) {
|
|
136
|
+
const embeddedClone = this.createEmbeddedSchemaClone(context, embeddedSchema, embeddedMode);
|
|
137
|
+
this.inlineEmbeddedSchemasInNode(context, rootSchema, embeddedClone, rootTitle, new Set([...ancestry, defsKey]));
|
|
138
|
+
if (embeddedMode === EmbeddedSchemaMode.Defs) {
|
|
139
|
+
rootSchema.$defs ??= {};
|
|
140
|
+
rootSchema.$defs[defsKey] ??= embeddedClone;
|
|
141
|
+
currentNode.$ref = `#/$defs/${defsKey}`;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
this.replaceSchemaNode(currentNode, embeddedClone);
|
|
145
|
+
hasInlineReplacement = true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
for (const value of Object.values(currentNode)) {
|
|
150
|
+
if (Is.array(value)) {
|
|
151
|
+
for (const item of value) {
|
|
152
|
+
if (Is.object(item)) {
|
|
153
|
+
hasInlineReplacement =
|
|
154
|
+
this.inlineEmbeddedSchemasInNode(context, rootSchema, item, rootTitle, ancestry) ||
|
|
155
|
+
hasInlineReplacement;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if (Is.object(value)) {
|
|
160
|
+
for (const nestedValue of Object.values(value)) {
|
|
161
|
+
if (Is.object(nestedValue)) {
|
|
162
|
+
hasInlineReplacement =
|
|
163
|
+
this.inlineEmbeddedSchemasInNode(context, rootSchema, nestedValue, rootTitle, ancestry) || hasInlineReplacement;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (hasInlineReplacement) {
|
|
169
|
+
this.flattenInlineAllOfBranches(currentNode);
|
|
170
|
+
}
|
|
171
|
+
return hasInlineReplacement;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Flatten inline-expanded object allOf branches into the containing schema.
|
|
175
|
+
* @param schema The schema to flatten.
|
|
176
|
+
*/
|
|
177
|
+
flattenInlineAllOfBranches(schema) {
|
|
178
|
+
if (!Is.array(schema.allOf) || schema.allOf.length === 0) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const remainingBranches = [];
|
|
182
|
+
const mergedProperties = {};
|
|
183
|
+
const mergedRequired = new Set((Is.array(schema.required) ? schema.required : []).filter((requiredKey) => Is.stringValue(requiredKey)));
|
|
184
|
+
let hasMergedBranch = false;
|
|
185
|
+
for (const branch of schema.allOf) {
|
|
186
|
+
if (this.canFlattenInlineAllOfBranch(branch)) {
|
|
187
|
+
hasMergedBranch = true;
|
|
188
|
+
schema.type ??= "object";
|
|
189
|
+
if (Is.object(branch.properties)) {
|
|
190
|
+
Object.assign(mergedProperties, branch.properties);
|
|
191
|
+
}
|
|
192
|
+
if (Is.array(branch.required)) {
|
|
193
|
+
for (const requiredKey of branch.required) {
|
|
194
|
+
if (Is.stringValue(requiredKey)) {
|
|
195
|
+
mergedRequired.add(requiredKey);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
remainingBranches.push(branch);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (!hasMergedBranch) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (Object.keys(mergedProperties).length > 0) {
|
|
208
|
+
schema.properties = Object.assign(schema.properties ?? {}, mergedProperties);
|
|
209
|
+
}
|
|
210
|
+
if (mergedRequired.size > 0) {
|
|
211
|
+
schema.required = [...mergedRequired];
|
|
212
|
+
}
|
|
213
|
+
if (remainingBranches.length > 0) {
|
|
214
|
+
schema.allOf = remainingBranches;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
delete schema.allOf;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Determine whether an allOf branch can be flattened into its parent after inline embedding.
|
|
222
|
+
* @param branch The allOf branch.
|
|
223
|
+
* @returns True if the branch is a plain object schema.
|
|
224
|
+
*/
|
|
225
|
+
canFlattenInlineAllOfBranch(branch) {
|
|
226
|
+
return Boolean(!branch.$ref &&
|
|
227
|
+
!branch.allOf &&
|
|
228
|
+
!branch.anyOf &&
|
|
229
|
+
!branch.oneOf &&
|
|
230
|
+
!branch.items &&
|
|
231
|
+
(branch.type === "object" || Is.object(branch.properties) || Is.array(branch.required)));
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Create a clone of an embedded schema suitable for defs or inline expansion.
|
|
235
|
+
* @param context The generation context.
|
|
236
|
+
* @param embeddedSchema The source schema.
|
|
237
|
+
* @param embeddedMode The embedding mode.
|
|
238
|
+
* @returns The cloned schema.
|
|
239
|
+
*/
|
|
240
|
+
createEmbeddedSchemaClone(context, embeddedSchema, embeddedMode) {
|
|
241
|
+
let embeddedClone = ObjectHelper.clone(embeddedSchema);
|
|
242
|
+
if (embeddedMode === EmbeddedSchemaMode.Inline) {
|
|
243
|
+
embeddedClone = JsonSchemaBuilder.expandAllOfReferences(context, embeddedClone);
|
|
244
|
+
this.removeSchemaComments(embeddedClone);
|
|
245
|
+
}
|
|
246
|
+
delete embeddedClone.$schema;
|
|
247
|
+
delete embeddedClone.$id;
|
|
248
|
+
if (embeddedMode === EmbeddedSchemaMode.Inline) {
|
|
249
|
+
delete embeddedClone.title;
|
|
250
|
+
}
|
|
251
|
+
return embeddedClone;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Replace the contents of a schema node while keeping the same object reference.
|
|
255
|
+
* @param target The schema node to mutate.
|
|
256
|
+
* @param replacement The replacement content.
|
|
257
|
+
*/
|
|
258
|
+
replaceSchemaNode(target, replacement) {
|
|
259
|
+
for (const key of Object.keys(target)) {
|
|
260
|
+
delete target[key];
|
|
261
|
+
}
|
|
262
|
+
Object.assign(target, replacement);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Find a generated schema by its canonical id across all loaded packages.
|
|
266
|
+
* @param context The generation context.
|
|
267
|
+
* @param schemaId The schema id to locate.
|
|
268
|
+
* @returns The schema when found.
|
|
269
|
+
*/
|
|
270
|
+
findSchemaById(context, schemaId) {
|
|
271
|
+
return Object.values(context.schemas)
|
|
272
|
+
.flatMap(packageSchemas => Object.values(packageSchemas))
|
|
273
|
+
.find(schema => schema.$id === schemaId);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Resolve the local $defs key to use for an embedded schema.
|
|
277
|
+
* @param schema The embedded schema.
|
|
278
|
+
* @param schemaId The canonical schema id.
|
|
279
|
+
* @returns The local definition key.
|
|
280
|
+
*/
|
|
281
|
+
getEmbeddedDefinitionKey(schema, schemaId) {
|
|
282
|
+
return schema.title ?? schemaId.split("/").pop() ?? schemaId;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Remove $comment fields from a schema tree.
|
|
286
|
+
* @param schema The schema tree to clean.
|
|
287
|
+
*/
|
|
288
|
+
removeSchemaComments(schema) {
|
|
289
|
+
delete schema.$comment;
|
|
290
|
+
for (const value of Object.values(schema)) {
|
|
291
|
+
if (Is.array(value)) {
|
|
292
|
+
for (const item of value) {
|
|
293
|
+
if (Is.object(item)) {
|
|
294
|
+
this.removeSchemaComments(item);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
else if (Is.object(value)) {
|
|
299
|
+
for (const nestedValue of Object.values(value)) {
|
|
300
|
+
if (Is.object(nestedValue)) {
|
|
301
|
+
this.removeSchemaComments(nestedValue);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
100
307
|
/**
|
|
101
308
|
* Determine whether an input value is a valid TypeScript type identifier.
|
|
102
309
|
* An identifier must start with a letter, underscore, or dollar sign and contain only
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeScriptToSchema.js","sourceRoot":"","sources":["../../../src/utils/typeScriptToSchema.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIzC;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAC9B;;;;;;;;OAQG;IACI,KAAK,CAAC,cAAc,CAC1B,SAAiB,EACjB,WAAmB,EACnB,OAAwD,EACxD,oBAA4B,EAC5B,OAAoC;QAEpC,MAAM,uBAAuB,GAAG,CAAC,OAAO,EAAE,uBAAuB,IAAI,EAAE,CAAC;aACtE,MAAM,CAAC,iBAAiB,CAAC,EAAE,CAAC,EAAE,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;aAC9D,GAAG,CAAC,iBAAiB,CAAC,EAAE,CAAC,iBAAiB,CAAC,WAAW,EAAE,CAAC,CAAC;QAC5D,MAAM,eAAe,GAA+B;YACnD,GA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IAAI,CAAC;aAClC,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;aACzD,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;QACxD,MAAM,qBAAqB,GAAG,WAAW,CAAC,WAAW,EAAE,CAAC;QACxD,MAAM,WAAW,GAAG,iBAAiB,qBAAqB,GAAG,CAAC;QAC9D,MAAM,0BAA0B,GAAG,iBAAiB,qBAAqB,EAAE,CAAC;QAE5E,OAAO,WAAW,CAAC,IAAI,CACtB,UAAU,CAAC,EAAE,CACZ,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,0BAA0B,CAAC,CACpF,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACK,eAAe,CAAC,KAAa;QACpC,OAAO,6BAA6B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;CACD","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is, StringHelper } from \"@twin.org/core\";\nimport type { IJsonSchema } from \"@twin.org/tools-models\";\nimport { FileUtils } from \"./fileUtils.js\";\nimport { JsonSchemaBuilder } from \"./jsonSchemaBuilder.js\";\nimport { Resolver } from \"./resolver.js\";\nimport type { ITypeScriptToSchemaContext } from \"../models/ITypeScriptToSchemaContext.js\";\nimport type { ITypeScriptToSchemaOptions } from \"../models/ITypeScriptToSchemaOptions.js\";\n\n/**\n * Class for converting TypeScript types to JSON Schema.\n */\nexport class TypeScriptToSchema {\n\t/**\n\t * Generates a JSON schema from a TypeScript source file or type name.\n\t * @param namespace The schema namespace.\n\t * @param packageName The package name.\n\t * @param schemas The package schema map.\n\t * @param sourceFileOrTypeName The source file to process or type name to resolve.\n\t * @param options Additional generation options.\n\t * @returns The generated JSON schemas indexed by title.\n\t */\n\tpublic async generateSchema(\n\t\tnamespace: string,\n\t\tpackageName: string,\n\t\tschemas: { [id: string]: { [id: string]: IJsonSchema } },\n\t\tsourceFileOrTypeName: string,\n\t\toptions?: ITypeScriptToSchemaOptions\n\t): Promise<{ [id: string]: IJsonSchema }> {\n\t\tconst suppressPackageWarnings = (options?.suppressPackageWarnings ?? [])\n\t\t\t.filter(packageNameToSkip => Is.stringValue(packageNameToSkip))\n\t\t\t.map(packageNameToSkip => packageNameToSkip.toLowerCase());\n\t\tconst filteredOptions: ITypeScriptToSchemaOptions = {\n\t\t\t...options,\n\t\t\tonDiagnostic: diagnostic => {\n\t\t\t\tif (\n\t\t\t\t\tsuppressPackageWarnings.some(packageToSkip =>\n\t\t\t\t\t\tthis.isDiagnosticFromPackage(diagnostic.path, diagnostic.fileName, packageToSkip)\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\toptions?.onDiagnostic?.(diagnostic);\n\t\t\t}\n\t\t};\n\n\t\tconst context: ITypeScriptToSchemaContext = {\n\t\t\tnamespace,\n\t\t\tpackageName,\n\t\t\tschemas,\n\t\t\toptions: filteredOptions\n\t\t};\n\n\t\tlet generatedTitles: string[] = [];\n\t\tcontext.schemas[context.packageName] ??= {};\n\t\tconst visitedFiles: string[] = [];\n\t\tconst sourceFiles = FileUtils.resolveSourceFiles(sourceFileOrTypeName);\n\n\t\tif (sourceFiles.length > 0) {\n\t\t\tfor (const sourceFilePath of sourceFiles) {\n\t\t\t\tconst source = FileUtils.readFile(sourceFilePath);\n\t\t\t\tif (source) {\n\t\t\t\t\tconst parsedTitles = JsonSchemaBuilder.parseAllObjectSchemas(\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tsourceFilePath,\n\t\t\t\t\t\tsource,\n\t\t\t\t\t\tvisitedFiles\n\t\t\t\t\t);\n\t\t\t\t\tfor (const parsedTitle of parsedTitles) {\n\t\t\t\t\t\tif (!generatedTitles.includes(parsedTitle)) {\n\t\t\t\t\t\t\tgeneratedTitles.push(parsedTitle);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.isTypeNameInput(sourceFileOrTypeName)) {\n\t\t\tconst declarationResult = Resolver.resolveTypeDeclarationAst(\n\t\t\t\tcontext.packageName,\n\t\t\t\tsourceFileOrTypeName\n\t\t\t);\n\t\t\tif (declarationResult) {\n\t\t\t\tgeneratedTitles = JsonSchemaBuilder.parseAllObjectSchemas(\n\t\t\t\t\tcontext,\n\t\t\t\t\tdeclarationResult.sourceFile.fileName,\n\t\t\t\t\tdeclarationResult.sourceFile.getFullText(),\n\t\t\t\t\tvisitedFiles\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\treturn {};\n\t\t}\n\n\t\tconst generatedSchemas: { [id: string]: IJsonSchema } = {};\n\t\tfor (const generatedTitle of generatedTitles) {\n\t\t\tconst generatedSchema = context.schemas[context.packageName][generatedTitle];\n\t\t\tif (generatedSchema) {\n\t\t\t\tgeneratedSchemas[generatedTitle] = generatedSchema;\n\t\t\t}\n\t\t}\n\n\t\tif (this.isTypeNameInput(sourceFileOrTypeName)) {\n\t\t\tconst requestedTitle = StringHelper.stripPrefix(sourceFileOrTypeName);\n\t\t\tconst requestedSchema = context.schemas[context.packageName][requestedTitle];\n\t\t\tif (requestedSchema) {\n\t\t\t\tgeneratedSchemas[requestedTitle] = requestedSchema;\n\t\t\t}\n\t\t}\n\n\t\treturn generatedSchemas;\n\t}\n\n\t/**\n\t * Determine if a diagnostic originates from a specific package.\n\t * @param path The schema or source path associated with the diagnostic.\n\t * @param fileName The source filename associated with the diagnostic.\n\t * @param packageName The package name to check, e.g. jose.\n\t * @returns True if the diagnostic originated from the package.\n\t */\n\tpublic isDiagnosticFromPackage(\n\t\tpath: string,\n\t\tfileName: string | undefined,\n\t\tpackageName: string\n\t): boolean {\n\t\tif (!Is.stringValue(packageName)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst sourcePaths = [fileName, path]\n\t\t\t.filter((value): value is string => Is.stringValue(value))\n\t\t\t.map(value => value.replace(/\\\\/g, \"/\").toLowerCase());\n\t\tconst normalisedPackageName = packageName.toLowerCase();\n\t\tconst packagePath = `/node_modules/${normalisedPackageName}/`;\n\t\tconst packagePathNoTrailingSlash = `/node_modules/${normalisedPackageName}`;\n\n\t\treturn sourcePaths.some(\n\t\t\tsourcePath =>\n\t\t\t\tsourcePath.includes(packagePath) || sourcePath.endsWith(packagePathNoTrailingSlash)\n\t\t);\n\t}\n\n\t/**\n\t * Determine whether an input value is a valid TypeScript type identifier.\n\t * An identifier must start with a letter, underscore, or dollar sign and contain only\n\t * alphanumerics, underscores, or dollar signs thereafter.\n\t * @param value The value to inspect.\n\t * @returns True if the value looks like a type name.\n\t * @internal\n\t */\n\tprivate isTypeNameInput(value: string): boolean {\n\t\treturn /^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(value);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"typeScriptToSchema.js","sourceRoot":"","sources":["../../../src/utils/typeScriptToSchema.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAIrE;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAC9B;;;;;;;;OAQG;IACI,KAAK,CAAC,cAAc,CAC1B,SAAiB,EACjB,WAAmB,EACnB,OAAwD,EACxD,oBAA4B,EAC5B,OAAoC;QAEpC,MAAM,uBAAuB,GAAG,CAAC,OAAO,EAAE,uBAAuB,I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CAAC;YACF,CAAC;iBAAM,IAAI,EAAE,CAAC,MAAM,CAA4B,KAAK,CAAC,EAAE,CAAC;gBACxD,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;oBAChD,IAAI,EAAE,CAAC,MAAM,CAAc,WAAW,CAAC,EAAE,CAAC;wBACzC,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;oBACxC,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;IAED;;;;;;;OAOG;IACK,eAAe,CAAC,KAAa;QACpC,OAAO,6BAA6B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;CACD","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is, ObjectHelper, StringHelper } from \"@twin.org/core\";\nimport type { IJsonSchema } from \"@twin.org/tools-models\";\nimport { FileUtils } from \"./fileUtils.js\";\nimport { JsonSchemaBuilder } from \"./jsonSchemaBuilder.js\";\nimport { Resolver } from \"./resolver.js\";\nimport { EmbeddedSchemaMode } from \"../models/embeddedSchemaMode.js\";\nimport type { ITypeScriptToSchemaContext } from \"../models/ITypeScriptToSchemaContext.js\";\nimport type { ITypeScriptToSchemaOptions } from \"../models/ITypeScriptToSchemaOptions.js\";\n\n/**\n * Class for converting TypeScript types to JSON Schema.\n */\nexport class TypeScriptToSchema {\n\t/**\n\t * Generates a JSON schema from a TypeScript source file or type name.\n\t * @param namespace The schema namespace.\n\t * @param packageName The package name.\n\t * @param schemas The package schema map.\n\t * @param sourceFileOrTypeName The source file to process or type name to resolve.\n\t * @param options Additional generation options.\n\t * @returns The generated JSON schemas indexed by title.\n\t */\n\tpublic async generateSchema(\n\t\tnamespace: string,\n\t\tpackageName: string,\n\t\tschemas: { [id: string]: { [id: string]: IJsonSchema } },\n\t\tsourceFileOrTypeName: string,\n\t\toptions?: ITypeScriptToSchemaOptions\n\t): Promise<{ [id: string]: IJsonSchema }> {\n\t\tconst suppressPackageWarnings = (options?.suppressPackageWarnings ?? [])\n\t\t\t.filter(packageNameToSkip => Is.stringValue(packageNameToSkip))\n\t\t\t.map(packageNameToSkip => packageNameToSkip.toLowerCase());\n\t\tconst filteredOptions: ITypeScriptToSchemaOptions = {\n\t\t\t...options,\n\t\t\tonDiagnostic: diagnostic => {\n\t\t\t\tif (\n\t\t\t\t\tsuppressPackageWarnings.some(packageToSkip =>\n\t\t\t\t\t\tthis.isDiagnosticFromPackage(diagnostic.path, diagnostic.fileName, packageToSkip)\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\toptions?.onDiagnostic?.(diagnostic);\n\t\t\t}\n\t\t};\n\n\t\tconst context: ITypeScriptToSchemaContext = {\n\t\t\tnamespace,\n\t\t\tpackageName,\n\t\t\tschemas,\n\t\t\toptions: filteredOptions\n\t\t};\n\n\t\tlet generatedTitles: string[] = [];\n\t\tcontext.schemas[context.packageName] ??= {};\n\t\tconst visitedFiles: string[] = [];\n\t\tconst sourceFiles = FileUtils.resolveSourceFiles(sourceFileOrTypeName);\n\n\t\tif (sourceFiles.length > 0) {\n\t\t\tfor (const sourceFilePath of sourceFiles) {\n\t\t\t\tconst source = FileUtils.readFile(sourceFilePath);\n\t\t\t\tif (source) {\n\t\t\t\t\tconst parsedTitles = JsonSchemaBuilder.parseAllObjectSchemas(\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tsourceFilePath,\n\t\t\t\t\t\tsource,\n\t\t\t\t\t\tvisitedFiles\n\t\t\t\t\t);\n\t\t\t\t\tfor (const parsedTitle of parsedTitles) {\n\t\t\t\t\t\tif (!generatedTitles.includes(parsedTitle)) {\n\t\t\t\t\t\t\tgeneratedTitles.push(parsedTitle);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.isTypeNameInput(sourceFileOrTypeName)) {\n\t\t\tconst declarationResult = Resolver.resolveTypeDeclarationAst(\n\t\t\t\tcontext.packageName,\n\t\t\t\tsourceFileOrTypeName\n\t\t\t);\n\t\t\tif (declarationResult) {\n\t\t\t\tgeneratedTitles = JsonSchemaBuilder.parseAllObjectSchemas(\n\t\t\t\t\tcontext,\n\t\t\t\t\tdeclarationResult.sourceFile.fileName,\n\t\t\t\t\tdeclarationResult.sourceFile.getFullText(),\n\t\t\t\t\tvisitedFiles\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\treturn {};\n\t\t}\n\n\t\tconst generatedSchemas: { [id: string]: IJsonSchema } = {};\n\t\tfor (const generatedTitle of generatedTitles) {\n\t\t\tconst generatedSchema = context.schemas[context.packageName][generatedTitle];\n\t\t\tif (generatedSchema) {\n\t\t\t\tgeneratedSchemas[generatedTitle] = generatedSchema;\n\t\t\t}\n\t\t}\n\n\t\tif (this.isTypeNameInput(sourceFileOrTypeName)) {\n\t\t\tconst requestedTitle = StringHelper.stripPrefix(sourceFileOrTypeName);\n\t\t\tconst requestedSchema = context.schemas[context.packageName][requestedTitle];\n\t\t\tif (requestedSchema) {\n\t\t\t\tgeneratedSchemas[requestedTitle] = requestedSchema;\n\t\t\t}\n\t\t}\n\n\t\tfor (const [generatedTitle, generatedSchema] of Object.entries(generatedSchemas)) {\n\t\t\tthis.inlineEmbeddedSchemas(context, generatedSchema, generatedTitle);\n\t\t}\n\n\t\treturn generatedSchemas;\n\t}\n\n\t/**\n\t * Determine if a diagnostic originates from a specific package.\n\t * @param path The schema or source path associated with the diagnostic.\n\t * @param fileName The source filename associated with the diagnostic.\n\t * @param packageName The package name to check, e.g. jose.\n\t * @returns True if the diagnostic originated from the package.\n\t */\n\tpublic isDiagnosticFromPackage(\n\t\tpath: string,\n\t\tfileName: string | undefined,\n\t\tpackageName: string\n\t): boolean {\n\t\tif (!Is.stringValue(packageName)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst sourcePaths = [fileName, path]\n\t\t\t.filter((value): value is string => Is.stringValue(value))\n\t\t\t.map(value => value.replace(/\\\\/g, \"/\").toLowerCase());\n\t\tconst normalisedPackageName = packageName.toLowerCase();\n\t\tconst packagePath = `/node_modules/${normalisedPackageName}/`;\n\t\tconst packagePathNoTrailingSlash = `/node_modules/${normalisedPackageName}`;\n\n\t\treturn sourcePaths.some(\n\t\t\tsourcePath =>\n\t\t\t\tsourcePath.includes(packagePath) || sourcePath.endsWith(packagePathNoTrailingSlash)\n\t\t);\n\t}\n\n\t/**\n\t * Rewrite refs to @json-schema embedded local types into the current schema's $defs.\n\t * @param context The generation context.\n\t * @param schema The root schema to rewrite.\n\t * @param rootTitle The title of the root schema.\n\t */\n\tprivate inlineEmbeddedSchemas(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\tschema: IJsonSchema,\n\t\trootTitle: string\n\t): void {\n\t\tthis.inlineEmbeddedSchemasInNode(context, schema, schema, rootTitle, new Set([rootTitle]));\n\t}\n\n\t/**\n\t * Traverse a schema tree and move embedded local refs into the root schema's $defs.\n\t * @param context The generation context.\n\t * @param rootSchema The root schema document being rewritten.\n\t * @param currentNode The current schema node.\n\t * @param rootTitle The title of the root schema.\n\t * @param ancestry Titles currently being expanded to avoid recursion cycles.\n\t * @returns True if inline embedding changed this node or a descendant.\n\t */\n\tprivate inlineEmbeddedSchemasInNode(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\trootSchema: IJsonSchema,\n\t\tcurrentNode: IJsonSchema,\n\t\trootTitle: string,\n\t\tancestry: Set<string>\n\t): boolean {\n\t\tlet hasInlineReplacement = false;\n\n\t\tif (Is.stringValue(currentNode.$ref)) {\n\t\t\tconst refId = currentNode.$ref;\n\t\t\tconst embeddedMode = context.embeddedSchemaModes?.[refId];\n\t\t\tconst embeddedSchema = this.findSchemaById(context, refId);\n\t\t\tconst defsKey = embeddedSchema\n\t\t\t\t? this.getEmbeddedDefinitionKey(embeddedSchema, refId)\n\t\t\t\t: undefined;\n\n\t\t\tif (\n\t\t\t\tembeddedMode &&\n\t\t\t\tembeddedSchema &&\n\t\t\t\tdefsKey &&\n\t\t\t\tdefsKey !== rootTitle &&\n\t\t\t\t!ancestry.has(defsKey)\n\t\t\t) {\n\t\t\t\tconst embeddedClone = this.createEmbeddedSchemaClone(context, embeddedSchema, embeddedMode);\n\t\t\t\tthis.inlineEmbeddedSchemasInNode(\n\t\t\t\t\tcontext,\n\t\t\t\t\trootSchema,\n\t\t\t\t\tembeddedClone,\n\t\t\t\t\trootTitle,\n\t\t\t\t\tnew Set([...ancestry, defsKey])\n\t\t\t\t);\n\n\t\t\t\tif (embeddedMode === EmbeddedSchemaMode.Defs) {\n\t\t\t\t\trootSchema.$defs ??= {};\n\t\t\t\t\trootSchema.$defs[defsKey] ??= embeddedClone;\n\t\t\t\t\tcurrentNode.$ref = `#/$defs/${defsKey}`;\n\t\t\t\t} else {\n\t\t\t\t\tthis.replaceSchemaNode(currentNode, embeddedClone);\n\t\t\t\t\thasInlineReplacement = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const value of Object.values(currentNode)) {\n\t\t\tif (Is.array(value)) {\n\t\t\t\tfor (const item of value) {\n\t\t\t\t\tif (Is.object<IJsonSchema>(item)) {\n\t\t\t\t\t\thasInlineReplacement =\n\t\t\t\t\t\t\tthis.inlineEmbeddedSchemasInNode(context, rootSchema, item, rootTitle, ancestry) ||\n\t\t\t\t\t\t\thasInlineReplacement;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (Is.object<{ [id: string]: unknown }>(value)) {\n\t\t\t\tfor (const nestedValue of Object.values(value)) {\n\t\t\t\t\tif (Is.object<IJsonSchema>(nestedValue)) {\n\t\t\t\t\t\thasInlineReplacement =\n\t\t\t\t\t\t\tthis.inlineEmbeddedSchemasInNode(\n\t\t\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t\t\trootSchema,\n\t\t\t\t\t\t\t\tnestedValue,\n\t\t\t\t\t\t\t\trootTitle,\n\t\t\t\t\t\t\t\tancestry\n\t\t\t\t\t\t\t) || hasInlineReplacement;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (hasInlineReplacement) {\n\t\t\tthis.flattenInlineAllOfBranches(currentNode);\n\t\t}\n\n\t\treturn hasInlineReplacement;\n\t}\n\n\t/**\n\t * Flatten inline-expanded object allOf branches into the containing schema.\n\t * @param schema The schema to flatten.\n\t */\n\tprivate flattenInlineAllOfBranches(schema: IJsonSchema): void {\n\t\tif (!Is.array(schema.allOf) || schema.allOf.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst remainingBranches: IJsonSchema[] = [];\n\t\tconst mergedProperties: { [id: string]: IJsonSchema } = {};\n\t\tconst mergedRequired = new Set<string>(\n\t\t\t(Is.array(schema.required) ? schema.required : []).filter(\n\t\t\t\t(requiredKey): requiredKey is string => Is.stringValue(requiredKey)\n\t\t\t)\n\t\t);\n\t\tlet hasMergedBranch = false;\n\n\t\tfor (const branch of schema.allOf) {\n\t\t\tif (this.canFlattenInlineAllOfBranch(branch)) {\n\t\t\t\thasMergedBranch = true;\n\t\t\t\tschema.type ??= \"object\";\n\t\t\t\tif (Is.object(branch.properties)) {\n\t\t\t\t\tObject.assign(mergedProperties, branch.properties);\n\t\t\t\t}\n\t\t\t\tif (Is.array(branch.required)) {\n\t\t\t\t\tfor (const requiredKey of branch.required) {\n\t\t\t\t\t\tif (Is.stringValue(requiredKey)) {\n\t\t\t\t\t\t\tmergedRequired.add(requiredKey);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tremainingBranches.push(branch);\n\t\t\t}\n\t\t}\n\n\t\tif (!hasMergedBranch) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (Object.keys(mergedProperties).length > 0) {\n\t\t\tschema.properties = Object.assign(schema.properties ?? {}, mergedProperties);\n\t\t}\n\n\t\tif (mergedRequired.size > 0) {\n\t\t\tschema.required = [...mergedRequired];\n\t\t}\n\n\t\tif (remainingBranches.length > 0) {\n\t\t\tschema.allOf = remainingBranches;\n\t\t} else {\n\t\t\tdelete schema.allOf;\n\t\t}\n\t}\n\n\t/**\n\t * Determine whether an allOf branch can be flattened into its parent after inline embedding.\n\t * @param branch The allOf branch.\n\t * @returns True if the branch is a plain object schema.\n\t */\n\tprivate canFlattenInlineAllOfBranch(branch: IJsonSchema): boolean {\n\t\treturn Boolean(\n\t\t\t!branch.$ref &&\n\t\t\t!branch.allOf &&\n\t\t\t!branch.anyOf &&\n\t\t\t!branch.oneOf &&\n\t\t\t!branch.items &&\n\t\t\t(branch.type === \"object\" || Is.object(branch.properties) || Is.array(branch.required))\n\t\t);\n\t}\n\n\t/**\n\t * Create a clone of an embedded schema suitable for defs or inline expansion.\n\t * @param context The generation context.\n\t * @param embeddedSchema The source schema.\n\t * @param embeddedMode The embedding mode.\n\t * @returns The cloned schema.\n\t */\n\tprivate createEmbeddedSchemaClone(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\tembeddedSchema: IJsonSchema,\n\t\tembeddedMode: EmbeddedSchemaMode\n\t): IJsonSchema {\n\t\tlet embeddedClone = ObjectHelper.clone(embeddedSchema);\n\t\tif (embeddedMode === EmbeddedSchemaMode.Inline) {\n\t\t\tembeddedClone = JsonSchemaBuilder.expandAllOfReferences(context, embeddedClone);\n\t\t\tthis.removeSchemaComments(embeddedClone);\n\t\t}\n\t\tdelete embeddedClone.$schema;\n\t\tdelete embeddedClone.$id;\n\t\tif (embeddedMode === EmbeddedSchemaMode.Inline) {\n\t\t\tdelete embeddedClone.title;\n\t\t}\n\n\t\treturn embeddedClone;\n\t}\n\n\t/**\n\t * Replace the contents of a schema node while keeping the same object reference.\n\t * @param target The schema node to mutate.\n\t * @param replacement The replacement content.\n\t */\n\tprivate replaceSchemaNode(target: IJsonSchema, replacement: IJsonSchema): void {\n\t\tfor (const key of Object.keys(target)) {\n\t\t\tdelete target[key as keyof IJsonSchema];\n\t\t}\n\n\t\tObject.assign(target, replacement);\n\t}\n\n\t/**\n\t * Find a generated schema by its canonical id across all loaded packages.\n\t * @param context The generation context.\n\t * @param schemaId The schema id to locate.\n\t * @returns The schema when found.\n\t */\n\tprivate findSchemaById(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\tschemaId: string\n\t): IJsonSchema | undefined {\n\t\treturn Object.values(context.schemas)\n\t\t\t.flatMap(packageSchemas => Object.values(packageSchemas))\n\t\t\t.find(schema => schema.$id === schemaId);\n\t}\n\n\t/**\n\t * Resolve the local $defs key to use for an embedded schema.\n\t * @param schema The embedded schema.\n\t * @param schemaId The canonical schema id.\n\t * @returns The local definition key.\n\t */\n\tprivate getEmbeddedDefinitionKey(schema: IJsonSchema, schemaId: string): string {\n\t\treturn schema.title ?? schemaId.split(\"/\").pop() ?? schemaId;\n\t}\n\n\t/**\n\t * Remove $comment fields from a schema tree.\n\t * @param schema The schema tree to clean.\n\t */\n\tprivate removeSchemaComments(schema: IJsonSchema): void {\n\t\tdelete schema.$comment;\n\n\t\tfor (const value of Object.values(schema)) {\n\t\t\tif (Is.array(value)) {\n\t\t\t\tfor (const item of value) {\n\t\t\t\t\tif (Is.object<IJsonSchema>(item)) {\n\t\t\t\t\t\tthis.removeSchemaComments(item);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (Is.object<{ [id: string]: unknown }>(value)) {\n\t\t\t\tfor (const nestedValue of Object.values(value)) {\n\t\t\t\t\tif (Is.object<IJsonSchema>(nestedValue)) {\n\t\t\t\t\t\tthis.removeSchemaComments(nestedValue);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Determine whether an input value is a valid TypeScript type identifier.\n\t * An identifier must start with a letter, underscore, or dollar sign and contain only\n\t * alphanumerics, underscores, or dollar signs thereafter.\n\t * @param value The value to inspect.\n\t * @returns True if the value looks like a type name.\n\t * @internal\n\t */\n\tprivate isTypeNameInput(value: string): boolean {\n\t\treturn /^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(value);\n\t}\n}\n"]}
|
|
@@ -9,9 +9,9 @@ import { ObjectTransformer } from "./objectTransformer.js";
|
|
|
9
9
|
*/
|
|
10
10
|
export class UtilityTypeSchemaMapper {
|
|
11
11
|
/**
|
|
12
|
-
* Map Partial<T
|
|
12
|
+
* Map `Partial<T>` to an object schema with no required properties.
|
|
13
13
|
* @param context The generation context.
|
|
14
|
-
* @param typeNode The Partial type reference.
|
|
14
|
+
* @param typeNode The `Partial` type reference.
|
|
15
15
|
* @returns The mapped schema.
|
|
16
16
|
*/
|
|
17
17
|
static mapPartialUtilityType(context, typeNode) {
|
|
@@ -28,9 +28,9 @@ export class UtilityTypeSchemaMapper {
|
|
|
28
28
|
return undefined;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* Map Required<T
|
|
31
|
+
* Map `Required<T>` to an object schema with all properties required.
|
|
32
32
|
* @param context The generation context.
|
|
33
|
-
* @param typeNode The Required type reference.
|
|
33
|
+
* @param typeNode The `Required` type reference.
|
|
34
34
|
* @returns The mapped schema.
|
|
35
35
|
*/
|
|
36
36
|
static mapRequiredUtilityType(context, typeNode) {
|
|
@@ -49,7 +49,7 @@ export class UtilityTypeSchemaMapper {
|
|
|
49
49
|
return undefined;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
* Map Pick<T, K
|
|
52
|
+
* Map `Pick<T, K>` to an object schema with selected keys preserved.
|
|
53
53
|
* @param context The generation context.
|
|
54
54
|
* @param typeNode The Pick type reference.
|
|
55
55
|
* @returns The mapped schema.
|
|
@@ -67,9 +67,9 @@ export class UtilityTypeSchemaMapper {
|
|
|
67
67
|
return undefined;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
* Map Omit<T, K
|
|
70
|
+
* Map `Omit<T, K>` to an object schema with selected keys removed.
|
|
71
71
|
* @param context The generation context.
|
|
72
|
-
* @param typeNode The Omit type reference.
|
|
72
|
+
* @param typeNode The `Omit` type reference.
|
|
73
73
|
* @returns The mapped schema.
|
|
74
74
|
*/
|
|
75
75
|
static mapOmitUtilityType(context, typeNode) {
|
|
@@ -85,9 +85,9 @@ export class UtilityTypeSchemaMapper {
|
|
|
85
85
|
return undefined;
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
88
|
-
* Map Exclude<T, U
|
|
88
|
+
* Map `Exclude<T, U>` to a schema that removes `U` members from `T`.
|
|
89
89
|
* @param context The generation context.
|
|
90
|
-
* @param typeNode The Exclude type reference.
|
|
90
|
+
* @param typeNode The `Exclude` type reference.
|
|
91
91
|
* @returns The mapped schema.
|
|
92
92
|
*/
|
|
93
93
|
static mapExcludeUtilityType(context, typeNode) {
|
|
@@ -125,9 +125,9 @@ export class UtilityTypeSchemaMapper {
|
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
|
-
* Map Extract<T, U
|
|
128
|
+
* Map `Extract<T, U>` to a schema that keeps `U` members from `T`.
|
|
129
129
|
* @param context The generation context.
|
|
130
|
-
* @param typeNode The Extract type reference.
|
|
130
|
+
* @param typeNode The `Extract` type reference.
|
|
131
131
|
* @returns The mapped schema.
|
|
132
132
|
*/
|
|
133
133
|
static mapExtractUtilityType(context, typeNode) {
|
|
@@ -164,9 +164,9 @@ export class UtilityTypeSchemaMapper {
|
|
|
164
164
|
};
|
|
165
165
|
}
|
|
166
166
|
/**
|
|
167
|
-
* Map NonNullable<T
|
|
167
|
+
* Map `NonNullable<T>` by removing `null` and `undefined` branches from `T`.
|
|
168
168
|
* @param context The generation context.
|
|
169
|
-
* @param typeNode The NonNullable type reference.
|
|
169
|
+
* @param typeNode The `NonNullable` type reference.
|
|
170
170
|
* @returns The mapped schema.
|
|
171
171
|
*/
|
|
172
172
|
static mapNonNullableUtilityType(context, typeNode) {
|
|
@@ -202,9 +202,9 @@ export class UtilityTypeSchemaMapper {
|
|
|
202
202
|
};
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
205
|
-
* Map Record<K, V
|
|
205
|
+
* Map `Record<K, V>` to an object schema with key constraints where possible.
|
|
206
206
|
* @param context The generation context.
|
|
207
|
-
* @param typeNode The Record type reference.
|
|
207
|
+
* @param typeNode The `Record` type reference.
|
|
208
208
|
* @returns The mapped schema.
|
|
209
209
|
*/
|
|
210
210
|
static mapRecordUtilityType(context, typeNode) {
|
|
@@ -235,9 +235,9 @@ export class UtilityTypeSchemaMapper {
|
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
237
|
/**
|
|
238
|
-
* Map JsonLdObject utility types using key-removal and optional key-addition rules.
|
|
238
|
+
* Map `JsonLdObject` utility types using key-removal and optional key-addition rules.
|
|
239
239
|
* @param context The generation context.
|
|
240
|
-
* @param typeNode The JsonLdObject utility type reference.
|
|
240
|
+
* @param typeNode The `JsonLdObject` utility type reference.
|
|
241
241
|
* @param options The mapping options for key removal and optional key addition.
|
|
242
242
|
* @param options.keysToRemove The property keys to remove from the base schema.
|
|
243
243
|
* @param options.keyToAdd The optional key to add after removal.
|
|
@@ -275,9 +275,9 @@ export class UtilityTypeSchemaMapper {
|
|
|
275
275
|
return mappedSchema;
|
|
276
276
|
}
|
|
277
277
|
/**
|
|
278
|
-
* Map ObjectOrArray<T
|
|
278
|
+
* Map `ObjectOrArray<T>` to a schema accepting `T` or `T[]`.
|
|
279
279
|
* @param context The generation context.
|
|
280
|
-
* @param typeNode The ObjectOrArray type reference.
|
|
280
|
+
* @param typeNode The `ObjectOrArray` type reference.
|
|
281
281
|
* @returns The mapped schema.
|
|
282
282
|
*/
|
|
283
283
|
static mapObjectOrArrayUtilityType(context, typeNode) {
|
|
@@ -297,9 +297,9 @@ export class UtilityTypeSchemaMapper {
|
|
|
297
297
|
};
|
|
298
298
|
}
|
|
299
299
|
/**
|
|
300
|
-
* Map SingleOccurrenceArray<T, U
|
|
300
|
+
* Map `SingleOccurrenceArray<T, U>` to a non-empty array containing exactly one `U`.
|
|
301
301
|
* @param context The generation context.
|
|
302
|
-
* @param typeNode The SingleOccurrenceArray type reference.
|
|
302
|
+
* @param typeNode The `SingleOccurrenceArray` type reference.
|
|
303
303
|
* @returns The mapped schema.
|
|
304
304
|
*/
|
|
305
305
|
static mapSingleOccurrenceArrayUtilityType(context, typeNode) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilityTypeSchemaMapper.js","sourceRoot":"","sources":["../../../src/utils/utilityTypeSchemaMapper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D;;GAEG;AACH,MAAM,OAAO,uBAAuB;IACnC;;;;;OAKG;IACI,MAAM,CAAC,qBAAqB,CAClC,OAAmC,EACnC,QAA8B;QAE9B,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,iBAAiB,CAAC,8BAA8B,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAC7F,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;;;;;OAKG;IACI,MAAM,CAAC,sBAAsB,CACnC,OAAmC,EACnC,QAA8B;QAE9B,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,CAAC,YAAY,EAAE,CAAC;YACnB,OAAO,SAAS,CA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 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is, JsonHelper, ObjectHelper } from \"@twin.org/core\";\nimport type { IJsonSchema } from \"@twin.org/tools-models\";\nimport * as ts from \"typescript\";\nimport { JsonSchemaBuilder } from \"./jsonSchemaBuilder.js\";\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 * @returns The mapped schema.\n\t */\n\tpublic static mapPartialUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 = JsonSchemaBuilder.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 * @returns The mapped schema.\n\t */\n\tpublic static mapRequiredUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 = JsonSchemaBuilder.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 * @param context The generation context.\n\t * @param typeNode The Pick type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapPickUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\n\t): IJsonSchema | undefined {\n\t\tconst baseTypeNode = typeNode.typeArguments?.[0];\n\t\tconst pickedKeys = JsonSchemaBuilder.extractUtilityTypeKeys(\n\t\t\tcontext,\n\t\t\ttypeNode.typeArguments?.[1]\n\t\t);\n\t\tif (!baseTypeNode || pickedKeys.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst baseSchema = JsonSchemaBuilder.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 * @param context The generation context.\n\t * @param typeNode The Omit type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapOmitUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\n\t): IJsonSchema | undefined {\n\t\tconst baseTypeNode = typeNode.typeArguments?.[0];\n\t\tconst omittedKeys = JsonSchemaBuilder.extractUtilityTypeKeys(\n\t\t\tcontext,\n\t\t\ttypeNode.typeArguments?.[1]\n\t\t);\n\t\tif (!baseTypeNode || omittedKeys.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst baseSchema = JsonSchemaBuilder.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 * @param context The generation context.\n\t * @param typeNode The Exclude type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapExcludeUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 => JsonSchemaBuilder.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 => JsonSchemaBuilder.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 * @param context The generation context.\n\t * @param typeNode The Extract type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapExtractUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 => JsonSchemaBuilder.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 => JsonSchemaBuilder.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 * @param context The generation context.\n\t * @param typeNode The NonNullable type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapNonNullableUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 => JsonSchemaBuilder.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 * @param context The generation context.\n\t * @param typeNode The Record type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapRecordUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 = JsonSchemaBuilder.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 * @param context The generation context.\n\t * @param typeNode The JsonLdObject utility type reference.\n\t * @param options The mapping options for key removal and optional key addition.\n\t * @param options.keysToRemove The property keys to remove from the base schema.\n\t * @param options.keyToAdd The optional key to add after removal.\n\t * @param options.isAddedKeyRequired True when the added key must be required.\n\t * @returns The mapped schema.\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): 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 = JsonSchemaBuilder.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? JsonSchemaBuilder.mapTypeNodeToSchema(context, valueTypeNode)\n\t\t\t: UtilityTypeSchemaMapper.mapJsonLdObjectDefaultSchemaByKey(\n\t\t\t\t\tcontext,\n\t\t\t\t\tbaseSchema,\n\t\t\t\t\toptions.keyToAdd\n\t\t\t\t);\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 * @param context The generation context.\n\t * @param typeNode The ObjectOrArray type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapObjectOrArrayUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 = JsonSchemaBuilder.mapTypeNodeToSchema(context, baseTypeNode);\n\t\tif (!itemSchema) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst scalarSchemas =\n\t\t\tIs.array(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 * @param context The generation context.\n\t * @param typeNode The SingleOccurrenceArray type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapSingleOccurrenceArrayUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 = JsonSchemaBuilder.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 = JsonSchemaBuilder.mapTypeNodeToSchema(\n\t\t\tcontext,\n\t\t\tsingleOccurrenceTypeNode\n\t\t);\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 * @param typeNode The type node to inspect.\n\t * @returns True if the node represents null or undefined; otherwise false.\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 * @param keyTypeNode The Record key type argument to inspect.\n\t * @returns The extracted literal keys.\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 * @param context The generation context.\n\t * @param baseSchema The base object schema being transformed.\n\t * @param keyToAdd The key to add when no explicit value type argument is provided.\n\t * @returns The resolved default schema for the added key.\n\t */\n\tprivate static mapJsonLdObjectDefaultSchemaByKey(\n\t\tcontext: ITypeScriptToSchemaContext,\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(\n\t\t\t\tcontext,\n\t\t\t\tbaseSchema\n\t\t\t);\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 * @param baseSchema The base object schema being transformed.\n\t * @returns The default id schema.\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 * @param baseSchema The base object schema being transformed.\n\t * @returns The default type schema.\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 * @param context The generation context.\n\t * @param baseSchema The base object schema being transformed.\n\t * @returns The default context schema.\n\t */\n\tprivate static mapJsonLdObjectWithContextDefaultContextSchema(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\tbaseSchema: IJsonSchema\n\t): IJsonSchema {\n\t\tconst existingContextSchema = ObjectTransformer.resolvePropertySchemaFromObjectSchema(\n\t\t\tbaseSchema,\n\t\t\t\"@context\"\n\t\t);\n\n\t\tif (existingContextSchema) {\n\t\t\treturn existingContextSchema;\n\t\t}\n\n\t\tconst mappedContextReference = JsonSchemaBuilder.resolveReferenceMappingTarget(\n\t\t\tcontext,\n\t\t\t\"\",\n\t\t\t\"JsonLdContextDefinitionRoot\"\n\t\t);\n\t\tif (mappedContextReference?.schemaId) {\n\t\t\treturn {\n\t\t\t\t$ref: mappedContextReference.schemaId\n\t\t\t};\n\t\t}\n\n\t\t// Look up JsonLdContextDefinitionRoot from the cache to get its correct namespace\n\t\tconst contextDefRootSchema = Object.entries(context.schemas)\n\t\t\t.filter(([packageName]) => packageName !== context.packageName)\n\t\t\t.flatMap(([, packageSchemas]) => Object.values(packageSchemas ?? {}))\n\t\t\t.find(schema => schema?.$id?.endsWith(\"JsonLdContextDefinitionRoot\"));\n\n\t\tif (contextDefRootSchema?.$id) {\n\t\t\treturn {\n\t\t\t\t$ref: contextDefRootSchema.$id\n\t\t\t};\n\t\t}\n\n\t\t// Fallback: return a reference using a common JSON-LD namespace\n\t\treturn {\n\t\t\t$ref: \"https://schema.twindev.org/json-ld/JsonLdContextDefinitionRoot\"\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 * @param baseSchema The base object schema being transformed.\n\t * @param firstKey The first property key to check.\n\t * @param secondKey The second property key to check.\n\t * @param fallbackSchema The fallback schema when neither key is present.\n\t * @returns The resolved schema.\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\treturn firstSchema ?? secondSchema ?? fallbackSchema;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utilityTypeSchemaMapper.js","sourceRoot":"","sources":["../../../src/utils/utilityTypeSchemaMapper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D;;GAEG;AACH,MAAM,OAAO,uBAAuB;IACnC;;;;;OAKG;IACI,MAAM,CAAC,qBAAqB,CAClC,OAAmC,EACnC,QAA8B;QAE9B,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,iBAAiB,CAAC,8BAA8B,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAC7F,IAAI,YAAY,EAAE,CAAC;YAClB,MAAM,aAAa,GAAG,iBAAi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C;QAEF,IAAI,WAAW,IAAI,YAAY,EAAE,CAAC;YACjC,IAAI,UAAU,CAAC,YAAY,CAAC,WAAW,CAAC,KAAK,UAAU,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,CAAC;gBACpF,OAAO,WAAW,CAAC;YACpB,CAAC;YAED,OAAO;gBACN,KAAK,EAAE,CAAC,WAAW,EAAE,YAAY,CAAC;aAClC,CAAC;QACH,CAAC;QAED,OAAO,WAAW,IAAI,YAAY,IAAI,cAAc,CAAC;IACtD,CAAC;CACD","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is, JsonHelper, ObjectHelper } from \"@twin.org/core\";\nimport type { IJsonSchema } from \"@twin.org/tools-models\";\nimport * as ts from \"typescript\";\nimport { JsonSchemaBuilder } from \"./jsonSchemaBuilder.js\";\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 * @returns The mapped schema.\n\t */\n\tpublic static mapPartialUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 = JsonSchemaBuilder.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 * @returns The mapped schema.\n\t */\n\tpublic static mapRequiredUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 = JsonSchemaBuilder.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 * @param context The generation context.\n\t * @param typeNode The Pick type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapPickUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\n\t): IJsonSchema | undefined {\n\t\tconst baseTypeNode = typeNode.typeArguments?.[0];\n\t\tconst pickedKeys = JsonSchemaBuilder.extractUtilityTypeKeys(\n\t\t\tcontext,\n\t\t\ttypeNode.typeArguments?.[1]\n\t\t);\n\t\tif (!baseTypeNode || pickedKeys.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst baseSchema = JsonSchemaBuilder.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 * @param context The generation context.\n\t * @param typeNode The `Omit` type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapOmitUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\n\t): IJsonSchema | undefined {\n\t\tconst baseTypeNode = typeNode.typeArguments?.[0];\n\t\tconst omittedKeys = JsonSchemaBuilder.extractUtilityTypeKeys(\n\t\t\tcontext,\n\t\t\ttypeNode.typeArguments?.[1]\n\t\t);\n\t\tif (!baseTypeNode || omittedKeys.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst baseSchema = JsonSchemaBuilder.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 * @param context The generation context.\n\t * @param typeNode The `Exclude` type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapExcludeUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 => JsonSchemaBuilder.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 => JsonSchemaBuilder.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 * @param context The generation context.\n\t * @param typeNode The `Extract` type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapExtractUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 => JsonSchemaBuilder.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 => JsonSchemaBuilder.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 * @param context The generation context.\n\t * @param typeNode The `NonNullable` type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapNonNullableUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 => JsonSchemaBuilder.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 * @param context The generation context.\n\t * @param typeNode The `Record` type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapRecordUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 = JsonSchemaBuilder.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 * @param context The generation context.\n\t * @param typeNode The `JsonLdObject` utility type reference.\n\t * @param options The mapping options for key removal and optional key addition.\n\t * @param options.keysToRemove The property keys to remove from the base schema.\n\t * @param options.keyToAdd The optional key to add after removal.\n\t * @param options.isAddedKeyRequired True when the added key must be required.\n\t * @returns The mapped schema.\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): 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 = JsonSchemaBuilder.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? JsonSchemaBuilder.mapTypeNodeToSchema(context, valueTypeNode)\n\t\t\t: UtilityTypeSchemaMapper.mapJsonLdObjectDefaultSchemaByKey(\n\t\t\t\t\tcontext,\n\t\t\t\t\tbaseSchema,\n\t\t\t\t\toptions.keyToAdd\n\t\t\t\t);\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 * @param context The generation context.\n\t * @param typeNode The `ObjectOrArray` type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapObjectOrArrayUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 = JsonSchemaBuilder.mapTypeNodeToSchema(context, baseTypeNode);\n\t\tif (!itemSchema) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst scalarSchemas =\n\t\t\tIs.array(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 * @param context The generation context.\n\t * @param typeNode The `SingleOccurrenceArray` type reference.\n\t * @returns The mapped schema.\n\t */\n\tpublic static mapSingleOccurrenceArrayUtilityType(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.TypeReferenceNode\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 = JsonSchemaBuilder.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 = JsonSchemaBuilder.mapTypeNodeToSchema(\n\t\t\tcontext,\n\t\t\tsingleOccurrenceTypeNode\n\t\t);\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 * @param typeNode The type node to inspect.\n\t * @returns True if the node represents null or undefined; otherwise false.\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 * @param keyTypeNode The Record key type argument to inspect.\n\t * @returns The extracted literal keys.\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 * @param context The generation context.\n\t * @param baseSchema The base object schema being transformed.\n\t * @param keyToAdd The key to add when no explicit value type argument is provided.\n\t * @returns The resolved default schema for the added key.\n\t */\n\tprivate static mapJsonLdObjectDefaultSchemaByKey(\n\t\tcontext: ITypeScriptToSchemaContext,\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(\n\t\t\t\tcontext,\n\t\t\t\tbaseSchema\n\t\t\t);\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 * @param baseSchema The base object schema being transformed.\n\t * @returns The default id schema.\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 * @param baseSchema The base object schema being transformed.\n\t * @returns The default type schema.\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 * @param context The generation context.\n\t * @param baseSchema The base object schema being transformed.\n\t * @returns The default context schema.\n\t */\n\tprivate static mapJsonLdObjectWithContextDefaultContextSchema(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\tbaseSchema: IJsonSchema\n\t): IJsonSchema {\n\t\tconst existingContextSchema = ObjectTransformer.resolvePropertySchemaFromObjectSchema(\n\t\t\tbaseSchema,\n\t\t\t\"@context\"\n\t\t);\n\n\t\tif (existingContextSchema) {\n\t\t\treturn existingContextSchema;\n\t\t}\n\n\t\tconst mappedContextReference = JsonSchemaBuilder.resolveReferenceMappingTarget(\n\t\t\tcontext,\n\t\t\t\"\",\n\t\t\t\"JsonLdContextDefinitionRoot\"\n\t\t);\n\t\tif (mappedContextReference?.schemaId) {\n\t\t\treturn {\n\t\t\t\t$ref: mappedContextReference.schemaId\n\t\t\t};\n\t\t}\n\n\t\t// Look up JsonLdContextDefinitionRoot from the cache to get its correct namespace\n\t\tconst contextDefRootSchema = Object.entries(context.schemas)\n\t\t\t.filter(([packageName]) => packageName !== context.packageName)\n\t\t\t.flatMap(([, packageSchemas]) => Object.values(packageSchemas ?? {}))\n\t\t\t.find(schema => schema?.$id?.endsWith(\"JsonLdContextDefinitionRoot\"));\n\n\t\tif (contextDefRootSchema?.$id) {\n\t\t\treturn {\n\t\t\t\t$ref: contextDefRootSchema.$id\n\t\t\t};\n\t\t}\n\n\t\t// Fallback: return a reference using a common JSON-LD namespace\n\t\treturn {\n\t\t\t$ref: \"https://schema.twindev.org/json-ld/JsonLdContextDefinitionRoot\"\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 * @param baseSchema The base object schema being transformed.\n\t * @param firstKey The first property key to check.\n\t * @param secondKey The second property key to check.\n\t * @param fallbackSchema The fallback schema when neither key is present.\n\t * @returns The resolved schema.\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\treturn firstSchema ?? secondSchema ?? fallbackSchema;\n\t}\n}\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
export * from "./models/embeddedSchemaMode.js";
|
|
1
2
|
export * from "./models/ITypeScriptToSchemaContext.js";
|
|
2
3
|
export * from "./models/ITypeScriptToSchemaDiagnostics.js";
|
|
3
4
|
export * from "./models/ITypeScriptToSchemaOptions.js";
|
|
5
|
+
export * from "./utils/constants.js";
|
|
4
6
|
export * from "./utils/diagnosticReporter.js";
|
|
5
7
|
export * from "./utils/disallowedTypeGuard.js";
|
|
6
8
|
export * from "./utils/enum.js";
|
|
@@ -8,13 +10,12 @@ export * from "./utils/fileUtils.js";
|
|
|
8
10
|
export * from "./utils/importTypeQuerySchemaResolver.js";
|
|
9
11
|
export * from "./utils/indexSignaturePatternResolver.js";
|
|
10
12
|
export * from "./utils/intersectionSchemaMerger.js";
|
|
13
|
+
export * from "./utils/jsDoc.js";
|
|
11
14
|
export * from "./utils/jsonSchemaBuilder.js";
|
|
12
|
-
export * from "./utils/constants.js";
|
|
13
15
|
export * from "./utils/mappedTypeSchemaResolver.js";
|
|
14
16
|
export * from "./utils/objectTransformer.js";
|
|
15
17
|
export * from "./utils/regEx.js";
|
|
16
18
|
export * from "./utils/resolver.js";
|
|
17
19
|
export * from "./utils/templateLiteralPatternBuilder.js";
|
|
18
20
|
export * from "./utils/typeScriptToSchema.js";
|
|
19
|
-
export * from "./utils/jsDoc.js";
|
|
20
21
|
export * from "./utils/utilityTypeSchemaMapper.js";
|