@distilled.cloud/core 1.0.0-rc.17 → 1.0.0-rc.19
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/base.js +2 -2
- package/lib/_bundle/base.js.map +1 -1
- package/lib/_bundle/graphql.js +2 -2
- package/lib/_bundle/graphql.js.map +1 -1
- package/lib/_bundle/grpc.js +2 -0
- package/lib/_bundle/grpc.js.map +1 -0
- package/lib/_bundle/rest.js +1 -1
- package/lib/_bundle/rest.js.map +1 -1
- package/lib/_bundle/xml.js +1 -1
- package/lib/_bundle/xml.js.map +1 -1
- 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 +52 -1
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +1 -1
- package/lib/category.d.ts.map +1 -1
- package/lib/config.d.ts +54 -13
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/errors.d.ts +3 -13
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -1
- package/lib/graphql.d.ts +26 -5
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.types.d.ts.map +1 -1
- 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 +76 -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 +6 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -0
- package/lib/pagination.d.ts +55 -3
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +1 -1
- package/lib/protobuf.d.ts +92 -0
- package/lib/protobuf.d.ts.map +1 -0
- package/lib/protobuf.js +1 -0
- package/lib/protocol-grpc.d.ts +86 -0
- package/lib/protocol-grpc.d.ts.map +1 -0
- package/lib/protocol-grpc.js +1 -0
- package/lib/protocol-http.d.ts +38 -9
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +1 -1
- package/lib/protocol-rest.d.ts +60 -42
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +1 -1
- package/lib/response-validation.d.ts +5 -4
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/schema-lite-typed.js +1 -2
- package/lib/sdk-error.d.ts +27 -0
- package/lib/sdk-error.d.ts.map +1 -0
- package/lib/sdk-error.js +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 +288 -0
- package/lib/telemetry.d.ts.map +1 -0
- package/lib/telemetry.js +3 -0
- package/lib/telemetry.js.map +1 -0
- package/lib/trait.d.ts +7 -0
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/package.json +3 -5
- package/src/annotations.ts +53 -0
- package/src/api.ts +316 -43
- package/src/category.ts +21 -22
- package/src/config.ts +58 -29
- package/src/error-category.ts +12 -14
- package/src/errors.ts +11 -7
- package/src/graphql.ts +191 -63
- package/src/graphql.types.ts +5 -1
- package/src/grpc-transport-cloudflare-http2.ts +494 -0
- package/src/grpc-transport-cloudflare-sockets.ts +299 -0
- package/src/grpc-transport-node-http2.ts +234 -0
- package/src/grpc-transport.ts +118 -0
- package/src/hpack.ts +331 -0
- package/src/index.ts +6 -2
- package/src/pagination.ts +193 -8
- package/src/protobuf.ts +1332 -0
- package/src/protocol-grpc.ts +641 -0
- package/src/protocol-http.ts +87 -67
- package/src/protocol-rest.ts +183 -191
- package/src/response-validation.ts +8 -5
- package/src/sdk-error.ts +33 -0
- package/src/sensitive.ts +154 -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 +832 -0
- package/src/trait.ts +10 -0
- package/src/xml.ts +10 -1
- package/lib/codegen/boolean-string-enums.d.ts +0 -36
- package/lib/codegen/boolean-string-enums.d.ts.map +0 -1
- package/lib/codegen/boolean-string-enums.js +0 -147
- package/lib/codegen/boolean-string-enums.js.map +0 -1
- package/lib/codegen/chunk.d.ts +0 -7
- package/lib/codegen/chunk.d.ts.map +0 -1
- package/lib/codegen/chunk.js +0 -139
- package/lib/codegen/chunk.js.map +0 -1
- package/lib/codegen/cli.d.ts +0 -80
- package/lib/codegen/cli.d.ts.map +0 -1
- package/lib/codegen/cli.js +0 -166
- package/lib/codegen/cli.js.map +0 -1
- package/lib/codegen/datafy.d.ts +0 -14
- package/lib/codegen/datafy.d.ts.map +0 -1
- package/lib/codegen/datafy.js +0 -853
- package/lib/codegen/datafy.js.map +0 -1
- package/lib/codegen/dedupe.d.ts +0 -5
- package/lib/codegen/dedupe.d.ts.map +0 -1
- package/lib/codegen/dedupe.js +0 -153
- package/lib/codegen/dedupe.js.map +0 -1
- package/lib/codegen/emit.d.ts +0 -125
- package/lib/codegen/emit.d.ts.map +0 -1
- package/lib/codegen/emit.js +0 -99
- package/lib/codegen/emit.js.map +0 -1
- package/lib/codegen/format.d.ts +0 -11
- package/lib/codegen/format.d.ts.map +0 -1
- package/lib/codegen/format.js +0 -32
- package/lib/codegen/format.js.map +0 -1
- package/lib/codegen/generated-at.d.ts +0 -29
- package/lib/codegen/generated-at.d.ts.map +0 -1
- package/lib/codegen/generated-at.js +0 -78
- package/lib/codegen/generated-at.js.map +0 -1
- package/lib/codegen/generator.d.ts +0 -353
- package/lib/codegen/generator.d.ts.map +0 -1
- package/lib/codegen/generator.js +0 -810
- package/lib/codegen/generator.js.map +0 -1
- package/lib/codegen/graph.d.ts +0 -36
- package/lib/codegen/graph.d.ts.map +0 -1
- package/lib/codegen/graph.js +0 -136
- package/lib/codegen/graph.js.map +0 -1
- package/lib/codegen/graphql-client.d.ts +0 -70
- package/lib/codegen/graphql-client.d.ts.map +0 -1
- package/lib/codegen/graphql-client.js +0 -439
- package/lib/codegen/graphql-client.js.map +0 -1
- package/lib/codegen/graphql.d.ts +0 -207
- package/lib/codegen/graphql.d.ts.map +0 -1
- package/lib/codegen/graphql.js +0 -786
- package/lib/codegen/graphql.js.map +0 -1
- package/lib/codegen/latin1.d.ts +0 -3
- package/lib/codegen/latin1.d.ts.map +0 -1
- package/lib/codegen/latin1.js +0 -126
- package/lib/codegen/latin1.js.map +0 -1
- package/lib/codegen/members.d.ts +0 -32
- package/lib/codegen/members.d.ts.map +0 -1
- package/lib/codegen/members.js +0 -62
- package/lib/codegen/members.js.map +0 -1
- package/lib/codegen/model-diff.d.ts +0 -10
- package/lib/codegen/model-diff.d.ts.map +0 -1
- package/lib/codegen/model-diff.js +0 -67
- package/lib/codegen/model-diff.js.map +0 -1
- package/lib/codegen/naming.d.ts +0 -29
- package/lib/codegen/naming.d.ts.map +0 -1
- package/lib/codegen/naming.js +0 -74
- package/lib/codegen/naming.js.map +0 -1
- package/lib/codegen/openapi-cli.d.ts +0 -52
- package/lib/codegen/openapi-cli.d.ts.map +0 -1
- package/lib/codegen/openapi-cli.js +0 -84
- package/lib/codegen/openapi-cli.js.map +0 -1
- package/lib/codegen/openapi.d.ts +0 -209
- package/lib/codegen/openapi.d.ts.map +0 -1
- package/lib/codegen/openapi.js +0 -1548
- package/lib/codegen/openapi.js.map +0 -1
- package/lib/codegen/operations.d.ts +0 -24
- package/lib/codegen/operations.d.ts.map +0 -1
- package/lib/codegen/operations.js +0 -56
- package/lib/codegen/operations.js.map +0 -1
- package/lib/codegen/pagination.d.ts +0 -39
- package/lib/codegen/pagination.d.ts.map +0 -1
- package/lib/codegen/pagination.js +0 -31
- package/lib/codegen/pagination.js.map +0 -1
- package/lib/codegen/patch-audit.d.ts +0 -84
- package/lib/codegen/patch-audit.d.ts.map +0 -1
- package/lib/codegen/patch-audit.js +0 -366
- package/lib/codegen/patch-audit.js.map +0 -1
- package/lib/codegen/patches.d.ts +0 -129
- package/lib/codegen/patches.d.ts.map +0 -1
- package/lib/codegen/patches.js +0 -472
- package/lib/codegen/patches.js.map +0 -1
- package/lib/codegen/prelude.d.ts +0 -15
- package/lib/codegen/prelude.d.ts.map +0 -1
- package/lib/codegen/prelude.js +0 -60
- package/lib/codegen/prelude.js.map +0 -1
- package/lib/codegen/privatize.d.ts +0 -21
- package/lib/codegen/privatize.d.ts.map +0 -1
- package/lib/codegen/privatize.js +0 -176
- package/lib/codegen/privatize.js.map +0 -1
- package/lib/codegen/proto.d.ts +0 -121
- package/lib/codegen/proto.d.ts.map +0 -1
- package/lib/codegen/proto.js +0 -960
- package/lib/codegen/proto.js.map +0 -1
- package/lib/codegen/pure.d.ts +0 -6
- package/lib/codegen/pure.d.ts.map +0 -1
- package/lib/codegen/pure.js +0 -91
- package/lib/codegen/pure.js.map +0 -1
- package/lib/codegen/rewrite-operation-ids.d.ts +0 -154
- package/lib/codegen/rewrite-operation-ids.d.ts.map +0 -1
- package/lib/codegen/rewrite-operation-ids.js +0 -1117
- package/lib/codegen/rewrite-operation-ids.js.map +0 -1
- package/lib/codegen/spec-path.d.ts +0 -16
- package/lib/codegen/spec-path.d.ts.map +0 -1
- package/lib/codegen/spec-path.js +0 -101
- package/lib/codegen/spec-path.js.map +0 -1
- package/lib/codegen/table.d.ts +0 -5
- package/lib/codegen/table.d.ts.map +0 -1
- package/lib/codegen/table.js +0 -249
- package/lib/codegen/table.js.map +0 -1
- package/lib/debug.d.ts +0 -2
- package/lib/debug.d.ts.map +0 -1
- package/lib/debug.js +0 -1
- package/lib/json-patch.d.ts +0 -58
- package/lib/json-patch.d.ts.map +0 -1
- package/lib/json-patch.js +0 -2
- package/lib/json-patch.js.map +0 -1
- package/lib/schema-lite-typed.js.map +0 -1
- package/lib/testing.d.ts +0 -40
- package/lib/testing.d.ts.map +0 -1
- package/lib/testing.js +0 -2
- package/lib/testing.js.map +0 -1
- package/src/codegen/boolean-string-enums.ts +0 -155
- package/src/codegen/chunk.ts +0 -147
- package/src/codegen/cli.ts +0 -293
- package/src/codegen/datafy.ts +0 -874
- package/src/codegen/dedupe.ts +0 -173
- package/src/codegen/emit.ts +0 -200
- package/src/codegen/format.ts +0 -49
- package/src/codegen/generated-at.ts +0 -88
- package/src/codegen/generator.ts +0 -1229
- package/src/codegen/graph.ts +0 -151
- package/src/codegen/graphql-client.ts +0 -545
- package/src/codegen/graphql.ts +0 -1145
- package/src/codegen/latin1.ts +0 -131
- package/src/codegen/members.ts +0 -79
- package/src/codegen/model-diff.ts +0 -67
- package/src/codegen/naming.ts +0 -85
- package/src/codegen/openapi-cli.ts +0 -141
- package/src/codegen/openapi.ts +0 -1845
- package/src/codegen/operations.ts +0 -73
- package/src/codegen/pagination.ts +0 -64
- package/src/codegen/patch-audit.ts +0 -480
- package/src/codegen/patches.ts +0 -581
- package/src/codegen/prelude.ts +0 -70
- package/src/codegen/privatize.ts +0 -200
- package/src/codegen/proto.ts +0 -1092
- package/src/codegen/pure.ts +0 -94
- package/src/codegen/rewrite-operation-ids.ts +0 -1219
- package/src/codegen/spec-path.ts +0 -112
- package/src/codegen/table.ts +0 -254
- package/src/debug.ts +0 -8
- package/src/json-patch.ts +0 -273
- package/src/testing.ts +0 -74
package/src/config.ts
CHANGED
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
* - Otherwise the value comes from `process.env`, which is what Effect's
|
|
14
14
|
* default provider reads.
|
|
15
15
|
*
|
|
16
|
-
* A missing variable fails with {@link
|
|
17
|
-
*
|
|
16
|
+
* A missing variable fails with {@link ConfigError} (with its `key`), which `withDefault`, `option` and `orElse` handle. A provided
|
|
17
|
+
* `ConfigProvider` that cannot read its source fails with its `SourceError`,
|
|
18
|
+
* which those helpers pass through.
|
|
18
19
|
*
|
|
19
20
|
* Credentials read these on every request, so without a provider a whole
|
|
20
21
|
* reader tree (`all`, `withDefault`, `orElse`, ...) runs as one synchronous
|
|
@@ -23,25 +24,30 @@
|
|
|
23
24
|
* A missing value inside the tree is a plain marker; the tagged error is
|
|
24
25
|
* only built if the whole tree fails.
|
|
25
26
|
*/
|
|
27
|
+
import type { SourceError } from "effect/ConfigProvider";
|
|
26
28
|
import * as Context from "effect/Context";
|
|
27
|
-
import * as Data from "effect/Data";
|
|
28
29
|
import * as Effect from "effect/Effect";
|
|
29
30
|
import * as Option from "effect/Option";
|
|
30
31
|
import * as Redact from "effect/Redacted";
|
|
32
|
+
import * as Category from "./category.ts";
|
|
33
|
+
import * as Schema from "./schema-lite-typed.ts";
|
|
31
34
|
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Configuration error - missing or invalid configuration. `key` is the
|
|
37
|
+
* configuration value (e.g. an environment variable) when one is missing.
|
|
38
|
+
*/
|
|
39
|
+
export class ConfigError
|
|
40
|
+
extends /*@__PURE__*/ Schema.TaggedError<ConfigError>()("ConfigError", {
|
|
41
|
+
message: Schema.String,
|
|
42
|
+
key: /*@__PURE__*/ Schema.optional(Schema.String),
|
|
43
|
+
}).pipe(Category.withConfigurationError) {}
|
|
38
44
|
|
|
39
45
|
const CONFIG_PROVIDER_KEY = "effect/ConfigProvider";
|
|
40
46
|
|
|
41
47
|
interface ProvidedConfigProvider {
|
|
42
48
|
readonly load: (
|
|
43
49
|
path: ReadonlyArray<string>,
|
|
44
|
-
) => Effect.Effect<{ readonly _tag: string; readonly value?: string } | undefined,
|
|
50
|
+
) => Effect.Effect<{ readonly _tag: string; readonly value?: string } | undefined, SourceError>;
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
const fromEnv = (name: string): string | undefined =>
|
|
@@ -81,7 +87,7 @@ const hasProvider = (context: Context.Context<never>): boolean =>
|
|
|
81
87
|
Context.getOrUndefined(context, providerKey) !== undefined;
|
|
82
88
|
|
|
83
89
|
const missingError = (m: Missing) =>
|
|
84
|
-
new
|
|
90
|
+
new ConfigError({ key: m.name, message: `Expected ${m.name} to be set` });
|
|
85
91
|
|
|
86
92
|
const fromReader = <A>(reader: Reader<A>): Effect.Effect<A, any, any> => {
|
|
87
93
|
const effect = Effect.withFiber((fiber) => {
|
|
@@ -94,41 +100,62 @@ const fromReader = <A>(reader: Reader<A>): Effect.Effect<A, any, any> => {
|
|
|
94
100
|
return effect;
|
|
95
101
|
};
|
|
96
102
|
|
|
97
|
-
/**
|
|
98
|
-
|
|
103
|
+
/**
|
|
104
|
+
* The raw value of `name` from the provided `ConfigProvider`, or undefined
|
|
105
|
+
* when unset. A provider that cannot read its source fails with `SourceError`.
|
|
106
|
+
*/
|
|
107
|
+
const lookup = (name: string): Effect.Effect<string | undefined, SourceError> =>
|
|
99
108
|
Effect.flatMap(Effect.context<never>(), (context) => {
|
|
100
109
|
const provider = context.mapUnsafe.get(CONFIG_PROVIDER_KEY) as
|
|
101
110
|
| ProvidedConfigProvider
|
|
102
111
|
| undefined;
|
|
103
112
|
if (!provider) return Effect.succeed(fromEnv(name));
|
|
104
|
-
return provider.load([name])
|
|
105
|
-
|
|
106
|
-
Effect.orElseSucceed(() => undefined),
|
|
113
|
+
return Effect.map(provider.load([name]), (node) =>
|
|
114
|
+
node?._tag === "Value" ? node.value : undefined,
|
|
107
115
|
);
|
|
108
116
|
});
|
|
109
117
|
|
|
110
|
-
const required = (name: string): Effect.Effect<string,
|
|
118
|
+
const required = (name: string): Effect.Effect<string, ConfigError | SourceError> =>
|
|
111
119
|
fromReader({
|
|
112
120
|
read: () => fromEnv(name) ?? new Missing(name),
|
|
113
121
|
viaEffect: () =>
|
|
114
122
|
Effect.flatMap(lookup(name), (value) =>
|
|
115
123
|
value === undefined ? Effect.fail(missingError(new Missing(name))) : Effect.succeed(value),
|
|
116
124
|
),
|
|
117
|
-
}) as Effect.Effect<string,
|
|
125
|
+
}) as Effect.Effect<string, ConfigError | SourceError>;
|
|
118
126
|
|
|
119
127
|
/** The string value of environment variable `name`. */
|
|
120
|
-
export const String = (name: string): Effect.Effect<string,
|
|
128
|
+
export const String = (name: string): Effect.Effect<string, ConfigError | SourceError> =>
|
|
129
|
+
required(name);
|
|
121
130
|
|
|
122
131
|
/** The value of `name`, redacted. */
|
|
123
|
-
export const Redacted = (
|
|
132
|
+
export const Redacted = (
|
|
133
|
+
name: string,
|
|
134
|
+
): Effect.Effect<Redact.Redacted<string>, ConfigError | SourceError> =>
|
|
124
135
|
map((value: string) => Redact.make(value))(required(name));
|
|
125
136
|
|
|
137
|
+
/**
|
|
138
|
+
* The failure of a missing value: {@link ConfigError}, matched by its tag
|
|
139
|
+
* (Effect's own config errors share it). `option`, `withDefault` and `orElse` handle
|
|
140
|
+
* only this failure; any other failure of `self` propagates.
|
|
141
|
+
*/
|
|
142
|
+
type Missed = { readonly _tag: "ConfigError" };
|
|
143
|
+
|
|
144
|
+
const isMissed = (error: unknown): boolean =>
|
|
145
|
+
typeof error === "object" && error !== null && (error as Missed)._tag === "ConfigError";
|
|
146
|
+
|
|
147
|
+
const catchMissed = <A, E, R, A2, E2, R2>(
|
|
148
|
+
self: Effect.Effect<A, E, R>,
|
|
149
|
+
f: () => Effect.Effect<A2, E2, R2>,
|
|
150
|
+
): Effect.Effect<A | A2, Exclude<E, Missed> | E2, R | R2> =>
|
|
151
|
+
Effect.catchIf(self, isMissed, f) as Effect.Effect<A | A2, Exclude<E, Missed> | E2, R | R2>;
|
|
152
|
+
|
|
126
153
|
/** The value as an `Option`: `None` when missing. */
|
|
127
154
|
export const option = <A, E, R>(
|
|
128
155
|
self: Effect.Effect<A, E, R>,
|
|
129
|
-
): Effect.Effect<Option.Option<A>,
|
|
156
|
+
): Effect.Effect<Option.Option<A>, Exclude<E, Missed>, R> => {
|
|
130
157
|
const viaEffect = () =>
|
|
131
|
-
|
|
158
|
+
catchMissed(Effect.map(self, Option.some), () => Effect.succeed(Option.none<A>()));
|
|
132
159
|
const reader = readerOf(self);
|
|
133
160
|
if (!reader) return viaEffect();
|
|
134
161
|
return fromReader({
|
|
@@ -138,14 +165,14 @@ export const option = <A, E, R>(
|
|
|
138
165
|
return value instanceof Missing ? Option.none<A>() : Option.some(value);
|
|
139
166
|
},
|
|
140
167
|
viaEffect,
|
|
141
|
-
}) as Effect.Effect<Option.Option<A>,
|
|
168
|
+
}) as Effect.Effect<Option.Option<A>, Exclude<E, Missed>, R>;
|
|
142
169
|
};
|
|
143
170
|
|
|
144
171
|
/** Use `value` when missing. */
|
|
145
172
|
export const withDefault =
|
|
146
173
|
<B>(value: B) =>
|
|
147
|
-
<A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A | B,
|
|
148
|
-
const viaEffect = () =>
|
|
174
|
+
<A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A | B, Exclude<E, Missed>, R> => {
|
|
175
|
+
const viaEffect = () => catchMissed(self, () => Effect.succeed(value));
|
|
149
176
|
const reader = readerOf(self);
|
|
150
177
|
if (!reader) return viaEffect();
|
|
151
178
|
return fromReader<A | B>({
|
|
@@ -154,14 +181,16 @@ export const withDefault =
|
|
|
154
181
|
return v instanceof Missing ? value : v;
|
|
155
182
|
},
|
|
156
183
|
viaEffect,
|
|
157
|
-
}) as Effect.Effect<A | B,
|
|
184
|
+
}) as Effect.Effect<A | B, Exclude<E, Missed>, R>;
|
|
158
185
|
};
|
|
159
186
|
|
|
160
187
|
/** Try `that` when missing. */
|
|
161
188
|
export const orElse =
|
|
162
189
|
<A2, E2, R2>(that: () => Effect.Effect<A2, E2, R2>) =>
|
|
163
|
-
<A, E, R>(
|
|
164
|
-
|
|
190
|
+
<A, E, R>(
|
|
191
|
+
self: Effect.Effect<A, E, R>,
|
|
192
|
+
): Effect.Effect<A | A2, Exclude<E, Missed> | E2, R | R2> => {
|
|
193
|
+
const viaEffect = () => catchMissed(self, that);
|
|
165
194
|
const reader = readerOf(self);
|
|
166
195
|
if (!reader) return viaEffect();
|
|
167
196
|
return fromReader<A | A2>({
|
|
@@ -172,7 +201,7 @@ export const orElse =
|
|
|
172
201
|
return fallback ? fallback.read() : DEFER;
|
|
173
202
|
},
|
|
174
203
|
viaEffect,
|
|
175
|
-
}) as Effect.Effect<A | A2, E2, R | R2>;
|
|
204
|
+
}) as Effect.Effect<A | A2, Exclude<E, Missed> | E2, R | R2>;
|
|
176
205
|
};
|
|
177
206
|
|
|
178
207
|
export const map =
|
package/src/error-category.ts
CHANGED
|
@@ -56,18 +56,16 @@ export const hasAnyCategory =
|
|
|
56
56
|
return false;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
export const catchCategory =
|
|
60
|
-
<E,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
]
|
|
65
|
-
) =>
|
|
66
|
-
|
|
59
|
+
export const catchCategory = <E, const Categories extends Array<AllKeys<E>>, A2, E2, R2>(
|
|
60
|
+
...args: [...Categories, f: (err: ExtractAll<E, Categories[number]>) => Effect.Effect<A2, E2, R2>]
|
|
61
|
+
) => {
|
|
62
|
+
// Split once, without mutating `args`, so one catcher can be reused.
|
|
63
|
+
const f = args[args.length - 1] as (
|
|
64
|
+
err: ExtractAll<E, Categories[number]>,
|
|
65
|
+
) => Effect.Effect<A2, E2, R2>;
|
|
66
|
+
const matches = hasAnyCategory(...(args.slice(0, -1) as Array<PropertyKey>));
|
|
67
|
+
return <A, R>(
|
|
67
68
|
effect: Effect.Effect<A, E, R>,
|
|
68
|
-
): Effect.Effect<A | A2, E2 | Exclude<E, ExtractAll<E, Categories[number]>>, R | R2> =>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const matches = hasAnyCategory(...categories);
|
|
72
|
-
return Effect.catchIf(effect, matches, (e) => f(e as ExtractAll<E, Categories[number]>)) as any;
|
|
73
|
-
};
|
|
69
|
+
): Effect.Effect<A | A2, E2 | Exclude<E, ExtractAll<E, Categories[number]>>, R | R2> =>
|
|
70
|
+
Effect.catchIf(effect, matches, (e) => f(e as ExtractAll<E, Categories[number]>)) as any;
|
|
71
|
+
};
|
package/src/errors.ts
CHANGED
|
@@ -139,13 +139,17 @@ export class GatewayTimeout
|
|
|
139
139
|
retryAfter: /*@__PURE__*/ Schema.optional(DurationSchema),
|
|
140
140
|
}).pipe(Category.withServerError, /*@__PURE__*/ Category.withRetryable()) {}
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
142
|
+
// Defined with the config readers (core's `base` bundle group, which every
|
|
143
|
+
// program loads) so they can fail with it without importing this module.
|
|
144
|
+
export { ConfigError } from "./config.ts";
|
|
145
|
+
|
|
146
|
+
// Defined with the label check (`protocol-http.ts`), so protocols can fail
|
|
147
|
+
// with it without importing every class in this module.
|
|
148
|
+
export { InvalidInput } from "./protocol-http.ts";
|
|
149
|
+
|
|
150
|
+
// Defined in the `base` bundle group (`sdk-error.ts`), with pagination and
|
|
151
|
+
// the operation runtime that fail with it.
|
|
152
|
+
export { SdkError } from "./sdk-error.ts";
|
|
149
153
|
|
|
150
154
|
// ============================================================================
|
|
151
155
|
// Error Maps
|
package/src/graphql.ts
CHANGED
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
* {@link GqlTransport.execute} posts `{ query, variables, operationName }`.
|
|
45
45
|
* The Effect it returns may require Credentials / HttpClient; those leak
|
|
46
46
|
* into `Query.fn`'s requirements. It returns the parsed `data` and raw
|
|
47
|
-
* `errors`; `Query.fn` classifies the errors (see "Errors" below).
|
|
48
|
-
*
|
|
47
|
+
* `errors`; `Query.fn` classifies the errors (see "Errors" below). A plan
|
|
48
|
+
* that can't be compiled fails with {@link GqlError}.
|
|
49
49
|
*
|
|
50
50
|
* Generated SDKs export *roots* (`Railway.me`, `Railway.project`).
|
|
51
51
|
* Combinators live in `@distilled.cloud/core/query`.
|
|
@@ -59,19 +59,34 @@ import * as Schedule from "effect/Schedule";
|
|
|
59
59
|
import * as S from "effect/Schema";
|
|
60
60
|
import * as Stream from "effect/Stream";
|
|
61
61
|
import { unwrapRedactedDeep } from "./plain-values.ts";
|
|
62
|
+
import * as Telemetry from "./telemetry.ts";
|
|
62
63
|
|
|
63
64
|
export const QuerySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/graphql/Query");
|
|
64
65
|
const inspect = /*@__PURE__*/ Symbol.for("nodejs.util.inspect.custom");
|
|
65
66
|
|
|
66
|
-
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
/**
|
|
68
|
+
* A plan that cannot be compiled (a programming error in the query). The
|
|
69
|
+
* compiler throws it; `Query.fn`, `Query.pages` and `Query.items` fail with
|
|
70
|
+
* it (see {@link compiling}).
|
|
71
|
+
*/
|
|
72
|
+
export class GqlError
|
|
73
|
+
extends /*@__PURE__*/ Data.TaggedError("GqlError")<{
|
|
74
|
+
readonly message: string;
|
|
75
|
+
}>
|
|
76
|
+
{
|
|
70
77
|
constructor(message: string) {
|
|
71
|
-
|
|
78
|
+
super({ message });
|
|
72
79
|
}
|
|
73
80
|
}
|
|
74
81
|
|
|
82
|
+
/** `f()`, with what the compiler throws failed as a {@link GqlError}. */
|
|
83
|
+
const compiling = <A>(f: () => A): Effect.Effect<A, GqlError> =>
|
|
84
|
+
Effect.try({
|
|
85
|
+
try: f,
|
|
86
|
+
catch: (e) =>
|
|
87
|
+
e instanceof GqlError ? e : new GqlError(e instanceof Error ? e.message : String(e)),
|
|
88
|
+
});
|
|
89
|
+
|
|
75
90
|
// U+2500U+2500 Errors U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500U+2500
|
|
76
91
|
//
|
|
77
92
|
// Every entry of a GraphQL `errors` array becomes one typed issue. Generated
|
|
@@ -304,6 +319,20 @@ export interface CompiledOperation {
|
|
|
304
319
|
readonly tree: SelNode;
|
|
305
320
|
}
|
|
306
321
|
|
|
322
|
+
/**
|
|
323
|
+
* What a GraphQL SDK's document spans carry, generated from its GraphQL
|
|
324
|
+
* model's `telemetry` entry (see `packages/dev/src/codegen/telemetry-traits.md`).
|
|
325
|
+
* One span per document: `<prefix>.<rootField>`, or `<prefix>.<kind>` when
|
|
326
|
+
* the document selects several root fields.
|
|
327
|
+
*/
|
|
328
|
+
export interface GraphQLTelemetry extends Telemetry.ServiceTelemetry {
|
|
329
|
+
readonly prefix: string;
|
|
330
|
+
/** `<kind>.<rootField>`, then argument name, then the attributes read from its value. */
|
|
331
|
+
readonly fields?: Readonly<
|
|
332
|
+
Record<string, Readonly<Record<string, ReadonlyArray<Telemetry.AttributeRule>>>>
|
|
333
|
+
>;
|
|
334
|
+
}
|
|
335
|
+
|
|
307
336
|
export class GqlTransport
|
|
308
337
|
extends /*@__PURE__*/ Context.Service<
|
|
309
338
|
GqlTransport,
|
|
@@ -311,6 +340,8 @@ export class GqlTransport
|
|
|
311
340
|
readonly execute: (
|
|
312
341
|
req: CompiledOperation,
|
|
313
342
|
) => Effect.Effect<GraphQLResponse, GraphQLTransportError, any>;
|
|
343
|
+
/** The SDK's span facts; no spans without it. */
|
|
344
|
+
readonly telemetry?: GraphQLTelemetry;
|
|
314
345
|
}
|
|
315
346
|
>()("@distilled.cloud/graphql/Transport") {}
|
|
316
347
|
|
|
@@ -378,7 +409,8 @@ export type QueryError<Error> =
|
|
|
378
409
|
| Error
|
|
379
410
|
| GraphQLFailure<Extract<Error, GraphQLIssue> | UnknownGraphQLError>
|
|
380
411
|
| UnknownGraphQLError
|
|
381
|
-
| GraphQLTransportError
|
|
412
|
+
| GraphQLTransportError
|
|
413
|
+
| GqlError;
|
|
382
414
|
|
|
383
415
|
type Expr =
|
|
384
416
|
| RootExpr
|
|
@@ -1195,13 +1227,15 @@ const interpretPlan = (
|
|
|
1195
1227
|
if (isQuery(plan)) {
|
|
1196
1228
|
const expr = (plan as QueryNode).expr;
|
|
1197
1229
|
if (expr._tag === "FlatMap") {
|
|
1198
|
-
const resolved =
|
|
1230
|
+
const resolved = yield* compiling(() =>
|
|
1231
|
+
interpretExpr(expr.parent, data, rootAlias, undefined),
|
|
1232
|
+
);
|
|
1199
1233
|
const next = expr.flatMapFn(resolved);
|
|
1200
1234
|
if (Effect.isEffect(next)) return yield* next;
|
|
1201
1235
|
if (isQuery(next)) return yield* interpretPlan(next, data, rootAlias);
|
|
1202
1236
|
return next;
|
|
1203
1237
|
}
|
|
1204
|
-
return interpretExpr(expr, data, rootAlias, undefined);
|
|
1238
|
+
return yield* compiling(() => interpretExpr(expr, data, rootAlias, undefined));
|
|
1205
1239
|
}
|
|
1206
1240
|
if (Effect.isEffect(plan)) return yield* plan;
|
|
1207
1241
|
if (plan !== null && typeof plan === "object" && !Array.isArray(plan)) {
|
|
@@ -1223,11 +1257,13 @@ const evaluatePlan = <Plan>(
|
|
|
1223
1257
|
): Effect.Effect<UnwrapPlan<Plan>, QueryError<PlanError<Plan>>, GqlTransport> =>
|
|
1224
1258
|
Effect.gen(function* () {
|
|
1225
1259
|
const forest = emptyForest();
|
|
1226
|
-
|
|
1260
|
+
const compiled = yield* compiling(() => {
|
|
1261
|
+
visitPlan(plan, forest);
|
|
1262
|
+
return forest.roots.children.size > 0 ? emit(forest) : undefined;
|
|
1263
|
+
});
|
|
1227
1264
|
let data: unknown = {};
|
|
1228
1265
|
let rootAlias: WeakMap<object, string> = new WeakMap();
|
|
1229
|
-
if (
|
|
1230
|
-
const compiled = emit(forest);
|
|
1266
|
+
if (compiled !== undefined) {
|
|
1231
1267
|
log("document\n" + compiled.document);
|
|
1232
1268
|
data = yield* execute(compiled);
|
|
1233
1269
|
rootAlias = compiled.rootAlias;
|
|
@@ -1246,7 +1282,18 @@ const execute = (compiled: Compiled): Effect.Effect<unknown, ExecuteError, GqlTr
|
|
|
1246
1282
|
const response = yield* transport.execute(compiled);
|
|
1247
1283
|
const data = redactSelected(compiled.tree, response.data);
|
|
1248
1284
|
const raw = response.errors ?? [];
|
|
1249
|
-
if (raw.length === 0)
|
|
1285
|
+
if (raw.length === 0) {
|
|
1286
|
+
// Without errors, a GraphQL response must carry a `data` object.
|
|
1287
|
+
if (!isRecord(response.data)) {
|
|
1288
|
+
return yield* Effect.fail(
|
|
1289
|
+
new GraphQLTransportError({
|
|
1290
|
+
message: "GraphQL response has no data object and no errors",
|
|
1291
|
+
status: response.status,
|
|
1292
|
+
}),
|
|
1293
|
+
);
|
|
1294
|
+
}
|
|
1295
|
+
return data;
|
|
1296
|
+
}
|
|
1250
1297
|
const issues = raw.map((error) => classify(compiled, error, response));
|
|
1251
1298
|
const [first, ...rest] = issues as [GraphQLIssue, ...GraphQLIssue[]];
|
|
1252
1299
|
return yield* Effect.fail(
|
|
@@ -1259,15 +1306,71 @@ const execute = (compiled: Compiled): Effect.Effect<unknown, ExecuteError, GqlTr
|
|
|
1259
1306
|
}),
|
|
1260
1307
|
);
|
|
1261
1308
|
});
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1309
|
+
const attempts = Effect.withFiber((fiber) => {
|
|
1310
|
+
if (compiled.kind !== "query") return once;
|
|
1311
|
+
const context = fiber.context as Context.Context<any>;
|
|
1312
|
+
let retries = 0;
|
|
1313
|
+
return once.pipe(
|
|
1314
|
+
Effect.retry({
|
|
1315
|
+
while: (error) => {
|
|
1316
|
+
const retry = isRetryable(compiled, error) && retries < 5;
|
|
1317
|
+
// Schedule.exponential("200 millis"): 200 ms, then doubling.
|
|
1318
|
+
if (retry) Telemetry.retried(context, ++retries, error, 200 * 2 ** (retries - 1));
|
|
1319
|
+
return retry;
|
|
1320
|
+
},
|
|
1321
|
+
times: 5,
|
|
1322
|
+
schedule: Schedule.exponential("200 millis"),
|
|
1323
|
+
}),
|
|
1324
|
+
);
|
|
1325
|
+
});
|
|
1326
|
+
return Effect.withFiber((fiber) => {
|
|
1327
|
+
const debug = fiber.getRef(Telemetry.Debug);
|
|
1328
|
+
const telemetry = Context.getOrUndefined(fiber.context, GqlTransport)?.telemetry;
|
|
1329
|
+
if (telemetry === undefined) return attempts;
|
|
1330
|
+
const [info, input] = documentInfo(telemetry, compiled);
|
|
1331
|
+
return Telemetry.operationSpan(fiber, debug, info, undefined, input, () => attempts);
|
|
1332
|
+
}) as Effect.Effect<unknown, ExecuteError, GqlTransport>;
|
|
1333
|
+
};
|
|
1334
|
+
|
|
1335
|
+
/**
|
|
1336
|
+
* One document's span facts: its root fields name it, and their arguments
|
|
1337
|
+
* fill the attributes the SDK's `fields` rules name (an input object keyed
|
|
1338
|
+
* `<kind>.<field>.<argument>`).
|
|
1339
|
+
*/
|
|
1340
|
+
const documentInfo = (
|
|
1341
|
+
telemetry: GraphQLTelemetry,
|
|
1342
|
+
compiled: Compiled,
|
|
1343
|
+
): readonly [Telemetry.OperationInfo, Record<string, unknown>] => {
|
|
1344
|
+
const roots = [...new Set([...compiled.tree.children.values()].map((node) => node.field))];
|
|
1345
|
+
const single = roots.length === 1 ? roots[0] : undefined;
|
|
1346
|
+
const target = single ?? compiled.kind;
|
|
1347
|
+
const input: Record<string, unknown> = {};
|
|
1348
|
+
const rules: Record<string, ReadonlyArray<Telemetry.AttributeRule>> = {};
|
|
1349
|
+
for (const node of compiled.tree.children.values()) {
|
|
1350
|
+
const fieldRules = telemetry.fields?.[`${compiled.kind}.${node.field}`];
|
|
1351
|
+
if (fieldRules === undefined || node.args === undefined) continue;
|
|
1352
|
+
for (const arg in node.args) {
|
|
1353
|
+
const argRules = fieldRules[arg];
|
|
1354
|
+
if (argRules === undefined) continue;
|
|
1355
|
+
const key = `${compiled.kind}.${node.field}.${arg}`;
|
|
1356
|
+
input[key] = compiled.variables[node.args[arg]!];
|
|
1357
|
+
rules[key] = argRules;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
const info = Telemetry.operationInfo(
|
|
1361
|
+
telemetry,
|
|
1362
|
+
{
|
|
1363
|
+
name: `${telemetry.prefix}.${target}`,
|
|
1364
|
+
method: `${telemetry.prefix}/${target}`,
|
|
1365
|
+
attributes: {
|
|
1366
|
+
"graphql.operation.type": compiled.kind,
|
|
1367
|
+
...(single !== undefined ? { "graphql.operation.name": single } : {}),
|
|
1368
|
+
},
|
|
1369
|
+
input: rules,
|
|
1370
|
+
},
|
|
1371
|
+
undefined,
|
|
1372
|
+
);
|
|
1373
|
+
return [info, input];
|
|
1271
1374
|
};
|
|
1272
1375
|
|
|
1273
1376
|
type ExecuteError = GraphQLIssue | GraphQLFailure | GraphQLTransportError;
|
|
@@ -1294,13 +1397,34 @@ const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
|
1294
1397
|
* declares (or the global errors for a path-less error). A tie between
|
|
1295
1398
|
* different tags is ambiguous and stays {@link UnknownGraphQLError}.
|
|
1296
1399
|
*/
|
|
1297
|
-
const classify = (
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1400
|
+
const classify = (compiled: Compiled, entry: unknown, response: GraphQLResponse): GraphQLIssue => {
|
|
1401
|
+
// The entry comes from the wire: anything that is not an object (`null`,
|
|
1402
|
+
// a bare string) is read as an error with only a message.
|
|
1403
|
+
const raw: Partial<RawGraphQLError> = isRecord(entry)
|
|
1404
|
+
? (entry as Partial<RawGraphQLError>)
|
|
1405
|
+
: {
|
|
1406
|
+
message:
|
|
1407
|
+
typeof entry === "string"
|
|
1408
|
+
? entry
|
|
1409
|
+
: `malformed GraphQL error entry (${entry === null ? "null" : typeof entry})`,
|
|
1410
|
+
};
|
|
1411
|
+
const rawPath = Array.isArray(raw.path) ? (raw.path as ReadonlyArray<unknown>) : undefined;
|
|
1412
|
+
const root = typeof rawPath?.[0] === "string" ? compiled.rootErrors.get(rawPath[0]) : undefined;
|
|
1413
|
+
// The error classes validate `path` and `locations`, so a malformed value
|
|
1414
|
+
// is left out instead of making the constructor throw.
|
|
1415
|
+
const path = rawPath?.every((key) => typeof key === "string" || typeof key === "number")
|
|
1416
|
+
? (rawPath as ReadonlyArray<string | number>)
|
|
1417
|
+
: undefined;
|
|
1418
|
+
const locations =
|
|
1419
|
+
Array.isArray(raw.locations) &&
|
|
1420
|
+
raw.locations.every(
|
|
1421
|
+
(location: unknown) =>
|
|
1422
|
+
isRecord(location) &&
|
|
1423
|
+
typeof location.line === "number" &&
|
|
1424
|
+
typeof location.column === "number",
|
|
1425
|
+
)
|
|
1426
|
+
? raw.locations
|
|
1427
|
+
: undefined;
|
|
1304
1428
|
const candidates = root
|
|
1305
1429
|
? root.errors
|
|
1306
1430
|
: uniqueByTag(
|
|
@@ -1321,7 +1445,7 @@ const classify = (
|
|
|
1321
1445
|
message,
|
|
1322
1446
|
code,
|
|
1323
1447
|
path,
|
|
1324
|
-
locations
|
|
1448
|
+
locations,
|
|
1325
1449
|
extensions: raw.extensions,
|
|
1326
1450
|
traceId:
|
|
1327
1451
|
typeof extensions.traceId === "string"
|
|
@@ -1573,15 +1697,17 @@ const fetchPage = <Item>(
|
|
|
1573
1697
|
state: PageState,
|
|
1574
1698
|
) =>
|
|
1575
1699
|
Effect.gen(function* () {
|
|
1576
|
-
const pageExpr =
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1700
|
+
const { pageExpr, connectionPath, compiled } = yield* compiling(() => {
|
|
1701
|
+
const pageExpr = withCursor(query.expr, connection, state.after);
|
|
1702
|
+
const forest = emptyForest();
|
|
1703
|
+
visitExpr(forest, pageExpr);
|
|
1704
|
+
const nodePath = paintAbs(forest, withCursor(connection, connection, state.after));
|
|
1705
|
+
const connectionPath = nodePath.slice(0, -2);
|
|
1706
|
+
const pageInfo = ensureChild(forest, selAt(forest.roots, connectionPath), "pageInfo", {});
|
|
1707
|
+
ensureChild(forest, pageInfo, "hasNextPage", { isScalar: true });
|
|
1708
|
+
ensureChild(forest, pageInfo, "endCursor", { isScalar: true });
|
|
1709
|
+
return { pageExpr, connectionPath, compiled: emit(forest) };
|
|
1710
|
+
});
|
|
1585
1711
|
log("page\n" + compiled.document);
|
|
1586
1712
|
const data = yield* execute(compiled);
|
|
1587
1713
|
const items = (yield* interpretPlan(make(pageExpr), data, compiled.rootAlias)) as
|
|
@@ -1618,29 +1744,31 @@ export const pagesQuery = <Item, Error>(
|
|
|
1618
1744
|
query: QueryNode<ReadonlyArray<Item> | null, Error>,
|
|
1619
1745
|
): Stream.Stream<ReadonlyArray<Item>, QueryError<Error> | GraphQLPaginationError, GqlTransport> =>
|
|
1620
1746
|
Stream.unwrap(
|
|
1621
|
-
Effect.
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1747
|
+
Effect.map(
|
|
1748
|
+
compiling(() => connectionOf(query.expr)),
|
|
1749
|
+
(connection) => {
|
|
1750
|
+
const after = connection.args?.after;
|
|
1751
|
+
return Stream.paginate<
|
|
1752
|
+
PageState,
|
|
1753
|
+
ReadonlyArray<Item>,
|
|
1754
|
+
QueryError<Error> | GraphQLPaginationError,
|
|
1755
|
+
GqlTransport
|
|
1756
|
+
>(
|
|
1757
|
+
{
|
|
1758
|
+
after: typeof after === "string" ? after : undefined,
|
|
1759
|
+
seen: new Set(),
|
|
1760
|
+
},
|
|
1761
|
+
(state) =>
|
|
1762
|
+
fetchPage(query, connection, state).pipe(
|
|
1763
|
+
Effect.map(([items, next]) => [[items], next] as const),
|
|
1764
|
+
) as Effect.Effect<
|
|
1765
|
+
readonly [ReadonlyArray<ReadonlyArray<Item>>, Option.Option<PageState>],
|
|
1766
|
+
QueryError<Error> | GraphQLPaginationError,
|
|
1767
|
+
GqlTransport
|
|
1768
|
+
>,
|
|
1769
|
+
);
|
|
1770
|
+
},
|
|
1771
|
+
),
|
|
1644
1772
|
);
|
|
1645
1773
|
|
|
1646
1774
|
/** Every node of a Relay connection, across all pages. */
|
package/src/graphql.types.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type * as Stream from "effect/Stream";
|
|
|
3
3
|
import { mapQuery } from "./graphql.ts";
|
|
4
4
|
import type {
|
|
5
5
|
itemsQuery,
|
|
6
|
+
GqlError,
|
|
6
7
|
GraphQLFailure,
|
|
7
8
|
GraphQLTransportError,
|
|
8
9
|
UnknownGraphQLError,
|
|
@@ -58,7 +59,10 @@ type _QueryError = Assert<
|
|
|
58
59
|
Equal<
|
|
59
60
|
Exclude<
|
|
60
61
|
QueryError<NotFound>,
|
|
61
|
-
GraphQLFailure<NotFound | UnknownGraphQLError>
|
|
62
|
+
| GraphQLFailure<NotFound | UnknownGraphQLError>
|
|
63
|
+
| UnknownGraphQLError
|
|
64
|
+
| GraphQLTransportError
|
|
65
|
+
| GqlError
|
|
62
66
|
>,
|
|
63
67
|
NotFound
|
|
64
68
|
>
|