ag-common 0.0.629 → 0.0.631

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.
@@ -22,10 +22,12 @@ export declare const scan: <T>(tableName: string, opt?: {
22
22
  filter?: {
23
23
  filterExpression: string;
24
24
  attrNames: Record<string, string>;
25
- attrValues: Record<string, string>;
25
+ attrValues?: Record<string, string>;
26
26
  };
27
27
  /** ProjectionExpression. will csv values */
28
28
  requiredAttributeList?: string[];
29
+ /** default =ALL */
30
+ maxCount?: number;
29
31
  }) => Promise<{
30
32
  data: T[];
31
33
  } | {
@@ -143,17 +143,16 @@ const batchDelete = ({ tableName, keys, pkName, }) => __awaiter(void 0, void 0,
143
143
  });
144
144
  exports.batchDelete = batchDelete;
145
145
  const scan = (tableName, opt) => __awaiter(void 0, void 0, void 0, function* () {
146
+ var _a;
146
147
  try {
147
148
  let ExclusiveStartKey;
148
- const Items = [];
149
+ let Items = [];
149
150
  do {
150
- let params = new lib_dynamodb_1.ScanCommand(Object.assign(Object.assign(Object.assign({ TableName: tableName }, ((opt === null || opt === void 0 ? void 0 : opt.filter) && {
151
- FilterExpression: opt.filter.filterExpression,
152
- ExpressionAttributeNames: opt.filter.attrNames,
151
+ let params = new lib_dynamodb_1.ScanCommand(Object.assign(Object.assign(Object.assign({ TableName: tableName }, ((opt === null || opt === void 0 ? void 0 : opt.filter) && Object.assign({ FilterExpression: opt.filter.filterExpression, ExpressionAttributeNames: opt.filter.attrNames }, (opt.filter.attrValues && {
153
152
  ExpressionAttributeValues: opt.filter.attrValues,
154
- })), ((opt === null || opt === void 0 ? void 0 : opt.requiredAttributeList) && {
153
+ })))), ((opt === null || opt === void 0 ? void 0 : opt.requiredAttributeList) && {
155
154
  ProjectionExpression: opt.requiredAttributeList.join(', '),
156
- })), { ExclusiveStartKey }));
155
+ })), { ExclusiveStartKey, Limit: (_a = opt === null || opt === void 0 ? void 0 : opt.maxCount) !== null && _a !== void 0 ? _a : undefined }));
157
156
  (0, log_1.debug)(`running dynamo scan=${JSON.stringify(params, null, 2)}`);
158
157
  const { Items: newitems, LastEvaluatedKey,
159
158
  // eslint-disable-next-line no-await-in-loop
@@ -162,7 +161,11 @@ const scan = (tableName, opt) => __awaiter(void 0, void 0, void 0, function* ()
162
161
  if (newitems) {
163
162
  Items.push(...newitems.map((r) => r));
164
163
  }
165
- } while (ExclusiveStartKey);
164
+ } while (ExclusiveStartKey &&
165
+ (!(opt === null || opt === void 0 ? void 0 : opt.maxCount) || Items.length < opt.maxCount));
166
+ if (opt === null || opt === void 0 ? void 0 : opt.maxCount) {
167
+ ({ part: Items } = (0, array_1.take)(Items, opt === null || opt === void 0 ? void 0 : opt.maxCount));
168
+ }
166
169
  (0, log_1.debug)(`dynamo scan against ${tableName} ok, count=${Items === null || Items === void 0 ? void 0 : Items.length}`);
167
170
  return { data: Items };
168
171
  }
@@ -173,7 +176,7 @@ const scan = (tableName, opt) => __awaiter(void 0, void 0, void 0, function* ()
173
176
  });
174
177
  exports.scan = scan;
175
178
  const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void 0, function* () {
176
- var _a, _b;
179
+ var _b, _c;
177
180
  const params = new lib_dynamodb_1.BatchGetCommand({
178
181
  RequestItems: {
179
182
  [tableName]: {
@@ -185,7 +188,7 @@ const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void
185
188
  });
186
189
  try {
187
190
  let res = yield exports.dynamoDb.send(params);
188
- let data = (_b = (_a = res.Responses) === null || _a === void 0 ? void 0 : _a[tableName].map((r) => r)) !== null && _b !== void 0 ? _b : [];
191
+ let data = (_c = (_b = res.Responses) === null || _b === void 0 ? void 0 : _b[tableName].map((r) => r)) !== null && _c !== void 0 ? _c : [];
189
192
  return { data };
190
193
  }
191
194
  catch (e) {
@@ -204,7 +207,7 @@ const getItemDynamo = ({ tableName, pkName, pkValue, }) => __awaiter(void 0, voi
204
207
  });
205
208
  exports.getItemDynamo = getItemDynamo;
206
209
  const queryDynamo = ({ tableName, pkName, pkValue, pkOperator = '=', skName, skValue, skOperator = '=', indexName, count = 1000, startKey, filterName, filterValue, filterOperator = '=', sortAscending = true, }) => __awaiter(void 0, void 0, void 0, function* () {
207
- var _c;
210
+ var _d;
208
211
  let kce = `#${pkName.toLowerCase()} ${pkOperator} :${pkName.toLowerCase()}`;
209
212
  const ean = { [`#${pkName.toLowerCase()}`]: pkName };
210
213
  const eav = {
@@ -270,7 +273,7 @@ const queryDynamo = ({ tableName, pkName, pkValue, pkOperator = '=', skName, skV
270
273
  }
271
274
  startKey = lek;
272
275
  (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}`);
273
- if (count > 0 && ((_c = newItems === null || newItems === void 0 ? void 0 : newItems.length) !== null && _c !== void 0 ? _c : 0) >= count) {
276
+ if (count > 0 && ((_d = newItems === null || newItems === void 0 ? void 0 : newItems.length) !== null && _d !== void 0 ? _d : 0) >= count) {
274
277
  return { data: Items, startKey };
275
278
  }
276
279
  } while (startKey && Object.keys(startKey).length > 0);
@@ -282,7 +285,7 @@ exports.getDynamoTtlDays = getDynamoTtlDays;
282
285
  const getDynamoTtlMinutes = (mins) => Math.ceil(new Date().getTime() / 1000) + mins * 60;
283
286
  exports.getDynamoTtlMinutes = getDynamoTtlMinutes;
284
287
  const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* () {
285
- var _d;
288
+ var _e;
286
289
  try {
287
290
  let infoV = yield exports.dynamoDb.send(new client_dynamodb_1.DescribeTableCommand({ TableName: tableName }));
288
291
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -296,7 +299,7 @@ const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* ()
296
299
  throw allraw.error;
297
300
  }
298
301
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
299
- let all = ((_d = allraw === null || allraw === void 0 ? void 0 : allraw.data) === null || _d === void 0 ? void 0 : _d.map((d) => d)) || [];
302
+ let all = ((_e = allraw === null || allraw === void 0 ? void 0 : allraw.data) === null || _e === void 0 ? void 0 : _e.map((d) => d)) || [];
300
303
  (0, log_1.warn)(`will delete ${all === null || all === void 0 ? void 0 : all.length} items from ${tableName}`);
301
304
  yield (0, exports.batchDelete)({
302
305
  tableName,
@@ -54,10 +54,14 @@ const Timeline = ({ lineColour = '#ccc', items, onClick, maxCircleSize = 'min(5v
54
54
  react_1.default.createElement(Line, { style: { backgroundColor: lineColour } }),
55
55
  items.map((p, index) => {
56
56
  const enabled = index === lastTrue || index === firstFalse;
57
+ let cursor = enabled ? 'pointer' : 'default';
58
+ if (p.checked) {
59
+ cursor = '';
60
+ }
57
61
  return (react_1.default.createElement(Item, { key: p.key, title: p === null || p === void 0 ? void 0 : p.title },
58
62
  react_1.default.createElement(Icon_1.Icon, { style: {
59
63
  maxWidth: maxCircleSize,
60
- cursor: enabled ? 'pointer' : 'default',
64
+ cursor,
61
65
  }, onClick: () => enabled && (onClick === null || onClick === void 0 ? void 0 : onClick(p)) }, p.checked ? (react_1.default.createElement(icons_1.Checkmark, { style: { fill: '#60b515', backgroundColor: 'inherit' } })) : index !== firstFalse ? (react_1.default.createElement(Circle_1.Circle, { style: { fill: '#007cbb', backgroundColor: 'inherit' }, dotted: p.disabled })) : (react_1.default.createElement(icons_1.CircleDot, { style: { fill: '#007cbb', backgroundColor: 'inherit' } })))));
62
66
  })),
63
67
  showTitles && items.find((i) => i.title) && (react_1.default.createElement(Row, { style: { marginTop: '1rem' } }, items.map(({ title, key }) => (react_1.default.createElement(Title, { key: key, style: {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.629",
2
+ "version": "0.0.631",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
@@ -53,7 +53,7 @@
53
53
  "@storybook/react-webpack5": "7.6.16",
54
54
  "@storybook/theming": "7.6.16",
55
55
  "@types/jsonwebtoken": "9.0.5",
56
- "@types/node": "20.11.18",
56
+ "@types/node": "20.11.19",
57
57
  "@types/react": "18.2.55",
58
58
  "@types/react-dom": "18.2.19",
59
59
  "cross-env": "7.0.3",