@toolproof-core/schema 1.0.9 → 1.0.10

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 (54) hide show
  1. package/dist/generated/artifacts/constants.d.ts +120 -0
  2. package/dist/generated/artifacts/constants.js +120 -0
  3. package/dist/generated/artifacts/mappings.d.ts +23 -0
  4. package/dist/generated/artifacts/mappings.js +23 -0
  5. package/dist/generated/normalized/Genesis.json +67 -53
  6. package/dist/generated/resources/Genesis.json +424 -236
  7. package/dist/generated/schemas/Genesis.json +56 -42
  8. package/dist/generated/schemas/standalone/Job.json +2 -0
  9. package/dist/generated/schemas/standalone/RawStrategy.json +86 -110
  10. package/dist/generated/schemas/standalone/RunnableStrategy.json +108 -132
  11. package/dist/generated/schemas/standalone/StrategyRun.json +86 -110
  12. package/dist/generated/types/types.d.ts +34 -34
  13. package/dist/index.d.ts +6 -3
  14. package/dist/index.js +5 -2
  15. package/dist/scripts/_lib/config.d.ts +3 -5
  16. package/dist/scripts/_lib/config.js +8 -14
  17. package/dist/scripts/generateConstantsAndMappings.d.ts +31 -0
  18. package/dist/scripts/generateConstantsAndMappings.js +243 -0
  19. package/dist/scripts/generateDependencies.js +1 -1
  20. package/dist/scripts/generateTerminals.js +2 -2
  21. package/dist/scripts/generateTypes.js +47 -2
  22. package/dist/scripts/wrapResourceTypesWithResourceShells.js +7 -3
  23. package/package.json +9 -10
  24. package/src/Genesis.json +1847 -1833
  25. package/src/generated/artifacts/constants.ts +121 -0
  26. package/src/generated/{dependencies → artifacts}/dependencyMap.json +16 -18
  27. package/src/generated/artifacts/mappings.ts +24 -0
  28. package/src/generated/{dependencies → artifacts}/terminals.json +1 -0
  29. package/src/generated/normalized/Genesis.json +1760 -1746
  30. package/src/generated/resources/Genesis.json +2796 -2608
  31. package/src/generated/schemas/Genesis.json +1329 -1315
  32. package/src/generated/schemas/standalone/Job.json +2 -0
  33. package/src/generated/schemas/standalone/RawStrategy.json +580 -604
  34. package/src/generated/schemas/standalone/RunnableStrategy.json +645 -669
  35. package/src/generated/schemas/standalone/StrategyRun.json +913 -937
  36. package/src/generated/types/types.d.ts +709 -709
  37. package/src/index.ts +75 -70
  38. package/src/scripts/_lib/config.ts +207 -215
  39. package/src/scripts/extractSchemasFromResourceTypeShells.ts +261 -261
  40. package/src/scripts/generateConstantsAndMappings.ts +309 -0
  41. package/src/scripts/generateDependencies.ts +121 -121
  42. package/src/scripts/generateSchemaShims.ts +127 -127
  43. package/src/scripts/generateStandaloneSchema.ts +185 -185
  44. package/src/scripts/generateStandaloneType.ts +127 -127
  45. package/src/scripts/generateTerminals.ts +73 -73
  46. package/src/scripts/generateTypes.ts +587 -531
  47. package/src/scripts/normalizeAnchorsToPointers.ts +141 -141
  48. package/src/scripts/wrapResourceTypesWithResourceShells.ts +86 -82
  49. package/dist/generated/constants/constants.d.ts +0 -60
  50. package/dist/generated/constants/constants.js +0 -60
  51. package/dist/scripts/generateConstants.d.ts +0 -12
  52. package/dist/scripts/generateConstants.js +0 -179
  53. package/src/generated/constants/constants.ts +0 -61
  54. package/src/scripts/generateConstants.ts +0 -217
@@ -1,127 +1,127 @@
1
- import fs from "fs";
2
- import { getConfig } from "./_lib/config.js";
3
-
4
- /**
5
- * Generate a typed Resource variant where `nucleus` is typed to a specific schema
6
- * extracted under the configured output directory.
7
- *
8
- * Usage: node ./dist/scripts/generateStandaloneTypes.js --name Job
9
- */
10
-
11
- // PURE: Generate the content of a standalone Resource type definition file for a given schema name.
12
- function generateStandaloneTypeLogic(name: string): string {
13
- const header = "// Auto-generated strict composite type. Do not edit.\n";
14
- const ts =
15
- `import type { ShellMaterializedBase, ${name} as NucleusSchema } from "../types.js";\n` +
16
- `export type Resource_${name} = ShellMaterializedBase & { nucleus: NucleusSchema };\n`;
17
- return header + ts;
18
- }
19
-
20
- // PURE: Strip accidental surrounding quotes from CLI values (PowerShell/cmd).
21
- function stripSurroundingQuotes(value: string): string {
22
- if ((value.startsWith("\"") && value.endsWith("\"")) || (value.startsWith("'") && value.endsWith("'"))) {
23
- return value.slice(1, -1);
24
- }
25
- return value;
26
- }
27
-
28
- // PURE: Validate a standalone schema and return warnings (no logging).
29
- function validateStandaloneSchemaForWarnings(schema: any): string[] {
30
- const warnings: string[] = [];
31
- if (schema?.$schema && schema.$schema !== "https://json-schema.org/draft/2020-12/schema") {
32
- warnings.push(
33
- `Warning: schema $schema is '${String(schema.$schema)}', expected draft 2020-12. Proceeding anyway.`
34
- );
35
- }
36
- if (schema?.type && schema.type !== "object") {
37
- warnings.push(
38
- `Warning: nucleusSchema usually has type: 'object' but this schema has type: '${String(schema.type)}'. Proceeding.`
39
- );
40
- }
41
- return warnings;
42
- }
43
-
44
- // PURE: Parse CLI args (no defaults, no filesystem probing).
45
- function parseArgs(args: string[]): { name?: string } {
46
- let name: string | undefined;
47
- for (let i = 0; i < args.length; i++) {
48
- const a = args[i];
49
- if (a === "--name") {
50
- name = args[i + 1];
51
- i++;
52
- } else if (a.startsWith("--name=")) {
53
- name = a.split("=")[1];
54
- }
55
- }
56
- const normalized = typeof name === "string" ? stripSurroundingQuotes(name) : undefined;
57
- return { name: normalized?.trim() ? normalized : undefined };
58
- }
59
-
60
- // IMPURE: Script entrypoint (config + filesystem I/O + console + process exit).
61
- function main() {
62
- try {
63
- const config = getConfig();
64
- const { name } = parseArgs(process.argv.slice(2));
65
-
66
- if (!name) {
67
- throw new Error("Missing --name <SchemaBasename> argument");
68
- }
69
-
70
- const inPath =
71
- name === "Genesis"
72
- ? config.getSchemaPath("Genesis.json")
73
- : config.getStandaloneSchemaPath(`${name}.json`);
74
-
75
- if (!fs.existsSync(inPath)) {
76
- if (name === "Genesis") {
77
- console.error(`Schema file not found: ${inPath}`);
78
- console.error("Run extractSchemasFromResourceTypeShells first.");
79
- } else {
80
- console.error(`Standalone schema file not found: ${inPath}`);
81
- console.error(`Run generateStandaloneSchema -- --name ${name} first.`);
82
- }
83
- throw new Error("Input schema file not found");
84
- }
85
-
86
- // Basic validation against the expected shape of nucleusSchema.
87
- const raw = fs.readFileSync(inPath, "utf8");
88
- const parsed: any = JSON.parse(raw);
89
-
90
- for (const warning of validateStandaloneSchemaForWarnings(parsed)) console.warn(warning);
91
-
92
- const tsContent = generateStandaloneTypeLogic(name);
93
- const jsContent = "export {}\n";
94
-
95
- // Output setup
96
- const outName = `Resource_${name}.d.ts`;
97
- const outJsName = `Resource_${name}.js`;
98
- const outDir = config.getStandaloneTypeSrcDir();
99
- const distLibDir = config.getStandaloneTypeDistDir();
100
-
101
- // Process src output
102
- fs.mkdirSync(outDir, { recursive: true });
103
- const outPath = config.getStandaloneTypeSrcPath(outName);
104
- const outJsPath = config.getStandaloneTypeSrcPath(outJsName);
105
- fs.writeFileSync(outPath, tsContent, "utf8");
106
- console.log(`Wrote ${outPath}`);
107
-
108
- if (!fs.existsSync(outJsPath)) {
109
- fs.writeFileSync(outJsPath, jsContent, "utf8");
110
- console.log(`Wrote ${outJsPath}`);
111
- }
112
-
113
- // Process dist output
114
- fs.mkdirSync(distLibDir, { recursive: true });
115
- const distDtsPath = config.getStandaloneTypeDistPath(outName);
116
- const distJsPath = config.getStandaloneTypeDistPath(outJsName);
117
- fs.writeFileSync(distDtsPath, tsContent, "utf8");
118
- fs.writeFileSync(distJsPath, jsContent, "utf8");
119
- console.log(`Wrote ${distDtsPath}`);
120
- console.log(`Wrote ${distJsPath}`);
121
- } catch (e) {
122
- console.error(e);
123
- process.exitCode = 1;
124
- }
125
- }
126
-
127
- main();
1
+ import fs from "fs";
2
+ import { getConfig } from "./_lib/config.js";
3
+
4
+ /**
5
+ * Generate a typed Resource variant where `nucleus` is typed to a specific schema
6
+ * extracted under the configured output directory.
7
+ *
8
+ * Usage: node ./dist/scripts/generateStandaloneTypes.js --name Job
9
+ */
10
+
11
+ // PURE: Generate the content of a standalone Resource type definition file for a given schema name.
12
+ function generateStandaloneTypeLogic(name: string): string {
13
+ const header = "// Auto-generated strict composite type. Do not edit.\n";
14
+ const ts =
15
+ `import type { ShellMaterializedBase, ${name} as NucleusSchema } from "../types.js";\n` +
16
+ `export type Resource_${name} = ShellMaterializedBase & { nucleus: NucleusSchema };\n`;
17
+ return header + ts;
18
+ }
19
+
20
+ // PURE: Strip accidental surrounding quotes from CLI values (PowerShell/cmd).
21
+ function stripSurroundingQuotes(value: string): string {
22
+ if ((value.startsWith("\"") && value.endsWith("\"")) || (value.startsWith("'") && value.endsWith("'"))) {
23
+ return value.slice(1, -1);
24
+ }
25
+ return value;
26
+ }
27
+
28
+ // PURE: Validate a standalone schema and return warnings (no logging).
29
+ function validateStandaloneSchemaForWarnings(schema: any): string[] {
30
+ const warnings: string[] = [];
31
+ if (schema?.$schema && schema.$schema !== "https://json-schema.org/draft/2020-12/schema") {
32
+ warnings.push(
33
+ `Warning: schema $schema is '${String(schema.$schema)}', expected draft 2020-12. Proceeding anyway.`
34
+ );
35
+ }
36
+ if (schema?.type && schema.type !== "object") {
37
+ warnings.push(
38
+ `Warning: nucleusSchema usually has type: 'object' but this schema has type: '${String(schema.type)}'. Proceeding.`
39
+ );
40
+ }
41
+ return warnings;
42
+ }
43
+
44
+ // PURE: Parse CLI args (no defaults, no filesystem probing).
45
+ function parseArgs(args: string[]): { name?: string } {
46
+ let name: string | undefined;
47
+ for (let i = 0; i < args.length; i++) {
48
+ const a = args[i];
49
+ if (a === "--name") {
50
+ name = args[i + 1];
51
+ i++;
52
+ } else if (a.startsWith("--name=")) {
53
+ name = a.split("=")[1];
54
+ }
55
+ }
56
+ const normalized = typeof name === "string" ? stripSurroundingQuotes(name) : undefined;
57
+ return { name: normalized?.trim() ? normalized : undefined };
58
+ }
59
+
60
+ // IMPURE: Script entrypoint (config + filesystem I/O + console + process exit).
61
+ function main() {
62
+ try {
63
+ const config = getConfig();
64
+ const { name } = parseArgs(process.argv.slice(2));
65
+
66
+ if (!name) {
67
+ throw new Error("Missing --name <SchemaBasename> argument");
68
+ }
69
+
70
+ const inPath =
71
+ name === "Genesis"
72
+ ? config.getSchemaPath("Genesis.json")
73
+ : config.getStandaloneSchemaPath(`${name}.json`);
74
+
75
+ if (!fs.existsSync(inPath)) {
76
+ if (name === "Genesis") {
77
+ console.error(`Schema file not found: ${inPath}`);
78
+ console.error("Run extractSchemasFromResourceTypeShells first.");
79
+ } else {
80
+ console.error(`Standalone schema file not found: ${inPath}`);
81
+ console.error(`Run generateStandaloneSchema -- --name ${name} first.`);
82
+ }
83
+ throw new Error("Input schema file not found");
84
+ }
85
+
86
+ // Basic validation against the expected shape of nucleusSchema.
87
+ const raw = fs.readFileSync(inPath, "utf8");
88
+ const parsed: any = JSON.parse(raw);
89
+
90
+ for (const warning of validateStandaloneSchemaForWarnings(parsed)) console.warn(warning);
91
+
92
+ const tsContent = generateStandaloneTypeLogic(name);
93
+ const jsContent = "export {}\n";
94
+
95
+ // Output setup
96
+ const outName = `Resource_${name}.d.ts`;
97
+ const outJsName = `Resource_${name}.js`;
98
+ const outDir = config.getStandaloneTypeSrcDir();
99
+ const distLibDir = config.getStandaloneTypeDistDir();
100
+
101
+ // Process src output
102
+ fs.mkdirSync(outDir, { recursive: true });
103
+ const outPath = config.getStandaloneTypeSrcPath(outName);
104
+ const outJsPath = config.getStandaloneTypeSrcPath(outJsName);
105
+ fs.writeFileSync(outPath, tsContent, "utf8");
106
+ console.log(`Wrote ${outPath}`);
107
+
108
+ if (!fs.existsSync(outJsPath)) {
109
+ fs.writeFileSync(outJsPath, jsContent, "utf8");
110
+ console.log(`Wrote ${outJsPath}`);
111
+ }
112
+
113
+ // Process dist output
114
+ fs.mkdirSync(distLibDir, { recursive: true });
115
+ const distDtsPath = config.getStandaloneTypeDistPath(outName);
116
+ const distJsPath = config.getStandaloneTypeDistPath(outJsName);
117
+ fs.writeFileSync(distDtsPath, tsContent, "utf8");
118
+ fs.writeFileSync(distJsPath, jsContent, "utf8");
119
+ console.log(`Wrote ${distDtsPath}`);
120
+ console.log(`Wrote ${distJsPath}`);
121
+ } catch (e) {
122
+ console.error(e);
123
+ process.exitCode = 1;
124
+ }
125
+ }
126
+
127
+ main();
@@ -1,73 +1,73 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { getConfig } from "./_lib/config.js";
4
-
5
- type DependencyMap = Record<string, string[]>;
6
-
7
- // PURE: Validate + normalize a dependency map loaded from JSON.
8
- function normalizeDependencyMap(value: unknown): DependencyMap {
9
- if (!value || typeof value !== "object" || Array.isArray(value)) {
10
- throw new Error("Invalid dependencyMap.json: expected an object");
11
- }
12
-
13
- const input = value as Record<string, unknown>;
14
- const out: DependencyMap = {};
15
-
16
- // Preserve insertion order from the parsed JSON object.
17
- for (const [key, rawDeps] of Object.entries(input)) {
18
- if (rawDeps == null) {
19
- out[key] = [];
20
- continue;
21
- }
22
- if (!Array.isArray(rawDeps)) {
23
- throw new Error(`Invalid dependencyMap.json: value for ${key} must be an array`);
24
- }
25
- out[key] = rawDeps.filter((d): d is string => typeof d === "string");
26
- }
27
-
28
- return out;
29
- }
30
-
31
- // PURE: Compute terminals (defs that are not depended-upon by any other def).
32
- function computeTerminalsInKeyOrder(dependencyMap: DependencyMap): string[] {
33
- const keys = Object.keys(dependencyMap);
34
- const dependedUpon = new Set<string>();
35
-
36
- for (const key of keys) {
37
- for (const dep of dependencyMap[key] ?? []) {
38
- dependedUpon.add(dep);
39
- }
40
- }
41
-
42
- // Preserve key order from dependencyMap.json.
43
- return keys.filter((k) => !dependedUpon.has(k));
44
- }
45
-
46
- // IMPURE: Script entrypoint (config + filesystem I/O + console + process exit code).
47
- function main() {
48
- try {
49
- const config = getConfig();
50
-
51
- const inPath = config.getDependencyMapPath();
52
- const outPath = path.join(path.dirname(inPath), "terminals.json");
53
-
54
- if (!fs.existsSync(inPath)) {
55
- throw new Error(`Dependency map not found at ${inPath}. Run generateDependencies first.`);
56
- }
57
-
58
- const raw = fs.readFileSync(inPath, "utf8");
59
- const parsed = JSON.parse(raw) as unknown;
60
-
61
- const dependencyMap = normalizeDependencyMap(parsed);
62
- const terminals = computeTerminalsInKeyOrder(dependencyMap);
63
-
64
- fs.mkdirSync(path.dirname(outPath), { recursive: true });
65
- fs.writeFileSync(outPath, JSON.stringify(terminals, null, 4), "utf8");
66
- console.log(`Wrote terminals to ${outPath}`);
67
- } catch (error: any) {
68
- console.error(`Error generating terminals: ${error?.message ?? error}`);
69
- process.exitCode = 1;
70
- }
71
- }
72
-
73
- main();
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { getConfig } from "./_lib/config.js";
4
+
5
+ type DependencyMap = Record<string, string[]>;
6
+
7
+ // PURE: Validate + normalize a dependency map loaded from JSON.
8
+ function normalizeDependencyMap(value: unknown): DependencyMap {
9
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
10
+ throw new Error("Invalid dependencyMap.json: expected an object");
11
+ }
12
+
13
+ const input = value as Record<string, unknown>;
14
+ const out: DependencyMap = {};
15
+
16
+ // Preserve insertion order from the parsed JSON object.
17
+ for (const [key, rawDeps] of Object.entries(input)) {
18
+ if (rawDeps == null) {
19
+ out[key] = [];
20
+ continue;
21
+ }
22
+ if (!Array.isArray(rawDeps)) {
23
+ throw new Error(`Invalid dependencyMap.json: value for ${key} must be an array`);
24
+ }
25
+ out[key] = rawDeps.filter((d): d is string => typeof d === "string");
26
+ }
27
+
28
+ return out;
29
+ }
30
+
31
+ // PURE: Compute terminals (defs that are not depended-upon by any other def).
32
+ function computeTerminalsInKeyOrder(dependencyMap: DependencyMap): string[] {
33
+ const keys = Object.keys(dependencyMap);
34
+ const dependedUpon = new Set<string>();
35
+
36
+ for (const key of keys) {
37
+ for (const dep of dependencyMap[key] ?? []) {
38
+ dependedUpon.add(dep);
39
+ }
40
+ }
41
+
42
+ // Preserve key order from dependencyMap.json.
43
+ return keys.filter((k) => !dependedUpon.has(k));
44
+ }
45
+
46
+ // IMPURE: Script entrypoint (config + filesystem I/O + console + process exit code).
47
+ function main() {
48
+ try {
49
+ const config = getConfig();
50
+
51
+ const inPath = config.getArtifactsPath("dependencyMap.json");
52
+ const outPath = config.getArtifactsPath("terminals.json");
53
+
54
+ if (!fs.existsSync(inPath)) {
55
+ throw new Error(`Dependency map not found at ${inPath}. Run generateDependencies first.`);
56
+ }
57
+
58
+ const raw = fs.readFileSync(inPath, "utf8");
59
+ const parsed = JSON.parse(raw) as unknown;
60
+
61
+ const dependencyMap = normalizeDependencyMap(parsed);
62
+ const terminals = computeTerminalsInKeyOrder(dependencyMap);
63
+
64
+ fs.mkdirSync(path.dirname(outPath), { recursive: true });
65
+ fs.writeFileSync(outPath, JSON.stringify(terminals, null, 4), "utf8");
66
+ console.log(`Wrote terminals to ${outPath}`);
67
+ } catch (error: any) {
68
+ console.error(`Error generating terminals: ${error?.message ?? error}`);
69
+ process.exitCode = 1;
70
+ }
71
+ }
72
+
73
+ main();