@tanstack/router-core 0.0.1-beta.155 → 0.0.1-beta.157

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.
@@ -1 +1 @@
1
- {"version":3,"file":"fileRoute.js","sources":["../../src/fileRoute.ts"],"sourcesContent":["import { ParsePathParams } from './link'\nimport {\n AnyRoute,\n ResolveFullPath,\n AnySearchSchema,\n ResolveFullSearchSchema,\n MergeParamsFromParent,\n RouteContext,\n AnyContext,\n RouteOptions,\n InferFullSearchSchema,\n UpdatableRouteOptions,\n Route,\n AnyPathParams,\n RootRouteId,\n TrimPathLeft,\n RouteConstraints,\n} from './route'\n\nexport interface FileRoutesByPath {\n // '/': {\n // parentRoute: typeof rootRoute\n // }\n}\n\ntype Replace<\n S extends string,\n From extends string,\n To extends string,\n> = S extends `${infer Start}${From}${infer Rest}`\n ? `${Start}${To}${Replace<Rest, From, To>}`\n : S\n\nexport type TrimLeft<\n T extends string,\n S extends string,\n> = T extends `${S}${infer U}` ? U : T\n\nexport type TrimRight<\n T extends string,\n S extends string,\n> = T extends `${infer U}${S}` ? U : T\n\nexport type Trim<T extends string, S extends string> = TrimLeft<\n TrimRight<T, S>,\n S\n>\n\nexport type RemoveUnderScores<T extends string> = Replace<\n Replace<TrimRight<TrimLeft<T, '/_'>, '_'>, '_/', '/'>,\n '/_',\n '/'\n>\n\nexport type ResolveFilePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> = TParentRoute['id'] extends RootRouteId\n ? TrimPathLeft<TFilePath>\n : Replace<\n TrimPathLeft<TFilePath>,\n TrimPathLeft<TParentRoute['__types']['customId']>,\n ''\n >\n\nexport type FileRoutePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}`\n ? string\n : ResolveFilePath<TParentRoute, TFilePath>\n\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = TFilePath,\n TPath extends RouteConstraints['TPath'] = FileRoutePath<\n TParentRoute,\n TFilePath\n >,\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n RemoveUnderScores<TPath>\n >,\n> {\n constructor(public path: TFilePath) {}\n\n createRoute = <\n TLoader = unknown,\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = ParsePathParams<TPath> extends never\n ? AnyPathParams\n : Record<ParsePathParams<TPath>, RouteConstraints['TPath']>,\n TAllParams extends RouteConstraints['TAllParams'] = MergeParamsFromParent<\n TParentRoute['__types']['allParams'],\n TParams\n >,\n TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['__types']['routeContext'],\n TAllParentContext extends RouteConstraints['TId'] = TParentRoute['__types']['context'],\n TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,\n TContext extends RouteConstraints['TContext'] = MergeParamsFromParent<\n TParentRoute['__types']['context'],\n TRouteContext\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n >(\n options: Omit<\n RouteOptions<\n TParentRoute,\n string,\n string,\n TLoader,\n InferFullSearchSchema<TParentRoute>,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TContext\n >,\n 'getParentRoute' | 'path' | 'id'\n > &\n UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TContext\n >,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TFilePath,\n TId,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TContext,\n TRouterContext,\n TChildren,\n TRouteTree\n > => {\n const route = new Route(options as any)\n ;(route as any).isRoot = false\n return route as any\n }\n}\n"],"names":["FileRoute","constructor","path","createRoute","options","route","Route","isRoot"],"mappings":";;;;;;;;;;;;;;;;AAwEO,MAAMA,SAAS,CAYpB;EACAC,WAAWA,CAAQC,IAAe,EAAE;IAAA,IAAjBA,CAAAA,IAAe,GAAfA,IAAe,CAAA;AAAG,GAAA;EAErCC,WAAW,GAyBTC,OAyBG,IAmBA;AACH,IAAA,MAAMC,OAAK,GAAG,IAAIC,WAAK,CAACF,OAAc,CAAC,CAAA;IACrCC,OAAK,CAASE,MAAM,GAAG,KAAK,CAAA;AAC9B,IAAA,OAAOF,OAAK,CAAA;GACb,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"fileRoute.js","sources":["../../src/fileRoute.ts"],"sourcesContent":["import { ParsePathParams } from './link'\nimport {\n AnyRoute,\n ResolveFullPath,\n AnySearchSchema,\n ResolveFullSearchSchema,\n MergeParamsFromParent,\n RouteContext,\n AnyContext,\n RouteOptions,\n InferFullSearchSchema,\n UpdatableRouteOptions,\n Route,\n AnyPathParams,\n RootRouteId,\n TrimPathLeft,\n RouteConstraints,\n} from './route'\n\nexport interface FileRoutesByPath {\n // '/': {\n // parentRoute: typeof rootRoute\n // }\n}\n\ntype Replace<\n S extends string,\n From extends string,\n To extends string,\n> = S extends `${infer Start}${From}${infer Rest}`\n ? `${Start}${To}${Replace<Rest, From, To>}`\n : S\n\nexport type TrimLeft<\n T extends string,\n S extends string,\n> = T extends `${S}${infer U}` ? U : T\n\nexport type TrimRight<\n T extends string,\n S extends string,\n> = T extends `${infer U}${S}` ? U : T\n\nexport type Trim<T extends string, S extends string> = TrimLeft<\n TrimRight<T, S>,\n S\n>\n\nexport type RemoveUnderScores<T extends string> = Replace<\n Replace<TrimRight<TrimLeft<T, '/_'>, '_'>, '_/', '/'>,\n '/_',\n '/'\n>\n\nexport type ResolveFilePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> = TParentRoute['id'] extends RootRouteId\n ? TrimPathLeft<TFilePath>\n : Replace<\n TrimPathLeft<TFilePath>,\n TrimPathLeft<TParentRoute['__types']['customId']>,\n ''\n >\n\nexport type FileRoutePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}`\n ? string\n : ResolveFilePath<TParentRoute, TFilePath>\n\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = TFilePath,\n TPath extends RouteConstraints['TPath'] = FileRoutePath<\n TParentRoute,\n TFilePath\n >,\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n RemoveUnderScores<TPath>\n >,\n> {\n constructor(public path: TFilePath) {}\n\n createRoute = <\n TLoader = unknown,\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = ParsePathParams<TPath> extends never\n ? AnyPathParams\n : Record<ParsePathParams<TPath>, RouteConstraints['TPath']>,\n TAllParams extends RouteConstraints['TAllParams'] = MergeParamsFromParent<\n TParentRoute['__types']['allParams'],\n TParams\n >,\n TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['__types']['routeContext'],\n TAllParentContext extends RouteConstraints['TId'] = TParentRoute['__types']['context'],\n TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,\n TContext extends RouteConstraints['TAllContext'] = MergeParamsFromParent<\n TParentRoute['__types']['context'],\n TRouteContext\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n >(\n options: Omit<\n RouteOptions<\n TParentRoute,\n string,\n string,\n TLoader,\n InferFullSearchSchema<TParentRoute>,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TContext\n >,\n 'getParentRoute' | 'path' | 'id'\n > &\n UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TContext\n >,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TFilePath,\n TId,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TContext,\n TRouterContext,\n TChildren,\n TRouteTree\n > => {\n const route = new Route(options as any)\n ;(route as any).isRoot = false\n return route as any\n }\n}\n"],"names":["FileRoute","constructor","path","createRoute","options","route","Route","isRoot"],"mappings":";;;;;;;;;;;;;;;;AAwEO,MAAMA,SAAS,CAYpB;EACAC,WAAWA,CAAQC,IAAe,EAAE;IAAA,IAAjBA,CAAAA,IAAe,GAAfA,IAAe,CAAA;AAAG,GAAA;EAErCC,WAAW,GAyBTC,OAyBG,IAmBA;AACH,IAAA,MAAMC,OAAK,GAAG,IAAIC,WAAK,CAACF,OAAc,CAAC,CAAA;IACrCC,OAAK,CAASE,MAAM,GAAG,KAAK,CAAA;AAC9B,IAAA,OAAOF,OAAK,CAAA;GACb,CAAA;AACH;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"route.js","sources":["../../src/route.ts"],"sourcesContent":["import { ParsePathParams } from './link'\nimport { AnyRouter, Router, RouteMatch, RegisteredRouter } from './router'\nimport { IsAny, NoInfer, PickRequired, UnionToIntersection } from './utils'\nimport invariant from 'tiny-invariant'\nimport { joinPaths, trimPath } from './path'\n\nexport const rootRouteId = '__root__' as const\nexport type RootRouteId = typeof rootRouteId\nexport type AnyPathParams = {}\nexport type AnySearchSchema = {}\nexport type AnyContext = {}\nexport interface RouteMeta {}\nexport interface RouteContext {}\nexport interface RegisterRouteComponent<TProps> {\n // RouteComponent: unknown // This is registered by the framework\n}\nexport interface RegisterRouteErrorComponent<TProps> {\n // RouteErrorComponent: unknown // This is registered by the framework\n}\n\nexport type RegisteredRouteComponent<TProps> =\n RegisterRouteComponent<TProps> extends {\n RouteComponent: infer T\n }\n ? T\n : (props: TProps) => unknown\n\nexport type RegisteredRouteErrorComponent<TProps> =\n RegisterRouteErrorComponent<TProps> extends {\n RouteErrorComponent: infer T\n }\n ? T\n : (props: TProps) => unknown\n\nexport type PreloadableObj = { preload?: () => Promise<void> }\n\nexport type RoutePathOptions<TCustomId, TPath> =\n | {\n path: TPath\n }\n | {\n id: TCustomId\n }\n\nexport type RoutePathOptionsIntersection<TCustomId, TPath> =\n UnionToIntersection<RoutePathOptions<TCustomId, TPath>>\n\nexport type MetaOptions = keyof PickRequired<RouteMeta> extends never\n ? {\n meta?: RouteMeta\n }\n : {\n meta: RouteMeta\n }\n\nexport type AnyRouteProps = RouteProps<any, any, any, any, any>\nexport type ComponentPropsFromRoute<TRoute> = TRoute extends Route<\n infer TParentRoute,\n infer TPath,\n infer TFullPath,\n infer TCustomId,\n infer TId,\n infer TLoader,\n infer TSearchSchema,\n infer TFullSearchSchema,\n infer TParams,\n infer TAllParams,\n infer TParentContext,\n infer TAllParentContext,\n infer TRouteContext,\n infer TContext,\n infer TRouterContext,\n infer TChildren,\n infer TRouteTree\n>\n ? RouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TContext>\n : never\n\nexport type ComponentFromRoute<TRoute> = RegisteredRouteComponent<\n ComponentPropsFromRoute<TRoute>\n>\n\nexport type RouteLoaderFromRoute<TRoute extends AnyRoute> = LoaderFn<\n TRoute['__types']['loader'],\n TRoute['__types']['searchSchema'],\n TRoute['__types']['fullSearchSchema'],\n TRoute['__types']['allParams'],\n TRoute['__types']['routeContext'],\n TRoute['__types']['context']\n>\n\nexport type RouteProps<\n TLoader = unknown,\n TFullSearchSchema extends AnySearchSchema = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends AnyContext = AnyContext,\n TContext extends AnyContext = AnyContext,\n> = {\n useMatch: () => RouteMatch<any, any>\n useLoader: () => UseLoaderResult<TLoader>\n useSearch: <\n TStrict extends boolean = true,\n TSearch = TFullSearchSchema,\n TSelected = TSearch,\n >(opts?: {\n strict?: TStrict\n select?: (search: TSearch) => TSelected\n }) => TStrict extends true ? TSelected : TSelected | undefined\n useParams: <\n TDefaultSelected = TAllParams,\n TSelected = TDefaultSelected,\n >(opts?: {\n select?: (params: TDefaultSelected) => TSelected\n }) => TSelected\n useContext: <\n TDefaultSelected = TContext,\n TSelected = TDefaultSelected,\n >(opts?: {\n select?: (context: TDefaultSelected) => TSelected\n }) => TSelected\n useRouteContext: <\n TDefaultSelected = TRouteContext,\n TSelected = TDefaultSelected,\n >(opts?: {\n select?: (context: TDefaultSelected) => TSelected\n }) => TSelected\n}\n\nexport type RouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TLoader = unknown,\n TParentSearchSchema extends AnySearchSchema = {},\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = TSearchSchema,\n TParams extends AnyPathParams = AnyPathParams,\n TAllParams extends AnyPathParams = TParams,\n TParentContext extends AnyContext = AnyContext,\n TAllParentContext extends AnyContext = AnyContext,\n TRouteContext extends RouteContext = RouteContext,\n TContext extends AnyContext = AnyContext,\n> = BaseRouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoader,\n TParentSearchSchema,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TContext\n> &\n UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TContext\n >\n\nexport type ParamsFallback<\n TPath extends string,\n TParams,\n> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams\n\ntype Prefix<T extends string, U extends string> = U extends `${T}${infer _}`\n ? U\n : never\n\ntype PrefixOrExact<T extends string, U extends string> = U extends T\n ? U\n : Prefix<T, U>\n\nexport type BaseRouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TLoader = unknown,\n TParentSearchSchema extends AnySearchSchema = {},\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = TSearchSchema,\n TParams = unknown,\n TAllParams = ParamsFallback<TPath, TParams>,\n TParentContext extends AnyContext = AnyContext,\n TAllParentContext extends AnyContext = AnyContext,\n TRouteContext extends RouteContext = RouteContext,\n TContext extends AnyContext = AnyContext,\n> = RoutePathOptions<TCustomId, TPath> & {\n layoutLimit?: string\n getParentRoute: () => TParentRoute\n validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>\n loader?: LoaderFn<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n NoInfer<TRouteContext>,\n TContext\n >\n} & (\n | {\n // Both or none\n parseParams?: (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n ) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : 'parseParams must return an object'\n // | {\n // parse: (\n // rawParams: IsAny<\n // TPath,\n // any,\n // Record<ParsePathParams<TPath>, string>\n // >,\n // ) => TParams extends Record<ParsePathParams<TPath>, any>\n // ? TParams\n // : 'parseParams must return an object'\n // }\n stringifyParams?: (\n params: NoInfer<ParamsFallback<TPath, TParams>>,\n ) => Record<ParsePathParams<TPath>, string>\n }\n | {\n stringifyParams?: never\n parseParams?: never\n }\n ) &\n (keyof PickRequired<RouteContext> extends never\n ? {\n getContext?: GetContextFn<\n TParentRoute,\n TAllParams,\n TFullSearchSchema,\n TParentContext,\n TAllParentContext,\n TRouteContext\n >\n }\n : {\n getContext: GetContextFn<\n TParentRoute,\n TAllParams,\n TFullSearchSchema,\n TParentContext,\n TAllParentContext,\n TRouteContext\n >\n })\n\ntype GetContextFn<\n TParentRoute,\n TAllParams,\n TFullSearchSchema,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n> = (\n opts: {\n params: TAllParams\n search: TFullSearchSchema\n } & (TParentRoute extends undefined\n ? {\n context?: TAllParentContext\n parentContext?: TParentContext\n }\n : {\n context: TAllParentContext\n parentContext: TParentContext\n }),\n) => TRouteContext\n\nexport type UpdatableRouteOptions<\n TLoader,\n TSearchSchema extends AnySearchSchema,\n TFullSearchSchema extends AnySearchSchema,\n TAllParams extends AnyPathParams,\n TRouteContext extends AnyContext,\n TContext extends AnyContext,\n> = MetaOptions & {\n key?: null | false | GetKeyFn<TFullSearchSchema, TAllParams>\n // If true, this route will be matched as case-sensitive\n caseSensitive?: boolean\n // If true, this route will be forcefully wrapped in a suspense boundary\n wrapInSuspense?: boolean\n // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`\n component?: RegisteredRouteComponent<\n RouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TContext>\n >\n // The content to be rendered when the route encounters an error\n errorComponent?: RegisteredRouteErrorComponent<\n { error: unknown } & Partial<\n RouteProps<\n TLoader,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TContext\n >\n >\n > //\n // If supported by your framework, the content to be rendered as the fallback content until the route is ready to render\n pendingComponent?: RegisteredRouteComponent<\n RouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TContext>\n >\n // Filter functions that can manipulate search params *before* they are passed to links and navigate\n // calls that match this route.\n preSearchFilters?: SearchFilter<TFullSearchSchema>[]\n // Filter functions that can manipulate search params *after* they are passed to links and navigate\n // calls that match this route.\n postSearchFilters?: SearchFilter<TFullSearchSchema>[]\n // If set, preload matches of this route will be considered fresh for this many milliseconds.\n preloadMaxAge?: number\n // If set, a match of this route will be considered fresh for this many milliseconds.\n maxAge?: number\n // If set, a match of this route that becomes inactive (or unused) will be garbage collected after this many milliseconds\n gcMaxAge?: number\n // This async function is called before a route is loaded.\n // If an error is thrown here, the route's loader will not be called.\n // If thrown during a navigation, the navigation will be cancelled and the error will be passed to the `onLoadError` function.\n // If thrown during a preload event, the error will be logged to the console.\n beforeLoad?: (\n opts: LoaderContext<\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n NoInfer<TRouteContext>,\n TContext\n >,\n ) => Promise<void> | void\n // This function will be called if the route's loader throws an error **during an attempted navigation**.\n // If you want to redirect due to an error, call `router.navigate()` from within this function.\n onBeforeLoadError?: (err: any) => void\n // This function will be called if the route's validateSearch option throws an error **during an attempted validation**.\n // If you want to redirect due to an error, call `router.navigate()` from within this function.\n // If you want to display the errorComponent, rethrow the error\n onValidateSearchError?: (err: any) => void\n onParseParamsError?: (err: any) => void\n onLoadError?: (err: any) => void\n onError?: (err: any) => void\n // This function is called\n // when moving from an inactive state to an active one. Likewise, when moving from\n // an active to an inactive state, the return function (if provided) is called.\n onLoaded?: (matchContext: {\n params: TAllParams\n search: TFullSearchSchema\n }) =>\n | void\n | undefined\n | ((match: { params: TAllParams; search: TFullSearchSchema }) => void)\n // This function is called when the route remains active from one transition to the next.\n onTransition?: (match: {\n params: TAllParams\n search: TFullSearchSchema\n }) => void\n}\n\nexport type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<\n TPath,\n TParams\n>\n// | ParseParamsObj<TPath, TParams>\n\nexport type ParseParamsFn<TPath extends string, TParams> = (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : 'parseParams must return an object'\n\nexport type ParseParamsObj<TPath extends string, TParams> = {\n parse?: ParseParamsFn<TPath, TParams>\n}\n\n// The parse type here allows a zod schema to be passed directly to the validator\nexport type SearchSchemaValidator<TReturn, TParentSchema> =\n | SearchSchemaValidatorObj<TReturn, TParentSchema>\n | SearchSchemaValidatorFn<TReturn, TParentSchema>\n\nexport type SearchSchemaValidatorObj<TReturn, TParentSchema> = {\n parse?: SearchSchemaValidatorFn<TReturn, TParentSchema>\n}\n\nexport type SearchSchemaValidatorFn<TReturn, TParentSchema> = (\n searchObj: Record<string, unknown>,\n) => {} extends TParentSchema\n ? TReturn\n : keyof TReturn extends keyof TParentSchema\n ? {\n error: 'Top level search params cannot be redefined by child routes!'\n keys: keyof TReturn & keyof TParentSchema\n }\n : TReturn\n\nexport type DefinedPathParamWarning =\n 'Path params cannot be redefined by child routes!'\n\nexport type ParentParams<TParentParams> = AnyPathParams extends TParentParams\n ? {}\n : {\n [Key in keyof TParentParams]?: DefinedPathParamWarning\n }\n\nexport type LoaderFn<\n TLoader = unknown,\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams = {},\n TContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> = (\n match: LoaderContext<\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TContext,\n TAllContext\n > & {\n parentMatchPromise?: Promise<void>\n },\n) => Promise<TLoader> | TLoader\n\nexport type GetKeyFn<\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams = {},\n> = (loaderContext: { params: TAllParams; search: TFullSearchSchema }) => any\n\nexport interface LoaderContext<\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams = {},\n TContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> {\n params: TAllParams\n routeSearch: TSearchSchema\n search: TFullSearchSchema\n abortController: AbortController\n preload: boolean\n routeContext: TContext\n context: TAllContext\n}\n\nexport type UnloaderFn<TPath extends string> = (\n routeMatch: RouteMatch<any, Route>,\n) => void\n\nexport type SearchFilter<T, U = T> = (prev: T) => U\n\nexport type ResolveId<\n TParentRoute,\n TCustomId extends string,\n TPath extends string,\n> = TParentRoute extends { id: infer TParentId extends string }\n ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId>\n : RootRouteId\n\nexport type InferFullSearchSchema<TRoute> = TRoute extends {\n isRoot: true\n __types: {\n searchSchema: infer TSearchSchema\n }\n}\n ? TSearchSchema\n : TRoute extends {\n __types: {\n fullSearchSchema: infer TFullSearchSchema\n }\n }\n ? TFullSearchSchema\n : {}\n\nexport type ResolveFullSearchSchema<TParentRoute, TSearchSchema> =\n InferFullSearchSchema<TParentRoute> & TSearchSchema\n\nexport interface AnyRoute\n extends Route<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > {}\n\nexport type MergeParamsFromParent<T, U> = IsAny<T, U, T & U>\n\nexport type UseLoaderResult<T> = T extends Record<PropertyKey, infer U>\n ? {\n [K in keyof T]: UseLoaderResultPromise<T[K]>\n }\n : UseLoaderResultPromise<T>\n\nexport type UseLoaderResultPromise<T> = T extends Promise<infer U>\n ? StreamedPromise<U>\n : T\n\nexport type StreamedPromise<T> = {\n promise: Promise<T>\n status: 'resolved' | 'pending'\n data: T\n resolve: (value: T) => void\n}\n\nexport type RouteConstraints = {\n TParentRoute: AnyRoute\n TPath: string\n TFullPath: string\n TCustomId: string\n TId: string\n TSearchSchema: AnySearchSchema\n TFullSearchSchema: AnySearchSchema\n TParams: Record<string, any>\n TAllParams: Record<string, any>\n TParentContext: AnyContext\n TAllParentContext: AnyContext\n TRouteContext: RouteContext\n TContext: AnyContext\n TRouterContext: AnyContext\n TChildren: unknown\n TRouteTree: AnyRoute\n}\n\nexport class Route<\n TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n TPath extends RouteConstraints['TPath'] = '/',\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n TCustomId extends RouteConstraints['TCustomId'] = string,\n TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n TLoader = unknown,\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = Record<\n ParsePathParams<TPath>,\n string\n >,\n TAllParams extends RouteConstraints['TAllParams'] = MergeParamsFromParent<\n TParentRoute['__types']['allParams'],\n TParams\n >,\n TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['__types']['routeContext'],\n TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['__types']['context'],\n TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,\n TContext extends RouteConstraints['TContext'] = MergeParamsFromParent<\n TParentRoute['__types']['context'],\n TRouteContext\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n> {\n __types!: {\n parentRoute: TParentRoute\n path: TPath\n to: TrimPathRight<TFullPath>\n fullPath: TFullPath\n customId: TCustomId\n id: TId\n loader: TLoader\n searchSchema: TSearchSchema\n fullSearchSchema: TFullSearchSchema\n params: TParams\n allParams: TAllParams\n parentContext: TParentContext\n allParentContext: TAllParentContext\n routeContext: TRouteContext\n context: TContext\n children: TChildren\n routeTree: TRouteTree\n routerContext: TRouterContext\n }\n isRoot: TParentRoute extends Route<any> ? true : false\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoader,\n InferFullSearchSchema<TParentRoute>,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TContext\n > &\n UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TContext\n >\n\n // Set up in this.init()\n parentRoute!: TParentRoute\n id!: TId\n // customId!: TCustomId\n path!: TPath\n fullPath!: TFullPath\n to!: TrimPathRight<TFullPath>\n\n // Optional\n children?: TChildren\n originalIndex?: number\n router?: AnyRouter\n rank!: number\n\n constructor(\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoader,\n InferFullSearchSchema<TParentRoute>,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TContext\n > &\n UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TContext\n >,\n ) {\n this.options = (options as any) || {}\n this.isRoot = !options?.getParentRoute as any\n Route.__onInit(this as any)\n }\n\n init = (opts: { originalIndex: number; router: AnyRouter }) => {\n this.originalIndex = opts.originalIndex\n this.router = opts.router\n\n const options = this.options as RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n InferFullSearchSchema<TParentRoute>,\n TSearchSchema,\n TParams\n > &\n RoutePathOptionsIntersection<TCustomId, TPath>\n\n const isRoot = !options?.path && !options?.id\n\n this.parentRoute = this.options?.getParentRoute?.()\n\n if (isRoot) {\n this.path = rootRouteId as TPath\n } else {\n invariant(\n this.parentRoute,\n `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,\n )\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPath(path)\n }\n\n const customId = options?.id || path\n\n // Strip the parentId prefix from the first level of children\n let id = isRoot\n ? rootRouteId\n : joinPaths([\n (this.parentRoute.id as any) === rootRouteId\n ? ''\n : this.parentRoute.id,\n customId,\n ])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : joinPaths([this.parentRoute.fullPath, path])\n\n this.path = path as TPath\n this.id = id as TId\n // this.customId = customId as TCustomId\n this.fullPath = fullPath as TFullPath\n this.to = fullPath as TrimPathRight<TFullPath>\n }\n\n addChildren = <TNewChildren extends AnyRoute[]>(\n children: TNewChildren,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TContext,\n TRouterContext,\n TNewChildren,\n TRouteTree\n > => {\n this.children = children as any\n return this as any\n }\n\n update = (\n options: UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TContext\n >,\n ) => {\n Object.assign(this.options, options)\n return this\n }\n\n static __onInit = (route: typeof this) => {\n // This is a dummy static method that should get\n // replaced by a framework specific implementation if necessary\n }\n}\n\nexport type AnyRootRoute = RootRoute<any, any, any, any>\n\nexport class RouterContext<TRouterContext extends {}> {\n constructor() {}\n\n createRootRoute = <\n TLoader = unknown,\n TSearchSchema extends AnySearchSchema = {},\n TContext extends RouteContext = RouteContext,\n >(\n options?: Omit<\n RouteOptions<AnyRoute, RootRouteId, '', {}, TSearchSchema, {}>,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n >,\n ) => {\n return new RootRoute<TLoader, TSearchSchema, TContext, TRouterContext>(\n options as any,\n )\n }\n}\n\nexport class RootRoute<\n TLoader = unknown,\n TSearchSchema extends AnySearchSchema = {},\n TContext extends RouteContext = RouteContext,\n TRouterContext extends {} = {},\n> extends Route<\n any,\n '/',\n '/',\n string,\n RootRouteId,\n TLoader,\n TSearchSchema,\n TSearchSchema,\n {},\n {},\n TRouterContext,\n TRouterContext,\n MergeParamsFromParent<TRouterContext, TContext>,\n MergeParamsFromParent<TRouterContext, TContext>,\n TRouterContext,\n any,\n any\n> {\n constructor(\n options?: Omit<\n RouteOptions<AnyRoute, RootRouteId, '', TLoader, TSearchSchema, {}>,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n >,\n ) {\n super(options as any)\n }\n}\n\nexport type ResolveFullPath<\n TParentRoute extends AnyRoute,\n TPath extends string,\n TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>,\n> = TPrefixed extends RootRouteId ? '/' : TPrefixed\n\ntype RoutePrefix<\n TPrefix extends string,\n TPath extends string,\n> = string extends TPath\n ? RootRouteId\n : TPath extends string\n ? TPrefix extends RootRouteId\n ? TPath extends '/'\n ? '/'\n : `/${TrimPath<TPath>}`\n : `${TPrefix}/${TPath}` extends '/'\n ? '/'\n : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`\n : never\n\nexport type TrimPath<T extends string> = '' extends T\n ? ''\n : TrimPathRight<TrimPathLeft<T>>\n\nexport type TrimPathLeft<T extends string> =\n T extends `${RootRouteId}/${infer U}`\n ? TrimPathLeft<U>\n : T extends `/${infer U}`\n ? TrimPathLeft<U>\n : T\nexport type TrimPathRight<T extends string> = T extends '/'\n ? '/'\n : T extends `${infer U}/`\n ? TrimPathRight<U>\n : T\n"],"names":["rootRouteId","Route","constructor","options","isRoot","getParentRoute","__onInit","init","opts","originalIndex","router","path","id","parentRoute","invariant","trimPath","customId","joinPaths","fullPath","to","addChildren","children","update","Object","assign","route","RouterContext","createRootRoute","RootRoute"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAMO,MAAMA,WAAW,GAAG,WAAmB;;AAwW9C;;AAYA;;AAgKO,MAAMC,KAAK,CAqChB;AA8CA;;AAGA;;AAKA;;EAMAC,WAAWA,CACTC,OAsBG,EACH;AACA,IAAA,IAAI,CAACA,OAAO,GAAIA,OAAO,IAAY,EAAE,CAAA;AACrC,IAAA,IAAI,CAACC,MAAM,GAAG,CAACD,OAAO,EAAEE,cAAqB,CAAA;AAC7CJ,IAAAA,KAAK,CAACK,QAAQ,CAAC,IAAW,CAAC,CAAA;AAC7B,GAAA;EAEAC,IAAI,GAAIC,IAAkD,IAAK;AAC7D,IAAA,IAAI,CAACC,aAAa,GAAGD,IAAI,CAACC,aAAa,CAAA;AACvC,IAAA,IAAI,CAACC,MAAM,GAAGF,IAAI,CAACE,MAAM,CAAA;AAEzB,IAAA,MAAMP,OAAO,GAAG,IAAI,CAACA,OAQ2B,CAAA;IAEhD,MAAMC,MAAM,GAAG,CAACD,OAAO,EAAEQ,IAAI,IAAI,CAACR,OAAO,EAAES,EAAE,CAAA;IAE7C,IAAI,CAACC,WAAW,GAAG,IAAI,CAACV,OAAO,EAAEE,cAAc,IAAI,CAAA;AAEnD,IAAA,IAAID,MAAM,EAAE;MACV,IAAI,CAACO,IAAI,GAAGX,WAAoB,CAAA;AAClC,KAAC,MAAM;AACLc,MAAAA,6BAAS,CACP,IAAI,CAACD,WAAW,EACf,6GACH,CAAC,CAAA;AACH,KAAA;IAEA,IAAIF,MAAwB,GAAGP,MAAM,GAAGJ,WAAW,GAAGG,OAAO,CAACQ,IAAI,CAAA;;AAElE;AACA,IAAA,IAAIA,MAAI,IAAIA,MAAI,KAAK,GAAG,EAAE;AACxBA,MAAAA,MAAI,GAAGI,aAAQ,CAACJ,MAAI,CAAC,CAAA;AACvB,KAAA;AAEA,IAAA,MAAMK,QAAQ,GAAGb,OAAO,EAAES,EAAE,IAAID,MAAI,CAAA;;AAEpC;IACA,IAAIC,EAAE,GAAGR,MAAM,GACXJ,WAAW,GACXiB,cAAS,CAAC,CACP,IAAI,CAACJ,WAAW,CAACD,EAAE,KAAaZ,WAAW,GACxC,EAAE,GACF,IAAI,CAACa,WAAW,CAACD,EAAE,EACvBI,QAAQ,CACT,CAAC,CAAA;IAEN,IAAIL,MAAI,KAAKX,WAAW,EAAE;AACxBW,MAAAA,MAAI,GAAG,GAAG,CAAA;AACZ,KAAA;IAEA,IAAIC,EAAE,KAAKZ,WAAW,EAAE;MACtBY,EAAE,GAAGK,cAAS,CAAC,CAAC,GAAG,EAAEL,EAAE,CAAC,CAAC,CAAA;AAC3B,KAAA;AAEA,IAAA,MAAMM,QAAQ,GACZN,EAAE,KAAKZ,WAAW,GAAG,GAAG,GAAGiB,cAAS,CAAC,CAAC,IAAI,CAACJ,WAAW,CAACK,QAAQ,EAAEP,MAAI,CAAC,CAAC,CAAA;IAEzE,IAAI,CAACA,IAAI,GAAGA,MAAa,CAAA;IACzB,IAAI,CAACC,EAAE,GAAGA,EAAS,CAAA;AACnB;IACA,IAAI,CAACM,QAAQ,GAAGA,QAAqB,CAAA;IACrC,IAAI,CAACC,EAAE,GAAGD,QAAoC,CAAA;GAC/C,CAAA;EAEDE,WAAW,GACTC,QAAsB,IAmBnB;IACH,IAAI,CAACA,QAAQ,GAAGA,QAAe,CAAA;AAC/B,IAAA,OAAO,IAAI,CAAA;GACZ,CAAA;EAEDC,MAAM,GACJnB,OAOC,IACE;IACHoB,MAAM,CAACC,MAAM,CAAC,IAAI,CAACrB,OAAO,EAAEA,OAAO,CAAC,CAAA;AACpC,IAAA,OAAO,IAAI,CAAA;GACZ,CAAA;EAED,OAAOG,QAAQ,GAAImB,KAAkB,IAAK;AACxC;AACA;GACD,CAAA;AACH,CAAA;AAIO,MAAMC,aAAa,CAA4B;EACpDxB,WAAWA,GAAG,EAAC;EAEfyB,eAAe,GAKbxB,OAQC,IACE;AACH,IAAA,OAAO,IAAIyB,SAAS,CAClBzB,OACF,CAAC,CAAA;GACF,CAAA;AACH,CAAA;AAEO,MAAMyB,SAAS,SAKZ3B,KAAK,CAkBb;EACAC,WAAWA,CACTC,OAQC,EACD;IACA,KAAK,CAACA,OAAc,CAAC,CAAA;AACvB,GAAA;AACF;;;;;;;"}
1
+ {"version":3,"file":"route.js","sources":["../../src/route.ts"],"sourcesContent":["import { ParsePathParams } from './link'\nimport { AnyRouter, Router, RouteMatch, RegisteredRouter } from './router'\nimport { IsAny, NoInfer, PickRequired, UnionToIntersection } from './utils'\nimport invariant from 'tiny-invariant'\nimport { joinPaths, trimPath } from './path'\n\nexport const rootRouteId = '__root__' as const\nexport type RootRouteId = typeof rootRouteId\nexport type AnyPathParams = {}\nexport type AnySearchSchema = {}\nexport type AnyContext = {}\nexport interface RouteMeta {}\nexport interface RouteContext {}\nexport interface RegisterRouteComponent<TProps> {\n // RouteComponent: unknown // This is registered by the framework\n}\nexport interface RegisterRouteErrorComponent<TProps> {\n // RouteErrorComponent: unknown // This is registered by the framework\n}\n\nexport type RegisteredRouteComponent<TProps> =\n RegisterRouteComponent<TProps> extends {\n RouteComponent: infer T\n }\n ? T\n : (props: TProps) => unknown\n\nexport type RegisteredRouteErrorComponent<TProps> =\n RegisterRouteErrorComponent<TProps> extends {\n RouteErrorComponent: infer T\n }\n ? T\n : (props: TProps) => unknown\n\nexport type PreloadableObj = { preload?: () => Promise<void> }\n\nexport type RoutePathOptions<TCustomId, TPath> =\n | {\n path: TPath\n }\n | {\n id: TCustomId\n }\n\nexport type RoutePathOptionsIntersection<TCustomId, TPath> =\n UnionToIntersection<RoutePathOptions<TCustomId, TPath>>\n\nexport type MetaOptions = keyof PickRequired<RouteMeta> extends never\n ? {\n meta?: RouteMeta\n }\n : {\n meta: RouteMeta\n }\n\nexport type AnyRouteProps = RouteProps<any, any, any, any, any>\nexport type ComponentPropsFromRoute<TRoute> = TRoute extends Route<\n infer TParentRoute,\n infer TPath,\n infer TFullPath,\n infer TCustomId,\n infer TId,\n infer TLoader,\n infer TSearchSchema,\n infer TFullSearchSchema,\n infer TParams,\n infer TAllParams,\n infer TParentContext,\n infer TAllParentContext,\n infer TRouteContext,\n infer TContext,\n infer TRouterContext,\n infer TChildren,\n infer TRouteTree\n>\n ? RouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TContext>\n : never\n\nexport type ComponentFromRoute<TRoute> = RegisteredRouteComponent<\n ComponentPropsFromRoute<TRoute>\n>\n\nexport type RouteLoaderFromRoute<TRoute extends AnyRoute> = LoaderFn<\n TRoute['__types']['loader'],\n TRoute['__types']['searchSchema'],\n TRoute['__types']['fullSearchSchema'],\n TRoute['__types']['allParams'],\n TRoute['__types']['routeContext'],\n TRoute['__types']['context']\n>\n\nexport type RouteProps<\n TLoader = unknown,\n TFullSearchSchema extends AnySearchSchema = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends AnyContext = AnyContext,\n TContext extends AnyContext = AnyContext,\n> = {\n useMatch: () => RouteMatch<any, any>\n useLoader: () => UseLoaderResult<TLoader>\n useSearch: <\n TStrict extends boolean = true,\n TSearch = TFullSearchSchema,\n TSelected = TSearch,\n >(opts?: {\n strict?: TStrict\n select?: (search: TSearch) => TSelected\n }) => TStrict extends true ? TSelected : TSelected | undefined\n useParams: <\n TDefaultSelected = TAllParams,\n TSelected = TDefaultSelected,\n >(opts?: {\n select?: (params: TDefaultSelected) => TSelected\n }) => TSelected\n useContext: <\n TDefaultSelected = TContext,\n TSelected = TDefaultSelected,\n >(opts?: {\n select?: (context: TDefaultSelected) => TSelected\n }) => TSelected\n useRouteContext: <\n TDefaultSelected = TRouteContext,\n TSelected = TDefaultSelected,\n >(opts?: {\n select?: (context: TDefaultSelected) => TSelected\n }) => TSelected\n}\n\nexport type RouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TLoader = unknown,\n TParentSearchSchema extends AnySearchSchema = {},\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = TSearchSchema,\n TParams extends AnyPathParams = AnyPathParams,\n TAllParams extends AnyPathParams = TParams,\n TParentContext extends AnyContext = AnyContext,\n TAllParentContext extends AnyContext = AnyContext,\n TRouteContext extends RouteContext = RouteContext,\n TAllContext extends AnyContext = AnyContext,\n> = BaseRouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoader,\n TParentSearchSchema,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TAllContext\n> &\n UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n >\n\nexport type ParamsFallback<\n TPath extends string,\n TParams,\n> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams\n\ntype Prefix<T extends string, U extends string> = U extends `${T}${infer _}`\n ? U\n : never\n\ntype PrefixOrExact<T extends string, U extends string> = U extends T\n ? U\n : Prefix<T, U>\n\nexport type BaseRouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TLoader = unknown,\n TParentSearchSchema extends AnySearchSchema = {},\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = TSearchSchema,\n TParams = unknown,\n TAllParams = ParamsFallback<TPath, TParams>,\n TParentContext extends AnyContext = AnyContext,\n TAllParentContext extends AnyContext = AnyContext,\n TRouteContext extends RouteContext = RouteContext,\n TAllContext extends AnyContext = AnyContext,\n> = RoutePathOptions<TCustomId, TPath> & {\n layoutLimit?: string\n getParentRoute: () => TParentRoute\n validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>\n loader?: LoaderFn<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n NoInfer<TRouteContext>,\n TAllContext\n >\n} & (\n | {\n // Both or none\n parseParams?: (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n ) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : 'parseParams must return an object'\n // | {\n // parse: (\n // rawParams: IsAny<\n // TPath,\n // any,\n // Record<ParsePathParams<TPath>, string>\n // >,\n // ) => TParams extends Record<ParsePathParams<TPath>, any>\n // ? TParams\n // : 'parseParams must return an object'\n // }\n stringifyParams?: (\n params: NoInfer<ParamsFallback<TPath, TParams>>,\n ) => Record<ParsePathParams<TPath>, string>\n }\n | {\n stringifyParams?: never\n parseParams?: never\n }\n ) &\n (keyof PickRequired<RouteContext> extends never\n ? {\n getContext?: GetContextFn<\n TParentRoute,\n TAllParams,\n TFullSearchSchema,\n TParentContext,\n TAllParentContext,\n TRouteContext\n >\n }\n : {\n getContext: GetContextFn<\n TParentRoute,\n TAllParams,\n TFullSearchSchema,\n TParentContext,\n TAllParentContext,\n TRouteContext\n >\n })\n\ntype GetContextFn<\n TParentRoute,\n TAllParams,\n TFullSearchSchema,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n> = (\n opts: {\n params: TAllParams\n search: TFullSearchSchema\n } & (TParentRoute extends undefined\n ? {\n context?: TAllParentContext\n parentContext?: TParentContext\n }\n : {\n context: TAllParentContext\n parentContext: TParentContext\n }),\n) => TRouteContext\n\nexport type UpdatableRouteOptions<\n TLoader,\n TSearchSchema extends AnySearchSchema,\n TFullSearchSchema extends AnySearchSchema,\n TAllParams extends AnyPathParams,\n TRouteContext extends AnyContext,\n TContext extends AnyContext,\n> = MetaOptions & {\n key?: null | false | GetKeyFn<TFullSearchSchema, TAllParams>\n // If true, this route will be matched as case-sensitive\n caseSensitive?: boolean\n // If true, this route will be forcefully wrapped in a suspense boundary\n wrapInSuspense?: boolean\n // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`\n component?: RegisteredRouteComponent<\n RouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TContext>\n >\n // The content to be rendered when the route encounters an error\n errorComponent?: RegisteredRouteErrorComponent<\n { error: unknown } & Partial<\n RouteProps<\n TLoader,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TContext\n >\n >\n > //\n // If supported by your framework, the content to be rendered as the fallback content until the route is ready to render\n pendingComponent?: RegisteredRouteComponent<\n RouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TContext>\n >\n // Filter functions that can manipulate search params *before* they are passed to links and navigate\n // calls that match this route.\n preSearchFilters?: SearchFilter<TFullSearchSchema>[]\n // Filter functions that can manipulate search params *after* they are passed to links and navigate\n // calls that match this route.\n postSearchFilters?: SearchFilter<TFullSearchSchema>[]\n // If set, preload matches of this route will be considered fresh for this many milliseconds.\n preloadMaxAge?: number\n // If set, a match of this route will be considered fresh for this many milliseconds.\n maxAge?: number\n // If set, a match of this route that becomes inactive (or unused) will be garbage collected after this many milliseconds\n gcMaxAge?: number\n // This async function is called before a route is loaded.\n // If an error is thrown here, the route's loader will not be called.\n // If thrown during a navigation, the navigation will be cancelled and the error will be passed to the `onLoadError` function.\n // If thrown during a preload event, the error will be logged to the console.\n beforeLoad?: (\n opts: LoaderContext<\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n NoInfer<TRouteContext>,\n TContext\n >,\n ) => Promise<void> | void\n // This function will be called if the route's loader throws an error **during an attempted navigation**.\n // If you want to redirect due to an error, call `router.navigate()` from within this function.\n onBeforeLoadError?: (err: any) => void\n // This function will be called if the route's validateSearch option throws an error **during an attempted validation**.\n // If you want to redirect due to an error, call `router.navigate()` from within this function.\n // If you want to display the errorComponent, rethrow the error\n onValidateSearchError?: (err: any) => void\n onParseParamsError?: (err: any) => void\n onLoadError?: (err: any) => void\n onError?: (err: any) => void\n // This function is called\n // when moving from an inactive state to an active one. Likewise, when moving from\n // an active to an inactive state, the return function (if provided) is called.\n onLoaded?: (matchContext: {\n params: TAllParams\n search: TFullSearchSchema\n }) =>\n | void\n | undefined\n | ((match: { params: TAllParams; search: TFullSearchSchema }) => void)\n // This function is called when the route remains active from one transition to the next.\n onTransition?: (match: {\n params: TAllParams\n search: TFullSearchSchema\n }) => void\n}\n\nexport type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<\n TPath,\n TParams\n>\n// | ParseParamsObj<TPath, TParams>\n\nexport type ParseParamsFn<TPath extends string, TParams> = (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : 'parseParams must return an object'\n\nexport type ParseParamsObj<TPath extends string, TParams> = {\n parse?: ParseParamsFn<TPath, TParams>\n}\n\n// The parse type here allows a zod schema to be passed directly to the validator\nexport type SearchSchemaValidator<TReturn, TParentSchema> =\n | SearchSchemaValidatorObj<TReturn, TParentSchema>\n | SearchSchemaValidatorFn<TReturn, TParentSchema>\n\nexport type SearchSchemaValidatorObj<TReturn, TParentSchema> = {\n parse?: SearchSchemaValidatorFn<TReturn, TParentSchema>\n}\n\nexport type SearchSchemaValidatorFn<TReturn, TParentSchema> = (\n searchObj: Record<string, unknown>,\n) => {} extends TParentSchema\n ? TReturn\n : keyof TReturn extends keyof TParentSchema\n ? {\n error: 'Top level search params cannot be redefined by child routes!'\n keys: keyof TReturn & keyof TParentSchema\n }\n : TReturn\n\nexport type DefinedPathParamWarning =\n 'Path params cannot be redefined by child routes!'\n\nexport type ParentParams<TParentParams> = AnyPathParams extends TParentParams\n ? {}\n : {\n [Key in keyof TParentParams]?: DefinedPathParamWarning\n }\n\nexport type LoaderFn<\n TLoader = unknown,\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams = {},\n TContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> = (\n match: LoaderContext<\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TContext,\n TAllContext\n > & {\n parentMatchPromise?: Promise<void>\n },\n) => Promise<TLoader> | TLoader\n\nexport type GetKeyFn<\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams = {},\n> = (loaderContext: { params: TAllParams; search: TFullSearchSchema }) => any\n\nexport interface LoaderContext<\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams = {},\n TContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> {\n params: TAllParams\n routeSearch: TSearchSchema\n search: TFullSearchSchema\n abortController: AbortController\n preload: boolean\n routeContext: TContext\n context: TAllContext\n}\n\nexport type UnloaderFn<TPath extends string> = (\n routeMatch: RouteMatch<any, Route>,\n) => void\n\nexport type SearchFilter<T, U = T> = (prev: T) => U\n\nexport type ResolveId<\n TParentRoute,\n TCustomId extends string,\n TPath extends string,\n> = TParentRoute extends { id: infer TParentId extends string }\n ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId>\n : RootRouteId\n\nexport type InferFullSearchSchema<TRoute> = TRoute extends {\n isRoot: true\n __types: {\n searchSchema: infer TSearchSchema\n }\n}\n ? TSearchSchema\n : TRoute extends {\n __types: {\n fullSearchSchema: infer TFullSearchSchema\n }\n }\n ? TFullSearchSchema\n : {}\n\nexport type ResolveFullSearchSchema<TParentRoute, TSearchSchema> =\n InferFullSearchSchema<TParentRoute> & TSearchSchema\n\nexport interface AnyRoute\n extends Route<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > {}\n\nexport type MergeParamsFromParent<T, U> = IsAny<T, U, T & U>\n\nexport type UseLoaderResult<T> = T extends Record<PropertyKey, infer U>\n ? {\n [K in keyof T]: UseLoaderResultPromise<T[K]>\n }\n : UseLoaderResultPromise<T>\n\nexport type UseLoaderResultPromise<T> = T extends Promise<infer U>\n ? StreamedPromise<U>\n : T\n\nexport type StreamedPromise<T> = {\n promise: Promise<T>\n status: 'resolved' | 'pending'\n data: T\n resolve: (value: T) => void\n}\n\nexport type RouteConstraints = {\n TParentRoute: AnyRoute\n TPath: string\n TFullPath: string\n TCustomId: string\n TId: string\n TSearchSchema: AnySearchSchema\n TFullSearchSchema: AnySearchSchema\n TParams: Record<string, any>\n TAllParams: Record<string, any>\n TParentContext: AnyContext\n TAllParentContext: AnyContext\n TRouteContext: RouteContext\n TAllContext: AnyContext\n TRouterContext: AnyContext\n TChildren: unknown\n TRouteTree: AnyRoute\n}\n\nexport class Route<\n TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n TPath extends RouteConstraints['TPath'] = '/',\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n TCustomId extends RouteConstraints['TCustomId'] = string,\n TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n TLoader = unknown,\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = Record<\n ParsePathParams<TPath>,\n string\n >,\n TAllParams extends RouteConstraints['TAllParams'] = MergeParamsFromParent<\n TParentRoute['__types']['allParams'],\n TParams\n >,\n TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['__types']['routeContext'],\n TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['__types']['context'],\n TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,\n TAllContext extends RouteConstraints['TAllContext'] = MergeParamsFromParent<\n TParentRoute['__types']['context'],\n TRouteContext\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n> {\n __types!: {\n parentRoute: TParentRoute\n path: TPath\n to: TrimPathRight<TFullPath>\n fullPath: TFullPath\n customId: TCustomId\n id: TId\n loader: TLoader\n searchSchema: TSearchSchema\n fullSearchSchema: TFullSearchSchema\n params: TParams\n allParams: TAllParams\n parentContext: TParentContext\n allParentContext: TAllParentContext\n routeContext: TRouteContext\n context: TAllContext\n children: TChildren\n routeTree: TRouteTree\n routerContext: TRouterContext\n }\n isRoot: TParentRoute extends Route<any> ? true : false\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoader,\n InferFullSearchSchema<TParentRoute>,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TAllContext\n > &\n UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n >\n\n // Set up in this.init()\n parentRoute!: TParentRoute\n id!: TId\n // customId!: TCustomId\n path!: TPath\n fullPath!: TFullPath\n to!: TrimPathRight<TFullPath>\n\n // Optional\n children?: TChildren\n originalIndex?: number\n router?: AnyRouter\n rank!: number\n\n constructor(\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoader,\n InferFullSearchSchema<TParentRoute>,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TAllContext\n > &\n UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n >,\n ) {\n this.options = (options as any) || {}\n this.isRoot = !options?.getParentRoute as any\n Route.__onInit(this as any)\n }\n\n init = (opts: { originalIndex: number; router: AnyRouter }) => {\n this.originalIndex = opts.originalIndex\n this.router = opts.router\n\n const options = this.options as RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n InferFullSearchSchema<TParentRoute>,\n TSearchSchema,\n TParams\n > &\n RoutePathOptionsIntersection<TCustomId, TPath>\n\n const isRoot = !options?.path && !options?.id\n\n this.parentRoute = this.options?.getParentRoute?.()\n\n if (isRoot) {\n this.path = rootRouteId as TPath\n } else {\n invariant(\n this.parentRoute,\n `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,\n )\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPath(path)\n }\n\n const customId = options?.id || path\n\n // Strip the parentId prefix from the first level of children\n let id = isRoot\n ? rootRouteId\n : joinPaths([\n (this.parentRoute.id as any) === rootRouteId\n ? ''\n : this.parentRoute.id,\n customId,\n ])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : joinPaths([this.parentRoute.fullPath, path])\n\n this.path = path as TPath\n this.id = id as TId\n // this.customId = customId as TCustomId\n this.fullPath = fullPath as TFullPath\n this.to = fullPath as TrimPathRight<TFullPath>\n }\n\n addChildren = <TNewChildren extends AnyRoute[]>(\n children: TNewChildren,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TAllContext,\n TRouterContext,\n TNewChildren,\n TRouteTree\n > => {\n this.children = children as any\n return this as any\n }\n\n update = (\n options: UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n >,\n ) => {\n Object.assign(this.options, options)\n return this\n }\n\n static __onInit = (route: typeof this) => {\n // This is a dummy static method that should get\n // replaced by a framework specific implementation if necessary\n }\n}\n\nexport type AnyRootRoute = RootRoute<any, any, any, any>\n\nexport class RouterContext<TRouterContext extends {}> {\n constructor() {}\n\n createRootRoute = <\n TLoader = unknown,\n TSearchSchema extends AnySearchSchema = {},\n TRouteContext extends RouteContext = RouteContext,\n >(\n options?: Omit<\n RouteOptions<\n AnyRoute,\n RootRouteId,\n '',\n TLoader,\n TSearchSchema,\n TSearchSchema,\n TSearchSchema,\n {},\n {},\n TRouterContext,\n TRouterContext,\n TRouteContext,\n MergeParamsFromParent<TRouterContext, TRouteContext>\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n >,\n ) => {\n return new RootRoute<TLoader, TSearchSchema, TRouteContext, TRouterContext>(\n options as any,\n )\n }\n}\n\nexport class RootRoute<\n TLoader = unknown,\n TSearchSchema extends AnySearchSchema = {},\n TRouteContext extends RouteContext = RouteContext,\n TRouterContext extends {} = {},\n> extends Route<\n any,\n '/',\n '/',\n string,\n RootRouteId,\n TLoader,\n TSearchSchema,\n TSearchSchema,\n {},\n {},\n TRouterContext,\n TRouterContext,\n TRouteContext,\n MergeParamsFromParent<TRouterContext, TRouteContext>,\n TRouterContext,\n any,\n any\n> {\n constructor(\n options?: Omit<\n RouteOptions<\n AnyRoute,\n RootRouteId,\n '',\n TLoader,\n TSearchSchema,\n TSearchSchema,\n TSearchSchema,\n {},\n {},\n TRouterContext,\n TRouterContext,\n TRouteContext,\n MergeParamsFromParent<TRouterContext, TRouteContext>\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n >,\n ) {\n super(options as any)\n }\n}\n\nexport type ResolveFullPath<\n TParentRoute extends AnyRoute,\n TPath extends string,\n TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>,\n> = TPrefixed extends RootRouteId ? '/' : TPrefixed\n\ntype RoutePrefix<\n TPrefix extends string,\n TPath extends string,\n> = string extends TPath\n ? RootRouteId\n : TPath extends string\n ? TPrefix extends RootRouteId\n ? TPath extends '/'\n ? '/'\n : `/${TrimPath<TPath>}`\n : `${TPrefix}/${TPath}` extends '/'\n ? '/'\n : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`\n : never\n\nexport type TrimPath<T extends string> = '' extends T\n ? ''\n : TrimPathRight<TrimPathLeft<T>>\n\nexport type TrimPathLeft<T extends string> =\n T extends `${RootRouteId}/${infer U}`\n ? TrimPathLeft<U>\n : T extends `/${infer U}`\n ? TrimPathLeft<U>\n : T\nexport type TrimPathRight<T extends string> = T extends '/'\n ? '/'\n : T extends `${infer U}/`\n ? TrimPathRight<U>\n : T\n"],"names":["rootRouteId","Route","constructor","options","isRoot","getParentRoute","__onInit","init","opts","originalIndex","router","path","id","parentRoute","invariant","trimPath","customId","joinPaths","fullPath","to","addChildren","children","update","Object","assign","route","RouterContext","createRootRoute","RootRoute"],"mappings":"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"}
@@ -15,7 +15,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
15
15
  var qss = require('./qss.js');
16
16
 
17
17
  const defaultParseSearch = parseSearchWith(JSON.parse);
18
- const defaultStringifySearch = stringifySearchWith(JSON.stringify);
18
+ const defaultStringifySearch = stringifySearchWith(JSON.stringify, JSON.parse);
19
19
  function parseSearchWith(parser) {
20
20
  return searchStr => {
21
21
  if (searchStr.substring(0, 1) === '?') {
@@ -37,7 +37,26 @@ function parseSearchWith(parser) {
37
37
  return query;
38
38
  };
39
39
  }
40
- function stringifySearchWith(stringify) {
40
+ function stringifySearchWith(stringify, parser) {
41
+ function stringifyValue(val) {
42
+ if (typeof val === 'object' && val !== null) {
43
+ try {
44
+ return stringify(val);
45
+ } catch (err) {
46
+ // silent
47
+ }
48
+ } else if (typeof val === 'string' && typeof parser === 'function') {
49
+ try {
50
+ // Check if it's a valid parseable string.
51
+ // If it is, then stringify it again.
52
+ parser(val);
53
+ return stringify(val);
54
+ } catch (err) {
55
+ // silent
56
+ }
57
+ }
58
+ return val;
59
+ }
41
60
  return search => {
42
61
  search = {
43
62
  ...search
@@ -47,12 +66,10 @@ function stringifySearchWith(stringify) {
47
66
  const val = search[key];
48
67
  if (typeof val === 'undefined' || val === undefined) {
49
68
  delete search[key];
50
- } else if (val && typeof val === 'object' && val !== null) {
51
- try {
52
- search[key] = stringify(val);
53
- } catch (err) {
54
- // silent
55
- }
69
+ } else if (Array.isArray(val)) {
70
+ search[key] = val.map(stringifyValue);
71
+ } else {
72
+ search[key] = stringifyValue(val);
56
73
  }
57
74
  });
58
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"searchParams.js","sources":["../../src/searchParams.ts"],"sourcesContent":["import { decode, encode } from './qss'\nimport { AnySearchSchema } from './route'\n\nexport const defaultParseSearch = parseSearchWith(JSON.parse)\nexport const defaultStringifySearch = stringifySearchWith(JSON.stringify)\n\nexport function parseSearchWith(parser: (str: string) => any) {\n return (searchStr: string): AnySearchSchema => {\n if (searchStr.substring(0, 1) === '?') {\n searchStr = searchStr.substring(1)\n }\n\n let query: Record<string, unknown> = decode(searchStr)\n\n // Try to parse any query params that might be json\n for (let 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(stringify: (search: any) => string) {\n return (search: Record<string, any>) => {\n search = { ...search }\n\n if (search) {\n Object.keys(search).forEach((key) => {\n const val = search[key]\n if (typeof val === 'undefined' || val === undefined) {\n delete search[key]\n } else if (val && typeof val === 'object' && val !== null) {\n try {\n search[key] = stringify(val)\n } catch (err) {\n // silent\n }\n }\n })\n }\n\n const searchStr = encode(search as Record<string, string>).toString()\n\n return searchStr ? `?${searchStr}` : ''\n }\n}\n"],"names":["defaultParseSearch","parseSearchWith","JSON","parse","defaultStringifySearch","stringifySearchWith","stringify","parser","searchStr","substring","query","decode","key","value","err","search","Object","keys","forEach","val","undefined","encode","toString"],"mappings":";;;;;;;;;;;;;;;;AAGO,MAAMA,kBAAkB,GAAGC,eAAe,CAACC,IAAI,CAACC,KAAK,EAAC;AACtD,MAAMC,sBAAsB,GAAGC,mBAAmB,CAACH,IAAI,CAACI,SAAS,EAAC;AAElE,SAASL,eAAeA,CAACM,MAA4B,EAAE;AAC5D,EAAA,OAAQC,SAAiB,IAAsB;IAC7C,IAAIA,SAAS,CAACC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,EAAE;AACrCD,MAAAA,SAAS,GAAGA,SAAS,CAACC,SAAS,CAAC,CAAC,CAAC,CAAA;AACpC,KAAA;AAEA,IAAA,IAAIC,KAA8B,GAAGC,UAAM,CAACH,SAAS,CAAC,CAAA;;AAEtD;AACA,IAAA,KAAK,IAAII,GAAG,IAAIF,KAAK,EAAE;AACrB,MAAA,MAAMG,KAAK,GAAGH,KAAK,CAACE,GAAG,CAAC,CAAA;AACxB,MAAA,IAAI,OAAOC,KAAK,KAAK,QAAQ,EAAE;QAC7B,IAAI;AACFH,UAAAA,KAAK,CAACE,GAAG,CAAC,GAAGL,MAAM,CAACM,KAAK,CAAC,CAAA;SAC3B,CAAC,OAAOC,GAAG,EAAE;AACZ;AAAA,SAAA;AAEJ,OAAA;AACF,KAAA;AAEA,IAAA,OAAOJ,KAAK,CAAA;GACb,CAAA;AACH,CAAA;AAEO,SAASL,mBAAmBA,CAACC,SAAkC,EAAE;AACtE,EAAA,OAAQS,MAA2B,IAAK;AACtCA,IAAAA,MAAM,GAAG;MAAE,GAAGA,MAAAA;KAAQ,CAAA;AAEtB,IAAA,IAAIA,MAAM,EAAE;MACVC,MAAM,CAACC,IAAI,CAACF,MAAM,CAAC,CAACG,OAAO,CAAEN,GAAG,IAAK;AACnC,QAAA,MAAMO,GAAG,GAAGJ,MAAM,CAACH,GAAG,CAAC,CAAA;QACvB,IAAI,OAAOO,GAAG,KAAK,WAAW,IAAIA,GAAG,KAAKC,SAAS,EAAE;UACnD,OAAOL,MAAM,CAACH,GAAG,CAAC,CAAA;AACpB,SAAC,MAAM,IAAIO,GAAG,IAAI,OAAOA,GAAG,KAAK,QAAQ,IAAIA,GAAG,KAAK,IAAI,EAAE;UACzD,IAAI;AACFJ,YAAAA,MAAM,CAACH,GAAG,CAAC,GAAGN,SAAS,CAACa,GAAG,CAAC,CAAA;WAC7B,CAAC,OAAOL,GAAG,EAAE;AACZ;AAAA,WAAA;AAEJ,SAAA;AACF,OAAC,CAAC,CAAA;AACJ,KAAA;IAEA,MAAMN,SAAS,GAAGa,UAAM,CAACN,MAAgC,CAAC,CAACO,QAAQ,EAAE,CAAA;AAErE,IAAA,OAAOd,SAAS,GAAI,CAAA,CAAA,EAAGA,SAAU,CAAA,CAAC,GAAG,EAAE,CAAA;GACxC,CAAA;AACH;;;;;;;"}
1
+ {"version":3,"file":"searchParams.js","sources":["../../src/searchParams.ts"],"sourcesContent":["import { decode, encode } from './qss'\nimport { AnySearchSchema } from './route'\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): AnySearchSchema => {\n if (searchStr.substring(0, 1) === '?') {\n searchStr = searchStr.substring(1)\n }\n\n let query: Record<string, unknown> = decode(searchStr)\n\n // Try to parse any query params that might be json\n for (let 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 if (search) {\n Object.keys(search).forEach((key) => {\n const val = search[key]\n if (typeof val === 'undefined' || val === undefined) {\n delete search[key]\n } else if (Array.isArray(val)) {\n search[key] = val.map(stringifyValue)\n } else {\n search[key] = stringifyValue(val)\n }\n })\n }\n\n const searchStr = encode(search as Record<string, string>).toString()\n\n return searchStr ? `?${searchStr}` : ''\n }\n}\n"],"names":["defaultParseSearch","parseSearchWith","JSON","parse","defaultStringifySearch","stringifySearchWith","stringify","parser","searchStr","substring","query","decode","key","value","err","stringifyValue","val","search","Object","keys","forEach","undefined","Array","isArray","map","encode","toString"],"mappings":";;;;;;;;;;;;;;;;AAGO,MAAMA,kBAAkB,GAAGC,eAAe,CAACC,IAAI,CAACC,KAAK,EAAC;AAChDC,MAAAA,sBAAsB,GAAGC,mBAAmB,CACvDH,IAAI,CAACI,SAAS,EACdJ,IAAI,CAACC,KACP,EAAC;AAEM,SAASF,eAAeA,CAACM,MAA4B,EAAE;AAC5D,EAAA,OAAQC,SAAiB,IAAsB;IAC7C,IAAIA,SAAS,CAACC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,EAAE;AACrCD,MAAAA,SAAS,GAAGA,SAAS,CAACC,SAAS,CAAC,CAAC,CAAC,CAAA;AACpC,KAAA;AAEA,IAAA,IAAIC,KAA8B,GAAGC,UAAM,CAACH,SAAS,CAAC,CAAA;;AAEtD;AACA,IAAA,KAAK,IAAII,GAAG,IAAIF,KAAK,EAAE;AACrB,MAAA,MAAMG,KAAK,GAAGH,KAAK,CAACE,GAAG,CAAC,CAAA;AACxB,MAAA,IAAI,OAAOC,KAAK,KAAK,QAAQ,EAAE;QAC7B,IAAI;AACFH,UAAAA,KAAK,CAACE,GAAG,CAAC,GAAGL,MAAM,CAACM,KAAK,CAAC,CAAA;SAC3B,CAAC,OAAOC,GAAG,EAAE;AACZ;AAAA,SAAA;AAEJ,OAAA;AACF,KAAA;AAEA,IAAA,OAAOJ,KAAK,CAAA;GACb,CAAA;AACH,CAAA;AAEO,SAASL,mBAAmBA,CACjCC,SAAkC,EAClCC,MAA6B,EAC7B;EACA,SAASQ,cAAcA,CAACC,GAAQ,EAAE;IAChC,IAAI,OAAOA,GAAG,KAAK,QAAQ,IAAIA,GAAG,KAAK,IAAI,EAAE;MAC3C,IAAI;QACF,OAAOV,SAAS,CAACU,GAAG,CAAC,CAAA;OACtB,CAAC,OAAOF,GAAG,EAAE;AACZ;AAAA,OAAA;KAEH,MAAM,IAAI,OAAOE,GAAG,KAAK,QAAQ,IAAI,OAAOT,MAAM,KAAK,UAAU,EAAE;MAClE,IAAI;AACF;AACA;QACAA,MAAM,CAACS,GAAG,CAAC,CAAA;QACX,OAAOV,SAAS,CAACU,GAAG,CAAC,CAAA;OACtB,CAAC,OAAOF,GAAG,EAAE;AACZ;AAAA,OAAA;AAEJ,KAAA;AACA,IAAA,OAAOE,GAAG,CAAA;AACZ,GAAA;AAEA,EAAA,OAAQC,MAA2B,IAAK;AACtCA,IAAAA,MAAM,GAAG;MAAE,GAAGA,MAAAA;KAAQ,CAAA;AAEtB,IAAA,IAAIA,MAAM,EAAE;MACVC,MAAM,CAACC,IAAI,CAACF,MAAM,CAAC,CAACG,OAAO,CAAER,GAAG,IAAK;AACnC,QAAA,MAAMI,GAAG,GAAGC,MAAM,CAACL,GAAG,CAAC,CAAA;QACvB,IAAI,OAAOI,GAAG,KAAK,WAAW,IAAIA,GAAG,KAAKK,SAAS,EAAE;UACnD,OAAOJ,MAAM,CAACL,GAAG,CAAC,CAAA;SACnB,MAAM,IAAIU,KAAK,CAACC,OAAO,CAACP,GAAG,CAAC,EAAE;UAC7BC,MAAM,CAACL,GAAG,CAAC,GAAGI,GAAG,CAACQ,GAAG,CAACT,cAAc,CAAC,CAAA;AACvC,SAAC,MAAM;AACLE,UAAAA,MAAM,CAACL,GAAG,CAAC,GAAGG,cAAc,CAACC,GAAG,CAAC,CAAA;AACnC,SAAA;AACF,OAAC,CAAC,CAAA;AACJ,KAAA;IAEA,MAAMR,SAAS,GAAGiB,UAAM,CAACR,MAAgC,CAAC,CAACS,QAAQ,EAAE,CAAA;AAErE,IAAA,OAAOlB,SAAS,GAAI,CAAA,CAAA,EAAGA,SAAU,CAAA,CAAC,GAAG,EAAE,CAAA;GACxC,CAAA;AACH;;;;;;;"}
@@ -636,7 +636,7 @@ class FileRoute {
636
636
  }
637
637
 
638
638
  const defaultParseSearch = parseSearchWith(JSON.parse);
639
- const defaultStringifySearch = stringifySearchWith(JSON.stringify);
639
+ const defaultStringifySearch = stringifySearchWith(JSON.stringify, JSON.parse);
640
640
  function parseSearchWith(parser) {
641
641
  return searchStr => {
642
642
  if (searchStr.substring(0, 1) === '?') {
@@ -658,7 +658,26 @@ function parseSearchWith(parser) {
658
658
  return query;
659
659
  };
660
660
  }
661
- function stringifySearchWith(stringify) {
661
+ function stringifySearchWith(stringify, parser) {
662
+ function stringifyValue(val) {
663
+ if (typeof val === 'object' && val !== null) {
664
+ try {
665
+ return stringify(val);
666
+ } catch (err) {
667
+ // silent
668
+ }
669
+ } else if (typeof val === 'string' && typeof parser === 'function') {
670
+ try {
671
+ // Check if it's a valid parseable string.
672
+ // If it is, then stringify it again.
673
+ parser(val);
674
+ return stringify(val);
675
+ } catch (err) {
676
+ // silent
677
+ }
678
+ }
679
+ return val;
680
+ }
662
681
  return search => {
663
682
  search = {
664
683
  ...search
@@ -668,12 +687,10 @@ function stringifySearchWith(stringify) {
668
687
  const val = search[key];
669
688
  if (typeof val === 'undefined' || val === undefined) {
670
689
  delete search[key];
671
- } else if (val && typeof val === 'object' && val !== null) {
672
- try {
673
- search[key] = stringify(val);
674
- } catch (err) {
675
- // silent
676
- }
690
+ } else if (Array.isArray(val)) {
691
+ search[key] = val.map(stringifyValue);
692
+ } else {
693
+ search[key] = stringifyValue(val);
677
694
  }
678
695
  });
679
696
  }