@fabricorg/gen-types 0.2.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/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/index.cjs +80 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add deterministic TypeScript, event-registry, capability-contract, and Markdown generator targets for
|
|
8
|
+
Fabric compiler IR.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
- @fabricorg/platform@0.11.0
|
|
16
|
+
- @fabricorg/compiler@0.2.0
|
|
17
|
+
|
|
18
|
+
## 0.1.0
|
|
19
|
+
|
|
20
|
+
- Add TypeScript contract generation from manifest JSON Schema.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fabric
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
jsonSchemaToTypeScript: () => jsonSchemaToTypeScript,
|
|
24
|
+
typesGenerator: () => typesGenerator
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
function jsonSchemaToTypeScript(schema, root = schema) {
|
|
28
|
+
if (!schema) return "unknown";
|
|
29
|
+
if (schema.$ref) {
|
|
30
|
+
const match = schema.$ref.match(/^#\/\$defs\/([^/]+)$/);
|
|
31
|
+
const resolved = match ? root?.$defs?.[decodeURIComponent(match[1])] : void 0;
|
|
32
|
+
if (!resolved) throw new Error(`Unsupported or unresolved JSON Schema reference "${schema.$ref}".`);
|
|
33
|
+
return jsonSchemaToTypeScript(resolved, root);
|
|
34
|
+
}
|
|
35
|
+
if (schema.allOf) return schema.allOf.map((item) => jsonSchemaToTypeScript(item, root)).join(" & ");
|
|
36
|
+
if (schema.enum) return schema.enum.map((value) => JSON.stringify(value)).join(" | ") || "never";
|
|
37
|
+
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(" | ");
|
|
40
|
+
const type = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];
|
|
41
|
+
const variants = type.map((item) => {
|
|
42
|
+
if (item === "string") return "string";
|
|
43
|
+
if (item === "number" || item === "integer") return "number";
|
|
44
|
+
if (item === "boolean") return "boolean";
|
|
45
|
+
if (item === "null") return "null";
|
|
46
|
+
if (item === "array") return `Array<${Array.isArray(schema.items) ? schema.items.map((child) => jsonSchemaToTypeScript(child, root)).join(" | ") : jsonSchemaToTypeScript(schema.items, root)}>`;
|
|
47
|
+
if (item === "object") {
|
|
48
|
+
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)};`);
|
|
50
|
+
return `{ ${properties.join(" ")} }`;
|
|
51
|
+
}
|
|
52
|
+
return "unknown";
|
|
53
|
+
});
|
|
54
|
+
return variants.length ? variants.join(" | ") : schema.properties ? jsonSchemaToTypeScript({ ...schema, type: "object" }, root) : "unknown";
|
|
55
|
+
}
|
|
56
|
+
var typesGenerator = {
|
|
57
|
+
name: "@fabricorg/gen-types",
|
|
58
|
+
version: "0.1.0",
|
|
59
|
+
generate(ir) {
|
|
60
|
+
return ir.modules.map((module2) => {
|
|
61
|
+
const declarations = module2.objectTypes.map((objectType) => `export type ${objectType.type} = ${jsonSchemaToTypeScript(objectType.schema)};`);
|
|
62
|
+
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)};`
|
|
65
|
+
]);
|
|
66
|
+
return { path: `${module2.namespace}/index.ts`, content: `// Generated by ${typesGenerator.name}@${typesGenerator.version}
|
|
67
|
+
// Manifest digest: ${ir.manifestDigest}
|
|
68
|
+
|
|
69
|
+
${[...declarations, ...actionTypes].join("\n\n")}
|
|
70
|
+
` };
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var pascal = (value) => value.split(/[._/-]/).filter(Boolean).map((part) => part[0]?.toUpperCase() + part.slice(1)).join("");
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
jsonSchemaToTypeScript,
|
|
78
|
+
typesGenerator
|
|
79
|
+
});
|
|
80
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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(schema: PortableJsonSchema | undefined, root = schema): 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\treturn jsonSchemaToTypeScript(resolved, root);\n\t}\n\tif (schema.allOf) return schema.allOf.map((item) => jsonSchemaToTypeScript(item, root)).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)).join(\" | \");\n\tif (schema.anyOf) return schema.anyOf.map((item) => jsonSchemaToTypeScript(item, root)).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\") return `Array<${Array.isArray(schema.items) ? schema.items.map((child) => jsonSchemaToTypeScript(child, root)).join(\" | \") : jsonSchemaToTypeScript(schema.items, root)}>`;\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)};`);\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) : \"unknown\";\n}\n\nexport const typesGenerator: GeneratorTarget = {\n\tname: \"@fabricorg/gen-types\",\n\tversion: \"0.1.0\",\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)};`);\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)};`,\n\t\t\t\t`export type ${pascal(action.actionId)}Result = ${jsonSchemaToTypeScript(action.resultSchema as PortableJsonSchema | undefined)};`,\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,uBAAuB,QAAwC,OAAO,QAAgB;AACrG,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,WAAO,uBAAuB,UAAU,IAAI;AAAA,EAC7C;AACA,MAAI,OAAO,MAAO,QAAO,OAAO,MAAM,IAAI,CAAC,SAAS,uBAAuB,MAAM,IAAI,CAAC,EAAE,KAAK,KAAK;AAClG,MAAI,OAAO,KAAM,QAAO,OAAO,KAAK,IAAI,CAAC,UAAU,KAAK,UAAU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,SAAS,GAAG,IAAI,IAAI;AACnI;AAEO,IAAM,iBAAkC;AAAA,EAC9C,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS,IAAsB;AAC9B,WAAO,GAAG,QAAQ,IAAI,CAACA,YAAW;AACjC,YAAM,eAAeA,QAAO,YAAY,IAAI,CAAC,eAAe,eAAe,WAAW,IAAI,MAAM,uBAAuB,WAAW,MAAM,CAAC,GAAG;AAC5I,YAAM,cAAcA,QAAO,QAAQ,QAAQ,CAAC,WAAW;AAAA,QACtD,eAAe,OAAO,OAAO,QAAQ,CAAC,gBAAgB,uBAAuB,OAAO,eAAiD,CAAC;AAAA,QACtI,eAAe,OAAO,OAAO,QAAQ,CAAC,YAAY,uBAAuB,OAAO,YAA8C,CAAC;AAAA,MAChI,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
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GeneratorTarget } from '@fabricorg/compiler';
|
|
2
|
+
import { PortableJsonSchema } from '@fabricorg/platform';
|
|
3
|
+
|
|
4
|
+
declare function jsonSchemaToTypeScript(schema: PortableJsonSchema | undefined, root?: PortableJsonSchema | undefined): string;
|
|
5
|
+
declare const typesGenerator: GeneratorTarget;
|
|
6
|
+
|
|
7
|
+
export { jsonSchemaToTypeScript, typesGenerator };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GeneratorTarget } from '@fabricorg/compiler';
|
|
2
|
+
import { PortableJsonSchema } from '@fabricorg/platform';
|
|
3
|
+
|
|
4
|
+
declare function jsonSchemaToTypeScript(schema: PortableJsonSchema | undefined, root?: PortableJsonSchema | undefined): string;
|
|
5
|
+
declare const typesGenerator: GeneratorTarget;
|
|
6
|
+
|
|
7
|
+
export { jsonSchemaToTypeScript, typesGenerator };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
function jsonSchemaToTypeScript(schema, root = schema) {
|
|
3
|
+
if (!schema) return "unknown";
|
|
4
|
+
if (schema.$ref) {
|
|
5
|
+
const match = schema.$ref.match(/^#\/\$defs\/([^/]+)$/);
|
|
6
|
+
const resolved = match ? root?.$defs?.[decodeURIComponent(match[1])] : void 0;
|
|
7
|
+
if (!resolved) throw new Error(`Unsupported or unresolved JSON Schema reference "${schema.$ref}".`);
|
|
8
|
+
return jsonSchemaToTypeScript(resolved, root);
|
|
9
|
+
}
|
|
10
|
+
if (schema.allOf) return schema.allOf.map((item) => jsonSchemaToTypeScript(item, root)).join(" & ");
|
|
11
|
+
if (schema.enum) return schema.enum.map((value) => JSON.stringify(value)).join(" | ") || "never";
|
|
12
|
+
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(" | ");
|
|
15
|
+
const type = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];
|
|
16
|
+
const variants = type.map((item) => {
|
|
17
|
+
if (item === "string") return "string";
|
|
18
|
+
if (item === "number" || item === "integer") return "number";
|
|
19
|
+
if (item === "boolean") return "boolean";
|
|
20
|
+
if (item === "null") return "null";
|
|
21
|
+
if (item === "array") return `Array<${Array.isArray(schema.items) ? schema.items.map((child) => jsonSchemaToTypeScript(child, root)).join(" | ") : jsonSchemaToTypeScript(schema.items, root)}>`;
|
|
22
|
+
if (item === "object") {
|
|
23
|
+
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)};`);
|
|
25
|
+
return `{ ${properties.join(" ")} }`;
|
|
26
|
+
}
|
|
27
|
+
return "unknown";
|
|
28
|
+
});
|
|
29
|
+
return variants.length ? variants.join(" | ") : schema.properties ? jsonSchemaToTypeScript({ ...schema, type: "object" }, root) : "unknown";
|
|
30
|
+
}
|
|
31
|
+
var typesGenerator = {
|
|
32
|
+
name: "@fabricorg/gen-types",
|
|
33
|
+
version: "0.1.0",
|
|
34
|
+
generate(ir) {
|
|
35
|
+
return ir.modules.map((module) => {
|
|
36
|
+
const declarations = module.objectTypes.map((objectType) => `export type ${objectType.type} = ${jsonSchemaToTypeScript(objectType.schema)};`);
|
|
37
|
+
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)};`
|
|
40
|
+
]);
|
|
41
|
+
return { path: `${module.namespace}/index.ts`, content: `// Generated by ${typesGenerator.name}@${typesGenerator.version}
|
|
42
|
+
// Manifest digest: ${ir.manifestDigest}
|
|
43
|
+
|
|
44
|
+
${[...declarations, ...actionTypes].join("\n\n")}
|
|
45
|
+
` };
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var pascal = (value) => value.split(/[._/-]/).filter(Boolean).map((part) => part[0]?.toUpperCase() + part.slice(1)).join("");
|
|
50
|
+
export {
|
|
51
|
+
jsonSchemaToTypeScript,
|
|
52
|
+
typesGenerator
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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(schema: PortableJsonSchema | undefined, root = schema): 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\treturn jsonSchemaToTypeScript(resolved, root);\n\t}\n\tif (schema.allOf) return schema.allOf.map((item) => jsonSchemaToTypeScript(item, root)).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)).join(\" | \");\n\tif (schema.anyOf) return schema.anyOf.map((item) => jsonSchemaToTypeScript(item, root)).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\") return `Array<${Array.isArray(schema.items) ? schema.items.map((child) => jsonSchemaToTypeScript(child, root)).join(\" | \") : jsonSchemaToTypeScript(schema.items, root)}>`;\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)};`);\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) : \"unknown\";\n}\n\nexport const typesGenerator: GeneratorTarget = {\n\tname: \"@fabricorg/gen-types\",\n\tversion: \"0.1.0\",\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)};`);\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)};`,\n\t\t\t\t`export type ${pascal(action.actionId)}Result = ${jsonSchemaToTypeScript(action.resultSchema as PortableJsonSchema | undefined)};`,\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,uBAAuB,QAAwC,OAAO,QAAgB;AACrG,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,WAAO,uBAAuB,UAAU,IAAI;AAAA,EAC7C;AACA,MAAI,OAAO,MAAO,QAAO,OAAO,MAAM,IAAI,CAAC,SAA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ACA,WAAO;AAAA,EACR,CAAC;AACD,SAAO,SAAS,SAAS,SAAS,KAAK,KAAK,IAAI,OAAO,aAAa,uBAAuB,EAAE,GAAG,QAAQ,MAAM,SAAS,GAAG,IAAI,IAAI;AACnI;AAEO,IAAM,iBAAkC;AAAA,EAC9C,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS,IAAsB;AAC9B,WAAO,GAAG,QAAQ,IAAI,CAAC,WAAW;AACjC,YAAM,eAAe,OAAO,YAAY,IAAI,CAAC,eAAe,eAAe,WAAW,IAAI,MAAM,uBAAuB,WAAW,MAAM,CAAC,GAAG;AAC5I,YAAM,cAAc,OAAO,QAAQ,QAAQ,CAAC,WAAW;AAAA,QACtD,eAAe,OAAO,OAAO,QAAQ,CAAC,gBAAgB,uBAAuB,OAAO,eAAiD,CAAC;AAAA,QACtI,eAAe,OAAO,OAAO,QAAQ,CAAC,YAAY,uBAAuB,OAAO,YAA8C,CAAC;AAAA,MAChI,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
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fabricorg/gen-types",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "TypeScript type generator for Fabric compiler IR.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/index.d.cts",
|
|
18
|
+
"default": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"README.md",
|
|
25
|
+
"CHANGELOG.md"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@fabricorg/compiler": "^0.2.0",
|
|
29
|
+
"@fabricorg/platform": "^0.11.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^22.10.0",
|
|
33
|
+
"tsup": "^8.5.0",
|
|
34
|
+
"typescript": "^5.7.3",
|
|
35
|
+
"vitest": "^4.1.5"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=20"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"type-check": "tsc --noEmit",
|
|
47
|
+
"test": "vitest run"
|
|
48
|
+
}
|
|
49
|
+
}
|