@izara_project/izara-market-library-service-schemas 1.0.11 → 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.
@@ -1,760 +0,0 @@
1
- /*
2
- Copyright (C) 2021 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
- const asyncFlowSharedLib = require('@izara_project/izara-shared/src/AsyncFlowSharedLib');
20
- const dynamodbSharedLib = require('@izara_project/izara-shared/src/DynamodbSharedLib');
21
- const lambdaSharedLib = require('@izara_project/izara-shared/src/LambdaSharedLib')
22
- const callingFlowSharedLib = require('@izara_project/izara-shared/src/CallingFlowSharedLib');
23
-
24
- const sns = require('@izara_project/izara-core-library-external-request/src/resources/Sns');
25
- const snsSharedLib = require('@izara_project/izara-shared/src/SnsSharedLib');
26
- const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
27
- const serviceConfigLib = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig')
28
-
29
- const uploadUseCase = require('@izara_project/izara-core-library-service-schemas/src/libs/UploadUseCase')
30
-
31
-
32
- const hash = require("object-hash")
33
- const NoRetryError = require('@izara_project/izara-core-library-core/src/NoRetryError');
34
- const path = require('path')
35
- const schemasPath = path.join(__dirname, '../schemas');
36
- const consts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
37
- const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
38
-
39
- const {
40
- generateDynamoDbIdentifiers,
41
- dynamoDbIdentifiersByStorageResource,
42
- collectGetData
43
- } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
44
-
45
- const {
46
- getGraphServiceTagWithCache,
47
- getServiceNameWithCache
48
- } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
49
-
50
- //-----------------------------------------------------------------------------------------------------------
51
- const PREFIX = {
52
- ONE: "one",
53
- MANY: "many",
54
- CREATE_OBJECT_ASYNC: "createObjectAsync",
55
- CREATE_OBJECT_ASYNC_COMPLETE: "createObjectAsyncComplete"
56
- }
57
- //-----------------------------------------------------------------------------------------------------------
58
-
59
- /**
60
- - all storageType( DB and Graph) use objInstance({identifiers,fields})
61
- - storageType[DB] async
62
- - storageType[Graph] sync (should be have lambda complete)
63
- -- before DB and Graph have boolend check (allStorageTagComplete = true) if storageType == graph set allStorageTagComplete = false,
64
- and save awaitingMultiplastep prefix(serviceTag_CreateObject{identifierId})
65
-
66
- >>> in lambdaComplete resive message from GrapHandler
67
- 1.1 check have returnValue.errorsFould.length > 0
68
- -- Delete all awitingMultiplestep and senf message to callingFlow have errorFound.
69
- 1.2 check awaitingmultipleStepall finish
70
- -- Delete awaitingStep in come if have other multiplestep(not finish)== not send message.
71
- --- if check awaitingmultipleStepall finish not have record ===> sendmessage to callingFlow.
72
- */
73
- //=========================================================================================
74
- /**
75
- *
76
- * @param {*} _izContext
77
- * @param {Object} requestParams = {fieldNames,relationships = []}
78
- * @param {*} callingFlowConfig
79
- */
80
-
81
- module.exports.createObject = async (
82
- _izContext,
83
- requestParams,
84
- callingFlowConfig
85
- ) => {
86
- try {
87
- _izContext.logger.debug("function createObject:", {
88
- requestParams,
89
- callingFlowConfig
90
- });
91
-
92
- _izContext.correlationIds.set(coreConsts.BASE_USER_ID, "BasDev");
93
-
94
- const OBJECT_TYPE = "<%- objectType %>";
95
- const SERVICE_TAG = process.env.iz_serviceTag
96
-
97
- const MAIN_OBJTYPE = {
98
- objectType: OBJECT_TYPE,
99
- serviceTag: SERVICE_TAG
100
- }
101
-
102
- let getLocalObjectSchemas = await getObjectSchema.getLocalObjectSchemasWithHierarchy(
103
- _izContext,
104
- OBJECT_TYPE,
105
-
106
- )
107
-
108
-
109
- _izContext.logger.debug("getLocalObjectSchemas:", getLocalObjectSchemas)
110
- let objectSchemas = uploadUseCase.generateObjectSchemaForGraphHandler(
111
- _izContext,
112
- getLocalObjectSchemas
113
- );
114
-
115
- let createDataDetails = await createDataDetailsLib(_izContext, objectSchemas);
116
- _izContext.logger.debug("createDataDetails is =", createDataDetails);
117
-
118
- //...............................................
119
- let objInstance = {};
120
- /* // seagame: can initial identifiers and fields properties inside objInstance
121
- let objInstance = {
122
- identifiers:{},
123
- fields:{}
124
- };
125
- */
126
-
127
- let listOfRequriedOnCreate = [];
128
- let listOfOptionalOnCreate = [];
129
-
130
- let allAwaitingStepsId = [];
131
- let errorsFound = [];
132
-
133
- //................................................
134
-
135
- // // // validate for create identifer.
136
- // for (let identifier of objectSchemas.identifiers) {
137
- // // check single and cancat identifier in objectType
138
- // // can use all dynamodb and graph.
139
-
140
- // if (objectSchemas.identifiers.length === 1 && !identifier.hasOwnProperty("fieldNames")) {
141
- // _izContext.logger.debug(":::::case single identifer:::::", identifier);
142
-
143
- // if (objectSchemas.fieldNames[identifier.fieldName].hasOwnProperty("randomOnCreate")) {
144
-
145
- // if ((objectSchemas.fieldNames[identifier.fieldName].randomOnCreate == true)) {
146
- // if ((objectSchemas.fieldNames[identifier.fieldName].requiredOnCreate == false)
147
- // && (objectSchemas.fieldNames[identifier.fieldName].optionalOnCreate == false)
148
- // && (objectSchemas.fieldNames[identifier.fieldName].canUpdate == false)
149
- // ) {
150
-
151
- // Object.assign(requestParams.fieldNames, {
152
- // [identifier.fieldName]: hash({
153
- // fieldNames: identifier, //
154
- // uniqueRequestId: _izContext.uniqueRequestId,
155
- // callingFlowConfig: callingFlowConfig
156
- // })
157
- // })
158
- // }
159
- // } else if ((objectSchemas.fieldNames[identifier.fieldName].randomOnCreate == false)) {
160
-
161
- // if ((objectSchemas.fieldNames[identifier.fieldName].requiredOnCreate == true)
162
- // && ((objectSchemas.fieldNames[identifier.fieldName].optionalOnCreate == false) || objectSchemas.fieldNames[identifier.fieldName].optionalOnCreate == true)
163
- // && (objectSchemas.fieldNames[identifier.fieldName].canUpdate == false)) {
164
- // // check Fns have resive
165
-
166
- // if (requestParams.fieldNames.hasOwnProperty([identifier.fieldName])) {
167
- // _izContext.logger.debug("identifier is exist:", {
168
- // [identifier.fieldName]: requestParams.fieldNames[identifier.fieldName]
169
- // });
170
-
171
- // } else {
172
- // errorsFound.push("[invalid]requestParams not have data fieldNames of requriedOnCreate");
173
- // }
174
- // }
175
- // };
176
- // } else {
177
- // if ((objectSchemas.fieldNames[identifier.fieldName].requiredOnCreate == false)
178
- // && (objectSchemas.fieldNames[identifier.fieldName].optionalOnCreate == false)
179
- // && (objectSchemas.fieldNames[identifier.fieldName].canUpdate == false)) {
180
- // errorsFound.push("[invalid]case single identifier invalid objectSchemass");
181
- // };
182
- // };
183
- // }
184
-
185
- // if (errorsFound.length > 0) {
186
- // _izContext.logger.debug("HaveError::", errorsFound);
187
- // break
188
- // };
189
- // };
190
-
191
-
192
-
193
- if (objectSchemas.identifiers.length === 1 && !identifier.hasOwnProperty("fieldNames")) {
194
-
195
- const identifier = objectSchemas.identifiers[0];
196
- _izContext.logger.debug(":::::case single identifer:::::", identifier);
197
-
198
- if (objectSchemas.fieldNames[identifier.fieldName].hasOwnProperty("randomOnCreate")) {
199
-
200
- if ((objectSchemas.fieldNames[identifier.fieldName].randomOnCreate == true)) {
201
- if ((objectSchemas.fieldNames[identifier.fieldName].requiredOnCreate == false)
202
- && (objectSchemas.fieldNames[identifier.fieldName].optionalOnCreate == false)
203
- && (objectSchemas.fieldNames[identifier.fieldName].canUpdate == false)
204
- ) {
205
-
206
- Object.assign(requestParams.fieldNames, {
207
- [identifier.fieldName]: hash({
208
- fieldNames: identifier, //
209
- uniqueRequestId: _izContext.uniqueRequestId,
210
- callingFlowConfig: callingFlowConfig
211
- })
212
- });
213
-
214
- }
215
-
216
- } else if ((objectSchemas.fieldNames[identifier.fieldName].randomOnCreate == false)) {
217
-
218
- if ((objectSchemas.fieldNames[identifier.fieldName].requiredOnCreate == true)
219
- && ((objectSchemas.fieldNames[identifier.fieldName].optionalOnCreate == false) || objectSchemas.fieldNames[identifier.fieldName].optionalOnCreate == true)
220
- && (objectSchemas.fieldNames[identifier.fieldName].canUpdate == false)) {
221
- // check Fns have resive
222
-
223
- if (requestParams.fieldNames.hasOwnProperty([identifier.fieldName])) {
224
- _izContext.logger.debug("identifier is exist:", {
225
- [identifier.fieldName]: requestParams.fieldNames[identifier.fieldName]
226
- });
227
-
228
- } else {
229
- errorsFound.push("[invalid]requestParams not have data fieldNames of requriedOnCreate");
230
- }
231
- }
232
- };
233
- } else {
234
- if ((objectSchemas.fieldNames[identifier.fieldName].requiredOnCreate == false)
235
- && (objectSchemas.fieldNames[identifier.fieldName].optionalOnCreate == false)
236
- && (objectSchemas.fieldNames[identifier.fieldName].canUpdate == false)) {
237
- errorsFound.push("[invalid]case single identifier invalid objectSchemass");
238
- };
239
- };
240
- }
241
-
242
-
243
- _izContext.logger.debug("requestParams is:", requestParams);
244
-
245
-
246
-
247
- // check settingObjSchemas
248
- for (let [keyFieldNames, valueFieldNames] of Object.entries(objectSchemas.fieldNames)) {
249
-
250
- if (valueFieldNames.hasOwnProperty("randomOnCreate") && valueFieldNames.randomOnCreate === true) {
251
- listOfRequriedOnCreate.push(keyFieldNames)
252
- };
253
-
254
- if (valueFieldNames.hasOwnProperty("requiredOnCreate") && valueFieldNames.requiredOnCreate === true) {
255
- listOfRequriedOnCreate.push(keyFieldNames)
256
- };
257
-
258
- if (valueFieldNames.hasOwnProperty("optionalOnCreate") && valueFieldNames.optionalOnCreate === true) {
259
- if ((valueFieldNames.requiredOnCreate === false) && valueFieldNames.optionalOnCreate === true) {
260
- listOfOptionalOnCreate.push(keyFieldNames)
261
- };
262
- };
263
-
264
- };// end iteration of fieldNames
265
-
266
- for (let fieldName of Object.keys(requestParams.fieldNames)) {
267
-
268
- if (!listOfRequriedOnCreate.includes(fieldName)) {
269
- if (!listOfOptionalOnCreate.includes(fieldName)) {
270
- errorsFound.push("[invalid] over fieldNames create object");
271
- }
272
- };
273
-
274
- if (listOfOptionalOnCreate.length > 0 && listOfRequriedOnCreate.includes(fieldName)) {
275
- // HookCode
276
- // HookCode
277
- };
278
-
279
- if (listOfRequriedOnCreate.includes(fieldName)) { // seagame: can delete this condition or move to else condition of !listOfRequiredOnCreate.includes(fieldName)
280
- //check idnetifier
281
- _izContext.logger.debug("check",
282
- objectSchemas.identifierFieldNames,
283
- { listOfRequriedOnCreate, fieldNames: fieldName });
284
-
285
- if (objectSchemas.identifierFieldNames.includes(fieldName)) {
286
- _izContext.logger.debug("identifiers is", fieldName);
287
-
288
- if (objInstance.hasOwnProperty("identifiers")) {
289
- Object.assign(objInstance.identifiers, {
290
- [fieldName]: requestParams.fieldNames[fieldName]
291
- })
292
- } else {
293
- Object.assign(objInstance, {
294
- identifiers: {
295
- [fieldName]: requestParams.fieldNames[fieldName]
296
- }
297
- });
298
- };
299
- };
300
-
301
- };
302
-
303
-
304
- /*
305
- fix version if change objInstance initial
306
- can delete condition if (listOfRequriedOnCreate.includes(fieldName))
307
- */
308
-
309
- // if (objectSchemas.identifierFieldNames.includes(fieldName)) {
310
- // _izContext.logger.debug("identifiers is", fieldName);
311
- // Object.assign(objInstance.identifiers, {
312
- // [fieldName]: requestParams.fieldNames[fieldName]
313
- // });
314
- // };
315
-
316
- if (errorsFound.length > 0) {
317
- _izContext.logger.debug("HaveError::", errorsFound);
318
- break
319
- };
320
-
321
- };// end loop
322
-
323
- let listOfObjectForCreates = [];
324
- let serviceName;
325
- let createDataDetail;
326
- if (errorsFound.length == 0) {
327
-
328
- for ([serviceName, createDataDetail] of Object.entries(createDataDetails)) {
329
-
330
- for (let fieldNames of Object.keys(requestParams.fieldNames)) {
331
-
332
- if (createDataDetail.fieldNames.includes(fieldNames) && listOfRequriedOnCreate.includes(fieldNames)
333
- ) {
334
- _izContext.logger.debug("fieldNames match in detail is:", fieldNames);
335
-
336
- if (objInstance.hasOwnProperty("fields")) {
337
- Object.assign(objInstance.fields, {
338
- [fieldNames]: requestParams.fieldNames[fieldNames]
339
- })
340
- } else {
341
- Object.assign(objInstance, {
342
- fields: {
343
- [fieldNames]: requestParams.fieldNames[fieldNames]
344
- }
345
- })
346
- };
347
- };
348
- };
349
-
350
- if (createDataDetail.storageType == consts.STORAGE_TYPES.dynamoDB) {
351
- _izContext.logger.debug("::::::DynamoDB::::::", { serviceName, objInstance });
352
-
353
- await dynamodbSharedLib.putItem(
354
- _izContext,
355
- await dynamodbSharedLib.tableName(
356
- _izContext,
357
- createDataDetail.tableName
358
- ),
359
- objInstance
360
- );
361
-
362
-
363
- } else if (createDataDetail.storageType == consts.STORAGE_TYPES.graph) {
364
- _izContext.logger.debug("::::::Graphanler::::::", { serviceName, objInstance });
365
-
366
- // allStorageTagComplete = false;
367
- allAwaitingStepsId.push(asyncFlowSharedLib.createAwaitingStepId(
368
- (hash({
369
- objType: MAIN_OBJTYPE,
370
- graphServerTag: serviceName,
371
- identifiers: objInstance.identifiers
372
- })),
373
- PREFIX.CREATE_OBJECT_ASYNC
374
- ));
375
- listOfObjectForCreates.push({
376
- [serviceName]: {
377
- objInstance: {
378
- identifiers: objInstance.identifiers,
379
- fields: objInstance.fields
380
- },
381
- allStorageTagComplete: false
382
- }
383
- });
384
-
385
- _izContext.logger.debug("FIRST", listOfObjectForCreates)
386
-
387
- };
388
- _izContext.logger.debug("[1]listOfObjectForCreates:::", listOfObjectForCreates);
389
-
390
- delete objInstance.fields
391
- };
392
- };
393
-
394
- /// step save awiatingMultipleStep of storageType graph ...........................................................
395
-
396
- await asyncFlowSharedLib.createAwaitingMultipleSteps(
397
- _izContext,
398
- allAwaitingStepsId,
399
- asyncFlowSharedLib.createPendingStepId((hash({ objType: MAIN_OBJTYPE, identifiers: objInstance.identifiers })), PREFIX.CREATE_OBJECT_ASYNC_COMPLETE)
400
- );
401
- //............................................................................................................
402
-
403
- // process storageType : graph
404
- let messageObject = {};
405
- for (let objectCreate of listOfObjectForCreates) {
406
-
407
- for (let [graphServiceName, objecForCreate] of Object.entries(objectCreate)) {
408
- _izContext.logger.debug("Loop each graph:", { [graphServiceName]: objecForCreate });
409
-
410
- if (objecForCreate.allStorageTagComplete == false) { // needless check because in listOfObjectForCreates push case graph only!
411
-
412
- messageObject = {
413
- objType: MAIN_OBJTYPE,
414
- objInstance: objecForCreate.objInstance,
415
- };
416
-
417
- /*
418
- seagame: should getRequiredOnCreateLinksGraphHandler before match with requestParams.relationships
419
- this condition will miss validation when objType have requiredOnCreateLink but not send relationships from requestParams
420
- */
421
-
422
- if (requestParams.hasOwnProperty("relationships") && requestParams.relationships.length > 0) {
423
- _izContext.logger.debug("SHOW RELATIONSHIP:", requestParams.relationships);
424
-
425
- // validate relationship only.
426
- let getRelationhsipSchemas = await getObjectSchema.getRequiredOnCreateLinksGraphHandler(
427
- _izContext,
428
- {
429
- objectType: OBJECT_TYPE,
430
- serviceTag: SERVICE_TAG
431
- }
432
- );
433
-
434
- _izContext.logger.debug("getRelationhsipSchemas is:::", getRelationhsipSchemas);
435
-
436
- if (Object.keys(getRelationhsipSchemas).length !== requestParams.relationships.length) {
437
- errorsFound.push("[invalid]relationships missmatch requiredOnCreateLink form relationshipschemas");
438
- } else {
439
-
440
- for (let eachRelationships of requestParams.relationships) {
441
- _izContext.logger.debug("eachRelationships is:", eachRelationships);
442
-
443
- // validate porperty in relatoinships.
444
- if (!eachRelationships.hasOwnProperty("relType") || Object.keys(eachRelationships.relType).length == 0) {
445
- errorsFound.push("[invalid relationsips] property relType in relationsips");
446
- };
447
- if (!eachRelationships.hasOwnProperty("targetObjType") || Object.keys(eachRelationships.targetObjType).length == 0) {
448
- errorsFound.push("[invalid relationsips] property targetObjType in relationsips");
449
- };
450
- if (!eachRelationships.hasOwnProperty("targetIdentifiers") || Object.keys(eachRelationships.targetIdentifiers).length == 0) {
451
- errorsFound.push("[invalid relationsips] property targetIdentifiers in relationsips");
452
- };
453
-
454
- let relationshipTag = eachRelationships.relType.relationshipTag
455
- let eachRelationhsipSchemas = getRelationhsipSchemas[eachRelationships.relType.relationshipTag]
456
- let targetObjType = eachRelationships.targetObjType
457
-
458
- _izContext.logger.debug("each Relationhsip is:::::", {
459
- relationshipTag,
460
- eachRelationhsipSchemas: eachRelationhsipSchemas,
461
- targetObjType
462
- });
463
-
464
- if (!eachRelationhsipSchemas) {
465
- errorsFound.push("misMatch relationhsipSchemas requriOnCreate");
466
- };
467
-
468
- if (errorsFound.length > 0) {
469
- break
470
- };
471
-
472
- let objTypeRequiredOnCreate = null;
473
- for (let link of eachRelationhsipSchemas.links) {
474
- /*
475
- seagame: one relationshipSchema probably have 2 or more links that contain mainObjType but have difference targetObjType
476
- */
477
-
478
- let objectSides = {
479
- from: MAIN_OBJTYPE,
480
- to: targetObjType
481
- };
482
-
483
- if (link.from.objType.serviceTag == targetObjType.serviceTag
484
- && link.from.objType.objectType == targetObjType.objectType) {
485
- objectSides = {
486
- from: targetObjType,
487
- to: MAIN_OBJTYPE
488
- };
489
- };
490
- _izContext.logger.debug("check side:", objectSides);
491
-
492
- // test both sides of link
493
- // let otherLinkConfigKey = "from";
494
- for (let linkKey of Object.keys(link)) {
495
- // _izContext.logger.debug("linkKey is:", linkKey);
496
- if (linkKey == "to" || linkKey == "from") {
497
- // set other side key
498
- let otherLinkConfigKey = "from";
499
- if (linkKey == "from") {
500
- otherLinkConfigKey = "to";
501
- }
502
-
503
- // case ONE-to-ONE
504
- if (link[linkKey].linkType == "one"
505
- && link[otherLinkConfigKey].linkType == "one") {
506
- _izContext.logger.debug("case ONE-to-ONE");
507
- if (link[linkKey].requiredOnCreate == true) {
508
-
509
- objTypeRequiredOnCreate = objectSides[linkKey];
510
- };
511
- };
512
-
513
- // case ONE-to-MANY
514
- if (link[linkKey].linkType == "many"
515
- && link[otherLinkConfigKey].linkType == "one") {
516
- _izContext.logger.debug("case ONE-to-MANY");
517
-
518
- if (link[linkKey].requiredOnCreate == true) {
519
-
520
- objTypeRequiredOnCreate = objectSides[linkKey];
521
- };
522
- };
523
-
524
- if ((objTypeRequiredOnCreate !== null && link[otherLinkConfigKey].objType !== null)) {
525
- /*
526
- seagame: one relationshipSchema probably have 2 or more links that contain mainObjType but have difference targetObjType
527
- if check other side with targetObjType will cause errors
528
- */
529
- if (
530
- ((objTypeRequiredOnCreate.objectType == MAIN_OBJTYPE.objectType) && (objTypeRequiredOnCreate.serviceTag == MAIN_OBJTYPE.serviceTag))
531
- && ((link[otherLinkConfigKey].objType.objectType == targetObjType.objectType) && (link[otherLinkConfigKey].objType.serviceTag == targetObjType.serviceTag))) {
532
-
533
- // seagame:
534
- // this line will re assign every time when validate requestParams.relationships
535
- // should finished validate all requestParams.relationships before assign to messageObject
536
- Object.assign(messageObject, { relationships: requestParams.relationships });
537
- _izContext.logger.debug("messageObject case relationships", messageObject)
538
-
539
- } else {
540
- errorsFound.push("[Invalid]main objType is not requriOnCreate")
541
- };
542
-
543
- }
544
-
545
- if (errorsFound.length > 0) {
546
- break
547
- };
548
- };
549
-
550
-
551
- }; // end check linkKey.
552
- }; // end links
553
- }; // end loop requestParams.relationships
554
- };// end eachRelationships
555
-
556
- if (errorsFound.length > 0) {
557
- break
558
- };
559
- }; // case relationships
560
- };
561
-
562
- if (errorsFound.length > 0) {
563
- break;
564
- } else {
565
- _izContext.logger.debug("SENT MESSAGE EACH GRAPH::::", { graphServiceName, messageObject, callingFlowConfig })
566
-
567
- Object.assign(messageObject, {
568
- settings: { updatePropertiesOnMatch: false },
569
- originTimestamp: Date.now()
570
- });
571
-
572
- // seagame: not need to check callingFlow before send to graph, Just add callingFlow and parent callingFlow before send to graph
573
- if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]) {
574
- _izContext.logger.debug("Have callingFlow", callingFlowConfig);
575
- _izContext.logger.debug("callingFlowProperties", callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOWPROPERTIES_PROPERTYNAME])
576
-
577
- messageObject = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
578
- messageObject,
579
- callingFlowSharedLib.addParentCallingFlowConfig(
580
- callingFlowConfig, // resive parent callingFlowConfig.
581
- callingFlowSharedLib.createCallingFlowConfig( // callinfflow own service
582
- await lambdaSharedLib.lambdaFunctionName(_izContext, "CreateObjectCompleteHdrSqs"),
583
- )
584
- )
585
- );
586
- };
587
-
588
- let messageToCreateObject = {
589
- Message: JSON.stringify(messageObject),
590
- TopicArn: await snsSharedLib.snsTopicArn(_izContext, "InCreateNodeV2", graphServiceName)
591
- };
592
- _izContext.logger.debug("RequestParams before send to sqs messageToCreateObject ::::::: ", messageToCreateObject);
593
- await sns.publishAsync(_izContext, messageToCreateObject);
594
- };
595
- };// end loop of objectCreate.
596
- if (errorsFound.length > 0) {
597
- break;
598
- }
599
- }; // end loop listOfObjectForCreates
600
-
601
- if (errorsFound.length > 0) {
602
- _izContext.logger.debug("Case have errorFound:::", errorsFound);
603
-
604
- // remove awaitngMultiplestep. [[[[[[[open when not test lolcal.]]]]]]]
605
- await asyncFlowSharedLib.clearAllAwaitingSteps(
606
- _izContext,
607
- asyncFlowSharedLib.createPendingStepId((hash({
608
- objType: MAIN_OBJTYPE,
609
- identifiers: objInstance.identifiers
610
- })), PREFIX.CREATE_OBJECT_ASYNC_COMPLETE)); // pendingStepId
611
-
612
- // send message to OutCreateObjectComplete.
613
- //..
614
- messageObject = {
615
- objType: MAIN_OBJTYPE,
616
- identifiers: null, // or {}
617
- errorsFound: errorsFound
618
- };
619
-
620
- // pass back property.
621
- messageObject = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, messageObject);
622
- let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
623
-
624
- let sendMessageOutCreateObjectComplete = {
625
- Message: JSON.stringify(messageObject),
626
- MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
627
- TopicArn: await snsSharedLib.snsTopicArn(_izContext, "OutCreateObjectComplete")
628
- };
629
- _izContext.logger.debug("Send message to OutCreateObjectComplete :::>", sendMessageOutCreateObjectComplete)
630
- await sns.publishAsync(_izContext, sendMessageOutCreateObjectComplete);
631
-
632
- return { returnValue: "function DeliveryMetodStandate have errorFounds" }
633
- }
634
- _izContext.logger.debug("end errorsFound is:", errorsFound);
635
-
636
- } catch (err) {
637
- throw (err)
638
- }
639
-
640
- }
641
-
642
- /*
643
- example return
644
- * identifierFieldNames will not includes inside fieldNames of createObjectDetails
645
- {
646
- dynamoDBStorageTag:{
647
- storageType:"dynamoDB",
648
- tableName:"xxx",
649
- fieldNames:[...fieldName]
650
- },
651
- GraphServiceTag:{
652
- storageType: 'graph',
653
- fieldNames: [ 'bookId2', 'bookName' ]
654
- }
655
- }
656
- */
657
- async function createDataDetailsLib(
658
- _izContext,
659
- objectSchemas
660
- ) {
661
- _izContext.logger.debug("Lib: createDataDetailsLib:", { objectSchemas: objectSchemas });
662
-
663
- let createDataDetails = {};
664
-
665
- let storageResources = objectSchemas.storageResources;
666
- _izContext.logger.debug("storageResources:", storageResources);
667
-
668
- for (let [keyFieldName, settingFieldName] of Object.entries(objectSchemas.fieldNames)) {
669
- // _izContext.logger.debug("Loop fieldNamesObjectSchemas", { keyFieldName });
670
-
671
- // check fiend is identifier
672
- if (objectSchemas.identifierFieldNames.includes(keyFieldName)) {
673
- continue
674
- };
675
- // validate storageResourceTags.
676
- _izContext.logger.debug("storageResourceTags is", settingFieldName.storageResourceTags);
677
-
678
- for (let eachStorageResourceTags of settingFieldName.storageResourceTags) {
679
- _izContext.logger.debug("Loop eachStorageResourceTags", eachStorageResourceTags);
680
-
681
- if (!storageResources.hasOwnProperty(eachStorageResourceTags)) {
682
- throw new Error("storageResources is'n exist");// should be validata in step uplode in s3
683
- } else {
684
-
685
- if (storageResources[eachStorageResourceTags].storageType == consts.STORAGE_TYPES.dynamoDB) {
686
- if (createDataDetails.hasOwnProperty(eachStorageResourceTags)) {
687
- _izContext.logger.debug("SAME STG DB", eachStorageResourceTags);
688
- createDataDetails[eachStorageResourceTags].fieldNames.push(keyFieldName);
689
-
690
- } else {
691
- _izContext.logger.debug("NEW STG DB", eachStorageResourceTags);
692
- Object.assign(createDataDetails, {
693
- [eachStorageResourceTags]: {
694
- storageType: consts.STORAGE_TYPES.dynamoDB,
695
- tableName: storageResources[eachStorageResourceTags].tableName,
696
- fieldNames: [keyFieldName]
697
- }
698
- });
699
-
700
- if (storageResources[eachStorageResourceTags].hasOwnProperty("groupByPartitionKeyField")) {
701
- Object.assign(createDataDetails[eachStorageResourceTags], {
702
- groupByPartitionKeyField: storageResources[eachStorageResourceTags].groupByPartitionKeyField
703
- });
704
- }
705
- }
706
-
707
- } else if (storageResources[eachStorageResourceTags].storageType == consts.STORAGE_TYPES.graph) {
708
- let checkGraphServerTags = await serviceConfigLib.getGraphServiceTag(
709
- _izContext,
710
- storageResources[eachStorageResourceTags].graphServerTag
711
- );
712
- if (checkGraphServerTags) {
713
- if (createDataDetails.hasOwnProperty(checkGraphServerTags)) {
714
- _izContext.logger.debug("SAME STG", checkGraphServerTags);
715
- createDataDetails[checkGraphServerTags].fieldNames.push(keyFieldName)
716
-
717
- } else {
718
- _izContext.logger.debug("NEW STG", checkGraphServerTags);
719
- Object.assign(createDataDetails, {
720
- [checkGraphServerTags]: {
721
- storageType: consts.STORAGE_TYPES.graph,
722
- fieldNames: [keyFieldName]
723
- }
724
- });
725
- };
726
- };
727
- };
728
- };
729
- };// end loop storageResourceTags
730
-
731
- };// end loop
732
- _izContext.logger.debug("_______All createDataDetails_____", createDataDetails);
733
- return createDataDetails;
734
- };
735
-
736
- (async () => {
737
- const path = require("path")
738
- const schemaPath = path.join(__dirname, '../schemas');
739
-
740
- const _izContext = {
741
- logger: require("@izara_project/izara-core-library-logger")
742
- };
743
-
744
-
745
- const objSchema = await getObjectSchema.getLocalObjectSchemasWithHierarchy(
746
- _izContext,
747
- "book",
748
- schemasPath // for test own local (part local not same link in aws.)
749
- ).then(data => data.records[0]);
750
-
751
- _izContext.logger.debug("objSchema: ", objSchema);
752
-
753
- const objSchemaGraph = uploadUseCase.generateObjectSchemaForGraphHandler(
754
- _izContext,
755
- objSchema
756
- );
757
-
758
- const createDataDetail = await createDataDetailsLib(_izContext, objSchemaGraph);
759
- _izContext.logger.debug("createDataDetail: ", createDataDetail);
760
- })()