@shivaedev/react 0.51.0 → 0.53.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 +27 -0
- package/README.md +73 -5
- package/dist/adapters/permissionBoundary.d.ts.map +1 -1
- package/dist/adapters/permissionBoundary.js +21 -2
- package/dist/adapters/permissionBoundary.js.map +1 -1
- package/dist/client/FailureHostContext.d.ts +1 -1
- package/dist/client/FailureHostContext.d.ts.map +1 -1
- package/dist/client/FailureHostContext.js.map +1 -1
- package/dist/client/NoticeContext.d.ts +1 -1
- package/dist/client/adapters/SessionGeneration.d.ts +6 -1
- package/dist/client/adapters/SessionGeneration.d.ts.map +1 -1
- package/dist/client/adapters/SessionGeneration.js +7 -2
- package/dist/client/adapters/SessionGeneration.js.map +1 -1
- package/dist/client/adapters/SessionSignOut.d.ts +2 -1
- package/dist/client/adapters/SessionSignOut.d.ts.map +1 -1
- package/dist/client/adapters/SessionSignOut.js +3 -2
- package/dist/client/adapters/SessionSignOut.js.map +1 -1
- package/dist/client/adapters/useFeedback.d.ts +1 -1
- package/dist/client/adapters/useFeedback.d.ts.map +1 -1
- package/dist/client/adapters/useFeedback.js +35 -20
- package/dist/client/adapters/useFeedback.js.map +1 -1
- package/dist/client/adapters/useStoredQueries.d.ts +7 -0
- package/dist/client/adapters/useStoredQueries.d.ts.map +1 -0
- package/dist/client/adapters/useStoredQueries.js +52 -0
- package/dist/client/adapters/useStoredQueries.js.map +1 -0
- package/dist/client/adapters/useWarmQueries.d.ts +4 -0
- package/dist/client/adapters/useWarmQueries.d.ts.map +1 -0
- package/dist/client/adapters/useWarmQueries.js +36 -0
- package/dist/client/adapters/useWarmQueries.js.map +1 -0
- package/dist/client/authSession.d.ts +10 -2
- package/dist/client/authSession.d.ts.map +1 -1
- package/dist/client/authSession.js +32 -3
- package/dist/client/authSession.js.map +1 -1
- package/dist/client/notices.d.ts.map +1 -1
- package/dist/client/notices.js +1 -3
- package/dist/client/notices.js.map +1 -1
- package/dist/client/sessionBoundary.d.ts +5 -2
- package/dist/client/sessionBoundary.d.ts.map +1 -1
- package/dist/client/sessionBoundary.js +7 -2
- package/dist/client/sessionBoundary.js.map +1 -1
- package/dist/noticeStore.d.ts +2 -2
- package/dist/noticeStore.d.ts.map +1 -1
- package/dist/noticeStore.js +4 -3
- package/dist/noticeStore.js.map +1 -1
- package/package.json +13 -13
- package/src/adapters/permissionBoundary.ts +23 -2
- package/src/client/FailureHostContext.ts +1 -1
- package/src/client/adapters/SessionGeneration.ts +13 -2
- package/src/client/adapters/SessionSignOut.ts +4 -1
- package/src/client/adapters/useFeedback.ts +22 -10
- package/src/client/adapters/useStoredQueries.ts +67 -0
- package/src/client/adapters/useWarmQueries.ts +39 -0
- package/src/client/authSession.ts +57 -4
- package/src/client/notices.ts +1 -3
- package/src/client/sessionBoundary.ts +12 -2
- package/src/noticeStore.ts +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.53.0 - 2026-11-20
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `SessionBoundary` takes `persist`, a storage Layer such as `browserQueryStorage`. Every result retention keeps is written to the device for the user `identify` names, within a second of settling and at once when the page hides, bounded by `queryRetention.capacity` and `queryRetention.storedBytes` (about 5 MB by default). The next generation for that user reads them before its first screen, so a reload shows the last results at once, marked `stale` and `refreshing` like retained ones, and a route loader commits without waiting. The boundary wipes stored results when the session ends or comes back signed out, and the previous user's when another user signs in. The person's data then rests on the device, readable by anyone using that browser profile.
|
|
8
|
+
- a sign-out through `SessionBoundary`'s `signOut` action wipes the stored results as soon as the request succeeds, and the remembered session too when `persist` also supplies the session memory, such as `Layer.merge(browserSessionMemory, browserQueryStorage)`.
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- when a command or form save succeeds, the failure notices that same hook published earlier go without Dismiss. A notice nobody resolves still stays until dismissed or expired.
|
|
13
|
+
|
|
14
|
+
### Breaking
|
|
15
|
+
|
|
16
|
+
- a function provided to `FailureHostContext` returns the published notice's dismiss function, or `undefined` when it published nothing.
|
|
17
|
+
|
|
18
|
+
## 0.52.0 - 2026-11-20
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- `authSession(read, { remember: browserSessionMemory })` answers at once with the remembered session, marked as refreshing, and checks the session in the background, so `SessionBoundary` renders and the live socket opens while the check is on the wire. The same user keeps the generation with refreshed permissions, another user starts a new one, a signed-out answer wipes the memory before the signed-out screen renders, a failed check keeps the remembered session rendering, and past the remembered expiry the launch waits for the check. With `remember`, the session's value is `RememberedSession | null`.
|
|
23
|
+
- with `remember`, the session has `signOut(request)`, which wipes the memory as soon as the sign-out request succeeds, so a relaunch starts without a remembered session even when the session check after the sign-out never answers.
|
|
24
|
+
- `SessionBoundary` takes `warm`, a function of the session's client that returns bound query atoms, such as `warm={(client) => [client.water.day.query({ date }), client.notes.list.query()]}`. Each listed query is mounted in the session's registry when the generation commits and stays subscribed until sign-out, another user or unmount, so a screen that reads it later renders its current value in its first render, also after a long idle stretch. The list is read again on every render and compared by atom identity: a changed payload opens the new query and hands the old one to retention. A warm query that no screen reads does not hold back `useFirstSettled`. Each listed query holds one subscription on the host for the whole session. Delete components that only mounted queries to keep them warm and list those queries instead.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- `PermissionBoundary` runs the router's guards again when the grants of its session change without a navigation, so a screen that needs a removed grant is replaced by the refusal.
|
|
29
|
+
|
|
3
30
|
## 0.51.0 - 2026-11-20
|
|
4
31
|
|
|
5
32
|
### Added
|
package/README.md
CHANGED
|
@@ -26,13 +26,13 @@ An **editor** joins a query atom, a form field schema and a save Effect. The que
|
|
|
26
26
|
|
|
27
27
|
Use `useConnectionStatus(client)` from `@shivaedev/react/client/adapters/useConnectionStatus.ts` with the client returned by contract's `makeClient`. It returns one `"live" | "reconnecting" | "waiting-for-connection"` value across mounted queries from every binding on that client's `Client` service. Live subscription status changes debounce for 300 ms on the client runtime's Clock. A bound command held for reconnection reports `"waiting-for-connection"` immediately, so the application can show Reconnecting while keeping the action pending. Contract holds unsent commands for up to 10 seconds and returns a typed `RpcClientError` on timeout; commands already sent are never replayed. The default socket probes Ping/Pong on browser or native resume and reconnects after 2.5 seconds without a Pong. 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.
|
|
28
28
|
|
|
29
|
-
Use `useFirstSettled(client)` from `@shivaedev/react/client/adapters/useFirstSettled.ts` with the same client to reveal a session's first screen in one step instead of one loading state per query. It returns `false` until a query mounted on that client has delivered its first success or failure and, with that, no mounted query awaits a first result and no command is in flight. From then on it returns `true` for that client: a later command or a newly mounted query does not turn it back. The signal belongs to the client, so a new session generation whose `connect` makes a new client starts at `false` again. A client whose screen mounts no query stays at `false`; gate only screens that read through the client.
|
|
29
|
+
Use `useFirstSettled(client)` from `@shivaedev/react/client/adapters/useFirstSettled.ts` with the same client to reveal a session's first screen in one step instead of one loading state per query. It returns `false` until a query mounted on that client has delivered its first success or failure and, with that, no mounted query awaits a first result and no command is in flight. From then on it returns `true` for that client: a later command or a newly mounted query does not turn it back. The signal belongs to the client, so a new session generation whose `connect` makes a new client starts at `false` again. A client whose screen mounts no query stays at `false`; gate only screens that read through the client. A query that only the session's [warm list](#keep-queries-warm-for-the-session) mounts does not hold it back while it awaits its first result.
|
|
30
30
|
|
|
31
31
|
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. The process holding the socket reloads the session and runs the read policy and handler for each subscriber independently. It stores one encoded-result hash per subscribed query in memory and pushes changed values; equal reads acknowledge completion without replacing the screen. Each subscription has at most one rerun in flight and one pending, merging further changes while busy. Other subscriptions run independently in parallel. Backlog overflow triggers a server `Resync`: the server reruns queries itself, and the client sends no follow-up reads. Query results stay in their native registry; RPC declarations and transport stay with native Effect and the application; this package supplies their React state and lifecycle boundary.
|
|
32
32
|
|
|
33
33
|
An explicit query refresh keeps the current data visible while reporting pending until the new subscription result arrives. Retryable connection failures keep that data visible during reconnection. Render read denials before retained data; replacing or ending the session disposes its registry.
|
|
34
34
|
|
|
35
|
-
Bound contract queries keep their last successful result for five minutes after the last reader leaves. Opening the same query in that window shows the kept value immediately with `stale: true` and `refreshing: true`, then replaces it when revalidation answers. Query execution and subscriptions stop while nobody reads. At most 100 idle results are kept per registry; the least recently left query is evicted first. Active readers do not consume that allowance. Set `queryRetention={{ timeToLive: "1 minute", capacity: 50 }}` on `SessionBoundary` to change these bounds; zero for either disables idle retention. Settings apply when a query becomes idle. Expiry uses the query runtime’s Effect Clock. Signing out or changing `identify(session)` disposes every kept result with the session registry. Results belong to individual queries, with no record sharing between them.
|
|
35
|
+
Bound contract queries keep their last successful result for five minutes after the last reader leaves. Opening the same query in that window shows the kept value immediately with `stale: true` and `refreshing: true`, then replaces it when revalidation answers. Query execution and subscriptions stop while nobody reads. At most 100 idle results are kept per registry; the least recently left query is evicted first. Active readers do not consume that allowance. Set `queryRetention={{ timeToLive: "1 minute", capacity: 50 }}` on `SessionBoundary` to change these bounds; zero for either disables idle retention. To keep results across a reload, see [`persist`](#keep-query-results-across-a-reload). Settings apply when a query becomes idle. Expiry uses the query runtime’s Effect Clock. Signing out or changing `identify(session)` disposes every kept result with the session registry. Results belong to individual queries, with no record sharing between them.
|
|
36
36
|
|
|
37
37
|
`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.
|
|
38
38
|
|
|
@@ -88,6 +88,58 @@ Pass the signed-out router as `signedOut` and the requested continuation address
|
|
|
88
88
|
|
|
89
89
|
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. Supply `runtime` on `SessionBoundary` to run these retries on a native atom runtime, including one carrying a story’s controlled Clock. 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.
|
|
90
90
|
|
|
91
|
+
#### Keep queries warm for the session
|
|
92
|
+
|
|
93
|
+
A screen's first visit, and a return after retention let its result go, wait one subscription round trip. Name the queries whose screens should open with current data in `SessionBoundary`'s `warm`, a function of the session's client that returns bound query atoms:
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
<SessionBoundary
|
|
97
|
+
session={session}
|
|
98
|
+
identify={(current) => current.user.id}
|
|
99
|
+
connect={connect}
|
|
100
|
+
recheck={recheck}
|
|
101
|
+
warm={(client) => [client.water.day.query({ date }), client.notes.list.query()]}
|
|
102
|
+
signedOut={<SignIn />}
|
|
103
|
+
>
|
|
104
|
+
{(client) => <Screens client={client} />}
|
|
105
|
+
</SessionBoundary>;
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`connect`, `date`, `SignIn` and `Screens` belong to the application; `date` is its own value, for example derived from `useNow`. The boundary mounts each listed query in the session's registry when the generation commits and keeps it subscribed until the session ends: sign-out, another user or unmount. The host pushes its changes, so a screen that reads it later renders the current value in its first render, with no request of its own. The list is read again on every render and compared by atom identity, and bound query atoms are cached per payload: when `date` changes, the new day's query opens and the previous one is handed to retention like a screen that closed. A warm query that no screen reads does not hold back `useFirstSettled`.
|
|
109
|
+
|
|
110
|
+
Each warm query holds one subscription on the host for the whole session, with its stored result hash and a rerun on each matching change, whether a screen shows it or not. The list must name the payload the screen reads: a query whose payload no screen asks for subscribes for nothing, and that screen stays cold.
|
|
111
|
+
|
|
112
|
+
#### Keep query results across a reload
|
|
113
|
+
|
|
114
|
+
A reload or relaunch starts with an empty registry, so the first screen waits for the session check, the socket and the first read. Pass a storage Layer as `persist`, and the last results show at once instead:
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
import { browserQueryStorage } from "@shivaedev/contract/adapters/browserQueryStorage.ts";
|
|
118
|
+
|
|
119
|
+
<SessionBoundary session={session} identify={(current) => current.user.id} connect={connect} recheck={recheck} persist={browserQueryStorage}>
|
|
120
|
+
{(client) => <Screens client={client} />}
|
|
121
|
+
</SessionBoundary>;
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Every bound query result that retention keeps is also written to the device under the user that `identify` names, in IndexedDB with `browserQueryStorage`. A result is written within a second of settling on the query runtime's Clock, and at once when the page hides. Storage keeps at most `queryRetention.capacity` results (100 by default) and about 5 MB of encoded results (`queryRetention={{ storedBytes }}` changes it), and drops the least recently settled first. When a generation starts, the boundary reads that user's stored results before it renders the first screen, and they seed retention: `useQuery`, a route's `useQuery()`, `QueryView` and `loadQuery` see a stored result as they see a retained one, with `stale: true` and `refreshing: true`, and a route loader commits at once while the subscription revalidates it. Each result is encoded with its operation's success schema; nothing is declared per query. Every result of a query the session reads is stored on the device, whatever its model marks. Fields a model keeps server-only never reach the client, so they are never stored. An application that does not want results at rest leaves `persist` off.
|
|
125
|
+
|
|
126
|
+
The boundary wipes stored results when `session` becomes `undefined` (a sign-out or a signed-out answer of the session check, including at launch) and the previous user's results when another user signs in. A query that answers `QueryReadDenied` or `NotFound`, or whose stored value no longer decodes, loses its entry. Storage the browser refuses leaves the generation without stored results.
|
|
127
|
+
|
|
128
|
+
With a [remembered session](#better-auth-actions), give `authSession`'s `remember` and `persist` one Layer, so the two are wiped together:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { Layer } from "effect";
|
|
132
|
+
import { browserQueryStorage } from "@shivaedev/contract/adapters/browserQueryStorage.ts";
|
|
133
|
+
import { browserSessionMemory } from "@shivaedev/identity/client/adapters/browserSessionMemory.ts";
|
|
134
|
+
|
|
135
|
+
export const deviceStorage = Layer.merge(browserSessionMemory, browserQueryStorage);
|
|
136
|
+
// authSession(read, { remember: deviceStorage }) and <SessionBoundary persist={deviceStorage} …>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Identity's `forgetSession` then wipes the stored results with the memory, which covers a passed expiry at launch as well. A sign-out through `SessionBoundary`'s `signOut` action wipes both as soon as the sign-out request succeeds, even when the session check after it never answers. Dispatch that action with [`useSignOut`](#better-auth-actions), which runs it in the auth owner's registry where the boundary watches it.
|
|
140
|
+
|
|
141
|
+
What this means for the person using the application: their data rests on the device, readable by anyone using that browser profile. Signing out on another device cannot erase it until the application next runs online here. A stored result can be days old; it shows as updating until the live result arrives, one subscription round trip after the socket opens.
|
|
142
|
+
|
|
91
143
|
#### Session-scoped bindings
|
|
92
144
|
|
|
93
145
|
A contract declared with `keyScope: "session"` binds to the registry that owns the session's queries. In the browser, `bind` prefixes every client read and invalidation key of that contract with an opaque id of its registry, so a successful command in one session refreshes none of another session's queries on the page, even when both registries share one runtime. The server adds no prefix: its subscriptions and committed writes use plain keys, and each query's read policy decides what a viewer receives. The [contract guide](https://github.com/ShivaeDev/platform/blob/main/packages/contract/README.md#session-owned-keys) describes the declaration and its handlers. `SessionBoundary` passes that registry to `connect` as its second argument:
|
|
@@ -446,6 +498,8 @@ A bound command given to `useAction`, `usePendingCommand` or `useUndoableChange`
|
|
|
446
498
|
- A rejection the app declared for itself has no default. The call does not compile until `failures` says what it shows.
|
|
447
499
|
- Interrupted work shows nothing.
|
|
448
500
|
|
|
501
|
+
The framework words every shared rejection it raises for the person using the application, so its message shows as it arrives: a missing session says `Sign in to continue` and a missing permission `You do not have permission to do this.`, with no `failures` handler to undo developer wording. When the same hook's command or save later succeeds, the failure notices it published go without Dismiss; a notice nobody resolves stays until dismissed or expired.
|
|
502
|
+
|
|
449
503
|
`failureKind` from `@shivaedev/contract/failureKind.ts` holds that classification, `AppRejection<E>` names the app's own rejections in an error type, and `RequestRejection` and `ServerFailure` in `@shivaedev/errors/taxonomy.ts` name the shared ones.
|
|
450
504
|
|
|
451
505
|
```tsx
|
|
@@ -791,6 +845,7 @@ import { can } from "@shivaedev/react/can.ts";
|
|
|
791
845
|
import { queryRoute } from "@shivaedev/react/client/adapters/queryRoute.ts";
|
|
792
846
|
import { api, registry } from "./notes-client.ts";
|
|
793
847
|
import { auth, SignIn } from "./auth.tsx";
|
|
848
|
+
import { navigateTo } from "./adapters/navigateTo.ts";
|
|
794
849
|
|
|
795
850
|
const ReadNotes = permission("notes.read");
|
|
796
851
|
const root = createRootRouteWithContext<{
|
|
@@ -829,7 +884,7 @@ const login = createRoute({
|
|
|
829
884
|
}),
|
|
830
885
|
component: () => {
|
|
831
886
|
const { returnTo } = login.useSearch();
|
|
832
|
-
return <SignIn onSignedIn={() => router
|
|
887
|
+
return <SignIn onSignedIn={() => navigateTo(router, returnTo)} />;
|
|
833
888
|
},
|
|
834
889
|
});
|
|
835
890
|
const router = createRouter({
|
|
@@ -875,8 +930,21 @@ export function App({ session }: { readonly session: PermissionSession | undefin
|
|
|
875
930
|
const showNotes = can(auth.session, ReadNotes);
|
|
876
931
|
```
|
|
877
932
|
|
|
933
|
+
TanStack's `navigate` answers with a Promise, so the sign-in callback starts the navigation through a module in `adapters/`:
|
|
934
|
+
|
|
935
|
+
```ts
|
|
936
|
+
// adapters/navigateTo.ts
|
|
937
|
+
import type { AnyRouter } from "@tanstack/react-router";
|
|
938
|
+
|
|
939
|
+
export function navigateTo(router: AnyRouter, href: string): void {
|
|
940
|
+
void router.navigate({ href });
|
|
941
|
+
}
|
|
942
|
+
```
|
|
943
|
+
|
|
878
944
|
`auth` owns the current session and passes it to `App`; `SignIn` updates that session before invoking `onSignedIn`. Use the session's registry for router context and React, as with other query routes. Importing `permissionGuard` augments TanStack's `StaticDataRouteOption`; route options and their inference remain native. The guard returns `void` explicitly, so `beforeLoad` needs no return annotation, including when it reads the session from route context.
|
|
879
945
|
|
|
946
|
+
`PermissionBoundary` runs the guards again when the grants of its `session` change without a navigation, such as a remembered session whose check answers with fewer grants, so a screen that needs a removed grant is replaced by the refusal. The application writes nothing for it; the boundary invalidates the router it renders inside.
|
|
947
|
+
|
|
880
948
|
`InnerWrap` puts `PermissionBoundary` inside the router, and the boundary's fallback can render `Link` and read route context. TanStack types `InnerWrap` as a component that returns an element, so `PermissionShell` leaves its return type to inference; annotated as returning `ReactNode`, it does not compile. Set `defaultErrorComponent: PermissionBoundaryError` so route and loader failures reach the boundary's fallback while TanStack keeps its navigation controller mounted. This lets a refused viewer follow the fallback link without reloading the page. Keep `disableGlobalCatchBoundary: true`; other errors propagate to an enclosing application boundary. A route-specific `errorComponent` owns any failures it consumes.
|
|
881
949
|
|
|
882
950
|
`Forbidden` from `@shivaedev/react/adapters/Forbidden.ts` supplies the no-access heading, explanation and a router link. Set `to` to a route the viewer may open. Optional `title`, `children`, `backLabel` and `className` let the application choose wording and layout. The default heading is “Permission denied” and the link says “Go back”.
|
|
@@ -906,7 +974,7 @@ function SignInButton({ email, password }: { email: string; password: string })
|
|
|
906
974
|
|
|
907
975
|
The example uses `authAction`, identity's `authCall`, `useAction`, `effect/reactivity/AsyncResult` and `effect/Option`, with an application-owned `authClient`. Identity owns the Promise bridge and its typed failures; see [Better Auth client adapters](https://github.com/ShivaeDev/platform/blob/main/packages/identity/README.md#better-auth-client-adapters). For a form's Effect-based `onSubmit`, pass the function returned by `authCall` directly.
|
|
908
976
|
|
|
909
|
-
Use `authSession` from `@shivaedev/react/client/authSession.ts` to wrap identity's session Effect. It returns a native `atom` for `useQuery` and a `refresh` Effect that refreshes that same atom and waits through its loading state. Both expose typed `user.permissions` alongside the provider's existing session and user fields, using the `PermissionSession` schema from `@shivaedev/identity/PermissionSession.ts`. Applications do not decode `get-session` themselves. Missing grants stay optional; malformed grants fail with `AuthUnavailable`. The reader must return a nullable session with a `user` object; use `authQuery` for other payload shapes. Supply Better Auth's public `getSession` call with `disableCookieCache: true` so a mutation reads current user data:
|
|
977
|
+
Use `authSession` from `@shivaedev/react/client/authSession.ts` to wrap identity's session Effect. It returns a native `atom` for `useQuery` and a `refresh` Effect that refreshes that same atom and waits through its loading state. Both expose typed `user.permissions` alongside the provider's existing session and user fields, using the `PermissionSession` schema from `@shivaedev/identity/PermissionSession.ts`. Applications do not decode `get-session` themselves. Missing grants stay optional; malformed grants fail with `AuthUnavailable`. The reader must return a nullable session with a `user` object; use `authQuery` for other payload shapes. Pass `{ remember: browserSessionMemory }` as the second argument to start a returning person's app from the last verified session while the check runs; see [identity's remembered session](https://github.com/ShivaeDev/platform/blob/main/packages/identity/README.md#start-from-the-last-verified-session) for what it keeps and what it means. With `remember`, the session also has `signOut(request)`, which wipes the memory when the sign-out request succeeds. Supply Better Auth's public `getSession` call with `disableCookieCache: true` so a mutation reads current user data:
|
|
910
978
|
|
|
911
979
|
```tsx
|
|
912
980
|
import { Effect } from "effect";
|
|
@@ -940,7 +1008,7 @@ The example uses `Option` from `effect` and the application's Better Auth client
|
|
|
940
1008
|
|
|
941
1009
|
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.
|
|
942
1010
|
|
|
943
|
-
Pass the auth owner’s sign-out atom to `SessionBoundary` as `signOut={signOut}
|
|
1011
|
+
Pass the auth owner’s sign-out atom to `SessionBoundary` as `signOut={signOut}` and dispatch it with `useSignOut` below. 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.
|
|
944
1012
|
|
|
945
1013
|
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. `signInRedirect` 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.
|
|
946
1014
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permissionBoundary.d.ts","sourceRoot":"","sources":["../../src/adapters/permissionBoundary.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"permissionBoundary.d.ts","sourceRoot":"","sources":["../../src/adapters/permissionBoundary.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,SAAS,EAAiC,MAAM,OAAO,CAAC;AACrF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAIlF,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,CAAC;CACvD;AAED,wBAAgB,MAAM,IAAI,CAAC,UAAU,EAAE,UAAU,KAAK,OAAO,CAG5D;AAED,wBAAgB,uBAAuB,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,CAMzF;AAsBD,wBAAgB,kBAAkB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,uBAAuB,GAAG,SAAS,CAOtG"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CatchBoundary } from "@tanstack/react-router";
|
|
2
|
-
import { createElement, useContext } from "react";
|
|
1
|
+
import { CatchBoundary, useRouter } from "@tanstack/react-router";
|
|
2
|
+
import { createElement, useContext, useEffect, useRef } from "react";
|
|
3
3
|
import { isForbidden } from "@shivaedev/errors/taxonomy.ts";
|
|
4
4
|
import { PermissionContext } from "#adapters/PermissionContext.ts";
|
|
5
5
|
import { can } from "#can.ts";
|
|
@@ -14,7 +14,26 @@ export function PermissionBoundaryError({ error }) {
|
|
|
14
14
|
}
|
|
15
15
|
return context?.fallback;
|
|
16
16
|
}
|
|
17
|
+
function grantKey(session) {
|
|
18
|
+
return (session?.user.permissions ?? [])
|
|
19
|
+
.map((grant) => `${grant.name}:${grant.strength}`)
|
|
20
|
+
.sort()
|
|
21
|
+
.join(",");
|
|
22
|
+
}
|
|
23
|
+
// Route guards read the session when a navigation loads, so a session refreshed in place reruns them here.
|
|
24
|
+
function useGuardRerun(session) {
|
|
25
|
+
const router = useRouter({ warn: false });
|
|
26
|
+
const grants = grantKey(session);
|
|
27
|
+
const guardedRef = useRef(grants);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (guardedRef.current !== grants) {
|
|
30
|
+
guardedRef.current = grants;
|
|
31
|
+
void router?.invalidate();
|
|
32
|
+
}
|
|
33
|
+
}, [router, grants]);
|
|
34
|
+
}
|
|
17
35
|
export function PermissionBoundary({ children, fallback, session }) {
|
|
36
|
+
useGuardRerun(session);
|
|
18
37
|
return createElement(PermissionContext.Provider, { value: { fallback, session } }, createElement(CatchBoundary, { children, errorComponent: PermissionBoundaryError, getResetKey: () => "permission" }));
|
|
19
38
|
}
|
|
20
39
|
//# sourceMappingURL=permissionBoundary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permissionBoundary.js","sourceRoot":"","sources":["../../src/adapters/permissionBoundary.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"permissionBoundary.js","sourceRoot":"","sources":["../../src/adapters/permissionBoundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,aAAa,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,aAAa,EAAkB,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAErF,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAQ9B,MAAM,UAAU,MAAM;IACrB,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC;IAC9C,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AAO,aAAa,CACnB,iBAAiB,CAAC,QAAQ,EAC1B,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAChC,aAAa,CAAC,aAAa,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,uBAAuB,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,CACpH,CAAC;AACH,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { UnexpectedFailure } from "#client/unexpectedFailure.ts";
|
|
2
|
-
export declare const FailureHostContext: import("react").Context<((failure: UnexpectedFailure) => void) | undefined>;
|
|
2
|
+
export declare const FailureHostContext: import("react").Context<((failure: UnexpectedFailure) => (() => void) | undefined) | undefined>;
|
|
3
3
|
//# sourceMappingURL=FailureHostContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FailureHostContext.d.ts","sourceRoot":"","sources":["../../src/client/FailureHostContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,eAAO,MAAM,kBAAkB,qCAA4B,iBAAiB,KAAK,IAAI,cAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"FailureHostContext.d.ts","sourceRoot":"","sources":["../../src/client/FailureHostContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,eAAO,MAAM,kBAAkB,qCAA4B,iBAAiB,KAAK,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,cAAyB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FailureHostContext.js","sourceRoot":"","sources":["../../src/client/FailureHostContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAGtC,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"FailureHostContext.js","sourceRoot":"","sources":["../../src/client/FailureHostContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAGtC,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAyE,SAAS,CAAC,CAAC"}
|
|
@@ -3,6 +3,6 @@ export declare const NoticeContext: import("react").Context<{
|
|
|
3
3
|
active: boolean;
|
|
4
4
|
close: () => void;
|
|
5
5
|
entries: import("effect/reactivity/Atom").Writable<readonly import("../noticeEntry.ts").NoticeEntry<ReactNode>[], readonly import("../noticeEntry.ts").NoticeEntry<ReactNode>[]>;
|
|
6
|
-
publish: (descriptor: Pick<import("../noticeTypes.ts").NoticeDescriptor<never, ReactNode>, "expiresIn" | "message">, kind: import("../noticeEntry.ts").NoticeKind, action?: import("../noticeEntry.ts").NoticeAction<ReactNode> | undefined) => void;
|
|
6
|
+
publish: (descriptor: Pick<import("../noticeTypes.ts").NoticeDescriptor<never, ReactNode>, "expiresIn" | "message">, kind: import("../noticeEntry.ts").NoticeKind, action?: import("../noticeEntry.ts").NoticeAction<ReactNode> | undefined) => (() => void) | undefined;
|
|
7
7
|
} | undefined>;
|
|
8
8
|
//# sourceMappingURL=NoticeContext.d.ts.map
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
+
import { type Layer } from "effect";
|
|
2
|
+
import type * as Atom from "effect/reactivity/Atom";
|
|
1
3
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
2
4
|
import { type ReactNode } from "react";
|
|
5
|
+
import type { QueryStorageProvider } from "@shivaedev/contract/QueryStorage.ts";
|
|
3
6
|
import { type QueryRetentionOptions } from "@shivaedev/contract/queryRetention.ts";
|
|
4
7
|
interface SessionGenerationProps<TSession, TClient> {
|
|
5
8
|
readonly children: (client: TClient) => ReactNode;
|
|
6
9
|
readonly connect: (session: TSession, registry: AtomRegistry.AtomRegistry) => TClient;
|
|
7
10
|
readonly identity: string | undefined;
|
|
11
|
+
readonly persist?: Layer.Layer<QueryStorageProvider> | undefined;
|
|
8
12
|
readonly queryRetention?: QueryRetentionOptions | undefined;
|
|
9
13
|
readonly recheck: () => void;
|
|
10
14
|
readonly session: TSession;
|
|
15
|
+
readonly warm?: ((client: TClient) => readonly Atom.Atom<unknown>[]) | undefined;
|
|
11
16
|
}
|
|
12
|
-
export declare function SessionGeneration<TSession, TClient>({ session, connect, recheck, children, identity, queryRetention: retention, }: SessionGenerationProps<TSession, TClient>): ReactNode;
|
|
17
|
+
export declare function SessionGeneration<TSession, TClient>({ session, connect, recheck, children, identity, persist, queryRetention: retention, warm, }: SessionGenerationProps<TSession, TClient>): ReactNode;
|
|
13
18
|
export {};
|
|
14
19
|
//# sourceMappingURL=SessionGeneration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionGeneration.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/SessionGeneration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SessionGeneration.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/SessionGeneration.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAiB,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAG3E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,KAAK,qBAAqB,EAAkB,MAAM,uCAAuC,CAAC;AA+DnG,UAAU,sBAAsB,CAAC,QAAQ,EAAE,OAAO;IACjD,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,SAAS,CAAC;IAClD,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,YAAY,KAAK,OAAO,CAAC;IACtF,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,oBAAoB,CAAC,GAAG,SAAS,CAAC;IACjE,QAAQ,CAAC,cAAc,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;IAC5D,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC;CACjF;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,EACpD,OAAO,EACP,OAAO,EACP,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,cAAc,EAAE,SAAS,EACzB,IAAI,GACJ,EAAE,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,SAAS,CA+BvD"}
|
|
@@ -7,6 +7,8 @@ import { liveBindings } from "@shivaedev/contract/composeBindings.ts";
|
|
|
7
7
|
import { queryRetention } from "@shivaedev/contract/queryRetention.ts";
|
|
8
8
|
import { registerSessionRecheck } from "#adapters/sessionRecheck.ts";
|
|
9
9
|
import { useLatestCallback } from "#adapters/useLatestCallback.ts";
|
|
10
|
+
import { useStoredQueries } from "#client/adapters/useStoredQueries.ts";
|
|
11
|
+
import { useWarmQueries } from "#client/adapters/useWarmQueries.ts";
|
|
10
12
|
import { mountLive } from "#client/mountLive.ts";
|
|
11
13
|
import { RecheckContext } from "#client/RecheckContext.ts";
|
|
12
14
|
function owning(connection, identity, retention) {
|
|
@@ -47,7 +49,8 @@ function hidden(connection, identity, retention) {
|
|
|
47
49
|
};
|
|
48
50
|
return owned;
|
|
49
51
|
}
|
|
50
|
-
|
|
52
|
+
const NOTHING_WARM = [];
|
|
53
|
+
export function SessionGeneration({ session, connect, recheck, children, identity, persist, queryRetention: retention, warm, }) {
|
|
51
54
|
const recheckLatest = useLatestCallback(recheck);
|
|
52
55
|
const [connection] = useState(() => ({ connect, session }));
|
|
53
56
|
const [owned, own] = useState(() => owning(connection, identity, retention));
|
|
@@ -71,6 +74,8 @@ export function SessionGeneration({ session, connect, recheck, children, identit
|
|
|
71
74
|
});
|
|
72
75
|
};
|
|
73
76
|
}, [identity, owned, connection]);
|
|
74
|
-
|
|
77
|
+
const ready = useStoredQueries(owned.registry, persist, identity);
|
|
78
|
+
useWarmQueries(owned.registry, (ready ? warm?.(owned.client) : undefined) ?? NOTHING_WARM);
|
|
79
|
+
return createElement(RecheckContext.Provider, { value: recheckLatest }, createElement(RegistryContext.Provider, { value: owned.registry }, ready ? children(owned.client) : null));
|
|
75
80
|
}
|
|
76
81
|
//# sourceMappingURL=SessionGeneration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionGeneration.js","sourceRoot":"","sources":["../../../src/client/adapters/SessionGeneration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"SessionGeneration.js","sourceRoot":"","sources":["../../../src/client/adapters/SessionGeneration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAC;AAE5C,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAkB,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAEtE,OAAO,EAA8B,cAAc,EAAE,MAAM,u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C,CAAC,SAAS,CAAC,IAAI,YAAY,CAAC,CAAC;IAC3F,OAAO,aAAa,CACnB,cAAc,CAAC,QAAQ,EACvB,EAAE,KAAK,EAAE,aAAa,EAAE,EACxB,aAAa,CAAC,eAAe,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CACzG,CAAC;AACH,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
2
2
|
import type * as Atom from "effect/reactivity/Atom";
|
|
3
3
|
import { type ReactNode } from "react";
|
|
4
|
-
export declare function SessionSignOut({ action, children, recheck, }: {
|
|
4
|
+
export declare function SessionSignOut({ action, children, recheck, wipe, }: {
|
|
5
5
|
readonly action: Atom.Atom<AsyncResult.AsyncResult<unknown, unknown>>;
|
|
6
6
|
readonly children?: ReactNode;
|
|
7
7
|
readonly recheck: () => void;
|
|
8
|
+
readonly wipe: () => void;
|
|
8
9
|
}): ReactNode;
|
|
9
10
|
//# sourceMappingURL=SessionSignOut.d.ts.map
|
|
@@ -1 +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,
|
|
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,EACP,IAAI,GACJ,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;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;CAC1B,GAAG,SAAS,CAcZ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useAtomValue } from "@effect/atom-react";
|
|
2
2
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
3
|
import { useEffect, useState } from "react";
|
|
4
|
-
export function SessionSignOut({ action, children, recheck, }) {
|
|
4
|
+
export function SessionSignOut({ action, children, recheck, wipe, }) {
|
|
5
5
|
const result = useAtomValue(action);
|
|
6
6
|
const [held, hold] = useState(false);
|
|
7
7
|
const blocked = result.waiting || (held && !AsyncResult.isFailure(result));
|
|
@@ -10,9 +10,10 @@ export function SessionSignOut({ action, children, recheck, }) {
|
|
|
10
10
|
}
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
if (held && AsyncResult.isSuccess(result) && !result.waiting) {
|
|
13
|
+
wipe();
|
|
13
14
|
recheck();
|
|
14
15
|
}
|
|
15
|
-
}, [held, result, recheck]);
|
|
16
|
+
}, [held, result, recheck, wipe]);
|
|
16
17
|
return blocked ? null : children;
|
|
17
18
|
}
|
|
18
19
|
//# sourceMappingURL=SessionSignOut.js.map
|
|
@@ -1 +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,
|
|
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,EACP,IAAI,GAMJ;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,IAAI,EAAE,CAAC;YACP,OAAO,EAAE,CAAC;QACX,CAAC;IACF,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;IAClC,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;AAClC,CAAC"}
|
|
@@ -6,6 +6,6 @@ import type { FailureChoices } from "#client/failures.ts";
|
|
|
6
6
|
import type { NoticeDescriptor } from "#client/notices.ts";
|
|
7
7
|
export declare function useFeedback<R, E>(runtime: Atom.AtomRuntime<R, E> | undefined): {
|
|
8
8
|
failed: (cause: Cause.Cause<unknown>, input: unknown, choices: FailureChoices, field?: (error: unknown) => FieldRejection<string> | undefined) => Decision<R>;
|
|
9
|
-
succeeded: (descriptor: NoticeDescriptor<R> | undefined) => void
|
|
9
|
+
succeeded: (descriptor: NoticeDescriptor<R> | undefined) => void;
|
|
10
10
|
};
|
|
11
11
|
//# sourceMappingURL=useFeedback.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFeedback.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useFeedback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAU,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAEpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAExE,OAAO,EAAE,KAAK,QAAQ,EAAU,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAW3D,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS;
|
|
1
|
+
{"version":3,"file":"useFeedback.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useFeedback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAU,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAEpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAExE,OAAO,EAAE,KAAK,QAAQ,EAAU,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAW3D,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS;oBAYlE,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,SACpB,OAAO,WACL,cAAc,UAChB,CAAC,KAAK,EAAE,OAAO,KAAK,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS,KAC3D,QAAQ,CAAC,CAAC,CAAC;4BAgBU,gBAAgB,CAAC,CAAC,CAAC,GAAG,SAAS;EAUzD"}
|
|
@@ -10,29 +10,44 @@ function noField() {
|
|
|
10
10
|
return undefined;
|
|
11
11
|
}
|
|
12
12
|
// An operation's owner presents each settled invocation once, so a failure reaches the screen or the failure host once however many
|
|
13
|
-
// components read the same result.
|
|
13
|
+
// components read the same result. Its later success means the problem is solved, so the failure notices it published go.
|
|
14
14
|
export function useFeedback(runtime) {
|
|
15
15
|
const store = useContext(NoticeContext);
|
|
16
16
|
const host = useContext(FailureHostContext);
|
|
17
|
-
return useMemo(() =>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
host?.(unexpectedFailure(cause));
|
|
23
|
-
}
|
|
24
|
-
return nothing;
|
|
25
|
-
}
|
|
26
|
-
const decision = decide(error.value, input, choices, field);
|
|
27
|
-
if (decision._tag === "notice" && runtime) {
|
|
28
|
-
publishNotice(store, runtime, decision.descriptor, "rejection");
|
|
17
|
+
return useMemo(() => {
|
|
18
|
+
const published = [];
|
|
19
|
+
function track(dismiss) {
|
|
20
|
+
if (dismiss) {
|
|
21
|
+
published.push(dismiss);
|
|
29
22
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
failed: (cause, input, choices, field = noField) => {
|
|
26
|
+
const error = Cause.findErrorOption(cause);
|
|
27
|
+
if (Option.isNone(error)) {
|
|
28
|
+
if (Cause.hasDies(cause) && !choices.silent) {
|
|
29
|
+
track(host?.(unexpectedFailure(cause)));
|
|
30
|
+
}
|
|
31
|
+
return nothing;
|
|
32
|
+
}
|
|
33
|
+
const decision = decide(error.value, input, choices, field);
|
|
34
|
+
if (decision._tag === "notice" && runtime) {
|
|
35
|
+
track(publishNotice(store, runtime, decision.descriptor, "rejection"));
|
|
36
|
+
}
|
|
37
|
+
else if (decision._tag === "unexpected") {
|
|
38
|
+
track(host?.(unexpectedFailure(cause)));
|
|
39
|
+
}
|
|
40
|
+
return decision;
|
|
41
|
+
},
|
|
42
|
+
succeeded: (descriptor) => {
|
|
43
|
+
for (const dismiss of published.splice(0)) {
|
|
44
|
+
dismiss();
|
|
45
|
+
}
|
|
46
|
+
if (runtime) {
|
|
47
|
+
publishNotice(store, runtime, descriptor, "success");
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}, [host, runtime, store]);
|
|
37
52
|
}
|
|
38
53
|
//# sourceMappingURL=useFeedback.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFeedback.js","sourceRoot":"","sources":["../../../src/client/adapters/useFeedback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAiB,MAAM,EAAE,MAAM,4BAA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E,SAAS,CAAC,CAAC;gBACtD,CAAC;YACF,CAAC;SACD,CAAC;IACH,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Layer } from "effect";
|
|
2
|
+
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
3
|
+
import type { QueryStorageProvider } from "@shivaedev/contract/QueryStorage.ts";
|
|
4
|
+
export declare function useStoredQueries(registry: AtomRegistry.AtomRegistry, persist: Layer.Layer<QueryStorageProvider> | undefined, identity: string | undefined): boolean;
|
|
5
|
+
export declare function useStoredQueryWipes(persist: Layer.Layer<QueryStorageProvider> | undefined, identity: string | undefined): void;
|
|
6
|
+
export declare function useDeviceWipe(persist: Layer.Layer<QueryStorageProvider> | undefined): () => void;
|
|
7
|
+
//# sourceMappingURL=useStoredQueries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStoredQueries.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useStoredQueries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,KAAK,EAAU,MAAM,QAAQ,CAAC;AAC1D,OAAO,KAAK,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAIpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAQhF,wBAAgB,gBAAgB,CAC/B,QAAQ,EAAE,YAAY,CAAC,YAAY,EACnC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,oBAAoB,CAAC,GAAG,SAAS,EACtD,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC1B,OAAO,CAuBT;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,oBAAoB,CAAC,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,QAUvH;AAQD,wBAAgB,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,oBAAoB,CAAC,GAAG,SAAS,GAAG,MAAM,IAAI,CAMhG"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Effect, Exit, Option } from "effect";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { queryPersistence } from "@shivaedev/contract/adapters/queryPersistence.ts";
|
|
4
|
+
import { clearStoredQueries, openStoredQueries } from "@shivaedev/contract/adapters/storedQueryAccess.ts";
|
|
5
|
+
import { storedQueries } from "@shivaedev/contract/storedQueries.ts";
|
|
6
|
+
import { forgetSession, SessionMemory } from "@shivaedev/identity/client/SessionMemory.ts";
|
|
7
|
+
import { pageHidden } from "#client/pageHidden.ts";
|
|
8
|
+
// The first screen renders once the user's stored results seed retention, so a loader finds them as retained values.
|
|
9
|
+
export function useStoredQueries(registry, persist, identity) {
|
|
10
|
+
const [opened, open] = useState(() => (persist === undefined || identity === undefined ? { storage: undefined } : undefined));
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (persist === undefined || identity === undefined) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
return Effect.runCallback(openStoredQueries(identity).pipe(Effect.provide(persist)), {
|
|
16
|
+
onExit: (exit) => open({ storage: Exit.isSuccess(exit) ? exit.value : undefined }),
|
|
17
|
+
});
|
|
18
|
+
}, [persist, identity]);
|
|
19
|
+
if (opened?.storage !== undefined && registry.get(storedQueries) !== opened.storage) {
|
|
20
|
+
registry.set(storedQueries, opened.storage);
|
|
21
|
+
}
|
|
22
|
+
useEffect(() => registry.subscribe(pageHidden, (hidden) => {
|
|
23
|
+
if (hidden) {
|
|
24
|
+
registry.get(queryPersistence)?.flush();
|
|
25
|
+
}
|
|
26
|
+
}), [registry]);
|
|
27
|
+
return opened !== undefined;
|
|
28
|
+
}
|
|
29
|
+
export function useStoredQueryWipes(persist, identity) {
|
|
30
|
+
const previousRef = useRef(identity);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const before = previousRef.current;
|
|
33
|
+
previousRef.current = identity;
|
|
34
|
+
if (persist === undefined || (identity !== undefined && (before === undefined || before === identity))) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
Effect.runFork(clearStoredQueries(identity === undefined ? undefined : before).pipe(Effect.provide(persist)));
|
|
38
|
+
}, [persist, identity]);
|
|
39
|
+
}
|
|
40
|
+
// A storage Layer that also supplies the remembered session forgets it in the same wipe, so a sign-out through the boundary leaves neither behind.
|
|
41
|
+
const deviceWipe = Effect.gen(function* () {
|
|
42
|
+
const memory = yield* Effect.serviceOption(SessionMemory);
|
|
43
|
+
yield* Option.isSome(memory) ? forgetSession.pipe(Effect.provideService(SessionMemory, memory.value)) : clearStoredQueries();
|
|
44
|
+
});
|
|
45
|
+
export function useDeviceWipe(persist) {
|
|
46
|
+
return useCallback(() => {
|
|
47
|
+
if (persist !== undefined) {
|
|
48
|
+
Effect.runFork(deviceWipe.pipe(Effect.provide(persist)));
|
|
49
|
+
}
|
|
50
|
+
}, [persist]);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=useStoredQueries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStoredQueries.js","sourceRoot":"","sources":["../../../src/client/adapters/useStoredQueries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAc,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kDAAkD,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mDAAmD,CAAC;AAE1G,OAAO,EAA2B,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC9F,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAC3F,OAAO,EAAE,UAAU,E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AC,GAAG,EAAE;QACvB,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC1D,CAAC;IACF,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type * as Atom from "effect/reactivity/Atom";
|
|
2
|
+
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
3
|
+
export declare function useWarmQueries(registry: AtomRegistry.AtomRegistry, queries: readonly Atom.Atom<unknown>[]): void;
|
|
4
|
+
//# sourceMappingURL=useWarmQueries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWarmQueries.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useWarmQueries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAiCpE,wBAAgB,cAAc,CAAC,QAAQ,EAAE,YAAY,CAAC,YAAY,EAAE,OAAO,EAAE,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,QAIzG"}
|