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