@shivaedev/react 0.27.0 → 0.28.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 +30 -0
- package/README.md +66 -42
- package/dist/client/actionCompletion.d.ts.map +1 -1
- package/dist/client/actionCompletion.js +3 -2
- package/dist/client/actionCompletion.js.map +1 -1
- package/dist/client/adapters/SessionGeneration.d.ts +14 -0
- package/dist/client/adapters/SessionGeneration.d.ts.map +1 -0
- package/dist/client/adapters/SessionGeneration.js +68 -0
- package/dist/client/adapters/SessionGeneration.js.map +1 -0
- package/dist/client/adapters/SessionHandoff.d.ts +7 -0
- package/dist/client/adapters/SessionHandoff.d.ts.map +1 -0
- package/dist/client/adapters/SessionHandoff.js +27 -0
- package/dist/client/adapters/SessionHandoff.js.map +1 -0
- package/dist/client/authAction.d.ts +0 -7
- package/dist/client/authAction.d.ts.map +1 -1
- package/dist/client/authAction.js +1 -3
- package/dist/client/authAction.js.map +1 -1
- package/dist/client/authQuery.d.ts +3 -2
- package/dist/client/authQuery.d.ts.map +1 -1
- package/dist/client/authQuery.js +2 -2
- package/dist/client/authQuery.js.map +1 -1
- package/dist/client/authSession.d.ts +12 -0
- package/dist/client/authSession.d.ts.map +1 -0
- package/dist/client/authSession.js +13 -0
- package/dist/client/authSession.js.map +1 -0
- package/dist/client/permissionBoundary.d.ts.map +1 -1
- package/dist/client/permissionBoundary.js +2 -2
- package/dist/client/permissionBoundary.js.map +1 -1
- package/dist/client/resultState.d.ts +0 -1
- package/dist/client/resultState.d.ts.map +1 -1
- package/dist/client/resultState.js +3 -5
- package/dist/client/resultState.js.map +1 -1
- package/dist/client/saveState.d.ts +1 -1
- package/dist/client/saveState.d.ts.map +1 -1
- package/dist/client/saveState.js +3 -3
- package/dist/client/saveState.js.map +1 -1
- package/dist/client/sessionBoundary.d.ts +4 -2
- package/dist/client/sessionBoundary.d.ts.map +1 -1
- package/dist/client/sessionBoundary.js +6 -68
- package/dist/client/sessionBoundary.js.map +1 -1
- package/dist/internal/RecheckContext.d.ts +2 -0
- package/dist/internal/RecheckContext.d.ts.map +1 -0
- package/dist/internal/RecheckContext.js +3 -0
- package/dist/internal/RecheckContext.js.map +1 -0
- package/dist/internal/sessionRecheck.d.ts +1 -0
- package/dist/internal/sessionRecheck.d.ts.map +1 -1
- package/dist/internal/sessionRecheck.js +6 -2
- package/dist/internal/sessionRecheck.js.map +1 -1
- package/dist/internal/usePermissionFailure.d.ts.map +1 -1
- package/dist/internal/usePermissionFailure.js +3 -2
- package/dist/internal/usePermissionFailure.js.map +1 -1
- package/dist/permissionGuard.d.ts +2 -0
- package/dist/permissionGuard.d.ts.map +1 -1
- package/dist/permissionGuard.js +1 -1
- package/dist/permissionGuard.js.map +1 -1
- package/dist/queryRoute.d.ts.map +1 -1
- package/dist/queryRoute.js +3 -3
- package/dist/queryRoute.js.map +1 -1
- package/package.json +9 -9
- package/src/client/actionCompletion.ts +3 -2
- package/src/client/adapters/SessionGeneration.ts +93 -0
- package/src/client/adapters/SessionHandoff.ts +36 -0
- package/src/client/authAction.ts +1 -5
- package/src/client/authQuery.ts +4 -3
- package/src/client/authSession.ts +22 -0
- package/src/client/permissionBoundary.ts +2 -2
- package/src/client/resultState.ts +3 -5
- package/src/client/saveState.ts +3 -3
- package/src/client/sessionBoundary.ts +14 -91
- package/src/internal/RecheckContext.ts +3 -0
- package/src/internal/sessionRecheck.ts +7 -2
- package/src/internal/usePermissionFailure.ts +3 -2
- package/src/permissionGuard.ts +3 -2
- package/src/queryRoute.ts +3 -3
- package/dist/resumeSignal.d.ts +0 -6
- package/dist/resumeSignal.d.ts.map +0 -1
- package/dist/resumeSignal.js +0 -5
- package/dist/resumeSignal.js.map +0 -1
- package/src/resumeSignal.ts +0 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.28.0 - 2026-10-31
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `SessionBoundary` accepts `redirectTo` and an optional `navigate` callback to continue sign-in through a same-origin URL replacement after unmounting the signed-out tree and before mounting the signed-in tree. Unsafe targets fall back to `/`.
|
|
8
|
+
- `authSession` exposes a Better Auth read as a native query atom and an Effect that refreshes and awaits its settled result, so user mutations keep their loading state until session data is current.
|
|
9
|
+
- React's `permissionGuard` accepts `staticData.signedIn: true` for routes that require a session without a permission grant. Signed-out viewers use the existing sign-in redirect and return location; undeclared routes remain public and matched permission requirements still apply.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Generated starters import schedule definitions and the default queue client factory from their defining modules.
|
|
14
|
+
- Generated apps declare the notes routes as signed-in-only and install `permissionGuard` once at the root, redirecting signed-out viewers before loading notes.
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Query, save, command, loader and live connection failures share one session recheck decision, including identity's native `Unauthorized` errors.
|
|
19
|
+
- Report exported type aliases of imports, value aliases with `typeof` annotations or local const chains, object facades and unchanged forwarding functions, with repairs naming their defining modules. Keep wrappers that transform inputs, add steps, supply defaults or declare overloads.
|
|
20
|
+
- Generated apps let the boundary hand off sign-in navigation and identify cookie sessions by user id, preserving signed-in screen state when a session rotates after a password change.
|
|
21
|
+
- Carry the original `NotFound` query rejection in TanStack Router's not-found `data` so a shared root screen can display its server message and typed fields while route-level not-found screens keep precedence.
|
|
22
|
+
|
|
23
|
+
### Breaking
|
|
24
|
+
|
|
25
|
+
- React recognizes session rechecks, permission failures and missing routes through the shared error classes. Fail with `Unauthorized`, `Forbidden` and `NotFound` from `@shivaedev/errors/taxonomy.ts` instead of objects or local classes with matching tags. Replace `isUnauthorized` imports from React's `client/resultState.ts` with the taxonomy guard; for a cause, use `Option.exists(Cause.findErrorOption(cause), isUnauthorized)`.
|
|
26
|
+
- `authQuery` and `authSession` fail rejected promises with `AuthUnavailable` from `@shivaedev/errors/taxonomy.ts`. Replace `AuthActionUnavailable` imports and error annotations with `AuthUnavailable`, and read its `message` instead of `cause`.
|
|
27
|
+
- Quality: the gate now rejects imported second names even when they use type aliases, value annotations, object facades or forwarding functions. Import from the defining module and remove the second name; existing facade debt can be recorded at adoption. Import `USAGE` from `cli/messages.ts` instead of `cli/args.ts`.
|
|
28
|
+
- Jobs: import `defaultClientFactory` from `@shivaedev/jobs/server/defaultClientFactory.ts` instead of `server/client.ts`. Import `defineSchedule` from `@shivaedev/jobs/server/defineSchedule.ts` instead of `server/definition.ts`. The removed `server/internal/nativeClient.ts` and `server/internal/scheduleDefinition.ts` exports migrate to those same modules as `defaultClientFactory` and `defineSchedule`. The default factory now exposes its native pg-boss return type; type custom factory mocks against `PgBossClient` or `PgBossClientFactory` from `server/client.ts`.
|
|
29
|
+
- React: import `resumeSignal`, `ResumeOptions`, `ResumeSource` and `ResumeWindow` from `@shivaedev/contract/resume.ts`; `@shivaedev/react/resumeSignal.ts` is removed.
|
|
30
|
+
- Work Board: import `Identity` from `path/Identity.ts`, view state helpers from `browser/views/state.ts`, `isMarkdown` from `path/isMarkdown.ts`, and `processes` from `server/processOwnership.ts`. The forwarding `server/views/state.ts` and `server/integration/processes.ts` modules are removed. Replace the removed `attention` facade with imports of `managedRequestReceipt` from `server/attention/managedRequestReceipt.ts`, `attentionProjection` from `server/attention/projection.ts`, and `RequestReceipt` from `attention/RequestReceipt.ts`. Replace the removed `publication` facade with direct imports from `server/responses/publicationDirectory.ts`. Import `Changes` from `server/files/changes.ts`, `MarkdownFile` from `server/files/list.ts`, `Snapshot` from `server/search/snapshot.ts`, metadata document/model/diagnostic/parsed types from `integration/metadata.ts`, `InboxProjection` from `browser/views/schema.ts` instead of `AttentionProjection`, `SourceFailure` from `diagnostics/source.ts`, and `WorkspaceOptions` from `server/workspace.ts` instead of the integration facades. Metadata types are also removed from `server/metadata/model.ts` and `server/metadata/parse.ts`; import them from `integration/metadata.ts`.
|
|
31
|
+
- Work Fleet: import `WAIT_EXIT`, `WaitState`, `WaitOutcome` and `settled` from `host/waitOutcome.ts` instead of `host/wait.ts`; import `fleetRecords` from `fleetRecords.ts` instead of `operations.ts`.
|
|
32
|
+
|
|
3
33
|
## 0.27.0 - 2026-10-31
|
|
4
34
|
|
|
5
35
|
### Added
|
package/README.md
CHANGED
|
@@ -60,16 +60,15 @@ import { makeOrderClient, OrderScreens } from "./orders.tsx";
|
|
|
60
60
|
|
|
61
61
|
interface Session {
|
|
62
62
|
readonly id: string;
|
|
63
|
-
readonly
|
|
64
|
-
readonly token: string;
|
|
63
|
+
readonly user: { readonly id: string };
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
export function App({ session, recheck }: { readonly session: Session | undefined; readonly recheck: () => void }) {
|
|
68
67
|
return (
|
|
69
68
|
<SessionBoundary
|
|
70
69
|
session={session}
|
|
71
|
-
identify={(current) =>
|
|
72
|
-
connect={(
|
|
70
|
+
identify={(current) => current.user.id}
|
|
71
|
+
connect={() => makeOrderClient()}
|
|
73
72
|
recheck={recheck}
|
|
74
73
|
signedOut={<p>Signed out</p>}
|
|
75
74
|
>
|
|
@@ -79,9 +78,11 @@ export function App({ session, recheck }: { readonly session: Session | undefine
|
|
|
79
78
|
}
|
|
80
79
|
```
|
|
81
80
|
|
|
82
|
-
`makeOrderClient` and `OrderScreens` belong to the application. A changed generation creates a new client and registry, acquires a socket with the current session cookie, remounts the screens and disposes the outgoing registry. Independent registries for the same generation share the socket. `undefined` renders `signedOut`. Updating the session object with the same generation keeps the existing client: `connect` does not receive a rotated token until the identity changes.
|
|
81
|
+
`makeOrderClient` and `OrderScreens` belong to the application; this example uses the current session cookie. Identify by user id by default: rotating a session after a password change keeps the signed-in screen's state. Identifying by session id is an explicit choice that discards state on rotation. A changed generation creates a new client and registry, acquires a socket with the current session cookie, remounts the screens and disposes the outgoing registry. Independent registries for the same generation share the socket. `undefined` renders `signedOut`. Updating the session object with the same generation keeps the existing client: `connect` does not receive a rotated token until the identity changes. If a client captures a token, either read the current token per request or explicitly include the session id or credential generation in `identify`, accepting a remount on rotation.
|
|
83
82
|
|
|
84
|
-
|
|
83
|
+
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.
|
|
84
|
+
|
|
85
|
+
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 socket failure also asks the auth owner to recheck, since the host closes revoked sessions. The auth owner can retry the same session or remove it; the hook does not sign the user out. 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.
|
|
85
86
|
|
|
86
87
|
#### Session-scoped bindings
|
|
87
88
|
|
|
@@ -93,8 +94,8 @@ import { SessionBoundary } from "@shivaedev/react/client/sessionBoundary.ts";
|
|
|
93
94
|
|
|
94
95
|
<SessionBoundary
|
|
95
96
|
session={session}
|
|
96
|
-
identify={(current) => current.
|
|
97
|
-
connect={(
|
|
97
|
+
identify={(current) => current.user.id}
|
|
98
|
+
connect={(_, registry) => bind(Preferences, makePreferencesClient(), { registry })}
|
|
98
99
|
recheck={recheck}
|
|
99
100
|
signedOut={<p>Signed out</p>}
|
|
100
101
|
>
|
|
@@ -102,7 +103,7 @@ import { SessionBoundary } from "@shivaedev/react/client/sessionBoundary.ts";
|
|
|
102
103
|
</SessionBoundary>;
|
|
103
104
|
```
|
|
104
105
|
|
|
105
|
-
`Preferences` is the application's session-scoped contract, and `makePreferencesClient(
|
|
106
|
+
`Preferences` is the application's session-scoped contract, and `makePreferencesClient()` creates its native AtomRpc service using the current session cookie. A one-argument `connect` callback also works. The boundary allocates the registry before calling `connect`; an unchanged generation keeps its binding and state. Account replacement, sign-out and same-account re-entry dispose the old registry, private query tracking, live registrations and pending refreshes. Use the user id for cookie-based clients so session rotation keeps state. A sign-out followed by sign-in creates a new registry even for the same user.
|
|
106
107
|
|
|
107
108
|
#### Resume from a native shell
|
|
108
109
|
|
|
@@ -110,7 +111,7 @@ For a native shell, pass its resume source when binding the API returned by `con
|
|
|
110
111
|
|
|
111
112
|
```ts
|
|
112
113
|
import { bind } from "@shivaedev/contract/bind.ts";
|
|
113
|
-
import type { ResumeSource } from "@shivaedev/
|
|
114
|
+
import type { ResumeSource } from "@shivaedev/contract/resume.ts";
|
|
114
115
|
import { onAppResume, onNetworkReturn } from "./native-lifecycle.ts";
|
|
115
116
|
|
|
116
117
|
const resume: ResumeSource = (notify) => {
|
|
@@ -224,7 +225,7 @@ export function App() {
|
|
|
224
225
|
|
|
225
226
|
The hook owns retained display data and the native atom owns execution and caching. `QueryView` creates neither. Expected query rejections stay in its failure renderer; defects are thrown to the application's error boundary. It leaves field and command failures with the editor, form or action that owns them. Native `useAtomSuspense` is unchanged and still throws failures.
|
|
226
227
|
|
|
227
|
-
For both queries and actions, a successful `undefined` is `Option.some(undefined)` in `data`, with `pending` and `refreshing` false. A defect or interruption is available as `Option.some(cause)` in `cause`;
|
|
228
|
+
For both queries and actions, a successful `undefined` is `Option.some(undefined)` in `data`, with `pending` and `refreshing` false. A defect or interruption is available as `Option.some(cause)` in `cause`; they do not request a session recheck, even when the defect has an `Unauthorized` tag.
|
|
228
229
|
|
|
229
230
|
The example's action returns a value; it does not persist the report or invalidate its query. In an application, use the native RPC query and mutation atoms instead:
|
|
230
231
|
|
|
@@ -570,23 +571,26 @@ With native `RpcClient.layerProtocolHttp` and `FetchHttpClient.layer` as the bro
|
|
|
570
571
|
|
|
571
572
|
#### Route loaders with TanStack Router
|
|
572
573
|
|
|
573
|
-
TanStack Router owns routes, navigation, search validation, loader data and screen components. Spread `queryRoute(buildQuery)` from `@shivaedev/react/queryRoute.ts` into `createRoute` to derive loader dependencies from validated search and load a contract query atom in the router context’s registry. A rejection
|
|
574
|
+
TanStack Router owns routes, navigation, search validation, loader data and screen components. Spread `queryRoute(buildQuery)` from `@shivaedev/react/queryRoute.ts` into `createRoute` to derive loader dependencies from validated search and load a contract query atom in the router context’s registry. A `NotFound` instance from `@shivaedev/errors/taxonomy.ts` enters TanStack's not-found handling with the original rejection in the not-found component's `data` prop, preserving its message. One root `notFoundComponent` can show that message for all query routes; a route's own `notFoundComponent` takes precedence. Other typed failures reach `errorComponent` unchanged. The atom runs through its native RPC runtime and shares its execution with React. The factory receives `{ context, params, search }`: `context` is the loader’s router context, including parent `beforeLoad` contributions. Annotate it with `typeof root.types.allContext` (or the parent route’s `types.allContext`) to keep client and viewer access checked against the route’s declaration.
|
|
574
575
|
|
|
575
576
|
This example assumes an application-owned `api.get.query({ id, page })` returning `{ id, title }`, with declared `NotFound` and `NoteMissing` rejections:
|
|
576
577
|
|
|
577
578
|
```tsx
|
|
578
579
|
import { RegistryContext } from "@effect/atom-react";
|
|
579
580
|
import { createRootRouteWithContext, createRoute, createRouter, RouterProvider, useRouterState } from "@tanstack/react-router";
|
|
580
|
-
import type { ErrorComponentProps } from "@tanstack/react-router";
|
|
581
|
+
import type { ErrorComponentProps, NotFoundRouteProps } from "@tanstack/react-router";
|
|
581
582
|
import { Effect, Option, Predicate, Schema } from "effect";
|
|
582
583
|
import type { ReactNode } from "react";
|
|
583
584
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
585
|
+
import { NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
584
586
|
import { queryRoute } from "@shivaedev/react/queryRoute.ts";
|
|
585
587
|
import { useLoaderQuery } from "@shivaedev/react/client/useLoaderQuery.ts";
|
|
586
588
|
import { api } from "./notes-client.ts";
|
|
587
589
|
|
|
588
590
|
const registry = AtomRegistry.make();
|
|
589
|
-
const root = createRootRouteWithContext<{ registry: AtomRegistry.AtomRegistry; api: typeof api }>()(
|
|
591
|
+
const root = createRootRouteWithContext<{ registry: AtomRegistry.AtomRegistry; api: typeof api }>()({
|
|
592
|
+
notFoundComponent: SharedNotFound,
|
|
593
|
+
});
|
|
590
594
|
const Search = Schema.Struct({
|
|
591
595
|
page: Schema.Number.check(Schema.isInt(), Schema.isGreaterThan(0)).pipe(
|
|
592
596
|
Schema.catchDecoding(() => Effect.succeed(Option.some(1))),
|
|
@@ -600,7 +604,6 @@ const note = createRoute({
|
|
|
600
604
|
...queryRoute(({ context, params, search }: { context: typeof root.types.allContext; params: { id: string }; search: typeof Search.Type }) =>
|
|
601
605
|
context.api.get.query({ id: params.id, page: search.page }),
|
|
602
606
|
),
|
|
603
|
-
notFoundComponent: () => <h1>Note not found</h1>,
|
|
604
607
|
component: Note,
|
|
605
608
|
errorComponent: Failure,
|
|
606
609
|
});
|
|
@@ -633,6 +636,9 @@ function Note() {
|
|
|
633
636
|
function Failure({ error }: ErrorComponentProps) {
|
|
634
637
|
return <p role="alert">{Predicate.isTagged(error, "NoteMissing") ? "Note missing" : "Could not load"}</p>;
|
|
635
638
|
}
|
|
639
|
+
function SharedNotFound({ data }: NotFoundRouteProps) {
|
|
640
|
+
return <h1>{Schema.is(NotFound)(data) ? data.message : "Page not found"}</h1>;
|
|
641
|
+
}
|
|
636
642
|
export function App() {
|
|
637
643
|
return (
|
|
638
644
|
<RegistryContext.Provider value={registry}>
|
|
@@ -642,7 +648,9 @@ export function App() {
|
|
|
642
648
|
}
|
|
643
649
|
```
|
|
644
650
|
|
|
645
|
-
`
|
|
651
|
+
`SharedNotFound` narrows `data` with the shared rejection schema before reading the server's message. The fallback handles not-found results without that rejection, such as unmatched URLs.
|
|
652
|
+
|
|
653
|
+
`validateSearch` stays native: `Schema.toStandardSchemaV1(Search)` supplies TanStack’s search input and output types. The schema defaults a missing or invalid page to `1`. The query callback names its params and schema output type because TypeScript cannot infer them backward through an object spread. Changing search changes the loader dependencies and queries the new payload. Keep `params`, `validateSearch`, `component` and `errorComponent` on the route, with an optional `notFoundComponent` to override the shared screen; options after the spread can override its `loaderDeps` or `loader`.
|
|
646
654
|
|
|
647
655
|
For a loader that coordinates more work, use `loadQuery(registry, atom, loaderContext)` from `@shivaedev/react/adapters/loadQuery.ts` directly. It reads the atom in the supplied registry and throws typed failures unchanged, including `NotFound`; the loader decides how to handle them.
|
|
648
656
|
|
|
@@ -658,7 +666,7 @@ For a loader that coordinates more work, use `loadQuery(registry, atom, loaderCo
|
|
|
658
666
|
|
|
659
667
|
Permissions come from the session payload's `user.permissions`, populated by `@shivaedev/access` through the server's role policy. `can(session, permission)` uses access's grant evaluator without making a request: names match exactly, and an `any` grant covers an `own` check for that name. An `own` grant does not cover an `any` check. `useCan()` supplies the same check from the nearest `PermissionBoundary` for component controls. A signed-out session has no grants. These checks control visibility; the server still authorizes every request.
|
|
660
668
|
|
|
661
|
-
Declare a route's requirement in TanStack's native `staticData
|
|
669
|
+
Declare a route's requirement in TanStack's native `staticData`: `signedIn: true` admits any signed-in viewer, and `permission` requires a specific grant. Routes that declare neither stay public. Install `permissionGuard` once as the root route's `beforeLoad`; it checks all matched routes before their loaders run, including requirements on parents. Signed-out visitors go to the app's `signIn` path with the full requested location in the `returnTo` search field. A signed-in session without a required grant throws the shared `Forbidden` failure. A signed-in-only parent does not bypass a child's permission requirement.
|
|
662
670
|
|
|
663
671
|
```tsx
|
|
664
672
|
import { RegistryContext } from "@effect/atom-react";
|
|
@@ -677,6 +685,12 @@ const ReadNotes = permission("notes.read");
|
|
|
677
685
|
const root = createRootRouteWithContext<{ registry: AtomRegistry.AtomRegistry; api: typeof api }>()({
|
|
678
686
|
beforeLoad: permissionGuard({ session: () => auth.session, signIn: "/login" }),
|
|
679
687
|
});
|
|
688
|
+
const profile = createRoute({
|
|
689
|
+
getParentRoute: () => root,
|
|
690
|
+
path: "/profile",
|
|
691
|
+
staticData: { signedIn: true },
|
|
692
|
+
component: () => <h1>Profile</h1>,
|
|
693
|
+
});
|
|
680
694
|
const note = createRoute({
|
|
681
695
|
getParentRoute: () => root,
|
|
682
696
|
path: "/notes/$id",
|
|
@@ -702,7 +716,7 @@ const login = createRoute({
|
|
|
702
716
|
});
|
|
703
717
|
const router = createRouter({
|
|
704
718
|
context: { registry, api },
|
|
705
|
-
routeTree: root.addChildren([note, login]),
|
|
719
|
+
routeTree: root.addChildren([profile, note, login]),
|
|
706
720
|
disableGlobalCatchBoundary: true,
|
|
707
721
|
});
|
|
708
722
|
|
|
@@ -727,7 +741,7 @@ const showNotes = can(auth.session, ReadNotes);
|
|
|
727
741
|
|
|
728
742
|
`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.
|
|
729
743
|
|
|
730
|
-
`PermissionBoundary` renders the app's one fallback at the denied URL for a refused route, a loader's `Forbidden`, or a `useQuery`/`useLoaderQuery` result
|
|
744
|
+
`PermissionBoundary` renders the app's one fallback at the denied URL for a refused route, a loader's `Forbidden`, or a `useQuery`/`useLoaderQuery` result containing the shared `Forbidden` class. Other errors propagate to an enclosing error boundary. Set TanStack's `disableGlobalCatchBoundary: true` and leave permission failures to this boundary; a route-specific `errorComponent` that consumes an error owns its rendering instead. Without a permission boundary, query failures keep their normal typed state. Like a React error boundary, remount it to clear a caught failure.
|
|
731
745
|
|
|
732
746
|
#### Better Auth actions
|
|
733
747
|
|
|
@@ -761,27 +775,38 @@ const onSubmit = (credentials: { email: string; password: string }) => signIn(cr
|
|
|
761
775
|
|
|
762
776
|
`authCall` returns a function from input to `Effect<A, AuthFailure>`. It uses the same failure codes and successful data as `authAction`.
|
|
763
777
|
|
|
764
|
-
`
|
|
778
|
+
Use `authSession` from `@shivaedev/react/client/authSession.ts` for the application's Better Auth session. It returns a native `atom` for `useQuery` and a `refresh` Effect that refreshes that same atom and waits through its loading state. Supply Better Auth's public `getSession` call with `disableCookieCache: true` so a mutation reads current user data:
|
|
765
779
|
|
|
766
780
|
```tsx
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
781
|
+
import { Effect } from "effect";
|
|
782
|
+
import * as Atom from "effect/reactivity/Atom";
|
|
783
|
+
import { authCall } from "@shivaedev/react/client/authAction.ts";
|
|
784
|
+
import { authSession } from "@shivaedev/react/client/authSession.ts";
|
|
785
|
+
import { useAction, useQuery } from "@shivaedev/react/client/resultState.ts";
|
|
786
|
+
|
|
787
|
+
const session = authSession((signal) => authClient.getSession({ query: { disableCookieCache: true }, fetchOptions: { signal } }));
|
|
788
|
+
const updateUser = authCall((name: string, signal) => authClient.updateUser({ name }, { signal }));
|
|
789
|
+
const rename = Atom.fn<string>()((name) => updateUser(name).pipe(Effect.andThen(session.refresh)));
|
|
770
790
|
|
|
771
791
|
function Account() {
|
|
772
|
-
const query = useQuery(
|
|
773
|
-
const
|
|
792
|
+
const query = useQuery(session.atom);
|
|
793
|
+
const action = useAction(rename);
|
|
774
794
|
return (
|
|
775
|
-
|
|
776
|
-
{query.pending && <p>Loading…</p>}
|
|
795
|
+
<section aria-busy={query.pending}>
|
|
777
796
|
{Option.isSome(query.data) && <p>{query.data.value?.user.name ?? "Signed out"}</p>}
|
|
778
|
-
{
|
|
779
|
-
|
|
797
|
+
<button disabled={action.pending} onClick={() => action.dispatch("Alicia")}>
|
|
798
|
+
{action.pending ? "Saving…" : "Change name"}
|
|
799
|
+
</button>
|
|
800
|
+
</section>
|
|
780
801
|
);
|
|
781
802
|
}
|
|
782
803
|
```
|
|
783
804
|
|
|
784
|
-
The example uses the application's Better Auth client. Reads preserve returned auth errors and use `
|
|
805
|
+
The example uses `Option` from `effect` and the application's Better Auth client. The mutation stays pending until the refreshed session settles; the query retains its previous data while refreshing and exposes `pending` for `aria-busy`. Compose email verification with `session.refresh` the same way. Reads preserve returned auth errors and use `AuthUnavailable` from `@shivaedev/errors/taxonomy.ts` for rejected promises; a failed refresh fails the composed mutation. A successful `null` session represents sign-out.
|
|
806
|
+
|
|
807
|
+
`session.refresh` uses the native `AtomRegistry` service supplied by action atoms and atom runtimes. For an Effect run outside an atom, provide the registry that renders the session with `Effect.provideService(AtomRegistry.AtomRegistry, registry)`. Keep the session atom in the auth owner's registry, above any session boundary whose subtree it replaces. The application owns when to refresh; this adapter does not subscribe to Better Auth's hook or store.
|
|
808
|
+
|
|
809
|
+
For other Better Auth reads, `authQuery` from `@shivaedev/react/client/authQuery.ts` creates an input-keyed query atom family. Call `authQuery((input, signal) => authClient.getSession({ query: input, fetchOptions: { signal } }))` with an explicitly typed input, then render its atom with `useQuery`. Releasing a pending read interrupts its Effect and aborts the supplied signal.
|
|
785
810
|
|
|
786
811
|
For an explicit sign-out in a TanStack route, use `useSignOut(signOut, { signIn: "/sign-in" })` from `@shivaedev/react/client/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. 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.
|
|
787
812
|
|
|
@@ -802,7 +827,7 @@ Changing the `fields` schema or `runtime` by reference replaces either hook's fo
|
|
|
802
827
|
Keep the signal and query identities stable:
|
|
803
828
|
|
|
804
829
|
```ts
|
|
805
|
-
import { resumeSignal } from "@shivaedev/
|
|
830
|
+
import { resumeSignal } from "@shivaedev/contract/resume.ts";
|
|
806
831
|
import { Effect } from "effect";
|
|
807
832
|
import * as Atom from "effect/reactivity/Atom";
|
|
808
833
|
|
|
@@ -849,15 +874,14 @@ pnpm add -D @shivaedev/test-story @effect/platform-node @effect/vitest vitest ha
|
|
|
849
874
|
Configure Vitest with `test: { environment: "happy-dom" }`, or select that environment for your DOM test project. This complete `notes.dom.test.tsx` renders a component that runs a declared query and command against native RPC test handlers:
|
|
850
875
|
|
|
851
876
|
```tsx
|
|
852
|
-
import { Effect, Option, Ref, Schema } from "effect";
|
|
853
|
-
import * as AtomRpc from "effect/reactivity/AtomRpc";
|
|
854
|
-
import { RpcTest } from "effect/rpc";
|
|
877
|
+
import { Effect, Layer, Option, Ref, Schema, Stream } from "effect";
|
|
855
878
|
import { act, createElement } from "react";
|
|
856
879
|
import { expect } from "vitest";
|
|
857
|
-
import {
|
|
880
|
+
import { makeClient } from "@shivaedev/contract/bind.ts";
|
|
858
881
|
import { contract } from "@shivaedev/contract/contract.ts";
|
|
859
882
|
import { collection } from "@shivaedev/changes/keys.ts";
|
|
860
883
|
import { command, query } from "@shivaedev/contract/operation.ts";
|
|
884
|
+
import { layerMemoryProtocol } from "@shivaedev/contract/testing.ts";
|
|
861
885
|
import { useAction, useQuery } from "@shivaedev/react/client/resultState.ts";
|
|
862
886
|
import { eventually, expectNoReactWarnings, render } from "@shivaedev/test-story/client/react.ts";
|
|
863
887
|
import { it } from "@shivaedev/test/it.ts";
|
|
@@ -866,7 +890,7 @@ Object.assign(globalThis, { "IS_REACT_ACT_ENVIRONMENT": true });
|
|
|
866
890
|
expectNoReactWarnings();
|
|
867
891
|
|
|
868
892
|
const notes = collection("notes", Schema.Number);
|
|
869
|
-
const List = query("list", { reads: () => [notes.list], success: Schema.Array(Schema.String) });
|
|
893
|
+
const List = query("list", { readPolicy: () => Effect.succeed(true), reads: () => [notes.list], success: Schema.Array(Schema.String) });
|
|
870
894
|
const Add = command("add", { invalidates: () => [notes.list], payload: { title: Schema.String } });
|
|
871
895
|
const Notes = contract("notes", { commands: [Add], queries: [List] });
|
|
872
896
|
|
|
@@ -874,17 +898,17 @@ const handlers = Notes.toLayer(
|
|
|
874
898
|
Effect.gen(function* () {
|
|
875
899
|
const stored = yield* Ref.make<readonly string[]>([]);
|
|
876
900
|
return Notes.of({
|
|
901
|
+
"notes.$changes": () => Stream.never,
|
|
877
902
|
"notes.add": ({ title }) => Ref.update(stored, (all) => [...all, title]),
|
|
878
903
|
"notes.list": () => Ref.get(stored).pipe(Effect.delay("20 millis")),
|
|
879
904
|
});
|
|
880
905
|
}),
|
|
881
906
|
);
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
})
|
|
887
|
-
const api = bind(Notes, Client);
|
|
907
|
+
const { api, Client } = makeClient(Notes, {
|
|
908
|
+
live: false,
|
|
909
|
+
protocol: layerMemoryProtocol(Notes).pipe(Layer.provide(handlers)),
|
|
910
|
+
url: "memory://notes",
|
|
911
|
+
});
|
|
888
912
|
const add = Client.runtime.fn(api.add.run);
|
|
889
913
|
function NotesView() {
|
|
890
914
|
const list = useQuery(api.list.query());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionCompletion.d.ts","sourceRoot":"","sources":["../../src/client/actionCompletion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,
|
|
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;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD,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,CA4DjD"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { RegistryContext } from "@effect/atom-react";
|
|
2
|
-
import { Effect
|
|
2
|
+
import { Effect } from "effect";
|
|
3
3
|
import { useContext, useInsertionEffect, useMemo, useRef } from "react";
|
|
4
4
|
import { NoticeContext } from "#internal/NoticeContext.ts";
|
|
5
5
|
import { publishNotice } from "#internal/noticeStore.ts";
|
|
6
|
+
import { requestsRecheck } from "#internal/sessionRecheck.ts";
|
|
6
7
|
import { useSessionRecheck } from "./sessionBoundary.js";
|
|
7
8
|
export function useActionSource(source, run, options) {
|
|
8
9
|
const registry = useContext(RegistryContext);
|
|
@@ -17,7 +18,7 @@ export function useActionSource(source, run, options) {
|
|
|
17
18
|
const lifetime = { active: false, registry };
|
|
18
19
|
function rejected(error, input) {
|
|
19
20
|
return Effect.gen(function* () {
|
|
20
|
-
if (lifetime.active &&
|
|
21
|
+
if (lifetime.active && requestsRecheck(error)) {
|
|
21
22
|
yield* Effect.sync(() => latestRef.current.recheck());
|
|
22
23
|
}
|
|
23
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,
|
|
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;AAExE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,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,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;IACpD,kBAAkB,CAAC,GAAG,EAAE;QACvB,SAAS,CAAC,OAAO,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;IAC/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AAG,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,14 @@
|
|
|
1
|
+
import type { Duration } from "effect";
|
|
2
|
+
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
3
|
+
import { type ReactNode } from "react";
|
|
4
|
+
interface SessionGenerationProps<TSession, TClient> {
|
|
5
|
+
readonly children: (client: TClient) => ReactNode;
|
|
6
|
+
readonly connect: (session: TSession, registry: AtomRegistry.AtomRegistry) => TClient;
|
|
7
|
+
readonly identity: string | undefined;
|
|
8
|
+
readonly liveCoalesceWindow?: Duration.Input | undefined;
|
|
9
|
+
readonly recheck: () => void;
|
|
10
|
+
readonly session: TSession;
|
|
11
|
+
}
|
|
12
|
+
export declare function SessionGeneration<TSession, TClient>({ session, connect, recheck, children, identity, liveCoalesceWindow, }: SessionGenerationProps<TSession, TClient>): ReactNode;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=SessionGeneration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionGeneration.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/SessionGeneration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAiB,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAiD3E,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,kBAAkB,CAAC,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAC;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;CAC3B;AACD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,EACpD,OAAO,EACP,OAAO,EACP,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,kBAAkB,GAClB,EAAE,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,SAAS,CAyBvD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { RegistryContext } from "@effect/atom-react";
|
|
2
|
+
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
3
|
+
import { createElement, useEffect, useState } from "react";
|
|
4
|
+
import { LiveConnection } from "@shivaedev/contract/automaticLive.ts";
|
|
5
|
+
import { mountLive } from "#client/mountLive.ts";
|
|
6
|
+
import { liveBindings } from "#internal/liveBindings.ts";
|
|
7
|
+
import { RecheckContext } from "#internal/RecheckContext.ts";
|
|
8
|
+
import { registerSessionRecheck } from "#internal/sessionRecheck.ts";
|
|
9
|
+
import { useLatestCallback } from "#internal/useLatestCallback.ts";
|
|
10
|
+
function owning(connect, identity) {
|
|
11
|
+
const registry = AtomRegistry.make({ "defaultIdleTTL": 400 });
|
|
12
|
+
let client;
|
|
13
|
+
return {
|
|
14
|
+
get client() {
|
|
15
|
+
client ??= { value: connect(registry) };
|
|
16
|
+
for (const binding of liveBindings(client.value)) {
|
|
17
|
+
const session = binding[LiveConnection].identity;
|
|
18
|
+
if (session !== undefined) {
|
|
19
|
+
registry.set(session, identity);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return client.value;
|
|
23
|
+
},
|
|
24
|
+
mounted: 0,
|
|
25
|
+
registry,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
// No cleanup runs when a hidden <Activity> subtree is unmounted, so nodes a hidden render creates must not outlive it.
|
|
29
|
+
function hidden(connect, identity) {
|
|
30
|
+
const owned = owning(connect, identity);
|
|
31
|
+
let reaping = false;
|
|
32
|
+
owned.registry.onNodeAdded = () => {
|
|
33
|
+
if (reaping || owned.mounted > 0) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
reaping = true;
|
|
37
|
+
setTimeout(() => {
|
|
38
|
+
reaping = false;
|
|
39
|
+
if (owned.mounted === 0) {
|
|
40
|
+
owned.registry.reset();
|
|
41
|
+
}
|
|
42
|
+
}, 0);
|
|
43
|
+
};
|
|
44
|
+
return owned;
|
|
45
|
+
}
|
|
46
|
+
export function SessionGeneration({ session, connect, recheck, children, identity, liveCoalesceWindow, }) {
|
|
47
|
+
const recheckLatest = useLatestCallback(recheck);
|
|
48
|
+
const [open] = useState(() => (registry) => connect(session, registry));
|
|
49
|
+
const [owned, own] = useState(() => owning(open, identity));
|
|
50
|
+
useEffect(() => registerSessionRecheck(owned.registry, recheckLatest), [owned, recheckLatest]);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
owned.mounted += 1;
|
|
53
|
+
const stopLive = mountLive(owned.registry, owned.client, liveCoalesceWindow);
|
|
54
|
+
return () => {
|
|
55
|
+
stopLive();
|
|
56
|
+
owned.mounted -= 1;
|
|
57
|
+
queueMicrotask(() => {
|
|
58
|
+
if (owned.mounted > 0) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
owned.registry.dispose();
|
|
62
|
+
own((current) => (current === owned ? hidden(open, identity) : current));
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
}, [identity, owned, liveCoalesceWindow, open]);
|
|
66
|
+
return createElement(RecheckContext.Provider, { value: recheckLatest }, createElement(RegistryContext.Provider, { value: owned.registry }, children(owned.client)));
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=SessionGeneration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionGeneration.js","sourceRoot":"","sources":["../../../src/client/adapters/SessionGeneration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,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,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAOnE,SAAS,MAAM,CAAU,OAAyD,EAAE,QAA4B;IAC/G,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,gBAAgB,EAAE,GAAG,EAAE,CAAC,CAAC;IAC9D,IAAI,MAA+C,CAAC;IACpD,OAAO;QACN,IAAI,MAAM;YACT,MAAM,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxC,KAAK,MAAM,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBAClD,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC;gBACjD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;oBAC3B,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;gBACjC,CAAC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aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC;IAC/F,SAAS,CAAC,GAAG,EAAE;QACd,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;QACnB,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;QAC7E,OAAO,GAAG,EAAE;YACX,QAAQ,EAAE,CAAC;YACX,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;YACnB,cAAc,CAAC,GAAG,EAAE;gBACnB,IAAI,KAAK,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;oBACvB,OAAO;gBACR,CAAC;gBACD,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;gBACzB,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;YAC1E,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,kBAAkB,EAAE,IAAI,CAAC,CAAC,CAAC;IAChD,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,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAC1F,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export declare function SessionHandoff({ children, redirectTo, navigate, }: {
|
|
3
|
+
readonly children?: ReactNode;
|
|
4
|
+
readonly redirectTo: string | undefined;
|
|
5
|
+
readonly navigate: ((href: string) => void) | undefined;
|
|
6
|
+
}): ReactNode;
|
|
7
|
+
//# sourceMappingURL=SessionHandoff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionHandoff.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/SessionHandoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAiB5D,wBAAgB,cAAc,CAAC,EAC9B,QAAQ,EACR,UAAU,EACV,QAA0B,GAC1B,EAAE;IACF,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACxD,GAAG,SAAS,CAUZ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
function safeDestination(target) {
|
|
3
|
+
try {
|
|
4
|
+
const url = new URL(target, window.location.origin);
|
|
5
|
+
return (url.protocol === "http:" || url.protocol === "https:") && url.origin === window.location.origin && !url.pathname.startsWith("//")
|
|
6
|
+
? `${url.pathname}${url.search}${url.hash}`
|
|
7
|
+
: "/";
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return "/";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function replaceLocation(href) {
|
|
14
|
+
window.history.replaceState(null, "", href);
|
|
15
|
+
}
|
|
16
|
+
export function SessionHandoff({ children, redirectTo, navigate = replaceLocation, }) {
|
|
17
|
+
const [ready, setReady] = useState(redirectTo === undefined);
|
|
18
|
+
// The signed-out router must finish unmounting before any history listener sees the destination.
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!ready && redirectTo !== undefined) {
|
|
21
|
+
navigate(safeDestination(redirectTo));
|
|
22
|
+
setReady(true);
|
|
23
|
+
}
|
|
24
|
+
}, [ready, redirectTo, navigate]);
|
|
25
|
+
return ready ? children : null;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=SessionHandoff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionHandoff.js","sourceRoot":"","sources":["../../../src/client/adapters/SessionHandoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5D,SAAS,eAAe,CAAC,MAAc;IACtC,IAAI,CAAC;QACJ,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACpD,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC;YACxI,CAAC,CAAC,GAAG,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE;YAC3C,CAAC,CAAC,GAAG,CAAC;IACR,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,GAAG,CAAC;IACZ,CAAC;AACF,CAAC;AAED,SAAS,eAAe,CAAC,IAAY;IACpC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAC9B,QAAQ,EACR,UAAU,EACV,QAAQ,GAAG,eAAe,GAK1B;IACA,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC;IAC7D,iGAAiG;IACjG,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,KAAK,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YACxC,QAAQ,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC;YACtC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAChB,CAAC;IACF,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;AAChC,CAAC"}
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import * as Atom from "effect/reactivity/Atom";
|
|
3
|
-
declare const AuthActionUnavailable_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
4
|
-
readonly _tag: "AuthActionUnavailable";
|
|
5
|
-
} & Readonly<A>;
|
|
6
|
-
export declare class AuthActionUnavailable extends AuthActionUnavailable_base<{
|
|
7
|
-
readonly cause: unknown;
|
|
8
|
-
}> {
|
|
9
|
-
}
|
|
10
3
|
export interface AuthActionResult<A, E> {
|
|
11
4
|
readonly data: A;
|
|
12
5
|
readonly error: E | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authAction.d.ts","sourceRoot":"","sources":["../../src/client/authAction.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"authAction.d.ts","sourceRoot":"","sources":["../../src/client/authAction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAE/C,MAAM,WAAW,gBAAgB,CAAC,CAAC,EAAE,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACjB,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CACzB;AAED,eAAO,MAAM,eAAe,+xCAoD1B,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC,IAAI,CAAC;;;;;AAE1D,qBAAa,WAAY,SAAQ,gBAG/B;CAAG;AAIL,wBAAgB,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,KAAK,EAC3D,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAC1E,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,CAAC,CAiBlD;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,KAAK,EAC7D,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAC1E,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,WAAW,CAAC,CAE3C"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
2
|
import * as HttpStatus from "effect/http/HttpStatus";
|
|
3
3
|
import * as Atom from "effect/reactivity/Atom";
|
|
4
|
-
export class AuthActionUnavailable extends Data.TaggedError("AuthActionUnavailable") {
|
|
5
|
-
}
|
|
6
4
|
export const AuthFailureCode = Schema.Literals([
|
|
7
5
|
"USER_NOT_FOUND",
|
|
8
6
|
"FAILED_TO_CREATE_USER",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authAction.js","sourceRoot":"","sources":["../../src/client/authAction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"authAction.js","sourceRoot":"","sources":["../../src/client/authA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syncResult";
|
|
2
2
|
import * as Atom from "effect/reactivity/Atom";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
|
|
4
|
+
import type { AuthActionResult } from "./authAction.ts";
|
|
5
|
+
export declare function authQuery<TInput, A, E extends object = never>(run: (input: TInput, signal: AbortSignal) => Promise<AuthActionResult<A, E>>): (input: TInput) => Atom.Atom<AsyncResult.AsyncResult<A, E | AuthUnavailable>>;
|
|
5
6
|
//# sourceMappingURL=authQuery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authQuery.d.ts","sourceRoot":"","sources":["../../src/client/authQuery.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"authQuery.d.ts","sourceRoot":"","sources":["../../src/client/authQuery.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,wBAAgB,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,KAAK,EAC5D,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAC1E,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAS/E"}
|
package/dist/client/authQuery.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import * as Atom from "effect/reactivity/Atom";
|
|
3
|
-
import {
|
|
3
|
+
import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
|
|
4
4
|
export function authQuery(run) {
|
|
5
5
|
return Atom.family((input) => Atom.make(Effect.tryPromise({
|
|
6
|
-
catch: (cause) => new
|
|
6
|
+
catch: (cause) => new AuthUnavailable({ message: String(cause) }),
|
|
7
7
|
try: (signal) => run(input, signal),
|
|
8
8
|
}).pipe(Effect.flatMap((result) => (result.error === null ? Effect.succeed(result.data) : Effect.fail(result.error))))));
|
|
9
9
|
}
|