@toolproof-core/schema 1.0.4 → 1.0.5

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 (63) hide show
  1. package/dist/generated/normalized/Genesis.json +0 -257
  2. package/dist/generated/resources/Genesis.json +0 -295
  3. package/dist/generated/schemas/Genesis.json +0 -146
  4. package/dist/generated/schemas/standalone/Goal.json +0 -33
  5. package/dist/generated/schemas/standalone/Job.json +0 -42
  6. package/dist/generated/schemas/standalone/RawStrategy.json +0 -46
  7. package/dist/generated/schemas/standalone/ResourceType.json +0 -34
  8. package/dist/generated/schemas/standalone/RunnableStrategy.json +0 -51
  9. package/dist/generated/schemas/standalone/StrategyRun.json +0 -65
  10. package/dist/generated/{typesTS → types}/standalone/Resource_Genesis.d.ts +1 -1
  11. package/{src/generated/typesTS → dist/generated/types}/standalone/Resource_Job.d.ts +1 -1
  12. package/{src/generated/typesTS → dist/generated/types}/standalone/Resource_RawStrategy.d.ts +1 -1
  13. package/{src/generated/typesTS → dist/generated/types}/standalone/Resource_ResourceType.d.ts +1 -1
  14. package/dist/generated/{typesTS → types}/standalone/Resource_RunnableStrategy.d.ts +1 -1
  15. package/dist/generated/{typesTS/typesTS.d.ts → types/types.d.ts} +13 -42
  16. package/dist/index.d.ts +6 -6
  17. package/dist/scripts/_lib/config.d.ts +12 -12
  18. package/dist/scripts/_lib/config.js +25 -27
  19. package/dist/scripts/generateSchemaShims.js +2 -2
  20. package/dist/scripts/generateStandaloneSchema.js +1 -1
  21. package/dist/scripts/{generateStandaloneTypeTS.js → generateStandaloneType.js} +9 -9
  22. package/dist/scripts/{generateTypesTS.js → generateTypes.js} +11 -11
  23. package/dist/scripts/normalizeAnchorsToPointers.d.ts +1 -1
  24. package/dist/scripts/normalizeAnchorsToPointers.js +33 -12
  25. package/package.json +5 -5
  26. package/src/Genesis.json +0 -170
  27. package/src/generated/dependencies/dependencyMap.json +2 -13
  28. package/src/generated/normalized/Genesis.json +0 -257
  29. package/src/generated/resources/Genesis.json +0 -295
  30. package/src/generated/schemas/Genesis.json +0 -146
  31. package/src/generated/schemas/standalone/Goal.json +0 -33
  32. package/src/generated/schemas/standalone/Job.json +0 -42
  33. package/src/generated/schemas/standalone/RawStrategy.json +0 -46
  34. package/src/generated/schemas/standalone/ResourceType.json +0 -34
  35. package/src/generated/schemas/standalone/RunnableStrategy.json +0 -51
  36. package/src/generated/schemas/standalone/StrategyRun.json +0 -65
  37. package/src/generated/{typesTS → types}/standalone/Resource_Genesis.d.ts +1 -1
  38. package/{dist/generated/typesTS → src/generated/types}/standalone/Resource_Job.d.ts +1 -1
  39. package/{dist/generated/typesTS → src/generated/types}/standalone/Resource_RawStrategy.d.ts +1 -1
  40. package/{dist/generated/typesTS → src/generated/types}/standalone/Resource_ResourceType.d.ts +1 -1
  41. package/src/generated/{typesTS → types}/standalone/Resource_RunnableStrategy.d.ts +1 -1
  42. package/src/generated/{typesTS/typesTS.d.ts → types/types.d.ts} +13 -42
  43. package/src/index.ts +6 -7
  44. package/src/scripts/_lib/config.ts +27 -29
  45. package/src/scripts/generateSchemaShims.ts +2 -2
  46. package/src/scripts/generateStandaloneSchema.ts +1 -1
  47. package/src/scripts/{generateStandaloneTypeTS.ts → generateStandaloneType.ts} +9 -9
  48. package/src/scripts/{generateTypesTS.ts → generateTypes.ts} +11 -11
  49. package/src/scripts/normalizeAnchorsToPointers.ts +38 -12
  50. /package/dist/generated/{typesTS → types}/standalone/Resource_Genesis.js +0 -0
  51. /package/dist/generated/{typesTS → types}/standalone/Resource_Job.js +0 -0
  52. /package/dist/generated/{typesTS → types}/standalone/Resource_RawStrategy.js +0 -0
  53. /package/dist/generated/{typesTS → types}/standalone/Resource_ResourceType.js +0 -0
  54. /package/dist/generated/{typesTS → types}/standalone/Resource_RunnableStrategy.js +0 -0
  55. /package/dist/generated/{typesTS/typesTS.js → types/types.js} +0 -0
  56. /package/dist/scripts/{generateStandaloneTypeTS.d.ts → generateStandaloneType.d.ts} +0 -0
  57. /package/dist/scripts/{generateTypesTS.d.ts → generateTypes.d.ts} +0 -0
  58. /package/src/generated/{typesTS → types}/standalone/Resource_Genesis.js +0 -0
  59. /package/src/generated/{typesTS → types}/standalone/Resource_Job.js +0 -0
  60. /package/src/generated/{typesTS → types}/standalone/Resource_RawStrategy.js +0 -0
  61. /package/src/generated/{typesTS → types}/standalone/Resource_ResourceType.js +0 -0
  62. /package/src/generated/{typesTS → types}/standalone/Resource_RunnableStrategy.js +0 -0
  63. /package/src/generated/{typesTS/typesTS.js → types/types.js} +0 -0
@@ -26,8 +26,8 @@ export class SchemaConfig {
26
26
  private readonly schemasDir: string;
27
27
  private readonly resourcesDir: string;
28
28
  private readonly dependencyMapPath: string;
29
- private readonly typesTsSrcDir: string;
30
- private readonly typesTsDistDir: string;
29
+ private readonly typesSrcDir: string;
30
+ private readonly typesDistDir: string;
31
31
 
32
32
  // Schema metadata
33
33
  private readonly baseUrl: string;
@@ -38,14 +38,12 @@ export class SchemaConfig {
38
38
  this.root = getEnv('TP_SCHEMA_ROOT', process.cwd());
39
39
  this.sourceDir = getEnv('TP_SCHEMA_SOURCE_DIR', 'src/');
40
40
  this.sourceFile = getEnv('TP_SCHEMA_SOURCE_FILE', 'Genesis.json');
41
- // Intermediate, generated artifact produced by normalizeAnchorsToPointers.
42
- // This should NOT live next to the source-of-truth schemas.
43
41
  this.normalizedDir = getEnv('TP_SCHEMA_NORMALIZED_DIR', 'src/generated/normalized');
44
42
  this.schemasDir = getEnv('TP_SCHEMA_SCHEMAS_DIR', 'src/generated/schemas');
45
43
  this.resourcesDir = getEnv('TP_SCHEMA_RESOURCES_DIR', 'src/generated/resources');
46
44
  this.dependencyMapPath = getEnv('TP_SCHEMA_DEPENDENCY_MAP_PATH', 'src/generated/dependencies/dependencyMap.json');
47
- this.typesTsSrcDir = getEnv('TP_SCHEMA_TYPES_TS_SRC_DIR', 'src/generated/typesTS');
48
- this.typesTsDistDir = getEnv('TP_SCHEMA_TYPES_TS_DIST_DIR', 'dist/generated/typesTS');
45
+ this.typesSrcDir = getEnv('TP_SCHEMA_TYPES_SRC_DIR', 'src/generated/types');
46
+ this.typesDistDir = getEnv('TP_SCHEMA_TYPES_DIST_DIR', 'dist/generated/types');
49
47
  this.baseUrl = getEnv('TP_SCHEMA_BASE_URL', 'https://schemas.toolproof.com');
50
48
  this.version = getEnv('TP_SCHEMA_VERSION', 'v0');
51
49
  }
@@ -96,48 +94,48 @@ export class SchemaConfig {
96
94
  return path.join(this.getSchemasDir(), filename);
97
95
  }
98
96
 
99
- getSchemasStandaloneDir(): string {
97
+ getStandaloneSchemaDir(): string {
100
98
  return path.join(this.getSchemasDir(), 'standalone');
101
99
  }
102
100
 
103
- getSchemaStandalonePath(filename: string): string {
104
- return path.join(this.getSchemasStandaloneDir(), filename);
101
+ getStandaloneSchemaPath(filename: string): string {
102
+ return path.join(this.getStandaloneSchemaDir(), filename);
105
103
  }
106
104
 
107
- getTypesTsSrcDir(): string {
108
- return path.isAbsolute(this.typesTsSrcDir)
109
- ? this.typesTsSrcDir
110
- : path.join(this.root, this.typesTsSrcDir);
105
+ getTypesSrcDir(): string {
106
+ return path.isAbsolute(this.typesSrcDir)
107
+ ? this.typesSrcDir
108
+ : path.join(this.root, this.typesSrcDir);
111
109
  }
112
110
 
113
- getTypesTsDistDir(): string {
114
- return path.isAbsolute(this.typesTsDistDir)
115
- ? this.typesTsDistDir
116
- : path.join(this.root, this.typesTsDistDir);
111
+ getTypesDistDir(): string {
112
+ return path.isAbsolute(this.typesDistDir)
113
+ ? this.typesDistDir
114
+ : path.join(this.root, this.typesDistDir);
117
115
  }
118
116
 
119
- getTypesTsSrcPath(filename: string): string {
120
- return path.join(this.getTypesTsSrcDir(), filename);
117
+ getTypesSrcPath(filename: string): string {
118
+ return path.join(this.getTypesSrcDir(), filename);
121
119
  }
122
120
 
123
- getTypesTsDistPath(filename: string): string {
124
- return path.join(this.getTypesTsDistDir(), filename);
121
+ getTypesDistPath(filename: string): string {
122
+ return path.join(this.getTypesDistDir(), filename);
125
123
  }
126
124
 
127
- getStandaloneTypeTsSrcDir(): string {
128
- return path.join(this.getTypesTsSrcDir(), 'standalone');
125
+ getStandaloneTypeSrcDir(): string {
126
+ return path.join(this.getTypesSrcDir(), 'standalone');
129
127
  }
130
128
 
131
- getStandaloneTypeTsDistDir(): string {
132
- return path.join(this.getTypesTsDistDir(), 'standalone');
129
+ getStandaloneTypeDistDir(): string {
130
+ return path.join(this.getTypesDistDir(), 'standalone');
133
131
  }
134
132
 
135
- getStandaloneTypeTsSrcPath(filename: string): string {
136
- return path.join(this.getStandaloneTypeTsSrcDir(), filename);
133
+ getStandaloneTypeSrcPath(filename: string): string {
134
+ return path.join(this.getStandaloneTypeSrcDir(), filename);
137
135
  }
138
136
 
139
- getStandaloneTypeTsDistPath(filename: string): string {
140
- return path.join(this.getStandaloneTypeTsDistDir(), filename);
137
+ getStandaloneTypeDistPath(filename: string): string {
138
+ return path.join(this.getStandaloneTypeDistDir(), filename);
141
139
  }
142
140
 
143
141
  getResourcesDir(): string {
@@ -11,7 +11,7 @@ import { getConfig } from './_lib/config.js';
11
11
  *
12
12
  * Generates shims for:
13
13
  * - schemas dir: config.getSchemasDir() (schema files)
14
- * - standalone schemas dir: config.getSchemasStandaloneDir() (standalone schema files)
14
+ * - standalone schemas dir: config.getStandaloneSchemaDir() (standalone schema files)
15
15
  * - resources dir: config.getResourcesDir() (resource envelope files)
16
16
  *
17
17
  * Usage: node ./dist/scripts/generateSchemaShims.js
@@ -38,7 +38,7 @@ function main() {
38
38
  try {
39
39
  const config = getConfig();
40
40
  const schemasDir = config.getSchemasDir();
41
- const standaloneSchemasDir = config.getSchemasStandaloneDir();
41
+ const standaloneSchemasDir = config.getStandaloneSchemaDir();
42
42
  const resourcesDir = config.getResourcesDir();
43
43
  const generatedResourceTypesDir = config.getNormalizedDir();
44
44
 
@@ -161,7 +161,7 @@ async function main() {
161
161
 
162
162
  const schemasDir = config.getSchemasDir();
163
163
  const genesisPath = path.join(schemasDir, config.getSourceFile());
164
- const outPath = config.getSchemaStandalonePath(`${name}.json`);
164
+ const outPath = config.getStandaloneSchemaPath(`${name}.json`);
165
165
 
166
166
  if (!fs.existsSync(genesisPath)) {
167
167
  throw new Error(`Genesis.json not found at ${genesisPath}. Run extractSchemasFromResourceTypeShells first.`);
@@ -5,14 +5,14 @@ import { getConfig } from "./_lib/config.js";
5
5
  * Generate a typed Resource variant where `nucleus` is typed to a specific schema
6
6
  * extracted under the configured output directory.
7
7
  *
8
- * Usage: node ./dist/scripts/generateStandaloneType.js --name Job
8
+ * Usage: node ./dist/scripts/generateStandaloneTypes.js --name Job
9
9
  */
10
10
 
11
11
  // PURE: Generate the content of a standalone Resource type definition file for a given schema name.
12
12
  function generateStandaloneTypeLogic(name: string): string {
13
13
  const header = "// Auto-generated strict composite type. Do not edit.\n";
14
14
  const ts =
15
- `import type { ShellMaterializedBase, ${name} as NucleusSchema } from "../typesTS.js";\n` +
15
+ `import type { ShellMaterializedBase, ${name} as NucleusSchema } from "../types.js";\n` +
16
16
  `export type Resource_${name} = ShellMaterializedBase & { nucleus: NucleusSchema };\n`;
17
17
  return header + ts;
18
18
  }
@@ -70,7 +70,7 @@ function main() {
70
70
  const inPath =
71
71
  name === "Genesis"
72
72
  ? config.getSchemaPath("Genesis.json")
73
- : config.getSchemaStandalonePath(`${name}.json`);
73
+ : config.getStandaloneSchemaPath(`${name}.json`);
74
74
 
75
75
  if (!fs.existsSync(inPath)) {
76
76
  if (name === "Genesis") {
@@ -95,13 +95,13 @@ function main() {
95
95
  // Output setup
96
96
  const outName = `Resource_${name}.d.ts`;
97
97
  const outJsName = `Resource_${name}.js`;
98
- const outDir = config.getStandaloneTypeTsSrcDir();
99
- const distLibDir = config.getStandaloneTypeTsDistDir();
98
+ const outDir = config.getStandaloneTypeSrcDir();
99
+ const distLibDir = config.getStandaloneTypeDistDir();
100
100
 
101
101
  // Process src output
102
102
  fs.mkdirSync(outDir, { recursive: true });
103
- const outPath = config.getStandaloneTypeTsSrcPath(outName);
104
- const outJsPath = config.getStandaloneTypeTsSrcPath(outJsName);
103
+ const outPath = config.getStandaloneTypeSrcPath(outName);
104
+ const outJsPath = config.getStandaloneTypeSrcPath(outJsName);
105
105
  fs.writeFileSync(outPath, tsContent, "utf8");
106
106
  console.log(`Wrote ${outPath}`);
107
107
 
@@ -112,8 +112,8 @@ function main() {
112
112
 
113
113
  // Process dist output
114
114
  fs.mkdirSync(distLibDir, { recursive: true });
115
- const distDtsPath = config.getStandaloneTypeTsDistPath(outName);
116
- const distJsPath = config.getStandaloneTypeTsDistPath(outJsName);
115
+ const distDtsPath = config.getStandaloneTypeDistPath(outName);
116
+ const distJsPath = config.getStandaloneTypeDistPath(outJsName);
117
117
  fs.writeFileSync(distDtsPath, tsContent, "utf8");
118
118
  fs.writeFileSync(distJsPath, jsContent, "utf8");
119
119
  console.log(`Wrote ${distDtsPath}`);
@@ -407,10 +407,10 @@ function postProcessEmittedTypes(ts: string, parsedSchema: any): string {
407
407
  }
408
408
 
409
409
  // PURE: Add banner + formatting/guards to build the final .d.ts content.
410
- function finalizeOutputDts(emittedTypesTs: string): string {
410
+ function finalizeOutputDts(emittedType: string): string {
411
411
  const banner = '// Auto-generated from JSON schemas. Do not edit.\n';
412
412
 
413
- let output = banner + '\n' + emittedTypesTs + '\n';
413
+ let output = banner + '\n' + emittedType + '\n';
414
414
 
415
415
  // Final guard: strip any lingering `[k: string]: unknown;` that might have been
416
416
  // reintroduced by later transforms.
@@ -438,8 +438,8 @@ async function main() {
438
438
  try {
439
439
  const config = getConfig();
440
440
  const inputDir = config.getSchemasDir();
441
- const srcLibTypesDir = config.getTypesTsSrcDir();
442
- const srcLibOutputPath = config.getTypesTsSrcPath('typesTS.d.ts');
441
+ const srcLibTypesDir = config.getTypesSrcDir();
442
+ const srcLibOutputPath = config.getTypesSrcPath('types.d.ts');
443
443
 
444
444
  fs.mkdirSync(srcLibTypesDir, { recursive: true });
445
445
 
@@ -493,8 +493,8 @@ async function main() {
493
493
  }
494
494
 
495
495
  // Also write a copy into dist so consumers get the generated declarations
496
- const distLibTypesDir = config.getTypesTsDistDir();
497
- const distLibOutputPath = config.getTypesTsDistPath('typesTS.d.ts');
496
+ const distLibTypesDir = config.getTypesDistDir();
497
+ const distLibOutputPath = config.getTypesDistPath('types.d.ts');
498
498
  try {
499
499
  fs.mkdirSync(distLibTypesDir, { recursive: true });
500
500
  fs.writeFileSync(distLibOutputPath, output, 'utf8');
@@ -504,24 +504,24 @@ async function main() {
504
504
  console.warn('Failed to write types to dist:', e);
505
505
  }
506
506
 
507
- // Ensure there is a runtime-resolvable module next to `typesTS.d.ts`
507
+ // Ensure there is a runtime-resolvable module next to `types.d.ts`
508
508
  // Some consumers and TS NodeNext resolution expect a concrete .js next to .d.ts
509
509
  // The file is intentionally empty as all exports are types-only.
510
510
  try {
511
- const srcLibTypesJsPath = config.getTypesTsSrcPath('typesTS.js');
511
+ const srcLibTypesJsPath = config.getTypesSrcPath('types.js');
512
512
  if (!fs.existsSync(srcLibTypesJsPath)) {
513
513
  fs.writeFileSync(srcLibTypesJsPath, 'export {}\n', 'utf8');
514
514
  console.log('Wrote', srcLibTypesJsPath);
515
515
  }
516
516
  } catch (e) {
517
- console.warn('Failed to write typesTS.js to src/_lib:', e);
517
+ console.warn('Failed to write types.js to src/_lib:', e);
518
518
  }
519
519
  try {
520
- const distLibTypesJsPath = config.getTypesTsDistPath('typesTS.js');
520
+ const distLibTypesJsPath = config.getTypesDistPath('types.js');
521
521
  fs.writeFileSync(distLibTypesJsPath, 'export {}\n', 'utf8');
522
522
  console.log('Wrote', distLibTypesJsPath);
523
523
  } catch (e) {
524
- console.warn('Failed to write typesTS.js to dist/_lib:', e);
524
+ console.warn('Failed to write types.js to dist/_lib:', e);
525
525
  }
526
526
  } catch (err) {
527
527
  console.error(err);
@@ -2,18 +2,41 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { getConfig } from './_lib/config.js';
4
4
 
5
- /**
6
- * Rewrite anchor-style references to JSON Pointer references in Genesis.json
7
- *
8
- * Converts #AnchorName to #/$defs/AnchorName for compatibility with strict
9
- * JSON Schema validators and downstream tooling. This normalization step runs
10
- * before both schema extraction and resource envelope generation.
11
- *
12
- * The rewritten file is saved under src/genesis/generated/resourceTypes/Genesis.json
13
- * for use by other scripts.
14
- *
15
- * Usage: node ./dist/scripts/normalizeAnchorsToPointers.js
16
- */
5
+ /*
6
+ * Rewrite anchor-style references to JSON Pointer references in Genesis.json.
7
+ * We also strip all $anchor fields from the output since they are no longer needed after rewriting refs.
8
+ */
9
+
10
+ // PURE: Remove all `$anchor` keys from a schema tree without rewriting refs.
11
+ export function stripAnchors<T>(schema: T): T {
12
+ const seen = new WeakMap<object, unknown>();
13
+
14
+ function walk(node: unknown): unknown {
15
+ if (!node || typeof node !== 'object') return node;
16
+
17
+ const existing = seen.get(node as object);
18
+ if (existing) return existing;
19
+
20
+ if (Array.isArray(node)) {
21
+ const out: unknown[] = [];
22
+ seen.set(node, out);
23
+ for (const item of node) out.push(walk(item));
24
+ return out;
25
+ }
26
+
27
+ const out: Record<string, unknown> = {};
28
+ seen.set(node as object, out);
29
+
30
+ for (const [key, value] of Object.entries(node as Record<string, unknown>)) {
31
+ if (key === '$anchor') continue;
32
+ out[key] = walk(value);
33
+ }
34
+
35
+ return out;
36
+ }
37
+
38
+ return walk(schema) as T;
39
+ }
17
40
 
18
41
  // PURE: Rewrite anchor-style `$ref` strings (`#Anchor`) into JSON Pointer refs (`#/$defs/DefName`).
19
42
  function normalizeAnchorsToPointers(input: any): any {
@@ -102,6 +125,9 @@ function main() {
102
125
  // Rewrite anchors in the nucleusSchema (pure function call)
103
126
  genesis.nucleusSchema = normalizeAnchorsToPointers(genesis.nucleusSchema);
104
127
 
128
+ // Strip $anchor fields from the schemas (pure function call)
129
+ genesis.nucleusSchema = stripAnchors(genesis.nucleusSchema);
130
+
105
131
  // Write normalized version
106
132
  fs.mkdirSync(path.dirname(normalizedPath), { recursive: true });
107
133
  fs.writeFileSync(normalizedPath, JSON.stringify(genesis, null, 4), 'utf-8');