ag-common 0.0.95 → 0.0.100

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.
@@ -1,4 +1,4 @@
1
- export declare const enforceDynamoProvisionCap: ({ tables, readsMax, writesMax, }: {
1
+ export declare const enforceDynamoProvisionCap: ({ tables, readsMax, writesMax, mustEqual, }: {
2
2
  tables: any[];
3
3
  /**
4
4
  * default 25
@@ -8,4 +8,8 @@ export declare const enforceDynamoProvisionCap: ({ tables, readsMax, writesMax,
8
8
  * default 25
9
9
  */
10
10
  writesMax?: number | undefined;
11
+ /**
12
+ * default false. if true, will throw if cap isnt met
13
+ */
14
+ mustEqual?: boolean | undefined;
11
15
  }) => void;
@@ -9,7 +9,7 @@ const extractSum = ({ str, regex }) => {
9
9
  return (0, math_1.sumArray)(((_a = str
10
10
  .match(regex)) === null || _a === void 0 ? void 0 : _a.map((s2) => (0, string_1.trim)(s2.substring(s2.indexOf(':') + 1), ':', ',', ' ')).filter((r) => r && Number(r)).map((r) => Number(r))) || []);
11
11
  };
12
- const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 25, }) => {
12
+ const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 25, mustEqual = false, }) => {
13
13
  if (!tables || tables.length === 0) {
14
14
  (0, log_1.warn)('error in dynamo FT enforce');
15
15
  return;
@@ -19,12 +19,13 @@ const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 25, }) =
19
19
  const s = (0, string_1.safeStringify)(t.node._children.Resource.node.scope);
20
20
  const reads = extractSum({ str: s, regex: /readCapacityUnits.*/gim });
21
21
  const writes = extractSum({ str: s, regex: /writeCapacityUnits.*/gim });
22
- if (reads > readsMax) {
23
- throw new Error(`dynamo table provisioned reads:${reads} greater than max:${readsMax}`);
22
+ (0, log_1.warn)(`dynamo table provisioned reads:${reads}/${readsMax}`);
23
+ (0, log_1.warn)(`dynamo table provisioned writes:${writes}/${writesMax}`);
24
+ if (reads > readsMax || writes > writesMax) {
25
+ throw new Error('exceeded dynamo provision cap');
24
26
  }
25
- if (writes > writesMax) {
26
- throw new Error(`dynamo table provisioned writes:${writes} greater than max:${writesMax}`);
27
+ if (mustEqual && (reads !== readsMax || writes !== writesMax)) {
28
+ throw new Error(`dynamo provision cap not met`);
27
29
  }
28
- (0, log_1.warn)(`dynamo provisioned total: R=${reads} W=${writes}`);
29
30
  };
30
31
  exports.enforceDynamoProvisionCap = enforceDynamoProvisionCap;
@@ -5,8 +5,16 @@ const react_1 = require("react");
5
5
  const log_1 = require("../../common/helpers/log");
6
6
  const object_1 = require("../../common/helpers/object");
7
7
  const getTimeSeconds = () => Math.ceil(new Date().getTime() / 1000);
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ if (!process.nodeLocalStorage) {
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ process.nodeLocalStorage = {};
13
+ }
8
14
  const clearLocalStorageItem = (key) => {
9
15
  if (typeof window === 'undefined') {
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ delete process.nodeLocalStorage[key];
10
18
  return;
11
19
  }
12
20
  try {
@@ -20,6 +28,8 @@ exports.clearLocalStorageItem = clearLocalStorageItem;
20
28
  const clearAllLocalStorage = (except) => {
21
29
  try {
22
30
  if (typeof window === 'undefined') {
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
+ process.nodeLocalStorage = {};
23
33
  return;
24
34
  }
25
35
  for (let i = 0; i < localStorage.length; i += 1) {
@@ -38,6 +48,8 @@ exports.clearAllLocalStorage = clearAllLocalStorage;
38
48
  const setLocalStorageItem = (key, value, ttl) => {
39
49
  try {
40
50
  if (typeof window === 'undefined') {
51
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
+ process.nodeLocalStorage[key] = value;
41
53
  return;
42
54
  }
43
55
  const set = {
@@ -54,7 +66,9 @@ const setLocalStorageItem = (key, value, ttl) => {
54
66
  exports.setLocalStorageItem = setLocalStorageItem;
55
67
  const getLocalStorageItem = (key, initialValue, ttl) => {
56
68
  if (typeof window === 'undefined') {
57
- return initialValue;
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ const value = process.nodeLocalStorage[key] || initialValue;
71
+ return value;
58
72
  }
59
73
  const itemraw = window.localStorage.getItem(key);
60
74
  const item = (0, object_1.tryJsonParse)(itemraw, undefined);
@@ -70,7 +84,6 @@ const getLocalStorageItem = (key, initialValue, ttl) => {
70
84
  return itemv;
71
85
  };
72
86
  exports.getLocalStorageItem = getLocalStorageItem;
73
- // Hook
74
87
  function UseLocalStorage(key, initialValue, ttl) {
75
88
  const storedValue = (0, exports.getLocalStorageItem)(key, initialValue, ttl);
76
89
  //bump use of stored value
@@ -78,9 +91,6 @@ function UseLocalStorage(key, initialValue, ttl) {
78
91
  // Return a wrapped version of useState's setter function that ...
79
92
  // ... persists the new value to localStorage.
80
93
  const setValue = (value) => {
81
- if (typeof window === 'undefined') {
82
- return;
83
- }
84
94
  const valueToStore = (value instanceof Function ? value(storedValue) : value);
85
95
  (0, exports.setLocalStorageItem)(key, valueToStore, ttl);
86
96
  setT(new Date().getTime());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.95",
3
+ "version": "0.0.100",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",