@izara_project/izara-core-generate-service-code 1.0.16 → 1.0.18

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.16",
3
+ "version": "1.0.18",
4
4
  "description": "Code for locally generating per service files",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -226,8 +226,9 @@ export default async function paginateProcessLogical(
226
226
  sortKeyFieldName: sortKeyFieldName,
227
227
  dynamoDbIdentifiers: dynamoDbIdentifiers,
228
228
  comparison: comparison,
229
- overwriteUniqueRequestId: overwriteUniqueRequestId,
230
229
  startKey: queryDatas.LastEvaluatedKey,
230
+ overwriteUniqueRequestId: overwriteUniqueRequestId,
231
+ overWriteCache: overWriteCache,
231
232
  callingFlow: callingFlow
232
233
  }),
233
234
  QueueUrl: await sqsSharedLib.sqsQueueUrl(
@@ -15,9 +15,10 @@ You should have received a copy of the GNU Affero General Public License
15
15
  along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
-
19
-
20
- import { middlewareHandler as middleware, validatorSchema} from "@izara_project/izara-middleware";
18
+ import {
19
+ middlewareHandler as middleware,
20
+ validatorSchema
21
+ } from '@izara_project/izara-middleware';
21
22
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
22
23
  import Logger from '@izara_project/izara-core-library-logger';
23
24
  import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
@@ -31,129 +32,140 @@ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
31
32
 
32
33
  // validate event params in middleware before into function
33
34
  let validator = {
34
- type: "object",
35
- required: ["firstObject", "relType", "relId", "relationshipDirection"],
35
+ type: 'object',
36
+ required: ['firstObject', 'relType', 'relId', 'relationshipDirection'],
36
37
  properties: {
37
38
  firstObject: {
38
- type: "object",
39
- required: ["objType", "identifiers"],
39
+ type: 'object',
40
+ required: ['objType', 'identifiers'],
40
41
  properties: {
41
42
  objType: {
42
- type: "object",
43
- required: ["serviceTag", "objectType"],
43
+ type: 'object',
44
+ required: ['serviceTag', 'objectType'],
44
45
  properties: {
45
46
  serviceTag: validatorSchema.stringNotEmpty(),
46
- objectType: validatorSchema.stringNotEmpty(),
47
+ objectType: validatorSchema.stringNotEmpty()
47
48
  }
48
49
  },
49
50
  identifiers: {
50
- type: "object",
51
+ type: 'object',
51
52
  minProperties: 1
52
53
  }
53
54
  }
54
55
  },
55
56
  secondObject: {
56
- type: "object",
57
- required: ["objType", "identifiers"],
57
+ type: 'object',
58
+ required: ['objType', 'identifiers'],
58
59
  properties: {
59
60
  objType: {
60
- type: "object",
61
- required: ["serviceTag", "objectType"],
61
+ type: 'object',
62
+ required: ['serviceTag', 'objectType'],
62
63
  properties: {
63
64
  serviceTag: validatorSchema.stringNotEmpty(),
64
- objectType: validatorSchema.stringNotEmpty(),
65
+ objectType: validatorSchema.stringNotEmpty()
65
66
  }
66
67
  },
67
68
  identifiers: {
68
- type: "object",
69
+ type: 'object',
69
70
  minProperties: 1
70
71
  }
71
72
  }
72
73
  },
73
74
  relType: {
74
- type: "object",
75
- required: ["relationshipTag", "serviceTag"],
75
+ type: 'object',
76
+ required: ['relationshipTag', 'serviceTag'],
76
77
  properties: {
77
78
  relationshipTag: validatorSchema.stringNotEmpty(),
78
79
  serviceTag: {
79
80
  type: 'string',
80
- pattern: "^[a-zA-Z0-9_-]+$",
81
+ pattern: '^[a-zA-Z0-9_-]+$',
81
82
  enum: [process.env.iz_serviceTag]
82
83
  }
83
84
  }
84
85
  },
85
86
  relId: validatorSchema.stringNotEmpty(),
86
87
  relationshipDirection: {
87
- type: "string",
88
+ type: 'string',
88
89
  enum: ['from', 'to']
89
90
  }
90
91
  }
91
92
  };
92
93
 
93
94
  //(<globalVariable>
94
- //</globalVariable>)
95
+ //</globalVariable>)
95
96
 
96
- // validate event params in middleware before into main function
97
- validator = callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validator);
98
- // if need to validate authorizer or additional params , add code to hook tag below
97
+ // validate event params in middleware before into main function
98
+ validator =
99
+ callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validator);
100
+ // if need to validate authorizer or additional params , add code to hook tag below
99
101
 
100
- //(<afterValidateWith>)
101
- //(</afterValidateWith>)
102
+ //(<afterValidateWith>)
103
+ //(</afterValidateWith>)
102
104
 
103
- module.exports.main = middleware.wrap(async (event, context, callback) => {
104
-
105
- try {
105
+ export const main = middleware.wrap(async (event, context, callback) => {
106
+ try {
107
+ let recordPromises = []; // final return
106
108
 
107
- let recordPromises = []; // final return
109
+ // loop each record and send to mainFunction
110
+ await Promise.all(
111
+ event.Records.map(async record => {
112
+ // promise.all for map() function
108
113
 
109
- // loop each record and send to mainFunction
110
- await Promise.all(event.Records.map(async record => { // promise.all for map() function
111
-
112
- let passOnProperties = []
114
+ let passOnProperties = [];
113
115
 
114
116
  // --- validate message (and MessageAttributes)
115
117
  await recordHandlerSharedLib.validateRecord(
116
118
  record, // one record will send to mainFunction
117
- "<%-firstLetterUpperCase(queueName) %>", // queue name that need to retry or send to dlq
118
- validator, // schema for record.Message
119
+ '<%-firstLetterUpperCase(queueName) %>', // queue name that need to retry or send to dlq
120
+ validator // schema for record.Message
119
121
  // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
120
122
  );
121
123
 
122
124
  // add argument (to invoke lambda) to passOnProperties[]
123
- passOnProperties.push(record.body.Message)
124
- passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
125
+ passOnProperties.push(record.body.Message);
126
+ passOnProperties.push(
127
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(
128
+ record.body.Message
129
+ )
130
+ );
125
131
  //(<afterPutParamIntoMainFunction>)
126
132
  //(</afterPutParamIntoMainFunction>)
127
133
 
128
- record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
134
+ record._izContext.logger.debug(
135
+ 'passOnProperties in handler',
136
+ passOnProperties
137
+ );
129
138
 
130
139
  // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
131
140
  let recordPromise = recordHandlerSharedLib.recordHandler(
132
141
  record, // one record will send to mainFunction
133
- <%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
134
- "<%-firstLetterUpperCase(queueName) %>", // queue name that need to retry or send to dlq
135
- passOnProperties, // all parameters that mainFunction needed.
136
- );
137
- record._izContext.logger.debug('after recordPromise in handler');
138
- recordPromises.push(recordPromise); // push promise to recordPromises
139
- })) //end record
140
-
141
- Logger.debug('before Promise.all(recordPromises) in handler');
142
- try {
143
- await Promise.all(recordPromises); // await all promises
144
- return event.Records // return all for local test
145
- } catch {
146
- Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
147
- }
148
- Logger.debug('after Promise.all(recordPromises) in handler');
149
- } catch (err) {
150
- Logger.error('Unhandled Error, updateRelationshipHdrDsq:', err);
151
- throw (err);
152
- }
153
- });
154
- <%_ function firstLetterUpperCase(text) {
155
- return text.charAt(0).toUpperCase() + text.slice(1)
156
- } _%>
157
- <%_ function firstLetterLowerCase(str) {
158
- return str.charAt(0).toLowerCase() + str.slice(1)
159
- } _%>
142
+ <%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
143
+ '<%-firstLetterUpperCase(queueName) %>', // queue name that need to retry or send to dlq
144
+ passOnProperties // all parameters that mainFunction needed.
145
+ );
146
+ record._izContext.logger.debug('after recordPromise in handler');
147
+ recordPromises.push(recordPromise); // push promise to recordPromises
148
+ })
149
+ ); //end record
150
+
151
+ Logger.debug('before Promise.all(recordPromises) in handler');
152
+ try {
153
+ await Promise.all(recordPromises); // await all promises
154
+ return event.Records; // return all for local test
155
+ } catch {
156
+ Logger.debug(
157
+ 'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
158
+ );
159
+ }
160
+ Logger.debug('after Promise.all(recordPromises) in handler');
161
+ } catch (err) {
162
+ Logger.error('Unhandled Error, updateRelationshipHdrDsq:', err);
163
+ throw err;
164
+ }
165
+ });
166
+ <%_ function firstLetterUpperCase(text) {
167
+ return text.charAt(0).toUpperCase() + text.slice(1)
168
+ } _%>
169
+ <%_ function firstLetterLowerCase(str) {
170
+ return str.charAt(0).toLowerCase() + str.slice(1)
171
+ } _%>
@@ -31,60 +31,66 @@ middlewareHandler.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema(
31
31
 
32
32
  // validate event params in middlewareHandler before into function
33
33
  let basicValidatorSchema = {
34
- type: "object",
35
- required: ["firstObject", "relType", "relationshipProperties", "relationshipDirection", "relId"],
34
+ type: 'object',
35
+ required: [
36
+ 'firstObject',
37
+ 'relType',
38
+ 'relationshipProperties',
39
+ 'relationshipDirection',
40
+ 'relId'
41
+ ],
36
42
  properties: {
37
43
  firstObject: {
38
- type: "object",
39
- required: ["objType", "identifiers"],
44
+ type: 'object',
45
+ required: ['objType', 'identifiers'],
40
46
  properties: {
41
47
  objType: {
42
- type: "object",
43
- required: ["serviceTag", "objectType"],
48
+ type: 'object',
49
+ required: ['serviceTag', 'objectType'],
44
50
  properties: {
45
51
  serviceTag: validatorSchema.stringNotEmpty(),
46
- objectType: validatorSchema.stringNotEmpty(),
52
+ objectType: validatorSchema.stringNotEmpty()
47
53
  }
48
54
  },
49
55
  identifiers: {
50
- type: "object",
56
+ type: 'object',
51
57
  minProperties: 1
52
58
  }
53
59
  }
54
60
  },
55
61
  secondObject: {
56
- type: "object",
57
- required: ["objType", "identifiers"],
62
+ type: 'object',
63
+ required: ['objType', 'identifiers'],
58
64
  properties: {
59
65
  objType: {
60
- type: "object",
61
- required: ["serviceTag", "objectType"],
66
+ type: 'object',
67
+ required: ['serviceTag', 'objectType'],
62
68
  properties: {
63
69
  serviceTag: validatorSchema.stringNotEmpty(),
64
- objectType: validatorSchema.stringNotEmpty(),
70
+ objectType: validatorSchema.stringNotEmpty()
65
71
  }
66
72
  },
67
73
  identifiers: {
68
- type: "object",
74
+ type: 'object',
69
75
  minProperties: 1
70
76
  }
71
77
  }
72
78
  },
73
79
  relType: {
74
- type: "object",
75
- required: ["relationshipTag", "serviceTag"],
80
+ type: 'object',
81
+ required: ['relationshipTag', 'serviceTag'],
76
82
  properties: {
77
83
  relationshipTag: validatorSchema.stringNotEmpty(),
78
84
  serviceTag: {
79
85
  type: 'string',
80
- pattern: "^[a-zA-Z0-9_-]+$",
86
+ pattern: '^[a-zA-Z0-9_-]+$',
81
87
  enum: [process.env.iz_serviceTag]
82
88
  }
83
89
  }
84
90
  },
85
91
  relId: validatorSchema.stringNotEmpty(),
86
92
  relationshipDirection: {
87
- type: "string",
93
+ type: 'string',
88
94
  enum: ['from', 'to']
89
95
  }
90
96
  }
@@ -94,63 +100,78 @@ let basicValidatorSchema = {
94
100
  //</globalVariable>)
95
101
 
96
102
  // validate event params in middlewareHandler before into main function
97
- basicValidatorSchema = callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(basicValidatorSchema);
103
+ basicValidatorSchema =
104
+ callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(
105
+ basicValidatorSchema
106
+ );
98
107
  // if need to validate authorizer or additional params , add code to hook tag below
99
108
 
100
109
  //(<afterValidateWith>)
101
110
  //(</afterValidateWith>)
102
111
 
103
- module.exports.main = middlewareHandler.wrap(async (event, context, callback) => {
104
-
105
- try {
106
-
107
- let recordPromises = []; // final return
108
-
109
- // loop each record and send to mainFunction
110
- await Promise.all(event.Records.map(async record => { // promise.all for map() function
111
-
112
- let passOnProperties = []
113
-
114
- // --- validate message (and MessageAttributes)
115
- await recordHandlerSharedLib.validateRecord(
116
- record, // one record will send to mainFunction
117
- "<%- queueName %>", // queue name that need to retry or send to dlq
118
- basicValidatorSchema, // schema for record.Message
119
- // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
120
- );
121
-
122
- // add argument (to invoke lambda) to passOnProperties[]
123
- passOnProperties.push(record.body.Message)
124
- passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
125
- //(<afterPutParamIntoMainFunction>)
126
- //(</afterPutParamIntoMainFunction>)
127
-
128
- record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
129
-
130
- // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
131
- let recordPromise = recordHandlerSharedLib.recordHandler(
132
- record, // one record will send to mainFunction
133
- <%- functionName %>, // mainFunction that need to invoke.
134
- "<%- queueName %>", // queue name that need to retry or send to dlq
135
- passOnProperties, // all parameters that mainFunction needed.
136
- );
137
- record._izContext.logger.debug('after recordPromise in handler');
138
- recordPromises.push(recordPromise); // push promise to recordPromises
139
- })) //end record
112
+ export const main = middlewareHandler.wrap(
113
+ async (event, context, callback) => {
114
+ try {
115
+ let recordPromises = []; // final return
116
+
117
+ // loop each record and send to mainFunction
118
+ await Promise.all(
119
+ event.Records.map(async record => {
120
+ // promise.all for map() function
121
+
122
+ let passOnProperties = [];
123
+
124
+ // --- validate message (and MessageAttributes)
125
+ await recordHandlerSharedLib.validateRecord(
126
+ record, // one record will send to mainFunction
127
+ "<%- queueName %>", // queue name that need to retry or send to dlq
128
+ basicValidatorSchema // schema for record.Message
129
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
130
+ );
131
+
132
+ // add argument (to invoke lambda) to passOnProperties[]
133
+ passOnProperties.push(record.body.Message);
134
+ passOnProperties.push(
135
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(
136
+ record.body.Message
137
+ )
138
+ );
139
+ //(<afterPutParamIntoMainFunction>)
140
+ //(</afterPutParamIntoMainFunction>)
141
+
142
+ record._izContext.logger.debug(
143
+ 'passOnProperties in handler',
144
+ passOnProperties
145
+ );
146
+
147
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
148
+ let recordPromise = recordHandlerSharedLib.recordHandler(
149
+ record, // one record will send to mainFunction
150
+ <%- functionName %>,, // mainFunction that need to invoke.
151
+ '<%- queueName %>', // queue name that need to retry or send to dlq
152
+ passOnProperties // all parameters that mainFunction needed.
153
+ );
154
+ record._izContext.logger.debug('after recordPromise in handler');
155
+ recordPromises.push(recordPromise); // push promise to recordPromises
156
+ })
157
+ ); //end record
140
158
 
141
159
  Logger.debug('before Promise.all(recordPromises) in handler');
142
160
  try {
143
161
  await Promise.all(recordPromises); // await all promises
144
- return event.Records // return all for local test
162
+ return event.Records; // return all for local test
145
163
  } catch {
146
- Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
164
+ Logger.debug(
165
+ 'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
166
+ );
147
167
  }
148
168
  Logger.debug('after Promise.all(recordPromises) in handler');
149
169
  } catch (err) {
150
170
  Logger.error('Unhandled Error, updateRelationshipHdrDsq:', err);
151
- throw (err);
171
+ throw err;
152
172
  }
153
- });
173
+ }
174
+ );
154
175
  <%_ function firstLetterUpperCase(text) {
155
176
  return text.charAt(0).toUpperCase() + text.slice(1)
156
177
  } _%>