@shivaedev/effect-contract 0.10.0 → 0.12.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 (55) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +33 -10
  3. package/dist/automaticLive.d.ts +9 -7
  4. package/dist/automaticLive.d.ts.map +1 -1
  5. package/dist/automaticLive.js +52 -19
  6. package/dist/automaticLive.js.map +1 -1
  7. package/dist/bind.d.ts +11 -7
  8. package/dist/bind.d.ts.map +1 -1
  9. package/dist/bind.js +9 -36
  10. package/dist/bind.js.map +1 -1
  11. package/dist/contract.d.ts +13 -8
  12. package/dist/contract.d.ts.map +1 -1
  13. package/dist/contract.js +19 -9
  14. package/dist/contract.js.map +1 -1
  15. package/dist/internal/bindingOwner.d.ts +8 -0
  16. package/dist/internal/bindingOwner.d.ts.map +1 -0
  17. package/dist/internal/bindingOwner.js +16 -0
  18. package/dist/internal/bindingOwner.js.map +1 -0
  19. package/dist/internal/clientOperations.d.ts +21 -0
  20. package/dist/internal/clientOperations.d.ts.map +1 -0
  21. package/dist/internal/clientOperations.js +36 -0
  22. package/dist/internal/clientOperations.js.map +1 -0
  23. package/dist/internal/queryReactivity.d.ts +2 -1
  24. package/dist/internal/queryReactivity.d.ts.map +1 -1
  25. package/dist/internal/queryReactivity.js +5 -1
  26. package/dist/internal/queryReactivity.js.map +1 -1
  27. package/dist/keys.d.ts +5 -2
  28. package/dist/keys.d.ts.map +1 -1
  29. package/dist/keys.js +7 -4
  30. package/dist/keys.js.map +1 -1
  31. package/dist/live.d.ts +4 -2
  32. package/dist/live.d.ts.map +1 -1
  33. package/dist/live.js +5 -4
  34. package/dist/live.js.map +1 -1
  35. package/dist/makeLiveServer.d.ts +2 -2
  36. package/dist/makeLiveServer.d.ts.map +1 -1
  37. package/dist/makeLiveServer.js +3 -3
  38. package/dist/makeLiveServer.js.map +1 -1
  39. package/dist/operation.d.ts +1 -1
  40. package/dist/serverMetadata.d.ts +21 -12
  41. package/dist/serverMetadata.d.ts.map +1 -1
  42. package/dist/serverMetadata.js +19 -4
  43. package/dist/serverMetadata.js.map +1 -1
  44. package/package.json +12 -12
  45. package/src/automaticLive.ts +64 -24
  46. package/src/bind.ts +21 -54
  47. package/src/contract.ts +43 -17
  48. package/src/internal/bindingOwner.ts +24 -0
  49. package/src/internal/clientOperations.ts +74 -0
  50. package/src/internal/queryReactivity.ts +11 -1
  51. package/src/keys.ts +16 -4
  52. package/src/live.ts +8 -5
  53. package/src/makeLiveServer.ts +4 -4
  54. package/src/operation.ts +1 -1
  55. package/src/serverMetadata.ts +40 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.12.0 - 2026-10-25
4
+
5
+ ### Added
6
+
7
+ - effect-contract item reads refresh on their collection-wide `<collection>:*` key, with live hints naming each affected subscribed item.
8
+
9
+ ### Breaking
10
+
11
+ - effect-sql writes returning more than 1,000 rows across all chunks of a single call announce `<table>` and `<table>:*` instead of item keys. Code registering raw `<table>:<id>` Reactivity keys outside effect-contract must also register `<table>:*`.
12
+
13
+ ## 0.11.1 - 2026-10-25
14
+
15
+ ### Changed
16
+
17
+ - Release with updated workspace dependencies.
18
+
19
+ ## 0.11.0 - 2026-10-24
20
+
21
+ ### Added
22
+
23
+ - Contracts expose `application`, a native RPC group for building application handlers without naming the reserved `$changes` stream. Middleware stays attached, and Platform hosts complete the full contract with the stream handler.
24
+ - Generated applications build their handlers through the contract's `application` group.
25
+
26
+ ### Changed
27
+
28
+ - Require Effect and its companion packages at exactly 4.0.5. Generated applications use the same versions.
29
+
3
30
  ## 0.10.0 - 2026-10-19
4
31
 
5
32
  ### Added
package/README.md CHANGED
@@ -132,7 +132,7 @@ export const NotesHandlers = Notes.toLayer(Effect.gen(function* () {
132
132
  }));
133
133
  ```
134
134
 
135
- 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.omit("notes.$changes")` and keep `Notes` as the host and client group.
135
+ 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.
136
136
 
137
137
  Native `.middleware(M)` returns a contract that retains its declarations. For example, a native middleware service can supply request identity:
138
138
 
@@ -231,6 +231,30 @@ The dependency rule is deliberately asymmetric:
231
231
 
232
232
  Client invalidation follows RPC success. Platform database hosts also publish declared command invalidations automatically after the handler succeeds, excluding keys already announced by repository commits, using `transact` from [`effect-sql`](https://github.com/ShivaeDev/platform/tree/main/packages/effect-sql); commit-bound changes belong to [`effect-changes`](https://github.com/ShivaeDev/platform/tree/main/packages/effect-changes).
233
233
 
234
+ ### Session-owned keys
235
+
236
+ Self-only features can declare `keyScope: "session"` without adding an owner id to query or command payloads:
237
+
238
+ ```ts
239
+ const Preferences = contract("preferences", {
240
+ keyScope: "session",
241
+ queries: [query("self", { reads: () => [preferences.item(0)], success: Schema.String })],
242
+ commands: [command("save", {
243
+ payload: { title: Schema.String },
244
+ invalidates: () => [preferences.item(0)],
245
+ })],
246
+ });
247
+ const api = bind(Preferences, Client, { registry });
248
+ const self = api.self.query(undefined);
249
+ const saved = api.save.run({ title: "My preferences" });
250
+ ```
251
+
252
+ The binding requires the session's owning registry. It scopes read registration, successful-command invalidation, live hints and reconciliation to that owner. A rejected command declares no invalidation. Query atoms and live connections belong in that registry; command and one-off query effects execute through it. Ordinary contracts keep unscoped keys and the two-argument `bind` call.
253
+
254
+ `List` and `Item` are still the key shapes. `readKeys(keys, { scope })` and `invalidationKeys(keys, { scope })` resolve the extra dimension while preserving item, list and wildcard semantics. An item invalidation refreshes that scope's item and list; a wildcard reaches only that scope's items. The client's opaque scope comes from its registry and is never sent as an owner id.
255
+
256
+ Server adapters read the RPC's `KeyScope` annotation. For `"session"`, they must obtain scope from request-local authenticated identity, then pass the same `{ scope }` to dependency registration, invalidation and `makeLiveServer.stream(keys, context)`. A shared server Layer must not capture identity, accept a client-selected scope or fall back to unscoped keys. This package supplies metadata and contextual keys; it has no server or authentication dependency.
257
+
234
258
  ### 4. Live invalidation and resume
235
259
 
236
260
  Platform database hosts serve the contract's reserved `<contract>.$changes` stream automatically. With NDJSON transport, `bind` and a React `SessionBoundary` connect query atoms without an application subscribe operation or `live()` call. The boundary finds bound APIs returned directly by `connect` or as properties such as `client.api`. See [automatic changes](https://github.com/ShivaeDev/platform/blob/main/docs/framework/changes.md) for defaults.
@@ -240,14 +264,13 @@ For a direct subscription, configure the server and `NotesClient` with `RpcSeria
240
264
  ```ts
241
265
  import { Effect, Stream } from "effect";
242
266
  import { NotesClient } from "./client.ts";
243
- import { notes } from "./notes.ts";
244
267
 
245
268
  const changes = Stream.unwrap(NotesClient.use((client) =>
246
- Effect.succeed(client("notes.$changes", { keys: [notes.item(1)] })),
269
+ Effect.succeed(client("notes.$changes", { queries: [{ query: "get", payload: { id: 1 } }] })),
247
270
  ));
248
271
  ```
249
272
 
250
- 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.
273
+ 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 }`. Subscription handlers resolve keys with `queryKeys(Notes.declaration.queries, queries)` from `serverMetadata.ts`, or the stream RPC's `ChangesReads` annotation, before calling `makeLiveServer.stream`. 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.
251
274
 
252
275
  For a custom transport or explicit pause/status controls, the native live APIs remain available:
253
276
 
@@ -372,14 +395,14 @@ Import the module that defines the name; the package has no root entry.
372
395
  | Module | Functions and schemas |
373
396
  | --- | --- |
374
397
  | `operation.ts` | `query(name, { payload?, success?, rejections?, reads })`; `command(name, { payload?, success?, rejections?, invalidates })`; `stream(name, { payload?, success, rejections?, reads })`. |
375
- | `contract.ts` | `contract(name, { queries?, commands?, streams? })`, returning a native RPC group with `declaration: { name, queries, commands, streams }`. |
398
+ | `contract.ts` | `contract(name, { queries?, commands?, streams?, keyScope? })`, returning a native RPC group with `declaration: { name, queries, commands, streams, keyScope }`. |
376
399
  | `rejection.ts` | `fieldRejection(struct, fields?)`; lower-level `rejectionSet(specs)`, which constructs the rejection classes, union schema and failure helpers used by operations. |
377
- | `keys.ts` | `collection(name, idSchema)`; `Key` schema; `readKeys(keys)` and `invalidationKeys(keys)`. |
378
- | `bind.ts` | `bind(contract, atomRpcService)`, exposing `{ query, run }` for queries, `{ run }` Effects for commands and `{ run }` native Streams for streams. |
379
- | `live.ts` | `LiveHint` schema; `live(runtime, { stream, resyncKeys, coalesceWindow?, resume?, retryDelay? })`, exposing `connection`, `coalesceWindow`, `paused` and `status`. |
400
+ | `keys.ts` | `collection(name, idSchema)`; `Key` schema; `readKeys(keys, context?)` and `invalidationKeys(keys, context?)`. |
401
+ | `bind.ts` | `bind(contract, atomRpcService, { registry }?)`, requiring the registry for session-scoped contracts and exposing `{ query, run }` for queries, `{ run }` Effects for commands and `{ run }` native Streams for streams. |
402
+ | `live.ts` | `LiveHint` schema; `live(runtime, { stream, resyncKeys, coalesceWindow?, keyContext?, resume?, retryDelay? })`, exposing `connection`, `coalesceWindow`, `paused` and `status`. |
380
403
  | `makeLiveServer.ts` | `makeLiveServer`, an Effect requiring `Reactivity` that creates scoped server hint streams and a `resync` Effect. |
381
404
  | `readPolicy.ts` | `authorizeReads(effect, request, policy, denied)`; `ReadPolicy`, the request-local fallible key policy used by server hint streams; `ReadPolicyMemoWindow`, a `Context.Reference<Duration.Input>` controlling each stream's memo duration. |
382
- | `serverMetadata.ts` | `QueryReads`, `CommandInvalidation` and `changesRpc(name)` for server adapters. |
405
+ | `serverMetadata.ts` | `KeyScope`, `QueryReads`, `CommandInvalidation`, `ChangesReads`, `queryKeys(queries, references)` and `changesRpc(name, queries)` for server adapters. |
383
406
  | `resume.ts` | `resumeSignal({ window?, native? })`, returning a native numeric signal atom. |
384
407
 
385
408
  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.
@@ -387,7 +410,7 @@ A query atom takes native query options as its optional second argument, for exa
387
410
  ### Install, setup and limits
388
411
 
389
412
  ```sh
390
- pnpm add @shivaedev/effect-contract effect@4.0.4
413
+ pnpm add @shivaedev/effect-contract effect@4.0.5
391
414
  ```
392
415
 
393
416
  `effect` is a peer, and the package needs Node.js 24 or newer. Choose the native server host separately; this package supplies no server process or HTTP transport implementation.
@@ -1,9 +1,11 @@
1
1
  import { type Duration } from "effect";
2
- import type * as Atom from "effect/reactivity/Atom";
2
+ import * as Atom from "effect/reactivity/Atom";
3
+ import * as AtomRegistry from "effect/reactivity/AtomRegistry";
3
4
  import type * as AtomRpc from "effect/reactivity/AtomRpc";
4
- import { type Key } from "./keys.ts";
5
- import { type LiveStatus } from "./live.ts";
6
- import type { changesRpc } from "./serverMetadata.ts";
5
+ import type { BindingOwner } from "#internal/bindingOwner.ts";
6
+ import { type Key } from "#keys.ts";
7
+ import { type LiveStatus } from "#live.ts";
8
+ import type { changesRpc, QueryReference } from "#serverMetadata.ts";
7
9
  export declare const LiveConnection: unique symbol;
8
10
  export interface LiveBound {
9
11
  readonly [LiveConnection]: {
@@ -13,13 +15,13 @@ export interface LiveBound {
13
15
  };
14
16
  }
15
17
  export type ChangesClient = AtomRpc.AtomRpcClient<unknown, string, ReturnType<typeof changesRpc>>;
16
- export declare function automaticLive(service: ChangesClient, name: string): {
18
+ export declare function automaticLive(service: ChangesClient, name: string, owner?: BindingOwner): {
17
19
  subscription: {
18
20
  coalesceWindow: Atom.Writable<Duration.Input, Duration.Input>;
19
- connection: Atom.Atom<import("effect/reactivity/AsyncResult").AsyncResult<void, never>>;
20
21
  paused: Atom.Writable<boolean, boolean>;
21
22
  status: Atom.Writable<LiveStatus<import("effect/rpc/RpcClientError").RpcClientError>, LiveStatus<import("effect/rpc/RpcClientError").RpcClientError>>;
23
+ connection: Atom.Atom<import("effect/reactivity/AsyncResult").AsyncResult<void, never>>;
22
24
  };
23
- track: (reads: readonly Key[]) => void;
25
+ track: (registry: AtomRegistry.AtomRegistry | undefined, reference: QueryReference, keys: readonly Key[]) => () => void;
24
26
  };
25
27
  //# sourceMappingURL=automaticLive.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"automaticLive.d.ts","sourceRoot":"","sources":["../src/automaticLive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAmC,MAAM,QAAQ,CAAC;AACxE,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,KAAK,OAAO,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,KAAK,GAAG,EAAY,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,KAAK,UAAU,EAAQ,MAAM,WAAW,CAAC;AAElD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAItD,eAAO,MAAM,cAAc,eAA0D,CAAC;AACtF,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,CAAC,cAAc,CAAC,EAAE;QAC1B,QAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACvD,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;KAChD,CAAC;CACF;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,OAAO,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E,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,YAAY;;;;;;;sBAI9D,YAAY,CAAC,YAAY,GAAG,SAAS,aAAa,cAAc,QAAQ,SAAS,GAAG,EAAE;EAuD/G"}
@@ -1,29 +1,62 @@
1
1
  import { Effect, Stream, SubscriptionRef } from "effect";
2
- import { readKeys } from "./keys.js";
3
- import { live } from "./live.js";
4
- import { resumeSignal } from "./resume.js";
2
+ import * as Atom from "effect/reactivity/Atom";
3
+ import * as AtomRegistry from "effect/reactivity/AtomRegistry";
4
+ import { readKeys } from "#keys.ts";
5
+ import { live } from "#live.ts";
6
+ import { resumeSignal } from "#resume.ts";
5
7
  export const LiveConnection = Symbol.for("@shivaedev/effect-contract/LiveConnection");
6
- export function automaticLive(service, name) {
7
- const keys = Effect.runSync(SubscriptionRef.make([]));
8
+ export function automaticLive(service, name, owner) {
9
+ const eager = owner === undefined ? Effect.runSync(SubscriptionRef.make(new Map())) : undefined;
8
10
  const known = new Set();
9
- function track(reads) {
10
- const fresh = reads.filter((key) => {
11
- const id = readKeys([key])[0] ?? "";
12
- if (known.has(id)) {
13
- return false;
14
- }
15
- known.add(id);
16
- return true;
17
- });
18
- if (fresh.length > 0) {
19
- Effect.runSync(SubscriptionRef.update(keys, (current) => [...current, ...fresh]));
11
+ const tracked = Atom.keepAlive(Atom.make(() => eager ?? Effect.runSync(SubscriptionRef.make(new Map()))));
12
+ function track(registry, reference, keys) {
13
+ const fresh = eager === undefined
14
+ ? keys
15
+ : keys.filter((key) => {
16
+ const id = readKeys([key])[0] ?? "";
17
+ if (known.has(id)) {
18
+ return false;
19
+ }
20
+ known.add(id);
21
+ return true;
22
+ });
23
+ if (fresh.length === 0) {
24
+ return () => undefined;
20
25
  }
26
+ const token = {};
27
+ const state = eager ?? registry?.get(tracked);
28
+ if (state === undefined) {
29
+ throw new Error("Session query tracking requires its owning registry");
30
+ }
31
+ Effect.runSync(SubscriptionRef.update(state, (current) => new Map([...current, [token, { keys: fresh, reference }]])));
32
+ if (eager !== undefined) {
33
+ return () => undefined;
34
+ }
35
+ return () => Effect.runSync(SubscriptionRef.update(state, (current) => {
36
+ const next = new Map(current);
37
+ next.delete(token);
38
+ return next;
39
+ }));
40
+ }
41
+ function subscribe(current) {
42
+ if (current.size === 0) {
43
+ return Stream.never;
44
+ }
45
+ const queries = [...current.values()].map(({ reference }) => reference);
46
+ return Stream.unwrap(service.use((client) => Effect.succeed(client(`${name}.$changes`, { queries }))));
21
47
  }
22
48
  const subscription = live(service.runtime, {
49
+ keyContext: owner?.context,
23
50
  resume: resumeSignal(typeof window === "undefined" ? {} : { window }),
24
- resyncKeys: () => Effect.runSync(SubscriptionRef.get(keys)),
25
- stream: SubscriptionRef.changes(keys).pipe(Stream.switchMap((current) => current.length === 0 ? Stream.never : Stream.unwrap(service.use((client) => Effect.succeed(client(`${name}.$changes`, { keys: current })))))),
51
+ resyncKeys: (registry) => [...Effect.runSync(SubscriptionRef.get(registry.get(tracked))).values()].flatMap(({ keys }) => keys),
52
+ stream: Stream.unwrap(Effect.map(AtomRegistry.AtomRegistry, (registry) => SubscriptionRef.changes(registry.get(tracked)).pipe(Stream.switchMap(subscribe)))),
26
53
  });
27
- return { subscription, track };
54
+ const connection = Atom.make((get) => {
55
+ if (owner !== undefined && owner.registry !== get.registry) {
56
+ throw new Error("A session-scoped live connection belongs to its binding registry");
57
+ }
58
+ return get(subscription.connection);
59
+ }).pipe(Atom.setIdleTTL(0));
60
+ return { subscription: { ...subscription, connection }, track };
28
61
  }
29
62
  //# sourceMappingURL=automaticLive.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"automaticLive.js","sourceRoot":"","sources":["../src/automaticLive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAGxE,OAAO,EAAY,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAmB,IAAI,EAAE,MAAM,WAAW,CAAC;AAClD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,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC;QAC9H,MAAM,EAAE,MAAM,CAAC,MAAM,CACpB,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CACrI;KACD,CAAC,CAAC;IACH,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;QACpC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,KAAK,GAAG,CAAC,QAAQ,EAAE,CAAC;YAC5D,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;QACrF,CAAC;QACD,OAAO,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,OAAO,EAAE,YAAY,EAAE,EAAE,GAAG,YAAY,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC;AACjE,CAAC"}
package/dist/bind.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- import type { Duration } from "effect";
2
- import { Effect, Stream } from "effect";
1
+ import type { Duration, Effect, Stream } from "effect";
3
2
  import type { Headers } from "effect/http";
4
3
  import type * as AsyncResult from "effect/reactivity/AsyncResult";
5
4
  import type * as Atom from "effect/reactivity/Atom";
5
+ import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
6
6
  import type * as AtomRpc from "effect/reactivity/AtomRpc";
7
- import * as Reactivity from "effect/reactivity/Reactivity";
7
+ import type * as Reactivity from "effect/reactivity/Reactivity";
8
8
  import type { Rpc } from "effect/rpc";
9
9
  import type { RpcClientError } from "effect/rpc/RpcClientError";
10
- import { type LiveBound } from "./automaticLive.ts";
11
- import type { Contract, Tag } from "./contract.ts";
12
- import type { CommandShape, QueryShape, StreamShape } from "./operation.ts";
10
+ import { type LiveBound } from "#automaticLive.ts";
11
+ import type { Contract, Tag } from "#contract.ts";
12
+ import type { CommandShape, QueryShape, StreamShape } from "#operation.ts";
13
13
  export type Failure<R extends Rpc.Any> = R extends Rpc.Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer TMiddleware, infer _Requires> ? Rpc.ErrorExit<R> | TMiddleware["error"]["Type"] | RpcClientError : never;
14
14
  export type RunFailure<R extends Rpc.Any> = R extends Rpc.Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer TMiddleware, infer _Requires> ? Failure<R> | TMiddleware["~ClientError"] : never;
15
15
  export interface QueryOptions {
@@ -39,6 +39,10 @@ type MatchingClient<TRpcs extends Rpc.Any, TClientRpcs extends Rpc.Any> = [TRpcs
39
39
  }>] ? [Extract<TClientRpcs, {
40
40
  readonly _tag: TRpcs["_tag"];
41
41
  }>] extends [TRpcs] ? unknown : "Client must preserve the contract RPC types" : "Client must implement the contract RPCs";
42
- export declare function bind<TName extends string, TQueries extends readonly QueryShape[], TCommands extends readonly CommandShape[], TRpcs extends Rpc.Any, TSelf, TId extends string, TClientRpcs extends Rpc.Any, TStreams extends readonly StreamShape[]>(contract: Contract<TName, TQueries, TCommands, TRpcs, TStreams>, service: AtomRpc.AtomRpcClient<TSelf, TId, TClientRpcs> & MatchingClient<NoInfer<TRpcs>, TClientRpcs>): Bound<TName, TQueries, TCommands, TRpcs, TSelf, TStreams> & LiveBound;
42
+ export declare function bind<TName extends string, TQueries extends readonly QueryShape[], TCommands extends readonly CommandShape[], TRpcs extends Rpc.Any, TSelf, TId extends string, TClientRpcs extends Rpc.Any, TStreams extends readonly StreamShape[], TScope extends "session" | undefined>(contract: Contract<TName, TQueries, TCommands, TRpcs, TStreams, TScope>, service: AtomRpc.AtomRpcClient<TSelf, TId, TClientRpcs> & MatchingClient<NoInfer<TRpcs>, TClientRpcs>, ...options: "session" extends TScope ? [options: {
43
+ readonly registry: AtomRegistry.AtomRegistry;
44
+ }] : [options?: {
45
+ readonly registry: AtomRegistry.AtomRegistry;
46
+ }]): Bound<TName, TQueries, TCommands, TRpcs, TSelf, TStreams> & LiveBound;
43
47
  export {};
44
48
  //# sourceMappingURL=bind.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../src/bind.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAU,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,KAAK,OAAO,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,EAAE,GAAG,EAAa,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAiB,KAAK,SAAS,EAAkB,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,QAAQ,EAAY,GAAG,EAAE,MAAM,eAAe,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE5E,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,GAAG,CAAC,GAAG,IACpC,CAAC,SAAS,GAAG,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,MAAM,QAAQ,EAAE,MAAM,QAAQ,E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CAAC,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,YAAY,CAAA;CAAE,CAAC,GAC7D,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC"}
package/dist/bind.js CHANGED
@@ -1,40 +1,13 @@
1
- import { Effect, Stream } from "effect";
2
- import * as Reactivity from "effect/reactivity/Reactivity";
3
- import { queryReactivity } from "#internal/queryReactivity.ts";
4
- import { automaticLive, LiveConnection } from "./automaticLive.js";
5
- import { invalidationKeys, readKeys } from "./keys.js";
6
- const invalidateAfter = Effect.fn("EffectContract.invalidateAfter")(function* (keys) {
7
- yield* Reactivity.invalidate(invalidationKeys(keys));
8
- });
9
- function boundQuery(service, tag, query, track) {
10
- const reactive = queryReactivity(service.runtime);
11
- function reads(payload) {
12
- return readKeys(query.reads(payload));
13
- }
14
- return {
15
- query: (payload, options = {}) => {
16
- track(query.reads(payload));
17
- return reactive(service.query(tag, payload, options), reads(payload));
18
- },
19
- run: (payload) => service.use((client) => client(tag, payload)),
20
- };
21
- }
22
- function boundCommand(service, tag, command) {
23
- return {
24
- run: (payload) => service.use((client) => client(tag, payload)).pipe(Effect.tap((result) => invalidateAfter(command.invalidates(payload, result)))),
25
- };
26
- }
27
- function boundStream(service, tag) {
28
- return {
29
- run: (payload) => Stream.unwrap(service.use((client) => Effect.succeed(client(tag, payload)))),
30
- };
31
- }
32
- export function bind(contract, service) {
33
- const { name, queries, commands, streams } = contract.declaration;
34
- const automatic = automaticLive(service, name);
1
+ import { automaticLive, LiveConnection } from "#automaticLive.ts";
2
+ import { bindingOwner } from "#internal/bindingOwner.ts";
3
+ import { boundCommand, boundQuery, boundStream } from "#internal/clientOperations.ts";
4
+ export function bind(contract, service, options) {
5
+ const { name, queries, commands, streams, keyScope } = contract.declaration;
6
+ const owner = bindingOwner(keyScope, options?.registry);
7
+ const automatic = automaticLive(service, name, owner);
35
8
  return Object.assign(Object.fromEntries([
36
- ...queries.map((query) => [query.name, boundQuery(service, `${name}.${query.name}`, query, automatic.track)]),
37
- ...commands.map((command) => [command.name, boundCommand(service, `${name}.${command.name}`, command)]),
9
+ ...queries.map((query) => [query.name, boundQuery(service, `${name}.${query.name}`, query, automatic.track, owner)]),
10
+ ...commands.map((command) => [command.name, boundCommand(service, `${name}.${command.name}`, command, owner)]),
38
11
  ...streams.map((stream) => [stream.name, boundStream(service, `${name}.${stream.name}`)]),
39
12
  ]), { [LiveConnection]: automatic.subscription });
40
13
  }
package/dist/bind.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bind.js","sourceRoot":"","sources":["../src/bind.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKxC,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAG3D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAkB,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEnF,OAAO,EAAE,gBAAgB,EAAY,QAAQ,EAAE,MAAM,WAAW,CAAC;AA6DjE,MAAM,eAAe,GAAG,MAAM,CAAC,EAAE,CAAC,gCAAgC,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAoB;IAClG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;AACtD,CAAC,CAAC,CAAC;AAEH,SAAS,UAAU,CAAC,OAAqB,EAAE,GAAW,EAAE,KAAiB,EAAE,KAAqC;IAC/G,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAClD,SAAS,KAAK,CAAC,OAAgB;QAC9B,OAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IACvC,CAAC;IACD,OAAO;QACN,KAAK,EAAE,CAAC,O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Q,CAAC,WAAW,CAAC;IAC5E,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IACtD,OAAO,MAAM,CAAC,MAAM,CACnB,MAAM,CAAC,WAAW,CAAC;QAClB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAU,CAAC;QAC7H,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,CAAU,CAAC;QACvH,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAU,CAAC;KAClG,CAAC,EACF,EAAE,CAAC,cAAc,CAAC,EAAE,SAAS,CAAC,YAAY,EAAE,CAC5C,CAAC;AACH,CAAC"}
@@ -1,28 +1,33 @@
1
1
  import { type Schema } from "effect";
2
2
  import { Rpc, RpcGroup, type RpcMiddleware, type RpcSchema } from "effect/rpc";
3
- import type { CommandShape, OperationShape, QueryShape, StreamShape } from "./operation.ts";
4
- import { changesRpc } from "./serverMetadata.ts";
3
+ import type { CommandShape, OperationShape, QueryShape, StreamShape } from "#operation.ts";
4
+ import { changesRpc } from "#serverMetadata.ts";
5
5
  export type Tag<TContract extends string, TName extends string> = `${TContract}.${TName}`;
6
6
  export type OperationRpc<TContract extends string, TOperation> = TOperation extends OperationShape ? TOperation extends StreamShape ? Rpc.Rpc<Tag<TContract, TOperation["name"]>, TOperation["payload"], RpcSchema.Stream<TOperation["success"], TOperation["error"]>, Schema.Never> : Rpc.Rpc<Tag<TContract, TOperation["name"]>, TOperation["payload"], TOperation["success"], TOperation["error"]> : never;
7
- export interface Declared<TName extends string, TQueries extends readonly QueryShape[], TCommands extends readonly CommandShape[], TStreams extends readonly StreamShape[] = readonly []> {
7
+ export interface Declared<TName extends string, TQueries extends readonly QueryShape[], TCommands extends readonly CommandShape[], TStreams extends readonly StreamShape[] = readonly [], TScope extends "session" | undefined = undefined> {
8
8
  readonly commands: TCommands;
9
+ readonly keyScope: TScope;
9
10
  readonly name: TName;
10
11
  readonly queries: TQueries;
11
12
  readonly streams: TStreams;
12
13
  }
13
- export interface Contract<TName extends string, TQueries extends readonly QueryShape[], TCommands extends readonly CommandShape[], TRpcs extends Rpc.Any = OperationRpc<TName, TQueries[number] | TCommands[number]> | ReturnType<typeof changesRpc<TName>>, TStreams extends readonly StreamShape[] = readonly []> extends RpcGroup.RpcGroup<TRpcs> {
14
- readonly declaration: Declared<TName, TQueries, TCommands, TStreams>;
15
- middleware: <TM extends RpcMiddleware.AnyService>(middleware: TM) => Contract<TName, TQueries, TCommands, Rpc.AddMiddleware<TRpcs, TM>, TStreams>;
14
+ export interface Contract<TName extends string, TQueries extends readonly QueryShape[], TCommands extends readonly CommandShape[], TRpcs extends Rpc.Any = OperationRpc<TName, TQueries[number] | TCommands[number]> | ReturnType<typeof changesRpc<TName, TQueries>>, TStreams extends readonly StreamShape[] = readonly [], TScope extends "session" | undefined = undefined> extends RpcGroup.RpcGroup<TRpcs> {
15
+ readonly application: RpcGroup.RpcGroup<Exclude<TRpcs, {
16
+ readonly _tag: `${TName}.$changes`;
17
+ }>>;
18
+ readonly declaration: Declared<TName, TQueries, TCommands, TStreams, TScope>;
19
+ middleware: <TM extends RpcMiddleware.AnyService>(middleware: TM) => Contract<TName, TQueries, TCommands, Rpc.AddMiddleware<TRpcs, TM>, TStreams, TScope>;
16
20
  }
17
21
  type Duplicated<TOperations extends readonly OperationShape[], TSeen extends string = never> = TOperations extends readonly [
18
22
  infer THead extends OperationShape,
19
23
  ...infer TTail extends readonly OperationShape[]
20
24
  ] ? (THead["name"] extends TSeen ? THead["name"] : never) | Duplicated<TTail, TSeen | THead["name"]> : never;
21
25
  type Unique<TOperations extends readonly OperationShape[]> = [Duplicated<TOperations>] extends [never] ? unknown : `Operation names must be unique; duplicated: ${Duplicated<TOperations>}`;
22
- export declare function contract<const TName extends string, const TQueries extends readonly QueryShape[] = readonly [], const TCommands extends readonly CommandShape[] = readonly [], const TStreams extends readonly StreamShape[] = readonly []>(name: TName, operations: {
26
+ export declare function contract<const TName extends string, const TQueries extends readonly QueryShape[] = readonly [], const TCommands extends readonly CommandShape[] = readonly [], const TStreams extends readonly StreamShape[] = readonly [], const TScope extends "session" | undefined = undefined>(name: TName, operations: {
27
+ readonly keyScope?: TScope;
23
28
  readonly queries?: TQueries & Unique<TQueries>;
24
29
  readonly commands?: TCommands & Unique<[...TQueries, ...TCommands]>;
25
30
  readonly streams?: TStreams & Unique<[...TQueries, ...TCommands, ...TStreams]>;
26
- }): Contract<TName, TQueries, TCommands, OperationRpc<TName, TQueries[number] | TCommands[number] | TStreams[number]> | ReturnType<typeof changesRpc<TName>>, TStreams>;
31
+ }): Contract<TName, TQueries, TCommands, OperationRpc<TName, TQueries[number] | TCommands[number] | TStreams[number]> | ReturnType<typeof changesRpc<TName, TQueries>>, TStreams, TScope>;
27
32
  export {};
28
33
  //# sourceMappingURL=contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,QAAQ,E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CAAC,OAAO,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,EAC7H,QAAQ,EACR,MAAM,CACN,CAAC"}
package/dist/contract.js CHANGED
@@ -1,34 +1,44 @@
1
1
  import { Context } from "effect";
2
2
  import { Rpc, RpcGroup } from "effect/rpc";
3
- import { CommandInvalidation, changesRpc, QueryReads } from "./serverMetadata.js";
3
+ import { CommandInvalidation, changesRpc, KeyScope, QueryReads } from "#serverMetadata.ts";
4
4
  function assertUnique(operations) {
5
5
  const duplicated = operations.map(({ name }) => name).filter((name, index, names) => names.indexOf(name) !== index);
6
6
  if (duplicated.length > 0) {
7
7
  throw new Error(`Operation names must be unique; duplicated: ${[...new Set(duplicated)].join(", ")}`);
8
8
  }
9
9
  }
10
- function annotations(operation) {
10
+ function annotations(operation, keyScope) {
11
+ const scope = keyScope === undefined ? Context.empty() : Context.make(KeyScope, keyScope);
11
12
  if (operation.kind === "command") {
12
- return Context.make(CommandInvalidation, operation.invalidates);
13
+ return Context.add(scope, CommandInvalidation, operation.invalidates);
13
14
  }
14
- return operation.kind === "query" ? Context.make(QueryReads, operation.reads) : Context.empty();
15
+ return operation.kind === "query" ? Context.add(scope, QueryReads, operation.reads) : scope;
15
16
  }
16
- function withDeclaration(group, declaration) {
17
+ function withDeclaration(group, application, declaration) {
17
18
  const nativeMiddleware = group.middleware.bind(group);
18
19
  return Object.assign(group, {
20
+ application,
19
21
  declaration,
20
- middleware: (middleware) => withDeclaration(nativeMiddleware(middleware), declaration),
22
+ middleware: (middleware) => withDeclaration(nativeMiddleware(middleware), application.middleware(middleware), declaration),
21
23
  });
22
24
  }
23
25
  export function contract(name, operations) {
24
- const { queries = [], commands = [], streams = [] } = operations;
26
+ const { queries = [], commands = [], streams = [], keyScope } = operations;
25
27
  assertUnique([...queries, ...commands, ...streams]);
26
28
  const rpcs = [...queries, ...commands, ...streams].map((operation) => Rpc.make(`${name}.${operation.name}`, {
27
29
  error: operation.error,
28
30
  payload: operation.payload,
29
31
  stream: operation.kind === "stream",
30
32
  success: operation.success,
31
- }).annotateMerge(annotations(operation)));
32
- return withDeclaration(RpcGroup.make(...rpcs, changesRpc(name)), { commands, name, queries, streams });
33
+ }).annotateMerge(annotations(operation, keyScope)));
34
+ const application = RpcGroup.make(...rpcs);
35
+ const changes = changesRpc(name, queries);
36
+ return withDeclaration(application.add(keyScope === undefined ? changes : changes.annotate(KeyScope, keyScope)), application, {
37
+ commands,
38
+ keyScope,
39
+ name,
40
+ queries,
41
+ streams,
42
+ });
33
43
  }
34
44
  //# sourceMappingURL=contract.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAsC,MAAM,YAAY,CAAC;AAE/E,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AA4ClF,SAAS,YAAY,CAAC,UAAqC;IAC1D,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC;IACpH,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvG,CAAC;AACF,CAAC;AAED,SAAS,WAAW,CAAC,SAAkD;IACtE,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO,OAAO,CAAC,IAAI,CAAC,mBAAmB,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QACnC,OAAO,EAAE,SAAS,CAAC,OAAO;KAC1B,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAClD,CAAC;IACF,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC1C,OAAO,eAAe,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,EAAE,WAAW,EAAE;QAC7H,QAAQ;QACR,QAAQ;QACR,IAAI;QACJ,OAAO;QACP,OAAO;KACP,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
2
+ import type { KeyContext } from "#keys.ts";
3
+ export interface BindingOwner {
4
+ readonly context: KeyContext;
5
+ readonly registry: AtomRegistry.AtomRegistry;
6
+ }
7
+ export declare function bindingOwner(scope: "session" | undefined, registry?: AtomRegistry.AtomRegistry): BindingOwner | undefined;
8
+ //# sourceMappingURL=bindingOwner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindingOwner.d.ts","sourceRoot":"","sources":["../../src/internal/bindingOwner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,YAAY,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,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"}
@@ -0,0 +1,16 @@
1
+ const contexts = new WeakMap();
2
+ export function bindingOwner(scope, registry) {
3
+ if (scope === undefined) {
4
+ return undefined;
5
+ }
6
+ if (registry === undefined) {
7
+ throw new Error("A session-scoped contract requires its owning registry");
8
+ }
9
+ let context = contexts.get(registry);
10
+ if (context === undefined) {
11
+ context = { scope: crypto.randomUUID() };
12
+ contexts.set(registry, context);
13
+ }
14
+ return { context, registry };
15
+ }
16
+ //# sourceMappingURL=bindingOwner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindingOwner.js","sourceRoot":"","sources":["../../src/internal/bindingOwner.ts"],"names":[],"mappings":"AAQA,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAyC,CAAC;AAEtE,MAAM,UAAU,YAAY,CAAC,KAA4B,EAAE,QAAoC;IAC9F,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC3E,CAAC;IACD,IAAI,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACrC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC;QACzC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { Effect, type Schema, Stream } from "effect";
2
+ import type * as AtomRpc from "effect/reactivity/AtomRpc";
3
+ import type { Rpc, RpcSchema } from "effect/rpc";
4
+ import type { automaticLive } from "#automaticLive.ts";
5
+ import type { QueryOptions } from "#bind.ts";
6
+ import type { CommandShape, QueryShape } from "#operation.ts";
7
+ import type { BindingOwner } from "./bindingOwner.ts";
8
+ type ErasedClient = AtomRpc.AtomRpcClient<unknown, string, Rpc.Rpc<string, Schema.Top, Schema.Top, Schema.Top>>;
9
+ type ErasedStreamingClient = AtomRpc.AtomRpcClient<unknown, string, Rpc.Rpc<string, Schema.Top, RpcSchema.Stream<Schema.Top, Schema.Top>, Schema.Never>>;
10
+ export declare function boundQuery(service: ErasedClient, tag: string, query: QueryShape, track: ReturnType<typeof automaticLive>["track"], owner?: BindingOwner): {
11
+ query: (payload: unknown, options?: QueryOptions) => import("effect/reactivity/Atom").Atom<import("effect/reactivity/AsyncResult").AsyncResult<unknown, unknown>>;
12
+ run: (payload: unknown) => Effect.Effect<unknown, unknown, unknown>;
13
+ };
14
+ export declare function boundCommand(service: ErasedClient, tag: string, command: CommandShape, owner?: BindingOwner): {
15
+ run: (payload: unknown) => Effect.Effect<unknown, unknown, unknown>;
16
+ };
17
+ export declare function boundStream(service: ErasedStreamingClient, tag: string): {
18
+ run: (payload: unknown) => Stream.Stream<unknown, unknown, unknown>;
19
+ };
20
+ export {};
21
+ //# sourceMappingURL=clientOperations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientOperations.d.ts","sourceRoot":"","sources":["../../src/internal/clientOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErD,OAAO,KAAK,KAAK,OAAO,MAAM,2BAA2B,CAAC;AAE1D,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,K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