@factorearth/recordmiddleware-dataaccesslayer 0.0.1-y.3 → 0.0.1-y.32

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.
Files changed (44) hide show
  1. package/dist/aws-services.js +7 -5
  2. package/dist/batchDeleteItems.js +87 -27
  3. package/dist/batchGetItems.js +93 -22
  4. package/dist/batchPutItems.js +87 -27
  5. package/dist/chunkBatch.js +8 -6
  6. package/dist/deleteItem.js +70 -17
  7. package/dist/getItem.js +100 -37
  8. package/dist/index.js +29 -11
  9. package/dist/putItem.js +69 -16
  10. package/dist/updateItem.js +69 -16
  11. package/dist/utils.js +16 -0
  12. package/package.json +37 -31
  13. package/dist/aws-services.d.ts +0 -2
  14. package/dist/aws-services.js.map +0 -1
  15. package/dist/batchDeleteItems.d.ts +0 -2
  16. package/dist/batchDeleteItems.js.map +0 -1
  17. package/dist/batchGetItems.d.ts +0 -2
  18. package/dist/batchGetItems.js.map +0 -1
  19. package/dist/batchPutItems.d.ts +0 -2
  20. package/dist/batchPutItems.js.map +0 -1
  21. package/dist/chunkBatch.d.ts +0 -7
  22. package/dist/chunkBatch.js.map +0 -1
  23. package/dist/deleteItem.d.ts +0 -1
  24. package/dist/deleteItem.js.map +0 -1
  25. package/dist/getItem.d.ts +0 -2
  26. package/dist/getItem.js.map +0 -1
  27. package/dist/index.d.ts +0 -13
  28. package/dist/index.js.map +0 -1
  29. package/dist/putItem.d.ts +0 -1
  30. package/dist/putItem.js.map +0 -1
  31. package/dist/updateItem.d.ts +0 -1
  32. package/dist/updateItem.js.map +0 -1
  33. package/lib/aws-services.ts +0 -5
  34. package/lib/batchDeleteItems.ts +0 -29
  35. package/lib/batchGetItems.ts +0 -24
  36. package/lib/batchPutItems.ts +0 -29
  37. package/lib/chunkBatch.ts +0 -27
  38. package/lib/deleteItem.ts +0 -18
  39. package/lib/getItem.ts +0 -42
  40. package/lib/index.ts +0 -15
  41. package/lib/putItem.ts +0 -17
  42. package/lib/updateItem.ts +0 -17
  43. package/tsconfig.json +0 -27
  44. package/tsconfig.tsbuildinfo +0 -1
@@ -1,5 +1,7 @@
1
- import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
2
- import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
3
- const dynamoDbClient = new DynamoDBClient();
4
- export const dynamoDbDocClient = DynamoDBDocumentClient.from(dynamoDbClient);
5
- //# sourceMappingURL=aws-services.js.map
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dynamoDbDocClient = void 0;
4
+ var client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
5
+ var lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
6
+ var dynamoDbClient = new client_dynamodb_1.DynamoDBClient();
7
+ exports.dynamoDbDocClient = lib_dynamodb_1.DynamoDBDocumentClient.from(dynamoDbClient);
@@ -1,30 +1,90 @@
1
- import { BatchWriteCommand } from "@aws-sdk/lib-dynamodb";
2
- import { dynamoDbDocClient } from "aws-services";
3
- import chunkBatch from "chunkBatch";
4
- import { MAX_ITEMS_BATCH_OPERATIONS } from "index";
5
- export async function batchDeleteItems(items, tableName) {
6
- const chunks = chunkBatch(items, MAX_ITEMS_BATCH_OPERATIONS);
7
- for (const chunk of chunks) {
8
- const deleteRequests = chunk.map((id) => {
9
- return {
10
- DeleteRequest: {
11
- Key: { id }
12
- }
13
- };
14
- });
15
- const commandInput = {
16
- RequestItems: {
17
- [tableName]: deleteRequests
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 __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
18
32
  }
19
- };
20
- const command = new BatchWriteCommand(commandInput);
21
- try {
22
- await dynamoDbDocClient.send(command);
23
- }
24
- catch (err) {
25
- console.error(`ERROR BATCH DELETING FROM TABLE ${tableName}`, err);
26
- console.log('IDS', deleteRequests);
27
- }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
28
36
  }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.batchDeleteItems = void 0;
40
+ var lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
41
+ var aws_services_js_1 = require("./aws-services.js");
42
+ var chunkBatch_js_1 = require("./chunkBatch.js");
43
+ var index_js_1 = require("./index.js");
44
+ function batchDeleteItems(items, tableName) {
45
+ return __awaiter(this, void 0, void 0, function () {
46
+ var chunks, _i, chunks_1, chunk, deleteRequests, commandInput, command, err_1;
47
+ var _a;
48
+ return __generator(this, function (_b) {
49
+ switch (_b.label) {
50
+ case 0:
51
+ chunks = (0, chunkBatch_js_1.default)(items, index_js_1.MAX_ITEMS_BATCH_WRITE);
52
+ _i = 0, chunks_1 = chunks;
53
+ _b.label = 1;
54
+ case 1:
55
+ if (!(_i < chunks_1.length)) return [3 /*break*/, 6];
56
+ chunk = chunks_1[_i];
57
+ deleteRequests = chunk.map(function (id) {
58
+ return {
59
+ DeleteRequest: {
60
+ Key: { id: id }
61
+ }
62
+ };
63
+ });
64
+ commandInput = {
65
+ RequestItems: (_a = {},
66
+ _a[tableName] = deleteRequests,
67
+ _a)
68
+ };
69
+ command = new lib_dynamodb_1.BatchWriteCommand(commandInput);
70
+ _b.label = 2;
71
+ case 2:
72
+ _b.trys.push([2, 4, , 5]);
73
+ return [4 /*yield*/, aws_services_js_1.dynamoDbDocClient.send(command)];
74
+ case 3:
75
+ _b.sent();
76
+ return [3 /*break*/, 5];
77
+ case 4:
78
+ err_1 = _b.sent();
79
+ console.error("ERROR BATCH DELETING FROM TABLE ".concat(tableName), err_1);
80
+ console.log('IDS', deleteRequests);
81
+ return [3 /*break*/, 5];
82
+ case 5:
83
+ _i++;
84
+ return [3 /*break*/, 1];
85
+ case 6: return [2 /*return*/];
86
+ }
87
+ });
88
+ });
29
89
  }
30
- //# sourceMappingURL=batchDeleteItems.js.map
90
+ exports.batchDeleteItems = batchDeleteItems;
@@ -1,25 +1,96 @@
1
- import { BatchGetCommand } from "@aws-sdk/lib-dynamodb";
2
- import { dynamoDbDocClient } from "aws-services";
3
- export async function batchGetItems(ids, tableName) {
4
- const commandInput = {
5
- RequestItems: {
6
- [tableName]: {
7
- Keys: ids
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 __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
8
32
  }
9
- }
10
- };
11
- const command = new BatchGetCommand(commandInput);
12
- try {
13
- const sendResult = await dynamoDbDocClient.send(command);
14
- const items = sendResult.Responses?.[tableName];
15
- if (items)
16
- return items;
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
17
36
  }
18
- catch (err) {
19
- console.error(`ERROR BATCH GETTING ITEMS FROM ${tableName}`);
20
- console.error("IDS ", ids);
21
- console.error(err);
22
- }
23
- return [];
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.batchGetItems = void 0;
40
+ var lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
41
+ var aws_services_js_1 = require("./aws-services.js");
42
+ var chunkBatch_js_1 = require("./chunkBatch.js");
43
+ var index_js_1 = require("./index.js");
44
+ function batchGetItems(ids, tableName) {
45
+ return __awaiter(this, void 0, void 0, function () {
46
+ var chunks, finalItems, _i, chunks_1, chunk, commandInput, command, sendResult, items, _a, items_1, item, err_1;
47
+ var _b;
48
+ var _c;
49
+ return __generator(this, function (_d) {
50
+ switch (_d.label) {
51
+ case 0:
52
+ chunks = (0, chunkBatch_js_1.default)(ids, index_js_1.MAX_ITEMS_BATCH_READ);
53
+ finalItems = [];
54
+ _i = 0, chunks_1 = chunks;
55
+ _d.label = 1;
56
+ case 1:
57
+ if (!(_i < chunks_1.length)) return [3 /*break*/, 6];
58
+ chunk = chunks_1[_i];
59
+ commandInput = {
60
+ RequestItems: (_b = {},
61
+ _b[tableName] = {
62
+ Keys: chunk
63
+ },
64
+ _b)
65
+ };
66
+ command = new lib_dynamodb_1.BatchGetCommand(commandInput);
67
+ _d.label = 2;
68
+ case 2:
69
+ _d.trys.push([2, 4, , 5]);
70
+ return [4 /*yield*/, aws_services_js_1.dynamoDbDocClient.send(command)];
71
+ case 3:
72
+ sendResult = _d.sent();
73
+ items = (_c = sendResult.Responses) === null || _c === void 0 ? void 0 : _c[tableName];
74
+ if (items) {
75
+ for (_a = 0, items_1 = items; _a < items_1.length; _a++) {
76
+ item = items_1[_a];
77
+ finalItems.push(item);
78
+ }
79
+ }
80
+ ;
81
+ return [3 /*break*/, 5];
82
+ case 4:
83
+ err_1 = _d.sent();
84
+ console.error("ERROR BATCH GETTING ITEMS FROM ".concat(tableName));
85
+ console.error("IDS ", chunk);
86
+ console.error(err_1);
87
+ return [3 /*break*/, 5];
88
+ case 5:
89
+ _i++;
90
+ return [3 /*break*/, 1];
91
+ case 6: return [2 /*return*/, finalItems];
92
+ }
93
+ });
94
+ });
24
95
  }
25
- //# sourceMappingURL=batchGetItems.js.map
96
+ exports.batchGetItems = batchGetItems;
@@ -1,30 +1,90 @@
1
- import { BatchWriteCommand } from "@aws-sdk/lib-dynamodb";
2
- import { dynamoDbDocClient } from "./aws-services";
3
- import chunkBatch from "./chunkBatch";
4
- import { MAX_ITEMS_BATCH_OPERATIONS } from "index";
5
- export async function batchPutItems(items, tableName) {
6
- const chunks = chunkBatch(items, MAX_ITEMS_BATCH_OPERATIONS);
7
- for (const chunk of chunks) {
8
- const putRequests = chunk.map((Item) => {
9
- return {
10
- PutRequest: {
11
- Item
12
- }
13
- };
14
- });
15
- const commandInput = {
16
- RequestItems: {
17
- [tableName]: putRequests
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 __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
18
32
  }
19
- };
20
- const command = new BatchWriteCommand(commandInput);
21
- try {
22
- await dynamoDbDocClient.send(command);
23
- }
24
- catch (err) {
25
- console.error(`ERROR BATCH PUTTING DOCUMENTS IN ${tableName}`, err);
26
- console.error(`DOCUMENTS: `, putRequests);
27
- }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
28
36
  }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.batchPutItems = void 0;
40
+ var lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
41
+ var aws_services_js_1 = require("./aws-services.js");
42
+ var chunkBatch_js_1 = require("./chunkBatch.js");
43
+ var index_js_1 = require("./index.js");
44
+ function batchPutItems(items, tableName) {
45
+ return __awaiter(this, void 0, void 0, function () {
46
+ var chunks, _i, chunks_1, chunk, putRequests, commandInput, command, err_1;
47
+ var _a;
48
+ return __generator(this, function (_b) {
49
+ switch (_b.label) {
50
+ case 0:
51
+ chunks = (0, chunkBatch_js_1.default)(items, index_js_1.MAX_ITEMS_BATCH_WRITE);
52
+ _i = 0, chunks_1 = chunks;
53
+ _b.label = 1;
54
+ case 1:
55
+ if (!(_i < chunks_1.length)) return [3 /*break*/, 6];
56
+ chunk = chunks_1[_i];
57
+ putRequests = chunk.map(function (Item) {
58
+ return {
59
+ PutRequest: {
60
+ Item: Item
61
+ }
62
+ };
63
+ });
64
+ commandInput = {
65
+ RequestItems: (_a = {},
66
+ _a[tableName] = putRequests,
67
+ _a)
68
+ };
69
+ command = new lib_dynamodb_1.BatchWriteCommand(commandInput);
70
+ _b.label = 2;
71
+ case 2:
72
+ _b.trys.push([2, 4, , 5]);
73
+ return [4 /*yield*/, aws_services_js_1.dynamoDbDocClient.send(command)];
74
+ case 3:
75
+ _b.sent();
76
+ return [3 /*break*/, 5];
77
+ case 4:
78
+ err_1 = _b.sent();
79
+ console.error("ERROR BATCH PUTTING DOCUMENTS IN ".concat(tableName), err_1);
80
+ console.error("DOCUMENTS ", putRequests);
81
+ return [3 /*break*/, 5];
82
+ case 5:
83
+ _i++;
84
+ return [3 /*break*/, 1];
85
+ case 6: return [2 /*return*/];
86
+ }
87
+ });
88
+ });
29
89
  }
30
- //# sourceMappingURL=batchPutItems.js.map
90
+ exports.batchPutItems = batchPutItems;
@@ -1,14 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  /**
2
4
  * Given an array of items, this module chunks them out into smaller arrays of {@link itemMax} length
3
5
  * @param array An array of items that we want to divide into a subset of arrays
4
6
  * @param itemMax The maximum number of items that can be in each array
5
7
  * @returns An array of item arrays
6
8
  */
7
- export default function chunkBatch(array, itemMax) {
8
- const final = [];
9
- let chunk = [];
10
- for (let i = 0; i < array.length; i++) {
11
- const element = array[i];
9
+ function chunkBatch(array, itemMax) {
10
+ var final = [];
11
+ var chunk = [];
12
+ for (var i = 0; i < array.length; i++) {
13
+ var element = array[i];
12
14
  if (i !== 0 && (i % itemMax === 0)) {
13
15
  // Its the beginning of the next one
14
16
  final.push(chunk);
@@ -23,4 +25,4 @@ export default function chunkBatch(array, itemMax) {
23
25
  }
24
26
  return final;
25
27
  }
26
- //# sourceMappingURL=chunkBatch.js.map
28
+ exports.default = chunkBatch;
@@ -1,19 +1,72 @@
1
- import { DeleteCommand } from "@aws-sdk/lib-dynamodb";
2
- import { dynamoDbDocClient } from "aws-services";
3
- export async function deleteItem(id, tableName) {
4
- const commandInput = {
5
- TableName: tableName,
6
- Key: {
7
- id
8
- }
9
- };
10
- const command = new DeleteCommand(commandInput);
11
- try {
12
- await dynamoDbDocClient.send(command);
13
- }
14
- catch (err) {
15
- console.error(`ERROR DELETING DOCUMENT ${id} in ${tableName}`);
16
- console.error(err);
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 __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
17
36
  }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.deleteItem = void 0;
40
+ var lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
41
+ var aws_services_js_1 = require("./aws-services.js");
42
+ function deleteItem(id, tableName) {
43
+ return __awaiter(this, void 0, void 0, function () {
44
+ var commandInput, command, err_1;
45
+ return __generator(this, function (_a) {
46
+ switch (_a.label) {
47
+ case 0:
48
+ commandInput = {
49
+ TableName: tableName,
50
+ Key: {
51
+ id: id
52
+ }
53
+ };
54
+ command = new lib_dynamodb_1.DeleteCommand(commandInput);
55
+ _a.label = 1;
56
+ case 1:
57
+ _a.trys.push([1, 3, , 4]);
58
+ return [4 /*yield*/, aws_services_js_1.dynamoDbDocClient.send(command)];
59
+ case 2:
60
+ _a.sent();
61
+ return [3 /*break*/, 4];
62
+ case 3:
63
+ err_1 = _a.sent();
64
+ console.error("ERROR DELETING DOCUMENT ".concat(id, " in ").concat(tableName));
65
+ console.error(err_1);
66
+ return [3 /*break*/, 4];
67
+ case 4: return [2 /*return*/];
68
+ }
69
+ });
70
+ });
18
71
  }
19
- //# sourceMappingURL=deleteItem.js.map
72
+ exports.deleteItem = deleteItem;
package/dist/getItem.js CHANGED
@@ -1,40 +1,103 @@
1
- import { dynamoDbDocClient } from "./aws-services.js";
2
- import { GetCommand, QueryCommand } from "@aws-sdk/lib-dynamodb";
3
- export const getItem = async (id, tableName) => {
4
- const params = {
5
- TableName: tableName,
6
- Key: {
7
- id
8
- }
9
- };
10
- try {
11
- const data = await dynamoDbDocClient.send(new GetCommand(params));
12
- return data.Item;
13
- }
14
- catch (err) {
15
- console.error("Error", err);
16
- return null;
17
- }
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
+ });
18
10
  };
19
- export const getItemsByIndex = async (indexName, tableName, fk, expression) => {
20
- const params = {
21
- TableName: tableName,
22
- IndexName: indexName,
23
- KeyConditionExpression: `fk = :${expression}`,
24
- ExpressionAttributeNames: {
25
- "fk": `${expression}`
26
- },
27
- ExpressionAttributeValues: {
28
- "fkval": fk
29
- }
30
- };
31
- try {
32
- const data = await dynamoDbDocClient.send(new QueryCommand(params));
33
- return data.Items || [];
34
- }
35
- catch (err) {
36
- console.error("Error", err);
37
- return [];
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
38
36
  }
39
37
  };
40
- //# sourceMappingURL=getItem.js.map
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getItemsByIndex = exports.getItem = void 0;
40
+ var aws_services_js_1 = require("./aws-services.js");
41
+ var lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
42
+ var utils_js_1 = require("./utils.js");
43
+ var getItem = function (id, tableName) { return __awaiter(void 0, void 0, void 0, function () {
44
+ var params, data, err_1;
45
+ return __generator(this, function (_a) {
46
+ switch (_a.label) {
47
+ case 0:
48
+ params = {
49
+ TableName: tableName,
50
+ Key: {
51
+ id: id
52
+ }
53
+ };
54
+ _a.label = 1;
55
+ case 1:
56
+ _a.trys.push([1, 3, , 4]);
57
+ return [4 /*yield*/, aws_services_js_1.dynamoDbDocClient.send(new lib_dynamodb_1.GetCommand(params))];
58
+ case 2:
59
+ data = _a.sent();
60
+ return [2 /*return*/, data.Item];
61
+ case 3:
62
+ err_1 = _a.sent();
63
+ console.error("Error", err_1);
64
+ return [2 /*return*/, null];
65
+ case 4: return [2 /*return*/];
66
+ }
67
+ });
68
+ }); };
69
+ exports.getItem = getItem;
70
+ var getItemsByIndex = function (indexName, tableName, attributeValue, attribute, columns) { return __awaiter(void 0, void 0, void 0, function () {
71
+ var _a, expressionAttributeNames, columnsToReturn, params, data, err_2;
72
+ return __generator(this, function (_b) {
73
+ switch (_b.label) {
74
+ case 0:
75
+ _a = (0, utils_js_1._columnsAndAttributeToReturn)({ attribute: attribute, columns: columns }), expressionAttributeNames = _a.expressionAttributeNames, columnsToReturn = _a.columnsToReturn;
76
+ params = {
77
+ TableName: tableName,
78
+ IndexName: indexName,
79
+ KeyConditionExpression: "#fk = :fkval",
80
+ ExpressionAttributeNames: expressionAttributeNames,
81
+ ExpressionAttributeValues: {
82
+ ":fkval": attributeValue
83
+ }
84
+ };
85
+ if (columnsToReturn) {
86
+ params.ProjectionExpression = columnsToReturn;
87
+ }
88
+ _b.label = 1;
89
+ case 1:
90
+ _b.trys.push([1, 3, , 4]);
91
+ return [4 /*yield*/, aws_services_js_1.dynamoDbDocClient.send(new lib_dynamodb_1.QueryCommand(params))];
92
+ case 2:
93
+ data = _b.sent();
94
+ return [2 /*return*/, data.Items || []];
95
+ case 3:
96
+ err_2 = _b.sent();
97
+ console.error("Error", err_2);
98
+ return [2 /*return*/, []];
99
+ case 4: return [2 /*return*/];
100
+ }
101
+ });
102
+ }); };
103
+ exports.getItemsByIndex = getItemsByIndex;