sdk-aws-lambda 0.4.1 → 0.5.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.
Files changed (161) hide show
  1. package/dist/contract/cli/gen.js +18 -0
  2. package/dist/contract/cli/gen.js.map +1 -1
  3. package/dist/domain.objects/AwsIdentitySynthetic.d.ts +20 -0
  4. package/dist/domain.objects/AwsIdentitySynthetic.js +24 -0
  5. package/dist/domain.objects/AwsIdentitySynthetic.js.map +1 -0
  6. package/dist/domain.objects/LambdaEndpointDialect.d.ts +19 -0
  7. package/dist/domain.objects/LambdaEndpointDialect.js +3 -0
  8. package/dist/domain.objects/LambdaEndpointDialect.js.map +1 -0
  9. package/dist/domain.objects/LambdaEndpointErrorResponseBody.d.ts +70 -0
  10. package/dist/domain.objects/LambdaEndpointErrorResponseBody.js +41 -0
  11. package/dist/domain.objects/LambdaEndpointErrorResponseBody.js.map +1 -0
  12. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.asExampleUuid.d.ts +7 -0
  13. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.asExampleUuid.js +13 -0
  14. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.asExampleUuid.js.map +1 -0
  15. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.constants.d.ts +36 -0
  16. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.constants.js +88 -0
  17. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.constants.js.map +1 -0
  18. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.d.ts +81 -0
  19. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromApiGateway.d.ts +75 -0
  20. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromApiGateway.js +163 -0
  21. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromApiGateway.js.map +1 -0
  22. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromKinesis.d.ts +32 -0
  23. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromKinesis.js +55 -0
  24. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromKinesis.js.map +1 -0
  25. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromS3.d.ts +40 -0
  26. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromS3.js +71 -0
  27. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromS3.js.map +1 -0
  28. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromSns.d.ts +27 -0
  29. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromSns.js +51 -0
  30. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromSns.js.map +1 -0
  31. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromSqs.d.ts +35 -0
  32. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromSqs.js +50 -0
  33. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromSqs.js.map +1 -0
  34. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.js +59 -0
  35. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.js.map +1 -0
  36. package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.d.ts +2 -1
  37. package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.js +19 -18
  38. package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.js.map +1 -1
  39. package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.js +1 -1
  40. package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.js.map +1 -1
  41. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.d.ts +9 -7
  42. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js.map +1 -1
  43. package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.d.ts +6 -19
  44. package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.js +6 -1
  45. package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.js.map +1 -1
  46. package/dist/domain.operations/genLambdaEndpoint/middleware/getUnwrappedEventWithExid.d.ts +1 -1
  47. package/dist/domain.operations/genLambdaEndpoint/middleware/getUnwrappedEventWithExid.js +1 -1
  48. package/dist/domain.operations/genLambdaEndpoint/middleware/getUnwrappedEventWithExid.js.map +1 -1
  49. package/dist/domain.operations/getAllLambdaContracts/getAllLambdaContracts.js +16 -35
  50. package/dist/domain.operations/getAllLambdaContracts/getAllLambdaContracts.js.map +1 -1
  51. package/dist/domain.operations/lambdaEndpointWire/context/getExidFromContext.js.map +1 -0
  52. package/dist/domain.operations/lambdaEndpointWire/context/getLogForExidExtraction.js.map +1 -0
  53. package/dist/domain.operations/lambdaEndpointWire/context/getOneTrailExid.d.ts +36 -0
  54. package/dist/domain.operations/lambdaEndpointWire/context/getOneTrailExid.js +53 -0
  55. package/dist/domain.operations/lambdaEndpointWire/context/getOneTrailExid.js.map +1 -0
  56. package/dist/domain.operations/lambdaEndpointWire/error/getIsContempErrorTagged.d.ts +1 -0
  57. package/dist/domain.operations/lambdaEndpointWire/error/getIsContempErrorTagged.js +32 -0
  58. package/dist/domain.operations/lambdaEndpointWire/error/getIsContempErrorTagged.js.map +1 -0
  59. package/dist/domain.operations/lambdaEndpointWire/error/getIsLambdaErrorResponse.d.ts +63 -0
  60. package/dist/domain.operations/lambdaEndpointWire/error/getIsLambdaErrorResponse.js +39 -0
  61. package/dist/domain.operations/lambdaEndpointWire/error/getIsLambdaErrorResponse.js.map +1 -0
  62. package/dist/domain.operations/lambdaEndpointWire/error/getLambdaErrorMetadata.js.map +1 -0
  63. package/dist/domain.operations/lambdaEndpointWire/error/getStackTraceString.js.map +1 -0
  64. package/dist/domain.operations/lambdaEndpointWire/error/throwIfCredentialsError.d.ts +54 -0
  65. package/dist/domain.operations/lambdaEndpointWire/error/throwIfCredentialsError.js +107 -0
  66. package/dist/domain.operations/lambdaEndpointWire/error/throwIfCredentialsError.js.map +1 -0
  67. package/dist/domain.operations/{genLambdaEndpoint/middleware → lambdaEndpointWire/frame}/getIsWrappedPayload.d.ts +6 -0
  68. package/dist/domain.operations/lambdaEndpointWire/frame/getIsWrappedPayload.js.map +1 -0
  69. package/dist/domain.operations/lambdaEndpointWire/getParsedResponse.d.ts +45 -0
  70. package/dist/domain.operations/lambdaEndpointWire/getParsedResponse.js +173 -0
  71. package/dist/domain.operations/lambdaEndpointWire/getParsedResponse.js.map +1 -0
  72. package/dist/domain.operations/lambdaEndpointWire/serde/asUnprefixedErrorMessage.d.ts +21 -0
  73. package/dist/domain.operations/lambdaEndpointWire/serde/asUnprefixedErrorMessage.js +33 -0
  74. package/dist/domain.operations/lambdaEndpointWire/serde/asUnprefixedErrorMessage.js.map +1 -0
  75. package/dist/domain.operations/lambdaEndpointWire/serde/getDecodedPayload.js.map +1 -0
  76. package/dist/domain.operations/lambdaEndpointWire/serde/getParsedJson.js.map +1 -0
  77. package/dist/domain.operations/runLambdaEndpoint/context/asLambdaContext.d.ts +24 -0
  78. package/dist/domain.operations/runLambdaEndpoint/context/asLambdaContext.js +70 -0
  79. package/dist/domain.operations/runLambdaEndpoint/context/asLambdaContext.js.map +1 -0
  80. package/dist/domain.operations/runLambdaEndpoint/dialect/LambdaEndpointRunOutput.d.ts +67 -0
  81. package/dist/domain.operations/runLambdaEndpoint/dialect/LambdaEndpointRunOutput.js +3 -0
  82. package/dist/domain.operations/runLambdaEndpoint/dialect/LambdaEndpointRunOutput.js.map +1 -0
  83. package/dist/domain.operations/runLambdaEndpoint/dialect/asLambdaEndpointDialect.d.ts +26 -0
  84. package/dist/domain.operations/runLambdaEndpoint/dialect/asLambdaEndpointDialect.js +43 -0
  85. package/dist/domain.operations/runLambdaEndpoint/dialect/asLambdaEndpointDialect.js.map +1 -0
  86. package/dist/domain.operations/runLambdaEndpoint/dialect/asLambdaEndpointOutput.d.ts +47 -0
  87. package/dist/domain.operations/runLambdaEndpoint/dialect/asLambdaEndpointOutput.js +89 -0
  88. package/dist/domain.operations/runLambdaEndpoint/dialect/asLambdaEndpointOutput.js.map +1 -0
  89. package/dist/domain.operations/runLambdaEndpoint/dialect/isLambdaEndpointErrorEnvelope.d.ts +73 -0
  90. package/dist/domain.operations/runLambdaEndpoint/dialect/isLambdaEndpointErrorEnvelope.js +108 -0
  91. package/dist/domain.operations/runLambdaEndpoint/dialect/isLambdaEndpointErrorEnvelope.js.map +1 -0
  92. package/dist/domain.operations/runLambdaEndpoint/error/isErrorLike.d.ts +50 -0
  93. package/dist/domain.operations/runLambdaEndpoint/error/isErrorLike.js +55 -0
  94. package/dist/domain.operations/runLambdaEndpoint/error/isErrorLike.js.map +1 -0
  95. package/dist/domain.operations/runLambdaEndpoint/guard/assertEventIsGiven.d.ts +56 -0
  96. package/dist/domain.operations/runLambdaEndpoint/guard/assertEventIsGiven.js +57 -0
  97. package/dist/domain.operations/runLambdaEndpoint/guard/assertEventIsGiven.js.map +1 -0
  98. package/dist/domain.operations/runLambdaEndpoint/guard/assertHandlerIsRunnable.d.ts +16 -0
  99. package/dist/domain.operations/runLambdaEndpoint/guard/assertHandlerIsRunnable.js +71 -0
  100. package/dist/domain.operations/runLambdaEndpoint/guard/assertHandlerIsRunnable.js.map +1 -0
  101. package/dist/domain.operations/runLambdaEndpoint/local/asLocalRunIdentity.d.ts +48 -0
  102. package/dist/domain.operations/runLambdaEndpoint/local/asLocalRunIdentity.js +57 -0
  103. package/dist/domain.operations/runLambdaEndpoint/local/asLocalRunIdentity.js.map +1 -0
  104. package/dist/domain.operations/runLambdaEndpoint/local/getOneHandlerFromServerlessYml.d.ts +18 -0
  105. package/dist/domain.operations/runLambdaEndpoint/local/getOneHandlerFromServerlessYml.js +239 -0
  106. package/dist/domain.operations/runLambdaEndpoint/local/getOneHandlerFromServerlessYml.js.map +1 -0
  107. package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.d.ts +82 -0
  108. package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.js +67 -0
  109. package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.js.map +1 -0
  110. package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onReferenced.d.ts +120 -0
  111. package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onReferenced.js +119 -0
  112. package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onReferenced.js.map +1 -0
  113. package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onSerialized.d.ts +98 -0
  114. package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onSerialized.js +176 -0
  115. package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onSerialized.js.map +1 -0
  116. package/dist/domain.operations/runLambdaEndpoint/serde/asFramedPayload.d.ts +41 -0
  117. package/dist/domain.operations/runLambdaEndpoint/serde/asFramedPayload.js +62 -0
  118. package/dist/domain.operations/runLambdaEndpoint/serde/asFramedPayload.js.map +1 -0
  119. package/dist/domain.operations/runLambdaEndpoint/serde/asWireFunctionErrorPayload.d.ts +40 -0
  120. package/dist/domain.operations/runLambdaEndpoint/serde/asWireFunctionErrorPayload.js +68 -0
  121. package/dist/domain.operations/runLambdaEndpoint/serde/asWireFunctionErrorPayload.js.map +1 -0
  122. package/dist/domain.operations/runLambdaEndpoint/serde/asWirePayload.d.ts +34 -0
  123. package/dist/domain.operations/runLambdaEndpoint/serde/asWirePayload.js +39 -0
  124. package/dist/domain.operations/runLambdaEndpoint/serde/asWirePayload.js.map +1 -0
  125. package/dist/domain.operations/runLambdaEndpoint/serde/asWireStripped.d.ts +25 -0
  126. package/dist/domain.operations/runLambdaEndpoint/serde/asWireStripped.js +85 -0
  127. package/dist/domain.operations/runLambdaEndpoint/serde/asWireStripped.js.map +1 -0
  128. package/dist/index.d.ts +9 -0
  129. package/dist/index.js +25 -1
  130. package/dist/index.js.map +1 -1
  131. package/package.json +2 -1
  132. package/readme.md +108 -49
  133. package/dist/domain.operations/askLambdaEndpoint/context/getExidFromContext.js.map +0 -1
  134. package/dist/domain.operations/askLambdaEndpoint/context/getLogForExidExtraction.js.map +0 -1
  135. package/dist/domain.operations/askLambdaEndpoint/error/getIsLambdaErrorResponse.d.ts +0 -42
  136. package/dist/domain.operations/askLambdaEndpoint/error/getIsLambdaErrorResponse.js +0 -21
  137. package/dist/domain.operations/askLambdaEndpoint/error/getIsLambdaErrorResponse.js.map +0 -1
  138. package/dist/domain.operations/askLambdaEndpoint/error/getLambdaErrorMetadata.js.map +0 -1
  139. package/dist/domain.operations/askLambdaEndpoint/error/getStackTraceString.js.map +0 -1
  140. package/dist/domain.operations/askLambdaEndpoint/serde/asUnprefixedErrorMessage.d.ts +0 -13
  141. package/dist/domain.operations/askLambdaEndpoint/serde/asUnprefixedErrorMessage.js +0 -26
  142. package/dist/domain.operations/askLambdaEndpoint/serde/asUnprefixedErrorMessage.js.map +0 -1
  143. package/dist/domain.operations/askLambdaEndpoint/serde/getDecodedPayload.js.map +0 -1
  144. package/dist/domain.operations/askLambdaEndpoint/serde/getParsedJson.js.map +0 -1
  145. package/dist/domain.operations/askLambdaEndpoint/serde/getParsedResponse.d.ts +0 -15
  146. package/dist/domain.operations/askLambdaEndpoint/serde/getParsedResponse.js +0 -100
  147. package/dist/domain.operations/askLambdaEndpoint/serde/getParsedResponse.js.map +0 -1
  148. package/dist/domain.operations/genLambdaEndpoint/middleware/getIsWrappedPayload.js.map +0 -1
  149. /package/dist/domain.operations/{askLambdaEndpoint → lambdaEndpointWire}/context/getExidFromContext.d.ts +0 -0
  150. /package/dist/domain.operations/{askLambdaEndpoint → lambdaEndpointWire}/context/getExidFromContext.js +0 -0
  151. /package/dist/domain.operations/{askLambdaEndpoint → lambdaEndpointWire}/context/getLogForExidExtraction.d.ts +0 -0
  152. /package/dist/domain.operations/{askLambdaEndpoint → lambdaEndpointWire}/context/getLogForExidExtraction.js +0 -0
  153. /package/dist/domain.operations/{askLambdaEndpoint → lambdaEndpointWire}/error/getLambdaErrorMetadata.d.ts +0 -0
  154. /package/dist/domain.operations/{askLambdaEndpoint → lambdaEndpointWire}/error/getLambdaErrorMetadata.js +0 -0
  155. /package/dist/domain.operations/{askLambdaEndpoint → lambdaEndpointWire}/error/getStackTraceString.d.ts +0 -0
  156. /package/dist/domain.operations/{askLambdaEndpoint → lambdaEndpointWire}/error/getStackTraceString.js +0 -0
  157. /package/dist/domain.operations/{genLambdaEndpoint/middleware → lambdaEndpointWire/frame}/getIsWrappedPayload.js +0 -0
  158. /package/dist/domain.operations/{askLambdaEndpoint → lambdaEndpointWire}/serde/getDecodedPayload.d.ts +0 -0
  159. /package/dist/domain.operations/{askLambdaEndpoint → lambdaEndpointWire}/serde/getDecodedPayload.js +0 -0
  160. /package/dist/domain.operations/{askLambdaEndpoint → lambdaEndpointWire}/serde/getParsedJson.d.ts +0 -0
  161. /package/dist/domain.operations/{askLambdaEndpoint → lambdaEndpointWire}/serde/getParsedJson.js +0 -0
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runLambdaEndpoint = void 0;
4
+ const runLambdaEndpoint_onReferenced_1 = require("./runLambdaEndpoint.onReferenced");
5
+ const runLambdaEndpoint_onSerialized_1 = require("./runLambdaEndpoint.onSerialized");
6
+ /**
7
+ * .what = runs a lambda endpoint, on either side of the RUN BOUNDARY
8
+ * .why = to run an endpoint, shapes must cross a boundary into it. they cross one
9
+ * of two ways, and the way they cross is a domain axis
10
+ * (define.lambda-endpoint-run-boundary)
11
+ *
12
+ * | boundary | shapes cross as | you hold |
13
+ * |----------|-----------------|----------|
14
+ * | **serialized** | json over a wire (real or simulated) | the endpoint's **slug** |
15
+ * | **referenced** | live object references, same process | the handler **function** |
16
+ *
17
+ * ```ts
18
+ * runLambdaEndpoint.onSerialized({ which, event, at: 'cloud' | 'local' }, context)
19
+ * runLambdaEndpoint.onReferenced({ handler, event }) // no `at` — none is possible
20
+ * ```
21
+ *
22
+ * ## 🔴 the boundary determines the ERROR STANCE
23
+ *
24
+ * this is the axis's whole value: it is *causal*, so it predicts behavior that a
25
+ * locus axis (cloud vs local) does not.
26
+ *
27
+ * | boundary | a constraint error arrives as | why |
28
+ * |----------|-------------------------------|-----|
29
+ * | **serialized** | a **thrown** error | you addressed the endpoint by slug, so you are a CALLER |
30
+ * | **referenced** | a **returned** envelope | you hold the handler, so you are the HOST |
31
+ *
32
+ * locus does not cleave this. `at: 'local'` and `at: 'cloud'` sit on the **same**
33
+ * side — both throw.
34
+ *
35
+ * ## the matrix — 4 cells, 3 reachable, 1 barred by nature
36
+ *
37
+ * | | **local** | **cloud** |
38
+ * |---|---|---|
39
+ * | **serialized** | ✅ look the slug up, simulate the wire | ✅ the real wire |
40
+ * | **referenced** | ✅ hold the handler, call it | 🚫 **barred** |
41
+ *
42
+ * ⚠️ **`referenced × cloud` is impossible: a function reference cannot cross a
43
+ * process.** to reach a cloud lambda you must name it, and to name it is to
44
+ * serialize.
45
+ *
46
+ * 🔴 **and the bar is UNREPRESENTABLE, by arity** — not documented and policed:
47
+ * `onSerialized` takes `at`, because a slug points either way;
48
+ * `onReferenced` takes **no** `at`, because a reference has one locus only.
49
+ * ⇒ `rule.prefer.prevent-over-correct`, rung 1: make it impossible.
50
+ *
51
+ * ## what it replaces
52
+ *
53
+ * | incumbent | successor |
54
+ * |---|---|
55
+ * | `invokeLambdaForTesting({ …, locally: false })` | `runLambdaEndpoint.onSerialized({ …, at: 'cloud' })` |
56
+ * | `invokeLambdaForTesting({ …, locally: true })` | `runLambdaEndpoint.onSerialized({ …, at: 'local' })` |
57
+ * | `invokeHandlerForTesting({ event, handler })` | `runLambdaEndpoint.onReferenced({ handler, event })` |
58
+ *
59
+ * ⚠️ the incumbent's `locally = false` is a **negative-default boolean** whose
60
+ * name states a locus and hides a stance. the named variants state both
61
+ * (`rule.forbid.ambiguous-labels`).
62
+ */
63
+ exports.runLambdaEndpoint = {
64
+ onReferenced: runLambdaEndpoint_onReferenced_1.onReferenced,
65
+ onSerialized: runLambdaEndpoint_onSerialized_1.onSerialized,
66
+ };
67
+ //# sourceMappingURL=runLambdaEndpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runLambdaEndpoint.js","sourceRoot":"","sources":["../../../src/domain.operations/runLambdaEndpoint/runLambdaEndpoint.ts"],"names":[],"mappings":";;;AAAA,qFAAgE;AAChE,qFAAgE;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACU,QAAA,iBAAiB,GAAG;IAC/B,YAAY,EAAZ,6CAAY;IACZ,YAAY,EAAZ,6CAAY;CACb,CAAC"}
@@ -0,0 +1,120 @@
1
+ import type { Context } from 'aws-lambda';
2
+ import type { LambdaEndpointDialect } from '../../domain.objects/LambdaEndpointDialect';
3
+ import type { LambdaEndpointRunOutput } from './dialect/LambdaEndpointRunOutput';
4
+ /**
5
+ * .what = a handler reachable by reference — the function itself, in this process
6
+ * .why = deliberately loose: a plain lambda handler, NOT a `genLambdaEndpoint`
7
+ * return type. 19 of 20 repos and 314 of 318 legacy call sites still define
8
+ * handlers with `createStandardHandler`; bind this to `genLambdaEndpoint` and
9
+ * none of them can adopt the util until they finish a migration not yet started.
10
+ */
11
+ export type LambdaEndpointHandlerReferenced<TEvent, TOutput> = (event: TEvent, context: Context) => Promise<TOutput> | TOutput;
12
+ /**
13
+ * .what = runs a lambda endpoint you hold a REFERENCE to — the handler function
14
+ * itself, in this process
15
+ * .why = shapes cross this boundary as live object references, so you are the
16
+ * endpoint's HOST rather than its caller — and a host sees what the
17
+ * function returned (define.lambda-endpoint-run-boundary)
18
+ *
19
+ * ## the error stance — a pass-through, both directions
20
+ *
21
+ * the handler RETURNS a constraint envelope ⇒ this returns it, stripped. the
22
+ * handler THROWS a malfunction ⇒ this lets it throw, untouched.
23
+ *
24
+ * ⚠️ it does NOT convert an envelope into a throw — that is the WIRE's job
25
+ * (`getParsedResponse`), and it is what makes `onSerialized` throw where this
26
+ * returns. nor does it swallow a throw: that needs a `catch` over a server
27
+ * fault (rule.forbid.failhide).
28
+ *
29
+ * ## the fidelity guard
30
+ *
31
+ * the event is json-stripped inbound and the output json-stripped outbound. this
32
+ * boundary crosses no wire, so without the strip a `Date` survives either way and
33
+ * a test passes on a shape the wire could never deliver.
34
+ *
35
+ * ## 🔴 the dialect frames the INPUT too, not only the answer
36
+ *
37
+ * | dialect | the handler RECEIVES | it must ANSWER |
38
+ * |---------|---------------------|----------------|
39
+ * | `contemp` (default) | `{ event, trail }` — the wrapper IS the declaration | the nested envelope |
40
+ * | `ancient` | the event, untouched | the flat `{ errorMessage, errorType }` |
41
+ *
42
+ * a `genLambdaEndpoint` handler never notices — `genTrailMiddleware` unwraps the
43
+ * frame first. a PLAIN handler does, and the failure is QUIET: contemp-framed, it
44
+ * reads `event.uuid` off the wrapper, finds `undefined`, and takes its own reject
45
+ * branch — a rejection envelope on the success case, with no type error anywhere.
46
+ *
47
+ * ⇒ so a legacy `createStandardHandler` handler needs `struct: { payload: 'ancient' }`.
48
+ * the frame is DERIVED from `struct.payload`, never from `trail`, so the two
49
+ * cannot disagree.
50
+ *
51
+ * ## two gates stand between a call and an error field, in order
52
+ *
53
+ * the return is a UNION — `TOutput | Envelope` — because a caller fault is a
54
+ * legitimate answer. so the union rejects every error field on either dialect;
55
+ * narrow FIRST, and only then does the dialect decide which fields you may read.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * // success — the handler's validated output, wire-stripped
60
+ * const out = await runLambdaEndpoint.onReferenced({ event: { uuid }, handler });
61
+ * expect(asLambdaEndpointOutput(out).found).toEqual(true);
62
+ *
63
+ * // a caller fault — an envelope, RETURNED. the lambda succeeded.
64
+ * const res = await runLambdaEndpoint.onReferenced({ event: { uuid: 'bad' }, handler });
65
+ * expect(asLambdaEndpointErrorEnvelopeContemp(res).error.class).toEqual('ConstraintError');
66
+ *
67
+ * // the ancient dialect, opt-in — declared on the call, and again on the narrow
68
+ * const old = await runLambdaEndpoint.onReferenced({
69
+ * event: { uuid: 'bad' }, handler, struct: { payload: 'ancient' },
70
+ * });
71
+ * expect(asLambdaEndpointErrorEnvelopeAncient(old).errorType).toEqual('BadRequestError');
72
+ *
73
+ * // a malfunction — THROWN, untouched, on either dialect
74
+ * await expect(
75
+ * runLambdaEndpoint.onReferenced({ event, handler: brokenHandler }),
76
+ * ).rejects.toThrow(MalfunctionError);
77
+ * ```
78
+ */
79
+ export declare const onReferenced: <TEvent, TOutput, TDialect extends LambdaEndpointDialect = "contemp">(input: {
80
+ /**
81
+ * the event to send, as the endpoint's own input shape
82
+ */
83
+ event: TEvent;
84
+ /**
85
+ * the handler to run — held by reference, so no slug and no `at`
86
+ *
87
+ * 🔴 the `any` on the EVENT slot is deliberate — every alternative was probed:
88
+ *
89
+ * | event param | consumer errors | why |
90
+ * |---|---|---|
91
+ * | `unknown` | **24** | contravariant under `strictFunctionTypes`, so it demands a handler that accepts EVERY shape — it refuses every typed handler |
92
+ * | `never` | 0 | variance-correct, and then `handler(payload, …)` cannot compile |
93
+ * | `TEvent`, both slots | 0 | works, and 🔴 rejects a schema-rejection fixture (`TS2741`) and a wire-hostile `Date` (`TS2322`) |
94
+ * | `any` | 0 | what ships |
95
+ *
96
+ * 🔴 the `TEvent` row is the one to hold: a handler's event type is the
97
+ * POST-validation shape, so a test that proves *"the schema refuses this"*
98
+ * must send an event that does not fit it. to bind `TEvent` bars `[case2]`
99
+ * and `[case4]`, the two experiences the util was built for.
100
+ *
101
+ * ⇒ the looseness is caught at RUNTIME — `assertHandlerIsRunnable` below.
102
+ */
103
+ handler: LambdaEndpointHandlerReferenced<any, TOutput>;
104
+ /**
105
+ * which error dialect the endpoint answers in. contemp by default.
106
+ */
107
+ struct?: {
108
+ payload: TDialect;
109
+ };
110
+ /**
111
+ * the trail to carry. supplies the exid only — it never selects the dialect.
112
+ */
113
+ trail?: {
114
+ exid?: string;
115
+ } | null;
116
+ /**
117
+ * overrides for the aws lambda context the handler receives
118
+ */
119
+ context?: Partial<Context>;
120
+ }) => Promise<LambdaEndpointRunOutput<TOutput, TDialect>>;
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onReferenced = void 0;
4
+ const asLambdaContext_1 = require("./context/asLambdaContext");
5
+ const asLambdaEndpointDialect_1 = require("./dialect/asLambdaEndpointDialect");
6
+ const assertEventIsGiven_1 = require("./guard/assertEventIsGiven");
7
+ const assertHandlerIsRunnable_1 = require("./guard/assertHandlerIsRunnable");
8
+ const asFramedPayload_1 = require("./serde/asFramedPayload");
9
+ const asWireStripped_1 = require("./serde/asWireStripped");
10
+ /**
11
+ * .what = runs a lambda endpoint you hold a REFERENCE to — the handler function
12
+ * itself, in this process
13
+ * .why = shapes cross this boundary as live object references, so you are the
14
+ * endpoint's HOST rather than its caller — and a host sees what the
15
+ * function returned (define.lambda-endpoint-run-boundary)
16
+ *
17
+ * ## the error stance — a pass-through, both directions
18
+ *
19
+ * the handler RETURNS a constraint envelope ⇒ this returns it, stripped. the
20
+ * handler THROWS a malfunction ⇒ this lets it throw, untouched.
21
+ *
22
+ * ⚠️ it does NOT convert an envelope into a throw — that is the WIRE's job
23
+ * (`getParsedResponse`), and it is what makes `onSerialized` throw where this
24
+ * returns. nor does it swallow a throw: that needs a `catch` over a server
25
+ * fault (rule.forbid.failhide).
26
+ *
27
+ * ## the fidelity guard
28
+ *
29
+ * the event is json-stripped inbound and the output json-stripped outbound. this
30
+ * boundary crosses no wire, so without the strip a `Date` survives either way and
31
+ * a test passes on a shape the wire could never deliver.
32
+ *
33
+ * ## 🔴 the dialect frames the INPUT too, not only the answer
34
+ *
35
+ * | dialect | the handler RECEIVES | it must ANSWER |
36
+ * |---------|---------------------|----------------|
37
+ * | `contemp` (default) | `{ event, trail }` — the wrapper IS the declaration | the nested envelope |
38
+ * | `ancient` | the event, untouched | the flat `{ errorMessage, errorType }` |
39
+ *
40
+ * a `genLambdaEndpoint` handler never notices — `genTrailMiddleware` unwraps the
41
+ * frame first. a PLAIN handler does, and the failure is QUIET: contemp-framed, it
42
+ * reads `event.uuid` off the wrapper, finds `undefined`, and takes its own reject
43
+ * branch — a rejection envelope on the success case, with no type error anywhere.
44
+ *
45
+ * ⇒ so a legacy `createStandardHandler` handler needs `struct: { payload: 'ancient' }`.
46
+ * the frame is DERIVED from `struct.payload`, never from `trail`, so the two
47
+ * cannot disagree.
48
+ *
49
+ * ## two gates stand between a call and an error field, in order
50
+ *
51
+ * the return is a UNION — `TOutput | Envelope` — because a caller fault is a
52
+ * legitimate answer. so the union rejects every error field on either dialect;
53
+ * narrow FIRST, and only then does the dialect decide which fields you may read.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * // success — the handler's validated output, wire-stripped
58
+ * const out = await runLambdaEndpoint.onReferenced({ event: { uuid }, handler });
59
+ * expect(asLambdaEndpointOutput(out).found).toEqual(true);
60
+ *
61
+ * // a caller fault — an envelope, RETURNED. the lambda succeeded.
62
+ * const res = await runLambdaEndpoint.onReferenced({ event: { uuid: 'bad' }, handler });
63
+ * expect(asLambdaEndpointErrorEnvelopeContemp(res).error.class).toEqual('ConstraintError');
64
+ *
65
+ * // the ancient dialect, opt-in — declared on the call, and again on the narrow
66
+ * const old = await runLambdaEndpoint.onReferenced({
67
+ * event: { uuid: 'bad' }, handler, struct: { payload: 'ancient' },
68
+ * });
69
+ * expect(asLambdaEndpointErrorEnvelopeAncient(old).errorType).toEqual('BadRequestError');
70
+ *
71
+ * // a malfunction — THROWN, untouched, on either dialect
72
+ * await expect(
73
+ * runLambdaEndpoint.onReferenced({ event, handler: brokenHandler }),
74
+ * ).rejects.toThrow(MalfunctionError);
75
+ * ```
76
+ */
77
+ const onReferenced = async (input) => {
78
+ // 🔴 an ABSENT event is REFUSED, never defaulted to `{}`. the corpus settles
79
+ // the direction: `event: {}` is the measured convention for an endpoint
80
+ // that takes no input (`event: undefined` → 0 matches across `ahbode/*`).
81
+ //
82
+ // ⚠️ the row the guard is owed for is a plain handler that READS rather
83
+ // than derefs — `(e) => e.slug` raises no error at all, so it answers a
84
+ // success-shaped value for work that ran on no input
85
+ // (`rule.forbid.failhide`).
86
+ (0, assertEventIsGiven_1.assertEventIsGiven)({ event: input.event, metadata: null });
87
+ // the dialect declares the frame; an unknown value is REFUSED, never fallen
88
+ // through — see `asLambdaEndpointDialect` for why
89
+ const dialect = (0, asLambdaEndpointDialect_1.asLambdaEndpointDialect)({
90
+ declared: input.struct?.payload,
91
+ });
92
+ // strip inbound, so no live object reaches the handler that the wire could not deliver
93
+ // `of: 'event'` — a refusal here is the CALLER's payload, so it raises a ConstraintError
94
+ const eventStripped = (0, asWireStripped_1.asWireStripped)({ value: input.event, of: 'event' });
95
+ // frame the payload, so the endpoint reads the dialect the caller declared
96
+ const payload = (0, asFramedPayload_1.asFramedPayload)({
97
+ event: eventStripped,
98
+ trail: input.trail ?? null,
99
+ dialect,
100
+ });
101
+ const context = (0, asLambdaContext_1.asLambdaContext)(input.context);
102
+ // shared with the serialized boundary, which needs it ahead of its delegation
103
+ (0, assertHandlerIsRunnable_1.assertHandlerIsRunnable)({ handler: input.handler });
104
+ // run it. a throw crosses untouched — this util adds no catch, and the absence
105
+ // is clamped for both actors (`[case3][t0]/[t1]`, `[case7][t2]`).
106
+ const output = await input.handler(payload, context);
107
+ // strip outbound, so no live object reaches the author that the wire would flatten
108
+ // `of: 'output'` — a refusal here is the HANDLER's return ⇒ MalfunctionError
109
+ //
110
+ // .as = a checker limit, never a shapefit dodge. `LambdaEndpointRunOutput` is a
111
+ // CONDITIONAL on an unresolved `TDialect`, which typescript cannot reduce
112
+ // inside a generic body; it resolves at every call site.
113
+ return (0, asWireStripped_1.asWireStripped)({
114
+ value: output,
115
+ of: 'output',
116
+ });
117
+ };
118
+ exports.onReferenced = onReferenced;
119
+ //# sourceMappingURL=runLambdaEndpoint.onReferenced.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runLambdaEndpoint.onReferenced.js","sourceRoot":"","sources":["../../../src/domain.operations/runLambd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AAO,EAAE,OAAO,CAAC,CAAC;IAErD,mFAAmF;IACnF,6EAA6E;IAC7E,EAAE;IACF,gFAAgF;IAChF,4EAA4E;IAC5E,2DAA2D;IAC3D,OAAO,IAAA,+BAAc,EAAC;QACpB,KAAK,EAAE,MAAM;QACb,EAAE,EAAE,QAAQ;KACb,CAA+C,CAAC;AACnD,CAAC,CAAC;AA5FW,QAAA,YAAY,gBA4FvB"}
@@ -0,0 +1,98 @@
1
+ import type { ContextAwsLambdaCaller } from '../../domain.objects/ContextAwsLambdaCaller';
2
+ import type { LambdaEndpointDialect } from '../../domain.objects/LambdaEndpointDialect';
3
+ import type { WireDelivered } from './dialect/LambdaEndpointRunOutput';
4
+ /**
5
+ * .what = where the endpoint runs, once you address it by slug
6
+ * .why = a slug points either at the real wire or at this repo's own
7
+ * serverless.yml. both cross the SERIALIZED boundary, so both take caller
8
+ * semantics — the locus changes where, never what
9
+ * (define.lambda-endpoint-run-boundary)
10
+ */
11
+ export type LambdaEndpointLocus = 'cloud' | 'local';
12
+ /**
13
+ * .what = runs a lambda endpoint you hold the SLUG of — `{ service, function }`
14
+ * plus the ambient access
15
+ * .why = shapes cross this boundary as json, so you are the endpoint's CALLER
16
+ * rather than its host — and a caller gets caller semantics
17
+ *
18
+ * ## 🔴 the error stance INVERTS, and that is the whole reason for the split
19
+ *
20
+ * | boundary | a constraint error arrives as | because |
21
+ * |----------|-------------------------------|---------|
22
+ * | `onReferenced` | a **returned** envelope | you hold the handler, so you are the HOST |
23
+ * | `onSerialized` | a **thrown** `ConstraintError` | you named the endpoint, so you are a CALLER |
24
+ *
25
+ * ⚠️ `at` does NOT cleave this — `'local'` and `'cloud'` both throw. a constraint
26
+ * fault is RETURNED by the handler and reaches the shared hydration by itself;
27
+ * a malfunction is THROWN, so `asWireFunctionErrorPayload` casts it into the
28
+ * payload aws would have sent. one hydration, both loci, both outcome families.
29
+ *
30
+ * ⚠️ the type does not catch a move across the boundary — a rejected `Promise<T>`
31
+ * is well-typed, so an author who comes from `onReferenced` and still expects a
32
+ * returned envelope gets a runtime surprise. the subdomain names are the cue.
33
+ *
34
+ * ## the two loci cannot drift
35
+ *
36
+ * `'local'` runs the handler in-process, then hands its output through the SAME
37
+ * hydration the wire uses (`getParsedResponse`). one hydration, not two.
38
+ *
39
+ * ## 🔴 what the move off the incumbent buys
40
+ *
41
+ * the incumbent reaches aws through `simple-lambda-client`, which pulls aws-sdk v2
42
+ * — no sso-profile support, so it hangs on IMDS. measured at **90s per invoke** on
43
+ * `ahbode/svc-home-services` PR #30 until credentials were exported to env vars.
44
+ * this sdk is on `@aws-sdk/client-lambda` v3, which reads an sso profile natively.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * // the deployed function, over the real wire
49
+ * const out = await runLambdaEndpoint.onSerialized(
50
+ * { which: { service: 'svc-home-services', function: 'getServiceBySlug' },
51
+ * event: { slug: 'surf-lesson' }, at: 'cloud' },
52
+ * { log, env: { access: 'prep' } },
53
+ * );
54
+ *
55
+ * // the same endpoint, run from this repo's serverless.yml
56
+ * const out = await runLambdaEndpoint.onSerialized({ …, at: 'local' }, { log, env });
57
+ *
58
+ * // a caller fault THROWS here, on either locus
59
+ * await expect(
60
+ * runLambdaEndpoint.onSerialized({ …, event: { slug: '' } }, ctx),
61
+ * ).rejects.toThrow(ConstraintError);
62
+ * ```
63
+ */
64
+ export declare const onSerialized: <TEvent, TOutput>(input: {
65
+ /**
66
+ * the endpoint's business identity. the ambient `context.env.access`
67
+ * completes the slug (rule.require.env-access-in-context).
68
+ */
69
+ which: {
70
+ service: string;
71
+ function: string;
72
+ };
73
+ /**
74
+ * the event to send
75
+ */
76
+ event: TEvent;
77
+ /**
78
+ * where the slug is looked up. cloud by default — the deployed function.
79
+ */
80
+ at?: LambdaEndpointLocus;
81
+ /**
82
+ * which error dialect to send in. contemp by default.
83
+ *
84
+ * 🔴 .note = a plain input here, NEVER a type parameter — unlike
85
+ * `onReferenced<…, TDialect>`. a type-level dialect needs an envelope in the
86
+ * return to guard, and this boundary has none: a caller fault is THROWN, and
87
+ * both dialects hydrate to the same error. so the dialect changes what goes
88
+ * over the WIRE and no shape the author can read; a `TDialect` here would
89
+ * advertise a guarantee with no arm to guard.
90
+ */
91
+ struct?: {
92
+ payload: LambdaEndpointDialect;
93
+ };
94
+ /**
95
+ * where to search for serverless.yml, when `at: 'local'`. cwd by default.
96
+ */
97
+ from?: string;
98
+ }, context: ContextAwsLambdaCaller) => Promise<WireDelivered<TOutput>>;
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onSerialized = void 0;
4
+ const helpful_errors_1 = require("helpful-errors");
5
+ const askLambdaEndpoint_1 = require("../askLambdaEndpoint/askLambdaEndpoint");
6
+ const asLambdaEndpoint_1 = require("../asLambdaEndpoint/asLambdaEndpoint");
7
+ const getOneTrailExid_1 = require("../lambdaEndpointWire/context/getOneTrailExid");
8
+ const throwIfCredentialsError_1 = require("../lambdaEndpointWire/error/throwIfCredentialsError");
9
+ const getParsedResponse_1 = require("../lambdaEndpointWire/getParsedResponse");
10
+ const asLambdaEndpointDialect_1 = require("./dialect/asLambdaEndpointDialect");
11
+ const assertEventIsGiven_1 = require("./guard/assertEventIsGiven");
12
+ const assertHandlerIsRunnable_1 = require("./guard/assertHandlerIsRunnable");
13
+ const asLocalRunIdentity_1 = require("./local/asLocalRunIdentity");
14
+ const getOneHandlerFromServerlessYml_1 = require("./local/getOneHandlerFromServerlessYml");
15
+ const runLambdaEndpoint_onReferenced_1 = require("./runLambdaEndpoint.onReferenced");
16
+ const asWireFunctionErrorPayload_1 = require("./serde/asWireFunctionErrorPayload");
17
+ const asWirePayload_1 = require("./serde/asWirePayload");
18
+ /**
19
+ * .what = runs a lambda endpoint you hold the SLUG of — `{ service, function }`
20
+ * plus the ambient access
21
+ * .why = shapes cross this boundary as json, so you are the endpoint's CALLER
22
+ * rather than its host — and a caller gets caller semantics
23
+ *
24
+ * ## 🔴 the error stance INVERTS, and that is the whole reason for the split
25
+ *
26
+ * | boundary | a constraint error arrives as | because |
27
+ * |----------|-------------------------------|---------|
28
+ * | `onReferenced` | a **returned** envelope | you hold the handler, so you are the HOST |
29
+ * | `onSerialized` | a **thrown** `ConstraintError` | you named the endpoint, so you are a CALLER |
30
+ *
31
+ * ⚠️ `at` does NOT cleave this — `'local'` and `'cloud'` both throw. a constraint
32
+ * fault is RETURNED by the handler and reaches the shared hydration by itself;
33
+ * a malfunction is THROWN, so `asWireFunctionErrorPayload` casts it into the
34
+ * payload aws would have sent. one hydration, both loci, both outcome families.
35
+ *
36
+ * ⚠️ the type does not catch a move across the boundary — a rejected `Promise<T>`
37
+ * is well-typed, so an author who comes from `onReferenced` and still expects a
38
+ * returned envelope gets a runtime surprise. the subdomain names are the cue.
39
+ *
40
+ * ## the two loci cannot drift
41
+ *
42
+ * `'local'` runs the handler in-process, then hands its output through the SAME
43
+ * hydration the wire uses (`getParsedResponse`). one hydration, not two.
44
+ *
45
+ * ## 🔴 what the move off the incumbent buys
46
+ *
47
+ * the incumbent reaches aws through `simple-lambda-client`, which pulls aws-sdk v2
48
+ * — no sso-profile support, so it hangs on IMDS. measured at **90s per invoke** on
49
+ * `ahbode/svc-home-services` PR #30 until credentials were exported to env vars.
50
+ * this sdk is on `@aws-sdk/client-lambda` v3, which reads an sso profile natively.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * // the deployed function, over the real wire
55
+ * const out = await runLambdaEndpoint.onSerialized(
56
+ * { which: { service: 'svc-home-services', function: 'getServiceBySlug' },
57
+ * event: { slug: 'surf-lesson' }, at: 'cloud' },
58
+ * { log, env: { access: 'prep' } },
59
+ * );
60
+ *
61
+ * // the same endpoint, run from this repo's serverless.yml
62
+ * const out = await runLambdaEndpoint.onSerialized({ …, at: 'local' }, { log, env });
63
+ *
64
+ * // a caller fault THROWS here, on either locus
65
+ * await expect(
66
+ * runLambdaEndpoint.onSerialized({ …, event: { slug: '' } }, ctx),
67
+ * ).rejects.toThrow(ConstraintError);
68
+ * ```
69
+ */
70
+ const onSerialized = async (input, context) => {
71
+ // an ABSENT event is refused HERE TOO, before the locus branch — the referenced
72
+ // twin's guard would answer the cloud locus 90s late and the local locus
73
+ // stripped of its hint. both halves measured; see `guard/assertEventIsGiven.ts`.
74
+ (0, assertEventIsGiven_1.assertEventIsGiven)({
75
+ event: input.event,
76
+ metadata: { which: input.which, at: input.at ?? 'cloud' },
77
+ });
78
+ const at = input.at ?? 'cloud';
79
+ // 🔴 an UNKNOWN locus is refused. the branch below reads `if (at === 'cloud')`
80
+ // and lets every other value fall to LOCAL, so `'CLOUD'` or an `at` read
81
+ // from config runs in-process while the caller believes they hit a deployed
82
+ // lambda — and a fall to local LOOKS LIKE A PASS where a fall to cloud
83
+ // would fail loud (`rule.forbid.unexpected-defaults`).
84
+ if (at !== 'cloud' && at !== 'local')
85
+ return helpful_errors_1.ConstraintError.throw('the locus given is not one this util can run', {
86
+ at,
87
+ options: ['cloud', 'local'],
88
+ hint: "pass `at: 'cloud'` to invoke the deployed lambda over the wire, or `at: 'local'` to resolve the handler from serverless.yml and run it in-process. omit `at` for the 'cloud' default.",
89
+ });
90
+ // 🔴 an UNKNOWN dialect is refused HERE, before either locus forwards it — the
91
+ // CLOUD half is what needs it, since local would be caught downstream. the
92
+ // result is BOUND and forwarded rather than discarded, so a delete of this
93
+ // line fails the build (`rule.prefer.prevent-over-correct`, rung 1).
94
+ const dialectValidated = (0, asLambdaEndpointDialect_1.asLambdaEndpointDialect)({
95
+ declared: input.struct?.payload,
96
+ });
97
+ const structValidated = { payload: dialectValidated };
98
+ // the cloud locus: the real wire, with v3 credentials and the sdk's own serde.
99
+ // the type argument is `WireDelivered<TOutput>`, never `TOutput` — it names
100
+ // the shape to PARSE OUT OF the wire payload.
101
+ //
102
+ // 🔴 the credentials fault is named HERE and deliberately NOT on
103
+ // `askLambdaEndpoint`. same aws error, opposite diagnosis:
104
+ //
105
+ // | boundary | who meets it | an absent credential is |
106
+ // |---|---|---|
107
+ // | `onSerialized({ at: 'cloud' })` | a developer, at a terminal | an expired sso session — one command away |
108
+ // | `askLambdaEndpoint` | a deployed lambda, in prod | a broken execution role — a server fault |
109
+ //
110
+ // `LambdaCredentialsAbsentError extends ConstraintError` ⇒ caller fault, NO
111
+ // ALARM. to map it on the runtime path would suppress the prod alarm that
112
+ // names a broken role (`invariant.badrequesterror-not-lambda-error`).
113
+ if (at === 'cloud')
114
+ return (0, askLambdaEndpoint_1.askLambdaEndpoint)({
115
+ which: input.which,
116
+ event: input.event,
117
+ struct: structValidated,
118
+ }, context).catch((error) => (0, throwIfCredentialsError_1.throwIfCredentialsError)({
119
+ error,
120
+ message: 'aws credentials are absent or expired, so the deployed endpoint cannot be invoked',
121
+ access: context.env.access,
122
+ metadata: {
123
+ which: input.which,
124
+ access: context.env.access,
125
+ at,
126
+ },
127
+ }));
128
+ // the local locus: look the handler up, run it, then hydrate exactly as the wire does
129
+ const endpoint = (0, asLambdaEndpoint_1.asLambdaEndpoint)({
130
+ service: input.which.service,
131
+ access: context.env.access,
132
+ function: input.which.function,
133
+ });
134
+ const handler = await (0, getOneHandlerFromServerlessYml_1.getOneHandlerFromServerlessYml)({
135
+ service: input.which.service,
136
+ function: input.which.function,
137
+ from: input.from,
138
+ });
139
+ // 🔴 the handler guards run HERE, ahead of the delegation — the placement IS
140
+ // the repair (see `serde/asWireFunctionErrorPayload.ts`). clamped at two
141
+ // grains, since the integration clamp imports an INTERNAL path and a barrel
142
+ // that re-caught on the way out would leave it green.
143
+ (0, assertHandlerIsRunnable_1.assertHandlerIsRunnable)({ handler });
144
+ // the exid AND its fallback report, in one call — the same call the cloud
145
+ // locus makes, so the two loci cannot diverge on this diagnostic
146
+ const exid = (0, getOneTrailExid_1.getOneTrailExid)({ log: context.log });
147
+ // reuse the referenced boundary to run it — the serialized-local cell is BUILT
148
+ // on the referenced cell, as the incumbent composes it
149
+ // (invokeLambdaForTestingLocally.ts:81).
150
+ // ⚠️ the `.catch` casts a THROW into the payload aws would have put on the
151
+ // wire, so it reaches the shared hydration below as the cloud locus does.
152
+ const output = await (0, runLambdaEndpoint_onReferenced_1.onReferenced)({
153
+ event: input.event,
154
+ handler,
155
+ struct: structValidated,
156
+ // the runtime identity is DERIVED from the endpoint, never a caller's knob —
157
+ // see `asLocalRunIdentity` for why a `context` passthrough is declined here
158
+ context: (0, asLocalRunIdentity_1.asLocalRunIdentity)({ endpoint, region: context.env.region }),
159
+ // 🟡 the trail, forwarded. omit it and the endpoint's trail middleware
160
+ // generates a fresh exid, so the caller's trace does not join up — and no
161
+ // test fails, because an absent trail is legal
162
+ // (`invariant.payload-format-compat`). it does NOT select the dialect.
163
+ trail: { exid },
164
+ }).catch(asWireFunctionErrorPayload_1.asWireFunctionErrorPayload);
165
+ // 🔴 one hydration, shared with the wire — so the two loci cannot disagree
166
+ // about what an envelope means. `asWirePayload` carries the one place they
167
+ // DO diverge (a void handler's value) and states why.
168
+ return (0, getParsedResponse_1.getParsedResponse)({
169
+ payload: (0, asWirePayload_1.asWirePayload)(output),
170
+ functionError: undefined,
171
+ endpoint,
172
+ exid,
173
+ });
174
+ };
175
+ exports.onSerialized = onSerialized;
176
+ //# sourceMappingURL=runLambdaEndpoint.onSerialized.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runLambdaEndpoint.onSerialized.js","sourceRoot":"","sources":["../../../src/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onSerialized.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAIjD,8EAA2E;AAC3E,2EAAwE;AACxE,mFAAgF;AAChF,iGAA8F;AAC9F,+EAA4E;AAC5E,+EAA4E;AAE5E,mEAAgE;AAChE,6EAA0E;AAC1E,mEAAgE;AAChE,2FAAwF;AACxF,qFAAgE;AAChE,mFAAgF;AAChF,yDAAsD;AAWtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACI,MAAM,YAAY,GAAG,KAAK,EAC/B,KAiCC,EACD,OAA+B,EAC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CAAkB,EAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QAErE,uEAAuE;QACvE,6EAA6E;QAC7E,kDAAkD;QAClD,0EAA0E;QAC1E,KAAK,EAAE,EAAE,IAAI,EAAE;KAChB,CAAC,CAAC,KAAK,CAAC,uDAA0B,CAAC,CAAC;IAErC,2EAA2E;IAC3E,8EAA8E;IAC9E,yDAAyD;IACzD,OAAO,IAAA,qCAAiB,EAAyB;QAC/C,OAAO,EAAE,IAAA,6BAAa,EAAC,MAAM,CAAC;QAC9B,aAAa,EAAE,SAAS;QACxB,QAAQ;QACR,IAAI;KACL,CAAC,CAAC;AACL,CAAC,CAAC;AAjKW,QAAA,YAAY,gBAiKvB"}
@@ -0,0 +1,41 @@
1
+ import type { LambdaEndpointDialect } from '../../../domain.objects/LambdaEndpointDialect';
2
+ /**
3
+ * .what = casts an event into the payload frame a given dialect sends
4
+ * .why = the endpoint reads the FRAME to decide the dialect — `getIsWrappedPayload`
5
+ * checks for exactly `{ event, trail }` — so the frame IS the declaration.
6
+ *
7
+ * | dialect | the frame emitted | getIsWrappedPayload |
8
+ * |---------|-------------------|---------------------|
9
+ * | contemp | `{ event, trail }` | true → contemp envelope |
10
+ * | ancient | the event, untouched | false → ancient envelope |
11
+ *
12
+ * 🔴 .the one knob
13
+ *
14
+ * F9 names an open bound in the vision: the frame is driven by `trail:` and the
15
+ * dialect is declared by `struct.payload` — **two knobs, one fact**, so they can
16
+ * be set to disagree, and that design admits a contemp envelope under an ancient
17
+ * return type.
18
+ *
19
+ * this closes it by DERIVATION: `struct.payload` is the only declaration, and the
20
+ * frame follows from it. `trail` supplies the exid and never the dialect. so the
21
+ * disagreement is unrepresentable rather than policed
22
+ * (rule.prefer.prevent-over-correct, rung 1).
23
+ *
24
+ * 🔴 .ancient drops the trail, exactly as the wire does
25
+ *
26
+ * `askLambdaEndpoint.ts:74-77` sends `input.event` and nothing else on the ancient
27
+ * dialect — the trail does not travel. this matches it verbatim.
28
+ *
29
+ * ⚠️ ancient never merges `{ ...event, trail }` for a caller that carries an exid
30
+ * — a shape `invariant.payload-format-compat` does describe, and that **no
31
+ * caller in this sdk ever sends**. that merge is backcompat nobody asked for,
32
+ * it makes the referenced boundary disagree with the wire, and it costs two
33
+ * defensive branches.
34
+ */
35
+ export declare const asFramedPayload: (input: {
36
+ event: unknown;
37
+ trail: {
38
+ exid?: string;
39
+ } | null;
40
+ dialect: LambdaEndpointDialect;
41
+ }) => unknown;