@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
|
@@ -11,30 +11,18 @@ import { authenticate } from "./identity/verifier.js";
|
|
|
11
11
|
import { notes } from "./notes/handlers.js";
|
|
12
12
|
import { status } from "./status/handlers.js";
|
|
13
13
|
|
|
14
|
-
// Every domain's implementation, once. Each surface below takes the same list.
|
|
15
14
|
const implementations = [status, notes, identity];
|
|
16
15
|
|
|
17
|
-
// JSON routes at `/api/<action>`, the binding's; `getStatus` answers anyone.
|
|
18
16
|
const api = ActionHttp.layer(Http, implementations);
|
|
19
17
|
|
|
20
|
-
// The host's own routes sit beside the actions' on the same router.
|
|
21
18
|
const health = HttpRouter.add("GET", "/healthz", HttpServerResponse.text("ok"));
|
|
22
19
|
|
|
23
|
-
// Served to anyone, which is a choice: it tells a signed-out caller every action's name and
|
|
24
|
-
// shape. To keep them, leave the route out, or provide `Authentication.protect(Login).layer`
|
|
25
|
-
// to it.
|
|
26
20
|
const openApi = HttpRouter.add(
|
|
27
21
|
"GET",
|
|
28
22
|
"/api/openapi.json",
|
|
29
23
|
HttpServerResponse.jsonUnsafe(OpenApi.fromApi(Http.api))
|
|
30
24
|
);
|
|
31
25
|
|
|
32
|
-
// What the host serves: the JSON routes, the same actions as MCP tools at `/mcp`, and the host's
|
|
33
|
-
// own routes. The MCP endpoint serves the public `getStatus` beside the protected tools, so a
|
|
34
|
-
// signed-out 2026-07-28 client may list the tools and call `getStatus`; what else needs a token
|
|
35
|
-
// is on `ActionMcp.LayerHttpOptions.authentication`. It still requires `NoteStore`: the
|
|
36
|
-
// entrypoint chooses which one, and a test chooses its own. The entrypoint also chooses how the
|
|
37
|
-
// MCP endpoint runs: one server for every request, or one per request.
|
|
38
26
|
const serving = (requestScoped: boolean) =>
|
|
39
27
|
Layer.mergeAll(
|
|
40
28
|
api,
|
|
@@ -7,11 +7,8 @@ import { HttpRouter, HttpServerRequest } from "effect/http";
|
|
|
7
7
|
import { NoteStore } from "./notes/store.js";
|
|
8
8
|
import { routes } from "./routes.js";
|
|
9
9
|
|
|
10
|
-
// Entrypoint: `node --import tsx examples/notes-service/src/server.ts`.
|
|
11
|
-
// It chooses the store, reads the configuration and starts Node's HTTP server.
|
|
12
10
|
const server = Layer.unwrap(
|
|
13
11
|
Effect.gen(function* () {
|
|
14
|
-
// The loopback default serves this machine alone; HOST=0.0.0.0 lets others reach it.
|
|
15
12
|
const host = yield* Config.String("HOST").pipe(
|
|
16
13
|
Config.withDefault("127.0.0.1")
|
|
17
14
|
);
|
|
@@ -20,12 +17,9 @@ const server = Layer.unwrap(
|
|
|
20
17
|
|
|
21
18
|
return HttpRouter.serve(routes).pipe(
|
|
22
19
|
Layer.provide(NodeHttpServer.layer(createServer, { host, port })),
|
|
23
|
-
// Request bodies have no size limit unless the host sets one. This covers every route that
|
|
24
|
-
// reads its body whole.
|
|
25
20
|
Layer.provide(
|
|
26
21
|
Layer.succeed(HttpServerRequest.MaxBodySize, ByteSize.mebibytes(1))
|
|
27
22
|
),
|
|
28
|
-
// DEMO ONLY: notes live in this process's memory; a deployment provides a store that lasts.
|
|
29
23
|
Layer.provide(NoteStore.layerMemory)
|
|
30
24
|
);
|
|
31
25
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as Action from "@gjermundgaraba/effect-actions/Action";
|
|
2
2
|
import { Schema } from "effect";
|
|
3
3
|
|
|
4
|
-
// Public: `caller: Action.Anyone`. It answers before anyone has signed in, on every surface.
|
|
5
4
|
export const GetStatus = Action.make("getStatus", {
|
|
6
5
|
description: "Report whether the service is up and how many notes it holds.",
|
|
7
6
|
success: { service: Schema.String, notes: Schema.Finite },
|
|
@@ -4,7 +4,6 @@ import { Effect } from "effect";
|
|
|
4
4
|
import { NoteStore } from "../notes/store.js";
|
|
5
5
|
import { GetStatus } from "./Status.js";
|
|
6
6
|
|
|
7
|
-
// A public action takes no `authorize`: nothing would run it.
|
|
8
7
|
export const status = Action.implement(
|
|
9
8
|
GetStatus,
|
|
10
9
|
Effect.gen(function* () {
|
|
@@ -5,27 +5,17 @@ import { Effect } from "effect";
|
|
|
5
5
|
|
|
6
6
|
import { identity } from "./identity/handlers.js";
|
|
7
7
|
import { CurrentUser } from "./identity/Identity.js";
|
|
8
|
-
import {
|
|
8
|
+
import { demoUsers } from "./identity/users.js";
|
|
9
9
|
import { notes } from "./notes/handlers.js";
|
|
10
10
|
import { NoteStore } from "./notes/store.js";
|
|
11
11
|
import { status } from "./status/handlers.js";
|
|
12
12
|
|
|
13
|
-
// Entrypoint: an MCP server a local agent starts as a subprocess, such as
|
|
14
|
-
// `claude mcp add notes -- "$PWD/node_modules/.bin/tsx" "$PWD/examples/notes-service/src/stdio.ts"`
|
|
15
|
-
// from the repository root. The host starts the process in a directory it chooses, so `tsx`
|
|
16
|
-
// and the file are named by full path.
|
|
17
|
-
// The same implementations as the HTTP server, and the same `authorize`. No token arrives
|
|
18
|
-
// over stdio, so this host names the caller itself. It is a process of its own with services
|
|
19
|
-
// of its own. DEMO ONLY: this in-memory store holds its notes, not the running server's. To
|
|
20
|
-
// share them, both provide a store they both reach, such as a database.
|
|
21
13
|
ActionMcp.runStdio([status, notes, identity], {
|
|
22
14
|
name: "notes-service",
|
|
23
15
|
version: "1.0.0",
|
|
24
16
|
}).pipe(
|
|
25
|
-
|
|
26
|
-
Effect.provideService(CurrentUser, users.ada),
|
|
17
|
+
Effect.provideService(CurrentUser, demoUsers.ada),
|
|
27
18
|
Effect.provide([NodeStdio.layer, NoteStore.layerMemory]),
|
|
28
|
-
// stdout carries the protocol alone, so logs and failures go to stderr.
|
|
29
19
|
ActionCli.logToStderr,
|
|
30
20
|
NodeRuntime.runMain()
|
|
31
21
|
);
|
|
@@ -4,15 +4,8 @@ import { HttpRouter, HttpServer } from "effect/http";
|
|
|
4
4
|
import { NoteStore } from "./notes/store.js";
|
|
5
5
|
import { requestScopedRoutes } from "./routes.js";
|
|
6
6
|
|
|
7
|
-
// Entrypoint for a host that calls `fetch` per request and runs nothing between requests, such
|
|
8
|
-
// as Cloudflare Workers, which takes this default export. The handler is built once, when the
|
|
9
|
-
// module loads, as Effect's `HttpRouter.toWebHandler` asks on Workers: a build started inside
|
|
10
|
-
// `fetch` would belong to that request. Building these routes does no I/O, which Workers refuses
|
|
11
|
-
// outside a request. `toWebHandler` reads no `MaxBodySize`, so the host limits request bodies.
|
|
12
7
|
const app = HttpRouter.toWebHandler(
|
|
13
8
|
requestScopedRoutes.pipe(
|
|
14
|
-
// DEMO ONLY: each instance of the worker holds notes of its own, lost when it stops. A
|
|
15
|
-
// deployment provides a store every instance reaches.
|
|
16
9
|
Layer.provide(NoteStore.layerMemory),
|
|
17
10
|
Layer.provide(HttpServer.layerServices)
|
|
18
11
|
)
|
|
@@ -22,15 +22,8 @@ import { ImportNotes, Note, NoteNotFound } from "../src/notes/Notes.js";
|
|
|
22
22
|
import { NoteStore } from "../src/notes/store.js";
|
|
23
23
|
import { routes } from "../src/routes.js";
|
|
24
24
|
|
|
25
|
-
// What the commands add to the routes: their syntax and what they print. They call the real
|
|
26
|
-
// routes in memory, as a client with a token does, where cli.ts connects them to a server. A
|
|
27
|
-
// service a builder yields is provided here too (routes.test.ts).
|
|
28
25
|
const served = Testing.layer(routes).pipe(Layer.provide(NoteStore.layerMemory));
|
|
29
26
|
|
|
30
|
-
// Effect's own runner, given arguments instead of the process's, and what the commands read from
|
|
31
|
-
// the environment as a Layer, so the test decides whether a token is configured, whatever the
|
|
32
|
-
// shell holds. The console of `it.effect` keeps every line printed, so a run returns the lines
|
|
33
|
-
// it added.
|
|
34
27
|
const connected = (
|
|
35
28
|
environment: Record<string, string>,
|
|
36
29
|
args: readonly string[],
|
|
@@ -53,14 +46,12 @@ const connected = (
|
|
|
53
46
|
return (yield* TestConsole.logLines).slice(before);
|
|
54
47
|
});
|
|
55
48
|
|
|
56
|
-
// A run as the caller `token` names.
|
|
57
49
|
const run = (token: string, args: readonly string[], stdin = "") =>
|
|
58
50
|
connected({ NOTES_TOKEN: token }, args, stdin);
|
|
59
51
|
|
|
60
52
|
const fitsAFile = (text: string) =>
|
|
61
53
|
new TextDecoder().decode(new TextEncoder().encode(text)) === text;
|
|
62
54
|
|
|
63
|
-
// Lines a random string almost never holds, each one the format has to keep apart from a title.
|
|
64
55
|
const trickyLines = Arbitrary.array(
|
|
65
56
|
Arbitrary.schema(
|
|
66
57
|
Schema.Literals([
|
|
@@ -103,7 +94,6 @@ describe("the commands", () => {
|
|
|
103
94
|
"take an argument, a flag and stdin, and print what `render` returns",
|
|
104
95
|
() =>
|
|
105
96
|
Effect.gen(function* () {
|
|
106
|
-
// A command without `render` prints its result as JSON.
|
|
107
97
|
const [created] = yield* run(
|
|
108
98
|
"ada",
|
|
109
99
|
["create-note", "--title", "Plan"],
|
|
@@ -134,7 +124,6 @@ describe("the commands", () => {
|
|
|
134
124
|
"describe a flag in `--help` as the contract describes its field",
|
|
135
125
|
() =>
|
|
136
126
|
Effect.gen(function* () {
|
|
137
|
-
// Help is one printed text. The description is the `revision` field's, from Notes.ts.
|
|
138
127
|
expect(yield* run("ada", ["update-note", "--help"])).toStrictEqual([
|
|
139
128
|
expect.stringContaining("The revision you read: 1 for a new note"),
|
|
140
129
|
]);
|
|
@@ -146,7 +135,6 @@ describe("the commands", () => {
|
|
|
146
135
|
yield* run("ada", ["create-note", "--title", "Plan"], "First draft\n");
|
|
147
136
|
yield* run("ada", ["create-note", "--title", "Budget"], "Too small\n");
|
|
148
137
|
|
|
149
|
-
// The command writes with the real file system, so the test gives it a real directory.
|
|
150
138
|
const files = yield* FileSystem.FileSystem;
|
|
151
139
|
const file = `${yield* files.makeTempDirectoryScoped()}/notes.md`;
|
|
152
140
|
|
|
@@ -202,7 +190,6 @@ describe("the commands", () => {
|
|
|
202
190
|
|
|
203
191
|
expect(notes.map(({ title }) => title)).toStrictEqual(["Plan", "Budget"]);
|
|
204
192
|
|
|
205
|
-
// A missing file is a usage error: the command's help, and the file named on stderr.
|
|
206
193
|
yield* Effect.flip(run("ada", ["import", `${directory}/nowhere.md`]));
|
|
207
194
|
|
|
208
195
|
expect(yield* TestConsole.errorLines).toContainEqual(
|
|
@@ -213,9 +200,6 @@ describe("the commands", () => {
|
|
|
213
200
|
}).pipe(Effect.provide(Layer.merge(served, NodeServices.layer)))
|
|
214
201
|
);
|
|
215
202
|
|
|
216
|
-
// Any notes the contract accepts, generated from its schema, with lines that start as a title
|
|
217
|
-
// would added to their bodies. A file holds Unicode text, so a string JSON carries but no file
|
|
218
|
-
// can, one with a lone surrogate, is left out.
|
|
219
203
|
it.effect.prop(
|
|
220
204
|
"import every note `export` wrote as it was, whatever its body holds",
|
|
221
205
|
[importable],
|
|
@@ -301,12 +285,10 @@ describe("the commands", () => {
|
|
|
301
285
|
"userMessage",
|
|
302
286
|
'{"_tag":"Unauthenticated","message":"Unknown demo token."}'
|
|
303
287
|
);
|
|
304
|
-
// The command's own context is a line of its own on stderr, the JSON left as it is.
|
|
305
288
|
expect(yield* TestConsole.errorLines).toContain(
|
|
306
289
|
"The export to notes.md did not finish."
|
|
307
290
|
);
|
|
308
291
|
|
|
309
|
-
// Not an action's error: the file system's, named in the message.
|
|
310
292
|
const unwritable = yield* Effect.flip(
|
|
311
293
|
run("ada", ["export", "no-such-directory/notes.md"])
|
|
312
294
|
);
|
|
@@ -342,12 +324,10 @@ describe("the commands", () => {
|
|
|
342
324
|
"MissingToken: NOTES_TOKEN is not set. Set it to your token: export NOTES_TOKEN=<your token>"
|
|
343
325
|
);
|
|
344
326
|
|
|
345
|
-
// What a person sees: that message, once, on stderr, and no report of a `ConfigError`.
|
|
346
327
|
expect(yield* TestConsole.errorLines).toStrictEqual([
|
|
347
328
|
expect.stringContaining("NOTES_TOKEN is not set."),
|
|
348
329
|
]);
|
|
349
330
|
|
|
350
|
-
// The token is read when a command runs, so help needs none.
|
|
351
331
|
yield* connected({}, ["list-notes", "--help"]);
|
|
352
332
|
|
|
353
333
|
expect(yield* TestConsole.logLines).toHaveLength(2);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
|
|
3
3
|
import { CurrentUser } from "../../src/identity/Identity.js";
|
|
4
|
-
import {
|
|
4
|
+
import { demoUsers } from "../../src/identity/users.js";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Effect.provideService(CurrentUser, users[user]);
|
|
6
|
+
export const as = (user: keyof typeof demoUsers) =>
|
|
7
|
+
Effect.provideService(CurrentUser, demoUsers[user]);
|
|
@@ -3,16 +3,13 @@ import * as Action from "@gjermundgaraba/effect-actions/Action";
|
|
|
3
3
|
import { Effect } from "effect";
|
|
4
4
|
|
|
5
5
|
import { CurrentUser } from "../../src/identity/Identity.js";
|
|
6
|
-
import {
|
|
6
|
+
import { demoUsers } from "../../src/identity/users.js";
|
|
7
7
|
import { notes } from "../../src/notes/handlers.js";
|
|
8
8
|
import { NoteNotFound } from "../../src/notes/Notes.js";
|
|
9
9
|
import { NoteStore } from "../../src/notes/store.js";
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// provides it per request.
|
|
14
|
-
const as = (user: keyof typeof users) =>
|
|
15
|
-
Effect.provideService(CurrentUser, users[user]);
|
|
11
|
+
const as = (user: keyof typeof demoUsers) =>
|
|
12
|
+
Effect.provideService(CurrentUser, demoUsers[user]);
|
|
16
13
|
|
|
17
14
|
describe("notes, in process", () => {
|
|
18
15
|
it.effect("keeps each user's notes their own", () =>
|
|
@@ -7,9 +7,6 @@ import { NoteChanged, NoteNotFound } from "../../src/notes/Notes.js";
|
|
|
7
7
|
import { NoteStore } from "../../src/notes/store.js";
|
|
8
8
|
import { as } from "./as.js";
|
|
9
9
|
|
|
10
|
-
// The store's rules, with no transport, as in-process.test.ts calls the implementation: a
|
|
11
|
-
// revision check, and a race two fibers run under every interleaving.
|
|
12
|
-
|
|
13
10
|
describe("notes, in process", () => {
|
|
14
11
|
it.effect("deletes a note for its owner", () =>
|
|
15
12
|
Effect.gen(function* () {
|
|
@@ -52,9 +49,6 @@ describe("notes, in process", () => {
|
|
|
52
49
|
Effect.gen(function* () {
|
|
53
50
|
const client = yield* Action.client(notes);
|
|
54
51
|
|
|
55
|
-
// A fiber is set aside after every `steps` steps, and two that run at once then take
|
|
56
|
-
// turns. Each count sets the first update aside at another point of its work; under
|
|
57
|
-
// three, the two do not finish.
|
|
58
52
|
const succeeded = yield* Effect.forEach(Array.range(3, 60), (steps) =>
|
|
59
53
|
Effect.gen(function* () {
|
|
60
54
|
const note = yield* client
|
|
@@ -12,10 +12,6 @@ import { NoteStore } from "../src/notes/store.js";
|
|
|
12
12
|
import { routes } from "../src/routes.js";
|
|
13
13
|
import { GetStatus } from "../src/status/Status.js";
|
|
14
14
|
|
|
15
|
-
// What the wire adds: the real routes, behind their real authentication, answering in memory.
|
|
16
|
-
// No port is opened. The caller is the token each client sends, as in production. A service a
|
|
17
|
-
// builder yields is provided here, as server.ts provides it: one left out is a `Scope` error at
|
|
18
|
-
// every `it.effect` (docs/Testing-failures.md).
|
|
19
15
|
const served = Testing.layer(routes).pipe(Layer.provide(NoteStore.layerMemory));
|
|
20
16
|
|
|
21
17
|
const as = (token: string) => ({
|
|
@@ -117,7 +113,6 @@ describe("the service, over HTTP and MCP", () => {
|
|
|
117
113
|
transformClient: (client) =>
|
|
118
114
|
client.pipe(
|
|
119
115
|
as("ada").transformClient,
|
|
120
|
-
// The real server finishes the write, but the caller receives no response.
|
|
121
116
|
HttpClient.transform((response, request) =>
|
|
122
117
|
response.pipe(
|
|
123
118
|
Effect.andThen(
|
|
@@ -9,7 +9,6 @@ import { CreateNote, GetNote } from "../src/notes/Notes.js";
|
|
|
9
9
|
import { GetStatus } from "../src/status/Status.js";
|
|
10
10
|
import worker from "../src/worker.js";
|
|
11
11
|
|
|
12
|
-
// What a host calling the worker's `fetch` gets: the module's own handler, answering in memory.
|
|
13
12
|
const served = Testing.layer(worker.fetch);
|
|
14
13
|
|
|
15
14
|
const as = (token: string) => ({
|
|
@@ -5,9 +5,6 @@ import { FetchHttpClient } from "effect/http";
|
|
|
5
5
|
|
|
6
6
|
import { Http } from "./Api.js";
|
|
7
7
|
|
|
8
|
-
// Entrypoint: `node --import tsx examples/quickstart/src/client.ts`, with the server running.
|
|
9
|
-
// One typed method per action of the binding.
|
|
10
|
-
// DEMO ONLY: a deployed client reads its `baseUrl` from configuration (kitchen-sink/src/seed.ts).
|
|
11
8
|
Effect.gen(function* () {
|
|
12
9
|
const client = yield* ActionHttp.client(Http, {
|
|
13
10
|
baseUrl: "http://127.0.0.1:3000",
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as Action from "@gjermundgaraba/effect-actions/Action";
|
|
2
2
|
import { Schema } from "effect";
|
|
3
3
|
|
|
4
|
-
// A contract: what the action takes and answers, whether it changes anything, and who may
|
|
5
|
-
// call it. It imports no server code, so any client can import it, a browser page included.
|
|
6
4
|
export const Greet = Action.make("greet", {
|
|
7
5
|
description: "Greet someone by name.",
|
|
8
6
|
input: { name: Schema.String },
|
|
@@ -3,7 +3,6 @@ import { Effect } from "effect";
|
|
|
3
3
|
|
|
4
4
|
import { Greet } from "./Greeting.js";
|
|
5
5
|
|
|
6
|
-
// The implementation: the contract bound to its handler. Every surface takes this one value.
|
|
7
6
|
export const greeting = Action.implement(Greet, ({ name }) =>
|
|
8
7
|
Effect.succeed(`Hello, ${name}!`)
|
|
9
8
|
);
|
|
@@ -5,7 +5,6 @@ import { Layer } from "effect";
|
|
|
5
5
|
import { Http } from "./Api.js";
|
|
6
6
|
import { greeting } from "./greeting/handlers.js";
|
|
7
7
|
|
|
8
|
-
// One implementation, two surfaces: a JSON route and an MCP tool at `/mcp`.
|
|
9
8
|
export const routes = Layer.mergeAll(
|
|
10
9
|
ActionHttp.layer(Http, greeting),
|
|
11
10
|
ActionMcp.layerHttp(greeting, { name: "greetings", version: "1.0.0" })
|
|
@@ -6,13 +6,10 @@ import { HttpRouter } from "effect/http";
|
|
|
6
6
|
|
|
7
7
|
import { routes } from "./routes.js";
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// as notes-service/src/server.ts does; `127.0.0.1` serves this machine alone.
|
|
9
|
+
const demoListen = { host: "127.0.0.1", port: 3000 };
|
|
10
|
+
|
|
12
11
|
HttpRouter.serve(routes).pipe(
|
|
13
|
-
Layer.provide(
|
|
14
|
-
NodeHttpServer.layer(createServer, { host: "127.0.0.1", port: 3000 })
|
|
15
|
-
),
|
|
12
|
+
Layer.provide(NodeHttpServer.layer(createServer, demoListen)),
|
|
16
13
|
Layer.launch,
|
|
17
14
|
NodeRuntime.runMain()
|
|
18
15
|
);
|
|
@@ -8,7 +8,6 @@ import { Http } from "../src/Api.js";
|
|
|
8
8
|
import { Greet } from "../src/greeting/Greeting.js";
|
|
9
9
|
import { routes } from "../src/routes.js";
|
|
10
10
|
|
|
11
|
-
// The routes answer in memory: no port, and the same code the server runs.
|
|
12
11
|
it.effect("greets over HTTP and as an MCP tool", () =>
|
|
13
12
|
Effect.gen(function* () {
|
|
14
13
|
const http = yield* ActionHttp.client(Http);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjermundgaraba/effect-actions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Define Effect action contracts once and project them onto HTTP, MCP, Effect RPC, native Toolkits, and CLIs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agents",
|
|
@@ -51,14 +51,14 @@
|
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@
|
|
54
|
+
"@clanker-stuff/oxlint-config": "0.1.0",
|
|
55
|
+
"@effect/platform-node": "4.1.1",
|
|
55
56
|
"@effect/tsgo": "0.57.0",
|
|
56
|
-
"@effect/vitest": "4.
|
|
57
|
+
"@effect/vitest": "4.1.1",
|
|
57
58
|
"@modelcontextprotocol/client": "2.3.1",
|
|
58
59
|
"@types/node": "26.6.5",
|
|
59
|
-
"effect": "4.
|
|
60
|
+
"effect": "4.1.1",
|
|
60
61
|
"oxfmt": "0.74.0",
|
|
61
|
-
"oxlint": "1.89.0",
|
|
62
62
|
"tsx": "4.23.15",
|
|
63
63
|
"typescript": "7.0.2",
|
|
64
64
|
"ultracite": "8.0.2",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"vitest": "5.0.5"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"effect": "~4.0
|
|
70
|
+
"effect": "~4.1.0"
|
|
71
71
|
},
|
|
72
72
|
"devEngines": {
|
|
73
73
|
"packageManager": {
|