ag-common 0.0.754 → 0.0.755
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.
|
@@ -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