@gjermundgaraba/effect-actions 0.29.0 → 0.31.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 +2 -2
- package/dist/Action.d.mts +6 -6
- package/dist/Action.mjs +17 -18
- package/dist/ActionCli.d.mts +23 -23
- package/dist/ActionCli.mjs +4 -4
- package/dist/ActionHttp.d.mts +17 -16
- package/dist/ActionHttp.mjs +18 -22
- package/dist/ActionMcp.d.mts +8 -8
- package/dist/ActionMcp.mjs +13 -16
- package/dist/ActionRpc.d.mts +24 -23
- package/dist/ActionRpc.mjs +58 -72
- package/dist/ActionToolkit.d.mts +1 -1
- package/dist/ActionToolkit.mjs +6 -5
- package/dist/Authentication.d.mts +2 -2
- package/dist/Authentication.mjs +44 -46
- package/dist/Event.d.mts +4 -4
- package/dist/Event.mjs +3 -3
- package/dist/Webhook.d.mts +2 -0
- package/dist/Webhook.mjs +1 -0
- package/dist/authentication/provider.d.mts +15 -15
- package/dist/authentication/refusal.mjs +12 -5
- package/dist/cli/commands.d.mts +2 -2
- package/dist/cli/commands.mjs +13 -13
- package/dist/contract/authorizer.d.mts +1 -1
- package/dist/contract/call.d.mts +2 -2
- package/dist/contract/call.mjs +1 -1
- package/dist/contract/callback.mjs +6 -1
- package/dist/contract/caller.d.mts +1 -1
- package/dist/contract/declared.d.mts +1 -1
- package/dist/contract/declared.mjs +1 -1
- package/dist/contract/digest.mjs +3 -2
- package/dist/contract/feed.d.mts +1 -1
- package/dist/contract/feed.mjs +12 -10
- package/dist/contract/hub.d.mts +1 -1
- package/dist/contract/idempotency.d.mts +1 -1
- package/dist/contract/idempotency.mjs +4 -4
- package/dist/contract/implementation.d.mts +27 -27
- package/dist/contract/implementation.mjs +8 -18
- package/dist/contract/input-check.d.mts +3 -3
- package/dist/contract/listed.d.mts +1 -1
- package/dist/contract/listed.mjs +1 -1
- package/dist/contract/pages.d.mts +1 -1
- package/dist/contract/push.d.mts +2 -2
- package/dist/contract/push.mjs +5 -7
- package/dist/contract/receiving.d.mts +2 -2
- package/dist/contract/receiving.mjs +1 -1
- package/dist/contract/recent.mjs +3 -2
- package/dist/contract/serving.mjs +18 -18
- package/dist/contract/stream.d.mts +1 -1
- package/dist/contract/stream.mjs +14 -2
- package/dist/contract/subscribe.mjs +7 -2
- package/dist/contract/transient.mjs +1 -1
- package/dist/contract/watch.d.mts +1 -1
- package/dist/contract/watch.mjs +5 -8
- package/dist/contract/webhooks.d.mts +1 -1
- package/dist/contract/webhooks.mjs +17 -6
- package/dist/http/client.d.mts +9 -9
- package/dist/http/client.mjs +6 -4
- package/dist/http/events.d.mts +6 -6
- package/dist/http/events.mjs +7 -5
- package/dist/http/placed.d.mts +3 -3
- package/dist/http/placed.mjs +5 -5
- package/dist/http/streamed.d.mts +3 -2
- package/dist/http/streamed.mjs +11 -6
- package/dist/http/watch.mjs +1 -1
- package/dist/mcp/bridge.mjs +13 -22
- package/dist/mcp/client.d.mts +10 -10
- package/dist/mcp/client.mjs +5 -14
- package/dist/mcp/events.mjs +1 -1
- package/dist/mcp/progress.mjs +11 -1
- package/dist/mcp/reply.d.mts +1 -1
- package/dist/mcp/watch.mjs +4 -4
- package/dist/rpc/watch.mjs +3 -5
- package/dist/webhook/health.mjs +25 -28
- package/dist/webhook/receiver.mjs +4 -7
- package/dist/webhook/stored.mjs +1 -1
- package/dist/webhook/subscriptions.mjs +19 -17
- package/docs/Action.md +1 -1
- package/docs/setup-failures.md +1 -1
- package/docs/setup.md +4 -4
- package/package.json +11 -12
package/README.md
CHANGED
|
@@ -76,10 +76,10 @@ Effect.gen(function* () {
|
|
|
76
76
|
## Install
|
|
77
77
|
|
|
78
78
|
```sh
|
|
79
|
-
pnpm add @gjermundgaraba/effect-actions effect@~4.1.
|
|
79
|
+
pnpm add @gjermundgaraba/effect-actions effect@~4.1.3
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
It needs TypeScript 7 or newer and is ESM only ([docs/setup.md](docs/setup.md#install)). Add `@effect/platform-node@~4.1.
|
|
82
|
+
It needs TypeScript 7 or newer and is ESM only ([docs/setup.md](docs/setup.md#install)). Add `@effect/platform-node@~4.1.3` to serve or run a CLI from Node, and `@types/node` for its `node:` imports. Every module is a subpath import (`.../Action`, `.../ActionHttp`, ...); there is no package root, so a contracts-only bundle never loads a server.
|
|
83
83
|
|
|
84
84
|
## Examples
|
|
85
85
|
|
package/dist/Action.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Authorizer, Deferred as Deferred$1 } from "./contract/authorizer.mjs";
|
|
2
|
+
import { Call } from "./contract/call.mjs";
|
|
2
3
|
import { Anyone } from "./contract/caller.mjs";
|
|
4
|
+
import { Codec, CodecOf, Fields, NoInput } from "./contract/codec.mjs";
|
|
3
5
|
import { BuiltIn, Forbidden, InvalidInput, Issue, Refusal, Unauthenticated } from "./contract/errors.mjs";
|
|
4
|
-
import { EventBuildError, EventBuildServices, EventOf, EventRequestOf, HoldingEvents, ServingEvents } from "./contract/feed.mjs";
|
|
5
6
|
import { Any as Any$1, Received, SubscriptionError } from "./Event.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import { ActionOf, AnyImplementation, Authorize, BuildError, BuildServices, Holding, Implementation, Known, Member, Offered, OptionalUnless, Protected, RequestOf, SelectedEventsOf, SelectedOf, Served, Serving } from "./contract/implementation.mjs";
|
|
8
|
-
import { Authorizer, Deferred as Deferred$1 } from "./contract/authorizer.mjs";
|
|
9
|
-
import { Call } from "./contract/call.mjs";
|
|
7
|
+
import { EventBuildError, EventBuildServices, EventOf, EventRequestOf, HoldingEvents, ServingEvents } from "./contract/feed.mjs";
|
|
10
8
|
import { Idempotency, layerIdempotency } from "./contract/idempotency.mjs";
|
|
9
|
+
import { ActionOf, AnyImplementation, Authorize, BuildError, BuildServices, Holding, Implementation, Known, Member, Offered, OptionalUnless, Protected, RequestOf, SelectedEventsOf, SelectedOf, Served, Serving } from "./contract/implementation.mjs";
|
|
10
|
+
import { ReportingOf } from "./contract/progress.mjs";
|
|
11
11
|
import { Answer, Stream, StreamOf } from "./contract/stream.mjs";
|
|
12
12
|
import { WatchArgs } from "./contract/watch.mjs";
|
|
13
13
|
import { Image } from "./contract/media.mjs";
|
package/dist/Action.mjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
+
import { authorizerOf } from "./contract/authorizer.mjs";
|
|
2
|
+
import { checked, checkedStream, jsonRoundTrip, watchInput } from "./contract/call.mjs";
|
|
1
3
|
import { Anyone, assertCaller } from "./contract/caller.mjs";
|
|
2
|
-
import {
|
|
4
|
+
import { codecOf } from "./contract/codec.mjs";
|
|
3
5
|
import { assertDistinctTags, errorList, projectedErrors } from "./contract/declared.mjs";
|
|
4
|
-
import {
|
|
6
|
+
import { NotServed, SubscriptionError } from "./Event.mjs";
|
|
7
|
+
import { acquireFeeds, eventsOf } from "./contract/feed.mjs";
|
|
8
|
+
import { Idempotency, keyed, layerIdempotency } from "./contract/idempotency.mjs";
|
|
9
|
+
import { Implementation, acquire, builtWith, elementsOf, memoized, toList, uniqueKey } from "./contract/implementation.mjs";
|
|
5
10
|
import { assertKnown, assertName, assertOnce, heldOnce } from "./contract/names.mjs";
|
|
6
11
|
import { progressSink } from "./contract/progress.mjs";
|
|
7
|
-
import { codecOf } from "./contract/codec.mjs";
|
|
8
|
-
import { Stream, elementOf } from "./contract/stream.mjs";
|
|
9
|
-
import { Implementation, acquire, builtWith, elementsOf, memoized, provideBuilders, toList, uniqueKey } from "./contract/implementation.mjs";
|
|
10
|
-
import { authorizerOf } from "./contract/authorizer.mjs";
|
|
11
|
-
import { inputOf, jsonRoundTrip, onProgressOf, watchInput } from "./contract/call.mjs";
|
|
12
|
-
import { acquireFeeds, eventsOf, feedBuilders } from "./contract/feed.mjs";
|
|
13
|
-
import { NotServed, SubscriptionError } from "./Event.mjs";
|
|
14
12
|
import { polledOn, queuedPush, readOn } from "./contract/push.mjs";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
13
|
+
import { buildersOf, provideServed, selectFrom } from "./contract/serving.mjs";
|
|
14
|
+
import { Stream, elementOf } from "./contract/stream.mjs";
|
|
17
15
|
import { watching } from "./contract/watch.mjs";
|
|
18
|
-
import {
|
|
16
|
+
import { BuiltIn, Forbidden, InvalidInput, Refusal, Unauthenticated } from "./contract/errors.mjs";
|
|
17
|
+
import { Image } from "./contract/media.mjs";
|
|
18
|
+
import { InputCheck } from "./contract/input-check.mjs";
|
|
19
19
|
import { Array as Array$1, Cause, Effect, Function, Layer, Predicate, Schema, Stream as Stream$1 } from "effect";
|
|
20
20
|
// src/contract/Action.ts
|
|
21
21
|
function make(name, options) {
|
|
@@ -91,7 +91,7 @@ function implement(actions, handlers, options) {
|
|
|
91
91
|
return new Implementation(listed, memoized(recorded), authorizer);
|
|
92
92
|
}
|
|
93
93
|
function layer(implementations) {
|
|
94
|
-
return Layer.empty.pipe(
|
|
94
|
+
return Layer.empty.pipe(provideServed(toList(implementations), eventsOf(implementations)));
|
|
95
95
|
}
|
|
96
96
|
const received = (schema) => {
|
|
97
97
|
const sent = jsonRoundTrip(schema);
|
|
@@ -101,15 +101,14 @@ const mapFailuresInPlace = (cause, failure) => Effect.map(Effect.forEach(cause.r
|
|
|
101
101
|
onFailure: (refused) => Cause.combine(Cause.die(refused), Cause.die(reason.error)),
|
|
102
102
|
onSuccess: (decoded) => Cause.fail(Predicate.isError(reason.error) && Predicate.isError(decoded) ? Object.assign(decoded, { stack: reason.error.stack }) : decoded)
|
|
103
103
|
}).pipe(Effect.map((mapped) => Cause.annotate(mapped, Cause.reasonAnnotations(reason)))) : Effect.succeed(Cause.fromReasons([reason]))), (causes) => Cause.fromReasons(causes.flatMap(({ reasons }) => reasons)));
|
|
104
|
+
const receivedInput = (action) => received(action.input);
|
|
104
105
|
const methodOf = (action, run) => {
|
|
105
|
-
const input = received(action.input);
|
|
106
106
|
const element = elementOf(action.success);
|
|
107
107
|
const success = received(element ?? action.success);
|
|
108
108
|
const failure = received(Schema.Union(projectedErrors(action)));
|
|
109
109
|
const declared = (cause) => Effect.flatMap(mapFailuresInPlace(cause, failure), Effect.failCause);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return (...args) => called(args).pipe(Effect.flatMap((answer) => Effect.catchCause(answer, declared)), Effect.flatMap((value) => Effect.orDie(success(value))));
|
|
110
|
+
if (element !== void 0) return checkedStream(action, receivedInput, (input, onProgress) => elementsOf(run(input, progressSink(onProgress))).pipe(Stream$1.catchCause((cause) => Stream$1.fromEffect(declared(cause))), Stream$1.mapEffect((value) => Effect.orDie(success(value)))));
|
|
111
|
+
return checked(action, receivedInput, (input, onProgress) => Effect.catchCause(run(input, progressSink(onProgress)), declared).pipe(Effect.flatMap((value) => Effect.orDie(success(value)))));
|
|
113
112
|
};
|
|
114
113
|
const watcherOf = (feeds) => (event, input, options) => {
|
|
115
114
|
const feed = feeds.find((held) => held.event === event);
|
|
@@ -131,7 +130,7 @@ function client(served, options) {
|
|
|
131
130
|
const { apps, events } = selectFrom(served, options?.actions);
|
|
132
131
|
assertOnce("action", apps.flatMap((app) => app.actions), heldOnce);
|
|
133
132
|
assertOnce("event", events.flatMap((app) => app.events), heldOnce);
|
|
134
|
-
return Effect.map(builtWith(
|
|
133
|
+
return Effect.map(builtWith(buildersOf(apps, events), Effect.all([acquire(apps, void 0), acquireFeeds(events)])), ([bound, feeds]) => ({
|
|
135
134
|
...Object.fromEntries(bound.map(([action, run]) => [action.name, methodOf(action, run)])),
|
|
136
135
|
...feeds.length === 0 ? {} : { watch: watcherOf(feeds) }
|
|
137
136
|
}));
|
package/dist/ActionCli.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BuiltIn } from "./contract/errors.mjs";
|
|
2
|
+
import { Any } from "./Action.mjs";
|
|
3
|
+
import { Declaring } from "./contract/declared.mjs";
|
|
4
|
+
import { Any as Any$1, SubscriptionError } from "./Event.mjs";
|
|
2
5
|
import { EventBuildError, EventBuildServices, EventOf, EventRequestOf, ServingEvents } from "./contract/feed.mjs";
|
|
3
|
-
import { Any, SubscriptionError } from "./Event.mjs";
|
|
4
6
|
import { ActionOf, BuildError, BuildServices, Holding, Known, Member, RequestOf, Selected, SelectedEvents, SelectedEventsOf, SelectedOf, Selection, Served, ServedActions } from "./contract/implementation.mjs";
|
|
5
7
|
import { Receiving } from "./contract/receiving.mjs";
|
|
6
8
|
import { WatchArgs } from "./contract/watch.mjs";
|
|
7
|
-
import { Any as Any$1 } from "./Action.mjs";
|
|
8
|
-
import { Declaring } from "./contract/declared.mjs";
|
|
9
9
|
import { AnyHttp, Client, WatchError } from "./http/client.mjs";
|
|
10
10
|
import "./ActionHttp.mjs";
|
|
11
11
|
import { Options, UserError } from "./cli/commands.mjs";
|
|
@@ -13,7 +13,7 @@ import { Effect, Stream } from "effect";
|
|
|
13
13
|
import { HttpClient } from "effect/http";
|
|
14
14
|
import { CliError, Command } from "effect/cli";
|
|
15
15
|
interface AnyBinding extends Declaring {
|
|
16
|
-
readonly actions: readonly Any
|
|
16
|
+
readonly actions: readonly Any[];
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Make a command of your own fail as a derived command does. Give it what the command calls, the
|
|
@@ -29,12 +29,12 @@ interface AnyBinding extends Declaring {
|
|
|
29
29
|
* - A failure left unmapped, one call's included, is reported as a crash, `ERROR (#n)` with a stack trace: pipe the whole Effect through it, once.
|
|
30
30
|
* - To add context, such as how far a batch got, print it before this in the pipe, `Effect.tapError(() => Console.error(…))`: a `UserError` wrapped around the result puts its JSON mid-sentence and hides the action's failure from `catchReason`.
|
|
31
31
|
*/
|
|
32
|
-
export declare const toUserError: (calls: AnyBinding | readonly Any
|
|
32
|
+
export declare const toUserError: (calls: AnyBinding | readonly Any[]) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, UserError<Exclude<E, CliError.CliError>> | Exclude<E, Exclude<E, CliError.CliError>>, R>;
|
|
33
33
|
/**
|
|
34
34
|
* An aggregate command of the actions `A`: its name, the actions that are its subcommands,
|
|
35
35
|
* and their options.
|
|
36
36
|
*/
|
|
37
|
-
interface Options$1<A extends Any
|
|
37
|
+
interface Options$1<A extends Any | Any$1 = Any | Any$1> {
|
|
38
38
|
/** The aggregate command's name. */
|
|
39
39
|
readonly name: string;
|
|
40
40
|
/**
|
|
@@ -51,7 +51,7 @@ interface Options$1<A extends Any$1 | Any = Any$1 | Any> {
|
|
|
51
51
|
* The options of each subcommand, keyed by its action's name, as `command` takes them:
|
|
52
52
|
* `{ readFile: { positional: ["path"], render } }`.
|
|
53
53
|
*/
|
|
54
|
-
readonly commands?: { readonly [K in Extract<A, Any
|
|
54
|
+
readonly commands?: { readonly [K in Extract<A, Any> as K["name"]]?: Options<K>; };
|
|
55
55
|
/**
|
|
56
56
|
* Commands of your own beside the derived ones, as `Command.withSubcommands` takes them:
|
|
57
57
|
* `[importLinks]`, each made with Effect CLI's `Command.make` and printing its output itself,
|
|
@@ -72,14 +72,14 @@ type OwnCommand<Own extends Subcommands> = Subcommands extends Own ? never : Own
|
|
|
72
72
|
type CommandsOf<O> = O extends unknown ? "commands" extends keyof O ? NonNullable<O["commands" & keyof O]> : never : never;
|
|
73
73
|
type KeysOf<C> = C extends unknown ? keyof C : never;
|
|
74
74
|
type CommandOf<C, K> = C extends unknown ? K extends keyof C ? C[K] : never : never;
|
|
75
|
-
type KnownOptions<O, Keys, A extends Any
|
|
76
|
-
readonly commands?: Known<CommandsOf<O>, { readonly [K in A["name"]]: Options<A>; }> & { readonly [K in KeysOf<CommandsOf<O>>]?: Known<CommandOf<CommandsOf<O>, K>, Options<Any
|
|
75
|
+
type KnownOptions<O, Keys, A extends Any> = Known<O, Keys> & ([CommandsOf<O>] extends [never] ? unknown : {
|
|
76
|
+
readonly commands?: Known<CommandsOf<O>, { readonly [K in A["name"]]: Options<A>; }> & { readonly [K in KeysOf<CommandsOf<O>>]?: Known<CommandOf<CommandsOf<O>, K>, Options<Any>>; };
|
|
77
77
|
});
|
|
78
|
-
type Owning<App, A extends Any
|
|
79
|
-
type Local<App, A extends Any
|
|
78
|
+
type Owning<App, A extends Any> = App extends unknown ? A extends ActionOf<App> ? App : never : never;
|
|
79
|
+
type Local<App, A extends Any> = Effect.Effect<A["success"]["Type"], A["error"][number]["Type"] | BuildError<App, A> | BuiltIn, RequestOf<App, A> | BuildServices<App, A>>;
|
|
80
80
|
type LocalCall<Apps extends Served, O> = [SelectedOf<O, Apps>] extends [never] ? never : Local<Holding<Member<Apps>, SelectedOf<O, Apps>>, SelectedOf<O, Apps>>;
|
|
81
|
-
type LocalWatch<App, Listed extends Any> = [ServingEvents<App, Listed>] extends [never] ? never : Effect.Effect<void, SubscriptionError | BuiltIn | EventBuildError<App, Listed>, EventRequestOf<App, ServingEvents<App, Listed>> | EventBuildServices<App, Listed>>;
|
|
82
|
-
type Watched<M, E extends Any> = M extends {
|
|
81
|
+
type LocalWatch<App, Listed extends Any$1> = [ServingEvents<App, Listed>] extends [never] ? never : Effect.Effect<void, SubscriptionError | BuiltIn | EventBuildError<App, Listed>, EventRequestOf<App, ServingEvents<App, Listed>> | EventBuildServices<App, Listed>>;
|
|
82
|
+
type Watched<M, E extends Any$1> = M extends {
|
|
83
83
|
readonly watch: (event: E, ...args: WatchArgs<E, never>) => Stream.Stream<unknown, infer WE, infer WR>;
|
|
84
84
|
} ? {
|
|
85
85
|
readonly error: WE;
|
|
@@ -88,8 +88,8 @@ type Watched<M, E extends Any> = M extends {
|
|
|
88
88
|
readonly error: never;
|
|
89
89
|
readonly services: never;
|
|
90
90
|
};
|
|
91
|
-
type WatchFailure<H extends AnyHttp, C, E extends Any> = [E] extends [never] ? never : C extends Effect.Effect<infer M, infer CE, unknown> ? CE | Watched<M, E>["error"] : WatchError<E, H>;
|
|
92
|
-
type WatchServices<C, E extends Any> = [E] extends [never] ? never : C extends Effect.Effect<infer M, unknown, infer CR> ? CR | Watched<M, E>["services"] : HttpClient.HttpClient;
|
|
91
|
+
type WatchFailure<H extends AnyHttp, C, E extends Any$1> = [E] extends [never] ? never : C extends Effect.Effect<infer M, infer CE, unknown> ? CE | Watched<M, E>["error"] : WatchError<E, H>;
|
|
92
|
+
type WatchServices<C, E extends Any$1> = [E] extends [never] ? never : C extends Effect.Effect<infer M, unknown, infer CR> ? CR | Watched<M, E>["services"] : HttpClient.HttpClient;
|
|
93
93
|
/**
|
|
94
94
|
* Project one implemented action into a native Effect CLI command that runs its handler in
|
|
95
95
|
* process, behind its implementation's authorization. It is named after the action in kebab
|
|
@@ -110,14 +110,14 @@ type WatchServices<C, E extends Any> = [E] extends [never] ? never : C extends E
|
|
|
110
110
|
* - Each run builds the action's implementation, its builder and an authorizer an Effect builds, and releases them after the call, even where the host already built them; implementations passed beside it are not built.
|
|
111
111
|
* - A field named like a global flag (`help`, `version`, `log-level`) is no clash: its flag shadows the global one on this command.
|
|
112
112
|
*/
|
|
113
|
-
export declare const command: <const Apps extends ServedActions, A extends ActionOf<Member<Apps>>, const O = {}>(implementations: Apps, action: A, options?: O & NoInfer<Options<A>> & NoInfer<Known<O, Options<Any
|
|
113
|
+
export declare const command: <const Apps extends ServedActions, A extends ActionOf<Member<Apps>>, const O = {}>(implementations: Apps, action: A, options?: O & NoInfer<Options<A>> & NoInfer<Known<O, Options<Any>>>) => Command.Command<string, never, {}, Failing<Effect.Error<Local<Owning<Member<Apps>, A>, A>>>, Effect.Services<Local<Owning<Member<Apps>, A>, A>>>;
|
|
114
114
|
/**
|
|
115
115
|
* Project one action of an HTTP binding into a native Effect CLI command, derived as `command`
|
|
116
116
|
* derives it, that calls the action through `client`'s method and fails as the method does, or
|
|
117
117
|
* as the Effect building the client does. It runs nothing locally and names no caller: the
|
|
118
118
|
* server verifies the credentials its client sends.
|
|
119
119
|
*/
|
|
120
|
-
export declare function remoteCommand<const H extends AnyHttp, A extends H["actions"][number], const O = {}, C extends ClientOf<H, A> | undefined = undefined>(binding: H, action: A, options?: O & NoInfer<Options<A>> & NoInfer<Known<O, RemoteKeys<Options<Any
|
|
120
|
+
export declare function remoteCommand<const H extends AnyHttp, A extends H["actions"][number], const O = {}, C extends ClientOf<H, A> | undefined = undefined>(binding: H, action: A, options?: O & NoInfer<Options<A>> & NoInfer<Known<O, RemoteKeys<Options<Any>>>> & Calling<C>): Command.Command<string, never, {}, Failing<CallFailure<H, C, A>>, CallServices<C, A>>;
|
|
121
121
|
/** The `client` option of `remote` and `remoteCommand`, declared once for both. */
|
|
122
122
|
export interface Calling<C> {
|
|
123
123
|
/**
|
|
@@ -137,18 +137,18 @@ export interface Calling<C> {
|
|
|
137
137
|
*/
|
|
138
138
|
readonly client?: C;
|
|
139
139
|
}
|
|
140
|
-
type ClientOf<H extends AnyHttp, A extends Any
|
|
141
|
-
type Needed<O, L extends readonly unknown[], All extends Any
|
|
142
|
-
type NeededEvents<O, L extends readonly unknown[], All extends Any> = "actions" extends (O extends unknown ? keyof O : never) ? SelectedEvents<O, All> : Extract<L[number], All>;
|
|
140
|
+
type ClientOf<H extends AnyHttp, A extends Any, E extends Any$1 = never> = Effect.Effect<Pick<Client<H, unknown, unknown>, A["name"] | ([E] extends [never] ? never : "watch")>, unknown, unknown>;
|
|
141
|
+
type Needed<O, L extends readonly unknown[], All extends Any> = "actions" extends (O extends unknown ? keyof O : never) ? Selected<O, All> : Extract<L[number], All>;
|
|
142
|
+
type NeededEvents<O, L extends readonly unknown[], All extends Any$1> = "actions" extends (O extends unknown ? keyof O : never) ? SelectedEvents<O, All> : Extract<L[number], All>;
|
|
143
143
|
type RemoteKeys<Keys> = Keys & {
|
|
144
144
|
readonly client?: unknown;
|
|
145
145
|
};
|
|
146
146
|
type Failing<F> = [F] extends [never] ? never : UserError<Exclude<F, CliError.CliError>> | Extract<F, CliError.CliError>;
|
|
147
|
-
type Called<M, A extends Any
|
|
147
|
+
type Called<M, A extends Any> = A extends unknown ? A["name"] extends keyof M ? M[A["name"]] extends ((...input: never) => infer Call) ? Call : never : never : never;
|
|
148
148
|
type CallError<Call> = Effect.Error<Call> | Stream.Error<Call>;
|
|
149
149
|
type CallRequirements<Call> = Effect.Services<Call> | Stream.Services<Call>;
|
|
150
|
-
type CallFailure<H extends AnyHttp, C, A extends Any
|
|
151
|
-
type CallServices<C, A extends Any
|
|
150
|
+
type CallFailure<H extends AnyHttp, C, A extends Any> = C extends Effect.Effect<infer M, infer CE, unknown> ? CE | CallError<Called<M, A>> : CallError<Called<Client<H>, A>>;
|
|
151
|
+
type CallServices<C, A extends Any> = C extends Effect.Effect<infer M, unknown, infer CR> ? CR | CallRequirements<Called<M, A>> : HttpClient.HttpClient;
|
|
152
152
|
/**
|
|
153
153
|
* Project the implemented actions, every one or those `actions` selects, as subcommands of one
|
|
154
154
|
* aggregate command, each derived as `command` derives it and run in process. `commands` gives a
|
package/dist/ActionCli.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { client } from "./Action.mjs";
|
|
1
2
|
import { bindingErrors, eventErrors, projectedErrors } from "./contract/declared.mjs";
|
|
2
|
-
import { assertDistinct, assertKnown } from "./contract/names.mjs";
|
|
3
|
-
import { progressSink } from "./contract/progress.mjs";
|
|
4
|
-
import { elementOf } from "./contract/stream.mjs";
|
|
5
3
|
import { Implementation, acquire, assertHeld, elementsOf, notHeld, toList } from "./contract/implementation.mjs";
|
|
6
4
|
import { selection } from "./contract/listed.mjs";
|
|
5
|
+
import { assertDistinct, assertKnown } from "./contract/names.mjs";
|
|
6
|
+
import { progressSink } from "./contract/progress.mjs";
|
|
7
7
|
import { selectFrom } from "./contract/serving.mjs";
|
|
8
|
-
import {
|
|
8
|
+
import { elementOf } from "./contract/stream.mjs";
|
|
9
9
|
import { client as client$1 } from "./ActionHttp.mjs";
|
|
10
10
|
import { command as command$1, failingAsDerived, watchCommand } from "./cli/commands.mjs";
|
|
11
11
|
import { Cause, Effect, Logger, Runtime, Stream } from "effect";
|
package/dist/ActionHttp.d.mts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { Any, DescriptorOf, LayerIdentity, Matching, PublicOnly, RemoteRequest, Required, ServedProvider, ServerBuildServices, VerifierError } from "./authentication/provider.mjs";
|
|
2
|
+
import { Any as Any$1, Errors } from "./Action.mjs";
|
|
1
3
|
import { Anyone } from "./contract/caller.mjs";
|
|
4
|
+
import { Certain, ErrorsOf } from "./contract/declared.mjs";
|
|
2
5
|
import { BuiltIn, BuiltIns } from "./contract/errors.mjs";
|
|
6
|
+
import { Any as Any$2 } from "./Event.mjs";
|
|
3
7
|
import { EventBuildError, EventBuildServices, EventServedRequest, HoldingEvents, ServingEvents } from "./contract/feed.mjs";
|
|
4
|
-
import { Any } from "./Event.mjs";
|
|
5
8
|
import { BuildError, Holding, Known, Member, MiddlewareOf, Selected, SelectedEvents, Served } from "./contract/implementation.mjs";
|
|
6
|
-
import { Any as Any$1, Errors } from "./Action.mjs";
|
|
7
|
-
import { Certain, ErrorsOf } from "./contract/declared.mjs";
|
|
8
|
-
import { Any as Any$2, DescriptorOf, LayerIdentity, Matching, PublicOnly, RemoteRequest, Required, ServedProvider, ServerBuildServices, VerifierError } from "./authentication/provider.mjs";
|
|
9
9
|
import { Only } from "./contract/listed.mjs";
|
|
10
10
|
import { SubscriptionOf } from "./contract/push.mjs";
|
|
11
|
-
import { pageOf, sentOf } from "./http/events.mjs";
|
|
12
11
|
import { AnyHttp, Client, MethodError, Options, WatchError } from "./http/client.mjs";
|
|
12
|
+
import { pageOf, sentOf } from "./http/events.mjs";
|
|
13
13
|
import { SuccessOf } from "./http/streamed.mjs";
|
|
14
14
|
import { Placed, placed } from "./http/placed.mjs";
|
|
15
15
|
import { Context, Effect, FileSystem, Layer, Path, Schema, Types } from "effect";
|
|
@@ -34,11 +34,11 @@ type Through<M extends Middleware, R> = number extends M["length"] ? R | HttpApi
|
|
|
34
34
|
type ServerOnly<M extends Middleware, E extends Errors> = [Exclude<HttpApiMiddleware.Error<IdOf<M[number]>>, Extract<Certain<E>, Errors[number]>["Type"] | BuiltIn> | HttpApiMiddleware.MiddlewareClient<IdOf<M[number]>>] extends [never] ? unknown : {
|
|
35
35
|
readonly "Layer middleware fails only with the binding's errors and needs no client": never;
|
|
36
36
|
};
|
|
37
|
-
type HttpLayer<H extends AnyHttp, Apps extends Served, M extends Middleware, A extends Any$1 = H["actions"][number], E extends Any = H["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> | HttpRouter.HttpRouter | HttpRouter.Request.From<"Requires", LayerRequest<Member<Apps>, A, E, M>> | ServedProvider<Member<Apps>, A, H extends {
|
|
37
|
+
type HttpLayer<H extends AnyHttp, Apps extends Served, M extends Middleware, A extends Any$1 = H["actions"][number], E extends Any$2 = H["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> | HttpRouter.HttpRouter | HttpRouter.Request.From<"Requires", LayerRequest<Member<Apps>, A, E, M>> | ServedProvider<Member<Apps>, A, H extends {
|
|
38
38
|
readonly authentication: infer D;
|
|
39
39
|
} ? D : never, ServingEvents<Member<Apps>, E>> | IdOf<M[number]> | Etag.Generator | FileSystem.FileSystem | HttpPlatform.HttpPlatform | Path.Path>;
|
|
40
40
|
/** `ActionHttp.layer`'s options. */
|
|
41
|
-
export interface LayerOptions<M extends Middleware = [], C extends Any$1 | Any = never> {
|
|
41
|
+
export interface LayerOptions<M extends Middleware = [], C extends Any$1 | Any$2 = never> {
|
|
42
42
|
/**
|
|
43
43
|
* The actions and event types it serves, among the binding's the implementations hold:
|
|
44
44
|
* `[GetUser, UserRenamed]`, exactly those. Defaults to every one of them.
|
|
@@ -59,7 +59,7 @@ export interface LayerOptions<M extends Middleware = [], C extends Any$1 | Any =
|
|
|
59
59
|
*/
|
|
60
60
|
readonly middleware?: M;
|
|
61
61
|
}
|
|
62
|
-
type LayerRequest<App, A extends Any$1, E extends Any, M extends Middleware> = Exclude<Through<M, RemoteRequest<App, A> | EventServedRequest<App, E>>, HttpRouter.Provided | LayerIdentity<App, A, E>>;
|
|
62
|
+
type LayerRequest<App, A extends Any$1, E extends Any$2, M extends Middleware> = Exclude<Through<M, RemoteRequest<App, A> | EventServedRequest<App, E>>, HttpRouter.Provided | LayerIdentity<App, A, E>>;
|
|
63
63
|
/** Contract-level configuration shared by servers and clients. */
|
|
64
64
|
interface Options$1<E extends Errors = Errors> {
|
|
65
65
|
/**
|
|
@@ -87,18 +87,18 @@ interface Options$1<E extends Errors = Errors> {
|
|
|
87
87
|
*
|
|
88
88
|
* - One descriptor per binding: actions of a second identity take a second binding with its own `prefix`, and a public action may be in both.
|
|
89
89
|
*/
|
|
90
|
-
readonly authentication?: Any
|
|
90
|
+
readonly authentication?: Any;
|
|
91
91
|
}
|
|
92
92
|
type EndpointError<A extends Any$1, E extends Errors, D> = Schema.toCodecJson<A["error"][number] | E[number] | VerifierError<A, D> | BuiltIns>;
|
|
93
93
|
type Endpoint<A extends Any$1, E extends Errors, D> = A extends Any$1 ? HttpApiEndpoint.HttpApiEndpoint<A["name"], "POST", `/${string}`, never, never, Schema.toCodecJson<A["input"]>, never, SuccessOf<A, EndpointError<A, E, D>>, EndpointError<A, E, D>> : never;
|
|
94
|
-
type EventEndpoint<V extends Any, E extends Errors, D> = V extends Any ? HttpApiEndpoint.HttpApiEndpoint<V["name"], "POST", `/${string}`, never, never, Schema.toCodecJson<ReturnType<typeof SubscriptionOf<V>>>, never, Schema.toCodecJson<ReturnType<typeof pageOf<V>>> | ReturnType<typeof sentOf<V>>, Schema.toCodecJson<E[number] | VerifierError<V, D> | BuiltIns>> : never;
|
|
95
|
-
type Api<Actions extends readonly Any$1[], E extends Errors, D, Events extends readonly Any[]> = HttpApi.HttpApi<"actions", HttpApiGroup.HttpApiGroup<string, Endpoint<Actions[number], E, D> | EventEndpoint<Events[number], E, D>, true>>;
|
|
94
|
+
type EventEndpoint<V extends Any$2, E extends Errors, D> = V extends Any$2 ? HttpApiEndpoint.HttpApiEndpoint<V["name"], "POST", `/${string}`, never, never, Schema.toCodecJson<ReturnType<typeof SubscriptionOf<V>>>, never, Schema.toCodecJson<ReturnType<typeof pageOf<V>>> | ReturnType<typeof sentOf<V>>, Schema.toCodecJson<E[number] | VerifierError<V, D> | BuiltIns>> : never;
|
|
95
|
+
type Api<Actions extends readonly Any$1[], E extends Errors, D, Events extends readonly Any$2[]> = HttpApi.HttpApi<"actions", HttpApiGroup.HttpApiGroup<string, Endpoint<Actions[number], E, D> | EventEndpoint<Events[number], E, D>, true>>;
|
|
96
96
|
/**
|
|
97
97
|
* An HTTP binding: actions and event types, the errors every endpoint declares, and where they
|
|
98
98
|
* are mounted. Plain data, so a copy of it, or one made by another installed copy of this
|
|
99
99
|
* package, serves the same; `layer` serves it and `client` calls it.
|
|
100
100
|
*/
|
|
101
|
-
export interface Binding<Actions extends readonly Any$1[], E extends Errors = [], D extends Any
|
|
101
|
+
export interface Binding<Actions extends readonly Any$1[], E extends Errors = [], D extends Any | undefined = undefined, Events extends readonly Any$2[] = readonly []> {
|
|
102
102
|
/** Its protected actions' authentication descriptor, or `undefined` without one. */
|
|
103
103
|
readonly authentication: D;
|
|
104
104
|
/** The exact actions bound to this binding. */
|
|
@@ -136,11 +136,11 @@ export interface Binding<Actions extends readonly Any$1[], E extends Errors = []
|
|
|
136
136
|
* - An action and an event type of one name, or an event type listed twice, throw when `make` is called: they would share a client's method.
|
|
137
137
|
* - A protected event type, where `authentication` has `principal`, is bound at `POST <prefix>/events/<name>/subscribe` and `/unsubscribe` too, for `Webhook.layer`'s delivery, and OpenAPI lists both: a binding cannot know whether its server provides that layer, and without it they answer a 409 `Event.SubscriptionError`, reason `Unsupported`.
|
|
138
138
|
*/
|
|
139
|
-
export declare function make<const Contracts extends ReadonlyArray<(Any$1 | Any) & {
|
|
139
|
+
export declare function make<const Contracts extends ReadonlyArray<(Any$1 | Any$2) & {
|
|
140
140
|
readonly caller: typeof Anyone;
|
|
141
|
-
}>>(contracts: Contracts, options?: Pick<Options$1, "prefix">): Binding<Only<Contracts, Any$1>, [], undefined, Only<Contracts, Any>>;
|
|
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
|
-
export declare function make<const Contracts extends ReadonlyArray<Any$1 | Any>>(contracts: Contracts & PublicOnly<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$2>>;
|
|
142
|
+
export declare function make<const Contracts extends ReadonlyArray<Any$1 | Any$2>, 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$2>>;
|
|
143
|
+
export declare function make<const Contracts extends ReadonlyArray<Any$1 | Any$2>>(contracts: Contracts & PublicOnly<Contracts>): Binding<Only<Contracts, Any$1>, [], undefined, Only<Contracts, Any$2>>;
|
|
144
144
|
/**
|
|
145
145
|
* Serve the binding's actions and event types among `implementations` in one layer, or those its
|
|
146
146
|
* `actions` lists, authenticating a protected action's request before decoding it, then running
|
|
@@ -162,6 +162,7 @@ export declare function make<const Contracts extends ReadonlyArray<Any$1 | Any>>
|
|
|
162
162
|
* - An action declaring `progress` answers a request whose `Accept` names `text/event-stream`, whatever else it names, with an SSE stream, listed in OpenAPI: a `progress` event for each value, its data the value's JSON, then one `final` event holding the answer's JSON, `null` for none; without that `Accept` it answers as any action, its progress dropped.
|
|
163
163
|
* - An action answering a stream, `Action.Stream`, answers an SSE stream alone, whatever `Accept` says: an `element` event for each element, its data the element's JSON, and a `progress` event for each value where it declares `progress`; a stream of none answers a 200 with no event. A failure before the first event answers its status; one after ends the stream as Effect's stream failure event, a defect as `Internal server error`.
|
|
164
164
|
* - The stream starts with the call's first event, so a failure before it, a refusal included, answers as it would without the stream; a declared failure after it ends the stream with Effect's `effect/http-api/stream/failure` event, reported as `Info` as without the stream, and a defect or an answer that does not encode with one saying `Internal server error`, its cause logged and reported.
|
|
165
|
+
* - An action's SSE stream writes a `: keepalive` comment every 15 seconds from its first event until it ends, events or not, which SSE clients skip, so a proxy closing a silent response keeps it open through a slow step; before the first event no response has started, so a proxy timing out a response's start still ends a call silent that long.
|
|
165
166
|
* - A body that is not JSON is a 400 `InvalidInput`; a request with no `Content-Type` a 415 `Unsupported content-type: none`, one with another type Effect's own 415; each after authentication on a protected route.
|
|
166
167
|
* - A defect, an undeclared failure, or a success or an error that does not encode answers an empty 500: the cause goes to the log and to the call's `ErrorReporter`s, never to the body.
|
|
167
168
|
* - A path no layer serves, or a method other than `POST` on a route, is a 404.
|
package/dist/ActionHttp.mjs
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
+
import { providerOf } from "./authentication/provider.mjs";
|
|
2
|
+
import { inputParseOptions } from "./contract/call.mjs";
|
|
1
3
|
import { Anyone } from "./contract/caller.mjs";
|
|
2
|
-
import { declared } from "./contract/status.mjs";
|
|
3
4
|
import { bindingErrors, bindingOf, eventErrors, projectedErrors } from "./contract/declared.mjs";
|
|
4
|
-
import { elementOf } from "./contract/stream.mjs";
|
|
5
5
|
import { acquire } from "./contract/implementation.mjs";
|
|
6
|
-
import { inputParseOptions } from "./contract/call.mjs";
|
|
7
|
-
import { acquireFeeds, unkeyedHook } from "./contract/feed.mjs";
|
|
8
|
-
import { offersWebhook, servedWebhooks } from "./contract/webhooks.mjs";
|
|
9
|
-
import { providerOf } from "./authentication/provider.mjs";
|
|
10
6
|
import { listed } from "./contract/listed.mjs";
|
|
11
7
|
import { provideServed, servingOf } from "./contract/serving.mjs";
|
|
12
|
-
import {
|
|
8
|
+
import { declared } from "./contract/status.mjs";
|
|
9
|
+
import { Answering, answeringOf } from "./contract/stream.mjs";
|
|
10
|
+
import { offersWebhook, servingFeeds } from "./contract/webhooks.mjs";
|
|
13
11
|
import { methods } from "./http/client.mjs";
|
|
14
12
|
import { answering, eventEndpointOf, servedSent, webhookAnswers, webhookEndpointsOf } from "./http/events.mjs";
|
|
15
13
|
import { SchemaErrors, schemaErrors } from "./http/schema-errors.mjs";
|
|
14
|
+
import { answeredWithProgress, answeringElements, answeringWithProgress, elementStreamOf, progressStreamOf } from "./http/streamed.mjs";
|
|
16
15
|
import { placed } from "./http/placed.mjs";
|
|
17
16
|
import { Context, Effect, Layer, Scope } from "effect";
|
|
18
17
|
import { FetchHttpClient, HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
@@ -26,21 +25,21 @@ const apiOf = (group, endpoints) => {
|
|
|
26
25
|
const [first, ...rest] = endpoints;
|
|
27
26
|
return HttpApi.make("actions").annotate(HttpApi.ParseOptions, { errors: "all" }).add(first === void 0 ? empty : empty.add(first, ...rest));
|
|
28
27
|
};
|
|
29
|
-
const successOf = (action, errors) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
28
|
+
const successOf = (action, errors) => Answering.$match(answeringOf(action), {
|
|
29
|
+
Value: ({ success }) => success,
|
|
30
|
+
Progressed: ({ success, progress }) => [answeredWithProgress(success), progressStreamOf(progress, success, errors)],
|
|
31
|
+
Elements: ({ element, progress }) => elementStreamOf(element, progress, errors)
|
|
32
|
+
});
|
|
34
33
|
const endpointOf = (action, path, errors) => HttpApiEndpoint.post(action.name, path, {
|
|
35
34
|
payload: action.input.pipe(HttpApiSchema.asJson()),
|
|
36
35
|
success: successOf(action, errors),
|
|
37
36
|
error: errors.map(declared)
|
|
38
37
|
});
|
|
39
|
-
const answerOf = (action, run) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
38
|
+
const answerOf = (action, run) => Answering.$match(answeringOf(action), {
|
|
39
|
+
Value: () => run,
|
|
40
|
+
Progressed: ({ success }) => answeringWithProgress(success, run),
|
|
41
|
+
Elements: ({ element }) => answeringElements(element, run)
|
|
42
|
+
});
|
|
44
43
|
const withinLayerMiddleware = (endpoint, middleware = []) => {
|
|
45
44
|
let within = endpoint;
|
|
46
45
|
for (const key of middleware) within = within.middleware(key);
|
|
@@ -98,10 +97,7 @@ function layer(binding, served, options = {}) {
|
|
|
98
97
|
})]).annotate(HttpApi.PayloadParseOptions, inputParseOptions);
|
|
99
98
|
const handlers = Layer.unwrap(Effect.gen(function* () {
|
|
100
99
|
const bound = yield* acquire(apps, authentication);
|
|
101
|
-
const feeds = yield*
|
|
102
|
-
const refusal = unkeyedHook("ActionHttp", feeds, authentication?.principal !== void 0);
|
|
103
|
-
if (refusal !== void 0) return yield* Effect.die(new Error(refusal));
|
|
104
|
-
const { webhooks, offered } = yield* servedWebhooks(feeds, authentication);
|
|
100
|
+
const { feeds, webhooks, offered } = yield* servingFeeds("ActionHttp", events, authentication);
|
|
105
101
|
const security = authentication === void 0 ? Layer.empty : yield* Effect.map(providerOf(authentication), (provider) => Layer.mergeAll(Layer.succeed(authentication["~middleware"], provider.middleware), Layer.succeed(StepUp, provider.stepUp)));
|
|
106
102
|
const hostProvidedMiddleware = yield* Effect.forEach(options.middleware ?? [], (key) => Effect.map(Effect.service(key), (service) => Layer.succeed(key, service)));
|
|
107
103
|
const webhookAnswered = offered.map((feed) => [feed.event.name, webhookAnswers(feed, authentication, webhooks)]);
|
|
@@ -120,7 +116,7 @@ function layer(binding, served, options = {}) {
|
|
|
120
116
|
security,
|
|
121
117
|
...hostProvidedMiddleware
|
|
122
118
|
]), buildInEmptyContext);
|
|
123
|
-
})).pipe(provideServed(selected));
|
|
119
|
+
})).pipe(provideServed(selected.apps, selected.events));
|
|
124
120
|
return HttpApiBuilder.layer(api).pipe(Layer.provide(handlers), Layer.provide(startupBeneathRequest()));
|
|
125
121
|
}
|
|
126
122
|
function client(binding, options) {
|
package/dist/ActionMcp.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { Any, Matching, ProviderOf, RemoteRequest, Required, ServerBuildServices } from "./authentication/provider.mjs";
|
|
2
|
+
import { Any as Any$1 } from "./Action.mjs";
|
|
3
|
+
import { Any as Any$2 } from "./Event.mjs";
|
|
1
4
|
import { EventBuildError, EventBuildServices, EventOf, EventRequestOf, EventServedRequest, HoldingEvents } from "./contract/feed.mjs";
|
|
2
|
-
import { Any } from "./Event.mjs";
|
|
3
5
|
import { ActionOf, BuildError, BuildServices, Holding, Known, Member, Protected, SelectedEventsOf, SelectedOf, Selection, Served, ServedRequest } from "./contract/implementation.mjs";
|
|
4
|
-
import { Any as Any$1 } from "./Action.mjs";
|
|
5
|
-
import { Any as Any$2, Matching, ProviderOf, RemoteRequest, Required, ServerBuildServices } from "./authentication/provider.mjs";
|
|
6
|
-
import { McpCallError } from "./mcp/reply.mjs";
|
|
7
6
|
import { Client, ClientOptions, client } from "./mcp/client.mjs";
|
|
7
|
+
import { McpCallError } from "./mcp/reply.mjs";
|
|
8
8
|
import { Params, RequestOptions, request } from "./mcp/request.mjs";
|
|
9
9
|
import { Cause, Effect, Layer, Scope, Stdio } from "effect";
|
|
10
10
|
import { HttpRouter } from "effect/http";
|
|
@@ -15,7 +15,7 @@ import { McpSchema, McpServer } from "effect/ai";
|
|
|
15
15
|
* among them, the actions `A` that are its tools and the event types `A` it serves, and the
|
|
16
16
|
* native features it serves beside them.
|
|
17
17
|
*/
|
|
18
|
-
export interface Options<E = never, R = never, A extends Any$1 | Any = Any$1 | Any> extends Omit<Parameters<typeof McpServer.layerStdio>[0], "protocols" | "registrations"> {
|
|
18
|
+
export interface Options<E = never, R = never, A extends Any$1 | Any$2 = Any$1 | Any$2> extends Omit<Parameters<typeof McpServer.layerStdio>[0], "protocols" | "registrations"> {
|
|
19
19
|
/**
|
|
20
20
|
* The actions that are tools and the event types it serves, among the implementations':
|
|
21
21
|
* `[GetUser, RenameUser, UserRenamed]`, exactly those. Each keeps its implementation's
|
|
@@ -47,7 +47,7 @@ export interface Options<E = never, R = never, A extends Any$1 | Any = Any$1 | A
|
|
|
47
47
|
* `McpServer.layerHttp` option, `allowedOrigins` among them, except `protocols`, `registrations`
|
|
48
48
|
* and `allowSessionTermination`, which are fixed.
|
|
49
49
|
*/
|
|
50
|
-
export interface LayerHttpOptions<E = never, R = never, A extends Any$1 | Any = Any$1 | Any> extends Options<E, R, A>, Omit<Parameters<typeof McpServer.layerHttp>[0], "protocols" | "path" | "allowSessionTermination" | "registrations"> {
|
|
50
|
+
export interface LayerHttpOptions<E = never, R = never, A extends Any$1 | Any$2 = Any$1 | Any$2> extends Options<E, R, A>, Omit<Parameters<typeof McpServer.layerHttp>[0], "protocols" | "path" | "allowSessionTermination" | "registrations"> {
|
|
51
51
|
/** The endpoint's route; defaults to `/mcp`. */
|
|
52
52
|
readonly path?: HttpRouter.PathInput;
|
|
53
53
|
/**
|
|
@@ -66,7 +66,7 @@ export interface LayerHttpOptions<E = never, R = never, A extends Any$1 | Any =
|
|
|
66
66
|
* - Every prompt and resource request needs a credential, listings included: to offer them signed out, serve them on an endpoint without protected tools.
|
|
67
67
|
* - A handler that sends a notification starts the response, so a refusal after it is an `isError: true` tool result, not the 401 or 403 a client re-authorizes on: refuse in `authorize`.
|
|
68
68
|
*/
|
|
69
|
-
readonly authentication?: Any
|
|
69
|
+
readonly authentication?: Any;
|
|
70
70
|
/**
|
|
71
71
|
* Whether MCP 2026-07-28 clients may subscribe, holding a stream open for list changes and
|
|
72
72
|
* resource updates. Defaults to whether `features` or event implementations are given: an
|
|
@@ -135,7 +135,7 @@ type Inferring<D, A extends Pick<Any$1, "caller">> = [D] extends [undefined] ? [
|
|
|
135
135
|
* - A poll's `maxEvents` caps a log source's page, at most 100, and is not honored for a check source, whose page is answered whole since only its last cursor resumes; `maxAgeMs` is accepted and not honored, a log source keeping what its `log.maxAge` and `log.maxEvents` say.
|
|
136
136
|
* - A push stream's failure that no refusal explains, such as an upstream's outage, is `notifications/events/error`, its cause logged and reported, and the stream resumes from where it reached after 5 seconds; a refusal ends it with `notifications/events/terminated`. One before `active`, or a poll's, is a JSON-RPC `-32603`, which `client`'s `watch` reconnects after, as after a 5xx.
|
|
137
137
|
*/
|
|
138
|
-
export declare function layerHttp<const Apps extends Served, const O extends Selection<ActionOf<Member<Apps>> | EventOf<Member<Apps>>> = {}, E = never, R = never, const D extends Any
|
|
138
|
+
export declare function layerHttp<const Apps extends Served, const O extends Selection<ActionOf<Member<Apps>> | EventOf<Member<Apps>>> = {}, E = never, R = never, const D extends Any | undefined = undefined>(implementations: Apps, options: LayerHttpOptions<E, R, ActionOf<Member<Apps>> | EventOf<Member<Apps>>> & O & NoInfer<Known<O, LayerHttpOptions<E, R>>> & NoInfer<Required<Contracts<Apps, O>>> & Matching<NoInfer<Contracts<Apps, O>>, NoInfer<D>> & Inferring<D, NoInfer<Contracts<Apps, O>>>): Layer.Layer<never, ServerError<Apps, O> | E, ServerBuildServices<Holding<Member<Apps>, SelectedOf<O, Apps>>, SelectedOf<O, Apps>> | EventServices<Apps, O> | HttpRouter.HttpRouter | HttpRouter.Request.From<"Requires", HttpToolRequestContext<RemoteRequest<Member<Apps>, SelectedOf<O, Apps>> | EventServedRequest<Member<Apps>, SelectedEventsOf<O, Apps>> | FeatureRequest<R>>> | ProviderOf<D> | Features<R>>;
|
|
139
139
|
/**
|
|
140
140
|
* Serve MCP tools through newline-delimited JSON-RPC on standard I/O, speaking MCP
|
|
141
141
|
* 2026-07-28, 2025-11-25 or 2025-06-18, as the host negotiates: the whole
|
package/dist/ActionMcp.mjs
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
+
import { providerOf } from "./authentication/provider.mjs";
|
|
2
|
+
import { asCaller } from "./authentication/refusal.mjs";
|
|
3
|
+
import { inputParseOptions } from "./contract/call.mjs";
|
|
1
4
|
import { Anyone, assertAuthentication } from "./contract/caller.mjs";
|
|
2
5
|
import { projectedErrors } from "./contract/declared.mjs";
|
|
3
|
-
import { assertOnce, heldOnce } from "./contract/names.mjs";
|
|
4
|
-
import { toolSuccessOf } from "./contract/stream.mjs";
|
|
5
|
-
import { acquire, answeringWhole } from "./contract/implementation.mjs";
|
|
6
|
-
import { inputParseOptions } from "./contract/call.mjs";
|
|
7
6
|
import { hintsOf } from "./contract/hints.mjs";
|
|
7
|
+
import { acquire, answeringWhole } from "./contract/implementation.mjs";
|
|
8
8
|
import { liftOf, liftedFrom } from "./contract/lift.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import { assertOnce, heldOnce } from "./contract/names.mjs";
|
|
10
10
|
import { provideServed, selectFrom } from "./contract/serving.mjs";
|
|
11
|
-
import {
|
|
11
|
+
import { toolSuccessOf } from "./contract/stream.mjs";
|
|
12
|
+
import { servingFeeds } from "./contract/webhooks.mjs";
|
|
12
13
|
import { withStderrConsole } from "./stdio/console.mjs";
|
|
13
|
-
import {
|
|
14
|
-
import { eventSchemasOf, refuseUnservable, serveWebhooks, withEvents } from "./mcp/bridge.mjs";
|
|
14
|
+
import { eventSchemasOf, withEvents } from "./mcp/bridge.mjs";
|
|
15
15
|
import { progressNotifier } from "./mcp/progress.mjs";
|
|
16
|
+
import { defaultPath, fieldKey, httpProtocol, isMisplaced, isObjectSchema, protocols, toolJsonSchema } from "./mcp/protocol.mjs";
|
|
17
|
+
import { client } from "./mcp/client.mjs";
|
|
16
18
|
import { McpCallError } from "./mcp/reply.mjs";
|
|
17
19
|
import { request } from "./mcp/request.mjs";
|
|
18
|
-
import { client } from "./mcp/client.mjs";
|
|
19
20
|
import { Cause, Context, Effect, ErrorReporter, Exit, Fiber, Layer, Option, Predicate, Schema, Stdio, Stream } from "effect";
|
|
20
21
|
import { HttpRouter, HttpServerRequest } from "effect/http";
|
|
21
22
|
import { AiError, McpSchema, McpServer } from "effect/ai";
|
|
@@ -78,7 +79,7 @@ const registerTools = Effect.fnUntraced(function* (apps, authentication) {
|
|
|
78
79
|
const encodeSuccess = encoder(toolSuccess);
|
|
79
80
|
const encodeFailure = encoder(Schema.Union(projectedErrors(action)));
|
|
80
81
|
const reported = (input) => action.progress === void 0 ? run(input) : Effect.flatMap(progressNotifier(registry.notifications, action.progress), (sink) => run(input, sink));
|
|
81
|
-
const call =
|
|
82
|
+
const call = (input) => asCaller(authentication, action, reported(input));
|
|
82
83
|
const liftedFieldNames = new Set(media?.fields.map(({ name }) => name));
|
|
83
84
|
const resultOf = (encoded, success) => {
|
|
84
85
|
if (media === void 0) return new McpSchema.CallToolResult({
|
|
@@ -131,14 +132,10 @@ const server = (apps, serving, transport, features = Layer.empty) => {
|
|
|
131
132
|
const register = Effect.gen(function* () {
|
|
132
133
|
const namesClaimedByFeatures = (yield* McpServer.McpServer).tools.flatMap(({ tool }) => names.has(tool.name) ? [tool.name] : []);
|
|
133
134
|
if (namesClaimedByFeatures.length > 0) return yield* Effect.die(/* @__PURE__ */ new Error(`Duplicate MCP tool: ${namesClaimedByFeatures.join(", ")}, claimed by an action and a native feature (rename the native tool, or leave the action out of actions)`));
|
|
134
|
-
yield*
|
|
135
|
-
yield* serveWebhooks(serving);
|
|
135
|
+
yield* servingFeeds("MCP", serving.events, serving.authentication);
|
|
136
136
|
yield* registerTools(apps, authentication);
|
|
137
137
|
});
|
|
138
|
-
return Layer.empty.pipe(Layer.provide(transport(Layer.effectDiscard(register).pipe(Layer.provide(features)))), Layer.fresh, provideServed(
|
|
139
|
-
apps,
|
|
140
|
-
events
|
|
141
|
-
}));
|
|
138
|
+
return Layer.empty.pipe(Layer.provide(transport(Layer.effectDiscard(register).pipe(Layer.provide(features)))), Layer.fresh, provideServed(apps, events));
|
|
142
139
|
};
|
|
143
140
|
const anonymousMethods = /* @__PURE__ */ new Set([
|
|
144
141
|
"server/discover",
|