@shivaedev/react 0.39.0 → 0.41.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 +23 -0
- package/README.md +76 -3
- package/dist/client/actionCompletion.d.ts.map +1 -1
- package/dist/client/actionCompletion.js +2 -2
- package/dist/client/actionCompletion.js.map +1 -1
- package/dist/client/adapters/SessionSignOut.d.ts +9 -0
- package/dist/client/adapters/SessionSignOut.d.ts.map +1 -0
- package/dist/client/adapters/SessionSignOut.js +18 -0
- package/dist/client/adapters/SessionSignOut.js.map +1 -0
- package/dist/client/adapters/crypto.d.ts +3 -0
- package/dist/client/adapters/crypto.d.ts.map +1 -0
- package/dist/client/adapters/crypto.js +9 -0
- package/dist/client/adapters/crypto.js.map +1 -0
- package/dist/client/adapters/handlerRuntime.d.ts +3 -0
- package/dist/client/adapters/handlerRuntime.d.ts.map +1 -0
- package/dist/client/adapters/handlerRuntime.js +4 -0
- package/dist/client/adapters/handlerRuntime.js.map +1 -0
- package/dist/client/adapters/useClock.d.ts +5 -0
- package/dist/client/adapters/useClock.d.ts.map +1 -0
- package/dist/client/adapters/useClock.js +9 -0
- package/dist/client/adapters/useClock.js.map +1 -0
- package/dist/client/adapters/useNewId.d.ts +5 -0
- package/dist/client/adapters/useNewId.d.ts.map +1 -0
- package/dist/client/adapters/useNewId.js +9 -0
- package/dist/client/adapters/useNewId.js.map +1 -0
- package/dist/client/adapters/usePromiseAction.d.ts +7 -0
- package/dist/client/adapters/usePromiseAction.d.ts.map +1 -0
- package/dist/client/adapters/usePromiseAction.js +16 -0
- package/dist/client/adapters/usePromiseAction.js.map +1 -0
- package/dist/client/adapters/useSessionRetry.d.ts +3 -0
- package/dist/client/adapters/useSessionRetry.d.ts.map +1 -0
- package/dist/client/adapters/useSessionRetry.js +48 -0
- package/dist/client/adapters/useSessionRetry.js.map +1 -0
- package/dist/client/adapters/useSignOut.d.ts +3 -2
- package/dist/client/adapters/useSignOut.d.ts.map +1 -1
- package/dist/client/adapters/useSignOut.js +6 -1
- package/dist/client/adapters/useSignOut.js.map +1 -1
- package/dist/client/adapters/useUndoableChange.d.ts +31 -0
- package/dist/client/adapters/useUndoableChange.d.ts.map +1 -0
- package/dist/client/adapters/useUndoableChange.js +48 -0
- package/dist/client/adapters/useUndoableChange.js.map +1 -0
- package/dist/client/mountLive.js +1 -1
- package/dist/client/mountLive.js.map +1 -1
- package/dist/client/resultState.d.ts.map +1 -1
- package/dist/client/resultState.js +2 -2
- package/dist/client/resultState.js.map +1 -1
- package/dist/client/saveState.d.ts.map +1 -1
- package/dist/client/saveState.js +2 -2
- package/dist/client/saveState.js.map +1 -1
- package/dist/client/sessionBoundary.d.ts +6 -3
- package/dist/client/sessionBoundary.d.ts.map +1 -1
- package/dist/client/sessionBoundary.js +16 -4
- package/dist/client/sessionBoundary.js.map +1 -1
- package/dist/internal/adapters/useLatestCallback.d.ts +1 -1
- package/dist/internal/adapters/useLatestCallback.d.ts.map +1 -1
- package/dist/internal/adapters/useLatestCallback.js.map +1 -1
- package/dist/internal/sessionRecheck.d.ts +1 -2
- package/dist/internal/sessionRecheck.d.ts.map +1 -1
- package/dist/internal/sessionRecheck.js +2 -6
- package/dist/internal/sessionRecheck.js.map +1 -1
- package/package.json +17 -17
- package/src/client/actionCompletion.ts +2 -2
- package/src/client/adapters/SessionSignOut.ts +27 -0
- package/src/client/adapters/crypto.ts +14 -0
- package/src/client/adapters/handlerRuntime.ts +4 -0
- package/src/client/adapters/useClock.ts +11 -0
- package/src/client/adapters/useNewId.ts +11 -0
- package/src/client/adapters/usePromiseAction.ts +25 -0
- package/src/client/adapters/useSessionRetry.ts +54 -0
- package/src/client/adapters/useSignOut.ts +6 -1
- package/src/client/adapters/useUndoableChange.ts +82 -0
- package/src/client/mountLive.ts +1 -1
- package/src/client/resultState.ts +2 -2
- package/src/client/saveState.ts +2 -2
- package/src/client/sessionBoundary.ts +33 -17
- package/src/internal/adapters/useLatestCallback.ts +1 -1
- package/src/internal/sessionRecheck.ts +2 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.41.0 - 2026-11-04
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Add `useUndoableChange` for versioned commands: capture an inverse payload, guard Undo with the returned version, keep the latest removal notice across reordered replies, preserve typed results and hold deployment updates while writes are pending.
|
|
8
|
+
- `SessionBoundary` accepts a session-check Effect, retries failed checks with exponential backoff, and retries immediately on online or foreground events. Its optional `signOut` atom holds the signed-in tree until the auth owner reports signed out.
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Socket transport failures no longer request a session check; typed authentication refusals still do.
|
|
13
|
+
|
|
14
|
+
## 0.40.0 - 2026-11-04
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- Activate staged updates while hidden once registered blockers release, and expose an application-owned reload action when activation is unavailable or blocked.
|
|
19
|
+
- Provide `useNewId` and `useClock` callbacks backed by atom runtime Crypto and Clock services, plus a Web Crypto client layer.
|
|
20
|
+
- Add `usePromiseAction` to dispatch promise calls with native action state, `UnknownError` failures by default and an optional typed rejection mapper.
|
|
21
|
+
|
|
22
|
+
### Breaking
|
|
23
|
+
|
|
24
|
+
- 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.
|
|
25
|
+
|
|
3
26
|
## 0.39.0 - 2026-11-04
|
|
4
27
|
|
|
5
28
|
### Added
|
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ export function App({ session, recheck }: { readonly session: Session | undefine
|
|
|
84
84
|
|
|
85
85
|
Pass the signed-out router as `signedOut` and the requested continuation address as `redirectTo` (for example, the sign-in route's `returnTo` search value). On successful sign-in, the auth owner supplies the new `session`; the boundary unmounts the signed-out tree before replacing the URL, then mounts the signed-in tree at that address. The sign-in screen requests a session recheck after success; it leaves navigation to the boundary. Off-site, non-HTTP and malformed targets fall back to `/`. A same-origin destination keeps its path, query and fragment. The default replacement uses browser history. Supply `navigate={(href) => history.replace(href)}` for a router history such as TanStack's memory history; the callback receives only the checked local path. Navigation happens once when entering a generation, so a same-user session rotation does not navigate again.
|
|
86
86
|
|
|
87
|
-
A query that fails with an `Unauthorized` from `@shivaedev/errors/taxonomy.ts` asks `recheck` to run and keeps its retained data. An action does the same once per failed result, retaining its last successful `data` and the typed failure in `cause`; rerendering that result does not repeat the recheck. A live
|
|
87
|
+
A query that fails with an `Unauthorized` from `@shivaedev/errors/taxonomy.ts` asks `recheck` to run and keeps its retained data. An action does the same once per failed result, retaining its last successful `data` and the typed failure in `cause`; rerendering that result does not repeat the recheck. A live reconnect requests a check only for a typed `Unauthorized` authentication refusal; dropped sockets and unreachable servers leave the session alone. Pass the auth owner’s session-refresh Effect as `recheck` (for example, `recheck={auth.session.refresh}`). The boundary shares an in-flight check, retries failures after 1, 2, 4 seconds and so on up to 30 seconds, and retries immediately on visible `online` or `visibilitychange` events while a check is pending, restarting an in-flight check too. Session replacement and unmount cancel retries. Existing void callbacks remain supported; they keep their own check and retry policy. Keep retained session data on screen when a refresh exposes a failure, and pass `session={undefined}` only after a definite signed-out answer. The auth owner decides whether the session ends. The boundary also handles React StrictMode's effect replay and preserves component state across hiding and revealing an `<Activity>` subtree, supplying a live registry when revealed.
|
|
88
88
|
|
|
89
89
|
#### Session-scoped bindings
|
|
90
90
|
|
|
@@ -564,6 +564,42 @@ A newer dispatch interrupts the earlier command by default. Interrupted work pro
|
|
|
564
564
|
|
|
565
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.
|
|
566
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
|
+
|
|
567
603
|
#### Commands with a pending display value
|
|
568
604
|
|
|
569
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:
|
|
@@ -905,7 +941,9 @@ The example uses `Option` from `effect` and the application's Better Auth client
|
|
|
905
941
|
|
|
906
942
|
For other Better Auth reads, `authQuery` from `@shivaedev/react/client/authQuery.ts` creates an input-keyed query atom family. Pass an input-to-Effect function, such as the result of `authQuery` from `@shivaedev/identity/client/adapters/authQuery.ts`, then render its atom with `useQuery`. Releasing a pending read interrupts its Effect and aborts the supplied signal.
|
|
907
943
|
|
|
908
|
-
|
|
944
|
+
Pass the auth owner’s sign-out atom to `SessionBoundary` as `signOut={signOut}`. The boundary mounts it in the auth owner’s registry and unmounts the signed-in tree while sign-out is pending, including the following session refetch. A successful action keeps the tree held until the session clears; a failed action releases the hold. Supply an atom for the sign-out request itself, and give `recheck` the auth owner’s session refresh. After the request succeeds, the boundary starts that check and retries failures while holding the tree. A failed session check never releases a successful sign-out’s hold.
|
|
945
|
+
|
|
946
|
+
For an explicit sign-out in a TanStack route, use `useSignOut(signOut, { signIn: "/sign-in" })` from `@shivaedev/react/client/adapters/useSignOut.ts` in place of `useAction`. It exposes the same state and a `dispatch()` handler. The hook records sign-out intent before the request and navigates to sign-in after success. A refused request clears that intent, including when the boundary remounts its route. Repeated clicks while pending share one request and follow-up. Unmounting the component or disposing its registry stops the follow-up navigation. If a session refresh replaces the component before the response, the replacement session’s route policy owns navigation to sign-in. `permissionGuard` and `signInSearch(location)` omit `returnTo` for that intent, including when the auth owner's session refresh reruns guards first. Use `signInSearch` for module sign-in links too; ordinary visits retain the full requested location. Applications do not need history markers or Better Auth completion timing hooks.
|
|
909
947
|
|
|
910
948
|
### 3. Every day
|
|
911
949
|
|
|
@@ -961,6 +999,41 @@ const minutesAgo = Math.floor((now - savedAt) / 60_000);
|
|
|
961
999
|
|
|
962
1000
|
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.
|
|
963
1001
|
|
|
1002
|
+
#### Ids, time and promises in callbacks
|
|
1003
|
+
|
|
1004
|
+
`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:
|
|
1005
|
+
|
|
1006
|
+
```tsx
|
|
1007
|
+
import { useState } from "react";
|
|
1008
|
+
import { useClock } from "@shivaedev/react/client/adapters/useClock.ts";
|
|
1009
|
+
import { useNewId } from "@shivaedev/react/client/adapters/useNewId.ts";
|
|
1010
|
+
|
|
1011
|
+
const newId = useNewId(client.runtime);
|
|
1012
|
+
const now = useClock(client.runtime);
|
|
1013
|
+
const [id] = useState(newId);
|
|
1014
|
+
const [createdAt] = useState(now);
|
|
1015
|
+
const stamp = () => ({ id: newId(), at: now() });
|
|
1016
|
+
```
|
|
1017
|
+
|
|
1018
|
+
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`.
|
|
1019
|
+
|
|
1020
|
+
`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:
|
|
1021
|
+
|
|
1022
|
+
```tsx
|
|
1023
|
+
import { usePromiseAction } from "@shivaedev/react/client/adapters/usePromiseAction.ts";
|
|
1024
|
+
|
|
1025
|
+
const copy = usePromiseAction(() => navigator.clipboard.writeText(text), {
|
|
1026
|
+
catch: (cause) => new ClipboardDenied({ reason: String(cause) }),
|
|
1027
|
+
});
|
|
1028
|
+
const button = (
|
|
1029
|
+
<button disabled={copy.pending} onClick={() => copy.dispatch()}>
|
|
1030
|
+
Copy
|
|
1031
|
+
</button>
|
|
1032
|
+
);
|
|
1033
|
+
```
|
|
1034
|
+
|
|
1035
|
+
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.
|
|
1036
|
+
|
|
964
1037
|
#### Render tests in happy-dom
|
|
965
1038
|
|
|
966
1039
|
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:
|
|
@@ -1117,7 +1190,7 @@ const screen = screenDriver({ act, pending, root: view.container, tell: story.te
|
|
|
1117
1190
|
|
|
1118
1191
|
`useQuery(atom, options?)` adds `refresh(): void`; `useAction` adds `dispatch(input): void`. `QueryOptions.coalesceWindow` accepts a native Duration for live changed hints on contract-bound queries; it belongs to the query atom in its registry, so readers sharing that atom share the window. Omitting it uses the session default. `QueryOptions.notice` publishes a notice descriptor for a failed result. `QueryOptions.keepPreviousData` defaults to `false` and controls retention across query atom changes. Same-identity refresh retention is always enabled. `result` and `cause` describe the current native query even when `data` displays a previous atom's success. Success, input and typed failure types are inferred from the supplied atom. The Effect overload is `useAction(runtime, run, options?)`, where `ActionOptions` supplies `concurrent`, `notices`, `onSuccess(value, input)` and `onFailure(error, input)`; its shared state also includes the native runtime's typed failure.
|
|
1119
1192
|
|
|
1120
|
-
Import the defining `.ts` module, such as `@shivaedev/react/client/editor.ts`. There is no root import. `useSessionRecheck()` from `client/sessionBoundary.ts`
|
|
1193
|
+
Import the defining `.ts` module, such as `@shivaedev/react/client/editor.ts`. There is no root import. `useSessionRecheck()` from `client/sessionBoundary.ts` requests the boundary’s shared session check.
|
|
1121
1194
|
|
|
1122
1195
|
Prefer `useEditor` and `useCreate` when binding a form to a command. The lower-level modules expose the same composition pieces: `submission` from `submission.ts` makes a form and its submission snapshot reader, `rejecting` from `@shivaedev/form/fieldRejection.ts` maps save failures through a submitter, and `useSaveState` from `client/saveState.ts` observes submission and invokes a success callback. Field-rejection mapping types and `fieldRejectionOf` also belong to `@shivaedev/form/fieldRejection.ts`; `AtomServices` belongs to `AtomServices.ts`.
|
|
1123
1196
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionCompletion.d.ts","sourceRoot":"","sources":["../../src/client/actionCompletion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"actionCompletion.d.ts","sourceRoot":"","sources":["../../src/client/actionCompletion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAGpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,MAAM,WAAW,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK;IACrD,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvD,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACvD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,EAC7D,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,aAAa,CAAC,EAC5E,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,EAC1E,OAAO,EAAE,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GACrC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,CA2DjD"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { RegistryContext } from "@effect/atom-react";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
3
|
import { useContext, useInsertionEffect, useMemo, useRef } from "react";
|
|
4
|
+
import { isUnauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
4
5
|
import { NoticeContext } from "#internal/NoticeContext.ts";
|
|
5
6
|
import { publishNotice } from "#internal/noticeStore.ts";
|
|
6
|
-
import { requestsRecheck } from "#internal/sessionRecheck.ts";
|
|
7
7
|
import { useSessionRecheck } from "./sessionBoundary.js";
|
|
8
8
|
export function useActionSource(source, run, options) {
|
|
9
9
|
const registry = useContext(RegistryContext);
|
|
@@ -18,7 +18,7 @@ export function useActionSource(source, run, options) {
|
|
|
18
18
|
const lifetime = { active: false, registry };
|
|
19
19
|
function rejected(error, input) {
|
|
20
20
|
return Effect.gen(function* () {
|
|
21
|
-
if (lifetime.active &&
|
|
21
|
+
if (lifetime.active && isUnauthorized(error)) {
|
|
22
22
|
yield* Effect.sync(() => latestRef.current.recheck());
|
|
23
23
|
}
|
|
24
24
|
yield* Effect.sync(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionCompletion.js","sourceRoot":"","sources":["../../src/client/actionCompletion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"actionCompletion.js","sourceRoot":"","sources":["../../src/client/actionCompletion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AASzD,MAAM,UAAU,eAAe,CAC9B,MAA4E,EAC5E,GAA0E,EAC1E,OAAuC;IAEvC,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAC7C,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC;IACpC,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,OA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AE,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;IACjD,kBAAkB,CAAC,GAAG,EAAE;QACvB,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC;QAC7B,OAAO,GAAG,EAAE;YACX,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC;QAC/B,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACZ,OAAO,KAAK,CAAC,IAAI,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
2
|
+
import type * as Atom from "effect/reactivity/Atom";
|
|
3
|
+
import { type ReactNode } from "react";
|
|
4
|
+
export declare function SessionSignOut({ action, children, recheck, }: {
|
|
5
|
+
readonly action: Atom.Atom<AsyncResult.AsyncResult<unknown, unknown>>;
|
|
6
|
+
readonly children?: ReactNode;
|
|
7
|
+
readonly recheck: () => void;
|
|
8
|
+
}): ReactNode;
|
|
9
|
+
//# sourceMappingURL=SessionSignOut.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionSignOut.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/SessionSignOut.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAE5D,wBAAgB,cAAc,CAAC,EAC9B,MAAM,EACN,QAAQ,EACR,OAAO,GACP,EAAE;IACF,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IACtE,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;CAC7B,GAAG,SAAS,CAaZ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useAtomValue } from "@effect/atom-react";
|
|
2
|
+
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
export function SessionSignOut({ action, children, recheck, }) {
|
|
5
|
+
const result = useAtomValue(action);
|
|
6
|
+
const [held, hold] = useState(false);
|
|
7
|
+
const blocked = result.waiting || (held && !AsyncResult.isFailure(result));
|
|
8
|
+
if (held !== blocked) {
|
|
9
|
+
hold(blocked);
|
|
10
|
+
}
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (held && AsyncResult.isSuccess(result) && !result.waiting) {
|
|
13
|
+
recheck();
|
|
14
|
+
}
|
|
15
|
+
}, [held, result, recheck]);
|
|
16
|
+
return blocked ? null : children;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=SessionSignOut.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionSignOut.js","sourceRoot":"","sources":["../../../src/client/adapters/SessionSignOut.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAkB,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5D,MAAM,UAAU,cAAc,CAAC,EAC9B,MAAM,EACN,QAAQ,EACR,OAAO,GAKP;IACA,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACrC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3E,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACtB,IAAI,CAAC,OAAO,CAAC,CAAC;IACf,CAAC;IACD,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,IAAI,IAAI,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAC9D,OAAO,EAAE,CAAC;QACX,CAAC;IACF,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5B,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;AAClC,CAAC"}
|
|
@@ -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 @@
|
|
|
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 @@
|
|
|
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,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 @@
|
|
|
1
|
+
{"version":3,"file":"useSessionRetry.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useSessionRetry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAGvE,wBAAgB,eAAe,CAAC,OAAO,EAAE,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,IAAI,CA8CpI"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { RegistryContext } from "@effect/atom-react";
|
|
2
|
+
import { Effect, Fiber, Schedule } from "effect";
|
|
3
|
+
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
4
|
+
import { useContext, useEffect, useMemo } from "react";
|
|
5
|
+
import { useLatestCallback } from "#internal/adapters/useLatestCallback.ts";
|
|
6
|
+
export function useSessionRetry(recheck, identity) {
|
|
7
|
+
const registry = useContext(RegistryContext);
|
|
8
|
+
const latest = useLatestCallback(() => (Effect.isEffect(recheck) ? recheck : Effect.sync(recheck)));
|
|
9
|
+
const retry = useMemo(() => {
|
|
10
|
+
let running;
|
|
11
|
+
function stop() {
|
|
12
|
+
if (running) {
|
|
13
|
+
Effect.runFork(Fiber.interrupt(running));
|
|
14
|
+
running = undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function start() {
|
|
18
|
+
if (running || identity === undefined) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const fiber = Effect.runFork(Effect.suspend(latest).pipe(Effect.retry(Schedule.min([Schedule.exponential("1 second"), Schedule.spaced("30 seconds")])), Effect.provideService(AtomRegistry.AtomRegistry, registry)));
|
|
22
|
+
running = fiber;
|
|
23
|
+
fiber.addObserver(() => {
|
|
24
|
+
if (running === fiber) {
|
|
25
|
+
running = undefined;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function resume() {
|
|
30
|
+
if (running && window.document.visibilityState === "visible") {
|
|
31
|
+
stop();
|
|
32
|
+
start();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return { resume, start, stop };
|
|
36
|
+
}, [latest, registry, identity]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
window.addEventListener("online", retry.resume);
|
|
39
|
+
window.addEventListener("visibilitychange", retry.resume);
|
|
40
|
+
return () => {
|
|
41
|
+
window.removeEventListener("online", retry.resume);
|
|
42
|
+
window.removeEventListener("visibilitychange", retry.resume);
|
|
43
|
+
retry.stop();
|
|
44
|
+
};
|
|
45
|
+
}, [retry]);
|
|
46
|
+
return retry.start;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=useSessionRetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSessionRetry.js","sourceRoot":"","sources":["../../../src/client/adapters/useSessionRetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAE5E,MAAM,UAAU,eAAe,CAAC,OAA0D,EAAE,QAA4B;IACvH,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG,iBAAiB,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CA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C,CAAC,CAAC;IACjC,SAAS,CAAC,GAAG,EAAE;QACd,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAChD,MAAM,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAC1D,OAAO,GAAG,EAAE;YACX,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YACnD,MAAM,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YAC7D,KAAK,CAAC,IAAI,EAAE,CAAC;QACd,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACZ,OAAO,KAAK,CAAC,KAAK,CAAC;AACpB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Option } from "effect";
|
|
1
2
|
import * as Atom from "effect/reactivity/Atom";
|
|
2
3
|
declare module "@tanstack/react-router" {
|
|
3
4
|
interface HistoryState {
|
|
@@ -7,8 +8,8 @@ declare module "@tanstack/react-router" {
|
|
|
7
8
|
export declare function useSignOut<A, E>(action: Atom.AtomResultFn<void, A, E>, options: {
|
|
8
9
|
readonly signIn: string;
|
|
9
10
|
}): {
|
|
10
|
-
cause:
|
|
11
|
-
data:
|
|
11
|
+
cause: Option.Option<import("effect/Cause").Cause<E>>;
|
|
12
|
+
data: Option.Option<A>;
|
|
12
13
|
pending: boolean;
|
|
13
14
|
refreshing: boolean;
|
|
14
15
|
result: import("effect/reactivity/AsyncResult").AsyncResult<A, E>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSignOut.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useSignOut.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSignOut.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useSignOut.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAM/C,OAAO,QAAQ,wBAAwB,CAAC;IACvC,UAAU,YAAY;QACrB,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;KACrC;CACD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE;;;;;;;EAmD3G"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RegistryContext, useAtomMount } from "@effect/atom-react";
|
|
2
2
|
import { useRouter } from "@tanstack/react-router";
|
|
3
|
-
import { Effect } from "effect";
|
|
3
|
+
import { Effect, Option } from "effect";
|
|
4
4
|
import * as Atom from "effect/reactivity/Atom";
|
|
5
5
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
6
6
|
import { useContext, useEffect, useMemo } from "react";
|
|
@@ -30,6 +30,11 @@ export function useSignOut(action, options) {
|
|
|
30
30
|
useAtomMount(followUp);
|
|
31
31
|
useEffect(() => () => local.set(followUp, Atom.Interrupt), [local, followUp]);
|
|
32
32
|
const state = useAction(source);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (router && Option.isSome(state.cause) && !state.pending && router.history.location.state.__platformSignOut) {
|
|
35
|
+
router.history.replace(router.history.location.href, { ...router.history.location.state, __platformSignOut: false });
|
|
36
|
+
}
|
|
37
|
+
}, [router, state.cause, state.pending]);
|
|
33
38
|
return {
|
|
34
39
|
...state,
|
|
35
40
|
dispatch: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSignOut.js","sourceRoot":"","sources":["../../../src/client/adapters/useSignOut.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAA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
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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AAK,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,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,CAA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