@izara_project/izara-core-generate-service-code 1.0.69 → 1.0.71
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 +1 -1
- package/scripts/format-ejs.js +35 -30
- package/src/compile/loadSchemas.js +84 -45
- package/src/emit/coreFunction/emitCoreFunctionArtifacts.js +163 -0
- package/src/emit/coreFunction/templates/CoreFunction_Yaml.ejs +38 -0
- package/src/emit/coreFunction/templates/CoreResource_Yaml.ejs +235 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataDynamo_HdrInv.ejs +16 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataDynamo_Main.ejs +38 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataGraphData_HdrInv.ejs +16 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataGraphData_Main.ejs +32 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataGraphSchema_HdrInv.ejs +16 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataGraphSchema_Main.ejs +71 -0
- package/src/emit/coreFunction/templates/GeneratedGraphNodeSchemas.ejs +47 -0
- package/src/emit/coreFunction/templates/GeneratedGraphRelSchemas.ejs +27 -0
- package/src/emit/coreFunction/templates/GeneratedTableConfigs.ejs +34 -0
- package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +108 -0
- package/src/emit/coreFunction/templates/InitialSetup_HdrInv.ejs +12 -0
- package/src/emit/coreFunction/templates/InitialSetup_Main.ejs +51 -0
- package/src/emit/coreFunction/templates/RemoveSeedDataDynamo_HdrInv.ejs +16 -0
- package/src/emit/coreFunction/templates/RemoveSeedDataDynamo_Main.ejs +31 -0
- package/src/emit/coreFunction/templates/UploadSchema_HdrInv.ejs +37 -0
- package/src/emit/coreFunction/templates/UploadSchema_Main.ejs +52 -0
- package/src/emit/crud/emitCrudApplicationArtifacts.js +12 -6
- package/src/emit/crud/templates/CreateEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/GetEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +1 -1
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +30 -11
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +2 -2
- package/src/emit/custom/templates/FlowStep_Main.ejs +1 -1
- package/src/emit/custom/templates/s3/CreateObject_Main.ejs +1 -1
- package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +1 -1
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +4 -4
- package/src/emit/function/functionYamlArtifact.js +5 -2
- package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +13 -3
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +1 -1
- package/src/emit/resource/emitResourceArtifacts.js +71 -15
- package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +17 -0
- package/src/emit/shared/templates/FindData_HdrSqs.ejs +120 -0
- package/src/emit/shared/templates/FindData_Main.ejs +345 -0
- package/src/emit/{crud → shared}/templates/FlowHandler_HdrApi.ejs +1 -1
- package/src/emit/{relationship → shared}/templates/FlowHandler_HdrDsq.ejs +4 -4
- package/src/emit/{crud → shared}/templates/FlowHandler_HdrInv.ejs +1 -1
- package/src/emit/{crud → shared}/templates/FlowHandler_HdrSqs.ejs +4 -4
- package/src/emit/shared/templates/PaginateProcessLogical_HdrDsq.ejs +162 -0
- package/src/emit/shared/templates/PaginateProcessLogical_HdrSqs.ejs +140 -0
- package/src/emit/shared/templates/PaginateProcessLogical_Main.ejs +268 -0
- package/src/emit/{relationship/templates/FlowHandler_HdrSqs.ejs → shared/templates/ProcessLogical_HdrSqs.ejs} +40 -55
- package/src/emit/shared/templates/ProcessLogical_Main.ejs +448 -0
- package/src/emit/system/emitSystemFindDataArtifacts.js +266 -0
- package/src/emit/system/templates/WebSocketComplete_HdrSqs.ejs +27 -11
- package/src/emit/system/templates/WebSocketComplete_Main.ejs +63 -18
- package/src/emit/system/templates/WebSocketConnect.ejs +26 -6
- package/src/generate.js +31 -4
- package/src/output/mergeHooks.js +18 -19
- package/test/core.test.js +4 -12
- package/test/crudApplicationArtifacts.test.js +14 -18
- package/test/publicApi.test.js +2 -2
- package/test/resourceArtifacts.test.js +1 -1
- package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +0 -59
- package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +0 -47
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
19
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
20
|
+
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
21
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
22
|
+
|
|
23
|
+
import paginateProcessLogical from './PaginateProcessLogical_Main.js';
|
|
24
|
+
|
|
25
|
+
// validate event properties in body.Message of sqs event
|
|
26
|
+
middleware.setValidatorSchema(
|
|
27
|
+
recordHandlerSharedLib.baseValidatorSchema({
|
|
28
|
+
type: 'object',
|
|
29
|
+
required: ['body', 'messageAttributes'],
|
|
30
|
+
properties: {
|
|
31
|
+
body: {
|
|
32
|
+
type: 'object'
|
|
33
|
+
},
|
|
34
|
+
messageAttributes: {
|
|
35
|
+
type: 'object'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// set schema for record.body.Message
|
|
42
|
+
const perRecordsValidatorSchema = {
|
|
43
|
+
type: 'object',
|
|
44
|
+
required: [
|
|
45
|
+
'logicalResultId',
|
|
46
|
+
'tableName',
|
|
47
|
+
'partitionKeyFieldName',
|
|
48
|
+
'sortKeyFieldName',
|
|
49
|
+
'dynamoDbIdentifiers',
|
|
50
|
+
'startKey',
|
|
51
|
+
'overwriteUniqueRequestId',
|
|
52
|
+
'overWriteCache'
|
|
53
|
+
],
|
|
54
|
+
properties: {
|
|
55
|
+
logicalResultId: {
|
|
56
|
+
type: 'string'
|
|
57
|
+
},
|
|
58
|
+
tableName: {
|
|
59
|
+
type: 'string'
|
|
60
|
+
},
|
|
61
|
+
partitionKeyFieldName: {
|
|
62
|
+
type: 'string'
|
|
63
|
+
},
|
|
64
|
+
sortKeyFieldName: {
|
|
65
|
+
type: 'string'
|
|
66
|
+
},
|
|
67
|
+
dynamoDbIdentifiers: {
|
|
68
|
+
type: 'object'
|
|
69
|
+
},
|
|
70
|
+
comparison: {
|
|
71
|
+
type: 'string',
|
|
72
|
+
default: ''
|
|
73
|
+
},
|
|
74
|
+
startKey: {
|
|
75
|
+
type: 'object'
|
|
76
|
+
},
|
|
77
|
+
overwriteUniqueRequestId: {
|
|
78
|
+
type: 'string'
|
|
79
|
+
},
|
|
80
|
+
overWriteCache: {
|
|
81
|
+
type: 'boolean'
|
|
82
|
+
},
|
|
83
|
+
callingFlow: {
|
|
84
|
+
type: 'string',
|
|
85
|
+
default: ''
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const main = middleware.wrap(async (event, context) => {
|
|
91
|
+
try {
|
|
92
|
+
let recordPromises = [];
|
|
93
|
+
|
|
94
|
+
// loop each record and send to mainFunction
|
|
95
|
+
await Promise.all(
|
|
96
|
+
event.Records.map(async record => {
|
|
97
|
+
// promise.all for map() function
|
|
98
|
+
|
|
99
|
+
// --- reforming record.body for Dsq request
|
|
100
|
+
record = recordHandlerSharedLib.reformatDsqMessage(
|
|
101
|
+
record._izContext,
|
|
102
|
+
record
|
|
103
|
+
);
|
|
104
|
+
record._izContext.logger.debug(
|
|
105
|
+
'record PaginateProcessLogicalHdrDsq after reform',
|
|
106
|
+
record
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
let passOnProperties = [];
|
|
110
|
+
|
|
111
|
+
// validate message (and MessageAttributes)
|
|
112
|
+
await recordHandlerSharedLib.validateRecord(
|
|
113
|
+
record, // one record will send to mainFunction
|
|
114
|
+
'PaginateProcessLogicalHdrDsq', // queue name that need to retry or send to dlq
|
|
115
|
+
perRecordsValidatorSchema // schema for record.Message
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
119
|
+
passOnProperties.push(record.body.Message.logicalResultId);
|
|
120
|
+
passOnProperties.push(record.body.Message.tableName);
|
|
121
|
+
passOnProperties.push(record.body.Message.partitionKeyFieldName);
|
|
122
|
+
passOnProperties.push(record.body.Message.sortKeyFieldName);
|
|
123
|
+
passOnProperties.push(record.body.Message.dynamoDbIdentifiers);
|
|
124
|
+
passOnProperties.push(record.body.Message.comparison);
|
|
125
|
+
passOnProperties.push(record.body.Message.startKey);
|
|
126
|
+
passOnProperties.push(record.body.Message.overwriteUniqueRequestId);
|
|
127
|
+
passOnProperties.push(record.body.Message.overWriteCache);
|
|
128
|
+
passOnProperties.push(record.body.Message.callingFlow);
|
|
129
|
+
record._izContext.logger.debug(
|
|
130
|
+
'passOnProperties in handler',
|
|
131
|
+
passOnProperties
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
135
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
136
|
+
record, // one record will send to mainFunction
|
|
137
|
+
paginateProcessLogical, // mainFunction that need to invoke.
|
|
138
|
+
'PaginateProcessLogicalHdrDsq', // queue name that need to retry or send to dlq
|
|
139
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
140
|
+
);
|
|
141
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
142
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
147
|
+
try {
|
|
148
|
+
// --- main await all promises
|
|
149
|
+
await Promise.all(recordPromises); // await all promises
|
|
150
|
+
|
|
151
|
+
return event.Records; // return all for local testing
|
|
152
|
+
} catch {
|
|
153
|
+
Logger.debug(
|
|
154
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
158
|
+
} catch (err) {
|
|
159
|
+
Logger.error('Unhandled Error, PaginateProcessLogicalHdrDsq: ', err);
|
|
160
|
+
throw err;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
19
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
20
|
+
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
21
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
22
|
+
|
|
23
|
+
import paginateProcessLogical from './PaginateProcessLogical_Main.js';
|
|
24
|
+
|
|
25
|
+
// validate event properties in body.Message of sqs event
|
|
26
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
27
|
+
|
|
28
|
+
// set schema for record.body.Message
|
|
29
|
+
const perRecordsValidatorSchema = {
|
|
30
|
+
type: 'object',
|
|
31
|
+
required: [
|
|
32
|
+
'logicalResultId',
|
|
33
|
+
'tableName',
|
|
34
|
+
'partitionKeyFieldName',
|
|
35
|
+
'sortKeyFieldName',
|
|
36
|
+
'dynamoDbIdentifiers',
|
|
37
|
+
'overWriteCache'
|
|
38
|
+
],
|
|
39
|
+
properties: {
|
|
40
|
+
logicalResultId: {
|
|
41
|
+
type: 'string'
|
|
42
|
+
},
|
|
43
|
+
tableName: {
|
|
44
|
+
type: 'string'
|
|
45
|
+
},
|
|
46
|
+
partitionKeyFieldName: {
|
|
47
|
+
type: 'string'
|
|
48
|
+
},
|
|
49
|
+
sortKeyFieldName: {
|
|
50
|
+
type: 'string'
|
|
51
|
+
},
|
|
52
|
+
dynamoDbIdentifiers: {
|
|
53
|
+
type: 'object'
|
|
54
|
+
},
|
|
55
|
+
comparison: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
default: ''
|
|
58
|
+
},
|
|
59
|
+
startKey: {
|
|
60
|
+
type: 'object',
|
|
61
|
+
default: {}
|
|
62
|
+
},
|
|
63
|
+
overwriteUniqueRequestId: {
|
|
64
|
+
type: 'string',
|
|
65
|
+
default: ''
|
|
66
|
+
},
|
|
67
|
+
overWriteCache: {
|
|
68
|
+
type: 'boolean'
|
|
69
|
+
},
|
|
70
|
+
callingFlow: {
|
|
71
|
+
type: 'string',
|
|
72
|
+
default: ''
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const main = middleware.wrap(async (event, context) => {
|
|
78
|
+
try {
|
|
79
|
+
let recordPromises = [];
|
|
80
|
+
|
|
81
|
+
// loop each record and send to mainFunction
|
|
82
|
+
await Promise.all(
|
|
83
|
+
event.Records.map(async record => {
|
|
84
|
+
// promise.all for map() function
|
|
85
|
+
|
|
86
|
+
let passOnProperties = [];
|
|
87
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
88
|
+
|
|
89
|
+
// validate message (and MessageAttributes)
|
|
90
|
+
await recordHandlerSharedLib.validateRecord(
|
|
91
|
+
record, // one record will send to mainFunction
|
|
92
|
+
'PaginateProcessLogicalHdrSqs', // queue name that need to retry or send to dlq
|
|
93
|
+
perRecordsValidatorSchema // schema for record.Message
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
97
|
+
passOnProperties.push(record.body.Message.logicalResultId);
|
|
98
|
+
passOnProperties.push(record.body.Message.tableName);
|
|
99
|
+
passOnProperties.push(record.body.Message.partitionKeyFieldName);
|
|
100
|
+
passOnProperties.push(record.body.Message.sortKeyFieldName);
|
|
101
|
+
passOnProperties.push(record.body.Message.dynamoDbIdentifiers);
|
|
102
|
+
passOnProperties.push(record.body.Message.comparison);
|
|
103
|
+
passOnProperties.push(record.body.Message.startKey);
|
|
104
|
+
passOnProperties.push(record.body.Message.overwriteUniqueRequestId);
|
|
105
|
+
passOnProperties.push(record.body.Message.overWriteCache);
|
|
106
|
+
passOnProperties.push(record.body.Message.callingFlow);
|
|
107
|
+
record._izContext.logger.debug(
|
|
108
|
+
'passOnProperties in handler',
|
|
109
|
+
passOnProperties
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
113
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
114
|
+
record, // one record will send to mainFunction
|
|
115
|
+
paginateProcessLogical, // mainFunction that need to invoke.
|
|
116
|
+
'PaginateProcessLogicalHdrSqs', // queue name that need to retry or send to dlq
|
|
117
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
118
|
+
);
|
|
119
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
120
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
125
|
+
try {
|
|
126
|
+
// --- main await all promises
|
|
127
|
+
await Promise.all(recordPromises); // await all promises
|
|
128
|
+
|
|
129
|
+
return event.Records; // return all for local testing
|
|
130
|
+
} catch {
|
|
131
|
+
Logger.debug(
|
|
132
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
136
|
+
} catch (err) {
|
|
137
|
+
Logger.error('Unhandled Error, PaginateProcessLogicalHdrSqs: ', err);
|
|
138
|
+
throw err;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
@@ -0,0 +1,268 @@
|
|
|
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
|
+
import logicalResultsSharedLib from '@izara_project/izara-core-library-logical-result';
|
|
19
|
+
import sqsSharedLib from '@izara_project/izara-core-library-sqs';
|
|
20
|
+
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
21
|
+
import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
|
|
22
|
+
|
|
23
|
+
import { sqs } from '@izara_project/izara-core-library-external-request';
|
|
24
|
+
|
|
25
|
+
import { NoRetryError } from '@izara_project/izara-core-library-core';
|
|
26
|
+
|
|
27
|
+
// set query limit
|
|
28
|
+
const limit = 2;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* performs the logical operation/filter/search in the element, saves into LogicalResultsData table
|
|
32
|
+
* @param {Object} _izContext
|
|
33
|
+
* @param {string} logicalResultId
|
|
34
|
+
* @param {string} tableName
|
|
35
|
+
* @param {string} partitionKeyFieldName
|
|
36
|
+
* @param {string} sortKeyFieldName
|
|
37
|
+
* @param {Object} dynamoDbIdentifiers
|
|
38
|
+
* @param {string} comparison
|
|
39
|
+
* @param {Object} startKey
|
|
40
|
+
* @param {string} overwriteUniqueRequestId
|
|
41
|
+
* @param {boolean} overwriteCache
|
|
42
|
+
* @param {string} callingFlow
|
|
43
|
+
*
|
|
44
|
+
* @returns {string} description of return value
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
export default async function paginateProcessLogical(
|
|
48
|
+
_izContext,
|
|
49
|
+
logicalResultId,
|
|
50
|
+
tableName,
|
|
51
|
+
partitionKeyFieldName,
|
|
52
|
+
sortKeyFieldName,
|
|
53
|
+
dynamoDbIdentifiers,
|
|
54
|
+
comparison, // optional
|
|
55
|
+
startKey, // optional
|
|
56
|
+
overwriteUniqueRequestId, // optional
|
|
57
|
+
overWriteCache,
|
|
58
|
+
callingFlow // optional
|
|
59
|
+
) {
|
|
60
|
+
try {
|
|
61
|
+
_izContext.logger.debug('----- PaginateProcessLogical event params -----', {
|
|
62
|
+
logicalResultId: logicalResultId,
|
|
63
|
+
tableName: tableName,
|
|
64
|
+
partitionKeyFieldName: partitionKeyFieldName,
|
|
65
|
+
sortKeyFieldName: sortKeyFieldName,
|
|
66
|
+
dynamoDbIdentifiers: dynamoDbIdentifiers,
|
|
67
|
+
comparison: comparison,
|
|
68
|
+
startKey: startKey,
|
|
69
|
+
overwriteUniqueRequestId: overwriteUniqueRequestId,
|
|
70
|
+
overWriteCache: overWriteCache,
|
|
71
|
+
callingFlow: callingFlow
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Check/Create logicalResultsMain
|
|
75
|
+
let [checkUniqueRequestProcessingStatus, logicalResultsMain] =
|
|
76
|
+
await asyncFlowSharedLib.checkUniqueRequestProcessing(
|
|
77
|
+
_izContext,
|
|
78
|
+
'LogicalResultsMain',
|
|
79
|
+
{
|
|
80
|
+
logicalResultId: logicalResultId
|
|
81
|
+
},
|
|
82
|
+
'paginateProcessLogical',
|
|
83
|
+
overwriteUniqueRequestId
|
|
84
|
+
);
|
|
85
|
+
_izContext.logger.debug('After check uniqueRequestProcessingStatus:', {
|
|
86
|
+
checkUniqueRequestProcessingStatus: checkUniqueRequestProcessingStatus,
|
|
87
|
+
logicalResultsMain: logicalResultsMain
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (checkUniqueRequestProcessingStatus == 'stop') {
|
|
91
|
+
return {
|
|
92
|
+
returnResponse: 'process already stop'
|
|
93
|
+
};
|
|
94
|
+
} else if (checkUniqueRequestProcessingStatus == 'recordNotFound') {
|
|
95
|
+
// should always have unless another request already completed it, in which case nothing to do
|
|
96
|
+
return {
|
|
97
|
+
returnResponse: 'record not found'
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
let errorsFound = [];
|
|
102
|
+
let standardErrorParams = [
|
|
103
|
+
_izContext,
|
|
104
|
+
logicalResultId,
|
|
105
|
+
logicalResultsMain.logicalElement,
|
|
106
|
+
logicalResultsMain.objType,
|
|
107
|
+
overWriteCache,
|
|
108
|
+
callingFlow,
|
|
109
|
+
'error'
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
let queryElements = {
|
|
113
|
+
limit: limit
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
//if received startKey validate it, if not received will return null
|
|
117
|
+
startKey = asyncFlowSharedLib.validateStartKeyParam(
|
|
118
|
+
_izContext,
|
|
119
|
+
startKey,
|
|
120
|
+
partitionKeyFieldName,
|
|
121
|
+
sortKeyFieldName
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
if (startKey === false) {
|
|
125
|
+
throw new NoRetryError('split processing received invalid startKey');
|
|
126
|
+
}
|
|
127
|
+
_izContext.logger.debug('startKey :', startKey);
|
|
128
|
+
|
|
129
|
+
if (startKey) {
|
|
130
|
+
queryElements['exclusiveStartKey'] = {
|
|
131
|
+
[partitionKeyFieldName]: startKey[partitionKeyFieldName],
|
|
132
|
+
[sortKeyFieldName]: startKey[sortKeyFieldName]
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (comparison) {
|
|
137
|
+
queryElements['sortKeyCondition'] = {
|
|
138
|
+
comparison: comparison,
|
|
139
|
+
name: sortKeyFieldName,
|
|
140
|
+
value: dynamoDbIdentifiers[sortKeyFieldName]
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let queryDatas = await dynamodbSharedLib.query(
|
|
145
|
+
_izContext,
|
|
146
|
+
await dynamodbSharedLib.tableName(_izContext, tableName),
|
|
147
|
+
{
|
|
148
|
+
[partitionKeyFieldName]: dynamoDbIdentifiers[partitionKeyFieldName]
|
|
149
|
+
},
|
|
150
|
+
queryElements
|
|
151
|
+
);
|
|
152
|
+
_izContext.logger.debug('queryDatas result: ', queryDatas);
|
|
153
|
+
|
|
154
|
+
if (!startKey && queryDatas.Items.length == 0) {
|
|
155
|
+
_izContext.logger.debug(`can't find data in table ${tableName}`);
|
|
156
|
+
errorsFound.push(`can't find data in table ${tableName}`);
|
|
157
|
+
standardErrorParams.push(errorsFound);
|
|
158
|
+
await logicalResultsSharedLib.completeLogicalResultsMain(
|
|
159
|
+
...standardErrorParams
|
|
160
|
+
);
|
|
161
|
+
return {
|
|
162
|
+
returnResponse: 'Cannot find data in table'
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// For conditionalFieldValues
|
|
167
|
+
let objInstanceBases = queryDatas.Items;
|
|
168
|
+
const conditionalFieldValues =
|
|
169
|
+
logicalResultsMain.logicalElement.conditionalFieldValues;
|
|
170
|
+
|
|
171
|
+
if (
|
|
172
|
+
Array.isArray(conditionalFieldValues) &&
|
|
173
|
+
conditionalFieldValues.length > 0
|
|
174
|
+
) {
|
|
175
|
+
for (const conditionalFieldValue of conditionalFieldValues) {
|
|
176
|
+
_izContext.logger.debug(
|
|
177
|
+
'conditionalFieldValue: ',
|
|
178
|
+
conditionalFieldValue
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
let conditionalFieldName = conditionalFieldValue.fieldName;
|
|
182
|
+
|
|
183
|
+
if (conditionalFieldValue.hasOwnProperty('includeValues')) {
|
|
184
|
+
let includeValues = conditionalFieldValue.includeValues; // array
|
|
185
|
+
|
|
186
|
+
objInstanceBases = objInstanceBases.filter(objInstanceBase => {
|
|
187
|
+
return includeValues.includes(
|
|
188
|
+
objInstanceBase[conditionalFieldName]
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
} else if (conditionalFieldValue.hasOwnProperty('excludeValues')) {
|
|
192
|
+
let excludeValues = conditionalFieldValue.excludeValues; // array
|
|
193
|
+
|
|
194
|
+
objInstanceBases = objInstanceBases.filter(objInstanceBase => {
|
|
195
|
+
return !excludeValues.includes(
|
|
196
|
+
objInstanceBase[conditionalFieldName]
|
|
197
|
+
);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
_izContext.logger.debug(
|
|
202
|
+
'objInstanceBases after conditionalFieldValues: ',
|
|
203
|
+
objInstanceBases
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
for (const objInstanceBase of objInstanceBases) {
|
|
208
|
+
await logicalResultsSharedLib.saveLogicalData(
|
|
209
|
+
_izContext,
|
|
210
|
+
logicalResultId,
|
|
211
|
+
logicalResultsMain.objType,
|
|
212
|
+
objInstanceBase
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (queryDatas.hasOwnProperty('LastEvaluatedKey')) {
|
|
217
|
+
if (!overwriteUniqueRequestId) {
|
|
218
|
+
overwriteUniqueRequestId = _izContext.uniqueRequestId;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
let continuePaginationMsg = {
|
|
222
|
+
MessageBody: JSON.stringify({
|
|
223
|
+
logicalResultId: logicalResultId,
|
|
224
|
+
tableName: tableName,
|
|
225
|
+
partitionKeyFieldName: partitionKeyFieldName,
|
|
226
|
+
sortKeyFieldName: sortKeyFieldName,
|
|
227
|
+
dynamoDbIdentifiers: dynamoDbIdentifiers,
|
|
228
|
+
comparison: comparison,
|
|
229
|
+
startKey: queryDatas.LastEvaluatedKey,
|
|
230
|
+
overwriteUniqueRequestId: overwriteUniqueRequestId,
|
|
231
|
+
overWriteCache: overWriteCache,
|
|
232
|
+
callingFlow: callingFlow
|
|
233
|
+
}),
|
|
234
|
+
QueueUrl: await sqsSharedLib.sqsQueueUrl(
|
|
235
|
+
_izContext,
|
|
236
|
+
'PaginateProcessLogicalHdrDsq'
|
|
237
|
+
)
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
_izContext.logger.debug(
|
|
241
|
+
'continuePaginationMessage: ',
|
|
242
|
+
continuePaginationMsg
|
|
243
|
+
);
|
|
244
|
+
await sqs.sendMessage(_izContext, continuePaginationMsg);
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
returnResponse: 'Continue PaginateProcessLogical'
|
|
248
|
+
};
|
|
249
|
+
} else {
|
|
250
|
+
await logicalResultsSharedLib.completeLogicalResultsMain(
|
|
251
|
+
_izContext,
|
|
252
|
+
logicalResultId,
|
|
253
|
+
logicalResultsMain.logicalElement,
|
|
254
|
+
logicalResultsMain.objType,
|
|
255
|
+
overWriteCache,
|
|
256
|
+
callingFlow,
|
|
257
|
+
'complete'
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return {
|
|
262
|
+
returnResponse: 'Function PaginateProcessLogical is Finished'
|
|
263
|
+
};
|
|
264
|
+
} catch (err) {
|
|
265
|
+
_izContext.logger.error('error PaginateProcessLogicalMain: ', err);
|
|
266
|
+
throw err;
|
|
267
|
+
}
|
|
268
|
+
}
|