@twin.org/tools-core 0.0.3-next.16 → 0.0.3-next.18

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.
@@ -4,7 +4,6 @@ import { Is, StringHelper } from "@twin.org/core";
4
4
  import { FileUtils } from "./fileUtils.js";
5
5
  import { JsonSchemaBuilder } from "./jsonSchemaBuilder.js";
6
6
  import { Resolver } from "./resolver.js";
7
- import { Utility } from "./utility.js";
8
7
  /**
9
8
  * Class for converting TypeScript types to JSON Schema.
10
9
  */
@@ -54,7 +53,7 @@ export class TypeScriptToSchema {
54
53
  }
55
54
  }
56
55
  }
57
- else if (Utility.isTypeNameInput(sourceFileOrTypeName)) {
56
+ else if (this.isTypeNameInput(sourceFileOrTypeName)) {
58
57
  const declarationResult = Resolver.resolveTypeDeclarationAst(context.packageName, sourceFileOrTypeName);
59
58
  if (declarationResult) {
60
59
  generatedTitles = JsonSchemaBuilder.parseAllObjectSchemas(context, declarationResult.sourceFile.fileName, declarationResult.sourceFile.getFullText(), visitedFiles);
@@ -70,7 +69,7 @@ export class TypeScriptToSchema {
70
69
  generatedSchemas[generatedTitle] = generatedSchema;
71
70
  }
72
71
  }
73
- if (Utility.isTypeNameInput(sourceFileOrTypeName)) {
72
+ if (this.isTypeNameInput(sourceFileOrTypeName)) {
74
73
  const requestedTitle = StringHelper.stripPrefix(sourceFileOrTypeName);
75
74
  const requestedSchema = context.schemas[context.packageName][requestedTitle];
76
75
  if (requestedSchema) {
@@ -98,5 +97,16 @@ export class TypeScriptToSchema {
98
97
  const packagePathNoTrailingSlash = `/node_modules/${normalisedPackageName}`;
99
98
  return sourcePaths.some(sourcePath => sourcePath.includes(packagePath) || sourcePath.endsWith(packagePathNoTrailingSlash));
100
99
  }
100
+ /**
101
+ * Determine whether an input value is a valid TypeScript type identifier.
102
+ * An identifier must start with a letter, underscore, or dollar sign and contain only
103
+ * alphanumerics, underscores, or dollar signs thereafter.
104
+ * @param value The value to inspect.
105
+ * @returns True if the value looks like a type name.
106
+ * @internal
107
+ */
108
+ isTypeNameInput(value) {
109
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(value);
110
+ }
101
111
  }
102
112
  //# sourceMappingURL=typeScriptToSchema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typeScriptToSchema.js","sourceRoot":"","sources":["../../../src/utils/typeScriptToSchema.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIvC;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAC9B;;;;;;;;OAQG;IACI,KAAK,CAAC,cAAc,CAC1B,SAAiB,EACjB,WAAmB,EACnB,OAAwD,EACxD,oBAA4B,EAC5B,OAAoC;QAEpC,MAAM,uBAAuB,GAAG,CAAC,OAAO,EAAE,uBAAuB,IAAI,EAAE,CAAC;aACtE,MAAM,CAAC,iBAAiB,CAAC,EAAE,CAAC,EAAE,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;aAC9D,GAAG,CAAC,iBAAiB,CAAC,EAAE,CAAC,iBAAiB,CAAC,WAAW,EAAE,CAAC,CAAC;QAC5D,MAAM,eAAe,GAA+B;YACnD,GAAG,OAAO;YACV,YAAY,EAAE,UAAU,CAAC,EAAE;gBAC1B,IACC,uBAAuB,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAC5C,IAAI,CAAC,uBAAuB,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,aAAa,CAAC,CACjF,EACA,CAAC;oBACF,OAAO;gBACR,CAAC;gBAED,O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GAAG,WAAW,CAAC,WAAW,EAAE,CAAC;QACxD,MAAM,WAAW,GAAG,iBAAiB,qBAAqB,GAAG,CAAC;QAC9D,MAAM,0BAA0B,GAAG,iBAAiB,qBAAqB,EAAE,CAAC;QAE5E,OAAO,WAAW,CAAC,IAAI,CACtB,UAAU,CAAC,EAAE,CACZ,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,0BAA0B,CAAC,CACpF,CAAC;IACH,CAAC;CACD","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is, StringHelper } from \"@twin.org/core\";\nimport type { IJsonSchema } from \"@twin.org/tools-models\";\nimport { FileUtils } from \"./fileUtils.js\";\nimport { JsonSchemaBuilder } from \"./jsonSchemaBuilder.js\";\nimport { Resolver } from \"./resolver.js\";\nimport { Utility } from \"./utility.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 (Utility.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 (Utility.isTypeNameInput(sourceFileOrTypeName)) {\n\t\t\tconst requestedTitle = StringHelper.stripPrefix(sourceFileOrTypeName);\n\t\t\tconst requestedSchema = context.schemas[context.packageName][requestedTitle];\n\t\t\tif (requestedSchema) {\n\t\t\t\tgeneratedSchemas[requestedTitle] = requestedSchema;\n\t\t\t}\n\t\t}\n\n\t\treturn generatedSchemas;\n\t}\n\n\t/**\n\t * Determine if a diagnostic originates from a specific package.\n\t * @param path The schema or source path associated with the diagnostic.\n\t * @param fileName The source filename associated with the diagnostic.\n\t * @param packageName The package name to check, e.g. jose.\n\t * @returns True if the diagnostic originated from the package.\n\t */\n\tpublic isDiagnosticFromPackage(\n\t\tpath: string,\n\t\tfileName: string | undefined,\n\t\tpackageName: string\n\t): boolean {\n\t\tif (!Is.stringValue(packageName)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst sourcePaths = [fileName, path]\n\t\t\t.filter((value): value is string => Is.stringValue(value))\n\t\t\t.map(value => value.replace(/\\\\/g, \"/\").toLowerCase());\n\t\tconst normalisedPackageName = packageName.toLowerCase();\n\t\tconst packagePath = `/node_modules/${normalisedPackageName}/`;\n\t\tconst packagePathNoTrailingSlash = `/node_modules/${normalisedPackageName}`;\n\n\t\treturn sourcePaths.some(\n\t\t\tsourcePath =>\n\t\t\t\tsourcePath.includes(packagePath) || sourcePath.endsWith(packageP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,UAAU,CAAC,EAAE,CACZ,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,0BAA0B,CAAC,CACpF,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACK,eAAe,CAAC,KAAa;QACpC,OAAO,6BAA6B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;CACD","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is, StringHelper } from \"@twin.org/core\";\nimport type { IJsonSchema } from \"@twin.org/tools-models\";\nimport { FileUtils } from \"./fileUtils.js\";\nimport { JsonSchemaBuilder } from \"./jsonSchemaBuilder.js\";\nimport { Resolver } from \"./resolver.js\";\nimport type { ITypeScriptToSchemaContext } from \"../models/ITypeScriptToSchemaContext.js\";\nimport type { ITypeScriptToSchemaOptions } from \"../models/ITypeScriptToSchemaOptions.js\";\n\n/**\n * Class for converting TypeScript types to JSON Schema.\n */\nexport class TypeScriptToSchema {\n\t/**\n\t * Generates a JSON schema from a TypeScript source file or type name.\n\t * @param namespace The schema namespace.\n\t * @param packageName The package name.\n\t * @param schemas The package schema map.\n\t * @param sourceFileOrTypeName The source file to process or type name to resolve.\n\t * @param options Additional generation options.\n\t * @returns The generated JSON schemas indexed by title.\n\t */\n\tpublic async generateSchema(\n\t\tnamespace: string,\n\t\tpackageName: string,\n\t\tschemas: { [id: string]: { [id: string]: IJsonSchema } },\n\t\tsourceFileOrTypeName: string,\n\t\toptions?: ITypeScriptToSchemaOptions\n\t): Promise<{ [id: string]: IJsonSchema }> {\n\t\tconst suppressPackageWarnings = (options?.suppressPackageWarnings ?? [])\n\t\t\t.filter(packageNameToSkip => Is.stringValue(packageNameToSkip))\n\t\t\t.map(packageNameToSkip => packageNameToSkip.toLowerCase());\n\t\tconst filteredOptions: ITypeScriptToSchemaOptions = {\n\t\t\t...options,\n\t\t\tonDiagnostic: diagnostic => {\n\t\t\t\tif (\n\t\t\t\t\tsuppressPackageWarnings.some(packageToSkip =>\n\t\t\t\t\t\tthis.isDiagnosticFromPackage(diagnostic.path, diagnostic.fileName, packageToSkip)\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\toptions?.onDiagnostic?.(diagnostic);\n\t\t\t}\n\t\t};\n\n\t\tconst context: ITypeScriptToSchemaContext = {\n\t\t\tnamespace,\n\t\t\tpackageName,\n\t\t\tschemas,\n\t\t\toptions: filteredOptions\n\t\t};\n\n\t\tlet generatedTitles: string[] = [];\n\t\tcontext.schemas[context.packageName] ??= {};\n\t\tconst visitedFiles: string[] = [];\n\t\tconst sourceFiles = FileUtils.resolveSourceFiles(sourceFileOrTypeName);\n\n\t\tif (sourceFiles.length > 0) {\n\t\t\tfor (const sourceFilePath of sourceFiles) {\n\t\t\t\tconst source = FileUtils.readFile(sourceFilePath);\n\t\t\t\tif (source) {\n\t\t\t\t\tconst parsedTitles = JsonSchemaBuilder.parseAllObjectSchemas(\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tsourceFilePath,\n\t\t\t\t\t\tsource,\n\t\t\t\t\t\tvisitedFiles\n\t\t\t\t\t);\n\t\t\t\t\tfor (const parsedTitle of parsedTitles) {\n\t\t\t\t\t\tif (!generatedTitles.includes(parsedTitle)) {\n\t\t\t\t\t\t\tgeneratedTitles.push(parsedTitle);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.isTypeNameInput(sourceFileOrTypeName)) {\n\t\t\tconst declarationResult = Resolver.resolveTypeDeclarationAst(\n\t\t\t\tcontext.packageName,\n\t\t\t\tsourceFileOrTypeName\n\t\t\t);\n\t\t\tif (declarationResult) {\n\t\t\t\tgeneratedTitles = JsonSchemaBuilder.parseAllObjectSchemas(\n\t\t\t\t\tcontext,\n\t\t\t\t\tdeclarationResult.sourceFile.fileName,\n\t\t\t\t\tdeclarationResult.sourceFile.getFullText(),\n\t\t\t\t\tvisitedFiles\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\treturn {};\n\t\t}\n\n\t\tconst generatedSchemas: { [id: string]: IJsonSchema } = {};\n\t\tfor (const generatedTitle of generatedTitles) {\n\t\t\tconst generatedSchema = context.schemas[context.packageName][generatedTitle];\n\t\t\tif (generatedSchema) {\n\t\t\t\tgeneratedSchemas[generatedTitle] = generatedSchema;\n\t\t\t}\n\t\t}\n\n\t\tif (this.isTypeNameInput(sourceFileOrTypeName)) {\n\t\t\tconst requestedTitle = StringHelper.stripPrefix(sourceFileOrTypeName);\n\t\t\tconst requestedSchema = context.schemas[context.packageName][requestedTitle];\n\t\t\tif (requestedSchema) {\n\t\t\t\tgeneratedSchemas[requestedTitle] = requestedSchema;\n\t\t\t}\n\t\t}\n\n\t\treturn generatedSchemas;\n\t}\n\n\t/**\n\t * Determine if a diagnostic originates from a specific package.\n\t * @param path The schema or source path associated with the diagnostic.\n\t * @param fileName The source filename associated with the diagnostic.\n\t * @param packageName The package name to check, e.g. jose.\n\t * @returns True if the diagnostic originated from the package.\n\t */\n\tpublic isDiagnosticFromPackage(\n\t\tpath: string,\n\t\tfileName: string | undefined,\n\t\tpackageName: string\n\t): boolean {\n\t\tif (!Is.stringValue(packageName)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst sourcePaths = [fileName, path]\n\t\t\t.filter((value): value is string => Is.stringValue(value))\n\t\t\t.map(value => value.replace(/\\\\/g, \"/\").toLowerCase());\n\t\tconst normalisedPackageName = packageName.toLowerCase();\n\t\tconst packagePath = `/node_modules/${normalisedPackageName}/`;\n\t\tconst packagePathNoTrailingSlash = `/node_modules/${normalisedPackageName}`;\n\n\t\treturn sourcePaths.some(\n\t\t\tsourcePath =>\n\t\t\t\tsourcePath.includes(packagePath) || sourcePath.endsWith(packagePathNoTrailingSlash)\n\t\t);\n\t}\n\n\t/**\n\t * Determine whether an input value is a valid TypeScript type identifier.\n\t * An identifier must start with a letter, underscore, or dollar sign and contain only\n\t * alphanumerics, underscores, or dollar signs thereafter.\n\t * @param value The value to inspect.\n\t * @returns True if the value looks like a type name.\n\t * @internal\n\t */\n\tprivate isTypeNameInput(value: string): boolean {\n\t\treturn /^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(value);\n\t}\n}\n"]}
@@ -16,5 +16,5 @@ export * from "./utils/regEx.js";
16
16
  export * from "./utils/resolver.js";
17
17
  export * from "./utils/templateLiteralPatternBuilder.js";
18
18
  export * from "./utils/typeScriptToSchema.js";
19
- export * from "./utils/utility.js";
19
+ export * from "./utils/jsDoc.js";
20
20
  export * from "./utils/utilityTypeSchemaMapper.js";
@@ -1,27 +1,8 @@
1
1
  import * as ts from "typescript";
2
2
  /**
3
- * General-purpose utility methods for working with TypeScript AST nodes.
4
- *
5
- * Enum-related helpers live in TypeScriptEnum.
6
- * Reference-mapping regex helpers live in TypeScriptRegEx.
3
+ * General-purpose utility methods for working with JsDoc.
7
4
  */
8
- export declare class Utility {
9
- /**
10
- * Determine whether an input value is a valid TypeScript type identifier.
11
- * An identifier must start with a letter, underscore, or dollar sign and contain only
12
- * alphanumerics, underscores, or dollar signs thereafter.
13
- * @param value The value to inspect.
14
- * @returns True if the value looks like a type name.
15
- */
16
- static isTypeNameInput(value: string): boolean;
17
- /**
18
- * Extract the inner type node from a named or rest tuple element.
19
- * Named tuple members and rest elements both wrap an inner type node; this unwraps them.
20
- * Plain type nodes are returned as-is.
21
- * @param element The tuple element.
22
- * @returns The inner type node.
23
- */
24
- static extractTupleElementType(element: ts.TypeNode): ts.TypeNode | undefined;
5
+ export declare class JsDoc {
25
6
  /**
26
7
  * Extract the JSDoc description comment for an AST node.
27
8
  * Only top-level JSDoc block comments are considered; inline tags are ignored.
@@ -47,6 +28,13 @@ export declare class Utility {
47
28
  static getNodeTags(node: ts.Node, tagName: string): {
48
29
  [id: string]: string;
49
30
  };
31
+ /**
32
+ * Read the plain comment text for the first matching JSDoc tag on a node.
33
+ * @param node The node to inspect.
34
+ * @param tagName The tag name to filter by (e.g., 'default').
35
+ * @returns The trimmed comment text, or undefined when absent.
36
+ */
37
+ static getNodeTagComment(node: ts.Node, tagName: string): string | undefined;
50
38
  /**
51
39
  * Parse a custom JSDoc tag value into JSON-compatible data.
52
40
  * Values that begin with a JSON token character ({, [, ", true, false, null) or look like a
@@ -112,6 +112,14 @@ export declare class JsonSchemaBuilder {
112
112
  * @returns The mapped schema.
113
113
  */
114
114
  static mapTypeNodeToSchema(context: ITypeScriptToSchemaContext, typeNode: ts.TypeNode): IJsonSchema | undefined;
115
+ /**
116
+ * Determine whether a union of primitive keyword branches is pairwise disjoint.
117
+ * @param unionTypeNode The union node being mapped.
118
+ * @param unionTypeNodes The original union branch type nodes.
119
+ * @param unionSchemas The mapped union branch schemas.
120
+ * @returns True if every branch is a primitive keyword schema and no branches overlap.
121
+ */
122
+ static isDisjointPrimitiveKeywordUnion(unionTypeNode: ts.UnionTypeNode, unionTypeNodes: ts.NodeArray<ts.TypeNode>, unionSchemas: IJsonSchema[]): boolean;
115
123
  /**
116
124
  * Determine whether a union of schemas represents mutually exclusive object branches.
117
125
  * @param context The generation context.
@@ -718,4 +726,12 @@ export declare class JsonSchemaBuilder {
718
726
  * @returns The schema key.
719
727
  */
720
728
  static mapJsonSchemaTagKey(key: string): string;
729
+ /**
730
+ * Extract the inner type node from a named or rest tuple element.
731
+ * Named tuple members and rest elements both wrap an inner type node; this unwraps them.
732
+ * Plain type nodes are returned as-is.
733
+ * @param element The tuple element.
734
+ * @returns The inner type node.
735
+ */
736
+ static extractTupleElementType(element: ts.TypeNode): ts.TypeNode | undefined;
721
737
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.18](https://github.com/twinfoundation/tools/compare/tools-core-v0.0.3-next.17...tools-core-v0.0.3-next.18) (2026-03-19)
4
+
5
+
6
+ ### Features
7
+
8
+ * add jsdoc default value to schema ([7886a84](https://github.com/twinfoundation/tools/commit/7886a84961e692d2054f223e2e99205a654b76a6))
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.17 to 0.0.3-next.18
16
+
17
+ ## [0.0.3-next.17](https://github.com/twinfoundation/tools/compare/tools-core-v0.0.3-next.16...tools-core-v0.0.3-next.17) (2026-03-19)
18
+
19
+
20
+ ### Features
21
+
22
+ * improve discriminated unions ([9c36ea7](https://github.com/twinfoundation/tools/commit/9c36ea7283230089ff19085ddc4b4c30a4e3f8a2))
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @twin.org/tools-models bumped from 0.0.3-next.16 to 0.0.3-next.17
30
+
3
31
  ## [0.0.3-next.16](https://github.com/twinfoundation/tools/compare/tools-core-v0.0.3-next.15...tools-core-v0.0.3-next.16) (2026-03-19)
4
32
 
5
33
 
@@ -1,70 +1,19 @@
1
- # Class: Utility
1
+ # Class: JsDoc
2
2
 
3
- General-purpose utility methods for working with TypeScript AST nodes.
4
-
5
- Enum-related helpers live in TypeScriptEnum.
6
- Reference-mapping regex helpers live in TypeScriptRegEx.
3
+ General-purpose utility methods for working with JsDoc.
7
4
 
8
5
  ## Constructors
9
6
 
10
7
  ### Constructor
11
8
 
12
- > **new Utility**(): `Utility`
9
+ > **new JsDoc**(): `JsDoc`
13
10
 
14
11
  #### Returns
15
12
 
16
- `Utility`
13
+ `JsDoc`
17
14
 
18
15
  ## Methods
19
16
 
20
- ### isTypeNameInput() {#istypenameinput}
21
-
22
- > `static` **isTypeNameInput**(`value`): `boolean`
23
-
24
- Determine whether an input value is a valid TypeScript type identifier.
25
- An identifier must start with a letter, underscore, or dollar sign and contain only
26
- alphanumerics, underscores, or dollar signs thereafter.
27
-
28
- #### Parameters
29
-
30
- ##### value
31
-
32
- `string`
33
-
34
- The value to inspect.
35
-
36
- #### Returns
37
-
38
- `boolean`
39
-
40
- True if the value looks like a type name.
41
-
42
- ***
43
-
44
- ### extractTupleElementType() {#extracttupleelementtype}
45
-
46
- > `static` **extractTupleElementType**(`element`): `TypeNode` \| `undefined`
47
-
48
- Extract the inner type node from a named or rest tuple element.
49
- Named tuple members and rest elements both wrap an inner type node; this unwraps them.
50
- Plain type nodes are returned as-is.
51
-
52
- #### Parameters
53
-
54
- ##### element
55
-
56
- `TypeNode`
57
-
58
- The tuple element.
59
-
60
- #### Returns
61
-
62
- `TypeNode` \| `undefined`
63
-
64
- The inner type node.
65
-
66
- ***
67
-
68
17
  ### getNodeJsDocDescription() {#getnodejsdocdescription}
69
18
 
70
19
  > `static` **getNodeJsDocDescription**(`node`): `string` \| `undefined`
@@ -141,6 +90,34 @@ The extracted key/value pairs.
141
90
 
142
91
  ***
143
92
 
93
+ ### getNodeTagComment() {#getnodetagcomment}
94
+
95
+ > `static` **getNodeTagComment**(`node`, `tagName`): `string` \| `undefined`
96
+
97
+ Read the plain comment text for the first matching JSDoc tag on a node.
98
+
99
+ #### Parameters
100
+
101
+ ##### node
102
+
103
+ `Node`
104
+
105
+ The node to inspect.
106
+
107
+ ##### tagName
108
+
109
+ `string`
110
+
111
+ The tag name to filter by (e.g., 'default').
112
+
113
+ #### Returns
114
+
115
+ `string` \| `undefined`
116
+
117
+ The trimmed comment text, or undefined when absent.
118
+
119
+ ***
120
+
144
121
  ### parseTagValue() {#parsetagvalue}
145
122
 
146
123
  > `static` **parseTagValue**(`value`): `unknown`
@@ -376,6 +376,40 @@ The mapped schema.
376
376
 
377
377
  ***
378
378
 
379
+ ### isDisjointPrimitiveKeywordUnion() {#isdisjointprimitivekeywordunion}
380
+
381
+ > `static` **isDisjointPrimitiveKeywordUnion**(`unionTypeNode`, `unionTypeNodes`, `unionSchemas`): `boolean`
382
+
383
+ Determine whether a union of primitive keyword branches is pairwise disjoint.
384
+
385
+ #### Parameters
386
+
387
+ ##### unionTypeNode
388
+
389
+ `UnionTypeNode`
390
+
391
+ The union node being mapped.
392
+
393
+ ##### unionTypeNodes
394
+
395
+ `NodeArray`\<`TypeNode`\>
396
+
397
+ The original union branch type nodes.
398
+
399
+ ##### unionSchemas
400
+
401
+ `IJsonSchema`[]
402
+
403
+ The mapped union branch schemas.
404
+
405
+ #### Returns
406
+
407
+ `boolean`
408
+
409
+ True if every branch is a primitive keyword schema and no branches overlap.
410
+
411
+ ***
412
+
379
413
  ### isNeverDiscriminatedObjectUnion() {#isneverdiscriminatedobjectunion}
380
414
 
381
415
  > `static` **isNeverDiscriminatedObjectUnion**(`context`, `unionTypeNodes`, `unionSchemas`): `boolean`
@@ -2770,3 +2804,27 @@ The raw tag key.
2770
2804
  `string`
2771
2805
 
2772
2806
  The schema key.
2807
+
2808
+ ***
2809
+
2810
+ ### extractTupleElementType() {#extracttupleelementtype}
2811
+
2812
+ > `static` **extractTupleElementType**(`element`): `TypeNode` \| `undefined`
2813
+
2814
+ Extract the inner type node from a named or rest tuple element.
2815
+ Named tuple members and rest elements both wrap an inner type node; this unwraps them.
2816
+ Plain type nodes are returned as-is.
2817
+
2818
+ #### Parameters
2819
+
2820
+ ##### element
2821
+
2822
+ `TypeNode`
2823
+
2824
+ The tuple element.
2825
+
2826
+ #### Returns
2827
+
2828
+ `TypeNode` \| `undefined`
2829
+
2830
+ The inner type node.
@@ -10,6 +10,7 @@
10
10
  - [ImportTypeQuerySchemaResolver](classes/ImportTypeQuerySchemaResolver.md)
11
11
  - [IndexSignaturePatternResolver](classes/IndexSignaturePatternResolver.md)
12
12
  - [IntersectionSchemaMerger](classes/IntersectionSchemaMerger.md)
13
+ - [JsDoc](classes/JsDoc.md)
13
14
  - [JsonSchemaBuilder](classes/JsonSchemaBuilder.md)
14
15
  - [MappedTypeSchemaResolver](classes/MappedTypeSchemaResolver.md)
15
16
  - [ObjectTransformer](classes/ObjectTransformer.md)
@@ -17,7 +18,6 @@
17
18
  - [Resolver](classes/Resolver.md)
18
19
  - [TemplateLiteralPatternBuilder](classes/TemplateLiteralPatternBuilder.md)
19
20
  - [TypeScriptToSchema](classes/TypeScriptToSchema.md)
20
- - [Utility](classes/Utility.md)
21
21
  - [UtilityTypeSchemaMapper](classes/UtilityTypeSchemaMapper.md)
22
22
 
23
23
  ## Interfaces
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/tools-core",
3
- "version": "0.0.3-next.16",
3
+ "version": "0.0.3-next.18",
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.16",
19
+ "@twin.org/tools-models": "0.0.3-next.18",
20
20
  "glob": "13.0.6"
21
21
  },
22
22
  "main": "./dist/es/index.js",
@@ -1 +0,0 @@
1
- {"version":3,"file":"utility.js","sourceRoot":"","sources":["../../../src/utils/utility.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,OAAO,OAAO;IACnB;;;;;;OAMG;IACI,MAAM,CAAC,eAAe,CAAC,KAAa;QAC1C,OAAO,6BAA6B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,uBAAuB,CAAC,OAAoB;QACzD,2EAA2E;QAC3E,IAAI,EAAE,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;YACpC,OAAO,OAAO,CAAC,IAAI,CAAC;QACrB,CAAC;QAED,kFAAkF;QAClF,IAAI,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;YAChC,OAAO,OAAO,CAAC,IAAI,CAAC;QACrB,CAAC;QAED,OAAO,OAAO,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,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C,MAAM,CAAC;YACR,OAAO,YAAY,CAAC;QACrB,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is } from \"@twin.org/core\";\nimport * as ts from \"typescript\";\n\n/**\n * General-purpose utility methods for working with TypeScript AST nodes.\n *\n * Enum-related helpers live in TypeScriptEnum.\n * Reference-mapping regex helpers live in TypeScriptRegEx.\n */\nexport class Utility {\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 */\n\tpublic static isTypeNameInput(value: string): boolean {\n\t\treturn /^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(value);\n\t}\n\n\t/**\n\t * Extract the inner type node from a named or rest tuple element.\n\t * Named tuple members and rest elements both wrap an inner type node; this unwraps them.\n\t * Plain type nodes are returned as-is.\n\t * @param element The tuple element.\n\t * @returns The inner type node.\n\t */\n\tpublic static extractTupleElementType(element: ts.TypeNode): ts.TypeNode | undefined {\n\t\t// label: string (named tuple member, e.g. [label: string, count: number])\n\t\tif (ts.isNamedTupleMember(element)) {\n\t\t\treturn element.type;\n\t\t}\n\n\t\t// ...string[] (rest element in a tuple, e.g. [first: string, ...rest: string[]])\n\t\tif (ts.isRestTypeNode(element)) {\n\t\t\treturn element.type;\n\t\t}\n\n\t\treturn element;\n\t}\n\n\t/**\n\t * Extract the JSDoc description comment for an AST node.\n\t * Only top-level JSDoc block comments are considered; inline tags are ignored.\n\t * @param node The node to inspect.\n\t * @returns The trimmed description text, or undefined when absent.\n\t */\n\tpublic static getNodeJsDocDescription(node: ts.Node): string | undefined {\n\t\t// /** Description text */ (JSDoc block attached to a declaration)\n\t\tconst jsDocNodes = ts\n\t\t\t.getJSDocCommentsAndTags(node)\n\t\t\t.filter(commentOrTag => ts.isJSDoc(commentOrTag));\n\t\tconst description = jsDocNodes\n\t\t\t.map(jsDocNode => ts.getTextOfJSDocComment(jsDocNode.comment)?.trim())\n\t\t\t.find((value): value is string => Boolean(value));\n\n\t\tif (description) {\n\t\t\treturn description;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Convert a JSDoc tag's comment portion to a plain text string.\n\t * JSDoc tag comments may be plain strings or arrays of link/text parts.\n\t * @param jsDocTag The JSDoc tag.\n\t * @returns The comment text, or undefined when absent.\n\t */\n\tpublic static getJSDocTagCommentText(jsDocTag: ts.JSDocTag): string | undefined {\n\t\tif (Is.string(jsDocTag.comment)) {\n\t\t\treturn jsDocTag.comment;\n\t\t}\n\n\t\tif (Array.isArray(jsDocTag.comment)) {\n\t\t\treturn jsDocTag.comment\n\t\t\t\t.map(part => part.text)\n\t\t\t\t.join(\"\")\n\t\t\t\t.trim();\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Read all custom JSDoc tags matching a tag name from a node and convert them to key/value pairs.\n\t * Each matching tag's comment must be in the form \"key: value\"; entries that do not follow this\n\t * convention are silently skipped.\n\t * @param node The node to inspect.\n\t * @param tagName The tag name to filter by (e.g., 'json-schema').\n\t * @returns The extracted key/value pairs.\n\t */\n\tpublic static getNodeTags(node: ts.Node, tagName: string): { [id: string]: string } {\n\t\tconst output: { [id: string]: string } = {};\n\t\tfor (const jsDocTag of ts.getJSDocTags(node)) {\n\t\t\tif (jsDocTag.tagName.text === tagName) {\n\t\t\t\tconst commentText = Utility.getJSDocTagCommentText(jsDocTag);\n\t\t\t\tif (commentText) {\n\t\t\t\t\tconst separatorIndex = commentText.indexOf(\":\");\n\t\t\t\t\tif (separatorIndex > 0) {\n\t\t\t\t\t\tconst key = commentText.slice(0, separatorIndex).trim();\n\t\t\t\t\t\tconst value = commentText.slice(separatorIndex + 1).trim();\n\t\t\t\t\t\tif (key.length > 0) {\n\t\t\t\t\t\t\toutput[key] = value;\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}\n\n\t\treturn output;\n\t}\n\n\t/**\n\t * Parse a custom JSDoc tag value into JSON-compatible data.\n\t * Values that begin with a JSON token character ({, [, \", true, false, null) or look like a\n\t * number are parsed with JSON.parse. All other values are returned as plain strings.\n\t * @param value The raw value text.\n\t * @returns The parsed value.\n\t */\n\tpublic static parseTagValue(value: string): unknown {\n\t\tconst trimmedValue = value.trim();\n\t\tif (trimmedValue.length === 0) {\n\t\t\treturn \"\";\n\t\t}\n\n\t\tconst startsWithJsonToken =\n\t\t\ttrimmedValue.startsWith(\"{\") ||\n\t\t\ttrimmedValue.startsWith(\"[\") ||\n\t\t\ttrimmedValue.startsWith('\"') ||\n\t\t\ttrimmedValue === \"true\" ||\n\t\t\ttrimmedValue === \"false\" ||\n\t\t\ttrimmedValue === \"null\" ||\n\t\t\t/^-?\\d+(\\.\\d+)?$/u.test(trimmedValue);\n\n\t\tif (!startsWithJsonToken) {\n\t\t\treturn trimmedValue;\n\t\t}\n\n\t\ttry {\n\t\t\treturn JSON.parse(trimmedValue);\n\t\t} catch {\n\t\t\treturn trimmedValue;\n\t\t}\n\t}\n}\n"]}