@shivaedev/contract 0.30.2 → 0.32.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 +39 -0
- package/README.md +107 -38
- package/dist/CommandGuard.d.ts +10 -0
- package/dist/CommandGuard.d.ts.map +1 -0
- package/dist/CommandGuard.js +20 -0
- package/dist/CommandGuard.js.map +1 -0
- package/dist/LiveServer.d.ts +6 -4
- package/dist/LiveServer.d.ts.map +1 -1
- package/dist/LiveServer.js +10 -5
- package/dist/LiveServer.js.map +1 -1
- package/dist/ReadPolicyGuard.d.ts +19 -0
- package/dist/ReadPolicyGuard.d.ts.map +1 -0
- package/dist/ReadPolicyGuard.js +23 -0
- package/dist/ReadPolicyGuard.js.map +1 -0
- package/dist/adapters/activityState.d.ts +9 -0
- package/dist/adapters/activityState.d.ts.map +1 -0
- package/dist/adapters/activityState.js +11 -0
- package/dist/adapters/activityState.js.map +1 -0
- package/dist/{internal → adapters}/bindingOwner.d.ts +1 -1
- package/dist/{internal → adapters}/bindingOwner.d.ts.map +1 -1
- package/dist/{internal → adapters}/bindingOwner.js +2 -1
- package/dist/adapters/bindingOwner.js.map +1 -0
- package/dist/adapters/clientId.d.ts +2 -0
- package/dist/adapters/clientId.d.ts.map +1 -0
- package/dist/adapters/clientId.js +4 -0
- package/dist/adapters/clientId.js.map +1 -0
- package/dist/automaticLive.d.ts +1 -1
- package/dist/automaticLive.d.ts.map +1 -1
- package/dist/automaticLive.js +7 -2
- package/dist/automaticLive.js.map +1 -1
- package/dist/bind.d.ts +5 -5
- package/dist/bind.d.ts.map +1 -1
- package/dist/bind.js +1 -1
- package/dist/bind.js.map +1 -1
- package/dist/changesHandlerLayer.d.ts +19 -0
- package/dist/changesHandlerLayer.d.ts.map +1 -0
- package/dist/changesHandlerLayer.js +15 -0
- package/dist/changesHandlerLayer.js.map +1 -0
- package/dist/clientActivity.d.ts +10 -1
- package/dist/clientActivity.d.ts.map +1 -1
- package/dist/clientActivity.js +7 -0
- package/dist/clientActivity.js.map +1 -1
- package/dist/clientKeys.d.ts +7 -0
- package/dist/clientKeys.d.ts.map +1 -0
- package/dist/clientKeys.js +11 -0
- package/dist/clientKeys.js.map +1 -0
- package/dist/clientOptions.d.ts +3 -0
- package/dist/clientOptions.d.ts.map +1 -1
- package/dist/composeBindings.d.ts +8 -0
- package/dist/composeBindings.d.ts.map +1 -0
- package/dist/composeBindings.js +18 -0
- package/dist/composeBindings.js.map +1 -0
- package/dist/contract.d.ts +5 -8
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +11 -7
- package/dist/contract.js.map +1 -1
- package/dist/internal/automaticQuery.d.ts +3 -1
- package/dist/internal/automaticQuery.d.ts.map +1 -1
- package/dist/internal/automaticQuery.js +9 -2
- package/dist/internal/automaticQuery.js.map +1 -1
- package/dist/internal/changesSuccess.d.ts +7 -2
- package/dist/internal/changesSuccess.d.ts.map +1 -1
- package/dist/internal/changesSuccess.js +12 -6
- package/dist/internal/changesSuccess.js.map +1 -1
- package/dist/internal/clientActivity.d.ts +5 -6
- package/dist/internal/clientActivity.d.ts.map +1 -1
- package/dist/internal/clientActivity.js +6 -18
- package/dist/internal/clientActivity.js.map +1 -1
- package/dist/internal/clientOperations.d.ts +1 -1
- package/dist/internal/clientOperations.d.ts.map +1 -1
- package/dist/internal/clientOperations.js +7 -4
- package/dist/internal/clientOperations.js.map +1 -1
- package/dist/internal/compareQueries.d.ts +2 -1
- package/dist/internal/compareQueries.d.ts.map +1 -1
- package/dist/internal/compareQueries.js +5 -7
- package/dist/internal/compareQueries.js.map +1 -1
- package/dist/internal/declarationError.d.ts +7 -1
- package/dist/internal/declarationError.d.ts.map +1 -1
- package/dist/internal/declarationError.js.map +1 -1
- package/dist/internal/liveAttempt.d.ts +13 -0
- package/dist/internal/liveAttempt.d.ts.map +1 -0
- package/dist/internal/liveAttempt.js +28 -0
- package/dist/internal/liveAttempt.js.map +1 -0
- package/dist/internal/prependMiddleware.d.ts +10 -0
- package/dist/internal/prependMiddleware.d.ts.map +1 -0
- package/dist/internal/prependMiddleware.js +12 -0
- package/dist/internal/prependMiddleware.js.map +1 -0
- package/dist/internal/queryDelivery.d.ts +4 -21
- package/dist/internal/queryDelivery.d.ts.map +1 -1
- package/dist/internal/queryDelivery.js +8 -1
- package/dist/internal/queryDelivery.js.map +1 -1
- package/dist/internal/queryHints.d.ts +3 -2
- package/dist/internal/queryHints.d.ts.map +1 -1
- package/dist/internal/queryHints.js +1 -1
- package/dist/internal/queryHints.js.map +1 -1
- package/dist/internal/queryReactivity.d.ts.map +1 -1
- package/dist/internal/queryReactivity.js +3 -11
- package/dist/internal/queryReactivity.js.map +1 -1
- package/dist/internal/querySignals.d.ts +8 -0
- package/dist/internal/querySignals.d.ts.map +1 -0
- package/dist/internal/querySignals.js +42 -0
- package/dist/internal/querySignals.js.map +1 -0
- package/dist/internal/wrapAtom.d.ts +3 -0
- package/dist/internal/wrapAtom.d.ts.map +1 -0
- package/dist/internal/wrapAtom.js +15 -0
- package/dist/internal/wrapAtom.js.map +1 -0
- package/dist/live.d.ts +7 -4
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +21 -28
- package/dist/live.js.map +1 -1
- package/dist/makeLiveServer.d.ts +23 -6
- package/dist/makeLiveServer.d.ts.map +1 -1
- package/dist/makeLiveServer.js +42 -26
- package/dist/makeLiveServer.js.map +1 -1
- package/dist/publicConfig.d.ts +19 -3
- package/dist/publicConfig.d.ts.map +1 -1
- package/dist/querySignals.d.ts +9 -0
- package/dist/querySignals.d.ts.map +1 -0
- package/dist/querySignals.js +14 -0
- package/dist/querySignals.js.map +1 -0
- package/dist/querySubscription.d.ts +3 -2
- package/dist/querySubscription.d.ts.map +1 -1
- package/dist/querySubscription.js +11 -5
- package/dist/querySubscription.js.map +1 -1
- package/dist/queryUpdate.d.ts +7 -1
- package/dist/queryUpdate.d.ts.map +1 -1
- package/dist/testing.d.ts +4 -40
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js.map +1 -1
- package/package.json +10 -10
- package/src/CommandGuard.ts +25 -0
- package/src/LiveServer.ts +18 -9
- package/src/ReadPolicyGuard.ts +31 -0
- package/src/adapters/activityState.ts +12 -0
- package/src/{internal → adapters}/bindingOwner.ts +3 -2
- package/src/adapters/clientId.ts +3 -0
- package/src/automaticLive.ts +8 -3
- package/src/bind.ts +10 -9
- package/src/changesHandlerLayer.ts +51 -0
- package/src/clientActivity.ts +8 -1
- package/src/clientKeys.ts +17 -0
- package/src/clientOptions.ts +3 -0
- package/src/composeBindings.ts +27 -0
- package/src/contract.ts +14 -20
- package/src/internal/automaticQuery.ts +11 -1
- package/src/internal/changesSuccess.ts +16 -9
- package/src/internal/clientActivity.ts +37 -52
- package/src/internal/clientOperations.ts +9 -5
- package/src/internal/compareQueries.ts +6 -8
- package/src/internal/declarationError.ts +12 -1
- package/src/internal/liveAttempt.ts +44 -0
- package/src/internal/prependMiddleware.ts +15 -0
- package/src/internal/queryDelivery.ts +11 -3
- package/src/internal/queryHints.ts +3 -2
- package/src/internal/queryReactivity.ts +4 -11
- package/src/internal/querySignals.ts +46 -0
- package/src/internal/wrapAtom.ts +14 -0
- package/src/live.ts +25 -31
- package/src/makeLiveServer.ts +73 -60
- package/src/querySignals.ts +22 -0
- package/src/querySubscription.ts +13 -8
- package/src/queryUpdate.ts +7 -1
- package/src/testing.ts +5 -5
- package/dist/internal/bindingOwner.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.32.0 - 2026-11-03
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `makeClient` accepts `resume` and `resumeWindow` so applications can supply native lifecycle signals and an embedded browser window directly, preserving the client's inferred API, failures and requirements.
|
|
8
|
+
- `composeBindings(client, bindings)` preserves the client's type and declares the bound APIs in one connection. `liveBindings(connection)` reads that composition while retaining support for direct bindings and object properties.
|
|
9
|
+
- Observe bound queries with `querySignals(query)`: a native atom reports completed reads, pending requests, and whether their subscription opened or was refused. Refreshes signal completion even when their result is unchanged.
|
|
10
|
+
- Supply `CommandGuard`, `CommandBoundary`, `guardCommands` and `commandGuardLayer` to evaluate declared command changes for the current viewer independently of authentication and tracing.
|
|
11
|
+
- Export `activityScreenSignal(activity)` from `clientActivity.ts`, projecting client activity into a native stream and current Effect of pending screen work and hint counts.
|
|
12
|
+
- Contract owns `ReadPolicyGuard`, `readPolicyGuardLayer()` and `guardReads(group)` in `@shivaedev/contract/ReadPolicyGuard.ts`. The guard checks each ordinary query's read policy once against the request's `CurrentViewer`.
|
|
13
|
+
- Derive custom subscription handlers with `changesHandlerLayer`, retaining query payloads, declared failures, read-policy services and stream requirements in a native Layer.
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- Schedule contract live hints through the Effect runtime's Scheduler, preserving batched changes, resyncs and stream cleanup. Isolate synchronous client identity and activity bridges in adapters and share atom wrapping across bindings.
|
|
18
|
+
- Refresh server-discovered read scopes on each live subscription rerun and replace their registrations, including when a pushed result is unchanged.
|
|
19
|
+
- `LiveServer.subscribe` preserves `SubscriptionHint` deliveries when no query runner is supplied, including an explicit `undefined`. Calls with a query runner keep `QueryUpdate` deliveries and retain the subscription's typed failures and service requirements.
|
|
20
|
+
- Contract groups enforce query read policies automatically in native Effect RPC hosts as well as the application host. A false policy returns `QueryReadDenied` without running the handler. Ordinary queries evaluate their policy once per request.
|
|
21
|
+
|
|
22
|
+
### Breaking
|
|
23
|
+
|
|
24
|
+
- Rerun-and-compare subscriptions emit an `Unchanged` update with the query index when a completed read preserves its previous value. Consumers of raw `$changes` streams must handle this update; bound queries handle it automatically. Deploy clients and servers together so both understand the updated stream schema.
|
|
25
|
+
- Calls to `LiveServer.subscribe` that explicitly supply its error and service type arguments and a query runner must also supply the runner type as the third type argument, or omit the type arguments and let TypeScript infer them.
|
|
26
|
+
- Remove `guardReads` from `@shivaedev/contract/ReadPolicyGuard.ts`. Serve the contract group directly with `RpcServer`; remove any explicit read-policy Layer unless you use `readPolicyGuardLayer()` to refuse HTTP `$changes` calls with `WebSocketRequired`. `ReadPolicyGuard` is now a defaulted Context reference rather than a service class and requires no provision. Remove its former service type from Layer annotations.
|
|
27
|
+
- Custom authentication middleware must supply `CurrentViewer` after session validation and stop calling `authorizeReads`; the contract's attached guard performs that check. Keep `authorizeReads` only for direct handler reruns outside RPC dispatch.
|
|
28
|
+
- Ordinary query failures now include `MissingReadPolicy` and `WebSocketRequired` from the attached middleware. `MissingReadPolicy` refuses untyped declarations that omit a policy; `WebSocketRequired` belongs to the optional HTTP subscription restriction. Add these refusals to exhaustive error handlers.
|
|
29
|
+
- `makeLiveServer.stream` and `LiveServer.stream` accept keys only. Their `subscribe` methods now take `(subscription, authorizedRunner?)`; remove the former context argument. `QuerySubscription.globalKeys` is removed because all server keys share the repository namespace; remove it from custom subscription objects.
|
|
30
|
+
|
|
31
|
+
## 0.31.0 - 2026-11-02
|
|
32
|
+
|
|
33
|
+
### Added
|
|
34
|
+
|
|
35
|
+
- Query subscriptions accept an optional `refresh` Effect supplying the context for each policy check and query rerun.
|
|
36
|
+
|
|
37
|
+
### Breaking
|
|
38
|
+
|
|
39
|
+
- Contract change streams emit `QueryReadDenied` as a delivery when an established subscription loses read access, keeping the subscription open so a later hint can resume delivery after access returns. Custom consumers must handle this delivery alongside `Changed`, `Resync` and `Result`; use `SubscriptionHint` for hint consumers. Initial subscription refusals remain typed stream failures. Bound query atoms display the denial and recover on a later authorized hint.
|
|
40
|
+
- Query atom failure types include client-middleware errors and the contract's change-subscription errors. Consumers with exhaustive error handlers must handle the additional subscription failures, including `MissingReadPolicy`, `WebSocketRequired`, and rejections declared by other queries in the contract. Explicit `BoundQuery` annotations can pass the subscription RPC as the third type parameter or be replaced with inference from the bound API. Direct `run` failure types stay specific to their RPC.
|
|
41
|
+
|
|
3
42
|
## 0.30.2 - 2026-11-02
|
|
4
43
|
|
|
5
44
|
### Fixed
|
package/README.md
CHANGED
|
@@ -227,7 +227,7 @@ const rename = runtime.fn(api.rename.run);
|
|
|
227
227
|
|
|
228
228
|
Browsers send the session cookie at upgrade. Mounting a query opens its subscription before running its first authorized read; unmounting cancels that subscription without restarting the socket or another query. Changed keys rerun only their readers, and equal results retain the bound atom's value. Connection failures use Effect RPC's reconnect backoff; subscriptions resume and mounted queries read again because there is no retained key history. `LiveConnection.status` reports `connecting`, `live` or `reconnecting`.
|
|
229
229
|
|
|
230
|
-
For a native WebView, pass the signed session credential as `bearerToken` to `makeClient`. The browser WebSocket constructor needs no upgrade headers. The client adds `auth=frame` to the RPC URL and sends `{"_tag":"Authenticate","token":"<credential>"}` as its first text frame on every connection, before native RPC traffic. The bearer never enters the URL. Use a host session provider that admits bearer sessions and configure the WebView's Origin on the host. Authentication failures close the socket with code 1008 and reason `Authentication required`; an unavailable session provider closes it with code 1011 and reason `Authentication unavailable`. Sign-out or session expiry also closes an established bearer socket.
|
|
230
|
+
For a native WebView, pass the signed session credential as `bearerToken` to `makeClient`. The browser WebSocket constructor needs no upgrade headers. The client adds `auth=frame` to the RPC URL and sends `{"_tag":"Authenticate","token":"<credential>"}` as its first text frame on every connection, before native RPC traffic. The bearer never enters the URL. Use a host session provider that admits bearer sessions and configure the WebView's Origin on the host. Authentication failures close the socket with code 1008 and reason `Authentication required`; an unavailable session provider closes it with code 1011 and reason `Authentication unavailable`. Sign-out or session expiry also closes an established bearer socket. Pass a native `resume` source to `makeClient` as shown below to reconcile live reads when the shell resumes.
|
|
231
231
|
|
|
232
232
|
`group` supplies a larger native RPC group containing the contract, such as an admin registry. The result is a native client Layer for `ManagedRuntime.make`, plus the native `Client` service, atom `runtime` and scoped `client` Effect. Session-scoped contracts require `registry`. For Node clients, supply upgrade `headers` and `webSocketConstructor: NodeSocket.layerWebSocketConstructorWS` from `@effect/platform-node`. A native `protocol` Layer selects another transport explicitly. A `protocol: (identity) => layer` factory follows the live session identity instead: the client rebuilds its transport when that identity changes. The scoped `client` Effect uses `undefined` as the factory identity. Return a shared Layer for clients that should share a socket within one session. Use `live: false` for ordinary clients without subscriptions.
|
|
233
233
|
|
|
@@ -277,7 +277,21 @@ Client invalidation follows RPC success. Database hosts from `@shivaedev/server`
|
|
|
277
277
|
|
|
278
278
|
### Client activity
|
|
279
279
|
|
|
280
|
-
`clientActivity(client)` from `@shivaedev/contract/clientActivity.ts` returns a native Effect `Stream` with a `current` Effect for a client made by `makeClient`. Its state reports `rpcCalls` for finite calls, `liveInvalidations` for queued live refreshes, `refreshingAtoms` for mounted query atoms awaiting values, and a `liveHints` sequence for received subscription updates. Long-lived streams do not count as finite calls. `isClientIdle(state)` is true when all three work counts are zero. Observe its stream or pass
|
|
280
|
+
`clientActivity(client)` from `@shivaedev/contract/clientActivity.ts` returns a native Effect `Stream` with a `current` Effect for a client made by `makeClient`. Its state reports `rpcCalls` for finite calls, `liveInvalidations` for queued live refreshes, `refreshingAtoms` for mounted query atoms awaiting values, and a `liveHints` sequence for received subscription updates. Long-lived streams do not count as finite calls. `isClientIdle(state)` is true when all three work counts are zero. Observe its stream or pass `activityScreenSignal(clientActivity(client))` to a test-story screen driver's `pending` option and call `settle()` before screen assertions. `activityScreenSignal(activity)` projects the stream and its `current` Effect into `{ pending, hints }`, with `pending` true while finite work remains and `hints` carrying the received live-hint count. The returned shape is structural and carries no test-story dependency. Coalesced work stays pending until its refresh completes.
|
|
281
|
+
|
|
282
|
+
### Query completion
|
|
283
|
+
|
|
284
|
+
`querySignals(query)` from `@shivaedev/contract/querySignals.ts` returns a native atom scoped to the query's registry. Its `completed` counter advances when the initial query or a refresh finishes, including typed failures and equal results. `pending` describes the query result awaiting completion. `subscription` is `disabled` for an ordinary query, `opening` while connecting, `open` once accepted, or `refused` after a terminal refusal. Read the query's `AsyncResult` for its value or typed failure.
|
|
285
|
+
|
|
286
|
+
```ts
|
|
287
|
+
import { querySignals } from "@shivaedev/contract/querySignals.ts";
|
|
288
|
+
|
|
289
|
+
const signals = querySignals(one);
|
|
290
|
+
const before = registry.get(signals).completed;
|
|
291
|
+
const completions = AtomRegistry.toStream(registry, signals);
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Mount the query to start it. Wait on `completions` for `completed > before` after an action that refreshes it; compare the counter rather than the result's identity. A server-pushed equal result completes without changing the visible value. Raw rerun-and-compare `$changes` consumers receive an `Unchanged` update with `queryIndex` for these completed reads. Clients and servers must understand the same stream schema.
|
|
281
295
|
|
|
282
296
|
### Session-owned keys
|
|
283
297
|
|
|
@@ -319,26 +333,48 @@ Preferences.application.toLayer({
|
|
|
319
333
|
});
|
|
320
334
|
```
|
|
321
335
|
|
|
322
|
-
`store` is the application's persistence service. No owner or client key scope is accepted from a request. The database app host
|
|
336
|
+
`store` is the application's persistence service. No owner or client key scope is accepted from a request. The database app host uses plain repository keys for every subscriber and rechecks each subscriber’s read policy before delivery.
|
|
323
337
|
|
|
324
338
|
The registry is required for session-scoped bindings. Query atoms and live connections belong in it; command and one-off query Effects execute through it. Explicit streams also run through its client, preserving the session transport and headers; disposing the registry ends those streams. Streams on ordinary contracts use the caller's client. A successful command invalidates its owner's keys, while a rejected command declares no invalidation. Ordinary contracts keep unscoped keys and the two-argument `bind` call.
|
|
325
339
|
|
|
326
|
-
|
|
340
|
+
Server subscriptions and committed writes use the same plain record, list and bucket keys, including for `keyScope: "session"`. A background worker needs no request identity or account prefix to refresh a session's query. Matching keys trigger the query's own read policy; authorized reads remain responsible for filtering rows to the viewer. A shared key can therefore trigger authorized rechecks for several accounts. Use model buckets to narrow that fan-out.
|
|
341
|
+
|
|
342
|
+
Client cache isolation belongs to the owning registry. `bind` supplies its opaque context automatically. Custom client coordination uses these helpers and context type:
|
|
327
343
|
|
|
328
|
-
|
|
344
|
+
```ts
|
|
345
|
+
import { clientInvalidationKeys, clientReadKeys, type KeyContext } from "@shivaedev/contract/clientKeys.ts";
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
`clientReadKeys(keys, context)` registers client dependencies; `clientInvalidationKeys(keys, context)` announces client cache changes. The context has type `KeyContext`. Never publish contextual client keys on the server.
|
|
349
|
+
|
|
350
|
+
### Compose feature bindings
|
|
351
|
+
|
|
352
|
+
Use `composeBindings(client, bindings)` when a connection contains several feature modules. The returned object keeps the client's fields and types and carries an explicit list of bound APIs. `liveBindings(connection)` reads this list; it also accepts a binding directly or an object with bound APIs as its own properties.
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
import { composeBindings } from "@shivaedev/contract/composeBindings.ts";
|
|
356
|
+
|
|
357
|
+
const modules = [notesModule, tasksModule] as const;
|
|
358
|
+
const connection = composeBindings(
|
|
359
|
+
{ modules },
|
|
360
|
+
modules.map((module) => module.api),
|
|
361
|
+
);
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
`notesModule` and `tasksModule` are application modules whose `api` values come from `bind` or `makeClient`. Return `connection` from React's `SessionBoundary` connection callback to mount both bindings while keeping the modules nested.
|
|
329
365
|
|
|
330
366
|
### 4. Live invalidation and resume
|
|
331
367
|
|
|
332
368
|
The automatic live connection exposed at `api[LiveConnection]` includes a writable `paused` atom. Set it in the binding’s registry to pause refreshes; clearing it reconciles the mounted queries. Bindings on the same client runtime share this pause state.
|
|
333
369
|
|
|
334
|
-
Database hosts from `@shivaedev/server` serve the contract's reserved `<contract>.$changes` stream automatically. With the native WebSocket protocol, `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.
|
|
370
|
+
Database hosts from `@shivaedev/server` serve the contract's reserved `<contract>.$changes` stream automatically. With the native WebSocket protocol, `bind` and a React `SessionBoundary` connect query atoms without an application subscribe operation or `live()` call. The boundary mounts the bindings declared with `composeBindings`, or 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.
|
|
335
371
|
|
|
336
372
|
Subscribing to the hosted `$changes` stream over HTTP fails with `WebSocketRequired` from `@shivaedev/contract/WebSocketRequired.ts`; its message names the stream and says it needs the WebSocket protocol.
|
|
337
373
|
|
|
338
|
-
A native shell supplies its lifecycle events through
|
|
374
|
+
A native shell supplies its lifecycle events through the optional `resume` source on `makeClient` or `bind`:
|
|
339
375
|
|
|
340
376
|
```ts
|
|
341
|
-
import {
|
|
377
|
+
import { makeClient } from "@shivaedev/contract/bind.ts";
|
|
342
378
|
import type { ResumeSource } from "@shivaedev/contract/resume.ts";
|
|
343
379
|
import { onAppResume, onNetworkReturn } from "./native-lifecycle.ts";
|
|
344
380
|
|
|
@@ -350,10 +386,10 @@ const resume: ResumeSource = (notify) => {
|
|
|
350
386
|
stopNetwork();
|
|
351
387
|
};
|
|
352
388
|
};
|
|
353
|
-
const api =
|
|
389
|
+
const { api, runtime } = makeClient(Notes, { url: "https://app.example/rpc", resume });
|
|
354
390
|
```
|
|
355
391
|
|
|
356
|
-
The application owns `onAppResume` and `onNetworkReturn`; each subscribes a callback and returns an unsubscribe function. The source joins the visible browser visibility and online defaults. Each notification reopens the live subscription and reconciles all reads tracked by the connection. The owning registry releases the source on disposal. Omitting `resume` keeps the browser defaults. Pass the same binding from React's `SessionBoundary.connect` to use it with automatic session subscriptions. An embedded browser can pass `resumeWindow` to observe that window’s visibility and online events.
|
|
392
|
+
The application owns `onAppResume` and `onNetworkReturn`; each subscribes a callback and returns an unsubscribe function. The source joins the visible browser visibility and online defaults. Each notification reopens the live subscription and reconciles all reads tracked by the connection. The owning registry releases the source on disposal. Omitting `resume` keeps the browser defaults. Pass the same binding from React's `SessionBoundary.connect` to use it with automatic session subscriptions. An embedded browser can pass `resumeWindow` to `makeClient` or `bind` to observe that window’s visibility and online events.
|
|
357
393
|
|
|
358
394
|
For a direct subscription, configure the server and `NotesClient` with `RpcSerialization.layerNdjson` and use the client already typed from `Notes`:
|
|
359
395
|
|
|
@@ -366,7 +402,34 @@ const changes = Stream.unwrap(
|
|
|
366
402
|
);
|
|
367
403
|
```
|
|
368
404
|
|
|
369
|
-
The contract includes the reserved stream's payload, `LiveHint` elements and middleware failures in its native RPC type. The subscription uses the contract's middleware and needs no separate RPC group or cast. The caller owns stream consumption and interruption. References name declared queries and reuse their payload schemas; payloadless queries use `{ query: "list", payload: undefined }`. Custom subscription handlers call `querySubscription(rpc, references, viewer)` with the native changes RPC definition and pass its authorized result to `makeLiveServer.subscribe(subscription
|
|
405
|
+
The contract includes the reserved stream's payload, `LiveHint` elements and middleware failures in its native RPC type. The subscription uses the contract's middleware and needs no separate RPC group or cast. The caller owns stream consumption and interruption. References name declared queries and reuse their payload schemas; payloadless queries use `{ query: "list", payload: undefined }`. Custom subscription handlers call `querySubscription(rpc, references, viewer)` with the native changes RPC definition and pass its authorized result to `makeLiveServer.subscribe(subscription)`. Hosted applications use `resolveChanges` from identity to supply that subscription. Session-scoped bindings track mounted queries per registry and drop their references on unmount or disposal. Ordinary bindings track query references when atoms are created.
|
|
406
|
+
|
|
407
|
+
Custom subscription handlers use `changesHandlerLayer` to derive the reserved handler Layer from the contract:
|
|
408
|
+
|
|
409
|
+
```ts
|
|
410
|
+
import { Effect, Stream } from "effect";
|
|
411
|
+
import { changesHandlerLayer } from "@shivaedev/contract/changesHandlerLayer.ts";
|
|
412
|
+
import { LiveServer } from "@shivaedev/contract/LiveServer.ts";
|
|
413
|
+
import { querySubscription } from "@shivaedev/contract/querySubscription.ts";
|
|
414
|
+
import { CurrentViewer } from "@shivaedev/contract/readPolicy.ts";
|
|
415
|
+
import { Notes } from "./notes.ts";
|
|
416
|
+
|
|
417
|
+
const changes = changesHandlerLayer(
|
|
418
|
+
Notes,
|
|
419
|
+
(rpc) =>
|
|
420
|
+
({ queries }) =>
|
|
421
|
+
Stream.unwrap(
|
|
422
|
+
Effect.gen(function* () {
|
|
423
|
+
const viewer = yield* CurrentViewer;
|
|
424
|
+
const subscription = yield* querySubscription(rpc, queries, viewer);
|
|
425
|
+
const live = yield* LiveServer;
|
|
426
|
+
return yield* live.subscribe(subscription);
|
|
427
|
+
}),
|
|
428
|
+
),
|
|
429
|
+
);
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
Merge this Layer with `Notes.application.toLayer(...)`. It retains the query read-policy and custom stream services as requirements, excluding services supplied by RPC middleware. The builder can also return an Effect to acquire services or fail during Layer construction. Declared stream failures remain in the contract's error channel. Pushed results are validated against the contract's decoded success types; custom handlers do not decode `changesSuccess` themselves.
|
|
370
433
|
|
|
371
434
|
For a custom transport or explicit pause and status controls, use the native live APIs.
|
|
372
435
|
|
|
@@ -440,7 +503,7 @@ const status = registry.get(updates.status);
|
|
|
440
503
|
|
|
441
504
|
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.
|
|
442
505
|
|
|
443
|
-
`status` exposes `connection`, `failure`, `needsResync` and `pending`. Expected stream rejections settle with `connection: "failed"` and their typed cause in `failure`. Typed rejections do not retry on a timer.
|
|
506
|
+
`status` exposes `connection`, `failure`, `needsResync` and `pending`. Expected stream rejections settle with `connection: "failed"` and their typed cause in `failure`. Typed rejections do not retry on a timer. An initial `QueryReadDenied` refusal stays settled through matching change invalidations and resume events; changing the query input or viewer identity starts a new subscription. A denial delivered on an established subscription also sets `connection: "failed"`, but the stream remains open and a later authorized hint restores the query and live status. Other expected rejections can reopen on matching invalidations. Low-level `live()` listens to `retryKeys`, defaulting to its `resyncKeys`, for matching invalidations. Transport errors and server defects reconnect with jittered exponential backoff, starting at `retryDelay` (one second by default) and capped at a nominal 30 seconds. A reconnection reconciles changes missed while disconnected, and successful delivery clears the 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`.
|
|
444
507
|
|
|
445
508
|
A `$changes` request is authorized as a whole: one denied member rejects or ends the entire batch, including its other queries. Split queries with independent permissions into separate `$changes` requests. Automatic bound query atoms already subscribe separately.
|
|
446
509
|
|
|
@@ -456,14 +519,16 @@ Call the release functions and dispose the registry when the application's root
|
|
|
456
519
|
|
|
457
520
|
### Server hint streams
|
|
458
521
|
|
|
459
|
-
Import `LiveServer` from `@shivaedev/contract/LiveServer.ts`. Provide `LiveServer.layer` with the server's `Reactivity` Layer; PostgreSQL `appHost` apps already provide it. Yield `LiveServer` to obtain the shared service. Its methods return Effects: unwrap `hints.stream(keys
|
|
522
|
+
Import `LiveServer` from `@shivaedev/contract/LiveServer.ts`. Provide `LiveServer.layer` with the server's `Reactivity` Layer; PostgreSQL `appHost` apps already provide it. Yield `LiveServer` to obtain the shared service. Its methods return Effects: unwrap `hints.stream(keys)` or `hints.subscribe(subscription, read?)` with `Stream.unwrap`, and call `hints.resync()` to reconcile its active streams. Subscription policy failures and caller requirements remain on the returned Stream.
|
|
460
523
|
|
|
461
524
|
Import `makeLiveServer` from `@shivaedev/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.
|
|
462
525
|
|
|
463
|
-
Each stream queues at most 256 hints. Overflow discards the pending hints and retains one `Resync`; further hints are absorbed until that reconciliation hint is pulled.
|
|
526
|
+
Each stream queues at most 256 hints. Overflow discards the pending hints and retains one `Resync`; further hints are absorbed until that reconciliation hint is pulled. Hint consumers read current query results; rerun-and-compare subscriptions rerun on the server and push changed current results. The [PostgreSQL and React stories](https://github.com/ShivaeDev/platform/blob/main/packages/react/src/comparedPostgres.dom.spec.ts) prove compared delivery without client reads, suppression of equal and SQL-filtered results, and reconciliation into a rendered query after a real loopback WebSocket withholds RPC acknowledgements across 257 repository commits. The [in-memory slow-consumer stories](src/slowConsumer.spec.ts) cover hint reconciliation. The queue bound counts hints, not commits or bytes: each hint's keys depend on the subscription. Transport buffers remain the transport's responsibility; a client lagging by 256 commits does not necessarily overflow this queue. Browser suspension, proxy buffering and deployment delivery are not proven here.
|
|
464
527
|
|
|
465
528
|
### Query policies, record keys and buckets
|
|
466
529
|
|
|
530
|
+
Contract groups carry their read-policy guard into native `RpcServer` hosts and Platform’s application host. An ordinary query evaluates its policy once per request, after identity middleware supplies `CurrentViewer` from its validated session. A false policy returns `QueryReadDenied` without running the handler. Native hosts need no policy middleware or guard Layer. Real HTTP stories exercise both hosts with allowed and denied counted policies; they prove this RPC boundary, not an application’s session or deployment policy. Platform’s application host refuses HTTP `$changes` calls with `WebSocketRequired`; subscriptions use its WebSocket protocol. Subscription delivery and pushed reruns continue to check current access.
|
|
531
|
+
|
|
467
532
|
A query declares its decoded input, result, `readPolicy` and `reads` together. `readPolicy(payload, viewer)` returns an Effect boolean. `viewer` is the session's `Option<{ id: string }>`; the browser does not send the identity. `signedIn` from `readPolicy.ts` allows any signed-in viewer and refuses a signed-out viewer. `QueryReadPolicy<Payload, E, R>` preserves typed failures and required services. Declare policy errors in the query's `rejections`; a failing access check reaches the client as its declared error, including during live reads. Only a successful `false` denies access. [Policy services](#policy-services) explains richer session requirements and where to provide implementations.
|
|
468
533
|
|
|
469
534
|
```ts
|
|
@@ -504,7 +569,7 @@ const AllNotes = query("allNotes", {
|
|
|
504
569
|
|
|
505
570
|
The application supplies the permission checker through `permissionReadPolicy(permission, check)`; `check` receives that permission and the current viewer, and must check the viewer's grant using server services. Its failures and service requirements flow through the query like any other read policy. Supply `SessionUser` with the application's identity middleware. The policy guards both calls and subscriptions, and runs again before changed hints are delivered. `readsCollections` requires this policy at declaration: a `signedIn` or ordinary boolean policy fails TypeScript checking, and building an untyped contract with that declaration throws an error explaining the required permission policy. The server also refuses collection queries changed to an ordinary policy after construction as `QueryReadDenied`. Tenant-facing queries use `notes.bucket.userId(viewerId)` instead.
|
|
506
571
|
|
|
507
|
-
Collection reads reuse the bare repository table key, the same key as `notes.list`, even when the contract uses `keyScope: "session"`;
|
|
572
|
+
Collection reads reuse the bare repository table key, the same key as `notes.list`, even when the contract uses `keyScope: "session"`; record and bucket reads also use plain server keys. They add no wildcard matching or write-side work. Every committed repository insert, update, delete, upsert and bulk write already publishes that key. Generated-id inserts also publish the bare collection key alongside their generated record key, so `publishes` stories that check exact published keys must allow the bare key today. For a table named `notes`, that is `"notes"` alongside `"notes:<id>"` and any affected bucket keys. Mounting a collection subscriber adds **zero PostgreSQL NOTIFY messages per write**: it consumes the existing payloads. It adds a normal query subscription and an authorized reread when the collection changes.
|
|
508
573
|
|
|
509
574
|
For dependencies that need server data, add `serverReads(payload, viewer)`, an Effect returning extra keys. Keep `reads` for keys the browser can derive, or return `[]` there. The server checks every referenced query's policy before it runs any `serverReads`, and resolves it with the owning query handler's services. Declare its failures in the query's `rejections`, as with policy failures. A denied subscription never runs the resolver.
|
|
510
575
|
|
|
@@ -563,13 +628,13 @@ The server provides `NoteOwner`; the shared declaration holds only its browser-s
|
|
|
563
628
|
|
|
564
629
|
A record key, `notes.item(id)`, names one record. A bucket, `notes.bucket.userId(id)`, names every row with that field value. Declare bucket fields on the collection model with their schemas. A list may add title, state or other filters to its input and handler, but those filters never narrow its bucket. It reruns whenever any row in that bucket changes, including a row excluded by the filter. Writers explicitly announce the record and affected buckets with the same constructors from `@shivaedev/changes/keys.ts`.
|
|
565
630
|
|
|
566
|
-
The same query policy guards running the query and subscribing to it. A subscription is meant to carry one query. It names query references, never arbitrary record or bucket keys. If a subscription mixes queries the viewer may and may not read, the entire subscription is refused with `QueryReadDenied`; it delivers no partial set of hints. Every query requires `readPolicy` at declaration, including queries used only through one-off `run` calls. TypeScript rejects a policy-less declaration before handlers or a live server can be built. Platform’s application host validates the complete RPC group while building its Layer, before listening; untyped declarations missing policies fail with `MissingReadPolicies`, whose `queries` and `message` name every affected RPC. Native hosts
|
|
631
|
+
The same query policy guards running the query and subscribing to it. A subscription is meant to carry one query. It names query references, never arbitrary record or bucket keys. If a subscription mixes queries the viewer may and may not read, the entire subscription is refused with `QueryReadDenied`; it delivers no partial set of hints. Every query requires `readPolicy` at declaration, including queries used only through one-off `run` calls. TypeScript rejects a policy-less declaration before handlers or a live server can be built. Platform’s application host validates the complete RPC group while building its Layer, before listening; untyped declarations missing policies fail with `MissingReadPolicies`, whose `queries` and `message` name every affected RPC. Native hosts enforce read policies automatically at request time. `MissingReadPolicy` remains a request-time refusal for untyped declarations served through native servers that bypass that boot check, on plain calls and subscriptions alike. Reads outside a declared query acquire no automatic subscription.
|
|
567
632
|
|
|
568
|
-
|
|
633
|
+
Session middleware supplies `CurrentViewer`; the guard attached to each contract query owns policy evaluation. Custom authentication middleware provides that viewer after validating its session. Before delivering changed keys, the stream rechecks the owning query's policy without memoization. In a session-backed host, a signed-out, revoked or expired session ends the subscription with `Unauthorized`; a signed-in viewer whose policy refuses receives a `QueryReadDenied` delivery while the established subscription stays open. A later authorized hint resumes delivery, including an unchanged pushed value. An initial subscription refusal still fails the stream with `QueryReadDenied`. Custom stream consumers handle the denial delivery alongside `Changed`, `Resync` and `Result`; `SubscriptionHint` from `queryUpdate.ts` types hint consumers. This distinction is the same whether a change hint or the session revalidation interval detects session removal. A client refresh runs the same authorized query that produced its first value; hints carry no row values.
|
|
569
634
|
|
|
570
635
|
### Policy services
|
|
571
636
|
|
|
572
|
-
Use the policy's `viewer` argument for the viewer ID. Read richer session context from Effect requirements. For example, a policy service can require `SessionUserWithProviderAccounts` from `@shivaedev/identity/identity.ts` and yield its `providerAccounts` Effect. Apply `AuthenticatedUserWithProviderAccounts` middleware to the contract and supply `authenticatedUserWithProviderAccountsLayer()` from `@shivaedev/identity/server/session.ts` alongside its handlers, with the shared `SessionPolicy` Layer provided once by the application host. The middleware provides this request-local context for both RPC calls and live change hints, including each policy recheck before a hint is delivered.
|
|
637
|
+
Use the policy's `viewer` argument for the viewer ID. Read richer session context from Effect requirements. For example, a policy service can require `SessionUserWithProviderAccounts` from `@shivaedev/identity/identity.ts` and yield its `providerAccounts` Effect. Apply `AuthenticatedUserWithProviderAccounts` middleware to the contract and supply `authenticatedUserWithProviderAccountsLayer()` from `@shivaedev/identity/server/session.ts` alongside its handlers, with the shared `SessionPolicy` Layer provided once by the application host. The middleware provides this request-local context for both RPC calls and live change hints, including each policy recheck before a hint is delivered. Session-backed hosts reload that context before each hint, and use the same snapshot for its policy and query rerun.
|
|
573
638
|
|
|
574
639
|
Keep the policy service tag and query declaration browser-safe; put its implementation on the server. Its method retains the session service in its requirements so the session is read when the policy runs:
|
|
575
640
|
|
|
@@ -663,26 +728,30 @@ expect(yield* heard(bob, [notes.item(1)], { within: "50 millis" })).toBe(false);
|
|
|
663
728
|
|
|
664
729
|
Import the module that defines the name; the package has no root entry.
|
|
665
730
|
|
|
666
|
-
| Module | Functions and schemas
|
|
667
|
-
| ------------------------- |
|
|
668
|
-
| `operation.ts` | `query(name, { payload?, success?, rejections?, readPolicy, reads, serverReads? })`; `command(name, { payload?, success?, rejections?, invalidates })`; `stream(name, { payload?, success, rejections?, reads })`.
|
|
669
|
-
| `contract.ts` | `contract(name, { queries?, commands?, streams?, keyScope? })`, returning a native RPC group with `declaration: { name, queries, commands, streams, keyScope }`.
|
|
670
|
-
| `rejection.ts` | `fieldRejection(struct, fields?)`; lower-level `rejectionSet(specs)`, which constructs the rejection classes, union schema and failure helpers used by operations.
|
|
671
|
-
| `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? })`, which builds the shared WebSocket client and binds it. |
|
|
672
|
-
| `queryCoalesceWindow.ts` | `queryCoalesceWindow(query)`, a writable atom for a bound query's live changed-hint window.
|
|
673
|
-
| `
|
|
674
|
-
| `
|
|
675
|
-
| `
|
|
676
|
-
| `
|
|
677
|
-
| `
|
|
678
|
-
| `
|
|
679
|
-
| `
|
|
680
|
-
| `
|
|
681
|
-
| `
|
|
682
|
-
| `
|
|
683
|
-
| `
|
|
684
|
-
| `
|
|
685
|
-
| `
|
|
731
|
+
| Module | Functions and schemas |
|
|
732
|
+
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
733
|
+
| `operation.ts` | `query(name, { payload?, success?, rejections?, readPolicy, reads, serverReads? })`; `command(name, { payload?, success?, rejections?, invalidates })`; `stream(name, { payload?, success, rejections?, reads })`. |
|
|
734
|
+
| `contract.ts` | `contract(name, { queries?, commands?, streams?, keyScope? })`, returning a native RPC group with `declaration: { name, queries, commands, streams, keyScope }`. |
|
|
735
|
+
| `rejection.ts` | `fieldRejection(struct, fields?)`; lower-level `rejectionSet(specs)`, which constructs the rejection classes, union schema and failure helpers used by operations. |
|
|
736
|
+
| `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. |
|
|
737
|
+
| `queryCoalesceWindow.ts` | `queryCoalesceWindow(query)`, a writable atom for a bound query's live changed-hint window. |
|
|
738
|
+
| `clientKeys.ts` | `KeyContext`, `clientReadKeys`, `clientInvalidationKeys`: registry-local cache keys for custom clients. |
|
|
739
|
+
| `live.ts` | `LiveHint` schema; `live(runtime, { stream, resyncKeys, coalesceWindow?, initialResync?, keyContext?, resume?, retryDelay?, retryKeys? })`, exposing `connection`, `coalesceWindow`, `paused` and `status`. |
|
|
740
|
+
| `querySubscription.ts` | `querySubscription(rpc, references, viewer)` checks each referenced query, resolves its payload and server-derived keys, and captures its scopes and ongoing authorization. |
|
|
741
|
+
| `LiveServer.ts` | `LiveServer`, the shared live server service and its `.layer`, requiring `Reactivity`. |
|
|
742
|
+
| `makeLiveServer.ts` | `makeLiveServer`, an Effect requiring `Reactivity` that creates scoped server hint streams and a `resync` Effect. |
|
|
743
|
+
| `readPolicy.ts` | `QueryReadPolicy`, `Viewer`, `signedIn`, `CurrentViewer`; `authorizeReads(effect, request, viewer)` for direct handler reruns outside RPC middleware. |
|
|
744
|
+
| `ReadPolicyGuard.ts` | `ReadPolicyGuard`, the defaulted middleware reference attached to contract queries; `readPolicyGuardLayer({ websocket? })`, an optional override that refuses HTTP `$changes` calls by default. |
|
|
745
|
+
| `validateReadPolicies.ts` | `validateReadPolicies(group)`, an Effect that fails with `MissingReadPolicies` when any served or subscribable query omits its policy. |
|
|
746
|
+
| `readPolicyErrors.ts` | `MissingReadPolicies` (boot), `MissingReadPolicy` (native-server request fallback) and `QueryReadDenied`. |
|
|
747
|
+
| `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. |
|
|
748
|
+
| `serverMetadata.ts` | `KeyScope`, `QueryDefinition.definition`, `CommandInvalidation.invalidates`, `ChangesQueries.queries`, `ChangesQueries.resolve(references)` and `changesRpc(name, queries)` for server adapters. |
|
|
749
|
+
| `queryKeys.ts` | `queryKeys(queries, references, viewer?)` authorizes references and resolves payload and server-derived keys using the provided services. |
|
|
750
|
+
| `QueryServerReads.ts` | `QueryServerReads<Payload, E, R>`, the server-only resolver type. |
|
|
751
|
+
| `resume.ts` | `resumeSignal({ window?, native? })`, returning a native numeric signal atom. |
|
|
752
|
+
| `querySignals.ts` | `querySignals(query)` exposes completion counts and subscription status as a native atom. |
|
|
753
|
+
| `clientActivity.ts` | `clientActivity(client)` exposes a native activity Stream with a `current` Effect; `isClientIdle(state)` checks finite work; `activityScreenSignal(activity)` projects pending work and hints for screen waits. |
|
|
754
|
+
| `testing.ts` | `layerMemoryProtocol(group)` supplies an in-memory native RPC protocol backed by the group’s handlers and middleware; `watchHints(stream)` starts a scoped viewer subscription; `heard(viewer, keys, { within? }?)` waits for matching changed keys. |
|
|
686
755
|
|
|
687
756
|
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.
|
|
688
757
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Effect, Layer } from "effect";
|
|
2
|
+
import { type Rpc, type RpcGroup, RpcMiddleware } from "effect/rpc";
|
|
3
|
+
export type CommandBoundary = <A, E, R>(effect: Effect.Effect<A, E, R>, keys: (result: A) => readonly unknown[]) => Effect.Effect<A, E, R>;
|
|
4
|
+
declare const CommandGuard_base: RpcMiddleware.ServiceClass<CommandGuard, "@shivaedev/contract/CommandGuard", never, import("effect/Schema").Never, never, never, false>;
|
|
5
|
+
export declare class CommandGuard extends CommandGuard_base {
|
|
6
|
+
}
|
|
7
|
+
export declare function commandGuardLayer(boundary: CommandBoundary): Layer.Layer<CommandGuard>;
|
|
8
|
+
export declare function guardCommands<R extends Rpc.Any>(group: RpcGroup.RpcGroup<R>): Effect.Effect<RpcGroup.RpcGroup<Rpc.AddMiddleware<R, typeof CommandGuard>>, never, never>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=CommandGuard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandGuard.d.ts","sourceRoot":"","sources":["../src/CommandGuard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAE,KAAK,EAAU,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAMpE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,SAAS,OAAO,EAAE,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;;AAE3I,qBAAa,YAAa,SAAQ,iBAAyE;CAAG;AAE9G,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,eAAe,GAAG,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAStF;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,6FAE3E"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Option } from "effect";
|
|
2
|
+
import { RpcMiddleware } from "effect/rpc";
|
|
3
|
+
import { invalidationKeys } from "@shivaedev/changes/keys.ts";
|
|
4
|
+
import { prependMiddleware } from "#internal/prependMiddleware.ts";
|
|
5
|
+
import { CurrentViewer } from "#readPolicy.ts";
|
|
6
|
+
import { CommandInvalidation } from "#serverMetadata.ts";
|
|
7
|
+
export class CommandGuard extends RpcMiddleware.Service()("@shivaedev/contract/CommandGuard") {
|
|
8
|
+
}
|
|
9
|
+
export function commandGuardLayer(boundary) {
|
|
10
|
+
return Layer.succeed(CommandGuard, (effect, { rpc, payload }) => {
|
|
11
|
+
const declaration = Context.getOption(rpc.annotations, CommandInvalidation);
|
|
12
|
+
return Option.isNone(declaration)
|
|
13
|
+
? effect
|
|
14
|
+
: Effect.flatMap(CurrentViewer, (viewer) => boundary(effect, (result) => invalidationKeys(declaration.value.invalidates(payload, result, viewer))));
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export function guardCommands(group) {
|
|
18
|
+
return prependMiddleware(group.middleware(CommandGuard), CommandGuard.key);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=CommandGuard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandGuard.js","sourceRoot":"","sources":["../src/CommandGuard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,EAA2B,aAAa,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAIzD,MAAM,OAAO,YAAa,SAAQ,aAAa,CAAC,OAAO,EAAgB,CAAC,kCAAkC,CAAC;CAAG;AAE9G,MAAM,UAAU,iBAAiB,CAAC,QAAyB;IAC1D,OAAO,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;QAC/D,MAAM,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;QAC5E,OAAO,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;YAChC,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CACzC,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CACtG,CAAC;IACL,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/LiveServer.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
1
|
+
import { Effect, type Stream } from "effect";
|
|
2
2
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
|
-
import type { Key
|
|
3
|
+
import type { Key } from "@shivaedev/changes/keys.ts";
|
|
4
4
|
import type { QueryRerun, QuerySubscription } from "#querySubscription.ts";
|
|
5
|
+
import type { QueryUpdate, SubscriptionHint } from "#queryUpdate.ts";
|
|
6
|
+
import type { QueryReadDenied } from "#readPolicyErrors.ts";
|
|
5
7
|
export declare const LiveServer: import("effect/Context").Service<"@shivaedev/contract/LiveServer", Readonly<{
|
|
6
8
|
readonly resync: () => Effect.Effect<number, never, never>;
|
|
7
|
-
readonly stream: (keys: readonly Key[]
|
|
9
|
+
readonly stream: (keys: readonly Key[]) => Effect.Effect<Stream.Stream<{
|
|
8
10
|
readonly _tag: "Changed";
|
|
9
11
|
readonly keys: readonly ({
|
|
10
12
|
readonly _tag: "Bucket";
|
|
@@ -23,7 +25,7 @@ export declare const LiveServer: import("effect/Context").Service<"@shivaedev/co
|
|
|
23
25
|
} | {
|
|
24
26
|
readonly _tag: "Resync";
|
|
25
27
|
}, never, never>, never, never>;
|
|
26
|
-
readonly subscribe: <E, R>(subscription: QuerySubscription<E, R>,
|
|
28
|
+
readonly subscribe: <E, R, TRead extends QueryRerun<unknown, unknown> | undefined = undefined>(subscription: QuerySubscription<E, R>, read?: (TRead & (QueryRerun<E, R> | undefined)) | undefined) => Effect.Effect<Stream.Stream<TRead extends undefined ? SubscriptionHint : QueryUpdate, E | QueryReadDenied, R>>;
|
|
27
29
|
}>> & {
|
|
28
30
|
readonly layer: import("effect/Layer").Layer<"@shivaedev/contract/LiveServer", never, Reactivity.Reactivity>;
|
|
29
31
|
};
|
package/dist/LiveServer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveServer.d.ts","sourceRoot":"","sources":["../src/LiveServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"LiveServer.d.ts","sourceRoot":"","sources":["../src/LiveServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAC;AAItD,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;yBAIF,CAAC,EAAE,CAAC,EAAE,KAAK,SAAS,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,SAAS,4BAChE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,kEAEnC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,SAAS,SAAS,GAAG,gBAAgB,GAAG,WAAW,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,CAAC,CAAC;;;CAWjH,CAAC"}
|
package/dist/LiveServer.js
CHANGED
|
@@ -6,11 +6,16 @@ import { makeLiveServer } from "#makeLiveServer.ts";
|
|
|
6
6
|
export const LiveServer = defineService({
|
|
7
7
|
id: "@shivaedev/contract/LiveServer",
|
|
8
8
|
initialize: makeLiveServer,
|
|
9
|
-
methods: (server) =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
methods: (server) => {
|
|
10
|
+
function subscribe(subscription, read) {
|
|
11
|
+
return Effect.succeed(read === undefined ? server.subscribe(subscription) : server.subscribe(subscription, read));
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
resync: () => server.resync,
|
|
15
|
+
stream: (keys) => Effect.succeed(server.stream(keys)),
|
|
16
|
+
subscribe: genericMethod(subscribe),
|
|
17
|
+
};
|
|
18
|
+
},
|
|
14
19
|
requires: [Reactivity.Reactivity],
|
|
15
20
|
});
|
|
16
21
|
//# sourceMappingURL=LiveServer.js.map
|
package/dist/LiveServer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveServer.js","sourceRoot":"","sources":["../src/LiveServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"LiveServer.js","sourceRoot":"","sources":["../src/LiveServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAe,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAKpD,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC;IACvC,EAAE,EAAE,gCAAgC;IACpC,UAAU,EAAE,cAAc;IAC1B,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE;QAKnB,SAAS,SAAS,CAAO,YAAqC,EAAE,IAAuB;YACtF,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;QACnH,CAAC;QACD,OAAO;YACN,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM;YAC3B,MAAM,EAAE,CAAC,IAAoB,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACrE,SAAS,EAAE,aAAa,CAAC,SAAS,CAAC;SACnC,CAAC;IACH,CAAC;IACD,QAAQ,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;CACjC,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Schema, type Types } from "effect";
|
|
2
|
+
import { type Rpc } from "effect/rpc";
|
|
3
|
+
import { MissingReadPolicy, QueryReadDenied } from "#readPolicyErrors.ts";
|
|
4
|
+
import { WebSocketRequired } from "#WebSocketRequired.ts";
|
|
5
|
+
declare function readPolicyGuard<A, E, R>(effect: Effect.Effect<A, E, R>, request: {
|
|
6
|
+
readonly rpc: Rpc.Any;
|
|
7
|
+
readonly payload: unknown;
|
|
8
|
+
}): Effect.Effect<A, E | MissingReadPolicy | QueryReadDenied | WebSocketRequired | Types.unhandled, R>;
|
|
9
|
+
export declare const ReadPolicyGuard: Context.Reference<typeof readPolicyGuard> & {
|
|
10
|
+
"~effect/rpc/RpcMiddleware": "~effect/rpc/RpcMiddleware";
|
|
11
|
+
"~ClientError": never;
|
|
12
|
+
error: Schema.Union<readonly [typeof MissingReadPolicy, typeof QueryReadDenied, typeof WebSocketRequired]>;
|
|
13
|
+
requiredForClient: false;
|
|
14
|
+
};
|
|
15
|
+
export declare function readPolicyGuardLayer(options?: {
|
|
16
|
+
readonly websocket?: boolean;
|
|
17
|
+
}): Layer.Layer<never, never, never>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=ReadPolicyGuard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReadPolicyGuard.d.ts","sourceRoot":"","sources":["../src/ReadPolicyGuard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAE,KAAK,GAAG,EAAiB,MAAM,YAAY,CAAC;AAErD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,iBAAS,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC9B,OAAO,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAC3D,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,iBAAiB,GAAG,eAAe,GAAG,iBAAiB,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAEpG;AAMD,eAAO,MAAM,eAAe;;;;;CAK1B,CAAC;AAEH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE;IAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAO,oCAMlF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
2
|
+
import { RpcMiddleware } from "effect/rpc";
|
|
3
|
+
import { authorizeReads, CurrentViewer } from "#readPolicy.ts";
|
|
4
|
+
import { MissingReadPolicy, QueryReadDenied } from "#readPolicyErrors.ts";
|
|
5
|
+
import { WebSocketRequired } from "#WebSocketRequired.ts";
|
|
6
|
+
function readPolicyGuard(effect, request) {
|
|
7
|
+
return Effect.flatMap(CurrentViewer, (viewer) => authorizeReads(effect, request, viewer));
|
|
8
|
+
}
|
|
9
|
+
const middleware = RpcMiddleware.Service()("@shivaedev/contract/ReadPolicyGuard", {
|
|
10
|
+
error: Schema.Union([MissingReadPolicy, QueryReadDenied, WebSocketRequired]),
|
|
11
|
+
});
|
|
12
|
+
export const ReadPolicyGuard = Object.assign(Context.Reference("@shivaedev/contract/ReadPolicyGuard", { defaultValue: () => readPolicyGuard }), {
|
|
13
|
+
[RpcMiddleware.TypeId]: middleware[RpcMiddleware.TypeId],
|
|
14
|
+
"~ClientError": middleware["~ClientError"],
|
|
15
|
+
error: middleware.error,
|
|
16
|
+
requiredForClient: middleware.requiredForClient,
|
|
17
|
+
});
|
|
18
|
+
export function readPolicyGuardLayer(options = {}) {
|
|
19
|
+
return Layer.succeed(ReadPolicyGuard, (effect, request) => !options.websocket && request.rpc._tag.endsWith(".$changes")
|
|
20
|
+
? Effect.fail(new WebSocketRequired({ message: `${request.rpc._tag} needs the WebSocket protocol` }))
|
|
21
|
+
: readPolicyGuard(effect, request));
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=ReadPolicyGuard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReadPolicyGuard.js","sourceRoot":"","sources":["../src/ReadPolicyGuard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAY,aAAa,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,SAAS,eAAe,CACvB,MAA8B,EAC9B,OAA6D;IAE7D,OAAO,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AAC3F,CAAC;AAED,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,EAAS,CAAC,qCAAqC,EAAE;IACxF,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,iBAAiB,EAAE,eAAe,EAAE,iBAAiB,CAAC,CAAC;CAC5E,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,qCAAqC,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,EAAE;IAC/I,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC;IACxD,cAAc,EAAE,UAAU,CAAC,cAAc,CAAC;IAC1C,KAAK,EAAE,UAAU,CAAC,KAAK;IACvB,iBAAiB,EAAE,UAAU,CAAC,iBAAiB;CAC/C,CAAC,CAAC;AAEH,MAAM,UAAU,oBAAoB,CAAC,OAAO,GAAqC,EAAE;IAClF,OAAO,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CACzD,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;QAC3D,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,iBAAiB,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,+BAA+B,EAAE,CAAC,CAAC;QACrG,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CACnC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { ClientActivityState } from "#clientActivity.ts";
|
|
3
|
+
export declare function activityState(): {
|
|
4
|
+
activity: import("effect/Stream").Stream<ClientActivityState, never, never> & {
|
|
5
|
+
current: Effect.Effect<ClientActivityState, never, never>;
|
|
6
|
+
};
|
|
7
|
+
change: (key: keyof ClientActivityState, delta: number) => void;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=activityState.d.ts.map
|
|
@@ -0,0 +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,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,wBAAgB,aAAa;IAG3B,QAAQ;;;IACR,MAAM,QAAQ,MAAM,mBAAmB,SAAS,MAAM;EAIvD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Effect, SubscriptionRef } from "effect";
|
|
2
|
+
export function activityState() {
|
|
3
|
+
const state = Effect.runSync(SubscriptionRef.make({ liveHints: 0, liveInvalidations: 0, refreshingAtoms: 0, rpcCalls: 0 }));
|
|
4
|
+
return {
|
|
5
|
+
activity: Object.assign(SubscriptionRef.changes(state), { current: SubscriptionRef.get(state) }),
|
|
6
|
+
change: (key, delta) => {
|
|
7
|
+
Effect.runSync(SubscriptionRef.update(state, (current) => ({ ...current, [key]: current[key] + delta })));
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=activityState.js.map
|
|
@@ -0,0 +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;AAGjD,MAAM,UAAU,aAAa;IAC5B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAsB,EAAE,SAAS,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACjJ,OAAO;QACN,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAChG,MAAM,EAAE,CAAC,GAA8B,EAAE,KAAa,EAAE,EAAE;YACzD,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QAC3G,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
2
|
-
import type { KeyContext } from "
|
|
2
|
+
import type { KeyContext } from "#clientKeys.ts";
|
|
3
3
|
export interface BindingOwner {
|
|
4
4
|
readonly context: KeyContext;
|
|
5
5
|
readonly registry: AtomRegistry.AtomRegistry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bindingOwner.d.ts","sourceRoot":"","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"bindingOwner.d.ts","sourceRoot":"","sources":["../../src/adapters/bindingOwner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,YAAY,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,YAAY,CAAC;CAC7C;AAID,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,YAAY,CAAC,YAAY,GAAG,YAAY,GAAG,SAAS,CAazH"}
|