@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.
Files changed (271) hide show
  1. package/README.md +7 -1
  2. package/dist/Action.d.mts +2 -2
  3. package/dist/Action.mjs +1 -0
  4. package/dist/ActionCli.mjs +0 -1
  5. package/dist/ActionHttp.d.mts +1 -1
  6. package/dist/ActionMcp.d.mts +0 -3
  7. package/dist/ActionMcp.mjs +0 -5
  8. package/dist/ActionRpc.d.mts +8 -15
  9. package/dist/ActionRpc.mjs +29 -54
  10. package/dist/ActionToolkit.d.mts +0 -2
  11. package/dist/ActionToolkit.mjs +0 -2
  12. package/dist/Event.d.mts +0 -23
  13. package/dist/Testing.mjs +3 -2
  14. package/dist/Webhook.mjs +2 -2
  15. package/dist/authentication/refusal.mjs +0 -1
  16. package/dist/cli/commands.mjs +0 -5
  17. package/dist/contract/authorizer.mjs +0 -5
  18. package/dist/contract/call.mjs +0 -23
  19. package/dist/contract/callback.mjs +0 -1
  20. package/dist/contract/caller.mjs +0 -11
  21. package/dist/contract/canonical.mjs +0 -5
  22. package/dist/contract/codec.d.mts +0 -1
  23. package/dist/contract/codec.mjs +0 -1
  24. package/dist/contract/codes.mjs +1 -15
  25. package/dist/contract/declared.mjs +0 -15
  26. package/dist/contract/digest.mjs +0 -1
  27. package/dist/contract/errors.d.mts +0 -4
  28. package/dist/contract/errors.mjs +0 -4
  29. package/dist/contract/feed.d.mts +0 -1
  30. package/dist/contract/feed.mjs +0 -20
  31. package/dist/contract/hints.mjs +0 -6
  32. package/dist/contract/hub.mjs +0 -3
  33. package/dist/contract/idempotency.mjs +0 -4
  34. package/dist/contract/implementation.d.mts +0 -1
  35. package/dist/contract/implementation.mjs +0 -27
  36. package/dist/contract/input-check.mjs +0 -1
  37. package/dist/contract/lease.mjs +0 -1
  38. package/dist/contract/listed.mjs +0 -6
  39. package/dist/contract/log.mjs +0 -8
  40. package/dist/contract/names.mjs +0 -1
  41. package/dist/contract/occurrence.mjs +0 -8
  42. package/dist/contract/pages.mjs +5 -12
  43. package/dist/contract/progress.mjs +2 -25
  44. package/dist/contract/push.d.mts +0 -5
  45. package/dist/contract/push.mjs +1 -24
  46. package/dist/contract/receiving.mjs +0 -7
  47. package/dist/contract/reported.mjs +0 -5
  48. package/dist/contract/serving.mjs +0 -18
  49. package/dist/contract/status.mjs +0 -3
  50. package/dist/contract/stream.mjs +0 -2
  51. package/dist/contract/subscribe.d.mts +0 -2
  52. package/dist/contract/subscribe.mjs +0 -8
  53. package/dist/contract/transient.mjs +0 -12
  54. package/dist/contract/watch.mjs +5 -17
  55. package/dist/contract/webhooks.mjs +0 -11
  56. package/dist/http/client.mjs +0 -1
  57. package/dist/http/events.d.mts +0 -10
  58. package/dist/http/events.mjs +2 -31
  59. package/dist/http/placed.d.mts +0 -2
  60. package/dist/http/streamed.d.mts +0 -1
  61. package/dist/http/streamed.mjs +4 -32
  62. package/dist/http/watch.mjs +0 -6
  63. package/dist/mcp/bridge.mjs +0 -25
  64. package/dist/mcp/client.d.mts +0 -1
  65. package/dist/mcp/client.mjs +0 -1
  66. package/dist/mcp/events.mjs +0 -6
  67. package/dist/mcp/progress.mjs +0 -7
  68. package/dist/mcp/protocol.mjs +0 -6
  69. package/dist/mcp/reply.mjs +0 -11
  70. package/dist/mcp/request.mjs +0 -1
  71. package/dist/mcp/watch.mjs +0 -6
  72. package/dist/rpc/watch.mjs +0 -6
  73. package/dist/stdio/console.mjs +2 -2
  74. package/dist/webhook/address.mjs +4 -9
  75. package/dist/webhook/attempt.mjs +2 -15
  76. package/dist/webhook/receiver.mjs +2 -8
  77. package/dist/webhook/signing.mjs +0 -3
  78. package/dist/webhook/stored.mjs +8 -17
  79. package/dist/webhook/subscriptions.mjs +19 -23
  80. package/docs/Action-streams.md +0 -12
  81. package/docs/Action.md +0 -10
  82. package/docs/ActionCli.md +2 -26
  83. package/docs/ActionHttp.md +0 -28
  84. package/docs/ActionMcp.md +2 -37
  85. package/docs/ActionRpc-events.md +0 -16
  86. package/docs/ActionRpc.md +0 -63
  87. package/docs/ActionToolkit.md +0 -11
  88. package/docs/Authentication-advanced.md +0 -31
  89. package/docs/Authentication.md +4 -13
  90. package/docs/Event.md +0 -37
  91. package/docs/README.md +1 -1
  92. package/docs/Testing.md +3 -13
  93. package/docs/Webhook.md +0 -46
  94. package/docs/setup.md +0 -5
  95. package/examples/README.md +7 -1
  96. package/examples/assistant/src/agent.ts +8 -31
  97. package/examples/assistant/src/cli.ts +2 -9
  98. package/examples/assistant/src/commands.ts +0 -8
  99. package/examples/assistant/src/identity/Identity.ts +0 -10
  100. package/examples/assistant/src/identity/authorize.ts +0 -4
  101. package/examples/assistant/src/identity/members.ts +1 -3
  102. package/examples/assistant/src/identity/permissions.ts +0 -5
  103. package/examples/assistant/src/platform/tasks-file.ts +1 -6
  104. package/examples/assistant/src/scripted.ts +0 -4
  105. package/examples/assistant/src/tasks/Tasks.ts +0 -2
  106. package/examples/assistant/src/tasks/handlers.ts +0 -3
  107. package/examples/assistant/src/tasks/store.ts +0 -7
  108. package/examples/assistant/src/toolkit.ts +0 -11
  109. package/examples/assistant/test/commands.test.ts +0 -5
  110. package/examples/assistant/test/identity/identity.test.ts +6 -6
  111. package/examples/assistant/test/platform/tasks-file.test.ts +2 -6
  112. package/examples/assistant/test/tasks/tasks.test.ts +13 -14
  113. package/examples/assistant/test/toolkit.test.ts +7 -18
  114. package/examples/build-events/README.md +2 -0
  115. package/examples/build-events/src/Api.ts +0 -3
  116. package/examples/build-events/src/Rpc.ts +0 -2
  117. package/examples/build-events/src/builds/Builds.ts +0 -15
  118. package/examples/build-events/src/builds/events.ts +0 -10
  119. package/examples/build-events/src/builds/handlers.ts +0 -6
  120. package/examples/build-events/src/builds/log.ts +0 -6
  121. package/examples/build-events/src/builds/status.ts +0 -4
  122. package/examples/build-events/src/builds/store.ts +0 -21
  123. package/examples/build-events/src/cli.ts +0 -2
  124. package/examples/build-events/src/commands.ts +0 -9
  125. package/examples/build-events/src/deploys/approvers.ts +0 -3
  126. package/examples/build-events/src/deploys/events.ts +0 -8
  127. package/examples/build-events/src/deploys/handlers.ts +0 -2
  128. package/examples/build-events/src/identity/Identity.ts +0 -11
  129. package/examples/build-events/src/identity/members.ts +1 -2
  130. package/examples/build-events/src/identity/verifier.ts +8 -9
  131. package/examples/build-events/src/notifier/Notices.ts +0 -3
  132. package/examples/build-events/src/notifier/routes.ts +0 -10
  133. package/examples/build-events/src/notifier.ts +0 -8
  134. package/examples/build-events/src/routes.ts +0 -24
  135. package/examples/build-events/src/server.ts +0 -14
  136. package/examples/build-events/test/builds/events.test.ts +0 -6
  137. package/examples/build-events/test/builds/log.test.ts +0 -1
  138. package/examples/build-events/test/builds/progress.test.ts +0 -1
  139. package/examples/build-events/test/commands.test.ts +0 -5
  140. package/examples/build-events/test/deploys/events.test.ts +0 -1
  141. package/examples/build-events/test/http.test.ts +0 -4
  142. package/examples/build-events/test/notifier.test.ts +0 -9
  143. package/examples/build-events/test/routes.test.ts +0 -9
  144. package/examples/build-events/test/rpc.test.ts +0 -4
  145. package/examples/build-events/test/support/as.ts +3 -4
  146. package/examples/build-events/test/support/memory.ts +0 -5
  147. package/examples/build-events/test/webhooks.test.ts +0 -12
  148. package/examples/kitchen-sink/README.md +1 -1
  149. package/examples/kitchen-sink/src/Actions.ts +0 -10
  150. package/examples/kitchen-sink/src/Api.ts +0 -8
  151. package/examples/kitchen-sink/src/Rpc.ts +0 -4
  152. package/examples/kitchen-sink/src/admin/Admin.ts +0 -9
  153. package/examples/kitchen-sink/src/admin/authenticate.ts +2 -6
  154. package/examples/kitchen-sink/src/admin/authorize.ts +0 -5
  155. package/examples/kitchen-sink/src/admin/grants.ts +0 -5
  156. package/examples/kitchen-sink/src/admin/handlers.ts +0 -2
  157. package/examples/kitchen-sink/src/admin/keys.ts +1 -3
  158. package/examples/kitchen-sink/src/agent.ts +2 -13
  159. package/examples/kitchen-sink/src/assistant/Assistant.ts +7 -24
  160. package/examples/kitchen-sink/src/assistant/conversations.ts +3 -21
  161. package/examples/kitchen-sink/src/assistant/demo-model.ts +0 -5
  162. package/examples/kitchen-sink/src/assistant/handlers.ts +1 -30
  163. package/examples/kitchen-sink/src/attachments/Attachments.ts +0 -4
  164. package/examples/kitchen-sink/src/attachments/download.ts +0 -10
  165. package/examples/kitchen-sink/src/attachments/handlers.ts +0 -3
  166. package/examples/kitchen-sink/src/attachments/store.ts +0 -3
  167. package/examples/kitchen-sink/src/browser.ts +0 -9
  168. package/examples/kitchen-sink/src/cli.ts +0 -19
  169. package/examples/kitchen-sink/src/config.ts +3 -11
  170. package/examples/kitchen-sink/src/identity/Identity.ts +0 -18
  171. package/examples/kitchen-sink/src/identity/authenticate.ts +3 -14
  172. package/examples/kitchen-sink/src/identity/authorize.ts +0 -6
  173. package/examples/kitchen-sink/src/identity/directory.ts +8 -18
  174. package/examples/kitchen-sink/src/identity/handlers.ts +0 -3
  175. package/examples/kitchen-sink/src/identity/members.ts +1 -5
  176. package/examples/kitchen-sink/src/identity/quota.ts +0 -11
  177. package/examples/kitchen-sink/src/issues/Issues.ts +0 -24
  178. package/examples/kitchen-sink/src/issues/assistant.ts +0 -10
  179. package/examples/kitchen-sink/src/issues/events.ts +2 -16
  180. package/examples/kitchen-sink/src/issues/export.ts +0 -5
  181. package/examples/kitchen-sink/src/issues/guide.ts +0 -5
  182. package/examples/kitchen-sink/src/issues/handlers.ts +0 -5
  183. package/examples/kitchen-sink/src/issues/store.ts +19 -23
  184. package/examples/kitchen-sink/src/issues/write-limit.ts +0 -12
  185. package/examples/kitchen-sink/src/memory.ts +0 -9
  186. package/examples/kitchen-sink/src/ops.ts +0 -6
  187. package/examples/kitchen-sink/src/request-policy.ts +0 -17
  188. package/examples/kitchen-sink/src/routes.ts +0 -48
  189. package/examples/kitchen-sink/src/sdk.ts +0 -12
  190. package/examples/kitchen-sink/src/seed.ts +0 -10
  191. package/examples/kitchen-sink/src/server.ts +0 -22
  192. package/examples/kitchen-sink/src/stdio.ts +2 -12
  193. package/examples/kitchen-sink/src/workspaces/Workspaces.ts +0 -4
  194. package/examples/kitchen-sink/src/workspaces/handlers.ts +0 -4
  195. package/examples/kitchen-sink/src/workspaces/registry.ts +0 -5
  196. package/examples/kitchen-sink/src/workspaces/tenant.ts +0 -4
  197. package/examples/kitchen-sink/test/admin/admin.test.ts +0 -1
  198. package/examples/kitchen-sink/test/assistant/assistant.test.ts +0 -18
  199. package/examples/kitchen-sink/test/attachments/attachments.test.ts +0 -9
  200. package/examples/kitchen-sink/test/identity/identity.test.ts +0 -10
  201. package/examples/kitchen-sink/test/identity/session.test.ts +0 -10
  202. package/examples/kitchen-sink/test/issues/assistant.test.ts +3 -7
  203. package/examples/kitchen-sink/test/issues/events.test.ts +2 -9
  204. package/examples/kitchen-sink/test/issues/export.test.ts +0 -3
  205. package/examples/kitchen-sink/test/issues/issues.test.ts +6 -12
  206. package/examples/kitchen-sink/test/request-policy.test.ts +0 -6
  207. package/examples/kitchen-sink/test/routes.test.ts +0 -6
  208. package/examples/kitchen-sink/test/support/as.ts +3 -5
  209. package/examples/kitchen-sink/test/support/scripted.ts +0 -3
  210. package/examples/kitchen-sink/test/support/services.ts +0 -3
  211. package/examples/live-rpc/src/Rpc.ts +0 -4
  212. package/examples/live-rpc/src/browser.ts +0 -24
  213. package/examples/live-rpc/src/chat/Chat.ts +0 -22
  214. package/examples/live-rpc/src/chat/authorize.ts +0 -3
  215. package/examples/live-rpc/src/chat/events.ts +0 -14
  216. package/examples/live-rpc/src/chat/handlers.ts +0 -5
  217. package/examples/live-rpc/src/chat/room.ts +0 -6
  218. package/examples/live-rpc/src/chat/store.ts +0 -9
  219. package/examples/live-rpc/src/client.ts +0 -6
  220. package/examples/live-rpc/src/identity/Identity.ts +0 -6
  221. package/examples/live-rpc/src/identity/members.ts +1 -3
  222. package/examples/live-rpc/src/identity/verifier.ts +6 -12
  223. package/examples/live-rpc/src/page.ts +0 -10
  224. package/examples/live-rpc/src/routes.ts +0 -13
  225. package/examples/live-rpc/src/server.ts +0 -16
  226. package/examples/live-rpc/test/browser.test.ts +0 -9
  227. package/examples/live-rpc/test/chat/chat.test.ts +3 -11
  228. package/examples/live-rpc/test/routes.test.ts +0 -8
  229. package/examples/live-rpc/test/server.test.ts +0 -13
  230. package/examples/mcp-tools/src/instructions.ts +0 -4
  231. package/examples/mcp-tools/src/platform/fake-farm.ts +0 -6
  232. package/examples/mcp-tools/src/platform/print-farm.ts +0 -16
  233. package/examples/mcp-tools/src/printers/Printers.ts +0 -21
  234. package/examples/mcp-tools/src/printers/farm.ts +0 -5
  235. package/examples/mcp-tools/src/printers/handlers.ts +0 -6
  236. package/examples/mcp-tools/src/routes.ts +0 -11
  237. package/examples/mcp-tools/src/server.ts +0 -9
  238. package/examples/mcp-tools/src/stdio.ts +1 -13
  239. package/examples/mcp-tools/test/printers/printers.test.ts +0 -10
  240. package/examples/mcp-tools/test/routes.test.ts +0 -14
  241. package/examples/notes-service/src/Api.ts +0 -4
  242. package/examples/notes-service/src/browser.ts +0 -12
  243. package/examples/notes-service/src/cli.ts +0 -2
  244. package/examples/notes-service/src/commands.ts +0 -30
  245. package/examples/notes-service/src/identity/Identity.ts +0 -2
  246. package/examples/notes-service/src/identity/authorize.ts +0 -4
  247. package/examples/notes-service/src/identity/users.ts +1 -3
  248. package/examples/notes-service/src/identity/verifier.ts +4 -11
  249. package/examples/notes-service/src/notes/Notes.ts +0 -12
  250. package/examples/notes-service/src/notes/handlers.ts +0 -4
  251. package/examples/notes-service/src/notes/store.ts +62 -48
  252. package/examples/notes-service/src/routes.ts +0 -12
  253. package/examples/notes-service/src/server.ts +0 -6
  254. package/examples/notes-service/src/status/Status.ts +0 -1
  255. package/examples/notes-service/src/status/handlers.ts +0 -1
  256. package/examples/notes-service/src/stdio.ts +2 -12
  257. package/examples/notes-service/src/worker.ts +0 -7
  258. package/examples/notes-service/test/commands.test.ts +0 -20
  259. package/examples/notes-service/test/notes/as.ts +3 -4
  260. package/examples/notes-service/test/notes/in-process.test.ts +3 -6
  261. package/examples/notes-service/test/notes/notes.test.ts +0 -6
  262. package/examples/notes-service/test/routes.test.ts +0 -5
  263. package/examples/notes-service/test/worker.test.ts +0 -1
  264. package/examples/quickstart/src/Api.ts +0 -1
  265. package/examples/quickstart/src/client.ts +0 -3
  266. package/examples/quickstart/src/greeting/Greeting.ts +0 -2
  267. package/examples/quickstart/src/greeting/handlers.ts +0 -1
  268. package/examples/quickstart/src/routes.ts +0 -1
  269. package/examples/quickstart/src/server.ts +3 -6
  270. package/examples/quickstart/test/routes.test.ts +0 -1
  271. package/package.json +2 -1
@@ -9,13 +9,6 @@ import { RpcSerialization, RpcServer } from "effect/rpc";
9
9
  import { MessageStore } from "./chat/store.js";
10
10
  import { rpc } from "./routes.js";
11
11
 
12
- // Entrypoint: `node --import tsx examples/live-rpc/src/server.ts`.
13
- // It chooses the protocol, the store and the port, and starts Node's HTTP server. It provides
14
- // no caller and no room: those arrive with each message.
15
-
16
- // The rpcs over a WebSocket at `/rpc`, the router's one route: Node's HTTP server answers the
17
- // upgrade. JSON, because a page's client speaks it: browser.ts gives its socket the same
18
- // serialization.
19
12
  const socket = rpc.pipe(
20
13
  Layer.provide(RpcServer.layerProtocolWebsocket({ path: "/rpc" })),
21
14
  Layer.provide(RpcSerialization.layerJson)
@@ -23,7 +16,6 @@ const socket = rpc.pipe(
23
16
 
24
17
  const server = Layer.unwrap(
25
18
  Effect.gen(function* () {
26
- // The loopback default serves this machine alone; HOST=0.0.0.0 lets others reach it.
27
19
  const host = yield* Config.String("HOST").pipe(
28
20
  Config.withDefault("127.0.0.1")
29
21
  );
@@ -35,18 +27,10 @@ const server = Layer.unwrap(
35
27
  NodeHttpServer.layer(createServer, {
36
28
  host,
37
29
  port,
38
- // A message on a WebSocket is no request body, so `HttpServerRequest.MaxBodySize`
39
- // does not bound it: Node's WebSocket server reads one of up to 100 MiB whole unless
40
- // told otherwise. A chat message is short, and a larger one closes the socket (1009).
41
30
  websocket: { maxPayload: 64 * 1024 },
42
31
  })
43
32
  ),
44
- // DEMO ONLY: messages live in this process's memory; a deployment provides a store that
45
- // lasts.
46
33
  Layer.provide(MessageStore.layerMemory),
47
- // The pages watching a room are this process's sockets, so what wakes them lives in its
48
- // memory too: one for the whole server. Several processes behind a balancer would each
49
- // wake only their own pages, the others reading a post at their next read, 5 seconds on.
50
34
  Layer.provide(Event.layerMemory)
51
35
  );
52
36
  })
@@ -11,9 +11,6 @@ import { MessageStore } from "../src/chat/store.js";
11
11
  import { chatOver } from "../src/page.js";
12
12
  import { rpc } from "../src/routes.js";
13
13
 
14
- // The page's client against the real rpcs, in memory, served as in routes.test.ts, NDJSON
15
- // included. `openChat` needs a client protocol and does not care which: a page gives it
16
- // `connection(url)`, a WebSocket, and this test Effect's HTTP protocol.
17
14
  const served = RpcClient.layerProtocolHttp({ url: "/rpc" }).pipe(
18
15
  Layer.provide(RpcSerialization.layerNdjson),
19
16
  Layer.provide(
@@ -108,8 +105,6 @@ describe("the page's client", () => {
108
105
 
109
106
  const { messages } = yield* lobby.read(0);
110
107
 
111
- // Posted after the page read and before it watches: the watch from the last id read
112
- // still sends it.
113
108
  yield* chat.room("lobby", "ada").post("Done.");
114
109
 
115
110
  const watched = yield* lobby
@@ -128,7 +123,6 @@ describe("the page's client", () => {
128
123
  Effect.gen(function* () {
129
124
  const chat = yield* openChat;
130
125
 
131
- // As after a restart emptied the demo's memory store: the page holds id 7.
132
126
  const watching = yield* chat
133
127
  .room("lobby", "grace")
134
128
  .messages(7)
@@ -144,8 +138,6 @@ describe("the page's client", () => {
144
138
  }).pipe(Effect.provide(served))
145
139
  );
146
140
 
147
- // `connect(url)` is this with a WebSocket. Each test's runtime builds its own layer, and so
148
- // its own store.
149
141
  it("answers a page that is not an Effect program with promises, until it closes", async () => {
150
142
  const chat = chatOver(served);
151
143
 
@@ -171,7 +163,6 @@ describe("the page's client", () => {
171
163
  { name: "lobby", messages: 1 },
172
164
  ]);
173
165
 
174
- // A failure `openChat` does not handle rejects: here, a text the contract refuses.
175
166
  await expect(chat.room("lobby", "ada").post("")).rejects.toBeInstanceOf(
176
167
  Action.InvalidInput
177
168
  );
@@ -10,15 +10,11 @@ import { messages } from "../../src/chat/handlers.js";
10
10
  import { CurrentRoom } from "../../src/chat/room.js";
11
11
  import { MessageStore } from "../../src/chat/store.js";
12
12
  import { CurrentMember } from "../../src/identity/Identity.js";
13
- import { members } from "../../src/identity/members.js";
13
+ import { demoMembers } from "../../src/identity/members.js";
14
14
 
15
- // What the implementation does, with no transport: `Action.client` runs the same decoding,
16
- // `authorize` and handler a server runs. No authentication and no middleware run here, so
17
- // each call is given what they would provide: its caller and its room. Neither is provided
18
- // around the client or beside the store: a request-time service belongs to one call.
19
- const as = (member: keyof typeof members, room: string) =>
15
+ const as = (member: keyof typeof demoMembers, room: string) =>
20
16
  flow(
21
- Effect.provideService(CurrentMember, members[member]),
17
+ Effect.provideService(CurrentMember, demoMembers[member]),
22
18
  Effect.provideService(CurrentRoom, room)
23
19
  );
24
20
 
@@ -122,14 +118,12 @@ describe("messages, in process", () => {
122
118
  Effect.forkChild
123
119
  );
124
120
 
125
- // The watch starts from now: let it take its first position before anyone posts.
126
121
  yield* TestClock.adjust("0 millis");
127
122
  yield* client
128
123
  .postMessage({ text: "Disk is full." })
129
124
  .pipe(as("ada", "ops"));
130
125
  yield* client.postMessage({ text: "Ready." }).pipe(as("ada", "lobby"));
131
126
 
132
- // `postMessage` notifies: the watch reads at once, with no wait for its next read.
133
127
  expect(yield* Fiber.join(watching)).toMatchObject([
134
128
  {
135
129
  _tag: "Occurrence",
@@ -166,7 +160,6 @@ describe("messages, in process", () => {
166
160
 
167
161
  const received = [...(yield* firstReceived), ...(yield* firstReceived)];
168
162
 
169
- // Both are the room's message 1, and a watch that saw the first still reads the second.
170
163
  expect(received).toMatchObject([
171
164
  { data: { id: 1 } },
172
165
  { data: { id: 1 } },
@@ -204,7 +197,6 @@ describe("messages, in process", () => {
204
197
 
205
198
  yield* client.postMessage({ text: "Ready." }).pipe(as("ada", "lobby"));
206
199
 
207
- // An event's id, such as `<epoch>:lobby:1`, is no cursor: the cursor is `<epoch>:<id>`.
208
200
  const received = yield* client
209
201
  .watch(MessagePosted, {}, { cursor: "lobby:1" })
210
202
  .pipe(Stream.take(1), Stream.runCollect, as("grace", "lobby"));
@@ -12,10 +12,6 @@ import { MessageStore } from "../src/chat/store.js";
12
12
  import { rpc } from "../src/routes.js";
13
13
  import { Rpc } from "../src/Rpc.js";
14
14
 
15
- // What the wire adds: the real rpcs, behind their real authentication and middleware,
16
- // answering in memory. The test gives them Effect's HTTP protocol, not the server's WebSocket,
17
- // because `Testing.layer` answers HTTP requests; no port is opened. NDJSON, not JSON: over
18
- // HTTP, JSON sends a response once all its streams end, so a watch would never answer.
19
15
  const server = rpc.pipe(
20
16
  Layer.provide(RpcServer.layerProtocolHttp({ path: "/rpc" })),
21
17
  Layer.provide(RpcSerialization.layerNdjson)
@@ -27,7 +23,6 @@ const served = RpcClient.layerProtocolHttp({ url: "/rpc" }).pipe(
27
23
  Layer.provide([MessageStore.layerMemory, Event.layerMemory])
28
24
  );
29
25
 
30
- // Each call carries its caller's token, so one client serves every caller of a test.
31
26
  const as = (token: string) =>
32
27
  RpcClient.withHeaders({ authorization: `Bearer ${token}` });
33
28
 
@@ -134,7 +129,6 @@ describe("the chat, over RPC", () => {
134
129
  Effect.forkChild
135
130
  );
136
131
 
137
- // Let the watch take its position through the in-memory socket before anyone posts.
138
132
  yield* Effect.repeat(TestClock.adjust("0 millis"), { times: 10 });
139
133
  yield* client
140
134
  .postMessage({ text: "Disk is full." })
@@ -174,8 +168,6 @@ describe("the chat, over RPC", () => {
174
168
  "serves a native RpcGroup: Effect's own client calls the same rpcs",
175
169
  () =>
176
170
  Effect.gen(function* () {
177
- // `Rpc.group` is what Effect's RPC tooling takes. Its methods take the payload as sent,
178
- // `{}` included; `ActionRpc.client` is the one to write an application with.
179
171
  const native = yield* RpcClient.make(Rpc.group);
180
172
 
181
173
  expect(yield* native.listRooms({})).toStrictEqual({ rooms: [] });
@@ -11,23 +11,17 @@ import { MessageStore } from "../src/chat/store.js";
11
11
  import { connect } from "../src/page.js";
12
12
  import { rpc } from "../src/routes.js";
13
13
 
14
- // What the socket adds, which no in-memory test reaches: the upgrade, the page's `connect(url)`
15
- // and the bound on a message. The rpcs are served as server.ts serves them, over a WebSocket
16
- // at `/rpc` on Node's HTTP server, on port 0: the system picks a free one, so tests run side
17
- // by side. The server closes with the test's scope.
18
14
  const socket = rpc.pipe(
19
15
  Layer.provide(RpcServer.layerProtocolWebsocket({ path: "/rpc" })),
20
16
  Layer.provide(RpcSerialization.layerJson)
21
17
  );
22
18
 
23
- // server.ts allows 64 KiB. A bound this small is passed by a message the contract accepts.
24
19
  const maxPayload = 256;
25
20
 
26
21
  const listening = HttpRouter.serve(socket, {
27
22
  disableLogger: true,
28
23
  disableListenLog: true,
29
24
  }).pipe(
30
- // `provideMerge` keeps `HttpServer` for the test, which reads the port from it.
31
25
  Layer.provideMerge(
32
26
  NodeHttpServer.layer(createServer, {
33
27
  host: "127.0.0.1",
@@ -38,8 +32,6 @@ const listening = HttpRouter.serve(socket, {
38
32
  Layer.provide([MessageStore.layerMemory, Event.layerMemory])
39
33
  );
40
34
 
41
- // The page's client, on Node's global `WebSocket`. Each test closes it with `Effect.scoped`,
42
- // before the server stops: a server that is stopping waits for its open sockets.
43
35
  const chat = Effect.gen(function* () {
44
36
  const server = yield* HttpServer.HttpServer;
45
37
  const url = HttpServer.formatAddress(server.address).replace("http", "ws");
@@ -88,8 +80,6 @@ describe("the chat, over a WebSocket", () => {
88
80
  const received = yield* Deferred.make<string>();
89
81
  const stopped = yield* Deferred.make<string>();
90
82
 
91
- // From the room's start, id 0, so the post reaches it however soon after the watch it is
92
- // sent.
93
83
  const stop = page.room("lobby", "grace").watch(
94
84
  0,
95
85
  (message) => {
@@ -123,9 +113,6 @@ describe("the chat, over a WebSocket", () => {
123
113
 
124
114
  yield* Effect.promise(async () => await ada.post("Short."));
125
115
 
126
- // 400 characters are a text the contract accepts and a message over 256 bytes. The server
127
- // reads none of it: it closes the socket with 1009, "message too big", and the call fails
128
- // with Effect's `RpcClientError`, its reason the socket's close, which no action declares.
129
116
  yield* Effect.promise(async () => {
130
117
  await expect(ada.post("x".repeat(400))).rejects.toMatchObject({
131
118
  reason: { code: 1009 },
@@ -1,7 +1,3 @@
1
- // What the server tells a client of itself, on either transport: `server.ts` and `stdio.ts`
2
- // both give it. `instructions` are for the model, as the tools' descriptions are: what the
3
- // tools are for together, and what to be careful with. A client shows them to the model once,
4
- // when it connects.
5
1
  export const serverInfo = {
6
2
  name: "print-farm",
7
3
  version: "1.0.0",
@@ -5,12 +5,6 @@ import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
5
5
 
6
6
  import type { Printer } from "../printers/Printers.js";
7
7
 
8
- // DEMO ONLY: the farm's HTTP API answered in memory, so the example and its tests run without
9
- // a farm. It is an `HttpClient`, so `printFarm` sends it the requests it would send over
10
- // the network. A real application has no such file: its entrypoints provide a real client,
11
- // `FetchHttpClient.layer` from `effect/http`.
12
-
13
- // A one-pixel PNG stands in for a camera's picture.
14
8
  export const picture = Uint8Array.from(
15
9
  Buffer.from(
16
10
  "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",
@@ -14,13 +14,8 @@ const fail = (message: string) => Effect.fail(new PrintFarmError({ message }));
14
14
 
15
15
  const unreadable = "The print farm sent an answer this server could not read.";
16
16
 
17
- // An id is written into the path as it is: the contract admits only letters, digits,
18
- // `_` and `-`, so it is always one segment. Encoding would not make other text safe:
19
- // `encodeURIComponent` leaves `..` alone, and a URL parser then walks up the path.
20
17
  const at = (id: string, rest = "") => `/api/printers/${id}${rest}`;
21
18
 
22
- // The farm answers a request it refuses with a status that is not 2xx and `{ "error": "..." }`.
23
- // Its reason is passed on to the model, which can act on "The printer is busy with a job".
24
19
  const refuseUnlessOk = HttpClientResponse.matchStatus({
25
20
  "2xx": (response) => Effect.succeed(response),
26
21
  orElse: (response) =>
@@ -35,9 +30,6 @@ const refuseUnlessOk = HttpClientResponse.matchStatus({
35
30
  ),
36
31
  });
37
32
 
38
- // Every other way a call to the farm fails, as the same declared error: no connection, an
39
- // answer of another shape than expected, or none in time. Nothing of the HTTP client's own
40
- // errors leaves this file, so no tool can fail with something its contract does not declare.
41
33
  const asPrintFarmError = <A>(
42
34
  effect: Effect.Effect<
43
35
  A,
@@ -71,10 +63,6 @@ const asImage = (response: HttpClientResponse.HttpClientResponse) =>
71
63
  return { data: new Uint8Array(yield* response.arrayBuffer), mimeType };
72
64
  });
73
65
 
74
- // Built once, when the process starts. It requires an `HttpClient` and reads its settings
75
- // from `Config`: the entrypoint decides which client, and the environment says which farm.
76
- // Not `fetch`: as a service, a test replaces the network alone and opens no port
77
- // (test/printers/printers.test.ts).
78
66
  export const printFarm = Layer.effect(
79
67
  PrintFarm,
80
68
  Effect.gen(function* () {
@@ -89,10 +77,6 @@ export const printFarm = Layer.effect(
89
77
  HttpClient.transformResponse(Effect.flatMap(refuseUnlessOk))
90
78
  );
91
79
 
92
- // Signs in once, here, and every call below reuses the token, kept `Redacted` so no log
93
- // prints it. A farm that refuses the sign-in stops the process at startup, with its
94
- // reason, before any tool is listed. A real client also signs in again when a call
95
- // answers 401, as tokens expire.
96
80
  const session = yield* http
97
81
  .post("/api/login", {
98
82
  body: HttpBody.jsonUnsafe({ user, password: Redacted.value(password) }),
@@ -17,9 +17,6 @@ export const Printer = Schema.Struct({
17
17
 
18
18
  export type Printer = typeof Printer.Type;
19
19
 
20
- // The one error every tool declares: the farm could not do what was asked. A model reads its
21
- // `message` and decides what to do next, so the message says what went wrong in plain words.
22
- // A handler failing with an error its action does not declare does not compile.
23
20
  export class PrintFarmError extends Schema.TaggedError<
24
21
  PrintFarmError,
25
22
  { readonly brand: unique symbol }
@@ -27,27 +24,14 @@ export class PrintFarmError extends Schema.TaggedError<
27
24
  message: Schema.String,
28
25
  }) {}
29
26
 
30
- // A field's description is part of the tool's input schema, which is all a model knows of it.
31
- // The pattern is there for safety: an id becomes a segment of the farm's URL, and it comes
32
- // from a model. An id that does not match is refused as invalid input, on every surface,
33
- // before a handler runs, so `..` or `a/b` never reaches the farm. The `u` flag is what puts the
34
- // pattern in the tool's schema, where the model reads it.
35
27
  const PrinterId = Schema.String.check(
36
28
  Schema.isPattern(/^[A-Za-z0-9_-]+$/u)
37
29
  ).annotate({
38
30
  description: "A printer's id, as list_printers gives it, such as mk4-1.",
39
31
  });
40
32
 
41
- // What every tool here shares. `caller: Action.Anyone` makes an action public: this server
42
- // authenticates nobody, so it is reachable by whoever can reach the process.
43
33
  const tool = { caller: Action.Anyone, error: PrintFarmError } as const;
44
34
 
45
- // The names are snake_case because this server is tools only, and that is the convention MCP
46
- // tool names usually follow. An application whose actions are also typed client methods or CLI
47
- // commands names them in camelCase, as notes-service does.
48
- //
49
- // A description is written for the model that picks the tool: what it does, when to call it,
50
- // and what it answers.
51
35
  export const ListPrinters = Action.make("list_printers", {
52
36
  ...tool,
53
37
  description:
@@ -59,7 +43,6 @@ export const ListPrinters = Action.make("list_printers", {
59
43
  mcp: { title: "List printers" },
60
44
  });
61
45
 
62
- // `image` is an `Action.Image`, so a model sees the picture rather than reading its base64.
63
46
  export const GetCameraSnapshot = Action.make("get_camera_snapshot", {
64
47
  ...tool,
65
48
  description:
@@ -72,8 +55,6 @@ export const GetCameraSnapshot = Action.make("get_camera_snapshot", {
72
55
  mcp: { title: "Camera snapshot" },
73
56
  });
74
57
 
75
- // Destructive, MCP's default for a write: a print sets a machine to work and spends material,
76
- // which is more than adding a record. A second call is refused, so it is not idempotent.
77
58
  export const StartPrint = Action.make("start_print", {
78
59
  ...tool,
79
60
  description:
@@ -90,7 +71,6 @@ export const StartPrint = Action.make("start_print", {
90
71
  mcp: { title: "Start a print" },
91
72
  });
92
73
 
93
- // Idempotent: the same call again leaves the printer as the first left it.
94
74
  export const SetPaused = Action.make("set_paused", {
95
75
  ...tool,
96
76
  description:
@@ -104,7 +84,6 @@ export const SetPaused = Action.make("set_paused", {
104
84
  },
105
85
  success: Printer,
106
86
  readOnly: false,
107
- // Destructive, MCP's default for a write: a pause interrupts a running print.
108
87
  mcp: { title: "Pause or resume a print", idempotentHint: true },
109
88
  });
110
89
 
@@ -4,11 +4,6 @@ import type { Effect } from "effect";
4
4
 
5
5
  import type { Printer, PrintFarmError } from "./Printers.js";
6
6
 
7
- /**
8
- * The print farm, the one upstream of this server. Its methods require nothing and fail only
9
- * with the error the tools declare: its layer, `printFarm` in src/platform/print-farm.ts, has
10
- * captured the HTTP client, the farm's URL and the session.
11
- */
12
7
  export class PrintFarm extends Context.Service<
13
8
  PrintFarm,
14
9
  {
@@ -4,11 +4,6 @@ import { Effect } from "effect";
4
4
  import { PrintFarm } from "./farm.js";
5
5
  import { Printers } from "./Printers.js";
6
6
 
7
- // The builder runs once, when the server starts, whichever transport serves the tools: it is
8
- // where the handlers get the farm, already signed in. Each handler is a step from a tool's
9
- // input to the service and back to the tool's success. None handles a failure: the service
10
- // fails only with `PrintFarmError`, which every tool declares, so it reaches the model as is.
11
- // Public actions take no `authorize`.
12
7
  export const printers = Action.implement(
13
8
  Printers,
14
9
  Effect.gen(function* () {
@@ -17,7 +12,6 @@ export const printers = Action.implement(
17
12
  return {
18
13
  list_printers: () =>
19
14
  Effect.map(farm.printers, (all) => ({ printers: all })),
20
- // Returned as `{ data, mimeType }` like any other field: the MCP surface makes the block.
21
15
  get_camera_snapshot: ({ printer_id }) =>
22
16
  Effect.all(
23
17
  {
@@ -5,23 +5,13 @@ import { HttpRouter, HttpServerResponse } from "effect/http";
5
5
  import { serverInfo } from "./instructions.js";
6
6
  import { printers } from "./printers/handlers.js";
7
7
 
8
- // The tools at `/mcp` and the host's own route beside them. It is a Layer built from `Config`
9
- // because the origins are known only where the server is deployed.
10
8
  export const routes = Layer.unwrap(
11
9
  Effect.gen(function* () {
12
- // A browser sends its page's `Origin`, and the endpoint refuses every origin not listed
13
- // here, so a web page a user happens to visit cannot call the tools. Other MCP clients
14
- // send none and pass. `ALLOWED_ORIGINS=https://a.example,https://b.example`; none by default.
15
10
  const allowedOrigins = yield* Config.Array(
16
11
  Schema.String,
17
12
  "ALLOWED_ORIGINS"
18
13
  ).pipe(Config.withDefault([]));
19
14
 
20
- // The Origin check only refuses. A browser also needs CORS: an answer to its preflight, and
21
- // headers on the endpoint's answers. `HttpRouter.cors` is global to the router and, given
22
- // no origin, allows every one, so it is added only where an origin is configured. The
23
- // methods are the endpoint's, the headers those an MCP client sends and must be able to
24
- // read; an endpoint with authentication adds `Authorization` and exposes `WWW-Authenticate`.
25
15
  const cors =
26
16
  allowedOrigins.length === 0
27
17
  ? Layer.empty
@@ -39,7 +29,6 @@ export const routes = Layer.unwrap(
39
29
  });
40
30
 
41
31
  return Layer.mergeAll(
42
- // No `authentication`: every tool is public, so the endpoint authenticates nothing.
43
32
  ActionMcp.layerHttp(printers, { ...serverInfo, allowedOrigins }),
44
33
  HttpRouter.add("GET", "/healthz", HttpServerResponse.text("ok"))
45
34
  ).pipe(Layer.provide(cors));
@@ -8,11 +8,6 @@ import { fakeFarm } from "./platform/fake-farm.js";
8
8
  import { printFarm } from "./platform/print-farm.js";
9
9
  import { routes } from "./routes.js";
10
10
 
11
- // Entrypoint: `node --import tsx examples/mcp-tools/src/server.ts`, with FARM_URL, FARM_USER
12
- // and FARM_PASSWORD set. MCP over HTTP, for clients that connect to a URL.
13
- // These tools are public: no route asks for a token, so where the server listens is its access
14
- // control, the loopback interface by default or a network only trusted clients are on. Tools
15
- // that need a caller are protected as docs/ActionMcp.md's "Protect tools" shows.
16
11
  const server = Layer.unwrap(
17
12
  Effect.gen(function* () {
18
13
  const host = yield* Config.String("HOST").pipe(
@@ -23,13 +18,9 @@ const server = Layer.unwrap(
23
18
 
24
19
  return HttpRouter.serve(routes).pipe(
25
20
  Layer.provide(NodeHttpServer.layer(createServer, { host, port })),
26
- // Request bodies have no size limit unless the host sets one. A tool call is a few
27
- // short fields, so anything larger is not one.
28
21
  Layer.provide(
29
22
  Layer.succeed(HttpServerRequest.MaxBodySize, ByteSize.kibibytes(64))
30
23
  ),
31
- // DEMO ONLY: `fakeFarm` answers the farm's API in memory. A real server provides
32
- // `FetchHttpClient.layer` in its place, and `printFarm` calls the farm at FARM_URL.
33
24
  Layer.provide(printFarm.pipe(Layer.provide(fakeFarm)))
34
25
  );
35
26
  })
@@ -8,20 +8,8 @@ import { fakeFarm } from "./platform/fake-farm.js";
8
8
  import { printFarm } from "./platform/print-farm.js";
9
9
  import { printers } from "./printers/handlers.js";
10
10
 
11
- // Entrypoint: an MCP server a local agent starts as a subprocess, with FARM_URL, FARM_USER and
12
- // FARM_PASSWORD in its environment. The README has the line that adds it to Claude Code and
13
- // its entry in Claude Desktop's configuration.
14
- // The same implementation and the same server information as the HTTP server, and no port:
15
- // the agent's host starts the process, writes requests to its stdin, and closes it to stop it.
16
11
  ActionMcp.runStdio(printers, serverInfo).pipe(
17
- Effect.provide([
18
- NodeStdio.layer,
19
- // DEMO ONLY: `fakeFarm` answers the farm's API in memory. A real server provides
20
- // `FetchHttpClient.layer` in its place.
21
- printFarm.pipe(Layer.provide(fakeFarm)),
22
- ]),
23
- // stdout carries the protocol alone. Applied last, this sends every log to stderr, the
24
- // sign-in line `printFarm` logs included, and a startup failure too.
12
+ Effect.provide([NodeStdio.layer, printFarm.pipe(Layer.provide(fakeFarm))]),
25
13
  ActionCli.logToStderr,
26
14
  NodeRuntime.runMain()
27
15
  );
@@ -10,11 +10,6 @@ import { printFarm } from "../../src/platform/print-farm.js";
10
10
  import { printers } from "../../src/printers/handlers.js";
11
11
  import { PrintFarmError } from "../../src/printers/Printers.js";
12
12
 
13
- // What the tools do, with no transport: `Action.client` runs the same decoding and the same
14
- // handlers a server runs. A public action has no caller, so a call needs none provided.
15
-
16
- // The real `PrintFarm` over an upstream of the test's: its requests, its sign-in and its error
17
- // mapping all run, and only the network is replaced. Its settings come from a Layer too.
18
13
  const farmOver = (upstream: Layer.Layer<HttpClient.HttpClient>) =>
19
14
  printFarm.pipe(
20
15
  Layer.provide(upstream),
@@ -29,8 +24,6 @@ const farmOver = (upstream: Layer.Layer<HttpClient.HttpClient>) =>
29
24
  )
30
25
  );
31
26
 
32
- // The fake farm, noting each request the service sends it. A request is noted as the service
33
- // wrote it, before its client prepends FARM_URL, so the paths are relative.
34
27
  const noting = (sent: string[]) =>
35
28
  Layer.effect(
36
29
  HttpClient.HttpClient,
@@ -42,7 +35,6 @@ const noting = (sent: string[]) =>
42
35
  )
43
36
  ).pipe(Layer.provide(fakeFarm));
44
37
 
45
- // A farm that lets the service sign in, then answers every other request with `answer`.
46
38
  const farmThat = (
47
39
  answer: (
48
40
  request: HttpClientRequest.HttpClientRequest
@@ -142,7 +134,6 @@ describe("printers, in process", () => {
142
134
  }
143
135
  );
144
136
 
145
- // The message is all a model gets of a failure, so each test asserts it.
146
137
  it.effect(
147
138
  "fails with the declared error, carrying the farm's own reason",
148
139
  () =>
@@ -214,7 +205,6 @@ describe("printers, in process", () => {
214
205
  )
215
206
  );
216
207
 
217
- // `it.effect` runs on a test clock, so the thirty seconds pass when the test says so.
218
208
  it.effect("gives up on a farm that does not answer", () =>
219
209
  Effect.gen(function* () {
220
210
  const client = yield* Action.client(printers);
@@ -9,17 +9,12 @@ import { printFarm } from "../src/platform/print-farm.js";
9
9
  import { PrintFarmError, Printers } from "../src/printers/Printers.js";
10
10
  import { routes } from "../src/routes.js";
11
11
 
12
- // What the MCP surface adds: the tools as listed, their results as sent, the origin check.
13
- // The real routes answer in memory, and no port is opened.
14
-
15
- // What the entrypoint reads from the environment, given to the test as a Layer.
16
12
  const farm = {
17
13
  FARM_URL: "https://farm.example.test",
18
14
  FARM_USER: "agent",
19
15
  FARM_PASSWORD: "secret",
20
16
  };
21
17
 
22
- // The fake farm goes to `printFarm` alone, so the test's own requests still reach the routes.
23
18
  const servedWith = (environment: Record<string, string>) =>
24
19
  Testing.layer(routes).pipe(
25
20
  Layer.provide(printFarm.pipe(Layer.provide(fakeFarm))),
@@ -33,7 +28,6 @@ const served = servedWith({
33
28
  ALLOWED_ORIGINS: "https://console.example.test,https://wall.example.test",
34
29
  });
35
30
 
36
- // A browser's preflight: what it asks before a cross-origin `POST` with an MCP client's headers.
37
31
  const preflight = (origin: string) =>
38
32
  HttpClient.execute(
39
33
  HttpClientRequest.make("OPTIONS")("/mcp", {
@@ -45,7 +39,6 @@ const preflight = (origin: string) =>
45
39
  })
46
40
  );
47
41
 
48
- // One tool of a `tools/list` answer, as far as this test reads it.
49
42
  const Listed = Schema.Struct({
50
43
  result: Schema.Struct({
51
44
  tools: Schema.Array(
@@ -80,7 +73,6 @@ const from = (origin: string) =>
80
73
  describe("the tools, over MCP", () => {
81
74
  it.effect("lists every tool with its title and hints as sent", () =>
82
75
  Effect.gen(function* () {
83
- // A raw request, for what no typed client shows: here, the listing itself.
84
76
  const response = yield* HttpClient.execute(
85
77
  ActionMcp.request("tools/list")
86
78
  );
@@ -121,8 +113,6 @@ describe("the tools, over MCP", () => {
121
113
 
122
114
  it.effect("answers a camera's picture as an image beside the printer", () =>
123
115
  Effect.gen(function* () {
124
- // A client method per tool: it sends `tools/call` and decodes the result, the image
125
- // from its image block, as the handler returned it.
126
116
  const mcp = yield* ActionMcp.client(Printers);
127
117
 
128
118
  expect(
@@ -200,7 +190,6 @@ describe("the tools, over MCP", () => {
200
190
  "Mcp-Session-Id"
201
191
  );
202
192
 
203
- // Two origins are configured, so each request's own is compared with the list.
204
193
  expect(
205
194
  (yield* preflight("https://elsewhere.example.test")).headers
206
195
  ).not.toHaveProperty("access-control-allow-origin");
@@ -211,9 +200,6 @@ describe("the tools, over MCP", () => {
211
200
  "names its one configured origin to every preflight, and still refuses any other",
212
201
  () =>
213
202
  Effect.gen(function* () {
214
- // With exactly one origin, Effect's CORS compares nothing: the header is that origin
215
- // whoever asks. A page elsewhere is still refused, twice: its browser reads an origin
216
- // that is not its own, and the endpoint answers its request 403.
217
203
  const asked = yield* preflight("https://elsewhere.example.test");
218
204
 
219
205
  expect(asked.status).toBe(204);
@@ -4,10 +4,6 @@ import { Login, WhoAmI } from "./identity/Identity.js";
4
4
  import { Notes } from "./notes/Notes.js";
5
5
  import { GetStatus } from "./status/Status.js";
6
6
 
7
- // The HTTP binding: every action at `POST /api/<name>`, the protected ones requiring `Login`.
8
- // It is plain data and imports no server code, so the server, the CLI and a browser page all
9
- // import this one value, and each gets its routes or its typed methods from it. An action
10
- // added here is also a `notes` command: commands.ts derives one per action of this binding.
11
7
  export const Http = ActionHttp.make([GetStatus, ...Notes, WhoAmI], {
12
8
  prefix: "/api",
13
9
  authentication: Login,
@@ -5,13 +5,7 @@ import { HttpClient, HttpClientRequest } from "effect/http";
5
5
  import { Http } from "./Api.js";
6
6
  import type { Note } from "./notes/Notes.js";
7
7
 
8
- // Client module: what a web page imports. It holds the binding and nothing of the server, so a
9
- // bundler gets the contracts and Effect's fetch client, and no handler.
10
- //
11
- // Without `baseUrl` the routes are called on the page's own origin. A page served elsewhere
12
- // passes the API's URL, and the server must then allow its origin (CORS).
13
8
  export const connect = (token: string, baseUrl?: string) => {
14
- // Built once, outside any Effect. Every method is typed from its action.
15
9
  const api = ActionHttp.fetchClient(Http, {
16
10
  transformClient: HttpClient.mapRequest(
17
11
  HttpClientRequest.bearerToken(token)
@@ -19,21 +13,15 @@ export const connect = (token: string, baseUrl?: string) => {
19
13
  ...(baseUrl === undefined ? {} : { baseUrl }),
20
14
  });
21
15
 
22
- // Each method returns a promise. A failure rejects it with the decoded error, so in a `catch`
23
- // `error instanceof Action.Unauthenticated` tells an expired sign-in from anything else.
24
16
  return {
25
17
  notes: async () => await Effect.runPromise(api.listNotes()),
26
18
 
27
- // A declared error can also be handled by its tag before the promise: a missing note is
28
- // `undefined` here, and every other failure still rejects.
29
19
  note: async (id: string): Promise<Note | undefined> =>
30
20
  await api.getNote({ id }).pipe(
31
21
  Effect.catchTag("NoteNotFound", () => Effect.undefined),
32
22
  Effect.runPromise
33
23
  ),
34
24
 
35
- // A stale revision is refused, never overwritten: the error, `NoteChanged`, carries the
36
- // current one.
37
25
  save: async (note: Note, body: string) =>
38
26
  await Effect.runPromise(
39
27
  api.updateNote({ id: note.id, body, revision: note.revision })
@@ -9,8 +9,6 @@ import { Command } from "effect/cli";
9
9
 
10
10
  import { commands } from "./commands.js";
11
11
 
12
- // Entrypoint: `node --import tsx examples/notes-service/src/cli.ts list-notes`.
13
- // The commands of commands.ts, which read where the server is and the token when one runs.
14
12
  Command.run(commands, { version: "1.0.0" }).pipe(
15
13
  Effect.provide([NodeHttpClient.layerUndici, NodeServices.layer]),
16
14
  ActionCli.logToStderr,