@gjermundgaraba/effect-actions 0.28.0 → 0.30.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/dist/Action.d.mts +6 -6
- package/dist/Action.mjs +11 -11
- package/dist/ActionCli.d.mts +23 -23
- package/dist/ActionCli.mjs +4 -4
- package/dist/ActionHttp.d.mts +16 -16
- package/dist/ActionHttp.mjs +7 -7
- package/dist/ActionMcp.d.mts +8 -8
- package/dist/ActionMcp.mjs +8 -8
- package/dist/ActionRpc.d.mts +22 -22
- package/dist/ActionRpc.mjs +8 -8
- package/dist/ActionToolkit.d.mts +1 -1
- package/dist/ActionToolkit.mjs +3 -3
- package/dist/Authentication.d.mts +2 -2
- package/dist/Authentication.mjs +1 -1
- 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 +1 -1
- package/dist/cli/commands.d.mts +2 -2
- package/dist/cli/commands.mjs +5 -5
- package/dist/contract/authorizer.d.mts +1 -1
- package/dist/contract/call.d.mts +2 -2
- 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/feed.d.mts +1 -1
- package/dist/contract/feed.mjs +6 -6
- 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 +1 -1
- 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 +2 -2
- package/dist/contract/receiving.d.mts +2 -2
- package/dist/contract/receiving.mjs +1 -1
- package/dist/contract/serving.mjs +2 -2
- package/dist/contract/subscribe.mjs +1 -1
- package/dist/contract/transient.mjs +1 -1
- package/dist/contract/watch.d.mts +1 -1
- package/dist/contract/watch.mjs +2 -2
- package/dist/contract/webhooks.d.mts +1 -1
- package/dist/http/client.d.mts +9 -9
- package/dist/http/client.mjs +1 -1
- package/dist/http/events.d.mts +6 -6
- package/dist/http/events.mjs +4 -4
- package/dist/http/placed.d.mts +3 -3
- package/dist/http/placed.mjs +5 -5
- package/dist/http/streamed.d.mts +2 -2
- package/dist/http/streamed.mjs +1 -1
- package/dist/http/watch.mjs +1 -1
- package/dist/mcp/bridge.mjs +8 -8
- package/dist/mcp/client.d.mts +10 -10
- package/dist/mcp/client.mjs +4 -4
- package/dist/mcp/protocol.mjs +16 -4
- package/dist/mcp/reply.d.mts +1 -1
- package/dist/mcp/watch.mjs +4 -4
- package/dist/webhook/stored.mjs +1 -1
- package/dist/webhook/subscriptions.mjs +8 -5
- package/docs/setup.md +1 -1
- package/package.json +11 -12
package/dist/Event.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { Options as Options$1 } from "./Action.mjs";
|
|
2
|
+
import { Authorizer, Deferred as Deferred$1 } from "./contract/authorizer.mjs";
|
|
1
3
|
import { Codec, CodecOf, Fields, NoInput } from "./contract/codec.mjs";
|
|
2
4
|
import { Refusal } from "./contract/errors.mjs";
|
|
3
|
-
import { Gap, OccurrenceSchema } from "./contract/occurrence.mjs";
|
|
4
5
|
import { AnyEventImplementation, EventImplementation } from "./contract/feed.mjs";
|
|
5
|
-
import { Listed, LogStorage } from "./contract/log.mjs";
|
|
6
6
|
import { Events, KeyOptions, MakeEventsOptions, RevisionStorage, layerMemory, makeEvents } from "./contract/hub.mjs";
|
|
7
7
|
import { Protected } from "./contract/implementation.mjs";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { Gap, OccurrenceSchema } from "./contract/occurrence.mjs";
|
|
9
|
+
import { Listed, LogStorage } from "./contract/log.mjs";
|
|
10
10
|
import { DateTime, Duration, Effect, Schema, Scope, Stream } from "effect";
|
|
11
11
|
declare const TypeId = "~@gjermundgaraba/effect-actions/Event";
|
|
12
12
|
/** What `make` needs to define an event type. */
|
package/dist/Event.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { authorizerOf } from "./contract/authorizer.mjs";
|
|
1
2
|
import { Anyone, assertCaller } from "./contract/caller.mjs";
|
|
2
|
-
import { assertEventName, assertOnce } from "./contract/names.mjs";
|
|
3
3
|
import { codecOf } from "./contract/codec.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { EventImplementation, sourcesOf } from "./contract/feed.mjs";
|
|
5
|
+
import { assertEventName, assertOnce } from "./contract/names.mjs";
|
|
5
6
|
import { Events, layerMemory, makeEvents } from "./contract/hub.mjs";
|
|
6
7
|
import { Gap } from "./contract/occurrence.mjs";
|
|
7
|
-
import { EventImplementation, sourcesOf } from "./contract/feed.mjs";
|
|
8
8
|
import { Array as Array$1, Data, Effect, Match, Predicate, Schema } from "effect";
|
|
9
9
|
// src/contract/Event.ts
|
|
10
10
|
const TypeId = "~@gjermundgaraba/effect-actions/Event";
|
package/dist/Webhook.d.mts
CHANGED
|
@@ -89,6 +89,7 @@ export interface Options {
|
|
|
89
89
|
* - An occurrence given up, its body over 256 KiB or its POST answered `410` or `413`, is POSTed as a `gap` at its cursor; one whose admission fails with no refusal is reported and read again, from before it, every 5 seconds.
|
|
90
90
|
* - A refresh restarts its subscription's reading under the refreshed subscriber, from where delivery reached: the subscription hook set up again once the old one is released, and a delivery in flight sent again, which the subscriber drops by its `eventId`.
|
|
91
91
|
* - A refresh its authorizer refuses ends the subscription it names, POSTing `terminated`, though each delivery, admitted as the subscriber of the last grant, would still pass.
|
|
92
|
+
* - A `terminated` POST is tried four times, and one never accepted is logged as a warning naming the subscription; one answered `410` or `413` is given up at once, unlogged.
|
|
92
93
|
* - A refresh with a new secret signs each POST with both secrets for 5 minutes, `webhook-signature` holding two, so a receiver may switch over; after that, with the new one alone.
|
|
93
94
|
* - A delivery runs in the subscribe request's context without the request: an authorizer or a source reading `HttpServerRequest` fails in a delivery, so read what it needs in middleware, which provides it as a service.
|
|
94
95
|
* - `allowedCallbacks` throws when `layer` is called for an entry that is not an https URL.
|
|
@@ -121,6 +122,7 @@ export type DeliveryOptions = ConstructorParameters<typeof WebhookDelivery>[0];
|
|
|
121
122
|
* - A server refuses a callback that is not globally reachable, so `baseUrl` is a public name of this process, such as a tunnel's in development.
|
|
122
123
|
* - The URL subscribed carries a `watch` query parameter, one per watch, so watches never share a subscription: a proxy in front of the route must pass the query on.
|
|
123
124
|
* - A restarted process subscribes afresh from the cursor `resume` kept, so the server sends again what the last process accepted and never handed on; the old subscription lapses at its grant, each delivery to it answered 410.
|
|
125
|
+
* - An unsubscribe that fails, or is not answered within 5 seconds, is not reported: the subscription lapses at its grant, as a restarted process's does.
|
|
124
126
|
*/
|
|
125
127
|
export declare const delivery: (options: DeliveryOptions) => WebhookDelivery;
|
|
126
128
|
/** Where `layerReceiver` serves its route. */
|
package/dist/Webhook.mjs
CHANGED
|
@@ -49,6 +49,7 @@ function layer(options = {}) {
|
|
|
49
49
|
* - A server refuses a callback that is not globally reachable, so `baseUrl` is a public name of this process, such as a tunnel's in development.
|
|
50
50
|
* - The URL subscribed carries a `watch` query parameter, one per watch, so watches never share a subscription: a proxy in front of the route must pass the query on.
|
|
51
51
|
* - A restarted process subscribes afresh from the cursor `resume` kept, so the server sends again what the last process accepted and never handed on; the old subscription lapses at its grant, each delivery to it answered 410.
|
|
52
|
+
* - An unsubscribe that fails, or is not answered within 5 seconds, is not reported: the subscription lapses at its grant, as a restarted process's does.
|
|
52
53
|
*/
|
|
53
54
|
const delivery = (options) => new WebhookDelivery(options);
|
|
54
55
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Any as Any$1, Errors } from "../Action.mjs";
|
|
2
2
|
import { Anyone } from "../contract/caller.mjs";
|
|
3
|
+
import { Codec } from "../contract/codec.mjs";
|
|
3
4
|
import { Refusal } from "../contract/errors.mjs";
|
|
5
|
+
import { Any as Any$2 } from "../Event.mjs";
|
|
4
6
|
import { EventOf, ServingEvents } from "../contract/feed.mjs";
|
|
5
|
-
import { Any as Any$1 } from "../Event.mjs";
|
|
6
7
|
import { BuildServices, Protected, ServedRequest, Serving } from "../contract/implementation.mjs";
|
|
7
|
-
import { Any as Any$2, Errors } from "../Action.mjs";
|
|
8
8
|
import { Context, Effect } from "effect";
|
|
9
9
|
import { HttpRouter, HttpServerResponse } from "effect/http";
|
|
10
10
|
import { HttpApiMiddleware, HttpApiSecurity } from "effect/http-api";
|
|
@@ -90,10 +90,10 @@ export interface Descriptor<I, A, S extends Security, Name extends string = stri
|
|
|
90
90
|
*/
|
|
91
91
|
export type Any = Descriptor<unknown, unknown, Security, string, Errors>;
|
|
92
92
|
/** The identity an action's `caller` names, or `never` for none. */
|
|
93
|
-
export type Identity<A extends Pick<Any$
|
|
94
|
-
type Covered<A extends Pick<Any$
|
|
93
|
+
export type Identity<A extends Pick<Any$1, "caller">> = [A] extends [never] ? never : A["caller"] extends Context.Key<infer I, unknown> ? I : never;
|
|
94
|
+
type Covered<A extends Pick<Any$1, "caller">> = Exclude<A["caller"], typeof Anyone> extends Context.Key<infer I, unknown> ? I : never;
|
|
95
95
|
/** The `authentication` a binding of these actions takes: required once one is protected. */
|
|
96
|
-
export type Required<A extends Pick<Any$
|
|
96
|
+
export type Required<A extends Pick<Any$1, "caller">> = [Protected<A>] extends [never] ? {
|
|
97
97
|
readonly authentication?: Any;
|
|
98
98
|
} : {
|
|
99
99
|
readonly authentication: Descriptor<Covered<Protected<A>>, unknown, Security, string, Errors>;
|
|
@@ -101,7 +101,7 @@ export type Required<A extends Pick<Any$2, "caller">> = [Protected<A>] extends [
|
|
|
101
101
|
/** The provider `Authentication.layer` builds for the descriptor `D`. */
|
|
102
102
|
export type ProviderOf<D> = D extends Descriptor<infer I, unknown, Security, infer Name, Errors> ? Provider<I, Name> : never;
|
|
103
103
|
/** Actions a binding takes without options: public ones, as a protected one names its descriptor. */
|
|
104
|
-
export type PublicOnly<Actions extends ReadonlyArray<Pick<Any$
|
|
104
|
+
export type PublicOnly<Actions extends ReadonlyArray<Pick<Any$1, "caller">>> = [Exclude<Actions[number], {
|
|
105
105
|
readonly caller: typeof Anyone;
|
|
106
106
|
}>] extends [never] ? unknown : {
|
|
107
107
|
readonly "Protected actions take options naming their authentication": never;
|
|
@@ -111,20 +111,20 @@ export type DescriptorOf<O> = [O] extends [{
|
|
|
111
111
|
readonly authentication: infer D extends Any;
|
|
112
112
|
}] ? D : undefined;
|
|
113
113
|
/** All protected actions on a surface use the descriptor's single identity key. */
|
|
114
|
-
export type Matching<A extends Pick<Any$
|
|
114
|
+
export type Matching<A extends Pick<Any$1, "caller">, D> = unknown extends Covered<Protected<A>> ? unknown : [Exclude<Covered<Protected<A>>, D extends Descriptor<infer I, unknown, Security, string, Errors> ? I : never>] extends [never] ? unknown : {
|
|
115
115
|
readonly "Authentication descriptor does not cover every protected action": never;
|
|
116
116
|
};
|
|
117
|
-
type PublicRequest<App, A extends Any$
|
|
117
|
+
type PublicRequest<App, A extends Any$1> = ServedRequest<App, Extract<A, {
|
|
118
118
|
readonly caller: typeof Anyone;
|
|
119
119
|
}>>;
|
|
120
|
-
type ProtectedRequestLessIdentity<App, A extends Any$
|
|
121
|
-
export type RemoteRequest<App, A extends Any$
|
|
120
|
+
type ProtectedRequestLessIdentity<App, A extends Any$1> = Exclude<ServedRequest<App, Protected<A>>, Identity<Protected<A>>>;
|
|
121
|
+
export type RemoteRequest<App, A extends Any$1> = PublicRequest<App, A> | ProtectedRequestLessIdentity<App, A>;
|
|
122
122
|
/**
|
|
123
123
|
* The identity a remote layer's authentication provides every request, where `App` serves only
|
|
124
124
|
* protected actions of `A` and event types of `E`: its middleware reading it then owes nothing.
|
|
125
125
|
* None where one served is public, whose requests authenticate no one.
|
|
126
126
|
*/
|
|
127
|
-
export type LayerIdentity<App, A extends Any$
|
|
127
|
+
export type LayerIdentity<App, A extends Any$1, E extends Any$2> = [Extract<Serving<App, A>, {
|
|
128
128
|
readonly caller: typeof Anyone;
|
|
129
129
|
}> | Extract<ServingEvents<App, E>, {
|
|
130
130
|
readonly caller: typeof Anyone;
|
|
@@ -134,7 +134,7 @@ export type LayerIdentity<App, A extends Any$2, E extends Any$1> = [Extract<Serv
|
|
|
134
134
|
* `BuildServices` states it, with the caller a builder yields named as the mistake it is: a server
|
|
135
135
|
* has its caller per request.
|
|
136
136
|
*/
|
|
137
|
-
export type ServerBuildServices<App, A extends Any$
|
|
137
|
+
export type ServerBuildServices<App, A extends Any$1> = App extends unknown ? BuildServices<App, A> extends (infer R) ? R extends Identity<Protected<A>> ? {
|
|
138
138
|
readonly "A builder yields the caller, which a server has per request: yield it in a handler or an authorizer": {
|
|
139
139
|
readonly caller: R;
|
|
140
140
|
readonly builderOf: Serving<App, A>["name"];
|
|
@@ -144,12 +144,12 @@ export type ServerBuildServices<App, A extends Any$2> = App extends unknown ? Bu
|
|
|
144
144
|
* What a call of `A` under the descriptor `D` may fail with from its verifier: the errors `D`
|
|
145
145
|
* declares, for a protected action; none for a public one, which nothing verifies.
|
|
146
146
|
*/
|
|
147
|
-
export type VerifierError<A extends Pick<Any$
|
|
147
|
+
export type VerifierError<A extends Pick<Any$1, "caller">, D> = A["caller"] extends typeof Anyone ? never : D extends {
|
|
148
148
|
readonly error: infer E extends Errors;
|
|
149
149
|
} ? E[number] : never;
|
|
150
150
|
/**
|
|
151
151
|
* The provider a surface's startup reads under the descriptor `D`, where the implementations
|
|
152
152
|
* `App` serve a protected action of `A` or a protected event type of `E`.
|
|
153
153
|
*/
|
|
154
|
-
export type ServedProvider<App, A extends Any$
|
|
154
|
+
export type ServedProvider<App, A extends Any$1, D, E extends Any$2 = EventOf<App>> = [Protected<Serving<App, A>> | Protected<E>] extends [never] ? never : ProviderOf<D>;
|
|
155
155
|
export { Runtime$1 as Runtime };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { errorSchemas } from "../contract/declared.mjs";
|
|
1
2
|
import { Forbidden, Refusal, Unauthenticated } from "../contract/errors.mjs";
|
|
2
3
|
import { declared, httpApiStatusOf } from "../contract/status.mjs";
|
|
3
|
-
import { errorSchemas } from "../contract/declared.mjs";
|
|
4
4
|
import { Cause, Context, Effect, Exit, Option, Predicate, Ref, Schema } from "effect";
|
|
5
5
|
import { HttpServerResponse } from "effect/http";
|
|
6
6
|
// src/authentication/refusal.ts
|
package/dist/cli/commands.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { Any } from "../Action.mjs";
|
|
1
2
|
import "../contract/errors.mjs";
|
|
2
3
|
import "../Event.mjs";
|
|
3
|
-
import "../contract/progress.mjs";
|
|
4
4
|
import "../contract/implementation.mjs";
|
|
5
|
+
import "../contract/progress.mjs";
|
|
5
6
|
import { Each } from "../contract/stream.mjs";
|
|
6
|
-
import { Any } from "../Action.mjs";
|
|
7
7
|
import { Effect, Option, Runtime, Stream, Types } from "effect";
|
|
8
8
|
import { CliError, Command } from "effect/cli";
|
|
9
9
|
type Field<A extends Any> = A["input"]["Encoded"] extends (infer E) ? true extends Types.IsUnion<E> ? never : E extends readonly unknown[] ? never : E extends object ? string extends keyof E ? never : Extract<keyof E, string> : never : never;
|
package/dist/cli/commands.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { literalValues, members, unsuspended } from "../contract/ast.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { decodeInput } from "../contract/call.mjs";
|
|
3
3
|
import { errorSchemas } from "../contract/declared.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { InvalidInput } from "../contract/errors.mjs";
|
|
5
|
+
import { SubscriptionError } from "../Event.mjs";
|
|
6
6
|
import { elementsOf } from "../contract/implementation.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import { assertDistinct } from "../contract/names.mjs";
|
|
8
8
|
import { ReceivedOf } from "../contract/occurrence.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import { elementOf } from "../contract/stream.mjs";
|
|
10
10
|
import { withStderrConsole } from "../stdio/console.mjs";
|
|
11
11
|
import { Console, Effect, Option, Predicate, Record, Runtime, Schema, SchemaAST, Stdio, Stream } from "effect";
|
|
12
12
|
import { CliError, Command, Flag, Param } from "effect/cli";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Refusal } from "./errors.mjs";
|
|
2
1
|
import "./implementation.mjs";
|
|
2
|
+
import { Refusal } from "./errors.mjs";
|
|
3
3
|
import { Effect } from "effect";
|
|
4
4
|
/** `T`, read only once it is inferred: an implementation's build channels. */
|
|
5
5
|
type Deferred$1<T> = [T][T extends unknown ? 0 : never];
|
package/dist/contract/call.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { Any } from "../Action.mjs";
|
|
1
2
|
import "./codec.mjs";
|
|
2
3
|
import "./errors.mjs";
|
|
3
|
-
import { ProgressArgs } from "./progress.mjs";
|
|
4
4
|
import "./implementation.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { ProgressArgs } from "./progress.mjs";
|
|
6
6
|
import { Effect, Schema, Stream } from "effect";
|
|
7
7
|
/**
|
|
8
8
|
* A call of `A` answering `R`, taking `{ onProgress }` after its input where `A` declares
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Anyone, assertAuthentication } from "./caller.mjs";
|
|
2
1
|
import { literalValues, members } from "./ast.mjs";
|
|
2
|
+
import { Anyone, assertAuthentication } from "./caller.mjs";
|
|
3
3
|
import { builtIns } from "./errors.mjs";
|
|
4
4
|
import { httpApiStatusOf } from "./status.mjs";
|
|
5
5
|
import { Predicate, Schema, SchemaAST } from "effect";
|
package/dist/contract/feed.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Anyone } from "./caller.mjs";
|
|
2
|
-
import { Fed, Page } from "./pages.mjs";
|
|
3
2
|
import { Any } from "../Event.mjs";
|
|
4
3
|
import { ErasedAuthorize, ErasedValue, Memoized, Protected } from "./implementation.mjs";
|
|
4
|
+
import { Fed, Page } from "./pages.mjs";
|
|
5
5
|
import { Context, Duration, Effect, Layer, Stream } from "effect";
|
|
6
6
|
/**
|
|
7
7
|
* An implemented event type, behind its authorizer, as a surface serves it: a poll, whose
|
package/dist/contract/feed.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Anyone } from "./caller.mjs";
|
|
2
|
-
import { Unauthenticated } from "./errors.mjs";
|
|
3
|
-
import { checkInput } from "./input-check.mjs";
|
|
4
|
-
import { assertKnown } from "./names.mjs";
|
|
5
|
-
import { builderLayer, memoized, notMadeHere, selectHeld } from "./implementation.mjs";
|
|
6
1
|
import { jsonRoundTrip } from "./call.mjs";
|
|
2
|
+
import { Anyone } from "./caller.mjs";
|
|
7
3
|
import { canonicalInput } from "./canonical.mjs";
|
|
8
|
-
import {
|
|
4
|
+
import { Unauthenticated } from "./errors.mjs";
|
|
9
5
|
import { Events, attachmentsOf, reaches } from "./hub.mjs";
|
|
6
|
+
import { builderLayer, memoized, notMadeHere, selectHeld } from "./implementation.mjs";
|
|
7
|
+
import { checkInput } from "./input-check.mjs";
|
|
10
8
|
import { makeLeases } from "./lease.mjs";
|
|
9
|
+
import { assertKnown } from "./names.mjs";
|
|
11
10
|
import { AnyOccurrence, Gap } from "./occurrence.mjs";
|
|
12
11
|
import { fedOf, pagedFrom } from "./pages.mjs";
|
|
12
|
+
import { reported } from "./reported.mjs";
|
|
13
13
|
import { Array, DateTime, Duration, Effect, Layer, Option, Predicate, Stream } from "effect";
|
|
14
14
|
// src/contract/feed.ts
|
|
15
15
|
const defaultNextPoll = Duration.seconds(5);
|
package/dist/contract/hub.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LogStorage } from "./log.mjs";
|
|
2
1
|
import { Any, Emitted } from "../Event.mjs";
|
|
2
|
+
import { LogStorage } from "./log.mjs";
|
|
3
3
|
import { Context, Effect, Layer, Scope, Stream } from "effect";
|
|
4
4
|
/** What `notify` and `publish` take: the key whose subscribers they reach. */
|
|
5
5
|
export interface KeyOptions {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { CallerKeyed, principalOf } from "./caller.mjs";
|
|
2
|
-
import { InvalidInput } from "./errors.mjs";
|
|
3
|
-
import { declaredStatus, isTransientStatus } from "./status.mjs";
|
|
4
|
-
import { projectedErrors } from "./declared.mjs";
|
|
5
|
-
import { answered } from "./implementation.mjs";
|
|
6
2
|
import { canonicalInput } from "./canonical.mjs";
|
|
3
|
+
import { projectedErrors } from "./declared.mjs";
|
|
7
4
|
import { sha256Hex } from "./digest.mjs";
|
|
5
|
+
import { InvalidInput } from "./errors.mjs";
|
|
6
|
+
import { answered } from "./implementation.mjs";
|
|
7
|
+
import { declaredStatus, isTransientStatus } from "./status.mjs";
|
|
8
8
|
import { Cause, Clock, Context, Deferred, Effect, Exit, Layer, Option, Predicate, Schema } from "effect";
|
|
9
9
|
// src/contract/idempotency.ts
|
|
10
10
|
const Kept = Schema.Struct({
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { Any } from "../Action.mjs";
|
|
1
2
|
import { Anyone, Keyed } from "./caller.mjs";
|
|
2
3
|
import { Refusal } from "./errors.mjs";
|
|
4
|
+
import { Any as Any$1 } from "../Event.mjs";
|
|
3
5
|
import { AnyEventImplementation, EventOf } from "./feed.mjs";
|
|
4
|
-
import { Any } from "../Event.mjs";
|
|
5
6
|
import { Reporting } from "./progress.mjs";
|
|
6
|
-
import { Any as Any$1 } from "../Action.mjs";
|
|
7
7
|
import { Context, Effect, Layer, Scope, Stream } from "effect";
|
|
8
8
|
/** Decoded values at the dispatch boundary every surface shares. */
|
|
9
|
-
export type ErasedValue = Any
|
|
9
|
+
export type ErasedValue = Any["input"]["Type"];
|
|
10
10
|
export type WrittenHandler<R> = {
|
|
11
11
|
bivarianceHack(input: ErasedValue, reporting?: Reporting): Effect.Effect<ErasedValue, ErasedValue, R> | Stream.Stream<ErasedValue, ErasedValue, R>;
|
|
12
12
|
}["bivarianceHack"];
|
|
@@ -21,13 +21,13 @@ export type ErasedHandler<R> = (input: ErasedValue, reporting?: Reporting) => Ef
|
|
|
21
21
|
* Authorization for protected contracts: it refuses, and fails with nothing else. It runs only for
|
|
22
22
|
* protected actions, after authentication and before the handler.
|
|
23
23
|
*/
|
|
24
|
-
export type Authorize<A extends Any
|
|
24
|
+
export type Authorize<A extends Any, R = never> = (action: A) => Effect.Effect<void, Refusal, R>;
|
|
25
25
|
/** An authorization rule over contracts `C`, erased: it refuses, or lets the call run. */
|
|
26
|
-
export type ErasedAuthorize<C = Any
|
|
26
|
+
export type ErasedAuthorize<C = Any> = (contract: C) => Effect.Effect<void, unknown, unknown>;
|
|
27
27
|
/** Each action of an implementation with its handler, as `dispatch` makes it. */
|
|
28
|
-
export type Bound = ReadonlyArray<readonly [Any
|
|
28
|
+
export type Bound = ReadonlyArray<readonly [Any, ErasedHandler<unknown>]>;
|
|
29
29
|
/** Each action of an implementation with its handler as written, as its builder made them. */
|
|
30
|
-
export type Written = ReadonlyArray<readonly [Any
|
|
30
|
+
export type Written = ReadonlyArray<readonly [Any, WrittenHandler<unknown>]>;
|
|
31
31
|
/** A build shared by every layer an implementation reaches, through the one key it is provided under. */
|
|
32
32
|
export interface Memoized<S, E, R> {
|
|
33
33
|
readonly key: Context.Key<S, S>;
|
|
@@ -42,7 +42,7 @@ export interface Memoized<S, E, R> {
|
|
|
42
42
|
* its handlers' builder, `RA` what its authorizer reads per request, and `EAX` and `RAX` the
|
|
43
43
|
* failures and services of the authorizer's builder.
|
|
44
44
|
*/
|
|
45
|
-
export declare class Implementation<A extends Any
|
|
45
|
+
export declare class Implementation<A extends Any, RequestServices, EX, RX, RA = never, EAX = never, RAX = never> {
|
|
46
46
|
#private;
|
|
47
47
|
/** Type-only: each action's handler's request-time requirements. */
|
|
48
48
|
readonly "~request": RequestServices;
|
|
@@ -64,7 +64,7 @@ export declare class Implementation<A extends Any$1, RequestServices, EX, RX, RA
|
|
|
64
64
|
/** Builds its authorizer. */
|
|
65
65
|
authorizer: Memoized<ErasedAuthorize, EAX, RAX>);
|
|
66
66
|
/** Select contracts while retaining their handlers, authorization and shared builder. */
|
|
67
|
-
static share(actions: readonly Any
|
|
67
|
+
static share(actions: readonly Any[], app: AnyImplementation): AnyImplementation;
|
|
68
68
|
/**
|
|
69
69
|
* The key of what runs a call of `app`'s actions: its handlers' memoized layer's, which each
|
|
70
70
|
* `implement` makes, so it is unique to the implementation. Every selection retains it.
|
|
@@ -90,7 +90,7 @@ export declare class Implementation<A extends Any$1, RequestServices, EX, RX, RA
|
|
|
90
90
|
* admits every implementation, while a value of this type owes `unknown`, which no surface can be
|
|
91
91
|
* given.
|
|
92
92
|
*/
|
|
93
|
-
export type AnyImplementation<A extends Any
|
|
93
|
+
export type AnyImplementation<A extends Any = Any> = Implementation<A, unknown, unknown, unknown, unknown, unknown, unknown>;
|
|
94
94
|
/** What a surface serves: one implementation, of actions or of events, or a list of them. */
|
|
95
95
|
export type Served = AnyImplementation | AnyEventImplementation | ReadonlyArray<AnyImplementation | AnyEventImplementation>;
|
|
96
96
|
/** What a surface serving no events takes: one action implementation, or a list of them. */
|
|
@@ -101,7 +101,7 @@ export type Member<S> = S extends ReadonlyArray<infer App> ? App : S;
|
|
|
101
101
|
* Options that may list actions and event types of `C`, the shape every selecting surface's
|
|
102
102
|
* options share.
|
|
103
103
|
*/
|
|
104
|
-
export interface Selection<C extends Any
|
|
104
|
+
export interface Selection<C extends Any | Any$1> {
|
|
105
105
|
readonly actions?: readonly C[] | undefined;
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
@@ -110,13 +110,13 @@ export interface Selection<C extends Any$1 | Any> {
|
|
|
110
110
|
* may be absent, being optional or a union with options lacking it, select every action at run
|
|
111
111
|
* time, so they narrow nothing.
|
|
112
112
|
*/
|
|
113
|
-
export type Selected<O, All extends Any
|
|
113
|
+
export type Selected<O, All extends Any> = O extends {
|
|
114
114
|
readonly actions: ReadonlyArray<infer C>;
|
|
115
|
-
} ? Extract<C, Any
|
|
115
|
+
} ? Extract<C, Any> : All;
|
|
116
116
|
/** The event types options `O` select, of `All`, as `Selected` selects actions. */
|
|
117
|
-
export type SelectedEvents<O, All extends Any> = O extends {
|
|
117
|
+
export type SelectedEvents<O, All extends Any$1> = O extends {
|
|
118
118
|
readonly actions: ReadonlyArray<infer C>;
|
|
119
|
-
} ? Extract<C, Any> : All;
|
|
119
|
+
} ? Extract<C, Any$1> : All;
|
|
120
120
|
/**
|
|
121
121
|
* The middleware options `O` install, each a member of `L`: its `middleware` when always given,
|
|
122
122
|
* an array of unknown length when it may be absent, which installs none or all of them, and
|
|
@@ -136,7 +136,7 @@ export type SelectedEventsOf<O, Apps extends Served> = SelectedEvents<O, EventOf
|
|
|
136
136
|
* list, wherever some member of `O` may list them, as each is present whether the list is
|
|
137
137
|
* given or not; every one where no member lists any.
|
|
138
138
|
*/
|
|
139
|
-
export type Offered<O, All extends Any
|
|
139
|
+
export type Offered<O, All extends Any | Any$1> = [Listing<O>] extends [never] ? All : Extract<All, Listing<O> extends ReadonlyArray<infer C> ? C : never>;
|
|
140
140
|
type Listing<O> = O extends unknown ? NonNullable<O["actions" & keyof O]> : never;
|
|
141
141
|
/**
|
|
142
142
|
* No key of any member of `O` beyond those of `Keys`, so a misspelled option is refused
|
|
@@ -154,7 +154,7 @@ export type OptionalUnless<O, Given> = {} extends O ? [options?: Given] : [optio
|
|
|
154
154
|
export type ActionOf<App> = App extends {
|
|
155
155
|
readonly actions: ReadonlyArray<infer A>;
|
|
156
156
|
} ? A : never;
|
|
157
|
-
type Matches<A extends Any
|
|
157
|
+
type Matches<A extends Any, Listed extends Any> = Listed extends Any ? [A] extends [Listed] ? true : [Listed] extends [A] ? true : never : never;
|
|
158
158
|
/**
|
|
159
159
|
* The actions of `App` a surface given the actions `Listed` may serve, as `select` selects
|
|
160
160
|
* them by identity: an action whose type either is assignable to, or is assigned by, one
|
|
@@ -162,34 +162,34 @@ type Matches<A extends Any$1, Listed extends Any$1> = Listed extends Any$1 ? [A]
|
|
|
162
162
|
* actions, an erased one included, still counts, and another contract of a listed name, which
|
|
163
163
|
* the surface leaves out beside an action it serves, does not.
|
|
164
164
|
*/
|
|
165
|
-
export type Serving<App, Listed extends Any
|
|
165
|
+
export type Serving<App, Listed extends Any> = ActionOf<App> extends (infer A extends Any) ? A extends unknown ? [A] extends [Listed] ? A : string extends A["name"] ? A : [Extract<A["name"], Listed["name"]>] extends [never] ? never : [Matches<A, Listed>] extends [never] ? never : A : never : never;
|
|
166
166
|
/**
|
|
167
167
|
* What each implementation among `App` owes per request where a surface serving the actions
|
|
168
168
|
* `Listed` serves it: its authorizer's services, and the handlers' of the actions it serves.
|
|
169
169
|
*/
|
|
170
|
-
export type ServedRequest<App, Listed extends Any
|
|
170
|
+
export type ServedRequest<App, Listed extends Any> = App extends unknown ? RequestOf<App, Serving<App, Listed>> : never;
|
|
171
171
|
/** The implementations among `App` holding an action of `Listed`: those a surface builds. */
|
|
172
|
-
export type Holding<App, Listed extends Any
|
|
172
|
+
export type Holding<App, Listed extends Any> = App extends unknown ? [Serving<App, Listed>] extends [never] ? never : App : never;
|
|
173
173
|
/** The protected members of a contract union, of actions or of events. */
|
|
174
|
-
export type Protected<A extends Pick<Any
|
|
174
|
+
export type Protected<A extends Pick<Any, "caller">> = A extends unknown ? A["caller"] extends typeof Anyone ? never : A : never;
|
|
175
175
|
type ServiceOf<K> = K extends Context.Key<infer I, unknown> ? I : never;
|
|
176
|
-
type AuthenticationOf<A extends Any
|
|
176
|
+
type AuthenticationOf<A extends Any> = A["caller"] extends typeof Anyone ? never : ServiceOf<A["caller"]>;
|
|
177
177
|
/**
|
|
178
178
|
* Per-request requirements of `App`'s authorization and handler for each `A` it
|
|
179
179
|
* implements: those of every name `A`'s may be, so a union or an erased name owes each it may
|
|
180
180
|
* stand for.
|
|
181
181
|
*/
|
|
182
|
-
export type RequestOf<App, A extends Any
|
|
182
|
+
export type RequestOf<App, A extends Any> = App extends {
|
|
183
183
|
readonly "~request": infer R;
|
|
184
184
|
readonly "~authorizeRequest": infer RA;
|
|
185
|
-
} ? A extends Any
|
|
186
|
-
type OwnActions<App> = Extract<ActionOf<App>, Any
|
|
185
|
+
} ? A extends Any ? unknown extends R ? unknown : [A["name"] & keyof R] extends [never] ? never : R[A["name"] & keyof R] | (A["caller"] extends typeof Anyone ? never : RA) | AuthenticationOf<A> : never : never;
|
|
186
|
+
type OwnActions<App> = Extract<ActionOf<App>, Any>;
|
|
187
187
|
/**
|
|
188
188
|
* What a surface serving the actions `Listed` of the implementations `App` fails with at startup:
|
|
189
189
|
* their builders' and built authorizers' failures, an authorizer's only if a selected protected
|
|
190
190
|
* action needs it.
|
|
191
191
|
*/
|
|
192
|
-
export type BuildError<App, Listed extends Any
|
|
192
|
+
export type BuildError<App, Listed extends Any = OwnActions<App>> = App extends {
|
|
193
193
|
readonly "~buildError": infer EX;
|
|
194
194
|
readonly "~authorizeBuildError": infer EAX;
|
|
195
195
|
} ? EX | ([Protected<Serving<App, Listed>>] extends [never] ? never : EAX) : never;
|
|
@@ -197,7 +197,7 @@ export type BuildError<App, Listed extends Any$1 = OwnActions<App>> = App extend
|
|
|
197
197
|
* What a surface serving the actions `Listed` of the implementations `App` reads at startup: their
|
|
198
198
|
* builders' and built authorizers' services.
|
|
199
199
|
*/
|
|
200
|
-
export type BuildServices<App, Listed extends Any
|
|
200
|
+
export type BuildServices<App, Listed extends Any = OwnActions<App>> = App extends {
|
|
201
201
|
readonly "~buildServices": infer RX;
|
|
202
202
|
readonly "~authorizeBuildServices": infer RAX;
|
|
203
203
|
} ? RX | ([Protected<Serving<App, Listed>>] extends [never] ? never : RAX) : never;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Anyone, CallerKeyed } from "./caller.mjs";
|
|
2
|
-
import { Unauthenticated } from "./errors.mjs";
|
|
3
2
|
import { projectedErrors } from "./declared.mjs";
|
|
3
|
+
import { Unauthenticated } from "./errors.mjs";
|
|
4
4
|
import { checkInput } from "./input-check.mjs";
|
|
5
5
|
import { assertOnce, heldOnce } from "./names.mjs";
|
|
6
6
|
import { reportedTo, streamReportedTo } from "./progress.mjs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Any } from "../Action.mjs";
|
|
1
2
|
import { Forbidden } from "./errors.mjs";
|
|
2
|
-
import { Any } from "../Event.mjs";
|
|
3
|
-
import { Any as Any$1 } from "../Action.mjs";
|
|
3
|
+
import { Any as Any$1 } from "../Event.mjs";
|
|
4
4
|
import { Context, Effect } from "effect";
|
|
5
5
|
/**
|
|
6
6
|
* A check every call and every subscription runs on its decoded input, on every surface, once the
|
|
@@ -12,4 +12,4 @@ import { Context, Effect } from "effect";
|
|
|
12
12
|
*
|
|
13
13
|
* - Provide it to the layer graph the surfaces are built in, as `Layer.succeed(Action.InputCheck)(check)`: provided per request, it misses a socket's later calls.
|
|
14
14
|
*/
|
|
15
|
-
export declare const InputCheck: Context.Reference<(contract: Any
|
|
15
|
+
export declare const InputCheck: Context.Reference<(contract: Any | Any$1, input: Any["input"]["Type"]) => Effect.Effect<void, Forbidden>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../Event.mjs";
|
|
2
1
|
import "../Action.mjs";
|
|
2
|
+
import "../Event.mjs";
|
|
3
3
|
/** The members of the list `T` that are `U`: `T` itself where every one is, `[]` where none is. */
|
|
4
4
|
export type Only<T extends readonly unknown[], U> = [Exclude<T[number], U>] extends [never] ? Extract<T, readonly U[]> : [Extract<T[number], U>] extends [never] ? readonly [] : ReadonlyArray<Extract<T[number], U>>;
|
package/dist/contract/listed.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { assertOnce } from "./names.mjs";
|
|
2
1
|
import { isEvent } from "../Event.mjs";
|
|
2
|
+
import { assertOnce } from "./names.mjs";
|
|
3
3
|
// src/contract/listed.ts
|
|
4
4
|
const split = (contracts) => ({
|
|
5
5
|
actions: contracts.flatMap((contract) => isEvent(contract) ? [] : [contract]),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Checked } from "./occurrence.mjs";
|
|
2
1
|
import { Any, Occurrence, Received } from "../Event.mjs";
|
|
2
|
+
import { Checked } from "./occurrence.mjs";
|
|
3
3
|
import { Duration, Effect, Stream } from "effect";
|
|
4
4
|
/** One poll's answer, as a surface sends it and a client reads it. */
|
|
5
5
|
export interface Page {
|
package/dist/contract/push.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { OccurrenceSchema } from "./occurrence.mjs";
|
|
1
2
|
import { Codec } from "./codec.mjs";
|
|
2
3
|
import "./errors.mjs";
|
|
3
|
-
import { OccurrenceSchema } from "./occurrence.mjs";
|
|
4
|
-
import "./pages.mjs";
|
|
5
4
|
import { Any } from "../Event.mjs";
|
|
5
|
+
import "./pages.mjs";
|
|
6
6
|
import { Cause, Effect, Queue, Schema, Stream } from "effect";
|
|
7
7
|
export declare const PushedOf: <E extends Any>(event: E) => Schema.Union<readonly [OccurrenceSchema<E>, Schema.TaggedStruct<"Gap", {
|
|
8
8
|
readonly cursor: Schema.NullOr<Schema.String>;
|
package/dist/contract/push.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Refusal } from "./errors.mjs";
|
|
2
|
-
import { reported } from "./reported.mjs";
|
|
3
|
-
import { Checked, Gap, OccurrenceOf } from "./occurrence.mjs";
|
|
4
2
|
import { defaultNextPoll } from "./feed.mjs";
|
|
3
|
+
import { Checked, Gap, OccurrenceOf } from "./occurrence.mjs";
|
|
4
|
+
import { reported } from "./reported.mjs";
|
|
5
5
|
import { Cause, Duration, Effect, Latch, Match, Queue, Schema, Stream } from "effect";
|
|
6
6
|
// src/contract/push.ts
|
|
7
7
|
const Failed = Schema.TaggedStruct("Failed", {});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { SigningSecret } from "./callback.mjs";
|
|
1
2
|
import "./errors.mjs";
|
|
2
|
-
import "./pages.mjs";
|
|
3
3
|
import "../Event.mjs";
|
|
4
|
-
import
|
|
4
|
+
import "./pages.mjs";
|
|
5
5
|
import { Context, Effect, Schema, Scope } from "effect";
|
|
6
6
|
/** A POST a receiver verified, its JSON body: an occurrence, or an envelope. */
|
|
7
7
|
export interface Delivered {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { reasonOf, refusalOf } from "./codes.mjs";
|
|
1
2
|
import { Forbidden } from "./errors.mjs";
|
|
2
3
|
import { Gap, untaggedOccurrenceOf } from "./occurrence.mjs";
|
|
3
|
-
import { reasonOf, refusalOf } from "./codes.mjs";
|
|
4
4
|
import { Context, Effect, Option, Schema, Struct } from "effect";
|
|
5
5
|
// src/contract/receiving.ts
|
|
6
6
|
const watchParameter = "watch";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Anyone, assertAuthentication } from "./caller.mjs";
|
|
2
|
-
import { assertDistinct, assertOnce, heldOnce } from "./names.mjs";
|
|
3
|
-
import { Implementation, assertHeld, markingOthers, notHeld, provideBuilders, select, servedBy, toList } from "./implementation.mjs";
|
|
4
2
|
import { eventsOf, feedBuilders, selectEvents } from "./feed.mjs";
|
|
3
|
+
import { Implementation, assertHeld, markingOthers, notHeld, provideBuilders, select, servedBy, toList } from "./implementation.mjs";
|
|
5
4
|
import { selection } from "./listed.mjs";
|
|
5
|
+
import { assertDistinct, assertOnce, heldOnce } from "./names.mjs";
|
|
6
6
|
// src/contract/serving.ts
|
|
7
7
|
const selectFrom = (served, actions) => {
|
|
8
8
|
const listed = selection(actions);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CallbackCategory } from "../Event.mjs";
|
|
2
1
|
import { CallbackUrl, WebhookSecret } from "./callback.mjs";
|
|
2
|
+
import { CallbackCategory } from "../Event.mjs";
|
|
3
3
|
import { SubscriptionOf } from "./push.mjs";
|
|
4
4
|
import { Schema, Struct } from "effect";
|
|
5
5
|
// src/contract/subscribe.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isTransientStatus } from "./status.mjs";
|
|
2
1
|
import { readOn } from "./push.mjs";
|
|
2
|
+
import { isTransientStatus } from "./status.mjs";
|
|
3
3
|
import { Cause, Duration, Effect, Function, Match, Predicate, Stream } from "effect";
|
|
4
4
|
import { HttpClientError } from "effect/http";
|
|
5
5
|
// src/contract/transient.ts
|
package/dist/contract/watch.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { CallbackUrl } from "./callback.mjs";
|
|
2
|
+
import { SubscriptionError, Unsupported } from "../Event.mjs";
|
|
1
3
|
import { Checked, Gap } from "./occurrence.mjs";
|
|
2
4
|
import { paged } from "./pages.mjs";
|
|
3
|
-
import { SubscriptionError, Unsupported } from "../Event.mjs";
|
|
4
5
|
import { watchParameter } from "./receiving.mjs";
|
|
5
6
|
import { makeRecent } from "./recent.mjs";
|
|
6
|
-
import { CallbackUrl } from "./callback.mjs";
|
|
7
7
|
import { Cause, Clock, Duration, Effect, Predicate, Queue, Schedule, Schema, Stream } from "effect";
|
|
8
8
|
// src/contract/watch.ts
|
|
9
9
|
const reconnectDelay = Duration.seconds(1);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Anyone, Named } from "./caller.mjs";
|
|
2
|
-
import { Feed } from "./feed.mjs";
|
|
3
2
|
import { Any } from "../Event.mjs";
|
|
3
|
+
import { Feed } from "./feed.mjs";
|
|
4
4
|
import { AnyWebhookCancellation, AnyWebhookSubscription, Subscribed } from "./subscribe.mjs";
|
|
5
5
|
import { Context, Effect, Option } from "effect";
|
|
6
6
|
/** An event type a surface may offer by webhook: a protected one, its caller an identity. */
|