@toolproof-npm/schema 0.1.49 → 0.1.52
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/genesis/generated/resource-envelopes/Genesis.d.ts +2 -0
- package/dist/genesis/generated/resource-envelopes/Genesis.js +2 -0
- package/dist/genesis/generated/resource-envelopes/Genesis.json +2337 -0
- package/dist/genesis/{resourceTypes → generated/resource-type-envelopes}/Genesis.json +223 -255
- package/dist/genesis/generated/resourceTypes/Genesis.d.ts +2 -0
- package/dist/genesis/generated/resourceTypes/Genesis.js +2 -0
- package/dist/genesis/generated/resourceTypes/Genesis.json +1757 -0
- package/dist/genesis/generated/resources/Genesis.json +157 -189
- package/dist/genesis/generated/schemas/Genesis.json +149 -181
- package/dist/genesis/generated/schemas/Job.json +20 -22
- package/dist/genesis/generated/schemas/ResourceFormat.json +14 -16
- package/dist/genesis/generated/schemas/ResourceType.json +28 -30
- package/dist/genesis/generated/schemas/StatefulStrategy.json +225 -251
- package/dist/genesis/generated/schemas/StatelessStrategy.json +103 -123
- package/dist/genesis/generated/types/types.d.ts +174 -86
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/scripts/_lib/config.d.ts +4 -0
- package/dist/scripts/_lib/config.js +18 -1
- package/dist/scripts/extractSchemas.js +2 -2
- package/dist/scripts/generateResourceEnvelopes.js +1 -1
- package/dist/scripts/generateSchemaShims.js +21 -0
- package/dist/scripts/generateTypes.js +58 -0
- package/dist/scripts/rewriteAnchors.js +4 -2
- package/package.json +1 -1
- /package/dist/genesis/{resourceTypes → generated/resource-type-envelopes}/Genesis.d.ts +0 -0
- /package/dist/genesis/{resourceTypes → generated/resource-type-envelopes}/Genesis.js +0 -0
|
@@ -220,8 +220,66 @@ async function main() {
|
|
|
220
220
|
for (const [k, v] of Object.entries(node))
|
|
221
221
|
normalizeArrays(v, k);
|
|
222
222
|
}
|
|
223
|
+
// json-schema-to-typescript has a long-standing quirk:
|
|
224
|
+
// when a schema uses `allOf`, sibling object keywords like `properties`/`required`
|
|
225
|
+
// can be ignored in the emitted TS (it treats `allOf` as the whole schema).
|
|
226
|
+
//
|
|
227
|
+
// Example (Genesis $defs/Job):
|
|
228
|
+
// { type: 'object', allOf: [Documented, RolesWrapper], properties: { identity: ... }, required: [...] }
|
|
229
|
+
// can become:
|
|
230
|
+
// type Job = Documented & RolesWrapper
|
|
231
|
+
//
|
|
232
|
+
// To avoid cluttering the source JSON schemas, we normalize to a temp file:
|
|
233
|
+
// move those sibling object keywords into an extra `allOf` item.
|
|
234
|
+
function normalizeAllOfSiblingObjectKeywords(node) {
|
|
235
|
+
if (Array.isArray(node)) {
|
|
236
|
+
for (const item of node)
|
|
237
|
+
normalizeAllOfSiblingObjectKeywords(item);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (!node || typeof node !== 'object')
|
|
241
|
+
return;
|
|
242
|
+
const hasAllOf = Array.isArray(node.allOf) && node.allOf.length > 0;
|
|
243
|
+
const looksLikeObjectSchema = node.type === 'object' ||
|
|
244
|
+
node.properties !== undefined ||
|
|
245
|
+
node.required !== undefined ||
|
|
246
|
+
node.unevaluatedProperties !== undefined ||
|
|
247
|
+
node.additionalProperties !== undefined;
|
|
248
|
+
if (hasAllOf && looksLikeObjectSchema) {
|
|
249
|
+
const siblingKeys = [
|
|
250
|
+
'properties',
|
|
251
|
+
'required',
|
|
252
|
+
'additionalProperties',
|
|
253
|
+
'unevaluatedProperties',
|
|
254
|
+
'propertyNames',
|
|
255
|
+
'patternProperties',
|
|
256
|
+
'dependentRequired',
|
|
257
|
+
'dependentSchemas',
|
|
258
|
+
'minProperties',
|
|
259
|
+
'maxProperties'
|
|
260
|
+
];
|
|
261
|
+
const hasSiblingObjectKeywords = siblingKeys.some((k) => k in node);
|
|
262
|
+
if (hasSiblingObjectKeywords) {
|
|
263
|
+
const overlay = {};
|
|
264
|
+
if (node.type === 'object')
|
|
265
|
+
overlay.type = 'object';
|
|
266
|
+
for (const k of siblingKeys) {
|
|
267
|
+
if (k in node) {
|
|
268
|
+
overlay[k] = node[k];
|
|
269
|
+
delete node[k];
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
// Prepend so it participates in the intersection early.
|
|
273
|
+
node.allOf = [overlay, ...node.allOf];
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
for (const v of Object.values(node))
|
|
277
|
+
normalizeAllOfSiblingObjectKeywords(v);
|
|
278
|
+
}
|
|
223
279
|
// Normalize expected arrays to prevent traversal crashes
|
|
224
280
|
normalizeArrays(parsedSchema);
|
|
281
|
+
// Normalize `allOf` + sibling object keywords so the TS generator doesn't drop them.
|
|
282
|
+
normalizeAllOfSiblingObjectKeywords(parsedSchema);
|
|
225
283
|
const tmpPath = path.join(inputDir, `.normalized.${path.basename(fileName)}`);
|
|
226
284
|
fs.writeFileSync(tmpPath, JSON.stringify(parsedSchema, null, 2), 'utf8');
|
|
227
285
|
toCompilePath = tmpPath;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
2
3
|
import { getConfig } from './_lib/config.js';
|
|
3
4
|
/**
|
|
4
5
|
* Rewrite anchor-style references to JSON Pointer references
|
|
@@ -65,8 +66,8 @@ function rewriteAnchorsToPointers(root) {
|
|
|
65
66
|
async function main() {
|
|
66
67
|
const config = getConfig();
|
|
67
68
|
const genesisSourcePath = config.getSourcePath();
|
|
68
|
-
// Create a
|
|
69
|
-
const normalizedPath =
|
|
69
|
+
// Create a generated/normalized version (anchor refs rewritten to pointers)
|
|
70
|
+
const normalizedPath = config.getNormalizedSourcePath();
|
|
70
71
|
if (!fs.existsSync(genesisSourcePath)) {
|
|
71
72
|
console.error(`Genesis source file not found at ${genesisSourcePath}`);
|
|
72
73
|
process.exit(1);
|
|
@@ -81,6 +82,7 @@ async function main() {
|
|
|
81
82
|
// Rewrite anchors in the extractionSchema (where $defs is at the top level)
|
|
82
83
|
rewriteAnchorsToPointers(genesis.extractionSchema);
|
|
83
84
|
// Write normalized version
|
|
85
|
+
fs.mkdirSync(path.dirname(normalizedPath), { recursive: true });
|
|
84
86
|
fs.writeFileSync(normalizedPath, JSON.stringify(genesis, null, 4), 'utf-8');
|
|
85
87
|
console.log(`Wrote normalized Genesis with pointer refs to ${normalizedPath}`);
|
|
86
88
|
}
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|