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