@toolproof-npm/schema 0.1.42 → 0.1.44
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/_lib/types/Resource_Job.d.ts +5 -4
- package/dist/_lib/types/Resource_ResourceFormat.d.ts +5 -4
- package/dist/_lib/types/Resource_ResourceType.d.ts +5 -4
- package/dist/_lib/types/Resource_StatelessStrategy.d.ts +5 -4
- package/dist/_lib/types/types.d.ts +14 -8
- package/dist/genesis/generated/resources/Genesis.json +34 -13
- package/dist/genesis/generated/schemas/Genesis.json +19 -14
- package/dist/genesis/generated/schemas/StatefulStrategy.json +18 -13
- package/dist/genesis/resourceTypes/Genesis.json +25 -14
- package/dist/index.d.ts +1 -1
- package/dist/scripts/resolveRefsInGenesisStory.d.ts +1 -0
- package/dist/scripts/resolveRefsInGenesisStory.js +199 -0
- package/package.json +2 -1
|
@@ -23,10 +23,11 @@ export type ResourceRoleValue = {
|
|
|
23
23
|
} & Documented;
|
|
24
24
|
|
|
25
25
|
export interface CreationContext {
|
|
26
|
-
creationContext:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
creationContext: CreationContextValue;
|
|
27
|
+
}
|
|
28
|
+
export interface CreationContextValue {
|
|
29
|
+
executionId: string;
|
|
30
|
+
resourceRoleId: string;
|
|
30
31
|
}
|
|
31
32
|
export interface ResourceKind {
|
|
32
33
|
kind: "missing" | "potential-input" | "potential-output" | "materialized";
|
|
@@ -18,10 +18,11 @@ export type ResourceFormat = {
|
|
|
18
18
|
export type Documented = Name & Description;
|
|
19
19
|
|
|
20
20
|
export interface CreationContext {
|
|
21
|
-
creationContext:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
creationContext: CreationContextValue;
|
|
22
|
+
}
|
|
23
|
+
export interface CreationContextValue {
|
|
24
|
+
executionId: string;
|
|
25
|
+
resourceRoleId: string;
|
|
25
26
|
}
|
|
26
27
|
export interface ResourceKind {
|
|
27
28
|
kind: "missing" | "potential-input" | "potential-output" | "materialized";
|
|
@@ -36,10 +36,11 @@ export type ExtractionSchemaValue = {
|
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
export interface CreationContext {
|
|
39
|
-
creationContext:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
creationContext: CreationContextValue;
|
|
40
|
+
}
|
|
41
|
+
export interface CreationContextValue {
|
|
42
|
+
executionId: string;
|
|
43
|
+
resourceRoleId: string;
|
|
43
44
|
}
|
|
44
45
|
export interface ResourceKind {
|
|
45
46
|
kind: "missing" | "potential-input" | "potential-output" | "materialized";
|
|
@@ -46,10 +46,11 @@ export type ForStep = StepKind & {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
export interface CreationContext {
|
|
49
|
-
creationContext:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
creationContext: CreationContextValue;
|
|
50
|
+
}
|
|
51
|
+
export interface CreationContextValue {
|
|
52
|
+
executionId: string;
|
|
53
|
+
resourceRoleId: string;
|
|
53
54
|
}
|
|
54
55
|
export interface ResourceKind {
|
|
55
56
|
kind: "missing" | "potential-input" | "potential-output" | "materialized";
|
|
@@ -343,10 +343,15 @@ export type RoleBindingMap = Record<ResourceRoleId, ResourceId>;
|
|
|
343
343
|
* via the `definition` "CreationContext".
|
|
344
344
|
*/
|
|
345
345
|
export interface CreationContext {
|
|
346
|
-
creationContext:
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
346
|
+
creationContext: CreationContextValue;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* This interface was referenced by `GenesisJson`'s JSON-Schema
|
|
350
|
+
* via the `definition` "CreationContextValue".
|
|
351
|
+
*/
|
|
352
|
+
export interface CreationContextValue {
|
|
353
|
+
executionId: ExecutionId;
|
|
354
|
+
resourceRoleId: ResourceRoleId;
|
|
350
355
|
}
|
|
351
356
|
/**
|
|
352
357
|
* This interface was referenced by `GenesisJson`'s JSON-Schema
|
|
@@ -700,10 +705,11 @@ export interface ResourceKind {
|
|
|
700
705
|
kind: "missing" | "potential-input" | "potential-output" | "materialized";
|
|
701
706
|
}
|
|
702
707
|
export interface CreationContext {
|
|
703
|
-
creationContext:
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
708
|
+
creationContext: CreationContextValue;
|
|
709
|
+
}
|
|
710
|
+
export interface CreationContextValue {
|
|
711
|
+
executionId: ExecutionId;
|
|
712
|
+
resourceRoleId: ResourceRoleId;
|
|
707
713
|
}
|
|
708
714
|
export interface Timestamp {
|
|
709
715
|
timestamp: string;
|
|
@@ -951,6 +951,39 @@
|
|
|
951
951
|
}
|
|
952
952
|
}
|
|
953
953
|
},
|
|
954
|
+
"CreationContextValue": {
|
|
955
|
+
"identity": "RESOURCE-CreationContextValue",
|
|
956
|
+
"resourceTypeId": "TYPE-ResourceType",
|
|
957
|
+
"creationContext": {
|
|
958
|
+
"resourceRoleId": "ROLE-Genesis",
|
|
959
|
+
"executionId": "EXECUTION-CreationContextValue"
|
|
960
|
+
},
|
|
961
|
+
"kind": "materialized",
|
|
962
|
+
"timestamp": "2025-11-30T00:00:00.000Z",
|
|
963
|
+
"extractedData": {
|
|
964
|
+
"identity": "TYPE-CreationContextValue",
|
|
965
|
+
"name": "CreationContextValue",
|
|
966
|
+
"description": "dummy-description",
|
|
967
|
+
"resourceFormatId": "FORMAT-ApplicationJson",
|
|
968
|
+
"extractionSchema": {
|
|
969
|
+
"$anchor": "CreationContextValue",
|
|
970
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
971
|
+
"type": "object",
|
|
972
|
+
"required": [
|
|
973
|
+
"resourceRoleId",
|
|
974
|
+
"executionId"
|
|
975
|
+
],
|
|
976
|
+
"properties": {
|
|
977
|
+
"resourceRoleId": {
|
|
978
|
+
"$ref": "#/$defs/ResourceRoleId"
|
|
979
|
+
},
|
|
980
|
+
"executionId": {
|
|
981
|
+
"$ref": "#/$defs/ExecutionId"
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
},
|
|
954
987
|
"CreationContext": {
|
|
955
988
|
"identity": "RESOURCE-CreationContext",
|
|
956
989
|
"resourceTypeId": "TYPE-ResourceType",
|
|
@@ -974,19 +1007,7 @@
|
|
|
974
1007
|
],
|
|
975
1008
|
"properties": {
|
|
976
1009
|
"creationContext": {
|
|
977
|
-
"
|
|
978
|
-
"required": [
|
|
979
|
-
"resourceRoleId",
|
|
980
|
-
"executionId"
|
|
981
|
-
],
|
|
982
|
-
"properties": {
|
|
983
|
-
"resourceRoleId": {
|
|
984
|
-
"$ref": "#/$defs/ResourceRoleId"
|
|
985
|
-
},
|
|
986
|
-
"executionId": {
|
|
987
|
-
"$ref": "#/$defs/ExecutionId"
|
|
988
|
-
}
|
|
989
|
-
}
|
|
1010
|
+
"$ref": "#/$defs/CreationContextValue"
|
|
990
1011
|
}
|
|
991
1012
|
}
|
|
992
1013
|
}
|
|
@@ -65,19 +65,7 @@
|
|
|
65
65
|
"type": "object",
|
|
66
66
|
"properties": {
|
|
67
67
|
"creationContext": {
|
|
68
|
-
"
|
|
69
|
-
"properties": {
|
|
70
|
-
"executionId": {
|
|
71
|
-
"$ref": "#/$defs/ExecutionId"
|
|
72
|
-
},
|
|
73
|
-
"resourceRoleId": {
|
|
74
|
-
"$ref": "#/$defs/ResourceRoleId"
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
"required": [
|
|
78
|
-
"resourceRoleId",
|
|
79
|
-
"executionId"
|
|
80
|
-
]
|
|
68
|
+
"$ref": "#/$defs/CreationContextValue"
|
|
81
69
|
}
|
|
82
70
|
},
|
|
83
71
|
"required": [
|
|
@@ -85,6 +73,23 @@
|
|
|
85
73
|
],
|
|
86
74
|
"$anchor": "CreationContext"
|
|
87
75
|
},
|
|
76
|
+
"CreationContextValue": {
|
|
77
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
78
|
+
"type": "object",
|
|
79
|
+
"properties": {
|
|
80
|
+
"executionId": {
|
|
81
|
+
"$ref": "#/$defs/ExecutionId"
|
|
82
|
+
},
|
|
83
|
+
"resourceRoleId": {
|
|
84
|
+
"$ref": "#/$defs/ResourceRoleId"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"required": [
|
|
88
|
+
"resourceRoleId",
|
|
89
|
+
"executionId"
|
|
90
|
+
],
|
|
91
|
+
"$anchor": "CreationContextValue"
|
|
92
|
+
},
|
|
88
93
|
"Description": {
|
|
89
94
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
90
95
|
"type": "object",
|
|
@@ -1146,5 +1151,5 @@
|
|
|
1146
1151
|
"pattern": "^WORKSTEP-.+$"
|
|
1147
1152
|
}
|
|
1148
1153
|
},
|
|
1149
|
-
"$comment": "This schema defines all genesis schemas used throughout the Toolproof ecosystem. The genesis schemas themselves are defined in $defs.<ResourceType>.extractionSchema. The build process (via extractSchemas.js) extracts these schemas and writes them to a separate file (
|
|
1154
|
+
"$comment": "This schema defines all genesis schemas used throughout the Toolproof ecosystem. The genesis schemas themselves are defined in $defs.<ResourceType>.extractionSchema. The build process (via extractSchemas.js) extracts these schemas and writes them to a separate file (genesis/generated/schemas/Genesis.json). The reason for this indirection is to have all these schema envelopes validate positively against the schema at $defs/ResourceType, effectively making them ResourceTypes, which are first-class citizens in the Toolproof ecosystem."
|
|
1150
1155
|
}
|
|
@@ -491,19 +491,7 @@
|
|
|
491
491
|
"type": "object",
|
|
492
492
|
"properties": {
|
|
493
493
|
"creationContext": {
|
|
494
|
-
"
|
|
495
|
-
"properties": {
|
|
496
|
-
"executionId": {
|
|
497
|
-
"$ref": "#/$defs/ExecutionId"
|
|
498
|
-
},
|
|
499
|
-
"resourceRoleId": {
|
|
500
|
-
"$ref": "#/$defs/ResourceRoleId"
|
|
501
|
-
}
|
|
502
|
-
},
|
|
503
|
-
"required": [
|
|
504
|
-
"resourceRoleId",
|
|
505
|
-
"executionId"
|
|
506
|
-
]
|
|
494
|
+
"$ref": "#/$defs/CreationContextValue"
|
|
507
495
|
}
|
|
508
496
|
},
|
|
509
497
|
"required": [
|
|
@@ -606,6 +594,23 @@
|
|
|
606
594
|
"$anchor": "ResourceTypeId",
|
|
607
595
|
"pattern": "^TYPE-.+$"
|
|
608
596
|
},
|
|
597
|
+
"CreationContextValue": {
|
|
598
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
599
|
+
"type": "object",
|
|
600
|
+
"properties": {
|
|
601
|
+
"executionId": {
|
|
602
|
+
"$ref": "#/$defs/ExecutionId"
|
|
603
|
+
},
|
|
604
|
+
"resourceRoleId": {
|
|
605
|
+
"$ref": "#/$defs/ResourceRoleId"
|
|
606
|
+
}
|
|
607
|
+
},
|
|
608
|
+
"required": [
|
|
609
|
+
"resourceRoleId",
|
|
610
|
+
"executionId"
|
|
611
|
+
],
|
|
612
|
+
"$anchor": "CreationContextValue"
|
|
613
|
+
},
|
|
609
614
|
"Timestamp": {
|
|
610
615
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
611
616
|
"type": "object",
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"description": "dummy-description",
|
|
5
5
|
"resourceFormatId": "FORMAT-ApplicationJson",
|
|
6
6
|
"extractionSchema": {
|
|
7
|
-
"$comment": "This schema defines all genesis schemas used throughout the Toolproof ecosystem. The genesis schemas themselves are defined in $defs.<ResourceType>.extractionSchema. The build process (via extractSchemas.js) extracts these schemas and writes them to a separate file (
|
|
7
|
+
"$comment": "This schema defines all genesis schemas used throughout the Toolproof ecosystem. The genesis schemas themselves are defined in $defs.<ResourceType>.extractionSchema. The build process (via extractSchemas.js) extracts these schemas and writes them to a separate file (genesis/generated/schemas/Genesis.json). The reason for this indirection is to have all these schema envelopes validate positively against the schema at $defs/ResourceType, effectively making them ResourceTypes, which are first-class citizens in the Toolproof ecosystem.",
|
|
8
8
|
"$id": "https://schemas.toolproof.com/v0/Genesis.json",
|
|
9
9
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
10
10
|
"$defs": {
|
|
@@ -699,6 +699,29 @@
|
|
|
699
699
|
}
|
|
700
700
|
}
|
|
701
701
|
},
|
|
702
|
+
"CreationContextValue": {
|
|
703
|
+
"identity": "TYPE-CreationContextValue",
|
|
704
|
+
"name": "CreationContextValue",
|
|
705
|
+
"description": "dummy-description",
|
|
706
|
+
"resourceFormatId": "FORMAT-ApplicationJson",
|
|
707
|
+
"extractionSchema": {
|
|
708
|
+
"$anchor": "CreationContextValue",
|
|
709
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
710
|
+
"type": "object",
|
|
711
|
+
"required": [
|
|
712
|
+
"resourceRoleId",
|
|
713
|
+
"executionId"
|
|
714
|
+
],
|
|
715
|
+
"properties": {
|
|
716
|
+
"resourceRoleId": {
|
|
717
|
+
"$ref": "#ResourceRoleId"
|
|
718
|
+
},
|
|
719
|
+
"executionId": {
|
|
720
|
+
"$ref": "#ExecutionId"
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
},
|
|
702
725
|
"CreationContext": {
|
|
703
726
|
"identity": "TYPE-CreationContext",
|
|
704
727
|
"name": "CreationContext",
|
|
@@ -713,19 +736,7 @@
|
|
|
713
736
|
],
|
|
714
737
|
"properties": {
|
|
715
738
|
"creationContext": {
|
|
716
|
-
"
|
|
717
|
-
"required": [
|
|
718
|
-
"resourceRoleId",
|
|
719
|
-
"executionId"
|
|
720
|
-
],
|
|
721
|
-
"properties": {
|
|
722
|
-
"resourceRoleId": {
|
|
723
|
-
"$ref": "#ResourceRoleId"
|
|
724
|
-
},
|
|
725
|
-
"executionId": {
|
|
726
|
-
"$ref": "#ExecutionId"
|
|
727
|
-
}
|
|
728
|
-
}
|
|
739
|
+
"$ref": "#CreationContextValue"
|
|
729
740
|
}
|
|
730
741
|
}
|
|
731
742
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export { default as JobSchema } from './genesis/generated/schemas/Job.js';
|
|
|
4
4
|
export type { Resource_ResourceFormat as Resource_ResourceFormatJson } from './_lib/types/Resource_ResourceFormat.js';
|
|
5
5
|
export type { Resource_ResourceType as Resource_ResourceTypeJson } from './_lib/types/Resource_ResourceType.js';
|
|
6
6
|
export type { Resource_Job as Resource_JobJson } from './_lib/types/Resource_Job.js';
|
|
7
|
-
export type { Documented as DocumentedJson, ResourceFormatId as ResourceFormatIdJson, ResourceFormat as ResourceFormatJson, ExtractionSchema as ExtractionSchemaJson, ExtractionSchemaValue as ExtractionSchemaValueJson, IdentityProp as IdentityPropJson, MeritProp as MeritPropJson, ResourceTypeId as ResourceTypeIdJson, ResourceType as ResourceTypeJson, ResourceRoleId as ResourceRoleIdJson, ResourceRoleValue as ResourceRoleValueJson, ExecutionId as ExecutionIdJson, Execution as ExecutionJson, ConditionalWrapper as ConditionalWrapperJson, RoleMap as RoleMapJson, RolesOuter as RolesOuterJson, RoleBindingMap as RoleBindingMapJson, RoleBindingsOuter as RoleBindingsOuterJson, ResourceId as ResourceIdJson, WorkStepId as WorkStepIdJson, BranchStepId as BranchStepIdJson, WhileStepId as WhileStepIdJson, ForStepId as ForStepIdJson, WorkStep as WorkStepJson, BranchStep as BranchStepJson, WhileStep as WhileStepJson, ForStep as ForStepJson, Step as StepJson, ResourcePotentialInput as ResourcePotentialInputJson, ResourcePotentialOutput as ResourcePotentialOutputJson, ResourceMetaBase as ResourceMetaJson, // ATTENTION: type not generated for ResourceMeta
|
|
7
|
+
export type { Documented as DocumentedJson, ResourceFormatId as ResourceFormatIdJson, ResourceFormat as ResourceFormatJson, ExtractionSchema as ExtractionSchemaJson, ExtractionSchemaValue as ExtractionSchemaValueJson, IdentityProp as IdentityPropJson, MeritProp as MeritPropJson, ResourceTypeId as ResourceTypeIdJson, ResourceType as ResourceTypeJson, ResourceRoleId as ResourceRoleIdJson, ResourceRoleValue as ResourceRoleValueJson, ExecutionId as ExecutionIdJson, Execution as ExecutionJson, ConditionalWrapper as ConditionalWrapperJson, RoleMap as RoleMapJson, RolesOuter as RolesOuterJson, RoleBindingMap as RoleBindingMapJson, RoleBindingsOuter as RoleBindingsOuterJson, ResourceId as ResourceIdJson, WorkStepId as WorkStepIdJson, BranchStepId as BranchStepIdJson, WhileStepId as WhileStepIdJson, ForStepId as ForStepIdJson, WorkStep as WorkStepJson, BranchStep as BranchStepJson, WhileStep as WhileStepJson, ForStep as ForStepJson, Step as StepJson, CreationContextValue as CreationContextValueJson, ResourceMissing as ResourceMissingJson, ResourcePotentialInput as ResourcePotentialInputJson, ResourcePotentialOutput as ResourcePotentialOutputJson, ResourceMetaBase as ResourceMetaJson, // ATTENTION: type not generated for ResourceMeta
|
|
8
8
|
Resource as ResourceJson, StrategyState as StrategyStateJson, StrategyStateValue as StrategyStateValueJson, StatelessStrategyId as StatelessStrategyIdJson, StatelessStrategy as StatelessStrategyJson, StatefulStrategyId as StatefulStrategyIdJson, StatefulStrategy as StatefulStrategyJson, JobId as JobIdJson, Job as JobJson, JsonValue as JsonValueJson, } from './_lib/types/types.js';
|
|
9
9
|
export { unsafeBrand, asResourceTypeId, asResourceRoleId, asExecutionId, asResourceId, asWorkStepId, asBranchStepId, asForStepId, asResourceFormatId, asWhileStepId, asStatelessStrategyId, asStatefulStrategyId, asResourceTypeIds, asResourceRoleIds, asExecutionIds, asResourceIds, asWorkStepIds, asBranchStepIds, asForStepIds, asResourceFormatIds, asWhileStepIds, asStatelessStrategyIds, asStatefulStrategyIds, } from './scripts/brandFactories.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import { getConfig } from "./_lib/config.js";
|
|
5
|
+
function stripSurroundingQuotes(v) {
|
|
6
|
+
if ((v.startsWith("'") && v.endsWith("'")) || (v.startsWith('"') && v.endsWith('"'))) {
|
|
7
|
+
return v.slice(1, -1);
|
|
8
|
+
}
|
|
9
|
+
return v;
|
|
10
|
+
}
|
|
11
|
+
function parseArgs() {
|
|
12
|
+
const config = getConfig();
|
|
13
|
+
const argv = process.argv.slice(2);
|
|
14
|
+
let storyInPath = "";
|
|
15
|
+
let storyOutPath = "";
|
|
16
|
+
let schemasPath = "";
|
|
17
|
+
let resourceTypesPath = "";
|
|
18
|
+
for (let i = 0; i < argv.length; i++) {
|
|
19
|
+
const a = argv[i];
|
|
20
|
+
if ((a === "--in" || a === "--storyIn") && i + 1 < argv.length)
|
|
21
|
+
storyInPath = stripSurroundingQuotes(argv[++i]);
|
|
22
|
+
else if ((a === "--out" || a === "--storyOut") && i + 1 < argv.length)
|
|
23
|
+
storyOutPath = stripSurroundingQuotes(argv[++i]);
|
|
24
|
+
else if ((a === "--schemas" || a === "--schemasPath") && i + 1 < argv.length)
|
|
25
|
+
schemasPath = stripSurroundingQuotes(argv[++i]);
|
|
26
|
+
else if ((a === "--resourceTypes" || a === "--resourceTypesPath") && i + 1 < argv.length)
|
|
27
|
+
resourceTypesPath = stripSurroundingQuotes(argv[++i]);
|
|
28
|
+
}
|
|
29
|
+
// Defaults
|
|
30
|
+
if (!storyInPath)
|
|
31
|
+
storyInPath = path.join(config.getRoot(), "src/genesis/GenesisStory.json");
|
|
32
|
+
if (!storyOutPath)
|
|
33
|
+
storyOutPath = path.join(config.getRoot(), "src/genesis/generated/GenesisStory.json");
|
|
34
|
+
// Extracted schemas (raw JSON Schemas)
|
|
35
|
+
if (!schemasPath)
|
|
36
|
+
schemasPath = config.getOutputPath(config.getSourceFile());
|
|
37
|
+
// ResourceType envelopes (ToolProof resources)
|
|
38
|
+
if (!resourceTypesPath)
|
|
39
|
+
resourceTypesPath = config.getSourcePath();
|
|
40
|
+
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
|
|
41
|
+
// Resolve relative paths against config root; then fallback relative to script dir
|
|
42
|
+
const resolveWithFallback = (p) => {
|
|
43
|
+
const wasRelative = !path.isAbsolute(p);
|
|
44
|
+
let candidate = p;
|
|
45
|
+
if (wasRelative)
|
|
46
|
+
candidate = path.join(config.getRoot(), p);
|
|
47
|
+
if (fs.existsSync(candidate))
|
|
48
|
+
return candidate;
|
|
49
|
+
if (wasRelative) {
|
|
50
|
+
const alt = path.resolve(scriptDir, p);
|
|
51
|
+
if (fs.existsSync(alt))
|
|
52
|
+
return alt;
|
|
53
|
+
}
|
|
54
|
+
return candidate;
|
|
55
|
+
};
|
|
56
|
+
storyInPath = resolveWithFallback(storyInPath);
|
|
57
|
+
storyOutPath = !path.isAbsolute(storyOutPath) ? path.join(config.getRoot(), storyOutPath) : storyOutPath;
|
|
58
|
+
schemasPath = resolveWithFallback(schemasPath);
|
|
59
|
+
resourceTypesPath = resolveWithFallback(resourceTypesPath);
|
|
60
|
+
return { storyInPath, storyOutPath, schemasPath, resourceTypesPath };
|
|
61
|
+
}
|
|
62
|
+
function deepClone(v) {
|
|
63
|
+
return JSON.parse(JSON.stringify(v));
|
|
64
|
+
}
|
|
65
|
+
function isRefWrapper(node) {
|
|
66
|
+
return (!!node &&
|
|
67
|
+
typeof node === "object" &&
|
|
68
|
+
!Array.isArray(node) &&
|
|
69
|
+
node.$ref &&
|
|
70
|
+
typeof node.$ref === "string" &&
|
|
71
|
+
Object.keys(node).length === 1);
|
|
72
|
+
}
|
|
73
|
+
function refToDefName(ref) {
|
|
74
|
+
let r = stripSurroundingQuotes(ref.trim());
|
|
75
|
+
// Support URL#anchor or URL#/$defs/Name
|
|
76
|
+
const hashIndex = r.indexOf("#");
|
|
77
|
+
if (hashIndex >= 0)
|
|
78
|
+
r = r.slice(hashIndex + 1);
|
|
79
|
+
// r could now be "Name" or "/$defs/Name" or "$defs/Name"
|
|
80
|
+
if (r.startsWith("/"))
|
|
81
|
+
r = r.slice(1);
|
|
82
|
+
if (r.startsWith("$defs/"))
|
|
83
|
+
r = r.slice("$defs/".length);
|
|
84
|
+
// If it's still a JSON pointer-like path, support only '$defs/<Name>'
|
|
85
|
+
if (r.includes("/")) {
|
|
86
|
+
const parts = r.split("/").filter(Boolean);
|
|
87
|
+
if (parts.length === 2 && parts[0] === "$defs")
|
|
88
|
+
return parts[1];
|
|
89
|
+
throw new Error(`Unsupported $ref format in GenesisStory: '${ref}'`);
|
|
90
|
+
}
|
|
91
|
+
return r;
|
|
92
|
+
}
|
|
93
|
+
function applyRefAliases(defName) {
|
|
94
|
+
// Backwards-compat / naming aliases (story names -> canonical def names)
|
|
95
|
+
const aliasMap = {
|
|
96
|
+
ExtractedSchemaValue: "ExtractionSchemaValue",
|
|
97
|
+
ExtractedSchema: "ExtractionSchema",
|
|
98
|
+
};
|
|
99
|
+
return defName in aliasMap ? aliasMap[defName] : defName;
|
|
100
|
+
}
|
|
101
|
+
function resolveRawSchemaDef(extractedSchemas, defName) {
|
|
102
|
+
defName = applyRefAliases(defName);
|
|
103
|
+
const defs = extractedSchemas?.$defs;
|
|
104
|
+
if (!defs || typeof defs !== "object") {
|
|
105
|
+
throw new Error("Extracted schemas file must contain a top-level $defs object");
|
|
106
|
+
}
|
|
107
|
+
if (defName in defs)
|
|
108
|
+
return defs[defName];
|
|
109
|
+
for (const v of Object.values(defs)) {
|
|
110
|
+
if (v && typeof v === "object" && v.$anchor === defName)
|
|
111
|
+
return v;
|
|
112
|
+
}
|
|
113
|
+
const available = Object.keys(defs).slice(0, 25);
|
|
114
|
+
throw new Error(`Could not resolve raw schema for ref '${defName}' from extracted schemas.$defs. ` +
|
|
115
|
+
`Example available keys: ${available.join(", ")}${Object.keys(defs).length > 25 ? ", ..." : ""}`);
|
|
116
|
+
}
|
|
117
|
+
function resolveResourceTypeEnvelope(resourceTypesDoc, defName) {
|
|
118
|
+
defName = applyRefAliases(defName);
|
|
119
|
+
const defs = resourceTypesDoc?.extractionSchema?.$defs;
|
|
120
|
+
if (!defs || typeof defs !== "object") {
|
|
121
|
+
throw new Error("ResourceTypes file must contain extractionSchema.$defs");
|
|
122
|
+
}
|
|
123
|
+
if (defName in defs)
|
|
124
|
+
return defs[defName];
|
|
125
|
+
// Fallback: match by envelope name or inner extractionSchema $anchor
|
|
126
|
+
for (const v of Object.values(defs)) {
|
|
127
|
+
if (!v || typeof v !== "object")
|
|
128
|
+
continue;
|
|
129
|
+
if (v.name === defName)
|
|
130
|
+
return v;
|
|
131
|
+
const innerAnchor = v.extractionSchema?.$anchor;
|
|
132
|
+
if (innerAnchor === defName)
|
|
133
|
+
return v;
|
|
134
|
+
}
|
|
135
|
+
const available = Object.keys(defs).slice(0, 25);
|
|
136
|
+
throw new Error(`Could not resolve ResourceType envelope for ref '${defName}' from resourceTypes.extractionSchema.$defs. ` +
|
|
137
|
+
`Example available keys: ${available.join(", ")}${Object.keys(defs).length > 25 ? ", ..." : ""}`);
|
|
138
|
+
}
|
|
139
|
+
function inlineRefs(node, resolve) {
|
|
140
|
+
if (isRefWrapper(node)) {
|
|
141
|
+
const defName = refToDefName(node.$ref);
|
|
142
|
+
const resolved = resolve(defName);
|
|
143
|
+
return deepClone(resolved);
|
|
144
|
+
}
|
|
145
|
+
if (Array.isArray(node)) {
|
|
146
|
+
return node.map((v) => inlineRefs(v, resolve));
|
|
147
|
+
}
|
|
148
|
+
if (node && typeof node === "object") {
|
|
149
|
+
const out = {};
|
|
150
|
+
for (const [k, v] of Object.entries(node)) {
|
|
151
|
+
out[k] = inlineRefs(v, resolve);
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
return node;
|
|
156
|
+
}
|
|
157
|
+
function main() {
|
|
158
|
+
const { storyInPath, storyOutPath, schemasPath, resourceTypesPath } = parseArgs();
|
|
159
|
+
if (!fs.existsSync(storyInPath))
|
|
160
|
+
throw new Error(`Story file not found: ${storyInPath}`);
|
|
161
|
+
if (!fs.existsSync(schemasPath))
|
|
162
|
+
throw new Error(`Schemas file not found: ${schemasPath}`);
|
|
163
|
+
if (!fs.existsSync(resourceTypesPath))
|
|
164
|
+
throw new Error(`ResourceTypes file not found: ${resourceTypesPath}`);
|
|
165
|
+
const storyRaw = fs.readFileSync(storyInPath, "utf8");
|
|
166
|
+
const story = JSON.parse(storyRaw);
|
|
167
|
+
const schemasRaw = fs.readFileSync(schemasPath, "utf8");
|
|
168
|
+
const extractedSchemas = JSON.parse(schemasRaw);
|
|
169
|
+
const resourceTypesRaw = fs.readFileSync(resourceTypesPath, "utf8");
|
|
170
|
+
const resourceTypesDoc = JSON.parse(resourceTypesRaw);
|
|
171
|
+
const resolved = resolveStoryDocument(story, extractedSchemas, resourceTypesDoc);
|
|
172
|
+
fs.mkdirSync(path.dirname(storyOutPath), { recursive: true });
|
|
173
|
+
fs.writeFileSync(storyOutPath, JSON.stringify(resolved, null, 4) + "\n", "utf8");
|
|
174
|
+
console.log(`Wrote resolved GenesisStory to ${storyOutPath}`);
|
|
175
|
+
}
|
|
176
|
+
function resolveStoryDocument(storyDoc, extractedSchemas, resourceTypesDoc) {
|
|
177
|
+
// Special handling: switch ref source after a marker in the GenesisStory array.
|
|
178
|
+
if (storyDoc &&
|
|
179
|
+
typeof storyDoc === "object" &&
|
|
180
|
+
!Array.isArray(storyDoc) &&
|
|
181
|
+
Array.isArray(storyDoc.GenesisStory)) {
|
|
182
|
+
const items = storyDoc.GenesisStory;
|
|
183
|
+
let inResourceTypeSpace = false;
|
|
184
|
+
const resolvedItems = items.map((item) => {
|
|
185
|
+
if (typeof item === "string" && item.trim() === "!!!!!") {
|
|
186
|
+
inResourceTypeSpace = true;
|
|
187
|
+
return item;
|
|
188
|
+
}
|
|
189
|
+
const resolver = inResourceTypeSpace
|
|
190
|
+
? (name) => resolveResourceTypeEnvelope(resourceTypesDoc, name)
|
|
191
|
+
: (name) => resolveRawSchemaDef(extractedSchemas, name);
|
|
192
|
+
return inlineRefs(item, resolver);
|
|
193
|
+
});
|
|
194
|
+
return { ...storyDoc, GenesisStory: resolvedItems };
|
|
195
|
+
}
|
|
196
|
+
// Fallback: if it's not a GenesisStory doc, just resolve using raw schemas.
|
|
197
|
+
return inlineRefs(storyDoc, (name) => resolveRawSchemaDef(extractedSchemas, name));
|
|
198
|
+
}
|
|
199
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toolproof-npm/schema",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.44",
|
|
4
4
|
"description": "JSON schemas and TypeScript types for ToolProof",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"toolproof",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"rewriteAnchors": "node ./dist/scripts/rewriteAnchors.js",
|
|
48
48
|
"extractSchemas": "node ./dist/scripts/extractSchemas.js",
|
|
49
49
|
"extractSubschema": "node ./dist/scripts/extractSubschemaWithDefs.js",
|
|
50
|
+
"resolveRefsInGenesisStory": "pnpm run build:scripts && node ./dist/scripts/resolveRefsInGenesisStory.js",
|
|
50
51
|
"generateTypes": "node ./dist/scripts/generateTypes.js",
|
|
51
52
|
"generateResourceTypeType": "node ./dist/scripts/generateResourceTypeType.js",
|
|
52
53
|
"generateResourceEnvelopes": "node ./dist/scripts/generateResourceEnvelopes.js",
|