ag-common 0.0.746 → 0.0.748

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.
@@ -6,8 +6,8 @@ export declare const batchDelete: (params: {
6
6
  opt?: {
7
7
  /** default 20 */
8
8
  batchSize?: number;
9
- /** option to always retry on 429 until done. default false */
10
- alwaysRetry?: boolean;
9
+ /** option to control retry behavior: undefined = 3 retries, null = infinite. default 3 */
10
+ maxRetries?: number | null;
11
11
  };
12
12
  }) => Promise<DynamoDBResult<void>>;
13
13
  export declare const wipeTable: (tableName: string) => Promise<DynamoDBResult<void>>;
@@ -26,7 +26,7 @@ const get_1 = require("./get");
26
26
  const batchDelete = (params) => __awaiter(void 0, void 0, void 0, function* () {
27
27
  var _a;
28
28
  try {
29
- const { batchSize = 20, alwaysRetry = false } = (_a = params.opt) !== null && _a !== void 0 ? _a : {};
29
+ const { batchSize = 20, maxRetries } = (_a = params.opt) !== null && _a !== void 0 ? _a : {};
30
30
  const chunked = (0, array_1.chunk)(params.keys, batchSize);
31
31
  let processed = 0;
32
32
  yield (0, async_1.asyncForEach)(chunked, (chunk) => __awaiter(void 0, void 0, void 0, function* () {
@@ -38,7 +38,7 @@ const batchDelete = (params) => __awaiter(void 0, void 0, void 0, function* () {
38
38
  },
39
39
  };
40
40
  yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.BatchWriteCommand(batchDeleteParams)), `batchdelete ${processed}/${params.keys.length}. size=${batchSize}`, {
41
- maxRetries: alwaysRetry ? null : undefined,
41
+ maxRetries: maxRetries === undefined ? 3 : maxRetries,
42
42
  });
43
43
  processed += chunk.length;
44
44
  }));
@@ -54,7 +54,7 @@ const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* ()
54
54
  try {
55
55
  const generator = (0, get_1.scanWithGenerator)(tableName, {
56
56
  BATCH_SIZE: 100, // Process in chunks of 100 items
57
- alwaysRetry: true, // Always retry on 429 since we want to ensure complete deletion
57
+ maxRetries: null, // Always retry on 429 since we want to ensure complete deletion
58
58
  });
59
59
  try {
60
60
  // Process each batch of items
@@ -69,7 +69,7 @@ const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* ()
69
69
  keys: pks,
70
70
  pkName: 'PK',
71
71
  opt: {
72
- alwaysRetry: true, // Always retry on 429 since we want to ensure complete deletion
72
+ maxRetries: null, // Always retry on 429 since we want to ensure complete deletion
73
73
  },
74
74
  });
75
75
  if ('error' in result) {
@@ -66,7 +66,7 @@ const executeQuery = (params, startKey) => __awaiter(void 0, void 0, void 0, fun
66
66
  ExpressionAttributeValues: Object.assign(Object.assign({}, eav), params.filter.attrValues),
67
67
  }))));
68
68
  return (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.QueryCommand(queryParams)), 'queryDynamo', {
69
- maxRetries: params.alwaysRetry ? null : undefined,
69
+ maxRetries: params.maxRetries === undefined ? 3 : params.maxRetries,
70
70
  });
71
71
  });
72
72
  /**
@@ -89,7 +89,7 @@ const executeScan = (tableName, options, exclusiveStartKey) => __awaiter(void 0,
89
89
  .join(', '),
90
90
  })), { ExclusiveStartKey: exclusiveStartKey });
91
91
  return (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.ScanCommand(scanParams)), `scan. already seen=${exclusiveStartKey ? 'some' : '0'} items`, {
92
- maxRetries: (options === null || options === void 0 ? void 0 : options.alwaysRetry) ? null : undefined,
92
+ maxRetries: (options === null || options === void 0 ? void 0 : options.maxRetries) === undefined ? 3 : options.maxRetries,
93
93
  });
94
94
  });
95
95
  const getItemsDynamo = (params) => __awaiter(void 0, void 0, void 0, function* () {
@@ -23,7 +23,7 @@ export declare const getItemDynamo: <T>(params: {
23
23
  export declare const putDynamo: <T extends Record<string, unknown>>(item: T, tableName: string, opt?: {
24
24
  pkName?: string;
25
25
  }) => Promise<import("./types").DynamoDBResult<void>>, batchWrite: <T extends Record<string, unknown>>(tableName: string, items: T[], opt?: {
26
- alwaysRetry?: boolean;
26
+ maxRetries?: number | null;
27
27
  batchSize?: number;
28
28
  }) => Promise<import("./types").DynamoDBResult<void>>, getDynamoUpdates: <T extends Record<string, unknown>>(item: T, options?: {
29
29
  excludeKeys?: string[];
@@ -39,7 +39,7 @@ export declare const batchDelete: (params: {
39
39
  pkName: string;
40
40
  opt?: {
41
41
  batchSize?: number;
42
- alwaysRetry?: boolean;
42
+ maxRetries?: number | null;
43
43
  };
44
44
  }) => Promise<import("./types").DynamoDBResult<void>>, wipeTable: (tableName: string) => Promise<import("./types").DynamoDBResult<void>>;
45
45
  export * from './types';
@@ -3,8 +3,8 @@ export declare const putDynamo: <T extends Record<string, unknown>>(item: T, tab
3
3
  pkName?: string;
4
4
  }) => Promise<DynamoDBResult<void>>;
5
5
  export declare const batchWrite: <T extends Record<string, unknown>>(tableName: string, items: T[], opt?: {
6
- /** option to always retry on 429 until done */
7
- alwaysRetry?: boolean;
6
+ /** option to control retry behavior: undefined = 3 retries, null = infinite */
7
+ maxRetries?: number | null;
8
8
  /** default 20 */
9
9
  batchSize?: number;
10
10
  }) => Promise<DynamoDBResult<void>>;
@@ -40,7 +40,7 @@ const batchWrite = (tableName, items, opt) => __awaiter(void 0, void 0, void 0,
40
40
  },
41
41
  };
42
42
  yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.BatchWriteCommand(batchWriteParams)), `batchwrite ${processed}/${items.length}. size=${batchSize}`, {
43
- maxRetries: (opt === null || opt === void 0 ? void 0 : opt.alwaysRetry) ? null : undefined,
43
+ maxRetries: (opt === null || opt === void 0 ? void 0 : opt.maxRetries) === undefined ? 3 : opt.maxRetries,
44
44
  });
45
45
  processed += chunk.length;
46
46
  }));
@@ -23,7 +23,7 @@ export interface ScanOptions {
23
23
  filter?: DynamoFilter;
24
24
  requiredAttributeList?: string[];
25
25
  indexName?: string;
26
- alwaysRetry?: boolean;
26
+ maxRetries?: number | null;
27
27
  }
28
28
  export interface DynamoQueryParams {
29
29
  tableName: string;
@@ -37,7 +37,7 @@ export interface DynamoQueryParams {
37
37
  limit?: number;
38
38
  filter?: DynamoFilter;
39
39
  sortAscending?: boolean;
40
- alwaysRetry?: boolean;
40
+ maxRetries?: number | null;
41
41
  }
42
42
  export interface DynamoBatchQueryParams {
43
43
  tableName: string;
@@ -128,7 +128,13 @@ function getS3Objects(_a) {
128
128
  }
129
129
  const putS3Object = (_a) => __awaiter(void 0, [_a], void 0, function* ({ Body, Bucket, Key, ContentType, CacheControl = 'public, max-age=300', }) {
130
130
  try {
131
- yield s3.send(new client_s3_1.PutObjectCommand({ Body, Bucket, Key, ContentType, CacheControl }));
131
+ const r = yield s3.send(new client_s3_1.PutObjectCommand({ Body, Bucket, Key, ContentType, CacheControl }));
132
+ const code = r.$metadata.httpStatusCode;
133
+ if (code !== 200) {
134
+ return {
135
+ error: `failed to upload file to s3. code=${code}. ${JSON.stringify(r.$metadata)}`,
136
+ };
137
+ }
132
138
  return {};
133
139
  }
134
140
  catch (e) {
@@ -50,16 +50,12 @@ const LineChart = (p) => {
50
50
  if (!tt && xTime) {
51
51
  tt = dateHelpers_1.timeTooltipTitle;
52
52
  }
53
- if (!tt) {
54
- tt = (s) => s.toString();
55
- }
53
+ tt !== null && tt !== void 0 ? tt : (tt = (s) => s.toString());
56
54
  let lt = p.legendTitle;
57
55
  if (!lt && xTime) {
58
56
  lt = dateHelpers_1.timeLegendTitle;
59
57
  }
60
- if (!lt) {
61
- lt = (s) => s.toString();
62
- }
58
+ lt !== null && lt !== void 0 ? lt : (lt = (s) => s.toString());
63
59
  const lt2 = lt;
64
60
  const tt2 = tt;
65
61
  const legendItems = (0, getLegendItems_1.getLegendItems)(Object.assign(Object.assign({ colours: p.colours, data: p.data, tt: tt2, lt: lt2 }, (_a = UT.pos) === null || _a === void 0 ? void 0 : _a.data), { fixed: false }));
@@ -33,12 +33,19 @@ const LegendY = ({ data, style, }) => {
33
33
  }
34
34
  items.push(maxY);
35
35
  const ch = maxY.toString().length;
36
+ const roundNumber = (num) => {
37
+ // Round to 2 decimal places and remove trailing zeros
38
+ const rounded = Math.round(num * 100) / 100;
39
+ return rounded % 1 === 0
40
+ ? rounded.toString()
41
+ : rounded.toFixed(2).replace(/\.?0+$/, '');
42
+ };
36
43
  return (react_1.default.createElement(Base, { style: Object.assign(Object.assign({}, style), { maxWidth: `${ch}ch`, paddingRight: '1ch' }) },
37
44
  react_1.default.createElement(Numbers, null, items.map((i, i2) => (react_1.default.createElement("span", {
38
45
  // eslint-disable-next-line react/no-array-index-key
39
46
  key: i + i2, style: {
40
47
  color: style.color,
41
48
  backgroundColor: style.backgroundColor,
42
- } }, i))))));
49
+ } }, roundNumber(i)))))));
43
50
  };
44
51
  exports.LegendY = LegendY;
@@ -34,18 +34,25 @@ const Total = styled_1.default.span `
34
34
  const TooltipContent = (p) => {
35
35
  var _a, _b;
36
36
  const name = p.tt((_b = (_a = p.selectedXs) === null || _a === void 0 ? void 0 : _a[0].x) !== null && _b !== void 0 ? _b : 0);
37
+ const roundNumber = (num) => {
38
+ // Round to 2 decimal places and remove trailing zeros
39
+ const rounded = Math.round(num * 100) / 100;
40
+ return rounded % 1 === 0
41
+ ? rounded.toString()
42
+ : rounded.toFixed(2).replace(/\.?0+$/, '');
43
+ };
37
44
  return (react_1.default.createElement(Base, { style: Object.assign(Object.assign({}, p.style), { border: `solid 1px ${p.style.borderColor}` }) },
38
45
  react_1.default.createElement(Title, null, name),
39
46
  react_1.default.createElement(Row, null,
40
47
  react_1.default.createElement("span", null, "total"),
41
- react_1.default.createElement(Total, null, p.legendItems.total)),
48
+ react_1.default.createElement(Total, null, roundNumber(p.legendItems.total))),
42
49
  p.legendItems.part.map((v) => (react_1.default.createElement(Row, { key: v.name + v.y, style: { color: v.colour } },
43
50
  react_1.default.createElement(ItemTitle, null, v.name),
44
- react_1.default.createElement(Total, null, v.y)))),
51
+ react_1.default.createElement(Total, null, roundNumber(v.y))))),
45
52
  p.legendItems.rest.length > 0 && (react_1.default.createElement(Row, null,
46
53
  react_1.default.createElement("span", null,
47
54
  p.legendItems.rest.length,
48
55
  " more"),
49
- react_1.default.createElement(Total, null, p.legendItems.restTotal)))));
56
+ react_1.default.createElement(Total, null, roundNumber(p.legendItems.restTotal))))));
50
57
  };
51
58
  exports.TooltipContent = TooltipContent;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.746",
2
+ "version": "0.0.748",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",