@shivaedev/contract 0.58.0 → 0.59.1

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.59.1 - 2026-11-21
4
+
5
+ ### Changed
6
+
7
+ - Update `@shivaedev/errors` from 0.14.1 to 0.15.0.
8
+
9
+ ## 0.59.0 - 2026-11-21
10
+
11
+ ### Added
12
+
13
+ - `forSubject(client, subject)` from `@shivaedev/contract/forSubject.ts` returns a client's `api`, one contract's client or any record of them with every query's, command's and stream's subject defaulted to `subject`, so a screen tree that acts for another account binds its client once instead of passing `{ subject }` on every call. A subject named on a call still wins. Anything else, such as the value `makeClient` returns, is a compile error. A query through the bound client is the same atom, with the same serialization and live-update keys, as the query that names the subject per call, and binding the same client to the same subject again returns the same operations, so React's action and form hooks send the subject with no change in the screen.
14
+
3
15
  ## 0.58.0 - 2026-11-21
4
16
 
5
17
  ### Breaking
package/README.md CHANGED
@@ -200,7 +200,7 @@ Each operation runs in a span named after the module and the operation, such as
200
200
 
201
201
  #### The wire and the browser's contract
202
202
 
203
- Types are erased, so the success schema and rejection classes the server encodes with and the browser decodes with must exist as values. [`@shivaedev/build`](https://github.com/ShivaeDev/platform/tree/main/packages/build) writes them from each module's `run` types into one file per module under `src/generated/`, which stays out of Git; an application runs it as `pnpm generate`. The module file passes its wire, as `Notes` does above, and every operation is served with its wire entry's success and rejections, plus `InternalServerError` and `ServiceUnavailable`. A wire entry's success describes only the shape: its RPC carries `GeneratedSuccess` from `@shivaedev/errors/GeneratedSuccess.ts`, so the host neither collects sensitive names from it nor treats its fields as public. Mark a sensitive field on the server's model instead, as the [errors README](https://github.com/ShivaeDev/platform/tree/main/packages/errors#masking-secrets-in-failures) describes.
203
+ Types are erased, so the success schema and rejection classes the server encodes with and the browser decodes with must exist as values. [`@shivaedev/build`](https://github.com/ShivaeDev/platform/tree/main/packages/build) writes them from each module's `run` types into one file per module under `src/generated/`, which stays out of Git; an application runs it as `pnpm generate`. The module file passes its wire, as `Notes` does above, and every operation is served with its wire entry's success and rejections, plus `InternalServerError` and `ServiceUnavailable`. A wire entry's success restates a plain object's fields without annotations and imports an exported Schema class that `run` returns: its RPC carries `GeneratedSuccess` from `@shivaedev/errors/GeneratedSuccess.ts`, so the host collects the names that the class marks sensitive but never treats a restated field as public. Mark a sensitive field on the server's model, or on the exported class a raw read decodes into, as the [errors README](https://github.com/ShivaeDev/platform/tree/main/packages/errors#masking-secrets-in-failures) describes.
204
204
 
205
205
  The file the generator writes exports the wire, the browser's contract built by `clientContract` from the wire, the names of the module's queries and commands, the copied payloads, and the module's name, middleware, subject and key scope, and it ends with a type-level assertion that the browser's contract and the server module have the same RPCs:
206
206
 
@@ -325,6 +325,16 @@ export const Account = defineModule({ name: "account", operations: [Save], subje
325
325
 
326
326
  `PreferenceFields` is `Schema.Struct({ title: Schema.String })` and `Profiles` an application service whose `rename` takes the account's `SubjectId`. Contracts with declared subjects can be exported from published packages with TypeScript declaration output. The client calls `account.save` with only its title. For a delegated subject, the client names the account per call: a bound query takes `subject` in its options and a query's, command's or stream's `run` takes `{ subject }` as its second argument, as in `api.title.query(undefined, { subject: "bob" })` and `api.rename.run({ title }, { subject: "bob" })`. The option sets the call's `x-platform-subject` message header, so one client and its one socket serve the actor's own data and any number of subjects, each live query keeping its own subject on its changes stream. Queries with different subjects are different atoms, keep separate retained results, and serialize under separate keys when they share a `serializationKey`. The session host installs the resolver; operations read `Subject` from the request environment. See [identity's subject guide](https://github.com/ShivaeDev/platform/tree/main/packages/identity#declared-request-subjects) for delegated selection and refusal declarations.
327
327
 
328
+ A screen tree that acts for one other account binds its client once instead of naming the account on every call. `forSubject(client, subject)` from `@shivaedev/contract/forSubject.ts` takes a client's `api`, one contract's client from it, or any record of them, and returns the same shape with every query's, command's and stream's subject defaulted to `subject`. A subject named on a call still wins. It refuses at compile time anything else, such as the value `makeClient` returns or a function or Effect beside the operations, because a call through it would act for the actor's own account. A query made through the bound client is the same atom, with the same serialization key and live-update keys, as the query that names the subject per call, so a screen that mixes both forms reads one cache entry. The bound client shares the original's socket, so the plain client beside it still reads the actor's own data. Binding the same client to the same subject again returns the same operations, so React's action and form hooks keep their action across renders when a component binds its client while rendering:
329
+
330
+ ```ts
331
+ import { forSubject } from "@shivaedev/contract/forSubject.ts";
332
+
333
+ const client = forSubject(api, clientId);
334
+ const diary = useQuery(client.coaching.diary.query());
335
+ const save = useAction(client.coaching.write, { failures: { NotYourClient: "message" } });
336
+ ```
337
+
328
338
  ### Expected failures
329
339
 
330
340
  Import the shared expected failures from `@shivaedev/errors/taxonomy.ts`: `NotFound`, `Unauthorized`, `Forbidden`, `BadRequest`, `Conflict`, `PreconditionFailed`, `TooManyRequests`, `AuthUnavailable`, `InternalServerError` and `ServiceUnavailable`. Each class is a tagged error schema with a string `message`; `BadRequest` and `Conflict` also accept an optional string `field`. An operation written with `run` raises them and its wire lists them; the rest of this section is about RPCs that state their failures by hand, as native `Rpc` definitions and operations declared without run do. Declare only the failures an operation can return:
@@ -615,7 +625,7 @@ The state's `firstSettled` flag is `false` until the stream's `rendered` Effect
615
625
 
616
626
  For screen stories, pass `activityScreenSignal(clientActivity(client))` to a test-story screen driver's `activity` option. By default, `settle()` waits for commands until they are reflected and for the first result of each mounted query, then flushes the renderer. Contract identifies commands from its own RPC annotations; kits need no query-name exceptions. The activity state's `commands` count includes commands held for a connection, `unreflectedCommands` counts commands from the moment they are sent until they are reflected or fail, and `initialQueries` counts mounted queries until their first success or failure. Unmounting releases that query's pending activity. `isClientSettled(state)` checks these three counts. An open live query that has delivered its first result, including one awaiting a later refresh, does not keep a screen story pending.
617
627
 
618
- `activityScreenSignal(activity)` projects the stream and its `current` Effect into `{ pending, connectionStatus }`. The returned shape is structural and carries no test-story dependency. Stories that wait for a write their client did not make pass `screenSync(client, registry)` from `screenSync.ts` as the driver's `sync` option: it runs the client's `sync` through the view's registry, and the driver's `sync()` settles the screen after it. `isClientIdle(state)` retains the full finite-work check: `rpcCalls` for finite calls, `refreshingAtoms` for mounted query atoms awaiting values must all be zero. Long-lived subscription streams and server reruns themselves do not count as finite calls.
628
+ `activityScreenSignal(activity)` projects the stream and its `current` Effect into `{ pending, connectionStatus }`. The returned shape is structural and carries no test-story dependency. Stories that wait for a write their client did not make pass `screenSync(client, registry)` from `screenSync.ts` as the driver's `sync` option: it runs the client's `sync` through the view's registry, and the driver's `sync()` settles the screen after it. `isClientIdle(state)` retains the full finite-work check: `rpcCalls` for finite calls, `refreshingAtoms` for mounted query atoms awaiting values must all be zero. Long-lived subscription streams and server reruns themselves do not count as finite calls. A screen verb that refreshes or retries a loaded query settles on `activityScreenSignal(activity, isClientIdle)`, because the default check does not wait for that refresh.
619
629
 
620
630
  ### Query completion
621
631
 
@@ -994,6 +1004,7 @@ Import the module that defines the name; the package has no root entry.
994
1004
  | `syncHeader.ts` | `syncClient(headers)` and `syncToken(headers)` read the client name and the sync token a request carries. |
995
1005
  | `operationKind.ts` | `operationKind(rpc)`: `"read"` for a query, a changes stream or a stream, `"write"` for a command or an RPC no contract marked. |
996
1006
  | `subjectHeader.ts` | `subjectHeader(headers)` reads the account a call names; `withSubject(headers, subject)` and `subjectSerializationKey(key, headers)` are what bound operations use to send it and to keep serialized results apart. |
1007
+ | `forSubject.ts` | `forSubject(client, subject)` returns the client with every call's subject defaulted to `subject`; a subject named on a call wins. |
997
1008
  | `screenSync.ts` | `screenSync(client, registry)` runs a client's `sync` through a registry, for a screen driver's `sync` option. |
998
1009
 
999
1010
  A bound query’s optional second argument accepts `headers`, `subject` and `serializationKey`. Successful results remain in their owning registry for five minutes after the last reader leaves, up to 100 idle queries, evicting the least recently left first. Reopening a query immediately returns the retained success with native `waiting: true` while a new subscription or read supplies fresh data. Execution stops between readers. Configure the registry’s `queryRetention` atom from `@shivaedev/contract/queryRetention.ts` with `{ timeToLive: "1 minute", capacity: 50 }`, or set React’s `SessionBoundary` prop of the same name. Zero for either disables idle retention. Expiry runs on the query runtime’s Effect Clock. Registry disposal clears all retained results; applications outside `SessionBoundary` own that disposal when their session changes. A native resume source receives a callback and returns a cleanup function.
@@ -7,6 +7,7 @@ import type { automaticLive } from "#automaticLive.ts";
7
7
  import type { QueryOptions, RunOptions } from "#Bound.ts";
8
8
  import type { ActivityTracker } from "#clientActivities.ts";
9
9
  import type { CommandShape, QueryShape } from "#operation.ts";
10
+ export declare function runSubject(options: unknown): string | undefined;
10
11
  export declare function clientOperations(service: AtomRpc.AtomRpcClient<unknown, string, Rpc.Any>, activity: ActivityTracker, automatic: ReturnType<typeof automaticLive>, owner?: BindingOwner): {
11
12
  command: (tag: string, command: CommandShape) => {
12
13
  payload: Schema.Top;
@@ -1 +1 @@
1
- {"version":3,"file":"clientOperations.d.ts","sourceRoot":"","sources":["../src/clientOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAE/C,OAAO,KAAK,KAAK,OAAO,MAAM,2BAA2B,CAAC;AAE1D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAM5D,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAY9D,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,EACxD,QAAQ,EAAE,eAAe,EACzB,SAAS,EAAE,UA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AAY;mBA2GJ,MAAM,WAAW,YAAY;;uBAjC5B,OAAO,YAAY,UAAU,GAAG,IAAI,CAAC,SAAS;;;iBAkCjD,MAAM,SAAS,UAAU;yBAhFpB,OAAO,kDAAiD,YAAY;uBA2BtE,OAAO,YAAY,UAAU,GAAG,IAAI,CAAC,SAAS;;;kBAsDhD,MAAM;uBAlBJ,OAAO,YAAY,UAAU,GAAG,IAAI,CAAC,SAAS;;;;EAqB/D"}
@@ -14,7 +14,7 @@ import { storedForm } from "#storedQueries.ts";
14
14
  import { inputSubject, subjectSerializationKey, withSubject } from "#subjectHeader.ts";
15
15
  import { warmQueries } from "#warmQueries.ts";
16
16
  // `runtime.fn(api.save.run)` passes its function context as the second argument, so only an options object selects a subject.
17
- function runSubject(options) {
17
+ export function runSubject(options) {
18
18
  return typeof options === "object" && options !== null && "subject" in options && typeof options.subject === "string" ? options.subject : undefined;
19
19
  }
20
20
  export function clientOperations(service, activity, automatic, owner) {
@@ -1 +1 @@
1
- {"version":3,"file":"clientOperations.js","sourceRoot":"","sources":["../src/clientOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAE/D,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAG3D,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAIzE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,O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AAW,EAAE,OAAqB,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC;QAC3E,KAAK,EAAE,CAAC,GAAW,EAAE,KAAiB,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC;QACjE,MAAM,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC;QACzC,IAAI;KACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ export type SubjectBindable<TClient> = TClient extends {
2
+ readonly run: (...args: never) => unknown;
3
+ readonly runtime: unknown;
4
+ } ? unknown : TClient extends (...args: never) => unknown ? never : TClient extends object ? {
5
+ readonly [TKey in keyof TClient]: TKey extends string ? SubjectBindable<TClient[TKey]> : TClient[TKey];
6
+ } : never;
7
+ export declare function forSubject<TClient extends object>(client: TClient & SubjectBindable<TClient>, subject: string): TClient;
8
+ //# sourceMappingURL=forSubject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forSubject.d.ts","sourceRoot":"","sources":["../src/forSubject.ts"],"names":[],"mappings":"AAmBA,MAAM,MAAM,eAAe,CAAC,OAAO,IAAI,OAAO,SAAS;IAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAC5H,OAAO,GACP,OAAO,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,GAC1C,KAAK,GACL,OAAO,SAAS,MAAM,GACrB;IAAE,QAAQ,EAAE,IAAI,IAAI,MAAM,OAAO,GAAG,IAAI,SAAS,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAAE,GAC1G,KAAK,CAAC;AAuCX,wBAAgB,UAAU,CAAC,OAAO,SAAS,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,eAAe,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { runSubject } from "#clientOperations.ts";
2
+ // React's action hooks take `run` as the action's identity, so each operation and record is bound once per subject, and a
3
+ // record is cached before its members so one that refers back to itself binds to its own copy.
4
+ const bindings = new WeakMap();
5
+ function isOperation(value) {
6
+ return "runtime" in value && "run" in value && typeof value.run === "function";
7
+ }
8
+ function boundOperation(operation, subject) {
9
+ const { query, run } = operation;
10
+ return {
11
+ ...operation,
12
+ ...(query === undefined ? {} : { query: (payload, options = {}) => query(payload, { ...options, subject: options.subject ?? subject }) }),
13
+ run: (payload, options) => run(payload, { subject: runSubject(options) ?? subject }),
14
+ };
15
+ }
16
+ function bind(value, subject) {
17
+ const bySubject = bindings.get(value) ?? new Map();
18
+ bindings.set(value, bySubject);
19
+ const existing = bySubject.get(subject);
20
+ if (existing !== undefined) {
21
+ return existing;
22
+ }
23
+ if (isOperation(value)) {
24
+ const bound = boundOperation(value, subject);
25
+ bySubject.set(subject, bound);
26
+ return bound;
27
+ }
28
+ const bound = { ...value };
29
+ bySubject.set(subject, bound);
30
+ for (const [name, member] of Object.entries(value)) {
31
+ bound[name] = bind(member, subject);
32
+ }
33
+ return bound;
34
+ }
35
+ export function forSubject(client, subject) {
36
+ return bind(client, subject);
37
+ }
38
+ //# sourceMappingURL=forSubject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forSubject.js","sourceRoot":"","sources":["../src/forSubject.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAyBlD,0HAA0H;AAC1H,+FAA+F;AAC/F,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAiC,CAAC;AAE9D,SAAS,WAAW,CAAC,KAAa;IACjC,OAAO,SAAS,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,GAAG,KAAK,UAAU,CAAC;AAChF,CAA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CAAC,CAAC;IAC9B,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACpD,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAGD,MAAM,UAAU,UAAU,CAAC,MAAgB,EAAE,OAAe;IAC3D,OAAO,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC9B,CAAC"}
package/dist/wire.js CHANGED
@@ -3,7 +3,7 @@ import { rejectionSet } from "#rejection.ts";
3
3
  export function wireRejections(rejections) {
4
4
  return { ...rejections, InternalServerError, ServiceUnavailable };
5
5
  }
6
- // A wire's success is generated from run's type and carries no annotation, so its RPC takes it out of the sensitivity policy.
6
+ // A wire's success is generated from run's type and restates its fields without annotations, so its RPC lets it mark names sensitive but never declare one public.
7
7
  export function wired(operation, entry) {
8
8
  if (entry === undefined) {
9
9
  return operation;
package/dist/wire.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"wire.js","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAExF,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AA+B7C,MAAM,UAAU,cAAc,CAAC,UAA2B;IACzD,OAAO,EAAE,GAAG,UAAU,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;AACnE,CAAC;AAED,8HAA8H;AAC9H,MAAM,UAAU,KAAK,CAAC,SAAoC,EAAE,KAA4B;IACvF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,UAAU,GAAG,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACpD,OAAO,EAAE,GAAG,SAAS,EAAE,gBAAgB,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,GAAG,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;AAClH,CAAC"}
1
+ {"version":3,"file":"wire.js","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAExF,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AA+B7C,MAAM,UAAU,cAAc,CAAC,UAA2B;IACzD,OAAO,EAAE,GAAG,UAAU,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;AACnE,CAAC;AAED,mKAAmK;AACnK,MAAM,UAAU,KAAK,CAAC,SAAoC,EAAE,KAA4B;IACvF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,UAAU,GAAG,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACpD,OAAO,EAAE,GAAG,SAAS,EAAE,gBAAgB,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,GAAG,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;AAClH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/contract",
3
- "version": "0.58.0",
3
+ "version": "0.59.1",
4
4
  "description": "Typed query and command contracts over native Effect RPC and reactivity",
5
5
  "keywords": [
6
6
  "effect"
@@ -44,20 +44,20 @@
44
44
  ],
45
45
  "dependencies": {
46
46
  "@shivaedev/changes": "0.14.1",
47
- "@shivaedev/errors": "0.14.1",
47
+ "@shivaedev/errors": "0.15.0",
48
48
  "@shivaedev/service": "0.9.2",
49
49
  "@shivaedev/types": "0.4.0"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@effect/platform-node": "4.1.4",
53
53
  "@effect/vitest": "4.1.4",
54
- "@shivaedev/identity": "0.39.0",
55
- "@shivaedev/quality": "0.83.3",
56
- "@shivaedev/server": "0.42.0",
57
- "@shivaedev/sql": "0.54.0",
58
- "@shivaedev/test-kits": "0.16.4",
59
- "@shivaedev/test-sql": "0.26.0",
60
- "@shivaedev/test-story": "0.52.4",
54
+ "@shivaedev/identity": "0.44.2",
55
+ "@shivaedev/quality": "0.84.4",
56
+ "@shivaedev/server": "0.46.4",
57
+ "@shivaedev/sql": "0.55.0",
58
+ "@shivaedev/test-kits": "0.16.14",
59
+ "@shivaedev/test-sql": "0.26.1",
60
+ "@shivaedev/test-story": "0.52.7",
61
61
  "@types/node": "24.19.2",
62
62
  "effect": "4.1.4",
63
63
  "fake-indexeddb": "6.2.8",
@@ -22,7 +22,7 @@ import { inputSubject, subjectSerializationKey, withSubject } from "#subjectHead
22
22
  import { warmQueries } from "#warmQueries.ts";
23
23
 
24
24
  // `runtime.fn(api.save.run)` passes its function context as the second argument, so only an options object selects a subject.
25
- function runSubject(options: unknown): string | undefined {
25
+ export function runSubject(options: unknown): string | undefined {
26
26
  return typeof options === "object" && options !== null && "subject" in options && typeof options.subject === "string" ? options.subject : undefined;
27
27
  }
28
28
 
@@ -0,0 +1,68 @@
1
+ import type * as Atom from "effect/reactivity/Atom";
2
+ import type { QueryOptions, RunOptions } from "#Bound.ts";
3
+ import { runSubject } from "#clientOperations.ts";
4
+
5
+ interface Operation {
6
+ readonly query?: (payload: unknown, options?: QueryOptions) => unknown;
7
+ readonly run: (payload: unknown, options?: RunOptions | Atom.FnContext) => unknown;
8
+ readonly runtime: unknown;
9
+ }
10
+
11
+ interface BindableRecord {
12
+ readonly [name: string]: Bindable;
13
+ }
14
+
15
+ type Bindable = Operation | BindableRecord;
16
+
17
+ // A bound operation, or a record whose string-keyed members are bound operations or such records. Anything else, such as
18
+ // the Layer `makeClient` returns or a function beside the operations, is refused, because a call through it would silently
19
+ // act for the caller's own account.
20
+ export type SubjectBindable<TClient> = TClient extends { readonly run: (...args: never) => unknown; readonly runtime: unknown }
21
+ ? unknown
22
+ : TClient extends (...args: never) => unknown
23
+ ? never
24
+ : TClient extends object
25
+ ? { readonly [TKey in keyof TClient]: TKey extends string ? SubjectBindable<TClient[TKey]> : TClient[TKey] }
26
+ : never;
27
+
28
+ // React's action hooks take `run` as the action's identity, so each operation and record is bound once per subject, and a
29
+ // record is cached before its members so one that refers back to itself binds to its own copy.
30
+ const bindings = new WeakMap<object, Map<string, Bindable>>();
31
+
32
+ function isOperation(value: object): value is Operation {
33
+ return "runtime" in value && "run" in value && typeof value.run === "function";
34
+ }
35
+
36
+ function boundOperation(operation: Operation, subject: string): Operation {
37
+ const { query, run } = operation;
38
+ return {
39
+ ...operation,
40
+ ...(query === undefined ? {} : { query: (payload, options = {}) => query(payload, { ...options, subject: options.subject ?? subject }) }),
41
+ run: (payload, options) => run(payload, { subject: runSubject(options) ?? subject }),
42
+ };
43
+ }
44
+
45
+ function bind(value: Bindable, subject: string): Bindable {
46
+ const bySubject = bindings.get(value) ?? new Map<string, Bindable>();
47
+ bindings.set(value, bySubject);
48
+ const existing = bySubject.get(subject);
49
+ if (existing !== undefined) {
50
+ return existing;
51
+ }
52
+ if (isOperation(value)) {
53
+ const bound = boundOperation(value, subject);
54
+ bySubject.set(subject, bound);
55
+ return bound;
56
+ }
57
+ const bound: Record<string, Bindable> = { ...value };
58
+ bySubject.set(subject, bound);
59
+ for (const [name, member] of Object.entries(value)) {
60
+ bound[name] = bind(member, subject);
61
+ }
62
+ return bound;
63
+ }
64
+
65
+ export function forSubject<TClient extends object>(client: TClient & SubjectBindable<TClient>, subject: string): TClient;
66
+ export function forSubject(client: Bindable, subject: string): Bindable {
67
+ return bind(client, subject);
68
+ }
package/src/wire.ts CHANGED
@@ -36,7 +36,7 @@ export function wireRejections(rejections: ClassRejections) {
36
36
  return { ...rejections, InternalServerError, ServiceUnavailable };
37
37
  }
38
38
 
39
- // A wire's success is generated from run's type and carries no annotation, so its RPC takes it out of the sensitivity policy.
39
+ // A wire's success is generated from run's type and restates its fields without annotations, so its RPC lets it mark names sensitive but never declare one public.
40
40
  export function wired(operation: QueryShape | CommandShape, entry: WireEntry | undefined): QueryShape | CommandShape {
41
41
  if (entry === undefined) {
42
42
  return operation;