@gjermundgaraba/effect-actions 0.34.0 → 0.36.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/dist/Action.d.mts +2 -2
- package/dist/Action.mjs +2 -2
- package/dist/ActionEntity.d.mts +209 -100
- package/dist/ActionEntity.mjs +129 -89
- package/dist/ActionHttp.d.mts +5 -2
- package/dist/ActionRpc.d.mts +65 -13
- package/dist/ActionRpc.mjs +22 -7
- package/dist/Event.d.mts +60 -6
- package/dist/Event.mjs +49 -2
- package/dist/RequestPolicy.d.mts +3 -9
- package/dist/RequestPolicy.mjs +18 -6
- package/dist/contract/errors.d.mts +5 -0
- package/dist/contract/errors.mjs +6 -1
- package/dist/contract/feed.mjs +41 -21
- package/dist/contract/serving.mjs +15 -9
- package/dist/contract/wake.d.mts +14 -0
- package/dist/contract/wake.mjs +4 -3
- package/dist/contract/watch.mjs +1 -2
- package/dist/entity/wakes.mjs +32 -22
- package/dist/http/unavailable.mjs +2 -2
- package/dist/rpc/erased.mjs +6 -2
- package/dist/rpc/watch.mjs +4 -2
- package/docs/Action.md +1 -1
- package/docs/ActionEntity-failures.md +0 -1
- package/docs/ActionEntity.md +19 -11
- package/docs/ActionHttp.md +1 -1
- package/docs/ActionRpc.md +21 -1
- package/docs/Authentication-failures.md +1 -1
- package/docs/Event.md +3 -1
- package/docs/setup.md +1 -1
- package/examples/kitchen-sink/src/browser.ts +9 -21
- package/examples/shopping-carts/README.md +1 -1
- package/examples/shopping-carts/src/entities.ts +4 -2
- package/package.json +1 -1
- package/examples/shopping-carts/src/Rpc.ts +0 -6
package/docs/ActionRpc.md
CHANGED
|
@@ -169,7 +169,27 @@ export const openChat = Effect.gen(function* () {
|
|
|
169
169
|
|
|
170
170
|
[live-rpc/src/client.ts](../examples/live-rpc/src/client.ts) runs it from Node, and [live-rpc/src/page.ts](../examples/live-rpc/src/page.ts) wraps it in promises for a page that is not one Effect program. The client's traps are on `ActionRpc.client`.
|
|
171
171
|
|
|
172
|
-
|
|
172
|
+
A page that holds one socket of its own builds the client with `ActionRpc.socketClient(Rpc, { url })`: one WebSocket for the client's `Scope`, JSON, reconnecting after a drop and stopping at a server's refusal. Its options, a constructor, `hooks`, `serialization` and `watchMode`, are on `ActionRpc.SocketClientOptions`:
|
|
173
|
+
|
|
174
|
+
```ts example=kitchen-sink/src/browser.ts
|
|
175
|
+
import * as ActionRpc from "@gjermundgaraba/effect-actions/ActionRpc";
|
|
176
|
+
import { Effect } from "effect";
|
|
177
|
+
|
|
178
|
+
import { Rpc } from "./Rpc.js";
|
|
179
|
+
|
|
180
|
+
export const board = (url: string) =>
|
|
181
|
+
Effect.gen(function* () {
|
|
182
|
+
const tracker = yield* ActionRpc.socketClient(Rpc, { url });
|
|
183
|
+
|
|
184
|
+
const me = yield* tracker.whoAmI();
|
|
185
|
+
const { issues } = yield* tracker.listIssues({ status: "open", limit: 50 });
|
|
186
|
+
|
|
187
|
+
return { me, issues };
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
export const open = async (url: string) =>
|
|
191
|
+
await Effect.runPromise(Effect.scoped(board(url)));
|
|
192
|
+
```
|
|
173
193
|
|
|
174
194
|
## Serve and watch events
|
|
175
195
|
|
|
@@ -5,7 +5,7 @@ What you see when something is wrong, and the fix: compiler diagnostics and erro
|
|
|
5
5
|
## Types and startup
|
|
6
6
|
|
|
7
7
|
- `Provider<CurrentUser, "notes-service.Login">` among a layer's requirements, `Type 'Provider<...>' is not assignable to type 'never'` at `Layer.launch` or `NodeRuntime.runMain`, or `Expected 2 arguments, but got 1` at a web handler's `handler(request)`: a layer serving protected actions requires the provider of the descriptor it names, and nothing else satisfies it, neither the identity nor another descriptor's provider. Provide it, `Layer.provide(authenticate)` ([Verify credentials](Authentication.md#verify-credentials)).
|
|
8
|
-
- `Property 'authentication' is missing`, or `No overload matches this call` with `"Protected actions take options naming their authentication"` or `"Authentication descriptor does not cover every protected action"`, at `ActionHttp.make`, `ActionRpc.make` or `ActionMcp.layerHttp`: a protected action is served and no descriptor is named. Give `{ authentication: Login }` ([Declare how callers sign in](Authentication.md#declare-how-callers-sign-in)).
|
|
8
|
+
- `Property 'authentication' is missing`, or `No overload matches this call` with `"Protected actions take options naming their authentication"` or `"Authentication descriptor does not cover every protected action"`, at `ActionHttp.make`, `ActionRpc.make`, `ActionEntity.make` or `ActionMcp.layerHttp`: a protected action is served and no descriptor is named. Give `{ authentication: Login }` ([Declare how callers sign in](Authentication.md#declare-how-callers-sign-in)).
|
|
9
9
|
- `Expected 3 arguments, but got 2`, or `is not assignable to parameter of type 'Options<never>`, at `Authentication.make`: a descriptor names its identity's stable id. Give it `{ principal: (user) => user.id }` ([Declare how callers sign in](Authentication.md#declare-how-callers-sign-in)).
|
|
10
10
|
- `Type 'Other' is not assignable to type 'CurrentUser'` under `Descriptor<…>`, at `authentication`: the descriptor authenticates another identity than the action's `caller`. Name the descriptor made for the caller's identity service.
|
|
11
11
|
- `is not assignable to type 'Forbidden | Unauthenticated'`, or `Property '…' is missing in type`, at `layer`'s verifier: it fails with an error that is neither a refusal nor one its descriptor declares, or succeeds with a value that is not the identity. Declare the error in the descriptor's `error`, or map it to a refusal where it is the caller's.
|
package/docs/Event.md
CHANGED
|
@@ -161,6 +161,8 @@ export const buildEvents = Event.implement(
|
|
|
161
161
|
|
|
162
162
|
A subscriber holding a stream open is read again every 5 seconds. Where the application writes the store itself, it wakes them at once: after the write, `Event.Events`' `notify`, as [build-events/src/builds/handlers.ts](../examples/build-events/src/builds/handlers.ts) does after each build finishes. A store another process writes is read at the next poll.
|
|
163
163
|
|
|
164
|
+
Where the store appends entries under increasing integer ids that last as long as it does, such as a SQLite table's `INTEGER PRIMARY KEY`, `Event.appended` builds the check from the newest id and a read after an id, as the Cloudflare package's chat-rooms example does for its messages: the cursor is the last id read, and what a stale cursor answers is on `Event.appended`.
|
|
165
|
+
|
|
164
166
|
- **Check what a subscriber may see where the data is read**, as an action's handler does: `authorize` decides whether it may subscribe at all, and receives the event type, not the subscription's input.
|
|
165
167
|
|
|
166
168
|
## Send a value whole
|
|
@@ -194,7 +196,7 @@ export const statusEvents = Event.implement(
|
|
|
194
196
|
);
|
|
195
197
|
```
|
|
196
198
|
|
|
197
|
-
[build-events/src/builds/handlers.ts](../examples/build-events/src/builds/handlers.ts) notifies after each build with its pipeline as the key, so a build wakes only that pipeline's subscribers.
|
|
199
|
+
[build-events/src/builds/handlers.ts](../examples/build-events/src/builds/handlers.ts) notifies after each build with its pipeline as the key, so a build wakes only that pipeline's subscribers. A notify that leaves the value as the subscriber saw it sends nothing. A polling client asks again at the source's `nextPoll`, 5 seconds by default, where a value changing faster is worth a quicker poll; why a value written as it is read is not missed is on `Event.Current`.
|
|
198
200
|
|
|
199
201
|
## Keep what nothing else keeps
|
|
200
202
|
|
package/docs/setup.md
CHANGED
|
@@ -108,4 +108,4 @@ Import into the page only the contract files, the binding and a client module of
|
|
|
108
108
|
|
|
109
109
|
- `Action`, `Event`, `ActionHttp`, `ActionRpc` and `Authentication` are the browser-safe modules: they use nothing of Node or a server platform.
|
|
110
110
|
- Keep `Action.implement` and `Authentication.layer` out of every file the page imports: a bundler keeps such a call, and what its handlers or verifier import, even unused.
|
|
111
|
-
- Those five modules import Effect through `effect`, `effect/http` and `effect/http-api` alone, and `ActionRpc` through `effect/rpc` too. A page loading Effect from an import map serves those
|
|
111
|
+
- Those five modules import Effect through `effect`, `effect/http` and `effect/http-api` alone, and `ActionRpc` through `effect/rpc` and `effect/socket` too. A page loading Effect from an import map serves those.
|
|
@@ -1,29 +1,17 @@
|
|
|
1
1
|
import * as ActionRpc from "@gjermundgaraba/effect-actions/ActionRpc";
|
|
2
|
-
import { Effect
|
|
3
|
-
import { RpcClient, RpcSerialization } from "effect/rpc";
|
|
4
|
-
import { Socket } from "effect/socket";
|
|
2
|
+
import { Effect } from "effect";
|
|
5
3
|
|
|
6
4
|
import { Rpc } from "./Rpc.js";
|
|
7
5
|
|
|
8
|
-
export const board =
|
|
9
|
-
|
|
6
|
+
export const board = (url: string) =>
|
|
7
|
+
Effect.gen(function* () {
|
|
8
|
+
const tracker = yield* ActionRpc.socketClient(Rpc, { url });
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const me = yield* tracker.whoAmI();
|
|
11
|
+
const { issues } = yield* tracker.listIssues({ status: "open", limit: 50 });
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
export const protocol = (url: string) =>
|
|
18
|
-
RpcClient.layerProtocolSocket().pipe(
|
|
19
|
-
Layer.provide(Socket.layerWebSocket(url)),
|
|
20
|
-
Layer.provide([
|
|
21
|
-
RpcSerialization.layerJson,
|
|
22
|
-
Socket.layerWebSocketConstructorGlobal,
|
|
23
|
-
])
|
|
24
|
-
);
|
|
13
|
+
return { me, issues };
|
|
14
|
+
});
|
|
25
15
|
|
|
26
16
|
export const open = async (url: string) =>
|
|
27
|
-
await Effect.runPromise(
|
|
28
|
-
board.pipe(Effect.scoped, Effect.provide(protocol(url)))
|
|
29
|
-
);
|
|
17
|
+
await Effect.runPromise(Effect.scoped(board(url)));
|
|
@@ -38,7 +38,7 @@ src/
|
|
|
38
38
|
├── platform/
|
|
39
39
|
│ ├── sql-carts.ts CartStore over a SqlClient
|
|
40
40
|
│ └── cluster.ts SingleRunner, the cluster in one process over that SqlClient
|
|
41
|
-
├── Api.ts
|
|
41
|
+
├── Api.ts the HTTP binding
|
|
42
42
|
├── entities.ts Cart, the entity: which cart each action's input names
|
|
43
43
|
├── routes.ts the entity's layer, and the JSON routes reaching it
|
|
44
44
|
└── server.ts entrypoint: both, with CartStore over SQL, on SingleRunner and one SQLite file
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as ActionEntity from "@gjermundgaraba/effect-actions/ActionEntity";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { Carts } from "./cart/Cart.js";
|
|
4
|
+
import { Login } from "./identity/Identity.js";
|
|
4
5
|
|
|
5
|
-
export const Cart = ActionEntity.make("Cart",
|
|
6
|
+
export const Cart = ActionEntity.make("Cart", Carts, {
|
|
7
|
+
authentication: Login,
|
|
6
8
|
key: ({ cart }) => cart,
|
|
7
9
|
});
|
package/package.json
CHANGED