@izara_project/izara-market-library-service-schemas 1.0.12 → 1.0.13
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
|
@@ -160,22 +160,6 @@ const createDeleteRelationshipCompleteHandler = require('./RelationshipPerAction
|
|
|
160
160
|
const createDeleteRelationshipCompleteSnsAndSqs = require('./RelationshipPerAction/DeleteRelationship/DeleteRelationshipComplete/sns-in-sqs/data');
|
|
161
161
|
const createDeleteRelationshipCompleteSnsOut = require('./RelationshipPerAction/DeleteRelationship/DeleteRelationshipComplete/sns-out/data');
|
|
162
162
|
|
|
163
|
-
// TranslateIdRequest
|
|
164
|
-
const createTranslateIdsCacheMainTable = require('./TranslateIdReq/TranslateIds/resourceYaml/dynamoDb/data');
|
|
165
|
-
const createTranslateIdsRequestMainFunction = require('./TranslateIdReq/TranslateIds/mainFunction/data');
|
|
166
|
-
const createTranslateIdsHandlerDsq = require('./TranslateIdReq/TranslateIds/handler/HdrDsq/data');
|
|
167
|
-
const createTranslateIdsHandlerSqs = require('./TranslateIdReq/TranslateIds/handler/HdrSqs/data');
|
|
168
|
-
const createTranslateIdFunctionYamlHdrDsq = require('./TranslateIdReq/TranslateIds/functionYaml/HdrDsq/data');
|
|
169
|
-
const createTranslateIdFunctionYamlHdrSqs = require('./TranslateIdReq/TranslateIds/functionYaml/HdrSqs/data');
|
|
170
|
-
const createSnsAndSqsTranslateId = require('./TranslateIdReq/TranslateIds/resourceYaml/sns-sqs/data');
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
// processTranslateIds
|
|
174
|
-
const createProcessTranslateIdsCompleteSnsOut = require('./TranslateIdReq/ProcessingTranslateIds/sns-out/data');
|
|
175
|
-
const createTranslateIdsProcessSnsQueue = require('./TranslateIdReq/ProcessingTranslateIds/sqs-sns/data');
|
|
176
|
-
const createTranslateIdsProcessFunctionYaml = require('./TranslateIdReq/ProcessingTranslateIds/functionYaml/data');
|
|
177
|
-
const createTranslateIdsProcessHandler = require('./TranslateIdReq/ProcessingTranslateIds/handler/dataHdrDsq');
|
|
178
|
-
const createTranslateIdsProcessMainFunction = require('./TranslateIdReq/ProcessingTranslateIds/mainFunction/data')
|
|
179
163
|
// findData
|
|
180
164
|
const createFindDataFunctionYaml = require('./FindData/FindDataYaml/data');
|
|
181
165
|
const createFindDataHandler = require('./FindData/Handler/data');
|
|
@@ -196,6 +180,11 @@ const createProcessLogicalPaginateFunctionYamlHdrSqs = require('./ProcessLogical
|
|
|
196
180
|
//get functionNameConfig
|
|
197
181
|
const functionNameConfigFile = require('./externalService/FunctionNameConfig/data')
|
|
198
182
|
|
|
183
|
+
//lib of generateCode
|
|
184
|
+
const { checkValidTableYaml } = require('./libs/GenerateCodeUtils');
|
|
185
|
+
|
|
186
|
+
const { NoRetryError } = require('@izara_project/izara-core-library-core');
|
|
187
|
+
|
|
199
188
|
/**
|
|
200
189
|
*
|
|
201
190
|
* get template and send to
|
|
@@ -225,7 +214,6 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
225
214
|
lamdaPerCombindActionPath: join(saveFilePath, `/generatedCode/lamdaPerCombindAction/source/`), // test
|
|
226
215
|
lambdaPerObjectTypePath: join(saveFilePath, `/generatedCode/lambdaPerObjectType/source/`), // test
|
|
227
216
|
updateRelationship: join(saveFilePath, `../src/generatedCode/RelationshipPerAction/source/`),
|
|
228
|
-
translateId: join(saveFilePath, `../src/generatedCode/TranslateId/source/`)
|
|
229
217
|
};
|
|
230
218
|
|
|
231
219
|
|
|
@@ -248,6 +236,9 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
248
236
|
|
|
249
237
|
let createSourceParams = [];
|
|
250
238
|
|
|
239
|
+
// use to check dynamoDB table yaml, to prevent duplicate tableName
|
|
240
|
+
let createdTableYaml = {};
|
|
241
|
+
|
|
251
242
|
for (const relTag in allObjectRelationships) {
|
|
252
243
|
// const relTagData = allObjectRelationships[relTag];
|
|
253
244
|
|
|
@@ -288,12 +279,19 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
288
279
|
const createFunctionYaml = [...createFunctionYamlHdrApi, ...createFunctionYamlHdrDsq, ...createFunctionYamlHdrInv, ...createFunctionYamlHdrSqs];
|
|
289
280
|
|
|
290
281
|
// generate Resource ..via dynamoDb sns-in-sqs sns-put
|
|
291
|
-
|
|
282
|
+
let [createResourceDynamo, newCreatedTableYaml] = checkValidTableYaml(
|
|
283
|
+
_izContext,
|
|
284
|
+
createSourceDataDynamoDB(_izContext, objectSchema, saveFilePath),
|
|
285
|
+
createdTableYaml
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
createdTableYaml = newCreatedTableYaml;
|
|
289
|
+
_izContext.logger.debug("createResourceDynamo: ", createResourceDynamo);
|
|
290
|
+
|
|
292
291
|
const createResourceSnsInSqs = createSourceSnsAndSqs(_izContext, objectSchema, saveFilePath);
|
|
293
292
|
const createResourceSnsOut = createDataForCreateSourceSnsOut(_izContext, objectSchema, saveFilePath);
|
|
294
293
|
|
|
295
294
|
// translateIdsMainFunction
|
|
296
|
-
const translateIdsMainFunction = await createTranslateIdsRequestMainFunction(_izContext, objectSchema, saveFilePath);
|
|
297
295
|
|
|
298
296
|
// wrap main Resource
|
|
299
297
|
const createMainResource = [...createResourceDynamo, ...createResourceSnsInSqs, ...createResourceSnsOut];
|
|
@@ -301,11 +299,10 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
301
299
|
|
|
302
300
|
createSourceParams = createSourceParams.concat([
|
|
303
301
|
// ...createSourceMainResourcesObjectSchema,
|
|
304
|
-
...createSourceHandler,
|
|
305
|
-
...createMainFunction,
|
|
306
|
-
...createFunctionYaml,
|
|
307
|
-
...createMainResource,
|
|
308
|
-
...translateIdsMainFunction,
|
|
302
|
+
...createSourceHandler, // create handler function
|
|
303
|
+
...createMainFunction, // create main function
|
|
304
|
+
...createFunctionYaml, // create function.yaml
|
|
305
|
+
...createMainResource, // create resource yaml
|
|
309
306
|
]);
|
|
310
307
|
|
|
311
308
|
// console.log("createSourceParams after concat: ", createSourceParams);
|
|
@@ -446,24 +443,6 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
446
443
|
|
|
447
444
|
const deleteRelationshipCompleteData = [...deleteRelationshipCompleteFunctionYaml, ...deleteRelationshipCompleteMainFunction, ...deleteRelationshipCompleteHandler, ...deleteRelationshipCompleteSnsAndSqs, ...deleteRelationshipCompleteSnsOut]
|
|
448
445
|
|
|
449
|
-
const translateIdsCacheIdsMainTable = createTranslateIdsCacheMainTable(_izContext, saveFilePath);
|
|
450
|
-
const translateIdsHandlerFunctionDsq = createTranslateIdsHandlerDsq(_izContext, saveFilePath);
|
|
451
|
-
const translateIdsHandlerFunctionSqs = createTranslateIdsHandlerSqs(_izContext, saveFilePath);
|
|
452
|
-
const translateIdsFunctionYamlDsq = createTranslateIdFunctionYamlHdrDsq(_izContext, saveFilePath);
|
|
453
|
-
const translateIdsFunctionYamlSqs = createTranslateIdFunctionYamlHdrSqs(_izContext, saveFilePath);
|
|
454
|
-
const translateIdsSnsAndSqsResourceQueue = createSnsAndSqsTranslateId(_izContext, saveFilePath);
|
|
455
|
-
|
|
456
|
-
const createTranslateIdsResourece = [...translateIdsCacheIdsMainTable, ...translateIdsHandlerFunctionDsq, ...translateIdsHandlerFunctionSqs,
|
|
457
|
-
...translateIdsFunctionYamlDsq, ...translateIdsFunctionYamlSqs, ...translateIdsSnsAndSqsResourceQueue
|
|
458
|
-
]
|
|
459
|
-
|
|
460
|
-
const translateIdsProcessingSnsOut = createProcessTranslateIdsCompleteSnsOut(_izContext, saveFilePath);
|
|
461
|
-
const translateIdsProcessingQueue = createTranslateIdsProcessSnsQueue(_izContext, saveFilePath);
|
|
462
|
-
const translateIdsProcessingFunctionYaml = createTranslateIdsProcessFunctionYaml(_izContext, saveFilePath);
|
|
463
|
-
const translateIdsProcessingHandler = createTranslateIdsProcessHandler(_izContext, saveFilePath);
|
|
464
|
-
const translateIdsProcessingMainFunction = createTranslateIdsProcessMainFunction(_izContext, saveFilePath);
|
|
465
|
-
const createTranslateIdsProcessing = [...translateIdsProcessingQueue, ...translateIdsProcessingFunctionYaml, ...translateIdsProcessingHandler, ...translateIdsProcessingMainFunction, ...translateIdsProcessingSnsOut]
|
|
466
|
-
|
|
467
446
|
const findDataHandlerSqs = createFindDataHandler(_izContext, saveFilePath);
|
|
468
447
|
const findDataMainFunction = await createFindDataMainFunction(_izContext, saveFilePath);
|
|
469
448
|
|
|
@@ -494,8 +473,6 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
494
473
|
createSourceParams.push(
|
|
495
474
|
...updateRelationshipSchemaDatas,
|
|
496
475
|
...createRelationshipSchemaDatas,
|
|
497
|
-
...createTranslateIdsResourece,
|
|
498
|
-
...createTranslateIdsProcessing,
|
|
499
476
|
...deleteRelationshipData,
|
|
500
477
|
...deleteRelationshipCompleteData
|
|
501
478
|
)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
const hash = require('object-hash');
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function checkValidTableYaml(_izContext, currentTableSetting, existsTableSetting) {
|
|
24
|
+
/*
|
|
25
|
+
return table yml setting that already filter duplicate tableName that have same table setting
|
|
26
|
+
throw error when found duplicate table name but not have same table setting
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
let filteredDynamoDbYamlSetting = [];
|
|
30
|
+
|
|
31
|
+
for (let i = 0, length = currentTableSetting.length; i < length; i++) {
|
|
32
|
+
let dynamoDbYamlSetting = currentTableSetting[i];
|
|
33
|
+
if (existsTableSetting.hasOwnProperty(dynamoDbYamlSetting.templateData.tableName)) {
|
|
34
|
+
|
|
35
|
+
// exists table
|
|
36
|
+
if (hash(existsTableSetting[dynamoDbYamlSetting.templateData.tableName]) === hash(dynamoDbYamlSetting.templateData.attributes.sort())) {
|
|
37
|
+
continue;
|
|
38
|
+
} else {
|
|
39
|
+
throw Error(`tableName:${dynamoDbYamlSetting.templateData.tableName} have duplicate setting but not have same setting`)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
} else {
|
|
43
|
+
filteredDynamoDbYamlSetting.push(dynamoDbYamlSetting);
|
|
44
|
+
|
|
45
|
+
// not exists table
|
|
46
|
+
Object.assign(
|
|
47
|
+
existsTableSetting,
|
|
48
|
+
{
|
|
49
|
+
[dynamoDbYamlSetting.templateData.tableName]: dynamoDbYamlSetting.templateData.attributes.sort()
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return [filteredDynamoDbYamlSetting, existsTableSetting];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = { checkValidTableYaml };
|