@toolproof-core/schema 1.0.10 → 1.0.12

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 (40) hide show
  1. package/dist/generated/artifacts/constants.d.ts +4 -3
  2. package/dist/generated/artifacts/constants.js +4 -3
  3. package/dist/generated/normalized/Genesis.json +50 -25
  4. package/dist/generated/resources/Genesis.json +68 -31
  5. package/dist/generated/schemas/Genesis.json +38 -19
  6. package/dist/generated/schemas/standalone/Job.json +7 -8
  7. package/dist/generated/schemas/standalone/ResourceType.json +4 -4
  8. package/dist/generated/schemas/standalone/RunnableStrategy.json +7 -7
  9. package/dist/generated/schemas/standalone/StrategyRun.json +7 -7
  10. package/dist/generated/types/standalone/Resource_Genesis.d.ts +1 -1
  11. package/dist/generated/types/standalone/Resource_Job.d.ts +1 -1
  12. package/dist/generated/types/standalone/Resource_RawStrategy.d.ts +1 -1
  13. package/dist/generated/types/standalone/Resource_ResourceType.d.ts +1 -1
  14. package/dist/generated/types/standalone/Resource_RunnableStrategy.d.ts +1 -1
  15. package/dist/generated/types/types.d.ts +229 -221
  16. package/dist/index.d.ts +1 -1
  17. package/dist/scripts/generateStandaloneType.js +2 -1
  18. package/dist/scripts/generateTypes.js +136 -3
  19. package/package.json +1 -1
  20. package/src/Genesis.json +54 -28
  21. package/src/generated/artifacts/constants.ts +4 -3
  22. package/src/generated/artifacts/dependencyMap.json +10 -6
  23. package/src/generated/artifacts/terminals.json +1 -0
  24. package/src/generated/normalized/Genesis.json +1785 -1760
  25. package/src/generated/resources/Genesis.json +2833 -2796
  26. package/src/generated/schemas/Genesis.json +1348 -1329
  27. package/src/generated/schemas/standalone/Job.json +7 -8
  28. package/src/generated/schemas/standalone/RawStrategy.json +580 -580
  29. package/src/generated/schemas/standalone/ResourceType.json +4 -4
  30. package/src/generated/schemas/standalone/RunnableStrategy.json +645 -645
  31. package/src/generated/schemas/standalone/StrategyRun.json +913 -913
  32. package/src/generated/types/standalone/Resource_Genesis.d.ts +1 -1
  33. package/src/generated/types/standalone/Resource_Job.d.ts +1 -1
  34. package/src/generated/types/standalone/Resource_RawStrategy.d.ts +1 -1
  35. package/src/generated/types/standalone/Resource_ResourceType.d.ts +1 -1
  36. package/src/generated/types/standalone/Resource_RunnableStrategy.d.ts +1 -1
  37. package/src/generated/types/types.d.ts +717 -709
  38. package/src/index.ts +48 -45
  39. package/src/scripts/generateStandaloneType.ts +3 -1
  40. package/src/scripts/generateTypes.ts +151 -5
package/src/index.ts CHANGED
@@ -27,49 +27,52 @@ export type {
27
27
 
28
28
 
29
29
  export type {
30
- DocumentationFacet as DocumentationFacetJson,
31
- NucleusFacet as NucleusFacetJson,
32
- ResourceTypeIdentity as ResourceTypeIdentityJson,
33
- ResourceType as ResourceTypeJson,
34
- ResourceRoleIdentity as ResourceRoleIdentityJson,
35
- ResourceRoleValue as ResourceRoleValueJson,
36
- Conditional as ConditionalJson,
37
- RoleMap as RoleMapJson,
38
- Roles as RolesJson,
39
- RoleBindings as RoleBindingsJson,
40
- ResourceIdentity as ResourceIdentityJson,
41
- JobStepIdentity as JobStepIdentityJson,
42
- BranchStepIdentity as BranchStepIdentityJson,
43
- WhileStepIdentity as WhileStepIdentityJson,
44
- ForStepIdentity as ForStepIdentityJson,
45
- JobStep as JobStepJson,
46
- BranchStep as BranchStepJson,
47
- WhileStep as WhileStepJson,
48
- ForStep as ForStepJson,
49
- StepKind as StepKindJson,
50
- StepIdentity as StepIdentityJson,
51
- Step as StepJson,
52
- CreationContext as CreationContextJson,
53
- ResourceMissing as ResourceMissingJson,
54
- ResourceInputPotential as ResourceInputPotentialJson,
55
- ResourceOutputPotential as ResourceOutputPotentialJson,
56
- ShellMaterializedBase as ShellMaterializedBaseJson,
57
- Resource as ResourceJson,
58
- StrategyState as StrategyStateJson,
59
- StepsFacet as StepsFacetJson,
60
- RawStrategy as RawStrategyJson,
61
- RunnableStrategyIdentity as RunnableStrategyIdentityJson,
62
- RunnableStrategyStatus as RunnableStrategyStatusJson,
63
- RunnableStrategy as RunnableStrategyJson,
64
- RunnableStrategyUpdate as RunnableStrategyUpdateJson,
65
- JobIdentity as JobIdentityJson,
66
- Job as JobJson,
67
- JsonData as JsonDataJson,
68
- StrategyThreadIdentity as StrategyThreadIdentityJson,
69
- StrategyThreadMap as StrategyThreadMapJson,
70
- JobStepSocket as JobStepSocketJson,
71
- Timestamp as TimestampJson,
72
- StrategyRunIdentity as StrategyRunIdentityJson,
73
- GoalIdentity as GoalIdentityJson,
74
- Goal as GoalJson,
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
+ StrategyRunJson,
75
+ GoalIdentityJson,
76
+ GoalJson,
77
+ ErrorJson,
75
78
  } 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, ${name} as NucleusSchema } from "../types.js";\n` +
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 RoleMap\s*{[^}]*}/g,
426
- `export type RoleMap = Record<${resourceRoleKeyType}, ResourceRoleValue>;`
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 strategyThreadMap are preserved as template-literal identity keys.
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 StrategyThreadMap\s*\{\s*\[k:\s*string\]:\s*StepArray;\s*\}/g,
457
- `export type StrategyThreadMap = Record<${strategyThreadKeyType}, StepArray>;`
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