@gjermundgaraba/effect-actions 0.22.0 → 0.24.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 +9 -3
- package/dist/Action.d.mts +2 -2
- package/dist/Action.mjs +1 -0
- package/dist/ActionCli.d.mts +1 -1
- package/dist/ActionCli.mjs +1 -2
- package/dist/ActionHttp.d.mts +2 -2
- package/dist/ActionMcp.d.mts +20 -20
- package/dist/ActionMcp.mjs +9 -11
- package/dist/ActionRpc.d.mts +8 -15
- package/dist/ActionRpc.mjs +29 -54
- package/dist/ActionToolkit.d.mts +0 -2
- package/dist/ActionToolkit.mjs +0 -2
- package/dist/Event.d.mts +0 -23
- package/dist/Testing.mjs +3 -2
- package/dist/Webhook.mjs +2 -2
- package/dist/authentication/refusal.mjs +0 -1
- package/dist/cli/commands.mjs +0 -5
- package/dist/contract/authorizer.mjs +0 -5
- package/dist/contract/call.mjs +0 -23
- package/dist/contract/callback.mjs +0 -1
- package/dist/contract/caller.mjs +0 -11
- package/dist/contract/canonical.mjs +0 -5
- package/dist/contract/codec.d.mts +0 -1
- package/dist/contract/codec.mjs +0 -1
- package/dist/contract/codes.mjs +1 -15
- package/dist/contract/declared.mjs +0 -15
- package/dist/contract/digest.mjs +0 -1
- package/dist/contract/errors.d.mts +0 -4
- package/dist/contract/errors.mjs +0 -4
- package/dist/contract/feed.d.mts +0 -1
- package/dist/contract/feed.mjs +0 -20
- package/dist/contract/hints.mjs +0 -6
- package/dist/contract/hub.mjs +0 -3
- package/dist/contract/idempotency.mjs +0 -4
- package/dist/contract/implementation.d.mts +0 -1
- package/dist/contract/implementation.mjs +0 -27
- package/dist/contract/input-check.mjs +0 -1
- package/dist/contract/lease.mjs +0 -1
- package/dist/contract/listed.mjs +0 -6
- package/dist/contract/log.mjs +0 -8
- package/dist/contract/names.mjs +0 -1
- package/dist/contract/occurrence.mjs +0 -8
- package/dist/contract/pages.mjs +5 -12
- package/dist/contract/progress.mjs +2 -25
- package/dist/contract/push.d.mts +0 -5
- package/dist/contract/push.mjs +1 -24
- package/dist/contract/receiving.mjs +0 -7
- package/dist/contract/reported.mjs +0 -5
- package/dist/contract/serving.mjs +0 -18
- package/dist/contract/status.mjs +0 -3
- package/dist/contract/stream.mjs +0 -2
- package/dist/contract/subscribe.d.mts +0 -2
- package/dist/contract/subscribe.mjs +0 -8
- package/dist/contract/transient.mjs +0 -12
- package/dist/contract/watch.mjs +5 -17
- package/dist/contract/webhooks.mjs +0 -11
- package/dist/http/client.mjs +0 -1
- package/dist/http/events.d.mts +0 -10
- package/dist/http/events.mjs +2 -31
- package/dist/http/placed.d.mts +0 -2
- package/dist/http/streamed.d.mts +0 -1
- package/dist/http/streamed.mjs +4 -32
- package/dist/http/watch.mjs +0 -6
- package/dist/mcp/bridge.mjs +1 -26
- package/dist/mcp/client.d.mts +0 -1
- package/dist/mcp/client.mjs +0 -1
- package/dist/mcp/events.mjs +0 -6
- package/dist/mcp/progress.mjs +0 -7
- package/dist/mcp/protocol.mjs +0 -6
- package/dist/mcp/reply.mjs +0 -11
- package/dist/mcp/request.mjs +0 -1
- package/dist/mcp/watch.mjs +0 -6
- package/dist/rpc/watch.mjs +0 -6
- package/dist/stdio/console.mjs +2 -2
- package/dist/webhook/address.mjs +4 -9
- package/dist/webhook/attempt.mjs +2 -15
- package/dist/webhook/receiver.mjs +2 -8
- package/dist/webhook/signing.mjs +0 -3
- package/dist/webhook/stored.mjs +8 -17
- package/dist/webhook/subscriptions.mjs +19 -23
- package/docs/Action-streams.md +0 -12
- package/docs/Action.md +0 -10
- package/docs/ActionCli.md +2 -26
- package/docs/ActionHttp-failures.md +1 -1
- package/docs/ActionHttp.md +0 -28
- package/docs/ActionMcp-failures.md +2 -1
- package/docs/ActionMcp.md +2 -37
- package/docs/ActionRpc-events.md +0 -16
- package/docs/ActionRpc.md +0 -63
- package/docs/ActionToolkit.md +0 -11
- package/docs/Authentication-advanced.md +0 -31
- package/docs/Authentication.md +4 -13
- package/docs/Event.md +0 -37
- package/docs/README.md +1 -1
- package/docs/Testing-failures.md +1 -1
- package/docs/Testing.md +3 -13
- package/docs/Webhook.md +0 -46
- package/docs/setup-failures.md +1 -1
- package/docs/setup.md +5 -10
- package/examples/README.md +7 -1
- package/examples/assistant/src/agent.ts +8 -31
- package/examples/assistant/src/cli.ts +2 -9
- package/examples/assistant/src/commands.ts +0 -8
- package/examples/assistant/src/identity/Identity.ts +0 -10
- package/examples/assistant/src/identity/authorize.ts +0 -4
- package/examples/assistant/src/identity/members.ts +1 -3
- package/examples/assistant/src/identity/permissions.ts +0 -5
- package/examples/assistant/src/platform/tasks-file.ts +1 -6
- package/examples/assistant/src/scripted.ts +0 -4
- package/examples/assistant/src/tasks/Tasks.ts +0 -2
- package/examples/assistant/src/tasks/handlers.ts +0 -3
- package/examples/assistant/src/tasks/store.ts +0 -7
- package/examples/assistant/src/toolkit.ts +0 -11
- package/examples/assistant/test/commands.test.ts +0 -5
- package/examples/assistant/test/identity/identity.test.ts +6 -6
- package/examples/assistant/test/platform/tasks-file.test.ts +2 -6
- package/examples/assistant/test/tasks/tasks.test.ts +13 -14
- package/examples/assistant/test/toolkit.test.ts +7 -18
- package/examples/build-events/README.md +2 -0
- package/examples/build-events/src/Api.ts +0 -3
- package/examples/build-events/src/Rpc.ts +0 -2
- package/examples/build-events/src/builds/Builds.ts +0 -15
- package/examples/build-events/src/builds/events.ts +0 -10
- package/examples/build-events/src/builds/handlers.ts +0 -6
- package/examples/build-events/src/builds/log.ts +0 -6
- package/examples/build-events/src/builds/status.ts +0 -4
- package/examples/build-events/src/builds/store.ts +0 -21
- package/examples/build-events/src/cli.ts +0 -2
- package/examples/build-events/src/commands.ts +0 -9
- package/examples/build-events/src/deploys/approvers.ts +0 -3
- package/examples/build-events/src/deploys/events.ts +0 -8
- package/examples/build-events/src/deploys/handlers.ts +0 -2
- package/examples/build-events/src/identity/Identity.ts +0 -11
- package/examples/build-events/src/identity/members.ts +1 -2
- package/examples/build-events/src/identity/verifier.ts +8 -9
- package/examples/build-events/src/notifier/Notices.ts +0 -3
- package/examples/build-events/src/notifier/routes.ts +0 -10
- package/examples/build-events/src/notifier.ts +0 -8
- package/examples/build-events/src/routes.ts +0 -24
- package/examples/build-events/src/server.ts +0 -14
- package/examples/build-events/test/builds/events.test.ts +0 -6
- package/examples/build-events/test/builds/log.test.ts +0 -1
- package/examples/build-events/test/builds/progress.test.ts +0 -1
- package/examples/build-events/test/commands.test.ts +0 -5
- package/examples/build-events/test/deploys/events.test.ts +0 -1
- package/examples/build-events/test/http.test.ts +0 -4
- package/examples/build-events/test/notifier.test.ts +0 -9
- package/examples/build-events/test/routes.test.ts +0 -9
- package/examples/build-events/test/rpc.test.ts +0 -4
- package/examples/build-events/test/support/as.ts +3 -4
- package/examples/build-events/test/support/memory.ts +0 -5
- package/examples/build-events/test/webhooks.test.ts +0 -12
- package/examples/kitchen-sink/README.md +1 -1
- package/examples/kitchen-sink/src/Actions.ts +0 -10
- package/examples/kitchen-sink/src/Api.ts +0 -8
- package/examples/kitchen-sink/src/Rpc.ts +0 -4
- package/examples/kitchen-sink/src/admin/Admin.ts +0 -9
- package/examples/kitchen-sink/src/admin/authenticate.ts +2 -6
- package/examples/kitchen-sink/src/admin/authorize.ts +0 -5
- package/examples/kitchen-sink/src/admin/grants.ts +0 -5
- package/examples/kitchen-sink/src/admin/handlers.ts +0 -2
- package/examples/kitchen-sink/src/admin/keys.ts +1 -3
- package/examples/kitchen-sink/src/agent.ts +2 -13
- package/examples/kitchen-sink/src/assistant/Assistant.ts +7 -24
- package/examples/kitchen-sink/src/assistant/conversations.ts +3 -21
- package/examples/kitchen-sink/src/assistant/demo-model.ts +0 -5
- package/examples/kitchen-sink/src/assistant/handlers.ts +1 -30
- package/examples/kitchen-sink/src/attachments/Attachments.ts +0 -4
- package/examples/kitchen-sink/src/attachments/download.ts +0 -10
- package/examples/kitchen-sink/src/attachments/handlers.ts +0 -3
- package/examples/kitchen-sink/src/attachments/store.ts +0 -3
- package/examples/kitchen-sink/src/browser.ts +0 -9
- package/examples/kitchen-sink/src/cli.ts +0 -19
- package/examples/kitchen-sink/src/config.ts +3 -11
- package/examples/kitchen-sink/src/identity/Identity.ts +0 -18
- package/examples/kitchen-sink/src/identity/authenticate.ts +3 -14
- package/examples/kitchen-sink/src/identity/authorize.ts +0 -6
- package/examples/kitchen-sink/src/identity/directory.ts +8 -18
- package/examples/kitchen-sink/src/identity/handlers.ts +0 -3
- package/examples/kitchen-sink/src/identity/members.ts +1 -5
- package/examples/kitchen-sink/src/identity/quota.ts +0 -11
- package/examples/kitchen-sink/src/issues/Issues.ts +0 -24
- package/examples/kitchen-sink/src/issues/assistant.ts +0 -10
- package/examples/kitchen-sink/src/issues/events.ts +2 -16
- package/examples/kitchen-sink/src/issues/export.ts +0 -5
- package/examples/kitchen-sink/src/issues/guide.ts +0 -5
- package/examples/kitchen-sink/src/issues/handlers.ts +0 -5
- package/examples/kitchen-sink/src/issues/store.ts +19 -23
- package/examples/kitchen-sink/src/issues/write-limit.ts +0 -12
- package/examples/kitchen-sink/src/memory.ts +0 -9
- package/examples/kitchen-sink/src/ops.ts +0 -6
- package/examples/kitchen-sink/src/request-policy.ts +0 -17
- package/examples/kitchen-sink/src/routes.ts +0 -48
- package/examples/kitchen-sink/src/sdk.ts +0 -12
- package/examples/kitchen-sink/src/seed.ts +0 -10
- package/examples/kitchen-sink/src/server.ts +0 -22
- package/examples/kitchen-sink/src/stdio.ts +2 -12
- package/examples/kitchen-sink/src/workspaces/Workspaces.ts +0 -4
- package/examples/kitchen-sink/src/workspaces/handlers.ts +0 -4
- package/examples/kitchen-sink/src/workspaces/registry.ts +0 -5
- package/examples/kitchen-sink/src/workspaces/tenant.ts +0 -4
- package/examples/kitchen-sink/test/admin/admin.test.ts +0 -1
- package/examples/kitchen-sink/test/assistant/assistant.test.ts +0 -18
- package/examples/kitchen-sink/test/attachments/attachments.test.ts +0 -9
- package/examples/kitchen-sink/test/identity/identity.test.ts +0 -10
- package/examples/kitchen-sink/test/identity/session.test.ts +0 -10
- package/examples/kitchen-sink/test/issues/assistant.test.ts +3 -7
- package/examples/kitchen-sink/test/issues/events.test.ts +2 -9
- package/examples/kitchen-sink/test/issues/export.test.ts +0 -3
- package/examples/kitchen-sink/test/issues/issues.test.ts +6 -12
- package/examples/kitchen-sink/test/request-policy.test.ts +0 -6
- package/examples/kitchen-sink/test/routes.test.ts +0 -6
- package/examples/kitchen-sink/test/support/as.ts +3 -5
- package/examples/kitchen-sink/test/support/scripted.ts +0 -3
- package/examples/kitchen-sink/test/support/services.ts +0 -3
- package/examples/live-rpc/src/Rpc.ts +0 -4
- package/examples/live-rpc/src/browser.ts +0 -24
- package/examples/live-rpc/src/chat/Chat.ts +0 -22
- package/examples/live-rpc/src/chat/authorize.ts +0 -3
- package/examples/live-rpc/src/chat/events.ts +0 -14
- package/examples/live-rpc/src/chat/handlers.ts +0 -5
- package/examples/live-rpc/src/chat/room.ts +0 -6
- package/examples/live-rpc/src/chat/store.ts +0 -9
- package/examples/live-rpc/src/client.ts +0 -6
- package/examples/live-rpc/src/identity/Identity.ts +0 -6
- package/examples/live-rpc/src/identity/members.ts +1 -3
- package/examples/live-rpc/src/identity/verifier.ts +6 -12
- package/examples/live-rpc/src/page.ts +0 -10
- package/examples/live-rpc/src/routes.ts +0 -13
- package/examples/live-rpc/src/server.ts +0 -16
- package/examples/live-rpc/test/browser.test.ts +0 -9
- package/examples/live-rpc/test/chat/chat.test.ts +3 -11
- package/examples/live-rpc/test/routes.test.ts +0 -8
- package/examples/live-rpc/test/server.test.ts +0 -13
- package/examples/mcp-tools/src/instructions.ts +0 -4
- package/examples/mcp-tools/src/platform/fake-farm.ts +0 -6
- package/examples/mcp-tools/src/platform/print-farm.ts +0 -16
- package/examples/mcp-tools/src/printers/Printers.ts +0 -21
- package/examples/mcp-tools/src/printers/farm.ts +0 -5
- package/examples/mcp-tools/src/printers/handlers.ts +0 -6
- package/examples/mcp-tools/src/routes.ts +0 -11
- package/examples/mcp-tools/src/server.ts +0 -9
- package/examples/mcp-tools/src/stdio.ts +1 -13
- package/examples/mcp-tools/test/printers/printers.test.ts +0 -10
- package/examples/mcp-tools/test/routes.test.ts +0 -14
- package/examples/notes-service/src/Api.ts +0 -4
- package/examples/notes-service/src/browser.ts +0 -12
- package/examples/notes-service/src/cli.ts +0 -2
- package/examples/notes-service/src/commands.ts +0 -30
- package/examples/notes-service/src/identity/Identity.ts +0 -2
- package/examples/notes-service/src/identity/authorize.ts +0 -4
- package/examples/notes-service/src/identity/users.ts +1 -3
- package/examples/notes-service/src/identity/verifier.ts +4 -11
- package/examples/notes-service/src/notes/Notes.ts +0 -12
- package/examples/notes-service/src/notes/handlers.ts +0 -4
- package/examples/notes-service/src/notes/store.ts +62 -48
- package/examples/notes-service/src/routes.ts +0 -12
- package/examples/notes-service/src/server.ts +0 -6
- package/examples/notes-service/src/status/Status.ts +0 -1
- package/examples/notes-service/src/status/handlers.ts +0 -1
- package/examples/notes-service/src/stdio.ts +2 -12
- package/examples/notes-service/src/worker.ts +0 -7
- package/examples/notes-service/test/commands.test.ts +0 -20
- package/examples/notes-service/test/notes/as.ts +3 -4
- package/examples/notes-service/test/notes/in-process.test.ts +3 -6
- package/examples/notes-service/test/notes/notes.test.ts +0 -6
- package/examples/notes-service/test/routes.test.ts +0 -5
- package/examples/notes-service/test/worker.test.ts +0 -1
- package/examples/quickstart/src/Api.ts +0 -1
- package/examples/quickstart/src/client.ts +0 -3
- package/examples/quickstart/src/greeting/Greeting.ts +0 -2
- package/examples/quickstart/src/greeting/handlers.ts +0 -1
- package/examples/quickstart/src/routes.ts +0 -1
- package/examples/quickstart/src/server.ts +3 -6
- package/examples/quickstart/test/routes.test.ts +0 -1
- package/package.json +6 -6
package/dist/cli/commands.mjs
CHANGED
|
@@ -353,11 +353,6 @@ const command = (action, execute, options, errors) => {
|
|
|
353
353
|
}, ({ input, args: values, json }) => run(parsedFields(input, values), json ? void 0 : render));
|
|
354
354
|
return stdinHelp === void 0 ? Command.withDescription(projected, description) : projected.pipe(Command.withDescription(`${description}\n\n${stdinHelp}`), Command.withShortDescription(description));
|
|
355
355
|
};
|
|
356
|
-
/**
|
|
357
|
-
* The command watching `event`, named after it, with one flag per field of its input as an
|
|
358
|
-
* action's command has, and `--cursor` to resume from: it prints each occurrence and gap `watch`
|
|
359
|
-
* yields as one line of compact JSON on stdout, until it is interrupted or the watch fails.
|
|
360
|
-
*/
|
|
361
356
|
const watchCommand = (event, watch, errors) => {
|
|
362
357
|
const { flags, decode } = inputConfig(event, [], {}, void 0);
|
|
363
358
|
const encode = Schema.encodeEffect(Schema.fromJsonString(Schema.toCodecJson(ReceivedOf(event))));
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { memoized } from "./implementation.mjs";
|
|
2
2
|
import { Effect, Predicate } from "effect";
|
|
3
3
|
// src/contract/authorizer.ts
|
|
4
|
-
/**
|
|
5
|
-
* The memoized authorizer of an implementation: the `authorize` given where it holds a protected
|
|
6
|
-
* contract, which then requires one, and a rule allowing every call where it holds none, which
|
|
7
|
-
* then takes none.
|
|
8
|
-
*/
|
|
9
4
|
const authorizerOf = (holding, holdsProtected, authorize) => {
|
|
10
5
|
const { singular, module } = holding;
|
|
11
6
|
if (holdsProtected && authorize === void 0) throw new Error(`Protected ${singular}s require authorize, or ${module}.allowAll`);
|
package/dist/contract/call.mjs
CHANGED
|
@@ -2,30 +2,19 @@ import { InvalidInput } from "./errors.mjs";
|
|
|
2
2
|
import { Effect, Predicate, Schema, Stream } from "effect";
|
|
3
3
|
// src/contract/call.ts
|
|
4
4
|
const isCallOptions = (options) => Predicate.hasProperty(options, "onProgress") && Predicate.isFunction(options.onProgress);
|
|
5
|
-
/** The `onProgress` a call's arguments give after its input, where they give one. */
|
|
6
5
|
const onProgressOf = (args) => {
|
|
7
6
|
const [, options] = args;
|
|
8
7
|
return isCallOptions(options) ? options.onProgress : void 0;
|
|
9
8
|
};
|
|
10
|
-
/**
|
|
11
|
-
* How HTTP, RPC, MCP and a command decode a request's input: reporting every issue, and refusing a
|
|
12
|
-
* field the input does not declare.
|
|
13
|
-
*/
|
|
14
9
|
const inputParseOptions = {
|
|
15
10
|
errors: "all",
|
|
16
11
|
onExcessProperty: "error"
|
|
17
12
|
};
|
|
18
|
-
/** Decode `action`'s input from its JSON form by `inputParseOptions`, or fail with `InvalidInput`. */
|
|
19
13
|
const decodeInput = (action) => {
|
|
20
14
|
const decode = Schema.decodeUnknownEffect(Schema.toCodecJson(action.input), inputParseOptions);
|
|
21
15
|
return (encoded) => Effect.mapError(decode(encoded), InvalidInput.fromSchemaError);
|
|
22
16
|
};
|
|
23
17
|
const inputOf = (action, args) => args.length === 0 ? Schema.decodeEffect(Schema.toCodecJson(action.input))({}) : Effect.succeed(args[0]);
|
|
24
|
-
/**
|
|
25
|
-
* Values of `schema` as they cross a network: each encoded to its JSON, then decoded back from
|
|
26
|
-
* that JSON's text, which carries `-0` as `0`, every issue reported, answering the JSON sent and
|
|
27
|
-
* the value received.
|
|
28
|
-
*/
|
|
29
18
|
const jsonRoundTrip = (schema) => {
|
|
30
19
|
const codec = Schema.toCodecJson(schema);
|
|
31
20
|
const encode = Schema.encodeUnknownEffect(codec, { errors: "all" });
|
|
@@ -35,28 +24,16 @@ const jsonRoundTrip = (schema) => {
|
|
|
35
24
|
value: received
|
|
36
25
|
})));
|
|
37
26
|
};
|
|
38
|
-
/**
|
|
39
|
-
* A watch's input as every client sends it: read as `inputOf` reads an action's, then through
|
|
40
|
-
* its JSON, dropping undeclared fields, or `InvalidInput` reporting every issue.
|
|
41
|
-
*/
|
|
42
27
|
const watchInput = (event, input) => inputOf(event, input === void 0 ? [] : [input]).pipe(Effect.flatMap(jsonRoundTrip(event.input)), Effect.mapError(InvalidInput.fromSchemaError));
|
|
43
|
-
/** Send the input's JSON, for a client handing it to its protocol as it is. */
|
|
44
28
|
const sendingJson = (action) => Schema.encodeUnknownEffect(Schema.toCodecJson(action.input), { errors: "all" });
|
|
45
|
-
/** Send the input itself once its JSON encodes, for a client encoding it by the action's schema. */
|
|
46
29
|
const sendingValue = (action) => {
|
|
47
30
|
const encode = sendingJson(action);
|
|
48
31
|
return (input) => Effect.as(encode(input), input);
|
|
49
32
|
};
|
|
50
|
-
/**
|
|
51
|
-
* A client's method of `action`, its input checked by `check` before `send` sends what the check
|
|
52
|
-
* answers, with the call's `onProgress` where it gave one, taking decoded values, for `send` to
|
|
53
|
-
* use where the action declares `progress`.
|
|
54
|
-
*/
|
|
55
33
|
const checked = (action, check, send) => {
|
|
56
34
|
const encode = check(action);
|
|
57
35
|
return (...args) => inputOf(action, args).pipe(Effect.flatMap(encode), Effect.mapError(InvalidInput.fromSchemaError), Effect.flatMap((input) => send(input, onProgressOf(args))));
|
|
58
36
|
};
|
|
59
|
-
/** A client's method of `action` answering a stream, its input checked as `checked` checks it. */
|
|
60
37
|
const checkedStream = (action, check, send) => {
|
|
61
38
|
const method = checked(action, check, (input, onProgress) => Effect.succeed(send(input, onProgress)));
|
|
62
39
|
return (...args) => Stream.unwrap(method(...args));
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Effect, Option, Schema, SchemaIssue, SchemaTransformation } from "effect";
|
|
2
2
|
// src/contract/callback.ts
|
|
3
|
-
/** A webhook's callback: an https URL, which each delivery is POSTed to, decoded as a `URL`. */
|
|
4
3
|
const CallbackUrl = Schema.String.annotate({ description: "The https URL each delivery is POSTed to." }).pipe(Schema.decodeTo(Schema.URL, SchemaTransformation.urlFromString), Schema.check(Schema.makeFilter((url) => url.protocol === "https:" || "an https URL")));
|
|
5
4
|
/** A Standard Webhooks signing secret: as written, `whsec_` and base64, and the key it holds. */
|
|
6
5
|
const SigningSecret = Schema.Struct({
|
package/dist/contract/caller.mjs
CHANGED
|
@@ -6,23 +6,12 @@ import { Context, Effect, Function } from "effect";
|
|
|
6
6
|
* agree on a name.
|
|
7
7
|
*/
|
|
8
8
|
const Anyone = Symbol.for("@gjermundgaraba/effect-actions/Anyone");
|
|
9
|
-
/**
|
|
10
|
-
* The authentication of the surface the running call came through, which names its caller where
|
|
11
|
-
* it has a `principal`: none in process, as `Action.client` calls.
|
|
12
|
-
*/
|
|
13
9
|
const CallerKeyed = Context.Reference("effect-actions/CallerKeyed", { defaultValue: Function.constUndefined });
|
|
14
|
-
/** Whether `keyed` names each caller, its `principal` given. */
|
|
15
10
|
const isNamed = (keyed) => keyed?.principal !== void 0;
|
|
16
|
-
/**
|
|
17
|
-
* The principal of the caller of `called`, as `keyed` names it: a poll's subscriber, for its
|
|
18
|
-
* `subscription` hook, and whose idempotency keys a call's are. None where `called` is public or
|
|
19
|
-
* `keyed` has no `principal`: every caller is then one.
|
|
20
|
-
*/
|
|
21
11
|
const principalOf = (called, keyed) => keyed?.principal === void 0 || called.caller === Anyone ? Effect.undefined : Effect.map(Effect.service(called.caller), (identity) => keyed.principal?.(identity));
|
|
22
12
|
const assertAuthentication = (contracts, authentication, noun = "action") => {
|
|
23
13
|
for (const contract of contracts) if (contract.caller !== Anyone && (authentication === void 0 || contract.caller.key !== authentication.identity.key)) throw new Error(`Protected ${noun} '${contract.name}' requires its matching authentication descriptor (give it the authentication whose identity the ${noun}'s caller names)`);
|
|
24
14
|
};
|
|
25
|
-
/** Refuses a declared `caller` that is neither `Anyone` nor an identity service. */
|
|
26
15
|
const assertCaller = (caller) => {
|
|
27
16
|
if (caller !== Anyone && !Context.isKey(caller)) throw new Error("Missing caller: declare Action.Anyone or an identity service key");
|
|
28
17
|
if (caller !== Anyone && Context.isReference(caller)) throw new Error("Invalid caller: an identity is a Context.Service, not a Context.Reference");
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { Effect, Predicate, Schema } from "effect";
|
|
2
2
|
// src/contract/canonical.ts
|
|
3
|
-
/**
|
|
4
|
-
* `value`, an encoded input, as JSON written one way whatever the order of its objects' keys:
|
|
5
|
-
* what makes two inputs one, for a subscription's key and an idempotency key's input alike.
|
|
6
|
-
*/
|
|
7
3
|
const canonical = (value) => JSON.stringify(value, (_key, nested) => Predicate.isObject(nested) && !Array.isArray(nested) ? Object.fromEntries(Object.entries(nested).toSorted(([a], [b]) => a < b ? -1 : 1)) : nested);
|
|
8
|
-
/** `input`, encoded to JSON by `schema`, as `canonical` writes it. */
|
|
9
4
|
const canonicalInput = (schema, input) => Effect.map(Effect.orDie(Schema.encodeUnknownEffect(Schema.toCodecJson(schema))(input)), canonical);
|
|
10
5
|
export { canonical, canonicalInput };
|
|
@@ -3,7 +3,6 @@ import { Schema } from "effect";
|
|
|
3
3
|
export type Codec = Schema.Codec<unknown>;
|
|
4
4
|
/** Struct fields, given in place of a schema. */
|
|
5
5
|
export type Fields = Readonly<Record<string, Codec>>;
|
|
6
|
-
/** The input of a contract declared without one: an empty object. */
|
|
7
6
|
export declare const NoInput: Schema.$Record<Schema.String, Schema.Never>;
|
|
8
7
|
/** The schema a contract holds for `S`, given as a schema or as struct fields. */
|
|
9
8
|
export type CodecOf<S extends Codec | Fields> = S extends Codec ? S : S extends Schema.Struct.Fields ? keyof S extends never ? typeof NoInput : Extract<Schema.Struct<S>, Codec> : never;
|
package/dist/contract/codec.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
// src/contract/codec.ts
|
|
3
|
-
/** The input of a contract declared without one: an empty object. */
|
|
4
3
|
const NoInput = Schema.Record(Schema.String, Schema.Never);
|
|
5
4
|
const codecOf = (schema) => {
|
|
6
5
|
if (Schema.isSchema(schema)) return schema;
|
package/dist/contract/codes.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { Forbidden, Refusal } from "./errors.mjs";
|
|
|
2
2
|
import { CallbackCategory, CallbackFailed, NotServed, NotSubscribed, SubscriptionError, Unsupported } from "../Event.mjs";
|
|
3
3
|
import { Option, Schema, SchemaTransformation, Struct } from "effect";
|
|
4
4
|
// src/contract/codes.ts
|
|
5
|
-
/** The error codes SEP-3415 defines, each naming one reason. */
|
|
6
5
|
const eventCodes = {
|
|
7
6
|
notFound: -32023,
|
|
8
7
|
forbidden: -32024,
|
|
@@ -19,7 +18,7 @@ const sent = {
|
|
|
19
18
|
},
|
|
20
19
|
NotServed: {
|
|
21
20
|
code: eventCodes.notFound,
|
|
22
|
-
data: Schema.
|
|
21
|
+
data: Schema.Struct({ kind: Schema.Literal("event") }).pipe(Schema.decodeTo(Schema.instanceOf(NotServed), SchemaTransformation.transform({
|
|
23
22
|
decode: () => new NotServed(),
|
|
24
23
|
encode: () => ({ kind: "event" })
|
|
25
24
|
})))
|
|
@@ -44,10 +43,6 @@ const sent = {
|
|
|
44
43
|
};
|
|
45
44
|
const encodeRefusal = Schema.encodeUnknownSync(Schema.toCodecJson(Refusal));
|
|
46
45
|
const decodeRefusal = Schema.decodeUnknownOption(Schema.toCodecJson(Refusal));
|
|
47
|
-
/**
|
|
48
|
-
* The SEP-3415 error `error` is sent as: a refusal's `-32024`, its message and the refusal as
|
|
49
|
-
* its data, or its reason's code and data beside its message.
|
|
50
|
-
*/
|
|
51
46
|
const sentError = (error) => {
|
|
52
47
|
if (Schema.is(Refusal)(error)) return {
|
|
53
48
|
code: eventCodes.forbidden,
|
|
@@ -61,16 +56,7 @@ const sentError = (error) => {
|
|
|
61
56
|
data: Schema.encodeUnknownSync(Schema.toCodecJson(data))(error.reason)
|
|
62
57
|
};
|
|
63
58
|
};
|
|
64
|
-
/**
|
|
65
|
-
* The refusal a SEP-3415 error carries, as `sentError` writes one: its `data` decoded, or
|
|
66
|
-
* `Forbidden` with its message where `data` is no refusal.
|
|
67
|
-
*/
|
|
68
59
|
const refusalOf = (error) => Option.getOrElse(decodeRefusal(error.data), () => new Forbidden({ message: error.message }));
|
|
69
|
-
/**
|
|
70
|
-
* What a SEP-3415 error of the event `name` names, as a subscription's request fails with one and
|
|
71
|
-
* its termination carries one: a reason of `Event.SubscriptionError`, or the refusal; `undefined`
|
|
72
|
-
* for a code SEP-3415 does not define, or one whose `data` does not say what it names.
|
|
73
|
-
*/
|
|
74
60
|
const reasonOf = (name, error) => {
|
|
75
61
|
if (error.code === eventCodes.forbidden) return refusalOf(error);
|
|
76
62
|
for (const { code, data } of Object.values(sent)) {
|
|
@@ -14,7 +14,6 @@ const schemasOf = (ast) => {
|
|
|
14
14
|
if (SchemaAST.isSuspend(ast)) return schemasOf(ast.thunk());
|
|
15
15
|
return SchemaAST.isUnion(ast) ? ast.types.flatMap(schemasOf) : [ast];
|
|
16
16
|
};
|
|
17
|
-
/** `errors` as the schemas a call decodes a failure with, in order, each once. */
|
|
18
17
|
const errorSchemas = (errors) => {
|
|
19
18
|
const schemas = /* @__PURE__ */ new Map();
|
|
20
19
|
for (const error of errors) for (const ast of schemasOf(error.ast)) if (!schemas.has(ast)) schemas.set(ast, ast === error.ast ? error : Schema.make(ast));
|
|
@@ -25,15 +24,7 @@ const projectedErrors = (action, surface = []) => errorSchemas([
|
|
|
25
24
|
...action.error,
|
|
26
25
|
...surface
|
|
27
26
|
]);
|
|
28
|
-
/**
|
|
29
|
-
* Every error a binding's call of `action` declares: the built-in ones, the action's, the
|
|
30
|
-
* binding's and, where `action` is protected, its authentication's.
|
|
31
|
-
*/
|
|
32
27
|
const bindingErrors = (action, binding) => projectedErrors(action, action.caller === Anyone || binding.authentication === void 0 ? binding.error : [...binding.error, ...binding.authentication.error]);
|
|
33
|
-
/**
|
|
34
|
-
* Every error a binding's subscription to `event` declares: the built-in ones, the binding's and,
|
|
35
|
-
* where `event` is protected, its authentication's. An event type declares none of its own.
|
|
36
|
-
*/
|
|
37
28
|
const eventErrors = (event, binding) => bindingErrors({
|
|
38
29
|
error: [],
|
|
39
30
|
caller: event.caller
|
|
@@ -43,7 +34,6 @@ const encodedTags = (ast) => members(SchemaAST.toEncoded(ast)).flatMap((member)
|
|
|
43
34
|
return tag === void 0 ? [] : members(tag).flatMap(literalValues).filter(Predicate.isString);
|
|
44
35
|
});
|
|
45
36
|
const builtInTags = new Set(builtIns.flatMap((schema) => encodedTags(schema.ast)));
|
|
46
|
-
/** Throws where two of the schemas in `errors` encode with one `_tag`. */
|
|
47
37
|
const assertDistinctTags = (what, errors) => {
|
|
48
38
|
const seen = /* @__PURE__ */ new Set();
|
|
49
39
|
for (const schema of errorSchemas(errors)) for (const tag of new Set(encodedTags(schema.ast))) {
|
|
@@ -51,11 +41,6 @@ const assertDistinctTags = (what, errors) => {
|
|
|
51
41
|
seen.add(tag);
|
|
52
42
|
}
|
|
53
43
|
};
|
|
54
|
-
/**
|
|
55
|
-
* The checks `ActionHttp.make` and `ActionRpc.make` share: the descriptor every protected action
|
|
56
|
-
* and event type names, and each call's and each subscription's errors distinct by `_tag`.
|
|
57
|
-
* Returns the binding's `error`, as a list, and `authentication`.
|
|
58
|
-
*/
|
|
59
44
|
const bindingOf = (what, actions, events, options) => {
|
|
60
45
|
const bound = {
|
|
61
46
|
error: errorList(options.error),
|
package/dist/contract/digest.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
// src/contract/digest.ts
|
|
3
3
|
const encoder = new TextEncoder();
|
|
4
|
-
/** The SHA-256 of `text`, in hex. */
|
|
5
4
|
const sha256Hex = (text) => Effect.promise(async () => Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", encoder.encode(text))), (byte) => byte.toString(16).padStart(2, "0")).join(""));
|
|
6
5
|
export { sha256Hex };
|
|
@@ -94,10 +94,6 @@ export declare class Forbidden extends Forbidden_base {
|
|
|
94
94
|
export declare const Refusal: Schema.Union<readonly [typeof Unauthenticated, typeof Forbidden]>;
|
|
95
95
|
/** A refusal: `Unauthenticated | Forbidden`. */
|
|
96
96
|
export type Refusal = (typeof Refusal)["Type"];
|
|
97
|
-
/**
|
|
98
|
-
* The failures every endpoint and tool declares beyond its action's own, and any handler may
|
|
99
|
-
* fail with: bad input, and every refusal. An action or a binding need not declare them; one listed is accepted.
|
|
100
|
-
*/
|
|
101
97
|
export declare const builtIns: readonly [typeof InvalidInput, typeof Unauthenticated, typeof Forbidden];
|
|
102
98
|
/** The built-in failures' schemas. */
|
|
103
99
|
export type BuiltIns = (typeof builtIns)[number];
|
package/dist/contract/errors.mjs
CHANGED
|
@@ -82,10 +82,6 @@ const refusals = [Unauthenticated, Forbidden];
|
|
|
82
82
|
* running a handler. As a schema, it tells a refusal apart: `Schema.is(Action.Refusal)(error)`.
|
|
83
83
|
*/
|
|
84
84
|
const Refusal = Schema.Union(refusals);
|
|
85
|
-
/**
|
|
86
|
-
* The failures every endpoint and tool declares beyond its action's own, and any handler may
|
|
87
|
-
* fail with: bad input, and every refusal. An action or a binding need not declare them; one listed is accepted.
|
|
88
|
-
*/
|
|
89
85
|
const builtIns = [InvalidInput, ...refusals];
|
|
90
86
|
/** The built-in failures as one schema: `Schema.is(Action.BuiltIn)(error)`. */
|
|
91
87
|
const BuiltIn = Schema.Union(builtIns);
|
package/dist/contract/feed.d.mts
CHANGED
|
@@ -74,7 +74,6 @@ export declare class EventImplementation<E extends Any, R, EX, RX, RA = never, E
|
|
|
74
74
|
static layerOf(app: AnyEventImplementation): Layer.Layer<never, unknown, unknown>;
|
|
75
75
|
/** The event types of `app` with what runs them, behind its authorizer. */
|
|
76
76
|
static feedsOf(app: AnyEventImplementation): Effect.Effect<readonly Feed[], never, unknown>;
|
|
77
|
-
/** What runs each event type `app` holds. */
|
|
78
77
|
private static held;
|
|
79
78
|
private static own;
|
|
80
79
|
}
|
package/dist/contract/feed.mjs
CHANGED
|
@@ -30,7 +30,6 @@ const occurrencesOf = (event) => {
|
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
32
|
const isOccurrence = (fed) => Predicate.isTagged(fed, "Occurrence");
|
|
33
|
-
/** A poll's page of `items`: their occurrences, `truncated` too where a gap stands for one. */
|
|
34
33
|
const pageOf = (items, { truncated, ...page }) => {
|
|
35
34
|
const events = items.filter(isOccurrence);
|
|
36
35
|
return {
|
|
@@ -40,7 +39,6 @@ const pageOf = (items, { truncated, ...page }) => {
|
|
|
40
39
|
};
|
|
41
40
|
};
|
|
42
41
|
const lifted = (value) => Effect.isEffect(value) ? value : Effect.succeed(value);
|
|
43
|
-
/** The key a subscriber of `input` is reached by, as the source's `key` answers it. */
|
|
44
42
|
const keyOf = (source, input) => source.key === void 0 ? Effect.undefined : lifted(source.key(input));
|
|
45
43
|
const leaseKey = (event, subscriber, input) => Effect.map(canonicalInput(event.input, input), (encoded) => `${subscriber ?? ""}\u0000${encoded}`);
|
|
46
44
|
const answeredPage = ({ answered, items }) => pageOf(items, {
|
|
@@ -118,7 +116,6 @@ const logRun = (event, source, log) => {
|
|
|
118
116
|
}))), Stream.flattenIterable)))
|
|
119
117
|
};
|
|
120
118
|
};
|
|
121
|
-
/** `run` with the source's `subscription` held while each subscription lasts. */
|
|
122
119
|
const hooked = (event, run, subscription, leases) => ({
|
|
123
120
|
...run,
|
|
124
121
|
poll: (input, cursor, options) => Effect.flatMap(leaseKey(event, options.subscriber, input), (key) => Effect.andThen(leases.hold(key, input), () => run.poll(input, cursor, options))),
|
|
@@ -149,10 +146,6 @@ const assertSource = (event, source) => {
|
|
|
149
146
|
if (!isSource(source)) throw new Error(`Event "${event.name}": its source needs exactly one of check, current or log (give check or current a function, or log its options, {} or { emit: stream })`);
|
|
150
147
|
return source;
|
|
151
148
|
};
|
|
152
|
-
/**
|
|
153
|
-
* The runtime of `events`' sources: one per event, from the source given for one event alone, or
|
|
154
|
-
* from a record keyed by event name, the builder run once for all of them.
|
|
155
|
-
*/
|
|
156
149
|
const sourcesOf = (events, single, sources) => {
|
|
157
150
|
const names = events.map((event) => event.name);
|
|
158
151
|
const checked = (built) => {
|
|
@@ -220,7 +213,6 @@ var EventImplementation = class EventImplementation {
|
|
|
220
213
|
return yield* Effect.forEach(EventImplementation.held(app), ([event, run]) => Effect.map(Effect.service(run.key), (ran) => guarded(event, ran, before)));
|
|
221
214
|
});
|
|
222
215
|
}
|
|
223
|
-
/** What runs each event type `app` holds. */
|
|
224
216
|
static held(app) {
|
|
225
217
|
return EventImplementation.own(app).#running.filter(([event]) => app.events.includes(event));
|
|
226
218
|
}
|
|
@@ -229,21 +221,9 @@ var EventImplementation = class EventImplementation {
|
|
|
229
221
|
return app;
|
|
230
222
|
}
|
|
231
223
|
};
|
|
232
|
-
/**
|
|
233
|
-
* Why `surface` cannot serve `feeds` unless its authentication is `keyed` by a principal: a
|
|
234
|
-
* protected event type whose `subscription` hook is held per subscriber between polls, which a
|
|
235
|
-
* principal names.
|
|
236
|
-
*/
|
|
237
224
|
const unkeyedHook = (surface, feeds, keyed) => keyed ? void 0 : Array.findFirst(feeds, ({ event, release }) => release !== void 0 && event.caller !== Anyone).pipe(Option.map(({ event }) => `${surface} event "${event.name}" is protected and has a subscription hook, so its authentication needs principal to tell poll subscribers apart (give Authentication.make a principal, such as (user) => user.id)`), Option.getOrUndefined);
|
|
238
|
-
/** The event implementations among what a surface is given. */
|
|
239
225
|
const eventsOf = (served) => Array.ensure(served).filter((app) => Predicate.isTagged(app, "EventImplementation"));
|
|
240
|
-
/**
|
|
241
|
-
* The event implementations among `apps` holding an event type of `listed`, each holding those
|
|
242
|
-
* alone, refusing one listed that none holds; every one where `listed` is absent.
|
|
243
|
-
*/
|
|
244
226
|
const selectEvents = (apps, listed) => selectHeld(apps, listed, (app) => app.events, (own, app) => EventImplementation.share(own, app));
|
|
245
|
-
/** The builder layers of event implementations, as a surface provides them. */
|
|
246
227
|
const feedBuilders = (events) => events.map((app) => EventImplementation.layerOf(app));
|
|
247
|
-
/** Every feed of event implementations, from the context their builders provide. */
|
|
248
228
|
const acquireFeeds = (events) => Effect.map(Effect.forEach(events, (app) => EventImplementation.feedsOf(app)), (feeds) => feeds.flat());
|
|
249
229
|
export { EventImplementation, acquireFeeds, defaultNextPoll, eventsOf, feedBuilders, selectEvents, sourcesOf, unkeyedHook };
|
package/dist/contract/hints.mjs
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
// src/contract/hints.ts
|
|
2
|
-
/**
|
|
3
|
-
* An action's MCP tool hints, MCP's defaults where its `mcp` leaves one out, except that a read
|
|
4
|
-
* is not destructive where MCP's default would say it is: no tool idempotent and every tool
|
|
5
|
-
* open-world. A given value passes through, as MCP
|
|
6
|
-
* calls `destructiveHint` and `idempotentHint` meaningless on a read-only tool.
|
|
7
|
-
*/
|
|
8
2
|
const hintsOf = ({ readOnly, mcp }) => ({
|
|
9
3
|
readOnlyHint: readOnly,
|
|
10
4
|
destructiveHint: mcp.destructiveHint ?? !readOnly,
|
package/dist/contract/hub.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { makeLog, makeLogStore, memoryStorage } from "./log.mjs";
|
|
2
2
|
import { Context, Effect, Layer, Queue, Stream } from "effect";
|
|
3
3
|
// src/contract/hub.ts
|
|
4
|
-
/** Revisions kept in memory, starting again, in a new epoch, with each call. */
|
|
5
4
|
const memoryRevisions = () => {
|
|
6
5
|
const counts = /* @__PURE__ */ new Map();
|
|
7
6
|
return {
|
|
@@ -31,12 +30,10 @@ const ofKey = (event, key) => `${event.name}\u0000=${key}`;
|
|
|
31
30
|
*/
|
|
32
31
|
var Events = class extends Context.Service()("effect-actions/Event/Events") {};
|
|
33
32
|
const attached = /* @__PURE__ */ new WeakMap();
|
|
34
|
-
/** How sources attach to `events`, the `Events` `makeEvents` made; one made otherwise dies. */
|
|
35
33
|
const attachmentsOf = (events) => Effect.suspend(() => {
|
|
36
34
|
const attachments = attached.get(events);
|
|
37
35
|
return attachments === void 0 ? Effect.die(/* @__PURE__ */ new Error("This Event.Events serves no event implementation: provide Event.layerMemory, or one Event.makeEvents builds")) : Effect.succeed(attachments);
|
|
38
36
|
});
|
|
39
|
-
/** Whether an announcement to `target` reaches a subscriber of `key`: either absent means every one. */
|
|
40
37
|
const reaches = (target, key) => target === void 0 || key === void 0 || target === key;
|
|
41
38
|
const holding = (set, value) => Effect.acquireRelease(Effect.sync(() => {
|
|
42
39
|
set.add(value);
|
|
@@ -53,10 +53,6 @@ const layerIdempotency = Layer.sync(Idempotency)(() => {
|
|
|
53
53
|
})
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
|
-
/**
|
|
57
|
-
* `handle`, answering a call given `action`'s idempotency key as the first call with it and the
|
|
58
|
-
* same input was answered: from `store`, or, while that call runs, once it has.
|
|
59
|
-
*/
|
|
60
56
|
const keyed = (action, store, handle) => {
|
|
61
57
|
const field = action.idempotencyKey;
|
|
62
58
|
if (field === void 0) return handle;
|
|
@@ -89,7 +89,6 @@ export declare class Implementation<A extends Any$1, RequestServices extends {
|
|
|
89
89
|
* `layerOf(app)` provides.
|
|
90
90
|
*/
|
|
91
91
|
static boundOf(app: AnyImplementation, keyed: Keyed | undefined): Effect.Effect<Bound, never, unknown>;
|
|
92
|
-
/** `app`, if this copy of the module made it; another installed copy's cannot be read. */
|
|
93
92
|
private static own;
|
|
94
93
|
}
|
|
95
94
|
/**
|
|
@@ -9,14 +9,8 @@ import { Array, Cause, Context, Effect, Exit, Layer, Option, Predicate, Referenc
|
|
|
9
9
|
// src/contract/implementation.ts
|
|
10
10
|
const uniqueKey = () => Math.random().toString(36).slice(2);
|
|
11
11
|
const notAStream = /* @__PURE__ */ new Error("A handler answered otherwise than its action's success declares");
|
|
12
|
-
/** The stream of a call of an action answering one, from its `ErasedHandler`'s answer. */
|
|
13
12
|
const elementsOf = (answer) => Stream.unwrap(Effect.filterOrElse(answer, Stream.isStream, () => Effect.die(notAStream)));
|
|
14
|
-
/** The answer of a handler of an action answering one value, a stream refused as a defect. */
|
|
15
13
|
const answered = (answer) => Stream.isStream(answer) ? Effect.die(notAStream) : answer;
|
|
16
|
-
/**
|
|
17
|
-
* `run` as a tool calls it, a tool answering one result: the elements of an action answering a
|
|
18
|
-
* stream collected, in order, into one array once the stream ends.
|
|
19
|
-
*/
|
|
20
14
|
const answeringWhole = (action, run) => elementOf(action.success) === void 0 ? run : (input, reporting) => Stream.runCollect(elementsOf(run(input, reporting)));
|
|
21
15
|
const memoized = (build) => {
|
|
22
16
|
const key = Context.Service(`effect-actions/Implementation/${uniqueKey()}`);
|
|
@@ -25,12 +19,7 @@ const memoized = (build) => {
|
|
|
25
19
|
layer: Layer.effect(key, build)
|
|
26
20
|
};
|
|
27
21
|
};
|
|
28
|
-
/**
|
|
29
|
-
* The builders of an implementation of `contracts` as one layer: what its builder made, and its
|
|
30
|
-
* authorizer where a contract is protected, as only those need one.
|
|
31
|
-
*/
|
|
32
22
|
const builderLayer = (contracts, built, authorizer) => contracts.some((contract) => contract.caller !== Anyone) ? Layer.merge(built.layer, authorizer.layer) : built.layer;
|
|
33
|
-
/** What a surface throws for an implementation some other copy of this module made. */
|
|
34
23
|
const notMadeHere = (module) => /* @__PURE__ */ new Error(`Not an implementation made by this ${module}.implement: pass the value implement returned, not a copy such as a spread; or effect-actions is installed twice`);
|
|
35
24
|
const asDefects = (reason, rejected) => {
|
|
36
25
|
const trace = Context.makeUnsafe(reason.annotations);
|
|
@@ -120,16 +109,11 @@ var Implementation = class Implementation {
|
|
|
120
109
|
return actions.flatMap((action) => bound.flatMap(([held, handle]) => held === action ? [[action, dispatch(action, handle, before, keyed)]] : []));
|
|
121
110
|
});
|
|
122
111
|
}
|
|
123
|
-
/** `app`, if this copy of the module made it; another installed copy's cannot be read. */
|
|
124
112
|
static own(app) {
|
|
125
113
|
if (!(#handlers in app)) throw notMadeHere("Action");
|
|
126
114
|
return app;
|
|
127
115
|
}
|
|
128
116
|
};
|
|
129
|
-
/**
|
|
130
|
-
* The action implementations among what a surface is given; `eventsOf` reads the event
|
|
131
|
-
* implementations, by their tag.
|
|
132
|
-
*/
|
|
133
117
|
const toList = (served) => Array.ensure(served).filter((app) => !Predicate.isTagged(app, "EventImplementation"));
|
|
134
118
|
const notHeld = {
|
|
135
119
|
byImplementation: {
|
|
@@ -143,7 +127,6 @@ const notHeld = {
|
|
|
143
127
|
holder: "it does not hold: list the one it holds"
|
|
144
128
|
}
|
|
145
129
|
};
|
|
146
|
-
/** The actions' names, joined; one whose name another listed contract shares is marked `(another contract)`. */
|
|
147
130
|
const markingOthers = (actions, names) => actions.map(({ name }) => names.has(name) ? `${name} (another contract)` : name).join(", ");
|
|
148
131
|
const assertHeld = ({ why, fix, holder }, listed, held) => {
|
|
149
132
|
const missing = listed.filter((action) => !held.includes(action));
|
|
@@ -153,11 +136,6 @@ const assertHeld = ({ why, fix, holder }, listed, held) => {
|
|
|
153
136
|
throw new Error(`Listed in actions, but ${why}: ${markingOthers(missing, names)} (${fix}${sameName ? `; one marked (another contract) is a contract of that name ${holder}` : ""})`);
|
|
154
137
|
}
|
|
155
138
|
};
|
|
156
|
-
/**
|
|
157
|
-
* The implementations among `apps` holding what `listed` lists, each sharing its builder to hold
|
|
158
|
-
* those alone, or every one where it lists none: action and event implementations alike, by the
|
|
159
|
-
* contracts each `holds` and how it `share`s them.
|
|
160
|
-
*/
|
|
161
139
|
const selectHeld = (apps, listed, holds, share) => {
|
|
162
140
|
if (listed === void 0) return apps;
|
|
163
141
|
assertHeld(notHeld.byImplementation, listed, apps.flatMap(holds));
|
|
@@ -181,17 +159,12 @@ const servedBy = (what, bound, apps, listed) => {
|
|
|
181
159
|
assertOnce("served action", actions, heldOnce);
|
|
182
160
|
return served;
|
|
183
161
|
};
|
|
184
|
-
/** Provide `builders`, implementations' builder layers, to a surface's layer. */
|
|
185
162
|
const provideBuilders = (builders) => (layer) => {
|
|
186
163
|
const [first, ...rest] = builders;
|
|
187
164
|
return first === void 0 ? layer : Layer.provide(layer, Layer.mergeAll(first, ...rest));
|
|
188
165
|
};
|
|
189
166
|
const provideHandlers = (apps) => provideBuilders(apps.map((app) => Implementation.layerOf(app)));
|
|
190
167
|
const acquire = (apps, keyed) => Effect.map(Effect.forEach(apps, (app) => Implementation.boundOf(app, keyed)), (bound) => bound.flat());
|
|
191
|
-
/**
|
|
192
|
-
* What `acquisition` reads, once `builders` are built into the layer graph around the caller, and
|
|
193
|
-
* held by its scope.
|
|
194
|
-
*/
|
|
195
168
|
const builtWith = (builders, acquisition) => {
|
|
196
169
|
const [first, ...rest] = builders;
|
|
197
170
|
return Effect.gen(function* () {
|
|
@@ -11,6 +11,5 @@ import { Context, Effect } from "effect";
|
|
|
11
11
|
* - 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.
|
|
12
12
|
*/
|
|
13
13
|
const InputCheck = Context.Reference("effect-actions/Action/InputCheck", { defaultValue: () => () => Effect.void });
|
|
14
|
-
/** `contract`'s `input`, as the provided `InputCheck` judges it. */
|
|
15
14
|
const checkInput = (contract, input) => Effect.flatMap(Effect.service(InputCheck), (check) => check(contract, input));
|
|
16
15
|
export { InputCheck, checkInput };
|
package/dist/contract/lease.mjs
CHANGED
package/dist/contract/listed.mjs
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { assertOnce } from "./names.mjs";
|
|
2
2
|
import { isEvent } from "../Event.mjs";
|
|
3
3
|
// src/contract/listed.ts
|
|
4
|
-
/** A list split into its actions and its event types. */
|
|
5
4
|
const split = (contracts) => ({
|
|
6
5
|
actions: contracts.flatMap((contract) => isEvent(contract) ? [] : [contract]),
|
|
7
6
|
events: contracts.filter(isEvent)
|
|
8
7
|
});
|
|
9
|
-
/** A binding's list split into its actions and its event types, each name used once. */
|
|
10
8
|
const listed = (contracts) => {
|
|
11
9
|
assertOnce("action or event", contracts);
|
|
12
10
|
return split(contracts);
|
|
13
11
|
};
|
|
14
|
-
/**
|
|
15
|
-
* A surface's `actions` option split into the actions and the event types it lists, both absent
|
|
16
|
-
* where it is: a surface given the option serves exactly what it lists.
|
|
17
|
-
*/
|
|
18
12
|
const selection = (contracts) => contracts === void 0 ? {
|
|
19
13
|
actions: void 0,
|
|
20
14
|
events: void 0
|
package/dist/contract/log.mjs
CHANGED
|
@@ -6,7 +6,6 @@ const defaultBounds = {
|
|
|
6
6
|
maxAge: Duration.minutes(10),
|
|
7
7
|
maxEvents: 1e4
|
|
8
8
|
};
|
|
9
|
-
/** A log storage in memory, for the process that makes it. */
|
|
10
9
|
const memoryStorage = () => {
|
|
11
10
|
let position;
|
|
12
11
|
let newest = 0;
|
|
@@ -41,12 +40,6 @@ const seqIn = (epoch, cursor) => {
|
|
|
41
40
|
const parsed = Number(seq);
|
|
42
41
|
return named === epoch && rest.length === 0 && Number.isSafeInteger(parsed) && parsed >= 0 ? parsed : void 0;
|
|
43
42
|
};
|
|
44
|
-
/**
|
|
45
|
-
* A log's entries over `storage`, read by cursor: a cursor is the storage's epoch and the
|
|
46
|
-
* sequence number of the last entry it has seen, so one minted by another epoch, such as a
|
|
47
|
-
* memory log's before a restart or a storage's before it was emptied, reads as truncated, as
|
|
48
|
-
* does one whose next entries were dropped. An epoch is minted where the storage holds none.
|
|
49
|
-
*/
|
|
50
43
|
const makeLogStore = (storage, { maxAge = defaultBounds.maxAge, maxEvents = defaultBounds.maxEvents } = {}) => {
|
|
51
44
|
if (!Number.isSafeInteger(maxEvents) || maxEvents < 1) throw new Error(`Invalid log maxEvents: ${maxEvents} (give a positive integer)`);
|
|
52
45
|
const age = Duration.toMillis(Duration.fromInputUnsafe(maxAge));
|
|
@@ -115,7 +108,6 @@ const makeLogStore = (storage, { maxAge = defaultBounds.maxAge, maxEvents = defa
|
|
|
115
108
|
}))
|
|
116
109
|
};
|
|
117
110
|
};
|
|
118
|
-
/** A log over `store`, waking its followers as each entry is appended. */
|
|
119
111
|
const makeLog = (store) => {
|
|
120
112
|
const followers = /* @__PURE__ */ new Set();
|
|
121
113
|
const append = (value, key) => Effect.andThen(store.append({
|
package/dist/contract/names.mjs
CHANGED
|
@@ -3,7 +3,6 @@ const namePattern = "[A-Za-z0-9_-]{1,128}";
|
|
|
3
3
|
const validName = new RegExp(`^${namePattern}$`, "u");
|
|
4
4
|
const reserved = [["then", "which would make a client a thenable, awaited as a promise"], ["watch", "every client's method for events"]];
|
|
5
5
|
const reservedNames = reserved.map(([name]) => name);
|
|
6
|
-
/** The reserved names as a message lists them: `"then" or "watch"`. */
|
|
7
6
|
const reservedList = reservedNames.map((name) => `"${name}"`).join(" or ");
|
|
8
7
|
const assertName = (name) => {
|
|
9
8
|
if (!validName.test(name) || reservedNames.includes(name)) throw new Error(`Invalid action name: ${name} (use ${namePattern}, other than ${reserved.map(([reservedName, why]) => `"${reservedName}", ${why}`).join(", and ")})`);
|
|
@@ -17,27 +17,19 @@ const fieldsOf = (name, data) => ({
|
|
|
17
17
|
data,
|
|
18
18
|
cursor: Schema.NullOr(Schema.String).annotate({ description: "Where to resume after it, null for an event type that cannot be resumed." })
|
|
19
19
|
});
|
|
20
|
-
/** An occurrence of `event`, as a subscriber decodes it. */
|
|
21
20
|
const OccurrenceOf = (event) => Schema.TaggedStruct("Occurrence", fieldsOf(Schema.Literal(event.name), event.payload));
|
|
22
|
-
/** Any occurrence, its data erased, as a feed makes it. */
|
|
23
21
|
const AnyOccurrence = Schema.TaggedStruct("Occurrence", fieldsOf(Schema.String, Schema.Unknown));
|
|
24
|
-
/** What a subscriber of `event` decodes: an occurrence, or a gap. */
|
|
25
22
|
const ReceivedOf = (event) => Schema.Union([OccurrenceOf(event), Gap]);
|
|
26
23
|
const untaggedOf = (event) => OccurrenceOf(event).mapFields((fields) => ({
|
|
27
24
|
...Struct.omit(fields, ["_tag"]),
|
|
28
25
|
timestamp: Schema.DateTimeUtcFromString,
|
|
29
26
|
data: Schema.toCodecJson(event.payload)
|
|
30
27
|
}));
|
|
31
|
-
/**
|
|
32
|
-
* How a subscriber of `event` decodes an occurrence sent as JSON without its tag, as MCP's
|
|
33
|
-
* notifications and a webhook's body carry one.
|
|
34
|
-
*/
|
|
35
28
|
const untaggedOccurrenceOf = (event) => {
|
|
36
29
|
const occurrence = OccurrenceOf(event);
|
|
37
30
|
const decode = Schema.decodeUnknownEffect(untaggedOf(event));
|
|
38
31
|
return (wire) => Effect.map(decode(wire), (fields) => occurrence.make(fields));
|
|
39
32
|
};
|
|
40
|
-
/** How a surface encodes an occurrence of `event` as JSON without its tag, its counterpart. */
|
|
41
33
|
const encodeUntaggedOf = (event) => {
|
|
42
34
|
const encode = Schema.encodeEffect(untaggedOf(event));
|
|
43
35
|
return (occurrence) => Effect.orDie(encode(occurrence));
|
package/dist/contract/pages.mjs
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
import { Checked, Gap } from "./occurrence.mjs";
|
|
2
2
|
import { Duration, Effect, Option, Stream } from "effect";
|
|
3
3
|
// src/contract/pages.ts
|
|
4
|
-
/** The shortest wait between polls, whatever a source or a server asks for. */
|
|
5
4
|
const pollFloor = Duration.seconds(1);
|
|
6
|
-
|
|
7
|
-
const fedOf = (
|
|
8
|
-
...truncated ? [Gap.make({ cursor:
|
|
9
|
-
...items,
|
|
10
|
-
Checked.make({ cursor: to })
|
|
5
|
+
const gapSkippingNoneOf = ({ items, from, to }) => items.length === 0 ? to : from;
|
|
6
|
+
const fedOf = (delivered) => [
|
|
7
|
+
...delivered.truncated ? [Gap.make({ cursor: gapSkippingNoneOf(delivered) })] : [],
|
|
8
|
+
...delivered.items,
|
|
9
|
+
Checked.make({ cursor: delivered.to })
|
|
11
10
|
];
|
|
12
|
-
/**
|
|
13
|
-
* Reads from `cursor` again and again, as long as the stream is read: what each page yields, then
|
|
14
|
-
* a wait of its `nextPoll`, at least `pollFloor`, cut short by `woken`, or none where it has more;
|
|
15
|
-
* where `polls` is `false`, a wait for `woken` alone.
|
|
16
|
-
*/
|
|
17
11
|
const pagedFrom = (read, cursor, woken, polls = true) => Stream.paginate({
|
|
18
12
|
cursor,
|
|
19
13
|
delay: Duration.zero
|
|
@@ -26,7 +20,6 @@ const pagedFrom = (read, cursor, woken, polls = true) => Stream.paginate({
|
|
|
26
20
|
if (woken === void 0 || Duration.isZero(state.delay)) return Effect.andThen(sleep, next);
|
|
27
21
|
return Effect.andThen(polls ? Effect.race(sleep, woken) : woken, next);
|
|
28
22
|
});
|
|
29
|
-
/** Polls from `cursor` as `pagedFrom` reads: each page as its gap, its occurrences, its end. */
|
|
30
23
|
const paged = (poll, cursor) => pagedFrom((at) => Effect.map(poll(at), (page) => ({
|
|
31
24
|
...page,
|
|
32
25
|
fed: fedOf({
|