@real-router/validation-plugin 0.11.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/validationPlugin.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/validationPlugin.ts"],"mappings":";;;;iBAmSgB,gBAAA,IAAoB,aAAa"}
|
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/logger");const r=[`replace`,`reload`,`force`,`forceDeactivate`,`redirected`];function i(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;for(let e of r){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 a=/\S/,o=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function s(e,t){return TypeError(`[router.${e}] ${t}`)}function c(e){return typeof e==`string`?e===``?!0:e.length>1e4?!1:e.startsWith(`@@`)?!0:o.test(e):!1}function l(e){if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function u(e,t){let n=Array.isArray(e)?e:Object.values(e);for(let e of n)t.push(e)}function ee(e){let t=typeof e;return t===`string`||t===`boolean`?!0:t===`number`?Number.isFinite(e):!1}var d=class{container;constructor(e){this.container=e}};function f(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 p(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(!f(e,t,n,r))return!1;continue}if(!ee(e))return!1}}return!0}function te(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`boolean`?!0:t===`number`?Number.isFinite(e):!1}function m(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?p(e):!0}function h(e){return c(e.name)&&typeof e.path==`string`&&m(e.params)}function g(e){return typeof e!=`object`||!e?!1:h(e)}function _(e){return typeof e==`string`}function v(e){return typeof e==`boolean`}function re(e,t){return e in t}function y(e,t){if(typeof e!=`string`)throw s(t,`Route name must be a string, got ${typeof e}`);if(e!==``){if(!a.test(e))throw s(t,`Route name cannot contain only whitespace`);if(e.length>1e4)throw s(t,`Route name exceeds maximum length of 10000 characters. This is a technical safety limit.`);if(!e.startsWith(`@@`)&&!o.test(e))throw s(t,`Invalid route name "${e}". Each segment must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens. Segments are separated by dots (e.g., "users.profile").`)}}function b(e){if(e===null)return`null`;if(Array.isArray(e))return`array[${e.length}]`;if(typeof e==`object`){try{let t=e.constructor;if(typeof t==`function`&&t.name!==`Object`)return t.name||`object`}catch{}return`object`}return typeof e}function x(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}function ie(e,t){if(typeof e!=`string`)throw TypeError(`[router.${t}] dependency name must be a string, got ${typeof e}`)}function ae(e){if(typeof e!=`string`)throw TypeError(`[router.setDependency] dependency name must be a string, got ${typeof e}`)}function oe(e,t){if(!(e&&typeof e==`object`&&e.constructor===Object))throw TypeError(`[router.${t}] Invalid argument: expected plain object, received ${b(e)}`);for(let n in e)if(Object.getOwnPropertyDescriptor(e,n)?.get)throw TypeError(`[router.${t}] Getters not allowed: "${n}"`)}function se(e,t){if(e===void 0)throw ReferenceError(`[router.getDependency] dependency "${t}" not found`)}function ce(e,t){let r=e,i=r.limits?.maxDependencies??100;if(i===0)return;let a=Object.keys(r.dependencies).length,{warn:o,error:s}=x(i);if(a>=i)throw RangeError(`[router.${t}] Dependency limit exceeded (${i}). Current: ${a}.`);a===s?n.logger.error(`router.${t}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${i}.`):a===o&&n.logger.warn(`router.${t}`,`${a} dependencies registered. Consider if all are necessary.`)}function le(e){if(e!==void 0){if(!(e&&typeof e==`object`&&e.constructor===Object))throw TypeError(`[cloneRouter] Invalid dependencies: expected plain object or undefined, received ${typeof e}`);for(let t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw TypeError(`[cloneRouter] Getters not allowed in dependencies: "${t}"`)}}function ue(e,t){n.logger.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function de(e,t){n.logger.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function fe(e){n.logger.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const pe=new Set([`$start`,`$stop`,`$$start`,`$$leaveApprove`,`$$cancel`,`$$success`,`$$error`]);function me(e){if(!pe.has(e))throw TypeError(`[router.addEventListener] Invalid event name: ${String(e)}. Must be one of: $start, $stop, $$start, $$leaveApprove, $$cancel, $$success, $$error`)}function he(e,t){if(me(e),typeof t!=`function`)throw TypeError(`[router.addEventListener] callback must be a function, got ${typeof t}`)}function ge(e,t){if(!v(e)&&typeof e!=`function`)throw TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${b(e)}`)}function _e(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 ve(e,t,r){if(r===0)return;let{warn:i,error:a}=x(r);e>=a?n.logger.error(`router.${t}`,`${e} lifecycle handlers registered! This is excessive. Hard limit at ${r}.`):e>=i&&n.logger.warn(`router.${t}`,`${e} lifecycle handlers registered. Consider consolidating logic.`)}function ye(e,t,r){n.logger.warn(`router.${r}`,`Overwriting existing ${t} handler for route "${e}"`)}function be(e,t){n.logger.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}function S(e){if(typeof e!=`string`)throw TypeError(`[router.navigate] Invalid route name: expected string, got ${b(e)}`)}function C(e){if(e!==void 0&&(typeof e!=`object`||!e))throw TypeError(`[router.navigateToDefault] Invalid options: ${b(e)}. Expected NavigationOptions object.`)}function w(e){if(typeof e!=`object`||!e)throw TypeError(`[router.navigateToState] Invalid state: ${b(e)}. Expected State object.`);let t=e;if(!_(t.name))throw TypeError(`[router.navigateToState] Invalid state.name: ${b(t.name)}. Expected string.`);if(!m(t.params))throw TypeError(`[router.navigateToState] Invalid state.params: ${b(t.params)}. Expected plain object.`);if(!_(t.path))throw TypeError(`[router.navigateToState] Invalid state.path: ${b(t.path)}. Expected string.`)}function T(e,t){if(!i(e))throw TypeError(`[router.${t}] Invalid options: ${b(e)}. Expected NavigationOptions object.`)}const E=/[\u0000-\u001F\u007F]/;function D(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`&&E.test(r))throw TypeError(`[router.${t}] param "${n}" must not contain control characters (NUL / C0 / DEL) — they corrupt the URL path.`)}}function O(e,t){if(e!==void 0&&(typeof e==`object`&&e&&!Array.isArray(e)&&D(e,t),!m(e)))throw TypeError(`[router.${t}] params must be a plain object, got ${b(e)}`)}function k(e){if(e!==void 0&&typeof e!=`string`)throw TypeError(`[router.start] path must be a string, got ${b(e)}.`);if(typeof e==`string`){if(E.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`]},M=new Set([`defaultRoute`,`defaultParams`,`trailingSlash`,`caseSensitive`,`queryParamsMode`,`queryParams`,`urlParamsEncoding`,`allowNotFound`,`rewritePathOnMatch`,`logger`,`limits`]),N={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 xe(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=N[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 Se(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(N,n))throw TypeError(`[router.${t}] unknown limit: "${n}"`);r!==void 0&&xe(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 P(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 Ce(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 we(e,t){if(e!==void 0&&typeof e!=`function`&&(!e||typeof e!=`object`||Array.isArray(e)||e.constructor!==Object))throw TypeError(`[router.${t}] Invalid "defaultParams": expected plain object or function, got ${typeof e}`)}function Te(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(!re(e,j))throw TypeError(`[router.${t}] Invalid "queryParams.${e}": unknown option`);P(r,`queryParams.${e}`,j[e],t)}}function Ee(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(!M.has(e))throw TypeError(`[router.${t}] Unknown option: "${e}"`);if(Ce(n.defaultRoute,t),we(n.defaultParams,t),P(n.trailingSlash,`trailingSlash`,A.trailingSlash,t),P(n.queryParamsMode,`queryParamsMode`,A.queryParamsMode,t),P(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}`);Te(n.queryParams,t),n.limits!==void 0&&Se(n.limits,t)}const F=`router.usePlugin`,De={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function Oe(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 ke(e,t){if(t.includes(e))throw Error(`[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.`)}function Ae(e,t){if(t===0)return;let{warn:r,error:i}=x(t);e>=i?n.logger.error(F,`${e} plugins registered! This is excessive. Hard limit at ${t}.`):e>=r&&n.logger.warn(F,`${e} plugins registered. Consider if all are necessary.`)}function je(e){for(let t in e)if(!(t===`teardown`||Object.hasOwn(De,t)))throw TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}function Me(){n.logger.warn(F,`Duplicate factory in batch, will be registered once`)}function Ne(e){n.logger.warn(F,`Property '${e}' is not a function, skipping`)}function Pe(e){e===`onStart`&&n.logger.warn(F,`Router already started, onStart will not be called`)}function Fe(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 Ie(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 Le(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(e.name.includes(`.`))throw TypeError(`[router.constructor] Route name "${e.name}" cannot contain dots. Use children array or { parent } option in addRoute() instead.`);if(typeof e.path!=`string`)throw TypeError(`[validation-plugin] validateExistingRoutes: route "${t}" has non-string path (${typeof e.path})`)})}function Re(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))Ie(e,t.forwardMap)}function ze(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 Be(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 Ve(e){if(!e||typeof e!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps must be an object`);let t=e;if(!t.dependencies||typeof t.dependencies!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.dependencies must be an object`);let n=t.dependencies;for(let e of Object.keys(n))if(Object.getOwnPropertyDescriptor(n,e)?.get)throw TypeError(`[validation-plugin] validateDependenciesStructure: dependency "${e}" must not use a getter`);if(!t.limits||typeof t.limits!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits must be an object`);let r=t.limits;for(let e of[`maxDependencies`,`maxPlugins`,`maxListeners`,`warnListeners`,`maxLifecycleHandlers`])if(typeof r[e]!=`number`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits.${e} must be a number, got ${typeof r[e]}`)}function He(e){let t=e&&typeof e==`object`?e:{};return t.limits&&typeof t.limits==`object`?t.limits:{}}function Ue(e,t){if(!e||typeof e!=`object`)return;let n=e,r=n.dependencies,i=n.limits;if(!r||typeof r!=`object`||!i||typeof i!=`object`)return;let a=Object.keys(r).length,o=i,s=t.maxDependencies,c=o.maxDependencies,l=typeof s==`number`?s:c;if(typeof l==`number`&&l>0&&a>=l)throw RangeError(`[validation-plugin] validateLimitsConsistency: dependency count (${a}) reaches or exceeds maxDependencies limit (${l})`)}function We(e,t){Ue(t,He(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 Ge(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 ${b(e.canActivate)}`);if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${b(e.canDeactivate)}`);if(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 ${b(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(Ge(e.forwardTo,t),e.children)for(let n of e.children)H(n,`${t}.${n.name}`)}function Ke(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 Ke(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 qe(e,t,n,r){return t?q(n.getSegmentsByName(e)??[]):U(W(r,e))}const Je=new Set;function Ye(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=[...qe(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 Xe(t,n,r,i){let a=G(t),o=i?new Set([...a].map(e=>`${i}.${e}`)):a,s=i?q(r.getSegmentsByName(i)):Je,c=K(t),l={...n};for(let[e,t]of c)l[e]=t;for(let[e,n]of c)Ye(e,n,t,o,r,s);for(let t of Object.keys(l))(0,e.resolveForwardChain)(t,l)}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 Ze(e){y(e,`removeRoute`)}function Qe(e){if(typeof e!=`string`)throw TypeError(`[router.setRootPath] rootPath must be a string, got ${b(e)}`)}function X(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function $e(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function, got ${b(t.canActivate)}`);if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function, got ${b(t.canDeactivate)}`)}function et(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 tt(e){for(let t of e){if(typeof t!=`object`||!t||Array.isArray(t))throw TypeError(`[router.addRoute] Route must be an object, got ${b(t)}`);H(t,t.name)}}function nt(e){if(typeof e!=`string`||e===``)throw TypeError(`[router.addRoute] parent option must be a non-empty string, got ${b(e)}`);y(e,`addRoute`)}function rt(e,t,n,r){if(!_(e))throw TypeError(`[router.isActiveRoute] name must be a string, got ${typeof e}`);if(t!==void 0&&!m(t))throw TypeError(`[router.isActiveRoute] params must be a plain object, got ${b(t)}`);if(n!==void 0&&typeof n!=`boolean`)throw TypeError(`[router.isActiveRoute] strictEquality must be a boolean, got ${typeof n}`);if(r!==void 0&&typeof r!=`boolean`)throw TypeError(`[router.isActiveRoute] ignoreQueryParams must be a boolean, got ${typeof r}`)}function Z(e,t,n){if(!_(e))throw TypeError(`[router.${n}] Invalid routeName: ${b(e)}. Expected string.`);if(!m(t))throw TypeError(`[router.${n}] Invalid routeParams: ${b(t)}. Expected plain object.`)}function it(e,t){if(y(e,`updateRoute`),e===``)throw ReferenceError(`[router.updateRoute] Invalid name: empty string. Cannot update root node.`);if(t===null)throw TypeError(`[router.updateRoute] updates must be an object, got null`);if(typeof t!=`object`||Array.isArray(t))throw TypeError(`[router.updateRoute] updates must be an object, got ${b(t)}`)}function Q(e,t){if(e.constructor.name===`AsyncFunction`||e.toString().includes(`__awaiter`))throw TypeError(`[router.updateRoute] ${t} cannot be an async function`)}function $(e,t){if(e!=null){if(typeof e!=`function`)throw TypeError(`[router.updateRoute] ${t} must be a function or null, got ${typeof e}`);Q(e,t)}}function at(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 ${b(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 ${b(t)}`);$(n,`decodeParams`),$(r,`encodeParams`)}function ot(e){if(!_(e)||e===``)throw TypeError(`[router.buildPath] route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`)}function st(e){if(!_(e))throw TypeError(`[router.matchPath] path must be a string, got ${typeof e}`)}function ct(e){if(!_(e))throw TypeError(`[router.shouldUpdateNode] nodeName must be a string, got ${typeof e}`)}function lt(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&&Xe(e,i,r,a)}function ut(e){let t=new Set;for(let n of e)for(let e of n.paramMeta.urlParams)t.add(e);return t}function dt(e,t,n){let r=n.getSegmentsByName(e),i=n.getSegmentsByName(t),a=ut(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 ft(t,n,r){(0,e.resolveForwardChain)(t,{...r.forwardMap,[t]:n})}function pt(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`);dt(e,t,r),ft(e,t,i)}}function mt(e,t,n){if(!_(e))throw TypeError(`[router.makeState] Invalid name: ${b(e)}. Expected string.`);if(t!==void 0&&!m(t))throw TypeError(`[router.makeState] Invalid params: ${b(t)}. Expected plain object.`);if(n!==void 0&&!_(n))throw TypeError(`[router.makeState] Invalid path: ${b(n)}. Expected string.`)}function ht(e){return{routes:{validateBuildPathArgs:ot,validateMatchPathArgs:st,validateIsActiveRouteArgs:rt,validateShouldUpdateNodeArgs:ct,validateStateBuilderArgs:Z,validateAddRouteArgs(e){tt(e)},validateRoutes(e,t,n){let r=t;lt(e,r.tree,r.matcher,r.config?.forwardMap,n)},validateRemoveRouteArgs:Ze,validateUpdateRouteBasicArgs:it,validateUpdateRoutePropertyTypes(e,t){let n=t;at(n.forwardTo,n.defaultParams,n.decodeParams,n.encodeParams)},validateUpdateRoute(e,t,n){let r=n,i=t.forwardTo;pt(e,i,e=>r.matcher.hasRoute(e),r.matcher,r.config)},validateParentOption(e,t){nt(e);let n=t;for(let t of e.split(`.`)){let r=n.children.get(t);if(!r)throw ReferenceError(`[router.addRoute] Parent route "${e}" does not exist`);n=r}},validateRouteName(e,t){y(e,t)},throwIfInternalRoute(e,t){J(e,t)},throwIfInternalRouteInArray(e,t){Y(e,t)},validateSetRootPathArgs:Qe,guardRouteCallbacks:$e,guardNoAsyncCallbacks:et},options:{validateOptions:Ee,validateResolvedDefaultRoute:V},dependencies:{validateDependencyName:ie,validateSetDependencyArgs(e,t,n){ae(e)},validateDependenciesObject:oe,validateDependencyExists(e,t){let n=t.dependencies?.[e];se(n,e)},validateDependencyCount:ce,validateCloneArgs:le,warnOverwrite:ue,warnBatchOverwrite:de,warnRemoveNonExistent:fe},plugins:{validatePluginLimit(e,t){Oe(e,1,t?.maxPlugins)},validateNoDuplicatePlugins:ke,validatePluginKeys:je,validateCountThresholds(t){Ae(t,e.getOptions().limits?.maxPlugins??50)},warnBatchDuplicates:Me,warnPluginMethodType:Ne,warnPluginAfterStart:Pe,validateAddInterceptorArgs:Fe},lifecycle:{validateHandler:ge,validateHandlerLimit(t,n){_e(t,n,e.getOptions().limits?.maxLifecycleHandlers??200)},validateCountThresholds(t,n){ve(t,n,e.getOptions().limits?.maxLifecycleHandlers??200)},warnOverwrite:ye,warnAsyncGuardSync:be},navigation:{validateNavigateArgs:S,validateNavigateToDefaultArgs:C,validateNavigateToStateArgs:w,validateNavigationOptions:T,validateParams:O,validateStartArgs:k},state:{validateMakeStateArgs:mt,validateAreStatesEqualArgs(e,t,n){if(!g(e))throw TypeError(`[router.areStatesEqual] Invalid state1: ${b(e)}. Expected State object.`);if(!g(t))throw TypeError(`[router.areStatesEqual] Invalid state2: ${b(t)}. Expected State object.`);if(n!==void 0&&!v(n))throw TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${b(n)}. Expected boolean.`)}},eventBus:{validateListenerArgs(e,t){he(e,t)}}}}function gt(){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=ht(r);try{let e=r.routeGetStore(),t=r.dependenciesGetStore(),n=r.getOptions();Le(e),Re(e),ze(e),Be(e),Ve(t),We(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=gt;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@real-router/core"),t=require("@real-router/core/validation"),n=require("@real-router/logger");const r=[`replace`,`reload`,`force`,`forceDeactivate`,`redirected`];function i(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;for(let e of r){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 a=/\S/,o=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function s(e,t){return TypeError(`[router.${e}] ${t}`)}function c(e){return typeof e==`string`?e===``?!0:e.length>1e4?!1:e.startsWith(`@@`)?!0:o.test(e):!1}function l(e){if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function u(e,t){let n=Array.isArray(e)?e:Object.values(e);for(let e of n)t.push(e)}function ee(e){let t=typeof e;return t===`string`||t===`boolean`?!0:t===`number`?Number.isFinite(e):!1}var d=class{container;constructor(e){this.container=e}};function f(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 te(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(!f(e,t,n,r))return!1;continue}if(!ee(e))return!1}}return!0}function ne(e){if(e==null)return!0;let t=typeof e;return t===`string`||t===`boolean`?!0:t===`number`?Number.isFinite(e):!1}function p(e){try{return re(e)}catch{return!1}}function re(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(!ne(r)){let e=typeof r;if(e===`function`||e===`symbol`)return!1;n=!0;break}}return n?te(e):!0}function m(e){return c(e.name)&&typeof e.path==`string`&&p(e.params)}function h(e){return typeof e!=`object`||!e?!1:m(e)}function g(e){return typeof e==`string`}function _(e){return typeof e==`boolean`}function ie(e,t){return e in t}function v(e,t){if(typeof e!=`string`)throw s(t,`Route name must be a string, got ${typeof e}`);if(e!==``){if(!a.test(e))throw s(t,`Route name cannot contain only whitespace`);if(e.length>1e4)throw s(t,`Route name exceeds maximum length of 10000 characters. This is a technical safety limit.`);if(!e.startsWith(`@@`)&&!o.test(e))throw s(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(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 b(e){return{warn:Math.floor(e*.2),error:Math.floor(e*.5)}}function ae(e,t){if(typeof e!=`string`)throw TypeError(`[router.${t}] dependency name must be a string, got ${typeof e}`)}function oe(e){if(typeof e!=`string`)throw TypeError(`[router.setDependency] dependency name must be a string, got ${typeof e}`)}function se(e,t){if(!(e&&typeof e==`object`&&e.constructor===Object))throw TypeError(`[router.${t}] Invalid argument: expected plain object, received ${y(e)}`);for(let n in e)if(Object.getOwnPropertyDescriptor(e,n)?.get)throw TypeError(`[router.${t}] Getters not allowed: "${n}"`)}function ce(e,t){if(e===void 0)throw ReferenceError(`[router.getDependency] dependency "${t}" not found`)}function le(e,t){let r=e,i=r.limits?.maxDependencies??100;if(i===0)return;let a=Object.keys(r.dependencies).length,{warn:o,error:s}=b(i);if(a>=i)throw RangeError(`[router.${t}] Dependency limit exceeded (${i}). Current: ${a}.`);a===s?n.logger.error(`router.${t}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${i}.`):a===o&&n.logger.warn(`router.${t}`,`${a} dependencies registered. Consider if all are necessary.`)}function ue(e){if(e!==void 0){if(!(e&&typeof e==`object`&&e.constructor===Object))throw TypeError(`[cloneRouter] Invalid dependencies: expected plain object or undefined, received ${typeof e}`);for(let t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw TypeError(`[cloneRouter] Getters not allowed in dependencies: "${t}"`)}}function de(e,t){n.logger.warn(`router.${t}`,`Router dependency already exists and is being overwritten:`,e)}function fe(e,t){n.logger.warn(`router.${t}`,`Overwritten:`,e.join(`, `))}function pe(e){n.logger.warn(`router.removeDependency`,`Attempted to remove non-existent dependency: "${typeof e==`string`?e:String(e)}"`)}const me=new Set([`$start`,`$stop`,`$$start`,`$$leaveApprove`,`$$cancel`,`$$success`,`$$error`]);function he(e){if(!me.has(e))throw TypeError(`[router.addEventListener] Invalid event name: ${String(e)}. Must be one of: $start, $stop, $$start, $$leaveApprove, $$cancel, $$success, $$error`)}function ge(e,t){if(he(e),typeof t!=`function`)throw TypeError(`[router.addEventListener] callback must be a function, got ${typeof t}`)}function _e(e,t,r,i=1e4){if(i===0)return;let{warn:a,error:o}=b(i);e>=o?n.logger.error(`router.${r}`,`${e} listeners registered for "${t}"! This is excessive. Hard limit at ${i}.`):e>=a&&n.logger.warn(`router.${r}`,`${e} listeners registered for "${t}". Consider whether all are necessary — a growing count usually means a missing unsubscribe.`)}function ve(e,t){if(!_(e)&&typeof e!=`function`)throw TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${y(e)}`)}function ye(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 be(e,t,r){if(r===0)return;let{warn:i,error:a}=b(r);e>=a?n.logger.error(`router.${t}`,`${e} lifecycle handlers registered! This is excessive. Hard limit at ${r}.`):e>=i&&n.logger.warn(`router.${t}`,`${e} lifecycle handlers registered. Consider consolidating logic.`)}function xe(e,t,r){n.logger.warn(`router.${r}`,`Overwriting existing ${t} handler for route "${e}"`)}function x(e,t){n.logger.warn(`router.${t}`,`Guard for "${e}" returned a Promise. Sync check cannot resolve async guards — returning false.`)}function S(e){if(typeof e!=`string`)throw TypeError(`[router.navigate] Invalid route name: expected string, got ${y(e)}`)}function C(e){if(e!==void 0&&(typeof e!=`object`||!e))throw TypeError(`[router.navigateToDefault] Invalid options: ${y(e)}. Expected NavigationOptions object.`)}function w(e){if(typeof e!=`object`||!e)throw TypeError(`[router.navigateToState] Invalid state: ${y(e)}. Expected State object.`);let t=e;if(!g(t.name))throw TypeError(`[router.navigateToState] Invalid state.name: ${y(t.name)}. Expected string.`);if(!p(t.params))throw TypeError(`[router.navigateToState] Invalid state.params: ${y(t.params)}. Expected plain object.`);if(!g(t.path))throw TypeError(`[router.navigateToState] Invalid state.path: ${y(t.path)}. Expected string.`)}function T(e,t){if(!i(e))throw TypeError(`[router.${t}] Invalid options: ${y(e)}. Expected NavigationOptions object.`)}const E=/[\u0000-\u001F\u007F]/;function D(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`&&E.test(r))throw TypeError(`[router.${t}] param "${n}" must not contain control characters (NUL / C0 / DEL) — they corrupt the URL path.`)}}function O(e,t){if(e!==void 0&&(typeof e==`object`&&e&&!Array.isArray(e)&&D(e,t),!p(e)))throw TypeError(`[router.${t}] params must be a plain object, got ${y(e)}`)}function k(e){if(e!==void 0&&typeof e!=`string`)throw TypeError(`[router.start] path must be a string, got ${y(e)}.`);if(typeof e==`string`){if(E.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`]},M=new Set([`defaultRoute`,`defaultParams`,`trailingSlash`,`caseSensitive`,`queryParamsMode`,`queryParams`,`urlParamsEncoding`,`allowNotFound`,`rewritePathOnMatch`,`logger`,`limits`]),N={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 Se(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=N[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 Ce(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(N,n))throw TypeError(`[router.${t}] unknown limit: "${n}"`);r!==void 0&&Se(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 P(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 we(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 Te(e,t){if(e!==void 0&&typeof e!=`function`&&(!e||typeof e!=`object`||Array.isArray(e)||e.constructor!==Object))throw TypeError(`[router.${t}] Invalid "defaultParams": expected plain object or function, got ${typeof e}`)}function Ee(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(!ie(e,j))throw TypeError(`[router.${t}] Invalid "queryParams.${e}": unknown option`);P(r,`queryParams.${e}`,j[e],t)}}function De(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(!M.has(e))throw TypeError(`[router.${t}] Unknown option: "${e}"`);if(we(n.defaultRoute,t),Te(n.defaultParams,t),P(n.trailingSlash,`trailingSlash`,A.trailingSlash,t),P(n.queryParamsMode,`queryParamsMode`,A.queryParamsMode,t),P(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}`);Ee(n.queryParams,t),n.limits!==void 0&&Ce(n.limits,t)}const F=`router.usePlugin`,Oe={onStart:!0,onStop:!0,onTransitionStart:!0,onTransitionLeaveApprove:!0,onTransitionSuccess:!0,onTransitionError:!0,onTransitionCancel:!0};function ke(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 Ae(e,t){if(t.includes(e))throw Error(`[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.`)}function je(e,t){if(t===0)return;let{warn:r,error:i}=b(t);e>=i?n.logger.error(F,`${e} plugins registered! This is excessive. Hard limit at ${t}.`):e>=r&&n.logger.warn(F,`${e} plugins registered. Consider if all are necessary.`)}function Me(e){for(let t in e)if(!(t===`teardown`||Object.hasOwn(Oe,t)))throw TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}function Ne(){n.logger.warn(F,`Duplicate factory in batch, will be registered once`)}function Pe(e){n.logger.warn(F,`Property '${e}' is not a function, skipping`)}function Fe(e){e===`onStart`&&n.logger.warn(F,`Router already started, onStart will not be called`)}function Ie(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 Le(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 Re(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(e.name.includes(`.`))throw TypeError(`[router.constructor] Route name "${e.name}" cannot contain dots. Use children array or { parent } option in addRoute() instead.`);if(typeof e.path!=`string`)throw TypeError(`[validation-plugin] validateExistingRoutes: route "${t}" has non-string path (${typeof e.path})`)})}function ze(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))Le(e,t.forwardMap)}function Be(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 Ve(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 He(e){if(!e||typeof e!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps must be an object`);let t=e;if(!t.dependencies||typeof t.dependencies!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.dependencies must be an object`);let n=t.dependencies;for(let e of Object.keys(n))if(Object.getOwnPropertyDescriptor(n,e)?.get)throw TypeError(`[validation-plugin] validateDependenciesStructure: dependency "${e}" must not use a getter`);if(!t.limits||typeof t.limits!=`object`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits must be an object`);let r=t.limits;for(let e of[`maxDependencies`,`maxPlugins`,`maxListeners`,`warnListeners`,`maxLifecycleHandlers`])if(typeof r[e]!=`number`)throw TypeError(`[validation-plugin] validateDependenciesStructure: deps.limits.${e} must be a number, got ${typeof r[e]}`)}function Ue(e){let t=e&&typeof e==`object`?e:{};return t.limits&&typeof t.limits==`object`?t.limits:{}}function We(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 Ge(e,t){We(t,Ue(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 Ke(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 ${y(e.canActivate)}`);if(e.canDeactivate!==void 0&&typeof e.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${y(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 ${y(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(Ke(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 Je(e,t,n,r){return t?q(n.getSegmentsByName(e)??[]):U(W(r,e))}const Ye=new Set;function Xe(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=[...Je(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 Ze(t,n,r,i){let a=G(t),o=i?new Set([...a].map(e=>`${i}.${e}`)):a,s=i?q(r.getSegmentsByName(i)):Ye,c=K(t),l={...n};for(let[e,t]of c)l[e]=t;for(let[e,n]of c)Xe(e,n,t,o,r,s);for(let t of Object.keys(l))(0,e.resolveForwardChain)(t,l)}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 Qe(e){v(e,`removeRoute`)}function $e(e){if(typeof e!=`string`)throw TypeError(`[router.setRootPath] rootPath must be a string, got ${y(e)}`)}function X(e){return e.constructor.name===`AsyncFunction`||String(e).includes(`__awaiter`)}function et(e){let t=e;if(t.canActivate!==void 0&&typeof t.canActivate!=`function`)throw TypeError(`[router.addRoute] canActivate must be a function, got ${y(t.canActivate)}`);if(t.canDeactivate!==void 0&&typeof t.canDeactivate!=`function`)throw TypeError(`[router.addRoute] canDeactivate must be a function, got ${y(t.canDeactivate)}`)}function tt(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 nt(e){for(let t of e){if(typeof t!=`object`||!t||Array.isArray(t))throw TypeError(`[router.addRoute] Route must be an object, got ${y(t)}`);H(t,t.name)}}function rt(e){if(typeof e!=`string`||e===``)throw TypeError(`[router.addRoute] parent option must be a non-empty string, got ${y(e)}`);v(e,`addRoute`)}function Z(e,t,n,r){if(!g(e))throw TypeError(`[router.isActiveRoute] name must be a string, got ${typeof e}`);if(t!==void 0&&!p(t))throw TypeError(`[router.isActiveRoute] params must be a plain object, got ${y(t)}`);if(n!==void 0&&typeof n!=`boolean`)throw TypeError(`[router.isActiveRoute] strictEquality must be a boolean, got ${typeof n}`);if(r!==void 0&&typeof r!=`boolean`)throw TypeError(`[router.isActiveRoute] ignoreQueryParams must be a boolean, got ${typeof r}`)}function it(e,t,n){if(!g(e))throw TypeError(`[router.${n}] Invalid routeName: ${y(e)}. Expected string.`);if(!p(t))throw TypeError(`[router.${n}] Invalid routeParams: ${y(t)}. Expected plain object.`)}function at(e,t){if(v(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 ${y(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 ot(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 ${y(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 ${y(t)}`);$(n,`decodeParams`),$(r,`encodeParams`)}function st(e){if(!g(e)||e===``)throw TypeError(`[router.buildPath] route must be a non-empty string, got ${typeof e==`string`?`""`:typeof e}`)}function ct(e){if(!g(e))throw TypeError(`[router.matchPath] path must be a string, got ${typeof e}`)}function lt(e){if(!g(e))throw TypeError(`[router.shouldUpdateNode] nodeName must be a string, got ${typeof e}`)}function ut(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&&Ze(e,i,r,a)}function dt(e){let t=new Set;for(let n of e)for(let e of n.paramMeta.urlParams)t.add(e);return t}function ft(e,t,n){let r=n.getSegmentsByName(e),i=n.getSegmentsByName(t),a=dt(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 pt(t,n,r){(0,e.resolveForwardChain)(t,{...r.forwardMap,[t]:n})}function mt(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`);ft(e,t,r),pt(e,t,i)}}function ht(e,t,n){if(!g(e))throw TypeError(`[router.makeState] Invalid name: ${y(e)}. Expected string.`);if(t!==void 0&&!p(t))throw TypeError(`[router.makeState] Invalid params: ${y(t)}. Expected plain object.`);if(n!==void 0&&!g(n))throw TypeError(`[router.makeState] Invalid path: ${y(n)}. Expected string.`)}function gt(e){return{routes:{validateBuildPathArgs:st,validateMatchPathArgs:ct,validateIsActiveRouteArgs:Z,validateShouldUpdateNodeArgs:lt,validateStateBuilderArgs:it,validateAddRouteArgs(e){nt(e)},validateRoutes(e,t,n){let r=t;ut(e,r.tree,r.matcher,r.config?.forwardMap,n)},validateRemoveRouteArgs:Qe,validateUpdateRouteBasicArgs:at,validateUpdateRoutePropertyTypes(e,t){let n=t;ot(n.forwardTo,n.defaultParams,n.decodeParams,n.encodeParams)},validateUpdateRoute(e,t,n){let r=n,i=t.forwardTo;mt(e,i,e=>r.matcher.hasRoute(e),r.matcher,r.config)},validateParentOption(e,t){rt(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){v(e,t)},throwIfInternalRoute(e,t){J(e,t)},throwIfInternalRouteInArray(e,t){Y(e,t)},validateSetRootPathArgs:$e,guardRouteCallbacks:et,guardNoAsyncCallbacks:tt},options:{validateOptions:De,validateResolvedDefaultRoute:V},dependencies:{validateDependencyName:ae,validateSetDependencyArgs(e,t,n){oe(e)},validateDependenciesObject:se,validateDependencyExists(e,t){let n=t.dependencies?.[e];ce(n,e)},validateDependencyCount:le,validateCloneArgs:ue,warnOverwrite:de,warnBatchOverwrite:fe,warnRemoveNonExistent:pe},plugins:{validatePluginLimit(e,t){ke(e,1,t?.maxPlugins)},validateNoDuplicatePlugins:Ae,validatePluginKeys:Me,validateCountThresholds(t){je(t,e.getOptions().limits?.maxPlugins??50)},warnBatchDuplicates:Ne,warnPluginMethodType:Pe,warnPluginAfterStart:Fe,validateAddInterceptorArgs:Ie},lifecycle:{validateHandler:ve,validateHandlerLimit(t,n){ye(t,n,e.getOptions().limits?.maxLifecycleHandlers??200)},validateCountThresholds(t,n){be(t,n,e.getOptions().limits?.maxLifecycleHandlers??200)},warnOverwrite:xe,warnAsyncGuardSync:x},navigation:{validateNavigateArgs:S,validateNavigateToDefaultArgs:C,validateNavigateToStateArgs:w,validateNavigationOptions:T,validateParams:O,validateStartArgs:k},state:{validateMakeStateArgs:ht,validateAreStatesEqualArgs(e,t,n){if(!h(e))throw TypeError(`[router.areStatesEqual] Invalid state1: ${y(e)}. Expected State object.`);if(!h(t))throw TypeError(`[router.areStatesEqual] Invalid state2: ${y(t)}. Expected State object.`);if(n!==void 0&&!_(n))throw TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${y(n)}. Expected boolean.`)}},eventBus:{validateListenerArgs(e,t){ge(e,t)},validateCountThresholds(t,n,r){_e(t,n,r,e.getOptions().limits?.maxListeners??1e4)}}}}function _t(){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=gt(r);try{let e=r.routeGetStore(),t=r.dependenciesGetStore(),n=r.getOptions();Re(e),ze(e),Be(e),Ve(e),He(t),Ge(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=_t;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|