lambder 7.3.1 → 8.1.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 (237) hide show
  1. package/CHANGELOG.md +1047 -3
  2. package/README.md +46 -21
  3. package/dist/api/LambderApiAnswer.d.ts +18 -22
  4. package/dist/api/LambderApiAnswer.js +6 -7
  5. package/dist/api/LambderApiCallContext.d.ts +21 -8
  6. package/dist/api/LambderApiCallContext.js +22 -4
  7. package/dist/api/LambderApiDefinition.d.ts +4 -3
  8. package/dist/api/LambderApiEnvelope.d.ts +14 -9
  9. package/dist/api/LambderApiEnvelope.js +33 -34
  10. package/dist/api/LambderApiGuards.d.ts +78 -51
  11. package/dist/api/LambderApiGuards.js +34 -36
  12. package/dist/api/LambderApiIdempotency.d.ts +68 -62
  13. package/dist/api/LambderApiIdempotency.js +214 -151
  14. package/dist/api/LambderApiOutputValidationError.d.ts +32 -0
  15. package/dist/api/LambderApiOutputValidationError.js +50 -0
  16. package/dist/api/LambderApiPipeline.d.ts +47 -38
  17. package/dist/api/LambderApiPipeline.js +122 -63
  18. package/dist/api/LambderApiRateLimits.d.ts +201 -54
  19. package/dist/api/LambderApiRateLimits.js +185 -108
  20. package/dist/api/LambderApiRequest.d.ts +27 -21
  21. package/dist/api/LambderApiRequest.js +26 -19
  22. package/dist/api/LambderApiSignature.d.ts +12 -15
  23. package/dist/api/LambderApiSignature.js +28 -51
  24. package/dist/api/LambderApiValidationRefusal.d.ts +9 -9
  25. package/dist/api/LambderApiValidationRefusal.js +10 -10
  26. package/dist/build/ContractTypePrinter.d.ts +85 -0
  27. package/dist/build/ContractTypePrinter.js +402 -0
  28. package/dist/build/freshProcessVerifier.d.ts +13 -0
  29. package/dist/build/freshProcessVerifier.js +19 -0
  30. package/dist/build/moduleLocation.d.ts +11 -0
  31. package/dist/build/moduleLocation.js +6 -0
  32. package/dist/build/writeApiContract.d.ts +78 -0
  33. package/dist/build/writeApiContract.js +302 -0
  34. package/dist/build/writeApiSignatures.d.ts +114 -0
  35. package/dist/build/writeApiSignatures.js +217 -0
  36. package/dist/build/writeFileAtomically.d.ts +8 -0
  37. package/dist/build/writeFileAtomically.js +22 -0
  38. package/dist/build.d.ts +14 -0
  39. package/dist/build.js +11 -0
  40. package/dist/client/LambderCaller.d.ts +13 -44
  41. package/dist/client/LambderCaller.js +77 -84
  42. package/dist/client/LambderReloadLoopBreaker.d.ts +56 -26
  43. package/dist/client/LambderReloadLoopBreaker.js +90 -46
  44. package/dist/client/LambderUploadRunner.d.ts +96 -0
  45. package/dist/client/LambderUploadRunner.js +234 -0
  46. package/dist/client/lambderFetchTransport.d.ts +4 -1
  47. package/dist/client/lambderFetchTransport.js +52 -28
  48. package/dist/client.d.ts +9 -3
  49. package/dist/client.js +6 -1
  50. package/dist/core/Lambder.d.ts +143 -79
  51. package/dist/core/Lambder.js +350 -231
  52. package/dist/core/LambderContext.d.ts +82 -15
  53. package/dist/core/LambderContext.js +107 -20
  54. package/dist/core/LambderCors.d.ts +21 -3
  55. package/dist/core/LambderCors.js +35 -16
  56. package/dist/core/LambderCrashHandling.d.ts +40 -0
  57. package/dist/core/LambderCrashHandling.js +97 -0
  58. package/dist/core/LambderCreateOptions.d.ts +151 -75
  59. package/dist/core/LambderCreateOptions.js +16 -23
  60. package/dist/core/LambderFiles.d.ts +21 -7
  61. package/dist/core/LambderFiles.js +62 -34
  62. package/dist/core/LambderIndexHtml.js +12 -11
  63. package/dist/core/LambderPolicyBuilders.d.ts +17 -5
  64. package/dist/core/LambderPolicyBuilders.js +17 -5
  65. package/dist/core/LambderPublicFiles.d.ts +11 -5
  66. package/dist/core/LambderPublicFiles.js +32 -4
  67. package/dist/core/LambderRequestPath.d.ts +43 -0
  68. package/dist/core/LambderRequestPath.js +63 -0
  69. package/dist/core/LambderResponse.d.ts +26 -5
  70. package/dist/core/LambderResponse.js +157 -70
  71. package/dist/core/LambderResponseBuilder.d.ts +49 -4
  72. package/dist/core/LambderResponseBuilder.js +64 -3
  73. package/dist/core/LambderRouting.d.ts +2 -3
  74. package/dist/core/LambderRouting.js +22 -7
  75. package/dist/core/LambderTemplatingEngine.js +211 -32
  76. package/dist/index.d.ts +25 -8
  77. package/dist/index.js +13 -4
  78. package/dist/invoke/LambderInvokeCaller.d.ts +37 -42
  79. package/dist/invoke/LambderInvokeCaller.js +76 -66
  80. package/dist/invoke/LambderInvokeOutcome.d.ts +27 -26
  81. package/dist/invoke/LambderInvokeOutcome.js +9 -22
  82. package/dist/invoke/LambderLambdaEvent.d.ts +29 -9
  83. package/dist/invoke/LambderLambdaEvent.js +40 -22
  84. package/dist/invoke/lambderHandlerTransport.d.ts +9 -10
  85. package/dist/invoke/lambderHandlerTransport.js +15 -18
  86. package/dist/mock/LambderMockApp.d.ts +67 -83
  87. package/dist/mock/LambderMockApp.js +167 -153
  88. package/dist/mock/LambderMockBrowserCookies.d.ts +24 -28
  89. package/dist/mock/LambderMockBrowserCookies.js +24 -28
  90. package/dist/mock/LambderMockCallRecorder.d.ts +15 -22
  91. package/dist/mock/LambderMockCallRecorder.js +19 -28
  92. package/dist/mock/LambderMockCreateOptions.d.ts +42 -24
  93. package/dist/mock/LambderMockEntryRegistry.d.ts +11 -12
  94. package/dist/mock/LambderMockEntryRegistry.js +24 -29
  95. package/dist/mock/LambderMockFailureInjector.d.ts +3 -6
  96. package/dist/mock/LambderMockFailureInjector.js +3 -6
  97. package/dist/mock/LambderMockTypes.d.ts +78 -108
  98. package/dist/mock/lambderMockInvokeTransport.d.ts +11 -13
  99. package/dist/mock/lambderMockInvokeTransport.js +11 -10
  100. package/dist/mock/lambderMockMswHandler.d.ts +43 -33
  101. package/dist/mock/lambderMockMswHandler.js +50 -39
  102. package/dist/mock/lambderMockUploadMswHandler.d.ts +26 -0
  103. package/dist/mock/lambderMockUploadMswHandler.js +28 -0
  104. package/dist/mock.d.ts +4 -1
  105. package/dist/mock.js +6 -3
  106. package/dist/session/LambderSessionController.d.ts +108 -89
  107. package/dist/session/LambderSessionController.js +187 -168
  108. package/dist/session/LambderSessionCrypto.d.ts +16 -7
  109. package/dist/session/LambderSessionCrypto.js +26 -12
  110. package/dist/session/LambderSessionManager.d.ts +124 -46
  111. package/dist/session/LambderSessionManager.js +262 -137
  112. package/dist/shared/LambderHtml.d.ts +42 -3
  113. package/dist/shared/LambderHtml.js +127 -7
  114. package/dist/shared/LambderHtmlPositions.d.ts +173 -0
  115. package/dist/shared/LambderHtmlPositions.js +652 -0
  116. package/dist/shared/LambderI18n.d.ts +10 -11
  117. package/dist/shared/LambderI18n.js +33 -21
  118. package/dist/shared/contracts/LambderCache.d.ts +66 -0
  119. package/dist/shared/contracts/LambderCache.js +11 -0
  120. package/dist/shared/contracts/LambderFileSource.d.ts +6 -6
  121. package/dist/shared/contracts/LambderFileSource.js +5 -8
  122. package/dist/shared/contracts/LambderIdempotencyStore.d.ts +51 -22
  123. package/dist/shared/contracts/LambderIdempotencyStore.js +4 -5
  124. package/dist/shared/contracts/LambderRateLimiter.d.ts +27 -15
  125. package/dist/shared/contracts/LambderRateLimiter.js +4 -5
  126. package/dist/shared/contracts/LambderSessionStore.d.ts +65 -26
  127. package/dist/shared/contracts/LambderSessionStore.js +5 -6
  128. package/dist/shared/contracts/LambderUploadBucket.d.ts +154 -0
  129. package/dist/shared/contracts/LambderUploadBucket.js +74 -0
  130. package/dist/shared/transport/LambderApiTransport.d.ts +27 -27
  131. package/dist/shared/transport/LambderApiTransport.js +7 -7
  132. package/dist/shared/transport/LambderCookieJar.d.ts +28 -35
  133. package/dist/shared/transport/LambderCookieJar.js +54 -66
  134. package/dist/shared/transport/lambderCookieJarTransport.d.ts +11 -13
  135. package/dist/shared/transport/lambderCookieJarTransport.js +24 -23
  136. package/dist/shared/util/LambderCallAbort.d.ts +5 -5
  137. package/dist/shared/util/LambderCallAbort.js +5 -5
  138. package/dist/shared/util/LambderClientIp.d.ts +27 -11
  139. package/dist/shared/util/LambderClientIp.js +96 -13
  140. package/dist/shared/util/LambderContentDisposition.d.ts +10 -0
  141. package/dist/shared/util/LambderContentDisposition.js +13 -0
  142. package/dist/shared/util/LambderExpiringMap.d.ts +35 -49
  143. package/dist/shared/util/LambderExpiringMap.js +41 -57
  144. package/dist/shared/util/LambderNodeModules.js +6 -7
  145. package/dist/shared/util/LambderOptionChecks.d.ts +4 -4
  146. package/dist/shared/util/LambderOptionChecks.js +4 -4
  147. package/dist/shared/util/LambderResponseBrand.d.ts +5 -5
  148. package/dist/shared/util/LambderResponseBrand.js +5 -5
  149. package/dist/shared/util/LambderTextDigest.d.ts +7 -5
  150. package/dist/shared/util/LambderTextDigest.js +11 -5
  151. package/dist/shared/util/LambderTypeUtilities.d.ts +7 -8
  152. package/dist/shared/util/LambderTypeUtilities.js +3 -3
  153. package/dist/shared/util/boundKeyField.d.ts +20 -0
  154. package/dist/shared/util/boundKeyField.js +34 -0
  155. package/dist/shared/util/canonicalJson.d.ts +11 -0
  156. package/dist/shared/util/canonicalJson.js +28 -0
  157. package/dist/shared/util/joinKeyFields.d.ts +20 -0
  158. package/dist/shared/util/joinKeyFields.js +22 -0
  159. package/dist/shared/wire/LambderAnswerHeaders.d.ts +12 -16
  160. package/dist/shared/wire/LambderAnswerHeaders.js +12 -16
  161. package/dist/shared/wire/LambderApiContract.d.ts +98 -53
  162. package/dist/shared/wire/LambderApiOutcome.d.ts +43 -31
  163. package/dist/shared/wire/LambderApiOutcome.js +48 -23
  164. package/dist/shared/wire/LambderApiRefusal.d.ts +45 -27
  165. package/dist/shared/wire/LambderApiRefusal.js +42 -7
  166. package/dist/shared/wire/LambderApiSignature.d.ts +18 -22
  167. package/dist/shared/wire/LambderApiSignature.js +16 -19
  168. package/dist/shared/wire/LambderCallOptions.d.ts +38 -47
  169. package/dist/shared/wire/LambderCallOptions.js +9 -11
  170. package/dist/shared/wire/LambderCompressionCodec.d.ts +29 -34
  171. package/dist/shared/wire/LambderCompressionCodec.js +31 -36
  172. package/dist/shared/wire/LambderCompressionOption.d.ts +9 -9
  173. package/dist/shared/wire/LambderCompressionOption.js +9 -9
  174. package/dist/shared/wire/LambderCrashDetail.d.ts +12 -15
  175. package/dist/shared/wire/LambderCrashDetail.js +12 -15
  176. package/dist/shared/wire/LambderDefaultApiPath.d.ts +6 -0
  177. package/dist/shared/wire/LambderDefaultApiPath.js +6 -0
  178. package/dist/shared/wire/LambderHttpStatus.d.ts +6 -7
  179. package/dist/shared/wire/LambderIdempotencyKeyScope.d.ts +89 -0
  180. package/dist/shared/wire/LambderIdempotencyKeyScope.js +146 -0
  181. package/dist/shared/wire/LambderInvokeApiId.d.ts +27 -0
  182. package/dist/shared/wire/LambderInvokeApiId.js +27 -0
  183. package/dist/shared/wire/LambderOutcomeAssertions.d.ts +6 -7
  184. package/dist/shared/wire/LambderOutcomeAssertions.js +6 -7
  185. package/dist/shared/wire/LambderRequestPayload.d.ts +18 -20
  186. package/dist/shared/wire/LambderRequestPayload.js +4 -6
  187. package/dist/shared/wire/LambderUploadObjectFields.d.ts +10 -0
  188. package/dist/shared/wire/LambderUploadObjectFields.js +24 -0
  189. package/dist/shared/wire/LambderUploadRefusal.d.ts +9 -0
  190. package/dist/shared/wire/LambderUploadRefusal.js +18 -0
  191. package/dist/shared/wire/LambderUploadSchemas.d.ts +12 -0
  192. package/dist/shared/wire/LambderUploadSchemas.js +30 -0
  193. package/dist/stores/LambderCacheFiller.d.ts +48 -0
  194. package/dist/stores/LambderCacheFiller.js +119 -0
  195. package/dist/stores/LambderCacheKeys.d.ts +26 -0
  196. package/dist/stores/LambderCacheKeys.js +54 -0
  197. package/dist/stores/LambderCacheValues.d.ts +45 -0
  198. package/dist/stores/LambderCacheValues.js +74 -0
  199. package/dist/stores/LambderDdbCache.d.ts +121 -56
  200. package/dist/stores/LambderDdbCache.js +528 -225
  201. package/dist/stores/LambderDdbIdempotencyStore.d.ts +33 -22
  202. package/dist/stores/LambderDdbIdempotencyStore.js +75 -50
  203. package/dist/stores/LambderDdbRateLimiter.d.ts +76 -20
  204. package/dist/stores/LambderDdbRateLimiter.js +151 -39
  205. package/dist/stores/LambderDdbSdk.d.ts +43 -31
  206. package/dist/stores/LambderDdbSdk.js +80 -38
  207. package/dist/stores/LambderDdbSessionStore.d.ts +27 -14
  208. package/dist/stores/LambderDdbSessionStore.js +119 -47
  209. package/dist/stores/LambderHttpFileSource.d.ts +15 -6
  210. package/dist/stores/LambderHttpFileSource.js +15 -13
  211. package/dist/stores/LambderMemoryCache.d.ts +49 -0
  212. package/dist/stores/LambderMemoryCache.js +113 -0
  213. package/dist/stores/LambderMemoryIdempotencyStore.d.ts +13 -12
  214. package/dist/stores/LambderMemoryIdempotencyStore.js +31 -30
  215. package/dist/stores/LambderMemoryRateLimiter.d.ts +8 -9
  216. package/dist/stores/LambderMemoryRateLimiter.js +14 -13
  217. package/dist/stores/LambderMemorySessionStore.d.ts +14 -11
  218. package/dist/stores/LambderMemorySessionStore.js +38 -19
  219. package/dist/stores/LambderMemoryUploadBucket.d.ts +99 -0
  220. package/dist/stores/LambderMemoryUploadBucket.js +219 -0
  221. package/dist/stores/LambderS3FileSource.d.ts +21 -6
  222. package/dist/stores/LambderS3FileSource.js +12 -7
  223. package/dist/stores/LambderS3UploadBucket.d.ts +73 -0
  224. package/dist/stores/LambderS3UploadBucket.js +144 -0
  225. package/dist/stores/LambderSdkInstallHint.d.ts +11 -0
  226. package/dist/stores/LambderSdkInstallHint.js +14 -0
  227. package/dist/testing/LambderTestApp.d.ts +23 -25
  228. package/dist/testing/LambderTestApp.js +22 -24
  229. package/dist/testing/LambderTestVisitor.d.ts +10 -12
  230. package/dist/testing/LambderTestVisitor.js +15 -15
  231. package/dist/testing.d.ts +3 -0
  232. package/dist/testing.js +2 -0
  233. package/package.json +26 -3
  234. package/dist/api/LambderApiPolicyEngine.d.ts +0 -47
  235. package/dist/api/LambderApiPolicyEngine.js +0 -85
  236. package/dist/shared/util/LambderKeyFields.d.ts +0 -32
  237. package/dist/shared/util/LambderKeyFields.js +0 -34
@@ -2,56 +2,35 @@ import { z } from "zod";
2
2
  import { toGuardEntries } from "./LambderApiGuards.js";
3
3
  import { API_SIGNATURE_HEX_LENGTH, EXTENSIBLE_ENUM_META_KEY } from "../shared/wire/LambderApiSignature.js";
4
4
  import { sha256HexOf } from "../shared/util/LambderTextDigest.js";
5
+ import { canonicalJson } from "../shared/util/canonicalJson.js";
5
6
  /*
6
7
  * The digest of an endpoint's client-facing shape, computed once, by the
7
8
  * generator, through Lambder.apiSignatures(). Nothing digests at request
8
- * time: the server and the client both carry the generated map and the
9
- * pipeline compares entries, so the one computation has nothing to agree
10
- * with but itself. See LambderApiSignatureMap.
9
+ * time: server and client both carry the generated map and the pipeline
10
+ * compares entries, so there is no second computation to disagree with.
11
+ * See LambderApiSignatureMap.
11
12
  */
12
- /**
13
- * JSON with object keys sorted at every level, so two descriptions of the
14
- * same shape hash the same whatever order they were built in. Arrays keep
15
- * their order: a tuple's positions and an enum's values are part of the
16
- * shape. Undefined entries are dropped, as JSON.stringify would drop them.
17
- */
18
- const canonicalJson = (value) => JSON.stringify(sortKeys(value));
19
- const sortKeys = (value) => {
20
- if (Array.isArray(value))
21
- return value.map(sortKeys);
22
- if (value === null || typeof value !== "object")
23
- return value;
24
- const source = value;
25
- const sorted = {};
26
- for (const key of Object.keys(source).sort()) {
27
- if (source[key] !== undefined)
28
- sorted[key] = sortKeys(source[key]);
29
- }
30
- return sorted;
31
- };
32
13
  /**
33
14
  * Three edits to every node zod emits, before it is hashed.
34
15
  *
35
16
  * The `default` keyword goes. Its value is server behaviour, not shape: a
36
- * client never sends it, and its compiled types do not carry it. And for a
37
- * function default (`.default(() => new Date())`, `.prefault`, `.catch`)
38
- * zod writes whatever the function returned at conversion time, a clock
39
- * reading or a random value, which would give the endpoint a different
40
- * digest on every computation and a generated map that never matches the
41
- * server. Nothing distinguishes such a default from a constant one once zod
42
- * has evaluated it, so every default goes, and the one thing about a default
43
- * a client can see, that the field may be omitted, stays through `required`.
17
+ * client never sends it. For a function default (`.default(() => new
18
+ * Date())`, `.prefault`, `.catch`) zod writes whatever the function returned
19
+ * at conversion time, a clock reading or a random value, so the digest would
20
+ * differ on every computation and the generated map would never match the
21
+ * server. Once evaluated, such a default looks like a constant one, so every
22
+ * default goes; what a client can see of it, that the field may be omitted,
23
+ * stays through `required`.
44
24
  *
45
- * `required` is sorted. It is a set, and the order fields are declared in is
46
- * not shape either; left as emitted, reordering two fields forced a reload.
25
+ * `required` is sorted: it is a set, and declaration order is not shape.
26
+ * Left as emitted, reordering two fields would force a reload.
47
27
  *
48
- * An enum marked with extensibleEnum() loses its values in an output. Its
49
- * clients tolerate a value they do not know, so a response carrying one they
50
- * were not built with, or no longer carrying one they were, changes nothing
51
- * they can see; the node still says it holds a string. In an input the values
52
- * stay, since a value dropped from the list is a request an older client may
53
- * still send and the server now refuses. The mark itself goes in both, so
54
- * marking an enum changes no input's digest.
28
+ * An enum marked with extensibleEnum() loses its values in an output: its
29
+ * clients tolerate unknown values, so adding or removing one changes nothing
30
+ * they can see, and the node still says it holds a string. In an input the
31
+ * values stay, since a value dropped from the list is one an older client
32
+ * may still send and the server would refuse. The mark itself goes in both,
33
+ * so marking an enum changes no input's digest.
55
34
  */
56
35
  const keepShapeOnly = (node, io) => {
57
36
  delete node.default;
@@ -76,18 +55,16 @@ const ownGuard = (guards, name) => guards !== undefined && Object.prototype.hasO
76
55
  * input and output schemas as JSON Schema, every guard it declares with the
77
56
  * schema that guard validates (the guardInput the client sends separately,
78
57
  * or the apiInput slice of the payload), and whether it demands an
79
- * idempotency key. Anything else about the endpoint (its rate limits, a
80
- * guard's parameter, the handler) changes nothing for a client and is left
81
- * out, so changing it never forces a reload.
58
+ * idempotency key. Anything else (rate limits, a guard's parameter, the
59
+ * handler) changes nothing for a client and is left out, so changing it never
60
+ * forces a reload.
82
61
  *
83
- * The description is hashed as built, descriptions and titles included: a
84
- * schema is what the server says it is, and a client built against a
85
- * different one reloads once, with one exception the schema declares itself:
86
- * the values of an extensibleEnum() in an output (see keepShapeOnly). What
87
- * must hold for the digest to mean anything is that a schema is built from
88
- * static values: one that reads the clock, a random source or the environment
89
- * at construction digests differently in the generator's process and on the
90
- * server.
62
+ * Schemas are hashed as built, descriptions and titles included, so a client
63
+ * built against a different one reloads once. The exception is an output
64
+ * extensibleEnum()'s values (see keepShapeOnly). Schemas must be built from
65
+ * static values: one that reads the clock, a random source or the
66
+ * environment at construction digests differently in the generator's process
67
+ * and on the server.
91
68
  */
92
69
  export const apiSignatureOf = async (definition, guards) => {
93
70
  const guardShapes = toGuardEntries(definition.guards).map(({ name }) => {
@@ -5,13 +5,12 @@ import { LambderApiRefusal } from "../shared/wire/LambderApiRefusal.js";
5
5
  * response. The API's own schema and every preflight slice (a guard's input,
6
6
  * a rate-limit key's fields) throw this when a value fails to parse, and the
7
7
  * pipeline renders it in one place: through the app's input validation
8
- * handler when it set one, otherwise as the standard 422 body. The engines
9
- * therefore never build a response and never see a resolver, which is what
10
- * lets them run outside a Lambda.
8
+ * handler when set, otherwise as the standard 422 body. The engines never
9
+ * build a response or see a resolver, which lets them run outside a Lambda.
11
10
  *
12
- * A LambderApiRefusal, so every catch that maps refusals already handles it;
13
- * the brand tells the pipeline to route it through the validation handler
14
- * instead of the refusal envelope.
11
+ * It is a LambderApiRefusal, so every catch that maps refusals handles it;
12
+ * the brand routes it through the validation handler instead of the refusal
13
+ * envelope.
15
14
  */
16
15
  export declare class LambderApiValidationRefusal extends LambderApiRefusal {
17
16
  /** Brand for detection across duplicate lambder installs, like LambderApiRefusal's. */
@@ -26,7 +25,8 @@ export declare const isLambderApiValidationRefusal: (err: unknown) => err is Lam
26
25
  * a guardInput value from the raw guardInputs map). Runs before the API's
27
26
  * own validation; a failure throws the same LambderApiValidationRefusal the
28
27
  * API's schema throws, so the pipeline answers every rejected input alike.
29
- * Shared by the guards engine and the rate-limit engine, and living here
30
- * beside the error it throws rather than in one of the two.
28
+ * Shared by the guards and rate-limit engines, so it lives beside the error
29
+ * it throws. Parsed asynchronously, so a slice with an async refinement (a
30
+ * lookup, say) validates instead of making zod throw on every call.
31
31
  */
32
- export declare const parsePreflightSlice: (input: z.ZodType, value: unknown) => unknown;
32
+ export declare const parsePreflightSlice: (input: z.ZodType, value: unknown) => Promise<unknown>;
@@ -4,13 +4,12 @@ import { LambderApiRefusal, isLambderApiRefusal } from "../shared/wire/LambderAp
4
4
  * response. The API's own schema and every preflight slice (a guard's input,
5
5
  * a rate-limit key's fields) throw this when a value fails to parse, and the
6
6
  * pipeline renders it in one place: through the app's input validation
7
- * handler when it set one, otherwise as the standard 422 body. The engines
8
- * therefore never build a response and never see a resolver, which is what
9
- * lets them run outside a Lambda.
7
+ * handler when set, otherwise as the standard 422 body. The engines never
8
+ * build a response or see a resolver, which lets them run outside a Lambda.
10
9
  *
11
- * A LambderApiRefusal, so every catch that maps refusals already handles it;
12
- * the brand tells the pipeline to route it through the validation handler
13
- * instead of the refusal envelope.
10
+ * It is a LambderApiRefusal, so every catch that maps refusals handles it;
11
+ * the brand routes it through the validation handler instead of the refusal
12
+ * envelope.
14
13
  */
15
14
  export class LambderApiValidationRefusal extends LambderApiRefusal {
16
15
  /** Brand for detection across duplicate lambder installs, like LambderApiRefusal's. */
@@ -29,11 +28,12 @@ export const isLambderApiValidationRefusal = (err) => isLambderApiRefusal(err) &
29
28
  * a guardInput value from the raw guardInputs map). Runs before the API's
30
29
  * own validation; a failure throws the same LambderApiValidationRefusal the
31
30
  * API's schema throws, so the pipeline answers every rejected input alike.
32
- * Shared by the guards engine and the rate-limit engine, and living here
33
- * beside the error it throws rather than in one of the two.
31
+ * Shared by the guards and rate-limit engines, so it lives beside the error
32
+ * it throws. Parsed asynchronously, so a slice with an async refinement (a
33
+ * lookup, say) validates instead of making zod throw on every call.
34
34
  */
35
- export const parsePreflightSlice = (input, value) => {
36
- const parsed = input.safeParse(value);
35
+ export const parsePreflightSlice = async (input, value) => {
36
+ const parsed = await input.safeParseAsync(value);
37
37
  if (!parsed.success)
38
38
  throw new LambderApiValidationRefusal(parsed.error);
39
39
  return parsed.data;
@@ -0,0 +1,85 @@
1
+ import type ts from "typescript";
2
+ /** How the printed module is punctuated. */
3
+ export type ContractPrintStyle = {
4
+ quote: "'" | "\"";
5
+ semicolon: "" | ";";
6
+ };
7
+ /** The contract as text: each entry by name, and the named types the entries refer to. */
8
+ export type PrintedContract = {
9
+ entries: {
10
+ name: string;
11
+ text: string;
12
+ }[];
13
+ declarations: {
14
+ name: string;
15
+ text: string;
16
+ }[];
17
+ /** Where the contract holds something with no plain form, and what it is. */
18
+ failures: string[];
19
+ };
20
+ export declare class ContractTypePrinter {
21
+ private readonly ts;
22
+ private readonly program;
23
+ private readonly checker;
24
+ private readonly style;
25
+ private readonly failures;
26
+ /** Every named declaration by the type it stands for; its text is null while it is being printed. */
27
+ private readonly declarations;
28
+ /** Names a declaration may not take: the default library's, and the contract's own. */
29
+ private readonly takenNames;
30
+ /** The anonymous types being printed: meeting one again inside itself is recursion, and it needs a name. */
31
+ private readonly inProgress;
32
+ /** Under exactOptionalPropertyTypes an optional member's type carries the compiler's own "missing" undefined, which its source never wrote. */
33
+ private readonly exactOptionalProperties;
34
+ constructor(ts: typeof import("typescript"), program: ts.Program, checker: ts.TypeChecker, style: ContractPrintStyle, contractName: string);
35
+ /** Prints each member of the contract type, sorted by name, and every declaration they refer to. */
36
+ printContract(contract: ts.Type): PrintedContract;
37
+ /**
38
+ * `label value`, with a union too long for one line starting on the next
39
+ * line, one member per line: what a property, an index signature and a
40
+ * declaration all print through.
41
+ */
42
+ labeledValue(label: string, value: string): string;
43
+ private print;
44
+ /** A union, an intersection or an object: printed in place, or as a reference to a declaration of its own. */
45
+ private printComposite;
46
+ /** The name a type is declared under, when it is one to print as a declaration: non-generic, and not the default library's. */
47
+ private declaredNameOf;
48
+ /** The name a symbol is declared under, read off its declaration, so `export default interface Customer` is Customer; undefined when it has none to print. */
49
+ private nameOf;
50
+ /**
51
+ * A name for a type that refers to itself and has none of its own: what it
52
+ * instantiates followed by its arguments (a JSON mapping of a Tree is
53
+ * `JsonOfTree`, a `Tree<string>` is `TreeString`), or `RecursiveType`.
54
+ */
55
+ private recursiveNameOf;
56
+ private printStructure;
57
+ private printUnion;
58
+ private printUnionOf;
59
+ private printIntersection;
60
+ private printObject;
61
+ private printMembers;
62
+ /**
63
+ * An optional member's type as its source wrote it. Under
64
+ * exactOptionalPropertyTypes the compiler adds its own "missing"
65
+ * undefined, a different type from the `undefined` a source writes;
66
+ * printed as `| undefined` it would let the member be undefined, which
67
+ * the source does not.
68
+ */
69
+ private printOptionalMember;
70
+ private printTuple;
71
+ private printTemplateLiteral;
72
+ /** Why a property cannot be printed as a plain member, or undefined when it can. */
73
+ private unprintableProperty;
74
+ /** An object type printed member by member: not an array, a tuple, a function or a default library interface. */
75
+ private isPlainObject;
76
+ private isCallable;
77
+ private isDefaultLibraryInterface;
78
+ /** Declared in the default library, even where a package augments it (as @types/node does some globals). */
79
+ private isDefaultLibrary;
80
+ private wrapped;
81
+ keyOf(name: string): string;
82
+ private quoted;
83
+ private takeName;
84
+ private fail;
85
+ }