@toolproof-core/genesis 1.0.52 → 1.0.53
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/utils/constantsAndMappings.d.ts +20 -2
- package/dist/src/utils/constantsAndMappings.js +113 -5
- package/generated-src/lookups/constants.ts +67 -0
- package/generated-src/lookups/mappings.ts +1 -1
- package/generated-src/metadata/Core.json +12 -12
- package/package.json +1 -1
- package/src/utils/constantsAndMappings.ts +172 -6
|
@@ -1,17 +1,35 @@
|
|
|
1
1
|
type JSONValue = null | boolean | number | string | JSONValue[] | {
|
|
2
2
|
[k: string]: JSONValue;
|
|
3
3
|
};
|
|
4
|
+
type HandleRecord = {
|
|
5
|
+
handle?: unknown;
|
|
6
|
+
};
|
|
7
|
+
type HandleRecordByName = Record<string, HandleRecord>;
|
|
8
|
+
type ToolRecord = HandleRecord & {
|
|
9
|
+
isTemplate?: unknown;
|
|
10
|
+
templateToolHandle?: unknown;
|
|
11
|
+
instantiationRoleSpec?: unknown;
|
|
12
|
+
roleSpec?: unknown;
|
|
13
|
+
};
|
|
14
|
+
type ToolRecordByName = Record<string, ToolRecord>;
|
|
4
15
|
export type GeneratedConstants = {
|
|
5
16
|
Names: Record<string, string>;
|
|
17
|
+
Handles: {
|
|
18
|
+
ResourceTypes: Record<string, string>;
|
|
19
|
+
Tools: Record<string, string>;
|
|
20
|
+
};
|
|
21
|
+
ToolRoleNames: Record<string, Record<string, string>>;
|
|
6
22
|
Enums: Record<string, Record<string, string>>;
|
|
7
23
|
};
|
|
8
24
|
export type GeneratedMappings = {
|
|
9
|
-
|
|
25
|
+
IdentifierNameToPrefix: Record<string, string>;
|
|
10
26
|
};
|
|
11
27
|
export declare function extractHandlePrefixes(schema: unknown): Record<string, string>;
|
|
12
28
|
export declare function extractSubschemaNames(schema: unknown): Record<string, string>;
|
|
13
29
|
export declare function extractEnums(schema: unknown): Record<string, Record<string, string>>;
|
|
14
|
-
export declare function
|
|
30
|
+
export declare function extractHandles(records: HandleRecordByName): Record<string, string>;
|
|
31
|
+
export declare function extractToolRoleNames(tools: ToolRecordByName): Record<string, Record<string, string>>;
|
|
32
|
+
export declare function extractGeneratedConstantsAndMappings(schema: JSONValue, resourceTypeShells: HandleRecordByName, tools: ToolRecordByName): {
|
|
15
33
|
CONSTANTS: GeneratedConstants;
|
|
16
34
|
MAPPINGS: GeneratedMappings;
|
|
17
35
|
};
|
|
@@ -78,17 +78,96 @@ export function extractEnums(schema) {
|
|
|
78
78
|
}
|
|
79
79
|
return out;
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
function toHandleConstantKey(handle) {
|
|
82
|
+
return handle.replace(/[^A-Za-z0-9]+/g, '_');
|
|
83
|
+
}
|
|
84
|
+
export function extractHandles(records) {
|
|
85
|
+
const recordEntries = Object.entries(records);
|
|
86
|
+
recordEntries.sort(([a], [b]) => a.localeCompare(b));
|
|
87
|
+
const out = {};
|
|
88
|
+
for (const [, record] of recordEntries) {
|
|
89
|
+
if (!record || typeof record !== 'object')
|
|
90
|
+
continue;
|
|
91
|
+
if (typeof record.handle !== 'string')
|
|
92
|
+
continue;
|
|
93
|
+
if (!record.handle || /[\n\r`]/.test(record.handle))
|
|
94
|
+
continue;
|
|
95
|
+
out[toHandleConstantKey(record.handle)] = record.handle;
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
function isPlainObject(value) {
|
|
100
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
101
|
+
}
|
|
102
|
+
function extractRoleNameMap(roleSpec) {
|
|
103
|
+
if (!isPlainObject(roleSpec)) {
|
|
104
|
+
return {};
|
|
105
|
+
}
|
|
106
|
+
const out = {};
|
|
107
|
+
const groups = [
|
|
108
|
+
roleSpec.inputRoleValueByName,
|
|
109
|
+
roleSpec.outputRoleValueByName,
|
|
110
|
+
];
|
|
111
|
+
for (const group of groups) {
|
|
112
|
+
if (!isPlainObject(group)) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const entries = Object.keys(group).sort((a, b) => a.localeCompare(b));
|
|
116
|
+
for (const roleName of entries) {
|
|
117
|
+
if (!roleName || /[\n\r`]/.test(roleName)) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
out[roleName] = roleName;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
function isCanonicalToolRecord(tool) {
|
|
126
|
+
if (tool.isTemplate === true) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
return tool.isTemplate === false && tool.templateToolHandle === undefined;
|
|
130
|
+
}
|
|
131
|
+
export function extractToolRoleNames(tools) {
|
|
132
|
+
const toolEntries = Object.values(tools)
|
|
133
|
+
.filter((tool) => isPlainObject(tool))
|
|
134
|
+
.filter((tool) => typeof tool.handle === 'string' && !!tool.handle)
|
|
135
|
+
.sort((a, b) => String(a.handle).localeCompare(String(b.handle)));
|
|
136
|
+
const out = {};
|
|
137
|
+
for (const tool of toolEntries) {
|
|
138
|
+
if (!isCanonicalToolRecord(tool)) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const roleSpec = tool.isTemplate === true
|
|
142
|
+
? tool.instantiationRoleSpec
|
|
143
|
+
: tool.roleSpec;
|
|
144
|
+
const roleNameMap = extractRoleNameMap(roleSpec);
|
|
145
|
+
if (Object.keys(roleNameMap).length === 0) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
out[toHandleConstantKey(tool.handle)] = roleNameMap;
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
export function extractGeneratedConstantsAndMappings(schema, resourceTypeShells, tools) {
|
|
82
153
|
const names = extractSubschemaNames(schema);
|
|
154
|
+
const resourceTypeHandles = extractHandles(resourceTypeShells);
|
|
155
|
+
const toolHandles = extractHandles(tools);
|
|
156
|
+
const toolRoleNames = extractToolRoleNames(tools);
|
|
83
157
|
const enums = extractEnums(schema);
|
|
84
158
|
const handlePrefixes = extractHandlePrefixes(schema);
|
|
85
159
|
return {
|
|
86
160
|
CONSTANTS: {
|
|
87
161
|
Names: names,
|
|
162
|
+
Handles: {
|
|
163
|
+
ResourceTypes: resourceTypeHandles,
|
|
164
|
+
Tools: toolHandles,
|
|
165
|
+
},
|
|
166
|
+
ToolRoleNames: toolRoleNames,
|
|
88
167
|
Enums: enums,
|
|
89
168
|
},
|
|
90
169
|
MAPPINGS: {
|
|
91
|
-
|
|
170
|
+
IdentifierNameToPrefix: handlePrefixes,
|
|
92
171
|
},
|
|
93
172
|
};
|
|
94
173
|
}
|
|
@@ -111,6 +190,9 @@ function renderTsKey(key) {
|
|
|
111
190
|
}
|
|
112
191
|
export function renderConstantsTs(constants) {
|
|
113
192
|
const nameKeys = Object.keys(constants.Names).sort((a, b) => a.localeCompare(b));
|
|
193
|
+
const resourceTypeHandleKeys = Object.keys(constants.Handles.ResourceTypes).sort((a, b) => a.localeCompare(b));
|
|
194
|
+
const toolHandleKeys = Object.keys(constants.Handles.Tools).sort((a, b) => a.localeCompare(b));
|
|
195
|
+
const toolRoleNameKeys = Object.keys(constants.ToolRoleNames).sort((a, b) => a.localeCompare(b));
|
|
114
196
|
const enumKeys = Object.keys(constants.Enums).sort((a, b) => a.localeCompare(b));
|
|
115
197
|
const lines = [];
|
|
116
198
|
lines.push('const CONSTANTS = {');
|
|
@@ -120,6 +202,32 @@ export function renderConstantsTs(constants) {
|
|
|
120
202
|
lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
|
|
121
203
|
}
|
|
122
204
|
lines.push(' },');
|
|
205
|
+
lines.push(' Handles: {');
|
|
206
|
+
lines.push(' ResourceTypes: {');
|
|
207
|
+
for (const key of resourceTypeHandleKeys) {
|
|
208
|
+
const value = constants.Handles.ResourceTypes[key] ?? '';
|
|
209
|
+
lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
|
|
210
|
+
}
|
|
211
|
+
lines.push(' },');
|
|
212
|
+
lines.push(' Tools: {');
|
|
213
|
+
for (const key of toolHandleKeys) {
|
|
214
|
+
const value = constants.Handles.Tools[key] ?? '';
|
|
215
|
+
lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
|
|
216
|
+
}
|
|
217
|
+
lines.push(' },');
|
|
218
|
+
lines.push(' },');
|
|
219
|
+
lines.push(' ToolRoleNames: {');
|
|
220
|
+
for (const toolKey of toolRoleNameKeys) {
|
|
221
|
+
const roleNames = constants.ToolRoleNames[toolKey] ?? {};
|
|
222
|
+
const roleKeys = Object.keys(roleNames).sort((a, b) => a.localeCompare(b));
|
|
223
|
+
lines.push(` ${renderTsKey(toolKey)}: {`);
|
|
224
|
+
for (const roleKey of roleKeys) {
|
|
225
|
+
const value = roleNames[roleKey] ?? '';
|
|
226
|
+
lines.push(` ${renderTsKey(roleKey)}: ${renderTsStringLiteral(value)},`);
|
|
227
|
+
}
|
|
228
|
+
lines.push(' },');
|
|
229
|
+
}
|
|
230
|
+
lines.push(' },');
|
|
123
231
|
lines.push(' Enums: {');
|
|
124
232
|
for (const key of enumKeys) {
|
|
125
233
|
const members = constants.Enums[key] ?? {};
|
|
@@ -138,12 +246,12 @@ export function renderConstantsTs(constants) {
|
|
|
138
246
|
return lines.join('\n');
|
|
139
247
|
}
|
|
140
248
|
export function renderMappingsTs(mappings) {
|
|
141
|
-
const handleKeys = Object.keys(mappings.
|
|
249
|
+
const handleKeys = Object.keys(mappings.IdentifierNameToPrefix).sort((a, b) => a.localeCompare(b));
|
|
142
250
|
const lines = [];
|
|
143
251
|
lines.push('const MAPPINGS = {');
|
|
144
|
-
lines.push('
|
|
252
|
+
lines.push(' IdentifierNameToPrefix: {');
|
|
145
253
|
for (const key of handleKeys) {
|
|
146
|
-
const value = mappings.
|
|
254
|
+
const value = mappings.IdentifierNameToPrefix[key] ?? '';
|
|
147
255
|
lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
|
|
148
256
|
}
|
|
149
257
|
lines.push(' },');
|
|
@@ -92,6 +92,73 @@ const CONSTANTS = {
|
|
|
92
92
|
UnthreadedToolStepPathSpec: 'UnthreadedToolStepPathSpec',
|
|
93
93
|
WhileStep: 'WhileStep',
|
|
94
94
|
},
|
|
95
|
+
Handles: {
|
|
96
|
+
ResourceTypes: {
|
|
97
|
+
TYPE_Boolean: 'TYPE-Boolean',
|
|
98
|
+
TYPE_Error: 'TYPE-Error',
|
|
99
|
+
TYPE_Goal: 'TYPE-Goal',
|
|
100
|
+
TYPE_Natural: 'TYPE-Natural',
|
|
101
|
+
TYPE_Resource: 'TYPE-Resource',
|
|
102
|
+
TYPE_ResourceType: 'TYPE-ResourceType',
|
|
103
|
+
TYPE_Strategy: 'TYPE-Strategy',
|
|
104
|
+
TYPE_StrategyTrace: 'TYPE-StrategyTrace',
|
|
105
|
+
TYPE_Suite: 'TYPE-Suite',
|
|
106
|
+
TYPE_Tool: 'TYPE-Tool',
|
|
107
|
+
},
|
|
108
|
+
Tools: {
|
|
109
|
+
TOOL_Add: 'TOOL-Add',
|
|
110
|
+
TOOL_BooleanIdentity: 'TOOL-BooleanIdentity',
|
|
111
|
+
TOOL_Divide: 'TOOL-Divide',
|
|
112
|
+
TOOL_Double: 'TOOL-Double',
|
|
113
|
+
TOOL_Identity: 'TOOL-Identity',
|
|
114
|
+
TOOL_LessThan: 'TOOL-LessThan',
|
|
115
|
+
TOOL_Multiply: 'TOOL-Multiply',
|
|
116
|
+
TOOL_NaturalAdd: 'TOOL-NaturalAdd',
|
|
117
|
+
TOOL_NaturalDivide: 'TOOL-NaturalDivide',
|
|
118
|
+
TOOL_NaturalDouble: 'TOOL-NaturalDouble',
|
|
119
|
+
TOOL_NaturalIdentity: 'TOOL-NaturalIdentity',
|
|
120
|
+
TOOL_NaturalLessThan: 'TOOL-NaturalLessThan',
|
|
121
|
+
TOOL_NaturalMultiply: 'TOOL-NaturalMultiply',
|
|
122
|
+
TOOL_NaturalSubtract: 'TOOL-NaturalSubtract',
|
|
123
|
+
TOOL_Subtract: 'TOOL-Subtract',
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
ToolRoleNames: {
|
|
127
|
+
TOOL_Add: {
|
|
128
|
+
AddendOne: 'AddendOne',
|
|
129
|
+
AddendTwo: 'AddendTwo',
|
|
130
|
+
Sum: 'Sum',
|
|
131
|
+
},
|
|
132
|
+
TOOL_Divide: {
|
|
133
|
+
Dividend: 'Dividend',
|
|
134
|
+
Divisor: 'Divisor',
|
|
135
|
+
Quotient: 'Quotient',
|
|
136
|
+
Remainder: 'Remainder',
|
|
137
|
+
},
|
|
138
|
+
TOOL_Double: {
|
|
139
|
+
Doubled: 'Doubled',
|
|
140
|
+
N: 'N',
|
|
141
|
+
},
|
|
142
|
+
TOOL_Identity: {
|
|
143
|
+
In: 'In',
|
|
144
|
+
Out: 'Out',
|
|
145
|
+
},
|
|
146
|
+
TOOL_LessThan: {
|
|
147
|
+
LessThanDecision: 'LessThanDecision',
|
|
148
|
+
LessThanSource: 'LessThanSource',
|
|
149
|
+
LessThanTarget: 'LessThanTarget',
|
|
150
|
+
},
|
|
151
|
+
TOOL_Multiply: {
|
|
152
|
+
Multiplicand: 'Multiplicand',
|
|
153
|
+
Multiplier: 'Multiplier',
|
|
154
|
+
Product: 'Product',
|
|
155
|
+
},
|
|
156
|
+
TOOL_Subtract: {
|
|
157
|
+
Difference: 'Difference',
|
|
158
|
+
Minuend: 'Minuend',
|
|
159
|
+
Subtrahend: 'Subtrahend',
|
|
160
|
+
},
|
|
161
|
+
},
|
|
95
162
|
Enums: {
|
|
96
163
|
ContainerKind: {
|
|
97
164
|
scalar: 'scalar',
|
|
@@ -1422,18 +1422,6 @@
|
|
|
1422
1422
|
"name": "src",
|
|
1423
1423
|
"path": "packages/lib/src",
|
|
1424
1424
|
"children": [
|
|
1425
|
-
{
|
|
1426
|
-
"kind": "directory",
|
|
1427
|
-
"name": "artifacts",
|
|
1428
|
-
"path": "packages/lib/src/artifacts",
|
|
1429
|
-
"children": [
|
|
1430
|
-
{
|
|
1431
|
-
"kind": "file",
|
|
1432
|
-
"name": "artifacts.ts",
|
|
1433
|
-
"path": "packages/lib/src/artifacts/artifacts.ts"
|
|
1434
|
-
}
|
|
1435
|
-
]
|
|
1436
|
-
},
|
|
1437
1425
|
{
|
|
1438
1426
|
"kind": "directory",
|
|
1439
1427
|
"name": "integrations",
|
|
@@ -1468,6 +1456,18 @@
|
|
|
1468
1456
|
}
|
|
1469
1457
|
]
|
|
1470
1458
|
},
|
|
1459
|
+
{
|
|
1460
|
+
"kind": "directory",
|
|
1461
|
+
"name": "lookups",
|
|
1462
|
+
"path": "packages/lib/src/lookups",
|
|
1463
|
+
"children": [
|
|
1464
|
+
{
|
|
1465
|
+
"kind": "file",
|
|
1466
|
+
"name": "lookups.ts",
|
|
1467
|
+
"path": "packages/lib/src/lookups/lookups.ts"
|
|
1468
|
+
}
|
|
1469
|
+
]
|
|
1470
|
+
},
|
|
1471
1471
|
{
|
|
1472
1472
|
"kind": "directory",
|
|
1473
1473
|
"name": "types",
|
package/package.json
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
type JSONValue = null | boolean | number | string | JSONValue[] | { [k: string]: JSONValue };
|
|
2
2
|
|
|
3
|
+
type HandleRecord = {
|
|
4
|
+
handle?: unknown;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
type HandleRecordByName = Record<string, HandleRecord>;
|
|
8
|
+
|
|
9
|
+
type RoleValueByNameRecord = Record<string, unknown>;
|
|
10
|
+
|
|
11
|
+
type RoleSpecRecord = {
|
|
12
|
+
inputRoleValueByName?: unknown;
|
|
13
|
+
outputRoleValueByName?: unknown;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type ToolRecord = HandleRecord & {
|
|
17
|
+
isTemplate?: unknown;
|
|
18
|
+
templateToolHandle?: unknown;
|
|
19
|
+
instantiationRoleSpec?: unknown;
|
|
20
|
+
roleSpec?: unknown;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type ToolRecordByName = Record<string, ToolRecord>;
|
|
24
|
+
|
|
3
25
|
export type GeneratedConstants = {
|
|
4
26
|
Names: Record<string, string>;
|
|
27
|
+
Handles: {
|
|
28
|
+
ResourceTypes: Record<string, string>;
|
|
29
|
+
Tools: Record<string, string>;
|
|
30
|
+
};
|
|
31
|
+
ToolRoleNames: Record<string, Record<string, string>>;
|
|
5
32
|
Enums: Record<string, Record<string, string>>;
|
|
6
33
|
};
|
|
7
34
|
|
|
8
35
|
export type GeneratedMappings = {
|
|
9
|
-
|
|
36
|
+
IdentifierNameToPrefix: Record<string, string>;
|
|
10
37
|
};
|
|
11
38
|
|
|
12
39
|
function deriveIdPrefixFromPattern(pattern: string): string | undefined {
|
|
@@ -96,21 +123,123 @@ export function extractEnums(schema: unknown): Record<string, Record<string, str
|
|
|
96
123
|
return out;
|
|
97
124
|
}
|
|
98
125
|
|
|
99
|
-
|
|
126
|
+
function toHandleConstantKey(handle: string): string {
|
|
127
|
+
return handle.replace(/[^A-Za-z0-9]+/g, '_');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function extractHandles(records: HandleRecordByName): Record<string, string> {
|
|
131
|
+
const recordEntries = Object.entries(records);
|
|
132
|
+
recordEntries.sort(([a], [b]) => a.localeCompare(b));
|
|
133
|
+
|
|
134
|
+
const out: Record<string, string> = {};
|
|
135
|
+
|
|
136
|
+
for (const [, record] of recordEntries) {
|
|
137
|
+
if (!record || typeof record !== 'object') continue;
|
|
138
|
+
if (typeof record.handle !== 'string') continue;
|
|
139
|
+
if (!record.handle || /[\n\r`]/.test(record.handle)) continue;
|
|
140
|
+
|
|
141
|
+
out[toHandleConstantKey(record.handle)] = record.handle;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
148
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function extractRoleNameMap(roleSpec: unknown): Record<string, string> {
|
|
152
|
+
if (!isPlainObject(roleSpec)) {
|
|
153
|
+
return {};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const out: Record<string, string> = {};
|
|
157
|
+
const groups = [
|
|
158
|
+
roleSpec.inputRoleValueByName,
|
|
159
|
+
roleSpec.outputRoleValueByName,
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
for (const group of groups) {
|
|
163
|
+
if (!isPlainObject(group)) {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const entries = Object.keys(group).sort((a, b) => a.localeCompare(b));
|
|
168
|
+
for (const roleName of entries) {
|
|
169
|
+
if (!roleName || /[\n\r`]/.test(roleName)) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
out[roleName] = roleName;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function isCanonicalToolRecord(tool: ToolRecord): boolean {
|
|
181
|
+
if (tool.isTemplate === true) {
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return tool.isTemplate === false && tool.templateToolHandle === undefined;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function extractToolRoleNames(tools: ToolRecordByName): Record<string, Record<string, string>> {
|
|
189
|
+
const toolEntries = Object.values(tools)
|
|
190
|
+
.filter((tool): tool is ToolRecord => isPlainObject(tool))
|
|
191
|
+
.filter((tool) => typeof tool.handle === 'string' && !!tool.handle)
|
|
192
|
+
.sort((a, b) => String(a.handle).localeCompare(String(b.handle)));
|
|
193
|
+
|
|
194
|
+
const out: Record<string, Record<string, string>> = {};
|
|
195
|
+
|
|
196
|
+
for (const tool of toolEntries) {
|
|
197
|
+
if (!isCanonicalToolRecord(tool)) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const roleSpec = tool.isTemplate === true
|
|
202
|
+
? tool.instantiationRoleSpec
|
|
203
|
+
: tool.roleSpec;
|
|
204
|
+
|
|
205
|
+
const roleNameMap = extractRoleNameMap(roleSpec);
|
|
206
|
+
if (Object.keys(roleNameMap).length === 0) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
out[toHandleConstantKey(tool.handle as string)] = roleNameMap;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function extractGeneratedConstantsAndMappings(
|
|
217
|
+
schema: JSONValue,
|
|
218
|
+
resourceTypeShells: HandleRecordByName,
|
|
219
|
+
tools: ToolRecordByName,
|
|
220
|
+
): {
|
|
100
221
|
CONSTANTS: GeneratedConstants;
|
|
101
222
|
MAPPINGS: GeneratedMappings;
|
|
102
223
|
} {
|
|
103
224
|
const names = extractSubschemaNames(schema);
|
|
225
|
+
const resourceTypeHandles = extractHandles(resourceTypeShells);
|
|
226
|
+
const toolHandles = extractHandles(tools);
|
|
227
|
+
const toolRoleNames = extractToolRoleNames(tools);
|
|
104
228
|
const enums = extractEnums(schema);
|
|
105
229
|
const handlePrefixes = extractHandlePrefixes(schema);
|
|
106
230
|
|
|
107
231
|
return {
|
|
108
232
|
CONSTANTS: {
|
|
109
233
|
Names: names,
|
|
234
|
+
Handles: {
|
|
235
|
+
ResourceTypes: resourceTypeHandles,
|
|
236
|
+
Tools: toolHandles,
|
|
237
|
+
},
|
|
238
|
+
ToolRoleNames: toolRoleNames,
|
|
110
239
|
Enums: enums,
|
|
111
240
|
},
|
|
112
241
|
MAPPINGS: {
|
|
113
|
-
|
|
242
|
+
IdentifierNameToPrefix: handlePrefixes,
|
|
114
243
|
},
|
|
115
244
|
};
|
|
116
245
|
}
|
|
@@ -138,6 +267,9 @@ function renderTsKey(key: string): string {
|
|
|
138
267
|
|
|
139
268
|
export function renderConstantsTs(constants: GeneratedConstants): string {
|
|
140
269
|
const nameKeys = Object.keys(constants.Names).sort((a, b) => a.localeCompare(b));
|
|
270
|
+
const resourceTypeHandleKeys = Object.keys(constants.Handles.ResourceTypes).sort((a, b) => a.localeCompare(b));
|
|
271
|
+
const toolHandleKeys = Object.keys(constants.Handles.Tools).sort((a, b) => a.localeCompare(b));
|
|
272
|
+
const toolRoleNameKeys = Object.keys(constants.ToolRoleNames).sort((a, b) => a.localeCompare(b));
|
|
141
273
|
const enumKeys = Object.keys(constants.Enums).sort((a, b) => a.localeCompare(b));
|
|
142
274
|
|
|
143
275
|
const lines: string[] = [];
|
|
@@ -149,6 +281,40 @@ export function renderConstantsTs(constants: GeneratedConstants): string {
|
|
|
149
281
|
lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
|
|
150
282
|
}
|
|
151
283
|
|
|
284
|
+
lines.push(' },');
|
|
285
|
+
lines.push(' Handles: {');
|
|
286
|
+
lines.push(' ResourceTypes: {');
|
|
287
|
+
|
|
288
|
+
for (const key of resourceTypeHandleKeys) {
|
|
289
|
+
const value = constants.Handles.ResourceTypes[key] ?? '';
|
|
290
|
+
lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
lines.push(' },');
|
|
294
|
+
lines.push(' Tools: {');
|
|
295
|
+
|
|
296
|
+
for (const key of toolHandleKeys) {
|
|
297
|
+
const value = constants.Handles.Tools[key] ?? '';
|
|
298
|
+
lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
lines.push(' },');
|
|
302
|
+
lines.push(' },');
|
|
303
|
+
lines.push(' ToolRoleNames: {');
|
|
304
|
+
|
|
305
|
+
for (const toolKey of toolRoleNameKeys) {
|
|
306
|
+
const roleNames = constants.ToolRoleNames[toolKey] ?? {};
|
|
307
|
+
const roleKeys = Object.keys(roleNames).sort((a, b) => a.localeCompare(b));
|
|
308
|
+
lines.push(` ${renderTsKey(toolKey)}: {`);
|
|
309
|
+
|
|
310
|
+
for (const roleKey of roleKeys) {
|
|
311
|
+
const value = roleNames[roleKey] ?? '';
|
|
312
|
+
lines.push(` ${renderTsKey(roleKey)}: ${renderTsStringLiteral(value)},`);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
lines.push(' },');
|
|
316
|
+
}
|
|
317
|
+
|
|
152
318
|
lines.push(' },');
|
|
153
319
|
lines.push(' Enums: {');
|
|
154
320
|
|
|
@@ -174,14 +340,14 @@ export function renderConstantsTs(constants: GeneratedConstants): string {
|
|
|
174
340
|
}
|
|
175
341
|
|
|
176
342
|
export function renderMappingsTs(mappings: GeneratedMappings): string {
|
|
177
|
-
const handleKeys = Object.keys(mappings.
|
|
343
|
+
const handleKeys = Object.keys(mappings.IdentifierNameToPrefix).sort((a, b) => a.localeCompare(b));
|
|
178
344
|
|
|
179
345
|
const lines: string[] = [];
|
|
180
346
|
lines.push('const MAPPINGS = {');
|
|
181
|
-
lines.push('
|
|
347
|
+
lines.push(' IdentifierNameToPrefix: {');
|
|
182
348
|
|
|
183
349
|
for (const key of handleKeys) {
|
|
184
|
-
const value = mappings.
|
|
350
|
+
const value = mappings.IdentifierNameToPrefix[key] ?? '';
|
|
185
351
|
lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
|
|
186
352
|
}
|
|
187
353
|
|