@izara_project/izara-core-generate-service-code 1.0.104 → 1.0.105
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@izara_project/izara-core-generate-service-code",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.105",
|
|
4
4
|
"description": "Code for locally generating per service files",
|
|
5
5
|
"homepage": "https://bitbucket.org/izara-core-support-services/izara-core-support-services-generate-service-code#readme",
|
|
6
6
|
"repository": {
|
|
@@ -167,9 +167,9 @@ export async function resolveAndGenerateIdentifiers(
|
|
|
167
167
|
const targetIdentifiers = requestParams.targetIdentifiers;
|
|
168
168
|
|
|
169
169
|
const objectSchemas =
|
|
170
|
-
|
|
170
|
+
await getObjectSchema.getObjectSchemaCombineFieldNamesWithCache(
|
|
171
171
|
_izContext,
|
|
172
|
-
|
|
172
|
+
objType
|
|
173
173
|
);
|
|
174
174
|
_izContext.logger.debug(
|
|
175
175
|
`[${process.env.iz_serviceTag}:<%- flowTag %>] objectSchemas:`,
|
|
@@ -997,32 +997,29 @@ export async function publishCompletionMessage(_izContext, message, messageAttri
|
|
|
997
997
|
* Resolves and combines object schemas from S3/hierarchy
|
|
998
998
|
* @param {Object} _izContext - Izara context object
|
|
999
999
|
* @param {string} objectType - Object type identifier
|
|
1000
|
-
* @returns {Promise<{ objType: Object,
|
|
1000
|
+
* @returns {Promise<{ objType: Object, objectSchemas: Object, parentObject?: Object }>}
|
|
1001
1001
|
*/
|
|
1002
1002
|
export async function resolveObjectSchemas(_izContext, objectType) {
|
|
1003
1003
|
const objType = createObjType(objectType);
|
|
1004
|
-
const objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(
|
|
1005
|
-
_izContext,
|
|
1006
|
-
objType
|
|
1007
|
-
);
|
|
1008
|
-
_izContext.logger.debug(`[${process.env.iz_serviceTag}:<%- flowTag %>LogicalLib] objectSchema:`, objectSchema);
|
|
1009
|
-
|
|
1010
1004
|
const objectSchemas =
|
|
1011
|
-
|
|
1005
|
+
await getObjectSchema.getObjectSchemaCombineFieldNamesWithCache(
|
|
1012
1006
|
_izContext,
|
|
1013
|
-
|
|
1007
|
+
objType
|
|
1014
1008
|
);
|
|
1015
|
-
_izContext.logger.debug(
|
|
1009
|
+
_izContext.logger.debug(
|
|
1010
|
+
`[${process.env.iz_serviceTag}:<%- flowTag %>LogicalLib] objectSchemas:`,
|
|
1011
|
+
objectSchemas
|
|
1012
|
+
);
|
|
1016
1013
|
|
|
1017
1014
|
let parentObject;
|
|
1018
1015
|
if (objectSchemas.hasOwnProperty('extendObjType')) {
|
|
1019
1016
|
parentObject = await getObjectSchema.getObjSchemaS3WithHierarchy(
|
|
1020
1017
|
_izContext,
|
|
1021
|
-
|
|
1018
|
+
objectSchemas.extendObjType
|
|
1022
1019
|
);
|
|
1023
1020
|
}
|
|
1024
1021
|
|
|
1025
|
-
return { objType,
|
|
1022
|
+
return { objType, objectSchemas, parentObject };
|
|
1026
1023
|
}
|
|
1027
1024
|
|
|
1028
1025
|
/**
|
|
@@ -1473,7 +1470,7 @@ export async function <%- flowTag %>LogicalLib(
|
|
|
1473
1470
|
//(</beforeCreateMainLogical>)
|
|
1474
1471
|
|
|
1475
1472
|
// 1. Load and resolve Schema
|
|
1476
|
-
const { objType,
|
|
1473
|
+
const { objType, objectSchemas, parentObject } =
|
|
1477
1474
|
await resolveObjectSchemas(_izContext, requestParams.objectType);
|
|
1478
1475
|
|
|
1479
1476
|
const directInvoke =
|
|
@@ -1551,7 +1548,7 @@ export async function <%- flowTag %>LogicalLib(
|
|
|
1551
1548
|
const identifiersForCreateData =
|
|
1552
1549
|
await dynamoDbIdentifiersByStorageResource(
|
|
1553
1550
|
_izContext,
|
|
1554
|
-
|
|
1551
|
+
objectSchemas,
|
|
1555
1552
|
createDataDetails,
|
|
1556
1553
|
objInstanceFullForDynamoDb.identifiers
|
|
1557
1554
|
);
|
|
@@ -1591,7 +1588,7 @@ export async function <%- flowTag %>LogicalLib(
|
|
|
1591
1588
|
|
|
1592
1589
|
// Auto-provision owner TargetRole for DynamoDB-only
|
|
1593
1590
|
await autoProvisionOwnerTargetRoleForDynamoOnly(_izContext, {
|
|
1594
|
-
objectSchema,
|
|
1591
|
+
objectSchema: objectSchemas,
|
|
1595
1592
|
identifiersForCreateData,
|
|
1596
1593
|
requestParams
|
|
1597
1594
|
});
|
|
@@ -2,7 +2,33 @@ export default [
|
|
|
2
2
|
{
|
|
3
3
|
"<%= relationshipTag %>": {
|
|
4
4
|
<% Object.entries(content).forEach(([key, val]) => { -%>
|
|
5
|
+
<% if (key === 'links' && Array.isArray(val)) { -%>
|
|
6
|
+
"links": [
|
|
7
|
+
<% val.forEach((link) => { -%>
|
|
8
|
+
<%- JSON.stringify(link, null, 6).replace(/\n/g, '\n ') %>,
|
|
9
|
+
<% }); -%>
|
|
10
|
+
//(<<%= relationshipTag %>LinksHookCode>)
|
|
11
|
+
//(</<%= relationshipTag %>LinksHookCode>)
|
|
12
|
+
],
|
|
13
|
+
<% } else if (key === 'storageResources' && typeof val === 'object' && val !== null) { -%>
|
|
14
|
+
"storageResources": {
|
|
15
|
+
<% Object.entries(val).forEach(([resKey, resVal]) => { -%>
|
|
16
|
+
"<%- resKey %>": <%- JSON.stringify(resVal, null, 6).replace(/\n/g, '\n ') %>,
|
|
17
|
+
<% }); -%>
|
|
18
|
+
//(<<%= relationshipTag %>StorageResourcesHookCode>)
|
|
19
|
+
//(</<%= relationshipTag %>StorageResourcesHookCode>)
|
|
20
|
+
},
|
|
21
|
+
<% } else if (key === 'fieldNames' && typeof val === 'object' && val !== null) { -%>
|
|
22
|
+
"fieldNames": {
|
|
23
|
+
<% Object.entries(val).forEach(([fKey, fVal]) => { -%>
|
|
24
|
+
"<%- fKey %>": <%- JSON.stringify(fVal, null, 6).replace(/\n/g, '\n ') %>,
|
|
25
|
+
<% }); -%>
|
|
26
|
+
//(<<%= relationshipTag %>FieldNamesHookCode>)
|
|
27
|
+
//(</<%= relationshipTag %>FieldNamesHookCode>)
|
|
28
|
+
},
|
|
29
|
+
<% } else { -%>
|
|
5
30
|
"<%- key %>": <%- JSON.stringify(val, null, 6).replace(/\n/g, '\n ') %>,
|
|
31
|
+
<% } -%>
|
|
6
32
|
<% }); -%>
|
|
7
33
|
//(<<%= relationshipTag %>HookCode>)
|
|
8
34
|
//(</<%= relationshipTag %>HookCode>)
|
|
@@ -166,14 +166,50 @@ test('emitLedgerRelationshipSchemas returns current, old, and is relationship sc
|
|
|
166
166
|
currentRel.content,
|
|
167
167
|
/\/\/\(<currentUnitStandardSupplyLocationHookCode>\)[\s\S]*?\/\/\(<\/currentUnitStandardSupplyLocationHookCode>\)/
|
|
168
168
|
);
|
|
169
|
+
assert.match(
|
|
170
|
+
currentRel.content,
|
|
171
|
+
/\/\/\(<currentUnitStandardSupplyLocationStorageResourcesHookCode>\)[\s\S]*?\/\/\(<\/currentUnitStandardSupplyLocationStorageResourcesHookCode>\)/
|
|
172
|
+
);
|
|
173
|
+
assert.match(
|
|
174
|
+
currentRel.content,
|
|
175
|
+
/\/\/\(<currentUnitStandardSupplyLocationFieldNamesHookCode>\)[\s\S]*?\/\/\(<\/currentUnitStandardSupplyLocationFieldNamesHookCode>\)/
|
|
176
|
+
);
|
|
177
|
+
assert.match(
|
|
178
|
+
currentRel.content,
|
|
179
|
+
/\/\/\(<currentUnitStandardSupplyLocationLinksHookCode>\)[\s\S]*?\/\/\(<\/currentUnitStandardSupplyLocationLinksHookCode>\)/
|
|
180
|
+
);
|
|
169
181
|
assert.match(
|
|
170
182
|
oldRel.content,
|
|
171
183
|
/\/\/\(<oldUnitStandardSupplyLocationHookCode>\)[\s\S]*?\/\/\(<\/oldUnitStandardSupplyLocationHookCode>\)/
|
|
172
184
|
);
|
|
185
|
+
assert.match(
|
|
186
|
+
oldRel.content,
|
|
187
|
+
/\/\/\(<oldUnitStandardSupplyLocationStorageResourcesHookCode>\)[\s\S]*?\/\/\(<\/oldUnitStandardSupplyLocationStorageResourcesHookCode>\)/
|
|
188
|
+
);
|
|
189
|
+
assert.match(
|
|
190
|
+
oldRel.content,
|
|
191
|
+
/\/\/\(<oldUnitStandardSupplyLocationFieldNamesHookCode>\)[\s\S]*?\/\/\(<\/oldUnitStandardSupplyLocationFieldNamesHookCode>\)/
|
|
192
|
+
);
|
|
193
|
+
assert.match(
|
|
194
|
+
oldRel.content,
|
|
195
|
+
/\/\/\(<oldUnitStandardSupplyLocationLinksHookCode>\)[\s\S]*?\/\/\(<\/oldUnitStandardSupplyLocationLinksHookCode>\)/
|
|
196
|
+
);
|
|
173
197
|
assert.match(
|
|
174
198
|
isRel.content,
|
|
175
199
|
/\/\/\(<isUnitStandardSupplyLocationEntryHookCode>\)[\s\S]*?\/\/\(<\/isUnitStandardSupplyLocationEntryHookCode>\)/
|
|
176
200
|
);
|
|
201
|
+
assert.match(
|
|
202
|
+
isRel.content,
|
|
203
|
+
/\/\/\(<isUnitStandardSupplyLocationEntryStorageResourcesHookCode>\)[\s\S]*?\/\/\(<\/isUnitStandardSupplyLocationEntryStorageResourcesHookCode>\)/
|
|
204
|
+
);
|
|
205
|
+
assert.match(
|
|
206
|
+
isRel.content,
|
|
207
|
+
/\/\/\(<isUnitStandardSupplyLocationEntryFieldNamesHookCode>\)[\s\S]*?\/\/\(<\/isUnitStandardSupplyLocationEntryFieldNamesHookCode>\)/
|
|
208
|
+
);
|
|
209
|
+
assert.match(
|
|
210
|
+
isRel.content,
|
|
211
|
+
/\/\/\(<isUnitStandardSupplyLocationEntryLinksHookCode>\)[\s\S]*?\/\/\(<\/isUnitStandardSupplyLocationEntryLinksHookCode>\)/
|
|
212
|
+
);
|
|
177
213
|
|
|
178
214
|
// 5. Verify requiredOnCreate is removed from links
|
|
179
215
|
const _parseRel = (content) => {
|
|
@@ -181,7 +217,7 @@ test('emitLedgerRelationshipSchemas returns current, old, and is relationship sc
|
|
|
181
217
|
.replace(/^export default\s+/, '')
|
|
182
218
|
.replace(/;\s*$/, '')
|
|
183
219
|
.replace(/\/\/.*/g, '')
|
|
184
|
-
.replace(/,(\s*})/g, '$1');
|
|
220
|
+
.replace(/,(\s*[}\]])/g, '$1');
|
|
185
221
|
return JSON.parse(raw)[0];
|
|
186
222
|
};
|
|
187
223
|
|
|
@@ -263,6 +299,18 @@ test('generate preserves user hooks in ledger ObjectSchemas and RelationshipSche
|
|
|
263
299
|
'//(<currentUnitStandardSupplyLocationHookCode>)\n //(</currentUnitStandardSupplyLocationHookCode>)',
|
|
264
300
|
'//(<currentUnitStandardSupplyLocationHookCode>)\n "customRelProp": true,\n //(</currentUnitStandardSupplyLocationHookCode>)'
|
|
265
301
|
);
|
|
302
|
+
relContent = relContent.replace(
|
|
303
|
+
'//(<currentUnitStandardSupplyLocationStorageResourcesHookCode>)\n //(</currentUnitStandardSupplyLocationStorageResourcesHookCode>)',
|
|
304
|
+
'//(<currentUnitStandardSupplyLocationStorageResourcesHookCode>)\n "customRes": { "storageType": "graph" },\n //(</currentUnitStandardSupplyLocationStorageResourcesHookCode>)'
|
|
305
|
+
);
|
|
306
|
+
relContent = relContent.replace(
|
|
307
|
+
'//(<currentUnitStandardSupplyLocationFieldNamesHookCode>)\n //(</currentUnitStandardSupplyLocationFieldNamesHookCode>)',
|
|
308
|
+
'//(<currentUnitStandardSupplyLocationFieldNamesHookCode>)\n "customRelField": { "type": "string" },\n //(</currentUnitStandardSupplyLocationFieldNamesHookCode>)'
|
|
309
|
+
);
|
|
310
|
+
relContent = relContent.replace(
|
|
311
|
+
'//(<currentUnitStandardSupplyLocationLinksHookCode>)\n //(</currentUnitStandardSupplyLocationLinksHookCode>)',
|
|
312
|
+
'//(<currentUnitStandardSupplyLocationLinksHookCode>)\n { "customLinkProp": true },\n //(</currentUnitStandardSupplyLocationLinksHookCode>)'
|
|
313
|
+
);
|
|
266
314
|
await writeProjectFile(rootPath, relRelPath, relContent);
|
|
267
315
|
|
|
268
316
|
// Re-run generate
|
|
@@ -273,6 +321,9 @@ test('generate preserves user hooks in ledger ObjectSchemas and RelationshipSche
|
|
|
273
321
|
|
|
274
322
|
const preservedRelContent = await readProjectFile(rootPath, relRelPath);
|
|
275
323
|
assert.match(preservedRelContent, /"customRelProp": true/);
|
|
324
|
+
assert.match(preservedRelContent, /"customRes": \{ "storageType": "graph" \}/);
|
|
325
|
+
assert.match(preservedRelContent, /"customRelField": \{ "type": "string" \}/);
|
|
326
|
+
assert.match(preservedRelContent, /"customLinkProp": true/);
|
|
276
327
|
});
|
|
277
328
|
|
|
278
329
|
test('emitLedgerObjectSchemas and managedPaths skip when entryObject is false', async () => {
|