@shivaedev/contract 0.31.0 → 0.32.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 +28 -0
- package/README.md +81 -12
- package/dist/CommandGuard.d.ts +10 -0
- package/dist/CommandGuard.d.ts.map +1 -0
- package/dist/CommandGuard.js +20 -0
- package/dist/CommandGuard.js.map +1 -0
- package/dist/LiveServer.d.ts +6 -4
- package/dist/LiveServer.d.ts.map +1 -1
- package/dist/LiveServer.js +10 -5
- package/dist/LiveServer.js.map +1 -1
- package/dist/ReadPolicyGuard.d.ts +19 -0
- package/dist/ReadPolicyGuard.d.ts.map +1 -0
- package/dist/ReadPolicyGuard.js +23 -0
- package/dist/ReadPolicyGuard.js.map +1 -0
- package/dist/adapters/activityState.d.ts +9 -0
- package/dist/adapters/activityState.d.ts.map +1 -0
- package/dist/adapters/activityState.js +11 -0
- package/dist/adapters/activityState.js.map +1 -0
- package/dist/{internal → adapters}/bindingOwner.d.ts +1 -1
- package/dist/{internal → adapters}/bindingOwner.d.ts.map +1 -1
- package/dist/{internal → adapters}/bindingOwner.js +2 -1
- package/dist/adapters/bindingOwner.js.map +1 -0
- package/dist/adapters/clientId.d.ts +2 -0
- package/dist/adapters/clientId.d.ts.map +1 -0
- package/dist/adapters/clientId.js +4 -0
- package/dist/adapters/clientId.js.map +1 -0
- package/dist/automaticLive.d.ts +1 -1
- package/dist/automaticLive.d.ts.map +1 -1
- package/dist/automaticLive.js +7 -2
- package/dist/automaticLive.js.map +1 -1
- package/dist/bind.d.ts.map +1 -1
- package/dist/bind.js +1 -1
- package/dist/bind.js.map +1 -1
- package/dist/changesHandlerLayer.d.ts +19 -0
- package/dist/changesHandlerLayer.d.ts.map +1 -0
- package/dist/changesHandlerLayer.js +15 -0
- package/dist/changesHandlerLayer.js.map +1 -0
- package/dist/clientActivity.d.ts +10 -1
- package/dist/clientActivity.d.ts.map +1 -1
- package/dist/clientActivity.js +7 -0
- package/dist/clientActivity.js.map +1 -1
- package/dist/clientKeys.d.ts +7 -0
- package/dist/clientKeys.d.ts.map +1 -0
- package/dist/clientKeys.js +11 -0
- package/dist/clientKeys.js.map +1 -0
- package/dist/composeBindings.d.ts +8 -0
- package/dist/composeBindings.d.ts.map +1 -0
- package/dist/composeBindings.js +18 -0
- package/dist/composeBindings.js.map +1 -0
- package/dist/contract.d.ts +5 -8
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +11 -7
- package/dist/contract.js.map +1 -1
- package/dist/internal/automaticQuery.d.ts +3 -1
- package/dist/internal/automaticQuery.d.ts.map +1 -1
- package/dist/internal/automaticQuery.js +9 -2
- package/dist/internal/automaticQuery.js.map +1 -1
- package/dist/internal/changesSuccess.d.ts +5 -1
- package/dist/internal/changesSuccess.d.ts.map +1 -1
- package/dist/internal/changesSuccess.js +10 -6
- package/dist/internal/changesSuccess.js.map +1 -1
- package/dist/internal/clientActivity.d.ts +5 -6
- package/dist/internal/clientActivity.d.ts.map +1 -1
- package/dist/internal/clientActivity.js +6 -18
- package/dist/internal/clientActivity.js.map +1 -1
- package/dist/internal/clientOperations.d.ts +1 -1
- package/dist/internal/clientOperations.d.ts.map +1 -1
- package/dist/internal/clientOperations.js +7 -4
- package/dist/internal/clientOperations.js.map +1 -1
- package/dist/internal/compareQueries.d.ts +2 -1
- package/dist/internal/compareQueries.d.ts.map +1 -1
- package/dist/internal/compareQueries.js +5 -7
- package/dist/internal/compareQueries.js.map +1 -1
- package/dist/internal/declarationError.d.ts +7 -1
- package/dist/internal/declarationError.d.ts.map +1 -1
- package/dist/internal/declarationError.js.map +1 -1
- package/dist/internal/prependMiddleware.d.ts +10 -0
- package/dist/internal/prependMiddleware.d.ts.map +1 -0
- package/dist/internal/prependMiddleware.js +12 -0
- package/dist/internal/prependMiddleware.js.map +1 -0
- package/dist/internal/queryDelivery.d.ts +2 -1
- package/dist/internal/queryDelivery.d.ts.map +1 -1
- package/dist/internal/queryDelivery.js +8 -1
- package/dist/internal/queryDelivery.js.map +1 -1
- package/dist/internal/queryReactivity.d.ts.map +1 -1
- package/dist/internal/queryReactivity.js +3 -11
- package/dist/internal/queryReactivity.js.map +1 -1
- package/dist/internal/querySignals.d.ts +8 -0
- package/dist/internal/querySignals.d.ts.map +1 -0
- package/dist/internal/querySignals.js +42 -0
- package/dist/internal/querySignals.js.map +1 -0
- package/dist/internal/wrapAtom.d.ts +3 -0
- package/dist/internal/wrapAtom.d.ts.map +1 -0
- package/dist/internal/wrapAtom.js +15 -0
- package/dist/internal/wrapAtom.js.map +1 -0
- package/dist/live.d.ts +2 -1
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +5 -4
- package/dist/live.js.map +1 -1
- package/dist/makeLiveServer.d.ts +22 -5
- package/dist/makeLiveServer.d.ts.map +1 -1
- package/dist/makeLiveServer.js +39 -24
- package/dist/makeLiveServer.js.map +1 -1
- package/dist/publicConfig.d.ts +19 -3
- package/dist/publicConfig.d.ts.map +1 -1
- package/dist/querySignals.d.ts +9 -0
- package/dist/querySignals.d.ts.map +1 -0
- package/dist/querySignals.js +14 -0
- package/dist/querySignals.js.map +1 -0
- package/dist/querySubscription.d.ts +1 -1
- package/dist/querySubscription.d.ts.map +1 -1
- package/dist/querySubscription.js +7 -4
- package/dist/querySubscription.js.map +1 -1
- package/dist/queryUpdate.d.ts +5 -1
- package/dist/queryUpdate.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/CommandGuard.ts +25 -0
- package/src/LiveServer.ts +18 -9
- package/src/ReadPolicyGuard.ts +31 -0
- package/src/adapters/activityState.ts +12 -0
- package/src/{internal → adapters}/bindingOwner.ts +3 -2
- package/src/adapters/clientId.ts +3 -0
- package/src/automaticLive.ts +8 -3
- package/src/bind.ts +1 -1
- package/src/changesHandlerLayer.ts +51 -0
- package/src/clientActivity.ts +8 -1
- package/src/clientKeys.ts +17 -0
- package/src/composeBindings.ts +27 -0
- package/src/contract.ts +14 -20
- package/src/internal/automaticQuery.ts +11 -1
- package/src/internal/changesSuccess.ts +13 -8
- package/src/internal/clientActivity.ts +37 -52
- package/src/internal/clientOperations.ts +9 -5
- package/src/internal/compareQueries.ts +6 -8
- package/src/internal/declarationError.ts +12 -1
- package/src/internal/prependMiddleware.ts +15 -0
- package/src/internal/queryDelivery.ts +9 -0
- package/src/internal/queryReactivity.ts +4 -11
- package/src/internal/querySignals.ts +46 -0
- package/src/internal/wrapAtom.ts +14 -0
- package/src/live.ts +5 -4
- package/src/makeLiveServer.ts +64 -57
- package/src/querySignals.ts +22 -0
- package/src/querySubscription.ts +8 -7
- package/src/queryUpdate.ts +5 -1
- package/dist/internal/bindingOwner.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.32.0 - 2026-11-03
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `makeClient` accepts `resume` and `resumeWindow` so applications can supply native lifecycle signals and an embedded browser window directly, preserving the client's inferred API, failures and requirements.
|
|
8
|
+
- `composeBindings(client, bindings)` preserves the client's type and declares the bound APIs in one connection. `liveBindings(connection)` reads that composition while retaining support for direct bindings and object properties.
|
|
9
|
+
- Observe bound queries with `querySignals(query)`: a native atom reports completed reads, pending requests, and whether their subscription opened or was refused. Refreshes signal completion even when their result is unchanged.
|
|
10
|
+
- Supply `CommandGuard`, `CommandBoundary`, `guardCommands` and `commandGuardLayer` to evaluate declared command changes for the current viewer independently of authentication and tracing.
|
|
11
|
+
- Export `activityScreenSignal(activity)` from `clientActivity.ts`, projecting client activity into a native stream and current Effect of pending screen work and hint counts.
|
|
12
|
+
- Contract owns `ReadPolicyGuard`, `readPolicyGuardLayer()` and `guardReads(group)` in `@shivaedev/contract/ReadPolicyGuard.ts`. The guard checks each ordinary query's read policy once against the request's `CurrentViewer`.
|
|
13
|
+
- Derive custom subscription handlers with `changesHandlerLayer`, retaining query payloads, declared failures, read-policy services and stream requirements in a native Layer.
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- Schedule contract live hints through the Effect runtime's Scheduler, preserving batched changes, resyncs and stream cleanup. Isolate synchronous client identity and activity bridges in adapters and share atom wrapping across bindings.
|
|
18
|
+
- Refresh server-discovered read scopes on each live subscription rerun and replace their registrations, including when a pushed result is unchanged.
|
|
19
|
+
- `LiveServer.subscribe` preserves `SubscriptionHint` deliveries when no query runner is supplied, including an explicit `undefined`. Calls with a query runner keep `QueryUpdate` deliveries and retain the subscription's typed failures and service requirements.
|
|
20
|
+
- Contract groups enforce query read policies automatically in native Effect RPC hosts as well as the application host. A false policy returns `QueryReadDenied` without running the handler. Ordinary queries evaluate their policy once per request.
|
|
21
|
+
|
|
22
|
+
### Breaking
|
|
23
|
+
|
|
24
|
+
- Rerun-and-compare subscriptions emit an `Unchanged` update with the query index when a completed read preserves its previous value. Consumers of raw `$changes` streams must handle this update; bound queries handle it automatically. Deploy clients and servers together so both understand the updated stream schema.
|
|
25
|
+
- Calls to `LiveServer.subscribe` that explicitly supply its error and service type arguments and a query runner must also supply the runner type as the third type argument, or omit the type arguments and let TypeScript infer them.
|
|
26
|
+
- Remove `guardReads` from `@shivaedev/contract/ReadPolicyGuard.ts`. Serve the contract group directly with `RpcServer`; remove any explicit read-policy Layer unless you use `readPolicyGuardLayer()` to refuse HTTP `$changes` calls with `WebSocketRequired`. `ReadPolicyGuard` is now a defaulted Context reference rather than a service class and requires no provision. Remove its former service type from Layer annotations.
|
|
27
|
+
- Custom authentication middleware must supply `CurrentViewer` after session validation and stop calling `authorizeReads`; the contract's attached guard performs that check. Keep `authorizeReads` only for direct handler reruns outside RPC dispatch.
|
|
28
|
+
- Ordinary query failures now include `MissingReadPolicy` and `WebSocketRequired` from the attached middleware. `MissingReadPolicy` refuses untyped declarations that omit a policy; `WebSocketRequired` belongs to the optional HTTP subscription restriction. Add these refusals to exhaustive error handlers.
|
|
29
|
+
- `makeLiveServer.stream` and `LiveServer.stream` accept keys only. Their `subscribe` methods now take `(subscription, authorizedRunner?)`; remove the former context argument. `QuerySubscription.globalKeys` is removed because all server keys share the repository namespace; remove it from custom subscription objects.
|
|
30
|
+
|
|
3
31
|
## 0.31.0 - 2026-11-02
|
|
4
32
|
|
|
5
33
|
### Added
|
package/README.md
CHANGED
|
@@ -277,7 +277,21 @@ Client invalidation follows RPC success. Database hosts from `@shivaedev/server`
|
|
|
277
277
|
|
|
278
278
|
### Client activity
|
|
279
279
|
|
|
280
|
-
`clientActivity(client)` from `@shivaedev/contract/clientActivity.ts` returns a native Effect `Stream` with a `current` Effect for a client made by `makeClient`. Its state reports `rpcCalls` for finite calls, `liveInvalidations` for queued live refreshes, `refreshingAtoms` for mounted query atoms awaiting values, and a `liveHints` sequence for received subscription updates. Long-lived streams do not count as finite calls. `isClientIdle(state)` is true when all three work counts are zero. Observe its stream or pass
|
|
280
|
+
`clientActivity(client)` from `@shivaedev/contract/clientActivity.ts` returns a native Effect `Stream` with a `current` Effect for a client made by `makeClient`. Its state reports `rpcCalls` for finite calls, `liveInvalidations` for queued live refreshes, `refreshingAtoms` for mounted query atoms awaiting values, and a `liveHints` sequence for received subscription updates. Long-lived streams do not count as finite calls. `isClientIdle(state)` is true when all three work counts are zero. Observe its stream or pass `activityScreenSignal(clientActivity(client))` to a test-story screen driver's `pending` option and call `settle()` before screen assertions. `activityScreenSignal(activity)` projects the stream and its `current` Effect into `{ pending, hints }`, with `pending` true while finite work remains and `hints` carrying the received live-hint count. The returned shape is structural and carries no test-story dependency. Coalesced work stays pending until its refresh completes.
|
|
281
|
+
|
|
282
|
+
### Query completion
|
|
283
|
+
|
|
284
|
+
`querySignals(query)` from `@shivaedev/contract/querySignals.ts` returns a native atom scoped to the query's registry. Its `completed` counter advances when the initial query or a refresh finishes, including typed failures and equal results. `pending` describes the query result awaiting completion. `subscription` is `disabled` for an ordinary query, `opening` while connecting, `open` once accepted, or `refused` after a terminal refusal. Read the query's `AsyncResult` for its value or typed failure.
|
|
285
|
+
|
|
286
|
+
```ts
|
|
287
|
+
import { querySignals } from "@shivaedev/contract/querySignals.ts";
|
|
288
|
+
|
|
289
|
+
const signals = querySignals(one);
|
|
290
|
+
const before = registry.get(signals).completed;
|
|
291
|
+
const completions = AtomRegistry.toStream(registry, signals);
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Mount the query to start it. Wait on `completions` for `completed > before` after an action that refreshes it; compare the counter rather than the result's identity. A server-pushed equal result completes without changing the visible value. Raw rerun-and-compare `$changes` consumers receive an `Unchanged` update with `queryIndex` for these completed reads. Clients and servers must understand the same stream schema.
|
|
281
295
|
|
|
282
296
|
### Session-owned keys
|
|
283
297
|
|
|
@@ -319,19 +333,41 @@ Preferences.application.toLayer({
|
|
|
319
333
|
});
|
|
320
334
|
```
|
|
321
335
|
|
|
322
|
-
`store` is the application's persistence service. No owner or client key scope is accepted from a request. The database app host
|
|
336
|
+
`store` is the application's persistence service. No owner or client key scope is accepted from a request. The database app host uses plain repository keys for every subscriber and rechecks each subscriber’s read policy before delivery.
|
|
323
337
|
|
|
324
338
|
The registry is required for session-scoped bindings. Query atoms and live connections belong in it; command and one-off query Effects execute through it. Explicit streams also run through its client, preserving the session transport and headers; disposing the registry ends those streams. Streams on ordinary contracts use the caller's client. A successful command invalidates its owner's keys, while a rejected command declares no invalidation. Ordinary contracts keep unscoped keys and the two-argument `bind` call.
|
|
325
339
|
|
|
326
|
-
|
|
340
|
+
Server subscriptions and committed writes use the same plain record, list and bucket keys, including for `keyScope: "session"`. A background worker needs no request identity or account prefix to refresh a session's query. Matching keys trigger the query's own read policy; authorized reads remain responsible for filtering rows to the viewer. A shared key can therefore trigger authorized rechecks for several accounts. Use model buckets to narrow that fan-out.
|
|
341
|
+
|
|
342
|
+
Client cache isolation belongs to the owning registry. `bind` supplies its opaque context automatically. Custom client coordination uses these helpers and context type:
|
|
327
343
|
|
|
328
|
-
|
|
344
|
+
```ts
|
|
345
|
+
import { clientInvalidationKeys, clientReadKeys, type KeyContext } from "@shivaedev/contract/clientKeys.ts";
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
`clientReadKeys(keys, context)` registers client dependencies; `clientInvalidationKeys(keys, context)` announces client cache changes. The context has type `KeyContext`. Never publish contextual client keys on the server.
|
|
349
|
+
|
|
350
|
+
### Compose feature bindings
|
|
351
|
+
|
|
352
|
+
Use `composeBindings(client, bindings)` when a connection contains several feature modules. The returned object keeps the client's fields and types and carries an explicit list of bound APIs. `liveBindings(connection)` reads this list; it also accepts a binding directly or an object with bound APIs as its own properties.
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
import { composeBindings } from "@shivaedev/contract/composeBindings.ts";
|
|
356
|
+
|
|
357
|
+
const modules = [notesModule, tasksModule] as const;
|
|
358
|
+
const connection = composeBindings(
|
|
359
|
+
{ modules },
|
|
360
|
+
modules.map((module) => module.api),
|
|
361
|
+
);
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
`notesModule` and `tasksModule` are application modules whose `api` values come from `bind` or `makeClient`. Return `connection` from React's `SessionBoundary` connection callback to mount both bindings while keeping the modules nested.
|
|
329
365
|
|
|
330
366
|
### 4. Live invalidation and resume
|
|
331
367
|
|
|
332
368
|
The automatic live connection exposed at `api[LiveConnection]` includes a writable `paused` atom. Set it in the binding’s registry to pause refreshes; clearing it reconciles the mounted queries. Bindings on the same client runtime share this pause state.
|
|
333
369
|
|
|
334
|
-
Database hosts from `@shivaedev/server` serve the contract's reserved `<contract>.$changes` stream automatically. With the native WebSocket protocol, `bind` and a React `SessionBoundary` connect query atoms without an application subscribe operation or `live()` call. The boundary finds bound APIs returned directly by `connect` or as properties such as `client.api`. See [automatic changes](https://github.com/ShivaeDev/platform/blob/main/docs/framework/changes.md) for defaults.
|
|
370
|
+
Database hosts from `@shivaedev/server` serve the contract's reserved `<contract>.$changes` stream automatically. With the native WebSocket protocol, `bind` and a React `SessionBoundary` connect query atoms without an application subscribe operation or `live()` call. The boundary mounts the bindings declared with `composeBindings`, or 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.
|
|
335
371
|
|
|
336
372
|
Subscribing to the hosted `$changes` stream over HTTP fails with `WebSocketRequired` from `@shivaedev/contract/WebSocketRequired.ts`; its message names the stream and says it needs the WebSocket protocol.
|
|
337
373
|
|
|
@@ -366,7 +402,34 @@ const changes = Stream.unwrap(
|
|
|
366
402
|
);
|
|
367
403
|
```
|
|
368
404
|
|
|
369
|
-
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 }`. Custom subscription handlers call `querySubscription(rpc, references, viewer)` with the native changes RPC definition and pass its authorized result to `makeLiveServer.subscribe(subscription
|
|
405
|
+
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 }`. Custom subscription handlers call `querySubscription(rpc, references, viewer)` with the native changes RPC definition and pass its authorized result to `makeLiveServer.subscribe(subscription)`. Hosted applications use `resolveChanges` from identity to supply that subscription. 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.
|
|
406
|
+
|
|
407
|
+
Custom subscription handlers use `changesHandlerLayer` to derive the reserved handler Layer from the contract:
|
|
408
|
+
|
|
409
|
+
```ts
|
|
410
|
+
import { Effect, Stream } from "effect";
|
|
411
|
+
import { changesHandlerLayer } from "@shivaedev/contract/changesHandlerLayer.ts";
|
|
412
|
+
import { LiveServer } from "@shivaedev/contract/LiveServer.ts";
|
|
413
|
+
import { querySubscription } from "@shivaedev/contract/querySubscription.ts";
|
|
414
|
+
import { CurrentViewer } from "@shivaedev/contract/readPolicy.ts";
|
|
415
|
+
import { Notes } from "./notes.ts";
|
|
416
|
+
|
|
417
|
+
const changes = changesHandlerLayer(
|
|
418
|
+
Notes,
|
|
419
|
+
(rpc) =>
|
|
420
|
+
({ queries }) =>
|
|
421
|
+
Stream.unwrap(
|
|
422
|
+
Effect.gen(function* () {
|
|
423
|
+
const viewer = yield* CurrentViewer;
|
|
424
|
+
const subscription = yield* querySubscription(rpc, queries, viewer);
|
|
425
|
+
const live = yield* LiveServer;
|
|
426
|
+
return yield* live.subscribe(subscription);
|
|
427
|
+
}),
|
|
428
|
+
),
|
|
429
|
+
);
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
Merge this Layer with `Notes.application.toLayer(...)`. It retains the query read-policy and custom stream services as requirements, excluding services supplied by RPC middleware. The builder can also return an Effect to acquire services or fail during Layer construction. Declared stream failures remain in the contract's error channel. Pushed results are validated against the contract's decoded success types; custom handlers do not decode `changesSuccess` themselves.
|
|
370
433
|
|
|
371
434
|
For a custom transport or explicit pause and status controls, use the native live APIs.
|
|
372
435
|
|
|
@@ -456,7 +519,7 @@ Call the release functions and dispose the registry when the application's root
|
|
|
456
519
|
|
|
457
520
|
### Server hint streams
|
|
458
521
|
|
|
459
|
-
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
|
|
522
|
+
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.
|
|
460
523
|
|
|
461
524
|
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.
|
|
462
525
|
|
|
@@ -464,6 +527,8 @@ Each stream queues at most 256 hints. Overflow discards the pending hints and re
|
|
|
464
527
|
|
|
465
528
|
### Query policies, record keys and buckets
|
|
466
529
|
|
|
530
|
+
Contract groups carry their read-policy guard into native `RpcServer` hosts and Platform’s application host. An ordinary query evaluates its policy once per request, after identity middleware supplies `CurrentViewer` from its validated session. A false policy returns `QueryReadDenied` without running the handler. Native hosts need no policy middleware or guard Layer. Real HTTP stories exercise both hosts with allowed and denied counted policies; they prove this RPC boundary, not an application’s session or deployment policy. Platform’s application host refuses HTTP `$changes` calls with `WebSocketRequired`; subscriptions use its WebSocket protocol. Subscription delivery and pushed reruns continue to check current access.
|
|
531
|
+
|
|
467
532
|
A query declares its decoded input, result, `readPolicy` and `reads` together. `readPolicy(payload, viewer)` returns an Effect boolean. `viewer` is the session's `Option<{ id: string }>`; the browser does not send the identity. `signedIn` from `readPolicy.ts` allows any signed-in viewer and refuses a signed-out viewer. `QueryReadPolicy<Payload, E, R>` preserves typed failures and required services. Declare policy errors in the query's `rejections`; a failing access check reaches the client as its declared error, including during live reads. Only a successful `false` denies access. [Policy services](#policy-services) explains richer session requirements and where to provide implementations.
|
|
468
533
|
|
|
469
534
|
```ts
|
|
@@ -504,7 +569,7 @@ const AllNotes = query("allNotes", {
|
|
|
504
569
|
|
|
505
570
|
The application supplies the permission checker through `permissionReadPolicy(permission, check)`; `check` receives that permission and the current viewer, and must check the viewer's grant using server services. Its failures and service requirements flow through the query like any other read policy. Supply `SessionUser` with the application's identity middleware. The policy guards both calls and subscriptions, and runs again before changed hints are delivered. `readsCollections` requires this policy at declaration: a `signedIn` or ordinary boolean policy fails TypeScript checking, and building an untyped contract with that declaration throws an error explaining the required permission policy. The server also refuses collection queries changed to an ordinary policy after construction as `QueryReadDenied`. Tenant-facing queries use `notes.bucket.userId(viewerId)` instead.
|
|
506
571
|
|
|
507
|
-
Collection reads reuse the bare repository table key, the same key as `notes.list`, even when the contract uses `keyScope: "session"`;
|
|
572
|
+
Collection reads reuse the bare repository table key, the same key as `notes.list`, even when the contract uses `keyScope: "session"`; record and bucket reads also use plain server keys. They add no wildcard matching or write-side work. Every committed repository insert, update, delete, upsert and bulk write already publishes that key. Generated-id inserts also publish the bare collection key alongside their generated record key, so `publishes` stories that check exact published keys must allow the bare key today. For a table named `notes`, that is `"notes"` alongside `"notes:<id>"` and any affected bucket keys. Mounting a collection subscriber adds **zero PostgreSQL NOTIFY messages per write**: it consumes the existing payloads. It adds a normal query subscription and an authorized reread when the collection changes.
|
|
508
573
|
|
|
509
574
|
For dependencies that need server data, add `serverReads(payload, viewer)`, an Effect returning extra keys. Keep `reads` for keys the browser can derive, or return `[]` there. The server checks every referenced query's policy before it runs any `serverReads`, and resolves it with the owning query handler's services. Declare its failures in the query's `rejections`, as with policy failures. A denied subscription never runs the resolver.
|
|
510
575
|
|
|
@@ -563,9 +628,9 @@ The server provides `NoteOwner`; the shared declaration holds only its browser-s
|
|
|
563
628
|
|
|
564
629
|
A record key, `notes.item(id)`, names one record. A bucket, `notes.bucket.userId(id)`, names every row with that field value. Declare bucket fields on the collection model with their schemas. A list may add title, state or other filters to its input and handler, but those filters never narrow its bucket. It reruns whenever any row in that bucket changes, including a row excluded by the filter. Writers explicitly announce the record and affected buckets with the same constructors from `@shivaedev/changes/keys.ts`.
|
|
565
630
|
|
|
566
|
-
The same query policy guards running the query and subscribing to it. A subscription is meant to carry one query. It names query references, never arbitrary record or bucket keys. If a subscription mixes queries the viewer may and may not read, the entire subscription is refused with `QueryReadDenied`; it delivers no partial set of hints. Every query requires `readPolicy` at declaration, including queries used only through one-off `run` calls. TypeScript rejects a policy-less declaration before handlers or a live server can be built. Platform’s application host validates the complete RPC group while building its Layer, before listening; untyped declarations missing policies fail with `MissingReadPolicies`, whose `queries` and `message` name every affected RPC. Native hosts
|
|
631
|
+
The same query policy guards running the query and subscribing to it. A subscription is meant to carry one query. It names query references, never arbitrary record or bucket keys. If a subscription mixes queries the viewer may and may not read, the entire subscription is refused with `QueryReadDenied`; it delivers no partial set of hints. Every query requires `readPolicy` at declaration, including queries used only through one-off `run` calls. TypeScript rejects a policy-less declaration before handlers or a live server can be built. Platform’s application host validates the complete RPC group while building its Layer, before listening; untyped declarations missing policies fail with `MissingReadPolicies`, whose `queries` and `message` name every affected RPC. Native hosts enforce read policies automatically at request time. `MissingReadPolicy` remains a request-time refusal for untyped declarations served through native servers that bypass that boot check, on plain calls and subscriptions alike. Reads outside a declared query acquire no automatic subscription.
|
|
567
632
|
|
|
568
|
-
|
|
633
|
+
Session middleware supplies `CurrentViewer`; the guard attached to each contract query owns policy evaluation. Custom authentication middleware provides that viewer after validating its session. 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 receives a `QueryReadDenied` delivery while the established subscription stays open. A later authorized hint resumes delivery, including an unchanged pushed value. An initial subscription refusal still fails the stream with `QueryReadDenied`. Custom stream consumers handle the denial delivery alongside `Changed`, `Resync` and `Result`; `SubscriptionHint` from `queryUpdate.ts` types hint consumers. 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.
|
|
569
634
|
|
|
570
635
|
### Policy services
|
|
571
636
|
|
|
@@ -670,18 +735,22 @@ Import the module that defines the name; the package has no root entry.
|
|
|
670
735
|
| `rejection.ts` | `fieldRejection(struct, fields?)`; lower-level `rejectionSet(specs)`, which constructs the rejection classes, union schema and failure helpers used by operations. |
|
|
671
736
|
| `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. |
|
|
672
737
|
| `queryCoalesceWindow.ts` | `queryCoalesceWindow(query)`, a writable atom for a bound query's live changed-hint window. |
|
|
738
|
+
| `clientKeys.ts` | `KeyContext`, `clientReadKeys`, `clientInvalidationKeys`: registry-local cache keys for custom clients. |
|
|
673
739
|
| `live.ts` | `LiveHint` schema; `live(runtime, { stream, resyncKeys, coalesceWindow?, initialResync?, keyContext?, resume?, retryDelay?, retryKeys? })`, exposing `connection`, `coalesceWindow`, `paused` and `status`. |
|
|
674
740
|
| `querySubscription.ts` | `querySubscription(rpc, references, viewer)` checks each referenced query, resolves its payload and server-derived keys, and captures its scopes and ongoing authorization. |
|
|
675
741
|
| `LiveServer.ts` | `LiveServer`, the shared live server service and its `.layer`, requiring `Reactivity`. |
|
|
676
742
|
| `makeLiveServer.ts` | `makeLiveServer`, an Effect requiring `Reactivity` that creates scoped server hint streams and a `resync` Effect. |
|
|
677
|
-
| `readPolicy.ts` | `QueryReadPolicy`, `Viewer`, `signedIn`, `authorizeReads(effect, request, viewer)
|
|
743
|
+
| `readPolicy.ts` | `QueryReadPolicy`, `Viewer`, `signedIn`, `CurrentViewer`; `authorizeReads(effect, request, viewer)` for direct handler reruns outside RPC middleware. |
|
|
744
|
+
| `ReadPolicyGuard.ts` | `ReadPolicyGuard`, the defaulted middleware reference attached to contract queries; `readPolicyGuardLayer({ websocket? })`, an optional override that refuses HTTP `$changes` calls by default. |
|
|
678
745
|
| `validateReadPolicies.ts` | `validateReadPolicies(group)`, an Effect that fails with `MissingReadPolicies` when any served or subscribable query omits its policy. |
|
|
679
746
|
| `readPolicyErrors.ts` | `MissingReadPolicies` (boot), `MissingReadPolicy` (native-server request fallback) and `QueryReadDenied`. |
|
|
747
|
+
| `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. |
|
|
680
748
|
| `serverMetadata.ts` | `KeyScope`, `QueryDefinition.definition`, `CommandInvalidation.invalidates`, `ChangesQueries.queries`, `ChangesQueries.resolve(references)` and `changesRpc(name, queries)` for server adapters. |
|
|
681
749
|
| `queryKeys.ts` | `queryKeys(queries, references, viewer?)` authorizes references and resolves payload and server-derived keys using the provided services. |
|
|
682
750
|
| `QueryServerReads.ts` | `QueryServerReads<Payload, E, R>`, the server-only resolver type. |
|
|
683
751
|
| `resume.ts` | `resumeSignal({ window?, native? })`, returning a native numeric signal atom. |
|
|
684
|
-
| `
|
|
752
|
+
| `querySignals.ts` | `querySignals(query)` exposes completion counts and subscription status as a native atom. |
|
|
753
|
+
| `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. |
|
|
685
754
|
| `testing.ts` | `layerMemoryProtocol(group)` supplies an in-memory native RPC protocol backed by the group’s handlers and middleware; `watchHints(stream)` starts a scoped viewer subscription; `heard(viewer, keys, { within? }?)` waits for matching changed keys. |
|
|
686
755
|
|
|
687
756
|
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.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Effect, Layer } from "effect";
|
|
2
|
+
import { type Rpc, type RpcGroup, RpcMiddleware } from "effect/rpc";
|
|
3
|
+
export type CommandBoundary = <A, E, R>(effect: Effect.Effect<A, E, R>, keys: (result: A) => readonly unknown[]) => Effect.Effect<A, E, R>;
|
|
4
|
+
declare const CommandGuard_base: RpcMiddleware.ServiceClass<CommandGuard, "@shivaedev/contract/CommandGuard", never, import("effect/Schema").Never, never, never, false>;
|
|
5
|
+
export declare class CommandGuard extends CommandGuard_base {
|
|
6
|
+
}
|
|
7
|
+
export declare function commandGuardLayer(boundary: CommandBoundary): Layer.Layer<CommandGuard>;
|
|
8
|
+
export declare function guardCommands<R extends Rpc.Any>(group: RpcGroup.RpcGroup<R>): Effect.Effect<RpcGroup.RpcGroup<Rpc.AddMiddleware<R, typeof CommandGuard>>, never, never>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=CommandGuard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandGuard.d.ts","sourceRoot":"","sources":["../src/CommandGuard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAE,KAAK,EAAU,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAMpE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,SAAS,OAAO,EAAE,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;;AAE3I,qBAAa,YAAa,SAAQ,iBAAyE;CAAG;AAE9G,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,eAAe,GAAG,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAStF;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,6FAE3E"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Option } from "effect";
|
|
2
|
+
import { RpcMiddleware } from "effect/rpc";
|
|
3
|
+
import { invalidationKeys } from "@shivaedev/changes/keys.ts";
|
|
4
|
+
import { prependMiddleware } from "#internal/prependMiddleware.ts";
|
|
5
|
+
import { CurrentViewer } from "#readPolicy.ts";
|
|
6
|
+
import { CommandInvalidation } from "#serverMetadata.ts";
|
|
7
|
+
export class CommandGuard extends RpcMiddleware.Service()("@shivaedev/contract/CommandGuard") {
|
|
8
|
+
}
|
|
9
|
+
export function commandGuardLayer(boundary) {
|
|
10
|
+
return Layer.succeed(CommandGuard, (effect, { rpc, payload }) => {
|
|
11
|
+
const declaration = Context.getOption(rpc.annotations, CommandInvalidation);
|
|
12
|
+
return Option.isNone(declaration)
|
|
13
|
+
? effect
|
|
14
|
+
: Effect.flatMap(CurrentViewer, (viewer) => boundary(effect, (result) => invalidationKeys(declaration.value.invalidates(payload, result, viewer))));
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export function guardCommands(group) {
|
|
18
|
+
return prependMiddleware(group.middleware(CommandGuard), CommandGuard.key);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=CommandGuard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandGuard.js","sourceRoot":"","sources":["../src/CommandGuard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,EAA2B,aAAa,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAIzD,MAAM,OAAO,YAAa,SAAQ,aAAa,CAAC,OAAO,EAAgB,CAAC,kCAAkC,CAAC;CAAG;AAE9G,MAAM,UAAU,iBAAiB,CAAC,QAAyB;IAC1D,OAAO,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;QAC/D,MAAM,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;QAC5E,OAAO,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;YAChC,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CACzC,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CACtG,CAAC;IACL,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aAAa,CAAoB,KAA2B;IAC3E,OAAO,iBAAiB,CAAC,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;AAC5E,CAAC"}
|
package/dist/LiveServer.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
1
|
+
import { Effect, type Stream } from "effect";
|
|
2
2
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
|
-
import type { Key
|
|
3
|
+
import type { Key } from "@shivaedev/changes/keys.ts";
|
|
4
4
|
import type { QueryRerun, QuerySubscription } from "#querySubscription.ts";
|
|
5
|
+
import type { QueryUpdate, SubscriptionHint } from "#queryUpdate.ts";
|
|
6
|
+
import type { QueryReadDenied } from "#readPolicyErrors.ts";
|
|
5
7
|
export declare const LiveServer: import("effect/Context").Service<"@shivaedev/contract/LiveServer", Readonly<{
|
|
6
8
|
readonly resync: () => Effect.Effect<number, never, never>;
|
|
7
|
-
readonly stream: (keys: readonly Key[]
|
|
9
|
+
readonly stream: (keys: readonly Key[]) => Effect.Effect<Stream.Stream<{
|
|
8
10
|
readonly _tag: "Changed";
|
|
9
11
|
readonly keys: readonly ({
|
|
10
12
|
readonly _tag: "Bucket";
|
|
@@ -23,7 +25,7 @@ export declare const LiveServer: import("effect/Context").Service<"@shivaedev/co
|
|
|
23
25
|
} | {
|
|
24
26
|
readonly _tag: "Resync";
|
|
25
27
|
}, never, never>, never, never>;
|
|
26
|
-
readonly subscribe: <E, R>(subscription: QuerySubscription<E, R>,
|
|
28
|
+
readonly subscribe: <E, R, TRead extends QueryRerun<unknown, unknown> | undefined = undefined>(subscription: QuerySubscription<E, R>, read?: (TRead & (QueryRerun<E, R> | undefined)) | undefined) => Effect.Effect<Stream.Stream<TRead extends undefined ? SubscriptionHint : QueryUpdate, E | QueryReadDenied, R>>;
|
|
27
29
|
}>> & {
|
|
28
30
|
readonly layer: import("effect/Layer").Layer<"@shivaedev/contract/LiveServer", never, Reactivity.Reactivity>;
|
|
29
31
|
};
|
package/dist/LiveServer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveServer.d.ts","sourceRoot":"","sources":["../src/LiveServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"LiveServer.d.ts","sourceRoot":"","sources":["../src/LiveServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,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,UAAU;;;;;;;;;;;;;;;;;;;;;yBAIF,CAAC,EAAE,CAAC,EAAE,KAAK,SAAS,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,SAAS,4BAChE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,kEAEnC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,SAAS,SAAS,GAAG,gBAAgB,GAAG,WAAW,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,CAAC,CAAC;;;CAWjH,CAAC"}
|
package/dist/LiveServer.js
CHANGED
|
@@ -6,11 +6,16 @@ import { makeLiveServer } from "#makeLiveServer.ts";
|
|
|
6
6
|
export const LiveServer = defineService({
|
|
7
7
|
id: "@shivaedev/contract/LiveServer",
|
|
8
8
|
initialize: makeLiveServer,
|
|
9
|
-
methods: (server) =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
methods: (server) => {
|
|
10
|
+
function subscribe(subscription, read) {
|
|
11
|
+
return Effect.succeed(read === undefined ? server.subscribe(subscription) : server.subscribe(subscription, read));
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
resync: () => server.resync,
|
|
15
|
+
stream: (keys) => Effect.succeed(server.stream(keys)),
|
|
16
|
+
subscribe: genericMethod(subscribe),
|
|
17
|
+
};
|
|
18
|
+
},
|
|
14
19
|
requires: [Reactivity.Reactivity],
|
|
15
20
|
});
|
|
16
21
|
//# sourceMappingURL=LiveServer.js.map
|
package/dist/LiveServer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveServer.js","sourceRoot":"","sources":["../src/LiveServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"LiveServer.js","sourceRoot":"","sources":["../src/LiveServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAe,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAKpD,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC;IACvC,EAAE,EAAE,gCAAgC;IACpC,UAAU,EAAE,cAAc;IAC1B,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE;QAKnB,SAAS,SAAS,CAAO,YAAqC,EAAE,IAAuB;YACtF,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;QACnH,CAAC;QACD,OAAO;YACN,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM;YAC3B,MAAM,EAAE,CAAC,IAAoB,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACrE,SAAS,EAAE,aAAa,CAAC,SAAS,CAAC;SACnC,CAAC;IACH,CAAC;IACD,QAAQ,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;CACjC,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Schema, type Types } from "effect";
|
|
2
|
+
import { type Rpc } from "effect/rpc";
|
|
3
|
+
import { MissingReadPolicy, QueryReadDenied } from "#readPolicyErrors.ts";
|
|
4
|
+
import { WebSocketRequired } from "#WebSocketRequired.ts";
|
|
5
|
+
declare function readPolicyGuard<A, E, R>(effect: Effect.Effect<A, E, R>, request: {
|
|
6
|
+
readonly rpc: Rpc.Any;
|
|
7
|
+
readonly payload: unknown;
|
|
8
|
+
}): Effect.Effect<A, E | MissingReadPolicy | QueryReadDenied | WebSocketRequired | Types.unhandled, R>;
|
|
9
|
+
export declare const ReadPolicyGuard: Context.Reference<typeof readPolicyGuard> & {
|
|
10
|
+
"~effect/rpc/RpcMiddleware": "~effect/rpc/RpcMiddleware";
|
|
11
|
+
"~ClientError": never;
|
|
12
|
+
error: Schema.Union<readonly [typeof MissingReadPolicy, typeof QueryReadDenied, typeof WebSocketRequired]>;
|
|
13
|
+
requiredForClient: false;
|
|
14
|
+
};
|
|
15
|
+
export declare function readPolicyGuardLayer(options?: {
|
|
16
|
+
readonly websocket?: boolean;
|
|
17
|
+
}): Layer.Layer<never, never, never>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=ReadPolicyGuard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReadPolicyGuard.d.ts","sourceRoot":"","sources":["../src/ReadPolicyGuard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAE,KAAK,GAAG,EAAiB,MAAM,YAAY,CAAC;AAErD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,iBAAS,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC9B,OAAO,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAC3D,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,iBAAiB,GAAG,eAAe,GAAG,iBAAiB,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAEpG;AAMD,eAAO,MAAM,eAAe;;;;;CAK1B,CAAC;AAEH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE;IAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAO,oCAMlF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
2
|
+
import { RpcMiddleware } from "effect/rpc";
|
|
3
|
+
import { authorizeReads, CurrentViewer } from "#readPolicy.ts";
|
|
4
|
+
import { MissingReadPolicy, QueryReadDenied } from "#readPolicyErrors.ts";
|
|
5
|
+
import { WebSocketRequired } from "#WebSocketRequired.ts";
|
|
6
|
+
function readPolicyGuard(effect, request) {
|
|
7
|
+
return Effect.flatMap(CurrentViewer, (viewer) => authorizeReads(effect, request, viewer));
|
|
8
|
+
}
|
|
9
|
+
const middleware = RpcMiddleware.Service()("@shivaedev/contract/ReadPolicyGuard", {
|
|
10
|
+
error: Schema.Union([MissingReadPolicy, QueryReadDenied, WebSocketRequired]),
|
|
11
|
+
});
|
|
12
|
+
export const ReadPolicyGuard = Object.assign(Context.Reference("@shivaedev/contract/ReadPolicyGuard", { defaultValue: () => readPolicyGuard }), {
|
|
13
|
+
[RpcMiddleware.TypeId]: middleware[RpcMiddleware.TypeId],
|
|
14
|
+
"~ClientError": middleware["~ClientError"],
|
|
15
|
+
error: middleware.error,
|
|
16
|
+
requiredForClient: middleware.requiredForClient,
|
|
17
|
+
});
|
|
18
|
+
export function readPolicyGuardLayer(options = {}) {
|
|
19
|
+
return Layer.succeed(ReadPolicyGuard, (effect, request) => !options.websocket && request.rpc._tag.endsWith(".$changes")
|
|
20
|
+
? Effect.fail(new WebSocketRequired({ message: `${request.rpc._tag} needs the WebSocket protocol` }))
|
|
21
|
+
: readPolicyGuard(effect, request));
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=ReadPolicyGuard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReadPolicyGuard.js","sourceRoot":"","sources":["../src/ReadPolicyGuard.ts"],"names":[],"m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O,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;QAC3D,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,iBAAiB,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,+BAA+B,EAAE,CAAC,CAAC;QACrG,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CACnC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { ClientActivityState } from "#clientActivity.ts";
|
|
3
|
+
export declare function activityState(): {
|
|
4
|
+
activity: import("effect/Stream").Stream<ClientActivityState, never, never> & {
|
|
5
|
+
current: Effect.Effect<ClientActivityState, never, never>;
|
|
6
|
+
};
|
|
7
|
+
change: (key: keyof ClientActivityState, delta: number) => void;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=activityState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activityState.d.ts","sourceRoot":"","sources":["../../src/adapters/activityState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmB,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,wBAAgB,aAAa;IAG3B,QAAQ;;;IACR,MAAM,QAAQ,MAAM,mBAAmB,SAAS,MAAM;EAIvD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Effect, SubscriptionRef } from "effect";
|
|
2
|
+
export function activityState() {
|
|
3
|
+
const state = Effect.runSync(SubscriptionRef.make({ liveHints: 0, liveInvalidations: 0, refreshingAtoms: 0, rpcCalls: 0 }));
|
|
4
|
+
return {
|
|
5
|
+
activity: Object.assign(SubscriptionRef.changes(state), { current: SubscriptionRef.get(state) }),
|
|
6
|
+
change: (key, delta) => {
|
|
7
|
+
Effect.runSync(SubscriptionRef.update(state, (current) => ({ ...current, [key]: current[key] + delta })));
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=activityState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activityState.js","sourceRoot":"","sources":["../../src/adapters/activityState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAGjD,MAAM,UAAU,aAAa;IAC5B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAsB,EAAE,SAAS,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACjJ,OAAO;QACN,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAChG,MAAM,EAAE,CAAC,GAA8B,EAAE,KAAa,EAAE,EAAE;YACzD,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QAC3G,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
2
|
-
import type { KeyContext } from "
|
|
2
|
+
import type { KeyContext } from "#clientKeys.ts";
|
|
3
3
|
export interface BindingOwner {
|
|
4
4
|
readonly context: KeyContext;
|
|
5
5
|
readonly registry: AtomRegistry.AtomRegistry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bindingOwner.d.ts","sourceRoot":"","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"bindingOwner.d.ts","sourceRoot":"","sources":["../../src/adapters/bindingOwner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,YAAY,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { clientId } from "./clientId.js";
|
|
1
2
|
const contexts = new WeakMap();
|
|
2
3
|
export function bindingOwner(scope, registry) {
|
|
3
4
|
if (scope === undefined) {
|
|
@@ -8,7 +9,7 @@ export function bindingOwner(scope, registry) {
|
|
|
8
9
|
}
|
|
9
10
|
let context = contexts.get(registry);
|
|
10
11
|
if (context === undefined) {
|
|
11
|
-
context = { scope:
|
|
12
|
+
context = { scope: clientId() };
|
|
12
13
|
contexts.set(registry, context);
|
|
13
14
|
}
|
|
14
15
|
return { context, registry };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bindingOwner.js","sourceRoot":"","sources":["../../src/adapters/bindingOwner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAOzC,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,QAAQ,EAAE,EAAE,CAAC;QAChC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientId.d.ts","sourceRoot":"","sources":["../../src/adapters/clientId.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,IAAI,MAAM,CAEjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientId.js","sourceRoot":"","sources":["../../src/adapters/clientId.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ;IACvB,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;AAC5B,CAAC"}
|
package/dist/automaticLive.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import * as Atom from "effect/reactivity/Atom";
|
|
|
5
5
|
import type * as AtomRpc from "effect/reactivity/AtomRpc";
|
|
6
6
|
import type { Rpc, RpcSchema } from "effect/rpc";
|
|
7
7
|
import type { Key } from "@shivaedev/changes/keys.ts";
|
|
8
|
-
import type { BindingOwner } from "#
|
|
8
|
+
import type { BindingOwner } from "#adapters/bindingOwner.ts";
|
|
9
9
|
import { type LiveStatus } from "#live.ts";
|
|
10
10
|
import type { QueryUpdate } from "#queryUpdate.ts";
|
|
11
11
|
import { type ResumeSource, type ResumeWindow } from "#resume.ts";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"automaticLive.d.ts","sourceRoot":"","sources":["../src/automaticLive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAU,KAAK,MAAM,EAAU,MAAM,QAAQ,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,KAAK,OAAO,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"automaticLive.d.ts","sourceRoot":"","sources":["../src/automaticLive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAU,KAAK,MAAM,EAAU,MAAM,QAAQ,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,KAAK,OAAO,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAO9D,OAAO,EAAE,KAAK,UAAU,EAAQ,MAAM,UAAU,CAAC;AAEjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAgB,MAAM,YAAY,CAAC;AAChF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAI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AC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aACnC,cAAc,QACnB,SAAS,GAAG,EAAE,cACR,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,WACjC,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,YACpB,OAAO,CAAC,KAAK;;;;;;;;EA0CxB"}
|
package/dist/automaticLive.js
CHANGED
|
@@ -4,8 +4,10 @@ import { aggregateLiveStatus } from "#internal/aggregateLiveStatus.ts";
|
|
|
4
4
|
import { automaticQuery } from "#internal/automaticQuery.ts";
|
|
5
5
|
import { queryDelivery } from "#internal/queryDelivery.ts";
|
|
6
6
|
import { localQueryKeys, queryHint } from "#internal/queryHints.ts";
|
|
7
|
+
import { queryProgress } from "#internal/querySignals.ts";
|
|
7
8
|
import { socketIdentity } from "#internal/rpcClient.ts";
|
|
8
9
|
import { live } from "#live.ts";
|
|
10
|
+
import { querySignals, shareQuerySignals } from "#querySignals.ts";
|
|
9
11
|
import { resumeSignal } from "#resume.ts";
|
|
10
12
|
export const LiveConnection = Symbol.for("@shivaedev/contract/LiveConnection");
|
|
11
13
|
const pausedByRuntime = Atom.family((_runtime) => Atom.keepAlive(Atom.make(false)));
|
|
@@ -28,10 +30,11 @@ export function automaticLive(service, name, owner, resume, enabled = true, resu
|
|
|
28
30
|
}).pipe(Atom.setIdleTTL(0));
|
|
29
31
|
function query(atom, reference, keys, equivalent, decode, headers) {
|
|
30
32
|
if (!enabled) {
|
|
31
|
-
return atom;
|
|
33
|
+
return queryProgress(atom);
|
|
32
34
|
}
|
|
33
35
|
const ready = Atom.make(false);
|
|
34
|
-
const
|
|
36
|
+
const signals = querySignals(atom);
|
|
37
|
+
const delivery = queryDelivery(atom, decode, paused, signals);
|
|
35
38
|
const source = decode === undefined ? delivery.atom.pipe(Atom.setIdleTTL(0)) : delivery.atom;
|
|
36
39
|
const subscription = live(service.runtime, {
|
|
37
40
|
initialResync: false,
|
|
@@ -50,10 +53,12 @@ export function automaticLive(service, name, owner, resume, enabled = true, resu
|
|
|
50
53
|
pushed: decode !== undefined,
|
|
51
54
|
ready,
|
|
52
55
|
signal,
|
|
56
|
+
signals,
|
|
53
57
|
source,
|
|
54
58
|
statuses,
|
|
55
59
|
subscription,
|
|
56
60
|
});
|
|
61
|
+
shareQuerySignals(gated, atom);
|
|
57
62
|
Object.assign(gated, { initialValueTarget: atom });
|
|
58
63
|
if (Atom.isSerializable(atom)) {
|
|
59
64
|
Object.assign(gated, { [Atom.SerializableTypeId]: atom[Atom.SerializableTypeId] });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"automaticLive.js","sourceRoot":"","sources":["../src/automaticLive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAe,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGpE,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"automaticLive.js","sourceRoot":"","sources":["../src/automaticLive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAe,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGpE,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAK/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAmB,IAAI,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAEnE,OAAO,EAAwC,YAA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