@distilled.cloud/core 1.0.0-rc.15 → 1.0.0-rc.17
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/api.d.ts +118 -13
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +1 -188
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +1 -278
- package/lib/chunks.d.ts +3 -0
- package/lib/chunks.d.ts.map +1 -0
- package/lib/chunks.js +1 -0
- package/lib/codegen/boolean-string-enums.js +36 -36
- package/lib/codegen/chunk.d.ts +7 -0
- package/lib/codegen/chunk.d.ts.map +1 -0
- package/lib/codegen/chunk.js +139 -0
- package/lib/codegen/chunk.js.map +1 -0
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +28 -14
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/datafy.d.ts +14 -0
- package/lib/codegen/datafy.d.ts.map +1 -0
- package/lib/codegen/datafy.js +853 -0
- package/lib/codegen/datafy.js.map +1 -0
- package/lib/codegen/dedupe.d.ts +5 -0
- package/lib/codegen/dedupe.d.ts.map +1 -0
- package/lib/codegen/dedupe.js +153 -0
- package/lib/codegen/dedupe.js.map +1 -0
- package/lib/codegen/emit.js +56 -56
- package/lib/codegen/format.js +18 -18
- package/lib/codegen/generated-at.js +29 -29
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +92 -84
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/graph.js +36 -36
- package/lib/codegen/graphql-client.d.ts +2 -0
- package/lib/codegen/graphql-client.d.ts.map +1 -1
- package/lib/codegen/graphql-client.js +55 -26
- package/lib/codegen/graphql-client.js.map +1 -1
- package/lib/codegen/graphql.js +113 -113
- package/lib/codegen/latin1.d.ts +3 -0
- package/lib/codegen/latin1.d.ts.map +1 -0
- package/lib/codegen/latin1.js +126 -0
- package/lib/codegen/latin1.js.map +1 -0
- package/lib/codegen/members.d.ts +7 -0
- package/lib/codegen/members.d.ts.map +1 -1
- package/lib/codegen/members.js +26 -19
- package/lib/codegen/members.js.map +1 -1
- package/lib/codegen/model-diff.js +6 -6
- package/lib/codegen/naming.js +19 -19
- package/lib/codegen/openapi-cli.js +15 -15
- package/lib/codegen/openapi.d.ts +17 -0
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +323 -169
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/operations.js +14 -14
- package/lib/codegen/pagination.js +11 -11
- package/lib/codegen/patch-audit.js +57 -57
- package/lib/codegen/patches.js +79 -79
- package/lib/codegen/prelude.js +19 -19
- package/lib/codegen/privatize.d.ts +21 -0
- package/lib/codegen/privatize.d.ts.map +1 -0
- package/lib/codegen/privatize.js +176 -0
- package/lib/codegen/privatize.js.map +1 -0
- package/lib/codegen/proto.js +25 -25
- package/lib/codegen/pure.d.ts +6 -0
- package/lib/codegen/pure.d.ts.map +1 -0
- package/lib/codegen/pure.js +91 -0
- package/lib/codegen/pure.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.js +108 -108
- package/lib/codegen/spec-path.js +57 -57
- package/lib/codegen/table.d.ts +5 -0
- package/lib/codegen/table.d.ts.map +1 -0
- package/lib/codegen/table.js +249 -0
- package/lib/codegen/table.js.map +1 -0
- package/lib/config.d.ts +27 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +1 -0
- package/lib/crypto.d.ts +76 -0
- package/lib/crypto.d.ts.map +1 -0
- package/lib/crypto.js +1 -0
- package/lib/debug.d.ts +2 -0
- package/lib/debug.d.ts.map +1 -0
- package/lib/debug.js +1 -0
- package/lib/error-category.d.ts +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js +1 -46
- package/lib/errors.d.ts +62 -62
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -195
- package/lib/graphql.d.ts +31 -20
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +1 -1027
- package/lib/graphql.types.js +1 -5
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -15
- package/lib/json-patch.d.ts +2 -2
- package/lib/json-patch.js +1 -226
- package/lib/json-patch.js.map +1 -1
- package/lib/pagination.d.ts +9 -25
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +1 -266
- package/lib/plain-values.d.ts +10 -0
- package/lib/plain-values.d.ts.map +1 -0
- package/lib/plain-values.js +2 -0
- package/lib/plain-values.js.map +1 -0
- package/lib/protocol-http.d.ts +50 -14
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +1 -639
- package/lib/protocol-rest.d.ts +38 -25
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +1 -267
- package/lib/query.js +1 -27
- package/lib/response-validation-strict.d.ts +48 -0
- package/lib/response-validation-strict.d.ts.map +1 -0
- package/lib/response-validation-strict.js +1 -0
- package/lib/response-validation.d.ts +43 -25
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js +1 -76
- package/lib/retry-after.d.ts +3 -3
- package/lib/retry-after.js +1 -112
- package/lib/retry.d.ts +48 -29
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -209
- package/lib/schema-lite-impl.d.ts +158 -0
- package/lib/schema-lite-impl.d.ts.map +1 -0
- package/lib/schema-lite-impl.js +1 -0
- package/lib/schema-lite-typed.d.ts +41 -0
- package/lib/schema-lite-typed.d.ts.map +1 -0
- package/lib/schema-lite-typed.js +2 -0
- package/lib/schema-lite-typed.js.map +1 -0
- package/lib/schema-lite.d.ts +40 -0
- package/lib/schema-lite.d.ts.map +1 -0
- package/lib/schema-lite.js +1 -0
- package/lib/schema.d.ts +20 -6
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +1 -48
- package/lib/testing.d.ts +3 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +1 -40
- package/lib/testing.js.map +1 -1
- package/lib/trait.d.ts +13 -13
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +1 -131
- package/lib/xml.d.ts +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/lib/xml.js +1 -311
- package/package.json +9 -7
- package/src/api.ts +1080 -180
- package/src/category.ts +33 -33
- package/src/chunks.ts +30 -0
- package/src/codegen/chunk.ts +147 -0
- package/src/codegen/cli.ts +27 -1
- package/src/codegen/datafy.ts +874 -0
- package/src/codegen/dedupe.ts +173 -0
- package/src/codegen/generator.ts +10 -3
- package/src/codegen/graphql-client.ts +49 -15
- package/src/codegen/latin1.ts +131 -0
- package/src/codegen/members.ts +8 -0
- package/src/codegen/openapi.ts +194 -3
- package/src/codegen/privatize.ts +200 -0
- package/src/codegen/pure.ts +94 -0
- package/src/codegen/table.ts +254 -0
- package/src/config.ts +216 -0
- package/src/crypto.ts +202 -0
- package/src/debug.ts +8 -0
- package/src/error-category.ts +2 -1
- package/src/errors.ts +65 -56
- package/src/graphql.ts +109 -62
- package/src/graphql.types.ts +9 -7
- package/src/index.ts +3 -2
- package/src/json-patch.ts +2 -2
- package/src/pagination.ts +37 -18
- package/src/plain-values.ts +41 -0
- package/src/protocol-http.ts +378 -145
- package/src/protocol-rest.ts +337 -169
- package/src/response-validation-strict.ts +327 -0
- package/src/response-validation.ts +101 -50
- package/src/retry-after.ts +3 -3
- package/src/retry.ts +94 -93
- package/src/schema-lite-impl.ts +550 -0
- package/src/schema-lite-typed.ts +44 -0
- package/src/schema-lite.ts +44 -0
- package/src/schema.ts +258 -14
- package/src/testing.ts +4 -2
- package/src/trait.ts +36 -28
- package/src/xml.ts +31 -17
- package/lib/api.js.map +0 -1
- package/lib/category.js.map +0 -1
- package/lib/codegen/boolean-string-enums.test.d.ts +0 -2
- package/lib/codegen/boolean-string-enums.test.d.ts.map +0 -1
- package/lib/codegen/boolean-string-enums.test.js +0 -275
- package/lib/codegen/boolean-string-enums.test.js.map +0 -1
- package/lib/codegen/defer-naming.test.d.ts +0 -2
- package/lib/codegen/defer-naming.test.d.ts.map +0 -1
- package/lib/codegen/defer-naming.test.js +0 -105
- package/lib/codegen/defer-naming.test.js.map +0 -1
- package/lib/codegen/generated-at.test.d.ts +0 -2
- package/lib/codegen/generated-at.test.d.ts.map +0 -1
- package/lib/codegen/generated-at.test.js +0 -81
- package/lib/codegen/generated-at.test.js.map +0 -1
- package/lib/codegen/generator.test.d.ts +0 -2
- package/lib/codegen/generator.test.d.ts.map +0 -1
- package/lib/codegen/generator.test.js +0 -121
- package/lib/codegen/generator.test.js.map +0 -1
- package/lib/codegen/graphql-client.test.d.ts +0 -2
- package/lib/codegen/graphql-client.test.d.ts.map +0 -1
- package/lib/codegen/graphql-client.test.js +0 -171
- package/lib/codegen/graphql-client.test.js.map +0 -1
- package/lib/codegen/openapi-binary.test.d.ts +0 -2
- package/lib/codegen/openapi-binary.test.d.ts.map +0 -1
- package/lib/codegen/openapi-binary.test.js +0 -67
- package/lib/codegen/openapi-binary.test.js.map +0 -1
- package/lib/codegen/patch-audit.test.d.ts +0 -2
- package/lib/codegen/patch-audit.test.d.ts.map +0 -1
- package/lib/codegen/patch-audit.test.js +0 -141
- package/lib/codegen/patch-audit.test.js.map +0 -1
- package/lib/codegen/patches.test.d.ts +0 -2
- package/lib/codegen/patches.test.d.ts.map +0 -1
- package/lib/codegen/patches.test.js +0 -155
- package/lib/codegen/patches.test.js.map +0 -1
- package/lib/codegen/protocol-imports.test.d.ts +0 -2
- package/lib/codegen/protocol-imports.test.d.ts.map +0 -1
- package/lib/codegen/protocol-imports.test.js +0 -36
- package/lib/codegen/protocol-imports.test.js.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.d.ts +0 -2
- package/lib/codegen/rewrite-operation-ids.test.d.ts.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.js +0 -451
- package/lib/codegen/rewrite-operation-ids.test.js.map +0 -1
- package/lib/codegen/untagged-unions.test.d.ts +0 -2
- package/lib/codegen/untagged-unions.test.d.ts.map +0 -1
- package/lib/codegen/untagged-unions.test.js +0 -80
- package/lib/codegen/untagged-unions.test.js.map +0 -1
- package/lib/error-category.js.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/fixtures/xml/upstream-validator.json +0 -397
- package/lib/graphql.js.map +0 -1
- package/lib/graphql.test.d.ts +0 -2
- package/lib/graphql.test.d.ts.map +0 -1
- package/lib/graphql.test.js +0 -151
- package/lib/graphql.test.js.map +0 -1
- package/lib/graphql.types.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/json-patch.test.d.ts +0 -2
- package/lib/json-patch.test.d.ts.map +0 -1
- package/lib/json-patch.test.js +0 -65
- package/lib/json-patch.test.js.map +0 -1
- package/lib/pagination.js.map +0 -1
- package/lib/pagination.test.d.ts +0 -2
- package/lib/pagination.test.d.ts.map +0 -1
- package/lib/pagination.test.js +0 -131
- package/lib/pagination.test.js.map +0 -1
- package/lib/protocol-http.js.map +0 -1
- package/lib/protocol-http.test.d.ts +0 -2
- package/lib/protocol-http.test.d.ts.map +0 -1
- package/lib/protocol-http.test.js +0 -228
- package/lib/protocol-http.test.js.map +0 -1
- package/lib/protocol-rest.js.map +0 -1
- package/lib/protocol-rest.test.d.ts +0 -2
- package/lib/protocol-rest.test.d.ts.map +0 -1
- package/lib/protocol-rest.test.js +0 -498
- package/lib/protocol-rest.test.js.map +0 -1
- package/lib/query.js.map +0 -1
- package/lib/response-validation.js.map +0 -1
- package/lib/response-validation.test.d.ts +0 -2
- package/lib/response-validation.test.d.ts.map +0 -1
- package/lib/response-validation.test.js +0 -72
- package/lib/response-validation.test.js.map +0 -1
- package/lib/retry-after.js.map +0 -1
- package/lib/retry-after.test.d.ts +0 -2
- package/lib/retry-after.test.d.ts.map +0 -1
- package/lib/retry-after.test.js +0 -204
- package/lib/retry-after.test.js.map +0 -1
- package/lib/retry.js.map +0 -1
- package/lib/retry.test.d.ts +0 -2
- package/lib/retry.test.d.ts.map +0 -1
- package/lib/retry.test.js +0 -407
- package/lib/retry.test.js.map +0 -1
- package/lib/schema.js.map +0 -1
- package/lib/sdks.test.d.ts +0 -2
- package/lib/sdks.test.d.ts.map +0 -1
- package/lib/sdks.test.js +0 -76
- package/lib/sdks.test.js.map +0 -1
- package/lib/trait.js.map +0 -1
- package/lib/xml.js.map +0 -1
- package/lib/xml.test.d.ts +0 -2
- package/lib/xml.test.d.ts.map +0 -1
- package/lib/xml.test.js +0 -210
- package/lib/xml.test.js.map +0 -1
- package/src/codegen/boolean-string-enums.test.ts +0 -299
- package/src/codegen/defer-naming.test.ts +0 -113
- package/src/codegen/generated-at.test.ts +0 -89
- package/src/codegen/generator.test.ts +0 -137
- package/src/codegen/graphql-client.test.ts +0 -189
- package/src/codegen/openapi-binary.test.ts +0 -91
- package/src/codegen/patch-audit.test.ts +0 -160
- package/src/codegen/patches.test.ts +0 -188
- package/src/codegen/protocol-imports.test.ts +0 -39
- package/src/codegen/rewrite-operation-ids.test.ts +0 -472
- package/src/codegen/untagged-unions.test.ts +0 -85
- package/src/fixtures/xml/upstream-validator.json +0 -397
- package/src/graphql.test.ts +0 -198
- package/src/json-patch.test.ts +0 -77
- package/src/pagination.test.ts +0 -169
- package/src/protocol-http.test.ts +0 -276
- package/src/protocol-rest.test.ts +0 -703
- package/src/response-validation.test.ts +0 -89
- package/src/retry-after.test.ts +0 -267
- package/src/retry.test.ts +0 -566
- package/src/sdks.test.ts +0 -87
- package/src/xml.test.ts +0 -251
package/src/json-patch.test.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
import { applyOperation, StaleTargetError } from "./json-patch.ts";
|
|
3
|
-
|
|
4
|
-
describe("RFC 6902 arrays", () => {
|
|
5
|
-
test("add at an index inserts before it", () => {
|
|
6
|
-
const doc = { errors: ["a", "c"] };
|
|
7
|
-
applyOperation(doc, { op: "add", path: "/errors/1", value: "b" });
|
|
8
|
-
expect(doc.errors).toEqual(["a", "b", "c"]);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test("add at the length appends, like `-`", () => {
|
|
12
|
-
const doc = { errors: ["a"] };
|
|
13
|
-
applyOperation(doc, { op: "add", path: "/errors/1", value: "b" });
|
|
14
|
-
applyOperation(doc, { op: "add", path: "/errors/-", value: "c" });
|
|
15
|
-
expect(doc.errors).toEqual(["a", "b", "c"]);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test("add past the end is a stale target", () => {
|
|
19
|
-
expect(() =>
|
|
20
|
-
applyOperation({ errors: [] }, { op: "add", path: "/errors/2", value: "x" }),
|
|
21
|
-
).toThrow(StaleTargetError);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("replace at an index overwrites", () => {
|
|
25
|
-
const doc = { errors: ["a", "x", "c"] };
|
|
26
|
-
applyOperation(doc, { op: "replace", path: "/errors/1", value: "b" });
|
|
27
|
-
expect(doc.errors).toEqual(["a", "b", "c"]);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("replace keeps an object key in place", () => {
|
|
31
|
-
const doc: Record<string, unknown> = { a: 1, b: 2, c: 3 };
|
|
32
|
-
applyOperation(doc, { op: "replace", path: "/b", value: 4 });
|
|
33
|
-
expect(Object.keys(doc)).toEqual(["a", "b", "c"]);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test("move into an array inserts", () => {
|
|
37
|
-
const doc = { from: "b", list: ["a", "c"] };
|
|
38
|
-
applyOperation(doc, { op: "move", from: "/from", path: "/list/1" });
|
|
39
|
-
expect(doc).toEqual({ list: ["a", "b", "c"] });
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe("`before` on object keys", () => {
|
|
44
|
-
test("add inserts a new key before the named sibling", () => {
|
|
45
|
-
const doc: Record<string, unknown> = { input: 1, output: 2, traits: 3 };
|
|
46
|
-
applyOperation(doc, { op: "add", path: "/errors", value: [], before: "traits" });
|
|
47
|
-
expect(Object.keys(doc)).toEqual(["input", "output", "errors", "traits"]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test("add keeps an existing key where it is", () => {
|
|
51
|
-
const doc: Record<string, unknown> = { a: 1, b: 2, c: 3 };
|
|
52
|
-
applyOperation(doc, { op: "add", path: "/c", value: 4, before: "a" });
|
|
53
|
-
expect(doc).toEqual({ a: 1, b: 2, c: 4 });
|
|
54
|
-
expect(Object.keys(doc)).toEqual(["a", "b", "c"]);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test("add appends when the sibling is absent", () => {
|
|
58
|
-
const doc: Record<string, unknown> = { a: 1 };
|
|
59
|
-
applyOperation(doc, { op: "add", path: "/b", value: 2, before: "missing" });
|
|
60
|
-
expect(Object.keys(doc)).toEqual(["a", "b"]);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test("add keeps the parent object's identity", () => {
|
|
64
|
-
const shapes: Record<string, unknown> = { a: 1, c: 3 };
|
|
65
|
-
const doc = { shapes };
|
|
66
|
-
applyOperation(doc, { op: "add", path: "/shapes/b", value: 2, before: "c" });
|
|
67
|
-
expect(doc.shapes).toBe(shapes);
|
|
68
|
-
expect(Object.keys(shapes)).toEqual(["a", "b", "c"]);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test("move onto itself reorders a key", () => {
|
|
72
|
-
const doc: Record<string, unknown> = { a: 1, b: 2, c: 3 };
|
|
73
|
-
applyOperation(doc, { op: "move", from: "/c", path: "/c", before: "a" });
|
|
74
|
-
expect(Object.keys(doc)).toEqual(["c", "a", "b"]);
|
|
75
|
-
expect(doc).toEqual({ a: 1, b: 2, c: 3 });
|
|
76
|
-
});
|
|
77
|
-
});
|
package/src/pagination.test.ts
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import * as Effect from "effect/Effect";
|
|
2
|
-
import * as Stream from "effect/Stream";
|
|
3
|
-
import { describe, expect, test } from "vitest";
|
|
4
|
-
import { extractItems, paginateCursor, type PaginatedTrait } from "./pagination.ts";
|
|
5
|
-
|
|
6
|
-
const pagination: PaginatedTrait = {
|
|
7
|
-
mode: "cursor",
|
|
8
|
-
inputToken: "cursor",
|
|
9
|
-
outputToken: "pagination.cursor",
|
|
10
|
-
items: "items",
|
|
11
|
-
pageSize: "limit",
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
type Page = {
|
|
15
|
-
items?: number[];
|
|
16
|
-
pagination?: { cursor?: string | null };
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
type Scenario = {
|
|
20
|
-
name: string;
|
|
21
|
-
start?: string;
|
|
22
|
-
pages: Page[];
|
|
23
|
-
cursors: Array<string | undefined>;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const scenarios: Scenario[] = [
|
|
27
|
-
{
|
|
28
|
-
name: "advances normally until the cursor is omitted",
|
|
29
|
-
pages: [
|
|
30
|
-
{ items: [1], pagination: { cursor: "a" } },
|
|
31
|
-
{ items: [2], pagination: { cursor: "b" } },
|
|
32
|
-
{ items: [3] },
|
|
33
|
-
],
|
|
34
|
-
cursors: [undefined, "a", "b"],
|
|
35
|
-
},
|
|
36
|
-
...([null, ""] as const).map((cursor) => ({
|
|
37
|
-
name: `terminates on ${JSON.stringify(cursor)}`,
|
|
38
|
-
pages: [
|
|
39
|
-
{ items: [1], pagination: { cursor: "a" } },
|
|
40
|
-
{ items: [2], pagination: { cursor } },
|
|
41
|
-
],
|
|
42
|
-
cursors: [undefined, "a"],
|
|
43
|
-
})),
|
|
44
|
-
{
|
|
45
|
-
name: "terminates on an empty page echoing the requested cursor",
|
|
46
|
-
pages: [
|
|
47
|
-
{ items: [1], pagination: { cursor: "a" } },
|
|
48
|
-
{ items: [], pagination: { cursor: "a" } },
|
|
49
|
-
],
|
|
50
|
-
cursors: [undefined, "a"],
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
name: "emits a nonempty page before stopping on a repeated cursor",
|
|
54
|
-
pages: [
|
|
55
|
-
{ items: [1], pagination: { cursor: "a" } },
|
|
56
|
-
{ items: [2], pagination: { cursor: "a" } },
|
|
57
|
-
],
|
|
58
|
-
cursors: [undefined, "a"],
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: "terminates when the first response echoes the initial cursor",
|
|
62
|
-
start: "initial",
|
|
63
|
-
pages: [{ items: [1], pagination: { cursor: "initial" } }],
|
|
64
|
-
cursors: ["initial"],
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: "terminates a multi-cursor cycle",
|
|
68
|
-
pages: [
|
|
69
|
-
{ items: [1], pagination: { cursor: "a" } },
|
|
70
|
-
{ items: [2], pagination: { cursor: "b" } },
|
|
71
|
-
{ items: [3], pagination: { cursor: "a" } },
|
|
72
|
-
],
|
|
73
|
-
cursors: [undefined, "a", "b"],
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
name: "terminates a cycle returning to the initial cursor",
|
|
77
|
-
start: "initial",
|
|
78
|
-
pages: [
|
|
79
|
-
{ items: [1], pagination: { cursor: "a" } },
|
|
80
|
-
{ items: [2], pagination: { cursor: "initial" } },
|
|
81
|
-
],
|
|
82
|
-
cursors: ["initial", "a"],
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
name: "preserves empty and sparse pages whose cursors advance",
|
|
86
|
-
pages: [
|
|
87
|
-
{ items: [], pagination: { cursor: "a" } },
|
|
88
|
-
{ pagination: { cursor: "b" } },
|
|
89
|
-
{ items: [1], pagination: { cursor: "c" } },
|
|
90
|
-
{ items: [], pagination: { cursor: "d" } },
|
|
91
|
-
{ items: [2] },
|
|
92
|
-
],
|
|
93
|
-
cursors: [undefined, "a", "b", "c", "d"],
|
|
94
|
-
},
|
|
95
|
-
];
|
|
96
|
-
|
|
97
|
-
const fixture = ({ pages, start }: Scenario) => {
|
|
98
|
-
const requests: Array<{ cursor?: string; limit: number }> = [];
|
|
99
|
-
const input = { ...(start === undefined ? {} : { cursor: start }), limit: 1 };
|
|
100
|
-
const stream = paginateCursor(
|
|
101
|
-
(request) =>
|
|
102
|
-
Effect.sync(() => {
|
|
103
|
-
const page = pages[requests.length];
|
|
104
|
-
requests.push(request);
|
|
105
|
-
if (!page) throw new Error("Paginator made an unexpected extra request");
|
|
106
|
-
return page;
|
|
107
|
-
}),
|
|
108
|
-
input,
|
|
109
|
-
pagination,
|
|
110
|
-
);
|
|
111
|
-
return { stream, requests, input };
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const collect = <A>(stream: Stream.Stream<A>) =>
|
|
115
|
-
Stream.runCollect(stream).pipe(Effect.timeout("1 second"));
|
|
116
|
-
|
|
117
|
-
describe("cursor pagination", () => {
|
|
118
|
-
test.each(scenarios)("$name", (scenario) =>
|
|
119
|
-
Effect.runPromise(
|
|
120
|
-
Effect.gen(function* () {
|
|
121
|
-
const { stream, requests, input } = fixture(scenario);
|
|
122
|
-
const pages = yield* collect(stream);
|
|
123
|
-
expect(Array.from(pages)).toEqual(scenario.pages);
|
|
124
|
-
expect(requests.map((request) => request.cursor)).toEqual(scenario.cursors);
|
|
125
|
-
expect(requests.every((request) => request.limit === 1)).toBe(true);
|
|
126
|
-
expect(input.cursor).toBe(scenario.start);
|
|
127
|
-
}),
|
|
128
|
-
),
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
test.each(scenarios)("item extraction: $name", (scenario) =>
|
|
132
|
-
Effect.runPromise(
|
|
133
|
-
Effect.gen(function* () {
|
|
134
|
-
const { stream, requests } = fixture(scenario);
|
|
135
|
-
const items = yield* collect(extractItems<Page, number, never, never>(stream, "items"));
|
|
136
|
-
expect(Array.from(items)).toEqual(scenario.pages.flatMap((page) => page.items ?? []));
|
|
137
|
-
expect(requests.map((request) => request.cursor)).toEqual(scenario.cursors);
|
|
138
|
-
}),
|
|
139
|
-
),
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
test("cursor history is isolated across repeated and concurrent stream runs", () =>
|
|
143
|
-
Effect.runPromise(
|
|
144
|
-
Effect.gen(function* () {
|
|
145
|
-
let calls = 0;
|
|
146
|
-
const pages: Page[] = [
|
|
147
|
-
{ items: [1], pagination: { cursor: "a" } },
|
|
148
|
-
{ items: [2], pagination: { cursor: "b" } },
|
|
149
|
-
{ items: [], pagination: { cursor: "b" } },
|
|
150
|
-
];
|
|
151
|
-
const stream = paginateCursor(
|
|
152
|
-
(input: { cursor?: string }) =>
|
|
153
|
-
Effect.sync(() => {
|
|
154
|
-
if (++calls > 12) throw new Error("Paginator exceeded the request bound");
|
|
155
|
-
return pages[input.cursor === "a" ? 1 : input.cursor === "b" ? 2 : 0]!;
|
|
156
|
-
}),
|
|
157
|
-
{},
|
|
158
|
-
pagination,
|
|
159
|
-
);
|
|
160
|
-
expect(Array.from(yield* collect(stream))).toEqual(pages);
|
|
161
|
-
expect(Array.from(yield* collect(stream))).toEqual(pages);
|
|
162
|
-
const concurrent = yield* Effect.all([collect(stream), collect(stream)], {
|
|
163
|
-
concurrency: "unbounded",
|
|
164
|
-
});
|
|
165
|
-
expect(concurrent.map((result) => Array.from(result))).toEqual([pages, pages]);
|
|
166
|
-
expect(calls).toBe(12);
|
|
167
|
-
}),
|
|
168
|
-
));
|
|
169
|
-
});
|
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
import * as Redacted from "effect/Redacted";
|
|
2
|
-
import { describe, expect, test } from "vitest";
|
|
3
|
-
import { buildRequest, mapKeys } from "./protocol-http.ts";
|
|
4
|
-
import { SensitiveValue, wrapSensitive } from "./protocol-rest.ts";
|
|
5
|
-
import * as S from "./schema.ts";
|
|
6
|
-
import * as T from "./trait.ts";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* `T.StringEncoded()`: the member's TS type stays natural (boolean) but the
|
|
10
|
-
* wire carries its string spelling, for APIs that document the field as the
|
|
11
|
-
* enum `"true" | "false"` rather than a JSON boolean.
|
|
12
|
-
*/
|
|
13
|
-
const JsonInput = S.Struct({
|
|
14
|
-
flag: S.optional(S.Boolean.pipe(T.Body("flag"), T.StringEncoded())),
|
|
15
|
-
plain: S.optional(S.Boolean.pipe(T.Body("plain"))),
|
|
16
|
-
nullable: S.optional(S.NullOr(S.Boolean).pipe(T.Body("nullable"), T.StringEncoded())),
|
|
17
|
-
flags: S.optional(S.Array(S.Boolean).pipe(T.Body("flags"), T.StringEncoded())),
|
|
18
|
-
profile: S.optional(
|
|
19
|
-
S.Struct({
|
|
20
|
-
nested: S.optional(S.Boolean.pipe(T.Body("nested_flag"), T.StringEncoded())),
|
|
21
|
-
plain: S.optional(S.Boolean.pipe(T.Body("plain_flag"))),
|
|
22
|
-
}).pipe(T.Body("profile")),
|
|
23
|
-
),
|
|
24
|
-
}).pipe(T.Http({ method: "POST", uri: "/things" }));
|
|
25
|
-
|
|
26
|
-
const jsonBodyOf = (input: unknown): unknown => {
|
|
27
|
-
const request = buildRequest({
|
|
28
|
-
input,
|
|
29
|
-
inputAst: JsonInput.ast,
|
|
30
|
-
baseUrl: "https://example.test",
|
|
31
|
-
});
|
|
32
|
-
const body = request.body as { readonly body?: string };
|
|
33
|
-
return JSON.parse(body.body ?? "{}");
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
describe("StringEncoded members", () => {
|
|
37
|
-
test("booleans serialize as their string spelling", () => {
|
|
38
|
-
expect(jsonBodyOf({ flag: true, plain: true })).toEqual({
|
|
39
|
-
flag: "true",
|
|
40
|
-
plain: true,
|
|
41
|
-
});
|
|
42
|
-
expect(jsonBodyOf({ flag: false, plain: false })).toEqual({
|
|
43
|
-
flag: "false",
|
|
44
|
-
plain: false,
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test("a list stringifies element-wise", () => {
|
|
49
|
-
expect(jsonBodyOf({ flags: [true, false] })).toEqual({
|
|
50
|
-
flags: ["true", "false"],
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test("a member nested in a body struct stringifies too", () => {
|
|
55
|
-
expect(jsonBodyOf({ profile: { nested: true, plain: true } })).toEqual({
|
|
56
|
-
profile: { nested_flag: "true", plain_flag: true },
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test("null stays null and an omitted member stays omitted", () => {
|
|
61
|
-
expect(jsonBodyOf({ nullable: null })).toEqual({ nullable: null });
|
|
62
|
-
expect(jsonBodyOf({})).toEqual({});
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe("URI label encoding", () => {
|
|
67
|
-
const input = (preserve?: string) =>
|
|
68
|
-
S.Struct({
|
|
69
|
-
scope:
|
|
70
|
-
preserve === undefined
|
|
71
|
-
? S.String.pipe(T.Label())
|
|
72
|
-
: S.String.pipe(T.Label(), T.LabelEncoding({ preserve })),
|
|
73
|
-
}).pipe(T.Http({ method: "POST", uri: "/runtime/{scope}" }));
|
|
74
|
-
const url = (scope: string, preserve?: string) =>
|
|
75
|
-
buildRequest({
|
|
76
|
-
input: { scope },
|
|
77
|
-
inputAst: input(preserve).ast,
|
|
78
|
-
baseUrl: "https://example.test",
|
|
79
|
-
}).url;
|
|
80
|
-
|
|
81
|
-
test("keeps the existing escaping unless a model opts in", () => {
|
|
82
|
-
expect(url("__KV:abc")).toBe("https://example.test/runtime/__KV%3Aabc");
|
|
83
|
-
expect(url("__KV:abc", ":")).toBe("https://example.test/runtime/__KV:abc");
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test("preserves only modeled pchar delimiters, not separators or escapes", () => {
|
|
87
|
-
expect(url("__KV:a/b?c#d%3Aé", ":")).toBe(
|
|
88
|
-
"https://example.test/runtime/__KV:a%2Fb%3Fc%23d%253A%C3%A9",
|
|
89
|
-
);
|
|
90
|
-
expect(url("$&:@", "$&:")).toBe("https://example.test/runtime/$&:%40");
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test("refuses unsafe preservation rules", () => {
|
|
94
|
-
for (const preserve of ["/", "?", "#", "%", "\\r", "[", "]"]) {
|
|
95
|
-
expect(() => T.LabelEncoding({ preserve })).toThrow(TypeError);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe("greedy labels", () => {
|
|
101
|
-
const ScopedInput = S.Struct({
|
|
102
|
-
scope: S.String.pipe(T.Label()),
|
|
103
|
-
name: S.String.pipe(T.Label()),
|
|
104
|
-
}).pipe(T.Http({ method: "GET", uri: "/{scope+}/providers/Things/{name}" }));
|
|
105
|
-
|
|
106
|
-
const urlOf = (input: unknown) =>
|
|
107
|
-
buildRequest({
|
|
108
|
-
input,
|
|
109
|
-
inputAst: ScopedInput.ast,
|
|
110
|
-
baseUrl: "https://example.test",
|
|
111
|
-
}).url;
|
|
112
|
-
|
|
113
|
-
test("keeps slashes and drops the leading slash of the value", () => {
|
|
114
|
-
expect(urlOf({ scope: "/subscriptions/abc/resourceGroups/my rg", name: "a/b" })).toBe(
|
|
115
|
-
"https://example.test/subscriptions/abc/resourceGroups/my%20rg/providers/Things/a%2Fb",
|
|
116
|
-
);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test("accepts a value without a leading slash", () => {
|
|
120
|
-
expect(urlOf({ scope: "subscriptions/abc", name: "x" })).toBe(
|
|
121
|
-
"https://example.test/subscriptions/abc/providers/Things/x",
|
|
122
|
-
);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
describe("multipart binary parts", () => {
|
|
127
|
-
const schema = S.Struct({ zip: S.Unknown, environment: S.String }).pipe(
|
|
128
|
-
T.Http({ method: "POST", uri: "/deployments", contentType: "multipart" }),
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
test("preserves typed-array slices and an already JSON-encoded environment", async () => {
|
|
132
|
-
const input = new Uint8Array([99, 80, 75, 0, 255, 99]).subarray(1, 5);
|
|
133
|
-
const environment = JSON.stringify({ SECRET: "value", REMOVED: "" });
|
|
134
|
-
const request = buildRequest({
|
|
135
|
-
input: { zip: input, environment },
|
|
136
|
-
inputAst: schema.ast,
|
|
137
|
-
baseUrl: "https://example.test",
|
|
138
|
-
});
|
|
139
|
-
if (request.body._tag !== "FormData") throw new Error("Expected multipart");
|
|
140
|
-
const part = request.body.formData.get("zip");
|
|
141
|
-
expect(part).toBeInstanceOf(File);
|
|
142
|
-
expect(new Uint8Array(await (part as File).arrayBuffer())).toEqual(input);
|
|
143
|
-
expect(request.body.formData.getAll("environment")).toEqual([environment]);
|
|
144
|
-
const wire = new Request(request.url, {
|
|
145
|
-
method: "POST",
|
|
146
|
-
body: request.body.formData,
|
|
147
|
-
});
|
|
148
|
-
expect(wire.headers.get("content-type")).toContain("multipart/form-data; boundary=");
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
test("preserves File names and ArrayBuffer bytes", async () => {
|
|
152
|
-
for (const zip of [
|
|
153
|
-
new File([new Uint8Array([80, 75, 255])], "bundle.zip"),
|
|
154
|
-
new Uint8Array([80, 75, 255]).buffer,
|
|
155
|
-
]) {
|
|
156
|
-
const request = buildRequest({
|
|
157
|
-
input: { zip, environment: "{}" },
|
|
158
|
-
inputAst: schema.ast,
|
|
159
|
-
baseUrl: "https://example.test",
|
|
160
|
-
});
|
|
161
|
-
if (request.body._tag !== "FormData") throw new Error("Expected multipart");
|
|
162
|
-
const part = request.body.formData.get("zip") as File;
|
|
163
|
-
expect(part.name).toBe(zip instanceof File ? "bundle.zip" : "zip");
|
|
164
|
-
expect(new Uint8Array(await part.arrayBuffer())).toEqual(new Uint8Array([80, 75, 255]));
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe("sensitive union responses", () => {
|
|
170
|
-
const schema = S.suspend(() =>
|
|
171
|
-
S.Union([
|
|
172
|
-
S.Struct({
|
|
173
|
-
type: S.Literal("standard"),
|
|
174
|
-
password: S.String.pipe(SensitiveValue()),
|
|
175
|
-
}),
|
|
176
|
-
S.Struct({
|
|
177
|
-
type: S.Literal("token"),
|
|
178
|
-
token: S.String.pipe(SensitiveValue()),
|
|
179
|
-
}),
|
|
180
|
-
S.Struct({ type: S.Literal("shared") }),
|
|
181
|
-
]),
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
test("all arms redact their secrets, even in partial or ambiguous responses", () => {
|
|
185
|
-
for (const value of [
|
|
186
|
-
{ type: "standard", password: "fixture-password" },
|
|
187
|
-
{ type: "token", token: "fixture-token" },
|
|
188
|
-
{ password: "fixture-password", token: "fixture-token" },
|
|
189
|
-
]) {
|
|
190
|
-
const wrapped = wrapSensitive(schema.ast, value);
|
|
191
|
-
expect(wrapped).toEqual(
|
|
192
|
-
Object.fromEntries(
|
|
193
|
-
Object.entries(value).map(([key, value]) => [
|
|
194
|
-
key,
|
|
195
|
-
key === "type" ? value : Redacted.make(value),
|
|
196
|
-
]),
|
|
197
|
-
),
|
|
198
|
-
);
|
|
199
|
-
expect(JSON.stringify(wrapped)).not.toContain("fixture-password");
|
|
200
|
-
expect(JSON.stringify(wrapped)).not.toContain("fixture-token");
|
|
201
|
-
expect(wrapSensitive(schema.ast, wrapped)).toEqual(wrapped);
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
test("nested arrays and optional nullable unions preserve nonsecret values", () => {
|
|
206
|
-
const nested = S.Struct({
|
|
207
|
-
provider: S.optional(S.NullOr(schema)),
|
|
208
|
-
providers: S.Array(schema),
|
|
209
|
-
});
|
|
210
|
-
for (const value of [{}, { provider: null }, { provider: { type: "shared" } }]) {
|
|
211
|
-
expect(
|
|
212
|
-
wrapSensitive(nested.ast, {
|
|
213
|
-
...value,
|
|
214
|
-
providers: [{ type: "standard", password: "fixture-password" }, { type: "shared" }],
|
|
215
|
-
}),
|
|
216
|
-
).toEqual({
|
|
217
|
-
...value,
|
|
218
|
-
providers: [
|
|
219
|
-
{ type: "standard", password: Redacted.make("fixture-password") },
|
|
220
|
-
{ type: "shared" },
|
|
221
|
-
],
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
describe("UnionCases decoding", () => {
|
|
228
|
-
const cases = [
|
|
229
|
-
["id", "type", "zoneName"],
|
|
230
|
-
["id", "type", "accountName"],
|
|
231
|
-
];
|
|
232
|
-
const merged = {
|
|
233
|
-
id: "1",
|
|
234
|
-
type: "account",
|
|
235
|
-
zoneName: "zone-a",
|
|
236
|
-
accountName: "acct-a",
|
|
237
|
-
};
|
|
238
|
-
const decode = (schema: S.Schema<unknown>, value: unknown) =>
|
|
239
|
-
mapKeys(schema.ast, value, "decode");
|
|
240
|
-
|
|
241
|
-
test("the discriminator picks the case key sets cannot tell apart", () => {
|
|
242
|
-
const schema = S.Unknown.pipe(
|
|
243
|
-
T.UnionCases(cases, { key: "type", values: ["zone", "account"] }),
|
|
244
|
-
);
|
|
245
|
-
expect(decode(schema, merged)).toEqual({
|
|
246
|
-
id: "1",
|
|
247
|
-
type: "account",
|
|
248
|
-
accountName: "acct-a",
|
|
249
|
-
});
|
|
250
|
-
expect(decode(schema, { ...merged, type: "zone" })).toEqual({
|
|
251
|
-
id: "1",
|
|
252
|
-
type: "zone",
|
|
253
|
-
zoneName: "zone-a",
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
test("an unknown tag falls back to key-set scoring", () => {
|
|
258
|
-
const schema = S.Unknown.pipe(
|
|
259
|
-
T.UnionCases(cases, { key: "type", values: ["zone", "account"] }),
|
|
260
|
-
);
|
|
261
|
-
expect(decode(schema, { ...merged, type: "other", accountName: null })).toEqual({
|
|
262
|
-
id: "1",
|
|
263
|
-
type: "other",
|
|
264
|
-
zoneName: "zone-a",
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
test("without a discriminator the best-explaining case wins", () => {
|
|
269
|
-
const schema = S.Unknown.pipe(T.UnionCases(cases));
|
|
270
|
-
expect(decode(schema, { ...merged, zoneName: null })).toEqual({
|
|
271
|
-
id: "1",
|
|
272
|
-
type: "account",
|
|
273
|
-
accountName: "acct-a",
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
});
|