@distilled.cloud/core 1.0.0-rc.14 → 1.0.0-rc.16
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/api.d.ts +118 -13
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +755 -147
- package/lib/api.js.map +1 -1
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +146 -146
- package/lib/category.js.map +1 -1
- package/lib/chunks.d.ts +3 -0
- package/lib/chunks.d.ts.map +1 -0
- package/lib/chunks.js +11 -0
- package/lib/chunks.js.map +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 +161 -0
- package/lib/config.js.map +1 -0
- package/lib/crypto.d.ts +76 -0
- package/lib/crypto.d.ts.map +1 -0
- package/lib/crypto.js +130 -0
- package/lib/crypto.js.map +1 -0
- package/lib/debug.d.ts +2 -0
- package/lib/debug.d.ts.map +1 -0
- package/lib/debug.js +8 -0
- package/lib/debug.js.map +1 -0
- package/lib/error-category.d.ts +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js +7 -6
- package/lib/error-category.js.map +1 -1
- package/lib/errors.d.ts +62 -62
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +117 -114
- package/lib/errors.js.map +1 -1
- package/lib/graphql.d.ts +31 -20
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +150 -119
- package/lib/graphql.js.map +1 -1
- package/lib/graphql.types.js +4 -3
- package/lib/graphql.types.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +15 -14
- package/lib/index.js.map +1 -1
- package/lib/json-patch.d.ts +2 -2
- package/lib/json-patch.js +28 -28
- package/lib/pagination.d.ts +9 -25
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +95 -90
- package/lib/pagination.js.map +1 -1
- package/lib/plain-values.d.ts +10 -0
- package/lib/plain-values.d.ts.map +1 -0
- package/lib/plain-values.js +40 -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 +351 -178
- package/lib/protocol-http.js.map +1 -1
- package/lib/protocol-rest.d.ts +38 -25
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +238 -130
- package/lib/protocol-rest.js.map +1 -1
- package/lib/query.js +16 -16
- 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 +284 -0
- package/lib/response-validation-strict.js.map +1 -0
- package/lib/response-validation.d.ts +43 -25
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js +112 -70
- package/lib/response-validation.js.map +1 -1
- package/lib/retry-after.d.ts +3 -3
- package/lib/retry-after.js +49 -49
- package/lib/retry.d.ts +48 -29
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +142 -154
- package/lib/retry.js.map +1 -1
- 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 +341 -0
- package/lib/schema-lite-impl.js.map +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 +27 -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 +31 -0
- package/lib/schema-lite.js.map +1 -0
- package/lib/schema.d.ts +20 -6
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +202 -30
- package/lib/schema.js.map +1 -1
- package/lib/testing.d.ts +3 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +22 -21
- 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 +80 -80
- package/lib/trait.js.map +1 -1
- package/lib/xml.d.ts +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/lib/xml.js +38 -26
- package/lib/xml.js.map +1 -1
- package/package.json +9 -7
- package/src/api.ts +1079 -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/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/fixtures/xml/upstream-validator.json +0 -397
- 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/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.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.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.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/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.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.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/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/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/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@distilled.cloud/core`
|
|
2
|
+
* `@distilled.cloud/core` -- the runtime shared by every distilled SDK.
|
|
3
3
|
*
|
|
4
4
|
* ```ts
|
|
5
5
|
* import { ResponseValidation, Retry } from "@distilled.cloud/core";
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* ```
|
|
9
9
|
*
|
|
10
10
|
* Each namespace is also importable on its own subpath
|
|
11
|
-
* (`@distilled.cloud/core/response-validation`,
|
|
11
|
+
* (`@distilled.cloud/core/response-validation`, ...); generated SDKs use the
|
|
12
12
|
* subpaths. Code generation (`codegen/*`) and test helpers (`testing`) stay
|
|
13
13
|
* subpath-only.
|
|
14
14
|
*/
|
|
@@ -20,6 +20,7 @@ export * as Pagination from "./pagination.ts";
|
|
|
20
20
|
export * as ProtocolHttp from "./protocol-http.ts";
|
|
21
21
|
export * as ProtocolRest from "./protocol-rest.ts";
|
|
22
22
|
export { Query } from "./query.ts";
|
|
23
|
+
export * as Crypto from "./crypto.ts";
|
|
23
24
|
export * as ResponseValidation from "./response-validation.ts";
|
|
24
25
|
export * as Retry from "./retry.ts";
|
|
25
26
|
export * as RetryAfter from "./retry-after.ts";
|
package/src/json-patch.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* model; generate does not patch. Operation names are convert policy
|
|
7
7
|
* (`operationNames`), never a patch.
|
|
8
8
|
*
|
|
9
|
-
* Pure functions only
|
|
9
|
+
* Pure functions only -- callers load patch files themselves (the generators
|
|
10
10
|
* use Effect's FileSystem) and hand the parsed operations to `applyPatch`.
|
|
11
11
|
*/
|
|
12
12
|
|
|
@@ -54,7 +54,7 @@ export function parseJsonPointer(pointer: string): string[] {
|
|
|
54
54
|
|
|
55
55
|
/** Get a value at a JSON Pointer path. */
|
|
56
56
|
/**
|
|
57
|
-
* The target location of a patch operation is absent from the document
|
|
57
|
+
* The target location of a patch operation is absent from the document --
|
|
58
58
|
* spec drift (renamed/removed upstream), not a malformed patch.
|
|
59
59
|
*/
|
|
60
60
|
export class StaleTargetError extends Error {
|
package/src/pagination.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* - Cursor-based: cursor/limit with an opaque next-cursor string
|
|
7
7
|
* - Token-based (AWS style): NextToken/MaxResults continuation tokens
|
|
8
8
|
* - Relay (GraphQL connections): after/first with a `pageInfo` block whose
|
|
9
|
-
* `hasNextPage`
|
|
9
|
+
* `hasNextPage` -- not the cursor -- marks the end
|
|
10
10
|
* - Single: one-shot list endpoints that still expose the paginated surface
|
|
11
11
|
*
|
|
12
12
|
* Each SDK stores a {@link PaginatedTrait} on its operations (sourced from the
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* {@link PaginationStrategy}; these shared utilities handle the streaming.
|
|
15
15
|
* Ported from the distilled repo's `core/pagination`.
|
|
16
16
|
*/
|
|
17
|
+
import type * as Arr from "effect/Array";
|
|
17
18
|
import * as Effect from "effect/Effect";
|
|
18
19
|
import * as Stream from "effect/Stream";
|
|
19
20
|
|
|
@@ -39,8 +40,8 @@ export const getPath = (obj: unknown, path: string): unknown => {
|
|
|
39
40
|
* cursors/tokens), every segment here fans out over whatever the previous one
|
|
40
41
|
* produced, so a path may cross a list:
|
|
41
42
|
*
|
|
42
|
-
* - `"items"` on `{ items: [a, b] }`
|
|
43
|
-
* - `"edges.node"` on a Relay connection
|
|
43
|
+
* - `"items"` on `{ items: [a, b] }` -> `[a, b]` (the common flat case)
|
|
44
|
+
* - `"edges.node"` on a Relay connection -> every edge's `node`
|
|
44
45
|
*
|
|
45
46
|
* `null`/`undefined` links are dropped rather than propagated, so a partially
|
|
46
47
|
* null page yields the items it does have instead of nothing.
|
|
@@ -52,8 +53,9 @@ export const getItems = (obj: unknown, path: string): readonly unknown[] => {
|
|
|
52
53
|
for (const value of current) {
|
|
53
54
|
if (value == null || typeof value !== "object") continue;
|
|
54
55
|
const child = (value as Record<string, unknown>)[part];
|
|
55
|
-
if (Array.isArray(child))
|
|
56
|
-
|
|
56
|
+
if (Array.isArray(child)) {
|
|
57
|
+
for (const item of child) next.push(item);
|
|
58
|
+
} else if (child != null) next.push(child);
|
|
57
59
|
}
|
|
58
60
|
current = next;
|
|
59
61
|
}
|
|
@@ -74,7 +76,7 @@ export interface PaginatedTrait {
|
|
|
74
76
|
readonly outputToken?: string;
|
|
75
77
|
/**
|
|
76
78
|
* The path to the output member containing the paginated items. Segments
|
|
77
|
-
* may cross arrays
|
|
79
|
+
* may cross arrays -- `"edges.node"` walks every edge and collects its
|
|
78
80
|
* `node` (see {@link getItems}).
|
|
79
81
|
*/
|
|
80
82
|
readonly items?: string;
|
|
@@ -84,7 +86,7 @@ export interface PaginatedTrait {
|
|
|
84
86
|
* Relay extension: the path to the boolean that says whether another page
|
|
85
87
|
* exists (`"pageInfo.hasNextPage"`). Relay connections keep returning the
|
|
86
88
|
* last page's `endCursor` after the end, so the cursor alone can't
|
|
87
|
-
* terminate traversal
|
|
89
|
+
* terminate traversal -- see {@link paginateRelay}.
|
|
88
90
|
*/
|
|
89
91
|
readonly hasNextPage?: string;
|
|
90
92
|
}
|
|
@@ -102,7 +104,7 @@ const missingPaginationConfig = (kind: string) => Stream.die(new Error(kind));
|
|
|
102
104
|
* means "no more pages".
|
|
103
105
|
*
|
|
104
106
|
* APIs mark the terminal page by omitting the output token, returning it
|
|
105
|
-
* as `null`, or
|
|
107
|
+
* as `null`, or -- for several services (e.g. SSM, CloudWatch Logs) -- as an
|
|
106
108
|
* empty string. Treating `""` as a live token re-requests the first page
|
|
107
109
|
* forever (or fails with a ValidationException). Object tokens (e.g.
|
|
108
110
|
* DynamoDB's `LastEvaluatedKey`) are always truthy and unaffected.
|
|
@@ -112,10 +114,11 @@ export const isTerminalToken = (token: unknown): boolean =>
|
|
|
112
114
|
|
|
113
115
|
/**
|
|
114
116
|
* Stream for single-shot list endpoints that still expose the paginated
|
|
115
|
-
* surface
|
|
117
|
+
* surface -- emits exactly one page.
|
|
116
118
|
*/
|
|
117
119
|
export const paginateSingle: PaginationStrategy = (operation, input) =>
|
|
118
|
-
Stream.
|
|
120
|
+
// `Stream.fromEffect` keeps `mapEffect`'s concurrency machinery out of bundles.
|
|
121
|
+
Stream.fromEffect(Effect.suspend(() => operation(input)));
|
|
119
122
|
|
|
120
123
|
// ============================================================================
|
|
121
124
|
// Page-based Pagination
|
|
@@ -175,7 +178,7 @@ export const paginatePageNumber = <Input extends Record<string, unknown>, Output
|
|
|
175
178
|
// ============================================================================
|
|
176
179
|
|
|
177
180
|
/**
|
|
178
|
-
* Stream of pages using cursor-based pagination
|
|
181
|
+
* Stream of pages using cursor-based pagination -- follow `outputToken`
|
|
179
182
|
* cursors until one comes back absent or repeats a previously requested cursor.
|
|
180
183
|
* Empty pages still advance when they return a new cursor.
|
|
181
184
|
*/
|
|
@@ -227,7 +230,7 @@ export const paginateCursor = <Input extends Record<string, unknown>, Output, E,
|
|
|
227
230
|
// ============================================================================
|
|
228
231
|
|
|
229
232
|
/**
|
|
230
|
-
* Stream of pages using token-based pagination
|
|
233
|
+
* Stream of pages using token-based pagination -- pass `outputToken` back as
|
|
231
234
|
* `inputToken` until it comes back absent.
|
|
232
235
|
*/
|
|
233
236
|
export const paginateToken = <Input extends Record<string, unknown>, Output, E, R>(
|
|
@@ -269,7 +272,7 @@ export const paginateToken = <Input extends Record<string, unknown>, Output, E,
|
|
|
269
272
|
// ============================================================================
|
|
270
273
|
|
|
271
274
|
/**
|
|
272
|
-
* Stream of pages over a Relay connection
|
|
275
|
+
* Stream of pages over a Relay connection -- pass `pageInfo.endCursor` back as
|
|
273
276
|
* `after` for as long as `pageInfo.hasNextPage` is true.
|
|
274
277
|
*
|
|
275
278
|
* Relay is cursor pagination with one twist that breaks
|
|
@@ -290,7 +293,7 @@ export const paginateRelay = <Input extends Record<string, unknown>, Output, E,
|
|
|
290
293
|
if (!inputToken || !outputToken) {
|
|
291
294
|
return missingPaginationConfig("Relay pagination requires inputToken and outputToken");
|
|
292
295
|
}
|
|
293
|
-
// `pageInfo.endCursor`
|
|
296
|
+
// `pageInfo.endCursor` -> `pageInfo.hasNextPage` when the trait doesn't say.
|
|
294
297
|
const hasNextPath =
|
|
295
298
|
pagination.hasNextPage ??
|
|
296
299
|
`${outputToken.split(".").slice(0, -1).concat("hasNextPage").join(".")}`;
|
|
@@ -313,7 +316,7 @@ export const paginateRelay = <Input extends Record<string, unknown>, Output, E,
|
|
|
313
316
|
const nextCursor = getPath(response, outputToken) as string | null | undefined;
|
|
314
317
|
const hasNext = getPath(response, hasNextPath) === true;
|
|
315
318
|
// An empty page means the connection is exhausted regardless of what
|
|
316
|
-
// `hasNextPage` claims
|
|
319
|
+
// `hasNextPage` claims -- re-requesting the same cursor would loop.
|
|
317
320
|
const emptyPage =
|
|
318
321
|
pagination.items !== undefined && getItems(response, pagination.items).length === 0;
|
|
319
322
|
// A connection that keeps returning the same `endCursor` with
|
|
@@ -373,6 +376,22 @@ export const extractItems = <Output, Item, E, R>(
|
|
|
373
376
|
pages: Stream.Stream<Output, E, R>,
|
|
374
377
|
itemsPath: string,
|
|
375
378
|
): Stream.Stream<Item, E, R> =>
|
|
376
|
-
pages
|
|
377
|
-
|
|
378
|
-
)
|
|
379
|
+
// Flattens each pulled chunk of pages directly, skipping pages with no
|
|
380
|
+
// items. `Stream.flatMap` / `flattenIterable` would do the same but pull in
|
|
381
|
+
// Effect's concurrent-merge machinery (Queue, Semaphore, ...): about 5 KB
|
|
382
|
+
// gzip in every bundle that uses a paginated operation.
|
|
383
|
+
Stream.transformPull(pages, (pull) => {
|
|
384
|
+
// Same error channel as `pull` (its `Done` included), so the stream ends where the pages end.
|
|
385
|
+
const next: Effect.Effect<Arr.NonEmptyReadonlyArray<Item>, unknown> = Effect.flatMap(
|
|
386
|
+
pull,
|
|
387
|
+
(chunk) => {
|
|
388
|
+
const items: Item[] = [];
|
|
389
|
+
for (const page of chunk)
|
|
390
|
+
for (const item of getItems(page, itemsPath)) items.push(item as Item);
|
|
391
|
+
return items.length > 0
|
|
392
|
+
? Effect.succeed(items as unknown as Arr.NonEmptyReadonlyArray<Item>)
|
|
393
|
+
: next;
|
|
394
|
+
},
|
|
395
|
+
);
|
|
396
|
+
return Effect.succeed(next);
|
|
397
|
+
}) as unknown as Stream.Stream<Item, E, R>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for walking plain request values. This module imports only
|
|
3
|
+
* `effect/Redacted`, so the GraphQL client can use it without loading the
|
|
4
|
+
* REST and HTTP protocol modules.
|
|
5
|
+
*/
|
|
6
|
+
import * as Redacted from "effect/Redacted";
|
|
7
|
+
|
|
8
|
+
/** Binary/opaque values that must never be treated as key-value objects. */
|
|
9
|
+
export const isOpaqueValue = (v: unknown): boolean =>
|
|
10
|
+
v instanceof Blob ||
|
|
11
|
+
v instanceof File ||
|
|
12
|
+
v instanceof ArrayBuffer ||
|
|
13
|
+
v instanceof Uint8Array ||
|
|
14
|
+
v instanceof Date;
|
|
15
|
+
|
|
16
|
+
const isPlainObject = (v: unknown): v is Record<string, unknown> =>
|
|
17
|
+
v !== null &&
|
|
18
|
+
typeof v === "object" &&
|
|
19
|
+
!Array.isArray(v) &&
|
|
20
|
+
!isOpaqueValue(v) &&
|
|
21
|
+
(Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Deep-unwrap `Redacted` values in an input (plain objects/arrays only --
|
|
25
|
+
* class instances, files, and binary payloads pass through untouched).
|
|
26
|
+
* Sensitive input members accept `string | Redacted<string>`; the wire wants
|
|
27
|
+
* the raw string.
|
|
28
|
+
*/
|
|
29
|
+
export const unwrapRedactedDeep = (value: unknown): unknown => {
|
|
30
|
+
if (Redacted.isRedacted(value)) return Redacted.value(value);
|
|
31
|
+
if (Array.isArray(value)) return value.map(unwrapRedactedDeep);
|
|
32
|
+
if (isPlainObject(value)) {
|
|
33
|
+
const out: Record<string, unknown> = {};
|
|
34
|
+
for (const [k, v] of Object.entries(value)) {
|
|
35
|
+
if (v === undefined) continue;
|
|
36
|
+
out[k] = unwrapRedactedDeep(v);
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
};
|