@kitbag/router 0.25.0 → 0.26.1

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.
Files changed (70) hide show
  1. package/dist/components/routerLink.d.ts +3 -3
  2. package/dist/compositions/useHasSuspenseBoundary.browser.spec.d.ts +1 -0
  3. package/dist/compositions/useHasSuspenseBoundary.d.ts +4 -0
  4. package/dist/compositions/useIsServerRendering.browser.spec.d.ts +1 -0
  5. package/dist/compositions/useIsServerRendering.d.ts +5 -0
  6. package/dist/compositions/useIsServerRendering.spec.d.ts +1 -0
  7. package/dist/errors/contextRedirectError.d.ts +7 -0
  8. package/dist/errors/navigationAbandonedError.d.ts +1 -0
  9. package/dist/errors/payloadValueError.d.ts +9 -0
  10. package/dist/errors/ssrOptionRequiredError.d.ts +7 -0
  11. package/dist/errors/unsupportedSchemaVendorError.d.ts +7 -0
  12. package/dist/errors/updateWithoutRouteError.d.ts +7 -0
  13. package/dist/kitbag-router.d.ts +1 -1
  14. package/dist/kitbag-router.js +6647 -6429
  15. package/dist/kitbag-router.umd.cjs +5 -5
  16. package/dist/main.d.ts +2 -0
  17. package/dist/services/addLoader.d.ts +4 -1
  18. package/dist/services/addView.d.ts +4 -1
  19. package/dist/services/arktype.spec-d.d.ts +1 -0
  20. package/dist/services/arktype.spec.d.ts +1 -0
  21. package/dist/services/createActivityTracker.d.ts +6 -0
  22. package/dist/services/createActivityTracker.spec.d.ts +1 -0
  23. package/dist/services/createCurrentRejection.d.ts +0 -3
  24. package/dist/services/createNavigationIds.d.ts +6 -0
  25. package/dist/services/createNavigationIds.spec.d.ts +1 -0
  26. package/dist/services/createNavigationStores.d.ts +10 -5
  27. package/dist/services/createRejection.d.ts +2 -6
  28. package/dist/services/createRejection.spec-d.d.ts +1 -0
  29. package/dist/services/createRejection.spec.d.ts +1 -0
  30. package/dist/services/createRouteHooks.d.ts +1 -1
  31. package/dist/services/createRouteValueStore.d.ts +44 -12
  32. package/dist/services/createRouteValueStore.spec.d.ts +1 -0
  33. package/dist/services/createRouterCallbackContext.d.ts +1 -1
  34. package/dist/services/createRouterHistory.spec.d.ts +1 -0
  35. package/dist/services/createServerRedirect.d.ts +14 -0
  36. package/dist/services/createServerRedirect.spec.d.ts +1 -0
  37. package/dist/services/getComputations.d.ts +40 -0
  38. package/dist/services/getGlobalRouteHooks.d.ts +2 -2
  39. package/dist/services/getInitialUrl.d.ts +2 -1
  40. package/dist/services/getRouteHooks.d.ts +2 -2
  41. package/dist/services/getRoutesForRouter.d.ts +3 -1
  42. package/dist/services/hooks.d.ts +1 -1
  43. package/dist/services/payload.d.ts +86 -0
  44. package/dist/services/payload.spec.d.ts +1 -0
  45. package/dist/services/standardSchema.d.ts +21 -0
  46. package/dist/services/urlParser.d.ts +5 -0
  47. package/dist/tests/hydration.browser.spec.d.ts +1 -0
  48. package/dist/tests/render.spec.d.ts +1 -0
  49. package/dist/types/addLoader.d.ts +3 -2
  50. package/dist/types/addView.d.ts +7 -2
  51. package/dist/types/callbackContext.d.ts +9 -0
  52. package/dist/types/hooks.d.ts +14 -15
  53. package/dist/types/paramTypes.d.ts +2 -3
  54. package/dist/types/params.d.ts +1 -1
  55. package/dist/types/redirects.d.ts +11 -3
  56. package/dist/types/rejection.d.ts +24 -4
  57. package/dist/types/resolved.d.ts +4 -2
  58. package/dist/types/routeLoaders.d.ts +2 -0
  59. package/dist/types/routeTitle.d.ts +2 -1
  60. package/dist/types/routeViews.d.ts +2 -0
  61. package/dist/types/router.d.ts +95 -3
  62. package/dist/types/routerPlugin.d.ts +7 -3
  63. package/dist/types/routerReject.d.ts +13 -0
  64. package/dist/types/routerRoute.d.ts +1 -1
  65. package/dist/types/serverRenderResponse.spec-d.d.ts +1 -0
  66. package/dist/utilities/components.d.ts +13 -1
  67. package/dist/utilities/setDocumentTitle.d.ts +1 -2
  68. package/package.json +10 -15
  69. package/dist/services/valibot.d.ts +0 -7
  70. package/dist/services/zod.d.ts +0 -11
package/dist/main.d.ts CHANGED
@@ -35,8 +35,10 @@ export { LoaderDataAccessError } from './errors/loaderDataAccessError';
35
35
  export { LoaderNameConflict } from './errors/loaderNameConflict';
36
36
  export { MetaPropertyConflict } from './errors/metaPropertyConflict';
37
37
  export { NavigationAbandonedError } from './errors/navigationAbandonedError';
38
+ export { PayloadValueError } from './errors/payloadValueError';
38
39
  export { RouterNotInstalledError } from './errors/routerNotInstalledError';
39
40
  export { UseRouteInvalidError } from './errors/useRouteInvalidError';
41
+ export { SsrOptionRequiredError } from './errors/ssrOptionRequiredError';
40
42
  export { createRoute } from './services/createRoute';
41
43
  export { createRejection } from './services/createRejection';
42
44
  export { createExternalRoute } from './services/createExternalRoute';
@@ -1,3 +1,4 @@
1
+ import { AnyPayloadTransformer } from './payload';
1
2
  import { PrefetchConfig } from '../types/prefetch';
2
3
  import { CreatedRouteOptions, Route } from '../types/route';
3
4
  import { AnyFunction } from '../types/utilities';
@@ -9,6 +10,7 @@ export declare const DEFAULT_LOADER_NAME = "default";
9
10
  type LoaderOptions = {
10
11
  name?: string;
11
12
  prefetch?: PrefetchConfig;
13
+ transformer?: AnyPayloadTransformer;
12
14
  };
13
15
  /**
14
16
  * The runtime arguments accepted by `addLoader`.
@@ -23,6 +25,7 @@ type Loader = {
23
25
  name: string;
24
26
  load: AnyFunction;
25
27
  prefetch: PrefetchConfig | undefined;
28
+ transformer: AnyPayloadTransformer | undefined;
26
29
  };
27
30
  export declare function toLoader(load: AnyFunction, options: LoaderOptions | undefined): Loader;
28
31
  /**
@@ -31,7 +34,7 @@ export declare function toLoader(load: AnyFunction, options: LoaderOptions | und
31
34
  * Matches are `markRaw` so that making a route reactive does not turn its loaders into reactive proxies.
32
35
  * Spreading a match drops that, so the rebuilt one is marked again.
33
36
  */
34
- export declare function addLoaderToMatch(match: CreatedRouteOptions, { name, load, prefetch }: Loader): CreatedRouteOptions;
37
+ export declare function addLoaderToMatch(match: CreatedRouteOptions, { name, load, prefetch, transformer }: Loader): CreatedRouteOptions;
35
38
  /**
36
39
  * A route's data combines the loaders of every match, so a name an ancestor already uses would be
37
40
  * ambiguous. Adding a loader the route itself already has is an override, and allowed.
@@ -1,4 +1,5 @@
1
1
  import { Component } from 'vue';
2
+ import { AnyPayloadTransformer } from './payload';
2
3
  import { PropsGetter } from '../types/createRouteOptions';
3
4
  import { PrefetchConfig } from '../types/prefetch';
4
5
  import { CreatedRouteOptions, Route } from '../types/route';
@@ -10,6 +11,7 @@ type ViewOptions = {
10
11
  name?: string;
11
12
  props?: PropsGetter;
12
13
  prefetch?: PrefetchConfig;
14
+ transformer?: AnyPayloadTransformer;
13
15
  };
14
16
  /**
15
17
  * The runtime arguments accepted by `addView`.
@@ -25,6 +27,7 @@ type View = {
25
27
  component: Component;
26
28
  props: PropsGetter | undefined;
27
29
  prefetch: PrefetchConfig | undefined;
30
+ transformer: AnyPayloadTransformer | undefined;
28
31
  };
29
32
  export declare function toView(component: Component, options: ViewOptions | undefined): View;
30
33
  /**
@@ -33,5 +36,5 @@ export declare function toView(component: Component, options: ViewOptions | unde
33
36
  * Matches are `markRaw` so that making a route reactive does not turn its components into reactive
34
37
  * proxies. Spreading a match drops that, so the rebuilt one is marked again.
35
38
  */
36
- export declare function addViewToMatch(match: CreatedRouteOptions, { name, component, props, prefetch }: View): CreatedRouteOptions;
39
+ export declare function addViewToMatch(match: CreatedRouteOptions, { name, component, props, prefetch, transformer }: View): CreatedRouteOptions;
37
40
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export type ActivityTracker = {
2
+ add: (...work: Promise<unknown>[]) => void;
3
+ wrap: <TArgs extends unknown[], TResult>(fn: (...args: TArgs) => Promise<TResult>) => (...args: TArgs) => Promise<TResult>;
4
+ idle: () => Promise<void>;
5
+ };
6
+ export declare function createActivityTracker(): ActivityTracker;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,11 +1,8 @@
1
1
  import { Rejection, RouterRejection } from '../types/rejection';
2
- import { ComputedRef } from 'vue';
3
- import { ResolvedRoute } from '../types/resolved';
4
2
  type RejectionUpdate = (rejection: Rejection) => void;
5
3
  type RejectionClear = () => void;
6
4
  type CurrentRejectionContext = {
7
5
  currentRejection: RouterRejection;
8
- currentRejectionRoute: ComputedRef<ResolvedRoute | null>;
9
6
  updateRejection: RejectionUpdate;
10
7
  clearRejection: RejectionClear;
11
8
  };
@@ -0,0 +1,6 @@
1
+ export type NavigationIds = {
2
+ getNavigationId: () => string;
3
+ isCurrentNavigationId: (id: string) => boolean;
4
+ stopNavigationIds: () => void;
5
+ };
6
+ export declare function createNavigationIds(): NavigationIds;
@@ -0,0 +1 @@
1
+ export {};
@@ -3,9 +3,9 @@ import { ResolvedRoute } from '../types/resolved';
3
3
  /**
4
4
  * Which store the rendered route reads from, and which one the next navigation will adopt.
5
5
  *
6
- * A navigation gets its own store so the one it replaces can be disposed outright. A followed link stages
7
- * the store it prefetched into, which the navigation it triggers picks up — staged rather than handed over
8
- * directly because a link is followed before that navigation starts.
6
+ * A navigation gets its own store so the one it replaces can be disposed outright. A store built ahead of
7
+ * a navigation is staged for it to pick up — staged rather than handed over directly because it is built
8
+ * before that navigation starts.
9
9
  */
10
10
  export type NavigationStores = {
11
11
  /**
@@ -13,10 +13,15 @@ export type NavigationStores = {
13
13
  */
14
14
  current: () => DataStore;
15
15
  /**
16
- * Parks a followed link's store for the navigation it triggered. A store already parked is disposed,
17
- * since following a second link before the first navigation arrives abandons the first.
16
+ * Parks a store for the next navigation. A store already parked is disposed, since staging a second
17
+ * store before a navigation arrives abandons the first.
18
18
  */
19
19
  stage: (store: DataStore) => void;
20
+ /**
21
+ * The staged store, created when nothing was staged, so a navigation can compute into it ahead of
22
+ * adopting it.
23
+ */
24
+ staged: () => DataStore;
20
25
  /**
21
26
  * Swaps in the staged store, or a fresh one, and hands back the store being replaced for disposal.
22
27
  */
@@ -1,8 +1,4 @@
1
1
  import { RejectionHooks } from '../types/hooks';
2
- import { Rejection } from '../types/rejection';
3
- import { Component } from 'vue';
2
+ import { Rejection, RejectionOptions } from '../types/rejection';
4
3
  import { RouteSetTitle } from '../types/routeTitle';
5
- export declare function createRejection<TType extends string>(options: {
6
- type: TType;
7
- component?: Component;
8
- }): Rejection<TType> & RejectionHooks<TType> & RouteSetTitle;
4
+ export declare function createRejection<TType extends string>(options: RejectionOptions<TType>): Rejection<TType> & RejectionHooks<TType> & RouteSetTitle;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -11,7 +11,7 @@ type RouteHooks<TRoutes extends Routes = Routes, TRejections extends Rejection[]
11
11
  onAfterRouteEnter: AddAfterEnterHook<TRoutes, TRejections>;
12
12
  onAfterRouteUpdate: AddAfterUpdateHook<TRoutes, TRejections>;
13
13
  onAfterRouteLeave: AddAfterLeaveHook<TRoutes, TRejections>;
14
- onError: AddErrorHook<TRoutes[number], TRoutes, TRejections>;
14
+ onError: AddErrorHook<TRoutes, TRejections>;
15
15
  onRejection: AddRejectionHook<ExtractRejectionTypes<TRejections>, TRoutes>;
16
16
  store: Hooks;
17
17
  };
@@ -1,9 +1,10 @@
1
- import { PrefetchConfigs, PrefetchStrategy } from '../types/prefetch';
2
1
  import { ResolvedRoute, WithData } from '../types/resolved';
3
2
  import { HasVueAppStore } from './createVueAppStore';
4
3
  import { CallbackContextPush, CallbackContextReject, CallbackContextSuccess } from '../types/callbackContext';
4
+ import { DataKind } from './createNavigationStores';
5
5
  import { PropsResult } from '../utilities/props';
6
6
  import { MaybePromise } from '../types/utilities';
7
+ import { ComputationFilter } from './getComputations';
7
8
  /**
8
9
  * A navigation that was superseded before its values settled. The navigation that replaced it owns the
9
10
  * outcome, so this one reports that it went nowhere rather than a success it never had.
@@ -21,30 +22,61 @@ export type RouteValueResponses = {
21
22
  loaders: Promise<RouteValueResponse>;
22
23
  };
23
24
  /**
24
- * A link's own bucket of prefetched values, handed to the current navigation when the link is followed and
25
- * discarded otherwise.
25
+ * A store of a route's values, whichever store that is.
26
26
  */
27
- export type PrefetchStore = {
27
+ export type ValueStore = {
28
28
  /**
29
- * Computes props for views whose prefetch option matches the given strategy.
29
+ * Computes the route's values, or only those the filter keeps, and reports how they settle.
30
30
  */
31
- prefetch: (strategy: PrefetchStrategy, route: ResolvedRoute, configs: PrefetchConfigs) => void;
31
+ compute: (route: ResolvedRoute, filter?: ComputationFilter) => RouteValueResponses;
32
32
  /**
33
- * Stages the prefetched store for the next navigation to adopt.
33
+ * Adopts values that already settled, in place of running their getters.
34
34
  */
35
- commit: () => void;
35
+ fill: (route: ResolvedRoute, values: RouteValue[]) => void;
36
+ };
37
+ /**
38
+ * A store kept apart from the navigation until it is staged, so values can be computed ahead of a
39
+ * navigation that may never come.
40
+ */
41
+ export type DetachedStore = ValueStore & {
36
42
  /**
37
- * Abandons what was prefetched and starts over, for a link that now points somewhere else.
43
+ * Becomes the staged store, replacing whatever was staged, and starts over empty.
44
+ */
45
+ stage: () => void;
46
+ /**
47
+ * Abandons what was computed and starts over.
38
48
  */
39
49
  reset: () => void;
40
50
  /**
41
- * Abandons what was prefetched, for a link that is gone.
51
+ * Abandons what was computed.
42
52
  */
43
53
  dispose: () => void;
44
54
  };
55
+ /**
56
+ * A value the store holds for a route: which computation it belongs to, and what it resolved to.
57
+ */
58
+ export type RouteValue = {
59
+ kind: DataKind;
60
+ depth: number;
61
+ name: string;
62
+ value: unknown;
63
+ };
45
64
  export type RouteValueStore = HasVueAppStore & {
46
- createPrefetchStore: () => PrefetchStore;
47
- setRouteValues: (route: ResolvedRoute) => RouteValueResponses;
65
+ createDetachedStore: () => DetachedStore;
66
+ /**
67
+ * The store the next navigation adopts, created when nothing is staged. Values computed into it ahead of
68
+ * the navigation are found under way when the navigation commits, while the rendered route keeps reading
69
+ * its own store meanwhile.
70
+ */
71
+ staged: () => ValueStore;
72
+ /**
73
+ * Makes the staged store current and computes whatever the route still lacks.
74
+ */
75
+ commit: (route: ResolvedRoute) => RouteValueResponses;
76
+ /**
77
+ * The values currently settled in the store.
78
+ */
79
+ getValues: (route: ResolvedRoute) => RouteValue[];
48
80
  getProps: (id: string, name: string, route: ResolvedRoute) => MaybePromise<PropsResult>;
49
81
  /**
50
82
  * What a route exposes as `data`. Resolved per read rather than captured, so it stays correct as
@@ -0,0 +1 @@
1
+ export {};
@@ -17,6 +17,6 @@ type RouterCallbackContext<TRoutes extends Routes = Routes, TRejections extends
17
17
  abort: CallbackContextAbort;
18
18
  };
19
19
  export declare function createRouterCallbackContext<TRoutes extends Routes, TRejections extends Rejections>({ to }: {
20
- to: ResolvedRoute;
20
+ to: ResolvedRoute | null;
21
21
  }): RouterCallbackContext<TRoutes, TRejections>;
22
22
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import { RedirectStatus, RenderRedirect } from '../types/router';
2
+ type ServerRedirect = {
3
+ /**
4
+ * Captures a redirect as the render's response. A server responds per redirect hop, so only the first
5
+ * is kept: the browser follows it, and the next request takes it from there.
6
+ */
7
+ setServerRedirect: (status: RedirectStatus, location: string) => void;
8
+ /**
9
+ * The redirect the render captured, or undefined when it has not redirected.
10
+ */
11
+ getServerRedirect: () => RenderRedirect | undefined;
12
+ };
13
+ export declare function createServerRedirect(): ServerRedirect;
14
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ import { PrefetchConfig } from '../types/prefetch';
2
+ import { ResolvedRoute } from '../types/resolved';
3
+ import { CreatedRouteOptions } from '../types/route';
4
+ import { DataKind } from './createNavigationStores';
5
+ import { AnyPayloadTransformer } from './payload';
6
+ import { AnyFunction } from '../types/utilities';
7
+ /**
8
+ * Something a route computes: a view's props getter, or a loader. Both are a named callback belonging to
9
+ * one match, so both are stored the same way — what differs is only what waits on them.
10
+ */
11
+ export type Computation = {
12
+ kind: DataKind;
13
+ id: string;
14
+ name: string;
15
+ depth: number;
16
+ key: string;
17
+ run: AnyFunction;
18
+ routePrefetch: PrefetchConfig | undefined;
19
+ prefetch: PrefetchConfig | undefined;
20
+ transformer: AnyPayloadTransformer | undefined;
21
+ };
22
+ /**
23
+ * Where a value lives, which is all that is needed to read it back out of a store.
24
+ */
25
+ export type ValueLocation = {
26
+ kind: DataKind;
27
+ id: string;
28
+ name: string;
29
+ };
30
+ /**
31
+ * Decides which of a route's computations to compute.
32
+ */
33
+ export type ComputationFilter = (computation: Computation) => boolean;
34
+ export declare function getComputations(route: ResolvedRoute): Computation[];
35
+ /**
36
+ * Only views with a getter, since a view with none is never computed and waiting on it would never settle.
37
+ */
38
+ export declare function propsLocations(match: CreatedRouteOptions): ValueLocation[];
39
+ export declare function loaderLocations(match: CreatedRouteOptions): ValueLocation[];
40
+ export declare function isKind(kind: DataKind): (computation: Computation) => boolean;
@@ -1,4 +1,4 @@
1
1
  import { ResolvedRoute } from '../types/resolved';
2
2
  import { Hooks } from '../models/hooks';
3
- export declare function getGlobalBeforeHooks(to: ResolvedRoute, from: ResolvedRoute | null, globalHooks: Hooks): Hooks;
4
- export declare function getGlobalAfterHooks(to: ResolvedRoute, from: ResolvedRoute | null, globalHooks: Hooks): Hooks;
3
+ export declare function getGlobalBeforeHooks(to: ResolvedRoute | null, from: ResolvedRoute | null, globalHooks: Hooks): Hooks;
4
+ export declare function getGlobalAfterHooks(to: ResolvedRoute | null, from: ResolvedRoute | null, globalHooks: Hooks): Hooks;
@@ -1 +1,2 @@
1
- export declare function getInitialUrl(initialUrl?: string): string;
1
+ import { RouterHistoryMode } from './createRouterHistory';
2
+ export declare function getInitialUrl(initialUrl?: string, mode?: RouterHistoryMode): string;
@@ -1,4 +1,4 @@
1
1
  import { ResolvedRoute } from '../types/resolved';
2
2
  import { Hooks } from '../models/hooks';
3
- export declare function getBeforeHooksFromRoutes(to: ResolvedRoute, from: ResolvedRoute | null): Hooks;
4
- export declare function getAfterHooksFromRoutes(to: ResolvedRoute, from: ResolvedRoute | null): Hooks;
3
+ export declare function getBeforeHooksFromRoutes(to: ResolvedRoute | null, from: ResolvedRoute | null): Hooks;
4
+ export declare function getAfterHooksFromRoutes(to: ResolvedRoute | null, from: ResolvedRoute | null): Hooks;
@@ -18,7 +18,9 @@ export declare function getRoutesForRouter(routes: Routes | Routes[], plugins?:
18
18
  prefetch?: import('../main').PrefetchConfig;
19
19
  context: import('../types/routeContext').RouteContext[];
20
20
  } & RouteInternal)[];
21
- rejections: (Rejection & RejectionInternal)[];
21
+ rejections: (Pick<import('../types/rejection').RejectionOptions<string>, "type" | "status"> & {
22
+ getTitle: import('../types/routeTitle').GetTitleCallback;
23
+ } & RejectionInternal)[];
22
24
  getRouteByName: (type: string) => Route | undefined;
23
25
  getRejectionByType: {
24
26
  (type: BuiltInRejectionType): (Rejection & RejectionInternal);
@@ -1,6 +1,6 @@
1
1
  import { HookLifecycle } from '../types/hooks';
2
2
  import { ResolvedRoute } from '../types/resolved';
3
- type RouteHookCondition = (to: ResolvedRoute, from: ResolvedRoute | null, depth: number) => boolean;
3
+ type RouteHookCondition = (to: ResolvedRoute | null, from: ResolvedRoute | null, depth: number) => boolean;
4
4
  export declare const isRouteEnter: RouteHookCondition;
5
5
  export declare const isRouteLeave: RouteHookCondition;
6
6
  export declare const isRouteUpdate: RouteHookCondition;
@@ -0,0 +1,86 @@
1
+ import { DataKind } from './createNavigationStores';
2
+ import { RouteValue } from './createRouteValueStore';
3
+ import { PayloadValueError } from '../errors/payloadValueError';
4
+ import { ResolvedRoute } from '../types/resolved';
5
+ export declare const PAYLOAD_ELEMENT_ID = "kitbag-payload";
6
+ /**
7
+ * The payload as a script tag to embed in the document a server sends.
8
+ *
9
+ * `<` is escaped so nothing in the payload can close the tag early, and the two unicode line separators
10
+ * because they terminate a line in javascript source. All three are json unicode escapes, so `JSON.parse`
11
+ * gives back exactly what went in.
12
+ */
13
+ export declare function payloadToScript(payload: RouterPayload): string;
14
+ export type TransformerOptions<TValue = unknown> = {
15
+ /**
16
+ * Transforms a value across the server render payload: `stringify` writes the value into the payload
17
+ * on the server, and `parse` reads it back on the client during hydration. Declare one for any value
18
+ * json cannot carry faithfully, such as a `Map`, `Set`, or `Date`, so the client adopts the same
19
+ * value the server rendered with. Defaults to json.
20
+ */
21
+ transformer?: PayloadTransformer<TValue>;
22
+ };
23
+ export type PayloadTransformer<TValue = unknown> = {
24
+ /**
25
+ * Turns a value into a string for the payload.
26
+ */
27
+ stringify: (value: TValue) => string;
28
+ /**
29
+ * Turns a string from the payload back into a value.
30
+ */
31
+ parse: (encoded: string) => TValue;
32
+ };
33
+ /**
34
+ * A transformer whose value type has been erased. Every loader's and view's transformer is stored in
35
+ * one record, so a stored one is typed for some value the record no longer names — `unknown` would
36
+ * claim it accepts anything, which a typed stringify does not.
37
+ */
38
+ export type AnyPayloadTransformer = PayloadTransformer<any>;
39
+ export declare const jsonTransformer: PayloadTransformer;
40
+ export type PayloadValue = {
41
+ kind: DataKind;
42
+ depth: number;
43
+ name: string;
44
+ encoded: string;
45
+ };
46
+ export type RouterPayload = SuccessPayload | RejectPayload;
47
+ type SuccessPayload = {
48
+ kind: 'success';
49
+ /**
50
+ * The url the server rendered.
51
+ */
52
+ url: string;
53
+ values: PayloadValue[];
54
+ };
55
+ type RejectPayload = {
56
+ kind: 'reject';
57
+ /**
58
+ * The url the server rendered.
59
+ */
60
+ url: string;
61
+ /**
62
+ * The type of the rejection the server rendered.
63
+ */
64
+ rejection: string;
65
+ };
66
+ export declare function isRouterPayload(value: unknown): value is RouterPayload;
67
+ /**
68
+ * The payload a server embedded in the document, or undefined when this is not a hydration.
69
+ */
70
+ export declare function getHydratingPayload(): RouterPayload | undefined;
71
+ type EncodedPayloadValues = {
72
+ values: PayloadValue[];
73
+ failures: PayloadValueError[];
74
+ };
75
+ /**
76
+ * Encodes settled values for the payload, each through its own stringifier or the fallback. A value that
77
+ * cannot be encoded is warned about, reported as a failure, and left out, so the client computes it again.
78
+ */
79
+ export declare function encodePayloadValues(route: ResolvedRoute, values: RouteValue[], fallback?: PayloadTransformer): EncodedPayloadValues;
80
+ /**
81
+ * Decodes payload values for the store to adopt, each through its own stringifier or the fallback. A
82
+ * value that is missing from the payload or that cannot be read is warned about and left out, so its
83
+ * getter runs again.
84
+ */
85
+ export declare function decodePayloadValues(route: ResolvedRoute, values: PayloadValue[], fallback?: PayloadTransformer): RouteValue[];
86
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { ParamGetSet } from '../types/paramTypes';
2
+ import { StandardSchemaV1 } from '@standard-schema/spec';
3
+ export interface ZodSchemaLike extends StandardSchemaV1<any> {
4
+ parse: (input: any) => any;
5
+ def: {
6
+ type: string;
7
+ };
8
+ }
9
+ export interface ValibotSchemaLike extends StandardSchemaV1<any> {
10
+ type: string;
11
+ }
12
+ export interface ArkTypeSchemaLike extends StandardSchemaV1<any> {
13
+ extends: (def: string) => boolean;
14
+ branches: readonly ArkTypeSchemaLike[];
15
+ }
16
+ export type StandardSchemaLike = ZodSchemaLike | ValibotSchemaLike | ArkTypeSchemaLike;
17
+ export declare function isZodSchema(value: unknown): value is ZodSchemaLike;
18
+ export declare function isValibotSchema(value: unknown): value is ValibotSchemaLike;
19
+ export declare function isArkTypeSchema(value: unknown): value is ArkTypeSchemaLike;
20
+ export declare function isStandardSchema(value: unknown): value is StandardSchemaLike;
21
+ export declare function createStandardSchemaParam<T>(schema: StandardSchemaLike): ParamGetSet<T>;
@@ -14,6 +14,11 @@ type UrlPartsInput = {
14
14
  };
15
15
  export declare function stringifyUrl(parts: UrlPartsInput): UrlString;
16
16
  export declare function parseUrl(value: string): UrlParts;
17
+ /**
18
+ * Ignores host, and sorts query params because the router reorders them when it separates declared
19
+ * params from the rest.
20
+ */
21
+ export declare function isSameUrl(left: string, right: string): boolean;
17
22
  export declare function updateUrl(url: string, updates: UrlPartsInput): UrlString;
18
23
  export declare function updateUrl(url: Partial<UrlParts>, updates: UrlPartsInput): UrlParts;
19
24
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,6 @@
1
1
  import { RouteWithMethods } from './routeWithMethods';
2
2
  import { PrefetchConfig } from './prefetch';
3
+ import { TransformerOptions } from '../services/payload';
3
4
  import { ResolvedRoute } from './resolved';
4
5
  import { CreatedRouteOptions, Route } from './route';
5
6
  import { RouteCallbackContext } from './routeCallbackContext';
@@ -19,7 +20,7 @@ export type LoaderGetter<TRoute extends Route = Route> = (route: ResolvedRoute<T
19
20
  *
20
21
  * @template TName - The loader's name, inferred from the `name` option.
21
22
  */
22
- export type AddLoaderOptions<TName extends string | undefined = string> = {
23
+ export type AddLoaderOptions<TName extends string | undefined = string, TValue = unknown> = TransformerOptions<TValue> & {
23
24
  /**
24
25
  * The name of the loader, which is the key its data is exposed under on the route. Defaults to the
25
26
  * unnamed loader, whose data is exposed as the route's data directly.
@@ -64,6 +65,6 @@ export type RouteAddLoader<TUrl extends Url = Url, TMatches extends CreatedRoute
64
65
  * @param load - The loader callback. Receives the resolved route and a context object.
65
66
  * @param options - The loader's `name` and `prefetch` config.
66
67
  */
67
- addLoader: <const TName extends string | undefined = undefined, const TGetter extends LoaderGetter<Route<TUrl, TMatches>> = LoaderGetter<Route<TUrl, TMatches>>>(load: TGetter, options?: AddLoaderOptions<TName>) => AddLoaderReturn<TUrl, TMatches, AddLoaderLoaders<CurrentMatchLoaders<TMatches>, TName, ReturnType<TGetter>>>;
68
+ addLoader: <const TName extends string | undefined = undefined, const TGetter extends LoaderGetter<Route<TUrl, TMatches>> = LoaderGetter<Route<TUrl, TMatches>>>(load: TGetter, options?: AddLoaderOptions<TName, Awaited<ReturnType<TGetter>>>) => AddLoaderReturn<TUrl, TMatches, AddLoaderLoaders<CurrentMatchLoaders<TMatches>, TName, ReturnType<TGetter>>>;
68
69
  };
69
70
  export {};
@@ -6,6 +6,7 @@ import { CreatedRouteOptions, Route } from './route';
6
6
  import { RouteCallbackContext } from './routeCallbackContext';
7
7
  import { RouteWithMethods } from './routeWithMethods';
8
8
  import { PrefetchConfig } from './prefetch';
9
+ import { TransformerOptions } from '../services/payload';
9
10
  import { RouteView, RouteViews } from './routeViews';
10
11
  import { Url } from './url';
11
12
  import { AnyFunction, Identity, LastInArray, MaybePromise } from './utilities';
@@ -31,7 +32,7 @@ type NewViewProps<TRoute extends Route, TComponent extends Component, TGetter ex
31
32
  * @template TName - The view's name, inferred from the `name` option.
32
33
  * @template TGetter - The view's props getter, inferred from the `props` option.
33
34
  */
34
- export type AddViewOptions<TName extends string | undefined = string, TGetter = PropsGetter> = {
35
+ export type AddViewOptions<TName extends string | undefined = string, TGetter = PropsGetter> = TransformerOptions<PayloadValueOf<TGetter>> & {
35
36
  /**
36
37
  * The name of the view, rendered by `<router-view name="..." />`. Defaults to the unnamed view.
37
38
  */
@@ -46,6 +47,10 @@ export type AddViewOptions<TName extends string | undefined = string, TGetter =
46
47
  */
47
48
  prefetch?: PrefetchConfig;
48
49
  };
50
+ /**
51
+ * What a getter resolves to, which is what its payload options carry.
52
+ */
53
+ type PayloadValueOf<TGetter> = TGetter extends (...args: any[]) => any ? Awaited<ReturnType<TGetter>> : unknown;
49
54
  /**
50
55
  * {@link AddViewOptions} with `props` promoted to required. Only reached for components that have
51
56
  * required props — everything else uses {@link AddViewOptions}, where `props` stays optional, so a view
@@ -54,7 +59,7 @@ export type AddViewOptions<TName extends string | undefined = string, TGetter =
54
59
  * Spelled out rather than intersected with {@link AddViewOptions} so that the literal `name` still
55
60
  * infers through the conditional args tuple.
56
61
  */
57
- type AddViewOptionsWithRequiredProps<TName extends string | undefined, TGetter> = {
62
+ type AddViewOptionsWithRequiredProps<TName extends string | undefined, TGetter> = TransformerOptions<PayloadValueOf<TGetter>> & {
58
63
  name?: TName;
59
64
  props: TGetter;
60
65
  prefetch?: PrefetchConfig;
@@ -1,3 +1,4 @@
1
+ import { RedirectStatus } from './router';
1
2
  import { RouterPush } from './routerPush';
2
3
  export type CallbackContextSuccess = {
3
4
  status: 'SUCCESS';
@@ -6,6 +7,14 @@ export type CallbackContextPush = {
6
7
  status: 'PUSH';
7
8
  to: Parameters<RouterPush>;
8
9
  };
10
+ export type CallbackContextRedirect = {
11
+ status: 'REDIRECT';
12
+ to: Parameters<RouterPush>;
13
+ /**
14
+ * The status the redirect declared, or undefined to use the router's `redirectStatus`.
15
+ */
16
+ redirectStatus: RedirectStatus | undefined;
17
+ };
9
18
  export type CallbackContextReject = {
10
19
  status: 'REJECT';
11
20
  type: string;