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