@toolproof-core/schema 1.0.10 → 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.
- package/dist/generated/artifacts/constants.d.ts +4 -3
- package/dist/generated/artifacts/constants.js +4 -3
- package/dist/generated/normalized/Genesis.json +50 -25
- package/dist/generated/resources/Genesis.json +68 -31
- package/dist/generated/schemas/Genesis.json +38 -19
- package/dist/generated/schemas/standalone/Job.json +7 -8
- package/dist/generated/schemas/standalone/ResourceType.json +4 -4
- package/dist/generated/schemas/standalone/RunnableStrategy.json +7 -7
- package/dist/generated/schemas/standalone/StrategyRun.json +7 -7
- 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 +229 -221
- package/dist/index.d.ts +1 -1
- package/dist/scripts/generateStandaloneType.js +2 -1
- package/dist/scripts/generateTypes.js +136 -3
- package/package.json +1 -1
- package/src/Genesis.json +54 -28
- package/src/generated/artifacts/constants.ts +122 -121
- package/src/generated/artifacts/dependencyMap.json +282 -278
- package/src/generated/artifacts/terminals.json +13 -12
- package/src/generated/normalized/Genesis.json +50 -25
- package/src/generated/resources/Genesis.json +68 -31
- package/src/generated/schemas/Genesis.json +38 -19
- package/src/generated/schemas/standalone/Job.json +195 -196
- package/src/generated/schemas/standalone/RawStrategy.json +580 -580
- package/src/generated/schemas/standalone/ResourceType.json +106 -106
- package/src/generated/schemas/standalone/RunnableStrategy.json +7 -7
- package/src/generated/schemas/standalone/StrategyRun.json +7 -7
- package/src/generated/types/standalone/Resource_Genesis.d.ts +3 -3
- package/src/generated/types/standalone/Resource_Job.d.ts +3 -3
- package/src/generated/types/standalone/Resource_RawStrategy.d.ts +3 -3
- package/src/generated/types/standalone/Resource_ResourceType.d.ts +3 -3
- package/src/generated/types/standalone/Resource_RunnableStrategy.d.ts +3 -3
- package/src/generated/types/types.d.ts +229 -221
- package/src/index.ts +47 -45
- package/src/scripts/generateStandaloneType.ts +3 -1
- package/src/scripts/generateTypes.ts +151 -5
package/src/index.ts
CHANGED
|
@@ -27,49 +27,51 @@ export type {
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
export type {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
30
|
+
DocumentationFacetJson,
|
|
31
|
+
NucleusFacetJson,
|
|
32
|
+
ResourceTypeIdentityJson,
|
|
33
|
+
ResourceTypeJson,
|
|
34
|
+
ResourceRoleIdentityJson,
|
|
35
|
+
ResourceRoleValueJson,
|
|
36
|
+
ResourceRoleJson,
|
|
37
|
+
ConditionalJson,
|
|
38
|
+
RoleDictJson,
|
|
39
|
+
RolesJson,
|
|
40
|
+
RoleBindingsJson,
|
|
41
|
+
ResourceIdentityJson,
|
|
42
|
+
JobStepIdentityJson,
|
|
43
|
+
BranchStepIdentityJson,
|
|
44
|
+
WhileStepIdentityJson,
|
|
45
|
+
ForStepIdentityJson,
|
|
46
|
+
JobStepJson,
|
|
47
|
+
BranchStepJson,
|
|
48
|
+
WhileStepJson,
|
|
49
|
+
ForStepJson,
|
|
50
|
+
StepKindJson,
|
|
51
|
+
StepIdentityJson,
|
|
52
|
+
StepJson,
|
|
53
|
+
CreationContextJson,
|
|
54
|
+
ResourceMissingJson,
|
|
55
|
+
ResourceInputPotentialJson,
|
|
56
|
+
ResourceOutputPotentialJson,
|
|
57
|
+
ShellMaterializedBaseJson,
|
|
58
|
+
ResourceJson,
|
|
59
|
+
StrategyStateJson,
|
|
60
|
+
StepsFacetJson,
|
|
61
|
+
RawStrategyJson,
|
|
62
|
+
RunnableStrategyIdentityJson,
|
|
63
|
+
RunnableStrategyStatusJson,
|
|
64
|
+
RunnableStrategyJson,
|
|
65
|
+
RunnableStrategyUpdateJson,
|
|
66
|
+
JobIdentityJson,
|
|
67
|
+
JobJson,
|
|
68
|
+
JsonDataJson,
|
|
69
|
+
StrategyThreadIdentityJson,
|
|
70
|
+
StrategyThreadDictJson,
|
|
71
|
+
JobStepSocketJson,
|
|
72
|
+
TimestampJson,
|
|
73
|
+
StrategyRunIdentityJson,
|
|
74
|
+
GoalIdentityJson,
|
|
75
|
+
GoalJson,
|
|
76
|
+
ErrorJson,
|
|
75
77
|
} from './generated/types/types.js';
|
|
@@ -11,8 +11,10 @@ import { getConfig } from "./_lib/config.js";
|
|
|
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
|
+
|
|
15
|
+
const nucleusTypeName = name.endsWith("Json") ? name : `${name}Json`;
|
|
14
16
|
const ts =
|
|
15
|
-
`import type { ShellMaterializedBase, ${
|
|
17
|
+
`import type { ShellMaterializedBaseJson as ShellMaterializedBase, ${nucleusTypeName} as NucleusSchema } from "../types.js";\n` +
|
|
16
18
|
`export type Resource_${name} = ShellMaterializedBase & { nucleus: NucleusSchema };\n`;
|
|
17
19
|
return header + ts;
|
|
18
20
|
}
|
|
@@ -260,6 +260,148 @@ function escapeRegExpLiteral(value: string): string {
|
|
|
260
260
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
+
// PURE: Rename exported top-level generated declarations to canonical `*Json` names.
|
|
264
|
+
// This makes editor hover/inference prefer `FooJson` because the underlying declared
|
|
265
|
+
// symbol is `FooJson` (not `Foo` with a re-export alias).
|
|
266
|
+
function applyReplacementsOutsideStringsAndComments(
|
|
267
|
+
text: string,
|
|
268
|
+
replaceCodeSegment: (code: string) => string,
|
|
269
|
+
): string {
|
|
270
|
+
const len = text.length;
|
|
271
|
+
let out = '';
|
|
272
|
+
|
|
273
|
+
let i = 0;
|
|
274
|
+
let codeStart = 0;
|
|
275
|
+
|
|
276
|
+
const flushCode = (end: number) => {
|
|
277
|
+
if (end > codeStart) out += replaceCodeSegment(text.slice(codeStart, end));
|
|
278
|
+
codeStart = end;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const startsWith = (s: string) => text.startsWith(s, i);
|
|
282
|
+
|
|
283
|
+
while (i < len) {
|
|
284
|
+
// Line comment
|
|
285
|
+
if (startsWith('//')) {
|
|
286
|
+
flushCode(i);
|
|
287
|
+
const start = i;
|
|
288
|
+
i += 2;
|
|
289
|
+
while (i < len && text[i] !== '\n') i++;
|
|
290
|
+
if (i < len && text[i] === '\n') i++;
|
|
291
|
+
out += text.slice(start, i);
|
|
292
|
+
codeStart = i;
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Block comment
|
|
297
|
+
if (startsWith('/*')) {
|
|
298
|
+
flushCode(i);
|
|
299
|
+
const start = i;
|
|
300
|
+
i += 2;
|
|
301
|
+
while (i < len && !text.startsWith('*/', i)) i++;
|
|
302
|
+
if (i < len) i += 2;
|
|
303
|
+
out += text.slice(start, i);
|
|
304
|
+
codeStart = i;
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const ch = text[i];
|
|
309
|
+
|
|
310
|
+
// Single-quoted string
|
|
311
|
+
if (ch === "'") {
|
|
312
|
+
flushCode(i);
|
|
313
|
+
const start = i;
|
|
314
|
+
i++;
|
|
315
|
+
while (i < len) {
|
|
316
|
+
const c = text[i];
|
|
317
|
+
if (c === '\\') {
|
|
318
|
+
i += 2;
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
i++;
|
|
322
|
+
if (c === "'") break;
|
|
323
|
+
}
|
|
324
|
+
out += text.slice(start, i);
|
|
325
|
+
codeStart = i;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Double-quoted string
|
|
330
|
+
if (ch === '"') {
|
|
331
|
+
flushCode(i);
|
|
332
|
+
const start = i;
|
|
333
|
+
i++;
|
|
334
|
+
while (i < len) {
|
|
335
|
+
const c = text[i];
|
|
336
|
+
if (c === '\\') {
|
|
337
|
+
i += 2;
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
i++;
|
|
341
|
+
if (c === '"') break;
|
|
342
|
+
}
|
|
343
|
+
out += text.slice(start, i);
|
|
344
|
+
codeStart = i;
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Template literal (backticks). We conservatively treat the whole template as a string.
|
|
349
|
+
// The generated .d.ts uses these primarily for template-literal *value* types like `TYPE-${string}`
|
|
350
|
+
// and we do not want to rewrite their raw text.
|
|
351
|
+
if (ch === '`') {
|
|
352
|
+
flushCode(i);
|
|
353
|
+
const start = i;
|
|
354
|
+
i++;
|
|
355
|
+
while (i < len) {
|
|
356
|
+
const c = text[i];
|
|
357
|
+
if (c === '\\') {
|
|
358
|
+
i += 2;
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
i++;
|
|
362
|
+
if (c === '`') break;
|
|
363
|
+
}
|
|
364
|
+
out += text.slice(start, i);
|
|
365
|
+
codeStart = i;
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
i++;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
flushCode(len);
|
|
373
|
+
return out;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function renameExportedTopLevelTypesToJson(tsText: string): string {
|
|
377
|
+
// Collect exported type/interface names.
|
|
378
|
+
const exportedDeclRegex = /^export\s+(?:type|interface)\s+([A-Za-z_][A-Za-z0-9_]*)\b/gm;
|
|
379
|
+
const exportedNames = new Set<string>();
|
|
380
|
+
for (let m = exportedDeclRegex.exec(tsText); m; m = exportedDeclRegex.exec(tsText)) {
|
|
381
|
+
exportedNames.add(m[1]);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const renamePairs = Array.from(exportedNames)
|
|
385
|
+
.filter((name) => !name.endsWith('Json'))
|
|
386
|
+
.map((name) => ({ from: name, to: `${name}Json` }));
|
|
387
|
+
|
|
388
|
+
if (!renamePairs.length) return tsText;
|
|
389
|
+
|
|
390
|
+
// Replace longer names first to reduce any accidental partial-match risk.
|
|
391
|
+
renamePairs.sort((a, b) => b.from.length - a.from.length);
|
|
392
|
+
|
|
393
|
+
const replaceCode = (code: string) => {
|
|
394
|
+
let out = code;
|
|
395
|
+
for (const { from, to } of renamePairs) {
|
|
396
|
+
const re = new RegExp(`\\b${escapeRegExpLiteral(from)}\\b`, 'g');
|
|
397
|
+
out = out.replace(re, to);
|
|
398
|
+
}
|
|
399
|
+
return out;
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
return applyReplacementsOutsideStringsAndComments(tsText, replaceCode);
|
|
403
|
+
}
|
|
404
|
+
|
|
263
405
|
// PURE: Derive the TS value type for JobStepSocket from Genesis.json.
|
|
264
406
|
// We prefer to match the schema shape:
|
|
265
407
|
// JobStepSocket.additionalProperties.oneOf = [#ResourcePotential, #Resource]
|
|
@@ -422,8 +564,8 @@ function postProcessEmittedTypes(ts: string, parsedSchema: any): string {
|
|
|
422
564
|
const strategyThreadKeyType = 'StrategyThreadIdentity';
|
|
423
565
|
|
|
424
566
|
ts = ts.replace(
|
|
425
|
-
/export interface
|
|
426
|
-
`export type
|
|
567
|
+
/export interface RoleDict\s*{[^}]*}/g,
|
|
568
|
+
`export type RoleDict = Record<${resourceRoleKeyType}, ResourceRoleValue>;`
|
|
427
569
|
);
|
|
428
570
|
// Normalize StrategyState & related socket maps to identity-keyed Records.
|
|
429
571
|
// These are emitted as `[k: string]` by json-schema-to-typescript but are identity-keyed in practice.
|
|
@@ -450,15 +592,19 @@ function postProcessEmittedTypes(ts: string, parsedSchema: any): string {
|
|
|
450
592
|
`$1Record<${jobStepKeyType}, JobStepSocket>;`
|
|
451
593
|
);
|
|
452
594
|
|
|
453
|
-
// Ensure key constraints for
|
|
595
|
+
// Ensure key constraints for strategyThreadDict are preserved as template-literal identity keys.
|
|
454
596
|
// json-schema-to-typescript emits `[k: string]: StepArray;`, but we want keys to be `StrategyThreadIdentity`.
|
|
455
597
|
ts = ts.replace(
|
|
456
|
-
/export interface
|
|
457
|
-
`export type
|
|
598
|
+
/export interface StrategyThreadDict\s*\{\s*\[k:\s*string\]:\s*StepArray;\s*\}/g,
|
|
599
|
+
`export type StrategyThreadDict = Record<${strategyThreadKeyType}, StepArray>;`
|
|
458
600
|
);
|
|
459
601
|
|
|
460
602
|
ts = fixJsonDataSelfReference(ts);
|
|
461
603
|
|
|
604
|
+
// IMPORTANT: do this last so earlier post-processing regexes can target
|
|
605
|
+
// the generator's original names (without `Json` suffixes).
|
|
606
|
+
ts = renameExportedTopLevelTypesToJson(ts);
|
|
607
|
+
|
|
462
608
|
return ts;
|
|
463
609
|
}
|
|
464
610
|
|