@toolproof-core/schema 1.0.1 → 1.0.2
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/package.json +8 -7
- package/src/Genesis.json +1999 -1999
- package/src/generated/types/standalone/Resource_Genesis.js +1 -1
- package/src/generated/types/standalone/Resource_Job.js +1 -1
- package/src/generated/types/standalone/Resource_RawStrategy.js +1 -1
- package/src/generated/types/standalone/Resource_ResourceType.js +1 -1
- package/src/generated/types/standalone/Resource_RunnableStrategy.js +1 -1
- package/src/scripts/_lib/config.ts +205 -205
- package/src/scripts/extractSchemasFromResourceTypeShells.ts +218 -218
- package/src/scripts/generateDependencies.ts +120 -120
- package/src/scripts/generateSchemaShims.ts +135 -135
- package/src/scripts/generateStandaloneSchema.ts +175 -175
- package/src/scripts/generateStandaloneType.ts +119 -119
- package/src/scripts/generateTypes.ts +614 -614
- package/src/scripts/normalizeAnchorsToPointers.ts +123 -123
- package/src/scripts/wrapResourceTypesWithResourceShells.ts +84 -84
|
@@ -1 +1 @@
|
|
|
1
|
-
export {}
|
|
1
|
+
export {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {}
|
|
1
|
+
export {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {}
|
|
1
|
+
export {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {}
|
|
1
|
+
export {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {}
|
|
1
|
+
export {}
|
|
@@ -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 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
|
-
// 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.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
|
-
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
|
-
getTypesSrcDir(): string {
|
|
108
|
-
return path.isAbsolute(this.typesSrcDir)
|
|
109
|
-
? this.typesSrcDir
|
|
110
|
-
: path.join(this.root, this.typesSrcDir);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
getTypesDistDir(): string {
|
|
114
|
-
return path.isAbsolute(this.typesDistDir)
|
|
115
|
-
? this.typesDistDir
|
|
116
|
-
: path.join(this.root, this.typesDistDir);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
getTypesSrcPath(filename: string): string {
|
|
120
|
-
return path.join(this.getTypesSrcDir(), filename);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
getTypesDistPath(filename: string): string {
|
|
124
|
-
return path.join(this.getTypesDistDir(), filename);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
getTypesStandaloneSrcDir(): string {
|
|
128
|
-
return path.join(this.getTypesSrcDir(), 'standalone');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
getTypesStandaloneDistDir(): string {
|
|
132
|
-
return path.join(this.getTypesDistDir(), 'standalone');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
getTypesStandaloneSrcPath(filename: string): string {
|
|
136
|
-
return path.join(this.getTypesStandaloneSrcDir(), filename);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
getTypesStandaloneDistPath(filename: string): string {
|
|
140
|
-
return path.join(this.getTypesStandaloneDistDir(), 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
|
-
}
|
|
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 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
|
+
// 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.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
|
+
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
|
+
getTypesSrcDir(): string {
|
|
108
|
+
return path.isAbsolute(this.typesSrcDir)
|
|
109
|
+
? this.typesSrcDir
|
|
110
|
+
: path.join(this.root, this.typesSrcDir);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
getTypesDistDir(): string {
|
|
114
|
+
return path.isAbsolute(this.typesDistDir)
|
|
115
|
+
? this.typesDistDir
|
|
116
|
+
: path.join(this.root, this.typesDistDir);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getTypesSrcPath(filename: string): string {
|
|
120
|
+
return path.join(this.getTypesSrcDir(), filename);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
getTypesDistPath(filename: string): string {
|
|
124
|
+
return path.join(this.getTypesDistDir(), filename);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
getTypesStandaloneSrcDir(): string {
|
|
128
|
+
return path.join(this.getTypesSrcDir(), 'standalone');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
getTypesStandaloneDistDir(): string {
|
|
132
|
+
return path.join(this.getTypesDistDir(), 'standalone');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
getTypesStandaloneSrcPath(filename: string): string {
|
|
136
|
+
return path.join(this.getTypesStandaloneSrcDir(), filename);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
getTypesStandaloneDistPath(filename: string): string {
|
|
140
|
+
return path.join(this.getTypesStandaloneDistDir(), 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
|
+
}
|