@shivaedev/react 0.38.1 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +101 -1
  3. package/dist/client/QueryView.js +1 -1
  4. package/dist/client/QueryView.js.map +1 -1
  5. package/dist/client/adapters/crypto.d.ts +3 -0
  6. package/dist/client/adapters/crypto.d.ts.map +1 -0
  7. package/dist/client/adapters/crypto.js +9 -0
  8. package/dist/client/adapters/crypto.js.map +1 -0
  9. package/dist/client/adapters/handlerRuntime.d.ts +3 -0
  10. package/dist/client/adapters/handlerRuntime.d.ts.map +1 -0
  11. package/dist/client/adapters/handlerRuntime.js +4 -0
  12. package/dist/client/adapters/handlerRuntime.js.map +1 -0
  13. package/dist/client/adapters/useClock.d.ts +5 -0
  14. package/dist/client/adapters/useClock.d.ts.map +1 -0
  15. package/dist/client/adapters/useClock.js +9 -0
  16. package/dist/client/adapters/useClock.js.map +1 -0
  17. package/dist/client/adapters/useConnectionStatus.d.ts +3 -0
  18. package/dist/client/adapters/useConnectionStatus.d.ts.map +1 -0
  19. package/dist/client/adapters/useConnectionStatus.js +6 -0
  20. package/dist/client/adapters/useConnectionStatus.js.map +1 -0
  21. package/dist/client/adapters/useDeployUpdate.d.ts +10 -0
  22. package/dist/client/adapters/useDeployUpdate.d.ts.map +1 -0
  23. package/dist/client/adapters/useDeployUpdate.js +18 -0
  24. package/dist/client/adapters/useDeployUpdate.js.map +1 -0
  25. package/dist/client/adapters/useNewId.d.ts +5 -0
  26. package/dist/client/adapters/useNewId.d.ts.map +1 -0
  27. package/dist/client/adapters/useNewId.js +9 -0
  28. package/dist/client/adapters/useNewId.js.map +1 -0
  29. package/dist/client/adapters/usePromiseAction.d.ts +7 -0
  30. package/dist/client/adapters/usePromiseAction.d.ts.map +1 -0
  31. package/dist/client/adapters/usePromiseAction.js +16 -0
  32. package/dist/client/adapters/usePromiseAction.js.map +1 -0
  33. package/dist/client/adapters/useUndoableChange.d.ts +31 -0
  34. package/dist/client/adapters/useUndoableChange.d.ts.map +1 -0
  35. package/dist/client/adapters/useUndoableChange.js +48 -0
  36. package/dist/client/adapters/useUndoableChange.js.map +1 -0
  37. package/dist/client/deployUpdate.d.ts +20 -0
  38. package/dist/client/deployUpdate.d.ts.map +1 -0
  39. package/dist/client/deployUpdate.js +53 -0
  40. package/dist/client/deployUpdate.js.map +1 -0
  41. package/dist/client/pageHidden.d.ts +3 -0
  42. package/dist/client/pageHidden.d.ts.map +1 -0
  43. package/dist/client/pageHidden.js +13 -0
  44. package/dist/client/pageHidden.js.map +1 -0
  45. package/dist/client/resultState.d.ts +3 -0
  46. package/dist/client/resultState.d.ts.map +1 -1
  47. package/dist/client/resultState.js +1 -0
  48. package/dist/client/resultState.js.map +1 -1
  49. package/dist/internal/loadedQuery.d.ts +6 -0
  50. package/dist/internal/loadedQuery.d.ts.map +1 -1
  51. package/dist/internal/loadedQuery.js +1 -0
  52. package/dist/internal/loadedQuery.js.map +1 -1
  53. package/package.json +17 -17
  54. package/src/client/QueryView.ts +1 -1
  55. package/src/client/adapters/crypto.ts +14 -0
  56. package/src/client/adapters/handlerRuntime.ts +4 -0
  57. package/src/client/adapters/useClock.ts +11 -0
  58. package/src/client/adapters/useConnectionStatus.ts +6 -0
  59. package/src/client/adapters/useDeployUpdate.ts +20 -0
  60. package/src/client/adapters/useNewId.ts +11 -0
  61. package/src/client/adapters/usePromiseAction.ts +25 -0
  62. package/src/client/adapters/useUndoableChange.ts +82 -0
  63. package/src/client/deployUpdate.ts +69 -0
  64. package/src/client/pageHidden.ts +13 -0
  65. package/src/client/resultState.ts +7 -0
  66. package/src/internal/loadedQuery.ts +2 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.40.0 - 2026-11-04
4
+
5
+ ### Added
6
+
7
+ - Activate staged updates while hidden once registered blockers release, and expose an application-owned reload action when activation is unavailable or blocked.
8
+ - Provide `useNewId` and `useClock` callbacks backed by atom runtime Crypto and Clock services, plus a Web Crypto client layer.
9
+ - Add `usePromiseAction` to dispatch promise calls with native action state, `UnknownError` failures by default and an optional typed rejection mapper.
10
+
11
+ ### Breaking
12
+
13
+ - TypeScript source exports now use `@shivaedev/source` instead of `source`. Replace `source` with `@shivaedev/source` in Node `--conditions`, TypeScript `customConditions`, and Vite/Vitest `resolve.conditions`. Bare `source` selects built JavaScript; no compatibility alias is provided.
14
+
15
+ ## 0.39.0 - 2026-11-04
16
+
17
+ ### Added
18
+
19
+ - `useConnectionStatus(client)` exposes one debounced `live | reconnecting` status across every binding on a client.
20
+ - Query state exposes `refusal` separately from RPC transport failures, keeping retained data available during socket recovery. `QueryView` reports refusals through its failure slot while keeping transport causes available on the query.
21
+
22
+ ### Fixed
23
+
24
+ - Session boundaries mount nested live bindings and apply the session coalescing window to them.
25
+
26
+ ### Breaking
27
+
28
+ - `QueryView` calls its failure renderer only for refusals. Read `query.cause` for transport diagnostics and use the client connection status for a shared reconnecting notice.
29
+
3
30
  ## 0.38.1 - 2026-11-04
4
31
 
5
32
  ### Changed
package/README.md CHANGED
@@ -24,10 +24,12 @@ const editor = useEditor({
24
24
 
25
25
  State belongs to an **atom in a registry**. A query hook reads that atom's native `AsyncResult`; an action hook reads and dispatches a native action atom. Two readers of the same query share its execution. Changing the query atom resets displayed data by default. An application can use `useQuery(atom, { keepPreviousData: true })` to keep the last successful value while a changed payload loads or fails. This retained display belongs to the hook and clears when its registry changes; native atoms still own execution and caching. Editors keep the default reset so a new record starts a new form.
26
26
 
27
- `useQuery` and `useAction` turn native results into `data`, `cause`, `pending` and `refreshing`. A query's same-identity refresh always keeps the last successful value, including after a typed failure, so a component can show data and an error together. An action uses the native result's retained success. Keep the atom's identity stable for the same work: declare it outside render or use the native family's identity, such as `AtomRpc.Service.query(...)`.
27
+ `useQuery` and `useAction` turn native results into `data`, `cause`, `pending` and `refreshing`. Queries also expose `refusal`, the typed error excluding RPC transport failures; use it for per-query error text during a connection interruption. `cause` and `result` retain the native transport failure for diagnostics. `QueryView` renders its failure slot for refusals and throws defects, while retained data stays visible during transport recovery. A query's same-identity refresh always keeps the last successful value, including after a typed failure, so a component can show data and an error together. An action uses the native result's retained success. Keep the atom's identity stable for the same work: declare it outside render or use the native family's identity, such as `AtomRpc.Service.query(...)`.
28
28
 
29
29
  An **editor** joins a query atom, a form field schema and a save Effect. The query provides the row; `values(row)` converts it to input values; the schema decodes those values before the save runs. form owns the draft and the per-field merge. A **create form** uses the same submission rules without a query and starts a fresh form after success.
30
30
 
31
+ Use `useConnectionStatus(client)` from `@shivaedev/react/client/adapters/useConnectionStatus.ts` with the client returned by contract's `makeClient`. It returns one `"live" | "reconnecting"` value across mounted queries from every binding on that client's `Client` service. Status changes debounce for 300 ms on the client runtime's Clock. A query refusal is separate from connectivity. Visible browser `online` and `visibilitychange` signals interrupt the live retry delay and reconnect immediately with a fresh backoff schedule.
32
+
31
33
  A **session generation** is the string returned by `identify(session)`. `SessionBoundary` owns its client, registry and React subtree. Your auth owner supplies the session and decides when to replace or end it. The boundary automatically mounts live connections on bound contract APIs returned by `connect`, directly or as client properties such as `api`. Use a Platform database host and the default shared WebSocket client; the application needs no subscribe handler or `live()` call. Live changed hints coalesce over 20 ms by default. Set `liveCoalesceWindow` on `SessionBoundary` to a native Duration to choose the window for that session, or `0` for immediate per-hint refreshes. A bound query can override that default with `useQuery(atom, { coalesceWindow: "2 seconds" })`. Changing this option applies to subsequent windows without reconnecting or refetching any query; a window already started keeps its deadline. A refetch in flight runs once more after settling when further hints arrive. Cache policy, RPC declarations and transport stay with native Effect and the application; this package supplies their React state and lifecycle boundary.
32
34
 
33
35
  `useEditor` and `useCreate` opt into persisted input with `persistedDraft: { key, ...persistence }`. Choose a stable key for the record or create request, independent of its server revision. Acquire `persistence` with `draftPersistence` from `@shivaedev/form/adapters/draftPersistence.ts`, provided with `browserDraftStorage` from `@shivaedev/form/adapters/browserDraftStorage.ts`. The setup reads the storage provider and Clock from the Effect environment; timestamps and expiry use that captured clock. The hooks inherit ownership from `SessionBoundary`: reload and query refresh preserve edits, successful submission clears accepted input, and a committed session replacement drops tracked drafts. A suspended replacement that is canceled keeps the visible session's draft and future writes. Later edits made during a save remain persisted. Observed draft storage shares changes across editors while preserving locally edited fields; a completed older save cannot clear a newer stored draft. Supply `DraftStorageProvider` for custom storage; optional `maxBytes` and `maxAgeMs` customize the bounds, which default to 256 KiB of UTF-8 JSON and seven days. See [form's persisted input API](https://github.com/ShivaeDev/platform/tree/main/packages/form#persist-input-across-reloads) for direct form hooks and limits.
@@ -145,6 +147,33 @@ const connect = () => bind(Notes, Client, { resume });
145
147
 
146
148
  `Notes` and `Client` are the application's contract and native AtomRpc client. The application implements `onAppResume` and `onNetworkReturn`, each returning its unsubscribe function. `SessionBoundary` mounts the bound connection, and native notifications reopen the subscription and reconcile its tracked queries alongside the browser visibility and online defaults. Disposing the session's registry releases the native listeners. Omitting `resume` keeps the browser defaults.
147
149
 
150
+ #### Detect a deployment and activate a staged update
151
+
152
+ Configure the host's `config.buildVersion` with the deployed build ID and embed that same ID in the browser bundle. Create one `deployUpdate` from `@shivaedev/react/client/deployUpdate.ts` per registry owner. Pass the same connection options as the application's contract clients so version announcements share their live socket. `useDeployUpdate` from `@shivaedev/react/client/adapters/useDeployUpdate.ts` mounts the controller and exposes `version`, `available`, `blocked`, the native `activation` result and `reload`.
153
+
154
+ ```tsx
155
+ import { Effect } from "effect";
156
+ import { deployUpdate } from "@shivaedev/react/client/deployUpdate.ts";
157
+ import { useDeployUpdate, useUpdateBlocker } from "@shivaedev/react/client/adapters/useDeployUpdate.ts";
158
+
159
+ const update = deployUpdate({
160
+ url: `${location.origin}/rpc`,
161
+ loadedVersion: BUILD_VERSION,
162
+ activate: Effect.promise(() => stagedUpdate.activate()),
163
+ reload: () => location.reload(),
164
+ });
165
+
166
+ function UpdateNotice({ saving, sheetOpen }: { saving: boolean; sheetOpen: boolean }) {
167
+ useUpdateBlocker(update, saving || sheetOpen);
168
+ const state = useDeployUpdate(update);
169
+ return state.available ? <button onClick={state.reload}>Reload application</button> : null;
170
+ }
171
+ ```
172
+
173
+ `BUILD_VERSION` and `stagedUpdate` are supplied by the application. Build IDs are opaque strings: a differing host ID means the loaded bundle has been superseded, including after a rollback. A host restart announces its ID through RPC after reconnect; there is no health polling. While visible or blocked, the controller leaves activation to the reload action. When hidden with no registered blockers, it runs the application's activation Effect once for that version. A successful activation clears `available`; a typed activation failure keeps reload available. Omit `activate` when the application has no staged-update mechanism; reload stays available even while hidden. UI wording and confirmation belong to the application.
174
+
175
+ Each `useUpdateBlocker(update, true)` holds its own blocker until it becomes false or unmounts. Code outside React can run `update.block` with the same `AtomRegistry` service; it returns a release function. Hold it around pending work and call that function when the work ends. All blockers must release before hidden activation proceeds.
176
+
148
177
  #### Mount the notice host
149
178
 
150
179
  Mount the optional `NoticeHost` from `@shivaedev/react/notices.ts` inside `SessionBoundary`, above the screens. The host owns a native atom collection, dismissal, expiry and each notice action's native `AsyncResult`. Supply `render(notice)` to choose markup, wording for action outcomes and labels. Render `notice.action.run` as a button handler and disable that control with `notice.action.pending`; `notice.dismiss` removes the entry. No command requires a host. Expiry sleeps on the `Clock` of the optional `runtime` prop, an atom runtime such as `client.runtime`; without it, the host uses Effect's default clock. A story can pass a runtime built with `Layer.succeed(Clock.Clock, clock)` and drive expiry with `TestClock.adjust`.
@@ -535,6 +564,42 @@ A newer dispatch interrupts the earlier command by default. Interrupted work pro
535
564
 
536
565
  A typed `Unauthorized` failure asks the session owner to recheck once per failed invocation, even with concurrent commands. The hook does not sign out. Session replacement discards outgoing callbacks and rechecks, including when outgoing work cannot be interrupted.
537
566
 
567
+ #### Remove with a version-guarded Undo
568
+
569
+ Use `useUndoableChange` from `@shivaedev/react/client/adapters/useUndoableChange.ts` when a versioned command also performs its inverse. Its payload includes `expectedVersion: number`, and its success includes `version: number`. Supply the bound command's `run`, its native `runtime`, and the application's `deployUpdate` as `update`:
570
+
571
+ ```tsx
572
+ import { Option } from "effect";
573
+ import { useUndoableChange } from "@shivaedev/react/client/adapters/useUndoableChange.ts";
574
+
575
+ function RemoveNote({ note }: { readonly note: { id: string; version: number } }) {
576
+ const change = useUndoableChange({ ...api.change, runtime: NotesClient.runtime, update }, { describe: (saved) => `Removed ${saved.id}` });
577
+ const notice = Option.getOrUndefined(change.notice);
578
+ return (
579
+ <>
580
+ <button
581
+ disabled={change.pending}
582
+ onClick={() => change.remove({ id: note.id, expectedVersion: note.version, removed: true }, { id: note.id, removed: false })}
583
+ >
584
+ Remove
585
+ </button>
586
+ {notice && (
587
+ <p>
588
+ {notice.message}
589
+ <button disabled={change.undoing} onClick={change.undo}>
590
+ Undo
591
+ </button>
592
+ </p>
593
+ )}
594
+ </>
595
+ );
596
+ }
597
+ ```
598
+
599
+ `api`, `NotesClient`, the soft-removal payload and `update` belong to the application. `remove(input, inverse)` captures the inverse domain fields. `undo()` sends those fields through the same command with `expectedVersion` set to the successful removal's returned `version`. The server must enforce that version and declare its typed conflict; a later edit then refuses Undo without overwriting the row. `removeResult` and `undoResult` preserve the native `AsyncResult`, including typed failures. Successful Undo clears its notice; a failed Undo leaves it available.
600
+
601
+ `notice` is a native `Option` containing `message`, the submitted `input` and returned `value`. Only the most recently dispatched removal can publish it, even when replies arrive in reverse order. An older Undo cannot clear a newer notice. `removing` and `undoing` describe the two writes, and `pending` includes either. Each invocation holds `update.block` for its whole Effect lifetime, so overlapping writes hold deployment activation until all finish. The hook keeps UI wording and inverse domain data in the app; no `NoticeHost` is needed.
602
+
538
603
  #### Commands with a pending display value
539
604
 
540
605
  Use `usePendingCommand` for a command acting on a query row, such as a list toggle. Give each row a stable action atom with the existing bound command, so the command's declared invalidation keys still drive refetches:
@@ -932,6 +997,41 @@ const minutesAgo = Math.floor((now - savedAt) / 60_000);
932
997
 
933
998
  Without a runtime it uses a native empty atom runtime. Stories supply a runtime with their TestClock service so advancing that clock updates the rendered time.
934
999
 
1000
+ #### Ids, time and promises in callbacks
1001
+
1002
+ `useNewId(runtime?)` from `@shivaedev/react/client/adapters/useNewId.ts` returns a UUIDv4 generator. `useClock(runtime?)` from `@shivaedev/react/client/adapters/useClock.ts` returns a `now()` callback that reads epoch milliseconds when called. Both read services from the supplied atom runtime in the current registry and can be used in state initializers and event handlers:
1003
+
1004
+ ```tsx
1005
+ import { useState } from "react";
1006
+ import { useClock } from "@shivaedev/react/client/adapters/useClock.ts";
1007
+ import { useNewId } from "@shivaedev/react/client/adapters/useNewId.ts";
1008
+
1009
+ const newId = useNewId(client.runtime);
1010
+ const now = useClock(client.runtime);
1011
+ const [id] = useState(newId);
1012
+ const [createdAt] = useState(now);
1013
+ const stamp = () => ({ id: newId(), at: now() });
1014
+ ```
1015
+
1016
+ These lines belong inside a component; `client` is the application's atom client. Stories pass a runtime containing their test Clock and seeded Crypto. The hooks use native atom suspense while the runtime builds. The supplied Crypto's UUID generation must be synchronous. Without a runtime, they use a shared native runtime with Effect's default Clock and `clientCrypto`, a Web Crypto Layer from `@shivaedev/react/client/adapters/crypto.ts`. Provide that Layer to an application's runtime when it needs browser Crypto; it uses `crypto.getRandomValues` and `crypto.subtle.digest`.
1017
+
1018
+ `usePromiseAction(() => promise, options?)` from `@shivaedev/react/client/adapters/usePromiseAction.ts` returns the same state as `useAction`, with `dispatch()` taking no input. It runs the callback on dispatch, keeps its atom across rerenders and calls the latest committed callback. A promise rejection or synchronous throw becomes `Cause.UnknownError` by default. Supply `catch` to map the unknown cause into an application's typed failure:
1019
+
1020
+ ```tsx
1021
+ import { usePromiseAction } from "@shivaedev/react/client/adapters/usePromiseAction.ts";
1022
+
1023
+ const copy = usePromiseAction(() => navigator.clipboard.writeText(text), {
1024
+ catch: (cause) => new ClipboardDenied({ reason: String(cause) }),
1025
+ });
1026
+ const button = (
1027
+ <button disabled={copy.pending} onClick={() => copy.dispatch()}>
1028
+ Copy
1029
+ </button>
1030
+ );
1031
+ ```
1032
+
1033
+ These lines belong inside a component; `text` and `ClipboardDenied` belong to the application. Read the success from `copy.data` and the typed failure from `copy.cause` or `copy.result`. The helper runs through a native action atom and adds no promise cancellation adapter.
1034
+
935
1035
  #### Render tests in happy-dom
936
1036
 
937
1037
  Use `@shivaedev/test-story/client/adapters/react.ts` with Vitest's `happy-dom` environment. Install contract and changes for the example's query, command and key declarations, and the testing peers and environment in your app's dev dependencies:
@@ -6,7 +6,7 @@ export function QueryView({ query, loading, content, failure }) {
6
6
  if (Result.isSuccess(defect)) {
7
7
  throw defect.success;
8
8
  }
9
- return Cause.findErrorOption(cause);
9
+ return query.refusal;
10
10
  });
11
11
  return createElement(Fragment, null, Option.isSome(query.data) ? content(query.data.value, query) : null, query.pending || (Option.isNone(query.data) && Option.isNone(error)) ? loading(query) : null, Option.isSome(error) ? failure(error.value, query) : null);
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"QueryView.js","sourceRoot":"","sources":["../../src/client/QueryView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAUhE,MAAM,UAAU,SAAS,CAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAwB;IACzF,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QACnD,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACvC,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9B,MAAM,MAAM,CAAC,OAAO,CAAC;QACtB,CAAC;QACD,OAAO,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IACH,OAAO,aAAa,CACnB,QAAQ,EACR,IAAI,EACJ,MAAM,CAAC,MAAM,CAAC,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AC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EACnE,KAAK,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAC5F,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CACzD,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Crypto, Layer } from "effect";
2
+ export declare const clientCrypto: Layer.Layer<Crypto.Crypto, never, never>;
3
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,KAAK,EAAiB,MAAM,QAAQ,CAAC;AAE9D,eAAO,MAAM,YAAY,0CAWxB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Crypto, Effect, Layer, PlatformError } from "effect";
2
+ export const clientCrypto = Layer.succeed(Crypto.Crypto, Crypto.make({
3
+ digest: (algorithm, data) => Effect.tryPromise({
4
+ catch: (cause) => PlatformError.systemError({ _tag: "Unknown", cause, description: "Could not compute digest", method: "digest", module: "Crypto" }),
5
+ try: () => globalThis.crypto.subtle.digest(algorithm, new Uint8Array(data)).then((buffer) => new Uint8Array(buffer)),
6
+ }),
7
+ randomBytes: (size) => globalThis.crypto.getRandomValues(new Uint8Array(size)),
8
+ }));
9
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../src/client/adapters/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE9D,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CACxC,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,IAAI,CAAC;IACX,MAAM,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAC3B,MAAM,CAAC,UAAU,CAAC;QACjB,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAChB,aAAa,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,0BAA0B,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;QACnI,GAAG,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;KACpH,CAAC;IACH,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;CAC9E,CAAC,CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import * as Atom from "effect/reactivity/Atom";
2
+ export declare const handlerRuntime: Atom.AtomRuntime<import("effect/Crypto").Crypto, never>;
3
+ //# sourceMappingURL=handlerRuntime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlerRuntime.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/handlerRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAG/C,eAAO,MAAM,cAAc,yDAA6B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import * as Atom from "effect/reactivity/Atom";
2
+ import { clientCrypto } from "#client/adapters/crypto.ts";
3
+ export const handlerRuntime = Atom.runtime(clientCrypto);
4
+ //# sourceMappingURL=handlerRuntime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlerRuntime.js","sourceRoot":"","sources":["../../../src/client/adapters/handlerRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Context } from "effect";
2
+ import type * as AsyncResult from "effect/reactivity/AsyncResult";
3
+ import type * as Atom from "effect/reactivity/Atom";
4
+ export declare function useClock(runtime?: Atom.Atom<AsyncResult.AsyncResult<Context.Context<never>, unknown>>): () => number;
5
+ //# sourceMappingURL=useClock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useClock.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useClock.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,OAAO,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAIpD,wBAAgB,QAAQ,CAAC,OAAO,GAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAkB,GAAG,MAAM,MAAM,CAGpI"}
@@ -0,0 +1,9 @@
1
+ import { useAtomSuspense } from "@effect/atom-react";
2
+ import { Clock, Context } from "effect";
3
+ import { useCallback } from "react";
4
+ import { handlerRuntime } from "#client/adapters/handlerRuntime.ts";
5
+ export function useClock(runtime = handlerRuntime) {
6
+ const clock = Context.get(useAtomSuspense(runtime).value, Clock.Clock);
7
+ return useCallback(() => clock.currentTimeMillisUnsafe(), [clock]);
8
+ }
9
+ //# sourceMappingURL=useClock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useClock.js","sourceRoot":"","sources":["../../../src/client/adapters/useClock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGxC,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,MAAM,UAAU,QAAQ,CAAC,OAAO,GAAwE,cAAc;IACrH,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,WAAW,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,uBAAuB,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AACpE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type ActiveClient, type ConnectionStatus } from "@shivaedev/contract/clientActivity.ts";
2
+ export declare function useConnectionStatus(client: ActiveClient): ConnectionStatus;
3
+ //# sourceMappingURL=useConnectionStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConnectionStatus.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useConnectionStatus.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAkB,MAAM,uCAAuC,CAAC;AAEjH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,gBAAgB,CAE1E"}
@@ -0,0 +1,6 @@
1
+ import { useAtomValue } from "@effect/atom-react";
2
+ import { clientActivity } from "@shivaedev/contract/clientActivity.ts";
3
+ export function useConnectionStatus(client) {
4
+ return useAtomValue(clientActivity(client).connectionStatus);
5
+ }
6
+ //# sourceMappingURL=useConnectionStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConnectionStatus.js","sourceRoot":"","sources":["../../../src/client/adapters/useConnectionStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAA4C,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAEjH,MAAM,UAAU,mBAAmB,CAAC,MAAoB;IACvD,OAAO,YAAY,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,gBAAgB,CAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { deployUpdate } from "#client/deployUpdate.ts";
2
+ export declare function useDeployUpdate<E>(update: ReturnType<typeof deployUpdate<E>>): {
3
+ available: boolean;
4
+ blocked: boolean;
5
+ version: string | undefined;
6
+ activation: import("effect/reactivity/AsyncResult").AsyncResult<void, E>;
7
+ reload: () => void;
8
+ };
9
+ export declare function useUpdateBlocker<E>(update: ReturnType<typeof deployUpdate<E>>, blocked: boolean): void;
10
+ //# sourceMappingURL=useDeployUpdate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDeployUpdate.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useDeployUpdate.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE5D,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC;;;;;;EAG5E;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAQtG"}
@@ -0,0 +1,18 @@
1
+ import { RegistryContext, useAtomMount, useAtomValue } from "@effect/atom-react";
2
+ import { Effect } from "effect";
3
+ import * as AtomRegistry from "effect/reactivity/AtomRegistry";
4
+ import { useContext, useEffect } from "react";
5
+ export function useDeployUpdate(update) {
6
+ useAtomMount(update.controller);
7
+ return { ...useAtomValue(update.state), activation: useAtomValue(update.activation), reload: update.reload };
8
+ }
9
+ export function useUpdateBlocker(update, blocked) {
10
+ const registry = useContext(RegistryContext);
11
+ useEffect(() => {
12
+ if (blocked) {
13
+ return Effect.runSync(update.block.pipe(Effect.provideService(AtomRegistry.AtomRegistry, registry)));
14
+ }
15
+ return undefined;
16
+ }, [blocked, registry, update]);
17
+ }
18
+ //# sourceMappingURL=useDeployUpdate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDeployUpdate.js","sourceRoot":"","sources":["../../../src/client/adapters/useDeployUpdate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAG9C,MAAM,UAAU,eAAe,CAAI,MAA0C;IAC5E,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAChC,OAAO,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;AAC9G,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAI,MAA0C,EAAE,OAAgB;IAC/F,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAC7C,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,OAAO,EAAE,CAAC;YACb,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;QACtG,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Context, Crypto } from "effect";
2
+ import type * as AsyncResult from "effect/reactivity/AsyncResult";
3
+ import type * as Atom from "effect/reactivity/Atom";
4
+ export declare function useNewId(runtime?: Atom.Atom<AsyncResult.AsyncResult<Context.Context<Crypto.Crypto>, unknown>>): () => string;
5
+ //# sourceMappingURL=useNewId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNewId.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useNewId.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAIpD,wBAAgB,QAAQ,CAAC,OAAO,GAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAkB,GAAG,MAAM,MAAM,CAG5I"}
@@ -0,0 +1,9 @@
1
+ import { useAtomSuspense } from "@effect/atom-react";
2
+ import { Context, Crypto, Effect } from "effect";
3
+ import { useCallback } from "react";
4
+ import { handlerRuntime } from "#client/adapters/handlerRuntime.ts";
5
+ export function useNewId(runtime = handlerRuntime) {
6
+ const crypto = Context.get(useAtomSuspense(runtime).value, Crypto.Crypto);
7
+ return useCallback(() => Effect.runSync(crypto.randomUUIDv4()), [crypto]);
8
+ }
9
+ //# sourceMappingURL=useNewId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNewId.js","sourceRoot":"","sources":["../../../src/client/adapters/useNewId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGjD,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,MAAM,UAAU,QAAQ,CAAC,OAAO,GAAgF,cAAc;IAC7H,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC1E,OAAO,WAAW,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Cause } from "effect";
2
+ import { type ActionState } from "#client/resultState.ts";
3
+ export declare function usePromiseAction<A>(run: () => PromiseLike<A>): ActionState<void, A, Cause.UnknownError>;
4
+ export declare function usePromiseAction<A, E>(run: () => PromiseLike<A>, options: {
5
+ readonly catch: (cause: unknown) => E;
6
+ }): ActionState<void, A, E>;
7
+ //# sourceMappingURL=usePromiseAction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePromiseAction.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/usePromiseAction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAU,MAAM,QAAQ,CAAC;AAGvC,OAAO,EAAE,KAAK,WAAW,EAAa,MAAM,wBAAwB,CAAC;AAErE,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;AACzG,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,CAAA;CAAE,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { Cause, Effect } from "effect";
2
+ import * as Atom from "effect/reactivity/Atom";
3
+ import { useInsertionEffect, useRef, useState } from "react";
4
+ import { useAction } from "#client/resultState.ts";
5
+ export function usePromiseAction(run, options) {
6
+ const latestRef = useRef({ reject: options?.catch, run });
7
+ useInsertionEffect(() => {
8
+ latestRef.current = { reject: options?.catch, run };
9
+ }, [run, options?.catch]);
10
+ const [atom] = useState(() => Atom.fn()(() => Effect.tryPromise({
11
+ catch: (cause) => (latestRef.current.reject ? latestRef.current.reject(cause) : new Cause.UnknownError(cause)),
12
+ try: () => latestRef.current.run(),
13
+ })));
14
+ return useAction(atom);
15
+ }
16
+ //# sourceMappingURL=usePromiseAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePromiseAction.js","sourceRoot":"","sources":["../../../src/client/adapters/usePromiseAction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAoB,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAIrE,MAAM,UAAU,gBAAgB,CAC/B,GAAyB,EACzB,OAAmD;IAEnD,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1D,kBAAkB,CAAC,GAAG,EAAE;QACvB,SAAS,CAAC,OAAO,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;IACrD,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IAC1B,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAC5B,IAAI,CAAC,EAAE,EAAQ,CAAC,GAAG,EAAE,CACpB,MAAM,CAAC,UAAU,CAAC;QACjB,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAC9G,GAAG,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE;KAClC,CAAC,CACF,CACD,CAAC;IACF,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { Effect, Option } from "effect";
2
+ import * as Atom from "effect/reactivity/Atom";
3
+ import type { AtomServices } from "#AtomServices.ts";
4
+ import type { deployUpdate } from "#client/deployUpdate.ts";
5
+ export interface VersionedChangeCommand<TInput, A, E, R, TRuntimeError> {
6
+ readonly run: (input: TInput) => Effect.Effect<A, E, AtomServices<R>>;
7
+ readonly runtime: Atom.AtomRuntime<R, TRuntimeError>;
8
+ readonly update: Pick<ReturnType<typeof deployUpdate>, "block">;
9
+ }
10
+ export interface UndoableNotice<TInput, A> {
11
+ readonly input: TInput;
12
+ readonly message: string;
13
+ readonly value: A;
14
+ }
15
+ export declare function useUndoableChange<TInput extends {
16
+ readonly expectedVersion: number;
17
+ }, A extends {
18
+ readonly version: number;
19
+ }, E, R, TRuntimeError>(command: VersionedChangeCommand<TInput, A, E, R, TRuntimeError>, options: {
20
+ readonly describe: (value: NoInfer<A>, input: NoInfer<TInput>) => string;
21
+ }): {
22
+ notice: Option.Option<UndoableNotice<TInput, A>>;
23
+ pending: boolean;
24
+ remove: (input: TInput, inverse: Omit<TInput, "expectedVersion">) => void;
25
+ removeResult: import("effect/reactivity/AsyncResult").AsyncResult<A, E | TRuntimeError>;
26
+ removing: boolean;
27
+ undo: () => void;
28
+ undoing: boolean;
29
+ undoResult: import("effect/reactivity/AsyncResult").AsyncResult<A, E | TRuntimeError>;
30
+ };
31
+ //# sourceMappingURL=useUndoableChange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUndoableChange.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useUndoableChange.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAG5D,MAAM,WAAW,sBAAsB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa;IACrE,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IACtE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC;IACrD,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,OAAO,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC;CAChE;AAED,MAAM,WAAW,cAAc,CAAC,MAAM,EAAE,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CAClB;AAED,wBAAgB,iBAAiB,CAAC,MAAM,SAAS;IAAE,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,SAAS;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,EACjJ,OAAO,EAAE,sBAAsB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,EAC/D,OAAO,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,MAAM,CAAA;CAAE;;;oBA4CpE,MAAM,WAAW,IAAI,CAAC,MAAM,EAAE,iBAAiB,CAAC;;;;;;EAejE"}
@@ -0,0 +1,48 @@
1
+ import { RegistryContext, useAtomValue } from "@effect/atom-react";
2
+ import { Effect, Option } from "effect";
3
+ import * as Atom from "effect/reactivity/Atom";
4
+ import { useContext, useMemo } from "react";
5
+ import { useAction } from "#client/resultState.ts";
6
+ export function useUndoableChange(command, options) {
7
+ const { run, runtime, update } = command;
8
+ const registry = useContext(RegistryContext);
9
+ const owner = useMemo(() => ({ notice: Atom.make(Option.none()), registry, run, runtime, sequence: 0, update }), [run, runtime, update, registry]);
10
+ const execute = useMemo(() => (input) => Effect.acquireUseRelease(owner.update.block, () => owner.run(input), (release) => Effect.sync(release)), [owner]);
11
+ const removeRun = useMemo(() => (request) => execute(request.input), [execute]);
12
+ const undoRun = useMemo(() => (entry) => execute({ ...entry.input, ...entry.inverse, expectedVersion: entry.value.version }), [execute]);
13
+ const removal = useAction(owner.runtime, removeRun, {
14
+ concurrent: true,
15
+ onSuccess: (value, { input, inverse, sequence }) => {
16
+ if (sequence === owner.sequence) {
17
+ owner.registry.set(owner.notice, Option.some({ input, inverse, message: options.describe(value, input), value }));
18
+ }
19
+ },
20
+ });
21
+ const restoration = useAction(owner.runtime, undoRun, {
22
+ onSuccess: (_value, entry) => {
23
+ if (Option.getOrUndefined(owner.registry.get(owner.notice)) === entry) {
24
+ owner.registry.set(owner.notice, Option.none());
25
+ }
26
+ },
27
+ });
28
+ const notice = useAtomValue(owner.notice);
29
+ return {
30
+ notice,
31
+ pending: removal.pending || restoration.pending,
32
+ remove: (input, inverse) => {
33
+ owner.sequence += 1;
34
+ removal.dispatch({ input, inverse, sequence: owner.sequence });
35
+ },
36
+ removeResult: removal.result,
37
+ removing: removal.pending,
38
+ undo: () => {
39
+ const current = owner.registry.get(owner.notice);
40
+ if (Option.isSome(current)) {
41
+ restoration.dispatch(current.value);
42
+ }
43
+ },
44
+ undoing: restoration.pending,
45
+ undoResult: restoration.result,
46
+ };
47
+ }
48
+ //# sourceMappingURL=useUndoableChange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUndoableChange.js","sourceRoot":"","sources":["../../../src/client/adapters/useUndoableChange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAG5C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAcnD,MAAM,UAAU,iBAAiB,CAChC,OAA+D,EAC/D,OAAqF;IAErF,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IACzC,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAO7C,MAAM,KAAK,GAAG,OAAO,CACpB,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAS,CAAC,EAAE,Q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C;YACrC,CAAC;QACF,CAAC;QACD,OAAO,EAAE,WAAW,CAAC,OAAO;QAC5B,UAAU,EAAE,WAAW,CAAC,MAAM;KAC9B,CAAC;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { Effect } from "effect";
2
+ import * as Atom from "effect/reactivity/Atom";
3
+ import * as AtomRegistry from "effect/reactivity/AtomRegistry";
4
+ import type { ClientOptions } from "@shivaedev/contract/clientOptions.ts";
5
+ export declare function deployUpdate<E = never>(options: ClientOptions & {
6
+ readonly loadedVersion: string;
7
+ readonly activate?: Effect.Effect<void, E>;
8
+ readonly reload: () => void;
9
+ }): {
10
+ activation: Atom.AtomResultFn<string, void, E>;
11
+ block: Effect.Effect<() => void, never, AtomRegistry.AtomRegistry>;
12
+ controller: Atom.Atom<undefined>;
13
+ reload: () => void;
14
+ state: Atom.Atom<{
15
+ available: boolean;
16
+ blocked: boolean;
17
+ version: string | undefined;
18
+ }>;
19
+ };
20
+ //# sourceMappingURL=deployUpdate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deployUpdate.d.ts","sourceRoot":"","sources":["../../src/client/deployUpdate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoB,MAAM,QAAQ,CAAC;AAClD,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAE/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAI1E,wBAAgB,YAAY,CAAC,CAAC,GAAG,KAAK,EACrC,OAAO,EAAE,aAAa,GAAG;IACxB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC;CAC5B;;;;kBADuB,IAAI;;;;;;EAwD5B"}
@@ -0,0 +1,53 @@
1
+ import { Effect, Schedule, Stream } from "effect";
2
+ import * as Atom from "effect/reactivity/Atom";
3
+ import * as AtomRegistry from "effect/reactivity/AtomRegistry";
4
+ import { makeClient } from "@shivaedev/contract/bind.ts";
5
+ import { HostVersion } from "@shivaedev/contract/HostVersion.ts";
6
+ import { pageHidden } from "./pageHidden.js";
7
+ export function deployUpdate(options) {
8
+ const client = makeClient(HostVersion, options);
9
+ const version = Atom.make(undefined);
10
+ const activated = Atom.make(undefined);
11
+ const blockers = Atom.make(new Set());
12
+ const activation = client.runtime.fn((next, get) => (options.activate ?? Effect.void).pipe(Effect.tap(() => Effect.sync(() => get.set(activated, next)))));
13
+ const connection = client.runtime.atom((get) => client.api.watch.run().pipe(Stream.retry(Schedule.spaced("500 millis")), Stream.runForEach((next) => Effect.sync(() => get.set(version, next)))));
14
+ const state = Atom.make((get) => {
15
+ get.mount(connection);
16
+ get.mount(activation);
17
+ const next = get(version);
18
+ return {
19
+ available: next !== undefined && next !== options.loadedVersion && next !== get(activated),
20
+ blocked: get(blockers).size > 0,
21
+ version: next,
22
+ };
23
+ });
24
+ const controller = Atom.make((get) => {
25
+ get.mount(state);
26
+ get.mount(pageHidden);
27
+ let activating;
28
+ function check() {
29
+ const current = get.once(state);
30
+ if (options.activate !== undefined
31
+ && current.available
32
+ && !current.blocked
33
+ && get.once(pageHidden)
34
+ && current.version !== undefined
35
+ && current.version !== activating) {
36
+ activating = current.version;
37
+ get.set(activation, current.version);
38
+ }
39
+ }
40
+ get.subscribe(state, check);
41
+ get.subscribe(pageHidden, check);
42
+ check();
43
+ return undefined;
44
+ }).pipe(Atom.setIdleTTL(0));
45
+ const block = Effect.gen(function* () {
46
+ const registry = yield* AtomRegistry.AtomRegistry;
47
+ const key = {};
48
+ registry.set(blockers, new Set([...registry.get(blockers), key]));
49
+ return () => registry.set(blockers, new Set([...registry.get(blockers)].filter((entry) => entry !== key)));
50
+ });
51
+ return { activation, block, controller, reload: options.reload, state };
52
+ }
53
+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,0 +1 @@
1
+ {"version":3,"file":"pageHidden.d.ts","sourceRoot":"","sources":["../../src/client/pageHidden.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAE/C,eAAO,MAAM,UAAU,oBAUI,CAAC"}
@@ -0,0 +1,13 @@
1
+ import * as Atom from "effect/reactivity/Atom";
2
+ export const pageHidden = Atom.make((get) => {
3
+ if (typeof document === "undefined") {
4
+ return false;
5
+ }
6
+ function changed() {
7
+ get.setSelf(document.visibilityState === "hidden");
8
+ }
9
+ document.addEventListener("visibilitychange", changed);
10
+ get.addFinalizer(() => document.removeEventListener("visibilitychange", changed));
11
+ return document.visibilityState === "hidden";
12
+ }).pipe(Atom.setIdleTTL(0));
13
+ //# sourceMappingURL=pageHidden.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pageHidden.js","sourceRoot":"","sources":["../../src/client/pageHidden.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAE/C,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;IAC3C,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACrC,OAAO,KAAK,CAAC;IACd,CAAC;IACD,SAAS,OAAO;QACf,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,KAAK,QAAQ,CAAC,CAAC;IACpD,CAAC;IACD,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;IACvD,GAAG,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC,CAAC;IAClF,OAAO,QAAQ,CAAC,eAAe,KAAK,QAAQ,CAAC;AAC9C,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -14,6 +14,9 @@ export interface ResultState<A, E> {
14
14
  export interface QueryState<A, E> extends ResultState<A, E> {
15
15
  readonly denied: boolean;
16
16
  readonly refresh: () => void;
17
+ readonly refusal: Option.Option<Exclude<E, {
18
+ readonly _tag: "RpcClientError";
19
+ }>>;
17
20
  }
18
21
  export interface QueryOptions<E = unknown> {
19
22
  readonly coalesceWindow?: Duration.Input | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"resultState.d.ts","sourceRoot":"","sources":["../../src/client/resultState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,MAAM,EAAa,MAAM,QAAQ,CAAC;AAC9E,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAGpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAOrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,KAAK,aAAa,EAAmB,MAAM,uBAAuB,CAAC;AAG5E,MAAM,WAAW,WAAW,CAAC,CAAC,EAAE,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAC/C;AAkBD,MAAM,WAAW,UAAU,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC;IAC1D,QAAQ,CAAC,MAAM,EAAE,O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AAE,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1G,wBAAgB,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,EACvD,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,aAAa,CAAC,EAC3C,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,EAC5D,OAAO,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GACjE,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC"}
@@ -50,6 +50,7 @@ export function useQuery(atom, options = {}) {
50
50
  ...state(result, data),
51
51
  denied: Option.exists(AsyncResult.cause(result), (cause) => Option.exists(Cause.findErrorOption(cause), Predicate.isTagged("QueryReadDenied"))),
52
52
  refresh,
53
+ refusal: Option.flatMap(AsyncResult.cause(result), (cause) => Option.filter(Cause.findErrorOption(cause), (error) => !Predicate.isTagged(error, "RpcClientError"))),
53
54
  };
54
55
  }
55
56
  export function useAction(source, run, options = {}) {
@@ -1 +1 @@
1
- {"version":3,"file":"resultState.js","sourceRoot":"","sources":["../../src/client/resultState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,KAAK,EAA8B,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9E,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA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AAC,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC,CACjH,CACD;KACD,CAAC;AACH,CAAC;AAUD,MAAM,UAAU,SAAS,CACxB,MAA4E,EAC5E,GAA6D,EAC7D,OAAO,GAAmC,EAAE;IAE5C,MAAM,IAAI,GAAG,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACrC,wBAAwB,CAAC,MAAM,EAAE,GAAG,KAAK,SAAS,CAAC,CAAC;IACpD,OAAO,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;AACzD,CAAC"}
@@ -5,6 +5,9 @@ interface QuerySnapshot<A, E> {
5
5
  readonly denied: boolean;
6
6
  readonly pending: boolean;
7
7
  readonly refresh: () => void;
8
+ readonly refusal: Option.Option<Exclude<E, {
9
+ readonly _tag: "RpcClientError";
10
+ }>>;
8
11
  }
9
12
  export declare function loadedQuery<A, E>(query: QuerySnapshot<A, E>, loaded: A): {
10
13
  cause: Option.Option<Cause.Cause<E>>;
@@ -13,6 +16,9 @@ export declare function loadedQuery<A, E>(query: QuerySnapshot<A, E>, loaded: A)
13
16
  pending: boolean;
14
17
  refresh: () => void;
15
18
  refreshing: boolean;
19
+ refusal: Option.Option<Exclude<E, {
20
+ readonly _tag: "RpcClientError";
21
+ }>>;
16
22
  };
17
23
  export {};
18
24
  //# sourceMappingURL=loadedQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loadedQuery.d.ts","sourceRoot":"","sources":["../../src/internal/loadedQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE5C,UAAU,aAAa,CAAC,CAAC,EAAE,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,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AC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;IAErE,KAAK;IACL,IAAI;IACJ,MAAM;IACN,OAAO;IACP,OAAO,QAVgB,IAAI;IAW3B,UAAU;IACV,OAAO;uBAXoD,gBAAgB;;EAa5E"}
@@ -7,6 +7,7 @@ export function loadedQuery(query, loaded) {
7
7
  pending: query.pending,
8
8
  refresh: query.refresh,
9
9
  refreshing: query.pending,
10
+ refusal: query.refusal,
10
11
  };
11
12
  }
12
13
  //# sourceMappingURL=loadedQuery.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"loadedQuery.js","sourceRoot":"","sources":["../../src/internal/loadedQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,MAAM,QAAQ,CAAC;AAU5C,MAAM,UAAU,WAAW,CAAO,KAA0B,EAAE,MAAS;IACtE,OAAO;QACN,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC;QAChD,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,UAAU,EAAE,KAAK,CAAC,OAAO;KACzB,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"loadedQuery.js","sourceRoot":"","sources":["../../src/internal/loadedQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,MAAM,QAAQ,CAAC;AAW5C,MAAM,UAAU,WAAW,CAAO,KAA0B,EAAE,MAAS;IACtE,OAAO;QACN,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC;QAChD,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,UAAU,EAAE,KAAK,CAAC,OAAO;QACzB,OAAO,EAAE,KAAK,CAAC,OAAO;KACtB,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/react",
3
- "version": "0.38.1",
3
+ "version": "0.40.0",
4
4
  "description": "React query, action, editor and session hooks for native Effect atoms",
5
5
  "keywords": [
6
6
  "effect"
@@ -20,14 +20,14 @@
20
20
  "imports": {
21
21
  "#test/*": "./src/test-support/*",
22
22
  "#*.ts": {
23
- "source": "./src/*.ts",
23
+ "@shivaedev/source": "./src/*.ts",
24
24
  "types": "./dist/*.d.ts",
25
25
  "default": "./dist/*.js"
26
26
  }
27
27
  },
28
28
  "exports": {
29
29
  "./*.ts": {
30
- "source": "./src/*.ts",
30
+ "@shivaedev/source": "./src/*.ts",
31
31
  "types": "./dist/*.d.ts",
32
32
  "default": "./dist/*.js"
33
33
  },
@@ -45,26 +45,26 @@
45
45
  "README.md"
46
46
  ],
47
47
  "dependencies": {
48
- "@shivaedev/access": "0.4.2",
49
- "@shivaedev/contract": "0.34.0",
50
- "@shivaedev/errors": "0.8.0",
51
- "@shivaedev/form": "0.15.0",
52
- "@shivaedev/identity": "0.23.0"
48
+ "@shivaedev/access": "0.5.0",
49
+ "@shivaedev/contract": "0.36.0",
50
+ "@shivaedev/errors": "0.9.0",
51
+ "@shivaedev/form": "0.16.0",
52
+ "@shivaedev/identity": "0.24.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@effect/atom-react": "4.0.6",
56
56
  "@effect/platform-node": "4.0.6",
57
57
  "@effect/sql-pg": "4.0.6",
58
58
  "@effect/sql-sqlite-node": "4.0.6",
59
- "@shivaedev/changes": "0.9.0",
60
- "@shivaedev/jobs": "0.34.0",
61
- "@shivaedev/quality": "0.58.0",
62
- "@shivaedev/server": "0.22.0",
63
- "@shivaedev/service": "0.6.2",
64
- "@shivaedev/sql": "0.36.1",
65
- "@shivaedev/test-kits": "0.2.1",
66
- "@shivaedev/test-sql": "0.18.2",
67
- "@shivaedev/test-story": "0.37.0",
59
+ "@shivaedev/changes": "0.10.0",
60
+ "@shivaedev/jobs": "0.35.0",
61
+ "@shivaedev/quality": "0.60.0",
62
+ "@shivaedev/server": "0.24.0",
63
+ "@shivaedev/service": "0.7.0",
64
+ "@shivaedev/sql": "0.37.0",
65
+ "@shivaedev/test-kits": "0.3.0",
66
+ "@shivaedev/test-sql": "0.20.0",
67
+ "@shivaedev/test-story": "0.38.0",
68
68
  "@tanstack/react-router": "1.170.46",
69
69
  "@types/node": "24.19.2",
70
70
  "@types/react": "19.3.0",
@@ -15,7 +15,7 @@ export function QueryView<A, E>({ query, loading, content, failure }: QueryViewP
15
15
  if (Result.isSuccess(defect)) {
16
16
  throw defect.success;
17
17
  }
18
- return Cause.findErrorOption(cause);
18
+ return query.refusal;
19
19
  });
20
20
  return createElement(
21
21
  Fragment,
@@ -0,0 +1,14 @@
1
+ import { Crypto, Effect, Layer, PlatformError } from "effect";
2
+
3
+ export const clientCrypto = Layer.succeed(
4
+ Crypto.Crypto,
5
+ Crypto.make({
6
+ digest: (algorithm, data) =>
7
+ Effect.tryPromise({
8
+ catch: (cause) =>
9
+ PlatformError.systemError({ _tag: "Unknown", cause, description: "Could not compute digest", method: "digest", module: "Crypto" }),
10
+ try: () => globalThis.crypto.subtle.digest(algorithm, new Uint8Array(data)).then((buffer) => new Uint8Array(buffer)),
11
+ }),
12
+ randomBytes: (size) => globalThis.crypto.getRandomValues(new Uint8Array(size)),
13
+ }),
14
+ );
@@ -0,0 +1,4 @@
1
+ import * as Atom from "effect/reactivity/Atom";
2
+ import { clientCrypto } from "#client/adapters/crypto.ts";
3
+
4
+ export const handlerRuntime = Atom.runtime(clientCrypto);
@@ -0,0 +1,11 @@
1
+ import { useAtomSuspense } from "@effect/atom-react";
2
+ import { Clock, Context } from "effect";
3
+ import type * as AsyncResult from "effect/reactivity/AsyncResult";
4
+ import type * as Atom from "effect/reactivity/Atom";
5
+ import { useCallback } from "react";
6
+ import { handlerRuntime } from "#client/adapters/handlerRuntime.ts";
7
+
8
+ export function useClock(runtime: Atom.Atom<AsyncResult.AsyncResult<Context.Context<never>, unknown>> = handlerRuntime): () => number {
9
+ const clock = Context.get(useAtomSuspense(runtime).value, Clock.Clock);
10
+ return useCallback(() => clock.currentTimeMillisUnsafe(), [clock]);
11
+ }
@@ -0,0 +1,6 @@
1
+ import { useAtomValue } from "@effect/atom-react";
2
+ import { type ActiveClient, type ConnectionStatus, clientActivity } from "@shivaedev/contract/clientActivity.ts";
3
+
4
+ export function useConnectionStatus(client: ActiveClient): ConnectionStatus {
5
+ return useAtomValue(clientActivity(client).connectionStatus);
6
+ }
@@ -0,0 +1,20 @@
1
+ import { RegistryContext, useAtomMount, useAtomValue } from "@effect/atom-react";
2
+ import { Effect } from "effect";
3
+ import * as AtomRegistry from "effect/reactivity/AtomRegistry";
4
+ import { useContext, useEffect } from "react";
5
+ import type { deployUpdate } from "#client/deployUpdate.ts";
6
+
7
+ export function useDeployUpdate<E>(update: ReturnType<typeof deployUpdate<E>>) {
8
+ useAtomMount(update.controller);
9
+ return { ...useAtomValue(update.state), activation: useAtomValue(update.activation), reload: update.reload };
10
+ }
11
+
12
+ export function useUpdateBlocker<E>(update: ReturnType<typeof deployUpdate<E>>, blocked: boolean): void {
13
+ const registry = useContext(RegistryContext);
14
+ useEffect(() => {
15
+ if (blocked) {
16
+ return Effect.runSync(update.block.pipe(Effect.provideService(AtomRegistry.AtomRegistry, registry)));
17
+ }
18
+ return undefined;
19
+ }, [blocked, registry, update]);
20
+ }
@@ -0,0 +1,11 @@
1
+ import { useAtomSuspense } from "@effect/atom-react";
2
+ import { Context, Crypto, Effect } from "effect";
3
+ import type * as AsyncResult from "effect/reactivity/AsyncResult";
4
+ import type * as Atom from "effect/reactivity/Atom";
5
+ import { useCallback } from "react";
6
+ import { handlerRuntime } from "#client/adapters/handlerRuntime.ts";
7
+
8
+ export function useNewId(runtime: Atom.Atom<AsyncResult.AsyncResult<Context.Context<Crypto.Crypto>, unknown>> = handlerRuntime): () => string {
9
+ const crypto = Context.get(useAtomSuspense(runtime).value, Crypto.Crypto);
10
+ return useCallback(() => Effect.runSync(crypto.randomUUIDv4()), [crypto]);
11
+ }
@@ -0,0 +1,25 @@
1
+ import { Cause, Effect } from "effect";
2
+ import * as Atom from "effect/reactivity/Atom";
3
+ import { useInsertionEffect, useRef, useState } from "react";
4
+ import { type ActionState, useAction } from "#client/resultState.ts";
5
+
6
+ export function usePromiseAction<A>(run: () => PromiseLike<A>): ActionState<void, A, Cause.UnknownError>;
7
+ export function usePromiseAction<A, E>(run: () => PromiseLike<A>, options: { readonly catch: (cause: unknown) => E }): ActionState<void, A, E>;
8
+ export function usePromiseAction<A, E>(
9
+ run: () => PromiseLike<A>,
10
+ options?: { readonly catch: (cause: unknown) => E },
11
+ ): ActionState<void, A, E | Cause.UnknownError> {
12
+ const latestRef = useRef({ reject: options?.catch, run });
13
+ useInsertionEffect(() => {
14
+ latestRef.current = { reject: options?.catch, run };
15
+ }, [run, options?.catch]);
16
+ const [atom] = useState(() =>
17
+ Atom.fn<void>()(() =>
18
+ Effect.tryPromise({
19
+ catch: (cause) => (latestRef.current.reject ? latestRef.current.reject(cause) : new Cause.UnknownError(cause)),
20
+ try: () => latestRef.current.run(),
21
+ }),
22
+ ),
23
+ );
24
+ return useAction(atom);
25
+ }
@@ -0,0 +1,82 @@
1
+ import { RegistryContext, useAtomValue } from "@effect/atom-react";
2
+ import { Effect, Option } from "effect";
3
+ import * as Atom from "effect/reactivity/Atom";
4
+ import { useContext, useMemo } from "react";
5
+ import type { AtomServices } from "#AtomServices.ts";
6
+ import type { deployUpdate } from "#client/deployUpdate.ts";
7
+ import { useAction } from "#client/resultState.ts";
8
+
9
+ export interface VersionedChangeCommand<TInput, A, E, R, TRuntimeError> {
10
+ readonly run: (input: TInput) => Effect.Effect<A, E, AtomServices<R>>;
11
+ readonly runtime: Atom.AtomRuntime<R, TRuntimeError>;
12
+ readonly update: Pick<ReturnType<typeof deployUpdate>, "block">;
13
+ }
14
+
15
+ export interface UndoableNotice<TInput, A> {
16
+ readonly input: TInput;
17
+ readonly message: string;
18
+ readonly value: A;
19
+ }
20
+
21
+ export function useUndoableChange<TInput extends { readonly expectedVersion: number }, A extends { readonly version: number }, E, R, TRuntimeError>(
22
+ command: VersionedChangeCommand<TInput, A, E, R, TRuntimeError>,
23
+ options: { readonly describe: (value: NoInfer<A>, input: NoInfer<TInput>) => string },
24
+ ) {
25
+ const { run, runtime, update } = command;
26
+ const registry = useContext(RegistryContext);
27
+ type Entry = UndoableNotice<TInput, A> & { readonly inverse: Omit<TInput, "expectedVersion"> };
28
+ interface Removal {
29
+ readonly input: TInput;
30
+ readonly inverse: Omit<TInput, "expectedVersion">;
31
+ readonly sequence: number;
32
+ }
33
+ const owner = useMemo(
34
+ () => ({ notice: Atom.make(Option.none<Entry>()), registry, run, runtime, sequence: 0, update }),
35
+ [run, runtime, update, registry],
36
+ );
37
+ const execute = useMemo(
38
+ () => (input: TInput) =>
39
+ Effect.acquireUseRelease(
40
+ owner.update.block,
41
+ () => owner.run(input),
42
+ (release) => Effect.sync(release),
43
+ ),
44
+ [owner],
45
+ );
46
+ const removeRun = useMemo(() => (request: Removal) => execute(request.input), [execute]);
47
+ const undoRun = useMemo(() => (entry: Entry) => execute({ ...entry.input, ...entry.inverse, expectedVersion: entry.value.version }), [execute]);
48
+ const removal = useAction(owner.runtime, removeRun, {
49
+ concurrent: true,
50
+ onSuccess: (value, { input, inverse, sequence }) => {
51
+ if (sequence === owner.sequence) {
52
+ owner.registry.set(owner.notice, Option.some({ input, inverse, message: options.describe(value, input), value }));
53
+ }
54
+ },
55
+ });
56
+ const restoration = useAction(owner.runtime, undoRun, {
57
+ onSuccess: (_value, entry) => {
58
+ if (Option.getOrUndefined(owner.registry.get(owner.notice)) === entry) {
59
+ owner.registry.set(owner.notice, Option.none());
60
+ }
61
+ },
62
+ });
63
+ const notice: Option.Option<UndoableNotice<TInput, A>> = useAtomValue(owner.notice);
64
+ return {
65
+ notice,
66
+ pending: removal.pending || restoration.pending,
67
+ remove: (input: TInput, inverse: Omit<TInput, "expectedVersion">) => {
68
+ owner.sequence += 1;
69
+ removal.dispatch({ input, inverse, sequence: owner.sequence });
70
+ },
71
+ removeResult: removal.result,
72
+ removing: removal.pending,
73
+ undo: () => {
74
+ const current = owner.registry.get(owner.notice);
75
+ if (Option.isSome(current)) {
76
+ restoration.dispatch(current.value);
77
+ }
78
+ },
79
+ undoing: restoration.pending,
80
+ undoResult: restoration.result,
81
+ };
82
+ }
@@ -0,0 +1,69 @@
1
+ import { Effect, Schedule, Stream } from "effect";
2
+ import * as Atom from "effect/reactivity/Atom";
3
+ import * as AtomRegistry from "effect/reactivity/AtomRegistry";
4
+ import { makeClient } from "@shivaedev/contract/bind.ts";
5
+ import type { ClientOptions } from "@shivaedev/contract/clientOptions.ts";
6
+ import { HostVersion } from "@shivaedev/contract/HostVersion.ts";
7
+ import { pageHidden } from "./pageHidden.ts";
8
+
9
+ export function deployUpdate<E = never>(
10
+ options: ClientOptions & {
11
+ readonly loadedVersion: string;
12
+ readonly activate?: Effect.Effect<void, E>;
13
+ readonly reload: () => void;
14
+ },
15
+ ) {
16
+ const client = makeClient(HostVersion, options);
17
+ const version = Atom.make<string | undefined>(undefined);
18
+ const activated = Atom.make<string | undefined>(undefined);
19
+ const blockers = Atom.make<ReadonlySet<object>>(new Set<object>());
20
+ const activation = client.runtime.fn((next: string, get) =>
21
+ (options.activate ?? Effect.void).pipe(Effect.tap(() => Effect.sync(() => get.set(activated, next)))),
22
+ );
23
+ const connection = client.runtime.atom((get) =>
24
+ client.api.watch.run().pipe(
25
+ Stream.retry(Schedule.spaced("500 millis")),
26
+ Stream.runForEach((next) => Effect.sync(() => get.set(version, next))),
27
+ ),
28
+ );
29
+ const state = Atom.make((get) => {
30
+ get.mount(connection);
31
+ get.mount(activation);
32
+ const next = get(version);
33
+ return {
34
+ available: next !== undefined && next !== options.loadedVersion && next !== get(activated),
35
+ blocked: get(blockers).size > 0,
36
+ version: next,
37
+ };
38
+ });
39
+ const controller = Atom.make((get) => {
40
+ get.mount(state);
41
+ get.mount(pageHidden);
42
+ let activating: string | undefined;
43
+ function check() {
44
+ const current = get.once(state);
45
+ if (
46
+ options.activate !== undefined
47
+ && current.available
48
+ && !current.blocked
49
+ && get.once(pageHidden)
50
+ && current.version !== undefined
51
+ && current.version !== activating
52
+ ) {
53
+ activating = current.version;
54
+ get.set(activation, current.version);
55
+ }
56
+ }
57
+ get.subscribe(state, check);
58
+ get.subscribe(pageHidden, check);
59
+ check();
60
+ return undefined;
61
+ }).pipe(Atom.setIdleTTL(0));
62
+ const block = Effect.gen(function* () {
63
+ const registry = yield* AtomRegistry.AtomRegistry;
64
+ const key = {};
65
+ registry.set(blockers, new Set([...registry.get(blockers), key]));
66
+ return () => registry.set(blockers, new Set([...registry.get(blockers)].filter((entry) => entry !== key)));
67
+ });
68
+ return { activation, block, controller, reload: options.reload, state };
69
+ }
@@ -0,0 +1,13 @@
1
+ import * as Atom from "effect/reactivity/Atom";
2
+
3
+ export const pageHidden = Atom.make((get) => {
4
+ if (typeof document === "undefined") {
5
+ return false;
6
+ }
7
+ function changed() {
8
+ get.setSelf(document.visibilityState === "hidden");
9
+ }
10
+ document.addEventListener("visibilitychange", changed);
11
+ get.addFinalizer(() => document.removeEventListener("visibilitychange", changed));
12
+ return document.visibilityState === "hidden";
13
+ }).pipe(Atom.setIdleTTL(0));
@@ -42,6 +42,7 @@ function useRecheckOnUnauthorized<A, E>(result: AsyncResult.AsyncResult<A, E>, e
42
42
  export interface QueryState<A, E> extends ResultState<A, E> {
43
43
  readonly denied: boolean;
44
44
  readonly refresh: () => void;
45
+ readonly refusal: Option.Option<Exclude<E, { readonly _tag: "RpcClientError" }>>;
45
46
  }
46
47
  export interface QueryOptions<E = unknown> {
47
48
  readonly coalesceWindow?: Duration.Input | undefined;
@@ -79,6 +80,12 @@ export function useQuery<A, E>(atom: Atom.Atom<AsyncResult.AsyncResult<A, E>>, o
79
80
  ...state(result, data),
80
81
  denied: Option.exists(AsyncResult.cause(result), (cause) => Option.exists(Cause.findErrorOption(cause), Predicate.isTagged("QueryReadDenied"))),
81
82
  refresh,
83
+ refusal: Option.flatMap(AsyncResult.cause(result), (cause) =>
84
+ Option.filter(
85
+ Cause.findErrorOption(cause),
86
+ (error): error is Exclude<E, { readonly _tag: "RpcClientError" }> => !Predicate.isTagged(error, "RpcClientError"),
87
+ ),
88
+ ),
82
89
  };
83
90
  }
84
91
  export interface ActionState<TInput, A, E> extends ResultState<A, E> {
@@ -6,6 +6,7 @@ interface QuerySnapshot<A, E> {
6
6
  readonly denied: boolean;
7
7
  readonly pending: boolean;
8
8
  readonly refresh: () => void;
9
+ readonly refusal: Option.Option<Exclude<E, { readonly _tag: "RpcClientError" }>>;
9
10
  }
10
11
 
11
12
  export function loadedQuery<A, E>(query: QuerySnapshot<A, E>, loaded: A) {
@@ -16,5 +17,6 @@ export function loadedQuery<A, E>(query: QuerySnapshot<A, E>, loaded: A) {
16
17
  pending: query.pending,
17
18
  refresh: query.refresh,
18
19
  refreshing: query.pending,
20
+ refusal: query.refusal,
19
21
  };
20
22
  }