ag-common 0.0.96 → 0.0.97
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,14 +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
|
-
|
|
23
|
-
|
|
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) {
|
|
24
25
|
throw new Error('exceeded dynamo provision cap');
|
|
25
26
|
}
|
|
26
|
-
if (writes
|
|
27
|
-
|
|
28
|
-
throw new Error('exceeded dynamo provision cap');
|
|
27
|
+
if (mustEqual && (reads !== readsMax || writes !== writesMax)) {
|
|
28
|
+
throw new Error(`dynamo provision cap not met reads`);
|
|
29
29
|
}
|
|
30
|
-
(0, log_1.warn)(`dynamo provisioned total: R=${reads} W=${writes}`);
|
|
31
30
|
};
|
|
32
31
|
exports.enforceDynamoProvisionCap = enforceDynamoProvisionCap;
|