ag-common 0.0.893 → 0.0.894
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/helpers/acm.js +7 -17
- package/dist/api/helpers/api.js +28 -23
- package/dist/api/helpers/apigw.js +54 -71
- package/dist/api/helpers/cosmos/delete.js +81 -94
- package/dist/api/helpers/cosmos/get.js +170 -195
- package/dist/api/helpers/cosmos/index.js +23 -53
- package/dist/api/helpers/cosmos/write.js +88 -92
- package/dist/api/helpers/dynamo/delete.js +22 -52
- package/dist/api/helpers/dynamo/get.js +145 -135
- package/dist/api/helpers/dynamo/set.js +22 -29
- package/dist/api/helpers/enforceDynamoProvisionCap.js +5 -5
- package/dist/api/helpers/google/apikey.js +1 -2
- package/dist/api/helpers/google/gemini.js +26 -37
- package/dist/api/helpers/retryOnError.js +15 -26
- package/dist/api/helpers/s3.js +102 -121
- package/dist/api/helpers/ses.js +19 -26
- package/dist/api/helpers/sqs.js +5 -15
- package/dist/api/helpers/ssmInfra/dynamo.js +9 -5
- package/dist/api/helpers/sts.js +26 -37
- package/dist/api/helpers/validations.js +7 -17
- package/dist/api/helpers/zod.js +1 -2
- package/dist/common/helpers/async.js +27 -42
- package/dist/common/helpers/csv.js +1 -4
- package/dist/common/helpers/date.js +2 -2
- package/dist/common/helpers/fetch.js +42 -55
- package/dist/common/helpers/generator.js +11 -22
- package/dist/common/helpers/i18n.js +3 -5
- package/dist/common/helpers/log.js +4 -4
- package/dist/common/helpers/math.js +1 -2
- package/dist/common/helpers/node-cache.js +10 -2
- package/dist/common/helpers/random.js +2 -2
- package/dist/common/helpers/secondsInNearest.js +1 -2
- package/dist/common/helpers/stream.js +24 -35
- package/dist/common/helpers/string/redact.js +1 -2
- package/dist/common/helpers/withRetry.js +5 -14
- package/dist/common/helpers/xml.js +9 -22
- package/dist/node/helpers/fetch.js +22 -33
- package/dist/ui/components/DarkMode/Base.js +10 -5
- package/dist/ui/components/Markdown/index.js +4 -5
- package/dist/ui/components/shadcn/accordion.js +13 -36
- package/dist/ui/components/shadcn/alert.d.ts +1 -1
- package/dist/ui/components/shadcn/alert.js +3 -23
- package/dist/ui/components/shadcn/avatar.js +4 -24
- package/dist/ui/components/shadcn/button.d.ts +1 -1
- package/dist/ui/components/shadcn/button.js +2 -14
- package/dist/ui/components/shadcn/card.js +6 -35
- package/dist/ui/components/shadcn/checkbox.js +4 -18
- package/dist/ui/components/shadcn/dialog.js +17 -46
- package/dist/ui/components/shadcn/dropdown-list.js +2 -2
- package/dist/ui/components/shadcn/dropdown-menu.js +22 -58
- package/dist/ui/components/shadcn/input-selector.js +4 -5
- package/dist/ui/components/shadcn/input.js +2 -14
- package/dist/ui/components/shadcn/label.d.ts +1 -1
- package/dist/ui/components/shadcn/label.js +2 -16
- package/dist/ui/components/shadcn/popover.js +3 -17
- package/dist/ui/components/shadcn/radio-group.js +4 -17
- package/dist/ui/components/shadcn/scroll-area.js +9 -26
- package/dist/ui/components/shadcn/select.js +23 -55
- package/dist/ui/components/shadcn/sheet.d.ts +1 -1
- package/dist/ui/components/shadcn/sheet.js +13 -42
- package/dist/ui/components/shadcn/switch.js +3 -17
- package/dist/ui/components/shadcn/textarea.js +2 -14
- package/dist/ui/components/shadcn/toast.js +6 -4
- package/dist/ui/helpers/cookie/get.js +5 -1
- package/dist/ui/helpers/cookie/raw.js +1 -2
- package/dist/ui/helpers/cookie/set.js +2 -2
- package/dist/ui/helpers/cookie/use.js +19 -9
- package/dist/ui/helpers/date.js +3 -4
- package/dist/ui/helpers/debounce.js +1 -1
- package/dist/ui/helpers/extractAttributes.js +1 -2
- package/dist/ui/helpers/openDialog.js +1 -2
- package/dist/ui/helpers/routes.js +6 -4
- package/dist/ui/helpers/serviceWorker.js +7 -18
- package/dist/ui/helpers/useContextMenu.js +2 -3
- package/dist/ui/helpers/useElementAttribute.js +1 -1
- package/dist/ui/helpers/useGranularHook.js +2 -2
- package/dist/ui/helpers/useInterval.js +5 -7
- package/dist/ui/helpers/useLocalStorage.js +1 -1
- package/dist/ui/helpers/useOnClickOutside.js +2 -3
- package/dist/ui/helpers/useOnScroll.js +6 -8
- package/dist/ui/helpers/useOverloadPageSearch.js +1 -1
- package/dist/ui/helpers/useQueryString.js +2 -2
- package/dist/ui/helpers/useResize.js +1 -1
- package/dist/ui/helpers/useTimeout.js +1 -1
- package/dist/ui/helpers/useTooltip.js +8 -5
- package/dist/ui/icons/Checkmark.js +2 -5
- package/dist/ui/icons/Circle.js +2 -5
- package/dist/ui/icons/Magnify.js +2 -5
- package/dist/ui/icons/Sun.js +8 -11
- package/dist/ui/icons/Warning.js +7 -10
- package/dist/ui/styles/common.js +8 -20
- package/package.json +66 -65
|
@@ -1,26 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
12
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
13
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
14
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
15
|
-
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
16
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
17
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
18
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
19
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
20
|
-
function fulfill(value) { resume("next", value); }
|
|
21
|
-
function reject(value) { resume("throw", value); }
|
|
22
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
23
|
-
};
|
|
24
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
3
|
exports.batchQueryDynamo = exports.scan = exports.queryDynamo = exports.getItemDynamo = exports.getItemsDynamo = void 0;
|
|
26
4
|
exports.queryWithGenerator = queryWithGenerator;
|
|
@@ -32,9 +10,8 @@ const isError = (result) => 'error' in result;
|
|
|
32
10
|
/**
|
|
33
11
|
* Helper function that builds the query parameters and executes the query
|
|
34
12
|
*/
|
|
35
|
-
const executeQuery = (params, exclusiveStartKey) =>
|
|
36
|
-
|
|
37
|
-
let kce = `#${params.pkName.toLowerCase()} ${(_a = params.pkOperator) !== null && _a !== void 0 ? _a : '='} :${params.pkName.toLowerCase()}`;
|
|
13
|
+
const executeQuery = async (params, exclusiveStartKey) => {
|
|
14
|
+
let kce = `#${params.pkName.toLowerCase()} ${params.pkOperator ?? '='} :${params.pkName.toLowerCase()}`;
|
|
38
15
|
const ean = {
|
|
39
16
|
[`#${params.pkName.toLowerCase()}`]: params.pkName,
|
|
40
17
|
};
|
|
@@ -61,44 +38,79 @@ const executeQuery = (params, exclusiveStartKey) => __awaiter(void 0, void 0, vo
|
|
|
61
38
|
eav[`:${skName.toLowerCase()}`] = skValue;
|
|
62
39
|
}
|
|
63
40
|
}
|
|
64
|
-
const queryParams =
|
|
65
|
-
|
|
66
|
-
|
|
41
|
+
const queryParams = {
|
|
42
|
+
TableName: params.tableName,
|
|
43
|
+
KeyConditionExpression: kce,
|
|
44
|
+
ExpressionAttributeNames: {
|
|
45
|
+
...ean,
|
|
46
|
+
...params.filter?.attrNames,
|
|
47
|
+
},
|
|
48
|
+
ExpressionAttributeValues: {
|
|
49
|
+
...eav,
|
|
50
|
+
...params.filter?.attrValues,
|
|
51
|
+
},
|
|
52
|
+
ScanIndexForward: params.sortAscending ?? true,
|
|
53
|
+
Limit: params.limit === -1 ? undefined : params.limit,
|
|
54
|
+
IndexName: params.indexName,
|
|
55
|
+
ExclusiveStartKey: exclusiveStartKey,
|
|
56
|
+
...(params.filter && {
|
|
57
|
+
FilterExpression: params.filter.filterExpression,
|
|
58
|
+
...(params.filter.attrValues && {
|
|
59
|
+
ExpressionAttributeValues: {
|
|
60
|
+
...eav,
|
|
61
|
+
...params.filter.attrValues,
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
}),
|
|
65
|
+
};
|
|
67
66
|
return (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.QueryCommand(queryParams)), 'queryDynamo:' + JSON.stringify(params), {
|
|
68
67
|
maxRetries: params.maxRetries === undefined ? 3 : params.maxRetries,
|
|
69
68
|
});
|
|
70
|
-
}
|
|
69
|
+
};
|
|
71
70
|
/**
|
|
72
71
|
* Helper function that builds the scan parameters and executes the scan
|
|
73
72
|
*/
|
|
74
|
-
const executeScan = (tableName, options, exclusiveStartKey) =>
|
|
75
|
-
|
|
76
|
-
const projectionAttrs = (_a = options === null || options === void 0 ? void 0 : options.requiredAttributeList) === null || _a === void 0 ? void 0 : _a.reduce((acc, attr, index) => {
|
|
73
|
+
const executeScan = async (tableName, options, exclusiveStartKey) => {
|
|
74
|
+
const projectionAttrs = options?.requiredAttributeList?.reduce((acc, attr, index) => {
|
|
77
75
|
acc[`#proj${index}`] = attr;
|
|
78
76
|
return acc;
|
|
79
77
|
}, {});
|
|
80
|
-
const expressionAttributeNames =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
78
|
+
const expressionAttributeNames = {
|
|
79
|
+
...projectionAttrs,
|
|
80
|
+
...options?.filter?.attrNames,
|
|
81
|
+
};
|
|
82
|
+
const scanParams = {
|
|
83
|
+
TableName: tableName,
|
|
84
|
+
IndexName: options?.indexName,
|
|
85
|
+
Limit: options?.limit === -1 ? undefined : options?.limit,
|
|
86
|
+
...(options?.filter && {
|
|
87
|
+
FilterExpression: options.filter.filterExpression,
|
|
88
|
+
...(options.filter.attrValues && {
|
|
89
|
+
ExpressionAttributeValues: options.filter.attrValues,
|
|
90
|
+
}),
|
|
91
|
+
}),
|
|
92
|
+
...(Object.keys(expressionAttributeNames).length > 0 && {
|
|
93
|
+
ExpressionAttributeNames: expressionAttributeNames,
|
|
94
|
+
}),
|
|
95
|
+
...(options?.requiredAttributeList && {
|
|
96
|
+
ProjectionExpression: options.requiredAttributeList
|
|
97
|
+
.map((_, index) => `#proj${index}`)
|
|
98
|
+
.join(', '),
|
|
99
|
+
}),
|
|
100
|
+
ExclusiveStartKey: exclusiveStartKey,
|
|
101
|
+
};
|
|
90
102
|
return (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.ScanCommand(scanParams)), `scan. already seen=${exclusiveStartKey ? 'some' : '0'} items`, {
|
|
91
|
-
maxRetries:
|
|
103
|
+
maxRetries: options?.maxRetries === undefined ? 3 : options.maxRetries,
|
|
92
104
|
});
|
|
93
|
-
}
|
|
94
|
-
const getItemsDynamo = (params) =>
|
|
105
|
+
};
|
|
106
|
+
const getItemsDynamo = async (params) => {
|
|
95
107
|
try {
|
|
96
108
|
const BATCH_SIZE = 100;
|
|
97
109
|
const chunks = [];
|
|
98
110
|
for (let i = 0; i < params.items.length; i += BATCH_SIZE) {
|
|
99
111
|
chunks.push(params.items.slice(i, i + BATCH_SIZE));
|
|
100
112
|
}
|
|
101
|
-
const responses =
|
|
113
|
+
const responses = await Promise.all(chunks.map((chunk) => {
|
|
102
114
|
const batchGetParams = {
|
|
103
115
|
RequestItems: {
|
|
104
116
|
[params.tableName]: {
|
|
@@ -112,8 +124,7 @@ const getItemsDynamo = (params) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
112
124
|
}));
|
|
113
125
|
const allItems = [];
|
|
114
126
|
responses.forEach((result) => {
|
|
115
|
-
|
|
116
|
-
const items = ((_b = (_a = result.Responses) === null || _a === void 0 ? void 0 : _a[params.tableName]) !== null && _b !== void 0 ? _b : []);
|
|
127
|
+
const items = (result.Responses?.[params.tableName] ?? []);
|
|
117
128
|
allItems.push(...items);
|
|
118
129
|
});
|
|
119
130
|
return { data: allItems };
|
|
@@ -121,10 +132,10 @@ const getItemsDynamo = (params) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
121
132
|
catch (e) {
|
|
122
133
|
return { error: e.toString() };
|
|
123
134
|
}
|
|
124
|
-
}
|
|
135
|
+
};
|
|
125
136
|
exports.getItemsDynamo = getItemsDynamo;
|
|
126
|
-
const getItemDynamo = (params) =>
|
|
127
|
-
const result =
|
|
137
|
+
const getItemDynamo = async (params) => {
|
|
138
|
+
const result = await (0, exports.getItemsDynamo)({
|
|
128
139
|
tableName: params.tableName,
|
|
129
140
|
items: [{ pkName: params.pkName, pkValue: params.pkValue }],
|
|
130
141
|
});
|
|
@@ -132,15 +143,15 @@ const getItemDynamo = (params) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
132
143
|
return result;
|
|
133
144
|
}
|
|
134
145
|
return { data: result.data[0] };
|
|
135
|
-
}
|
|
146
|
+
};
|
|
136
147
|
exports.getItemDynamo = getItemDynamo;
|
|
137
|
-
const queryDynamo = (params) =>
|
|
148
|
+
const queryDynamo = async (params) => {
|
|
138
149
|
try {
|
|
139
150
|
const items = [];
|
|
140
151
|
let lastEvaluatedKey = params.exclusiveStartKey;
|
|
141
152
|
const hasLimit = params.limit && params.limit > 0;
|
|
142
153
|
do {
|
|
143
|
-
const result =
|
|
154
|
+
const result = await executeQuery(params, lastEvaluatedKey);
|
|
144
155
|
if (result.Items) {
|
|
145
156
|
items.push(...result.Items);
|
|
146
157
|
}
|
|
@@ -162,20 +173,20 @@ const queryDynamo = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
162
173
|
catch (e) {
|
|
163
174
|
return { error: e.toString() };
|
|
164
175
|
}
|
|
165
|
-
}
|
|
176
|
+
};
|
|
166
177
|
exports.queryDynamo = queryDynamo;
|
|
167
|
-
const scan = (tableName, options) =>
|
|
178
|
+
const scan = async (tableName, options) => {
|
|
168
179
|
try {
|
|
169
180
|
const Items = [];
|
|
170
181
|
let ExclusiveStartKey;
|
|
171
182
|
do {
|
|
172
|
-
const result =
|
|
183
|
+
const result = await executeScan(tableName, options, ExclusiveStartKey);
|
|
173
184
|
if (result.Items) {
|
|
174
185
|
Items.push(...result.Items);
|
|
175
186
|
}
|
|
176
187
|
ExclusiveStartKey = result.LastEvaluatedKey;
|
|
177
188
|
// If limit is undefined, we stop after one query (default to single page).
|
|
178
|
-
if (
|
|
189
|
+
if (options?.limit === undefined) {
|
|
179
190
|
break;
|
|
180
191
|
}
|
|
181
192
|
const limit = options.limit;
|
|
@@ -191,7 +202,7 @@ const scan = (tableName, options) => __awaiter(void 0, void 0, void 0, function*
|
|
|
191
202
|
catch (e) {
|
|
192
203
|
return { error: e.toString() };
|
|
193
204
|
}
|
|
194
|
-
}
|
|
205
|
+
};
|
|
195
206
|
exports.scan = scan;
|
|
196
207
|
/**
|
|
197
208
|
* Batch query DynamoDB using PartiQL to query multiple partition key values at once
|
|
@@ -229,7 +240,7 @@ exports.scan = scan;
|
|
|
229
240
|
* @param params - The batch query parameters
|
|
230
241
|
* @returns Promise resolving to query results or error
|
|
231
242
|
*/
|
|
232
|
-
const batchQueryDynamo = (params) =>
|
|
243
|
+
const batchQueryDynamo = async (params) => {
|
|
233
244
|
try {
|
|
234
245
|
if (params.pkValues.length === 0) {
|
|
235
246
|
return { data: [] };
|
|
@@ -246,7 +257,10 @@ const batchQueryDynamo = (params) => __awaiter(void 0, void 0, void 0, function*
|
|
|
246
257
|
let totalProcessed = 0;
|
|
247
258
|
// Process each chunk
|
|
248
259
|
for (const chunk of chunks) {
|
|
249
|
-
const result =
|
|
260
|
+
const result = await executePartiQLQuery({
|
|
261
|
+
...params,
|
|
262
|
+
pkValues: chunk,
|
|
263
|
+
});
|
|
250
264
|
if ('error' in result) {
|
|
251
265
|
return result;
|
|
252
266
|
}
|
|
@@ -266,12 +280,12 @@ const batchQueryDynamo = (params) => __awaiter(void 0, void 0, void 0, function*
|
|
|
266
280
|
catch (e) {
|
|
267
281
|
return { error: e.toString() };
|
|
268
282
|
}
|
|
269
|
-
}
|
|
283
|
+
};
|
|
270
284
|
exports.batchQueryDynamo = batchQueryDynamo;
|
|
271
285
|
/**
|
|
272
286
|
* Helper function to execute a single PartiQL query for a chunk of partition keys
|
|
273
287
|
*/
|
|
274
|
-
const executePartiQLQuery = (params) =>
|
|
288
|
+
const executePartiQLQuery = async (params) => {
|
|
275
289
|
try {
|
|
276
290
|
// Build the PartiQL WHERE clause for multiple partition keys
|
|
277
291
|
const pkPlaceholders = params.pkValues.map(() => '?').join(', ');
|
|
@@ -305,7 +319,7 @@ const executePartiQLQuery = (params) => __awaiter(void 0, void 0, void 0, functi
|
|
|
305
319
|
Limit: params.limit === -1 ? undefined : params.limit,
|
|
306
320
|
NextToken: nextToken,
|
|
307
321
|
};
|
|
308
|
-
const result =
|
|
322
|
+
const result = await (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.ExecuteStatementCommand(executeParams)), 'batchQueryDynamo:' + JSON.stringify(params), {
|
|
309
323
|
maxRetries: params.maxRetries === undefined ? 3 : params.maxRetries,
|
|
310
324
|
});
|
|
311
325
|
if (result.Items) {
|
|
@@ -326,86 +340,82 @@ const executePartiQLQuery = (params) => __awaiter(void 0, void 0, void 0, functi
|
|
|
326
340
|
catch (e) {
|
|
327
341
|
return { error: e.toString() };
|
|
328
342
|
}
|
|
329
|
-
}
|
|
330
|
-
function queryWithGenerator(params) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
return yield __await(void 0);
|
|
349
|
-
}
|
|
343
|
+
};
|
|
344
|
+
async function* queryWithGenerator(params) {
|
|
345
|
+
let limit = undefined;
|
|
346
|
+
if (params.limit && params.limit !== -1) {
|
|
347
|
+
limit = params.limit;
|
|
348
|
+
}
|
|
349
|
+
let items = [];
|
|
350
|
+
let lastEvaluatedKey = params.exclusiveStartKey;
|
|
351
|
+
try {
|
|
352
|
+
do {
|
|
353
|
+
const result = await executeQuery(params, lastEvaluatedKey);
|
|
354
|
+
if (result.Items) {
|
|
355
|
+
items.push(...result.Items);
|
|
356
|
+
// Process items in chunks of BATCH_SIZE
|
|
357
|
+
if (!limit) {
|
|
358
|
+
yield items;
|
|
359
|
+
items = [];
|
|
360
|
+
if (params.limit !== -1) {
|
|
361
|
+
return;
|
|
350
362
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
while (items.length >= limit) {
|
|
366
|
+
const batch = items.slice(0, limit);
|
|
367
|
+
items = items.slice(limit);
|
|
368
|
+
yield batch;
|
|
357
369
|
}
|
|
358
370
|
}
|
|
359
|
-
lastEvaluatedKey = result.LastEvaluatedKey;
|
|
360
|
-
} while (lastEvaluatedKey && Object.keys(lastEvaluatedKey).length > 0);
|
|
361
|
-
// Yield any remaining items
|
|
362
|
-
if (items.length > 0) {
|
|
363
|
-
yield yield __await(items);
|
|
364
371
|
}
|
|
372
|
+
lastEvaluatedKey = result.LastEvaluatedKey;
|
|
373
|
+
} while (lastEvaluatedKey && Object.keys(lastEvaluatedKey).length > 0);
|
|
374
|
+
// Yield any remaining items
|
|
375
|
+
if (items.length > 0) {
|
|
376
|
+
yield items;
|
|
365
377
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
}
|
|
378
|
+
}
|
|
379
|
+
catch (e) {
|
|
380
|
+
throw new Error(`Query generator error: ${e.toString()}`);
|
|
381
|
+
}
|
|
370
382
|
}
|
|
371
|
-
function scanWithGenerator(tableName, options) {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
return yield __await(void 0);
|
|
390
|
-
}
|
|
383
|
+
async function* scanWithGenerator(tableName, options) {
|
|
384
|
+
let limit = undefined;
|
|
385
|
+
if (options?.limit && options.limit !== -1) {
|
|
386
|
+
limit = options.limit;
|
|
387
|
+
}
|
|
388
|
+
let items = [];
|
|
389
|
+
let exclusiveStartKey;
|
|
390
|
+
try {
|
|
391
|
+
do {
|
|
392
|
+
const result = await executeScan(tableName, options, exclusiveStartKey);
|
|
393
|
+
if (result.Items) {
|
|
394
|
+
items.push(...result.Items);
|
|
395
|
+
// Process items in chunks of limit
|
|
396
|
+
if (!limit) {
|
|
397
|
+
yield items;
|
|
398
|
+
items = [];
|
|
399
|
+
if (options?.limit !== -1) {
|
|
400
|
+
return;
|
|
391
401
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
while (items.length >= limit) {
|
|
405
|
+
const batch = items.slice(0, limit);
|
|
406
|
+
items = items.slice(limit);
|
|
407
|
+
yield batch;
|
|
398
408
|
}
|
|
399
409
|
}
|
|
400
|
-
exclusiveStartKey = result.LastEvaluatedKey;
|
|
401
|
-
} while (exclusiveStartKey);
|
|
402
|
-
// Yield any remaining items
|
|
403
|
-
if (items.length > 0) {
|
|
404
|
-
yield yield __await(items);
|
|
405
410
|
}
|
|
411
|
+
exclusiveStartKey = result.LastEvaluatedKey;
|
|
412
|
+
} while (exclusiveStartKey);
|
|
413
|
+
// Yield any remaining items
|
|
414
|
+
if (items.length > 0) {
|
|
415
|
+
yield items;
|
|
406
416
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
}
|
|
410
|
-
}
|
|
417
|
+
}
|
|
418
|
+
catch (e) {
|
|
419
|
+
throw new Error(`Scan generator error: ${e.toString()}`);
|
|
420
|
+
}
|
|
411
421
|
}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getDynamoUpdates = exports.incrementDynamo = exports.batchWrite = exports.putDynamo = void 0;
|
|
13
4
|
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
@@ -15,12 +6,16 @@ const array_1 = require("../../../common/helpers/array");
|
|
|
15
6
|
const async_1 = require("../../../common/helpers/async");
|
|
16
7
|
const withRetry_1 = require("../../../common/helpers/withRetry");
|
|
17
8
|
const _1 = require(".");
|
|
18
|
-
const putDynamo = (item, tableName, opt) =>
|
|
19
|
-
const putParams =
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
const putDynamo = async (item, tableName, opt) => {
|
|
10
|
+
const putParams = {
|
|
11
|
+
TableName: tableName,
|
|
12
|
+
Item: item,
|
|
13
|
+
...(opt?.pkName && {
|
|
14
|
+
ConditionExpression: `attribute_not_exists(${opt.pkName})`,
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
22
17
|
try {
|
|
23
|
-
const res =
|
|
18
|
+
const res = await (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.PutCommand(putParams)), 'putDynamo');
|
|
24
19
|
if (res.$metadata.httpStatusCode !== 200) {
|
|
25
20
|
return { error: res.toString() };
|
|
26
21
|
}
|
|
@@ -29,33 +24,32 @@ const putDynamo = (item, tableName, opt) => __awaiter(void 0, void 0, void 0, fu
|
|
|
29
24
|
catch (e) {
|
|
30
25
|
return { error: e.toString() };
|
|
31
26
|
}
|
|
32
|
-
}
|
|
27
|
+
};
|
|
33
28
|
exports.putDynamo = putDynamo;
|
|
34
|
-
const batchWrite = (tableName, items, opt) =>
|
|
29
|
+
const batchWrite = async (tableName, items, opt) => {
|
|
35
30
|
try {
|
|
36
|
-
const { batchSize = 20 } = opt
|
|
31
|
+
const { batchSize = 20 } = opt ?? {};
|
|
37
32
|
let processed = 0;
|
|
38
33
|
const chunked = (0, array_1.chunk)(items, batchSize);
|
|
39
|
-
|
|
34
|
+
await (0, async_1.asyncForEach)(chunked, async (chunk) => {
|
|
40
35
|
const batchWriteParams = {
|
|
41
36
|
RequestItems: {
|
|
42
37
|
[tableName]: chunk.map((Item) => ({ PutRequest: { Item } })),
|
|
43
38
|
},
|
|
44
39
|
};
|
|
45
|
-
|
|
46
|
-
maxRetries:
|
|
40
|
+
await (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.BatchWriteCommand(batchWriteParams)), `batchwrite ${processed}/${items.length}. size=${batchSize}`, {
|
|
41
|
+
maxRetries: opt?.maxRetries === undefined ? 3 : opt.maxRetries,
|
|
47
42
|
});
|
|
48
43
|
processed += chunk.length;
|
|
49
|
-
})
|
|
44
|
+
});
|
|
50
45
|
return { data: undefined };
|
|
51
46
|
}
|
|
52
47
|
catch (e) {
|
|
53
48
|
return { error: e.toString() };
|
|
54
49
|
}
|
|
55
|
-
}
|
|
50
|
+
};
|
|
56
51
|
exports.batchWrite = batchWrite;
|
|
57
|
-
const incrementDynamo =
|
|
58
|
-
var _b;
|
|
52
|
+
const incrementDynamo = async ({ tableName, pkName, pkValue, fieldName, incrementValue = 1, }) => {
|
|
59
53
|
const updateParams = {
|
|
60
54
|
TableName: tableName,
|
|
61
55
|
Key: { [pkName]: pkValue },
|
|
@@ -69,22 +63,21 @@ const incrementDynamo = (_a) => __awaiter(void 0, [_a], void 0, function* ({ tab
|
|
|
69
63
|
ReturnValues: 'UPDATED_NEW',
|
|
70
64
|
};
|
|
71
65
|
try {
|
|
72
|
-
const res =
|
|
66
|
+
const res = await (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.UpdateCommand(updateParams)), 'incrementDynamo');
|
|
73
67
|
if (res.$metadata.httpStatusCode !== 200) {
|
|
74
68
|
return { error: res.toString() };
|
|
75
69
|
}
|
|
76
70
|
// Extract the updated value from the response
|
|
77
|
-
const updatedValue =
|
|
71
|
+
const updatedValue = res.Attributes?.[fieldName];
|
|
78
72
|
return { data: updatedValue };
|
|
79
73
|
}
|
|
80
74
|
catch (e) {
|
|
81
75
|
return { error: e.toString() };
|
|
82
76
|
}
|
|
83
|
-
}
|
|
77
|
+
};
|
|
84
78
|
exports.incrementDynamo = incrementDynamo;
|
|
85
79
|
const getDynamoUpdates = (item, options) => {
|
|
86
|
-
|
|
87
|
-
const excludeKeys = ((_a = options === null || options === void 0 ? void 0 : options.excludeKeys) !== null && _a !== void 0 ? _a : ['PK']).map((k) => k.toLowerCase());
|
|
80
|
+
const excludeKeys = (options?.excludeKeys ?? ['PK']).map((k) => k.toLowerCase());
|
|
88
81
|
const validEntries = Object.entries(item).filter(([key, value]) => !excludeKeys.includes(key.toLowerCase()) && value != null);
|
|
89
82
|
const ExpressionAttributeNames = {};
|
|
90
83
|
const ExpressionAttributeValues = {};
|
|
@@ -5,11 +5,11 @@ const log_1 = require("../../common/helpers/log");
|
|
|
5
5
|
const math_1 = require("../../common/helpers/math");
|
|
6
6
|
const json_1 = require("../../common/helpers/string/json");
|
|
7
7
|
const trim_1 = require("../../common/helpers/string/trim");
|
|
8
|
-
const extractSum = ({ str, regex }) =>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
const extractSum = ({ str, regex }) => (0, math_1.sumArray)(str
|
|
9
|
+
.match(regex)
|
|
10
|
+
?.map((s2) => (0, trim_1.trim)(s2.substring(s2.indexOf(':') + 1), ':', ',', ' '))
|
|
11
|
+
.filter((r) => r && Number(r))
|
|
12
|
+
.map((r) => Number(r)) ?? []);
|
|
13
13
|
/** ensure that dynamo tables in stack dont exceed passed in provisioned limits */
|
|
14
14
|
const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 25, mustEqual = false, }) => {
|
|
15
15
|
if (tables.length === 0) {
|
|
@@ -19,8 +19,7 @@ const addToBlocklist = (apiKey, service) => {
|
|
|
19
19
|
};
|
|
20
20
|
// Get available API keys from environment (internal use only)
|
|
21
21
|
const getApiKeys = () => {
|
|
22
|
-
|
|
23
|
-
return ((_a = process.env.GOOGLE_API_KEY) !== null && _a !== void 0 ? _a : '').split(',').filter(array_1.notEmpty);
|
|
22
|
+
return (process.env.GOOGLE_API_KEY ?? '').split(',').filter(array_1.notEmpty);
|
|
24
23
|
};
|
|
25
24
|
// Get available key+service combinations
|
|
26
25
|
const getAvailableCombinations = (service) => {
|