ajsc 5.2.3 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +253 -145
- package/dist/converter/BaseConverter.d.ts +283 -0
- package/dist/converter/BaseConverter.js +131 -0
- package/dist/converter/BaseConverter.js.map +1 -0
- package/dist/converter/Emitter.d.ts +35 -0
- package/dist/converter/Emitter.js +50 -0
- package/dist/converter/Emitter.js.map +1 -0
- package/dist/converter/discriminatedUnions.d.ts +47 -0
- package/dist/converter/discriminatedUnions.js +168 -0
- package/dist/converter/discriminatedUnions.js.map +1 -0
- package/dist/converter/formatDefault.d.ts +20 -0
- package/dist/converter/formatDefault.js +31 -0
- package/dist/converter/formatDefault.js.map +1 -0
- package/dist/converter/index.d.ts +2 -0
- package/dist/converter/index.js +2 -0
- package/dist/converter/index.js.map +1 -0
- package/dist/converter/mergeUnions.d.ts +36 -0
- package/dist/converter/mergeUnions.js +189 -0
- package/dist/converter/mergeUnions.js.map +1 -0
- package/dist/converter/naming.d.ts +29 -0
- package/dist/converter/naming.js +130 -0
- package/dist/converter/naming.js.map +1 -0
- package/dist/converter/registry.d.ts +18 -0
- package/dist/converter/registry.js +50 -0
- package/dist/converter/registry.js.map +1 -0
- package/dist/converter/walk.d.ts +9 -0
- package/dist/converter/walk.js +40 -0
- package/dist/converter/walk.js.map +1 -0
- package/dist/index.d.ts +71 -3
- package/dist/index.js +63 -3
- package/dist/index.js.map +1 -1
- package/dist/{JSONSchemaConverter.d.ts → ir/JSONSchemaConverter.d.ts} +1 -1
- package/dist/{JSONSchemaConverter.js → ir/JSONSchemaConverter.js} +9 -3
- package/dist/ir/JSONSchemaConverter.js.map +1 -0
- package/dist/ir/index.d.ts +1 -0
- package/dist/ir/index.js +2 -0
- package/dist/ir/index.js.map +1 -0
- package/dist/kotlin/KotlinBaseConverter.d.ts +18 -0
- package/dist/kotlin/KotlinBaseConverter.js +36 -0
- package/dist/kotlin/KotlinBaseConverter.js.map +1 -0
- package/dist/kotlin/KotlinConverter.d.ts +67 -0
- package/dist/kotlin/KotlinConverter.js +140 -0
- package/dist/kotlin/KotlinConverter.js.map +1 -0
- package/dist/kotlin/annotations.d.ts +26 -0
- package/dist/kotlin/annotations.js +35 -0
- package/dist/kotlin/annotations.js.map +1 -0
- package/dist/kotlin/enums.d.ts +15 -0
- package/dist/kotlin/enums.js +58 -0
- package/dist/kotlin/enums.js.map +1 -0
- package/dist/kotlin/index.d.ts +2 -0
- package/dist/kotlin/index.js +3 -0
- package/dist/kotlin/index.js.map +1 -0
- package/dist/kotlin/objectEmitter.d.ts +12 -0
- package/dist/kotlin/objectEmitter.js +74 -0
- package/dist/kotlin/objectEmitter.js.map +1 -0
- package/dist/kotlin/sealedUnion.d.ts +17 -0
- package/dist/kotlin/sealedUnion.js +74 -0
- package/dist/kotlin/sealedUnion.js.map +1 -0
- package/dist/kotlin/typeMapper.d.ts +17 -0
- package/dist/kotlin/typeMapper.js +107 -0
- package/dist/kotlin/typeMapper.js.map +1 -0
- package/dist/kotlin/unsupported.d.ts +13 -0
- package/dist/kotlin/unsupported.js +53 -0
- package/dist/kotlin/unsupported.js.map +1 -0
- package/dist/swift/SwiftBaseConverter.d.ts +18 -0
- package/dist/swift/SwiftBaseConverter.js +38 -0
- package/dist/swift/SwiftBaseConverter.js.map +1 -0
- package/dist/swift/SwiftConverter.d.ts +60 -0
- package/dist/swift/SwiftConverter.js +111 -0
- package/dist/swift/SwiftConverter.js.map +1 -0
- package/dist/swift/discriminatedEnum.d.ts +18 -0
- package/dist/swift/discriminatedEnum.js +99 -0
- package/dist/swift/discriminatedEnum.js.map +1 -0
- package/dist/swift/enums.d.ts +15 -0
- package/dist/swift/enums.js +62 -0
- package/dist/swift/enums.js.map +1 -0
- package/dist/swift/index.d.ts +2 -0
- package/dist/swift/index.js +3 -0
- package/dist/swift/index.js.map +1 -0
- package/dist/swift/structEmitter.d.ts +12 -0
- package/dist/swift/structEmitter.js +70 -0
- package/dist/swift/structEmitter.js.map +1 -0
- package/dist/swift/typeMapper.d.ts +18 -0
- package/dist/swift/typeMapper.js +106 -0
- package/dist/swift/typeMapper.js.map +1 -0
- package/dist/swift/unsupported.d.ts +19 -0
- package/dist/swift/unsupported.js +88 -0
- package/dist/swift/unsupported.js.map +1 -0
- package/dist/typescript/TypescriptBaseConverter.d.ts +25 -0
- package/dist/typescript/TypescriptBaseConverter.js +178 -0
- package/dist/typescript/TypescriptBaseConverter.js.map +1 -0
- package/dist/typescript/TypescriptConverter.d.ts +74 -0
- package/dist/typescript/TypescriptConverter.js +252 -0
- package/dist/typescript/TypescriptConverter.js.map +1 -0
- package/dist/typescript/index.d.ts +2 -0
- package/dist/typescript/index.js +3 -0
- package/dist/typescript/index.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +37 -5
- package/dist/JSONSchemaConverter.js.map +0 -1
- package/dist/JSONSchemaConverter.test.d.ts +0 -1
- package/dist/JSONSchemaConverter.test.js +0 -585
- package/dist/JSONSchemaConverter.test.js.map +0 -1
- package/dist/Typebox.test.d.ts +0 -1
- package/dist/Typebox.test.js +0 -88
- package/dist/Typebox.test.js.map +0 -1
- package/dist/TypescriptBaseConverter.d.ts +0 -75
- package/dist/TypescriptBaseConverter.js +0 -321
- package/dist/TypescriptBaseConverter.js.map +0 -1
- package/dist/TypescriptConverter.additionalProperties.test.d.ts +0 -1
- package/dist/TypescriptConverter.additionalProperties.test.js +0 -110
- package/dist/TypescriptConverter.additionalProperties.test.js.map +0 -1
- package/dist/TypescriptConverter.arrays.test.d.ts +0 -1
- package/dist/TypescriptConverter.arrays.test.js +0 -130
- package/dist/TypescriptConverter.arrays.test.js.map +0 -1
- package/dist/TypescriptConverter.composites.advanced.test.d.ts +0 -1
- package/dist/TypescriptConverter.composites.advanced.test.js +0 -924
- package/dist/TypescriptConverter.composites.advanced.test.js.map +0 -1
- package/dist/TypescriptConverter.composites.test.d.ts +0 -1
- package/dist/TypescriptConverter.composites.test.js +0 -335
- package/dist/TypescriptConverter.composites.test.js.map +0 -1
- package/dist/TypescriptConverter.d.ts +0 -163
- package/dist/TypescriptConverter.js +0 -595
- package/dist/TypescriptConverter.js.map +0 -1
- package/dist/TypescriptConverter.jsdoc.test.d.ts +0 -1
- package/dist/TypescriptConverter.jsdoc.test.js +0 -194
- package/dist/TypescriptConverter.jsdoc.test.js.map +0 -1
- package/dist/TypescriptConverter.objects.test.d.ts +0 -1
- package/dist/TypescriptConverter.objects.test.js +0 -258
- package/dist/TypescriptConverter.objects.test.js.map +0 -1
- package/dist/TypescriptConverter.options.test.d.ts +0 -1
- package/dist/TypescriptConverter.options.test.js +0 -501
- package/dist/TypescriptConverter.options.test.js.map +0 -1
- package/dist/TypescriptConverter.primitives.test.d.ts +0 -1
- package/dist/TypescriptConverter.primitives.test.js +0 -26
- package/dist/TypescriptConverter.primitives.test.js.map +0 -1
- package/dist/utils/path-utils.test.d.ts +0 -1
- package/dist/utils/path-utils.test.js +0 -92
- package/dist/utils/path-utils.test.js.map +0 -1
package/dist/Typebox.test.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { JSONSchemaConverter } from "./JSONSchemaConverter.js";
|
|
3
|
-
import { Type } from "@sinclair/typebox";
|
|
4
|
-
describe("Typebox to IRNode Test", () => {
|
|
5
|
-
it("should convert strings", () => {
|
|
6
|
-
expect(new JSONSchemaConverter(Type.String()).irNode.type).toMatch("string");
|
|
7
|
-
});
|
|
8
|
-
it("should convert numbers", () => {
|
|
9
|
-
expect(new JSONSchemaConverter(Type.Number()).irNode.type).toMatch("number");
|
|
10
|
-
});
|
|
11
|
-
it("should convert booleans", () => {
|
|
12
|
-
expect(new JSONSchemaConverter(Type.Boolean()).irNode.type).toMatch("boolean");
|
|
13
|
-
});
|
|
14
|
-
it("should convert null", () => {
|
|
15
|
-
expect(new JSONSchemaConverter(Type.Null()).irNode.type).toMatch("null");
|
|
16
|
-
});
|
|
17
|
-
it("should convert literals", () => {
|
|
18
|
-
expect(new JSONSchemaConverter(Type.Literal("fixedValue")).irNode).toMatchObject({ type: "literal", constraints: { value: "fixedValue" } });
|
|
19
|
-
});
|
|
20
|
-
it("should convert enums", () => {
|
|
21
|
-
expect(new JSONSchemaConverter(Type.Enum({ Value1: "value1", Value2: "value2", Value3: "value3" })).irNode).toMatchObject({
|
|
22
|
-
type: "union",
|
|
23
|
-
options: [
|
|
24
|
-
{ type: "literal", constraints: { value: "value1" } },
|
|
25
|
-
{ type: "literal", constraints: { value: "value2" } },
|
|
26
|
-
{ type: "literal", constraints: { value: "value3" } },
|
|
27
|
-
],
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
it("should convert Record", () => {
|
|
31
|
-
expect(new JSONSchemaConverter(Type.Record(Type.String(), Type.Object({
|
|
32
|
-
name: Type.String(),
|
|
33
|
-
email: Type.String(),
|
|
34
|
-
}))).irNode).toMatchObject({
|
|
35
|
-
type: "object",
|
|
36
|
-
additionalProperties: {
|
|
37
|
-
type: "object",
|
|
38
|
-
properties: {
|
|
39
|
-
name: {
|
|
40
|
-
type: "string",
|
|
41
|
-
path: "*.name",
|
|
42
|
-
constraints: {},
|
|
43
|
-
required: true,
|
|
44
|
-
},
|
|
45
|
-
email: {
|
|
46
|
-
type: "string",
|
|
47
|
-
path: "*.email",
|
|
48
|
-
constraints: {},
|
|
49
|
-
required: true,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
it("should convert unions", () => {
|
|
56
|
-
expect(new JSONSchemaConverter(Type.Union([Type.String(), Type.Number()]))
|
|
57
|
-
.irNode).toMatchObject({
|
|
58
|
-
type: "union",
|
|
59
|
-
options: [{ type: "string" }, { type: "number" }],
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
it("should convert composite unions", () => {
|
|
63
|
-
expect(new JSONSchemaConverter(Type.Composite([
|
|
64
|
-
Type.Object({ a: Type.String() }),
|
|
65
|
-
Type.Object({ b: Type.Number() }),
|
|
66
|
-
])).irNode).toMatchObject({
|
|
67
|
-
type: "object",
|
|
68
|
-
properties: {
|
|
69
|
-
a: { type: "string", path: "a", required: true },
|
|
70
|
-
b: { type: "number", path: "b", required: true },
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
it("should convert intersections", () => {
|
|
75
|
-
expect(new JSONSchemaConverter(Type.Intersect([Type.String(), Type.Number()]))
|
|
76
|
-
.irNode).toMatchObject({
|
|
77
|
-
type: "intersection",
|
|
78
|
-
options: [{ type: "string" }, { type: "number" }],
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
it("should convert arrays", () => {
|
|
82
|
-
expect(new JSONSchemaConverter(Type.Array(Type.String())).irNode).toMatchObject({
|
|
83
|
-
type: "array",
|
|
84
|
-
items: { type: "string" },
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
//# sourceMappingURL=Typebox.test.js.map
|
package/dist/Typebox.test.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Typebox.test.js","sourceRoot":"","sources":["../src/Typebox.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,wBAAwB,EAAE,GAAG,EAAE;QAChC,MAAM,CAAC,IAAI,mBAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAChE,QAAQ,CACT,CAAC;IACJ,CAAC,CAAC,CAAC;IA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AC,aAAa,CAAC;YACd,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC1B,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { IRNode, SignatureOccurrenceValue } from "./types.js";
|
|
2
|
-
export type RefTypeName = string;
|
|
3
|
-
export type RefTypes = [
|
|
4
|
-
SignatureOccurrenceValue["signature"],
|
|
5
|
-
RefTypeName,
|
|
6
|
-
{
|
|
7
|
-
code: string;
|
|
8
|
-
title?: string;
|
|
9
|
-
description?: string;
|
|
10
|
-
}
|
|
11
|
-
][];
|
|
12
|
-
export interface RefTypeNamingConfig {
|
|
13
|
-
/** Base postfixes to try for name collision resolution */
|
|
14
|
-
postfixes: string[];
|
|
15
|
-
/** If true, singularize array item path segments (e.g. "entries" → "entry", "people" → "person") */
|
|
16
|
-
depluralize?: boolean;
|
|
17
|
-
/** If true, handle "*" path endings with AnyKey/AnyProperty postfixes */
|
|
18
|
-
handleAnySymbol?: boolean;
|
|
19
|
-
/** If true, strip leading "*" from proposed names */
|
|
20
|
-
stripLeadingAnySymbol?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Controls the postfix added to array item type names.
|
|
23
|
-
* - `false` (default) → no postfix, uses property name directly
|
|
24
|
-
* - `string` → custom postfix (e.g. "Item" → ContactsItem, "Element" → ContactsElement)
|
|
25
|
-
*/
|
|
26
|
-
arrayItemNaming?: string | false;
|
|
27
|
-
/**
|
|
28
|
-
* Additional words that should not be singularized when `depluralize` is true.
|
|
29
|
-
* Built-in uncountables: "data", "metadata".
|
|
30
|
-
* @example ["criteria", "alumni", "corpus"]
|
|
31
|
-
*/
|
|
32
|
-
uncountableWords?: string[];
|
|
33
|
-
}
|
|
34
|
-
export type GenerateTypeUtils = {
|
|
35
|
-
getReferencedType(ir: IRNode): string | undefined;
|
|
36
|
-
};
|
|
37
|
-
export declare abstract class TypescriptBaseConverter {
|
|
38
|
-
abstract readonly code: string;
|
|
39
|
-
protected refTypes: RefTypes;
|
|
40
|
-
/** Shared registry of all top-level declaration names (types + enums) for cross-namespace collision detection. */
|
|
41
|
-
protected usedDeclarationNames: Set<string>;
|
|
42
|
-
/** Root schema name, used as fallback context for root-level array item naming. */
|
|
43
|
-
protected rootName?: string;
|
|
44
|
-
protected emitJSDoc: boolean;
|
|
45
|
-
private fallbackCounter;
|
|
46
|
-
protected getRefTypeNamingConfig(): RefTypeNamingConfig;
|
|
47
|
-
/**
|
|
48
|
-
* Recursively generates a TypeScript type string for the given IR node.
|
|
49
|
-
*/
|
|
50
|
-
protected generateType(ir: IRNode, utils: GenerateTypeUtils): string;
|
|
51
|
-
protected generateArrayType(ir: IRNode, utils: GenerateTypeUtils): string;
|
|
52
|
-
protected generateTupleType(ir: IRNode, utils: GenerateTypeUtils): string;
|
|
53
|
-
protected generateUnionType(ir: IRNode, utils: GenerateTypeUtils): string;
|
|
54
|
-
protected generateIntersectionType(ir: IRNode, utils: GenerateTypeUtils): string;
|
|
55
|
-
protected generateEnumType(ir: IRNode): string;
|
|
56
|
-
protected generateLiteralType(ir: IRNode): string;
|
|
57
|
-
protected getPrimitiveTypeMap(): Record<string, string>;
|
|
58
|
-
/**
|
|
59
|
-
* Generates a TypeScript object type (as an inline type literal) from the given IR node.
|
|
60
|
-
*/
|
|
61
|
-
protected generateObjectType(ir: IRNode, utils: GenerateTypeUtils): string;
|
|
62
|
-
protected isValidIdentifier(name: string): boolean;
|
|
63
|
-
protected formatJSDoc(description: string, title?: string): string;
|
|
64
|
-
private singularize;
|
|
65
|
-
protected makeTypeReferenceName(signatureOccurrences: SignatureOccurrenceValue["occurrences"]): string;
|
|
66
|
-
protected getUniqueRefTypeName(signature: string, nodePath: string): RefTypeName;
|
|
67
|
-
protected resolveRefTypeName(ir: IRNode, signature: string): string;
|
|
68
|
-
/**
|
|
69
|
-
* Hook for subclasses to enable signature-only deduplication for specific signatures.
|
|
70
|
-
* When this returns true for a signature, `getReferencedType` will reuse the first
|
|
71
|
-
* ref type with that signature regardless of path, avoiding duplicate type declarations.
|
|
72
|
-
*/
|
|
73
|
-
protected shouldReuseExistingSignature(_signature: string): boolean;
|
|
74
|
-
protected getReferencedType(ir: IRNode): string | undefined;
|
|
75
|
-
}
|
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import pluralize from "pluralize";
|
|
2
|
-
import { PathUtils } from "./utils/path-utils.js";
|
|
3
|
-
import { toPascalCase } from "./utils/to-pascal-case.js";
|
|
4
|
-
/** Default words that should not be singularized (common programming/API terms). */
|
|
5
|
-
const DEFAULT_UNCOUNTABLE_WORDS = ["data", "metadata"];
|
|
6
|
-
export class TypescriptBaseConverter {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.refTypes = [];
|
|
9
|
-
/** Shared registry of all top-level declaration names (types + enums) for cross-namespace collision detection. */
|
|
10
|
-
this.usedDeclarationNames = new Set();
|
|
11
|
-
this.emitJSDoc = false;
|
|
12
|
-
this.fallbackCounter = 0;
|
|
13
|
-
}
|
|
14
|
-
getRefTypeNamingConfig() {
|
|
15
|
-
return {
|
|
16
|
-
postfixes: [
|
|
17
|
-
"Type", "Element", "Schema", "Object", "Shape", "Definition",
|
|
18
|
-
"Item", "Entry", "One", "Two", "Three", "Four", "Five",
|
|
19
|
-
"Six", "Seven", "Eight", "Nine", "Ten",
|
|
20
|
-
],
|
|
21
|
-
handleAnySymbol: true,
|
|
22
|
-
stripLeadingAnySymbol: true,
|
|
23
|
-
depluralize: true,
|
|
24
|
-
arrayItemNaming: false,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Recursively generates a TypeScript type string for the given IR node.
|
|
29
|
-
*/
|
|
30
|
-
generateType(ir, utils) {
|
|
31
|
-
switch (ir.type) {
|
|
32
|
-
case "object": {
|
|
33
|
-
const referencedType = utils.getReferencedType(ir);
|
|
34
|
-
if (referencedType)
|
|
35
|
-
return referencedType;
|
|
36
|
-
return this.generateObjectType(ir, utils);
|
|
37
|
-
}
|
|
38
|
-
case "array":
|
|
39
|
-
return this.generateArrayType(ir, utils);
|
|
40
|
-
case "tuple":
|
|
41
|
-
return this.generateTupleType(ir, utils);
|
|
42
|
-
case "union":
|
|
43
|
-
return this.generateUnionType(ir, utils);
|
|
44
|
-
case "intersection":
|
|
45
|
-
return this.generateIntersectionType(ir, utils);
|
|
46
|
-
case "enum":
|
|
47
|
-
return this.generateEnumType(ir);
|
|
48
|
-
case "literal":
|
|
49
|
-
return this.generateLiteralType(ir);
|
|
50
|
-
case "any":
|
|
51
|
-
return "any";
|
|
52
|
-
case "unknown":
|
|
53
|
-
return "unknown";
|
|
54
|
-
case "never":
|
|
55
|
-
return "never";
|
|
56
|
-
default: {
|
|
57
|
-
const primitiveMap = this.getPrimitiveTypeMap();
|
|
58
|
-
if (ir.type in primitiveMap) {
|
|
59
|
-
return primitiveMap[ir.type];
|
|
60
|
-
}
|
|
61
|
-
return "any";
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
generateArrayType(ir, utils) {
|
|
66
|
-
if (ir.items) {
|
|
67
|
-
return `Array<${this.generateType(ir.items, utils)}>`;
|
|
68
|
-
}
|
|
69
|
-
return "any[]";
|
|
70
|
-
}
|
|
71
|
-
generateTupleType(ir, utils) {
|
|
72
|
-
if (ir.tupleItems && ir.tupleItems.length > 0) {
|
|
73
|
-
const elements = ir.tupleItems.map((item) => this.generateType(item, utils));
|
|
74
|
-
return `[${elements.join(", ")}]`;
|
|
75
|
-
}
|
|
76
|
-
return "[]";
|
|
77
|
-
}
|
|
78
|
-
generateUnionType(ir, utils) {
|
|
79
|
-
if (ir.options && ir.options.length > 0) {
|
|
80
|
-
return ir.options
|
|
81
|
-
.map((opt) => this.generateType(opt, utils))
|
|
82
|
-
.join(" | ");
|
|
83
|
-
}
|
|
84
|
-
return "never";
|
|
85
|
-
}
|
|
86
|
-
generateIntersectionType(ir, utils) {
|
|
87
|
-
if (ir.options && ir.options.length > 0) {
|
|
88
|
-
return ir.options
|
|
89
|
-
.map((opt) => this.generateType(opt, utils))
|
|
90
|
-
.join(" & ");
|
|
91
|
-
}
|
|
92
|
-
return "never";
|
|
93
|
-
}
|
|
94
|
-
generateEnumType(ir) {
|
|
95
|
-
if (ir.values && ir.values.length > 0) {
|
|
96
|
-
return ir.values.map((v) => JSON.stringify(v)).join(" | ");
|
|
97
|
-
}
|
|
98
|
-
return "never";
|
|
99
|
-
}
|
|
100
|
-
generateLiteralType(ir) {
|
|
101
|
-
return typeof ir.constraints?.value === "string"
|
|
102
|
-
? JSON.stringify(ir.constraints.value)
|
|
103
|
-
: String(ir.constraints?.value);
|
|
104
|
-
}
|
|
105
|
-
getPrimitiveTypeMap() {
|
|
106
|
-
return {
|
|
107
|
-
string: "string",
|
|
108
|
-
number: "number",
|
|
109
|
-
integer: "number",
|
|
110
|
-
boolean: "boolean",
|
|
111
|
-
null: "null",
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Generates a TypeScript object type (as an inline type literal) from the given IR node.
|
|
116
|
-
*/
|
|
117
|
-
generateObjectType(ir, utils) {
|
|
118
|
-
let generated = ``;
|
|
119
|
-
const generatedAdditionalValues = new Set();
|
|
120
|
-
if (ir.additionalProperties === true) {
|
|
121
|
-
generatedAdditionalValues.add("Record<string, any>");
|
|
122
|
-
}
|
|
123
|
-
else if (ir.additionalProperties) {
|
|
124
|
-
generatedAdditionalValues.add(`Record<string, ${this.generateType(ir.additionalProperties, utils)}>`);
|
|
125
|
-
}
|
|
126
|
-
if (ir.properties) {
|
|
127
|
-
const hasAnnotations = this.emitJSDoc &&
|
|
128
|
-
Object.values(ir.properties).some((p) => p.description || p.title);
|
|
129
|
-
const props = Object.keys(ir.properties).map((key) => {
|
|
130
|
-
const prop = ir.properties[key];
|
|
131
|
-
// Append '?' if the property is not required.
|
|
132
|
-
const optional = prop.required ? "" : "?";
|
|
133
|
-
const propKey = this.isValidIdentifier(key) ? key : `"${key}"`;
|
|
134
|
-
const propLine = `${propKey}${optional}: ${this.generateType(prop, utils)};`;
|
|
135
|
-
if (hasAnnotations && (prop.description || prop.title)) {
|
|
136
|
-
const jsdoc = prop.description
|
|
137
|
-
? this.formatJSDoc(prop.description, prop.title)
|
|
138
|
-
: this.formatJSDoc(prop.title);
|
|
139
|
-
return `${jsdoc}\n${propLine}`;
|
|
140
|
-
}
|
|
141
|
-
return propLine;
|
|
142
|
-
});
|
|
143
|
-
if (!props.length && generatedAdditionalValues.size === 0) {
|
|
144
|
-
generatedAdditionalValues.add("{ [key:string]: unknown }");
|
|
145
|
-
}
|
|
146
|
-
else if (props.length) {
|
|
147
|
-
if (hasAnnotations) {
|
|
148
|
-
const indented = props
|
|
149
|
-
.map((block) => block
|
|
150
|
-
.split("\n")
|
|
151
|
-
.map((line) => ` ${line}`)
|
|
152
|
-
.join("\n"))
|
|
153
|
-
.join("\n");
|
|
154
|
-
generated = `{\n${indented}\n}`;
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
generated = `{ ${props.join(" ")} }`;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
let returnValue = ``;
|
|
162
|
-
if (generatedAdditionalValues.size > 0) {
|
|
163
|
-
if (generated) {
|
|
164
|
-
returnValue = `(${generated} & (${Array.from(generatedAdditionalValues).join(" & ")}))`;
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
returnValue = Array.from(generatedAdditionalValues).join(" & ");
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
returnValue = generated || "{ [key:string]: unknown }";
|
|
172
|
-
}
|
|
173
|
-
return returnValue;
|
|
174
|
-
}
|
|
175
|
-
isValidIdentifier(name) {
|
|
176
|
-
return /^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(name);
|
|
177
|
-
}
|
|
178
|
-
formatJSDoc(description, title) {
|
|
179
|
-
const safe = description.replace(/\*\//g, "*\\/");
|
|
180
|
-
const parts = [];
|
|
181
|
-
if (title) {
|
|
182
|
-
parts.push(title.replace(/\*\//g, "*\\/"));
|
|
183
|
-
parts.push("");
|
|
184
|
-
parts.push(safe);
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
parts.push(safe);
|
|
188
|
-
}
|
|
189
|
-
const text = parts.join("\n");
|
|
190
|
-
const lines = text.split("\n");
|
|
191
|
-
if (lines.length === 1) {
|
|
192
|
-
return `/** ${text} */`;
|
|
193
|
-
}
|
|
194
|
-
return `/**\n${lines.map((l) => ` * ${l}`).join("\n")}\n */`;
|
|
195
|
-
}
|
|
196
|
-
singularize(word, extraUncountable) {
|
|
197
|
-
const uncountable = [...DEFAULT_UNCOUNTABLE_WORDS, ...(extraUncountable ?? [])];
|
|
198
|
-
if (uncountable.some((u) => word.toLowerCase().endsWith(u.toLowerCase()))) {
|
|
199
|
-
return word;
|
|
200
|
-
}
|
|
201
|
-
return pluralize.singular(word);
|
|
202
|
-
}
|
|
203
|
-
makeTypeReferenceName(signatureOccurrences) {
|
|
204
|
-
const paths = PathUtils.parsePaths(signatureOccurrences.map((occurrence) => occurrence.nodePath));
|
|
205
|
-
const common = PathUtils.commonSequence(paths);
|
|
206
|
-
return common.map((str) => toPascalCase(str)).join("");
|
|
207
|
-
}
|
|
208
|
-
getUniqueRefTypeName(signature, nodePath) {
|
|
209
|
-
const config = this.getRefTypeNamingConfig();
|
|
210
|
-
const path = PathUtils.parsePath(nodePath);
|
|
211
|
-
const lastPathItem = nodePath.split(".").slice(-1)[0];
|
|
212
|
-
const isArrayItem = lastPathItem === "0";
|
|
213
|
-
const isAnySymbol = lastPathItem === "*";
|
|
214
|
-
const postFixes = [...config.postfixes];
|
|
215
|
-
if (isArrayItem) {
|
|
216
|
-
if (config.arrayItemNaming !== false) {
|
|
217
|
-
postFixes.unshift(config.arrayItemNaming ?? "Item");
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
postFixes.unshift("");
|
|
221
|
-
}
|
|
222
|
-
// When path is empty (root-level array), use the root schema name as context
|
|
223
|
-
if (path.length === 0 && this.rootName) {
|
|
224
|
-
path.push(this.rootName);
|
|
225
|
-
}
|
|
226
|
-
if (config.depluralize && path.length > 0 && path[path.length - 1]) {
|
|
227
|
-
path[path.length - 1] = this.singularize(path[path.length - 1], config.uncountableWords);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
else if (config.handleAnySymbol && isAnySymbol) {
|
|
231
|
-
postFixes.unshift("AnyKey", "AnyProperty", "AnyField", "AnyIdentifier");
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
postFixes.unshift("");
|
|
235
|
-
}
|
|
236
|
-
let pathsSegmentsToInclude = 1;
|
|
237
|
-
let name = "";
|
|
238
|
-
let postFixIndexToTry = 0;
|
|
239
|
-
while (!name) {
|
|
240
|
-
let proposedName = path.slice(-pathsSegmentsToInclude).map(toPascalCase).join("") +
|
|
241
|
-
postFixes[postFixIndexToTry];
|
|
242
|
-
if (config.stripLeadingAnySymbol && proposedName[0] === "*") {
|
|
243
|
-
proposedName = proposedName.slice(1);
|
|
244
|
-
}
|
|
245
|
-
const foundSignatureMatch = this.refTypes.find(([sig, n]) => sig === signature && n === proposedName);
|
|
246
|
-
if (foundSignatureMatch) {
|
|
247
|
-
return foundSignatureMatch[1];
|
|
248
|
-
}
|
|
249
|
-
// Skip empty proposed names (e.g. empty path with no postfix)
|
|
250
|
-
if (!proposedName) {
|
|
251
|
-
postFixIndexToTry++;
|
|
252
|
-
if (postFixIndexToTry >= postFixes.length) {
|
|
253
|
-
do {
|
|
254
|
-
this.fallbackCounter++;
|
|
255
|
-
name = "Type" + this.fallbackCounter;
|
|
256
|
-
} while (this.usedDeclarationNames.has(name));
|
|
257
|
-
}
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
const nameAlreadyUsed = this.usedDeclarationNames.has(proposedName);
|
|
261
|
-
if (nameAlreadyUsed) {
|
|
262
|
-
pathsSegmentsToInclude++;
|
|
263
|
-
if (pathsSegmentsToInclude >= path.length) {
|
|
264
|
-
postFixIndexToTry++;
|
|
265
|
-
pathsSegmentsToInclude = 1;
|
|
266
|
-
if (postFixIndexToTry === postFixes.length) {
|
|
267
|
-
// Deterministic instance-scoped fallback
|
|
268
|
-
do {
|
|
269
|
-
this.fallbackCounter++;
|
|
270
|
-
name = proposedName + this.fallbackCounter;
|
|
271
|
-
} while (this.usedDeclarationNames.has(name));
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
name = proposedName;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
this.usedDeclarationNames.add(name);
|
|
280
|
-
return name;
|
|
281
|
-
}
|
|
282
|
-
resolveRefTypeName(ir, signature) {
|
|
283
|
-
return this.getUniqueRefTypeName(signature, ir.path);
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Hook for subclasses to enable signature-only deduplication for specific signatures.
|
|
287
|
-
* When this returns true for a signature, `getReferencedType` will reuse the first
|
|
288
|
-
* ref type with that signature regardless of path, avoiding duplicate type declarations.
|
|
289
|
-
*/
|
|
290
|
-
shouldReuseExistingSignature(_signature) {
|
|
291
|
-
return false;
|
|
292
|
-
}
|
|
293
|
-
getReferencedType(ir) {
|
|
294
|
-
const signature = ir.signature;
|
|
295
|
-
if (!signature) {
|
|
296
|
-
return undefined;
|
|
297
|
-
}
|
|
298
|
-
// Hook: allow subclasses to enable signature-only dedup for specific signatures
|
|
299
|
-
if (this.shouldReuseExistingSignature(signature)) {
|
|
300
|
-
const existingBySignature = this.refTypes.find(([sig]) => sig === signature);
|
|
301
|
-
if (existingBySignature)
|
|
302
|
-
return existingBySignature[1];
|
|
303
|
-
}
|
|
304
|
-
const name = this.resolveRefTypeName(ir, signature);
|
|
305
|
-
// Account for recursion: the ref type could have already been created
|
|
306
|
-
const existing = this.refTypes.find(([sig, _name]) => sig === signature && _name === name);
|
|
307
|
-
if (existing) {
|
|
308
|
-
return name;
|
|
309
|
-
}
|
|
310
|
-
// Push entry with empty code placeholder - hold reference for safe assignment
|
|
311
|
-
const entry = [signature, name, { code: "", title: ir.title, description: ir.description }];
|
|
312
|
-
this.refTypes.push(entry);
|
|
313
|
-
const code = this.generateObjectType(ir, {
|
|
314
|
-
getReferencedType: this.getReferencedType.bind(this),
|
|
315
|
-
});
|
|
316
|
-
// Safe assignment via direct reference
|
|
317
|
-
entry[2].code = code;
|
|
318
|
-
return name;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
//# sourceMappingURL=TypescriptBaseConverter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TypescriptBaseConverter.js","sourceRoot":"","sources":["../src/TypescriptBaseConverter.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,oFAAoF;AACpF,MAAM,yBAAyB,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAqCvD,MAAM,OAAgB,uBAAuB;IAA7C;QAGY,aAAQ,GAAa,EAAE,CAAC;QAClC,kHAAkH;QACxG,yBAAoB,GAAG,IAAI,GAAG,EAAU,CAAC;QAGzC,cAAS,GAAG,KAAK,CAAC;QACpB,oBAAe,GAAG,CAAC,CAAC;IAmW9B,CAAC;IAjWW,sBAAsB;QAC9B,OAAO;YACL,SAAS,EAAE;gBACT,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY;gBAC5D,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM;gBACtD,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK;aACvC;YACD,eAAe,EAAE,IAAI;YACrB,qBA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AK,CAAC,CAAC;QAE1B,MAAM,IAAI,GAAG,IAAI,CAAC,kBAAkB,CAAC,EAAE,EAAE;YACvC,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC;SACrD,CAAC,CAAC;QAEH,uCAAuC;QACvC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC;QAErB,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { TypescriptConverter } from "./TypescriptConverter.js";
|
|
3
|
-
describe("TypescriptConverter - additionalProperties and patternProperties", () => {
|
|
4
|
-
it("should convert objects with only additionalProperties", async () => {
|
|
5
|
-
expect(new TypescriptConverter({
|
|
6
|
-
type: "object",
|
|
7
|
-
properties: {
|
|
8
|
-
metadata: {
|
|
9
|
-
type: "object",
|
|
10
|
-
additionalProperties: { type: "string" },
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
required: ["metadata"],
|
|
14
|
-
}, {
|
|
15
|
-
inlineTypes: true,
|
|
16
|
-
}).code.replace(/\s/g, "")).toEqual(`{metadata: Record<string, string>; }`.replace(/\s/g, ""));
|
|
17
|
-
});
|
|
18
|
-
it("should convert objects with mixed properties & additionalProperties", async () => {
|
|
19
|
-
expect(new TypescriptConverter({
|
|
20
|
-
type: "object",
|
|
21
|
-
properties: {
|
|
22
|
-
metadata: {
|
|
23
|
-
type: "object",
|
|
24
|
-
additionalProperties: { type: "string" },
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
additionalProperties: { type: "string" },
|
|
28
|
-
required: ["metadata"],
|
|
29
|
-
}, {
|
|
30
|
-
inlineTypes: true,
|
|
31
|
-
}).code.replace(/\s/g, "")).toEqual(`({metadata:Record<string,string>;}&(Record<string,string>))`.replace(/\s/g, ""));
|
|
32
|
-
});
|
|
33
|
-
it("should convert objects with complex additionalProperties", async () => {
|
|
34
|
-
expect(new TypescriptConverter({
|
|
35
|
-
type: "object",
|
|
36
|
-
properties: {
|
|
37
|
-
specificProp: {
|
|
38
|
-
type: "string",
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
additionalProperties: {
|
|
42
|
-
type: "object",
|
|
43
|
-
properties: {
|
|
44
|
-
subAdditionalProp: { type: "string" },
|
|
45
|
-
},
|
|
46
|
-
additionalProperties: { type: "string" },
|
|
47
|
-
},
|
|
48
|
-
required: ["metadata"],
|
|
49
|
-
}, {
|
|
50
|
-
inlineTypes: true,
|
|
51
|
-
}).code.replace(/\s/g, "")).toEqual(`({specificProp?:string;}&(Record<string,({subAdditionalProp?:string;}&(Record<string,string>))>))`.replace(/\s/g, ""));
|
|
52
|
-
});
|
|
53
|
-
it("should convert { type: 'object', additionalProperties: true } to Record<string, any>", () => {
|
|
54
|
-
expect(new TypescriptConverter({
|
|
55
|
-
type: "object",
|
|
56
|
-
additionalProperties: true,
|
|
57
|
-
}, { inlineTypes: true }).code.replace(/\s/g, "")).toEqual("Record<string,any>".replace(/\s/g, ""));
|
|
58
|
-
});
|
|
59
|
-
it("should render additionalProperties: false without extra Record types", () => {
|
|
60
|
-
expect(new TypescriptConverter({
|
|
61
|
-
type: "object",
|
|
62
|
-
properties: {
|
|
63
|
-
name: { type: "string" },
|
|
64
|
-
},
|
|
65
|
-
additionalProperties: false,
|
|
66
|
-
required: ["name"],
|
|
67
|
-
}, { inlineTypes: true }).code.replace(/\s/g, "")).toEqual("{ name: string; }".replace(/\s/g, ""));
|
|
68
|
-
});
|
|
69
|
-
it("should convert a JSON schema with pattern properties", () => {
|
|
70
|
-
expect(new TypescriptConverter({
|
|
71
|
-
type: "object",
|
|
72
|
-
properties: {
|
|
73
|
-
totalTodo: {
|
|
74
|
-
type: "number",
|
|
75
|
-
},
|
|
76
|
-
totalPastDue: {
|
|
77
|
-
type: "number",
|
|
78
|
-
},
|
|
79
|
-
unassignedTodo: {
|
|
80
|
-
type: "number",
|
|
81
|
-
},
|
|
82
|
-
todoByAssignee: {
|
|
83
|
-
type: "object",
|
|
84
|
-
patternProperties: {
|
|
85
|
-
"^(.*)$": {
|
|
86
|
-
type: "object",
|
|
87
|
-
properties: {
|
|
88
|
-
todo: {
|
|
89
|
-
type: "number",
|
|
90
|
-
},
|
|
91
|
-
pastDue: {
|
|
92
|
-
type: "number",
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
required: ["todo", "pastDue"],
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
required: [
|
|
101
|
-
"totalTodo",
|
|
102
|
-
"totalPastDue",
|
|
103
|
-
"unassignedTodo",
|
|
104
|
-
"todoByAssignee",
|
|
105
|
-
],
|
|
106
|
-
title: "Root",
|
|
107
|
-
}).code.replace(/\s/g, "")).toEqual("export type TodoByAssignee = Record<string, TodoByAssigneeAnyKey>;export type TodoByAssigneeAnyKey = { todo: number; pastDue: number; };export type Root = { totalTodo: number; totalPastDue: number; unassignedTodo: number; todoByAssignee: TodoByAssignee; };".replace(/\s/g, ""));
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
//# sourceMappingURL=TypescriptConverter.additionalProperties.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TypescriptConverter.additionalProperties.test.js","sourceRoot":"","sources":["../src/TypescriptConverter.additionalProperties.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,QAAQ,CAAC,kEAAkE,EAAE,GAAG,EAAE;IAChF,EAAE,CAAC,uDAAuD,EAAE,KAAK,IAAI,EAAE;QACrE,MAAM,CACJ,IAAI,mBAAmB,CACrB;YACE,IAAI,EAAE,QAAQ;YACd,UAAU,E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