@toolproof-core/schema 1.0.2 → 1.0.4
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/normalized/Genesis.d.ts +2 -0
- package/dist/generated/normalized/Genesis.js +2 -0
- package/dist/generated/normalized/Genesis.json +2008 -0
- package/dist/generated/resources/Genesis.d.ts +2 -0
- package/dist/generated/resources/Genesis.js +2 -0
- package/dist/generated/resources/Genesis.json +2907 -0
- package/dist/generated/schemas/Genesis.d.ts +2 -0
- package/dist/generated/schemas/Genesis.js +2 -0
- package/dist/generated/schemas/Genesis.json +1466 -0
- package/dist/generated/schemas/standalone/Goal.d.ts +2 -0
- package/dist/generated/schemas/standalone/Goal.js +2 -0
- package/dist/generated/schemas/standalone/Goal.json +86 -0
- package/dist/generated/schemas/standalone/Job.d.ts +2 -0
- package/dist/generated/schemas/standalone/Job.js +2 -0
- package/dist/generated/schemas/standalone/Job.json +236 -0
- package/dist/generated/schemas/standalone/RawStrategy.d.ts +2 -0
- package/dist/generated/schemas/standalone/RawStrategy.js +2 -0
- package/dist/generated/schemas/standalone/RawStrategy.json +650 -0
- package/dist/generated/schemas/standalone/ResourceType.d.ts +2 -0
- package/dist/generated/schemas/standalone/ResourceType.js +2 -0
- package/dist/generated/schemas/standalone/ResourceType.json +140 -0
- package/dist/generated/schemas/standalone/RunnableStrategy.d.ts +2 -0
- package/dist/generated/schemas/standalone/RunnableStrategy.js +2 -0
- package/dist/generated/schemas/standalone/RunnableStrategy.json +720 -0
- package/dist/generated/schemas/standalone/StrategyRun.d.ts +2 -0
- package/dist/generated/schemas/standalone/StrategyRun.js +2 -0
- package/dist/generated/schemas/standalone/StrategyRun.json +1002 -0
- package/dist/generated/{types → typesTS}/standalone/Resource_Genesis.d.ts +1 -1
- package/{src/generated/types → dist/generated/typesTS}/standalone/Resource_Job.d.ts +1 -1
- package/{src/generated/types → dist/generated/typesTS}/standalone/Resource_RawStrategy.d.ts +1 -1
- package/{src/generated/types → dist/generated/typesTS}/standalone/Resource_ResourceType.d.ts +1 -1
- package/dist/generated/{types → typesTS}/standalone/Resource_RunnableStrategy.d.ts +1 -1
- package/dist/generated/typesTS/typesTS.d.ts +745 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +5 -0
- package/dist/scripts/_lib/config.d.ts +10 -10
- package/dist/scripts/_lib/config.js +23 -23
- package/dist/scripts/extractSchemasFromResourceTypeShells.js +109 -103
- package/dist/scripts/generateDependencies.js +15 -14
- package/dist/scripts/generateSchemaShims.js +76 -84
- package/dist/scripts/generateStandaloneSchema.js +47 -37
- package/dist/scripts/generateStandaloneTypeTS.js +108 -0
- package/dist/scripts/generateTypesTS.js +430 -0
- package/dist/scripts/normalizeAnchorsToPointers.js +37 -30
- package/dist/scripts/wrapResourceTypesWithResourceShells.js +14 -16
- package/package.json +11 -12
- package/src/Genesis.json +2007 -1999
- package/src/generated/{dependencyMap.json → dependencies/dependencyMap.json} +7 -6
- package/src/generated/normalized/Genesis.json +17 -9
- package/src/generated/resources/Genesis.json +19 -11
- package/src/generated/schemas/Genesis.json +15 -7
- package/src/generated/schemas/standalone/RawStrategy.json +15 -7
- package/src/generated/schemas/standalone/RunnableStrategy.json +15 -7
- package/src/generated/schemas/standalone/StrategyRun.json +15 -7
- package/src/generated/{types → typesTS}/standalone/Resource_Genesis.d.ts +1 -1
- package/{dist/generated/types → src/generated/typesTS}/standalone/Resource_Job.d.ts +1 -1
- package/{dist/generated/types → src/generated/typesTS}/standalone/Resource_RawStrategy.d.ts +1 -1
- package/{dist/generated/types → src/generated/typesTS}/standalone/Resource_ResourceType.d.ts +1 -1
- package/src/generated/{types → typesTS}/standalone/Resource_RunnableStrategy.d.ts +1 -1
- package/src/generated/typesTS/typesTS.d.ts +745 -0
- package/src/index.ts +67 -1
- package/src/scripts/_lib/config.ts +205 -205
- package/src/scripts/extractSchemasFromResourceTypeShells.ts +261 -218
- package/src/scripts/generateDependencies.ts +121 -120
- package/src/scripts/generateSchemaShims.ts +127 -135
- package/src/scripts/generateStandaloneSchema.ts +185 -175
- package/src/scripts/generateStandaloneTypeTS.ts +127 -0
- package/src/scripts/generateTypesTS.ts +532 -0
- package/src/scripts/normalizeAnchorsToPointers.ts +115 -123
- package/src/scripts/wrapResourceTypesWithResourceShells.ts +82 -84
- package/dist/generated/types/types.d.ts +0 -1723
- package/dist/scripts/generateStandaloneType.js +0 -102
- package/dist/scripts/generateTypes.js +0 -550
- package/src/generated/types/types.d.ts +0 -1723
- package/src/scripts/generateStandaloneType.ts +0 -119
- package/src/scripts/generateTypes.ts +0 -615
- /package/dist/generated/{types → typesTS}/standalone/Resource_Genesis.js +0 -0
- /package/dist/generated/{types → typesTS}/standalone/Resource_Job.js +0 -0
- /package/dist/generated/{types → typesTS}/standalone/Resource_RawStrategy.js +0 -0
- /package/dist/generated/{types → typesTS}/standalone/Resource_ResourceType.js +0 -0
- /package/dist/generated/{types → typesTS}/standalone/Resource_RunnableStrategy.js +0 -0
- /package/dist/generated/{types/types.js → typesTS/typesTS.js} +0 -0
- /package/dist/scripts/{generateStandaloneType.d.ts → generateStandaloneTypeTS.d.ts} +0 -0
- /package/dist/scripts/{generateTypes.d.ts → generateTypesTS.d.ts} +0 -0
- /package/src/generated/{types → typesTS}/standalone/Resource_Genesis.js +0 -0
- /package/src/generated/{types → typesTS}/standalone/Resource_Job.js +0 -0
- /package/src/generated/{types → typesTS}/standalone/Resource_RawStrategy.js +0 -0
- /package/src/generated/{types → typesTS}/standalone/Resource_ResourceType.js +0 -0
- /package/src/generated/{types → typesTS}/standalone/Resource_RunnableStrategy.js +0 -0
- /package/src/generated/{types/types.js → typesTS/typesTS.js} +0 -0
package/src/index.ts
CHANGED
|
@@ -1 +1,67 @@
|
|
|
1
|
-
export
|
|
1
|
+
// Re-export JSON schemas via .ts shims to avoid .json re-exports in declarations
|
|
2
|
+
export { default as SchemaGenesis } from './generated/schemas/Genesis.js';
|
|
3
|
+
export { default as SchemaJob } from './generated/schemas/standalone/Job.js';
|
|
4
|
+
export { default as SchemaStrategyRun } from './generated/schemas/standalone/StrategyRun.js';
|
|
5
|
+
export { default as ResourceTypeGenesis } from './generated/resources/Genesis.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export type {
|
|
9
|
+
Resource_Genesis as Resource_GenesisJson
|
|
10
|
+
} from './generated/typesTS/standalone/Resource_Genesis.js';
|
|
11
|
+
export type {
|
|
12
|
+
Resource_ResourceType as Resource_ResourceTypeJson
|
|
13
|
+
} from './generated/typesTS/standalone/Resource_ResourceType.js';
|
|
14
|
+
export type {
|
|
15
|
+
Resource_Job as Resource_JobJson
|
|
16
|
+
} from './generated/typesTS/standalone/Resource_Job.js';
|
|
17
|
+
export type {
|
|
18
|
+
Resource_RawStrategy as Resource_RawStrategyJson
|
|
19
|
+
} from './generated/typesTS/standalone/Resource_RawStrategy.js';
|
|
20
|
+
export type {
|
|
21
|
+
Resource_RunnableStrategy as Resource_RunnableStrategyJson
|
|
22
|
+
} from './generated/typesTS/standalone/Resource_RunnableStrategy.js';
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export type {
|
|
26
|
+
DocumentationFacet as DocumentationFacetJson,
|
|
27
|
+
NucleusFacet as NucleusFacetJson,
|
|
28
|
+
ResourceTypeIdentity as ResourceTypeIdentityJson,
|
|
29
|
+
ResourceType as ResourceTypeJson,
|
|
30
|
+
ResourceRoleIdentity as ResourceRoleIdentityJson,
|
|
31
|
+
ResourceRoleValue as ResourceRoleValueJson,
|
|
32
|
+
Conditional as ConditionalJson,
|
|
33
|
+
RoleMap as RoleMapJson,
|
|
34
|
+
Roles as RolesJson,
|
|
35
|
+
RoleBindings as RoleBindingsJson,
|
|
36
|
+
ResourceIdentity as ResourceIdentityJson,
|
|
37
|
+
JobStepIdentity as JobStepIdentityJson,
|
|
38
|
+
BranchStepIdentity as BranchStepIdentityJson,
|
|
39
|
+
WhileStepIdentity as WhileStepIdentityJson,
|
|
40
|
+
ForStepIdentity as ForStepIdentityJson,
|
|
41
|
+
JobStep as JobStepJson,
|
|
42
|
+
BranchStep as BranchStepJson,
|
|
43
|
+
WhileStep as WhileStepJson,
|
|
44
|
+
ForStep as ForStepJson,
|
|
45
|
+
StepKind as StepKindJson,
|
|
46
|
+
StepIdentity as StepIdentityJson,
|
|
47
|
+
Step as StepJson,
|
|
48
|
+
CreationContext as CreationContextJson,
|
|
49
|
+
ResourceMissing as ResourceMissingJson,
|
|
50
|
+
Resource as ResourceJson,
|
|
51
|
+
StrategyState as StrategyStateJson,
|
|
52
|
+
StepsFacet as StepsFacetJson,
|
|
53
|
+
RawStrategy as RawStrategyJson,
|
|
54
|
+
RunnableStrategyIdentity as RunnableStrategyIdentityJson,
|
|
55
|
+
RunnableStrategyStatus as RunnableStrategyStatusJson,
|
|
56
|
+
RunnableStrategy as RunnableStrategyJson,
|
|
57
|
+
RunnableStrategyUpdate as RunnableStrategyUpdateJson,
|
|
58
|
+
Domain as DomainJson,
|
|
59
|
+
JobIdentity as JobIdentityJson,
|
|
60
|
+
Job as JobJson,
|
|
61
|
+
JsonData as JsonDataJson,
|
|
62
|
+
StrategyThreadIdentity as StrategyThreadIdentityJson,
|
|
63
|
+
StrategyThreadMap as StrategyThreadMapJson,
|
|
64
|
+
JobStepSocket as JobStepSocketJson,
|
|
65
|
+
Timestamp as TimestampJson,
|
|
66
|
+
Goal as GoalJson,
|
|
67
|
+
} from './generated/typesTS/typesTS.js';
|
|
@@ -1,205 +1,205 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration for schema generation scripts
|
|
3
|
-
* All paths are configurable via environment variables
|
|
4
|
-
* Provides sensible defaults for standard project structure
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import path from 'path';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Get environment variable with optional default
|
|
11
|
-
*/
|
|
12
|
-
function getEnv(name: string, defaultValue: string): string {
|
|
13
|
-
const value = process.env[name];
|
|
14
|
-
return value || defaultValue;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Schema configuration with required environment variables
|
|
19
|
-
*/
|
|
20
|
-
export class SchemaConfig {
|
|
21
|
-
// Base paths
|
|
22
|
-
private readonly root: string;
|
|
23
|
-
private readonly sourceDir: string;
|
|
24
|
-
private readonly sourceFile: string;
|
|
25
|
-
private readonly normalizedDir: string;
|
|
26
|
-
private readonly schemasDir: string;
|
|
27
|
-
private readonly resourcesDir: string;
|
|
28
|
-
private readonly dependencyMapPath: string;
|
|
29
|
-
private readonly
|
|
30
|
-
private readonly
|
|
31
|
-
|
|
32
|
-
// Schema metadata
|
|
33
|
-
private readonly baseUrl: string;
|
|
34
|
-
private readonly version: string;
|
|
35
|
-
|
|
36
|
-
constructor() {
|
|
37
|
-
// Environment variables with sensible defaults
|
|
38
|
-
this.root = getEnv('TP_SCHEMA_ROOT', process.cwd());
|
|
39
|
-
this.sourceDir = getEnv('TP_SCHEMA_SOURCE_DIR', 'src/');
|
|
40
|
-
this.sourceFile = getEnv('TP_SCHEMA_SOURCE_FILE', 'Genesis.json');
|
|
41
|
-
// Intermediate, generated artifact produced by normalizeAnchorsToPointers.
|
|
42
|
-
// This should NOT live next to the source-of-truth schemas.
|
|
43
|
-
this.normalizedDir = getEnv('TP_SCHEMA_NORMALIZED_DIR', 'src/generated/normalized');
|
|
44
|
-
this.schemasDir = getEnv('TP_SCHEMA_SCHEMAS_DIR', 'src/generated/schemas');
|
|
45
|
-
this.resourcesDir = getEnv('TP_SCHEMA_RESOURCES_DIR', 'src/generated/resources');
|
|
46
|
-
this.dependencyMapPath = getEnv('TP_SCHEMA_DEPENDENCY_MAP_PATH', 'src/generated/dependencyMap.json');
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
49
|
-
this.baseUrl = getEnv('TP_SCHEMA_BASE_URL', 'https://schemas.toolproof.com');
|
|
50
|
-
this.version = getEnv('TP_SCHEMA_VERSION', 'v0');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Path getters
|
|
54
|
-
getRoot(): string {
|
|
55
|
-
return this.root;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
getSourceDir(): string {
|
|
59
|
-
return path.isAbsolute(this.sourceDir)
|
|
60
|
-
? this.sourceDir
|
|
61
|
-
: path.join(this.root, this.sourceDir);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
getSourceFile(): string {
|
|
65
|
-
return this.sourceFile;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
getSourcePath(): string {
|
|
69
|
-
return path.join(this.getSourceDir(), this.sourceFile);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
getNormalizedDir(): string {
|
|
73
|
-
return path.isAbsolute(this.normalizedDir)
|
|
74
|
-
? this.normalizedDir
|
|
75
|
-
: path.join(this.root, this.normalizedDir);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
getNormalizedSourceFile(): string {
|
|
79
|
-
// We keep the same basename (Genesis.json) in the generated folder.
|
|
80
|
-
// The source-of-truth Genesis.json lives under `TP_SCHEMA_SOURCE_DIR`.
|
|
81
|
-
// The generated/normalized Genesis.json lives under `TP_SCHEMA_NORMALIZED_DIR`.
|
|
82
|
-
return this.sourceFile;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
getNormalizedSourcePath(): string {
|
|
86
|
-
return path.join(this.getNormalizedDir(), this.getNormalizedSourceFile());
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
getSchemasDir(): string {
|
|
90
|
-
return path.isAbsolute(this.schemasDir)
|
|
91
|
-
? this.schemasDir
|
|
92
|
-
: path.join(this.root, this.schemasDir);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
getSchemaPath(filename: string): string {
|
|
96
|
-
return path.join(this.getSchemasDir(), filename);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
getSchemasStandaloneDir(): string {
|
|
100
|
-
return path.join(this.getSchemasDir(), 'standalone');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
getSchemaStandalonePath(filename: string): string {
|
|
104
|
-
return path.join(this.getSchemasStandaloneDir(), filename);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return path.isAbsolute(this.
|
|
109
|
-
? this.
|
|
110
|
-
: path.join(this.root, this.
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return path.isAbsolute(this.
|
|
115
|
-
? this.
|
|
116
|
-
: path.join(this.root, this.
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return path.join(this.
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return path.join(this.
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return path.join(this.
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return path.join(this.
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return path.join(this.
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return path.join(this.
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
getResourcesDir(): string {
|
|
144
|
-
return path.isAbsolute(this.resourcesDir)
|
|
145
|
-
? this.resourcesDir
|
|
146
|
-
: path.join(this.root, this.resourcesDir);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
getDependencyMapPath(): string {
|
|
150
|
-
return path.isAbsolute(this.dependencyMapPath)
|
|
151
|
-
? this.dependencyMapPath
|
|
152
|
-
: path.join(this.root, this.dependencyMapPath);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Schema URL methods
|
|
156
|
-
getBaseUrl(): string {
|
|
157
|
-
return this.baseUrl;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
getVersion(): string {
|
|
161
|
-
return this.version;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
getSchemaId(schemaName: string): string {
|
|
165
|
-
return `${this.baseUrl}/${this.version}/${schemaName}.json`;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Check if a URL matches the configured schema base URL pattern
|
|
170
|
-
*/
|
|
171
|
-
isSchemaUrl(url: string): boolean {
|
|
172
|
-
const baseUrlPattern = this.baseUrl.replace('https://', 'https?://');
|
|
173
|
-
return new RegExp(`^${baseUrlPattern}/`, 'i').test(url);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Extract schema name from URL (removes base URL and version prefix)
|
|
178
|
-
*/
|
|
179
|
-
extractSchemaName(url: string): string {
|
|
180
|
-
// Remove base URL
|
|
181
|
-
let name = url.replace(new RegExp(`^${this.baseUrl}/`, 'i'), '');
|
|
182
|
-
|
|
183
|
-
// Remove version prefix (v0/, v1/, etc.)
|
|
184
|
-
name = name.replace(/^v\d+\//, '');
|
|
185
|
-
|
|
186
|
-
// Remove .json extension
|
|
187
|
-
name = name.replace(/\.json$/, '');
|
|
188
|
-
|
|
189
|
-
return name;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Singleton instance
|
|
194
|
-
let configInstance: SchemaConfig | null = null;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Get the schema configuration singleton
|
|
198
|
-
* Throws error if required environment variables are not set
|
|
199
|
-
*/
|
|
200
|
-
export function getConfig(): SchemaConfig {
|
|
201
|
-
if (!configInstance) {
|
|
202
|
-
configInstance = new SchemaConfig();
|
|
203
|
-
}
|
|
204
|
-
return configInstance;
|
|
205
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for schema generation scripts
|
|
3
|
+
* All paths are configurable via environment variables
|
|
4
|
+
* Provides sensible defaults for standard project structure
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import path from 'path';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get environment variable with optional default
|
|
11
|
+
*/
|
|
12
|
+
function getEnv(name: string, defaultValue: string): string {
|
|
13
|
+
const value = process.env[name];
|
|
14
|
+
return value || defaultValue;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Schema configuration with required environment variables
|
|
19
|
+
*/
|
|
20
|
+
export class SchemaConfig {
|
|
21
|
+
// Base paths
|
|
22
|
+
private readonly root: string;
|
|
23
|
+
private readonly sourceDir: string;
|
|
24
|
+
private readonly sourceFile: string;
|
|
25
|
+
private readonly normalizedDir: string;
|
|
26
|
+
private readonly schemasDir: string;
|
|
27
|
+
private readonly resourcesDir: string;
|
|
28
|
+
private readonly dependencyMapPath: string;
|
|
29
|
+
private readonly typesTsSrcDir: string;
|
|
30
|
+
private readonly typesTsDistDir: string;
|
|
31
|
+
|
|
32
|
+
// Schema metadata
|
|
33
|
+
private readonly baseUrl: string;
|
|
34
|
+
private readonly version: string;
|
|
35
|
+
|
|
36
|
+
constructor() {
|
|
37
|
+
// Environment variables with sensible defaults
|
|
38
|
+
this.root = getEnv('TP_SCHEMA_ROOT', process.cwd());
|
|
39
|
+
this.sourceDir = getEnv('TP_SCHEMA_SOURCE_DIR', 'src/');
|
|
40
|
+
this.sourceFile = getEnv('TP_SCHEMA_SOURCE_FILE', 'Genesis.json');
|
|
41
|
+
// Intermediate, generated artifact produced by normalizeAnchorsToPointers.
|
|
42
|
+
// This should NOT live next to the source-of-truth schemas.
|
|
43
|
+
this.normalizedDir = getEnv('TP_SCHEMA_NORMALIZED_DIR', 'src/generated/normalized');
|
|
44
|
+
this.schemasDir = getEnv('TP_SCHEMA_SCHEMAS_DIR', 'src/generated/schemas');
|
|
45
|
+
this.resourcesDir = getEnv('TP_SCHEMA_RESOURCES_DIR', 'src/generated/resources');
|
|
46
|
+
this.dependencyMapPath = getEnv('TP_SCHEMA_DEPENDENCY_MAP_PATH', 'src/generated/dependencies/dependencyMap.json');
|
|
47
|
+
this.typesTsSrcDir = getEnv('TP_SCHEMA_TYPES_TS_SRC_DIR', 'src/generated/typesTS');
|
|
48
|
+
this.typesTsDistDir = getEnv('TP_SCHEMA_TYPES_TS_DIST_DIR', 'dist/generated/typesTS');
|
|
49
|
+
this.baseUrl = getEnv('TP_SCHEMA_BASE_URL', 'https://schemas.toolproof.com');
|
|
50
|
+
this.version = getEnv('TP_SCHEMA_VERSION', 'v0');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Path getters
|
|
54
|
+
getRoot(): string {
|
|
55
|
+
return this.root;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getSourceDir(): string {
|
|
59
|
+
return path.isAbsolute(this.sourceDir)
|
|
60
|
+
? this.sourceDir
|
|
61
|
+
: path.join(this.root, this.sourceDir);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getSourceFile(): string {
|
|
65
|
+
return this.sourceFile;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getSourcePath(): string {
|
|
69
|
+
return path.join(this.getSourceDir(), this.sourceFile);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getNormalizedDir(): string {
|
|
73
|
+
return path.isAbsolute(this.normalizedDir)
|
|
74
|
+
? this.normalizedDir
|
|
75
|
+
: path.join(this.root, this.normalizedDir);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getNormalizedSourceFile(): string {
|
|
79
|
+
// We keep the same basename (Genesis.json) in the generated folder.
|
|
80
|
+
// The source-of-truth Genesis.json lives under `TP_SCHEMA_SOURCE_DIR`.
|
|
81
|
+
// The generated/normalized Genesis.json lives under `TP_SCHEMA_NORMALIZED_DIR`.
|
|
82
|
+
return this.sourceFile;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getNormalizedSourcePath(): string {
|
|
86
|
+
return path.join(this.getNormalizedDir(), this.getNormalizedSourceFile());
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
getSchemasDir(): string {
|
|
90
|
+
return path.isAbsolute(this.schemasDir)
|
|
91
|
+
? this.schemasDir
|
|
92
|
+
: path.join(this.root, this.schemasDir);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getSchemaPath(filename: string): string {
|
|
96
|
+
return path.join(this.getSchemasDir(), filename);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
getSchemasStandaloneDir(): string {
|
|
100
|
+
return path.join(this.getSchemasDir(), 'standalone');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getSchemaStandalonePath(filename: string): string {
|
|
104
|
+
return path.join(this.getSchemasStandaloneDir(), filename);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
getTypesTsSrcDir(): string {
|
|
108
|
+
return path.isAbsolute(this.typesTsSrcDir)
|
|
109
|
+
? this.typesTsSrcDir
|
|
110
|
+
: path.join(this.root, this.typesTsSrcDir);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
getTypesTsDistDir(): string {
|
|
114
|
+
return path.isAbsolute(this.typesTsDistDir)
|
|
115
|
+
? this.typesTsDistDir
|
|
116
|
+
: path.join(this.root, this.typesTsDistDir);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getTypesTsSrcPath(filename: string): string {
|
|
120
|
+
return path.join(this.getTypesTsSrcDir(), filename);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
getTypesTsDistPath(filename: string): string {
|
|
124
|
+
return path.join(this.getTypesTsDistDir(), filename);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
getStandaloneTypeTsSrcDir(): string {
|
|
128
|
+
return path.join(this.getTypesTsSrcDir(), 'standalone');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
getStandaloneTypeTsDistDir(): string {
|
|
132
|
+
return path.join(this.getTypesTsDistDir(), 'standalone');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
getStandaloneTypeTsSrcPath(filename: string): string {
|
|
136
|
+
return path.join(this.getStandaloneTypeTsSrcDir(), filename);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
getStandaloneTypeTsDistPath(filename: string): string {
|
|
140
|
+
return path.join(this.getStandaloneTypeTsDistDir(), filename);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getResourcesDir(): string {
|
|
144
|
+
return path.isAbsolute(this.resourcesDir)
|
|
145
|
+
? this.resourcesDir
|
|
146
|
+
: path.join(this.root, this.resourcesDir);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
getDependencyMapPath(): string {
|
|
150
|
+
return path.isAbsolute(this.dependencyMapPath)
|
|
151
|
+
? this.dependencyMapPath
|
|
152
|
+
: path.join(this.root, this.dependencyMapPath);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Schema URL methods
|
|
156
|
+
getBaseUrl(): string {
|
|
157
|
+
return this.baseUrl;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
getVersion(): string {
|
|
161
|
+
return this.version;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
getSchemaId(schemaName: string): string {
|
|
165
|
+
return `${this.baseUrl}/${this.version}/${schemaName}.json`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Check if a URL matches the configured schema base URL pattern
|
|
170
|
+
*/
|
|
171
|
+
isSchemaUrl(url: string): boolean {
|
|
172
|
+
const baseUrlPattern = this.baseUrl.replace('https://', 'https?://');
|
|
173
|
+
return new RegExp(`^${baseUrlPattern}/`, 'i').test(url);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Extract schema name from URL (removes base URL and version prefix)
|
|
178
|
+
*/
|
|
179
|
+
extractSchemaName(url: string): string {
|
|
180
|
+
// Remove base URL
|
|
181
|
+
let name = url.replace(new RegExp(`^${this.baseUrl}/`, 'i'), '');
|
|
182
|
+
|
|
183
|
+
// Remove version prefix (v0/, v1/, etc.)
|
|
184
|
+
name = name.replace(/^v\d+\//, '');
|
|
185
|
+
|
|
186
|
+
// Remove .json extension
|
|
187
|
+
name = name.replace(/\.json$/, '');
|
|
188
|
+
|
|
189
|
+
return name;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Singleton instance
|
|
194
|
+
let configInstance: SchemaConfig | null = null;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Get the schema configuration singleton
|
|
198
|
+
* Throws error if required environment variables are not set
|
|
199
|
+
*/
|
|
200
|
+
export function getConfig(): SchemaConfig {
|
|
201
|
+
if (!configInstance) {
|
|
202
|
+
configInstance = new SchemaConfig();
|
|
203
|
+
}
|
|
204
|
+
return configInstance;
|
|
205
|
+
}
|