ag-common 0.0.739 → 0.0.741

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.
@@ -30,14 +30,14 @@ const batchDelete = (params) => __awaiter(void 0, void 0, void 0, function* () {
30
30
  const chunked = (0, array_1.chunk)(params.keys, batchSize);
31
31
  let processed = 0;
32
32
  yield (0, async_1.asyncForEach)(chunked, (chunk) => __awaiter(void 0, void 0, void 0, function* () {
33
- const command = new lib_dynamodb_1.BatchWriteCommand({
33
+ const batchDeleteParams = {
34
34
  RequestItems: {
35
35
  [params.tableName]: chunk.map((key) => ({
36
36
  DeleteRequest: { Key: { [params.pkName]: key } },
37
37
  })),
38
38
  },
39
- });
40
- yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(command), `batchdelete ${processed}/${params.keys.length}. size=${batchSize}`, {
39
+ };
40
+ yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.BatchWriteCommand(batchDeleteParams)), `batchdelete ${processed}/${params.keys.length}. size=${batchSize}`, {
41
41
  maxRetries: alwaysRetry ? null : undefined,
42
42
  });
43
43
  processed += chunk.length;
@@ -62,11 +62,10 @@ const executeQuery = (params, startKey) => __awaiter(void 0, void 0, void 0, fun
62
62
  eav[`:${skName.toLowerCase()}`] = skValue;
63
63
  }
64
64
  }
65
- const queryParams = new lib_dynamodb_1.QueryCommand(Object.assign({ TableName: params.tableName, KeyConditionExpression: kce, ExpressionAttributeNames: Object.assign(Object.assign({}, ean), (_b = params.filter) === null || _b === void 0 ? void 0 : _b.attrNames), ExpressionAttributeValues: Object.assign(Object.assign({}, eav), (_c = params.filter) === null || _c === void 0 ? void 0 : _c.attrValues), ScanIndexForward: (_d = params.sortAscending) !== null && _d !== void 0 ? _d : true, Limit: (_e = params.BATCH_SIZE) !== null && _e !== void 0 ? _e : params.limit, IndexName: params.indexName, ExclusiveStartKey: startKey }, (params.filter && Object.assign({ FilterExpression: params.filter.filterExpression }, (params.filter.attrValues && {
65
+ const queryParams = Object.assign({ TableName: params.tableName, KeyConditionExpression: kce, ExpressionAttributeNames: Object.assign(Object.assign({}, ean), (_b = params.filter) === null || _b === void 0 ? void 0 : _b.attrNames), ExpressionAttributeValues: Object.assign(Object.assign({}, eav), (_c = params.filter) === null || _c === void 0 ? void 0 : _c.attrValues), ScanIndexForward: (_d = params.sortAscending) !== null && _d !== void 0 ? _d : true, Limit: (_e = params.BATCH_SIZE) !== null && _e !== void 0 ? _e : params.limit, IndexName: params.indexName, ExclusiveStartKey: startKey }, (params.filter && Object.assign({ FilterExpression: params.filter.filterExpression }, (params.filter.attrValues && {
66
66
  ExpressionAttributeValues: Object.assign(Object.assign({}, eav), params.filter.attrValues),
67
- })))));
68
- // eslint-disable-next-line no-return-await
69
- return yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(queryParams), 'queryDynamo');
67
+ }))));
68
+ return (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.QueryCommand(queryParams)), 'queryDynamo');
70
69
  });
71
70
  /**
72
71
  * Helper function that builds the scan parameters and executes the scan
@@ -78,7 +77,7 @@ const executeScan = (tableName, options, exclusiveStartKey) => __awaiter(void 0,
78
77
  return acc;
79
78
  }, {});
80
79
  const expressionAttributeNames = Object.assign(Object.assign({}, projectionAttrs), (_b = options === null || options === void 0 ? void 0 : options.filter) === null || _b === void 0 ? void 0 : _b.attrNames);
81
- const params = new lib_dynamodb_1.ScanCommand(Object.assign(Object.assign(Object.assign(Object.assign({ TableName: tableName, IndexName: options === null || options === void 0 ? void 0 : options.indexName, Limit: options === null || options === void 0 ? void 0 : options.BATCH_SIZE }, ((options === null || options === void 0 ? void 0 : options.filter) && Object.assign({ FilterExpression: options.filter.filterExpression }, (options.filter.attrValues && {
80
+ const scanParams = Object.assign(Object.assign(Object.assign(Object.assign({ TableName: tableName, IndexName: options === null || options === void 0 ? void 0 : options.indexName, Limit: options === null || options === void 0 ? void 0 : options.BATCH_SIZE }, ((options === null || options === void 0 ? void 0 : options.filter) && Object.assign({ FilterExpression: options.filter.filterExpression }, (options.filter.attrValues && {
82
81
  ExpressionAttributeValues: options.filter.attrValues,
83
82
  })))), (Object.keys(expressionAttributeNames).length > 0 && {
84
83
  ExpressionAttributeNames: expressionAttributeNames,
@@ -86,16 +85,15 @@ const executeScan = (tableName, options, exclusiveStartKey) => __awaiter(void 0,
86
85
  ProjectionExpression: options.requiredAttributeList
87
86
  .map((_, index) => `#proj${index}`)
88
87
  .join(', '),
89
- })), { ExclusiveStartKey: exclusiveStartKey }));
90
- // eslint-disable-next-line no-return-await
91
- return yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(params), `scan. already seen=${exclusiveStartKey ? 'some' : '0'} items`, {
88
+ })), { ExclusiveStartKey: exclusiveStartKey });
89
+ return (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.ScanCommand(scanParams)), `scan. already seen=${exclusiveStartKey ? 'some' : '0'} items`, {
92
90
  maxRetries: (options === null || options === void 0 ? void 0 : options.alwaysRetry) ? null : undefined,
93
91
  });
94
92
  });
95
93
  const getItemsDynamo = (params) => __awaiter(void 0, void 0, void 0, function* () {
96
94
  var _a, _b;
97
95
  try {
98
- const command = new lib_dynamodb_1.BatchGetCommand({
96
+ const batchGetParams = {
99
97
  RequestItems: {
100
98
  [params.tableName]: {
101
99
  Keys: params.items.map(({ pkName, pkValue }) => ({
@@ -103,8 +101,8 @@ const getItemsDynamo = (params) => __awaiter(void 0, void 0, void 0, function* (
103
101
  })),
104
102
  },
105
103
  },
106
- });
107
- const result = yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(command), 'getItemsDynamo');
104
+ };
105
+ const result = yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.BatchGetCommand(batchGetParams)), 'getItemsDynamo');
108
106
  return {
109
107
  data: (_b = (_a = result.Responses) === null || _a === void 0 ? void 0 : _a[params.tableName]) !== null && _b !== void 0 ? _b : [],
110
108
  };
@@ -16,11 +16,11 @@ const async_1 = require("../../../common/helpers/async");
16
16
  const withRetry_1 = require("../withRetry");
17
17
  const _1 = require(".");
18
18
  const putDynamo = (item, tableName, opt) => __awaiter(void 0, void 0, void 0, function* () {
19
- const params = new lib_dynamodb_1.PutCommand(Object.assign({ TableName: tableName, Item: item }, ((opt === null || opt === void 0 ? void 0 : opt.pkName) && {
19
+ const putParams = Object.assign({ TableName: tableName, Item: item }, ((opt === null || opt === void 0 ? void 0 : opt.pkName) && {
20
20
  ConditionExpression: `attribute_not_exists(${opt.pkName})`,
21
- })));
21
+ }));
22
22
  try {
23
- yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(params), 'putDynamo');
23
+ yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.PutCommand(putParams)), 'putDynamo');
24
24
  return { data: undefined };
25
25
  }
26
26
  catch (e) {
@@ -34,12 +34,12 @@ const batchWrite = (tableName, items, opt) => __awaiter(void 0, void 0, void 0,
34
34
  let processed = 0;
35
35
  const chunked = (0, array_1.chunk)(items, batchSize);
36
36
  yield (0, async_1.asyncForEach)(chunked, (chunk) => __awaiter(void 0, void 0, void 0, function* () {
37
- const params = new lib_dynamodb_1.BatchWriteCommand({
37
+ const batchWriteParams = {
38
38
  RequestItems: {
39
39
  [tableName]: chunk.map((Item) => ({ PutRequest: { Item } })),
40
40
  },
41
- });
42
- yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(params), `batchwrite ${processed}/${items.length}. size=${batchSize}`, {
41
+ };
42
+ yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.BatchWriteCommand(batchWriteParams)), `batchwrite ${processed}/${items.length}. size=${batchSize}`, {
43
43
  maxRetries: (opt === null || opt === void 0 ? void 0 : opt.alwaysRetry) ? null : undefined,
44
44
  });
45
45
  processed += chunk.length;
@@ -14,6 +14,8 @@ export type StorageConfig = {
14
14
  accountId: string;
15
15
  accessKeyId?: string;
16
16
  secretAccessKey?: string;
17
+ /** region to use. default auto */
18
+ region?: string;
17
19
  };
18
20
  export declare const createStorageClient: (config: StorageConfig) => S3Client;
19
21
  export declare const setS3: (config: StorageConfig) => void;
@@ -48,6 +48,7 @@ const getCacheKey = (config) => {
48
48
  });
49
49
  };
50
50
  const createStorageClient = (config) => {
51
+ var _a;
51
52
  const cacheKey = getCacheKey(config);
52
53
  const cachedClient = clientCache.get(cacheKey);
53
54
  if (cachedClient) {
@@ -59,14 +60,14 @@ const createStorageClient = (config) => {
59
60
  if (!accountId) {
60
61
  throw new Error('Account ID is required for R2. Set CLOUDFLARE_ACCOUNT_ID env var or provide accountId in config');
61
62
  }
62
- client = new client_s3_1.S3Client(Object.assign({ endpoint: `https://${accountId}.r2.cloudflarestorage.com`, forcePathStyle: true }, (config.accessKeyId && config.secretAccessKey
63
+ client = new client_s3_1.S3Client(Object.assign(Object.assign({ endpoint: `https://${accountId}.r2.cloudflarestorage.com`, forcePathStyle: true }, (config.accessKeyId && config.secretAccessKey
63
64
  ? {
64
65
  credentials: {
65
66
  accessKeyId: config.accessKeyId,
66
67
  secretAccessKey: config.secretAccessKey,
67
68
  },
68
69
  }
69
- : {})));
70
+ : {})), { region: (_a = config.region) !== null && _a !== void 0 ? _a : 'auto' }));
70
71
  }
71
72
  else {
72
73
  client = new client_s3_1.S3Client({
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.739",
2
+ "version": "0.0.741",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",