@gjermundgaraba/effect-actions 0.21.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/dist/Action.d.mts +2 -2
- package/dist/Action.mjs +1 -0
- package/dist/ActionCli.mjs +0 -1
- package/dist/ActionHttp.d.mts +1 -1
- package/dist/ActionMcp.d.mts +0 -3
- package/dist/ActionMcp.mjs +0 -5
- package/dist/ActionRpc.d.mts +8 -15
- package/dist/ActionRpc.mjs +29 -54
- package/dist/ActionToolkit.d.mts +0 -2
- package/dist/ActionToolkit.mjs +0 -2
- package/dist/Event.d.mts +0 -23
- package/dist/Testing.mjs +3 -2
- package/dist/Webhook.mjs +2 -2
- package/dist/authentication/refusal.mjs +0 -1
- package/dist/cli/commands.mjs +0 -5
- package/dist/contract/authorizer.mjs +0 -5
- package/dist/contract/call.mjs +0 -23
- package/dist/contract/callback.mjs +0 -1
- package/dist/contract/caller.mjs +0 -11
- package/dist/contract/canonical.mjs +0 -5
- package/dist/contract/codec.d.mts +0 -1
- package/dist/contract/codec.mjs +0 -1
- package/dist/contract/codes.mjs +1 -15
- package/dist/contract/declared.mjs +0 -15
- package/dist/contract/digest.mjs +0 -1
- package/dist/contract/errors.d.mts +0 -4
- package/dist/contract/errors.mjs +0 -4
- package/dist/contract/feed.d.mts +0 -1
- package/dist/contract/feed.mjs +0 -20
- package/dist/contract/hints.mjs +0 -6
- package/dist/contract/hub.mjs +0 -3
- package/dist/contract/idempotency.mjs +0 -4
- package/dist/contract/implementation.d.mts +0 -1
- package/dist/contract/implementation.mjs +0 -27
- package/dist/contract/input-check.mjs +0 -1
- package/dist/contract/lease.mjs +0 -1
- package/dist/contract/listed.mjs +0 -6
- package/dist/contract/log.mjs +0 -8
- package/dist/contract/names.mjs +0 -1
- package/dist/contract/occurrence.mjs +0 -8
- package/dist/contract/pages.mjs +5 -12
- package/dist/contract/progress.mjs +2 -25
- package/dist/contract/push.d.mts +0 -5
- package/dist/contract/push.mjs +1 -24
- package/dist/contract/receiving.mjs +0 -7
- package/dist/contract/reported.mjs +0 -5
- package/dist/contract/serving.mjs +0 -18
- package/dist/contract/status.mjs +0 -3
- package/dist/contract/stream.mjs +0 -2
- package/dist/contract/subscribe.d.mts +0 -2
- package/dist/contract/subscribe.mjs +0 -8
- package/dist/contract/transient.mjs +0 -12
- package/dist/contract/watch.mjs +5 -17
- package/dist/contract/webhooks.mjs +0 -11
- package/dist/http/client.mjs +0 -1
- package/dist/http/events.d.mts +0 -10
- package/dist/http/events.mjs +2 -31
- package/dist/http/placed.d.mts +0 -2
- package/dist/http/streamed.d.mts +0 -1
- package/dist/http/streamed.mjs +4 -32
- package/dist/http/watch.mjs +0 -6
- package/dist/mcp/bridge.mjs +0 -25
- package/dist/mcp/client.d.mts +0 -1
- package/dist/mcp/client.mjs +0 -1
- package/dist/mcp/events.mjs +0 -6
- package/dist/mcp/progress.mjs +0 -7
- package/dist/mcp/protocol.mjs +0 -6
- package/dist/mcp/reply.mjs +0 -11
- package/dist/mcp/request.mjs +0 -1
- package/dist/mcp/watch.mjs +0 -6
- package/dist/rpc/watch.mjs +0 -6
- package/dist/stdio/console.mjs +2 -2
- package/dist/webhook/address.mjs +4 -9
- package/dist/webhook/attempt.mjs +2 -15
- package/dist/webhook/receiver.mjs +2 -8
- package/dist/webhook/signing.mjs +0 -3
- package/dist/webhook/stored.mjs +8 -17
- package/dist/webhook/subscriptions.mjs +19 -23
- package/docs/Action-streams.md +0 -12
- package/docs/Action.md +0 -10
- package/docs/ActionCli.md +2 -26
- package/docs/ActionHttp.md +0 -28
- package/docs/ActionMcp.md +2 -37
- package/docs/ActionRpc-events.md +0 -16
- package/docs/ActionRpc.md +0 -63
- package/docs/ActionToolkit.md +0 -11
- package/docs/Authentication-advanced.md +0 -31
- package/docs/Authentication.md +4 -13
- package/docs/Event.md +0 -37
- package/docs/README.md +1 -1
- package/docs/Testing.md +3 -13
- package/docs/Webhook.md +0 -46
- package/docs/setup.md +0 -5
- package/examples/README.md +7 -1
- package/examples/assistant/src/agent.ts +8 -31
- package/examples/assistant/src/cli.ts +2 -9
- package/examples/assistant/src/commands.ts +0 -8
- package/examples/assistant/src/identity/Identity.ts +0 -10
- package/examples/assistant/src/identity/authorize.ts +0 -4
- package/examples/assistant/src/identity/members.ts +1 -3
- package/examples/assistant/src/identity/permissions.ts +0 -5
- package/examples/assistant/src/platform/tasks-file.ts +1 -6
- package/examples/assistant/src/scripted.ts +0 -4
- package/examples/assistant/src/tasks/Tasks.ts +0 -2
- package/examples/assistant/src/tasks/handlers.ts +0 -3
- package/examples/assistant/src/tasks/store.ts +0 -7
- package/examples/assistant/src/toolkit.ts +0 -11
- package/examples/assistant/test/commands.test.ts +0 -5
- package/examples/assistant/test/identity/identity.test.ts +6 -6
- package/examples/assistant/test/platform/tasks-file.test.ts +2 -6
- package/examples/assistant/test/tasks/tasks.test.ts +13 -14
- package/examples/assistant/test/toolkit.test.ts +7 -18
- package/examples/build-events/README.md +2 -0
- package/examples/build-events/src/Api.ts +0 -3
- package/examples/build-events/src/Rpc.ts +0 -2
- package/examples/build-events/src/builds/Builds.ts +0 -15
- package/examples/build-events/src/builds/events.ts +0 -10
- package/examples/build-events/src/builds/handlers.ts +0 -6
- package/examples/build-events/src/builds/log.ts +0 -6
- package/examples/build-events/src/builds/status.ts +0 -4
- package/examples/build-events/src/builds/store.ts +0 -21
- package/examples/build-events/src/cli.ts +0 -2
- package/examples/build-events/src/commands.ts +0 -9
- package/examples/build-events/src/deploys/approvers.ts +0 -3
- package/examples/build-events/src/deploys/events.ts +0 -8
- package/examples/build-events/src/deploys/handlers.ts +0 -2
- package/examples/build-events/src/identity/Identity.ts +0 -11
- package/examples/build-events/src/identity/members.ts +1 -2
- package/examples/build-events/src/identity/verifier.ts +8 -9
- package/examples/build-events/src/notifier/Notices.ts +0 -3
- package/examples/build-events/src/notifier/routes.ts +0 -10
- package/examples/build-events/src/notifier.ts +0 -8
- package/examples/build-events/src/routes.ts +0 -24
- package/examples/build-events/src/server.ts +0 -14
- package/examples/build-events/test/builds/events.test.ts +0 -6
- package/examples/build-events/test/builds/log.test.ts +0 -1
- package/examples/build-events/test/builds/progress.test.ts +0 -1
- package/examples/build-events/test/commands.test.ts +0 -5
- package/examples/build-events/test/deploys/events.test.ts +0 -1
- package/examples/build-events/test/http.test.ts +0 -4
- package/examples/build-events/test/notifier.test.ts +0 -9
- package/examples/build-events/test/routes.test.ts +0 -9
- package/examples/build-events/test/rpc.test.ts +0 -4
- package/examples/build-events/test/support/as.ts +3 -4
- package/examples/build-events/test/support/memory.ts +0 -5
- package/examples/build-events/test/webhooks.test.ts +0 -12
- package/examples/kitchen-sink/README.md +1 -1
- package/examples/kitchen-sink/src/Actions.ts +0 -10
- package/examples/kitchen-sink/src/Api.ts +0 -8
- package/examples/kitchen-sink/src/Rpc.ts +0 -4
- package/examples/kitchen-sink/src/admin/Admin.ts +0 -9
- package/examples/kitchen-sink/src/admin/authenticate.ts +2 -6
- package/examples/kitchen-sink/src/admin/authorize.ts +0 -5
- package/examples/kitchen-sink/src/admin/grants.ts +0 -5
- package/examples/kitchen-sink/src/admin/handlers.ts +0 -2
- package/examples/kitchen-sink/src/admin/keys.ts +1 -3
- package/examples/kitchen-sink/src/agent.ts +2 -13
- package/examples/kitchen-sink/src/assistant/Assistant.ts +7 -24
- package/examples/kitchen-sink/src/assistant/conversations.ts +3 -21
- package/examples/kitchen-sink/src/assistant/demo-model.ts +0 -5
- package/examples/kitchen-sink/src/assistant/handlers.ts +1 -30
- package/examples/kitchen-sink/src/attachments/Attachments.ts +0 -4
- package/examples/kitchen-sink/src/attachments/download.ts +0 -10
- package/examples/kitchen-sink/src/attachments/handlers.ts +0 -3
- package/examples/kitchen-sink/src/attachments/store.ts +0 -3
- package/examples/kitchen-sink/src/browser.ts +0 -9
- package/examples/kitchen-sink/src/cli.ts +0 -19
- package/examples/kitchen-sink/src/config.ts +3 -11
- package/examples/kitchen-sink/src/identity/Identity.ts +0 -18
- package/examples/kitchen-sink/src/identity/authenticate.ts +3 -14
- package/examples/kitchen-sink/src/identity/authorize.ts +0 -6
- package/examples/kitchen-sink/src/identity/directory.ts +8 -18
- package/examples/kitchen-sink/src/identity/handlers.ts +0 -3
- package/examples/kitchen-sink/src/identity/members.ts +1 -5
- package/examples/kitchen-sink/src/identity/quota.ts +0 -11
- package/examples/kitchen-sink/src/issues/Issues.ts +0 -24
- package/examples/kitchen-sink/src/issues/assistant.ts +0 -10
- package/examples/kitchen-sink/src/issues/events.ts +2 -16
- package/examples/kitchen-sink/src/issues/export.ts +0 -5
- package/examples/kitchen-sink/src/issues/guide.ts +0 -5
- package/examples/kitchen-sink/src/issues/handlers.ts +0 -5
- package/examples/kitchen-sink/src/issues/store.ts +19 -23
- package/examples/kitchen-sink/src/issues/write-limit.ts +0 -12
- package/examples/kitchen-sink/src/memory.ts +0 -9
- package/examples/kitchen-sink/src/ops.ts +0 -6
- package/examples/kitchen-sink/src/request-policy.ts +0 -17
- package/examples/kitchen-sink/src/routes.ts +0 -48
- package/examples/kitchen-sink/src/sdk.ts +0 -12
- package/examples/kitchen-sink/src/seed.ts +0 -10
- package/examples/kitchen-sink/src/server.ts +0 -22
- package/examples/kitchen-sink/src/stdio.ts +2 -12
- package/examples/kitchen-sink/src/workspaces/Workspaces.ts +0 -4
- package/examples/kitchen-sink/src/workspaces/handlers.ts +0 -4
- package/examples/kitchen-sink/src/workspaces/registry.ts +0 -5
- package/examples/kitchen-sink/src/workspaces/tenant.ts +0 -4
- package/examples/kitchen-sink/test/admin/admin.test.ts +0 -1
- package/examples/kitchen-sink/test/assistant/assistant.test.ts +0 -18
- package/examples/kitchen-sink/test/attachments/attachments.test.ts +0 -9
- package/examples/kitchen-sink/test/identity/identity.test.ts +0 -10
- package/examples/kitchen-sink/test/identity/session.test.ts +0 -10
- package/examples/kitchen-sink/test/issues/assistant.test.ts +3 -7
- package/examples/kitchen-sink/test/issues/events.test.ts +2 -9
- package/examples/kitchen-sink/test/issues/export.test.ts +0 -3
- package/examples/kitchen-sink/test/issues/issues.test.ts +6 -12
- package/examples/kitchen-sink/test/request-policy.test.ts +0 -6
- package/examples/kitchen-sink/test/routes.test.ts +0 -6
- package/examples/kitchen-sink/test/support/as.ts +3 -5
- package/examples/kitchen-sink/test/support/scripted.ts +0 -3
- package/examples/kitchen-sink/test/support/services.ts +0 -3
- package/examples/live-rpc/src/Rpc.ts +0 -4
- package/examples/live-rpc/src/browser.ts +0 -24
- package/examples/live-rpc/src/chat/Chat.ts +0 -22
- package/examples/live-rpc/src/chat/authorize.ts +0 -3
- package/examples/live-rpc/src/chat/events.ts +0 -14
- package/examples/live-rpc/src/chat/handlers.ts +0 -5
- package/examples/live-rpc/src/chat/room.ts +0 -6
- package/examples/live-rpc/src/chat/store.ts +0 -9
- package/examples/live-rpc/src/client.ts +0 -6
- package/examples/live-rpc/src/identity/Identity.ts +0 -6
- package/examples/live-rpc/src/identity/members.ts +1 -3
- package/examples/live-rpc/src/identity/verifier.ts +6 -12
- package/examples/live-rpc/src/page.ts +0 -10
- package/examples/live-rpc/src/routes.ts +0 -13
- package/examples/live-rpc/src/server.ts +0 -16
- package/examples/live-rpc/test/browser.test.ts +0 -9
- package/examples/live-rpc/test/chat/chat.test.ts +3 -11
- package/examples/live-rpc/test/routes.test.ts +0 -8
- package/examples/live-rpc/test/server.test.ts +0 -13
- package/examples/mcp-tools/src/instructions.ts +0 -4
- package/examples/mcp-tools/src/platform/fake-farm.ts +0 -6
- package/examples/mcp-tools/src/platform/print-farm.ts +0 -16
- package/examples/mcp-tools/src/printers/Printers.ts +0 -21
- package/examples/mcp-tools/src/printers/farm.ts +0 -5
- package/examples/mcp-tools/src/printers/handlers.ts +0 -6
- package/examples/mcp-tools/src/routes.ts +0 -11
- package/examples/mcp-tools/src/server.ts +0 -9
- package/examples/mcp-tools/src/stdio.ts +1 -13
- package/examples/mcp-tools/test/printers/printers.test.ts +0 -10
- package/examples/mcp-tools/test/routes.test.ts +0 -14
- package/examples/notes-service/src/Api.ts +0 -4
- package/examples/notes-service/src/browser.ts +0 -12
- package/examples/notes-service/src/cli.ts +0 -2
- package/examples/notes-service/src/commands.ts +0 -30
- package/examples/notes-service/src/identity/Identity.ts +0 -2
- package/examples/notes-service/src/identity/authorize.ts +0 -4
- package/examples/notes-service/src/identity/users.ts +1 -3
- package/examples/notes-service/src/identity/verifier.ts +4 -11
- package/examples/notes-service/src/notes/Notes.ts +0 -12
- package/examples/notes-service/src/notes/handlers.ts +0 -4
- package/examples/notes-service/src/notes/store.ts +62 -48
- package/examples/notes-service/src/routes.ts +0 -12
- package/examples/notes-service/src/server.ts +0 -6
- package/examples/notes-service/src/status/Status.ts +0 -1
- package/examples/notes-service/src/status/handlers.ts +0 -1
- package/examples/notes-service/src/stdio.ts +2 -12
- package/examples/notes-service/src/worker.ts +0 -7
- package/examples/notes-service/test/commands.test.ts +0 -20
- package/examples/notes-service/test/notes/as.ts +3 -4
- package/examples/notes-service/test/notes/in-process.test.ts +3 -6
- package/examples/notes-service/test/notes/notes.test.ts +0 -6
- package/examples/notes-service/test/routes.test.ts +0 -5
- package/examples/notes-service/test/worker.test.ts +0 -1
- package/examples/quickstart/src/Api.ts +0 -1
- package/examples/quickstart/src/client.ts +0 -3
- package/examples/quickstart/src/greeting/Greeting.ts +0 -2
- package/examples/quickstart/src/greeting/handlers.ts +0 -1
- package/examples/quickstart/src/routes.ts +0 -1
- package/examples/quickstart/src/server.ts +3 -6
- package/examples/quickstart/test/routes.test.ts +0 -1
- package/package.json +2 -1
package/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({
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { Cause, Data, Effect, Exit, Fiber, Option, Queue, Schema, Stream } from "effect";
|
|
2
2
|
// src/contract/progress.ts
|
|
3
3
|
const capacity = 16;
|
|
4
|
-
/**
|
|
5
|
-
* What a handler reports by, where `progress` is declared: each value checked by the schema, one
|
|
6
|
-
* breaking it a defect, and handed to `sink` from a buffer dropping the oldest, so the handler
|
|
7
|
-
* never waits. Without a `sink`, values are checked and dropped.
|
|
8
|
-
*/
|
|
9
4
|
const buffering = (progress, sink) => {
|
|
10
5
|
const check = Schema.decodeUnknownEffect(Schema.toType(progress));
|
|
11
6
|
const checked = (value) => Effect.orDie(check(value));
|
|
@@ -22,12 +17,7 @@ const buffering = (progress, sink) => {
|
|
|
22
17
|
};
|
|
23
18
|
});
|
|
24
19
|
};
|
|
25
|
-
/** Whether what is buffered still reaches the caller after `cause` ends a call. */
|
|
26
20
|
const drainsAfter = (cause) => !Cause.hasInterruptsOnly(cause);
|
|
27
|
-
/**
|
|
28
|
-
* Runs `handle` with what it reports by, as `buffering` makes it; what is buffered when it
|
|
29
|
-
* succeeds or fails reaches `sink` before its answer.
|
|
30
|
-
*/
|
|
31
21
|
const reportedTo = (progress, sink, handle) => {
|
|
32
22
|
if (progress === void 0) return handle(void 0);
|
|
33
23
|
return Effect.gen(function* () {
|
|
@@ -37,23 +27,14 @@ const reportedTo = (progress, sink, handle) => {
|
|
|
37
27
|
return yield* exit;
|
|
38
28
|
});
|
|
39
29
|
};
|
|
40
|
-
/**
|
|
41
|
-
* Runs the stream `handle` gives with what it reports by, as `buffering` makes it, in the
|
|
42
|
-
* stream's scope; what is buffered when it ends or fails reaches `sink` before its end.
|
|
43
|
-
*/
|
|
44
30
|
const streamReportedTo = (progress, sink, handle) => {
|
|
45
31
|
if (progress === void 0) return handle(void 0);
|
|
46
32
|
return Stream.unwrap(Effect.map(buffering(progress, sink), ({ reporting, drained }) => handle(reporting).pipe(Stream.onEnd(drained), Stream.catchCause((cause) => drainsAfter(cause) ? Stream.unwrap(Effect.as(drained, Stream.failCause(cause))) : Stream.failCause(cause)))));
|
|
47
33
|
};
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
const progressSink = (onProgress) => onProgress === void 0 ? void 0 : { progress: shown(onProgress) };
|
|
34
|
+
const shownIgnoringFailures = (onProgress) => (value) => Effect.catchCauseIf(Effect.suspend(() => onProgress(value)), (cause) => !Cause.hasInterruptsOnly(cause), (cause) => Effect.logWarning("onProgress failed", cause));
|
|
35
|
+
const progressSink = (onProgress) => onProgress === void 0 ? void 0 : { progress: shownIgnoringFailures(onProgress) };
|
|
51
36
|
const Progressed = Data.taggedEnum();
|
|
52
37
|
const endedEarly = Effect.die(/* @__PURE__ */ new Error("An answer streamed with its progress ended without its final element"));
|
|
53
|
-
/**
|
|
54
|
-
* A client's answer from a call's `stream`: each `Progress` value handed to `onProgress`, where
|
|
55
|
-
* the call gave one, then the `Final` value. A stream ending without one is a defect.
|
|
56
|
-
*/
|
|
57
38
|
const answerFrom = (stream, onProgress) => {
|
|
58
39
|
const report = progressSink(onProgress)?.progress ?? (() => Effect.void);
|
|
59
40
|
return Effect.flatMap(Stream.runFoldEffect(stream, () => Option.none(), (final, element) => Progressed.$is("Final")(element) ? Effect.succeedSome(element.value) : Effect.as(report(element.value), final)), Option.match({
|
|
@@ -61,10 +42,6 @@ const answerFrom = (stream, onProgress) => {
|
|
|
61
42
|
onSome: Effect.succeed
|
|
62
43
|
}));
|
|
63
44
|
};
|
|
64
|
-
/**
|
|
65
|
-
* A client's elements from a call's `stream` of an action answering a stream: each `Progress`
|
|
66
|
-
* value handed to `onProgress`, where the call gave one, and each `Element` value streamed.
|
|
67
|
-
*/
|
|
68
45
|
const elementsFrom = (stream, onProgress) => {
|
|
69
46
|
const report = progressSink(onProgress)?.progress ?? (() => Effect.void);
|
|
70
47
|
return Stream.flatMap(stream, (sent) => Progressed.$is("Progress")(sent) ? Stream.fromEffectDrain(report(sent.value)) : Stream.make(sent.value));
|
package/dist/contract/push.d.mts
CHANGED
|
@@ -4,16 +4,11 @@ import { OccurrenceSchema } from "./occurrence.mjs";
|
|
|
4
4
|
import "./pages.mjs";
|
|
5
5
|
import { Any } from "../Event.mjs";
|
|
6
6
|
import { Cause, Effect, Queue, Schema, Stream } from "effect";
|
|
7
|
-
/** What a push subscription of `event` sends, as each surface's stream encodes it. */
|
|
8
7
|
export declare const PushedOf: <E extends Any>(event: E) => Schema.Union<readonly [OccurrenceSchema<E>, Schema.TaggedStruct<"Gap", {
|
|
9
8
|
readonly cursor: Schema.NullOr<Schema.String>;
|
|
10
9
|
}>, Schema.TaggedStruct<"Checked", {
|
|
11
10
|
readonly cursor: Schema.NullOr<Schema.String>;
|
|
12
11
|
}>, Schema.TaggedStruct<"Failed", {}>]>;
|
|
13
|
-
/**
|
|
14
|
-
* What a subscription's request carries: the event's input, and the cursor it resumes from,
|
|
15
|
-
* `null` where it is omitted.
|
|
16
|
-
*/
|
|
17
12
|
export declare const SubscriptionOf: <E extends Any>(event: E) => Schema.Struct<{
|
|
18
13
|
readonly input: Codec;
|
|
19
14
|
readonly cursor: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.String>, never>;
|
package/dist/contract/push.mjs
CHANGED
|
@@ -9,7 +9,6 @@ import { Cause, Duration, Effect, Latch, Match, Queue, Schema, Stream } from "ef
|
|
|
9
9
|
* outage: its cause is logged and reported, and reading resumes from the position reached.
|
|
10
10
|
*/
|
|
11
11
|
const Failed = Schema.TaggedStruct("Failed", {});
|
|
12
|
-
/** What a push subscription of `event` sends, as each surface's stream encodes it. */
|
|
13
12
|
const PushedOf = (event) => Schema.Union([
|
|
14
13
|
OccurrenceOf(event),
|
|
15
14
|
Gap,
|
|
@@ -20,26 +19,14 @@ const subscriptionWith = (input) => Schema.Struct({
|
|
|
20
19
|
input,
|
|
21
20
|
cursor: Schema.NullOr(Schema.String).annotate({ description: "Where to resume: a cursor an occurrence or a page carried; null or omitted, from now." }).pipe(Schema.withDecodingDefaultKey(Effect.succeed(null)))
|
|
22
21
|
});
|
|
23
|
-
/**
|
|
24
|
-
* What a subscription's request carries: the event's input, and the cursor it resumes from,
|
|
25
|
-
* `null` where it is omitted.
|
|
26
|
-
*/
|
|
27
22
|
const SubscriptionOf = (event) => subscriptionWith(event.input);
|
|
28
|
-
/** A subscription's request, its input left as JSON for its event's schema to decode. */
|
|
29
23
|
const Subscription = subscriptionWith(Schema.Json);
|
|
30
24
|
const queued = 16;
|
|
31
25
|
const heartbeatEvery = Duration.seconds(30);
|
|
32
26
|
const isFailed = Schema.is(Failed);
|
|
33
|
-
/** Each element of a push stream of `surface`'s event `name` but `Failed`, which is logged. */
|
|
34
27
|
const readOn = (surface, name) => (sent) => sent.pipe(Stream.mapEffect((element) => isFailed(element) ? Effect.as(Effect.logWarning(`${surface} event "${name}" failed to read, and resumes`), []) : Effect.succeed([element])), Stream.flattenIterable);
|
|
35
28
|
const isRefused = Schema.is(Refusal);
|
|
36
|
-
/** The refusal that `cause` fails with, unless it also holds a defect. */
|
|
37
29
|
const refusalIn = (cause) => Cause.hasDies(cause) ? void 0 : cause.reasons.flatMap((reason) => Cause.isFailReason(reason) && isRefused(reason.error) ? [reason.error] : [])[0];
|
|
38
|
-
/**
|
|
39
|
-
* A poll of `name` that answers a failure no refusal explains, reported, as a page of none from
|
|
40
|
-
* the cursor asked, read again after the poll interval: where no network carries a 500 for a
|
|
41
|
-
* client to retry, as in process, it reads on as `pushed` does.
|
|
42
|
-
*/
|
|
43
30
|
const polledOn = (surface, name) => (poll) => (cursor) => Effect.catchCauseIf(poll(cursor), (cause) => !Cause.hasInterruptsOnly(cause) && refusalIn(cause) === void 0, (cause) => Effect.as(Effect.andThen(reported(cause), Effect.logWarning(`${surface} event "${name}" failed to read, and resumes`)), {
|
|
44
31
|
events: [],
|
|
45
32
|
cursor,
|
|
@@ -47,12 +34,6 @@ const polledOn = (surface, name) => (poll) => (cursor) => Effect.catchCauseIf(po
|
|
|
47
34
|
hasMore: false,
|
|
48
35
|
nextPoll: defaultNextPoll
|
|
49
36
|
}));
|
|
50
|
-
/**
|
|
51
|
-
* One push subscription of a feed `open` reads from a cursor, starting at `cursor`, each thing it
|
|
52
|
-
* sends given to `deliver`. A refusal, an interruption, or, unless `resumesUnconfirmed`, a failure
|
|
53
|
-
* before it is confirmed ends it; any other failure of a read or of its delivery is reported,
|
|
54
|
-
* sent as `Failed`, and reading resumes from the position delivered after the poll interval.
|
|
55
|
-
*/
|
|
56
37
|
const pushed = (open, cursor, deliver, { resumesUnconfirmed = false, inOrder = false } = {}) => Effect.gen(function* () {
|
|
57
38
|
const confirmed = yield* Latch.make();
|
|
58
39
|
let reached = cursor;
|
|
@@ -81,11 +62,7 @@ const pushed = (open, cursor, deliver, { resumesUnconfirmed = false, inOrder = f
|
|
|
81
62
|
const heartbeat = Effect.andThen(confirmed.await, Effect.forever(Effect.andThen(Effect.sleep(heartbeatEvery), () => Effect.suspend(() => deliver(Checked.make({ cursor: reached }))))));
|
|
82
63
|
return yield* inOrder ? Effect.forever(once) : Effect.raceFirst(Effect.forever(once), heartbeat);
|
|
83
64
|
});
|
|
84
|
-
|
|
85
|
-
* A push subscription for a surface's streamed response: read into a bounded queue, each element
|
|
86
|
-
* as `encode` gives it, forked in the current scope.
|
|
87
|
-
*/
|
|
88
|
-
const queuedPush = (open, cursor, encode, { ending = (run) => run, inOrder = false, capacity = queued } = {}) => Effect.gen(function* () {
|
|
65
|
+
const queuedPush = (open, cursor, encode, { ending, inOrder = false, capacity = queued }) => Effect.gen(function* () {
|
|
89
66
|
const queue = yield* Queue.bounded(capacity);
|
|
90
67
|
yield* pushed(open, cursor, (sent) => Effect.flatMap(encode(sent), (element) => Queue.offer(queue, element)), {
|
|
91
68
|
resumesUnconfirmed: true,
|
|
@@ -3,7 +3,6 @@ import { Gap, untaggedOccurrenceOf } from "./occurrence.mjs";
|
|
|
3
3
|
import { reasonOf, refusalOf } from "./codes.mjs";
|
|
4
4
|
import { Context, Effect, Option, Schema, Struct } from "effect";
|
|
5
5
|
// src/contract/receiving.ts
|
|
6
|
-
/** The query parameter of a watch's delivery URL naming its place at the receiver. */
|
|
7
6
|
const watchParameter = "watch";
|
|
8
7
|
/**
|
|
9
8
|
* Where a watch by webhook receives its deliveries in this process: `Webhook.layerReceiver`
|
|
@@ -20,12 +19,6 @@ const Terminated = Schema.Struct({ error: Schema.Struct({
|
|
|
20
19
|
const decodeTerminated = Schema.decodeUnknownOption(Terminated);
|
|
21
20
|
const decodeGap = Schema.decodeUnknownEffect(Schema.toCodecJson(Gap.mapFields(Struct.omit(["_tag"]))));
|
|
22
21
|
const ended = new Forbidden({ message: "The subscription was ended." });
|
|
23
|
-
/**
|
|
24
|
-
* What a watch of `event` reads from one delivered body: its occurrence, or the gap an envelope
|
|
25
|
-
* reports; a `terminated` envelope fails with the reason its error's code names, its refusal for
|
|
26
|
-
* any other, an envelope of another type is skipped, and a body that does not decode fails with a
|
|
27
|
-
* `SchemaError`.
|
|
28
|
-
*/
|
|
29
22
|
const webhookFed = (event) => {
|
|
30
23
|
const occurrenceOf = untaggedOccurrenceOf(event);
|
|
31
24
|
return (body) => {
|