@real-router/validation-plugin 0.31.1 → 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":";;;;;;;;;;;;;;;wBAubgB,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{buildParamMeta as a,findMisChanneledKey as o,getInternals as s,validateRoute as c}from"@real-router/core/validation";import{events as l,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 ee(e,t){return e in t}const h=Object.getPrototypeOf,g=Object.values,_=Object.hasOwn;function te(e){if(Array.isArray(e))return!0;let t=h(e);return t===null||t===Object.prototype}function ne(e,t){let n=Array.isArray(e)?e:g(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 v=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 v(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 v)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 y(e){try{return se(e)}catch{return!1}}function se(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(!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/,b=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function x(e,t){return i(`router`,e).type`${t}`}function de(e){return typeof e==`string`?e===``?!0:e.length>1e4?!1:e.startsWith(`@@`)?!0:b.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 S(e,t){if(typeof e!=`string`)throw x(t,`Route name must be a string, got ${typeof e}`);if(e!==``){if(!ue.test(e))throw x(t,`Route name cannot contain only whitespace`);if(e.length>1e4)throw x(t,`Route name exceeds maximum length of 10000 characters. This is a technical safety limit.`);if(!e.startsWith(`@@`)&&!b.test(e))throw x(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 C(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`),w=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 ${C(e)}`;for(let n of w(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 w(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}=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 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 w(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(l));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=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 T=i(`router`,`addRoute`),He=Object.keys;function E(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 T.type`forwardTo must be a string or function for route "${t}", got ${C(e)}`;if(typeof e==`function`){let n=e.constructor.name===`AsyncFunction`,r=e.toString().includes(`__awaiter`);if(n||r)throw T.type`forwardTo callback cannot be async for route "${t}". Async functions break matchPath/buildPath.`}}}function D(e,t,n){if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))throw T.type`${t} must be an object for route "${n}", got ${C(e)}`}function We(e,t){if(e.canActivate!==void 0&&typeof e.canActivate!=`function`)throw T.type`canActivate must be a function for route "${t}", got ${C(e.canActivate)}`;if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw T.type`canDeactivate must be a function for route "${t}", got ${C(e.canDeactivate)}`;D(e.defaultParams,`defaultParams`,t),D(e.defaultSearch,`defaultSearch`,t);let{decodeParams:n,encodeParams:r}=e;if(typeof n==`function`&&n.constructor.name===`AsyncFunction`)throw T.type`decodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`;if(typeof r==`function`&&r.constructor.name===`AsyncFunction`)throw T.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)We(n,E(t,n.name))}function Ge(e){let t=new Set;for(let n of e)for(let e of a(n).urlParams)t.add(e);return t}function Ke(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 Ke(n.children,t,e,a)}throw n.plain`collectPathsToRoute: route "${t}" not found`}function qe(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 qe(r.children,e))n.add(t)}return n}function Je(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 Je(r.children,e))n.set(t,i)}return n}function Ye(e,t,n,r){return t?new Set(n.getUrlParams(e)):Ge(r(e))}const Xe=new Set;function Ze(e,t,n,r,i,a){let o=i.hasRoute(t),s=r.has(t);if(!o&&!s)throw T.ref`forwardTo target "${t}" does not exist for route "${e}"`;let c=new Set([...a,...Ge(n(e))]),l=[...Ye(t,o,i,n)].filter(e=>!c.has(e));if(l.length>0)throw T.plain`forwardTo target "${t}" requires params [${l.join(`, `)}] that are not available in source route "${e}"`}function Qe(e,t,n,i){let a=qe(e,i),o=t=>Ke(e,i?t.slice(i.length+1):t),s=i?new Set(n.getUrlParams(i)):Xe,c=Je(e,i),l={...t};for(let[e,t]of c)r(l,e,t);for(let[e,t]of c)Ze(e,t,o,a,n,s);for(let e of He(l))u(e,l)}function $e(e,t){if(!m(e)&&typeof e!=`function`)throw i(`router`,t).type`Handler must be a boolean or factory function, got ${C(e)}`}function et(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 tt(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 nt(e,t,n,r){r.warn(`router.${n}`,`Overwriting existing ${t} handler for route "${e}"`)}function rt(e,t,n){n.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}function it(e,t){return`Guard for "${e}" must answer true or false, got ${C(t)} — read as a refusal.`}function at(e,t,n,r){r.warn(`router.${n}`,it(e,t))}function ot(e,t,n){n.warn(`router`,it(e,t))}const O=i(`router`,`start`),k=i(`router`,`navigateToState`),st=i(`router`,`navigateToDefault`),ct=i(`router`,`navigate`),lt=Object.hasOwn,ut=Object.getPrototypeOf;function dt(e){if(typeof e!=`string`)throw ct.type`Invalid route name: expected string, got ${C(e)}`}function ft(e){if(e!==void 0&&(typeof e!=`object`||!e))throw st.type`Invalid options: ${C(e)}. Expected NavigationOptions object.`}function pt(e){if(typeof e!=`object`||!e)throw k.type`Invalid state: ${C(e)}. Expected State object.`;let t=e;if(!p(t.name))throw k.type`Invalid state.name: ${C(t.name)}. Expected string.`;if(!y(t.params))throw k.type`Invalid state.params: ${C(t.params)}. Expected plain object.`;if(!p(t.path))throw k.type`Invalid state.path: ${C(t.path)}. Expected string.`}function A(e,t){if(!le(e))throw i(`router`,t).type`Invalid options: ${C(e)}. Expected NavigationOptions object.`}const j=/[\u0000-\u001F\u007F]/;function mt(e,t){for(let n in e){if(!lt(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`&&j.test(r))throw i(`router`,t).type`param "${n}" must not contain control characters (NUL / C0 / DEL) — they corrupt the URL path.`}}function M(e,t){if(e===void 0)return;let n=e!==null&&ut(e);if(Array.isArray(e)||n!==null&&n!==Object.prototype)throw i(`router`,t).type`params must be a plain object, got ${C(e)}`}function N(e,t){if(e!==void 0&&(mt(e,t),!y(e)))throw i(`router`,t).type`params must be a plain object, got ${C(e)}`}function P(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 ${C(e)}`}function ht(e){if(e!==void 0&&typeof e!=`string`)throw O.type`path must be a string, got ${C(e)}.`;if(typeof e==`string`){if(j.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 gt=Object.entries,_t=Object.hasOwn,F=Object.keys,vt=Object.getPrototypeOf,I={trailingSlash:[`strict`,`never`,`always`,`preserve`],queryParamsMode:[`default`,`strict`,`loose`],urlParamsEncoding:[`default`,`uri`,`uriComponent`,`none`]},yt={arrayFormat:!0,booleanFormat:!0,nullFormat:!0,numberFormat:!0},bt=new Set(F({defaultRoute:!0,defaultParams:!0,defaultSearch:!0,trailingSlash:!0,caseSensitive:!0,queryParamsMode:!0,queryParams:!0,urlParamsEncoding:!0,allowNotFound:!0,rewritePathOnMatch:!0,logger:!0,limits:!0})),xt={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 St(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=xt[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 Ct(e){let t=vt(e);return t===null||t===Object.prototype}function wt(e,t){if(!e||typeof e!=`object`||!Ct(e))throw i(`router`,t).type`invalid limits: expected plain object, got ${typeof e}`;for(let[n,r]of gt(e)){if(!_t(xt,n))throw i(`router`,t).type`unknown limit: "${n}"`;r!==void 0&&St(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 L(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 Tt(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 Et(e,t,n){if(e!==void 0&&typeof e!=`function`&&(!e||typeof e!=`object`||Array.isArray(e)||!Ct(e)))throw i(`router`,n).type`Invalid "${t}": expected plain object or function, got ${typeof e}`}function Dt(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 F(n))if(!ee(e,yt))throw i(`router`,t).type`Invalid "queryParams.${e}": unknown option`}function Ot(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 F(n))if(!bt.has(e))throw i(`router`,t).type`Unknown option: "${e}"`;if(Tt(n.defaultRoute,t),Et(n.defaultParams,`defaultParams`,t),Et(n.defaultSearch,`defaultSearch`,t),L(n.trailingSlash,`trailingSlash`,I.trailingSlash,t),L(n.queryParamsMode,`queryParamsMode`,I.queryParamsMode,t),L(n.urlParamsEncoding,`urlParamsEncoding`,I.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}`;Dt(n.queryParams,t),n.limits!==void 0&&wt(n.limits,t)}const R=i(`router`,`usePlugin`),kt=Object.hasOwn,z=`router.usePlugin`,At={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function jt(e,t,n=d.maxPlugins){if(n!==0&&e+t>n)throw R.range`Plugin limit exceeded (${n}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating plugins.`}function Mt(e,t){if(t.includes(e))throw R.plain`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}=f(t);e>=i?n.error(z,`${e} plugins registered! This is excessive. Hard limit at ${t}.`):e>=r&&n.warn(z,`${e} plugins registered. Consider if all are necessary.`)}function Pt(e){for(let t in e)if(!(t===`teardown`||kt(At,t)))throw R.type`Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`}function Ft(e){e.warn(z,`Duplicate factory in batch, will be registered once`)}function It(e,t){t.warn(z,`Property '${e}' is not a function, skipping`)}function Lt(e,t){e===`onStart`&&t.warn(z,`Router already started, onStart will not be called`)}const Rt=i(`router`,`navigateToDefault`),B=i(`validation-plugin`),V=Object.entries,zt=Object.getOwnPropertyDescriptor,Bt=Object.keys;function H(e,t,n=``){for(let r of e){let e=n?`${n}.${r.name}`:r.name;t(r,e),r.children&&H(r.children,t,e)}}function U(e,t){let n=[];return H(e,(e,r)=>{let i=t(e);i!==void 0&&n.push([r,i])}),n}function Vt(e,t){try{return u(e,t)}catch(e){let t=e.message.replace(/^\[router\] /u,``);throw B.plain({cause:e})`${t}`}}function W(e,t,n){let r=e;if(r.constructor.name===`AsyncFunction`||r.toString().includes(`__awaiter`))throw B.type`Route "${n}" ${t} cannot be async`}function Ht(e){H(e,(e,t)=>{if(typeof e.name!=`string`||!e.name)throw B.type`validateExistingRoutes: route has invalid name: ${e.name}`;if(typeof e.path!=`string`)throw B.type`validateExistingRoutes: route "${t}" has non-string path (${typeof e.path})`})}function Ut(e,t){for(let[n,r]of V(e)){if(!t.hasRoute(r))throw B.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 B.plain`validateForwardToConsistency: forwardTo target "${r}" requires params [${i.join(`, `)}] not available in source route "${n}"`}for(let t of Bt(e))Vt(t,e)}function Wt(e,t){for(let[n,r]of e)if(typeof r!=`object`||!r||Array.isArray(r))throw B.type`validateRoutePropertiesStore: route "${n}" ${t} must be a plain object, got ${Array.isArray(r)?`array`:typeof r}`}function Gt(e){let t=U(e,e=>e.decodeParams),n=U(e,e=>e.encodeParams),r=U(e,e=>typeof e.forwardTo==`string`?void 0:e.forwardTo);for(let[e,n]of t){if(typeof n!=`function`)throw B.type`validateRoutePropertiesStore: route "${e}" decoder must be a function, got ${typeof n}`;W(n,`decoder`,e)}for(let[e,t]of n){if(typeof t!=`function`)throw B.type`validateRoutePropertiesStore: route "${e}" encoder must be a function, got ${typeof t}`;W(t,`encoder`,e)}Wt(U(e,e=>e.defaultParams),`defaultParams`),Wt(U(e,e=>e.defaultSearch),`defaultSearch`);for(let[e,t]of r){if(typeof t!=`function`)throw B.type`validateRoutePropertiesStore: route "${e}" forwardTo callback must be a function, got ${typeof t}`;W(t,`forwardTo callback`,e)}}function Kt(e,t){for(let[n,r]of V(e))if(!t.hasRoute(r))throw B.plain`validateForwardToTargetsStore: forwardTo target "${r}" does not exist for route "${n}"`}function qt(e,t){for(let t of Bt(e))if(zt(e,t)?.get)throw B.type`validateDependenciesStructure: dependency "${t}" must not use a getter`;for(let[e,n]of V(t))if(!Number.isInteger(n))throw B.type`validateDependenciesStructure: deps.limits.${e} must be an integer, got ${String(n)}`}function Jt(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 B.range`validateLimitsConsistency: dependency count (${t}) exceeds maxDependencies limit (${a})`}function Yt(e,t){return typeof e==`string`&&e!==``&&!t.hasRoute(e)}function Xt(e,t){if(Yt(e,t))throw B.plain`defaultRoute resolved to non-existent route: "${e}"`}function Zt(e,t){if(Yt(e,t))throw Rt.plain`defaultRoute callback resolved to non-existent route: "${e}"`}function Qt(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 G=i(`router`,`updateRoute`),K=i(`router`,`addRoute`),$t=i(`router`,`shouldUpdateNode`),en=i(`router`,`matchPath`),tn=i(`router`,`buildPath`),q=i(`router`,`isActiveRoute`),nn=i(`router`,`setRootPath`);function J(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 rn(e,t){for(let n of e)n&&typeof n==`object`&&typeof n.name==`string`&&(J(n.name,t),n.children&&rn(n.children,t))}function an(e){S(e,`removeRoute`)}function on(e){if(typeof e!=`string`)throw nn.type`rootPath must be a string, got ${C(e)}`}function Y(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function sn(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw K.type`canActivate must be a function, got ${C(t.canActivate)}`;if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw K.type`canDeactivate must be a function, got ${C(t.canDeactivate)}`}function cn(e,t){let n=e;if(typeof n.decodeParams==`function`&&Y(n.decodeParams))throw K.type`decodeParams cannot be async for route "${String(t)}"`;if(typeof n.encodeParams==`function`&&Y(n.encodeParams))throw K.type`encodeParams cannot be async for route "${String(t)}"`;if(typeof n.forwardTo==`function`&&Y(n.forwardTo))throw K.type`forwardTo callback cannot be async for route "${String(t)}"`}function ln(e,t){for(let n of e){if(typeof n!=`object`||!n||Array.isArray(n))throw K.type`Route must be an object, got ${C(n)}`;We(n,E(t,n.name))}}function un(e){if(typeof e!=`string`||e===``)throw K.type`parent option must be a non-empty string, got ${C(e)}`;S(e,`addRoute`)}function dn(e,t,n,r){if(!p(e))throw q.type`name must be a string, got ${typeof e}`;if(M(t,`isActiveRoute`),n!==void 0&&typeof n!=`boolean`)throw q.type`strictEquality must be a boolean, got ${typeof n}`;if(r!==void 0&&typeof r!=`boolean`)throw q.type`ignoreQueryParams must be a boolean, got ${typeof r}`}function X(e,t,n){if(!p(e))throw i(`router`,n).type`Invalid routeName: ${C(e)}. Expected string.`;if(!y(t))throw i(`router`,n).type`Invalid routeParams: ${C(t)}. Expected plain object.`}function fn(e,t){if(S(e,`updateRoute`),e===``)throw G.ref`Invalid name: empty string. Cannot update root node.`;if(t===null)throw G.type`updates must be an object, got null`;if(typeof t!=`object`||Array.isArray(t))throw G.type`updates must be an object, got ${C(t)}`}function pn(e,t){if(e.constructor.name===`AsyncFunction`||e.toString().includes(`__awaiter`))throw G.type`${t} cannot be an async function`}function Z(e,t){if(e!=null){if(typeof e!=`function`)throw G.type`${t} must be a function or null, got ${typeof e}`;pn(e,t)}}function mn(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 G.type`forwardTo must be a string, function, or null, got ${C(t)}`;typeof t==`function`&&pn(t,`forwardTo callback`)}hn(n,`defaultParams`),hn(r,`defaultSearch`),Z(i,`decodeParams`),Z(a,`encodeParams`),Z(o,`canActivate`),Z(s,`canDeactivate`)}function hn(e,t){if(e!=null&&(typeof e!=`object`||Array.isArray(e)))throw G.type`${t} must be an object or null, got ${C(e)}`}function gn(e){if(!p(e)||e===``)throw tn.type`route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`}function _n(e){let t=new Set;return function(n,r){let i=o(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 vn(e){if(!p(e))throw en.type`path must be a string, got ${typeof e}`}function yn(e){if(!p(e))throw $t.type`nodeName must be a string, got ${typeof e}`}function bn(e,t,n,r,i){if(i){let e=t;for(let t of i.split(`.`))if(e=e.children.get(t),!e)throw K.ref`Parent route "${i}" does not exist`}let a=new Set,o=new Map;for(let n of e)c(n,`addRoute`,t,i??``,a,o);Qe(e,r,n,i)}function xn(e,t,n){let r=new Set(n.getUrlParams(e)),i=n.getUrlParams(t).filter(e=>!r.has(e));if(i.length>0)throw G.plain`forwardTo target "${t}" requires params [${i.join(`, `)}] that are not available in source route "${e}"`}function Sn(e,t,n){let r={...n,[e]:t};u(e,r)}function Cn(e,t,n,r){if(!n.hasRoute(e))throw G.ref`route "${e}" does not exist`;if(t!=null&&typeof t==`string`){if(!n.hasRoute(t))throw G.plain`forwardTo target "${t}" does not exist`;xn(e,t,n),Sn(e,t,r)}}const Q=i(`router`,`makeState`);function wn(e,t,n){if(!p(e))throw Q.type`Invalid name: ${C(e)}. Expected string.`;if(t!==void 0&&!y(t))throw Q.type`Invalid params: ${C(t)}. Expected plain object.`;if(n!==void 0&&!p(n))throw Q.type`Invalid path: ${C(n)}. Expected string.`}function Tn(){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 En(){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.`))}}const Dn=i(`validation-plugin`),On=i(`router`,`addRoute`),$=i(`router`,`areStatesEqual`);function kn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function An(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 jn={hasRoute:()=>!1,getUrlParams:()=>[]};function Mn(e){return{tree:{...e,children:new Map,nonAbsoluteChildren:[]},lookup:jn,forwardMap:{}}}function Nn(e,t){let n=[];for(let r of e.getTree().children.keys())n.push(t.get(r));return n}function Pn(e,t,n){let r=_n(t=>e.getDeclaredQueryNames(t));return{routes:{validateBuildPathArgs(e,t){gn(e),r(e,t)},validateMatchPathArgs:vn,validateIsActiveRouteArgs(e,t,n,i){dn(e,t,n,i),r(e,t)},validateShouldUpdateNodeArgs:yn,validateStateBuilderArgs:X,validateRouteName(e,t){S(e,t)},validateSetRootPathArgs:on},options:{validateOptions:Ot,validateResolvedDefaultRoute(e){Zt(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){jt(e,1,t?.maxPlugins)},validateNoDuplicatePlugins:Mt,validatePluginKeys:Pt,validateCountThresholds(t){Nt(t,e.getOptions().limits?.maxPlugins??d.maxPlugins,e.logger)},warnBatchDuplicates(){Ft(e.logger)},warnPluginMethodType(t){It(t,e.logger)}},lifecycle:{validateHandlerLimit(t,n){et(t,n,e.getOptions().limits?.maxLifecycleHandlers??d.maxLifecycleHandlers)},validateCountThresholds(t,n){tt(t,n,e.getOptions().limits?.maxLifecycleHandlers??d.maxLifecycleHandlers,e.logger)},warnOverwrite(t,n,r){nt(t,n,r,e.logger)},warnAsyncGuardSync(t,n){rt(t,n,e.logger)},warnNonBooleanGuardSync(t,n,r){at(t,n,r,e.logger)},warnNonBooleanGuard(t,n){ot(t,n,e.logger)}},navigation:{validateNavigateToDefaultArgs(t){ft(t),n.check(e.logger)},validateNavigateToStateArgs:pt,validateNavigationOptions:A,validateParamsShape:M,validateSearch:P,validateStartArgs:ht},state:{validateMakeStateArgs:wn,reportDroppedQueryKey:Tn(),reportUndeclaredParamKey:En(),validateAreStatesEqualArgs(e,t,n){if(!pe(e))throw $.type`Invalid state1: ${C(e)}. Expected State object.`;if(!pe(t))throw $.type`Invalid state2: ${C(t)}. Expected State object.`;if(n!==void 0&&!m(n))throw $.type`Invalid ignoreQueryParams: ${C(n)}. Expected boolean.`;if(n===!1){if(!kn(e.search))throw $.type`Invalid state1.search: ${C(e.search)}. Expected a plain object.`;if(!kn(t.search))throw $.type`Invalid state2.search: ${C(t.search)}. Expected a plain object.`}}},eventBus:{validateListenerArgs(e,t){Be(e,t)},validateCountThresholds(t,n,r){let i=e.getOptions().limits?.maxListeners??d.maxListeners;Ve(t,n,r,e.logger,i)}}}}function Fn(){return n=>{let r=s(n),i=e(n);if(n.isActive())throw Dn.code(`VALIDATION_PLUGIN_AFTER_START`)`must be registered before router.start()`;if(r.validator!==null)throw Dn.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=An(i),c=Pn(i,o,a),l=()=>{r.validator===c&&(r.validator=null)};r.validator=c;try{let e=Nn(i,t(n)),a=i.getForwardMap(),s=i.getResolvedLimits(),c=i.getOptions();Ht(e),Ut(a,o),Gt(e),Kt(a,o),qt(r.dependenciesGetStore().dependencies,s),Jt(c,i.getDependencyKeys().length,s.maxDependencies),r.validator.options.validateOptions(c,`constructor (retrospective)`),typeof c.defaultRoute==`string`&&Xt(c.defaultRoute,o)}catch(e){throw l(),e}let u=i.addInterceptor(`start`,(e,t)=>{try{Qt(i.getExternalGuardNames(),o,i.logger)}catch{}return e(t)}),d=i.addCheck(`buildPath:params`,e=>{N(e,`buildPath`)}),f=i.addCheck(`buildPathResolved:params`,e=>{N(e,`buildPathResolved`)}),p=i.addCheck(`canNavigateTo:entry`,(e,t,n)=>{S(e,`canNavigateTo`),M(t,`canNavigateTo`),P(n,`canNavigateTo`)}),m=i.addCheck(`canNavigateTo:params`,e=>{N(e,`canNavigateTo`)}),ee=i.addCheck(`navigate:entry`,(e,t,n,r)=>{dt(e),M(t,`navigate`),P(n,`navigate`),A(r,`navigate`)}),h=i.addCheck(`navigate:params`,e=>{N(e,`navigate`)}),g=(e,t)=>{for(let n of e){let e=E(t,n.name);sn(n),cn(n,e),n.children!==void 0&&g(n.children,e)}},_=(e,t,n,r)=>{if(g(e,typeof n==`string`&&o.hasRoute(n)?n:void 0),n!==void 0&&(un(n),!o.hasRoute(n)))throw On.ref`Parent route "${n}" does not exist`;rn(e,t),ln(e,n);let i=r();bn(e,i.tree,i.lookup,i.forwardMap,n)},te=i.addCheck(`addRoute:batch`,(e,t)=>{_(e,`addRoute`,t,()=>({tree:i.getTree(),lookup:o,forwardMap:i.getForwardMap()}))}),ne=i.addCheck(`replaceRoutes:batch`,e=>{_(e,`replaceRoutes`,void 0,()=>Mn(i.getTree()))}),re=i.addCheck(`removeRoute:entry`,e=>{an(e),J(e,`removeRoute`)}),v=i.addCheck(`updateRoute:entry`,(e,t)=>{let n=t;fn(e,t),J(e,`updateRoute`),mn({forwardTo:n.forwardTo,defaultParams:n.defaultParams,defaultSearch:n.defaultSearch,decodeParams:n.decodeParams,encodeParams:n.encodeParams,canActivate:n.canActivate,canDeactivate:n.canDeactivate}),Cn(e,n.forwardTo,o,i.getForwardMap())}),ie=i.addCheck(`hasRoute:entry`,e=>{S(e,`hasRoute`)}),ae=i.addCheck(`getRoute:entry`,e=>{S(e,`getRoute`)}),oe=i.addCheck(`forwardState:entry`,(e,t,n)=>{X(e,t,`forwardState`),P(n,`forwardState`)}),y=i.addCheck(`buildNavigationState:state`,(e,t,n)=>{P(n,`buildNavigationState`),X(e,t,`buildNavigationState`)}),se=i.addCheck(`addActivateGuard:entry`,(e,t)=>{S(e,`addActivateGuard`),$e(t,`addActivateGuard`)}),ce=i.addCheck(`addDeactivateGuard:entry`,(e,t)=>{S(e,`addDeactivateGuard`),$e(t,`addDeactivateGuard`)}),le=i.addCheck(`removeActivateGuard:entry`,e=>{S(e,`removeActivateGuard`)}),ue=i.addCheck(`removeDeactivateGuard:entry`,e=>{S(e,`removeDeactivateGuard`)}),b=i.subscribeDiagnostic(`PLUGIN_AFTER_START`,e=>{Lt(e,i.logger)});return{teardown(){d(),f(),p(),m(),ee(),h(),te(),ne(),re(),v(),ie(),ae(),oe(),y(),se(),ce(),le(),ue(),b(),u(),l()}}}}export{Fn 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