@izara_project/izara-market-library-service-schemas 1.0.11 → 1.0.12
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 +2 -2
- package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +164 -111
- package/src/TemplateManager/src/GenerateCode.js +6 -6
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/data.js +4 -4
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/template.ejs +3 -3
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +148 -139
- package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsAndSqsPerActiondata.js +1 -1
- package/src/TemplateManager/src/ResourceYaml/sns-out/data.js +1 -1
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/CreateObject_main.js +0 -760
|
@@ -16,120 +16,125 @@ Copyright (C) 2020 Sven Mason <http: //izara.io>
|
|
|
16
16
|
<http: //www.gnu.org/licenses />.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
'use strict';
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const {
|
|
22
22
|
getObjSchemaS3WithHierarchy,
|
|
23
|
-
|
|
23
|
+
} = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const {
|
|
26
26
|
getGraphServiceTagWithCache,
|
|
27
|
-
|
|
28
|
-
} = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
|
|
27
|
+
} = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
const consts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
31
30
|
|
|
31
|
+
const {
|
|
32
|
+
objInstanceFromobjInstanceBase
|
|
33
|
+
} = require('@izara_project/izara-core-library-service-schemas/src/IdentifiersObject');
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
const {
|
|
34
36
|
dynamoDbIdentifiersByStorageResource,
|
|
35
|
-
collectGetData
|
|
36
|
-
|
|
37
|
+
collectGetData,
|
|
38
|
+
createGetDataDetails,
|
|
39
|
+
} = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
|
|
37
40
|
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
const dynamodbSharedLib = require('@izara_project/izara-shared/src/DynamodbSharedLib');
|
|
43
|
+
const graphSharedLib = require('@izara_project/izara-shared/src/GraphSharedLib');
|
|
41
44
|
|
|
45
|
+
const NoRetryError = require('@izara_project/izara-core-library-core/src/NoRetryError');
|
|
42
46
|
|
|
43
|
-
const NoRetryError = require('@izara_project/izara-core-library-core/src/NoRetryError');
|
|
44
|
-
const { createGetDataDetails } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs')
|
|
45
47
|
|
|
46
48
|
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
*
|
|
53
|
+
* description of function.
|
|
54
|
+
* @param {Object} _izContext
|
|
55
|
+
* @param {CorrelationIds} _izContext.correlationIds - property of _izContext
|
|
56
|
+
* @param {Logger} _izContext.logger - property of _izContext
|
|
57
|
+
* @param {Object} requestParams - request params
|
|
58
|
+
* @param {Object} requestParams.identifiers - identifiers for get data
|
|
59
|
+
* @param {Object} requestParams.additionalRequest - additionalRequest
|
|
60
|
+
*
|
|
61
|
+
*
|
|
62
|
+
* @returns {object} description of return value
|
|
63
|
+
*/
|
|
64
|
+
module.exports.<%- functionName %>Main = async (
|
|
65
|
+
_izContext,
|
|
66
|
+
requestParams,
|
|
67
|
+
callingFlowConfig = {},
|
|
68
|
+
//(<additionalParams>)
|
|
69
|
+
//(</additionalParams>)
|
|
70
|
+
) => {
|
|
69
71
|
|
|
70
72
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
try {
|
|
74
|
+
_izContext.logger.debug('<%- functionName %> _izContext: ', _izContext);
|
|
75
|
+
_izContext.logger.debug('<%- functionName %> requestParams: ', requestParams);
|
|
76
|
+
_izContext.logger.debug('<%- functionName %> callingFlowConfig: ', callingFlowConfig);
|
|
75
77
|
|
|
78
|
+
const returnFormat = requestParams.additionalRequest?.setting?.returnFormat;
|
|
79
|
+
const throwWhenNotFoundSomeRecord = requestParams.additionalRequest?.setting?.throwWhenNotFoundSomeRecord || true;
|
|
76
80
|
|
|
77
|
-
const OBJECT_TYPE = "<%- objectType %>";
|
|
78
|
-
const SERVICE_TAG = process.env.iz_serviceTag;
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
const OBJECT_TYPE = "<%- objectType %>";
|
|
83
|
+
const SERVICE_TAG = process.env.iz_serviceTag;
|
|
82
84
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
//(<beforeQuery>)
|
|
86
|
+
//(</beforeQuery>)
|
|
87
|
+
|
|
88
|
+
let objectSchema = await getObjSchemaS3WithHierarchy(
|
|
89
|
+
_izContext,
|
|
90
|
+
{
|
|
86
91
|
objectType: OBJECT_TYPE,
|
|
87
92
|
serviceTag: SERVICE_TAG
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
}
|
|
94
|
+
);
|
|
90
95
|
|
|
91
|
-
|
|
96
|
+
_izContext.logger.debug("objectSchema: ", objectSchema);
|
|
92
97
|
|
|
93
|
-
|
|
94
|
-
|
|
98
|
+
let getDataDetails = await createGetDataDetails(_izContext, objectSchema);
|
|
99
|
+
_izContext.logger.debug("getDataDetails:", getDataDetails)
|
|
95
100
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
// start to get data
|
|
102
|
+
let getResults = []; // for collect result data from
|
|
103
|
+
let getRecordStatus = {
|
|
104
|
+
getAtLeastOneRecord: false,
|
|
105
|
+
notFoundSomeRecord: false
|
|
106
|
+
};
|
|
102
107
|
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
await Promise.all(
|
|
109
|
+
Object.entries(getDataDetails).map(
|
|
105
110
|
async ([storageTag, getDataDetail]) => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
111
|
+
if (getDataDetail.storageType === consts.STORAGE_TYPES.graph) {
|
|
112
|
+
// get data from graph
|
|
113
|
+
let graphServiceName = await getGraphServiceTagWithCache(_izContext, getDataDetail.graphServiceTag);
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
let versionedDataLabels = [];
|
|
117
|
+
if (getDataDetail.versionedDatas && Object.keys(getDataDetail.versionedDatas).length) {
|
|
118
|
+
// have versionedData
|
|
119
|
+
versionedDataLabels = Object.keys(getDataDetail.versionedDatas);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
//(<beforeGetGraph>)
|
|
124
|
+
//(</beforeGetGraph>)
|
|
125
|
+
|
|
126
|
+
let dataFromGraph = await graphSharedLib.getNodeV2(
|
|
127
|
+
_izContext,
|
|
128
|
+
graphServiceName,
|
|
129
|
+
{
|
|
130
|
+
objectType: OBJECT_TYPE,
|
|
131
|
+
serviceTag: SERVICE_TAG
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
identifiers: requestParams.identifiers
|
|
135
|
+
},
|
|
136
|
+
versionedDataLabels
|
|
137
|
+
)
|
|
133
138
|
|
|
134
139
|
_izContext.logger.debug("dataFromGraphV2: ", dataFromGraph);
|
|
135
140
|
|
|
@@ -139,84 +144,88 @@ Copyright (C) 2020 Sven Mason <http: //izara.io>
|
|
|
139
144
|
getRecordStatus.notFoundSomeRecord = true
|
|
140
145
|
}
|
|
141
146
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
Object.assign(
|
|
146
|
-
getResults,
|
|
147
|
-
collectGetData(_izContext, dataFromGraph, getDataDetail)
|
|
148
|
-
)
|
|
147
|
+
//(<afterGetGraph>)
|
|
148
|
+
//(</afterGetGraph>)
|
|
149
149
|
|
|
150
|
+
getResults.push([dataFromGraph, getDataDetail]);
|
|
150
151
|
|
|
151
|
-
|
|
152
|
+
} else {
|
|
152
153
|
|
|
153
154
|
let identifiersForGetData = await dynamoDbIdentifiersByStorageResource(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
_izContext,
|
|
156
|
+
objectSchema,
|
|
157
|
+
getDataDetail,
|
|
158
|
+
requestParams.identifiers
|
|
158
159
|
);
|
|
159
160
|
|
|
160
161
|
_izContext.logger.debug("identifiersForGetData: ", identifiersForGetData);
|
|
161
162
|
|
|
162
163
|
|
|
163
164
|
//(<beforeGetDynamoDb>)
|
|
164
|
-
|
|
165
|
+
//(</beforeGetDynamoDb>)
|
|
165
166
|
|
|
166
167
|
let dataFromDynamoDb = await dynamodbSharedLib.getItem(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
_izContext,
|
|
169
|
+
await dynamodbSharedLib.tableName(_izContext, getDataDetail.tableName),
|
|
170
|
+
identifiersForGetData
|
|
170
171
|
);
|
|
171
172
|
|
|
172
173
|
_izContext.logger.debug("dataFromDynamoDb: ", dataFromDynamoDb);
|
|
173
174
|
|
|
174
175
|
|
|
175
176
|
if (dataFromDynamoDb) {
|
|
176
|
-
|
|
177
|
+
dataFromDynamoDb = await objInstanceFromobjInstanceBase(
|
|
178
|
+
_izContext,
|
|
179
|
+
{
|
|
180
|
+
objectType: OBJECT_TYPE,
|
|
181
|
+
serviceTag: SERVICE_TAG
|
|
182
|
+
},
|
|
183
|
+
dataFromDynamoDb
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
getRecordStatus.getAtLeastOneRecord = true;
|
|
177
187
|
} else {
|
|
178
|
-
|
|
188
|
+
getRecordStatus.notFoundSomeRecord = true;
|
|
179
189
|
}
|
|
180
190
|
|
|
181
191
|
//(<afterGetDynamoDb>)
|
|
182
|
-
|
|
192
|
+
//(</afterGetDynamoDb>)
|
|
183
193
|
|
|
184
194
|
// collect return data depend on getDataDetail
|
|
185
|
-
|
|
186
|
-
getResults,
|
|
187
|
-
collectGetData(_izContext, dataFromDynamoDb, getDataDetail)
|
|
188
|
-
);
|
|
195
|
+
getResults.push([dataFromDynamoDb, getDataDetail]);
|
|
189
196
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
197
|
+
}
|
|
198
|
+
})
|
|
199
|
+
);
|
|
193
200
|
|
|
194
|
-
|
|
201
|
+
_izContext.logger.debug("getRecordStatus: ", getRecordStatus);
|
|
195
202
|
|
|
196
|
-
|
|
203
|
+
if (throwWhenNotFoundSomeRecord && getRecordStatus.getAtLeastOneRecord === true && getRecordStatus.notFoundSomeRecord === true) {
|
|
197
204
|
throw Error("Not found some record while get data");
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
let getResult = collectGetData(_izContext, getResults, objectSchema, returnFormat);
|
|
208
|
+
|
|
209
|
+
return getResult;
|
|
210
|
+
} catch (err) {
|
|
211
|
+
_izContext.logger.error('error <%- firstLetterUpperCase(functionName) %>Main: ', err)
|
|
212
|
+
throw (err)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
<%_ function firstLetterUpperCase(text){ return text.charAt(0).toUpperCase() + text.slice(1) } _%>
|
|
217
|
+
<%_ function firstLetterLowerCase(str) { return str.charAt(0).toLowerCase() + str.slice(1) } _%>
|
|
218
|
+
|
|
219
|
+
// request input
|
|
220
|
+
// {
|
|
221
|
+
// "identifiers": {
|
|
222
|
+
// "companyId": "seagame001GenerateCode2",
|
|
223
|
+
// "city": "cnxCity",
|
|
224
|
+
// "companyName": "RoyalSeafood"
|
|
225
|
+
// },
|
|
226
|
+
// "additionalRequest": {
|
|
227
|
+
// "setting": {
|
|
228
|
+
// "returnFormat": "STD" || "FULL"
|
|
229
|
+
// }
|
|
230
|
+
// }
|
|
231
|
+
// }
|
|
@@ -44,7 +44,7 @@ const sqsTemplatePath = path.join(__dirname, './sqsTemplate.ejs')
|
|
|
44
44
|
function dataForCreateSnsAndSqsQueueFromObjectSchema(_izContext, objectSchema, srcPath) {
|
|
45
45
|
const snsAndSqsDataArray = [];
|
|
46
46
|
for (const action of Object.values(ACTIONS)) {
|
|
47
|
-
if (objectSchema.overWriteHandlers[action]) {
|
|
47
|
+
if (objectSchema.overWriteHandlers?.[action]) {
|
|
48
48
|
for (const handler of objectSchema.overWriteHandlers[action]) {
|
|
49
49
|
const snsAndSqsData = {
|
|
50
50
|
queueName: createQueueNameForSnsAndSqsQueue(_izContext, objectSchema, action, handler, srcPath)
|
|
@@ -35,7 +35,7 @@ const templatePath = path.join(__dirname, "./template.ejs")
|
|
|
35
35
|
function createDataForCreateSourceSnsOut(_izContext, objectSchema, srcPath) {
|
|
36
36
|
const createSourceArray = [];
|
|
37
37
|
for (const action of Object.values(ACTIONS)) {
|
|
38
|
-
if (objectSchema.overWriteHandlers[action]) {
|
|
38
|
+
if (objectSchema.overWriteHandlers?.[action]) {
|
|
39
39
|
for (const handler of objectSchema.overWriteHandlers[action]) {
|
|
40
40
|
const snsOut = {
|
|
41
41
|
queueName: createQueueName(_izContext, objectSchema, action, handler, srcPath)
|