@shivaedev/contract 0.39.0 → 0.40.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.
Files changed (94) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +29 -28
  3. package/dist/adapters/LiveDispatcher.d.ts +9 -0
  4. package/dist/adapters/LiveDispatcher.d.ts.map +1 -0
  5. package/dist/adapters/LiveDispatcher.js +5 -0
  6. package/dist/adapters/LiveDispatcher.js.map +1 -0
  7. package/dist/adapters/liveHintStream.d.ts +30 -0
  8. package/dist/adapters/liveHintStream.d.ts.map +1 -0
  9. package/dist/adapters/liveHintStream.js +10 -0
  10. package/dist/adapters/liveHintStream.js.map +1 -0
  11. package/dist/adapters/openLiveHints.d.ts +30 -0
  12. package/dist/adapters/openLiveHints.d.ts.map +1 -0
  13. package/dist/adapters/openLiveHints.js +59 -0
  14. package/dist/adapters/openLiveHints.js.map +1 -0
  15. package/dist/adapters/refreshSubscription.d.ts +4 -0
  16. package/dist/adapters/refreshSubscription.d.ts.map +1 -0
  17. package/dist/adapters/refreshSubscription.js +5 -0
  18. package/dist/adapters/refreshSubscription.js.map +1 -0
  19. package/dist/adapters/standaloneLiveServer.d.ts +32 -0
  20. package/dist/adapters/standaloneLiveServer.d.ts.map +1 -0
  21. package/dist/adapters/standaloneLiveServer.js +13 -0
  22. package/dist/adapters/standaloneLiveServer.js.map +1 -0
  23. package/dist/adapters/withClientProtocol.d.ts +4 -0
  24. package/dist/adapters/withClientProtocol.d.ts.map +1 -0
  25. package/dist/adapters/withClientProtocol.js +6 -0
  26. package/dist/adapters/withClientProtocol.js.map +1 -0
  27. package/dist/adapters/withPolicyContext.d.ts +4 -0
  28. package/dist/adapters/withPolicyContext.d.ts.map +1 -0
  29. package/dist/adapters/withPolicyContext.js +7 -0
  30. package/dist/adapters/withPolicyContext.js.map +1 -0
  31. package/dist/live-server/initialize.d.ts +6 -0
  32. package/dist/live-server/initialize.d.ts.map +1 -0
  33. package/dist/live-server/initialize.js +7 -0
  34. package/dist/live-server/initialize.js.map +1 -0
  35. package/dist/live-server/layer.d.ts +3 -0
  36. package/dist/live-server/layer.d.ts.map +1 -0
  37. package/dist/live-server/layer.js +5 -0
  38. package/dist/live-server/layer.js.map +1 -0
  39. package/dist/live-server/register.d.ts +26 -0
  40. package/dist/live-server/register.d.ts.map +1 -0
  41. package/dist/live-server/register.js +8 -0
  42. package/dist/live-server/register.js.map +1 -0
  43. package/dist/live-server/resync.d.ts +4 -3
  44. package/dist/live-server/resync.d.ts.map +1 -1
  45. package/dist/live-server/resync.js +8 -2
  46. package/dist/live-server/resync.js.map +1 -1
  47. package/dist/live-server/service.d.ts +49 -0
  48. package/dist/live-server/service.d.ts.map +1 -0
  49. package/dist/live-server/service.js +19 -0
  50. package/dist/live-server/service.js.map +1 -0
  51. package/dist/live-server/stream.d.ts +4 -4
  52. package/dist/live-server/stream.d.ts.map +1 -1
  53. package/dist/live-server/stream.js +6 -3
  54. package/dist/live-server/stream.js.map +1 -1
  55. package/dist/live-server/subscribe.d.ts +3 -4
  56. package/dist/live-server/subscribe.d.ts.map +1 -1
  57. package/dist/live-server/subscribe.js +28 -6
  58. package/dist/live-server/subscribe.js.map +1 -1
  59. package/dist/makeLiveServer.d.ts +5 -10
  60. package/dist/makeLiveServer.d.ts.map +1 -1
  61. package/dist/makeLiveServer.js +3 -90
  62. package/dist/makeLiveServer.js.map +1 -1
  63. package/dist/querySubscription.js +5 -11
  64. package/dist/querySubscription.js.map +1 -1
  65. package/dist/readPolicy.d.ts.map +1 -1
  66. package/dist/readPolicy.js +2 -3
  67. package/dist/readPolicy.js.map +1 -1
  68. package/dist/rpcClient.d.ts.map +1 -1
  69. package/dist/rpcClient.js +2 -1
  70. package/dist/rpcClient.js.map +1 -1
  71. package/package.json +8 -8
  72. package/src/adapters/LiveDispatcher.ts +10 -0
  73. package/src/adapters/liveHintStream.ts +15 -0
  74. package/src/adapters/openLiveHints.ts +62 -0
  75. package/src/adapters/refreshSubscription.ts +6 -0
  76. package/src/adapters/standaloneLiveServer.ts +19 -0
  77. package/src/adapters/withClientProtocol.ts +10 -0
  78. package/src/adapters/withPolicyContext.ts +8 -0
  79. package/src/live-server/initialize.ts +7 -0
  80. package/src/live-server/layer.ts +5 -0
  81. package/src/live-server/register.ts +10 -0
  82. package/src/live-server/resync.ts +9 -4
  83. package/src/live-server/service.ts +19 -0
  84. package/src/live-server/stream.ts +7 -4
  85. package/src/live-server/subscribe.ts +43 -12
  86. package/src/makeLiveServer.ts +3 -104
  87. package/src/querySubscription.ts +8 -11
  88. package/src/readPolicy.ts +2 -3
  89. package/src/rpcClient.ts +4 -6
  90. package/dist/LiveServer.d.ts +0 -27
  91. package/dist/LiveServer.d.ts.map +0 -1
  92. package/dist/LiveServer.js +0 -18
  93. package/dist/LiveServer.js.map +0 -1
  94. package/src/LiveServer.ts +0 -18
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.40.0 - 2026-11-05
4
+
5
+ ### Added
6
+
7
+ - `LiveServer.register(keys)` returns a scoped registration stream whose read keys can be replaced while it is consumed.
8
+
9
+ ### Breaking
10
+
11
+ - Import `LiveServer` from `@shivaedev/contract/live-server/service.ts`. Replace `live.subscribe(subscription, read?)` with `subscribe(subscription, read?)` from `@shivaedev/contract/live-server/subscribe.ts`; replace `LiveServer.layer` with `liveServerLayer` from `@shivaedev/contract/live-server/layer.ts` and provide that one Layer. Unwrap the subscription Effect with `Stream.unwrap`. Reactivity remains bound by the Layer, and policy and query-runner requirements remain on the Stream. The `makeLiveServer` convenience API keeps its existing shape.
12
+
3
13
  ## 0.39.0 - 2026-11-05
4
14
 
5
15
  ### Breaking
package/README.md CHANGED
@@ -459,7 +459,7 @@ Custom subscription handlers use `changesHandlerLayer` to derive the reserved ha
459
459
  ```ts
460
460
  import { Effect, Stream } from "effect";
461
461
  import { changesHandlerLayer } from "@shivaedev/contract/changesHandlerLayer.ts";
462
- import { LiveServer } from "@shivaedev/contract/LiveServer.ts";
462
+ import { subscribe } from "@shivaedev/contract/live-server/subscribe.ts";
463
463
  import { querySubscription } from "@shivaedev/contract/querySubscription.ts";
464
464
  import { CurrentViewer } from "@shivaedev/contract/readPolicy.ts";
465
465
  import { Notes } from "./notes.ts";
@@ -472,8 +472,7 @@ const changes = changesHandlerLayer(
472
472
  Effect.gen(function* () {
473
473
  const viewer = yield* CurrentViewer;
474
474
  const subscription = yield* querySubscription(rpc, queries, viewer);
475
- const live = yield* LiveServer;
476
- return yield* live.subscribe(subscription);
475
+ return yield* subscribe(subscription);
477
476
  }),
478
477
  ),
479
478
  );
@@ -569,7 +568,7 @@ Call the release functions and dispose the registry when the application's root
569
568
 
570
569
  ### Server hint streams
571
570
 
572
- 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.
571
+ Import `LiveServer` from `@shivaedev/contract/live-server/service.ts`. Import `liveServerLayer` from `@shivaedev/contract/live-server/layer.ts` and provide it 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)` with `Stream.unwrap`, and call `hints.resync()` to reconcile its active streams. For authorized query subscriptions, import `subscribe` from `@shivaedev/contract/live-server/subscribe.ts` and unwrap `subscribe(subscription, read?)`. This operation yields `LiveServer`; its Layer binds Reactivity, while subscription policy failures and query-runner requirements remain on the returned Stream. Each Layer build owns its resync identity and stream counter. The package Layer also provides its dispatcher service. `register(keys)` exposes a scoped stream registration with `replaceKeys` for updating its read scope; consumption and interruption own that registration.
573
572
 
574
573
  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.
575
574
 
@@ -794,30 +793,32 @@ expect(yield* heard(bob, [notes.item(1)], { within: "50 millis" })).toBe(false);
794
793
 
795
794
  Import the module that defines the name; the package has no root entry.
796
795
 
797
- | Module | Functions and schemas |
798
- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
799
- | `operation.ts` | `query(name, { payload?, success?, rejections?, readPolicy, reads, serverReads? })`; `command(name, { payload?, success?, rejections?, invalidates })`; `stream(name, { payload?, success, rejections?, reads })`. |
800
- | `contract.ts` | `contract(name, { queries?, commands?, streams?, keyScope? })`, returning a native RPC group with `declaration: { name, queries, commands, streams, keyScope }`. |
801
- | `rejection.ts` | `fieldRejection(struct, fields?)`; lower-level `rejectionSet(specs)`, which constructs the rejection classes, union schema and failure helpers used by operations. |
802
- | `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. |
803
- | `queryCoalesceWindow.ts` | `queryCoalesceWindow(query)`, a writable atom for a bound query's live changed-hint window. |
804
- | `clientKeys.ts` | `KeyContext`, `clientReadKeys`, `clientInvalidationKeys`: registry-local cache keys for custom clients. |
805
- | `live.ts` | `LiveHint` schema; `live(runtime, { stream, resyncKeys, coalesceWindow?, initialResync?, keyContext?, resume?, retryDelay?, retryKeys? })`, exposing `connection`, `coalesceWindow`, `paused` and `status`. |
806
- | `querySubscription.ts` | `querySubscription(rpc, references, viewer)` checks each referenced query, resolves its payload and server-derived keys, and captures its scopes and ongoing authorization. |
807
- | `LiveServer.ts` | `LiveServer`, the shared live server service and its `.layer`, requiring `Reactivity`. |
808
- | `makeLiveServer.ts` | `makeLiveServer`, an Effect requiring `Reactivity` that creates scoped server hint streams and a `resync` Effect. |
809
- | `readPolicy.ts` | `QueryReadPolicy`, `Viewer`, `signedIn`, `CurrentViewer`; `authorizeReads(effect, request, viewer)` for direct handler reruns outside RPC middleware. |
810
- | `ReadPolicyGuard.ts` | `ReadPolicyGuard`, the defaulted middleware reference attached to contract queries; `readPolicyGuardLayer({ websocket? })`, an optional override that refuses HTTP `$changes` calls by default. |
811
- | `validateReadPolicies.ts` | `validateReadPolicies(group)`, an Effect that fails with `MissingReadPolicies` when any served or subscribable query omits its policy. |
812
- | `readPolicyErrors.ts` | `MissingReadPolicies` (boot), `MissingReadPolicy` (native-server request fallback) and `QueryReadDenied`. |
813
- | `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. |
814
- | `commandResult.ts` | `commandResult({ result, invalidates })` contributes server-only keys from a guarded command handler and returns only its success value. |
815
- | `serverMetadata.ts` | `KeyScope`, `QueryDefinition.definition`, `CommandInvalidation.invalidates`, `ChangesQueries.queries`, `ChangesQueries.resolve(references)` and `changesRpc(name, queries)` for server adapters. |
816
- | `queryKeys.ts` | `queryKeys(queries, references, viewer?)` authorizes references and resolves payload and server-derived keys using the provided services. |
817
- | `QueryServerReads.ts` | `QueryServerReads<Payload, E, R>`, the server-only resolver type. |
818
- | `resume.ts` | `resumeSignal({ window?, native? })`, returning a native numeric signal atom. |
819
- | `querySignals.ts` | `querySignals(query)` exposes completion counts and subscription status as a native atom. |
820
- | `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. |
796
+ | Module | Functions and schemas |
797
+ | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
798
+ | `operation.ts` | `query(name, { payload?, success?, rejections?, readPolicy, reads, serverReads? })`; `command(name, { payload?, success?, rejections?, invalidates })`; `stream(name, { payload?, success, rejections?, reads })`. |
799
+ | `contract.ts` | `contract(name, { queries?, commands?, streams?, keyScope? })`, returning a native RPC group with `declaration: { name, queries, commands, streams, keyScope }`. |
800
+ | `rejection.ts` | `fieldRejection(struct, fields?)`; lower-level `rejectionSet(specs)`, which constructs the rejection classes, union schema and failure helpers used by operations. |
801
+ | `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. |
802
+ | `queryCoalesceWindow.ts` | `queryCoalesceWindow(query)`, a writable atom for a bound query's live changed-hint window. |
803
+ | `clientKeys.ts` | `KeyContext`, `clientReadKeys`, `clientInvalidationKeys`: registry-local cache keys for custom clients. |
804
+ | `live.ts` | `LiveHint` schema; `live(runtime, { stream, resyncKeys, coalesceWindow?, initialResync?, keyContext?, resume?, retryDelay?, retryKeys? })`, exposing `connection`, `coalesceWindow`, `paused` and `status`. |
805
+ | `querySubscription.ts` | `querySubscription(rpc, references, viewer)` checks each referenced query, resolves its payload and server-derived keys, and captures its scopes and ongoing authorization. |
806
+ | `live-server/service.ts` | `LiveServer`, the shared live server service. |
807
+ | `live-server/layer.ts` | `liveServerLayer`, providing `LiveServer` and its dispatcher dependency, requiring `Reactivity`. |
808
+ | `live-server/subscribe.ts` | `subscribe(subscription, read?)`, an Effect requiring `LiveServer` that returns an authorized subscription Stream with its policy and query-runner requirements. |
809
+ | `makeLiveServer.ts` | `makeLiveServer`, an Effect requiring `Reactivity` that creates scoped server hint streams and a `resync` Effect. |
810
+ | `readPolicy.ts` | `QueryReadPolicy`, `Viewer`, `signedIn`, `CurrentViewer`; `authorizeReads(effect, request, viewer)` for direct handler reruns outside RPC middleware. |
811
+ | `ReadPolicyGuard.ts` | `ReadPolicyGuard`, the defaulted middleware reference attached to contract queries; `readPolicyGuardLayer({ websocket? })`, an optional override that refuses HTTP `$changes` calls by default. |
812
+ | `validateReadPolicies.ts` | `validateReadPolicies(group)`, an Effect that fails with `MissingReadPolicies` when any served or subscribable query omits its policy. |
813
+ | `readPolicyErrors.ts` | `MissingReadPolicies` (boot), `MissingReadPolicy` (native-server request fallback) and `QueryReadDenied`. |
814
+ | `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. |
815
+ | `commandResult.ts` | `commandResult({ result, invalidates })` contributes server-only keys from a guarded command handler and returns only its success value. |
816
+ | `serverMetadata.ts` | `KeyScope`, `QueryDefinition.definition`, `CommandInvalidation.invalidates`, `ChangesQueries.queries`, `ChangesQueries.resolve(references)` and `changesRpc(name, queries)` for server adapters. |
817
+ | `queryKeys.ts` | `queryKeys(queries, references, viewer?)` authorizes references and resolves payload and server-derived keys using the provided services. |
818
+ | `QueryServerReads.ts` | `QueryServerReads<Payload, E, R>`, the server-only resolver type. |
819
+ | `resume.ts` | `resumeSignal({ window?, native? })`, returning a native numeric signal atom. |
820
+ | `querySignals.ts` | `querySignals(query)` exposes completion counts and subscription status as a native atom. |
821
+ | `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. |
821
822
 
822
823
  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.
823
824
 
@@ -0,0 +1,9 @@
1
+ import { Context, Layer, Scheduler } from "effect";
2
+ declare const LiveDispatcher_base: Context.ServiceClass<LiveDispatcher, "@shivaedev/contract/LiveDispatcher", {
3
+ readonly dispatcher: Scheduler.SchedulerDispatcher;
4
+ }>;
5
+ export declare class LiveDispatcher extends LiveDispatcher_base {
6
+ static readonly layer: Layer.Layer<LiveDispatcher, never, never>;
7
+ }
8
+ export {};
9
+ //# sourceMappingURL=LiveDispatcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LiveDispatcher.d.ts","sourceRoot":"","sources":["../../src/adapters/LiveDispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;;yBAEgC,SAAS,CAAC,mBAAmB;;AAAxH,qBAAa,cAAe,SAAQ,mBAEnC;IACA,MAAM,CAAC,QAAQ,CAAC,KAAK,4CAGnB;CACF"}
@@ -0,0 +1,5 @@
1
+ import { Context, Effect, Layer, Scheduler } from "effect";
2
+ export class LiveDispatcher extends Context.Service()("@shivaedev/contract/LiveDispatcher") {
3
+ static layer = Layer.effect(this, Effect.map(Scheduler.Scheduler, (scheduler) => ({ dispatcher: scheduler.makeDispatcher() })));
4
+ }
5
+ //# sourceMappingURL=LiveDispatcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LiveDispatcher.js","sourceRoot":"","sources":["../../src/adapters/LiveDispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE3D,MAAM,OAAO,cAAe,SAAQ,OAAO,CAAC,OAAO,EAA0E,CAC5H,oCAAoC,CACpC;IACA,MAAM,CAAU,KAAK,GAAG,KAAK,CAAC,MAAM,CACnC,IAAI,EACJ,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,SAAS,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,CAC5F,CAAC;CACF"}
@@ -0,0 +1,30 @@
1
+ import { Effect, Stream } from "effect";
2
+ import * as Reactivity from "effect/reactivity/Reactivity";
3
+ import type { Key } from "@shivaedev/changes/keys.ts";
4
+ import { LiveDispatcher } from "./LiveDispatcher.ts";
5
+ export declare const liveHintStream: (state: {
6
+ openStreams: import("effect/Ref").Ref<number>;
7
+ resyncKey: string;
8
+ }, keys: readonly Key[]) => Effect.Effect<Stream.Stream<{
9
+ replaceKeys: (current: readonly Key[]) => void;
10
+ stream: Stream.Stream<{
11
+ readonly _tag: "Changed";
12
+ readonly keys: readonly ({
13
+ readonly _tag: "Bucket";
14
+ readonly collection: string;
15
+ readonly field: string;
16
+ readonly value: string | number;
17
+ } | {
18
+ readonly _tag: "List";
19
+ readonly collection: string;
20
+ } | {
21
+ readonly _tag: "Item";
22
+ readonly collection: string;
23
+ readonly id: string | number;
24
+ })[];
25
+ readonly queryIndexes?: readonly number[] | undefined;
26
+ } | {
27
+ readonly _tag: "Resync";
28
+ }, never, never>;
29
+ }, never, never>, never, LiveDispatcher | Reactivity.Reactivity>;
30
+ //# sourceMappingURL=liveHintStream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"liveHintStream.d.ts","sourceRoot":"","sources":["../../src/adapters/liveHintStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;gEAOzB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { Effect, Stream } from "effect";
2
+ import * as Reactivity from "effect/reactivity/Reactivity";
3
+ import { LiveDispatcher } from "./LiveDispatcher.js";
4
+ import { openLiveHints } from "./openLiveHints.js";
5
+ export const liveHintStream = Effect.fn("LiveServer.liveHintStream")(function* (state, keys) {
6
+ const reactivity = yield* Reactivity.Reactivity;
7
+ const dispatcher = yield* LiveDispatcher;
8
+ return Stream.unwrap(Effect.map(openLiveHints(state, keys), Stream.succeed)).pipe(Stream.provideService(Reactivity.Reactivity, reactivity), Stream.provideService(LiveDispatcher, dispatcher));
9
+ });
10
+ //# sourceMappingURL=liveHintStream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"liveHintStream.js","sourceRoot":"","sources":["../../src/adapters/liveHintStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAG3D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,EAAE,CAAC,2BAA2B,CAAC,CAAC,QAAQ,CAAC,EAAE,KAAwC,EAAE,IAAoB;IAC7I,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;IAChD,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,cAAc,CAAC;IACzC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAChF,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,EACxD,MAAM,CAAC,cAAc,CAAC,cAAc,EAAE,UAAU,CAAC,CACjD,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { Effect, Ref, Stream } from "effect";
2
+ import * as Reactivity from "effect/reactivity/Reactivity";
3
+ import { type Key } from "@shivaedev/changes/keys.ts";
4
+ import { LiveDispatcher } from "./LiveDispatcher.ts";
5
+ export declare const openLiveHints: (state: {
6
+ openStreams: Ref.Ref<number>;
7
+ resyncKey: string;
8
+ }, keys: readonly Key[]) => Effect.Effect<{
9
+ replaceKeys: (current: readonly Key[]) => void;
10
+ stream: Stream.Stream<{
11
+ readonly _tag: "Changed";
12
+ readonly keys: readonly ({
13
+ readonly _tag: "Bucket";
14
+ readonly collection: string;
15
+ readonly field: string;
16
+ readonly value: string | number;
17
+ } | {
18
+ readonly _tag: "List";
19
+ readonly collection: string;
20
+ } | {
21
+ readonly _tag: "Item";
22
+ readonly collection: string;
23
+ readonly id: string | number;
24
+ })[];
25
+ readonly queryIndexes?: readonly number[] | undefined;
26
+ } | {
27
+ readonly _tag: "Resync";
28
+ }, never, never>;
29
+ }, never, LiveDispatcher | Reactivity.Reactivity | import("effect/Scope").Scope>;
30
+ //# sourceMappingURL=openLiveHints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openLiveHints.d.ts","sourceRoot":"","sources":["../../src/adapters/openLiveHints.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAS,GAAG,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACpD,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,KAAK,GAAG,EAAY,MAAM,4BAA4B,CAAC;AAGhE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,eAAO,MAAM,aAAa;;;;2BAwBK,SAAS,GAAG,EAAE;;;;;;;;;;;;;;;;;;;;gFA8B3C,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { Effect, Queue, Ref, Stream } from "effect";
2
+ import * as Reactivity from "effect/reactivity/Reactivity";
3
+ import { readKeys } from "@shivaedev/changes/keys.ts";
4
+ import { liveHintQueue } from "#liveHintQueue.ts";
5
+ import { LiveDispatcher } from "./LiveDispatcher.js";
6
+ export const openLiveHints = Effect.fn("LiveServer.openLiveHints")(function* (state, keys) {
7
+ const reactivity = yield* Reactivity.Reactivity;
8
+ const { openStreams, resyncKey } = state;
9
+ const { dispatcher } = yield* LiveDispatcher;
10
+ const { offer, queue } = yield* liveHintQueue;
11
+ const pending = new Map();
12
+ let scheduled = false;
13
+ let resync = false;
14
+ let active = true;
15
+ function flush() {
16
+ if (scheduled) {
17
+ return;
18
+ }
19
+ scheduled = true;
20
+ dispatcher.scheduleTask(() => {
21
+ scheduled = false;
22
+ if (active) {
23
+ offer(resync ? { _tag: "Resync" } : { _tag: "Changed", keys: [...pending.values()] });
24
+ }
25
+ pending.clear();
26
+ resync = false;
27
+ }, 0);
28
+ }
29
+ let cancelKeys = [];
30
+ function replaceKeys(current) {
31
+ for (const stop of cancelKeys) {
32
+ stop();
33
+ }
34
+ cancelKeys = current.map((key) => {
35
+ const own = readKeys([key]);
36
+ return reactivity.registerUnsafe(own, () => {
37
+ pending.set(own[0] ?? "", key);
38
+ flush();
39
+ });
40
+ });
41
+ }
42
+ replaceKeys(keys);
43
+ const cancel = [
44
+ reactivity.registerUnsafe([resyncKey], () => {
45
+ resync = true;
46
+ flush();
47
+ }),
48
+ ];
49
+ yield* Ref.update(openStreams, (count) => count + 1);
50
+ yield* Effect.addFinalizer(() => Effect.sync(() => {
51
+ active = false;
52
+ for (const stop of [...cancelKeys, ...cancel]) {
53
+ stop();
54
+ }
55
+ }).pipe(Effect.andThen(Ref.update(openStreams, (count) => count - 1))));
56
+ yield* Queue.offer(queue, { _tag: "Resync" });
57
+ return { replaceKeys, stream: Stream.fromQueue(queue) };
58
+ });
59
+ //# sourceMappingURL=openLiveHints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openLiveHints.js","sourceRoot":"","sources":["../../src/adapters/openLiveHints.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,4 @@
1
+ import { Effect } from "effect";
2
+ import type { QuerySubscription } from "#querySubscription.ts";
3
+ export declare function refreshSubscription<A, E, R>(subscription: QuerySubscription<E, R>, next: Effect.Effect<A, E, R>): Effect.Effect<A, E, R | Exclude<R, never>>;
4
+ //# sourceMappingURL=refreshSubscription.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refreshSubscription.d.ts","sourceRoot":"","sources":["../../src/adapters/refreshSubscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,YAAY,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,8CAE/G"}
@@ -0,0 +1,5 @@
1
+ import { Effect } from "effect";
2
+ export function refreshSubscription(subscription, next) {
3
+ return Effect.flatMap(subscription.refresh ?? Effect.context(), (current) => Effect.provideContext(next, current));
4
+ }
5
+ //# sourceMappingURL=refreshSubscription.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refreshSubscription.js","sourceRoot":"","sources":["../../src/adapters/refreshSubscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,MAAM,UAAU,mBAAmB,CAAU,YAAqC,EAAE,IAA4B;IAC/G,OAAO,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,EAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;AAC3H,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { Effect, Stream } from "effect";
2
+ import type { Key } from "@shivaedev/changes/keys.ts";
3
+ import type { QueryRerun, QuerySubscription } from "#querySubscription.ts";
4
+ import type { QueryUpdate, SubscriptionHint } from "#queryUpdate.ts";
5
+ import type { QueryReadDenied } from "#readPolicyErrors.ts";
6
+ export declare const standaloneLiveServer: Effect.Effect<{
7
+ resync: Effect.Effect<number, never, never>;
8
+ stream: (keys: readonly Key[]) => Stream.Stream<{
9
+ readonly _tag: "Changed";
10
+ readonly keys: readonly ({
11
+ readonly _tag: "Bucket";
12
+ readonly collection: string;
13
+ readonly field: string;
14
+ readonly value: string | number;
15
+ } | {
16
+ readonly _tag: "List";
17
+ readonly collection: string;
18
+ } | {
19
+ readonly _tag: "Item";
20
+ readonly collection: string;
21
+ readonly id: string | number;
22
+ })[];
23
+ readonly queryIndexes?: readonly number[] | undefined;
24
+ } | {
25
+ readonly _tag: "Resync";
26
+ }, never, never>;
27
+ subscribe: {
28
+ <E, R>(subscription: QuerySubscription<E, R>): Stream.Stream<SubscriptionHint, E | QueryReadDenied, R>;
29
+ <E, R>(subscription: QuerySubscription<E, R>, read: QueryRerun<E, R>): Stream.Stream<QueryUpdate, E | QueryReadDenied, R>;
30
+ };
31
+ }, never, import("effect/reactivity/Reactivity").Reactivity>;
32
+ //# sourceMappingURL=standaloneLiveServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standaloneLiveServer.d.ts","sourceRoot":"","sources":["../../src/adapters/standaloneLiveServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAS,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxD,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,oBAAoB;;mBAQiB,SAAS,GAAG,EAAE;;;;;;;;;;;;;;;;;;;;SAL5C,CAAC,EAAE,CAAC,gBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,CAAC;SACrG,CAAC,EAAE,CAAC,gBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,CAAC;;4DAK1I,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { Context, Effect, Layer, Stream } from "effect";
2
+ import { liveServerLayer } from "#live-server/layer.ts";
3
+ import { LiveServer } from "#live-server/service.ts";
4
+ import { subscribe as subscribeQueries } from "#live-server/subscribe.ts";
5
+ export const standaloneLiveServer = Effect.gen(function* () {
6
+ const context = yield* Effect.scoped(Layer.build(liveServerLayer));
7
+ const server = Context.get(context, LiveServer);
8
+ function subscribe(subscription, read) {
9
+ return Stream.unwrap(Effect.provideContext(subscribeQueries(subscription, read), context));
10
+ }
11
+ return { resync: server.resync(), stream: (keys) => Stream.unwrap(server.stream(keys)), subscribe };
12
+ });
13
+ //# sourceMappingURL=standaloneLiveServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standaloneLiveServer.js","sourceRoot":"","sources":["../../src/adapters/standaloneLiveServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAK1E,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IACvD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;IACnE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAGhD,SAAS,SAAS,CAAO,YAAqC,EAAE,IAAuB;QACtF,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,IAAoB,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC;AACrH,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Effect, Layer } from "effect";
2
+ import type { RpcClient } from "effect/rpc";
3
+ export declare const withClientProtocol: <A, E, R, TMakeError, TMakeRequirements>(protocol: Layer.Layer<RpcClient.Protocol, E, R>, make: Effect.Effect<A, TMakeError, TMakeRequirements>) => Effect.Effect<A, E | TMakeError, R | import("effect/Scope").Scope | Exclude<TMakeRequirements, RpcClient.Protocol>>;
4
+ //# sourceMappingURL=withClientProtocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withClientProtocol.d.ts","sourceRoot":"","sources":["../../src/adapters/withClientProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,eAAO,MAAM,kBAAkB,GAAwD,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,iBAAiB,gOAM3H,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { Effect, Layer } from "effect";
2
+ export const withClientProtocol = Effect.fn("RpcClient.withClientProtocol")(function* (protocol, make) {
3
+ const context = yield* Layer.build(protocol);
4
+ return yield* Effect.provideContext(make, context);
5
+ });
6
+ //# sourceMappingURL=withClientProtocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withClientProtocol.js","sourceRoot":"","sources":["../../src/adapters/withClientProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAGvC,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC,8BAA8B,CAAC,CAAC,QAAQ,CAAC,EACpF,QAA+C,EAC/C,IAAqD;IAErD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7C,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Effect } from "effect";
2
+ import type { Rpc } from "effect/rpc";
3
+ export declare const withPolicyContext: <A, E, R>(rpc: Rpc.Any, effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, unknown>;
4
+ //# sourceMappingURL=withPolicyContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withPolicyContext.d.ts","sourceRoot":"","sources":["../../src/adapters/withPolicyContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAGtC,eAAO,MAAM,iBAAiB,GAAwD,CAAC,EAAE,CAAC,EAAE,CAAC,+EAG3F,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Effect } from "effect";
2
+ import { policyContext } from "#policyContext.ts";
3
+ export const withPolicyContext = Effect.fn("ReadPolicy.withPolicyContext")(function* (rpc, effect) {
4
+ const context = yield* policyContext(rpc);
5
+ return yield* Effect.provideContext(effect, context);
6
+ });
7
+ //# sourceMappingURL=withPolicyContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withPolicyContext.js","sourceRoot":"","sources":["../../src/adapters/withPolicyContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,EAAE,CAAC,8BAA8B,CAAC,CAAC,QAAQ,CAAC,EAAW,GAAY,EAAE,MAA8B;IAC1I,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAC1C,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { Effect, Ref } from "effect";
2
+ export declare const initialize: Effect.Effect<{
3
+ openStreams: Ref.Ref<number>;
4
+ resyncKey: string;
5
+ }, never, never>;
6
+ //# sourceMappingURL=initialize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../src/live-server/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7C,eAAO,MAAM,UAAU;;;gBAIrB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Effect, Random, Ref } from "effect";
2
+ export const initialize = Effect.gen(function* () {
3
+ const openStreams = yield* Ref.make(0);
4
+ const resyncKey = `@shivaedev/contract/resync/${yield* Random.nextInt}`;
5
+ return { openStreams, resyncKey };
6
+ });
7
+ //# sourceMappingURL=initialize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../src/live-server/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7C,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC7C,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACvC,MAAM,SAAS,GAAG,8BAA8B,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IACxE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;AACnC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Layer } from "effect";
2
+ export declare const liveServerLayer: Layer.Layer<"@shivaedev/contract/LiveServer", never, import("effect/reactivity/Reactivity").Reactivity>;
3
+ //# sourceMappingURL=layer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layer.d.ts","sourceRoot":"","sources":["../../src/live-server/layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAI/B,eAAO,MAAM,eAAe,yGAA6D,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Layer } from "effect";
2
+ import { LiveDispatcher } from "#adapters/LiveDispatcher.ts";
3
+ import { LiveServer } from "./service.js";
4
+ export const liveServerLayer = LiveServer.layer.pipe(Layer.provide(LiveDispatcher.layer));
5
+ //# sourceMappingURL=layer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layer.js","sourceRoot":"","sources":["../../src/live-server/layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { Effect } from "effect";
2
+ import type { Key } from "@shivaedev/changes/keys.ts";
3
+ import type { initialize } from "./initialize.ts";
4
+ export declare function register(state: Effect.Success<typeof initialize>): (keys: readonly Key[]) => Effect.Effect<import("effect/Stream").Stream<{
5
+ replaceKeys: (current: readonly Key[]) => void;
6
+ stream: import("effect/Stream").Stream<{
7
+ readonly _tag: "Changed";
8
+ readonly keys: readonly ({
9
+ readonly _tag: "Bucket";
10
+ readonly collection: string;
11
+ readonly field: string;
12
+ readonly value: string | number;
13
+ } | {
14
+ readonly _tag: "List";
15
+ readonly collection: string;
16
+ } | {
17
+ readonly _tag: "Item";
18
+ readonly collection: string;
19
+ readonly id: string | number;
20
+ })[];
21
+ readonly queryIndexes?: readonly number[] | undefined;
22
+ } | {
23
+ readonly _tag: "Resync";
24
+ }, never, never>;
25
+ }, never, never>, never, import("../adapters/LiveDispatcher.ts").LiveDispatcher | import("effect/reactivity/Reactivity").Reactivity>;
26
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/live-server/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAC;AAEtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;qIAIhE"}
@@ -0,0 +1,8 @@
1
+ import { Effect } from "effect";
2
+ import { liveHintStream } from "#adapters/liveHintStream.ts";
3
+ export function register(state) {
4
+ return Effect.fn("LiveServer.register")(function* (keys) {
5
+ return yield* liveHintStream(state, keys);
6
+ });
7
+ }
8
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/live-server/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAG7D,MAAM,UAAU,QAAQ,CAAC,KAAwC;IAChE,OAAO,MAAM,CAAC,EAAE,CAAC,qBAAqB,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAoB;QACtE,OAAO,KAAK,CAAC,CAAC,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -1,4 +1,5 @@
1
- import type { Effect } from "effect";
2
- import type { makeLiveServer } from "#makeLiveServer.ts";
3
- export declare function resync(server: Effect.Success<typeof makeLiveServer>): () => Effect.Effect<number, never, never>;
1
+ import { Effect } from "effect";
2
+ import * as Reactivity from "effect/reactivity/Reactivity";
3
+ import type { initialize } from "./initialize.ts";
4
+ export declare function resync(state: Effect.Success<typeof initialize>): () => Effect.Effect<number, never, Reactivity.Reactivity>;
4
5
  //# sourceMappingURL=resync.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resync.d.ts","sourceRoot":"","sources":["../../src/live-server/resync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,cAAc,CAAC,6CAEnE"}
1
+ {"version":3,"file":"resync.d.ts","sourceRoot":"","sources":["../../src/live-server/resync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAO,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,UAAU,CAAC,6DAM9D"}
@@ -1,4 +1,10 @@
1
- export function resync(server) {
2
- return () => server.resync;
1
+ import { Effect, Ref } from "effect";
2
+ import * as Reactivity from "effect/reactivity/Reactivity";
3
+ export function resync(state) {
4
+ return Effect.fn("LiveServer.resync")(function* () {
5
+ const reactivity = yield* Reactivity.Reactivity;
6
+ yield* Effect.sync(() => reactivity.invalidateUnsafe([state.resyncKey]));
7
+ return yield* Ref.get(state.openStreams);
8
+ });
3
9
  }
4
10
  //# sourceMappingURL=resync.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resync.js","sourceRoot":"","sources":["../../src/live-server/resync.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,MAAM,CAAC,MAA6C;IACnE,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC;AAC5B,CAAC"}
1
+ {"version":3,"file":"resync.js","sourceRoot":"","sources":["../../src/live-server/resync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAG3D,MAAM,UAAU,MAAM,CAAC,KAAwC;IAC9D,OAAO,MAAM,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,QAAQ,CAAC;QAC9C,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;QAChD,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACzE,OAAO,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACJ,CAAC"}