@fabricorg/gen-types 0.2.0 → 0.2.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.
- package/CHANGELOG.md +13 -0
- package/dist/index.cjs +20 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +20 -12
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Close final uplift audit gaps: align Host 2.x documentation and migration evidence, surface every
|
|
8
|
+
compiler/generator API to LLM consumers, make memory outbox egress directly usable, sanitize relay
|
|
9
|
+
failures, validate complete archetype state maps, support recursive JSON Schema generation, reject
|
|
10
|
+
cross-platform path traversal, synchronize artifact version stamps, and include package licenses.
|
|
11
|
+
- Consume Platform as a peer dependency so applications keep a single copy of the public contracts.
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- @fabricorg/platform@0.11.1
|
|
14
|
+
- @fabricorg/compiler@0.2.1
|
|
15
|
+
|
|
3
16
|
## 0.2.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/dist/index.cjs
CHANGED
|
@@ -24,44 +24,52 @@ __export(index_exports, {
|
|
|
24
24
|
typesGenerator: () => typesGenerator
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
|
-
function jsonSchemaToTypeScript(schema, root = schema) {
|
|
27
|
+
function jsonSchemaToTypeScript(schema, root = schema, resolving = /* @__PURE__ */ new Set(), recursiveTypeName) {
|
|
28
28
|
if (!schema) return "unknown";
|
|
29
29
|
if (schema.$ref) {
|
|
30
30
|
const match = schema.$ref.match(/^#\/\$defs\/([^/]+)$/);
|
|
31
31
|
const resolved = match ? root?.$defs?.[decodeURIComponent(match[1])] : void 0;
|
|
32
32
|
if (!resolved) throw new Error(`Unsupported or unresolved JSON Schema reference "${schema.$ref}".`);
|
|
33
|
-
|
|
33
|
+
if (resolving.has(schema.$ref)) {
|
|
34
|
+
if (recursiveTypeName) return recursiveTypeName;
|
|
35
|
+
throw new Error(`Recursive JSON Schema reference "${schema.$ref}" requires a named generated type.`);
|
|
36
|
+
}
|
|
37
|
+
const next = new Set(resolving).add(schema.$ref);
|
|
38
|
+
return jsonSchemaToTypeScript(resolved, root, next, recursiveTypeName);
|
|
34
39
|
}
|
|
35
|
-
if (schema.allOf) return schema.allOf.map((item) => jsonSchemaToTypeScript(item, root)).join(" & ");
|
|
40
|
+
if (schema.allOf) return schema.allOf.map((item) => jsonSchemaToTypeScript(item, root, resolving, recursiveTypeName)).join(" & ");
|
|
36
41
|
if (schema.enum) return schema.enum.map((value) => JSON.stringify(value)).join(" | ") || "never";
|
|
37
42
|
if (schema.const !== void 0) return JSON.stringify(schema.const);
|
|
38
|
-
if (schema.oneOf) return schema.oneOf.map((item) => jsonSchemaToTypeScript(item, root)).join(" | ");
|
|
39
|
-
if (schema.anyOf) return schema.anyOf.map((item) => jsonSchemaToTypeScript(item, root)).join(" | ");
|
|
43
|
+
if (schema.oneOf) return schema.oneOf.map((item) => jsonSchemaToTypeScript(item, root, resolving, recursiveTypeName)).join(" | ");
|
|
44
|
+
if (schema.anyOf) return schema.anyOf.map((item) => jsonSchemaToTypeScript(item, root, resolving, recursiveTypeName)).join(" | ");
|
|
40
45
|
const type = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];
|
|
41
46
|
const variants = type.map((item) => {
|
|
42
47
|
if (item === "string") return "string";
|
|
43
48
|
if (item === "number" || item === "integer") return "number";
|
|
44
49
|
if (item === "boolean") return "boolean";
|
|
45
50
|
if (item === "null") return "null";
|
|
46
|
-
if (item === "array")
|
|
51
|
+
if (item === "array") {
|
|
52
|
+
if (schema.prefixItems) return `[${schema.prefixItems.map((child) => jsonSchemaToTypeScript(child, root, resolving, recursiveTypeName)).join(", ")}]`;
|
|
53
|
+
return `Array<${Array.isArray(schema.items) ? schema.items.map((child) => jsonSchemaToTypeScript(child, root, resolving, recursiveTypeName)).join(" | ") : jsonSchemaToTypeScript(schema.items, root, resolving, recursiveTypeName)}>`;
|
|
54
|
+
}
|
|
47
55
|
if (item === "object") {
|
|
48
56
|
const required = new Set(schema.required ?? []);
|
|
49
|
-
const properties = Object.entries(schema.properties ?? {}).map(([name, child]) => `${JSON.stringify(name)}${required.has(name) ? "" : "?"}: ${jsonSchemaToTypeScript(child, root)};`);
|
|
57
|
+
const properties = Object.entries(schema.properties ?? {}).map(([name, child]) => `${JSON.stringify(name)}${required.has(name) ? "" : "?"}: ${jsonSchemaToTypeScript(child, root, resolving, recursiveTypeName)};`);
|
|
50
58
|
return `{ ${properties.join(" ")} }`;
|
|
51
59
|
}
|
|
52
60
|
return "unknown";
|
|
53
61
|
});
|
|
54
|
-
return variants.length ? variants.join(" | ") : schema.properties ? jsonSchemaToTypeScript({ ...schema, type: "object" }, root) : "unknown";
|
|
62
|
+
return variants.length ? variants.join(" | ") : schema.properties ? jsonSchemaToTypeScript({ ...schema, type: "object" }, root, resolving, recursiveTypeName) : "unknown";
|
|
55
63
|
}
|
|
56
64
|
var typesGenerator = {
|
|
57
65
|
name: "@fabricorg/gen-types",
|
|
58
|
-
version: "0.1
|
|
66
|
+
version: "0.2.1",
|
|
59
67
|
generate(ir) {
|
|
60
68
|
return ir.modules.map((module2) => {
|
|
61
|
-
const declarations = module2.objectTypes.map((objectType) => `export type ${objectType.type} = ${jsonSchemaToTypeScript(objectType.schema)};`);
|
|
69
|
+
const declarations = module2.objectTypes.map((objectType) => `export type ${objectType.type} = ${jsonSchemaToTypeScript(objectType.schema, objectType.schema, /* @__PURE__ */ new Set(), objectType.type)};`);
|
|
62
70
|
const actionTypes = module2.actions.flatMap((action) => [
|
|
63
|
-
`export type ${pascal(action.actionId)}Parameters = ${jsonSchemaToTypeScript(action.parameterSchema)};`,
|
|
64
|
-
`export type ${pascal(action.actionId)}Result = ${jsonSchemaToTypeScript(action.resultSchema)};`
|
|
71
|
+
`export type ${pascal(action.actionId)}Parameters = ${jsonSchemaToTypeScript(action.parameterSchema, action.parameterSchema, /* @__PURE__ */ new Set(), `${pascal(action.actionId)}Parameters`)};`,
|
|
72
|
+
`export type ${pascal(action.actionId)}Result = ${jsonSchemaToTypeScript(action.resultSchema, action.resultSchema, /* @__PURE__ */ new Set(), `${pascal(action.actionId)}Result`)};`
|
|
65
73
|
]);
|
|
66
74
|
return { path: `${module2.namespace}/index.ts`, content: `// Generated by ${typesGenerator.name}@${typesGenerator.version}
|
|
67
75
|
// Manifest digest: ${ir.manifestDigest}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts"],"sourcesContent":["import type { FabricCompilerIr, GeneratorTarget } from \"@fabricorg/compiler\";\nimport type { PortableJsonSchema } from \"@fabricorg/platform\";\n\nexport function jsonSchemaToTypeScript(
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["import type { FabricCompilerIr, GeneratorTarget } from \"@fabricorg/compiler\";\nimport type { PortableJsonSchema } from \"@fabricorg/platform\";\n\nexport function jsonSchemaToTypeScript(\n\tschema: PortableJsonSchema | undefined,\n\troot = schema,\n\tresolving = new Set<string>(),\n\trecursiveTypeName?: string,\n): string {\n\tif (!schema) return \"unknown\";\n\tif (schema.$ref) {\n\t\tconst match = schema.$ref.match(/^#\\/\\$defs\\/([^/]+)$/);\n\t\tconst resolved = match ? root?.$defs?.[decodeURIComponent(match[1]!)] : undefined;\n\t\tif (!resolved) throw new Error(`Unsupported or unresolved JSON Schema reference \"${schema.$ref}\".`);\n\t\tif (resolving.has(schema.$ref)) {\n\t\t\tif (recursiveTypeName) return recursiveTypeName;\n\t\t\tthrow new Error(`Recursive JSON Schema reference \"${schema.$ref}\" requires a named generated type.`);\n\t\t}\n\t\tconst next = new Set(resolving).add(schema.$ref);\n\t\treturn jsonSchemaToTypeScript(resolved, root, next, recursiveTypeName);\n\t}\n\tif (schema.allOf) return schema.allOf.map((item) => jsonSchemaToTypeScript(item, root, resolving, recursiveTypeName)).join(\" & \");\n\tif (schema.enum) return schema.enum.map((value) => JSON.stringify(value)).join(\" | \") || \"never\";\n\tif (schema.const !== undefined) return JSON.stringify(schema.const);\n\tif (schema.oneOf) return schema.oneOf.map((item) => jsonSchemaToTypeScript(item, root, resolving, recursiveTypeName)).join(\" | \");\n\tif (schema.anyOf) return schema.anyOf.map((item) => jsonSchemaToTypeScript(item, root, resolving, recursiveTypeName)).join(\" | \");\n\tconst type = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];\n\tconst variants = type.map((item) => {\n\t\tif (item === \"string\") return \"string\";\n\t\tif (item === \"number\" || item === \"integer\") return \"number\";\n\t\tif (item === \"boolean\") return \"boolean\";\n\t\tif (item === \"null\") return \"null\";\n\t\tif (item === \"array\") {\n\t\t\tif (schema.prefixItems) return `[${schema.prefixItems.map((child) => jsonSchemaToTypeScript(child, root, resolving, recursiveTypeName)).join(\", \")}]`;\n\t\t\treturn `Array<${Array.isArray(schema.items) ? schema.items.map((child) => jsonSchemaToTypeScript(child, root, resolving, recursiveTypeName)).join(\" | \") : jsonSchemaToTypeScript(schema.items, root, resolving, recursiveTypeName)}>`;\n\t\t}\n\t\tif (item === \"object\") {\n\t\t\tconst required = new Set(schema.required ?? []);\n\t\t\tconst properties = Object.entries(schema.properties ?? {}).map(([name, child]) => `${JSON.stringify(name)}${required.has(name) ? \"\" : \"?\"}: ${jsonSchemaToTypeScript(child, root, resolving, recursiveTypeName)};`);\n\t\t\treturn `{ ${properties.join(\" \")} }`;\n\t\t}\n\t\treturn \"unknown\";\n\t});\n\treturn variants.length ? variants.join(\" | \") : schema.properties ? jsonSchemaToTypeScript({ ...schema, type: \"object\" }, root, resolving, recursiveTypeName) : \"unknown\";\n}\n\nexport const typesGenerator: GeneratorTarget = {\n\tname: \"@fabricorg/gen-types\",\n\tversion: \"0.2.1\",\n\tgenerate(ir: FabricCompilerIr) {\n\t\treturn ir.modules.map((module) => {\n\t\t\tconst declarations = module.objectTypes.map((objectType) => `export type ${objectType.type} = ${jsonSchemaToTypeScript(objectType.schema, objectType.schema, new Set(), objectType.type)};`);\n\t\t\tconst actionTypes = module.actions.flatMap((action) => [\n\t\t\t\t`export type ${pascal(action.actionId)}Parameters = ${jsonSchemaToTypeScript(action.parameterSchema as PortableJsonSchema | undefined, action.parameterSchema as PortableJsonSchema | undefined, new Set(), `${pascal(action.actionId)}Parameters`)};`,\n\t\t\t\t`export type ${pascal(action.actionId)}Result = ${jsonSchemaToTypeScript(action.resultSchema as PortableJsonSchema | undefined, action.resultSchema as PortableJsonSchema | undefined, new Set(), `${pascal(action.actionId)}Result`)};`,\n\t\t\t]);\n\t\t\treturn { path: `${module.namespace}/index.ts`, content: `// Generated by ${typesGenerator.name}@${typesGenerator.version}\\n// Manifest digest: ${ir.manifestDigest}\\n\\n${[...declarations, ...actionTypes].join(\"\\n\\n\")}\\n` };\n\t\t});\n\t},\n};\n\nconst pascal = (value: string): string => value.split(/[._/-]/).filter(Boolean).map((part) => part[0]?.toUpperCase() + part.slice(1)).join(\"\");\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,uBACf,QACA,OAAO,QACP,YAAY,oBAAI,IAAY,GAC5B,mBACS;AACT,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,OAAO,MAAM;AAChB,UAAM,QAAQ,OAAO,KAAK,MAAM,sBAAsB;AACtD,UAAM,WAAW,QAAQ,MAAM,QAAQ,mBAAmB,MAAM,CAAC,CAAE,CAAC,IAAI;AACxE,QAAI,CAAC,SAAU,OAAM,IAAI,MAAM,oDAAoD,OAAO,IAAI,IAAI;AAClG,QAAI,UAAU,IAAI,OAAO,IAAI,GAAG;AAC/B,UAAI,kBAAmB,QAAO;AAC9B,Y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O,QAAQ,CAAC,QAAQ,CAAC;AAAA,MACtO,CAAC;AACD,aAAO,EAAE,MAAM,GAAGA,QAAO,SAAS,aAAa,SAAS,mBAAmB,eAAe,IAAI,IAAI,eAAe,OAAO;AAAA,sBAAyB,GAAG,cAAc;AAAA;AAAA,EAAO,CAAC,GAAG,cAAc,GAAG,WAAW,EAAE,KAAK,MAAM,CAAC;AAAA,EAAK;AAAA,IAC7N,CAAC;AAAA,EACF;AACD;AAEA,IAAM,SAAS,CAAC,UAA0B,MAAM,MAAM,QAAQ,EAAE,OAAO,OAAO,EAAE,IAAI,CAAC,SAAS,KAAK,CAAC,GAAG,YAAY,IAAI,KAAK,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE;","names":["module"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GeneratorTarget } from '@fabricorg/compiler';
|
|
2
2
|
import { PortableJsonSchema } from '@fabricorg/platform';
|
|
3
3
|
|
|
4
|
-
declare function jsonSchemaToTypeScript(schema: PortableJsonSchema | undefined, root?: PortableJsonSchema | undefined): string;
|
|
4
|
+
declare function jsonSchemaToTypeScript(schema: PortableJsonSchema | undefined, root?: PortableJsonSchema | undefined, resolving?: Set<string>, recursiveTypeName?: string): string;
|
|
5
5
|
declare const typesGenerator: GeneratorTarget;
|
|
6
6
|
|
|
7
7
|
export { jsonSchemaToTypeScript, typesGenerator };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GeneratorTarget } from '@fabricorg/compiler';
|
|
2
2
|
import { PortableJsonSchema } from '@fabricorg/platform';
|
|
3
3
|
|
|
4
|
-
declare function jsonSchemaToTypeScript(schema: PortableJsonSchema | undefined, root?: PortableJsonSchema | undefined): string;
|
|
4
|
+
declare function jsonSchemaToTypeScript(schema: PortableJsonSchema | undefined, root?: PortableJsonSchema | undefined, resolving?: Set<string>, recursiveTypeName?: string): string;
|
|
5
5
|
declare const typesGenerator: GeneratorTarget;
|
|
6
6
|
|
|
7
7
|
export { jsonSchemaToTypeScript, typesGenerator };
|
package/dist/index.js
CHANGED
|
@@ -1,42 +1,50 @@
|
|
|
1
1
|
// index.ts
|
|
2
|
-
function jsonSchemaToTypeScript(schema, root = schema) {
|
|
2
|
+
function jsonSchemaToTypeScript(schema, root = schema, resolving = /* @__PURE__ */ new Set(), recursiveTypeName) {
|
|
3
3
|
if (!schema) return "unknown";
|
|
4
4
|
if (schema.$ref) {
|
|
5
5
|
const match = schema.$ref.match(/^#\/\$defs\/([^/]+)$/);
|
|
6
6
|
const resolved = match ? root?.$defs?.[decodeURIComponent(match[1])] : void 0;
|
|
7
7
|
if (!resolved) throw new Error(`Unsupported or unresolved JSON Schema reference "${schema.$ref}".`);
|
|
8
|
-
|
|
8
|
+
if (resolving.has(schema.$ref)) {
|
|
9
|
+
if (recursiveTypeName) return recursiveTypeName;
|
|
10
|
+
throw new Error(`Recursive JSON Schema reference "${schema.$ref}" requires a named generated type.`);
|
|
11
|
+
}
|
|
12
|
+
const next = new Set(resolving).add(schema.$ref);
|
|
13
|
+
return jsonSchemaToTypeScript(resolved, root, next, recursiveTypeName);
|
|
9
14
|
}
|
|
10
|
-
if (schema.allOf) return schema.allOf.map((item) => jsonSchemaToTypeScript(item, root)).join(" & ");
|
|
15
|
+
if (schema.allOf) return schema.allOf.map((item) => jsonSchemaToTypeScript(item, root, resolving, recursiveTypeName)).join(" & ");
|
|
11
16
|
if (schema.enum) return schema.enum.map((value) => JSON.stringify(value)).join(" | ") || "never";
|
|
12
17
|
if (schema.const !== void 0) return JSON.stringify(schema.const);
|
|
13
|
-
if (schema.oneOf) return schema.oneOf.map((item) => jsonSchemaToTypeScript(item, root)).join(" | ");
|
|
14
|
-
if (schema.anyOf) return schema.anyOf.map((item) => jsonSchemaToTypeScript(item, root)).join(" | ");
|
|
18
|
+
if (schema.oneOf) return schema.oneOf.map((item) => jsonSchemaToTypeScript(item, root, resolving, recursiveTypeName)).join(" | ");
|
|
19
|
+
if (schema.anyOf) return schema.anyOf.map((item) => jsonSchemaToTypeScript(item, root, resolving, recursiveTypeName)).join(" | ");
|
|
15
20
|
const type = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];
|
|
16
21
|
const variants = type.map((item) => {
|
|
17
22
|
if (item === "string") return "string";
|
|
18
23
|
if (item === "number" || item === "integer") return "number";
|
|
19
24
|
if (item === "boolean") return "boolean";
|
|
20
25
|
if (item === "null") return "null";
|
|
21
|
-
if (item === "array")
|
|
26
|
+
if (item === "array") {
|
|
27
|
+
if (schema.prefixItems) return `[${schema.prefixItems.map((child) => jsonSchemaToTypeScript(child, root, resolving, recursiveTypeName)).join(", ")}]`;
|
|
28
|
+
return `Array<${Array.isArray(schema.items) ? schema.items.map((child) => jsonSchemaToTypeScript(child, root, resolving, recursiveTypeName)).join(" | ") : jsonSchemaToTypeScript(schema.items, root, resolving, recursiveTypeName)}>`;
|
|
29
|
+
}
|
|
22
30
|
if (item === "object") {
|
|
23
31
|
const required = new Set(schema.required ?? []);
|
|
24
|
-
const properties = Object.entries(schema.properties ?? {}).map(([name, child]) => `${JSON.stringify(name)}${required.has(name) ? "" : "?"}: ${jsonSchemaToTypeScript(child, root)};`);
|
|
32
|
+
const properties = Object.entries(schema.properties ?? {}).map(([name, child]) => `${JSON.stringify(name)}${required.has(name) ? "" : "?"}: ${jsonSchemaToTypeScript(child, root, resolving, recursiveTypeName)};`);
|
|
25
33
|
return `{ ${properties.join(" ")} }`;
|
|
26
34
|
}
|
|
27
35
|
return "unknown";
|
|
28
36
|
});
|
|
29
|
-
return variants.length ? variants.join(" | ") : schema.properties ? jsonSchemaToTypeScript({ ...schema, type: "object" }, root) : "unknown";
|
|
37
|
+
return variants.length ? variants.join(" | ") : schema.properties ? jsonSchemaToTypeScript({ ...schema, type: "object" }, root, resolving, recursiveTypeName) : "unknown";
|
|
30
38
|
}
|
|
31
39
|
var typesGenerator = {
|
|
32
40
|
name: "@fabricorg/gen-types",
|
|
33
|
-
version: "0.1
|
|
41
|
+
version: "0.2.1",
|
|
34
42
|
generate(ir) {
|
|
35
43
|
return ir.modules.map((module) => {
|
|
36
|
-
const declarations = module.objectTypes.map((objectType) => `export type ${objectType.type} = ${jsonSchemaToTypeScript(objectType.schema)};`);
|
|
44
|
+
const declarations = module.objectTypes.map((objectType) => `export type ${objectType.type} = ${jsonSchemaToTypeScript(objectType.schema, objectType.schema, /* @__PURE__ */ new Set(), objectType.type)};`);
|
|
37
45
|
const actionTypes = module.actions.flatMap((action) => [
|
|
38
|
-
`export type ${pascal(action.actionId)}Parameters = ${jsonSchemaToTypeScript(action.parameterSchema)};`,
|
|
39
|
-
`export type ${pascal(action.actionId)}Result = ${jsonSchemaToTypeScript(action.resultSchema)};`
|
|
46
|
+
`export type ${pascal(action.actionId)}Parameters = ${jsonSchemaToTypeScript(action.parameterSchema, action.parameterSchema, /* @__PURE__ */ new Set(), `${pascal(action.actionId)}Parameters`)};`,
|
|
47
|
+
`export type ${pascal(action.actionId)}Result = ${jsonSchemaToTypeScript(action.resultSchema, action.resultSchema, /* @__PURE__ */ new Set(), `${pascal(action.actionId)}Result`)};`
|
|
40
48
|
]);
|
|
41
49
|
return { path: `${module.namespace}/index.ts`, content: `// Generated by ${typesGenerator.name}@${typesGenerator.version}
|
|
42
50
|
// Manifest digest: ${ir.manifestDigest}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts"],"sourcesContent":["import type { FabricCompilerIr, GeneratorTarget } from \"@fabricorg/compiler\";\nimport type { PortableJsonSchema } from \"@fabricorg/platform\";\n\nexport function jsonSchemaToTypeScript(
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["import type { FabricCompilerIr, GeneratorTarget } from \"@fabricorg/compiler\";\nimport type { PortableJsonSchema } from \"@fabricorg/platform\";\n\nexport function jsonSchemaToTypeScript(\n\tschema: PortableJsonSchema | undefined,\n\troot = schema,\n\tresolving = new Set<string>(),\n\trecursiveTypeName?: string,\n): string {\n\tif (!schema) return \"unknown\";\n\tif (schema.$ref) {\n\t\tconst match = schema.$ref.match(/^#\\/\\$defs\\/([^/]+)$/);\n\t\tconst resolved = match ? root?.$defs?.[decodeURIComponent(match[1]!)] : undefined;\n\t\tif (!resolved) throw new Error(`Unsupported or unresolved JSON Schema reference \"${schema.$ref}\".`);\n\t\tif (resolving.has(schema.$ref)) {\n\t\t\tif (recursiveTypeName) return recursiveTypeName;\n\t\t\tthrow new Error(`Recursive JSON Schema reference \"${schema.$ref}\" requires a named generated type.`);\n\t\t}\n\t\tconst next = new Set(resolving).add(schema.$ref);\n\t\treturn jsonSchemaToTypeScript(resolved, root, next, recursiveTypeName);\n\t}\n\tif (schema.allOf) return schema.allOf.map((item) => jsonSchemaToTypeScript(item, root, resolving, recursiveTypeName)).join(\" & \");\n\tif (schema.enum) return schema.enum.map((value) => JSON.stringify(value)).join(\" | \") || \"never\";\n\tif (schema.const !== undefined) return JSON.stringify(schema.const);\n\tif (schema.oneOf) return schema.oneOf.map((item) => jsonSchemaToTypeScript(item, root, resolving, recursiveTypeName)).join(\" | \");\n\tif (schema.anyOf) return schema.anyOf.map((item) => jsonSchemaToTypeScript(item, root, resolving, recursiveTypeName)).join(\" | \");\n\tconst type = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];\n\tconst variants = type.map((item) => {\n\t\tif (item === \"string\") return \"string\";\n\t\tif (item === \"number\" || item === \"integer\") return \"number\";\n\t\tif (item === \"boolean\") return \"boolean\";\n\t\tif (item === \"null\") return \"null\";\n\t\tif (item === \"array\") {\n\t\t\tif (schema.prefixItems) return `[${schema.prefixItems.map((child) => jsonSchemaToTypeScript(child, root, resolving, recursiveTypeName)).join(\", \")}]`;\n\t\t\treturn `Array<${Array.isArray(schema.items) ? schema.items.map((child) => jsonSchemaToTypeScript(child, root, resolving, recursiveTypeName)).join(\" | \") : jsonSchemaToTypeScript(schema.items, root, resolving, recursiveTypeName)}>`;\n\t\t}\n\t\tif (item === \"object\") {\n\t\t\tconst required = new Set(schema.required ?? []);\n\t\t\tconst properties = Object.entries(schema.properties ?? {}).map(([name, child]) => `${JSON.stringify(name)}${required.has(name) ? \"\" : \"?\"}: ${jsonSchemaToTypeScript(child, root, resolving, recursiveTypeName)};`);\n\t\t\treturn `{ ${properties.join(\" \")} }`;\n\t\t}\n\t\treturn \"unknown\";\n\t});\n\treturn variants.length ? variants.join(\" | \") : schema.properties ? jsonSchemaToTypeScript({ ...schema, type: \"object\" }, root, resolving, recursiveTypeName) : \"unknown\";\n}\n\nexport const typesGenerator: GeneratorTarget = {\n\tname: \"@fabricorg/gen-types\",\n\tversion: \"0.2.1\",\n\tgenerate(ir: FabricCompilerIr) {\n\t\treturn ir.modules.map((module) => {\n\t\t\tconst declarations = module.objectTypes.map((objectType) => `export type ${objectType.type} = ${jsonSchemaToTypeScript(objectType.schema, objectType.schema, new Set(), objectType.type)};`);\n\t\t\tconst actionTypes = module.actions.flatMap((action) => [\n\t\t\t\t`export type ${pascal(action.actionId)}Parameters = ${jsonSchemaToTypeScript(action.parameterSchema as PortableJsonSchema | undefined, action.parameterSchema as PortableJsonSchema | undefined, new Set(), `${pascal(action.actionId)}Parameters`)};`,\n\t\t\t\t`export type ${pascal(action.actionId)}Result = ${jsonSchemaToTypeScript(action.resultSchema as PortableJsonSchema | undefined, action.resultSchema as PortableJsonSchema | undefined, new Set(), `${pascal(action.actionId)}Result`)};`,\n\t\t\t]);\n\t\t\treturn { path: `${module.namespace}/index.ts`, content: `// Generated by ${typesGenerator.name}@${typesGenerator.version}\\n// Manifest digest: ${ir.manifestDigest}\\n\\n${[...declarations, ...actionTypes].join(\"\\n\\n\")}\\n` };\n\t\t});\n\t},\n};\n\nconst pascal = (value: string): string => value.split(/[._/-]/).filter(Boolean).map((part) => part[0]?.toUpperCase() + part.slice(1)).join(\"\");\n"],"mappings":";AAGO,SAAS,uBACf,QACA,OAAO,QACP,YAAY,oBAAI,IAAY,GAC5B,mBACS;AACT,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,YAAM,cAAc,OAAO,QAAQ,QAAQ,CAAC,WAAW;AAAA,QACtD,eAAe,OAAO,OAAO,QAAQ,CAAC,gBAAgB,uBAAuB,OAAO,iBAAmD,OAAO,iBAAmD,oBAAI,IAAI,GAAG,GAAG,OAAO,OAAO,QAAQ,CAAC,YAAY,CAAC;AAAA,QACnP,eAAe,OAAO,OAAO,QAAQ,CAAC,YAAY,uBAAuB,OAAO,cAAgD,OAAO,cAAgD,oBAAI,IAAI,GAAG,GAAG,OAAO,OAAO,QAAQ,CAAC,QAAQ,CAAC;AAAA,MACtO,CAAC;AACD,aAAO,EAAE,MAAM,GAAG,OAAO,SAAS,aAAa,SAAS,mBAAmB,eAAe,IAAI,IAAI,eAAe,OAAO;AAAA,sBAAyB,GAAG,cAAc;AAAA;AAAA,EAAO,CAAC,GAAG,cAAc,GAAG,WAAW,EAAE,KAAK,MAAM,CAAC;AAAA,EAAK;AAAA,IAC7N,CAAC;AAAA,EACF;AACD;AAEA,IAAM,SAAS,CAAC,UAA0B,MAAM,MAAM,QAAQ,EAAE,OAAO,OAAO,EAAE,IAAI,CAAC,SAAS,KAAK,CAAC,GAAG,YAAY,IAAI,KAAK,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabricorg/gen-types",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "TypeScript type generator for Fabric compiler IR.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -25,14 +25,17 @@
|
|
|
25
25
|
"CHANGELOG.md"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@fabricorg/compiler": "^0.2.
|
|
29
|
-
|
|
28
|
+
"@fabricorg/compiler": "^0.2.1"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@fabricorg/platform": "^0.11.1"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
32
34
|
"@types/node": "^22.10.0",
|
|
33
35
|
"tsup": "^8.5.0",
|
|
34
36
|
"typescript": "^5.7.3",
|
|
35
|
-
"vitest": "^4.1.5"
|
|
37
|
+
"vitest": "^4.1.5",
|
|
38
|
+
"@fabricorg/platform": "^0.11.1"
|
|
36
39
|
},
|
|
37
40
|
"engines": {
|
|
38
41
|
"node": ">=20"
|