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,13 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.genConstraintErrorMiddleware = void 0;
|
|
4
|
+
const asContextTrailed_1 = require("./asContextTrailed");
|
|
4
5
|
const getErrorResponseBody_1 = require("./getErrorResponseBody");
|
|
5
6
|
const getIsConstraintError_1 = require("./getIsConstraintError");
|
|
6
7
|
/**
|
|
7
8
|
* .what = middleware that handles ConstraintError (and legacy BadRequestError)
|
|
8
|
-
* .why = ConstraintError = caller fault, not server fault
|
|
9
|
-
*
|
|
10
|
-
* -
|
|
9
|
+
* .why = ConstraintError = caller fault, not server fault, so the invocation SUCCEEDS either
|
|
10
|
+
* way — a caller fault must not emit a cloudwatch error nor signal a retry
|
|
11
|
+
* (invariant.badrequesterror-not-lambda-error)
|
|
12
|
+
*
|
|
13
|
+
* .note = this middleware does NOT know which families exist. it builds the error BODY and
|
|
14
|
+
* hands it to the family's own `asOutputAfter`, so the wire shape is the family's to
|
|
15
|
+
* state. a flag read here would fork one guarantee across two paths
|
|
16
|
+
* (rule.forbid.parallel-codepaths)
|
|
11
17
|
*
|
|
12
18
|
* note: InternalServiceError is handled by genInternalServiceErrorMiddleware
|
|
13
19
|
*
|
|
@@ -26,30 +32,21 @@ const genConstraintErrorMiddleware = (opts) => {
|
|
|
26
32
|
if (!isConstraintError)
|
|
27
33
|
return;
|
|
28
34
|
// detect if caller is contemp (sent wrapped payload) or ancient
|
|
29
|
-
const
|
|
30
|
-
|
|
35
|
+
const { isContempCaller = false } = (0, asContextTrailed_1.asContextTrailed)({
|
|
36
|
+
context: request.context,
|
|
37
|
+
});
|
|
31
38
|
// build error response body via transformer based on caller type
|
|
32
39
|
const body = isContempCaller
|
|
33
40
|
? (0, getErrorResponseBody_1.getErrorResponseBodyContemp)({ error, errorClass: 'ConstraintError' })
|
|
34
41
|
: (0, getErrorResponseBody_1.getErrorResponseBodyAncient)({ error, errorType: 'BadRequestError' });
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
body: JSON.stringify(body),
|
|
44
|
-
headers: {
|
|
45
|
-
'Content-Type': 'application/json',
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
// for standard handler: return error response object
|
|
51
|
-
// lambda invocation succeeds, caller detects error shape and throws
|
|
52
|
-
request.response = body;
|
|
42
|
+
/**
|
|
43
|
+
* .what = hand the wire whatever shape this family owes for a caller fault
|
|
44
|
+
* .why = the lambda invocation SUCCEEDS either way — a caller fault must not emit a
|
|
45
|
+
* cloudwatch error nor signal a retry (invariant.badrequesterror-not-lambda-error)
|
|
46
|
+
*
|
|
47
|
+
* .note = DELIBERATE MUTATION — `request` is middy's only channel to hand a value onward
|
|
48
|
+
*/
|
|
49
|
+
request.response = opts.asOutputAfter(body);
|
|
53
50
|
};
|
|
54
51
|
return { onError };
|
|
55
52
|
};
|
package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genConstraintErrorMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.ts"],"names":[],"mappings":";;;AAEA,iEAKgC;AAChC,iEAA8D;
|
|
1
|
+
{"version":3,"file":"genConstraintErrorMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.ts"],"names":[],"mappings":";;;AAEA,yDAAsD;AACtD,iEAKgC;AAChC,iEAA8D;AAE9D;;;;;;;;;;;;;;;;GAgBG;AACI,MAAM,4BAA4B,GAAG,CAAC,IAa5C,EAEC,EAAE;IACF,MAAM,OAAO,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,KAAK;YAAE,OAAO;QAEnB,qEAAqE;QACrE,uEAAuE;QACvE,MAAM,iBAAiB,GAAG,IAAA,2CAAoB,EAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,iBAAiB;YAAE,OAAO;QAE/B,gEAAgE;QAChE,MAAM,EAAE,eAAe,GAAG,KAAK,EAAE,GAAG,IAAA,mCAAgB,EAAC;YACnD,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC,CAAC;QAEH,iEAAiE;QACjE,MAAM,IAAI,GAEmC,eAAe;YAC1D,CAAC,CAAC,IAAA,kDAA2B,EAAC,EAAE,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC;YACvE,CAAC,CAAC,IAAA,kDAA2B,EAAC,EAAE,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC,CAAC;QAEzE;;;;;;WAMG;QACH,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC,CAAC;AA/CW,QAAA,4BAA4B,gCA+CvC"}
|
package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.d.ts
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
import type middy from '@middy/core';
|
|
2
2
|
/**
|
|
3
3
|
* .what = middleware that logs and handles internal service errors
|
|
4
|
-
* .why = all errors that are not
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* .why = all errors that are not a ConstraintError are internal service errors, so each one is
|
|
5
|
+
* logged loudly and never echoed to the wire — no internal detail, no secret
|
|
6
|
+
*
|
|
7
|
+
* .note = this middleware does NOT know which families exist. the family states what a server
|
|
8
|
+
* fault owes the wire via `asOutputAfter` — and that includes the choice to DECLINE and
|
|
9
|
+
* let the invocation fail. a flag read here would fork one guarantee across two paths
|
|
10
|
+
* (rule.forbid.parallel-codepaths)
|
|
8
11
|
*/
|
|
9
|
-
export declare const genInternalServiceErrorMiddleware: (opts
|
|
10
|
-
|
|
12
|
+
export declare const genInternalServiceErrorMiddleware: (opts: {
|
|
13
|
+
/**
|
|
14
|
+
* .what = renders a server fault as this family's `outputAfter`, or declines to answer
|
|
15
|
+
* .why = the two families make DIFFERENT guarantees for the same fault, so this is not one
|
|
16
|
+
* shape with two renderings (rule.forbid.parallel-codepaths exempts genuinely
|
|
17
|
+
* different guarantees — it forbids only the FLAG that selected between them):
|
|
18
|
+
*
|
|
19
|
+
* function -> answer the wire with this shape; the invocation SUCCEEDS, since http demands
|
|
20
|
+
* a response and a hung request is worse than a 500
|
|
21
|
+
* false -> DISARMED; rethrow, so the invocation FAILS, cloudwatch records the error, and
|
|
22
|
+
* the caller may retry — which is the right contract for a server fault when no
|
|
23
|
+
* http client waits on it
|
|
24
|
+
*
|
|
25
|
+
* .note = the off-state is `false`, never absent. an absent field would disable a guarantee by
|
|
26
|
+
* omission, so a caller who forgot it would be indistinguishable from one who chose it
|
|
27
|
+
* (rule.require.explicit-optout), and `false` differs maximally in form from
|
|
28
|
+
* `undefined` (rule.forbid.opposite-senses-on-undefined-and-null)
|
|
29
|
+
*/
|
|
30
|
+
asOutputAfter: ((input: {
|
|
31
|
+
error: Error;
|
|
32
|
+
exid: string | null;
|
|
33
|
+
}) => unknown) | false;
|
|
11
34
|
}) => {
|
|
12
35
|
onError: middy.MiddlewareFn<any, any>;
|
|
13
36
|
};
|
package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.genInternalServiceErrorMiddleware = void 0;
|
|
4
|
+
const asContextTrailed_1 = require("./asContextTrailed");
|
|
4
5
|
const getIsConstraintError_1 = require("./getIsConstraintError");
|
|
5
6
|
/**
|
|
6
7
|
* .what = middleware that logs and handles internal service errors
|
|
7
|
-
* .why = all errors that are not
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* .why = all errors that are not a ConstraintError are internal service errors, so each one is
|
|
9
|
+
* logged loudly and never echoed to the wire — no internal detail, no secret
|
|
10
|
+
*
|
|
11
|
+
* .note = this middleware does NOT know which families exist. the family states what a server
|
|
12
|
+
* fault owes the wire via `asOutputAfter` — and that includes the choice to DECLINE and
|
|
13
|
+
* let the invocation fail. a flag read here would fork one guarantee across two paths
|
|
14
|
+
* (rule.forbid.parallel-codepaths)
|
|
11
15
|
*/
|
|
12
16
|
const genInternalServiceErrorMiddleware = (opts) => {
|
|
13
17
|
const onError = async (request) => {
|
|
@@ -19,36 +23,27 @@ const genInternalServiceErrorMiddleware = (opts) => {
|
|
|
19
23
|
const isBadRequest = (0, getIsConstraintError_1.getIsConstraintError)({ error });
|
|
20
24
|
if (isBadRequest)
|
|
21
25
|
return;
|
|
22
|
-
//
|
|
23
|
-
const log = request.context
|
|
26
|
+
// read the sdk-managed context once — trail may not have run yet
|
|
27
|
+
const { log } = (0, asContextTrailed_1.asContextTrailed)({ context: request.context });
|
|
24
28
|
// log the error via context.log or fallback to console
|
|
25
29
|
const logError = log?.error ?? console.error;
|
|
26
30
|
logError('handler.error', {
|
|
27
31
|
errorMessage: error.message,
|
|
28
32
|
stackTrace: error.stack,
|
|
29
33
|
});
|
|
30
|
-
//
|
|
31
|
-
if (opts
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}),
|
|
44
|
-
headers: { 'Content-Type': 'application/json' },
|
|
45
|
-
};
|
|
46
|
-
// return undefined so that middy knows we handled the error
|
|
47
|
-
// prevents cloudWatch from classifying this as a lambda error
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
// if we didn't handle the error above, rethrow it
|
|
51
|
-
throw error;
|
|
34
|
+
// a family that declines to answer lets the invocation fail, so cloudwatch records it
|
|
35
|
+
if (opts.asOutputAfter === false)
|
|
36
|
+
throw error;
|
|
37
|
+
// get exid from trail context if available for correlation
|
|
38
|
+
const exid = log?.trail?.exid ?? null;
|
|
39
|
+
/**
|
|
40
|
+
* .what = answer the wire with this family's shape for a server fault
|
|
41
|
+
* .why = middy treats a set `request.response` as "handled", which keeps the invocation a
|
|
42
|
+
* SUCCESS and stops cloudwatch from a lambda-error classification
|
|
43
|
+
*
|
|
44
|
+
* .note = DELIBERATE MUTATION — `request` is middy's only channel to hand a value onward
|
|
45
|
+
*/
|
|
46
|
+
request.response = opts.asOutputAfter({ error, exid });
|
|
52
47
|
};
|
|
53
48
|
return { onError };
|
|
54
49
|
};
|
package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genInternalServiceErrorMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.ts"],"names":[],"mappings":";;;AAEA,iEAA8D;AAE9D
|
|
1
|
+
{"version":3,"file":"genInternalServiceErrorMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.ts"],"names":[],"mappings":";;;AAEA,yDAAsD;AACtD,iEAA8D;AAE9D;;;;;;;;;GASG;AACI,MAAM,iCAAiC,GAAG,CAAC,IAqBjD,EAEC,EAAE;IACF,MAAM,OAAO,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,KAAK;YAAE,OAAO;QAEnB,4DAA4D;QAC5D,yEAAyE;QACzE,MAAM,YAAY,GAAG,IAAA,2CAAoB,EAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QACrD,IAAI,YAAY;YAAE,OAAO;QAEzB,iEAAiE;QACjE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAA,mCAAgB,EAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAE/D,uDAAuD;QACvD,MAAM,QAAQ,GAAG,GAAG,EAAE,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC;QAC7C,QAAQ,CAAC,eAAe,EAAE;YACxB,YAAY,EAAE,KAAK,CAAC,OAAO;YAC3B,UAAU,EAAE,KAAK,CAAC,KAAK;SACxB,CAAC,CAAC;QAEH,sFAAsF;QACtF,IAAI,IAAI,CAAC,aAAa,KAAK,KAAK;YAAE,MAAM,KAAK,CAAC;QAE9C,2DAA2D;QAC3D,MAAM,IAAI,GAAG,GAAG,EAAE,KAAK,EAAE,IAAI,IAAI,IAAI,CAAC;QAEtC;;;;;;WAMG;QACH,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC,CAAC;AA3DW,QAAA,iCAAiC,qCA2D5C"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type middy from '@middy/core';
|
|
2
2
|
import type { ZodType } from 'zod';
|
|
3
3
|
import type { EnvConfig } from '../../../domain.objects/ContextAwsLambdaServer';
|
|
4
|
+
import type { LambdaEndpointSchema } from '../../../domain.objects/LambdaEndpointSchema';
|
|
4
5
|
/**
|
|
5
6
|
* .what = middleware that intercepts introspection requests
|
|
6
7
|
* .why = enables runtime schema discovery for sdk generation
|
|
@@ -16,7 +17,21 @@ export declare const genIntrospectionMiddleware: <TInput, TOutput>(opts: {
|
|
|
16
17
|
output: ZodType<TOutput>;
|
|
17
18
|
};
|
|
18
19
|
env?: EnvConfig;
|
|
19
|
-
|
|
20
|
+
/**
|
|
21
|
+
* .what = reads `inputAfter` out of the middy request, per family
|
|
22
|
+
* .why = each family keeps the caller's value in a DIFFERENT place, and only the family
|
|
23
|
+
* knows which. the api-gateway chain must keep `request.event` HTTP-SHAPED, since
|
|
24
|
+
* `@middy/http-cors` reads `request.event.headers` and derives the http method from
|
|
25
|
+
* `request.event` in its `after` hook — so that family carries the value at
|
|
26
|
+
* `event.body`, while the ask-endpoint family carries it at `event` itself
|
|
27
|
+
*/
|
|
28
|
+
asInputAfter: (request: any) => unknown;
|
|
29
|
+
/**
|
|
30
|
+
* .what = renders the schema as this family's `outputAfter`, per family
|
|
31
|
+
* .why = the short-circuit writes STRAIGHT to the wire, so the shape is the family's own:
|
|
32
|
+
* api-gateway owes a wire payload, while an ask-endpoint response IS its payload
|
|
33
|
+
*/
|
|
34
|
+
asOutputAfter: (schema: LambdaEndpointSchema) => unknown;
|
|
20
35
|
}) => {
|
|
21
36
|
before: middy.MiddlewareFn<any, any>;
|
|
22
37
|
};
|
|
@@ -15,9 +15,8 @@ const genIntrospectionMiddleware_isIntrospectionPayload_1 = require("./genIntros
|
|
|
15
15
|
*/
|
|
16
16
|
const genIntrospectionMiddleware = (opts) => {
|
|
17
17
|
const before = async (request) => {
|
|
18
|
-
//
|
|
19
|
-
const payload = opts.
|
|
20
|
-
// check if introspection request
|
|
18
|
+
// read inputAfter from wherever this family keeps it
|
|
19
|
+
const payload = opts.asInputAfter(request);
|
|
21
20
|
if (!(0, genIntrospectionMiddleware_isIntrospectionPayload_1.isIntrospectionPayload)(payload))
|
|
22
21
|
return;
|
|
23
22
|
// extract env from config
|
|
@@ -35,16 +34,13 @@ const genIntrospectionMiddleware = (opts) => {
|
|
|
35
34
|
input: (0, genIntrospectionMiddleware_getJsonSchemaFromZod_1.getJsonSchemaFromZod)(opts.schema.input),
|
|
36
35
|
output: (0, genIntrospectionMiddleware_getJsonSchemaFromZod_1.getJsonSchemaFromZod)(opts.schema.output),
|
|
37
36
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return request.response;
|
|
46
|
-
}
|
|
47
|
-
request.response = schema;
|
|
37
|
+
/**
|
|
38
|
+
* .what = short-circuit the chain with this family's own wire shape
|
|
39
|
+
* .note = DELIBERATE MUTATION. middy's `before` contract is that a hook short-circuits by
|
|
40
|
+
* assignment to `request.response`; there is no immutable form of that signal
|
|
41
|
+
* (rule.require.immutable-vars, the annotated-exception clause)
|
|
42
|
+
*/
|
|
43
|
+
request.response = opts.asOutputAfter(schema);
|
|
48
44
|
return request.response;
|
|
49
45
|
};
|
|
50
46
|
return { before };
|
package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genIntrospectionMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.ts"],"names":[],"mappings":";;;AACA,mDAAiD;
|
|
1
|
+
{"version":3,"file":"genIntrospectionMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.ts"],"names":[],"mappings":";;;AACA,mDAAiD;AA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CAAC,CAAC;AApEW,QAAA,0BAA0B,8BAoErC"}
|
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
import type middy from '@middy/core';
|
|
2
|
-
|
|
3
|
-
input?: (event: unknown) => unknown;
|
|
4
|
-
output?: (response: unknown) => unknown;
|
|
5
|
-
}
|
|
2
|
+
import type { TranslateLog } from '../TranslateLog';
|
|
6
3
|
/**
|
|
7
4
|
* .what = middleware that logs handler input and output
|
|
8
|
-
* .why = enables debug observability with optional redaction via
|
|
5
|
+
* .why = enables debug observability with optional redaction via translate.log
|
|
6
|
+
*
|
|
7
|
+
* ⚠️ .note = LIVE, NOT FIXED — on an error, the `request.response` branch of `onError` below
|
|
8
|
+
* never runs. both shipped chains log the `errorMessage` / `stackTrace` branch
|
|
9
|
+
* instead.
|
|
10
|
+
*
|
|
11
|
+
* .the cause = middy `unshift`s `after` and `onError` hooks
|
|
12
|
+
* (`@middy/core/index.js:79-100`), so registration order REVERSES at run time: a
|
|
13
|
+
* HIGHER array index runs EARLIER on the error path. `onError` here reads
|
|
14
|
+
* `request.response`, which exists only once an error-builder has set it — so this
|
|
15
|
+
* middleware must sit at a LOWER index than `genConstraintErrorMiddleware` /
|
|
16
|
+
* `genInternalServiceErrorMiddleware` for its response branch to observe a value at
|
|
17
|
+
* all. today it sits HIGHER in both.
|
|
18
|
+
*
|
|
19
|
+
* .the repair, unapplied = move it below the error builders. left with the peer
|
|
20
|
+
* header-order defect (F32) because that reorder also moves the SUCCESS-path `after`
|
|
21
|
+
* order for every handler — a blast radius this wish's bound does not cover.
|
|
22
|
+
*
|
|
23
|
+
* ⚠️ do NOT delete the response branch as dead code. it names a real intent — *on an
|
|
24
|
+
* error, log what the caller actually received* — and it goes live the moment the
|
|
25
|
+
* reorder lands (rule.require.retest-the-model-on-every-family: prune a slot, never a
|
|
26
|
+
* name).
|
|
27
|
+
*
|
|
28
|
+
* ⚠️ the same mechanism binds a CUSTOM chain: place this below your own error
|
|
29
|
+
* builders, or its error-path response branch is dead there too.
|
|
9
30
|
*/
|
|
10
31
|
export declare const genIoLoggerMiddleware: (input?: {
|
|
11
|
-
logTranslate?:
|
|
32
|
+
logTranslate?: TranslateLog;
|
|
12
33
|
}) => {
|
|
13
34
|
before: middy.MiddlewareFn<any, any>;
|
|
14
35
|
after: middy.MiddlewareFn<any, any>;
|
|
@@ -1,21 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.genIoLoggerMiddleware = void 0;
|
|
4
|
+
const asContextTrailed_1 = require("./asContextTrailed");
|
|
4
5
|
/**
|
|
5
6
|
* .what = middleware that logs handler input and output
|
|
6
|
-
* .why = enables debug observability with optional redaction via
|
|
7
|
+
* .why = enables debug observability with optional redaction via translate.log
|
|
8
|
+
*
|
|
9
|
+
* ⚠️ .note = LIVE, NOT FIXED — on an error, the `request.response` branch of `onError` below
|
|
10
|
+
* never runs. both shipped chains log the `errorMessage` / `stackTrace` branch
|
|
11
|
+
* instead.
|
|
12
|
+
*
|
|
13
|
+
* .the cause = middy `unshift`s `after` and `onError` hooks
|
|
14
|
+
* (`@middy/core/index.js:79-100`), so registration order REVERSES at run time: a
|
|
15
|
+
* HIGHER array index runs EARLIER on the error path. `onError` here reads
|
|
16
|
+
* `request.response`, which exists only once an error-builder has set it — so this
|
|
17
|
+
* middleware must sit at a LOWER index than `genConstraintErrorMiddleware` /
|
|
18
|
+
* `genInternalServiceErrorMiddleware` for its response branch to observe a value at
|
|
19
|
+
* all. today it sits HIGHER in both.
|
|
20
|
+
*
|
|
21
|
+
* .the repair, unapplied = move it below the error builders. left with the peer
|
|
22
|
+
* header-order defect (F32) because that reorder also moves the SUCCESS-path `after`
|
|
23
|
+
* order for every handler — a blast radius this wish's bound does not cover.
|
|
24
|
+
*
|
|
25
|
+
* ⚠️ do NOT delete the response branch as dead code. it names a real intent — *on an
|
|
26
|
+
* error, log what the caller actually received* — and it goes live the moment the
|
|
27
|
+
* reorder lands (rule.require.retest-the-model-on-every-family: prune a slot, never a
|
|
28
|
+
* name).
|
|
29
|
+
*
|
|
30
|
+
* ⚠️ the same mechanism binds a CUSTOM chain: place this below your own error
|
|
31
|
+
* builders, or its error-path response branch is dead there too.
|
|
7
32
|
*/
|
|
8
33
|
const genIoLoggerMiddleware = (input) => {
|
|
9
34
|
const translateInput = input?.logTranslate?.input ?? ((event) => event);
|
|
10
35
|
const translateOutput = input?.logTranslate?.output ?? ((response) => response);
|
|
11
36
|
const before = async (request) => {
|
|
12
|
-
const log = request.context
|
|
37
|
+
const log = (0, asContextTrailed_1.asContextTrailed)({ context: request.context }).log;
|
|
13
38
|
if (log) {
|
|
14
39
|
log.debug('handler.input', { event: translateInput(request.event) });
|
|
15
40
|
}
|
|
16
41
|
};
|
|
17
42
|
const after = async (request) => {
|
|
18
|
-
const log = request.context
|
|
43
|
+
const log = (0, asContextTrailed_1.asContextTrailed)({ context: request.context }).log;
|
|
19
44
|
if (log) {
|
|
20
45
|
log.debug('handler.output', {
|
|
21
46
|
response: translateOutput(request.response),
|
|
@@ -23,7 +48,7 @@ const genIoLoggerMiddleware = (input) => {
|
|
|
23
48
|
}
|
|
24
49
|
};
|
|
25
50
|
const onError = async (request) => {
|
|
26
|
-
const log = request.context
|
|
51
|
+
const log = (0, asContextTrailed_1.asContextTrailed)({ context: request.context }).log;
|
|
27
52
|
if (log) {
|
|
28
53
|
if (request.response) {
|
|
29
54
|
log.debug('handler.output', {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genIoLoggerMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"genIoLoggerMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.ts"],"names":[],"mappings":";;;AAGA,yDAAsD;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2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KAAK,CAAC,gBAAgB,EAAE;oBAC1B,QAAQ,EAAE,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC;iBAC5C,CAAC,CAAC;YACL,CAAC;iBAAM,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;gBACzB,GAAG,CAAC,KAAK,CAAC,gBAAgB,EAAE;oBAC1B,YAAY,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;oBACnC,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK;iBAChC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AACpC,CAAC,CAAC;AA5CW,QAAA,qBAAqB,yBA4ChC"}
|
|
@@ -31,14 +31,22 @@ const genTrailMiddleware = () => {
|
|
|
31
31
|
env: null,
|
|
32
32
|
});
|
|
33
33
|
// unwrap event (if wrapped format)
|
|
34
|
+
// .note = DELIBERATE MUTATION — `request` is middy's only channel to hand a value onward
|
|
34
35
|
request.event = unwrappedEvent;
|
|
35
36
|
// inject log and caller version flag into context
|
|
36
|
-
const contextBefore = (request.context ?? {});
|
|
37
37
|
/**
|
|
38
|
-
* .as = middy types request.context as aws-lambda Context
|
|
39
|
-
*
|
|
40
|
-
*
|
|
38
|
+
* .as = TWO casts, one subject: middy types `request.context` as aws-lambda's `Context`,
|
|
39
|
+
* which declares neither `log` nor `isContempCaller`. the first widens the read so
|
|
40
|
+
* every extant key survives the spread; the second declares the extension this
|
|
41
|
+
* middleware writes
|
|
42
|
+
*
|
|
43
|
+
* .why not `asContextTrailed` = that reader returns only the TWO sdk-managed fields, so a
|
|
44
|
+
* spread of it would DROP every aws-supplied key. a writer needs the whole bag
|
|
45
|
+
*
|
|
46
|
+
* .removal = removable when middy's `Request` carries a caller-declared context type
|
|
47
|
+
* parameter this chain can bind, such that a middleware may declare what it adds
|
|
41
48
|
*/
|
|
49
|
+
const contextBefore = (request.context ?? {});
|
|
42
50
|
request.context = {
|
|
43
51
|
...contextBefore,
|
|
44
52
|
log: contextLogTrail.log,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genTrailMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.ts"],"names":[],"mappings":";;;AACA,mCAAoC;AACpC,uCAIkB;AAElB,2EAAwE;AAExE;;;;;;;GAOG;AACI,MAAM,kBAAkB,GAAG,GAEhC,EAAE;IACF,MAAM,MAAM,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7D,kDAAkD;QAClD,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,GACxD,IAAA,qDAAyB,EAAC;YACxB,OAAO,EAAE,OAAO,CAAC,KAAK;SACvB,CAAC,CAAC;QAEL,gCAAgC;QAChC,MAAM,IAAI,GAAG,eAAe,IAAI,QAAQ,IAAA,mBAAU,GAAE,EAAE,CAAC;QAEvD,eAAe;QACf,MAAM,KAAK,GAAa;YACtB,IAAI;YACJ,KAAK,EAAE,EAAE;SACV,CAAC;QAEF,kCAAkC;QAClC,MAAM,eAAe,GAAG,IAAA,6BAAkB,EAAC;YACzC,KAAK;YACL,GAAG,EAAE,IAAI;SACV,CAAC,CAAC;QAEH,mCAAmC;QACnC,OAAO,CAAC,KAAK,GAAG,cAAc,CAAC;QAE/B,kDAAkD;QAClD,MAAM,aAAa,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAG3C,CAAC;QACF
|
|
1
|
+
{"version":3,"file":"genTrailMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.ts"],"names":[],"mappings":";;;AACA,mCAAoC;AACpC,uCAIkB;AAElB,2EAAwE;AAExE;;;;;;;GAOG;AACI,MAAM,kBAAkB,GAAG,GAEhC,EAAE;IACF,MAAM,MAAM,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7D,kDAAkD;QAClD,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,GACxD,IAAA,qDAAyB,EAAC;YACxB,OAAO,EAAE,OAAO,CAAC,KAAK;SACvB,CAAC,CAAC;QAEL,gCAAgC;QAChC,MAAM,IAAI,GAAG,eAAe,IAAI,QAAQ,IAAA,mBAAU,GAAE,EAAE,CAAC;QAEvD,eAAe;QACf,MAAM,KAAK,GAAa;YACtB,IAAI;YACJ,KAAK,EAAE,EAAE;SACV,CAAC;QAEF,kCAAkC;QAClC,MAAM,eAAe,GAAG,IAAA,6BAAkB,EAAC;YACzC,KAAK;YACL,GAAG,EAAE,IAAI;SACV,CAAC,CAAC;QAEH,mCAAmC;QACnC,yFAAyF;QACzF,OAAO,CAAC,KAAK,GAAG,cAAc,CAAC;QAE/B,kDAAkD;QAClD;;;;;;;;;;;WAWG;QACH,MAAM,aAAa,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAG3C,CAAC;QACF,OAAO,CAAC,OAAO,GAAG;YAChB,GAAG,aAAa;YAChB,GAAG,EAAE,eAAe,CAAC,GAAG;YACxB,eAAe;SAE+B,CAAC;IACnD,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AAvDW,QAAA,kBAAkB,sBAuD7B"}
|
package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.d.ts
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
import type middy from '@middy/core';
|
|
2
2
|
import type { ZodSchema } from 'zod';
|
|
3
3
|
/**
|
|
4
|
-
* .what = middleware that validates handler output against zod schema
|
|
5
|
-
* .why = ensures type-safe output before response is returned
|
|
4
|
+
* .what = middleware that validates handler output against a zod schema
|
|
5
|
+
* .why = ensures type-safe output before the response is returned
|
|
6
|
+
*
|
|
7
|
+
* ⚠️ .note = WHICH SHAPE THIS VALIDATES DEPENDS ON WHERE YOU REGISTER IT.
|
|
8
|
+
*
|
|
9
|
+
* it reads `request.response`, and on the api-gateway path that slot holds a different
|
|
10
|
+
* type at different points in the chain:
|
|
11
|
+
*
|
|
12
|
+
* before the output translator -> `ApiGatewayResponse<TBody>` (the handler's shape)
|
|
13
|
+
* after the output translator -> `ApiGatewayResponsePayload` (the wire form, body
|
|
14
|
+
* already a string)
|
|
15
|
+
*
|
|
16
|
+
* a schema written for one refuses the other, so a caller who composes this into a
|
|
17
|
+
* custom chain validates whichever shape their registration order produces. the
|
|
18
|
+
* signature cannot warn them — `request.response` is `unknown` to middy, so both bind.
|
|
19
|
+
*
|
|
20
|
+
* .note = UNRESOLVED, NOT A DEFECT — this export carries two contracts with no discriminant.
|
|
21
|
+
* tracked as **F33** in `1.vision.yield.md`'s fulcrum table, where the three options
|
|
22
|
+
* (deprecate, add a `point` discriminant, accept) are spelled out.
|
|
23
|
+
*
|
|
24
|
+
* no shipped chain registers it — both families validate inline instead, because each
|
|
25
|
+
* knows which of the two shapes it holds at that moment and this middleware cannot. so
|
|
26
|
+
* the open question is one of surface area, never of a live defect.
|
|
27
|
+
*
|
|
28
|
+
* .note = the validation itself is delegated to `getValidatedOutput`, as both input-side peers
|
|
29
|
+
* delegate to `getValidationError` — one guarantee, one implementation
|
|
30
|
+
* (rule.forbid.parallel-codepaths)
|
|
6
31
|
*/
|
|
7
32
|
export declare const genZodOutputValidationMiddleware: <TOutput>(input: {
|
|
8
33
|
schema: ZodSchema<TOutput>;
|
package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.js
CHANGED
|
@@ -1,24 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.genZodOutputValidationMiddleware = void 0;
|
|
4
|
-
const
|
|
5
|
-
const getZodIssuesSummary_1 = require("./getZodIssuesSummary");
|
|
4
|
+
const getValidatedOutput_1 = require("./getValidatedOutput");
|
|
6
5
|
/**
|
|
7
|
-
* .what = middleware that validates handler output against zod schema
|
|
8
|
-
* .why = ensures type-safe output before response is returned
|
|
6
|
+
* .what = middleware that validates handler output against a zod schema
|
|
7
|
+
* .why = ensures type-safe output before the response is returned
|
|
8
|
+
*
|
|
9
|
+
* ⚠️ .note = WHICH SHAPE THIS VALIDATES DEPENDS ON WHERE YOU REGISTER IT.
|
|
10
|
+
*
|
|
11
|
+
* it reads `request.response`, and on the api-gateway path that slot holds a different
|
|
12
|
+
* type at different points in the chain:
|
|
13
|
+
*
|
|
14
|
+
* before the output translator -> `ApiGatewayResponse<TBody>` (the handler's shape)
|
|
15
|
+
* after the output translator -> `ApiGatewayResponsePayload` (the wire form, body
|
|
16
|
+
* already a string)
|
|
17
|
+
*
|
|
18
|
+
* a schema written for one refuses the other, so a caller who composes this into a
|
|
19
|
+
* custom chain validates whichever shape their registration order produces. the
|
|
20
|
+
* signature cannot warn them — `request.response` is `unknown` to middy, so both bind.
|
|
21
|
+
*
|
|
22
|
+
* .note = UNRESOLVED, NOT A DEFECT — this export carries two contracts with no discriminant.
|
|
23
|
+
* tracked as **F33** in `1.vision.yield.md`'s fulcrum table, where the three options
|
|
24
|
+
* (deprecate, add a `point` discriminant, accept) are spelled out.
|
|
25
|
+
*
|
|
26
|
+
* no shipped chain registers it — both families validate inline instead, because each
|
|
27
|
+
* knows which of the two shapes it holds at that moment and this middleware cannot. so
|
|
28
|
+
* the open question is one of surface area, never of a live defect.
|
|
29
|
+
*
|
|
30
|
+
* .note = the validation itself is delegated to `getValidatedOutput`, as both input-side peers
|
|
31
|
+
* delegate to `getValidationError` — one guarantee, one implementation
|
|
32
|
+
* (rule.forbid.parallel-codepaths)
|
|
9
33
|
*/
|
|
10
34
|
const genZodOutputValidationMiddleware = (input) => {
|
|
11
35
|
return {
|
|
12
36
|
after: async (request) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
// replace response with validated data (includes defaults, transforms)
|
|
21
|
-
request.response = result.data;
|
|
37
|
+
// replace response with validated data (defaults + transforms applied)
|
|
38
|
+
// .note = DELIBERATE MUTATION — `request` is middy's only channel to hand a value onward
|
|
39
|
+
request.response = (0, getValidatedOutput_1.getValidatedOutput)({
|
|
40
|
+
response: request.response,
|
|
41
|
+
schema: input.schema,
|
|
42
|
+
});
|
|
22
43
|
},
|
|
23
44
|
};
|
|
24
45
|
};
|
package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genZodOutputValidationMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"genZodOutputValidationMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.ts"],"names":[],"mappings":";;;AAGA,6DAA0D;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACI,MAAM,gCAAgC,GAAG,CAAU,KAEzD,EAAyC,EAAE;IAC1C,OAAO;QACL,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACvB,uEAAuE;YACvE,yFAAyF;YACzF,OAAO,CAAC,QAAQ,GAAG,IAAA,uCAAkB,EAAC;gBACpC,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,MAAM,EAAE,KAAK,CAAC,MAAM;aACrB,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,gCAAgC,oCAa3C"}
|
|
@@ -16,6 +16,7 @@ const getCauseMessage = (input) => {
|
|
|
16
16
|
* .why = named transformer for clear narrative
|
|
17
17
|
*/
|
|
18
18
|
const getErrorMetadata = (input) => {
|
|
19
|
+
// .note = the `in` guard narrows, so this needs no cast (rule.forbid.as-cast)
|
|
19
20
|
if ('metadata' in input.error) {
|
|
20
21
|
return input.error.metadata;
|
|
21
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getErrorResponseBody.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.ts"],"names":[],"mappings":";;;AAuBA;;;GAGG;AACH,MAAM,eAAe,GAAG,CAAC,KAAuB,EAAsB,EAAE;IACtE,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,YAAY,KAAK,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC;IACnC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,gBAAgB,GAAG,CAAC,KAAuB,EAAuB,EAAE;IACxE,IAAI,UAAU,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAC9B,
|
|
1
|
+
{"version":3,"file":"getErrorResponseBody.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.ts"],"names":[],"mappings":";;;AAuBA;;;GAGG;AACH,MAAM,eAAe,GAAG,CAAC,KAAuB,EAAsB,EAAE;IACtE,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,YAAY,KAAK,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC;IACnC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,gBAAgB,GAAG,CAAC,KAAuB,EAAuB,EAAE;IACxE,8EAA8E;IAC9E,IAAI,UAAU,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC9B,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF;;;GAGG;AACI,MAAM,2BAA2B,GAAG,CAAC,KAG3C,EAA0C,EAAE;IAC3C,MAAM,YAAY,GAAG,eA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