@gjermundgaraba/effect-actions 0.11.0 → 0.12.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 (215) hide show
  1. package/README.md +101 -40
  2. package/dist/Action.d.mts +29 -117
  3. package/dist/Action.mjs +14 -53
  4. package/dist/ActionCli.d.mts +60 -28
  5. package/dist/ActionCli.mjs +54 -48
  6. package/dist/ActionHttp.d.mts +18 -67
  7. package/dist/ActionHttp.mjs +20 -70
  8. package/dist/ActionMcp.d.mts +23 -29
  9. package/dist/ActionMcp.mjs +56 -114
  10. package/dist/ActionRpc.d.mts +147 -0
  11. package/dist/ActionRpc.mjs +113 -0
  12. package/dist/ActionToolkit.d.mts +5 -8
  13. package/dist/ActionToolkit.mjs +3 -3
  14. package/dist/Authentication.d.mts +15 -15
  15. package/dist/Authentication.mjs +42 -96
  16. package/dist/Testing.d.mts +28 -23
  17. package/dist/Testing.mjs +27 -44
  18. package/dist/{internal/authentication.d.mts → authentication/provider.d.mts} +41 -9
  19. package/dist/authentication/provider.mjs +12 -0
  20. package/dist/authentication/refusal.mjs +36 -0
  21. package/dist/{internal/cli.d.mts → cli/commands.d.mts} +16 -12
  22. package/dist/cli/commands.mjs +302 -0
  23. package/dist/{internal → contract}/call.d.mts +2 -2
  24. package/dist/contract/call.mjs +10 -0
  25. package/dist/{internal → contract}/errors.d.mts +13 -10
  26. package/dist/{internal → contract}/errors.mjs +9 -14
  27. package/dist/{internal → contract}/implementation.d.mts +37 -21
  28. package/dist/{internal → contract}/implementation.mjs +18 -49
  29. package/dist/contract/media.d.mts +13 -0
  30. package/dist/contract/media.mjs +18 -0
  31. package/dist/contract/rules.d.mts +25 -0
  32. package/dist/{internal/actions.mjs → contract/rules.mjs} +6 -42
  33. package/dist/{internal → http}/client.d.mts +7 -9
  34. package/dist/http/client.mjs +17 -0
  35. package/dist/http/declared.mjs +20 -0
  36. package/dist/http/schema-errors.mjs +9 -0
  37. package/dist/mcp/protocol.d.mts +17 -0
  38. package/dist/{internal/mcp.mjs → mcp/protocol.mjs} +29 -62
  39. package/dist/stdio/console.mjs +64 -0
  40. package/dist/{internal → testing}/memory.d.mts +1 -1
  41. package/dist/{internal → testing}/memory.mjs +5 -17
  42. package/dist/toolkit/tools.mjs +29 -0
  43. package/docs/Action-failures.md +47 -0
  44. package/docs/Action-in-process.md +93 -0
  45. package/docs/Action.md +206 -426
  46. package/docs/ActionCli-failures.md +102 -0
  47. package/docs/ActionCli.md +206 -293
  48. package/docs/ActionHttp-failures.md +83 -0
  49. package/docs/ActionHttp.md +202 -282
  50. package/docs/ActionMcp-failures.md +31 -0
  51. package/docs/ActionMcp.md +222 -271
  52. package/docs/ActionRpc-failures.md +21 -0
  53. package/docs/ActionRpc.md +178 -0
  54. package/docs/ActionToolkit-failures.md +15 -0
  55. package/docs/ActionToolkit.md +100 -119
  56. package/docs/Authentication-advanced.md +139 -0
  57. package/docs/Authentication-failures.md +99 -0
  58. package/docs/Authentication.md +142 -392
  59. package/docs/CONTEXT.md +39 -24
  60. package/docs/README.md +71 -35
  61. package/docs/Testing-failures.md +20 -0
  62. package/docs/Testing.md +186 -151
  63. package/docs/guarantees.md +35 -96
  64. package/docs/setup-failures.md +34 -0
  65. package/docs/setup.md +87 -91
  66. package/examples/README.md +68 -0
  67. package/examples/assistant/README.md +92 -0
  68. package/examples/assistant/src/agent.ts +92 -0
  69. package/examples/assistant/src/cli.ts +34 -0
  70. package/examples/assistant/src/commands.ts +25 -0
  71. package/examples/assistant/src/identity/Identity.ts +33 -0
  72. package/examples/assistant/src/identity/authorize.ts +24 -0
  73. package/examples/assistant/src/identity/handlers.ts +10 -0
  74. package/examples/assistant/src/identity/members.ts +9 -0
  75. package/examples/assistant/src/identity/permissions.ts +23 -0
  76. package/examples/assistant/src/scripted.ts +23 -0
  77. package/examples/assistant/src/tasks/Tasks.ts +63 -0
  78. package/examples/assistant/src/tasks/handlers.ts +25 -0
  79. package/examples/assistant/src/tasks/store.ts +96 -0
  80. package/examples/assistant/src/toolkit.ts +30 -0
  81. package/examples/assistant/test/commands.test.ts +57 -0
  82. package/examples/assistant/test/identity/identity.test.ts +43 -0
  83. package/examples/assistant/test/tasks/store.test.ts +48 -0
  84. package/examples/assistant/test/tasks/tasks.test.ts +75 -0
  85. package/examples/assistant/test/toolkit.test.ts +121 -0
  86. package/examples/kitchen-sink/README.md +317 -0
  87. package/examples/kitchen-sink/src/Actions.ts +19 -0
  88. package/examples/kitchen-sink/src/Api.ts +24 -0
  89. package/examples/kitchen-sink/src/Rpc.ts +12 -0
  90. package/examples/kitchen-sink/src/admin/Admin.ts +59 -0
  91. package/examples/kitchen-sink/src/admin/authenticate.ts +18 -0
  92. package/examples/kitchen-sink/src/admin/authorize.ts +27 -0
  93. package/examples/kitchen-sink/src/admin/grants.ts +22 -0
  94. package/examples/kitchen-sink/src/admin/handlers.ts +21 -0
  95. package/examples/kitchen-sink/src/admin/keys.ts +8 -0
  96. package/examples/kitchen-sink/src/agent.ts +47 -0
  97. package/examples/kitchen-sink/src/assistant/Assistant.ts +82 -0
  98. package/examples/kitchen-sink/src/assistant/conversations.ts +71 -0
  99. package/examples/kitchen-sink/src/assistant/demo-model.ts +33 -0
  100. package/examples/kitchen-sink/src/assistant/handlers.ts +146 -0
  101. package/examples/kitchen-sink/src/attachments/Attachments.ts +48 -0
  102. package/examples/kitchen-sink/src/attachments/download.ts +49 -0
  103. package/examples/kitchen-sink/src/attachments/handlers.ts +38 -0
  104. package/examples/kitchen-sink/src/attachments/store.ts +58 -0
  105. package/examples/kitchen-sink/src/browser.ts +33 -0
  106. package/examples/kitchen-sink/src/cli.ts +85 -0
  107. package/examples/kitchen-sink/src/config.ts +18 -0
  108. package/examples/kitchen-sink/src/identity/Identity.ts +61 -0
  109. package/examples/kitchen-sink/src/identity/authenticate.ts +87 -0
  110. package/examples/kitchen-sink/src/identity/authorize.ts +16 -0
  111. package/examples/kitchen-sink/src/identity/directory.ts +52 -0
  112. package/examples/kitchen-sink/src/identity/handlers.ts +9 -0
  113. package/examples/kitchen-sink/src/identity/members.ts +13 -0
  114. package/examples/kitchen-sink/src/identity/quota.ts +62 -0
  115. package/examples/kitchen-sink/src/issues/Issues.ts +109 -0
  116. package/examples/kitchen-sink/src/issues/assistant.ts +23 -0
  117. package/examples/kitchen-sink/src/issues/guide.ts +37 -0
  118. package/examples/kitchen-sink/src/issues/handlers.ts +37 -0
  119. package/examples/kitchen-sink/src/issues/store.ts +96 -0
  120. package/examples/kitchen-sink/src/issues/write-limit.ts +41 -0
  121. package/examples/kitchen-sink/src/memory.ts +30 -0
  122. package/examples/kitchen-sink/src/ops.ts +42 -0
  123. package/examples/kitchen-sink/src/request-policy.ts +63 -0
  124. package/examples/kitchen-sink/src/routes.ts +120 -0
  125. package/examples/kitchen-sink/src/sdk.ts +46 -0
  126. package/examples/kitchen-sink/src/seed.ts +65 -0
  127. package/examples/kitchen-sink/src/server.ts +62 -0
  128. package/examples/kitchen-sink/src/stdio.ts +34 -0
  129. package/examples/kitchen-sink/src/workspaces/Workspaces.ts +28 -0
  130. package/examples/kitchen-sink/src/workspaces/handlers.ts +23 -0
  131. package/examples/kitchen-sink/src/workspaces/registry.ts +46 -0
  132. package/examples/kitchen-sink/src/workspaces/tenant.ts +17 -0
  133. package/examples/kitchen-sink/test/admin/admin.test.ts +67 -0
  134. package/examples/kitchen-sink/test/assistant/assistant.test.ts +435 -0
  135. package/examples/kitchen-sink/test/attachments/attachments.test.ts +161 -0
  136. package/examples/kitchen-sink/test/identity/identity.test.ts +137 -0
  137. package/examples/kitchen-sink/test/identity/session.test.ts +110 -0
  138. package/examples/kitchen-sink/test/issues/assistant.test.ts +75 -0
  139. package/examples/kitchen-sink/test/issues/issues.test.ts +135 -0
  140. package/examples/kitchen-sink/test/request-policy.test.ts +125 -0
  141. package/examples/kitchen-sink/test/routes.test.ts +123 -0
  142. package/examples/kitchen-sink/test/support/scripted.ts +40 -0
  143. package/examples/live-rpc/README.md +107 -0
  144. package/examples/live-rpc/src/Rpc.ts +8 -0
  145. package/examples/live-rpc/src/browser.ts +98 -0
  146. package/examples/live-rpc/src/chat/Chat.ts +75 -0
  147. package/examples/live-rpc/src/chat/authorize.ts +16 -0
  148. package/examples/live-rpc/src/chat/handlers.ts +50 -0
  149. package/examples/live-rpc/src/chat/room.ts +23 -0
  150. package/examples/live-rpc/src/chat/store.ts +54 -0
  151. package/examples/live-rpc/src/client.ts +37 -0
  152. package/examples/live-rpc/src/identity/Identity.ts +19 -0
  153. package/examples/live-rpc/src/identity/members.ts +8 -0
  154. package/examples/live-rpc/src/identity/verifier.ts +23 -0
  155. package/examples/live-rpc/src/routes.ts +22 -0
  156. package/examples/live-rpc/src/server.ts +43 -0
  157. package/examples/live-rpc/test/browser.test.ts +105 -0
  158. package/examples/live-rpc/test/chat/chat.test.ts +69 -0
  159. package/examples/live-rpc/test/routes.test.ts +99 -0
  160. package/examples/live-rpc/test/server.test.ts +75 -0
  161. package/examples/mcp-tools/README.md +136 -0
  162. package/examples/mcp-tools/src/instructions.ts +12 -0
  163. package/examples/mcp-tools/src/printers/Printers.ts +119 -0
  164. package/examples/mcp-tools/src/printers/fake.ts +115 -0
  165. package/examples/mcp-tools/src/printers/farm.ts +136 -0
  166. package/examples/mcp-tools/src/printers/handlers.ts +29 -0
  167. package/examples/mcp-tools/src/routes.ts +52 -0
  168. package/examples/mcp-tools/src/server.ts +30 -0
  169. package/examples/mcp-tools/src/stdio.ts +26 -0
  170. package/examples/mcp-tools/test/printers/printers.test.ts +189 -0
  171. package/examples/mcp-tools/test/routes.test.ts +202 -0
  172. package/examples/notes-service/README.md +108 -0
  173. package/examples/notes-service/src/Api.ts +13 -0
  174. package/examples/notes-service/src/browser.ts +41 -0
  175. package/examples/notes-service/src/cli.ts +22 -0
  176. package/examples/notes-service/src/commands.ts +89 -0
  177. package/examples/notes-service/src/identity/Identity.ts +31 -0
  178. package/examples/notes-service/src/identity/authorize.ts +18 -0
  179. package/examples/notes-service/src/identity/handlers.ts +10 -0
  180. package/examples/notes-service/src/identity/users.ts +9 -0
  181. package/examples/notes-service/src/identity/verifier.ts +36 -0
  182. package/examples/notes-service/src/notes/Notes.ts +91 -0
  183. package/examples/notes-service/src/notes/handlers.ts +33 -0
  184. package/examples/notes-service/src/notes/store.ts +73 -0
  185. package/examples/notes-service/src/routes.ts +45 -0
  186. package/examples/notes-service/src/server.ts +26 -0
  187. package/examples/notes-service/src/status/Status.ts +10 -0
  188. package/examples/notes-service/src/status/handlers.ts +14 -0
  189. package/examples/notes-service/src/stdio.ts +25 -0
  190. package/examples/notes-service/test/commands.test.ts +134 -0
  191. package/examples/notes-service/test/notes/notes.test.ts +103 -0
  192. package/examples/notes-service/test/routes.test.ts +84 -0
  193. package/examples/quickstart/README.md +31 -0
  194. package/examples/quickstart/src/Api.ts +5 -0
  195. package/examples/quickstart/src/client.ts +13 -0
  196. package/examples/quickstart/src/greeting/Greeting.ts +12 -0
  197. package/examples/quickstart/src/greeting/handlers.ts +6 -0
  198. package/examples/quickstart/src/routes.ts +11 -0
  199. package/examples/quickstart/src/server.ts +16 -0
  200. package/examples/quickstart/test/greeting/greeting.test.ts +18 -0
  201. package/package.json +23 -5
  202. package/dist/internal/actions.d.mts +0 -9
  203. package/dist/internal/authentication.mjs +0 -11
  204. package/dist/internal/call.mjs +0 -12
  205. package/dist/internal/cli.mjs +0 -328
  206. package/dist/internal/client.mjs +0 -25
  207. package/dist/internal/console.mjs +0 -77
  208. package/dist/internal/declared.d.mts +0 -13
  209. package/dist/internal/declared.mjs +0 -34
  210. package/dist/internal/mcp.d.mts +0 -14
  211. package/dist/internal/media.d.mts +0 -8
  212. package/dist/internal/media.mjs +0 -26
  213. package/dist/internal/refusal.mjs +0 -67
  214. package/dist/internal/schema-errors.mjs +0 -20
  215. package/dist/internal/tools.mjs +0 -44
@@ -0,0 +1,102 @@
1
+ # ActionCli failure modes
2
+
3
+ What you see when something is wrong, and the fix. Search for a fragment of the message.
4
+ The tasks are in [ActionCli.md](ActionCli.md).
5
+
6
+ ## Flags and input
7
+
8
+ - `Unrecognized flag: --<field> in command …` for an input field: a field listed in `positional`
9
+ has no flag. Pass its value as an argument.
10
+ - `Missing value for flag --<flag>`, or `Unrecognized flag: -x`, for a value starting with `-`:
11
+ Effect's parser reads a value written apart from its flag as a flag itself when it starts with
12
+ `-`, `-` alone and a number such as `-5` excepted: `--note -x` is a missing value, and
13
+ `--note --help` prints help. Write `--<flag>=<value>`; `--` does not help, since what follows
14
+ it is positional.
15
+ - `InvalidInput` naming an unexpected key: `--input` or a flag's JSON holds a field the schema
16
+ does not declare, such as a misspelling.
17
+ - `InvalidInput` from a command whose input is not a struct, run without `--input`: the schema
18
+ rejects the default `{}`. Pass `--input`.
19
+ - `InvalidInput` for a flag's value that looks right: a flag takes the encoded value, and reads
20
+ its text as JSON when the field accepts that kind of JSON value. Quote a string that reads as
21
+ JSON: `--id '"123"'` for a `String | Number` field. Malformed JSON is taken as text.
22
+ - A command with a `stdin` field waits without output: nothing closes stdin, such as a parent
23
+ process holding the pipe, or `ssh` run without `-n`. Pipe the value in, or redirect stdin from
24
+ a file or `/dev/null`.
25
+
26
+ ## Thrown when a command is built
27
+
28
+ - `Required positional argument after an optional one: <field>`, or
29
+ `Repeated positional argument before another one: <field>`: `positional` lists every required
30
+ field before any optional one, and an array field last.
31
+ - `Not an input field: <field>`: `positional` names no field of the input.
32
+ - `Not a flag's input field: <field>`: an `aliases` key names a field that is positional, read
33
+ from stdin, or no field.
34
+ - `Not a required input field: <field>`: `stdin` names an optional field, or no field.
35
+ - `Positional arguments need named input fields`, `Aliases need named input fields: <fields>`, or
36
+ `Stdin needs named input fields: <field>`: the action's input is not a struct.
37
+ - `Duplicate flag: --<name>, claimed by ...`: two flags of one command share a name, such as two
38
+ fields with one kebab-case name (`userId`, `user_id`), a `json` field beside `render`'s
39
+ `--json`, or an alias another flag's name or alias takes. Rename the field or the alias, or
40
+ drop `render`. A field named like a global flag (`help`, `version`, `log-level`) is not a
41
+ clash: its flag shadows the global one on that command.
42
+ - `Duplicate command: <name>, claimed by action ... and action ...`: two actions of an aggregate
43
+ have the same kebab-case name. Give one a `name` in `commands`, or use separate aggregates.
44
+ - `Duplicate command: <name>, claimed by action ... and subcommands`: a command passed in
45
+ `subcommands` has a derived command's name. Rename either.
46
+ - `Unknown commands: <keys>`: a `commands` key names no action. Use the action's own name, not
47
+ its kebab-case command name.
48
+ - `Listed in actions, but no implementation holds it: <names>`, or
49
+ `but the binding does not hold it`: `actions` lists a contract that the implementations, or the
50
+ binding, do not hold, by identity. `(another contract)` marks one whose name they hold, as a
51
+ second copy of the contracts module makes. List the contract they implement or bind.
52
+ - `Action "x" has no implementation here`, or a type error at `command`: no implementation passed
53
+ has that contract. Pass the implementation, and select with the exact contract value it
54
+ implements; an equal-looking action does not match.
55
+ - `Action "x" is not in this HTTP binding`, or a type error at `remoteCommand`: the action was not
56
+ passed to this binding's `ActionHttp.make`. Select with the exact contract value it received.
57
+
58
+ ## Types
59
+
60
+ - An argument of type `Binding<…>` not assignable at `make` or `command`, an implementation not
61
+ assignable at `remote` or `remoteCommand`, or `client` refused at `make` or `command`: `make`
62
+ and `command` take implementations; `remote` and `remoteCommand` take a binding, and alone take
63
+ `client`. To choose by a condition, build a command from each:
64
+ `remotely ? ActionCli.remote(Http, options) : ActionCli.make(users, options)`.
65
+ - `Type 'HttpClient' is not assignable to type 'never'` in the pipe that runs a remote command:
66
+ provide `NodeHttpClient.layerUndici` (or `FetchHttpClient.layer`).
67
+ - A local command requires an identity service no handler yields: its action is protected, and
68
+ requires the identity its contract declares. Provide it on the command
69
+ ([Name the caller](ActionCli.md#name-the-caller)); do not make the contract public to satisfy
70
+ the requirement.
71
+ - Type error at `Effect.catchTag("UserNotFound", ...)` after `Command.run`: a command fails with
72
+ `UserError`. Use `Effect.catchReason("UserError", "UserNotFound", ...)`.
73
+ - Type error at `Effect.catchReason("UserError", "<Tag>", ...)`, its tag typed `never`: a failure
74
+ of the command has no `_tag`, such as a builder's plain `Error`. Fail with a tagged error, such
75
+ as a `Schema.TaggedError` or `Data.TaggedError`.
76
+
77
+ ## Running
78
+
79
+ - `--help` or a mistyped flag connects to a database, or fails reading config: services provided
80
+ around `Command.run` are built before parsing. Provide them on the command,
81
+ `Command.provide(layer)`.
82
+ - `ERROR (#n): ConfigError: SchemaError(Expected string at ["NOTES_TOKEN"])` from a public
83
+ command, exit 1, on stdout, or on stderr under `logToStderr`: the client provided on the
84
+ command requires a token, and a failure of what a command is provided is `runMain`'s report,
85
+ not the command's JSON. Read the token with `Config.option` and add the header only when it is
86
+ there. Where every command needs it, keep it required and map the failure, in the Effect that
87
+ provides the client, to `new CliError.UserError({ cause, userMessage })`:
88
+ [notes-service/src/commands.ts](../examples/notes-service/src/commands.ts).
89
+ - `HttpClientError` whose `reason._tag` is `InvalidUrlError`, from a remote command: its client
90
+ has no `baseUrl` and prepends no URL.
91
+ - 401 `Unauthenticated` from a remote command: a remote command adds no headers of its own. Add
92
+ credentials in `client`'s `transformClient`, or on the `HttpClient` the command is provided.
93
+ - Another command's request goes to the API's URL, or carries its token: an `HttpClient`
94
+ configured around the whole program rewrites every request the program makes. Configure it in
95
+ the `client` option, or provide it on the remote command alone.
96
+ - A report with a stack on stdout, `ERROR (#1): ...`, instead of JSON on stderr: a defect, or a
97
+ failure of a layer the host provides, which `runMain` reports. Fix the defect; apply
98
+ `ActionCli.logToStderr` to keep such reports off stdout.
99
+ - `ERROR (#n)` with a stack for a declared error, such as `UserNotFound`, from a command built
100
+ with `Command.make`: a command of your own that calls `Action.client` or `ActionHttp.client`
101
+ fails with the action's own error. Pipe the command's whole Effect through
102
+ `ActionCli.toUserError`, given the binding or the actions it calls, or derive the command with `ActionCli.command`.