@toolproof-core/schema 1.0.0 → 1.0.2
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/types/standalone/Resource_Genesis.d.ts +3 -0
- package/dist/generated/types/standalone/Resource_Job.d.ts +3 -0
- package/dist/generated/types/standalone/Resource_RawStrategy.d.ts +3 -0
- package/dist/generated/types/standalone/Resource_ResourceType.d.ts +3 -0
- package/dist/generated/types/standalone/Resource_RunnableStrategy.d.ts +3 -0
- package/dist/generated/types/types.d.ts +487 -548
- package/dist/scripts/_lib/config.d.ts +12 -6
- package/dist/scripts/_lib/config.js +33 -15
- package/dist/scripts/{extractSchemas.js → extractSchemasFromResourceTypeShells.js} +14 -27
- package/dist/scripts/generateDependencies.js +2 -2
- package/dist/scripts/generateSchemaShims.js +22 -4
- package/dist/scripts/{extractSubSchemaWithDefs.js → generateStandaloneSchema.js} +12 -34
- package/dist/scripts/{generateResourceTypeType.js → generateStandaloneType.js} +23 -14
- package/dist/scripts/generateTypes.js +1 -1
- package/dist/scripts/{rewriteAnchors.js → normalizeAnchorsToPointers.js} +2 -2
- package/dist/scripts/{generateResourceShells.js → wrapResourceTypesWithResourceShells.js} +12 -34
- package/package.json +15 -14
- package/src/Genesis.json +1999 -2042
- package/src/generated/{dependencies.json → dependencyMap.json} +207 -214
- package/src/generated/{resourceTypes → normalized}/Genesis.json +44 -87
- package/src/generated/resources/Genesis.json +415 -478
- package/src/generated/schemas/Genesis.json +1026 -1057
- package/src/generated/schemas/{Goal.json → standalone/Goal.json} +34 -34
- package/src/generated/schemas/{Job.json → standalone/Job.json} +85 -85
- package/src/generated/schemas/{RawStrategy.json → standalone/RawStrategy.json} +238 -263
- package/src/generated/schemas/{ResourceType.json → standalone/ResourceType.json} +60 -60
- package/src/generated/schemas/{RunnableStrategy.json → standalone/RunnableStrategy.json} +296 -321
- package/src/generated/schemas/{StrategyRun.json → standalone/StrategyRun.json} +390 -421
- package/src/generated/types/standalone/Resource_Genesis.d.ts +3 -0
- package/src/generated/types/standalone/Resource_Genesis.js +1 -0
- package/src/generated/types/standalone/Resource_Job.d.ts +3 -0
- package/src/generated/types/standalone/Resource_Job.js +1 -0
- package/src/generated/types/standalone/Resource_RawStrategy.d.ts +3 -0
- package/src/generated/types/standalone/Resource_RawStrategy.js +1 -0
- package/src/generated/types/standalone/Resource_ResourceType.d.ts +3 -0
- package/src/generated/types/standalone/Resource_ResourceType.js +1 -0
- package/src/generated/types/standalone/Resource_RunnableStrategy.d.ts +3 -0
- package/src/generated/types/standalone/Resource_RunnableStrategy.js +1 -0
- package/src/generated/types/types.d.ts +487 -548
- package/src/generated/types/types.js +1 -1
- package/src/scripts/_lib/config.ts +205 -181
- package/src/scripts/extractSchemasFromResourceTypeShells.ts +218 -0
- package/src/scripts/generateDependencies.ts +120 -120
- package/src/scripts/generateSchemaShims.ts +135 -115
- package/src/scripts/{extractSubSchemaWithDefs.ts → generateStandaloneSchema.ts} +175 -196
- package/src/scripts/{generateResourceTypeType.ts → generateStandaloneType.ts} +119 -110
- package/src/scripts/generateTypes.ts +614 -614
- package/src/scripts/{rewriteAnchors.ts → normalizeAnchorsToPointers.ts} +123 -123
- package/src/scripts/{generateResourceShells.ts → wrapResourceTypesWithResourceShells.ts} +84 -105
- package/dist/generated/types/Resource_Genesis.d.ts +0 -3
- package/dist/generated/types/Resource_Job.d.ts +0 -3
- package/dist/generated/types/Resource_RawStrategy.d.ts +0 -3
- package/dist/generated/types/Resource_ResourceType.d.ts +0 -3
- package/dist/generated/types/Resource_RunnableStrategy.d.ts +0 -3
- package/src/Roadmap.json +0 -102
- package/src/generated/types/Resource_Genesis.d.ts +0 -3
- package/src/generated/types/Resource_Genesis.js +0 -1
- package/src/generated/types/Resource_Job.d.ts +0 -3
- package/src/generated/types/Resource_Job.js +0 -1
- package/src/generated/types/Resource_RawStrategy.d.ts +0 -3
- package/src/generated/types/Resource_RawStrategy.js +0 -1
- package/src/generated/types/Resource_ResourceType.d.ts +0 -3
- package/src/generated/types/Resource_ResourceType.js +0 -1
- package/src/generated/types/Resource_RunnableStrategy.d.ts +0 -3
- package/src/generated/types/Resource_RunnableStrategy.js +0 -1
- package/src/scripts/extractSchemas.ts +0 -229
- /package/dist/generated/types/{Resource_Genesis.js → standalone/Resource_Genesis.js} +0 -0
- /package/dist/generated/types/{Resource_Job.js → standalone/Resource_Job.js} +0 -0
- /package/dist/generated/types/{Resource_RawStrategy.js → standalone/Resource_RawStrategy.js} +0 -0
- /package/dist/generated/types/{Resource_ResourceType.js → standalone/Resource_ResourceType.js} +0 -0
- /package/dist/generated/types/{Resource_RunnableStrategy.js → standalone/Resource_RunnableStrategy.js} +0 -0
- /package/dist/scripts/{extractSchemas.d.ts → extractSchemasFromResourceTypeShells.d.ts} +0 -0
- /package/dist/scripts/{extractSubSchemaWithDefs.d.ts → generateStandaloneSchema.d.ts} +0 -0
- /package/dist/scripts/{generateResourceShells.d.ts → generateStandaloneType.d.ts} +0 -0
- /package/dist/scripts/{generateResourceTypeType.d.ts → normalizeAnchorsToPointers.d.ts} +0 -0
- /package/dist/scripts/{rewriteAnchors.d.ts → wrapResourceTypesWithResourceShells.d.ts} +0 -0
- /package/src/generated/{resourceTypes → normalized}/Genesis.ts +0 -0
- /package/src/generated/schemas/{Goal.ts → standalone/Goal.ts} +0 -0
- /package/src/generated/schemas/{Job.ts → standalone/Job.ts} +0 -0
- /package/src/generated/schemas/{RawStrategy.ts → standalone/RawStrategy.ts} +0 -0
- /package/src/generated/schemas/{ResourceType.ts → standalone/ResourceType.ts} +0 -0
- /package/src/generated/schemas/{RunnableStrategy.ts → standalone/RunnableStrategy.ts} +0 -0
- /package/src/generated/schemas/{StrategyRun.ts → standalone/StrategyRun.ts} +0 -0
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
4
|
-
import { getConfig } from "./_lib/config.js";
|
|
5
|
-
|
|
6
|
-
type JSONValue = null | boolean | number | string | JSONValue[] | { [k: string]: JSONValue };
|
|
7
|
-
|
|
8
|
-
interface ExtractOptions {
|
|
9
|
-
inPath: string;
|
|
10
|
-
outPath: string;
|
|
11
|
-
topLevelId?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function parseArgs(): ExtractOptions {
|
|
15
|
-
const config = getConfig();
|
|
16
|
-
const argv = process.argv.slice(2);
|
|
17
|
-
let inPath = "";
|
|
18
|
-
let outPath = "";
|
|
19
|
-
let topLevelId: string | undefined;
|
|
20
|
-
for (let i = 0; i < argv.length; i++) {
|
|
21
|
-
const a = argv[i];
|
|
22
|
-
if (a === "--in" && i + 1 < argv.length) inPath = argv[++i];
|
|
23
|
-
else if (a === "--out" && i + 1 < argv.length) outPath = argv[++i];
|
|
24
|
-
else if (a === "--id" && i + 1 < argv.length) {
|
|
25
|
-
let v = argv[++i];
|
|
26
|
-
// Strip accidental surrounding quotes from PowerShell/cmd
|
|
27
|
-
if ((v.startsWith("'") && v.endsWith("'")) || (v.startsWith('"') && v.endsWith('"'))) {
|
|
28
|
-
v = v.slice(1, -1);
|
|
29
|
-
}
|
|
30
|
-
topLevelId = v;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Use config defaults if not provided via CLI
|
|
35
|
-
if (!inPath) {
|
|
36
|
-
// Use generated/normalized version with anchor refs rewritten to pointers
|
|
37
|
-
inPath = config.getNormalizedSourcePath();
|
|
38
|
-
}
|
|
39
|
-
if (!outPath) {
|
|
40
|
-
outPath = config.getOutputPath(config.getSourceFile());
|
|
41
|
-
}
|
|
42
|
-
if (!topLevelId) {
|
|
43
|
-
topLevelId = config.getSchemaId('Genesis');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Resolve to absolute paths from project root
|
|
47
|
-
const cwd = config.getRoot();
|
|
48
|
-
const wasInRelative = !path.isAbsolute(inPath);
|
|
49
|
-
const wasOutRelative = !path.isAbsolute(outPath);
|
|
50
|
-
if (wasInRelative) inPath = path.join(cwd, inPath);
|
|
51
|
-
if (wasOutRelative) outPath = path.join(cwd, outPath);
|
|
52
|
-
// Fallback: resolve relative to script directory if not found
|
|
53
|
-
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
|
|
54
|
-
if (!fs.existsSync(inPath) && wasInRelative) inPath = path.resolve(scriptDir, inPath);
|
|
55
|
-
const outDir = path.dirname(outPath);
|
|
56
|
-
if (!fs.existsSync(outDir) && wasOutRelative) {
|
|
57
|
-
// Try making directory relative to script dir
|
|
58
|
-
const altOut = path.resolve(scriptDir, outPath);
|
|
59
|
-
const altOutDir = path.dirname(altOut);
|
|
60
|
-
if (!fs.existsSync(path.dirname(outPath))) {
|
|
61
|
-
// Prefer creating outDir at cwd location if possible; otherwise fallback below when writing
|
|
62
|
-
} else {
|
|
63
|
-
outPath = altOut;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return { inPath, outPath, topLevelId };
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Heuristic: determine if a node is a Type envelope
|
|
70
|
-
function isTypeEnvelope(node: any): boolean {
|
|
71
|
-
return (
|
|
72
|
-
node && typeof node === "object" && !Array.isArray(node) &&
|
|
73
|
-
// Treat any object that has an 'nucleusSchema' AND 'identity' as a Type envelope
|
|
74
|
-
// This prevents false positives where 'nucleusSchema' is just a regular schema property
|
|
75
|
-
node.nucleusSchema && typeof node.nucleusSchema === "object" &&
|
|
76
|
-
node.identity && typeof node.identity === "string"
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Merge $defs into target, without overwriting existing keys unless identical
|
|
81
|
-
function mergeDefs(target: Record<string, JSONValue>, source?: any, label?: string) {
|
|
82
|
-
if (!source || typeof source !== "object") return;
|
|
83
|
-
const src = (source as any)["$defs"];
|
|
84
|
-
if (!src || typeof src !== "object") return;
|
|
85
|
-
for (const [k, v] of Object.entries(src)) {
|
|
86
|
-
if (!(k in target)) {
|
|
87
|
-
target[k] = v as JSONValue;
|
|
88
|
-
} else {
|
|
89
|
-
// Best-effort: if duplicate key, require structural equality; otherwise, namespace
|
|
90
|
-
const existing = JSON.stringify(target[k]);
|
|
91
|
-
const incoming = JSON.stringify(v);
|
|
92
|
-
if (existing !== incoming) {
|
|
93
|
-
const altKey = `${k}__from_${(label || "defs").replace(/[^A-Za-z0-9_]+/g, "_")}`;
|
|
94
|
-
if (!(altKey in target)) target[altKey] = v as JSONValue;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Deeply traverse an object replacing any Type envelope with its nucleusSchema,
|
|
101
|
-
// and hoist its inner $defs to topDefs. Prevent infinite recursion with a visited set.
|
|
102
|
-
function unwrapTypes(node: JSONValue, topDefs: Record<string, JSONValue>, labelPath: string[] = [], visited = new Set<any>()): JSONValue {
|
|
103
|
-
if (node && typeof node === "object") {
|
|
104
|
-
if (visited.has(node)) return node; // avoid cycles
|
|
105
|
-
visited.add(node);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (isTypeEnvelope(node)) {
|
|
109
|
-
const env = node as any;
|
|
110
|
-
const inner = env.nucleusSchema;
|
|
111
|
-
// Hoist inner $defs before stripping
|
|
112
|
-
mergeDefs(topDefs, inner, labelPath.join("_"));
|
|
113
|
-
// Return the inner schema itself, after also unwrapping any nested envelopes it may contain
|
|
114
|
-
const unwrappedInner = unwrapTypes(inner as JSONValue, topDefs, labelPath.concat([String(env.identity || "env")]), visited);
|
|
115
|
-
return unwrappedInner;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (Array.isArray(node)) {
|
|
119
|
-
return node.map((v, i) => unwrapTypes(v, topDefs, labelPath.concat([String(i)]), visited)) as JSONValue;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (node && typeof node === "object") {
|
|
123
|
-
const out: Record<string, JSONValue> = {};
|
|
124
|
-
for (const [k, v] of Object.entries(node)) {
|
|
125
|
-
if (k === "$defs" && v && typeof v === "object" && !Array.isArray(v)) {
|
|
126
|
-
// Process nested $defs: unwrap each entry value if it's a Type envelope
|
|
127
|
-
const defsOut: Record<string, JSONValue> = {};
|
|
128
|
-
for (const [dk, dv] of Object.entries(v as any)) {
|
|
129
|
-
const unwrapped = unwrapTypes(dv as JSONValue, topDefs, labelPath.concat(["$defs", dk]), visited);
|
|
130
|
-
defsOut[dk] = unwrapped;
|
|
131
|
-
}
|
|
132
|
-
out[k] = defsOut;
|
|
133
|
-
} else {
|
|
134
|
-
out[k] = unwrapTypes(v as JSONValue, topDefs, labelPath.concat([k]), visited);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return out;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return node;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Pure function that takes a schema document and options, and returns the flattened schema.
|
|
145
|
-
* Performs no I/O operations.
|
|
146
|
-
*/
|
|
147
|
-
function extractSchemaLogic(doc: any, topLevelId?: string): any {
|
|
148
|
-
if (!doc || typeof doc !== "object" || !doc.nucleusSchema) {
|
|
149
|
-
throw new Error("Input must be a Type JSON with an nucleusSchema at the top level");
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const topSchema = (doc as any).nucleusSchema;
|
|
153
|
-
const outDefs: Record<string, JSONValue> = {};
|
|
154
|
-
|
|
155
|
-
// Seed with top-level $defs (if any) before unwrapping
|
|
156
|
-
mergeDefs(outDefs, topSchema, "top");
|
|
157
|
-
|
|
158
|
-
// Unwrap the entire top schema tree so that any nested Type envelopes become raw schemas
|
|
159
|
-
const flattened = unwrapTypes(topSchema as JSONValue, outDefs, ["nucleusSchema"]);
|
|
160
|
-
|
|
161
|
-
// Assemble output: force $schema, optionally set $id, hoist collected $defs
|
|
162
|
-
let base: any;
|
|
163
|
-
if (flattened && typeof flattened === "object" && !Array.isArray(flattened)) {
|
|
164
|
-
base = { ...(flattened as any) };
|
|
165
|
-
} else {
|
|
166
|
-
// If flattened is not an object (should be rare for a top-level schema), wrap it
|
|
167
|
-
base = { const: flattened };
|
|
168
|
-
}
|
|
169
|
-
// Assemble, but avoid duplicating $id: if the flattened base already has $id, prefer it.
|
|
170
|
-
const output: Record<string, JSONValue> = {
|
|
171
|
-
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
172
|
-
...base,
|
|
173
|
-
};
|
|
174
|
-
if (topLevelId && !(output as any).$id) {
|
|
175
|
-
(output as any).$id = topLevelId;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Enforce presence of $id: schema must declare an absolute identity.
|
|
179
|
-
if (!(output as any).$id) {
|
|
180
|
-
throw new Error(
|
|
181
|
-
"Flattened schema must define $id. Provide it via CLI --id or include $id in the source nucleusSchema."
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Merge collected defs into output.$defs, taking care not to clobber any existing
|
|
186
|
-
if (!("$defs" in output)) output.$defs = {} as any;
|
|
187
|
-
const finalDefs: Record<string, JSONValue> = (output.$defs as any) || {};
|
|
188
|
-
for (const [k, v] of Object.entries(outDefs)) {
|
|
189
|
-
if (!(k in finalDefs)) finalDefs[k] = v;
|
|
190
|
-
}
|
|
191
|
-
output.$defs = finalDefs as any;
|
|
192
|
-
|
|
193
|
-
// Ensure a stable order for readability
|
|
194
|
-
return orderKeys(output, ["$id", "$schema", "$vocabulary", "$defs", "title", "description", "type", "allOf", "anyOf", "oneOf", "not", "if", "then", "else", "properties", "required", "additionalProperties", "unevaluatedProperties"]);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function main() {
|
|
198
|
-
const { inPath, outPath, topLevelId } = parseArgs();
|
|
199
|
-
|
|
200
|
-
if (!fs.existsSync(inPath)) {
|
|
201
|
-
console.error(`Input file not found at ${inPath}`);
|
|
202
|
-
process.exit(1);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const raw = fs.readFileSync(inPath, "utf8");
|
|
206
|
-
const doc = JSON.parse(raw);
|
|
207
|
-
|
|
208
|
-
// Core logic is now in a pure function
|
|
209
|
-
const ordered = extractSchemaLogic(doc, topLevelId);
|
|
210
|
-
|
|
211
|
-
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
212
|
-
fs.writeFileSync(outPath, JSON.stringify(ordered, null, 4), "utf8");
|
|
213
|
-
console.log(`Wrote flattened schema to ${outPath}`);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function orderKeys(obj: any, preferred: string[]): any {
|
|
217
|
-
if (Array.isArray(obj)) return obj.map((v) => orderKeys(v, preferred));
|
|
218
|
-
if (!obj || typeof obj !== "object") return obj;
|
|
219
|
-
const keys = Object.keys(obj);
|
|
220
|
-
const sorted = [
|
|
221
|
-
...preferred.filter((k) => keys.includes(k)),
|
|
222
|
-
...keys.filter((k) => !preferred.includes(k)).sort()
|
|
223
|
-
];
|
|
224
|
-
const out: any = {};
|
|
225
|
-
for (const k of sorted) out[k] = orderKeys(obj[k], preferred);
|
|
226
|
-
return out;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
main();
|
|
File without changes
|
|
File without changes
|
/package/dist/generated/types/{Resource_RawStrategy.js → standalone/Resource_RawStrategy.js}
RENAMED
|
File without changes
|
/package/dist/generated/types/{Resource_ResourceType.js → standalone/Resource_ResourceType.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|