ag-common 0.0.722 → 0.0.724
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/dynamo.js +33 -17
- package/dist/api/helpers/s3.d.ts +3 -1
- package/dist/api/helpers/s3.js +2 -2
- package/package.json +1 -1
|
@@ -156,26 +156,42 @@ const batchDelete = (_a) => __awaiter(void 0, [_a], void 0, function* ({ tableNa
|
|
|
156
156
|
});
|
|
157
157
|
exports.batchDelete = batchDelete;
|
|
158
158
|
const scan = (tableName, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
159
|
+
var _b, _c;
|
|
159
160
|
try {
|
|
160
161
|
let ExclusiveStartKey;
|
|
161
162
|
let Items = [];
|
|
163
|
+
// Handle projection attributes
|
|
164
|
+
const projectionAttrs = (_b = opt === null || opt === void 0 ? void 0 : opt.requiredAttributeList) === null || _b === void 0 ? void 0 : _b.reduce((acc, attr, index) => {
|
|
165
|
+
const escapedName = `#proj${index}`;
|
|
166
|
+
acc[escapedName] = attr;
|
|
167
|
+
return acc;
|
|
168
|
+
}, {});
|
|
169
|
+
// Merge projection attribute names with filter attribute names
|
|
170
|
+
const expressionAttributeNames = Object.assign(Object.assign({}, projectionAttrs), (_c = opt === null || opt === void 0 ? void 0 : opt.filter) === null || _c === void 0 ? void 0 : _c.attrNames);
|
|
162
171
|
do {
|
|
163
|
-
|
|
172
|
+
const params = new lib_dynamodb_1.ScanCommand(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ TableName: tableName }, ((opt === null || opt === void 0 ? void 0 : opt.filter) && Object.assign({ FilterExpression: opt.filter.filterExpression }, (opt.filter.attrValues && {
|
|
164
173
|
ExpressionAttributeValues: opt.filter.attrValues,
|
|
165
|
-
})))), ((
|
|
166
|
-
|
|
167
|
-
})),
|
|
174
|
+
})))), (Object.keys(expressionAttributeNames).length > 0 && {
|
|
175
|
+
ExpressionAttributeNames: expressionAttributeNames,
|
|
176
|
+
})), ((opt === null || opt === void 0 ? void 0 : opt.requiredAttributeList) && {
|
|
177
|
+
ProjectionExpression: opt.requiredAttributeList
|
|
178
|
+
.map((_, index) => `#proj${index}`)
|
|
179
|
+
.join(', '),
|
|
180
|
+
})), { ExclusiveStartKey }), (((opt === null || opt === void 0 ? void 0 : opt.limit) && Items.length < opt.limit) && {
|
|
181
|
+
Limit: opt.limit - Items.length
|
|
182
|
+
})));
|
|
168
183
|
(0, log_1.debug)(`running dynamo scan=${JSON.stringify(params, null, 2)}`);
|
|
169
|
-
const { Items:
|
|
170
|
-
// eslint-disable-next-line no-await-in-loop
|
|
171
|
-
} = yield exports.dynamoDb.send(params);
|
|
184
|
+
const { Items: newItems = [], LastEvaluatedKey, } = yield exports.dynamoDb.send(params);
|
|
172
185
|
ExclusiveStartKey = LastEvaluatedKey;
|
|
173
|
-
|
|
174
|
-
|
|
186
|
+
Items.push(...newItems);
|
|
187
|
+
// Break the loop if we've reached the limit
|
|
188
|
+
if ((opt === null || opt === void 0 ? void 0 : opt.limit) && Items.length >= opt.limit) {
|
|
189
|
+
break;
|
|
175
190
|
}
|
|
176
|
-
} while (ExclusiveStartKey
|
|
177
|
-
|
|
178
|
-
|
|
191
|
+
} while (ExclusiveStartKey);
|
|
192
|
+
// Ensure we don't return more items than the limit
|
|
193
|
+
if ((opt === null || opt === void 0 ? void 0 : opt.limit) && Items.length > opt.limit) {
|
|
194
|
+
Items = Items.slice(0, opt.limit);
|
|
179
195
|
}
|
|
180
196
|
(0, log_1.debug)(`dynamo scan against ${tableName} ok, count=${Items.length}`);
|
|
181
197
|
return { data: Items };
|
|
@@ -186,8 +202,8 @@ const scan = (tableName, opt) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
186
202
|
}
|
|
187
203
|
});
|
|
188
204
|
exports.scan = scan;
|
|
189
|
-
const getItemsDynamo = (
|
|
190
|
-
var
|
|
205
|
+
const getItemsDynamo = (_d) => __awaiter(void 0, [_d], void 0, function* ({ tableName, items, }) {
|
|
206
|
+
var _e, _f;
|
|
191
207
|
const params = new lib_dynamodb_1.BatchGetCommand({
|
|
192
208
|
RequestItems: {
|
|
193
209
|
[tableName]: {
|
|
@@ -199,7 +215,7 @@ const getItemsDynamo = (_b) => __awaiter(void 0, [_b], void 0, function* ({ tabl
|
|
|
199
215
|
});
|
|
200
216
|
try {
|
|
201
217
|
let res = yield exports.dynamoDb.send(params);
|
|
202
|
-
let data = (
|
|
218
|
+
let data = (_f = (_e = res.Responses) === null || _e === void 0 ? void 0 : _e[tableName].map((r) => r)) !== null && _f !== void 0 ? _f : [];
|
|
203
219
|
return { data };
|
|
204
220
|
}
|
|
205
221
|
catch (e) {
|
|
@@ -209,7 +225,7 @@ const getItemsDynamo = (_b) => __awaiter(void 0, [_b], void 0, function* ({ tabl
|
|
|
209
225
|
}
|
|
210
226
|
});
|
|
211
227
|
exports.getItemsDynamo = getItemsDynamo;
|
|
212
|
-
const getItemDynamo = (
|
|
228
|
+
const getItemDynamo = (_g) => __awaiter(void 0, [_g], void 0, function* ({ tableName, pkName, pkValue, }) {
|
|
213
229
|
let r = yield (0, exports.getItemsDynamo)({ tableName, items: [{ pkName, pkValue }] });
|
|
214
230
|
if ('error' in r) {
|
|
215
231
|
return { error: r.error };
|
|
@@ -217,7 +233,7 @@ const getItemDynamo = (_e) => __awaiter(void 0, [_e], void 0, function* ({ table
|
|
|
217
233
|
return { data: r.data[0] };
|
|
218
234
|
});
|
|
219
235
|
exports.getItemDynamo = getItemDynamo;
|
|
220
|
-
const queryDynamo = (
|
|
236
|
+
const queryDynamo = (_h) => __awaiter(void 0, [_h], void 0, function* ({ tableName, pkName, pkValue, pkOperator = '=', skName, skValue, skOperator = '=', indexName, limit = 1000, startKey, filterName, filterValue, filterOperator = '=', sortAscending = true, }) {
|
|
221
237
|
let kce = `#${pkName.toLowerCase()} ${pkOperator} :${pkName.toLowerCase()}`;
|
|
222
238
|
const ean = { [`#${pkName.toLowerCase()}`]: pkName };
|
|
223
239
|
const eav = {
|
package/dist/api/helpers/s3.d.ts
CHANGED
|
@@ -30,11 +30,13 @@ export declare function getS3Objects({ bucket, keys, }: {
|
|
|
30
30
|
data: IS3Object;
|
|
31
31
|
error?: undefined;
|
|
32
32
|
}, void, unknown>;
|
|
33
|
-
export declare const putS3Object: ({ Body, Bucket, Key, ContentType, }: {
|
|
33
|
+
export declare const putS3Object: ({ Body, Bucket, Key, ContentType, CacheControl, }: {
|
|
34
34
|
ContentType?: string;
|
|
35
35
|
Body: string | Blob | Buffer;
|
|
36
36
|
Bucket: string;
|
|
37
37
|
Key: string;
|
|
38
|
+
/** default public, max-age=300 */
|
|
39
|
+
CacheControl?: string;
|
|
38
40
|
}) => Promise<{
|
|
39
41
|
error?: string;
|
|
40
42
|
}>;
|
package/dist/api/helpers/s3.js
CHANGED
|
@@ -74,9 +74,9 @@ function getS3Objects(_a) {
|
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
exports.getS3Objects = getS3Objects;
|
|
77
|
-
const putS3Object = (_b) => __awaiter(void 0, [_b], void 0, function* ({ Body, Bucket, Key, ContentType, }) {
|
|
77
|
+
const putS3Object = (_b) => __awaiter(void 0, [_b], void 0, function* ({ Body, Bucket, Key, ContentType, CacheControl = 'public, max-age=300', }) {
|
|
78
78
|
try {
|
|
79
|
-
yield exports.s3.send(new client_s3_1.PutObjectCommand({ Body, Bucket, Key, ContentType }));
|
|
79
|
+
yield exports.s3.send(new client_s3_1.PutObjectCommand({ Body, Bucket, Key, ContentType, CacheControl }));
|
|
80
80
|
return {};
|
|
81
81
|
}
|
|
82
82
|
catch (e) {
|
package/package.json
CHANGED