@real-router/core 0.134.1 → 0.135.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@real-router/core",
3
- "version": "0.134.1",
3
+ "version": "0.135.0",
4
4
  "type": "commonjs",
5
5
  "description": "A simple, powerful, view-agnostic, modular and extensible router",
6
6
  "main": "./dist/cjs/index.js",
@@ -1,2 +0,0 @@
1
- const e=require("./RouterError-C-p1yaby.js"),t=Object.hasOwn;function n(e,n){if(n.length!==0&&e!=null)for(let r of n){if(!t(e,r))continue;let n;try{n=e[r]}catch{return}if(n!==void 0)return r}}function r(e,t,r,i,o,s){let c=n(r,i);if(c!==void 0)throw TypeError(`[router.${e}] ${a(t,c,typeof o==`function`?o():o,s)}`)}function i(e,t,n,i){r(e,t,n,i,"the `params` bag this call is about to ship — the channel check above it read a different value, so the caller's object answered differently between the two reads")}function a(e,t,n="the `params` argument",r="Pass it in `search` instead"){return`Route "${e}" declares \`${t}\` as a query param, but it was given in ${n} — the path channel. ${r}; the two channels are separate since RFC-4 M2 and the router never moves a key between them.`}const o=e=>e===58||e===42;function s(e){let t=[],n=0;for(let r=0;r<e.length;r+=1)e.charCodeAt(r)===47&&(t.push(e.slice(n,r)),n=r+1);return t.push(e.slice(n)),t}function c(e){let t=e.length;if(t===0)return{kind:`static`,text:``};if(!o(e.charCodeAt(0))){for(let n=0;n<t;n+=1){let r=e.charCodeAt(n);if(r===60||r===62)return{error:`constraint-removed`};if(o(r)&&n+1<t)return{error:`fused-marker`}}return e.charCodeAt(t-1)===63?{error:`name-less`}:{kind:`static`,text:e}}let n=e.charCodeAt(0)===42,r=1;for(;r<t;){let t=e.charCodeAt(r);if(t===60||t===62||t===63)break;r+=1}let i=e.slice(1,r);return i.length===0?{error:`name-less`}:o(i.charCodeAt(i.length-1))?{error:`trailing-marker`}:r<t?e.charCodeAt(r)===63?{error:`optional-removed`}:{error:`constraint-removed`}:n?{kind:`splat`,name:i}:{kind:`param`,name:i}}function l(e){for(let t of s(e)){let e=c(t);if(`error`in e)return e.error}}function u(e){let t=s(e);for(let e=0;e<t.length;e+=1){let n=c(t[e]);if(`error`in n){if(n.error===`optional-removed`){let n=t[e],r=[...t];return r[e]=n.slice(0,n.indexOf(`?`)),{code:`optional-removed`,segment:n,withoutSegment:t.filter((t,n)=>n!==e).join(`/`),requiredForm:r.join(`/`)}}return n.error===`constraint-removed`?{code:`constraint-removed`,segment:t[e]}:void 0}}}const d=/[<>]/u;function f(e){for(let t=0;t<e.length;t+=1){if(e.codePointAt(t)!==63)continue;let n=t+1<e.length?e.codePointAt(t+1):-1;if(n!==-1&&n!==47&&n!==63&&n!==60)return t}return-1}const p=Object.freeze([]),m=Object.freeze({}),h=Object.freeze({urlParams:p,queryParams:p,paramTypeMap:m,pathPattern:``});function g(e,t,n){for(let r of s(e)){if(r.length===0)continue;let e=c(r);`error`in e||e.kind===`static`||(t.push(e.name),n[e.name]=`url`)}}function _(t){let n=[],r=[],i=e.a(),a=f(t);if(a!==-1){let e=t.slice(a+1).split(`&`);for(let t of e){let e=t.trim();e.length>0&&(r.push(e),i[e]=`query`)}t=t.slice(0,a)}return g(t,n,i),v(n,r,e.o(i),t)}function v(e,t,n,r){return{urlParams:e.length===0?p:e,queryParams:t.length===0?p:t,paramTypeMap:e.length===0&&t.length===0?m:n,pathPattern:r}}const y=/^[A-Z_a-z][\w-]*$/,ee=/\S/,b=1e4;function x(e,t){if(e===``)throw TypeError(`[router.${t}] Route name cannot be empty`)}function S(e,t){if(!ee.test(e))throw TypeError(`[router.${t}] Route name cannot contain only whitespace`)}function C(e,t){if(e.length>b)throw TypeError(`[router.${t}] Route name exceeds maximum length of ${b} characters`)}function w(e,t){if(e.includes(`.`))throw TypeError(`[router.${t}] Route name "${e}" cannot contain dots. Use children array or { parent } option in addRoute() instead.`)}function T(e,t){if(!y.test(e))throw TypeError(`[router.${t}] Invalid route name "${e}". Name must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens.`)}function E(e,t){return TypeError(`[router.${e}] ${t}`)}function D(e,t,n,r){let i=new Set;for(let a of e){if(i.has(a))throw E(n,`Invalid path for route "${t}": duplicate parameter name ':${a}' in "${r}" (a param name must be unique within a route — the second binding would overwrite the first)`);i.add(a)}}function O(e,t,n,r){for(let i of e)if(d.test(i))throw E(n,`Invalid path for route "${t}": invalid query-param name "${i}" in "${r}" (a query-param name cannot contain '<' or '>' — it would never round-trip; rename the query param)`)}function k(e){let t=!0,n=!1;for(let r of e){if(r===`/`){t=!0;continue}if(t&&=(n=r===`:`||r===`*`,!1),!n&&r.codePointAt(0)>=128)return!0}return!1}function A(e,t,n){switch(e){case`name-less`:case`trailing-marker`:return`Invalid path for route "${t}": parameter marker (':' or '*') without a name in "${n}"`;case`fused-marker`:return`Invalid path for route "${t}": parameter marker (':' or '*') must begin a segment, but "${n}" fuses one to a static prefix (use a boundary marker like "/a/:b")`}}function j(e,t){return e.code===`optional-removed`?`Invalid path for route "${t}": optional params are not supported — "${e.segment}". Declare two sibling routes instead: "${e.withoutSegment}" and "${e.requiredForm}" (the route hierarchy already expresses optionality)`:`Invalid path for route "${t}": regex constraints are not supported — '<' and '>' are reserved in path segments ("${e.segment}"). Match the segment as a plain string and validate the value in a guard (canActivate) or app code`}function M(e,t,n,r){if(typeof e!=`string`){let t;throw t=e===null?`null`:Array.isArray(e)?`array`:typeof e,E(n,`Route path must be a string, got ${t}`)}if(e===``)return;if(/\s/.test(e))throw E(n,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw E(n,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes(`//`))throw E(n,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);let{pathPattern:i,urlParams:a,queryParams:o}=_(e);D(a,t,n,e),O(o,t,n,e);let s=u(i);if(s!==void 0)throw E(n,j(s,t));let c=l(i);if(c!==void 0)throw E(n,A(c,t,e));if(k(i))throw E(n,`Invalid path for route "${t}": non-ASCII static segment in "${e}" — match compares static segments raw and rejects non-ASCII input, so this route would never match. Percent-encode it (e.g. '/caf%C3%A9') or use a param`);let d=r&&r.paramMeta.urlParams.length>0;if(e.startsWith(`~`)&&d)throw E(n,`Absolute path "${e}" cannot be used under parent route with URL parameters`)}const N=Object.getOwnPropertyDescriptor,P=Object.keys,F=Object.getPrototypeOf;function I(e){if(e===null)return`null`;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 L(e){for(let t of P(e)){let n=N(e,t);if(n&&(n.get||n.set))return!0}return!1}function R(e,t){if(!e||typeof e!=`object`)throw TypeError(`[router.${t}] Route must be an object, got ${I(e)}`);let n=F(e);if(n!==Object.prototype&&n!==null)throw TypeError(`[router.${t}] Route must be a plain object, got ${I(e)}`);if(L(e))throw TypeError(`[router.${t}] Route must not have getters or setters`)}function z(e,t){if(e.encodeParams!==void 0&&typeof e.encodeParams!=`function`)throw TypeError(`[router.${t}] Route "${String(e.name)}" encodeParams must be a function`)}function B(e,t){if(e.decodeParams!==void 0&&typeof e.decodeParams!=`function`)throw TypeError(`[router.${t}] Route "${String(e.name)}" decodeParams must be a function`)}function V(e,t){if(typeof e.name!=`string`)throw TypeError(`[router.${t}] Route name must be a string, got ${I(e.name)}`);let n=e.name;x(n,t),S(n,t),C(n,t),!n.startsWith(`@@`)&&(w(n,t),T(n,t))}function H(e,t){if(!t.includes(`.`))return e.children.get(t);let n=e;for(let e of t.split(`.`))if(n=n.children.get(e),!n)return;return n}function U(e,t,n){if(H(e,t))throw Error(`[router.${n}] Route "${t}" already exists`)}function W(e,t,n){if(e.has(t))throw Error(`[router.${n}] Duplicate route "${t}" in batch`);e.add(t)}function G(e,t,n,r){let i=t===``?e:H(e,t);if(i){for(let e of i.children.values())if(e.path===n)throw Error(`[router.${r}] Path "${n}" is already defined`)}}function K(e,t,n,r){let i=e.get(t);if(i?.has(n))throw Error(`[router.${r}] Path "${n}" is already defined`);i?i.add(n):e.set(t,new Set([n]))}function q(e,t,n,r=``,i,a){R(e,t);let o=e;V(o,t),M(o.path,o.name,t,n),z(o,t),B(o,t);let s=o.name,c=r?`${r}.${s}`:s;n&&c&&U(n,c,t),i&&W(i,c,t);let l=o.path,u=r;if(n&&G(n,u,l,t),a&&K(a,u,l,t),o.children!==void 0){if(!Array.isArray(o.children))throw TypeError(`[router.${t}] Route "${s}" children must be an array, got ${I(o.children)}`);for(let e of o.children)q(e,t,n,c,i,a)}}const J=new WeakMap;function Y(e){let t=J.get(e);if(!t)throw TypeError(`[real-router] Invalid router instance — not found in internals registry`);return t}function X(e,t,n,i){r(t,n,i,e.getQueryParams(n))}function Z(t){if(t())throw e.n(new e.t(e.g.ROUTER_DISPOSED))}function Q(e,t){J.set(e,t)}function $(e,t,n,r){let i=t;for(let t of e){let e=i,n=r===void 0?e:(...t)=>r(e(...t));i=(...e)=>t(n,...e)}return i(...n)}const te={start:`start`,forwardState:`forwardState`};function ne(e,t,n){return((...r)=>{let i=n.get(e);return!i||i.length===0?t(...r):$(i,t,r)})}function re(e,t,n,r,i){return(a,o,s)=>{let c=n.get(e);return!c||c.length===0?t(a,o,s):$(c,t,i(a,o,s),r)}}Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return re}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return n}});
2
- //# sourceMappingURL=internals-M-DOGwyl.js.map
@@ -1,2 +0,0 @@
1
- import{a as e,g as t,n,o as r,t as i}from"./RouterError-gEM9-BIR.mjs";const a=Object.hasOwn;function o(e,t){if(t.length!==0&&e!=null)for(let n of t){if(!a(e,n))continue;let t;try{t=e[n]}catch{return}if(t!==void 0)return n}}function s(e,t,n,r,i,a){let s=o(n,r);if(s!==void 0)throw TypeError(`[router.${e}] ${l(t,s,typeof i==`function`?i():i,a)}`)}function c(e,t,n,r){s(e,t,n,r,"the `params` bag this call is about to ship — the channel check above it read a different value, so the caller's object answered differently between the two reads")}function l(e,t,n="the `params` argument",r="Pass it in `search` instead"){return`Route "${e}" declares \`${t}\` as a query param, but it was given in ${n} — the path channel. ${r}; the two channels are separate since RFC-4 M2 and the router never moves a key between them.`}const u=e=>e===58||e===42;function d(e){let t=[],n=0;for(let r=0;r<e.length;r+=1)e.charCodeAt(r)===47&&(t.push(e.slice(n,r)),n=r+1);return t.push(e.slice(n)),t}function f(e){let t=e.length;if(t===0)return{kind:`static`,text:``};if(!u(e.charCodeAt(0))){for(let n=0;n<t;n+=1){let r=e.charCodeAt(n);if(r===60||r===62)return{error:`constraint-removed`};if(u(r)&&n+1<t)return{error:`fused-marker`}}return e.charCodeAt(t-1)===63?{error:`name-less`}:{kind:`static`,text:e}}let n=e.charCodeAt(0)===42,r=1;for(;r<t;){let t=e.charCodeAt(r);if(t===60||t===62||t===63)break;r+=1}let i=e.slice(1,r);return i.length===0?{error:`name-less`}:u(i.charCodeAt(i.length-1))?{error:`trailing-marker`}:r<t?e.charCodeAt(r)===63?{error:`optional-removed`}:{error:`constraint-removed`}:n?{kind:`splat`,name:i}:{kind:`param`,name:i}}function p(e){for(let t of d(e)){let e=f(t);if(`error`in e)return e.error}}function m(e){let t=d(e);for(let e=0;e<t.length;e+=1){let n=f(t[e]);if(`error`in n){if(n.error===`optional-removed`){let n=t[e],r=[...t];return r[e]=n.slice(0,n.indexOf(`?`)),{code:`optional-removed`,segment:n,withoutSegment:t.filter((t,n)=>n!==e).join(`/`),requiredForm:r.join(`/`)}}return n.error===`constraint-removed`?{code:`constraint-removed`,segment:t[e]}:void 0}}}const h=/[<>]/u;function g(e){for(let t=0;t<e.length;t+=1){if(e.codePointAt(t)!==63)continue;let n=t+1<e.length?e.codePointAt(t+1):-1;if(n!==-1&&n!==47&&n!==63&&n!==60)return t}return-1}const _=Object.freeze([]),v=Object.freeze({}),y=Object.freeze({urlParams:_,queryParams:_,paramTypeMap:v,pathPattern:``});function b(e,t,n){for(let r of d(e)){if(r.length===0)continue;let e=f(r);`error`in e||e.kind===`static`||(t.push(e.name),n[e.name]=`url`)}}function x(t){let n=[],i=[],a=e(),o=g(t);if(o!==-1){let e=t.slice(o+1).split(`&`);for(let t of e){let e=t.trim();e.length>0&&(i.push(e),a[e]=`query`)}t=t.slice(0,o)}return b(t,n,a),S(n,i,r(a),t)}function S(e,t,n,r){return{urlParams:e.length===0?_:e,queryParams:t.length===0?_:t,paramTypeMap:e.length===0&&t.length===0?v:n,pathPattern:r}}const C=/^[A-Z_a-z][\w-]*$/,w=/\S/,T=1e4;function E(e,t){if(e===``)throw TypeError(`[router.${t}] Route name cannot be empty`)}function ee(e,t){if(!w.test(e))throw TypeError(`[router.${t}] Route name cannot contain only whitespace`)}function D(e,t){if(e.length>T)throw TypeError(`[router.${t}] Route name exceeds maximum length of ${T} characters`)}function O(e,t){if(e.includes(`.`))throw TypeError(`[router.${t}] Route name "${e}" cannot contain dots. Use children array or { parent } option in addRoute() instead.`)}function k(e,t){if(!C.test(e))throw TypeError(`[router.${t}] Invalid route name "${e}". Name must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens.`)}function A(e,t){return TypeError(`[router.${e}] ${t}`)}function j(e,t,n,r){let i=new Set;for(let a of e){if(i.has(a))throw A(n,`Invalid path for route "${t}": duplicate parameter name ':${a}' in "${r}" (a param name must be unique within a route — the second binding would overwrite the first)`);i.add(a)}}function M(e,t,n,r){for(let i of e)if(h.test(i))throw A(n,`Invalid path for route "${t}": invalid query-param name "${i}" in "${r}" (a query-param name cannot contain '<' or '>' — it would never round-trip; rename the query param)`)}function N(e){let t=!0,n=!1;for(let r of e){if(r===`/`){t=!0;continue}if(t&&=(n=r===`:`||r===`*`,!1),!n&&r.codePointAt(0)>=128)return!0}return!1}function P(e,t,n){switch(e){case`name-less`:case`trailing-marker`:return`Invalid path for route "${t}": parameter marker (':' or '*') without a name in "${n}"`;case`fused-marker`:return`Invalid path for route "${t}": parameter marker (':' or '*') must begin a segment, but "${n}" fuses one to a static prefix (use a boundary marker like "/a/:b")`}}function F(e,t){return e.code===`optional-removed`?`Invalid path for route "${t}": optional params are not supported — "${e.segment}". Declare two sibling routes instead: "${e.withoutSegment}" and "${e.requiredForm}" (the route hierarchy already expresses optionality)`:`Invalid path for route "${t}": regex constraints are not supported — '<' and '>' are reserved in path segments ("${e.segment}"). Match the segment as a plain string and validate the value in a guard (canActivate) or app code`}function I(e,t,n,r){if(typeof e!=`string`){let t;throw t=e===null?`null`:Array.isArray(e)?`array`:typeof e,A(n,`Route path must be a string, got ${t}`)}if(e===``)return;if(/\s/.test(e))throw A(n,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw A(n,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes(`//`))throw A(n,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);let{pathPattern:i,urlParams:a,queryParams:o}=x(e);j(a,t,n,e),M(o,t,n,e);let s=m(i);if(s!==void 0)throw A(n,F(s,t));let c=p(i);if(c!==void 0)throw A(n,P(c,t,e));if(N(i))throw A(n,`Invalid path for route "${t}": non-ASCII static segment in "${e}" — match compares static segments raw and rejects non-ASCII input, so this route would never match. Percent-encode it (e.g. '/caf%C3%A9') or use a param`);let l=r&&r.paramMeta.urlParams.length>0;if(e.startsWith(`~`)&&l)throw A(n,`Absolute path "${e}" cannot be used under parent route with URL parameters`)}const L=Object.getOwnPropertyDescriptor,R=Object.keys,z=Object.getPrototypeOf;function B(e){if(e===null)return`null`;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){for(let t of R(e)){let n=L(e,t);if(n&&(n.get||n.set))return!0}return!1}function H(e,t){if(!e||typeof e!=`object`)throw TypeError(`[router.${t}] Route must be an object, got ${B(e)}`);let n=z(e);if(n!==Object.prototype&&n!==null)throw TypeError(`[router.${t}] Route must be a plain object, got ${B(e)}`);if(V(e))throw TypeError(`[router.${t}] Route must not have getters or setters`)}function te(e,t){if(e.encodeParams!==void 0&&typeof e.encodeParams!=`function`)throw TypeError(`[router.${t}] Route "${String(e.name)}" encodeParams must be a function`)}function U(e,t){if(e.decodeParams!==void 0&&typeof e.decodeParams!=`function`)throw TypeError(`[router.${t}] Route "${String(e.name)}" decodeParams must be a function`)}function W(e,t){if(typeof e.name!=`string`)throw TypeError(`[router.${t}] Route name must be a string, got ${B(e.name)}`);let n=e.name;E(n,t),ee(n,t),D(n,t),!n.startsWith(`@@`)&&(O(n,t),k(n,t))}function G(e,t){if(!t.includes(`.`))return e.children.get(t);let n=e;for(let e of t.split(`.`))if(n=n.children.get(e),!n)return;return n}function K(e,t,n){if(G(e,t))throw Error(`[router.${n}] Route "${t}" already exists`)}function q(e,t,n){if(e.has(t))throw Error(`[router.${n}] Duplicate route "${t}" in batch`);e.add(t)}function J(e,t,n,r){let i=t===``?e:G(e,t);if(i){for(let e of i.children.values())if(e.path===n)throw Error(`[router.${r}] Path "${n}" is already defined`)}}function Y(e,t,n,r){let i=e.get(t);if(i?.has(n))throw Error(`[router.${r}] Path "${n}" is already defined`);i?i.add(n):e.set(t,new Set([n]))}function X(e,t,n,r=``,i,a){H(e,t);let o=e;W(o,t),I(o.path,o.name,t,n),te(o,t),U(o,t);let s=o.name,c=r?`${r}.${s}`:s;n&&c&&K(n,c,t),i&&q(i,c,t);let l=o.path,u=r;if(n&&J(n,u,l,t),a&&Y(a,u,l,t),o.children!==void 0){if(!Array.isArray(o.children))throw TypeError(`[router.${t}] Route "${s}" children must be an array, got ${B(o.children)}`);for(let e of o.children)X(e,t,n,c,i,a)}}const Z=new WeakMap;function Q(e){let t=Z.get(e);if(!t)throw TypeError(`[real-router] Invalid router instance — not found in internals registry`);return t}function ne(e,t,n,r){s(t,n,r,e.getQueryParams(n))}function re(e){if(e())throw n(new i(t.ROUTER_DISPOSED))}function ie(e,t){Z.set(e,t)}function $(e,t,n,r){let i=t;for(let t of e){let e=i,n=r===void 0?e:(...t)=>r(e(...t));i=(...e)=>t(n,...e)}return i(...n)}const ae={start:`start`,forwardState:`forwardState`};function oe(e,t,n){return((...r)=>{let i=n.get(e);return!i||i.length===0?t(...r):$(i,t,r)})}function se(e,t,n,r,i){return(a,o,s)=>{let c=n.get(e);return!c||c.length===0?t(a,o,s):$(c,t,i(a,o,s),r)}}export{s as _,ie as a,l as b,X as c,E as d,y as f,d as g,f as h,Q as i,H as l,x as m,oe as n,re as o,h as p,se as r,ne as s,ae as t,O as u,c as v,o as y};
2
- //# sourceMappingURL=internals-cRXzvqP_.mjs.map