@tanstack/react-router 1.81.4 → 1.81.6
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/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +3 -2
- package/dist/cjs/index.d.cts +3 -2
- package/dist/cjs/location.d.cts +2 -2
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +14 -51
- package/dist/cjs/routeInfo.d.cts +6 -6
- package/dist/cjs/router.cjs +26 -5
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +3 -2
- package/dist/cjs/searchParams.cjs.map +1 -1
- package/dist/cjs/searchParams.d.cts +3 -3
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +17 -5
- package/dist/cjs/validators.d.cts +49 -0
- package/dist/esm/fileRoute.d.ts +3 -2
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/location.d.ts +2 -2
- package/dist/esm/route.d.ts +14 -51
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/routeInfo.d.ts +6 -6
- package/dist/esm/router.d.ts +3 -2
- package/dist/esm/router.js +26 -5
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/searchParams.d.ts +3 -3
- package/dist/esm/searchParams.js.map +1 -1
- package/dist/esm/utils.d.ts +17 -5
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/validators.d.ts +49 -0
- package/package.json +3 -3
- package/src/fileRoute.ts +2 -2
- package/src/index.tsx +18 -15
- package/src/location.ts +2 -2
- package/src/route.ts +32 -79
- package/src/routeInfo.ts +6 -6
- package/src/router.ts +31 -13
- package/src/searchParams.ts +2 -2
- package/src/utils.ts +38 -8
- package/src/validators.ts +106 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const defaultParseSearch: (searchStr: string) =>
|
|
1
|
+
import { AnySchema } from './validators.js';
|
|
2
|
+
export declare const defaultParseSearch: (searchStr: string) => AnySchema;
|
|
3
3
|
export declare const defaultStringifySearch: (search: Record<string, any>) => string;
|
|
4
|
-
export declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) =>
|
|
4
|
+
export declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) => AnySchema;
|
|
5
5
|
export declare function stringifySearchWith(stringify: (search: any) => string, parser?: (str: string) => any): (search: Record<string, any>) => string;
|
|
6
6
|
export type SearchSerializer = (searchObj: Record<string, any>) => string;
|
|
7
7
|
export type SearchParser = (searchStr: string) => Record<string, any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchParams.js","sources":["../../src/searchParams.ts"],"sourcesContent":["import { decode, encode } from './qss'\nimport type {
|
|
1
|
+
{"version":3,"file":"searchParams.js","sources":["../../src/searchParams.ts"],"sourcesContent":["import { decode, encode } from './qss'\nimport type { AnySchema } from './validators'\n\nexport const defaultParseSearch = parseSearchWith(JSON.parse)\nexport const defaultStringifySearch = stringifySearchWith(\n JSON.stringify,\n JSON.parse,\n)\n\nexport function parseSearchWith(parser: (str: string) => any) {\n return (searchStr: string): AnySchema => {\n if (searchStr.substring(0, 1) === '?') {\n searchStr = searchStr.substring(1)\n }\n\n const query: Record<string, unknown> = decode(searchStr)\n\n // Try to parse any query params that might be json\n for (const key in query) {\n const value = query[key]\n if (typeof value === 'string') {\n try {\n query[key] = parser(value)\n } catch (err) {\n //\n }\n }\n }\n\n return query\n }\n}\n\nexport function stringifySearchWith(\n stringify: (search: any) => string,\n parser?: (str: string) => any,\n) {\n function stringifyValue(val: any) {\n if (typeof val === 'object' && val !== null) {\n try {\n return stringify(val)\n } catch (err) {\n // silent\n }\n } else if (typeof val === 'string' && typeof parser === 'function') {\n try {\n // Check if it's a valid parseable string.\n // If it is, then stringify it again.\n parser(val)\n return stringify(val)\n } catch (err) {\n // silent\n }\n }\n return val\n }\n\n return (search: Record<string, any>) => {\n search = { ...search }\n\n Object.keys(search).forEach((key) => {\n const val = search[key]\n if (typeof val === 'undefined' || val === undefined) {\n delete search[key]\n } else {\n search[key] = stringifyValue(val)\n }\n })\n\n const searchStr = encode(search as Record<string, string>).toString()\n\n return searchStr ? `?${searchStr}` : ''\n }\n}\n\nexport type SearchSerializer = (searchObj: Record<string, any>) => string\nexport type SearchParser = (searchStr: string) => Record<string, any>\n"],"names":[],"mappings":";AAGa,MAAA,qBAAqB,gBAAgB,KAAK,KAAK;AACrD,MAAM,yBAAyB;AAAA,EACpC,KAAK;AAAA,EACL,KAAK;AACP;AAEO,SAAS,gBAAgB,QAA8B;AAC5D,SAAO,CAAC,cAAiC;AACvC,QAAI,UAAU,UAAU,GAAG,CAAC,MAAM,KAAK;AACzB,kBAAA,UAAU,UAAU,CAAC;AAAA,IAAA;AAG7B,UAAA,QAAiC,OAAO,SAAS;AAGvD,eAAW,OAAO,OAAO;AACjB,YAAA,QAAQ,MAAM,GAAG;AACnB,UAAA,OAAO,UAAU,UAAU;AACzB,YAAA;AACI,gBAAA,GAAG,IAAI,OAAO,KAAK;AAAA,iBAClB,KAAK;AAAA,QAAA;AAAA,MAEd;AAAA,IACF;AAGK,WAAA;AAAA,EACT;AACF;AAEgB,SAAA,oBACd,WACA,QACA;AACA,WAAS,eAAe,KAAU;AAChC,QAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM;AACvC,UAAA;AACF,eAAO,UAAU,GAAG;AAAA,eACb,KAAK;AAAA,MAAA;AAAA,eAGL,OAAO,QAAQ,YAAY,OAAO,WAAW,YAAY;AAC9D,UAAA;AAGF,eAAO,GAAG;AACV,eAAO,UAAU,GAAG;AAAA,eACb,KAAK;AAAA,MAAA;AAAA,IAEd;AAEK,WAAA;AAAA,EAAA;AAGT,SAAO,CAAC,WAAgC;AAC7B,aAAA,EAAE,GAAG,OAAO;AAErB,WAAO,KAAK,MAAM,EAAE,QAAQ,CAAC,QAAQ;AAC7B,YAAA,MAAM,OAAO,GAAG;AACtB,UAAI,OAAO,QAAQ,eAAe,QAAQ,QAAW;AACnD,eAAO,OAAO,GAAG;AAAA,MAAA,OACZ;AACE,eAAA,GAAG,IAAI,eAAe,GAAG;AAAA,MAAA;AAAA,IAClC,CACD;AAED,UAAM,YAAY,OAAO,MAAgC,EAAE,SAAS;AAE7D,WAAA,YAAY,IAAI,SAAS,KAAK;AAAA,EACvC;AACF;"}
|
package/dist/esm/utils.d.ts
CHANGED
|
@@ -25,13 +25,25 @@ export type Assign<TLeft, TRight> = keyof TLeft extends never ? TRight : keyof T
|
|
|
25
25
|
export type Timeout = ReturnType<typeof setTimeout>;
|
|
26
26
|
export type Updater<TPrevious, TResult = TPrevious> = TResult | ((prev?: TPrevious) => TResult);
|
|
27
27
|
export type NonNullableUpdater<TPrevious, TResult = TPrevious> = TResult | ((prev: TPrevious) => TResult);
|
|
28
|
-
export type
|
|
29
|
-
export type
|
|
28
|
+
export type ExtractObjects<TUnion> = TUnion extends MergeAllPrimitive ? never : TUnion;
|
|
29
|
+
export type PartialMergeAllObject<TUnion> = ExtractObjects<TUnion> extends infer TObj ? {
|
|
30
30
|
[TKey in TObj extends any ? keyof TObj : never]?: TObj extends any ? TKey extends keyof TObj ? TObj[TKey] : never : never;
|
|
31
31
|
} : never;
|
|
32
|
-
export type
|
|
33
|
-
export type
|
|
34
|
-
export type
|
|
32
|
+
export type MergeAllPrimitive = ReadonlyArray<any> | number | string | bigint | boolean | symbol | undefined | null;
|
|
33
|
+
export type ExtractPrimitives<TUnion> = TUnion extends MergeAllPrimitive ? TUnion : TUnion extends object ? never : TUnion;
|
|
34
|
+
export type PartialMergeAll<TUnion> = ExtractPrimitives<TUnion> | PartialMergeAllObject<TUnion>;
|
|
35
|
+
/**
|
|
36
|
+
* To be added to router types
|
|
37
|
+
*/
|
|
38
|
+
export type UnionToIntersection<T> = (T extends any ? (arg: T) => any : never) extends (arg: infer T) => any ? T : never;
|
|
39
|
+
/**
|
|
40
|
+
* Merges everything in a union into one object.
|
|
41
|
+
* This mapped type is homomorphic which means it preserves stuff! :)
|
|
42
|
+
*/
|
|
43
|
+
export type MergeAllObjects<TUnion, TIntersected = UnionToIntersection<ExtractObjects<TUnion>>> = [keyof TIntersected] extends [never] ? never : {
|
|
44
|
+
[TKey in keyof TIntersected]: TUnion extends any ? TUnion[TKey & keyof TUnion] : never;
|
|
45
|
+
};
|
|
46
|
+
export type MergeAll<TUnion> = MergeAllObjects<TUnion> | ExtractPrimitives<TUnion>;
|
|
35
47
|
export type Constrain<T, TConstraint, TDefault = TConstraint> = (T extends TConstraint ? T : never) | TDefault;
|
|
36
48
|
export type ValidateJSON<T> = ((...args: Array<any>) => any) extends T ? unknown extends T ? never : 'Function is not serializable' : {
|
|
37
49
|
[K in keyof T]: ValidateJSON<T[K]>;
|
package/dist/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\nimport type { RouteIds } from './routeInfo'\nimport type { AnyRouter } from './router'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\nexport type IsAny<TValue, TYesResult, TNoResult = TValue> = 1 extends 0 & TValue\n ? TYesResult\n : TNoResult\n\nexport type PickAsRequired<TValue, TKey extends keyof TValue> = Omit<\n TValue,\n TKey\n> &\n Required<Pick<TValue, TKey>>\n\nexport type PickRequired<T> = {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K]\n}\n\nexport type PickOptional<T> = {\n [K in keyof T as undefined extends T[K] ? K : never]: T[K]\n}\n\n// from https://stackoverflow.com/a/76458160\nexport type WithoutEmpty<T> = T extends any ? ({} extends T ? never : T) : never\n\n// export type Expand<T> = T\nexport type Expand<T> = T extends object\n ? T extends infer O\n ? O extends Function\n ? O\n : { [K in keyof O]: O[K] }\n : never\n : T\n\nexport type DeepPartial<T> = T extends object\n ? {\n [P in keyof T]?: DeepPartial<T[P]>\n }\n : T\n\nexport type MakeDifferenceOptional<TLeft, TRight> = Omit<\n TRight,\n keyof TLeft\n> & {\n [K in keyof TLeft & keyof TRight]?: TRight[K]\n}\n\n// from https://stackoverflow.com/a/53955431\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type IsUnion<T, U extends T = T> = (\n T extends any ? (U extends T ? false : true) : never\n) extends false\n ? false\n : true\n\nexport type Assign<TLeft, TRight> = keyof TLeft extends never\n ? TRight\n : keyof TRight extends never\n ? TLeft\n : keyof TLeft & keyof TRight extends never\n ? TLeft & TRight\n : Omit<TLeft, keyof TRight> & TRight\n\nexport type Timeout = ReturnType<typeof setTimeout>\n\nexport type Updater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev?: TPrevious) => TResult)\n\nexport type NonNullableUpdater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev: TPrevious) => TResult)\n\nexport type MergeUnionObjects<TUnion> = TUnion extends MergeUnionPrimitive\n ? never\n : TUnion\n\nexport type MergeUnionObject<TUnion> =\n MergeUnionObjects<TUnion> extends infer TObj\n ? {\n [TKey in TObj extends any ? keyof TObj : never]?: TObj extends any\n ? TKey extends keyof TObj\n ? TObj[TKey]\n : never\n : never\n }\n : never\n\nexport type MergeUnionPrimitive =\n | ReadonlyArray<any>\n | number\n | string\n | bigint\n | boolean\n | symbol\n\nexport type MergeUnionPrimitives<TUnion> = TUnion extends MergeUnionPrimitive\n ? TUnion\n : TUnion extends object\n ? never\n : TUnion\n\nexport type MergeUnion<TUnion> =\n | MergeUnionPrimitives<TUnion>\n | MergeUnionObject<TUnion>\n\nexport type Constrain<T, TConstraint, TDefault = TConstraint> =\n | (T extends TConstraint ? T : never)\n | TDefault\n\nexport type ValidateJSON<T> = ((...args: Array<any>) => any) extends T\n ? unknown extends T\n ? never\n : 'Function is not serializable'\n : { [K in keyof T]: ValidateJSON<T[K]> }\n\nexport function last<T>(arr: Array<T>) {\n return arr[arr.length - 1]\n}\n\nfunction isFunction(d: any): d is Function {\n return typeof d === 'function'\n}\n\nexport function functionalUpdate<TResult>(\n updater: Updater<TResult> | NonNullableUpdater<TResult>,\n previous: TResult,\n): TResult {\n if (isFunction(updater)) {\n return updater(previous)\n }\n\n return updater\n}\n\nexport function pick<TValue, TKey extends keyof TValue>(\n parent: TValue,\n keys: Array<TKey>,\n): Pick<TValue, TKey> {\n return keys.reduce((obj: any, key: TKey) => {\n obj[key] = parent[key]\n return obj\n }, {} as any)\n}\n\n/**\n * This function returns `prev` if `_next` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between immutable JSON values for example.\n * Do not use this with signals\n */\nexport function replaceEqualDeep<T>(prev: any, _next: T): T {\n if (prev === _next) {\n return prev\n }\n\n const next = _next as any\n\n const array = isPlainArray(prev) && isPlainArray(next)\n\n if (array || (isPlainObject(prev) && isPlainObject(next))) {\n const prevItems = array ? prev : Object.keys(prev)\n const prevSize = prevItems.length\n const nextItems = array ? next : Object.keys(next)\n const nextSize = nextItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < nextSize; i++) {\n const key = array ? i : (nextItems[i] as any)\n if (\n ((!array && prevItems.includes(key)) || array) &&\n prev[key] === undefined &&\n next[key] === undefined\n ) {\n copy[key] = undefined\n equalItems++\n } else {\n copy[key] = replaceEqualDeep(prev[key], next[key])\n if (copy[key] === prev[key] && prev[key] !== undefined) {\n equalItems++\n }\n }\n }\n\n return prevSize === nextSize && equalItems === prevSize ? prev : copy\n }\n\n return next\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any) {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any) {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\nexport function isPlainArray(value: unknown): value is Array<unknown> {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\nfunction getObjectKeys(obj: any, ignoreUndefined: boolean) {\n let keys = Object.keys(obj)\n if (ignoreUndefined) {\n keys = keys.filter((key) => obj[key] !== undefined)\n }\n return keys\n}\n\nexport function deepEqual(\n a: any,\n b: any,\n opts?: { partial?: boolean; ignoreUndefined?: boolean },\n): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (isPlainObject(a) && isPlainObject(b)) {\n const ignoreUndefined = opts?.ignoreUndefined ?? true\n const aKeys = getObjectKeys(a, ignoreUndefined)\n const bKeys = getObjectKeys(b, ignoreUndefined)\n\n if (!opts?.partial && aKeys.length !== bKeys.length) {\n return false\n }\n\n return bKeys.every((key) => deepEqual(a[key], b[key], opts))\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) {\n return false\n }\n return !a.some((item, index) => !deepEqual(item, b[index], opts))\n }\n\n return false\n}\n\nexport function useStableCallback<T extends (...args: Array<any>) => any>(\n fn: T,\n): T {\n const fnRef = React.useRef(fn)\n fnRef.current = fn\n\n const ref = React.useRef((...args: Array<any>) => fnRef.current(...args))\n return ref.current as T\n}\n\nexport function shallow<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n const keysA = Object.keys(objA)\n if (keysA.length !== Object.keys(objB).length) {\n return false\n }\n\n for (const item of keysA) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, item) ||\n !Object.is(objA[item as keyof T], objB[item as keyof T])\n ) {\n return false\n }\n }\n return true\n}\n\nexport type StringLiteral<T> = T extends string\n ? string extends T\n ? string\n : T\n : never\n\nexport type StrictOrFrom<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean = true,\n> = TStrict extends false\n ? {\n from?: never\n strict: TStrict\n }\n : {\n from: StringLiteral<Constrain<TFrom, RouteIds<TRouter['routeTree']>>>\n strict?: TStrict\n }\n\nexport type ThrowOrOptional<T, TThrow extends boolean> = TThrow extends true\n ? T\n : T | undefined\n\nexport const useLayoutEffect =\n typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\n/**\n *\n * @deprecated use `jsesc` instead\n */\nexport function escapeJSON(jsonString: string) {\n return jsonString\n .replace(/\\\\/g, '\\\\\\\\') // Escape backslashes\n .replace(/'/g, \"\\\\'\") // Escape single quotes\n .replace(/\"/g, '\\\\\"') // Escape double quotes\n}\n\nexport type ControlledPromise<T> = Promise<T> & {\n resolve: (value: T) => void\n reject: (value: any) => void\n status: 'pending' | 'resolved' | 'rejected'\n value?: T\n}\n\nexport function createControlledPromise<T>(onResolve?: (value: T) => void) {\n let resolveLoadPromise!: (value: T) => void\n let rejectLoadPromise!: (value: any) => void\n\n const controlledPromise = new Promise<T>((resolve, reject) => {\n resolveLoadPromise = resolve\n rejectLoadPromise = reject\n }) as ControlledPromise<T>\n\n controlledPromise.status = 'pending'\n\n controlledPromise.resolve = (value: T) => {\n controlledPromise.status = 'resolved'\n controlledPromise.value = value\n resolveLoadPromise(value)\n onResolve?.(value)\n }\n\n controlledPromise.reject = (e) => {\n controlledPromise.status = 'rejected'\n rejectLoadPromise(e)\n }\n\n return controlledPromise\n}\n\n/**\n * Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3\n */\nexport function usePrevious<T>(value: T): T | null {\n // initialise the ref with previous and current values\n const ref = React.useRef<{ value: T; prev: T | null }>({\n value: value,\n prev: null,\n })\n\n const current = ref.current.value\n\n // if the value passed into hook doesn't match what we store as \"current\"\n // move the \"current\" to the \"previous\"\n // and store the passed value as \"current\"\n if (value !== current) {\n ref.current = {\n value: value,\n prev: current,\n }\n }\n\n // return the previous value only\n return ref.current.prev\n}\n\n/**\n * React hook to wrap `IntersectionObserver`.\n *\n * This hook will create an `IntersectionObserver` and observe the ref passed to it.\n *\n * When the intersection changes, the callback will be called with the `IntersectionObserverEntry`.\n *\n * @param ref - The ref to observe\n * @param intersectionObserverOptions - The options to pass to the IntersectionObserver\n * @param options - The options to pass to the hook\n * @param callback - The callback to call when the intersection changes\n * @returns The IntersectionObserver instance\n * @example\n * ```tsx\n * const MyComponent = () => {\n * const ref = React.useRef<HTMLDivElement>(null)\n * useIntersectionObserver(\n * ref,\n * (entry) => { doSomething(entry) },\n * { rootMargin: '10px' },\n * { disabled: false }\n * )\n * return <div ref={ref} />\n * ```\n */\nexport function useIntersectionObserver<T extends Element>(\n ref: React.RefObject<T>,\n callback: (entry: IntersectionObserverEntry | undefined) => void,\n intersectionObserverOptions: IntersectionObserverInit = {},\n options: { disabled?: boolean } = {},\n): IntersectionObserver | null {\n const isIntersectionObserverAvailable = React.useRef(\n typeof IntersectionObserver === 'function',\n )\n\n const observerRef = React.useRef<IntersectionObserver | null>(null)\n\n React.useEffect(() => {\n if (\n !ref.current ||\n !isIntersectionObserverAvailable.current ||\n options.disabled\n ) {\n return\n }\n\n observerRef.current = new IntersectionObserver(([entry]) => {\n callback(entry)\n }, intersectionObserverOptions)\n\n observerRef.current.observe(ref.current)\n\n return () => {\n observerRef.current?.disconnect()\n }\n }, [callback, intersectionObserverOptions, options.disabled, ref])\n\n return observerRef.current\n}\n\n/**\n * React hook to take a `React.ForwardedRef` and returns a `ref` that can be used on a DOM element.\n *\n * @param ref - The forwarded ref\n * @returns The inner ref returned by `useRef`\n * @example\n * ```tsx\n * const MyComponent = React.forwardRef((props, ref) => {\n * const innerRef = useForwardedRef(ref)\n * return <div ref={innerRef} />\n * })\n * ```\n */\nexport function useForwardedRef<T>(ref?: React.ForwardedRef<T>) {\n const innerRef = React.useRef<T>(null)\n\n React.useEffect(() => {\n if (!ref) return\n if (typeof ref === 'function') {\n ref(innerRef.current)\n } else {\n ref.current = innerRef.current\n }\n })\n\n return innerRef\n}\n"],"names":[],"mappings":";AAqHO,SAAS,KAAQ,KAAe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A,IAAA,OACf;AACL,UAAI,UAAU,SAAS;AAAA,IAAA;AAAA,EACzB,CACD;AAEM,SAAA;AACT;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\nimport type { RouteIds } from './routeInfo'\nimport type { AnyRouter } from './router'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\nexport type IsAny<TValue, TYesResult, TNoResult = TValue> = 1 extends 0 & TValue\n ? TYesResult\n : TNoResult\n\nexport type PickAsRequired<TValue, TKey extends keyof TValue> = Omit<\n TValue,\n TKey\n> &\n Required<Pick<TValue, TKey>>\n\nexport type PickRequired<T> = {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K]\n}\n\nexport type PickOptional<T> = {\n [K in keyof T as undefined extends T[K] ? K : never]: T[K]\n}\n\n// from https://stackoverflow.com/a/76458160\nexport type WithoutEmpty<T> = T extends any ? ({} extends T ? never : T) : never\n\n// export type Expand<T> = T\nexport type Expand<T> = T extends object\n ? T extends infer O\n ? O extends Function\n ? O\n : { [K in keyof O]: O[K] }\n : never\n : T\n\nexport type DeepPartial<T> = T extends object\n ? {\n [P in keyof T]?: DeepPartial<T[P]>\n }\n : T\n\nexport type MakeDifferenceOptional<TLeft, TRight> = Omit<\n TRight,\n keyof TLeft\n> & {\n [K in keyof TLeft & keyof TRight]?: TRight[K]\n}\n\n// from https://stackoverflow.com/a/53955431\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type IsUnion<T, U extends T = T> = (\n T extends any ? (U extends T ? false : true) : never\n) extends false\n ? false\n : true\n\nexport type Assign<TLeft, TRight> = keyof TLeft extends never\n ? TRight\n : keyof TRight extends never\n ? TLeft\n : keyof TLeft & keyof TRight extends never\n ? TLeft & TRight\n : Omit<TLeft, keyof TRight> & TRight\n\nexport type Timeout = ReturnType<typeof setTimeout>\n\nexport type Updater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev?: TPrevious) => TResult)\n\nexport type NonNullableUpdater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev: TPrevious) => TResult)\n\nexport type ExtractObjects<TUnion> = TUnion extends MergeAllPrimitive\n ? never\n : TUnion\n\nexport type PartialMergeAllObject<TUnion> =\n ExtractObjects<TUnion> extends infer TObj\n ? {\n [TKey in TObj extends any ? keyof TObj : never]?: TObj extends any\n ? TKey extends keyof TObj\n ? TObj[TKey]\n : never\n : never\n }\n : never\n\nexport type MergeAllPrimitive =\n | ReadonlyArray<any>\n | number\n | string\n | bigint\n | boolean\n | symbol\n | undefined\n | null\n\nexport type ExtractPrimitives<TUnion> = TUnion extends MergeAllPrimitive\n ? TUnion\n : TUnion extends object\n ? never\n : TUnion\n\nexport type PartialMergeAll<TUnion> =\n | ExtractPrimitives<TUnion>\n | PartialMergeAllObject<TUnion>\n\n/**\n * To be added to router types\n */\nexport type UnionToIntersection<T> = (\n T extends any ? (arg: T) => any : never\n) extends (arg: infer T) => any\n ? T\n : never\n\n/**\n * Merges everything in a union into one object.\n * This mapped type is homomorphic which means it preserves stuff! :)\n */\nexport type MergeAllObjects<\n TUnion,\n TIntersected = UnionToIntersection<ExtractObjects<TUnion>>,\n> = [keyof TIntersected] extends [never]\n ? never\n : {\n [TKey in keyof TIntersected]: TUnion extends any\n ? TUnion[TKey & keyof TUnion]\n : never\n }\n\nexport type MergeAll<TUnion> =\n | MergeAllObjects<TUnion>\n | ExtractPrimitives<TUnion>\n\nexport type Constrain<T, TConstraint, TDefault = TConstraint> =\n | (T extends TConstraint ? T : never)\n | TDefault\n\nexport type ValidateJSON<T> = ((...args: Array<any>) => any) extends T\n ? unknown extends T\n ? never\n : 'Function is not serializable'\n : { [K in keyof T]: ValidateJSON<T[K]> }\n\nexport function last<T>(arr: Array<T>) {\n return arr[arr.length - 1]\n}\n\nfunction isFunction(d: any): d is Function {\n return typeof d === 'function'\n}\n\nexport function functionalUpdate<TResult>(\n updater: Updater<TResult> | NonNullableUpdater<TResult>,\n previous: TResult,\n): TResult {\n if (isFunction(updater)) {\n return updater(previous)\n }\n\n return updater\n}\n\nexport function pick<TValue, TKey extends keyof TValue>(\n parent: TValue,\n keys: Array<TKey>,\n): Pick<TValue, TKey> {\n return keys.reduce((obj: any, key: TKey) => {\n obj[key] = parent[key]\n return obj\n }, {} as any)\n}\n\n/**\n * This function returns `prev` if `_next` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between immutable JSON values for example.\n * Do not use this with signals\n */\nexport function replaceEqualDeep<T>(prev: any, _next: T): T {\n if (prev === _next) {\n return prev\n }\n\n const next = _next as any\n\n const array = isPlainArray(prev) && isPlainArray(next)\n\n if (array || (isPlainObject(prev) && isPlainObject(next))) {\n const prevItems = array ? prev : Object.keys(prev)\n const prevSize = prevItems.length\n const nextItems = array ? next : Object.keys(next)\n const nextSize = nextItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < nextSize; i++) {\n const key = array ? i : (nextItems[i] as any)\n if (\n ((!array && prevItems.includes(key)) || array) &&\n prev[key] === undefined &&\n next[key] === undefined\n ) {\n copy[key] = undefined\n equalItems++\n } else {\n copy[key] = replaceEqualDeep(prev[key], next[key])\n if (copy[key] === prev[key] && prev[key] !== undefined) {\n equalItems++\n }\n }\n }\n\n return prevSize === nextSize && equalItems === prevSize ? prev : copy\n }\n\n return next\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any) {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any) {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\nexport function isPlainArray(value: unknown): value is Array<unknown> {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\nfunction getObjectKeys(obj: any, ignoreUndefined: boolean) {\n let keys = Object.keys(obj)\n if (ignoreUndefined) {\n keys = keys.filter((key) => obj[key] !== undefined)\n }\n return keys\n}\n\nexport function deepEqual(\n a: any,\n b: any,\n opts?: { partial?: boolean; ignoreUndefined?: boolean },\n): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (isPlainObject(a) && isPlainObject(b)) {\n const ignoreUndefined = opts?.ignoreUndefined ?? true\n const aKeys = getObjectKeys(a, ignoreUndefined)\n const bKeys = getObjectKeys(b, ignoreUndefined)\n\n if (!opts?.partial && aKeys.length !== bKeys.length) {\n return false\n }\n\n return bKeys.every((key) => deepEqual(a[key], b[key], opts))\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) {\n return false\n }\n return !a.some((item, index) => !deepEqual(item, b[index], opts))\n }\n\n return false\n}\n\nexport function useStableCallback<T extends (...args: Array<any>) => any>(\n fn: T,\n): T {\n const fnRef = React.useRef(fn)\n fnRef.current = fn\n\n const ref = React.useRef((...args: Array<any>) => fnRef.current(...args))\n return ref.current as T\n}\n\nexport function shallow<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n const keysA = Object.keys(objA)\n if (keysA.length !== Object.keys(objB).length) {\n return false\n }\n\n for (const item of keysA) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, item) ||\n !Object.is(objA[item as keyof T], objB[item as keyof T])\n ) {\n return false\n }\n }\n return true\n}\n\nexport type StringLiteral<T> = T extends string\n ? string extends T\n ? string\n : T\n : never\n\nexport type StrictOrFrom<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean = true,\n> = TStrict extends false\n ? {\n from?: never\n strict: TStrict\n }\n : {\n from: StringLiteral<Constrain<TFrom, RouteIds<TRouter['routeTree']>>>\n strict?: TStrict\n }\n\nexport type ThrowOrOptional<T, TThrow extends boolean> = TThrow extends true\n ? T\n : T | undefined\n\nexport const useLayoutEffect =\n typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\n/**\n *\n * @deprecated use `jsesc` instead\n */\nexport function escapeJSON(jsonString: string) {\n return jsonString\n .replace(/\\\\/g, '\\\\\\\\') // Escape backslashes\n .replace(/'/g, \"\\\\'\") // Escape single quotes\n .replace(/\"/g, '\\\\\"') // Escape double quotes\n}\n\nexport type ControlledPromise<T> = Promise<T> & {\n resolve: (value: T) => void\n reject: (value: any) => void\n status: 'pending' | 'resolved' | 'rejected'\n value?: T\n}\n\nexport function createControlledPromise<T>(onResolve?: (value: T) => void) {\n let resolveLoadPromise!: (value: T) => void\n let rejectLoadPromise!: (value: any) => void\n\n const controlledPromise = new Promise<T>((resolve, reject) => {\n resolveLoadPromise = resolve\n rejectLoadPromise = reject\n }) as ControlledPromise<T>\n\n controlledPromise.status = 'pending'\n\n controlledPromise.resolve = (value: T) => {\n controlledPromise.status = 'resolved'\n controlledPromise.value = value\n resolveLoadPromise(value)\n onResolve?.(value)\n }\n\n controlledPromise.reject = (e) => {\n controlledPromise.status = 'rejected'\n rejectLoadPromise(e)\n }\n\n return controlledPromise\n}\n\n/**\n * Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3\n */\nexport function usePrevious<T>(value: T): T | null {\n // initialise the ref with previous and current values\n const ref = React.useRef<{ value: T; prev: T | null }>({\n value: value,\n prev: null,\n })\n\n const current = ref.current.value\n\n // if the value passed into hook doesn't match what we store as \"current\"\n // move the \"current\" to the \"previous\"\n // and store the passed value as \"current\"\n if (value !== current) {\n ref.current = {\n value: value,\n prev: current,\n }\n }\n\n // return the previous value only\n return ref.current.prev\n}\n\n/**\n * React hook to wrap `IntersectionObserver`.\n *\n * This hook will create an `IntersectionObserver` and observe the ref passed to it.\n *\n * When the intersection changes, the callback will be called with the `IntersectionObserverEntry`.\n *\n * @param ref - The ref to observe\n * @param intersectionObserverOptions - The options to pass to the IntersectionObserver\n * @param options - The options to pass to the hook\n * @param callback - The callback to call when the intersection changes\n * @returns The IntersectionObserver instance\n * @example\n * ```tsx\n * const MyComponent = () => {\n * const ref = React.useRef<HTMLDivElement>(null)\n * useIntersectionObserver(\n * ref,\n * (entry) => { doSomething(entry) },\n * { rootMargin: '10px' },\n * { disabled: false }\n * )\n * return <div ref={ref} />\n * ```\n */\nexport function useIntersectionObserver<T extends Element>(\n ref: React.RefObject<T>,\n callback: (entry: IntersectionObserverEntry | undefined) => void,\n intersectionObserverOptions: IntersectionObserverInit = {},\n options: { disabled?: boolean } = {},\n): IntersectionObserver | null {\n const isIntersectionObserverAvailable = React.useRef(\n typeof IntersectionObserver === 'function',\n )\n\n const observerRef = React.useRef<IntersectionObserver | null>(null)\n\n React.useEffect(() => {\n if (\n !ref.current ||\n !isIntersectionObserverAvailable.current ||\n options.disabled\n ) {\n return\n }\n\n observerRef.current = new IntersectionObserver(([entry]) => {\n callback(entry)\n }, intersectionObserverOptions)\n\n observerRef.current.observe(ref.current)\n\n return () => {\n observerRef.current?.disconnect()\n }\n }, [callback, intersectionObserverOptions, options.disabled, ref])\n\n return observerRef.current\n}\n\n/**\n * React hook to take a `React.ForwardedRef` and returns a `ref` that can be used on a DOM element.\n *\n * @param ref - The forwarded ref\n * @returns The inner ref returned by `useRef`\n * @example\n * ```tsx\n * const MyComponent = React.forwardRef((props, ref) => {\n * const innerRef = useForwardedRef(ref)\n * return <div ref={innerRef} />\n * })\n * ```\n */\nexport function useForwardedRef<T>(ref?: React.ForwardedRef<T>) {\n const innerRef = React.useRef<T>(null)\n\n React.useEffect(() => {\n if (!ref) return\n if (typeof ref === 'function') {\n ref(innerRef.current)\n } else {\n ref.current = innerRef.current\n }\n })\n\n return innerRef\n}\n"],"names":[],"mappings":";AAmJO,SAAS,KAAQ,KAAe;AAC9B,SAAA,IAAI,IAAI,SAAS,CAAC;AAC3B;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A;AAAA,EACzB,CACD;AAEM,SAAA;AACT;"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { SearchSchemaInput } from './route.js';
|
|
2
|
+
export interface StandardSchemaValidatorProps<TInput, TOutput> {
|
|
3
|
+
readonly types?: StandardSchemaValidatorTypes<TInput, TOutput> | undefined;
|
|
4
|
+
readonly validate: AnyStandardSchemaValidate;
|
|
5
|
+
}
|
|
6
|
+
export interface StandardSchemaValidator<TInput, TOutput> {
|
|
7
|
+
readonly '~standard': StandardSchemaValidatorProps<TInput, TOutput>;
|
|
8
|
+
}
|
|
9
|
+
export type AnyStandardSchemaValidator = StandardSchemaValidator<any, any>;
|
|
10
|
+
export interface StandardSchemaValidatorTypes<TInput, TOutput> {
|
|
11
|
+
readonly input: TInput;
|
|
12
|
+
readonly output: TOutput;
|
|
13
|
+
}
|
|
14
|
+
export interface AnyStandardSchemaValidateSuccess {
|
|
15
|
+
readonly value: any;
|
|
16
|
+
readonly issues?: undefined;
|
|
17
|
+
}
|
|
18
|
+
export interface AnyStandardSchemaValidateFailure {
|
|
19
|
+
readonly issues: ReadonlyArray<AnyStandardSchemaValidateIssue>;
|
|
20
|
+
}
|
|
21
|
+
export interface AnyStandardSchemaValidateIssue {
|
|
22
|
+
readonly message: string;
|
|
23
|
+
}
|
|
24
|
+
export interface AnyStandardSchemaValidateInput {
|
|
25
|
+
readonly value: any;
|
|
26
|
+
}
|
|
27
|
+
export type AnyStandardSchemaValidate = (value: unknown) => (AnyStandardSchemaValidateSuccess | AnyStandardSchemaValidateFailure) | Promise<AnyStandardSchemaValidateSuccess | AnyStandardSchemaValidateFailure>;
|
|
28
|
+
export interface ValidatorObj<TInput, TOutput> {
|
|
29
|
+
parse: ValidatorFn<TInput, TOutput>;
|
|
30
|
+
}
|
|
31
|
+
export type AnyValidatorObj = ValidatorObj<any, any>;
|
|
32
|
+
export interface ValidatorAdapter<TInput, TOutput> {
|
|
33
|
+
types: {
|
|
34
|
+
input: TInput;
|
|
35
|
+
output: TOutput;
|
|
36
|
+
};
|
|
37
|
+
parse: (input: unknown) => TOutput;
|
|
38
|
+
}
|
|
39
|
+
export type AnyValidatorAdapter = ValidatorAdapter<any, any>;
|
|
40
|
+
export type AnyValidatorFn = ValidatorFn<any, any>;
|
|
41
|
+
export type ValidatorFn<TInput, TOutput> = (input: TInput) => TOutput;
|
|
42
|
+
export type Validator<TInput, TOutput> = ValidatorObj<TInput, TOutput> | ValidatorFn<TInput, TOutput> | ValidatorAdapter<TInput, TOutput> | StandardSchemaValidator<TInput, TOutput> | undefined;
|
|
43
|
+
export type AnyValidator = Validator<any, any>;
|
|
44
|
+
export type AnySchema = {};
|
|
45
|
+
export type DefaultValidator = Validator<Record<string, unknown>, AnySchema>;
|
|
46
|
+
export type ResolveValidatorInputFn<TValidator> = TValidator extends (input: infer TSchemaInput) => any ? TSchemaInput extends SearchSchemaInput ? Omit<TSchemaInput, keyof SearchSchemaInput> : ResolveValidatorOutputFn<TValidator> : AnySchema;
|
|
47
|
+
export type ResolveValidatorInput<TValidator> = TValidator extends AnyStandardSchemaValidator ? NonNullable<TValidator['~standard']['types']>['input'] : TValidator extends AnyValidatorAdapter ? TValidator['types']['input'] : TValidator extends AnyValidatorObj ? ResolveValidatorInputFn<TValidator['parse']> : ResolveValidatorInputFn<TValidator>;
|
|
48
|
+
export type ResolveValidatorOutputFn<TValidator> = TValidator extends (...args: any) => infer TSchema ? TSchema : AnySchema;
|
|
49
|
+
export type ResolveValidatorOutput<TValidator> = unknown extends TValidator ? TValidator : TValidator extends AnyStandardSchemaValidator ? NonNullable<TValidator['~standard']['types']>['output'] : TValidator extends AnyValidatorAdapter ? TValidator['types']['output'] : TValidator extends AnyValidatorObj ? ResolveValidatorOutputFn<TValidator['parse']> : ResolveValidatorOutputFn<TValidator>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
|
-
"version": "1.81.
|
|
3
|
+
"version": "1.81.6",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"jsesc": "^3.0.2",
|
|
54
54
|
"tiny-invariant": "^1.3.3",
|
|
55
55
|
"tiny-warning": "^1.0.3",
|
|
56
|
-
"@tanstack/history": "1.81.
|
|
56
|
+
"@tanstack/history": "1.81.6"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/jsesc": "^3.0.3",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"react": ">=18",
|
|
70
70
|
"react-dom": ">=18",
|
|
71
|
-
"@tanstack/router-generator": "1.
|
|
71
|
+
"@tanstack/router-generator": "1.81.6"
|
|
72
72
|
},
|
|
73
73
|
"peerDependenciesMeta": {
|
|
74
74
|
"@tanstack/router-generator": {
|
package/src/fileRoute.ts
CHANGED
|
@@ -15,7 +15,6 @@ import type {
|
|
|
15
15
|
AnyContext,
|
|
16
16
|
AnyPathParams,
|
|
17
17
|
AnyRoute,
|
|
18
|
-
AnySearchValidator,
|
|
19
18
|
FileBaseRouteOptions,
|
|
20
19
|
ResolveParams,
|
|
21
20
|
RootRoute,
|
|
@@ -26,6 +25,7 @@ import type {
|
|
|
26
25
|
} from './route'
|
|
27
26
|
import type { RegisteredRouter } from './router'
|
|
28
27
|
import type { RouteById, RouteIds } from './routeInfo'
|
|
28
|
+
import type { AnyValidator } from './validators'
|
|
29
29
|
import type { UseLoaderDepsRoute } from './useLoaderDeps'
|
|
30
30
|
import type { UseLoaderDataRoute } from './useLoaderData'
|
|
31
31
|
import type { UseRouteContextRoute } from './useRouteContext'
|
|
@@ -190,7 +190,7 @@ export type LazyRouteOptions = Pick<
|
|
|
190
190
|
string,
|
|
191
191
|
string,
|
|
192
192
|
AnyPathParams,
|
|
193
|
-
|
|
193
|
+
AnyValidator,
|
|
194
194
|
{},
|
|
195
195
|
AnyContext,
|
|
196
196
|
AnyContext,
|
package/src/index.tsx
CHANGED
|
@@ -150,8 +150,6 @@ export type {
|
|
|
150
150
|
AnyPathParams,
|
|
151
151
|
ResolveParams,
|
|
152
152
|
SearchSchemaInput,
|
|
153
|
-
SearchValidatorAdapter,
|
|
154
|
-
AnySearchSchema,
|
|
155
153
|
AnyContext,
|
|
156
154
|
RouteContext,
|
|
157
155
|
PreloadableObj,
|
|
@@ -202,20 +200,9 @@ export type {
|
|
|
202
200
|
RouteContextOptions,
|
|
203
201
|
BeforeLoadFn,
|
|
204
202
|
BeforeLoadContextOptions,
|
|
205
|
-
AnySearchValidator,
|
|
206
|
-
DefaultSearchValidator,
|
|
207
203
|
ContextOptions,
|
|
208
|
-
SearchValidatorObj,
|
|
209
|
-
AnySearchValidatorObj,
|
|
210
|
-
AnySearchValidatorAdapter,
|
|
211
|
-
AnySearchValidatorFn,
|
|
212
|
-
SearchValidatorFn,
|
|
213
|
-
SearchValidator,
|
|
214
204
|
InferAllParams,
|
|
215
205
|
InferAllContext,
|
|
216
|
-
ResolveSearchSchemaFnInput,
|
|
217
|
-
ResolveSearchSchemaInput,
|
|
218
|
-
ResolveSearchSchema,
|
|
219
206
|
LooseReturnType,
|
|
220
207
|
LooseAsyncReturnType,
|
|
221
208
|
ContextReturnType,
|
|
@@ -226,7 +213,6 @@ export type {
|
|
|
226
213
|
ResolveLoaderData,
|
|
227
214
|
ResolveAllParamsFromParent,
|
|
228
215
|
ResolveRouteContext,
|
|
229
|
-
ResolveSearchSchemaFn,
|
|
230
216
|
} from './route'
|
|
231
217
|
|
|
232
218
|
export type {
|
|
@@ -351,6 +337,23 @@ export type { NotFoundError } from './not-found'
|
|
|
351
337
|
export type { Manifest, RouterManagedTag } from './manifest'
|
|
352
338
|
|
|
353
339
|
export { createControlledPromise } from './utils'
|
|
354
|
-
export type { ControlledPromise } from './utils'
|
|
340
|
+
export type { ControlledPromise, Constrain, Expand, MergeAll } from './utils'
|
|
341
|
+
|
|
342
|
+
export type {
|
|
343
|
+
ResolveValidatorInput,
|
|
344
|
+
ResolveValidatorOutput,
|
|
345
|
+
AnyValidator,
|
|
346
|
+
DefaultValidator,
|
|
347
|
+
ValidatorFn,
|
|
348
|
+
AnySchema,
|
|
349
|
+
AnyValidatorAdapter,
|
|
350
|
+
AnyValidatorFn,
|
|
351
|
+
AnyValidatorObj,
|
|
352
|
+
ResolveValidatorInputFn,
|
|
353
|
+
ResolveValidatorOutputFn,
|
|
354
|
+
Validator,
|
|
355
|
+
ValidatorAdapter,
|
|
356
|
+
ValidatorObj,
|
|
357
|
+
} from './validators'
|
|
355
358
|
|
|
356
359
|
export { retainSearchParams, stripSearchParams } from './searchMiddleware'
|
package/src/location.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HistoryState } from '@tanstack/history'
|
|
2
|
-
import type {
|
|
2
|
+
import type { AnySchema } from './validators'
|
|
3
3
|
|
|
4
|
-
export interface ParsedLocation<TSearchObj extends
|
|
4
|
+
export interface ParsedLocation<TSearchObj extends AnySchema = {}> {
|
|
5
5
|
href: string
|
|
6
6
|
pathname: string
|
|
7
7
|
search: TSearchObj
|
package/src/route.ts
CHANGED
|
@@ -29,6 +29,20 @@ import type { Assign, Constrain, Expand, NoInfer } from './utils'
|
|
|
29
29
|
import type { BuildLocationFn, NavigateFn } from './RouterProvider'
|
|
30
30
|
import type { NotFoundError } from './not-found'
|
|
31
31
|
import type { LazyRoute } from './fileRoute'
|
|
32
|
+
import type {
|
|
33
|
+
AnySchema,
|
|
34
|
+
AnyStandardSchemaValidator,
|
|
35
|
+
AnyValidator,
|
|
36
|
+
AnyValidatorAdapter,
|
|
37
|
+
AnyValidatorObj,
|
|
38
|
+
DefaultValidator,
|
|
39
|
+
ResolveValidatorInput,
|
|
40
|
+
ResolveValidatorOutput,
|
|
41
|
+
StandardSchemaValidator,
|
|
42
|
+
ValidatorAdapter,
|
|
43
|
+
ValidatorFn,
|
|
44
|
+
ValidatorObj,
|
|
45
|
+
} from './validators'
|
|
32
46
|
import type { UseRouteContextRoute } from './useRouteContext'
|
|
33
47
|
|
|
34
48
|
export type AnyPathParams = {}
|
|
@@ -37,8 +51,6 @@ export type SearchSchemaInput = {
|
|
|
37
51
|
__TSearchSchemaInput__: 'TSearchSchemaInput'
|
|
38
52
|
}
|
|
39
53
|
|
|
40
|
-
export type AnySearchSchema = {}
|
|
41
|
-
|
|
42
54
|
export type AnyContext = {}
|
|
43
55
|
|
|
44
56
|
export interface RouteContext {}
|
|
@@ -190,11 +202,7 @@ export type FileBaseRouteOptions<
|
|
|
190
202
|
TRouteContextFn = AnyContext,
|
|
191
203
|
TBeforeLoadFn = AnyContext,
|
|
192
204
|
> = ParamsOptions<TPath, TParams> & {
|
|
193
|
-
validateSearch?: Constrain<
|
|
194
|
-
TSearchValidator,
|
|
195
|
-
AnySearchValidator,
|
|
196
|
-
DefaultSearchValidator
|
|
197
|
-
>
|
|
205
|
+
validateSearch?: Constrain<TSearchValidator, AnyValidator, DefaultValidator>
|
|
198
206
|
|
|
199
207
|
shouldReload?:
|
|
200
208
|
| boolean
|
|
@@ -499,65 +507,10 @@ type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray
|
|
|
499
507
|
|
|
500
508
|
export type RouteLinkEntry = {}
|
|
501
509
|
|
|
502
|
-
export interface SearchValidatorObj<TInput, TOutput> {
|
|
503
|
-
parse: SearchValidatorFn<TInput, TOutput>
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
export type AnySearchValidatorObj = SearchValidatorObj<any, any>
|
|
507
|
-
|
|
508
|
-
export interface SearchValidatorAdapter<TInput, TOutput> {
|
|
509
|
-
types: {
|
|
510
|
-
input: TInput
|
|
511
|
-
output: TOutput
|
|
512
|
-
}
|
|
513
|
-
parse: (input: unknown) => TOutput
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
export type AnySearchValidatorAdapter = SearchValidatorAdapter<any, any>
|
|
517
|
-
|
|
518
|
-
export interface StandardSchemaValidatorProps<TInput, TOutput> {
|
|
519
|
-
readonly types?: StandardSchemaValidatorTypes<TInput, TOutput> | undefined
|
|
520
|
-
readonly validate: AnyStandardSchemaValidate
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
export interface StandardSchemaValidator<TInput, TOutput> {
|
|
524
|
-
readonly '~standard': StandardSchemaValidatorProps<TInput, TOutput>
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
export type AnyStandardSchemaValidator = StandardSchemaValidator<any, any>
|
|
528
|
-
|
|
529
|
-
export interface StandardSchemaValidatorTypes<TInput, TOutput> {
|
|
530
|
-
readonly input: TInput
|
|
531
|
-
readonly output: TOutput
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
export interface AnyStandardSchemaValidateSuccess {
|
|
535
|
-
readonly value: any
|
|
536
|
-
readonly issues?: undefined
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
export interface AnyStandardSchemaValidateFailure {
|
|
540
|
-
readonly issues: ReadonlyArray<AnyStandardSchemaValidateIssue>
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
export interface AnyStandardSchemaValidateIssue {
|
|
544
|
-
readonly message: string
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
export type AnyStandardSchemaValidate = (
|
|
548
|
-
value: unknown,
|
|
549
|
-
) =>
|
|
550
|
-
| (AnyStandardSchemaValidateSuccess | AnyStandardSchemaValidateFailure)
|
|
551
|
-
| Promise<AnyStandardSchemaValidateSuccess | AnyStandardSchemaValidateFailure>
|
|
552
|
-
|
|
553
|
-
export type AnySearchValidatorFn = SearchValidatorFn<any, any>
|
|
554
|
-
|
|
555
|
-
export type SearchValidatorFn<TInput, TOutput> = (input: TInput) => TOutput
|
|
556
|
-
|
|
557
510
|
export type SearchValidator<TInput, TOutput> =
|
|
558
|
-
|
|
|
559
|
-
|
|
|
560
|
-
|
|
|
511
|
+
| ValidatorObj<TInput, TOutput>
|
|
512
|
+
| ValidatorFn<TInput, TOutput>
|
|
513
|
+
| ValidatorAdapter<TInput, TOutput>
|
|
561
514
|
| StandardSchemaValidator<TInput, TOutput>
|
|
562
515
|
| undefined
|
|
563
516
|
|
|
@@ -565,7 +518,7 @@ export type AnySearchValidator = SearchValidator<any, any>
|
|
|
565
518
|
|
|
566
519
|
export type DefaultSearchValidator = SearchValidator<
|
|
567
520
|
Record<string, unknown>,
|
|
568
|
-
|
|
521
|
+
AnySchema
|
|
569
522
|
>
|
|
570
523
|
|
|
571
524
|
export type RouteLoaderFn<
|
|
@@ -680,14 +633,14 @@ export type ResolveSearchSchemaFnInput<TSearchValidator> =
|
|
|
680
633
|
? TSearchSchemaInput extends SearchSchemaInput
|
|
681
634
|
? Omit<TSearchSchemaInput, keyof SearchSchemaInput>
|
|
682
635
|
: ResolveSearchSchemaFn<TSearchValidator>
|
|
683
|
-
:
|
|
636
|
+
: AnySchema
|
|
684
637
|
|
|
685
638
|
export type ResolveSearchSchemaInput<TSearchValidator> =
|
|
686
639
|
TSearchValidator extends AnyStandardSchemaValidator
|
|
687
640
|
? NonNullable<TSearchValidator['~standard']['types']>['input']
|
|
688
|
-
: TSearchValidator extends
|
|
641
|
+
: TSearchValidator extends AnyValidatorAdapter
|
|
689
642
|
? TSearchValidator['types']['input']
|
|
690
|
-
: TSearchValidator extends
|
|
643
|
+
: TSearchValidator extends AnyValidatorObj
|
|
691
644
|
? ResolveSearchSchemaFnInput<TSearchValidator['parse']>
|
|
692
645
|
: ResolveSearchSchemaFnInput<TSearchValidator>
|
|
693
646
|
|
|
@@ -695,16 +648,16 @@ export type ResolveSearchSchemaFn<TSearchValidator> = TSearchValidator extends (
|
|
|
695
648
|
...args: any
|
|
696
649
|
) => infer TSearchSchema
|
|
697
650
|
? TSearchSchema
|
|
698
|
-
:
|
|
651
|
+
: AnySchema
|
|
699
652
|
|
|
700
653
|
export type ResolveSearchSchema<TSearchValidator> =
|
|
701
654
|
unknown extends TSearchValidator
|
|
702
655
|
? TSearchValidator
|
|
703
656
|
: TSearchValidator extends AnyStandardSchemaValidator
|
|
704
657
|
? NonNullable<TSearchValidator['~standard']['types']>['output']
|
|
705
|
-
: TSearchValidator extends
|
|
658
|
+
: TSearchValidator extends AnyValidatorAdapter
|
|
706
659
|
? TSearchValidator['types']['output']
|
|
707
|
-
: TSearchValidator extends
|
|
660
|
+
: TSearchValidator extends AnyValidatorObj
|
|
708
661
|
? ResolveSearchSchemaFn<TSearchValidator['parse']>
|
|
709
662
|
: ResolveSearchSchemaFn<TSearchValidator>
|
|
710
663
|
|
|
@@ -712,10 +665,10 @@ export type ResolveFullSearchSchema<
|
|
|
712
665
|
TParentRoute extends AnyRoute,
|
|
713
666
|
TSearchValidator,
|
|
714
667
|
> = unknown extends TParentRoute
|
|
715
|
-
?
|
|
668
|
+
? ResolveValidatorOutput<TSearchValidator>
|
|
716
669
|
: Assign<
|
|
717
670
|
InferFullSearchSchema<TParentRoute>,
|
|
718
|
-
|
|
671
|
+
ResolveValidatorOutput<TSearchValidator>
|
|
719
672
|
>
|
|
720
673
|
|
|
721
674
|
export type ResolveFullSearchSchemaInput<
|
|
@@ -723,7 +676,7 @@ export type ResolveFullSearchSchemaInput<
|
|
|
723
676
|
TSearchValidator,
|
|
724
677
|
> = Assign<
|
|
725
678
|
InferFullSearchSchemaInput<TParentRoute>,
|
|
726
|
-
|
|
679
|
+
ResolveValidatorInput<TSearchValidator>
|
|
727
680
|
>
|
|
728
681
|
|
|
729
682
|
export type LooseReturnType<T> = T extends (
|
|
@@ -820,8 +773,8 @@ export type RouteConstraints = {
|
|
|
820
773
|
TFullPath: string
|
|
821
774
|
TCustomId: string
|
|
822
775
|
TId: string
|
|
823
|
-
TSearchSchema:
|
|
824
|
-
TFullSearchSchema:
|
|
776
|
+
TSearchSchema: AnySchema
|
|
777
|
+
TFullSearchSchema: AnySchema
|
|
825
778
|
TParams: Record<string, any>
|
|
826
779
|
TAllParams: Record<string, any>
|
|
827
780
|
TParentContext: AnyContext
|
|
@@ -1031,8 +984,8 @@ export class Route<
|
|
|
1031
984
|
fullPath: TFullPath
|
|
1032
985
|
customId: TCustomId
|
|
1033
986
|
id: TId
|
|
1034
|
-
searchSchema:
|
|
1035
|
-
searchSchemaInput:
|
|
987
|
+
searchSchema: ResolveValidatorOutput<TSearchValidator>
|
|
988
|
+
searchSchemaInput: ResolveValidatorInput<TSearchValidator>
|
|
1036
989
|
searchValidator: TSearchValidator
|
|
1037
990
|
fullSearchSchema: ResolveFullSearchSchema<TParentRoute, TSearchValidator>
|
|
1038
991
|
fullSearchSchemaInput: ResolveFullSearchSchemaInput<
|
package/src/routeInfo.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { InferFileRouteTypes } from './fileRoute'
|
|
|
2
2
|
import type { AddTrailingSlash, RemoveTrailingSlashes } from './link'
|
|
3
3
|
import type { AnyRoute } from './route'
|
|
4
4
|
import type { AnyRouter, TrailingSlashOption } from './router'
|
|
5
|
-
import type {
|
|
5
|
+
import type { PartialMergeAll } from './utils'
|
|
6
6
|
|
|
7
7
|
export type ParseRoute<TRouteTree, TAcc = TRouteTree> = TRouteTree extends {
|
|
8
8
|
types: { children: infer TChildren }
|
|
@@ -207,25 +207,25 @@ export type RouteByToPath<TRouter extends AnyRouter, TTo> =
|
|
|
207
207
|
|
|
208
208
|
export type FullSearchSchema<TRouteTree extends AnyRoute> =
|
|
209
209
|
ParseRoute<TRouteTree> extends infer TRoutes extends AnyRoute
|
|
210
|
-
?
|
|
210
|
+
? PartialMergeAll<TRoutes['types']['fullSearchSchema']>
|
|
211
211
|
: never
|
|
212
212
|
|
|
213
213
|
export type FullSearchSchemaInput<TRouteTree extends AnyRoute> =
|
|
214
214
|
ParseRoute<TRouteTree> extends infer TRoutes extends AnyRoute
|
|
215
|
-
?
|
|
215
|
+
? PartialMergeAll<TRoutes['types']['fullSearchSchemaInput']>
|
|
216
216
|
: never
|
|
217
217
|
|
|
218
218
|
export type AllParams<TRouteTree extends AnyRoute> =
|
|
219
219
|
ParseRoute<TRouteTree> extends infer TRoutes extends AnyRoute
|
|
220
|
-
?
|
|
220
|
+
? PartialMergeAll<TRoutes['types']['allParams']>
|
|
221
221
|
: never
|
|
222
222
|
|
|
223
223
|
export type AllContext<TRouteTree extends AnyRoute> =
|
|
224
224
|
ParseRoute<TRouteTree> extends infer TRoutes extends AnyRoute
|
|
225
|
-
?
|
|
225
|
+
? PartialMergeAll<TRoutes['types']['allContext']>
|
|
226
226
|
: never
|
|
227
227
|
|
|
228
228
|
export type AllLoaderData<TRouteTree extends AnyRoute> =
|
|
229
229
|
ParseRoute<TRouteTree> extends infer TRoutes extends AnyRoute
|
|
230
|
-
?
|
|
230
|
+
? PartialMergeAll<TRoutes['types']['loaderData']>
|
|
231
231
|
: never
|