@distilled.cloud/core 1.0.0-rc.16 → 1.0.0-rc.18
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/lib/_bundle/aws.js +2 -0
- package/lib/_bundle/aws.js.map +1 -0
- package/lib/_bundle/base.js +5 -0
- package/lib/_bundle/base.js.map +1 -0
- package/lib/_bundle/graphql.js +3 -0
- package/lib/_bundle/graphql.js.map +1 -0
- package/lib/_bundle/rest.js +2 -0
- package/lib/_bundle/rest.js.map +1 -0
- package/lib/_bundle/xml.js +4 -0
- package/lib/_bundle/xml.js.map +1 -0
- package/lib/annotations.d.ts +15 -0
- package/lib/annotations.d.ts.map +1 -0
- package/lib/annotations.js +2 -0
- package/lib/annotations.js.map +1 -0
- package/lib/api.d.ts +15 -0
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +1 -796
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +1 -278
- package/lib/chunks.js +1 -11
- package/lib/config.d.ts +54 -13
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +1 -161
- package/lib/crypto.js +1 -130
- package/lib/debug.d.ts.map +1 -1
- package/lib/debug.js +1 -8
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js +1 -47
- package/lib/errors.d.ts +2 -13
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -198
- package/lib/graphql.d.ts +14 -0
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +1 -1058
- package/lib/graphql.types.js +1 -6
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -15
- package/lib/pagination.d.ts +34 -2
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +1 -271
- package/lib/plain-values.js +1 -39
- package/lib/plain-values.js.map +1 -1
- package/lib/protocol-http.d.ts +30 -6
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +1 -812
- package/lib/protocol-rest.d.ts +53 -39
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +1 -375
- package/lib/query.js +1 -27
- package/lib/response-validation-strict.js +1 -284
- package/lib/response-validation.d.ts +4 -3
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js +1 -118
- package/lib/retry-after.js +1 -112
- package/lib/retry.js +1 -197
- package/lib/schema-lite-impl.js +1 -341
- package/lib/schema-lite-typed.js +1 -27
- package/lib/schema-lite.js +1 -31
- package/lib/schema.js +1 -220
- package/lib/telemetry-debug.d.ts +14 -0
- package/lib/telemetry-debug.d.ts.map +1 -0
- package/lib/telemetry-debug.js +2 -0
- package/lib/telemetry-debug.js.map +1 -0
- package/lib/telemetry-hooks.d.ts +32 -0
- package/lib/telemetry-hooks.d.ts.map +1 -0
- package/lib/telemetry-hooks.js +2 -0
- package/lib/telemetry-hooks.js.map +1 -0
- package/lib/telemetry-host-rules.d.ts +23 -0
- package/lib/telemetry-host-rules.d.ts.map +1 -0
- package/lib/telemetry-host-rules.js +2 -0
- package/lib/telemetry-host-rules.js.map +1 -0
- package/lib/telemetry-lambda-context.d.ts +17 -0
- package/lib/telemetry-lambda-context.d.ts.map +1 -0
- package/lib/telemetry-lambda-context.js +2 -0
- package/lib/telemetry-lambda-context.js.map +1 -0
- package/lib/telemetry-message-context.d.ts +52 -0
- package/lib/telemetry-message-context.d.ts.map +1 -0
- package/lib/telemetry-message-context.js +2 -0
- package/lib/telemetry-message-context.js.map +1 -0
- package/lib/telemetry-metrics.d.ts +6 -0
- package/lib/telemetry-metrics.d.ts.map +1 -0
- package/lib/telemetry-metrics.js +2 -0
- package/lib/telemetry-metrics.js.map +1 -0
- package/lib/telemetry-name-template.d.ts +13 -0
- package/lib/telemetry-name-template.d.ts.map +1 -0
- package/lib/telemetry-name-template.js +2 -0
- package/lib/telemetry-name-template.js.map +1 -0
- package/lib/telemetry-stream.d.ts +9 -0
- package/lib/telemetry-stream.d.ts.map +1 -0
- package/lib/telemetry-stream.js +2 -0
- package/lib/telemetry-stream.js.map +1 -0
- package/lib/telemetry-xray.d.ts +28 -0
- package/lib/telemetry-xray.d.ts.map +1 -0
- package/lib/telemetry-xray.js +2 -0
- package/lib/telemetry-xray.js.map +1 -0
- package/lib/telemetry.d.ts +269 -0
- package/lib/telemetry.d.ts.map +1 -0
- package/lib/telemetry.js +3 -0
- package/lib/telemetry.js.map +1 -0
- package/lib/trait.js +1 -131
- package/lib/xml.js +1 -323
- package/package.json +1 -3
- package/src/annotations.ts +37 -0
- package/src/api.ts +130 -30
- package/src/category.ts +21 -22
- package/src/config.ts +58 -29
- package/src/debug.ts +9 -6
- package/src/error-category.ts +12 -14
- package/src/errors.ts +7 -7
- package/src/graphql.ts +123 -18
- package/src/index.ts +3 -2
- package/src/pagination.ts +119 -6
- package/src/protocol-http.ts +63 -43
- package/src/protocol-rest.ts +201 -140
- package/src/response-validation.ts +4 -3
- package/src/telemetry-debug.ts +135 -0
- package/src/telemetry-hooks.ts +33 -0
- package/src/telemetry-host-rules.ts +39 -0
- package/src/telemetry-lambda-context.ts +46 -0
- package/src/telemetry-message-context.ts +170 -0
- package/src/telemetry-metrics.ts +69 -0
- package/src/telemetry-name-template.ts +26 -0
- package/src/telemetry-stream.ts +91 -0
- package/src/telemetry-xray.ts +66 -0
- package/src/telemetry.ts +768 -0
- package/lib/api.js.map +0 -1
- package/lib/category.js.map +0 -1
- package/lib/chunks.js.map +0 -1
- package/lib/codegen/boolean-string-enums.d.ts +0 -36
- package/lib/codegen/boolean-string-enums.d.ts.map +0 -1
- package/lib/codegen/boolean-string-enums.js +0 -147
- package/lib/codegen/boolean-string-enums.js.map +0 -1
- package/lib/codegen/chunk.d.ts +0 -7
- package/lib/codegen/chunk.d.ts.map +0 -1
- package/lib/codegen/chunk.js +0 -139
- package/lib/codegen/chunk.js.map +0 -1
- package/lib/codegen/cli.d.ts +0 -80
- package/lib/codegen/cli.d.ts.map +0 -1
- package/lib/codegen/cli.js +0 -166
- package/lib/codegen/cli.js.map +0 -1
- package/lib/codegen/datafy.d.ts +0 -14
- package/lib/codegen/datafy.d.ts.map +0 -1
- package/lib/codegen/datafy.js +0 -853
- package/lib/codegen/datafy.js.map +0 -1
- package/lib/codegen/dedupe.d.ts +0 -5
- package/lib/codegen/dedupe.d.ts.map +0 -1
- package/lib/codegen/dedupe.js +0 -153
- package/lib/codegen/dedupe.js.map +0 -1
- package/lib/codegen/emit.d.ts +0 -125
- package/lib/codegen/emit.d.ts.map +0 -1
- package/lib/codegen/emit.js +0 -99
- package/lib/codegen/emit.js.map +0 -1
- package/lib/codegen/format.d.ts +0 -11
- package/lib/codegen/format.d.ts.map +0 -1
- package/lib/codegen/format.js +0 -32
- package/lib/codegen/format.js.map +0 -1
- package/lib/codegen/generated-at.d.ts +0 -29
- package/lib/codegen/generated-at.d.ts.map +0 -1
- package/lib/codegen/generated-at.js +0 -78
- package/lib/codegen/generated-at.js.map +0 -1
- package/lib/codegen/generator.d.ts +0 -353
- package/lib/codegen/generator.d.ts.map +0 -1
- package/lib/codegen/generator.js +0 -810
- package/lib/codegen/generator.js.map +0 -1
- package/lib/codegen/graph.d.ts +0 -36
- package/lib/codegen/graph.d.ts.map +0 -1
- package/lib/codegen/graph.js +0 -136
- package/lib/codegen/graph.js.map +0 -1
- package/lib/codegen/graphql-client.d.ts +0 -70
- package/lib/codegen/graphql-client.d.ts.map +0 -1
- package/lib/codegen/graphql-client.js +0 -439
- package/lib/codegen/graphql-client.js.map +0 -1
- package/lib/codegen/graphql.d.ts +0 -207
- package/lib/codegen/graphql.d.ts.map +0 -1
- package/lib/codegen/graphql.js +0 -786
- package/lib/codegen/graphql.js.map +0 -1
- package/lib/codegen/latin1.d.ts +0 -3
- package/lib/codegen/latin1.d.ts.map +0 -1
- package/lib/codegen/latin1.js +0 -126
- package/lib/codegen/latin1.js.map +0 -1
- package/lib/codegen/members.d.ts +0 -32
- package/lib/codegen/members.d.ts.map +0 -1
- package/lib/codegen/members.js +0 -62
- package/lib/codegen/members.js.map +0 -1
- package/lib/codegen/model-diff.d.ts +0 -10
- package/lib/codegen/model-diff.d.ts.map +0 -1
- package/lib/codegen/model-diff.js +0 -67
- package/lib/codegen/model-diff.js.map +0 -1
- package/lib/codegen/naming.d.ts +0 -29
- package/lib/codegen/naming.d.ts.map +0 -1
- package/lib/codegen/naming.js +0 -74
- package/lib/codegen/naming.js.map +0 -1
- package/lib/codegen/openapi-cli.d.ts +0 -52
- package/lib/codegen/openapi-cli.d.ts.map +0 -1
- package/lib/codegen/openapi-cli.js +0 -84
- package/lib/codegen/openapi-cli.js.map +0 -1
- package/lib/codegen/openapi.d.ts +0 -209
- package/lib/codegen/openapi.d.ts.map +0 -1
- package/lib/codegen/openapi.js +0 -1548
- package/lib/codegen/openapi.js.map +0 -1
- package/lib/codegen/operations.d.ts +0 -24
- package/lib/codegen/operations.d.ts.map +0 -1
- package/lib/codegen/operations.js +0 -56
- package/lib/codegen/operations.js.map +0 -1
- package/lib/codegen/pagination.d.ts +0 -39
- package/lib/codegen/pagination.d.ts.map +0 -1
- package/lib/codegen/pagination.js +0 -31
- package/lib/codegen/pagination.js.map +0 -1
- package/lib/codegen/patch-audit.d.ts +0 -84
- package/lib/codegen/patch-audit.d.ts.map +0 -1
- package/lib/codegen/patch-audit.js +0 -366
- package/lib/codegen/patch-audit.js.map +0 -1
- package/lib/codegen/patches.d.ts +0 -129
- package/lib/codegen/patches.d.ts.map +0 -1
- package/lib/codegen/patches.js +0 -472
- package/lib/codegen/patches.js.map +0 -1
- package/lib/codegen/prelude.d.ts +0 -15
- package/lib/codegen/prelude.d.ts.map +0 -1
- package/lib/codegen/prelude.js +0 -60
- package/lib/codegen/prelude.js.map +0 -1
- package/lib/codegen/privatize.d.ts +0 -21
- package/lib/codegen/privatize.d.ts.map +0 -1
- package/lib/codegen/privatize.js +0 -176
- package/lib/codegen/privatize.js.map +0 -1
- package/lib/codegen/proto.d.ts +0 -121
- package/lib/codegen/proto.d.ts.map +0 -1
- package/lib/codegen/proto.js +0 -960
- package/lib/codegen/proto.js.map +0 -1
- package/lib/codegen/pure.d.ts +0 -6
- package/lib/codegen/pure.d.ts.map +0 -1
- package/lib/codegen/pure.js +0 -91
- package/lib/codegen/pure.js.map +0 -1
- package/lib/codegen/rewrite-operation-ids.d.ts +0 -154
- package/lib/codegen/rewrite-operation-ids.d.ts.map +0 -1
- package/lib/codegen/rewrite-operation-ids.js +0 -1117
- package/lib/codegen/rewrite-operation-ids.js.map +0 -1
- package/lib/codegen/spec-path.d.ts +0 -16
- package/lib/codegen/spec-path.d.ts.map +0 -1
- package/lib/codegen/spec-path.js +0 -101
- package/lib/codegen/spec-path.js.map +0 -1
- package/lib/codegen/table.d.ts +0 -5
- package/lib/codegen/table.d.ts.map +0 -1
- package/lib/codegen/table.js +0 -249
- package/lib/codegen/table.js.map +0 -1
- package/lib/config.js.map +0 -1
- package/lib/crypto.js.map +0 -1
- package/lib/debug.js.map +0 -1
- package/lib/error-category.js.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/graphql.js.map +0 -1
- package/lib/graphql.types.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/json-patch.d.ts +0 -58
- package/lib/json-patch.d.ts.map +0 -1
- package/lib/json-patch.js +0 -227
- package/lib/json-patch.js.map +0 -1
- package/lib/pagination.js.map +0 -1
- package/lib/protocol-http.js.map +0 -1
- package/lib/protocol-rest.js.map +0 -1
- package/lib/query.js.map +0 -1
- package/lib/response-validation-strict.js.map +0 -1
- package/lib/response-validation.js.map +0 -1
- package/lib/retry-after.js.map +0 -1
- package/lib/retry.js.map +0 -1
- package/lib/schema-lite-impl.js.map +0 -1
- package/lib/schema-lite-typed.js.map +0 -1
- package/lib/schema-lite.js.map +0 -1
- package/lib/schema.js.map +0 -1
- package/lib/testing.d.ts +0 -40
- package/lib/testing.d.ts.map +0 -1
- package/lib/testing.js +0 -42
- package/lib/testing.js.map +0 -1
- package/lib/trait.js.map +0 -1
- package/lib/xml.js.map +0 -1
- package/src/codegen/boolean-string-enums.ts +0 -155
- package/src/codegen/chunk.ts +0 -147
- package/src/codegen/cli.ts +0 -293
- package/src/codegen/datafy.ts +0 -874
- package/src/codegen/dedupe.ts +0 -173
- package/src/codegen/emit.ts +0 -200
- package/src/codegen/format.ts +0 -49
- package/src/codegen/generated-at.ts +0 -88
- package/src/codegen/generator.ts +0 -1229
- package/src/codegen/graph.ts +0 -151
- package/src/codegen/graphql-client.ts +0 -545
- package/src/codegen/graphql.ts +0 -1145
- package/src/codegen/latin1.ts +0 -131
- package/src/codegen/members.ts +0 -79
- package/src/codegen/model-diff.ts +0 -67
- package/src/codegen/naming.ts +0 -85
- package/src/codegen/openapi-cli.ts +0 -141
- package/src/codegen/openapi.ts +0 -1845
- package/src/codegen/operations.ts +0 -73
- package/src/codegen/pagination.ts +0 -64
- package/src/codegen/patch-audit.ts +0 -480
- package/src/codegen/patches.ts +0 -581
- package/src/codegen/prelude.ts +0 -70
- package/src/codegen/privatize.ts +0 -200
- package/src/codegen/proto.ts +0 -1092
- package/src/codegen/pure.ts +0 -94
- package/src/codegen/rewrite-operation-ids.ts +0 -1219
- package/src/codegen/spec-path.ts +0 -112
- package/src/codegen/table.ts +0 -254
- package/src/json-patch.ts +0 -273
- package/src/testing.ts +0 -74
|
@@ -1,284 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export class SchemaMismatch extends Error {
|
|
3
|
-
name = "SchemaError";
|
|
4
|
-
|
|
5
|
-
path;
|
|
6
|
-
|
|
7
|
-
expected;
|
|
8
|
-
actual;
|
|
9
|
-
constructor(path, expected, actual) {
|
|
10
|
-
super(`Expected ${expected}, got ${show(actual)}${path.length ? ` at ${JSON.stringify(path.map((k) => (typeof k === "symbol" ? String(k) : k)))}` : ""}`);
|
|
11
|
-
this.path = path;
|
|
12
|
-
this.expected = expected;
|
|
13
|
-
this.actual = actual;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export const withholdActual = (mismatch) => new SchemaMismatch(mismatch.path, mismatch.expected, "[REDACTED]");
|
|
21
|
-
const show = (u) => {
|
|
22
|
-
if (u === MISSING)
|
|
23
|
-
return "nothing (missing key)";
|
|
24
|
-
if (u === undefined)
|
|
25
|
-
return "undefined";
|
|
26
|
-
if (typeof u === "string")
|
|
27
|
-
return JSON.stringify(u.length > 40 ? `${u.slice(0, 40)}...` : u);
|
|
28
|
-
if (Array.isArray(u))
|
|
29
|
-
return "an array";
|
|
30
|
-
if (u !== null && typeof u === "object")
|
|
31
|
-
return "an object";
|
|
32
|
-
return String(u);
|
|
33
|
-
};
|
|
34
|
-
const MISSING = Symbol("missing");
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const makeCompile = (exact) => {
|
|
40
|
-
const fail = (expected, actual) => ({ path: [], expected, actual });
|
|
41
|
-
const ok = () => undefined;
|
|
42
|
-
const typeOf = (t) => (u) => typeof u === t ? undefined : fail(t, u);
|
|
43
|
-
const compiled = new WeakMap();
|
|
44
|
-
const compile = (n) => {
|
|
45
|
-
let c = compiled.get(n);
|
|
46
|
-
if (c === undefined) {
|
|
47
|
-
// A node reached again while it compiles (only through Suspend) calls
|
|
48
|
-
// through this slot.
|
|
49
|
-
let self;
|
|
50
|
-
compiled.set(n, (u) => self(u));
|
|
51
|
-
self = c = withChecks(n, build(n));
|
|
52
|
-
compiled.set(n, c);
|
|
53
|
-
}
|
|
54
|
-
return c;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const withChecks = (n, base) => {
|
|
58
|
-
const checks = n.checks;
|
|
59
|
-
if (!checks?.length || isLite(n))
|
|
60
|
-
return base;
|
|
61
|
-
const flat = [];
|
|
62
|
-
const add = (c) => (c._tag === "FilterGroup" ? c.checks.forEach(add) : flat.push(c));
|
|
63
|
-
checks.forEach(add);
|
|
64
|
-
return (u) => {
|
|
65
|
-
const f = base(u);
|
|
66
|
-
if (f)
|
|
67
|
-
return f;
|
|
68
|
-
for (const c of flat) {
|
|
69
|
-
const r = c.run(u, n, {});
|
|
70
|
-
if (r !== undefined && r !== true)
|
|
71
|
-
return fail(String(c.annotations?.expected ?? "a valid value"), u);
|
|
72
|
-
}
|
|
73
|
-
return undefined;
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
const isLite = (n) => n["~lite"] === true;
|
|
77
|
-
const isOptional = (n) => n.context?.isOptional === true;
|
|
78
|
-
const build = (n) => {
|
|
79
|
-
// A real node that decodes from another form is checked in that form (the
|
|
80
|
-
// body as read); lite encodings are type-side only.
|
|
81
|
-
const encoding = n.encoding;
|
|
82
|
-
if (encoding?.length && !isLite(n))
|
|
83
|
-
return compile(encoding[encoding.length - 1].to);
|
|
84
|
-
switch (n._tag) {
|
|
85
|
-
case "String":
|
|
86
|
-
case "TemplateLiteral":
|
|
87
|
-
return typeOf("string");
|
|
88
|
-
case "Number":
|
|
89
|
-
return typeOf("number");
|
|
90
|
-
case "Boolean":
|
|
91
|
-
return typeOf("boolean");
|
|
92
|
-
case "BigInt":
|
|
93
|
-
return typeOf("bigint");
|
|
94
|
-
case "Symbol":
|
|
95
|
-
return typeOf("symbol");
|
|
96
|
-
case "Null":
|
|
97
|
-
return (u) => (u === null ? undefined : fail("null", u));
|
|
98
|
-
case "Undefined":
|
|
99
|
-
return (u) => (u === undefined ? undefined : fail("undefined", u));
|
|
100
|
-
case "Never":
|
|
101
|
-
return (u) => fail("never", u);
|
|
102
|
-
case "Literal":
|
|
103
|
-
case "UniqueSymbol": {
|
|
104
|
-
const lit = n._tag === "Literal" ? n.literal : n.symbol;
|
|
105
|
-
return (u) => (u === lit ? undefined : fail(show(lit), u));
|
|
106
|
-
}
|
|
107
|
-
case "Enum": {
|
|
108
|
-
const values = n.enums.map((e) => e[1]);
|
|
109
|
-
return (u) => (values.includes(u) ? undefined : fail("an enum value", u));
|
|
110
|
-
}
|
|
111
|
-
case "ObjectKeyword":
|
|
112
|
-
return (u) => (typeof u === "object" && u !== null) || typeof u === "function"
|
|
113
|
-
? undefined
|
|
114
|
-
: fail("object | function", u);
|
|
115
|
-
case "Union":
|
|
116
|
-
return union(n);
|
|
117
|
-
case "Arrays":
|
|
118
|
-
return arrays(n);
|
|
119
|
-
case "Objects":
|
|
120
|
-
return objects(n);
|
|
121
|
-
case "Suspend": {
|
|
122
|
-
let inner;
|
|
123
|
-
return (u) => (inner ??= compile(n.thunk()))(u);
|
|
124
|
-
}
|
|
125
|
-
case "Declaration": {
|
|
126
|
-
if (isLite(n)) {
|
|
127
|
-
const check = n.check;
|
|
128
|
-
const name = String(n.annotations?.identifier ?? "a valid value");
|
|
129
|
-
return check ? (u) => (check(u) ? undefined : fail(name, u)) : ok;
|
|
130
|
-
}
|
|
131
|
-
return declaration(n);
|
|
132
|
-
}
|
|
133
|
-
default:
|
|
134
|
-
// Unknown, Any, Void (Effect's `void` accepts any value) and anything
|
|
135
|
-
// without structure.
|
|
136
|
-
return ok;
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const declaration = (n) => {
|
|
141
|
-
const run = n.run;
|
|
142
|
-
if (!run || n.typeParameters?.length)
|
|
143
|
-
return ok;
|
|
144
|
-
let parse;
|
|
145
|
-
return (u) => {
|
|
146
|
-
const exit = (parse ??= run([]))(u, n, {});
|
|
147
|
-
return exit?._tag === "Failure"
|
|
148
|
-
? fail(String(n.annotations?.identifier ?? n.annotations?.expected ?? "a valid value"), u)
|
|
149
|
-
: undefined;
|
|
150
|
-
};
|
|
151
|
-
};
|
|
152
|
-
const union = (n) => {
|
|
153
|
-
const members = n.types.map(compile);
|
|
154
|
-
return (u) => {
|
|
155
|
-
let first;
|
|
156
|
-
for (let i = 0; i < members.length; i++) {
|
|
157
|
-
const f = members[i](u);
|
|
158
|
-
if (f === undefined)
|
|
159
|
-
return undefined;
|
|
160
|
-
first ??= f;
|
|
161
|
-
}
|
|
162
|
-
return members.length === 1 ? first : fail("a union member", u);
|
|
163
|
-
};
|
|
164
|
-
};
|
|
165
|
-
const arrays = (n) => {
|
|
166
|
-
const elements = (n.elements ?? []).map((e) => [compile(e), isOptional(e)]);
|
|
167
|
-
const rest = (n.rest ?? []).map(compile);
|
|
168
|
-
const head = rest[0];
|
|
169
|
-
const tail = rest.slice(1);
|
|
170
|
-
return (u) => {
|
|
171
|
-
if (!Array.isArray(u))
|
|
172
|
-
return fail("array", u);
|
|
173
|
-
const len = u.length;
|
|
174
|
-
for (let i = 0; i < elements.length; i++) {
|
|
175
|
-
const [check, optional] = elements[i];
|
|
176
|
-
if (i >= len) {
|
|
177
|
-
if (optional)
|
|
178
|
-
continue;
|
|
179
|
-
return at(fail("an element", MISSING), i);
|
|
180
|
-
}
|
|
181
|
-
const f = check(u[i]);
|
|
182
|
-
if (f)
|
|
183
|
-
return at(f, i);
|
|
184
|
-
}
|
|
185
|
-
if (head === undefined) {
|
|
186
|
-
return len > elements.length
|
|
187
|
-
? at(fail("never", u[elements.length]), elements.length)
|
|
188
|
-
: undefined;
|
|
189
|
-
}
|
|
190
|
-
const end = len - tail.length;
|
|
191
|
-
if (end < elements.length)
|
|
192
|
-
return at(fail("an element", MISSING), len);
|
|
193
|
-
for (let i = elements.length; i < end; i++) {
|
|
194
|
-
const f = head(u[i]);
|
|
195
|
-
if (f)
|
|
196
|
-
return at(f, i);
|
|
197
|
-
}
|
|
198
|
-
for (let j = 0; j < tail.length; j++) {
|
|
199
|
-
const f = tail[j](u[end + j]);
|
|
200
|
-
if (f)
|
|
201
|
-
return at(f, end + j);
|
|
202
|
-
}
|
|
203
|
-
return undefined;
|
|
204
|
-
};
|
|
205
|
-
};
|
|
206
|
-
const at = (f, key) => {
|
|
207
|
-
f.path.push(key);
|
|
208
|
-
return f;
|
|
209
|
-
};
|
|
210
|
-
const objects = (n) => {
|
|
211
|
-
const props = (n.propertySignatures ?? []).map((p) => [p.name, compile(p.type), isOptional(p.type)]);
|
|
212
|
-
const index = (n.indexSignatures ?? []).map((s) => [compile(s.parameter), compile(s.type)]);
|
|
213
|
-
const known = new Set(props.map((p) => p[0]));
|
|
214
|
-
// Effect's empty struct is TypeScript's `{}`: any value but null and undefined.
|
|
215
|
-
// Exact mode leaves it open too: generated code emits `{}` for outputs
|
|
216
|
-
// it does not model.
|
|
217
|
-
if (props.length === 0 && index.length === 0) {
|
|
218
|
-
return (u) => (u === null || u === undefined ? fail("{}", u) : undefined);
|
|
219
|
-
}
|
|
220
|
-
return (u) => {
|
|
221
|
-
if (typeof u !== "object" || u === null || Array.isArray(u))
|
|
222
|
-
return fail("object", u);
|
|
223
|
-
const o = u;
|
|
224
|
-
for (let i = 0; i < props.length; i++) {
|
|
225
|
-
const [name, check, optional] = props[i];
|
|
226
|
-
if (!(name === "__proto__" ? Object.hasOwn(o, name) : name in o)) {
|
|
227
|
-
if (optional)
|
|
228
|
-
continue;
|
|
229
|
-
return at(fail("a value", MISSING), name);
|
|
230
|
-
}
|
|
231
|
-
const f = check(o[name]);
|
|
232
|
-
if (f)
|
|
233
|
-
return at(f, name);
|
|
234
|
-
}
|
|
235
|
-
if (index.length || exact) {
|
|
236
|
-
for (const key of Object.keys(o)) {
|
|
237
|
-
if (known.has(key))
|
|
238
|
-
continue;
|
|
239
|
-
let covered = false;
|
|
240
|
-
for (const [param, check] of index) {
|
|
241
|
-
if (param(key) !== undefined)
|
|
242
|
-
continue;
|
|
243
|
-
covered = true;
|
|
244
|
-
const f = check(o[key]);
|
|
245
|
-
if (f)
|
|
246
|
-
return at(f, key);
|
|
247
|
-
}
|
|
248
|
-
if (exact && !covered) {
|
|
249
|
-
return at(fail("no value (the schema does not model this key)", o[key]), key);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return undefined;
|
|
254
|
-
};
|
|
255
|
-
};
|
|
256
|
-
return compile;
|
|
257
|
-
};
|
|
258
|
-
let compileNode;
|
|
259
|
-
let compileExact;
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
export const decoderFor = (ast, exact = false) => {
|
|
266
|
-
const decoders = exact ? exactDecoders : openDecoders;
|
|
267
|
-
let decode = decoders.get(ast);
|
|
268
|
-
if (decode === undefined) {
|
|
269
|
-
const check = exact
|
|
270
|
-
? (compileExact ??= makeCompile(true))(ast)
|
|
271
|
-
: (compileNode ??= makeCompile(false))(ast);
|
|
272
|
-
decode = (input) => {
|
|
273
|
-
const f = check(input);
|
|
274
|
-
return f === undefined
|
|
275
|
-
? undefined
|
|
276
|
-
: new SchemaMismatch(f.path.reverse(), f.expected, f.actual);
|
|
277
|
-
};
|
|
278
|
-
decoders.set(ast, decode);
|
|
279
|
-
}
|
|
280
|
-
return decode;
|
|
281
|
-
};
|
|
282
|
-
const openDecoders = /*@__PURE__*/ new WeakMap();
|
|
283
|
-
const exactDecoders = /*@__PURE__*/ new WeakMap();
|
|
284
|
-
//# sourceMappingURL=response-validation-strict.js.map
|
|
1
|
+
export { response_validation_strict$SchemaMismatch as SchemaMismatch, response_validation_strict$decoderFor as decoderFor, response_validation_strict$withholdActual as withholdActual } from "./_bundle/base.js";
|
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
* lenient (default): the response is returned as the protocol read it.
|
|
8
8
|
* A body that does not match the declared output type
|
|
9
9
|
* (a missing member, a wrong primitive, a non-JSON
|
|
10
|
-
* body) still succeeds, except that
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* body) still succeeds, except that a non-JSON body for
|
|
11
|
+
* an output with sensitive members fails in every mode
|
|
12
|
+
* (REST-style protocols through core's `checkSuccess`
|
|
13
|
+
* in `protocol-rest`, plus ZeroSSL and AWS).
|
|
13
14
|
* additionalProperties: the response is checked against the output
|
|
14
15
|
* schema, and a mismatch fails the call with the SDK's
|
|
15
16
|
* `<Sdk>ParseError` (AWS: `ParseError`). Keys the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-validation.d.ts","sourceRoot":"","sources":["../src/response-validation.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"response-validation.d.ts","sourceRoot":"","sources":["../src/response-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,KAAK,GAAG,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,KAAK,MAAM,EAAc,KAAK,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAE/F,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjF,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG,sBAAsB,GAAG,QAAQ,CAAC;AAEjE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,yBAG9B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,2BACjB,GAAG,CAAC,GAAG,SAAS,OAAO,KAAK,MAAM,cACmD,CAAC;AAoB/F;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAMrC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAMnD,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAEtC,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAG/C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,KAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAG7E,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,aAAa,YACf,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,aAClB,GAAG,CAAC,GAAG,SACX,OAAO,KACb,cAAc,GAAG,SAQnB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,CAAC,aACrB,GAAG,CAAC,GAAG,SACX,OAAO,WACL,CAAC,KAAK,EAAE,cAAc,KAAK,CAAC,KACpC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAIvB,CAAC"}
|
|
@@ -1,118 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
import * as Context from "effect/Context";
|
|
40
|
-
import * as Effect from "effect/Effect";
|
|
41
|
-
import * as Layer from "effect/Layer";
|
|
42
|
-
import { decoderFor } from "./response-validation-strict.js";
|
|
43
|
-
export { SchemaMismatch, withholdActual } from "./response-validation-strict.js";
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
export const ResponseValidation = /*@__PURE__*/ Context.Reference("@distilled.cloud/core/ResponseValidation", { defaultValue: () => "lenient" });
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export const StrictDecoder = /*@__PURE__*/ Context.Reference("@distilled.cloud/core/ResponseValidation/StrictDecoder", { defaultValue: () => undefined });
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const layerOfContext = (context) => {
|
|
64
|
-
const layer = Layer.succeedContext(context);
|
|
65
|
-
const both = Object.create(context);
|
|
66
|
-
const layerProto = Object.getPrototypeOf(layer);
|
|
67
|
-
for (const key of Reflect.ownKeys(layerProto)) {
|
|
68
|
-
if (key !== "pipe")
|
|
69
|
-
both[key] = layerProto[key];
|
|
70
|
-
}
|
|
71
|
-
both.build = layer.build;
|
|
72
|
-
return both;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
export const strict = /*@__PURE__*/ layerOfContext(
|
|
79
|
-
/*@__PURE__*/ Context.add(
|
|
80
|
-
/*@__PURE__*/ Context.make(ResponseValidation, "strict"), StrictDecoder, decoderFor));
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
export const additionalProperties = /*@__PURE__*/ layerOfContext(
|
|
86
|
-
/*@__PURE__*/ Context.add(
|
|
87
|
-
/*@__PURE__*/ Context.make(ResponseValidation, "additionalProperties"), StrictDecoder, decoderFor));
|
|
88
|
-
|
|
89
|
-
export const lenient = /*@__PURE__*/ layerOfContext(
|
|
90
|
-
/*@__PURE__*/ Context.make(ResponseValidation, "lenient"));
|
|
91
|
-
|
|
92
|
-
export const isValidating = /*@__PURE__*/ Effect.map(ResponseValidation, (mode) => mode !== "lenient");
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
export const failUnlessLenient = (error, asRead) => Effect.flatMap(ResponseValidation, (mode) => mode === "lenient" ? Effect.succeed(asRead) : Effect.fail(error));
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
export const checkResponse = (context, outputAst, value) => {
|
|
105
|
-
const mode = Context.get(context, ResponseValidation);
|
|
106
|
-
if (mode === "lenient")
|
|
107
|
-
return undefined;
|
|
108
|
-
const decoderOf = Context.get(context, StrictDecoder);
|
|
109
|
-
if (!decoderOf) {
|
|
110
|
-
throw new Error(`${mode} response validation needs the ResponseValidation.${mode} layer`);
|
|
111
|
-
}
|
|
112
|
-
return decoderOf(outputAst, mode === "strict")(value);
|
|
113
|
-
};
|
|
114
|
-
export const validateResponse = (outputAst, value, onError) => Effect.withFiber((fiber) => {
|
|
115
|
-
const error = checkResponse(fiber.context, outputAst, value);
|
|
116
|
-
return error === undefined ? Effect.succeed(value) : Effect.fail(onError(error));
|
|
117
|
-
});
|
|
118
|
-
//# sourceMappingURL=response-validation.js.map
|
|
1
|
+
export { response_validation$ResponseValidation as ResponseValidation, response_validation$SchemaMismatch as SchemaMismatch, response_validation$StrictDecoder as StrictDecoder, response_validation$additionalProperties as additionalProperties, response_validation$checkResponse as checkResponse, response_validation$failUnlessLenient as failUnlessLenient, response_validation$isValidating as isValidating, response_validation$lenient as lenient, response_validation$strict as strict, response_validation$validateResponse as validateResponse, response_validation$withholdActual as withholdActual } from "./_bundle/base.js";
|
package/lib/retry-after.js
CHANGED
|
@@ -1,112 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import * as Duration from "effect/Duration";
|
|
18
|
-
import { RETRYABLE_HTTP_STATUSES } from "./errors.js";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export const parseRetryAfter = (headers) => {
|
|
28
|
-
const raw = headers?.["retry-after"];
|
|
29
|
-
if (!raw)
|
|
30
|
-
return undefined;
|
|
31
|
-
const trimmed = raw.trim();
|
|
32
|
-
if (trimmed.length === 0)
|
|
33
|
-
return undefined;
|
|
34
|
-
// delay-seconds: 1*DIGIT (non-negative decimal integer per RFC).
|
|
35
|
-
if (/^\d+$/.test(trimmed)) {
|
|
36
|
-
const seconds = Number(trimmed);
|
|
37
|
-
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
38
|
-
return Duration.seconds(seconds);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
// Reject anything that *looks* numeric but isn't a valid delay-seconds.
|
|
42
|
-
// Without this, `Date.parse("-5")` happens to return 0 on some engines and
|
|
43
|
-
// would silently yield a zero-duration instead of the expected undefined.
|
|
44
|
-
if (/^[-+]?\d+(?:\.\d+)?$/.test(trimmed))
|
|
45
|
-
return undefined;
|
|
46
|
-
// HTTP-date: try Date.parse, which handles RFC 1123 / RFC 850 / asctime.
|
|
47
|
-
const ts = Date.parse(trimmed);
|
|
48
|
-
if (!Number.isNaN(ts)) {
|
|
49
|
-
const ms = Math.max(0, ts - Date.now());
|
|
50
|
-
return Duration.millis(ms);
|
|
51
|
-
}
|
|
52
|
-
return undefined;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
export const parseRatelimit = (headers) => {
|
|
67
|
-
const raw = headers?.["ratelimit"];
|
|
68
|
-
if (!raw)
|
|
69
|
-
return undefined;
|
|
70
|
-
let remaining;
|
|
71
|
-
let reset;
|
|
72
|
-
// Tokenize on commas and semicolons; tolerate `key=value` and `key =value`.
|
|
73
|
-
for (const piece of raw.split(/[,;]/)) {
|
|
74
|
-
const eq = piece.indexOf("=");
|
|
75
|
-
if (eq < 0)
|
|
76
|
-
continue;
|
|
77
|
-
const key = piece.slice(0, eq).trim().toLowerCase();
|
|
78
|
-
const value = piece.slice(eq + 1).trim();
|
|
79
|
-
const num = Number(value);
|
|
80
|
-
if (!Number.isFinite(num))
|
|
81
|
-
continue;
|
|
82
|
-
if (key === "r" || key === "remaining")
|
|
83
|
-
remaining = num;
|
|
84
|
-
else if (key === "t" || key === "reset")
|
|
85
|
-
reset = num;
|
|
86
|
-
}
|
|
87
|
-
if (remaining !== 0)
|
|
88
|
-
return undefined;
|
|
89
|
-
if (reset === undefined || reset < 0)
|
|
90
|
-
return undefined;
|
|
91
|
-
return Duration.seconds(reset);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
export const parseServerRetryHint = (headers) => parseRetryAfter(headers) ?? parseRatelimit(headers);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
export const parseRetryAfterForStatus = (status, headers) => {
|
|
108
|
-
if (!RETRYABLE_HTTP_STATUSES.has(status))
|
|
109
|
-
return undefined;
|
|
110
|
-
return parseServerRetryHint(headers);
|
|
111
|
-
};
|
|
112
|
-
//# sourceMappingURL=retry-after.js.map
|
|
1
|
+
export { retry_after$parseRatelimit as parseRatelimit, retry_after$parseRetryAfter as parseRetryAfter, retry_after$parseRetryAfterForStatus as parseRetryAfterForStatus, retry_after$parseServerRetryHint as parseServerRetryHint } from "./_bundle/rest.js";
|