sdk-aws-lambda 0.3.0 → 0.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/dist/domain.objects/ApiGatewayRequestPayload.d.ts +12 -0
- package/dist/domain.objects/ApiGatewayRequestPayload.js +3 -0
- package/dist/domain.objects/ApiGatewayRequestPayload.js.map +1 -0
- package/dist/domain.objects/ApiGatewayResponse.d.ts +30 -0
- package/dist/domain.objects/ApiGatewayResponse.js +3 -0
- package/dist/domain.objects/ApiGatewayResponse.js.map +1 -0
- package/dist/domain.objects/ApiGatewayResponsePayload.d.ts +30 -0
- package/dist/domain.objects/ApiGatewayResponsePayload.js +3 -0
- package/dist/domain.objects/ApiGatewayResponsePayload.js.map +1 -0
- package/dist/domain.objects/HttpStatusCode.d.ts +1 -0
- package/dist/domain.objects/HttpStatusCode.js +1 -0
- package/dist/domain.objects/HttpStatusCode.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/TranslateLog.d.ts +29 -0
- package/dist/domain.operations/genLambdaEndpoint/TranslateLog.js +3 -0
- package/dist/domain.operations/genLambdaEndpoint/TranslateLog.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/asContextLogTrail.d.ts +29 -0
- package/dist/domain.operations/genLambdaEndpoint/asContextLogTrail.js +30 -0
- package/dist/domain.operations/genLambdaEndpoint/asContextLogTrail.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/UnifiedApiGatewayEvent.d.ts +36 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/UnifiedApiGatewayEvent.js +3 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/UnifiedApiGatewayEvent.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayload.d.ts +19 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayload.js +24 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayload.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayloadJson.d.ts +26 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayloadJson.js +31 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayloadJson.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponseSchema.d.ts +33 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponseSchema.js +39 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponseSchema.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asUnifiedApiGatewayEvent.d.ts +27 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asUnifiedApiGatewayEvent.js +118 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asUnifiedApiGatewayEvent.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.d.ts +76 -36
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js +153 -45
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getAllWirePayloadKeysFound.d.ts +8 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getAllWirePayloadKeysFound.js +34 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getAllWirePayloadKeysFound.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/isApiGatewayResponse.d.ts +19 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/isApiGatewayResponse.js +36 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/isApiGatewayResponse.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.d.ts +7 -24
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js +19 -103
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genContentTypeCoherenceMiddleware.d.ts +20 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genContentTypeCoherenceMiddleware.js +48 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genContentTypeCoherenceMiddleware.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.d.ts +16 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.js +32 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.d.ts +6 -22
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js +24 -18
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.d.ts +11 -2
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.js +12 -2
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/asContextTrailed.d.ts +37 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/asContextTrailed.js +24 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/asContextTrailed.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.d.ts +18 -10
- package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.js +20 -23
- package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.d.ts +29 -6
- package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js +23 -28
- package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.d.ts +16 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.js +9 -13
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.d.ts +27 -6
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js +29 -4
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js +12 -4
- package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.d.ts +27 -2
- package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.js +34 -13
- package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.js +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.js.map +1 -1
- package/dist/index.d.ts +33 -2
- package/dist/index.js +20 -1
- package/dist/index.js.map +1 -1
- package/package.json +12 -11
- package/readme.md +50 -2
|
@@ -1,113 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.genApiGatewayEventNormalizationMiddleware = void 0;
|
|
4
|
-
const
|
|
5
|
-
const getIsV1ApiGatewayEvent_1 = require("../getIsV1ApiGatewayEvent");
|
|
6
|
-
const getIsV2ApiGatewayEvent_1 = require("../getIsV2ApiGatewayEvent");
|
|
4
|
+
const asUnifiedApiGatewayEvent_1 = require("../asUnifiedApiGatewayEvent");
|
|
7
5
|
/**
|
|
8
|
-
* .what =
|
|
9
|
-
* .why =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const decoded = input.isBase64Encoded
|
|
16
|
-
? Buffer.from(input.body, 'base64').toString('utf-8')
|
|
17
|
-
: input.body;
|
|
18
|
-
// parse json or return raw string
|
|
19
|
-
try {
|
|
20
|
-
return JSON.parse(decoded);
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
return decoded;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* .what = convert v2 HTTP API event to unified format
|
|
28
|
-
* .why = isolates transformation logic from orchestrator
|
|
29
|
-
*/
|
|
30
|
-
const asUnifiedEventFromV2 = (input) => {
|
|
31
|
-
const body = input.parseBody
|
|
32
|
-
? getParsedApiGatewayBody({
|
|
33
|
-
body: input.event.body,
|
|
34
|
-
isBase64Encoded: input.event.isBase64Encoded,
|
|
35
|
-
})
|
|
36
|
-
: input.event.body;
|
|
37
|
-
return {
|
|
38
|
-
httpMethod: input.event.requestContext.http.method,
|
|
39
|
-
path: input.event.requestContext.http.path,
|
|
40
|
-
headers: input.event.headers,
|
|
41
|
-
queryStringParameters: input.event.queryStringParameters ?? null,
|
|
42
|
-
pathParameters: input.event.pathParameters ?? null,
|
|
43
|
-
body,
|
|
44
|
-
rawBody: input.event.body ?? null,
|
|
45
|
-
isBase64Encoded: input.event.isBase64Encoded,
|
|
46
|
-
requestContext: {
|
|
47
|
-
requestId: input.event.requestContext.requestId,
|
|
48
|
-
stage: input.event.requestContext.stage,
|
|
49
|
-
domainName: input.event.requestContext.domainName,
|
|
50
|
-
accountId: input.event.requestContext.accountId,
|
|
51
|
-
},
|
|
52
|
-
rawEvent: input.event,
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* .what = convert v1 REST API event to unified format
|
|
57
|
-
* .why = isolates transformation logic from orchestrator
|
|
58
|
-
*/
|
|
59
|
-
const asUnifiedEventFromV1 = (input) => {
|
|
60
|
-
const body = input.parseBody
|
|
61
|
-
? getParsedApiGatewayBody({
|
|
62
|
-
body: input.event.body,
|
|
63
|
-
isBase64Encoded: input.event.isBase64Encoded,
|
|
64
|
-
})
|
|
65
|
-
: input.event.body;
|
|
66
|
-
return {
|
|
67
|
-
httpMethod: input.event.httpMethod,
|
|
68
|
-
path: input.event.path,
|
|
69
|
-
headers: input.event.headers,
|
|
70
|
-
queryStringParameters: input.event.queryStringParameters ?? null,
|
|
71
|
-
pathParameters: input.event.pathParameters ?? null,
|
|
72
|
-
body,
|
|
73
|
-
rawBody: input.event.body ?? null,
|
|
74
|
-
isBase64Encoded: input.event.isBase64Encoded,
|
|
75
|
-
requestContext: {
|
|
76
|
-
requestId: input.event.requestContext.requestId,
|
|
77
|
-
stage: input.event.requestContext.stage,
|
|
78
|
-
domainName: input.event.requestContext.domainName,
|
|
79
|
-
accountId: input.event.requestContext.accountId,
|
|
80
|
-
},
|
|
81
|
-
rawEvent: input.event,
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* .what = converts v1/v2 API Gateway events to unified format
|
|
86
|
-
* .why = handlers work with consistent event shape regardless of API type
|
|
6
|
+
* .what = replaces the event with the v1/v2-reconciled shape
|
|
7
|
+
* .why = the api-gateway chain must read the same whichever version the trigger delivers, so
|
|
8
|
+
* this runs first and every step after it reads one shape
|
|
9
|
+
*
|
|
10
|
+
* .note = this DELEGATES to `asUnifiedApiGatewayEvent` rather than hold its own copy of the
|
|
11
|
+
* reconcile logic. one guarantee, one implementation, two entry points — a second
|
|
12
|
+
* copy would be the parallel code path (rule.forbid.parallel-codepaths)
|
|
87
13
|
*/
|
|
88
14
|
const genApiGatewayEventNormalizationMiddleware = (input) => {
|
|
89
15
|
const before = async (request) => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
request.event = asUnifiedEventFromV1({
|
|
102
|
-
event: rawEvent,
|
|
103
|
-
parseBody: input.parseBody,
|
|
104
|
-
});
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
// fail if neither v1 nor v2
|
|
108
|
-
throw new helpful_errors_1.MalfunctionError('event is neither v1 nor v2 API Gateway event', {
|
|
109
|
-
rawEvent,
|
|
110
|
-
});
|
|
16
|
+
/**
|
|
17
|
+
* .as = both casts exist because this middleware is typed `<any, any>`, so `request.event`
|
|
18
|
+
* is `any` on the way in and its declared type on the way out. the transform is
|
|
19
|
+
* real — `ApiGatewayRequestPayload` becomes `UnifiedApiGatewayEvent` — and middy
|
|
20
|
+
* cannot track a shape change across a `before` hook
|
|
21
|
+
* .removal = drops when middy gains typed inference across `.use`, at which point the
|
|
22
|
+
* middleware's own two type parameters name these shapes and no cast is owed
|
|
23
|
+
*
|
|
24
|
+
* .note = DELIBERATE MUTATION — `request` is middy's only channel to hand a value onward
|
|
25
|
+
*/
|
|
26
|
+
request.event = (0, asUnifiedApiGatewayEvent_1.asUnifiedApiGatewayEvent)({ payload: request.event }, { deserialize: { body: input.parseBody } });
|
|
111
27
|
};
|
|
112
28
|
return { before };
|
|
113
29
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genApiGatewayEventNormalizationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"genApiGatewayEventNormalizationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.ts"],"names":[],"mappings":";;;AAGA,0EAAuE;AAEvE;;;;;;;;GAQG;AACI,MAAM,yCAAyC,GAAG,CAAC,KAEzD,EAEC,EAAE;IACF,MAAM,MAAM,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7D;;;;;;;;;WASG;QACH,OAAO,CAAC,KAAK,GAAG,IAAA,mDAAwB,EACtC,EAAE,OAAO,EAAE,OAAO,CAAC,KAAiC,EAAE,EACtD,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,SAAS,EAAE,EAAE,CACR,CAAC;IACvC,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AAvBW,QAAA,yCAAyC,6CAuBpD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type middy from '@middy/core';
|
|
2
|
+
/**
|
|
3
|
+
* .what = removes `Content-Type` from a response that carries no body
|
|
4
|
+
* .why = a content-type that contradicts the body is the exact shape that raises twilio 11200 —
|
|
5
|
+
* the defect this whole affordance exists to retire. a 204 and a 308 each reach the wire
|
|
6
|
+
* body-less and would otherwise claim `application/json`
|
|
7
|
+
*
|
|
8
|
+
* ⚠️ .note = MUST be registered FIRST in the chain array. middy `unshift`s `after` and `onError`,
|
|
9
|
+
* so index 0 runs LAST on both — the only position later than the serializer that stamps
|
|
10
|
+
* the header, and later than the error builders that set `request.response`. anywhere
|
|
11
|
+
* else, the `onError` hook meets an absent response and returns early
|
|
12
|
+
*
|
|
13
|
+
* .note = the same function serves both hooks, so one implementation holds the guarantee on
|
|
14
|
+
* either path. no error response is body-less today, so `onError` finds no work yet; it
|
|
15
|
+
* is registered for a future body-less error status (a 304, a 205)
|
|
16
|
+
*/
|
|
17
|
+
export declare const genContentTypeCoherenceMiddleware: () => {
|
|
18
|
+
after: middy.MiddlewareFn<any, any>;
|
|
19
|
+
onError: middy.MiddlewareFn<any, any>;
|
|
20
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genContentTypeCoherenceMiddleware = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = removes `Content-Type` from a response that carries no body
|
|
6
|
+
* .why = a content-type that contradicts the body is the exact shape that raises twilio 11200 —
|
|
7
|
+
* the defect this whole affordance exists to retire. a 204 and a 308 each reach the wire
|
|
8
|
+
* body-less and would otherwise claim `application/json`
|
|
9
|
+
*
|
|
10
|
+
* ⚠️ .note = MUST be registered FIRST in the chain array. middy `unshift`s `after` and `onError`,
|
|
11
|
+
* so index 0 runs LAST on both — the only position later than the serializer that stamps
|
|
12
|
+
* the header, and later than the error builders that set `request.response`. anywhere
|
|
13
|
+
* else, the `onError` hook meets an absent response and returns early
|
|
14
|
+
*
|
|
15
|
+
* .note = the same function serves both hooks, so one implementation holds the guarantee on
|
|
16
|
+
* either path. no error response is body-less today, so `onError` finds no work yet; it
|
|
17
|
+
* is registered for a future body-less error status (a 304, a 205)
|
|
18
|
+
*/
|
|
19
|
+
const genContentTypeCoherenceMiddleware = () => {
|
|
20
|
+
const onResponse = async (request) => {
|
|
21
|
+
// an error path can reach here before any response was set
|
|
22
|
+
if (!request.response)
|
|
23
|
+
return;
|
|
24
|
+
// a body present means the Content-Type describes real bytes, so leave it be
|
|
25
|
+
if (request.response.body !== undefined)
|
|
26
|
+
return;
|
|
27
|
+
/**
|
|
28
|
+
* .as = middy types `request.response` as `unknown`, so `.headers` arrives untyped. the cast
|
|
29
|
+
* declares the shape this chain always puts there — `httpSecurityHeaders`, `httpCors`,
|
|
30
|
+
* and the error builders each write a flat string map
|
|
31
|
+
* .removal = drops when middy gains typed response inference, at which point
|
|
32
|
+
* `ApiGatewayResponsePayload['headers']` types this member directly
|
|
33
|
+
*/
|
|
34
|
+
const headers = request.response.headers;
|
|
35
|
+
if (!headers)
|
|
36
|
+
return;
|
|
37
|
+
/**
|
|
38
|
+
* .note = DELIBERATE MUTATION. `request` is middy's ONLY channel to hand a value onward,
|
|
39
|
+
* so a middleware that must alter the response has no immutable form available
|
|
40
|
+
* (rule.require.immutable-vars, the annotated-exception clause). the write is
|
|
41
|
+
* bounded to `headers` and replaces it with a fresh object rather than a splice
|
|
42
|
+
*/
|
|
43
|
+
request.response.headers = Object.fromEntries(Object.entries(headers).filter(([key]) => key.toLowerCase() !== 'content-type'));
|
|
44
|
+
};
|
|
45
|
+
return { after: onResponse, onError: onResponse };
|
|
46
|
+
};
|
|
47
|
+
exports.genContentTypeCoherenceMiddleware = genContentTypeCoherenceMiddleware;
|
|
48
|
+
//# sourceMappingURL=genContentTypeCoherenceMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genContentTypeCoherenceMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genContentTypeCoherenceMiddleware.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;GAcG;AACI,MAAM,iCAAiC,GAAG,GAG/C,EAAE;IACF,MAAM,UAAU,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QACjE,2DAA2D;QAC3D,IAAI,CAAC,OAAO,CAAC,QAAQ;YAAE,OAAO;QAE9B,6EAA6E;QAC7E,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO;QAEhD;;;;;;WAMG;QACH,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,OAEpB,CAAC;QACd,IAAI,CAAC,OAAO;YAAE,OAAO;QAErB;;;;;WAKG;QACH,OAAO,CAAC,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC,WAAW,CAC3C,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAC5B,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,cAAc,CAChD,CACF,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AACpD,CAAC,CAAC;AArCW,QAAA,iCAAiC,qCAqC5C"}
|
|
@@ -3,6 +3,22 @@ import type { ZodSchema } from 'zod';
|
|
|
3
3
|
/**
|
|
4
4
|
* .what = validates event.body against zod schema for API Gateway
|
|
5
5
|
* .why = API Gateway events have body as separate property, validate just the body
|
|
6
|
+
*
|
|
7
|
+
* .note = this family validates `event.body` rather than the whole event because
|
|
8
|
+
* `request.event` must stay http-shaped through the chain: `@middy/http-cors` reads
|
|
9
|
+
* `request.event.headers` and derives the http method from `request.event` in its
|
|
10
|
+
* `after` hook (`@middy/http-cors/index.js:38,83,106`). so the body cannot take the
|
|
11
|
+
* event's place, and this cannot yet collapse into `genZodEventValidationMiddleware`
|
|
12
|
+
*
|
|
13
|
+
* .note = the constraint is SHARPER than "http-shaped", and the precise form is what any
|
|
14
|
+
* future input translate must honor. cors picks its method extractor by
|
|
15
|
+
* `request.event.version ?? '1.0'` (`index.js:38,106`), and `UnifiedApiGatewayEvent`
|
|
16
|
+
* declares no `version` — so cors always falls to its **v1** extractor,
|
|
17
|
+
* `(event) => event.httpMethod`. that works only because the unified shape happens to
|
|
18
|
+
* expose `httpMethod` and `headers` at its top level under v1's own names. so the real
|
|
19
|
+
* requirement is: whatever occupies `request.event` when cors's `after` runs must keep
|
|
20
|
+
* `httpMethod` and `headers` readable at the top level, with v1 names. an arbitrary
|
|
21
|
+
* `TInput` cannot promise that, which is why the input translate has no home here yet
|
|
6
22
|
*/
|
|
7
23
|
export declare const genZodBodyValidationMiddleware: <TInput>(input: {
|
|
8
24
|
schema: ZodSchema<TInput>;
|
|
@@ -5,6 +5,22 @@ const getValidationError_1 = require("../../middleware/getValidationError");
|
|
|
5
5
|
/**
|
|
6
6
|
* .what = validates event.body against zod schema for API Gateway
|
|
7
7
|
* .why = API Gateway events have body as separate property, validate just the body
|
|
8
|
+
*
|
|
9
|
+
* .note = this family validates `event.body` rather than the whole event because
|
|
10
|
+
* `request.event` must stay http-shaped through the chain: `@middy/http-cors` reads
|
|
11
|
+
* `request.event.headers` and derives the http method from `request.event` in its
|
|
12
|
+
* `after` hook (`@middy/http-cors/index.js:38,83,106`). so the body cannot take the
|
|
13
|
+
* event's place, and this cannot yet collapse into `genZodEventValidationMiddleware`
|
|
14
|
+
*
|
|
15
|
+
* .note = the constraint is SHARPER than "http-shaped", and the precise form is what any
|
|
16
|
+
* future input translate must honor. cors picks its method extractor by
|
|
17
|
+
* `request.event.version ?? '1.0'` (`index.js:38,106`), and `UnifiedApiGatewayEvent`
|
|
18
|
+
* declares no `version` — so cors always falls to its **v1** extractor,
|
|
19
|
+
* `(event) => event.httpMethod`. that works only because the unified shape happens to
|
|
20
|
+
* expose `httpMethod` and `headers` at its top level under v1's own names. so the real
|
|
21
|
+
* requirement is: whatever occupies `request.event` when cors's `after` runs must keep
|
|
22
|
+
* `httpMethod` and `headers` readable at the top level, with v1 names. an arbitrary
|
|
23
|
+
* `TInput` cannot promise that, which is why the input translate has no home here yet
|
|
8
24
|
*/
|
|
9
25
|
const genZodBodyValidationMiddleware = (input) => {
|
|
10
26
|
const before = async (request) => {
|
|
@@ -14,6 +30,22 @@ const genZodBodyValidationMiddleware = (input) => {
|
|
|
14
30
|
throw (0, getValidationError_1.getValidationError)({ error: result.error });
|
|
15
31
|
}
|
|
16
32
|
// replace body with parsed (transformed) result
|
|
33
|
+
/**
|
|
34
|
+
* .note = DELIBERATE MUTATION — `request` is middy's only channel to hand a value onward,
|
|
35
|
+
* and `event` is an ALIAS of `request.event`, so this writes through to the chain
|
|
36
|
+
*
|
|
37
|
+
* ⚠️ .note = this site escaped the first sweep of this class, because that grep anchored on
|
|
38
|
+
* `request.` and an alias hides the receiver. a mutation through a local alias is
|
|
39
|
+
* the same mutation — so the pattern must match the ALIAS too
|
|
40
|
+
* (`^\s*(event|response|payload)\.\w+\s*=`), which finds exactly this one
|
|
41
|
+
*
|
|
42
|
+
* .as = `UnifiedApiGatewayEvent.body` is the PRE-validation shape (a string, or a parsed
|
|
43
|
+
* json value), while `result.data` is `TInput` — the POST-validation domain shape.
|
|
44
|
+
* the two are unrelated by declaration, which is exactly right: this assignment IS
|
|
45
|
+
* the step that changes which of them lives in the slot
|
|
46
|
+
* .removal = drops once the input-side translator lands and the chain carries `inputAfter`
|
|
47
|
+
* in its own slot rather than back in the event's `body` — the 🚧 F31 fulcrum
|
|
48
|
+
*/
|
|
17
49
|
event.body = result.data;
|
|
18
50
|
};
|
|
19
51
|
return { before };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genZodBodyValidationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.ts"],"names":[],"mappings":";;;AAGA,4EAAyE;AAGzE
|
|
1
|
+
{"version":3,"file":"genZodBodyValidationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.ts"],"names":[],"mappings":";;;AAGA,4EAAyE;AAGzE;;;;;;;;;;;;;;;;;;;GAmBG;AACI,MAAM,8BAA8B,GAAG,CAAS,KAEtD,EAEC,EAAE;IACF,MAAM,MAAM,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7D,MAAM,KAAK,GAAG,OAAO,CAAC,KAA+B,CAAC;QACtD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,IAAA,uCAAkB,EAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;QACpD,CAAC;QACD,gDAAgD;QAChD;;;;;;;;;;;;;;;WAeG;QACH,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,IAAoC,CAAC;IAC3D,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AAhCW,QAAA,8BAA8B,kCAgCzC"}
|
|
@@ -3,7 +3,7 @@ import type { Context } from 'aws-lambda';
|
|
|
3
3
|
import type { ContextLogTrail } from 'sdk-logs';
|
|
4
4
|
import type { ZodSchema } from 'zod';
|
|
5
5
|
import type { ContextAwsLambdaServer } from '../../../domain.objects/ContextAwsLambdaServer';
|
|
6
|
-
import type {
|
|
6
|
+
import type { TranslateLog } from '../TranslateLog';
|
|
7
7
|
/**
|
|
8
8
|
* .what = wrapped payload format: event nested under `event` key with trail
|
|
9
9
|
* .why = askLambdaEndpoint sends this format for trail propagation
|
|
@@ -45,7 +45,7 @@ export type GenLambdaEndpointInput<TInput, TOutput> = {
|
|
|
45
45
|
output: ZodSchema<TOutput>;
|
|
46
46
|
};
|
|
47
47
|
invoke: EndpointOperation<TInput, TOutput>;
|
|
48
|
-
logTranslate?:
|
|
48
|
+
logTranslate?: TranslateLog;
|
|
49
49
|
};
|
|
50
50
|
/**
|
|
51
51
|
* .what = sdk contract type for genLambdaEndpoint context
|
|
@@ -55,24 +55,8 @@ export type GenLambdaEndpointInput<TInput, TOutput> = {
|
|
|
55
55
|
export type GenLambdaEndpointContext = ContextAwsLambdaServer;
|
|
56
56
|
/**
|
|
57
57
|
* .what = generates a lambda handler with validation and trail context
|
|
58
|
-
* .why = standardizes handler creation with schema validation and observability
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* - uses middy middleware chain
|
|
62
|
-
* - badRequestError middleware returns error object instead of throw
|
|
63
|
-
* - internalServiceError middleware logs errors loudly
|
|
64
|
-
* - ioLogger middleware logs input/output for debug
|
|
65
|
-
* - validation middleware validates input against schema
|
|
66
|
-
*
|
|
67
|
-
* additions for sdk-aws-lambda:
|
|
68
|
-
* - trail middleware injects log with trail context
|
|
69
|
-
* - output validation via zod schema
|
|
58
|
+
* .why = standardizes handler creation with schema validation and observability. the chain:
|
|
59
|
+
* constraint error (a caller fault becomes a response object, never a throw), internal
|
|
60
|
+
* service error (logs loudly), io logger, trail, input + output validation
|
|
70
61
|
*/
|
|
71
|
-
export declare const genLambdaEndpoint: <TInput, TOutput>(input:
|
|
72
|
-
schema: {
|
|
73
|
-
input: ZodSchema<TInput>;
|
|
74
|
-
output: ZodSchema<TOutput>;
|
|
75
|
-
};
|
|
76
|
-
invoke: EndpointOperation<TInput, TOutput>;
|
|
77
|
-
logTranslate?: IoLogTranslate;
|
|
78
|
-
}, context?: ContextAwsLambdaServer) => middy.MiddyfiedHandler<LambdaHandlerInput<TInput>, TOutput, Error, Context>;
|
|
62
|
+
export declare const genLambdaEndpoint: <TInput, TOutput>(input: GenLambdaEndpointInput<TInput, TOutput>, context?: ContextAwsLambdaServer) => middy.MiddyfiedHandler<LambdaHandlerInput<TInput>, TOutput, Error, Context>;
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.genLambdaEndpoint = void 0;
|
|
7
7
|
const core_1 = __importDefault(require("@middy/core"));
|
|
8
|
+
const asContextLogTrail_1 = require("../asContextLogTrail");
|
|
8
9
|
const genConstraintErrorMiddleware_1 = require("../middleware/genConstraintErrorMiddleware");
|
|
9
10
|
const genInternalServiceErrorMiddleware_1 = require("../middleware/genInternalServiceErrorMiddleware");
|
|
10
11
|
const genIntrospectionMiddleware_1 = require("../middleware/genIntrospectionMiddleware");
|
|
@@ -14,24 +15,18 @@ const getValidatedOutput_1 = require("../middleware/getValidatedOutput");
|
|
|
14
15
|
const genZodEventValidationMiddleware_1 = require("./middleware/genZodEventValidationMiddleware");
|
|
15
16
|
/**
|
|
16
17
|
* .what = generates a lambda handler with validation and trail context
|
|
17
|
-
* .why = standardizes handler creation with schema validation and observability
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* - uses middy middleware chain
|
|
21
|
-
* - badRequestError middleware returns error object instead of throw
|
|
22
|
-
* - internalServiceError middleware logs errors loudly
|
|
23
|
-
* - ioLogger middleware logs input/output for debug
|
|
24
|
-
* - validation middleware validates input against schema
|
|
25
|
-
*
|
|
26
|
-
* additions for sdk-aws-lambda:
|
|
27
|
-
* - trail middleware injects log with trail context
|
|
28
|
-
* - output validation via zod schema
|
|
18
|
+
* .why = standardizes handler creation with schema validation and observability. the chain:
|
|
19
|
+
* constraint error (a caller fault becomes a response object, never a throw), internal
|
|
20
|
+
* service error (logs loudly), io logger, trail, input + output validation
|
|
29
21
|
*/
|
|
30
|
-
const genLambdaEndpoint = (
|
|
22
|
+
const genLambdaEndpoint = (
|
|
23
|
+
// typed by the EXPORTED contract rather than an inline restatement — the two were hand-synced
|
|
24
|
+
// before, and a rename that reached only one of them would have compiled
|
|
25
|
+
input, context) => {
|
|
31
26
|
// build logic that invokes user handler and validates output
|
|
32
27
|
const logic = async (event, lambdaContext) => {
|
|
33
|
-
//
|
|
34
|
-
const log = lambdaContext
|
|
28
|
+
// read the trail log `genTrailMiddleware` wrote; the cast lives in the shared reader
|
|
29
|
+
const { log } = (0, asContextLogTrail_1.asContextLogTrail)({ context: lambdaContext });
|
|
35
30
|
// invoke user handler
|
|
36
31
|
const response = await input.invoke({ event }, { log });
|
|
37
32
|
// validate output and return typed result
|
|
@@ -44,11 +39,22 @@ const genLambdaEndpoint = (input, context) => {
|
|
|
44
39
|
// 4. introspection (onBefore) - intercepts introspect requests, returns schema
|
|
45
40
|
// 5. validation (onBefore) - validates event against schema
|
|
46
41
|
const middlewares = [
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
/**
|
|
43
|
+
* .note = this family's response IS its payload, so a caller fault renders as the body
|
|
44
|
+
* itself — and a SERVER fault is declined (`false`), which lets the invocation FAIL
|
|
45
|
+
* so cloudwatch records it and the caller may retry
|
|
46
|
+
*/
|
|
47
|
+
(0, genConstraintErrorMiddleware_1.genConstraintErrorMiddleware)({ asOutputAfter: (body) => body }),
|
|
48
|
+
(0, genInternalServiceErrorMiddleware_1.genInternalServiceErrorMiddleware)({ asOutputAfter: false }),
|
|
49
49
|
(0, genTrailMiddleware_1.genTrailMiddleware)(),
|
|
50
50
|
(0, genIoLoggerMiddleware_1.genIoLoggerMiddleware)({ logTranslate: input.logTranslate }),
|
|
51
|
-
(0, genIntrospectionMiddleware_1.genIntrospectionMiddleware)({
|
|
51
|
+
(0, genIntrospectionMiddleware_1.genIntrospectionMiddleware)({
|
|
52
|
+
schema: input.schema,
|
|
53
|
+
env: context?.env,
|
|
54
|
+
// this family carries `inputAfter` at `event` itself, and its response IS its payload
|
|
55
|
+
asInputAfter: (request) => request.event,
|
|
56
|
+
asOutputAfter: (schema) => schema,
|
|
57
|
+
}),
|
|
52
58
|
(0, genZodEventValidationMiddleware_1.genZodEventValidationMiddleware)({ schema: input.schema.input }),
|
|
53
59
|
];
|
|
54
60
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genLambdaEndpoint.forAskEndpoint.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAgC;AAMhC,6FAA0F;AAC1F,uGAAoG;AACpG,yFAAsF;
|
|
1
|
+
{"version":3,"file":"genLambdaEndpoint.forAskEndpoint.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAgC;AAMhC,4DAAyD;AACzD,6FAA0F;AAC1F,uGAAoG;AACpG,yFAAsF;AACtF,+EAA4E;AAC5E,yEAAsE;AACtE,yEAAsE;AAEtE,kGAA+F;AAsD/F;;;;;GAKG;AACI,MAAM,iBAAiB,GAAG;AAC/B,8FAA8F;AAC9F,yEAAyE;AACzE,KAA8C,EAC9C,OAAgC,EAMhC,EAAE;IACF,6DAA6D;IAC7D,MAAM,KAAK,GAAG,KAAK,EACjB,KAAa,EACb,aAAsB,EACJ,EAAE;QACpB,qFAAqF;QACrF,MAAM,EAAE,GAAG,EAAE,GAAG,IAAA,qCAAiB,EAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC;QAE9D,sBAAsB;QACtB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QAExD,0CAA0C;QAC1C,OAAO,IAAA,uCAAkB,EAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACvE,CAAC,CAAC;IAEF,4BAA4B;IAC5B,wFAAwF;IACxF,2GAA2G;IAC3G,6CAA6C;IAC7C,+EAA+E;IAC/E,4DAA4D;IAC5D,MAAM,WAAW,GAAG;QAClB;;;;WAIG;QACH,IAAA,2DAA4B,EAAC,EAAE,aAAa,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;QAC/D,IAAA,qEAAiC,EAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;QAC3D,IAAA,uCAAkB,GAAE;QACpB,IAAA,6CAAqB,EAAC,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC;QAC3D,IAAA,uDAA0B,EAAC;YACzB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,GAAG,EAAE,OAAO,EAAE,GAAG;YACjB,sFAAsF;YACtF,YAAY,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK;YACxC,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;SAClC,CAAC;QACF,IAAA,iEAA+B,EAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KAChE,CAAC;IAEF;;;;OAIG;IACH,OAAO,IAAA,cAAK,EACV,KAGqB,CACtB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AACrB,CAAC,CAAC;AA/DW,QAAA,iBAAiB,qBA+D5B"}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import type middy from '@middy/core';
|
|
2
2
|
import type { ZodSchema } from 'zod';
|
|
3
3
|
/**
|
|
4
|
-
* .what = validates entire event against zod schema
|
|
5
|
-
* .why =
|
|
4
|
+
* .what = validates the entire event against a zod schema
|
|
5
|
+
* .why = the ask-endpoint family reaches this step with the caller's value AT `request.event`,
|
|
6
|
+
* so the whole event is what the schema describes
|
|
7
|
+
*
|
|
8
|
+
* .note = its api-gateway peer, `genZodBodyValidationMiddleware`, validates `event.body`
|
|
9
|
+
* instead, because that chain must keep `request.event` http-shaped. the two collapse
|
|
10
|
+
* into one validator at the common ancestor the moment `inputAfter` has ONE home
|
|
11
|
+
* across both chains — see the 🚧 note in
|
|
12
|
+
* `.behavior/v2026_08_03.feat-apigateway-wire-response/5.1.execution.from_vision.yield.md`.
|
|
13
|
+
* this stays at the leaf until then, because a lift with one consumer is speculative
|
|
14
|
+
* (rule.prefer.most-common-denominator)
|
|
6
15
|
*/
|
|
7
16
|
export declare const genZodEventValidationMiddleware: <TInput>(input: {
|
|
8
17
|
schema: ZodSchema<TInput>;
|
|
@@ -3,8 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.genZodEventValidationMiddleware = void 0;
|
|
4
4
|
const getValidationError_1 = require("../../middleware/getValidationError");
|
|
5
5
|
/**
|
|
6
|
-
* .what = validates entire event against zod schema
|
|
7
|
-
* .why =
|
|
6
|
+
* .what = validates the entire event against a zod schema
|
|
7
|
+
* .why = the ask-endpoint family reaches this step with the caller's value AT `request.event`,
|
|
8
|
+
* so the whole event is what the schema describes
|
|
9
|
+
*
|
|
10
|
+
* .note = its api-gateway peer, `genZodBodyValidationMiddleware`, validates `event.body`
|
|
11
|
+
* instead, because that chain must keep `request.event` http-shaped. the two collapse
|
|
12
|
+
* into one validator at the common ancestor the moment `inputAfter` has ONE home
|
|
13
|
+
* across both chains — see the 🚧 note in
|
|
14
|
+
* `.behavior/v2026_08_03.feat-apigateway-wire-response/5.1.execution.from_vision.yield.md`.
|
|
15
|
+
* this stays at the leaf until then, because a lift with one consumer is speculative
|
|
16
|
+
* (rule.prefer.most-common-denominator)
|
|
8
17
|
*/
|
|
9
18
|
const genZodEventValidationMiddleware = (input) => {
|
|
10
19
|
const before = async (request) => {
|
|
@@ -13,6 +22,7 @@ const genZodEventValidationMiddleware = (input) => {
|
|
|
13
22
|
throw (0, getValidationError_1.getValidationError)({ error: result.error });
|
|
14
23
|
}
|
|
15
24
|
// replace event with parsed (transformed) result
|
|
25
|
+
// .note = DELIBERATE MUTATION — `request` is middy's only channel to hand a value onward
|
|
16
26
|
request.event = result.data;
|
|
17
27
|
};
|
|
18
28
|
return { before };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genZodEventValidationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.ts"],"names":[],"mappings":";;;AAGA,4EAAyE;AAEzE
|
|
1
|
+
{"version":3,"file":"genZodEventValidationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.ts"],"names":[],"mappings":";;;AAGA,4EAAyE;AAEzE;;;;;;;;;;;;GAYG;AACI,MAAM,+BAA+B,GAAG,CAAS,KAEvD,EAEC,EAAE;IACF,MAAM,MAAM,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7D,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACrD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,IAAA,uCAAkB,EAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;QACpD,CAAC;QACD,iDAAiD;QACjD,yFAAyF;QACzF,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AAhBW,QAAA,+BAA+B,mCAgB1C"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ContextLogTrail } from 'sdk-logs';
|
|
2
|
+
/**
|
|
3
|
+
* .what = the fields THIS SDK adds onto the lambda context, beyond aws's own `Context`
|
|
4
|
+
* .why = `genTrailMiddleware` writes both of these, and six middleware sites read them. each
|
|
5
|
+
* had restated the same inline cast shape, so a change to either field meant six edits
|
|
6
|
+
* (rule.forbid.parallel-codepaths)
|
|
7
|
+
*
|
|
8
|
+
* .note = both are OPTIONAL by honest necessity, never by preference. a middleware's array
|
|
9
|
+
* position decides whether trail has run yet, so a reader placed above trail genuinely
|
|
10
|
+
* sees `undefined` — that is the live `handler.input` defect, and a required type here
|
|
11
|
+
* would state a guarantee the chain does not keep
|
|
12
|
+
*/
|
|
13
|
+
export interface ContextTrailed {
|
|
14
|
+
log?: ContextLogTrail['log'];
|
|
15
|
+
isContempCaller?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* .what = reads the sdk-managed fields off a middy request's context
|
|
19
|
+
* .why = ONE documented cast, in place of the same cast restated at every read site
|
|
20
|
+
* (rule.forbid.as-cast, rule.require.named-transformers)
|
|
21
|
+
*
|
|
22
|
+
* .as = middy types `request.context` as aws-lambda's `Context`, which declares neither `log`
|
|
23
|
+
* nor `isContempCaller`. this sdk puts both there itself, via `genTrailMiddleware`, so the
|
|
24
|
+
* cast asserts what the sdk's own middleware wrote — never an outside claim
|
|
25
|
+
*
|
|
26
|
+
* .removal = removable when middy's `Request` carries a caller-declared context type parameter
|
|
27
|
+
* this chain can bind, such that `MiddyfiedHandler`'s `TContext` reaches a middleware's
|
|
28
|
+
* `request.context`. until then no type-level path exists from what `genTrailMiddleware`
|
|
29
|
+
* writes to what a later middleware reads
|
|
30
|
+
*
|
|
31
|
+
* .note = an absent context yields `{}` rather than a throw. a reader must handle the
|
|
32
|
+
* trail-has-not-run case regardless (see `.note` on `ContextTrailed`), so a throw here
|
|
33
|
+
* would convert a documented fact about array order into a crash
|
|
34
|
+
*/
|
|
35
|
+
export declare const asContextTrailed: (input: {
|
|
36
|
+
context: unknown;
|
|
37
|
+
}) => ContextTrailed;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asContextTrailed = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = reads the sdk-managed fields off a middy request's context
|
|
6
|
+
* .why = ONE documented cast, in place of the same cast restated at every read site
|
|
7
|
+
* (rule.forbid.as-cast, rule.require.named-transformers)
|
|
8
|
+
*
|
|
9
|
+
* .as = middy types `request.context` as aws-lambda's `Context`, which declares neither `log`
|
|
10
|
+
* nor `isContempCaller`. this sdk puts both there itself, via `genTrailMiddleware`, so the
|
|
11
|
+
* cast asserts what the sdk's own middleware wrote — never an outside claim
|
|
12
|
+
*
|
|
13
|
+
* .removal = removable when middy's `Request` carries a caller-declared context type parameter
|
|
14
|
+
* this chain can bind, such that `MiddyfiedHandler`'s `TContext` reaches a middleware's
|
|
15
|
+
* `request.context`. until then no type-level path exists from what `genTrailMiddleware`
|
|
16
|
+
* writes to what a later middleware reads
|
|
17
|
+
*
|
|
18
|
+
* .note = an absent context yields `{}` rather than a throw. a reader must handle the
|
|
19
|
+
* trail-has-not-run case regardless (see `.note` on `ContextTrailed`), so a throw here
|
|
20
|
+
* would convert a documented fact about array order into a crash
|
|
21
|
+
*/
|
|
22
|
+
const asContextTrailed = (input) => (input.context ?? {});
|
|
23
|
+
exports.asContextTrailed = asContextTrailed;
|
|
24
|
+
//# sourceMappingURL=asContextTrailed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asContextTrailed.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/asContextTrailed.ts"],"names":[],"mappings":";;;AAkBA;;;;;;;;;;;;;;;;;GAiBG;AACI,MAAM,gBAAgB,GAAG,CAAC,KAA2B,EAAkB,EAAE,CAC9E,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAmB,CAAC;AAD7B,QAAA,gBAAgB,oBACa"}
|
package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type middy from '@middy/core';
|
|
2
|
-
|
|
3
|
-
statusCode: number;
|
|
4
|
-
body: string;
|
|
5
|
-
headers?: Record<string, string>;
|
|
6
|
-
}
|
|
2
|
+
import { type LambdaEndpointErrorResponseBodyAncient, type LambdaEndpointErrorResponseBodyContemp } from './getErrorResponseBody';
|
|
7
3
|
/**
|
|
8
4
|
* .what = middleware that handles ConstraintError (and legacy BadRequestError)
|
|
9
|
-
* .why = ConstraintError = caller fault, not server fault
|
|
10
|
-
*
|
|
11
|
-
* -
|
|
5
|
+
* .why = ConstraintError = caller fault, not server fault, so the invocation SUCCEEDS either
|
|
6
|
+
* way — a caller fault must not emit a cloudwatch error nor signal a retry
|
|
7
|
+
* (invariant.badrequesterror-not-lambda-error)
|
|
8
|
+
*
|
|
9
|
+
* .note = this middleware does NOT know which families exist. it builds the error BODY and
|
|
10
|
+
* hands it to the family's own `asOutputAfter`, so the wire shape is the family's to
|
|
11
|
+
* state. a flag read here would fork one guarantee across two paths
|
|
12
|
+
* (rule.forbid.parallel-codepaths)
|
|
12
13
|
*
|
|
13
14
|
* note: InternalServiceError is handled by genInternalServiceErrorMiddleware
|
|
14
15
|
*
|
|
@@ -16,8 +17,15 @@ export interface ApiGatewayResponse {
|
|
|
16
17
|
* flat errorType/errorMessage format
|
|
17
18
|
* contemp callers receive nested { error: { _serde, class, message } }
|
|
18
19
|
*/
|
|
19
|
-
export declare const genConstraintErrorMiddleware: (opts
|
|
20
|
-
|
|
20
|
+
export declare const genConstraintErrorMiddleware: (opts: {
|
|
21
|
+
/**
|
|
22
|
+
* .what = renders the error body as this family's `outputAfter`
|
|
23
|
+
* .why = the two families owe DIFFERENT shapes for the same fault: api-gateway owes a wire
|
|
24
|
+
* payload with a 400 and a stringified body, while an ask-endpoint response IS its
|
|
25
|
+
* payload. only the family knows which, so the family supplies it — never a flag read
|
|
26
|
+
* here (rule.forbid.parallel-codepaths)
|
|
27
|
+
*/
|
|
28
|
+
asOutputAfter: (body: LambdaEndpointErrorResponseBodyContemp | LambdaEndpointErrorResponseBodyAncient) => unknown;
|
|
21
29
|
}) => {
|
|
22
30
|
onError: middy.MiddlewareFn<any, any>;
|
|
23
31
|
};
|