@gjermundgaraba/effect-actions 0.19.0 → 0.21.0
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/README.md +19 -41
- package/dist/Action.d.mts +140 -48
- package/dist/Action.mjs +88 -44
- package/dist/ActionCli.d.mts +70 -35
- package/dist/ActionCli.mjs +53 -34
- package/dist/ActionHttp.d.mts +70 -38
- package/dist/ActionHttp.mjs +76 -25
- package/dist/ActionMcp.d.mts +56 -24
- package/dist/ActionMcp.mjs +104 -61
- package/dist/ActionRpc.d.mts +222 -57
- package/dist/ActionRpc.mjs +301 -49
- package/dist/ActionToolkit.d.mts +22 -7
- package/dist/ActionToolkit.mjs +37 -14
- package/dist/Authentication.d.mts +42 -12
- package/dist/Authentication.mjs +38 -32
- package/dist/Event.d.mts +370 -0
- package/dist/Event.mjs +103 -0
- package/dist/Testing.d.mts +1 -3
- package/dist/Testing.mjs +2 -3
- package/dist/Webhook.d.mts +146 -0
- package/dist/Webhook.mjs +72 -0
- package/dist/authentication/provider.d.mts +35 -12
- package/dist/authentication/provider.mjs +2 -3
- package/dist/authentication/refusal.mjs +3 -4
- package/dist/cli/commands.d.mts +9 -7
- package/dist/cli/commands.mjs +85 -35
- package/dist/contract/ast.mjs +5 -3
- package/dist/contract/authorizer.d.mts +8 -0
- package/dist/contract/authorizer.mjs +20 -0
- package/dist/contract/call.d.mts +9 -8
- package/dist/contract/call.mjs +49 -8
- package/dist/contract/callback.d.mts +7 -0
- package/dist/contract/callback.mjs +27 -0
- package/dist/contract/caller.d.mts +12 -3
- package/dist/contract/caller.mjs +23 -5
- package/dist/contract/canonical.mjs +10 -0
- package/dist/contract/codec.d.mts +9 -0
- package/dist/contract/codec.mjs +9 -0
- package/dist/contract/codes.mjs +81 -0
- package/dist/contract/declared.d.mts +0 -2
- package/dist/contract/declared.mjs +26 -11
- package/dist/contract/digest.mjs +6 -0
- package/dist/contract/errors.d.mts +9 -5
- package/dist/contract/errors.mjs +2 -3
- package/dist/contract/feed.d.mts +127 -0
- package/dist/contract/feed.mjs +249 -0
- package/dist/contract/hints.mjs +1 -2
- package/dist/contract/hub.d.mts +94 -0
- package/dist/contract/hub.mjs +133 -0
- package/dist/contract/idempotency.d.mts +47 -0
- package/dist/contract/idempotency.mjs +99 -0
- package/dist/contract/implementation.d.mts +73 -51
- package/dist/contract/implementation.mjs +94 -60
- package/dist/contract/input-check.d.mts +15 -0
- package/dist/contract/input-check.mjs +16 -0
- package/dist/contract/lease.mjs +28 -0
- package/dist/contract/listed.d.mts +4 -0
- package/dist/contract/listed.mjs +22 -0
- package/dist/contract/log.d.mts +41 -0
- package/dist/contract/log.mjs +144 -0
- package/dist/contract/media.d.mts +1 -3
- package/dist/contract/media.mjs +1 -2
- package/dist/contract/names.mjs +15 -6
- package/dist/contract/occurrence.d.mts +29 -0
- package/dist/contract/occurrence.mjs +45 -0
- package/dist/contract/pages.d.mts +13 -0
- package/dist/contract/pages.mjs +39 -0
- package/dist/contract/progress.d.mts +26 -0
- package/dist/contract/progress.mjs +72 -0
- package/dist/contract/push.d.mts +20 -0
- package/dist/contract/push.mjs +96 -0
- package/dist/contract/receiving.d.mts +29 -0
- package/dist/contract/receiving.mjs +42 -0
- package/dist/contract/recent.mjs +12 -0
- package/dist/contract/reported.mjs +16 -0
- package/dist/contract/serving.mjs +63 -0
- package/dist/contract/status.mjs +15 -7
- package/dist/contract/stream.d.mts +34 -0
- package/dist/contract/stream.mjs +31 -0
- package/dist/contract/subscribe.d.mts +45 -0
- package/dist/contract/subscribe.mjs +50 -0
- package/dist/contract/transient.mjs +28 -0
- package/dist/contract/watch.d.mts +18 -0
- package/dist/contract/watch.mjs +105 -0
- package/dist/contract/webhooks.d.mts +42 -0
- package/dist/contract/webhooks.mjs +53 -0
- package/dist/http/client.d.mts +37 -14
- package/dist/http/client.mjs +52 -14
- package/dist/http/events.d.mts +56 -0
- package/dist/http/events.mjs +102 -0
- package/dist/http/placed.d.mts +36 -0
- package/dist/http/placed.mjs +71 -0
- package/dist/http/schema-errors.mjs +2 -3
- package/dist/http/streamed.d.mts +21 -0
- package/dist/http/streamed.mjs +94 -0
- package/dist/http/watch.mjs +50 -0
- package/dist/mcp/bridge.mjs +283 -0
- package/dist/mcp/client.d.mts +30 -99
- package/dist/mcp/client.mjs +60 -134
- package/dist/mcp/events.mjs +142 -0
- package/dist/mcp/progress.mjs +34 -0
- package/dist/mcp/protocol.mjs +40 -15
- package/dist/mcp/reply.d.mts +79 -0
- package/dist/mcp/reply.mjs +99 -0
- package/dist/mcp/request.d.mts +40 -0
- package/dist/mcp/request.mjs +51 -0
- package/dist/mcp/watch.mjs +115 -0
- package/dist/rpc/watch.mjs +39 -0
- package/dist/stdio/console.mjs +14 -7
- package/dist/testing/memory.d.mts +1 -3
- package/dist/testing/memory.mjs +4 -5
- package/dist/webhook/address.mjs +47 -0
- package/dist/webhook/attempt.mjs +65 -0
- package/dist/webhook/receiver.mjs +67 -0
- package/dist/webhook/signing.mjs +28 -0
- package/dist/webhook/stored.mjs +57 -0
- package/dist/webhook/subscriptions.mjs +342 -0
- package/docs/Action-failures.md +2 -2
- package/docs/Action-streams.md +115 -0
- package/docs/Action.md +58 -124
- package/docs/ActionCli-failures.md +1 -2
- package/docs/ActionCli.md +83 -88
- package/docs/ActionHttp-failures.md +3 -3
- package/docs/ActionHttp.md +90 -70
- package/docs/ActionMcp-failures.md +2 -1
- package/docs/ActionMcp.md +120 -92
- package/docs/ActionRpc-events.md +126 -0
- package/docs/ActionRpc-failures.md +1 -2
- package/docs/ActionRpc.md +108 -79
- package/docs/ActionToolkit-failures.md +1 -2
- package/docs/ActionToolkit.md +33 -90
- package/docs/Authentication-advanced.md +57 -61
- package/docs/Authentication-failures.md +5 -4
- package/docs/Authentication.md +23 -58
- package/docs/Event-failures.md +15 -0
- package/docs/Event.md +281 -0
- package/docs/README.md +51 -82
- package/docs/Testing-failures.md +1 -5
- package/docs/Testing.md +126 -86
- package/docs/Webhook-failures.md +8 -0
- package/docs/Webhook.md +319 -0
- package/docs/setup-failures.md +2 -3
- package/docs/setup.md +32 -53
- package/examples/README.md +12 -37
- package/examples/assistant/README.md +21 -26
- package/examples/assistant/src/agent.ts +66 -24
- package/examples/assistant/src/cli.ts +7 -4
- package/examples/assistant/src/commands.ts +9 -4
- package/examples/assistant/src/identity/Identity.ts +5 -4
- package/examples/assistant/src/identity/authorize.ts +13 -5
- package/examples/assistant/src/identity/handlers.ts +3 -2
- package/examples/assistant/src/identity/permissions.ts +9 -3
- package/examples/assistant/src/platform/tasks-file.ts +15 -11
- package/examples/assistant/src/scripted.ts +7 -4
- package/examples/assistant/src/tasks/Tasks.ts +20 -6
- package/examples/assistant/src/tasks/handlers.ts +9 -5
- package/examples/assistant/src/tasks/store.ts +38 -11
- package/examples/assistant/src/toolkit.ts +11 -7
- package/examples/assistant/test/commands.test.ts +53 -27
- package/examples/assistant/test/identity/identity.test.ts +27 -11
- package/examples/assistant/test/platform/tasks-file.test.ts +39 -23
- package/examples/assistant/test/tasks/tasks.test.ts +62 -34
- package/examples/assistant/test/toolkit.test.ts +104 -75
- package/examples/build-events/README.md +83 -0
- package/examples/build-events/src/Api.ts +27 -0
- package/examples/build-events/src/Rpc.ts +26 -0
- package/examples/build-events/src/builds/Builds.ts +108 -0
- package/examples/build-events/src/builds/events.ts +54 -0
- package/examples/build-events/src/builds/handlers.ts +58 -0
- package/examples/build-events/src/builds/log.ts +30 -0
- package/examples/build-events/src/builds/status.ts +28 -0
- package/examples/build-events/src/builds/store.ts +130 -0
- package/examples/build-events/src/cli.ts +18 -0
- package/examples/build-events/src/commands.ts +32 -0
- package/examples/build-events/src/deploys/Deploys.ts +44 -0
- package/examples/build-events/src/deploys/approvers.ts +55 -0
- package/examples/build-events/src/deploys/events.ts +32 -0
- package/examples/build-events/src/deploys/handlers.ts +38 -0
- package/examples/build-events/src/identity/Identity.ts +29 -0
- package/examples/build-events/src/identity/members.ts +7 -0
- package/examples/build-events/src/identity/verifier.ts +22 -0
- package/examples/build-events/src/notifier/Notices.ts +26 -0
- package/examples/build-events/src/notifier/routes.ts +71 -0
- package/examples/build-events/src/notifier.ts +48 -0
- package/examples/build-events/src/routes.ts +71 -0
- package/examples/build-events/src/server.ts +62 -0
- package/examples/build-events/test/builds/events.test.ts +68 -0
- package/examples/build-events/test/builds/log.test.ts +71 -0
- package/examples/build-events/test/builds/progress.test.ts +57 -0
- package/examples/build-events/test/builds/status.test.ts +42 -0
- package/examples/build-events/test/commands.test.ts +103 -0
- package/examples/build-events/test/deploys/events.test.ts +52 -0
- package/examples/build-events/test/http.test.ts +95 -0
- package/examples/build-events/test/notifier.test.ts +80 -0
- package/examples/build-events/test/routes.test.ts +96 -0
- package/examples/build-events/test/rpc.test.ts +84 -0
- package/examples/build-events/test/support/as.ts +8 -0
- package/examples/build-events/test/support/memory.ts +43 -0
- package/examples/build-events/test/webhooks.test.ts +143 -0
- package/examples/kitchen-sink/README.md +178 -166
- package/examples/kitchen-sink/src/Actions.ts +11 -3
- package/examples/kitchen-sink/src/Api.ts +12 -6
- package/examples/kitchen-sink/src/Rpc.ts +7 -5
- package/examples/kitchen-sink/src/admin/Admin.ts +21 -10
- package/examples/kitchen-sink/src/admin/authenticate.ts +8 -4
- package/examples/kitchen-sink/src/admin/authorize.ts +13 -5
- package/examples/kitchen-sink/src/admin/grants.ts +5 -3
- package/examples/kitchen-sink/src/admin/handlers.ts +9 -5
- package/examples/kitchen-sink/src/agent.ts +14 -6
- package/examples/kitchen-sink/src/assistant/Assistant.ts +21 -15
- package/examples/kitchen-sink/src/assistant/conversations.ts +14 -9
- package/examples/kitchen-sink/src/assistant/demo-model.ts +2 -2
- package/examples/kitchen-sink/src/assistant/handlers.ts +42 -22
- package/examples/kitchen-sink/src/attachments/Attachments.ts +6 -6
- package/examples/kitchen-sink/src/attachments/download.ts +7 -6
- package/examples/kitchen-sink/src/attachments/handlers.ts +9 -4
- package/examples/kitchen-sink/src/attachments/store.ts +25 -18
- package/examples/kitchen-sink/src/browser.ts +10 -4
- package/examples/kitchen-sink/src/cli.ts +28 -12
- package/examples/kitchen-sink/src/config.ts +1 -1
- package/examples/kitchen-sink/src/identity/Identity.ts +24 -10
- package/examples/kitchen-sink/src/identity/authenticate.ts +19 -11
- package/examples/kitchen-sink/src/identity/authorize.ts +14 -4
- package/examples/kitchen-sink/src/identity/directory.ts +16 -7
- package/examples/kitchen-sink/src/identity/handlers.ts +1 -0
- package/examples/kitchen-sink/src/identity/members.ts +7 -2
- package/examples/kitchen-sink/src/identity/quota.ts +23 -20
- package/examples/kitchen-sink/src/issues/Issues.ts +91 -15
- package/examples/kitchen-sink/src/issues/assistant.ts +4 -2
- package/examples/kitchen-sink/src/issues/events.ts +46 -0
- package/examples/kitchen-sink/src/issues/export.ts +35 -0
- package/examples/kitchen-sink/src/issues/guide.ts +4 -3
- package/examples/kitchen-sink/src/issues/handlers.ts +20 -7
- package/examples/kitchen-sink/src/issues/store.ts +156 -67
- package/examples/kitchen-sink/src/issues/write-limit.ts +44 -18
- package/examples/kitchen-sink/src/memory.ts +11 -2
- package/examples/kitchen-sink/src/ops.ts +10 -5
- package/examples/kitchen-sink/src/request-policy.ts +25 -9
- package/examples/kitchen-sink/src/routes.ts +67 -27
- package/examples/kitchen-sink/src/sdk.ts +22 -12
- package/examples/kitchen-sink/src/seed.ts +15 -9
- package/examples/kitchen-sink/src/server.ts +24 -10
- package/examples/kitchen-sink/src/stdio.ts +9 -3
- package/examples/kitchen-sink/src/workspaces/Workspaces.ts +10 -7
- package/examples/kitchen-sink/src/workspaces/handlers.ts +3 -2
- package/examples/kitchen-sink/src/workspaces/registry.ts +16 -10
- package/examples/kitchen-sink/src/workspaces/tenant.ts +12 -5
- package/examples/kitchen-sink/test/admin/admin.test.ts +38 -23
- package/examples/kitchen-sink/test/assistant/assistant.test.ts +471 -299
- package/examples/kitchen-sink/test/attachments/attachments.test.ts +135 -94
- package/examples/kitchen-sink/test/identity/identity.test.ts +110 -82
- package/examples/kitchen-sink/test/identity/session.test.ts +65 -43
- package/examples/kitchen-sink/test/issues/assistant.test.ts +50 -31
- package/examples/kitchen-sink/test/issues/events.test.ts +273 -0
- package/examples/kitchen-sink/test/issues/export.test.ts +120 -0
- package/examples/kitchen-sink/test/issues/issues.test.ts +105 -75
- package/examples/kitchen-sink/test/request-policy.test.ts +130 -33
- package/examples/kitchen-sink/test/routes.test.ts +102 -57
- package/examples/kitchen-sink/test/support/as.ts +9 -0
- package/examples/kitchen-sink/test/support/scripted.ts +6 -5
- package/examples/kitchen-sink/test/support/services.ts +17 -0
- package/examples/live-rpc/README.md +33 -35
- package/examples/live-rpc/src/Rpc.ts +9 -5
- package/examples/live-rpc/src/browser.ts +39 -11
- package/examples/live-rpc/src/chat/Chat.ts +30 -16
- package/examples/live-rpc/src/chat/authorize.ts +2 -1
- package/examples/live-rpc/src/chat/events.ts +74 -0
- package/examples/live-rpc/src/chat/handlers.ts +13 -5
- package/examples/live-rpc/src/chat/room.ts +9 -5
- package/examples/live-rpc/src/chat/store.ts +51 -14
- package/examples/live-rpc/src/client.ts +22 -5
- package/examples/live-rpc/src/identity/Identity.ts +3 -3
- package/examples/live-rpc/src/identity/verifier.ts +8 -4
- package/examples/live-rpc/src/page.ts +58 -12
- package/examples/live-rpc/src/routes.ts +14 -10
- package/examples/live-rpc/src/server.ts +15 -5
- package/examples/live-rpc/test/browser.test.ts +127 -50
- package/examples/live-rpc/test/chat/chat.test.ts +215 -23
- package/examples/live-rpc/test/routes.test.ts +130 -46
- package/examples/live-rpc/test/server.test.ts +94 -33
- package/examples/mcp-tools/README.md +24 -38
- package/examples/mcp-tools/src/platform/fake-farm.ts +63 -24
- package/examples/mcp-tools/src/platform/print-farm.ts +59 -29
- package/examples/mcp-tools/src/printers/Printers.ts +18 -7
- package/examples/mcp-tools/src/printers/farm.ts +15 -5
- package/examples/mcp-tools/src/printers/handlers.ts +12 -6
- package/examples/mcp-tools/src/routes.ts +8 -6
- package/examples/mcp-tools/src/server.ts +12 -5
- package/examples/mcp-tools/src/stdio.ts +3 -2
- package/examples/mcp-tools/test/printers/printers.test.ts +132 -89
- package/examples/mcp-tools/test/routes.test.ts +140 -81
- package/examples/notes-service/README.md +30 -45
- package/examples/notes-service/src/Api.ts +1 -0
- package/examples/notes-service/src/browser.ts +15 -14
- package/examples/notes-service/src/cli.ts +8 -3
- package/examples/notes-service/src/commands.ts +46 -20
- package/examples/notes-service/src/identity/Identity.ts +2 -2
- package/examples/notes-service/src/identity/authorize.ts +6 -2
- package/examples/notes-service/src/identity/handlers.ts +3 -2
- package/examples/notes-service/src/identity/users.ts +2 -1
- package/examples/notes-service/src/identity/verifier.ts +12 -6
- package/examples/notes-service/src/notes/Notes.ts +46 -22
- package/examples/notes-service/src/notes/handlers.ts +18 -9
- package/examples/notes-service/src/notes/store.ts +70 -43
- package/examples/notes-service/src/routes.ts +7 -5
- package/examples/notes-service/src/server.ts +12 -5
- package/examples/notes-service/src/status/Status.ts +1 -1
- package/examples/notes-service/src/status/handlers.ts +5 -3
- package/examples/notes-service/src/stdio.ts +7 -3
- package/examples/notes-service/src/worker.ts +6 -3
- package/examples/notes-service/test/commands.test.ts +164 -91
- package/examples/notes-service/test/notes/as.ts +3 -1
- package/examples/notes-service/test/notes/idempotency.test.ts +97 -67
- package/examples/notes-service/test/notes/in-process.test.ts +26 -15
- package/examples/notes-service/test/notes/notes.test.ts +49 -31
- package/examples/notes-service/test/routes.test.ts +106 -71
- package/examples/notes-service/test/worker.test.ts +21 -13
- package/examples/quickstart/README.md +2 -6
- package/examples/quickstart/src/Api.ts +1 -0
- package/examples/quickstart/src/client.ts +6 -3
- package/examples/quickstart/src/greeting/Greeting.ts +1 -1
- package/examples/quickstart/src/greeting/handlers.ts +5 -2
- package/examples/quickstart/src/routes.ts +3 -2
- package/examples/quickstart/src/server.ts +6 -2
- package/examples/quickstart/test/routes.test.ts +3 -2
- package/package.json +19 -17
package/dist/ActionRpc.d.mts
CHANGED
|
@@ -1,43 +1,102 @@
|
|
|
1
|
+
import { Codec } from "./contract/codec.mjs";
|
|
1
2
|
import { Anyone } from "./contract/caller.mjs";
|
|
2
|
-
import { BuiltIn, BuiltIns } from "./contract/errors.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { BuiltIn, BuiltIns, Unauthenticated } from "./contract/errors.mjs";
|
|
4
|
+
import { EventBuildError, EventBuildServices, EventServedRequest, HoldingEvents, ServingEvents } from "./contract/feed.mjs";
|
|
5
|
+
import { Any as Any$1, Received, SubscriptionError } from "./Event.mjs";
|
|
6
|
+
import { BuildError, Holding, Known, Member, MiddlewareOf, Selected, SelectedEvents, Served } from "./contract/implementation.mjs";
|
|
4
7
|
import { Call } from "./contract/call.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
8
|
+
import { Answer, StreamOf } from "./contract/stream.mjs";
|
|
9
|
+
import { WatchArgs } from "./contract/watch.mjs";
|
|
10
|
+
import { Any as Any$2, Errors } from "./Action.mjs";
|
|
7
11
|
import { Certain, ErrorsOf } from "./contract/declared.mjs";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
+
import { Any as Any$3, Descriptor, DescriptorOf, LayerIdentity, Matching, ProviderOf, PublicOnly, RemoteRequest, Required, Security, ServedProvider, ServerBuildServices, VerifierError } from "./authentication/provider.mjs";
|
|
13
|
+
import { Only } from "./contract/listed.mjs";
|
|
14
|
+
import { PushedOf, SubscriptionOf } from "./contract/push.mjs";
|
|
15
|
+
import { Context, Effect, Layer, Schedule, Schema, Scope, Stream, Types } from "effect";
|
|
16
|
+
import { HttpRouter, HttpServerRequest } from "effect/http";
|
|
17
|
+
import { Rpc, RpcClient, RpcClientError, RpcGroup, RpcMessage, RpcMiddleware, RpcSchema, RpcServer } from "effect/rpc";
|
|
12
18
|
type BindingError = Errors[number];
|
|
13
|
-
type ErrorOf<A extends Any$
|
|
14
|
-
type RpcOf<A extends Any$1, E extends Errors, D> = A extends Any$1 ? Rpc.Rpc<A["name"], A["input"], A["success"], ErrorOf<A, E, D>> : never;
|
|
19
|
+
type ErrorOf<A extends Any$2, E extends Errors, D> = Schema.Union<ReadonlyArray<A["error"][number] | E[number] | VerifierError<A, D> | BuiltIns>>;
|
|
15
20
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* this package, serves the same; `layer` serves it and `client` calls it.
|
|
21
|
+
* What the stream rpc of an action declaring `progress` sends: a `Progress` for each value its
|
|
22
|
+
* handler reports, then a `Final` with its answer.
|
|
19
23
|
*/
|
|
20
|
-
|
|
24
|
+
declare const ProgressedOf: <P extends Codec, S extends Codec>(progress: P, success: S) => Schema.Union<readonly [Schema.TaggedStruct<"Progress", {
|
|
25
|
+
readonly value: P;
|
|
26
|
+
}>, Schema.TaggedStruct<"Final", {
|
|
27
|
+
readonly value: S;
|
|
28
|
+
}>]>;
|
|
29
|
+
/**
|
|
30
|
+
* What the stream rpc of an action answering a stream sends: an `Element` for each element, and a
|
|
31
|
+
* `Progress` for each value its handler reports where it declares `progress`.
|
|
32
|
+
*/
|
|
33
|
+
type ElementedOf<Element extends Schema.Constraint, P> = Schema.Union<readonly [Schema.TaggedStruct<"Element", {
|
|
34
|
+
readonly value: Element;
|
|
35
|
+
}>, ...(P extends Codec ? [Schema.TaggedStruct<"Progress", {
|
|
36
|
+
readonly value: P;
|
|
37
|
+
}>] : [])]>;
|
|
38
|
+
type RpcOf<A extends Any$2, E extends Errors, D> = A extends Any$2 ? A["success"] extends StreamOf<infer Element> ? Rpc.Rpc<A["name"], A["input"], RpcSchema.Stream<ElementedOf<Element, A["progress"]>, ErrorOf<A, E, D>>> : A["progress"] extends Codec ? Rpc.Rpc<A["name"], A["input"], RpcSchema.Stream<ReturnType<typeof ProgressedOf<A["progress"], A["success"]>>, ErrorOf<A, E, D>>> : Rpc.Rpc<A["name"], A["input"], A["success"], ErrorOf<A, E, D>> : never;
|
|
39
|
+
type EventRpcOf<V extends Any$1, E extends Errors, D> = V extends Any$1 ? Rpc.Rpc<V["name"], ReturnType<typeof SubscriptionOf<V>>, RpcSchema.Stream<ReturnType<typeof PushedOf<V>>, Schema.Union<ReadonlyArray<E[number] | VerifierError<V, D> | BuiltIns>>>> : never;
|
|
40
|
+
declare const authenticatedKey = "effect-actions/ActionRpc/Authenticated";
|
|
41
|
+
type RefusalOf<E extends Errors> = Schema.Union<ReadonlyArray<typeof Unauthenticated | E[number]>>;
|
|
42
|
+
declare const authenticatedBrand: unique symbol;
|
|
43
|
+
/**
|
|
44
|
+
* The middleware authenticating a binding's native rpcs, as Effect's server reads it: what it
|
|
45
|
+
* provides their handlers, and what it fails with.
|
|
46
|
+
*/
|
|
47
|
+
interface Authenticated<I, E extends Errors = Errors> {
|
|
48
|
+
readonly [authenticatedBrand]: typeof authenticatedBrand;
|
|
49
|
+
readonly [RpcMiddleware.TypeId]: {
|
|
50
|
+
readonly provides: I;
|
|
51
|
+
readonly requires: never;
|
|
52
|
+
readonly error: RefusalOf<E>;
|
|
53
|
+
readonly clientError: never;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
type AuthenticatedOf<D> = D extends Descriptor<infer I, unknown, Security, string, infer E> ? RpcMiddleware.ServiceClass<Authenticated<I, E>, typeof authenticatedKey, I, RefusalOf<E>, never, never, false> : never;
|
|
57
|
+
type NativeOf<N extends Rpc.Any, D> = [D] extends [Any$3] ? Rpc.AddMiddleware<N, AuthenticatedOf<D>> : N;
|
|
58
|
+
/**
|
|
59
|
+
* An RPC binding: actions, event types, the errors every rpc declares, the descriptor
|
|
60
|
+
* authenticating its protected ones, and the native rpcs it serves beside them. Plain data, so a
|
|
61
|
+
* copy of it, or one made by another installed copy of this package, serves the same; `layer`
|
|
62
|
+
* serves it and `client` calls it.
|
|
63
|
+
*/
|
|
64
|
+
export interface Binding<Actions extends readonly Any$2[], E extends Errors = [], D extends Any$3 | undefined = undefined, Events extends readonly Any$1[] = readonly [], N extends Rpc.Any = never> {
|
|
21
65
|
/** The descriptor authenticating its protected actions, or `undefined` when it names none. */
|
|
22
66
|
readonly authentication: D;
|
|
23
67
|
/** The exact actions bound to this binding. */
|
|
24
68
|
readonly actions: Actions;
|
|
69
|
+
/** The exact event types bound to this binding, each a stream rpc named after it. */
|
|
70
|
+
readonly events: Events;
|
|
25
71
|
/** The errors every rpc declares besides its action's own, as a list. */
|
|
26
72
|
readonly error: E;
|
|
27
73
|
/**
|
|
28
|
-
* The native
|
|
74
|
+
* The native rpcs `make`'s `rpcs` gave, as served: under an `authentication`, each runs
|
|
75
|
+
* behind the middleware authenticating it, which provides its handler the identity. A host
|
|
76
|
+
* implements them with `rpcs.toLayer`.
|
|
77
|
+
*/
|
|
78
|
+
readonly rpcs: RpcGroup.RpcGroup<NativeOf<N, D>>;
|
|
79
|
+
/**
|
|
80
|
+
* The native group of one rpc per action, named after it, one stream rpc per event type,
|
|
81
|
+
* taking `{ input, cursor }`, `cursor: null` reading from now, and `rpcs`, as clients see it:
|
|
29
82
|
* `RpcClient.make(Rpc.group)` is the native client.
|
|
83
|
+
*
|
|
84
|
+
* **Gotchas**
|
|
85
|
+
*
|
|
86
|
+
* - `layer` hands the protocol an action's and an event type's values as their JSON, the native `rpcs`' as they are: under a codec other than a JSON serialization's, such as schema-binary's or a protocol passing values, `RpcClient.make(Rpc.group)` decodes an action's answer or an event's occurrence by its own schema and fails; call actions and watch events through `client`, which hands them over as JSON too.
|
|
30
87
|
*/
|
|
31
|
-
readonly group: RpcGroup.RpcGroup<RpcOf<Actions[number], E, D>>;
|
|
88
|
+
readonly group: RpcGroup.RpcGroup<RpcOf<Actions[number], E, D> | EventRpcOf<Events[number], E, D> | NativeOf<N, D>>;
|
|
32
89
|
}
|
|
33
90
|
/**
|
|
34
|
-
* Any RPC binding. Its
|
|
91
|
+
* Any RPC binding. Its groups are any native groups here, since native groups are invariant in
|
|
35
92
|
* their rpcs; `actions` carries the types.
|
|
36
93
|
*/
|
|
37
94
|
export interface Any {
|
|
38
|
-
readonly authentication?: Any$
|
|
39
|
-
readonly actions:
|
|
95
|
+
readonly authentication?: Any$3 | undefined;
|
|
96
|
+
readonly actions: readonly Any$2[];
|
|
97
|
+
readonly events: readonly Any$1[];
|
|
40
98
|
readonly error: Errors;
|
|
99
|
+
readonly rpcs: RpcGroup.Any;
|
|
41
100
|
readonly group: RpcGroup.Any;
|
|
42
101
|
}
|
|
43
102
|
/** Contract-level configuration shared by servers and clients. */
|
|
@@ -51,22 +110,48 @@ export interface Options<E extends Errors = Errors> {
|
|
|
51
110
|
* `Authentication.make(...)` of the protected actions' identity, which authenticates each of
|
|
52
111
|
* their messages: required when the binding holds a protected action, and of its identity.
|
|
53
112
|
*/
|
|
54
|
-
readonly authentication?: Any$
|
|
113
|
+
readonly authentication?: Any$3;
|
|
114
|
+
/**
|
|
115
|
+
* Native rpcs the binding serves beside its actions and event types, with their own schemas
|
|
116
|
+
* and handlers: `RpcGroup.make(Upload)`. Under an `authentication`, each of their messages
|
|
117
|
+
* authenticates as a protected action's does: its handler reads the identity, and a refusal
|
|
118
|
+
* fails the call with `Unauthenticated`.
|
|
119
|
+
*
|
|
120
|
+
* **Gotchas**
|
|
121
|
+
*
|
|
122
|
+
* - `layer` requires their handlers, which the host provides from the binding's own `rpcs`: `Rpc.rpcs.toLayer(handlers)`, whose types then leave the identity unowed.
|
|
123
|
+
* - A native rpc runs no implementation's `authorize`: its handler authorizes the identity itself, as an action's `authorize` would, or every authenticated caller is served.
|
|
124
|
+
* - The layer's `middleware` runs on actions and event types alone: a native rpc runs the native middleware its group adds, inside its authentication.
|
|
125
|
+
* - Native middleware added to the binding's `rpcs` after `make` runs outside the authentication, before the identity exists; added to the group given here, inside it.
|
|
126
|
+
* - `layer` refuses a protected binding holding a native rpc without its authentication, such as one added with `rpcs.add` after `make`: add rpcs to the group given here.
|
|
127
|
+
* - A native rpc named after an action, an event type or a name the client keeps, `then` or `watch`, its method of events, is refused as the binding is made.
|
|
128
|
+
*/
|
|
129
|
+
readonly rpcs?: RpcGroup.Any;
|
|
55
130
|
}
|
|
131
|
+
type RpcsOf<O> = O extends {
|
|
132
|
+
readonly rpcs: infer G;
|
|
133
|
+
} ? RpcGroup.Rpcs<G> : never;
|
|
56
134
|
/**
|
|
57
135
|
* Bind actions once, for servers and clients alike, each as an rpc named after it, taking
|
|
58
|
-
* its action's input and answering its success
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
136
|
+
* its action's input and answering its success, and event types, each a stream rpc named after
|
|
137
|
+
* it, taking `{ input, cursor }`. Every rpc declares its action's errors, the binding's `error`,
|
|
138
|
+
* and the built-in `InvalidInput`, `Unauthenticated` and `Forbidden`, so clients decode each as
|
|
139
|
+
* a typed failure; a protected one also declares what its descriptor's verifier fails with.
|
|
140
|
+
* `rpcs` adds native ones beside them. Browser-safe, as an HTTP binding is.
|
|
62
141
|
* Guide: `docs/ActionRpc.md` in this package; in an application: `examples/live-rpc/`.
|
|
142
|
+
*
|
|
143
|
+
* **Gotchas**
|
|
144
|
+
*
|
|
145
|
+
* - An action, an event type and a native rpc of one name throw when `make` is called: they would share a client's method.
|
|
146
|
+
* - An action declaring `progress` is a stream rpc taking its input, streaming `{ _tag: "Progress", value }` for each value its handler reports, then one `{ _tag: "Final", value }` holding its answer: the native client's method of it returns a `Stream`.
|
|
147
|
+
* - An action answering a stream, `Action.Stream`, is a stream rpc taking its input, streaming `{ _tag: "Element", value }` for each element, beside `{ _tag: "Progress", value }` for each value where it declares `progress`; `client`'s method returns a `Stream` of the elements.
|
|
63
148
|
*/
|
|
64
|
-
export declare function make<const
|
|
149
|
+
export declare function make<const Contracts extends ReadonlyArray<(Any$2 | Any$1) & {
|
|
65
150
|
readonly caller: typeof Anyone;
|
|
66
|
-
}>>(
|
|
67
|
-
export declare function make<const
|
|
68
|
-
export declare function make<const
|
|
69
|
-
type Middleware =
|
|
151
|
+
}>>(contracts: Contracts): Binding<Only<Contracts, Any$2>, [], undefined, Only<Contracts, Any$1>>;
|
|
152
|
+
export declare function make<const Contracts extends ReadonlyArray<Any$2 | Any$1>, const O extends Options = {}>(contracts: Contracts, options: O & Required<Contracts[number]> & Matching<Contracts[number], NoInfer<DescriptorOf<O>>> & NoInfer<Known<O, Options>>): Binding<Only<Contracts, Any$2>, ErrorsOf<O>, DescriptorOf<O>, Only<Contracts, Any$1>, RpcsOf<O>>;
|
|
153
|
+
export declare function make<const Contracts extends ReadonlyArray<Any$2 | Any$1>>(contracts: Contracts & PublicOnly<Contracts>): Binding<Only<Contracts, Any$2>, [], undefined, Only<Contracts, Any$1>>;
|
|
154
|
+
type Middleware = readonly RpcMiddleware.AnyService[];
|
|
70
155
|
type IdOf<K> = K extends Context.Key<infer I extends RpcMiddleware.AnyId, unknown> ? I : never;
|
|
71
156
|
type Through<M extends Middleware, R> = number extends M["length"] ? R | RpcMiddleware.Requires<IdOf<M[number]>> : M extends readonly [infer K, ...infer Rest extends Middleware] ? Through<Rest, true extends Types.IsUnion<IdOf<K>> ? R | RpcMiddleware.Requires<IdOf<K>> : RpcMiddleware.ApplyServices<IdOf<K>, R>> : R;
|
|
72
157
|
type ForClient<K> = K extends {
|
|
@@ -75,19 +160,24 @@ type ForClient<K> = K extends {
|
|
|
75
160
|
type ServerOnly<M extends Middleware, E extends Errors> = [Exclude<RpcMiddleware.Error<IdOf<M[number]>>, Extract<Certain<E>, BindingError>["Type"] | BuiltIn> | ForClient<M[number]>] extends [never] ? unknown : {
|
|
76
161
|
readonly "Layer middleware fails only with the binding's errors and needs no client": never;
|
|
77
162
|
};
|
|
78
|
-
type LayerRequest<App, A extends Any$1, M extends Middleware> = Exclude<Through<M, RemoteRequest<App, A>>,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
163
|
+
type LayerRequest<App, A extends Any$2, E extends Any$1, M extends Middleware> = Exclude<Through<M, RemoteRequest<App, A> | EventServedRequest<App, E>>, HttpServerRequest.HttpServerRequest | HttpServerRequest.ParsedSearchParams | LayerIdentity<App, A, E>>;
|
|
164
|
+
type RpcLayer<B extends Any, Apps extends Served, M extends Middleware, A extends Any$2 = B["actions"][number], E extends Any$1 = B["events"][number]> = Layer.Layer<never, BuildError<Holding<Member<Apps>, A>, A> | EventBuildError<HoldingEvents<Member<Apps>, E>, E>, ServerBuildServices<Holding<Member<Apps>, A>, A> | EventBuildServices<HoldingEvents<Member<Apps>, E>, E> | RpcServer.Protocol | HttpRouter.Request.From<"Requires", LayerRequest<Member<Apps>, A, E, M>> | ServedProvider<Member<Apps>, A, B extends {
|
|
165
|
+
readonly authentication: infer D;
|
|
166
|
+
} ? D : never, ServingEvents<Member<Apps>, E>> | IdOf<M[number]> | NativeServer<RpcGroup.Rpcs<B["rpcs"]>, B extends {
|
|
82
167
|
readonly authentication: infer D;
|
|
83
|
-
} ? D : never
|
|
168
|
+
} ? D : never>>;
|
|
169
|
+
type NativeServer<N extends Rpc.Any, D> = [N] extends [never] ? never : Rpc.ToHandler<N> | Exclude<Rpc.Middleware<N>, Authenticated<unknown>> | Rpc.ServicesServer<N> | ProviderOf<D>;
|
|
84
170
|
/** `ActionRpc.layer`'s options. */
|
|
85
|
-
export interface LayerOptions<M extends Middleware = [],
|
|
171
|
+
export interface LayerOptions<M extends Middleware = [], C extends Any$2 | Any$1 = never> {
|
|
86
172
|
/**
|
|
87
|
-
* The actions it serves, among the binding's
|
|
88
|
-
* Defaults to every one of them.
|
|
173
|
+
* The actions and event types it serves, among the binding's the implementations hold:
|
|
174
|
+
* `[GetUser, UserRenamed]`, exactly those. Defaults to every one of them.
|
|
175
|
+
*
|
|
176
|
+
* **Gotchas**
|
|
177
|
+
*
|
|
178
|
+
* - A list naming actions alone serves no event type: a client's watch fails with `Event.SubscriptionError`, reason `NotServed`, until the event types are listed beside them.
|
|
89
179
|
*/
|
|
90
|
-
readonly actions?:
|
|
180
|
+
readonly actions?: readonly C[] | undefined;
|
|
91
181
|
/**
|
|
92
182
|
* Native rpc middleware every served rpc runs on each message, the first innermost: inside
|
|
93
183
|
* the authentication of a protected rpc, so none provides what a verifier reads, and outside
|
|
@@ -96,21 +186,60 @@ export interface LayerOptions<M extends Middleware = [], A extends Any$1 = never
|
|
|
96
186
|
*
|
|
97
187
|
* **Gotchas**
|
|
98
188
|
*
|
|
99
|
-
* - A middleware requiring the identity leaves it owed on a layer serving a public action: bind the protected
|
|
189
|
+
* - A middleware requiring the identity leaves it owed on a layer serving a public action or event type: bind the protected ones apart, or read the identity with `Effect.serviceOption`, which a public rpc's call lacks.
|
|
100
190
|
* - A middleware provides a service only to those listed before it and the handlers, and only in a list written in place as a tuple: listed earlier, or in an array-typed list, it leaves the service owed.
|
|
101
191
|
* - Router middleware around the layer runs once per WebSocket, at its upgrade, so its value holds for the whole connection: what differs per message needs a listed middleware.
|
|
192
|
+
* - On an event's stream rpc, a middleware and the authentication run once, around the subscription's admission, not its stream: one timing the call or releasing something as it ends sees it end as the stream starts, and never sees a later refusal; what it provides lasts the stream.
|
|
193
|
+
* - On the stream rpc of an action declaring `progress` or answering a stream they run around its start alike, before its handler runs: one timing it sees it end before the handler does, and never sees its failure; what it provides lasts the handler.
|
|
102
194
|
*/
|
|
103
195
|
readonly middleware?: M;
|
|
104
196
|
}
|
|
105
197
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
198
|
+
* One event subscription a `SubscriptionKeeper` keeps, as it arrived: the request a keeper writes
|
|
199
|
+
* to the server again, once restarted, with the payload `resumeFrom` gave for the last value sent.
|
|
200
|
+
*/
|
|
201
|
+
export interface KeptSubscription {
|
|
202
|
+
readonly clientId: number;
|
|
203
|
+
readonly requestId: string | number;
|
|
204
|
+
readonly tag: string;
|
|
205
|
+
/** The subscription's payload, an object of its `input` and the `cursor` it resumes from. */
|
|
206
|
+
readonly payload: Schema.Json;
|
|
207
|
+
/** The headers the request was authenticated with, which a resumed one is authenticated with again. */
|
|
208
|
+
readonly headers: ReadonlyArray<readonly [string, string]>;
|
|
209
|
+
/**
|
|
210
|
+
* The payload that resumes the subscription after `values`, a chunk sent for it, or
|
|
211
|
+
* `undefined` where they reach no position.
|
|
212
|
+
*/
|
|
213
|
+
readonly resumeFrom: (values: RpcMessage.ResponseChunkEncoded["values"]) => Schema.Json | undefined;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* What a protocol keeping event subscriptions across restarts of its server offers under
|
|
217
|
+
* `subscriptionKeeper`, as the Cloudflare package's `layerWebSocket` does: `layer` hands it each
|
|
218
|
+
* subscription once admitted, and sends every position the subscription reaches, with no
|
|
219
|
+
* 30-second heartbeat, whose timer would keep such a host awake.
|
|
220
|
+
*/
|
|
221
|
+
export interface SubscriptionKeeper {
|
|
222
|
+
readonly keep: (subscription: KeptSubscription) => Effect.Effect<void>;
|
|
223
|
+
}
|
|
224
|
+
/** The key a protocol sets to its `SubscriptionKeeper` on its `RpcServer.Protocol` service. */
|
|
225
|
+
export declare const subscriptionKeeper: unique symbol;
|
|
226
|
+
/**
|
|
227
|
+
* The key a protocol answering each call once sets to `true` on its `RpcServer.Protocol`
|
|
228
|
+
* service, as the Cloudflare package's stub protocol does, since Effect's protocol has no flag of
|
|
229
|
+
* its own for it: `layer` refuses to serve a streaming action, an event type or a native stream
|
|
230
|
+
* rpc on it, where a stream is answered with a defect at its first element and one with none
|
|
231
|
+
* waits for good.
|
|
232
|
+
*/
|
|
233
|
+
export declare const unaryProtocol: unique symbol;
|
|
234
|
+
/**
|
|
235
|
+
* Serve the binding's actions and event types among `implementations` with Effect's own
|
|
236
|
+
* `RpcServer`, or those its `actions` lists, as `ActionHttp.layer` selects them, under the
|
|
237
|
+
* protocol and serialization the host provides. Each message of a protected rpc authenticates
|
|
238
|
+
* from its own headers with the binding's descriptor; then the listed `middleware` runs, the
|
|
239
|
+
* input decodes, and the implementation's `authorize` and the handler run, as on every surface.
|
|
240
|
+
* The layer fails as the builders do and needs at startup what they need; per request it owes,
|
|
241
|
+
* as router request markers, what the authorizers and handlers read until its `middleware`
|
|
242
|
+
* provides it, or, over a router-mounted protocol, the route's request context.
|
|
114
243
|
* A protected action's identity comes from its authentication alone.
|
|
115
244
|
*
|
|
116
245
|
* **Gotchas**
|
|
@@ -121,22 +250,40 @@ export interface LayerOptions<M extends Middleware = [], A extends Any$1 = never
|
|
|
121
250
|
* - A defect, an undeclared failure, a middleware that throws, or a success or an error that does not encode ends that call with an `Error` whose message is `Internal server error`, its cause logged and reported to the call's `ErrorReporter`s; the connection's other calls go on.
|
|
122
251
|
* - An `ErrorReporter` is given only what ends a call with `Internal server error`, never a declared failure, a refusal or `InvalidInput`, unlike `ActionHttp.layer`'s `Info`: an alert counting declared failures counts none from rpcs.
|
|
123
252
|
* - An rpc's credential is read from its headers alone: an API key `in: "query"` never reaches authentication.
|
|
124
|
-
* - Over a protocol with no router, such as `RpcServer.layerProtocolSocketServer` or `layerProtocolStdio`, there is no
|
|
253
|
+
* - Over a protocol with no router, such as `RpcServer.layerProtocolSocketServer` or `layerProtocolStdio`, there is no route: a provider publishing a `protectedResource` leaves `HttpRouter` owed; the request a handler or a verifier reads is, on every protocol, one holding the message's headers, at `/`, with no query or body.
|
|
254
|
+
* - An event's stream rpc takes `{ input, cursor }`, a `cursor` omitted or `null` reading from now, and streams `Checked`, `Occurrence`, `Gap` and `Failed`, a `Checked` every 30 seconds; over `RpcServer.layerProtocolHttp` serialize with `RpcSerialization.layerNdjson`: under `layerJson` a response is sent once its streams end, so a watch never answers.
|
|
255
|
+
* - A subscription refused when it starts or later ends its stream rpc with the refusal as the typed failure; a source's failure no refusal explains is logged and reported once, sent as a bare `Failed`, and read again from where it reached after 5 seconds.
|
|
256
|
+
* - A stream is read only as fast as its client reads it: a slow reader of a log source falls behind its log, and receives a `Gap`.
|
|
257
|
+
* - An action declaring `progress` streams it to every call, a client's call without `onProgress` too, its values handed on one at a time, so a slow reader drops the oldest; under `RpcSerialization.layerJson` over HTTP they arrive with the answer, at the end.
|
|
258
|
+
* - A failure after an action's progress or its first element ends its stream rpc as it ends any call: a declared failure as the typed failure, a defect as `Internal server error`.
|
|
259
|
+
* - The binding's native `rpcs` are served on the same protocol with their own schemas, every one, whatever `actions` lists, and their handlers are owed until provided: `Rpc.rpcs.toLayer(handlers)`; a native rpc's defect or undeclared failure is answered as Effect's server answers it, never `Internal server error`, and only its verifier's defect is.
|
|
260
|
+
* - On a protocol answering each call once, one setting `unaryProtocol`, such as a Durable Object stub's, the build fails while it would serve a streaming action, an event type or a native stream rpc.
|
|
125
261
|
*/
|
|
126
262
|
export declare function layer<const B extends Any, const Apps extends Served>(binding: B, implementations: Apps): RpcLayer<B, Apps, []>;
|
|
127
|
-
export declare function layer<const B extends Any, const Apps extends Served, const O extends LayerOptions<Middleware, B["actions"][number]>>(binding: B, implementations: Apps, options: O & ServerOnly<MiddlewareOf<O, Middleware>, B["error"]> & NoInfer<Known<O, LayerOptions<Middleware>>>): RpcLayer<B, Apps, MiddlewareOf<O, Middleware>, Selected<O, B["actions"][number]>>;
|
|
263
|
+
export declare function layer<const B extends Any, const Apps extends Served, const O extends LayerOptions<Middleware, B["actions"][number] | B["events"][number]>>(binding: B, implementations: Apps, options: O & ServerOnly<MiddlewareOf<O, Middleware>, B["error"]> & NoInfer<Known<O, LayerOptions<Middleware>>>): RpcLayer<B, Apps, MiddlewareOf<O, Middleware>, Selected<O, B["actions"][number]>, SelectedEvents<O, B["events"][number]>>;
|
|
128
264
|
/**
|
|
129
265
|
* What one call of an action `A` fails with, beside the binding's errors `E`: its declared and
|
|
130
266
|
* built-in errors, and Effect's own `RpcClientError` when the server could not be reached. An
|
|
131
267
|
* answer that does not decode is a defect, as the native client makes it.
|
|
132
268
|
*/
|
|
133
|
-
export type MethodError<A extends Any$
|
|
134
|
-
type Method<A extends Any$
|
|
269
|
+
export type MethodError<A extends Any$2, E extends BindingError = never> = A["error"][number]["Type"] | E["Type"] | BuiltIns["Type"] | RpcClientError.RpcClientError;
|
|
270
|
+
type Method<A extends Any$2, E extends BindingError> = Call<A, Answer<A["success"], MethodError<A, E>, never>>;
|
|
271
|
+
/**
|
|
272
|
+
* What a watch of `W` over the binding `B` may fail with: a refusal, when it starts or later,
|
|
273
|
+
* `InvalidInput`, the binding's errors, an `Event.SubscriptionError` (`Unsupported` for
|
|
274
|
+
* `mode: "poll"`, which rpcs do not serve, `NotServed` for an event the server does not serve), or
|
|
275
|
+
* Effect's own `RpcClientError` that no reconnect outlasts. An element that does not decode is a defect, as for a call.
|
|
276
|
+
*/
|
|
277
|
+
export type WatchError<W extends Any$1, B extends Any> = SubscriptionError | BuiltIns["Type"] | B["error"][number]["Type"] | VerifierError<W, B["authentication"]>["Type"] | RpcClientError.RpcClientError;
|
|
278
|
+
type Watching<B extends Any> = [B["events"][number]] extends [never] ? unknown : {
|
|
279
|
+
readonly watch: <W extends B["events"][number], SE = never>(event: W, ...args: WatchArgs<W, SE>) => Stream.Stream<Received<W>, WatchError<W, B> | SE>;
|
|
280
|
+
};
|
|
135
281
|
/**
|
|
136
282
|
* Every action of the binding `B`, as `client.<action>(input)`: a protected one may also fail
|
|
137
|
-
* with what its descriptor's verifier declares.
|
|
283
|
+
* with what its descriptor's verifier declares. Where `B` lists event types, `watch(event, input,
|
|
284
|
+
* options)` streams one; each native rpc of its `rpcs` is the native client's method.
|
|
138
285
|
*/
|
|
139
|
-
export type Client<B extends Any> = { readonly [A in B["actions"][number] as A["name"]]: Method<A, B["error"][number] | VerifierError<A, B["authentication"]>>; }
|
|
286
|
+
export type Client<B extends Any> = { readonly [A in B["actions"][number] as A["name"]]: Method<A, B["error"][number] | VerifierError<A, B["authentication"]>>; } & Watching<B> & RpcClient.RpcClient<RpcGroup.Rpcs<B["rpcs"]>, RpcClientError.RpcClientError>;
|
|
140
287
|
/**
|
|
141
288
|
* The native `RpcClient.make` options `client` takes: `spanPrefix`, `spanAttributes`,
|
|
142
289
|
* `generateRequestId` and `disableTracing`. `flatten` changes the client's shape, which the
|
|
@@ -148,15 +295,33 @@ export type ClientOptions = Omit<NonNullable<Parameters<typeof RpcClient.make>[1
|
|
|
148
295
|
* directly: `client.greet({ name })`, as `ActionHttp.client`'s, the argument omitted when `{}`
|
|
149
296
|
* is a valid input, each call failing with its `MethodError`. Requires the native client
|
|
150
297
|
* `Protocol` and a `Scope`, as `RpcClient.make` does; headers set with `RpcClient.withHeaders`
|
|
151
|
-
* around a call go with its message
|
|
152
|
-
* `RpcClient.make(Rpc.group)`.
|
|
298
|
+
* around a call go with its message, and the binding's native `rpcs` are its methods too. The
|
|
299
|
+
* native client stays available under a JSON serialization: `RpcClient.make(Rpc.group)`.
|
|
153
300
|
*
|
|
154
301
|
* **Gotchas**
|
|
155
302
|
*
|
|
156
303
|
* - It drops undeclared input fields as it encodes, and fails with `InvalidInput`, sending nothing, for an input that does not encode.
|
|
157
304
|
* - A browser WebSocket cannot set an `Authorization` header on its upgrade, so under Bearer a protected call without its own token fails with `Unauthenticated`, `A bearer token is required.`: send the token on each call with `RpcClient.withHeaders`.
|
|
158
305
|
* - The socket belongs to the Layer providing the protocol, not to the `Scope` around the client: provided around one call, it opens a socket for that call alone.
|
|
306
|
+
* - `watch(event, input, options)` holds the event's stream rpc open, as `Action.client`'s does; `mode: "poll"` fails with `Event.SubscriptionError`, reason `Unsupported`, since rpcs serve no poll, and a watch of an event the server does not serve fails with it, reason `NotServed`, as over HTTP.
|
|
307
|
+
* - A watch reconnects after the protocol's socket or HTTP transport fails, a response ends before its stream does, as a server's restart ends it, a status a server sends while it recovers, or, over Effect's HTTP protocol, 60 seconds without an element, a socket's own pings telling a dead one, a second later and doubling to 30 seconds, each reconnect logged as a warning; a declared error, a refusal included, or a socket's close with an application's code, 4000 to 4999, ends it.
|
|
308
|
+
* - A native rpc of the binding's `rpcs` is the native client's method: a stream rpc's is a `Stream`, its headers given as its options' `headers`, since `RpcClient.withHeaders` wraps an Effect.
|
|
309
|
+
*/
|
|
310
|
+
export declare function client<const B extends Any>(binding: B, options?: ClientOptions): Effect.Effect<Client<B>, never, RpcClient.Protocol | Scope.Scope | Rpc.MiddlewareClient<RpcGroup.Rpcs<B["rpcs"]>>>;
|
|
311
|
+
/**
|
|
312
|
+
* A socket client's `retryPolicy`, for `RpcClient.layerProtocolSocket`, that stops connecting
|
|
313
|
+
* again once the server closes the socket with one of `codes`, such as a refusal of its upgrade:
|
|
314
|
+
* until then it is Effect's own default, `Schedule.min([Schedule.exponential(500, 1.5),
|
|
315
|
+
* Schedule.spaced(5000)])`, which Effect does not export. A page refused with its code stops, its
|
|
316
|
+
* calls and streams failing with an `RpcClientError` whose `reason` is that `SocketCloseError`,
|
|
317
|
+
* its `code` the one it closed with.
|
|
318
|
+
*
|
|
319
|
+
* **Gotchas**
|
|
320
|
+
*
|
|
321
|
+
* - A client without it connects again after a refusal as after any close, every five seconds for good.
|
|
322
|
+
* - Any other socket error, a drop included, is retried as Effect's default retries it.
|
|
159
323
|
*/
|
|
160
|
-
export declare
|
|
161
|
-
|
|
324
|
+
export declare const reconnectUntil: (...codes: readonly number[]) => Schedule.Schedule<import("effect/Duration").Duration, {
|
|
325
|
+
readonly reason: unknown;
|
|
326
|
+
}, never, never>;
|
|
162
327
|
export {};
|