@toolproof-core/schema 1.0.9 → 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.
Files changed (67) hide show
  1. package/dist/generated/artifacts/constants.d.ts +121 -0
  2. package/dist/generated/artifacts/constants.js +121 -0
  3. package/dist/generated/artifacts/mappings.d.ts +23 -0
  4. package/dist/generated/artifacts/mappings.js +23 -0
  5. package/dist/generated/normalized/Genesis.json +117 -78
  6. package/dist/generated/resources/Genesis.json +489 -264
  7. package/dist/generated/schemas/Genesis.json +94 -61
  8. package/dist/generated/schemas/standalone/Job.json +9 -8
  9. package/dist/generated/schemas/standalone/RawStrategy.json +86 -110
  10. package/dist/generated/schemas/standalone/ResourceType.json +4 -4
  11. package/dist/generated/schemas/standalone/RunnableStrategy.json +115 -139
  12. package/dist/generated/schemas/standalone/StrategyRun.json +93 -117
  13. package/dist/generated/types/standalone/Resource_Genesis.d.ts +1 -1
  14. package/dist/generated/types/standalone/Resource_Job.d.ts +1 -1
  15. package/dist/generated/types/standalone/Resource_RawStrategy.d.ts +1 -1
  16. package/dist/generated/types/standalone/Resource_ResourceType.d.ts +1 -1
  17. package/dist/generated/types/standalone/Resource_RunnableStrategy.d.ts +1 -1
  18. package/dist/generated/types/types.d.ts +247 -239
  19. package/dist/index.d.ts +6 -3
  20. package/dist/index.js +5 -2
  21. package/dist/scripts/_lib/config.d.ts +3 -5
  22. package/dist/scripts/_lib/config.js +8 -14
  23. package/dist/scripts/generateConstantsAndMappings.d.ts +31 -0
  24. package/dist/scripts/generateConstantsAndMappings.js +243 -0
  25. package/dist/scripts/generateDependencies.js +1 -1
  26. package/dist/scripts/generateStandaloneType.js +2 -1
  27. package/dist/scripts/generateTerminals.js +2 -2
  28. package/dist/scripts/generateTypes.js +183 -5
  29. package/dist/scripts/wrapResourceTypesWithResourceShells.js +7 -3
  30. package/package.json +9 -10
  31. package/src/Genesis.json +1873 -1833
  32. package/src/generated/artifacts/constants.ts +122 -0
  33. package/src/generated/{dependencies → artifacts}/dependencyMap.json +282 -280
  34. package/src/generated/artifacts/mappings.ts +24 -0
  35. package/src/generated/{dependencies → artifacts}/terminals.json +13 -11
  36. package/src/generated/normalized/Genesis.json +1785 -1746
  37. package/src/generated/resources/Genesis.json +2833 -2608
  38. package/src/generated/schemas/Genesis.json +1348 -1315
  39. package/src/generated/schemas/standalone/Job.json +195 -194
  40. package/src/generated/schemas/standalone/RawStrategy.json +86 -110
  41. package/src/generated/schemas/standalone/ResourceType.json +106 -106
  42. package/src/generated/schemas/standalone/RunnableStrategy.json +645 -669
  43. package/src/generated/schemas/standalone/StrategyRun.json +913 -937
  44. package/src/generated/types/standalone/Resource_Genesis.d.ts +3 -3
  45. package/src/generated/types/standalone/Resource_Job.d.ts +3 -3
  46. package/src/generated/types/standalone/Resource_RawStrategy.d.ts +3 -3
  47. package/src/generated/types/standalone/Resource_ResourceType.d.ts +3 -3
  48. package/src/generated/types/standalone/Resource_RunnableStrategy.d.ts +3 -3
  49. package/src/generated/types/types.d.ts +717 -709
  50. package/src/index.ts +77 -70
  51. package/src/scripts/_lib/config.ts +207 -215
  52. package/src/scripts/extractSchemasFromResourceTypeShells.ts +261 -261
  53. package/src/scripts/generateConstantsAndMappings.ts +309 -0
  54. package/src/scripts/generateDependencies.ts +121 -121
  55. package/src/scripts/generateSchemaShims.ts +127 -127
  56. package/src/scripts/generateStandaloneSchema.ts +185 -185
  57. package/src/scripts/generateStandaloneType.ts +129 -127
  58. package/src/scripts/generateTerminals.ts +73 -73
  59. package/src/scripts/generateTypes.ts +733 -531
  60. package/src/scripts/normalizeAnchorsToPointers.ts +141 -141
  61. package/src/scripts/wrapResourceTypesWithResourceShells.ts +86 -82
  62. package/dist/generated/constants/constants.d.ts +0 -60
  63. package/dist/generated/constants/constants.js +0 -60
  64. package/dist/scripts/generateConstants.d.ts +0 -12
  65. package/dist/scripts/generateConstants.js +0 -179
  66. package/src/generated/constants/constants.ts +0 -61
  67. package/src/scripts/generateConstants.ts +0 -217
package/src/index.ts CHANGED
@@ -1,70 +1,77 @@
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
- export { default as CONSTANTS } from './generated/constants/constants.js';
7
-
8
-
9
- export type {
10
- Resource_Genesis as Resource_GenesisJson
11
- } from './generated/types/standalone/Resource_Genesis.js';
12
- export type {
13
- Resource_ResourceType as Resource_ResourceTypeJson
14
- } from './generated/types/standalone/Resource_ResourceType.js';
15
- export type {
16
- Resource_Job as Resource_JobJson
17
- } from './generated/types/standalone/Resource_Job.js';
18
- export type {
19
- Resource_RawStrategy as Resource_RawStrategyJson
20
- } from './generated/types/standalone/Resource_RawStrategy.js';
21
- export type {
22
- Resource_RunnableStrategy as Resource_RunnableStrategyJson
23
- } from './generated/types/standalone/Resource_RunnableStrategy.js';
24
-
25
-
26
- export type {
27
- DocumentationFacet as DocumentationFacetJson,
28
- NucleusFacet as NucleusFacetJson,
29
- ResourceTypeIdentity as ResourceTypeIdentityJson,
30
- ResourceType as ResourceTypeJson,
31
- ResourceRoleIdentity as ResourceRoleIdentityJson,
32
- ResourceRoleValue as ResourceRoleValueJson,
33
- Conditional as ConditionalJson,
34
- RoleMap as RoleMapJson,
35
- Roles as RolesJson,
36
- RoleBindings as RoleBindingsJson,
37
- ResourceIdentity as ResourceIdentityJson,
38
- JobStepIdentity as JobStepIdentityJson,
39
- BranchStepIdentity as BranchStepIdentityJson,
40
- WhileStepIdentity as WhileStepIdentityJson,
41
- ForStepIdentity as ForStepIdentityJson,
42
- JobStep as JobStepJson,
43
- BranchStep as BranchStepJson,
44
- WhileStep as WhileStepJson,
45
- ForStep as ForStepJson,
46
- StepKind as StepKindJson,
47
- StepIdentity as StepIdentityJson,
48
- Step as StepJson,
49
- CreationContext as CreationContextJson,
50
- ResourceMissing as ResourceMissingJson,
51
- Resource as ResourceJson,
52
- StrategyState as StrategyStateJson,
53
- StepsFacet as StepsFacetJson,
54
- RawStrategy as RawStrategyJson,
55
- RunnableStrategyIdentity as RunnableStrategyIdentityJson,
56
- RunnableStrategyStatus as RunnableStrategyStatusJson,
57
- RunnableStrategy as RunnableStrategyJson,
58
- RunnableStrategyUpdate as RunnableStrategyUpdateJson,
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
- StrategyRunIdentity as StrategyRunIdentityJson,
67
- GoalIdentity as GoalIdentityJson,
68
- Goal as GoalJson,
69
- ShellMaterializedBase as ShellMaterializedBaseJson,
70
- } from './generated/types/types.js';
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 SchemaResourceType } from './generated/schemas/standalone/ResourceType.js';
4
+ export { default as SchemaJob } from './generated/schemas/standalone/Job.js';
5
+ export { default as SchemaRunnableStrategy } from './generated/schemas/standalone/RunnableStrategy.js';
6
+ export { default as SchemaStrategyRun } from './generated/schemas/standalone/StrategyRun.js';
7
+ export { default as ResourceGenesis } from './generated/resources/Genesis.js';
8
+ export { default as CONSTANTS } from './generated/artifacts/constants.js';
9
+ export { default as MAPPINGS } from './generated/artifacts/mappings.js';
10
+
11
+
12
+ export type {
13
+ Resource_Genesis as Resource_GenesisJson
14
+ } from './generated/types/standalone/Resource_Genesis.js';
15
+ export type {
16
+ Resource_ResourceType as Resource_ResourceTypeJson
17
+ } from './generated/types/standalone/Resource_ResourceType.js';
18
+ export type {
19
+ Resource_Job as Resource_JobJson
20
+ } from './generated/types/standalone/Resource_Job.js';
21
+ export type {
22
+ Resource_RawStrategy as Resource_RawStrategyJson
23
+ } from './generated/types/standalone/Resource_RawStrategy.js';
24
+ export type {
25
+ Resource_RunnableStrategy as Resource_RunnableStrategyJson
26
+ } from './generated/types/standalone/Resource_RunnableStrategy.js';
27
+
28
+
29
+ export type {
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,
77
+ } from './generated/types/types.js';
@@ -1,215 +1,207 @@
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 constantsDir: string;
28
- private readonly resourcesDir: string;
29
- private readonly dependencyMapPath: string;
30
- private readonly typesSrcDir: string;
31
- private readonly typesDistDir: string;
32
-
33
- // Schema metadata
34
- private readonly baseUrl: string;
35
- private readonly version: string;
36
-
37
- constructor() {
38
- // Environment variables with sensible defaults
39
- this.root = getEnv('TP_SCHEMA_ROOT', process.cwd());
40
- this.sourceDir = getEnv('TP_SCHEMA_SOURCE_DIR', 'src/');
41
- this.sourceFile = getEnv('TP_SCHEMA_SOURCE_FILE', 'Genesis.json');
42
- this.normalizedDir = getEnv('TP_SCHEMA_NORMALIZED_DIR', 'src/generated/normalized');
43
- this.schemasDir = getEnv('TP_SCHEMA_SCHEMAS_DIR', 'src/generated/schemas');
44
- this.constantsDir = getEnv('TP_SCHEMA_CONSTANTS_DIR', 'src/generated/constants');
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.typesSrcDir = getEnv('TP_SCHEMA_TYPES_SRC_DIR', 'src/generated/types');
48
- this.typesDistDir = getEnv('TP_SCHEMA_TYPES_DIST_DIR', 'dist/generated/types');
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
- getConstantsDir(): string {
100
- return path.isAbsolute(this.constantsDir)
101
- ? this.constantsDir
102
- : path.join(this.root, this.constantsDir);
103
- }
104
-
105
- getConstantsPath(filename: string): string {
106
- return path.join(this.getConstantsDir(), filename);
107
- }
108
-
109
- getStandaloneSchemaDir(): string {
110
- return path.join(this.getSchemasDir(), 'standalone');
111
- }
112
-
113
- getStandaloneSchemaPath(filename: string): string {
114
- return path.join(this.getStandaloneSchemaDir(), filename);
115
- }
116
-
117
- getTypesSrcDir(): string {
118
- return path.isAbsolute(this.typesSrcDir)
119
- ? this.typesSrcDir
120
- : path.join(this.root, this.typesSrcDir);
121
- }
122
-
123
- getTypesDistDir(): string {
124
- return path.isAbsolute(this.typesDistDir)
125
- ? this.typesDistDir
126
- : path.join(this.root, this.typesDistDir);
127
- }
128
-
129
- getTypesSrcPath(filename: string): string {
130
- return path.join(this.getTypesSrcDir(), filename);
131
- }
132
-
133
- getTypesDistPath(filename: string): string {
134
- return path.join(this.getTypesDistDir(), filename);
135
- }
136
-
137
- getStandaloneTypeSrcDir(): string {
138
- return path.join(this.getTypesSrcDir(), 'standalone');
139
- }
140
-
141
- getStandaloneTypeDistDir(): string {
142
- return path.join(this.getTypesDistDir(), 'standalone');
143
- }
144
-
145
- getStandaloneTypeSrcPath(filename: string): string {
146
- return path.join(this.getStandaloneTypeSrcDir(), filename);
147
- }
148
-
149
- getStandaloneTypeDistPath(filename: string): string {
150
- return path.join(this.getStandaloneTypeDistDir(), filename);
151
- }
152
-
153
- getResourcesDir(): string {
154
- return path.isAbsolute(this.resourcesDir)
155
- ? this.resourcesDir
156
- : path.join(this.root, this.resourcesDir);
157
- }
158
-
159
- getDependencyMapPath(): string {
160
- return path.isAbsolute(this.dependencyMapPath)
161
- ? this.dependencyMapPath
162
- : path.join(this.root, this.dependencyMapPath);
163
- }
164
-
165
- // Schema URL methods
166
- getBaseUrl(): string {
167
- return this.baseUrl;
168
- }
169
-
170
- getVersion(): string {
171
- return this.version;
172
- }
173
-
174
- getSchemaId(schemaName: string): string {
175
- return `${this.baseUrl}/${this.version}/${schemaName}.json`;
176
- }
177
-
178
- /**
179
- * Check if a URL matches the configured schema base URL pattern
180
- */
181
- isSchemaUrl(url: string): boolean {
182
- const baseUrlPattern = this.baseUrl.replace('https://', 'https?://');
183
- return new RegExp(`^${baseUrlPattern}/`, 'i').test(url);
184
- }
185
-
186
- /**
187
- * Extract schema name from URL (removes base URL and version prefix)
188
- */
189
- extractSchemaName(url: string): string {
190
- // Remove base URL
191
- let name = url.replace(new RegExp(`^${this.baseUrl}/`, 'i'), '');
192
-
193
- // Remove version prefix (v0/, v1/, etc.)
194
- name = name.replace(/^v\d+\//, '');
195
-
196
- // Remove .json extension
197
- name = name.replace(/\.json$/, '');
198
-
199
- return name;
200
- }
201
- }
202
-
203
- // Singleton instance
204
- let configInstance: SchemaConfig | null = null;
205
-
206
- /**
207
- * Get the schema configuration singleton
208
- * Throws error if required environment variables are not set
209
- */
210
- export function getConfig(): SchemaConfig {
211
- if (!configInstance) {
212
- configInstance = new SchemaConfig();
213
- }
214
- return configInstance;
215
- }
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 artifactsDir: string;
28
+ private readonly resourcesDir: string;
29
+ private readonly typesSrcDir: string;
30
+ private readonly typesDistDir: 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
+ this.normalizedDir = getEnv('TP_SCHEMA_NORMALIZED_DIR', 'src/generated/normalized');
42
+ this.schemasDir = getEnv('TP_SCHEMA_SCHEMAS_DIR', 'src/generated/schemas');
43
+ this.artifactsDir = getEnv('TP_SCHEMA_ARTIFACTS_DIR', 'src/generated/artifacts');
44
+ this.resourcesDir = getEnv('TP_SCHEMA_RESOURCES_DIR', 'src/generated/resources');
45
+ this.typesSrcDir = getEnv('TP_SCHEMA_TYPES_SRC_DIR', 'src/generated/types');
46
+ this.typesDistDir = getEnv('TP_SCHEMA_TYPES_DIST_DIR', 'dist/generated/types');
47
+ this.baseUrl = getEnv('TP_SCHEMA_BASE_URL', 'https://schemas.toolproof.com');
48
+ this.version = getEnv('TP_SCHEMA_VERSION', 'v1');
49
+ }
50
+
51
+ // Path getters
52
+ getRoot(): string {
53
+ return this.root;
54
+ }
55
+
56
+ getSourceDir(): string {
57
+ return path.isAbsolute(this.sourceDir)
58
+ ? this.sourceDir
59
+ : path.join(this.root, this.sourceDir);
60
+ }
61
+
62
+ getSourceFile(): string {
63
+ return this.sourceFile;
64
+ }
65
+
66
+ getSourcePath(): string {
67
+ return path.join(this.getSourceDir(), this.sourceFile);
68
+ }
69
+
70
+ getNormalizedDir(): string {
71
+ return path.isAbsolute(this.normalizedDir)
72
+ ? this.normalizedDir
73
+ : path.join(this.root, this.normalizedDir);
74
+ }
75
+
76
+ getNormalizedSourceFile(): string {
77
+ // We keep the same basename (Genesis.json) in the generated folder.
78
+ // The source-of-truth Genesis.json lives under `TP_SCHEMA_SOURCE_DIR`.
79
+ // The generated/normalized Genesis.json lives under `TP_SCHEMA_NORMALIZED_DIR`.
80
+ return this.sourceFile;
81
+ }
82
+
83
+ getNormalizedSourcePath(): string {
84
+ return path.join(this.getNormalizedDir(), this.getNormalizedSourceFile());
85
+ }
86
+
87
+ getSchemasDir(): string {
88
+ return path.isAbsolute(this.schemasDir)
89
+ ? this.schemasDir
90
+ : path.join(this.root, this.schemasDir);
91
+ }
92
+
93
+ getSchemaPath(filename: string): string {
94
+ return path.join(this.getSchemasDir(), filename);
95
+ }
96
+
97
+ getArtifactsDir(): string {
98
+ return path.isAbsolute(this.artifactsDir)
99
+ ? this.artifactsDir
100
+ : path.join(this.root, this.artifactsDir);
101
+ }
102
+
103
+ getArtifactsPath(filename: string): string {
104
+ return path.join(this.getArtifactsDir(), filename);
105
+ }
106
+
107
+ getStandaloneSchemaDir(): string {
108
+ return path.join(this.getSchemasDir(), 'standalone');
109
+ }
110
+
111
+ getStandaloneSchemaPath(filename: string): string {
112
+ return path.join(this.getStandaloneSchemaDir(), filename);
113
+ }
114
+
115
+ getTypesSrcDir(): string {
116
+ return path.isAbsolute(this.typesSrcDir)
117
+ ? this.typesSrcDir
118
+ : path.join(this.root, this.typesSrcDir);
119
+ }
120
+
121
+ getTypesDistDir(): string {
122
+ return path.isAbsolute(this.typesDistDir)
123
+ ? this.typesDistDir
124
+ : path.join(this.root, this.typesDistDir);
125
+ }
126
+
127
+ getTypesSrcPath(filename: string): string {
128
+ return path.join(this.getTypesSrcDir(), filename);
129
+ }
130
+
131
+ getTypesDistPath(filename: string): string {
132
+ return path.join(this.getTypesDistDir(), filename);
133
+ }
134
+
135
+ getStandaloneTypeSrcDir(): string {
136
+ return path.join(this.getTypesSrcDir(), 'standalone');
137
+ }
138
+
139
+ getStandaloneTypeDistDir(): string {
140
+ return path.join(this.getTypesDistDir(), 'standalone');
141
+ }
142
+
143
+ getStandaloneTypeSrcPath(filename: string): string {
144
+ return path.join(this.getStandaloneTypeSrcDir(), filename);
145
+ }
146
+
147
+ getStandaloneTypeDistPath(filename: string): string {
148
+ return path.join(this.getStandaloneTypeDistDir(), filename);
149
+ }
150
+
151
+ getResourcesDir(): string {
152
+ return path.isAbsolute(this.resourcesDir)
153
+ ? this.resourcesDir
154
+ : path.join(this.root, this.resourcesDir);
155
+ }
156
+
157
+ // Schema URL methods
158
+ getBaseUrl(): string {
159
+ return this.baseUrl;
160
+ }
161
+
162
+ getVersion(): string {
163
+ return this.version;
164
+ }
165
+
166
+ getSchemaId(schemaName: string): string {
167
+ return `${this.baseUrl}/${this.version}/${schemaName}.json`;
168
+ }
169
+
170
+ /**
171
+ * Check if a URL matches the configured schema base URL pattern
172
+ */
173
+ isSchemaUrl(url: string): boolean {
174
+ const baseUrlPattern = this.baseUrl.replace('https://', 'https?://');
175
+ return new RegExp(`^${baseUrlPattern}/`, 'i').test(url);
176
+ }
177
+
178
+ /**
179
+ * Extract schema name from URL (removes base URL and version prefix)
180
+ */
181
+ extractSchemaName(url: string): string {
182
+ // Remove base URL
183
+ let name = url.replace(new RegExp(`^${this.baseUrl}/`, 'i'), '');
184
+
185
+ // Remove version prefix (v0/, v1/, etc.)
186
+ name = name.replace(/^v\d+\//, '');
187
+
188
+ // Remove .json extension
189
+ name = name.replace(/\.json$/, '');
190
+
191
+ return name;
192
+ }
193
+ }
194
+
195
+ // Singleton instance
196
+ let configInstance: SchemaConfig | null = null;
197
+
198
+ /**
199
+ * Get the schema configuration singleton
200
+ * Throws error if required environment variables are not set
201
+ */
202
+ export function getConfig(): SchemaConfig {
203
+ if (!configInstance) {
204
+ configInstance = new SchemaConfig();
205
+ }
206
+ return configInstance;
207
+ }