@shivaedev/contract 0.44.0 → 0.46.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 +22 -0
- package/README.md +73 -37
- package/dist/AutomaticQueryOptions.d.ts +2 -0
- package/dist/AutomaticQueryOptions.d.ts.map +1 -1
- package/dist/CommandGuard.d.ts +2 -1
- package/dist/CommandGuard.d.ts.map +1 -1
- package/dist/CommandGuard.js +3 -2
- package/dist/CommandGuard.js.map +1 -1
- package/dist/HostVersion.d.ts +6 -1
- package/dist/HostVersion.d.ts.map +1 -1
- package/dist/LiveSync.d.ts +18 -0
- package/dist/LiveSync.d.ts.map +1 -0
- package/dist/LiveSync.js +9 -0
- package/dist/LiveSync.js.map +1 -0
- package/dist/adapters/activityState.d.ts +3 -2
- package/dist/adapters/activityState.d.ts.map +1 -1
- package/dist/adapters/activityState.js +12 -1
- package/dist/adapters/activityState.js.map +1 -1
- package/dist/adapters/clientConnection.d.ts +1 -0
- package/dist/adapters/clientConnection.d.ts.map +1 -1
- package/dist/adapters/clientConnection.js +18 -10
- package/dist/adapters/clientConnection.js.map +1 -1
- package/dist/adapters/liveHintStream.d.ts +3 -19
- package/dist/adapters/liveHintStream.d.ts.map +1 -1
- package/dist/adapters/liveHintStream.js +2 -2
- package/dist/adapters/liveHintStream.js.map +1 -1
- package/dist/adapters/openLiveHints.d.ts +3 -19
- package/dist/adapters/openLiveHints.d.ts.map +1 -1
- package/dist/adapters/openLiveHints.js +21 -3
- package/dist/adapters/openLiveHints.js.map +1 -1
- package/dist/adapters/standaloneLiveServer.d.ts +5 -18
- package/dist/adapters/standaloneLiveServer.d.ts.map +1 -1
- package/dist/adapters/standaloneLiveServer.js +6 -1
- package/dist/adapters/standaloneLiveServer.js.map +1 -1
- package/dist/automaticLive.d.ts.map +1 -1
- package/dist/automaticLive.js +21 -1
- package/dist/automaticLive.js.map +1 -1
- package/dist/automaticQuery.d.ts +1 -1
- package/dist/automaticQuery.d.ts.map +1 -1
- package/dist/automaticQuery.js +7 -1
- package/dist/automaticQuery.js.map +1 -1
- package/dist/bind.js +3 -2
- package/dist/bind.js.map +1 -1
- package/dist/catchUp.d.ts +6 -0
- package/dist/catchUp.d.ts.map +1 -0
- package/dist/catchUp.js +9 -0
- package/dist/catchUp.js.map +1 -0
- package/dist/changesSuccess.d.ts +2 -1
- package/dist/changesSuccess.d.ts.map +1 -1
- package/dist/changesSuccess.js +3 -0
- package/dist/changesSuccess.js.map +1 -1
- package/dist/clientActivities.d.ts +4 -0
- package/dist/clientActivities.d.ts.map +1 -1
- package/dist/clientActivities.js +8 -3
- package/dist/clientActivities.js.map +1 -1
- package/dist/clientActivity.d.ts +3 -0
- package/dist/clientActivity.d.ts.map +1 -1
- package/dist/clientActivity.js +1 -1
- package/dist/clientActivity.js.map +1 -1
- package/dist/clientOperations.d.ts +1 -0
- package/dist/clientOperations.d.ts.map +1 -1
- package/dist/clientOperations.js +17 -1
- package/dist/clientOperations.js.map +1 -1
- package/dist/clientOptions.d.ts +1 -0
- package/dist/clientOptions.d.ts.map +1 -1
- package/dist/commandSignal.d.ts +5 -0
- package/dist/commandSignal.d.ts.map +1 -0
- package/dist/commandSignal.js +25 -0
- package/dist/commandSignal.js.map +1 -0
- package/dist/connectionProtocol.d.ts +10 -14
- package/dist/connectionProtocol.d.ts.map +1 -1
- package/dist/connectionProtocol.js +8 -3
- package/dist/connectionProtocol.js.map +1 -1
- package/dist/defineModule.js +1 -1
- package/dist/defineModule.js.map +1 -1
- package/dist/live-server/initialize.d.ts +1 -0
- package/dist/live-server/initialize.d.ts.map +1 -1
- package/dist/live-server/initialize.js +2 -1
- package/dist/live-server/initialize.js.map +1 -1
- package/dist/live-server/register.d.ts +2 -19
- package/dist/live-server/register.d.ts.map +1 -1
- package/dist/live-server/register.js +2 -2
- package/dist/live-server/register.js.map +1 -1
- package/dist/live-server/service.d.ts +7 -37
- package/dist/live-server/service.d.ts.map +1 -1
- package/dist/live-server/service.js +2 -0
- package/dist/live-server/service.js.map +1 -1
- package/dist/live-server/stream.d.ts +1 -18
- package/dist/live-server/stream.d.ts.map +1 -1
- package/dist/live-server/stream.js +2 -2
- package/dist/live-server/stream.js.map +1 -1
- package/dist/live-server/subscribe.d.ts.map +1 -1
- package/dist/live-server/subscribe.js +6 -2
- package/dist/live-server/subscribe.js.map +1 -1
- package/dist/live-server/syncFrames.d.ts +5 -0
- package/dist/live-server/syncFrames.d.ts.map +1 -0
- package/dist/live-server/syncFrames.js +16 -0
- package/dist/live-server/syncFrames.js.map +1 -0
- package/dist/live-server/synced.d.ts +7 -0
- package/dist/live-server/synced.d.ts.map +1 -0
- package/dist/live-server/synced.js +11 -0
- package/dist/live-server/synced.js.map +1 -0
- package/dist/liveHintQueue.d.ts +5 -19
- package/dist/liveHintQueue.d.ts.map +1 -1
- package/dist/liveHintQueue.js +4 -2
- package/dist/liveHintQueue.js.map +1 -1
- package/dist/liveRetry.d.ts +1 -0
- package/dist/liveRetry.d.ts.map +1 -1
- package/dist/liveRetry.js +5 -2
- package/dist/liveRetry.js.map +1 -1
- package/dist/liveSyncRequest.d.ts +6 -0
- package/dist/liveSyncRequest.d.ts.map +1 -0
- package/dist/liveSyncRequest.js +7 -0
- package/dist/liveSyncRequest.js.map +1 -0
- package/dist/liveSyncRpc.d.ts +7 -0
- package/dist/liveSyncRpc.d.ts.map +1 -0
- package/dist/liveSyncRpc.js +10 -0
- package/dist/liveSyncRpc.js.map +1 -0
- package/dist/makeLiveServer.d.ts +5 -18
- package/dist/makeLiveServer.d.ts.map +1 -1
- package/dist/publicConfig.d.ts +6 -1
- package/dist/publicConfig.d.ts.map +1 -1
- package/dist/queryDelivery.d.ts +2 -1
- package/dist/queryDelivery.d.ts.map +1 -1
- package/dist/queryDelivery.js +20 -4
- package/dist/queryDelivery.js.map +1 -1
- package/dist/querySubscription.d.ts +1 -0
- package/dist/querySubscription.d.ts.map +1 -1
- package/dist/querySubscription.js.map +1 -1
- package/dist/queryUpdate.d.ts +15 -1
- package/dist/queryUpdate.d.ts.map +1 -1
- package/dist/queryUpdate.js +4 -0
- package/dist/queryUpdate.js.map +1 -1
- package/dist/reflectCommand.d.ts +10 -0
- package/dist/reflectCommand.d.ts.map +1 -0
- package/dist/reflectCommand.js +35 -0
- package/dist/reflectCommand.js.map +1 -0
- package/dist/reflectedStream.d.ts +18 -0
- package/dist/reflectedStream.d.ts.map +1 -0
- package/dist/reflectedStream.js +35 -0
- package/dist/reflectedStream.js.map +1 -0
- package/dist/reflection.d.ts +26 -0
- package/dist/reflection.d.ts.map +1 -0
- package/dist/reflection.js +94 -0
- package/dist/reflection.js.map +1 -0
- package/dist/rpcClient.d.ts +4 -2
- package/dist/rpcClient.d.ts.map +1 -1
- package/dist/rpcClient.js +12 -6
- package/dist/rpcClient.js.map +1 -1
- package/dist/screenSync.d.ts +8 -0
- package/dist/screenSync.d.ts.map +1 -0
- package/dist/screenSync.js +6 -0
- package/dist/screenSync.js.map +1 -0
- package/dist/socketProtocol.d.ts +1 -1
- package/dist/socketProtocol.d.ts.map +1 -1
- package/dist/syncHeader.d.ts +7 -0
- package/dist/syncHeader.d.ts.map +1 -0
- package/dist/syncHeader.js +22 -0
- package/dist/syncHeader.js.map +1 -0
- package/package.json +9 -9
- package/src/AutomaticQueryOptions.ts +2 -0
- package/src/CommandGuard.ts +12 -4
- package/src/LiveSync.ts +9 -0
- package/src/adapters/activityState.ts +13 -3
- package/src/adapters/clientConnection.ts +24 -16
- package/src/adapters/liveHintStream.ts +6 -2
- package/src/adapters/openLiveHints.ts +25 -3
- package/src/adapters/standaloneLiveServer.ts +6 -1
- package/src/automaticLive.ts +24 -2
- package/src/automaticQuery.ts +7 -0
- package/src/bind.ts +3 -2
- package/src/catchUp.ts +21 -0
- package/src/changesSuccess.ts +4 -1
- package/src/clientActivities.ts +9 -4
- package/src/clientActivity.ts +4 -1
- package/src/clientOperations.ts +28 -10
- package/src/clientOptions.ts +1 -0
- package/src/commandSignal.ts +27 -0
- package/src/connectionProtocol.ts +9 -3
- package/src/defineModule.ts +1 -1
- package/src/live-server/initialize.ts +2 -1
- package/src/live-server/register.ts +2 -2
- package/src/live-server/service.ts +2 -0
- package/src/live-server/stream.ts +2 -2
- package/src/live-server/subscribe.ts +10 -4
- package/src/live-server/syncFrames.ts +19 -0
- package/src/live-server/synced.ts +13 -0
- package/src/liveHintQueue.ts +9 -4
- package/src/liveRetry.ts +6 -2
- package/src/liveSyncRequest.ts +17 -0
- package/src/liveSyncRpc.ts +11 -0
- package/src/queryDelivery.ts +29 -5
- package/src/querySubscription.ts +1 -0
- package/src/queryUpdate.ts +7 -1
- package/src/reflectCommand.ts +48 -0
- package/src/reflectedStream.ts +54 -0
- package/src/reflection.ts +110 -0
- package/src/rpcClient.ts +12 -6
- package/src/screenSync.ts +10 -0
- package/src/syncHeader.ts +27 -0
- package/dist/liveAnswers.d.ts +0 -9
- package/dist/liveAnswers.d.ts.map +0 -1
- package/dist/liveAnswers.js +0 -12
- package/dist/liveAnswers.js.map +0 -1
- package/src/liveAnswers.ts +0 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.46.0 - 2026-11-18
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- A command run through a client from `makeClient` has three states: `sent`, `accepted` when its reply arrives, and `reflected` when every live query open on the same connection shows the server's state after the command. `untilReflected` from `@shivaedev/contract/commandSignal.ts` completes a command's Effect at `reflected`, and `CommandSignal` from the same module receives each state. A command that publishes nothing is reflected without waiting for an update, and a failed command leaves nothing to wait for. Work a command starts for later, such as a job, is not covered.
|
|
8
|
+
- `sync` on the value `makeClient` returns waits the same way without writing anything, so a client can wait for a write it did not make. It sends the `platform.liveSync.request` command of `LiveSync` from `@shivaedev/contract/LiveSync.ts`.
|
|
9
|
+
- Client activity has an `unreflectedCommands` count, which holds a command from the moment it is sent until it is reflected or fails.
|
|
10
|
+
- `LiveServer` and `makeLiveServer` have `synced(token)`, which queues a sync token in the subscriptions of the client it names, and `register` and `stream` take that client's name. A `$changes` request that names its client in the `x-shivaedev-sync` header receives `Syncing` and `Synced` frames; other requests receive the same frames as before.
|
|
11
|
+
|
|
12
|
+
### Breaking
|
|
13
|
+
|
|
14
|
+
- `isClientSettled` also waits for `unreflectedCommands` to reach zero, so a screen story's `settle()` returns after a command's change is on the screen. Code that builds a `ClientActivityState` by hand adds `unreflectedCommands: 0`.
|
|
15
|
+
- The `$changes` stream's success type and `QueryUpdate` include `Syncing` and `Synced`. Code that matches every `QueryUpdate` tag adds the two cases; a consumer that sends no `x-shivaedev-sync` header never receives them.
|
|
16
|
+
- The `CommandBoundary` of `commandGuardLayer` receives the command's sync token as a third argument. A custom boundary passes it to `CommandPublication.publish(keys, sync)`.
|
|
17
|
+
- A client from `makeClient` also declares the `platform.liveSync.request` command. A custom native RPC host that passes `syncClient` to its subscriptions merges `LiveSync.application` into its group and handles the command with `Effect.void`. A host that does neither needs no change: its clients' commands are reflected as soon as they are accepted.
|
|
18
|
+
|
|
19
|
+
## 0.45.0 - 2026-11-18
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- The client activity state carries `firstSettled`, the latch behind that hook, and `clientActivity(client)` exposes it as a native `firstSettled` atom beside `connectionStatus`. Code that builds a `ClientActivityState` value itself adds `firstSettled`.
|
|
24
|
+
|
|
3
25
|
## 0.44.0 - 2026-11-11
|
|
4
26
|
|
|
5
27
|
### Added
|
package/README.md
CHANGED
|
@@ -528,6 +528,38 @@ Here `audienceFor` reads household members and people who ate from the pot from
|
|
|
528
528
|
|
|
529
529
|
Use this helper in hosts from `@shivaedev/server`, or a native RPC host wired with `guardCommands` and `commandGuardLayer`. Keys are isolated per command, deduplicated with declared keys, and published through the existing `@shivaedev/changes` command publication boundary after success. A failed handler discards them. They do not enter the browser's pure `invalidates` callback; live subscriptions receive the server’s changed query results.
|
|
530
530
|
|
|
531
|
+
#### When a command's change is on the screen
|
|
532
|
+
|
|
533
|
+
A command's reply arrives before the live queries it changed are updated. A command run through a client from `makeClient` passes through three states in order: `sent` when it leaves, `accepted` when its success reply arrives, and `reflected` when every live query open on the same connection shows the server's state after the command. A failed command stops at `sent`: its failure is the Effect's error and nothing waits. `run` completes at `accepted`. Wrap it with `untilReflected` to complete at `reflected`:
|
|
534
|
+
|
|
535
|
+
```ts
|
|
536
|
+
import { untilReflected } from "@shivaedev/contract/commandSignal.ts";
|
|
537
|
+
|
|
538
|
+
const renamed = untilReflected(api.rename.run({ id: 1, title: "Uno" }));
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
To follow each state, provide `CommandSignal` from the same module to the command's Effect, a function that receives `"sent"`, `"accepted"` and `"reflected"` as they happen. The client applies no optimistic update; `reflected` reports what the server pushed.
|
|
542
|
+
|
|
543
|
+
`sync` on the value `makeClient` returns is an Effect that writes nothing and waits the same way. It completes once every open live query shows the changes committed before it, including writes of other clients through other hosts. Use it to wait for a write this client did not make.
|
|
544
|
+
|
|
545
|
+
```ts
|
|
546
|
+
import { makeClient } from "@shivaedev/contract/bind.ts";
|
|
547
|
+
|
|
548
|
+
const client = makeClient(Notes, { url: "/rpc" });
|
|
549
|
+
const current = client.sync;
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
The wait rests on a sync token. The client names itself on each live stream and numbers each command. When the handler has finished, the host sends that number on the change channel behind the command's keys, and each stream of that client confirms it after the reruns queued ahead of it. The rules that follow from this:
|
|
553
|
+
|
|
554
|
+
- A command that publishes nothing is reflected when its token returns. It waits for no update.
|
|
555
|
+
- The token leaves after the handler's last commit, so a command that commits several transactions is reflected after the last one's update. Work the command starts for later, such as a job, is not covered: `reflected` says nothing about writes made after the handler returned.
|
|
556
|
+
- A query opened while the command was in flight, and a query reopened by a reconnect, may have missed the token. The client then sends a sync of its own once that stream is open, and the command is reflected when the stream has its first result and that sync returns.
|
|
557
|
+
- While the `paused` atom is set, a command stays `accepted`. It is reflected when live queries resume and their reopened streams catch up.
|
|
558
|
+
- When the host's change listener was down, the token is lost. The listener's recovery resyncs every stream, which makes the client sync again, and that releases the wait.
|
|
559
|
+
- A host from before sync tokens never confirms one. The client sees that on the stream's first frame and stops waiting for that query, so against such a host a command is reflected as soon as it is accepted. A client built with a custom `protocol` sends no number on its commands and syncs after each reply instead; when that sync fails, the waits it covered end.
|
|
560
|
+
- Only a stream that names its client receives the confirmation frames. Other clients and other viewers receive the same results as before.
|
|
561
|
+
- A host confirms a token only on the streams of the client it names. The number is no secret: a guessed token can at most end that one client's wait early.
|
|
562
|
+
|
|
531
563
|
### Host build announcements
|
|
532
564
|
|
|
533
565
|
`HostVersion` from `@shivaedev/contract/HostVersion.ts` declares the native `platform.hostVersion.watch` string stream shared by the application host and React's deploy controller. The host announces its configured build ID on subscription, including after a host replacement reconnects. It uses the same shared WebSocket connection as other `makeClient` bindings with matching transport options. Applications normally use the controller from `@shivaedev/react/client/deployUpdate.ts` rather than consuming this stream directly.
|
|
@@ -536,11 +568,11 @@ Use this helper in hosts from `@shivaedev/server`, or a native RPC host wired wi
|
|
|
536
568
|
|
|
537
569
|
`clientActivity(client)` from `@shivaedev/contract/clientActivity.ts` returns a native Effect `Stream` with a `current` Effect for a client made by `makeClient`. Its state includes `connectionStatus`, a `"live" | "reconnecting" | "waiting-for-connection"` value aggregated across mounted queries from all bindings of the same client service, with live subscription changes debounced for 300 ms on the client runtime’s Clock and held commands reported immediately. Refused subscriptions do not count as reconnecting. The stream also exposes its native `connectionStatus` atom for React readers.
|
|
538
570
|
|
|
539
|
-
|
|
571
|
+
The state's `firstSettled` flag is `false` until a mounted query has delivered its first success or failure and, with that, no mounted query awaits a first result and no command is in flight. It then stays `true` for that client: a later command or a newly mounted query does not turn it back, and a client that mounts no query never turns it on. The stream exposes it as its native `firstSettled` atom, which React reads through `useFirstSettled`.
|
|
540
572
|
|
|
541
|
-
`activityScreenSignal(
|
|
573
|
+
For screen stories, pass `activityScreenSignal(clientActivity(client))` to a test-story screen driver's `activity` option. By default, `settle()` waits for commands until they are reflected and for the first result of each mounted query, then flushes the renderer. Contract identifies commands from its own RPC annotations; kits need no query-name exceptions. The activity state's `commands` count includes commands held for a connection, `unreflectedCommands` counts commands from the moment they are sent until they are reflected or fail, and `initialQueries` counts mounted queries until their first success or failure. Unmounting releases that query's pending activity. `isClientSettled(state)` checks these three counts. An open live query that has delivered its first result, including one awaiting a later refresh, does not keep a screen story pending.
|
|
542
574
|
|
|
543
|
-
`
|
|
575
|
+
`activityScreenSignal(activity)` projects the stream and its `current` Effect into `{ pending, connectionStatus }`. The returned shape is structural and carries no test-story dependency. Stories that wait for a write their client did not make pass `screenSync(client, registry)` from `screenSync.ts` as the driver's `sync` option: it runs the client's `sync` through the view's registry, and the driver's `sync()` settles the screen after it. `isClientIdle(state)` retains the full finite-work check: `rpcCalls` for finite calls, `refreshingAtoms` for mounted query atoms awaiting values must all be zero. Long-lived subscription streams and server reruns themselves do not count as finite calls.
|
|
544
576
|
|
|
545
577
|
### Query completion
|
|
546
578
|
|
|
@@ -646,9 +678,9 @@ Visible browser `online` and `visibilitychange` events reopen active subscriptio
|
|
|
646
678
|
|
|
647
679
|
`status` exposes `connection`, `failure`, `needsResync` and `pending`. A resume keeps `connection` unchanged and sets `needsResync` until the reopened subscription delivers its first update, while the query results keep their values and report nothing pending. A typed stream rejection settles as `failed`; transport failures and defects retry with the existing jittered exponential backoff. A denied subscription stays refused through matching local invalidations and resume events; it reopens when the viewer changes or the query is refreshed explicitly. A matching local invalidation still retries a subscription that settled with another failure, such as a declared `NotFound`. A query with no keys in the browser has nothing for a local invalidation to match, so such a subscription stays settled through its contract's commands, and an explicit refresh reopens it. An established subscription remains open after a policy denial so a later authorized change can restore its value. A `$changes` request is authorized as a whole; automatic query atoms subscribe separately so independent permissions remain independent.
|
|
648
680
|
|
|
649
|
-
Custom native hosts use `changesHandlerLayer`, `querySubscription(rpc, references, viewer)` and `subscribe(subscription, read)`. The authorized query runner is required and must use the same handler and read policy as an ordinary read; session-backed hosts must provide a fresh session context on each rerun. Platform's host supplies this composition. The caller owns consumption and interruption of a raw `$changes` stream, whose values are `Result`, `Unchanged` and `QueryReadDenied`.
|
|
681
|
+
Custom native hosts use `changesHandlerLayer`, `querySubscription(rpc, references, viewer)` and `subscribe(subscription, read)`. The authorized query runner is required and must use the same handler and read policy as an ordinary read; session-backed hosts must provide a fresh session context on each rerun. Platform's host supplies this composition. The caller owns consumption and interruption of a raw `$changes` stream, whose values are `Result`, `Unchanged` and `QueryReadDenied`. A request that names its client in the `x-shivaedev-sync` header also receives `Syncing` before each full read and `Synced` with the sync tokens the stream passed; a host passes that name as the subscription's `syncClient`, read with `syncClient(headers)` from `@shivaedev/contract/syncHeader.ts`. The command boundary of `commandGuardLayer` receives the command's sync token as its third argument, and a host without `@shivaedev/server` serves the `LiveSync` contract from `@shivaedev/contract/LiveSync.ts` with a handler that does nothing.
|
|
650
682
|
|
|
651
|
-
Server adapters import `LiveServer` from `@shivaedev/contract/live-server/service.ts` and `liveServerLayer` from `@shivaedev/contract/live-server/layer.ts`. The Layer captures the server's Reactivity service and dispatcher. `register(keys)` provides a scoped registration with `replaceKeys`; `resync()` reconciles its active subscriptions. `makeLiveServer` supplies a standalone server using the same subscription engine. Server hints contain keys, never authoritative row data.
|
|
683
|
+
Server adapters import `LiveServer` from `@shivaedev/contract/live-server/service.ts` and `liveServerLayer` from `@shivaedev/contract/live-server/layer.ts`. The Layer captures the server's Reactivity service and dispatcher. `register(keys, syncClient?)` provides a scoped registration with `replaceKeys`; `resync()` reconciles its active subscriptions; `synced(token)` hands a sync token to the streams registered for the client it names. `makeLiveServer` supplies a standalone server using the same subscription engine. Server hints contain keys, never authoritative row data.
|
|
652
684
|
|
|
653
685
|
### Query policies, record keys and buckets
|
|
654
686
|
|
|
@@ -836,7 +868,7 @@ const client = makeClient(Notes, {
|
|
|
836
868
|
});
|
|
837
869
|
```
|
|
838
870
|
|
|
839
|
-
The URL identifies the client configuration; the in-memory protocol opens no socket. The client's direct calls and bound query atoms use the real handlers, schema decoding and middleware. Live subscriptions use the supplied handlers and change source, and mounted queries refresh from their updates. Closing a subscription interrupts its server stream. The protocol does not add handlers or publish changes: provide the same live handlers and change source that the application serves over WebSocket.
|
|
871
|
+
The URL identifies the client configuration; the in-memory protocol opens no socket. The client's direct calls and bound query atoms use the real handlers, schema decoding and middleware. Live subscriptions use the supplied handlers and change source, and mounted queries refresh from their updates. Closing a subscription interrupts its server stream. The protocol does not add handlers or publish changes: provide the same live handlers and change source that the application serves over WebSocket. It refuses a group the application host would refuse to start, such as one whose RPC uses a field name both as sensitive and as public, with the host's error; the [test-kits README](https://github.com/ShivaeDev/platform/tree/main/packages/test-kits#contract-subscriptions) describes the check.
|
|
840
872
|
|
|
841
873
|
### Settled queries in stories
|
|
842
874
|
|
|
@@ -862,37 +894,41 @@ Observe raw result streams with `watchHints` from `@shivaedev/test-kits/contract
|
|
|
862
894
|
|
|
863
895
|
Import the module that defines the name; the package has no root entry.
|
|
864
896
|
|
|
865
|
-
| Module | Functions and schemas
|
|
866
|
-
| -------------------------- |
|
|
867
|
-
| `operation.ts` | `query(name, { payload?, success?, rejections?, readPolicy, reads?, serverReads? })`; `command(name, { payload?, success?, rejections?, invalidates })`; `query(name, { payload?, *run, readPolicy?, reads?, serverReads?, readsCollections?, success?, rejections? })` and `command(name, { payload?, *run, invalidates?, success?, rejections? })` with an Effect-returning `run`; `stream(name, { payload?, success, rejections?, reads })`.
|
|
868
|
-
| `contract.ts` | `contract(name, { queries?, commands?, streams?, keyScope? })`, returning a native RPC group with `declaration: { name, queries, commands, streams, keyScope }`.
|
|
869
|
-
| `defineModule.ts` | `defineModule({ name, operations, requires, middleware?, subject?, keyScope?, wire? })`, returning the module's contract.
|
|
870
|
-
| `moduleHandlers.ts` | `moduleHandlers(module)`, the module's handler Layer, requiring exactly its `requires`.
|
|
871
|
-
| `clientContract.ts` | `clientContract({ name, wire, payloads?, queries?, commands?, middleware?, subject?, keyScope? })`, the browser's contract of a module that generated files build.
|
|
872
|
-
| `clientMatchesModule.ts` | `ClientMatchesModule<Client, Module>`, `true` when the browser's contract and the server module have the same RPCs, else `ClientDiffersFromModule`.
|
|
873
|
-
| `rejection.ts` | `fieldRejection(struct, fields?)`; lower-level `rejectionSet(specs)`, which constructs the rejection classes, union schema and failure helpers used by operations.
|
|
874
|
-
| `bind.ts` | `bind(contract, atomRpcService, { registry?, live?, resume?, resumeWindow? }?)`, requiring the registry for session-scoped contracts and exposing `{ query, run }` for queries, `{ run }` Effects for commands and `{ run }` native Streams for streams; `makeClient(contract, { url, protocol?, headers?, webSocketConstructor?, group?, registry?, live?, resume?, resumeWindow? })`, which builds the shared WebSocket client and binds it
|
|
875
|
-
| `clientKeys.ts` | `KeyContext`, `clientReadKeys`, `clientInvalidationKeys`: registry-local cache keys for custom clients.
|
|
876
|
-
| `live.ts` | `LiveHint` schema; `live(runtime, { stream, keyContext?, resume?, retryDelay?, retryKeys? })`, exposing `connection`, `paused` and `status`; `isLiveConnection(atom)` tells whether an atom is such a `connection`, which waits for as long as its subscription runs.
|
|
877
|
-
| `querySubscription.ts` | `querySubscription(rpc, references, viewer)` checks each referenced query, resolves its payload and server-derived keys, and captures its scopes and ongoing authorization.
|
|
878
|
-
| `live-server/service.ts` | `LiveServer`, the shared live server service.
|
|
879
|
-
| `live-server/layer.ts` | `liveServerLayer`, providing `LiveServer` and its dispatcher dependency, requiring `Reactivity`.
|
|
880
|
-
| `live-server/subscribe.ts` | `subscribe(subscription, read?)`, an Effect requiring `LiveServer` that returns an authorized subscription Stream with its policy and query-runner requirements.
|
|
881
|
-
| `makeLiveServer.ts` | `makeLiveServer`, an Effect requiring `Reactivity` that creates scoped server hint streams
|
|
882
|
-
| `readPolicy.ts` | `QueryReadPolicy`, `Viewer`, `signedIn`, `CurrentViewer`; `authorizeReads(effect, request, viewer)` for direct handler reruns outside RPC middleware.
|
|
883
|
-
| `ReadPolicyGuard.ts` | `ReadPolicyGuard`, the defaulted middleware reference attached to contract queries; `readPolicyGuardLayer({ websocket? })`, an optional override that refuses HTTP `$changes` calls by default.
|
|
884
|
-
| `validateReadPolicies.ts` | `validateReadPolicies(group)`, an Effect that fails with `MissingReadPolicies` when any served or subscribable query omits its policy.
|
|
885
|
-
| `readPolicyErrors.ts` | `MissingReadPolicies` (boot), `MissingReadPolicy` (native-server request fallback) and `QueryReadDenied`.
|
|
886
|
-
| `CommandGuard.ts` | `guardCommands(group)` places command publication inside viewer-providing middleware; `commandGuardLayer(boundary)` evaluates declared invalidations for that viewer and delegates publication to the host boundary.
|
|
887
|
-
| `commandResult.ts` | `commandResult({ result, invalidates })` contributes server-only keys from a guarded command handler and returns only its success value.
|
|
888
|
-
| `serverMetadata.ts` | `QueryDefinition.definition`, `CommandInvalidation.invalidates`, `ChangesQueries.queries`, `ChangesQueries.resolve(references)` and `changesRpc(name, queries)` for server adapters.
|
|
889
|
-
| `queryKeys.ts` | `queryKeys(queries, references, viewer?)` authorizes references and resolves payload and server-derived keys using the provided services.
|
|
890
|
-
| `QueryServerReads.ts` | `QueryServerReads<Payload, E, R>`, the server-only resolver type.
|
|
891
|
-
| `resume.ts` | `resumeSignal({ window?, native? })`, returning a native numeric signal atom.
|
|
892
|
-
| `querySignals.ts` | `querySignals(query)` exposes completion counts and subscription status as a native atom.
|
|
893
|
-
| `retainQuery.ts` | `queryRuntime(query)` returns the atom runtime a bound query runs on, so a reader can schedule work on the same Effect `Clock`.
|
|
894
|
-
| `clientActivity.ts` | `clientActivity(client)` exposes a native activity Stream with a `current` Effect; `isClientSettled(state)` checks commands and first query results; `isClientIdle(state)` checks all finite work; `activityScreenSignal(activity, settled?)` projects pending work for screen waits.
|
|
895
|
-
| `
|
|
897
|
+
| Module | Functions and schemas |
|
|
898
|
+
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
899
|
+
| `operation.ts` | `query(name, { payload?, success?, rejections?, readPolicy, reads?, serverReads? })`; `command(name, { payload?, success?, rejections?, invalidates })`; `query(name, { payload?, *run, readPolicy?, reads?, serverReads?, readsCollections?, success?, rejections? })` and `command(name, { payload?, *run, invalidates?, success?, rejections? })` with an Effect-returning `run`; `stream(name, { payload?, success, rejections?, reads })`. |
|
|
900
|
+
| `contract.ts` | `contract(name, { queries?, commands?, streams?, keyScope? })`, returning a native RPC group with `declaration: { name, queries, commands, streams, keyScope }`. |
|
|
901
|
+
| `defineModule.ts` | `defineModule({ name, operations, requires, middleware?, subject?, keyScope?, wire? })`, returning the module's contract. |
|
|
902
|
+
| `moduleHandlers.ts` | `moduleHandlers(module)`, the module's handler Layer, requiring exactly its `requires`. |
|
|
903
|
+
| `clientContract.ts` | `clientContract({ name, wire, payloads?, queries?, commands?, middleware?, subject?, keyScope? })`, the browser's contract of a module that generated files build. |
|
|
904
|
+
| `clientMatchesModule.ts` | `ClientMatchesModule<Client, Module>`, `true` when the browser's contract and the server module have the same RPCs, else `ClientDiffersFromModule`. |
|
|
905
|
+
| `rejection.ts` | `fieldRejection(struct, fields?)`; lower-level `rejectionSet(specs)`, which constructs the rejection classes, union schema and failure helpers used by operations. |
|
|
906
|
+
| `bind.ts` | `bind(contract, atomRpcService, { registry?, live?, resume?, resumeWindow? }?)`, requiring the registry for session-scoped contracts and exposing `{ query, run }` for queries, `{ run }` Effects for commands and `{ run }` native Streams for streams; `makeClient(contract, { url, protocol?, headers?, webSocketConstructor?, group?, registry?, live?, resume?, resumeWindow? })`, which builds the shared WebSocket client and binds it, with `sync` beside `api`. |
|
|
907
|
+
| `clientKeys.ts` | `KeyContext`, `clientReadKeys`, `clientInvalidationKeys`: registry-local cache keys for custom clients. |
|
|
908
|
+
| `live.ts` | `LiveHint` schema; `live(runtime, { stream, keyContext?, resume?, retryDelay?, retryKeys? })`, exposing `connection`, `paused` and `status`; `isLiveConnection(atom)` tells whether an atom is such a `connection`, which waits for as long as its subscription runs. |
|
|
909
|
+
| `querySubscription.ts` | `querySubscription(rpc, references, viewer)` checks each referenced query, resolves its payload and server-derived keys, and captures its scopes and ongoing authorization. |
|
|
910
|
+
| `live-server/service.ts` | `LiveServer`, the shared live server service. |
|
|
911
|
+
| `live-server/layer.ts` | `liveServerLayer`, providing `LiveServer` and its dispatcher dependency, requiring `Reactivity`. |
|
|
912
|
+
| `live-server/subscribe.ts` | `subscribe(subscription, read?)`, an Effect requiring `LiveServer` that returns an authorized subscription Stream with its policy and query-runner requirements. |
|
|
913
|
+
| `makeLiveServer.ts` | `makeLiveServer`, an Effect requiring `Reactivity` that creates scoped server hint streams, a `resync` Effect and `synced(token)`. |
|
|
914
|
+
| `readPolicy.ts` | `QueryReadPolicy`, `Viewer`, `signedIn`, `CurrentViewer`; `authorizeReads(effect, request, viewer)` for direct handler reruns outside RPC middleware. |
|
|
915
|
+
| `ReadPolicyGuard.ts` | `ReadPolicyGuard`, the defaulted middleware reference attached to contract queries; `readPolicyGuardLayer({ websocket? })`, an optional override that refuses HTTP `$changes` calls by default. |
|
|
916
|
+
| `validateReadPolicies.ts` | `validateReadPolicies(group)`, an Effect that fails with `MissingReadPolicies` when any served or subscribable query omits its policy. |
|
|
917
|
+
| `readPolicyErrors.ts` | `MissingReadPolicies` (boot), `MissingReadPolicy` (native-server request fallback) and `QueryReadDenied`. |
|
|
918
|
+
| `CommandGuard.ts` | `guardCommands(group)` places command publication inside viewer-providing middleware; `commandGuardLayer(boundary)` evaluates declared invalidations for that viewer and delegates publication to the host boundary. |
|
|
919
|
+
| `commandResult.ts` | `commandResult({ result, invalidates })` contributes server-only keys from a guarded command handler and returns only its success value. |
|
|
920
|
+
| `serverMetadata.ts` | `QueryDefinition.definition`, `CommandInvalidation.invalidates`, `ChangesQueries.queries`, `ChangesQueries.resolve(references)` and `changesRpc(name, queries)` for server adapters. |
|
|
921
|
+
| `queryKeys.ts` | `queryKeys(queries, references, viewer?)` authorizes references and resolves payload and server-derived keys using the provided services. |
|
|
922
|
+
| `QueryServerReads.ts` | `QueryServerReads<Payload, E, R>`, the server-only resolver type. |
|
|
923
|
+
| `resume.ts` | `resumeSignal({ window?, native? })`, returning a native numeric signal atom. |
|
|
924
|
+
| `querySignals.ts` | `querySignals(query)` exposes completion counts and subscription status as a native atom. |
|
|
925
|
+
| `retainQuery.ts` | `queryRuntime(query)` returns the atom runtime a bound query runs on, so a reader can schedule work on the same Effect `Clock`. |
|
|
926
|
+
| `clientActivity.ts` | `clientActivity(client)` exposes a native activity Stream with a `current` Effect; `isClientSettled(state)` checks commands, commands not yet reflected and first query results; `isClientIdle(state)` checks all finite work; `activityScreenSignal(activity, settled?)` projects pending work for screen waits. |
|
|
927
|
+
| `commandSignal.ts` | `untilReflected(command)` completes a command's Effect when it is reflected; `CommandSignal` receives each `CommandState`. |
|
|
928
|
+
| `LiveSync.ts` | `LiveSync`, the host's contract of the `platform.liveSync.request` command that carries a sync token and writes nothing. Browser code takes the same command from `liveSyncRpc.ts`. |
|
|
929
|
+
| `liveSyncRpc.ts` | `liveSyncRpc`, the RPC group a client declares for that command without importing its operation file, and `LIVE_SYNC`, its tag. |
|
|
930
|
+
| `syncHeader.ts` | `syncClient(headers)` and `syncToken(headers)` read the client name and the sync token a request carries. |
|
|
931
|
+
| `screenSync.ts` | `screenSync(client, registry)` runs a client's `sync` through a registry, for a screen driver's `sync` option. |
|
|
896
932
|
|
|
897
933
|
A bound query’s optional second argument accepts `headers` and `serializationKey`. Successful results remain in their owning registry for five minutes after the last reader leaves, up to 100 idle queries, evicting the least recently left first. Reopening a query immediately returns the retained success with native `waiting: true` while a new subscription or read supplies fresh data. Execution stops between readers. Configure the registry’s `queryRetention` atom from `@shivaedev/contract/queryRetention.ts` with `{ timeToLive: "1 minute", capacity: 50 }`, or set React’s `SessionBoundary` prop of the same name. Zero for either disables idle retention. Expiry runs on the query runtime’s Effect Clock. Registry disposal clears all retained results; applications outside `SessionBoundary` own that disposal when their session changes. A native resume source receives a callback and returns a cleanup function.
|
|
898
934
|
|
|
@@ -3,7 +3,9 @@ import type * as Atom from "effect/reactivity/Atom";
|
|
|
3
3
|
import type { LiveBound, LiveConnection } from "#automaticLive.ts";
|
|
4
4
|
import type { LiveStatus } from "#live.ts";
|
|
5
5
|
import type { QuerySignals } from "#querySignals.ts";
|
|
6
|
+
import type { StreamAnchor } from "#reflectedStream.ts";
|
|
6
7
|
export interface AutomaticQueryOptions<A, E> {
|
|
8
|
+
readonly anchor: (registry: object) => StreamAnchor;
|
|
7
9
|
readonly clientStatuses: Atom.Writable<ReadonlyMap<object, LiveStatus<unknown>>> | undefined;
|
|
8
10
|
readonly equivalent: (left: A, right: A) => boolean;
|
|
9
11
|
readonly paused: Atom.Writable<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutomaticQueryOptions.d.ts","sourceRoot":"","sources":["../src/AutomaticQueryOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"AutomaticQueryOptions.d.ts","sourceRoot":"","sources":["../src/AutomaticQueryOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,WAAW,qBAAqB,CAAC,CAAC,EAAE,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,YAAY,CAAC;IACpD,QAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAC7F,QAAQ,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC;IACpD,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC9C,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC1D,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3E,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC,OAAO,cAAc,CAAC,CAAC;IACxD,QAAQ,CAAC,mBAAmB,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;CAChD"}
|
package/dist/CommandGuard.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Effect, Layer } from "effect";
|
|
2
2
|
import { type Rpc, type RpcGroup, RpcMiddleware } from "effect/rpc";
|
|
3
|
-
|
|
3
|
+
import type { SyncToken } from "@shivaedev/changes/syncToken.ts";
|
|
4
|
+
export type CommandBoundary = <A, E, R>(effect: Effect.Effect<A, E, R>, keys: (result: A) => readonly unknown[], sync?: SyncToken) => Effect.Effect<A, E, R>;
|
|
4
5
|
declare const CommandGuard_base: RpcMiddleware.ServiceClass<CommandGuard, "@shivaedev/contract/CommandGuard", never, import("effect/Schema").Never, never, never, false>;
|
|
5
6
|
export declare class CommandGuard extends CommandGuard_base {
|
|
6
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandGuard.d.ts","sourceRoot":"","sources":["../src/CommandGuard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAE,KAAK,EAAe,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"CommandGuard.d.ts","sourceRoot":"","sources":["../src/CommandGuard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAE,KAAK,EAAe,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAOjE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACrC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC9B,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,SAAS,OAAO,EAAE,EACvC,IAAI,CAAC,EAAE,SAAS,KACZ,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;;AAE5B,qBAAa,YAAa,SAAQ,iBAAyE;CAAG;AAE9G,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,eAAe,GAAG,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAoBtF;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,6FAE3E"}
|
package/dist/CommandGuard.js
CHANGED
|
@@ -5,10 +5,11 @@ import { CommandResultKeys } from "#CommandResultKeys.ts";
|
|
|
5
5
|
import { prependMiddleware } from "#prependMiddleware.ts";
|
|
6
6
|
import { CurrentViewer } from "#readPolicy.ts";
|
|
7
7
|
import { CommandInvalidation } from "#serverMetadata.ts";
|
|
8
|
+
import { syncToken } from "#syncHeader.ts";
|
|
8
9
|
export class CommandGuard extends RpcMiddleware.Service()("@shivaedev/contract/CommandGuard") {
|
|
9
10
|
}
|
|
10
11
|
export function commandGuardLayer(boundary) {
|
|
11
|
-
return Layer.succeed(CommandGuard, (effect, { rpc, payload }) => {
|
|
12
|
+
return Layer.succeed(CommandGuard, (effect, { rpc, payload, headers }) => {
|
|
12
13
|
const declaration = Context.getOption(rpc.annotations, CommandInvalidation);
|
|
13
14
|
return Option.isNone(declaration)
|
|
14
15
|
? effect
|
|
@@ -16,7 +17,7 @@ export function commandGuardLayer(boundary) {
|
|
|
16
17
|
const viewer = yield* CurrentViewer;
|
|
17
18
|
const keys = yield* Ref.make([]);
|
|
18
19
|
const completed = effect.pipe(Effect.provideService(CommandResultKeys, keys), Effect.flatMap((result) => Effect.map(Ref.get(keys), (extra) => ({ extra, result }))));
|
|
19
|
-
const published = yield* boundary(completed, ({ extra, result }) => invalidationKeys([...declaration.value.invalidates(payload, result, viewer), ...extra]));
|
|
20
|
+
const published = yield* boundary(completed, ({ extra, result }) => invalidationKeys([...declaration.value.invalidates(payload, result, viewer), ...extra]), syncToken(headers));
|
|
20
21
|
return published.result;
|
|
21
22
|
});
|
|
22
23
|
});
|
package/dist/CommandGuard.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandGuard.js","sourceRoot":"","sources":["../src/CommandGuard.ts"],"names":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MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,aAAa,CAAC;gBACpC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAiB,EAAE,CAAC,CAAC;gBACjD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAC5B,MAAM,CAAC,cAAc,CAAC,iBAAiB,EAAE,IAAI,CAAC,EAC9C,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CACrF,CAAC;gBACF,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,QAAQ,CAChC,SAAS,EACT,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,gBAAgB,CAAC,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,EAC9G,SAAS,CAAC,OAAO,CAAC,CAClB,CAAC;gBACF,OAAO,SAAS,CAAC,MAAM,CAAC;YACzB,CAAC,CAAC,CAAC;IACN,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aAAa,CAAoB,KAA2B;IAC3E,OAAO,iBAAiB,CAAC,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;AAC5E,CAAC"}
|
package/dist/HostVersion.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
export declare const HostVersion: import("#contract.ts").Contract<"platform.hostVersion", readonly [], readonly [], import("effect/rpc/Rpc").Rpc<"platform.hostVersion.$changes", Schema.Struct<{
|
|
3
3
|
queries: Schema.$Array<Schema.Union<readonly never[]>>;
|
|
4
|
-
}>, import("effect/rpc/RpcSchema").Stream<Schema.Union<readonly [typeof import("./readPolicyErrors.ts").QueryReadDenied,
|
|
4
|
+
}>, import("effect/rpc/RpcSchema").Stream<Schema.Union<readonly [typeof import("./readPolicyErrors.ts").QueryReadDenied, Schema.Struct<{
|
|
5
|
+
readonly _tag: Schema.Literal<"Syncing">;
|
|
6
|
+
}>, Schema.Struct<{
|
|
7
|
+
readonly _tag: Schema.Literal<"Synced">;
|
|
8
|
+
readonly ids: Schema.$Array<Schema.Number>;
|
|
9
|
+
}>, ...never[]]>, Schema.Union<readonly [typeof import("./readPolicyErrors.ts").MissingReadPolicy, typeof import("./readPolicyErrors.ts").QueryReadDenied, typeof import("./WebSocketRequired.ts").WebSocketRequired, ...never[]]>>, Schema.Never, import("effect/Context").Reference<<A, E, R>(effect: import("effect/Effect").Effect<A, E, R>, request: {
|
|
5
10
|
readonly rpc: import("effect/rpc/Rpc").Any;
|
|
6
11
|
readonly payload: unknown;
|
|
7
12
|
}) => import("effect/Effect").Effect<A, E | import("./readPolicyErrors.ts").MissingReadPolicy | import("./readPolicyErrors.ts").QueryReadDenied | import("./WebSocketRequired.ts").WebSocketRequired | import("effect/Types").unhandled, R>> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HostVersion.d.ts","sourceRoot":"","sources":["../src/HostVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,eAAO,MAAM,WAAW
|
|
1
|
+
{"version":3,"file":"HostVersion.d.ts","sourceRoot":"","sources":["../src/HostVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;+RAEtB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export declare const LiveSync: import("#contract.ts").Contract<"platform.liveSync", readonly [], readonly [NoInfer<import("#operation.ts").Command<"request", Schema.Void, Schema.Void, {}>>], import("effect/rpc/Rpc").Rpc<"platform.liveSync.$changes", Schema.Struct<{
|
|
3
|
+
queries: Schema.$Array<Schema.Union<readonly never[]>>;
|
|
4
|
+
}>, import("effect/rpc/RpcSchema").Stream<Schema.Union<readonly [typeof import("./readPolicyErrors.ts").QueryReadDenied, Schema.Struct<{
|
|
5
|
+
readonly _tag: Schema.Literal<"Syncing">;
|
|
6
|
+
}>, Schema.Struct<{
|
|
7
|
+
readonly _tag: Schema.Literal<"Synced">;
|
|
8
|
+
readonly ids: Schema.$Array<Schema.Number>;
|
|
9
|
+
}>, ...never[]]>, Schema.Union<readonly [typeof import("./readPolicyErrors.ts").MissingReadPolicy, typeof import("./readPolicyErrors.ts").QueryReadDenied, typeof import("./WebSocketRequired.ts").WebSocketRequired, ...never[]]>>, Schema.Never, import("effect/Context").Reference<<A, E, R>(effect: import("effect/Effect").Effect<A, E, R>, request: {
|
|
10
|
+
readonly rpc: import("effect/rpc/Rpc").Any;
|
|
11
|
+
readonly payload: unknown;
|
|
12
|
+
}) => import("effect/Effect").Effect<A, E | import("./readPolicyErrors.ts").MissingReadPolicy | import("./readPolicyErrors.ts").QueryReadDenied | import("./WebSocketRequired.ts").WebSocketRequired | import("effect/Types").unhandled, R>> & {
|
|
13
|
+
"~effect/rpc/RpcMiddleware": "~effect/rpc/RpcMiddleware";
|
|
14
|
+
"~ClientError": never;
|
|
15
|
+
error: Schema.Union<readonly [typeof import("./readPolicyErrors.ts").MissingReadPolicy, typeof import("./readPolicyErrors.ts").QueryReadDenied, typeof import("./WebSocketRequired.ts").WebSocketRequired]>;
|
|
16
|
+
requiredForClient: false;
|
|
17
|
+
}, never> | import("effect/rpc/Rpc").Rpc<"platform.liveSync.request", Schema.Void, Schema.Void, Schema.Never, never, never>, readonly [], undefined>;
|
|
18
|
+
//# sourceMappingURL=LiveSync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiveSync.d.ts","sourceRoot":"","sources":["../src/LiveSync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;oJAEnB,CAAC"}
|
package/dist/LiveSync.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { contract } from "#contract.ts";
|
|
3
|
+
import { LIVE_SYNC_COMMAND, LIVE_SYNC_CONTRACT } from "#liveSyncRpc.ts";
|
|
4
|
+
import { command } from "#operation.ts";
|
|
5
|
+
// A command that writes nothing: its sync token alone travels the change channel, behind every earlier commit.
|
|
6
|
+
export const LiveSync = contract(LIVE_SYNC_CONTRACT, {
|
|
7
|
+
commands: [command(LIVE_SYNC_COMMAND, { invalidates: () => [], success: Schema.Void })],
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=LiveSync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiveSync.js","sourceRoot":"","sources":["../src/LiveSync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,+GAA+G;AAC/G,MAAM,CAAC,MAAM,QAAQ,GAAG,QAAQ,CAAC,kBAAkB,EAAE;IACpD,QAAQ,EAAE,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;CACvF,CAAC,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import type
|
|
2
|
+
import { type ClientActivityState, type ConnectionStatus } from "#clientActivity.ts";
|
|
3
3
|
export declare function activityState(): {
|
|
4
4
|
activity: import("effect/Stream").Stream<ClientActivityState, never, never> & {
|
|
5
5
|
current: Effect.Effect<ClientActivityState, never, never>;
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
answered: () => void;
|
|
8
|
+
change: (key: Exclude<keyof ClientActivityState, "connectionStatus" | "firstSettled">, delta: number) => void;
|
|
8
9
|
hold: () => () => void;
|
|
9
10
|
setConnection: (connectionStatus: ConnectionStatus) => void;
|
|
10
11
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"activityState.d.ts","sourceRoot":"","sources":["../../src/adapters/activityState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmB,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"activityState.d.ts","sourceRoot":"","sources":["../../src/adapters/activityState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmB,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,gBAAgB,EAAmB,MAAM,oBAAoB,CAAC;AAEtG,wBAAgB,aAAa;IA0B3B,QAAQ;;;IACR,QAAQ;IAIR,MAAM,QAAQ,OAAO,CAAC,MAAM,mBAAmB,EAAE,kBAAkB,GAAG,cAAc,CAAC,SAAS,MAAM;IAGpG,IAAI;IAQJ,aAAa,qBAAqB,gBAAgB;EAKnD"}
|
|
@@ -1,23 +1,34 @@
|
|
|
1
1
|
import { Effect, SubscriptionRef } from "effect";
|
|
2
|
+
import { isClientSettled } from "#clientActivity.ts";
|
|
2
3
|
export function activityState() {
|
|
3
4
|
let held = 0;
|
|
5
|
+
let answered = false;
|
|
4
6
|
let connection = "live";
|
|
5
7
|
const state = Effect.runSync(SubscriptionRef.make({
|
|
6
8
|
commands: 0,
|
|
7
9
|
connectionStatus: "live",
|
|
10
|
+
firstSettled: false,
|
|
8
11
|
initialQueries: 0,
|
|
9
12
|
liveHints: 0,
|
|
10
13
|
refreshingAtoms: 0,
|
|
11
14
|
rpcCalls: 0,
|
|
15
|
+
unreflectedCommands: 0,
|
|
12
16
|
}));
|
|
13
17
|
function publish() {
|
|
14
18
|
const connectionStatus = held > 0 ? "waiting-for-connection" : connection;
|
|
15
19
|
Effect.runSync(SubscriptionRef.update(state, (current) => (current.connectionStatus === connectionStatus ? current : { ...current, connectionStatus })));
|
|
16
20
|
}
|
|
21
|
+
function latched(current) {
|
|
22
|
+
return answered && !current.firstSettled && isClientSettled(current) ? { ...current, firstSettled: true } : current;
|
|
23
|
+
}
|
|
17
24
|
return {
|
|
18
25
|
activity: Object.assign(SubscriptionRef.changes(state), { current: SubscriptionRef.get(state) }),
|
|
26
|
+
answered: () => {
|
|
27
|
+
answered = true;
|
|
28
|
+
Effect.runSync(SubscriptionRef.update(state, latched));
|
|
29
|
+
},
|
|
19
30
|
change: (key, delta) => {
|
|
20
|
-
Effect.runSync(SubscriptionRef.update(state, (current) => ({ ...current, [key]: current[key] + delta })));
|
|
31
|
+
Effect.runSync(SubscriptionRef.update(state, (current) => latched({ ...current, [key]: current[key] + delta })));
|
|
21
32
|
},
|
|
22
33
|
hold: () => {
|
|
23
34
|
held += 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"activityState.js","sourceRoot":"","sources":["../../src/adapters/activityState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"activityState.js","sourceRoot":"","sources":["../../src/adapters/activityState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAmD,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEtG,MAAM,UAAU,aAAa;IAC5B,IAAI,IAAI,GAAG,CAAC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AM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;QACxD,CAAC;QACD,MAAM,EAAE,CAAC,GAA4E,EAAE,KAAa,EAAE,EAAE;YACvG,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QAClH,CAAC;QACD,IAAI,EAAE,GAAG,EAAE;YACV,IAAI,IAAI,CAAC,CAAC;YACV,OAAO,EAAE,CAAC;YACV,OAAO,GAAG,EAAE;gBACX,IAAI,IAAI,CAAC,CAAC;gBACV,OAAO,EAAE,CAAC;YACX,CAAC,CAAC;QACH,CAAC;QACD,aAAa,EAAE,CAAC,gBAAkC,EAAE,EAAE;YACrD,UAAU,GAAG,gBAAgB,CAAC;YAC9B,OAAO,EAAE,CAAC;QACX,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -5,6 +5,7 @@ import type { LiveStatus } from "#live.ts";
|
|
|
5
5
|
export declare function clientConnection(factory: Atom.RuntimeFactory, publish: (status: ConnectionStatus) => void, activity: Stream.Stream<ClientActivityState> & {
|
|
6
6
|
readonly current: Effect.Effect<ClientActivityState>;
|
|
7
7
|
}): {
|
|
8
|
+
firstSettled: Atom.Atom<boolean>;
|
|
8
9
|
status: Atom.Atom<ConnectionStatus>;
|
|
9
10
|
statuses: Atom.Writable<ReadonlyMap<object, LiveStatus<unknown>>, ReadonlyMap<object, LiveStatus<unknown>>>;
|
|
10
11
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientConnection.d.ts","sourceRoot":"","sources":["../../src/adapters/clientConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEvD,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,IAAI,CAAC,cAAc,EAC5B,OAAO,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,EAC3C,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAA;CAAE
|
|
1
|
+
{"version":3,"file":"clientConnection.d.ts","sourceRoot":"","sources":["../../src/adapters/clientConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEvD,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,IAAI,CAAC,cAAc,EAC5B,OAAO,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,EAC3C,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAA;CAAE;;;;EAsDvG"}
|
|
@@ -17,15 +17,23 @@ export function clientConnection(factory, publish, activity) {
|
|
|
17
17
|
get.addFinalizer(cancel);
|
|
18
18
|
return "live";
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
function follow(select, mounts = []) {
|
|
21
|
+
return Atom.make((get) => {
|
|
22
|
+
for (const mounted of mounts) {
|
|
23
|
+
get.mount(mounted);
|
|
24
|
+
}
|
|
25
|
+
const context = AsyncResult.value(get(runtime));
|
|
26
|
+
if (Option.isSome(context)) {
|
|
27
|
+
const cancel = Effect.runCallbackWith(context.value)(activity.pipe(Stream.map(select), Stream.changes, Stream.runForEach((value) => Effect.sync(() => get.setSelf(value)))));
|
|
28
|
+
get.addFinalizer(cancel);
|
|
29
|
+
}
|
|
30
|
+
return select(Effect.runSync(activity.current));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
firstSettled: follow((state) => state.firstSettled),
|
|
35
|
+
status: follow((state) => state.connectionStatus, [debounced]),
|
|
36
|
+
statuses,
|
|
37
|
+
};
|
|
30
38
|
}
|
|
31
39
|
//# sourceMappingURL=clientConnection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientConnection.js","sourceRoot":"","sources":["../../src/adapters/clientConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACvD,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAI/C,MAAM,UAAU,gBAAgB,CAC/B,OAA4B,EAC5B,OAA2C,EAC3C,QAAuG;IAEvG,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAA2C,IAAI,GAAG,EAAE,CAAC,CAAC;IAChF,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CACvB,QAAQ,EACR,CAAC,MAAM,EAAoB,EAAE,CAC5B,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,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AE,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,SAAS,CAAC,CAAC;QAC9D,QAAQ;KACR,CAAC;AACH,CAAC"}
|
|
@@ -5,25 +5,9 @@ import { LiveDispatcher } from "#adapters/LiveDispatcher.ts";
|
|
|
5
5
|
export declare const liveHintStream: (state: {
|
|
6
6
|
openStreams: import("effect/Ref").Ref<number>;
|
|
7
7
|
resyncKey: string;
|
|
8
|
-
|
|
8
|
+
syncClients: Map<string, Set<(id: number) => void>>;
|
|
9
|
+
}, keys: readonly Key[], syncClient?: string | undefined) => Effect.Effect<Stream.Stream<{
|
|
9
10
|
replaceKeys: (current: readonly Key[]) => void;
|
|
10
|
-
stream: Stream.Stream<
|
|
11
|
-
readonly _tag: "Changed";
|
|
12
|
-
readonly keys: readonly ({
|
|
13
|
-
readonly _tag: "Bucket";
|
|
14
|
-
readonly collection: string;
|
|
15
|
-
readonly field: string;
|
|
16
|
-
readonly value: string | number;
|
|
17
|
-
} | {
|
|
18
|
-
readonly _tag: "List";
|
|
19
|
-
readonly collection: string;
|
|
20
|
-
} | {
|
|
21
|
-
readonly _tag: "Item";
|
|
22
|
-
readonly collection: string;
|
|
23
|
-
readonly id: string | number;
|
|
24
|
-
})[];
|
|
25
|
-
} | {
|
|
26
|
-
readonly _tag: "Resync";
|
|
27
|
-
}, never, never>;
|
|
11
|
+
stream: Stream.Stream<import("../liveHintQueue.ts").SubscriptionHint, never, never>;
|
|
28
12
|
}, never, never>, never, LiveDispatcher | Reactivity.Reactivity>;
|
|
29
13
|
//# sourceMappingURL=liveHintStream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liveHintStream.d.ts","sourceRoot":"","sources":["../../src/adapters/liveHintStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAI7D,eAAO,MAAM,cAAc
|
|
1
|
+
{"version":3,"file":"liveHintStream.d.ts","sourceRoot":"","sources":["../../src/adapters/liveHintStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAI7D,eAAO,MAAM,cAAc;;;;;;;gEAWzB,CAAC"}
|
|
@@ -2,9 +2,9 @@ import { Effect, Stream } from "effect";
|
|
|
2
2
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
3
|
import { LiveDispatcher } from "#adapters/LiveDispatcher.ts";
|
|
4
4
|
import { openLiveHints } from "#adapters/openLiveHints.ts";
|
|
5
|
-
export const liveHintStream = Effect.fn("LiveServer.liveHintStream")(function* (state, keys) {
|
|
5
|
+
export const liveHintStream = Effect.fn("LiveServer.liveHintStream")(function* (state, keys, syncClient) {
|
|
6
6
|
const reactivity = yield* Reactivity.Reactivity;
|
|
7
7
|
const dispatcher = yield* LiveDispatcher;
|
|
8
|
-
return Stream.unwrap(Effect.map(openLiveHints(state, keys), Stream.succeed)).pipe(Stream.provideService(Reactivity.Reactivity, reactivity), Stream.provideService(LiveDispatcher, dispatcher));
|
|
8
|
+
return Stream.unwrap(Effect.map(openLiveHints(state, keys, syncClient), Stream.succeed)).pipe(Stream.provideService(Reactivity.Reactivity, reactivity), Stream.provideService(LiveDispatcher, dispatcher));
|
|
9
9
|
});
|
|
10
10
|
//# sourceMappingURL=liveHintStream.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liveHintStream.js","sourceRoot":"","sources":["../../src/adapters/liveHintStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAG3D,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,EAAE,CAAC,2BAA2B,CAAC,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"liveHintStream.js","sourceRoot":"","sources":["../../src/adapters/liveHintStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAG3D,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,EAAE,CAAC,2BAA2B,CAAC,CAAC,QAAQ,CAAC,EAC7E,KAAwC,EACxC,IAAoB,EACpB,UAAmB;IAEnB,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;IAChD,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,cAAc,CAAC;IACzC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAC5F,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,EACxD,MAAM,CAAC,cAAc,CAAC,cAAc,EAAE,UAAU,CAAC,CACjD,CAAC;AACH,CAAC,CAAC,CAAC"}
|