klaim 1.7.46 → 1.7.48

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/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antharuu/klaim",
3
- "version": "1.7.46",
3
+ "version": "1.7.48",
4
4
  "description": "Klaim is a lightweight TypeScript library designed to manage APIs and record requests, optimized for an optimal user experience.",
5
5
  "repository": {
6
6
  "type": "git",
package/dist/klaim.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var T=Object.defineProperty;var R=(s,t,e)=>t in s?T(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var o=(s,t,e)=>R(s,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function b(s){return s.replace(/([-_][a-z])/gi,t=>t.toUpperCase().replace("-","").replace("_","")).replace(/(^\w)/,t=>t.toLowerCase())}function K(s){return s.trim().replace(/^\/|\/$/g,"")}class C{constructor(t,e,a,r={}){o(this,"type");o(this,"name");o(this,"url");o(this,"headers");o(this,"parent");o(this,"method");o(this,"arguments",new Set);o(this,"schema");o(this,"callbacks",{before:null,after:null,call:null});o(this,"cache",!1);o(this,"retry",!1);this.type=t,this.name=b(e),this.name!==e&&console.warn(`Name "${e}" has been camelCased to "${this.name}"`),this.url=K(a),this.headers=r||{}}before(t){return this.callbacks.before=t,this}after(t){return this.callbacks.after=t,this}onCall(t){return this.callbacks.call=t,this}withCache(t=20){return this.cache=t,this}withRetry(t=2){return this.retry=t,this}}const p=class p{constructor(){o(this,"cache");this.cache=new Map}static get i(){return p._instance||(p._instance=new p),p._instance}set(t,e,a=0){const r=Date.now()+a;this.cache.set(t,{data:e,expiry:r})}has(t){const e=this.cache.get(t);return e?Date.now()>e.expiry?(this.cache.delete(t),!1):!0:!1}get(t){return this.has(t)?this.cache.get(t).data:null}};o(p,"_instance");let g=p;function N(s){let a=2166136261;for(let n=0;n<s.length;n++)a^=s.charCodeAt(n),a*=16777619;let r=(a>>>0).toString(16).padStart(8,"0");for(;r.length<32;)a^=r.charCodeAt(r.length%r.length),a*=16777619,r+=(a>>>0).toString(16).padStart(8,"0");return r.substring(0,32)}async function j(s,t,e){const a=`${s.toString()}${JSON.stringify(t)}`,r=N(a);if(g.i.has(r))return g.i.get(r);const c=await(await fetch(s,t)).json();return g.i.set(r,c,e),c}class E{static subscribe(t,e){this._callbacks.set(t,e)}static run(t){const e=this._callbacks.get(t);e&&e()}}o(E,"_callbacks",new Map);const m={};async function x(s,t,e={},a={}){const r=s.split(".");let n;for(let y=0;y<r.length;y++){const v=r[y];if(n=i.i.getApi(v),n)break}if(!t||!n||t.type!=="route"||n.type!=="api")throw new Error(`Invalid path: ${s}.${t.name}`);let c=O(`${n.url}/${t.url}`,t,e),l={};a&&t.method!=="GET"&&(l.body=JSON.stringify(a)),l.headers={"Content-Type":"application/json",...n.headers,...t.headers},l.method=t.method;const{beforeRoute:h,beforeApi:f,beforeUrl:d,beforeConfig:P}=U({route:t,api:n,url:c,config:l});c=d,l=P,i.updateElement(f),i.updateElement(h);let w=await G(n,t,c,l);t.schema&&"validate"in t.schema&&(w=await t.schema.validate(w));const{afterRoute:_,afterApi:F,afterData:S}=H({route:t,api:n,response:w,data:w});return i.updateElement(F),i.updateElement(_),E.run(`${n.name}.${t.name}`),S}async function D(s,t,e,a){return s?await j(t,e,a.cache):await(await fetch(t,e)).json()}async function G(s,t,e,a){var f,d;const r=s.cache||t.cache,n=t.retry||s.retry||0;let c,l=!1,h=0;for(;h<=n&&!l;)try{(f=t.callbacks)!=null&&f.call?t.callbacks.call({}):(d=s.callbacks)!=null&&d.call&&s.callbacks.call({}),c=await D(!!r,e,a,s),l=!0}catch(P){if(h++,h>n)throw P.message=`Failed to fetch ${e} after ${n} attempts`,P}return c}function O(s,t,e){let a=s;return t.arguments.forEach(r=>{if(e[r]===void 0)throw new Error(`Argument ${r} is missing`);a=a.replace(`[${r}]`,e[r])}),a}function U({route:s,api:t,url:e,config:a}){var n,c;const r=(c=(n=s.callbacks).before)==null?void 0:c.call(n,{route:s,api:t,url:e,config:a});return{beforeRoute:(r==null?void 0:r.route)||s,beforeApi:(r==null?void 0:r.api)||t,beforeUrl:(r==null?void 0:r.url)||e,beforeConfig:(r==null?void 0:r.config)||a}}function H({route:s,api:t,response:e,data:a}){var n,c;const r=(c=(n=s.callbacks).after)==null?void 0:c.call(n,{route:s,api:t,response:e,data:a});return{afterRoute:(r==null?void 0:r.route)||s,afterApi:(r==null?void 0:r.api)||t,afterResponse:(r==null?void 0:r.response)||e,afterData:(r==null?void 0:r.data)||a}}const u=class u{constructor(){o(this,"_elements",new Map);o(this,"_currentParent",null)}static get i(){return u._instance||(u._instance=new u),u._instance}registerElement(t){const e=this._currentParent;e&&(t.parent=this.getFullPath(e));const a=this.getElementKey(t);if(this._elements.set(a,t),t.type==="api"||t.type==="group"){let r=m;if(e){const n=this.getFullPath(e).split(".");for(const c of n)r[c]||(r[c]={}),r=r[c]}r[t.name]||(r[t.name]={})}}getCurrentParent(){return this._currentParent}setCurrentParent(t){const e=this._elements.get(t);if(!e||e.type!=="api"&&e.type!=="group")throw new Error(`Element ${t} not found or not a valid parent type`);this._currentParent=e}clearCurrentParent(){this._currentParent=null}registerRoute(t){if(!this._currentParent)throw new Error("No current parent set, use Route only inside Api or Group create callback");t.parent=this.getFullPath(this._currentParent);const e=this.getElementKey(t);this._elements.set(e,t),this.addToKlaimRoute(t)}addToKlaimRoute(t){if(!t.parent)return;let e=m;const a=t.parent.split(".");for(const r of a)e[r]||(e[r]={}),e=e[r];e[t.name]=function(r={},n={}){return x(t.parent,t,r,n)}}getElementKey(t){return t?t.parent?`${t.parent}.${t.name}`:t.name:""}getFullPath(t){if(!t)return"";if(!t.parent)return t.name;const e=[t.name];let a=t;for(;a.parent;){const r=this._elements.get(a.parent);if(!r)break;e.unshift(r.name),a=r}return e.join(".")}getRoute(t,e){return this._elements.get(`${t}.${e}`)}getChildren(t){const e=[];return this._elements.forEach(a=>{a.parent===t&&e.push(a)}),e}static updateElement(t){return u.i._elements.get(u.i.getElementKey(t))||t}getApi(t){const e=this._elements.get(t);if(!e){for(const[a,r]of this._elements.entries())if(r.type==="api"&&a.endsWith(`.${t}`))return r;return}return e.type==="api"?e:this.findApi(e)}findApi(t){if(!t||!t.parent)return;const e=t.parent.split(".");for(let a=e.length;a>=0;a--){const r=e.slice(0,a).join("."),n=this._elements.get(r);if((n==null?void 0:n.type)==="api")return n}}};o(u,"_instance");let i=u;class $ extends C{static create(t,e,a,r={}){const n=b(t);n!==t&&console.warn(`API name "${t}" has been camelCased to "${n}"`);const c=new $(n,e,r),l=i.i.getCurrentParent();i.i.registerElement(c);const h=l?i.i.getFullPath(l):"",f=h?`${h}.${n}`:n;return i.i.setCurrentParent(f),a(),l?i.i.setCurrentParent(i.i.getFullPath(l)):i.i.clearCurrentParent(),c}constructor(t,e,a={}){super("api",t,e,a)}}class k extends C{static create(t,e){const a=b(t),r=i.i.getCurrentParent(),n=r?i.i.getFullPath(r):"",c=n?`${n}.${a}`:a,l=new k(a,"");a!==t&&console.warn(`Group name "${t}" has been camelCased to "${a}"`),i.i.registerElement(l);const h=i.i.getCurrentParent();return i.i.setCurrentParent(c),e(),h?i.i.setCurrentParent(i.i.getFullPath(h)):i.i.clearCurrentParent(),l}constructor(t,e,a={}){super("group",t,e,a)}withCache(t=20){return super.withCache(t),i.i.getChildren(i.i.getFullPath(this)).forEach(e=>{e.cache||(e.cache=t)}),this}withRetry(t=2){return super.withRetry(t),i.i.getChildren(i.i.getFullPath(this)).forEach(e=>{e.retry||(e.retry=t)}),this}before(t){return super.before(t),i.i.getChildren(i.i.getFullPath(this)).forEach(e=>{e.callbacks.before||(e.callbacks.before=t)}),this}after(t){return super.after(t),i.i.getChildren(i.i.getFullPath(this)).forEach(e=>{e.callbacks.after||(e.callbacks.after=t)}),this}onCall(t){return super.onCall(t),i.i.getChildren(i.i.getFullPath(this)).forEach(e=>{e.callbacks.call||(e.callbacks.call=t)}),this}}class A extends C{constructor(t,e,a={},r="GET"){super("route",t,e,a),this.method=r,this.detectArguments()}static createRoute(t,e,a={},r){const n=new A(t,e,a,r);return i.i.registerRoute(n),n}static get(t,e,a={}){return this.createRoute(t,e,a,"GET")}static post(t,e,a={}){return this.createRoute(t,e,a,"POST")}static put(t,e,a={}){return this.createRoute(t,e,a,"PUT")}static delete(t,e,a={}){return this.createRoute(t,e,a,"DELETE")}static patch(t,e,a={}){return this.createRoute(t,e,a,"PATCH")}static options(t,e,a={}){return this.createRoute(t,e,a,"OPTIONS")}detectArguments(){const t=this.url.match(/\[([^\]]+)]/g);t&&t.forEach(e=>{const a=e.replace("[","").replace("]","");this.arguments.add(a)})}validate(t){return this.schema=t,this}}exports.Api=$;exports.Group=k;exports.Hook=E;exports.Klaim=m;exports.Registry=i;exports.Route=A;
1
+ "use strict";var R=Object.defineProperty;var v=(s,t,e)=>t in s?R(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var l=(s,t,e)=>v(s,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function b(s){return s.replace(/([-_][a-z])/gi,t=>t.toUpperCase().replace("-","").replace("_","")).replace(/(^\w)/,t=>t.toLowerCase())}function K(s){return s.trim().replace(/^\/|\/$/g,"")}class C{constructor(t,e,a,r={}){l(this,"type");l(this,"name");l(this,"url");l(this,"headers");l(this,"parent");l(this,"method");l(this,"arguments",new Set);l(this,"schema");l(this,"callbacks",{before:null,after:null,call:null});l(this,"cache",!1);l(this,"retry",!1);this.type=t,this.name=b(e),this.name!==e&&console.warn(`Name "${e}" has been camelCased to "${this.name}"`),this.url=K(a),this.headers=r||{}}before(t){return this.callbacks.before=t,this}after(t){return this.callbacks.after=t,this}onCall(t){return this.callbacks.call=t,this}withCache(t=20){return this.cache=t,this}withRetry(t=2){return this.retry=t,this}}const p=class p{constructor(){l(this,"cache");this.cache=new Map}static get i(){return p._instance||(p._instance=new p),p._instance}set(t,e,a=0){const r=Date.now()+a;this.cache.set(t,{data:e,expiry:r})}has(t){const e=this.cache.get(t);return e?Date.now()>e.expiry?(this.cache.delete(t),!1):!0:!1}get(t){return this.has(t)?this.cache.get(t).data:null}};l(p,"_instance");let g=p;function N(s){let a=2166136261;for(let n=0;n<s.length;n++)a^=s.charCodeAt(n),a*=16777619;let r=(a>>>0).toString(16).padStart(8,"0");for(;r.length<32;)a^=r.charCodeAt(r.length%r.length),a*=16777619,r+=(a>>>0).toString(16).padStart(8,"0");return r.substring(0,32)}async function j(s,t,e){const a=`${s.toString()}${JSON.stringify(t)}`,r=N(a);if(g.i.has(r))return g.i.get(r);const c=await(await fetch(s,t)).json();return g.i.set(r,c,e),c}class E{static subscribe(t,e){this._callbacks.set(t,e)}static run(t){const e=this._callbacks.get(t);e&&e()}}l(E,"_callbacks",new Map);const m={};async function x(s,t,e={},a={}){const r=s.split(".");let n;for(let y=0;y<r.length;y++){const T=r[y];if(n=i.i.getApi(T),n)break}if(!t||!n||t.type!=="route"||n.type!=="api")throw new Error(`Invalid path: ${s}.${t.name}`);let c=O(`${n.url}/${t.url}`,t,e),o={};a&&t.method!=="GET"&&(o.body=JSON.stringify(a)),o.headers={"Content-Type":"application/json",...n.headers,...t.headers},o.method=t.method;const{beforeRoute:u,beforeApi:f,beforeUrl:d,beforeConfig:P}=U({route:t,api:n,url:c,config:o});c=d,o=P,i.updateElement(f),i.updateElement(u);let w=await G(n,t,c,o);t.schema&&"validate"in t.schema&&(w=await t.schema.validate(w));const{afterRoute:_,afterApi:F,afterData:S}=H({route:t,api:n,response:w,data:w});return i.updateElement(F),i.updateElement(_),E.run(`${n.name}.${t.name}`),S}async function D(s,t,e,a){return s?await j(t,e,a.cache):await(await fetch(t,e)).json()}async function G(s,t,e,a){var f,d;const r=s.cache||t.cache,n=t.retry||s.retry||0;let c,o=!1,u=0;for(;u<=n&&!o;)try{(f=t.callbacks)!=null&&f.call?t.callbacks.call({}):(d=s.callbacks)!=null&&d.call&&s.callbacks.call({}),c=await D(!!r,e,a,s),o=!0}catch(P){if(u++,u>n)throw P.message=`Failed to fetch ${e} after ${n} attempts`,P}return c}function O(s,t,e){let a=s;return t.arguments.forEach(r=>{if(e[r]===void 0)throw new Error(`Argument ${r} is missing`);a=a.replace(`[${r}]`,e[r])}),a}function U({route:s,api:t,url:e,config:a}){var n,c;const r=(c=(n=s.callbacks).before)==null?void 0:c.call(n,{route:s,api:t,url:e,config:a});return{beforeRoute:(r==null?void 0:r.route)||s,beforeApi:(r==null?void 0:r.api)||t,beforeUrl:(r==null?void 0:r.url)||e,beforeConfig:(r==null?void 0:r.config)||a}}function H({route:s,api:t,response:e,data:a}){var n,c;const r=(c=(n=s.callbacks).after)==null?void 0:c.call(n,{route:s,api:t,response:e,data:a});return{afterRoute:(r==null?void 0:r.route)||s,afterApi:(r==null?void 0:r.api)||t,afterResponse:(r==null?void 0:r.response)||e,afterData:(r==null?void 0:r.data)||a}}const h=class h{constructor(){l(this,"_elements",new Map);l(this,"_currentParent",null)}static get i(){return h._instance||(h._instance=new h),h._instance}registerElement(t){const e=this._currentParent;e&&(t.parent=this.getFullPath(e));const a=this.getElementKey(t);if(this._elements.set(a,t),t.type==="api"||t.type==="group"){let r=m;if(e){const n=this.getFullPath(e).split(".");for(const c of n)r[c]||(r[c]={}),r=r[c]}r[t.name]||(r[t.name]={})}}getCurrentParent(){return this._currentParent}setCurrentParent(t){const e=this._elements.get(t);if(!e||e.type!=="api"&&e.type!=="group")throw new Error(`Element ${t} not found or not a valid parent type`);this._currentParent=e}clearCurrentParent(){this._currentParent=null}registerRoute(t){if(!this._currentParent)throw new Error("No current parent set, use Route only inside Api or Group create callback");t.parent=this.getFullPath(this._currentParent);const e=this.getElementKey(t);this._elements.set(e,t),this.addToKlaimRoute(t)}addToKlaimRoute(t){if(!t.parent)return;let e=m;const a=t.parent.split(".");for(const r of a)e[r]||(e[r]={}),e=e[r];e[t.name]=function(r={},n={}){return x(t.parent,t,r,n)}}getElementKey(t){return t?t.parent?`${t.parent}.${t.name}`:t.name:""}getFullPath(t){if(!t)return"";if(!t.parent)return t.name;const e=[t.name];let a=t;for(;a.parent;){const r=this._elements.get(a.parent);if(!r)break;e.unshift(r.name),a=r}return e.join(".")}getRoute(t,e){return this._elements.get(`${t}.${e}`)}getChildren(t){const e=[];return this._elements.forEach(a=>{a.parent===t&&e.push(a)}),e}static updateElement(t){return h.i._elements.get(h.i.getElementKey(t))||t}getApi(t){const e=this._elements.get(t);if(!e){for(const[a,r]of this._elements.entries())if(r.type==="api"&&a.endsWith(`.${t}`))return r;return}return e.type==="api"?e:this.findApi(e)}findApi(t){if(!t||!t.parent)return;const e=t.parent.split(".");for(let a=e.length;a>=0;a--){const r=e.slice(0,a).join("."),n=this._elements.get(r);if((n==null?void 0:n.type)==="api")return n}}};l(h,"_instance");let i=h;class $ extends C{static create(t,e,a,r={}){const n=b(t);n!==t&&console.warn(`API name "${t}" has been camelCased to "${n}"`);const c=new $(n,e,r),o=i.i.getCurrentParent();i.i.registerElement(c);const u=o?i.i.getFullPath(o):"",f=u?`${u}.${n}`:n;return i.i.setCurrentParent(f),a(),o?i.i.setCurrentParent(i.i.getFullPath(o)):i.i.clearCurrentParent(),c}constructor(t,e,a={}){super("api",t,e,a)}}class k extends C{static create(t,e){const a=b(t),r=i.i.getCurrentParent(),n=r?i.i.getFullPath(r):"",c=n?`${n}.${a}`:a,o=new k(a,"");a!==t&&console.warn(`Group name "${t}" has been camelCased to "${a}"`),i.i.registerElement(o);const u=i.i.getCurrentParent();return i.i.setCurrentParent(c),e(),u?i.i.setCurrentParent(i.i.getFullPath(u)):i.i.clearCurrentParent(),o}constructor(t,e,a={}){super("group",t,e,a)}withCache(t=20){return super.withCache(t),i.i.getChildren(i.i.getFullPath(this)).forEach(e=>{e.cache||(e.cache=t)}),this}withRetry(t=2){return super.withRetry(t),i.i.getChildren(i.i.getFullPath(this)).forEach(e=>{e.retry||(e.retry=t)}),this}before(t){return super.before(t),i.i.getChildren(i.i.getFullPath(this)).forEach(e=>{e.callbacks.before||(e.callbacks.before=t)}),this}after(t){return super.after(t),i.i.getChildren(i.i.getFullPath(this)).forEach(e=>{e.callbacks.after||(e.callbacks.after=t)}),this}onCall(t){return super.onCall(t),i.i.getChildren(i.i.getFullPath(this)).forEach(e=>{e.callbacks.call||(e.callbacks.call=t)}),this}}class A extends C{constructor(t,e,a={},r="GET"){super("route",t,e,a),this.method=r,this.detectArguments()}static createRoute(t,e,a={},r){const n=new A(t,e,a,r);return i.i.registerRoute(n),n}static get(t,e,a={}){return this.createRoute(t,e,a,"GET")}static post(t,e,a={}){return this.createRoute(t,e,a,"POST")}static put(t,e,a={}){return this.createRoute(t,e,a,"PUT")}static delete(t,e,a={}){return this.createRoute(t,e,a,"DELETE")}static patch(t,e,a={}){return this.createRoute(t,e,a,"PATCH")}static options(t,e,a={}){return this.createRoute(t,e,a,"OPTIONS")}detectArguments(){const t=this.url.match(/\[([^\]]+)]/g);t&&t.forEach(e=>{const a=e.replace("[","").replace("]","");this.arguments.add(a)})}validate(t){return this.schema=t,this}}exports.Api=$;exports.Group=k;exports.Hook=E;exports.Klaim=m;exports.Registry=i;exports.Route=A;
package/dist/klaim.es.js CHANGED
@@ -1,6 +1,6 @@
1
- var T = Object.defineProperty;
2
- var N = (s, t, e) => t in s ? T(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var o = (s, t, e) => N(s, typeof t != "symbol" ? t + "" : t, e);
1
+ var N = Object.defineProperty;
2
+ var v = (s, t, e) => t in s ? N(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var l = (s, t, e) => v(s, typeof t != "symbol" ? t + "" : t, e);
4
4
  function m(s) {
5
5
  return s.replace(/([-_][a-z])/gi, (t) => t.toUpperCase().replace("-", "").replace("_", "")).replace(/(^\w)/, (t) => t.toLowerCase());
6
6
  }
@@ -18,31 +18,31 @@ class C {
18
18
  */
19
19
  constructor(t, e, a, r = {}) {
20
20
  /** Element type identifier */
21
- o(this, "type");
21
+ l(this, "type");
22
22
  /** Element name (unique within its scope) */
23
- o(this, "name");
23
+ l(this, "name");
24
24
  /** Base URL or path segment */
25
- o(this, "url");
25
+ l(this, "url");
26
26
  /** HTTP headers specific to this element */
27
- o(this, "headers");
27
+ l(this, "headers");
28
28
  /** Reference to parent element name */
29
- o(this, "parent");
29
+ l(this, "parent");
30
30
  /** HTTP method (for routes) */
31
- o(this, "method");
31
+ l(this, "method");
32
32
  /** Set of dynamic URL parameters */
33
- o(this, "arguments", /* @__PURE__ */ new Set());
33
+ l(this, "arguments", /* @__PURE__ */ new Set());
34
34
  /** Response validation schema */
35
- o(this, "schema");
35
+ l(this, "schema");
36
36
  /** Middleware callbacks collection */
37
- o(this, "callbacks", {
37
+ l(this, "callbacks", {
38
38
  before: null,
39
39
  after: null,
40
40
  call: null
41
41
  });
42
42
  /** Cache duration in seconds, or false if disabled */
43
- o(this, "cache", !1);
43
+ l(this, "cache", !1);
44
44
  /** Number of retry attempts, or false if disabled */
45
- o(this, "retry", !1);
45
+ l(this, "retry", !1);
46
46
  this.type = t, this.name = m(e), this.name !== e && console.warn(`Name "${e}" has been camelCased to "${this.name}"`), this.url = K(a), this.headers = r || {};
47
47
  }
48
48
  /**
@@ -105,7 +105,7 @@ const p = class p {
105
105
  *
106
106
  * @private
107
107
  */
108
- o(this, "cache");
108
+ l(this, "cache");
109
109
  this.cache = /* @__PURE__ */ new Map();
110
110
  }
111
111
  /**
@@ -182,7 +182,7 @@ const p = class p {
182
182
  *
183
183
  * @private
184
184
  */
185
- o(p, "_instance");
185
+ l(p, "_instance");
186
186
  let g = p;
187
187
  function R(s) {
188
188
  let a = 2166136261;
@@ -242,38 +242,38 @@ class E {
242
242
  *
243
243
  * @private
244
244
  */
245
- o(E, "_callbacks", /* @__PURE__ */ new Map());
245
+ l(E, "_callbacks", /* @__PURE__ */ new Map());
246
246
  const b = {};
247
247
  async function D(s, t, e = {}, a = {}) {
248
248
  const r = s.split(".");
249
249
  let n;
250
250
  for (let y = 0; y < r.length; y++) {
251
- const S = r[y];
252
- if (n = i.i.getApi(S), n) break;
251
+ const T = r[y];
252
+ if (n = i.i.getApi(T), n) break;
253
253
  }
254
254
  if (!t || !n || t.type !== "route" || n.type !== "api")
255
255
  throw new Error(`Invalid path: ${s}.${t.name}`);
256
- let c = G(`${n.url}/${t.url}`, t, e), l = {};
257
- a && t.method !== "GET" && (l.body = JSON.stringify(a)), l.headers = {
256
+ let c = G(`${n.url}/${t.url}`, t, e), o = {};
257
+ a && t.method !== "GET" && (o.body = JSON.stringify(a)), o.headers = {
258
258
  "Content-Type": "application/json",
259
259
  ...n.headers,
260
260
  ...t.headers
261
- }, l.method = t.method;
261
+ }, o.method = t.method;
262
262
  const {
263
263
  beforeRoute: h,
264
264
  beforeApi: f,
265
265
  beforeUrl: d,
266
266
  beforeConfig: w
267
- } = O({ route: t, api: n, url: c, config: l });
268
- c = d, l = w, i.updateElement(f), i.updateElement(h);
269
- let P = await j(n, t, c, l);
267
+ } = O({ route: t, api: n, url: c, config: o });
268
+ c = d, o = w, i.updateElement(f), i.updateElement(h);
269
+ let P = await j(n, t, c, o);
270
270
  t.schema && "validate" in t.schema && (P = await t.schema.validate(P));
271
271
  const {
272
272
  afterRoute: _,
273
273
  afterApi: F,
274
- afterData: v
274
+ afterData: S
275
275
  } = H({ route: t, api: n, response: P, data: P });
276
- return i.updateElement(F), i.updateElement(_), E.run(`${n.name}.${t.name}`), v;
276
+ return i.updateElement(F), i.updateElement(_), E.run(`${n.name}.${t.name}`), S;
277
277
  }
278
278
  async function U(s, t, e, a) {
279
279
  return s ? await x(t, e, a.cache) : await (await fetch(t, e)).json();
@@ -281,10 +281,10 @@ async function U(s, t, e, a) {
281
281
  async function j(s, t, e, a) {
282
282
  var f, d;
283
283
  const r = s.cache || t.cache, n = t.retry || s.retry || 0;
284
- let c, l = !1, h = 0;
285
- for (; h <= n && !l; )
284
+ let c, o = !1, h = 0;
285
+ for (; h <= n && !o; )
286
286
  try {
287
- (f = t.callbacks) != null && f.call ? t.callbacks.call({}) : (d = s.callbacks) != null && d.call && s.callbacks.call({}), c = await U(!!r, e, a, s), l = !0;
287
+ (f = t.callbacks) != null && f.call ? t.callbacks.call({}) : (d = s.callbacks) != null && d.call && s.callbacks.call({}), c = await U(!!r, e, a, s), o = !0;
288
288
  } catch (w) {
289
289
  if (h++, h > n)
290
290
  throw w.message = `Failed to fetch ${e} after ${n} attempts`, w;
@@ -325,12 +325,12 @@ const u = class u {
325
325
  * Map storing all registered elements with their full paths as keys
326
326
  * @private
327
327
  */
328
- o(this, "_elements", /* @__PURE__ */ new Map());
328
+ l(this, "_elements", /* @__PURE__ */ new Map());
329
329
  /**
330
330
  * Reference to the current parent element during registration
331
331
  * @private
332
332
  */
333
- o(this, "_currentParent", null);
333
+ l(this, "_currentParent", null);
334
334
  }
335
335
  /**
336
336
  * Gets the singleton instance of the Registry
@@ -507,7 +507,7 @@ const u = class u {
507
507
  }
508
508
  }
509
509
  };
510
- o(u, "_instance");
510
+ l(u, "_instance");
511
511
  let i = u;
512
512
  class $ extends C {
513
513
  /**
@@ -531,10 +531,10 @@ class $ extends C {
531
531
  static create(t, e, a, r = {}) {
532
532
  const n = m(t);
533
533
  n !== t && console.warn(`API name "${t}" has been camelCased to "${n}"`);
534
- const c = new $(n, e, r), l = i.i.getCurrentParent();
534
+ const c = new $(n, e, r), o = i.i.getCurrentParent();
535
535
  i.i.registerElement(c);
536
- const h = l ? i.i.getFullPath(l) : "", f = h ? `${h}.${n}` : n;
537
- return i.i.setCurrentParent(f), a(), l ? i.i.setCurrentParent(i.i.getFullPath(l)) : i.i.clearCurrentParent(), c;
536
+ const h = o ? i.i.getFullPath(o) : "", f = h ? `${h}.${n}` : n;
537
+ return i.i.setCurrentParent(f), a(), o ? i.i.setCurrentParent(i.i.getFullPath(o)) : i.i.clearCurrentParent(), c;
538
538
  }
539
539
  /**
540
540
  * Creates a new API instance
@@ -575,10 +575,10 @@ class k extends C {
575
575
  * ```
576
576
  */
577
577
  static create(t, e) {
578
- const a = m(t), r = i.i.getCurrentParent(), n = r ? i.i.getFullPath(r) : "", c = n ? `${n}.${a}` : a, l = new k(a, "");
579
- a !== t && console.warn(`Group name "${t}" has been camelCased to "${a}"`), i.i.registerElement(l);
578
+ const a = m(t), r = i.i.getCurrentParent(), n = r ? i.i.getFullPath(r) : "", c = n ? `${n}.${a}` : a, o = new k(a, "");
579
+ a !== t && console.warn(`Group name "${t}" has been camelCased to "${a}"`), i.i.registerElement(o);
580
580
  const h = i.i.getCurrentParent();
581
- return i.i.setCurrentParent(c), e(), h ? i.i.setCurrentParent(i.i.getFullPath(h)) : i.i.clearCurrentParent(), l;
581
+ return i.i.setCurrentParent(c), e(), h ? i.i.setCurrentParent(i.i.getFullPath(h)) : i.i.clearCurrentParent(), o;
582
582
  }
583
583
  /**
584
584
  * Creates a new Group instance.
package/dist/klaim.umd.js CHANGED
@@ -1 +1 @@
1
- (function(l,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(l=typeof globalThis<"u"?globalThis:l||self,h(l.klaim={}))})(this,function(l){"use strict";var M=Object.defineProperty;var x=(l,h,d)=>h in l?M(l,h,{enumerable:!0,configurable:!0,writable:!0,value:d}):l[h]=d;var o=(l,h,d)=>x(l,typeof h!="symbol"?h+"":h,d);function h(i){return i.replace(/([-_][a-z])/gi,t=>t.toUpperCase().replace("-","").replace("_","")).replace(/(^\w)/,t=>t.toLowerCase())}function d(i){return i.trim().replace(/^\/|\/$/g,"")}class C{constructor(t,e,a,r={}){o(this,"type");o(this,"name");o(this,"url");o(this,"headers");o(this,"parent");o(this,"method");o(this,"arguments",new Set);o(this,"schema");o(this,"callbacks",{before:null,after:null,call:null});o(this,"cache",!1);o(this,"retry",!1);this.type=t,this.name=h(e),this.name!==e&&console.warn(`Name "${e}" has been camelCased to "${this.name}"`),this.url=d(a),this.headers=r||{}}before(t){return this.callbacks.before=t,this}after(t){return this.callbacks.after=t,this}onCall(t){return this.callbacks.call=t,this}withCache(t=20){return this.cache=t,this}withRetry(t=2){return this.retry=t,this}}const g=class g{constructor(){o(this,"cache");this.cache=new Map}static get i(){return g._instance||(g._instance=new g),g._instance}set(t,e,a=0){const r=Date.now()+a;this.cache.set(t,{data:e,expiry:r})}has(t){const e=this.cache.get(t);return e?Date.now()>e.expiry?(this.cache.delete(t),!1):!0:!1}get(t){return this.has(t)?this.cache.get(t).data:null}};o(g,"_instance");let w=g;function S(i){let a=2166136261;for(let n=0;n<i.length;n++)a^=i.charCodeAt(n),a*=16777619;let r=(a>>>0).toString(16).padStart(8,"0");for(;r.length<32;)a^=r.charCodeAt(r.length%r.length),a*=16777619,r+=(a>>>0).toString(16).padStart(8,"0");return r.substring(0,32)}async function T(i,t,e){const a=`${i.toString()}${JSON.stringify(t)}`,r=S(a);if(w.i.has(r))return w.i.get(r);const c=await(await fetch(i,t)).json();return w.i.set(r,c,e),c}class E{static subscribe(t,e){this._callbacks.set(t,e)}static run(t){const e=this._callbacks.get(t);e&&e()}}o(E,"_callbacks",new Map);const $={};async function v(i,t,e={},a={}){const r=i.split(".");let n;for(let F=0;F<r.length;F++){const H=r[F];if(n=s.i.getApi(H),n)break}if(!t||!n||t.type!=="route"||n.type!=="api")throw new Error(`Invalid path: ${i}.${t.name}`);let c=N(`${n.url}/${t.url}`,t,e),u={};a&&t.method!=="GET"&&(u.body=JSON.stringify(a)),u.headers={"Content-Type":"application/json",...n.headers,...t.headers},u.method=t.method;const{beforeRoute:p,beforeApi:P,beforeUrl:y,beforeConfig:m}=j({route:t,api:n,url:c,config:u});c=y,u=m,s.updateElement(P),s.updateElement(p);let b=await K(n,t,c,u);t.schema&&"validate"in t.schema&&(b=await t.schema.validate(b));const{afterRoute:G,afterApi:O,afterData:U}=D({route:t,api:n,response:b,data:b});return s.updateElement(O),s.updateElement(G),E.run(`${n.name}.${t.name}`),U}async function R(i,t,e,a){return i?await T(t,e,a.cache):await(await fetch(t,e)).json()}async function K(i,t,e,a){var P,y;const r=i.cache||t.cache,n=t.retry||i.retry||0;let c,u=!1,p=0;for(;p<=n&&!u;)try{(P=t.callbacks)!=null&&P.call?t.callbacks.call({}):(y=i.callbacks)!=null&&y.call&&i.callbacks.call({}),c=await R(!!r,e,a,i),u=!0}catch(m){if(p++,p>n)throw m.message=`Failed to fetch ${e} after ${n} attempts`,m}return c}function N(i,t,e){let a=i;return t.arguments.forEach(r=>{if(e[r]===void 0)throw new Error(`Argument ${r} is missing`);a=a.replace(`[${r}]`,e[r])}),a}function j({route:i,api:t,url:e,config:a}){var n,c;const r=(c=(n=i.callbacks).before)==null?void 0:c.call(n,{route:i,api:t,url:e,config:a});return{beforeRoute:(r==null?void 0:r.route)||i,beforeApi:(r==null?void 0:r.api)||t,beforeUrl:(r==null?void 0:r.url)||e,beforeConfig:(r==null?void 0:r.config)||a}}function D({route:i,api:t,response:e,data:a}){var n,c;const r=(c=(n=i.callbacks).after)==null?void 0:c.call(n,{route:i,api:t,response:e,data:a});return{afterRoute:(r==null?void 0:r.route)||i,afterApi:(r==null?void 0:r.api)||t,afterResponse:(r==null?void 0:r.response)||e,afterData:(r==null?void 0:r.data)||a}}const f=class f{constructor(){o(this,"_elements",new Map);o(this,"_currentParent",null)}static get i(){return f._instance||(f._instance=new f),f._instance}registerElement(t){const e=this._currentParent;e&&(t.parent=this.getFullPath(e));const a=this.getElementKey(t);if(this._elements.set(a,t),t.type==="api"||t.type==="group"){let r=$;if(e){const n=this.getFullPath(e).split(".");for(const c of n)r[c]||(r[c]={}),r=r[c]}r[t.name]||(r[t.name]={})}}getCurrentParent(){return this._currentParent}setCurrentParent(t){const e=this._elements.get(t);if(!e||e.type!=="api"&&e.type!=="group")throw new Error(`Element ${t} not found or not a valid parent type`);this._currentParent=e}clearCurrentParent(){this._currentParent=null}registerRoute(t){if(!this._currentParent)throw new Error("No current parent set, use Route only inside Api or Group create callback");t.parent=this.getFullPath(this._currentParent);const e=this.getElementKey(t);this._elements.set(e,t),this.addToKlaimRoute(t)}addToKlaimRoute(t){if(!t.parent)return;let e=$;const a=t.parent.split(".");for(const r of a)e[r]||(e[r]={}),e=e[r];e[t.name]=function(r={},n={}){return v(t.parent,t,r,n)}}getElementKey(t){return t?t.parent?`${t.parent}.${t.name}`:t.name:""}getFullPath(t){if(!t)return"";if(!t.parent)return t.name;const e=[t.name];let a=t;for(;a.parent;){const r=this._elements.get(a.parent);if(!r)break;e.unshift(r.name),a=r}return e.join(".")}getRoute(t,e){return this._elements.get(`${t}.${e}`)}getChildren(t){const e=[];return this._elements.forEach(a=>{a.parent===t&&e.push(a)}),e}static updateElement(t){return f.i._elements.get(f.i.getElementKey(t))||t}getApi(t){const e=this._elements.get(t);if(!e){for(const[a,r]of this._elements.entries())if(r.type==="api"&&a.endsWith(`.${t}`))return r;return}return e.type==="api"?e:this.findApi(e)}findApi(t){if(!t||!t.parent)return;const e=t.parent.split(".");for(let a=e.length;a>=0;a--){const r=e.slice(0,a).join("."),n=this._elements.get(r);if((n==null?void 0:n.type)==="api")return n}}};o(f,"_instance");let s=f;class k extends C{static create(t,e,a,r={}){const n=h(t);n!==t&&console.warn(`API name "${t}" has been camelCased to "${n}"`);const c=new k(n,e,r),u=s.i.getCurrentParent();s.i.registerElement(c);const p=u?s.i.getFullPath(u):"",P=p?`${p}.${n}`:n;return s.i.setCurrentParent(P),a(),u?s.i.setCurrentParent(s.i.getFullPath(u)):s.i.clearCurrentParent(),c}constructor(t,e,a={}){super("api",t,e,a)}}class A extends C{static create(t,e){const a=h(t),r=s.i.getCurrentParent(),n=r?s.i.getFullPath(r):"",c=n?`${n}.${a}`:a,u=new A(a,"");a!==t&&console.warn(`Group name "${t}" has been camelCased to "${a}"`),s.i.registerElement(u);const p=s.i.getCurrentParent();return s.i.setCurrentParent(c),e(),p?s.i.setCurrentParent(s.i.getFullPath(p)):s.i.clearCurrentParent(),u}constructor(t,e,a={}){super("group",t,e,a)}withCache(t=20){return super.withCache(t),s.i.getChildren(s.i.getFullPath(this)).forEach(e=>{e.cache||(e.cache=t)}),this}withRetry(t=2){return super.withRetry(t),s.i.getChildren(s.i.getFullPath(this)).forEach(e=>{e.retry||(e.retry=t)}),this}before(t){return super.before(t),s.i.getChildren(s.i.getFullPath(this)).forEach(e=>{e.callbacks.before||(e.callbacks.before=t)}),this}after(t){return super.after(t),s.i.getChildren(s.i.getFullPath(this)).forEach(e=>{e.callbacks.after||(e.callbacks.after=t)}),this}onCall(t){return super.onCall(t),s.i.getChildren(s.i.getFullPath(this)).forEach(e=>{e.callbacks.call||(e.callbacks.call=t)}),this}}class _ extends C{constructor(t,e,a={},r="GET"){super("route",t,e,a),this.method=r,this.detectArguments()}static createRoute(t,e,a={},r){const n=new _(t,e,a,r);return s.i.registerRoute(n),n}static get(t,e,a={}){return this.createRoute(t,e,a,"GET")}static post(t,e,a={}){return this.createRoute(t,e,a,"POST")}static put(t,e,a={}){return this.createRoute(t,e,a,"PUT")}static delete(t,e,a={}){return this.createRoute(t,e,a,"DELETE")}static patch(t,e,a={}){return this.createRoute(t,e,a,"PATCH")}static options(t,e,a={}){return this.createRoute(t,e,a,"OPTIONS")}detectArguments(){const t=this.url.match(/\[([^\]]+)]/g);t&&t.forEach(e=>{const a=e.replace("[","").replace("]","");this.arguments.add(a)})}validate(t){return this.schema=t,this}}l.Api=k,l.Group=A,l.Hook=E,l.Klaim=$,l.Registry=s,l.Route=_,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
1
+ (function(l,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(l=typeof globalThis<"u"?globalThis:l||self,h(l.klaim={}))})(this,function(l){"use strict";var M=Object.defineProperty;var x=(l,h,d)=>h in l?M(l,h,{enumerable:!0,configurable:!0,writable:!0,value:d}):l[h]=d;var o=(l,h,d)=>x(l,typeof h!="symbol"?h+"":h,d);function h(i){return i.replace(/([-_][a-z])/gi,t=>t.toUpperCase().replace("-","").replace("_","")).replace(/(^\w)/,t=>t.toLowerCase())}function d(i){return i.trim().replace(/^\/|\/$/g,"")}class C{constructor(t,e,a,r={}){o(this,"type");o(this,"name");o(this,"url");o(this,"headers");o(this,"parent");o(this,"method");o(this,"arguments",new Set);o(this,"schema");o(this,"callbacks",{before:null,after:null,call:null});o(this,"cache",!1);o(this,"retry",!1);this.type=t,this.name=h(e),this.name!==e&&console.warn(`Name "${e}" has been camelCased to "${this.name}"`),this.url=d(a),this.headers=r||{}}before(t){return this.callbacks.before=t,this}after(t){return this.callbacks.after=t,this}onCall(t){return this.callbacks.call=t,this}withCache(t=20){return this.cache=t,this}withRetry(t=2){return this.retry=t,this}}const g=class g{constructor(){o(this,"cache");this.cache=new Map}static get i(){return g._instance||(g._instance=new g),g._instance}set(t,e,a=0){const r=Date.now()+a;this.cache.set(t,{data:e,expiry:r})}has(t){const e=this.cache.get(t);return e?Date.now()>e.expiry?(this.cache.delete(t),!1):!0:!1}get(t){return this.has(t)?this.cache.get(t).data:null}};o(g,"_instance");let w=g;function S(i){let a=2166136261;for(let n=0;n<i.length;n++)a^=i.charCodeAt(n),a*=16777619;let r=(a>>>0).toString(16).padStart(8,"0");for(;r.length<32;)a^=r.charCodeAt(r.length%r.length),a*=16777619,r+=(a>>>0).toString(16).padStart(8,"0");return r.substring(0,32)}async function T(i,t,e){const a=`${i.toString()}${JSON.stringify(t)}`,r=S(a);if(w.i.has(r))return w.i.get(r);const c=await(await fetch(i,t)).json();return w.i.set(r,c,e),c}class E{static subscribe(t,e){this._callbacks.set(t,e)}static run(t){const e=this._callbacks.get(t);e&&e()}}o(E,"_callbacks",new Map);const $={};async function R(i,t,e={},a={}){const r=i.split(".");let n;for(let F=0;F<r.length;F++){const H=r[F];if(n=s.i.getApi(H),n)break}if(!t||!n||t.type!=="route"||n.type!=="api")throw new Error(`Invalid path: ${i}.${t.name}`);let c=N(`${n.url}/${t.url}`,t,e),u={};a&&t.method!=="GET"&&(u.body=JSON.stringify(a)),u.headers={"Content-Type":"application/json",...n.headers,...t.headers},u.method=t.method;const{beforeRoute:f,beforeApi:P,beforeUrl:y,beforeConfig:m}=j({route:t,api:n,url:c,config:u});c=y,u=m,s.updateElement(P),s.updateElement(f);let b=await K(n,t,c,u);t.schema&&"validate"in t.schema&&(b=await t.schema.validate(b));const{afterRoute:G,afterApi:O,afterData:U}=D({route:t,api:n,response:b,data:b});return s.updateElement(O),s.updateElement(G),E.run(`${n.name}.${t.name}`),U}async function v(i,t,e,a){return i?await T(t,e,a.cache):await(await fetch(t,e)).json()}async function K(i,t,e,a){var P,y;const r=i.cache||t.cache,n=t.retry||i.retry||0;let c,u=!1,f=0;for(;f<=n&&!u;)try{(P=t.callbacks)!=null&&P.call?t.callbacks.call({}):(y=i.callbacks)!=null&&y.call&&i.callbacks.call({}),c=await v(!!r,e,a,i),u=!0}catch(m){if(f++,f>n)throw m.message=`Failed to fetch ${e} after ${n} attempts`,m}return c}function N(i,t,e){let a=i;return t.arguments.forEach(r=>{if(e[r]===void 0)throw new Error(`Argument ${r} is missing`);a=a.replace(`[${r}]`,e[r])}),a}function j({route:i,api:t,url:e,config:a}){var n,c;const r=(c=(n=i.callbacks).before)==null?void 0:c.call(n,{route:i,api:t,url:e,config:a});return{beforeRoute:(r==null?void 0:r.route)||i,beforeApi:(r==null?void 0:r.api)||t,beforeUrl:(r==null?void 0:r.url)||e,beforeConfig:(r==null?void 0:r.config)||a}}function D({route:i,api:t,response:e,data:a}){var n,c;const r=(c=(n=i.callbacks).after)==null?void 0:c.call(n,{route:i,api:t,response:e,data:a});return{afterRoute:(r==null?void 0:r.route)||i,afterApi:(r==null?void 0:r.api)||t,afterResponse:(r==null?void 0:r.response)||e,afterData:(r==null?void 0:r.data)||a}}const p=class p{constructor(){o(this,"_elements",new Map);o(this,"_currentParent",null)}static get i(){return p._instance||(p._instance=new p),p._instance}registerElement(t){const e=this._currentParent;e&&(t.parent=this.getFullPath(e));const a=this.getElementKey(t);if(this._elements.set(a,t),t.type==="api"||t.type==="group"){let r=$;if(e){const n=this.getFullPath(e).split(".");for(const c of n)r[c]||(r[c]={}),r=r[c]}r[t.name]||(r[t.name]={})}}getCurrentParent(){return this._currentParent}setCurrentParent(t){const e=this._elements.get(t);if(!e||e.type!=="api"&&e.type!=="group")throw new Error(`Element ${t} not found or not a valid parent type`);this._currentParent=e}clearCurrentParent(){this._currentParent=null}registerRoute(t){if(!this._currentParent)throw new Error("No current parent set, use Route only inside Api or Group create callback");t.parent=this.getFullPath(this._currentParent);const e=this.getElementKey(t);this._elements.set(e,t),this.addToKlaimRoute(t)}addToKlaimRoute(t){if(!t.parent)return;let e=$;const a=t.parent.split(".");for(const r of a)e[r]||(e[r]={}),e=e[r];e[t.name]=function(r={},n={}){return R(t.parent,t,r,n)}}getElementKey(t){return t?t.parent?`${t.parent}.${t.name}`:t.name:""}getFullPath(t){if(!t)return"";if(!t.parent)return t.name;const e=[t.name];let a=t;for(;a.parent;){const r=this._elements.get(a.parent);if(!r)break;e.unshift(r.name),a=r}return e.join(".")}getRoute(t,e){return this._elements.get(`${t}.${e}`)}getChildren(t){const e=[];return this._elements.forEach(a=>{a.parent===t&&e.push(a)}),e}static updateElement(t){return p.i._elements.get(p.i.getElementKey(t))||t}getApi(t){const e=this._elements.get(t);if(!e){for(const[a,r]of this._elements.entries())if(r.type==="api"&&a.endsWith(`.${t}`))return r;return}return e.type==="api"?e:this.findApi(e)}findApi(t){if(!t||!t.parent)return;const e=t.parent.split(".");for(let a=e.length;a>=0;a--){const r=e.slice(0,a).join("."),n=this._elements.get(r);if((n==null?void 0:n.type)==="api")return n}}};o(p,"_instance");let s=p;class k extends C{static create(t,e,a,r={}){const n=h(t);n!==t&&console.warn(`API name "${t}" has been camelCased to "${n}"`);const c=new k(n,e,r),u=s.i.getCurrentParent();s.i.registerElement(c);const f=u?s.i.getFullPath(u):"",P=f?`${f}.${n}`:n;return s.i.setCurrentParent(P),a(),u?s.i.setCurrentParent(s.i.getFullPath(u)):s.i.clearCurrentParent(),c}constructor(t,e,a={}){super("api",t,e,a)}}class A extends C{static create(t,e){const a=h(t),r=s.i.getCurrentParent(),n=r?s.i.getFullPath(r):"",c=n?`${n}.${a}`:a,u=new A(a,"");a!==t&&console.warn(`Group name "${t}" has been camelCased to "${a}"`),s.i.registerElement(u);const f=s.i.getCurrentParent();return s.i.setCurrentParent(c),e(),f?s.i.setCurrentParent(s.i.getFullPath(f)):s.i.clearCurrentParent(),u}constructor(t,e,a={}){super("group",t,e,a)}withCache(t=20){return super.withCache(t),s.i.getChildren(s.i.getFullPath(this)).forEach(e=>{e.cache||(e.cache=t)}),this}withRetry(t=2){return super.withRetry(t),s.i.getChildren(s.i.getFullPath(this)).forEach(e=>{e.retry||(e.retry=t)}),this}before(t){return super.before(t),s.i.getChildren(s.i.getFullPath(this)).forEach(e=>{e.callbacks.before||(e.callbacks.before=t)}),this}after(t){return super.after(t),s.i.getChildren(s.i.getFullPath(this)).forEach(e=>{e.callbacks.after||(e.callbacks.after=t)}),this}onCall(t){return super.onCall(t),s.i.getChildren(s.i.getFullPath(this)).forEach(e=>{e.callbacks.call||(e.callbacks.call=t)}),this}}class _ extends C{constructor(t,e,a={},r="GET"){super("route",t,e,a),this.method=r,this.detectArguments()}static createRoute(t,e,a={},r){const n=new _(t,e,a,r);return s.i.registerRoute(n),n}static get(t,e,a={}){return this.createRoute(t,e,a,"GET")}static post(t,e,a={}){return this.createRoute(t,e,a,"POST")}static put(t,e,a={}){return this.createRoute(t,e,a,"PUT")}static delete(t,e,a={}){return this.createRoute(t,e,a,"DELETE")}static patch(t,e,a={}){return this.createRoute(t,e,a,"PATCH")}static options(t,e,a={}){return this.createRoute(t,e,a,"OPTIONS")}detectArguments(){const t=this.url.match(/\[([^\]]+)]/g);t&&t.forEach(e=>{const a=e.replace("[","").replace("]","");this.arguments.add(a)})}validate(t){return this.schema=t,this}}l.Api=k,l.Group=A,l.Hook=E,l.Klaim=$,l.Registry=s,l.Route=_,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "klaim",
3
- "version": "1.7.46",
3
+ "version": "1.7.48",
4
4
  "author": "antharuu",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,8 +14,8 @@
14
14
  "@types/bun": "latest",
15
15
  "@types/eslint__js": "8.42.3",
16
16
  "@types/node": "^22.10.7",
17
- "@vitest/coverage-v8": "^3.0.2",
18
- "@vitest/ui": "^3.0.2",
17
+ "@vitest/coverage-v8": "^3.0.3",
18
+ "@vitest/ui": "^3.0.3",
19
19
  "dotenv-cli": "^8.0.0",
20
20
  "eslint": "9.18.0",
21
21
  "eslint-plugin-jsdoc": "50.6.2",
@@ -24,8 +24,8 @@
24
24
  "release-it": "^18.1.1",
25
25
  "typescript": "^5.7.3",
26
26
  "typescript-eslint": "8.21.0",
27
- "vite": "^6.0.10",
28
- "vitest": "^3.0.2",
27
+ "vite": "^6.0.11",
28
+ "vitest": "^3.0.3",
29
29
  "yup": "^1.6.1"
30
30
  },
31
31
  "bugs": {