@real-router/validation-plugin 0.31.0 → 0.32.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,6 +1,5 @@
1
1
  import { RouterValidator } from "@real-router/core/validation";
2
2
  import { DefaultDependencies, PluginFactory } from "@real-router/core";
3
- //#region src/validationPlugin.d.ts
4
3
  /**
5
4
  * The dependency map is a type parameter so the factory carries the CALLER's
6
5
  * `D` rather than the `object` default (#1621). `keyof object` is `never`, so a
@@ -15,6 +14,5 @@ import { DefaultDependencies, PluginFactory } from "@real-router/core";
15
14
  * this plugin actually reads dependencies.
16
15
  */
17
16
  export declare function validationPlugin<Dependencies extends DefaultDependencies = DefaultDependencies>(): PluginFactory<Dependencies>;
18
- //#endregion
19
17
  export type { RouterValidator };
20
18
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/validationPlugin.ts"],"mappings":";;;;;;;;;;;;;;;;wBAkagB,iBACd,qBAAqB,sBAAsB,wBACxC,cAAc"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/validationPlugin.ts"],"mappings":";;;;;;;;;;;;;;;wBAybgB,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{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 An={hasRoute:()=>!1,getUrlParams:()=>[]};function jn(e){return{tree:{...e,children:new Map,nonAbsoluteChildren:[]},lookup:An,forwardMap:{}}}function Mn(e,t){let n=[];for(let r of e.getTree().children.keys())n.push(t.get(r));return n}function Nn(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.`}},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 Pn(){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=kn(i),c=Nn(i,o,a),l=()=>{r.validator===c&&(r.validator=null)};r.validator=c;try{let e=Mn(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,()=>jn(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{Pn 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 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};
2
2
  //# sourceMappingURL=index.mjs.map