@gjermundgaraba/effect-actions 0.21.0 → 0.23.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 +7 -1
- package/dist/Action.d.mts +2 -2
- package/dist/Action.mjs +1 -0
- package/dist/ActionCli.mjs +0 -1
- package/dist/ActionHttp.d.mts +1 -1
- package/dist/ActionMcp.d.mts +0 -3
- package/dist/ActionMcp.mjs +0 -5
- package/dist/ActionRpc.d.mts +8 -15
- package/dist/ActionRpc.mjs +29 -54
- package/dist/ActionToolkit.d.mts +0 -2
- package/dist/ActionToolkit.mjs +0 -2
- package/dist/Event.d.mts +0 -23
- package/dist/Testing.mjs +3 -2
- package/dist/Webhook.mjs +2 -2
- package/dist/authentication/refusal.mjs +0 -1
- package/dist/cli/commands.mjs +0 -5
- package/dist/contract/authorizer.mjs +0 -5
- package/dist/contract/call.mjs +0 -23
- package/dist/contract/callback.mjs +0 -1
- package/dist/contract/caller.mjs +0 -11
- package/dist/contract/canonical.mjs +0 -5
- package/dist/contract/codec.d.mts +0 -1
- package/dist/contract/codec.mjs +0 -1
- package/dist/contract/codes.mjs +1 -15
- package/dist/contract/declared.mjs +0 -15
- package/dist/contract/digest.mjs +0 -1
- package/dist/contract/errors.d.mts +0 -4
- package/dist/contract/errors.mjs +0 -4
- package/dist/contract/feed.d.mts +0 -1
- package/dist/contract/feed.mjs +0 -20
- package/dist/contract/hints.mjs +0 -6
- package/dist/contract/hub.mjs +0 -3
- package/dist/contract/idempotency.mjs +0 -4
- package/dist/contract/implementation.d.mts +0 -1
- package/dist/contract/implementation.mjs +0 -27
- package/dist/contract/input-check.mjs +0 -1
- package/dist/contract/lease.mjs +0 -1
- package/dist/contract/listed.mjs +0 -6
- package/dist/contract/log.mjs +0 -8
- package/dist/contract/names.mjs +0 -1
- package/dist/contract/occurrence.mjs +0 -8
- package/dist/contract/pages.mjs +5 -12
- package/dist/contract/progress.mjs +2 -25
- package/dist/contract/push.d.mts +0 -5
- package/dist/contract/push.mjs +1 -24
- package/dist/contract/receiving.mjs +0 -7
- package/dist/contract/reported.mjs +0 -5
- package/dist/contract/serving.mjs +0 -18
- package/dist/contract/status.mjs +0 -3
- package/dist/contract/stream.mjs +0 -2
- package/dist/contract/subscribe.d.mts +0 -2
- package/dist/contract/subscribe.mjs +0 -8
- package/dist/contract/transient.mjs +0 -12
- package/dist/contract/watch.mjs +5 -17
- package/dist/contract/webhooks.mjs +0 -11
- package/dist/http/client.mjs +0 -1
- package/dist/http/events.d.mts +0 -10
- package/dist/http/events.mjs +2 -31
- package/dist/http/placed.d.mts +0 -2
- package/dist/http/streamed.d.mts +0 -1
- package/dist/http/streamed.mjs +4 -32
- package/dist/http/watch.mjs +0 -6
- package/dist/mcp/bridge.mjs +0 -25
- package/dist/mcp/client.d.mts +0 -1
- package/dist/mcp/client.mjs +0 -1
- package/dist/mcp/events.mjs +0 -6
- package/dist/mcp/progress.mjs +0 -7
- package/dist/mcp/protocol.mjs +0 -6
- package/dist/mcp/reply.mjs +0 -11
- package/dist/mcp/request.mjs +0 -1
- package/dist/mcp/watch.mjs +0 -6
- package/dist/rpc/watch.mjs +0 -6
- package/dist/stdio/console.mjs +2 -2
- package/dist/webhook/address.mjs +4 -9
- package/dist/webhook/attempt.mjs +2 -15
- package/dist/webhook/receiver.mjs +2 -8
- package/dist/webhook/signing.mjs +0 -3
- package/dist/webhook/stored.mjs +8 -17
- package/dist/webhook/subscriptions.mjs +19 -23
- package/docs/Action-streams.md +0 -12
- package/docs/Action.md +0 -10
- package/docs/ActionCli.md +2 -26
- package/docs/ActionHttp.md +0 -28
- package/docs/ActionMcp.md +2 -37
- package/docs/ActionRpc-events.md +0 -16
- package/docs/ActionRpc.md +0 -63
- package/docs/ActionToolkit.md +0 -11
- package/docs/Authentication-advanced.md +0 -31
- package/docs/Authentication.md +4 -13
- package/docs/Event.md +0 -37
- package/docs/README.md +1 -1
- package/docs/Testing.md +3 -13
- package/docs/Webhook.md +0 -46
- package/docs/setup.md +0 -5
- package/examples/README.md +7 -1
- package/examples/assistant/src/agent.ts +8 -31
- package/examples/assistant/src/cli.ts +2 -9
- package/examples/assistant/src/commands.ts +0 -8
- package/examples/assistant/src/identity/Identity.ts +0 -10
- package/examples/assistant/src/identity/authorize.ts +0 -4
- package/examples/assistant/src/identity/members.ts +1 -3
- package/examples/assistant/src/identity/permissions.ts +0 -5
- package/examples/assistant/src/platform/tasks-file.ts +1 -6
- package/examples/assistant/src/scripted.ts +0 -4
- package/examples/assistant/src/tasks/Tasks.ts +0 -2
- package/examples/assistant/src/tasks/handlers.ts +0 -3
- package/examples/assistant/src/tasks/store.ts +0 -7
- package/examples/assistant/src/toolkit.ts +0 -11
- package/examples/assistant/test/commands.test.ts +0 -5
- package/examples/assistant/test/identity/identity.test.ts +6 -6
- package/examples/assistant/test/platform/tasks-file.test.ts +2 -6
- package/examples/assistant/test/tasks/tasks.test.ts +13 -14
- package/examples/assistant/test/toolkit.test.ts +7 -18
- package/examples/build-events/README.md +2 -0
- package/examples/build-events/src/Api.ts +0 -3
- package/examples/build-events/src/Rpc.ts +0 -2
- package/examples/build-events/src/builds/Builds.ts +0 -15
- package/examples/build-events/src/builds/events.ts +0 -10
- package/examples/build-events/src/builds/handlers.ts +0 -6
- package/examples/build-events/src/builds/log.ts +0 -6
- package/examples/build-events/src/builds/status.ts +0 -4
- package/examples/build-events/src/builds/store.ts +0 -21
- package/examples/build-events/src/cli.ts +0 -2
- package/examples/build-events/src/commands.ts +0 -9
- package/examples/build-events/src/deploys/approvers.ts +0 -3
- package/examples/build-events/src/deploys/events.ts +0 -8
- package/examples/build-events/src/deploys/handlers.ts +0 -2
- package/examples/build-events/src/identity/Identity.ts +0 -11
- package/examples/build-events/src/identity/members.ts +1 -2
- package/examples/build-events/src/identity/verifier.ts +8 -9
- package/examples/build-events/src/notifier/Notices.ts +0 -3
- package/examples/build-events/src/notifier/routes.ts +0 -10
- package/examples/build-events/src/notifier.ts +0 -8
- package/examples/build-events/src/routes.ts +0 -24
- package/examples/build-events/src/server.ts +0 -14
- package/examples/build-events/test/builds/events.test.ts +0 -6
- package/examples/build-events/test/builds/log.test.ts +0 -1
- package/examples/build-events/test/builds/progress.test.ts +0 -1
- package/examples/build-events/test/commands.test.ts +0 -5
- package/examples/build-events/test/deploys/events.test.ts +0 -1
- package/examples/build-events/test/http.test.ts +0 -4
- package/examples/build-events/test/notifier.test.ts +0 -9
- package/examples/build-events/test/routes.test.ts +0 -9
- package/examples/build-events/test/rpc.test.ts +0 -4
- package/examples/build-events/test/support/as.ts +3 -4
- package/examples/build-events/test/support/memory.ts +0 -5
- package/examples/build-events/test/webhooks.test.ts +0 -12
- package/examples/kitchen-sink/README.md +1 -1
- package/examples/kitchen-sink/src/Actions.ts +0 -10
- package/examples/kitchen-sink/src/Api.ts +0 -8
- package/examples/kitchen-sink/src/Rpc.ts +0 -4
- package/examples/kitchen-sink/src/admin/Admin.ts +0 -9
- package/examples/kitchen-sink/src/admin/authenticate.ts +2 -6
- package/examples/kitchen-sink/src/admin/authorize.ts +0 -5
- package/examples/kitchen-sink/src/admin/grants.ts +0 -5
- package/examples/kitchen-sink/src/admin/handlers.ts +0 -2
- package/examples/kitchen-sink/src/admin/keys.ts +1 -3
- package/examples/kitchen-sink/src/agent.ts +2 -13
- package/examples/kitchen-sink/src/assistant/Assistant.ts +7 -24
- package/examples/kitchen-sink/src/assistant/conversations.ts +3 -21
- package/examples/kitchen-sink/src/assistant/demo-model.ts +0 -5
- package/examples/kitchen-sink/src/assistant/handlers.ts +1 -30
- package/examples/kitchen-sink/src/attachments/Attachments.ts +0 -4
- package/examples/kitchen-sink/src/attachments/download.ts +0 -10
- package/examples/kitchen-sink/src/attachments/handlers.ts +0 -3
- package/examples/kitchen-sink/src/attachments/store.ts +0 -3
- package/examples/kitchen-sink/src/browser.ts +0 -9
- package/examples/kitchen-sink/src/cli.ts +0 -19
- package/examples/kitchen-sink/src/config.ts +3 -11
- package/examples/kitchen-sink/src/identity/Identity.ts +0 -18
- package/examples/kitchen-sink/src/identity/authenticate.ts +3 -14
- package/examples/kitchen-sink/src/identity/authorize.ts +0 -6
- package/examples/kitchen-sink/src/identity/directory.ts +8 -18
- package/examples/kitchen-sink/src/identity/handlers.ts +0 -3
- package/examples/kitchen-sink/src/identity/members.ts +1 -5
- package/examples/kitchen-sink/src/identity/quota.ts +0 -11
- package/examples/kitchen-sink/src/issues/Issues.ts +0 -24
- package/examples/kitchen-sink/src/issues/assistant.ts +0 -10
- package/examples/kitchen-sink/src/issues/events.ts +2 -16
- package/examples/kitchen-sink/src/issues/export.ts +0 -5
- package/examples/kitchen-sink/src/issues/guide.ts +0 -5
- package/examples/kitchen-sink/src/issues/handlers.ts +0 -5
- package/examples/kitchen-sink/src/issues/store.ts +19 -23
- package/examples/kitchen-sink/src/issues/write-limit.ts +0 -12
- package/examples/kitchen-sink/src/memory.ts +0 -9
- package/examples/kitchen-sink/src/ops.ts +0 -6
- package/examples/kitchen-sink/src/request-policy.ts +0 -17
- package/examples/kitchen-sink/src/routes.ts +0 -48
- package/examples/kitchen-sink/src/sdk.ts +0 -12
- package/examples/kitchen-sink/src/seed.ts +0 -10
- package/examples/kitchen-sink/src/server.ts +0 -22
- package/examples/kitchen-sink/src/stdio.ts +2 -12
- package/examples/kitchen-sink/src/workspaces/Workspaces.ts +0 -4
- package/examples/kitchen-sink/src/workspaces/handlers.ts +0 -4
- package/examples/kitchen-sink/src/workspaces/registry.ts +0 -5
- package/examples/kitchen-sink/src/workspaces/tenant.ts +0 -4
- package/examples/kitchen-sink/test/admin/admin.test.ts +0 -1
- package/examples/kitchen-sink/test/assistant/assistant.test.ts +0 -18
- package/examples/kitchen-sink/test/attachments/attachments.test.ts +0 -9
- package/examples/kitchen-sink/test/identity/identity.test.ts +0 -10
- package/examples/kitchen-sink/test/identity/session.test.ts +0 -10
- package/examples/kitchen-sink/test/issues/assistant.test.ts +3 -7
- package/examples/kitchen-sink/test/issues/events.test.ts +2 -9
- package/examples/kitchen-sink/test/issues/export.test.ts +0 -3
- package/examples/kitchen-sink/test/issues/issues.test.ts +6 -12
- package/examples/kitchen-sink/test/request-policy.test.ts +0 -6
- package/examples/kitchen-sink/test/routes.test.ts +0 -6
- package/examples/kitchen-sink/test/support/as.ts +3 -5
- package/examples/kitchen-sink/test/support/scripted.ts +0 -3
- package/examples/kitchen-sink/test/support/services.ts +0 -3
- package/examples/live-rpc/src/Rpc.ts +0 -4
- package/examples/live-rpc/src/browser.ts +0 -24
- package/examples/live-rpc/src/chat/Chat.ts +0 -22
- package/examples/live-rpc/src/chat/authorize.ts +0 -3
- package/examples/live-rpc/src/chat/events.ts +0 -14
- package/examples/live-rpc/src/chat/handlers.ts +0 -5
- package/examples/live-rpc/src/chat/room.ts +0 -6
- package/examples/live-rpc/src/chat/store.ts +0 -9
- package/examples/live-rpc/src/client.ts +0 -6
- package/examples/live-rpc/src/identity/Identity.ts +0 -6
- package/examples/live-rpc/src/identity/members.ts +1 -3
- package/examples/live-rpc/src/identity/verifier.ts +6 -12
- package/examples/live-rpc/src/page.ts +0 -10
- package/examples/live-rpc/src/routes.ts +0 -13
- package/examples/live-rpc/src/server.ts +0 -16
- package/examples/live-rpc/test/browser.test.ts +0 -9
- package/examples/live-rpc/test/chat/chat.test.ts +3 -11
- package/examples/live-rpc/test/routes.test.ts +0 -8
- package/examples/live-rpc/test/server.test.ts +0 -13
- package/examples/mcp-tools/src/instructions.ts +0 -4
- package/examples/mcp-tools/src/platform/fake-farm.ts +0 -6
- package/examples/mcp-tools/src/platform/print-farm.ts +0 -16
- package/examples/mcp-tools/src/printers/Printers.ts +0 -21
- package/examples/mcp-tools/src/printers/farm.ts +0 -5
- package/examples/mcp-tools/src/printers/handlers.ts +0 -6
- package/examples/mcp-tools/src/routes.ts +0 -11
- package/examples/mcp-tools/src/server.ts +0 -9
- package/examples/mcp-tools/src/stdio.ts +1 -13
- package/examples/mcp-tools/test/printers/printers.test.ts +0 -10
- package/examples/mcp-tools/test/routes.test.ts +0 -14
- package/examples/notes-service/src/Api.ts +0 -4
- package/examples/notes-service/src/browser.ts +0 -12
- package/examples/notes-service/src/cli.ts +0 -2
- package/examples/notes-service/src/commands.ts +0 -30
- package/examples/notes-service/src/identity/Identity.ts +0 -2
- package/examples/notes-service/src/identity/authorize.ts +0 -4
- package/examples/notes-service/src/identity/users.ts +1 -3
- package/examples/notes-service/src/identity/verifier.ts +4 -11
- package/examples/notes-service/src/notes/Notes.ts +0 -12
- package/examples/notes-service/src/notes/handlers.ts +0 -4
- package/examples/notes-service/src/notes/store.ts +62 -48
- package/examples/notes-service/src/routes.ts +0 -12
- package/examples/notes-service/src/server.ts +0 -6
- package/examples/notes-service/src/status/Status.ts +0 -1
- package/examples/notes-service/src/status/handlers.ts +0 -1
- package/examples/notes-service/src/stdio.ts +2 -12
- package/examples/notes-service/src/worker.ts +0 -7
- package/examples/notes-service/test/commands.test.ts +0 -20
- package/examples/notes-service/test/notes/as.ts +3 -4
- package/examples/notes-service/test/notes/in-process.test.ts +3 -6
- package/examples/notes-service/test/notes/notes.test.ts +0 -6
- package/examples/notes-service/test/routes.test.ts +0 -5
- package/examples/notes-service/test/worker.test.ts +0 -1
- package/examples/quickstart/src/Api.ts +0 -1
- package/examples/quickstart/src/client.ts +0 -3
- package/examples/quickstart/src/greeting/Greeting.ts +0 -2
- package/examples/quickstart/src/greeting/handlers.ts +0 -1
- package/examples/quickstart/src/routes.ts +0 -1
- package/examples/quickstart/src/server.ts +3 -6
- package/examples/quickstart/test/routes.test.ts +0 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -131,4 +131,10 @@ A few ideas (like the native Toolkit and CLI projections) are inspired by the ex
|
|
|
131
131
|
|
|
132
132
|
## Contributing
|
|
133
133
|
|
|
134
|
-
The rules for changing the library are in [AGENTS.md](https://github.com/gjermundgaraba/effect-actions/blob/main/AGENTS.md). MIT licensed.
|
|
134
|
+
Set up with [Vite+](https://viteplus.dev/guide/): `vp install`, then `vp run ready` runs every check. The rules for changing the library are in [AGENTS.md](https://github.com/gjermundgaraba/effect-actions/blob/main/AGENTS.md). MIT licensed.
|
|
135
|
+
|
|
136
|
+
## Releasing
|
|
137
|
+
|
|
138
|
+
Bump the version in `package.json` and `packages/cloudflare/package.json`, commit, tag `v<version>` and push the tag. `.github/workflows/npm.yml` then publishes every package whose version npm does not have yet, the core first, through npm trusted publishing. A new package's first version is published by hand with `vp pm publish`, followed by `npm trust github <package> --repo <repo> --file npm.yml` so the workflow can publish the next.
|
|
139
|
+
|
|
140
|
+
`.github/workflows/effect-latest.yml` runs the full check weekly against the newest Effect 4.x, so a minor release that passes can be admitted to the `effect` peer range.
|
package/dist/Action.d.mts
CHANGED
|
@@ -253,10 +253,10 @@ type NamesOf<T extends Target> = ActionsOf<T>["name"];
|
|
|
253
253
|
type KeepsAnswers<T extends Target> = [Extract<ActionsOf<T>, {
|
|
254
254
|
readonly idempotencyKey: string;
|
|
255
255
|
}>] extends [never] ? never : Idempotency;
|
|
256
|
-
type
|
|
256
|
+
type InferenceAnchor<R> = {
|
|
257
257
|
readonly "~list": R;
|
|
258
258
|
};
|
|
259
|
-
type Single<T extends Target, R> = T extends Any ? (input: T["input"]["Type"], ...reporting: ReportingOf<T>) => Answer<T["success"], T["error"][number]["Type"] | BuiltIn, R> :
|
|
259
|
+
type Single<T extends Target, R> = T extends Any ? (input: T["input"]["Type"], ...reporting: ReportingOf<T>) => Answer<T["success"], T["error"][number]["Type"] | BuiltIn, R> : InferenceAnchor<R>;
|
|
260
260
|
type Several<T extends Target, RequestServices> = { readonly [K in keyof RequestServices]: K extends NamesOf<T> ? Handler<Extract<ActionsOf<T>, {
|
|
261
261
|
readonly name: K;
|
|
262
262
|
}>, RequestServices[K]> : never; };
|
package/dist/Action.mjs
CHANGED
|
@@ -120,6 +120,7 @@ const watcherOf = (feeds) => (event, input, options) => {
|
|
|
120
120
|
name: event.name,
|
|
121
121
|
poll: polledOn("In process", event.name)((cursor) => feed.poll(value, cursor, { subscriber })),
|
|
122
122
|
stream: (cursor) => Stream$1.unwrap(Effect.flatMap(feed.stream(value), (open) => Effect.map(queuedPush(open, cursor, Effect.succeed, {
|
|
123
|
+
ending: Function.identity,
|
|
123
124
|
inOrder: true,
|
|
124
125
|
capacity: 1
|
|
125
126
|
}), (queue) => Stream$1.fromQueue(queue)))).pipe(readOn("In process", event.name))
|
package/dist/ActionCli.mjs
CHANGED
|
@@ -54,7 +54,6 @@ const overHttp = (binding, action, options, client) => {
|
|
|
54
54
|
return Stream.isStream(answer) ? Effect.succeed(answer) : answer;
|
|
55
55
|
}), options, bindingErrors(action, binding));
|
|
56
56
|
};
|
|
57
|
-
/** The command watching `event` through the `watch` of each client `client` makes as it runs. */
|
|
58
57
|
const watched = (event, client, errors) => watchCommand(event, (input, cursor) => Stream.unwrap(Effect.map(client, (methods) => methods.watch(event, input, { cursor }))), errors);
|
|
59
58
|
const aggregateCommand = (name, actions, commands, own, project, watches) => {
|
|
60
59
|
const derived = [...actions.map((action) => ({
|
package/dist/ActionHttp.d.mts
CHANGED
|
@@ -138,7 +138,7 @@ export interface Binding<Actions extends readonly Any$1[], E extends Errors = []
|
|
|
138
138
|
*/
|
|
139
139
|
export declare function make<const Contracts extends ReadonlyArray<(Any$1 | Any) & {
|
|
140
140
|
readonly caller: typeof Anyone;
|
|
141
|
-
}>>(contracts: Contracts): Binding<Only<Contracts, Any$1>, [], undefined, Only<Contracts, Any>>;
|
|
141
|
+
}>>(contracts: Contracts, options?: Pick<Options$1, "prefix">): Binding<Only<Contracts, Any$1>, [], undefined, Only<Contracts, Any>>;
|
|
142
142
|
export declare function make<const Contracts extends ReadonlyArray<Any$1 | Any>, const O extends Options$1 = {}>(contracts: Contracts, options: O & Required<Contracts[number]> & Matching<Contracts[number], NoInfer<DescriptorOf<O>>> & NoInfer<Known<O, Options$1>>): Binding<Only<Contracts, Any$1>, ErrorsOf<O>, DescriptorOf<O>, Only<Contracts, Any>>;
|
|
143
143
|
export declare function make<const Contracts extends ReadonlyArray<Any$1 | Any>>(contracts: Contracts & PublicOnly<Contracts>): Binding<Only<Contracts, Any$1>, [], undefined, Only<Contracts, Any>>;
|
|
144
144
|
/**
|
package/dist/ActionMcp.d.mts
CHANGED
|
@@ -87,11 +87,8 @@ export interface LayerHttpOptions<E = never, R = never, A extends Any$1 | Any =
|
|
|
87
87
|
type ToolRequestContext<R> = Exclude<R, McpSchema.McpRequestContext | McpServer.McpServer>;
|
|
88
88
|
type HttpToolRequestContext<R> = Exclude<ToolRequestContext<R>, HttpRouter.Provided>;
|
|
89
89
|
type Features<R> = Exclude<R, McpServer.McpServer>;
|
|
90
|
-
/** The actions and event types an endpoint of `Apps` given the options `O` serves. */
|
|
91
90
|
type Contracts<Apps extends Served, O> = SelectedOf<O, Apps> | SelectedEventsOf<O, Apps>;
|
|
92
|
-
/** What building an endpoint of `Apps` given the options `O` may fail with. */
|
|
93
91
|
type ServerError<Apps extends Served, O> = BuildError<Holding<Member<Apps>, SelectedOf<O, Apps>>, SelectedOf<O, Apps>> | EventBuildError<HoldingEvents<Member<Apps>, SelectedEventsOf<O, Apps>>, SelectedEventsOf<O, Apps>> | Cause.IllegalArgumentError;
|
|
94
|
-
/** What building the event sources of an endpoint of `Apps` given the options `O` needs. */
|
|
95
92
|
type EventServices<Apps extends Served, O> = EventBuildServices<HoldingEvents<Member<Apps>, SelectedEventsOf<O, Apps>>, SelectedEventsOf<O, Apps>>;
|
|
96
93
|
type Inferring<D, A extends Pick<Any$1, "caller">> = [D] extends [undefined] ? [Protected<A>] extends [never] ? {
|
|
97
94
|
readonly authentication?: undefined;
|
package/dist/ActionMcp.mjs
CHANGED
|
@@ -113,17 +113,12 @@ const registerTools = Effect.fnUntraced(function* (apps, authentication) {
|
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
});
|
|
116
|
-
/**
|
|
117
|
-
* Refuses event types an endpoint cannot serve as MCP events: one named twice, one named as MCP's
|
|
118
|
-
* own, or one whose input or payload is no object.
|
|
119
|
-
*/
|
|
120
116
|
const assertEventsServable = (events) => {
|
|
121
117
|
assertOnce("MCP event", events);
|
|
122
118
|
const reserved = events.find(({ name }) => name.startsWith("mcp."));
|
|
123
119
|
if (reserved !== void 0) throw new Error(`MCP event name starts with "mcp.", which MCP keeps for its own events: ${reserved.name} (rename it, or serve it on another surface)`);
|
|
124
120
|
for (const event of events) eventSchemasOf(event);
|
|
125
121
|
};
|
|
126
|
-
/** The revisions an endpoint speaks, the 2026-07-28 one serving `serving`'s events if any. */
|
|
127
122
|
const servingEvents = ([stateless, ...rest], serving) => serving.events.length === 0 ? [stateless, ...rest] : [withEvents(stateless, serving), ...rest];
|
|
128
123
|
const server = (apps, serving, transport, features = Layer.empty) => {
|
|
129
124
|
const { events, authentication } = serving;
|
package/dist/ActionRpc.d.mts
CHANGED
|
@@ -17,19 +17,11 @@ import { HttpRouter, HttpServerRequest } from "effect/http";
|
|
|
17
17
|
import { Rpc, RpcClient, RpcClientError, RpcGroup, RpcMessage, RpcMiddleware, RpcSchema, RpcServer } from "effect/rpc";
|
|
18
18
|
type BindingError = Errors[number];
|
|
19
19
|
type ErrorOf<A extends Any$2, E extends Errors, D> = Schema.Union<ReadonlyArray<A["error"][number] | E[number] | VerifierError<A, D> | BuiltIns>>;
|
|
20
|
-
/**
|
|
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.
|
|
23
|
-
*/
|
|
24
20
|
declare const ProgressedOf: <P extends Codec, S extends Codec>(progress: P, success: S) => Schema.Union<readonly [Schema.TaggedStruct<"Progress", {
|
|
25
21
|
readonly value: P;
|
|
26
22
|
}>, Schema.TaggedStruct<"Final", {
|
|
27
23
|
readonly value: S;
|
|
28
24
|
}>]>;
|
|
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
25
|
type ElementedOf<Element extends Schema.Constraint, P> = Schema.Union<readonly [Schema.TaggedStruct<"Element", {
|
|
34
26
|
readonly value: Element;
|
|
35
27
|
}>, ...(P extends Codec ? [Schema.TaggedStruct<"Progress", {
|
|
@@ -40,10 +32,6 @@ type EventRpcOf<V extends Any$1, E extends Errors, D> = V extends Any$1 ? Rpc.Rp
|
|
|
40
32
|
declare const authenticatedKey = "effect-actions/ActionRpc/Authenticated";
|
|
41
33
|
type RefusalOf<E extends Errors> = Schema.Union<ReadonlyArray<typeof Unauthenticated | E[number]>>;
|
|
42
34
|
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
35
|
interface Authenticated<I, E extends Errors = Errors> {
|
|
48
36
|
readonly [authenticatedBrand]: typeof authenticatedBrand;
|
|
49
37
|
readonly [RpcMiddleware.TypeId]: {
|
|
@@ -308,6 +296,13 @@ export type ClientOptions = Omit<NonNullable<Parameters<typeof RpcClient.make>[1
|
|
|
308
296
|
* - 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
297
|
*/
|
|
310
298
|
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"]>>>;
|
|
299
|
+
/**
|
|
300
|
+
* What `reconnectUntil`'s schedule reads of each failure to connect: the `reason` of the
|
|
301
|
+
* `Socket.SocketError` Effect's socket protocol retries after.
|
|
302
|
+
*/
|
|
303
|
+
export interface ReconnectReason {
|
|
304
|
+
readonly reason: unknown;
|
|
305
|
+
}
|
|
311
306
|
/**
|
|
312
307
|
* A socket client's `retryPolicy`, for `RpcClient.layerProtocolSocket`, that stops connecting
|
|
313
308
|
* again once the server closes the socket with one of `codes`, such as a refusal of its upgrade:
|
|
@@ -321,7 +316,5 @@ export declare function client<const B extends Any>(binding: B, options?: Client
|
|
|
321
316
|
* - A client without it connects again after a refusal as after any close, every five seconds for good.
|
|
322
317
|
* - Any other socket error, a drop included, is retried as Effect's default retries it.
|
|
323
318
|
*/
|
|
324
|
-
export declare const reconnectUntil: (...codes: readonly number[]) => Schedule.Schedule<import("effect/Duration").Duration,
|
|
325
|
-
readonly reason: unknown;
|
|
326
|
-
}, never, never>;
|
|
319
|
+
export declare const reconnectUntil: (...codes: readonly number[]) => Schedule.Schedule<import("effect/Duration").Duration, ReconnectReason, never, never>;
|
|
327
320
|
export {};
|
package/dist/ActionRpc.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { Anyone } from "./contract/caller.mjs";
|
|
|
2
2
|
import { InvalidInput, Unauthenticated } from "./contract/errors.mjs";
|
|
3
3
|
import { bindingErrors, bindingOf, eventErrors } from "./contract/declared.mjs";
|
|
4
4
|
import { reservedList, reservedNames } from "./contract/names.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { answerFrom, elementsFrom } from "./contract/progress.mjs";
|
|
6
6
|
import { elementOf } from "./contract/stream.mjs";
|
|
7
7
|
import { acquire, elementsOf } from "./contract/implementation.mjs";
|
|
8
8
|
import { checked, checkedStream, decodeInput, inputParseOptions, sendingJson, watchInput } from "./contract/call.mjs";
|
|
@@ -19,24 +19,18 @@ import { HttpClientRequest, HttpServerRequest } from "effect/http";
|
|
|
19
19
|
import { HttpApiBuilder } from "effect/http-api";
|
|
20
20
|
import { Rpc, RpcClient, RpcGroup, RpcMiddleware, RpcSchema, RpcServer } from "effect/rpc";
|
|
21
21
|
// src/rpc/ActionRpc.ts
|
|
22
|
-
/**
|
|
23
|
-
* What the stream rpc of an action declaring `progress` sends: a `Progress` for each value its
|
|
24
|
-
* handler reports, then a `Final` with its answer.
|
|
25
|
-
*/
|
|
26
22
|
const ProgressedOf = (progress, success) => Schema.Union([Schema.TaggedStruct("Progress", { value: progress }), Schema.TaggedStruct("Final", { value: success })]);
|
|
27
23
|
const elementedOf = (element, progress) => Schema.Union([Schema.TaggedStruct("Element", { value: element }), ...progress === void 0 ? [] : [Schema.TaggedStruct("Progress", { value: progress })]]);
|
|
28
|
-
/** Whether `action`'s rpc is a stream rpc: it answers a stream, or declares `progress`. */
|
|
29
24
|
const streams = (action) => action.progress !== void 0 || elementOf(action.success) !== void 0;
|
|
30
|
-
|
|
31
|
-
const sentOf = (action) => {
|
|
25
|
+
const streamedOf = (action) => {
|
|
32
26
|
const element = elementOf(action.success);
|
|
33
27
|
if (element !== void 0) return elementedOf(element, action.progress);
|
|
34
|
-
return action.progress === void 0 ?
|
|
28
|
+
return action.progress === void 0 ? void 0 : ProgressedOf(action.progress, action.success);
|
|
35
29
|
};
|
|
30
|
+
const sentOf = (action) => streamedOf(action) ?? action.success;
|
|
36
31
|
const authenticatedKey = "effect-actions/ActionRpc/Authenticated";
|
|
37
32
|
const nativeOf = (group) => group;
|
|
38
33
|
const authenticatedOf = (authentication) => RpcMiddleware.Service()(authenticatedKey, { error: Schema.Union([Unauthenticated, ...authentication.error]) });
|
|
39
|
-
/** The middleware authenticating `rpc`, wherever among its middleware it runs. */
|
|
40
34
|
const authenticatedIn = (rpc) => [...rpc.middlewares].find(({ key }) => key === authenticatedKey);
|
|
41
35
|
function make(contracts, options = {}) {
|
|
42
36
|
const { actions, events } = listed(contracts);
|
|
@@ -64,8 +58,7 @@ function make(contracts, options = {}) {
|
|
|
64
58
|
group
|
|
65
59
|
};
|
|
66
60
|
}
|
|
67
|
-
const
|
|
68
|
-
/** `call` inside `steps`, the first innermost, each given the call's options. */
|
|
61
|
+
const withSyntheticRequestFromHeaders = (headers) => (effect) => effect.pipe(Effect.provideService(HttpServerRequest.HttpServerRequest, HttpServerRequest.fromClientRequest(HttpClientRequest.get("/", { headers }))), Effect.provideService(HttpServerRequest.ParsedSearchParams, {}));
|
|
69
62
|
const throughSteps = (steps, call, options) => {
|
|
70
63
|
let wrapped = call;
|
|
71
64
|
for (const step of steps) {
|
|
@@ -74,10 +67,6 @@ const throughSteps = (steps, call, options) => {
|
|
|
74
67
|
}
|
|
75
68
|
return wrapped;
|
|
76
69
|
};
|
|
77
|
-
/**
|
|
78
|
-
* The step authenticating a call with `authentication`'s provider: the identity its verification
|
|
79
|
-
* answers is provided to the call, the verification run as `verifying` runs it.
|
|
80
|
-
*/
|
|
81
70
|
const authenticatingOf = (authentication) => Effect.map(providerOf(authentication), (provider) => {
|
|
82
71
|
const verify = Effect.flatMap(HttpApiBuilder.securityDecode(authentication.security), provider.authenticate);
|
|
83
72
|
return (verifying) => (effect, options) => Effect.flatMap(verifying(verify, options), (actor) => Effect.provideService(effect, authentication.identity, actor));
|
|
@@ -119,7 +108,7 @@ const callBoundaryOf = (error) => {
|
|
|
119
108
|
return Result.isSuccess(failure) ? encode(failure.success.error).pipe(Effect.matchCauseEffect({
|
|
120
109
|
onFailure: (unencoded) => concealed(Cause.combine(cause, unencoded)),
|
|
121
110
|
onSuccess: (encoded) => Effect.fail(new DeclaredFailure(encoded))
|
|
122
|
-
})) : Effect.failCause(
|
|
111
|
+
})) : Effect.failCause(failure.failure);
|
|
123
112
|
});
|
|
124
113
|
};
|
|
125
114
|
const handlerOf = (action, run, steps, error) => {
|
|
@@ -135,12 +124,6 @@ const handlerOf = (action, run, steps, error) => {
|
|
|
135
124
|
return boundary(wrapped);
|
|
136
125
|
};
|
|
137
126
|
};
|
|
138
|
-
/**
|
|
139
|
-
* The handler of the stream rpc of an action declaring `progress` or answering a stream: its call
|
|
140
|
-
* authenticates before its stream starts, then runs in the call's scope, what `sending` sends sent
|
|
141
|
-
* one at a time, so a caller reading slowly holds up the call, whose progress then drops the
|
|
142
|
-
* oldest values. A failure ends the stream as a call's ends it.
|
|
143
|
-
*/
|
|
144
127
|
const streamingHandlerOf = (action, sending, steps, error) => {
|
|
145
128
|
const decode = decodeInput(action);
|
|
146
129
|
const boundary = callBoundaryOf(error);
|
|
@@ -150,7 +133,10 @@ const streamingHandlerOf = (action, sending, steps, error) => {
|
|
|
150
133
|
const input = yield* decode(payload);
|
|
151
134
|
const sent = yield* Queue.bounded(1);
|
|
152
135
|
const send = (each) => Effect.asVoid(Queue.offer(sent, each));
|
|
153
|
-
yield* sending(input, { progress: (value) => Effect.flatMap(Effect.orDie(encodeProgress(value)), (json) => send(
|
|
136
|
+
yield* sending(input, { progress: (value) => Effect.flatMap(Effect.orDie(encodeProgress(value)), (json) => send({
|
|
137
|
+
_tag: "Progress",
|
|
138
|
+
value: json
|
|
139
|
+
})) }, send).pipe(boundary, Queue.into(sent), Effect.forkScoped({ startImmediately: true }));
|
|
154
140
|
return sent;
|
|
155
141
|
});
|
|
156
142
|
const wrapped = throughSteps(steps, call, {
|
|
@@ -160,28 +146,27 @@ const streamingHandlerOf = (action, sending, steps, error) => {
|
|
|
160
146
|
return boundary(wrapped);
|
|
161
147
|
};
|
|
162
148
|
};
|
|
163
|
-
/** Each value `run` reports sent as a `Progress`, then its answer as a `Final`. */
|
|
164
149
|
const sendingAnswer = (success, run) => {
|
|
165
150
|
const encode = Schema.encodeUnknownEffect(Schema.toCodecJson(success));
|
|
166
|
-
return (input, reporting, send) => run(input, reporting).pipe(Effect.flatMap(encode), Effect.flatMap((value) => send(
|
|
151
|
+
return (input, reporting, send) => run(input, reporting).pipe(Effect.flatMap(encode), Effect.flatMap((value) => send({
|
|
152
|
+
_tag: "Final",
|
|
153
|
+
value
|
|
154
|
+
})));
|
|
167
155
|
};
|
|
168
|
-
/** Each element of the stream `run` answers sent as an `Element`, beside its progress. */
|
|
169
156
|
const sendingElements = (element, run) => {
|
|
170
157
|
const encode = Schema.encodeUnknownEffect(Schema.toCodecJson(element));
|
|
171
|
-
return (input, reporting, send) => Stream.runForEach(elementsOf(run(input, reporting)), (each) => Effect.flatMap(encode(each), (value) => send(
|
|
158
|
+
return (input, reporting, send) => Stream.runForEach(elementsOf(run(input, reporting)), (each) => Effect.flatMap(encode(each), (value) => send({
|
|
159
|
+
_tag: "Element",
|
|
160
|
+
value
|
|
161
|
+
})));
|
|
172
162
|
};
|
|
173
163
|
/** The key a protocol sets to its `SubscriptionKeeper` on its `RpcServer.Protocol` service. */
|
|
174
164
|
const subscriptionKeeper = Symbol.for("effect-actions/ActionRpc/subscriptionKeeper");
|
|
165
|
+
const isSubscriptionKeeper = (kept) => Predicate.hasProperty(kept, "keep") && Predicate.isFunction(kept.keep);
|
|
175
166
|
const keeperOf = (protocol) => {
|
|
176
|
-
|
|
167
|
+
const kept = Predicate.hasProperty(protocol, subscriptionKeeper) ? protocol[subscriptionKeeper] : void 0;
|
|
168
|
+
return isSubscriptionKeeper(kept) ? kept : void 0;
|
|
177
169
|
};
|
|
178
|
-
/**
|
|
179
|
-
* The handler of one event type's stream rpc: the subscription's request authenticates and is
|
|
180
|
-
* admitted before its stream starts, so a refusal fails the call; the feed is then read from the
|
|
181
|
-
* call, in its scope, into a bounded queue, each element encoded, and read on through a source's
|
|
182
|
-
* failure, before its first `Checked` too. A later refusal ends the stream as a declared failure.
|
|
183
|
-
* Over a protocol with a `keeper`, the admitted subscription is kept, and every position sent.
|
|
184
|
-
*/
|
|
185
170
|
const subscriptionHandlerOf = (feed, steps, error, keeper) => {
|
|
186
171
|
const decode = Schema.decodeUnknownEffect(Subscription, inputParseOptions);
|
|
187
172
|
const decodeEventInput = decodeInput(feed.event);
|
|
@@ -228,8 +213,8 @@ const subscriptionHandlerOf = (feed, steps, error, keeper) => {
|
|
|
228
213
|
* waits for good.
|
|
229
214
|
*/
|
|
230
215
|
const unaryProtocol = Symbol.for("effect-actions/ActionRpc/unary");
|
|
231
|
-
const verifyingNative = (verify, { headers }) =>
|
|
232
|
-
const requested = (effect, { headers }) =>
|
|
216
|
+
const verifyingNative = (verify, { headers }) => withSyntheticRequestFromHeaders(headers)(verify).pipe(Effect.catchCauseIf(Cause.hasDies, concealed));
|
|
217
|
+
const requested = (effect, { headers }) => withSyntheticRequestFromHeaders(headers)(effect);
|
|
233
218
|
const isUnary = (protocol) => Predicate.hasProperty(protocol, unaryProtocol) && protocol[unaryProtocol] === true;
|
|
234
219
|
function layer(binding, served, options = {}) {
|
|
235
220
|
const selected = servingOf("RPC binding", binding, served, options);
|
|
@@ -275,33 +260,23 @@ function layer(binding, served, options = {}) {
|
|
|
275
260
|
return RpcServer.layer(jsonGroup.merge(binding.rpcs), { disableFatalDefects: true }).pipe(Layer.provide(handlers));
|
|
276
261
|
}
|
|
277
262
|
const isDeclared = (failure) => failure instanceof DeclaredFailure;
|
|
278
|
-
/** Fail with the declared failure a wrapper holds, decoded by `error`, or die where it does not. */
|
|
279
263
|
const failedOf = (error) => {
|
|
280
264
|
const decode = Schema.decodeUnknownEffect(Schema.toCodecJson(error));
|
|
281
265
|
return (failure) => Effect.flatMap(Effect.orDie(decode(failure.json)), Effect.fail);
|
|
282
266
|
};
|
|
283
|
-
/**
|
|
284
|
-
* A client's method of `action`, calling `method`, its rpc of `erasedOf`, with its input's JSON:
|
|
285
|
-
* what the server sends, its answer or each element it streams, and its declared failure, decoded
|
|
286
|
-
* by the action's schemas; one that does not decode is a defect, as the native client makes it.
|
|
287
|
-
*/
|
|
288
267
|
const actionMethodOf = (action, binding, method) => {
|
|
289
|
-
const decode = Schema.decodeUnknownEffect(Schema.toCodecJson(sentOf(action)));
|
|
290
268
|
const failed = failedOf(Schema.Union(bindingErrors(action, binding)));
|
|
291
|
-
const
|
|
292
|
-
if (
|
|
269
|
+
const streamed = streamedOf(action);
|
|
270
|
+
if (streamed === void 0) {
|
|
271
|
+
const decode = Schema.decodeUnknownEffect(Schema.toCodecJson(action.success));
|
|
293
272
|
const call = method;
|
|
294
|
-
return checked(action, sendingJson, (json) => call(json).pipe(Effect.catchIf(isDeclared, failed), Effect.flatMap(sent)));
|
|
273
|
+
return checked(action, sendingJson, (json) => call(json).pipe(Effect.catchIf(isDeclared, failed), Effect.flatMap((sent) => Effect.orDie(decode(sent)))));
|
|
295
274
|
}
|
|
275
|
+
const decode = Schema.decodeUnknownEffect(Schema.toCodecJson(streamed));
|
|
296
276
|
const call = method;
|
|
297
|
-
const progressed = (json) => call(json).pipe(Stream.catchIf(isDeclared, (failure) => Stream.fromEffect(failed(failure))), Stream.mapEffect(sent));
|
|
277
|
+
const progressed = (json) => call(json).pipe(Stream.catchIf(isDeclared, (failure) => Stream.fromEffect(failed(failure))), Stream.mapEffect((sent) => Effect.orDie(decode(sent))));
|
|
298
278
|
return elementOf(action.success) === void 0 ? checked(action, sendingJson, (json, onProgress) => answerFrom(progressed(json), onProgress)) : checkedStream(action, sendingJson, (json, onProgress) => elementsFrom(progressed(json), onProgress));
|
|
299
279
|
};
|
|
300
|
-
/**
|
|
301
|
-
* A client's subscription to `event`, calling `method`, its stream rpc of `erasedOf`, with its
|
|
302
|
-
* input's JSON and the cursor it resumes from: what the server sends, and its declared failure,
|
|
303
|
-
* decoded by the event's schemas; one that does not decode is a defect, as for an action.
|
|
304
|
-
*/
|
|
305
280
|
const eventMethodOf = (event, binding, method) => {
|
|
306
281
|
const decode = Schema.decodeUnknownEffect(Schema.toCodecJson(PushedOf(event)));
|
|
307
282
|
const failed = failedOf(Schema.Union(eventErrors(event, binding)));
|
package/dist/ActionToolkit.d.mts
CHANGED
|
@@ -65,13 +65,11 @@ export interface Options<A extends Any> {
|
|
|
65
65
|
*/
|
|
66
66
|
readonly needsApproval?: (call: ToolCall<A>, context: Tool.NeedsApprovalContext) => boolean | Effect.Effect<boolean, unknown>;
|
|
67
67
|
}
|
|
68
|
-
/** A value an action reported, as a toolkit's preliminary result holds it. */
|
|
69
68
|
declare class Reported<A> {
|
|
70
69
|
readonly _tag = "Progress";
|
|
71
70
|
readonly value: A;
|
|
72
71
|
constructor(value: A);
|
|
73
72
|
}
|
|
74
|
-
/** A preliminary result of a tool whose action declares `progress`: one value it reported. */
|
|
75
73
|
declare const ProgressOf: (progress: Codec) => Schema.decodeTo<Schema.declare<Reported<unknown>, Reported<unknown>>, Schema.TaggedStruct<"Progress", {
|
|
76
74
|
readonly value: Codec;
|
|
77
75
|
}>, never, never>;
|
package/dist/ActionToolkit.mjs
CHANGED
|
@@ -14,7 +14,6 @@ const annotateFromContract = (tool, action) => {
|
|
|
14
14
|
const hinted = tool.annotate(Tool.Readonly, readOnlyHint).annotate(Tool.Destructive, destructiveHint).annotate(Tool.Idempotent, idempotentHint).annotate(Tool.OpenWorld, openWorldHint);
|
|
15
15
|
return annotateIfGiven(annotateIfGiven(hinted, Tool.Title, title), Tool.Meta, _meta === void 0 ? void 0 : { ..._meta });
|
|
16
16
|
};
|
|
17
|
-
/** A value an action reported, as a toolkit's preliminary result holds it. */
|
|
18
17
|
var Reported = class {
|
|
19
18
|
_tag = "Progress";
|
|
20
19
|
value;
|
|
@@ -22,7 +21,6 @@ var Reported = class {
|
|
|
22
21
|
this.value = value;
|
|
23
22
|
}
|
|
24
23
|
};
|
|
25
|
-
/** A preliminary result of a tool whose action declares `progress`: one value it reported. */
|
|
26
24
|
const ProgressOf = (progress) => Schema.TaggedStruct("Progress", { value: progress }).pipe(Schema.decodeTo(Schema.declare((input) => input instanceof Reported), {
|
|
27
25
|
decode: SchemaGetter.transform(({ value }) => new Reported(value)),
|
|
28
26
|
encode: SchemaGetter.transform((reported) => ({
|
package/dist/Event.d.mts
CHANGED
|
@@ -105,31 +105,8 @@ export interface Page<E extends Any> {
|
|
|
105
105
|
readonly nextPoll?: Duration.Input | undefined;
|
|
106
106
|
}
|
|
107
107
|
interface Hooked<E extends Any, R> {
|
|
108
|
-
/**
|
|
109
|
-
* What a subscription needs set up upstream while it lasts, such as joining a channel: a scoped
|
|
110
|
-
* Effect, whose finalizer tears it down, run as the subscriber. A stream's lasts as long as the
|
|
111
|
-
* stream, a poll subscription's until `lease` after its last poll, or, watched in process, until
|
|
112
|
-
* the watch ends, and a webhook subscription's until it is unsubscribed or lapses, set up again
|
|
113
|
-
* as `persist` restores it.
|
|
114
|
-
*
|
|
115
|
-
* **Gotchas**
|
|
116
|
-
*
|
|
117
|
-
* - Write it so it may run twice for one subscription: a lease does not outlive the process, so a poll after a restart sets it up again.
|
|
118
|
-
* - A poll subscription's runs in its first poll's context, that request included, held until its lease ends, where a webhook subscription's runs without the request: read what it needs from the request in middleware, which provides it as a service.
|
|
119
|
-
*/
|
|
120
108
|
readonly subscription?: ((input: E["input"]["Type"]) => Effect.Effect<void, never, R | Scope.Scope>) | undefined;
|
|
121
|
-
/** How long a poll subscription's `subscription` lasts after its last poll; defaults to 5 minutes. */
|
|
122
109
|
readonly lease?: Duration.Input | undefined;
|
|
123
|
-
/**
|
|
124
|
-
* The key a subscriber of `input` is reached by, run as the subscriber, such as the room it
|
|
125
|
-
* follows: `Events.notify` and `Events.publish` given a key reach the subscribers of that key
|
|
126
|
-
* alone, and those it answers `undefined` for, who follow every key. Without it, every
|
|
127
|
-
* announcement reaches every subscriber.
|
|
128
|
-
*
|
|
129
|
-
* **Gotchas**
|
|
130
|
-
*
|
|
131
|
-
* - An occurrence a log's `emit` gives without a `key` reaches every subscriber, whatever key it follows: give each one its key.
|
|
132
|
-
*/
|
|
133
110
|
readonly key?: ((input: E["input"]["Type"]) => string | undefined | Effect.Effect<string | undefined, never, R>) | undefined;
|
|
134
111
|
}
|
|
135
112
|
/**
|
package/dist/Testing.mjs
CHANGED
|
@@ -2,7 +2,8 @@ import { clientOf } from "./testing/memory.mjs";
|
|
|
2
2
|
import { Cause, Console, Context, Effect, ErrorReporter, FileSystem, Layer, Option, Path } from "effect";
|
|
3
3
|
import { Etag, HttpEffect, HttpPlatform, HttpRouter } from "effect/http";
|
|
4
4
|
// src/testing/Testing.ts
|
|
5
|
-
const
|
|
5
|
+
const reachedRouterUnhandled = (cause) => cause.reasons.some((reason) => Cause.isFailReason(reason) && !ErrorReporter.isIgnored(reason.error) || Cause.isDieReason(reason) && !ErrorReporter.isIgnored(reason.defect));
|
|
6
|
+
const logUnhandledToProcessConsole = (cause) => reachedRouterUnhandled(cause) ? Effect.logError(cause).pipe(Effect.provideService(Console.Console, globalThis.console)) : Effect.void;
|
|
6
7
|
function layer(routes) {
|
|
7
8
|
if (!Layer.isLayer(routes)) return clientOf(routes);
|
|
8
9
|
return Layer.unwrap(Effect.gen(function* () {
|
|
@@ -10,7 +11,7 @@ function layer(routes) {
|
|
|
10
11
|
const platform = yield* Layer.build(Layer.fresh(Layer.mergeAll(HttpPlatform.layer, Path.layer, Etag.layerWeak).pipe(Layer.provideMerge(Layer.succeed(FileSystem.FileSystem, fileSystem)))));
|
|
11
12
|
const context = Context.merge(platform, yield* Effect.context());
|
|
12
13
|
const app = yield* HttpRouter.toHttpEffect(routes).pipe(Effect.provideContext(context));
|
|
13
|
-
return clientOf(HttpEffect.toWebHandlerWith(context)(Effect.tapCause(app,
|
|
14
|
+
return clientOf(HttpEffect.toWebHandlerWith(context)(Effect.tapCause(app, logUnhandledToProcessConsole)));
|
|
14
15
|
}));
|
|
15
16
|
}
|
|
16
17
|
export { layer };
|
package/dist/Webhook.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { WebhookDelivery } from "./Event.mjs";
|
|
|
2
2
|
import { Receiving } from "./contract/receiving.mjs";
|
|
3
3
|
import { Webhooks } from "./contract/webhooks.mjs";
|
|
4
4
|
import { makeReceiver } from "./webhook/receiver.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { makeWriteBehindStorage } from "./webhook/stored.mjs";
|
|
6
6
|
import { makeWebhooks } from "./webhook/subscriptions.mjs";
|
|
7
7
|
import { Duration, Effect, Layer } from "effect";
|
|
8
8
|
import { HttpRouter } from "effect/http";
|
|
@@ -24,7 +24,7 @@ function layer(options = {}) {
|
|
|
24
24
|
const maxTtl = maxTtlOf(options.maxTtl ?? "1 hour");
|
|
25
25
|
return Layer.effect(Webhooks, Effect.gen(function* () {
|
|
26
26
|
const dns = options.resolveCallbacks === false ? void 0 : yield* Dns.Dns;
|
|
27
|
-
const storage = options.persist === true ? yield* Effect.flatMap(KeyValueStore.KeyValueStore,
|
|
27
|
+
const storage = options.persist === true ? yield* Effect.flatMap(KeyValueStore.KeyValueStore, makeWriteBehindStorage) : void 0;
|
|
28
28
|
return yield* makeWebhooks({
|
|
29
29
|
maxTtl,
|
|
30
30
|
allowedCallbacks,
|
|
@@ -5,7 +5,6 @@ import { Cause, Context, Effect, Exit, Option, Predicate, Ref, Schema } from "ef
|
|
|
5
5
|
import { HttpServerResponse } from "effect/http";
|
|
6
6
|
// src/authentication/refusal.ts
|
|
7
7
|
const responseOf = (schema, error) => HttpServerResponse.jsonUnsafe(Schema.encodeUnknownSync(Schema.toCodecJson(schema))(error), { status: httpApiStatusOf(schema.ast) ?? 422 });
|
|
8
|
-
/** `error` answered as an endpoint declaring `errors` answers it, if one of them declares it. */
|
|
9
8
|
const declaredResponse = (errors, error) => {
|
|
10
9
|
const schema = errorSchemas(errors).map(declared).find((each) => Schema.is(each)(error));
|
|
11
10
|
return schema === void 0 ? void 0 : responseOf(schema, error);
|
package/dist/cli/commands.mjs
CHANGED
|
@@ -353,11 +353,6 @@ const command = (action, execute, options, errors) => {
|
|
|
353
353
|
}, ({ input, args: values, json }) => run(parsedFields(input, values), json ? void 0 : render));
|
|
354
354
|
return stdinHelp === void 0 ? Command.withDescription(projected, description) : projected.pipe(Command.withDescription(`${description}\n\n${stdinHelp}`), Command.withShortDescription(description));
|
|
355
355
|
};
|
|
356
|
-
/**
|
|
357
|
-
* The command watching `event`, named after it, with one flag per field of its input as an
|
|
358
|
-
* action's command has, and `--cursor` to resume from: it prints each occurrence and gap `watch`
|
|
359
|
-
* yields as one line of compact JSON on stdout, until it is interrupted or the watch fails.
|
|
360
|
-
*/
|
|
361
356
|
const watchCommand = (event, watch, errors) => {
|
|
362
357
|
const { flags, decode } = inputConfig(event, [], {}, void 0);
|
|
363
358
|
const encode = Schema.encodeEffect(Schema.fromJsonString(Schema.toCodecJson(ReceivedOf(event))));
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { memoized } from "./implementation.mjs";
|
|
2
2
|
import { Effect, Predicate } from "effect";
|
|
3
3
|
// src/contract/authorizer.ts
|
|
4
|
-
/**
|
|
5
|
-
* The memoized authorizer of an implementation: the `authorize` given where it holds a protected
|
|
6
|
-
* contract, which then requires one, and a rule allowing every call where it holds none, which
|
|
7
|
-
* then takes none.
|
|
8
|
-
*/
|
|
9
4
|
const authorizerOf = (holding, holdsProtected, authorize) => {
|
|
10
5
|
const { singular, module } = holding;
|
|
11
6
|
if (holdsProtected && authorize === void 0) throw new Error(`Protected ${singular}s require authorize, or ${module}.allowAll`);
|
package/dist/contract/call.mjs
CHANGED
|
@@ -2,30 +2,19 @@ import { InvalidInput } from "./errors.mjs";
|
|
|
2
2
|
import { Effect, Predicate, Schema, Stream } from "effect";
|
|
3
3
|
// src/contract/call.ts
|
|
4
4
|
const isCallOptions = (options) => Predicate.hasProperty(options, "onProgress") && Predicate.isFunction(options.onProgress);
|
|
5
|
-
/** The `onProgress` a call's arguments give after its input, where they give one. */
|
|
6
5
|
const onProgressOf = (args) => {
|
|
7
6
|
const [, options] = args;
|
|
8
7
|
return isCallOptions(options) ? options.onProgress : void 0;
|
|
9
8
|
};
|
|
10
|
-
/**
|
|
11
|
-
* How HTTP, RPC, MCP and a command decode a request's input: reporting every issue, and refusing a
|
|
12
|
-
* field the input does not declare.
|
|
13
|
-
*/
|
|
14
9
|
const inputParseOptions = {
|
|
15
10
|
errors: "all",
|
|
16
11
|
onExcessProperty: "error"
|
|
17
12
|
};
|
|
18
|
-
/** Decode `action`'s input from its JSON form by `inputParseOptions`, or fail with `InvalidInput`. */
|
|
19
13
|
const decodeInput = (action) => {
|
|
20
14
|
const decode = Schema.decodeUnknownEffect(Schema.toCodecJson(action.input), inputParseOptions);
|
|
21
15
|
return (encoded) => Effect.mapError(decode(encoded), InvalidInput.fromSchemaError);
|
|
22
16
|
};
|
|
23
17
|
const inputOf = (action, args) => args.length === 0 ? Schema.decodeEffect(Schema.toCodecJson(action.input))({}) : Effect.succeed(args[0]);
|
|
24
|
-
/**
|
|
25
|
-
* Values of `schema` as they cross a network: each encoded to its JSON, then decoded back from
|
|
26
|
-
* that JSON's text, which carries `-0` as `0`, every issue reported, answering the JSON sent and
|
|
27
|
-
* the value received.
|
|
28
|
-
*/
|
|
29
18
|
const jsonRoundTrip = (schema) => {
|
|
30
19
|
const codec = Schema.toCodecJson(schema);
|
|
31
20
|
const encode = Schema.encodeUnknownEffect(codec, { errors: "all" });
|
|
@@ -35,28 +24,16 @@ const jsonRoundTrip = (schema) => {
|
|
|
35
24
|
value: received
|
|
36
25
|
})));
|
|
37
26
|
};
|
|
38
|
-
/**
|
|
39
|
-
* A watch's input as every client sends it: read as `inputOf` reads an action's, then through
|
|
40
|
-
* its JSON, dropping undeclared fields, or `InvalidInput` reporting every issue.
|
|
41
|
-
*/
|
|
42
27
|
const watchInput = (event, input) => inputOf(event, input === void 0 ? [] : [input]).pipe(Effect.flatMap(jsonRoundTrip(event.input)), Effect.mapError(InvalidInput.fromSchemaError));
|
|
43
|
-
/** Send the input's JSON, for a client handing it to its protocol as it is. */
|
|
44
28
|
const sendingJson = (action) => Schema.encodeUnknownEffect(Schema.toCodecJson(action.input), { errors: "all" });
|
|
45
|
-
/** Send the input itself once its JSON encodes, for a client encoding it by the action's schema. */
|
|
46
29
|
const sendingValue = (action) => {
|
|
47
30
|
const encode = sendingJson(action);
|
|
48
31
|
return (input) => Effect.as(encode(input), input);
|
|
49
32
|
};
|
|
50
|
-
/**
|
|
51
|
-
* A client's method of `action`, its input checked by `check` before `send` sends what the check
|
|
52
|
-
* answers, with the call's `onProgress` where it gave one, taking decoded values, for `send` to
|
|
53
|
-
* use where the action declares `progress`.
|
|
54
|
-
*/
|
|
55
33
|
const checked = (action, check, send) => {
|
|
56
34
|
const encode = check(action);
|
|
57
35
|
return (...args) => inputOf(action, args).pipe(Effect.flatMap(encode), Effect.mapError(InvalidInput.fromSchemaError), Effect.flatMap((input) => send(input, onProgressOf(args))));
|
|
58
36
|
};
|
|
59
|
-
/** A client's method of `action` answering a stream, its input checked as `checked` checks it. */
|
|
60
37
|
const checkedStream = (action, check, send) => {
|
|
61
38
|
const method = checked(action, check, (input, onProgress) => Effect.succeed(send(input, onProgress)));
|
|
62
39
|
return (...args) => Stream.unwrap(method(...args));
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Effect, Option, Schema, SchemaIssue, SchemaTransformation } from "effect";
|
|
2
2
|
// src/contract/callback.ts
|
|
3
|
-
/** A webhook's callback: an https URL, which each delivery is POSTed to, decoded as a `URL`. */
|
|
4
3
|
const CallbackUrl = Schema.String.annotate({ description: "The https URL each delivery is POSTed to." }).pipe(Schema.decodeTo(Schema.URL, SchemaTransformation.urlFromString), Schema.check(Schema.makeFilter((url) => url.protocol === "https:" || "an https URL")));
|
|
5
4
|
/** A Standard Webhooks signing secret: as written, `whsec_` and base64, and the key it holds. */
|
|
6
5
|
const SigningSecret = Schema.Struct({
|
package/dist/contract/caller.mjs
CHANGED
|
@@ -6,23 +6,12 @@ import { Context, Effect, Function } from "effect";
|
|
|
6
6
|
* agree on a name.
|
|
7
7
|
*/
|
|
8
8
|
const Anyone = Symbol.for("@gjermundgaraba/effect-actions/Anyone");
|
|
9
|
-
/**
|
|
10
|
-
* The authentication of the surface the running call came through, which names its caller where
|
|
11
|
-
* it has a `principal`: none in process, as `Action.client` calls.
|
|
12
|
-
*/
|
|
13
9
|
const CallerKeyed = Context.Reference("effect-actions/CallerKeyed", { defaultValue: Function.constUndefined });
|
|
14
|
-
/** Whether `keyed` names each caller, its `principal` given. */
|
|
15
10
|
const isNamed = (keyed) => keyed?.principal !== void 0;
|
|
16
|
-
/**
|
|
17
|
-
* The principal of the caller of `called`, as `keyed` names it: a poll's subscriber, for its
|
|
18
|
-
* `subscription` hook, and whose idempotency keys a call's are. None where `called` is public or
|
|
19
|
-
* `keyed` has no `principal`: every caller is then one.
|
|
20
|
-
*/
|
|
21
11
|
const principalOf = (called, keyed) => keyed?.principal === void 0 || called.caller === Anyone ? Effect.undefined : Effect.map(Effect.service(called.caller), (identity) => keyed.principal?.(identity));
|
|
22
12
|
const assertAuthentication = (contracts, authentication, noun = "action") => {
|
|
23
13
|
for (const contract of contracts) if (contract.caller !== Anyone && (authentication === void 0 || contract.caller.key !== authentication.identity.key)) throw new Error(`Protected ${noun} '${contract.name}' requires its matching authentication descriptor (give it the authentication whose identity the ${noun}'s caller names)`);
|
|
24
14
|
};
|
|
25
|
-
/** Refuses a declared `caller` that is neither `Anyone` nor an identity service. */
|
|
26
15
|
const assertCaller = (caller) => {
|
|
27
16
|
if (caller !== Anyone && !Context.isKey(caller)) throw new Error("Missing caller: declare Action.Anyone or an identity service key");
|
|
28
17
|
if (caller !== Anyone && Context.isReference(caller)) throw new Error("Invalid caller: an identity is a Context.Service, not a Context.Reference");
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { Effect, Predicate, Schema } from "effect";
|
|
2
2
|
// src/contract/canonical.ts
|
|
3
|
-
/**
|
|
4
|
-
* `value`, an encoded input, as JSON written one way whatever the order of its objects' keys:
|
|
5
|
-
* what makes two inputs one, for a subscription's key and an idempotency key's input alike.
|
|
6
|
-
*/
|
|
7
3
|
const canonical = (value) => JSON.stringify(value, (_key, nested) => Predicate.isObject(nested) && !Array.isArray(nested) ? Object.fromEntries(Object.entries(nested).toSorted(([a], [b]) => a < b ? -1 : 1)) : nested);
|
|
8
|
-
/** `input`, encoded to JSON by `schema`, as `canonical` writes it. */
|
|
9
4
|
const canonicalInput = (schema, input) => Effect.map(Effect.orDie(Schema.encodeUnknownEffect(Schema.toCodecJson(schema))(input)), canonical);
|
|
10
5
|
export { canonical, canonicalInput };
|
|
@@ -3,7 +3,6 @@ import { Schema } from "effect";
|
|
|
3
3
|
export type Codec = Schema.Codec<unknown>;
|
|
4
4
|
/** Struct fields, given in place of a schema. */
|
|
5
5
|
export type Fields = Readonly<Record<string, Codec>>;
|
|
6
|
-
/** The input of a contract declared without one: an empty object. */
|
|
7
6
|
export declare const NoInput: Schema.$Record<Schema.String, Schema.Never>;
|
|
8
7
|
/** The schema a contract holds for `S`, given as a schema or as struct fields. */
|
|
9
8
|
export type CodecOf<S extends Codec | Fields> = S extends Codec ? S : S extends Schema.Struct.Fields ? keyof S extends never ? typeof NoInput : Extract<Schema.Struct<S>, Codec> : never;
|
package/dist/contract/codec.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
// src/contract/codec.ts
|
|
3
|
-
/** The input of a contract declared without one: an empty object. */
|
|
4
3
|
const NoInput = Schema.Record(Schema.String, Schema.Never);
|
|
5
4
|
const codecOf = (schema) => {
|
|
6
5
|
if (Schema.isSchema(schema)) return schema;
|