@shivaedev/effect-contract 0.5.1 → 0.7.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/CHANGELOG.md +29 -0
- package/README.md +43 -32
- package/dist/automaticLive.d.ts +22 -0
- package/dist/automaticLive.d.ts.map +1 -0
- package/dist/automaticLive.js +29 -0
- package/dist/automaticLive.js.map +1 -0
- package/dist/bind.d.ts +2 -1
- package/dist/bind.d.ts.map +1 -1
- package/dist/bind.js +10 -5
- package/dist/bind.js.map +1 -1
- package/dist/contract.d.ts +1 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +10 -2
- package/dist/contract.js.map +1 -1
- package/dist/keys.d.ts +4 -4
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +13 -9
- package/dist/keys.js.map +1 -1
- package/dist/live.d.ts +1 -1
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +3 -1
- package/dist/live.js.map +1 -1
- package/dist/makeLiveServer.d.ts.map +1 -1
- package/dist/makeLiveServer.js +42 -10
- package/dist/makeLiveServer.js.map +1 -1
- package/dist/readPolicy.d.ts +9 -0
- package/dist/readPolicy.d.ts.map +1 -0
- package/dist/readPolicy.js +21 -0
- package/dist/readPolicy.js.map +1 -0
- package/dist/serverMetadata.d.ts +33 -0
- package/dist/serverMetadata.d.ts.map +1 -0
- package/dist/serverMetadata.js +12 -0
- package/dist/serverMetadata.js.map +1 -0
- package/package.json +11 -55
- package/src/automaticLive.ts +44 -0
- package/src/bind.ts +16 -8
- package/src/contract.ts +11 -3
- package/src/keys.ts +14 -10
- package/src/live.ts +4 -2
- package/src/makeLiveServer.ts +50 -12
- package/src/readPolicy.ts +29 -0
- package/src/serverMetadata.ts +15 -0
- package/docs/north-star.md +0 -45
- package/docs/roadmap.md +0 -26
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0 - 2026-10-19
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `authorizeReads(effect, request, policy, denied)` and `ReadPolicy` in `readPolicy.ts` share a key authorization policy between query reads and live hints. `QueryReads` in `serverMetadata.ts` exposes the declared query read keys to server middleware.
|
|
8
|
+
- `changesRpc(name)` retains the literal contract name for typed native clients.
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- effect-contract's `live` coordinator no longer reconciles its read scope when `paused` is read for the first time; a component that showed the pause state while connecting used to make every loaded query read again.
|
|
13
|
+
- Opening a Board page sends each read once. The page starts its reads after the live connection's first update, which used to read navigation and watcher state a second time, and a failed connection does not hold the page.
|
|
14
|
+
- A file event that changes neither the bytes nor the modification time no longer refreshes open Board pages. A file saved with the same bytes and a new modification time still refreshes them.
|
|
15
|
+
- Live streams filter changed keys with the viewer's read policy and suppress empty hints, while preserving independently allowed list hints.
|
|
16
|
+
|
|
17
|
+
## 0.6.0 - 2026-10-18
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- Contracts attach command invalidation metadata and a host-served change subscription. `serverMetadata.ts` exports `CommandInvalidation` and `changesRpc(name)` for server adapters.
|
|
22
|
+
- Bindings expose the `LiveConnection` symbol from `automaticLive.ts`; React session boundaries mount its `connection` atom and track the binding's query keys. `LiveBound` describes its connection and status atoms; `automaticLive(service, name)` and `ChangesClient` expose the underlying tracked coordination. `live` also accepts a function for `resyncKeys`.
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- Live server hints contain only changed keys intersecting the subscription, so one item's change does not refetch unrelated item queries.
|
|
27
|
+
|
|
28
|
+
### Breaking
|
|
29
|
+
|
|
30
|
+
- Contracts reserve the `<contract>.$changes` RPC name for automatic subscriptions. Use Platform's database host and NDJSON transport for automatic live queries, and remove application subscription handlers and `live()` mounting when using a React session boundary.
|
|
31
|
+
|
|
3
32
|
## 0.5.1 - 2026-10-17
|
|
4
33
|
|
|
5
34
|
### Fixed
|
package/README.md
CHANGED
|
@@ -131,7 +131,7 @@ export const NotesHandlers = Notes.toLayer(Effect.gen(function* () {
|
|
|
131
131
|
}));
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
-
Save this module as `handlers.ts`.
|
|
134
|
+
Save this module as `handlers.ts`. An application can put repository and service calls in these handlers. The contract checks handler result and rejection types; it does not implement persistence, authorization or transactions.
|
|
135
135
|
|
|
136
136
|
Native `.middleware(M)` returns a contract that retains its declarations. For example, a native middleware service can supply request identity:
|
|
137
137
|
|
|
@@ -180,7 +180,7 @@ export class NotesClient extends AtomRpc.Service<NotesClient>()("app/NotesClient
|
|
|
180
180
|
export const api = bind(Notes, NotesClient);
|
|
181
181
|
```
|
|
182
182
|
|
|
183
|
-
Save the client module as `client.ts`. The [native RPC guide](https://github.com/ShivaeDev/platform/blob/main/docs/framework/native-rpc.md) covers hosting; the [
|
|
183
|
+
Save the client module as `client.ts`. The [native RPC guide](https://github.com/ShivaeDev/platform/blob/main/docs/framework/native-rpc.md) covers hosting; the [reference composition](https://github.com/ShivaeDev/platform/blob/main/docs/framework/composed-example.md) composes handlers, request identity, SQL and a rendered client.
|
|
184
184
|
|
|
185
185
|
### 3. Every day: read and change
|
|
186
186
|
|
|
@@ -226,11 +226,15 @@ The dependency rule is deliberately asymmetric:
|
|
|
226
226
|
|
|
227
227
|
`readKeys` and `invalidationKeys` produce these native keys and remove duplicates. An item change refreshes that item and its list, preserving other item queries. A list-only invalidation refreshes list queries and leaves item queries alone. These keys match native Reactivity's record-key hashing of `{ notes: [1] }`.
|
|
228
228
|
|
|
229
|
-
Client invalidation follows RPC success.
|
|
229
|
+
Client invalidation follows RPC success. Platform database hosts also publish declared command invalidations automatically after the handler succeeds, excluding keys already announced by repository commits, using `transact` from [`effect-sql`](https://github.com/ShivaeDev/platform/tree/main/packages/effect-sql); commit-bound changes belong to [`effect-changes`](https://github.com/ShivaeDev/platform/tree/main/packages/effect-changes).
|
|
230
230
|
|
|
231
|
-
### 4.
|
|
231
|
+
### 4. Live invalidation and resume
|
|
232
232
|
|
|
233
|
-
|
|
233
|
+
Platform database hosts serve the contract's reserved `<contract>.$changes` stream automatically. With NDJSON transport, `bind` and a React `SessionBoundary` connect query atoms without an application subscribe operation or `live()` call. The boundary finds bound APIs returned directly by `connect` or as properties such as `client.api`. See [automatic changes](https://github.com/ShivaeDev/platform/blob/main/docs/framework/changes.md) for defaults.
|
|
234
|
+
|
|
235
|
+
For a custom transport or explicit pause/status controls, the native live APIs remain available:
|
|
236
|
+
|
|
237
|
+
Declare subscriptions with `stream` in the same contract. Its `success` schema describes each element, and its `rejections` become the native stream error schema. `bind` exposes `run(payload)` as a native `Stream`, preserving declared rejections, middleware errors and RPC client errors. Completion and client interruption release the server subscription. The compiler rejects a unary client for a streaming operation.
|
|
234
238
|
|
|
235
239
|
Every query that should reconcile together must read the same explicit scope. This variant of the feature adds `workspace.list` alongside each query's item or list key:
|
|
236
240
|
|
|
@@ -259,7 +263,7 @@ export const LiveNotes = contract("notes", { queries: [LiveGet, LiveList], comma
|
|
|
259
263
|
|
|
260
264
|
Save the shared module as `live-notes.ts`. A collection list key alone does not cover its item queries. The common `workspace.list` key expresses that the caller intends to reconcile all queries that read it.
|
|
261
265
|
|
|
262
|
-
Use `LiveNotes` as the server group and implement `notes.subscribe` with a native Stream. For streaming HTTP,
|
|
266
|
+
Use `LiveNotes` as the server group and implement `notes.subscribe` with a native Stream. For streaming HTTP, use `RpcSerialization.layerNdjson` on both sides. This client mounts live coordination alongside its queries:
|
|
263
267
|
|
|
264
268
|
```ts
|
|
265
269
|
import { Layer } from "effect";
|
|
@@ -298,7 +302,7 @@ const releaseConnection = registry.mount(updates.connection);
|
|
|
298
302
|
| `Resync` | The exact `resyncKeys` read scope. |
|
|
299
303
|
| First hint on a new or reconnected stream | The full explicit scope, even if the hint is targeted. |
|
|
300
304
|
|
|
301
|
-
`LiveHint` and `Key` are schemas.
|
|
305
|
+
`LiveHint` and `Key` are schemas. Decoding rejects unknown hint tags and item keys with an invalid ID type.
|
|
302
306
|
|
|
303
307
|
```ts
|
|
304
308
|
registry.set(updates.paused, true);
|
|
@@ -306,11 +310,11 @@ registry.set(updates.paused, false);
|
|
|
306
310
|
const status = registry.get(updates.status);
|
|
307
311
|
```
|
|
308
312
|
|
|
309
|
-
While paused,
|
|
313
|
+
While paused, live coordination keeps observing hints and suppresses automatic refresh. `status.pending` saturates at 256 observations. Unpausing reconciles the explicit scope and resets the count. A resume signal also requests reconciliation: an injected native source and visible browser `online` and `visibilitychange` events request it, while hidden events do not.
|
|
310
314
|
|
|
311
|
-
`status` exposes `connection`, `failure`, `needsResync` and `pending`.
|
|
315
|
+
`status` exposes `connection`, `failure`, `needsResync` and `pending`. A reconnection reconciles changes missed while disconnected, and successful delivery clears a typed stream failure. Native query atoms keep previous successful data during a read failure and reject stale responses after invalidation. Query failures remain in their own `AsyncResult`; stream failures appear in `status.failure`.
|
|
312
316
|
|
|
313
|
-
The resume signal is a scoped native atom.
|
|
317
|
+
The resume signal is a scoped native atom. Disposing the registry removes its browser listeners, cleans up an injected source, including one used only through `live`, and releases the stream subscription:
|
|
314
318
|
|
|
315
319
|
```ts
|
|
316
320
|
releaseQuery();
|
|
@@ -320,6 +324,28 @@ registry.dispose();
|
|
|
320
324
|
|
|
321
325
|
Call the release functions and dispose the registry when the application's root no longer owns them.
|
|
322
326
|
|
|
327
|
+
### Server hint streams
|
|
328
|
+
|
|
329
|
+
Import `makeLiveServer` from `@shivaedev/effect-contract/makeLiveServer.ts` and create it once with the server's `Reactivity` service. After application authorization, return `hints.stream([orders.item(id)])` from the native streaming RPC handler. Each subscription starts with `Resync`; invalidating its read keys produces `Changed` with those declared keys. `hints.resync` sends `Resync` to every live stream owned by that helper, including streams for otherwise unrelated keys. Independent helpers keep their resync scopes separate even when they share Reactivity. The native stream owns registration and interruption. Keep this server helper separate from the browser's `live` coordinator.
|
|
330
|
+
|
|
331
|
+
For viewer-scoped hints, call `authorizeReads` once in the application's native authorization middleware, after resolving the session:
|
|
332
|
+
|
|
333
|
+
```ts
|
|
334
|
+
import { authorizeReads } from "@shivaedev/effect-contract/readPolicy.ts";
|
|
335
|
+
|
|
336
|
+
const guard = Layer.succeed(Guard, (effect, request) =>
|
|
337
|
+
Effect.flatMap(resolveSession(request.headers), (session) =>
|
|
338
|
+
authorizeReads(effect, request, (key) => canRead(session, key), Effect.fail(new Denied())).pipe(
|
|
339
|
+
Effect.provideService(Session, session),
|
|
340
|
+
),
|
|
341
|
+
),
|
|
342
|
+
);
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
The application supplies `resolveSession`, `canRead` and its middleware's `Denied` failure. Apply this middleware to the contract, including its reserved change stream. The policy returns an Effect boolean for a key. `authorizeReads` checks every declared query read key before running its handler and supplies the same policy to `makeLiveServer` streams, with the request's Effect context. Queries need no additional authorization declaration. A denied query returns the supplied failure.
|
|
346
|
+
|
|
347
|
+
Each changed hint checks its keys against that viewer's policy before delivery and omits denied keys. An empty hint is suppressed. Item and list keys are checked independently: allow a list key when the viewer may read that list, even when a changed item is private to another viewer. The list query still selects its visible rows. Without a supplied `ReadPolicy`, streams keep the default of allowing their subscribed keys; applications own the policy.
|
|
348
|
+
|
|
323
349
|
### API by module
|
|
324
350
|
|
|
325
351
|
Import the module that defines the name; the package has no root entry.
|
|
@@ -332,21 +358,12 @@ Import the module that defines the name; the package has no root entry.
|
|
|
332
358
|
| `keys.ts` | `collection(name, idSchema)`; `Key` schema; `readKeys(keys)` and `invalidationKeys(keys)`. |
|
|
333
359
|
| `bind.ts` | `bind(contract, atomRpcService)`, exposing `{ query, run }` for queries, `{ run }` Effects for commands and `{ run }` native Streams for streams. |
|
|
334
360
|
| `live.ts` | `LiveHint` schema; `live(runtime, { stream, resyncKeys, resume?, retryDelay? })`, exposing `connection`, `paused` and `status`. |
|
|
361
|
+
| `makeLiveServer.ts` | `makeLiveServer`, an Effect requiring `Reactivity` that creates scoped server hint streams and a `resync` Effect. |
|
|
362
|
+
| `readPolicy.ts` | `authorizeReads(effect, request, policy, denied)`; `ReadPolicy`, the request-local key policy used by server hint streams. |
|
|
363
|
+
| `serverMetadata.ts` | `QueryReads`, `CommandInvalidation` and `changesRpc(name)` for server adapters. |
|
|
335
364
|
| `resume.ts` | `resumeSignal({ window?, native? })`, returning a native numeric signal atom. |
|
|
336
365
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
| Module | Exported types |
|
|
340
|
-
| --- | --- |
|
|
341
|
-
| `operation.ts` | `Query`, `Command`, `Streaming`, `QueryShape`, `CommandShape`, `StreamShape`, `OperationShape`, `PayloadSchema`. |
|
|
342
|
-
| `contract.ts` | `Contract`, `Declared`, `OperationRpc`, `Tag`. |
|
|
343
|
-
| `rejection.ts` | `FieldRejection`, `MatchingTags`, `Reject`, `RejectedBy`, `RejectionClass`, `RejectionSpecs`, `Rejections`, `RejectionSet`, `RejectionUnion`, `RejectionValue`, `TaggedRejection`. |
|
|
344
|
-
| `keys.ts` | `Collection`, `Identity`, `ItemKey`, `ListKey`, `Key`. |
|
|
345
|
-
| `bind.ts` | `Bound`, `BoundQuery`, `BoundCommand`, `BoundStream`, `Failure`, `RunFailure`, `QueryOptions`. |
|
|
346
|
-
| `live.ts` | `LiveHint`, `LiveOptions`, `LiveStatus`. |
|
|
347
|
-
| `resume.ts` | `ResumeOptions`, `ResumeSource`, `ResumeWindow`. |
|
|
348
|
-
|
|
349
|
-
The shape types describe operation declarations, the bound types describe client members, and the rejection types derive classes and failures from declared specs. A native resume source receives a callback and returns a cleanup function. `ResumeWindow` describes the browser event and visibility methods the signal uses.
|
|
366
|
+
A query atom takes native query options as its optional second argument, for example `api.get.query({ id: 1 }, { timeToLive: "1 minute" })`. A native resume source receives a callback and returns a cleanup function.
|
|
350
367
|
|
|
351
368
|
### Install, setup and limits
|
|
352
369
|
|
|
@@ -354,16 +371,10 @@ The shape types describe operation declarations, the bound types describe client
|
|
|
354
371
|
pnpm add @shivaedev/effect-contract effect@4.0.4
|
|
355
372
|
```
|
|
356
373
|
|
|
357
|
-
`effect` is a peer
|
|
374
|
+
`effect` is a peer, and the package needs Node.js 24 or newer. Choose the native server host separately; this package supplies no server process or HTTP transport implementation.
|
|
358
375
|
|
|
359
376
|
- Put schema declarations where server and browser can share them. Put service, authorization and transaction implementations on the server. React rendering and editable forms belong to `effect-react` and `effect-form`.
|
|
360
377
|
- Run command Effects with the Reactivity instance that owns the queries to refresh, as in the registry example.
|
|
361
378
|
- Choose a common read key for every query in a full reconciliation scope. A list key does not implicitly cover item queries.
|
|
362
|
-
- Supply browser or native resume sources explicitly.
|
|
363
|
-
- Live hints carry refresh requests, not authoritative data or durable history. Applications own dependency discovery, authenticated subscriptions, delivery across processes, SSR and deployment behavior.
|
|
364
|
-
|
|
365
|
-
The package's design priorities are in [docs/north-star.md](docs/north-star.md), and package work and maintainer questions are in [docs/roadmap.md](docs/roadmap.md).
|
|
366
|
-
|
|
367
|
-
### Server hint streams
|
|
368
|
-
|
|
369
|
-
Import `makeLiveServer` from `@shivaedev/effect-contract/makeLiveServer.ts` and create it once with the server's `Reactivity` service. After application authorization, return `hints.stream([orders.item(id)])` from the native streaming RPC handler. Each subscription starts with `Resync`; invalidating its read keys produces `Changed` with those declared keys. `hints.resync` sends `Resync` to every live stream owned by that helper, including streams for otherwise unrelated keys. Independent helpers keep their resync scopes separate even when they share Reactivity. The native stream owns registration and interruption. Keep this server helper separate from the browser's `live` coordinator.
|
|
379
|
+
- Supply browser or native resume sources explicitly.
|
|
380
|
+
- Live hints carry refresh requests, not authoritative data or durable history. Applications own dependency discovery, authenticated subscriptions, delivery across processes, SSR and deployment behavior.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type * as Atom from "effect/reactivity/Atom";
|
|
2
|
+
import type * as AtomRpc from "effect/reactivity/AtomRpc";
|
|
3
|
+
import { type Key } from "./keys.ts";
|
|
4
|
+
import { type LiveStatus } from "./live.ts";
|
|
5
|
+
import type { changesRpc } from "./serverMetadata.ts";
|
|
6
|
+
export declare const LiveConnection: unique symbol;
|
|
7
|
+
export interface LiveBound {
|
|
8
|
+
readonly [LiveConnection]: {
|
|
9
|
+
readonly connection: Atom.Atom<unknown>;
|
|
10
|
+
readonly status: Atom.Atom<LiveStatus<unknown>>;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export type ChangesClient = AtomRpc.AtomRpcClient<unknown, string, ReturnType<typeof changesRpc>>;
|
|
14
|
+
export declare function automaticLive(service: ChangesClient, name: string): {
|
|
15
|
+
subscription: {
|
|
16
|
+
connection: Atom.Atom<import("effect/reactivity/AsyncResult").AsyncResult<void, never>>;
|
|
17
|
+
paused: Atom.Writable<boolean, boolean>;
|
|
18
|
+
status: Atom.Writable<LiveStatus<import("effect/rpc/RpcClientError").RpcClientError>, LiveStatus<import("effect/rpc/RpcClientError").RpcClientError>>;
|
|
19
|
+
};
|
|
20
|
+
track: (reads: readonly Key[]) => void;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=automaticLive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"automaticLive.d.ts","sourceRoot":"","sources":["../src/automaticLive.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,KAAK,OAAO,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,KAAK,GAAG,EAAY,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,KAAK,UAAU,EAAQ,MAAM,WAAW,CAAC;AAElD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAItD,eAAO,MAAM,cAAc,eAA0D,CAAC;AACtF,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,CAAC,cAAc,CAAC,EAAE;QAAE,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAA;KAAE,CAAC;CACxH;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC;AAElG,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM;;;;;;mBAG3C,SAAS,GAAG,EAAE;EAuBpC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Effect, Stream, SubscriptionRef } from "effect";
|
|
2
|
+
import { readKeys } from "./keys.js";
|
|
3
|
+
import { live } from "./live.js";
|
|
4
|
+
import { resumeSignal } from "./resume.js";
|
|
5
|
+
export const LiveConnection = Symbol.for("@shivaedev/effect-contract/LiveConnection");
|
|
6
|
+
export function automaticLive(service, name) {
|
|
7
|
+
const keys = Effect.runSync(SubscriptionRef.make([]));
|
|
8
|
+
const known = new Set();
|
|
9
|
+
function track(reads) {
|
|
10
|
+
const fresh = reads.filter((key) => {
|
|
11
|
+
const id = readKeys([key])[0] ?? "";
|
|
12
|
+
if (known.has(id)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
known.add(id);
|
|
16
|
+
return true;
|
|
17
|
+
});
|
|
18
|
+
if (fresh.length > 0) {
|
|
19
|
+
Effect.runSync(SubscriptionRef.update(keys, (current) => [...current, ...fresh]));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const subscription = live(service.runtime, {
|
|
23
|
+
resume: resumeSignal(typeof window === "undefined" ? {} : { window }),
|
|
24
|
+
resyncKeys: () => Effect.runSync(SubscriptionRef.get(keys)),
|
|
25
|
+
stream: SubscriptionRef.changes(keys).pipe(Stream.switchMap((current) => current.length === 0 ? Stream.never : Stream.unwrap(service.use((client) => Effect.succeed(client(`${name}.$changes`, { keys: current })))))),
|
|
26
|
+
});
|
|
27
|
+
return { subscription, track };
|
|
28
|
+
}
|
|
29
|
+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nF,CAAC;IACF,CAAC;IACD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;QAC1C,MAAM,EAAE,YAAY,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;QACrE,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC3D,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CACzC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAC5B,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,WAAW,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAC3I,CACD;KACD,CAAC,CAAC;IACH,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;AAChC,CAAC"}
|
package/dist/bind.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type * as AtomRpc from "effect/reactivity/AtomRpc";
|
|
|
7
7
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
8
8
|
import type { Rpc } from "effect/rpc";
|
|
9
9
|
import type { RpcClientError } from "effect/rpc/RpcClientError";
|
|
10
|
+
import { type LiveBound } from "./automaticLive.ts";
|
|
10
11
|
import type { Contract, Tag } from "./contract.ts";
|
|
11
12
|
import type { CommandShape, QueryShape, StreamShape } from "./operation.ts";
|
|
12
13
|
export type Failure<R extends Rpc.Any> = R extends Rpc.Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer TMiddleware, infer _Requires> ? Rpc.ErrorExit<R> | TMiddleware["error"]["Type"] | RpcClientError : never;
|
|
@@ -38,6 +39,6 @@ type MatchingClient<TRpcs extends Rpc.Any, TClientRpcs extends Rpc.Any> = [TRpcs
|
|
|
38
39
|
}>] ? [Extract<TClientRpcs, {
|
|
39
40
|
readonly _tag: TRpcs["_tag"];
|
|
40
41
|
}>] extends [TRpcs] ? unknown : "Client must preserve the contract RPC types" : "Client must implement the contract RPCs";
|
|
41
|
-
export declare function bind<TName extends string, TQueries extends readonly QueryShape[], TCommands extends readonly CommandShape[], TRpcs extends Rpc.Any, TSelf, TId extends string, TClientRpcs extends Rpc.Any, TStreams extends readonly StreamShape[]>(contract: Contract<TName, TQueries, TCommands, TRpcs, TStreams>, service: AtomRpc.AtomRpcClient<TSelf, TId, TClientRpcs> & MatchingClient<NoInfer<TRpcs>, TClientRpcs>): Bound<TName, TQueries, TCommands, TRpcs, TSelf, TStreams
|
|
42
|
+
export declare function bind<TName extends string, TQueries extends readonly QueryShape[], TCommands extends readonly CommandShape[], TRpcs extends Rpc.Any, TSelf, TId extends string, TClientRpcs extends Rpc.Any, TStreams extends readonly StreamShape[]>(contract: Contract<TName, TQueries, TCommands, TRpcs, TStreams>, service: AtomRpc.AtomRpcClient<TSelf, TId, TClientRpcs> & MatchingClient<NoInfer<TRpcs>, TClientRpcs>): Bound<TName, TQueries, TCommands, TRpcs, TSelf, TStreams> & LiveBound;
|
|
42
43
|
export {};
|
|
43
44
|
//# sourceMappingURL=bind.d.ts.map
|
package/dist/bind.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../src/bind.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAU,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAA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/reactivity/Reactivity";
|
|
3
|
+
import { automaticLive, LiveConnection } from "./automaticLive.js";
|
|
3
4
|
import { invalidationKeys, readKeys } from "./keys.js";
|
|
4
5
|
const invalidateAfter = Effect.fn("EffectContract.invalidateAfter")(function* (keys) {
|
|
5
6
|
yield* Reactivity.invalidate(invalidationKeys(keys));
|
|
6
7
|
});
|
|
7
|
-
function boundQuery(service, tag, query) {
|
|
8
|
+
function boundQuery(service, tag, query, track) {
|
|
8
9
|
function reads(payload) {
|
|
9
10
|
return readKeys(query.reads(payload));
|
|
10
11
|
}
|
|
11
12
|
return {
|
|
12
|
-
query: (payload, options = {}) =>
|
|
13
|
+
query: (payload, options = {}) => {
|
|
14
|
+
track(query.reads(payload));
|
|
15
|
+
return service.query(tag, payload, { ...options, reactivityKeys: reads(payload) });
|
|
16
|
+
},
|
|
13
17
|
run: (payload) => service.use((client) => client(tag, payload)),
|
|
14
18
|
};
|
|
15
19
|
}
|
|
@@ -25,10 +29,11 @@ function boundStream(service, tag) {
|
|
|
25
29
|
}
|
|
26
30
|
export function bind(contract, service) {
|
|
27
31
|
const { name, queries, commands, streams } = contract.declaration;
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
const automatic = automaticLive(service, name);
|
|
33
|
+
return Object.assign(Object.fromEntries([
|
|
34
|
+
...queries.map((query) => [query.name, boundQuery(service, `${name}.${query.name}`, query, automatic.track)]),
|
|
30
35
|
...commands.map((command) => [command.name, boundCommand(service, `${name}.${command.name}`, command)]),
|
|
31
36
|
...streams.map((stream) => [stream.name, boundStream(service, `${name}.${stream.name}`)]),
|
|
32
|
-
]);
|
|
37
|
+
]), { [LiveConnection]: automatic.subscription });
|
|
33
38
|
}
|
|
34
39
|
//# sourceMappingURL=bind.js.map
|
package/dist/bind.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind.js","sourceRoot":"","sources":["../src/bind.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE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,CAAC,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,CAAU,CAAC;QAChH,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAU,CAAC;KAClG,CAAC,EACF,EAAE,CAAC,cAAc,CAAC,EAAE,SAAS,CAAC,YAAY,EAAE,CAC5C,CAAC;AACH,CAAC"}
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Schema } from "effect";
|
|
2
2
|
import { Rpc, RpcGroup, type RpcMiddleware, type RpcSchema } from "effect/rpc";
|
|
3
3
|
import type { CommandShape, OperationShape, QueryShape, StreamShape } from "./operation.ts";
|
|
4
4
|
export type Tag<TContract extends string, TName extends string> = `${TContract}.${TName}`;
|
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG5F,MAAM,MAAM,GAAG,CAAC,SAAS,SAAS,MAAM,EAAE,KAAK,SAAS,MAAM,IAAI,GAAG,SAAS,IAAI,K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,EAAE;IACX,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/C,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC,CAAC,GAAG,QAAQ,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC;IACpE,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC,CAAC,GAAG,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC;CAC/E,GACC,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC"}
|
package/dist/contract.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
import { Context } from "effect";
|
|
1
2
|
import { Rpc, RpcGroup } from "effect/rpc";
|
|
3
|
+
import { CommandInvalidation, changesRpc, QueryReads } from "./serverMetadata.js";
|
|
2
4
|
function assertUnique(operations) {
|
|
3
5
|
const duplicated = operations.map(({ name }) => name).filter((name, index, names) => names.indexOf(name) !== index);
|
|
4
6
|
if (duplicated.length > 0) {
|
|
5
7
|
throw new Error(`Operation names must be unique; duplicated: ${[...new Set(duplicated)].join(", ")}`);
|
|
6
8
|
}
|
|
7
9
|
}
|
|
10
|
+
function annotations(operation) {
|
|
11
|
+
if (operation.kind === "command") {
|
|
12
|
+
return Context.make(CommandInvalidation, operation.invalidates);
|
|
13
|
+
}
|
|
14
|
+
return operation.kind === "query" ? Context.make(QueryReads, operation.reads) : Context.empty();
|
|
15
|
+
}
|
|
8
16
|
function withDeclaration(group, declaration) {
|
|
9
17
|
const nativeMiddleware = group.middleware.bind(group);
|
|
10
18
|
return Object.assign(group, {
|
|
@@ -20,7 +28,7 @@ export function contract(name, operations) {
|
|
|
20
28
|
payload: operation.payload,
|
|
21
29
|
stream: operation.kind === "stream",
|
|
22
30
|
success: operation.success,
|
|
23
|
-
}));
|
|
24
|
-
return withDeclaration(RpcGroup.make(...rpcs), { commands, name, queries, streams });
|
|
31
|
+
}).annotateMerge(annotations(operation)));
|
|
32
|
+
return withDeclaration(RpcGroup.make(...rpcs, changesRpc(name)), { commands, name, queries, streams });
|
|
25
33
|
}
|
|
26
34
|
//# sourceMappingURL=contract.js.map
|
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAsC,MAAM,YAAY,CAAC;AAE/E,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AA4ClF,SAAS,YAAY,CAAC,UAAqC;IAC1D,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC;IACpH,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvG,CAAC;AACF,CAAC;AAED,SAAS,WAAW,CAAC,SAAkD;IACtE,IAAI,SAAS,CAAC,IAAI,KAAK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KAC1B,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CACxC,CAAC;IACF,OAAO,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;AACxG,CAAC"}
|
package/dist/keys.d.ts
CHANGED
|
@@ -23,9 +23,9 @@ export interface Collection<TName extends string, TId extends Identity> {
|
|
|
23
23
|
readonly list: ListKey<TName>;
|
|
24
24
|
readonly name: TName;
|
|
25
25
|
}
|
|
26
|
-
export declare
|
|
26
|
+
export declare function collection<const TName extends string, TId extends Schema.Top & {
|
|
27
27
|
readonly Type: Identity;
|
|
28
|
-
}>(name: TName, _id: TId)
|
|
29
|
-
export declare
|
|
30
|
-
export declare
|
|
28
|
+
}>(name: TName, _id: TId): Collection<TName, TId["Type"]>;
|
|
29
|
+
export declare function readKeys(keys: readonly Key[]): readonly string[];
|
|
30
|
+
export declare function invalidationKeys(keys: readonly Key[]): readonly string[];
|
|
31
31
|
//# sourceMappingURL=keys.d.ts.map
|
package/dist/keys.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvC,MAAM,WAAW,OAAO,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC;CAC3B;AAED,MAAM,WAAW,OAAO,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CA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CAAC,KAAK,CAAC,CAAC;IAC3C,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;CACrB;AAED,wBAAgB,UAAU,CAAC,KAAK,CAAC,KAAK,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,CAAC,GAAG,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,EAC1G,IAAI,EAAE,KAAK,EACX,GAAG,EAAE,GAAG,GACN,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAMhC;AAMD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,GAAG,SAAS,MAAM,EAAE,CAEhE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,GAAG,SAAS,MAAM,EAAE,CAExE"}
|
package/dist/keys.js
CHANGED
|
@@ -3,16 +3,20 @@ export const Key = Schema.Union([
|
|
|
3
3
|
Schema.Struct({ _tag: Schema.Literal("List"), collection: Schema.String }),
|
|
4
4
|
Schema.Struct({ _tag: Schema.Literal("Item"), collection: Schema.String, id: Schema.Union([Schema.String, Schema.Number]) }),
|
|
5
5
|
]);
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
export function collection(name, _id) {
|
|
7
|
+
return {
|
|
8
|
+
item: (id) => ({ _tag: "Item", collection: name, id }),
|
|
9
|
+
list: { _tag: "List", collection: name },
|
|
10
|
+
name,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
11
13
|
function own(key) {
|
|
12
14
|
return key._tag === "List" ? key.collection : `${key.collection}:${key.id}`;
|
|
13
15
|
}
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
export function readKeys(keys) {
|
|
17
|
+
return [...new Set(keys.map(own))];
|
|
18
|
+
}
|
|
19
|
+
export function invalidationKeys(keys) {
|
|
20
|
+
return [...new Set(keys.flatMap((key) => (key._tag === "List" ? [key.collection] : [own(key), key.collection])))];
|
|
21
|
+
}
|
|
18
22
|
//# sourceMappingURL=keys.js.map
|
package/dist/keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAiBhC,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC;IAC/B,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;IAC1E,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;CAC5H,CAAC,CAAC;AAQH,MAAM,
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAiBhC,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC;IAC/B,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;IAC1E,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM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known>;
|
|
26
|
-
readonly resyncKeys: readonly Key[];
|
|
26
|
+
readonly resyncKeys: readonly Key[] | (() => readonly Key[]);
|
|
27
27
|
readonly retryDelay?: Duration.Input;
|
|
28
28
|
readonly stream: Stream.Stream<LiveHint, E, R>;
|
|
29
29
|
}
|
package/dist/live.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live.d.ts","sourceRoot":"","sources":["../src/live.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,QAAQ,EAAU,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACnF,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAE/C,OAAO,EAAoB,GAAG,EAAY,MAAM,WAAW,CAAC;AAE5D,eAAO,MAAM,QAAQ;;;;;;;;;;;;IAGnB,CAAC;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAC;AAC5C,MAAM,WAAW,UAAU,CAAC,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,YAAY,GAAG,MAAM,GAAG,cAAc,CAAC;IAC5D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB;AACD,MAAM,WAAW,WAAW,CAAC,CAAC,EAAE,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrC,QAAQ,CAAC,UAAU,EAAE,SAAS,GAAG,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"live.d.ts","sourceRoot":"","sources":["../src/live.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,QAAQ,EAAU,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: true });
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
-
reactivity.invalidateUnsafe(readKeys(options.resyncKeys));
|
|
25
|
+
reactivity.invalidateUnsafe(readKeys(typeof options.resyncKeys === "function" ? options.resyncKeys() : options.resyncKeys));
|
|
26
26
|
update({ needsResync: false, pending: 0 });
|
|
27
27
|
}
|
|
28
|
+
// A subscription alone does not build the flag, so its first read would otherwise announce a change.
|
|
29
|
+
get.once(paused);
|
|
28
30
|
get.subscribe(paused, (value) => {
|
|
29
31
|
if (!value) {
|
|
30
32
|
resync();
|
package/dist/live.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live.js","sourceRoot":"","sources":["../src/live.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACnF,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE5D,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC;IACpC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;IAC3E,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;CACjD,CAAC,CAAC;AAeH,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,MAAM,UAAU,IAAI,CAAsB,OAA2C,EAAE,OAA0B;IAChH,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,MAAM,MAAM,GAAG,IAAI,CAAC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BAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC1D,CAAC;gBACD,OAAO,GAAG,KAAK,CAAC;YACjB,CAAC;YACD,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CACzB,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAC7D,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAC5F,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAC5F,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,IAAI,UAAU,CAAC,CAAC,CAC9D,CAAC;QACH,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC,CAAC,CACF;SACA,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACvC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeLiveServer.d.ts","sourceRoot":"","sources":["../src/makeLiveServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"makeLiveServer.d.ts","sourceRoot":"","sources":["../src/makeLiveServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAS,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,KAAK,GAAG,EAAY,MAAM,WAAW,CAAC;AAI/C,eAAO,MAAM,cAAc;;mBAGJ,SAAS,GAAG,EAAE;;;;;;;;;;;;;gCA4DnC,CAAC"}
|
package/dist/makeLiveServer.js
CHANGED
|
@@ -1,24 +1,56 @@
|
|
|
1
|
-
import { Effect, Stream } from "effect";
|
|
1
|
+
import { Effect, Queue, Stream } from "effect";
|
|
2
2
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
3
|
import { readKeys } from "./keys.js";
|
|
4
|
+
import { ReadPolicy } from "./readPolicy.js";
|
|
4
5
|
export const makeLiveServer = Effect.gen(function* () {
|
|
5
6
|
const reactivity = yield* Reactivity.Reactivity;
|
|
6
7
|
const resyncKey = `@shivaedev/effect-contract/resync/${crypto.randomUUID()}`;
|
|
7
|
-
let generation = 0;
|
|
8
8
|
function stream(keys) {
|
|
9
|
-
return Stream.unwrap(Effect.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
return Stream.unwrap(Effect.gen(function* () {
|
|
10
|
+
const canRead = yield* ReadPolicy;
|
|
11
|
+
const queue = yield* Queue.unbounded();
|
|
12
|
+
const pending = new Map();
|
|
13
|
+
let scheduled = false;
|
|
14
|
+
let resync = false;
|
|
15
|
+
let active = true;
|
|
16
|
+
function flush() {
|
|
17
|
+
if (scheduled) {
|
|
18
|
+
return;
|
|
15
19
|
}
|
|
16
|
-
|
|
20
|
+
scheduled = true;
|
|
21
|
+
queueMicrotask(() => {
|
|
22
|
+
scheduled = false;
|
|
23
|
+
if (active) {
|
|
24
|
+
Queue.offerUnsafe(queue, resync ? { _tag: "Resync" } : { _tag: "Changed", keys: [...pending.values()] });
|
|
25
|
+
}
|
|
26
|
+
pending.clear();
|
|
27
|
+
resync = false;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const cancel = keys.map((key) => {
|
|
31
|
+
const own = readKeys([key]);
|
|
32
|
+
return reactivity.registerUnsafe(own, () => {
|
|
33
|
+
pending.set(own[0] ?? "", key);
|
|
34
|
+
flush();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
cancel.push(reactivity.registerUnsafe([resyncKey], () => {
|
|
38
|
+
resync = true;
|
|
39
|
+
flush();
|
|
17
40
|
}));
|
|
41
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => {
|
|
42
|
+
active = false;
|
|
43
|
+
for (const stop of cancel) {
|
|
44
|
+
stop();
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
yield* Queue.offer(queue, { _tag: "Resync" });
|
|
48
|
+
return Stream.fromQueue(queue).pipe(Stream.mapEffect((hint) => hint._tag === "Resync"
|
|
49
|
+
? Effect.succeed(hint)
|
|
50
|
+
: Effect.map(Effect.filter(hint.keys, canRead), (allowed) => ({ _tag: "Changed", keys: allowed }))), Stream.filter((hint) => hint._tag === "Resync" || hint.keys.length > 0));
|
|
18
51
|
}));
|
|
19
52
|
}
|
|
20
53
|
const resync = Effect.sync(() => {
|
|
21
|
-
generation += 1;
|
|
22
54
|
reactivity.invalidateUnsafe([resyncKey]);
|
|
23
55
|
});
|
|
24
56
|
return { resync, stream };
|