@toolproof-core/genesis 1.0.55 → 1.0.58
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-src/declarations/resourceTypes.json +12 -3
- package/dist/generated-src/lookups/constants.d.ts +12 -25
- package/dist/generated-src/lookups/constants.js +12 -25
- package/dist/generated-src/schemas/schemas.json +73 -214
- package/dist/generated-src/schemas/standalone/Resource.json +18 -17
- package/dist/generated-src/schemas/standalone/Strategy.json +129 -261
- package/dist/generated-src/schemas/standalone/StrategyTrace.json +91 -150
- package/dist/generated-src/schemas/standalone/Suite.json +1 -2
- package/dist/generated-src/schemas/standalone/Tool.json +1 -2
- package/dist/generated-src/schemas/zod/Resource.js +3 -4
- package/dist/generated-src/schemas/zod/Strategy.d.ts +0 -6
- package/dist/generated-src/schemas/zod/Strategy.js +11 -31
- package/dist/generated-src/schemas/zod/StrategyTrace.d.ts +0 -6
- package/dist/generated-src/schemas/zod/StrategyTrace.js +20 -32
- package/dist/generated-src/timestampedResources/booleans.json +2 -2
- package/dist/generated-src/timestampedResources/naturals.json +11 -11
- package/dist/generated-src/timestampedResources/resourceTypes.json +22 -13
- package/dist/generated-src/timestampedResources/tools.json +15 -15
- package/dist/generated-src/types/types.d.ts +48 -124
- package/dist/src/index.d.ts +1 -1
- package/dist/src/utils/standaloneZodSchemas.js +6 -6
- package/dist/src/utils/timestampedResources.d.ts +1 -1
- package/dist/src/utils/timestampedResources.js +1 -1
- package/dist/src/utils/typeGenerationPostProcess.js +20 -6
- package/dist/src/utils/zodCodegen.d.ts +1 -1
- package/dist/src/utils/zodCodegen.js +7 -7
- package/package.json +1 -1
|
@@ -78,7 +78,7 @@ export type ResourceId =
|
|
|
78
78
|
* via the `definition` "Provenance".
|
|
79
79
|
*/
|
|
80
80
|
export type Provenance =
|
|
81
|
-
GenesisProvenance | StrategyProvenance;
|
|
81
|
+
GenesisProvenance | RuntimeProvenance | StrategyProvenance;
|
|
82
82
|
/**
|
|
83
83
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
84
84
|
* via the `definition` "StrategyTraceHandle".
|
|
@@ -90,19 +90,7 @@ export type StrategyTraceHandle =
|
|
|
90
90
|
* via the `definition` "ToolStepPath".
|
|
91
91
|
*/
|
|
92
92
|
export type ToolStepPath =
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
96
|
-
* via the `definition` "UnthreadedToolStepPath".
|
|
97
|
-
*/
|
|
98
|
-
export type UnthreadedToolStepPath =
|
|
99
|
-
string;
|
|
100
|
-
/**
|
|
101
|
-
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
102
|
-
* via the `definition` "ThreadedToolStepPath".
|
|
103
|
-
*/
|
|
104
|
-
export type ThreadedToolStepPath =
|
|
105
|
-
string;
|
|
93
|
+
string & { readonly __brand: 'ToolStepPath' };
|
|
106
94
|
/**
|
|
107
95
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
108
96
|
* via the `definition` "ResourceType".
|
|
@@ -219,7 +207,7 @@ export type Step =
|
|
|
219
207
|
* via the `definition` "ProvenanceKind".
|
|
220
208
|
*/
|
|
221
209
|
export type ProvenanceKind =
|
|
222
|
-
"genesis" | "strategy";
|
|
210
|
+
"genesis" | "runtime" | "strategy";
|
|
223
211
|
/**
|
|
224
212
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
225
213
|
* via the `definition` "BaseResource".
|
|
@@ -279,13 +267,14 @@ export type StepArrayArray =
|
|
|
279
267
|
* via the `definition` "ToolStepPathSlot".
|
|
280
268
|
*/
|
|
281
269
|
export type ToolStepPathSlot =
|
|
282
|
-
"self" | "case
|
|
270
|
+
"self" | "case/when" | "case/what" | "cases/when" | "cases/what";
|
|
283
271
|
/**
|
|
284
272
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
285
|
-
* via the `definition` "
|
|
273
|
+
* via the `definition` "ToolStepPathSpec".
|
|
286
274
|
*/
|
|
287
|
-
export type
|
|
275
|
+
export type ToolStepPathSpec =
|
|
288
276
|
{
|
|
277
|
+
threadIndex: Natural;
|
|
289
278
|
stepIndex: Natural;
|
|
290
279
|
toolStepPathSlot: ToolStepPathSlot;
|
|
291
280
|
caseIndex?: Natural;
|
|
@@ -297,74 +286,35 @@ export type BaseToolStepPathSpec =
|
|
|
297
286
|
*/
|
|
298
287
|
export type Natural =
|
|
299
288
|
number;
|
|
300
|
-
/**
|
|
301
|
-
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
302
|
-
* via the `definition` "UnthreadedToolStepPathSpec".
|
|
303
|
-
*/
|
|
304
|
-
export type UnthreadedToolStepPathSpec =
|
|
305
|
-
{
|
|
306
|
-
} & BaseToolStepPathSpec;
|
|
307
|
-
/**
|
|
308
|
-
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
309
|
-
* via the `definition` "ThreadedToolStepPathSpec".
|
|
310
|
-
*/
|
|
311
|
-
export type ThreadedToolStepPathSpec =
|
|
312
|
-
{
|
|
313
|
-
} & BaseToolStepPathSpec & {
|
|
314
|
-
threadIndex: Natural;
|
|
315
|
-
};
|
|
316
|
-
/**
|
|
317
|
-
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
318
|
-
* via the `definition` "StrategyKind".
|
|
319
|
-
*/
|
|
320
|
-
export type StrategyKind =
|
|
321
|
-
"unthreaded" | "threaded";
|
|
322
289
|
/**
|
|
323
290
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
324
291
|
* via the `definition` "StrategyHandle".
|
|
325
292
|
*/
|
|
326
293
|
export type StrategyHandle =
|
|
327
294
|
`STRATEGY-${string}`;
|
|
328
|
-
/**
|
|
329
|
-
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
330
|
-
* via the `definition` "UnthreadedStrategy".
|
|
331
|
-
*/
|
|
332
|
-
export type UnthreadedStrategy =
|
|
333
|
-
{
|
|
334
|
-
} & BaseStrategy & {
|
|
335
|
-
strategyKind?: "unthreaded";
|
|
336
|
-
} & StepsFacet &
|
|
337
|
-
UnthreadedStrategyStateFacet;
|
|
338
|
-
/**
|
|
339
|
-
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
340
|
-
* via the `definition` "ThreadedStrategy".
|
|
341
|
-
*/
|
|
342
|
-
export type ThreadedStrategy =
|
|
343
|
-
{
|
|
344
|
-
} & BaseStrategy & {
|
|
345
|
-
strategyKind?: "threaded";
|
|
346
|
-
} & StepsByThreadIndexFacet &
|
|
347
|
-
ThreadedStrategyStateFacet;
|
|
348
295
|
/**
|
|
349
296
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
350
297
|
* via the `definition` "Strategy".
|
|
351
298
|
*/
|
|
352
299
|
export type Strategy =
|
|
353
|
-
|
|
300
|
+
{
|
|
301
|
+
handle: StrategyHandle;
|
|
302
|
+
} & StepsByThreadIndexFacet &
|
|
303
|
+
StrategyStateFacet;
|
|
354
304
|
/**
|
|
355
305
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
356
306
|
* via the `definition` "TracePointKind".
|
|
357
307
|
*/
|
|
358
308
|
export type TracePointKind =
|
|
359
|
-
"
|
|
309
|
+
"strategy_start" | "tick" | "suspended" | "strategy_end";
|
|
360
310
|
/**
|
|
361
311
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
362
|
-
* via the `definition` "
|
|
312
|
+
* via the `definition` "StrategyStartTracePoint".
|
|
363
313
|
*/
|
|
364
|
-
export type
|
|
314
|
+
export type StrategyStartTracePoint =
|
|
365
315
|
BaseTracePoint & {
|
|
366
|
-
tracePointKind?: "
|
|
367
|
-
} &
|
|
316
|
+
tracePointKind?: "strategy_start";
|
|
317
|
+
} & StrategyFacet;
|
|
368
318
|
/**
|
|
369
319
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
370
320
|
* via the `definition` "TickTracePoint".
|
|
@@ -373,37 +323,39 @@ export type TickTracePoint =
|
|
|
373
323
|
BaseTracePoint & {
|
|
374
324
|
tracePointKind?: "tick";
|
|
375
325
|
counterSnapshot: TracePointCounterSnapshot;
|
|
376
|
-
|
|
326
|
+
threadIndex: Natural;
|
|
327
|
+
toolStepPath: ToolStepPath;
|
|
377
328
|
delta: TracePointDelta;
|
|
378
329
|
};
|
|
379
330
|
/**
|
|
380
331
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
381
|
-
* via the `definition` "
|
|
332
|
+
* via the `definition` "SuspendedTracePoint".
|
|
382
333
|
*/
|
|
383
|
-
export type
|
|
334
|
+
export type SuspendedTracePoint =
|
|
384
335
|
BaseTracePoint & {
|
|
385
|
-
tracePointKind?: "
|
|
336
|
+
tracePointKind?: "suspended";
|
|
386
337
|
counterSnapshot: TracePointCounterSnapshot;
|
|
387
|
-
|
|
338
|
+
threadIndex: Natural;
|
|
339
|
+
toolStepPath: ToolStepPath;
|
|
388
340
|
delta: TracePointDelta & {
|
|
389
|
-
|
|
341
|
+
suspendedData: {
|
|
390
342
|
};
|
|
391
343
|
};
|
|
392
344
|
};
|
|
393
345
|
/**
|
|
394
346
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
395
|
-
* via the `definition` "
|
|
347
|
+
* via the `definition` "StrategyEndTracePoint".
|
|
396
348
|
*/
|
|
397
|
-
export type
|
|
349
|
+
export type StrategyEndTracePoint =
|
|
398
350
|
BaseTracePoint & {
|
|
399
|
-
tracePointKind?: "
|
|
351
|
+
tracePointKind?: "strategy_end";
|
|
400
352
|
};
|
|
401
353
|
/**
|
|
402
354
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
403
355
|
* via the `definition` "TracePoint".
|
|
404
356
|
*/
|
|
405
357
|
export type TracePoint =
|
|
406
|
-
|
|
358
|
+
StrategyStartTracePoint | TickTracePoint | SuspendedTracePoint | StrategyEndTracePoint;
|
|
407
359
|
/**
|
|
408
360
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
409
361
|
* via the `definition` "GoalHandle".
|
|
@@ -507,6 +459,13 @@ export interface ProvenanceFacet {
|
|
|
507
459
|
export interface GenesisProvenance {
|
|
508
460
|
provenanceKind: "genesis";
|
|
509
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
464
|
+
* via the `definition` "RuntimeProvenance".
|
|
465
|
+
*/
|
|
466
|
+
export interface RuntimeProvenance {
|
|
467
|
+
provenanceKind: "runtime";
|
|
468
|
+
}
|
|
510
469
|
/**
|
|
511
470
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
512
471
|
* via the `definition` "StrategyProvenance".
|
|
@@ -521,8 +480,8 @@ export interface StrategyProvenance {
|
|
|
521
480
|
* via the `definition` "ToolStepRoleAddress".
|
|
522
481
|
*/
|
|
523
482
|
export interface ToolStepRoleAddress {
|
|
524
|
-
roleName:
|
|
525
|
-
|
|
483
|
+
roleName: RoleName;
|
|
484
|
+
toolStepPath: ToolStepPath;
|
|
526
485
|
}
|
|
527
486
|
export interface JsonSchemaObject1 {
|
|
528
487
|
$schema: "https://json-schema.org/draft/2020-12/schema";
|
|
@@ -584,22 +543,12 @@ export interface Case {
|
|
|
584
543
|
when: ToolStep;
|
|
585
544
|
what: ToolStep;
|
|
586
545
|
}
|
|
587
|
-
/**
|
|
588
|
-
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
589
|
-
* via the `definition` "DeferredStrategyProvenance".
|
|
590
|
-
*/
|
|
591
|
-
export interface DeferredStrategyProvenance {
|
|
592
|
-
provenanceKind: "strategy";
|
|
593
|
-
toolStepRoleAddress: ToolStepRoleAddress;
|
|
594
|
-
}
|
|
595
546
|
/**
|
|
596
547
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
597
548
|
* via the `definition` "ExternalInputPotential".
|
|
598
549
|
*/
|
|
599
550
|
export interface ExternalInputPotential {
|
|
600
551
|
strategyStateInputKind: "externalInputPotential";
|
|
601
|
-
id: ResourceId;
|
|
602
|
-
resourceTypeHandle: ResourceTypeHandle;
|
|
603
552
|
}
|
|
604
553
|
/**
|
|
605
554
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
@@ -607,9 +556,7 @@ export interface ExternalInputPotential {
|
|
|
607
556
|
*/
|
|
608
557
|
export interface InternalInputPotential {
|
|
609
558
|
strategyStateInputKind: "internalInputPotential";
|
|
610
|
-
|
|
611
|
-
resourceTypeHandle: ResourceTypeHandle;
|
|
612
|
-
provenance: DeferredStrategyProvenance;
|
|
559
|
+
toolStepRoleAddress: ToolStepRoleAddress;
|
|
613
560
|
}
|
|
614
561
|
/**
|
|
615
562
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
@@ -632,39 +579,17 @@ export interface ToolStepPathSlotFacet {
|
|
|
632
579
|
}
|
|
633
580
|
/**
|
|
634
581
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
635
|
-
* via the `definition` "
|
|
582
|
+
* via the `definition` "StrategyState".
|
|
636
583
|
*/
|
|
637
|
-
export interface
|
|
584
|
+
export interface StrategyState {
|
|
638
585
|
[k: string]: StrategyStateInputEntryByRoleName;
|
|
639
586
|
}
|
|
640
587
|
/**
|
|
641
588
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
642
|
-
* via the `definition` "
|
|
589
|
+
* via the `definition` "StrategyStateFacet".
|
|
643
590
|
*/
|
|
644
|
-
export interface
|
|
645
|
-
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
649
|
-
* via the `definition` "UnthreadedStrategyStateFacet".
|
|
650
|
-
*/
|
|
651
|
-
export interface UnthreadedStrategyStateFacet {
|
|
652
|
-
strategyState: UnthreadedStrategyState;
|
|
653
|
-
}
|
|
654
|
-
/**
|
|
655
|
-
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
656
|
-
* via the `definition` "ThreadedStrategyStateFacet".
|
|
657
|
-
*/
|
|
658
|
-
export interface ThreadedStrategyStateFacet {
|
|
659
|
-
strategyState: ThreadedStrategyState;
|
|
660
|
-
}
|
|
661
|
-
/**
|
|
662
|
-
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
663
|
-
* via the `definition` "BaseStrategy".
|
|
664
|
-
*/
|
|
665
|
-
export interface BaseStrategy {
|
|
666
|
-
handle: StrategyHandle;
|
|
667
|
-
strategyKind: StrategyKind;
|
|
591
|
+
export interface StrategyStateFacet {
|
|
592
|
+
strategyState: StrategyState;
|
|
668
593
|
}
|
|
669
594
|
/**
|
|
670
595
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
@@ -690,8 +615,8 @@ export interface TracePointDelta {
|
|
|
690
615
|
insertAt: Natural;
|
|
691
616
|
insertedSteps: StepArray;
|
|
692
617
|
};
|
|
693
|
-
strategyStateDelta?:
|
|
694
|
-
|
|
618
|
+
strategyStateDelta?: StrategyState;
|
|
619
|
+
suspendedData?: {
|
|
695
620
|
} | null;
|
|
696
621
|
}
|
|
697
622
|
/**
|
|
@@ -701,15 +626,14 @@ export interface TracePointDelta {
|
|
|
701
626
|
export interface BaseTracePoint {
|
|
702
627
|
tracePointKind: TracePointKind;
|
|
703
628
|
strategyHandle: StrategyHandle;
|
|
704
|
-
threadIndex: Natural;
|
|
705
629
|
tracePointIndex: Natural;
|
|
706
630
|
}
|
|
707
631
|
/**
|
|
708
632
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
|
709
|
-
* via the `definition` "
|
|
633
|
+
* via the `definition` "StrategyFacet".
|
|
710
634
|
*/
|
|
711
|
-
export interface
|
|
712
|
-
|
|
635
|
+
export interface StrategyFacet {
|
|
636
|
+
strategy: Strategy;
|
|
713
637
|
}
|
|
714
638
|
/**
|
|
715
639
|
* This interface was referenced by `Genesis`'s JSON-Schema
|
package/dist/src/index.d.ts
CHANGED
|
@@ -17,4 +17,4 @@ export type { ResourceTypeResource, } from '../generated-src/types/standalone/Re
|
|
|
17
17
|
export type { ToolResource, } from '../generated-src/types/standalone/ToolResource.js';
|
|
18
18
|
export type { StrategyResource, } from '../generated-src/types/standalone/StrategyResource.js';
|
|
19
19
|
export type { StrategyTraceResource, } from '../generated-src/types/standalone/StrategyTraceResource.js';
|
|
20
|
-
export type { BaseResource,
|
|
20
|
+
export type { BaseResource, Boolean, BranchStep, Case, ContainerKind, Description, DescriptionFacet, DocumentationSpec, ExternalInputPotential, StrategyEndTracePoint, StrategyStartTracePoint, GenesisProvenance, Goal, InputPotential, InputResource, InternalInputPotential, SuspendedTracePoint, JsonSchemaObject, Name, NameFacet, Natural, ToolStepRoleAddress, Provenance, ProvenanceFacet, ProvenanceKind, Resource, ResourceId, ResourcePointer, ResourceType, ResourceTypeHandle, RoleBindingSpec, RoleBindingSpecFacet, RoleName, RoleNameArray, RoleSpec, RoleSpecFacet, RoleValue, RoleValueByName, RuntimeProvenance, Step, StepArray, StepArrayArray, StepKind, StepKindFacet, StrategyHandle, StrategyProvenance, StrategyStateInputEntry, StrategyStateInputEntryByRoleName, StrategyStateInputKind, StrategyTrace, StrategyTraceHandle, TickTracePoint, TimestampedResource, TracePoint, Strategy, StrategyState, StrategyStateFacet, ToolStepPath, ToolStepPathSpec, Tool, ToolHandle, ToolStep, ToolStepPathSlot, ToolStepPathSlotFacet, TypeRef, WhileStep, ForStep, } from '../generated-src/types/types.js';
|
|
@@ -12,7 +12,7 @@ function emitHeader(name) {
|
|
|
12
12
|
return (`// Auto-generated from standalone schema '${name}'. Do not edit.\n` +
|
|
13
13
|
`import { z } from 'zod/v4';\n\n`);
|
|
14
14
|
}
|
|
15
|
-
function emitModule(name,
|
|
15
|
+
function emitModule(name, expressionByName, warnings) {
|
|
16
16
|
const lines = [];
|
|
17
17
|
lines.push(emitHeader(name));
|
|
18
18
|
if (warnings.length > 0) {
|
|
@@ -20,7 +20,7 @@ function emitModule(name, expressionsByName, warnings) {
|
|
|
20
20
|
lines.push(`export const ${warningsName} = ${JSON.stringify(warnings, null, 2)} as const;\n`);
|
|
21
21
|
}
|
|
22
22
|
const rootIdent = toIdentifier(name);
|
|
23
|
-
const defNames = Object.keys(
|
|
23
|
+
const defNames = Object.keys(expressionByName)
|
|
24
24
|
.filter((schemaName) => schemaName !== name)
|
|
25
25
|
.sort((a, b) => a.localeCompare(b));
|
|
26
26
|
for (const schemaName of defNames) {
|
|
@@ -28,19 +28,19 @@ function emitModule(name, expressionsByName, warnings) {
|
|
|
28
28
|
if (!isValidIdentifier(ident)) {
|
|
29
29
|
throw new Error(`Invalid generated identifier for schema '${schemaName}': '${ident}'`);
|
|
30
30
|
}
|
|
31
|
-
const expr =
|
|
31
|
+
const expr = expressionByName[schemaName];
|
|
32
32
|
lines.push(`const ${ident}Schema: z.ZodTypeAny = z.lazy(() => ${expr});`);
|
|
33
33
|
}
|
|
34
34
|
lines.push('');
|
|
35
|
-
const rootExpr =
|
|
35
|
+
const rootExpr = expressionByName[name];
|
|
36
36
|
lines.push(`export const ${rootIdent}Schema: z.ZodTypeAny = z.lazy(() => ${rootExpr});`);
|
|
37
37
|
return lines.join('\n') + '\n';
|
|
38
38
|
}
|
|
39
39
|
export function generateStandaloneZodModule(name, standaloneSchema) {
|
|
40
|
-
const {
|
|
40
|
+
const { expressionByName, warnings } = jsonSchemaToZodExpressions(standaloneSchema, name);
|
|
41
41
|
return {
|
|
42
42
|
fileName: `${name}.ts`,
|
|
43
|
-
content: emitModule(name,
|
|
43
|
+
content: emitModule(name, expressionByName, warnings),
|
|
44
44
|
warnings,
|
|
45
45
|
};
|
|
46
46
|
}
|
|
@@ -9,7 +9,7 @@ function createTimestampedResource(projection, options) {
|
|
|
9
9
|
id: options.getResourceId(projection),
|
|
10
10
|
resourceTypeHandle: options.resourceTypeHandle,
|
|
11
11
|
provenance: {
|
|
12
|
-
|
|
12
|
+
provenanceKind: 'genesis',
|
|
13
13
|
},
|
|
14
14
|
timestamp: GENESIS_TIMESTAMP,
|
|
15
15
|
projection,
|
|
@@ -108,6 +108,24 @@ function fixRecursiveArrayAliasSelfReference(ts, typeName) {
|
|
|
108
108
|
}
|
|
109
109
|
return lines.join('\n');
|
|
110
110
|
}
|
|
111
|
+
function brandToolStepPathAlias(ts) {
|
|
112
|
+
return ts.replace(/\/\*\*\r?\n \* This interface was referenced by `Genesis`'s JSON-Schema\r?\n \* via the `definition` "ToolStepPath"\.\r?\n \*\/\r?\nexport type ToolStepPath =\r?\n[\s\S]*?;/, `/**
|
|
113
|
+
* This interface was referenced by \`Genesis\`'s JSON-Schema
|
|
114
|
+
* via the \`definition\` "ToolStepPath".
|
|
115
|
+
*/
|
|
116
|
+
export type ToolStepPath =
|
|
117
|
+
string & { readonly __brand: 'ToolStepPath' };`);
|
|
118
|
+
}
|
|
119
|
+
function addTypedToolStepRoleAddressAlias(ts) {
|
|
120
|
+
return ts.replace(/\/\*\*\r?\n \* This interface was referenced by `Genesis`'s JSON-Schema\r?\n \* via the `definition` "ToolStepRoleAddress"\.\r?\n \*\/\r?\nexport interface ToolStepRoleAddress \{\r?\n roleName: (?:string|RoleName);\r?\n toolStepPath: ToolStepPath;\r?\n\}/, `/**
|
|
121
|
+
* This interface was referenced by \`Genesis\`'s JSON-Schema
|
|
122
|
+
* via the \`definition\` "ToolStepRoleAddress".
|
|
123
|
+
*/
|
|
124
|
+
export interface ToolStepRoleAddress {
|
|
125
|
+
roleName: RoleName;
|
|
126
|
+
toolStepPath: ToolStepPath;
|
|
127
|
+
}`);
|
|
128
|
+
}
|
|
111
129
|
export function postProcessEmittedTypes(ts, parsedSchema) {
|
|
112
130
|
ts = ts.replace(/^\s*\[k:\s*string\]:\s*unknown;\s*(?:\r?\n)?/gm, '');
|
|
113
131
|
ts = ts.replace(/^(\s*)(\$defs\??:\s*)\{\s*\r?\n\s*\};/gm, (_m, indent, head) => `${indent}${head}Record<string, unknown>;`);
|
|
@@ -133,18 +151,14 @@ export function postProcessEmittedTypes(ts, parsedSchema) {
|
|
|
133
151
|
const tmpl = patternTemplates[typeName];
|
|
134
152
|
return `${p1}${typeName}${p3}${tmpl ?? 'string'};`;
|
|
135
153
|
});
|
|
154
|
+
ts = brandToolStepPathAlias(ts);
|
|
155
|
+
ts = addTypedToolStepRoleAddressAlias(ts);
|
|
136
156
|
const roleNameKeyType = 'RoleName';
|
|
137
|
-
const unthreadedToolStepPathKeyType = 'UnthreadedToolStepPath';
|
|
138
|
-
const threadedToolStepPathKeyType = 'ThreadedToolStepPath';
|
|
139
157
|
const toolStepPathKeyType = 'ToolStepPath';
|
|
140
158
|
ts = ts.replace(/export interface RoleValueByName\s*\{\s*\[k:\s*string\]:\s*RoleValue;\s*\}/g, `export type RoleValueByName = Record<${roleNameKeyType}, RoleValue>;`);
|
|
141
159
|
const strategyStateInputEntryByRoleNameValueType = deriveStrategyStateInputEntryByRoleNameValueType(parsedSchema);
|
|
142
160
|
ts = ts.replace(/export interface StrategyStateInputEntryByRoleName\s*\{\s*\[k:\s*string\]:\s*[^;]+;\s*\}/g, `export type StrategyStateInputEntryByRoleName = Record<${roleNameKeyType}, ${strategyStateInputEntryByRoleNameValueType}>;`);
|
|
143
161
|
ts = ts.replace(/export\s+type\s+StrategyStateInputEntryByRoleName\s*=\s*Record<\s*RoleName\s*,\s*[^>]+>\s*;/g, `export type StrategyStateInputEntryByRoleName = Record<${roleNameKeyType}, ${strategyStateInputEntryByRoleNameValueType}>;`);
|
|
144
|
-
ts = ts.replace(/export interface StrategyStateInputEntryByRoleNameByUnthreadedToolStepPath\s*\{\s*\[k:\s*string\]:\s*StrategyStateInputEntryByRoleName;\s*\}/g, `export type StrategyStateInputEntryByRoleNameByUnthreadedToolStepPath = Record<${unthreadedToolStepPathKeyType}, StrategyStateInputEntryByRoleName>;`);
|
|
145
|
-
ts = ts.replace(/export interface StrategyStateInputEntryByRoleNameByThreadedToolStepPath\s*\{\s*\[k:\s*string\]:\s*StrategyStateInputEntryByRoleName;\s*\}/g, `export type StrategyStateInputEntryByRoleNameByThreadedToolStepPath = Record<${threadedToolStepPathKeyType}, StrategyStateInputEntryByRoleName>;`);
|
|
146
|
-
ts = ts.replace(/export\s+type\s+UnthreadedStrategyState\s*=\s*StrategyStateInputEntryByRoleNameByUnthreadedToolStepPath\s*;/g, `export type UnthreadedStrategyState = Record<${unthreadedToolStepPathKeyType}, StrategyStateInputEntryByRoleName>;`);
|
|
147
|
-
ts = ts.replace(/export\s+type\s+ThreadedStrategyState\s*=\s*StrategyStateInputEntryByRoleNameByThreadedToolStepPath\s*;/g, `export type ThreadedStrategyState = Record<${threadedToolStepPathKeyType}, StrategyStateInputEntryByRoleName>;`);
|
|
148
162
|
ts = ts.replace(/(strategyState\??:\s*)\{\s*\[k:\s*string\]:\s*StrategyStateInputEntryByRoleName;\s*\};/g, `$1Record<${toolStepPathKeyType}, StrategyStateInputEntryByRoleName>;`);
|
|
149
163
|
ts = ts.replace(/(strategyStateUpdate\??:\s*)\{\s*\[k:\s*string\]:\s*StrategyStateInputEntryByRoleName;\s*\};/g, `$1Record<${toolStepPathKeyType}, StrategyStateInputEntryByRoleName>;`);
|
|
150
164
|
ts = ts.replace(/export interface StepsByThreadIndexFacet\s*\{\s*stepsByThreadIndex:\s*StepArrayArray;\s*\}/g, 'export interface StepsByThreadIndexFacet {\n stepsByThreadIndex: StepArrayArray;\n}');
|
|
@@ -4,7 +4,7 @@ export type JsonSchemaToZodWarning = {
|
|
|
4
4
|
message: string;
|
|
5
5
|
};
|
|
6
6
|
export type JsonSchemaToZodResult = {
|
|
7
|
-
|
|
7
|
+
expressionByName: Record<string, string>;
|
|
8
8
|
warnings: JsonSchemaToZodWarning[];
|
|
9
9
|
};
|
|
10
10
|
export declare function jsonSchemaToZodExpressions(standaloneSchema: JsonSchema, rootName: string): JsonSchemaToZodResult;
|
|
@@ -76,7 +76,7 @@ function emitRecordLikeObjectSchema(node, ctx, path) {
|
|
|
76
76
|
}
|
|
77
77
|
else if (typeof pn.$ref === 'string') {
|
|
78
78
|
const defName = resolveLocalRef(pn.$ref, ctx);
|
|
79
|
-
const resolved = defName ? ctx.
|
|
79
|
+
const resolved = defName ? ctx.defByName[defName] : undefined;
|
|
80
80
|
if (isObject(resolved) && typeof resolved.pattern === 'string') {
|
|
81
81
|
keyPattern = resolved.pattern;
|
|
82
82
|
}
|
|
@@ -112,7 +112,7 @@ function resolveSchemaIfRef(node, ctx) {
|
|
|
112
112
|
if (isObject(node) && typeof node.$ref === 'string') {
|
|
113
113
|
const defName = resolveLocalRef(node.$ref, ctx);
|
|
114
114
|
if (defName)
|
|
115
|
-
return ctx.
|
|
115
|
+
return ctx.defByName[defName];
|
|
116
116
|
}
|
|
117
117
|
return node;
|
|
118
118
|
}
|
|
@@ -508,14 +508,14 @@ export function jsonSchemaToZodExpressions(standaloneSchema, rootName) {
|
|
|
508
508
|
const defNames = new Set(Object.keys(defs));
|
|
509
509
|
const ctx = {
|
|
510
510
|
defNames,
|
|
511
|
-
|
|
511
|
+
defByName: defs,
|
|
512
512
|
anchorToDefName: buildAnchorMap(defs),
|
|
513
513
|
warnings: []
|
|
514
514
|
};
|
|
515
|
-
const
|
|
515
|
+
const expressionByName = {};
|
|
516
516
|
for (const defName of Object.keys(defs)) {
|
|
517
|
-
|
|
517
|
+
expressionByName[defName] = emitSchema(defs[defName], ctx, `$defs.${defName}`);
|
|
518
518
|
}
|
|
519
|
-
|
|
520
|
-
return {
|
|
519
|
+
expressionByName[rootName] = emitSchema(normalized, ctx, rootName);
|
|
520
|
+
return { expressionByName, warnings: ctx.warnings };
|
|
521
521
|
}
|
package/package.json
CHANGED