@toolproof-core/schema 1.0.3 → 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.
- package/dist/generated/normalized/Genesis.json +16 -265
- package/dist/generated/resources/Genesis.json +18 -305
- package/dist/generated/schemas/Genesis.json +14 -152
- package/dist/generated/schemas/standalone/Goal.json +0 -33
- package/dist/generated/schemas/standalone/Job.json +0 -42
- package/dist/generated/schemas/standalone/RawStrategy.json +14 -52
- package/dist/generated/schemas/standalone/ResourceType.json +0 -34
- package/dist/generated/schemas/standalone/RunnableStrategy.json +14 -57
- package/dist/generated/schemas/standalone/StrategyRun.json +14 -71
- package/dist/generated/types/standalone/Resource_Genesis.d.ts +1 -1
- package/dist/generated/types/standalone/Resource_Job.d.ts +1 -1
- package/dist/generated/types/standalone/Resource_RawStrategy.d.ts +1 -1
- package/dist/generated/types/standalone/Resource_ResourceType.d.ts +1 -1
- package/dist/generated/types/standalone/Resource_RunnableStrategy.d.ts +1 -1
- package/dist/generated/types/types.d.ts +119 -1126
- package/dist/index.d.ts +1 -4
- package/dist/index.js +0 -2
- package/dist/scripts/_lib/config.d.ts +6 -6
- package/dist/scripts/_lib/config.js +10 -12
- package/dist/scripts/extractSchemasFromResourceTypeShells.js +109 -103
- package/dist/scripts/generateDependencies.js +15 -14
- package/dist/scripts/generateSchemaShims.js +77 -85
- package/dist/scripts/generateStandaloneSchema.js +47 -37
- package/dist/scripts/generateStandaloneType.js +85 -79
- package/dist/scripts/generateTypes.js +350 -470
- package/dist/scripts/normalizeAnchorsToPointers.d.ts +1 -1
- package/dist/scripts/normalizeAnchorsToPointers.js +61 -33
- package/dist/scripts/wrapResourceTypesWithResourceShells.js +14 -16
- package/package.json +7 -8
- package/src/Genesis.json +1837 -1999
- package/src/generated/{dependencyMap.json → dependencies/dependencyMap.json} +9 -19
- package/src/generated/normalized/Genesis.json +16 -265
- package/src/generated/resources/Genesis.json +18 -305
- package/src/generated/schemas/Genesis.json +14 -152
- package/src/generated/schemas/standalone/Goal.json +0 -33
- package/src/generated/schemas/standalone/Job.json +0 -42
- package/src/generated/schemas/standalone/RawStrategy.json +14 -52
- package/src/generated/schemas/standalone/ResourceType.json +0 -34
- package/src/generated/schemas/standalone/RunnableStrategy.json +14 -57
- package/src/generated/schemas/standalone/StrategyRun.json +14 -71
- package/src/generated/types/standalone/Resource_Genesis.d.ts +1 -1
- package/src/generated/types/standalone/Resource_Job.d.ts +1 -1
- package/src/generated/types/standalone/Resource_RawStrategy.d.ts +1 -1
- package/src/generated/types/standalone/Resource_ResourceType.d.ts +1 -1
- package/src/generated/types/standalone/Resource_RunnableStrategy.d.ts +1 -1
- package/src/generated/types/types.d.ts +119 -1126
- package/src/index.ts +66 -93
- package/src/scripts/_lib/config.ts +203 -205
- package/src/scripts/extractSchemasFromResourceTypeShells.ts +261 -218
- package/src/scripts/generateDependencies.ts +121 -120
- package/src/scripts/generateSchemaShims.ts +127 -135
- package/src/scripts/generateStandaloneSchema.ts +185 -175
- package/src/scripts/generateStandaloneType.ts +127 -119
- package/src/scripts/generateTypes.ts +532 -615
- package/src/scripts/normalizeAnchorsToPointers.ts +141 -123
- package/src/scripts/wrapResourceTypesWithResourceShells.ts +82 -84
- package/dist/generated/dependencyMap.json +0 -292
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function stripAnchors<T>(schema: T): T;
|
|
@@ -1,15 +1,39 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { getConfig } from './_lib/config.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
/*
|
|
5
|
+
* Rewrite anchor-style references to JSON Pointer references in Genesis.json.
|
|
6
|
+
* We also strip all $anchor fields from the output since they are no longer needed after rewriting refs.
|
|
7
|
+
*/
|
|
8
|
+
// PURE: Remove all `$anchor` keys from a schema tree without rewriting refs.
|
|
9
|
+
export function stripAnchors(schema) {
|
|
10
|
+
const seen = new WeakMap();
|
|
11
|
+
function walk(node) {
|
|
12
|
+
if (!node || typeof node !== 'object')
|
|
13
|
+
return node;
|
|
14
|
+
const existing = seen.get(node);
|
|
15
|
+
if (existing)
|
|
16
|
+
return existing;
|
|
17
|
+
if (Array.isArray(node)) {
|
|
18
|
+
const out = [];
|
|
19
|
+
seen.set(node, out);
|
|
20
|
+
for (const item of node)
|
|
21
|
+
out.push(walk(item));
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
const out = {};
|
|
25
|
+
seen.set(node, out);
|
|
26
|
+
for (const [key, value] of Object.entries(node)) {
|
|
27
|
+
if (key === '$anchor')
|
|
28
|
+
continue;
|
|
29
|
+
out[key] = walk(value);
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
return walk(schema);
|
|
34
|
+
}
|
|
35
|
+
// PURE: Rewrite anchor-style `$ref` strings (`#Anchor`) into JSON Pointer refs (`#/$defs/DefName`).
|
|
36
|
+
function normalizeAnchorsToPointers(input) {
|
|
13
37
|
if (!input || typeof input !== "object")
|
|
14
38
|
return input;
|
|
15
39
|
// Deep clone the input to ensure the function is pure (no side effects on input)
|
|
@@ -67,30 +91,34 @@ function normalizeAnchorsToPointersToPointers(input) {
|
|
|
67
91
|
walk(root);
|
|
68
92
|
return root;
|
|
69
93
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
94
|
+
// IMPURE: Script entrypoint (config + filesystem I/O + console + process exit code).
|
|
95
|
+
function main() {
|
|
96
|
+
try {
|
|
97
|
+
const config = getConfig();
|
|
98
|
+
const genesisSourcePath = config.getSourcePath();
|
|
99
|
+
// Create a generated/normalized version (anchor refs rewritten to pointers)
|
|
100
|
+
const normalizedPath = config.getNormalizedSourcePath();
|
|
101
|
+
if (!fs.existsSync(genesisSourcePath)) {
|
|
102
|
+
throw new Error(`Genesis source file not found at ${genesisSourcePath}`);
|
|
103
|
+
}
|
|
104
|
+
const raw = fs.readFileSync(genesisSourcePath, 'utf-8');
|
|
105
|
+
const genesis = JSON.parse(raw);
|
|
106
|
+
// Validate structure
|
|
107
|
+
if (!genesis.nucleusSchema || !genesis.nucleusSchema.$defs) {
|
|
108
|
+
throw new Error('Genesis.json must have nucleusSchema.$defs');
|
|
109
|
+
}
|
|
110
|
+
// Rewrite anchors in the nucleusSchema (pure function call)
|
|
111
|
+
genesis.nucleusSchema = normalizeAnchorsToPointers(genesis.nucleusSchema);
|
|
112
|
+
// Strip $anchor fields from the schemas (pure function call)
|
|
113
|
+
genesis.nucleusSchema = stripAnchors(genesis.nucleusSchema);
|
|
114
|
+
// Write normalized version
|
|
115
|
+
fs.mkdirSync(path.dirname(normalizedPath), { recursive: true });
|
|
116
|
+
fs.writeFileSync(normalizedPath, JSON.stringify(genesis, null, 4), 'utf-8');
|
|
117
|
+
console.log(`Wrote normalized Genesis with pointer refs to ${normalizedPath}`);
|
|
78
118
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (!genesis.nucleusSchema || !genesis.nucleusSchema.$defs) {
|
|
83
|
-
console.error('Genesis.json must have nucleusSchema.$defs');
|
|
84
|
-
process.exit(1);
|
|
119
|
+
catch (e) {
|
|
120
|
+
console.error(e);
|
|
121
|
+
process.exitCode = 1;
|
|
85
122
|
}
|
|
86
|
-
// Rewrite anchors in the nucleusSchema (pure function call)
|
|
87
|
-
genesis.nucleusSchema = normalizeAnchorsToPointersToPointers(genesis.nucleusSchema);
|
|
88
|
-
// Write normalized version
|
|
89
|
-
fs.mkdirSync(path.dirname(normalizedPath), { recursive: true });
|
|
90
|
-
fs.writeFileSync(normalizedPath, JSON.stringify(genesis, null, 4), 'utf-8');
|
|
91
|
-
console.log(`Wrote normalized Genesis with pointer refs to ${normalizedPath}`);
|
|
92
123
|
}
|
|
93
|
-
main()
|
|
94
|
-
console.error(e);
|
|
95
|
-
process.exit(1);
|
|
96
|
-
});
|
|
124
|
+
main();
|
|
@@ -5,6 +5,7 @@ import { getConfig } from './_lib/config.js';
|
|
|
5
5
|
* Wrap each ResourceType definition (from Genesis.nucleusSchema.$defs) with a Resource shell
|
|
6
6
|
* that conforms to the Resource.nucleusSchema pattern defined in Genesis.json.
|
|
7
7
|
*/
|
|
8
|
+
// PURE: Build Resource shell envelopes for each $defs entry (no I/O, no mutation of inputs).
|
|
8
9
|
function generateResourceShellLogic(genesis) {
|
|
9
10
|
if (!genesis.nucleusSchema || !genesis.nucleusSchema.$defs) {
|
|
10
11
|
throw new Error('Genesis.json must have nucleusSchema.$defs');
|
|
@@ -41,17 +42,17 @@ function generateResourceShellLogic(genesis) {
|
|
|
41
42
|
});
|
|
42
43
|
return resources;
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const genesisSourcePath = config.getNormalizedSourcePath();
|
|
47
|
-
const outputPath = path.join(config.getResourcesDir(), 'Genesis.json');
|
|
48
|
-
if (!fs.existsSync(genesisSourcePath)) {
|
|
49
|
-
console.error(`Genesis source file not found at ${genesisSourcePath}`);
|
|
50
|
-
process.exit(1);
|
|
51
|
-
}
|
|
52
|
-
const raw = fs.readFileSync(genesisSourcePath, 'utf-8');
|
|
53
|
-
const genesis = JSON.parse(raw);
|
|
45
|
+
// IMPURE: Script entrypoint (config + filesystem I/O + console + process exit code).
|
|
46
|
+
function main() {
|
|
54
47
|
try {
|
|
48
|
+
const config = getConfig();
|
|
49
|
+
const genesisSourcePath = config.getNormalizedSourcePath();
|
|
50
|
+
const outputPath = path.join(config.getResourcesDir(), 'Genesis.json');
|
|
51
|
+
if (!fs.existsSync(genesisSourcePath)) {
|
|
52
|
+
throw new Error(`Genesis source file not found at ${genesisSourcePath}`);
|
|
53
|
+
}
|
|
54
|
+
const raw = fs.readFileSync(genesisSourcePath, 'utf-8');
|
|
55
|
+
const genesis = JSON.parse(raw);
|
|
55
56
|
const resources = generateResourceShellLogic(genesis);
|
|
56
57
|
const outputDir = path.dirname(outputPath);
|
|
57
58
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
@@ -59,11 +60,8 @@ async function main() {
|
|
|
59
60
|
console.log(`Generated ${Object.keys(resources).length} Resource envelopes -> ${outputPath}`);
|
|
60
61
|
}
|
|
61
62
|
catch (error) {
|
|
62
|
-
console.error(error
|
|
63
|
-
process.
|
|
63
|
+
console.error(error?.message ?? error);
|
|
64
|
+
process.exitCode = 1;
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
|
-
main()
|
|
67
|
-
console.error(e);
|
|
68
|
-
process.exit(1);
|
|
69
|
-
});
|
|
67
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toolproof-core/schema",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "JSON schemas and TypeScript types for ToolProof",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,10 +18,15 @@
|
|
|
18
18
|
"keywords": [],
|
|
19
19
|
"author": "",
|
|
20
20
|
"license": "ISC",
|
|
21
|
-
"packageManager": "pnpm@10.15.0",
|
|
22
21
|
"publishConfig": {
|
|
23
22
|
"access": "public"
|
|
24
23
|
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^20.8.1",
|
|
26
|
+
"json-schema-to-typescript": "^15.0.4",
|
|
27
|
+
"rimraf": "^5.0.0",
|
|
28
|
+
"typescript": "^5.9.3"
|
|
29
|
+
},
|
|
25
30
|
"scripts": {
|
|
26
31
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
27
32
|
"build": "tsc -b",
|
|
@@ -36,11 +41,5 @@
|
|
|
36
41
|
"generateDependencies": "node ./dist/scripts/generateDependencies.js",
|
|
37
42
|
"generateResourceTypeGenesisType": "node ./dist/scripts/generateStandaloneType.js --name Genesis",
|
|
38
43
|
"update": "rimraf /s /q dist && pnpm run build:scripts && pnpm run normalizeAnchorsToPointers && pnpm run extractSchemasFromResourceTypeShells && pnpm run generateStandaloneSchema -- --name Job && pnpm run generateStandaloneSchema -- --name ResourceType && pnpm run generateStandaloneSchema -- --name RawStrategy && pnpm run generateStandaloneSchema -- --name RunnableStrategy && pnpm run generateStandaloneSchema -- --name StrategyRun && pnpm run generateStandaloneSchema -- --name Goal && pnpm run wrapResourceTypesWithResourceShells && pnpm run generateSchemaShims && pnpm run generateTypes && pnpm run generateStandaloneType -- --name Job && pnpm run generateStandaloneType -- --name ResourceType && pnpm run generateStandaloneType -- --name RawStrategy && pnpm run generateStandaloneType -- --name RunnableStrategy && pnpm run generateResourceTypeGenesisType && pnpm run generateDependencies && pnpm run build"
|
|
39
|
-
},
|
|
40
|
-
"devDependencies": {
|
|
41
|
-
"@types/node": "^20.8.1",
|
|
42
|
-
"json-schema-to-typescript": "^15.0.4",
|
|
43
|
-
"rimraf": "^5.0.0",
|
|
44
|
-
"typescript": "^5.9.3"
|
|
45
44
|
}
|
|
46
45
|
}
|