@shivaedev/react 0.25.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 CHANGED
@@ -1,5 +1,25 @@
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
+
13
+ ## 0.26.0 - 2026-10-31
14
+
15
+ ### Added
16
+
17
+ - Screen kits can build a screen driver's `pending` signal with `screenPending({ router })` from `client/screenPending.ts`, which reads the `AtomRegistry` from the environment: it reports pending while a read `AsyncResult` is waiting or the TanStack router is loading a route, and ignores results left waiting by unmounted components.
18
+
19
+ ### Breaking
20
+
21
+ - `loadQuery` moved from `@shivaedev/react/loadQuery.ts` to `@shivaedev/react/adapters/loadQuery.ts`, beside the other bridges from outside libraries into Effect. Change the import path; the function and its behavior are unchanged.
22
+
3
23
  ## 0.25.0 - 2026-10-30
4
24
 
5
25
  ### 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 }) => api.get.query({ id: params.id, page: search.page })),
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,
@@ -642,7 +644,7 @@ export function App() {
642
644
 
643
645
  `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`, `errorComponent` and `notFoundComponent` on the route; options after the spread can override its `loaderDeps` or `loader`.
644
646
 
645
- For a loader that coordinates more work, use `loadQuery(registry, atom, loaderContext)` from `@shivaedev/react/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.
647
+ 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.
646
648
 
647
649
  `defaultPendingMs: Infinity` keeps the current route's data visible during navigation; the shell reads TanStack's `isLoading` to display pending state. The new route commits when its loader settles. This is TanStack's pending policy, separate from `useQuery`'s retained display. The loader and the component share one query execution even when the route delays mounting for 650 ms, beyond the registry’s idle window: the first render has the loaded value and the RPC handler runs once.
648
650
 
@@ -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> }) => api.get.query({ id: params.id, page: 1 })),
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
  });
@@ -938,6 +942,13 @@ screenStories.it("shows the route failure", [], async () => {
938
942
 
939
943
  Story kits can acquire `captureReactWarnings` from `@shivaedev/test-story/client/react.ts` in their `create` effect with `const warnings = yield* captureReactWarnings`. The scope owns the capture and restores `console.error` when it closes, including after a failed story. Pass `warnings.onCaughtError` to `render` to capture boundary errors, or `warnings.expectCaughtError(predicate)` to exclude a declared error. Both handlers silence caught errors; the capture also silences and records `console.error` calls. `warnings.read()` returns `{ consoleErrors, caughtErrors }`, with each console call's arguments and the unexpected caught errors. It asserts nothing, leaving the story spec to state its expectation. The Vitest guard uses the same capture mechanism and additionally checks that every declared error occurred.
940
944
 
945
+ A screen kit tells its screen driver when the screen has finished its work with `screenPending({ router })` from `@shivaedev/react/client/screenPending.ts`. The Effect reads the `AtomRegistry` from its environment and returns a function that reports `true` while a native `AsyncResult` that something still reads is waiting, or while the optional TanStack router loads a route, and `false` otherwise. A result left waiting by a component that has unmounted does not count, even while the registry's idle window keeps its atom. Each call reads the registry and router at that moment, so pass it as the driver's `pending` option instead of listing the screen's queries by hand:
946
+
947
+ ```ts
948
+ const pending = yield* screenPending({ router }).pipe(Effect.provideService(AtomRegistry.AtomRegistry, view.registry));
949
+ const screen = screenDriver({ act, pending, root: view.container, tell: story.tell });
950
+ ```
951
+
941
952
  ### API
942
953
 
943
954
  `useQuery(atom)` and `useAction(atom)` return these shared fields:
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadQuery.d.ts","sourceRoot":"","sources":["../../src/adapters/loadQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AA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AO,CAAC,CAAC;YACpD,MAAM,MAAM,CAAC,OAAO,CAAC;QACtB,CAAC;QACD,OAAO,MAAM,CAAC,OAAO,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,OAAO,EAAE,CAAC;QAClB,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,QAAQ,GAAG,IAAI,KAAK,CAAC,wBAAwB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YACvE,QAAQ,CAAC,IAAI,GAAG,YAAY,CAAC;YAC7B,MAAM,QAAQ,CAAC;QAChB,CAAC;QACD,MAAM,KAAK,CAAC;IACb,CAAC;YAAS,CAAC;QACV,OAAO,CAAC,QAAQ,EAAE,CAAC;IACpB,CAAC;AACF,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { AnyRouter } from "@tanstack/react-router";
2
+ import { Effect } from "effect";
3
+ import * as AtomRegistry from "effect/reactivity/AtomRegistry";
4
+ export interface ScreenPendingOptions {
5
+ readonly router?: AnyRouter | undefined;
6
+ }
7
+ export declare function screenPending({ router }?: ScreenPendingOptions): Effect.Effect<() => boolean, never, AtomRegistry.AtomRegistry>;
8
+ //# sourceMappingURL=screenPending.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screenPending.d.ts","sourceRoot":"","sources":["../../src/client/screenPending.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAExC,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAE/D,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;CACxC;AAED,wBAAgB,aAAa,CAAC,EAAE,MAAM,EAAE,GAAE,oBAAyB,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,OAAO,EAAE,KAAK,EAAE,YAAY,CAAC,YAAY,CAAC,CAKnI"}
@@ -0,0 +1,21 @@
1
+ import { Effect, Option } from "effect";
2
+ import * as AsyncResult from "effect/reactivity/AsyncResult";
3
+ import * as AtomRegistry from "effect/reactivity/AtomRegistry";
4
+ export function screenPending({ router } = {}) {
5
+ return Effect.map(Effect.service(AtomRegistry.AtomRegistry), (registry) => () => routing(router) || [...registry.getNodes().values()].some((node) => waiting(node) && observed(node, new Set())));
6
+ }
7
+ function routing(router) {
8
+ return router !== undefined && (router.state.isLoading || router.state.matches.some((match) => match.isFetching !== false));
9
+ }
10
+ function waiting(node) {
11
+ return Option.match(node.valueOption(), { onNone: () => false, onSome: (value) => AsyncResult.isAsyncResult(value) && value.waiting });
12
+ }
13
+ // An idle dependent keeps its edge to a parent until the idle window removes it, so only a listener proves a reader.
14
+ function observed(node, visited) {
15
+ if (node.listeners.size > 0) {
16
+ return true;
17
+ }
18
+ visited.add(node);
19
+ return [...node.children].some((child) => !visited.has(child) && observed(child, visited));
20
+ }
21
+ //# sourceMappingURL=screenPending.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screenPending.js","sourceRoot":"","sources":["../../src/client/screenPending.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAM/D,MAAM,UAAU,aAAa,CAAC,EAAE,MAAM,EAAE,GAAyB,EAAE;IAClE,OAAO,MAAM,CAAC,GAAG,CAChB,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,EACzC,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC,CACnI,CAAC;AACH,CAAC;AAED,SAAS,OAAO,CAAC,MAA6B;IAC7C,OAAO,MAAM,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,KAAK,CAAC,CAAC,CAAC;AAC7H,CAAC;AAED,SAAS,OAAO,CAAC,IAAgC;IAChD,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;AACxI,CAAC;AAED,qHAAqH;AACrH,SAAS,QAAQ,CAAC,IAAgC,EAAE,OAAwC;IAC3F,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClB,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAC5F,CAAC"}
@@ -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>(query: (route: {
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>;
@@ -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,CAAC,OAAO,SAAS,MAAM,EAAE,OAAO,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAC9E,KAAK,EAAE,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CAAE,KAAK,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAGjH,MAAM,YACI,IAAI,CAAC,eAAe,EAAE,iBAAiB,CAAC,GAAG;QACnD,QAAQ,CAAC,OAAO,EAAE;YAAE,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,YAAY,CAAA;SAAE,CAAC;QACnE,QAAQ,CAAC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AM,EAAE,OAAO,CAAA;KAAE;EAEtD"}
@@ -1,11 +1,11 @@
1
1
  import { notFound } from "@tanstack/react-router";
2
2
  import { Predicate } from "effect";
3
- import { loadQuery } from "./loadQuery.js";
3
+ import { loadQuery } from "#adapters/loadQuery.ts";
4
4
  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")) {
@@ -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,gBAAgB,CAAC;AAE3C,MAAM,UAAU,UAAU,CACzB,KAAkH;IAElH,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,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;YACpH,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"}
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.25.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"
@@ -45,9 +45,9 @@
45
45
  "README.md"
46
46
  ],
47
47
  "dependencies": {
48
- "@shivaedev/access": "0.3.0",
49
- "@shivaedev/contract": "0.25.0",
50
- "@shivaedev/errors": "0.1.2",
48
+ "@shivaedev/access": "0.3.1",
49
+ "@shivaedev/contract": "0.27.0",
50
+ "@shivaedev/errors": "0.1.3",
51
51
  "@shivaedev/form": "0.9.0"
52
52
  },
53
53
  "devDependencies": {
@@ -56,15 +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.9.1",
60
- "@shivaedev/jobs": "0.23.2",
61
- "@shivaedev/quality": "0.48.1",
62
- "@shivaedev/server": "0.9.2",
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
- "@shivaedev/test": "0.12.0",
66
65
  "@shivaedev/test-sql": "0.15.0",
67
- "@shivaedev/test-story": "0.26.3",
66
+ "@shivaedev/test-story": "0.28.0",
68
67
  "@tanstack/react-router": "1.170.46",
69
68
  "@types/node": "24.19.2",
70
69
  "@types/react": "19.3.0",
@@ -0,0 +1,32 @@
1
+ import type { AnyRouter } from "@tanstack/react-router";
2
+ import { Effect, Option } from "effect";
3
+ import * as AsyncResult from "effect/reactivity/AsyncResult";
4
+ import * as AtomRegistry from "effect/reactivity/AtomRegistry";
5
+
6
+ export interface ScreenPendingOptions {
7
+ readonly router?: AnyRouter | undefined;
8
+ }
9
+
10
+ export function screenPending({ router }: ScreenPendingOptions = {}): Effect.Effect<() => boolean, never, AtomRegistry.AtomRegistry> {
11
+ return Effect.map(
12
+ Effect.service(AtomRegistry.AtomRegistry),
13
+ (registry) => () => routing(router) || [...registry.getNodes().values()].some((node) => waiting(node) && observed(node, new Set())),
14
+ );
15
+ }
16
+
17
+ function routing(router: AnyRouter | undefined): boolean {
18
+ return router !== undefined && (router.state.isLoading || router.state.matches.some((match) => match.isFetching !== false));
19
+ }
20
+
21
+ function waiting(node: AtomRegistry.Node<unknown>): boolean {
22
+ return Option.match(node.valueOption(), { onNone: () => false, onSome: (value) => AsyncResult.isAsyncResult(value) && value.waiting });
23
+ }
24
+
25
+ // An idle dependent keeps its edge to a parent until the idle window removes it, so only a listener proves a reader.
26
+ function observed(node: AtomRegistry.Node<unknown>, visited: Set<AtomRegistry.Node<unknown>>): boolean {
27
+ if (node.listeners.size > 0) {
28
+ return true;
29
+ }
30
+ visited.add(node);
31
+ return [...node.children].some((child) => !visited.has(child) && observed(child, visited));
32
+ }
package/src/queryRoute.ts CHANGED
@@ -3,21 +3,25 @@ import { Predicate } from "effect";
3
3
  import type * as AsyncResult from "effect/reactivity/AsyncResult";
4
4
  import type * as Atom from "effect/reactivity/Atom";
5
5
  import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
6
- import { loadQuery } from "./loadQuery.ts";
6
+ import { loadQuery } from "#adapters/loadQuery.ts";
7
7
 
8
- export function queryRoute<TParams extends object, TSearch extends object, A, E>(
9
- query: (route: { readonly params: TParams; readonly search: TSearch }) => Atom.Atom<AsyncResult.AsyncResult<A, E>>,
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: { readonly registry: AtomRegistry.AtomRegistry };
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();
@@ -1 +0,0 @@
1
- {"version":3,"file":"loadQuery.d.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