lambda-toolkit 0.0.13-beta → 0.0.14-beta

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.
Files changed (2) hide show
  1. package/dist/index.js +210 -21
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -473,6 +473,37 @@ const methods = {
473
473
  module.exports = createInstance( clientProvider.bind( null, S3Client ), methods );
474
474
 
475
475
 
476
+ /***/ }),
477
+
478
+ /***/ 739:
479
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
480
+
481
+ const { GetQueryResultsCommand } = __webpack_require__( 7493 );
482
+ const pollingDelay = __webpack_require__( 2549 );
483
+ const sleep = t => new Promise( r => setTimeout( () => r(), t ) );
484
+
485
+ const getResults = async ( { client, command } ) => {
486
+ const { results, status } = await client.send( command );
487
+
488
+ if ( [ 'Cancelled', 'Failed', 'Timeout', 'Unknown' ].includes( status ) ) {
489
+ throw new Error( `Query status is "${status}"` );
490
+ }
491
+
492
+ if ( status === 'Complete' ) {
493
+ return results;
494
+ }
495
+
496
+ // Running, Scheduled
497
+ await sleep( pollingDelay );
498
+ return getResults( { client, command } );
499
+ };
500
+
501
+ module.exports = async ( { client, queryId } ) => {
502
+ const command = new GetQueryResultsCommand( { queryId } );
503
+ return getResults( { client, command } );
504
+ };
505
+
506
+
476
507
  /***/ }),
477
508
 
478
509
  /***/ 748:
@@ -833,6 +864,14 @@ const defaultArgs = {
833
864
  module.exports = createInstance( args => clientProvider( TimestreamWriteClient, [ Object.assign( {}, defaultArgs, args ) ] ), methods );
834
865
 
835
866
 
867
+ /***/ }),
868
+
869
+ /***/ 2549:
870
+ /***/ ((module) => {
871
+
872
+ module.exports = 500;
873
+
874
+
836
875
  /***/ }),
837
876
 
838
877
  /***/ 2705:
@@ -843,6 +882,23 @@ const LambdaApi = __webpack_require__( 321 );
843
882
  module.exports = { LambdaApi };
844
883
 
845
884
 
885
+ /***/ }),
886
+
887
+ /***/ 2710:
888
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
889
+
890
+ const { CloudWatchLogsClient } = __webpack_require__( 7493 );
891
+ const clientProvider = __webpack_require__( 9039 );
892
+ const query = __webpack_require__( 4338 );
893
+ const createInstance = __webpack_require__( 5438 );
894
+
895
+ const methods = {
896
+ query
897
+ };
898
+
899
+ module.exports = createInstance( clientProvider.bind( null, CloudWatchLogsClient ), methods );
900
+
901
+
846
902
  /***/ }),
847
903
 
848
904
  /***/ 2736:
@@ -866,6 +922,57 @@ module.exports = values => {
866
922
  module.exports = ( ...args ) => [ ...new Set( args.filter( Array.isArray ).flat() ) ];
867
923
 
868
924
 
925
+ /***/ }),
926
+
927
+ /***/ 2847:
928
+ /***/ ((module) => {
929
+
930
+ const parseInteger = value => {
931
+ const number = parseInt( value, 10 );
932
+ return number <= Number.MAX_SAFE_INTEGER && number >= Number.MIN_SAFE_INTEGER ? number : value;
933
+ };
934
+
935
+ const parseFloatingPoint = value => {
936
+ if ( value.replace( /[^\d]/g, '' ).length > 16 ) {
937
+ return value;
938
+ }
939
+ const number = parseFloat( value, 10 );
940
+ return number <= Number.MAX_SAFE_INTEGER && number >= Number.MIN_SAFE_INTEGER ? number : value;
941
+ };
942
+
943
+ /* eslint-disable consistent-return */
944
+ module.exports = value => {
945
+ if ( [ null, undefined ].includes( value ) ) {
946
+ return undefined;
947
+ }
948
+
949
+ if ( /^\d{4}-\d\d-\d\d((T| )\d\d:\d\d:\d\d(.\d{3})?(Z|\+\d\d:?\d\d)?)?$/.test( value ) ) {
950
+ return new Date( value );
951
+ }
952
+
953
+ // integer
954
+ if ( /^-?\d+$/.test( value ) ) {
955
+ return parseInteger( value );
956
+ }
957
+
958
+ // float
959
+ if ( /^-?(\d+\.|\.\d+|\d+\.\d+)$/.test( value ) ) {
960
+ return parseFloatingPoint( value );
961
+ }
962
+
963
+ // boolean
964
+ if ( /^true$/.test( value ) ) {
965
+ return true;
966
+ }
967
+
968
+ if ( /^false$/.test( value ) ) {
969
+ return false;
970
+ }
971
+
972
+ return value;
973
+ };
974
+
975
+
869
976
  /***/ }),
870
977
 
871
978
  /***/ 2966:
@@ -1199,28 +1306,16 @@ module.exports = createInstance( clientProvider.bind( null, LambdaClient ), meth
1199
1306
  /***/ 3649:
1200
1307
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1201
1308
 
1202
- const { QueryCommand } = __webpack_require__( 1671 );
1203
- const { camelize } = __webpack_require__( 5762 );
1204
- const parseItems = __webpack_require__( 7261 );
1205
-
1206
- const query = async ( client, queryString, { prevItems = [], recursive, paginationToken, maxRows, rawResponse } ) => {
1207
- const response = await client.send( new QueryCommand( { QueryString: queryString, NextToken: paginationToken, MaxRows: maxRows } ) );
1208
- if ( !recursive && rawResponse ) {
1209
- return response;
1210
- }
1309
+ const { StartQueryCommand } = __webpack_require__( 7493 );
1211
1310
 
1212
- const nextToken = response.NextToken;
1213
- if ( nextToken && recursive ) {
1214
- return query( client, queryString, { prevItems: parseItems( response ), recursive, paginationToken: nextToken, maxRows } );
1215
- }
1311
+ module.exports = async ( { client, nativeArgs, range } ) => {
1312
+ const startTime = range?.from ? Math.trunc( range.from / 1000 ) : nativeArgs.startTime;
1313
+ const endTime = range?.to ? Math.trunc( range.to / 1000 ) : nativeArgs.endTime;
1216
1314
 
1217
- const items = prevItems.concat( parseItems( response ) );
1218
- return { nextToken, count: items.length, items, queryStatus: camelize( response.QueryStatus ) };
1315
+ const { queryId } = await client.send( new StartQueryCommand( { ...nativeArgs, startTime, endTime } ) );
1316
+ return queryId;
1219
1317
  };
1220
1318
 
1221
- module.exports = async ( client, queryString, { recursive = false, paginationToken = undefined, maxRows = undefined, rawResponse = false } = {} ) =>
1222
- query( client, queryString, { recursive, paginationToken, maxRows, rawResponse } );
1223
-
1224
1319
 
1225
1320
  /***/ }),
1226
1321
 
@@ -1402,7 +1497,7 @@ module.exports = {
1402
1497
  /***/ 4225:
1403
1498
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1404
1499
 
1405
- const query = __webpack_require__( 3649 );
1500
+ const query = __webpack_require__( 6030 );
1406
1501
  const { TimestreamQueryClient } = __webpack_require__( 1671 );
1407
1502
  const { Agent } = __webpack_require__( 5692 );
1408
1503
  const clientProvider = __webpack_require__( 9039 );
@@ -1471,6 +1566,40 @@ module.exports = async ( closure, { limit = 0, delay = 0, retryHook = null } = {
1471
1566
  execWithRetry( closure, { limit, delay, retryHook } );
1472
1567
 
1473
1568
 
1569
+ /***/ }),
1570
+
1571
+ /***/ 4338:
1572
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1573
+
1574
+ const startQuery = __webpack_require__( 3649 );
1575
+ const getResults = __webpack_require__( 739 );
1576
+ const parseResults = __webpack_require__( 9552 );
1577
+
1578
+ /**
1579
+ * @class Result
1580
+ * @type {Object}
1581
+ * @property {Object[]} items Each query result row, parsed to a camelized js object
1582
+ * @property {Number} count Total number of results
1583
+ */
1584
+
1585
+ /**
1586
+ * Executes an Athena Query
1587
+ * @param {*} client The native client
1588
+ * @param {Object} nativeArgs The native args to start the Cloudwatch Query
1589
+ * @param {Object=} options Extra options for this command
1590
+ * @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"
1591
+ * @param {Number} options.range.from The beginning of the time range to query, overwrites "startTime"
1592
+ * @param {Number} options.range.to The end of the time range to query, overwrites "endTime"
1593
+ * @returns {Result} The query result
1594
+ */
1595
+ module.exports = async ( client, nativeArgs, { range = {} } = {} ) => {
1596
+ const queryId = await startQuery( { client, nativeArgs, range } );
1597
+ const results = await getResults( { client, queryId } );
1598
+ const items = parseResults( results );
1599
+ return { items, count: items.length };
1600
+ };
1601
+
1602
+
1474
1603
  /***/ }),
1475
1604
 
1476
1605
  /***/ 4348:
@@ -1530,6 +1659,7 @@ module.exports = ( items, size ) => items.reduce( ( arrs, item ) =>
1530
1659
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1531
1660
 
1532
1661
  const athena = __webpack_require__( 228 );
1662
+ const cwLogs = __webpack_require__( 2710 );
1533
1663
  const dynamo = __webpack_require__( 1505 );
1534
1664
  const lambda = __webpack_require__( 3544 );
1535
1665
  const s3 = __webpack_require__( 645 );
@@ -1542,6 +1672,7 @@ const timestreamWrite = __webpack_require__( 2538 );
1542
1672
 
1543
1673
  module.exports = {
1544
1674
  athena,
1675
+ cwLogs,
1545
1676
  dynamo,
1546
1677
  lambda,
1547
1678
  s3,
@@ -1827,6 +1958,34 @@ module.exports = async ( client, name, payload = {}, type = 'RequestResponse' )
1827
1958
  };
1828
1959
 
1829
1960
 
1961
+ /***/ }),
1962
+
1963
+ /***/ 6030:
1964
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1965
+
1966
+ const { QueryCommand } = __webpack_require__( 1671 );
1967
+ const { camelize } = __webpack_require__( 5762 );
1968
+ const parseItems = __webpack_require__( 7261 );
1969
+
1970
+ const query = async ( client, queryString, { prevItems = [], recursive, paginationToken, maxRows, rawResponse } ) => {
1971
+ const response = await client.send( new QueryCommand( { QueryString: queryString, NextToken: paginationToken, MaxRows: maxRows } ) );
1972
+ if ( !recursive && rawResponse ) {
1973
+ return response;
1974
+ }
1975
+
1976
+ const nextToken = response.NextToken;
1977
+ if ( nextToken && recursive ) {
1978
+ return query( client, queryString, { prevItems: parseItems( response ), recursive, paginationToken: nextToken, maxRows } );
1979
+ }
1980
+
1981
+ const items = prevItems.concat( parseItems( response ) );
1982
+ return { nextToken, count: items.length, items, queryStatus: camelize( response.QueryStatus ) };
1983
+ };
1984
+
1985
+ module.exports = async ( client, queryString, { recursive = false, paginationToken = undefined, maxRows = undefined, rawResponse = false } = {} ) =>
1986
+ query( client, queryString, { recursive, paginationToken, maxRows, rawResponse } );
1987
+
1988
+
1830
1989
  /***/ }),
1831
1990
 
1832
1991
  /***/ 6089:
@@ -2080,6 +2239,14 @@ module.exports = getResults;
2080
2239
  module.exports = v => Math.ceil( v / 1000 );
2081
2240
 
2082
2241
 
2242
+ /***/ }),
2243
+
2244
+ /***/ 7493:
2245
+ /***/ ((module) => {
2246
+
2247
+ "use strict";
2248
+ module.exports = require("@aws-sdk/client-cloudwatch-logs");
2249
+
2083
2250
  /***/ }),
2084
2251
 
2085
2252
  /***/ 7572:
@@ -2400,8 +2567,6 @@ module.exports = ( constructor, args = [] ) => {
2400
2567
  const cacheKey = `${constructor.name}(${args.map( arg => JSON.stringify( arg ) ).join( ',' )})`;
2401
2568
  return cache.get( cacheKey ) ?? ( () => {
2402
2569
  const client = Reflect.construct( constructor, args );
2403
- // console.log( 'client', client );
2404
- // const client = new constructor( ...args );
2405
2570
  cache.set( cacheKey, client );
2406
2571
  return client;
2407
2572
  } )();
@@ -2456,6 +2621,30 @@ module.exports = ( v, type ) => {
2456
2621
  };
2457
2622
 
2458
2623
 
2624
+ /***/ }),
2625
+
2626
+ /***/ 9179:
2627
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2628
+
2629
+ const parseValue = __webpack_require__( 2847 );
2630
+
2631
+ module.exports = item =>
2632
+ item.reduce( ( row, { field, value } ) =>
2633
+ Object.assign( row, {
2634
+ [field]: parseValue( value )
2635
+ } ), {} );
2636
+
2637
+
2638
+ /***/ }),
2639
+
2640
+ /***/ 9552:
2641
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2642
+
2643
+ const parseItem = __webpack_require__( 9179 );
2644
+
2645
+ module.exports = results => results.map( item => parseItem( item ) );
2646
+
2647
+
2459
2648
  /***/ }),
2460
2649
 
2461
2650
  /***/ 9556:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambda-toolkit",
3
- "version": "0.0.13-beta",
3
+ "version": "0.0.14-beta",
4
4
  "description": "A set of tools to help and simplify Node Js code development for AWS Lambdas",
5
5
  "files": [
6
6
  "./license",
@@ -25,6 +25,7 @@
25
25
  "homepage": "https://github.com/szanata/lambda-toolkit",
26
26
  "dependencies": {
27
27
  "@aws-sdk/client-athena": "^3.758.0",
28
+ "@aws-sdk/client-cloudwatch-logs": "^3.774.0",
28
29
  "@aws-sdk/client-dynamodb": "^3.758.0",
29
30
  "@aws-sdk/client-lambda": "^3.758.0",
30
31
  "@aws-sdk/client-s3": "^3.758.0",