@real-router/validation-plugin 0.9.5 → 0.9.7

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){if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function ee(e,t){let n=Array.isArray(e)?e:Object.values(e);for(let e of n)t.push(e)}function te(e){let t=typeof e;return t===`string`||t===`boolean`?!0:t===`number`?Number.isFinite(e):!1}var d=class{container;constructor(e){this.container=e}};function ne(e,t,n,r){return n.has(e)?!1:r.has(e)?!0:u(e)?(n.add(e),t.push(new d(e)),ee(e,t),!0):!1}function re(e){let t=[e],n=new WeakSet,r=new WeakSet;for(;t.length>0;){let e=t.pop();if(e instanceof d){n.delete(e.container),r.add(e.container);continue}if(e!=null){if(typeof e==`object`){if(!ne(e,t,n,r))return!1;continue}if(!te(e))return!1}}return!0}function ie(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`boolean`?!0:t===`number`?Number.isFinite(e):!1}function f(e){try{return ae(e)}catch{return!1}}function ae(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(!ie(r)){let e=typeof r;if(e===`function`||e===`symbol`)return!1;n=!0;break}}return n?re(e):!0}function oe(e){return l(e.name)&&typeof e.path==`string`&&f(e.params)}function p(e){return typeof e!=`object`||!e?!1:oe(e)}function m(e){return typeof e==`string`}function h(e){return typeof e==`boolean`}function se(e,t){return e in t}function g(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 _(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}function v(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}function ce(e,t){if(typeof e!=`string`)throw TypeError(`[router.${t}] dependency name must be a string, got ${typeof e}`)}function le(e){if(typeof e!=`string`)throw TypeError(`[router.setDependency] dependency name must be a string, got ${typeof e}`)}function ue(e,t){if(!(e&&typeof e==`object`&&e.constructor===Object))throw TypeError(`[router.${t}] Invalid argument: expected plain object, received ${_(e)}`);for(let n in e)if(Object.getOwnPropertyDescriptor(e,n)?.get)throw TypeError(`[router.${t}] Getters not allowed: "${n}"`)}function de(e,t){if(e===void 0)throw ReferenceError(`[router.getDependency] dependency "${t}" not found`)}function fe(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}=v(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 pe(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 me(e,t){r.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function he(e,t){r.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function ge(e){r.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const _e=new Set([`$start`,`$stop`,`$$start`,`$$leaveApprove`,`$$cancel`,`$$success`,`$$error`]);function y(e){if(!_e.has(e))throw TypeError(`[router.addEventListener] Invalid event name: ${String(e)}. Must be one of: $start, $stop, $$start, $$leaveApprove, $$cancel, $$success, $$error`)}function ve(e,t){if(y(e),typeof t!=`function`)throw TypeError(`[router.addEventListener] callback must be a function, got ${typeof t}`)}function ye(e,t){if(!h(e)&&typeof e!=`function`)throw TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${_(e)}`)}function be(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 xe(e,t,n){if(n===0)return;let{warn:i,error:a}=v(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 Se(e,t,n){r.warn(`router.${n}`,`Overwriting existing ${t} handler for route "${e}"`)}function Ce(e,t){r.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}function we(e){if(typeof e!=`string`)throw TypeError(`[router.navigate] Invalid route name: expected string, got ${_(e)}`)}function Te(e){if(e!==void 0&&(typeof e!=`object`||!e))throw TypeError(`[router.navigateToDefault] Invalid options: ${_(e)}. Expected NavigationOptions object.`)}function Ee(e){if(typeof e!=`object`||!e)throw TypeError(`[router.navigateToState] Invalid state: ${_(e)}. Expected State object.`);let t=e;if(!m(t.name))throw TypeError(`[router.navigateToState] Invalid state.name: ${_(t.name)}. Expected string.`);if(!f(t.params))throw TypeError(`[router.navigateToState] Invalid state.params: ${_(t.params)}. Expected plain object.`);if(!m(t.path))throw TypeError(`[router.navigateToState] Invalid state.path: ${_(t.path)}. Expected string.`)}function De(e,t){if(!a(e))throw TypeError(`[router.${t}] Invalid options: ${_(e)}. Expected NavigationOptions object.`)}const b=/[\u0000-\u001F\u007F]/;function Oe(e,t){for(let n in e){if(!Object.hasOwn(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`&&b.test(r))throw TypeError(`[router.${t}] param "${n}" must not contain control characters (NUL / C0 / DEL) — they corrupt the URL path.`)}}function ke(e,t){if(e!==void 0&&(typeof e==`object`&&e&&!Array.isArray(e)&&Oe(e,t),!f(e)))throw TypeError(`[router.${t}] params must be a plain object, got ${_(e)}`)}function Ae(e){if(e!==void 0&&typeof e!=`string`)throw TypeError(`[router.start] path must be a string, got ${_(e)}.`);if(typeof e==`string`){if(b.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 x={trailingSlash:[`strict`,`never`,`always`,`preserve`],queryParamsMode:[`default`,`strict`,`loose`],urlParamsEncoding:[`default`,`uri`,`uriComponent`,`none`]},S={arrayFormat:[`none`,`brackets`,`index`,`comma`],booleanFormat:[`none`,`auto`,`empty-true`],nullFormat:[`default`,`hidden`],numberFormat:[`none`,`auto`]},je=new Set([`defaultRoute`,`defaultParams`,`trailingSlash`,`queryParamsMode`,`queryParams`,`urlParamsEncoding`,`allowNotFound`,`rewritePathOnMatch`,`logger`,`limits`]),C={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 w(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=C[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 T(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(C,n))throw TypeError(`[router.${t}] unknown limit: "${n}"`);r!==void 0&&w(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 E(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 Me(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 Ne(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 Pe(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(!se(e,S))throw TypeError(`[router.${t}] Invalid "queryParams.${e}": unknown option`);E(r,`queryParams.${e}`,S[e],t)}}function Fe(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(!je.has(e))throw TypeError(`[router.${t}] Unknown option: "${e}"`);if(Me(n.defaultRoute,t),Ne(n.defaultParams,t),E(n.trailingSlash,`trailingSlash`,x.trailingSlash,t),E(n.queryParamsMode,`queryParamsMode`,x.queryParamsMode,t),E(n.urlParamsEncoding,`urlParamsEncoding`,x.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}`);Pe(n.queryParams,t),n.limits!==void 0&&T(n.limits,t)}const D=`router.usePlugin`,Ie={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function Le(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 Re(e,t){if(t.includes(e))throw Error(`[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.`)}function ze(e,t){if(t===0)return;let{warn:n,error:i}=v(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 Be(e){for(let t in e)if(!(t===`teardown`||Object.hasOwn(Ie,t)))throw TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}function Ve(){r.warn(D,`Duplicate factory in batch, will be registered once`)}function He(e){r.warn(D,`Property '${e}' is not a function, skipping`)}function Ue(e){e===`onStart`&&r.warn(D,`Router already started, onStart will not be called`)}function We(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 Ge(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))Ge(e,t.forwardMap)}function Ke(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 qe(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`,`maxLifecycleHandlers`])if(typeof r[e]!=`number`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits.${e} must be a number, got ${typeof r[e]}`)}function Je(e){let t=e&&typeof e==`object`?e:{};return t.limits&&typeof t.limits==`object`?t.limits:{}}function Ye(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 Xe(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 Ze(e,t,n){let r=Je(e);Ye(t,r),Xe(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}"`)}const 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){return`(${e.replaceAll(/(^<|>$)/g,``)})`}const R=`[^/?<]+`,et=new RegExp(String.raw`([:*])(${R})(<${L}>)?(\?)?`,`g`),tt=new RegExp(String.raw`([:*]${R}(?:<${L}>)?)\?(?=[/?]|$)`,`g`),nt=RegExp(`<${L}>`,`g`),rt=/\?(.+)$/;function it(e){return e.replaceAll(nt,e=>`<${`x`.repeat(e.length-2)}>`).replaceAll(tt,`$1\0`)}const z=Object.freeze([]),at=Object.freeze({}),ot=new Map;function st(e){let t=[],n=[],r=[],i={},a=new Map,o=rt.exec(it(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=et.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=`^${$e(o)}$`;a.set(n,{pattern:new RegExp(e),constraint:o})}}return ct(t,n,r,i,a,e)}function ct(e,t,n,r,i,a){return{urlParams:e.length===0?z:e,queryParams:t.length===0?z:t,spatParams:n.length===0?z:n,paramTypeMap:e.length===0&&t.length===0?at:r,constraintPatterns:i.size===0?ot:i,pathPattern:a}}Object.freeze([]),Object.freeze([]),Object.freeze({}),RegExp(`<${L}>`,`g`),RegExp(`^[:*](${R})`),RegExp(`[:*]${R}`),Object.freeze(new Map),Object.freeze([]);function lt(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 B(e,t){return TypeError(`[router.${e}] ${t}`)}function ut(e,t,n){if(!Qe(e))throw B(n,`Invalid path for route "${t}": unbalanced constraint delimiter ('<' or '>') in "${e}"`);if(e.includes(`<>`))throw B(n,`Invalid path for route "${t}": empty constraint '<>' in "${e}" (a constraint body must be non-empty, e.g. '<[0-9]+>')`)}function dt(e,t,n,r){let i=new Set;for(let a of e){if(i.has(a))throw B(n,`Invalid path for route "${t}": duplicate parameter name ':${a}' in "${r}" (a param name must be unique within a route — the second binding would overwrite the first)`);i.add(a)}}const ft=RegExp(`[:*](?!${R})`);function pt(e){let t=!0,n=!1;for(let r of e)if(r===`/`)t=!0;else if(t)n=r===`:`||r===`*`,t=!1;else if((r===`:`||r===`*`)&&!n)return!0;return!1}function mt(e){for(let t=0;t<e.length;t++){if(e[t]!==`>`)continue;let n=e.charAt(t+1);if(n!==``&&n!==`/`&&n!==`?`)return!0}return!1}function ht(e){let t=!0,n=!1,r=!1;for(let i of e){if(r){r=i!==`>`;continue}if(i===`<`){r=!0;continue}if(i===`/`){t=!0;continue}if(t&&=(n=i===`:`||i===`*`,!1),!n&&i.codePointAt(0)>=128)return!0}return!1}function gt(e){let t=!0,n=!1;for(let r of e)if(r===`/`)t=!0,n=!1;else if(t)n=r===`*`,t=!1;else if(r===`?`&&n)return!0;return!1}function _t(e){for(let t=1;t<e.length;t++)if(e[t]===`?`&&e[t-1]!==`>`&&e[t+1]===`/`&&e[t+2]===`*`)return!0;return!1}function vt(e,t,n,r){if(typeof e!=`string`){let t;throw t=e===null?`null`:Array.isArray(e)?`array`:typeof e,B(n,`Route path must be a string, got ${t}`)}if(e===``)return;if(/\s/.test(e))throw B(n,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw B(n,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes(`//`))throw B(n,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);ut(e,t,n);let{pathPattern:i,urlParams:a}=st(e);if(dt(a,t,n,e),ft.test(i))throw B(n,`Invalid path for route "${t}": parameter marker (':' or '*') without a name in "${e}"`);if(pt(i))throw B(n,`Invalid path for route "${t}": parameter marker (':' or '*') must begin a segment, but "${e}" fuses one to a static prefix (use a boundary marker like "/a/:b")`);if(mt(i))throw B(n,`Invalid path for route "${t}": text fused to a constraint '>' in "${e}" (a '<...>' must end its segment or be followed by '/' or an optional '?' — use "/:id<...>/rest", not "/:id<...>rest")`);if(gt(i))throw B(n,`Invalid path for route "${t}": optional splat ('*name?') is not supported in "${e}" — a splat cannot be optional (use a required splat '*name')`);if(_t(i))throw B(n,`Invalid path for route "${t}": an unconstrained optional param before a splat is not supported in "${e}" — it is ambiguous (every multi-segment value has two readings). Add a constraint (e.g. ':lang<[a-z]+>?') or model it as two routes`);if(ht(i))throw B(n,`Invalid path for route "${t}": non-ASCII static segment in "${e}" — match compares static segments raw and rejects non-ASCII input, so this route would never match. Percent-encode it (e.g. '/caf%C3%A9') or use a param`);let o=r&&r.paramMeta.urlParams.length>0;if(e.startsWith(`~`)&&o)throw B(n,`Absolute path "${e}" cannot be used under parent route with URL parameters`)}const yt=/^[A-Z_a-z][\w-]*$/,bt=/\S/,V=1e4;function H(e){if(e===null)return`null`;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}function xt(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 St(e,t){if(!e||typeof e!=`object`)throw TypeError(`[router.${t}] Route must be an object, got ${H(e)}`);let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw TypeError(`[router.${t}] Route must be a plain object, got ${H(e)}`);if(xt(e))throw TypeError(`[router.${t}] Route must not have getters or setters`)}function Ct(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 wt(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 Tt(e,t){if(typeof e.name!=`string`)throw TypeError(`[router.${t}] Route name must be a string, got ${H(e.name)}`);let n=e.name;if(n===``)throw TypeError(`[router.${t}] Route name cannot be empty`);if(!bt.test(n))throw TypeError(`[router.${t}] Route name cannot contain only whitespace`);if(n.length>V)throw TypeError(`[router.${t}] Route name exceeds maximum length of ${V} 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(!yt.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 U(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 Et(e,t,n){if(U(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 Ot(e,t,n,r){let i=t===``?e:U(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 kt(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 W(e,t,n,r=``,i,a){St(e,t);let o=e;Tt(o,t),vt(o.path,o.name,t,n),Ct(o,t),wt(o,t);let s=o.name,c=r?`${r}.${s}`:s;n&&c&&Et(n,c,t),i&&Dt(i,c,t);let l=o.path,u=r;if(n&&Ot(n,u,l,t),a&&kt(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 ${H(o.children)}`);for(let e of o.children)W(e,t,n,c,i,a)}}function At(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 G(e,t){if(e.canActivate!==void 0&&typeof e.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function for route "${t}", got ${_(e.canActivate)}`);if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${_(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 ${_(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(At(e.forwardTo,t),e.children)for(let n of e.children)G(n,`${t}.${n.name}`)}function jt(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 K(e){let t=new Set;for(let n of e)for(let e of jt(n))t.add(e);return t}function q(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 q(i.children,t,e,a)}throw Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function J(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 J(r.children,e))n.add(t)}return n}function Y(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 Y(r.children,e))n.set(t,i)}return n}function Mt(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 Nt(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 Pt(e,t,n,r){return t?Mt(lt(n,e)??[]):K(q(r,e))}function Ft(e,t,n,r,i){let a=Nt(i,t),o=r.has(t);if(!a&&!o)throw ReferenceError(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);let s=K(q(n,e)),c=[...Pt(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 It(e,n,r){let i=J(e),a=Y(e),o={...n};for(let[e,t]of a)o[e]=t;for(let[t,n]of a)Ft(t,n,e,i,r);for(let e of Object.keys(o))t(e,o)}function X(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 Z(e,t){for(let n of e)n&&typeof n==`object`&&typeof n.name==`string`&&(X(n.name,t),n.children&&Z(n.children,t))}function Lt(e){g(e,`removeRoute`)}function Rt(e){if(typeof e!=`string`)throw TypeError(`[router.setRootPath] rootPath must be a string, got ${_(e)}`)}function Q(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function zt(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function, got ${_(t.canActivate)}`);if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function, got ${_(t.canDeactivate)}`)}function Bt(e){let t=e,n=t.name;if(t.decodeParams!==void 0&&Q(t.decodeParams))throw TypeError(`[router.addRoute] decodeParams cannot be async for route "${String(n)}"`);if(t.encodeParams!==void 0&&Q(t.encodeParams))throw TypeError(`[router.addRoute] encodeParams cannot be async for route "${String(n)}"`);if(typeof t.forwardTo==`function`&&Q(t.forwardTo))throw TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${String(n)}"`)}function Vt(e){for(let t of e){if(typeof t!=`object`||!t||Array.isArray(t))throw TypeError(`[router.addRoute] Route must be an object, got ${_(t)}`);G(t,t.name)}}function Ht(e){if(typeof e!=`string`||e===``)throw TypeError(`[router.addRoute] parent option must be a non-empty string, got ${_(e)}`);g(e,`addRoute`)}function Ut(e,t,n,r){if(!m(e))throw TypeError(`[router.isActiveRoute] name must be a string, got ${typeof e}`);if(t!==void 0&&!f(t))throw TypeError(`[router.isActiveRoute] params must be a plain object, got ${_(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 Wt(e,t,n){if(!m(e))throw TypeError(`[router.${n}] Invalid routeName: ${_(e)}. Expected string.`);if(!f(t))throw TypeError(`[router.${n}] Invalid routeParams: ${_(t)}. Expected plain object.`)}function Gt(e,t){if(g(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 ${_(t)}`)}function Kt(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}`);Kt(e,t)}}function qt(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 ${_(e)}`);typeof e==`function`&&Kt(e,`forwardTo callback`)}if(t!=null&&(typeof t!=`object`||Array.isArray(t)))throw TypeError(`[router.updateRoute] defaultParams must be an object or null, got ${_(t)}`);$(n,`decodeParams`),$(r,`encodeParams`)}function Jt(e){if(!m(e)||e===``)throw TypeError(`[router.buildPath] route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`)}function Yt(e){if(!m(e))throw TypeError(`[router.matchPath] path must be a string, got ${typeof e}`)}function Xt(e){if(!m(e))throw TypeError(`[router.shouldUpdateNode] nodeName must be a string, got ${typeof e}`)}function Zt(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)W(n,`addRoute`,t,r??``,i,a);t&&n&&It(e,n,t)}function Qt(e){let t=new Set;for(let n of e)for(let e of n.paramMeta.urlParams)t.add(e);return t}function $t(e,t,n){let r=n.getSegmentsByName(e),i=n.getSegmentsByName(t),a=Qt(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 en(e,n,r){t(e,{...r.forwardMap,[e]:n})}function tn(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`);$t(e,t,r),en(e,t,i)}}function nn(e,t,n){if(!m(e))throw TypeError(`[router.makeState] Invalid name: ${_(e)}. Expected string.`);if(t!==void 0&&!f(t))throw TypeError(`[router.makeState] Invalid params: ${_(t)}. Expected plain object.`);if(n!==void 0&&!m(n))throw TypeError(`[router.makeState] Invalid path: ${_(n)}. Expected string.`)}function rn(e){return{routes:{validateBuildPathArgs:Jt,validateMatchPathArgs:Yt,validateIsActiveRouteArgs:Ut,validateShouldUpdateNodeArgs:Xt,validateStateBuilderArgs:Wt,validateAddRouteArgs(e){Vt(e)},validateRoutes(e,t){let n=t;Zt(e,n.tree,n.config?.forwardMap)},validateRemoveRouteArgs:Lt,validateUpdateRouteBasicArgs:Gt,validateUpdateRoutePropertyTypes(e,t){let n=t;qt(n.forwardTo,n.defaultParams,n.decodeParams,n.encodeParams)},validateUpdateRoute(e,t,n){let r=n,i=t.forwardTo;tn(e,i,e=>r.matcher.hasRoute(e),r.matcher,r.config)},validateParentOption(e,t){Ht(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){g(e,t)},throwIfInternalRoute(e,t){X(e,t)},throwIfInternalRouteInArray(e,t){Z(e,t)},validateExistingRoutes:N,validateForwardToConsistency:P,validateSetRootPathArgs:Rt,guardRouteCallbacks:zt,guardNoAsyncCallbacks:Bt},options:{validateLimitValue(e,t){w(e,t,`validate`)},validateLimits(e){T(e,`validate`)},validateOptions:Fe,validateResolvedDefaultRoute:I},dependencies:{validateDependencyName:ce,validateSetDependencyArgs(e,t,n){le(e)},validateDependenciesObject:ue,validateDependencyExists(e,t){let n=t.dependencies?.[e];de(n,e)},validateDependencyLimit(e,t){},validateDependenciesStructure:F,validateDependencyCount:fe,validateCloneArgs:pe,warnOverwrite:me,warnBatchOverwrite:he,warnRemoveNonExistent:ge},plugins:{validatePluginLimit(e,t){Le(e,1,t?.maxPlugins)},validateNoDuplicatePlugins:Re,validatePluginKeys:Be,validateCountThresholds(t){ze(t,e.getOptions().limits?.maxPlugins??50)},warnBatchDuplicates:Ve,warnPluginMethodType:He,warnPluginAfterStart:Ue,validateAddInterceptorArgs:We},lifecycle:{validateHandler:ye,validateHandlerLimit(t,n){be(t,n,e.getOptions().limits?.maxLifecycleHandlers??200)},validateCountThresholds(t,n){xe(t,n,e.getOptions().limits?.maxLifecycleHandlers??200)},warnOverwrite:Se,warnAsyncGuardSync:Ce},navigation:{validateNavigateArgs:we,validateNavigateToDefaultArgs:Te,validateNavigateToStateArgs:Ee,validateNavigationOptions:De,validateParams:ke,validateStartArgs:Ae},state:{validateMakeStateArgs:nn,validateAreStatesEqualArgs(e,t,n){if(!p(e))throw TypeError(`[router.areStatesEqual] Invalid state1: ${_(e)}. Expected State object.`);if(!p(t))throw TypeError(`[router.areStatesEqual] Invalid state2: ${_(t)}. Expected State object.`);if(n!==void 0&&!h(n))throw TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${_(n)}. Expected boolean.`)}},eventBus:{validateEventName:y,validateListenerArgs(e,t){ve(e,t)}}}}function an(){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=rn(r);try{let e=r.routeGetStore(),t=r.dependenciesGetStore(),n=r.getOptions();N(e),P(e),Ke(e),qe(e),F(t),Ze(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{an 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){if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function ee(e,t){let n=Array.isArray(e)?e:Object.values(e);for(let e of n)t.push(e)}function te(e){let t=typeof e;return t===`string`||t===`boolean`?!0:t===`number`?Number.isFinite(e):!1}var d=class{container;constructor(e){this.container=e}};function ne(e,t,n,r){return n.has(e)?!1:r.has(e)?!0:u(e)?(n.add(e),t.push(new d(e)),ee(e,t),!0):!1}function re(e){let t=[e],n=new WeakSet,r=new WeakSet;for(;t.length>0;){let e=t.pop();if(e instanceof d){n.delete(e.container),r.add(e.container);continue}if(e!=null){if(typeof e==`object`){if(!ne(e,t,n,r))return!1;continue}if(!te(e))return!1}}return!0}function ie(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`boolean`?!0:t===`number`?Number.isFinite(e):!1}function f(e){try{return ae(e)}catch{return!1}}function ae(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(!ie(r)){let e=typeof r;if(e===`function`||e===`symbol`)return!1;n=!0;break}}return n?re(e):!0}function oe(e){return l(e.name)&&typeof e.path==`string`&&f(e.params)}function p(e){return typeof e!=`object`||!e?!1:oe(e)}function m(e){return typeof e==`string`}function h(e){return typeof e==`boolean`}function se(e,t){return e in t}function g(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 _(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}function v(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}function ce(e,t){if(typeof e!=`string`)throw TypeError(`[router.${t}] dependency name must be a string, got ${typeof e}`)}function le(e){if(typeof e!=`string`)throw TypeError(`[router.setDependency] dependency name must be a string, got ${typeof e}`)}function ue(e,t){if(!(e&&typeof e==`object`&&e.constructor===Object))throw TypeError(`[router.${t}] Invalid argument: expected plain object, received ${_(e)}`);for(let n in e)if(Object.getOwnPropertyDescriptor(e,n)?.get)throw TypeError(`[router.${t}] Getters not allowed: "${n}"`)}function de(e,t){if(e===void 0)throw ReferenceError(`[router.getDependency] dependency "${t}" not found`)}function fe(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}=v(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 pe(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 me(e,t){r.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function he(e,t){r.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function ge(e){r.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const _e=new Set([`$start`,`$stop`,`$$start`,`$$leaveApprove`,`$$cancel`,`$$success`,`$$error`]);function y(e){if(!_e.has(e))throw TypeError(`[router.addEventListener] Invalid event name: ${String(e)}. Must be one of: $start, $stop, $$start, $$leaveApprove, $$cancel, $$success, $$error`)}function ve(e,t){if(y(e),typeof t!=`function`)throw TypeError(`[router.addEventListener] callback must be a function, got ${typeof t}`)}function ye(e,t){if(!h(e)&&typeof e!=`function`)throw TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${_(e)}`)}function be(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 xe(e,t,n){if(n===0)return;let{warn:i,error:a}=v(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 Se(e,t,n){r.warn(`router.${n}`,`Overwriting existing ${t} handler for route "${e}"`)}function Ce(e,t){r.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}function we(e){if(typeof e!=`string`)throw TypeError(`[router.navigate] Invalid route name: expected string, got ${_(e)}`)}function Te(e){if(e!==void 0&&(typeof e!=`object`||!e))throw TypeError(`[router.navigateToDefault] Invalid options: ${_(e)}. Expected NavigationOptions object.`)}function Ee(e){if(typeof e!=`object`||!e)throw TypeError(`[router.navigateToState] Invalid state: ${_(e)}. Expected State object.`);let t=e;if(!m(t.name))throw TypeError(`[router.navigateToState] Invalid state.name: ${_(t.name)}. Expected string.`);if(!f(t.params))throw TypeError(`[router.navigateToState] Invalid state.params: ${_(t.params)}. Expected plain object.`);if(!m(t.path))throw TypeError(`[router.navigateToState] Invalid state.path: ${_(t.path)}. Expected string.`)}function De(e,t){if(!a(e))throw TypeError(`[router.${t}] Invalid options: ${_(e)}. Expected NavigationOptions object.`)}const b=/[\u0000-\u001F\u007F]/;function Oe(e,t){for(let n in e){if(!Object.hasOwn(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`&&b.test(r))throw TypeError(`[router.${t}] param "${n}" must not contain control characters (NUL / C0 / DEL) — they corrupt the URL path.`)}}function ke(e,t){if(e!==void 0&&(typeof e==`object`&&e&&!Array.isArray(e)&&Oe(e,t),!f(e)))throw TypeError(`[router.${t}] params must be a plain object, got ${_(e)}`)}function Ae(e){if(e!==void 0&&typeof e!=`string`)throw TypeError(`[router.start] path must be a string, got ${_(e)}.`);if(typeof e==`string`){if(b.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 x={trailingSlash:[`strict`,`never`,`always`,`preserve`],queryParamsMode:[`default`,`strict`,`loose`],urlParamsEncoding:[`default`,`uri`,`uriComponent`,`none`]},S={arrayFormat:[`none`,`brackets`,`index`,`comma`],booleanFormat:[`none`,`auto`,`empty-true`],nullFormat:[`default`,`hidden`],numberFormat:[`none`,`auto`]},je=new Set([`defaultRoute`,`defaultParams`,`trailingSlash`,`queryParamsMode`,`queryParams`,`urlParamsEncoding`,`allowNotFound`,`rewritePathOnMatch`,`logger`,`limits`]),C={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 w(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=C[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 T(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(C,n))throw TypeError(`[router.${t}] unknown limit: "${n}"`);r!==void 0&&w(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 E(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 Me(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 Ne(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 Pe(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(!se(e,S))throw TypeError(`[router.${t}] Invalid "queryParams.${e}": unknown option`);E(r,`queryParams.${e}`,S[e],t)}}function Fe(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(!je.has(e))throw TypeError(`[router.${t}] Unknown option: "${e}"`);if(Me(n.defaultRoute,t),Ne(n.defaultParams,t),E(n.trailingSlash,`trailingSlash`,x.trailingSlash,t),E(n.queryParamsMode,`queryParamsMode`,x.queryParamsMode,t),E(n.urlParamsEncoding,`urlParamsEncoding`,x.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}`);Pe(n.queryParams,t),n.limits!==void 0&&T(n.limits,t)}const D=`router.usePlugin`,Ie={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function Le(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 Re(e,t){if(t.includes(e))throw Error(`[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.`)}function ze(e,t){if(t===0)return;let{warn:n,error:i}=v(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 Be(e){for(let t in e)if(!(t===`teardown`||Object.hasOwn(Ie,t)))throw TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}function Ve(){r.warn(D,`Duplicate factory in batch, will be registered once`)}function He(e){r.warn(D,`Property '${e}' is not a function, skipping`)}function Ue(e){e===`onStart`&&r.warn(D,`Router already started, onStart will not be called`)}function We(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 Ge(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))Ge(e,t.forwardMap)}function Ke(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 qe(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`,`maxLifecycleHandlers`])if(typeof r[e]!=`number`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits.${e} must be a number, got ${typeof r[e]}`)}function Je(e){let t=e&&typeof e==`object`?e:{};return t.limits&&typeof t.limits==`object`?t.limits:{}}function Ye(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 Xe(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 Ze(e,t,n){let r=Je(e);Ye(t,r),Xe(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}"`)}const 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){return`(${e.replaceAll(/(^<|>$)/g,``)})`}const R=`[^/?<]+`,et=new RegExp(String.raw`([:*])(${R})(<${L}>)?(\?)?`,`g`),tt=new RegExp(String.raw`([:*]${R}(?:<${L}>)?)\?(?=[/?]|$)`,`g`),nt=RegExp(`<${L}>`,`g`),rt=/\?(.+)$/;function it(e){return e.replaceAll(nt,e=>`<${`x`.repeat(e.length-2)}>`).replaceAll(tt,`$1\0`)}const z=Object.freeze([]),at=Object.freeze({}),ot=new Map;function st(e){let t=[],n=[],r=[],i={},a=new Map,o=rt.exec(it(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=et.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=`^${$e(o)}$`;a.set(n,{pattern:new RegExp(e),constraint:o})}}return ct(t,n,r,i,a,e)}function ct(e,t,n,r,i,a){return{urlParams:e.length===0?z:e,queryParams:t.length===0?z:t,spatParams:n.length===0?z:n,paramTypeMap:e.length===0&&t.length===0?at:r,constraintPatterns:i.size===0?ot:i,pathPattern:a}}Object.freeze([]),Object.freeze(new Set),Object.freeze(new Map),Object.freeze([]),Object.freeze({}),RegExp(`<${L}>`,`g`),RegExp(`^[:*](${R})`),RegExp(`[:*]${R}`),Object.freeze(new Map),Object.freeze([]);function lt(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 B(e,t){return TypeError(`[router.${e}] ${t}`)}function ut(e,t,n){if(!Qe(e))throw B(n,`Invalid path for route "${t}": unbalanced constraint delimiter ('<' or '>') in "${e}"`);if(e.includes(`<>`))throw B(n,`Invalid path for route "${t}": empty constraint '<>' in "${e}" (a constraint body must be non-empty, e.g. '<[0-9]+>')`)}function dt(e,t,n,r){let i=new Set;for(let a of e){if(i.has(a))throw B(n,`Invalid path for route "${t}": duplicate parameter name ':${a}' in "${r}" (a param name must be unique within a route — the second binding would overwrite the first)`);i.add(a)}}const ft=/[<>]/u;function pt(e,t,n,r,i){let a=new Set(e);for(let e of t){if(ft.test(e))throw B(r,`Invalid path for route "${n}": invalid query-param name "${e}" in "${i}" (a query-param name cannot contain '<' or '>' — a reverse-order modifier typo that leaked a constraint into the query; put the optional '?' after the constraint, ':id<...>?')`);if(a.has(e))throw B(r,`Invalid path for route "${n}": "${e}" is declared as both a path param and a query param in "${i}" — buildPath would emit its value twice (rename one)`)}}const mt=RegExp(`[:*](?!${R})`);function ht(e){let t=!0,n=!1;for(let r of e)if(r===`/`)t=!0;else if(t)n=r===`:`||r===`*`,t=!1;else if((r===`:`||r===`*`)&&!n)return!0;return!1}function gt(e){for(let t=0;t<e.length;t++){if(e[t]!==`>`)continue;let n=e.charAt(t+1);if(n!==``&&n!==`/`&&n!==`?`)return!0}return!1}function _t(e){let t=!0,n=!1,r=!1;for(let i of e){if(r){r=i!==`>`;continue}if(i===`<`){r=!0;continue}if(i===`/`){t=!0;continue}if(t&&=(n=i===`:`||i===`*`,!1),!n&&i.codePointAt(0)>=128)return!0}return!1}function vt(e){let t=!0,n=!1;for(let r of e)if(r===`/`)t=!0,n=!1;else if(t)n=r===`*`,t=!1;else if(r===`?`&&n)return!0;return!1}function yt(e){for(let t=1;t<e.length;t++)if(e[t]===`?`&&e[t-1]!==`>`&&e[t+1]===`/`&&e[t+2]===`*`)return!0;return!1}function bt(e,t,n,r){if(typeof e!=`string`){let t;throw t=e===null?`null`:Array.isArray(e)?`array`:typeof e,B(n,`Route path must be a string, got ${t}`)}if(e===``)return;if(/\s/.test(e))throw B(n,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw B(n,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes(`//`))throw B(n,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);ut(e,t,n);let{pathPattern:i,urlParams:a,queryParams:o}=st(e);if(dt(a,t,n,e),pt(a,o,t,n,e),mt.test(i))throw B(n,`Invalid path for route "${t}": parameter marker (':' or '*') without a name in "${e}"`);if(ht(i))throw B(n,`Invalid path for route "${t}": parameter marker (':' or '*') must begin a segment, but "${e}" fuses one to a static prefix (use a boundary marker like "/a/:b")`);if(gt(i))throw B(n,`Invalid path for route "${t}": text fused to a constraint '>' in "${e}" (a '<...>' must end its segment or be followed by '/' or an optional '?' — use "/:id<...>/rest", not "/:id<...>rest")`);if(vt(i))throw B(n,`Invalid path for route "${t}": optional splat ('*name?') is not supported in "${e}" — a splat cannot be optional (use a required splat '*name')`);if(yt(i))throw B(n,`Invalid path for route "${t}": an unconstrained optional param before a splat is not supported in "${e}" — it is ambiguous (every multi-segment value has two readings). Add a constraint (e.g. ':lang<[a-z]+>?') or model it as two routes`);if(_t(i))throw B(n,`Invalid path for route "${t}": non-ASCII static segment in "${e}" — match compares static segments raw and rejects non-ASCII input, so this route would never match. Percent-encode it (e.g. '/caf%C3%A9') or use a param`);let s=r&&r.paramMeta.urlParams.length>0;if(e.startsWith(`~`)&&s)throw B(n,`Absolute path "${e}" cannot be used under parent route with URL parameters`)}const xt=/^[A-Z_a-z][\w-]*$/,St=/\S/,V=1e4;function H(e){if(e===null)return`null`;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}function Ct(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 wt(e,t){if(!e||typeof e!=`object`)throw TypeError(`[router.${t}] Route must be an object, got ${H(e)}`);let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw TypeError(`[router.${t}] Route must be a plain object, got ${H(e)}`);if(Ct(e))throw TypeError(`[router.${t}] Route must not have getters or setters`)}function Tt(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 Et(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 Dt(e,t){if(typeof e.name!=`string`)throw TypeError(`[router.${t}] Route name must be a string, got ${H(e.name)}`);let n=e.name;if(n===``)throw TypeError(`[router.${t}] Route name cannot be empty`);if(!St.test(n))throw TypeError(`[router.${t}] Route name cannot contain only whitespace`);if(n.length>V)throw TypeError(`[router.${t}] Route name exceeds maximum length of ${V} 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(!xt.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 U(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 Ot(e,t,n){if(U(e,t))throw Error(`[router.${n}] Route "${t}" already exists`)}function kt(e,t,n){if(e.has(t))throw Error(`[router.${n}] Duplicate route "${t}" in batch`);e.add(t)}function At(e,t,n,r){let i=t===``?e:U(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 jt(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 W(e,t,n,r=``,i,a){wt(e,t);let o=e;Dt(o,t),bt(o.path,o.name,t,n),Tt(o,t),Et(o,t);let s=o.name,c=r?`${r}.${s}`:s;n&&c&&Ot(n,c,t),i&&kt(i,c,t);let l=o.path,u=r;if(n&&At(n,u,l,t),a&&jt(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 ${H(o.children)}`);for(let e of o.children)W(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 G(e,t){if(e.canActivate!==void 0&&typeof e.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function for route "${t}", got ${_(e.canActivate)}`);if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${_(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 ${_(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)G(n,`${t}.${n.name}`)}function Nt(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 K(e){let t=new Set;for(let n of e)for(let e of Nt(n))t.add(e);return t}function q(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 q(i.children,t,e,a)}throw Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function J(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 J(r.children,e))n.add(t)}return n}function Y(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 Y(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 Ft(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 It(e,t,n,r){return t?Pt(lt(n,e)??[]):K(q(r,e))}function Lt(e,t,n,r,i){let a=Ft(i,t),o=r.has(t);if(!a&&!o)throw ReferenceError(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);let s=K(q(n,e)),c=[...It(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 Rt(e,n,r){let i=J(e),a=Y(e),o={...n};for(let[e,t]of a)o[e]=t;for(let[t,n]of a)Lt(t,n,e,i,r);for(let e of Object.keys(o))t(e,o)}function X(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 Z(e,t){for(let n of e)n&&typeof n==`object`&&typeof n.name==`string`&&(X(n.name,t),n.children&&Z(n.children,t))}function zt(e){g(e,`removeRoute`)}function Bt(e){if(typeof e!=`string`)throw TypeError(`[router.setRootPath] rootPath must be a string, got ${_(e)}`)}function Q(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function Vt(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function, got ${_(t.canActivate)}`);if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function, got ${_(t.canDeactivate)}`)}function Ht(e){let t=e,n=t.name;if(t.decodeParams!==void 0&&Q(t.decodeParams))throw TypeError(`[router.addRoute] decodeParams cannot be async for route "${String(n)}"`);if(t.encodeParams!==void 0&&Q(t.encodeParams))throw TypeError(`[router.addRoute] encodeParams cannot be async for route "${String(n)}"`);if(typeof t.forwardTo==`function`&&Q(t.forwardTo))throw TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${String(n)}"`)}function Ut(e){for(let t of e){if(typeof t!=`object`||!t||Array.isArray(t))throw TypeError(`[router.addRoute] Route must be an object, got ${_(t)}`);G(t,t.name)}}function Wt(e){if(typeof e!=`string`||e===``)throw TypeError(`[router.addRoute] parent option must be a non-empty string, got ${_(e)}`);g(e,`addRoute`)}function Gt(e,t,n,r){if(!m(e))throw TypeError(`[router.isActiveRoute] name must be a string, got ${typeof e}`);if(t!==void 0&&!f(t))throw TypeError(`[router.isActiveRoute] params must be a plain object, got ${_(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 Kt(e,t,n){if(!m(e))throw TypeError(`[router.${n}] Invalid routeName: ${_(e)}. Expected string.`);if(!f(t))throw TypeError(`[router.${n}] Invalid routeParams: ${_(t)}. Expected plain object.`)}function qt(e,t){if(g(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 ${_(t)}`)}function Jt(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}`);Jt(e,t)}}function Yt(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 ${_(e)}`);typeof e==`function`&&Jt(e,`forwardTo callback`)}if(t!=null&&(typeof t!=`object`||Array.isArray(t)))throw TypeError(`[router.updateRoute] defaultParams must be an object or null, got ${_(t)}`);$(n,`decodeParams`),$(r,`encodeParams`)}function Xt(e){if(!m(e)||e===``)throw TypeError(`[router.buildPath] route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`)}function Zt(e){if(!m(e))throw TypeError(`[router.matchPath] path must be a string, got ${typeof e}`)}function Qt(e){if(!m(e))throw TypeError(`[router.shouldUpdateNode] nodeName must be a string, got ${typeof e}`)}function $t(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)W(n,`addRoute`,t,r??``,i,a);t&&n&&Rt(e,n,t)}function en(e){let t=new Set;for(let n of e)for(let e of n.paramMeta.urlParams)t.add(e);return t}function tn(e,t,n){let r=n.getSegmentsByName(e),i=n.getSegmentsByName(t),a=en(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 nn(e,n,r){t(e,{...r.forwardMap,[e]:n})}function rn(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`);tn(e,t,r),nn(e,t,i)}}function an(e,t,n){if(!m(e))throw TypeError(`[router.makeState] Invalid name: ${_(e)}. Expected string.`);if(t!==void 0&&!f(t))throw TypeError(`[router.makeState] Invalid params: ${_(t)}. Expected plain object.`);if(n!==void 0&&!m(n))throw TypeError(`[router.makeState] Invalid path: ${_(n)}. Expected string.`)}function on(e){return{routes:{validateBuildPathArgs:Xt,validateMatchPathArgs:Zt,validateIsActiveRouteArgs:Gt,validateShouldUpdateNodeArgs:Qt,validateStateBuilderArgs:Kt,validateAddRouteArgs(e){Ut(e)},validateRoutes(e,t){let n=t;$t(e,n.tree,n.config?.forwardMap)},validateRemoveRouteArgs:zt,validateUpdateRouteBasicArgs:qt,validateUpdateRoutePropertyTypes(e,t){let n=t;Yt(n.forwardTo,n.defaultParams,n.decodeParams,n.encodeParams)},validateUpdateRoute(e,t,n){let r=n,i=t.forwardTo;rn(e,i,e=>r.matcher.hasRoute(e),r.matcher,r.config)},validateParentOption(e,t){Wt(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){g(e,t)},throwIfInternalRoute(e,t){X(e,t)},throwIfInternalRouteInArray(e,t){Z(e,t)},validateExistingRoutes:N,validateForwardToConsistency:P,validateSetRootPathArgs:Bt,guardRouteCallbacks:Vt,guardNoAsyncCallbacks:Ht},options:{validateLimitValue(e,t){w(e,t,`validate`)},validateLimits(e){T(e,`validate`)},validateOptions:Fe,validateResolvedDefaultRoute:I},dependencies:{validateDependencyName:ce,validateSetDependencyArgs(e,t,n){le(e)},validateDependenciesObject:ue,validateDependencyExists(e,t){let n=t.dependencies?.[e];de(n,e)},validateDependencyLimit(e,t){},validateDependenciesStructure:F,validateDependencyCount:fe,validateCloneArgs:pe,warnOverwrite:me,warnBatchOverwrite:he,warnRemoveNonExistent:ge},plugins:{validatePluginLimit(e,t){Le(e,1,t?.maxPlugins)},validateNoDuplicatePlugins:Re,validatePluginKeys:Be,validateCountThresholds(t){ze(t,e.getOptions().limits?.maxPlugins??50)},warnBatchDuplicates:Ve,warnPluginMethodType:He,warnPluginAfterStart:Ue,validateAddInterceptorArgs:We},lifecycle:{validateHandler:ye,validateHandlerLimit(t,n){be(t,n,e.getOptions().limits?.maxLifecycleHandlers??200)},validateCountThresholds(t,n){xe(t,n,e.getOptions().limits?.maxLifecycleHandlers??200)},warnOverwrite:Se,warnAsyncGuardSync:Ce},navigation:{validateNavigateArgs:we,validateNavigateToDefaultArgs:Te,validateNavigateToStateArgs:Ee,validateNavigationOptions:De,validateParams:ke,validateStartArgs:Ae},state:{validateMakeStateArgs:an,validateAreStatesEqualArgs(e,t,n){if(!p(e))throw TypeError(`[router.areStatesEqual] Invalid state1: ${_(e)}. Expected State object.`);if(!p(t))throw TypeError(`[router.areStatesEqual] Invalid state2: ${_(t)}. Expected State object.`);if(n!==void 0&&!h(n))throw TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${_(n)}. Expected boolean.`)}},eventBus:{validateEventName:y,validateListenerArgs(e,t){ve(e,t)}}}}function sn(){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=on(r);try{let e=r.routeGetStore(),t=r.dependenciesGetStore(),n=r.getOptions();N(e),P(e),Ke(e),qe(e),F(t),Ze(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{sn as validationPlugin};
2
2
  //# sourceMappingURL=index.mjs.map