sdk-aws-lambda 0.3.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.
Files changed (87) hide show
  1. package/dist/access/sdks/lambda/genLambdaSdk.d.ts +8 -1
  2. package/dist/access/sdks/lambda/genLambdaSdk.js +57 -4
  3. package/dist/access/sdks/lambda/genLambdaSdk.js.map +1 -1
  4. package/dist/domain.objects/ApiGatewayRequestPayload.d.ts +12 -0
  5. package/dist/domain.objects/ApiGatewayRequestPayload.js +3 -0
  6. package/dist/domain.objects/ApiGatewayRequestPayload.js.map +1 -0
  7. package/dist/domain.objects/ApiGatewayResponse.d.ts +30 -0
  8. package/dist/domain.objects/ApiGatewayResponse.js +3 -0
  9. package/dist/domain.objects/ApiGatewayResponse.js.map +1 -0
  10. package/dist/domain.objects/ApiGatewayResponsePayload.d.ts +30 -0
  11. package/dist/domain.objects/ApiGatewayResponsePayload.js +3 -0
  12. package/dist/domain.objects/ApiGatewayResponsePayload.js.map +1 -0
  13. package/dist/domain.objects/HttpStatusCode.d.ts +1 -0
  14. package/dist/domain.objects/HttpStatusCode.js +1 -0
  15. package/dist/domain.objects/HttpStatusCode.js.map +1 -1
  16. package/dist/domain.operations/genLambdaEndpoint/TranslateLog.d.ts +29 -0
  17. package/dist/domain.operations/genLambdaEndpoint/TranslateLog.js +3 -0
  18. package/dist/domain.operations/genLambdaEndpoint/TranslateLog.js.map +1 -0
  19. package/dist/domain.operations/genLambdaEndpoint/asContextLogTrail.d.ts +29 -0
  20. package/dist/domain.operations/genLambdaEndpoint/asContextLogTrail.js +30 -0
  21. package/dist/domain.operations/genLambdaEndpoint/asContextLogTrail.js.map +1 -0
  22. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/UnifiedApiGatewayEvent.d.ts +36 -0
  23. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/UnifiedApiGatewayEvent.js +3 -0
  24. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/UnifiedApiGatewayEvent.js.map +1 -0
  25. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayload.d.ts +19 -0
  26. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayload.js +24 -0
  27. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayload.js.map +1 -0
  28. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayloadJson.d.ts +26 -0
  29. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayloadJson.js +31 -0
  30. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayloadJson.js.map +1 -0
  31. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponseSchema.d.ts +33 -0
  32. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponseSchema.js +39 -0
  33. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponseSchema.js.map +1 -0
  34. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asUnifiedApiGatewayEvent.d.ts +27 -0
  35. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asUnifiedApiGatewayEvent.js +118 -0
  36. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asUnifiedApiGatewayEvent.js.map +1 -0
  37. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.d.ts +76 -36
  38. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js +153 -45
  39. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js.map +1 -1
  40. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getAllWirePayloadKeysFound.d.ts +8 -0
  41. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getAllWirePayloadKeysFound.js +34 -0
  42. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getAllWirePayloadKeysFound.js.map +1 -0
  43. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/isApiGatewayResponse.d.ts +19 -0
  44. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/isApiGatewayResponse.js +36 -0
  45. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/isApiGatewayResponse.js.map +1 -0
  46. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.d.ts +7 -24
  47. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js +19 -103
  48. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js.map +1 -1
  49. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genContentTypeCoherenceMiddleware.d.ts +20 -0
  50. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genContentTypeCoherenceMiddleware.js +48 -0
  51. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genContentTypeCoherenceMiddleware.js.map +1 -0
  52. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.d.ts +16 -0
  53. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.js +32 -0
  54. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.js.map +1 -1
  55. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.d.ts +6 -22
  56. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js +24 -18
  57. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js.map +1 -1
  58. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.d.ts +11 -2
  59. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.js +12 -2
  60. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.js.map +1 -1
  61. package/dist/domain.operations/genLambdaEndpoint/middleware/asContextTrailed.d.ts +37 -0
  62. package/dist/domain.operations/genLambdaEndpoint/middleware/asContextTrailed.js +24 -0
  63. package/dist/domain.operations/genLambdaEndpoint/middleware/asContextTrailed.js.map +1 -0
  64. package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.d.ts +18 -10
  65. package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.js +20 -23
  66. package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.js.map +1 -1
  67. package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.d.ts +29 -6
  68. package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js +23 -28
  69. package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js.map +1 -1
  70. package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.d.ts +16 -1
  71. package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.js +9 -13
  72. package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.js.map +1 -1
  73. package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.d.ts +27 -6
  74. package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js +29 -4
  75. package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js.map +1 -1
  76. package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js +12 -4
  77. package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js.map +1 -1
  78. package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.d.ts +27 -2
  79. package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.js +34 -13
  80. package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.js.map +1 -1
  81. package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.js +1 -0
  82. package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.js.map +1 -1
  83. package/dist/index.d.ts +40 -2
  84. package/dist/index.js +28 -1
  85. package/dist/index.js.map +1 -1
  86. package/package.json +12 -11
  87. package/readme.md +50 -2
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isApiGatewayResponse = void 0;
4
+ const type_fns_1 = require("type-fns");
5
+ const getAllWirePayloadKeysFound_1 = require("./getAllWirePayloadKeysFound");
6
+ /**
7
+ * .what = checks that a value is an ApiGatewayResponse — an object with at least one of
8
+ * status, headers, or body, and none of the aws wire-payload keys
9
+ * .why = the type refuses `{}` at compile time, but a handler's return crosses an
10
+ * `unknown` boundary at run time (a js caller, an `any`, a cast). this is the
11
+ * runtime backstop for the invariants the type holds
12
+ *
13
+ * .note = it checks CARDINALITY and FOREIGN KEYS, not field types. the field types are
14
+ * `schema.output`'s job; this exists so an empty, non-object, or wire-shaped return
15
+ * fails loud HERE rather than reach middy's `statusCode ??= 500` and emit a silent 500
16
+ *
17
+ * .note = the foreign-key half closes a MIGRATION hazard the cardinality half could not see.
18
+ * `{ statusCode: 404, body: JSON.stringify(x) }` — the aws-native shape, and the one
19
+ * the wish's own `.ground` evidence used — satisfies `'body' in input`, so it used to
20
+ * pass. it then lost its 404 to `status ?? 200` and had its body encoded twice
21
+ * (rule.forbid.failhide)
22
+ */
23
+ exports.isApiGatewayResponse = (0, type_fns_1.withAssure)((input) => {
24
+ // reject a non-object; a response is always an envelope
25
+ if (typeof input !== 'object' || input === null)
26
+ return false;
27
+ // reject an array; api gateway has no array response shape
28
+ if (Array.isArray(input))
29
+ return false;
30
+ // reject the aws wire shape; no step here reads its keys, so they would vanish
31
+ if ((0, getAllWirePayloadKeysFound_1.getAllWirePayloadKeysFound)({ response: input }).length)
32
+ return false;
33
+ // require at least one of the three fields — this is what PickAny encodes
34
+ return 'status' in input || 'headers' in input || 'body' in input;
35
+ }, { name: 'isApiGatewayResponse' });
36
+ //# sourceMappingURL=isApiGatewayResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isApiGatewayResponse.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/isApiGatewayResponse.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AAGtC,6EAA0E;AAE1E;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,oBAAoB,GAAG,IAAA,qBAAU,EAC5C,CAAC,KAAc,EAAwC,EAAE;IACvD,wDAAwD;IACxD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAE9D,2DAA2D;IAC3D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAEvC,+EAA+E;IAC/E,IAAI,IAAA,uDAA0B,EAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAEzE,0EAA0E;IAC1E,OAAO,QAAQ,IAAI,KAAK,IAAI,SAAS,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC;AACpE,CAAC,EACD,EAAE,IAAI,EAAE,sBAAsB,EAAE,CACjC,CAAC"}
@@ -1,29 +1,12 @@
1
1
  import type middy from '@middy/core';
2
- import type { APIGatewayProxyEvent, APIGatewayProxyEventV2 } from 'aws-lambda';
3
2
  /**
4
- * .what = unified API Gateway event format
5
- * .why = abstracts v1/v2 differences for handler consumption
6
- */
7
- export interface UnifiedApiGatewayEvent {
8
- httpMethod: string;
9
- path: string;
10
- headers: Record<string, string | undefined>;
11
- queryStringParameters: Record<string, string | undefined> | null;
12
- pathParameters: Record<string, string | undefined> | null;
13
- body: unknown;
14
- rawBody: string | null;
15
- isBase64Encoded: boolean;
16
- requestContext: {
17
- requestId: string;
18
- stage: string;
19
- domainName?: string;
20
- accountId?: string;
21
- };
22
- rawEvent: APIGatewayProxyEvent | APIGatewayProxyEventV2;
23
- }
24
- /**
25
- * .what = converts v1/v2 API Gateway events to unified format
26
- * .why = handlers work with consistent event shape regardless of API type
3
+ * .what = replaces the event with the v1/v2-reconciled shape
4
+ * .why = the api-gateway chain must read the same whichever version the trigger delivers, so
5
+ * this runs first and every step after it reads one shape
6
+ *
7
+ * .note = this DELEGATES to `asUnifiedApiGatewayEvent` rather than hold its own copy of the
8
+ * reconcile logic. one guarantee, one implementation, two entry points — a second
9
+ * copy would be the parallel code path (rule.forbid.parallel-codepaths)
27
10
  */
28
11
  export declare const genApiGatewayEventNormalizationMiddleware: (input: {
29
12
  parseBody: boolean;
@@ -1,113 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.genApiGatewayEventNormalizationMiddleware = void 0;
4
- const helpful_errors_1 = require("helpful-errors");
5
- const getIsV1ApiGatewayEvent_1 = require("../getIsV1ApiGatewayEvent");
6
- const getIsV2ApiGatewayEvent_1 = require("../getIsV2ApiGatewayEvent");
4
+ const asUnifiedApiGatewayEvent_1 = require("../asUnifiedApiGatewayEvent");
7
5
  /**
8
- * .what = parses JSON body string to object
9
- * .why = API Gateway sends body as string, handlers need object
10
- */
11
- const getParsedApiGatewayBody = (input) => {
12
- if (!input.body)
13
- return null;
14
- // decode base64 if needed
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
- const rawEvent = request.event;
91
- // convert v2 HTTP API event to unified format
92
- if ((0, getIsV2ApiGatewayEvent_1.getIsV2ApiGatewayEvent)(rawEvent)) {
93
- request.event = asUnifiedEventFromV2({
94
- event: rawEvent,
95
- parseBody: input.parseBody,
96
- });
97
- return;
98
- }
99
- // convert v1 REST API event to unified format
100
- if ((0, getIsV1ApiGatewayEvent_1.getIsV1ApiGatewayEvent)(rawEvent)) {
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":";;;AAEA,mDAAkD;AAElD,sEAAmE;AACnE,sEAAmE;AAwBnE;;;GAGG;AACH,MAAM,uBAAuB,GAAG,CAAC,KAGhC,EAAW,EAAE;IACZ,IAAI,CAAC,KAAK,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IAE7B,0BAA0B;IAC1B,MAAM,OAAO,GAAG,KAAK,CAAC,eAAe;QACnC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;QACrD,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;IAEf,kCAAkC;IAClC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,oBAAoB,GAAG,CAAC,KAG7B,EAA0B,EAAE;IAC3B,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS;QAC1B,CAAC,CAAC,uBAAuB,CAAC;YACtB,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI;YACtB,eAAe,EAAE,KAAK,CAAC,KAAK,CAAC,eAAe;SAC7C,CAAC;QACJ,CAAC,CAAC,KAAK,CAAC,KAA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QAED,4BAA4B;QAC5B,MAAM,IAAI,iCAAgB,CAAC,8CAA8C,EAAE;YACzE,QAAQ;SACT,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AAjCW,QAAA,yCAAyC,6CAiCpD"}
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;;;GAGG;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,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,IAAoC,CAAC;IAC3D,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AAhBW,QAAA,8BAA8B,kCAgBzC"}
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 { IoLogTranslate } from '../middleware/genIoLoggerMiddleware';
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?: IoLogTranslate;
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
- * follows simple-lambda-handlers createStandardHandler pattern:
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
- * follows simple-lambda-handlers createStandardHandler pattern:
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 = (input, context) => {
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
- // get log from lambda context (injected by trail middleware)
34
- const log = lambdaContext.log;
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
- (0, genConstraintErrorMiddleware_1.genConstraintErrorMiddleware)(),
48
- (0, genInternalServiceErrorMiddleware_1.genInternalServiceErrorMiddleware)(),
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)({ schema: input.schema, env: context?.env }),
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.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C,CAAC;AACrB,CAAC,CAAC;AAzDW,QAAA,iBAAiB,qBAyD5B"}
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 = askLambdaEndpoint sends unwrapped payload, validate full event
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 = askLambdaEndpoint sends unwrapped payload, validate full event
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;;;GAGG;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,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AAfW,QAAA,+BAA+B,mCAe1C"}
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"}