@contrail/util 1.4.0-alpha.ebd7d81 → 1.4.0
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 +4 -6
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/lambda-util/lambda-util.d.ts +4 -0
- package/lib/lambda-util/lambda-util.js +10 -0
- package/package.json +1 -1
- package/lib/response-size-util/response-size-util.d.ts +0 -10
- package/lib/response-size-util/response-size-util.js +0 -46
package/CHANGELOG.md
CHANGED
|
@@ -7,14 +7,12 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
## [1.4.0] - 2026-09-11
|
|
11
|
-
|
|
12
10
|
### Added
|
|
13
11
|
|
|
14
|
-
- `
|
|
15
|
-
- `
|
|
16
|
-
- `
|
|
17
|
-
- `
|
|
12
|
+
- `lambda-util` — AWS Lambda response-size helpers shared across services.
|
|
13
|
+
- `MAX_LAMBDA_RESPONSE_MB` / `RESPONSE_SIZE_BUFFER_MB` — the 6MB Lambda response cap and the safety buffer held below it.
|
|
14
|
+
- `RESPONSE_BYTE_LIMIT` — the cap minus the buffer, in bytes, for size checks that work in bytes.
|
|
15
|
+
- `getSerializedByteSize` — serialized byte size of any value. Treats `undefined` as `null`, since `JSON.stringify(undefined)` returns `undefined` rather than a string and `Buffer.byteLength` throws on it.
|
|
18
16
|
|
|
19
17
|
## [1.2.1] - 2026-03-25
|
|
20
18
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export * from './app-util/app-util';
|
|
2
2
|
export * from './compression-util';
|
|
3
3
|
export * from './date-util/date-util';
|
|
4
|
+
export * from './lambda-util/lambda-util';
|
|
4
5
|
export * from './map-util/map-util';
|
|
5
6
|
export * from './object-util/object-util';
|
|
6
7
|
export * from './order-util/order-util';
|
|
7
8
|
export * from './performance-util/performance-util';
|
|
8
9
|
export * from './promise-util/promise-util';
|
|
9
|
-
export * from './response-size-util/response-size-util';
|
|
10
10
|
export * from './retry-util/retry-util';
|
|
11
11
|
export * from './string-util/string-util';
|
|
12
12
|
export * from './timer-util/timer-util';
|
package/lib/index.js
CHANGED
|
@@ -17,12 +17,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./app-util/app-util"), exports);
|
|
18
18
|
__exportStar(require("./compression-util"), exports);
|
|
19
19
|
__exportStar(require("./date-util/date-util"), exports);
|
|
20
|
+
__exportStar(require("./lambda-util/lambda-util"), exports);
|
|
20
21
|
__exportStar(require("./map-util/map-util"), exports);
|
|
21
22
|
__exportStar(require("./object-util/object-util"), exports);
|
|
22
23
|
__exportStar(require("./order-util/order-util"), exports);
|
|
23
24
|
__exportStar(require("./performance-util/performance-util"), exports);
|
|
24
25
|
__exportStar(require("./promise-util/promise-util"), exports);
|
|
25
|
-
__exportStar(require("./response-size-util/response-size-util"), exports);
|
|
26
26
|
__exportStar(require("./retry-util/retry-util"), exports);
|
|
27
27
|
__exportStar(require("./string-util/string-util"), exports);
|
|
28
28
|
__exportStar(require("./timer-util/timer-util"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RESPONSE_BYTE_LIMIT = exports.RESPONSE_SIZE_BUFFER_MB = exports.MAX_LAMBDA_RESPONSE_MB = void 0;
|
|
4
|
+
exports.getSerializedByteSize = getSerializedByteSize;
|
|
5
|
+
exports.MAX_LAMBDA_RESPONSE_MB = 6;
|
|
6
|
+
exports.RESPONSE_SIZE_BUFFER_MB = 0.5;
|
|
7
|
+
exports.RESPONSE_BYTE_LIMIT = (exports.MAX_LAMBDA_RESPONSE_MB - exports.RESPONSE_SIZE_BUFFER_MB) * 1024 * 1024;
|
|
8
|
+
function getSerializedByteSize(value) {
|
|
9
|
+
return Buffer.byteLength(JSON.stringify(value !== null && value !== void 0 ? value : null));
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare const LAMBDA_MAX_RESPONSE_BYTES: number;
|
|
2
|
-
export declare const DEFAULT_RESPONSE_BUFFER_BYTES: number;
|
|
3
|
-
export interface ResponseBudgetOptions {
|
|
4
|
-
maxBytes?: number;
|
|
5
|
-
bufferBytes?: number;
|
|
6
|
-
}
|
|
7
|
-
export declare function getResponseBudgetBytes(options?: ResponseBudgetOptions): number;
|
|
8
|
-
export declare function getUtf8ByteLength(str: string): number;
|
|
9
|
-
export declare function getJsonByteLength(value: unknown): number;
|
|
10
|
-
export declare function exceedsResponseBudget(value: unknown, options?: ResponseBudgetOptions): boolean;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_RESPONSE_BUFFER_BYTES = exports.LAMBDA_MAX_RESPONSE_BYTES = void 0;
|
|
4
|
-
exports.getResponseBudgetBytes = getResponseBudgetBytes;
|
|
5
|
-
exports.getUtf8ByteLength = getUtf8ByteLength;
|
|
6
|
-
exports.getJsonByteLength = getJsonByteLength;
|
|
7
|
-
exports.exceedsResponseBudget = exceedsResponseBudget;
|
|
8
|
-
exports.LAMBDA_MAX_RESPONSE_BYTES = 6 * 1024 * 1024;
|
|
9
|
-
exports.DEFAULT_RESPONSE_BUFFER_BYTES = 0.5 * 1024 * 1024;
|
|
10
|
-
function getResponseBudgetBytes(options = {}) {
|
|
11
|
-
var _a, _b;
|
|
12
|
-
const maxBytes = (_a = options.maxBytes) !== null && _a !== void 0 ? _a : exports.LAMBDA_MAX_RESPONSE_BYTES;
|
|
13
|
-
const bufferBytes = (_b = options.bufferBytes) !== null && _b !== void 0 ? _b : exports.DEFAULT_RESPONSE_BUFFER_BYTES;
|
|
14
|
-
return Math.max(0, maxBytes - bufferBytes);
|
|
15
|
-
}
|
|
16
|
-
function getUtf8ByteLength(str) {
|
|
17
|
-
if (typeof Buffer !== 'undefined') {
|
|
18
|
-
return Buffer.byteLength(str, 'utf8');
|
|
19
|
-
}
|
|
20
|
-
return new TextEncoder().encode(str).length;
|
|
21
|
-
}
|
|
22
|
-
function getJsonByteLength(value) {
|
|
23
|
-
const serialized = JSON.stringify(value);
|
|
24
|
-
return serialized === undefined ? 0 : getUtf8ByteLength(serialized);
|
|
25
|
-
}
|
|
26
|
-
function exceedsResponseBudget(value, options = {}) {
|
|
27
|
-
const budgetBytes = getResponseBudgetBytes(options);
|
|
28
|
-
if (value === null || value === undefined) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
if (!Array.isArray(value)) {
|
|
32
|
-
return getJsonByteLength(value) > budgetBytes;
|
|
33
|
-
}
|
|
34
|
-
if (value.length === 0) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
let totalBytes = 2 + (value.length - 1);
|
|
38
|
-
for (const element of value) {
|
|
39
|
-
if (totalBytes > budgetBytes) {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
const serialized = JSON.stringify(element);
|
|
43
|
-
totalBytes += serialized === undefined ? 4 : getUtf8ByteLength(serialized);
|
|
44
|
-
}
|
|
45
|
-
return totalBytes > budgetBytes;
|
|
46
|
-
}
|