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