@toolproof-core/schema 1.0.9 → 1.0.11

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 (67) hide show
  1. package/dist/generated/artifacts/constants.d.ts +121 -0
  2. package/dist/generated/artifacts/constants.js +121 -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 +117 -78
  6. package/dist/generated/resources/Genesis.json +489 -264
  7. package/dist/generated/schemas/Genesis.json +94 -61
  8. package/dist/generated/schemas/standalone/Job.json +9 -8
  9. package/dist/generated/schemas/standalone/RawStrategy.json +86 -110
  10. package/dist/generated/schemas/standalone/ResourceType.json +4 -4
  11. package/dist/generated/schemas/standalone/RunnableStrategy.json +115 -139
  12. package/dist/generated/schemas/standalone/StrategyRun.json +93 -117
  13. package/dist/generated/types/standalone/Resource_Genesis.d.ts +1 -1
  14. package/dist/generated/types/standalone/Resource_Job.d.ts +1 -1
  15. package/dist/generated/types/standalone/Resource_RawStrategy.d.ts +1 -1
  16. package/dist/generated/types/standalone/Resource_ResourceType.d.ts +1 -1
  17. package/dist/generated/types/standalone/Resource_RunnableStrategy.d.ts +1 -1
  18. package/dist/generated/types/types.d.ts +247 -239
  19. package/dist/index.d.ts +6 -3
  20. package/dist/index.js +5 -2
  21. package/dist/scripts/_lib/config.d.ts +3 -5
  22. package/dist/scripts/_lib/config.js +8 -14
  23. package/dist/scripts/generateConstantsAndMappings.d.ts +31 -0
  24. package/dist/scripts/generateConstantsAndMappings.js +243 -0
  25. package/dist/scripts/generateDependencies.js +1 -1
  26. package/dist/scripts/generateStandaloneType.js +2 -1
  27. package/dist/scripts/generateTerminals.js +2 -2
  28. package/dist/scripts/generateTypes.js +183 -5
  29. package/dist/scripts/wrapResourceTypesWithResourceShells.js +7 -3
  30. package/package.json +9 -10
  31. package/src/Genesis.json +1873 -1833
  32. package/src/generated/artifacts/constants.ts +122 -0
  33. package/src/generated/{dependencies → artifacts}/dependencyMap.json +282 -280
  34. package/src/generated/artifacts/mappings.ts +24 -0
  35. package/src/generated/{dependencies → artifacts}/terminals.json +13 -11
  36. package/src/generated/normalized/Genesis.json +1785 -1746
  37. package/src/generated/resources/Genesis.json +2833 -2608
  38. package/src/generated/schemas/Genesis.json +1348 -1315
  39. package/src/generated/schemas/standalone/Job.json +195 -194
  40. package/src/generated/schemas/standalone/RawStrategy.json +86 -110
  41. package/src/generated/schemas/standalone/ResourceType.json +106 -106
  42. package/src/generated/schemas/standalone/RunnableStrategy.json +645 -669
  43. package/src/generated/schemas/standalone/StrategyRun.json +913 -937
  44. package/src/generated/types/standalone/Resource_Genesis.d.ts +3 -3
  45. package/src/generated/types/standalone/Resource_Job.d.ts +3 -3
  46. package/src/generated/types/standalone/Resource_RawStrategy.d.ts +3 -3
  47. package/src/generated/types/standalone/Resource_ResourceType.d.ts +3 -3
  48. package/src/generated/types/standalone/Resource_RunnableStrategy.d.ts +3 -3
  49. package/src/generated/types/types.d.ts +717 -709
  50. package/src/index.ts +77 -70
  51. package/src/scripts/_lib/config.ts +207 -215
  52. package/src/scripts/extractSchemasFromResourceTypeShells.ts +261 -261
  53. package/src/scripts/generateConstantsAndMappings.ts +309 -0
  54. package/src/scripts/generateDependencies.ts +121 -121
  55. package/src/scripts/generateSchemaShims.ts +127 -127
  56. package/src/scripts/generateStandaloneSchema.ts +185 -185
  57. package/src/scripts/generateStandaloneType.ts +129 -127
  58. package/src/scripts/generateTerminals.ts +73 -73
  59. package/src/scripts/generateTypes.ts +733 -531
  60. package/src/scripts/normalizeAnchorsToPointers.ts +141 -141
  61. package/src/scripts/wrapResourceTypesWithResourceShells.ts +86 -82
  62. package/dist/generated/constants/constants.d.ts +0 -60
  63. package/dist/generated/constants/constants.js +0 -60
  64. package/dist/scripts/generateConstants.d.ts +0 -12
  65. package/dist/scripts/generateConstants.js +0 -179
  66. package/src/generated/constants/constants.ts +0 -61
  67. package/src/scripts/generateConstants.ts +0 -217
@@ -1,127 +1,129 @@
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
+
15
+ const nucleusTypeName = name.endsWith("Json") ? name : `${name}Json`;
16
+ const ts =
17
+ `import type { ShellMaterializedBaseJson as ShellMaterializedBase, ${nucleusTypeName} as NucleusSchema } from "../types.js";\n` +
18
+ `export type Resource_${name} = ShellMaterializedBase & { nucleus: NucleusSchema };\n`;
19
+ return header + ts;
20
+ }
21
+
22
+ // PURE: Strip accidental surrounding quotes from CLI values (PowerShell/cmd).
23
+ function stripSurroundingQuotes(value: string): string {
24
+ if ((value.startsWith("\"") && value.endsWith("\"")) || (value.startsWith("'") && value.endsWith("'"))) {
25
+ return value.slice(1, -1);
26
+ }
27
+ return value;
28
+ }
29
+
30
+ // PURE: Validate a standalone schema and return warnings (no logging).
31
+ function validateStandaloneSchemaForWarnings(schema: any): string[] {
32
+ const warnings: string[] = [];
33
+ if (schema?.$schema && schema.$schema !== "https://json-schema.org/draft/2020-12/schema") {
34
+ warnings.push(
35
+ `Warning: schema $schema is '${String(schema.$schema)}', expected draft 2020-12. Proceeding anyway.`
36
+ );
37
+ }
38
+ if (schema?.type && schema.type !== "object") {
39
+ warnings.push(
40
+ `Warning: nucleusSchema usually has type: 'object' but this schema has type: '${String(schema.type)}'. Proceeding.`
41
+ );
42
+ }
43
+ return warnings;
44
+ }
45
+
46
+ // PURE: Parse CLI args (no defaults, no filesystem probing).
47
+ function parseArgs(args: string[]): { name?: string } {
48
+ let name: string | undefined;
49
+ for (let i = 0; i < args.length; i++) {
50
+ const a = args[i];
51
+ if (a === "--name") {
52
+ name = args[i + 1];
53
+ i++;
54
+ } else if (a.startsWith("--name=")) {
55
+ name = a.split("=")[1];
56
+ }
57
+ }
58
+ const normalized = typeof name === "string" ? stripSurroundingQuotes(name) : undefined;
59
+ return { name: normalized?.trim() ? normalized : undefined };
60
+ }
61
+
62
+ // IMPURE: Script entrypoint (config + filesystem I/O + console + process exit).
63
+ function main() {
64
+ try {
65
+ const config = getConfig();
66
+ const { name } = parseArgs(process.argv.slice(2));
67
+
68
+ if (!name) {
69
+ throw new Error("Missing --name <SchemaBasename> argument");
70
+ }
71
+
72
+ const inPath =
73
+ name === "Genesis"
74
+ ? config.getSchemaPath("Genesis.json")
75
+ : config.getStandaloneSchemaPath(`${name}.json`);
76
+
77
+ if (!fs.existsSync(inPath)) {
78
+ if (name === "Genesis") {
79
+ console.error(`Schema file not found: ${inPath}`);
80
+ console.error("Run extractSchemasFromResourceTypeShells first.");
81
+ } else {
82
+ console.error(`Standalone schema file not found: ${inPath}`);
83
+ console.error(`Run generateStandaloneSchema -- --name ${name} first.`);
84
+ }
85
+ throw new Error("Input schema file not found");
86
+ }
87
+
88
+ // Basic validation against the expected shape of nucleusSchema.
89
+ const raw = fs.readFileSync(inPath, "utf8");
90
+ const parsed: any = JSON.parse(raw);
91
+
92
+ for (const warning of validateStandaloneSchemaForWarnings(parsed)) console.warn(warning);
93
+
94
+ const tsContent = generateStandaloneTypeLogic(name);
95
+ const jsContent = "export {}\n";
96
+
97
+ // Output setup
98
+ const outName = `Resource_${name}.d.ts`;
99
+ const outJsName = `Resource_${name}.js`;
100
+ const outDir = config.getStandaloneTypeSrcDir();
101
+ const distLibDir = config.getStandaloneTypeDistDir();
102
+
103
+ // Process src output
104
+ fs.mkdirSync(outDir, { recursive: true });
105
+ const outPath = config.getStandaloneTypeSrcPath(outName);
106
+ const outJsPath = config.getStandaloneTypeSrcPath(outJsName);
107
+ fs.writeFileSync(outPath, tsContent, "utf8");
108
+ console.log(`Wrote ${outPath}`);
109
+
110
+ if (!fs.existsSync(outJsPath)) {
111
+ fs.writeFileSync(outJsPath, jsContent, "utf8");
112
+ console.log(`Wrote ${outJsPath}`);
113
+ }
114
+
115
+ // Process dist output
116
+ fs.mkdirSync(distLibDir, { recursive: true });
117
+ const distDtsPath = config.getStandaloneTypeDistPath(outName);
118
+ const distJsPath = config.getStandaloneTypeDistPath(outJsName);
119
+ fs.writeFileSync(distDtsPath, tsContent, "utf8");
120
+ fs.writeFileSync(distJsPath, jsContent, "utf8");
121
+ console.log(`Wrote ${distDtsPath}`);
122
+ console.log(`Wrote ${distJsPath}`);
123
+ } catch (e) {
124
+ console.error(e);
125
+ process.exitCode = 1;
126
+ }
127
+ }
128
+
129
+ 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();