@real-router/validation-plugin 0.33.1 → 0.33.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@real-router/core/api"),t=require("@real-router/core/utils"),n=require("@real-router/core/validation"),r=require("@real-router/core");const i=Object.freeze({maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxLifecycleHandlers:200});function a(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}function o(e){return typeof e==`string`}function s(e){return typeof e==`boolean`}function c(e,t){return e in t}const l=Object.getPrototypeOf,u=Object.values,ee=Object.hasOwn,te=Date,ne=Date.prototype.getTime;function re(e){if(Array.isArray(e))return!0;let t=l(e);return t===null||t===Object.prototype}function ie(e,t){let n=Array.isArray(e)?e:u(e);for(let e of n)t.push(e)}function d(e){let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}var f=class{container;constructor(e){this.container=e}};function p(e,t,n,r){return n.has(e)?!1:r.has(e)?!0:re(e)?(n.add(e),t.push(new f(e)),ie(e,t),!0):e instanceof te&&(ne.call(e),!0)}function ae(e){let t=[e],n=new WeakSet,r=new WeakSet;for(;t.length>0;){let e=t.pop();if(e instanceof f)n.delete(e.container),r.add(e.container);else if(e!=null){if(typeof e==`object`){if(!p(e,t,n,r))return!1}else if(!d(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 m(e){try{return se(e)}catch{return!1}}function se(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=l(e);if(t!==null&&t!==Object.prototype)return!1;let n=!1;for(let t in e){if(!ee(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/,h=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function g(e,n){return(0,t.raiser)(`router`,e).type`${n}`}function de(e){return typeof e==`string`?e===``?!0:e.length>1e4?!1:e.startsWith(`@@`)?!0:h.test(e):!1}function fe(e){return de(e.name)&&typeof e.path==`string`&&m(e.params)}function _(e){return typeof e!=`object`||!e?!1:fe(e)}function v(e,t){if(typeof e!=`string`)throw g(t,`Route name must be a string, got ${typeof e}`);if(e!==``){if(!ue.test(e))throw g(t,`Route name cannot contain only whitespace`);if(e.length>1e4)throw g(t,`Route name exceeds maximum length of 10000 characters. This is a technical safety limit.`);if(!e.startsWith(`@@`)&&!h.test(e))throw g(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 y(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 pe=Object.entries,me=[`defaultParams`,`defaultSearch`],he=e=>new Map(pe(e)),ge=(e,t)=>{let n=pe(e);return n.length!==t.size||n.some(([e,n])=>!t.has(e)||!Object.is(t.get(e),n))};var _e=class{#e=new Map;#t=new Set;watch(e){for(let t of me){let n=e[t],r=n?.deref();n!==void 0&&r!==void 0&&this.#e.set(t,{ref:n,before:he(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&&ge(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 b=(0,t.raiser)(`cloneRouter`),ve=(0,t.raiser)(`router`,`getDependency`),ye=(0,t.raiser)(`router`,`setDependency`),x=Object.keys,be=Object.getOwnPropertyDescriptor,xe=Object.getPrototypeOf,Se=Object;function Ce(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=xe(e);return t===null||t.constructor===Se}function we(e,n){if(typeof e!=`string`)throw(0,t.raiser)(`router`,n).type`dependency name must be a string, got ${typeof e}`}function Te(e){if(typeof e!=`string`)throw ye.type`dependency name must be a string, got ${typeof e}`}function Ee(e,n){if(!Ce(e))throw(0,t.raiser)(`router`,n).type`Invalid argument: expected plain object, received ${y(e)}`;for(let r of x(e))if(be(e,r)?.get)throw(0,t.raiser)(`router`,n).type`Getters not allowed: "${r}"`}function De(e,n,r,i){if(r===0)return;let a=new Set(n),o=0;for(let t of x(e))a.has(t)||(o+=1);let s=n.length;if(s+o>r)throw(0,t.raiser)(`router`,i).range`Dependency limit exceeded (${r}). Current: ${s}, this batch adds ${o}.`}function Oe(e,t){if(e===void 0)throw ve.ref`dependency "${t}" not found`}function ke(e,n,r,i){if(n===0)return;let{warn:o,error:s}=a(n);if(e>=n)throw(0,t.raiser)(`router`,r).range`Dependency limit exceeded (${n}). Current: ${e}.`;e===s?i.error(`router.${r}`,`${e} dependencies registered! This indicates architectural problems. Hard limit at ${n}.`):e===o&&i.warn(`router.${r}`,`${e} dependencies registered. Consider if all are necessary.`)}function Ae(e){if(e!==void 0){if(!Ce(e))throw b.type`Invalid dependencies: expected plain object or undefined, received ${typeof e}`;for(let t of x(e))if(be(e,t)?.get)throw b.type`Getters not allowed in dependencies: "${t}"`}}function je(e,t,n){n.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function Me(e,t,n){n.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function Ne(e,t){t.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const S=(0,t.raiser)(`router`,`addEventListener`),Pe=Object.values,Fe=new Set(Pe(r.events));function Ie(e){if(!Fe.has(e))throw S.type`Invalid event name: ${String(e)}. Must be one of: $start, $stop, $$start, $$leaveApprove, $$cancel, $$success, $$error`}function Le(e,t){if(Ie(e),typeof t!=`function`)throw S.type`callback must be a function, got ${typeof t}`}function Re(e,t,n,r,o=i.maxListeners){if(o===0)return;let{warn:s,error:c}=a(o);e>=c?r.error(`router.${n}`,`${e} listeners registered for "${t}"! This is excessive. Hard limit at ${o}.`):e>=s&&r.warn(`router.${n}`,`${e} listeners registered for "${t}". Consider whether all are necessary — a growing count usually means a missing unsubscribe.`)}const C=(0,t.raiser)(`router`,`addRoute`),ze=Object.keys;function w(e,t){return typeof e==`string`&&e!==``&&typeof t==`string`?`${e}.${t}`:t}function Be(e,t){if(e!==void 0){if(typeof e!=`string`&&typeof e!=`function`)throw C.type`forwardTo must be a string or function for route "${t}", got ${y(e)}`;if(typeof e==`function`){let n=e.constructor.name===`AsyncFunction`,r=e.toString().includes(`__awaiter`);if(n||r)throw C.type`forwardTo callback cannot be async for route "${t}". Async functions break matchPath/buildPath.`}}}function T(e,t,n){if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))throw C.type`${t} must be an object for route "${n}", got ${y(e)}`}function E(e,t){if(e.canActivate!==void 0&&typeof e.canActivate!=`function`)throw C.type`canActivate must be a function for route "${t}", got ${y(e.canActivate)}`;if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw C.type`canDeactivate must be a function for route "${t}", got ${y(e.canDeactivate)}`;T(e.defaultParams,`defaultParams`,t),T(e.defaultSearch,`defaultSearch`,t);let{decodeParams:n,encodeParams:r}=e;if(typeof n==`function`&&n.constructor.name===`AsyncFunction`)throw C.type`decodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`;if(typeof r==`function`&&r.constructor.name===`AsyncFunction`)throw C.type`encodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`;if(Be(e.forwardTo,t),e.children)for(let n of e.children)E(n,w(t,n.name))}function D(e){let t=new Set;for(let r of e)for(let e of(0,n.buildParamMeta)(r).urlParams)t.add(e);return t}function O(e,n,r=``,i=[]){for(let t of e){let e=r?`${r}.${t.name}`:t.name,a=[...i,t.path];if(e===n)return a;if(t.children&&n.startsWith(`${e}.`))return O(t.children,n,e,a)}throw t.internalDefect.plain`collectPathsToRoute: route "${n}" not found`}function Ve(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 Ve(r.children,e))n.add(t)}return n}function He(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 He(r.children,e))n.set(t,i)}return n}function Ue(e,t,n,r){return t?new Set(n.getUrlParams(e)):D(r(e))}const We=new Set;function Ge(e,t,n,r,i,a){let o=i.hasRoute(t),s=r.has(t);if(!o&&!s)throw C.ref`forwardTo target "${t}" does not exist for route "${e}"`;let c=new Set([...a,...D(n(e))]),l=[...Ue(t,o,i,n)].filter(e=>!c.has(e));if(l.length>0)throw C.plain`forwardTo target "${t}" requires params [${l.join(`, `)}] that are not available in source route "${e}"`}function Ke(e,n,i,a){let o=Ve(e,a),s=t=>O(e,a?t.slice(a.length+1):t),c=a?new Set(i.getUrlParams(a)):We,l=He(e,a),u={...n};for(let[e,n]of l)(0,t.putField)(u,e,n);for(let[e,t]of l)Ge(e,t,s,o,i,c);for(let e of ze(u))(0,r.resolveForwardChain)(e,u)}function qe(e,n){if(!s(e)&&typeof e!=`function`)throw(0,t.raiser)(`router`,n).type`Handler must be a boolean or factory function, got ${y(e)}`}function Je(e,n,r=i.maxLifecycleHandlers){if(r!==0&&e>=r)throw(0,t.raiser)(`router`,n).range`Lifecycle handler limit exceeded (${r}). This indicates too many routes with individual handlers. Consider using plugins for cross-cutting concerns.`}function Ye(e,t,n,r){if(n===0)return;let{warn:i,error:o}=a(n);e>=o?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 Xe(e,t,n,r){r.warn(`router.${n}`,`Overwriting existing ${t} handler for route "${e}"`)}function Ze(e,t,n){n.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}function Qe(e,t){return`Guard for "${e}" must answer true or false, got ${y(t)} — read as a refusal.`}function $e(e,t,n,r){r.warn(`router.${n}`,Qe(e,t))}function et(e,t,n){n.warn(`router`,Qe(e,t))}const k=(0,t.raiser)(`router`,`start`),A=(0,t.raiser)(`router`,`navigateToState`),tt=(0,t.raiser)(`router`,`navigateToDefault`),nt=(0,t.raiser)(`router`,`navigate`),rt=Object.hasOwn,it=Object.getPrototypeOf;function at(e){if(typeof e!=`string`)throw nt.type`Invalid route name: expected string, got ${y(e)}`}function ot(e){if(e!==void 0&&(typeof e!=`object`||!e))throw tt.type`Invalid options: ${y(e)}. Expected NavigationOptions object.`}function st(e){if(typeof e!=`object`||!e)throw A.type`Invalid state: ${y(e)}. Expected State object.`;let t=e;if(!o(t.name))throw A.type`Invalid state.name: ${y(t.name)}. Expected string.`;if(!m(t.params))throw A.type`Invalid state.params: ${y(t.params)}. Expected plain object.`;if(!o(t.path))throw A.type`Invalid state.path: ${y(t.path)}. Expected string.`}function ct(e,n){if(!le(e))throw(0,t.raiser)(`router`,n).type`Invalid options: ${y(e)}. Expected NavigationOptions object.`}const lt=/[\u0000-\u001F\u007F]/;function ut(e,n){for(let r in e){if(!rt(e,r))continue;let i=e[r],a=typeof i;if(a===`symbol`||a===`bigint`)throw(0,t.raiser)(`router`,n).type`param "${r}" cannot be a ${a} — it does not round-trip through the URL path. Use a string, number, or boolean.`;if(a===`string`&<.test(i))throw(0,t.raiser)(`router`,n).type`param "${r}" must not contain control characters (NUL / C0 / DEL) — they corrupt the URL path.`}}function j(e,n){if(e===void 0)return;let r=e!==null&&it(e);if(Array.isArray(e)||r!==null&&r!==Object.prototype)throw(0,t.raiser)(`router`,n).type`params must be a plain object, got ${y(e)}`}function M(e,n){if(e!==void 0&&(ut(e,n),!m(e)))throw(0,t.raiser)(`router`,n).type`params must be a plain object, got ${y(e)}`}function N(e,n){if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))throw(0,t.raiser)(`router`,n).type`search must be a plain object, got ${y(e)}`}function dt(e){if(e!==void 0&&typeof e!=`string`)throw k.type`path must be a string, got ${y(e)}.`;if(typeof e==`string`){if(lt.test(e))throw k.type`path must not contain control characters (NUL / C0 / DEL).`;if(e!==``&&!e.startsWith(`/`))throw k.type`path must start with "/", got "${e}".`}}const ft=Object.entries,pt=Object.hasOwn,P=Object.keys,mt=Object.getPrototypeOf,F={trailingSlash:[`strict`,`never`,`always`,`preserve`],queryParamsMode:[`default`,`strict`,`loose`],urlParamsEncoding:[`default`,`uri`,`uriComponent`,`none`]},ht={arrayFormat:!0,booleanFormat:!0,nullFormat:!0,numberFormat:!0},gt=new Set(P({defaultRoute:!0,defaultParams:!0,defaultSearch:!0,trailingSlash:!0,caseSensitive:!0,queryParamsMode:!0,queryParams:!0,urlParamsEncoding:!0,allowNotFound:!0,rewritePathOnMatch:!0,logger:!0,limits:!0})),_t={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 vt(e,n,r){if(typeof n!=`number`||!Number.isInteger(n))throw(0,t.raiser)(`router`,r).type`limit "${e}" must be an integer, got ${String(n)}`;let i=_t[e];if(n<i.min||n>i.max)throw(0,t.raiser)(`router`,r).range`limit "${e}" must be between ${i.min} and ${i.max}, got ${n}`}function yt(e){let t=mt(e);return t===null||t===Object.prototype}function bt(e,n){if(!e||typeof e!=`object`||!yt(e))throw(0,t.raiser)(`router`,n).type`invalid limits: expected plain object, got ${typeof e}`;for(let[r,i]of ft(e)){if(!pt(_t,r))throw(0,t.raiser)(`router`,n).type`unknown limit: "${r}"`;i!==void 0&&vt(r,i,n)}let{warnListeners:r,maxListeners:i}=e;if(typeof r==`number`&&typeof i==`number`&&i>0&&r>i)throw(0,t.raiser)(`router`,n).range`"limits.warnListeners" (${r}) must not exceed "limits.maxListeners" (${i}) — the warning channel would be unreachable`}function I(e,n,r,i){if(e!==void 0&&(typeof e!=`string`||!r.includes(e))){let a=r.map(e=>`"${e}"`).join(`, `),o=typeof e==`string`?e:`(${typeof e})`;throw(0,t.raiser)(`router`,i).type`Invalid "${n}": "${o}". Must be one of: ${a}`}}function xt(e,n){if(e!==void 0&&typeof e!=`string`&&typeof e!=`function`)throw(0,t.raiser)(`router`,n).type`Invalid "defaultRoute": expected string or function, got ${typeof e}`}function St(e,n,r){if(e!==void 0&&typeof e!=`function`&&(!e||typeof e!=`object`||Array.isArray(e)||!yt(e)))throw(0,t.raiser)(`router`,r).type`Invalid "${n}": expected plain object or function, got ${typeof e}`}function Ct(e,n){if(e===void 0)return;if(!e||typeof e!=`object`||Array.isArray(e))throw(0,t.raiser)(`router`,n).type`Invalid "queryParams": expected plain object`;let r=e;for(let e of P(r))if(!c(e,ht))throw(0,t.raiser)(`router`,n).type`Invalid "queryParams.${e}": unknown option`}function wt(e,n){if(!e||typeof e!=`object`||Array.isArray(e))throw(0,t.raiser)(`router`,n).type`Invalid options: expected plain object`;let r=e;for(let e of P(r))if(!gt.has(e))throw(0,t.raiser)(`router`,n).type`Unknown option: "${e}"`;if(xt(r.defaultRoute,n),St(r.defaultParams,`defaultParams`,n),St(r.defaultSearch,`defaultSearch`,n),I(r.trailingSlash,`trailingSlash`,F.trailingSlash,n),I(r.queryParamsMode,`queryParamsMode`,F.queryParamsMode,n),I(r.urlParamsEncoding,`urlParamsEncoding`,F.urlParamsEncoding,n),r.allowNotFound!==void 0&&typeof r.allowNotFound!=`boolean`)throw(0,t.raiser)(`router`,n).type`Invalid "allowNotFound": expected boolean, got ${typeof r.allowNotFound}`;if(r.rewritePathOnMatch!==void 0&&typeof r.rewritePathOnMatch!=`boolean`)throw(0,t.raiser)(`router`,n).type`Invalid "rewritePathOnMatch": expected boolean, got ${typeof r.rewritePathOnMatch}`;if(r.caseSensitive!==void 0&&typeof r.caseSensitive!=`boolean`)throw(0,t.raiser)(`router`,n).type`Invalid "caseSensitive": expected boolean, got ${typeof r.caseSensitive}`;Ct(r.queryParams,n),r.limits!==void 0&&bt(r.limits,n)}const L=(0,t.raiser)(`router`,`usePlugin`),Tt=Object.hasOwn,R=`router.usePlugin`,Et={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function Dt(e,t,n=i.maxPlugins){if(n!==0&&e+t>n)throw L.range`Plugin limit exceeded (${n}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating plugins.`}function Ot(e,t){if(t.includes(e))throw L.plain`Plugin factory already registered. To re-register, first unsubscribe the existing plugin.`}function kt(e,t,n){if(t===0)return;let{warn:r,error:i}=a(t);e>=i?n.error(R,`${e} plugins registered! This is excessive. Hard limit at ${t}.`):e>=r&&n.warn(R,`${e} plugins registered. Consider if all are necessary.`)}function At(e){for(let t in e)if(!(t===`teardown`||Tt(Et,t)))throw L.type`Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`}function jt(e){e.warn(R,`Duplicate factory in batch, will be registered once`)}function Mt(e,t){t.warn(R,`Property '${e}' is not a function, skipping`)}function Nt(e,t){e===`onStart`&&t.warn(R,`Router already started, onStart will not be called`)}const Pt=(0,t.raiser)(`router`,`navigateToDefault`),z=(0,t.raiser)(`validation-plugin`),B=Object.entries,Ft=Object.getOwnPropertyDescriptor,It=Object.keys;function V(e,t,n=``){for(let r of e){let e=n?`${n}.${r.name}`:r.name;t(r,e),r.children&&V(r.children,t,e)}}function H(e,t){let n=[];return V(e,(e,r)=>{let i=t(e);i!==void 0&&n.push([r,i])}),n}function Lt(e,t){try{return(0,r.resolveForwardChain)(e,t)}catch(e){let t=e.message.replace(/^\[router\] /u,``);throw z.plain({cause:e})`${t}`}}function U(e,t,n){let r=e;if(r.constructor.name===`AsyncFunction`||r.toString().includes(`__awaiter`))throw z.type`Route "${n}" ${t} cannot be async`}function Rt(e){V(e,(e,t)=>{if(typeof e.name!=`string`||!e.name)throw z.type`validateExistingRoutes: route has invalid name: ${e.name}`;if(typeof e.path!=`string`)throw z.type`validateExistingRoutes: route "${t}" has non-string path (${typeof e.path})`})}function zt(e,t){for(let[n,r]of B(e)){if(!t.hasRoute(r))throw z.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 z.plain`validateForwardToConsistency: forwardTo target "${r}" requires params [${i.join(`, `)}] not available in source route "${n}"`}for(let t of It(e))Lt(t,e)}function Bt(e,t){for(let[n,r]of e)if(typeof r!=`object`||!r||Array.isArray(r))throw z.type`validateRoutePropertiesStore: route "${n}" ${t} must be a plain object, got ${Array.isArray(r)?`array`:typeof r}`}function Vt(e){let t=H(e,e=>e.decodeParams),n=H(e,e=>e.encodeParams),r=H(e,e=>typeof e.forwardTo==`string`?void 0:e.forwardTo);for(let[e,n]of t){if(typeof n!=`function`)throw z.type`validateRoutePropertiesStore: route "${e}" decoder must be a function, got ${typeof n}`;U(n,`decoder`,e)}for(let[e,t]of n){if(typeof t!=`function`)throw z.type`validateRoutePropertiesStore: route "${e}" encoder must be a function, got ${typeof t}`;U(t,`encoder`,e)}Bt(H(e,e=>e.defaultParams),`defaultParams`),Bt(H(e,e=>e.defaultSearch),`defaultSearch`);for(let[e,t]of r){if(typeof t!=`function`)throw z.type`validateRoutePropertiesStore: route "${e}" forwardTo callback must be a function, got ${typeof t}`;U(t,`forwardTo callback`,e)}}function Ht(e,t){for(let[n,r]of B(e))if(!t.hasRoute(r))throw z.plain`validateForwardToTargetsStore: forwardTo target "${r}" does not exist for route "${n}"`}function Ut(e,t){for(let t of It(e))if(Ft(e,t)?.get)throw z.type`validateDependenciesStructure: dependency "${t}" must not use a getter`;for(let[e,n]of B(t))if(!Number.isInteger(n))throw z.type`validateDependenciesStructure: deps.limits.${e} must be an integer, got ${String(n)}`}function Wt(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 z.range`validateLimitsConsistency: dependency count (${t}) exceeds maxDependencies limit (${a})`}function Gt(e,t){return typeof e==`string`&&e!==``&&!t.hasRoute(e)}function Kt(e,t){if(Gt(e,t))throw z.plain`defaultRoute resolved to non-existent route: "${e}"`}function qt(e,t){if(Gt(e,t))throw Pt.plain`defaultRoute callback resolved to non-existent route: "${e}"`}function Jt(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 W=(0,t.raiser)(`router`,`updateRoute`),G=(0,t.raiser)(`router`,`addRoute`),Yt=(0,t.raiser)(`router`,`shouldUpdateNode`),Xt=(0,t.raiser)(`router`,`matchPath`),Zt=(0,t.raiser)(`router`,`buildPath`),K=(0,t.raiser)(`router`,`isActiveRoute`),Qt=(0,t.raiser)(`router`,`setRootPath`);function q(e,n){if(e.startsWith(`@@`))throw(0,t.raiser)(`router`,n).plain`Route name "${e}" uses the reserved "${`@@`}" prefix. Routes with this prefix are internal and cannot be modified through the public API.`}function $t(e,t){for(let n of e)n&&typeof n==`object`&&typeof n.name==`string`&&(q(n.name,t),n.children&&$t(n.children,t))}function en(e){v(e,`removeRoute`)}function tn(e){if(typeof e!=`string`)throw Qt.type`rootPath must be a string, got ${y(e)}`}function J(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function nn(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw G.type`canActivate must be a function, got ${y(t.canActivate)}`;if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw G.type`canDeactivate must be a function, got ${y(t.canDeactivate)}`}function rn(e,t){let n=e;if(typeof n.decodeParams==`function`&&J(n.decodeParams))throw G.type`decodeParams cannot be async for route "${String(t)}"`;if(typeof n.encodeParams==`function`&&J(n.encodeParams))throw G.type`encodeParams cannot be async for route "${String(t)}"`;if(typeof n.forwardTo==`function`&&J(n.forwardTo))throw G.type`forwardTo callback cannot be async for route "${String(t)}"`}function an(e,t){for(let n of e){if(typeof n!=`object`||!n||Array.isArray(n))throw G.type`Route must be an object, got ${y(n)}`;E(n,w(t,n.name))}}function on(e){if(typeof e!=`string`||e===``)throw G.type`parent option must be a non-empty string, got ${y(e)}`;v(e,`addRoute`)}function sn(e,t,n,r){if(!o(e))throw K.type`name must be a string, got ${typeof e}`;if(j(t,`isActiveRoute`),n!==void 0&&typeof n!=`boolean`)throw K.type`strictEquality must be a boolean, got ${typeof n}`;if(r!==void 0&&typeof r!=`boolean`)throw K.type`ignoreQueryParams must be a boolean, got ${typeof r}`}function Y(e,n,r){if(!o(e))throw(0,t.raiser)(`router`,r).type`Invalid routeName: ${y(e)}. Expected string.`;if(!m(n))throw(0,t.raiser)(`router`,r).type`Invalid routeParams: ${y(n)}. Expected plain object.`}function cn(e,t){if(v(e,`updateRoute`),e===``)throw W.ref`Invalid name: empty string. Cannot update root node.`;if(t===null)throw W.type`updates must be an object, got null`;if(typeof t!=`object`||Array.isArray(t))throw W.type`updates must be an object, got ${y(t)}`}function ln(e,t){if(e.constructor.name===`AsyncFunction`||e.toString().includes(`__awaiter`))throw W.type`${t} cannot be an async function`}function X(e,t){if(e!=null){if(typeof e!=`function`)throw W.type`${t} must be a function or null, got ${typeof e}`;ln(e,t)}}function un(e){let{forwardTo:t,defaultParams:n,defaultSearch:r,decodeParams:i,encodeParams:a,canActivate:o,canDeactivate:s}=e;if(t!=null){if(typeof t!=`string`&&typeof t!=`function`)throw W.type`forwardTo must be a string, function, or null, got ${y(t)}`;typeof t==`function`&&ln(t,`forwardTo callback`)}dn(n,`defaultParams`),dn(r,`defaultSearch`),X(i,`decodeParams`),X(a,`encodeParams`),X(o,`canActivate`),X(s,`canDeactivate`)}function dn(e,t){if(e!=null&&(typeof e!=`object`||Array.isArray(e)))throw W.type`${t} must be an object or null, got ${y(e)}`}function fn(e){if(!o(e)||e===``)throw Zt.type`route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`}function pn(e){let t=new Set;return function(r,i){let a=(0,n.findMisChanneledKey)(i,e(r));if(a===void 0)return;let o=`${r} ${a}`;t.has(o)||(t.add(o),console.warn(`[router] Route "${r}" declares \`${a}\` as a query param, but it was given in the \`params\` bag — the path channel. The URL is built without it, so the href does not match what you asked for; a plain click throws, but a ⌘-click, a copied link and server-rendered markup all follow the wrong URL in silence. Pass it in \`search\` instead.`))}}function mn(e){if(!o(e))throw Xt.type`path must be a string, got ${typeof e}`}function hn(e){if(!o(e))throw Yt.type`nodeName must be a string, got ${typeof e}`}function gn(e,t,r,i,a){if(a){let e=t;for(let t of a.split(`.`))if(e=e.children.get(t),!e)throw G.ref`Parent route "${a}" does not exist`}let o=new Set,s=new Map;for(let r of e)(0,n.validateRoute)(r,`addRoute`,t,a??``,o,s);Ke(e,i,r,a)}function _n(e,t,n){let r=new Set(n.getUrlParams(e)),i=n.getUrlParams(t).filter(e=>!r.has(e));if(i.length>0)throw W.plain`forwardTo target "${t}" requires params [${i.join(`, `)}] that are not available in source route "${e}"`}function vn(e,t,n){let i={...n,[e]:t};(0,r.resolveForwardChain)(e,i)}function yn(e,t,n,r){if(!n.hasRoute(e))throw W.ref`route "${e}" does not exist`;if(t!=null&&typeof t==`string`){if(!n.hasRoute(t))throw W.plain`forwardTo target "${t}" does not exist`;_n(e,t,n),vn(e,t,r)}}const Z=(0,t.raiser)(`router`,`makeState`),bn=Object.entries;function xn(e,t,n){if(!o(e))throw Z.type`Invalid name: ${y(e)}. Expected string.`;if(t!==void 0&&!m(t))throw Z.type`Invalid params: ${y(t)}. Expected plain object.`;if(n!==void 0&&!o(n))throw Z.type`Invalid path: ${y(n)}. Expected string.`}function Sn(){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 Cn(){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 wn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Tn(e,t){let n={params:{...t.params},search:{...t.search}};if(e===void 0)return n;let r=e(n),i=r.params??n.params,a=r.search??n.search;return wn(i)&&wn(a)?{params:i,search:a}:void 0}function En(e,t){try{return Tn(e,t)}catch{return}}function Q(e){return new Map(bn(e).filter(([,e])=>e!==void 0))}function Dn(e){return Array.isArray(e)?e.some(e=>Dn(e)):typeof e==`object`&&!!e}function On(e,t){try{return e(t)}catch{return}}function kn(e,t){let n=n=>{let r=Q(e[n]);return new Map([...Q(t[n])].filter(([e])=>!r.has(e)))};return{params:n(`params`),search:n(`search`)}}function An(e,t){return Object.fromEntries(bn(e).filter(([e])=>!t.has(e)))}function jn(e,t,r){if(r.params.size+r.search.size===0)return r;try{let i=t(e.name,An(e.params,r.params),An(e.search,r.search)),a=e=>{let t=Q(i[e]??{});return new Map([...r[e]].filter(([e,r])=>t.has(e)&&(0,n.areParamValuesEqual)(t.get(e),r)))};return{params:a(`params`),search:a(`search`)}}catch{return{params:new Map,search:new Map}}}function Mn(e,t,r,i){let a=En(e.codec.encode,{...e.state,[t]:{...e.state[t],[r]:i}});return a!==void 0&&(0,n.areParamValuesEqual)(e.encoded[t][r],a[t][r])}function Nn(e,t,n){return e.credited[t].has(n)?void 0:`added`}function Pn(e,t,r,i,a){if(!Dn(a))return(0,n.areParamValuesEqual)(i,a)?void 0:`changed`;if(!Mn(e,t,r,a))return`changed`;if(!(0,n.areParamValuesEqual)(i,a))return(0,n.areParamValuesEqual)(a,e.readAgain()?.[t][r])?`undecoded`:`keyless`}function Fn(e,t){let n=Q(e.state[t]),r=Q(e.back[t]),i=[];for(let[a,o]of r){let r=n.has(a)?Pn(e,t,a,n.get(a),o):Nn(e,t,a);r!==void 0&&i.push([t,a,r])}for(let a of n.keys())!r.has(a)&&(t===`search`||e.pathSlots.includes(a))&&i.push([t,a,`dropped`]);return i}function In(e,t,n,r,i){let a=r(e.path);if(a?.name!==e.name)return[];let o=Tn(t.encode,e);if(o===void 0)return[];let s,c={state:e,codec:t,pathSlots:n,encoded:o,back:a,readAgain:()=>(s??={state:On(r,e.path)},s.state),credited:jn(a,i,kn(e,a))};return[...Fn(c,`params`),...Fn(c,`search`)]}function Ln(e){return e.decode===void 0?`The route has an encodeParams and no decodeParams to undo it.`:e.encode===void 0?`With no encodeParams, decodeParams must return each value so that it prints as the URL shows it.`:`decodeParams must undo encodeParams.`}function Rn(e,t,n,r,i){let a=`Route "${e}": its codec`,o=`${a} changes "${n}" in state.${t}, so a link and a reload of the same URL commit different values.`;switch(r){case`added`:return`${a} adds "${n}" to state.${t}, so a link commits a state without it and a reload of the same URL commits one with it. Derive "${n}" in a forwardState interceptor instead: navigate and matchPath both run it.`;case`changed`:return`${o} ${Ln(i)}`;case`undecoded`:return`${o} encodeParams prints both as one piece of the URL, so a link must pass the value decodeParams returns for that piece.`;case`keyless`:return`${o} Two reloads of one URL decode values that never compare equal: give the value a key — a Date, or a plain object JSON.stringify prints in full.`;case`dropped`:return`${a} drops "${n}" from state.${t}, so a reload of the URL a link builds loses it. ${Ln(i)}`}}function zn(e,t,n){let r=new Set;return function(i,a,o){let s;try{s=In(i,a,o,t,n)}catch{return}for(let[t,n,o]of s){let s=`${i.name} ${t} ${n}`;r.has(s)||(r.add(s),e.warn(`router`,Rn(i.name,t,n,o,a)))}}}const Bn=(0,t.raiser)(`validation-plugin`),Vn=(0,t.raiser)(`router`,`addRoute`),$=(0,t.raiser)(`router`,`areStatesEqual`);function Hn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Un(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 Wn={hasRoute:()=>!1,getUrlParams:()=>[]};function Gn(e){return{tree:{...e,children:new Map,nonAbsoluteChildren:[]},lookup:Wn,forwardMap:{}}}function Kn(e,t){let n=[];for(let r of e.getTree().children.keys())n.push(t.get(r));return n}function qn(e,t,n,r){let a=pn(t=>e.getDeclaredQueryNames(t));return{routes:{validateBuildPathArgs(e,t){fn(e),a(e,t)},validateMatchPathArgs:mn,validateIsActiveRouteArgs(e,t,n,r){sn(e,t,n,r),a(e,t)},validateShouldUpdateNodeArgs:hn,validateStateBuilderArgs:Y,validateRouteName(e,t){v(e,t)},validateSetRootPathArgs:tn},options:{validateOptions:wt,validateResolvedDefaultRoute(e){qt(e,t)}},dependencies:{validateDependencyName:we,validateSetDependencyArgs(e,t,n){Te(e)},validateDependenciesObject(t,n){Ee(t,n),De(t,e.getDependencyKeys(),e.getResolvedLimits().maxDependencies,n)},validateDependencyExists(e,t){Oe(t,e)},validateDependencyCount(t,n,r){ke(t,n,r,e.logger)},validateCloneArgs:Ae,warnOverwrite(t,n){je(t,n,e.logger)},warnBatchOverwrite(t,n){Me(t,n,e.logger)},warnRemoveNonExistent(t){Ne(t,e.logger)}},plugins:{validatePluginLimit(e,t){Dt(e,1,t?.maxPlugins)},validateNoDuplicatePlugins:Ot,validatePluginKeys:At,validateCountThresholds(t){kt(t,e.getOptions().limits?.maxPlugins??i.maxPlugins,e.logger)},warnBatchDuplicates(){jt(e.logger)},warnPluginMethodType(t){Mt(t,e.logger)}},lifecycle:{validateHandlerLimit(t,n){Je(t,n,e.getOptions().limits?.maxLifecycleHandlers??i.maxLifecycleHandlers)},validateCountThresholds(t,n){Ye(t,n,e.getOptions().limits?.maxLifecycleHandlers??i.maxLifecycleHandlers,e.logger)},warnOverwrite(t,n,r){Xe(t,n,r,e.logger)},warnAsyncGuardSync(t,n){Ze(t,n,e.logger)},warnNonBooleanGuardSync(t,n,r){$e(t,n,r,e.logger)},warnNonBooleanGuard(t,n){et(t,n,e.logger)}},navigation:{validateNavigateToDefaultArgs(t){ot(t),n.check(e.logger)},validateNavigateToStateArgs:st,validateNavigationOptions:ct,validateParamsShape:j,validateSearch:N,validateStartArgs:dt},state:{validateMakeStateArgs:xn,reportDroppedQueryKey:Sn(),reportUndeclaredParamKey:Cn(),reportCodecRoundTrip:zn(e.logger,r,e.forwardState),validateAreStatesEqualArgs(e,t,n){if(!_(e))throw $.type`Invalid state1: ${y(e)}. Expected State object.`;if(!_(t))throw $.type`Invalid state2: ${y(t)}. Expected State object.`;if(n!==void 0&&!s(n))throw $.type`Invalid ignoreQueryParams: ${y(n)}. Expected boolean.`;if(n===!1){if(!Hn(e.search))throw $.type`Invalid state1.search: ${y(e.search)}. Expected a plain object.`;if(!Hn(t.search))throw $.type`Invalid state2.search: ${y(t.search)}. Expected a plain object.`}}},eventBus:{validateListenerArgs(e,t){Le(e,t)},validateCountThresholds(t,n,r){let a=e.getOptions().limits?.maxListeners??i.maxListeners;Re(t,n,r,e.logger,a)}}}}function Jn(){return t=>{let r=(0,n.getInternals)(t),i=(0,e.getPluginApi)(t);if(t.isActive())throw Bn.code(`VALIDATION_PLUGIN_AFTER_START`)`must be registered before router.start()`;if(r.validator!==null)throw Bn.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 _e;a.watch(i.getAdoptedOrigins());let o=e=>r.matchPath(e,{...i.getOptions(),rewritePathOnMatch:!1}),s=Un(i),c=qn(i,s,a,o),l=()=>{r.validator===c&&(r.validator=null)};r.validator=c;try{let n=Kn(i,(0,e.getRoutesApi)(t)),a=i.getForwardMap(),o=i.getResolvedLimits(),c=i.getOptions();Rt(n),zt(a,s),Vt(n),Ht(a,s),Ut(r.dependenciesGetStore().dependencies,o),Wt(c,i.getDependencyKeys().length,o.maxDependencies),r.validator.options.validateOptions(c,`constructor (retrospective)`),typeof c.defaultRoute==`string`&&Kt(c.defaultRoute,s)}catch(e){throw l(),e}let u=i.addInterceptor(`start`,(e,t)=>{try{Jt(i.getExternalGuardNames(),s,i.logger)}catch{}return e(t)}),ee=i.addCheck(`buildPath:params`,e=>{M(e,`buildPath`)}),te=i.addCheck(`buildPathResolved:params`,e=>{M(e,`buildPathResolved`)}),ne=i.addCheck(`canNavigateTo:entry`,(e,t,n)=>{v(e,`canNavigateTo`),j(t,`canNavigateTo`),N(n,`canNavigateTo`)}),re=i.addCheck(`canNavigateTo:params`,e=>{M(e,`canNavigateTo`)}),ie=i.addCheck(`navigate:entry`,(e,t,n,r)=>{at(e),j(t,`navigate`),N(n,`navigate`),ct(r,`navigate`)}),d=i.addCheck(`navigate:params`,e=>{M(e,`navigate`)}),f=(e,t)=>{for(let n of e){let e=w(t,n.name);nn(n),rn(n,e),n.children!==void 0&&f(n.children,e)}},p=(e,t,n,r)=>{if(f(e,typeof n==`string`&&s.hasRoute(n)?n:void 0),n!==void 0&&(on(n),!s.hasRoute(n)))throw Vn.ref`Parent route "${n}" does not exist`;$t(e,t),an(e,n);let i=r();gn(e,i.tree,i.lookup,i.forwardMap,n)},ae=i.addCheck(`addRoute:batch`,(e,t)=>{p(e,`addRoute`,t,()=>({tree:i.getTree(),lookup:s,forwardMap:i.getForwardMap()}))}),oe=i.addCheck(`replaceRoutes:batch`,e=>{p(e,`replaceRoutes`,void 0,()=>Gn(i.getTree()))}),m=i.addCheck(`removeRoute:entry`,e=>{en(e),q(e,`removeRoute`)}),se=i.addCheck(`updateRoute:entry`,(e,t)=>{let n=t;cn(e,t),q(e,`updateRoute`),un({forwardTo:n.forwardTo,defaultParams:n.defaultParams,defaultSearch:n.defaultSearch,decodeParams:n.decodeParams,encodeParams:n.encodeParams,canActivate:n.canActivate,canDeactivate:n.canDeactivate}),yn(e,n.forwardTo,s,i.getForwardMap())}),ce=i.addCheck(`hasRoute:entry`,e=>{v(e,`hasRoute`)}),le=i.addCheck(`getRoute:entry`,e=>{v(e,`getRoute`)}),ue=i.addCheck(`forwardState:entry`,(e,t,n)=>{Y(e,t,`forwardState`),N(n,`forwardState`)}),h=i.addCheck(`buildNavigationState:state`,(e,t,n)=>{N(n,`buildNavigationState`),Y(e,t,`buildNavigationState`)}),g=i.addCheck(`addActivateGuard:entry`,(e,t)=>{v(e,`addActivateGuard`),qe(t,`addActivateGuard`)}),de=i.addCheck(`addDeactivateGuard:entry`,(e,t)=>{v(e,`addDeactivateGuard`),qe(t,`addDeactivateGuard`)}),fe=i.addCheck(`removeActivateGuard:entry`,e=>{v(e,`removeActivateGuard`)}),_=i.addCheck(`removeDeactivateGuard:entry`,e=>{v(e,`removeDeactivateGuard`)}),y=i.subscribeDiagnostic(`PLUGIN_AFTER_START`,e=>{Nt(e,i.logger)});return{teardown(){ee(),te(),ne(),re(),ie(),d(),ae(),oe(),m(),se(),ce(),le(),ue(),h(),g(),de(),fe(),_(),y(),u(),l()}}}}exports.validationPlugin=Jn;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@real-router/core/api"),t=require("@real-router/core/utils"),n=require("@real-router/core/validation"),r=require("@real-router/core");const i=Object.freeze({maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxLifecycleHandlers:200});function a(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}function o(e){return typeof e==`string`}function s(e){return typeof e==`boolean`}function c(e,t){return e in t}const l=Object.getPrototypeOf,u=Object.values,ee=Object.hasOwn,te=Date,ne=Date.prototype.getTime;function re(e){if(Array.isArray(e))return!0;let t=l(e);return t===null||t===Object.prototype}function ie(e,t){let n=Array.isArray(e)?e:u(e);for(let e of n)t.push(e)}function d(e){let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}var f=class{container;constructor(e){this.container=e}};function p(e,t,n,r){return n.has(e)?!1:r.has(e)?!0:re(e)?(n.add(e),t.push(new f(e)),ie(e,t),!0):e instanceof te&&(ne.call(e),!0)}function ae(e){let t=[e],n=new WeakSet,r=new WeakSet;for(;t.length>0;){let e=t.pop();if(e instanceof f)n.delete(e.container),r.add(e.container);else if(e!=null){if(typeof e==`object`){if(!p(e,t,n,r))return!1}else if(!d(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 m(e){try{return se(e)}catch{return!1}}function se(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=l(e);if(t!==null&&t!==Object.prototype)return!1;let n=!1;for(let t in e){if(!ee(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/,h=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function g(e,n){return(0,t.raiser)(`router`,e).type`${n}`}function de(e){return typeof e==`string`?e===``?!0:e.length>1e4?!1:e.startsWith(`@@`)?!0:h.test(e):!1}function fe(e){return de(e.name)&&typeof e.path==`string`&&m(e.params)}function _(e){return typeof e!=`object`||!e?!1:fe(e)}function v(e,t){if(typeof e!=`string`)throw g(t,`Route name must be a string, got ${typeof e}`);if(e!==``){if(!ue.test(e))throw g(t,`Route name cannot contain only whitespace`);if(e.length>1e4)throw g(t,`Route name exceeds maximum length of 10000 characters. This is a technical safety limit.`);if(!e.startsWith(`@@`)&&!h.test(e))throw g(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 y(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 pe=Object.entries,me=[`defaultParams`,`defaultSearch`],he=e=>new Map(pe(e)),ge=(e,t)=>{let n=pe(e);return n.length!==t.size||n.some(([e,n])=>!t.has(e)||!Object.is(t.get(e),n))};var _e=class{#e=new Map;#t=new Set;watch(e){for(let t of me){let n=e[t],r=n?.deref();n!==void 0&&r!==void 0&&this.#e.set(t,{ref:n,before:he(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&&ge(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 b=(0,t.raiser)(`cloneRouter`),ve=(0,t.raiser)(`router`,`getDependency`),ye=(0,t.raiser)(`router`,`setDependency`),x=Object.keys,be=Object.getOwnPropertyDescriptor,xe=Object.getPrototypeOf,Se=Object;function Ce(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=xe(e);return t===null||t.constructor===Se}function we(e,n){if(typeof e!=`string`)throw(0,t.raiser)(`router`,n).type`dependency name must be a string, got ${typeof e}`}function Te(e){if(typeof e!=`string`)throw ye.type`dependency name must be a string, got ${typeof e}`}function Ee(e,n){if(!Ce(e))throw(0,t.raiser)(`router`,n).type`Invalid argument: expected plain object, received ${y(e)}`;for(let r of x(e))if(be(e,r)?.get)throw(0,t.raiser)(`router`,n).type`Getters not allowed: "${r}"`}function De(e,n,r,i){if(r===0)return;let a=new Set(n),o=0;for(let t of x(e))a.has(t)||(o+=1);let s=n.length;if(s+o>r)throw(0,t.raiser)(`router`,i).range`Dependency limit exceeded (${r}). Current: ${s}, this batch adds ${o}.`}function Oe(e,t){if(e===void 0)throw ve.ref`dependency "${t}" not found`}function ke(e,n,r,i){if(n===0)return;let{warn:o,error:s}=a(n);if(e>=n)throw(0,t.raiser)(`router`,r).range`Dependency limit exceeded (${n}). Current: ${e}.`;e===s?i.error(`router.${r}`,`${e} dependencies registered! This indicates architectural problems. Hard limit at ${n}.`):e===o&&i.warn(`router.${r}`,`${e} dependencies registered. Consider if all are necessary.`)}function Ae(e){if(e!==void 0){if(!Ce(e))throw b.type`Invalid dependencies: expected plain object or undefined, received ${typeof e}`;for(let t of x(e))if(be(e,t)?.get)throw b.type`Getters not allowed in dependencies: "${t}"`}}function je(e,t,n){n.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function Me(e,t,n){n.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function Ne(e,t){t.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const S=(0,t.raiser)(`router`,`addEventListener`),Pe=Object.values,Fe=new Set(Pe(r.events));function Ie(e){if(!Fe.has(e))throw S.type`Invalid event name: ${String(e)}. Must be one of: $start, $stop, $$start, $$leaveApprove, $$cancel, $$success, $$error`}function Le(e,t){if(Ie(e),typeof t!=`function`)throw S.type`callback must be a function, got ${typeof t}`}function Re(e,t,n,r,o=i.maxListeners){if(o===0)return;let{warn:s,error:c}=a(o);e>=c?r.error(`router.${n}`,`${e} listeners registered for "${t}"! This is excessive. Hard limit at ${o}.`):e>=s&&r.warn(`router.${n}`,`${e} listeners registered for "${t}". Consider whether all are necessary — a growing count usually means a missing unsubscribe.`)}const C=(0,t.raiser)(`router`,`addRoute`),ze=Object.keys;function w(e,t){return typeof e==`string`&&e!==``&&typeof t==`string`?`${e}.${t}`:t}function Be(e,t){if(e!==void 0){if(typeof e!=`string`&&typeof e!=`function`)throw C.type`forwardTo must be a string or function for route "${t}", got ${y(e)}`;if(typeof e==`function`){let n=e.constructor.name===`AsyncFunction`,r=e.toString().includes(`__awaiter`);if(n||r)throw C.type`forwardTo callback cannot be async for route "${t}". Async functions break matchPath/buildPath.`}}}function T(e,t,n){if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))throw C.type`${t} must be an object for route "${n}", got ${y(e)}`}function E(e,t){if(e.canActivate!==void 0&&typeof e.canActivate!=`function`)throw C.type`canActivate must be a function for route "${t}", got ${y(e.canActivate)}`;if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw C.type`canDeactivate must be a function for route "${t}", got ${y(e.canDeactivate)}`;T(e.defaultParams,`defaultParams`,t),T(e.defaultSearch,`defaultSearch`,t);let{decodeParams:n,encodeParams:r}=e;if(typeof n==`function`&&n.constructor.name===`AsyncFunction`)throw C.type`decodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`;if(typeof r==`function`&&r.constructor.name===`AsyncFunction`)throw C.type`encodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`;if(Be(e.forwardTo,t),e.children)for(let n of e.children)E(n,w(t,n.name))}function D(e){let t=new Set;for(let r of e)for(let e of(0,n.buildParamMeta)(r).urlParams)t.add(e);return t}function O(e,n,r=``,i=[]){for(let t of e){let e=r?`${r}.${t.name}`:t.name,a=[...i,t.path];if(e===n)return a;if(t.children&&n.startsWith(`${e}.`))return O(t.children,n,e,a)}throw t.internalDefect.plain`collectPathsToRoute: route "${n}" not found`}function Ve(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 Ve(r.children,e))n.add(t)}return n}function He(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 He(r.children,e))n.set(t,i)}return n}function Ue(e,t,n,r){return t?new Set(n.getUrlParams(e)):D(r(e))}const We=new Set;function Ge(e,t,n,r,i,a){let o=i.hasRoute(t),s=r.has(t);if(!o&&!s)throw C.ref`forwardTo target "${t}" does not exist for route "${e}"`;let c=new Set([...a,...D(n(e))]),l=[...Ue(t,o,i,n)].filter(e=>!c.has(e));if(l.length>0)throw C.plain`forwardTo target "${t}" requires params [${l.join(`, `)}] that are not available in source route "${e}"`}function Ke(e,n,i,a){let o=Ve(e,a),s=t=>O(e,a?t.slice(a.length+1):t),c=a?new Set(i.getUrlParams(a)):We,l=He(e,a),u={...n};for(let[e,n]of l)(0,t.putField)(u,e,n);for(let[e,t]of l)Ge(e,t,s,o,i,c);for(let e of ze(u))(0,r.resolveForwardChain)(e,u)}function qe(e,n){if(!s(e)&&typeof e!=`function`)throw(0,t.raiser)(`router`,n).type`Handler must be a boolean or factory function, got ${y(e)}`}function Je(e,n,r=i.maxLifecycleHandlers){if(r!==0&&e>=r)throw(0,t.raiser)(`router`,n).range`Lifecycle handler limit exceeded (${r}). This indicates too many routes with individual handlers. Consider using plugins for cross-cutting concerns.`}function Ye(e,t,n,r){if(n===0)return;let{warn:i,error:o}=a(n);e>=o?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 Xe(e,t,n,r){r.warn(`router.${n}`,`Overwriting existing ${t} handler for route "${e}"`)}function Ze(e,t,n){n.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}function Qe(e,t){return`Guard for "${e}" must answer true or false, got ${y(t)} — read as a refusal.`}function $e(e,t,n,r){r.warn(`router.${n}`,Qe(e,t))}function et(e,t,n){n.warn(`router`,Qe(e,t))}const k=(0,t.raiser)(`router`,`start`),A=(0,t.raiser)(`router`,`navigateToState`),tt=(0,t.raiser)(`router`,`navigateToDefault`),nt=(0,t.raiser)(`router`,`navigate`),rt=Object.hasOwn,it=Object.getPrototypeOf;function at(e){if(typeof e!=`string`)throw nt.type`Invalid route name: expected string, got ${y(e)}`}function ot(e){if(e!==void 0&&(typeof e!=`object`||!e))throw tt.type`Invalid options: ${y(e)}. Expected NavigationOptions object.`}function st(e){if(typeof e!=`object`||!e)throw A.type`Invalid state: ${y(e)}. Expected State object.`;let t=e;if(!o(t.name))throw A.type`Invalid state.name: ${y(t.name)}. Expected string.`;if(!m(t.params))throw A.type`Invalid state.params: ${y(t.params)}. Expected plain object.`;if(!o(t.path))throw A.type`Invalid state.path: ${y(t.path)}. Expected string.`}function ct(e,n){if(!le(e))throw(0,t.raiser)(`router`,n).type`Invalid options: ${y(e)}. Expected NavigationOptions object.`}const lt=/[\u0000-\u001F\u007F]/;function ut(e,n){for(let r in e){if(!rt(e,r))continue;let i=e[r],a=typeof i;if(a===`symbol`||a===`bigint`)throw(0,t.raiser)(`router`,n).type`param "${r}" cannot be a ${a} — it does not round-trip through the URL path. Use a string, number, or boolean.`;if(a===`string`&<.test(i))throw(0,t.raiser)(`router`,n).type`param "${r}" must not contain control characters (NUL / C0 / DEL) — they corrupt the URL path.`}}function j(e,n){if(e===void 0)return;let r=e!==null&&it(e);if(Array.isArray(e)||r!==null&&r!==Object.prototype)throw(0,t.raiser)(`router`,n).type`params must be a plain object, got ${y(e)}`}function M(e,n){if(e!==void 0&&(ut(e,n),!m(e)))throw(0,t.raiser)(`router`,n).type`params must be a plain object, got ${y(e)}`}function N(e,n){if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))throw(0,t.raiser)(`router`,n).type`search must be a plain object, got ${y(e)}`}function dt(e){if(e!==void 0&&typeof e!=`string`)throw k.type`path must be a string, got ${y(e)}.`;if(typeof e==`string`){if(lt.test(e))throw k.type`path must not contain control characters (NUL / C0 / DEL).`;if(e!==``&&!e.startsWith(`/`))throw k.type`path must start with "/", got "${e}".`}}const ft=Object.entries,pt=Object.hasOwn,P=Object.keys,mt=Object.getPrototypeOf,F={trailingSlash:[`strict`,`never`,`always`,`preserve`],queryParamsMode:[`default`,`strict`,`loose`],urlParamsEncoding:[`default`,`uri`,`uriComponent`,`none`]},ht={arrayFormat:!0,booleanFormat:!0,nullFormat:!0,numberFormat:!0},gt=new Set(P({defaultRoute:!0,defaultParams:!0,defaultSearch:!0,trailingSlash:!0,caseSensitive:!0,queryParamsMode:!0,queryParams:!0,urlParamsEncoding:!0,allowNotFound:!0,rewritePathOnMatch:!0,logger:!0,limits:!0})),_t={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 vt(e,n,r){if(typeof n!=`number`||!Number.isInteger(n))throw(0,t.raiser)(`router`,r).type`limit "${e}" must be an integer, got ${String(n)}`;let i=_t[e];if(n<i.min||n>i.max)throw(0,t.raiser)(`router`,r).range`limit "${e}" must be between ${i.min} and ${i.max}, got ${n}`}function yt(e){let t=mt(e);return t===null||t===Object.prototype}function bt(e,n){if(!e||typeof e!=`object`||!yt(e))throw(0,t.raiser)(`router`,n).type`invalid limits: expected plain object, got ${typeof e}`;for(let[r,i]of ft(e)){if(!pt(_t,r))throw(0,t.raiser)(`router`,n).type`unknown limit: "${r}"`;i!==void 0&&vt(r,i,n)}let{warnListeners:r,maxListeners:i}=e;if(typeof r==`number`&&typeof i==`number`&&i>0&&r>i)throw(0,t.raiser)(`router`,n).range`"limits.warnListeners" (${r}) must not exceed "limits.maxListeners" (${i}) — the warning channel would be unreachable`}function I(e,n,r,i){if(e!==void 0&&(typeof e!=`string`||!r.includes(e))){let a=r.map(e=>`"${e}"`).join(`, `),o=typeof e==`string`?e:`(${typeof e})`;throw(0,t.raiser)(`router`,i).type`Invalid "${n}": "${o}". Must be one of: ${a}`}}function xt(e,n){if(e!==void 0&&typeof e!=`string`&&typeof e!=`function`)throw(0,t.raiser)(`router`,n).type`Invalid "defaultRoute": expected string or function, got ${typeof e}`}function St(e,n,r){if(e!==void 0&&typeof e!=`function`&&(!e||typeof e!=`object`||Array.isArray(e)||!yt(e)))throw(0,t.raiser)(`router`,r).type`Invalid "${n}": expected plain object or function, got ${typeof e}`}function Ct(e,n){if(e===void 0)return;if(!e||typeof e!=`object`||Array.isArray(e))throw(0,t.raiser)(`router`,n).type`Invalid "queryParams": expected plain object`;let r=e;for(let e of P(r))if(!c(e,ht))throw(0,t.raiser)(`router`,n).type`Invalid "queryParams.${e}": unknown option`}function wt(e,n){if(!e||typeof e!=`object`||Array.isArray(e))throw(0,t.raiser)(`router`,n).type`Invalid options: expected plain object`;let r=e;for(let e of P(r))if(!gt.has(e))throw(0,t.raiser)(`router`,n).type`Unknown option: "${e}"`;if(xt(r.defaultRoute,n),St(r.defaultParams,`defaultParams`,n),St(r.defaultSearch,`defaultSearch`,n),I(r.trailingSlash,`trailingSlash`,F.trailingSlash,n),I(r.queryParamsMode,`queryParamsMode`,F.queryParamsMode,n),I(r.urlParamsEncoding,`urlParamsEncoding`,F.urlParamsEncoding,n),r.allowNotFound!==void 0&&typeof r.allowNotFound!=`boolean`)throw(0,t.raiser)(`router`,n).type`Invalid "allowNotFound": expected boolean, got ${typeof r.allowNotFound}`;if(r.rewritePathOnMatch!==void 0&&typeof r.rewritePathOnMatch!=`boolean`)throw(0,t.raiser)(`router`,n).type`Invalid "rewritePathOnMatch": expected boolean, got ${typeof r.rewritePathOnMatch}`;if(r.caseSensitive!==void 0&&typeof r.caseSensitive!=`boolean`)throw(0,t.raiser)(`router`,n).type`Invalid "caseSensitive": expected boolean, got ${typeof r.caseSensitive}`;Ct(r.queryParams,n),r.limits!==void 0&&bt(r.limits,n)}const L=(0,t.raiser)(`router`,`usePlugin`),Tt=Object.hasOwn,R=`router.usePlugin`,Et={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function Dt(e,t,n=i.maxPlugins){if(n!==0&&e+t>n)throw L.range`Plugin limit exceeded (${n}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating plugins.`}function Ot(e,t){if(t.includes(e))throw L.plain`Plugin factory already registered. To re-register, first unsubscribe the existing plugin.`}function kt(e,t,n){if(t===0)return;let{warn:r,error:i}=a(t);e>=i?n.error(R,`${e} plugins registered! This is excessive. Hard limit at ${t}.`):e>=r&&n.warn(R,`${e} plugins registered. Consider if all are necessary.`)}function At(e){for(let t in e)if(!(t===`teardown`||Tt(Et,t)))throw L.type`Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`}function jt(e){e.warn(R,`Duplicate factory in batch, will be registered once`)}function Mt(e,t){t.warn(R,`Property '${e}' is not a function, skipping`)}function Nt(e,t){e===`onStart`&&t.warn(R,`Router already started, onStart will not be called`)}const Pt=(0,t.raiser)(`router`,`navigateToDefault`),z=(0,t.raiser)(`validation-plugin`),B=Object.entries,Ft=Object.getOwnPropertyDescriptor,It=Object.keys;function V(e,t,n=``){for(let r of e){let e=n?`${n}.${r.name}`:r.name;t(r,e),r.children&&V(r.children,t,e)}}function H(e,t){let n=[];return V(e,(e,r)=>{let i=t(e);i!==void 0&&n.push([r,i])}),n}function Lt(e,t){try{return(0,r.resolveForwardChain)(e,t)}catch(e){let t=e.message.replace(/^\[router\] /u,``);throw z.plain({cause:e})`${t}`}}function U(e,t,n){let r=e;if(r.constructor.name===`AsyncFunction`||r.toString().includes(`__awaiter`))throw z.type`Route "${n}" ${t} cannot be async`}function Rt(e){V(e,(e,t)=>{if(typeof e.name!=`string`||!e.name)throw z.type`validateExistingRoutes: route has invalid name: ${e.name}`;if(typeof e.path!=`string`)throw z.type`validateExistingRoutes: route "${t}" has non-string path (${typeof e.path})`})}function zt(e,t){for(let[n,r]of B(e)){if(!t.hasRoute(r))throw z.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 z.plain`validateForwardToConsistency: forwardTo target "${r}" requires params [${i.join(`, `)}] not available in source route "${n}"`}for(let t of It(e))Lt(t,e)}function Bt(e,t){for(let[n,r]of e)if(typeof r!=`object`||!r||Array.isArray(r))throw z.type`validateRoutePropertiesStore: route "${n}" ${t} must be a plain object, got ${Array.isArray(r)?`array`:typeof r}`}function Vt(e){let t=H(e,e=>e.decodeParams),n=H(e,e=>e.encodeParams),r=H(e,e=>typeof e.forwardTo==`string`?void 0:e.forwardTo);for(let[e,n]of t){if(typeof n!=`function`)throw z.type`validateRoutePropertiesStore: route "${e}" decoder must be a function, got ${typeof n}`;U(n,`decoder`,e)}for(let[e,t]of n){if(typeof t!=`function`)throw z.type`validateRoutePropertiesStore: route "${e}" encoder must be a function, got ${typeof t}`;U(t,`encoder`,e)}Bt(H(e,e=>e.defaultParams),`defaultParams`),Bt(H(e,e=>e.defaultSearch),`defaultSearch`);for(let[e,t]of r){if(typeof t!=`function`)throw z.type`validateRoutePropertiesStore: route "${e}" forwardTo callback must be a function, got ${typeof t}`;U(t,`forwardTo callback`,e)}}function Ht(e,t){for(let[n,r]of B(e))if(!t.hasRoute(r))throw z.plain`validateForwardToTargetsStore: forwardTo target "${r}" does not exist for route "${n}"`}function Ut(e,t){for(let t of It(e))if(Ft(e,t)?.get)throw z.type`validateDependenciesStructure: dependency "${t}" must not use a getter`;for(let[e,n]of B(t))if(!Number.isInteger(n))throw z.type`validateDependenciesStructure: deps.limits.${e} must be an integer, got ${String(n)}`}function Wt(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 z.range`validateLimitsConsistency: dependency count (${t}) exceeds maxDependencies limit (${a})`}function Gt(e,t){return typeof e==`string`&&e!==``&&!t.hasRoute(e)}function Kt(e,t){if(Gt(e,t))throw z.plain`defaultRoute resolved to non-existent route: "${e}"`}function qt(e,t){if(Gt(e,t))throw Pt.plain`defaultRoute callback resolved to non-existent route: "${e}"`}function Jt(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 W=(0,t.raiser)(`router`,`updateRoute`),G=(0,t.raiser)(`router`,`addRoute`),Yt=(0,t.raiser)(`router`,`shouldUpdateNode`),Xt=(0,t.raiser)(`router`,`matchPath`),Zt=(0,t.raiser)(`router`,`buildPath`),K=(0,t.raiser)(`router`,`isActiveRoute`),Qt=(0,t.raiser)(`router`,`setRootPath`);function q(e,n){if(e.startsWith(`@@`))throw(0,t.raiser)(`router`,n).plain`Route name "${e}" uses the reserved "${`@@`}" prefix. Routes with this prefix are internal and cannot be modified through the public API.`}function $t(e,t){for(let n of e)n&&typeof n==`object`&&typeof n.name==`string`&&(q(n.name,t),n.children&&$t(n.children,t))}function en(e){v(e,`removeRoute`)}function tn(e){if(typeof e!=`string`)throw Qt.type`rootPath must be a string, got ${y(e)}`}function J(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function nn(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw G.type`canActivate must be a function, got ${y(t.canActivate)}`;if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw G.type`canDeactivate must be a function, got ${y(t.canDeactivate)}`}function rn(e,t){let n=e;if(typeof n.decodeParams==`function`&&J(n.decodeParams))throw G.type`decodeParams cannot be async for route "${String(t)}"`;if(typeof n.encodeParams==`function`&&J(n.encodeParams))throw G.type`encodeParams cannot be async for route "${String(t)}"`;if(typeof n.forwardTo==`function`&&J(n.forwardTo))throw G.type`forwardTo callback cannot be async for route "${String(t)}"`}function an(e,t){for(let n of e){if(typeof n!=`object`||!n||Array.isArray(n))throw G.type`Route must be an object, got ${y(n)}`;E(n,w(t,n.name))}}function on(e){if(typeof e!=`string`||e===``)throw G.type`parent option must be a non-empty string, got ${y(e)}`;v(e,`addRoute`)}function sn(e,t,n,r){if(!o(e))throw K.type`name must be a string, got ${typeof e}`;if(j(t,`isActiveRoute`),n!==void 0&&typeof n!=`boolean`)throw K.type`strictEquality must be a boolean, got ${typeof n}`;if(r!==void 0&&typeof r!=`boolean`)throw K.type`ignoreQueryParams must be a boolean, got ${typeof r}`}function Y(e,n,r){if(!o(e))throw(0,t.raiser)(`router`,r).type`Invalid routeName: ${y(e)}. Expected string.`;if(!m(n))throw(0,t.raiser)(`router`,r).type`Invalid routeParams: ${y(n)}. Expected plain object.`}function cn(e,t){if(v(e,`updateRoute`),e===``)throw W.ref`Invalid name: empty string. Cannot update root node.`;if(t===null)throw W.type`updates must be an object, got null`;if(typeof t!=`object`||Array.isArray(t))throw W.type`updates must be an object, got ${y(t)}`}function ln(e,t){if(e.constructor.name===`AsyncFunction`||e.toString().includes(`__awaiter`))throw W.type`${t} cannot be an async function`}function X(e,t){if(e!=null){if(typeof e!=`function`)throw W.type`${t} must be a function or null, got ${typeof e}`;ln(e,t)}}function un(e){let{forwardTo:t,defaultParams:n,defaultSearch:r,decodeParams:i,encodeParams:a,canActivate:o,canDeactivate:s}=e;if(t!=null){if(typeof t!=`string`&&typeof t!=`function`)throw W.type`forwardTo must be a string, function, or null, got ${y(t)}`;typeof t==`function`&&ln(t,`forwardTo callback`)}dn(n,`defaultParams`),dn(r,`defaultSearch`),X(i,`decodeParams`),X(a,`encodeParams`),X(o,`canActivate`),X(s,`canDeactivate`)}function dn(e,t){if(e!=null&&(typeof e!=`object`||Array.isArray(e)))throw W.type`${t} must be an object or null, got ${y(e)}`}function fn(e){if(!o(e)||e===``)throw Zt.type`route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`}function pn(e){let t=new Set;return function(r,i){let a=(0,n.findMisChanneledKey)(i,e(r));if(a===void 0)return;let o=`${r} ${a}`;t.has(o)||(t.add(o),console.warn(`[router] Route "${r}" declares \`${a}\` as a query param, but it was given in the \`params\` bag — the path channel. The URL is built without it, so the href does not match what you asked for; a plain click throws, but a ⌘-click, a copied link and server-rendered markup all follow the wrong URL in silence. Pass it in \`search\` instead.`))}}function mn(e){if(!o(e))throw Xt.type`path must be a string, got ${typeof e}`}function hn(e){if(!o(e))throw Yt.type`nodeName must be a string, got ${typeof e}`}function gn(e,t,r,i,a){if(a){let e=t;for(let t of a.split(`.`))if(e=e.children.get(t),!e)throw G.ref`Parent route "${a}" does not exist`}let o=new Set,s=new Map;for(let r of e)(0,n.validateRoute)(r,`addRoute`,t,a??``,o,s);Ke(e,i,r,a)}function _n(e,t,n){let r=new Set(n.getUrlParams(e)),i=n.getUrlParams(t).filter(e=>!r.has(e));if(i.length>0)throw W.plain`forwardTo target "${t}" requires params [${i.join(`, `)}] that are not available in source route "${e}"`}function vn(e,t,n){let i={...n,[e]:t};(0,r.resolveForwardChain)(e,i)}function yn(e,t,n,r){if(!n.hasRoute(e))throw W.ref`route "${e}" does not exist`;if(t!=null&&typeof t==`string`){if(!n.hasRoute(t))throw W.plain`forwardTo target "${t}" does not exist`;_n(e,t,n),vn(e,t,r)}}const Z=(0,t.raiser)(`router`,`makeState`),bn=Object.entries;function xn(e,t,n){if(!o(e))throw Z.type`Invalid name: ${y(e)}. Expected string.`;if(t!==void 0&&!m(t))throw Z.type`Invalid params: ${y(t)}. Expected plain object.`;if(n!==void 0&&!o(n))throw Z.type`Invalid path: ${y(n)}. Expected string.`}function Sn(){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 Cn(){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 wn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Tn(e,t){let n={params:{...t.params},search:{...t.search}};if(e===void 0)return n;let r=e(n),i=r.params??n.params,a=r.search??n.search;return wn(i)&&wn(a)?{params:i,search:a}:void 0}function En(e,t){try{return Tn(e,t)}catch{return}}function Q(e){return new Map(bn(e).filter(([,e])=>e!==void 0))}function Dn(e){return Array.isArray(e)?e.some(e=>Dn(e)):typeof e==`object`&&!!e}function On(e,t){try{return e(t)}catch{return}}function kn(e,t){let n=n=>{let r=Q(e[n]);return new Map([...Q(t[n])].filter(([e])=>!r.has(e)))};return{params:n(`params`),search:n(`search`)}}function An(e,t){return Object.fromEntries(bn(e).filter(([e])=>!t.has(e)))}function jn(e,t,r){if(r.params.size+r.search.size===0)return r;try{let i=t(e.name,An(e.params,r.params),An(e.search,r.search)),a=e=>{let t=Q(i[e]??{});return new Map([...r[e]].filter(([e,r])=>t.has(e)&&(0,n.areParamValuesEqual)(t.get(e),r)))};return{params:a(`params`),search:a(`search`)}}catch{return{params:new Map,search:new Map}}}function Mn(e,t,r,i){let a=En(e.codec.encode,{...e.state,[t]:{...e.state[t],[r]:i}});return a!==void 0&&(0,n.areParamValuesEqual)(e.encoded[t][r],a[t][r])}function Nn(e,t,n){return e.credited[t].has(n)?void 0:`added`}function Pn(e,t,r,i,a){if(!Dn(a))return(0,n.areParamValuesEqual)(i,a)?void 0:`changed`;if(!Mn(e,t,r,a))return`changed`;if(!(0,n.areParamValuesEqual)(i,a))return(0,n.areParamValuesEqual)(a,e.readAgain()?.[t][r])?`undecoded`:`keyless`}function Fn(e,t){let n=Q(e.state[t]),r=Q(e.back[t]),i=[];for(let[a,o]of r){let r=n.has(a)?Pn(e,t,a,n.get(a),o):Nn(e,t,a);r!==void 0&&i.push([t,a,r])}for(let a of n.keys())!r.has(a)&&(t===`search`||e.pathSlots.includes(a))&&i.push([t,a,`dropped`]);return i}function In(e,t,n,r,i){let a=r(e.path);if(a?.name!==e.name)return[];let o=Tn(t.encode,e);if(o===void 0)return[];let s,c={state:e,codec:t,pathSlots:n,encoded:o,back:a,readAgain:()=>(s??={state:On(r,e.path)},s.state),credited:jn(a,i,kn(e,a))};return[...Fn(c,`params`),...Fn(c,`search`)]}function Ln(e){return e.decode===void 0?`The route has an encodeParams and no decodeParams to undo it.`:e.encode===void 0?`With no encodeParams, decodeParams must return each value so that it prints as the URL shows it.`:`decodeParams must undo encodeParams.`}function Rn(e,t,n,r,i){let a=`Route "${e}": its codec`,o=`${a} changes "${n}" in state.${t}, so a link and a reload of the same URL commit different values.`;switch(r){case`added`:return`${a} adds "${n}" to state.${t}, so a link commits a state without it and a reload of the same URL commits one with it. Derive "${n}" in a forwardState interceptor instead: navigate and matchPath both run it.`;case`changed`:return`${o} ${Ln(i)}`;case`undecoded`:return`${o} encodeParams prints both as one piece of the URL, so a link must pass the value decodeParams returns for that piece.`;case`keyless`:return`${o} Two reloads of one URL decode values that never compare equal: give the value a key — a Date, or a plain object JSON.stringify prints in full.`;case`dropped`:return`${a} drops "${n}" from state.${t}, so a reload of the URL a link builds loses it. ${Ln(i)}`}}function zn(e,t,n){let r=new Set;return function(i,a,o){let s;try{s=In(i,a,o,t,n)}catch{return}for(let[t,n,o]of s){let s=`${i.name} ${t} ${n}`;r.has(s)||(r.add(s),e.warn(`router`,Rn(i.name,t,n,o,a)))}}}const Bn=(0,t.raiser)(`validation-plugin`),Vn=(0,t.raiser)(`router`,`addRoute`),$=(0,t.raiser)(`router`,`areStatesEqual`);function Hn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Un(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 Wn={hasRoute:()=>!1,getUrlParams:()=>[]};function Gn(e){return{tree:{...e,children:new Map,nonAbsoluteChildren:[]},lookup:Wn,forwardMap:{}}}function Kn(e,t){let n=[];for(let r of e.getTree().children.keys())n.push(t.get(r));return n}function qn(e,t,n,r){let a=pn(t=>e.getDeclaredQueryNames(t));return{routes:{validateBuildPathArgs(e,t){fn(e),a(e,t)},validateMatchPathArgs:mn,validateIsActiveRouteArgs(e,t,n,r){sn(e,t,n,r),a(e,t)},validateShouldUpdateNodeArgs:hn,validateStateBuilderArgs:Y,validateRouteName(e,t){v(e,t)},validateSetRootPathArgs:tn},options:{validateOptions:wt,validateResolvedDefaultRoute(e){qt(e,t)}},dependencies:{validateDependencyName:we,validateSetDependencyArgs(e,t,n){Te(e)},validateDependenciesObject(t,n){Ee(t,n),De(t,e.getDependencyKeys(),e.getResolvedLimits().maxDependencies,n)},validateDependencyExists(e,t){Oe(t,e)},validateDependencyCount(t,n,r){ke(t,n,r,e.logger)},validateCloneArgs:Ae,warnOverwrite(t,n){je(t,n,e.logger)},warnBatchOverwrite(t,n){Me(t,n,e.logger)},warnRemoveNonExistent(t){Ne(t,e.logger)}},plugins:{validatePluginLimit(e,t,n){Dt(e,t,n?.maxPlugins)},validateNoDuplicatePlugins:Ot,validatePluginKeys:At,validateCountThresholds(t){kt(t,e.getOptions().limits?.maxPlugins??i.maxPlugins,e.logger)},warnBatchDuplicates(){jt(e.logger)},warnPluginMethodType(t){Mt(t,e.logger)}},lifecycle:{validateHandlerLimit(t,n){Je(t,n,e.getOptions().limits?.maxLifecycleHandlers??i.maxLifecycleHandlers)},validateCountThresholds(t,n){Ye(t,n,e.getOptions().limits?.maxLifecycleHandlers??i.maxLifecycleHandlers,e.logger)},warnOverwrite(t,n,r){Xe(t,n,r,e.logger)},warnAsyncGuardSync(t,n){Ze(t,n,e.logger)},warnNonBooleanGuardSync(t,n,r){$e(t,n,r,e.logger)},warnNonBooleanGuard(t,n){et(t,n,e.logger)}},navigation:{validateNavigateToDefaultArgs(t){ot(t),n.check(e.logger)},validateNavigateToStateArgs:st,validateNavigationOptions:ct,validateParamsShape:j,validateSearch:N,validateStartArgs:dt},state:{validateMakeStateArgs:xn,reportDroppedQueryKey:Sn(),reportUndeclaredParamKey:Cn(),reportCodecRoundTrip:zn(e.logger,r,e.forwardState),validateAreStatesEqualArgs(e,t,n){if(!_(e))throw $.type`Invalid state1: ${y(e)}. Expected State object.`;if(!_(t))throw $.type`Invalid state2: ${y(t)}. Expected State object.`;if(n!==void 0&&!s(n))throw $.type`Invalid ignoreQueryParams: ${y(n)}. Expected boolean.`;if(n===!1){if(!Hn(e.search))throw $.type`Invalid state1.search: ${y(e.search)}. Expected a plain object.`;if(!Hn(t.search))throw $.type`Invalid state2.search: ${y(t.search)}. Expected a plain object.`}}},eventBus:{validateListenerArgs(e,t){Le(e,t)},validateCountThresholds(t,n,r){let a=e.getOptions().limits?.maxListeners??i.maxListeners;Re(t,n,r,e.logger,a)}}}}function Jn(){return t=>{let r=(0,n.getInternals)(t),i=(0,e.getPluginApi)(t);if(t.isActive())throw Bn.code(`VALIDATION_PLUGIN_AFTER_START`)`must be registered before router.start()`;if(r.validator!==null)throw Bn.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 _e;a.watch(i.getAdoptedOrigins());let o=e=>r.matchPath(e,{...i.getOptions(),rewritePathOnMatch:!1}),s=Un(i),c=qn(i,s,a,o),l=()=>{r.validator===c&&(r.validator=null)};r.validator=c;try{let n=Kn(i,(0,e.getRoutesApi)(t)),a=i.getForwardMap(),o=i.getResolvedLimits(),c=i.getOptions();Rt(n),zt(a,s),Vt(n),Ht(a,s),Ut(r.dependenciesGetStore().dependencies,o),Wt(c,i.getDependencyKeys().length,o.maxDependencies),r.validator.options.validateOptions(c,`constructor (retrospective)`),typeof c.defaultRoute==`string`&&Kt(c.defaultRoute,s)}catch(e){throw l(),e}let u=i.addInterceptor(`start`,(e,t)=>{try{Jt(i.getExternalGuardNames(),s,i.logger)}catch{}return e(t)}),ee=i.addCheck(`buildPath:params`,e=>{M(e,`buildPath`)}),te=i.addCheck(`buildPathResolved:params`,e=>{M(e,`buildPathResolved`)}),ne=i.addCheck(`canNavigateTo:entry`,(e,t,n)=>{v(e,`canNavigateTo`),j(t,`canNavigateTo`),N(n,`canNavigateTo`)}),re=i.addCheck(`canNavigateTo:params`,e=>{M(e,`canNavigateTo`)}),ie=i.addCheck(`navigate:entry`,(e,t,n,r)=>{at(e),j(t,`navigate`),N(n,`navigate`),ct(r,`navigate`)}),d=i.addCheck(`navigate:params`,e=>{M(e,`navigate`)}),f=(e,t)=>{for(let n of e){let e=w(t,n.name);nn(n),rn(n,e),n.children!==void 0&&f(n.children,e)}},p=(e,t,n,r)=>{if(f(e,typeof n==`string`&&s.hasRoute(n)?n:void 0),n!==void 0&&(on(n),!s.hasRoute(n)))throw Vn.ref`Parent route "${n}" does not exist`;$t(e,t),an(e,n);let i=r();gn(e,i.tree,i.lookup,i.forwardMap,n)},ae=i.addCheck(`addRoute:batch`,(e,t)=>{p(e,`addRoute`,t,()=>({tree:i.getTree(),lookup:s,forwardMap:i.getForwardMap()}))}),oe=i.addCheck(`replaceRoutes:batch`,e=>{p(e,`replaceRoutes`,void 0,()=>Gn(i.getTree()))}),m=i.addCheck(`removeRoute:entry`,e=>{en(e),q(e,`removeRoute`)}),se=i.addCheck(`updateRoute:entry`,(e,t)=>{let n=t;cn(e,t),q(e,`updateRoute`),un({forwardTo:n.forwardTo,defaultParams:n.defaultParams,defaultSearch:n.defaultSearch,decodeParams:n.decodeParams,encodeParams:n.encodeParams,canActivate:n.canActivate,canDeactivate:n.canDeactivate}),yn(e,n.forwardTo,s,i.getForwardMap())}),ce=i.addCheck(`hasRoute:entry`,e=>{v(e,`hasRoute`)}),le=i.addCheck(`getRoute:entry`,e=>{v(e,`getRoute`)}),ue=i.addCheck(`forwardState:entry`,(e,t,n)=>{Y(e,t,`forwardState`),N(n,`forwardState`)}),h=i.addCheck(`buildNavigationState:state`,(e,t,n)=>{N(n,`buildNavigationState`),Y(e,t,`buildNavigationState`)}),g=i.addCheck(`addActivateGuard:entry`,(e,t)=>{v(e,`addActivateGuard`),qe(t,`addActivateGuard`)}),de=i.addCheck(`addDeactivateGuard:entry`,(e,t)=>{v(e,`addDeactivateGuard`),qe(t,`addDeactivateGuard`)}),fe=i.addCheck(`removeActivateGuard:entry`,e=>{v(e,`removeActivateGuard`)}),_=i.addCheck(`removeDeactivateGuard:entry`,e=>{v(e,`removeDeactivateGuard`)}),y=i.subscribeDiagnostic(`PLUGIN_AFTER_START`,e=>{Nt(e,i.logger)});return{teardown(){ee(),te(),ne(),re(),ie(),d(),ae(),oe(),m(),se(),ce(),le(),ue(),h(),g(),de(),fe(),_(),y(),u(),l()}}}}exports.validationPlugin=Jn;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|