@real-router/validation-plugin 0.17.2 → 0.17.4
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/README.md +1 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.mts +2 -2
- package/dist/esm/index.d.mts.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/esm/index.d.mts
CHANGED
|
@@ -14,7 +14,7 @@ import { RouterValidator } from "@real-router/core/validation";
|
|
|
14
14
|
* `AnyOptions = Options<never>` in core): it fails on both compilers, because
|
|
15
15
|
* this plugin actually reads dependencies.
|
|
16
16
|
*/
|
|
17
|
-
declare function validationPlugin<Dependencies extends DefaultDependencies = DefaultDependencies>(): PluginFactory<Dependencies>;
|
|
17
|
+
export declare function validationPlugin<Dependencies extends DefaultDependencies = DefaultDependencies>(): PluginFactory<Dependencies>;
|
|
18
18
|
//#endregion
|
|
19
|
-
export {
|
|
19
|
+
export type { RouterValidator };
|
|
20
20
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/esm/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/validationPlugin.ts"],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/validationPlugin.ts"],"mappings":";;;;;;;;;;;;;;;;wBA8WgB,iBACd,qBAAqB,sBAAsB,wBACxC,cAAc"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{RouterError as e,events as t,resolveForwardChain as n}from"@real-router/core";import{freezeThrownError as r,putField as i}from"@real-router/core/utils";import{getInternals as a,validateRoute as o}from"@real-router/core/validation";const s=Object.freeze({maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxLifecycleHandlers:200});function c(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}function l(e){return typeof e==`string`}function u(e){return typeof e==`boolean`}function ee(e,t){return e in t}const d=Object.getPrototypeOf,te=Object.values,ne=Object.hasOwn;function re(e){if(Array.isArray(e))return!0;let t=d(e);return t===null||t===Object.prototype}function ie(e,t){let n=Array.isArray(e)?e:te(e);for(let e of n)t.push(e)}function ae(e){let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}var f=class{container;constructor(e){this.container=e}};function oe(e,t,n,r){return n.has(e)?!1:r.has(e)?!0:re(e)?(n.add(e),t.push(new f(e)),ie(e,t),!0):!1}function se(e){let t=[e],n=new WeakSet,r=new WeakSet;for(;t.length>0;){let e=t.pop();if(e instanceof f){n.delete(e.container),r.add(e.container);continue}if(e!=null){if(typeof e==`object`){if(!oe(e,t,n,r))return!1;continue}if(!ae(e))return!1}}return!0}function ce(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}function p(e){try{return le(e)}catch{return!1}}function le(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=d(e);if(t!==null&&t!==Object.prototype)return!1;let n=!1;for(let t in e){if(!ne(e,t))continue;let r=e[t];if(!ce(r)){let e=typeof r;if(e===`function`||e===`symbol`)return!1;n=!0;break}}return!n||se(e)}const ue=[`replace`,`reload`,`force`,`forceDeactivate`,`redirected`];function de(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;for(let e of ue){let n=t[e];if(n!==void 0&&typeof n!=`boolean`)return!1}let n=t.signal;return n===void 0||n instanceof AbortSignal}const fe=/\S/,m=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function h(e,t){return TypeError(`[router.${e}] ${t}`)}function pe(e){return typeof e==`string`?e===``?!0:e.length>1e4?!1:e.startsWith(`@@`)?!0:m.test(e):!1}function me(e){return pe(e.name)&&typeof e.path==`string`&&p(e.params)}function g(e){return typeof e!=`object`||!e?!1:me(e)}function _(e,t){if(typeof e!=`string`)throw h(t,`Route name must be a string, got ${typeof e}`);if(e!==``){if(!fe.test(e))throw h(t,`Route name cannot contain only whitespace`);if(e.length>1e4)throw h(t,`Route name exceeds maximum length of 10000 characters. This is a technical safety limit.`);if(!e.startsWith(`@@`)&&!m.test(e))throw h(t,`Invalid route name "${e}". Each segment must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens. Segments are separated by dots (e.g., "users.profile").`)}}function v(e){if(e===null)return`null`;if(Array.isArray(e))return`array[${e.length}]`;if(typeof e==`object`){try{let t=e.constructor;if(typeof t==`function`&&t.name!==`Object`)return t.name||`object`}catch{}return`object`}return typeof e}const y=Object.keys,b=Object.getOwnPropertyDescriptor,he=Object.getPrototypeOf,ge=Object;function x(e){if(!e||typeof e!=`object`)return!1;let t=he(e);return t===null||t.constructor===ge}function _e(e,t){if(typeof e!=`string`)throw TypeError(`[router.${t}] dependency name must be a string, got ${typeof e}`)}function ve(e){if(typeof e!=`string`)throw TypeError(`[router.setDependency] dependency name must be a string, got ${typeof e}`)}function ye(e,t){if(!x(e))throw TypeError(`[router.${t}] Invalid argument: expected plain object, received ${v(e)}`);for(let n of y(e))if(b(e,n)?.get)throw TypeError(`[router.${t}] Getters not allowed: "${n}"`)}function be(e,t){if(e===void 0)throw ReferenceError(`[router.getDependency] dependency "${t}" not found`)}function xe(e,t,n){let r=e,i=r.limits?.maxDependencies??s.maxDependencies;if(i===0)return;let a=y(r.dependencies).length,{warn:o,error:l}=c(i);if(a>=i)throw RangeError(`[router.${t}] Dependency limit exceeded (${i}). Current: ${a}.`);a===l?n.error(`router.${t}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${i}.`):a===o&&n.warn(`router.${t}`,`${a} dependencies registered. Consider if all are necessary.`)}function Se(e){if(e!==void 0){if(!x(e))throw TypeError(`[cloneRouter] Invalid dependencies: expected plain object or undefined, received ${typeof e}`);for(let t of y(e))if(b(e,t)?.get)throw TypeError(`[cloneRouter] Getters not allowed in dependencies: "${t}"`)}}function Ce(e,t,n){n.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function we(e,t,n){n.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function Te(e,t){t.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const Ee=Object.values,De=new Set(Ee(t));function Oe(e){if(!De.has(e))throw TypeError(`[router.addEventListener] Invalid event name: ${String(e)}. Must be one of: $start, $stop, $$start, $$leaveApprove, $$cancel, $$success, $$error`)}function ke(e,t){if(Oe(e),typeof t!=`function`)throw TypeError(`[router.addEventListener] callback must be a function, got ${typeof t}`)}function Ae(e,t,n,r,i=s.maxListeners){if(i===0)return;let{warn:a,error:o}=c(i);e>=o?r.error(`router.${n}`,`${e} listeners registered for "${t}"! This is excessive. Hard limit at ${i}.`):e>=a&&r.warn(`router.${n}`,`${e} listeners registered for "${t}". Consider whether all are necessary — a growing count usually means a missing unsubscribe.`)}function je(e,t){if(!u(e)&&typeof e!=`function`)throw TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${v(e)}`)}function S(e,t,n=s.maxLifecycleHandlers){if(n!==0&&e>=n)throw RangeError(`[router.${t}] Lifecycle handler limit exceeded (${n}). This indicates too many routes with individual handlers. Consider using plugins for cross-cutting concerns.`)}function Me(e,t,n,r){if(n===0)return;let{warn:i,error:a}=c(n);e>=a?r.error(`router.${t}`,`${e} lifecycle handlers registered! This is excessive. Hard limit at ${n}.`):e>=i&&r.warn(`router.${t}`,`${e} lifecycle handlers registered. Consider consolidating logic.`)}function Ne(e,t,n,r){r.warn(`router.${n}`,`Overwriting existing ${t} handler for route "${e}"`)}function Pe(e,t,n){n.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}const Fe=Object.hasOwn;function Ie(e){if(typeof e!=`string`)throw TypeError(`[router.navigate] Invalid route name: expected string, got ${v(e)}`)}function Le(e){if(e!==void 0&&(typeof e!=`object`||!e))throw TypeError(`[router.navigateToDefault] Invalid options: ${v(e)}. Expected NavigationOptions object.`)}function Re(e){if(typeof e!=`object`||!e)throw TypeError(`[router.navigateToState] Invalid state: ${v(e)}. Expected State object.`);let t=e;if(!l(t.name))throw TypeError(`[router.navigateToState] Invalid state.name: ${v(t.name)}. Expected string.`);if(!p(t.params))throw TypeError(`[router.navigateToState] Invalid state.params: ${v(t.params)}. Expected plain object.`);if(!l(t.path))throw TypeError(`[router.navigateToState] Invalid state.path: ${v(t.path)}. Expected string.`)}function ze(e,t){if(!de(e))throw TypeError(`[router.${t}] Invalid options: ${v(e)}. Expected NavigationOptions object.`)}const C=/[\u0000-\u001F\u007F]/;function Be(e,t){for(let n in e){if(!Fe(e,n))continue;let r=e[n],i=typeof r;if(i===`symbol`||i===`bigint`)throw TypeError(`[router.${t}] param "${n}" cannot be a ${i} — it does not round-trip through the URL path. Use a string, number, or boolean.`);if(i===`string`&&C.test(r))throw TypeError(`[router.${t}] param "${n}" must not contain control characters (NUL / C0 / DEL) — they corrupt the URL path.`)}}function Ve(e,t){if(e!==void 0&&(typeof e==`object`&&e&&!Array.isArray(e)&&Be(e,t),!p(e)))throw TypeError(`[router.${t}] params must be a plain object, got ${v(e)}`)}function He(e,t){if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))throw TypeError(`[router.${t}] search must be a plain object, got ${v(e)}`)}function Ue(e){if(e!==void 0&&typeof e!=`string`)throw TypeError(`[router.start] path must be a string, got ${v(e)}.`);if(typeof e==`string`){if(C.test(e))throw TypeError(`[router.start] path must not contain control characters (NUL / C0 / DEL).`);if(e!==``&&!e.startsWith(`/`))throw TypeError(`[router.start] path must start with "/", got "${e}".`)}}const w=Object.entries,We=Object.hasOwn,Ge=Object.keys,T={trailingSlash:[`strict`,`never`,`always`,`preserve`],queryParamsMode:[`default`,`strict`,`loose`],urlParamsEncoding:[`default`,`uri`,`uriComponent`,`none`]},E={arrayFormat:[`none`,`brackets`,`index`,`comma`],booleanFormat:[`none`,`auto`,`empty-true`],nullFormat:[`default`,`hidden`],numberFormat:[`none`,`auto`]},Ke=new Set([`defaultRoute`,`defaultParams`,`defaultSearch`,`trailingSlash`,`caseSensitive`,`queryParamsMode`,`queryParams`,`urlParamsEncoding`,`allowNotFound`,`rewritePathOnMatch`,`logger`,`limits`]),D={maxDependencies:{min:0,max:1e4},maxPlugins:{min:0,max:1e3},maxListeners:{min:0,max:1e5},warnListeners:{min:0,max:1e5},maxLifecycleHandlers:{min:0,max:1e4}};function qe(e,t,n){if(typeof t!=`number`||!Number.isInteger(t))throw TypeError(`[router.${n}] limit "${e}" must be an integer, got ${String(t)}`);let r=D[e];if(t<r.min||t>r.max)throw RangeError(`[router.${n}] limit "${e}" must be between ${r.min} and ${r.max}, got ${t}`)}function Je(e,t){if(!e||typeof e!=`object`||e.constructor!==Object)throw TypeError(`[router.${t}] invalid limits: expected plain object, got ${typeof e}`);for(let[n,r]of w(e)){if(!We(D,n))throw TypeError(`[router.${t}] unknown limit: "${n}"`);r!==void 0&&qe(n,r,t)}let{warnListeners:n,maxListeners:r}=e;if(typeof n==`number`&&typeof r==`number`&&r>0&&n>r)throw RangeError(`[router.${t}] "limits.warnListeners" (${n}) must not exceed "limits.maxListeners" (${r}) — the warning channel would be unreachable`)}function O(e,t,n,r){if(e!==void 0&&(typeof e!=`string`||!n.includes(e))){let i=n.map(e=>`"${e}"`).join(`, `);throw TypeError(`[router.${r}] Invalid "${t}": "${typeof e==`string`?e:`(${typeof e})`}". Must be one of: ${i}`)}}function Ye(e,t){if(e!==void 0&&typeof e!=`string`&&typeof e!=`function`)throw TypeError(`[router.${t}] Invalid "defaultRoute": expected string or function, got ${typeof e}`)}function k(e,t,n){if(e!==void 0&&typeof e!=`function`&&(!e||typeof e!=`object`||Array.isArray(e)||e.constructor!==Object))throw TypeError(`[router.${n}] Invalid "${t}": expected plain object or function, got ${typeof e}`)}function Xe(e,t){if(e===void 0)return;if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`[router.${t}] Invalid "queryParams": expected plain object`);let n=e;for(let[e,r]of w(n)){if(!ee(e,E))throw TypeError(`[router.${t}] Invalid "queryParams.${e}": unknown option`);O(r,`queryParams.${e}`,E[e],t)}}function Ze(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`[router.${t}] Invalid options: expected plain object`);let n=e;for(let e of Ge(n))if(!Ke.has(e))throw TypeError(`[router.${t}] Unknown option: "${e}"`);if(Ye(n.defaultRoute,t),k(n.defaultParams,`defaultParams`,t),k(n.defaultSearch,`defaultSearch`,t),O(n.trailingSlash,`trailingSlash`,T.trailingSlash,t),O(n.queryParamsMode,`queryParamsMode`,T.queryParamsMode,t),O(n.urlParamsEncoding,`urlParamsEncoding`,T.urlParamsEncoding,t),n.allowNotFound!==void 0&&typeof n.allowNotFound!=`boolean`)throw TypeError(`[router.${t}] Invalid "allowNotFound": expected boolean, got ${typeof n.allowNotFound}`);if(n.rewritePathOnMatch!==void 0&&typeof n.rewritePathOnMatch!=`boolean`)throw TypeError(`[router.${t}] Invalid "rewritePathOnMatch": expected boolean, got ${typeof n.rewritePathOnMatch}`);if(n.caseSensitive!==void 0&&typeof n.caseSensitive!=`boolean`)throw TypeError(`[router.${t}] Invalid "caseSensitive": expected boolean, got ${typeof n.caseSensitive}`);Xe(n.queryParams,t),n.limits!==void 0&&Je(n.limits,t)}const Qe=Object.hasOwn,A=`router.usePlugin`,$e={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function et(e,t,n=s.maxPlugins){if(n!==0&&e+t>n)throw RangeError(`[router.usePlugin] Plugin limit exceeded (${n}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating plugins.`)}function tt(e,t){if(t.includes(e))throw Error(`[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.`)}function nt(e,t,n){if(t===0)return;let{warn:r,error:i}=c(t);e>=i?n.error(A,`${e} plugins registered! This is excessive. Hard limit at ${t}.`):e>=r&&n.warn(A,`${e} plugins registered. Consider if all are necessary.`)}function rt(e){for(let t in e)if(!(t===`teardown`||Qe($e,t)))throw TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}function it(e){e.warn(A,`Duplicate factory in batch, will be registered once`)}function at(e,t){t.warn(A,`Property '${e}' is not a function, skipping`)}function ot(e,t){e===`onStart`&&t.warn(A,`Router already started, onStart will not be called`)}const j=Object.entries,st=Object.getOwnPropertyDescriptor,M=Object.keys;function N(e,t){if(!e||typeof e!=`object`)throw TypeError(`[validation-plugin] ${t}: store must be an object`);let n=e;if(!Array.isArray(n.definitions))throw TypeError(`[validation-plugin] ${t}: store.definitions must be an array`);if(!n.config||typeof n.config!=`object`)throw TypeError(`[validation-plugin] ${t}: store.config must be an object`);if(!n.tree||typeof n.tree!=`object`)throw TypeError(`[validation-plugin] ${t}: store.tree must be an object`);return n}function P(e,t,n=``){for(let r of e){let e=n?`${n}.${r.name}`:r.name;t(r,e),r.children&&P(r.children,t,e)}}function F(e,t){let n=t.split(`.`),r=e;for(let e of n)if(r=r.children.get(e),!r)return!1;return!0}function ct(e,t){try{return n(e,t)}catch(e){throw Error(`[validation-plugin] ${e.message}`,{cause:e})}}function I(e){let t=new Set;for(let n of e)for(let e of n.paramMeta.urlParams)t.add(e);return t}function L(e,t,n){let r=e;if(r.constructor.name===`AsyncFunction`||r.toString().includes(`__awaiter`))throw TypeError(`[validation-plugin] Route "${n}" ${t} cannot be async`)}function lt(e){P(N(e,`validateExistingRoutes`).definitions,(e,t)=>{if(typeof e.name!=`string`||!e.name)throw TypeError(`[validation-plugin] validateExistingRoutes: route has invalid name: ${e.name}`);if(typeof e.path!=`string`)throw TypeError(`[validation-plugin] validateExistingRoutes: route "${t}" has non-string path (${typeof e.path})`)})}function ut(e){let{config:t,tree:n,matcher:r}=N(e,`validateForwardToConsistency`);for(let[e,i]of j(t.forwardMap)){if(!F(n,i))throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${i}" does not exist in tree (source route: "${e}")`);let t=r.getSegmentsByName(e),a=r.getSegmentsByName(i);if(t&&a){let n=I(t),r=[...I(a)].filter(e=>!n.has(e));if(r.length>0)throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${i}" requires params [${r.join(`, `)}] not available in source route "${e}"`)}}for(let e of M(t.forwardMap))ct(e,t.forwardMap)}function R(e,t){for(let[n,r]of j(e))if(typeof r!=`object`||!r||Array.isArray(r))throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${n}" ${t} must be a plain object, got ${Array.isArray(r)?`array`:typeof r}`)}function dt(e){let{config:t}=N(e,`validateRoutePropertiesStore`);for(let[e,n]of j(t.decoders)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" decoder must be a function, got ${typeof n}`);L(n,`decoder`,e)}for(let[e,n]of j(t.encoders)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" encoder must be a function, got ${typeof n}`);L(n,`encoder`,e)}R(t.defaultParams,`defaultParams`),R(t.defaultSearch,`defaultSearch`);for(let[e,n]of j(t.forwardFnMap)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" forwardTo callback must be a function, got ${typeof n}`);L(n,`forwardTo callback`,e)}}function ft(e){let{config:t,tree:n}=N(e,`validateForwardToTargetsStore`);for(let[e,r]of j(t.forwardMap))if(!F(n,r))throw Error(`[validation-plugin] validateForwardToTargetsStore: forwardTo target "${r}" does not exist for route "${e}"`)}function pt(e){if(!e||typeof e!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps must be an object`);let t=e;if(!t.dependencies||typeof t.dependencies!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.dependencies must be an object`);let n=t.dependencies;for(let e of M(n))if(st(n,e)?.get)throw TypeError(`[validation-plugin] validateDependenciesStructure: dependency "${e}" must not use a getter`);if(!t.limits||typeof t.limits!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits must be an object`);let r=t.limits;for(let e of[`maxDependencies`,`maxPlugins`,`maxListeners`,`warnListeners`,`maxLifecycleHandlers`])if(!Number.isInteger(r[e]))throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits.${e} must be an integer, got ${String(r[e])}`)}function mt(e){let t=e&&typeof e==`object`?e:{};return t.limits&&typeof t.limits==`object`?t.limits:{}}function ht(e,t){if(!e||typeof e!=`object`)return;let n=e,r=n.dependencies,i=n.limits;if(!r||typeof r!=`object`||!i||typeof i!=`object`)return;let a=M(r).length,o=i,s=t.maxDependencies,c=o.maxDependencies,l=typeof s==`number`?s:c;if(typeof l==`number`&&l>0&&a>l)throw RangeError(`[validation-plugin] validateLimitsConsistency: dependency count (${a}) exceeds maxDependencies limit (${l})`)}function gt(e,t){ht(t,mt(e))}function z(e,t){if(!(typeof e!=`string`||!e)&&!F(N(t,`validateResolvedDefaultRoute`).tree,e))throw Error(`[validation-plugin] defaultRoute resolved to non-existent route: "${e}"`)}const _t=Object.keys;function vt(e,t){if(e!==void 0){if(typeof e!=`string`&&typeof e!=`function`)throw TypeError(`[router.addRoute] forwardTo must be a string or function for route "${t}", got ${v(e)}`);if(typeof e==`function`){let n=e.constructor.name===`AsyncFunction`,r=e.toString().includes(`__awaiter`);if(n||r)throw TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${t}". Async functions break matchPath/buildPath.`)}}}function B(e,t,n){if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))throw TypeError(`[router.addRoute] ${t} must be an object for route "${n}", got ${v(e)}`)}function V(e,t){if(e.canActivate!==void 0&&typeof e.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function for route "${t}", got ${v(e.canActivate)}`);if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${v(e.canDeactivate)}`);if(B(e.defaultParams,`defaultParams`,t),B(e.defaultSearch,`defaultSearch`,t),e.decodeParams?.constructor.name===`AsyncFunction`)throw TypeError(`[router.addRoute] decodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if(e.encodeParams?.constructor.name===`AsyncFunction`)throw TypeError(`[router.addRoute] encodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if(vt(e.forwardTo,t),e.children)for(let n of e.children)V(n,`${t}.${n.name}`)}function yt(e){let t=new Set,n=/[*:]([A-Z_a-z]\w*)/g,r;for(;(r=n.exec(e))!==null;)t.add(r[1]);return t}function H(e){let t=new Set;for(let n of e)for(let e of yt(n))t.add(e);return t}function U(e,t,n=``,r=[]){for(let i of e){let e=n?`${n}.${i.name}`:i.name,a=[...r,i.path];if(e===t)return a;if(i.children&&t.startsWith(`${e}.`))return U(i.children,t,e,a)}throw Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function W(e,t=``){let n=new Set;for(let r of e){let e=t?`${t}.${r.name}`:r.name;if(n.add(e),r.children)for(let t of W(r.children,e))n.add(t)}return n}function G(e,t=``){let n=new Map;for(let r of e){let e=t?`${t}.${r.name}`:r.name;if(r.forwardTo&&typeof r.forwardTo==`string`&&n.set(e,r.forwardTo),r.children)for(let[t,i]of G(r.children,e))n.set(t,i)}return n}function K(e){let t=new Set;for(let n of e)for(let e of n.paramMeta.urlParams)t.add(e);return t}function bt(e,t,n,r){return t?K(n.getSegmentsByName(e)??[]):H(U(r,e))}const xt=new Set;function St(e,t,n,r,i,a){let o=i.hasRoute(t),s=r.has(t);if(!o&&!s)throw ReferenceError(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);let c=new Set([...a,...H(U(n,e))]),l=[...bt(t,o,i,n)].filter(e=>!c.has(e));if(l.length>0)throw Error(`[router.addRoute] forwardTo target "${t}" requires params [${l.join(`, `)}] that are not available in source route "${e}"`)}function Ct(e,t,r,a){let o=W(e),s=a?new Set([...o].map(e=>`${a}.${e}`)):o,c=a?K(r.getSegmentsByName(a)):xt,l=G(e),u={...t};for(let[e,t]of l)i(u,e,t);for(let[t,n]of l)St(t,n,e,s,r,c);for(let e of _t(u))n(e,u)}function q(e,t){if(e.startsWith(`@@`))throw Error(`[router.${t}] Route name "${e}" uses the reserved "@@" prefix. Routes with this prefix are internal and cannot be modified through the public API.`)}function J(e,t){for(let n of e)n&&typeof n==`object`&&typeof n.name==`string`&&(q(n.name,t),n.children&&J(n.children,t))}function wt(e){_(e,`removeRoute`)}function Tt(e){if(typeof e!=`string`)throw TypeError(`[router.setRootPath] rootPath must be a string, got ${v(e)}`)}function Y(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function Et(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function, got ${v(t.canActivate)}`);if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function, got ${v(t.canDeactivate)}`)}function Dt(e){let t=e,n=t.name;if(t.decodeParams!==void 0&&Y(t.decodeParams))throw TypeError(`[router.addRoute] decodeParams cannot be async for route "${String(n)}"`);if(t.encodeParams!==void 0&&Y(t.encodeParams))throw TypeError(`[router.addRoute] encodeParams cannot be async for route "${String(n)}"`);if(typeof t.forwardTo==`function`&&Y(t.forwardTo))throw TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${String(n)}"`)}function Ot(e){for(let t of e){if(typeof t!=`object`||!t||Array.isArray(t))throw TypeError(`[router.addRoute] Route must be an object, got ${v(t)}`);V(t,t.name)}}function kt(e){if(typeof e!=`string`||e===``)throw TypeError(`[router.addRoute] parent option must be a non-empty string, got ${v(e)}`);_(e,`addRoute`)}function At(e,t,n,r){if(!l(e))throw TypeError(`[router.isActiveRoute] name must be a string, got ${typeof e}`);if(t!==void 0&&!p(t))throw TypeError(`[router.isActiveRoute] params must be a plain object, got ${v(t)}`);if(n!==void 0&&typeof n!=`boolean`)throw TypeError(`[router.isActiveRoute] strictEquality must be a boolean, got ${typeof n}`);if(r!==void 0&&typeof r!=`boolean`)throw TypeError(`[router.isActiveRoute] ignoreQueryParams must be a boolean, got ${typeof r}`)}function jt(e,t,n){if(!l(e))throw TypeError(`[router.${n}] Invalid routeName: ${v(e)}. Expected string.`);if(!p(t))throw TypeError(`[router.${n}] Invalid routeParams: ${v(t)}. Expected plain object.`)}function Mt(e,t){if(_(e,`updateRoute`),e===``)throw ReferenceError(`[router.updateRoute] Invalid name: empty string. Cannot update root node.`);if(t===null)throw TypeError(`[router.updateRoute] updates must be an object, got null`);if(typeof t!=`object`||Array.isArray(t))throw TypeError(`[router.updateRoute] updates must be an object, got ${v(t)}`)}function X(e,t){if(e.constructor.name===`AsyncFunction`||e.toString().includes(`__awaiter`))throw TypeError(`[router.updateRoute] ${t} cannot be an async function`)}function Z(e,t){if(e!=null){if(typeof e!=`function`)throw TypeError(`[router.updateRoute] ${t} must be a function or null, got ${typeof e}`);X(e,t)}}function Nt(e){let{forwardTo:t,defaultParams:n,defaultSearch:r,decodeParams:i,encodeParams:a,canActivate:o,canDeactivate:s}=e;if(t!=null){if(typeof t!=`string`&&typeof t!=`function`)throw TypeError(`[router.updateRoute] forwardTo must be a string, function, or null, got ${v(t)}`);typeof t==`function`&&X(t,`forwardTo callback`)}Q(n,`defaultParams`),Q(r,`defaultSearch`),Z(i,`decodeParams`),Z(a,`encodeParams`),Z(o,`canActivate`),Z(s,`canDeactivate`)}function Q(e,t){if(e!=null&&(typeof e!=`object`||Array.isArray(e)))throw TypeError(`[router.updateRoute] ${t} must be an object or null, got ${v(e)}`)}function $(e){if(!l(e)||e===``)throw TypeError(`[router.buildPath] route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`)}function Pt(e){if(!l(e))throw TypeError(`[router.matchPath] path must be a string, got ${typeof e}`)}function Ft(e){if(!l(e))throw TypeError(`[router.shouldUpdateNode] nodeName must be a string, got ${typeof e}`)}function It(e,t,n,r,i){if(i&&t){let e=t;for(let t of i.split(`.`))if(e=e.children.get(t),!e)throw ReferenceError(`[router.addRoute] Parent route "${i}" does not exist`)}let a=new Set,s=new Map;for(let n of e)o(n,`addRoute`,t,i??``,a,s);n&&r&&Ct(e,r,n,i)}function Lt(e){let t=new Set;for(let n of e)for(let e of n.paramMeta.urlParams)t.add(e);return t}function Rt(e,t,n){let r=n.getSegmentsByName(e),i=n.getSegmentsByName(t),a=Lt(r),o=[];for(let e of i)for(let t of e.paramMeta.urlParams)o.push(t);let s=o.filter(e=>!a.has(e));if(s.length>0)throw Error(`[router.addRoute] forwardTo target "${t}" requires params [${s.join(`, `)}] that are not available in source route "${e}"`)}function zt(e,t,r){n(e,{...r.forwardMap,[e]:t})}function Bt(e,t,n,r,i){if(!n(e))throw ReferenceError(`[router.updateRoute] route "${e}" does not exist`);if(t!=null&&typeof t==`string`){if(!n(t))throw Error(`[router.updateRoute] forwardTo target "${t}" does not exist`);Rt(e,t,r),zt(e,t,i)}}function Vt(e,t,n){if(!l(e))throw TypeError(`[router.makeState] Invalid name: ${v(e)}. Expected string.`);if(t!==void 0&&!p(t))throw TypeError(`[router.makeState] Invalid params: ${v(t)}. Expected plain object.`);if(n!==void 0&&!l(n))throw TypeError(`[router.makeState] Invalid path: ${v(n)}. Expected string.`)}function Ht(){let e=new Set;return function(t,n){let r=`${t} ${n}`;e.has(r)||(e.add(r),console.warn(`[router] Query key "${n}" is not declared on route "${t}" (\`?${n}\`), so the current \`queryParamsMode\` will not print it — it was dropped from \`state.search\` rather than published beside a \`state.path\` that cannot show it. Declare it on the route path, or use \`queryParamsMode: "loose"\` to keep undeclared keys. A \`defaultSearch\` entry for "${n}" is dead config in this mode for the same reason.`))}}function Ut(){let e=new Set;return function(t,n){let r=`${t} ${n}`;e.has(r)||(e.add(r),console.warn(`[router] Param "${n}" is declared nowhere on route "${t}" — neither as a path slot (:${n}) nor as a query param (?${n}), so it stays in state.params but never reaches the URL. The state will not round-trip: matchPath(state.path) cannot recover it. Declare it on the route path if it belongs in the URL, or pass it through the search channel; keep it here only if it is deliberately app-level data.`))}}function Wt(e){return{routes:{validateBuildPathArgs:$,validateMatchPathArgs:Pt,validateIsActiveRouteArgs:At,validateShouldUpdateNodeArgs:Ft,validateStateBuilderArgs:jt,validateAddRouteArgs(e){Ot(e)},validateRoutes(e,t,n){let r=t;It(e,r.tree,r.matcher,r.config?.forwardMap,n)},validateRemoveRouteArgs:wt,validateUpdateRouteBasicArgs:Mt,validateUpdateRoutePropertyTypes(e,t){let n=t;Nt({forwardTo:n.forwardTo,defaultParams:n.defaultParams,defaultSearch:n.defaultSearch,decodeParams:n.decodeParams,encodeParams:n.encodeParams,canActivate:n.canActivate,canDeactivate:n.canDeactivate})},validateUpdateRoute(e,t,n){let r=n,i=t.forwardTo;Bt(e,i,e=>r.matcher.hasRoute(e),r.matcher,r.config)},validateParentOption(e,t){kt(e);let n=t;for(let t of e.split(`.`)){let r=n.children.get(t);if(!r)throw ReferenceError(`[router.addRoute] Parent route "${e}" does not exist`);n=r}},validateRouteName(e,t){_(e,t)},throwIfInternalRoute(e,t){q(e,t)},throwIfInternalRouteInArray(e,t){J(e,t)},validateSetRootPathArgs:Tt,guardRouteCallbacks:Et,guardNoAsyncCallbacks:Dt},options:{validateOptions:Ze,validateResolvedDefaultRoute:z},dependencies:{validateDependencyName:_e,validateSetDependencyArgs(e,t,n){ve(e)},validateDependenciesObject:ye,validateDependencyExists(e,t){let n=t.dependencies?.[e];be(n,e)},validateDependencyCount(t,n){xe(t,n,e.logger)},validateCloneArgs:Se,warnOverwrite(t,n){Ce(t,n,e.logger)},warnBatchOverwrite(t,n){we(t,n,e.logger)},warnRemoveNonExistent(t){Te(t,e.logger)}},plugins:{validatePluginLimit(e,t){et(e,1,t?.maxPlugins)},validateNoDuplicatePlugins:tt,validatePluginKeys:rt,validateCountThresholds(t){nt(t,e.getOptions().limits?.maxPlugins??s.maxPlugins,e.logger)},warnBatchDuplicates(){it(e.logger)},warnPluginMethodType(t){at(t,e.logger)},warnPluginAfterStart(t){ot(t,e.logger)}},lifecycle:{validateHandler:je,validateHandlerLimit(t,n){S(t,n,e.getOptions().limits?.maxLifecycleHandlers??s.maxLifecycleHandlers)},validateCountThresholds(t,n){Me(t,n,e.getOptions().limits?.maxLifecycleHandlers??s.maxLifecycleHandlers,e.logger)},warnOverwrite(t,n,r){Ne(t,n,r,e.logger)},warnAsyncGuardSync(t,n){Pe(t,n,e.logger)}},navigation:{validateNavigateArgs:Ie,validateNavigateToDefaultArgs:Le,validateNavigateToStateArgs:Re,validateNavigationOptions:ze,validateParams:Ve,validateSearch:He,validateStartArgs:Ue},state:{validateMakeStateArgs:Vt,reportDroppedQueryKey:Ht(),reportUndeclaredParamKey:Ut(),validateAreStatesEqualArgs(e,t,n){if(!g(e))throw TypeError(`[router.areStatesEqual] Invalid state1: ${v(e)}. Expected State object.`);if(!g(t))throw TypeError(`[router.areStatesEqual] Invalid state2: ${v(t)}. Expected State object.`);if(n!==void 0&&!u(n))throw TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${v(n)}. Expected boolean.`)}},eventBus:{validateListenerArgs(e,t){ke(e,t)},validateCountThresholds(t,n,r){let i=e.getOptions().limits?.maxListeners??s.maxListeners;Ae(t,n,r,e.logger,i)}}}}function Gt(){return t=>{let n=a(t);if(t.isActive())throw r(new e(`VALIDATION_PLUGIN_AFTER_START`,{message:`validation-plugin must be registered before router.start()`}));n.validator=Wt(n);try{let e=n.routeGetStore(),t=n.dependenciesGetStore(),r=n.getOptions();lt(e),ut(e),dt(e),ft(e),pt(t),gt(r,t),n.validator.options.validateOptions(r,`constructor (retrospective)`),typeof r.defaultRoute==`string`&&z(r.defaultRoute,e)}catch(e){throw n.validator=null,e}return{teardown(){n.validator=null}}}}export{Gt as validationPlugin};
|
|
1
|
+
import{RouterError as e,events as t,resolveForwardChain as n}from"@real-router/core";import{freezeThrownError as r,putField as i}from"@real-router/core/utils";import{getInternals as a,validateRoute as o}from"@real-router/core/validation";const s=Object.freeze({maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxLifecycleHandlers:200});function c(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}function l(e){return typeof e==`string`}function u(e){return typeof e==`boolean`}function d(e,t){return e in t}const f=Object.getPrototypeOf,ee=Object.values,te=Object.hasOwn;function ne(e){if(Array.isArray(e))return!0;let t=f(e);return t===null||t===Object.prototype}function re(e,t){let n=Array.isArray(e)?e:ee(e);for(let e of n)t.push(e)}function ie(e){let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}var p=class{container;constructor(e){this.container=e}};function ae(e,t,n,r){return n.has(e)?!1:r.has(e)?!0:ne(e)?(n.add(e),t.push(new p(e)),re(e,t),!0):!1}function oe(e){let t=[e],n=new WeakSet,r=new WeakSet;for(;t.length>0;){let e=t.pop();if(e instanceof p){n.delete(e.container),r.add(e.container);continue}if(e!=null){if(typeof e==`object`){if(!ae(e,t,n,r))return!1;continue}if(!ie(e))return!1}}return!0}function se(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}function m(e){try{return ce(e)}catch{return!1}}function ce(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=f(e);if(t!==null&&t!==Object.prototype)return!1;let n=!1;for(let t in e){if(!te(e,t))continue;let r=e[t];if(!se(r)){let e=typeof r;if(e===`function`||e===`symbol`)return!1;n=!0;break}}return!n||oe(e)}const le=[`replace`,`reload`,`force`,`forceDeactivate`,`redirected`];function ue(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;for(let e of le){let n=t[e];if(n!==void 0&&typeof n!=`boolean`)return!1}let n=t.signal;return n===void 0||n instanceof AbortSignal}const de=/\S/,h=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function g(e,t){return TypeError(`[router.${e}] ${t}`)}function fe(e){return typeof e==`string`?e===``?!0:e.length>1e4?!1:e.startsWith(`@@`)?!0:h.test(e):!1}function pe(e){return fe(e.name)&&typeof e.path==`string`&&m(e.params)}function _(e){return typeof e!=`object`||!e?!1:pe(e)}function v(e,t){if(typeof e!=`string`)throw g(t,`Route name must be a string, got ${typeof e}`);if(e!==``){if(!de.test(e))throw g(t,`Route name cannot contain only whitespace`);if(e.length>1e4)throw g(t,`Route name exceeds maximum length of 10000 characters. This is a technical safety limit.`);if(!e.startsWith(`@@`)&&!h.test(e))throw g(t,`Invalid route name "${e}". Each segment must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens. Segments are separated by dots (e.g., "users.profile").`)}}function y(e){if(e===null)return`null`;if(Array.isArray(e))return`array[${e.length}]`;if(typeof e==`object`){try{let t=e.constructor;if(typeof t==`function`&&t.name!==`Object`)return t.name||`object`}catch{}return`object`}return typeof e}const b=Object.entries,me=[`defaultParams`,`defaultSearch`],he=e=>new Map(b(e)),ge=(e,t)=>{let n=b(e);return n.length!==t.size||n.some(([e,n])=>!t.has(e)||!Object.is(t.get(e),n))};var _e=class{#e=new Map;#t=new Set;watch(e){for(let t of me){let n=e[t],r=n?.deref();n!==void 0&&r!==void 0&&this.#e.set(t,{ref:n,before:he(r)})}}check(e){for(let[t,{ref:n,before:r}]of this.#e){if(this.#t.has(t))continue;let i=n.deref();i!==void 0&&ge(i,r)&&(this.#t.add(t),e.warn(`router.navigateToDefault`,`mutating \`${t}\` after createRouter() no longer affects routing — the router copied it at construction. Use the callback form (\`${t}: () => ({ … })\`), which is resolved at the point of use.`))}}};const x=Object.keys,S=Object.getOwnPropertyDescriptor,ve=Object.getPrototypeOf,ye=Object;function C(e){if(!e||typeof e!=`object`)return!1;let t=ve(e);return t===null||t.constructor===ye}function be(e,t){if(typeof e!=`string`)throw TypeError(`[router.${t}] dependency name must be a string, got ${typeof e}`)}function xe(e){if(typeof e!=`string`)throw TypeError(`[router.setDependency] dependency name must be a string, got ${typeof e}`)}function Se(e,t){if(!C(e))throw TypeError(`[router.${t}] Invalid argument: expected plain object, received ${y(e)}`);for(let n of x(e))if(S(e,n)?.get)throw TypeError(`[router.${t}] Getters not allowed: "${n}"`)}function Ce(e,t){if(e===void 0)throw ReferenceError(`[router.getDependency] dependency "${t}" not found`)}function we(e,t,n){let r=e,i=r.limits?.maxDependencies??s.maxDependencies;if(i===0)return;let a=x(r.dependencies).length,{warn:o,error:l}=c(i);if(a>=i)throw RangeError(`[router.${t}] Dependency limit exceeded (${i}). Current: ${a}.`);a===l?n.error(`router.${t}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${i}.`):a===o&&n.warn(`router.${t}`,`${a} dependencies registered. Consider if all are necessary.`)}function Te(e){if(e!==void 0){if(!C(e))throw TypeError(`[cloneRouter] Invalid dependencies: expected plain object or undefined, received ${typeof e}`);for(let t of x(e))if(S(e,t)?.get)throw TypeError(`[cloneRouter] Getters not allowed in dependencies: "${t}"`)}}function Ee(e,t,n){n.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function De(e,t,n){n.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function Oe(e,t){t.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const ke=Object.values,Ae=new Set(ke(t));function je(e){if(!Ae.has(e))throw TypeError(`[router.addEventListener] Invalid event name: ${String(e)}. Must be one of: $start, $stop, $$start, $$leaveApprove, $$cancel, $$success, $$error`)}function Me(e,t){if(je(e),typeof t!=`function`)throw TypeError(`[router.addEventListener] callback must be a function, got ${typeof t}`)}function Ne(e,t,n,r,i=s.maxListeners){if(i===0)return;let{warn:a,error:o}=c(i);e>=o?r.error(`router.${n}`,`${e} listeners registered for "${t}"! This is excessive. Hard limit at ${i}.`):e>=a&&r.warn(`router.${n}`,`${e} listeners registered for "${t}". Consider whether all are necessary — a growing count usually means a missing unsubscribe.`)}function Pe(e,t){if(!u(e)&&typeof e!=`function`)throw TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${y(e)}`)}function Fe(e,t,n=s.maxLifecycleHandlers){if(n!==0&&e>=n)throw RangeError(`[router.${t}] Lifecycle handler limit exceeded (${n}). This indicates too many routes with individual handlers. Consider using plugins for cross-cutting concerns.`)}function Ie(e,t,n,r){if(n===0)return;let{warn:i,error:a}=c(n);e>=a?r.error(`router.${t}`,`${e} lifecycle handlers registered! This is excessive. Hard limit at ${n}.`):e>=i&&r.warn(`router.${t}`,`${e} lifecycle handlers registered. Consider consolidating logic.`)}function Le(e,t,n,r){r.warn(`router.${n}`,`Overwriting existing ${t} handler for route "${e}"`)}function Re(e,t,n){n.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}const ze=Object.hasOwn;function Be(e){if(typeof e!=`string`)throw TypeError(`[router.navigate] Invalid route name: expected string, got ${y(e)}`)}function Ve(e){if(e!==void 0&&(typeof e!=`object`||!e))throw TypeError(`[router.navigateToDefault] Invalid options: ${y(e)}. Expected NavigationOptions object.`)}function He(e){if(typeof e!=`object`||!e)throw TypeError(`[router.navigateToState] Invalid state: ${y(e)}. Expected State object.`);let t=e;if(!l(t.name))throw TypeError(`[router.navigateToState] Invalid state.name: ${y(t.name)}. Expected string.`);if(!m(t.params))throw TypeError(`[router.navigateToState] Invalid state.params: ${y(t.params)}. Expected plain object.`);if(!l(t.path))throw TypeError(`[router.navigateToState] Invalid state.path: ${y(t.path)}. Expected string.`)}function Ue(e,t){if(!ue(e))throw TypeError(`[router.${t}] Invalid options: ${y(e)}. Expected NavigationOptions object.`)}const w=/[\u0000-\u001F\u007F]/;function We(e,t){for(let n in e){if(!ze(e,n))continue;let r=e[n],i=typeof r;if(i===`symbol`||i===`bigint`)throw TypeError(`[router.${t}] param "${n}" cannot be a ${i} — it does not round-trip through the URL path. Use a string, number, or boolean.`);if(i===`string`&&w.test(r))throw TypeError(`[router.${t}] param "${n}" must not contain control characters (NUL / C0 / DEL) — they corrupt the URL path.`)}}function Ge(e,t){if(e!==void 0&&(typeof e==`object`&&e&&!Array.isArray(e)&&We(e,t),!m(e)))throw TypeError(`[router.${t}] params must be a plain object, got ${y(e)}`)}function Ke(e,t){if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))throw TypeError(`[router.${t}] search must be a plain object, got ${y(e)}`)}function qe(e){if(e!==void 0&&typeof e!=`string`)throw TypeError(`[router.start] path must be a string, got ${y(e)}.`);if(typeof e==`string`){if(w.test(e))throw TypeError(`[router.start] path must not contain control characters (NUL / C0 / DEL).`);if(e!==``&&!e.startsWith(`/`))throw TypeError(`[router.start] path must start with "/", got "${e}".`)}}const T=Object.entries,Je=Object.hasOwn,Ye=Object.keys,E={trailingSlash:[`strict`,`never`,`always`,`preserve`],queryParamsMode:[`default`,`strict`,`loose`],urlParamsEncoding:[`default`,`uri`,`uriComponent`,`none`]},D={arrayFormat:[`none`,`brackets`,`index`,`comma`],booleanFormat:[`none`,`auto`,`empty-true`],nullFormat:[`default`,`hidden`],numberFormat:[`none`,`auto`]},Xe=new Set([`defaultRoute`,`defaultParams`,`defaultSearch`,`trailingSlash`,`caseSensitive`,`queryParamsMode`,`queryParams`,`urlParamsEncoding`,`allowNotFound`,`rewritePathOnMatch`,`logger`,`limits`]),O={maxDependencies:{min:0,max:1e4},maxPlugins:{min:0,max:1e3},maxListeners:{min:0,max:1e5},warnListeners:{min:0,max:1e5},maxLifecycleHandlers:{min:0,max:1e4}};function Ze(e,t,n){if(typeof t!=`number`||!Number.isInteger(t))throw TypeError(`[router.${n}] limit "${e}" must be an integer, got ${String(t)}`);let r=O[e];if(t<r.min||t>r.max)throw RangeError(`[router.${n}] limit "${e}" must be between ${r.min} and ${r.max}, got ${t}`)}function Qe(e,t){if(!e||typeof e!=`object`||e.constructor!==Object)throw TypeError(`[router.${t}] invalid limits: expected plain object, got ${typeof e}`);for(let[n,r]of T(e)){if(!Je(O,n))throw TypeError(`[router.${t}] unknown limit: "${n}"`);r!==void 0&&Ze(n,r,t)}let{warnListeners:n,maxListeners:r}=e;if(typeof n==`number`&&typeof r==`number`&&r>0&&n>r)throw RangeError(`[router.${t}] "limits.warnListeners" (${n}) must not exceed "limits.maxListeners" (${r}) — the warning channel would be unreachable`)}function k(e,t,n,r){if(e!==void 0&&(typeof e!=`string`||!n.includes(e))){let i=n.map(e=>`"${e}"`).join(`, `);throw TypeError(`[router.${r}] Invalid "${t}": "${typeof e==`string`?e:`(${typeof e})`}". Must be one of: ${i}`)}}function $e(e,t){if(e!==void 0&&typeof e!=`string`&&typeof e!=`function`)throw TypeError(`[router.${t}] Invalid "defaultRoute": expected string or function, got ${typeof e}`)}function A(e,t,n){if(e!==void 0&&typeof e!=`function`&&(!e||typeof e!=`object`||Array.isArray(e)||e.constructor!==Object))throw TypeError(`[router.${n}] Invalid "${t}": expected plain object or function, got ${typeof e}`)}function et(e,t){if(e===void 0)return;if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`[router.${t}] Invalid "queryParams": expected plain object`);let n=e;for(let[e,r]of T(n)){if(!d(e,D))throw TypeError(`[router.${t}] Invalid "queryParams.${e}": unknown option`);k(r,`queryParams.${e}`,D[e],t)}}function tt(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`[router.${t}] Invalid options: expected plain object`);let n=e;for(let e of Ye(n))if(!Xe.has(e))throw TypeError(`[router.${t}] Unknown option: "${e}"`);if($e(n.defaultRoute,t),A(n.defaultParams,`defaultParams`,t),A(n.defaultSearch,`defaultSearch`,t),k(n.trailingSlash,`trailingSlash`,E.trailingSlash,t),k(n.queryParamsMode,`queryParamsMode`,E.queryParamsMode,t),k(n.urlParamsEncoding,`urlParamsEncoding`,E.urlParamsEncoding,t),n.allowNotFound!==void 0&&typeof n.allowNotFound!=`boolean`)throw TypeError(`[router.${t}] Invalid "allowNotFound": expected boolean, got ${typeof n.allowNotFound}`);if(n.rewritePathOnMatch!==void 0&&typeof n.rewritePathOnMatch!=`boolean`)throw TypeError(`[router.${t}] Invalid "rewritePathOnMatch": expected boolean, got ${typeof n.rewritePathOnMatch}`);if(n.caseSensitive!==void 0&&typeof n.caseSensitive!=`boolean`)throw TypeError(`[router.${t}] Invalid "caseSensitive": expected boolean, got ${typeof n.caseSensitive}`);et(n.queryParams,t),n.limits!==void 0&&Qe(n.limits,t)}const nt=Object.hasOwn,j=`router.usePlugin`,rt={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function it(e,t,n=s.maxPlugins){if(n!==0&&e+t>n)throw RangeError(`[router.usePlugin] Plugin limit exceeded (${n}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating plugins.`)}function at(e,t){if(t.includes(e))throw Error(`[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.`)}function ot(e,t,n){if(t===0)return;let{warn:r,error:i}=c(t);e>=i?n.error(j,`${e} plugins registered! This is excessive. Hard limit at ${t}.`):e>=r&&n.warn(j,`${e} plugins registered. Consider if all are necessary.`)}function st(e){for(let t in e)if(!(t===`teardown`||nt(rt,t)))throw TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}function ct(e){e.warn(j,`Duplicate factory in batch, will be registered once`)}function lt(e,t){t.warn(j,`Property '${e}' is not a function, skipping`)}function ut(e,t){e===`onStart`&&t.warn(j,`Router already started, onStart will not be called`)}const M=Object.entries,dt=Object.getOwnPropertyDescriptor,N=Object.keys;function P(e,t){if(!e||typeof e!=`object`)throw TypeError(`[validation-plugin] ${t}: store must be an object`);let n=e;if(!Array.isArray(n.definitions))throw TypeError(`[validation-plugin] ${t}: store.definitions must be an array`);if(!n.config||typeof n.config!=`object`)throw TypeError(`[validation-plugin] ${t}: store.config must be an object`);if(!n.tree||typeof n.tree!=`object`)throw TypeError(`[validation-plugin] ${t}: store.tree must be an object`);return n}function F(e,t,n=``){for(let r of e){let e=n?`${n}.${r.name}`:r.name;t(r,e),r.children&&F(r.children,t,e)}}function I(e,t){let n=t.split(`.`),r=e;for(let e of n)if(r=r.children.get(e),!r)return!1;return!0}function ft(e,t){try{return n(e,t)}catch(e){throw Error(`[validation-plugin] ${e.message}`,{cause:e})}}function L(e){let t=new Set;for(let n of e)for(let e of n.paramMeta.urlParams)t.add(e);return t}function R(e,t,n){let r=e;if(r.constructor.name===`AsyncFunction`||r.toString().includes(`__awaiter`))throw TypeError(`[validation-plugin] Route "${n}" ${t} cannot be async`)}function pt(e){F(P(e,`validateExistingRoutes`).definitions,(e,t)=>{if(typeof e.name!=`string`||!e.name)throw TypeError(`[validation-plugin] validateExistingRoutes: route has invalid name: ${e.name}`);if(typeof e.path!=`string`)throw TypeError(`[validation-plugin] validateExistingRoutes: route "${t}" has non-string path (${typeof e.path})`)})}function mt(e){let{config:t,tree:n,matcher:r}=P(e,`validateForwardToConsistency`);for(let[e,i]of M(t.forwardMap)){if(!I(n,i))throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${i}" does not exist in tree (source route: "${e}")`);let t=r.getSegmentsByName(e),a=r.getSegmentsByName(i);if(t&&a){let n=L(t),r=[...L(a)].filter(e=>!n.has(e));if(r.length>0)throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${i}" requires params [${r.join(`, `)}] not available in source route "${e}"`)}}for(let e of N(t.forwardMap))ft(e,t.forwardMap)}function z(e,t){for(let[n,r]of M(e))if(typeof r!=`object`||!r||Array.isArray(r))throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${n}" ${t} must be a plain object, got ${Array.isArray(r)?`array`:typeof r}`)}function ht(e){let{config:t}=P(e,`validateRoutePropertiesStore`);for(let[e,n]of M(t.decoders)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" decoder must be a function, got ${typeof n}`);R(n,`decoder`,e)}for(let[e,n]of M(t.encoders)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" encoder must be a function, got ${typeof n}`);R(n,`encoder`,e)}z(t.defaultParams,`defaultParams`),z(t.defaultSearch,`defaultSearch`);for(let[e,n]of M(t.forwardFnMap)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" forwardTo callback must be a function, got ${typeof n}`);R(n,`forwardTo callback`,e)}}function gt(e){let{config:t,tree:n}=P(e,`validateForwardToTargetsStore`);for(let[e,r]of M(t.forwardMap))if(!I(n,r))throw Error(`[validation-plugin] validateForwardToTargetsStore: forwardTo target "${r}" does not exist for route "${e}"`)}function _t(e){if(!e||typeof e!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps must be an object`);let t=e;if(!t.dependencies||typeof t.dependencies!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.dependencies must be an object`);let n=t.dependencies;for(let e of N(n))if(dt(n,e)?.get)throw TypeError(`[validation-plugin] validateDependenciesStructure: dependency "${e}" must not use a getter`);if(!t.limits||typeof t.limits!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits must be an object`);let r=t.limits;for(let e of[`maxDependencies`,`maxPlugins`,`maxListeners`,`warnListeners`,`maxLifecycleHandlers`])if(!Number.isInteger(r[e]))throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits.${e} must be an integer, got ${String(r[e])}`)}function vt(e){let t=e&&typeof e==`object`?e:{};return t.limits&&typeof t.limits==`object`?t.limits:{}}function yt(e,t){if(!e||typeof e!=`object`)return;let n=e,r=n.dependencies,i=n.limits;if(!r||typeof r!=`object`||!i||typeof i!=`object`)return;let a=N(r).length,o=i,s=t.maxDependencies,c=o.maxDependencies,l=typeof s==`number`?s:c;if(typeof l==`number`&&l>0&&a>l)throw RangeError(`[validation-plugin] validateLimitsConsistency: dependency count (${a}) exceeds maxDependencies limit (${l})`)}function bt(e,t){yt(t,vt(e))}function B(e,t){if(typeof e==`string`&&e&&!I(P(t,`validateResolvedDefaultRoute`).tree,e))throw Error(`[validation-plugin] defaultRoute resolved to non-existent route: "${e}"`)}const xt=Object.keys;function St(e,t){if(e!==void 0){if(typeof e!=`string`&&typeof e!=`function`)throw TypeError(`[router.addRoute] forwardTo must be a string or function for route "${t}", got ${y(e)}`);if(typeof e==`function`){let n=e.constructor.name===`AsyncFunction`,r=e.toString().includes(`__awaiter`);if(n||r)throw TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${t}". Async functions break matchPath/buildPath.`)}}}function V(e,t,n){if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))throw TypeError(`[router.addRoute] ${t} must be an object for route "${n}", got ${y(e)}`)}function H(e,t){if(e.canActivate!==void 0&&typeof e.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function for route "${t}", got ${y(e.canActivate)}`);if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${y(e.canDeactivate)}`);if(V(e.defaultParams,`defaultParams`,t),V(e.defaultSearch,`defaultSearch`,t),e.decodeParams?.constructor.name===`AsyncFunction`)throw TypeError(`[router.addRoute] decodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if(e.encodeParams?.constructor.name===`AsyncFunction`)throw TypeError(`[router.addRoute] encodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if(St(e.forwardTo,t),e.children)for(let n of e.children)H(n,`${t}.${n.name}`)}function Ct(e){let t=new Set,n=/[*:]([A-Z_a-z]\w*)/g,r;for(;(r=n.exec(e))!==null;)t.add(r[1]);return t}function U(e){let t=new Set;for(let n of e)for(let e of Ct(n))t.add(e);return t}function W(e,t,n=``,r=[]){for(let i of e){let e=n?`${n}.${i.name}`:i.name,a=[...r,i.path];if(e===t)return a;if(i.children&&t.startsWith(`${e}.`))return W(i.children,t,e,a)}throw Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function G(e,t=``){let n=new Set;for(let r of e){let e=t?`${t}.${r.name}`:r.name;if(n.add(e),r.children)for(let t of G(r.children,e))n.add(t)}return n}function K(e,t=``){let n=new Map;for(let r of e){let e=t?`${t}.${r.name}`:r.name;if(r.forwardTo&&typeof r.forwardTo==`string`&&n.set(e,r.forwardTo),r.children)for(let[t,i]of K(r.children,e))n.set(t,i)}return n}function q(e){let t=new Set;for(let n of e)for(let e of n.paramMeta.urlParams)t.add(e);return t}function wt(e,t,n,r){return t?q(n.getSegmentsByName(e)??[]):U(W(r,e))}const Tt=new Set;function Et(e,t,n,r,i,a){let o=i.hasRoute(t),s=r.has(t);if(!o&&!s)throw ReferenceError(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);let c=new Set([...a,...U(W(n,e))]),l=[...wt(t,o,i,n)].filter(e=>!c.has(e));if(l.length>0)throw Error(`[router.addRoute] forwardTo target "${t}" requires params [${l.join(`, `)}] that are not available in source route "${e}"`)}function Dt(e,t,r,a){let o=G(e),s=a?new Set([...o].map(e=>`${a}.${e}`)):o,c=a?q(r.getSegmentsByName(a)):Tt,l=K(e),u={...t};for(let[e,t]of l)i(u,e,t);for(let[t,n]of l)Et(t,n,e,s,r,c);for(let e of xt(u))n(e,u)}function J(e,t){if(e.startsWith(`@@`))throw Error(`[router.${t}] Route name "${e}" uses the reserved "@@" prefix. Routes with this prefix are internal and cannot be modified through the public API.`)}function Y(e,t){for(let n of e)n&&typeof n==`object`&&typeof n.name==`string`&&(J(n.name,t),n.children&&Y(n.children,t))}function Ot(e){v(e,`removeRoute`)}function kt(e){if(typeof e!=`string`)throw TypeError(`[router.setRootPath] rootPath must be a string, got ${y(e)}`)}function X(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function At(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function, got ${y(t.canActivate)}`);if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function, got ${y(t.canDeactivate)}`)}function jt(e){let t=e,n=t.name;if(t.decodeParams!==void 0&&X(t.decodeParams))throw TypeError(`[router.addRoute] decodeParams cannot be async for route "${String(n)}"`);if(t.encodeParams!==void 0&&X(t.encodeParams))throw TypeError(`[router.addRoute] encodeParams cannot be async for route "${String(n)}"`);if(typeof t.forwardTo==`function`&&X(t.forwardTo))throw TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${String(n)}"`)}function Mt(e){for(let t of e){if(typeof t!=`object`||!t||Array.isArray(t))throw TypeError(`[router.addRoute] Route must be an object, got ${y(t)}`);H(t,t.name)}}function Nt(e){if(typeof e!=`string`||e===``)throw TypeError(`[router.addRoute] parent option must be a non-empty string, got ${y(e)}`);v(e,`addRoute`)}function Pt(e,t,n,r){if(!l(e))throw TypeError(`[router.isActiveRoute] name must be a string, got ${typeof e}`);if(t!==void 0&&!m(t))throw TypeError(`[router.isActiveRoute] params must be a plain object, got ${y(t)}`);if(n!==void 0&&typeof n!=`boolean`)throw TypeError(`[router.isActiveRoute] strictEquality must be a boolean, got ${typeof n}`);if(r!==void 0&&typeof r!=`boolean`)throw TypeError(`[router.isActiveRoute] ignoreQueryParams must be a boolean, got ${typeof r}`)}function Ft(e,t,n){if(!l(e))throw TypeError(`[router.${n}] Invalid routeName: ${y(e)}. Expected string.`);if(!m(t))throw TypeError(`[router.${n}] Invalid routeParams: ${y(t)}. Expected plain object.`)}function It(e,t){if(v(e,`updateRoute`),e===``)throw ReferenceError(`[router.updateRoute] Invalid name: empty string. Cannot update root node.`);if(t===null)throw TypeError(`[router.updateRoute] updates must be an object, got null`);if(typeof t!=`object`||Array.isArray(t))throw TypeError(`[router.updateRoute] updates must be an object, got ${y(t)}`)}function Z(e,t){if(e.constructor.name===`AsyncFunction`||e.toString().includes(`__awaiter`))throw TypeError(`[router.updateRoute] ${t} cannot be an async function`)}function Q(e,t){if(e!=null){if(typeof e!=`function`)throw TypeError(`[router.updateRoute] ${t} must be a function or null, got ${typeof e}`);Z(e,t)}}function Lt(e){let{forwardTo:t,defaultParams:n,defaultSearch:r,decodeParams:i,encodeParams:a,canActivate:o,canDeactivate:s}=e;if(t!=null){if(typeof t!=`string`&&typeof t!=`function`)throw TypeError(`[router.updateRoute] forwardTo must be a string, function, or null, got ${y(t)}`);typeof t==`function`&&Z(t,`forwardTo callback`)}$(n,`defaultParams`),$(r,`defaultSearch`),Q(i,`decodeParams`),Q(a,`encodeParams`),Q(o,`canActivate`),Q(s,`canDeactivate`)}function $(e,t){if(e!=null&&(typeof e!=`object`||Array.isArray(e)))throw TypeError(`[router.updateRoute] ${t} must be an object or null, got ${y(e)}`)}function Rt(e){if(!l(e)||e===``)throw TypeError(`[router.buildPath] route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`)}function zt(e){if(!l(e))throw TypeError(`[router.matchPath] path must be a string, got ${typeof e}`)}function Bt(e){if(!l(e))throw TypeError(`[router.shouldUpdateNode] nodeName must be a string, got ${typeof e}`)}function Vt(e,t,n,r,i){if(i&&t){let e=t;for(let t of i.split(`.`))if(e=e.children.get(t),!e)throw ReferenceError(`[router.addRoute] Parent route "${i}" does not exist`)}let a=new Set,s=new Map;for(let n of e)o(n,`addRoute`,t,i??``,a,s);n&&r&&Dt(e,r,n,i)}function Ht(e){let t=new Set;for(let n of e)for(let e of n.paramMeta.urlParams)t.add(e);return t}function Ut(e,t,n){let r=n.getSegmentsByName(e),i=n.getSegmentsByName(t),a=Ht(r),o=[];for(let e of i)for(let t of e.paramMeta.urlParams)o.push(t);let s=o.filter(e=>!a.has(e));if(s.length>0)throw Error(`[router.addRoute] forwardTo target "${t}" requires params [${s.join(`, `)}] that are not available in source route "${e}"`)}function Wt(e,t,r){let i={...r.forwardMap,[e]:t};n(e,i)}function Gt(e,t,n,r,i){if(!n(e))throw ReferenceError(`[router.updateRoute] route "${e}" does not exist`);if(t!=null&&typeof t==`string`){if(!n(t))throw Error(`[router.updateRoute] forwardTo target "${t}" does not exist`);Ut(e,t,r),Wt(e,t,i)}}function Kt(e,t,n){if(!l(e))throw TypeError(`[router.makeState] Invalid name: ${y(e)}. Expected string.`);if(t!==void 0&&!m(t))throw TypeError(`[router.makeState] Invalid params: ${y(t)}. Expected plain object.`);if(n!==void 0&&!l(n))throw TypeError(`[router.makeState] Invalid path: ${y(n)}. Expected string.`)}function qt(){let e=new Set;return function(t,n){let r=`${t} ${n}`;e.has(r)||(e.add(r),console.warn(`[router] Query key "${n}" is not declared on route "${t}" (\`?${n}\`), so the current \`queryParamsMode\` will not print it — it was dropped from \`state.search\` rather than published beside a \`state.path\` that cannot show it. Declare it on the route path, or use \`queryParamsMode: "loose"\` to keep undeclared keys. A \`defaultSearch\` entry for "${n}" is dead config in this mode for the same reason.`))}}function Jt(){let e=new Set;return function(t,n){let r=`${t} ${n}`;e.has(r)||(e.add(r),console.warn(`[router] Param "${n}" is declared nowhere on route "${t}" — neither as a path slot (:${n}) nor as a query param (?${n}), so it stays in state.params but never reaches the URL. The state will not round-trip: matchPath(state.path) cannot recover it. Declare it on the route path if it belongs in the URL, or pass it through the search channel; keep it here only if it is deliberately app-level data.`))}}function Yt(e,t){return{routes:{validateBuildPathArgs:Rt,validateMatchPathArgs:zt,validateIsActiveRouteArgs:Pt,validateShouldUpdateNodeArgs:Bt,validateStateBuilderArgs:Ft,validateAddRouteArgs(e){Mt(e)},validateRoutes(e,t,n){let r=t;Vt(e,r.tree,r.matcher,r.config?.forwardMap,n)},validateRemoveRouteArgs:Ot,validateUpdateRouteBasicArgs:It,validateUpdateRoutePropertyTypes(e,t){let n=t;Lt({forwardTo:n.forwardTo,defaultParams:n.defaultParams,defaultSearch:n.defaultSearch,decodeParams:n.decodeParams,encodeParams:n.encodeParams,canActivate:n.canActivate,canDeactivate:n.canDeactivate})},validateUpdateRoute(e,t,n){let r=n,i=t.forwardTo;Gt(e,i,e=>r.matcher.hasRoute(e),r.matcher,r.config)},validateParentOption(e,t){Nt(e);let n=t;for(let t of e.split(`.`)){let r=n.children.get(t);if(!r)throw ReferenceError(`[router.addRoute] Parent route "${e}" does not exist`);n=r}},validateRouteName(e,t){v(e,t)},throwIfInternalRoute(e,t){J(e,t)},throwIfInternalRouteInArray(e,t){Y(e,t)},validateSetRootPathArgs:kt,guardRouteCallbacks:At,guardNoAsyncCallbacks:jt},options:{validateOptions:tt,validateResolvedDefaultRoute:B},dependencies:{validateDependencyName:be,validateSetDependencyArgs(e,t,n){xe(e)},validateDependenciesObject:Se,validateDependencyExists(e,t){let n=t.dependencies?.[e];Ce(n,e)},validateDependencyCount(t,n){we(t,n,e.logger)},validateCloneArgs:Te,warnOverwrite(t,n){Ee(t,n,e.logger)},warnBatchOverwrite(t,n){De(t,n,e.logger)},warnRemoveNonExistent(t){Oe(t,e.logger)}},plugins:{validatePluginLimit(e,t){it(e,1,t?.maxPlugins)},validateNoDuplicatePlugins:at,validatePluginKeys:st,validateCountThresholds(t){ot(t,e.getOptions().limits?.maxPlugins??s.maxPlugins,e.logger)},warnBatchDuplicates(){ct(e.logger)},warnPluginMethodType(t){lt(t,e.logger)},warnPluginAfterStart(t){ut(t,e.logger)}},lifecycle:{validateHandler:Pe,validateHandlerLimit(t,n){Fe(t,n,e.getOptions().limits?.maxLifecycleHandlers??s.maxLifecycleHandlers)},validateCountThresholds(t,n){Ie(t,n,e.getOptions().limits?.maxLifecycleHandlers??s.maxLifecycleHandlers,e.logger)},warnOverwrite(t,n,r){Le(t,n,r,e.logger)},warnAsyncGuardSync(t,n){Re(t,n,e.logger)}},navigation:{validateNavigateArgs:Be,validateNavigateToDefaultArgs(n){Ve(n),t.check(e.logger)},validateNavigateToStateArgs:He,validateNavigationOptions:Ue,validateParams:Ge,validateSearch:Ke,validateStartArgs:qe},state:{validateMakeStateArgs:Kt,reportDroppedQueryKey:qt(),reportUndeclaredParamKey:Jt(),validateAreStatesEqualArgs(e,t,n){if(!_(e))throw TypeError(`[router.areStatesEqual] Invalid state1: ${y(e)}. Expected State object.`);if(!_(t))throw TypeError(`[router.areStatesEqual] Invalid state2: ${y(t)}. Expected State object.`);if(n!==void 0&&!u(n))throw TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${y(n)}. Expected boolean.`)}},eventBus:{validateListenerArgs(e,t){Me(e,t)},validateCountThresholds(t,n,r){let i=e.getOptions().limits?.maxListeners??s.maxListeners;Ne(t,n,r,e.logger,i)}}}}function Xt(){return t=>{let n=a(t);if(t.isActive())throw r(new e(`VALIDATION_PLUGIN_AFTER_START`,{message:`validation-plugin must be registered before router.start()`}));let i=new _e;i.watch(n.getAdoptedOrigins()),n.validator=Yt(n,i);try{let e=n.routeGetStore(),t=n.dependenciesGetStore(),r=n.getOptions();pt(e),mt(e),ht(e),gt(e),_t(t),bt(r,t),n.validator.options.validateOptions(r,`constructor (retrospective)`),typeof r.defaultRoute==`string`&&B(r.defaultRoute,e)}catch(e){throw n.validator=null,e}return{teardown(){n.validator=null}}}}export{Xt as validationPlugin};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|