ag-common 0.0.754 → 0.0.756
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.
|
@@ -25,7 +25,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.batchQueryDynamo = exports.scan = exports.queryDynamo = exports.getItemDynamo = exports.getItemsDynamo = void 0;
|
|
26
26
|
exports.queryWithGenerator = queryWithGenerator;
|
|
27
27
|
exports.scanWithGenerator = scanWithGenerator;
|
|
28
|
-
/* eslint-disable no-await-in-loop */
|
|
29
28
|
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
30
29
|
const withRetry_1 = require("../withRetry");
|
|
31
30
|
const _1 = require(".");
|
|
@@ -65,7 +64,7 @@ const executeQuery = (params, startKey) => __awaiter(void 0, void 0, void 0, fun
|
|
|
65
64
|
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
65
|
ExpressionAttributeValues: Object.assign(Object.assign({}, eav), params.filter.attrValues),
|
|
67
66
|
}))));
|
|
68
|
-
return (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.QueryCommand(queryParams)), 'queryDynamo', {
|
|
67
|
+
return (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.QueryCommand(queryParams)), 'queryDynamo:' + JSON.stringify(queryParams), {
|
|
69
68
|
maxRetries: params.maxRetries === undefined ? 3 : params.maxRetries,
|
|
70
69
|
});
|
|
71
70
|
});
|
|
@@ -104,7 +103,7 @@ const getItemsDynamo = (params) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
104
103
|
},
|
|
105
104
|
},
|
|
106
105
|
};
|
|
107
|
-
const result = yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.BatchGetCommand(batchGetParams)), 'getItemsDynamo');
|
|
106
|
+
const result = yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.BatchGetCommand(batchGetParams)), 'getItemsDynamo:' + JSON.stringify(batchGetParams));
|
|
108
107
|
return {
|
|
109
108
|
data: (_b = (_a = result.Responses) === null || _a === void 0 ? void 0 : _a[params.tableName]) !== null && _b !== void 0 ? _b : [],
|
|
110
109
|
};
|
|
@@ -279,7 +278,7 @@ const executePartiQLQuery = (params) => __awaiter(void 0, void 0, void 0, functi
|
|
|
279
278
|
Limit: params.limit,
|
|
280
279
|
NextToken: nextToken,
|
|
281
280
|
};
|
|
282
|
-
const result = yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.ExecuteStatementCommand(executeParams)), 'batchQueryDynamo', {
|
|
281
|
+
const result = yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.ExecuteStatementCommand(executeParams)), 'batchQueryDynamo:' + JSON.stringify(executeParams), {
|
|
283
282
|
maxRetries: params.maxRetries === undefined ? 3 : params.maxRetries,
|
|
284
283
|
});
|
|
285
284
|
if (result.Items) {
|
|
@@ -8,6 +8,13 @@ export declare const batchWrite: <T extends Record<string, unknown>>(tableName:
|
|
|
8
8
|
/** default 20 */
|
|
9
9
|
batchSize?: number;
|
|
10
10
|
}) => Promise<DynamoDBResult<void>>;
|
|
11
|
+
export declare const incrementDynamo: ({ tableName, pkName, pkValue, fieldName, incrementValue, }: {
|
|
12
|
+
tableName: string;
|
|
13
|
+
pkName: string;
|
|
14
|
+
pkValue: unknown;
|
|
15
|
+
fieldName: string;
|
|
16
|
+
incrementValue: number;
|
|
17
|
+
}) => Promise<DynamoDBResult<number>>;
|
|
11
18
|
export declare const getDynamoUpdates: <T extends Record<string, unknown>>(item: T, options?: {
|
|
12
19
|
excludeKeys?: string[];
|
|
13
20
|
}) => {
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getDynamoUpdates = exports.batchWrite = exports.putDynamo = void 0;
|
|
12
|
+
exports.getDynamoUpdates = exports.incrementDynamo = exports.batchWrite = exports.putDynamo = void 0;
|
|
13
13
|
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
14
14
|
const array_1 = require("../../../common/helpers/array");
|
|
15
15
|
const async_1 = require("../../../common/helpers/async");
|
|
@@ -54,6 +54,34 @@ const batchWrite = (tableName, items, opt) => __awaiter(void 0, void 0, void 0,
|
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
exports.batchWrite = batchWrite;
|
|
57
|
+
const incrementDynamo = (_a) => __awaiter(void 0, [_a], void 0, function* ({ tableName, pkName, pkValue, fieldName, incrementValue = 1, }) {
|
|
58
|
+
var _b;
|
|
59
|
+
const updateParams = {
|
|
60
|
+
TableName: tableName,
|
|
61
|
+
Key: { [pkName]: pkValue },
|
|
62
|
+
UpdateExpression: `ADD #field :increment`,
|
|
63
|
+
ExpressionAttributeNames: {
|
|
64
|
+
'#field': fieldName,
|
|
65
|
+
},
|
|
66
|
+
ExpressionAttributeValues: {
|
|
67
|
+
':increment': incrementValue,
|
|
68
|
+
},
|
|
69
|
+
ReturnValues: 'UPDATED_NEW',
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
const res = yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.UpdateCommand(updateParams)), 'incrementDynamo');
|
|
73
|
+
if (res.$metadata.httpStatusCode !== 200) {
|
|
74
|
+
return { error: res.toString() };
|
|
75
|
+
}
|
|
76
|
+
// Extract the updated value from the response
|
|
77
|
+
const updatedValue = (_b = res.Attributes) === null || _b === void 0 ? void 0 : _b[fieldName];
|
|
78
|
+
return { data: updatedValue };
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
return { error: e.toString() };
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
exports.incrementDynamo = incrementDynamo;
|
|
57
85
|
const getDynamoUpdates = (item, options) => {
|
|
58
86
|
var _a;
|
|
59
87
|
const excludeKeys = ((_a = options === null || options === void 0 ? void 0 : options.excludeKeys) !== null && _a !== void 0 ? _a : ['PK']).map((k) => k.toLowerCase());
|
package/package.json
CHANGED