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.
- package/CHANGELOG.md +1047 -3
- package/README.md +46 -21
- package/dist/api/LambderApiAnswer.d.ts +18 -22
- package/dist/api/LambderApiAnswer.js +6 -7
- package/dist/api/LambderApiCallContext.d.ts +21 -8
- package/dist/api/LambderApiCallContext.js +22 -4
- package/dist/api/LambderApiDefinition.d.ts +4 -3
- package/dist/api/LambderApiEnvelope.d.ts +14 -9
- package/dist/api/LambderApiEnvelope.js +33 -34
- package/dist/api/LambderApiGuards.d.ts +78 -51
- package/dist/api/LambderApiGuards.js +34 -36
- package/dist/api/LambderApiIdempotency.d.ts +68 -62
- package/dist/api/LambderApiIdempotency.js +214 -151
- package/dist/api/LambderApiOutputValidationError.d.ts +32 -0
- package/dist/api/LambderApiOutputValidationError.js +50 -0
- package/dist/api/LambderApiPipeline.d.ts +47 -38
- package/dist/api/LambderApiPipeline.js +122 -63
- package/dist/api/LambderApiRateLimits.d.ts +201 -54
- package/dist/api/LambderApiRateLimits.js +185 -108
- package/dist/api/LambderApiRequest.d.ts +27 -21
- package/dist/api/LambderApiRequest.js +26 -19
- package/dist/api/LambderApiSignature.d.ts +12 -15
- package/dist/api/LambderApiSignature.js +28 -51
- package/dist/api/LambderApiValidationRefusal.d.ts +9 -9
- package/dist/api/LambderApiValidationRefusal.js +10 -10
- package/dist/build/ContractTypePrinter.d.ts +85 -0
- package/dist/build/ContractTypePrinter.js +402 -0
- package/dist/build/freshProcessVerifier.d.ts +13 -0
- package/dist/build/freshProcessVerifier.js +19 -0
- package/dist/build/moduleLocation.d.ts +11 -0
- package/dist/build/moduleLocation.js +6 -0
- package/dist/build/writeApiContract.d.ts +78 -0
- package/dist/build/writeApiContract.js +302 -0
- package/dist/build/writeApiSignatures.d.ts +114 -0
- package/dist/build/writeApiSignatures.js +217 -0
- package/dist/build/writeFileAtomically.d.ts +8 -0
- package/dist/build/writeFileAtomically.js +22 -0
- package/dist/build.d.ts +14 -0
- package/dist/build.js +11 -0
- package/dist/client/LambderCaller.d.ts +13 -44
- package/dist/client/LambderCaller.js +77 -84
- package/dist/client/LambderReloadLoopBreaker.d.ts +56 -26
- package/dist/client/LambderReloadLoopBreaker.js +90 -46
- package/dist/client/LambderUploadRunner.d.ts +96 -0
- package/dist/client/LambderUploadRunner.js +234 -0
- package/dist/client/lambderFetchTransport.d.ts +4 -1
- package/dist/client/lambderFetchTransport.js +52 -28
- package/dist/client.d.ts +9 -3
- package/dist/client.js +6 -1
- package/dist/core/Lambder.d.ts +143 -79
- package/dist/core/Lambder.js +350 -231
- package/dist/core/LambderContext.d.ts +82 -15
- package/dist/core/LambderContext.js +107 -20
- package/dist/core/LambderCors.d.ts +21 -3
- package/dist/core/LambderCors.js +35 -16
- package/dist/core/LambderCrashHandling.d.ts +40 -0
- package/dist/core/LambderCrashHandling.js +97 -0
- package/dist/core/LambderCreateOptions.d.ts +151 -75
- package/dist/core/LambderCreateOptions.js +16 -23
- package/dist/core/LambderFiles.d.ts +21 -7
- package/dist/core/LambderFiles.js +62 -34
- package/dist/core/LambderIndexHtml.js +12 -11
- package/dist/core/LambderPolicyBuilders.d.ts +17 -5
- package/dist/core/LambderPolicyBuilders.js +17 -5
- package/dist/core/LambderPublicFiles.d.ts +11 -5
- package/dist/core/LambderPublicFiles.js +32 -4
- package/dist/core/LambderRequestPath.d.ts +43 -0
- package/dist/core/LambderRequestPath.js +63 -0
- package/dist/core/LambderResponse.d.ts +26 -5
- package/dist/core/LambderResponse.js +157 -70
- package/dist/core/LambderResponseBuilder.d.ts +49 -4
- package/dist/core/LambderResponseBuilder.js +64 -3
- package/dist/core/LambderRouting.d.ts +2 -3
- package/dist/core/LambderRouting.js +22 -7
- package/dist/core/LambderTemplatingEngine.js +211 -32
- package/dist/index.d.ts +25 -8
- package/dist/index.js +13 -4
- package/dist/invoke/LambderInvokeCaller.d.ts +37 -42
- package/dist/invoke/LambderInvokeCaller.js +76 -66
- package/dist/invoke/LambderInvokeOutcome.d.ts +27 -26
- package/dist/invoke/LambderInvokeOutcome.js +9 -22
- package/dist/invoke/LambderLambdaEvent.d.ts +29 -9
- package/dist/invoke/LambderLambdaEvent.js +40 -22
- package/dist/invoke/lambderHandlerTransport.d.ts +9 -10
- package/dist/invoke/lambderHandlerTransport.js +15 -18
- package/dist/mock/LambderMockApp.d.ts +67 -83
- package/dist/mock/LambderMockApp.js +167 -153
- package/dist/mock/LambderMockBrowserCookies.d.ts +24 -28
- package/dist/mock/LambderMockBrowserCookies.js +24 -28
- package/dist/mock/LambderMockCallRecorder.d.ts +15 -22
- package/dist/mock/LambderMockCallRecorder.js +19 -28
- package/dist/mock/LambderMockCreateOptions.d.ts +42 -24
- package/dist/mock/LambderMockEntryRegistry.d.ts +11 -12
- package/dist/mock/LambderMockEntryRegistry.js +24 -29
- package/dist/mock/LambderMockFailureInjector.d.ts +3 -6
- package/dist/mock/LambderMockFailureInjector.js +3 -6
- package/dist/mock/LambderMockTypes.d.ts +78 -108
- package/dist/mock/lambderMockInvokeTransport.d.ts +11 -13
- package/dist/mock/lambderMockInvokeTransport.js +11 -10
- package/dist/mock/lambderMockMswHandler.d.ts +43 -33
- package/dist/mock/lambderMockMswHandler.js +50 -39
- package/dist/mock/lambderMockUploadMswHandler.d.ts +26 -0
- package/dist/mock/lambderMockUploadMswHandler.js +28 -0
- package/dist/mock.d.ts +4 -1
- package/dist/mock.js +6 -3
- package/dist/session/LambderSessionController.d.ts +108 -89
- package/dist/session/LambderSessionController.js +187 -168
- package/dist/session/LambderSessionCrypto.d.ts +16 -7
- package/dist/session/LambderSessionCrypto.js +26 -12
- package/dist/session/LambderSessionManager.d.ts +124 -46
- package/dist/session/LambderSessionManager.js +262 -137
- package/dist/shared/LambderHtml.d.ts +42 -3
- package/dist/shared/LambderHtml.js +127 -7
- package/dist/shared/LambderHtmlPositions.d.ts +173 -0
- package/dist/shared/LambderHtmlPositions.js +652 -0
- package/dist/shared/LambderI18n.d.ts +10 -11
- package/dist/shared/LambderI18n.js +33 -21
- package/dist/shared/contracts/LambderCache.d.ts +66 -0
- package/dist/shared/contracts/LambderCache.js +11 -0
- package/dist/shared/contracts/LambderFileSource.d.ts +6 -6
- package/dist/shared/contracts/LambderFileSource.js +5 -8
- package/dist/shared/contracts/LambderIdempotencyStore.d.ts +51 -22
- package/dist/shared/contracts/LambderIdempotencyStore.js +4 -5
- package/dist/shared/contracts/LambderRateLimiter.d.ts +27 -15
- package/dist/shared/contracts/LambderRateLimiter.js +4 -5
- package/dist/shared/contracts/LambderSessionStore.d.ts +65 -26
- package/dist/shared/contracts/LambderSessionStore.js +5 -6
- package/dist/shared/contracts/LambderUploadBucket.d.ts +154 -0
- package/dist/shared/contracts/LambderUploadBucket.js +74 -0
- package/dist/shared/transport/LambderApiTransport.d.ts +27 -27
- package/dist/shared/transport/LambderApiTransport.js +7 -7
- package/dist/shared/transport/LambderCookieJar.d.ts +28 -35
- package/dist/shared/transport/LambderCookieJar.js +54 -66
- package/dist/shared/transport/lambderCookieJarTransport.d.ts +11 -13
- package/dist/shared/transport/lambderCookieJarTransport.js +24 -23
- package/dist/shared/util/LambderCallAbort.d.ts +5 -5
- package/dist/shared/util/LambderCallAbort.js +5 -5
- package/dist/shared/util/LambderClientIp.d.ts +27 -11
- package/dist/shared/util/LambderClientIp.js +96 -13
- package/dist/shared/util/LambderContentDisposition.d.ts +10 -0
- package/dist/shared/util/LambderContentDisposition.js +13 -0
- package/dist/shared/util/LambderExpiringMap.d.ts +35 -49
- package/dist/shared/util/LambderExpiringMap.js +41 -57
- package/dist/shared/util/LambderNodeModules.js +6 -7
- package/dist/shared/util/LambderOptionChecks.d.ts +4 -4
- package/dist/shared/util/LambderOptionChecks.js +4 -4
- package/dist/shared/util/LambderResponseBrand.d.ts +5 -5
- package/dist/shared/util/LambderResponseBrand.js +5 -5
- package/dist/shared/util/LambderTextDigest.d.ts +7 -5
- package/dist/shared/util/LambderTextDigest.js +11 -5
- package/dist/shared/util/LambderTypeUtilities.d.ts +7 -8
- package/dist/shared/util/LambderTypeUtilities.js +3 -3
- package/dist/shared/util/boundKeyField.d.ts +20 -0
- package/dist/shared/util/boundKeyField.js +34 -0
- package/dist/shared/util/canonicalJson.d.ts +11 -0
- package/dist/shared/util/canonicalJson.js +28 -0
- package/dist/shared/util/joinKeyFields.d.ts +20 -0
- package/dist/shared/util/joinKeyFields.js +22 -0
- package/dist/shared/wire/LambderAnswerHeaders.d.ts +12 -16
- package/dist/shared/wire/LambderAnswerHeaders.js +12 -16
- package/dist/shared/wire/LambderApiContract.d.ts +98 -53
- package/dist/shared/wire/LambderApiOutcome.d.ts +43 -31
- package/dist/shared/wire/LambderApiOutcome.js +48 -23
- package/dist/shared/wire/LambderApiRefusal.d.ts +45 -27
- package/dist/shared/wire/LambderApiRefusal.js +42 -7
- package/dist/shared/wire/LambderApiSignature.d.ts +18 -22
- package/dist/shared/wire/LambderApiSignature.js +16 -19
- package/dist/shared/wire/LambderCallOptions.d.ts +38 -47
- package/dist/shared/wire/LambderCallOptions.js +9 -11
- package/dist/shared/wire/LambderCompressionCodec.d.ts +29 -34
- package/dist/shared/wire/LambderCompressionCodec.js +31 -36
- package/dist/shared/wire/LambderCompressionOption.d.ts +9 -9
- package/dist/shared/wire/LambderCompressionOption.js +9 -9
- package/dist/shared/wire/LambderCrashDetail.d.ts +12 -15
- package/dist/shared/wire/LambderCrashDetail.js +12 -15
- package/dist/shared/wire/LambderDefaultApiPath.d.ts +6 -0
- package/dist/shared/wire/LambderDefaultApiPath.js +6 -0
- package/dist/shared/wire/LambderHttpStatus.d.ts +6 -7
- package/dist/shared/wire/LambderIdempotencyKeyScope.d.ts +89 -0
- package/dist/shared/wire/LambderIdempotencyKeyScope.js +146 -0
- package/dist/shared/wire/LambderInvokeApiId.d.ts +27 -0
- package/dist/shared/wire/LambderInvokeApiId.js +27 -0
- package/dist/shared/wire/LambderOutcomeAssertions.d.ts +6 -7
- package/dist/shared/wire/LambderOutcomeAssertions.js +6 -7
- package/dist/shared/wire/LambderRequestPayload.d.ts +18 -20
- package/dist/shared/wire/LambderRequestPayload.js +4 -6
- package/dist/shared/wire/LambderUploadObjectFields.d.ts +10 -0
- package/dist/shared/wire/LambderUploadObjectFields.js +24 -0
- package/dist/shared/wire/LambderUploadRefusal.d.ts +9 -0
- package/dist/shared/wire/LambderUploadRefusal.js +18 -0
- package/dist/shared/wire/LambderUploadSchemas.d.ts +12 -0
- package/dist/shared/wire/LambderUploadSchemas.js +30 -0
- package/dist/stores/LambderCacheFiller.d.ts +48 -0
- package/dist/stores/LambderCacheFiller.js +119 -0
- package/dist/stores/LambderCacheKeys.d.ts +26 -0
- package/dist/stores/LambderCacheKeys.js +54 -0
- package/dist/stores/LambderCacheValues.d.ts +45 -0
- package/dist/stores/LambderCacheValues.js +74 -0
- package/dist/stores/LambderDdbCache.d.ts +121 -56
- package/dist/stores/LambderDdbCache.js +528 -225
- package/dist/stores/LambderDdbIdempotencyStore.d.ts +33 -22
- package/dist/stores/LambderDdbIdempotencyStore.js +75 -50
- package/dist/stores/LambderDdbRateLimiter.d.ts +76 -20
- package/dist/stores/LambderDdbRateLimiter.js +151 -39
- package/dist/stores/LambderDdbSdk.d.ts +43 -31
- package/dist/stores/LambderDdbSdk.js +80 -38
- package/dist/stores/LambderDdbSessionStore.d.ts +27 -14
- package/dist/stores/LambderDdbSessionStore.js +119 -47
- package/dist/stores/LambderHttpFileSource.d.ts +15 -6
- package/dist/stores/LambderHttpFileSource.js +15 -13
- package/dist/stores/LambderMemoryCache.d.ts +49 -0
- package/dist/stores/LambderMemoryCache.js +113 -0
- package/dist/stores/LambderMemoryIdempotencyStore.d.ts +13 -12
- package/dist/stores/LambderMemoryIdempotencyStore.js +31 -30
- package/dist/stores/LambderMemoryRateLimiter.d.ts +8 -9
- package/dist/stores/LambderMemoryRateLimiter.js +14 -13
- package/dist/stores/LambderMemorySessionStore.d.ts +14 -11
- package/dist/stores/LambderMemorySessionStore.js +38 -19
- package/dist/stores/LambderMemoryUploadBucket.d.ts +99 -0
- package/dist/stores/LambderMemoryUploadBucket.js +219 -0
- package/dist/stores/LambderS3FileSource.d.ts +21 -6
- package/dist/stores/LambderS3FileSource.js +12 -7
- package/dist/stores/LambderS3UploadBucket.d.ts +73 -0
- package/dist/stores/LambderS3UploadBucket.js +144 -0
- package/dist/stores/LambderSdkInstallHint.d.ts +11 -0
- package/dist/stores/LambderSdkInstallHint.js +14 -0
- package/dist/testing/LambderTestApp.d.ts +23 -25
- package/dist/testing/LambderTestApp.js +22 -24
- package/dist/testing/LambderTestVisitor.d.ts +10 -12
- package/dist/testing/LambderTestVisitor.js +15 -15
- package/dist/testing.d.ts +3 -0
- package/dist/testing.js +2 -0
- package/package.json +26 -3
- package/dist/api/LambderApiPolicyEngine.d.ts +0 -47
- package/dist/api/LambderApiPolicyEngine.js +0 -85
- package/dist/shared/util/LambderKeyFields.d.ts +0 -32
- 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:
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
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
|
|
46
|
-
*
|
|
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
|
|
49
|
-
* clients tolerate
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
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
|
|
80
|
-
*
|
|
81
|
-
*
|
|
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
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
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
|
|
9
|
-
*
|
|
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
|
-
*
|
|
13
|
-
* the brand
|
|
14
|
-
*
|
|
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
|
|
30
|
-
*
|
|
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
|
|
8
|
-
*
|
|
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
|
-
*
|
|
12
|
-
* the brand
|
|
13
|
-
*
|
|
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
|
|
33
|
-
*
|
|
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.
|
|
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
|
+
}
|