@real-router/validation-plugin 0.32.0 → 0.33.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":";;;;;;;;;;;;;;;wBAybgB,iBACd,qBAAqB,sBAAsB,wBACxC,cAAc"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/validationPlugin.ts"],"mappings":";;;;;;;;;;;;;;;wBA+bgB,iBACd,qBAAqB,sBAAsB,wBACxC,cAAc"}
@@ -1,2 +1,2 @@
1
- import{getPluginApi as e,getRoutesApi as t}from"@real-router/core/api";import{internalDefect as n,putField as r,raiser as i}from"@real-router/core/utils";import{areParamValuesEqual as a,buildParamMeta as o,findMisChanneledKey as s,getInternals as c,validateRoute as l}from"@real-router/core/validation";import{events as ee,resolveForwardChain as u}from"@real-router/core";const d=Object.freeze({maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxLifecycleHandlers:200});function f(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}function p(e){return typeof e==`string`}function m(e){return typeof e==`boolean`}function te(e,t){return e in t}const h=Object.getPrototypeOf,g=Object.values,ne=Object.hasOwn;function re(e){if(Array.isArray(e))return!0;let t=h(e);return t===null||t===Object.prototype}function ie(e,t){let n=Array.isArray(e)?e:g(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 _=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 _(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 _)n.delete(e.container),r.add(e.container);else if(e!=null){if(typeof e==`object`){if(!oe(e,t,n,r))return!1}else 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 v(e){try{return le(e)}catch{return!1}}function le(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(!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`,`revalidate`];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/,pe=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function y(e,t){return i(`router`,e).type`${t}`}function me(e){return typeof e==`string`?e===``?!0:e.length>1e4?!1:e.startsWith(`@@`)?!0:pe.test(e):!1}function he(e){return me(e.name)&&typeof e.path==`string`&&v(e.params)}function ge(e){return typeof e!=`object`||!e?!1:he(e)}function b(e,t){if(typeof e!=`string`)throw y(t,`Route name must be a string, got ${typeof e}`);if(e!==``){if(!fe.test(e))throw y(t,`Route name cannot contain only whitespace`);if(e.length>1e4)throw y(t,`Route name exceeds maximum length of 10000 characters. This is a technical safety limit.`);if(!e.startsWith(`@@`)&&!pe.test(e))throw y(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 x(e){if(e===null)return`null`;if(typeof e!=`object`)return typeof e;try{if(Array.isArray(e))return`array[${e.length}]`;let t=e.constructor;if(typeof t==`function`){let e=t.name;if(typeof e==`string`&&e!==``&&e!==`Object`)return e}}catch{}return`object`}const _e=Object.entries,ve=[`defaultParams`,`defaultSearch`],ye=e=>new Map(_e(e)),be=(e,t)=>{let n=_e(e);return n.length!==t.size||n.some(([e,n])=>!t.has(e)||!Object.is(t.get(e),n))};var xe=class{#e=new Map;#t=new Set;watch(e){for(let t of ve){let n=e[t],r=n?.deref();n!==void 0&&r!==void 0&&this.#e.set(t,{ref:n,before:ye(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&&be(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 Se=i(`cloneRouter`),Ce=i(`router`,`getDependency`),we=i(`router`,`setDependency`),S=Object.keys,Te=Object.getOwnPropertyDescriptor,Ee=Object.getPrototypeOf,De=Object;function Oe(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=Ee(e);return t===null||t.constructor===De}function ke(e,t){if(typeof e!=`string`)throw i(`router`,t).type`dependency name must be a string, got ${typeof e}`}function Ae(e){if(typeof e!=`string`)throw we.type`dependency name must be a string, got ${typeof e}`}function je(e,t){if(!Oe(e))throw i(`router`,t).type`Invalid argument: expected plain object, received ${x(e)}`;for(let n of S(e))if(Te(e,n)?.get)throw i(`router`,t).type`Getters not allowed: "${n}"`}function Me(e,t,n,r){if(n===0)return;let a=new Set(t),o=0;for(let t of S(e))a.has(t)||(o+=1);let s=t.length;if(s+o>n)throw i(`router`,r).range`Dependency limit exceeded (${n}). Current: ${s}, this batch adds ${o}.`}function Ne(e,t){if(e===void 0)throw Ce.ref`dependency "${t}" not found`}function Pe(e,t,n,r){if(t===0)return;let{warn:a,error:o}=f(t);if(e>=t)throw i(`router`,n).range`Dependency limit exceeded (${t}). Current: ${e}.`;e===o?r.error(`router.${n}`,`${e} dependencies registered! This indicates architectural problems. Hard limit at ${t}.`):e===a&&r.warn(`router.${n}`,`${e} dependencies registered. Consider if all are necessary.`)}function Fe(e){if(e!==void 0){if(!Oe(e))throw Se.type`Invalid dependencies: expected plain object or undefined, received ${typeof e}`;for(let t of S(e))if(Te(e,t)?.get)throw Se.type`Getters not allowed in dependencies: "${t}"`}}function Ie(e,t,n){n.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function Le(e,t,n){n.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function Re(e,t){t.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const ze=i(`router`,`addEventListener`),Be=Object.values,Ve=new Set(Be(ee));function He(e){if(!Ve.has(e))throw ze.type`Invalid event name: ${String(e)}. Must be one of: $start, $stop, $$start, $$leaveApprove, $$cancel, $$success, $$error`}function Ue(e,t){if(He(e),typeof t!=`function`)throw ze.type`callback must be a function, got ${typeof t}`}function We(e,t,n,r,i=d.maxListeners){if(i===0)return;let{warn:a,error:o}=f(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.`)}const C=i(`router`,`addRoute`),Ge=Object.keys;function w(e,t){return typeof e==`string`&&e!==``&&typeof t==`string`?`${e}.${t}`:t}function Ke(e,t){if(e!==void 0){if(typeof e!=`string`&&typeof e!=`function`)throw C.type`forwardTo must be a string or function for route "${t}", got ${x(e)}`;if(typeof e==`function`){let n=e.constructor.name===`AsyncFunction`,r=e.toString().includes(`__awaiter`);if(n||r)throw C.type`forwardTo callback cannot be async for route "${t}". Async functions break matchPath/buildPath.`}}}function T(e,t,n){if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))throw C.type`${t} must be an object for route "${n}", got ${x(e)}`}function qe(e,t){if(e.canActivate!==void 0&&typeof e.canActivate!=`function`)throw C.type`canActivate must be a function for route "${t}", got ${x(e.canActivate)}`;if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw C.type`canDeactivate must be a function for route "${t}", got ${x(e.canDeactivate)}`;T(e.defaultParams,`defaultParams`,t),T(e.defaultSearch,`defaultSearch`,t);let{decodeParams:n,encodeParams:r}=e;if(typeof n==`function`&&n.constructor.name===`AsyncFunction`)throw C.type`decodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`;if(typeof r==`function`&&r.constructor.name===`AsyncFunction`)throw C.type`encodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`;if(Ke(e.forwardTo,t),e.children)for(let n of e.children)qe(n,w(t,n.name))}function Je(e){let t=new Set;for(let n of e)for(let e of o(n).urlParams)t.add(e);return t}function Ye(e,t,r=``,i=[]){for(let n of e){let e=r?`${r}.${n.name}`:n.name,a=[...i,n.path];if(e===t)return a;if(n.children&&t.startsWith(`${e}.`))return Ye(n.children,t,e,a)}throw n.plain`collectPathsToRoute: route "${t}" not found`}function Xe(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 Xe(r.children,e))n.add(t)}return n}function Ze(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 Ze(r.children,e))n.set(t,i)}return n}function Qe(e,t,n,r){return t?new Set(n.getUrlParams(e)):Je(r(e))}const $e=new Set;function et(e,t,n,r,i,a){let o=i.hasRoute(t),s=r.has(t);if(!o&&!s)throw C.ref`forwardTo target "${t}" does not exist for route "${e}"`;let c=new Set([...a,...Je(n(e))]),l=[...Qe(t,o,i,n)].filter(e=>!c.has(e));if(l.length>0)throw C.plain`forwardTo target "${t}" requires params [${l.join(`, `)}] that are not available in source route "${e}"`}function tt(e,t,n,i){let a=Xe(e,i),o=t=>Ye(e,i?t.slice(i.length+1):t),s=i?new Set(n.getUrlParams(i)):$e,c=Ze(e,i),l={...t};for(let[e,t]of c)r(l,e,t);for(let[e,t]of c)et(e,t,o,a,n,s);for(let e of Ge(l))u(e,l)}function nt(e,t){if(!m(e)&&typeof e!=`function`)throw i(`router`,t).type`Handler must be a boolean or factory function, got ${x(e)}`}function rt(e,t,n=d.maxLifecycleHandlers){if(n!==0&&e>=n)throw i(`router`,t).range`Lifecycle handler limit exceeded (${n}). This indicates too many routes with individual handlers. Consider using plugins for cross-cutting concerns.`}function it(e,t,n,r){if(n===0)return;let{warn:i,error:a}=f(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 at(e,t,n,r){r.warn(`router.${n}`,`Overwriting existing ${t} handler for route "${e}"`)}function ot(e,t,n){n.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}function st(e,t){return`Guard for "${e}" must answer true or false, got ${x(t)} — read as a refusal.`}function ct(e,t,n,r){r.warn(`router.${n}`,st(e,t))}function lt(e,t,n){n.warn(`router`,st(e,t))}const E=i(`router`,`start`),D=i(`router`,`navigateToState`),ut=i(`router`,`navigateToDefault`),dt=i(`router`,`navigate`),ft=Object.hasOwn,pt=Object.getPrototypeOf;function mt(e){if(typeof e!=`string`)throw dt.type`Invalid route name: expected string, got ${x(e)}`}function ht(e){if(e!==void 0&&(typeof e!=`object`||!e))throw ut.type`Invalid options: ${x(e)}. Expected NavigationOptions object.`}function gt(e){if(typeof e!=`object`||!e)throw D.type`Invalid state: ${x(e)}. Expected State object.`;let t=e;if(!p(t.name))throw D.type`Invalid state.name: ${x(t.name)}. Expected string.`;if(!v(t.params))throw D.type`Invalid state.params: ${x(t.params)}. Expected plain object.`;if(!p(t.path))throw D.type`Invalid state.path: ${x(t.path)}. Expected string.`}function O(e,t){if(!de(e))throw i(`router`,t).type`Invalid options: ${x(e)}. Expected NavigationOptions object.`}const _t=/[\u0000-\u001F\u007F]/;function vt(e,t){for(let n in e){if(!ft(e,n))continue;let r=e[n],a=typeof r;if(a===`symbol`||a===`bigint`)throw i(`router`,t).type`param "${n}" cannot be a ${a} — it does not round-trip through the URL path. Use a string, number, or boolean.`;if(a===`string`&&_t.test(r))throw i(`router`,t).type`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&&pt(e);if(Array.isArray(e)||n!==null&&n!==Object.prototype)throw i(`router`,t).type`params must be a plain object, got ${x(e)}`}function A(e,t){if(e!==void 0&&(vt(e,t),!v(e)))throw i(`router`,t).type`params must be a plain object, got ${x(e)}`}function j(e,t){if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))throw i(`router`,t).type`search must be a plain object, got ${x(e)}`}function yt(e){if(e!==void 0&&typeof e!=`string`)throw E.type`path must be a string, got ${x(e)}.`;if(typeof e==`string`){if(_t.test(e))throw E.type`path must not contain control characters (NUL / C0 / DEL).`;if(e!==``&&!e.startsWith(`/`))throw E.type`path must start with "/", got "${e}".`}}const bt=Object.entries,xt=Object.hasOwn,M=Object.keys,St=Object.getPrototypeOf,N={trailingSlash:[`strict`,`never`,`always`,`preserve`],queryParamsMode:[`default`,`strict`,`loose`],urlParamsEncoding:[`default`,`uri`,`uriComponent`,`none`]},Ct={arrayFormat:!0,booleanFormat:!0,nullFormat:!0,numberFormat:!0},wt=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})),Tt={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 Et(e,t,n){if(typeof t!=`number`||!Number.isInteger(t))throw i(`router`,n).type`limit "${e}" must be an integer, got ${String(t)}`;let r=Tt[e];if(t<r.min||t>r.max)throw i(`router`,n).range`limit "${e}" must be between ${r.min} and ${r.max}, got ${t}`}function Dt(e){let t=St(e);return t===null||t===Object.prototype}function Ot(e,t){if(!e||typeof e!=`object`||!Dt(e))throw i(`router`,t).type`invalid limits: expected plain object, got ${typeof e}`;for(let[n,r]of bt(e)){if(!xt(Tt,n))throw i(`router`,t).type`unknown limit: "${n}"`;r!==void 0&&Et(n,r,t)}let{warnListeners:n,maxListeners:r}=e;if(typeof n==`number`&&typeof r==`number`&&r>0&&n>r)throw i(`router`,t).range`"limits.warnListeners" (${n}) must not exceed "limits.maxListeners" (${r}) — the warning channel would be unreachable`}function P(e,t,n,r){if(e!==void 0&&(typeof e!=`string`||!n.includes(e))){let a=n.map(e=>`"${e}"`).join(`, `),o=typeof e==`string`?e:`(${typeof e})`;throw i(`router`,r).type`Invalid "${t}": "${o}". Must be one of: ${a}`}}function kt(e,t){if(e!==void 0&&typeof e!=`string`&&typeof e!=`function`)throw i(`router`,t).type`Invalid "defaultRoute": expected string or function, got ${typeof e}`}function At(e,t,n){if(e!==void 0&&typeof e!=`function`&&(!e||typeof e!=`object`||Array.isArray(e)||!Dt(e)))throw i(`router`,n).type`Invalid "${t}": expected plain object or function, got ${typeof e}`}function jt(e,t){if(e===void 0)return;if(!e||typeof e!=`object`||Array.isArray(e))throw i(`router`,t).type`Invalid "queryParams": expected plain object`;let n=e;for(let e of M(n))if(!te(e,Ct))throw i(`router`,t).type`Invalid "queryParams.${e}": unknown option`}function Mt(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw i(`router`,t).type`Invalid options: expected plain object`;let n=e;for(let e of M(n))if(!wt.has(e))throw i(`router`,t).type`Unknown option: "${e}"`;if(kt(n.defaultRoute,t),At(n.defaultParams,`defaultParams`,t),At(n.defaultSearch,`defaultSearch`,t),P(n.trailingSlash,`trailingSlash`,N.trailingSlash,t),P(n.queryParamsMode,`queryParamsMode`,N.queryParamsMode,t),P(n.urlParamsEncoding,`urlParamsEncoding`,N.urlParamsEncoding,t),n.allowNotFound!==void 0&&typeof n.allowNotFound!=`boolean`)throw i(`router`,t).type`Invalid "allowNotFound": expected boolean, got ${typeof n.allowNotFound}`;if(n.rewritePathOnMatch!==void 0&&typeof n.rewritePathOnMatch!=`boolean`)throw i(`router`,t).type`Invalid "rewritePathOnMatch": expected boolean, got ${typeof n.rewritePathOnMatch}`;if(n.caseSensitive!==void 0&&typeof n.caseSensitive!=`boolean`)throw i(`router`,t).type`Invalid "caseSensitive": expected boolean, got ${typeof n.caseSensitive}`;jt(n.queryParams,t),n.limits!==void 0&&Ot(n.limits,t)}const F=i(`router`,`usePlugin`),Nt=Object.hasOwn,I=`router.usePlugin`,Pt={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function Ft(e,t,n=d.maxPlugins){if(n!==0&&e+t>n)throw F.range`Plugin limit exceeded (${n}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating plugins.`}function It(e,t){if(t.includes(e))throw F.plain`Plugin factory already registered. To re-register, first unsubscribe the existing plugin.`}function Lt(e,t,n){if(t===0)return;let{warn:r,error:i}=f(t);e>=i?n.error(I,`${e} plugins registered! This is excessive. Hard limit at ${t}.`):e>=r&&n.warn(I,`${e} plugins registered. Consider if all are necessary.`)}function Rt(e){for(let t in e)if(!(t===`teardown`||Nt(Pt,t)))throw F.type`Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`}function zt(e){e.warn(I,`Duplicate factory in batch, will be registered once`)}function Bt(e,t){t.warn(I,`Property '${e}' is not a function, skipping`)}function Vt(e,t){e===`onStart`&&t.warn(I,`Router already started, onStart will not be called`)}const Ht=i(`router`,`navigateToDefault`),L=i(`validation-plugin`),R=Object.entries,Ut=Object.getOwnPropertyDescriptor,Wt=Object.keys;function z(e,t,n=``){for(let r of e){let e=n?`${n}.${r.name}`:r.name;t(r,e),r.children&&z(r.children,t,e)}}function B(e,t){let n=[];return z(e,(e,r)=>{let i=t(e);i!==void 0&&n.push([r,i])}),n}function Gt(e,t){try{return u(e,t)}catch(e){let t=e.message.replace(/^\[router\] /u,``);throw L.plain({cause:e})`${t}`}}function V(e,t,n){let r=e;if(r.constructor.name===`AsyncFunction`||r.toString().includes(`__awaiter`))throw L.type`Route "${n}" ${t} cannot be async`}function Kt(e){z(e,(e,t)=>{if(typeof e.name!=`string`||!e.name)throw L.type`validateExistingRoutes: route has invalid name: ${e.name}`;if(typeof e.path!=`string`)throw L.type`validateExistingRoutes: route "${t}" has non-string path (${typeof e.path})`})}function qt(e,t){for(let[n,r]of R(e)){if(!t.hasRoute(r))throw L.plain`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 L.plain`validateForwardToConsistency: forwardTo target "${r}" requires params [${i.join(`, `)}] not available in source route "${n}"`}for(let t of Wt(e))Gt(t,e)}function Jt(e,t){for(let[n,r]of e)if(typeof r!=`object`||!r||Array.isArray(r))throw L.type`validateRoutePropertiesStore: route "${n}" ${t} must be a plain object, got ${Array.isArray(r)?`array`:typeof r}`}function Yt(e){let t=B(e,e=>e.decodeParams),n=B(e,e=>e.encodeParams),r=B(e,e=>typeof e.forwardTo==`string`?void 0:e.forwardTo);for(let[e,n]of t){if(typeof n!=`function`)throw L.type`validateRoutePropertiesStore: route "${e}" decoder must be a function, got ${typeof n}`;V(n,`decoder`,e)}for(let[e,t]of n){if(typeof t!=`function`)throw L.type`validateRoutePropertiesStore: route "${e}" encoder must be a function, got ${typeof t}`;V(t,`encoder`,e)}Jt(B(e,e=>e.defaultParams),`defaultParams`),Jt(B(e,e=>e.defaultSearch),`defaultSearch`);for(let[e,t]of r){if(typeof t!=`function`)throw L.type`validateRoutePropertiesStore: route "${e}" forwardTo callback must be a function, got ${typeof t}`;V(t,`forwardTo callback`,e)}}function Xt(e,t){for(let[n,r]of R(e))if(!t.hasRoute(r))throw L.plain`validateForwardToTargetsStore: forwardTo target "${r}" does not exist for route "${n}"`}function Zt(e,t){for(let t of Wt(e))if(Ut(e,t)?.get)throw L.type`validateDependenciesStructure: dependency "${t}" must not use a getter`;for(let[e,n]of R(t))if(!Number.isInteger(n))throw L.type`validateDependenciesStructure: deps.limits.${e} must be an integer, got ${String(n)}`}function Qt(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 L.range`validateLimitsConsistency: dependency count (${t}) exceeds maxDependencies limit (${a})`}function $t(e,t){return typeof e==`string`&&e!==``&&!t.hasRoute(e)}function en(e,t){if($t(e,t))throw L.plain`defaultRoute resolved to non-existent route: "${e}"`}function tn(e,t){if($t(e,t))throw Ht.plain`defaultRoute callback resolved to non-existent route: "${e}"`}function nn(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 H=i(`router`,`updateRoute`),U=i(`router`,`addRoute`),rn=i(`router`,`shouldUpdateNode`),an=i(`router`,`matchPath`),on=i(`router`,`buildPath`),W=i(`router`,`isActiveRoute`),sn=i(`router`,`setRootPath`);function G(e,t){if(e.startsWith(`@@`))throw i(`router`,t).plain`Route name "${e}" uses the reserved "${`@@`}" prefix. Routes with this prefix are internal and cannot be modified through the public API.`}function cn(e,t){for(let n of e)n&&typeof n==`object`&&typeof n.name==`string`&&(G(n.name,t),n.children&&cn(n.children,t))}function ln(e){b(e,`removeRoute`)}function un(e){if(typeof e!=`string`)throw sn.type`rootPath must be a string, got ${x(e)}`}function K(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function dn(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw U.type`canActivate must be a function, got ${x(t.canActivate)}`;if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw U.type`canDeactivate must be a function, got ${x(t.canDeactivate)}`}function fn(e,t){let n=e;if(typeof n.decodeParams==`function`&&K(n.decodeParams))throw U.type`decodeParams cannot be async for route "${String(t)}"`;if(typeof n.encodeParams==`function`&&K(n.encodeParams))throw U.type`encodeParams cannot be async for route "${String(t)}"`;if(typeof n.forwardTo==`function`&&K(n.forwardTo))throw U.type`forwardTo callback cannot be async for route "${String(t)}"`}function pn(e,t){for(let n of e){if(typeof n!=`object`||!n||Array.isArray(n))throw U.type`Route must be an object, got ${x(n)}`;qe(n,w(t,n.name))}}function mn(e){if(typeof e!=`string`||e===``)throw U.type`parent option must be a non-empty string, got ${x(e)}`;b(e,`addRoute`)}function hn(e,t,n,r){if(!p(e))throw W.type`name must be a string, got ${typeof e}`;if(k(t,`isActiveRoute`),n!==void 0&&typeof n!=`boolean`)throw W.type`strictEquality must be a boolean, got ${typeof n}`;if(r!==void 0&&typeof r!=`boolean`)throw W.type`ignoreQueryParams must be a boolean, got ${typeof r}`}function q(e,t,n){if(!p(e))throw i(`router`,n).type`Invalid routeName: ${x(e)}. Expected string.`;if(!v(t))throw i(`router`,n).type`Invalid routeParams: ${x(t)}. Expected plain object.`}function gn(e,t){if(b(e,`updateRoute`),e===``)throw H.ref`Invalid name: empty string. Cannot update root node.`;if(t===null)throw H.type`updates must be an object, got null`;if(typeof t!=`object`||Array.isArray(t))throw H.type`updates must be an object, got ${x(t)}`}function _n(e,t){if(e.constructor.name===`AsyncFunction`||e.toString().includes(`__awaiter`))throw H.type`${t} cannot be an async function`}function J(e,t){if(e!=null){if(typeof e!=`function`)throw H.type`${t} must be a function or null, got ${typeof e}`;_n(e,t)}}function vn(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 H.type`forwardTo must be a string, function, or null, got ${x(t)}`;typeof t==`function`&&_n(t,`forwardTo callback`)}yn(n,`defaultParams`),yn(r,`defaultSearch`),J(i,`decodeParams`),J(a,`encodeParams`),J(o,`canActivate`),J(s,`canDeactivate`)}function yn(e,t){if(e!=null&&(typeof e!=`object`||Array.isArray(e)))throw H.type`${t} must be an object or null, got ${x(e)}`}function bn(e){if(!p(e)||e===``)throw on.type`route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`}function xn(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 Sn(e){if(!p(e))throw an.type`path must be a string, got ${typeof e}`}function Cn(e){if(!p(e))throw rn.type`nodeName must be a string, got ${typeof e}`}function wn(e,t,n,r,i){if(i){let e=t;for(let t of i.split(`.`))if(e=e.children.get(t),!e)throw U.ref`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);tt(e,r,n,i)}function Tn(e,t,n){let r=new Set(n.getUrlParams(e)),i=n.getUrlParams(t).filter(e=>!r.has(e));if(i.length>0)throw H.plain`forwardTo target "${t}" requires params [${i.join(`, `)}] that are not available in source route "${e}"`}function En(e,t,n){let r={...n,[e]:t};u(e,r)}function Dn(e,t,n,r){if(!n.hasRoute(e))throw H.ref`route "${e}" does not exist`;if(t!=null&&typeof t==`string`){if(!n.hasRoute(t))throw H.plain`forwardTo target "${t}" does not exist`;Tn(e,t,n),En(e,t,r)}}const Y=i(`router`,`makeState`),On=Object.entries;function kn(e,t,n){if(!p(e))throw Y.type`Invalid name: ${x(e)}. Expected string.`;if(t!==void 0&&!v(t))throw Y.type`Invalid params: ${x(t)}. Expected plain object.`;if(n!==void 0&&!p(n))throw Y.type`Invalid path: ${x(n)}. Expected string.`}function An(){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 jn(){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 Mn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function X(e,t){let n={params:{...t.params},search:{...t.search}};if(e===void 0)return n;let r=e(n),i=r.params??n.params,a=r.search??n.search;return Mn(i)&&Mn(a)?{params:i,search:a}:void 0}function Nn(e,t){try{return X(e,t)}catch{return}}function Z(e){return new Map(On(e).filter(([,e])=>e!==void 0))}function Pn(e){return typeof e==`number`||typeof e==`boolean`?String(e):e}function Fn(e,t){let n=Z(e.params);return{params:Object.fromEntries(t.filter(e=>n.has(e)).map(e=>[e,Pn(n.get(e))])),search:e.search}}function Q(e){return Array.isArray(e)?e.some(e=>Q(e)):typeof e==`object`&&!!e}function In(e,t,n){if(a(e,t))return!0;if(!Q(e)&&!Q(t))return!1;let[r,i]=n();return a(r,i)}function Ln(e,t,n){let r=X(t.encode,e);if(r===void 0)return[];let i=X(t.decode,Fn(r,n));if(i===void 0)return[];let a=(n,i,a)=>[r[n][i],Nn(t.encode,{...e,[n]:{...e[n],[i]:a}})?.[n][i]],o=[];for(let t of[`params`,`search`]){let r=Z(e[t]),s=Z(i[t]);for(let[e,n]of s)r.has(e)?In(r.get(e),n,()=>a(t,e,n))||o.push([t,e,`changed`]):o.push([t,e,`added`]);for(let e of r.keys())!s.has(e)&&(t===`search`||n.includes(e))&&o.push([t,e,`dropped`])}return o}function Rn(e){return e.decode===void 0?`The route has an encodeParams and no decodeParams to undo it.`:e.encode===void 0?`With no encodeParams, decodeParams must return each value so that it prints as the URL shows it.`:`decodeParams must undo encodeParams.`}function zn(e,t,n,r,i){let a=`Route "${e}": its codec`;switch(r){case`added`:return`${a} adds "${n}" to state.${t}, so a link commits a state without it and a reload of the same URL commits one with it. Derive "${n}" in a forwardState interceptor instead: navigate and matchPath both run it.`;case`changed`:return`${a} changes "${n}" in state.${t}, so a link and a reload of the same URL commit different values. ${Rn(i)}`;case`dropped`:return`${a} drops "${n}" from state.${t}, so a reload of the URL a link builds loses it. ${Rn(i)}`}}function Bn(e){let t=new Set;return function(n,r,i){let a;try{a=Ln(n,r,i)}catch{return}for(let[i,o,s]of a){let a=`${n.name} ${i} ${o}`;t.has(a)||(t.add(a),e.warn(`router`,zn(n.name,i,o,s,r)))}}}const Vn=i(`validation-plugin`),Hn=i(`router`,`addRoute`),$=i(`router`,`areStatesEqual`);function Un(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Wn(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)}}const Gn={hasRoute:()=>!1,getUrlParams:()=>[]};function Kn(e){return{tree:{...e,children:new Map,nonAbsoluteChildren:[]},lookup:Gn,forwardMap:{}}}function qn(e,t){let n=[];for(let r of e.getTree().children.keys())n.push(t.get(r));return n}function Jn(e,t,n){let r=xn(t=>e.getDeclaredQueryNames(t));return{routes:{validateBuildPathArgs(e,t){bn(e),r(e,t)},validateMatchPathArgs:Sn,validateIsActiveRouteArgs(e,t,n,i){hn(e,t,n,i),r(e,t)},validateShouldUpdateNodeArgs:Cn,validateStateBuilderArgs:q,validateRouteName(e,t){b(e,t)},validateSetRootPathArgs:un},options:{validateOptions:Mt,validateResolvedDefaultRoute(e){tn(e,t)}},dependencies:{validateDependencyName:ke,validateSetDependencyArgs(e,t,n){Ae(e)},validateDependenciesObject(t,n){je(t,n),Me(t,e.getDependencyKeys(),e.getResolvedLimits().maxDependencies,n)},validateDependencyExists(e,t){Ne(t,e)},validateDependencyCount(t,n,r){Pe(t,n,r,e.logger)},validateCloneArgs:Fe,warnOverwrite(t,n){Ie(t,n,e.logger)},warnBatchOverwrite(t,n){Le(t,n,e.logger)},warnRemoveNonExistent(t){Re(t,e.logger)}},plugins:{validatePluginLimit(e,t){Ft(e,1,t?.maxPlugins)},validateNoDuplicatePlugins:It,validatePluginKeys:Rt,validateCountThresholds(t){Lt(t,e.getOptions().limits?.maxPlugins??d.maxPlugins,e.logger)},warnBatchDuplicates(){zt(e.logger)},warnPluginMethodType(t){Bt(t,e.logger)}},lifecycle:{validateHandlerLimit(t,n){rt(t,n,e.getOptions().limits?.maxLifecycleHandlers??d.maxLifecycleHandlers)},validateCountThresholds(t,n){it(t,n,e.getOptions().limits?.maxLifecycleHandlers??d.maxLifecycleHandlers,e.logger)},warnOverwrite(t,n,r){at(t,n,r,e.logger)},warnAsyncGuardSync(t,n){ot(t,n,e.logger)},warnNonBooleanGuardSync(t,n,r){ct(t,n,r,e.logger)},warnNonBooleanGuard(t,n){lt(t,n,e.logger)}},navigation:{validateNavigateToDefaultArgs(t){ht(t),n.check(e.logger)},validateNavigateToStateArgs:gt,validateNavigationOptions:O,validateParamsShape:k,validateSearch:j,validateStartArgs:yt},state:{validateMakeStateArgs:kn,reportDroppedQueryKey:An(),reportUndeclaredParamKey:jn(),reportCodecRoundTrip:Bn(e.logger),validateAreStatesEqualArgs(e,t,n){if(!ge(e))throw $.type`Invalid state1: ${x(e)}. Expected State object.`;if(!ge(t))throw $.type`Invalid state2: ${x(t)}. Expected State object.`;if(n!==void 0&&!m(n))throw $.type`Invalid ignoreQueryParams: ${x(n)}. Expected boolean.`;if(n===!1){if(!Un(e.search))throw $.type`Invalid state1.search: ${x(e.search)}. Expected a plain object.`;if(!Un(t.search))throw $.type`Invalid state2.search: ${x(t.search)}. Expected a plain object.`}}},eventBus:{validateListenerArgs(e,t){Ue(e,t)},validateCountThresholds(t,n,r){let i=e.getOptions().limits?.maxListeners??d.maxListeners;We(t,n,r,e.logger,i)}}}}function Yn(){return n=>{let r=c(n),i=e(n);if(n.isActive())throw Vn.code(`VALIDATION_PLUGIN_AFTER_START`)`must be registered before router.start()`;if(r.validator!==null)throw Vn.code(`VALIDATION_PLUGIN_ALREADY_INSTALLED`)`is already installed on this router — a clone re-runs plugin factories, so it needs no usePlugin of its own`;let a=new xe;a.watch(i.getAdoptedOrigins());let o=Wn(i),s=Jn(i,o,a),l=()=>{r.validator===s&&(r.validator=null)};r.validator=s;try{let e=qn(i,t(n)),a=i.getForwardMap(),s=i.getResolvedLimits(),c=i.getOptions();Kt(e),qt(a,o),Yt(e),Xt(a,o),Zt(r.dependenciesGetStore().dependencies,s),Qt(c,i.getDependencyKeys().length,s.maxDependencies),r.validator.options.validateOptions(c,`constructor (retrospective)`),typeof c.defaultRoute==`string`&&en(c.defaultRoute,o)}catch(e){throw l(),e}let ee=i.addInterceptor(`start`,(e,t)=>{try{nn(i.getExternalGuardNames(),o,i.logger)}catch{}return e(t)}),u=i.addCheck(`buildPath:params`,e=>{A(e,`buildPath`)}),d=i.addCheck(`buildPathResolved:params`,e=>{A(e,`buildPathResolved`)}),f=i.addCheck(`canNavigateTo:entry`,(e,t,n)=>{b(e,`canNavigateTo`),k(t,`canNavigateTo`),j(n,`canNavigateTo`)}),p=i.addCheck(`canNavigateTo:params`,e=>{A(e,`canNavigateTo`)}),m=i.addCheck(`navigate:entry`,(e,t,n,r)=>{mt(e),k(t,`navigate`),j(n,`navigate`),O(r,`navigate`)}),te=i.addCheck(`navigate:params`,e=>{A(e,`navigate`)}),h=(e,t)=>{for(let n of e){let e=w(t,n.name);dn(n),fn(n,e),n.children!==void 0&&h(n.children,e)}},g=(e,t,n,r)=>{if(h(e,typeof n==`string`&&o.hasRoute(n)?n:void 0),n!==void 0&&(mn(n),!o.hasRoute(n)))throw Hn.ref`Parent route "${n}" does not exist`;cn(e,t),pn(e,n);let i=r();wn(e,i.tree,i.lookup,i.forwardMap,n)},ne=i.addCheck(`addRoute:batch`,(e,t)=>{g(e,`addRoute`,t,()=>({tree:i.getTree(),lookup:o,forwardMap:i.getForwardMap()}))}),re=i.addCheck(`replaceRoutes:batch`,e=>{g(e,`replaceRoutes`,void 0,()=>Kn(i.getTree()))}),ie=i.addCheck(`removeRoute:entry`,e=>{ln(e),G(e,`removeRoute`)}),ae=i.addCheck(`updateRoute:entry`,(e,t)=>{let n=t;gn(e,t),G(e,`updateRoute`),vn({forwardTo:n.forwardTo,defaultParams:n.defaultParams,defaultSearch:n.defaultSearch,decodeParams:n.decodeParams,encodeParams:n.encodeParams,canActivate:n.canActivate,canDeactivate:n.canDeactivate}),Dn(e,n.forwardTo,o,i.getForwardMap())}),_=i.addCheck(`hasRoute:entry`,e=>{b(e,`hasRoute`)}),oe=i.addCheck(`getRoute:entry`,e=>{b(e,`getRoute`)}),se=i.addCheck(`forwardState:entry`,(e,t,n)=>{q(e,t,`forwardState`),j(n,`forwardState`)}),ce=i.addCheck(`buildNavigationState:state`,(e,t,n)=>{j(n,`buildNavigationState`),q(e,t,`buildNavigationState`)}),v=i.addCheck(`addActivateGuard:entry`,(e,t)=>{b(e,`addActivateGuard`),nt(t,`addActivateGuard`)}),le=i.addCheck(`addDeactivateGuard:entry`,(e,t)=>{b(e,`addDeactivateGuard`),nt(t,`addDeactivateGuard`)}),ue=i.addCheck(`removeActivateGuard:entry`,e=>{b(e,`removeActivateGuard`)}),de=i.addCheck(`removeDeactivateGuard:entry`,e=>{b(e,`removeDeactivateGuard`)}),fe=i.subscribeDiagnostic(`PLUGIN_AFTER_START`,e=>{Vt(e,i.logger)});return{teardown(){u(),d(),f(),p(),m(),te(),ne(),re(),ie(),ae(),_(),oe(),se(),ce(),v(),le(),ue(),de(),fe(),ee(),l()}}}}export{Yn as validationPlugin};
1
+ import{getPluginApi as e,getRoutesApi as t}from"@real-router/core/api";import{internalDefect as n,putField as r,raiser as i}from"@real-router/core/utils";import{areParamValuesEqual as a,buildParamMeta as o,findMisChanneledKey as s,getInternals as c,validateRoute as l}from"@real-router/core/validation";import{events as u,resolveForwardChain as d}from"@real-router/core";const f=Object.freeze({maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxLifecycleHandlers:200});function p(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}function m(e){return typeof e==`string`}function h(e){return typeof e==`boolean`}function ee(e,t){return e in t}const g=Object.getPrototypeOf,_=Object.values,v=Object.hasOwn;function te(e){if(Array.isArray(e))return!0;let t=g(e);return t===null||t===Object.prototype}function ne(e,t){let n=Array.isArray(e)?e:_(e);for(let e of n)t.push(e)}function re(e){let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}var y=class{container;constructor(e){this.container=e}};function ie(e,t,n,r){return n.has(e)?!1:r.has(e)?!0:te(e)?(n.add(e),t.push(new y(e)),ne(e,t),!0):!1}function ae(e){let t=[e],n=new WeakSet,r=new WeakSet;for(;t.length>0;){let e=t.pop();if(e instanceof y)n.delete(e.container),r.add(e.container);else if(e!=null){if(typeof e==`object`){if(!ie(e,t,n,r))return!1}else if(!re(e))return!1}}return!0}function oe(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}function b(e){try{return se(e)}catch{return!1}}function se(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=g(e);if(t!==null&&t!==Object.prototype)return!1;let n=!1;for(let t in e){if(!v(e,t))continue;let r=e[t];if(!oe(r)){let e=typeof r;if(e===`function`||e===`symbol`)return!1;n=!0;break}}return!n||ae(e)}const ce=[`replace`,`reload`,`force`,`forceDeactivate`,`redirected`,`revalidate`];function le(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;for(let e of ce){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 ue=/\S/,x=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function S(e,t){return i(`router`,e).type`${t}`}function de(e){return typeof e==`string`?e===``?!0:e.length>1e4?!1:e.startsWith(`@@`)?!0:x.test(e):!1}function fe(e){return de(e.name)&&typeof e.path==`string`&&b(e.params)}function pe(e){return typeof e!=`object`||!e?!1:fe(e)}function C(e,t){if(typeof e!=`string`)throw S(t,`Route name must be a string, got ${typeof e}`);if(e!==``){if(!ue.test(e))throw S(t,`Route name cannot contain only whitespace`);if(e.length>1e4)throw S(t,`Route name exceeds maximum length of 10000 characters. This is a technical safety limit.`);if(!e.startsWith(`@@`)&&!x.test(e))throw S(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 w(e){if(e===null)return`null`;if(typeof e!=`object`)return typeof e;try{if(Array.isArray(e))return`array[${e.length}]`;let t=e.constructor;if(typeof t==`function`){let e=t.name;if(typeof e==`string`&&e!==``&&e!==`Object`)return e}}catch{}return`object`}const me=Object.entries,he=[`defaultParams`,`defaultSearch`],ge=e=>new Map(me(e)),_e=(e,t)=>{let n=me(e);return n.length!==t.size||n.some(([e,n])=>!t.has(e)||!Object.is(t.get(e),n))};var ve=class{#e=new Map;#t=new Set;watch(e){for(let t of he){let n=e[t],r=n?.deref();n!==void 0&&r!==void 0&&this.#e.set(t,{ref:n,before:ge(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&&_e(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 ye=i(`cloneRouter`),be=i(`router`,`getDependency`),xe=i(`router`,`setDependency`),T=Object.keys,Se=Object.getOwnPropertyDescriptor,Ce=Object.getPrototypeOf,we=Object;function Te(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=Ce(e);return t===null||t.constructor===we}function Ee(e,t){if(typeof e!=`string`)throw i(`router`,t).type`dependency name must be a string, got ${typeof e}`}function De(e){if(typeof e!=`string`)throw xe.type`dependency name must be a string, got ${typeof e}`}function Oe(e,t){if(!Te(e))throw i(`router`,t).type`Invalid argument: expected plain object, received ${w(e)}`;for(let n of T(e))if(Se(e,n)?.get)throw i(`router`,t).type`Getters not allowed: "${n}"`}function ke(e,t,n,r){if(n===0)return;let a=new Set(t),o=0;for(let t of T(e))a.has(t)||(o+=1);let s=t.length;if(s+o>n)throw i(`router`,r).range`Dependency limit exceeded (${n}). Current: ${s}, this batch adds ${o}.`}function Ae(e,t){if(e===void 0)throw be.ref`dependency "${t}" not found`}function je(e,t,n,r){if(t===0)return;let{warn:a,error:o}=p(t);if(e>=t)throw i(`router`,n).range`Dependency limit exceeded (${t}). Current: ${e}.`;e===o?r.error(`router.${n}`,`${e} dependencies registered! This indicates architectural problems. Hard limit at ${t}.`):e===a&&r.warn(`router.${n}`,`${e} dependencies registered. Consider if all are necessary.`)}function Me(e){if(e!==void 0){if(!Te(e))throw ye.type`Invalid dependencies: expected plain object or undefined, received ${typeof e}`;for(let t of T(e))if(Se(e,t)?.get)throw ye.type`Getters not allowed in dependencies: "${t}"`}}function Ne(e,t,n){n.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function Pe(e,t,n){n.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function Fe(e,t){t.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const Ie=i(`router`,`addEventListener`),Le=Object.values,Re=new Set(Le(u));function ze(e){if(!Re.has(e))throw Ie.type`Invalid event name: ${String(e)}. Must be one of: $start, $stop, $$start, $$leaveApprove, $$cancel, $$success, $$error`}function Be(e,t){if(ze(e),typeof t!=`function`)throw Ie.type`callback must be a function, got ${typeof t}`}function Ve(e,t,n,r,i=f.maxListeners){if(i===0)return;let{warn:a,error:o}=p(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.`)}const E=i(`router`,`addRoute`),He=Object.keys;function D(e,t){return typeof e==`string`&&e!==``&&typeof t==`string`?`${e}.${t}`:t}function Ue(e,t){if(e!==void 0){if(typeof e!=`string`&&typeof e!=`function`)throw E.type`forwardTo must be a string or function for route "${t}", got ${w(e)}`;if(typeof e==`function`){let n=e.constructor.name===`AsyncFunction`,r=e.toString().includes(`__awaiter`);if(n||r)throw E.type`forwardTo callback cannot be async for route "${t}". Async functions break matchPath/buildPath.`}}}function We(e,t,n){if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))throw E.type`${t} must be an object for route "${n}", got ${w(e)}`}function Ge(e,t){if(e.canActivate!==void 0&&typeof e.canActivate!=`function`)throw E.type`canActivate must be a function for route "${t}", got ${w(e.canActivate)}`;if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw E.type`canDeactivate must be a function for route "${t}", got ${w(e.canDeactivate)}`;We(e.defaultParams,`defaultParams`,t),We(e.defaultSearch,`defaultSearch`,t);let{decodeParams:n,encodeParams:r}=e;if(typeof n==`function`&&n.constructor.name===`AsyncFunction`)throw E.type`decodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`;if(typeof r==`function`&&r.constructor.name===`AsyncFunction`)throw E.type`encodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`;if(Ue(e.forwardTo,t),e.children)for(let n of e.children)Ge(n,D(t,n.name))}function Ke(e){let t=new Set;for(let n of e)for(let e of o(n).urlParams)t.add(e);return t}function qe(e,t,r=``,i=[]){for(let n of e){let e=r?`${r}.${n.name}`:n.name,a=[...i,n.path];if(e===t)return a;if(n.children&&t.startsWith(`${e}.`))return qe(n.children,t,e,a)}throw n.plain`collectPathsToRoute: route "${t}" not found`}function Je(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 Je(r.children,e))n.add(t)}return n}function Ye(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 Ye(r.children,e))n.set(t,i)}return n}function Xe(e,t,n,r){return t?new Set(n.getUrlParams(e)):Ke(r(e))}const Ze=new Set;function Qe(e,t,n,r,i,a){let o=i.hasRoute(t),s=r.has(t);if(!o&&!s)throw E.ref`forwardTo target "${t}" does not exist for route "${e}"`;let c=new Set([...a,...Ke(n(e))]),l=[...Xe(t,o,i,n)].filter(e=>!c.has(e));if(l.length>0)throw E.plain`forwardTo target "${t}" requires params [${l.join(`, `)}] that are not available in source route "${e}"`}function $e(e,t,n,i){let a=Je(e,i),o=t=>qe(e,i?t.slice(i.length+1):t),s=i?new Set(n.getUrlParams(i)):Ze,c=Ye(e,i),l={...t};for(let[e,t]of c)r(l,e,t);for(let[e,t]of c)Qe(e,t,o,a,n,s);for(let e of He(l))d(e,l)}function et(e,t){if(!h(e)&&typeof e!=`function`)throw i(`router`,t).type`Handler must be a boolean or factory function, got ${w(e)}`}function tt(e,t,n=f.maxLifecycleHandlers){if(n!==0&&e>=n)throw i(`router`,t).range`Lifecycle handler limit exceeded (${n}). This indicates too many routes with individual handlers. Consider using plugins for cross-cutting concerns.`}function nt(e,t,n,r){if(n===0)return;let{warn:i,error:a}=p(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 rt(e,t,n,r){r.warn(`router.${n}`,`Overwriting existing ${t} handler for route "${e}"`)}function it(e,t,n){n.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}function at(e,t){return`Guard for "${e}" must answer true or false, got ${w(t)} — read as a refusal.`}function ot(e,t,n,r){r.warn(`router.${n}`,at(e,t))}function st(e,t,n){n.warn(`router`,at(e,t))}const O=i(`router`,`start`),k=i(`router`,`navigateToState`),ct=i(`router`,`navigateToDefault`),lt=i(`router`,`navigate`),ut=Object.hasOwn,dt=Object.getPrototypeOf;function ft(e){if(typeof e!=`string`)throw lt.type`Invalid route name: expected string, got ${w(e)}`}function pt(e){if(e!==void 0&&(typeof e!=`object`||!e))throw ct.type`Invalid options: ${w(e)}. Expected NavigationOptions object.`}function mt(e){if(typeof e!=`object`||!e)throw k.type`Invalid state: ${w(e)}. Expected State object.`;let t=e;if(!m(t.name))throw k.type`Invalid state.name: ${w(t.name)}. Expected string.`;if(!b(t.params))throw k.type`Invalid state.params: ${w(t.params)}. Expected plain object.`;if(!m(t.path))throw k.type`Invalid state.path: ${w(t.path)}. Expected string.`}function ht(e,t){if(!le(e))throw i(`router`,t).type`Invalid options: ${w(e)}. Expected NavigationOptions object.`}const gt=/[\u0000-\u001F\u007F]/;function _t(e,t){for(let n in e){if(!ut(e,n))continue;let r=e[n],a=typeof r;if(a===`symbol`||a===`bigint`)throw i(`router`,t).type`param "${n}" cannot be a ${a} — it does not round-trip through the URL path. Use a string, number, or boolean.`;if(a===`string`&&gt.test(r))throw i(`router`,t).type`param "${n}" must not contain control characters (NUL / C0 / DEL) — they corrupt the URL path.`}}function A(e,t){if(e===void 0)return;let n=e!==null&&dt(e);if(Array.isArray(e)||n!==null&&n!==Object.prototype)throw i(`router`,t).type`params must be a plain object, got ${w(e)}`}function j(e,t){if(e!==void 0&&(_t(e,t),!b(e)))throw i(`router`,t).type`params must be a plain object, got ${w(e)}`}function M(e,t){if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))throw i(`router`,t).type`search must be a plain object, got ${w(e)}`}function vt(e){if(e!==void 0&&typeof e!=`string`)throw O.type`path must be a string, got ${w(e)}.`;if(typeof e==`string`){if(gt.test(e))throw O.type`path must not contain control characters (NUL / C0 / DEL).`;if(e!==``&&!e.startsWith(`/`))throw O.type`path must start with "/", got "${e}".`}}const yt=Object.entries,bt=Object.hasOwn,N=Object.keys,xt=Object.getPrototypeOf,P={trailingSlash:[`strict`,`never`,`always`,`preserve`],queryParamsMode:[`default`,`strict`,`loose`],urlParamsEncoding:[`default`,`uri`,`uriComponent`,`none`]},St={arrayFormat:!0,booleanFormat:!0,nullFormat:!0,numberFormat:!0},Ct=new Set(N({defaultRoute:!0,defaultParams:!0,defaultSearch:!0,trailingSlash:!0,caseSensitive:!0,queryParamsMode:!0,queryParams:!0,urlParamsEncoding:!0,allowNotFound:!0,rewritePathOnMatch:!0,logger:!0,limits:!0})),wt={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 Tt(e,t,n){if(typeof t!=`number`||!Number.isInteger(t))throw i(`router`,n).type`limit "${e}" must be an integer, got ${String(t)}`;let r=wt[e];if(t<r.min||t>r.max)throw i(`router`,n).range`limit "${e}" must be between ${r.min} and ${r.max}, got ${t}`}function Et(e){let t=xt(e);return t===null||t===Object.prototype}function Dt(e,t){if(!e||typeof e!=`object`||!Et(e))throw i(`router`,t).type`invalid limits: expected plain object, got ${typeof e}`;for(let[n,r]of yt(e)){if(!bt(wt,n))throw i(`router`,t).type`unknown limit: "${n}"`;r!==void 0&&Tt(n,r,t)}let{warnListeners:n,maxListeners:r}=e;if(typeof n==`number`&&typeof r==`number`&&r>0&&n>r)throw i(`router`,t).range`"limits.warnListeners" (${n}) must not exceed "limits.maxListeners" (${r}) — the warning channel would be unreachable`}function F(e,t,n,r){if(e!==void 0&&(typeof e!=`string`||!n.includes(e))){let a=n.map(e=>`"${e}"`).join(`, `),o=typeof e==`string`?e:`(${typeof e})`;throw i(`router`,r).type`Invalid "${t}": "${o}". Must be one of: ${a}`}}function Ot(e,t){if(e!==void 0&&typeof e!=`string`&&typeof e!=`function`)throw i(`router`,t).type`Invalid "defaultRoute": expected string or function, got ${typeof e}`}function kt(e,t,n){if(e!==void 0&&typeof e!=`function`&&(!e||typeof e!=`object`||Array.isArray(e)||!Et(e)))throw i(`router`,n).type`Invalid "${t}": expected plain object or function, got ${typeof e}`}function At(e,t){if(e===void 0)return;if(!e||typeof e!=`object`||Array.isArray(e))throw i(`router`,t).type`Invalid "queryParams": expected plain object`;let n=e;for(let e of N(n))if(!ee(e,St))throw i(`router`,t).type`Invalid "queryParams.${e}": unknown option`}function jt(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw i(`router`,t).type`Invalid options: expected plain object`;let n=e;for(let e of N(n))if(!Ct.has(e))throw i(`router`,t).type`Unknown option: "${e}"`;if(Ot(n.defaultRoute,t),kt(n.defaultParams,`defaultParams`,t),kt(n.defaultSearch,`defaultSearch`,t),F(n.trailingSlash,`trailingSlash`,P.trailingSlash,t),F(n.queryParamsMode,`queryParamsMode`,P.queryParamsMode,t),F(n.urlParamsEncoding,`urlParamsEncoding`,P.urlParamsEncoding,t),n.allowNotFound!==void 0&&typeof n.allowNotFound!=`boolean`)throw i(`router`,t).type`Invalid "allowNotFound": expected boolean, got ${typeof n.allowNotFound}`;if(n.rewritePathOnMatch!==void 0&&typeof n.rewritePathOnMatch!=`boolean`)throw i(`router`,t).type`Invalid "rewritePathOnMatch": expected boolean, got ${typeof n.rewritePathOnMatch}`;if(n.caseSensitive!==void 0&&typeof n.caseSensitive!=`boolean`)throw i(`router`,t).type`Invalid "caseSensitive": expected boolean, got ${typeof n.caseSensitive}`;At(n.queryParams,t),n.limits!==void 0&&Dt(n.limits,t)}const I=i(`router`,`usePlugin`),Mt=Object.hasOwn,L=`router.usePlugin`,Nt={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function Pt(e,t,n=f.maxPlugins){if(n!==0&&e+t>n)throw I.range`Plugin limit exceeded (${n}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating plugins.`}function Ft(e,t){if(t.includes(e))throw I.plain`Plugin factory already registered. To re-register, first unsubscribe the existing plugin.`}function It(e,t,n){if(t===0)return;let{warn:r,error:i}=p(t);e>=i?n.error(L,`${e} plugins registered! This is excessive. Hard limit at ${t}.`):e>=r&&n.warn(L,`${e} plugins registered. Consider if all are necessary.`)}function Lt(e){for(let t in e)if(!(t===`teardown`||Mt(Nt,t)))throw I.type`Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`}function Rt(e){e.warn(L,`Duplicate factory in batch, will be registered once`)}function zt(e,t){t.warn(L,`Property '${e}' is not a function, skipping`)}function Bt(e,t){e===`onStart`&&t.warn(L,`Router already started, onStart will not be called`)}const Vt=i(`router`,`navigateToDefault`),R=i(`validation-plugin`),z=Object.entries,Ht=Object.getOwnPropertyDescriptor,Ut=Object.keys;function B(e,t,n=``){for(let r of e){let e=n?`${n}.${r.name}`:r.name;t(r,e),r.children&&B(r.children,t,e)}}function V(e,t){let n=[];return B(e,(e,r)=>{let i=t(e);i!==void 0&&n.push([r,i])}),n}function Wt(e,t){try{return d(e,t)}catch(e){let t=e.message.replace(/^\[router\] /u,``);throw R.plain({cause:e})`${t}`}}function H(e,t,n){let r=e;if(r.constructor.name===`AsyncFunction`||r.toString().includes(`__awaiter`))throw R.type`Route "${n}" ${t} cannot be async`}function Gt(e){B(e,(e,t)=>{if(typeof e.name!=`string`||!e.name)throw R.type`validateExistingRoutes: route has invalid name: ${e.name}`;if(typeof e.path!=`string`)throw R.type`validateExistingRoutes: route "${t}" has non-string path (${typeof e.path})`})}function Kt(e,t){for(let[n,r]of z(e)){if(!t.hasRoute(r))throw R.plain`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 R.plain`validateForwardToConsistency: forwardTo target "${r}" requires params [${i.join(`, `)}] not available in source route "${n}"`}for(let t of Ut(e))Wt(t,e)}function qt(e,t){for(let[n,r]of e)if(typeof r!=`object`||!r||Array.isArray(r))throw R.type`validateRoutePropertiesStore: route "${n}" ${t} must be a plain object, got ${Array.isArray(r)?`array`:typeof r}`}function Jt(e){let t=V(e,e=>e.decodeParams),n=V(e,e=>e.encodeParams),r=V(e,e=>typeof e.forwardTo==`string`?void 0:e.forwardTo);for(let[e,n]of t){if(typeof n!=`function`)throw R.type`validateRoutePropertiesStore: route "${e}" decoder must be a function, got ${typeof n}`;H(n,`decoder`,e)}for(let[e,t]of n){if(typeof t!=`function`)throw R.type`validateRoutePropertiesStore: route "${e}" encoder must be a function, got ${typeof t}`;H(t,`encoder`,e)}qt(V(e,e=>e.defaultParams),`defaultParams`),qt(V(e,e=>e.defaultSearch),`defaultSearch`);for(let[e,t]of r){if(typeof t!=`function`)throw R.type`validateRoutePropertiesStore: route "${e}" forwardTo callback must be a function, got ${typeof t}`;H(t,`forwardTo callback`,e)}}function Yt(e,t){for(let[n,r]of z(e))if(!t.hasRoute(r))throw R.plain`validateForwardToTargetsStore: forwardTo target "${r}" does not exist for route "${n}"`}function Xt(e,t){for(let t of Ut(e))if(Ht(e,t)?.get)throw R.type`validateDependenciesStructure: dependency "${t}" must not use a getter`;for(let[e,n]of z(t))if(!Number.isInteger(n))throw R.type`validateDependenciesStructure: deps.limits.${e} must be an integer, got ${String(n)}`}function Zt(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 R.range`validateLimitsConsistency: dependency count (${t}) exceeds maxDependencies limit (${a})`}function Qt(e,t){return typeof e==`string`&&e!==``&&!t.hasRoute(e)}function $t(e,t){if(Qt(e,t))throw R.plain`defaultRoute resolved to non-existent route: "${e}"`}function en(e,t){if(Qt(e,t))throw Vt.plain`defaultRoute callback resolved to non-existent route: "${e}"`}function tn(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 U=i(`router`,`updateRoute`),W=i(`router`,`addRoute`),nn=i(`router`,`shouldUpdateNode`),rn=i(`router`,`matchPath`),an=i(`router`,`buildPath`),G=i(`router`,`isActiveRoute`),on=i(`router`,`setRootPath`);function K(e,t){if(e.startsWith(`@@`))throw i(`router`,t).plain`Route name "${e}" uses the reserved "${`@@`}" prefix. Routes with this prefix are internal and cannot be modified through the public API.`}function sn(e,t){for(let n of e)n&&typeof n==`object`&&typeof n.name==`string`&&(K(n.name,t),n.children&&sn(n.children,t))}function cn(e){C(e,`removeRoute`)}function ln(e){if(typeof e!=`string`)throw on.type`rootPath must be a string, got ${w(e)}`}function q(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function un(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw W.type`canActivate must be a function, got ${w(t.canActivate)}`;if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw W.type`canDeactivate must be a function, got ${w(t.canDeactivate)}`}function dn(e,t){let n=e;if(typeof n.decodeParams==`function`&&q(n.decodeParams))throw W.type`decodeParams cannot be async for route "${String(t)}"`;if(typeof n.encodeParams==`function`&&q(n.encodeParams))throw W.type`encodeParams cannot be async for route "${String(t)}"`;if(typeof n.forwardTo==`function`&&q(n.forwardTo))throw W.type`forwardTo callback cannot be async for route "${String(t)}"`}function fn(e,t){for(let n of e){if(typeof n!=`object`||!n||Array.isArray(n))throw W.type`Route must be an object, got ${w(n)}`;Ge(n,D(t,n.name))}}function pn(e){if(typeof e!=`string`||e===``)throw W.type`parent option must be a non-empty string, got ${w(e)}`;C(e,`addRoute`)}function mn(e,t,n,r){if(!m(e))throw G.type`name must be a string, got ${typeof e}`;if(A(t,`isActiveRoute`),n!==void 0&&typeof n!=`boolean`)throw G.type`strictEquality must be a boolean, got ${typeof n}`;if(r!==void 0&&typeof r!=`boolean`)throw G.type`ignoreQueryParams must be a boolean, got ${typeof r}`}function J(e,t,n){if(!m(e))throw i(`router`,n).type`Invalid routeName: ${w(e)}. Expected string.`;if(!b(t))throw i(`router`,n).type`Invalid routeParams: ${w(t)}. Expected plain object.`}function hn(e,t){if(C(e,`updateRoute`),e===``)throw U.ref`Invalid name: empty string. Cannot update root node.`;if(t===null)throw U.type`updates must be an object, got null`;if(typeof t!=`object`||Array.isArray(t))throw U.type`updates must be an object, got ${w(t)}`}function gn(e,t){if(e.constructor.name===`AsyncFunction`||e.toString().includes(`__awaiter`))throw U.type`${t} cannot be an async function`}function Y(e,t){if(e!=null){if(typeof e!=`function`)throw U.type`${t} must be a function or null, got ${typeof e}`;gn(e,t)}}function _n(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 U.type`forwardTo must be a string, function, or null, got ${w(t)}`;typeof t==`function`&&gn(t,`forwardTo callback`)}vn(n,`defaultParams`),vn(r,`defaultSearch`),Y(i,`decodeParams`),Y(a,`encodeParams`),Y(o,`canActivate`),Y(s,`canDeactivate`)}function vn(e,t){if(e!=null&&(typeof e!=`object`||Array.isArray(e)))throw U.type`${t} must be an object or null, got ${w(e)}`}function yn(e){if(!m(e)||e===``)throw an.type`route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`}function bn(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 xn(e){if(!m(e))throw rn.type`path must be a string, got ${typeof e}`}function Sn(e){if(!m(e))throw nn.type`nodeName must be a string, got ${typeof e}`}function Cn(e,t,n,r,i){if(i){let e=t;for(let t of i.split(`.`))if(e=e.children.get(t),!e)throw W.ref`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);$e(e,r,n,i)}function wn(e,t,n){let r=new Set(n.getUrlParams(e)),i=n.getUrlParams(t).filter(e=>!r.has(e));if(i.length>0)throw U.plain`forwardTo target "${t}" requires params [${i.join(`, `)}] that are not available in source route "${e}"`}function Tn(e,t,n){let r={...n,[e]:t};d(e,r)}function En(e,t,n,r){if(!n.hasRoute(e))throw U.ref`route "${e}" does not exist`;if(t!=null&&typeof t==`string`){if(!n.hasRoute(t))throw U.plain`forwardTo target "${t}" does not exist`;wn(e,t,n),Tn(e,t,r)}}const X=i(`router`,`makeState`),Dn=Object.entries;function On(e,t,n){if(!m(e))throw X.type`Invalid name: ${w(e)}. Expected string.`;if(t!==void 0&&!b(t))throw X.type`Invalid params: ${w(t)}. Expected plain object.`;if(n!==void 0&&!m(n))throw X.type`Invalid path: ${w(n)}. Expected string.`}function kn(){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 An(){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 Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function jn(e,t){let n={params:{...t.params},search:{...t.search}};if(e===void 0)return n;let r=e(n),i=r.params??n.params,a=r.search??n.search;return Z(i)&&Z(a)?{params:i,search:a}:void 0}function Mn(e,t){try{return jn(e,t)}catch{return}}function Q(e){return new Map(Dn(e).filter(([,e])=>e!==void 0))}function Nn(e){return Array.isArray(e)?e.some(e=>Nn(e)):typeof e==`object`&&!!e}function Pn(e,t){try{return e(t)}catch{return}}function Fn(e,t){let n=n=>{let r=Q(e[n]);return new Map([...Q(t[n])].filter(([e])=>!r.has(e)))};return{params:n(`params`),search:n(`search`)}}function In(e,t){return Object.fromEntries(Dn(e).filter(([e])=>!t.has(e)))}function Ln(e,t,n){if(n.params.size+n.search.size===0)return n;try{let r=t(e.name,In(e.params,n.params),In(e.search,n.search)),i=e=>{let t=Q(r[e]??{});return new Map([...n[e]].filter(([e,n])=>t.has(e)&&a(t.get(e),n)))};return{params:i(`params`),search:i(`search`)}}catch{return{params:new Map,search:new Map}}}function Rn(e,t,n,r){let i=Mn(e.codec.encode,{...e.state,[t]:{...e.state[t],[n]:r}});return i!==void 0&&a(e.encoded[t][n],i[t][n])}function zn(e,t,n){return e.credited[t].has(n)?void 0:`added`}function Bn(e,t,n,r,i){if(!Nn(i))return a(r,i)?void 0:`changed`;if(!Rn(e,t,n,i))return`changed`;if(!a(r,i))return a(i,e.readAgain()?.[t][n])?`undecoded`:`keyless`}function Vn(e,t){let n=Q(e.state[t]),r=Q(e.back[t]),i=[];for(let[a,o]of r){let r=n.has(a)?Bn(e,t,a,n.get(a),o):zn(e,t,a);r!==void 0&&i.push([t,a,r])}for(let a of n.keys())!r.has(a)&&(t===`search`||e.pathSlots.includes(a))&&i.push([t,a,`dropped`]);return i}function Hn(e,t,n,r,i){let a=r(e.path);if(a?.name!==e.name)return[];let o=jn(t.encode,e);if(o===void 0)return[];let s,c={state:e,codec:t,pathSlots:n,encoded:o,back:a,readAgain:()=>(s??={state:Pn(r,e.path)},s.state),credited:Ln(a,i,Fn(e,a))};return[...Vn(c,`params`),...Vn(c,`search`)]}function Un(e){return e.decode===void 0?`The route has an encodeParams and no decodeParams to undo it.`:e.encode===void 0?`With no encodeParams, decodeParams must return each value so that it prints as the URL shows it.`:`decodeParams must undo encodeParams.`}function Wn(e,t,n,r,i){let a=`Route "${e}": its codec`,o=`${a} changes "${n}" in state.${t}, so a link and a reload of the same URL commit different values.`;switch(r){case`added`:return`${a} adds "${n}" to state.${t}, so a link commits a state without it and a reload of the same URL commits one with it. Derive "${n}" in a forwardState interceptor instead: navigate and matchPath both run it.`;case`changed`:return`${o} ${Un(i)}`;case`undecoded`:return`${o} encodeParams prints both as one piece of the URL, so a link must pass the value decodeParams returns for that piece.`;case`keyless`:return`${o} Two reloads of one URL decode values that never compare equal: give the value a key — a Date, or a plain object JSON.stringify prints in full.`;case`dropped`:return`${a} drops "${n}" from state.${t}, so a reload of the URL a link builds loses it. ${Un(i)}`}}function Gn(e,t,n){let r=new Set;return function(i,a,o){let s;try{s=Hn(i,a,o,t,n)}catch{return}for(let[t,n,o]of s){let s=`${i.name} ${t} ${n}`;r.has(s)||(r.add(s),e.warn(`router`,Wn(i.name,t,n,o,a)))}}}const Kn=i(`validation-plugin`),qn=i(`router`,`addRoute`),$=i(`router`,`areStatesEqual`);function Jn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Yn(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)}}const Xn={hasRoute:()=>!1,getUrlParams:()=>[]};function Zn(e){return{tree:{...e,children:new Map,nonAbsoluteChildren:[]},lookup:Xn,forwardMap:{}}}function Qn(e,t){let n=[];for(let r of e.getTree().children.keys())n.push(t.get(r));return n}function $n(e,t,n,r){let i=bn(t=>e.getDeclaredQueryNames(t));return{routes:{validateBuildPathArgs(e,t){yn(e),i(e,t)},validateMatchPathArgs:xn,validateIsActiveRouteArgs(e,t,n,r){mn(e,t,n,r),i(e,t)},validateShouldUpdateNodeArgs:Sn,validateStateBuilderArgs:J,validateRouteName(e,t){C(e,t)},validateSetRootPathArgs:ln},options:{validateOptions:jt,validateResolvedDefaultRoute(e){en(e,t)}},dependencies:{validateDependencyName:Ee,validateSetDependencyArgs(e,t,n){De(e)},validateDependenciesObject(t,n){Oe(t,n),ke(t,e.getDependencyKeys(),e.getResolvedLimits().maxDependencies,n)},validateDependencyExists(e,t){Ae(t,e)},validateDependencyCount(t,n,r){je(t,n,r,e.logger)},validateCloneArgs:Me,warnOverwrite(t,n){Ne(t,n,e.logger)},warnBatchOverwrite(t,n){Pe(t,n,e.logger)},warnRemoveNonExistent(t){Fe(t,e.logger)}},plugins:{validatePluginLimit(e,t){Pt(e,1,t?.maxPlugins)},validateNoDuplicatePlugins:Ft,validatePluginKeys:Lt,validateCountThresholds(t){It(t,e.getOptions().limits?.maxPlugins??f.maxPlugins,e.logger)},warnBatchDuplicates(){Rt(e.logger)},warnPluginMethodType(t){zt(t,e.logger)}},lifecycle:{validateHandlerLimit(t,n){tt(t,n,e.getOptions().limits?.maxLifecycleHandlers??f.maxLifecycleHandlers)},validateCountThresholds(t,n){nt(t,n,e.getOptions().limits?.maxLifecycleHandlers??f.maxLifecycleHandlers,e.logger)},warnOverwrite(t,n,r){rt(t,n,r,e.logger)},warnAsyncGuardSync(t,n){it(t,n,e.logger)},warnNonBooleanGuardSync(t,n,r){ot(t,n,r,e.logger)},warnNonBooleanGuard(t,n){st(t,n,e.logger)}},navigation:{validateNavigateToDefaultArgs(t){pt(t),n.check(e.logger)},validateNavigateToStateArgs:mt,validateNavigationOptions:ht,validateParamsShape:A,validateSearch:M,validateStartArgs:vt},state:{validateMakeStateArgs:On,reportDroppedQueryKey:kn(),reportUndeclaredParamKey:An(),reportCodecRoundTrip:Gn(e.logger,r,e.forwardState),validateAreStatesEqualArgs(e,t,n){if(!pe(e))throw $.type`Invalid state1: ${w(e)}. Expected State object.`;if(!pe(t))throw $.type`Invalid state2: ${w(t)}. Expected State object.`;if(n!==void 0&&!h(n))throw $.type`Invalid ignoreQueryParams: ${w(n)}. Expected boolean.`;if(n===!1){if(!Jn(e.search))throw $.type`Invalid state1.search: ${w(e.search)}. Expected a plain object.`;if(!Jn(t.search))throw $.type`Invalid state2.search: ${w(t.search)}. Expected a plain object.`}}},eventBus:{validateListenerArgs(e,t){Be(e,t)},validateCountThresholds(t,n,r){let i=e.getOptions().limits?.maxListeners??f.maxListeners;Ve(t,n,r,e.logger,i)}}}}function er(){return n=>{let r=c(n),i=e(n);if(n.isActive())throw Kn.code(`VALIDATION_PLUGIN_AFTER_START`)`must be registered before router.start()`;if(r.validator!==null)throw Kn.code(`VALIDATION_PLUGIN_ALREADY_INSTALLED`)`is already installed on this router — a clone re-runs plugin factories, so it needs no usePlugin of its own`;let a=new ve;a.watch(i.getAdoptedOrigins());let o=e=>r.matchPath(e,{...i.getOptions(),rewritePathOnMatch:!1}),s=Yn(i),l=$n(i,s,a,o),u=()=>{r.validator===l&&(r.validator=null)};r.validator=l;try{let e=Qn(i,t(n)),a=i.getForwardMap(),o=i.getResolvedLimits(),c=i.getOptions();Gt(e),Kt(a,s),Jt(e),Yt(a,s),Xt(r.dependenciesGetStore().dependencies,o),Zt(c,i.getDependencyKeys().length,o.maxDependencies),r.validator.options.validateOptions(c,`constructor (retrospective)`),typeof c.defaultRoute==`string`&&$t(c.defaultRoute,s)}catch(e){throw u(),e}let d=i.addInterceptor(`start`,(e,t)=>{try{tn(i.getExternalGuardNames(),s,i.logger)}catch{}return e(t)}),f=i.addCheck(`buildPath:params`,e=>{j(e,`buildPath`)}),p=i.addCheck(`buildPathResolved:params`,e=>{j(e,`buildPathResolved`)}),m=i.addCheck(`canNavigateTo:entry`,(e,t,n)=>{C(e,`canNavigateTo`),A(t,`canNavigateTo`),M(n,`canNavigateTo`)}),h=i.addCheck(`canNavigateTo:params`,e=>{j(e,`canNavigateTo`)}),ee=i.addCheck(`navigate:entry`,(e,t,n,r)=>{ft(e),A(t,`navigate`),M(n,`navigate`),ht(r,`navigate`)}),g=i.addCheck(`navigate:params`,e=>{j(e,`navigate`)}),_=(e,t)=>{for(let n of e){let e=D(t,n.name);un(n),dn(n,e),n.children!==void 0&&_(n.children,e)}},v=(e,t,n,r)=>{if(_(e,typeof n==`string`&&s.hasRoute(n)?n:void 0),n!==void 0&&(pn(n),!s.hasRoute(n)))throw qn.ref`Parent route "${n}" does not exist`;sn(e,t),fn(e,n);let i=r();Cn(e,i.tree,i.lookup,i.forwardMap,n)},te=i.addCheck(`addRoute:batch`,(e,t)=>{v(e,`addRoute`,t,()=>({tree:i.getTree(),lookup:s,forwardMap:i.getForwardMap()}))}),ne=i.addCheck(`replaceRoutes:batch`,e=>{v(e,`replaceRoutes`,void 0,()=>Zn(i.getTree()))}),re=i.addCheck(`removeRoute:entry`,e=>{cn(e),K(e,`removeRoute`)}),y=i.addCheck(`updateRoute:entry`,(e,t)=>{let n=t;hn(e,t),K(e,`updateRoute`),_n({forwardTo:n.forwardTo,defaultParams:n.defaultParams,defaultSearch:n.defaultSearch,decodeParams:n.decodeParams,encodeParams:n.encodeParams,canActivate:n.canActivate,canDeactivate:n.canDeactivate}),En(e,n.forwardTo,s,i.getForwardMap())}),ie=i.addCheck(`hasRoute:entry`,e=>{C(e,`hasRoute`)}),ae=i.addCheck(`getRoute:entry`,e=>{C(e,`getRoute`)}),oe=i.addCheck(`forwardState:entry`,(e,t,n)=>{J(e,t,`forwardState`),M(n,`forwardState`)}),b=i.addCheck(`buildNavigationState:state`,(e,t,n)=>{M(n,`buildNavigationState`),J(e,t,`buildNavigationState`)}),se=i.addCheck(`addActivateGuard:entry`,(e,t)=>{C(e,`addActivateGuard`),et(t,`addActivateGuard`)}),ce=i.addCheck(`addDeactivateGuard:entry`,(e,t)=>{C(e,`addDeactivateGuard`),et(t,`addDeactivateGuard`)}),le=i.addCheck(`removeActivateGuard:entry`,e=>{C(e,`removeActivateGuard`)}),ue=i.addCheck(`removeDeactivateGuard:entry`,e=>{C(e,`removeDeactivateGuard`)}),x=i.subscribeDiagnostic(`PLUGIN_AFTER_START`,e=>{Bt(e,i.logger)});return{teardown(){f(),p(),m(),h(),ee(),g(),te(),ne(),re(),y(),ie(),ae(),oe(),b(),se(),ce(),le(),ue(),x(),d(),u()}}}}export{er as validationPlugin};
2
2
  //# sourceMappingURL=index.mjs.map