@contrail/util 2.2.0-alpha.3804ed9 → 2.2.0-alpha.3b8e11b
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.
package/CHANGELOG.md
CHANGED
|
@@ -18,10 +18,11 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
18
18
|
|
|
19
19
|
### Added
|
|
20
20
|
|
|
21
|
-
- `response-size-util` — measures whether a payload fits within AWS Lambda
|
|
21
|
+
- `response-size-util` — measures whether a payload fits within the AWS Lambda response limit, so services can decide to offload to S3 based on actual serialized bytes rather than a row count.
|
|
22
22
|
- `exceedsResponseBudget(value, options?)` — the decision helper. For arrays it serializes one element at a time and stops as soon as the budget is crossed, so the cost is bounded by the budget rather than by the size of the payload.
|
|
23
23
|
- `getJsonByteLength(value)` / `getUtf8ByteLength(str)` — exact UTF-8 byte measurement.
|
|
24
|
-
- `getResponseBudgetBytes(options?)
|
|
24
|
+
- `getResponseBudgetBytes(options?)` — the budget a measured payload must stay under.
|
|
25
|
+
- `LAMBDA_MAX_RESPONSE_BYTES`, `RESPONSE_GUARD_LIMIT_BYTES`, `DEFAULT_RESPONSE_BUFFER_BYTES`, `DEFAULT_RESPONSE_BUDGET_BYTES` — the ladder of thresholds a response crosses, each sitting below the one above it so a payload offloads before `core`'s response guard returns a 413, and the guard fires before Lambda rejects the invocation.
|
|
25
26
|
|
|
26
27
|
## [1.2.1] - 2026-03-25
|
|
27
28
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export declare const LAMBDA_MAX_RESPONSE_BYTES
|
|
2
|
-
export declare const
|
|
1
|
+
export declare const LAMBDA_MAX_RESPONSE_BYTES = 6000000;
|
|
2
|
+
export declare const RESPONSE_GUARD_LIMIT_BYTES = 5500000;
|
|
3
|
+
export declare const DEFAULT_RESPONSE_BUFFER_BYTES = 500000;
|
|
4
|
+
export declare const DEFAULT_RESPONSE_BUDGET_BYTES: number;
|
|
3
5
|
export interface ResponseBudgetOptions {
|
|
4
|
-
|
|
6
|
+
limitBytes?: number;
|
|
5
7
|
bufferBytes?: number;
|
|
6
8
|
}
|
|
7
9
|
export declare function getResponseBudgetBytes(options?: ResponseBudgetOptions): number;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_RESPONSE_BUFFER_BYTES = exports.LAMBDA_MAX_RESPONSE_BYTES = void 0;
|
|
3
|
+
exports.DEFAULT_RESPONSE_BUDGET_BYTES = exports.DEFAULT_RESPONSE_BUFFER_BYTES = exports.RESPONSE_GUARD_LIMIT_BYTES = exports.LAMBDA_MAX_RESPONSE_BYTES = void 0;
|
|
4
4
|
exports.getResponseBudgetBytes = getResponseBudgetBytes;
|
|
5
5
|
exports.getUtf8ByteLength = getUtf8ByteLength;
|
|
6
6
|
exports.getJsonByteLength = getJsonByteLength;
|
|
7
7
|
exports.exceedsResponseBudget = exceedsResponseBudget;
|
|
8
|
-
exports.LAMBDA_MAX_RESPONSE_BYTES =
|
|
9
|
-
exports.
|
|
8
|
+
exports.LAMBDA_MAX_RESPONSE_BYTES = 6000000;
|
|
9
|
+
exports.RESPONSE_GUARD_LIMIT_BYTES = 5500000;
|
|
10
|
+
exports.DEFAULT_RESPONSE_BUFFER_BYTES = 500000;
|
|
11
|
+
exports.DEFAULT_RESPONSE_BUDGET_BYTES = exports.RESPONSE_GUARD_LIMIT_BYTES - exports.DEFAULT_RESPONSE_BUFFER_BYTES;
|
|
12
|
+
const JSON_NULL_BYTES = 'null'.length;
|
|
10
13
|
function getResponseBudgetBytes(options = {}) {
|
|
11
14
|
var _a, _b;
|
|
12
|
-
const
|
|
15
|
+
const limitBytes = (_a = options.limitBytes) !== null && _a !== void 0 ? _a : exports.RESPONSE_GUARD_LIMIT_BYTES;
|
|
13
16
|
const bufferBytes = (_b = options.bufferBytes) !== null && _b !== void 0 ? _b : exports.DEFAULT_RESPONSE_BUFFER_BYTES;
|
|
14
|
-
return Math.max(0,
|
|
17
|
+
return Math.max(0, limitBytes - bufferBytes);
|
|
15
18
|
}
|
|
16
19
|
function getUtf8ByteLength(str) {
|
|
17
20
|
if (typeof Buffer !== 'undefined') {
|
|
@@ -34,13 +37,15 @@ function exceedsResponseBudget(value, options = {}) {
|
|
|
34
37
|
if (value.length === 0) {
|
|
35
38
|
return false;
|
|
36
39
|
}
|
|
37
|
-
|
|
40
|
+
const bracketBytes = '[]'.length;
|
|
41
|
+
const separatorBytes = value.length - 1;
|
|
42
|
+
let totalBytes = bracketBytes + separatorBytes;
|
|
38
43
|
for (const element of value) {
|
|
39
44
|
if (totalBytes > budgetBytes) {
|
|
40
45
|
return true;
|
|
41
46
|
}
|
|
42
47
|
const serialized = JSON.stringify(element);
|
|
43
|
-
totalBytes += serialized === undefined ?
|
|
48
|
+
totalBytes += serialized === undefined ? JSON_NULL_BYTES : getUtf8ByteLength(serialized);
|
|
44
49
|
}
|
|
45
50
|
return totalBytes > budgetBytes;
|
|
46
51
|
}
|