lambda-toolkit 1.1.1 → 2.0.0-dev.0

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,1243 +1,1637 @@
1
1
  /******/ (() => { // webpackBootstrap
2
- /******/ var __webpack_modules__ = ({
3
-
4
- /***/ 8278
5
- (module, __unused_webpack_exports, __webpack_require__) {
6
-
7
- const joinUnique = __webpack_require__( 2836 );
8
- const joinUniqueCustom = __webpack_require__( 536 );
9
- const splitBatches = __webpack_require__( 4821 );
10
-
11
- module.exports = {
12
- joinUnique,
13
- joinUniqueCustom,
14
- splitBatches
2
+ /******/ "use strict";
3
+ /******/ // The require scope
4
+ /******/ var __webpack_require__ = {};
5
+ /******/
6
+ /************************************************************************/
7
+ /******/ /* webpack/runtime/define property getters */
8
+ /******/ (() => {
9
+ /******/ // define getter functions for harmony exports
10
+ /******/ __webpack_require__.d = (exports, definition) => {
11
+ /******/ for(var key in definition) {
12
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
13
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
14
+ /******/ }
15
+ /******/ }
16
+ /******/ };
17
+ /******/ })();
18
+ /******/
19
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
20
+ /******/ (() => {
21
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
22
+ /******/ })();
23
+ /******/
24
+ /******/ /* webpack/runtime/make namespace object */
25
+ /******/ (() => {
26
+ /******/ // define __esModule on exports
27
+ /******/ __webpack_require__.r = (exports) => {
28
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
29
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
30
+ /******/ }
31
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
32
+ /******/ };
33
+ /******/ })();
34
+ /******/
35
+ /************************************************************************/
36
+ var __webpack_exports__ = {};
37
+ // ESM COMPAT FLAG
38
+ __webpack_require__.r(__webpack_exports__);
39
+
40
+ // EXPORTS
41
+ __webpack_require__.d(__webpack_exports__, {
42
+ LambdaApi: () => (/* reexport */ src_lambda_api_namespaceObject),
43
+ array: () => (/* reexport */ array_namespaceObject),
44
+ aws: () => (/* reexport */ aws_namespaceObject),
45
+ epoch: () => (/* reexport */ epoch_namespaceObject),
46
+ math: () => (/* reexport */ math_namespaceObject),
47
+ object: () => (/* reexport */ object_namespaceObject),
48
+ redis: () => (/* reexport */ redis_namespaceObject),
49
+ string: () => (/* reexport */ string_namespaceObject),
50
+ utils: () => (/* reexport */ utils_namespaceObject)
51
+ });
52
+
53
+ // NAMESPACE OBJECT: ./src/lambda_api/index.js
54
+ var src_lambda_api_namespaceObject = {};
55
+ __webpack_require__.r(src_lambda_api_namespaceObject);
56
+ __webpack_require__.d(src_lambda_api_namespaceObject, {
57
+ LambdaApi: () => (LambdaApi)
58
+ });
59
+
60
+ // NAMESPACE OBJECT: ./src/array/index.js
61
+ var array_namespaceObject = {};
62
+ __webpack_require__.r(array_namespaceObject);
63
+ __webpack_require__.d(array_namespaceObject, {
64
+ joinUnique: () => (joinUnique),
65
+ joinUniqueCustom: () => (joinUniqueCustom),
66
+ splitBatches: () => (splitBatches)
67
+ });
68
+
69
+ // NAMESPACE OBJECT: ./src/aws/index.js
70
+ var aws_namespaceObject = {};
71
+ __webpack_require__.r(aws_namespaceObject);
72
+ __webpack_require__.d(aws_namespaceObject, {
73
+ athena: () => (athena),
74
+ cwLogs: () => (cwLogs),
75
+ dynamo: () => (dynamo),
76
+ lambda: () => (lambda),
77
+ s3: () => (s3),
78
+ ses: () => (ses),
79
+ sns: () => (sns),
80
+ sqs: () => (sqs),
81
+ ssm: () => (ssm),
82
+ timestreamQuery: () => (timestreamQuery),
83
+ timestreamWrite: () => (timestreamWrite)
84
+ });
85
+
86
+ // NAMESPACE OBJECT: ./src/epoch/index.js
87
+ var epoch_namespaceObject = {};
88
+ __webpack_require__.r(epoch_namespaceObject);
89
+ __webpack_require__.d(epoch_namespaceObject, {
90
+ days: () => (days),
91
+ hours: () => (hours),
92
+ minutes: () => (minutes),
93
+ months: () => (months),
94
+ msToS: () => (msToS),
95
+ round: () => (round),
96
+ seconds: () => (seconds)
97
+ });
98
+
99
+ // NAMESPACE OBJECT: ./src/math/index.js
100
+ var math_namespaceObject = {};
101
+ __webpack_require__.r(math_namespaceObject);
102
+ __webpack_require__.d(math_namespaceObject, {
103
+ calcMean: () => (calcMean),
104
+ calcMedian: () => (calcMedian),
105
+ calcMedianAbsDev: () => (calcMedianAbsDev),
106
+ calcStdDevPopulation: () => (calcStdDevPopulation),
107
+ calcStdDevSample: () => (calcStdDevSample),
108
+ calcZScore: () => (calcZScore),
109
+ roundGaussian: () => (roundGaussian),
110
+ roundStandard: () => (roundStandard)
111
+ });
112
+
113
+ // NAMESPACE OBJECT: ./src/object/index.js
114
+ var object_namespaceObject = {};
115
+ __webpack_require__.r(object_namespaceObject);
116
+ __webpack_require__.d(object_namespaceObject, {
117
+ camelize: () => (camelize_camelize),
118
+ filterProps: () => (filterProps),
119
+ removeEmptyArrays: () => (removeEmptyArrays),
120
+ snakelize: () => (snakelize_snakelize)
121
+ });
122
+
123
+ // NAMESPACE OBJECT: ./src/redis/index.js
124
+ var redis_namespaceObject = {};
125
+ __webpack_require__.r(redis_namespaceObject);
126
+ __webpack_require__.d(redis_namespaceObject, {
127
+ createClient: () => (createClient)
128
+ });
129
+
130
+ // NAMESPACE OBJECT: ./src/string/index.js
131
+ var string_namespaceObject = {};
132
+ __webpack_require__.r(string_namespaceObject);
133
+ __webpack_require__.d(string_namespaceObject, {
134
+ camelize: () => (camelize),
135
+ capitalizeWords: () => (capitalizeWords),
136
+ snakelize: () => (snakelize)
137
+ });
138
+
139
+ // NAMESPACE OBJECT: ./src/utils/index.js
140
+ var utils_namespaceObject = {};
141
+ __webpack_require__.r(utils_namespaceObject);
142
+ __webpack_require__.d(utils_namespaceObject, {
143
+ Timer: () => (Timer),
144
+ retryOnError: () => (retryOnError),
145
+ sleep: () => (sleep_sleep),
146
+ untarJsonGz: () => (untarJsonGz)
147
+ });
148
+
149
+ ;// ./src/lambda_api/text_enum.js
150
+ const Text = {
151
+ ERROR_500: 'Internal Server Error',
152
+ ERROR_405: 'Method Not Allowed',
153
+ INVALID_ERROR_TYPE: 'Argument "errorType" must be a constructor Function',
154
+ INVALID_FN: 'Argument "fn" must be of type function',
155
+ INVALID_METHOD: 'Argument "method" must be one of the default HTTP methods',
156
+ INVALID_STATUS_CODE: 'Argument "statusCode" must be valid HTTP Status Code',
157
+ INVALID_TRANSFORM_REQUEST: 'Argument "transformRequest" must be either "camelize", "snakelize", false or null',
158
+ INVALID_TRANSFORM_RESPONSE: 'Argument "transformResponse" must be either "camelize", "snakelize", false or null',
159
+ INVALID_MATCHER_ROUTE: 'Argument "route" must be either undefined or an string with length greater than 0',
160
+ INVALID_MATCHER_ROUTE_INCLUDES: 'Argument "routeIncludes" must be either undefined or an string with length greater than 0',
161
+ INVALID_MATCHER_ROUTE_NOT_INCLUDES: 'Argument "routeNotIncludes" must be either undefined or an string with length greater than 0',
162
+ INVALID_MATCHER_ROUTE_MATCH: 'Argument "routeMatch" must be either undefined or type RegExp',
163
+ INVALID_MATCHER_PATH: 'Argument "path" must be either undefined or an string with length greater than 0',
164
+ INVALID_MATCHER_PATH_INCLUDES: 'Argument "pathIncludes" must be either undefined or an string with length greater than 0',
165
+ INVALID_MATCHER_PATH_NOT_INCLUDES: 'Argument "pathNotIncludes" must be either undefined or an string with length greater than 0',
166
+ INVALID_MATCHER_PATH_MATCH: 'Argument "pathMatch" must be either undefined or type RegExp',
167
+ INVALID_USER_RESPONSE: 'Function return must be a number, a string, an array (where p=0 is a number) or an object (where .statusCode is a number)'
15
168
  };
16
169
 
170
+ ;// ./src/lambda_api/lambda_api_validation_error.js
171
+ class LambdaApiValidationError extends Error {};
17
172
 
18
- /***/ },
173
+ ;// ./src/lambda_api/validator.js
19
174
 
20
- /***/ 2836
21
- (module) {
22
175
 
23
- module.exports = ( ...args ) => [ ...new Set( args.filter( Array.isArray ).flat() ) ];
24
176
 
177
+ const evaluate = ( condition, errorMessage ) => {
178
+ if ( !condition ) { throw new LambdaApiValidationError( errorMessage ); }
179
+ };
25
180
 
26
- /***/ },
27
-
28
- /***/ 536
29
- (module) {
30
-
31
- module.exports = ( { key, items } ) => [
32
- ...items.filter( Array.isArray ).flat().reduce( ( map, v ) => {
33
- const k = key( v );
34
- if ( !map.has( k ) ) {
35
- map.set( k, v );
36
- }
37
- return map;
38
- }, new Map() ).values()
39
- ];
181
+ const isConstructor = v => {
182
+ try {
183
+ return !!Reflect.construct( new Proxy( v, {} ), [] );
184
+ } catch {
185
+ return false;
186
+ }
187
+ };
40
188
 
189
+ const Validator = {
190
+ errorType: v => evaluate( isConstructor( v ), Text.INVALID_ERROR_TYPE ),
191
+ function: v => evaluate( typeof v === 'function', Text.INVALID_FN ),
192
+ httpMethod: v => evaluate( [ 'DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT' ].includes( v ), Text.INVALID_METHOD ),
193
+ matcherPath: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_PATH ),
194
+ matcherPathIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_PATH_INCLUDES ),
195
+ matcherPathMatch: v => evaluate( v === undefined || v?.constructor?.name === RegExp.name, Text.INVALID_MATCHER_PATH_MATCH ),
196
+ matcherPathNotIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_PATH_NOT_INCLUDES ),
197
+ matcherRoute: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_ROUTE ),
198
+ matcherRouteIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_ROUTE_INCLUDES ),
199
+ matcherRouteMatch: v => evaluate( v === undefined || v?.constructor?.name === RegExp.name, Text.INVALID_MATCHER_ROUTE_MATCH ),
200
+ matcherRouteNotIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_ROUTE_NOT_INCLUDES ),
201
+ statusCode: v => evaluate( typeof v === 'number' && /^[1-5]\d\d$/.test( String( v ) ), Text.INVALID_STATUS_CODE ),
202
+ transformRequest: v => evaluate( [ 'camelcase', 'snakecase', null, false ].includes( v ), Text.INVALID_TRANSFORM_REQUEST ),
203
+ transformResponse: v => evaluate( [ 'camelcase', 'snakecase', null, false ].includes( v ), Text.INVALID_TRANSFORM_RESPONSE )
204
+ };
41
205
 
42
- /***/ },
206
+ ;// ./src/object/is_serializable.js
207
+ const isSerializable = obj =>
208
+ typeof obj === 'object' &&
209
+ obj !== null &&
210
+ !( obj instanceof String ) &&
211
+ !( obj instanceof Number ) &&
212
+ !( obj instanceof Boolean ) &&
213
+ !( obj instanceof Date );
43
214
 
44
- /***/ 4821
45
- (module) {
215
+ ;// ./src/string/camelize.js
216
+ // Convert a string to camelCase
217
+ const camelize = ( input, { keepAllCaps = false } = {} ) =>
218
+ // Break the string into sequences to rebuild later
219
+ !input ? input : input.split( /\s/ )
220
+ // ALL_CAPS terms are ignored
221
+ .map( term => [ term, keepAllCaps && /^[A-Z_]+$/g.test( term ) ? term : term
222
+ // Matches the penultimate letter in a sequence of upper case followed by lower case and convert it to lower case
223
+ // Effectively creating a word break eg: BDay => bDay
224
+ .replace( /[A-Z](?=[A-Z][a-z])/g, c => `${c[0].toLowerCase()}` )
225
+ .replace( /([A-Z])([A-Z]+)/g, c => `${c[0]}${c.slice( 1 ).toLowerCase()}` ) // Sequences of upper case
226
+ .replace( /([-_]\w)/g, c => c[1].toUpperCase() ) // first letter after hyphen and underline
227
+ .replace( /^([A-Z])/g, c => c[0].toLowerCase() ) // first letter
228
+ ] )
229
+ // Rebuild the string replacing the converter terms keeping the original delimiters
230
+ .reduce( ( result, [ term, repl ] ) => result.replace( term, repl ), input );
46
231
 
47
- module.exports = ( items, size ) => items.reduce( ( arrs, item ) =>
48
- ( arrs[0] && arrs[0].length < size ) ?
49
- [ [ ...arrs[0], item ] ].concat( arrs.slice( 1 ) ) :
50
- [ [ item ] ].concat( arrs )
51
- , [] ).reverse();
232
+ ;// ./src/object/camelize.js
52
233
 
53
234
 
54
- /***/ },
55
235
 
56
- /***/ 228
57
- (module, __unused_webpack_exports, __webpack_require__) {
236
+ const change = ( obj, keepAllCaps ) =>
237
+ !isSerializable( obj ) ? obj : Object.entries( obj ).reduce( ( transformed, [ key, value ] ) => {
238
+ delete transformed[key];
239
+ transformed[camelize( key, { keepAllCaps } )] = typeof value === 'object' ? change( value, keepAllCaps ) : value;
240
+ return transformed;
241
+ }, Array.isArray( obj ) ? [] : {} );
58
242
 
59
- const { AthenaClient } = __webpack_require__( 3744 );
60
- const clientProvider = __webpack_require__( 9039 );
61
- const query = __webpack_require__( 140 );
62
- const createInstance = __webpack_require__( 5438 );
243
+ const camelize_camelize = ( obj, { keepAllCaps = false } = {} ) => change( obj, keepAllCaps );
63
244
 
64
- const methods = {
65
- query
66
- };
245
+ ;// ./src/string/snakelize.js
246
+ // convert a string to snake_case
247
+ const snakelize = ( input, { keepAllCaps = false } = {} ) =>
248
+ // Break the string into sequences to rebuild later
249
+ !input ? input : input.split( /\s/ )
250
+ // ALL_CAPS terms are ignored
251
+ .map( term => [ term, keepAllCaps && /^[A-Z_]+$/g.test( term ) ? term : term
252
+ .replace( /-/g, '_' ) // replaces hyphen
253
+ .replace( /([a-z\d])([A-Z])/g, '$1_$2' ) // add _ between lower and upper case letters
254
+ .replace( /([A-Z])([A-Z])(?=[a-z\d])/g, '$1_$2' ).toLowerCase() // add _ between uppercase char and next uppercase char follow by lowercase
255
+ ] )
256
+ // Rebuild the string replacing the converter terms keeping the original delimiters
257
+ .reduce( ( result, [ term, repl ] ) => result.replace( term, repl ), input );
67
258
 
68
- module.exports = createInstance( clientProvider.bind( null, AthenaClient ), methods );
259
+ ;// ./src/object/snakelize.js
69
260
 
70
261
 
71
- /***/ },
72
262
 
73
- /***/ 7337
74
- (module, __unused_webpack_exports, __webpack_require__) {
263
+ const snakelize_change = ( obj, keepAllCaps ) =>
264
+ !isSerializable( obj ) ? obj : Object.entries( obj ).reduce( ( transformed, [ key, value ] ) => {
265
+ delete transformed[key];
266
+ transformed[snakelize( key, { keepAllCaps } )] = typeof value === 'object' ? snakelize_change( value, keepAllCaps ) : value;
267
+ return transformed;
268
+ }, Array.isArray( obj ) ? [] : {} );
75
269
 
76
- const { GetQueryExecutionCommand, GetQueryResultsCommand } = __webpack_require__( 3744 );
77
- const parseResults = __webpack_require__( 834 );
78
- const pollingDelay = __webpack_require__( 4127 );
270
+ const snakelize_snakelize = ( obj, { keepAllCaps = false } = {} ) => snakelize_change( obj, keepAllCaps );
79
271
 
80
- const sleep = t => new Promise( r => setTimeout( () => r(), t ) );
272
+ ;// ./src/lambda_api/api_response.js
81
273
 
82
- const getQueryResults = async ( { client, queryExecutionId, maxResults, token } ) => {
83
- const { NextToken: nextToken, ResultSet } = await client.send( new GetQueryResultsCommand( {
84
- ...{ QueryExecutionId: queryExecutionId },
85
- ...( maxResults ? { MaxResults: maxResults } : {} ),
86
- ...( token ? { NextToken: token } : {} )
87
- } ) );
88
274
 
89
- return { nextToken, items: parseResults( ResultSet ) };
90
- };
91
- const getQueryResultsRecursive = async ( { client, queryExecutionId, token } ) => {
92
- const { nextToken, items } = await getQueryResults( { client, queryExecutionId, token } );
275
+ const charset = 'utf-8';
93
276
 
94
- if ( nextToken ) {
95
- return { items: items.concat( ( await getQueryResultsRecursive( { client, queryExecutionId, token: nextToken } ) ).items ) };
96
- }
97
- return { items };
277
+ const transformFns = {
278
+ camelcase: camelize_camelize,
279
+ snakecase: snakelize_snakelize
98
280
  };
99
281
 
100
- /**
101
- * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/athena/command/GetQueryResultsCommand/
102
- * { client, recursive, queryExecutionId, maxResults, paginationToken }
103
- */
104
- const getResults = async ( { client, recursive, queryExecutionId, token, maxResults } ) => {
105
- const { QueryExecution: { Status: status } } = await client.send( new GetQueryExecutionCommand( { QueryExecutionId: queryExecutionId } ) );
282
+ class ApiResponse {
283
+ #headers = null;
284
+ #statusCode = null;
285
+ #transformFn = false;
286
+ #isBase64Encoded = false;
287
+ #body = '';
106
288
 
107
- if ( status.State === 'FAILED' ) {
108
- throw new Error( status.AthenaError?.ErrorMessage ?? status.StateChangeReason );
289
+ constructor( { headers = {}, transform } = {} ) {
290
+ this.#transformFn = transformFns[transform] ?? ( v => v );
291
+ this.#headers = Object.assign( {
292
+ 'Cache-Control': 'no-store',
293
+ 'Access-Control-Allow-Origin': '*'
294
+ }, headers );
109
295
  }
110
296
 
111
- if ( status.State === 'SUCCEEDED' ) {
112
- const fn = recursive ? getQueryResultsRecursive : getQueryResults;
113
- return fn( { client, recursive, queryExecutionId, token, maxResults } );
297
+ setContent( statusCode, body, headers = {}, isBase64Encoded = false ) {
298
+ this.#statusCode = statusCode;
299
+ this.#isBase64Encoded = isBase64Encoded;
300
+ if ( body?.length === 0 || [ null, undefined ].includes( body ) ) {
301
+ this.#body = '';
302
+ } else if ( typeof body === 'object' ) {
303
+ this.#body = JSON.stringify( this.#transformFn( body ) );
304
+ this.#headers['Content-Type'] = `application/json; charset=${charset}`;
305
+ } else {
306
+ this.#body = String( body );
307
+ this.#headers['Content-Type'] = `text/plain; charset=${charset}`;
308
+ }
309
+ this.#headers['Content-Length'] = this.#body.length;
310
+ Object.assign( this.#headers, headers ?? {} );
311
+ return this;
114
312
  }
115
313
 
116
- // sleep an try again
117
- await sleep( pollingDelay );
118
- return getResults( { client, recursive, queryExecutionId, token, maxResults } );
314
+ toJSON() {
315
+ return {
316
+ isBase64Encoded: this.#isBase64Encoded,
317
+ statusCode: this.#statusCode,
318
+ body: this.#body,
319
+ headers: this.#headers
320
+ };
321
+ }
119
322
  };
120
323
 
121
- module.exports = getResults;
122
-
123
-
124
- /***/ },
125
-
126
- /***/ 834
127
- (module, __unused_webpack_exports, __webpack_require__) {
324
+ ;// ./src/lambda_api/event.js
128
325
 
129
- const parseValue = __webpack_require__( 9129 );
130
326
 
131
- module.exports = resultSet => {
132
- const columns = resultSet.ResultSetMetadata.ColumnInfo
133
- .map( col => ( { name: col.Name, type: col.Type } ) );
134
-
135
- // first data row contains the table field names
136
- return resultSet.Rows.slice( 1 ).map( row => {
137
- const values = row.Data.map( d => d.VarCharValue );
138
- return columns.reduce( ( obj, p, i ) => Object.assign( obj, { [p.name]: parseValue( values[i], p.type ) } ), {} );
139
- } );
327
+ const event_transformFns = {
328
+ camelcase: camelize_camelize,
329
+ snakecase: snakelize_snakelize
140
330
  };
141
331
 
332
+ const parseJson = content => {
333
+ try {
334
+ return JSON.parse( content );
335
+ } catch {
336
+ return content;
337
+ }
338
+ };
142
339
 
143
- /***/ },
144
-
145
- /***/ 9129
146
- (module) {
340
+ class Event {
341
+ #transformFn;
342
+ authorizer;
343
+ body;
344
+ rawBody;
345
+ headers;
346
+ method;
347
+ params;
348
+ path;
349
+ queryString;
350
+ route;
147
351
 
148
- /* eslint consistent-return: 0 */
149
- const removeNullValues = ( o, isArray = Array.isArray( o ) ) =>
150
- Object.entries( o ).reduce( ( newObj, [ k, v ] ) => {
151
- if ( v === null && !isArray ) { return newObj; }
152
- return Object.assign( newObj, { [k]: v?.constructor === Object ? removeNullValues( v ) : v } );
153
- }, isArray ? [] : {} );
352
+ context = {};
154
353
 
155
- module.exports = ( v, type ) => {
156
- if ( [ null, undefined ].includes( v ) ) {
157
- return undefined;
158
- }
159
- if ( v === '' && type !== 'varchar' ) {
160
- return undefined;
161
- }
162
- if ( type === 'boolean' ) {
163
- return v === 'true';
164
- }
165
- if ( [ 'float', 'decimal', 'double' ].includes( type ) ) {
166
- return parseFloat( v );
167
- }
168
- if ( [ 'tinyint', 'smallint', 'int', 'bigint' ].includes( type ) ) {
169
- return parseInt( v );
170
- }
171
- if ( 'timestamp' === type ) {
172
- return new Date( v ).getTime();
354
+ constructor( { transform = false } = {} ) {
355
+ this.#transformFn = event_transformFns[transform] ?? ( v => v );
173
356
  }
174
- if ( [ 'row', 'array' ].includes( type ) ) {
175
- const obj = v.replace( /(?<=(?:{|,\s)[\w-_]+)=/g, '@@DELIMITER@@' ) // replaces delimiter = with @@DELIMITER@@
176
- .replace( /(?<={|,\s)([\w_-]+)(?=@@DELIMITER@@)/g, '"$1"' ) // wrap object keys
177
- .replace( /(?<=@@DELIMITER@@)((?:(?!,\s|}|\[|{).)+)/g, '"$1"' ) // wrap object values
178
- .replace( /(?<=\[|,\s)((?:(?!,\s|{|\]|").)+)/g, '"$1"' ) // wrap array values
179
- .replace( /"null"/g, 'null' ) // convert "null" to null
180
- .replace( /@@DELIMITER@@/g, ':' ); // replaces @@DELIMITER@@ for :
181
357
 
182
- return removeNullValues( JSON.parse( obj ) );
183
- }
184
- if ( 'json' === type ) {
185
- return JSON.parse( v );
358
+ parseFromAwsEvent( awsEvent ) {
359
+ this[`parseFromAwsEventV${awsEvent.version === '2.0' ? 2 : 1}`]( awsEvent );
186
360
  }
187
- return v;
188
- };
189
361
 
362
+ parseFromAwsEventV1( awsEvent ) {
363
+ const {
364
+ body,
365
+ path,
366
+ resource,
367
+ httpMethod,
368
+ requestContext,
369
+ pathParameters,
370
+ headers,
371
+ multiValueHeaders,
372
+ queryStringParameters,
373
+ multiValueQueryStringParameters: multiValueQueryString,
374
+ isBase64Encoded
375
+ } = awsEvent;
190
376
 
191
- /***/ },
192
-
193
- /***/ 4127
194
- (module) {
195
-
196
- module.exports = 500;
377
+ const unifiedHeaders = {
378
+ ...headers,
379
+ ...Object.fromEntries( Object.entries( multiValueHeaders ?? {} ).map( ( [ k, v ] ) => [ k, Array.isArray( v ) ? v.join( ',' ) : k ] ) )
380
+ };
197
381
 
382
+ const unifiedQueryString = {
383
+ ...queryStringParameters,
384
+ ...Object.fromEntries( Object.entries( multiValueQueryString ?? {} ).map( ( [ k, v ] ) => [ k, Array.isArray( v ) ? v.join( ',' ) : k ] ) )
385
+ };
198
386
 
199
- /***/ },
387
+ this.authorizer = requestContext?.authorizer;
388
+ this.rawBody = body ?? null;
389
+ this.body = body ? this.#transformFn( parseJson( body ) ) : null;
390
+ this.headers = unifiedHeaders ?? {};
391
+ this.method = httpMethod;
392
+ this.params = this.#transformFn( pathParameters ) ?? {};
393
+ this.path = path;
394
+ this.queryString = this.#transformFn( unifiedQueryString ) ?? {};
395
+ this.route = resource;
396
+ this.isBase64Encoded = isBase64Encoded ?? false;
397
+ }
200
398
 
201
- /***/ 5723
202
- (module, __unused_webpack_exports, __webpack_require__) {
399
+ parseFromAwsEventV2( awsEvent ) {
400
+ const {
401
+ body,
402
+ routeKey,
403
+ requestContext,
404
+ pathParameters,
405
+ headers,
406
+ queryStringParameters,
407
+ isBase64Encoded
408
+ } = awsEvent;
203
409
 
204
- const { randomBytes } = __webpack_require__( 6982 );
205
- const { StartQueryExecutionCommand } = __webpack_require__( 3744 );
410
+ const { http: { method, path } } = requestContext;
206
411
 
207
- /**
208
- * args : https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/athena/command/StartQueryExecutionCommand/
209
- * A ClientRequestToken is created automatically
210
- */
211
- module.exports = async ( { client, ...args } ) => {
212
- const cmd = new StartQueryExecutionCommand( {
213
- ClientRequestToken: randomBytes( 16 ).toString( 'hex' ),
214
- ...args
215
- } );
216
- const { QueryExecutionId: queryId } = await client.send( cmd );
217
- return queryId;
412
+ this.authorizer = requestContext?.authorizer;
413
+ this.rawBody = body ?? null;
414
+ this.body = body ? this.#transformFn( parseJson( body ) ) : null;
415
+ this.headers = headers ?? {};
416
+ this.method = method;
417
+ this.params = this.#transformFn( pathParameters ) ?? {};
418
+ this.path = path;
419
+ this.queryString = this.#transformFn( queryStringParameters ) ?? {};
420
+ this.route = routeKey?.split( ' ' )[1].replace( /\/$/, '' );
421
+ this.isBase64Encoded = isBase64Encoded ?? false;
422
+ }
218
423
  };
219
424
 
425
+ ;// ./src/lambda_api/handler.js
220
426
 
221
- /***/ },
222
427
 
223
- /***/ 140
224
- (module, __unused_webpack_exports, __webpack_require__) {
428
+ class Handler {
429
+ #method;
430
+ #fn;
431
+ #route;
432
+ #routeIncludes;
433
+ #routeNotIncludes;
434
+ #routeMatches;
435
+ #path;
436
+ #pathIncludes;
437
+ #pathNotIncludes;
438
+ #pathMatches;
225
439
 
226
- const { encode, decode } = __webpack_require__( 5744 );
227
- const startQuery = __webpack_require__( 5723 );
228
- const getResults = __webpack_require__( 7337 );
440
+ constructor( { method, fn, ...matchers } ) {
441
+ Validator.httpMethod( method );
442
+ Validator.function( fn );
443
+ Validator.matcherRoute( matchers.route );
444
+ Validator.matcherRouteIncludes( matchers.routeIncludes );
445
+ Validator.matcherRouteNotIncludes( matchers.routeNotIncludes );
446
+ Validator.matcherRouteMatch( matchers.routeMatch );
447
+ Validator.matcherPath( matchers.path );
448
+ Validator.matcherPathIncludes( matchers.pathIncludes );
449
+ Validator.matcherPathNotIncludes( matchers.pathNotIncludes );
450
+ Validator.matcherPathMatch( matchers.pathMatch );
229
451
 
230
- const getQueryExecutionId = async ( { client, nativeArgs, recursive, paginationToken } ) => {
231
- if ( !recursive && paginationToken ) {
232
- const { queryExecutionId, token } = decode( paginationToken );
233
- return { queryExecutionId, token };
452
+ this.#method = method;
453
+ this.#fn = fn;
454
+ this.#route = matchers.route;
455
+ this.#routeIncludes = matchers.routeIncludes;
456
+ this.#routeNotIncludes = matchers.routeNotIncludes;
457
+ this.#routeMatches = matchers.routeMatches;
458
+ this.#path = matchers.path;
459
+ this.#pathIncludes = matchers.pathIncludes;
460
+ this.#pathNotIncludes = matchers.pathNotIncludes;
461
+ this.#pathMatches = matchers.pathMatches;
234
462
  }
235
463
 
236
- const queryExecutionId = await startQuery( { client, ...nativeArgs } );
237
- return { queryExecutionId };
238
- };
239
-
240
- /**
241
- * @class Result
242
- * @type {Object}
243
- * @property {Object[]} items Each query result row, parsed to a camelized js object
244
- * @property {String} paginationToken The next pagination token, if recursive = false ans there are more results for the query
245
- */
246
-
247
- /**
248
- * Executes an Athena Query
249
- * @param {*} client The native client
250
- * @param {Object} nativeArgs The native args to start the Athena Query
251
- * @param {Object=} options Query configuration
252
- * @param {Boolean=} [options.recursive=false] If to recursive query all results or to return a paginationToken after each page
253
- * @param {String=} options.paginationToken The pagination token received in the previous call to resume the query (only used when recursive = false)
254
- * @param {Number=} options.maxResults The maximum number of results per page (only when using pagination token)
255
- * @returns {Result} The query result
256
- */
257
- module.exports = async ( client, nativeArgs, options ) => {
258
- const { recursive = false, paginationToken, maxResults } = options;
259
-
260
- const { queryExecutionId, token } = await getQueryExecutionId( { client, nativeArgs, recursive, paginationToken } );
464
+ match( event ) {
465
+ if ( this.#method !== event.method ) {
466
+ return false;
467
+ }
468
+ if ( this.#route ) {
469
+ return this.#route === event.route;
470
+ }
471
+ if ( this.#path ) {
472
+ return this.#path === event.path;
473
+ }
474
+ if ( this.#routeIncludes && !event.route.includes( this.#routeIncludes ) ) {
475
+ return false;
476
+ }
477
+ if ( this.#routeNotIncludes && event.route.includes( this.#routeNotIncludes ) ) {
478
+ return false;
479
+ }
480
+ if ( this.#routeMatches && !this.#routeMatches.test( event.route ) ) {
481
+ return false;
482
+ }
483
+ if ( this.#pathIncludes && !event.path.includes( this.#pathIncludes ) ) {
484
+ return false;
485
+ }
486
+ if ( this.#pathNotIncludes && event.path.includes( this.#pathNotIncludes ) ) {
487
+ return false;
488
+ }
489
+ if ( this.#pathMatches && !this.#pathMatches.test( event.path ) ) {
490
+ return false;
491
+ }
492
+ return true;
493
+ }
261
494
 
262
- const { nextToken, items } = await getResults( { client, queryExecutionId, token, recursive, maxResults } );
263
- return { paginationToken: nextToken ? encode( { queryExecutionId, token: nextToken } ) : undefined, items };
495
+ get fn() { return this.#fn; }
264
496
  };
265
497
 
498
+ ;// ./src/lambda_api/hook.js
266
499
 
267
- /***/ },
268
-
269
- /***/ 4164
270
- (module, __unused_webpack_exports, __webpack_require__) {
271
-
272
- const cacheSym = Symbol.for( 'cache' );
273
- const crypto = __webpack_require__( 6982 );
274
-
275
- const hash = text => crypto.createHash( 'md5' ).update( text ).digest( 'hex' );
276
-
277
- const propOpts = {
278
- enumerable: false,
279
- configurable: false,
280
- writable: false
281
- };
282
-
283
- module.exports = {
284
- set: ( key, value ) => {
285
- const keySym = Symbol.for( hash( key ) );
286
500
 
287
- if ( !global[cacheSym] ) {
288
- Object.defineProperty( global, cacheSym, { ...propOpts, value: {} } );
289
- }
501
+ class Hook {
502
+ #fn;
290
503
 
291
- Object.defineProperty( global[cacheSym], keySym, { ...propOpts, value } );
292
- },
293
- get: key => {
294
- return global[cacheSym]?.[Symbol.for( hash( key ) )];
504
+ constructor( { fn } ) {
505
+ Validator.function( fn );
506
+ this.#fn = fn;
295
507
  }
296
- };
297
-
298
508
 
299
- /***/ },
300
-
301
- /***/ 5438
302
- (module) {
509
+ get fn() { return this.#fn; }
510
+ };
303
511
 
304
- /**
305
- * This is base object each AWS abstraction will provide
306
- */
307
- module.exports = ( providerFn, methods ) => {
308
- // This creates the "instance",
309
- // so calling the method as a function returns a copy of its client instantiated with the given args
310
- // every method called from it will use this instance
311
- const factory = args => {
312
- const client = providerFn( args );
313
- // return self, so it is possible use the native client
314
- methods.getClient = () => client;
315
- return Object.entries( methods ).reduce( ( o, [ k, v ] ) => Object.assign( o, { [k]: v.bind( null, client ) } ), { } );
316
- };
512
+ ;// ./src/lambda_api/user_response.js
317
513
 
318
- // This is the singleton part;
319
- // First add the static method to the factory;
320
- Object.entries( methods ).forEach( ( [ key, value ] ) => factory[key] = value );
321
514
 
322
- // Then add the special method "getClient", so it is possible use the native client
323
- factory.getClient = client => client;
324
515
 
325
- // Finally makes the proxy which will allow each singleton method to use the client provider of the AWS service+
326
- return new Proxy( factory, {
327
- get( target, key ) {
328
- const t = target[key];
329
- return ( typeof t === 'function' ) ? t.bind( null, providerFn() ) : t;
330
- }
331
- } );
332
- };
333
516
 
517
+ class UserResponse {
518
+ constructor( args ) {
519
+ if ( args === undefined ) {
520
+ this.values = [ 204 ];
521
+ } else if ( typeof args === 'string' && args.length === 0 ) {
522
+ this.values = [ 204 ];
334
523
 
335
- /***/ },
524
+ } else if ( typeof args === 'string' && args.length > 0 ) {
525
+ this.values = [ 200, args ];
336
526
 
337
- /***/ 5744
338
- (module) {
527
+ } else if ( typeof args === 'number' ) {
528
+ Validator.statusCode( args );
529
+ this.values = [ args ];
339
530
 
340
- module.exports = {
341
- encode: k => {
342
- if ( k === null || k === undefined ) { return k; }
531
+ } else if ( Array.isArray( args ) ) {
532
+ Validator.statusCode( args[0] );
533
+ this.values = args;
343
534
 
344
- return Buffer.from( JSON.stringify( k ) ).toString( 'base64' );
345
- },
346
- decode: k => {
347
- if ( k === null || k === undefined ) { return k; }
535
+ } else if ( args.statusCode ) {
536
+ Validator.statusCode( args.statusCode );
537
+ this.values = [ args.statusCode, args.body, args.headers, args.isBase64Encoded ];
348
538
 
349
- const result = Buffer.from( k, 'base64' ).toString( 'utf8' );
350
- try {
351
- return JSON.parse( result );
352
- } catch {
353
- return result;
539
+ } else if ( [ undefined, null ].includes( args ) ) {
540
+ this.values = [ 200 ];
541
+ } else {
542
+ throw new LambdaApiValidationError( Text.INVALID_USER_RESPONSE );
354
543
  }
355
544
  }
356
545
  };
357
546
 
547
+ ;// ./src/lambda_api/lambda_api.js
358
548
 
359
- /***/ },
360
-
361
- /***/ 9039
362
- (module, __unused_webpack_exports, __webpack_require__) {
363
-
364
- const cache = __webpack_require__( 4164 );
365
-
366
- module.exports = ( constructor, args = [] ) => {
367
- const cacheKey = `${constructor.name}(${args.map( arg => JSON.stringify( arg ) ).join( ',' )})`;
368
- return cache.get( cacheKey ) ?? ( () => {
369
- const client = Reflect.construct( constructor, args );
370
- cache.set( cacheKey, client );
371
- return client;
372
- } )();
373
- };
374
-
375
-
376
- /***/ },
377
549
 
378
- /***/ 2710
379
- (module, __unused_webpack_exports, __webpack_require__) {
380
550
 
381
- const { CloudWatchLogsClient } = __webpack_require__( 7493 );
382
- const clientProvider = __webpack_require__( 9039 );
383
- const query = __webpack_require__( 4338 );
384
- const createInstance = __webpack_require__( 5438 );
385
-
386
- const methods = {
387
- query
388
- };
389
551
 
390
- module.exports = createInstance( clientProvider.bind( null, CloudWatchLogsClient ), methods );
391
552
 
392
553
 
393
- /***/ },
394
554
 
395
- /***/ 739
396
- (module, __unused_webpack_exports, __webpack_require__) {
397
555
 
398
- const { GetQueryResultsCommand } = __webpack_require__( 7493 );
399
- const pollingDelay = __webpack_require__( 2549 );
400
- const sleep = t => new Promise( r => setTimeout( () => r(), t ) );
556
+ class LambdaApi {
557
+ #apiResponse = null;
558
+ #handlers = [];
559
+ #errorResponses = [];
560
+ #beforeHooks = [];
561
+ #afterHooks = [];
562
+ #transformRequest = [];
401
563
 
402
- const getResults = async ( { client, command } ) => {
403
- const { results, status } = await client.send( command );
564
+ /**
565
+ * Creates a new Lambda Api
566
+ *
567
+ * @param {Object} headers Any headers you want to be included in all responses
568
+ */
569
+ constructor( { headers = {}, transformRequest = false, transformResponse = false } = {} ) {
570
+ Validator.transformRequest( transformRequest );
571
+ Validator.transformResponse( transformResponse );
404
572
 
405
- if ( [ 'Cancelled', 'Failed', 'Timeout', 'Unknown' ].includes( status ) ) {
406
- throw new Error( `Query status is "${status}"` );
573
+ this.#transformRequest = transformRequest;
574
+ this.#apiResponse = new ApiResponse( { headers, transform: transformResponse } );
407
575
  }
408
576
 
409
- if ( status === 'Complete' ) {
410
- return results;
577
+ /**
578
+ * Register a function that will run before the matching route (only if matches)
579
+ *
580
+ * @param {Object} args
581
+ * @param {function} args.fn A function
582
+ */
583
+ addBeforeHook( { fn } = {} ) {
584
+ this.#beforeHooks.push( new Hook( { fn } ) );
411
585
  }
412
586
 
413
- // Running, Scheduled
414
- await sleep( pollingDelay );
415
- return getResults( { client, command } );
416
- };
587
+ /**
588
+ * Register a function that will run after the matching route (only if matches)
589
+ *
590
+ * @param {Object} args
591
+ * @param {function} args.fn A function
592
+ */
593
+ addAfterHook( { fn } = {} ) {
594
+ this.#afterHooks.push( new Hook( { fn } ) );
595
+ }
417
596
 
418
- module.exports = async ( { client, queryId } ) => {
419
- const command = new GetQueryResultsCommand( { queryId } );
420
- return getResults( { client, command } );
421
- };
597
+ /**
598
+ * Register a handler for a given request method and optionally a path
599
+ *
600
+ * @param {Object} args
601
+ * @param {string} args.method The method to match this handler
602
+ * @param {function} args.fn The handler function
603
+ * @param {string} [args.route] A route to match this handler
604
+ * @param {string} [args.routeIncludes] A part of the route to match this handler
605
+ * @param {string} [args.routeNotIncludes] A part of the route to not match this handler
606
+ * @param {RegExp} [args.routeMatches] A RegExp to match the route
607
+ * @param {string} [args.path] A path to match this handler
608
+ * @param {string} [args.pathIncludes] A part of the path to match this handler
609
+ * @param {string} [args.pathNotIncludes] A part of the path to not match this handler
610
+ * @param {RegExp} [args.pathMatches] A RegExp to match the path
611
+ */
612
+ addHandler( { method, fn, ...matchers } = {} ) {
613
+ this.#handlers.push( new Handler( { method, fn, ...matchers } ) );
614
+ }
422
615
 
616
+ /**
617
+ * Register an automatic error code response for given error class (constructor name)
618
+ *
619
+ * @param {Object} args
620
+ * @param {string} args.code The HTTP status code to return
621
+ * @param {class} args.errorType The error class
622
+ * @param {string} [args.message=null] Optional message to return for the status code, if not present will default to Error.message
623
+ * @param {message} [args.errorType] And optional message to display
624
+ */
625
+ addErrorHandler( { errorType, code, message = null } = {} ) {
626
+ Validator.statusCode( code );
627
+ Validator.errorType( errorType );
628
+ this.#errorResponses.push( { errorType, code, message } );
629
+ }
423
630
 
424
- /***/ },
631
+ /**
632
+ * Init the flow using a given AWS Lambda APIGateway event (v2 syntax)
633
+ *
634
+ * @param {Object} ApiGatewayPayload The raw API Gateway event
635
+ * @returns {Object} The http response with status, body and headers
636
+ */
637
+ async process( awsEvent ) {
638
+ const event = new Event( { transform: this.#transformRequest } );
639
+ event.parseFromAwsEvent( awsEvent );
425
640
 
426
- /***/ 4338
427
- (module, __unused_webpack_exports, __webpack_require__) {
641
+ if ( event.method === 'HEAD' ) {
642
+ return this.#apiResponse.setContent( 204 ).toJSON();
643
+ }
428
644
 
429
- const startQuery = __webpack_require__( 3649 );
430
- const getResults = __webpack_require__( 739 );
431
- const parseResults = __webpack_require__( 9552 );
645
+ const handler = this.#handlers.find( h => h.match( event ) );
646
+ if ( !handler ) {
647
+ return this.#apiResponse.setContent( 405, Text.ERROR_405 ).toJSON();
648
+ }
432
649
 
433
- /**
434
- * @class Result
435
- * @type {Object}
436
- * @property {Object[]} items Each query result row, parsed to a camelized js object
437
- * @property {Number} count Total number of results
438
- */
650
+ const chain = [
651
+ ...this.#beforeHooks.map( b => b.fn ),
652
+ async ev => {
653
+ const result = await handler.fn( ev );
654
+ const response = new UserResponse( result );
655
+ this.#apiResponse.setContent( ...response.values ).toJSON();
656
+ },
657
+ ...this.#afterHooks.map( a => a.fn )
658
+ ];
439
659
 
440
- /**
441
- * Executes an Athena Query
442
- * @param {*} client The native client
443
- * @param {Object} nativeArgs The native args to start the Cloudwatch Query
444
- * @param {Object=} options Extra options for this command
445
- * @param {Object=} options.range Since the nativeArgs "startTime" and "endTime" are second based epochs, the "range" argument accepts milliseconds based epochs for convenience, thus overwriting the "nativeArgs"
446
- * @param {Number} options.range.from The beginning of the time range to query, overwrites "startTime"
447
- * @param {Number} options.range.to The end of the time range to query, overwrites "endTime"
448
- * @returns {Result} The query result
449
- */
450
- module.exports = async ( client, nativeArgs, { range = {} } = {} ) => {
451
- const queryId = await startQuery( { client, nativeArgs, range } );
452
- const results = await getResults( { client, queryId } );
453
- const items = parseResults( results );
454
- return { items, count: items.length };
660
+ try {
661
+ for ( const fn of chain ) {
662
+ await fn( event );
663
+ }
664
+ return this.#apiResponse.toJSON();
665
+
666
+ } catch ( error ) {
667
+ console.error( 'Lambda API Error', { error, event } );
668
+
669
+ const response = this.#errorResponses.find( e => error instanceof e.errorType );
670
+ if ( response ) {
671
+ return this.#apiResponse.setContent( response.code, response.message ?? error.message ).toJSON();
672
+ }
673
+ return this.#apiResponse.setContent( 500, Text.ERROR_500 ).toJSON();
674
+ }
675
+ }
455
676
  };
456
677
 
678
+ ;// ./src/lambda_api/index.js
457
679
 
458
- /***/ },
459
680
 
460
- /***/ 9179
461
- (module, __unused_webpack_exports, __webpack_require__) {
462
681
 
463
- const parseValue = __webpack_require__( 2847 );
464
682
 
465
- module.exports = item =>
466
- item.reduce( ( row, { field, value } ) =>
467
- Object.assign( row, {
468
- [field]: parseValue( value )
469
- } ), {} );
683
+ ;// ./src/array/join_unique.js
684
+ const joinUnique = ( ...args ) => [ ...new Set( args.filter( Array.isArray ).flat() ) ];
470
685
 
686
+ ;// ./src/array/join_unique_custom.js
687
+ const joinUniqueCustom = ( { key, items } ) => [
688
+ ...items.filter( Array.isArray ).flat().reduce( ( map, v ) => {
689
+ const k = key( v );
690
+ if ( !map.has( k ) ) {
691
+ map.set( k, v );
692
+ }
693
+ return map;
694
+ }, new Map() ).values()
695
+ ];
471
696
 
472
- /***/ },
697
+ ;// ./src/array/split_batches.js
698
+ const splitBatches = ( items, size ) => items.reduce( ( arrs, item ) =>
699
+ ( arrs[0] && arrs[0].length < size ) ?
700
+ [ [ ...arrs[0], item ] ].concat( arrs.slice( 1 ) ) :
701
+ [ [ item ] ].concat( arrs )
702
+ , [] ).reverse();
473
703
 
474
- /***/ 9552
475
- (module, __unused_webpack_exports, __webpack_require__) {
704
+ ;// ./src/array/index.js
476
705
 
477
- const parseItem = __webpack_require__( 9179 );
478
706
 
479
- module.exports = results => results.map( item => parseItem( item ) );
480
707
 
481
708
 
482
- /***/ },
483
709
 
484
- /***/ 2847
485
- (module) {
486
710
 
487
- const parseInteger = value => {
488
- const number = parseInt( value, 10 );
489
- return number <= Number.MAX_SAFE_INTEGER && number >= Number.MIN_SAFE_INTEGER ? number : value;
490
- };
711
+ ;// external "@aws-sdk/client-athena"
712
+ const client_athena_namespaceObject = require("@aws-sdk/client-athena");
713
+ ;// external "node:crypto"
714
+ const external_node_crypto_namespaceObject = require("node:crypto");
715
+ ;// ./src/aws/core/cache_storage.js
491
716
 
492
- const parseFloatingPoint = value => {
493
- if ( value.replace( /[^\d]/g, '' ).length > 16 ) {
494
- return value;
495
- }
496
- const number = parseFloat( value, 10 );
497
- return number <= Number.MAX_SAFE_INTEGER && number >= Number.MIN_SAFE_INTEGER ? number : value;
498
- };
499
717
 
500
- /* eslint-disable consistent-return */
501
- module.exports = value => {
502
- if ( [ null, undefined ].includes( value ) ) {
503
- return undefined;
504
- }
718
+ const cacheSym = Symbol.for( 'cache' );
505
719
 
506
- if ( /^\d{4}-\d\d-\d\d((T| )\d\d:\d\d:\d\d(.\d{3})?(Z|\+\d\d:?\d\d)?)?$/.test( value ) ) {
507
- return new Date( value );
508
- }
720
+ const hash = text => (0,external_node_crypto_namespaceObject.createHash)( 'md5' ).update( text ).digest( 'hex' );
509
721
 
510
- // integer
511
- if ( /^-?\d+$/.test( value ) ) {
512
- return parseInteger( value );
513
- }
722
+ const propOpts = {
723
+ enumerable: false,
724
+ configurable: false,
725
+ writable: false
726
+ };
514
727
 
515
- // float
516
- if ( /^-?(\d+\.|\.\d+|\d+\.\d+)$/.test( value ) ) {
517
- return parseFloatingPoint( value );
518
- }
728
+ const CacheStorage = {
729
+ set: ( key, value ) => {
730
+ const keySym = Symbol.for( hash( key ) );
519
731
 
520
- // boolean
521
- if ( /^true$/.test( value ) ) {
522
- return true;
523
- }
732
+ if ( !global[cacheSym] ) {
733
+ Object.defineProperty( global, cacheSym, { ...propOpts, value: {} } );
734
+ }
524
735
 
525
- if ( /^false$/.test( value ) ) {
526
- return false;
736
+ Object.defineProperty( global[cacheSym], keySym, { ...propOpts, value } );
737
+ },
738
+ get: key => {
739
+ return global[cacheSym]?.[Symbol.for( hash( key ) )];
527
740
  }
528
-
529
- return value;
530
741
  };
531
742
 
743
+ ;// ./src/aws/core/generic_client_provider.js
532
744
 
533
- /***/ },
534
745
 
535
- /***/ 2549
536
- (module) {
746
+ const genericClientProvider = ( constructor, args = [] ) => {
747
+ const cacheKey = `${constructor.name}(${args.map( arg => JSON.stringify( arg ) ).join( ',' )})`;
748
+ return CacheStorage.get( cacheKey ) ?? ( () => {
749
+ const client = Reflect.construct( constructor, args );
750
+ CacheStorage.set( cacheKey, client );
751
+ return client;
752
+ } )();
753
+ };
537
754
 
538
- module.exports = 500;
755
+ ;// ./src/aws/core/encoder.js
756
+ const Encoder = {
757
+ encode: k => {
758
+ if ( k === null || k === undefined ) { return k; }
539
759
 
760
+ return Buffer.from( JSON.stringify( k ) ).toString( 'base64' );
761
+ },
762
+ decode: k => {
763
+ if ( k === null || k === undefined ) { return k; }
540
764
 
541
- /***/ },
765
+ const result = Buffer.from( k, 'base64' ).toString( 'utf8' );
766
+ try {
767
+ return JSON.parse( result );
768
+ } catch {
769
+ return result;
770
+ }
771
+ }
772
+ };
542
773
 
543
- /***/ 3649
544
- (module, __unused_webpack_exports, __webpack_require__) {
774
+ ;// ./src/aws/athena/lib/start_query.js
545
775
 
546
- const { StartQueryCommand } = __webpack_require__( 7493 );
547
776
 
548
- module.exports = async ( { client, nativeArgs, range } ) => {
549
- const startTime = range?.from ? Math.trunc( range.from / 1000 ) : nativeArgs.startTime;
550
- const endTime = range?.to ? Math.trunc( range.to / 1000 ) : nativeArgs.endTime;
551
777
 
552
- const { queryId } = await client.send( new StartQueryCommand( { ...nativeArgs, startTime, endTime } ) );
778
+ /**
779
+ * args : https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/athena/command/StartQueryExecutionCommand/
780
+ * A ClientRequestToken is created automatically
781
+ */
782
+ const startQuery = async ( { client, ...args } ) => {
783
+ const cmd = new client_athena_namespaceObject.StartQueryExecutionCommand( {
784
+ ClientRequestToken: (0,external_node_crypto_namespaceObject.randomBytes)( 16 ).toString( 'hex' ),
785
+ ...args
786
+ } );
787
+ const { QueryExecutionId: queryId } = await client.send( cmd );
553
788
  return queryId;
554
789
  };
555
790
 
791
+ ;// ./src/aws/athena/lib/parse_value.js
792
+ /* eslint consistent-return: 0 */
793
+ const removeNullValues = ( o, isArray = Array.isArray( o ) ) =>
794
+ Object.entries( o ).reduce( ( newObj, [ k, v ] ) => {
795
+ if ( v === null && !isArray ) { return newObj; }
796
+ return Object.assign( newObj, { [k]: v?.constructor === Object ? removeNullValues( v ) : v } );
797
+ }, isArray ? [] : {} );
556
798
 
557
- /***/ },
558
-
559
- /***/ 8593
560
- (module, __unused_webpack_exports, __webpack_require__) {
561
-
562
- const { BatchWriteCommand } = __webpack_require__( 3489 );
563
- const splitBatches = __webpack_require__( 4821 );
799
+ const parseValue = ( v, type ) => {
800
+ if ( [ null, undefined ].includes( v ) ) {
801
+ return undefined;
802
+ }
803
+ if ( v === '' && type !== 'varchar' ) {
804
+ return undefined;
805
+ }
806
+ if ( type === 'boolean' ) {
807
+ return v === 'true';
808
+ }
809
+ if ( [ 'float', 'decimal', 'double' ].includes( type ) ) {
810
+ return parseFloat( v );
811
+ }
812
+ if ( [ 'tinyint', 'smallint', 'int', 'bigint' ].includes( type ) ) {
813
+ return parseInt( v );
814
+ }
815
+ if ( 'timestamp' === type ) {
816
+ return new Date( v ).getTime();
817
+ }
818
+ if ( [ 'row', 'array' ].includes( type ) ) {
819
+ const obj = v.replace( /(?<=(?:{|,\s)[\w-_]+)=/g, '@@DELIMITER@@' ) // replaces delimiter = with @@DELIMITER@@
820
+ .replace( /(?<={|,\s)([\w_-]+)(?=@@DELIMITER@@)/g, '"$1"' ) // wrap object keys
821
+ .replace( /(?<=@@DELIMITER@@)((?:(?!,\s|}|\[|{).)+)/g, '"$1"' ) // wrap object values
822
+ .replace( /(?<=\[|,\s)((?:(?!,\s|{|\]|").)+)/g, '"$1"' ) // wrap array values
823
+ .replace( /"null"/g, 'null' ) // convert "null" to null
824
+ .replace( /@@DELIMITER@@/g, ':' ); // replaces @@DELIMITER@@ for :
564
825
 
565
- const batchSize = 25;
826
+ return removeNullValues( JSON.parse( obj ) );
827
+ }
828
+ if ( 'json' === type ) {
829
+ return JSON.parse( v );
830
+ }
831
+ return v;
832
+ };
566
833
 
567
- const getMapper = method => method === 'put' ? v => ( { PutRequest: { Item: v } } ) : v => ( { DeleteRequest: { Key: v } } );
834
+ ;// ./src/aws/athena/lib/parse_results.js
568
835
 
569
- const process = async ( { client, method, table, batches } ) => {
570
- if ( batches.length === 0 ) { return true; }
571
836
 
572
- const response = await client.send( new BatchWriteCommand( { RequestItems: { [table]: batches[0] } } ) );
837
+ const parseResults = resultSet => {
838
+ const columns = resultSet.ResultSetMetadata.ColumnInfo
839
+ .map( col => ( { name: col.Name, type: col.Type } ) );
573
840
 
574
- const unprocessed = response.UnprocessedItems?.[table];
575
- return process( {
576
- client, method, table,
577
- batches: unprocessed ? splitBatches( batches.slice( 1 ).flat().concat( unprocessed ), batchSize ) : batches.slice( 1 )
841
+ // first data row contains the table field names
842
+ return resultSet.Rows.slice( 1 ).map( row => {
843
+ const values = row.Data.map( d => d.VarCharValue );
844
+ return columns.reduce( ( obj, p, i ) => Object.assign( obj, { [p.name]: parseValue( values[i], p.type ) } ), {} );
578
845
  } );
579
846
  };
580
847
 
581
- module.exports = async ( client, method, table, items ) =>
582
- process( { client, method, table, batches: splitBatches( items.map( getMapper( method ) ), batchSize ) } );
848
+ ;// ./src/aws/athena/lib/polling_delay.js
849
+ const pollingDelay = 500;
583
850
 
851
+ ;// ./src/aws/athena/lib/get_results.js
584
852
 
585
- /***/ },
586
853
 
587
- /***/ 2966
588
- (module, __unused_webpack_exports, __webpack_require__) {
589
854
 
590
- const { DynamoDBClient } = __webpack_require__( 4671 );
591
- const { DynamoDBDocumentClient } = __webpack_require__( 3489 );
592
- const cache = __webpack_require__( 4164 );
593
855
 
594
- module.exports = nativeArgs => {
595
- const translateConfig = {
596
- // Yes I copied those from the docs, read more here:
597
- // https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html#dynamodbdocumentclientresolvedconfig-1
598
- marshallOptions: {
599
- // Whether to automatically convert empty strings, blobs, and sets to `null`.
600
- convertEmptyValues: true, // false, by default.
601
- // Whether to remove undefined values while marshalling.
602
- removeUndefinedValues: true, // false, by default.
603
- // Whether to convert typeof object to map attribute.
604
- convertClassInstanceToMap: true // false, by default.
605
- },
606
- unmarshallOptions: {
607
- // Whether to return numbers as a string instead of converting them to native JavaScript numbers.
608
- wrapNumbers: false // false, by default.
609
- }
610
- };
856
+ const sleep = t => new Promise( r => setTimeout( () => r(), t ) );
611
857
 
612
- const key = `Dynamodb(${JSON.stringify( nativeArgs )}).DocumentClient`;
613
- return cache.get( key ) ?? ( () => {
614
- const client = new DynamoDBClient( nativeArgs );
615
- const docClient = DynamoDBDocumentClient.from( client, translateConfig );
858
+ const getQueryResults = async ( { client, queryExecutionId, maxResults, token } ) => {
859
+ const { NextToken: nextToken, ResultSet } = await client.send( new client_athena_namespaceObject.GetQueryResultsCommand( {
860
+ ...{ QueryExecutionId: queryExecutionId },
861
+ ...( maxResults ? { MaxResults: maxResults } : {} ),
862
+ ...( token ? { NextToken: token } : {} )
863
+ } ) );
616
864
 
617
- cache.set( key, docClient );
618
- return docClient;
619
- } )();
865
+ return { nextToken, items: parseResults( ResultSet ) };
620
866
  };
867
+ const getQueryResultsRecursive = async ( { client, queryExecutionId, token } ) => {
868
+ const { nextToken, items } = await getQueryResults( { client, queryExecutionId, token } );
621
869
 
622
-
623
- /***/ },
624
-
625
- /***/ 1417
626
- (module, __unused_webpack_exports, __webpack_require__) {
627
-
628
- const { GetCommand } = __webpack_require__( 3489 );
629
-
630
- const parseArgs = args => {
631
- // native args mode
632
- if ( args[0] instanceof Object ) {
633
- return args[0];
870
+ if ( nextToken ) {
871
+ return { items: items.concat( ( await getQueryResultsRecursive( { client, queryExecutionId, token: nextToken } ) ).items ) };
634
872
  }
635
- // sugar mode
636
- return {
637
- TableName: args[0],
638
- Key: args[1]
639
- };
640
- };
641
-
642
- module.exports = async ( client, ...args ) => {
643
- const response = await client.send( new GetCommand( parseArgs( args ) ) );
644
- return response.Item;
873
+ return { items };
645
874
  };
646
875
 
876
+ /**
877
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/athena/command/GetQueryResultsCommand/
878
+ * { client, recursive, queryExecutionId, maxResults, paginationToken }
879
+ */
880
+ const getResults = async ( { client, recursive, queryExecutionId, token, maxResults } ) => {
881
+ const { QueryExecution: { Status: status } } = await client.send( new client_athena_namespaceObject.GetQueryExecutionCommand( { QueryExecutionId: queryExecutionId } ) );
647
882
 
648
- /***/ },
649
-
650
- /***/ 1505
651
- (module, __unused_webpack_exports, __webpack_require__) {
883
+ if ( status.State === 'FAILED' ) {
884
+ throw new Error( status.AthenaError?.ErrorMessage ?? status.StateChangeReason );
885
+ }
652
886
 
653
- const documentClientProvider = __webpack_require__( 2966 );
654
- const get = __webpack_require__( 1417 );
655
- const put = __webpack_require__( 9628 );
656
- const putBatch = __webpack_require__( 5847 );
657
- const query = __webpack_require__( 5265 );
658
- const remove = __webpack_require__( 6777 );
659
- const removeBatch = __webpack_require__( 3862 );
660
- const scan = __webpack_require__( 748 );
661
- const smartUpdate = __webpack_require__( 2266 );
662
- const transactWrite = __webpack_require__( 1659 );
663
- const update = __webpack_require__( 4144 );
664
- const createInstance = __webpack_require__( 5438 );
887
+ if ( status.State === 'SUCCEEDED' ) {
888
+ const fn = recursive ? getQueryResultsRecursive : getQueryResults;
889
+ return fn( { client, recursive, queryExecutionId, token, maxResults } );
890
+ }
665
891
 
666
- const methods = {
667
- get,
668
- put,
669
- putBatch,
670
- query,
671
- remove,
672
- removeBatch,
673
- scan,
674
- smartUpdate,
675
- transactWrite,
676
- update
892
+ // sleep an try again
893
+ await sleep( pollingDelay );
894
+ return getResults( { client, recursive, queryExecutionId, token, maxResults } );
677
895
  };
678
896
 
679
- module.exports = createInstance( documentClientProvider, methods );
680
-
897
+ ;// ./src/aws/athena/query.js
681
898
 
682
- /***/ },
683
899
 
684
- /***/ 9628
685
- (module, __unused_webpack_exports, __webpack_require__) {
686
900
 
687
- const { PutCommand } = __webpack_require__( 3489 );
688
901
 
689
- const parseArgs = args => {
690
- // native args mode
691
- if ( args[0] instanceof Object ) {
692
- return args[0];
902
+ const getQueryExecutionId = async ( { client, nativeArgs, recursive, paginationToken } ) => {
903
+ if ( !recursive && paginationToken ) {
904
+ const { queryExecutionId, token } = Encoder.decode( paginationToken );
905
+ return { queryExecutionId, token };
693
906
  }
694
- // sugar mode
695
- return {
696
- TableName: args[0],
697
- Item: args[1],
698
- ReturnValues: 'NONE',
699
- ReturnConsumedCapacity: 'NONE'
700
- };
907
+
908
+ const queryExecutionId = await startQuery( { client, ...nativeArgs } );
909
+ return { queryExecutionId };
701
910
  };
702
911
 
703
912
  /**
704
- *
705
- * @param {*} client
706
- * @param {...any} args The args. either one object with the native args or two string args, tableName and item.
707
- * @returns
913
+ * @class Result
914
+ * @type {Object}
915
+ * @property {Object[]} items Each query result row, parsed to a camelized js object
916
+ * @property {String} paginationToken The next pagination token, if recursive = false ans there are more results for the query
708
917
  */
709
- module.exports = async ( client, ...args ) => {
710
- const nativeArgs = parseArgs( args );
711
- const response = await client.send( new PutCommand( nativeArgs ) );
712
- return response.Attributes ?? nativeArgs.Item;
713
- };
714
-
715
918
 
716
- /***/ },
717
-
718
- /***/ 5847
719
- (module, __unused_webpack_exports, __webpack_require__) {
919
+ /**
920
+ * Executes an Athena Query
921
+ * @param {*} client The native client
922
+ * @param {Object} nativeArgs The native args to start the Athena Query
923
+ * @param {Object=} options Query configuration
924
+ * @param {Boolean=} [options.recursive=false] If to recursive query all results or to return a paginationToken after each page
925
+ * @param {String=} options.paginationToken The pagination token received in the previous call to resume the query (only used when recursive = false)
926
+ * @param {Number=} options.maxResults The maximum number of results per page (only when using pagination token)
927
+ * @returns {Result} The query result
928
+ */
929
+ const query = async ( client, nativeArgs, options ) => {
930
+ const { recursive = false, paginationToken, maxResults } = options;
720
931
 
721
- const batchWrite = __webpack_require__( 8593 );
932
+ const { queryExecutionId, token } = await getQueryExecutionId( { client, nativeArgs, recursive, paginationToken } );
722
933
 
723
- module.exports = async ( client, ...args ) => batchWrite( client, 'put', ...args );
934
+ const { nextToken, items } = await getResults( { client, queryExecutionId, token, recursive, maxResults } );
935
+ return { paginationToken: nextToken ? Encoder.encode( { queryExecutionId, token: nextToken } ) : undefined, items };
936
+ };
724
937
 
938
+ ;// ./src/aws/core/create_instance.js
939
+ /**
940
+ * This is base object each AWS abstraction will provide
941
+ */
942
+ const createInstance = ( providerFn, methods ) => {
943
+ // This creates the "instance",
944
+ // so calling the method as a function returns a copy of its client instantiated with the given args
945
+ // every method called from it will use this instance
946
+ const factory = args => {
947
+ const client = providerFn( args );
948
+ // return self, so it is possible use the native client
949
+ methods.getClient = () => client;
950
+ return Object.entries( methods ).reduce( ( o, [ k, v ] ) => Object.assign( o, { [k]: v.bind( null, client ) } ), { } );
951
+ };
725
952
 
726
- /***/ },
953
+ // This is the singleton part;
954
+ // First add the static method to the factory;
955
+ Object.entries( methods ).forEach( ( [ key, value ] ) => factory[key] = value );
727
956
 
728
- /***/ 5265
729
- (module, __unused_webpack_exports, __webpack_require__) {
957
+ // Then add the special method "getClient", so it is possible use the native client
958
+ factory.getClient = client => client;
730
959
 
731
- const select = __webpack_require__( 2157 );
960
+ // Finally makes the proxy which will allow each singleton method to use the client provider of the AWS service+
961
+ return new Proxy( factory, {
962
+ get( target, key ) {
963
+ const t = target[key];
964
+ return ( typeof t === 'function' ) ? t.bind( null, providerFn() ) : t;
965
+ }
966
+ } );
967
+ };
732
968
 
733
- module.exports = async ( client, ...args ) => select( client, 'query', ...args );
969
+ ;// ./src/aws/athena/index.js
734
970
 
735
971
 
736
- /***/ },
737
972
 
738
- /***/ 6777
739
- (module, __unused_webpack_exports, __webpack_require__) {
740
973
 
741
- const { DeleteCommand } = __webpack_require__( 3489 );
742
974
 
743
- module.exports = async ( client, tableName, key ) => {
744
- const { Attributes: item } = await client.send( new DeleteCommand( {
745
- ReturnValues: 'ALL_OLD',
746
- TableName: tableName,
747
- Key: key
748
- } ) );
749
- return item;
975
+ const methods = {
976
+ query: query
750
977
  };
751
978
 
979
+ const athena = createInstance( genericClientProvider.bind( null, client_athena_namespaceObject.AthenaClient ), methods );
752
980
 
753
- /***/ },
981
+ ;// external "@aws-sdk/client-cloudwatch-logs"
982
+ const client_cloudwatch_logs_namespaceObject = require("@aws-sdk/client-cloudwatch-logs");
983
+ ;// ./src/aws/cw_logs/query/start_query.js
754
984
 
755
- /***/ 3862
756
- (module, __unused_webpack_exports, __webpack_require__) {
757
985
 
758
- const batchWrite = __webpack_require__( 8593 );
759
-
760
- module.exports = async ( client, ...args ) => batchWrite( client, 'remove', ...args );
761
-
762
-
763
- /***/ },
764
-
765
- /***/ 748
766
- (module, __unused_webpack_exports, __webpack_require__) {
767
-
768
- const select = __webpack_require__( 2157 );
986
+ const start_query_startQuery = async ( { client, nativeArgs, range } ) => {
987
+ const startTime = range?.from ? Math.trunc( range.from / 1000 ) : nativeArgs.startTime;
988
+ const endTime = range?.to ? Math.trunc( range.to / 1000 ) : nativeArgs.endTime;
769
989
 
770
- module.exports = async ( client, ...args ) => select( client, 'scan', ...args );
990
+ const { queryId } = await client.send( new client_cloudwatch_logs_namespaceObject.StartQueryCommand( { ...nativeArgs, startTime, endTime } ) );
991
+ return queryId;
992
+ };
771
993
 
994
+ ;// ./src/aws/cw_logs/query/polling_delay.js
995
+ const polling_delay_pollingDelay = 500;
772
996
 
773
- /***/ },
997
+ ;// ./src/utils/sleep.js
998
+ const sleep_sleep = t => new Promise( r => setTimeout( r, t ) );
774
999
 
775
- /***/ 2157
776
- (module, __unused_webpack_exports, __webpack_require__) {
1000
+ ;// ./src/aws/cw_logs/query/get_results.js
777
1001
 
778
- const { encode, decode } = __webpack_require__( 5744 );
779
- const { ScanCommand, QueryCommand } = __webpack_require__( 3489 );
780
1002
 
781
- const query = async ( { client, command, args, recursive, startKey, items = [], count = 0 } ) => {
782
- const response = await client.send( new command( {
783
- ...args,
784
- ...( startKey && { ExclusiveStartKey: startKey } )
785
- } ) );
786
1003
 
787
- const isCount = args.Select === 'COUNT';
788
- const hasLimit = Number.isFinite( args.Limit );
789
1004
 
790
- const result = {
791
- items: isCount ? null : items.concat( response.Items ),
792
- count: count + response.Count,
793
- startKey: response.LastEvaluatedKey
794
- };
1005
+ const getResultsRecursive = async ( { client, command } ) => {
1006
+ const { results, status } = await client.send( command );
795
1007
 
796
- if ( !recursive ) {
797
- return { items: result.items, count: result.count, ...( result.startKey && { nextToken: encode( result.startKey ) } ) };
1008
+ if ( [ 'Cancelled', 'Failed', 'Timeout', 'Unknown' ].includes( status ) ) {
1009
+ throw new Error( `Query status is "${status}"` );
798
1010
  }
799
1011
 
800
- if ( result.startKey && ( isCount || ( hasLimit && result.items.length < args.Limit ) || ( !isCount && !hasLimit ) ) ) {
801
- return query( { client, command, args, recursive, ...result } );
1012
+ if ( status === 'Complete' ) {
1013
+ return results;
802
1014
  }
803
1015
 
804
- if ( isCount ) {
805
- return { items: null, count: result.count };
806
- }
807
- const trimmedItems = result.items.slice( 0, args.Limit );
808
- return { items: trimmedItems, count: trimmedItems.length };
1016
+ // Running, Scheduled
1017
+ await sleep_sleep( polling_delay_pollingDelay );
1018
+ return getResultsRecursive( { client, command } );
809
1019
  };
810
1020
 
811
- module.exports = async ( client, method, args, options = { recursive: false, paginationToken: null } ) => {
812
- const command = method === 'scan' ? ScanCommand : QueryCommand;
813
-
814
- return query( { client, command, args, recursive: options.recursive, startKey: decode( options.paginationToken ) } );
1021
+ const get_results_getResults = async ( { client, queryId } ) => {
1022
+ const command = new client_cloudwatch_logs_namespaceObject.GetQueryResultsCommand( { queryId } );
1023
+ return getResultsRecursive( { client, command } );
815
1024
  };
816
1025
 
1026
+ ;// ./src/aws/cw_logs/query/parse_value.js
1027
+ const parseInteger = value => {
1028
+ const number = parseInt( value, 10 );
1029
+ return number <= Number.MAX_SAFE_INTEGER && number >= Number.MIN_SAFE_INTEGER ? number : value;
1030
+ };
817
1031
 
818
- /***/ },
819
-
820
- /***/ 2266
821
- (module, __unused_webpack_exports, __webpack_require__) {
822
-
823
- const { UpdateCommand } = __webpack_require__( 3489 );
824
-
825
- module.exports = async ( client, tableName, key, keyValues ) => {
826
- const { updates, removals, names, values } = Object.entries( keyValues ).reduce( ( args, [ k, value ], index ) => {
827
- const isRemoval = value === undefined;
828
-
829
- const attrs = k.split( '.' ).map( ( attr, i ) => {
830
- const arrayPosition = attr.match( /\[(\d+)\]$/ )?.[1];
831
- return {
832
- key: `#${attr.replace( /\[\d+\]$|[^a-zA-Z0-9_]/g, '' )}${i}`,
833
- name: attr.replace( /\[\d+\]$/g, '' ),
834
- arrayPosition
835
- };
836
- } );
837
- const fullPath = attrs.map( attr => attr.key + ( attr.arrayPosition ? `[${attr.arrayPosition}]` : '' ) ).join( '.' );
838
- const valueId = `:v${index}`;
839
- const expAttrNames = attrs.reduce( ( obj, attr ) =>
840
- Object.assign( {}, obj, { [attr.key]: attr.name } )
841
- , {} );
842
-
843
- Object.assign( args.names, expAttrNames );
844
-
845
- if ( isRemoval ) {
846
- args.removals.push( fullPath );
847
- } else {
848
- args.updates.push( fullPath + ' = ' + valueId );
849
- Object.assign( args.values, { [valueId]: value } );
850
- }
1032
+ const parseFloatingPoint = value => {
1033
+ if ( value.replace( /[^\d]/g, '' ).length > 16 ) {
1034
+ return value;
1035
+ }
1036
+ const number = parseFloat( value, 10 );
1037
+ return number <= Number.MAX_SAFE_INTEGER && number >= Number.MIN_SAFE_INTEGER ? number : value;
1038
+ };
851
1039
 
852
- return args;
853
- }, { removals: [], updates: [], names: {}, values: {} } );
1040
+ /* eslint-disable consistent-return */
1041
+ const parse_value_parseValue = value => {
1042
+ if ( [ null, undefined ].includes( value ) ) {
1043
+ return undefined;
1044
+ }
854
1045
 
855
- const conditionalExpressions = [];
856
- for ( const k of Object.keys( key ) ) {
857
- Object.assign( names, { [`#key_${k}`]: k } );
858
- conditionalExpressions.push( `attribute_exists(#key_${k})` );
1046
+ if ( /^\d{4}-\d\d-\d\d((T| )\d\d:\d\d:\d\d(.\d{3})?(Z|\+\d\d:?\d\d)?)?$/.test( value ) ) {
1047
+ return new Date( value );
859
1048
  }
860
1049
 
861
- if ( updates.length + removals.length === 0 ) { return null; }
1050
+ // integer
1051
+ if ( /^-?\d+$/.test( value ) ) {
1052
+ return parseInteger( value );
1053
+ }
862
1054
 
863
- const expressions = [];
864
- if ( updates.length ) {
865
- expressions.push( 'SET ' + updates.join( ', ' ) );
866
- } if ( removals.length ) {
867
- expressions.push( 'REMOVE ' + removals.join( ', ' ) );
1055
+ // float
1056
+ if ( /^-?(\d+\.|\.\d+|\d+\.\d+)$/.test( value ) ) {
1057
+ return parseFloatingPoint( value );
868
1058
  }
869
1059
 
870
- const statement = {
871
- TableName: tableName,
872
- ReturnValues: 'ALL_NEW',
873
- Key: key,
874
- ConditionExpression: conditionalExpressions.join( ' AND ' ),
875
- UpdateExpression: expressions.join( ' ' ),
876
- ExpressionAttributeNames: names
877
- };
878
- if ( Object.keys( values ).length > 0 ) {
879
- statement.ExpressionAttributeValues = values;
1060
+ // boolean
1061
+ if ( /^true$/.test( value ) ) {
1062
+ return true;
880
1063
  }
881
1064
 
882
- try {
883
- const response = await client.send( new UpdateCommand( statement ) );
884
- return response.Attributes;
885
- } catch ( error ) {
886
- if ( error.constructor.name === 'ConditionalCheckFailedException' ) {
887
- console.info( 'Fail to update a record that was not found.' );
888
- return null;
889
- }
890
- throw error;
1065
+ if ( /^false$/.test( value ) ) {
1066
+ return false;
891
1067
  }
1068
+
1069
+ return value;
892
1070
  };
893
1071
 
1072
+ ;// ./src/aws/cw_logs/query/parse_item.js
894
1073
 
895
- /***/ },
896
1074
 
897
- /***/ 1659
898
- (module, __unused_webpack_exports, __webpack_require__) {
1075
+ const parseItem = item =>
1076
+ item.reduce( ( row, { field, value } ) =>
1077
+ Object.assign( row, {
1078
+ [field]: parse_value_parseValue( value )
1079
+ } ), {} );
899
1080
 
900
- const { TransactWriteCommand } = __webpack_require__( 3489 );
1081
+ ;// ./src/aws/cw_logs/query/parse_results.js
901
1082
 
902
- module.exports = async ( client, items ) => {
903
- const response = await client.send( new TransactWriteCommand( { TransactItems: items } ) );
904
- return response;
905
- };
906
1083
 
1084
+ const parse_results_parseResults = results => results.map( item => parseItem( item ) );
907
1085
 
908
- /***/ },
1086
+ ;// ./src/aws/cw_logs/query/index.js
909
1087
 
910
- /***/ 4144
911
- (module, __unused_webpack_exports, __webpack_require__) {
912
1088
 
913
- const { UpdateCommand } = __webpack_require__( 3489 );
914
1089
 
915
- module.exports = async ( client, nativeArgs ) => {
916
- const args = Object.assign( { ReturnValues: 'ALL_NEW' }, nativeArgs );
917
- const response = await client.send( new UpdateCommand( args ) );
918
- return response.Attributes;
919
- };
920
1090
 
1091
+ /**
1092
+ * @class Result
1093
+ * @type {Object}
1094
+ * @property {Object[]} items Each query result row, parsed to a camelized js object
1095
+ * @property {Number} count Total number of results
1096
+ */
921
1097
 
922
- /***/ },
1098
+ /**
1099
+ * Executes an Athena Query
1100
+ * @param {*} client The native client
1101
+ * @param {Object} nativeArgs The native args to start the Cloudwatch Query
1102
+ * @param {Object=} options Extra options for this command
1103
+ * @param {Object=} options.range Since the nativeArgs "startTime" and "endTime" are second based epochs, the "range" argument accepts milliseconds based epochs for convenience, thus overwriting the "nativeArgs"
1104
+ * @param {Number} options.range.from The beginning of the time range to query, overwrites "startTime"
1105
+ * @param {Number} options.range.to The end of the time range to query, overwrites "endTime"
1106
+ * @returns {Result} The query result
1107
+ */
1108
+ const query_query = async ( client, nativeArgs, { range = {} } = {} ) => {
1109
+ const queryId = await start_query_startQuery( { client, nativeArgs, range } );
1110
+ const results = await get_results_getResults( { client, queryId } );
1111
+ const items = parse_results_parseResults( results );
1112
+ return { items, count: items.length };
1113
+ };
923
1114
 
924
- /***/ 4870
925
- (module, __unused_webpack_exports, __webpack_require__) {
1115
+ ;// ./src/aws/cw_logs/index.js
926
1116
 
927
- const athena = __webpack_require__( 228 );
928
- const cwLogs = __webpack_require__( 2710 );
929
- const dynamo = __webpack_require__( 1505 );
930
- const lambda = __webpack_require__( 3544 );
931
- const s3 = __webpack_require__( 645 );
932
- const ses = __webpack_require__( 5624 );
933
- const sns = __webpack_require__( 3099 );
934
- const sqs = __webpack_require__( 3340 );
935
- const ssm = __webpack_require__( 5888 );
936
- const timestreamQuery = __webpack_require__( 4225 );
937
- const timestreamWrite = __webpack_require__( 2538 );
938
1117
 
939
- module.exports = {
940
- athena,
941
- cwLogs,
942
- dynamo,
943
- lambda,
944
- s3,
945
- ses,
946
- sns,
947
- sqs,
948
- ssm,
949
- timestreamQuery,
950
- timestreamWrite
951
- };
952
1118
 
953
1119
 
954
- /***/ },
955
1120
 
956
- /***/ 3544
957
- (module, __unused_webpack_exports, __webpack_require__) {
1121
+ const cw_logs_methods = {
1122
+ query: query_query
1123
+ };
958
1124
 
959
- const invoke = __webpack_require__( 5894 );
960
- const { LambdaClient } = __webpack_require__( 5892 );
961
- const clientProvider = __webpack_require__( 9039 );
962
- const createInstance = __webpack_require__( 5438 );
1125
+ const cwLogs = createInstance( genericClientProvider.bind( null, client_cloudwatch_logs_namespaceObject.CloudWatchLogsClient ), cw_logs_methods );
963
1126
 
964
- const methods = {
965
- invoke
966
- };
1127
+ ;// external "@aws-sdk/client-dynamodb"
1128
+ const client_dynamodb_namespaceObject = require("@aws-sdk/client-dynamodb");
1129
+ ;// external "@aws-sdk/lib-dynamodb"
1130
+ const lib_dynamodb_namespaceObject = require("@aws-sdk/lib-dynamodb");
1131
+ ;// ./src/aws/dynamo/document_client_provider.js
967
1132
 
968
- module.exports = createInstance( clientProvider.bind( null, LambdaClient ), methods );
969
1133
 
970
1134
 
971
- /***/ },
972
1135
 
973
- /***/ 5894
974
- (module, __unused_webpack_exports, __webpack_require__) {
1136
+ const documentClientProvider = nativeArgs => {
1137
+ const translateConfig = {
1138
+ // Yes I copied those from the docs, read more here:
1139
+ // https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html#dynamodbdocumentclientresolvedconfig-1
1140
+ marshallOptions: {
1141
+ // Whether to automatically convert empty strings, blobs, and sets to `null`.
1142
+ convertEmptyValues: true, // false, by default.
1143
+ // Whether to remove undefined values while marshalling.
1144
+ removeUndefinedValues: true, // false, by default.
1145
+ // Whether to convert typeof object to map attribute.
1146
+ convertClassInstanceToMap: true // false, by default.
1147
+ },
1148
+ unmarshallOptions: {
1149
+ // Whether to return numbers as a string instead of converting them to native JavaScript numbers.
1150
+ wrapNumbers: false // false, by default.
1151
+ }
1152
+ };
975
1153
 
976
- const { InvokeCommand } = __webpack_require__( 5892 );
977
- const AWSLambdaError = __webpack_require__( 468 );
1154
+ const key = `Dynamodb(${JSON.stringify( nativeArgs )}).DocumentClient`;
1155
+ return CacheStorage.get( key ) ?? ( () => {
1156
+ const client = new client_dynamodb_namespaceObject.DynamoDBClient( nativeArgs );
1157
+ const docClient = lib_dynamodb_namespaceObject.DynamoDBDocumentClient.from( client, translateConfig );
978
1158
 
979
- module.exports = async ( client, name, payload = {}, type = 'RequestResponse' ) => {
980
- const response = await client.send( new InvokeCommand( {
981
- FunctionName: name,
982
- InvocationType: type,
983
- Payload: Buffer.from( JSON.stringify( payload ) )
984
- } ) );
1159
+ CacheStorage.set( key, docClient );
1160
+ return docClient;
1161
+ } )();
1162
+ };
985
1163
 
986
- if ( response.FunctionError ) {
987
- throw new AWSLambdaError( response );
988
- }
1164
+ ;// ./src/aws/dynamo/get.js
989
1165
 
990
- if ( type !== 'RequestResponse' ) { return true; }
991
1166
 
992
- try {
993
- return JSON.parse( Buffer.from( response.Payload ).toString() );
994
- } catch {
995
- return response.Payload;
1167
+ const parseArgs = args => {
1168
+ // native args mode
1169
+ if ( args[0] instanceof Object ) {
1170
+ return args[0];
996
1171
  }
1172
+ // sugar mode
1173
+ return {
1174
+ TableName: args[0],
1175
+ Key: args[1]
1176
+ };
997
1177
  };
998
1178
 
1179
+ const get = async ( client, ...args ) => {
1180
+ const response = await client.send( new lib_dynamodb_namespaceObject.GetCommand( parseArgs( args ) ) );
1181
+ return response.Item;
1182
+ };
999
1183
 
1000
- /***/ },
1184
+ ;// ./src/aws/dynamo/put.js
1001
1185
 
1002
- /***/ 468
1003
- (module) {
1004
1186
 
1005
- const parsePayload = payload => {
1006
- try {
1007
- return JSON.parse( Buffer.from( payload ).toString( 'utf-8' ) );
1008
- } catch {
1009
- return null;
1187
+ const put_parseArgs = args => {
1188
+ // native args mode
1189
+ if ( args[0] instanceof Object ) {
1190
+ return args[0];
1010
1191
  }
1192
+ // sugar mode
1193
+ return {
1194
+ TableName: args[0],
1195
+ Item: args[1],
1196
+ ReturnValues: 'NONE',
1197
+ ReturnConsumedCapacity: 'NONE'
1198
+ };
1011
1199
  };
1012
1200
 
1013
- module.exports = class LambdaError extends Error {
1014
- constructor( response ) {
1015
- const { StatusCode: statusCode, Payload: rawPayload } = response;
1016
- const payload = parsePayload( rawPayload );
1017
- const lambdaErrorType = payload?.errorType ?? Error.name;
1018
- const lambdaErrorMessage = payload?.errorMessage;
1019
- if ( statusCode === 200 ) {
1020
- super( `Invoked function threw "[${lambdaErrorType}]${lambdaErrorMessage ? ' ' + lambdaErrorMessage : ''}"` );
1021
- } else {
1022
- super( 'Error invoking the function' );
1023
- }
1024
- this.statusCode = statusCode;
1025
- this.lambdaErrorType = lambdaErrorType;
1026
- this.lambdaErrorMessage = lambdaErrorMessage;
1027
- }
1201
+ /**
1202
+ *
1203
+ * @param {*} client
1204
+ * @param {...any} args The args. either one object with the native args or two string args, tableName and item.
1205
+ * @returns
1206
+ */
1207
+ const put = async ( client, ...args ) => {
1208
+ const nativeArgs = put_parseArgs( args );
1209
+ const response = await client.send( new lib_dynamodb_namespaceObject.PutCommand( nativeArgs ) );
1210
+ return response.Attributes ?? nativeArgs.Item;
1028
1211
  };
1029
1212
 
1213
+ ;// ./src/aws/dynamo/batch_write.js
1214
+
1030
1215
 
1031
- /***/ },
1032
1216
 
1033
- /***/ 3936
1034
- (module, __unused_webpack_exports, __webpack_require__) {
1217
+ const batchSize = 25;
1035
1218
 
1036
- const { CopyObjectCommand } = __webpack_require__( 5725 );
1219
+ const getMapper = method => method === 'put' ? v => ( { PutRequest: { Item: v } } ) : v => ( { DeleteRequest: { Key: v } } );
1037
1220
 
1038
- module.exports = async ( client, bucket, key, source, nativeArgs ) => {
1039
- const response = await client.send( new CopyObjectCommand( {
1040
- ...nativeArgs,
1041
- Bucket: bucket,
1042
- Key: key,
1043
- CopySource: source
1044
- } ) );
1045
- return response;
1221
+ const process = async ( { client, method, table, batches } ) => {
1222
+ if ( batches.length === 0 ) { return true; }
1223
+
1224
+ const response = await client.send( new lib_dynamodb_namespaceObject.BatchWriteCommand( { RequestItems: { [table]: batches[0] } } ) );
1225
+
1226
+ const unprocessed = response.UnprocessedItems?.[table];
1227
+ return process( {
1228
+ client, method, table,
1229
+ batches: unprocessed ? splitBatches( batches.slice( 1 ).flat().concat( unprocessed ), batchSize ) : batches.slice( 1 )
1230
+ } );
1046
1231
  };
1047
1232
 
1233
+ const batchWrite = async ( client, method, table, items ) =>
1234
+ process( { client, method, table, batches: splitBatches( items.map( getMapper( method ) ), batchSize ) } );
1048
1235
 
1049
- /***/ },
1236
+ ;// ./src/aws/dynamo/put_batch.js
1050
1237
 
1051
- /***/ 345
1052
- (module, __unused_webpack_exports, __webpack_require__) {
1053
1238
 
1054
- const { GetObjectCommand } = __webpack_require__( 5725 );
1239
+ const putBatch = async ( client, ...args ) => batchWrite( client, 'put', ...args );
1055
1240
 
1056
- module.exports = async ( client, bucket, key, nativeArgs ) => {
1057
- const response = await client.send( new GetObjectCommand( {
1058
- ...nativeArgs,
1059
- Bucket: bucket,
1060
- Key: key
1241
+ ;// ./src/aws/dynamo/select.js
1242
+
1243
+
1244
+
1245
+ const select_query = async ( { client, command, args, recursive, startKey, items = [], count = 0 } ) => {
1246
+ const response = await client.send( new command( {
1247
+ ...args,
1248
+ ...( startKey && { ExclusiveStartKey: startKey } )
1061
1249
  } ) );
1062
- const stream = response.Body;
1063
- return Buffer.concat( await stream.toArray() ).toString( 'utf-8' );
1064
- };
1065
1250
 
1251
+ const isCount = args.Select === 'COUNT';
1252
+ const hasLimit = Number.isFinite( args.Limit );
1066
1253
 
1067
- /***/ },
1254
+ const result = {
1255
+ items: isCount ? null : items.concat( response.Items ),
1256
+ count: count + response.Count,
1257
+ startKey: response.LastEvaluatedKey
1258
+ };
1068
1259
 
1069
- /***/ 3758
1070
- (module, __unused_webpack_exports, __webpack_require__) {
1260
+ if ( !recursive ) {
1261
+ return { items: result.items, count: result.count, ...( result.startKey && { nextToken: Encoder.encode( result.startKey ) } ) };
1262
+ }
1071
1263
 
1072
- const { getSignedUrl } = __webpack_require__( 4991 );
1073
- const { GetObjectCommand } = __webpack_require__( 5725 );
1264
+ if ( result.startKey && ( isCount || ( hasLimit && result.items.length < args.Limit ) || ( !isCount && !hasLimit ) ) ) {
1265
+ return select_query( { client, command, args, recursive, ...result } );
1266
+ }
1074
1267
 
1075
- module.exports = async ( client, bucket, key, expiration ) => {
1076
- const getObjectCmd = new GetObjectCommand( { Bucket: bucket, Key: key } );
1077
- const url = await getSignedUrl( client, getObjectCmd, { expiresIn: expiration } );
1078
- return url;
1268
+ if ( isCount ) {
1269
+ return { items: null, count: result.count };
1270
+ }
1271
+ const trimmedItems = result.items.slice( 0, args.Limit );
1272
+ return { items: trimmedItems, count: trimmedItems.length };
1079
1273
  };
1080
1274
 
1275
+ const select_select = async ( client, method, args, options = { recursive: false, paginationToken: null } ) => {
1276
+ const command = method === 'scan' ? lib_dynamodb_namespaceObject.ScanCommand : lib_dynamodb_namespaceObject.QueryCommand;
1081
1277
 
1082
- /***/ },
1278
+ return select_query( { client, command, args, recursive: options.recursive, startKey: Encoder.decode( options.paginationToken ) } );
1279
+ };
1083
1280
 
1084
- /***/ 279
1085
- (module, __unused_webpack_exports, __webpack_require__) {
1281
+ ;// ./src/aws/dynamo/query.js
1086
1282
 
1087
- const { HeadObjectCommand } = __webpack_require__( 5725 );
1088
1283
 
1089
- module.exports = async ( client, bucket, key ) =>
1090
- client.send( new HeadObjectCommand( { Bucket: bucket, Key: key } ) );
1284
+ const dynamo_query_query = async ( client, ...args ) => select_select( client, 'query', ...args );
1091
1285
 
1286
+ ;// ./src/aws/dynamo/remove.js
1092
1287
 
1093
- /***/ },
1094
1288
 
1095
- /***/ 645
1096
- (module, __unused_webpack_exports, __webpack_require__) {
1289
+ const remove = async ( client, tableName, key ) => {
1290
+ const { Attributes: item } = await client.send( new lib_dynamodb_namespaceObject.DeleteCommand( {
1291
+ ReturnValues: 'ALL_OLD',
1292
+ TableName: tableName,
1293
+ Key: key
1294
+ } ) );
1295
+ return item;
1296
+ };
1097
1297
 
1098
- const copy = __webpack_require__( 3936 );
1099
- const download = __webpack_require__( 345 );
1100
- const getSignedUrl = __webpack_require__( 3758 );
1101
- const head = __webpack_require__( 279 );
1102
- const upload = __webpack_require__( 9704 );
1103
- const { S3Client } = __webpack_require__( 5725 );
1104
- const clientProvider = __webpack_require__( 9039 );
1105
- const createInstance = __webpack_require__( 5438 );
1298
+ ;// ./src/aws/dynamo/remove_batch.js
1106
1299
 
1107
- const methods = {
1108
- copy,
1109
- download,
1110
- getSignedUrl,
1111
- head,
1112
- upload
1113
- };
1114
1300
 
1115
- module.exports = createInstance( clientProvider.bind( null, S3Client ), methods );
1301
+ const removeBatch = async ( client, ...args ) => batchWrite( client, 'remove', ...args );
1116
1302
 
1303
+ ;// ./src/aws/dynamo/scan.js
1117
1304
 
1118
- /***/ },
1119
1305
 
1120
- /***/ 9704
1121
- (module, __unused_webpack_exports, __webpack_require__) {
1306
+ const scan = async ( client, ...args ) => select_select( client, 'scan', ...args );
1122
1307
 
1123
- const { PutObjectCommand } = __webpack_require__( 5725 );
1308
+ ;// ./src/aws/dynamo/smart_update.js
1124
1309
 
1125
- module.exports = ( client, bucket, key, body, nativeArgs ) =>
1126
- client.send( new PutObjectCommand( {
1127
- ...nativeArgs,
1128
- Bucket: bucket,
1129
- Key: key,
1130
- Body: typeof body === 'string' || Buffer.isBuffer( body ) ? body : JSON.stringify( body )
1131
- } ) );
1132
1310
 
1311
+ const smartUpdate = async ( client, tableName, key, keyValues ) => {
1312
+ const { updates, removals, names, values } = Object.entries( keyValues ).reduce( ( args, [ k, value ], index ) => {
1313
+ const isRemoval = value === undefined;
1133
1314
 
1134
- /***/ },
1315
+ const attrs = k.split( '.' ).map( ( attr, i ) => {
1316
+ const arrayPosition = attr.match( /\[(\d+)\]$/ )?.[1];
1317
+ return {
1318
+ key: `#${attr.replace( /\[\d+\]$|[^a-zA-Z0-9_]/g, '' )}${i}`,
1319
+ name: attr.replace( /\[\d+\]$/g, '' ),
1320
+ arrayPosition
1321
+ };
1322
+ } );
1323
+ const fullPath = attrs.map( attr => attr.key + ( attr.arrayPosition ? `[${attr.arrayPosition}]` : '' ) ).join( '.' );
1324
+ const valueId = `:v${index}`;
1325
+ const expAttrNames = attrs.reduce( ( obj, attr ) =>
1326
+ Object.assign( {}, obj, { [attr.key]: attr.name } )
1327
+ , {} );
1135
1328
 
1136
- /***/ 809
1137
- (module, __unused_webpack_exports, __webpack_require__) {
1329
+ Object.assign( args.names, expAttrNames );
1138
1330
 
1139
- const { DeleteSuppressedDestinationCommand } = __webpack_require__( 9556 );
1331
+ if ( isRemoval ) {
1332
+ args.removals.push( fullPath );
1333
+ } else {
1334
+ args.updates.push( fullPath + ' = ' + valueId );
1335
+ Object.assign( args.values, { [valueId]: value } );
1336
+ }
1140
1337
 
1141
- module.exports = ( client, address ) => client.send( new DeleteSuppressedDestinationCommand( { EmailAddress: address } ) );
1338
+ return args;
1339
+ }, { removals: [], updates: [], names: {}, values: {} } );
1142
1340
 
1341
+ const conditionalExpressions = [];
1342
+ for ( const k of Object.keys( key ) ) {
1343
+ Object.assign( names, { [`#key_${k}`]: k } );
1344
+ conditionalExpressions.push( `attribute_exists(#key_${k})` );
1345
+ }
1143
1346
 
1144
- /***/ },
1347
+ if ( updates.length + removals.length === 0 ) { return null; }
1145
1348
 
1146
- /***/ 5624
1147
- (module, __unused_webpack_exports, __webpack_require__) {
1349
+ const expressions = [];
1350
+ if ( updates.length ) {
1351
+ expressions.push( 'SET ' + updates.join( ', ' ) );
1352
+ } if ( removals.length ) {
1353
+ expressions.push( 'REMOVE ' + removals.join( ', ' ) );
1354
+ }
1148
1355
 
1149
- const deleteSuppressedDestination = __webpack_require__( 809 );
1150
- const sendEmail = __webpack_require__( 1783 );
1151
- const { SESv2Client } = __webpack_require__( 9556 );
1152
- const clientProvider = __webpack_require__( 9039 );
1153
- const createInstance = __webpack_require__( 5438 );
1356
+ const statement = {
1357
+ TableName: tableName,
1358
+ ReturnValues: 'ALL_NEW',
1359
+ Key: key,
1360
+ ConditionExpression: conditionalExpressions.join( ' AND ' ),
1361
+ UpdateExpression: expressions.join( ' ' ),
1362
+ ExpressionAttributeNames: names
1363
+ };
1364
+ if ( Object.keys( values ).length > 0 ) {
1365
+ statement.ExpressionAttributeValues = values;
1366
+ }
1154
1367
 
1155
- const methods = {
1156
- deleteSuppressedDestination,
1157
- sendEmail
1368
+ try {
1369
+ const response = await client.send( new lib_dynamodb_namespaceObject.UpdateCommand( statement ) );
1370
+ return response.Attributes;
1371
+ } catch ( error ) {
1372
+ if ( error.constructor.name === 'ConditionalCheckFailedException' ) {
1373
+ console.info( 'Fail to update a record that was not found.' );
1374
+ return null;
1375
+ }
1376
+ throw error;
1377
+ }
1158
1378
  };
1159
1379
 
1160
- module.exports = createInstance( clientProvider.bind( null, SESv2Client ), methods );
1380
+ ;// ./src/aws/dynamo/transact_write.js
1161
1381
 
1162
1382
 
1163
- /***/ },
1383
+ const transactWrite = async ( client, items ) => {
1384
+ const response = await client.send( new lib_dynamodb_namespaceObject.TransactWriteCommand( { TransactItems: items } ) );
1385
+ return response;
1386
+ };
1164
1387
 
1165
- /***/ 1783
1166
- (module, __unused_webpack_exports, __webpack_require__) {
1388
+ ;// ./src/aws/dynamo/update.js
1167
1389
 
1168
- const { SendEmailCommand } = __webpack_require__( 9556 );
1169
1390
 
1170
- module.exports = ( client, { to = [], from, html, subject }, args ) =>
1171
- client.send( new SendEmailCommand( {
1172
- Destination: {
1173
- ToAddresses: to
1174
- },
1175
- Content: {
1176
- Simple: {
1177
- Body: {
1178
- Html: {
1179
- Data: html,
1180
- Charset: 'utf-8'
1181
- }
1182
- },
1183
- Subject: {
1184
- Data: subject
1185
- }
1186
- }
1187
- },
1188
- FromEmailAddress: from,
1189
- ...args
1190
- } ) );
1391
+ const update = async ( client, nativeArgs ) => {
1392
+ const args = Object.assign( { ReturnValues: 'ALL_NEW' }, nativeArgs );
1393
+ const response = await client.send( new lib_dynamodb_namespaceObject.UpdateCommand( args ) );
1394
+ return response.Attributes;
1395
+ };
1191
1396
 
1397
+ ;// ./src/aws/dynamo/index.js
1192
1398
 
1193
- /***/ },
1194
1399
 
1195
- /***/ 3099
1196
- (module, __unused_webpack_exports, __webpack_require__) {
1197
1400
 
1198
- const publish = __webpack_require__( 8080 );
1199
- const publishBatch = __webpack_require__( 3531 );
1200
- const { SNSClient } = __webpack_require__( 7651 );
1201
- const clientProvider = __webpack_require__( 9039 );
1202
- const createInstance = __webpack_require__( 5438 );
1203
1401
 
1204
- const methods = {
1205
- publish,
1206
- publishBatch
1207
- };
1208
1402
 
1209
- module.exports = createInstance( clientProvider.bind( null, SNSClient ), methods );
1210
1403
 
1211
1404
 
1212
- /***/ },
1213
1405
 
1214
- /***/ 8080
1215
- (module, __unused_webpack_exports, __webpack_require__) {
1216
1406
 
1217
- const { PublishCommand } = __webpack_require__( 7651 );
1218
1407
 
1219
- module.exports = async ( client, topic, message, args = {} ) => {
1220
- const response = await client.send( new PublishCommand( {
1221
- ...args,
1222
- TopicArn: topic,
1223
- Message: typeof message === 'string' ? message : JSON.stringify( message )
1224
- } ) );
1225
- return response.MessageId;
1226
- };
1227
1408
 
1228
1409
 
1229
- /***/ },
1230
1410
 
1231
- /***/ 3531
1232
- (module, __unused_webpack_exports, __webpack_require__) {
1411
+ const dynamo_methods = {
1412
+ get: get,
1413
+ put: put,
1414
+ putBatch: putBatch,
1415
+ query: dynamo_query_query,
1416
+ remove: remove,
1417
+ removeBatch: removeBatch,
1418
+ scan: scan,
1419
+ smartUpdate: smartUpdate,
1420
+ transactWrite: transactWrite,
1421
+ update: update
1422
+ };
1233
1423
 
1234
- const { PublishBatchCommand } = __webpack_require__( 7651 );
1424
+ const dynamo = createInstance( documentClientProvider, dynamo_methods );
1235
1425
 
1236
- module.exports = async ( client, topic, messages ) => {
1237
- if ( messages.length > 10 ) {
1426
+ ;// external "@aws-sdk/client-lambda"
1427
+ const client_lambda_namespaceObject = require("@aws-sdk/client-lambda");
1428
+ ;// ./src/aws/lambda/lambda_error.js
1429
+ const parsePayload = payload => {
1430
+ try {
1431
+ return JSON.parse( Buffer.from( payload ).toString( 'utf-8' ) );
1432
+ } catch {
1433
+ return null;
1434
+ }
1435
+ };
1436
+
1437
+ class LambdaError extends Error {
1438
+ constructor( response ) {
1439
+ const { StatusCode: statusCode, Payload: rawPayload } = response;
1440
+ const payload = parsePayload( rawPayload );
1441
+ const lambdaErrorType = payload?.errorType ?? Error.name;
1442
+ const lambdaErrorMessage = payload?.errorMessage;
1443
+ if ( statusCode === 200 ) {
1444
+ super( `Invoked function threw "[${lambdaErrorType}]${lambdaErrorMessage ? ' ' + lambdaErrorMessage : ''}"` );
1445
+ } else {
1446
+ super( 'Error invoking the function' );
1447
+ }
1448
+ this.statusCode = statusCode;
1449
+ this.lambdaErrorType = lambdaErrorType;
1450
+ this.lambdaErrorMessage = lambdaErrorMessage;
1451
+ }
1452
+ };
1453
+
1454
+ ;// ./src/aws/lambda/invoke.js
1455
+
1456
+
1457
+
1458
+ const invoke = async ( client, name, payload = {}, type = 'RequestResponse' ) => {
1459
+ const response = await client.send( new client_lambda_namespaceObject.InvokeCommand( {
1460
+ FunctionName: name,
1461
+ InvocationType: type,
1462
+ Payload: Buffer.from( JSON.stringify( payload ) )
1463
+ } ) );
1464
+
1465
+ if ( response.FunctionError ) {
1466
+ throw new LambdaError( response );
1467
+ }
1468
+
1469
+ if ( type !== 'RequestResponse' ) { return true; }
1470
+
1471
+ try {
1472
+ return JSON.parse( Buffer.from( response.Payload ).toString() );
1473
+ } catch {
1474
+ return response.Payload;
1475
+ }
1476
+ };
1477
+
1478
+ ;// ./src/aws/lambda/index.js
1479
+
1480
+
1481
+
1482
+
1483
+
1484
+ const lambda_methods = {
1485
+ invoke: invoke
1486
+ };
1487
+
1488
+ const lambda = createInstance( genericClientProvider.bind( null, client_lambda_namespaceObject.LambdaClient ), lambda_methods );
1489
+
1490
+ ;// external "@aws-sdk/client-s3"
1491
+ const client_s3_namespaceObject = require("@aws-sdk/client-s3");
1492
+ ;// ./src/aws/s3/copy.js
1493
+
1494
+
1495
+ const copy = async ( client, bucket, key, source, nativeArgs ) => {
1496
+ const response = await client.send( new client_s3_namespaceObject.CopyObjectCommand( {
1497
+ ...nativeArgs,
1498
+ Bucket: bucket,
1499
+ Key: key,
1500
+ CopySource: source
1501
+ } ) );
1502
+ return response;
1503
+ };
1504
+
1505
+ ;// ./src/aws/s3/download.js
1506
+
1507
+
1508
+ const download = async ( client, bucket, key, nativeArgs ) => {
1509
+ const response = await client.send( new client_s3_namespaceObject.GetObjectCommand( {
1510
+ ...nativeArgs,
1511
+ Bucket: bucket,
1512
+ Key: key
1513
+ } ) );
1514
+ const stream = response.Body;
1515
+ return Buffer.concat( await stream.toArray() ).toString( 'utf-8' );
1516
+ };
1517
+
1518
+ ;// external "@aws-sdk/s3-request-presigner"
1519
+ const s3_request_presigner_namespaceObject = require("@aws-sdk/s3-request-presigner");
1520
+ ;// ./src/aws/s3/get_signed_url.js
1521
+
1522
+
1523
+
1524
+ const getSignedUrl = async ( client, bucket, key, expiration ) => {
1525
+ const getObjectCmd = new client_s3_namespaceObject.GetObjectCommand( { Bucket: bucket, Key: key } );
1526
+ const url = await (0,s3_request_presigner_namespaceObject.getSignedUrl)( client, getObjectCmd, { expiresIn: expiration } );
1527
+ return url;
1528
+ };
1529
+
1530
+ ;// ./src/aws/s3/head.js
1531
+
1532
+
1533
+ const head = async ( client, bucket, key ) =>
1534
+ client.send( new client_s3_namespaceObject.HeadObjectCommand( { Bucket: bucket, Key: key } ) );
1535
+
1536
+ ;// ./src/aws/s3/upload.js
1537
+
1538
+
1539
+ const upload = ( client, bucket, key, body, nativeArgs ) =>
1540
+ client.send( new client_s3_namespaceObject.PutObjectCommand( {
1541
+ ...nativeArgs,
1542
+ Bucket: bucket,
1543
+ Key: key,
1544
+ Body: typeof body === 'string' || Buffer.isBuffer( body ) ? body : JSON.stringify( body )
1545
+ } ) );
1546
+
1547
+ ;// ./src/aws/s3/index.js
1548
+
1549
+
1550
+
1551
+
1552
+
1553
+
1554
+
1555
+
1556
+
1557
+ const s3_methods = {
1558
+ copy: copy,
1559
+ download: download,
1560
+ getSignedUrl: getSignedUrl,
1561
+ head: head,
1562
+ upload: upload
1563
+ };
1564
+
1565
+ const s3 = createInstance( genericClientProvider.bind( null, client_s3_namespaceObject.S3Client ), s3_methods );
1566
+
1567
+ ;// external "@aws-sdk/client-sesv2"
1568
+ const client_sesv2_namespaceObject = require("@aws-sdk/client-sesv2");
1569
+ ;// ./src/aws/ses/delete_suppressed_destination.js
1570
+
1571
+
1572
+ const deleteSuppressedDestination = ( client, address ) => client.send( new client_sesv2_namespaceObject.DeleteSuppressedDestinationCommand( { EmailAddress: address } ) );
1573
+
1574
+ ;// ./src/aws/ses/send_email.js
1575
+
1576
+
1577
+ const sendEmail = ( client, { to = [], from, html, subject }, args ) =>
1578
+ client.send( new client_sesv2_namespaceObject.SendEmailCommand( {
1579
+ Destination: {
1580
+ ToAddresses: to
1581
+ },
1582
+ Content: {
1583
+ Simple: {
1584
+ Body: {
1585
+ Html: {
1586
+ Data: html,
1587
+ Charset: 'utf-8'
1588
+ }
1589
+ },
1590
+ Subject: {
1591
+ Data: subject
1592
+ }
1593
+ }
1594
+ },
1595
+ FromEmailAddress: from,
1596
+ ...args
1597
+ } ) );
1598
+
1599
+ ;// ./src/aws/ses/index.js
1600
+
1601
+
1602
+
1603
+
1604
+
1605
+
1606
+ const ses_methods = {
1607
+ deleteSuppressedDestination: deleteSuppressedDestination,
1608
+ sendEmail: sendEmail
1609
+ };
1610
+
1611
+ const ses = createInstance( genericClientProvider.bind( null, client_sesv2_namespaceObject.SESv2Client ), ses_methods );
1612
+
1613
+ ;// external "@aws-sdk/client-sns"
1614
+ const client_sns_namespaceObject = require("@aws-sdk/client-sns");
1615
+ ;// ./src/aws/sns/publish.js
1616
+
1617
+
1618
+ const publish = async ( client, topic, message, args = {} ) => {
1619
+ const response = await client.send( new client_sns_namespaceObject.PublishCommand( {
1620
+ ...args,
1621
+ TopicArn: topic,
1622
+ Message: typeof message === 'string' ? message : JSON.stringify( message )
1623
+ } ) );
1624
+ return response.MessageId;
1625
+ };
1626
+
1627
+ ;// ./src/aws/sns/publish_batch.js
1628
+
1629
+
1630
+ const publishBatch = async ( client, topic, messages ) => {
1631
+ if ( messages.length > 10 ) {
1238
1632
  throw new Error( 'SNS.publishBatch only accepts up to 10 messages.' );
1239
1633
  }
1240
- const response = await client.send( new PublishBatchCommand( {
1634
+ const response = await client.send( new client_sns_namespaceObject.PublishBatchCommand( {
1241
1635
  TopicArn: topic,
1242
1636
  PublishBatchRequestEntries: messages.map( ( { body, id = null, nativeArgs }, index ) => ( {
1243
1637
  Id: id ?? `message_${index}`,
@@ -1254,65 +1648,45 @@ module.exports = async ( client, topic, messages ) => {
1254
1648
  return response;
1255
1649
  };
1256
1650
 
1651
+ ;// ./src/aws/sns/index.js
1257
1652
 
1258
- /***/ },
1259
-
1260
- /***/ 5637
1261
- (module, __unused_webpack_exports, __webpack_require__) {
1262
-
1263
- const { DeleteMessageCommand } = __webpack_require__( 1976 );
1264
-
1265
- module.exports = async ( client, queue, receiptHandle ) =>
1266
- client.send( new DeleteMessageCommand( {
1267
- QueueUrl: queue,
1268
- ReceiptHandle: receiptHandle
1269
- } ) );
1270
1653
 
1271
1654
 
1272
- /***/ },
1273
1655
 
1274
- /***/ 3340
1275
- (module, __unused_webpack_exports, __webpack_require__) {
1276
1656
 
1277
- const deleteMessage = __webpack_require__( 5637 );
1278
- const sendMessage = __webpack_require__( 6720 );
1279
- const sendMessageBatch = __webpack_require__( 3131 );
1280
- const { SQSClient } = __webpack_require__( 1976 );
1281
- const clientProvider = __webpack_require__( 9039 );
1282
- const createInstance = __webpack_require__( 5438 );
1283
1657
 
1284
- const methods = {
1285
- deleteMessage,
1286
- sendMessage,
1287
- sendMessageBatch
1658
+ const sns_methods = {
1659
+ publish: publish,
1660
+ publishBatch: publishBatch
1288
1661
  };
1289
1662
 
1290
- module.exports = createInstance( clientProvider.bind( null, SQSClient ), methods );
1663
+ const sns = createInstance( genericClientProvider.bind( null, client_sns_namespaceObject.SNSClient ), sns_methods );
1291
1664
 
1665
+ ;// external "@aws-sdk/client-sqs"
1666
+ const client_sqs_namespaceObject = require("@aws-sdk/client-sqs");
1667
+ ;// ./src/aws/sqs/delete_message.js
1292
1668
 
1293
- /***/ },
1294
1669
 
1295
- /***/ 8175
1296
- (module) {
1670
+ const deleteMessage = async ( client, queue, receiptHandle ) =>
1671
+ client.send( new client_sqs_namespaceObject.DeleteMessageCommand( {
1672
+ QueueUrl: queue,
1673
+ ReceiptHandle: receiptHandle
1674
+ } ) );
1297
1675
 
1676
+ ;// ./src/aws/sqs/sanitize_sqs.js
1298
1677
  /*
1299
1678
  References:
1300
1679
  - https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html
1301
1680
  - https://stackoverflow.com/questions/58809098/remove-invalid-characters-from-message-sent-to-aws-amazon-sqs
1302
1681
  */
1303
- module.exports = v => v?.replace( /[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/ug, '' ) // eslint-disable-line
1304
-
1682
+ const sanitizeSqs = v => v?.replace( /[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/ug, '' ) // eslint-disable-line
1305
1683
 
1306
- /***/ },
1684
+ ;// ./src/aws/sqs/send_message.js
1307
1685
 
1308
- /***/ 6720
1309
- (module, __unused_webpack_exports, __webpack_require__) {
1310
1686
 
1311
- const { SendMessageCommand } = __webpack_require__( 1976 );
1312
- const sanitizeSqs = __webpack_require__( 8175 );
1313
1687
 
1314
- module.exports = async ( client, queue, body, args ) => {
1315
- const response = await client.send( new SendMessageCommand( {
1688
+ const sendMessage = async ( client, queue, body, args ) => {
1689
+ const response = await client.send( new client_sqs_namespaceObject.SendMessageCommand( {
1316
1690
  ...args,
1317
1691
  MessageBody: sanitizeSqs( typeof body === 'string' ? body : JSON.stringify( body ) ),
1318
1692
  QueueUrl: queue
@@ -1320,20 +1694,15 @@ module.exports = async ( client, queue, body, args ) => {
1320
1694
  return response.MessageId;
1321
1695
  };
1322
1696
 
1697
+ ;// ./src/aws/sqs/send_message_batch.js
1323
1698
 
1324
- /***/ },
1325
1699
 
1326
- /***/ 3131
1327
- (module, __unused_webpack_exports, __webpack_require__) {
1328
1700
 
1329
- const { SendMessageBatchCommand } = __webpack_require__( 1976 );
1330
- const sanitizeSqs = __webpack_require__( 8175 );
1331
-
1332
- module.exports = async ( client, queue, messages ) => {
1701
+ const sendMessageBatch = async ( client, queue, messages ) => {
1333
1702
  if ( messages.length > 10 ) {
1334
1703
  throw new Error( 'SQS.sendMessageBatch only accepts up to 10 messages.' );
1335
1704
  }
1336
- const response = await client.send( new SendMessageBatchCommand( {
1705
+ const response = await client.send( new client_sqs_namespaceObject.SendMessageBatchCommand( {
1337
1706
  QueueUrl: queue,
1338
1707
  Entries: messages.map( ( { body, id = null, nativeArgs }, index ) => ( {
1339
1708
  Id: id ?? `message_${index}`,
@@ -1350,24 +1719,37 @@ module.exports = async ( client, queue, messages ) => {
1350
1719
  return response;
1351
1720
  };
1352
1721
 
1722
+ ;// ./src/aws/sqs/index.js
1723
+
1724
+
1725
+
1726
+
1727
+
1728
+
1729
+
1730
+ const sqs_methods = {
1731
+ deleteMessage: deleteMessage,
1732
+ sendMessage: sendMessage,
1733
+ sendMessageBatch: sendMessageBatch
1734
+ };
1735
+
1736
+ const sqs = createInstance( genericClientProvider.bind( null, client_sqs_namespaceObject.SQSClient ), sqs_methods );
1353
1737
 
1354
- /***/ },
1738
+ ;// external "@aws-sdk/client-ssm"
1739
+ const client_ssm_namespaceObject = require("@aws-sdk/client-ssm");
1740
+ ;// ./src/aws/ssm/get.js
1355
1741
 
1356
- /***/ 8660
1357
- (module, __unused_webpack_exports, __webpack_require__) {
1358
1742
 
1359
- const cacheStorage = __webpack_require__( 4164 );
1360
- const { GetParameterCommand } = __webpack_require__( 4348 );
1361
1743
 
1362
- module.exports = async ( client, name ) => {
1744
+ const get_get = async ( client, name ) => {
1363
1745
  const key = `SSM_${name}`;
1364
- const cacheValue = cacheStorage.get( key );
1746
+ const cacheValue = CacheStorage.get( key );
1365
1747
  if ( cacheValue ) { return cacheValue; }
1366
1748
 
1367
1749
  try {
1368
- const response = await client.send( new GetParameterCommand( { Name: name, WithDecryption: true } ) );
1750
+ const response = await client.send( new client_ssm_namespaceObject.GetParameterCommand( { Name: name, WithDecryption: true } ) );
1369
1751
  const value = response?.Parameter?.Value;
1370
- cacheStorage.set( key, value );
1752
+ CacheStorage.set( key, value );
1371
1753
  return value;
1372
1754
  } catch ( error ) {
1373
1755
  if ( error.constructor.name === 'ParameterNotFound' ) {
@@ -1377,51 +1759,23 @@ module.exports = async ( client, name ) => {
1377
1759
  }
1378
1760
  };
1379
1761
 
1762
+ ;// ./src/aws/ssm/index.js
1380
1763
 
1381
- /***/ },
1382
-
1383
- /***/ 5888
1384
- (module, __unused_webpack_exports, __webpack_require__) {
1385
-
1386
- const get = __webpack_require__( 8660 );
1387
- const { SSMClient } = __webpack_require__( 4348 );
1388
- const clientProvider = __webpack_require__( 9039 );
1389
- const createInstance = __webpack_require__( 5438 );
1390
-
1391
- const methods = { get };
1392
-
1393
- module.exports = createInstance( clientProvider.bind( null, SSMClient ), methods );
1394
-
1395
-
1396
- /***/ },
1397
-
1398
- /***/ 4225
1399
- (module, __unused_webpack_exports, __webpack_require__) {
1400
-
1401
- const query = __webpack_require__( 6030 );
1402
- const { TimestreamQueryClient } = __webpack_require__( 1671 );
1403
- const { Agent } = __webpack_require__( 5692 );
1404
- const clientProvider = __webpack_require__( 9039 );
1405
- const createInstance = __webpack_require__( 5438 );
1406
1764
 
1407
- const methods = { query };
1408
- const defaultArgs = {
1409
- maxRetries: 10,
1410
- httpOptions: { timeout: 60000, agent: new Agent( { maxSockets: 5000 } ) }
1411
- };
1412
1765
 
1413
- module.exports = createInstance( args => clientProvider( TimestreamQueryClient, [ Object.assign( {}, defaultArgs, args ) ] ), methods );
1414
1766
 
1415
1767
 
1416
- /***/ },
1768
+ const ssm_methods = { get: get_get };
1417
1769
 
1418
- /***/ 7261
1419
- (module, __unused_webpack_exports, __webpack_require__) {
1770
+ const ssm = createInstance( genericClientProvider.bind( null, client_ssm_namespaceObject.SSMClient ), ssm_methods );
1420
1771
 
1772
+ ;// external "@aws-sdk/client-timestream-query"
1773
+ const client_timestream_query_namespaceObject = require("@aws-sdk/client-timestream-query");
1774
+ ;// ./src/aws/timestream_query/parse_items.js
1421
1775
  // https://docs.aws.amazon.com/timestream/latest/developerguide/API_query_Type.html
1422
1776
  // https://docs.aws.amazon.com/timestream/latest/developerguide/supported-data-types.html
1423
1777
 
1424
- const { ScalarType } = __webpack_require__( 1671 );
1778
+
1425
1779
 
1426
1780
  const parseBigInt = value => {
1427
1781
  const asInt = parseInt( value, 10 );
@@ -1430,29 +1784,29 @@ const parseBigInt = value => {
1430
1784
 
1431
1785
  const parseScalarValue = ( type, value ) => {
1432
1786
  switch ( type ) {
1433
- case ScalarType.BOOLEAN:
1787
+ case client_timestream_query_namespaceObject.ScalarType.BOOLEAN:
1434
1788
  return value === 'true';
1435
- case ScalarType.DOUBLE:
1789
+ case client_timestream_query_namespaceObject.ScalarType.DOUBLE:
1436
1790
  return parseFloat( value );
1437
- case ScalarType.TIMESTAMP:
1791
+ case client_timestream_query_namespaceObject.ScalarType.TIMESTAMP:
1438
1792
  return new Date( `${value.replace( ' ', 'T' )}Z` );
1439
- case ScalarType.INTEGER:
1793
+ case client_timestream_query_namespaceObject.ScalarType.INTEGER:
1440
1794
  return parseInt( value, 10 );
1441
- case ScalarType.UNKNOWN: // is NULL
1795
+ case client_timestream_query_namespaceObject.ScalarType.UNKNOWN: // is NULL
1442
1796
  return null;
1443
- case ScalarType.BIGINT:
1797
+ case client_timestream_query_namespaceObject.ScalarType.BIGINT:
1444
1798
  return parseBigInt( value );
1445
- case ScalarType.VARCHAR:
1446
- case ScalarType.DATE:
1447
- case ScalarType.TIME:
1448
- case ScalarType.INTERVAL_DAY_TO_SECOND:
1449
- case ScalarType.INTERVAL_YEAR_TO_MONTH:
1799
+ case client_timestream_query_namespaceObject.ScalarType.VARCHAR:
1800
+ case client_timestream_query_namespaceObject.ScalarType.DATE:
1801
+ case client_timestream_query_namespaceObject.ScalarType.TIME:
1802
+ case client_timestream_query_namespaceObject.ScalarType.INTERVAL_DAY_TO_SECOND:
1803
+ case client_timestream_query_namespaceObject.ScalarType.INTERVAL_YEAR_TO_MONTH:
1450
1804
  default:
1451
1805
  return value;
1452
1806
  }
1453
1807
  };
1454
1808
 
1455
- const parseValue = ( typeInfo, datum ) => {
1809
+ const parse_items_parseValue = ( typeInfo, datum ) => {
1456
1810
  // value might be null
1457
1811
  if ( datum['NullValue'] === true ) {
1458
1812
  return null;
@@ -1462,13 +1816,13 @@ const parseValue = ( typeInfo, datum ) => {
1462
1816
  if ( Object.hasOwn( typeInfo, 'TimeSeriesMeasureValueColumnInfo' ) ) {
1463
1817
  return datum.TimeSeriesValue.map( v => ( {
1464
1818
  time: new Date( v.Time ),
1465
- value: parseValue( typeInfo.TimeSeriesMeasureValueColumnInfo.Type, v.Value )
1819
+ value: parse_items_parseValue( typeInfo.TimeSeriesMeasureValueColumnInfo.Type, v.Value )
1466
1820
  } ) );
1467
1821
  }
1468
1822
 
1469
1823
  // maybe an array
1470
1824
  if ( Object.hasOwn( typeInfo, 'ArrayColumnInfo' ) ) {
1471
- return datum.ArrayValue.map( v => parseValue( typeInfo.ArrayColumnInfo.Type, v ) );
1825
+ return datum.ArrayValue.map( v => parse_items_parseValue( typeInfo.ArrayColumnInfo.Type, v ) );
1472
1826
  }
1473
1827
 
1474
1828
  // or even a row
@@ -1476,7 +1830,7 @@ const parseValue = ( typeInfo, datum ) => {
1476
1830
  const rowColumnInfo = typeInfo.RowColumnInfo;
1477
1831
  return datum.RowValue.Data.reduce( ( object, value, index ) => {
1478
1832
  const { Name: name, Type: typeInfo } = rowColumnInfo[index];
1479
- return Object.assign( object, { [name]: parseValue( typeInfo, value ) } );
1833
+ return Object.assign( object, { [name]: parse_items_parseValue( typeInfo, value ) } );
1480
1834
  }, {} );
1481
1835
  }
1482
1836
 
@@ -1484,75 +1838,66 @@ const parseValue = ( typeInfo, datum ) => {
1484
1838
  return parseScalarValue( typeInfo.ScalarType, datum['ScalarValue'] );
1485
1839
  };
1486
1840
 
1487
- module.exports = response => {
1841
+ const parseItems = response => {
1488
1842
  const { ColumnInfo: colInfo, Rows: rows } = response;
1489
1843
  return rows.map( row =>
1490
1844
  row.Data.reduce( ( entry, value, index ) => {
1491
1845
  const { Name: name, Type: typeInfo } = colInfo[index];
1492
- return Object.assign( entry, { [name]: parseValue( typeInfo, value ) } );
1846
+ return Object.assign( entry, { [name]: parse_items_parseValue( typeInfo, value ) } );
1493
1847
  }, { } )
1494
1848
  );
1495
1849
  };
1496
1850
 
1851
+ ;// ./src/aws/timestream_query/query.js
1497
1852
 
1498
- /***/ },
1499
1853
 
1500
- /***/ 6030
1501
- (module, __unused_webpack_exports, __webpack_require__) {
1502
1854
 
1503
- const { QueryCommand } = __webpack_require__( 1671 );
1504
- const { camelize } = __webpack_require__( 5762 );
1505
- const parseItems = __webpack_require__( 7261 );
1506
1855
 
1507
- const query = async ( client, queryString, { prevItems = [], recursive, paginationToken, maxRows, rawResponse } ) => {
1508
- const response = await client.send( new QueryCommand( { QueryString: queryString, NextToken: paginationToken, MaxRows: maxRows } ) );
1856
+ const sendQuery = async ( client, queryString, { prevItems = [], recursive, paginationToken, maxRows, rawResponse } ) => {
1857
+ const response = await client.send( new client_timestream_query_namespaceObject.QueryCommand( { QueryString: queryString, NextToken: paginationToken, MaxRows: maxRows } ) );
1509
1858
  if ( !recursive && rawResponse ) {
1510
1859
  return response;
1511
1860
  }
1512
1861
 
1513
1862
  const nextToken = response.NextToken;
1514
1863
  if ( nextToken && recursive ) {
1515
- return query( client, queryString, { prevItems: parseItems( response ), recursive, paginationToken: nextToken, maxRows } );
1864
+ return sendQuery( client, queryString, { prevItems: parseItems( response ), recursive, paginationToken: nextToken, maxRows } );
1516
1865
  }
1517
1866
 
1518
1867
  const items = prevItems.concat( parseItems( response ) );
1519
- return { nextToken, count: items.length, items, queryStatus: camelize( response.QueryStatus ) };
1868
+ return { nextToken, count: items.length, items, queryStatus: camelize_camelize( response.QueryStatus ) };
1520
1869
  };
1521
1870
 
1522
- module.exports = async ( client, queryString, { recursive = false, paginationToken = undefined, maxRows = undefined, rawResponse = false } = {} ) =>
1523
- query( client, queryString, { recursive, paginationToken, maxRows, rawResponse } );
1871
+ const timestream_query_query_query =
1872
+ async ( client, queryString, { recursive = false, paginationToken = undefined, maxRows = undefined, rawResponse = false } = {} ) =>
1873
+ sendQuery( client, queryString, { recursive, paginationToken, maxRows, rawResponse } );
1524
1874
 
1875
+ ;// external "https"
1876
+ const external_https_namespaceObject = require("https");
1877
+ ;// ./src/aws/timestream_query/index.js
1525
1878
 
1526
- /***/ },
1527
1879
 
1528
- /***/ 2538
1529
- (module, __unused_webpack_exports, __webpack_require__) {
1530
1880
 
1531
- const writeRecords = __webpack_require__( 8936 );
1532
- const { TimestreamWriteClient } = __webpack_require__( 8248 );
1533
- const { Agent } = __webpack_require__( 5692 );
1534
- const clientProvider = __webpack_require__( 9039 );
1535
- const createInstance = __webpack_require__( 5438 );
1536
1881
 
1537
- const methods = { writeRecords };
1882
+
1883
+
1884
+ const timestream_query_methods = { query: timestream_query_query_query };
1538
1885
  const defaultArgs = {
1539
1886
  maxRetries: 10,
1540
- httpOptions: { timeout: 60000, agent: new Agent( { maxSockets: 5000 } ) }
1887
+ httpOptions: { timeout: 60000, agent: new external_https_namespaceObject.Agent( { maxSockets: 5000 } ) }
1541
1888
  };
1542
1889
 
1543
- module.exports = createInstance( args => clientProvider( TimestreamWriteClient, [ Object.assign( {}, defaultArgs, args ) ] ), methods );
1544
-
1545
-
1546
- /***/ },
1890
+ const timestreamQuery =
1891
+ createInstance( args => genericClientProvider( client_timestream_query_namespaceObject.TimestreamQueryClient, [ Object.assign( {}, defaultArgs, args ) ] ), timestream_query_methods );
1547
1892
 
1548
- /***/ 8936
1549
- (module, __unused_webpack_exports, __webpack_require__) {
1893
+ ;// external "@aws-sdk/client-timestream-write"
1894
+ const client_timestream_write_namespaceObject = require("@aws-sdk/client-timestream-write");
1895
+ ;// ./src/aws/timestream_write/write_records.js
1550
1896
 
1551
- const { WriteRecordsCommand } = __webpack_require__( 8248 );
1552
1897
 
1553
- module.exports = async ( client, { database, table, records, ignoreRejections = false } ) => {
1898
+ const writeRecords = async ( client, { database, table, records, ignoreRejections = false } ) => {
1554
1899
  try {
1555
- const response = await client.send( new WriteRecordsCommand( {
1900
+ const response = await client.send( new client_timestream_write_namespaceObject.WriteRecordsCommand( {
1556
1901
  DatabaseName: database,
1557
1902
  TableName: table,
1558
1903
  Records: records
@@ -1561,651 +1906,79 @@ module.exports = async ( client, { database, table, records, ignoreRejections =
1561
1906
  } catch ( error ) {
1562
1907
  if ( ignoreRejections && error.name === 'RejectedRecordsException' ) {
1563
1908
  return { rejectedRecords: error.RejectedRecords };
1564
- }
1565
- throw error;
1566
- }
1567
- };
1568
-
1569
-
1570
- /***/ },
1571
-
1572
- /***/ 5263
1573
- (module) {
1574
-
1575
- module.exports = t => t * 24 * 60 * 60 * 1000;
1576
-
1577
-
1578
- /***/ },
1579
-
1580
- /***/ 6961
1581
- (module) {
1582
-
1583
- module.exports = t => t * 60 * 60 * 1000;
1584
-
1585
-
1586
- /***/ },
1587
-
1588
- /***/ 3830
1589
- (module, __unused_webpack_exports, __webpack_require__) {
1590
-
1591
- const days = __webpack_require__( 5263 );
1592
- const hours = __webpack_require__( 6961 );
1593
- const minutes = __webpack_require__( 6635 );
1594
- const months = __webpack_require__( 8119 );
1595
- const msToS = __webpack_require__( 7416 );
1596
- const round = __webpack_require__( 3990 );
1597
- const seconds = __webpack_require__( 7051 );
1598
-
1599
- module.exports = {
1600
- days,
1601
- hours,
1602
- minutes,
1603
- months,
1604
- msToS,
1605
- round,
1606
- seconds
1607
- };
1608
-
1609
-
1610
- /***/ },
1611
-
1612
- /***/ 6635
1613
- (module) {
1614
-
1615
- module.exports = t => t * 60 * 1000;
1616
-
1617
-
1618
- /***/ },
1619
-
1620
- /***/ 8119
1621
- (module) {
1622
-
1623
- module.exports = t => t * 30 * 24 * 60 * 60 * 1000;
1624
-
1625
-
1626
- /***/ },
1627
-
1628
- /***/ 7416
1629
- (module) {
1630
-
1631
- module.exports = v => Math.ceil( v / 1000 );
1632
-
1633
-
1634
- /***/ },
1635
-
1636
- /***/ 3990
1637
- (module) {
1638
-
1639
- module.exports = ( time, interval ) => time - ( time % interval );
1640
-
1641
-
1642
- /***/ },
1643
-
1644
- /***/ 7051
1645
- (module) {
1646
-
1647
- module.exports = t => t * 1000;
1648
-
1649
-
1650
- /***/ },
1651
-
1652
- /***/ 44
1653
- (module, __unused_webpack_exports, __webpack_require__) {
1654
-
1655
- const { LambdaApi } = __webpack_require__( 2705 );
1656
- const array = __webpack_require__( 8278 );
1657
- const aws = __webpack_require__( 4870 );
1658
- const epoch = __webpack_require__( 3830 );
1659
- const math = __webpack_require__( 943 );
1660
- const object = __webpack_require__( 5762 );
1661
- const redis = __webpack_require__( 4528 );
1662
- const string = __webpack_require__( 268 );
1663
- const utils = __webpack_require__( 6878 );
1664
-
1665
- module.exports = {
1666
- array,
1667
- aws,
1668
- epoch,
1669
- LambdaApi,
1670
- math,
1671
- object,
1672
- redis,
1673
- string,
1674
- utils
1675
- };
1676
-
1677
-
1678
- /***/ },
1679
-
1680
- /***/ 3119
1681
- (module, __unused_webpack_exports, __webpack_require__) {
1682
-
1683
- const { snakelize, camelize } = __webpack_require__( 5762 );
1684
- const charset = 'utf-8';
1685
-
1686
- const transformFns = {
1687
- camelcase: camelize,
1688
- snakecase: snakelize
1689
- };
1690
-
1691
- module.exports = class ApiResponse {
1692
- #headers = null;
1693
- #statusCode = null;
1694
- #transformFn = false;
1695
- #isBase64Encoded = false;
1696
- #body = '';
1697
-
1698
- constructor( { headers = {}, transform } = {} ) {
1699
- this.#transformFn = transformFns[transform] ?? ( v => v );
1700
- this.#headers = Object.assign( {
1701
- 'Cache-Control': 'no-store',
1702
- 'Access-Control-Allow-Origin': '*'
1703
- }, headers );
1704
- }
1705
-
1706
- setContent( statusCode, body, headers = {}, isBase64Encoded = false ) {
1707
- this.#statusCode = statusCode;
1708
- this.#isBase64Encoded = isBase64Encoded;
1709
- if ( body?.length === 0 || [ null, undefined ].includes( body ) ) {
1710
- this.#body = '';
1711
- } else if ( typeof body === 'object' ) {
1712
- this.#body = JSON.stringify( this.#transformFn( body ) );
1713
- this.#headers['Content-Type'] = `application/json; charset=${charset}`;
1714
- } else {
1715
- this.#body = String( body );
1716
- this.#headers['Content-Type'] = `text/plain; charset=${charset}`;
1717
- }
1718
- this.#headers['Content-Length'] = this.#body.length;
1719
- Object.assign( this.#headers, headers ?? {} );
1720
- return this;
1721
- }
1722
-
1723
- toJSON() {
1724
- return {
1725
- isBase64Encoded: this.#isBase64Encoded,
1726
- statusCode: this.#statusCode,
1727
- body: this.#body,
1728
- headers: this.#headers
1729
- };
1730
- }
1731
- };
1732
-
1733
-
1734
- /***/ },
1735
-
1736
- /***/ 329
1737
- (module, __unused_webpack_exports, __webpack_require__) {
1738
-
1739
- const { camelize, snakelize } = __webpack_require__( 5762 );
1740
-
1741
- const transformFns = {
1742
- camelcase: camelize,
1743
- snakecase: snakelize
1744
- };
1745
-
1746
- const parseJson = content => {
1747
- try {
1748
- return JSON.parse( content );
1749
- } catch {
1750
- return content;
1751
- }
1752
- };
1753
-
1754
- module.exports = class Event {
1755
- #transformFn;
1756
- authorizer;
1757
- body;
1758
- rawBody;
1759
- headers;
1760
- method;
1761
- params;
1762
- path;
1763
- queryString;
1764
- route;
1765
-
1766
- context = {};
1767
-
1768
- constructor( { transform = false } = {} ) {
1769
- this.#transformFn = transformFns[transform] ?? ( v => v );
1770
- }
1771
-
1772
- parseFromAwsEvent( awsEvent ) {
1773
- this[`parseFromAwsEventV${awsEvent.version === '2.0' ? 2 : 1}`]( awsEvent );
1774
- }
1775
-
1776
- parseFromAwsEventV1( awsEvent ) {
1777
- const {
1778
- body,
1779
- path,
1780
- resource,
1781
- httpMethod,
1782
- requestContext,
1783
- pathParameters,
1784
- headers,
1785
- multiValueHeaders,
1786
- queryStringParameters,
1787
- multiValueQueryStringParameters: multiValueQueryString,
1788
- isBase64Encoded
1789
- } = awsEvent;
1790
-
1791
- const unifiedHeaders = {
1792
- ...headers,
1793
- ...Object.fromEntries( Object.entries( multiValueHeaders ?? {} ).map( ( [ k, v ] ) => [ k, Array.isArray( v ) ? v.join( ',' ) : k ] ) )
1794
- };
1795
-
1796
- const unifiedQueryString = {
1797
- ...queryStringParameters,
1798
- ...Object.fromEntries( Object.entries( multiValueQueryString ?? {} ).map( ( [ k, v ] ) => [ k, Array.isArray( v ) ? v.join( ',' ) : k ] ) )
1799
- };
1800
-
1801
- this.authorizer = requestContext?.authorizer;
1802
- this.rawBody = body ?? null;
1803
- this.body = body ? this.#transformFn( parseJson( body ) ) : null;
1804
- this.headers = unifiedHeaders ?? {};
1805
- this.method = httpMethod;
1806
- this.params = this.#transformFn( pathParameters ) ?? {};
1807
- this.path = path;
1808
- this.queryString = this.#transformFn( unifiedQueryString ) ?? {};
1809
- this.route = resource;
1810
- this.isBase64Encoded = isBase64Encoded ?? false;
1811
- }
1812
-
1813
- parseFromAwsEventV2( awsEvent ) {
1814
- const {
1815
- body,
1816
- routeKey,
1817
- requestContext,
1818
- pathParameters,
1819
- headers,
1820
- queryStringParameters,
1821
- isBase64Encoded
1822
- } = awsEvent;
1823
-
1824
- const { http: { method, path } } = requestContext;
1825
-
1826
- this.authorizer = requestContext?.authorizer;
1827
- this.rawBody = body ?? null;
1828
- this.body = body ? this.#transformFn( parseJson( body ) ) : null;
1829
- this.headers = headers ?? {};
1830
- this.method = method;
1831
- this.params = this.#transformFn( pathParameters ) ?? {};
1832
- this.path = path;
1833
- this.queryString = this.#transformFn( queryStringParameters ) ?? {};
1834
- this.route = routeKey?.split( ' ' )[1].replace( /\/$/, '' );
1835
- this.isBase64Encoded = isBase64Encoded ?? false;
1836
- }
1837
- };
1838
-
1839
-
1840
- /***/ },
1841
-
1842
- /***/ 3109
1843
- (module, __unused_webpack_exports, __webpack_require__) {
1844
-
1845
- const validators = __webpack_require__( 8994 );
1846
-
1847
- module.exports = class Handler {
1848
- #method;
1849
- #fn;
1850
- #route;
1851
- #routeIncludes;
1852
- #routeNotIncludes;
1853
- #routeMatches;
1854
- #path;
1855
- #pathIncludes;
1856
- #pathNotIncludes;
1857
- #pathMatches;
1858
-
1859
- constructor( { method, fn, ...matchers } ) {
1860
- validators.httpMethod( method );
1861
- validators.function( fn );
1862
- validators.matcherRoute( matchers.route );
1863
- validators.matcherRouteIncludes( matchers.routeIncludes );
1864
- validators.matcherRouteNotIncludes( matchers.routeNotIncludes );
1865
- validators.matcherRouteMatch( matchers.routeMatch );
1866
- validators.matcherPath( matchers.path );
1867
- validators.matcherPathIncludes( matchers.pathIncludes );
1868
- validators.matcherPathNotIncludes( matchers.pathNotIncludes );
1869
- validators.matcherPathMatch( matchers.pathMatch );
1870
-
1871
- this.#method = method;
1872
- this.#fn = fn;
1873
- this.#route = matchers.route;
1874
- this.#routeIncludes = matchers.routeIncludes;
1875
- this.#routeNotIncludes = matchers.routeNotIncludes;
1876
- this.#routeMatches = matchers.routeMatches;
1877
- this.#path = matchers.path;
1878
- this.#pathIncludes = matchers.pathIncludes;
1879
- this.#pathNotIncludes = matchers.pathNotIncludes;
1880
- this.#pathMatches = matchers.pathMatches;
1881
- }
1882
-
1883
- match( event ) {
1884
- if ( this.#method !== event.method ) {
1885
- return false;
1886
- }
1887
- if ( this.#route ) {
1888
- return this.#route === event.route;
1889
- }
1890
- if ( this.#path ) {
1891
- return this.#path === event.path;
1892
- }
1893
- if ( this.#routeIncludes && !event.route.includes( this.#routeIncludes ) ) {
1894
- return false;
1895
- }
1896
- if ( this.#routeNotIncludes && event.route.includes( this.#routeNotIncludes ) ) {
1897
- return false;
1898
- }
1899
- if ( this.#routeMatches && !this.#routeMatches.test( event.route ) ) {
1900
- return false;
1901
- }
1902
- if ( this.#pathIncludes && !event.path.includes( this.#pathIncludes ) ) {
1903
- return false;
1904
- }
1905
- if ( this.#pathNotIncludes && event.path.includes( this.#pathNotIncludes ) ) {
1906
- return false;
1907
- }
1908
- if ( this.#pathMatches && !this.#pathMatches.test( event.path ) ) {
1909
- return false;
1910
- }
1911
- return true;
1912
- }
1913
-
1914
- get fn() { return this.#fn; }
1915
- };
1916
-
1917
-
1918
- /***/ },
1919
-
1920
- /***/ 798
1921
- (module, __unused_webpack_exports, __webpack_require__) {
1922
-
1923
- const validators = __webpack_require__( 8994 );
1924
-
1925
- module.exports = class Hook {
1926
- #fn;
1927
-
1928
- constructor( { fn } ) {
1929
- validators.function( fn );
1930
- this.#fn = fn;
1931
- }
1932
-
1933
- get fn() { return this.#fn; }
1934
- };
1935
-
1936
-
1937
- /***/ },
1938
-
1939
- /***/ 2705
1940
- (module, __unused_webpack_exports, __webpack_require__) {
1941
-
1942
- const LambdaApi = __webpack_require__( 321 );
1943
-
1944
- module.exports = { LambdaApi };
1945
-
1946
-
1947
- /***/ },
1948
-
1949
- /***/ 321
1950
- (module, __unused_webpack_exports, __webpack_require__) {
1951
-
1952
- const validators = __webpack_require__( 8994 );
1953
- const ApiResponse = __webpack_require__( 3119 );
1954
- const Event = __webpack_require__( 329 );
1955
- const Handler = __webpack_require__( 3109 );
1956
- const Hook = __webpack_require__( 798 );
1957
- const UserResponse = __webpack_require__( 8282 );
1958
- const Text = __webpack_require__( 9760 );
1959
-
1960
- module.exports = class LambdaApi {
1961
- #apiResponse = null;
1962
- #handlers = [];
1963
- #errorResponses = [];
1964
- #beforeHooks = [];
1965
- #afterHooks = [];
1966
- #transformRequest = [];
1967
-
1968
- /**
1969
- * Creates a new Lambda Api
1970
- *
1971
- * @param {Object} headers Any headers you want to be included in all responses
1972
- */
1973
- constructor( { headers = {}, transformRequest = false, transformResponse = false } = {} ) {
1974
- validators.transformRequest( transformRequest );
1975
- validators.transformResponse( transformResponse );
1976
-
1977
- this.#transformRequest = transformRequest;
1978
- this.#apiResponse = new ApiResponse( { headers, transform: transformResponse } );
1979
- }
1980
-
1981
- /**
1982
- * Register a function that will run before the matching route (only if matches)
1983
- *
1984
- * @param {Object} args
1985
- * @param {function} args.fn A function
1986
- */
1987
- addBeforeHook( { fn } = {} ) {
1988
- this.#beforeHooks.push( new Hook( { fn } ) );
1989
- }
1990
-
1991
- /**
1992
- * Register a function that will run after the matching route (only if matches)
1993
- *
1994
- * @param {Object} args
1995
- * @param {function} args.fn A function
1996
- */
1997
- addAfterHook( { fn } = {} ) {
1998
- this.#afterHooks.push( new Hook( { fn } ) );
1999
- }
2000
-
2001
- /**
2002
- * Register a handler for a given request method and optionally a path
2003
- *
2004
- * @param {Object} args
2005
- * @param {string} args.method The method to match this handler
2006
- * @param {function} args.fn The handler function
2007
- * @param {string} [args.route] A route to match this handler
2008
- * @param {string} [args.routeIncludes] A part of the route to match this handler
2009
- * @param {string} [args.routeNotIncludes] A part of the route to not match this handler
2010
- * @param {RegExp} [args.routeMatches] A RegExp to match the route
2011
- * @param {string} [args.path] A path to match this handler
2012
- * @param {string} [args.pathIncludes] A part of the path to match this handler
2013
- * @param {string} [args.pathNotIncludes] A part of the path to not match this handler
2014
- * @param {RegExp} [args.pathMatches] A RegExp to match the path
2015
- */
2016
- addHandler( { method, fn, ...matchers } = {} ) {
2017
- this.#handlers.push( new Handler( { method, fn, ...matchers } ) );
2018
- }
2019
-
2020
- /**
2021
- * Register an automatic error code response for given error class (constructor name)
2022
- *
2023
- * @param {Object} args
2024
- * @param {string} args.code The HTTP status code to return
2025
- * @param {class} args.errorType The error class
2026
- * @param {string} [args.message=null] Optional message to return for the status code, if not present will default to Error.message
2027
- * @param {message} [args.errorType] And optional message to display
2028
- */
2029
- addErrorHandler( { errorType, code, message = null } = {} ) {
2030
- validators.statusCode( code );
2031
- validators.errorType( errorType );
2032
- this.#errorResponses.push( { errorType, code, message } );
1909
+ }
1910
+ throw error;
2033
1911
  }
1912
+ };
2034
1913
 
2035
- /**
2036
- * Init the flow using a given AWS Lambda APIGateway event (v2 syntax)
2037
- *
2038
- * @param {Object} ApiGatewayPayload The raw API Gateway event
2039
- * @returns {Object} The http response with status, body and headers
2040
- */
2041
- async process( awsEvent ) {
2042
- const event = new Event( { transform: this.#transformRequest } );
2043
- event.parseFromAwsEvent( awsEvent );
1914
+ ;// ./src/aws/timestream_write/index.js
2044
1915
 
2045
- if ( event.method === 'HEAD' ) {
2046
- return this.#apiResponse.setContent( 204 ).toJSON();
2047
- }
2048
1916
 
2049
- const handler = this.#handlers.find( h => h.match( event ) );
2050
- if ( !handler ) {
2051
- return this.#apiResponse.setContent( 405, Text.ERROR_405 ).toJSON();
2052
- }
2053
1917
 
2054
- const chain = [
2055
- ...this.#beforeHooks.map( b => b.fn ),
2056
- async ev => {
2057
- const result = await handler.fn( ev );
2058
- const response = new UserResponse( result );
2059
- this.#apiResponse.setContent( ...response.values ).toJSON();
2060
- },
2061
- ...this.#afterHooks.map( a => a.fn )
2062
- ];
2063
1918
 
2064
- try {
2065
- for ( const fn of chain ) {
2066
- await fn( event );
2067
- }
2068
- return this.#apiResponse.toJSON();
2069
1919
 
2070
- } catch ( error ) {
2071
- console.error( 'Lambda API Error', { error, event } );
2072
1920
 
2073
- const response = this.#errorResponses.find( e => error instanceof e.errorType );
2074
- if ( response ) {
2075
- return this.#apiResponse.setContent( response.code, response.message ?? error.message ).toJSON();
2076
- }
2077
- return this.#apiResponse.setContent( 500, Text.ERROR_500 ).toJSON();
2078
- }
2079
- }
1921
+ const timestream_write_methods = { writeRecords: writeRecords };
1922
+ const timestream_write_defaultArgs = {
1923
+ maxRetries: 10,
1924
+ httpOptions: { timeout: 60000, agent: new external_https_namespaceObject.Agent( { maxSockets: 5000 } ) }
2080
1925
  };
2081
1926
 
1927
+ const timestreamWrite =
1928
+ createInstance( args => genericClientProvider( client_timestream_write_namespaceObject.TimestreamWriteClient, [ Object.assign( {}, timestream_write_defaultArgs, args ) ] ), timestream_write_methods );
2082
1929
 
2083
- /***/ },
1930
+ ;// ./src/aws/index.js
2084
1931
 
2085
- /***/ 3446
2086
- (module) {
2087
1932
 
2088
- module.exports = class LambdaApiValidationError extends Error {};
2089
1933
 
2090
1934
 
2091
- /***/ },
2092
1935
 
2093
- /***/ 9760
2094
- (module) {
2095
1936
 
2096
- module.exports = {
2097
- ERROR_500: 'Internal Server Error',
2098
- ERROR_405: 'Method Not Allowed',
2099
- INVALID_ERROR_TYPE: 'Argument "errorType" must be a constructor Function',
2100
- INVALID_FN: 'Argument "fn" must be of type function',
2101
- INVALID_METHOD: 'Argument "method" must be one of the default HTTP methods',
2102
- INVALID_STATUS_CODE: 'Argument "statusCode" must be valid HTTP Status Code',
2103
- INVALID_TRANSFORM_REQUEST: 'Argument "transformRequest" must be either "camelize", "snakelize", false or null',
2104
- INVALID_TRANSFORM_RESPONSE: 'Argument "transformResponse" must be either "camelize", "snakelize", false or null',
2105
- INVALID_MATCHER_ROUTE: 'Argument "route" must be either undefined or an string with length greater than 0',
2106
- INVALID_MATCHER_ROUTE_INCLUDES: 'Argument "routeIncludes" must be either undefined or an string with length greater than 0',
2107
- INVALID_MATCHER_ROUTE_NOT_INCLUDES: 'Argument "routeNotIncludes" must be either undefined or an string with length greater than 0',
2108
- INVALID_MATCHER_ROUTE_MATCH: 'Argument "routeMatch" must be either undefined or type RegExp',
2109
- INVALID_MATCHER_PATH: 'Argument "path" must be either undefined or an string with length greater than 0',
2110
- INVALID_MATCHER_PATH_INCLUDES: 'Argument "pathIncludes" must be either undefined or an string with length greater than 0',
2111
- INVALID_MATCHER_PATH_NOT_INCLUDES: 'Argument "pathNotIncludes" must be either undefined or an string with length greater than 0',
2112
- INVALID_MATCHER_PATH_MATCH: 'Argument "pathMatch" must be either undefined or type RegExp',
2113
- INVALID_USER_RESPONSE: 'Function return must be a number, a string, an array (where p=0 is a number) or an object (where .statusCode is a number)'
2114
- };
2115
1937
 
2116
1938
 
2117
- /***/ },
2118
1939
 
2119
- /***/ 8282
2120
- (module, __unused_webpack_exports, __webpack_require__) {
2121
1940
 
2122
- const validators = __webpack_require__( 8994 );
2123
- const LambdaApiValidationError = __webpack_require__( 3446 );
2124
- const Text = __webpack_require__( 9760 );
2125
1941
 
2126
- module.exports = class UserResponse {
2127
- constructor( args ) {
2128
- if ( args === undefined ) {
2129
- this.values = [ 204 ];
2130
- } else if ( typeof args === 'string' && args.length === 0 ) {
2131
- this.values = [ 204 ];
2132
1942
 
2133
- } else if ( typeof args === 'string' && args.length > 0 ) {
2134
- this.values = [ 200, args ];
2135
1943
 
2136
- } else if ( typeof args === 'number' ) {
2137
- validators.statusCode( args );
2138
- this.values = [ args ];
2139
1944
 
2140
- } else if ( Array.isArray( args ) ) {
2141
- validators.statusCode( args[0] );
2142
- this.values = args;
1945
+ ;// ./src/epoch/days.js
1946
+ const days = t => t * 24 * 60 * 60 * 1000;
2143
1947
 
2144
- } else if ( args.statusCode ) {
2145
- validators.statusCode( args.statusCode );
2146
- this.values = [ args.statusCode, args.body, args.headers, args.isBase64Encoded ];
1948
+ ;// ./src/epoch/hours.js
1949
+ const hours = t => t * 60 * 60 * 1000;
2147
1950
 
2148
- } else if ( [ undefined, null ].includes( args ) ) {
2149
- this.values = [ 200 ];
2150
- } else {
2151
- throw new LambdaApiValidationError( Text.INVALID_USER_RESPONSE );
2152
- }
2153
- }
2154
- };
1951
+ ;// ./src/epoch/minutes.js
1952
+ const minutes = t => t * 60 * 1000;
2155
1953
 
1954
+ ;// ./src/epoch/months.js
1955
+ const months = t => t * 30 * 24 * 60 * 60 * 1000;
2156
1956
 
2157
- /***/ },
1957
+ ;// ./src/epoch/ms_to_s.js
1958
+ const msToS = v => Math.ceil( v / 1000 );
2158
1959
 
2159
- /***/ 8994
2160
- (module, __unused_webpack_exports, __webpack_require__) {
1960
+ ;// ./src/epoch/round.js
1961
+ const round = ( time, interval ) => time - ( time % interval );
2161
1962
 
2162
- const Text = __webpack_require__( 9760 );
2163
- const LambdaApiValidationError = __webpack_require__( 3446 );
1963
+ ;// ./src/epoch/seconds.js
1964
+ const seconds = t => t * 1000;
2164
1965
 
2165
- const evaluate = ( condition, errorMessage ) => {
2166
- if ( !condition ) { throw new LambdaApiValidationError( errorMessage ); }
2167
- };
1966
+ ;// ./src/epoch/index.js
2168
1967
 
2169
- const isConstructor = v => {
2170
- try {
2171
- return !!Reflect.construct( new Proxy( v, {} ), [] );
2172
- } catch {
2173
- return false;
2174
- }
2175
- };
2176
1968
 
2177
- module.exports = {
2178
- errorType: v => evaluate( isConstructor( v ), Text.INVALID_ERROR_TYPE ),
2179
- function: v => evaluate( typeof v === 'function', Text.INVALID_FN ),
2180
- httpMethod: v => evaluate( [ 'DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT' ].includes( v ), Text.INVALID_METHOD ),
2181
- matcherPath: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_PATH ),
2182
- matcherPathIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_PATH_INCLUDES ),
2183
- matcherPathMatch: v => evaluate( v === undefined || v?.constructor?.name === RegExp.name, Text.INVALID_MATCHER_PATH_MATCH ),
2184
- matcherPathNotIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_PATH_NOT_INCLUDES ),
2185
- matcherRoute: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_ROUTE ),
2186
- matcherRouteIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_ROUTE_INCLUDES ),
2187
- matcherRouteMatch: v => evaluate( v === undefined || v?.constructor?.name === RegExp.name, Text.INVALID_MATCHER_ROUTE_MATCH ),
2188
- matcherRouteNotIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_ROUTE_NOT_INCLUDES ),
2189
- statusCode: v => evaluate( typeof v === 'number' && /^[1-5]\d\d$/.test( String( v ) ), Text.INVALID_STATUS_CODE ),
2190
- transformRequest: v => evaluate( [ 'camelcase', 'snakecase', null, false ].includes( v ), Text.INVALID_TRANSFORM_REQUEST ),
2191
- transformResponse: v => evaluate( [ 'camelcase', 'snakecase', null, false ].includes( v ), Text.INVALID_TRANSFORM_RESPONSE )
2192
- };
2193
1969
 
2194
1970
 
2195
- /***/ },
2196
1971
 
2197
- /***/ 4124
2198
- (module) {
2199
1972
 
2200
- module.exports = values => values.reduce( ( sum, value ) => sum + value, 0 ) / values.length;
2201
1973
 
2202
1974
 
2203
- /***/ },
2204
1975
 
2205
- /***/ 3187
2206
- (module) {
2207
1976
 
2208
- module.exports = values => {
1977
+ ;// ./src/math/calc_mean.js
1978
+ const calcMean = values => values.reduce( ( sum, value ) => sum + value, 0 ) / values.length;
1979
+
1980
+ ;// ./src/math/calc_median.js
1981
+ const calcMedian = values => {
2209
1982
  //Sort bug: https://www.tutorialrepublic.com/faq/how-to-sort-an-array-of-integers-correctly-in-javascript.php
2210
1983
  const sorted = values.slice().sort( ( a, b ) => a - b );
2211
1984
  const evenArray = values.length % 2 === 0;
@@ -2213,43 +1986,28 @@ module.exports = values => {
2213
1986
  return evenArray ? ( sorted[midIndex - 1] + sorted[midIndex] ) / 2 : sorted[midIndex];
2214
1987
  };
2215
1988
 
1989
+ ;// ./src/math/calc_median_abs_dev.js
2216
1990
 
2217
- /***/ },
2218
-
2219
- /***/ 4692
2220
- (module, __unused_webpack_exports, __webpack_require__) {
2221
1991
 
2222
- const calcMedian = __webpack_require__( 3187 );
2223
-
2224
- module.exports = pop => {
1992
+ const calcMedianAbsDev = pop => {
2225
1993
  const center = calcMedian( pop );
2226
1994
  return calcMedian( pop.map( v => Math.abs( v - center ) ) );
2227
1995
  };
2228
1996
 
1997
+ ;// ./src/math/calc_std_dev_population.js
2229
1998
 
2230
- /***/ },
2231
-
2232
- /***/ 2736
2233
- (module, __unused_webpack_exports, __webpack_require__) {
2234
1999
 
2235
- const calcMean = __webpack_require__( 4124 );
2236
-
2237
- module.exports = values => {
2000
+ const calcStdDevPopulation = values => {
2238
2001
  const mean = calcMean( values );
2239
2002
  const squareDiffs = values.map( value => Math.pow( value - mean, 2 ) );
2240
2003
  const avgSquareDiff = calcMean( squareDiffs );
2241
2004
  return Math.sqrt( avgSquareDiff );
2242
2005
  };
2243
2006
 
2007
+ ;// ./src/math/calc_std_dev_sample.js
2244
2008
 
2245
- /***/ },
2246
-
2247
- /***/ 6089
2248
- (module, __unused_webpack_exports, __webpack_require__) {
2249
2009
 
2250
- const calcMean = __webpack_require__( 4124 );
2251
-
2252
- module.exports = values => {
2010
+ const calcStdDevSample = values => {
2253
2011
  if ( values.length < 2 ) { return NaN; }
2254
2012
 
2255
2013
  const mean = calcMean( values );
@@ -2258,47 +2016,11 @@ module.exports = values => {
2258
2016
  return Math.sqrt( avgSquareDiff );
2259
2017
  };
2260
2018
 
2019
+ ;// ./src/math/calc_z_score.js
2020
+ const calcZScore = ( sample, mean, stdDev ) => stdDev === 0 ? NaN : ( sample - mean ) / stdDev;
2261
2021
 
2262
- /***/ },
2263
-
2264
- /***/ 4110
2265
- (module) {
2266
-
2267
- module.exports = ( sample, mean, stdDev ) => stdDev === 0 ? NaN : ( sample - mean ) / stdDev;
2268
-
2269
-
2270
- /***/ },
2271
-
2272
- /***/ 943
2273
- (module, __unused_webpack_exports, __webpack_require__) {
2274
-
2275
- const calcMean = __webpack_require__( 4124 );
2276
- const calcMedian = __webpack_require__( 3187 );
2277
- const calcMedianAbsDev = __webpack_require__( 4692 );
2278
- const calcStdDevPopulation = __webpack_require__( 2736 );
2279
- const calcStdDevSample = __webpack_require__( 6089 );
2280
- const calcZScore = __webpack_require__( 4110 );
2281
- const roundGaussian = __webpack_require__( 637 );
2282
- const roundStandard = __webpack_require__( 115 );
2283
-
2284
- module.exports = {
2285
- calcMean,
2286
- calcMedian,
2287
- calcMedianAbsDev,
2288
- calcStdDevPopulation,
2289
- calcStdDevSample,
2290
- calcZScore,
2291
- roundGaussian,
2292
- roundStandard
2293
- };
2294
-
2295
-
2296
- /***/ },
2297
-
2298
- /***/ 637
2299
- (module) {
2300
-
2301
- module.exports = ( n, d = 2 ) => {
2022
+ ;// ./src/math/round_gaussian.js
2023
+ const roundGaussian = ( n, d = 2 ) => {
2302
2024
  if ( !isFinite( n ) || typeof n !== 'number' ) { return NaN; }
2303
2025
 
2304
2026
  const m = Math.pow( 10, d );
@@ -2311,113 +2033,49 @@ module.exports = ( n, d = 2 ) => {
2311
2033
  return r / m;
2312
2034
  };
2313
2035
 
2036
+ ;// ./src/math/round_standard.js
2037
+ const roundStandard = ( n, d = 2 ) => Math.round( n * ( 10 ** d ) ) / ( 10 ** d );
2314
2038
 
2315
- /***/ },
2316
-
2317
- /***/ 115
2318
- (module) {
2319
-
2320
- module.exports = ( n, d = 2 ) => Math.round( n * ( 10 ** d ) ) / ( 10 ** d );
2321
-
2039
+ ;// ./src/math/index.js
2322
2040
 
2323
- /***/ },
2324
2041
 
2325
- /***/ 8256
2326
- (module, __unused_webpack_exports, __webpack_require__) {
2327
2042
 
2328
- const isSerializable = __webpack_require__( 8864 );
2329
- const camelize = __webpack_require__( 3914 );
2330
-
2331
- const change = ( obj, keepAllCaps ) =>
2332
- !isSerializable( obj ) ? obj : Object.entries( obj ).reduce( ( transformed, [ key, value ] ) => {
2333
- delete transformed[key];
2334
- transformed[camelize( key, { keepAllCaps } )] = typeof value === 'object' ? change( value, keepAllCaps ) : value;
2335
- return transformed;
2336
- }, Array.isArray( obj ) ? [] : {} );
2337
-
2338
- module.exports = ( obj, { keepAllCaps = false } = {} ) => change( obj, keepAllCaps );
2339
-
2340
-
2341
- /***/ },
2342
-
2343
- /***/ 6451
2344
- (module) {
2345
-
2346
- module.exports = ( obj, props ) => Object.fromEntries( Object.entries( obj ).filter( ( [ k ] ) => props.includes( k ) ) );
2347
-
2348
-
2349
- /***/ },
2350
-
2351
- /***/ 5762
2352
- (module, __unused_webpack_exports, __webpack_require__) {
2353
-
2354
- const camelize = __webpack_require__( 8256 );
2355
- const filterProps = __webpack_require__( 6451 );
2356
- const removeEmptyArrays = __webpack_require__( 2047 );
2357
- const snakelize = __webpack_require__( 7572 );
2358
-
2359
- module.exports = {
2360
- camelize,
2361
- filterProps,
2362
- removeEmptyArrays,
2363
- snakelize
2364
- };
2365
2043
 
2366
2044
 
2367
- /***/ },
2368
2045
 
2369
- /***/ 8864
2370
- (module) {
2371
-
2372
- module.exports = obj =>
2373
- typeof obj === 'object' &&
2374
- obj !== null &&
2375
- !( obj instanceof String ) &&
2376
- !( obj instanceof Number ) &&
2377
- !( obj instanceof Boolean ) &&
2378
- !( obj instanceof Date );
2379
2046
 
2380
2047
 
2381
- /***/ },
2382
2048
 
2383
- /***/ 2047
2384
- (module) {
2385
2049
 
2386
- module.exports = o => Object.fromEntries( Object.entries( o ).filter( ( [ , v ] ) => !Array.isArray( v ) || v.length > 0 ) );
2387
2050
 
2051
+ ;// ./src/object/filter_props.js
2052
+ const filterProps = ( obj, props ) => Object.fromEntries( Object.entries( obj ).filter( ( [ k ] ) => props.includes( k ) ) );
2388
2053
 
2389
- /***/ },
2054
+ ;// ./src/object/remove_empty_arrays.js
2055
+ const removeEmptyArrays = o => Object.fromEntries( Object.entries( o ).filter( ( [ , v ] ) => !Array.isArray( v ) || v.length > 0 ) );
2390
2056
 
2391
- /***/ 7572
2392
- (module, __unused_webpack_exports, __webpack_require__) {
2057
+ ;// ./src/object/index.js
2393
2058
 
2394
- const isSerializable = __webpack_require__( 8864 );
2395
- const snakelize = __webpack_require__( 3402 );
2396
2059
 
2397
- const change = ( obj, keepAllCaps ) =>
2398
- !isSerializable( obj ) ? obj : Object.entries( obj ).reduce( ( transformed, [ key, value ] ) => {
2399
- delete transformed[key];
2400
- transformed[snakelize( key, { keepAllCaps } )] = typeof value === 'object' ? change( value, keepAllCaps ) : value;
2401
- return transformed;
2402
- }, Array.isArray( obj ) ? [] : {} );
2403
2060
 
2404
- module.exports = ( obj, { keepAllCaps = false } = {} ) => change( obj, keepAllCaps );
2405
2061
 
2406
2062
 
2407
- /***/ },
2408
2063
 
2409
- /***/ 5422
2410
- (module) {
2411
2064
 
2065
+ ;// ./src/redis/create_client.js
2412
2066
  global.__redisInstances = {};
2413
2067
 
2414
2068
  /**
2415
2069
  * Create a redis client instance
2416
- * @param {Object} redis Redis npm dependency
2417
- * @param {String} address Redis DB address (either RW or RO)
2070
+ *
2071
+ * @param {Object} args
2072
+ * @param {Object} args.redis Redis npm dependency
2073
+ * @param {String} args.address Redis DB address (either RW or RO)
2074
+ * @param {String} [args.protocol=rediss] Redis connection protocol
2075
+ * @param {String} [args.port=6379] Redis DB connection port
2418
2076
  * @returns redisClient A new redis client instance connected to the database
2419
2077
  */
2420
- module.exports = async ( { redis, address, protocol = 'rediss', port = 6379 } ) => {
2078
+ const createClient = async ( { redis, address, protocol = 'rediss', port = 6379 } ) => {
2421
2079
  if ( global.__redisInstances[address] ) {
2422
2080
  try {
2423
2081
  const r = await global.__redisInstances[address].ping();
@@ -2439,47 +2097,13 @@ module.exports = async ( { redis, address, protocol = 'rediss', port = 6379 } )
2439
2097
  return client;
2440
2098
  };
2441
2099
 
2442
-
2443
- /***/ },
2444
-
2445
- /***/ 4528
2446
- (module, __unused_webpack_exports, __webpack_require__) {
2447
-
2448
- const createClient = __webpack_require__( 5422 );
2449
-
2450
- module.exports = {
2451
- createClient
2452
- };
2453
-
2454
-
2455
- /***/ },
2456
-
2457
- /***/ 3914
2458
- (module) {
2459
-
2460
- // Convert a string to camelCase
2461
- module.exports = ( input, { keepAllCaps = false } = {} ) =>
2462
- // Break the string into sequences to rebuild later
2463
- !input ? input : input.split( /\s/ )
2464
- // ALL_CAPS terms are ignored
2465
- .map( term => [ term, keepAllCaps && /^[A-Z_]+$/g.test( term ) ? term : term
2466
- // Matches the penultimate letter in a sequence of upper case followed by lower case and convert it to lower case
2467
- // Effectively creating a word break eg: BDay => bDay
2468
- .replace( /[A-Z](?=[A-Z][a-z])/g, c => `${c[0].toLowerCase()}` )
2469
- .replace( /([A-Z])([A-Z]+)/g, c => `${c[0]}${c.slice( 1 ).toLowerCase()}` ) // Sequences of upper case
2470
- .replace( /([-_]\w)/g, c => c[1].toUpperCase() ) // first letter after hyphen and underline
2471
- .replace( /^([A-Z])/g, c => c[0].toLowerCase() ) // first letter
2472
- ] )
2473
- // Rebuild the string replacing the converter terms keeping the original delimiters
2474
- .reduce( ( result, [ term, repl ] ) => result.replace( term, repl ), input );
2100
+ ;// ./src/redis/index.js
2475
2101
 
2476
2102
 
2477
- /***/ },
2478
2103
 
2479
- /***/ 3258
2480
- (module) {
2481
2104
 
2482
- module.exports = input =>
2105
+ ;// ./src/string/capitalize_words.js
2106
+ const capitalizeWords = input =>
2483
2107
  // Break the string into sequences to rebuild later
2484
2108
  !input ? input : input.split( /\s/ )
2485
2109
  // ALL_CAPS terms are ignored
@@ -2487,66 +2111,15 @@ module.exports = input =>
2487
2111
  // Rebuild the string replacing the converter terms keeping the original delimiters
2488
2112
  .reduce( ( result, [ term, repl ] ) => result.replace( term, repl ), input );
2489
2113
 
2114
+ ;// ./src/string/index.js
2490
2115
 
2491
- /***/ },
2492
-
2493
- /***/ 268
2494
- (module, __unused_webpack_exports, __webpack_require__) {
2495
-
2496
- const camelize = __webpack_require__( 3914 );
2497
- const capitalizeWords = __webpack_require__( 3258 );
2498
- const snakelize = __webpack_require__( 3402 );
2499
-
2500
- module.exports = {
2501
- camelize,
2502
- capitalizeWords,
2503
- snakelize
2504
- };
2505
-
2506
-
2507
- /***/ },
2508
-
2509
- /***/ 3402
2510
- (module) {
2511
-
2512
- // convert a string to snake_case
2513
- module.exports = ( input, { keepAllCaps = false } = {} ) =>
2514
- // Break the string into sequences to rebuild later
2515
- !input ? input : input.split( /\s/ )
2516
- // ALL_CAPS terms are ignored
2517
- .map( term => [ term, keepAllCaps && /^[A-Z_]+$/g.test( term ) ? term : term
2518
- .replace( /-/g, '_' ) // replaces hyphen
2519
- .replace( /([a-z\d])([A-Z])/g, '$1_$2' ) // add _ between lower and upper case letters
2520
- .replace( /([A-Z])([A-Z])(?=[a-z\d])/g, '$1_$2' ).toLowerCase() // add _ between uppercase char and next uppercase char follow by lowercase
2521
- ] )
2522
- // Rebuild the string replacing the converter terms keeping the original delimiters
2523
- .reduce( ( result, [ term, repl ] ) => result.replace( term, repl ), input );
2524
-
2525
-
2526
- /***/ },
2527
-
2528
- /***/ 6878
2529
- (module, __unused_webpack_exports, __webpack_require__) {
2530
2116
 
2531
- const retryOnError = __webpack_require__( 4243 );
2532
- const sleep = __webpack_require__( 2445 );
2533
- const Timer = __webpack_require__( 9651 );
2534
- const untarJsonGz = __webpack_require__( 8233 );
2535
2117
 
2536
- module.exports = {
2537
- retryOnError,
2538
- sleep,
2539
- Timer,
2540
- untarJsonGz
2541
- };
2542
2118
 
2543
2119
 
2544
- /***/ },
2545
2120
 
2546
- /***/ 4243
2547
- (module, __unused_webpack_exports, __webpack_require__) {
2121
+ ;// ./src/utils/retry_on_error.js
2548
2122
 
2549
- const sleep = __webpack_require__( 2445 );
2550
2123
 
2551
2124
  const execWithRetry = async ( closure, { limit, delay, retryHook, execCount = 0 } ) => {
2552
2125
  if ( !( closure instanceof Function ) ) {
@@ -2574,7 +2147,7 @@ const execWithRetry = async ( closure, { limit, delay, retryHook, execCount = 0
2574
2147
 
2575
2148
  // if there is no hook back-off and retry
2576
2149
  if ( delay > 0 ) {
2577
- await sleep( delay ** ( 1 + execCount ) );
2150
+ await sleep_sleep( delay ** ( 1 + execCount ) );
2578
2151
  }
2579
2152
  return execWithRetry( closure, { limit, delay, retryHook, execCount: execCount + 1 } );
2580
2153
  }
@@ -2584,31 +2157,19 @@ const execWithRetry = async ( closure, { limit, delay, retryHook, execCount = 0
2584
2157
  *
2585
2158
  * @param {Function} closure A self contained function that will be invoked
2586
2159
  * @param {Object} config
2587
- * @param {Number} limit The max number of retries
2588
- * @param {Number} delay The delay between each retry (it will be multiplied by the number of retries, so, it is linear back-off)
2589
- * @param {Function} retryHook A function to be called every-time a retry is needed.
2590
- * If this functions returns false, the retry error is raised
2591
- * If this functions throws error, the thrown error is raised
2160
+ * @param {Number} config.limit The max number of retries
2161
+ * @param {Number} config.delay The delay between each retry (it will be raised to the power of the number of retries, so it is exponential back-off)
2162
+ * @param {Function} config.retryHook A function to be called every time a retry is needed.
2163
+ * If this functions returns true, the retry flow continues until limit
2164
+ * If this functions returns false, the retry flow is aborted, returning false
2165
+ * If this functions throws an error, the retry flow is aborted with that error
2592
2166
  * @returns {Any} The closure result
2593
2167
  */
2594
- module.exports = async ( closure, { limit = 0, delay = 0, retryHook = null } = {} ) =>
2168
+ const retryOnError = async ( closure, { limit = 0, delay = 0, retryHook = null } = {} ) =>
2595
2169
  execWithRetry( closure, { limit, delay, retryHook } );
2596
2170
 
2597
-
2598
- /***/ },
2599
-
2600
- /***/ 2445
2601
- (module) {
2602
-
2603
- module.exports = t => new Promise( r => setTimeout( r, t ) );
2604
-
2605
-
2606
- /***/ },
2607
-
2608
- /***/ 9651
2609
- (module) {
2610
-
2611
- module.exports = class Timer {
2171
+ ;// ./src/utils/timer.js
2172
+ class Timer {
2612
2173
  #startedAt;
2613
2174
  #stoppedAt = null;
2614
2175
  #running = false;
@@ -2650,13 +2211,10 @@ module.exports = class Timer {
2650
2211
  }
2651
2212
  };
2652
2213
 
2214
+ ;// external "node:zlib"
2215
+ const external_node_zlib_namespaceObject = require("node:zlib");
2216
+ ;// ./src/utils/untar_json_gz.js
2653
2217
 
2654
- /***/ },
2655
-
2656
- /***/ 8233
2657
- (module, __unused_webpack_exports, __webpack_require__) {
2658
-
2659
- const { unzipSync } = __webpack_require__( 3106 );
2660
2218
 
2661
2219
  const firstIndexOf = ( c, ...vars ) => Math.min( ...vars.map( v => c.indexOf( v ) ).filter( n => n > -1 ) );
2662
2220
  const lastIndexOf = ( c, ...vars ) => Math.max( ...vars.map( v => c.lastIndexOf( v ) ) );
@@ -2673,8 +2231,8 @@ const lastIndexOf = ( c, ...vars ) => Math.max( ...vars.map( v => c.lastIndexOf(
2673
2231
  *
2674
2232
  * Enjoy this 100% native tarball decompression!
2675
2233
  */
2676
- module.exports = raw =>
2677
- unzipSync( raw )
2234
+ const untarJsonGz = raw =>
2235
+ (0,external_node_zlib_namespaceObject.unzipSync)( raw )
2678
2236
  .toString( 'utf-8' )
2679
2237
  .split( '\0ustar' )
2680
2238
  .slice( 1 )
@@ -2682,170 +2240,25 @@ module.exports = raw =>
2682
2240
  JSON.parse( c.substring( firstIndexOf( c, '{', '[' ), lastIndexOf( c, '}', ']' ) + 1 ) )
2683
2241
  );
2684
2242
 
2243
+ ;// ./src/utils/index.js
2685
2244
 
2686
- /***/ },
2687
-
2688
- /***/ 3744
2689
- (module) {
2690
-
2691
- "use strict";
2692
- module.exports = require("@aws-sdk/client-athena");
2693
-
2694
- /***/ },
2695
-
2696
- /***/ 7493
2697
- (module) {
2698
-
2699
- "use strict";
2700
- module.exports = require("@aws-sdk/client-cloudwatch-logs");
2701
-
2702
- /***/ },
2703
-
2704
- /***/ 4671
2705
- (module) {
2706
-
2707
- "use strict";
2708
- module.exports = require("@aws-sdk/client-dynamodb");
2709
-
2710
- /***/ },
2711
-
2712
- /***/ 5892
2713
- (module) {
2714
2245
 
2715
- "use strict";
2716
- module.exports = require("@aws-sdk/client-lambda");
2717
2246
 
2718
- /***/ },
2719
2247
 
2720
- /***/ 5725
2721
- (module) {
2722
2248
 
2723
- "use strict";
2724
- module.exports = require("@aws-sdk/client-s3");
2725
2249
 
2726
- /***/ },
2727
2250
 
2728
- /***/ 9556
2729
- (module) {
2251
+ ;// ./src/index.mjs
2730
2252
 
2731
- "use strict";
2732
- module.exports = require("@aws-sdk/client-sesv2");
2733
2253
 
2734
- /***/ },
2735
2254
 
2736
- /***/ 7651
2737
- (module) {
2738
2255
 
2739
- "use strict";
2740
- module.exports = require("@aws-sdk/client-sns");
2741
2256
 
2742
- /***/ },
2743
2257
 
2744
- /***/ 1976
2745
- (module) {
2746
2258
 
2747
- "use strict";
2748
- module.exports = require("@aws-sdk/client-sqs");
2749
2259
 
2750
- /***/ },
2751
2260
 
2752
- /***/ 4348
2753
- (module) {
2754
2261
 
2755
- "use strict";
2756
- module.exports = require("@aws-sdk/client-ssm");
2757
-
2758
- /***/ },
2759
-
2760
- /***/ 1671
2761
- (module) {
2762
-
2763
- "use strict";
2764
- module.exports = require("@aws-sdk/client-timestream-query");
2765
-
2766
- /***/ },
2767
-
2768
- /***/ 8248
2769
- (module) {
2770
-
2771
- "use strict";
2772
- module.exports = require("@aws-sdk/client-timestream-write");
2773
-
2774
- /***/ },
2775
-
2776
- /***/ 3489
2777
- (module) {
2778
-
2779
- "use strict";
2780
- module.exports = require("@aws-sdk/lib-dynamodb");
2781
-
2782
- /***/ },
2783
-
2784
- /***/ 4991
2785
- (module) {
2786
-
2787
- "use strict";
2788
- module.exports = require("@aws-sdk/s3-request-presigner");
2789
-
2790
- /***/ },
2791
-
2792
- /***/ 6982
2793
- (module) {
2794
-
2795
- "use strict";
2796
- module.exports = require("crypto");
2797
-
2798
- /***/ },
2799
-
2800
- /***/ 5692
2801
- (module) {
2802
-
2803
- "use strict";
2804
- module.exports = require("https");
2805
-
2806
- /***/ },
2807
-
2808
- /***/ 3106
2809
- (module) {
2810
-
2811
- "use strict";
2812
- module.exports = require("zlib");
2813
-
2814
- /***/ }
2815
-
2816
- /******/ });
2817
- /************************************************************************/
2818
- /******/ // The module cache
2819
- /******/ var __webpack_module_cache__ = {};
2820
- /******/
2821
- /******/ // The require function
2822
- /******/ function __webpack_require__(moduleId) {
2823
- /******/ // Check if module is in cache
2824
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
2825
- /******/ if (cachedModule !== undefined) {
2826
- /******/ return cachedModule.exports;
2827
- /******/ }
2828
- /******/ // Create a new module (and put it into the cache)
2829
- /******/ var module = __webpack_module_cache__[moduleId] = {
2830
- /******/ // no module.id needed
2831
- /******/ // no module.loaded needed
2832
- /******/ exports: {}
2833
- /******/ };
2834
- /******/
2835
- /******/ // Execute the module function
2836
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
2837
- /******/
2838
- /******/ // Return the exports of the module
2839
- /******/ return module.exports;
2840
- /******/ }
2841
- /******/
2842
- /************************************************************************/
2843
- /******/
2844
- /******/ // startup
2845
- /******/ // Load entry module and return exports
2846
- /******/ // This entry module is referenced by other modules so it can't be inlined
2847
- /******/ var __webpack_exports__ = __webpack_require__(44);
2848
- /******/ module.exports = __webpack_exports__;
2849
- /******/
2262
+ module.exports = __webpack_exports__;
2850
2263
  /******/ })()
2851
2264
  ;