@shivaedev/react 0.26.0 → 0.27.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 +10 -0
- package/README.md +11 -7
- package/dist/queryRoute.d.ts +7 -4
- package/dist/queryRoute.d.ts.map +1 -1
- package/dist/queryRoute.js +1 -1
- package/dist/queryRoute.js.map +1 -1
- package/package.json +7 -7
- package/src/queryRoute.ts +9 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.27.0 - 2026-10-31
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `@shivaedev/react`: `queryRoute` passes the loader's router context to its query factory alongside params and validated search. Annotate `context` with the parent route's `types.allContext` to read declared clients and viewer state with type checking.
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- `@shivaedev/create-app`: generated starter routes read clients and session state from native router context instead of taking them as route factory parameters.
|
|
12
|
+
|
|
3
13
|
## 0.26.0 - 2026-10-31
|
|
4
14
|
|
|
5
15
|
### Added
|
package/README.md
CHANGED
|
@@ -570,7 +570,7 @@ With native `RpcClient.layerProtocolHttp` and `FetchHttpClient.layer` as the bro
|
|
|
570
570
|
|
|
571
571
|
#### Route loaders with TanStack Router
|
|
572
572
|
|
|
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 tagged `NotFound` renders the route’s `notFoundComponent`; other typed failures reach `errorComponent` unchanged. The atom runs through its native RPC runtime and shares its execution with React.
|
|
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 tagged `NotFound` renders the route’s `notFoundComponent`; 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
574
|
|
|
575
575
|
This example assumes an application-owned `api.get.query({ id, page })` returning `{ id, title }`, with declared `NotFound` and `NoteMissing` rejections:
|
|
576
576
|
|
|
@@ -586,7 +586,7 @@ import { useLoaderQuery } from "@shivaedev/react/client/useLoaderQuery.ts";
|
|
|
586
586
|
import { api } from "./notes-client.ts";
|
|
587
587
|
|
|
588
588
|
const registry = AtomRegistry.make();
|
|
589
|
-
const root = createRootRouteWithContext<{ registry: AtomRegistry.AtomRegistry }>()();
|
|
589
|
+
const root = createRootRouteWithContext<{ registry: AtomRegistry.AtomRegistry; api: typeof api }>()();
|
|
590
590
|
const Search = Schema.Struct({
|
|
591
591
|
page: Schema.Number.check(Schema.isInt(), Schema.isGreaterThan(0)).pipe(
|
|
592
592
|
Schema.catchDecoding(() => Effect.succeed(Option.some(1))),
|
|
@@ -597,13 +597,15 @@ const note = createRoute({
|
|
|
597
597
|
getParentRoute: () => root,
|
|
598
598
|
path: "/notes/$id",
|
|
599
599
|
validateSearch: Schema.toStandardSchemaV1(Search),
|
|
600
|
-
...queryRoute(({ params, search }: { params: { id: string }; search: typeof Search.Type }) =>
|
|
600
|
+
...queryRoute(({ context, params, search }: { context: typeof root.types.allContext; params: { id: string }; search: typeof Search.Type }) =>
|
|
601
|
+
context.api.get.query({ id: params.id, page: search.page }),
|
|
602
|
+
),
|
|
601
603
|
notFoundComponent: () => <h1>Note not found</h1>,
|
|
602
604
|
component: Note,
|
|
603
605
|
errorComponent: Failure,
|
|
604
606
|
});
|
|
605
607
|
const router = createRouter({
|
|
606
|
-
context: { registry },
|
|
608
|
+
context: { registry, api },
|
|
607
609
|
routeTree: root.addChildren([note]),
|
|
608
610
|
defaultPendingMs: Infinity,
|
|
609
611
|
InnerWrap: Shell,
|
|
@@ -672,14 +674,16 @@ import { api, registry } from "./notes-client.ts";
|
|
|
672
674
|
import { auth, SignIn } from "./auth.tsx";
|
|
673
675
|
|
|
674
676
|
const ReadNotes = permission("notes.read");
|
|
675
|
-
const root = createRootRouteWithContext<{ registry: AtomRegistry.AtomRegistry }>()({
|
|
677
|
+
const root = createRootRouteWithContext<{ registry: AtomRegistry.AtomRegistry; api: typeof api }>()({
|
|
676
678
|
beforeLoad: permissionGuard({ session: () => auth.session, signIn: "/login" }),
|
|
677
679
|
});
|
|
678
680
|
const note = createRoute({
|
|
679
681
|
getParentRoute: () => root,
|
|
680
682
|
path: "/notes/$id",
|
|
681
683
|
staticData: { permission: ReadNotes },
|
|
682
|
-
...queryRoute(({ params }: { params: { id: string }; search: Record<string, never> }) =>
|
|
684
|
+
...queryRoute(({ context, params }: { context: typeof root.types.allContext; params: { id: string }; search: Record<string, never> }) =>
|
|
685
|
+
context.api.get.query({ id: params.id, page: 1 }),
|
|
686
|
+
),
|
|
683
687
|
component: () => {
|
|
684
688
|
const query = useLoaderQuery(api.get.query({ ...note.useParams(), page: 1 }), note.useLoaderData());
|
|
685
689
|
return <h1>{query.data.title}</h1>;
|
|
@@ -697,7 +701,7 @@ const login = createRoute({
|
|
|
697
701
|
},
|
|
698
702
|
});
|
|
699
703
|
const router = createRouter({
|
|
700
|
-
context: { registry },
|
|
704
|
+
context: { registry, api },
|
|
701
705
|
routeTree: root.addChildren([note, login]),
|
|
702
706
|
disableGlobalCatchBoundary: true,
|
|
703
707
|
});
|
package/dist/queryRoute.d.ts
CHANGED
|
@@ -2,14 +2,17 @@ import { type LoaderFnContext } from "@tanstack/react-router";
|
|
|
2
2
|
import type * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
3
|
import type * as Atom from "effect/reactivity/Atom";
|
|
4
4
|
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
5
|
-
export declare function queryRoute<TParams extends object, TSearch extends object, A, E
|
|
5
|
+
export declare function queryRoute<TParams extends object, TSearch extends object, A, E, TContext extends {
|
|
6
|
+
readonly registry: AtomRegistry.AtomRegistry;
|
|
7
|
+
} = {
|
|
8
|
+
readonly registry: AtomRegistry.AtomRegistry;
|
|
9
|
+
}>(query: (route: {
|
|
6
10
|
readonly params: TParams;
|
|
7
11
|
readonly search: TSearch;
|
|
12
|
+
readonly context: TContext;
|
|
8
13
|
}) => Atom.Atom<AsyncResult.AsyncResult<A, E>>): {
|
|
9
14
|
loader: (context: Pick<LoaderFnContext, "abortController"> & {
|
|
10
|
-
readonly context:
|
|
11
|
-
readonly registry: AtomRegistry.AtomRegistry;
|
|
12
|
-
};
|
|
15
|
+
readonly context: TContext;
|
|
13
16
|
readonly deps: TSearch;
|
|
14
17
|
readonly params: TParams;
|
|
15
18
|
}) => Promise<A>;
|
package/dist/queryRoute.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryRoute.d.ts","sourceRoot":"","sources":["../src/queryRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAY,MAAM,wBAAwB,CAAC;AAExE,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAGpE,wBAAgB,UAAU,
|
|
1
|
+
{"version":3,"file":"queryRoute.d.ts","sourceRoot":"","sources":["../src/queryRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAY,MAAM,wBAAwB,CAAC;AAExE,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAGpE,wBAAgB,UAAU,CACzB,OAAO,SAAS,MAAM,EACtB,OAAO,SAAS,MAAM,EACtB,CAAC,EACD,CAAC,EACD,QAAQ,SAAS;IAAE,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,YAAY,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,YAAY,CAAA;CAAE,EACnH,KAAK,EAAE,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,KAAK,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAE9I,MAAM,YACI,IAAI,CAAC,eAAe,EAAE,iBAAiB,CAAC,GAAG;QACnD,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;QAC3B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;QACvB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;KACzB,KACC,OAAO,CAAC,CAAC,CAAC;IAUb,UAAU,eAAe;QAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;KAAE;EAEtD"}
|
package/dist/queryRoute.js
CHANGED
|
@@ -5,7 +5,7 @@ export function queryRoute(query) {
|
|
|
5
5
|
return {
|
|
6
6
|
loader: async (context) => {
|
|
7
7
|
try {
|
|
8
|
-
return await loadQuery(context.context.registry, query({ params: context.params, search: context.deps }), context);
|
|
8
|
+
return await loadQuery(context.context.registry, query({ context: context.context, params: context.params, search: context.deps }), context);
|
|
9
9
|
}
|
|
10
10
|
catch (error) {
|
|
11
11
|
if (Predicate.isTagged(error, "NotFound")) {
|
package/dist/queryRoute.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryRoute.js","sourceRoot":"","sources":["../src/queryRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAInC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,MAAM,UAAU,UAAU,
|
|
1
|
+
{"version":3,"file":"queryRoute.js","sourceRoot":"","sources":["../src/queryRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAInC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,MAAM,UAAU,UAAU,CAMxB,KAA8I;IAC/I,OAAO;QACN,MAAM,EAAE,KAAK,EACZ,OAIC,EACY,EAAE;YACf,IAAI,CAAC;gBACJ,OAAO,MAAM,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;YAC9I,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,CAAC;oBAC3C,MAAM,QAAQ,EAAE,CAAC;gBAClB,CAAC;gBACD,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC;QACD,UAAU,EAAE,CAAC,EAAE,MAAM,EAAgC,EAAE,EAAE,CAAC,MAAM;KAChE,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "React query, action, editor and session hooks for native Effect atoms",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@shivaedev/access": "0.3.1",
|
|
49
|
-
"@shivaedev/contract": "0.
|
|
49
|
+
"@shivaedev/contract": "0.27.0",
|
|
50
50
|
"@shivaedev/errors": "0.1.3",
|
|
51
51
|
"@shivaedev/form": "0.9.0"
|
|
52
52
|
},
|
|
@@ -56,14 +56,14 @@
|
|
|
56
56
|
"@effect/sql-pg": "4.0.6",
|
|
57
57
|
"@effect/sql-sqlite-node": "4.0.6",
|
|
58
58
|
"@shivaedev/changes": "0.6.0",
|
|
59
|
-
"@shivaedev/identity": "0.10.
|
|
60
|
-
"@shivaedev/jobs": "0.
|
|
61
|
-
"@shivaedev/quality": "0.48.
|
|
62
|
-
"@shivaedev/server": "0.
|
|
59
|
+
"@shivaedev/identity": "0.10.1",
|
|
60
|
+
"@shivaedev/jobs": "0.25.0",
|
|
61
|
+
"@shivaedev/quality": "0.48.2",
|
|
62
|
+
"@shivaedev/server": "0.10.0",
|
|
63
63
|
"@shivaedev/service": "0.6.0",
|
|
64
64
|
"@shivaedev/sql": "0.27.0",
|
|
65
65
|
"@shivaedev/test-sql": "0.15.0",
|
|
66
|
-
"@shivaedev/test-story": "0.
|
|
66
|
+
"@shivaedev/test-story": "0.28.0",
|
|
67
67
|
"@tanstack/react-router": "1.170.46",
|
|
68
68
|
"@types/node": "24.19.2",
|
|
69
69
|
"@types/react": "19.3.0",
|
package/src/queryRoute.ts
CHANGED
|
@@ -5,19 +5,23 @@ import type * as Atom from "effect/reactivity/Atom";
|
|
|
5
5
|
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
6
6
|
import { loadQuery } from "#adapters/loadQuery.ts";
|
|
7
7
|
|
|
8
|
-
export function queryRoute<
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export function queryRoute<
|
|
9
|
+
TParams extends object,
|
|
10
|
+
TSearch extends object,
|
|
11
|
+
A,
|
|
12
|
+
E,
|
|
13
|
+
TContext extends { readonly registry: AtomRegistry.AtomRegistry } = { readonly registry: AtomRegistry.AtomRegistry },
|
|
14
|
+
>(query: (route: { readonly params: TParams; readonly search: TSearch; readonly context: TContext }) => Atom.Atom<AsyncResult.AsyncResult<A, E>>) {
|
|
11
15
|
return {
|
|
12
16
|
loader: async (
|
|
13
17
|
context: Pick<LoaderFnContext, "abortController"> & {
|
|
14
|
-
readonly context:
|
|
18
|
+
readonly context: TContext;
|
|
15
19
|
readonly deps: TSearch;
|
|
16
20
|
readonly params: TParams;
|
|
17
21
|
},
|
|
18
22
|
): Promise<A> => {
|
|
19
23
|
try {
|
|
20
|
-
return await loadQuery(context.context.registry, query({ params: context.params, search: context.deps }), context);
|
|
24
|
+
return await loadQuery(context.context.registry, query({ context: context.context, params: context.params, search: context.deps }), context);
|
|
21
25
|
} catch (error) {
|
|
22
26
|
if (Predicate.isTagged(error, "NotFound")) {
|
|
23
27
|
throw notFound();
|