@twin.org/tools-core 0.0.3-next.29 → 0.0.3-next.30

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.
@@ -92,14 +92,13 @@ export class ObjectTransformer {
92
92
  // Collect properties and required fields from all allOf branches
93
93
  for (const branch of mappedSchema.allOf) {
94
94
  if (Is.object(branch)) {
95
- const branchRecord = branch;
96
95
  // Merge properties
97
- if (Is.object(branchRecord.properties)) {
98
- Object.assign(mergedProperties, branchRecord.properties);
96
+ if (Is.object(branch.properties)) {
97
+ Object.assign(mergedProperties, branch.properties);
99
98
  }
100
99
  // Collect required fields
101
- if (Is.array(branchRecord.required)) {
102
- for (const field of branchRecord.required) {
100
+ if (Is.array(branch.required)) {
101
+ for (const field of branch.required) {
103
102
  if (Is.stringValue(field)) {
104
103
  mergedRequired.add(field);
105
104
  }
@@ -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,EACvB,WAAqB;QA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C,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\tconst branchRecord = branch as { [key: string]: unknown };\n\t\t\t\t\t// Merge properties\n\t\t\t\t\tif (Is.object(branchRecord.properties)) {\n\t\t\t\t\t\tObject.assign(mergedProperties, branchRecord.properties);\n\t\t\t\t\t}\n\t\t\t\t\t// Collect required fields\n\t\t\t\t\tif (Is.array(branchRecord.required)) {\n\t\t\t\t\t\tfor (const field of branchRecord.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,M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@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"]}
package/docs/changelog.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.30](https://github.com/iotaledger/twin-tools/compare/tools-core-v0.0.3-next.29...tools-core-v0.0.3-next.30) (2026-05-18)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * ajv stack overflow for oneOf on large enums ([#112](https://github.com/iotaledger/twin-tools/issues/112)) ([6be32a3](https://github.com/iotaledger/twin-tools/commit/6be32a3ae5b3cf188c0d1caf1080f497b648705c))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/tools-models bumped from 0.0.3-next.29 to 0.0.3-next.30
16
+
3
17
  ## [0.0.3-next.29](https://github.com/iotaledger/twin-tools/compare/tools-core-v0.0.3-next.28...tools-core-v0.0.3-next.29) (2026-05-14)
4
18
 
5
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/tools-core",
3
- "version": "0.0.3-next.29",
3
+ "version": "0.0.3-next.30",
4
4
  "description": "Shared utilities and models for tooling packages",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,7 @@
16
16
  "dependencies": {
17
17
  "@twin.org/core": "next",
18
18
  "@twin.org/nameof": "next",
19
- "@twin.org/tools-models": "0.0.3-next.29",
19
+ "@twin.org/tools-models": "0.0.3-next.30",
20
20
  "glob": "13.0.6"
21
21
  },
22
22
  "main": "./dist/es/index.js",