@toolproof-core/genesis 1.0.49 → 1.0.50
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/src/implementations/tools.d.ts +100 -0
- package/dist/src/implementations/tools.js +135 -0
- package/dist/src/index.d.ts +5 -4
- package/dist/src/index.js +4 -3
- package/dist/src/utils/resourceTypes.d.ts +2 -1
- package/dist/src/utils/resourceTypes.js +22 -6
- package/dist/src/utils/schemaRefNormalization.js +3 -3
- package/dist/src/utils/standaloneTypes.js +2 -2
- package/dist/src/utils/timestampedResources.d.ts +16 -0
- package/dist/src/utils/timestampedResources.js +17 -0
- package/dist/src/utils/typeGenerationPostProcess.js +2 -2
- package/dist/src/utils/zodCodegen.js +3 -3
- package/generated-src/declarations/booleans.json +4 -0
- package/generated-src/declarations/booleans.ts +2 -0
- package/generated-src/declarations/naturals.json +13 -0
- package/generated-src/declarations/naturals.ts +2 -0
- package/generated-src/{resourceTypes → declarations}/resourceTypes.json +176 -39
- package/generated-src/declarations/resourceTypes.ts +2 -0
- package/generated-src/declarations/tools.json +705 -0
- package/generated-src/declarations/tools.ts +2 -0
- package/generated-src/implementations/tools.ts +214 -0
- package/generated-src/{derived → lookups}/constants.ts +4 -5
- package/generated-src/metadata/Core.json +51 -114
- package/generated-src/metadata/dependencyMap.json +16 -2
- package/generated-src/metadata/terminals.json +3 -4
- package/generated-src/schemas/schemas.json +198 -29
- package/generated-src/schemas/standalone/Resource.json +4 -8
- package/generated-src/schemas/standalone/ResourceType.json +21 -5
- package/generated-src/schemas/standalone/Strategy.json +4 -8
- package/generated-src/schemas/standalone/StrategyTrace.json +4 -8
- package/generated-src/schemas/standalone/Suite.json +646 -0
- package/generated-src/schemas/standalone/Suite.ts +2 -0
- package/generated-src/schemas/standalone/Tool.json +48 -23
- package/generated-src/schemas/zod/Resource.ts +2 -2
- package/generated-src/schemas/zod/ResourceType.ts +1 -1
- package/generated-src/schemas/zod/Strategy.ts +3 -3
- package/generated-src/schemas/zod/StrategyTrace.ts +3 -3
- package/generated-src/schemas/zod/Suite.ts +44 -0
- package/generated-src/schemas/zod/Tool.ts +7 -2
- package/generated-src/schemas/zod/index.ts +1 -0
- package/{src/genesis/resources → generated-src/timestampedResources}/booleans.json +19 -23
- package/generated-src/timestampedResources/booleans.ts +2 -0
- package/{src/genesis/resources → generated-src/timestampedResources}/naturals.json +100 -111
- package/generated-src/timestampedResources/naturals.ts +2 -0
- package/generated-src/{resources → timestampedResources}/resourceTypes.json +202 -66
- package/generated-src/timestampedResources/resourceTypes.ts +2 -0
- package/{src/genesis/resources → generated-src/timestampedResources}/tools.json +824 -839
- package/generated-src/timestampedResources/tools.ts +2 -0
- package/generated-src/types/standalone/BooleanResource.d.ts +2 -2
- package/generated-src/types/standalone/ErrorResource.d.ts +2 -2
- package/generated-src/types/standalone/GoalResource.d.ts +2 -2
- package/generated-src/types/standalone/NaturalResource.d.ts +2 -2
- package/generated-src/types/standalone/ResourceResource.d.ts +2 -2
- package/generated-src/types/standalone/ResourceTypeResource.d.ts +2 -2
- package/generated-src/types/standalone/StrategyResource.d.ts +2 -2
- package/generated-src/types/standalone/StrategyTraceResource.d.ts +2 -2
- package/generated-src/types/standalone/SuiteResource.d.ts +3 -0
- package/generated-src/types/standalone/SuiteResource.js +1 -0
- package/generated-src/types/standalone/ToolResource.d.ts +2 -2
- package/generated-src/types/types.d.ts +57 -14
- package/package.json +18 -13
- package/src/declarations/booleans.json +4 -0
- package/src/declarations/naturals.json +13 -0
- package/src/{genesis → declarations/resourceTypes}/resourceTypeShells.json +52 -46
- package/src/{genesis → declarations/resourceTypes}/schemas.json +1838 -1669
- package/src/declarations/tools.json +705 -0
- package/src/implementations/tools.ts +214 -0
- package/src/index.ts +131 -110
- package/src/utils/constantsAndMappings.ts +194 -194
- package/src/utils/coreProjection.ts +52 -52
- package/src/utils/resourceTypes.ts +70 -38
- package/src/utils/schemaDependencies.ts +114 -114
- package/src/utils/schemaObjectNormalization.ts +70 -70
- package/src/utils/schemaRefNormalization.ts +82 -82
- package/src/utils/schemaShims.ts +16 -16
- package/src/utils/standaloneSchemas.ts +113 -113
- package/src/utils/standaloneTypes.ts +27 -27
- package/src/utils/standaloneZodSchemas.ts +71 -71
- package/src/utils/timestampedResources.ts +42 -0
- package/src/utils/typeGeneration.ts +30 -30
- package/src/utils/typeGenerationPostProcess.ts +245 -245
- package/src/utils/typeGenerationPreflight.ts +118 -118
- package/src/utils/zodCodegen.ts +548 -548
- package/toolproof.json +19 -0
- package/dist/src/genesis/resources/implementations/foo.d.ts +0 -1
- package/dist/src/genesis/resources/implementations/foo.js +0 -184
- package/dist/src/utils/resources.d.ts +0 -5
- package/dist/src/utils/resources.js +0 -17
- package/generated-src/resourceTypes/resourceTypes.ts +0 -2
- package/generated-src/resources/resourceTypes.ts +0 -2
- package/src/genesis/resources/implementations/foo.ts +0 -183
- package/src/utils/resources.ts +0 -26
- /package/generated-src/{derived → lookups}/mappings.ts +0 -0
|
@@ -1,195 +1,195 @@
|
|
|
1
|
-
type JSONValue = null | boolean | number | string | JSONValue[] | { [k: string]: JSONValue };
|
|
2
|
-
|
|
3
|
-
export type GeneratedConstants = {
|
|
4
|
-
Names: Record<string, string>;
|
|
5
|
-
Enums: Record<string, Record<string, string>>;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type GeneratedMappings = {
|
|
9
|
-
HandleNameToPrefix: Record<string, string>;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
function deriveIdPrefixFromPattern(pattern: string): string | undefined {
|
|
13
|
-
const match = /^\^([^$]+)\.\+\$$/.exec(pattern);
|
|
14
|
-
if (!match) return undefined;
|
|
15
|
-
|
|
16
|
-
const prefix = match[1];
|
|
17
|
-
if (!prefix || /[`\n\r]/.test(prefix)) return undefined;
|
|
18
|
-
|
|
19
|
-
return prefix;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function extractHandlePrefixes(schema: unknown): Record<string, string> {
|
|
23
|
-
if (!schema || typeof schema !== 'object') return {};
|
|
24
|
-
|
|
25
|
-
const defs = (schema as { $defs?: unknown }).$defs;
|
|
26
|
-
if (!defs || typeof defs !== 'object') return {};
|
|
27
|
-
|
|
28
|
-
const defEntries = Object.entries(defs as Record<string, unknown>);
|
|
29
|
-
defEntries.sort(([a], [b]) => a.localeCompare(b));
|
|
30
|
-
|
|
31
|
-
const out: Record<string, string> = {};
|
|
32
|
-
|
|
33
|
-
for (const [defName, defVal] of defEntries) {
|
|
34
|
-
if (!/(Id|Handle)$/.test(defName)) continue;
|
|
35
|
-
if (!defVal || typeof defVal !== 'object' || Array.isArray(defVal)) continue;
|
|
36
|
-
|
|
37
|
-
const value = defVal as { type?: unknown; pattern?: unknown };
|
|
38
|
-
if (value.type !== 'string') continue;
|
|
39
|
-
if (typeof value.pattern !== 'string') continue;
|
|
40
|
-
|
|
41
|
-
const prefix = deriveIdPrefixFromPattern(value.pattern);
|
|
42
|
-
if (!prefix) continue;
|
|
43
|
-
|
|
44
|
-
out[defName] = prefix;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return out;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function extractSubschemaNames(schema: unknown): Record<string, string> {
|
|
51
|
-
if (!schema || typeof schema !== 'object') return {};
|
|
52
|
-
|
|
53
|
-
const defs = (schema as { $defs?: unknown }).$defs;
|
|
54
|
-
if (!defs || typeof defs !== 'object') return {};
|
|
55
|
-
|
|
56
|
-
const defEntries = Object.entries(defs as Record<string, unknown>);
|
|
57
|
-
defEntries.sort(([a], [b]) => a.localeCompare(b));
|
|
58
|
-
|
|
59
|
-
const out: Record<string, string> = {};
|
|
60
|
-
for (const [defName] of defEntries) {
|
|
61
|
-
if (!defName || /[\n\r`]/.test(defName)) continue;
|
|
62
|
-
out[defName] = defName;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return out;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function extractEnums(schema: unknown): Record<string, Record<string, string>> {
|
|
69
|
-
if (!schema || typeof schema !== 'object') return {};
|
|
70
|
-
|
|
71
|
-
const defs = (schema as { $defs?: unknown }).$defs;
|
|
72
|
-
if (!defs || typeof defs !== 'object') return {};
|
|
73
|
-
|
|
74
|
-
const defEntries = Object.entries(defs as Record<string, unknown>);
|
|
75
|
-
defEntries.sort(([a], [b]) => a.localeCompare(b));
|
|
76
|
-
|
|
77
|
-
const out: Record<string, Record<string, string>> = {};
|
|
78
|
-
|
|
79
|
-
for (const [defName, defVal] of defEntries) {
|
|
80
|
-
if (!/(Kind|Status)$/.test(defName)) continue;
|
|
81
|
-
if (!defVal || typeof defVal !== 'object' || Array.isArray(defVal)) continue;
|
|
82
|
-
|
|
83
|
-
const value = defVal as { type?: unknown; enum?: unknown };
|
|
84
|
-
if (value.type !== 'string') continue;
|
|
85
|
-
if (!Array.isArray(value.enum) || value.enum.length === 0) continue;
|
|
86
|
-
if (value.enum.some((item) => typeof item !== 'string')) continue;
|
|
87
|
-
|
|
88
|
-
const members: Record<string, string> = {};
|
|
89
|
-
for (const member of value.enum as readonly string[]) {
|
|
90
|
-
members[member] = member;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
out[defName] = members;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return out;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function extractGeneratedConstantsAndMappings(schema: JSONValue): {
|
|
100
|
-
CONSTANTS: GeneratedConstants;
|
|
101
|
-
MAPPINGS: GeneratedMappings;
|
|
102
|
-
} {
|
|
103
|
-
const names = extractSubschemaNames(schema);
|
|
104
|
-
const enums = extractEnums(schema);
|
|
105
|
-
const handlePrefixes = extractHandlePrefixes(schema);
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
CONSTANTS: {
|
|
109
|
-
Names: names,
|
|
110
|
-
Enums: enums,
|
|
111
|
-
},
|
|
112
|
-
MAPPINGS: {
|
|
113
|
-
HandleNameToPrefix: handlePrefixes,
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function escapeTsString(value: string): string {
|
|
119
|
-
return value
|
|
120
|
-
.replace(/\\/g, '\\\\')
|
|
121
|
-
.replace(/\r/g, '\\r')
|
|
122
|
-
.replace(/\n/g, '\\n')
|
|
123
|
-
.replace(/\t/g, '\\t')
|
|
124
|
-
.replace(/'/g, "\\'");
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function renderTsStringLiteral(value: string): string {
|
|
128
|
-
return `'${escapeTsString(value)}'`;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function isValidTsIdentifier(key: string): boolean {
|
|
132
|
-
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function renderTsKey(key: string): string {
|
|
136
|
-
return isValidTsIdentifier(key) ? key : renderTsStringLiteral(key);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export function renderConstantsTs(constants: GeneratedConstants): string {
|
|
140
|
-
const nameKeys = Object.keys(constants.Names).sort((a, b) => a.localeCompare(b));
|
|
141
|
-
const enumKeys = Object.keys(constants.Enums).sort((a, b) => a.localeCompare(b));
|
|
142
|
-
|
|
143
|
-
const lines: string[] = [];
|
|
144
|
-
lines.push('const CONSTANTS = {');
|
|
145
|
-
lines.push(' Names: {');
|
|
146
|
-
|
|
147
|
-
for (const key of nameKeys) {
|
|
148
|
-
const value = constants.Names[key] ?? '';
|
|
149
|
-
lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
lines.push(' },');
|
|
153
|
-
lines.push(' Enums: {');
|
|
154
|
-
|
|
155
|
-
for (const key of enumKeys) {
|
|
156
|
-
const members = constants.Enums[key] ?? {};
|
|
157
|
-
lines.push(` ${renderTsKey(key)}: {`);
|
|
158
|
-
|
|
159
|
-
for (const memberKey of Object.keys(members)) {
|
|
160
|
-
const value = members[memberKey] ?? '';
|
|
161
|
-
lines.push(` ${renderTsKey(memberKey)}: ${renderTsStringLiteral(value)},`);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
lines.push(' },');
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
lines.push(' }');
|
|
168
|
-
lines.push('} as const;');
|
|
169
|
-
lines.push('');
|
|
170
|
-
lines.push('export default CONSTANTS;');
|
|
171
|
-
lines.push('');
|
|
172
|
-
|
|
173
|
-
return lines.join('\n');
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export function renderMappingsTs(mappings: GeneratedMappings): string {
|
|
177
|
-
const handleKeys = Object.keys(mappings.HandleNameToPrefix).sort((a, b) => a.localeCompare(b));
|
|
178
|
-
|
|
179
|
-
const lines: string[] = [];
|
|
180
|
-
lines.push('const MAPPINGS = {');
|
|
181
|
-
lines.push(' HandleNameToPrefix: {');
|
|
182
|
-
|
|
183
|
-
for (const key of handleKeys) {
|
|
184
|
-
const value = mappings.HandleNameToPrefix[key] ?? '';
|
|
185
|
-
lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
lines.push(' },');
|
|
189
|
-
lines.push('} as const;');
|
|
190
|
-
lines.push('');
|
|
191
|
-
lines.push('export default MAPPINGS;');
|
|
192
|
-
lines.push('');
|
|
193
|
-
|
|
194
|
-
return lines.join('\n');
|
|
1
|
+
type JSONValue = null | boolean | number | string | JSONValue[] | { [k: string]: JSONValue };
|
|
2
|
+
|
|
3
|
+
export type GeneratedConstants = {
|
|
4
|
+
Names: Record<string, string>;
|
|
5
|
+
Enums: Record<string, Record<string, string>>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type GeneratedMappings = {
|
|
9
|
+
HandleNameToPrefix: Record<string, string>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function deriveIdPrefixFromPattern(pattern: string): string | undefined {
|
|
13
|
+
const match = /^\^([^$]+)\.\+\$$/.exec(pattern);
|
|
14
|
+
if (!match) return undefined;
|
|
15
|
+
|
|
16
|
+
const prefix = match[1];
|
|
17
|
+
if (!prefix || /[`\n\r]/.test(prefix)) return undefined;
|
|
18
|
+
|
|
19
|
+
return prefix;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function extractHandlePrefixes(schema: unknown): Record<string, string> {
|
|
23
|
+
if (!schema || typeof schema !== 'object') return {};
|
|
24
|
+
|
|
25
|
+
const defs = (schema as { $defs?: unknown }).$defs;
|
|
26
|
+
if (!defs || typeof defs !== 'object') return {};
|
|
27
|
+
|
|
28
|
+
const defEntries = Object.entries(defs as Record<string, unknown>);
|
|
29
|
+
defEntries.sort(([a], [b]) => a.localeCompare(b));
|
|
30
|
+
|
|
31
|
+
const out: Record<string, string> = {};
|
|
32
|
+
|
|
33
|
+
for (const [defName, defVal] of defEntries) {
|
|
34
|
+
if (!/(Id|Handle)$/.test(defName)) continue;
|
|
35
|
+
if (!defVal || typeof defVal !== 'object' || Array.isArray(defVal)) continue;
|
|
36
|
+
|
|
37
|
+
const value = defVal as { type?: unknown; pattern?: unknown };
|
|
38
|
+
if (value.type !== 'string') continue;
|
|
39
|
+
if (typeof value.pattern !== 'string') continue;
|
|
40
|
+
|
|
41
|
+
const prefix = deriveIdPrefixFromPattern(value.pattern);
|
|
42
|
+
if (!prefix) continue;
|
|
43
|
+
|
|
44
|
+
out[defName] = prefix;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function extractSubschemaNames(schema: unknown): Record<string, string> {
|
|
51
|
+
if (!schema || typeof schema !== 'object') return {};
|
|
52
|
+
|
|
53
|
+
const defs = (schema as { $defs?: unknown }).$defs;
|
|
54
|
+
if (!defs || typeof defs !== 'object') return {};
|
|
55
|
+
|
|
56
|
+
const defEntries = Object.entries(defs as Record<string, unknown>);
|
|
57
|
+
defEntries.sort(([a], [b]) => a.localeCompare(b));
|
|
58
|
+
|
|
59
|
+
const out: Record<string, string> = {};
|
|
60
|
+
for (const [defName] of defEntries) {
|
|
61
|
+
if (!defName || /[\n\r`]/.test(defName)) continue;
|
|
62
|
+
out[defName] = defName;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function extractEnums(schema: unknown): Record<string, Record<string, string>> {
|
|
69
|
+
if (!schema || typeof schema !== 'object') return {};
|
|
70
|
+
|
|
71
|
+
const defs = (schema as { $defs?: unknown }).$defs;
|
|
72
|
+
if (!defs || typeof defs !== 'object') return {};
|
|
73
|
+
|
|
74
|
+
const defEntries = Object.entries(defs as Record<string, unknown>);
|
|
75
|
+
defEntries.sort(([a], [b]) => a.localeCompare(b));
|
|
76
|
+
|
|
77
|
+
const out: Record<string, Record<string, string>> = {};
|
|
78
|
+
|
|
79
|
+
for (const [defName, defVal] of defEntries) {
|
|
80
|
+
if (!/(Kind|Status)$/.test(defName)) continue;
|
|
81
|
+
if (!defVal || typeof defVal !== 'object' || Array.isArray(defVal)) continue;
|
|
82
|
+
|
|
83
|
+
const value = defVal as { type?: unknown; enum?: unknown };
|
|
84
|
+
if (value.type !== 'string') continue;
|
|
85
|
+
if (!Array.isArray(value.enum) || value.enum.length === 0) continue;
|
|
86
|
+
if (value.enum.some((item) => typeof item !== 'string')) continue;
|
|
87
|
+
|
|
88
|
+
const members: Record<string, string> = {};
|
|
89
|
+
for (const member of value.enum as readonly string[]) {
|
|
90
|
+
members[member] = member;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
out[defName] = members;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function extractGeneratedConstantsAndMappings(schema: JSONValue): {
|
|
100
|
+
CONSTANTS: GeneratedConstants;
|
|
101
|
+
MAPPINGS: GeneratedMappings;
|
|
102
|
+
} {
|
|
103
|
+
const names = extractSubschemaNames(schema);
|
|
104
|
+
const enums = extractEnums(schema);
|
|
105
|
+
const handlePrefixes = extractHandlePrefixes(schema);
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
CONSTANTS: {
|
|
109
|
+
Names: names,
|
|
110
|
+
Enums: enums,
|
|
111
|
+
},
|
|
112
|
+
MAPPINGS: {
|
|
113
|
+
HandleNameToPrefix: handlePrefixes,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function escapeTsString(value: string): string {
|
|
119
|
+
return value
|
|
120
|
+
.replace(/\\/g, '\\\\')
|
|
121
|
+
.replace(/\r/g, '\\r')
|
|
122
|
+
.replace(/\n/g, '\\n')
|
|
123
|
+
.replace(/\t/g, '\\t')
|
|
124
|
+
.replace(/'/g, "\\'");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function renderTsStringLiteral(value: string): string {
|
|
128
|
+
return `'${escapeTsString(value)}'`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function isValidTsIdentifier(key: string): boolean {
|
|
132
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function renderTsKey(key: string): string {
|
|
136
|
+
return isValidTsIdentifier(key) ? key : renderTsStringLiteral(key);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function renderConstantsTs(constants: GeneratedConstants): string {
|
|
140
|
+
const nameKeys = Object.keys(constants.Names).sort((a, b) => a.localeCompare(b));
|
|
141
|
+
const enumKeys = Object.keys(constants.Enums).sort((a, b) => a.localeCompare(b));
|
|
142
|
+
|
|
143
|
+
const lines: string[] = [];
|
|
144
|
+
lines.push('const CONSTANTS = {');
|
|
145
|
+
lines.push(' Names: {');
|
|
146
|
+
|
|
147
|
+
for (const key of nameKeys) {
|
|
148
|
+
const value = constants.Names[key] ?? '';
|
|
149
|
+
lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
lines.push(' },');
|
|
153
|
+
lines.push(' Enums: {');
|
|
154
|
+
|
|
155
|
+
for (const key of enumKeys) {
|
|
156
|
+
const members = constants.Enums[key] ?? {};
|
|
157
|
+
lines.push(` ${renderTsKey(key)}: {`);
|
|
158
|
+
|
|
159
|
+
for (const memberKey of Object.keys(members)) {
|
|
160
|
+
const value = members[memberKey] ?? '';
|
|
161
|
+
lines.push(` ${renderTsKey(memberKey)}: ${renderTsStringLiteral(value)},`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
lines.push(' },');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
lines.push(' }');
|
|
168
|
+
lines.push('} as const;');
|
|
169
|
+
lines.push('');
|
|
170
|
+
lines.push('export default CONSTANTS;');
|
|
171
|
+
lines.push('');
|
|
172
|
+
|
|
173
|
+
return lines.join('\n');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function renderMappingsTs(mappings: GeneratedMappings): string {
|
|
177
|
+
const handleKeys = Object.keys(mappings.HandleNameToPrefix).sort((a, b) => a.localeCompare(b));
|
|
178
|
+
|
|
179
|
+
const lines: string[] = [];
|
|
180
|
+
lines.push('const MAPPINGS = {');
|
|
181
|
+
lines.push(' HandleNameToPrefix: {');
|
|
182
|
+
|
|
183
|
+
for (const key of handleKeys) {
|
|
184
|
+
const value = mappings.HandleNameToPrefix[key] ?? '';
|
|
185
|
+
lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
lines.push(' },');
|
|
189
|
+
lines.push('} as const;');
|
|
190
|
+
lines.push('');
|
|
191
|
+
lines.push('export default MAPPINGS;');
|
|
192
|
+
lines.push('');
|
|
193
|
+
|
|
194
|
+
return lines.join('\n');
|
|
195
195
|
}
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
|
|
3
|
-
export type CoreProjectionNode = CoreProjectionDirectoryNode | CoreProjectionFileNode;
|
|
4
|
-
|
|
5
|
-
export interface CoreProjectionBaseNode {
|
|
6
|
-
kind: 'directory' | 'file';
|
|
7
|
-
name: string;
|
|
8
|
-
path: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface CoreProjectionDirectoryNode extends CoreProjectionBaseNode {
|
|
12
|
-
kind: 'directory';
|
|
13
|
-
children: CoreProjectionNode[];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface CoreProjectionFileNode extends CoreProjectionBaseNode {
|
|
17
|
-
kind: 'file';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const EXCLUDED_DIRECTORY_NAMES = new Set([
|
|
21
|
-
'.git',
|
|
22
|
-
'.next',
|
|
23
|
-
'dist',
|
|
24
|
-
'node_modules',
|
|
25
|
-
]);
|
|
26
|
-
|
|
27
|
-
export function toPosixPath(value: string): string {
|
|
28
|
-
return value.split(path.sep).join('/');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function shouldExclude(relativePath: string, isDirectory: boolean, excludedRelativePathPrefixes: string[]): boolean {
|
|
32
|
-
if (!relativePath || relativePath === '.') {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const normalizedPath = toPosixPath(relativePath);
|
|
37
|
-
const baseName = path.posix.basename(normalizedPath);
|
|
38
|
-
|
|
39
|
-
if (isDirectory && EXCLUDED_DIRECTORY_NAMES.has(baseName)) {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return excludedRelativePathPrefixes.some((prefix) => {
|
|
44
|
-
return normalizedPath === prefix || normalizedPath.startsWith(`${prefix}/`);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function compareNodes(a: CoreProjectionNode, b: CoreProjectionNode): number {
|
|
49
|
-
if (a.kind !== b.kind) {
|
|
50
|
-
return a.kind === 'directory' ? -1 : 1;
|
|
51
|
-
}
|
|
52
|
-
return a.name.localeCompare(b.name);
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
|
|
3
|
+
export type CoreProjectionNode = CoreProjectionDirectoryNode | CoreProjectionFileNode;
|
|
4
|
+
|
|
5
|
+
export interface CoreProjectionBaseNode {
|
|
6
|
+
kind: 'directory' | 'file';
|
|
7
|
+
name: string;
|
|
8
|
+
path: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface CoreProjectionDirectoryNode extends CoreProjectionBaseNode {
|
|
12
|
+
kind: 'directory';
|
|
13
|
+
children: CoreProjectionNode[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface CoreProjectionFileNode extends CoreProjectionBaseNode {
|
|
17
|
+
kind: 'file';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const EXCLUDED_DIRECTORY_NAMES = new Set([
|
|
21
|
+
'.git',
|
|
22
|
+
'.next',
|
|
23
|
+
'dist',
|
|
24
|
+
'node_modules',
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
export function toPosixPath(value: string): string {
|
|
28
|
+
return value.split(path.sep).join('/');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function shouldExclude(relativePath: string, isDirectory: boolean, excludedRelativePathPrefixes: string[]): boolean {
|
|
32
|
+
if (!relativePath || relativePath === '.') {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const normalizedPath = toPosixPath(relativePath);
|
|
37
|
+
const baseName = path.posix.basename(normalizedPath);
|
|
38
|
+
|
|
39
|
+
if (isDirectory && EXCLUDED_DIRECTORY_NAMES.has(baseName)) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return excludedRelativePathPrefixes.some((prefix) => {
|
|
44
|
+
return normalizedPath === prefix || normalizedPath.startsWith(`${prefix}/`);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function compareNodes(a: CoreProjectionNode, b: CoreProjectionNode): number {
|
|
49
|
+
if (a.kind !== b.kind) {
|
|
50
|
+
return a.kind === 'directory' ? -1 : 1;
|
|
51
|
+
}
|
|
52
|
+
return a.name.localeCompare(b.name);
|
|
53
53
|
}
|
|
@@ -1,39 +1,71 @@
|
|
|
1
|
-
type JsonObject = Record<string, unknown>;
|
|
2
|
-
|
|
3
|
-
type SchemasDocument = {
|
|
4
|
-
$defs?: Record<string, JsonObject>;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
type ResourceTypeShell = JsonObject & {
|
|
8
|
-
handle?: unknown;
|
|
9
|
-
name?: unknown;
|
|
10
|
-
description?: unknown;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
1
|
+
type JsonObject = Record<string, unknown>;
|
|
2
|
+
|
|
3
|
+
type SchemasDocument = {
|
|
4
|
+
$defs?: Record<string, JsonObject>;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
type ResourceTypeShell = JsonObject & {
|
|
8
|
+
handle?: unknown;
|
|
9
|
+
name?: unknown;
|
|
10
|
+
description?: unknown;
|
|
11
|
+
ingestorToolInputSchema?: unknown;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type ResourceTypeShellByName = Record<string, ResourceTypeShell>;
|
|
15
|
+
|
|
16
|
+
export function generateResourceTypes(
|
|
17
|
+
schemasDocument: SchemasDocument,
|
|
18
|
+
resourceTypeShells: ResourceTypeShellByName,
|
|
19
|
+
): ResourceTypeShell[] {
|
|
20
|
+
if (!schemasDocument.$defs || typeof schemasDocument.$defs !== 'object') {
|
|
21
|
+
throw new Error('Schema document must have root $defs');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const resourceTypes: ResourceTypeShell[] = [];
|
|
25
|
+
|
|
26
|
+
for (const [resourceTypeName, resourceTypeShell] of Object.entries(resourceTypeShells)) {
|
|
27
|
+
const projectionSchema = schemasDocument.$defs[resourceTypeName];
|
|
28
|
+
const ingestorToolInputSchemaDefName = resourceTypeShell.ingestorToolInputSchema;
|
|
29
|
+
|
|
30
|
+
if (!projectionSchema || typeof projectionSchema !== 'object' || Array.isArray(projectionSchema)) {
|
|
31
|
+
throw new Error(`Missing matching schema for resource type record ${resourceTypeName}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (
|
|
35
|
+
ingestorToolInputSchemaDefName !== undefined &&
|
|
36
|
+
typeof ingestorToolInputSchemaDefName !== 'string'
|
|
37
|
+
) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`ingestorToolInputSchema for resource type record ${resourceTypeName} must be a schema definition name when present`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const ingestorToolInputSchema =
|
|
44
|
+
typeof ingestorToolInputSchemaDefName === 'string'
|
|
45
|
+
? schemasDocument.$defs[ingestorToolInputSchemaDefName]
|
|
46
|
+
: undefined;
|
|
47
|
+
|
|
48
|
+
if (typeof ingestorToolInputSchemaDefName === 'string' && !ingestorToolInputSchema) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Missing ingestor input schema ${ingestorToolInputSchemaDefName} for resource type record ${resourceTypeName}`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (
|
|
55
|
+
ingestorToolInputSchema !== undefined &&
|
|
56
|
+
(typeof ingestorToolInputSchema !== 'object' || Array.isArray(ingestorToolInputSchema))
|
|
57
|
+
) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Ingestor input schema ${ingestorToolInputSchemaDefName} for resource type record ${resourceTypeName} must be an object`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
resourceTypes.push({
|
|
64
|
+
...resourceTypeShell,
|
|
65
|
+
projectionSchema,
|
|
66
|
+
...(ingestorToolInputSchema ? { ingestorToolInputSchema } : {}),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return resourceTypes;
|
|
39
71
|
}
|