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