@real-router/validation-plugin 0.7.10 → 0.7.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import{RouterError as e,resolveForwardChain as t}from"@real-router/core";import{getInternals as n}from"@real-router/core/validation";import{logger as r}from"@real-router/logger";const i=[`replace`,`reload`,`force`,`forceDeactivate`,`redirected`];function a(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;for(let e of i){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 o=/\S/,s=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function c(e,t){return TypeError(`[router.${e}] ${t}`)}function l(e){return typeof e==`string`?e===``?!0:e.length>1e4?!1:e.startsWith(`@@`)?!0:s.test(e):!1}function u(e,t=new WeakSet){if(e==null)return!0;let n=typeof e;if(n===`string`||n===`boolean`)return!0;if(n===`number`)return Number.isFinite(e);if(n===`function`||n===`symbol`)return!1;if(Array.isArray(e))return t.has(e)?!1:(t.add(e),e.every(e=>u(e,t)));if(n===`object`){if(t.has(e))return!1;t.add(e);let n=Object.getPrototypeOf(e);return n!==null&&n!==Object.prototype?!1:Object.values(e).every(e=>u(e,t))}return!1}function ee(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`boolean`?!0:t===`number`?Number.isFinite(e):!1}function d(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);if(t!==null&&t!==Object.prototype)return!1;let n=!1;for(let t in e){if(!Object.hasOwn(e,t))continue;let r=e[t];if(!ee(r)){let e=typeof r;if(e===`function`||e===`symbol`)return!1;n=!0;break}}return n?u(e):!0}function te(e){return l(e.name)&&typeof e.path==`string`&&d(e.params)}function f(e){return typeof e!=`object`||!e?!1:te(e)}function p(e){return typeof e==`string`}function m(e){return typeof e==`boolean`}function ne(e,t){return e in t}function h(e,t){if(typeof e!=`string`)throw c(t,`Route name must be a string, got ${typeof e}`);if(e!==``){if(!o.test(e))throw c(t,`Route name cannot contain only whitespace`);if(e.length>1e4)throw c(t,`Route name exceeds maximum length of 10000 characters. This is a technical safety limit.`);if(!e.startsWith(`@@`)&&!s.test(e))throw c(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 g(e){return e===null?`null`:Array.isArray(e)?`array[${e.length}]`:typeof e==`object`?`constructor`in e&&e.constructor.name!==`Object`?e.constructor.name:`object`:typeof e}function _(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}function re(e,t){if(typeof e!=`string`)throw TypeError(`[router.${t}] dependency name must be a string, got ${typeof e}`)}function ie(e){if(typeof e!=`string`)throw TypeError(`[router.setDependency] dependency name must be a string, got ${typeof e}`)}function ae(e,t){if(!(e&&typeof e==`object`&&e.constructor===Object))throw TypeError(`[router.${t}] Invalid argument: expected plain object, received ${g(e)}`);for(let n in e)if(Object.getOwnPropertyDescriptor(e,n)?.get)throw TypeError(`[router.${t}] Getters not allowed: "${n}"`)}function oe(e,t){if(e===void 0)throw ReferenceError(`[router.getDependency] dependency "${t}" not found`)}function se(e,t){let n=e,i=n.limits?.maxDependencies??100;if(i===0)return;let a=Object.keys(n.dependencies).length,{warn:o,error:s}=_(i);if(a>=i)throw RangeError(`[router.${t}] Dependency limit exceeded (${i}). Current: ${a}.`);a===s?r.error(`router.${t}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${i}.`):a===o&&r.warn(`router.${t}`,`${a} dependencies registered. Consider if all are necessary.`)}function ce(e){if(e!==void 0){if(!(e&&typeof e==`object`&&e.constructor===Object))throw TypeError(`[cloneRouter] Invalid dependencies: expected plain object or undefined, received ${typeof e}`);for(let t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw TypeError(`[cloneRouter] Getters not allowed in dependencies: "${t}"`)}}function le(e,t){r.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function ue(e,t){r.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function de(e){r.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const fe=new Set([`$start`,`$stop`,`$$start`,`$$leaveApprove`,`$$cancel`,`$$success`,`$$error`]);function v(e){if(!fe.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(v(e),typeof t!=`function`)throw TypeError(`[router.addEventListener] callback must be a function, got ${typeof t}`)}function me(e,t){if(!m(e)&&typeof e!=`function`)throw TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${g(e)}`)}function he(e,t,n){if(e)throw Error(`[router.${n}] Cannot modify route "${t}" during its own registration`)}function ge(e,t,n=200){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 _e(e,t,n){if(n===0)return;let{warn:i,error:a}=_(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 ve(e,t,n){r.warn(`router.${n}`,`Overwriting existing ${t} handler for route "${e}"`)}function ye(e,t){r.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}function be(e){if(typeof e!=`string`)throw TypeError(`[router.navigate] Invalid route name: expected string, got ${g(e)}`)}function xe(e){if(e!==void 0&&(typeof e!=`object`||!e))throw TypeError(`[router.navigateToDefault] Invalid options: ${g(e)}. Expected NavigationOptions object.`)}function Se(e){if(typeof e!=`object`||!e)throw TypeError(`[router.navigateToState] Invalid state: ${g(e)}. Expected State object.`);let t=e;if(!p(t.name))throw TypeError(`[router.navigateToState] Invalid state.name: ${g(t.name)}. Expected string.`);if(!d(t.params))throw TypeError(`[router.navigateToState] Invalid state.params: ${g(t.params)}. Expected plain object.`);if(!p(t.path))throw TypeError(`[router.navigateToState] Invalid state.path: ${g(t.path)}. Expected string.`)}function Ce(e,t){if(!a(e))throw TypeError(`[router.${t}] Invalid options: ${g(e)}. Expected NavigationOptions object.`)}function we(e,t){if(e!==void 0&&!d(e))throw TypeError(`[router.${t}] params must be a plain object, got ${g(e)}`)}function Te(e){if(e!==void 0&&typeof e!=`string`)throw TypeError(`[router.start] path must be a string, got ${g(e)}.`);if(typeof e==`string`&&e!==``&&!e.startsWith(`/`))throw TypeError(`[router.start] path must start with "/", got "${e}".`)}const y={trailingSlash:[`strict`,`never`,`always`,`preserve`],queryParamsMode:[`default`,`strict`,`loose`],urlParamsEncoding:[`default`,`uri`,`uriComponent`,`none`]},b={arrayFormat:[`none`,`brackets`,`index`,`comma`],booleanFormat:[`none`,`auto`,`empty-true`],nullFormat:[`default`,`hidden`],numberFormat:[`none`,`auto`]},x=[`all`,`warn-error`,`error-only`,`none`],Ee=new Set([`defaultRoute`,`defaultParams`,`trailingSlash`,`queryParamsMode`,`queryParams`,`urlParamsEncoding`,`allowNotFound`,`rewritePathOnMatch`,`logger`,`limits`]),S={maxDependencies:{min:0,max:1e4},maxPlugins:{min:0,max:1e3},maxListeners:{min:0,max:1e5},warnListeners:{min:0,max:1e5},maxEventDepth:{min:0,max:100},maxLifecycleHandlers:{min:0,max:1e4}};function C(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=S[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 w(e,t){if(!e||typeof e!=`object`||e.constructor!==Object)throw TypeError(`[router.${t}] invalid limits: expected plain object, got ${typeof e}`);for(let[n,r]of Object.entries(e)){if(!Object.hasOwn(S,n))throw TypeError(`[router.${t}] unknown limit: "${n}"`);r!==void 0&&C(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 T(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 De(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 E(e,t){if(e!==void 0&&typeof e!=`function`&&(!e||typeof e!=`object`||Array.isArray(e)||e.constructor!==Object))throw TypeError(`[router.${t}] Invalid "defaultParams": expected plain object or function, got ${typeof e}`)}function Oe(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,r]of Object.entries(n)){if(!ne(e,b))throw TypeError(`[router.${t}] Invalid "queryParams.${e}": unknown option`);T(r,`queryParams.${e}`,b[e],t)}}function ke(e,t){if(e===void 0)return;if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`[router.${t}] Invalid "logger": expected plain object`);let n=e;if(n.level!==void 0&&!x.includes(n.level)){let e=x.map(e=>`"${e}"`).join(`, `),r=typeof n.level==`string`?n.level:`(${typeof n.level})`;throw TypeError(`[router.${t}] Invalid "logger.level": "${r}". Must be one of: ${e}`)}if(n.callback!==void 0&&typeof n.callback!=`function`)throw TypeError(`[router.${t}] Invalid "logger.callback": expected function`);if(n.callbackIgnoresLevel!==void 0&&typeof n.callbackIgnoresLevel!=`boolean`)throw TypeError(`[router.${t}] Invalid "logger.callbackIgnoresLevel": expected boolean`);n.callbackIgnoresLevel===!0&&n.callback===void 0&&r.error(`router.${t}`,`"logger.callbackIgnoresLevel: true" has no effect without "logger.callback" — the option is ignored`)}function Ae(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 Object.keys(n))if(!Ee.has(e))throw TypeError(`[router.${t}] Unknown option: "${e}"`);if(De(n.defaultRoute,t),E(n.defaultParams,t),T(n.trailingSlash,`trailingSlash`,y.trailingSlash,t),T(n.queryParamsMode,`queryParamsMode`,y.queryParamsMode,t),T(n.urlParamsEncoding,`urlParamsEncoding`,y.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}`);Oe(n.queryParams,t),ke(n.logger,t),n.limits!==void 0&&w(n.limits,t)}const D=`router.usePlugin`,je={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function Me(e,t,n=50){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 Ne(e,t){if(t===0)return;let{warn:n,error:i}=_(t);e>=i?r.error(D,`${e} plugins registered! This is excessive. Hard limit at ${t}.`):e>=n&&r.warn(D,`${e} plugins registered. Consider if all are necessary.`)}function Pe(e){for(let t in e)if(!(t===`teardown`||Object.hasOwn(je,t)))throw TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}function Fe(){r.warn(D,`Duplicate factory in batch, will be registered once`)}function Ie(e){r.warn(D,`Property '${e}' is not a function, skipping`)}function Le(e){e===`onStart`&&r.warn(D,`Router already started, onStart will not be called`)}function Re(e,t){let n=[`start`,`buildPath`,`forwardState`];if(typeof e!=`string`||!n.includes(e))throw TypeError(`[router.addInterceptor] Invalid method: "${String(e)}". Must be one of: ${n.join(`, `)}`);if(typeof t!=`function`)throw TypeError(`[router.addInterceptor] interceptor must be a function, got ${typeof t}`)}function O(e,t){if(!e||typeof e!=`object`)throw TypeError(`[validation-plugin] ${t}: store must be an object`);let n=e;if(!Array.isArray(n.definitions))throw TypeError(`[validation-plugin] ${t}: store.definitions must be an array`);if(!n.config||typeof n.config!=`object`)throw TypeError(`[validation-plugin] ${t}: store.config must be an object`);if(!n.tree||typeof n.tree!=`object`)throw TypeError(`[validation-plugin] ${t}: store.tree must be an object`);return n}function k(e,t,n=``){for(let r of e){let e=n?`${n}.${r.name}`:r.name;t(r,e),r.children&&k(r.children,t,e)}}function A(e,t){let n=t.split(`.`),r=e;for(let e of n)if(r=r.children.get(e),!r)return!1;return!0}function ze(e,n){try{return t(e,n)}catch(e){throw Error(`[validation-plugin] ${e.message}`,{cause:e})}}function j(e){let t=new Set;for(let n of e){for(let e of n.paramMeta.urlParams)t.add(e);for(let e of n.paramMeta.spatParams)t.add(e)}return t}function M(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 N(e){let t=O(e,`validateExistingRoutes`),n=new Set;k(t.definitions,(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})`);if(n.has(t))throw Error(`[validation-plugin] validateExistingRoutes: duplicate route name detected: "${t}"`);n.add(t)})}function P(e){let{config:t,tree:n,matcher:r}=O(e,`validateForwardToConsistency`);for(let[e,i]of Object.entries(t.forwardMap)){if(!A(n,i))throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${i}" does not exist in tree (source route: "${e}")`);let t=r.getSegmentsByName(e),a=r.getSegmentsByName(i);if(t&&a){let n=j(t),r=[...j(a)].filter(e=>!n.has(e));if(r.length>0)throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${i}" requires params [${r.join(`, `)}] not available in source route "${e}"`)}}for(let e of Object.keys(t.forwardMap))ze(e,t.forwardMap)}function Be(e){let{config:t}=O(e,`validateRoutePropertiesStore`);for(let[e,n]of Object.entries(t.decoders)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" decoder must be a function, got ${typeof n}`);M(n,`decoder`,e)}for(let[e,n]of Object.entries(t.encoders)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" encoder must be a function, got ${typeof n}`);M(n,`encoder`,e)}for(let[e,n]of Object.entries(t.defaultParams))if(typeof n!=`object`||!n||Array.isArray(n))throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" defaultParams must be a plain object, got ${Array.isArray(n)?`array`:typeof n}`);for(let[e,n]of Object.entries(t.forwardFnMap)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" forwardTo callback must be a function, got ${typeof n}`);M(n,`forwardTo callback`,e)}}function Ve(e){let{config:t,tree:n}=O(e,`validateForwardToTargetsStore`);for(let[e,r]of Object.entries(t.forwardMap))if(!A(n,r))throw Error(`[validation-plugin] validateForwardToTargetsStore: forwardTo target "${r}" does not exist for route "${e}"`)}function F(e){if(!e||typeof e!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps must be an object`);let t=e;if(!t.dependencies||typeof t.dependencies!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.dependencies must be an object`);let n=t.dependencies;for(let e of Object.keys(n))if(Object.getOwnPropertyDescriptor(n,e)?.get)throw TypeError(`[validation-plugin] validateDependenciesStructure: dependency "${e}" must not use a getter`);if(!t.limits||typeof t.limits!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits must be an object`);let r=t.limits;for(let e of[`maxDependencies`,`maxPlugins`,`maxListeners`,`warnListeners`,`maxEventDepth`,`maxLifecycleHandlers`])if(typeof r[e]!=`number`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits.${e} must be a number, got ${typeof r[e]}`)}function He(e){let t=e&&typeof e==`object`?e:{};return t.limits&&typeof t.limits==`object`?t.limits:{}}function Ue(e,t){if(!e||typeof e!=`object`)return;let n=e;if(!Array.isArray(n.definitions))return;let r=n.definitions.length,i=t.maxRoutes;if(typeof i==`number`&&i>0&&r>i)throw RangeError(`[validation-plugin] validateLimitsConsistency: route count (${r}) exceeds configured limit (${i})`)}function We(e,t){if(!e||typeof e!=`object`)return;let n=e,r=n.dependencies,i=n.limits;if(!r||typeof r!=`object`||!i||typeof i!=`object`)return;let a=Object.keys(r).length,o=i,s=t.maxDependencies,c=o.maxDependencies,l=typeof s==`number`?s:c;if(typeof l==`number`&&l>0&&a>=l)throw RangeError(`[validation-plugin] validateLimitsConsistency: dependency count (${a}) reaches or exceeds maxDependencies limit (${l})`)}function Ge(e,t,n){let r=He(e);Ue(t,r),We(n,r)}function I(e,t){if(!(typeof e!=`string`||!e)&&!A(O(t,`validateResolvedDefaultRoute`).tree,e))throw Error(`[validation-plugin] defaultRoute resolved to non-existent route: "${e}"`)}function Ke(e){return`(${e.replaceAll(/(^<|>$)/g,``)})`}const L=`[^/?<]+`,qe=new RegExp(String.raw`([:*])(${L})(<[^>]+>)?(\?)?`,`g`),Je=new RegExp(String.raw`([:*]${L}(?:<[^>]+>)?)\?(?=[/?]|$)`,`g`),Ye=/<[^>]*>/g,Xe=/\?(.+)$/;function Ze(e){return e.replaceAll(Ye,e=>`<${`x`.repeat(e.length-2)}>`).replaceAll(Je,`$1\0`)}function Qe(e){let t=[],n=[],r=[],i={},a=new Map,o=Xe.exec(Ze(e));if(o!==null){let t=e.slice(o.index+1).split(`&`);for(let e of t){let t=e.trim();t.length>0&&(n.push(t),i[t]=`query`)}e=e.slice(0,o.index)}let s;for(;(s=qe.exec(e))!==null;){let e=s[1],n=s[2],o=s[3];if(e===`*`)r.push(n),t.push(n),i[n]=`url`;else if(t.push(n),i[n]=`url`,o){let e=`^${Ke(o)}$`;a.set(n,{pattern:new RegExp(e),constraint:o})}}return{urlParams:t,queryParams:n,spatParams:r,paramTypeMap:i,constraintPatterns:a,pathPattern:e}}RegExp(`^[:*](${L})`),Object.freeze(new Map),Object.freeze([]);function $e(e,t){let n=[],r=t.includes(`.`)?t.split(`.`):[t];e.path!==``&&n.push(e);let i=e;for(let e of r){let t=i.children.get(e);if(!t)return null;n.push(t),i=t}return n}function R(e,t){return TypeError(`[router.${e}] ${t}`)}const et=RegExp(`[:*](?!${L})`);function tt(e){let t=!1;for(let n of e)if(n===`<`)t=!0;else if(n===`>`){if(!t)return!1;t=!1}return!t}function nt(e,t,n,r){if(typeof e!=`string`){let t;throw t=e===null?`null`:Array.isArray(e)?`array`:typeof e,R(n,`Route path must be a string, got ${t}`)}if(e===``)return;if(/\s/.test(e))throw R(n,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw R(n,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes(`//`))throw R(n,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);if(!tt(e))throw R(n,`Invalid path for route "${t}": unbalanced constraint delimiter ('<' or '>') in "${e}"`);if(et.test(Qe(e).pathPattern))throw R(n,`Invalid path for route "${t}": parameter marker (':' or '*') without a name in "${e}"`);let i=r&&r.paramMeta.urlParams.length>0;if(e.startsWith(`~`)&&i)throw R(n,`Absolute path "${e}" cannot be used under parent route with URL parameters`)}const rt=/^[A-Z_a-z][\w-]*$/,it=/\S/,z=1e4;function B(e){return e===null?`null`:typeof e==`object`?`constructor`in e&&e.constructor.name!==`Object`?e.constructor.name:`object`:typeof e}function at(e){for(let t of Object.keys(e)){let n=Object.getOwnPropertyDescriptor(e,t);if(n&&(n.get||n.set))return!0}return!1}function ot(e,t){if(!e||typeof e!=`object`)throw TypeError(`[router.${t}] Route must be an object, got ${B(e)}`);let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw TypeError(`[router.${t}] Route must be a plain object, got ${B(e)}`);if(at(e))throw TypeError(`[router.${t}] Route must not have getters or setters`)}function st(e,t){if(e.encodeParams!==void 0&&typeof e.encodeParams!=`function`)throw TypeError(`[router.${t}] Route "${String(e.name)}" encodeParams must be a function`)}function ct(e,t){if(e.decodeParams!==void 0&&typeof e.decodeParams!=`function`)throw TypeError(`[router.${t}] Route "${String(e.name)}" decodeParams must be a function`)}function lt(e,t){if(typeof e.name!=`string`)throw TypeError(`[router.${t}] Route name must be a string, got ${B(e.name)}`);let n=e.name;if(n===``)throw TypeError(`[router.${t}] Route name cannot be empty`);if(!it.test(n))throw TypeError(`[router.${t}] Route name cannot contain only whitespace`);if(n.length>z)throw TypeError(`[router.${t}] Route name exceeds maximum length of ${z} characters`);if(!n.startsWith(`@@`)){if(n.includes(`.`))throw TypeError(`[router.${t}] Route name "${n}" cannot contain dots. Use children array or { parent } option in addRoute() instead.`);if(!rt.test(n))throw TypeError(`[router.${t}] Invalid route name "${n}". Name must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens.`)}}function V(e,t){if(!t.includes(`.`))return e.children.get(t);let n=e;for(let e of t.split(`.`))if(n=n.children.get(e),!n)return;return n}function ut(e,t,n){if(V(e,t))throw Error(`[router.${n}] Route "${t}" already exists`)}function dt(e,t,n){if(e.has(t))throw Error(`[router.${n}] Duplicate route "${t}" in batch`);e.add(t)}function ft(e,t,n,r){let i=t===``?e:V(e,t);if(i){for(let e of i.children.values())if(e.path===n)throw Error(`[router.${r}] Path "${n}" is already defined`)}}function pt(e,t,n,r){let i=e.get(t);if(i?.has(n))throw Error(`[router.${r}] Path "${n}" is already defined`);i?i.add(n):e.set(t,new Set([n]))}function H(e,t,n,r=``,i,a){ot(e,t);let o=e;lt(o,t),nt(o.path,o.name,t,n),st(o,t),ct(o,t);let s=o.name,c=r?`${r}.${s}`:s;n&&c&&ut(n,c,t),i&&dt(i,c,t);let l=o.path,u=r;if(n&&ft(n,u,l,t),a&&pt(a,u,l,t),o.children!==void 0){if(!Array.isArray(o.children))throw TypeError(`[router.${t}] Route "${s}" children must be an array, got ${B(o.children)}`);for(let e of o.children)H(e,t,n,c,i,a)}}function mt(e,t){if(e!==void 0&&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){if(e.canActivate!==void 0&&typeof e.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function for route "${t}", got ${g(e.canActivate)}`);if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${g(e.canDeactivate)}`);if(e.defaultParams!==void 0){let n=e.defaultParams;if(typeof n!=`object`||!n||Array.isArray(n))throw TypeError(`[router.addRoute] defaultParams must be an object for route "${t}", got ${g(e.defaultParams)}`)}if(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(mt(e.forwardTo,t),e.children)for(let n of e.children)U(n,`${t}.${n.name}`)}function ht(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 W(e){let t=new Set;for(let n of e)for(let e of ht(n))t.add(e);return t}function G(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 G(i.children,t,e,a)}throw Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function K(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 K(r.children,e))n.add(t)}return n}function q(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 q(r.children,e))n.set(t,i)}return n}function gt(e){let t=new Set;for(let n of e){for(let e of n.paramMeta.urlParams)t.add(e);for(let e of n.paramMeta.spatParams)t.add(e)}return t}function _t(e,t){let n=t.split(`.`),r=e;for(let e of n)if(r=r.children.get(e),!r)return!1;return!0}function vt(e,t,n,r){return t?gt($e(n,e)??[]):W(G(r,e))}function yt(e,t,n,r,i){let a=_t(i,t),o=r.has(t);if(!a&&!o)throw ReferenceError(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);let s=W(G(n,e)),c=[...vt(t,a,i,n)].filter(e=>!s.has(e));if(c.length>0)throw Error(`[router.addRoute] forwardTo target "${t}" requires params [${c.join(`, `)}] that are not available in source route "${e}"`)}function bt(e,n,r){let i=K(e),a=q(e),o={...n};for(let[e,t]of a)o[e]=t;for(let[t,n]of a)yt(t,n,e,i,r);for(let e of Object.keys(o))t(e,o)}function J(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 Y(e,t){for(let n of e)n&&typeof n==`object`&&typeof n.name==`string`&&(J(n.name,t),n.children&&Y(n.children,t))}function xt(e){h(e,`removeRoute`)}function St(e){if(typeof e!=`string`)throw TypeError(`[router.setRootPath] rootPath must be a string, got ${g(e)}`)}function X(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function Ct(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function, got ${g(t.canActivate)}`);if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function, got ${g(t.canDeactivate)}`)}function wt(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 Tt(e){for(let t of e){if(typeof t!=`object`||!t||Array.isArray(t))throw TypeError(`[router.addRoute] Route must be an object, got ${g(t)}`);U(t,t.name)}}function Et(e){if(typeof e!=`string`||e===``)throw TypeError(`[router.addRoute] parent option must be a non-empty string, got ${g(e)}`);h(e,`addRoute`)}function Dt(e,t,n,r){if(!p(e))throw TypeError(`[router.isActiveRoute] name must be a string, got ${typeof e}`);if(t!==void 0&&!d(t))throw TypeError(`[router.isActiveRoute] params must be a plain object, got ${g(t)}`);if(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 Ot(e,t,n){if(!p(e))throw TypeError(`[router.${n}] Invalid routeName: ${g(e)}. Expected string.`);if(!d(t))throw TypeError(`[router.${n}] Invalid routeParams: ${g(t)}. Expected plain object.`)}function Z(e,t){if(h(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 ${g(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 kt(e,t,n,r){if(e!=null){if(typeof e!=`string`&&typeof e!=`function`)throw TypeError(`[router.updateRoute] forwardTo must be a string, function, or null, got ${g(e)}`);typeof e==`function`&&Q(e,`forwardTo callback`)}if(t!=null&&(typeof t!=`object`||Array.isArray(t)))throw TypeError(`[router.updateRoute] defaultParams must be an object or null, got ${g(t)}`);$(n,`decodeParams`),$(r,`encodeParams`)}function At(e){if(!p(e)||e===``)throw TypeError(`[router.buildPath] route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`)}function jt(e){if(!p(e))throw TypeError(`[router.matchPath] path must be a string, got ${typeof e}`)}function Mt(e){if(!p(e))throw TypeError(`[router.shouldUpdateNode] nodeName must be a string, got ${typeof e}`)}function Nt(e,t,n,r){if(r&&t){let e=t;for(let t of r.split(`.`))if(e=e.children.get(t),!e)throw ReferenceError(`[router.addRoute] Parent route "${r}" does not exist`)}let i=new Set,a=new Map;for(let n of e)H(n,`addRoute`,t,r??``,i,a);t&&n&&bt(e,n,t)}function Pt(e){let t=new Set;for(let n of e)for(let e of n.paramMeta.urlParams)t.add(e);return t}function Ft(e,t,n){let r=n.getSegmentsByName(e),i=n.getSegmentsByName(t),a=Pt(r),o=[];for(let e of i)for(let t of e.paramMeta.urlParams)o.push(t);let s=o.filter(e=>!a.has(e));if(s.length>0)throw Error(`[router.addRoute] forwardTo target "${t}" requires params [${s.join(`, `)}] that are not available in source route "${e}"`)}function It(e,n,r){t(e,{...r.forwardMap,[e]:n})}function Lt(e,t,n,r,i){if(!n(e))throw ReferenceError(`[router.updateRoute] route "${e}" does not exist`);if(t!=null&&typeof t==`string`){if(!n(t))throw Error(`[router.updateRoute] forwardTo target "${t}" does not exist`);Ft(e,t,r),It(e,t,i)}}function Rt(e,t,n){if(!p(e))throw TypeError(`[router.makeState] Invalid name: ${g(e)}. Expected string.`);if(t!==void 0&&!d(t))throw TypeError(`[router.makeState] Invalid params: ${g(t)}. Expected plain object.`);if(n!==void 0&&!p(n))throw TypeError(`[router.makeState] Invalid path: ${g(n)}. Expected string.`)}function zt(e){return{routes:{validateBuildPathArgs:At,validateMatchPathArgs:jt,validateIsActiveRouteArgs:Dt,validateShouldUpdateNodeArgs:Mt,validateStateBuilderArgs:Ot,validateAddRouteArgs(e){Tt(e)},validateRoutes(e,t){let n=t;Nt(e,n.tree,n.config?.forwardMap)},validateRemoveRouteArgs:xt,validateUpdateRouteBasicArgs:Z,validateUpdateRoutePropertyTypes(e,t){let n=t;kt(n.forwardTo,n.defaultParams,n.decodeParams,n.encodeParams)},validateUpdateRoute(e,t,n){let r=n,i=t.forwardTo;Lt(e,i,e=>r.matcher.hasRoute(e),r.matcher,r.config)},validateParentOption(e,t){Et(e);let n=t;for(let t of e.split(`.`)){let r=n.children.get(t);if(!r)throw ReferenceError(`[router.addRoute] Parent route "${e}" does not exist`);n=r}},validateRouteName(e,t){h(e,t)},throwIfInternalRoute(e,t){J(e,t)},throwIfInternalRouteInArray(e,t){Y(e,t)},validateExistingRoutes:N,validateForwardToConsistency:P,validateSetRootPathArgs:St,guardRouteCallbacks:Ct,guardNoAsyncCallbacks:wt},options:{validateLimitValue(e,t){C(e,t,`validate`)},validateLimits(e){w(e,`validate`)},validateOptions:Ae,validateResolvedDefaultRoute:I},dependencies:{validateDependencyName:re,validateSetDependencyArgs(e,t,n){ie(e)},validateDependenciesObject:ae,validateDependencyExists(e,t){let n=t.dependencies?.[e];oe(n,e)},validateDependencyLimit(e,t){},validateDependenciesStructure:F,validateDependencyCount:se,validateCloneArgs:ce,warnOverwrite:le,warnBatchOverwrite:ue,warnRemoveNonExistent:de},plugins:{validatePluginLimit(e,t){Me(e,1,t?.maxPlugins)},validateNoDuplicatePlugins(e,t){},validatePluginKeys:Pe,validateCountThresholds(t){Ne(t,e.getOptions().limits?.maxPlugins??50)},warnBatchDuplicates:Fe,warnPluginMethodType:Ie,warnPluginAfterStart:Le,validateAddInterceptorArgs:Re},lifecycle:{validateHandler:me,validateNotRegistering(e,t,n){he(!1,e,n)},validateHandlerLimit(e,t,n){ge(e,n,t?.maxLifecycleHandlers)},validateCountThresholds(t,n){_e(t,n,e.getOptions().limits?.maxLifecycleHandlers??200)},warnOverwrite:ve,warnAsyncGuardSync:ye},navigation:{validateNavigateArgs:be,validateNavigateToDefaultArgs:xe,validateNavigateToStateArgs:Se,validateNavigationOptions:Ce,validateParams:we,validateStartArgs:Te},state:{validateMakeStateArgs:Rt,validateAreStatesEqualArgs(e,t,n){if(!f(e))throw TypeError(`[router.areStatesEqual] Invalid state1: ${g(e)}. Expected State object.`);if(!f(t))throw TypeError(`[router.areStatesEqual] Invalid state2: ${g(t)}. Expected State object.`);if(n!==void 0&&!m(n))throw TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${g(n)}. Expected boolean.`)}},eventBus:{validateEventName:v,validateListenerArgs(e,t){pe(e,t)}}}}function Bt(){return t=>{let r=n(t);if(t.isActive())throw new e(`VALIDATION_PLUGIN_AFTER_START`,{message:`validation-plugin must be registered before router.start()`});r.validator=zt(r);try{let e=r.routeGetStore(),t=r.dependenciesGetStore(),n=r.getOptions();N(e),P(e),Be(e),Ve(e),F(t),Ge(n,e,t),r.validator.options.validateOptions(n,`constructor (retrospective)`),typeof n.defaultRoute==`string`&&I(n.defaultRoute,e)}catch(e){throw r.validator=null,e}return{teardown(){r.validator=null}}}}export{Bt as validationPlugin};
1
+ import{RouterError as e,resolveForwardChain as t}from"@real-router/core";import{getInternals as n}from"@real-router/core/validation";import{logger as r}from"@real-router/logger";const i=[`replace`,`reload`,`force`,`forceDeactivate`,`redirected`];function a(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;for(let e of i){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 o=/\S/,s=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function c(e,t){return TypeError(`[router.${e}] ${t}`)}function l(e){return typeof e==`string`?e===``?!0:e.length>1e4?!1:e.startsWith(`@@`)?!0:s.test(e):!1}function u(e,t=new WeakSet){if(e==null)return!0;let n=typeof e;if(n===`string`||n===`boolean`)return!0;if(n===`number`)return Number.isFinite(e);if(n===`function`||n===`symbol`)return!1;if(Array.isArray(e))return t.has(e)?!1:(t.add(e),e.every(e=>u(e,t)));if(n===`object`){if(t.has(e))return!1;t.add(e);let n=Object.getPrototypeOf(e);return n!==null&&n!==Object.prototype?!1:Object.values(e).every(e=>u(e,t))}return!1}function ee(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`boolean`?!0:t===`number`?Number.isFinite(e):!1}function d(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);if(t!==null&&t!==Object.prototype)return!1;let n=!1;for(let t in e){if(!Object.hasOwn(e,t))continue;let r=e[t];if(!ee(r)){let e=typeof r;if(e===`function`||e===`symbol`)return!1;n=!0;break}}return n?u(e):!0}function te(e){return l(e.name)&&typeof e.path==`string`&&d(e.params)}function f(e){return typeof e!=`object`||!e?!1:te(e)}function p(e){return typeof e==`string`}function m(e){return typeof e==`boolean`}function ne(e,t){return e in t}function h(e,t){if(typeof e!=`string`)throw c(t,`Route name must be a string, got ${typeof e}`);if(e!==``){if(!o.test(e))throw c(t,`Route name cannot contain only whitespace`);if(e.length>1e4)throw c(t,`Route name exceeds maximum length of 10000 characters. This is a technical safety limit.`);if(!e.startsWith(`@@`)&&!s.test(e))throw c(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 g(e){return e===null?`null`:Array.isArray(e)?`array[${e.length}]`:typeof e==`object`?`constructor`in e&&e.constructor.name!==`Object`?e.constructor.name:`object`:typeof e}function _(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}function re(e,t){if(typeof e!=`string`)throw TypeError(`[router.${t}] dependency name must be a string, got ${typeof e}`)}function ie(e){if(typeof e!=`string`)throw TypeError(`[router.setDependency] dependency name must be a string, got ${typeof e}`)}function ae(e,t){if(!(e&&typeof e==`object`&&e.constructor===Object))throw TypeError(`[router.${t}] Invalid argument: expected plain object, received ${g(e)}`);for(let n in e)if(Object.getOwnPropertyDescriptor(e,n)?.get)throw TypeError(`[router.${t}] Getters not allowed: "${n}"`)}function oe(e,t){if(e===void 0)throw ReferenceError(`[router.getDependency] dependency "${t}" not found`)}function se(e,t){let n=e,i=n.limits?.maxDependencies??100;if(i===0)return;let a=Object.keys(n.dependencies).length,{warn:o,error:s}=_(i);if(a>=i)throw RangeError(`[router.${t}] Dependency limit exceeded (${i}). Current: ${a}.`);a===s?r.error(`router.${t}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${i}.`):a===o&&r.warn(`router.${t}`,`${a} dependencies registered. Consider if all are necessary.`)}function ce(e){if(e!==void 0){if(!(e&&typeof e==`object`&&e.constructor===Object))throw TypeError(`[cloneRouter] Invalid dependencies: expected plain object or undefined, received ${typeof e}`);for(let t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw TypeError(`[cloneRouter] Getters not allowed in dependencies: "${t}"`)}}function le(e,t){r.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function ue(e,t){r.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function de(e){r.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const fe=new Set([`$start`,`$stop`,`$$start`,`$$leaveApprove`,`$$cancel`,`$$success`,`$$error`]);function v(e){if(!fe.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(v(e),typeof t!=`function`)throw TypeError(`[router.addEventListener] callback must be a function, got ${typeof t}`)}function me(e,t){if(!m(e)&&typeof e!=`function`)throw TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${g(e)}`)}function he(e,t,n){if(e)throw Error(`[router.${n}] Cannot modify route "${t}" during its own registration`)}function ge(e,t,n=200){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 _e(e,t,n){if(n===0)return;let{warn:i,error:a}=_(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 ve(e,t,n){r.warn(`router.${n}`,`Overwriting existing ${t} handler for route "${e}"`)}function ye(e,t){r.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}function be(e){if(typeof e!=`string`)throw TypeError(`[router.navigate] Invalid route name: expected string, got ${g(e)}`)}function xe(e){if(e!==void 0&&(typeof e!=`object`||!e))throw TypeError(`[router.navigateToDefault] Invalid options: ${g(e)}. Expected NavigationOptions object.`)}function Se(e){if(typeof e!=`object`||!e)throw TypeError(`[router.navigateToState] Invalid state: ${g(e)}. Expected State object.`);let t=e;if(!p(t.name))throw TypeError(`[router.navigateToState] Invalid state.name: ${g(t.name)}. Expected string.`);if(!d(t.params))throw TypeError(`[router.navigateToState] Invalid state.params: ${g(t.params)}. Expected plain object.`);if(!p(t.path))throw TypeError(`[router.navigateToState] Invalid state.path: ${g(t.path)}. Expected string.`)}function Ce(e,t){if(!a(e))throw TypeError(`[router.${t}] Invalid options: ${g(e)}. Expected NavigationOptions object.`)}function we(e,t){if(e!==void 0&&!d(e))throw TypeError(`[router.${t}] params must be a plain object, got ${g(e)}`)}function Te(e){if(e!==void 0&&typeof e!=`string`)throw TypeError(`[router.start] path must be a string, got ${g(e)}.`);if(typeof e==`string`&&e!==``&&!e.startsWith(`/`))throw TypeError(`[router.start] path must start with "/", got "${e}".`)}const y={trailingSlash:[`strict`,`never`,`always`,`preserve`],queryParamsMode:[`default`,`strict`,`loose`],urlParamsEncoding:[`default`,`uri`,`uriComponent`,`none`]},b={arrayFormat:[`none`,`brackets`,`index`,`comma`],booleanFormat:[`none`,`auto`,`empty-true`],nullFormat:[`default`,`hidden`],numberFormat:[`none`,`auto`]},Ee=new Set([`defaultRoute`,`defaultParams`,`trailingSlash`,`queryParamsMode`,`queryParams`,`urlParamsEncoding`,`allowNotFound`,`rewritePathOnMatch`,`logger`,`limits`]),x={maxDependencies:{min:0,max:1e4},maxPlugins:{min:0,max:1e3},maxListeners:{min:0,max:1e5},warnListeners:{min:0,max:1e5},maxEventDepth:{min:0,max:100},maxLifecycleHandlers:{min:0,max:1e4}};function S(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=x[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 C(e,t){if(!e||typeof e!=`object`||e.constructor!==Object)throw TypeError(`[router.${t}] invalid limits: expected plain object, got ${typeof e}`);for(let[n,r]of Object.entries(e)){if(!Object.hasOwn(x,n))throw TypeError(`[router.${t}] unknown limit: "${n}"`);r!==void 0&&S(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 w(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 De(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 T(e,t){if(e!==void 0&&typeof e!=`function`&&(!e||typeof e!=`object`||Array.isArray(e)||e.constructor!==Object))throw TypeError(`[router.${t}] Invalid "defaultParams": expected plain object or function, got ${typeof e}`)}function E(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,r]of Object.entries(n)){if(!ne(e,b))throw TypeError(`[router.${t}] Invalid "queryParams.${e}": unknown option`);w(r,`queryParams.${e}`,b[e],t)}}function Oe(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 Object.keys(n))if(!Ee.has(e))throw TypeError(`[router.${t}] Unknown option: "${e}"`);if(De(n.defaultRoute,t),T(n.defaultParams,t),w(n.trailingSlash,`trailingSlash`,y.trailingSlash,t),w(n.queryParamsMode,`queryParamsMode`,y.queryParamsMode,t),w(n.urlParamsEncoding,`urlParamsEncoding`,y.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}`);E(n.queryParams,t),n.limits!==void 0&&C(n.limits,t)}const D=`router.usePlugin`,ke={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function Ae(e,t,n=50){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 je(e,t){if(t===0)return;let{warn:n,error:i}=_(t);e>=i?r.error(D,`${e} plugins registered! This is excessive. Hard limit at ${t}.`):e>=n&&r.warn(D,`${e} plugins registered. Consider if all are necessary.`)}function Me(e){for(let t in e)if(!(t===`teardown`||Object.hasOwn(ke,t)))throw TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}function Ne(){r.warn(D,`Duplicate factory in batch, will be registered once`)}function Pe(e){r.warn(D,`Property '${e}' is not a function, skipping`)}function Fe(e){e===`onStart`&&r.warn(D,`Router already started, onStart will not be called`)}function Ie(e,t){let n=[`start`,`buildPath`,`forwardState`];if(typeof e!=`string`||!n.includes(e))throw TypeError(`[router.addInterceptor] Invalid method: "${String(e)}". Must be one of: ${n.join(`, `)}`);if(typeof t!=`function`)throw TypeError(`[router.addInterceptor] interceptor must be a function, got ${typeof t}`)}function O(e,t){if(!e||typeof e!=`object`)throw TypeError(`[validation-plugin] ${t}: store must be an object`);let n=e;if(!Array.isArray(n.definitions))throw TypeError(`[validation-plugin] ${t}: store.definitions must be an array`);if(!n.config||typeof n.config!=`object`)throw TypeError(`[validation-plugin] ${t}: store.config must be an object`);if(!n.tree||typeof n.tree!=`object`)throw TypeError(`[validation-plugin] ${t}: store.tree must be an object`);return n}function k(e,t,n=``){for(let r of e){let e=n?`${n}.${r.name}`:r.name;t(r,e),r.children&&k(r.children,t,e)}}function A(e,t){let n=t.split(`.`),r=e;for(let e of n)if(r=r.children.get(e),!r)return!1;return!0}function Le(e,n){try{return t(e,n)}catch(e){throw Error(`[validation-plugin] ${e.message}`,{cause:e})}}function j(e){let t=new Set;for(let n of e){for(let e of n.paramMeta.urlParams)t.add(e);for(let e of n.paramMeta.spatParams)t.add(e)}return t}function M(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 N(e){let t=O(e,`validateExistingRoutes`),n=new Set;k(t.definitions,(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})`);if(n.has(t))throw Error(`[validation-plugin] validateExistingRoutes: duplicate route name detected: "${t}"`);n.add(t)})}function P(e){let{config:t,tree:n,matcher:r}=O(e,`validateForwardToConsistency`);for(let[e,i]of Object.entries(t.forwardMap)){if(!A(n,i))throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${i}" does not exist in tree (source route: "${e}")`);let t=r.getSegmentsByName(e),a=r.getSegmentsByName(i);if(t&&a){let n=j(t),r=[...j(a)].filter(e=>!n.has(e));if(r.length>0)throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${i}" requires params [${r.join(`, `)}] not available in source route "${e}"`)}}for(let e of Object.keys(t.forwardMap))Le(e,t.forwardMap)}function Re(e){let{config:t}=O(e,`validateRoutePropertiesStore`);for(let[e,n]of Object.entries(t.decoders)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" decoder must be a function, got ${typeof n}`);M(n,`decoder`,e)}for(let[e,n]of Object.entries(t.encoders)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" encoder must be a function, got ${typeof n}`);M(n,`encoder`,e)}for(let[e,n]of Object.entries(t.defaultParams))if(typeof n!=`object`||!n||Array.isArray(n))throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" defaultParams must be a plain object, got ${Array.isArray(n)?`array`:typeof n}`);for(let[e,n]of Object.entries(t.forwardFnMap)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" forwardTo callback must be a function, got ${typeof n}`);M(n,`forwardTo callback`,e)}}function ze(e){let{config:t,tree:n}=O(e,`validateForwardToTargetsStore`);for(let[e,r]of Object.entries(t.forwardMap))if(!A(n,r))throw Error(`[validation-plugin] validateForwardToTargetsStore: forwardTo target "${r}" does not exist for route "${e}"`)}function F(e){if(!e||typeof e!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps must be an object`);let t=e;if(!t.dependencies||typeof t.dependencies!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.dependencies must be an object`);let n=t.dependencies;for(let e of Object.keys(n))if(Object.getOwnPropertyDescriptor(n,e)?.get)throw TypeError(`[validation-plugin] validateDependenciesStructure: dependency "${e}" must not use a getter`);if(!t.limits||typeof t.limits!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits must be an object`);let r=t.limits;for(let e of[`maxDependencies`,`maxPlugins`,`maxListeners`,`warnListeners`,`maxEventDepth`,`maxLifecycleHandlers`])if(typeof r[e]!=`number`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits.${e} must be a number, got ${typeof r[e]}`)}function Be(e){let t=e&&typeof e==`object`?e:{};return t.limits&&typeof t.limits==`object`?t.limits:{}}function Ve(e,t){if(!e||typeof e!=`object`)return;let n=e;if(!Array.isArray(n.definitions))return;let r=n.definitions.length,i=t.maxRoutes;if(typeof i==`number`&&i>0&&r>i)throw RangeError(`[validation-plugin] validateLimitsConsistency: route count (${r}) exceeds configured limit (${i})`)}function He(e,t){if(!e||typeof e!=`object`)return;let n=e,r=n.dependencies,i=n.limits;if(!r||typeof r!=`object`||!i||typeof i!=`object`)return;let a=Object.keys(r).length,o=i,s=t.maxDependencies,c=o.maxDependencies,l=typeof s==`number`?s:c;if(typeof l==`number`&&l>0&&a>=l)throw RangeError(`[validation-plugin] validateLimitsConsistency: dependency count (${a}) reaches or exceeds maxDependencies limit (${l})`)}function Ue(e,t,n){let r=Be(e);Ve(t,r),He(n,r)}function I(e,t){if(!(typeof e!=`string`||!e)&&!A(O(t,`validateResolvedDefaultRoute`).tree,e))throw Error(`[validation-plugin] defaultRoute resolved to non-existent route: "${e}"`)}function We(e){return`(${e.replaceAll(/(^<|>$)/g,``)})`}const L=`[^/?<]+`,Ge=new RegExp(String.raw`([:*])(${L})(<[^>]+>)?(\?)?`,`g`),Ke=new RegExp(String.raw`([:*]${L}(?:<[^>]+>)?)\?(?=[/?]|$)`,`g`),qe=/<[^>]*>/g,Je=/\?(.+)$/;function Ye(e){return e.replaceAll(qe,e=>`<${`x`.repeat(e.length-2)}>`).replaceAll(Ke,`$1\0`)}function R(e){let t=[],n=[],r=[],i={},a=new Map,o=Je.exec(Ye(e));if(o!==null){let t=e.slice(o.index+1).split(`&`);for(let e of t){let t=e.trim();t.length>0&&(n.push(t),i[t]=`query`)}e=e.slice(0,o.index)}let s;for(;(s=Ge.exec(e))!==null;){let e=s[1],n=s[2],o=s[3];if(e===`*`)r.push(n),t.push(n),i[n]=`url`;else if(t.push(n),i[n]=`url`,o){let e=`^${We(o)}$`;a.set(n,{pattern:new RegExp(e),constraint:o})}}return{urlParams:t,queryParams:n,spatParams:r,paramTypeMap:i,constraintPatterns:a,pathPattern:e}}RegExp(`^[:*](${L})`),Object.freeze(new Map),Object.freeze([]);function Xe(e,t){let n=[],r=t.includes(`.`)?t.split(`.`):[t];e.path!==``&&n.push(e);let i=e;for(let e of r){let t=i.children.get(e);if(!t)return null;n.push(t),i=t}return n}function z(e,t){return TypeError(`[router.${e}] ${t}`)}const Ze=RegExp(`[:*](?!${L})`);function Qe(e){let t=!1;for(let n of e)if(n===`<`)t=!0;else if(n===`>`){if(!t)return!1;t=!1}return!t}function $e(e,t,n,r){if(typeof e!=`string`){let t;throw t=e===null?`null`:Array.isArray(e)?`array`:typeof e,z(n,`Route path must be a string, got ${t}`)}if(e===``)return;if(/\s/.test(e))throw z(n,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw z(n,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes(`//`))throw z(n,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);if(!Qe(e))throw z(n,`Invalid path for route "${t}": unbalanced constraint delimiter ('<' or '>') in "${e}"`);if(Ze.test(R(e).pathPattern))throw z(n,`Invalid path for route "${t}": parameter marker (':' or '*') without a name in "${e}"`);let i=r&&r.paramMeta.urlParams.length>0;if(e.startsWith(`~`)&&i)throw z(n,`Absolute path "${e}" cannot be used under parent route with URL parameters`)}const et=/^[A-Z_a-z][\w-]*$/,tt=/\S/,B=1e4;function V(e){return e===null?`null`:typeof e==`object`?`constructor`in e&&e.constructor.name!==`Object`?e.constructor.name:`object`:typeof e}function nt(e){for(let t of Object.keys(e)){let n=Object.getOwnPropertyDescriptor(e,t);if(n&&(n.get||n.set))return!0}return!1}function rt(e,t){if(!e||typeof e!=`object`)throw TypeError(`[router.${t}] Route must be an object, got ${V(e)}`);let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw TypeError(`[router.${t}] Route must be a plain object, got ${V(e)}`);if(nt(e))throw TypeError(`[router.${t}] Route must not have getters or setters`)}function it(e,t){if(e.encodeParams!==void 0&&typeof e.encodeParams!=`function`)throw TypeError(`[router.${t}] Route "${String(e.name)}" encodeParams must be a function`)}function at(e,t){if(e.decodeParams!==void 0&&typeof e.decodeParams!=`function`)throw TypeError(`[router.${t}] Route "${String(e.name)}" decodeParams must be a function`)}function ot(e,t){if(typeof e.name!=`string`)throw TypeError(`[router.${t}] Route name must be a string, got ${V(e.name)}`);let n=e.name;if(n===``)throw TypeError(`[router.${t}] Route name cannot be empty`);if(!tt.test(n))throw TypeError(`[router.${t}] Route name cannot contain only whitespace`);if(n.length>B)throw TypeError(`[router.${t}] Route name exceeds maximum length of ${B} characters`);if(!n.startsWith(`@@`)){if(n.includes(`.`))throw TypeError(`[router.${t}] Route name "${n}" cannot contain dots. Use children array or { parent } option in addRoute() instead.`);if(!et.test(n))throw TypeError(`[router.${t}] Invalid route name "${n}". Name must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens.`)}}function H(e,t){if(!t.includes(`.`))return e.children.get(t);let n=e;for(let e of t.split(`.`))if(n=n.children.get(e),!n)return;return n}function st(e,t,n){if(H(e,t))throw Error(`[router.${n}] Route "${t}" already exists`)}function ct(e,t,n){if(e.has(t))throw Error(`[router.${n}] Duplicate route "${t}" in batch`);e.add(t)}function lt(e,t,n,r){let i=t===``?e:H(e,t);if(i){for(let e of i.children.values())if(e.path===n)throw Error(`[router.${r}] Path "${n}" is already defined`)}}function ut(e,t,n,r){let i=e.get(t);if(i?.has(n))throw Error(`[router.${r}] Path "${n}" is already defined`);i?i.add(n):e.set(t,new Set([n]))}function U(e,t,n,r=``,i,a){rt(e,t);let o=e;ot(o,t),$e(o.path,o.name,t,n),it(o,t),at(o,t);let s=o.name,c=r?`${r}.${s}`:s;n&&c&&st(n,c,t),i&&ct(i,c,t);let l=o.path,u=r;if(n&&lt(n,u,l,t),a&&ut(a,u,l,t),o.children!==void 0){if(!Array.isArray(o.children))throw TypeError(`[router.${t}] Route "${s}" children must be an array, got ${V(o.children)}`);for(let e of o.children)U(e,t,n,c,i,a)}}function dt(e,t){if(e!==void 0&&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 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 ${g(e.canActivate)}`);if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${g(e.canDeactivate)}`);if(e.defaultParams!==void 0){let n=e.defaultParams;if(typeof n!=`object`||!n||Array.isArray(n))throw TypeError(`[router.addRoute] defaultParams must be an object for route "${t}", got ${g(e.defaultParams)}`)}if(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(dt(e.forwardTo,t),e.children)for(let n of e.children)W(n,`${t}.${n.name}`)}function ft(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 ft(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 pt(e){let t=new Set;for(let n of e){for(let e of n.paramMeta.urlParams)t.add(e);for(let e of n.paramMeta.spatParams)t.add(e)}return t}function mt(e,t){let n=t.split(`.`),r=e;for(let e of n)if(r=r.children.get(e),!r)return!1;return!0}function ht(e,t,n,r){return t?pt(Xe(n,e)??[]):G(K(r,e))}function gt(e,t,n,r,i){let a=mt(i,t),o=r.has(t);if(!a&&!o)throw ReferenceError(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);let s=G(K(n,e)),c=[...ht(t,a,i,n)].filter(e=>!s.has(e));if(c.length>0)throw Error(`[router.addRoute] forwardTo target "${t}" requires params [${c.join(`, `)}] that are not available in source route "${e}"`)}function _t(e,n,r){let i=q(e),a=J(e),o={...n};for(let[e,t]of a)o[e]=t;for(let[t,n]of a)gt(t,n,e,i,r);for(let e of Object.keys(o))t(e,o)}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 vt(e){h(e,`removeRoute`)}function yt(e){if(typeof e!=`string`)throw TypeError(`[router.setRootPath] rootPath must be a string, got ${g(e)}`)}function Z(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function bt(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function, got ${g(t.canActivate)}`);if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function, got ${g(t.canDeactivate)}`)}function xt(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 St(e){for(let t of e){if(typeof t!=`object`||!t||Array.isArray(t))throw TypeError(`[router.addRoute] Route must be an object, got ${g(t)}`);W(t,t.name)}}function Ct(e){if(typeof e!=`string`||e===``)throw TypeError(`[router.addRoute] parent option must be a non-empty string, got ${g(e)}`);h(e,`addRoute`)}function wt(e,t,n,r){if(!p(e))throw TypeError(`[router.isActiveRoute] name must be a string, got ${typeof e}`);if(t!==void 0&&!d(t))throw TypeError(`[router.isActiveRoute] params must be a plain object, got ${g(t)}`);if(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 Tt(e,t,n){if(!p(e))throw TypeError(`[router.${n}] Invalid routeName: ${g(e)}. Expected string.`);if(!d(t))throw TypeError(`[router.${n}] Invalid routeParams: ${g(t)}. Expected plain object.`)}function Et(e,t){if(h(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 ${g(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 Dt(e,t,n,r){if(e!=null){if(typeof e!=`string`&&typeof e!=`function`)throw TypeError(`[router.updateRoute] forwardTo must be a string, function, or null, got ${g(e)}`);typeof e==`function`&&Q(e,`forwardTo callback`)}if(t!=null&&(typeof t!=`object`||Array.isArray(t)))throw TypeError(`[router.updateRoute] defaultParams must be an object or null, got ${g(t)}`);$(n,`decodeParams`),$(r,`encodeParams`)}function Ot(e){if(!p(e)||e===``)throw TypeError(`[router.buildPath] route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`)}function kt(e){if(!p(e))throw TypeError(`[router.matchPath] path must be a string, got ${typeof e}`)}function At(e){if(!p(e))throw TypeError(`[router.shouldUpdateNode] nodeName must be a string, got ${typeof e}`)}function jt(e,t,n,r){if(r&&t){let e=t;for(let t of r.split(`.`))if(e=e.children.get(t),!e)throw ReferenceError(`[router.addRoute] Parent route "${r}" does not exist`)}let i=new Set,a=new Map;for(let n of e)U(n,`addRoute`,t,r??``,i,a);t&&n&&_t(e,n,t)}function Mt(e){let t=new Set;for(let n of e)for(let e of n.paramMeta.urlParams)t.add(e);return t}function Nt(e,t,n){let r=n.getSegmentsByName(e),i=n.getSegmentsByName(t),a=Mt(r),o=[];for(let e of i)for(let t of e.paramMeta.urlParams)o.push(t);let s=o.filter(e=>!a.has(e));if(s.length>0)throw Error(`[router.addRoute] forwardTo target "${t}" requires params [${s.join(`, `)}] that are not available in source route "${e}"`)}function Pt(e,n,r){t(e,{...r.forwardMap,[e]:n})}function Ft(e,t,n,r,i){if(!n(e))throw ReferenceError(`[router.updateRoute] route "${e}" does not exist`);if(t!=null&&typeof t==`string`){if(!n(t))throw Error(`[router.updateRoute] forwardTo target "${t}" does not exist`);Nt(e,t,r),Pt(e,t,i)}}function It(e,t,n){if(!p(e))throw TypeError(`[router.makeState] Invalid name: ${g(e)}. Expected string.`);if(t!==void 0&&!d(t))throw TypeError(`[router.makeState] Invalid params: ${g(t)}. Expected plain object.`);if(n!==void 0&&!p(n))throw TypeError(`[router.makeState] Invalid path: ${g(n)}. Expected string.`)}function Lt(e){return{routes:{validateBuildPathArgs:Ot,validateMatchPathArgs:kt,validateIsActiveRouteArgs:wt,validateShouldUpdateNodeArgs:At,validateStateBuilderArgs:Tt,validateAddRouteArgs(e){St(e)},validateRoutes(e,t){let n=t;jt(e,n.tree,n.config?.forwardMap)},validateRemoveRouteArgs:vt,validateUpdateRouteBasicArgs:Et,validateUpdateRoutePropertyTypes(e,t){let n=t;Dt(n.forwardTo,n.defaultParams,n.decodeParams,n.encodeParams)},validateUpdateRoute(e,t,n){let r=n,i=t.forwardTo;Ft(e,i,e=>r.matcher.hasRoute(e),r.matcher,r.config)},validateParentOption(e,t){Ct(e);let n=t;for(let t of e.split(`.`)){let r=n.children.get(t);if(!r)throw ReferenceError(`[router.addRoute] Parent route "${e}" does not exist`);n=r}},validateRouteName(e,t){h(e,t)},throwIfInternalRoute(e,t){Y(e,t)},throwIfInternalRouteInArray(e,t){X(e,t)},validateExistingRoutes:N,validateForwardToConsistency:P,validateSetRootPathArgs:yt,guardRouteCallbacks:bt,guardNoAsyncCallbacks:xt},options:{validateLimitValue(e,t){S(e,t,`validate`)},validateLimits(e){C(e,`validate`)},validateOptions:Oe,validateResolvedDefaultRoute:I},dependencies:{validateDependencyName:re,validateSetDependencyArgs(e,t,n){ie(e)},validateDependenciesObject:ae,validateDependencyExists(e,t){let n=t.dependencies?.[e];oe(n,e)},validateDependencyLimit(e,t){},validateDependenciesStructure:F,validateDependencyCount:se,validateCloneArgs:ce,warnOverwrite:le,warnBatchOverwrite:ue,warnRemoveNonExistent:de},plugins:{validatePluginLimit(e,t){Ae(e,1,t?.maxPlugins)},validateNoDuplicatePlugins(e,t){},validatePluginKeys:Me,validateCountThresholds(t){je(t,e.getOptions().limits?.maxPlugins??50)},warnBatchDuplicates:Ne,warnPluginMethodType:Pe,warnPluginAfterStart:Fe,validateAddInterceptorArgs:Ie},lifecycle:{validateHandler:me,validateNotRegistering(e,t,n){he(!1,e,n)},validateHandlerLimit(e,t,n){ge(e,n,t?.maxLifecycleHandlers)},validateCountThresholds(t,n){_e(t,n,e.getOptions().limits?.maxLifecycleHandlers??200)},warnOverwrite:ve,warnAsyncGuardSync:ye},navigation:{validateNavigateArgs:be,validateNavigateToDefaultArgs:xe,validateNavigateToStateArgs:Se,validateNavigationOptions:Ce,validateParams:we,validateStartArgs:Te},state:{validateMakeStateArgs:It,validateAreStatesEqualArgs(e,t,n){if(!f(e))throw TypeError(`[router.areStatesEqual] Invalid state1: ${g(e)}. Expected State object.`);if(!f(t))throw TypeError(`[router.areStatesEqual] Invalid state2: ${g(t)}. Expected State object.`);if(n!==void 0&&!m(n))throw TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${g(n)}. Expected boolean.`)}},eventBus:{validateEventName:v,validateListenerArgs(e,t){pe(e,t)}}}}function Rt(){return t=>{let r=n(t);if(t.isActive())throw new e(`VALIDATION_PLUGIN_AFTER_START`,{message:`validation-plugin must be registered before router.start()`});r.validator=Lt(r);try{let e=r.routeGetStore(),t=r.dependenciesGetStore(),n=r.getOptions();N(e),P(e),Re(e),ze(e),F(t),Ue(n,e,t),r.validator.options.validateOptions(n,`constructor (retrospective)`),typeof n.defaultRoute==`string`&&I(n.defaultRoute,e)}catch(e){throw r.validator=null,e}return{teardown(){r.validator=null}}}}export{Rt as validationPlugin};
2
2
  //# sourceMappingURL=index.mjs.map