@real-router/validation-plugin 0.13.29 → 0.13.30
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 +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@real-router/core"),t=require("@real-router/core/validation"),n=require("@real-router/core/utils");function r(e){return typeof e==`string`}function i(e){return typeof e==`boolean`}function a(e,t){return e in t}function o(e){if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function s(e,t){let n=Array.isArray(e)?e:Object.values(e);for(let e of n)t.push(e)}function c(e){let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}var l=class{container;constructor(e){this.container=e}};function u(e,t,n,r){return n.has(e)?!1:r.has(e)?!0:o(e)?(n.add(e),t.push(new l(e)),s(e,t),!0):!1}function ee(e){let t=[e],n=new WeakSet,r=new WeakSet;for(;t.length>0;){let e=t.pop();if(e instanceof l){n.delete(e.container),r.add(e.container);continue}if(e!=null){if(typeof e==`object`){if(!u(e,t,n,r))return!1;continue}if(!c(e))return!1}}return!0}function te(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}function d(e){try{return ne(e)}catch{return!1}}function ne(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);if(t!==null&&t!==Object.prototype)return!1;let n=!1;for(let t in e){if(!Object.hasOwn(e,t))continue;let r=e[t];if(!te(r)){let e=typeof r;if(e===`function`||e===`symbol`)return!1;n=!0;break}}return!n||ee(e)}const re=[`replace`,`reload`,`force`,`forceDeactivate`,`redirected`];function ie(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;for(let e of re){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 ae=/\S/,f=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function p(e,t){return TypeError(`[router.${e}] ${t}`)}function oe(e){return typeof e==`string`?e===``?!0:e.length>1e4?!1:e.startsWith(`@@`)?!0:f.test(e):!1}function m(e){return oe(e.name)&&typeof e.path==`string`&&d(e.params)}function h(e){return typeof e!=`object`||!e?!1:m(e)}function g(e,t){if(typeof e!=`string`)throw p(t,`Route name must be a string, got ${typeof e}`);if(e!==``){if(!ae.test(e))throw p(t,`Route name cannot contain only whitespace`);if(e.length>1e4)throw p(t,`Route name exceeds maximum length of 10000 characters. This is a technical safety limit.`);if(!e.startsWith(`@@`)&&!f.test(e))throw p(t,`Invalid route name "${e}". Each segment must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens. Segments are separated by dots (e.g., "users.profile").`)}}function _(e){if(e===null)return`null`;if(Array.isArray(e))return`array[${e.length}]`;if(typeof e==`object`){try{let t=e.constructor;if(typeof t==`function`&&t.name!==`Object`)return t.name||`object`}catch{}return`object`}return typeof e}function v(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}const y=Object.keys,b=Object.getOwnPropertyDescriptor,se=Object.getPrototypeOf,ce=Object;function x(e){if(!e||typeof e!=`object`)return!1;let t=se(e);return t===null||t.constructor===ce}function le(e,t){if(typeof e!=`string`)throw TypeError(`[router.${t}] dependency name must be a string, got ${typeof e}`)}function ue(e){if(typeof e!=`string`)throw TypeError(`[router.setDependency] dependency name must be a string, got ${typeof e}`)}function de(e,t){if(!x(e))throw TypeError(`[router.${t}] Invalid argument: expected plain object, received ${_(e)}`);for(let n of y(e))if(b(e,n)?.get)throw TypeError(`[router.${t}] Getters not allowed: "${n}"`)}function fe(e,t){if(e===void 0)throw ReferenceError(`[router.getDependency] dependency "${t}" not found`)}function pe(e,t,n){let r=e,i=r.limits?.maxDependencies??100;if(i===0)return;let a=Object.keys(r.dependencies).length,{warn:o,error:s}=v(i);if(a>=i)throw RangeError(`[router.${t}] Dependency limit exceeded (${i}). Current: ${a}.`);a===s?n.error(`router.${t}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${i}.`):a===o&&n.warn(`router.${t}`,`${a} dependencies registered. Consider if all are necessary.`)}function me(e){if(e!==void 0){if(!x(e))throw TypeError(`[cloneRouter] Invalid dependencies: expected plain object or undefined, received ${typeof e}`);for(let t of y(e))if(b(e,t)?.get)throw TypeError(`[cloneRouter] Getters not allowed in dependencies: "${t}"`)}}function he(e,t,n){n.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function ge(e,t,n){n.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function _e(e,t){t.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const ve=new Set([`$start`,`$stop`,`$$start`,`$$leaveApprove`,`$$cancel`,`$$success`,`$$error`]);function ye(e){if(!ve.has(e))throw TypeError(`[router.addEventListener] Invalid event name: ${String(e)}. Must be one of: $start, $stop, $$start, $$leaveApprove, $$cancel, $$success, $$error`)}function be(e,t){if(ye(e),typeof t!=`function`)throw TypeError(`[router.addEventListener] callback must be a function, got ${typeof t}`)}function xe(e,t,n,r,i=1e4){if(i===0)return;let{warn:a,error:o}=v(i);e>=o?r.error(`router.${n}`,`${e} listeners registered for "${t}"! This is excessive. Hard limit at ${i}.`):e>=a&&r.warn(`router.${n}`,`${e} listeners registered for "${t}". Consider whether all are necessary — a growing count usually means a missing unsubscribe.`)}function Se(e,t){if(!i(e)&&typeof e!=`function`)throw TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${_(e)}`)}function Ce(e,t,n=200){if(n!==0&&e>=n)throw RangeError(`[router.${t}] Lifecycle handler limit exceeded (${n}). This indicates too many routes with individual handlers. Consider using plugins for cross-cutting concerns.`)}function we(e,t,n,r){if(n===0)return;let{warn:i,error:a}=v(n);e>=a?r.error(`router.${t}`,`${e} lifecycle handlers registered! This is excessive. Hard limit at ${n}.`):e>=i&&r.warn(`router.${t}`,`${e} lifecycle handlers registered. Consider consolidating logic.`)}function S(e,t,n,r){r.warn(`router.${n}`,`Overwriting existing ${t} handler for route "${e}"`)}function C(e,t,n){n.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}function w(e){if(typeof e!=`string`)throw TypeError(`[router.navigate] Invalid route name: expected string, got ${_(e)}`)}function T(e){if(e!==void 0&&(typeof e!=`object`||!e))throw TypeError(`[router.navigateToDefault] Invalid options: ${_(e)}. Expected NavigationOptions object.`)}function E(e){if(typeof e!=`object`||!e)throw TypeError(`[router.navigateToState] Invalid state: ${_(e)}. Expected State object.`);let t=e;if(!r(t.name))throw TypeError(`[router.navigateToState] Invalid state.name: ${_(t.name)}. Expected string.`);if(!d(t.params))throw TypeError(`[router.navigateToState] Invalid state.params: ${_(t.params)}. Expected plain object.`);if(!r(t.path))throw TypeError(`[router.navigateToState] Invalid state.path: ${_(t.path)}. Expected string.`)}function D(e,t){if(!ie(e))throw TypeError(`[router.${t}] Invalid options: ${_(e)}. Expected NavigationOptions object.`)}const O=/[\u0000-\u001F\u007F]/;function k(e,t){for(let n in e){if(!Object.hasOwn(e,n))continue;let r=e[n],i=typeof r;if(i===`symbol`||i===`bigint`)throw TypeError(`[router.${t}] param "${n}" cannot be a ${i} — it does not round-trip through the URL path. Use a string, number, or boolean.`);if(i===`string`&&O.test(r))throw TypeError(`[router.${t}] param "${n}" must not contain control characters (NUL / C0 / DEL) — they corrupt the URL path.`)}}function Te(e,t){if(e!==void 0&&(typeof e==`object`&&e&&!Array.isArray(e)&&k(e,t),!d(e)))throw TypeError(`[router.${t}] params must be a plain object, got ${_(e)}`)}function Ee(e){if(e!==void 0&&typeof e!=`string`)throw TypeError(`[router.start] path must be a string, got ${_(e)}.`);if(typeof e==`string`){if(O.test(e))throw TypeError(`[router.start] path must not contain control characters (NUL / C0 / DEL).`);if(e!==``&&!e.startsWith(`/`))throw TypeError(`[router.start] path must start with "/", got "${e}".`)}}const A={trailingSlash:[`strict`,`never`,`always`,`preserve`],queryParamsMode:[`default`,`strict`,`loose`],urlParamsEncoding:[`default`,`uri`,`uriComponent`,`none`]},j={arrayFormat:[`none`,`brackets`,`index`,`comma`],booleanFormat:[`none`,`auto`,`empty-true`],nullFormat:[`default`,`hidden`],numberFormat:[`none`,`auto`]},De=new Set([`defaultRoute`,`defaultParams`,`defaultSearch`,`trailingSlash`,`caseSensitive`,`queryParamsMode`,`queryParams`,`urlParamsEncoding`,`allowNotFound`,`rewritePathOnMatch`,`logger`,`limits`]),M={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 Oe(e,t,n){if(typeof t!=`number`||!Number.isInteger(t))throw TypeError(`[router.${n}] limit "${e}" must be an integer, got ${String(t)}`);let r=M[e];if(t<r.min||t>r.max)throw RangeError(`[router.${n}] limit "${e}" must be between ${r.min} and ${r.max}, got ${t}`)}function ke(e,t){if(!e||typeof e!=`object`||e.constructor!==Object)throw TypeError(`[router.${t}] invalid limits: expected plain object, got ${typeof e}`);for(let[n,r]of Object.entries(e)){if(!Object.hasOwn(M,n))throw TypeError(`[router.${t}] unknown limit: "${n}"`);r!==void 0&&Oe(n,r,t)}let{warnListeners:n,maxListeners:r}=e;if(typeof n==`number`&&typeof r==`number`&&r>0&&n>r)throw RangeError(`[router.${t}] "limits.warnListeners" (${n}) must not exceed "limits.maxListeners" (${r}) — the warning channel would be unreachable`)}function N(e,t,n,r){if(e!==void 0&&(typeof e!=`string`||!n.includes(e))){let i=n.map(e=>`"${e}"`).join(`, `);throw TypeError(`[router.${r}] Invalid "${t}": "${typeof e==`string`?e:`(${typeof e})`}". Must be one of: ${i}`)}}function Ae(e,t){if(e!==void 0&&typeof e!=`string`&&typeof e!=`function`)throw TypeError(`[router.${t}] Invalid "defaultRoute": expected string or function, got ${typeof e}`)}function P(e,t,n){if(e!==void 0&&typeof e!=`function`&&(!e||typeof e!=`object`||Array.isArray(e)||e.constructor!==Object))throw TypeError(`[router.${n}] Invalid "${t}": expected plain object or function, got ${typeof e}`)}function je(e,t){if(e===void 0)return;if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`[router.${t}] Invalid "queryParams": expected plain object`);let n=e;for(let[e,r]of Object.entries(n)){if(!a(e,j))throw TypeError(`[router.${t}] Invalid "queryParams.${e}": unknown option`);N(r,`queryParams.${e}`,j[e],t)}}function Me(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`[router.${t}] Invalid options: expected plain object`);let n=e;for(let e of Object.keys(n))if(!De.has(e))throw TypeError(`[router.${t}] Unknown option: "${e}"`);if(Ae(n.defaultRoute,t),P(n.defaultParams,`defaultParams`,t),P(n.defaultSearch,`defaultSearch`,t),N(n.trailingSlash,`trailingSlash`,A.trailingSlash,t),N(n.queryParamsMode,`queryParamsMode`,A.queryParamsMode,t),N(n.urlParamsEncoding,`urlParamsEncoding`,A.urlParamsEncoding,t),n.allowNotFound!==void 0&&typeof n.allowNotFound!=`boolean`)throw TypeError(`[router.${t}] Invalid "allowNotFound": expected boolean, got ${typeof n.allowNotFound}`);if(n.rewritePathOnMatch!==void 0&&typeof n.rewritePathOnMatch!=`boolean`)throw TypeError(`[router.${t}] Invalid "rewritePathOnMatch": expected boolean, got ${typeof n.rewritePathOnMatch}`);if(n.caseSensitive!==void 0&&typeof n.caseSensitive!=`boolean`)throw TypeError(`[router.${t}] Invalid "caseSensitive": expected boolean, got ${typeof n.caseSensitive}`);je(n.queryParams,t),n.limits!==void 0&&ke(n.limits,t)}const F=`router.usePlugin`,Ne={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function Pe(e,t,n=50){if(n!==0&&e+t>n)throw RangeError(`[router.usePlugin] Plugin limit exceeded (${n}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating plugins.`)}function Fe(e,t){if(t.includes(e))throw Error(`[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.`)}function Ie(e,t,n){if(t===0)return;let{warn:r,error:i}=v(t);e>=i?n.error(F,`${e} plugins registered! This is excessive. Hard limit at ${t}.`):e>=r&&n.warn(F,`${e} plugins registered. Consider if all are necessary.`)}function Le(e){for(let t in e)if(!(t===`teardown`||Object.hasOwn(Ne,t)))throw TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}function Re(e){e.warn(F,`Duplicate factory in batch, will be registered once`)}function ze(e,t){t.warn(F,`Property '${e}' is not a function, skipping`)}function Be(e,t){e===`onStart`&&t.warn(F,`Router already started, onStart will not be called`)}function Ve(e,t){let n=[`start`,`buildPath`,`forwardState`];if(typeof e!=`string`||!n.includes(e))throw TypeError(`[router.addInterceptor] Invalid method: "${String(e)}". Must be one of: ${n.join(`, `)}`);if(typeof t!=`function`)throw TypeError(`[router.addInterceptor] interceptor must be a function, got ${typeof t}`)}function I(e,t){if(!e||typeof e!=`object`)throw TypeError(`[validation-plugin] ${t}: store must be an object`);let n=e;if(!Array.isArray(n.definitions))throw TypeError(`[validation-plugin] ${t}: store.definitions must be an array`);if(!n.config||typeof n.config!=`object`)throw TypeError(`[validation-plugin] ${t}: store.config must be an object`);if(!n.tree||typeof n.tree!=`object`)throw TypeError(`[validation-plugin] ${t}: store.tree must be an object`);return n}function L(e,t,n=``){for(let r of e){let e=n?`${n}.${r.name}`:r.name;t(r,e),r.children&&L(r.children,t,e)}}function R(e,t){let n=t.split(`.`),r=e;for(let e of n)if(r=r.children.get(e),!r)return!1;return!0}function He(t,n){try{return(0,e.resolveForwardChain)(t,n)}catch(e){throw Error(`[validation-plugin] ${e.message}`,{cause:e})}}function z(e){let t=new Set;for(let n of e){for(let e of n.paramMeta.urlParams)t.add(e);for(let e of n.paramMeta.spatParams)t.add(e)}return t}function B(e,t,n){let r=e;if(r.constructor.name===`AsyncFunction`||r.toString().includes(`__awaiter`))throw TypeError(`[validation-plugin] Route "${n}" ${t} cannot be async`)}function Ue(e){L(I(e,`validateExistingRoutes`).definitions,(e,t)=>{if(typeof e.name!=`string`||!e.name)throw TypeError(`[validation-plugin] validateExistingRoutes: route has invalid name: ${e.name}`);if(typeof e.path!=`string`)throw TypeError(`[validation-plugin] validateExistingRoutes: route "${t}" has non-string path (${typeof e.path})`)})}function We(e){let{config:t,tree:n,matcher:r}=I(e,`validateForwardToConsistency`);for(let[e,i]of Object.entries(t.forwardMap)){if(!R(n,i))throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${i}" does not exist in tree (source route: "${e}")`);let t=r.getSegmentsByName(e),a=r.getSegmentsByName(i);if(t&&a){let n=z(t),r=[...z(a)].filter(e=>!n.has(e));if(r.length>0)throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${i}" requires params [${r.join(`, `)}] not available in source route "${e}"`)}}for(let e of Object.keys(t.forwardMap))He(e,t.forwardMap)}function Ge(e){let{config:t}=I(e,`validateRoutePropertiesStore`);for(let[e,n]of Object.entries(t.decoders)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" decoder must be a function, got ${typeof n}`);B(n,`decoder`,e)}for(let[e,n]of Object.entries(t.encoders)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" encoder must be a function, got ${typeof n}`);B(n,`encoder`,e)}for(let[e,n]of Object.entries(t.defaultParams))if(typeof n!=`object`||!n||Array.isArray(n))throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" defaultParams must be a plain object, got ${Array.isArray(n)?`array`:typeof n}`);for(let[e,n]of Object.entries(t.forwardFnMap)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" forwardTo callback must be a function, got ${typeof n}`);B(n,`forwardTo callback`,e)}}function Ke(e){let{config:t,tree:n}=I(e,`validateForwardToTargetsStore`);for(let[e,r]of Object.entries(t.forwardMap))if(!R(n,r))throw Error(`[validation-plugin] validateForwardToTargetsStore: forwardTo target "${r}" does not exist for route "${e}"`)}function qe(e){if(!e||typeof e!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps must be an object`);let t=e;if(!t.dependencies||typeof t.dependencies!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.dependencies must be an object`);let n=t.dependencies;for(let e of Object.keys(n))if(Object.getOwnPropertyDescriptor(n,e)?.get)throw TypeError(`[validation-plugin] validateDependenciesStructure: dependency "${e}" must not use a getter`);if(!t.limits||typeof t.limits!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits must be an object`);let r=t.limits;for(let e of[`maxDependencies`,`maxPlugins`,`maxListeners`,`warnListeners`,`maxLifecycleHandlers`])if(!Number.isInteger(r[e]))throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits.${e} must be an integer, got ${String(r[e])}`)}function Je(e){let t=e&&typeof e==`object`?e:{};return t.limits&&typeof t.limits==`object`?t.limits:{}}function Ye(e,t){if(!e||typeof e!=`object`)return;let n=e,r=n.dependencies,i=n.limits;if(!r||typeof r!=`object`||!i||typeof i!=`object`)return;let a=Object.keys(r).length,o=i,s=t.maxDependencies,c=o.maxDependencies,l=typeof s==`number`?s:c;if(typeof l==`number`&&l>0&&a>l)throw RangeError(`[validation-plugin] validateLimitsConsistency: dependency count (${a}) exceeds maxDependencies limit (${l})`)}function Xe(e,t){Ye(t,Je(e))}function V(e,t){if(!(typeof e!=`string`||!e)&&!R(I(t,`validateResolvedDefaultRoute`).tree,e))throw Error(`[validation-plugin] defaultRoute resolved to non-existent route: "${e}"`)}function Ze(e,t){if(e!==void 0&&typeof e==`function`){let n=e.constructor.name===`AsyncFunction`,r=e.toString().includes(`__awaiter`);if(n||r)throw TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${t}". Async functions break matchPath/buildPath.`)}}function H(e,t){if(e.canActivate!==void 0&&typeof e.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function for route "${t}", got ${_(e.canActivate)}`);if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${_(e.canDeactivate)}`);if(e.defaultParams!==void 0){let n=e.defaultParams;if(typeof n!=`object`||!n||Array.isArray(n))throw TypeError(`[router.addRoute] defaultParams must be an object for route "${t}", got ${_(e.defaultParams)}`)}if(e.decodeParams?.constructor.name===`AsyncFunction`)throw TypeError(`[router.addRoute] decodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if(e.encodeParams?.constructor.name===`AsyncFunction`)throw TypeError(`[router.addRoute] encodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if(Ze(e.forwardTo,t),e.children)for(let n of e.children)H(n,`${t}.${n.name}`)}function Qe(e){let t=new Set,n=/[*:]([A-Z_a-z]\w*)/g,r;for(;(r=n.exec(e))!==null;)t.add(r[1]);return t}function U(e){let t=new Set;for(let n of e)for(let e of Qe(n))t.add(e);return t}function W(e,t,n=``,r=[]){for(let i of e){let e=n?`${n}.${i.name}`:i.name,a=[...r,i.path];if(e===t)return a;if(i.children&&t.startsWith(`${e}.`))return W(i.children,t,e,a)}throw Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function G(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 G(r.children,e))n.add(t)}return n}function K(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 K(r.children,e))n.set(t,i)}return n}function q(e){let t=new Set;for(let n of e){for(let e of n.paramMeta.urlParams)t.add(e);for(let e of n.paramMeta.spatParams)t.add(e)}return t}function $e(e,t,n,r){return t?q(n.getSegmentsByName(e)??[]):U(W(r,e))}const et=new Set;function tt(e,t,n,r,i,a){let o=i.hasRoute(t),s=r.has(t);if(!o&&!s)throw ReferenceError(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);let c=new Set([...a,...U(W(n,e))]),l=[...$e(t,o,i,n)].filter(e=>!c.has(e));if(l.length>0)throw Error(`[router.addRoute] forwardTo target "${t}" requires params [${l.join(`, `)}] that are not available in source route "${e}"`)}function nt(t,r,i,a){let o=G(t),s=a?new Set([...o].map(e=>`${a}.${e}`)):o,c=a?q(i.getSegmentsByName(a)):et,l=K(t),u={...r};for(let[e,t]of l)(0,n.putField)(u,e,t);for(let[e,n]of l)tt(e,n,t,s,i,c);for(let t of Object.keys(u))(0,e.resolveForwardChain)(t,u)}function J(e,t){if(e.startsWith(`@@`))throw Error(`[router.${t}] Route name "${e}" uses the reserved "@@" prefix. Routes with this prefix are internal and cannot be modified through the public API.`)}function Y(e,t){for(let n of e)n&&typeof n==`object`&&typeof n.name==`string`&&(J(n.name,t),n.children&&Y(n.children,t))}function rt(e){g(e,`removeRoute`)}function it(e){if(typeof e!=`string`)throw TypeError(`[router.setRootPath] rootPath must be a string, got ${_(e)}`)}function X(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function at(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function, got ${_(t.canActivate)}`);if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function, got ${_(t.canDeactivate)}`)}function ot(e){let t=e,n=t.name;if(t.decodeParams!==void 0&&X(t.decodeParams))throw TypeError(`[router.addRoute] decodeParams cannot be async for route "${String(n)}"`);if(t.encodeParams!==void 0&&X(t.encodeParams))throw TypeError(`[router.addRoute] encodeParams cannot be async for route "${String(n)}"`);if(typeof t.forwardTo==`function`&&X(t.forwardTo))throw TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${String(n)}"`)}function st(e){for(let t of e){if(typeof t!=`object`||!t||Array.isArray(t))throw TypeError(`[router.addRoute] Route must be an object, got ${_(t)}`);H(t,t.name)}}function ct(e){if(typeof e!=`string`||e===``)throw TypeError(`[router.addRoute] parent option must be a non-empty string, got ${_(e)}`);g(e,`addRoute`)}function lt(e,t,n,i){if(!r(e))throw TypeError(`[router.isActiveRoute] name must be a string, got ${typeof e}`);if(t!==void 0&&!d(t))throw TypeError(`[router.isActiveRoute] params must be a plain object, got ${_(t)}`);if(n!==void 0&&typeof n!=`boolean`)throw TypeError(`[router.isActiveRoute] strictEquality must be a boolean, got ${typeof n}`);if(i!==void 0&&typeof i!=`boolean`)throw TypeError(`[router.isActiveRoute] ignoreQueryParams must be a boolean, got ${typeof i}`)}function ut(e,t,n){if(!r(e))throw TypeError(`[router.${n}] Invalid routeName: ${_(e)}. Expected string.`);if(!d(t))throw TypeError(`[router.${n}] Invalid routeParams: ${_(t)}. Expected plain object.`)}function dt(e,t){if(g(e,`updateRoute`),e===``)throw ReferenceError(`[router.updateRoute] Invalid name: empty string. Cannot update root node.`);if(t===null)throw TypeError(`[router.updateRoute] updates must be an object, got null`);if(typeof t!=`object`||Array.isArray(t))throw TypeError(`[router.updateRoute] updates must be an object, got ${_(t)}`)}function Z(e,t){if(e.constructor.name===`AsyncFunction`||e.toString().includes(`__awaiter`))throw TypeError(`[router.updateRoute] ${t} cannot be an async function`)}function Q(e,t){if(e!=null){if(typeof e!=`function`)throw TypeError(`[router.updateRoute] ${t} must be a function or null, got ${typeof e}`);Z(e,t)}}function ft(e,t,n,r){if(e!=null){if(typeof e!=`string`&&typeof e!=`function`)throw TypeError(`[router.updateRoute] forwardTo must be a string, function, or null, got ${_(e)}`);typeof e==`function`&&Z(e,`forwardTo callback`)}if(t!=null&&(typeof t!=`object`||Array.isArray(t)))throw TypeError(`[router.updateRoute] defaultParams must be an object or null, got ${_(t)}`);Q(n,`decodeParams`),Q(r,`encodeParams`)}function $(e){if(!r(e)||e===``)throw TypeError(`[router.buildPath] route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`)}function pt(e){if(!r(e))throw TypeError(`[router.matchPath] path must be a string, got ${typeof e}`)}function mt(e){if(!r(e))throw TypeError(`[router.shouldUpdateNode] nodeName must be a string, got ${typeof e}`)}function ht(e,n,r,i,a){if(a&&n){let e=n;for(let t of a.split(`.`))if(e=e.children.get(t),!e)throw ReferenceError(`[router.addRoute] Parent route "${a}" does not exist`)}let o=new Set,s=new Map;for(let r of e)(0,t.validateRoute)(r,`addRoute`,n,a??``,o,s);r&&i&&nt(e,i,r,a)}function gt(e){let t=new Set;for(let n of e)for(let e of n.paramMeta.urlParams)t.add(e);return t}function _t(e,t,n){let r=n.getSegmentsByName(e),i=n.getSegmentsByName(t),a=gt(r),o=[];for(let e of i)for(let t of e.paramMeta.urlParams)o.push(t);let s=o.filter(e=>!a.has(e));if(s.length>0)throw Error(`[router.addRoute] forwardTo target "${t}" requires params [${s.join(`, `)}] that are not available in source route "${e}"`)}function vt(t,n,r){(0,e.resolveForwardChain)(t,{...r.forwardMap,[t]:n})}function yt(e,t,n,r,i){if(!n(e))throw ReferenceError(`[router.updateRoute] route "${e}" does not exist`);if(t!=null&&typeof t==`string`){if(!n(t))throw Error(`[router.updateRoute] forwardTo target "${t}" does not exist`);_t(e,t,r),vt(e,t,i)}}function bt(e,t,n){if(!r(e))throw TypeError(`[router.makeState] Invalid name: ${_(e)}. Expected string.`);if(t!==void 0&&!d(t))throw TypeError(`[router.makeState] Invalid params: ${_(t)}. Expected plain object.`);if(n!==void 0&&!r(n))throw TypeError(`[router.makeState] Invalid path: ${_(n)}. Expected string.`)}function xt(){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 St(){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 Ct(e){return{routes:{validateBuildPathArgs:$,validateMatchPathArgs:pt,validateIsActiveRouteArgs:lt,validateShouldUpdateNodeArgs:mt,validateStateBuilderArgs:ut,validateAddRouteArgs(e){st(e)},validateRoutes(e,t,n){let r=t;ht(e,r.tree,r.matcher,r.config?.forwardMap,n)},validateRemoveRouteArgs:rt,validateUpdateRouteBasicArgs:dt,validateUpdateRoutePropertyTypes(e,t){let n=t;ft(n.forwardTo,n.defaultParams,n.decodeParams,n.encodeParams)},validateUpdateRoute(e,t,n){let r=n,i=t.forwardTo;yt(e,i,e=>r.matcher.hasRoute(e),r.matcher,r.config)},validateParentOption(e,t){ct(e);let n=t;for(let t of e.split(`.`)){let r=n.children.get(t);if(!r)throw ReferenceError(`[router.addRoute] Parent route "${e}" does not exist`);n=r}},validateRouteName(e,t){g(e,t)},throwIfInternalRoute(e,t){J(e,t)},throwIfInternalRouteInArray(e,t){Y(e,t)},validateSetRootPathArgs:it,guardRouteCallbacks:at,guardNoAsyncCallbacks:ot},options:{validateOptions:Me,validateResolvedDefaultRoute:V},dependencies:{validateDependencyName:le,validateSetDependencyArgs(e,t,n){ue(e)},validateDependenciesObject:de,validateDependencyExists(e,t){let n=t.dependencies?.[e];fe(n,e)},validateDependencyCount(t,n){pe(t,n,e.logger)},validateCloneArgs:me,warnOverwrite(t,n){he(t,n,e.logger)},warnBatchOverwrite(t,n){ge(t,n,e.logger)},warnRemoveNonExistent(t){_e(t,e.logger)}},plugins:{validatePluginLimit(e,t){Pe(e,1,t?.maxPlugins)},validateNoDuplicatePlugins:Fe,validatePluginKeys:Le,validateCountThresholds(t){Ie(t,e.getOptions().limits?.maxPlugins??50,e.logger)},warnBatchDuplicates(){Re(e.logger)},warnPluginMethodType(t){ze(t,e.logger)},warnPluginAfterStart(t){Be(t,e.logger)},validateAddInterceptorArgs:Ve},lifecycle:{validateHandler:Se,validateHandlerLimit(t,n){Ce(t,n,e.getOptions().limits?.maxLifecycleHandlers??200)},validateCountThresholds(t,n){we(t,n,e.getOptions().limits?.maxLifecycleHandlers??200,e.logger)},warnOverwrite(t,n,r){S(t,n,r,e.logger)},warnAsyncGuardSync(t,n){C(t,n,e.logger)}},navigation:{validateNavigateArgs:w,validateNavigateToDefaultArgs:T,validateNavigateToStateArgs:E,validateNavigationOptions:D,validateParams:Te,validateStartArgs:Ee},state:{validateMakeStateArgs:bt,reportDroppedQueryKey:xt(),reportUndeclaredParamKey:St(),validateAreStatesEqualArgs(e,t,n){if(!h(e))throw TypeError(`[router.areStatesEqual] Invalid state1: ${_(e)}. Expected State object.`);if(!h(t))throw TypeError(`[router.areStatesEqual] Invalid state2: ${_(t)}. Expected State object.`);if(n!==void 0&&!i(n))throw TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${_(n)}. Expected boolean.`)}},eventBus:{validateListenerArgs(e,t){be(e,t)},validateCountThresholds(t,n,r){let i=e.getOptions().limits?.maxListeners??1e4;xe(t,n,r,e.logger,i)}}}}function wt(){return n=>{let r=(0,t.getInternals)(n);if(n.isActive())throw new e.RouterError(`VALIDATION_PLUGIN_AFTER_START`,{message:`validation-plugin must be registered before router.start()`});r.validator=Ct(r);try{let e=r.routeGetStore(),t=r.dependenciesGetStore(),n=r.getOptions();Ue(e),We(e),Ge(e),Ke(e),qe(t),Xe(n,t),r.validator.options.validateOptions(n,`constructor (retrospective)`),typeof n.defaultRoute==`string`&&V(n.defaultRoute,e)}catch(e){throw r.validator=null,e}return{teardown(){r.validator=null}}}}exports.validationPlugin=wt;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@real-router/core"),t=require("@real-router/core/validation"),n=require("@real-router/core/utils");function r(e){return typeof e==`string`}function i(e){return typeof e==`boolean`}function a(e,t){return e in t}const o=Object.getPrototypeOf,s=Object.values,c=Object.hasOwn;function l(e){if(Array.isArray(e))return!0;let t=o(e);return t===null||t===Object.prototype}function u(e,t){let n=Array.isArray(e)?e:s(e);for(let e of n)t.push(e)}function ee(e){let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}var d=class{container;constructor(e){this.container=e}};function te(e,t,n,r){return n.has(e)?!1:r.has(e)?!0:l(e)?(n.add(e),t.push(new d(e)),u(e,t),!0):!1}function ne(e){let t=[e],n=new WeakSet,r=new WeakSet;for(;t.length>0;){let e=t.pop();if(e instanceof d){n.delete(e.container),r.add(e.container);continue}if(e!=null){if(typeof e==`object`){if(!te(e,t,n,r))return!1;continue}if(!ee(e))return!1}}return!0}function re(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)}function f(e){try{return ie(e)}catch{return!1}}function ie(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=o(e);if(t!==null&&t!==Object.prototype)return!1;let n=!1;for(let t in e){if(!c(e,t))continue;let r=e[t];if(!re(r)){let e=typeof r;if(e===`function`||e===`symbol`)return!1;n=!0;break}}return!n||ne(e)}const ae=[`replace`,`reload`,`force`,`forceDeactivate`,`redirected`];function oe(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;for(let e of ae){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 se=/\S/,p=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function m(e,t){return TypeError(`[router.${e}] ${t}`)}function ce(e){return typeof e==`string`?e===``?!0:e.length>1e4?!1:e.startsWith(`@@`)?!0:p.test(e):!1}function h(e){return ce(e.name)&&typeof e.path==`string`&&f(e.params)}function g(e){return typeof e!=`object`||!e?!1:h(e)}function _(e,t){if(typeof e!=`string`)throw m(t,`Route name must be a string, got ${typeof e}`);if(e!==``){if(!se.test(e))throw m(t,`Route name cannot contain only whitespace`);if(e.length>1e4)throw m(t,`Route name exceeds maximum length of 10000 characters. This is a technical safety limit.`);if(!e.startsWith(`@@`)&&!p.test(e))throw m(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 v(e){if(e===null)return`null`;if(Array.isArray(e))return`array[${e.length}]`;if(typeof e==`object`){try{let t=e.constructor;if(typeof t==`function`&&t.name!==`Object`)return t.name||`object`}catch{}return`object`}return typeof e}function y(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}const b=Object.keys,x=Object.getOwnPropertyDescriptor,le=Object.getPrototypeOf,ue=Object;function S(e){if(!e||typeof e!=`object`)return!1;let t=le(e);return t===null||t.constructor===ue}function de(e,t){if(typeof e!=`string`)throw TypeError(`[router.${t}] dependency name must be a string, got ${typeof e}`)}function fe(e){if(typeof e!=`string`)throw TypeError(`[router.setDependency] dependency name must be a string, got ${typeof e}`)}function pe(e,t){if(!S(e))throw TypeError(`[router.${t}] Invalid argument: expected plain object, received ${v(e)}`);for(let n of b(e))if(x(e,n)?.get)throw TypeError(`[router.${t}] Getters not allowed: "${n}"`)}function me(e,t){if(e===void 0)throw ReferenceError(`[router.getDependency] dependency "${t}" not found`)}function he(e,t,n){let r=e,i=r.limits?.maxDependencies??100;if(i===0)return;let a=b(r.dependencies).length,{warn:o,error:s}=y(i);if(a>=i)throw RangeError(`[router.${t}] Dependency limit exceeded (${i}). Current: ${a}.`);a===s?n.error(`router.${t}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${i}.`):a===o&&n.warn(`router.${t}`,`${a} dependencies registered. Consider if all are necessary.`)}function ge(e){if(e!==void 0){if(!S(e))throw TypeError(`[cloneRouter] Invalid dependencies: expected plain object or undefined, received ${typeof e}`);for(let t of b(e))if(x(e,t)?.get)throw TypeError(`[cloneRouter] Getters not allowed in dependencies: "${t}"`)}}function _e(e,t,n){n.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function ve(e,t,n){n.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function ye(e,t){t.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const be=new Set([`$start`,`$stop`,`$$start`,`$$leaveApprove`,`$$cancel`,`$$success`,`$$error`]);function xe(e){if(!be.has(e))throw TypeError(`[router.addEventListener] Invalid event name: ${String(e)}. Must be one of: $start, $stop, $$start, $$leaveApprove, $$cancel, $$success, $$error`)}function Se(e,t){if(xe(e),typeof t!=`function`)throw TypeError(`[router.addEventListener] callback must be a function, got ${typeof t}`)}function Ce(e,t,n,r,i=1e4){if(i===0)return;let{warn:a,error:o}=y(i);e>=o?r.error(`router.${n}`,`${e} listeners registered for "${t}"! This is excessive. Hard limit at ${i}.`):e>=a&&r.warn(`router.${n}`,`${e} listeners registered for "${t}". Consider whether all are necessary — a growing count usually means a missing unsubscribe.`)}function we(e,t){if(!i(e)&&typeof e!=`function`)throw TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${v(e)}`)}function Te(e,t,n=200){if(n!==0&&e>=n)throw RangeError(`[router.${t}] Lifecycle handler limit exceeded (${n}). This indicates too many routes with individual handlers. Consider using plugins for cross-cutting concerns.`)}function Ee(e,t,n,r){if(n===0)return;let{warn:i,error:a}=y(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 De(e,t,n,r){r.warn(`router.${n}`,`Overwriting existing ${t} handler for route "${e}"`)}function C(e,t,n){n.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}const w=Object.hasOwn;function T(e){if(typeof e!=`string`)throw TypeError(`[router.navigate] Invalid route name: expected string, got ${v(e)}`)}function E(e){if(e!==void 0&&(typeof e!=`object`||!e))throw TypeError(`[router.navigateToDefault] Invalid options: ${v(e)}. Expected NavigationOptions object.`)}function Oe(e){if(typeof e!=`object`||!e)throw TypeError(`[router.navigateToState] Invalid state: ${v(e)}. Expected State object.`);let t=e;if(!r(t.name))throw TypeError(`[router.navigateToState] Invalid state.name: ${v(t.name)}. Expected string.`);if(!f(t.params))throw TypeError(`[router.navigateToState] Invalid state.params: ${v(t.params)}. Expected plain object.`);if(!r(t.path))throw TypeError(`[router.navigateToState] Invalid state.path: ${v(t.path)}. Expected string.`)}function ke(e,t){if(!oe(e))throw TypeError(`[router.${t}] Invalid options: ${v(e)}. Expected NavigationOptions object.`)}const D=/[\u0000-\u001F\u007F]/;function Ae(e,t){for(let n in e){if(!w(e,n))continue;let r=e[n],i=typeof r;if(i===`symbol`||i===`bigint`)throw TypeError(`[router.${t}] param "${n}" cannot be a ${i} — it does not round-trip through the URL path. Use a string, number, or boolean.`);if(i===`string`&&D.test(r))throw TypeError(`[router.${t}] param "${n}" must not contain control characters (NUL / C0 / DEL) — they corrupt the URL path.`)}}function je(e,t){if(e!==void 0&&(typeof e==`object`&&e&&!Array.isArray(e)&&Ae(e,t),!f(e)))throw TypeError(`[router.${t}] params must be a plain object, got ${v(e)}`)}function Me(e){if(e!==void 0&&typeof e!=`string`)throw TypeError(`[router.start] path must be a string, got ${v(e)}.`);if(typeof e==`string`){if(D.test(e))throw TypeError(`[router.start] path must not contain control characters (NUL / C0 / DEL).`);if(e!==``&&!e.startsWith(`/`))throw TypeError(`[router.start] path must start with "/", got "${e}".`)}}const O=Object.entries,Ne=Object.hasOwn,Pe=Object.keys,k={trailingSlash:[`strict`,`never`,`always`,`preserve`],queryParamsMode:[`default`,`strict`,`loose`],urlParamsEncoding:[`default`,`uri`,`uriComponent`,`none`]},A={arrayFormat:[`none`,`brackets`,`index`,`comma`],booleanFormat:[`none`,`auto`,`empty-true`],nullFormat:[`default`,`hidden`],numberFormat:[`none`,`auto`]},Fe=new Set([`defaultRoute`,`defaultParams`,`defaultSearch`,`trailingSlash`,`caseSensitive`,`queryParamsMode`,`queryParams`,`urlParamsEncoding`,`allowNotFound`,`rewritePathOnMatch`,`logger`,`limits`]),j={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 Ie(e,t,n){if(typeof t!=`number`||!Number.isInteger(t))throw TypeError(`[router.${n}] limit "${e}" must be an integer, got ${String(t)}`);let r=j[e];if(t<r.min||t>r.max)throw RangeError(`[router.${n}] limit "${e}" must be between ${r.min} and ${r.max}, got ${t}`)}function Le(e,t){if(!e||typeof e!=`object`||e.constructor!==Object)throw TypeError(`[router.${t}] invalid limits: expected plain object, got ${typeof e}`);for(let[n,r]of O(e)){if(!Ne(j,n))throw TypeError(`[router.${t}] unknown limit: "${n}"`);r!==void 0&&Ie(n,r,t)}let{warnListeners:n,maxListeners:r}=e;if(typeof n==`number`&&typeof r==`number`&&r>0&&n>r)throw RangeError(`[router.${t}] "limits.warnListeners" (${n}) must not exceed "limits.maxListeners" (${r}) — the warning channel would be unreachable`)}function M(e,t,n,r){if(e!==void 0&&(typeof e!=`string`||!n.includes(e))){let i=n.map(e=>`"${e}"`).join(`, `);throw TypeError(`[router.${r}] Invalid "${t}": "${typeof e==`string`?e:`(${typeof e})`}". Must be one of: ${i}`)}}function Re(e,t){if(e!==void 0&&typeof e!=`string`&&typeof e!=`function`)throw TypeError(`[router.${t}] Invalid "defaultRoute": expected string or function, got ${typeof e}`)}function N(e,t,n){if(e!==void 0&&typeof e!=`function`&&(!e||typeof e!=`object`||Array.isArray(e)||e.constructor!==Object))throw TypeError(`[router.${n}] Invalid "${t}": expected plain object or function, got ${typeof e}`)}function ze(e,t){if(e===void 0)return;if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`[router.${t}] Invalid "queryParams": expected plain object`);let n=e;for(let[e,r]of O(n)){if(!a(e,A))throw TypeError(`[router.${t}] Invalid "queryParams.${e}": unknown option`);M(r,`queryParams.${e}`,A[e],t)}}function Be(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`[router.${t}] Invalid options: expected plain object`);let n=e;for(let e of Pe(n))if(!Fe.has(e))throw TypeError(`[router.${t}] Unknown option: "${e}"`);if(Re(n.defaultRoute,t),N(n.defaultParams,`defaultParams`,t),N(n.defaultSearch,`defaultSearch`,t),M(n.trailingSlash,`trailingSlash`,k.trailingSlash,t),M(n.queryParamsMode,`queryParamsMode`,k.queryParamsMode,t),M(n.urlParamsEncoding,`urlParamsEncoding`,k.urlParamsEncoding,t),n.allowNotFound!==void 0&&typeof n.allowNotFound!=`boolean`)throw TypeError(`[router.${t}] Invalid "allowNotFound": expected boolean, got ${typeof n.allowNotFound}`);if(n.rewritePathOnMatch!==void 0&&typeof n.rewritePathOnMatch!=`boolean`)throw TypeError(`[router.${t}] Invalid "rewritePathOnMatch": expected boolean, got ${typeof n.rewritePathOnMatch}`);if(n.caseSensitive!==void 0&&typeof n.caseSensitive!=`boolean`)throw TypeError(`[router.${t}] Invalid "caseSensitive": expected boolean, got ${typeof n.caseSensitive}`);ze(n.queryParams,t),n.limits!==void 0&&Le(n.limits,t)}const Ve=Object.hasOwn,P=`router.usePlugin`,He={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function Ue(e,t,n=50){if(n!==0&&e+t>n)throw RangeError(`[router.usePlugin] Plugin limit exceeded (${n}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating plugins.`)}function We(e,t){if(t.includes(e))throw Error(`[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.`)}function Ge(e,t,n){if(t===0)return;let{warn:r,error:i}=y(t);e>=i?n.error(P,`${e} plugins registered! This is excessive. Hard limit at ${t}.`):e>=r&&n.warn(P,`${e} plugins registered. Consider if all are necessary.`)}function Ke(e){for(let t in e)if(!(t===`teardown`||Ve(He,t)))throw TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}function qe(e){e.warn(P,`Duplicate factory in batch, will be registered once`)}function Je(e,t){t.warn(P,`Property '${e}' is not a function, skipping`)}function Ye(e,t){e===`onStart`&&t.warn(P,`Router already started, onStart will not be called`)}function Xe(e,t){let n=[`start`,`buildPath`,`forwardState`];if(typeof e!=`string`||!n.includes(e))throw TypeError(`[router.addInterceptor] Invalid method: "${String(e)}". Must be one of: ${n.join(`, `)}`);if(typeof t!=`function`)throw TypeError(`[router.addInterceptor] interceptor must be a function, got ${typeof t}`)}const F=Object.entries,Ze=Object.getOwnPropertyDescriptor,I=Object.keys;function L(e,t){if(!e||typeof e!=`object`)throw TypeError(`[validation-plugin] ${t}: store must be an object`);let n=e;if(!Array.isArray(n.definitions))throw TypeError(`[validation-plugin] ${t}: store.definitions must be an array`);if(!n.config||typeof n.config!=`object`)throw TypeError(`[validation-plugin] ${t}: store.config must be an object`);if(!n.tree||typeof n.tree!=`object`)throw TypeError(`[validation-plugin] ${t}: store.tree must be an object`);return n}function R(e,t,n=``){for(let r of e){let e=n?`${n}.${r.name}`:r.name;t(r,e),r.children&&R(r.children,t,e)}}function z(e,t){let n=t.split(`.`),r=e;for(let e of n)if(r=r.children.get(e),!r)return!1;return!0}function Qe(t,n){try{return(0,e.resolveForwardChain)(t,n)}catch(e){throw Error(`[validation-plugin] ${e.message}`,{cause:e})}}function B(e){let t=new Set;for(let n of e){for(let e of n.paramMeta.urlParams)t.add(e);for(let e of n.paramMeta.spatParams)t.add(e)}return t}function V(e,t,n){let r=e;if(r.constructor.name===`AsyncFunction`||r.toString().includes(`__awaiter`))throw TypeError(`[validation-plugin] Route "${n}" ${t} cannot be async`)}function $e(e){R(L(e,`validateExistingRoutes`).definitions,(e,t)=>{if(typeof e.name!=`string`||!e.name)throw TypeError(`[validation-plugin] validateExistingRoutes: route has invalid name: ${e.name}`);if(typeof e.path!=`string`)throw TypeError(`[validation-plugin] validateExistingRoutes: route "${t}" has non-string path (${typeof e.path})`)})}function et(e){let{config:t,tree:n,matcher:r}=L(e,`validateForwardToConsistency`);for(let[e,i]of F(t.forwardMap)){if(!z(n,i))throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${i}" does not exist in tree (source route: "${e}")`);let t=r.getSegmentsByName(e),a=r.getSegmentsByName(i);if(t&&a){let n=B(t),r=[...B(a)].filter(e=>!n.has(e));if(r.length>0)throw Error(`[validation-plugin] validateForwardToConsistency: forwardTo target "${i}" requires params [${r.join(`, `)}] not available in source route "${e}"`)}}for(let e of I(t.forwardMap))Qe(e,t.forwardMap)}function tt(e){let{config:t}=L(e,`validateRoutePropertiesStore`);for(let[e,n]of F(t.decoders)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" decoder must be a function, got ${typeof n}`);V(n,`decoder`,e)}for(let[e,n]of F(t.encoders)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" encoder must be a function, got ${typeof n}`);V(n,`encoder`,e)}for(let[e,n]of F(t.defaultParams))if(typeof n!=`object`||!n||Array.isArray(n))throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" defaultParams must be a plain object, got ${Array.isArray(n)?`array`:typeof n}`);for(let[e,n]of F(t.forwardFnMap)){if(typeof n!=`function`)throw TypeError(`[validation-plugin] validateRoutePropertiesStore: route "${e}" forwardTo callback must be a function, got ${typeof n}`);V(n,`forwardTo callback`,e)}}function nt(e){let{config:t,tree:n}=L(e,`validateForwardToTargetsStore`);for(let[e,r]of F(t.forwardMap))if(!z(n,r))throw Error(`[validation-plugin] validateForwardToTargetsStore: forwardTo target "${r}" does not exist for route "${e}"`)}function rt(e){if(!e||typeof e!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps must be an object`);let t=e;if(!t.dependencies||typeof t.dependencies!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.dependencies must be an object`);let n=t.dependencies;for(let e of I(n))if(Ze(n,e)?.get)throw TypeError(`[validation-plugin] validateDependenciesStructure: dependency "${e}" must not use a getter`);if(!t.limits||typeof t.limits!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits must be an object`);let r=t.limits;for(let e of[`maxDependencies`,`maxPlugins`,`maxListeners`,`warnListeners`,`maxLifecycleHandlers`])if(!Number.isInteger(r[e]))throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits.${e} must be an integer, got ${String(r[e])}`)}function it(e){let t=e&&typeof e==`object`?e:{};return t.limits&&typeof t.limits==`object`?t.limits:{}}function at(e,t){if(!e||typeof e!=`object`)return;let n=e,r=n.dependencies,i=n.limits;if(!r||typeof r!=`object`||!i||typeof i!=`object`)return;let a=I(r).length,o=i,s=t.maxDependencies,c=o.maxDependencies,l=typeof s==`number`?s:c;if(typeof l==`number`&&l>0&&a>l)throw RangeError(`[validation-plugin] validateLimitsConsistency: dependency count (${a}) exceeds maxDependencies limit (${l})`)}function ot(e,t){at(t,it(e))}function H(e,t){if(!(typeof e!=`string`||!e)&&!z(L(t,`validateResolvedDefaultRoute`).tree,e))throw Error(`[validation-plugin] defaultRoute resolved to non-existent route: "${e}"`)}const st=Object.keys;function ct(e,t){if(e!==void 0&&typeof e==`function`){let n=e.constructor.name===`AsyncFunction`,r=e.toString().includes(`__awaiter`);if(n||r)throw TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${t}". Async functions break matchPath/buildPath.`)}}function U(e,t){if(e.canActivate!==void 0&&typeof e.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function for route "${t}", got ${v(e.canActivate)}`);if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${v(e.canDeactivate)}`);if(e.defaultParams!==void 0){let n=e.defaultParams;if(typeof n!=`object`||!n||Array.isArray(n))throw TypeError(`[router.addRoute] defaultParams must be an object for route "${t}", got ${v(e.defaultParams)}`)}if(e.decodeParams?.constructor.name===`AsyncFunction`)throw TypeError(`[router.addRoute] decodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if(e.encodeParams?.constructor.name===`AsyncFunction`)throw TypeError(`[router.addRoute] encodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if(ct(e.forwardTo,t),e.children)for(let n of e.children)U(n,`${t}.${n.name}`)}function lt(e){let t=new Set,n=/[*:]([A-Z_a-z]\w*)/g,r;for(;(r=n.exec(e))!==null;)t.add(r[1]);return t}function W(e){let t=new Set;for(let n of e)for(let e of lt(n))t.add(e);return t}function G(e,t,n=``,r=[]){for(let i of e){let e=n?`${n}.${i.name}`:i.name,a=[...r,i.path];if(e===t)return a;if(i.children&&t.startsWith(`${e}.`))return G(i.children,t,e,a)}throw Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function K(e,t=``){let n=new Set;for(let r of e){let e=t?`${t}.${r.name}`:r.name;if(n.add(e),r.children)for(let t of K(r.children,e))n.add(t)}return n}function q(e,t=``){let n=new Map;for(let r of e){let e=t?`${t}.${r.name}`:r.name;if(r.forwardTo&&typeof r.forwardTo==`string`&&n.set(e,r.forwardTo),r.children)for(let[t,i]of q(r.children,e))n.set(t,i)}return n}function J(e){let t=new Set;for(let n of e){for(let e of n.paramMeta.urlParams)t.add(e);for(let e of n.paramMeta.spatParams)t.add(e)}return t}function ut(e,t,n,r){return t?J(n.getSegmentsByName(e)??[]):W(G(r,e))}const dt=new Set;function ft(e,t,n,r,i,a){let o=i.hasRoute(t),s=r.has(t);if(!o&&!s)throw ReferenceError(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);let c=new Set([...a,...W(G(n,e))]),l=[...ut(t,o,i,n)].filter(e=>!c.has(e));if(l.length>0)throw Error(`[router.addRoute] forwardTo target "${t}" requires params [${l.join(`, `)}] that are not available in source route "${e}"`)}function pt(t,r,i,a){let o=K(t),s=a?new Set([...o].map(e=>`${a}.${e}`)):o,c=a?J(i.getSegmentsByName(a)):dt,l=q(t),u={...r};for(let[e,t]of l)(0,n.putField)(u,e,t);for(let[e,n]of l)ft(e,n,t,s,i,c);for(let t of st(u))(0,e.resolveForwardChain)(t,u)}function Y(e,t){if(e.startsWith(`@@`))throw Error(`[router.${t}] Route name "${e}" uses the reserved "@@" prefix. Routes with this prefix are internal and cannot be modified through the public API.`)}function X(e,t){for(let n of e)n&&typeof n==`object`&&typeof n.name==`string`&&(Y(n.name,t),n.children&&X(n.children,t))}function mt(e){_(e,`removeRoute`)}function ht(e){if(typeof e!=`string`)throw TypeError(`[router.setRootPath] rootPath must be a string, got ${v(e)}`)}function Z(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function gt(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function, got ${v(t.canActivate)}`);if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function, got ${v(t.canDeactivate)}`)}function _t(e){let t=e,n=t.name;if(t.decodeParams!==void 0&&Z(t.decodeParams))throw TypeError(`[router.addRoute] decodeParams cannot be async for route "${String(n)}"`);if(t.encodeParams!==void 0&&Z(t.encodeParams))throw TypeError(`[router.addRoute] encodeParams cannot be async for route "${String(n)}"`);if(typeof t.forwardTo==`function`&&Z(t.forwardTo))throw TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${String(n)}"`)}function vt(e){for(let t of e){if(typeof t!=`object`||!t||Array.isArray(t))throw TypeError(`[router.addRoute] Route must be an object, got ${v(t)}`);U(t,t.name)}}function yt(e){if(typeof e!=`string`||e===``)throw TypeError(`[router.addRoute] parent option must be a non-empty string, got ${v(e)}`);_(e,`addRoute`)}function bt(e,t,n,i){if(!r(e))throw TypeError(`[router.isActiveRoute] name must be a string, got ${typeof e}`);if(t!==void 0&&!f(t))throw TypeError(`[router.isActiveRoute] params must be a plain object, got ${v(t)}`);if(n!==void 0&&typeof n!=`boolean`)throw TypeError(`[router.isActiveRoute] strictEquality must be a boolean, got ${typeof n}`);if(i!==void 0&&typeof i!=`boolean`)throw TypeError(`[router.isActiveRoute] ignoreQueryParams must be a boolean, got ${typeof i}`)}function xt(e,t,n){if(!r(e))throw TypeError(`[router.${n}] Invalid routeName: ${v(e)}. Expected string.`);if(!f(t))throw TypeError(`[router.${n}] Invalid routeParams: ${v(t)}. Expected plain object.`)}function St(e,t){if(_(e,`updateRoute`),e===``)throw ReferenceError(`[router.updateRoute] Invalid name: empty string. Cannot update root node.`);if(t===null)throw TypeError(`[router.updateRoute] updates must be an object, got null`);if(typeof t!=`object`||Array.isArray(t))throw TypeError(`[router.updateRoute] updates must be an object, got ${v(t)}`)}function Q(e,t){if(e.constructor.name===`AsyncFunction`||e.toString().includes(`__awaiter`))throw TypeError(`[router.updateRoute] ${t} cannot be an async function`)}function $(e,t){if(e!=null){if(typeof e!=`function`)throw TypeError(`[router.updateRoute] ${t} must be a function or null, got ${typeof e}`);Q(e,t)}}function Ct(e,t,n,r){if(e!=null){if(typeof e!=`string`&&typeof e!=`function`)throw TypeError(`[router.updateRoute] forwardTo must be a string, function, or null, got ${v(e)}`);typeof e==`function`&&Q(e,`forwardTo callback`)}if(t!=null&&(typeof t!=`object`||Array.isArray(t)))throw TypeError(`[router.updateRoute] defaultParams must be an object or null, got ${v(t)}`);$(n,`decodeParams`),$(r,`encodeParams`)}function wt(e){if(!r(e)||e===``)throw TypeError(`[router.buildPath] route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`)}function Tt(e){if(!r(e))throw TypeError(`[router.matchPath] path must be a string, got ${typeof e}`)}function Et(e){if(!r(e))throw TypeError(`[router.shouldUpdateNode] nodeName must be a string, got ${typeof e}`)}function Dt(e,n,r,i,a){if(a&&n){let e=n;for(let t of a.split(`.`))if(e=e.children.get(t),!e)throw ReferenceError(`[router.addRoute] Parent route "${a}" does not exist`)}let o=new Set,s=new Map;for(let r of e)(0,t.validateRoute)(r,`addRoute`,n,a??``,o,s);r&&i&&pt(e,i,r,a)}function Ot(e){let t=new Set;for(let n of e)for(let e of n.paramMeta.urlParams)t.add(e);return t}function kt(e,t,n){let r=n.getSegmentsByName(e),i=n.getSegmentsByName(t),a=Ot(r),o=[];for(let e of i)for(let t of e.paramMeta.urlParams)o.push(t);let s=o.filter(e=>!a.has(e));if(s.length>0)throw Error(`[router.addRoute] forwardTo target "${t}" requires params [${s.join(`, `)}] that are not available in source route "${e}"`)}function At(t,n,r){(0,e.resolveForwardChain)(t,{...r.forwardMap,[t]:n})}function jt(e,t,n,r,i){if(!n(e))throw ReferenceError(`[router.updateRoute] route "${e}" does not exist`);if(t!=null&&typeof t==`string`){if(!n(t))throw Error(`[router.updateRoute] forwardTo target "${t}" does not exist`);kt(e,t,r),At(e,t,i)}}function Mt(e,t,n){if(!r(e))throw TypeError(`[router.makeState] Invalid name: ${v(e)}. Expected string.`);if(t!==void 0&&!f(t))throw TypeError(`[router.makeState] Invalid params: ${v(t)}. Expected plain object.`);if(n!==void 0&&!r(n))throw TypeError(`[router.makeState] Invalid path: ${v(n)}. Expected string.`)}function Nt(){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 Pt(){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 Ft(e){return{routes:{validateBuildPathArgs:wt,validateMatchPathArgs:Tt,validateIsActiveRouteArgs:bt,validateShouldUpdateNodeArgs:Et,validateStateBuilderArgs:xt,validateAddRouteArgs(e){vt(e)},validateRoutes(e,t,n){let r=t;Dt(e,r.tree,r.matcher,r.config?.forwardMap,n)},validateRemoveRouteArgs:mt,validateUpdateRouteBasicArgs:St,validateUpdateRoutePropertyTypes(e,t){let n=t;Ct(n.forwardTo,n.defaultParams,n.decodeParams,n.encodeParams)},validateUpdateRoute(e,t,n){let r=n,i=t.forwardTo;jt(e,i,e=>r.matcher.hasRoute(e),r.matcher,r.config)},validateParentOption(e,t){yt(e);let n=t;for(let t of e.split(`.`)){let r=n.children.get(t);if(!r)throw ReferenceError(`[router.addRoute] Parent route "${e}" does not exist`);n=r}},validateRouteName(e,t){_(e,t)},throwIfInternalRoute(e,t){Y(e,t)},throwIfInternalRouteInArray(e,t){X(e,t)},validateSetRootPathArgs:ht,guardRouteCallbacks:gt,guardNoAsyncCallbacks:_t},options:{validateOptions:Be,validateResolvedDefaultRoute:H},dependencies:{validateDependencyName:de,validateSetDependencyArgs(e,t,n){fe(e)},validateDependenciesObject:pe,validateDependencyExists(e,t){let n=t.dependencies?.[e];me(n,e)},validateDependencyCount(t,n){he(t,n,e.logger)},validateCloneArgs:ge,warnOverwrite(t,n){_e(t,n,e.logger)},warnBatchOverwrite(t,n){ve(t,n,e.logger)},warnRemoveNonExistent(t){ye(t,e.logger)}},plugins:{validatePluginLimit(e,t){Ue(e,1,t?.maxPlugins)},validateNoDuplicatePlugins:We,validatePluginKeys:Ke,validateCountThresholds(t){Ge(t,e.getOptions().limits?.maxPlugins??50,e.logger)},warnBatchDuplicates(){qe(e.logger)},warnPluginMethodType(t){Je(t,e.logger)},warnPluginAfterStart(t){Ye(t,e.logger)},validateAddInterceptorArgs:Xe},lifecycle:{validateHandler:we,validateHandlerLimit(t,n){Te(t,n,e.getOptions().limits?.maxLifecycleHandlers??200)},validateCountThresholds(t,n){Ee(t,n,e.getOptions().limits?.maxLifecycleHandlers??200,e.logger)},warnOverwrite(t,n,r){De(t,n,r,e.logger)},warnAsyncGuardSync(t,n){C(t,n,e.logger)}},navigation:{validateNavigateArgs:T,validateNavigateToDefaultArgs:E,validateNavigateToStateArgs:Oe,validateNavigationOptions:ke,validateParams:je,validateStartArgs:Me},state:{validateMakeStateArgs:Mt,reportDroppedQueryKey:Nt(),reportUndeclaredParamKey:Pt(),validateAreStatesEqualArgs(e,t,n){if(!g(e))throw TypeError(`[router.areStatesEqual] Invalid state1: ${v(e)}. Expected State object.`);if(!g(t))throw TypeError(`[router.areStatesEqual] Invalid state2: ${v(t)}. Expected State object.`);if(n!==void 0&&!i(n))throw TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${v(n)}. Expected boolean.`)}},eventBus:{validateListenerArgs(e,t){Se(e,t)},validateCountThresholds(t,n,r){let i=e.getOptions().limits?.maxListeners??1e4;Ce(t,n,r,e.logger,i)}}}}function It(){return n=>{let r=(0,t.getInternals)(n);if(n.isActive())throw new e.RouterError(`VALIDATION_PLUGIN_AFTER_START`,{message:`validation-plugin must be registered before router.start()`});r.validator=Ft(r);try{let e=r.routeGetStore(),t=r.dependenciesGetStore(),n=r.getOptions();$e(e),et(e),tt(e),nt(e),rt(t),ot(n,t),r.validator.options.validateOptions(n,`constructor (retrospective)`),typeof n.defaultRoute==`string`&&H(n.defaultRoute,e)}catch(e){throw r.validator=null,e}return{teardown(){r.validator=null}}}}exports.validationPlugin=It;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|