@real-router/validation-plugin 0.25.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/validationPlugin.ts"],"mappings":";;;;;;;;;;;;;;;;wBAobgB,iBACd,qBAAqB,sBAAsB,wBACxC,cAAc"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/validationPlugin.ts"],"mappings":";;;;;;;;;;;;;;;;wBAyXgB,iBACd,qBAAqB,sBAAsB,wBACxC,cAAc"}
@@ -1,2 +1,2 @@
1
- import{RouterError as e,events as t,resolveForwardChain as n}from"@real-router/core";import{getPluginApi as r,getRoutesApi as i}from"@real-router/core/api";import{freezeThrownError as a,putField as o}from"@real-router/core/utils";import{findMisChanneledKey as s,getInternals as c,validateRoute as l}from"@real-router/core/validation";const u=Object.freeze({maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxLifecycleHandlers:200});function d(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}function f(e){return typeof e==`string`}function p(e){return typeof e==`boolean`}function m(e,t){return e in t}const h=Object.getPrototypeOf,ee=Object.values,g=Object.hasOwn;function _(e){if(Array.isArray(e))return!0;let t=h(e);return t===null||t===Object.prototype}function te(e,t){let n=Array.isArray(e)?e:ee(e);for(let e of n)t.push(e)}function ne(e){let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}var v=class{container;constructor(e){this.container=e}};function re(e,t,n,r){return n.has(e)?!1:r.has(e)?!0:_(e)?(n.add(e),t.push(new v(e)),te(e,t),!0):!1}function ie(e){let t=[e],n=new WeakSet,r=new WeakSet;for(;t.length>0;){let e=t.pop();if(e instanceof v){n.delete(e.container),r.add(e.container);continue}if(e!=null){if(typeof e==`object`){if(!re(e,t,n,r))return!1;continue}if(!ne(e))return!1}}return!0}function ae(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}function y(e){try{return oe(e)}catch{return!1}}function oe(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=h(e);if(t!==null&&t!==Object.prototype)return!1;let n=!1;for(let t in e){if(!g(e,t))continue;let r=e[t];if(!ae(r)){let e=typeof r;if(e===`function`||e===`symbol`)return!1;n=!0;break}}return!n||ie(e)}const se=[`replace`,`reload`,`force`,`forceDeactivate`,`redirected`,`revalidate`];function ce(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;for(let e of se){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 le=/\S/,ue=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function b(e,t){return TypeError(`[router.${e}] ${t}`)}function de(e){return typeof e==`string`?e===``?!0:e.length>1e4?!1:e.startsWith(`@@`)?!0:ue.test(e):!1}function fe(e){return de(e.name)&&typeof e.path==`string`&&y(e.params)}function pe(e){return typeof e!=`object`||!e?!1:fe(e)}function x(e,t){if(typeof e!=`string`)throw b(t,`Route name must be a string, got ${typeof e}`);if(e!==``){if(!le.test(e))throw b(t,`Route name cannot contain only whitespace`);if(e.length>1e4)throw b(t,`Route name exceeds maximum length of 10000 characters. This is a technical safety limit.`);if(!e.startsWith(`@@`)&&!ue.test(e))throw b(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 S(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 C=Object.entries,me=[`defaultParams`,`defaultSearch`],he=e=>new Map(C(e)),ge=(e,t)=>{let n=C(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 w=Object.keys,T=Object.getOwnPropertyDescriptor,ve=Object.getPrototypeOf,ye=Object;function E(e){if(!e||typeof e!=`object`||Array.isArray(e))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(!E(e))throw TypeError(`[router.${t}] Invalid argument: expected plain object, received ${S(e)}`);for(let n of w(e))if(T(e,n)?.get)throw TypeError(`[router.${t}] Getters not allowed: "${n}"`)}function Ce(e,t,n,r){if(n===0)return;let i=new Set(t),a=0;for(let t of w(e))i.has(t)||(a+=1);let o=t.length;if(o+a>n)throw RangeError(`[router.${r}] Dependency limit exceeded (${n}). Current: ${o}, this batch adds ${a}.`)}function we(e,t){if(e===void 0)throw ReferenceError(`[router.getDependency] dependency "${t}" not found`)}function Te(e,t,n,r){if(t===0)return;let{warn:i,error:a}=d(t);if(e>=t)throw RangeError(`[router.${n}] Dependency limit exceeded (${t}). Current: ${e}.`);e===a?r.error(`router.${n}`,`${e} dependencies registered! This indicates architectural problems. Hard limit at ${t}.`):e===i&&r.warn(`router.${n}`,`${e} dependencies registered. Consider if all are necessary.`)}function Ee(e){if(e!==void 0){if(!E(e))throw TypeError(`[cloneRouter] Invalid dependencies: expected plain object or undefined, received ${typeof e}`);for(let t of w(e))if(T(e,t)?.get)throw TypeError(`[cloneRouter] Getters not allowed in dependencies: "${t}"`)}}function De(e,t,n){n.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function Oe(e,t,n){n.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function ke(e,t){t.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const Ae=Object.values,je=new Set(Ae(t));function Me(e){if(!je.has(e))throw TypeError(`[router.addEventListener] Invalid event name: ${String(e)}. Must be one of: $start, $stop, $$start, $$leaveApprove, $$cancel, $$success, $$error`)}function Ne(e,t){if(Me(e),typeof t!=`function`)throw TypeError(`[router.addEventListener] callback must be a function, got ${typeof t}`)}function Pe(e,t,n,r,i=u.maxListeners){if(i===0)return;let{warn:a,error:o}=d(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 Fe(e,t){if(!p(e)&&typeof e!=`function`)throw TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${S(e)}`)}function Ie(e,t,n=u.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 Le(e,t,n,r){if(n===0)return;let{warn:i,error:a}=d(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 Re(e,t,n,r){r.warn(`router.${n}`,`Overwriting existing ${t} handler for route "${e}"`)}function ze(e,t,n){n.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}const Be=Object.hasOwn,Ve=Object.getPrototypeOf;function He(e){if(typeof e!=`string`)throw TypeError(`[router.navigate] Invalid route name: expected string, got ${S(e)}`)}function Ue(e){if(e!==void 0&&(typeof e!=`object`||!e))throw TypeError(`[router.navigateToDefault] Invalid options: ${S(e)}. Expected NavigationOptions object.`)}function We(e){if(typeof e!=`object`||!e)throw TypeError(`[router.navigateToState] Invalid state: ${S(e)}. Expected State object.`);let t=e;if(!f(t.name))throw TypeError(`[router.navigateToState] Invalid state.name: ${S(t.name)}. Expected string.`);if(!y(t.params))throw TypeError(`[router.navigateToState] Invalid state.params: ${S(t.params)}. Expected plain object.`);if(!f(t.path))throw TypeError(`[router.navigateToState] Invalid state.path: ${S(t.path)}. Expected string.`)}function D(e,t){if(!ce(e))throw TypeError(`[router.${t}] Invalid options: ${S(e)}. Expected NavigationOptions object.`)}const O=/[\u0000-\u001F\u007F]/;function Ge(e,t){for(let n in e){if(!Be(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`&&O.test(r))throw TypeError(`[router.${t}] param "${n}" must not contain control characters (NUL / C0 / DEL) — they corrupt the URL path.`)}}function k(e,t){if(e===void 0)return;let n=e!==null&&Ve(e);if(Array.isArray(e)||n!==null&&n!==Object.prototype)throw TypeError(`[router.${t}] params must be a plain object, got ${S(e)}`)}function A(e,t){if(e!==void 0&&(Ge(e,t),!y(e)))throw TypeError(`[router.${t}] params must be a plain object, got ${S(e)}`)}function j(e,t){if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))throw TypeError(`[router.${t}] search must be a plain object, got ${S(e)}`)}function Ke(e){if(e!==void 0&&typeof e!=`string`)throw TypeError(`[router.start] path must be a string, got ${S(e)}.`);if(typeof e==`string`){if(O.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 qe=Object.entries,Je=Object.hasOwn,M=Object.keys,Ye=Object.getPrototypeOf,N={trailingSlash:[`strict`,`never`,`always`,`preserve`],queryParamsMode:[`default`,`strict`,`loose`],urlParamsEncoding:[`default`,`uri`,`uriComponent`,`none`]},Xe={arrayFormat:!0,booleanFormat:!0,nullFormat:!0,numberFormat:!0},Ze=new Set(M({defaultRoute:!0,defaultParams:!0,defaultSearch:!0,trailingSlash:!0,caseSensitive:!0,queryParamsMode:!0,queryParams:!0,urlParamsEncoding:!0,allowNotFound:!0,rewritePathOnMatch:!0,logger:!0,limits:!0})),P={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=P[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 F(e){let t=Ye(e);return t===null||t===Object.prototype}function $e(e,t){if(!e||typeof e!=`object`||!F(e))throw TypeError(`[router.${t}] invalid limits: expected plain object, got ${typeof e}`);for(let[n,r]of qe(e)){if(!Je(P,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 I(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 et(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 L(e,t,n){if(e!==void 0&&typeof e!=`function`&&(!e||typeof e!=`object`||Array.isArray(e)||!F(e)))throw TypeError(`[router.${n}] Invalid "${t}": expected plain object or function, got ${typeof e}`)}function tt(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 of M(n))if(!m(e,Xe))throw TypeError(`[router.${t}] Invalid "queryParams.${e}": unknown option`)}function nt(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 M(n))if(!Ze.has(e))throw TypeError(`[router.${t}] Unknown option: "${e}"`);if(et(n.defaultRoute,t),L(n.defaultParams,`defaultParams`,t),L(n.defaultSearch,`defaultSearch`,t),I(n.trailingSlash,`trailingSlash`,N.trailingSlash,t),I(n.queryParamsMode,`queryParamsMode`,N.queryParamsMode,t),I(n.urlParamsEncoding,`urlParamsEncoding`,N.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}`);tt(n.queryParams,t),n.limits!==void 0&&$e(n.limits,t)}const rt=Object.hasOwn,R=`router.usePlugin`,it={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function at(e,t,n=u.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 ot(e,t){if(t.includes(e))throw Error(`[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.`)}function st(e,t,n){if(t===0)return;let{warn:r,error:i}=d(t);e>=i?n.error(R,`${e} plugins registered! This is excessive. Hard limit at ${t}.`):e>=r&&n.warn(R,`${e} plugins registered. Consider if all are necessary.`)}function ct(e){for(let t in e)if(!(t===`teardown`||rt(it,t)))throw TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}function lt(e){e.warn(R,`Duplicate factory in batch, will be registered once`)}function ut(e,t){t.warn(R,`Property '${e}' is not a function, skipping`)}function dt(e,t){e===`onStart`&&t.warn(R,`Router already started, onStart will not be called`)}const z=Object.entries,ft=Object.getOwnPropertyDescriptor,B=Object.keys;function V(e,t,n=``){for(let r of e){let e=n?`${n}.${r.name}`:r.name;t(r,e),r.children&&V(r.children,t,e)}}function H(e,t){let n=[];return V(e,(e,r)=>{let i=t(e);i!==void 0&&n.push([r,i])}),n}function pt(e,t){try{return n(e,t)}catch(e){throw Error(`[validation-plugin] ${e.message}`,{cause:e})}}function U(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 mt(e){V(e,(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 ht(e,t){for(let[n,r]of z(e)){if(!t.hasRoute(r))throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${r}" does not exist in tree (source route: "${n}")`);let e=new Set(t.getUrlParams(n)),i=[...new Set(t.getUrlParams(r))].filter(t=>!e.has(t));if(i.length>0)throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${r}" requires params [${i.join(`, `)}] not available in source route "${n}"`)}for(let t of B(e))pt(t,e)}function W(e,t){for(let[n,r]of 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 gt(e){let t=H(e,e=>e.decodeParams),n=H(e,e=>e.encodeParams),r=H(e,e=>typeof e.forwardTo==`string`?void 0:e.forwardTo);for(let[e,n]of t){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" decoder must be a function, got ${typeof n}`);U(n,`decoder`,e)}for(let[e,t]of n){if(typeof t!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" encoder must be a function, got ${typeof t}`);U(t,`encoder`,e)}W(H(e,e=>e.defaultParams),`defaultParams`),W(H(e,e=>e.defaultSearch),`defaultSearch`);for(let[e,t]of r){if(typeof t!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" forwardTo callback must be a function, got ${typeof t}`);U(t,`forwardTo callback`,e)}}function _t(e,t){for(let[n,r]of z(e))if(!t.hasRoute(r))throw Error(`[validation-plugin] validateForwardToTargetsStore: forwardTo target "${r}" does not exist for route "${n}"`)}function vt(e,t){for(let t of B(e))if(ft(e,t)?.get)throw TypeError(`[validation-plugin] validateDependenciesStructure: dependency "${t}" must not use a getter`);for(let[e,n]of z(t))if(!Number.isInteger(n))throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits.${e} must be an integer, got ${String(n)}`)}function yt(e,t,n){let r=e&&typeof e==`object`?e:{},i=(r.limits&&typeof r.limits==`object`?r.limits:{}).maxDependencies,a=typeof i==`number`?i:n;if(a>0&&t>a)throw RangeError(`[validation-plugin] validateLimitsConsistency: dependency count (${t}) exceeds maxDependencies limit (${a})`)}function G(e,t){if(typeof e==`string`&&e&&!t.hasRoute(e))throw Error(`[validation-plugin] defaultRoute resolved to non-existent route: "${e}"`)}function bt(e,t,n){for(let r of e)t.hasRoute(r)||n.warn(`router.start`,`Guard registered for route "${r}", which the route tree does not contain. It will never run unless that route is added. Check the name for a typo.`)}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 ${S(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 K(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 ${S(e)}`)}function q(e,t){if(e.canActivate!==void 0&&typeof e.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function for route "${t}", got ${S(e.canActivate)}`);if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${S(e.canDeactivate)}`);if(K(e.defaultParams,`defaultParams`,t),K(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)q(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 J(e){let t=new Set;for(let n of e)for(let e of Ct(n))t.add(e);return t}function Y(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 Y(i.children,t,e,a)}throw Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function X(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 X(r.children,e))n.add(t)}return n}function Z(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 Z(r.children,e))n.set(t,i)}return n}function wt(e,t,n,r){return t?new Set(n.getUrlParams(e)):J(Y(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,...J(Y(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,i){let a=X(e),s=i?new Set([...a].map(e=>`${i}.${e}`)):a,c=i?new Set(r.getUrlParams(i)):Tt,l=Z(e),u={...t};for(let[e,t]of l)o(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 Ot(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 kt(e,t){for(let n of e)n&&typeof n==`object`&&typeof n.name==`string`&&(Ot(n.name,t),n.children&&kt(n.children,t))}function At(e){x(e,`removeRoute`)}function jt(e){if(typeof e!=`string`)throw TypeError(`[router.setRootPath] rootPath must be a string, got ${S(e)}`)}function Q(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function Mt(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function, got ${S(t.canActivate)}`);if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function, got ${S(t.canDeactivate)}`)}function Nt(e){let t=e,n=t.name;if(t.decodeParams!==void 0&&Q(t.decodeParams))throw TypeError(`[router.addRoute] decodeParams cannot be async for route "${String(n)}"`);if(t.encodeParams!==void 0&&Q(t.encodeParams))throw TypeError(`[router.addRoute] encodeParams cannot be async for route "${String(n)}"`);if(typeof t.forwardTo==`function`&&Q(t.forwardTo))throw TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${String(n)}"`)}function Pt(e){for(let t of e){if(typeof t!=`object`||!t||Array.isArray(t))throw TypeError(`[router.addRoute] Route must be an object, got ${S(t)}`);q(t,t.name)}}function Ft(e){if(typeof e!=`string`||e===``)throw TypeError(`[router.addRoute] parent option must be a non-empty string, got ${S(e)}`);x(e,`addRoute`)}function It(e,t,n,r){if(!f(e))throw TypeError(`[router.isActiveRoute] name must be a string, got ${typeof e}`);if(k(t,`isActiveRoute`),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 Lt(e,t,n){if(!f(e))throw TypeError(`[router.${n}] Invalid routeName: ${S(e)}. Expected string.`);if(!y(t))throw TypeError(`[router.${n}] Invalid routeParams: ${S(t)}. Expected plain object.`)}function Rt(e,t){if(x(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 ${S(t)}`)}function zt(e,t){if(e.constructor.name===`AsyncFunction`||e.toString().includes(`__awaiter`))throw TypeError(`[router.updateRoute] ${t} cannot be an async function`)}function $(e,t){if(e!=null){if(typeof e!=`function`)throw TypeError(`[router.updateRoute] ${t} must be a function or null, got ${typeof e}`);zt(e,t)}}function Bt(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 ${S(t)}`);typeof t==`function`&&zt(t,`forwardTo callback`)}Vt(n,`defaultParams`),Vt(r,`defaultSearch`),$(i,`decodeParams`),$(a,`encodeParams`),$(o,`canActivate`),$(s,`canDeactivate`)}function Vt(e,t){if(e!=null&&(typeof e!=`object`||Array.isArray(e)))throw TypeError(`[router.updateRoute] ${t} must be an object or null, got ${S(e)}`)}function Ht(e){if(!f(e)||e===``)throw TypeError(`[router.buildPath] route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`)}function Ut(e){let t=new Set;return function(n,r){let i=s(r,e(n));if(i===void 0)return;let a=`${n} ${i}`;t.has(a)||(t.add(a),console.warn(`[router] Route "${n}" declares \`${i}\` as a query param, but it was given in the \`params\` bag — the path channel. The URL is built without it, so the href does not match what you asked for; a plain click throws, but a ⌘-click, a copied link and server-rendered markup all follow the wrong URL in silence. Pass it in \`search\` instead.`))}}function Wt(e){if(!f(e))throw TypeError(`[router.matchPath] path must be a string, got ${typeof e}`)}function Gt(e){if(!f(e))throw TypeError(`[router.shouldUpdateNode] nodeName must be a string, got ${typeof e}`)}function Kt(e,t,n,r,i){if(i){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,o=new Map;for(let n of e)l(n,`addRoute`,t,i??``,a,o);Dt(e,r,n,i)}function qt(e,t,n){let r=new Set(n.getUrlParams(e)),i=n.getUrlParams(t).filter(e=>!r.has(e));if(i.length>0)throw Error(`[router.addRoute] forwardTo target "${t}" requires params [${i.join(`, `)}] that are not available in source route "${e}"`)}function Jt(e,t,r){let i={...r,[e]:t};n(e,i)}function Yt(e,t,n,r){if(!n.hasRoute(e))throw ReferenceError(`[router.updateRoute] route "${e}" does not exist`);if(t!=null&&typeof t==`string`){if(!n.hasRoute(t))throw Error(`[router.updateRoute] forwardTo target "${t}" does not exist`);qt(e,t,n),Jt(e,t,r)}}function Xt(e,t,n){if(!f(e))throw TypeError(`[router.makeState] Invalid name: ${S(e)}. Expected string.`);if(t!==void 0&&!y(t))throw TypeError(`[router.makeState] Invalid params: ${S(t)}. Expected plain object.`);if(n!==void 0&&!f(n))throw TypeError(`[router.makeState] Invalid path: ${S(n)}. Expected string.`)}function Zt(){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 Qt(){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 $t(e){return{hasRoute:t=>{let n=e.getTree();for(let e of t.split(`.`))if(n=n?.children.get(e),!n)return!1;return!0},getUrlParams:t=>e.getUrlParams(t)}}function en(e,t){let n=[];for(let r of e.getTree().children.keys())n.push(t.get(r));return n}function tn(e,t,n){let r=Ut(t=>e.getDeclaredQueryNames(t));return{routes:{validateBuildPathArgs(e,t){Ht(e),r(e,t)},validateMatchPathArgs:Wt,validateIsActiveRouteArgs(e,t,n,i){It(e,t,n,i),r(e,t)},validateShouldUpdateNodeArgs:Gt,validateStateBuilderArgs:Lt,validateAddRouteArgs(e){Pt(e)},validateRoutes(n,r){Kt(n,e.getTree(),t,e.getForwardMap(),r)},validateRemoveRouteArgs:At,validateUpdateRouteBasicArgs:Rt,validateUpdateRoutePropertyTypes(e,t){let n=t;Bt({forwardTo:n.forwardTo,defaultParams:n.defaultParams,defaultSearch:n.defaultSearch,decodeParams:n.decodeParams,encodeParams:n.encodeParams,canActivate:n.canActivate,canDeactivate:n.canDeactivate})},validateUpdateRoute(n,r){let i=r.forwardTo;Yt(n,i,t,e.getForwardMap())},validateParentOption(e){if(Ft(e),!t.hasRoute(e))throw ReferenceError(`[router.addRoute] Parent route "${e}" does not exist`)},validateRouteName(e,t){x(e,t)},throwIfInternalRoute(e,t){Ot(e,t)},throwIfInternalRouteInArray(e,t){kt(e,t)},validateSetRootPathArgs:jt,guardRouteCallbacks:Mt,guardNoAsyncCallbacks:Nt},options:{validateOptions:nt,validateResolvedDefaultRoute(e){G(e,t)}},dependencies:{validateDependencyName:be,validateSetDependencyArgs(e,t,n){xe(e)},validateDependenciesObject(t,n){Se(t,n),Ce(t,e.getDependencyKeys(),e.getResolvedLimits().maxDependencies,n)},validateDependencyExists(e,t){we(t,e)},validateDependencyCount(t,n,r){Te(t,n,r,e.logger)},validateCloneArgs:Ee,warnOverwrite(t,n){De(t,n,e.logger)},warnBatchOverwrite(t,n){Oe(t,n,e.logger)},warnRemoveNonExistent(t){ke(t,e.logger)}},plugins:{validatePluginLimit(e,t){at(e,1,t?.maxPlugins)},validateNoDuplicatePlugins:ot,validatePluginKeys:ct,validateCountThresholds(t){st(t,e.getOptions().limits?.maxPlugins??u.maxPlugins,e.logger)},warnBatchDuplicates(){lt(e.logger)},warnPluginMethodType(t){ut(t,e.logger)},warnPluginAfterStart(t){dt(t,e.logger)}},lifecycle:{validateHandler:Fe,validateHandlerLimit(t,n){Ie(t,n,e.getOptions().limits?.maxLifecycleHandlers??u.maxLifecycleHandlers)},validateCountThresholds(t,n){Le(t,n,e.getOptions().limits?.maxLifecycleHandlers??u.maxLifecycleHandlers,e.logger)},warnOverwrite(t,n,r){Re(t,n,r,e.logger)},warnAsyncGuardSync(t,n){ze(t,n,e.logger)}},navigation:{validateNavigateToDefaultArgs(t){Ue(t),n.check(e.logger)},validateNavigateToStateArgs:We,validateNavigationOptions:D,validateParamsShape:k,validateSearch:j,validateStartArgs:Ke},state:{validateMakeStateArgs:Xt,reportDroppedQueryKey:Zt(),reportUndeclaredParamKey:Qt(),validateAreStatesEqualArgs(e,t,n){if(!pe(e))throw TypeError(`[router.areStatesEqual] Invalid state1: ${S(e)}. Expected State object.`);if(!pe(t))throw TypeError(`[router.areStatesEqual] Invalid state2: ${S(t)}. Expected State object.`);if(n!==void 0&&!p(n))throw TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${S(n)}. Expected boolean.`)}},eventBus:{validateListenerArgs(e,t){Ne(e,t)},validateCountThresholds(t,n,r){let i=e.getOptions().limits?.maxListeners??u.maxListeners;Pe(t,n,r,e.logger,i)}}}}function nn(){return t=>{let n=c(t),o=r(t);if(t.isActive())throw a(new e(`VALIDATION_PLUGIN_AFTER_START`,{message:`validation-plugin must be registered before router.start()`}));if(n.validator!==null)throw a(new e(`VALIDATION_PLUGIN_ALREADY_INSTALLED`,{message:`validation-plugin is already installed on this router — a clone re-runs plugin factories, so it needs no usePlugin of its own`}));let s=new _e;s.watch(o.getAdoptedOrigins());let l=$t(o),u=tn(o,l,s),d=()=>{n.validator===u&&(n.validator=null)};n.validator=u;try{let e=en(o,i(t)),r=o.getForwardMap(),a=o.getResolvedLimits(),s=o.getOptions();mt(e),ht(r,l),gt(e),_t(r,l),vt(n.dependenciesGetStore().dependencies,a),yt(s,o.getDependencyKeys().length,a.maxDependencies),n.validator.options.validateOptions(s,`constructor (retrospective)`),typeof s.defaultRoute==`string`&&G(s.defaultRoute,l)}catch(e){throw d(),e}let f=o.addInterceptor(`start`,(e,t)=>{try{bt(o.getExternalGuardNames(),l,o.logger)}catch{}return e(t)}),p=o.addCheck(`buildPath:params`,e=>{A(e,`buildPath`)}),m=o.addCheck(`buildPathResolved:params`,e=>{A(e,`buildPathResolved`)}),h=o.addCheck(`canNavigateTo:entry`,(e,t,n)=>{x(e,`canNavigateTo`),k(t,`canNavigateTo`),j(n,`canNavigateTo`)}),ee=o.addCheck(`canNavigateTo:params`,e=>{A(e,`canNavigateTo`)}),g=o.addCheck(`navigate:entry`,(e,t,n,r)=>{He(e),k(t,`navigate`),j(n,`navigate`),D(r,`navigate`)}),_=o.addCheck(`navigate:params`,e=>{A(e,`navigate`)});return{teardown(){p(),m(),h(),ee(),g(),_(),f(),d()}}}}export{nn as validationPlugin};
1
+ import{RouterError as e,events as t,resolveForwardChain as n}from"@real-router/core";import{getPluginApi as r,getRoutesApi as i}from"@real-router/core/api";import{freezeThrownError as a,putField as o}from"@real-router/core/utils";import{findMisChanneledKey as s,getInternals as c,validateRoute as l}from"@real-router/core/validation";const u=Object.freeze({maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxLifecycleHandlers:200});function d(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}function f(e){return typeof e==`string`}function p(e){return typeof e==`boolean`}function m(e,t){return e in t}const h=Object.getPrototypeOf,g=Object.values,_=Object.hasOwn;function v(e){if(Array.isArray(e))return!0;let t=h(e);return t===null||t===Object.prototype}function y(e,t){let n=Array.isArray(e)?e:g(e);for(let e of n)t.push(e)}function b(e){let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}var x=class{container;constructor(e){this.container=e}};function ee(e,t,n,r){return n.has(e)?!1:r.has(e)?!0:v(e)?(n.add(e),t.push(new x(e)),y(e,t),!0):!1}function te(e){let t=[e],n=new WeakSet,r=new WeakSet;for(;t.length>0;){let e=t.pop();if(e instanceof x){n.delete(e.container),r.add(e.container);continue}if(e!=null){if(typeof e==`object`){if(!ee(e,t,n,r))return!1;continue}if(!b(e))return!1}}return!0}function S(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}function C(e){try{return w(e)}catch{return!1}}function w(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=h(e);if(t!==null&&t!==Object.prototype)return!1;let n=!1;for(let t in e){if(!_(e,t))continue;let r=e[t];if(!S(r)){let e=typeof r;if(e===`function`||e===`symbol`)return!1;n=!0;break}}return!n||te(e)}const T=[`replace`,`reload`,`force`,`forceDeactivate`,`redirected`,`revalidate`];function ne(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;for(let e of T){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 re=/\S/,E=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function D(e,t){return TypeError(`[router.${e}] ${t}`)}function O(e){return typeof e==`string`?e===``?!0:e.length>1e4?!1:e.startsWith(`@@`)?!0:E.test(e):!1}function ie(e){return O(e.name)&&typeof e.path==`string`&&C(e.params)}function k(e){return typeof e!=`object`||!e?!1:ie(e)}function A(e,t){if(typeof e!=`string`)throw D(t,`Route name must be a string, got ${typeof e}`);if(e!==``){if(!re.test(e))throw D(t,`Route name cannot contain only whitespace`);if(e.length>1e4)throw D(t,`Route name exceeds maximum length of 10000 characters. This is a technical safety limit.`);if(!e.startsWith(`@@`)&&!E.test(e))throw D(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 j(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 ae=Object.entries,oe=[`defaultParams`,`defaultSearch`],se=e=>new Map(ae(e)),ce=(e,t)=>{let n=ae(e);return n.length!==t.size||n.some(([e,n])=>!t.has(e)||!Object.is(t.get(e),n))};var le=class{#e=new Map;#t=new Set;watch(e){for(let t of oe){let n=e[t],r=n?.deref();n!==void 0&&r!==void 0&&this.#e.set(t,{ref:n,before:se(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&&ce(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 M=Object.keys,ue=Object.getOwnPropertyDescriptor,de=Object.getPrototypeOf,fe=Object;function pe(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=de(e);return t===null||t.constructor===fe}function me(e,t){if(typeof e!=`string`)throw TypeError(`[router.${t}] dependency name must be a string, got ${typeof e}`)}function he(e){if(typeof e!=`string`)throw TypeError(`[router.setDependency] dependency name must be a string, got ${typeof e}`)}function ge(e,t){if(!pe(e))throw TypeError(`[router.${t}] Invalid argument: expected plain object, received ${j(e)}`);for(let n of M(e))if(ue(e,n)?.get)throw TypeError(`[router.${t}] Getters not allowed: "${n}"`)}function _e(e,t,n,r){if(n===0)return;let i=new Set(t),a=0;for(let t of M(e))i.has(t)||(a+=1);let o=t.length;if(o+a>n)throw RangeError(`[router.${r}] Dependency limit exceeded (${n}). Current: ${o}, this batch adds ${a}.`)}function ve(e,t){if(e===void 0)throw ReferenceError(`[router.getDependency] dependency "${t}" not found`)}function ye(e,t,n,r){if(t===0)return;let{warn:i,error:a}=d(t);if(e>=t)throw RangeError(`[router.${n}] Dependency limit exceeded (${t}). Current: ${e}.`);e===a?r.error(`router.${n}`,`${e} dependencies registered! This indicates architectural problems. Hard limit at ${t}.`):e===i&&r.warn(`router.${n}`,`${e} dependencies registered. Consider if all are necessary.`)}function be(e){if(e!==void 0){if(!pe(e))throw TypeError(`[cloneRouter] Invalid dependencies: expected plain object or undefined, received ${typeof e}`);for(let t of M(e))if(ue(e,t)?.get)throw TypeError(`[cloneRouter] Getters not allowed in dependencies: "${t}"`)}}function xe(e,t,n){n.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function Se(e,t,n){n.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function Ce(e,t){t.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const we=Object.values,Te=new Set(we(t));function Ee(e){if(!Te.has(e))throw TypeError(`[router.addEventListener] Invalid event name: ${String(e)}. Must be one of: $start, $stop, $$start, $$leaveApprove, $$cancel, $$success, $$error`)}function De(e,t){if(Ee(e),typeof t!=`function`)throw TypeError(`[router.addEventListener] callback must be a function, got ${typeof t}`)}function Oe(e,t,n,r,i=u.maxListeners){if(i===0)return;let{warn:a,error:o}=d(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 ke(e,t){if(!p(e)&&typeof e!=`function`)throw TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${j(e)}`)}function Ae(e,t,n=u.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 je(e,t,n,r){if(n===0)return;let{warn:i,error:a}=d(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 Me(e,t,n,r){r.warn(`router.${n}`,`Overwriting existing ${t} handler for route "${e}"`)}function Ne(e,t,n){n.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}const Pe=Object.hasOwn,Fe=Object.getPrototypeOf;function Ie(e){if(typeof e!=`string`)throw TypeError(`[router.navigate] Invalid route name: expected string, got ${j(e)}`)}function Le(e){if(e!==void 0&&(typeof e!=`object`||!e))throw TypeError(`[router.navigateToDefault] Invalid options: ${j(e)}. Expected NavigationOptions object.`)}function Re(e){if(typeof e!=`object`||!e)throw TypeError(`[router.navigateToState] Invalid state: ${j(e)}. Expected State object.`);let t=e;if(!f(t.name))throw TypeError(`[router.navigateToState] Invalid state.name: ${j(t.name)}. Expected string.`);if(!C(t.params))throw TypeError(`[router.navigateToState] Invalid state.params: ${j(t.params)}. Expected plain object.`);if(!f(t.path))throw TypeError(`[router.navigateToState] Invalid state.path: ${j(t.path)}. Expected string.`)}function ze(e,t){if(!ne(e))throw TypeError(`[router.${t}] Invalid options: ${j(e)}. Expected NavigationOptions object.`)}const N=/[\u0000-\u001F\u007F]/;function Be(e,t){for(let n in e){if(!Pe(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`&&N.test(r))throw TypeError(`[router.${t}] param "${n}" must not contain control characters (NUL / C0 / DEL) — they corrupt the URL path.`)}}function P(e,t){if(e===void 0)return;let n=e!==null&&Fe(e);if(Array.isArray(e)||n!==null&&n!==Object.prototype)throw TypeError(`[router.${t}] params must be a plain object, got ${j(e)}`)}function F(e,t){if(e!==void 0&&(Be(e,t),!C(e)))throw TypeError(`[router.${t}] params must be a plain object, got ${j(e)}`)}function I(e,t){if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))throw TypeError(`[router.${t}] search must be a plain object, got ${j(e)}`)}function Ve(e){if(e!==void 0&&typeof e!=`string`)throw TypeError(`[router.start] path must be a string, got ${j(e)}.`);if(typeof e==`string`){if(N.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 He=Object.entries,Ue=Object.hasOwn,L=Object.keys,We=Object.getPrototypeOf,R={trailingSlash:[`strict`,`never`,`always`,`preserve`],queryParamsMode:[`default`,`strict`,`loose`],urlParamsEncoding:[`default`,`uri`,`uriComponent`,`none`]},Ge={arrayFormat:!0,booleanFormat:!0,nullFormat:!0,numberFormat:!0},Ke=new Set(L({defaultRoute:!0,defaultParams:!0,defaultSearch:!0,trailingSlash:!0,caseSensitive:!0,queryParamsMode:!0,queryParams:!0,urlParamsEncoding:!0,allowNotFound:!0,rewritePathOnMatch:!0,logger:!0,limits:!0})),z={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=z[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 B(e){let t=We(e);return t===null||t===Object.prototype}function Je(e,t){if(!e||typeof e!=`object`||!B(e))throw TypeError(`[router.${t}] invalid limits: expected plain object, got ${typeof e}`);for(let[n,r]of He(e)){if(!Ue(z,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 V(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 H(e,t,n){if(e!==void 0&&typeof e!=`function`&&(!e||typeof e!=`object`||Array.isArray(e)||!B(e)))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 of L(n))if(!m(e,Ge))throw TypeError(`[router.${t}] Invalid "queryParams.${e}": unknown option`)}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 L(n))if(!Ke.has(e))throw TypeError(`[router.${t}] Unknown option: "${e}"`);if(Ye(n.defaultRoute,t),H(n.defaultParams,`defaultParams`,t),H(n.defaultSearch,`defaultSearch`,t),V(n.trailingSlash,`trailingSlash`,R.trailingSlash,t),V(n.queryParamsMode,`queryParamsMode`,R.queryParamsMode,t),V(n.urlParamsEncoding,`urlParamsEncoding`,R.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,U=`router.usePlugin`,$e={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function et(e,t,n=u.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}=d(t);e>=i?n.error(U,`${e} plugins registered! This is excessive. Hard limit at ${t}.`):e>=r&&n.warn(U,`${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(U,`Duplicate factory in batch, will be registered once`)}function at(e,t){t.warn(U,`Property '${e}' is not a function, skipping`)}function ot(e,t){e===`onStart`&&t.warn(U,`Router already started, onStart will not be called`)}const W=Object.entries,st=Object.getOwnPropertyDescriptor,G=Object.keys;function K(e,t,n=``){for(let r of e){let e=n?`${n}.${r.name}`:r.name;t(r,e),r.children&&K(r.children,t,e)}}function q(e,t){let n=[];return K(e,(e,r)=>{let i=t(e);i!==void 0&&n.push([r,i])}),n}function ct(e,t){try{return n(e,t)}catch(e){throw Error(`[validation-plugin] ${e.message}`,{cause:e})}}function J(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){K(e,(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,t){for(let[n,r]of W(e)){if(!t.hasRoute(r))throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${r}" does not exist in tree (source route: "${n}")`);let e=new Set(t.getUrlParams(n)),i=[...new Set(t.getUrlParams(r))].filter(t=>!e.has(t));if(i.length>0)throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${r}" requires params [${i.join(`, `)}] not available in source route "${n}"`)}for(let t of G(e))ct(t,e)}function dt(e,t){for(let[n,r]of 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 ft(e){let t=q(e,e=>e.decodeParams),n=q(e,e=>e.encodeParams),r=q(e,e=>typeof e.forwardTo==`string`?void 0:e.forwardTo);for(let[e,n]of t){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" decoder must be a function, got ${typeof n}`);J(n,`decoder`,e)}for(let[e,t]of n){if(typeof t!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" encoder must be a function, got ${typeof t}`);J(t,`encoder`,e)}dt(q(e,e=>e.defaultParams),`defaultParams`),dt(q(e,e=>e.defaultSearch),`defaultSearch`);for(let[e,t]of r){if(typeof t!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" forwardTo callback must be a function, got ${typeof t}`);J(t,`forwardTo callback`,e)}}function pt(e,t){for(let[n,r]of W(e))if(!t.hasRoute(r))throw Error(`[validation-plugin] validateForwardToTargetsStore: forwardTo target "${r}" does not exist for route "${n}"`)}function mt(e,t){for(let t of G(e))if(st(e,t)?.get)throw TypeError(`[validation-plugin] validateDependenciesStructure: dependency "${t}" must not use a getter`);for(let[e,n]of W(t))if(!Number.isInteger(n))throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits.${e} must be an integer, got ${String(n)}`)}function ht(e,t,n){let r=e&&typeof e==`object`?e:{},i=(r.limits&&typeof r.limits==`object`?r.limits:{}).maxDependencies,a=typeof i==`number`?i:n;if(a>0&&t>a)throw RangeError(`[validation-plugin] validateLimitsConsistency: dependency count (${t}) exceeds maxDependencies limit (${a})`)}function gt(e,t){if(typeof e==`string`&&e&&!t.hasRoute(e))throw Error(`[validation-plugin] defaultRoute resolved to non-existent route: "${e}"`)}function _t(e,t,n){for(let r of e)t.hasRoute(r)||n.warn(`router.start`,`Guard registered for route "${r}", which the route tree does not contain. It will never run unless that route is added. Check the name for a typo.`)}const vt=Object.keys;function yt(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 ${j(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 bt(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 ${j(e)}`)}function xt(e,t){if(e.canActivate!==void 0&&typeof e.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function for route "${t}", got ${j(e.canActivate)}`);if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${j(e.canDeactivate)}`);if(bt(e.defaultParams,`defaultParams`,t),bt(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(yt(e.forwardTo,t),e.children)for(let n of e.children)xt(n,`${t}.${n.name}`)}function St(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 Ct(e){let t=new Set;for(let n of e)for(let e of St(n))t.add(e);return t}function Y(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 Y(i.children,t,e,a)}throw Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function wt(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 wt(r.children,e))n.add(t)}return n}function Tt(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 Tt(r.children,e))n.set(t,i)}return n}function Et(e,t,n,r){return t?new Set(n.getUrlParams(e)):Ct(Y(r,e))}const Dt=new Set;function Ot(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,...Ct(Y(n,e))]),l=[...Et(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 kt(e,t,r,i){let a=wt(e),s=i?new Set([...a].map(e=>`${i}.${e}`)):a,c=i?new Set(r.getUrlParams(i)):Dt,l=Tt(e),u={...t};for(let[e,t]of l)o(u,e,t);for(let[t,n]of l)Ot(t,n,e,s,r,c);for(let e of vt(u))n(e,u)}function X(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 At(e,t){for(let n of e)n&&typeof n==`object`&&typeof n.name==`string`&&(X(n.name,t),n.children&&At(n.children,t))}function jt(e){A(e,`removeRoute`)}function Mt(e){if(typeof e!=`string`)throw TypeError(`[router.setRootPath] rootPath must be a string, got ${j(e)}`)}function Z(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function Nt(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function, got ${j(t.canActivate)}`);if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function, got ${j(t.canDeactivate)}`)}function Pt(e){let t=e,n=t.name;if(t.decodeParams!==void 0&&Z(t.decodeParams))throw TypeError(`[router.addRoute] decodeParams cannot be async for route "${String(n)}"`);if(t.encodeParams!==void 0&&Z(t.encodeParams))throw TypeError(`[router.addRoute] encodeParams cannot be async for route "${String(n)}"`);if(typeof t.forwardTo==`function`&&Z(t.forwardTo))throw TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${String(n)}"`)}function Ft(e){for(let t of e){if(typeof t!=`object`||!t||Array.isArray(t))throw TypeError(`[router.addRoute] Route must be an object, got ${j(t)}`);xt(t,t.name)}}function It(e){if(typeof e!=`string`||e===``)throw TypeError(`[router.addRoute] parent option must be a non-empty string, got ${j(e)}`);A(e,`addRoute`)}function Lt(e,t,n,r){if(!f(e))throw TypeError(`[router.isActiveRoute] name must be a string, got ${typeof e}`);if(P(t,`isActiveRoute`),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 Q(e,t,n){if(!f(e))throw TypeError(`[router.${n}] Invalid routeName: ${j(e)}. Expected string.`);if(!C(t))throw TypeError(`[router.${n}] Invalid routeParams: ${j(t)}. Expected plain object.`)}function Rt(e,t){if(A(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 ${j(t)}`)}function zt(e,t){if(e.constructor.name===`AsyncFunction`||e.toString().includes(`__awaiter`))throw TypeError(`[router.updateRoute] ${t} cannot be an async function`)}function $(e,t){if(e!=null){if(typeof e!=`function`)throw TypeError(`[router.updateRoute] ${t} must be a function or null, got ${typeof e}`);zt(e,t)}}function Bt(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 ${j(t)}`);typeof t==`function`&&zt(t,`forwardTo callback`)}Vt(n,`defaultParams`),Vt(r,`defaultSearch`),$(i,`decodeParams`),$(a,`encodeParams`),$(o,`canActivate`),$(s,`canDeactivate`)}function Vt(e,t){if(e!=null&&(typeof e!=`object`||Array.isArray(e)))throw TypeError(`[router.updateRoute] ${t} must be an object or null, got ${j(e)}`)}function Ht(e){if(!f(e)||e===``)throw TypeError(`[router.buildPath] route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`)}function Ut(e){let t=new Set;return function(n,r){let i=s(r,e(n));if(i===void 0)return;let a=`${n} ${i}`;t.has(a)||(t.add(a),console.warn(`[router] Route "${n}" declares \`${i}\` as a query param, but it was given in the \`params\` bag — the path channel. The URL is built without it, so the href does not match what you asked for; a plain click throws, but a ⌘-click, a copied link and server-rendered markup all follow the wrong URL in silence. Pass it in \`search\` instead.`))}}function Wt(e){if(!f(e))throw TypeError(`[router.matchPath] path must be a string, got ${typeof e}`)}function Gt(e){if(!f(e))throw TypeError(`[router.shouldUpdateNode] nodeName must be a string, got ${typeof e}`)}function Kt(e,t,n,r,i){if(i){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,o=new Map;for(let n of e)l(n,`addRoute`,t,i??``,a,o);kt(e,r,n,i)}function qt(e,t,n){let r=new Set(n.getUrlParams(e)),i=n.getUrlParams(t).filter(e=>!r.has(e));if(i.length>0)throw Error(`[router.addRoute] forwardTo target "${t}" requires params [${i.join(`, `)}] that are not available in source route "${e}"`)}function Jt(e,t,r){let i={...r,[e]:t};n(e,i)}function Yt(e,t,n,r){if(!n.hasRoute(e))throw ReferenceError(`[router.updateRoute] route "${e}" does not exist`);if(t!=null&&typeof t==`string`){if(!n.hasRoute(t))throw Error(`[router.updateRoute] forwardTo target "${t}" does not exist`);qt(e,t,n),Jt(e,t,r)}}function Xt(e,t,n){if(!f(e))throw TypeError(`[router.makeState] Invalid name: ${j(e)}. Expected string.`);if(t!==void 0&&!C(t))throw TypeError(`[router.makeState] Invalid params: ${j(t)}. Expected plain object.`);if(n!==void 0&&!f(n))throw TypeError(`[router.makeState] Invalid path: ${j(n)}. Expected string.`)}function Zt(){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 Qt(){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 $t(e){return{hasRoute:t=>{let n=e.getTree();for(let e of t.split(`.`))if(n=n?.children.get(e),!n)return!1;return!0},getUrlParams:t=>e.getUrlParams(t)}}function en(e,t){let n=[];for(let r of e.getTree().children.keys())n.push(t.get(r));return n}function tn(e,t,n){let r=Ut(t=>e.getDeclaredQueryNames(t));return{routes:{validateBuildPathArgs(e,t){Ht(e),r(e,t)},validateMatchPathArgs:Wt,validateIsActiveRouteArgs(e,t,n,i){Lt(e,t,n,i),r(e,t)},validateShouldUpdateNodeArgs:Gt,validateStateBuilderArgs:Q,validateRouteName(e,t){A(e,t)},validateSetRootPathArgs:Mt},options:{validateOptions:Ze,validateResolvedDefaultRoute(e){gt(e,t)}},dependencies:{validateDependencyName:me,validateSetDependencyArgs(e,t,n){he(e)},validateDependenciesObject(t,n){ge(t,n),_e(t,e.getDependencyKeys(),e.getResolvedLimits().maxDependencies,n)},validateDependencyExists(e,t){ve(t,e)},validateDependencyCount(t,n,r){ye(t,n,r,e.logger)},validateCloneArgs:be,warnOverwrite(t,n){xe(t,n,e.logger)},warnBatchOverwrite(t,n){Se(t,n,e.logger)},warnRemoveNonExistent(t){Ce(t,e.logger)}},plugins:{validatePluginLimit(e,t){et(e,1,t?.maxPlugins)},validateNoDuplicatePlugins:tt,validatePluginKeys:rt,validateCountThresholds(t){nt(t,e.getOptions().limits?.maxPlugins??u.maxPlugins,e.logger)},warnBatchDuplicates(){it(e.logger)},warnPluginMethodType(t){at(t,e.logger)},warnPluginAfterStart(t){ot(t,e.logger)}},lifecycle:{validateHandlerLimit(t,n){Ae(t,n,e.getOptions().limits?.maxLifecycleHandlers??u.maxLifecycleHandlers)},validateCountThresholds(t,n){je(t,n,e.getOptions().limits?.maxLifecycleHandlers??u.maxLifecycleHandlers,e.logger)},warnOverwrite(t,n,r){Me(t,n,r,e.logger)},warnAsyncGuardSync(t,n){Ne(t,n,e.logger)}},navigation:{validateNavigateToDefaultArgs(t){Le(t),n.check(e.logger)},validateNavigateToStateArgs:Re,validateNavigationOptions:ze,validateParamsShape:P,validateSearch:I,validateStartArgs:Ve},state:{validateMakeStateArgs:Xt,reportDroppedQueryKey:Zt(),reportUndeclaredParamKey:Qt(),validateAreStatesEqualArgs(e,t,n){if(!k(e))throw TypeError(`[router.areStatesEqual] Invalid state1: ${j(e)}. Expected State object.`);if(!k(t))throw TypeError(`[router.areStatesEqual] Invalid state2: ${j(t)}. Expected State object.`);if(n!==void 0&&!p(n))throw TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${j(n)}. Expected boolean.`)}},eventBus:{validateListenerArgs(e,t){De(e,t)},validateCountThresholds(t,n,r){let i=e.getOptions().limits?.maxListeners??u.maxListeners;Oe(t,n,r,e.logger,i)}}}}function nn(){return t=>{let n=c(t),o=r(t);if(t.isActive())throw a(new e(`VALIDATION_PLUGIN_AFTER_START`,{message:`validation-plugin must be registered before router.start()`}));if(n.validator!==null)throw a(new e(`VALIDATION_PLUGIN_ALREADY_INSTALLED`,{message:`validation-plugin is already installed on this router — a clone re-runs plugin factories, so it needs no usePlugin of its own`}));let s=new le;s.watch(o.getAdoptedOrigins());let l=$t(o),u=tn(o,l,s),d=()=>{n.validator===u&&(n.validator=null)};n.validator=u;try{let e=en(o,i(t)),r=o.getForwardMap(),a=o.getResolvedLimits(),s=o.getOptions();lt(e),ut(r,l),ft(e),pt(r,l),mt(n.dependenciesGetStore().dependencies,a),ht(s,o.getDependencyKeys().length,a.maxDependencies),n.validator.options.validateOptions(s,`constructor (retrospective)`),typeof s.defaultRoute==`string`&&gt(s.defaultRoute,l)}catch(e){throw d(),e}let f=o.addInterceptor(`start`,(e,t)=>{try{_t(o.getExternalGuardNames(),l,o.logger)}catch{}return e(t)}),p=o.addCheck(`buildPath:params`,e=>{F(e,`buildPath`)}),m=o.addCheck(`buildPathResolved:params`,e=>{F(e,`buildPathResolved`)}),h=o.addCheck(`canNavigateTo:entry`,(e,t,n)=>{A(e,`canNavigateTo`),P(t,`canNavigateTo`),I(n,`canNavigateTo`)}),g=o.addCheck(`canNavigateTo:params`,e=>{F(e,`canNavigateTo`)}),_=o.addCheck(`navigate:entry`,(e,t,n,r)=>{Ie(e),P(t,`navigate`),I(n,`navigate`),ze(r,`navigate`)}),v=o.addCheck(`navigate:params`,e=>{F(e,`navigate`)}),y=e=>{for(let t of e)Nt(t),Pt(t),t.children!==void 0&&y(t.children)},b=(e,t,n)=>{if(y(e),n!==void 0&&(It(n),!l.hasRoute(n)))throw ReferenceError(`[router.addRoute] Parent route "${n}" does not exist`);At(e,t),Ft(e),Kt(e,o.getTree(),l,o.getForwardMap(),n)},x=o.addCheck(`addRoute:batch`,(e,t)=>{b(e,`addRoute`,t)}),ee=o.addCheck(`replaceRoutes:batch`,e=>{b(e,`replaceRoutes`,void 0)}),te=o.addCheck(`removeRoute:entry`,e=>{jt(e),X(e,`removeRoute`)}),S=o.addCheck(`updateRoute:entry`,(e,t)=>{let n=t;Rt(e,t),X(e,`updateRoute`),Bt({forwardTo:n.forwardTo,defaultParams:n.defaultParams,defaultSearch:n.defaultSearch,decodeParams:n.decodeParams,encodeParams:n.encodeParams,canActivate:n.canActivate,canDeactivate:n.canDeactivate}),Yt(e,n.forwardTo,l,o.getForwardMap())}),C=o.addCheck(`hasRoute:entry`,e=>{A(e,`hasRoute`)}),w=o.addCheck(`getRoute:entry`,e=>{A(e,`getRoute`)}),T=o.addCheck(`forwardState:entry`,(e,t,n)=>{Q(e,t,`forwardState`),I(n,`forwardState`)}),ne=o.addCheck(`buildNavigationState:state`,(e,t,n)=>{I(n,`buildNavigationState`),Q(e,t,`buildNavigationState`)}),re=o.addCheck(`addActivateGuard:entry`,(e,t)=>{A(e,`addActivateGuard`),ke(t,`addActivateGuard`)}),E=o.addCheck(`addDeactivateGuard:entry`,(e,t)=>{A(e,`addDeactivateGuard`),ke(t,`addDeactivateGuard`)}),D=o.addCheck(`removeActivateGuard:entry`,e=>{A(e,`removeActivateGuard`)}),O=o.addCheck(`removeDeactivateGuard:entry`,e=>{A(e,`removeDeactivateGuard`)});return{teardown(){p(),m(),h(),g(),_(),v(),x(),ee(),te(),S(),C(),w(),T(),ne(),re(),E(),D(),O(),f(),d()}}}}export{nn as validationPlugin};
2
2
  //# sourceMappingURL=index.mjs.map