sdk-aws-lambda 0.4.0 → 0.4.1
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,6 +1,6 @@
|
|
|
1
1
|
import { LambdaClient } from '@aws-sdk/client-lambda';
|
|
2
2
|
/**
|
|
3
|
-
* .what =
|
|
3
|
+
* .what = findserts the LambdaClient for this config; returns the injected one, if any
|
|
4
4
|
* .why = named transformer for clear narrative in orchestrator
|
|
5
5
|
*/
|
|
6
6
|
export declare const genLambdaSdk: (input: {
|
|
@@ -9,3 +9,10 @@ export declare const genLambdaSdk: (input: {
|
|
|
9
9
|
region?: string;
|
|
10
10
|
};
|
|
11
11
|
}) => LambdaClient;
|
|
12
|
+
/**
|
|
13
|
+
* .what = releases every memoized LambdaClient and destroys its sockets
|
|
14
|
+
* .why = the `del` mirror of `gen`. a memoized client holds a keep-alive agent, and a live
|
|
15
|
+
* agent can hold the event loop open in a cli or a one-off command, which drains its
|
|
16
|
+
* loop rather than a call to `process.exit`. this is that escape hatch
|
|
17
|
+
*/
|
|
18
|
+
export declare const delLambdaSdks: () => void;
|
|
@@ -1,17 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.genLambdaSdk = void 0;
|
|
3
|
+
exports.delLambdaSdks = exports.genLambdaSdk = void 0;
|
|
4
4
|
const client_lambda_1 = require("@aws-sdk/client-lambda");
|
|
5
|
+
const domain_objects_1 = require("domain-objects");
|
|
6
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
7
|
/**
|
|
6
|
-
* .what =
|
|
8
|
+
* .what = the LambdaClient already made per distinct client config
|
|
9
|
+
* .why = `gen` promises findsert, so the same input must converge on the same client.
|
|
10
|
+
* a client per call is an `https.Agent` per call, and an agent's keep-alive pool
|
|
11
|
+
* is per-agent — so a fresh agent always starts empty, never reuses a socket, and
|
|
12
|
+
* starves the runtime's dns budget (`getaddrinfo EBUSY` -> `Runtime.ExitError`)
|
|
13
|
+
*/
|
|
14
|
+
const sdkByConfig = new Map();
|
|
15
|
+
/**
|
|
16
|
+
* .what = the memo key for a LambdaClient config
|
|
17
|
+
* .why = the key must cover EVERY knob that changes client identity, so it derives from
|
|
18
|
+
* the config object itself rather than from a hand-listed field. a hand-listed key
|
|
19
|
+
* silently hands back a wrong-config client the day a second knob lands
|
|
20
|
+
* .note = throws when a knob does not survive serialization (e.g. a function-valued
|
|
21
|
+
* `credentials` provider), since such a knob would collide in silence
|
|
22
|
+
*/
|
|
23
|
+
const asLambdaSdkMemoKey = (config) => {
|
|
24
|
+
const key = (0, domain_objects_1.serialize)(config);
|
|
25
|
+
// failfast when a knob drops out of the key; a dropped knob is a silent collision
|
|
26
|
+
const knobsGiven = Object.keys(config);
|
|
27
|
+
const knobsKeyed = Object.keys(JSON.parse(key));
|
|
28
|
+
if (knobsKeyed.length !== knobsGiven.length)
|
|
29
|
+
helpful_errors_1.MalfunctionError.throw('lambda sdk config holds a knob the memo key drops', {
|
|
30
|
+
knobsGiven,
|
|
31
|
+
knobsKeyed,
|
|
32
|
+
});
|
|
33
|
+
return key;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* .what = findserts the LambdaClient for this config; returns the injected one, if any
|
|
7
37
|
* .why = named transformer for clear narrative in orchestrator
|
|
8
38
|
*/
|
|
9
39
|
const genLambdaSdk = (input) => {
|
|
10
40
|
// return injected LambdaClient if provided
|
|
11
41
|
if (input.sdk)
|
|
12
42
|
return input.sdk;
|
|
13
|
-
//
|
|
14
|
-
|
|
43
|
+
// build the config, let sdk infer region unless explicitly provided
|
|
44
|
+
const config = input.env?.region
|
|
45
|
+
? { region: input.env.region }
|
|
46
|
+
: {};
|
|
47
|
+
// find the client already made for this config, if any
|
|
48
|
+
const key = asLambdaSdkMemoKey(config);
|
|
49
|
+
const sdkFound = sdkByConfig.get(key);
|
|
50
|
+
if (sdkFound)
|
|
51
|
+
return sdkFound;
|
|
52
|
+
// otherwise, insert one
|
|
53
|
+
const sdkMade = new client_lambda_1.LambdaClient(config);
|
|
54
|
+
sdkByConfig.set(key, sdkMade);
|
|
55
|
+
return sdkMade;
|
|
15
56
|
};
|
|
16
57
|
exports.genLambdaSdk = genLambdaSdk;
|
|
58
|
+
/**
|
|
59
|
+
* .what = releases every memoized LambdaClient and destroys its sockets
|
|
60
|
+
* .why = the `del` mirror of `gen`. a memoized client holds a keep-alive agent, and a live
|
|
61
|
+
* agent can hold the event loop open in a cli or a one-off command, which drains its
|
|
62
|
+
* loop rather than a call to `process.exit`. this is that escape hatch
|
|
63
|
+
*/
|
|
64
|
+
const delLambdaSdks = () => {
|
|
65
|
+
for (const sdk of sdkByConfig.values())
|
|
66
|
+
sdk.destroy();
|
|
67
|
+
sdkByConfig.clear();
|
|
68
|
+
};
|
|
69
|
+
exports.delLambdaSdks = delLambdaSdks;
|
|
17
70
|
//# sourceMappingURL=genLambdaSdk.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genLambdaSdk.js","sourceRoot":"","sources":["../../../../src/access/sdks/lambda/genLambdaSdk.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"genLambdaSdk.js","sourceRoot":"","sources":["../../../../src/access/sdks/lambda/genLambdaSdk.ts"],"names":[],"mappings":";;;AAAA,0DAA+E;AAC/E,mDAA2C;AAC3C,mDAAkD;AAElD;;;;;;GAMG;AACH,MAAM,WAAW,GAA8B,IAAI,GAAG,EAAE,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,kBAAkB,GAAG,CAAC,MAA0B,EAAU,EAAE;IAChE,MAAM,GAAG,GAAG,IAAA,0BAAS,EAAC,MAAM,CAAC,CAAC;IAE9B,kFAAkF;IAClF,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GA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
|
|
5
5
|
*/
|
|
6
6
|
export { BadRequestError } from 'helpful-errors';
|
|
7
|
+
/**
|
|
8
|
+
* .what = releases every LambdaClient this sdk memoized on the caller's behalf
|
|
9
|
+
* .why = `askLambdaEndpoint` findserts a client per region and holds it for the process, so
|
|
10
|
+
* its keep-alive agent can hold the event loop open in a cli or one-off command. a
|
|
11
|
+
* library that makes process-lifetime state owes the caller a way to release it
|
|
12
|
+
*/
|
|
13
|
+
export { delLambdaSdks } from './access/sdks/lambda/genLambdaSdk';
|
|
7
14
|
export type { ApiGatewayRequestPayload } from './domain.objects/ApiGatewayRequestPayload';
|
|
8
15
|
export type { ApiGatewayResponse } from './domain.objects/ApiGatewayResponse';
|
|
9
16
|
export type { ApiGatewayResponsePayload } from './domain.objects/ApiGatewayResponsePayload';
|
package/dist/index.js
CHANGED
|
@@ -5,10 +5,18 @@
|
|
|
5
5
|
* define endpoints, ask endpoints, auto-propagate trace-ids.
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.getOneLambdaContract = exports.getAllLambdaFunctionsByPrefix = exports.getAllLambdaContracts = exports.genServiceSdk = exports.genZodOutputValidationMiddleware = exports.genTrailMiddleware = exports.genIoLoggerMiddleware = exports.genIntrospectionMiddleware = exports.genInternalServiceErrorMiddleware = exports.genConstraintErrorMiddleware = exports.asContextTrailed = exports.genZodEventValidationMiddleware = exports.genLambdaEndpoint = exports.genZodBodyValidationMiddleware = exports.genContentTypeCoherenceMiddleware = exports.genApiGatewayEventNormalizationMiddleware = exports.isApiGatewayResponse = exports.forApiGateway = exports.asApiGatewayResponseSchema = exports.asLambdaEndpoint = exports.getAskLambdaCacheKey = exports.asCacheWithoutSet = exports.askLambdaEndpoint = exports.LambdaServiceNotFoundError = exports.LambdaIntrospectionNotSupportedError = exports.LambdaIntrospectionBlockedError = exports.LambdaFunctionNotFoundError = exports.LambdaEndpointError = exports.LambdaEndpoint = exports.LambdaDomainObjectRefUnbindableError = exports.LambdaDomainObjectNotCapturableError = exports.LambdaCredentialsAbsentError = exports.HttpStatusCode = exports.GeneratedFile = exports.BadRequestError = void 0;
|
|
8
|
+
exports.getOneLambdaContract = exports.getAllLambdaFunctionsByPrefix = exports.getAllLambdaContracts = exports.genServiceSdk = exports.genZodOutputValidationMiddleware = exports.genTrailMiddleware = exports.genIoLoggerMiddleware = exports.genIntrospectionMiddleware = exports.genInternalServiceErrorMiddleware = exports.genConstraintErrorMiddleware = exports.asContextTrailed = exports.genZodEventValidationMiddleware = exports.genLambdaEndpoint = exports.genZodBodyValidationMiddleware = exports.genContentTypeCoherenceMiddleware = exports.genApiGatewayEventNormalizationMiddleware = exports.isApiGatewayResponse = exports.forApiGateway = exports.asApiGatewayResponseSchema = exports.asLambdaEndpoint = exports.getAskLambdaCacheKey = exports.asCacheWithoutSet = exports.askLambdaEndpoint = exports.LambdaServiceNotFoundError = exports.LambdaIntrospectionNotSupportedError = exports.LambdaIntrospectionBlockedError = exports.LambdaFunctionNotFoundError = exports.LambdaEndpointError = exports.LambdaEndpoint = exports.LambdaDomainObjectRefUnbindableError = exports.LambdaDomainObjectNotCapturableError = exports.LambdaCredentialsAbsentError = exports.HttpStatusCode = exports.GeneratedFile = exports.delLambdaSdks = exports.BadRequestError = void 0;
|
|
9
9
|
// re-export from helpful-errors for convenience
|
|
10
10
|
var helpful_errors_1 = require("helpful-errors");
|
|
11
11
|
Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return helpful_errors_1.BadRequestError; } });
|
|
12
|
+
/**
|
|
13
|
+
* .what = releases every LambdaClient this sdk memoized on the caller's behalf
|
|
14
|
+
* .why = `askLambdaEndpoint` findserts a client per region and holds it for the process, so
|
|
15
|
+
* its keep-alive agent can hold the event loop open in a cli or one-off command. a
|
|
16
|
+
* library that makes process-lifetime state owes the caller a way to release it
|
|
17
|
+
*/
|
|
18
|
+
var genLambdaSdk_1 = require("./access/sdks/lambda/genLambdaSdk");
|
|
19
|
+
Object.defineProperty(exports, "delLambdaSdks", { enumerable: true, get: function () { return genLambdaSdk_1.delLambdaSdks; } });
|
|
12
20
|
var GeneratedFile_1 = require("./domain.objects/GeneratedFile");
|
|
13
21
|
Object.defineProperty(exports, "GeneratedFile", { enumerable: true, get: function () { return GeneratedFile_1.GeneratedFile; } });
|
|
14
22
|
var HttpStatusCode_1 = require("./domain.objects/HttpStatusCode");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,gDAAgD;AAChD,iDAAiD;AAAxC,iHAAA,eAAe,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,gDAAgD;AAChD,iDAAiD;AAAxC,iHAAA,eAAe,OAAA;AAExB;;;;;GAKG;AACH,kEAAkE;AAAzD,6GAAA,aAAa,OAAA;AAWtB,gEAA+D;AAAtD,8GAAA,aAAa,OAAA;AACtB,kEAAiE;AAAxD,gHAAA,cAAc,OAAA;AACvB,8FAA6F;AAApF,4IAAA,4BAA4B,OAAA;AACrC,8GAA6G;AAApG,4JAAA,oCAAoC,OAAA;AAC7C,8GAA6G;AAApG,4JAAA,oCAAoC,OAAA;AAC7C,kEAAiE;AAAxD,gHAAA,cAAc,OAAA;AACvB,4EAA2E;AAAlE,0HAAA,mBAAmB,OAAA;AAE5B,4BAA4B;AAC5B,4FAA2F;AAAlF,0IAAA,2BAA2B,OAAA;AACpC,oGAAmG;AAA1F,kJAAA,+BAA+B,OAAA;AACxC,8GAA6G;AAApG,4JAAA,oCAAoC,OAAA;AAC7C,0FAAyF;AAAhF,wIAAA,0BAA0B,OAAA;AAKnC,oBAAoB;AACpB,6FAA4F;AAAnF,sHAAA,iBAAiB,OAAA;AAC1B,mGAAkG;AAAzF,sHAAA,iBAAiB,OAAA;AAC1B,yGAAwG;AAA/F,4HAAA,oBAAoB,OAAA;AAC7B,eAAe;AACf,0FAAyF;AAAhF,oHAAA,gBAAgB,OAAA;AACzB,+IAA8I;AAArI,wIAAA,0BAA0B,OAAA;AAMnC,yJAAsI;AAA7H,gIAAA,aAAa,OAAA;AACtB,mIAAkI;AAAzH,4HAAA,oBAAoB,OAAA;AAC7B,wLAAuL;AAA9K,sKAAA,yCAAyC,OAAA;AAClD,wKAAuK;AAA9J,sJAAA,iCAAiC,OAAA;AAC1C,kKAAiK;AAAxJ,gJAAA,8BAA8B,OAAA;AAUvC,4JAA4I;AAAnI,qIAAA,iBAAiB,OAAA;AAC1B,qKAAoK;AAA3J,kJAAA,+BAA+B,OAAA;AACxC;;;;;;GAMG;AACH,sGAG2E;AAFzE,oHAAA,gBAAgB,OAAA;AAGlB,8HAA6H;AAApH,4IAAA,4BAA4B,OAAA;AACrC,wIAAuI;AAA9H,sJAAA,iCAAiC,OAAA;AAC1C,0HAAyH;AAAhH,wIAAA,0BAA0B,OAAA;AACnC,gHAA+G;AAAtG,8HAAA,qBAAqB,OAAA;AAC9B,gCAAgC;AAChC,0GAAyG;AAAhG,wHAAA,kBAAkB,OAAA;AAC3B,sIAAqI;AAA5H,oJAAA,gCAAgC,OAAA;AAoBzC,8DAA8D;AAC9D,iFAAgF;AAAvE,8GAAA,aAAa,OAAA;AACtB,0CAA0C;AAC1C,yGAIyE;AADvE,8HAAA,qBAAqB,OAAA;AAEvB,wIAAuI;AAA9H,8IAAA,6BAA6B,OAAA;AACtC,sGAIuE;AADrE,4HAAA,oBAAoB,OAAA"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "sdk-aws-lambda",
|
|
3
3
|
"author": "ehmpathy",
|
|
4
4
|
"description": "a simple and opinionated sdk for aws lambda. define endpoints, ask endpoints, auto-propagate trace-ids.",
|
|
5
|
-
"version": "0.4.
|
|
5
|
+
"version": "0.4.1",
|
|
6
6
|
"repository": "ehmpathy/sdk-aws-lambda",
|
|
7
7
|
"homepage": "https://github.com/ehmpathy/sdk-aws-lambda",
|
|
8
8
|
"keywords": [
|
|
@@ -102,9 +102,9 @@
|
|
|
102
102
|
"jest": "30.2.0",
|
|
103
103
|
"rhachet": "1.47.5",
|
|
104
104
|
"rhachet-brains-anthropic": "0.4.3",
|
|
105
|
-
"rhachet-brains-fireworksai": "0.1.
|
|
105
|
+
"rhachet-brains-fireworksai": "0.1.7",
|
|
106
106
|
"rhachet-brains-xai": "0.3.3",
|
|
107
|
-
"rhachet-roles-bhrain": "0.
|
|
107
|
+
"rhachet-roles-bhrain": "0.37.0",
|
|
108
108
|
"rhachet-roles-bhuild": "0.21.36",
|
|
109
109
|
"rhachet-roles-ehmpathy": "1.38.12",
|
|
110
110
|
"rhachet-roles-rhachet": "0.1.7",
|