@twin.org/tools-core 0.0.4-next.2 → 0.9.0-next.1

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.
Files changed (33) hide show
  1. package/dist/es/utils/disallowedTypeGuard.js +1 -0
  2. package/dist/es/utils/disallowedTypeGuard.js.map +1 -1
  3. package/dist/es/utils/fileUtils.js +4 -4
  4. package/dist/es/utils/fileUtils.js.map +1 -1
  5. package/dist/es/utils/importTypeQuerySchemaResolver.js +8 -0
  6. package/dist/es/utils/importTypeQuerySchemaResolver.js.map +1 -1
  7. package/dist/es/utils/intersectionSchemaMerger.js +1 -0
  8. package/dist/es/utils/intersectionSchemaMerger.js.map +1 -1
  9. package/dist/es/utils/jsonSchemaBuilder.js +3 -0
  10. package/dist/es/utils/jsonSchemaBuilder.js.map +1 -1
  11. package/dist/es/utils/mappedTypeSchemaResolver.js +1 -0
  12. package/dist/es/utils/mappedTypeSchemaResolver.js.map +1 -1
  13. package/dist/es/utils/objectTransformer.js +27 -0
  14. package/dist/es/utils/objectTransformer.js.map +1 -1
  15. package/dist/es/utils/regEx.js +1 -1
  16. package/dist/es/utils/regEx.js.map +1 -1
  17. package/dist/es/utils/typeScriptToSchema.js +9 -0
  18. package/dist/es/utils/typeScriptToSchema.js.map +1 -1
  19. package/dist/es/utils/utilityTypeSchemaMapper.js +33 -0
  20. package/dist/es/utils/utilityTypeSchemaMapper.js.map +1 -1
  21. package/dist/types/utils/disallowedTypeGuard.d.ts +0 -4
  22. package/dist/types/utils/fileUtils.d.ts +4 -4
  23. package/dist/types/utils/importTypeQuerySchemaResolver.d.ts +0 -56
  24. package/dist/types/utils/jsonSchemaBuilder.d.ts +0 -4
  25. package/dist/types/utils/mappedTypeSchemaResolver.d.ts +0 -7
  26. package/dist/types/utils/objectTransformer.d.ts +8 -0
  27. package/dist/types/utils/typeScriptToSchema.d.ts +0 -61
  28. package/dist/types/utils/utilityTypeSchemaMapper.d.ts +9 -48
  29. package/docs/changelog.md +62 -0
  30. package/docs/reference/classes/FileUtils.md +4 -4
  31. package/docs/reference/classes/ObjectTransformer.md +29 -0
  32. package/docs/reference/classes/UtilityTypeSchemaMapper.md +30 -0
  33. package/package.json +4 -4
@@ -246,6 +246,7 @@ export class MappedTypeSchemaResolver {
246
246
  * @param intrinsicName The intrinsic helper name.
247
247
  * @param value The input key value.
248
248
  * @returns The remapped key value.
249
+ * @internal
249
250
  */
250
251
  static applyIntrinsicMappedTypeKeyRemap(intrinsicName, value) {
251
252
  switch (intrinsicName) {
@@ -1 +1 @@
1
- {"version":3,"file":"mappedTypeSchemaResolver.js","sourceRoot":"","sources":["../../../src/utils/mappedTypeSchemaResolver.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D;;GAEG;AACH,MAAM,OAAO,wBAAwB;IACpC;;;;;;;OAOG;IACI,MAAM,CAAC,gCAAgC,CAC7C,OAAmC,EACnC,QAA2B,EAC3B,UAAoB,EACpB,uBAA+B;QAE/B,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACxB,OAAO,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QAC3E,CAAC;QAED,MAAM,aAAa,GAA+C,EAAE,CAAC;QAErE,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACpC,MAAM,SAAS,GAAG,wBAAwB,CAAC,4BAA4B,CACtE,OAAO,EACP,QAAQ,CAAC,QAAQ,EACjB,SAAS,EACT,uBAAuB,CACvB,CAAC;YACF,IAAI,SAAS,KAAK,IAAI,IAAI,CAAC,EAAE,CAAC,WAAW,CA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AAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;YAChF,KAAK,cAAc;gBAClB,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;YAChF;gBACC,OAAO,SAAS,CAAC;QACnB,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is, JsonHelper } from \"@twin.org/core\";\nimport type { IJsonSchema } from \"@twin.org/tools-models\";\nimport * as ts from \"typescript\";\nimport { JsonSchemaBuilder } from \"./jsonSchemaBuilder.js\";\nimport type { ITypeScriptToSchemaContext } from \"../models/ITypeScriptToSchemaContext.js\";\n\n/**\n * Static mapped-type schema transformation helpers.\n */\nexport class MappedTypeSchemaResolver {\n\t/**\n\t * Resolve mapped type output keys, including remapped key names via `as`.\n\t * @param context The generation context.\n\t * @param typeNode The mapped type node.\n\t * @param mappedKeys The resolved source keys from the mapped type constraint.\n\t * @param mappedTypeParameterName The mapped type parameter identifier.\n\t * @returns The resolved source-to-output mapped key entries.\n\t */\n\tpublic static resolveMappedTypePropertyEntries(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.MappedTypeNode,\n\t\tmappedKeys: string[],\n\t\tmappedTypeParameterName: string\n\t): { sourceKey: string; mappedKey: string }[] | undefined {\n\t\tif (!typeNode.nameType) {\n\t\t\treturn mappedKeys.map(mappedKey => ({ sourceKey: mappedKey, mappedKey }));\n\t\t}\n\n\t\tconst mappedEntries: { sourceKey: string; mappedKey: string }[] = [];\n\n\t\tfor (const sourceKey of mappedKeys) {\n\t\t\tconst mappedKey = MappedTypeSchemaResolver.resolveMappedTypeRemappedKey(\n\t\t\t\tcontext,\n\t\t\t\ttypeNode.nameType,\n\t\t\t\tsourceKey,\n\t\t\t\tmappedTypeParameterName\n\t\t\t);\n\t\t\tif (mappedKey !== null && !Is.stringValue(mappedKey)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif (Is.stringValue(mappedKey)) {\n\t\t\t\tmappedEntries.push({ sourceKey, mappedKey });\n\t\t\t}\n\t\t}\n\n\t\treturn mappedEntries;\n\t}\n\n\t/**\n\t * Resolve a remapped mapped-type key expression for a concrete source key.\n\t * @param context The generation context.\n\t * @param nameTypeNode The mapped type name remapping expression node.\n\t * @param sourceKey The concrete source key currently being evaluated.\n\t * @param mappedTypeParameterName The mapped type parameter identifier.\n\t * @returns The remapped key, null when excluded via never, or undefined when unresolved.\n\t */\n\tpublic static resolveMappedTypeRemappedKey(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\tnameTypeNode: ts.TypeNode,\n\t\tsourceKey: string,\n\t\tmappedTypeParameterName: string\n\t): string | null | undefined {\n\t\tif (ts.isParenthesizedTypeNode(nameTypeNode)) {\n\t\t\treturn MappedTypeSchemaResolver.resolveMappedTypeRemappedKey(\n\t\t\t\tcontext,\n\t\t\t\tnameTypeNode.type,\n\t\t\t\tsourceKey,\n\t\t\t\tmappedTypeParameterName\n\t\t\t);\n\t\t}\n\n\t\tif (nameTypeNode.kind === ts.SyntaxKind.NeverKeyword) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (JsonSchemaBuilder.isMappedTypeParameterReference(nameTypeNode, mappedTypeParameterName)) {\n\t\t\treturn sourceKey;\n\t\t}\n\n\t\tif (ts.isLiteralTypeNode(nameTypeNode)) {\n\t\t\tif (ts.isStringLiteral(nameTypeNode.literal) || ts.isNumericLiteral(nameTypeNode.literal)) {\n\t\t\t\treturn nameTypeNode.literal.text;\n\t\t\t}\n\t\t\tif (nameTypeNode.literal.kind === ts.SyntaxKind.TrueKeyword) {\n\t\t\t\treturn \"true\";\n\t\t\t}\n\t\t\tif (nameTypeNode.literal.kind === ts.SyntaxKind.FalseKeyword) {\n\t\t\t\treturn \"false\";\n\t\t\t}\n\t\t}\n\n\t\tif (ts.isIntersectionTypeNode(nameTypeNode)) {\n\t\t\tconst hasMappedKeyReference = nameTypeNode.types.some(type =>\n\t\t\t\tJsonSchemaBuilder.isMappedTypeParameterReference(type, mappedTypeParameterName)\n\t\t\t);\n\t\t\tconst hasStringKeyword = nameTypeNode.types.some(\n\t\t\t\ttype => type.kind === ts.SyntaxKind.StringKeyword\n\t\t\t);\n\t\t\tif (hasMappedKeyReference && hasStringKeyword) {\n\t\t\t\treturn sourceKey;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (ts.isTemplateLiteralTypeNode(nameTypeNode)) {\n\t\t\tlet remappedKey = nameTypeNode.head.text;\n\t\t\tfor (const span of nameTypeNode.templateSpans) {\n\t\t\t\tconst spanValue = MappedTypeSchemaResolver.resolveMappedTypeRemappedKey(\n\t\t\t\t\tcontext,\n\t\t\t\t\tspan.type,\n\t\t\t\t\tsourceKey,\n\t\t\t\t\tmappedTypeParameterName\n\t\t\t\t);\n\t\t\t\tif (!Is.stringValue(spanValue)) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\tremappedKey += `${spanValue}${span.literal.text}`;\n\t\t\t}\n\n\t\t\treturn remappedKey;\n\t\t}\n\n\t\tif (ts.isTypeReferenceNode(nameTypeNode) && ts.isIdentifier(nameTypeNode.typeName)) {\n\t\t\tconst intrinsicName = nameTypeNode.typeName.text;\n\t\t\tif (nameTypeNode.typeArguments?.length === 1) {\n\t\t\t\tconst intrinsicInput = MappedTypeSchemaResolver.resolveMappedTypeRemappedKey(\n\t\t\t\t\tcontext,\n\t\t\t\t\tnameTypeNode.typeArguments[0],\n\t\t\t\t\tsourceKey,\n\t\t\t\t\tmappedTypeParameterName\n\t\t\t\t);\n\t\t\t\tif (!Is.stringValue(intrinsicInput)) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\treturn MappedTypeSchemaResolver.applyIntrinsicMappedTypeKeyRemap(\n\t\t\t\t\tintrinsicName,\n\t\t\t\t\tintrinsicInput\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (ts.isConditionalTypeNode(nameTypeNode)) {\n\t\t\tif (\n\t\t\t\t!JsonSchemaBuilder.isMappedTypeParameterReference(\n\t\t\t\t\tnameTypeNode.checkType,\n\t\t\t\t\tmappedTypeParameterName\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst satisfies = MappedTypeSchemaResolver.evaluateMappedKeyExtendsCondition(\n\t\t\t\tcontext,\n\t\t\t\tsourceKey,\n\t\t\t\tnameTypeNode.extendsType\n\t\t\t);\n\t\t\tif (satisfies === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst branchType = satisfies ? nameTypeNode.trueType : nameTypeNode.falseType;\n\t\t\treturn MappedTypeSchemaResolver.resolveMappedTypeRemappedKey(\n\t\t\t\tcontext,\n\t\t\t\tbranchType,\n\t\t\t\tsourceKey,\n\t\t\t\tmappedTypeParameterName\n\t\t\t);\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Evaluate whether a concrete mapped key satisfies an `extends` condition.\n\t * @param context The generation context.\n\t * @param sourceKey The concrete source key being evaluated.\n\t * @param extendsTypeNode The extends condition type node.\n\t * @returns True when the key satisfies the condition, false when it does not, otherwise undefined.\n\t */\n\tpublic static evaluateMappedKeyExtendsCondition(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\tsourceKey: string,\n\t\textendsTypeNode: ts.TypeNode\n\t): boolean | undefined {\n\t\tif (ts.isParenthesizedTypeNode(extendsTypeNode)) {\n\t\t\treturn MappedTypeSchemaResolver.evaluateMappedKeyExtendsCondition(\n\t\t\t\tcontext,\n\t\t\t\tsourceKey,\n\t\t\t\textendsTypeNode.type\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\textendsTypeNode.kind === ts.SyntaxKind.StringKeyword ||\n\t\t\textendsTypeNode.kind === ts.SyntaxKind.AnyKeyword ||\n\t\t\textendsTypeNode.kind === ts.SyntaxKind.UnknownKeyword\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (\n\t\t\textendsTypeNode.kind === ts.SyntaxKind.NeverKeyword ||\n\t\t\textendsTypeNode.kind === ts.SyntaxKind.NumberKeyword ||\n\t\t\textendsTypeNode.kind === ts.SyntaxKind.BooleanKeyword ||\n\t\t\textendsTypeNode.kind === ts.SyntaxKind.ObjectKeyword\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (ts.isLiteralTypeNode(extendsTypeNode)) {\n\t\t\tif (\n\t\t\t\tts.isStringLiteral(extendsTypeNode.literal) ||\n\t\t\t\tts.isNumericLiteral(extendsTypeNode.literal)\n\t\t\t) {\n\t\t\t\treturn sourceKey === extendsTypeNode.literal.text;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\tif (ts.isUnionTypeNode(extendsTypeNode)) {\n\t\t\tlet hasUndetermined = false;\n\t\t\tfor (const memberType of extendsTypeNode.types) {\n\t\t\t\tconst result = MappedTypeSchemaResolver.evaluateMappedKeyExtendsCondition(\n\t\t\t\t\tcontext,\n\t\t\t\t\tsourceKey,\n\t\t\t\t\tmemberType\n\t\t\t\t);\n\t\t\t\tif (result === true) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tif (result === undefined) {\n\t\t\t\t\thasUndetermined = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn hasUndetermined ? undefined : false;\n\t\t}\n\n\t\tif (\n\t\t\tts.isTypeOperatorNode(extendsTypeNode) &&\n\t\t\textendsTypeNode.operator === ts.SyntaxKind.KeyOfKeyword\n\t\t) {\n\t\t\tconst keys = JsonSchemaBuilder.extractKeyofTypeKeys(context, extendsTypeNode.type);\n\t\t\tif (keys.length > 0) {\n\t\t\t\treturn keys.includes(sourceKey);\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (ts.isTypeReferenceNode(extendsTypeNode)) {\n\t\t\tconst resolved = JsonSchemaBuilder.resolveReferencedTypeNodeFromLocalDeclaration(\n\t\t\t\tcontext,\n\t\t\t\textendsTypeNode\n\t\t\t);\n\t\t\tif (resolved) {\n\t\t\t\treturn MappedTypeSchemaResolver.evaluateMappedKeyExtendsCondition(\n\t\t\t\t\tcontext,\n\t\t\t\t\tsourceKey,\n\t\t\t\t\tresolved\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Build a conservative fallback schema for mapped types whose key remapping cannot be resolved.\n\t * @param context The generation context.\n\t * @param typeNode The mapped type node.\n\t * @param mappedKeys The resolved source keys from the mapped type constraint.\n\t * @param mappedTypeParameterName The mapped type parameter identifier.\n\t * @param sourceObjectSchema The optional source object schema for property lookups.\n\t * @returns The fallback mapped type schema.\n\t */\n\tpublic static buildMappedTypeFallbackSchema(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.MappedTypeNode,\n\t\tmappedKeys: string[],\n\t\tmappedTypeParameterName: string,\n\t\tsourceObjectSchema?: IJsonSchema\n\t): IJsonSchema {\n\t\tconst additionalProperties =\n\t\t\tMappedTypeSchemaResolver.buildMappedTypeFallbackAdditionalProperties(\n\t\t\t\tcontext,\n\t\t\t\ttypeNode,\n\t\t\t\tmappedKeys,\n\t\t\t\tmappedTypeParameterName,\n\t\t\t\tsourceObjectSchema\n\t\t\t);\n\n\t\treturn {\n\t\t\ttype: \"object\",\n\t\t\tadditionalProperties: additionalProperties ?? {}\n\t\t};\n\t}\n\n\t/**\n\t * Build fallback additionalProperties for unresolved mapped key remapping.\n\t * @param context The generation context.\n\t * @param typeNode The mapped type node.\n\t * @param mappedKeys The resolved source keys from the mapped type constraint.\n\t * @param mappedTypeParameterName The mapped type parameter identifier.\n\t * @param sourceObjectSchema The optional source object schema for property lookups.\n\t * @returns The fallback additionalProperties schema.\n\t */\n\tpublic static buildMappedTypeFallbackAdditionalProperties(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.MappedTypeNode,\n\t\tmappedKeys: string[],\n\t\tmappedTypeParameterName: string,\n\t\tsourceObjectSchema?: IJsonSchema\n\t): IJsonSchema | undefined {\n\t\tconst resolvedPropertySchemas = mappedKeys\n\t\t\t.map(mappedKey =>\n\t\t\t\tJsonSchemaBuilder.mapMappedTypePropertySchema(\n\t\t\t\t\tcontext,\n\t\t\t\t\ttypeNode,\n\t\t\t\t\tmappedKey,\n\t\t\t\t\tmappedTypeParameterName,\n\t\t\t\t\tsourceObjectSchema\n\t\t\t\t)\n\t\t\t)\n\t\t\t.filter((mappedType): mappedType is IJsonSchema => mappedType !== undefined);\n\n\t\tif (resolvedPropertySchemas.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst uniqueSchemas = resolvedPropertySchemas.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 * Merge mapped property schemas when multiple source keys remap to the same output key.\n\t * @param existingSchema The existing schema already assigned to the mapped key.\n\t * @param nextSchema The next schema to merge into the mapped key.\n\t * @returns The merged schema.\n\t */\n\tpublic static mergeMappedTypePropertySchemas(\n\t\texistingSchema: IJsonSchema,\n\t\tnextSchema: IJsonSchema\n\t): IJsonSchema {\n\t\tconst schemaVariants = [\n\t\t\t...(existingSchema.anyOf ?? [existingSchema]),\n\t\t\t...(nextSchema.anyOf ?? [nextSchema])\n\t\t];\n\n\t\tconst uniqueSchemas = schemaVariants.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 * Resolve required remapped keys from the source object's required key set.\n\t * @param mappedEntries The source-to-output mapped key entries.\n\t * @param sourceObjectSchema The source object schema containing required keys.\n\t * @returns The required output keys.\n\t */\n\tpublic static resolveMappedTypeSourceRequiredPropertyKeys(\n\t\tmappedEntries: { sourceKey: string; mappedKey: string }[],\n\t\tsourceObjectSchema: IJsonSchema\n\t): string[] | undefined {\n\t\tif (!Is.array<string>(sourceObjectSchema.required)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst sourceRequiredKeys = new Set(sourceObjectSchema.required);\n\t\tconst remappedRequiredKeys = mappedEntries\n\t\t\t.filter(mappedEntry => sourceRequiredKeys.has(mappedEntry.sourceKey))\n\t\t\t.map(mappedEntry => mappedEntry.mappedKey);\n\n\t\treturn [...new Set(remappedRequiredKeys)];\n\t}\n\n\t/**\n\t * Apply TypeScript intrinsic string remapping helpers to a key.\n\t * @param intrinsicName The intrinsic helper name.\n\t * @param value The input key value.\n\t * @returns The remapped key value.\n\t */\n\tprivate static applyIntrinsicMappedTypeKeyRemap(\n\t\tintrinsicName: string,\n\t\tvalue: string\n\t): string | undefined {\n\t\tswitch (intrinsicName) {\n\t\t\tcase \"Uppercase\":\n\t\t\t\treturn value.toUpperCase();\n\t\t\tcase \"Lowercase\":\n\t\t\t\treturn value.toLowerCase();\n\t\t\tcase \"Capitalize\":\n\t\t\t\treturn value.length > 0 ? `${value[0].toUpperCase()}${value.slice(1)}` : value;\n\t\t\tcase \"Uncapitalize\":\n\t\t\t\treturn value.length > 0 ? `${value[0].toLowerCase()}${value.slice(1)}` : value;\n\t\t\tdefault:\n\t\t\t\treturn undefined;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"mappedTypeSchemaResolver.js","sourceRoot":"","sources":["../../../src/utils/mappedTypeSchemaResolver.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D;;GAEG;AACH,MAAM,OAAO,wBAAwB;IACpC;;;;;;;OAOG;IACI,MAAM,CAAC,gCAAgC,CAC7C,OAAmC,EACnC,QAA2B,EAC3B,UAAoB,EACpB,uBAA+B;QAE/B,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACxB,OAAO,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QAC3E,CAAC;QAED,MAAM,aAAa,GAA+C,EAAE,CAAC;QAErE,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACpC,MAAM,SAAS,GAAG,wBAAwB,CAAC,4BAA4B,CACtE,OAAO,EACP,QAAQ,CAAC,QAAQ,EACjB,SAAS,EACT,uBAAuB,CACvB,CAAC;YACF,IAAI,SAAS,KAAK,IAAI,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;gBACtD,OAAO,SAAS,CAAC;YAClB,CAAC;YACD,IAAI,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC/B,aAAa,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;YAC9C,CAAC;QACF,CAAC;QAED,OAAO,aAAa,CAAC;IACtB,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,4B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,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;YAChF;gBACC,OAAO,SAAS,CAAC;QACnB,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is, JsonHelper } from \"@twin.org/core\";\nimport type { IJsonSchema } from \"@twin.org/tools-models\";\nimport * as ts from \"typescript\";\nimport { JsonSchemaBuilder } from \"./jsonSchemaBuilder.js\";\nimport type { ITypeScriptToSchemaContext } from \"../models/ITypeScriptToSchemaContext.js\";\n\n/**\n * Static mapped-type schema transformation helpers.\n */\nexport class MappedTypeSchemaResolver {\n\t/**\n\t * Resolve mapped type output keys, including remapped key names via `as`.\n\t * @param context The generation context.\n\t * @param typeNode The mapped type node.\n\t * @param mappedKeys The resolved source keys from the mapped type constraint.\n\t * @param mappedTypeParameterName The mapped type parameter identifier.\n\t * @returns The resolved source-to-output mapped key entries.\n\t */\n\tpublic static resolveMappedTypePropertyEntries(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.MappedTypeNode,\n\t\tmappedKeys: string[],\n\t\tmappedTypeParameterName: string\n\t): { sourceKey: string; mappedKey: string }[] | undefined {\n\t\tif (!typeNode.nameType) {\n\t\t\treturn mappedKeys.map(mappedKey => ({ sourceKey: mappedKey, mappedKey }));\n\t\t}\n\n\t\tconst mappedEntries: { sourceKey: string; mappedKey: string }[] = [];\n\n\t\tfor (const sourceKey of mappedKeys) {\n\t\t\tconst mappedKey = MappedTypeSchemaResolver.resolveMappedTypeRemappedKey(\n\t\t\t\tcontext,\n\t\t\t\ttypeNode.nameType,\n\t\t\t\tsourceKey,\n\t\t\t\tmappedTypeParameterName\n\t\t\t);\n\t\t\tif (mappedKey !== null && !Is.stringValue(mappedKey)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif (Is.stringValue(mappedKey)) {\n\t\t\t\tmappedEntries.push({ sourceKey, mappedKey });\n\t\t\t}\n\t\t}\n\n\t\treturn mappedEntries;\n\t}\n\n\t/**\n\t * Resolve a remapped mapped-type key expression for a concrete source key.\n\t * @param context The generation context.\n\t * @param nameTypeNode The mapped type name remapping expression node.\n\t * @param sourceKey The concrete source key currently being evaluated.\n\t * @param mappedTypeParameterName The mapped type parameter identifier.\n\t * @returns The remapped key, null when excluded via never, or undefined when unresolved.\n\t */\n\tpublic static resolveMappedTypeRemappedKey(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\tnameTypeNode: ts.TypeNode,\n\t\tsourceKey: string,\n\t\tmappedTypeParameterName: string\n\t): string | null | undefined {\n\t\tif (ts.isParenthesizedTypeNode(nameTypeNode)) {\n\t\t\treturn MappedTypeSchemaResolver.resolveMappedTypeRemappedKey(\n\t\t\t\tcontext,\n\t\t\t\tnameTypeNode.type,\n\t\t\t\tsourceKey,\n\t\t\t\tmappedTypeParameterName\n\t\t\t);\n\t\t}\n\n\t\tif (nameTypeNode.kind === ts.SyntaxKind.NeverKeyword) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (JsonSchemaBuilder.isMappedTypeParameterReference(nameTypeNode, mappedTypeParameterName)) {\n\t\t\treturn sourceKey;\n\t\t}\n\n\t\tif (ts.isLiteralTypeNode(nameTypeNode)) {\n\t\t\tif (ts.isStringLiteral(nameTypeNode.literal) || ts.isNumericLiteral(nameTypeNode.literal)) {\n\t\t\t\treturn nameTypeNode.literal.text;\n\t\t\t}\n\t\t\tif (nameTypeNode.literal.kind === ts.SyntaxKind.TrueKeyword) {\n\t\t\t\treturn \"true\";\n\t\t\t}\n\t\t\tif (nameTypeNode.literal.kind === ts.SyntaxKind.FalseKeyword) {\n\t\t\t\treturn \"false\";\n\t\t\t}\n\t\t}\n\n\t\tif (ts.isIntersectionTypeNode(nameTypeNode)) {\n\t\t\tconst hasMappedKeyReference = nameTypeNode.types.some(type =>\n\t\t\t\tJsonSchemaBuilder.isMappedTypeParameterReference(type, mappedTypeParameterName)\n\t\t\t);\n\t\t\tconst hasStringKeyword = nameTypeNode.types.some(\n\t\t\t\ttype => type.kind === ts.SyntaxKind.StringKeyword\n\t\t\t);\n\t\t\tif (hasMappedKeyReference && hasStringKeyword) {\n\t\t\t\treturn sourceKey;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (ts.isTemplateLiteralTypeNode(nameTypeNode)) {\n\t\t\tlet remappedKey = nameTypeNode.head.text;\n\t\t\tfor (const span of nameTypeNode.templateSpans) {\n\t\t\t\tconst spanValue = MappedTypeSchemaResolver.resolveMappedTypeRemappedKey(\n\t\t\t\t\tcontext,\n\t\t\t\t\tspan.type,\n\t\t\t\t\tsourceKey,\n\t\t\t\t\tmappedTypeParameterName\n\t\t\t\t);\n\t\t\t\tif (!Is.stringValue(spanValue)) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\tremappedKey += `${spanValue}${span.literal.text}`;\n\t\t\t}\n\n\t\t\treturn remappedKey;\n\t\t}\n\n\t\tif (ts.isTypeReferenceNode(nameTypeNode) && ts.isIdentifier(nameTypeNode.typeName)) {\n\t\t\tconst intrinsicName = nameTypeNode.typeName.text;\n\t\t\tif (nameTypeNode.typeArguments?.length === 1) {\n\t\t\t\tconst intrinsicInput = MappedTypeSchemaResolver.resolveMappedTypeRemappedKey(\n\t\t\t\t\tcontext,\n\t\t\t\t\tnameTypeNode.typeArguments[0],\n\t\t\t\t\tsourceKey,\n\t\t\t\t\tmappedTypeParameterName\n\t\t\t\t);\n\t\t\t\tif (!Is.stringValue(intrinsicInput)) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\treturn MappedTypeSchemaResolver.applyIntrinsicMappedTypeKeyRemap(\n\t\t\t\t\tintrinsicName,\n\t\t\t\t\tintrinsicInput\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (ts.isConditionalTypeNode(nameTypeNode)) {\n\t\t\tif (\n\t\t\t\t!JsonSchemaBuilder.isMappedTypeParameterReference(\n\t\t\t\t\tnameTypeNode.checkType,\n\t\t\t\t\tmappedTypeParameterName\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst satisfies = MappedTypeSchemaResolver.evaluateMappedKeyExtendsCondition(\n\t\t\t\tcontext,\n\t\t\t\tsourceKey,\n\t\t\t\tnameTypeNode.extendsType\n\t\t\t);\n\t\t\tif (satisfies === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst branchType = satisfies ? nameTypeNode.trueType : nameTypeNode.falseType;\n\t\t\treturn MappedTypeSchemaResolver.resolveMappedTypeRemappedKey(\n\t\t\t\tcontext,\n\t\t\t\tbranchType,\n\t\t\t\tsourceKey,\n\t\t\t\tmappedTypeParameterName\n\t\t\t);\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Evaluate whether a concrete mapped key satisfies an `extends` condition.\n\t * @param context The generation context.\n\t * @param sourceKey The concrete source key being evaluated.\n\t * @param extendsTypeNode The extends condition type node.\n\t * @returns True when the key satisfies the condition, false when it does not, otherwise undefined.\n\t */\n\tpublic static evaluateMappedKeyExtendsCondition(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\tsourceKey: string,\n\t\textendsTypeNode: ts.TypeNode\n\t): boolean | undefined {\n\t\tif (ts.isParenthesizedTypeNode(extendsTypeNode)) {\n\t\t\treturn MappedTypeSchemaResolver.evaluateMappedKeyExtendsCondition(\n\t\t\t\tcontext,\n\t\t\t\tsourceKey,\n\t\t\t\textendsTypeNode.type\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\textendsTypeNode.kind === ts.SyntaxKind.StringKeyword ||\n\t\t\textendsTypeNode.kind === ts.SyntaxKind.AnyKeyword ||\n\t\t\textendsTypeNode.kind === ts.SyntaxKind.UnknownKeyword\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (\n\t\t\textendsTypeNode.kind === ts.SyntaxKind.NeverKeyword ||\n\t\t\textendsTypeNode.kind === ts.SyntaxKind.NumberKeyword ||\n\t\t\textendsTypeNode.kind === ts.SyntaxKind.BooleanKeyword ||\n\t\t\textendsTypeNode.kind === ts.SyntaxKind.ObjectKeyword\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (ts.isLiteralTypeNode(extendsTypeNode)) {\n\t\t\tif (\n\t\t\t\tts.isStringLiteral(extendsTypeNode.literal) ||\n\t\t\t\tts.isNumericLiteral(extendsTypeNode.literal)\n\t\t\t) {\n\t\t\t\treturn sourceKey === extendsTypeNode.literal.text;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\tif (ts.isUnionTypeNode(extendsTypeNode)) {\n\t\t\tlet hasUndetermined = false;\n\t\t\tfor (const memberType of extendsTypeNode.types) {\n\t\t\t\tconst result = MappedTypeSchemaResolver.evaluateMappedKeyExtendsCondition(\n\t\t\t\t\tcontext,\n\t\t\t\t\tsourceKey,\n\t\t\t\t\tmemberType\n\t\t\t\t);\n\t\t\t\tif (result === true) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tif (result === undefined) {\n\t\t\t\t\thasUndetermined = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn hasUndetermined ? undefined : false;\n\t\t}\n\n\t\tif (\n\t\t\tts.isTypeOperatorNode(extendsTypeNode) &&\n\t\t\textendsTypeNode.operator === ts.SyntaxKind.KeyOfKeyword\n\t\t) {\n\t\t\tconst keys = JsonSchemaBuilder.extractKeyofTypeKeys(context, extendsTypeNode.type);\n\t\t\tif (keys.length > 0) {\n\t\t\t\treturn keys.includes(sourceKey);\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (ts.isTypeReferenceNode(extendsTypeNode)) {\n\t\t\tconst resolved = JsonSchemaBuilder.resolveReferencedTypeNodeFromLocalDeclaration(\n\t\t\t\tcontext,\n\t\t\t\textendsTypeNode\n\t\t\t);\n\t\t\tif (resolved) {\n\t\t\t\treturn MappedTypeSchemaResolver.evaluateMappedKeyExtendsCondition(\n\t\t\t\t\tcontext,\n\t\t\t\t\tsourceKey,\n\t\t\t\t\tresolved\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Build a conservative fallback schema for mapped types whose key remapping cannot be resolved.\n\t * @param context The generation context.\n\t * @param typeNode The mapped type node.\n\t * @param mappedKeys The resolved source keys from the mapped type constraint.\n\t * @param mappedTypeParameterName The mapped type parameter identifier.\n\t * @param sourceObjectSchema The optional source object schema for property lookups.\n\t * @returns The fallback mapped type schema.\n\t */\n\tpublic static buildMappedTypeFallbackSchema(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.MappedTypeNode,\n\t\tmappedKeys: string[],\n\t\tmappedTypeParameterName: string,\n\t\tsourceObjectSchema?: IJsonSchema\n\t): IJsonSchema {\n\t\tconst additionalProperties =\n\t\t\tMappedTypeSchemaResolver.buildMappedTypeFallbackAdditionalProperties(\n\t\t\t\tcontext,\n\t\t\t\ttypeNode,\n\t\t\t\tmappedKeys,\n\t\t\t\tmappedTypeParameterName,\n\t\t\t\tsourceObjectSchema\n\t\t\t);\n\n\t\treturn {\n\t\t\ttype: \"object\",\n\t\t\tadditionalProperties: additionalProperties ?? {}\n\t\t};\n\t}\n\n\t/**\n\t * Build fallback additionalProperties for unresolved mapped key remapping.\n\t * @param context The generation context.\n\t * @param typeNode The mapped type node.\n\t * @param mappedKeys The resolved source keys from the mapped type constraint.\n\t * @param mappedTypeParameterName The mapped type parameter identifier.\n\t * @param sourceObjectSchema The optional source object schema for property lookups.\n\t * @returns The fallback additionalProperties schema.\n\t */\n\tpublic static buildMappedTypeFallbackAdditionalProperties(\n\t\tcontext: ITypeScriptToSchemaContext,\n\t\ttypeNode: ts.MappedTypeNode,\n\t\tmappedKeys: string[],\n\t\tmappedTypeParameterName: string,\n\t\tsourceObjectSchema?: IJsonSchema\n\t): IJsonSchema | undefined {\n\t\tconst resolvedPropertySchemas = mappedKeys\n\t\t\t.map(mappedKey =>\n\t\t\t\tJsonSchemaBuilder.mapMappedTypePropertySchema(\n\t\t\t\t\tcontext,\n\t\t\t\t\ttypeNode,\n\t\t\t\t\tmappedKey,\n\t\t\t\t\tmappedTypeParameterName,\n\t\t\t\t\tsourceObjectSchema\n\t\t\t\t)\n\t\t\t)\n\t\t\t.filter((mappedType): mappedType is IJsonSchema => mappedType !== undefined);\n\n\t\tif (resolvedPropertySchemas.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst uniqueSchemas = resolvedPropertySchemas.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 * Merge mapped property schemas when multiple source keys remap to the same output key.\n\t * @param existingSchema The existing schema already assigned to the mapped key.\n\t * @param nextSchema The next schema to merge into the mapped key.\n\t * @returns The merged schema.\n\t */\n\tpublic static mergeMappedTypePropertySchemas(\n\t\texistingSchema: IJsonSchema,\n\t\tnextSchema: IJsonSchema\n\t): IJsonSchema {\n\t\tconst schemaVariants = [\n\t\t\t...(existingSchema.anyOf ?? [existingSchema]),\n\t\t\t...(nextSchema.anyOf ?? [nextSchema])\n\t\t];\n\n\t\tconst uniqueSchemas = schemaVariants.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 * Resolve required remapped keys from the source object's required key set.\n\t * @param mappedEntries The source-to-output mapped key entries.\n\t * @param sourceObjectSchema The source object schema containing required keys.\n\t * @returns The required output keys.\n\t */\n\tpublic static resolveMappedTypeSourceRequiredPropertyKeys(\n\t\tmappedEntries: { sourceKey: string; mappedKey: string }[],\n\t\tsourceObjectSchema: IJsonSchema\n\t): string[] | undefined {\n\t\tif (!Is.array<string>(sourceObjectSchema.required)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst sourceRequiredKeys = new Set(sourceObjectSchema.required);\n\t\tconst remappedRequiredKeys = mappedEntries\n\t\t\t.filter(mappedEntry => sourceRequiredKeys.has(mappedEntry.sourceKey))\n\t\t\t.map(mappedEntry => mappedEntry.mappedKey);\n\n\t\treturn [...new Set(remappedRequiredKeys)];\n\t}\n\n\t/**\n\t * Apply TypeScript intrinsic string remapping helpers to a key.\n\t * @param intrinsicName The intrinsic helper name.\n\t * @param value The input key value.\n\t * @returns The remapped key value.\n\t * @internal\n\t */\n\tprivate static applyIntrinsicMappedTypeKeyRemap(\n\t\tintrinsicName: string,\n\t\tvalue: string\n\t): string | undefined {\n\t\tswitch (intrinsicName) {\n\t\t\tcase \"Uppercase\":\n\t\t\t\treturn value.toUpperCase();\n\t\t\tcase \"Lowercase\":\n\t\t\t\treturn value.toLowerCase();\n\t\t\tcase \"Capitalize\":\n\t\t\t\treturn value.length > 0 ? `${value[0].toUpperCase()}${value.slice(1)}` : value;\n\t\t\tcase \"Uncapitalize\":\n\t\t\t\treturn value.length > 0 ? `${value[0].toLowerCase()}${value.slice(1)}` : value;\n\t\t\tdefault:\n\t\t\t\treturn undefined;\n\t\t}\n\t}\n}\n"]}
@@ -145,6 +145,33 @@ export class ObjectTransformer {
145
145
  normalizeObject(normalizedSchema);
146
146
  return normalizedSchema;
147
147
  }
148
+ /**
149
+ * Rename all non-JSON-LD property keys in an object schema by prefixing them.
150
+ * Keys that already start with "@" are preserved as-is; all others become `prefix:key`.
151
+ * @param baseSchema The source object schema.
152
+ * @param prefix The namespace prefix to apply.
153
+ * @returns The transformed object schema.
154
+ */
155
+ static renameKeysWithPrefixInObjectSchema(baseSchema, prefix) {
156
+ const mappedSchema = ObjectTransformer.toInlineUtilityObjectSchema(baseSchema);
157
+ if (Is.object(mappedSchema.properties)) {
158
+ const renamedProperties = {};
159
+ for (const [key, propSchema] of Object.entries(mappedSchema.properties)) {
160
+ const newKey = key.startsWith("@") ? key : `${prefix}:${key}`;
161
+ renamedProperties[newKey] = propSchema;
162
+ }
163
+ mappedSchema.properties = renamedProperties;
164
+ }
165
+ if (Is.array(mappedSchema.required)) {
166
+ mappedSchema.required = mappedSchema.required.map(key => {
167
+ if (Is.stringValue(key) && key.startsWith("@")) {
168
+ return key;
169
+ }
170
+ return `${prefix}:${key}`;
171
+ });
172
+ }
173
+ return mappedSchema;
174
+ }
148
175
  /**
149
176
  * Normalize a description string while preserving explicit line breaks from source comments.
150
177
  * @param description The description to normalize.
@@ -1 +1 @@
1
- {"version":3,"file":"objectTransformer.js","sourceRoot":"","sources":["../../../src/utils/objectTransformer.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGlD;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAC7B;;;;;OAKG;IACI,MAAM,CAAC,qCAAqC,CAClD,UAAuB,EACvB,WAAmB;QAEnB,IAAI,CAAC,UAAU,CAAC,UAAU,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YACjE,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,MAAM,cAAc,GAAG,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC1D,OAAO,cAAc,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACxE,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,wBAAwB,CACrC,UAAuB,EACv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Content":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is, ObjectHelper } from \"@twin.org/core\";\nimport type { IJsonSchema } from \"@twin.org/tools-models\";\n\n/**\n * Applies common object-schema transformations used by the builder.\n */\nexport class ObjectTransformer {\n\t/**\n\t * Resolve a property schema from an object schema by property key.\n\t * @param baseSchema The source object schema.\n\t * @param propertyKey The property key to resolve.\n\t * @returns The resolved property schema.\n\t */\n\tpublic static resolvePropertySchemaFromObjectSchema(\n\t\tbaseSchema: IJsonSchema,\n\t\tpropertyKey: string\n\t): IJsonSchema | undefined {\n\t\tif (!baseSchema.properties || !Is.object(baseSchema.properties)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst propertySchema = baseSchema.properties[propertyKey];\n\t\treturn propertySchema ? ObjectHelper.clone(propertySchema) : undefined;\n\t}\n\n\t/**\n\t * Remove keys from an object schema.\n\t * @param baseSchema The source object schema.\n\t * @param omittedKeys The keys to remove.\n\t * @returns The transformed object schema.\n\t */\n\tpublic static omitKeysFromObjectSchema(\n\t\tbaseSchema: IJsonSchema,\n\t\tomittedKeys: string[]\n\t): IJsonSchema {\n\t\tconst omittedKeySet = new Set(omittedKeys);\n\t\tconst mappedSchema = ObjectTransformer.toInlineUtilityObjectSchema(baseSchema);\n\n\t\tif (Is.object(mappedSchema.properties)) {\n\t\t\tfor (const key of Object.keys(mappedSchema.properties)) {\n\t\t\t\tif (omittedKeySet.has(key)) {\n\t\t\t\t\tdelete mappedSchema.properties[key];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Object.keys(mappedSchema.properties).length === 0) {\n\t\t\t\tdelete mappedSchema.properties;\n\t\t\t}\n\t\t}\n\n\t\tif (Is.array(mappedSchema.required)) {\n\t\t\tmappedSchema.required = mappedSchema.required.filter(key => !omittedKeySet.has(key));\n\t\t\tif (mappedSchema.required.length === 0) {\n\t\t\t\tdelete mappedSchema.required;\n\t\t\t}\n\t\t}\n\n\t\treturn mappedSchema;\n\t}\n\n\t/**\n\t * Keep only keys from an object schema.\n\t * @param baseSchema The source object schema.\n\t * @param pickedKeys The keys to keep.\n\t * @returns The transformed object schema.\n\t */\n\tpublic static pickKeysFromObjectSchema(\n\t\tbaseSchema: IJsonSchema,\n\t\tpickedKeys: string[]\n\t): IJsonSchema {\n\t\tconst pickedKeySet = new Set(pickedKeys);\n\t\tconst mappedSchema = ObjectTransformer.toInlineUtilityObjectSchema(baseSchema);\n\n\t\tif (Is.object(mappedSchema.properties)) {\n\t\t\tfor (const key of Object.keys(mappedSchema.properties)) {\n\t\t\t\tif (!pickedKeySet.has(key)) {\n\t\t\t\t\tdelete mappedSchema.properties[key];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Object.keys(mappedSchema.properties).length === 0) {\n\t\t\t\tdelete mappedSchema.properties;\n\t\t\t}\n\t\t}\n\n\t\tif (Is.array(mappedSchema.required)) {\n\t\t\tmappedSchema.required = mappedSchema.required.filter(key => pickedKeySet.has(key));\n\t\t\tif (mappedSchema.required.length === 0) {\n\t\t\t\tdelete mappedSchema.required;\n\t\t\t}\n\t\t}\n\n\t\treturn mappedSchema;\n\t}\n\n\t/**\n\t * Normalize utility-derived object schemas for inline property usage.\n\t * When the schema contains an allOf, flatten it by merging properties from all branches.\n\t * @param schema The source object schema.\n\t * @returns The normalized inline schema.\n\t * @internal\n\t */\n\tpublic static toInlineUtilityObjectSchema(schema: IJsonSchema): IJsonSchema {\n\t\tconst mappedSchema = ObjectHelper.clone(schema);\n\t\tdelete mappedSchema.$schema;\n\t\tdelete mappedSchema.$id;\n\t\tdelete mappedSchema.title;\n\n\t\t// Flatten allOf by merging properties and required arrays from all branches\n\t\t// This handles inheritance cases where a type extends another type\n\t\tif (Is.array(mappedSchema.allOf) && mappedSchema.allOf.length > 0) {\n\t\t\tconst mergedProperties: { [key: string]: unknown } = {};\n\t\t\tconst mergedRequired = new Set<string>();\n\n\t\t\t// Collect properties and required fields from all allOf branches\n\t\t\tfor (const branch of mappedSchema.allOf) {\n\t\t\t\tif (Is.object(branch)) {\n\t\t\t\t\t// Merge properties\n\t\t\t\t\tif (Is.object(branch.properties)) {\n\t\t\t\t\t\tObject.assign(mergedProperties, branch.properties);\n\t\t\t\t\t}\n\t\t\t\t\t// Collect required fields\n\t\t\t\t\tif (Is.array(branch.required)) {\n\t\t\t\t\t\tfor (const field of branch.required) {\n\t\t\t\t\t\t\tif (Is.stringValue(field)) {\n\t\t\t\t\t\t\t\tmergedRequired.add(field);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Remove allOf and set merged properties at the top level\n\t\t\tdelete mappedSchema.allOf;\n\n\t\t\tif (Object.keys(mergedProperties).length > 0) {\n\t\t\t\tmappedSchema.properties = Object.assign(mappedSchema.properties ?? {}, mergedProperties);\n\t\t\t}\n\n\t\t\tif (mergedRequired.size > 0) {\n\t\t\t\tconst existingRequired = Is.array(mappedSchema.required) ? mappedSchema.required : [];\n\t\t\t\tmappedSchema.required = [...new Set([...existingRequired, ...mergedRequired])];\n\t\t\t}\n\t\t}\n\n\t\treturn mappedSchema;\n\t}\n\n\t/**\n\t * Normalize schema description whitespace while preserving intentional line breaks.\n\t * @param schema The schema to normalize.\n\t * @returns The normalized schema.\n\t */\n\tpublic static normalizeSchemaDescriptions(schema: IJsonSchema): IJsonSchema {\n\t\tconst normalizedSchema = ObjectHelper.clone(schema);\n\t\tconst normalizeObject = (value: unknown): void => {\n\t\t\tif (Is.array(value)) {\n\t\t\t\tfor (const item of value) {\n\t\t\t\t\tnormalizeObject(item);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (Is.object(value)) {\n\t\t\t\tconst valueRecord = value;\n\t\t\t\tif (Is.stringValue(valueRecord.description)) {\n\t\t\t\t\tvalueRecord.description = ObjectTransformer.normalizeSchemaDescriptionText(\n\t\t\t\t\t\tvalueRecord.description\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tfor (const nestedValue of Object.values(valueRecord)) {\n\t\t\t\t\tnormalizeObject(nestedValue);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tnormalizeObject(normalizedSchema);\n\t\treturn normalizedSchema;\n\t}\n\n\t/**\n\t * Normalize a description string while preserving explicit line breaks from source comments.\n\t * @param description The description to normalize.\n\t * @returns The normalized description.\n\t * @internal\n\t */\n\tprivate static normalizeSchemaDescriptionText(description: string): string {\n\t\treturn description\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map(line => line.replace(/\\s{2,}/g, \" \").trim())\n\t\t\t.join(\"\\n\");\n\t}\n}\n"]}
1
+ {"version":3,"file":"objectTransformer.js","sourceRoot":"","sources":["../../../src/utils/objectTransformer.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGlD;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAC7B;;;;;OAKG;IACI,MAAM,CAAC,qCAAqC,CAClD,UAAuB,EACvB,WAAmB;QAEnB,IAAI,CAAC,UAAU,CAAC,UAAU,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YACjE,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,MAAM,cAAc,GAAG,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC1D,OAAO,cAAc,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACxE,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,wBAAwB,CACrC,UAAuB,EACvB,WAAqB;QAErB,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;QAC3C,MAAM,YAAY,GAAG,iBAAiB,CAAC,2BAA2B,CAAC,UAAU,CAAC,CAAC;QAE/E,IAAI,EAAE,C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,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,CAAC;gBAC9D,iBAAiB,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC;YACxC,CAAC;YACD,YAAY,CAAC,UAAU,GAAG,iBAAiB,CAAC;QAC7C,CAAC;QAED,IAAI,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;YACrC,YAAY,CAAC,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBACvD,IAAI,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;oBAChD,OAAO,GAAG,CAAC;gBACZ,CAAC;gBACD,OAAO,GAAG,MAAM,IAAI,GAAG,EAAE,CAAC;YAC3B,CAAC,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,YAAY,CAAC;IACrB,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,8BAA8B,CAAC,WAAmB;QAChE,OAAO,WAAW;aAChB,KAAK,CAAC,OAAO,CAAC;aACd,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;aAChD,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;CACD","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is, ObjectHelper } from \"@twin.org/core\";\nimport type { IJsonSchema } from \"@twin.org/tools-models\";\n\n/**\n * Applies common object-schema transformations used by the builder.\n */\nexport class ObjectTransformer {\n\t/**\n\t * Resolve a property schema from an object schema by property key.\n\t * @param baseSchema The source object schema.\n\t * @param propertyKey The property key to resolve.\n\t * @returns The resolved property schema.\n\t */\n\tpublic static resolvePropertySchemaFromObjectSchema(\n\t\tbaseSchema: IJsonSchema,\n\t\tpropertyKey: string\n\t): IJsonSchema | undefined {\n\t\tif (!baseSchema.properties || !Is.object(baseSchema.properties)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst propertySchema = baseSchema.properties[propertyKey];\n\t\treturn propertySchema ? ObjectHelper.clone(propertySchema) : undefined;\n\t}\n\n\t/**\n\t * Remove keys from an object schema.\n\t * @param baseSchema The source object schema.\n\t * @param omittedKeys The keys to remove.\n\t * @returns The transformed object schema.\n\t */\n\tpublic static omitKeysFromObjectSchema(\n\t\tbaseSchema: IJsonSchema,\n\t\tomittedKeys: string[]\n\t): IJsonSchema {\n\t\tconst omittedKeySet = new Set(omittedKeys);\n\t\tconst mappedSchema = ObjectTransformer.toInlineUtilityObjectSchema(baseSchema);\n\n\t\tif (Is.object(mappedSchema.properties)) {\n\t\t\tfor (const key of Object.keys(mappedSchema.properties)) {\n\t\t\t\tif (omittedKeySet.has(key)) {\n\t\t\t\t\tdelete mappedSchema.properties[key];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Object.keys(mappedSchema.properties).length === 0) {\n\t\t\t\tdelete mappedSchema.properties;\n\t\t\t}\n\t\t}\n\n\t\tif (Is.array(mappedSchema.required)) {\n\t\t\tmappedSchema.required = mappedSchema.required.filter(key => !omittedKeySet.has(key));\n\t\t\tif (mappedSchema.required.length === 0) {\n\t\t\t\tdelete mappedSchema.required;\n\t\t\t}\n\t\t}\n\n\t\treturn mappedSchema;\n\t}\n\n\t/**\n\t * Keep only keys from an object schema.\n\t * @param baseSchema The source object schema.\n\t * @param pickedKeys The keys to keep.\n\t * @returns The transformed object schema.\n\t */\n\tpublic static pickKeysFromObjectSchema(\n\t\tbaseSchema: IJsonSchema,\n\t\tpickedKeys: string[]\n\t): IJsonSchema {\n\t\tconst pickedKeySet = new Set(pickedKeys);\n\t\tconst mappedSchema = ObjectTransformer.toInlineUtilityObjectSchema(baseSchema);\n\n\t\tif (Is.object(mappedSchema.properties)) {\n\t\t\tfor (const key of Object.keys(mappedSchema.properties)) {\n\t\t\t\tif (!pickedKeySet.has(key)) {\n\t\t\t\t\tdelete mappedSchema.properties[key];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Object.keys(mappedSchema.properties).length === 0) {\n\t\t\t\tdelete mappedSchema.properties;\n\t\t\t}\n\t\t}\n\n\t\tif (Is.array(mappedSchema.required)) {\n\t\t\tmappedSchema.required = mappedSchema.required.filter(key => pickedKeySet.has(key));\n\t\t\tif (mappedSchema.required.length === 0) {\n\t\t\t\tdelete mappedSchema.required;\n\t\t\t}\n\t\t}\n\n\t\treturn mappedSchema;\n\t}\n\n\t/**\n\t * Normalize utility-derived object schemas for inline property usage.\n\t * When the schema contains an allOf, flatten it by merging properties from all branches.\n\t * @param schema The source object schema.\n\t * @returns The normalized inline schema.\n\t * @internal\n\t */\n\tpublic static toInlineUtilityObjectSchema(schema: IJsonSchema): IJsonSchema {\n\t\tconst mappedSchema = ObjectHelper.clone(schema);\n\t\tdelete mappedSchema.$schema;\n\t\tdelete mappedSchema.$id;\n\t\tdelete mappedSchema.title;\n\n\t\t// Flatten allOf by merging properties and required arrays from all branches\n\t\t// This handles inheritance cases where a type extends another type\n\t\tif (Is.array(mappedSchema.allOf) && mappedSchema.allOf.length > 0) {\n\t\t\tconst mergedProperties: { [key: string]: unknown } = {};\n\t\t\tconst mergedRequired = new Set<string>();\n\n\t\t\t// Collect properties and required fields from all allOf branches\n\t\t\tfor (const branch of mappedSchema.allOf) {\n\t\t\t\tif (Is.object(branch)) {\n\t\t\t\t\t// Merge properties\n\t\t\t\t\tif (Is.object(branch.properties)) {\n\t\t\t\t\t\tObject.assign(mergedProperties, branch.properties);\n\t\t\t\t\t}\n\t\t\t\t\t// Collect required fields\n\t\t\t\t\tif (Is.array(branch.required)) {\n\t\t\t\t\t\tfor (const field of branch.required) {\n\t\t\t\t\t\t\tif (Is.stringValue(field)) {\n\t\t\t\t\t\t\t\tmergedRequired.add(field);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Remove allOf and set merged properties at the top level\n\t\t\tdelete mappedSchema.allOf;\n\n\t\t\tif (Object.keys(mergedProperties).length > 0) {\n\t\t\t\tmappedSchema.properties = Object.assign(mappedSchema.properties ?? {}, mergedProperties);\n\t\t\t}\n\n\t\t\tif (mergedRequired.size > 0) {\n\t\t\t\tconst existingRequired = Is.array(mappedSchema.required) ? mappedSchema.required : [];\n\t\t\t\tmappedSchema.required = [...new Set([...existingRequired, ...mergedRequired])];\n\t\t\t}\n\t\t}\n\n\t\treturn mappedSchema;\n\t}\n\n\t/**\n\t * Normalize schema description whitespace while preserving intentional line breaks.\n\t * @param schema The schema to normalize.\n\t * @returns The normalized schema.\n\t */\n\tpublic static normalizeSchemaDescriptions(schema: IJsonSchema): IJsonSchema {\n\t\tconst normalizedSchema = ObjectHelper.clone(schema);\n\t\tconst normalizeObject = (value: unknown): void => {\n\t\t\tif (Is.array(value)) {\n\t\t\t\tfor (const item of value) {\n\t\t\t\t\tnormalizeObject(item);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (Is.object(value)) {\n\t\t\t\tconst valueRecord = value;\n\t\t\t\tif (Is.stringValue(valueRecord.description)) {\n\t\t\t\t\tvalueRecord.description = ObjectTransformer.normalizeSchemaDescriptionText(\n\t\t\t\t\t\tvalueRecord.description\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tfor (const nestedValue of Object.values(valueRecord)) {\n\t\t\t\t\tnormalizeObject(nestedValue);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tnormalizeObject(normalizedSchema);\n\t\treturn normalizedSchema;\n\t}\n\n\t/**\n\t * Rename all non-JSON-LD property keys in an object schema by prefixing them.\n\t * Keys that already start with \"@\" are preserved as-is; all others become `prefix:key`.\n\t * @param baseSchema The source object schema.\n\t * @param prefix The namespace prefix to apply.\n\t * @returns The transformed object schema.\n\t */\n\tpublic static renameKeysWithPrefixInObjectSchema(\n\t\tbaseSchema: IJsonSchema,\n\t\tprefix: string\n\t): IJsonSchema {\n\t\tconst mappedSchema = ObjectTransformer.toInlineUtilityObjectSchema(baseSchema);\n\n\t\tif (Is.object(mappedSchema.properties)) {\n\t\t\tconst renamedProperties: { [key: string]: IJsonSchema } = {};\n\t\t\tfor (const [key, propSchema] of Object.entries(mappedSchema.properties)) {\n\t\t\t\tconst newKey = key.startsWith(\"@\") ? key : `${prefix}:${key}`;\n\t\t\t\trenamedProperties[newKey] = propSchema;\n\t\t\t}\n\t\t\tmappedSchema.properties = renamedProperties;\n\t\t}\n\n\t\tif (Is.array(mappedSchema.required)) {\n\t\t\tmappedSchema.required = mappedSchema.required.map(key => {\n\t\t\t\tif (Is.stringValue(key) && key.startsWith(\"@\")) {\n\t\t\t\t\treturn key;\n\t\t\t\t}\n\t\t\t\treturn `${prefix}:${key}`;\n\t\t\t});\n\t\t}\n\n\t\treturn mappedSchema;\n\t}\n\n\t/**\n\t * Normalize a description string while preserving explicit line breaks from source comments.\n\t * @param description The description to normalize.\n\t * @returns The normalized description.\n\t * @internal\n\t */\n\tprivate static normalizeSchemaDescriptionText(description: string): string {\n\t\treturn description\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map(line => line.replace(/\\s{2,}/g, \" \").trim())\n\t\t\t.join(\"\\n\");\n\t}\n}\n"]}
@@ -43,7 +43,7 @@ export class RegEx {
43
43
  }
44
44
  /**
45
45
  * Determine if a mapping pattern is a regex literal surrounded by forward slashes.
46
- * Example pattern: /^foo.*bar$/
46
+ * Example pattern: /^foo.*bar$/.
47
47
  * @param pattern The mapping pattern.
48
48
  * @returns True if the pattern looks like a regex literal.
49
49
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"regEx.js","sourceRoot":"","sources":["../../../src/utils/regEx.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,MAAM,OAAO,KAAK;IACjB;;;;;;;OAOG;IACI,MAAM,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AY,CAAC,CAAC;IACjC,CAAC;CACD","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Utility methods for pattern matching and regex construction.\n */\nexport class RegEx {\n\t/**\n\t * Determine whether a reference mapping pattern matches an external reference.\n\t * @param pattern The mapping pattern.\n\t * @param packageName The external package name.\n\t * @param typeName The imported type name.\n\t * @param schemaTitle The derived schema title.\n\t * @returns True if matched.\n\t */\n\tpublic static isReferencePatternMatch(\n\t\tpattern: string,\n\t\tpackageName: string,\n\t\ttypeName: string,\n\t\tschemaTitle: string\n\t): boolean {\n\t\tconst regex = RegEx.toRegexFromReferencePattern(pattern);\n\t\treturn regex\n\t\t\t? regex.test(packageName) || regex.test(typeName) || regex.test(schemaTitle)\n\t\t\t: false;\n\t}\n\n\t/**\n\t * Apply a reference mapping replacement to the first matching candidate.\n\t * @param pattern The mapping pattern.\n\t * @param replacement The replacement template.\n\t * @param packageName The external package name.\n\t * @param typeName The imported type name.\n\t * @param schemaTitle The derived schema title.\n\t * @returns The replaced value if a candidate matches.\n\t */\n\tpublic static applyReferencePatternReplacement(\n\t\tpattern: string,\n\t\treplacement: string,\n\t\tpackageName: string,\n\t\ttypeName: string,\n\t\tschemaTitle: string\n\t): string | undefined {\n\t\tconst regex = RegEx.toRegexFromReferencePattern(pattern);\n\t\tif (!regex) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tfor (const candidate of [packageName, typeName, schemaTitle]) {\n\t\t\tregex.lastIndex = 0;\n\t\t\tif (regex.test(candidate)) {\n\t\t\t\tregex.lastIndex = 0;\n\t\t\t\treturn candidate.replace(regex, replacement);\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Determine if a mapping pattern is a regex literal surrounded by forward slashes.\n\t * Example pattern: /^foo.*bar$/\n\t * @param pattern The mapping pattern.\n\t * @returns True if the pattern looks like a regex literal.\n\t * @internal\n\t */\n\tprivate static isRegexLiteralPattern(pattern: string): boolean {\n\t\treturn pattern.length > 2 && pattern.startsWith(\"/\") && pattern.endsWith(\"/\");\n\t}\n\n\t/**\n\t * Determine if a mapping pattern should be treated as a raw regex expression.\n\t * Any pattern that contains at least one regex meta character is treated as a raw expression.\n\t * @param pattern The mapping pattern.\n\t * @returns True if the pattern contains regex syntax.\n\t * @internal\n\t */\n\tprivate static isRegexExpressionPattern(pattern: string): boolean {\n\t\treturn /[()[\\]{}+?|^$\\\\]/u.test(pattern);\n\t}\n\n\t/**\n\t * Convert a regex literal mapping pattern to a RegExp.\n\t * The surrounding forward slashes are stripped before compiling.\n\t * @param pattern The regex literal pattern, e.g. /^foo.*bar$/\n\t * @returns The RegExp instance, or undefined when the inner expression is invalid.\n\t * @internal\n\t */\n\tprivate static toRegexFromLiteralPattern(pattern: string): RegExp | undefined {\n\t\ttry {\n\t\t\treturn new RegExp(pattern.slice(1, -1));\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Convert a raw regex expression mapping pattern to a RegExp anchored to full-string match.\n\t * The expression is wrapped with ^ and $ so that partial matches are not accepted.\n\t * @param pattern The raw regex expression.\n\t * @returns The RegExp instance, or undefined when the expression is invalid.\n\t * @internal\n\t */\n\tprivate static toRegexFromExpressionPattern(pattern: string): RegExp | undefined {\n\t\ttry {\n\t\t\treturn new RegExp(`^${pattern}$`);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Select and compile the appropriate RegExp for a reference mapping pattern.\n\t * Evaluation order: regex literal -> raw regex expression -> wildcard glob.\n\t * Plain strings with none of these characteristics return undefined.\n\t * @param pattern The mapping pattern.\n\t * @returns The RegExp instance, or undefined when the pattern is not pattern-based.\n\t * @internal\n\t */\n\tprivate static toRegexFromReferencePattern(pattern: string): RegExp | undefined {\n\t\tif (RegEx.isRegexLiteralPattern(pattern)) {\n\t\t\treturn RegEx.toRegexFromLiteralPattern(pattern);\n\t\t}\n\n\t\tif (RegEx.isRegexExpressionPattern(pattern)) {\n\t\t\treturn RegEx.toRegexFromExpressionPattern(pattern);\n\t\t}\n\n\t\tif (pattern.includes(\"*\")) {\n\t\t\treturn RegEx.toRegexFromWildcardPattern(pattern);\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Convert a glob wildcard pattern to a RegExp.\n\t * All regex metacharacters in the pattern are escaped first, then each * is replaced with .*.\n\t * The resulting expression is anchored with ^ and $ for full-string matching.\n\t * @param pattern The wildcard pattern, e.g. *Operation or @twin.org/*.\n\t * @returns The compiled RegExp.\n\t * @internal\n\t */\n\tprivate static toRegexFromWildcardPattern(pattern: string): RegExp {\n\t\tconst escapedPattern = pattern.replace(/[$()+./?[\\\\\\]^{|}-]/g, \"\\\\$&\");\n\t\tconst regexPattern = `^${escapedPattern.replace(/\\*/g, \".*\")}$`;\n\t\treturn new RegExp(regexPattern);\n\t}\n}\n"]}
1
+ {"version":3,"file":"regEx.js","sourceRoot":"","sources":["../../../src/utils/regEx.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,MAAM,OAAO,KAAK;IACjB;;;;;;;OAOG;IACI,MAAM,CAAC,uBAAuB,CACpC,OAAe,EACf,WAAmB,EACnB,QAAgB,EAChB,WAAmB;QAEnB,MAAM,KAAK,GAAG,KAAK,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC;QACzD,OAAO,KAAK;YACX,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC;YAC5E,CAAC,CAAC,KAAK,CAAC;IACV,CAAC;IAED;;;;;;;;OAQG;IACI,MAAM,CAAC,gCAAgC,CAC7C,OAAe,EACf,WAAmB,EACnB,WAAmB,EACnB,QAAgB,EAChB,WAAmB;QAEnB,MAAM,KAAK,GAAG,KAAK,CAAC,2BAA2B,CAAC,OAAO,CAAC,C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IACK,MAAM,CAAC,2BAA2B,CAAC,OAAe;QACzD,IAAI,KAAK,CAAC,qBAAqB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1C,OAAO,KAAK,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,IAAI,KAAK,CAAC,wBAAwB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,OAAO,KAAK,CAAC,4BAA4B,CAAC,OAAO,CAAC,CAAC;QACpD,CAAC;QAED,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;;;;;;OAOG;IACK,MAAM,CAAC,0BAA0B,CAAC,OAAe;QACxD,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;QACvE,MAAM,YAAY,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC;QAChE,OAAO,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC;IACjC,CAAC;CACD","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Utility methods for pattern matching and regex construction.\n */\nexport class RegEx {\n\t/**\n\t * Determine whether a reference mapping pattern matches an external reference.\n\t * @param pattern The mapping pattern.\n\t * @param packageName The external package name.\n\t * @param typeName The imported type name.\n\t * @param schemaTitle The derived schema title.\n\t * @returns True if matched.\n\t */\n\tpublic static isReferencePatternMatch(\n\t\tpattern: string,\n\t\tpackageName: string,\n\t\ttypeName: string,\n\t\tschemaTitle: string\n\t): boolean {\n\t\tconst regex = RegEx.toRegexFromReferencePattern(pattern);\n\t\treturn regex\n\t\t\t? regex.test(packageName) || regex.test(typeName) || regex.test(schemaTitle)\n\t\t\t: false;\n\t}\n\n\t/**\n\t * Apply a reference mapping replacement to the first matching candidate.\n\t * @param pattern The mapping pattern.\n\t * @param replacement The replacement template.\n\t * @param packageName The external package name.\n\t * @param typeName The imported type name.\n\t * @param schemaTitle The derived schema title.\n\t * @returns The replaced value if a candidate matches.\n\t */\n\tpublic static applyReferencePatternReplacement(\n\t\tpattern: string,\n\t\treplacement: string,\n\t\tpackageName: string,\n\t\ttypeName: string,\n\t\tschemaTitle: string\n\t): string | undefined {\n\t\tconst regex = RegEx.toRegexFromReferencePattern(pattern);\n\t\tif (!regex) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tfor (const candidate of [packageName, typeName, schemaTitle]) {\n\t\t\tregex.lastIndex = 0;\n\t\t\tif (regex.test(candidate)) {\n\t\t\t\tregex.lastIndex = 0;\n\t\t\t\treturn candidate.replace(regex, replacement);\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Determine if a mapping pattern is a regex literal surrounded by forward slashes.\n\t * Example pattern: /^foo.*bar$/.\n\t * @param pattern The mapping pattern.\n\t * @returns True if the pattern looks like a regex literal.\n\t * @internal\n\t */\n\tprivate static isRegexLiteralPattern(pattern: string): boolean {\n\t\treturn pattern.length > 2 && pattern.startsWith(\"/\") && pattern.endsWith(\"/\");\n\t}\n\n\t/**\n\t * Determine if a mapping pattern should be treated as a raw regex expression.\n\t * Any pattern that contains at least one regex meta character is treated as a raw expression.\n\t * @param pattern The mapping pattern.\n\t * @returns True if the pattern contains regex syntax.\n\t * @internal\n\t */\n\tprivate static isRegexExpressionPattern(pattern: string): boolean {\n\t\treturn /[()[\\]{}+?|^$\\\\]/u.test(pattern);\n\t}\n\n\t/**\n\t * Convert a regex literal mapping pattern to a RegExp.\n\t * The surrounding forward slashes are stripped before compiling.\n\t * @param pattern The regex literal pattern, e.g. /^foo.*bar$/\n\t * @returns The RegExp instance, or undefined when the inner expression is invalid.\n\t * @internal\n\t */\n\tprivate static toRegexFromLiteralPattern(pattern: string): RegExp | undefined {\n\t\ttry {\n\t\t\treturn new RegExp(pattern.slice(1, -1));\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Convert a raw regex expression mapping pattern to a RegExp anchored to full-string match.\n\t * The expression is wrapped with ^ and $ so that partial matches are not accepted.\n\t * @param pattern The raw regex expression.\n\t * @returns The RegExp instance, or undefined when the expression is invalid.\n\t * @internal\n\t */\n\tprivate static toRegexFromExpressionPattern(pattern: string): RegExp | undefined {\n\t\ttry {\n\t\t\treturn new RegExp(`^${pattern}$`);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Select and compile the appropriate RegExp for a reference mapping pattern.\n\t * Evaluation order: regex literal -> raw regex expression -> wildcard glob.\n\t * Plain strings with none of these characteristics return undefined.\n\t * @param pattern The mapping pattern.\n\t * @returns The RegExp instance, or undefined when the pattern is not pattern-based.\n\t * @internal\n\t */\n\tprivate static toRegexFromReferencePattern(pattern: string): RegExp | undefined {\n\t\tif (RegEx.isRegexLiteralPattern(pattern)) {\n\t\t\treturn RegEx.toRegexFromLiteralPattern(pattern);\n\t\t}\n\n\t\tif (RegEx.isRegexExpressionPattern(pattern)) {\n\t\t\treturn RegEx.toRegexFromExpressionPattern(pattern);\n\t\t}\n\n\t\tif (pattern.includes(\"*\")) {\n\t\t\treturn RegEx.toRegexFromWildcardPattern(pattern);\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Convert a glob wildcard pattern to a RegExp.\n\t * All regex metacharacters in the pattern are escaped first, then each * is replaced with .*.\n\t * The resulting expression is anchored with ^ and $ for full-string matching.\n\t * @param pattern The wildcard pattern, e.g. *Operation or @twin.org/*.\n\t * @returns The compiled RegExp.\n\t * @internal\n\t */\n\tprivate static toRegexFromWildcardPattern(pattern: string): RegExp {\n\t\tconst escapedPattern = pattern.replace(/[$()+./?[\\\\\\]^{|}-]/g, \"\\\\$&\");\n\t\tconst regexPattern = `^${escapedPattern.replace(/\\*/g, \".*\")}$`;\n\t\treturn new RegExp(regexPattern);\n\t}\n}\n"]}
@@ -106,6 +106,7 @@ export class TypeScriptToSchema {
106
106
  * @param context The generation context.
107
107
  * @param schema The root schema to rewrite.
108
108
  * @param rootTitle The title of the root schema.
109
+ * @internal
109
110
  */
110
111
  inlineEmbeddedSchemas(context, schema, rootTitle) {
111
112
  this.inlineEmbeddedSchemasInNode(context, schema, schema, rootTitle, new Set([rootTitle]));
@@ -118,6 +119,7 @@ export class TypeScriptToSchema {
118
119
  * @param rootTitle The title of the root schema.
119
120
  * @param ancestry Titles currently being expanded to avoid recursion cycles.
120
121
  * @returns True if inline embedding changed this node or a descendant.
122
+ * @internal
121
123
  */
122
124
  inlineEmbeddedSchemasInNode(context, rootSchema, currentNode, rootTitle, ancestry) {
123
125
  let hasInlineReplacement = false;
@@ -173,6 +175,7 @@ export class TypeScriptToSchema {
173
175
  /**
174
176
  * Flatten inline-expanded object allOf branches into the containing schema.
175
177
  * @param schema The schema to flatten.
178
+ * @internal
176
179
  */
177
180
  flattenInlineAllOfBranches(schema) {
178
181
  if (!Is.array(schema.allOf) || schema.allOf.length === 0) {
@@ -221,6 +224,7 @@ export class TypeScriptToSchema {
221
224
  * Determine whether an allOf branch can be flattened into its parent after inline embedding.
222
225
  * @param branch The allOf branch.
223
226
  * @returns True if the branch is a plain object schema.
227
+ * @internal
224
228
  */
225
229
  canFlattenInlineAllOfBranch(branch) {
226
230
  return Boolean(!branch.$ref &&
@@ -236,6 +240,7 @@ export class TypeScriptToSchema {
236
240
  * @param embeddedSchema The source schema.
237
241
  * @param embeddedMode The embedding mode.
238
242
  * @returns The cloned schema.
243
+ * @internal
239
244
  */
240
245
  createEmbeddedSchemaClone(context, embeddedSchema, embeddedMode) {
241
246
  let embeddedClone = ObjectHelper.clone(embeddedSchema);
@@ -254,6 +259,7 @@ export class TypeScriptToSchema {
254
259
  * Replace the contents of a schema node while keeping the same object reference.
255
260
  * @param target The schema node to mutate.
256
261
  * @param replacement The replacement content.
262
+ * @internal
257
263
  */
258
264
  replaceSchemaNode(target, replacement) {
259
265
  for (const key of Object.keys(target)) {
@@ -266,6 +272,7 @@ export class TypeScriptToSchema {
266
272
  * @param context The generation context.
267
273
  * @param schemaId The schema id to locate.
268
274
  * @returns The schema when found.
275
+ * @internal
269
276
  */
270
277
  findSchemaById(context, schemaId) {
271
278
  return Object.values(context.schemas)
@@ -277,6 +284,7 @@ export class TypeScriptToSchema {
277
284
  * @param schema The embedded schema.
278
285
  * @param schemaId The canonical schema id.
279
286
  * @returns The local definition key.
287
+ * @internal
280
288
  */
281
289
  getEmbeddedDefinitionKey(schema, schemaId) {
282
290
  return schema.title ?? schemaId.split("/").pop() ?? schemaId;
@@ -284,6 +292,7 @@ export class TypeScriptToSchema {
284
292
  /**
285
293
  * Remove $comment fields from a schema tree.
286
294
  * @param schema The schema tree to clean.
295
+ * @internal
287
296
  */
288
297
  removeSchemaComments(schema) {
289
298
  delete schema.$comment;
@@ -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,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,IAAI,EAAE,CAAC;a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BAAM,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"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KAAK,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;OAMG;IACK,wBAAwB,CAAC,MAAmB,EAAE,QAAgB;QACrE,OAAO,MAAM,CAAC,KAAK,IAAI,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,QAAQ,CAAC;IAC9D,CAAC;IAED;;;;OAIG;IACK,oBAAoB,CAAC,MAAmB;QAC/C,OAAO,MAAM,CAAC,QAAQ,CAAC;QAEvB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3C,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACrB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;oBAC1B,IAAI,EAAE,CAAC,MAAM,CAAc,IAAI,CAAC,EAAE,CAAC;wBAClC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;oBACjC,CAAC;gBACF,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 * @internal\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 * @internal\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 * @internal\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 * @internal\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 * @internal\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 * @internal\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 * @internal\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 * @internal\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 * @internal\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"]}
@@ -274,6 +274,32 @@ export class UtilityTypeSchemaMapper {
274
274
  }
275
275
  return mappedSchema;
276
276
  }
277
+ /**
278
+ * Map `JsonLdWithAliases<T, Prefix>` (and `JsonLdObjectWithAliases<T, Prefix>`) to an object
279
+ * schema where non-JSON-LD property keys are renamed to `Prefix:key` and `@`-prefixed keys
280
+ * are preserved as-is.
281
+ * @param context The generation context.
282
+ * @param typeNode The type reference node.
283
+ * @returns The mapped schema.
284
+ */
285
+ static mapJsonLdWithAliasesUtilityType(context, typeNode) {
286
+ const baseTypeNode = typeNode.typeArguments?.[0];
287
+ if (!baseTypeNode) {
288
+ return undefined;
289
+ }
290
+ const prefixTypeNode = typeNode.typeArguments?.[1];
291
+ if (!prefixTypeNode ||
292
+ !ts.isLiteralTypeNode(prefixTypeNode) ||
293
+ !ts.isStringLiteral(prefixTypeNode.literal)) {
294
+ return undefined;
295
+ }
296
+ const prefix = prefixTypeNode.literal.text;
297
+ const baseSchema = JsonSchemaBuilder.resolveUtilityBaseObjectSchema(context, baseTypeNode);
298
+ if (!baseSchema) {
299
+ return undefined;
300
+ }
301
+ return ObjectTransformer.renameKeysWithPrefixInObjectSchema(baseSchema, prefix);
302
+ }
277
303
  /**
278
304
  * Map `ObjectOrArray<T>` to a schema accepting `T` or `T[]`.
279
305
  * @param context The generation context.
@@ -350,6 +376,7 @@ export class UtilityTypeSchemaMapper {
350
376
  * Determine whether a type node represents null or undefined.
351
377
  * @param typeNode The type node to inspect.
352
378
  * @returns True if the node represents null or undefined; otherwise false.
379
+ * @internal
353
380
  */
354
381
  static isNullOrUndefinedTypeNode(typeNode) {
355
382
  if (typeNode.kind === ts.SyntaxKind.NullKeyword ||
@@ -368,6 +395,7 @@ export class UtilityTypeSchemaMapper {
368
395
  * Extract literal keys from a Record key type argument.
369
396
  * @param keyTypeNode The Record key type argument to inspect.
370
397
  * @returns The extracted literal keys.
398
+ * @internal
371
399
  */
372
400
  static extractRecordLiteralKeys(keyTypeNode) {
373
401
  if (ts.isLiteralTypeNode(keyTypeNode) && ts.isStringLiteral(keyTypeNode.literal)) {
@@ -388,6 +416,7 @@ export class UtilityTypeSchemaMapper {
388
416
  * @param baseSchema The base object schema being transformed.
389
417
  * @param keyToAdd The key to add when no explicit value type argument is provided.
390
418
  * @returns The resolved default schema for the added key.
419
+ * @internal
391
420
  */
392
421
  static mapJsonLdObjectDefaultSchemaByKey(context, baseSchema, keyToAdd) {
393
422
  if (keyToAdd === "id" || keyToAdd === "@id") {
@@ -402,6 +431,7 @@ export class UtilityTypeSchemaMapper {
402
431
  * Resolve default id schema for JsonLdObjectWithId when Id type argument is omitted.
403
432
  * @param baseSchema The base object schema being transformed.
404
433
  * @returns The default id schema.
434
+ * @internal
405
435
  */
406
436
  static mapJsonLdObjectWithIdDefaultIdSchema(baseSchema) {
407
437
  return UtilityTypeSchemaMapper.mapJsonLdObjectDefaultEitherSchema(baseSchema, "id", "@id", {
@@ -412,6 +442,7 @@ export class UtilityTypeSchemaMapper {
412
442
  * Resolve default type schema for JsonLdObjectWithType when Type argument is omitted.
413
443
  * @param baseSchema The base object schema being transformed.
414
444
  * @returns The default type schema.
445
+ * @internal
415
446
  */
416
447
  static mapJsonLdObjectWithTypeDefaultTypeSchema(baseSchema) {
417
448
  return UtilityTypeSchemaMapper.mapJsonLdObjectDefaultEitherSchema(baseSchema, "type", "@type", {
@@ -423,6 +454,7 @@ export class UtilityTypeSchemaMapper {
423
454
  * @param context The generation context.
424
455
  * @param baseSchema The base object schema being transformed.
425
456
  * @returns The default context schema.
457
+ * @internal
426
458
  */
427
459
  static mapJsonLdObjectWithContextDefaultContextSchema(context, baseSchema) {
428
460
  const existingContextSchema = ObjectTransformer.resolvePropertySchemaFromObjectSchema(baseSchema, "@context");
@@ -457,6 +489,7 @@ export class UtilityTypeSchemaMapper {
457
489
  * @param secondKey The second property key to check.
458
490
  * @param fallbackSchema The fallback schema when neither key is present.
459
491
  * @returns The resolved schema.
492
+ * @internal
460
493
  */
461
494
  static mapJsonLdObjectDefaultEitherSchema(baseSchema, firstKey, secondKey, fallbackSchema) {
462
495
  const firstSchema = ObjectTransformer.resolvePropertySchemaFromObjectSchema(baseSchema, firstKey);