ag-common 0.0.463 → 0.0.465

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.
@@ -27,8 +27,9 @@ export declare const scan: <T>(tableName: string, opt?: {
27
27
  /** ProjectionExpression. will csv values */
28
28
  requiredAttributeList?: string[];
29
29
  }) => Promise<{
30
- data?: T[] | undefined;
31
- error?: string | undefined;
30
+ data: T[];
31
+ } | {
32
+ error: string;
32
33
  }>;
33
34
  export declare const getItemsDynamo: <T>({ tableName, items, }: {
34
35
  items: {
@@ -37,21 +38,24 @@ export declare const getItemsDynamo: <T>({ tableName, items, }: {
37
38
  }[];
38
39
  tableName: string;
39
40
  }) => Promise<{
40
- data?: T[] | undefined;
41
- error?: string | undefined;
41
+ data: T[];
42
+ } | {
43
+ error: string;
42
44
  }>;
43
45
  export declare const getItemDynamo: <T>({ tableName, pkName, pkValue, }: {
44
46
  pkName: string;
45
47
  pkValue: string;
46
48
  tableName: string;
47
49
  }) => Promise<{
48
- data?: T | undefined;
49
- error?: string | undefined;
50
+ data: T;
51
+ } | {
52
+ error: string;
50
53
  }>;
51
54
  export declare const queryDynamo: <T>({ tableName, pkName, pkValue, pkOperator, skName, skValue, skOperator, indexName, count, startKeyPk, filterName, filterValue, filterOperator, sortAscending, }: IQueryDynamo) => Promise<{
52
- data?: T[] | undefined;
55
+ data: T[];
53
56
  startKey?: Key | undefined;
54
- error?: string | undefined;
57
+ } | {
58
+ error: string;
55
59
  }>;
56
60
  export declare const getDynamoTtlDays: (days: number) => number;
57
61
  export declare const getDynamoTtlMinutes: (mins: number) => number;
@@ -193,13 +193,15 @@ const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void
193
193
  });
194
194
  exports.getItemsDynamo = getItemsDynamo;
195
195
  const getItemDynamo = ({ tableName, pkName, pkValue, }) => __awaiter(void 0, void 0, void 0, function* () {
196
- var _c;
197
196
  let r = yield (0, exports.getItemsDynamo)({ tableName, items: [{ pkName, pkValue }] });
198
- return { data: (_c = r.data) === null || _c === void 0 ? void 0 : _c[0], error: r.error };
197
+ if ('error' in r) {
198
+ return { error: r.error };
199
+ }
200
+ return { data: r.data[0] };
199
201
  });
200
202
  exports.getItemDynamo = getItemDynamo;
201
203
  const queryDynamo = ({ tableName, pkName, pkValue, pkOperator = '=', skName, skValue, skOperator = '=', indexName, count = 1000, startKeyPk, filterName, filterValue, filterOperator = '=', sortAscending = true, }) => __awaiter(void 0, void 0, void 0, function* () {
202
- var _d;
204
+ var _c;
203
205
  let kce = `#${pkName.toLowerCase()} ${pkOperator} :${pkName.toLowerCase()}`;
204
206
  const ean = { [`#${pkName.toLowerCase()}`]: pkName };
205
207
  const eav = {
@@ -268,11 +270,11 @@ const queryDynamo = ({ tableName, pkName, pkValue, pkOperator = '=', skName, skV
268
270
  }
269
271
  startKey = lek;
270
272
  (0, log_1.debug)(`dynamo query against ${params === null || params === void 0 ? void 0 : params.input.TableName} ok, count=${newItems === null || newItems === void 0 ? void 0 : newItems.length} ${JSON.stringify(params)}`, ` next startkey=${startKey}`);
271
- if (count > 0 && ((_d = newItems === null || newItems === void 0 ? void 0 : newItems.length) !== null && _d !== void 0 ? _d : 0) >= count) {
273
+ if (count > 0 && ((_c = newItems === null || newItems === void 0 ? void 0 : newItems.length) !== null && _c !== void 0 ? _c : 0) >= count) {
272
274
  return { data: Items, startKey };
273
275
  }
274
276
  } while (startKey && Object.keys(startKey).length > 0);
275
- return { data: Items, startKey: undefined };
277
+ return { data: Items };
276
278
  });
277
279
  exports.queryDynamo = queryDynamo;
278
280
  const getDynamoTtlDays = (days) => Math.ceil(new Date().getTime() / 1000) + days * 86400;
@@ -280,7 +282,7 @@ exports.getDynamoTtlDays = getDynamoTtlDays;
280
282
  const getDynamoTtlMinutes = (mins) => Math.ceil(new Date().getTime() / 1000) + mins * 60;
281
283
  exports.getDynamoTtlMinutes = getDynamoTtlMinutes;
282
284
  const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* () {
283
- var _e, _f;
285
+ var _d;
284
286
  try {
285
287
  let infoV = yield exports.dynamoDb.send(new client_dynamodb_1.DescribeTableCommand({ TableName: tableName }));
286
288
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -289,8 +291,12 @@ const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* ()
289
291
  if (!keyHash) {
290
292
  throw new Error('couldnt find keyHash');
291
293
  }
294
+ let allraw = yield (0, exports.scan)(tableName);
295
+ if ('error' in allraw) {
296
+ throw allraw.error;
297
+ }
292
298
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
293
- let all = ((_f = (_e = (yield (0, exports.scan)(tableName))) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.map((d) => d)) || [];
299
+ let all = ((_d = allraw === null || allraw === void 0 ? void 0 : allraw.data) === null || _d === void 0 ? void 0 : _d.map((d) => d)) || [];
294
300
  (0, log_1.warn)(`will delete ${all === null || all === void 0 ? void 0 : all.length} items from ${tableName}`);
295
301
  yield (0, exports.batchDelete)({
296
302
  tableName,
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.463",
2
+ "version": "0.0.465",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
@@ -52,7 +52,7 @@
52
52
  "@types/react": "18.2.17",
53
53
  "@types/react-dom": "18.2.7",
54
54
  "cross-env": "7.0.3",
55
- "eslint-config-e7npm": "0.0.13",
55
+ "eslint-config-e7npm": "0.0.14",
56
56
  "jest": "^29.6.2",
57
57
  "rimraf": "5.0.1",
58
58
  "storybook": "7.1.1",