@shivaedev/contract 0.28.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +63 -4
- package/dist/QueryServerReads.d.ts +5 -0
- package/dist/QueryServerReads.d.ts.map +1 -0
- package/dist/QueryServerReads.js +2 -0
- package/dist/QueryServerReads.js.map +1 -0
- package/dist/WebSocketRequired.d.ts +8 -0
- package/dist/WebSocketRequired.d.ts.map +1 -0
- package/dist/WebSocketRequired.js +4 -0
- package/dist/WebSocketRequired.js.map +1 -0
- package/dist/automaticLive.js +1 -1
- package/dist/automaticLive.js.map +1 -1
- package/dist/internal/automaticQuery.d.ts +1 -1
- package/dist/internal/automaticQuery.d.ts.map +1 -1
- package/dist/internal/automaticQuery.js +21 -4
- package/dist/internal/automaticQuery.js.map +1 -1
- package/dist/internal/operationDeclaration.d.ts +17 -3
- package/dist/internal/operationDeclaration.d.ts.map +1 -1
- package/dist/internal/operationDeclaration.js.map +1 -1
- package/dist/internal/queryReactivity.d.ts.map +1 -1
- package/dist/internal/queryReactivity.js +10 -5
- package/dist/internal/queryReactivity.js.map +1 -1
- package/dist/internal/queryReadKeys.d.ts +5 -0
- package/dist/internal/queryReadKeys.d.ts.map +1 -0
- package/dist/internal/queryReadKeys.js +6 -0
- package/dist/internal/queryReadKeys.js.map +1 -0
- package/dist/internal/resolveQueries.d.ts +8 -0
- package/dist/internal/resolveQueries.d.ts.map +1 -0
- package/dist/internal/resolveQueries.js +8 -0
- package/dist/internal/resolveQueries.js.map +1 -0
- package/dist/internal/retryOnChange.d.ts.map +1 -1
- package/dist/internal/retryOnChange.js +8 -3
- package/dist/internal/retryOnChange.js.map +1 -1
- package/dist/makeLiveServer.d.ts +1 -1
- package/dist/makeLiveServer.d.ts.map +1 -1
- package/dist/makeLiveServer.js +5 -3
- package/dist/makeLiveServer.js.map +1 -1
- package/dist/operation.d.ts +12 -11
- package/dist/operation.d.ts.map +1 -1
- package/dist/operation.js +4 -1
- package/dist/operation.js.map +1 -1
- package/dist/permissionReadPolicy.d.ts +21 -0
- package/dist/permissionReadPolicy.d.ts.map +1 -0
- package/dist/permissionReadPolicy.js +10 -0
- package/dist/permissionReadPolicy.js.map +1 -0
- package/dist/publicConfig.d.ts +1 -1
- package/dist/publicConfig.d.ts.map +1 -1
- package/dist/queryKeys.d.ts +9 -0
- package/dist/queryKeys.d.ts.map +1 -0
- package/dist/queryKeys.js +13 -0
- package/dist/queryKeys.js.map +1 -0
- package/dist/querySubscription.d.ts +1 -0
- package/dist/querySubscription.d.ts.map +1 -1
- package/dist/querySubscription.js +5 -2
- package/dist/querySubscription.js.map +1 -1
- package/dist/readPolicy.d.ts.map +1 -1
- package/dist/readPolicy.js +4 -0
- package/dist/readPolicy.js.map +1 -1
- package/dist/serverMetadata.d.ts +3 -5
- package/dist/serverMetadata.d.ts.map +1 -1
- package/dist/serverMetadata.js +4 -12
- package/dist/serverMetadata.js.map +1 -1
- package/package.json +8 -7
- package/src/QueryServerReads.ts +8 -0
- package/src/WebSocketRequired.ts +3 -0
- package/src/automaticLive.ts +1 -1
- package/src/internal/automaticQuery.ts +21 -5
- package/src/internal/operationDeclaration.ts +26 -3
- package/src/internal/queryReactivity.ts +14 -5
- package/src/internal/queryReadKeys.ts +8 -0
- package/src/internal/resolveQueries.ts +10 -0
- package/src/internal/retryOnChange.ts +10 -3
- package/src/makeLiveServer.ts +5 -3
- package/src/operation.ts +14 -14
- package/src/permissionReadPolicy.ts +28 -0
- package/src/queryKeys.ts +23 -0
- package/src/querySubscription.ts +8 -2
- package/src/readPolicy.ts +4 -0
- package/src/serverMetadata.ts +5 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.30.0 - 2026-10-31
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Queries can declare `readsCollections` with `permissionReadPolicy` to refresh admin lists after any committed repository write, using the existing collection key and NOTIFY payloads, including in session-scoped contracts. Ordinary member policies are refused by TypeScript at declaration time and by the server before reading or subscribing.
|
|
8
|
+
|
|
9
|
+
## 0.29.0 - 2026-10-31
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `rpcBoundaryHandlers(group, boundary, handlers)` applies one boundary and unexpected mapping to a native RPC handler map, including Effect and Stream handlers and native RPC wrappers.
|
|
14
|
+
- Contract changes streams declare `WebSocketRequired` so HTTP clients can decode the protocol error.
|
|
15
|
+
- React query hooks, including `useLoaderQuery` and loader-backed editor queries, expose `denied` for a `QueryReadDenied` refusal so screens can replace retained data.
|
|
16
|
+
- Queries can declare a `serverReads(payload, viewer)` Effect to load additional read keys on the server after every subscription policy allows access. Its services come from the owning query handler; failures use the query's declared rejections. Bound clients refresh from the resulting hints without receiving record IDs in their payloads.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- A `$changes` batch remains all-or-nothing: one denied query rejects or ends live updates for the whole batch. Split queries with independent permissions into separate `$changes` requests; automatic bound queries already subscribe separately.
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- Hosted `$changes` subscriptions over HTTP fail with a message saying they need the WebSocket protocol.
|
|
25
|
+
- Live queries refused with `QueryReadDenied` remain refused through matching invalidations and resume events until their input or viewer changes. They stop automatic subscription attempts and refused reads.
|
|
26
|
+
- `queryRoute` sends read denials to the route's not-found component, just like missing records.
|
|
27
|
+
|
|
28
|
+
### Breaking
|
|
29
|
+
|
|
30
|
+
- `queryKeys` moves from `serverMetadata.ts` to `queryKeys.ts` and now checks every referenced query's read policy before resolving payload and server-derived keys, and preserves their errors and service requirements. Change imports to `@shivaedev/contract/queryKeys.ts`. Custom adapters must provide those services, pass the server-resolved viewer, and handle declared rejections, `MissingReadPolicy` and `QueryReadDenied`; use `querySubscription` to capture handler services and ongoing authorization.
|
|
31
|
+
|
|
3
32
|
## 0.28.0 - 2026-10-31
|
|
4
33
|
|
|
5
34
|
### Added
|
package/README.md
CHANGED
|
@@ -159,6 +159,8 @@ export const NotesHandlers = Notes.toLayer(
|
|
|
159
159
|
|
|
160
160
|
Save this module as `handlers.ts`. An application can put repository and service calls in these handlers. The contract checks handler result and rejection types; it does not implement persistence, authorization or transactions. This in-memory server keeps the reserved change stream open without publishing hints. When a Platform host supplies that handler, build application handlers from `Notes.application` and keep `Notes` as the host and client group.
|
|
161
161
|
|
|
162
|
+
To map unexpected failures once for a handler registration, declare `boundary = rpcBoundary(schema, options)` once and use `rpcBoundaryHandlers(Notes.application, boundary, handlers)` from [`@shivaedev/errors`](https://github.com/ShivaeDev/platform/tree/main/packages/errors#mapping-unexpected-failures-at-the-handler-edge), then pass the map to `Notes.application.toLayer`. Each operation declares the boundary's rejection schema; payloads, successful results and required services retain their native types.
|
|
163
|
+
|
|
162
164
|
Native `.middleware(M)` returns a contract that retains its declarations. For example, a native middleware service can supply request identity:
|
|
163
165
|
|
|
164
166
|
```ts
|
|
@@ -331,6 +333,8 @@ The automatic live connection exposed at `api[LiveConnection]` includes a writab
|
|
|
331
333
|
|
|
332
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.
|
|
333
335
|
|
|
336
|
+
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
|
+
|
|
334
338
|
A native shell supplies its lifecycle events through `bind`'s optional `resume` source:
|
|
335
339
|
|
|
336
340
|
```ts
|
|
@@ -436,7 +440,9 @@ const status = registry.get(updates.status);
|
|
|
436
440
|
|
|
437
441
|
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.
|
|
438
442
|
|
|
439
|
-
`status` exposes `connection`, `failure`, `needsResync` and `pending`. Expected stream rejections settle with `connection: "failed"` and their typed cause in `failure`.
|
|
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. A `QueryReadDenied` refusal stays settled through matching change invalidations and resume events; changing the query input or viewer identity starts a new subscription. 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
|
+
|
|
445
|
+
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.
|
|
440
446
|
|
|
441
447
|
The resume signal is a scoped native atom. Disposing the registry removes its browser listeners, cleans up an injected source, including one used only through `live`, and releases the stream subscription:
|
|
442
448
|
|
|
@@ -475,6 +481,57 @@ const Mine = query("mine", {
|
|
|
475
481
|
});
|
|
476
482
|
```
|
|
477
483
|
|
|
484
|
+
On a repository model, annotate tenant fields with `bucket()` from `@shivaedev/changes/buckets.ts` so writes announce the affected buckets. For an admin page spanning every tenant, declare `readsCollections` beside a permission read policy:
|
|
485
|
+
|
|
486
|
+
```ts
|
|
487
|
+
import { Effect, Schema } from "effect";
|
|
488
|
+
import { permission } from "@shivaedev/access/permission.ts";
|
|
489
|
+
import { collection } from "@shivaedev/changes/keys.ts";
|
|
490
|
+
import { query } from "@shivaedev/contract/operation.ts";
|
|
491
|
+
import { permissionReadPolicy } from "@shivaedev/contract/permissionReadPolicy.ts";
|
|
492
|
+
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
493
|
+
import { hasPermission } from "@shivaedev/identity/permission.ts";
|
|
494
|
+
|
|
495
|
+
const notes = collection("notes", Schema.Number);
|
|
496
|
+
const ManageNotes = permission("notes.manage").any;
|
|
497
|
+
const AllNotes = query("allNotes", {
|
|
498
|
+
success: Schema.Array(Schema.String),
|
|
499
|
+
readPolicy: permissionReadPolicy(ManageNotes, (required) => Effect.map(SessionUser, (user) => hasPermission(user, required))),
|
|
500
|
+
reads: () => [],
|
|
501
|
+
readsCollections: [notes],
|
|
502
|
+
});
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
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. The server also refuses untyped collection queries with an ordinary policy as `QueryReadDenied`. Tenant-facing queries use `notes.bucket.userId(viewerId)` instead.
|
|
506
|
+
|
|
507
|
+
Collection reads reuse the bare repository table key, the same key as `notes.list`, even when the contract uses `keyScope: "session"`; ordinary reads keep their session scope. 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
|
+
|
|
509
|
+
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
|
+
|
|
511
|
+
```ts
|
|
512
|
+
import { Context, Effect, Schema } from "effect";
|
|
513
|
+
import type { Key } from "@shivaedev/changes/keys.ts";
|
|
514
|
+
import { query } from "@shivaedev/contract/operation.ts";
|
|
515
|
+
import { signedIn } from "@shivaedev/contract/readPolicy.ts";
|
|
516
|
+
|
|
517
|
+
class TimelineData extends Context.Service<
|
|
518
|
+
TimelineData,
|
|
519
|
+
{
|
|
520
|
+
readonly readKeys: (workspaceId: string) => Effect.Effect<readonly Key[]>;
|
|
521
|
+
}
|
|
522
|
+
>()("app/TimelineData") {}
|
|
523
|
+
|
|
524
|
+
const Timeline = query("timeline", {
|
|
525
|
+
payload: { workspaceId: Schema.String },
|
|
526
|
+
success: Schema.Array(Schema.String),
|
|
527
|
+
readPolicy: signedIn,
|
|
528
|
+
reads: () => [],
|
|
529
|
+
serverReads: ({ workspaceId }) => Effect.flatMap(TimelineData, (data) => data.readKeys(workspaceId)),
|
|
530
|
+
});
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
Provide `TimelineData` on the server to load the workspace's lists and return their keys. Use an application policy that checks workspace access; derived keys are refresh dependencies and grant no read access. Each write must publish the same keys. Keys are resolved once when the subscription opens. If new lists can join the workspace while it remains open, include a workspace bucket that every record write in that workspace also publishes, or reopen the subscription when membership changes. The browser never runs `serverReads`; changed hints identify the affected query for its normal authorized reread.
|
|
534
|
+
|
|
478
535
|
Return `false` when denial may be disclosed; the caller receives `QueryReadDenied`. For a private item whose existence the viewer must not learn, fail with a declared `NotFound` for both an absent item and an item owned by someone else:
|
|
479
536
|
|
|
480
537
|
```ts
|
|
@@ -608,19 +665,21 @@ Import the module that defines the name; the package has no root entry.
|
|
|
608
665
|
|
|
609
666
|
| Module | Functions and schemas |
|
|
610
667
|
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
611
|
-
| `operation.ts` | `query(name, { payload?, success?, rejections?, readPolicy, reads })`; `command(name, { payload?, success?, rejections?, invalidates })`; `stream(name, { payload?, success, rejections?, reads })`.
|
|
668
|
+
| `operation.ts` | `query(name, { payload?, success?, rejections?, readPolicy, reads, serverReads? })`; `command(name, { payload?, success?, rejections?, invalidates })`; `stream(name, { payload?, success, rejections?, reads })`. |
|
|
612
669
|
| `contract.ts` | `contract(name, { queries?, commands?, streams?, keyScope? })`, returning a native RPC group with `declaration: { name, queries, commands, streams, keyScope }`. |
|
|
613
670
|
| `rejection.ts` | `fieldRejection(struct, fields?)`; lower-level `rejectionSet(specs)`, which constructs the rejection classes, union schema and failure helpers used by operations. |
|
|
614
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. |
|
|
615
672
|
| `queryCoalesceWindow.ts` | `queryCoalesceWindow(query)`, a writable atom for a bound query's live changed-hint window. |
|
|
616
673
|
| `live.ts` | `LiveHint` schema; `live(runtime, { stream, resyncKeys, coalesceWindow?, initialResync?, keyContext?, resume?, retryDelay?, retryKeys? })`, exposing `connection`, `coalesceWindow`, `paused` and `status`. |
|
|
617
|
-
| `querySubscription.ts` | `querySubscription(rpc, references, viewer)` checks each referenced query and captures its scopes and ongoing authorization.
|
|
674
|
+
| `querySubscription.ts` | `querySubscription(rpc, references, viewer)` checks each referenced query, resolves its payload and server-derived keys, and captures its scopes and ongoing authorization. |
|
|
618
675
|
| `LiveServer.ts` | `LiveServer`, the shared live server service and its `.layer`, requiring `Reactivity`. |
|
|
619
676
|
| `makeLiveServer.ts` | `makeLiveServer`, an Effect requiring `Reactivity` that creates scoped server hint streams and a `resync` Effect. |
|
|
620
677
|
| `readPolicy.ts` | `QueryReadPolicy`, `Viewer`, `signedIn`, `authorizeReads(effect, request, viewer)`, `CurrentViewer`. |
|
|
621
678
|
| `validateReadPolicies.ts` | `validateReadPolicies(group)`, an Effect that fails with `MissingReadPolicies` when any served or subscribable query omits its policy. |
|
|
622
679
|
| `readPolicyErrors.ts` | `MissingReadPolicies` (boot), `MissingReadPolicy` (native-server request fallback) and `QueryReadDenied`. |
|
|
623
|
-
| `serverMetadata.ts` | `KeyScope`, `QueryDefinition.definition`, `CommandInvalidation.invalidates`, `ChangesQueries.queries`, `ChangesQueries.resolve(references)
|
|
680
|
+
| `serverMetadata.ts` | `KeyScope`, `QueryDefinition.definition`, `CommandInvalidation.invalidates`, `ChangesQueries.queries`, `ChangesQueries.resolve(references)` and `changesRpc(name, queries)` for server adapters. |
|
|
681
|
+
| `queryKeys.ts` | `queryKeys(queries, references, viewer?)` authorizes references and resolves payload and server-derived keys using the provided services. |
|
|
682
|
+
| `QueryServerReads.ts` | `QueryServerReads<Payload, E, R>`, the server-only resolver type. |
|
|
624
683
|
| `resume.ts` | `resumeSignal({ window?, native? })`, returning a native numeric signal atom. |
|
|
625
684
|
| `clientActivity.ts` | `clientActivity(client)` exposes a native activity Stream with a `current` Effect; `isClientIdle(state)` checks finite work. |
|
|
626
685
|
| `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. |
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Effect, Option } from "effect";
|
|
2
|
+
import type { Key } from "@shivaedev/changes/keys.ts";
|
|
3
|
+
import type { Viewer } from "#readPolicy.ts";
|
|
4
|
+
export type QueryServerReads<TPayload, E = never, R = never> = (payload: TPayload, viewer: Option.Option<Viewer>) => Effect.Effect<readonly Key[], E, R>;
|
|
5
|
+
//# sourceMappingURL=QueryServerReads.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryServerReads.d.ts","sourceRoot":"","sources":["../src/QueryServerReads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,MAAM,gBAAgB,CAAC,QAAQ,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,IAAI,CAC9D,OAAO,EAAE,QAAQ,EACjB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KACzB,MAAM,CAAC,MAAM,CAAC,SAAS,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryServerReads.js","sourceRoot":"","sources":["../src/QueryServerReads.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
declare const WebSocketRequired_base: Schema.Class<WebSocketRequired, Schema.TaggedStruct<"WebSocketRequired", {
|
|
3
|
+
readonly message: Schema.String;
|
|
4
|
+
}>, import("effect/Cause").YieldableError>;
|
|
5
|
+
export declare class WebSocketRequired extends WebSocketRequired_base {
|
|
6
|
+
}
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=WebSocketRequired.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebSocketRequired.d.ts","sourceRoot":"","sources":["../src/WebSocketRequired.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;AAEhC,qBAAa,iBAAkB,SAAQ,sBAAwF;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebSocketRequired.js","sourceRoot":"","sources":["../src/WebSocketRequired.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,OAAO,iBAAkB,SAAQ,MAAM,CAAC,WAAW,EAAqB,CAAC,mBAAmB,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;CAAG"}
|
package/dist/automaticLive.js
CHANGED
|
@@ -32,7 +32,7 @@ export function automaticLive(service, name, owner, resume, enabled = true, resu
|
|
|
32
32
|
}
|
|
33
33
|
const ready = Atom.make(false);
|
|
34
34
|
const delivery = queryDelivery(atom, decode, paused);
|
|
35
|
-
const source = delivery.atom;
|
|
35
|
+
const source = decode === undefined ? delivery.atom.pipe(Atom.setIdleTTL(0)) : delivery.atom;
|
|
36
36
|
const subscription = live(service.runtime, {
|
|
37
37
|
initialResync: false,
|
|
38
38
|
keyContext: owner?.context,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"automaticLive.js","sourceRoot":"","sources":["../src/automaticLive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAe,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEpE,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAI/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAmB,IAAI,EAAE,MAAM,UAAU,CAAC;AAEjD,OAAO,EAAwC,YAAY,EAAE,MAAM,YAAY,CAAC;AAKhF,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;AAW/E,MA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C,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3E,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC,OAAO,cAAc,CAAC,CAAC;CACxD;AACD,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,EACpC,IAAI,EACJ,WAAW,EACX,cAAc,EACd,UAAU,EACV,MAAM,EACN,MAAM,EACN,KAAK,EACL,MAAM,EACN,MAAM,EACN,QAAQ,EACR,YAAY,GACZ,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,4CAkGnB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Cause, Option, Predicate } from "effect";
|
|
1
2
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
2
3
|
import * as Atom from "effect/reactivity/Atom";
|
|
3
4
|
import { queryFailure } from "#internal/queryFailure.ts";
|
|
@@ -8,6 +9,9 @@ export function automaticQuery({ atom, assertOwner, coalesceWindow, equivalent,
|
|
|
8
9
|
assertOwner(get);
|
|
9
10
|
const registry = get.registry;
|
|
10
11
|
const dispatcher = registry.schedulerAsync.makeDispatcher();
|
|
12
|
+
let denied = false;
|
|
13
|
+
let stopSource;
|
|
14
|
+
get.addFinalizer(() => stopSource?.());
|
|
11
15
|
get.set(ready, false);
|
|
12
16
|
get.once(queryCoalesceWindow(gated));
|
|
13
17
|
get.subscribe(queryCoalesceWindow(gated), (value) => get.set(queryCoalesceWindow(atom), value), { immediate: true });
|
|
@@ -20,6 +24,7 @@ export function automaticQuery({ atom, assertOwner, coalesceWindow, equivalent,
|
|
|
20
24
|
}
|
|
21
25
|
}, 0);
|
|
22
26
|
if (value.connection === "live") {
|
|
27
|
+
denied = false;
|
|
23
28
|
registry.set(ready, true);
|
|
24
29
|
}
|
|
25
30
|
}
|
|
@@ -37,15 +42,19 @@ export function automaticQuery({ atom, assertOwner, coalesceWindow, equivalent,
|
|
|
37
42
|
get.addFinalizer(registry.subscribe(coalesceWindow, (value) => registry.set(subscription.coalesceWindow, value), { immediate: true }));
|
|
38
43
|
let started = false;
|
|
39
44
|
function start() {
|
|
40
|
-
if (
|
|
45
|
+
if (stopSource !== undefined) {
|
|
41
46
|
return;
|
|
42
47
|
}
|
|
43
48
|
started = true;
|
|
44
49
|
if (!pushed) {
|
|
45
50
|
get.refresh(source);
|
|
46
51
|
}
|
|
47
|
-
const publish = queryResult(equivalent, (value) =>
|
|
48
|
-
|
|
52
|
+
const publish = queryResult(equivalent, (value) => {
|
|
53
|
+
if (!denied) {
|
|
54
|
+
get.setSelf(value);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
stopSource = registry.subscribe(source, publish);
|
|
49
58
|
publish(get.once(source));
|
|
50
59
|
}
|
|
51
60
|
get.once(ready);
|
|
@@ -54,7 +63,15 @@ export function automaticQuery({ atom, assertOwner, coalesceWindow, equivalent,
|
|
|
54
63
|
start();
|
|
55
64
|
}
|
|
56
65
|
});
|
|
57
|
-
const failed = queryFailure(() => started && !pushed, (cause) =>
|
|
66
|
+
const failed = queryFailure(() => started && !pushed, (cause) => {
|
|
67
|
+
if (Option.exists(Cause.findErrorOption(cause), Predicate.isTagged("QueryReadDenied"))) {
|
|
68
|
+
denied = true;
|
|
69
|
+
registry.set(ready, false);
|
|
70
|
+
stopSource?.();
|
|
71
|
+
stopSource = undefined;
|
|
72
|
+
}
|
|
73
|
+
get.setSelf(AsyncResult.failure(cause));
|
|
74
|
+
});
|
|
58
75
|
get.subscribe(subscription.status, failed);
|
|
59
76
|
get.addFinalizer(registry.subscribe(paused, (value) => registry.set(subscription.paused, value), { immediate: true }));
|
|
60
77
|
function resume() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"automaticQuery.js","sourceRoot":"","sources":["../../src/internal/automaticQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"automaticQuery.js","sourceRoot":"","sources":["../../src/internal/automaticQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK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AC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CACxE,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
1
|
+
import { type Option, Schema } from "effect";
|
|
2
|
+
import type { Key } from "@shivaedev/changes/keys.ts";
|
|
3
|
+
import type { OperationShape, PayloadSchema } from "#operation.ts";
|
|
4
|
+
import type { CollectionReads } from "#permissionReadPolicy.ts";
|
|
5
|
+
import type { QueryServerReads } from "#QueryServerReads.ts";
|
|
6
|
+
import type { Viewer } from "#readPolicy.ts";
|
|
7
|
+
import { type MatchingTags, type RejectedBy, type RejectionSpecs } from "#rejection.ts";
|
|
8
|
+
export interface Declaration<TPayload extends Schema.Top | Schema.Struct.Fields, TSuccess extends Schema.Top, TSpecs extends RejectionSpecs> {
|
|
9
|
+
readonly payload?: TPayload;
|
|
10
|
+
readonly rejections?: TSpecs & MatchingTags<TSpecs>;
|
|
11
|
+
readonly success?: TSuccess;
|
|
12
|
+
}
|
|
13
|
+
export type QueryDeclaration<TPayload extends Schema.Top | Schema.Struct.Fields, TSuccess extends Schema.Top, TSpecs extends RejectionSpecs, R, TLive extends "rerun-and-compare" | undefined> = Declaration<TPayload, TSuccess, TSpecs> & CollectionReads<PayloadSchema<TPayload>["Type"], NoInfer<RejectedBy<TSpecs>>, R> & {
|
|
14
|
+
readonly live?: TLive;
|
|
15
|
+
readonly reads: (payload: PayloadSchema<TPayload>["Type"], viewer: Option.Option<Viewer>) => readonly Key[];
|
|
16
|
+
readonly serverReads?: QueryServerReads<PayloadSchema<TPayload>["Type"], NoInfer<RejectedBy<TSpecs>>, R>;
|
|
17
|
+
};
|
|
4
18
|
export interface Loose {
|
|
5
19
|
readonly payload?: Schema.Top | Schema.Struct.Fields;
|
|
6
20
|
readonly rejections?: RejectionSpecs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operationDeclaration.d.ts","sourceRoot":"","sources":["../../src/internal/operationDeclaration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"operationDeclaration.d.ts","sourceRoot":"","sources":["../../src/internal/operationDeclaration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAgB,MAAM,eAAe,CAAC;AAEtG,MAAM,WAAW,WAAW,CAAC,QAAQ,SAAS,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,SAAS,MAAM,CAAC,GAAG,EAAE,MAAM,SAAS,cAAc;IAC1I,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACpD,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC;CAC5B;AAED,MAAM,MAAM,gBAAgB,CAC3B,QAAQ,SAAS,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,E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
|
+
{"version":3,"file":"operationDeclaration.js","sourceRoot":"","sources":["../../src/internal/operationDeclaration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,MAAM,QAAQ,CAAC;AAM7C,OAAO,EAA2D,YAAY,EAAE,MAAM,eAAe,CAAC;AA2BtG,SAAS,aAAa,CAAC,OAAyB;IAC/C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,MAAM,CAAC,IAAI,CAAC;IACpB,CAAC;IACD,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,SAAS,CAAuC,IAAW,EAAE,IAAY,EAAE,WAAkB;IAC5G,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,GAAG,EAAE,EAAE,GAAG,WAAW,CAAC;IAC1D,OAAO;QACN,IAAI;QACJ,IAAI;QACJ,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC;QAC/B,UAAU;QACV,OAAO,EAAE,OAAO,IAAI,MAAM,CAAC,IAAI;QAC/B,GAAG,YAAY,CAAC,UAAU,CAAC;KAC3B,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryReactivity.d.ts","sourceRoot":"","sources":["../../src/internal/queryReactivity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAKpE,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,MAAM,IAAI,sEAInE,SAAS,MAAM,EAAE,UAAU,YAAY,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"queryReactivity.d.ts","sourceRoot":"","sources":["../../src/internal/queryReactivity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAKpE,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,MAAM,IAAI,sEAInE,SAAS,MAAM,EAAE,UAAU,YAAY,CAAC,YAAY,0DAuH/E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Duration, Effect } from "effect";
|
|
1
|
+
import { Cause, Duration, Effect, Option, Predicate } from "effect";
|
|
2
2
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
3
|
import * as Atom from "effect/reactivity/Atom";
|
|
4
4
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
@@ -42,6 +42,11 @@ export function queryReactivity(runtime, queue) {
|
|
|
42
42
|
pending = undefined;
|
|
43
43
|
dequeue();
|
|
44
44
|
}
|
|
45
|
+
function reread() {
|
|
46
|
+
if (!Option.exists(AsyncResult.cause(get.once(source)), (cause) => Option.exists(Cause.findErrorOption(cause), Predicate.isTagged("QueryReadDenied")))) {
|
|
47
|
+
get.refresh(source);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
45
50
|
function refresh(active) {
|
|
46
51
|
if (!active()) {
|
|
47
52
|
dequeue();
|
|
@@ -52,7 +57,7 @@ export function queryReactivity(runtime, queue) {
|
|
|
52
57
|
}
|
|
53
58
|
else {
|
|
54
59
|
pending = undefined;
|
|
55
|
-
|
|
60
|
+
reread();
|
|
56
61
|
dequeue();
|
|
57
62
|
}
|
|
58
63
|
}
|
|
@@ -65,7 +70,7 @@ export function queryReactivity(runtime, queue) {
|
|
|
65
70
|
const delay = Duration.toMillis(Duration.fromInputUnsafe(get.once(queryCoalesceWindow(wrapped)) ?? batch.window ?? 0));
|
|
66
71
|
if (delay === 0) {
|
|
67
72
|
clear();
|
|
68
|
-
|
|
73
|
+
reread();
|
|
69
74
|
}
|
|
70
75
|
else if (!scheduled) {
|
|
71
76
|
queued ??= queue?.();
|
|
@@ -78,7 +83,7 @@ export function queryReactivity(runtime, queue) {
|
|
|
78
83
|
get.addFinalizer(reactivity.registerUnsafe(keys, () => {
|
|
79
84
|
if (!liveBatches.has(reactivity)) {
|
|
80
85
|
clear();
|
|
81
|
-
|
|
86
|
+
reread();
|
|
82
87
|
}
|
|
83
88
|
}));
|
|
84
89
|
get.subscribe(source, (value) => {
|
|
@@ -87,7 +92,7 @@ export function queryReactivity(runtime, queue) {
|
|
|
87
92
|
const active = pending;
|
|
88
93
|
pending = undefined;
|
|
89
94
|
if (active()) {
|
|
90
|
-
|
|
95
|
+
reread();
|
|
91
96
|
}
|
|
92
97
|
dequeue();
|
|
93
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryReactivity.js","sourceRoot":"","sources":["../../src/internal/queryReactivity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"queryReactivity.js","sourceRoot":"","sources":["../../src/internal/queryReactivity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAE/C,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO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|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Effect, type Option } from "effect";
|
|
2
|
+
import type { QueryShape } from "#operation.ts";
|
|
3
|
+
import type { Viewer } from "#readPolicy.ts";
|
|
4
|
+
export declare const queryReadKeys: <E, R>(query: QueryShape<E, R>, payload: unknown, viewer: Option.Option<Viewer>) => Effect.Effect<import("@shivaedev/changes/keys.ts").Key[], E, R>;
|
|
5
|
+
//# sourceMappingURL=queryReadKeys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryReadKeys.d.ts","sourceRoot":"","sources":["../../src/internal/queryReadKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,eAAO,MAAM,aAAa,GAAgC,CAAC,EAAE,CAAC,8IAG5D,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
export const queryReadKeys = Effect.fnUntraced(function* (query, payload, viewer) {
|
|
3
|
+
const derived = query.serverReads === undefined ? [] : yield* query.serverReads(payload, viewer);
|
|
4
|
+
return [...query.reads(payload, viewer), ...derived];
|
|
5
|
+
});
|
|
6
|
+
//# sourceMappingURL=queryReadKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryReadKeys.js","sourceRoot":"","sources":["../../src/internal/queryReadKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAe,MAAM,QAAQ,CAAC;AAI7C,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAQ,KAAuB,EAAE,OAAgB,EAAE,MAA6B;IACvI,MAAM,OAAO,GAAG,KAAK,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACjG,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC;AACtD,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { QueryShape } from "#operation.ts";
|
|
3
|
+
import type { QueryReference } from "#serverMetadata.ts";
|
|
4
|
+
export declare function resolveQueries(queries: readonly QueryShape[], requested: readonly QueryReference[]): Effect.Effect<{
|
|
5
|
+
payload: unknown;
|
|
6
|
+
query: QueryShape<unknown, unknown>;
|
|
7
|
+
}[], never, never>;
|
|
8
|
+
//# sourceMappingURL=resolveQueries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveQueries.d.ts","sourceRoot":"","sources":["../../src/internal/resolveQueries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,wBAAgB,cAAc,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,EAAE,SAAS,EAAE,SAAS,cAAc,EAAE;;;mBAKlG"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
export function resolveQueries(queries, requested) {
|
|
3
|
+
return Effect.forEach(requested, (reference) => {
|
|
4
|
+
const query = queries.find((candidate) => candidate.name === reference.query);
|
|
5
|
+
return query === undefined ? Effect.die(new Error(`Unknown query: ${reference.query}`)) : Effect.succeed({ payload: reference.payload, query });
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=resolveQueries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveQueries.js","sourceRoot":"","sources":["../../src/internal/resolveQueries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,MAAM,UAAU,cAAc,CAAC,OAA8B,EAAE,SAAoC;IAClG,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,SAAS,EAAE,EAAE;QAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9E,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,kBAAkB,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IACjJ,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryOnChange.d.ts","sourceRoot":"","sources":["../../src/internal/retryOnChange.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"retryOnChange.d.ts","sourceRoot":"","sources":["../../src/internal/retryOnChange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAqB,MAAM,QAAQ,CAAC;AAC1D,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAC/D,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,eAAO,MAAM,aAAa,GAAgC,CAAC,4EAA4E,IAAI,iHA8BzI,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
1
|
+
import { Cause, Effect, Option, Predicate } from "effect";
|
|
2
2
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
3
3
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
4
4
|
export const retryOnChange = Effect.fnUntraced(function* (status, keys, restart) {
|
|
@@ -6,13 +6,18 @@ export const retryOnChange = Effect.fnUntraced(function* (status, keys, restart)
|
|
|
6
6
|
const registry = yield* AtomRegistry.AtomRegistry;
|
|
7
7
|
const dispatcher = registry.schedulerAsync.makeDispatcher();
|
|
8
8
|
let active = true;
|
|
9
|
+
function canRetry() {
|
|
10
|
+
const current = registry.get(status);
|
|
11
|
+
return (current.connection === "failed"
|
|
12
|
+
&& !Option.exists(current.failure, (cause) => Option.exists(Cause.findErrorOption(cause), Predicate.isTagged("QueryReadDenied"))));
|
|
13
|
+
}
|
|
9
14
|
function retry() {
|
|
10
|
-
if (active &&
|
|
15
|
+
if (active && canRetry()) {
|
|
11
16
|
restart();
|
|
12
17
|
}
|
|
13
18
|
}
|
|
14
19
|
function changed() {
|
|
15
|
-
if (
|
|
20
|
+
if (canRetry()) {
|
|
16
21
|
dispatcher.scheduleTask(retry, 0);
|
|
17
22
|
}
|
|
18
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryOnChange.js","sourceRoot":"","sources":["../../src/internal/retryOnChange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"retryOnChange.js","sourceRoot":"","sources":["../../src/internal/retryOnChange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE1D,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAC/D,OAAO,KAAK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AAK,CAAC;QACf,OAAO,EAAE,CAAC;IACX,CAAC,CAAC,CACH,CAAC;AACH,CAAC,CAAC,CAAC"}
|
package/dist/makeLiveServer.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { QueryUpdate } from "#queryUpdate.ts";
|
|
|
7
7
|
import { QueryReadDenied } from "#readPolicyErrors.ts";
|
|
8
8
|
export declare const makeLiveServer: Effect.Effect<{
|
|
9
9
|
resync: Effect.Effect<number, never, never>;
|
|
10
|
-
stream: (keys: readonly Key[], context?: KeyContext) => Stream.Stream<LiveHint>;
|
|
10
|
+
stream: (keys: readonly Key[], context?: KeyContext, globalKeys?: readonly Key[]) => Stream.Stream<LiveHint>;
|
|
11
11
|
subscribe: {
|
|
12
12
|
<E, R>(subscription: QuerySubscription<E, R>, context?: KeyContext): Stream.Stream<LiveHint, E | QueryReadDenied, R>;
|
|
13
13
|
<E, R>(subscription: QuerySubscription<E, R>, context: KeyContext | undefined, read: QueryRerun<E, R>): Stream.Stream<QueryUpdate, E | QueryReadDenied, R>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeLiveServer.d.ts","sourceRoot":"","sources":["../src/makeLiveServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,EAAE,MAAM,QAAQ,CAAC;AACvD,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,UAAU,EAAY,MAAM,4BAA4B,CAAC;AAGjF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,eAAO,MAAM,cAAc;;mBAIN,SAAS,GAAG,EAAE,YAAY,UAAU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