@gjermundgaraba/effect-actions 0.36.0 → 0.37.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 -7
- package/dist/Action.d.mts +2 -2
- package/dist/Action.mjs +1 -1
- package/dist/ActionEntity.mjs +1 -0
- package/dist/ActionHttp.d.mts +2 -2
- package/dist/ActionRpc.d.mts +4 -4
- package/dist/ActionRpc.mjs +7 -4
- package/dist/Event.d.mts +2 -2
- package/dist/authentication/provider.d.mts +0 -22
- package/dist/authentication/refusal.mjs +0 -4
- package/dist/contract/authorizer.d.mts +0 -4
- package/dist/contract/call.mjs +0 -4
- package/dist/contract/caller.mjs +0 -1
- package/dist/contract/declared.d.mts +0 -1
- package/dist/contract/feed.d.mts +0 -3
- package/dist/contract/feed.mjs +0 -3
- package/dist/contract/hub.mjs +0 -10
- package/dist/contract/implementation.d.mts +4 -27
- package/dist/contract/implementation.mjs +0 -9
- package/dist/contract/progress.d.mts +0 -1
- package/dist/contract/subscribe.mjs +0 -1
- package/dist/contract/webhooks.mjs +0 -13
- package/dist/entity/wakes.mjs +2 -5
- package/dist/http/client.mjs +8 -2
- package/dist/http/streamed.d.mts +6 -5
- package/dist/http/streamed.mjs +17 -3
- package/dist/rpc/erased.d.mts +0 -11
- package/dist/rpc/erased.mjs +1 -6
- package/docs/setup.md +1 -1
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ const greeting = Action.implement(Greet, ({ name }) =>
|
|
|
29
29
|
A binding gives it a route, for the server to serve and a client to call:
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
|
-
const Http = ActionHttp.make([Greet]);
|
|
32
|
+
const Http = ActionHttp.make([Greet]);
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
And the same implementation is served on every surface the host wants:
|
|
@@ -44,13 +44,13 @@ const routes = Layer.mergeAll(
|
|
|
44
44
|
Serve `routes` with Effect's `HttpRouter.serve` and a platform server, as [examples/quickstart](examples/quickstart) does, file by file, and you have `POST /api/greet` and an MCP tool named `greet` at `/mcp`. The same `greeting` implementation is also:
|
|
45
45
|
|
|
46
46
|
```ts
|
|
47
|
-
const { toolkit, layer } = ActionToolkit.make(greeting);
|
|
48
|
-
const cli = ActionCli.make(greeting, { name: "greetings" });
|
|
47
|
+
const { toolkit, layer } = ActionToolkit.make(greeting);
|
|
48
|
+
const cli = ActionCli.make(greeting, { name: "greetings" });
|
|
49
49
|
const remote = ActionCli.remoteCommand(Http, Greet, {
|
|
50
50
|
client: ActionHttp.client(Http, { baseUrl }),
|
|
51
|
-
});
|
|
52
|
-
const local = Action.client(greeting);
|
|
53
|
-
const rpc = ActionRpc.layer(ActionRpc.make([Greet]), greeting);
|
|
51
|
+
});
|
|
52
|
+
const local = Action.client(greeting);
|
|
53
|
+
const rpc = ActionRpc.layer(ActionRpc.make([Greet]), greeting);
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
And the client is Effect's own `HttpApiClient`, typed from the same contract, one method per action:
|
|
@@ -59,7 +59,7 @@ And the client is Effect's own `HttpApiClient`, typed from the same contract, on
|
|
|
59
59
|
Effect.gen(function* () {
|
|
60
60
|
const client = yield* ActionHttp.client(Http, { baseUrl });
|
|
61
61
|
|
|
62
|
-
return yield* client.greet({ name: "Ada" });
|
|
62
|
+
return yield* client.greet({ name: "Ada" });
|
|
63
63
|
});
|
|
64
64
|
```
|
|
65
65
|
|
package/dist/Action.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Deferred as Deferred$1 } from "./contract/authorizer.mjs";
|
|
2
2
|
import { Call } from "./contract/call.mjs";
|
|
3
3
|
import { Anyone } from "./contract/caller.mjs";
|
|
4
4
|
import { Codec, CodecOf, Fields, NoInput } from "./contract/codec.mjs";
|
|
@@ -284,7 +284,7 @@ export declare const allowAll: Authorize<Any>;
|
|
|
284
284
|
export declare function implement<const T extends Target, RequestServices extends (T extends readonly Any[] ? { readonly [K in NamesOf<T>]: unknown; } : never), R = never, EX = never, RX = never, RA = never, EAX = never, RAX = never>(actions: T, handlers: HandlersOf<T, R, RequestServices> | Effect.Effect<HandlersOf<T, R, RequestServices>, EX, RX>, options: [Protected<ActionsOf<T>>] extends [never] ? {
|
|
285
285
|
readonly authorize?: "A public-only target takes no authorize";
|
|
286
286
|
} | undefined : {
|
|
287
|
-
readonly authorize:
|
|
287
|
+
readonly authorize: ((contract: Protected<ActionsOf<T>>) => Effect.Effect<void, Refusal, RA>) | Effect.Effect<(contract: Protected<ActionsOf<T>>) => Effect.Effect<void, Refusal, RA>, EAX, RAX>;
|
|
288
288
|
}): Implemented<T, RequestServices, R, EX, RX, RA, EAX, RAX>;
|
|
289
289
|
export declare function implement<const T extends Target, RequestServices extends (T extends readonly Any[] ? { readonly [K in NamesOf<T>]: unknown; } : never), R = never, EX = never, RX = never>(actions: T & TakesNoAuthorize<T>, handlers: HandlersOf<T, R, RequestServices> | Effect.Effect<HandlersOf<T, R, RequestServices>, EX, RX>): Implemented<T, RequestServices, R, EX, RX, never, never, never>;
|
|
290
290
|
/**
|
package/dist/Action.mjs
CHANGED
|
@@ -86,7 +86,7 @@ function implement(actions, handlers, options) {
|
|
|
86
86
|
return bound;
|
|
87
87
|
};
|
|
88
88
|
const paired = Effect.isEffect(handlers) ? Effect.map(handlers, pairWithActions) : Effect.succeed(pairWithActions(handlers));
|
|
89
|
-
const recorded = listed.some((action) => action.idempotencyKey !== void 0) ? Effect.
|
|
89
|
+
const recorded = listed.some((action) => action.idempotencyKey !== void 0) ? Effect.zipWith(paired, Effect.service(Idempotency), (written, store) => written.map(([action, handle]) => [action, keyed(action, store, handle)])) : paired;
|
|
90
90
|
return new Implementation(listed, memoized(recorded), authorizer);
|
|
91
91
|
}
|
|
92
92
|
function layer(implementations) {
|
package/dist/ActionEntity.mjs
CHANGED
|
@@ -72,6 +72,7 @@ const wakeAt = (at) => Effect.flatMap(Wake, (wake) => wake.wakeAt(Math.ceil(Date
|
|
|
72
72
|
const callOf = (request, rpc) => ({
|
|
73
73
|
client: new Rpc.ServerClient(0),
|
|
74
74
|
requestId: RpcMessage.RequestId(String(request.requestId)),
|
|
75
|
+
remoteParentSpan: void 0,
|
|
75
76
|
headers: request.headers,
|
|
76
77
|
rpc
|
|
77
78
|
});
|
package/dist/ActionHttp.d.mts
CHANGED
|
@@ -162,7 +162,7 @@ export declare function make<const Contracts extends ReadonlyArray<Any$1 | Any$2
|
|
|
162
162
|
* **Gotchas**
|
|
163
163
|
*
|
|
164
164
|
* - A success is its JSON as the body; an action without `success` answers an empty 200, no body and no content type, so a hand-written client must not parse it, or an empty 204 where it declares `progress`. One without `input` still takes the body `{}` typed as JSON: no body is a 400.
|
|
165
|
-
* - An action declaring `progress` answers a request whose `Accept`
|
|
165
|
+
* - An action declaring `progress` answers a request whose `Accept` explicitly allows `text/event-stream` at nonzero quality 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.
|
|
166
166
|
* - 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`.
|
|
167
167
|
* - 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.
|
|
168
168
|
* - 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.
|
|
@@ -197,7 +197,7 @@ export declare function layer<const H extends AnyHttp, const Apps extends Served
|
|
|
197
197
|
* - `watch(event, input, options)` holds the event's SSE stream open, or polls its pages with `mode: "poll"`, as `Action.client`'s; a watch of an event the server does not serve, its route a 404, fails with `Event.SubscriptionError`, reason `NotServed`.
|
|
198
198
|
* - A watch reconnects after the transport fails, a status such as 502, `Action.Unavailable`, or 60 seconds without an answer or a frame, a second later and doubling to 30 seconds, each reconnect logged as a warning; another declared error, a refusal included, ends it.
|
|
199
199
|
* - A watch's stream ends at an SSE `retry:` field, which `ActionHttp.layer` never sends, as Effect's client decodes it, and the watch connects again: a server or proxy sending one as each stream starts delivers nothing.
|
|
200
|
-
* - A call of an action declaring `progress` reads the route's event
|
|
200
|
+
* - A call of an action declaring `progress` reads the route's `text/event-stream` response and its answer from the `final` event; the server sends the values whether or not the call gave `onProgress`, and without one they are dropped.
|
|
201
201
|
* - A call of an action answering a stream returns a `Stream` of its elements, failing as the route's stream fails, with `Sse.SseError` or `Sse.Retry` too; its `onProgress` gets each `progress` event, which the server sends whether or not the call gave one.
|
|
202
202
|
*/
|
|
203
203
|
export declare function client<const H extends AnyHttp>(binding: H, options?: Options): Effect.Effect<Client<H>, never, HttpClient.HttpClient>;
|
package/dist/ActionRpc.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ import { Call } from "./contract/call.mjs";
|
|
|
4
4
|
import { Anyone } from "./contract/caller.mjs";
|
|
5
5
|
import { Codec } from "./contract/codec.mjs";
|
|
6
6
|
import { Certain, ErrorsOf } from "./contract/declared.mjs";
|
|
7
|
-
import { BuiltIn, BuiltIns, Unauthenticated } from "./contract/errors.mjs";
|
|
7
|
+
import { BuiltIn, BuiltIns, Forbidden, Unauthenticated } from "./contract/errors.mjs";
|
|
8
8
|
import { Any as Any$3, Received, SubscriptionError } from "./Event.mjs";
|
|
9
9
|
import { EventBuildError, EventBuildServices, EventServedRequest, HoldingEvents, ServingEvents } from "./contract/feed.mjs";
|
|
10
10
|
import { BuildError, Holding, Known, Member, MiddlewareOf, Selected, SelectedEvents, Served } from "./contract/implementation.mjs";
|
|
@@ -28,7 +28,7 @@ type ElementedOf<Element extends Schema.Constraint, P> = Schema.Union<readonly [
|
|
|
28
28
|
type RpcOf<A extends Any$2, E extends Errors, D> = A extends Any$2 ? A["success"] extends StreamOf<infer Element> ? Rpc.Rpc<A["name"], A["input"], RpcSchema.Stream<ElementedOf<Element, A["progress"]>, ErrorOf<A, E, D>>> : A["progress"] extends Codec ? Rpc.Rpc<A["name"], A["input"], RpcSchema.Stream<ReturnType<typeof ProgressedOf<A["progress"], A["success"]>>, ErrorOf<A, E, D>>> : Rpc.Rpc<A["name"], A["input"], A["success"], ErrorOf<A, E, D>> : never;
|
|
29
29
|
type EventRpcOf<V extends Any$3, E extends Errors, D> = V extends Any$3 ? Rpc.Rpc<V["name"], ReturnType<typeof SubscriptionOf<V>>, RpcSchema.Stream<ReturnType<typeof PushedOf<V>>, Schema.Union<ReadonlyArray<E[number] | VerifierError<V, D> | BuiltIns>>>> : never;
|
|
30
30
|
declare const authenticatedKey = "effect-actions/ActionRpc/Authenticated";
|
|
31
|
-
type RefusalOf<E extends Errors> = Schema.Union<ReadonlyArray<typeof Unauthenticated | E[number]>>;
|
|
31
|
+
type RefusalOf<E extends Errors> = Schema.Union<ReadonlyArray<typeof Unauthenticated | typeof Forbidden | E[number]>>;
|
|
32
32
|
declare const authenticatedBrand: unique symbol;
|
|
33
33
|
interface Authenticated<I, E extends Errors = Errors> {
|
|
34
34
|
readonly [authenticatedBrand]: typeof authenticatedBrand;
|
|
@@ -101,8 +101,8 @@ export interface Options<E extends Errors = Errors> {
|
|
|
101
101
|
/**
|
|
102
102
|
* Native rpcs the binding serves beside its actions and event types, with their own schemas
|
|
103
103
|
* and handlers: `RpcGroup.make(Upload)`. Under an `authentication`, each of their messages
|
|
104
|
-
* authenticates as a protected action's does: its handler reads the identity, and
|
|
105
|
-
*
|
|
104
|
+
* authenticates as a protected action's does: its handler reads the identity, and the client
|
|
105
|
+
* receives the verifier's `Unauthenticated`, `Forbidden` (including any `scopes`), or declared error.
|
|
106
106
|
*
|
|
107
107
|
* **Gotchas**
|
|
108
108
|
*
|
package/dist/ActionRpc.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { bindingErrors, bindingOf, eventErrors } from "./contract/declared.mjs";
|
|
2
|
-
import { Unauthenticated } from "./contract/errors.mjs";
|
|
2
|
+
import { Forbidden, Unauthenticated } from "./contract/errors.mjs";
|
|
3
3
|
import { listed } from "./contract/listed.mjs";
|
|
4
4
|
import { reservedList, reservedNames } from "./contract/names.mjs";
|
|
5
5
|
import { PushedOf, SubscriptionOf } from "./contract/push.mjs";
|
|
@@ -12,7 +12,11 @@ import { Rpc, RpcClient, RpcGroup, RpcMiddleware, RpcSerialization, RpcServer }
|
|
|
12
12
|
import { Socket } from "effect/socket";
|
|
13
13
|
// src/rpc/ActionRpc.ts
|
|
14
14
|
const authenticatedKey = "effect-actions/ActionRpc/Authenticated";
|
|
15
|
-
const authenticatedOf = (authentication) => RpcMiddleware.Service()(authenticatedKey, { error: Schema.Union([
|
|
15
|
+
const authenticatedOf = (authentication) => RpcMiddleware.Service()(authenticatedKey, { error: Schema.Union([
|
|
16
|
+
Unauthenticated,
|
|
17
|
+
Forbidden,
|
|
18
|
+
...authentication.error
|
|
19
|
+
]) });
|
|
16
20
|
const authenticatedIn = (rpc) => [...rpc.middlewares].find(({ key }) => key === authenticatedKey);
|
|
17
21
|
function make(contracts, options = {}) {
|
|
18
22
|
const { actions, events } = listed(contracts);
|
|
@@ -68,8 +72,7 @@ function layer(binding, served, options = {}) {
|
|
|
68
72
|
const servedActions = jsonGroup.toLayer(byName);
|
|
69
73
|
const authenticated = natives.map(authenticatedIn).find(Predicate.isNotUndefined);
|
|
70
74
|
if (authenticated === void 0 || authenticating === void 0) return servedActions;
|
|
71
|
-
|
|
72
|
-
return Layer.merge(servedActions, Layer.succeed(authenticated)(authenticate));
|
|
75
|
+
return Layer.merge(servedActions, Layer.succeed(authenticated)(authenticating(verifyingNative)));
|
|
73
76
|
})).pipe(provideServed(selected.apps, selected.events));
|
|
74
77
|
return RpcServer.layer(jsonGroup.merge(binding.rpcs), { disableFatalDefects: true }).pipe(Layer.provide(handlers));
|
|
75
78
|
}
|
package/dist/Event.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Options as Options$1 } from "./Action.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { Deferred as Deferred$1 } from "./contract/authorizer.mjs";
|
|
3
3
|
import { Codec, CodecOf, Fields, NoInput } from "./contract/codec.mjs";
|
|
4
4
|
import { Refusal } from "./contract/errors.mjs";
|
|
5
5
|
import { AnyEventImplementation, EventImplementation } from "./contract/feed.mjs";
|
|
@@ -415,7 +415,7 @@ type Implemented<T extends Target, RequestServices, R, EX, RX, RA, EAX, RAX> = E
|
|
|
415
415
|
export declare function implement<const T extends Target, RequestServices extends (T extends readonly Any[] ? { readonly [K in NamesOf<T>]: unknown; } : never), R = never, EX = never, RX = never, RA = never, EAX = never, RAX = never>(events: T, sources: SourcesOf<T, R, RequestServices> | Effect.Effect<SourcesOf<T, R, RequestServices>, EX, RX>, options: [Protected<EventsOf<T>>] extends [never] ? {
|
|
416
416
|
readonly authorize?: "A public-only target takes no authorize";
|
|
417
417
|
} | undefined : {
|
|
418
|
-
readonly authorize:
|
|
418
|
+
readonly authorize: ((contract: Protected<EventsOf<T>>) => Effect.Effect<void, Refusal, RA>) | Effect.Effect<(contract: Protected<EventsOf<T>>) => Effect.Effect<void, Refusal, RA>, EAX, RAX>;
|
|
419
419
|
}): Implemented<T, RequestServices, R, EX, RX, RA, EAX, RAX>;
|
|
420
420
|
export declare function implement<const T extends Target, RequestServices extends (T extends readonly Any[] ? { readonly [K in NamesOf<T>]: unknown; } : never), R = never, EX = never, RX = never>(events: T & TakesNoAuthorize<T>, sources: SourcesOf<T, R, RequestServices> | Effect.Effect<SourcesOf<T, R, RequestServices>, EX, RX>): Implemented<T, RequestServices, R, EX, RX, never, never, never>;
|
|
421
421
|
export { type AnyEventImplementation as AnyImplementation, Events, Gap, type EventImplementation as Implementation, type KeyOptions, type Listed, layerMemory };
|
|
@@ -33,35 +33,14 @@ export interface SecurityMiddleware<I, Name extends string = string> {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
type Response = Effect.Effect<HttpServerResponse.HttpServerResponse, unknown, unknown>;
|
|
36
|
-
/** What a provider holds for the surfaces serving its descriptor, beside its identity. */
|
|
37
36
|
interface Runtime$1 {
|
|
38
|
-
/** The descriptor the provider was built from, the one a binding naming it must hold. */
|
|
39
37
|
readonly descriptor: unknown;
|
|
40
|
-
/**
|
|
41
|
-
* The verifier itself, for a surface answering refusals its own way, such as RPC: the
|
|
42
|
-
* credential to the identity, or a refusal, or an error the descriptor declares. An empty
|
|
43
|
-
* credential, as the native decoder gives an absent one, is refused without reaching it.
|
|
44
|
-
*/
|
|
45
38
|
readonly authenticate: (credential: Credential) => Effect.Effect<unknown, unknown, unknown>;
|
|
46
|
-
/** The native security middleware's implementation, keyed by its scheme. */
|
|
47
39
|
readonly middleware: Readonly<Record<string, (route: Response, options: {
|
|
48
40
|
readonly credential: Credential;
|
|
49
41
|
}) => Response>>;
|
|
50
|
-
/**
|
|
51
|
-
* A protected HTTP route as it leaves the layer's middleware, a step-up refusal it fails with
|
|
52
|
-
* answered with its challenge under Bearer; as it is under another scheme.
|
|
53
|
-
*/
|
|
54
42
|
readonly stepUp: HttpApiMiddleware.HttpApiMiddleware<never, never, never>;
|
|
55
|
-
/**
|
|
56
|
-
* An MCP endpoint's request: decoded here, and a protected tool's call promotes what it
|
|
57
|
-
* verified. Where `optional`, a request presenting no credential, which the scheme decodes as
|
|
58
|
-
* empty, passes signed out.
|
|
59
|
-
*/
|
|
60
43
|
readonly http: <E, R>(route: Effect.Effect<HttpServerResponse.HttpServerResponse, E, R>, optional: boolean) => Effect.Effect<HttpServerResponse.HttpServerResponse, E, R | HttpRouter.Provided>;
|
|
61
|
-
/**
|
|
62
|
-
* A route of the host's own: the request is decoded here, the route gets the identity
|
|
63
|
-
* itself, and a refusal it fails with is answered as an action route's.
|
|
64
|
-
*/
|
|
65
44
|
readonly route: <E, R>(route: Effect.Effect<HttpServerResponse.HttpServerResponse, E, R>) => Effect.Effect<HttpServerResponse.HttpServerResponse, Exclude<E, Refusal>, HttpRouter.Provided>;
|
|
66
45
|
}
|
|
67
46
|
/**
|
|
@@ -81,7 +60,6 @@ export interface Descriptor<I, A, S extends Security, Name extends string = stri
|
|
|
81
60
|
readonly schema?: Codec | undefined;
|
|
82
61
|
readonly "~provider": Context.Key<Provider<I, Name>, Runtime$1>;
|
|
83
62
|
readonly "~middleware": Context.Key<SecurityMiddleware<I, Name>, unknown>;
|
|
84
|
-
/** An MCP request's verified identity, which a protected tool's call promotes. */
|
|
85
63
|
readonly "~verified": Context.Key<never, unknown>;
|
|
86
64
|
}
|
|
87
65
|
/**
|
|
@@ -37,10 +37,6 @@ const answer = (error, metadataUrl) => {
|
|
|
37
37
|
var SteppedUpRefusal = class extends Context.Service()("effect-actions/SteppedUp") {};
|
|
38
38
|
const isStepUp = (error) => isRefusal(error) && (!Predicate.isTagged(error, "Forbidden") || error.scopes !== void 0);
|
|
39
39
|
const recordStepUp = (call) => Effect.tapError(call, (error) => isStepUp(error) ? Effect.flatMap(Effect.serviceOption(SteppedUpRefusal), (slot) => Option.isSome(slot) ? Ref.set(slot.value, Option.some(error)) : Effect.void) : Effect.void);
|
|
40
|
-
/**
|
|
41
|
-
* `run` as the caller of `called`: unchanged where it is public or nothing authenticates, and
|
|
42
|
-
* otherwise with the identity its request verified, a step-up it fails with recorded.
|
|
43
|
-
*/
|
|
44
40
|
const asCaller = (authentication, called, run) => authentication === void 0 || called.caller === Anyone ? run : recordStepUp(promote(authentication, run));
|
|
45
41
|
const answerStepUp = (route, metadataUrl) => Effect.gen(function* () {
|
|
46
42
|
const slot = yield* Ref.make(Option.none());
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import "./implementation.mjs";
|
|
2
|
-
import { Refusal } from "./errors.mjs";
|
|
3
2
|
import { Effect } from "effect";
|
|
4
|
-
/** `T`, read only once it is inferred: an implementation's build channels. */
|
|
5
3
|
type Deferred$1<T> = [T][T extends unknown ? 0 : never];
|
|
6
|
-
/** What `implement` takes as `authorize` for contracts `C`: the rule, or an Effect building it. */
|
|
7
|
-
export type Authorizer<C, RA, EAX, RAX> = ((contract: C) => Effect.Effect<void, Refusal, RA>) | Effect.Effect<(contract: C) => Effect.Effect<void, Refusal, RA>, EAX, RAX>;
|
|
8
4
|
export { Deferred$1 as Deferred };
|
package/dist/contract/call.mjs
CHANGED
|
@@ -24,10 +24,6 @@ const jsonRoundTrip = (schema) => {
|
|
|
24
24
|
value: received
|
|
25
25
|
})));
|
|
26
26
|
};
|
|
27
|
-
/**
|
|
28
|
-
* A call's or a watch's input as it is sent, `{}` decoded where it is left out: its JSON, and the
|
|
29
|
-
* value the server decodes from it.
|
|
30
|
-
*/
|
|
31
27
|
const sentInput = (event, input) => inputOf(event, input === void 0 ? [] : [input]).pipe(Effect.flatMap(jsonRoundTrip(event.input)), Effect.mapError(InvalidInput.fromSchemaError));
|
|
32
28
|
const sendingJson = (action) => Schema.encodeUnknownEffect(Schema.toCodecJson(action.input), { errors: "all" });
|
|
33
29
|
const sendingValue = (action) => {
|
package/dist/contract/caller.mjs
CHANGED
|
@@ -7,7 +7,6 @@ import { Context, Effect, Function } from "effect";
|
|
|
7
7
|
*/
|
|
8
8
|
const Anyone = Symbol.for("@gjermundgaraba/effect-actions/Anyone");
|
|
9
9
|
const CallerKeyed = Context.Reference("effect-actions/CallerKeyed", { defaultValue: Function.constUndefined });
|
|
10
|
-
/** The caller's principal: none for a public one, or on a surface with no authentication. */
|
|
11
10
|
const principalOf = (called, keyed) => keyed === void 0 || called.caller === Anyone ? Effect.undefined : Effect.map(Effect.service(called.caller), keyed.principal);
|
|
12
11
|
const assertAuthentication = (contracts, authentication, noun = "action") => {
|
|
13
12
|
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)`);
|
|
@@ -16,7 +16,6 @@ type Single<T> = true extends Types.IsUnion<T> ? never : T;
|
|
|
16
16
|
* `E` may be one of several.
|
|
17
17
|
*/
|
|
18
18
|
export type Certain<E extends Errors> = true extends Types.IsUnion<E> ? never : number extends E["length"] ? never : { readonly [K in keyof E]: Single<E[K]>; }[number];
|
|
19
|
-
/** The errors a binding declares for every call, and its protected actions' authentication's. */
|
|
20
19
|
export interface Declaring {
|
|
21
20
|
readonly error: Errors;
|
|
22
21
|
readonly authentication?: {
|
package/dist/contract/feed.d.mts
CHANGED
|
@@ -80,11 +80,8 @@ export declare class EventImplementation<E extends Any, R, EX, RX, RA = never, E
|
|
|
80
80
|
/** The event types this implementation answers. */
|
|
81
81
|
readonly events: readonly E[];
|
|
82
82
|
constructor(events: readonly E[], running: Running<EX, RX>, authorizer: Memoized<ErasedAuthorize<Any>, EAX, RAX>);
|
|
83
|
-
/** Select event types while retaining their sources, authorization and shared builder. */
|
|
84
83
|
static share(events: readonly Any[], app: AnyEventImplementation): AnyEventImplementation;
|
|
85
|
-
/** The builders of `app`, its sources' and its authorizer's, as one layer. */
|
|
86
84
|
static layerOf(app: AnyEventImplementation): Layer.Layer<never, unknown, unknown>;
|
|
87
|
-
/** The event types of `app` with what runs them, behind its authorizer. */
|
|
88
85
|
static feedsOf(app: AnyEventImplementation): Effect.Effect<readonly Feed[], never, unknown>;
|
|
89
86
|
private static held;
|
|
90
87
|
private static own;
|
package/dist/contract/feed.mjs
CHANGED
|
@@ -223,18 +223,15 @@ var EventImplementation = class EventImplementation {
|
|
|
223
223
|
this.#running = running;
|
|
224
224
|
this.#authorizer = authorizer;
|
|
225
225
|
}
|
|
226
|
-
/** Select event types while retaining their sources, authorization and shared builder. */
|
|
227
226
|
static share(events, app) {
|
|
228
227
|
const source = EventImplementation.own(app);
|
|
229
228
|
return new EventImplementation(events, source.#running, source.#authorizer);
|
|
230
229
|
}
|
|
231
|
-
/** The builders of `app`, its sources' and its authorizer's, as one layer. */
|
|
232
230
|
static layerOf(app) {
|
|
233
231
|
const source = EventImplementation.own(app);
|
|
234
232
|
const runs = Layer.mergeAll(Layer.empty, ...EventImplementation.held(app).map(([, run]) => run.layer));
|
|
235
233
|
return builderLayer(app.events, { layer: runs }, source.#authorizer);
|
|
236
234
|
}
|
|
237
|
-
/** The event types of `app` with what runs them, behind its authorizer. */
|
|
238
235
|
static feedsOf(app) {
|
|
239
236
|
const source = EventImplementation.own(app);
|
|
240
237
|
return Effect.gen(function* () {
|
package/dist/contract/hub.mjs
CHANGED
|
@@ -40,16 +40,6 @@ const holding = (set, value) => Effect.acquireRelease(Effect.sync(() => {
|
|
|
40
40
|
set.add(value);
|
|
41
41
|
return value;
|
|
42
42
|
}), () => Effect.sync(() => set.delete(value)));
|
|
43
|
-
/**
|
|
44
|
-
* An `Events` for as long as the scope lasts, over the log storage `log` makes: what
|
|
45
|
-
* `Stored.layerEvents` provides over SQL, its subscribers' wakes in memory and its logs where
|
|
46
|
-
* `log` keeps them.
|
|
47
|
-
*
|
|
48
|
-
* **Gotchas**
|
|
49
|
-
*
|
|
50
|
-
* - Make it once per database, around the handlers that announce and the surfaces that serve, as `layerMemory` is built.
|
|
51
|
-
* - A log's storage is made once per event for the life of the scope, its position read on every append and read: a storage emptied behind its back starts a new epoch, and a cursor from before reads a gap.
|
|
52
|
-
*/
|
|
53
43
|
const makeEvents = (options) => Effect.gen(function* () {
|
|
54
44
|
const revisions = options.revisions ?? memoryRevisions();
|
|
55
45
|
const scope = yield* Effect.scope;
|
|
@@ -5,30 +5,19 @@ import { Any as Any$1 } from "../Event.mjs";
|
|
|
5
5
|
import { AnyEventImplementation, EventOf } from "./feed.mjs";
|
|
6
6
|
import { Reporting } from "./progress.mjs";
|
|
7
7
|
import { Context, Effect, Layer, Scope, Stream } from "effect";
|
|
8
|
-
/** Decoded values at the dispatch boundary every surface shares. */
|
|
9
8
|
export type ErasedValue = Any["input"]["Type"];
|
|
10
9
|
export type WrittenHandler<R> = {
|
|
11
10
|
bivarianceHack(input: ErasedValue, reporting?: Reporting): Effect.Effect<ErasedValue, ErasedValue, R> | Stream.Stream<ErasedValue, ErasedValue, R>;
|
|
12
11
|
}["bivarianceHack"];
|
|
13
|
-
/**
|
|
14
|
-
* A handler behind its action's authentication, authorization and declared errors, as a surface
|
|
15
|
-
* calls it. For an action answering a stream it succeeds at once with the call's stream, which
|
|
16
|
-
* `elementsOf` reads, the refusals included. `reporting` is where its progress goes, ignored for
|
|
17
|
-
* an action declaring no `progress`, so a surface may hand one to every call.
|
|
18
|
-
*/
|
|
19
12
|
export type ErasedHandler<R> = (input: ErasedValue, reporting?: Reporting) => Effect.Effect<ErasedValue, ErasedValue, R>;
|
|
20
13
|
/**
|
|
21
14
|
* Authorization for protected contracts: it refuses, and fails with nothing else. It runs only for
|
|
22
15
|
* protected actions, after authentication and before the handler.
|
|
23
16
|
*/
|
|
24
17
|
export type Authorize<A extends Any, R = never> = (action: A) => Effect.Effect<void, Refusal, R>;
|
|
25
|
-
/** An authorization rule over contracts `C`, erased: it refuses, or lets the call run. */
|
|
26
18
|
export type ErasedAuthorize<C = Any> = (contract: C) => Effect.Effect<void, unknown, unknown>;
|
|
27
|
-
/** Each action of an implementation with its handler, as `dispatch` makes it. */
|
|
28
19
|
export type Bound = ReadonlyArray<readonly [Any, ErasedHandler<unknown>]>;
|
|
29
|
-
/** Each action of an implementation with its handler as written, as its builder made them. */
|
|
30
20
|
export type Written = ReadonlyArray<readonly [Any, WrittenHandler<unknown>]>;
|
|
31
|
-
/** A build shared by every layer an implementation reaches, through the one key it is provided under. */
|
|
32
21
|
export interface Memoized<S, E, R> {
|
|
33
22
|
readonly key: Context.Key<S, S>;
|
|
34
23
|
readonly layer: Layer.Layer<S, E, R>;
|
|
@@ -58,17 +47,8 @@ export declare class Implementation<A extends Any, RequestServices, EX, RX, RA =
|
|
|
58
47
|
readonly "~authorizeBuildServices": RAX;
|
|
59
48
|
/** The contracts this implementation answers. */
|
|
60
49
|
readonly actions: readonly A[];
|
|
61
|
-
constructor(actions: readonly A[],
|
|
62
|
-
/** Builds each action paired with its handler: its own builder, or the one it shares. */
|
|
63
|
-
handlers: Memoized<Written, EX, RX>,
|
|
64
|
-
/** Builds its authorizer. */
|
|
65
|
-
authorizer: Memoized<ErasedAuthorize, EAX, RAX>);
|
|
66
|
-
/** Select contracts while retaining their handlers, authorization and shared builder. */
|
|
50
|
+
constructor(actions: readonly A[], handlers: Memoized<Written, EX, RX>, authorizer: Memoized<ErasedAuthorize, EAX, RAX>);
|
|
67
51
|
static share(actions: readonly Any[], app: AnyImplementation): AnyImplementation;
|
|
68
|
-
/**
|
|
69
|
-
* The key of what runs a call of `app`'s actions: its handlers' memoized layer's, which each
|
|
70
|
-
* `implement` makes, so it is unique to the implementation. Every selection retains it.
|
|
71
|
-
*/
|
|
72
52
|
static runKey(app: AnyImplementation): string;
|
|
73
53
|
/**
|
|
74
54
|
* The builders of `app`, its handlers' and its authorizer's, as a layer. Effect memoizes each
|
|
@@ -76,10 +56,6 @@ export declare class Implementation<A extends Any, RequestServices, EX, RX, RA =
|
|
|
76
56
|
* implementation sharing its builder, shares one run.
|
|
77
57
|
*/
|
|
78
58
|
static layerOf(app: AnyImplementation): Layer.Layer<never, unknown, unknown>;
|
|
79
|
-
/**
|
|
80
|
-
* The actions of `app` with their handlers, behind its authorizer, from the context
|
|
81
|
-
* `layerOf(app)` provides.
|
|
82
|
-
*/
|
|
83
59
|
static boundOf(app: AnyImplementation, keyed: Keyed | undefined): Effect.Effect<Bound, never, unknown>;
|
|
84
60
|
private static own;
|
|
85
61
|
}
|
|
@@ -141,9 +117,10 @@ type Listing<O> = O extends unknown ? NonNullable<O["actions" & keyof O]> : neve
|
|
|
141
117
|
/**
|
|
142
118
|
* No key of any member of `O` beyond those of `Keys`, so a misspelled option is refused
|
|
143
119
|
* rather than ignored: options inferred whole, as a type parameter, skip TypeScript's own
|
|
144
|
-
* check, and `keyof` a union holds only the keys every member has.
|
|
120
|
+
* check, and `keyof` a union holds only the keys every member has. An index signature of `O`,
|
|
121
|
+
* a record built at runtime, names no key, so it is left to the runtime check.
|
|
145
122
|
*/
|
|
146
|
-
export type Known<O, Keys> = { readonly [K in Exclude<O extends unknown ? keyof O : never, keyof Keys>]?: never; };
|
|
123
|
+
export type Known<O, Keys> = { readonly [K in Exclude<O extends unknown ? keyof O : never, keyof Keys> as string extends K ? never : number extends K ? never : K]?: never; };
|
|
147
124
|
/**
|
|
148
125
|
* The parameters of an optional options argument of type `O`: required where `O` names what
|
|
149
126
|
* only a given argument holds, such as listed actions, so explicit type arguments cannot
|
|
@@ -73,15 +73,10 @@ var Implementation = class Implementation {
|
|
|
73
73
|
this.#handlers = handlers;
|
|
74
74
|
this.#authorizer = authorizer;
|
|
75
75
|
}
|
|
76
|
-
/** Select contracts while retaining their handlers, authorization and shared builder. */
|
|
77
76
|
static share(actions, app) {
|
|
78
77
|
const source = Implementation.own(app);
|
|
79
78
|
return new Implementation(actions, source.#handlers, source.#authorizer);
|
|
80
79
|
}
|
|
81
|
-
/**
|
|
82
|
-
* The key of what runs a call of `app`'s actions: its handlers' memoized layer's, which each
|
|
83
|
-
* `implement` makes, so it is unique to the implementation. Every selection retains it.
|
|
84
|
-
*/
|
|
85
80
|
static runKey(app) {
|
|
86
81
|
return Implementation.own(app).#handlers.key.key;
|
|
87
82
|
}
|
|
@@ -94,10 +89,6 @@ var Implementation = class Implementation {
|
|
|
94
89
|
const source = Implementation.own(app);
|
|
95
90
|
return builderLayer(app.actions, source.#handlers, source.#authorizer);
|
|
96
91
|
}
|
|
97
|
-
/**
|
|
98
|
-
* The actions of `app` with their handlers, behind its authorizer, from the context
|
|
99
|
-
* `layerOf(app)` provides.
|
|
100
|
-
*/
|
|
101
92
|
static boundOf(app, keyed) {
|
|
102
93
|
const { actions } = app;
|
|
103
94
|
const source = Implementation.own(app);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Codec } from "./codec.mjs";
|
|
2
2
|
import { ErasedValue } from "./implementation.mjs";
|
|
3
3
|
import { Data, Effect, Scope, Stream } from "effect";
|
|
4
|
-
/** Where a call's progress goes: each value reported, checked by its schema, is given to `progress`. */
|
|
5
4
|
export interface Reporting {
|
|
6
5
|
readonly progress: (value: ErasedValue) => Effect.Effect<void>;
|
|
7
6
|
}
|
|
@@ -3,7 +3,6 @@ import { CallbackCategory, SubscriptionError, Unsupported } from "../Event.mjs";
|
|
|
3
3
|
import { SubscriptionOf } from "./push.mjs";
|
|
4
4
|
import { Schema, Struct } from "effect";
|
|
5
5
|
// src/contract/subscribe.ts
|
|
6
|
-
/** The error for `event` that is not delivered by `mode` where it is asked for. */
|
|
7
6
|
const deliveryUnsupported = (event, mode) => SubscriptionError.of(event, new Unsupported({
|
|
8
7
|
feature: "deliveryMode",
|
|
9
8
|
value: mode
|
|
@@ -14,24 +14,16 @@ import { Context, Effect, Option } from "effect";
|
|
|
14
14
|
* `Event.SubscriptionError`.
|
|
15
15
|
*/
|
|
16
16
|
var Webhooks = class extends Context.Service()("effect-actions/Webhooks") {};
|
|
17
|
-
/** Whether a surface offers `event` by webhook: a protected one, its caller an identity. */
|
|
18
17
|
const offersWebhook = (event) => event.caller !== Anyone;
|
|
19
18
|
const offeredByWebhook = (feed) => offersWebhook(feed.event);
|
|
20
19
|
const deliversByWebhook = (feed) => feed.webhook === void 0 && offeredByWebhook(feed);
|
|
21
|
-
/**
|
|
22
|
-
* Who subscribes to `feed`'s webhooks, and where they are held: the holder the feed names, a
|
|
23
|
-
* reached entity, or else the surface's own `Webhooks`; none where the event is not offered by
|
|
24
|
-
* webhook. Its principal is read from the caller each time it runs.
|
|
25
|
-
*/
|
|
26
20
|
const webhookSubscriber = (feed, keyed, webhooks) => keyed !== void 0 && offeredByWebhook(feed) ? Option.map(feed.webhook === void 0 ? webhooks : Option.some(feed.webhook), (holder) => Effect.map(Effect.service(feed.event.caller), (identity) => ({
|
|
27
21
|
webhooks: holder,
|
|
28
22
|
feed,
|
|
29
23
|
keyed,
|
|
30
24
|
principal: keyed.principal(identity)
|
|
31
25
|
}))) : Option.none();
|
|
32
|
-
/** As `webhookSubscriber`, failing as `Unsupported` where the event is not offered by webhook. */
|
|
33
26
|
const subscriberOf = (feed, keyed, webhooks) => Option.getOrElse(webhookSubscriber(feed, keyed, webhooks), () => Effect.fail(deliveryUnsupported(feed.event.name, "webhook")));
|
|
34
|
-
/** A surface's answers to a webhook subscribe and unsubscribe of `feed`, run as its subscriber. */
|
|
35
27
|
const webhookAnswers = (feed, keyed, webhooks) => {
|
|
36
28
|
const served = subscriberOf(feed, keyed, webhooks);
|
|
37
29
|
return {
|
|
@@ -46,11 +38,6 @@ const webhookAnswers = (feed, keyed, webhooks) => {
|
|
|
46
38
|
}))
|
|
47
39
|
};
|
|
48
40
|
};
|
|
49
|
-
/**
|
|
50
|
-
* The feeds of `events` a surface's layer serves, and the `Webhooks` it offers them by: run as
|
|
51
|
-
* the layer builds, which serves the webhooks it delivers itself, those of the feeds `holds`
|
|
52
|
-
* admits, and restores their kept subscriptions.
|
|
53
|
-
*/
|
|
54
41
|
const servingFeeds = Effect.fnUntraced(function* (events, keyed, holds = () => true) {
|
|
55
42
|
const feeds = yield* acquireFeeds(events);
|
|
56
43
|
const webhooks = yield* Effect.serviceOption(Webhooks);
|
package/dist/entity/wakes.mjs
CHANGED
|
@@ -12,11 +12,8 @@ var WakeAt = class extends Schema.Class("effect-actions/ActionEntity/WakeAt")({
|
|
|
12
12
|
};
|
|
13
13
|
const WakeRpc = Rpc.make(wakeTag, { payload: WakeAt }).annotate(ClusterSchema.Persisted, true);
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* waits for a wake due no earlier, so no earlier wake hands it over; `woke` takes a delivery,
|
|
18
|
-
* which may be stale or replayed. A send and its record hold the lock, uninterruptibly, and so
|
|
19
|
-
* does a delivery's bookkeeping, so a delivery racing its own send cannot leave a fired time pending.
|
|
15
|
+
* An entity's wake scheduler. Sending and recording a wake hold the same lock as delivery
|
|
16
|
+
* bookkeeping, so a delivery racing its own send cannot leave a fired time pending.
|
|
20
17
|
*/
|
|
21
18
|
const makeWake = (send) => Effect.gen(function* () {
|
|
22
19
|
const clock = yield* Clock.Clock;
|
package/dist/http/client.mjs
CHANGED
|
@@ -21,8 +21,14 @@ const actionMethodOf = (action, native) => {
|
|
|
21
21
|
const method = methodOf(native, action.name, "action");
|
|
22
22
|
return Answering.$match(answeringOf(action), {
|
|
23
23
|
Value: () => checked(action, sendingValue, (payload) => method({ payload })),
|
|
24
|
-
Progressed: () => checked(action, sendingValue, (payload, onProgress) => Effect.flatMap(method({
|
|
25
|
-
|
|
24
|
+
Progressed: () => checked(action, sendingValue, (payload, onProgress) => Effect.flatMap(method({
|
|
25
|
+
payload,
|
|
26
|
+
responseMode: "decoded-and-response"
|
|
27
|
+
}), (answer) => readWithProgress(answer, onProgress))),
|
|
28
|
+
Elements: () => checkedStream(action, sendingValue, (payload, onProgress) => Stream.unwrap(Effect.map(method({
|
|
29
|
+
payload,
|
|
30
|
+
responseMode: "decoded-and-response"
|
|
31
|
+
}), (answer) => readElements(answer, onProgress))))
|
|
26
32
|
});
|
|
27
33
|
};
|
|
28
34
|
const sendersWith = (http, httpClient, baseUrl) => Effect.gen(function* () {
|
package/dist/http/streamed.d.mts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Any } from "../Action.mjs";
|
|
2
2
|
import { Codec } from "../contract/codec.mjs";
|
|
3
|
-
import
|
|
3
|
+
import "../contract/implementation.mjs";
|
|
4
4
|
import "../contract/progress.mjs";
|
|
5
5
|
import { StreamOf } from "../contract/stream.mjs";
|
|
6
6
|
import { Effect, Schema, Stream } from "effect";
|
|
7
7
|
import { HttpServerRequest } from "effect/http";
|
|
8
8
|
import { HttpApiSchema } from "effect/http-api";
|
|
9
|
-
|
|
10
|
-
readonly event: "progress"
|
|
11
|
-
readonly data:
|
|
12
|
-
}
|
|
9
|
+
declare const Sent: Schema.Struct<{
|
|
10
|
+
readonly event: Schema.Literals<readonly ["progress", "element", "final"]>;
|
|
11
|
+
readonly data: Schema.Unknown;
|
|
12
|
+
}>;
|
|
13
|
+
type Sent = typeof Sent.Type;
|
|
13
14
|
declare const eventOf: <const N extends Sent["event"], D extends Codec>(event: N, data: D) => Schema.Struct<{
|
|
14
15
|
readonly id: Schema.optional<Schema.String>;
|
|
15
16
|
readonly event: Schema.Literal<N>;
|
package/dist/http/streamed.mjs
CHANGED
|
@@ -5,6 +5,15 @@ import { Cause, Duration, Effect, ErrorReporter, Queue, Schema, Stream } from "e
|
|
|
5
5
|
import { HttpServerRequest } from "effect/http";
|
|
6
6
|
import { HttpApiSchema } from "effect/http-api";
|
|
7
7
|
// src/http/streamed.ts
|
|
8
|
+
const Sent = Schema.Struct({
|
|
9
|
+
event: Schema.Literals([
|
|
10
|
+
"progress",
|
|
11
|
+
"element",
|
|
12
|
+
"final"
|
|
13
|
+
]),
|
|
14
|
+
data: Schema.Unknown
|
|
15
|
+
});
|
|
16
|
+
const isSent = Schema.is(Sent);
|
|
8
17
|
const eventOf = (event, data) => Schema.Struct({
|
|
9
18
|
id: Schema.optional(Schema.String),
|
|
10
19
|
event: Schema.Literal(event),
|
|
@@ -44,8 +53,13 @@ const checkedBy = (schema) => {
|
|
|
44
53
|
const encode = Schema.encodeUnknownEffect(Schema.toCodecJson(schema));
|
|
45
54
|
return (data) => Effect.orDie(encode(data));
|
|
46
55
|
};
|
|
47
|
-
|
|
48
|
-
const
|
|
56
|
+
const acceptsEventStream = (request) => ((request.headers["accept"] ?? "").match(/(?:[^",]|"(?:[^"\\]|\\.)*")+/gu) ?? []).some((range) => {
|
|
57
|
+
const [media, ...parameters] = range.match(/(?:[^";]|"(?:[^"\\]|\\.)*")+/gu) ?? [];
|
|
58
|
+
if (media?.trim().toLowerCase() !== "text/event-stream") return false;
|
|
59
|
+
const quality = parameters.find((parameter) => /^\s*q\s*=/iu.test(parameter));
|
|
60
|
+
const weight = quality === void 0 ? 1 : Number(quality.split("=")[1]);
|
|
61
|
+
return weight > 0 && weight <= 1;
|
|
62
|
+
});
|
|
49
63
|
const answeringWithProgress = (success, run) => {
|
|
50
64
|
const check = checkedBy(success);
|
|
51
65
|
return (payload) => Effect.flatMap(HttpServerRequest.HttpServerRequest, (request) => acceptsEventStream(request) ? streamed((reporting, send) => run(payload, reporting).pipe(Effect.tap(check), Effect.flatMap((data) => send({
|
|
@@ -65,7 +79,7 @@ const progressedOf = ({ event, data }) => {
|
|
|
65
79
|
return event === "final" ? Progressed.Final({ value: data }) : Progressed.Element({ value: data });
|
|
66
80
|
};
|
|
67
81
|
const answeredWithout = /* @__PURE__ */ new Error("A route of an action declaring progress or answering a stream answered without its event stream");
|
|
68
|
-
const sentFrom = (answer) => Stream.isStream(answer) ? Stream.
|
|
82
|
+
const sentFrom = ([answer, response]) => response.headers["content-type"]?.split(";")[0]?.trim().toLowerCase() === "text/event-stream" && Stream.isStream(answer) ? Stream.mapEffect(answer, (event) => isSent(event) ? Effect.succeed(progressedOf(event)) : Effect.die(answeredWithout)) : Stream.die(answeredWithout);
|
|
69
83
|
const readWithProgress = (answer, onProgress) => answerFrom(sentFrom(answer), onProgress);
|
|
70
84
|
const readElements = (answer, onProgress) => elementsFrom(sentFrom(answer), onProgress);
|
|
71
85
|
export { acceptsEventStream, answeredWithProgress, answeringElements, answeringWithProgress, elementStreamOf, progressStreamOf, readElements, readWithProgress };
|
package/dist/rpc/erased.d.mts
CHANGED
|
@@ -18,11 +18,6 @@ export declare class DeclaredFailure {
|
|
|
18
18
|
constructor(json: Schema.Json);
|
|
19
19
|
toString(): string;
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
22
|
-
* What serves a binding's erased rpcs: `ActionRpc.layer`, which streams each event type beside
|
|
23
|
-
* polling it, through its `middleware`, or an entity, which only polls them, holds their webhooks
|
|
24
|
-
* and runs `check` on each input.
|
|
25
|
-
*/
|
|
26
21
|
export type Server = {
|
|
27
22
|
readonly _tag: "ActionRpc.layer";
|
|
28
23
|
readonly middleware: readonly RpcMiddleware.AnyService[];
|
|
@@ -36,7 +31,6 @@ export type Server = {
|
|
|
36
31
|
* `ActionRpc.client`'s polling watch calls.
|
|
37
32
|
*/
|
|
38
33
|
export declare const pollTag: (name: string) => string;
|
|
39
|
-
/** The rpcs `server` serves for `actions` and `events`, and its clients call. */
|
|
40
34
|
export declare const erasedOf: (actions: readonly Any[], events: readonly Any$1[], server: Server["_tag"]) => RpcGroup.RpcGroup<Rpc.Rpc<string, Schema.Codec<Schema.Json, Schema.Json, never, never>, Schema.Codec<Schema.Json, Schema.Json, never, never>, Schema.instanceOf<DeclaredFailure, DeclaredFailure>, never, never> | Rpc.Rpc<string, Schema.Codec<Schema.Json, Schema.Json, never, never>, import("effect/rpc/RpcSchema").Stream<Schema.Codec<Schema.Json, Schema.Json, never, never>, Schema.instanceOf<DeclaredFailure, DeclaredFailure>>, Schema.Never, never, never>>;
|
|
41
35
|
/**
|
|
42
36
|
* The payload of an event type's poll rpc, `<event>/poll`, past its `input`, as a client sends
|
|
@@ -54,9 +48,4 @@ export declare const ProgressedOf: <P extends Codec, S extends Codec>(progress:
|
|
|
54
48
|
}>, Schema.TaggedStruct<"Final", {
|
|
55
49
|
readonly value: S;
|
|
56
50
|
}>]>;
|
|
57
|
-
/**
|
|
58
|
-
* What a server checks of each call's and subscription's decoded input, once it has verified its
|
|
59
|
-
* caller and before the implementation's authorizer: an entity refuses an input whose key names
|
|
60
|
-
* another entity.
|
|
61
|
-
*/
|
|
62
51
|
export type InputCheck = (contract: Any | Any$1, input: ErasedValue) => Effect.Effect<void, Forbidden>;
|
package/dist/rpc/erased.mjs
CHANGED
|
@@ -31,7 +31,7 @@ const throughSteps = (steps, call, options) => {
|
|
|
31
31
|
};
|
|
32
32
|
const authenticatingOf = (authentication) => Effect.map(providerOf(authentication), (provider) => {
|
|
33
33
|
const verify = Effect.flatMap(HttpApiBuilder.securityDecode(authentication.security), provider.authenticate);
|
|
34
|
-
return (verifying) => (effect, options) => Effect.
|
|
34
|
+
return (verifying) => (effect, options) => Effect.provideServiceEffect(effect, authentication.identity, verifying(verify, options));
|
|
35
35
|
});
|
|
36
36
|
var DeclaredFailure = class {
|
|
37
37
|
[ErrorReporter.ignore] = true;
|
|
@@ -73,7 +73,6 @@ const subscribeTag = (name) => `${name}/subscribe`;
|
|
|
73
73
|
const unsubscribeTag = (name) => `${name}/unsubscribe`;
|
|
74
74
|
const webhookRpcsOf = (events) => RpcGroup.make(...events.filter(offersWebhook).flatMap((event) => [unaryOf(subscribeTag(event.name)), unaryOf(unsubscribeTag(event.name))]));
|
|
75
75
|
const webhookErrors = (event, binding) => Schema.Union([...eventErrors(event, binding), SubscriptionError]);
|
|
76
|
-
/** The rpcs `server` serves for `actions` and `events`, and its clients call. */
|
|
77
76
|
const erasedOf = (actions, events, server) => RpcGroup.make(...actions.map((action) => streams(action) ? streamOf(action.name) : unaryOf(action.name)), ...events.flatMap((event) => [...streamsEvents(server) ? [streamOf(event.name)] : [], unaryOf(pollTag(event.name))]));
|
|
78
77
|
const Watch = Schema.String.check(Schema.isUUID());
|
|
79
78
|
/**
|
|
@@ -191,10 +190,6 @@ const polledTransport = (transient, resendAfter) => (event, binding) => {
|
|
|
191
190
|
};
|
|
192
191
|
};
|
|
193
192
|
};
|
|
194
|
-
/**
|
|
195
|
-
* An action's client method over `reach`: its call goes where its input, decoded as the server
|
|
196
|
-
* will decode it, a decoding default included, says.
|
|
197
|
-
*/
|
|
198
193
|
const actionMethodOf = (action, binding) => {
|
|
199
194
|
const method = calledMethodOf(action, binding);
|
|
200
195
|
const answer = (reach, [input, ...rest]) => Effect.flatMap(sentInput(action, input), ({ value }) => Effect.map(reach(action, value), (call) => method(call)(value, ...rest)));
|
package/docs/setup.md
CHANGED
|
@@ -23,7 +23,7 @@ The `effect` peer admits the 4.1.x patches from the oldest whose APIs and behavi
|
|
|
23
23
|
|
|
24
24
|
Keep the tilde in `package.json`: `^4.1.4`, which npm writes for `effect@4.1.4`, admits a minor release outside the peer range. `npm install effect@~4.1.4` keeps it.
|
|
25
25
|
|
|
26
|
-
Node `>=26.13.
|
|
26
|
+
Node `>=26.13.1`: the package's `engines`, the Node the library is developed and tested on. TypeScript 7 or newer. ESM only. The repository checks the examples with a stricter `tsconfig.json`; this is the minimum a project needs. The package's modules resolve only through its `exports`, which `"module": "nodenext"` reads, as a bundler project's `"moduleResolution": "bundler"` does. `"strict": true` is required, by Effect:
|
|
27
27
|
|
|
28
28
|
```json
|
|
29
29
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjermundgaraba/effect-actions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "Define Effect action contracts once and project them onto HTTP, MCP, Effect RPC, native Toolkits, and CLIs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agents",
|
|
@@ -54,19 +54,19 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@clanker-stuff/oxlint-config": "0.5.
|
|
58
|
-
"@effect/platform-node": "4.1.
|
|
59
|
-
"@effect/sql-sqlite-node": "4.1.
|
|
60
|
-
"@effect/tsgo": "0.
|
|
61
|
-
"@effect/vitest": "4.1.
|
|
57
|
+
"@clanker-stuff/oxlint-config": "0.5.1",
|
|
58
|
+
"@effect/platform-node": "4.1.5",
|
|
59
|
+
"@effect/sql-sqlite-node": "4.1.5",
|
|
60
|
+
"@effect/tsgo": "0.73.2",
|
|
61
|
+
"@effect/vitest": "4.1.5",
|
|
62
62
|
"@modelcontextprotocol/client": "2.4.0",
|
|
63
63
|
"@types/node": "26.6.6",
|
|
64
|
-
"effect": "4.1.
|
|
64
|
+
"effect": "4.1.5",
|
|
65
65
|
"tsx": "4.23.15",
|
|
66
66
|
"typescript": "7.0.2",
|
|
67
|
-
"ultracite": "8.
|
|
68
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@
|
|
69
|
-
"vite-plus": "1.
|
|
67
|
+
"ultracite": "8.3.1",
|
|
68
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@8.3.8000",
|
|
69
|
+
"vite-plus": "1.7.0",
|
|
70
70
|
"vitest": "5.1.0"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
@@ -75,12 +75,12 @@
|
|
|
75
75
|
"devEngines": {
|
|
76
76
|
"packageManager": {
|
|
77
77
|
"name": "pnpm",
|
|
78
|
-
"version": "12.
|
|
78
|
+
"version": "12.21.0",
|
|
79
79
|
"onFail": "download"
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
"engines": {
|
|
83
|
-
"node": ">=26.13.
|
|
83
|
+
"node": ">=26.13.1"
|
|
84
84
|
},
|
|
85
85
|
"scripts": {
|
|
86
86
|
"build": "vp pack",
|