@toolproof-core/schema 1.0.7 → 1.0.9

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 (33) hide show
  1. package/dist/generated/constants/constants.d.ts +2 -2
  2. package/dist/generated/constants/constants.js +2 -2
  3. package/dist/generated/normalized/Genesis.json +5 -5
  4. package/dist/generated/resources/Genesis.json +5 -5
  5. package/dist/generated/schemas/Genesis.json +5 -5
  6. package/dist/generated/schemas/standalone/RawStrategy.json +4 -4
  7. package/dist/generated/schemas/standalone/RunnableStrategy.json +5 -5
  8. package/dist/generated/schemas/standalone/StrategyRun.json +5 -5
  9. package/dist/generated/types/types.d.ts +5 -5
  10. package/dist/index.d.ts +1 -1
  11. package/dist/scripts/generateConstants.js +1 -1
  12. package/package.json +8 -7
  13. package/src/Genesis.json +1833 -1833
  14. package/src/generated/constants/constants.ts +2 -2
  15. package/src/generated/normalized/Genesis.json +5 -5
  16. package/src/generated/resources/Genesis.json +5 -5
  17. package/src/generated/schemas/Genesis.json +5 -5
  18. package/src/generated/schemas/standalone/RawStrategy.json +4 -4
  19. package/src/generated/schemas/standalone/RunnableStrategy.json +5 -5
  20. package/src/generated/schemas/standalone/StrategyRun.json +5 -5
  21. package/src/generated/types/types.d.ts +5 -5
  22. package/src/index.ts +70 -69
  23. package/src/scripts/_lib/config.ts +215 -215
  24. package/src/scripts/extractSchemasFromResourceTypeShells.ts +261 -261
  25. package/src/scripts/generateConstants.ts +217 -217
  26. package/src/scripts/generateDependencies.ts +121 -121
  27. package/src/scripts/generateSchemaShims.ts +127 -127
  28. package/src/scripts/generateStandaloneSchema.ts +185 -185
  29. package/src/scripts/generateStandaloneType.ts +127 -127
  30. package/src/scripts/generateTerminals.ts +73 -73
  31. package/src/scripts/generateTypes.ts +531 -531
  32. package/src/scripts/normalizeAnchorsToPointers.ts +141 -141
  33. package/src/scripts/wrapResourceTypesWithResourceShells.ts +82 -82
@@ -1,121 +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
- // 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
+ 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,127 +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.getStandaloneSchemaDir() (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.getStandaloneSchemaDir();
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();
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.getStandaloneSchemaDir() (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.getStandaloneSchemaDir();
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();