@distilled.cloud/core 1.0.0-rc.2 → 1.0.0-rc.21
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/LICENSE +201 -0
- package/README.md +33 -0
- 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/grpc.js +3 -0
- package/lib/_bundle/grpc.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 +17 -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 +220 -51
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +1 -178
- package/lib/category.d.ts +19 -16
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +1 -280
- package/lib/chunks.d.ts +3 -0
- package/lib/chunks.d.ts.map +1 -0
- package/lib/chunks.js +1 -0
- package/lib/config.d.ts +81 -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/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 +99 -74
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -186
- package/lib/graphql.d.ts +420 -0
- package/lib/graphql.d.ts.map +1 -0
- package/lib/graphql.js +1 -0
- package/lib/graphql.types.d.ts +11 -0
- package/lib/graphql.types.d.ts.map +1 -0
- package/lib/graphql.types.js +1 -0
- package/lib/grpc-transport-cloudflare-http2.d.ts +7 -0
- package/lib/grpc-transport-cloudflare-http2.d.ts.map +1 -0
- package/lib/grpc-transport-cloudflare-http2.js +6 -0
- package/lib/grpc-transport-cloudflare-http2.js.map +1 -0
- package/lib/grpc-transport-cloudflare-sockets.d.ts +7 -0
- package/lib/grpc-transport-cloudflare-sockets.d.ts.map +1 -0
- package/lib/grpc-transport-cloudflare-sockets.js +5 -0
- package/lib/grpc-transport-cloudflare-sockets.js.map +1 -0
- package/lib/grpc-transport-node-http2.d.ts +19 -0
- package/lib/grpc-transport-node-http2.d.ts.map +1 -0
- package/lib/grpc-transport-node-http2.js +2 -0
- package/lib/grpc-transport-node-http2.js.map +1 -0
- package/lib/grpc-transport.d.ts +111 -0
- package/lib/grpc-transport.d.ts.map +1 -0
- package/lib/grpc-transport.js +1 -0
- package/lib/hpack.d.ts +34 -0
- package/lib/hpack.d.ts.map +1 -0
- package/lib/hpack.js +2 -0
- package/lib/hpack.js.map +1 -0
- package/lib/index.d.ts +32 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +17 -0
- package/lib/max-message-bytes.d.ts +42 -0
- package/lib/max-message-bytes.d.ts.map +1 -0
- package/lib/max-message-bytes.js +2 -0
- package/lib/max-message-bytes.js.map +1 -0
- package/lib/ndjson.d.ts +3 -0
- package/lib/ndjson.d.ts.map +1 -0
- package/lib/ndjson.js +2 -0
- package/lib/ndjson.js.map +1 -0
- package/lib/pagination.d.ts +105 -25
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +1 -182
- package/lib/plain-values.d.ts +21 -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/protobuf.d.ts +85 -0
- package/lib/protobuf.d.ts.map +1 -0
- package/lib/protobuf.js +1 -0
- package/lib/protocol-grpc.d.ts +123 -0
- package/lib/protocol-grpc.d.ts.map +1 -0
- package/lib/protocol-grpc.js +1 -0
- package/lib/protocol-http.d.ts +206 -25
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +1 -554
- package/lib/protocol-rest.d.ts +258 -64
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +1 -242
- package/lib/protocol.d.ts +113 -0
- package/lib/protocol.d.ts.map +1 -0
- package/lib/protocol.js +0 -0
- package/lib/query.d.ts +29 -0
- package/lib/query.d.ts.map +1 -0
- package/lib/query.js +1 -0
- 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 +86 -0
- package/lib/response-validation.d.ts.map +1 -0
- package/lib/response-validation.js +1 -0
- package/lib/retry-after.d.ts +4 -4
- package/lib/retry-after.d.ts.map +1 -1
- package/lib/retry-after.js +1 -112
- package/lib/retry-state.d.ts +26 -0
- package/lib/retry-state.d.ts.map +1 -0
- package/lib/retry-state.js +2 -0
- package/lib/retry-state.js.map +1 -0
- package/lib/retry.d.ts +141 -42
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -210
- package/lib/schema-lite-impl.d.ts +179 -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 +1 -0
- package/lib/schema-lite.d.ts +41 -0
- package/lib/schema-lite.d.ts.map +1 -0
- package/lib/schema-lite.js +1 -0
- package/lib/schema.d.ts +21 -7
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +1 -48
- package/lib/sdk-error.d.ts +31 -0
- package/lib/sdk-error.d.ts.map +1 -0
- package/lib/sdk-error.js +1 -0
- package/lib/send.d.ts +37 -0
- package/lib/send.d.ts.map +1 -0
- package/lib/send.js +2 -0
- package/lib/send.js.map +1 -0
- package/lib/sensitive.d.ts +28 -0
- package/lib/sensitive.d.ts.map +1 -0
- package/lib/sensitive.js +2 -0
- package/lib/sensitive.js.map +1 -0
- package/lib/telemetry-debug.d.ts +6 -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 +11 -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 +317 -0
- package/lib/telemetry.d.ts.map +1 -0
- package/lib/telemetry.js +3 -0
- package/lib/telemetry.js.map +1 -0
- package/lib/token-cache.d.ts +31 -0
- package/lib/token-cache.d.ts.map +1 -0
- package/lib/token-cache.js +2 -0
- package/lib/token-cache.js.map +1 -0
- package/lib/trait.d.ts +94 -20
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +1 -107
- package/lib/unknown-error.d.ts +18 -0
- package/lib/unknown-error.d.ts.map +1 -0
- package/lib/unknown-error.js +1 -0
- package/lib/xml.d.ts +44 -0
- package/lib/xml.d.ts.map +1 -0
- package/lib/xml.js +1 -0
- package/package.json +13 -13
- package/src/annotations.ts +53 -0
- package/src/api.ts +1597 -234
- package/src/category.ts +97 -134
- package/src/chunks.ts +30 -0
- package/src/config.ts +261 -0
- package/src/crypto.ts +202 -0
- package/src/error-category.ts +16 -29
- package/src/errors.ts +99 -77
- package/src/graphql.ts +1817 -0
- package/src/graphql.types.ts +120 -0
- package/src/grpc-transport-cloudflare-http2.ts +569 -0
- package/src/grpc-transport-cloudflare-sockets.ts +368 -0
- package/src/grpc-transport-node-http2.ts +307 -0
- package/src/grpc-transport.ts +287 -0
- package/src/hpack.ts +331 -0
- package/src/index.ts +31 -0
- package/src/max-message-bytes.ts +58 -0
- package/src/ndjson.ts +55 -0
- package/src/pagination.ts +379 -94
- package/src/plain-values.ts +70 -0
- package/src/protobuf.ts +1367 -0
- package/src/protocol-grpc.ts +811 -0
- package/src/protocol-http.ts +1045 -371
- package/src/protocol-rest.ts +908 -255
- package/src/protocol.ts +150 -0
- package/src/query.ts +39 -0
- package/src/response-validation-strict.ts +333 -0
- package/src/response-validation.ts +161 -0
- package/src/retry-after.ts +8 -14
- package/src/retry-state.ts +105 -0
- package/src/retry.ts +260 -145
- package/src/schema-lite-impl.ts +621 -0
- package/src/schema-lite-typed.ts +44 -0
- package/src/schema-lite.ts +45 -0
- package/src/schema.ts +259 -15
- package/src/sdk-error.ts +37 -0
- package/src/send.ts +156 -0
- package/src/sensitive.ts +188 -0
- package/src/telemetry-debug.ts +179 -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 +100 -0
- package/src/telemetry-xray.ts +66 -0
- package/src/telemetry.ts +800 -0
- package/src/token-cache.ts +117 -0
- package/src/trait.ts +139 -67
- package/src/unknown-error.ts +38 -0
- package/src/xml.ts +346 -0
- package/lib/api.js.map +0 -1
- package/lib/category.js.map +0 -1
- package/lib/codegen/cli.d.ts +0 -29
- package/lib/codegen/cli.d.ts.map +0 -1
- package/lib/codegen/cli.js +0 -165
- package/lib/codegen/cli.js.map +0 -1
- package/lib/codegen/emit.d.ts +0 -129
- package/lib/codegen/emit.d.ts.map +0 -1
- package/lib/codegen/emit.js +0 -105
- package/lib/codegen/emit.js.map +0 -1
- package/lib/codegen/format.d.ts +0 -23
- package/lib/codegen/format.d.ts.map +0 -1
- package/lib/codegen/format.js +0 -28
- package/lib/codegen/format.js.map +0 -1
- package/lib/codegen/generator.d.ts +0 -334
- package/lib/codegen/generator.d.ts.map +0 -1
- package/lib/codegen/generator.js +0 -691
- 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/members.d.ts +0 -25
- package/lib/codegen/members.d.ts.map +0 -1
- package/lib/codegen/members.js +0 -55
- package/lib/codegen/members.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 -38
- package/lib/codegen/openapi-cli.d.ts.map +0 -1
- package/lib/codegen/openapi-cli.js +0 -107
- package/lib/codegen/openapi-cli.js.map +0 -1
- package/lib/codegen/openapi.d.ts +0 -115
- package/lib/codegen/openapi.d.ts.map +0 -1
- package/lib/codegen/openapi.js +0 -1220
- 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 -33
- package/lib/codegen/pagination.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/error-category.js.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/json-patch.d.ts +0 -44
- package/lib/json-patch.d.ts.map +0 -1
- package/lib/json-patch.js +0 -174
- 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/retry-after.js.map +0 -1
- package/lib/retry.js.map +0 -1
- package/lib/schema.js.map +0 -1
- package/lib/trait.js.map +0 -1
- package/src/codegen/cli.ts +0 -268
- package/src/codegen/emit.ts +0 -207
- package/src/codegen/format.ts +0 -47
- package/src/codegen/generator.ts +0 -1153
- package/src/codegen/graph.ts +0 -151
- package/src/codegen/members.ts +0 -71
- package/src/codegen/naming.ts +0 -86
- package/src/codegen/openapi-cli.ts +0 -166
- package/src/codegen/openapi.ts +0 -1450
- package/src/codegen/operations.ts +0 -76
- package/src/codegen/pagination.ts +0 -71
- package/src/codegen/prelude.ts +0 -70
- package/src/json-patch.ts +0 -222
package/lib/pagination.js
CHANGED
|
@@ -1,182 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Pagination utilities for streaming through paginated API responses.
|
|
3
|
-
*
|
|
4
|
-
* Supports multiple pagination styles:
|
|
5
|
-
* - Page-based: page/per_page with a page number that advances
|
|
6
|
-
* - Cursor-based: cursor/limit with an opaque next-cursor string
|
|
7
|
-
* - Token-based (AWS style): NextToken/MaxResults continuation tokens
|
|
8
|
-
* - Single: one-shot list endpoints that still expose the paginated surface
|
|
9
|
-
*
|
|
10
|
-
* Each SDK stores a {@link PaginatedTrait} on its operations (sourced from the
|
|
11
|
-
* `smithy.api#paginated` trait in its models) and picks a
|
|
12
|
-
* {@link PaginationStrategy}; these shared utilities handle the streaming.
|
|
13
|
-
* Ported from the distilled repo's `core/pagination`.
|
|
14
|
-
*/
|
|
15
|
-
import * as Effect from "effect/Effect";
|
|
16
|
-
import * as Stream from "effect/Stream";
|
|
17
|
-
/**
|
|
18
|
-
* Get a value from an object using a dot-separated path (e.g.
|
|
19
|
-
* `"resultInfo.page"`). Used for pagination traits and nested access.
|
|
20
|
-
*/
|
|
21
|
-
export const getPath = (obj, path) => {
|
|
22
|
-
const parts = path.split(".");
|
|
23
|
-
let current = obj;
|
|
24
|
-
for (const part of parts) {
|
|
25
|
-
if (current == null || typeof current !== "object") {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
current = current[part];
|
|
29
|
-
}
|
|
30
|
-
return current;
|
|
31
|
-
};
|
|
32
|
-
const missingPaginationConfig = (kind) => Stream.die(new Error(kind));
|
|
33
|
-
/**
|
|
34
|
-
* Whether a continuation token/cursor returned by a paginated operation
|
|
35
|
-
* means "no more pages".
|
|
36
|
-
*
|
|
37
|
-
* APIs mark the terminal page by omitting the output token, returning it
|
|
38
|
-
* as `null`, or — for several services (e.g. SSM, CloudWatch Logs) — as an
|
|
39
|
-
* empty string. Treating `""` as a live token re-requests the first page
|
|
40
|
-
* forever (or fails with a ValidationException). Object tokens (e.g.
|
|
41
|
-
* DynamoDB's `LastEvaluatedKey`) are always truthy and unaffected.
|
|
42
|
-
*/
|
|
43
|
-
export const isTerminalToken = (token) => token === undefined || token === null || token === "";
|
|
44
|
-
/**
|
|
45
|
-
* Stream for single-shot list endpoints that still expose the paginated
|
|
46
|
-
* surface — emits exactly one page.
|
|
47
|
-
*/
|
|
48
|
-
export const paginateSingle = (operation, input) => Stream.make(input).pipe(Stream.mapEffect((requestPayload) => operation(requestPayload)));
|
|
49
|
-
// ============================================================================
|
|
50
|
-
// Page-based Pagination
|
|
51
|
-
// ============================================================================
|
|
52
|
-
/**
|
|
53
|
-
* Stream of pages using page-number pagination. The next page is taken from
|
|
54
|
-
* `outputToken` when it advances; otherwise the page number is incremented,
|
|
55
|
-
* terminating when a page comes back with no items (or no token).
|
|
56
|
-
*/
|
|
57
|
-
export const paginatePageNumber = (operation, input, pagination) => {
|
|
58
|
-
const inputToken = pagination.inputToken;
|
|
59
|
-
const outputToken = pagination.outputToken;
|
|
60
|
-
if (!inputToken || !outputToken) {
|
|
61
|
-
return missingPaginationConfig("Page-number pagination requires inputToken and outputToken");
|
|
62
|
-
}
|
|
63
|
-
const startPage = typeof input[inputToken] === "number" ? input[inputToken] : 1;
|
|
64
|
-
return Stream.unfold({ page: startPage, done: false }, (state) => Effect.gen(function* () {
|
|
65
|
-
if (state.done)
|
|
66
|
-
return undefined;
|
|
67
|
-
const requestPayload = { ...input, [inputToken]: state.page };
|
|
68
|
-
const response = yield* operation(requestPayload);
|
|
69
|
-
const nextPage = getPath(response, outputToken);
|
|
70
|
-
// Some APIs report the CURRENT page at `outputToken` rather than the
|
|
71
|
-
// next one (e.g. Cloudflare's `result_info.page`). Taking that value as
|
|
72
|
-
// the next page re-requests the same page forever. Only accept an
|
|
73
|
-
// *advancing* page number; otherwise advance by one and terminate when
|
|
74
|
-
// a page comes back with no items (or the token is absent).
|
|
75
|
-
const items = pagination.items
|
|
76
|
-
? getPath(response, pagination.items)
|
|
77
|
-
: undefined;
|
|
78
|
-
const nextState = {
|
|
79
|
-
page: typeof nextPage === "number" && nextPage > state.page
|
|
80
|
-
? nextPage
|
|
81
|
-
: state.page + 1,
|
|
82
|
-
done: nextPage === null ||
|
|
83
|
-
nextPage === undefined ||
|
|
84
|
-
(items !== undefined && items.length === 0),
|
|
85
|
-
};
|
|
86
|
-
return [response, nextState];
|
|
87
|
-
}));
|
|
88
|
-
};
|
|
89
|
-
// ============================================================================
|
|
90
|
-
// Cursor-based Pagination
|
|
91
|
-
// ============================================================================
|
|
92
|
-
/**
|
|
93
|
-
* Stream of pages using cursor-based pagination — follow `outputToken`
|
|
94
|
-
* cursors until one comes back absent.
|
|
95
|
-
*/
|
|
96
|
-
export const paginateCursor = (operation, input, pagination) => {
|
|
97
|
-
const inputToken = pagination.inputToken;
|
|
98
|
-
const outputToken = pagination.outputToken;
|
|
99
|
-
if (!inputToken || !outputToken) {
|
|
100
|
-
return missingPaginationConfig("Cursor pagination requires inputToken and outputToken");
|
|
101
|
-
}
|
|
102
|
-
const startCursor = typeof input[inputToken] === "string"
|
|
103
|
-
? input[inputToken]
|
|
104
|
-
: undefined;
|
|
105
|
-
return Stream.unfold({ cursor: startCursor, done: false }, (state) => Effect.gen(function* () {
|
|
106
|
-
if (state.done)
|
|
107
|
-
return undefined;
|
|
108
|
-
const requestPayload = {
|
|
109
|
-
...input,
|
|
110
|
-
...(state.cursor ? { [inputToken]: state.cursor } : {}),
|
|
111
|
-
};
|
|
112
|
-
const response = yield* operation(requestPayload);
|
|
113
|
-
const nextCursor = getPath(response, outputToken);
|
|
114
|
-
const nextState = {
|
|
115
|
-
cursor: nextCursor ?? undefined,
|
|
116
|
-
done: isTerminalToken(nextCursor),
|
|
117
|
-
};
|
|
118
|
-
return [response, nextState];
|
|
119
|
-
}));
|
|
120
|
-
};
|
|
121
|
-
// ============================================================================
|
|
122
|
-
// Token-based Pagination (AWS style)
|
|
123
|
-
// ============================================================================
|
|
124
|
-
/**
|
|
125
|
-
* Stream of pages using token-based pagination — pass `outputToken` back as
|
|
126
|
-
* `inputToken` until it comes back absent.
|
|
127
|
-
*/
|
|
128
|
-
export const paginateToken = (operation, input, pagination) => {
|
|
129
|
-
const inputToken = pagination.inputToken;
|
|
130
|
-
const outputToken = pagination.outputToken;
|
|
131
|
-
if (!inputToken || !outputToken) {
|
|
132
|
-
return missingPaginationConfig("Token pagination requires inputToken and outputToken");
|
|
133
|
-
}
|
|
134
|
-
const startToken = input[inputToken];
|
|
135
|
-
return Stream.unfold({ token: startToken, done: false }, (state) => Effect.gen(function* () {
|
|
136
|
-
if (state.done)
|
|
137
|
-
return undefined;
|
|
138
|
-
const requestPayload = state.token !== undefined
|
|
139
|
-
? { ...input, [inputToken]: state.token }
|
|
140
|
-
: input;
|
|
141
|
-
const response = yield* operation(requestPayload);
|
|
142
|
-
const nextToken = getPath(response, outputToken);
|
|
143
|
-
const nextState = {
|
|
144
|
-
token: nextToken,
|
|
145
|
-
done: isTerminalToken(nextToken),
|
|
146
|
-
};
|
|
147
|
-
return [response, nextState];
|
|
148
|
-
}));
|
|
149
|
-
};
|
|
150
|
-
/**
|
|
151
|
-
* Shared default pagination dispatcher for SDKs that use generic
|
|
152
|
-
* token/cursor/page traversal.
|
|
153
|
-
*/
|
|
154
|
-
export const paginateWithDefaults = (operation, input, pagination) => {
|
|
155
|
-
const mode = pagination.mode ?? "token";
|
|
156
|
-
switch (mode) {
|
|
157
|
-
case "page":
|
|
158
|
-
return paginatePageNumber(operation, input, pagination);
|
|
159
|
-
case "cursor":
|
|
160
|
-
return paginateCursor(operation, input, pagination);
|
|
161
|
-
case "single":
|
|
162
|
-
return paginateSingle(operation, input, pagination);
|
|
163
|
-
case "token":
|
|
164
|
-
default:
|
|
165
|
-
return paginateToken(operation, input, pagination);
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
// ============================================================================
|
|
169
|
-
// Item extraction
|
|
170
|
-
// ============================================================================
|
|
171
|
-
/**
|
|
172
|
-
* Extracts individual items from a page stream.
|
|
173
|
-
*
|
|
174
|
-
* @param pages - A stream of page responses
|
|
175
|
-
* @param itemsPath - Dot-separated path to the items array in the page
|
|
176
|
-
* @returns A Stream of individual items
|
|
177
|
-
*/
|
|
178
|
-
export const extractItems = (pages, itemsPath) => pages.pipe(Stream.flatMap((page) => {
|
|
179
|
-
const items = getPath(page, itemsPath);
|
|
180
|
-
return Stream.fromIterable(items ?? []);
|
|
181
|
-
}));
|
|
182
|
-
//# sourceMappingURL=pagination.js.map
|
|
1
|
+
export { pagination$extractArrayItems as extractArrayItems, pagination$extractItems as extractItems, pagination$getItems as getItems, pagination$getPath as getPath, pagination$isTerminalToken as isTerminalToken, pagination$missingPaginationConfig as missingPaginationConfig, pagination$nextLink as nextLink, pagination$paginateCursor as paginateCursor, pagination$paginateKeyset as paginateKeyset, pagination$paginateLink as paginateLink, pagination$paginatePageNumber as paginatePageNumber, pagination$paginateRelay as paginateRelay, pagination$paginateSingle as paginateSingle, pagination$paginateToken as paginateToken, pagination$paginateWithDefaults as paginateWithDefaults, pagination$recordPageHeaders as recordPageHeaders } from "./_bundle/base.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether `v` is an Effect `Stream` (an upload body). Read from the
|
|
3
|
+
* prototype's type id, so this module does not load `effect/Stream`.
|
|
4
|
+
*/
|
|
5
|
+
export declare const isEffectStream: (v: unknown) => boolean;
|
|
6
|
+
/** Binary/opaque values that must never be treated as key-value objects. */
|
|
7
|
+
export declare const isOpaqueValue: (v: unknown) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Sets `out[key] = value` as an own property. A plain assignment to a
|
|
10
|
+
* `__proto__` key replaces the object's prototype; this keeps it a key, as
|
|
11
|
+
* `JSON.parse` does.
|
|
12
|
+
*/
|
|
13
|
+
export declare const setOwnKey: (out: Record<string, unknown>, key: string, value: unknown) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Deep-unwrap `Redacted` values in an input (plain objects/arrays only --
|
|
16
|
+
* class instances, files, and binary payloads pass through untouched).
|
|
17
|
+
* Sensitive input members accept `string | Redacted<string>`; the wire wants
|
|
18
|
+
* the raw string.
|
|
19
|
+
*/
|
|
20
|
+
export declare const unwrapRedactedDeep: (value: unknown) => unknown;
|
|
21
|
+
//# sourceMappingURL=plain-values.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plain-values.d.ts","sources":["../src/plain-values.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,eAAO,MAAM,cAAc,MAAO,OAAO,KAAG,OAIE,CAAC;AAE/C,4EAA4E;AAC5E,eAAO,MAAM,aAAa,MAAO,OAAO,KAAG,OAMxB,CAAC;AASpB;;;;GAIG;AACH,eAAO,MAAM,SAAS,QAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,MAAM,SAAS,OAAO,KAAG,IAWrF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,UAAW,OAAO,KAAG,OAYnD,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import*as e from"effect/Redacted";const isEffectStream=e=>e!==null&&typeof e===`object`&&Object.getPrototypeOf(e)!==null&&`~effect/Stream`in Object.getPrototypeOf(e);const isOpaqueValue=e=>e instanceof Blob||e instanceof File||e instanceof ArrayBuffer||e instanceof Uint8Array||e instanceof Date||isEffectStream(e);const isPlainObject=e=>e!==null&&typeof e===`object`&&!Array.isArray(e)&&!isOpaqueValue(e)&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null);const setOwnKey=(e,t,n)=>{if(t===`__proto__`)Object.defineProperty(e,t,{value:n,enumerable:true,writable:true,configurable:true});else e[t]=n};const unwrapRedactedDeep=t=>{if(e.isRedacted(t))return e.value(t);if(Array.isArray(t))return t.map(unwrapRedactedDeep);if(isPlainObject(t)){const e={};for(const[n,r]of Object.entries(t)){if(r===void 0)continue;e[n]=unwrapRedactedDeep(r)}return e}return t};export{isEffectStream,isOpaqueValue,setOwnKey,unwrapRedactedDeep};
|
|
2
|
+
//# sourceMappingURL=plain-values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plain-values.js","names":["Redacted","v","key","out","value","k"],"sources":["../src/plain-values.ts"],"mappings":"kCAWA,MAAa,eAAkB,GAC7BC,IAAM,MACN,OAAOA,IAAM,UACb,OAAO,eAAeA,CAAC,IAAM,MAC7B,mBAAoB,OAAO,eAAeA,CAAC,EAG7C,MAAa,cAAiB,GAC5BA,aAAa,MACbA,aAAa,MACbA,aAAa,aACbA,aAAa,YACbA,aAAa,MACb,eAAeA,CAAC,EAElB,MAAM,cAAiB,GACrBA,IAAM,MACN,OAAOA,IAAM,UACb,CAAC,MAAM,QAAQA,CAAC,GAChB,CAAC,cAAcA,CAAC,IACf,OAAO,eAAeA,CAAC,IAAM,OAAO,WAAa,OAAO,eAAeA,CAAC,IAAM,MAOjF,MAAa,WAAa,EAA8B,EAAa,IAAyB,CAC5F,GAAIC,IAAQ,YACV,OAAO,eAAeC,EAAKD,EAAK,CAC9B,QACA,WAAY,KACZ,SAAU,KACV,aAAc,IAChB,CAAC,MAED,GAAIA,GAAOE,CAEf,EAQA,MAAa,mBAAsB,GAA4B,CAC7D,GAAIJ,EAAS,WAAWI,CAAK,EAAG,OAAOJ,EAAS,MAAMI,CAAK,EAC3D,GAAI,MAAM,QAAQA,CAAK,EAAG,OAAOA,EAAM,IAAI,kBAAkB,EAC7D,GAAI,cAAcA,CAAK,EAAG,CACxB,MAAMD,EAA+B,CAAC,EACtC,IAAK,KAAM,CAACE,EAAGJ,KAAM,OAAO,QAAQG,CAAK,EAAG,CAC1C,GAAIH,IAAM,IAAA,GAAW,SACrB,EAAII,GAAK,mBAAmBJ,CAAC,CAC/B,CACA,OAAOE,CACT,CACA,OAAOC,CACT"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** A scalar or composite field kind. */
|
|
2
|
+
export type FieldKind = "double" | "float" | "int32" | "int64" | "uint32" | "uint64" | "sint32" | "sint64" | "fixed32" | "fixed64" | "sfixed32" | "sfixed64" | "bool" | "string" | "bytes" | "enum" | "message" | "map";
|
|
3
|
+
/** `[keyKind, valueKind, valueRef?]` for a `map<K, V>` field. */
|
|
4
|
+
export type MapRef = readonly [key: FieldKind, value: FieldKind, ref?: string];
|
|
5
|
+
/**
|
|
6
|
+
* One field: `[number, jsonName, kind, ref?, repeated?, presence?]`. `ref`
|
|
7
|
+
* names the message or enum for `message`/`enum` kinds and is a
|
|
8
|
+
* {@link MapRef} for `map`; `repeated` is `1` for repeated fields. `presence`
|
|
9
|
+
* is set for a field whose absence is observable: `1` for a proto3
|
|
10
|
+
* `optional` field, and `n >= 2` for the members of the message's oneof `n`
|
|
11
|
+
* (setting one member clears the others). Message fields always have
|
|
12
|
+
* presence.
|
|
13
|
+
*/
|
|
14
|
+
export type FieldDescriptor = readonly [
|
|
15
|
+
number: number,
|
|
16
|
+
jsonName: string,
|
|
17
|
+
kind: FieldKind,
|
|
18
|
+
ref?: string | MapRef | 0,
|
|
19
|
+
repeated?: 0 | 1,
|
|
20
|
+
presence?: number
|
|
21
|
+
];
|
|
22
|
+
export interface ProtoDescriptors {
|
|
23
|
+
/** Message full name -> fields. */
|
|
24
|
+
readonly messages: Readonly<Record<string, ReadonlyArray<FieldDescriptor>>>;
|
|
25
|
+
/** Enum full name -> value name -> number. */
|
|
26
|
+
readonly enums: Readonly<Record<string, Readonly<Record<string, number>>>>;
|
|
27
|
+
/**
|
|
28
|
+
* gRPC method path (`/<package>.<Service>/<Method>`) ->
|
|
29
|
+
* `[requestMessage, responseMessage, serverStream?]`. A server-streaming
|
|
30
|
+
* method's JSON output is `{ items: [response, ...] }`.
|
|
31
|
+
*/
|
|
32
|
+
readonly methods: Readonly<Record<string, readonly [request: string, response: string, serverStream?: 0 | 1]>>;
|
|
33
|
+
}
|
|
34
|
+
/** A value the descriptors can't encode (a wrong type for its field). */
|
|
35
|
+
export declare class ProtobufEncodeError extends Error {
|
|
36
|
+
readonly _tag = "ProtobufEncodeError";
|
|
37
|
+
}
|
|
38
|
+
/** Bytes that aren't valid protobuf for the expected message. */
|
|
39
|
+
export declare class ProtobufDecodeError extends Error {
|
|
40
|
+
readonly _tag: string;
|
|
41
|
+
}
|
|
42
|
+
/** A frame whose header announces more bytes than the reader accepts. */
|
|
43
|
+
export declare class FrameTooLargeError extends ProtobufDecodeError {
|
|
44
|
+
readonly _tag: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Valid protobuf whose value proto3 JSON can't represent: a Timestamp
|
|
48
|
+
* outside years 0001 to 9999, or a Duration beyond 10,000 years.
|
|
49
|
+
*/
|
|
50
|
+
export declare class ProtobufJsonRangeError extends ProtobufDecodeError {
|
|
51
|
+
readonly _tag = "ProtobufJsonRangeError";
|
|
52
|
+
}
|
|
53
|
+
/** Encode a proto3 JSON value of message `name` to protobuf bytes. */
|
|
54
|
+
export declare const encodeMessage: (d: ProtoDescriptors, name: string, value: unknown) => Uint8Array;
|
|
55
|
+
/**
|
|
56
|
+
* Decode protobuf bytes of message `name` to a proto3 JSON value. As in any
|
|
57
|
+
* proto3 parser, the last value of a singular field wins, a message field
|
|
58
|
+
* seen more than once is merged, setting a oneof member clears the others,
|
|
59
|
+
* a field whose wire type doesn't match its kind is skipped as unknown, and
|
|
60
|
+
* unknown fields are dropped.
|
|
61
|
+
*/
|
|
62
|
+
export declare const decodeMessage: (d: ProtoDescriptors, name: string, bytes: Uint8Array) => unknown;
|
|
63
|
+
/** One gRPC message frame: `[flag=0][u32 length BE][payload]`. */
|
|
64
|
+
export declare const frame: (payload: Uint8Array) => Uint8Array;
|
|
65
|
+
/**
|
|
66
|
+
* Reads gRPC message frames from a body that arrives in chunks: `push` each
|
|
67
|
+
* chunk and get back the messages it completed. `rest` is the number of
|
|
68
|
+
* bytes held for an incomplete frame (`0` once a body ends cleanly).
|
|
69
|
+
* Compressed frames are rejected. A gRPC-Web trailer frame (flag `0x80`) is
|
|
70
|
+
* not a message: its `name: value` lines are collected in `trailers`.
|
|
71
|
+
*/
|
|
72
|
+
export declare class FrameReader {
|
|
73
|
+
private buf;
|
|
74
|
+
private readonly maxBytes;
|
|
75
|
+
/** `maxBytes`: the largest frame payload accepted; a larger one throws {@link FrameTooLargeError}. */
|
|
76
|
+
constructor(maxBytes?: number);
|
|
77
|
+
/** The trailers of the gRPC-Web trailer frames read so far, names lowercase. */
|
|
78
|
+
readonly trailers: Record<string, string>;
|
|
79
|
+
get rest(): number;
|
|
80
|
+
push(chunk: Uint8Array): Uint8Array[];
|
|
81
|
+
private readTrailers;
|
|
82
|
+
}
|
|
83
|
+
/** Split a whole gRPC body into message payloads. */
|
|
84
|
+
export declare const unframe: (body: Uint8Array) => Uint8Array[];
|
|
85
|
+
//# sourceMappingURL=protobuf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protobuf.d.ts","sources":["../src/protobuf.ts"],"names":[],"mappings":"AAoBA,wCAAwC;AACxC,MAAM,MAAM,SAAS,GACjB,QAAQ,GACR,OAAO,GACP,OAAO,GACP,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,SAAS,GACT,UAAU,GACV,UAAU,GACV,MAAM,GACN,QAAQ,GACR,OAAO,GACP,MAAM,GACN,SAAS,GACT,KAAK,CAAC;AAEV,iEAAiE;AACjE,MAAM,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;AAE/E;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS;IACrC,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE,SAAS;IACf,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC;IACzB,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM;CAClB,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,mCAAmC;IACnC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAC5E,8CAA8C;IAC9C,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3E;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,QAAQ,CACxB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CACnF,CAAC;CACH;AAED,yEAAyE;AACzE,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,yBAAyB;CACvC;AAED,iEAAiE;AACjE,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAyB;CAC/C;AAED,yEAAyE;AACzE,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,SAAkB,IAAI,EAAE,MAAM,CAAwB;CACvD;AAED;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC7D,SAAkB,IAAI,4BAA4B;CACnD;AA2tBD,sEAAsE;AACtE,eAAO,MAAM,aAAa,MAAO,gBAAgB,QAAQ,MAAM,SAAS,OAAO,KAAG,UAOjF,CAAC;AAoUF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,MAAO,gBAAgB,QAAQ,MAAM,SAAS,UAAU,KAAG,OA0EpF,CAAC;AA4CF,kEAAkE;AAClE,eAAO,MAAM,KAAK,YAAa,UAAU,KAAG,UAK3C,CAAC;AAEF;;;;;;GAMG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,GAAG,CAAkD;IAC7D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAElC,sGAAsG;IACtG,YAAY,QAAQ,GAAE,MAAiB,EAEtC;IAED,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IAE/C,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,EAAE,CA8BpC;IAED,OAAO,CAAC,YAAY;CAOrB;AAID,qDAAqD;AACrD,eAAO,MAAM,OAAO,SAAU,UAAU,KAAG,UAAU,EAKpD,CAAC"}
|
package/lib/protobuf.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { protobuf$FrameReader as FrameReader, protobuf$FrameTooLargeError as FrameTooLargeError, protobuf$ProtobufDecodeError as ProtobufDecodeError, protobuf$ProtobufEncodeError as ProtobufEncodeError, protobuf$ProtobufJsonRangeError as ProtobufJsonRangeError, protobuf$decodeMessage as decodeMessage, protobuf$encodeMessage as encodeMessage, protobuf$frame as frame, protobuf$unframe as unframe } from "./_bundle/grpc.js";
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC (binary protobuf) protocol for proto-sourced SDKs.
|
|
3
|
+
*
|
|
4
|
+
* Proto SDKs are generated as REST-shaped operations: each RPC is
|
|
5
|
+
* `POST /<package>.<Service>/<Method>` with a proto3 JSON body. Servers that
|
|
6
|
+
* accept JSON (Connect, grpc-gateway) use {@link restProtocol} directly.
|
|
7
|
+
* Servers that only speak gRPC use this protocol, which builds the request
|
|
8
|
+
* with the REST protocol and speaks gRPC on the wire. `grpcProtocol(options)`
|
|
9
|
+
* builds a core protocol (core/protocol):
|
|
10
|
+
*
|
|
11
|
+
* - **Request**: the proto3 JSON body is transcoded to one protobuf message
|
|
12
|
+
* ({@link encodeMessage}) in one gRPC frame, sent as `application/grpc`.
|
|
13
|
+
* - **Transport**: the call goes through the `HttpClient` the
|
|
14
|
+
* `GrpcTransport` reference holds, or the caller's `HttpClient` when it
|
|
15
|
+
* holds none (see `@distilled.cloud/core/grpc-transport`). Plain `fetch`
|
|
16
|
+
* works where a proxy bridges HTTP/1.1 to gRPC (envoy).
|
|
17
|
+
* - **gRPC-Web**: with `web: true` the request is sent as
|
|
18
|
+
* `application/grpc-web+proto`, which servers such as `tonic-web` answer
|
|
19
|
+
* over HTTP/1.1. The reply's trailers arrive as the last frame of its body,
|
|
20
|
+
* so plain `fetch` sees every status.
|
|
21
|
+
* - **Status**: the call's `grpc-status` is read from the trailers, or from
|
|
22
|
+
* the headers of a trailers-only reply. A transport that can't see
|
|
23
|
+
* trailers (`fetch`) leaves only the headers; a reply with message frames
|
|
24
|
+
* and no status there is treated as OK.
|
|
25
|
+
* - **Errors**: a non-zero status becomes the operation's typed error. The
|
|
26
|
+
* REST decoder receives `{ code, status, message }` (`{ code: 5, status:
|
|
27
|
+
* "NOT_FOUND", ... }`) with the HTTP status grpc-gateway maps the code to
|
|
28
|
+
* (`NOT_FOUND` -> 404, `UNAVAILABLE` -> 503, ...), so error matchers key on
|
|
29
|
+
* the numeric gRPC `code`, and categories and retries follow the HTTP
|
|
30
|
+
* status.
|
|
31
|
+
* - **Response**: protobuf messages are transcoded back to proto3 JSON and
|
|
32
|
+
* decoded by the operation's output schema, so schemas, sensitive values
|
|
33
|
+
* and response validation behave exactly as for REST.
|
|
34
|
+
*
|
|
35
|
+
* A server-streaming method's output is `{ items: [message, ...] }`. Calling
|
|
36
|
+
* the operation collects the whole stream; its `.stream(input)` (see
|
|
37
|
+
* `API.makeStreaming`) emits each message as it arrives, and stopping the
|
|
38
|
+
* stream cancels the call.
|
|
39
|
+
*
|
|
40
|
+
* {@link Deadline} bounds calls in its scope: it is sent as `grpc-timeout`
|
|
41
|
+
* and enforced here, and a call that runs past it fails with
|
|
42
|
+
* `DEADLINE_EXCEEDED` (code 4).
|
|
43
|
+
*/
|
|
44
|
+
import * as Context from "effect/Context";
|
|
45
|
+
import * as Duration from "effect/Duration";
|
|
46
|
+
import { type ProtoDescriptors } from "./protobuf.ts";
|
|
47
|
+
import { type RestProtocolError, type RestProtocolOptions } from "./protocol-rest.ts";
|
|
48
|
+
import type { Protocol } from "./protocol.ts";
|
|
49
|
+
/** gRPC status code -> name. */
|
|
50
|
+
export declare const GRPC_STATUS_NAMES: Readonly<Record<number, string>>;
|
|
51
|
+
/** gRPC status code -> HTTP status (grpc-gateway's mapping). */
|
|
52
|
+
export declare const GRPC_HTTP_STATUS: Readonly<Record<number, number>>;
|
|
53
|
+
/**
|
|
54
|
+
* The deadline of gRPC calls in its scope, from when each call starts.
|
|
55
|
+
* `undefined` (the default) sets none.
|
|
56
|
+
*
|
|
57
|
+
* ```ts
|
|
58
|
+
* router.taskExecWait(input).pipe(Effect.provideService(Deadline, "30 seconds"));
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare const Deadline: Context.Reference<Duration.Input | undefined>;
|
|
62
|
+
/**
|
|
63
|
+
* What this module's own code fails with, whatever the options: the errors
|
|
64
|
+
* every gRPC protocol declares. They are the REST protocol's: a message the
|
|
65
|
+
* descriptors can't encode (`InvalidInput`), a request or reply gRPC can't
|
|
66
|
+
* use (`SdkError`), the transport, a body or its trailers
|
|
67
|
+
* (`HttpClientError`), and a 5xx status that neither the operation nor its
|
|
68
|
+
* service declares (`InternalServerError`).
|
|
69
|
+
*/
|
|
70
|
+
export type GrpcProtocolError = RestProtocolError;
|
|
71
|
+
/**
|
|
72
|
+
* Options of {@link grpcProtocol}: the REST protocol's (see
|
|
73
|
+
* {@link RestProtocolOptions} for the type parameters) and gRPC's own.
|
|
74
|
+
* `StatusError` is what `statusError` returns.
|
|
75
|
+
*/
|
|
76
|
+
export interface GrpcProtocolOptions<Credentials, CredentialsError, CredentialsRequirements, RouteError, ClassifiedError, UnknownError, ParseError, StatusError> extends RestProtocolOptions<Credentials, CredentialsError, CredentialsRequirements, RouteError, ClassifiedError, UnknownError, ParseError> {
|
|
77
|
+
/** The SDK's generated descriptors (`src/descriptors.ts`). */
|
|
78
|
+
readonly descriptors: ProtoDescriptors;
|
|
79
|
+
/**
|
|
80
|
+
* The error for a non-zero status no typed error matched, from its gRPC
|
|
81
|
+
* code. By default the REST decoder classifies it by the HTTP status the
|
|
82
|
+
* code maps to (`UNAVAILABLE` -> `ServiceUnavailable`, which retries), which
|
|
83
|
+
* keeps retries working but merges codes that share a status
|
|
84
|
+
* (`INVALID_ARGUMENT`, `FAILED_PRECONDITION` and `OUT_OF_RANGE` are all
|
|
85
|
+
* `BadRequest`).
|
|
86
|
+
*/
|
|
87
|
+
readonly statusError?: (info: StatusInfo) => StatusError;
|
|
88
|
+
/**
|
|
89
|
+
* Send gRPC-Web (`application/grpc-web+proto`) instead of gRPC, for a
|
|
90
|
+
* server that answers HTTP/1.1 only that way (`tonic-web`). The reply
|
|
91
|
+
* carries its trailers in its body, so `fetch` sees every status.
|
|
92
|
+
*/
|
|
93
|
+
readonly web?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* The largest message the server may send, when neither the call's
|
|
96
|
+
* `maxMessageBytes` nor the `MaxMessageBytes` layer sets one. Default
|
|
97
|
+
* `DEFAULT_MAX_MESSAGE_BYTES` (16 MiB). See `max-message-bytes.ts`.
|
|
98
|
+
*/
|
|
99
|
+
readonly maxMessageBytes?: number;
|
|
100
|
+
}
|
|
101
|
+
/** A non-OK gRPC status, as `statusError` receives it. */
|
|
102
|
+
export interface StatusInfo {
|
|
103
|
+
readonly code: number;
|
|
104
|
+
readonly message: string;
|
|
105
|
+
/** `google.rpc.Status.details` from `grpc-status-details-bin`, as proto3 JSON `Any`s. */
|
|
106
|
+
readonly details: ReadonlyArray<unknown>;
|
|
107
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
108
|
+
}
|
|
109
|
+
/** gRPC's mapping of an HTTP status, for a reply that carries no gRPC status. */
|
|
110
|
+
export declare const HTTP_GRPC_STATUS: Readonly<Record<number, number>>;
|
|
111
|
+
/**
|
|
112
|
+
* The gRPC protocol (core/protocol), over the options of
|
|
113
|
+
* {@link restProtocol}. Assign the result to a module-level const in the
|
|
114
|
+
* provider's `protocol.ts`:
|
|
115
|
+
*
|
|
116
|
+
* export const ModalProtocol = grpcProtocol({ ... });
|
|
117
|
+
*
|
|
118
|
+
* A non-zero status becomes a class the operation or its service declares,
|
|
119
|
+
* as a failed REST response does (see {@link restProtocol}). The protocol
|
|
120
|
+
* declares what the options and {@link GrpcProtocolError} fail with.
|
|
121
|
+
*/
|
|
122
|
+
export declare const grpcProtocol: <Credentials, CredentialsError = never, CredentialsRequirements = never, RouteError = never, ClassifiedError = never, UnknownError = never, ParseError = never, StatusError = never>(options: GrpcProtocolOptions<Credentials, CredentialsError, CredentialsRequirements, RouteError, ClassifiedError, UnknownError, ParseError, StatusError>) => Protocol<CredentialsError | RouteError | ClassifiedError | UnknownError | ParseError | StatusError | GrpcProtocolError, CredentialsRequirements>;
|
|
123
|
+
//# sourceMappingURL=protocol-grpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-grpc.d.ts","sources":["../src/protocol-grpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAU5C,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAKV,QAAQ,EACT,MAAM,eAAe,CAAC;AAIvB,gCAAgC;AAChC,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAkB9D,CAAC;AAEF,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAkB7D,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,+CAGpB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAElD;;;;GAIG;AACH,MAAM,WAAW,mBAAmB,CAClC,WAAW,EACX,gBAAgB,EAChB,uBAAuB,EACvB,UAAU,EACV,eAAe,EACf,YAAY,EACZ,UAAU,EACV,WAAW,CACX,SAAQ,mBAAmB,CAC3B,WAAW,EACX,gBAAgB,EAChB,uBAAuB,EACvB,UAAU,EACV,eAAe,EACf,YAAY,EACZ,UAAU,CACX;IACC,8DAA8D;IAC9D,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC;IACvC;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,WAAW,CAAC;IACzD;;;;OAIG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAED,0DAA0D;AAC1D,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,yFAAyF;IACzF,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACpD;AAED,iFAAiF;AACjF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAS7D,CAAC;AA+iBF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GACvB,WAAW,EACX,gBAAgB,GAAG,KAAK,EACxB,uBAAuB,GAAG,KAAK,EAC/B,UAAU,GAAG,KAAK,EAClB,eAAe,GAAG,KAAK,EACvB,YAAY,GAAG,KAAK,EACpB,UAAU,GAAG,KAAK,EAClB,WAAW,GAAG,KAAK,WAEV,mBAAmB,CAC1B,WAAW,EACX,gBAAgB,EAChB,uBAAuB,EACvB,UAAU,EACV,eAAe,EACf,YAAY,EACZ,UAAU,EACV,WAAW,CACZ,KACA,QAAQ,CACP,gBAAgB,GAChB,UAAU,GACV,eAAe,GACf,YAAY,GACZ,UAAU,GACV,WAAW,GACX,iBAAiB,EACnB,uBAAuB,CAC8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { protocol_grpc$Deadline as Deadline, protocol_grpc$GRPC_HTTP_STATUS as GRPC_HTTP_STATUS, protocol_grpc$GRPC_STATUS_NAMES as GRPC_STATUS_NAMES, protocol_grpc$HTTP_GRPC_STATUS as HTTP_GRPC_STATUS, protocol_grpc$grpcProtocol as grpcProtocol } from "./_bundle/grpc.js";
|