@shivaedev/contract 0.24.1 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/README.md +2 -2
- package/dist/clientOptions.d.ts +1 -1
- package/dist/clientOptions.d.ts.map +1 -1
- package/dist/internal/rpcClient.d.ts.map +1 -1
- package/dist/internal/rpcClient.js +4 -2
- package/dist/internal/rpcClient.js.map +1 -1
- package/package.json +3 -3
- package/src/clientOptions.ts +1 -1
- package/src/internal/rpcClient.ts +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.26.0 - 2026-10-31
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Browser readouts expose each subscription opening's state and an Effect that waits for all openings to receive a first response or a tagged refusal, without polling.
|
|
8
|
+
- Contract clients accept a session identity protocol factory so custom transports can follow sign-in and sign-out.
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- End hosted live subscriptions with `Unauthorized` when the original session is signed out, revoked or expired, whether detected during a change hint or periodic revalidation. Keep `QueryReadDenied` for a signed-in viewer whose query policy refuses the read.
|
|
13
|
+
- Batch shared socket session lookups with an Effect scheduler yield so advancing `TestClock` past `streamRevalidationInterval` completes revalidation without another clock advance.
|
|
14
|
+
- Preserve typed session-provider failures during hint-time authorization instead of reporting them as read-policy refusals.
|
|
15
|
+
|
|
16
|
+
### Breaking
|
|
17
|
+
|
|
18
|
+
- `browserReads().protocol` is now a session identity protocol factory. Continue passing it directly to `makeClient`; native Layer consumers must call `observed.protocol(undefined)` for an anonymous client, or pass the session identity. The same readout counts traffic across session sockets.
|
|
19
|
+
|
|
20
|
+
## 0.25.0 - 2026-10-30
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- Accept `retryKeys` in `live()` to identify changes that reopen a settled subscription independently of its resync scope. It defaults to `resyncKeys`.
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- Keep denied live queries and subscriptions settled until the viewer identity changes or a matching change invalidation arrives. Resume events do not retry a settled rejection.
|
|
29
|
+
- Retry transport failures and server outages with jittered exponential backoff. `retryDelay` sets the initial delay; backoff grows to a nominal 30 seconds.
|
|
30
|
+
|
|
31
|
+
### Breaking
|
|
32
|
+
|
|
33
|
+
- Live subscriptions settle expected failures with `LiveStatus.connection: "failed"`. Add a `"failed"` case to exhaustive connection handlers and show `status.failure`; applications no longer receive repeated attempts for denied reads or declared query errors.
|
|
34
|
+
|
|
3
35
|
## 0.24.1 - 2026-10-30
|
|
4
36
|
|
|
5
37
|
### Changed
|
package/README.md
CHANGED
|
@@ -225,7 +225,7 @@ const rename = runtime.fn(api.rename.run);
|
|
|
225
225
|
|
|
226
226
|
Browsers send the session cookie at upgrade. Mounting a query opens its subscription before running its first authorized read; unmounting cancels that subscription without restarting the socket or another query. Changed keys rerun only their readers, and equal results retain the bound atom's value. Connection failures use Effect RPC's reconnect backoff; subscriptions resume and mounted queries read again because there is no retained key history. `LiveConnection.status` reports `connecting`, `live` or `reconnecting`.
|
|
227
227
|
|
|
228
|
-
`group` supplies a larger native RPC group containing the contract, such as an admin registry. The result is a native client Layer for `ManagedRuntime.make`, plus the native `Client` service, atom `runtime` and scoped `client` Effect. Session-scoped contracts require `registry`. For Node clients, supply upgrade `headers` and `webSocketConstructor: NodeSocket.layerWebSocketConstructorWS` from `@effect/platform-node`. A native `protocol` Layer selects another transport explicitly. Use `live: false` for ordinary clients without subscriptions.
|
|
228
|
+
`group` supplies a larger native RPC group containing the contract, such as an admin registry. The result is a native client Layer for `ManagedRuntime.make`, plus the native `Client` service, atom `runtime` and scoped `client` Effect. Session-scoped contracts require `registry`. For Node clients, supply upgrade `headers` and `webSocketConstructor: NodeSocket.layerWebSocketConstructorWS` from `@effect/platform-node`. A native `protocol` Layer selects another transport explicitly. A `protocol: (identity) => layer` factory follows the live session identity instead: the client rebuilds its transport when that identity changes. The scoped `client` Effect uses `undefined` as the factory identity. Return a shared Layer for clients that should share a socket within one session. Use `live: false` for ordinary clients without subscriptions.
|
|
229
229
|
|
|
230
230
|
### 3. Every day: read and change
|
|
231
231
|
|
|
@@ -469,7 +469,7 @@ A record key, `notes.item(id)`, names one record. A bucket, `notes.bucket.userId
|
|
|
469
469
|
|
|
470
470
|
The same query policy guards running the query and subscribing to it. A subscription names query references, never arbitrary record or bucket keys. The entire subscription is refused with `QueryReadDenied` if any referenced query is denied. Without `readPolicy`, a query has no authorized live subscription: `MissingReadPolicy` tells its author to declare one. Bound query atoms also refuse a missing policy before their first read. Ordinary one-off `run` calls remain available. Reads outside a declared query acquire no automatic subscription.
|
|
471
471
|
|
|
472
|
-
The session middleware supplies the viewer and runs `authorizeReads(effect, request, viewer)`. Custom middleware calls that function after resolving its session and declares `MissingReadPolicy` and `QueryReadDenied` in its error schema. Before delivering changed keys, the stream rechecks the owning query's policy without memoization. A client refresh runs the same authorized query that produced its first value; hints carry no row values.
|
|
472
|
+
The session middleware supplies the viewer and runs `authorizeReads(effect, request, viewer)`. Custom middleware calls that function after resolving its session and declares `MissingReadPolicy` and `QueryReadDenied` in its error schema. Before delivering changed keys, the stream rechecks the owning query's policy without memoization. In a session-backed host, a signed-out, revoked or expired session ends the subscription with `Unauthorized`; a signed-in viewer whose policy refuses ends it with `QueryReadDenied`. This distinction is the same whether a change hint or the session revalidation interval detects session removal. A client refresh runs the same authorized query that produced its first value; hints carry no row values.
|
|
473
473
|
|
|
474
474
|
### Live hints in stories
|
|
475
475
|
|
package/dist/clientOptions.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { CommandShape, QueryShape, StreamShape } from "#operation.ts";
|
|
|
10
10
|
export interface ClientOptions {
|
|
11
11
|
readonly headers?: Readonly<Record<string, string>>;
|
|
12
12
|
readonly live?: boolean;
|
|
13
|
-
readonly protocol?: Layer.Layer<RpcClient.Protocol
|
|
13
|
+
readonly protocol?: Layer.Layer<RpcClient.Protocol> | ((identity: string | undefined) => Layer.Layer<RpcClient.Protocol>);
|
|
14
14
|
readonly url: string;
|
|
15
15
|
readonly webSocketConstructor?: Layer.Layer<Socket.WebSocketConstructor>;
|
|
16
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientOptions.d.ts","sourceRoot":"","sources":["../src/clientOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,KAAK,OAAO,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,KAAK,MAAM,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE3E,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"clientOptions.d.ts","sourceRoot":"","sources":["../src/clientOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,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-13,10 +13,12 @@ export function rpcClient(name, source, options) {
|
|
|
13
13
|
webSocketConstructor: options.webSocketConstructor,
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
-
const
|
|
16
|
+
const customProtocol = options.protocol;
|
|
17
|
+
const protocolFor = typeof customProtocol === "function" ? customProtocol : sharedProtocol;
|
|
18
|
+
const protocol = typeof customProtocol === "function" ? customProtocol(undefined) : (customProtocol ?? sharedProtocol());
|
|
17
19
|
const Client = AtomRpc.Service()(`${name}/Client`, {
|
|
18
20
|
group,
|
|
19
|
-
protocol:
|
|
21
|
+
protocol: typeof customProtocol === "object" ? customProtocol : (get) => protocolFor(get(socketIdentity)),
|
|
20
22
|
});
|
|
21
23
|
const client = Effect.flatMap(Layer.build(protocol), (context) => RpcClient.make(group).pipe(Effect.provideContext(context)));
|
|
22
24
|
const layer = Layer.effect(Client, RpcClient.make(group, { flatten: true })).pipe(Layer.provide(protocol));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpcClient.js","sourceRoot":"","sources":["../../src/internal/rpcClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC/D,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,OAAO,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAY,SAAS,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAC;AAQ/C,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,MAAiB,EAAE,OAAsB;IAChF,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC3F,SAAS,cAAc,CAAC,QAAiB;QACxC,OAAO,cAAc,C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;IACJ,MAAM,QAAQ,GAAG,SAAS,CAAC,mBAAmB,CAAC;QAC9C,WAAW,EAAE,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACrG,CAAC,CAAC,IAAI,CACN,KAAK,CAAC,OAAO,CACZ,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CACpE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,oBAAoB,IAAI,MAAM,CAAC,+BAA+B,CAAC,CACrF,CACD,EACD,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAC3C,CAAC;IACF,OAAO,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAC7H,CAAC,CACD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/contract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Typed query and command contracts over native Effect RPC and reactivity",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@effect/platform-node": "4.0.6",
|
|
51
51
|
"@effect/vitest": "4.0.6",
|
|
52
|
-
"@shivaedev/quality": "0.48.
|
|
52
|
+
"@shivaedev/quality": "0.48.1",
|
|
53
53
|
"@shivaedev/test": "0.12.0",
|
|
54
54
|
"@shivaedev/test-sql": "0.15.0",
|
|
55
|
-
"@shivaedev/test-story": "0.
|
|
55
|
+
"@shivaedev/test-story": "0.27.0",
|
|
56
56
|
"@types/node": "24.19.2",
|
|
57
57
|
"effect": "4.0.6",
|
|
58
58
|
"esbuild": "0.28.2",
|
package/src/clientOptions.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type { CommandShape, QueryShape, StreamShape } from "#operation.ts";
|
|
|
11
11
|
export interface ClientOptions {
|
|
12
12
|
readonly headers?: Readonly<Record<string, string>>;
|
|
13
13
|
readonly live?: boolean;
|
|
14
|
-
readonly protocol?: Layer.Layer<RpcClient.Protocol
|
|
14
|
+
readonly protocol?: Layer.Layer<RpcClient.Protocol> | ((identity: string | undefined) => Layer.Layer<RpcClient.Protocol>);
|
|
15
15
|
readonly url: string;
|
|
16
16
|
readonly webSocketConstructor?: Layer.Layer<Socket.WebSocketConstructor>;
|
|
17
17
|
}
|
|
@@ -20,10 +20,12 @@ export function rpcClient(name: string, source: RpcSource, options: ClientOption
|
|
|
20
20
|
webSocketConstructor: options.webSocketConstructor,
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
-
const
|
|
23
|
+
const customProtocol = options.protocol;
|
|
24
|
+
const protocolFor = typeof customProtocol === "function" ? customProtocol : sharedProtocol;
|
|
25
|
+
const protocol = typeof customProtocol === "function" ? customProtocol(undefined) : (customProtocol ?? sharedProtocol());
|
|
24
26
|
const Client = AtomRpc.Service<unknown>()(`${name}/Client`, {
|
|
25
27
|
group,
|
|
26
|
-
protocol:
|
|
28
|
+
protocol: typeof customProtocol === "object" ? customProtocol : (get) => protocolFor(get(socketIdentity)),
|
|
27
29
|
});
|
|
28
30
|
const client = Effect.flatMap(Layer.build(protocol), (context) => RpcClient.make(group).pipe(Effect.provideContext(context)));
|
|
29
31
|
const layer = Layer.effect(Client, RpcClient.make(group, { flatten: true })).pipe(Layer.provide(protocol));
|