@toolproof-core/schema 1.0.2 → 1.0.4

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.
Files changed (90) hide show
  1. package/dist/generated/normalized/Genesis.d.ts +2 -0
  2. package/dist/generated/normalized/Genesis.js +2 -0
  3. package/dist/generated/normalized/Genesis.json +2008 -0
  4. package/dist/generated/resources/Genesis.d.ts +2 -0
  5. package/dist/generated/resources/Genesis.js +2 -0
  6. package/dist/generated/resources/Genesis.json +2907 -0
  7. package/dist/generated/schemas/Genesis.d.ts +2 -0
  8. package/dist/generated/schemas/Genesis.js +2 -0
  9. package/dist/generated/schemas/Genesis.json +1466 -0
  10. package/dist/generated/schemas/standalone/Goal.d.ts +2 -0
  11. package/dist/generated/schemas/standalone/Goal.js +2 -0
  12. package/dist/generated/schemas/standalone/Goal.json +86 -0
  13. package/dist/generated/schemas/standalone/Job.d.ts +2 -0
  14. package/dist/generated/schemas/standalone/Job.js +2 -0
  15. package/dist/generated/schemas/standalone/Job.json +236 -0
  16. package/dist/generated/schemas/standalone/RawStrategy.d.ts +2 -0
  17. package/dist/generated/schemas/standalone/RawStrategy.js +2 -0
  18. package/dist/generated/schemas/standalone/RawStrategy.json +650 -0
  19. package/dist/generated/schemas/standalone/ResourceType.d.ts +2 -0
  20. package/dist/generated/schemas/standalone/ResourceType.js +2 -0
  21. package/dist/generated/schemas/standalone/ResourceType.json +140 -0
  22. package/dist/generated/schemas/standalone/RunnableStrategy.d.ts +2 -0
  23. package/dist/generated/schemas/standalone/RunnableStrategy.js +2 -0
  24. package/dist/generated/schemas/standalone/RunnableStrategy.json +720 -0
  25. package/dist/generated/schemas/standalone/StrategyRun.d.ts +2 -0
  26. package/dist/generated/schemas/standalone/StrategyRun.js +2 -0
  27. package/dist/generated/schemas/standalone/StrategyRun.json +1002 -0
  28. package/dist/generated/{types → typesTS}/standalone/Resource_Genesis.d.ts +1 -1
  29. package/{src/generated/types → dist/generated/typesTS}/standalone/Resource_Job.d.ts +1 -1
  30. package/{src/generated/types → dist/generated/typesTS}/standalone/Resource_RawStrategy.d.ts +1 -1
  31. package/{src/generated/types → dist/generated/typesTS}/standalone/Resource_ResourceType.d.ts +1 -1
  32. package/dist/generated/{types → typesTS}/standalone/Resource_RunnableStrategy.d.ts +1 -1
  33. package/dist/generated/typesTS/typesTS.d.ts +745 -0
  34. package/dist/index.d.ts +10 -0
  35. package/dist/index.js +5 -0
  36. package/dist/scripts/_lib/config.d.ts +10 -10
  37. package/dist/scripts/_lib/config.js +23 -23
  38. package/dist/scripts/extractSchemasFromResourceTypeShells.js +109 -103
  39. package/dist/scripts/generateDependencies.js +15 -14
  40. package/dist/scripts/generateSchemaShims.js +76 -84
  41. package/dist/scripts/generateStandaloneSchema.js +47 -37
  42. package/dist/scripts/generateStandaloneTypeTS.js +108 -0
  43. package/dist/scripts/generateTypesTS.js +430 -0
  44. package/dist/scripts/normalizeAnchorsToPointers.js +37 -30
  45. package/dist/scripts/wrapResourceTypesWithResourceShells.js +14 -16
  46. package/package.json +11 -12
  47. package/src/Genesis.json +2007 -1999
  48. package/src/generated/{dependencyMap.json → dependencies/dependencyMap.json} +7 -6
  49. package/src/generated/normalized/Genesis.json +17 -9
  50. package/src/generated/resources/Genesis.json +19 -11
  51. package/src/generated/schemas/Genesis.json +15 -7
  52. package/src/generated/schemas/standalone/RawStrategy.json +15 -7
  53. package/src/generated/schemas/standalone/RunnableStrategy.json +15 -7
  54. package/src/generated/schemas/standalone/StrategyRun.json +15 -7
  55. package/src/generated/{types → typesTS}/standalone/Resource_Genesis.d.ts +1 -1
  56. package/{dist/generated/types → src/generated/typesTS}/standalone/Resource_Job.d.ts +1 -1
  57. package/{dist/generated/types → src/generated/typesTS}/standalone/Resource_RawStrategy.d.ts +1 -1
  58. package/{dist/generated/types → src/generated/typesTS}/standalone/Resource_ResourceType.d.ts +1 -1
  59. package/src/generated/{types → typesTS}/standalone/Resource_RunnableStrategy.d.ts +1 -1
  60. package/src/generated/typesTS/typesTS.d.ts +745 -0
  61. package/src/index.ts +67 -1
  62. package/src/scripts/_lib/config.ts +205 -205
  63. package/src/scripts/extractSchemasFromResourceTypeShells.ts +261 -218
  64. package/src/scripts/generateDependencies.ts +121 -120
  65. package/src/scripts/generateSchemaShims.ts +127 -135
  66. package/src/scripts/generateStandaloneSchema.ts +185 -175
  67. package/src/scripts/generateStandaloneTypeTS.ts +127 -0
  68. package/src/scripts/generateTypesTS.ts +532 -0
  69. package/src/scripts/normalizeAnchorsToPointers.ts +115 -123
  70. package/src/scripts/wrapResourceTypesWithResourceShells.ts +82 -84
  71. package/dist/generated/types/types.d.ts +0 -1723
  72. package/dist/scripts/generateStandaloneType.js +0 -102
  73. package/dist/scripts/generateTypes.js +0 -550
  74. package/src/generated/types/types.d.ts +0 -1723
  75. package/src/scripts/generateStandaloneType.ts +0 -119
  76. package/src/scripts/generateTypes.ts +0 -615
  77. /package/dist/generated/{types → typesTS}/standalone/Resource_Genesis.js +0 -0
  78. /package/dist/generated/{types → typesTS}/standalone/Resource_Job.js +0 -0
  79. /package/dist/generated/{types → typesTS}/standalone/Resource_RawStrategy.js +0 -0
  80. /package/dist/generated/{types → typesTS}/standalone/Resource_ResourceType.js +0 -0
  81. /package/dist/generated/{types → typesTS}/standalone/Resource_RunnableStrategy.js +0 -0
  82. /package/dist/generated/{types/types.js → typesTS/typesTS.js} +0 -0
  83. /package/dist/scripts/{generateStandaloneType.d.ts → generateStandaloneTypeTS.d.ts} +0 -0
  84. /package/dist/scripts/{generateTypes.d.ts → generateTypesTS.d.ts} +0 -0
  85. /package/src/generated/{types → typesTS}/standalone/Resource_Genesis.js +0 -0
  86. /package/src/generated/{types → typesTS}/standalone/Resource_Job.js +0 -0
  87. /package/src/generated/{types → typesTS}/standalone/Resource_RawStrategy.js +0 -0
  88. /package/src/generated/{types → typesTS}/standalone/Resource_ResourceType.js +0 -0
  89. /package/src/generated/{types → typesTS}/standalone/Resource_RunnableStrategy.js +0 -0
  90. /package/src/generated/{types/types.js → typesTS/typesTS.js} +0 -0
@@ -1,120 +1,121 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { getConfig } from "./_lib/config.js";
4
-
5
- type JSONValue = null | boolean | number | string | JSONValue[] | { [k: string]: JSONValue };
6
-
7
- function decodeJsonPointerSegment(segment: string): string {
8
- // JSON Pointer decoding: ~1 => / and ~0 => ~
9
- return segment.replace(/~1/g, "/").replace(/~0/g, "~");
10
- }
11
-
12
- function collectRefs(node: unknown, out: Set<string>): void {
13
- if (Array.isArray(node)) {
14
- for (const item of node) collectRefs(item, out);
15
- return;
16
- }
17
- if (!node || typeof node !== "object") return;
18
-
19
- const obj = node as Record<string, unknown>;
20
- const ref = obj["$ref"];
21
- if (typeof ref === "string") out.add(ref);
22
-
23
- for (const value of Object.values(obj)) {
24
- collectRefs(value, out);
25
- }
26
- }
27
-
28
- function resolveInternalRefToDefKey(ref: string, defKeys: Set<string>, anchorToDef: Record<string, string>): string | null {
29
- if (!ref.startsWith("#")) return null;
30
-
31
- // JSON Pointer: #/$defs/<Name>(/...)
32
- const defsPrefix = "#/$defs/";
33
- if (ref.startsWith(defsPrefix)) {
34
- const rest = ref.slice(defsPrefix.length);
35
- const firstSegment = rest.split("/")[0] ?? "";
36
- const defKey = decodeJsonPointerSegment(firstSegment);
37
- return defKeys.has(defKey) ? defKey : null;
38
- }
39
-
40
- // Anchor ref: #AnchorName
41
- if (!ref.startsWith("#/")) {
42
- const anchor = ref.slice(1);
43
- const mapped = anchorToDef[anchor];
44
- if (mapped && defKeys.has(mapped)) return mapped;
45
- if (defKeys.has(anchor)) return anchor;
46
- }
47
-
48
- return null;
49
- }
50
-
51
- /**
52
- * Pure function that generates a dependency map from a JSON Schema document.
53
- *
54
- * @param doc The source JSON Schema document
55
- * @returns A record mapping definition names to their dependency lists
56
- */
57
- function generateDependencyMapLogic(doc: any): Record<string, string[]> {
58
- const defs: Record<string, JSONValue> = doc?.$defs && typeof doc.$defs === "object" ? doc.$defs : {};
59
- const defKeys = new Set(Object.keys(defs));
60
-
61
- // Map anchors to $defs keys (useful if any anchor-style refs remain)
62
- const anchorToDef: Record<string, string> = {};
63
- for (const [defKey, defSchema] of Object.entries(defs)) {
64
- if (!defSchema || typeof defSchema !== "object" || Array.isArray(defSchema)) continue;
65
- const anchor = (defSchema as any).$anchor;
66
- if (typeof anchor === "string" && !(anchor in anchorToDef)) {
67
- anchorToDef[anchor] = defKey;
68
- }
69
- }
70
-
71
- const dependencyMap: Record<string, string[]> = {};
72
-
73
- for (const [defKey, defSchema] of Object.entries(defs)) {
74
- const refs = new Set<string>();
75
- collectRefs(defSchema, refs);
76
-
77
- const deps = new Set<string>();
78
- for (const ref of refs) {
79
- const depKey = resolveInternalRefToDefKey(ref, defKeys, anchorToDef);
80
- if (!depKey) continue;
81
- if (depKey === defKey) continue;
82
- deps.add(depKey);
83
- }
84
-
85
- dependencyMap[defKey] = Array.from(deps);
86
- }
87
-
88
- return dependencyMap;
89
- }
90
-
91
- async function main() {
92
- const config = getConfig();
93
-
94
- const inPath = config.getSchemaPath("Genesis.json");
95
- const outPath = config.getDependencyMapPath();
96
-
97
- if (!fs.existsSync(inPath)) {
98
- console.error(`Genesis schema not found at ${inPath}. Run extractSchemasFromResourceTypeShells first.`);
99
- process.exit(1);
100
- }
101
-
102
- try {
103
- const raw = fs.readFileSync(inPath, "utf8");
104
- const doc = JSON.parse(raw);
105
-
106
- const dependencyMap = generateDependencyMapLogic(doc);
107
-
108
- fs.mkdirSync(path.dirname(outPath), { recursive: true });
109
- fs.writeFileSync(outPath, JSON.stringify(dependencyMap, null, 4), "utf8");
110
- console.log(`Wrote dependency map to ${outPath}`);
111
- } catch (error: any) {
112
- console.error(`Error generating dependency map: ${error.message}`);
113
- process.exit(1);
114
- }
115
- }
116
-
117
- main().catch((e) => {
118
- console.error(e);
119
- process.exit(1);
120
- });
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { getConfig } from "./_lib/config.js";
4
+
5
+ type JSONValue = null | boolean | number | string | JSONValue[] | { [k: string]: JSONValue };
6
+
7
+ // PURE: Decode a single JSON Pointer segment.
8
+ function decodeJsonPointerSegment(segment: string): string {
9
+ // JSON Pointer decoding: ~1 => / and ~0 => ~
10
+ return segment.replace(/~1/g, "/").replace(/~0/g, "~");
11
+ }
12
+
13
+ // PURE: Collect all `$ref` strings from a JSON-ish tree.
14
+ function collectRefs(node: unknown, out: Set<string>): void {
15
+ if (Array.isArray(node)) {
16
+ for (const item of node) collectRefs(item, out);
17
+ return;
18
+ }
19
+ if (!node || typeof node !== "object") return;
20
+
21
+ const obj = node as Record<string, unknown>;
22
+ const ref = obj["$ref"];
23
+ if (typeof ref === "string") out.add(ref);
24
+
25
+ for (const value of Object.values(obj)) {
26
+ collectRefs(value, out);
27
+ }
28
+ }
29
+
30
+ // PURE: Resolve an internal ref (pointer or anchor) to a root $defs key, if possible.
31
+ function resolveInternalRefToDefKey(ref: string, defKeys: Set<string>, anchorToDef: Record<string, string>): string | null {
32
+ if (!ref.startsWith("#")) return null;
33
+
34
+ // JSON Pointer: #/$defs/<Name>(/...)
35
+ const defsPrefix = "#/$defs/";
36
+ if (ref.startsWith(defsPrefix)) {
37
+ const rest = ref.slice(defsPrefix.length);
38
+ const firstSegment = rest.split("/")[0] ?? "";
39
+ const defKey = decodeJsonPointerSegment(firstSegment);
40
+ return defKeys.has(defKey) ? defKey : null;
41
+ }
42
+
43
+ // Anchor ref: #AnchorName
44
+ if (!ref.startsWith("#/")) {
45
+ const anchor = ref.slice(1);
46
+ const mapped = anchorToDef[anchor];
47
+ if (mapped && defKeys.has(mapped)) return mapped;
48
+ if (defKeys.has(anchor)) return anchor;
49
+ }
50
+
51
+ return null;
52
+ }
53
+
54
+ /**
55
+ * Pure function that generates a dependency map from a JSON Schema document.
56
+ *
57
+ * @param doc The source JSON Schema document
58
+ * @returns A record mapping definition names to their dependency lists
59
+ */
60
+ // PURE: Generate a $defs dependency map from a JSON Schema document (no I/O).
61
+ function generateDependencyMapLogic(doc: any): Record<string, string[]> {
62
+ const defs: Record<string, JSONValue> = doc?.$defs && typeof doc.$defs === "object" ? doc.$defs : {};
63
+ const defKeys = new Set(Object.keys(defs));
64
+
65
+ // Map anchors to $defs keys (useful if any anchor-style refs remain)
66
+ const anchorToDef: Record<string, string> = {};
67
+ for (const [defKey, defSchema] of Object.entries(defs)) {
68
+ if (!defSchema || typeof defSchema !== "object" || Array.isArray(defSchema)) continue;
69
+ const anchor = (defSchema as any).$anchor;
70
+ if (typeof anchor === "string" && !(anchor in anchorToDef)) {
71
+ anchorToDef[anchor] = defKey;
72
+ }
73
+ }
74
+
75
+ const dependencyMap: Record<string, string[]> = {};
76
+
77
+ for (const [defKey, defSchema] of Object.entries(defs)) {
78
+ const refs = new Set<string>();
79
+ collectRefs(defSchema, refs);
80
+
81
+ const deps = new Set<string>();
82
+ for (const ref of refs) {
83
+ const depKey = resolveInternalRefToDefKey(ref, defKeys, anchorToDef);
84
+ if (!depKey) continue;
85
+ if (depKey === defKey) continue;
86
+ deps.add(depKey);
87
+ }
88
+
89
+ dependencyMap[defKey] = Array.from(deps);
90
+ }
91
+
92
+ return dependencyMap;
93
+ }
94
+
95
+ // IMPURE: Script entrypoint (config + filesystem I/O + console + process exit code).
96
+ function main() {
97
+ try {
98
+ const config = getConfig();
99
+
100
+ const inPath = config.getSchemaPath("Genesis.json");
101
+ const outPath = config.getDependencyMapPath();
102
+
103
+ if (!fs.existsSync(inPath)) {
104
+ throw new Error(`Genesis schema not found at ${inPath}. Run extractSchemasFromResourceTypeShells first.`);
105
+ }
106
+
107
+ const raw = fs.readFileSync(inPath, "utf8");
108
+ const doc = JSON.parse(raw);
109
+
110
+ const dependencyMap = generateDependencyMapLogic(doc);
111
+
112
+ fs.mkdirSync(path.dirname(outPath), { recursive: true });
113
+ fs.writeFileSync(outPath, JSON.stringify(dependencyMap, null, 4), "utf8");
114
+ console.log(`Wrote dependency map to ${outPath}`);
115
+ } catch (error: any) {
116
+ console.error(`Error generating dependency map: ${error?.message ?? error}`);
117
+ process.exitCode = 1;
118
+ }
119
+ }
120
+
121
+ main();
@@ -1,135 +1,127 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { getConfig } from './_lib/config.js';
4
-
5
- /**
6
- * Generate TypeScript shim files for all JSON schemas and resources
7
- *
8
- * Creates .ts files that import and re-export .json files using
9
- * the JSON import assertion syntax. This enables proper dependency resolution
10
- * and type inference when importing schemas in TypeScript.
11
- *
12
- * Generates shims for:
13
- * - schemas dir: config.getSchemasDir() (schema files)
14
- * - standalone schemas dir: config.getSchemasStandaloneDir() (standalone schema files)
15
- * - resources dir: config.getResourcesDir() (resource envelope files)
16
- *
17
- * Usage: node ./dist/scripts/generateSchemaShims.js
18
- */
19
- /**
20
- * Pure function to generate the content of a TypeScript shim file.
21
- *
22
- * @param jsonFile The name of the JSON file to import
23
- * @param variableName The name of the variable to use for the import
24
- * @returns The TypeScript file content
25
- */
26
- function generateShimContent(jsonFile: string, variableName: string): string {
27
- return `import ${variableName} from './${jsonFile}' with { type: 'json' };\nexport default ${variableName};\n`;
28
- }
29
-
30
- /**
31
- * Pure function to map a list of JSON files to their corresponding TypeScript shim files and contents.
32
- *
33
- * @param jsonFiles List of JSON filenames
34
- * @param variableName The variable name to use in the shim
35
- * @returns A record mapping TS filenames to their contents
36
- */
37
- function getShimsForFiles(jsonFiles: string[], variableName: string): Record<string, string> {
38
- const shims: Record<string, string> = {};
39
- for (const jsonFile of jsonFiles) {
40
- const baseName = path.basename(jsonFile, '.json');
41
- const tsFile = `${baseName}.ts`;
42
- shims[tsFile] = generateShimContent(jsonFile, variableName);
43
- }
44
- return shims;
45
- }
46
-
47
- async function main() {
48
- const config = getConfig();
49
- const schemasDir = config.getSchemasDir();
50
- const standaloneSchemasDir = config.getSchemasStandaloneDir();
51
- const resourcesDir = config.getResourcesDir();
52
- const generatedResourceTypesDir = config.getNormalizedDir();
53
-
54
- let totalCount = 0;
55
-
56
- // Process schemas directory
57
- if (fs.existsSync(schemasDir)) {
58
- const files = fs.readdirSync(schemasDir);
59
- const jsonFiles = files.filter(f => f.endsWith('.json') && !f.startsWith('.'));
60
-
61
- const shims = getShimsForFiles(jsonFiles, 'schema');
62
-
63
- for (const [tsFile, content] of Object.entries(shims)) {
64
- const tsPath = path.join(schemasDir, tsFile);
65
- fs.writeFileSync(tsPath, content, 'utf-8');
66
- console.log(`Generated ${tsFile} in ${schemasDir}`);
67
- totalCount++;
68
- }
69
- console.log(`Generated ${jsonFiles.length} TypeScript schema shims in ${schemasDir}`);
70
- } else {
71
- console.warn(`Schemas directory not found at ${schemasDir}`);
72
- }
73
-
74
- // Process standalone schemas directory
75
- if (fs.existsSync(standaloneSchemasDir)) {
76
- const files = fs.readdirSync(standaloneSchemasDir);
77
- const jsonFiles = files.filter(f => f.endsWith('.json') && !f.startsWith('.'));
78
-
79
- const shims = getShimsForFiles(jsonFiles, 'schema');
80
-
81
- for (const [tsFile, content] of Object.entries(shims)) {
82
- const tsPath = path.join(standaloneSchemasDir, tsFile);
83
- fs.writeFileSync(tsPath, content, 'utf-8');
84
- console.log(`Generated ${tsFile} in ${standaloneSchemasDir}`);
85
- totalCount++;
86
- }
87
- console.log(`Generated ${jsonFiles.length} TypeScript standalone schema shims in ${standaloneSchemasDir}`);
88
- } else {
89
- // Standalone schemas are optional
90
- }
91
-
92
- // Process resources directory
93
- if (fs.existsSync(resourcesDir)) {
94
- const files = fs.readdirSync(resourcesDir);
95
- const jsonFiles = files.filter(f => f.endsWith('.json') && !f.startsWith('.'));
96
-
97
- const shims = getShimsForFiles(jsonFiles, 'resources');
98
-
99
- for (const [tsFile, content] of Object.entries(shims)) {
100
- const tsPath = path.join(resourcesDir, tsFile);
101
- fs.writeFileSync(tsPath, content, 'utf-8');
102
- console.log(`Generated ${tsFile} in ${resourcesDir}`);
103
- totalCount++;
104
- }
105
- console.log(`Generated ${jsonFiles.length} TypeScript resource shims in ${resourcesDir}`);
106
- } else {
107
- console.warn(`Resources directory not found at ${resourcesDir}`);
108
- }
109
-
110
- // Genesis (normalized) shim
111
- try {
112
- const genesisJsonPath = config.getNormalizedSourcePath();
113
- if (fs.existsSync(genesisJsonPath)) {
114
- fs.mkdirSync(generatedResourceTypesDir, { recursive: true });
115
- const tsFile = 'Genesis.ts';
116
- const content = generateShimContent('Genesis.json', 'schema');
117
- const tsPath = path.join(generatedResourceTypesDir, tsFile);
118
-
119
- fs.writeFileSync(tsPath, content, 'utf-8');
120
- console.log(`Generated ${tsFile} in ${generatedResourceTypesDir}`);
121
- totalCount++;
122
- } else {
123
- console.warn(`Genesis source JSON not found at ${genesisJsonPath}; skipping Genesis.ts shim`);
124
- }
125
- } catch (e) {
126
- console.warn('Failed to generate Genesis.ts shim:', e);
127
- }
128
-
129
- console.log(`Generated ${totalCount} total TypeScript shims`);
130
- }
131
-
132
- main().catch((e) => {
133
- console.error(e);
134
- process.exit(1);
135
- });
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { getConfig } from './_lib/config.js';
4
+
5
+ /**
6
+ * Generate TypeScript shim files for all JSON schemas and resources
7
+ *
8
+ * Creates .ts files that import and re-export .json files using
9
+ * the JSON import assertion syntax. This enables proper dependency resolution
10
+ * and type inference when importing schemas in TypeScript.
11
+ *
12
+ * Generates shims for:
13
+ * - schemas dir: config.getSchemasDir() (schema files)
14
+ * - standalone schemas dir: config.getSchemasStandaloneDir() (standalone schema files)
15
+ * - resources dir: config.getResourcesDir() (resource envelope files)
16
+ *
17
+ * Usage: node ./dist/scripts/generateSchemaShims.js
18
+ */
19
+
20
+ // PURE: Generate the .ts shim module content for a given .json filename.
21
+ function generateShimContent(jsonFile: string, variableName: string): string {
22
+ return `import ${variableName} from './${jsonFile}' with { type: 'json' };\nexport default ${variableName};\n`;
23
+ }
24
+
25
+ // PURE: Map JSON filenames to deterministic shim file contents.
26
+ function getShimsForFiles(jsonFiles: string[], variableName: string): Record<string, string> {
27
+ const shims: Record<string, string> = {};
28
+ for (const jsonFile of jsonFiles) {
29
+ const baseName = path.basename(jsonFile, '.json');
30
+ const tsFile = `${baseName}.ts`;
31
+ shims[tsFile] = generateShimContent(jsonFile, variableName);
32
+ }
33
+ return shims;
34
+ }
35
+
36
+ // IMPURE: Script entrypoint (config + filesystem I/O + console + process exit code).
37
+ function main() {
38
+ try {
39
+ const config = getConfig();
40
+ const schemasDir = config.getSchemasDir();
41
+ const standaloneSchemasDir = config.getSchemasStandaloneDir();
42
+ const resourcesDir = config.getResourcesDir();
43
+ const generatedResourceTypesDir = config.getNormalizedDir();
44
+
45
+ let totalCount = 0;
46
+
47
+ // Process schemas directory
48
+ if (fs.existsSync(schemasDir)) {
49
+ const files = fs.readdirSync(schemasDir);
50
+ const jsonFiles = files.filter((f) => f.endsWith('.json') && !f.startsWith('.'));
51
+
52
+ const shims = getShimsForFiles(jsonFiles, 'schema');
53
+
54
+ for (const [tsFile, content] of Object.entries(shims)) {
55
+ const tsPath = path.join(schemasDir, tsFile);
56
+ fs.writeFileSync(tsPath, content, 'utf-8');
57
+ console.log('Generated ' + tsFile + ' in ' + schemasDir);
58
+ totalCount++;
59
+ }
60
+ console.log('Generated ' + jsonFiles.length + ' TypeScript schema shims in ' + schemasDir);
61
+ } else {
62
+ console.warn('Schemas directory not found at ' + schemasDir);
63
+ }
64
+
65
+ // Process standalone schemas directory
66
+ if (fs.existsSync(standaloneSchemasDir)) {
67
+ const files = fs.readdirSync(standaloneSchemasDir);
68
+ const jsonFiles = files.filter((f) => f.endsWith('.json') && !f.startsWith('.'));
69
+
70
+ const shims = getShimsForFiles(jsonFiles, 'schema');
71
+
72
+ for (const [tsFile, content] of Object.entries(shims)) {
73
+ const tsPath = path.join(standaloneSchemasDir, tsFile);
74
+ fs.writeFileSync(tsPath, content, 'utf-8');
75
+ console.log('Generated ' + tsFile + ' in ' + standaloneSchemasDir);
76
+ totalCount++;
77
+ }
78
+ console.log('Generated ' + jsonFiles.length + ' TypeScript standalone schema shims in ' + standaloneSchemasDir);
79
+ } else {
80
+ // Standalone schemas are optional
81
+ }
82
+
83
+ // Process resources directory
84
+ if (fs.existsSync(resourcesDir)) {
85
+ const files = fs.readdirSync(resourcesDir);
86
+ const jsonFiles = files.filter((f) => f.endsWith('.json') && !f.startsWith('.'));
87
+
88
+ const shims = getShimsForFiles(jsonFiles, 'resources');
89
+
90
+ for (const [tsFile, content] of Object.entries(shims)) {
91
+ const tsPath = path.join(resourcesDir, tsFile);
92
+ fs.writeFileSync(tsPath, content, 'utf-8');
93
+ console.log('Generated ' + tsFile + ' in ' + resourcesDir);
94
+ totalCount++;
95
+ }
96
+ console.log('Generated ' + jsonFiles.length + ' TypeScript resource shims in ' + resourcesDir);
97
+ } else {
98
+ console.warn('Resources directory not found at ' + resourcesDir);
99
+ }
100
+
101
+ // Genesis (normalized) shim
102
+ try {
103
+ const genesisJsonPath = config.getNormalizedSourcePath();
104
+ if (fs.existsSync(genesisJsonPath)) {
105
+ fs.mkdirSync(generatedResourceTypesDir, { recursive: true });
106
+ const tsFile = 'Genesis.ts';
107
+ const content = generateShimContent('Genesis.json', 'schema');
108
+ const tsPath = path.join(generatedResourceTypesDir, tsFile);
109
+
110
+ fs.writeFileSync(tsPath, content, 'utf-8');
111
+ console.log('Generated ' + tsFile + ' in ' + generatedResourceTypesDir);
112
+ totalCount++;
113
+ } else {
114
+ console.warn('Genesis source JSON not found at ' + genesisJsonPath + '; skipping Genesis.ts shim');
115
+ }
116
+ } catch (e) {
117
+ console.warn('Failed to generate Genesis.ts shim:', e);
118
+ }
119
+
120
+ console.log('Generated ' + totalCount + ' total TypeScript shims');
121
+ } catch (e) {
122
+ console.error(e);
123
+ process.exitCode = 1;
124
+ }
125
+ }
126
+
127
+ main();