@elysiajs/eden 0.6.5 → 0.7.0-beta.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.
@@ -0,0 +1 @@
1
+ import{a as S}from"./chunk-Y6SMVGJX.mjs";var k=(n,e,t)=>{if(n.endsWith("/")||(n+="/"),e==="index"&&(e=""),!t||!Object.keys(t).length)return`${n}${e}`;let r="";for(let[o,s]of Object.entries(t))r+=`${o}=${s}&`;return`${n}${e}?${r.slice(0,-1)}`};var v=typeof FileList>"u",x=n=>v?n instanceof Blob:n instanceof FileList||n instanceof File,F=n=>{if(!n)return!1;for(let e in n){if(x(n[e]))return!0;if(Array.isArray(n[e])&&n[e].find(t=>x(t)))return!0}return!1},$=n=>v?n:new Promise(e=>{let t=new FileReader;t.onload=()=>{e(new Blob([t.result],{type:n.type}))},t.readAsArrayBuffer(n)}),b=class{ws;url;constructor(e){this.ws=new WebSocket(e),this.url=e}send(e){return Array.isArray(e)?(e.forEach(t=>this.send(t)),this):(this.ws.send(typeof e=="object"?JSON.stringify(e):e.toString()),this)}on(e,t,r){return this.addEventListener(e,t,r)}off(e,t,r){return this.ws.removeEventListener(e,t,r),this}subscribe(e,t){return this.addEventListener("message",e,t)}addEventListener(e,t,r){return this.ws.addEventListener(e,o=>{if(e==="message"){let s=o.data.toString(),d=s.charCodeAt(0);if(d===47||d===123)try{s=JSON.parse(s)}catch{}else Number.isNaN(+s)?s==="true"?s=!0:s==="fase"&&(s=!1):s=+s;t({...o,data:s})}else t(o)},r),this}removeEventListener(e,t,r){return this.off(e,t,r),this}close(){return this.ws.close(),this}},L=(n,e="",t)=>new Proxy(()=>{},{get(r,o,s){return L(n,`${e}/${o.toString()}`,t)},apply(r,o,[{$query:s,$fetch:d,$headers:W,...m}={$fetch:void 0,$headers:void 0,$query:void 0}]=[{}]){let h=e.lastIndexOf("/"),y=e.slice(h+1),g=k(n,h===-1?"/":e.slice(0,h),s),A=t.fetcher??fetch;return y==="subscribe"?new b(g.replace(/^([^]+):\/\//,g.startsWith("https://")?"wss://":"ws://")):(async()=>{let c,w={...t.$fetch?.headers,...d?.headers,...W};if(y!=="GET"&&y!=="HEAD"){c=Object.keys(m).length?m:void 0;let a=typeof c=="object";if(a&&F(c)){let u=new FormData;for(let[p,f]of Object.entries(c))if(v)u.append(p,f);else if(f instanceof File)u.append(p,await $(f));else if(f instanceof FileList)for(let E=0;E<f.length;E++)u.append(p,await $(f[E]));else u.append(p,f);c=u}else w["content-type"]=a?"application/json":"text/plain",a&&(c=JSON.stringify(c))}let i=await A(g,{method:y,body:c,...t.$fetch,...d,headers:w}),l;switch(i.headers.get("Content-Type")?.split(";")[0]){case"application/json":l=await i.json();break;default:l=await i.text().then(a=>Number.isNaN(+a)?a==="true"?!0:a==="false"?!1:a:+a)}return i.status>300?{data:l,error:new S(i.status,await l),status:i.status,raw:i,headers:i.headers}:{data:l,status:i.status,response:i,headers:i.headers,error:null}})()}}),M=(n,e={fetcher:fetch})=>new Proxy({},{get(t,r){return L(n,r,e)}});export{b as a,M as b};
@@ -1,4 +1,7 @@
1
1
  import type { Elysia } from 'elysia';
2
2
  import type { EdenFetch } from './types';
3
3
  export type { EdenFetch } from './types';
4
- export declare const edenFetch: <App extends Elysia<any, any>>(server: string, config?: EdenFetch.Config) => EdenFetch.Create<App>;
4
+ export declare const edenFetch: <App extends Elysia<any, any, {
5
+ type: {};
6
+ error: {};
7
+ }, {}, {}, false>>(server: string, config?: EdenFetch.Config) => EdenFetch.Create<App>;
@@ -6,7 +6,7 @@ type Prettify<T> = {
6
6
  [K in keyof T]: T[K];
7
7
  } & {};
8
8
  export declare namespace EdenFetch {
9
- type Create<App extends Elysia<any, any>> = App['meta'] extends {
9
+ type Create<App extends Elysia<any, any, any, any, any, any>> = App extends {
10
10
  schema: infer Schema extends Record<string, any>;
11
11
  } ? EdenFetch.Fn<Schema> : 'Please install Elysia before using Eden';
12
12
  interface Config {
@@ -1,4 +1,7 @@
1
1
  import type { Elysia } from 'elysia';
2
2
  import type { EdenFn } from './types';
3
3
  export type { EdenFn } from './types';
4
- export declare const edenFn: <App extends Elysia<any, any>>(domain: string, config?: EdenFn.Config) => EdenFn.Create<App>;
4
+ export declare const edenFn: <App extends Elysia<any, any, {
5
+ type: {};
6
+ error: {};
7
+ }, {}, {}, false>>(domain: string, config?: EdenFn.Config) => EdenFn.Create<App>;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export { edenTreaty } from './treaty';
2
2
  export { edenFetch } from './fetch';
3
- export { edenFn } from './fn';
@@ -1 +1 @@
1
- "use strict";var Eden=(()=>{var G=Object.defineProperty;var tr=Object.getOwnPropertyDescriptor;var nr=Object.getOwnPropertyNames;var ir=Object.prototype.hasOwnProperty;var d=(e,r)=>()=>(e&&(r=e(e=0)),r);var me=(e,r)=>{for(var t in r)G(e,t,{get:r[t],enumerable:!0})},sr=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of nr(r))!ir.call(e,i)&&i!==t&&G(e,i,{get:()=>r[i],enumerable:!(n=tr(r,i))||n.enumerable});return e};var or=e=>sr(G({},"__esModule",{value:!0}),e);var Ee,xe=d(()=>{"use strict";Ee=function(){function e(){this.keyToValue=new Map,this.valueToKey=new Map}return e.prototype.set=function(r,t){this.keyToValue.set(r,t),this.valueToKey.set(t,r)},e.prototype.getByKey=function(r){return this.keyToValue.get(r)},e.prototype.getByValue=function(r){return this.valueToKey.get(r)},e.prototype.clear=function(){this.keyToValue.clear(),this.valueToKey.clear()},e}()});var B,X=d(()=>{"use strict";xe();B=function(){function e(r){this.generateIdentifier=r,this.kv=new Ee}return e.prototype.register=function(r,t){this.kv.getByValue(r)||(t||(t=this.generateIdentifier(r)),this.kv.set(t,r))},e.prototype.clear=function(){this.kv.clear()},e.prototype.getIdentifier=function(r){return this.kv.getByValue(r)},e.prototype.getValue=function(r){return this.kv.getByKey(r)},e}()});var ur,Se,Oe=d(()=>{"use strict";X();ur=function(){var e=function(r,t){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},e(r,t)};return function(r,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");e(r,t);function n(){this.constructor=r}r.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),Se=function(e){ur(r,e);function r(){var t=e.call(this,function(n){return n.name})||this;return t.classToAllowedProps=new Map,t}return r.prototype.register=function(t,n){typeof n=="object"?(n.allowProps&&this.classToAllowedProps.set(t,n.allowProps),e.prototype.register.call(this,t,n.identifier)):e.prototype.register.call(this,t,n)},r.prototype.getAllowedProps=function(t){return this.classToAllowedProps.get(t)},r}(B)});function cr(e){if("values"in Object)return Object.values(e);var r=[];for(var t in e)e.hasOwnProperty(t)&&r.push(e[t]);return r}function Ae(e,r){var t=cr(e);if("find"in t)return t.find(r);for(var n=t,i=0;i<n.length;i++){var s=n[i];if(r(s))return s}}function P(e,r){Object.entries(e).forEach(function(t){var n=fr(t,2),i=n[0],s=n[1];return r(s,i)})}function T(e,r){return e.indexOf(r)!==-1}function Y(e,r){for(var t=0;t<e.length;t++){var n=e[t];if(r(n))return n}}var fr,z=d(()=>{"use strict";fr=function(e,r){var t=typeof Symbol=="function"&&e[Symbol.iterator];if(!t)return e;var n=t.call(e),i,s=[],o;try{for(;(r===void 0||r-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(o)throw o.error}}return s}});var Ne,Pe=d(()=>{"use strict";z();Ne=function(){function e(){this.transfomers={}}return e.prototype.register=function(r){this.transfomers[r.name]=r},e.prototype.findApplicable=function(r){return Ae(this.transfomers,function(t){return t.isApplicable(r)})},e.prototype.findByName=function(r){return this.transfomers[r]},e}()});var lr,Z,pr,_,K,g,yr,mr,dr,_e,x,S,ee,Re,ke,re,te,Te,Fe,Ie,Ce,$=d(()=>{"use strict";lr=function(e){return Object.prototype.toString.call(e).slice(8,-1)},Z=function(e){return typeof e>"u"},pr=function(e){return e===null},_=function(e){return typeof e!="object"||e===null||e===Object.prototype?!1:Object.getPrototypeOf(e)===null?!0:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype},K=function(e){return _(e)&&Object.keys(e).length===0},g=function(e){return Array.isArray(e)},yr=function(e){return typeof e=="string"},mr=function(e){return typeof e=="number"&&!isNaN(e)},dr=function(e){return typeof e=="boolean"},_e=function(e){return e instanceof RegExp},x=function(e){return e instanceof Map},S=function(e){return e instanceof Set},ee=function(e){return lr(e)==="Symbol"},Re=function(e){return e instanceof Date&&!isNaN(e.valueOf())},ke=function(e){return e instanceof Error},re=function(e){return typeof e=="number"&&isNaN(e)},te=function(e){return dr(e)||pr(e)||Z(e)||mr(e)||yr(e)||ee(e)},Te=function(e){return typeof e=="bigint"},Fe=function(e){return e===1/0||e===-1/0},Ie=function(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)},Ce=function(e){return e instanceof URL}});var ne,L,F,ie=d(()=>{"use strict";ne=function(e){return e.replace(/\./g,"\\.")},L=function(e){return e.map(String).map(ne).join(".")},F=function(e){for(var r=[],t="",n=0;n<e.length;n++){var i=e.charAt(n),s=i==="\\"&&e.charAt(n+1)===".";if(s){t+=".",n++;continue}var o=i===".";if(o){r.push(t),t="";continue}t+=i}var a=t;return r.push(a),r}});function v(e,r,t,n){return{isApplicable:e,annotation:r,transform:t,untransform:n}}function M(e,r,t,n){return{isApplicable:e,annotation:r,transform:t,untransform:n}}function ue(e,r){if(e?.constructor){var t=!!r.classRegistry.getIdentifier(e.constructor);return t}return!1}var se,oe,ae,Ve,ze,hr,je,Be,Ke,gr,fe,$e,Le,Me=d(()=>{"use strict";$();z();se=function(){return se=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++){r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},se.apply(this,arguments)},oe=function(e,r){var t=typeof Symbol=="function"&&e[Symbol.iterator];if(!t)return e;var n=t.call(e),i,s=[],o;try{for(;(r===void 0||r-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(o)throw o.error}}return s},ae=function(e,r){for(var t=0,n=r.length,i=e.length;t<n;t++,i++)e[i]=r[t];return e};Ve=[v(Z,"undefined",function(){return null},function(){}),v(Te,"bigint",function(e){return e.toString()},function(e){return typeof BigInt<"u"?BigInt(e):(console.error("Please add a BigInt polyfill."),e)}),v(Re,"Date",function(e){return e.toISOString()},function(e){return new Date(e)}),v(ke,"Error",function(e,r){var t={name:e.name,message:e.message};return r.allowedErrorProps.forEach(function(n){t[n]=e[n]}),t},function(e,r){var t=new Error(e.message);return t.name=e.name,t.stack=e.stack,r.allowedErrorProps.forEach(function(n){t[n]=e[n]}),t}),v(_e,"regexp",function(e){return""+e},function(e){var r=e.slice(1,e.lastIndexOf("/")),t=e.slice(e.lastIndexOf("/")+1);return new RegExp(r,t)}),v(S,"set",function(e){return ae([],oe(e.values()))},function(e){return new Set(e)}),v(x,"map",function(e){return ae([],oe(e.entries()))},function(e){return new Map(e)}),v(function(e){return re(e)||Fe(e)},"number",function(e){return re(e)?"NaN":e>0?"Infinity":"-Infinity"},Number),v(function(e){return e===0&&1/e===-1/0},"number",function(){return"-0"},Number),v(Ce,"URL",function(e){return e.toString()},function(e){return new URL(e)})];ze=M(function(e,r){if(ee(e)){var t=!!r.symbolRegistry.getIdentifier(e);return t}return!1},function(e,r){var t=r.symbolRegistry.getIdentifier(e);return["symbol",t]},function(e){return e.description},function(e,r,t){var n=t.symbolRegistry.getValue(r[1]);if(!n)throw new Error("Trying to deserialize unknown symbol");return n}),hr=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Uint8ClampedArray].reduce(function(e,r){return e[r.name]=r,e},{}),je=M(Ie,function(e){return["typed-array",e.constructor.name]},function(e){return ae([],oe(e))},function(e,r){var t=hr[r[1]];if(!t)throw new Error("Trying to deserialize unknown typed array");return new t(e)});Be=M(ue,function(e,r){var t=r.classRegistry.getIdentifier(e.constructor);return["class",t]},function(e,r){var t=r.classRegistry.getAllowedProps(e.constructor);if(!t)return se({},e);var n={};return t.forEach(function(i){n[i]=e[i]}),n},function(e,r,t){var n=t.classRegistry.getValue(r[1]);if(!n)throw new Error("Trying to deserialize unknown class - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564");return Object.assign(Object.create(n.prototype),e)}),Ke=M(function(e,r){return!!r.customTransformerRegistry.findApplicable(e)},function(e,r){var t=r.customTransformerRegistry.findApplicable(e);return["custom",t.name]},function(e,r){var t=r.customTransformerRegistry.findApplicable(e);return t.serialize(e)},function(e,r,t){var n=t.customTransformerRegistry.findByName(r[1]);if(!n)throw new Error("Trying to deserialize unknown custom value");return n.deserialize(e)}),gr=[Be,ze,Ke,je],fe=function(e,r){var t=Y(gr,function(i){return i.isApplicable(e,r)});if(t)return{value:t.transform(e,r),type:t.annotation(e,r)};var n=Y(Ve,function(i){return i.isApplicable(e,r)});if(n)return{value:n.transform(e,r),type:n.annotation}},$e={};Ve.forEach(function(e){$e[e.annotation]=e});Le=function(e,r,t){if(g(r))switch(r[0]){case"symbol":return ze.untransform(e,r,t);case"class":return Be.untransform(e,r,t);case"custom":return Ke.untransform(e,r,t);case"typed-array":return je.untransform(e,r,t);default:throw new Error("Unknown transformation: "+r)}else{var n=$e[r];if(!n)throw new Error("Unknown transformation: "+r);return n.untransform(e,t)}}});function De(e){if(T(e,"__proto__"))throw new Error("__proto__ is not allowed as a property");if(T(e,"prototype"))throw new Error("prototype is not allowed as a property");if(T(e,"constructor"))throw new Error("constructor is not allowed as a property")}var I,We,D,Ue=d(()=>{"use strict";$();z();I=function(e,r){for(var t=e.keys();r>0;)t.next(),r--;return t.next().value};We=function(e,r){De(r);for(var t=0;t<r.length;t++){var n=r[t];if(S(e))e=I(e,+n);else if(x(e)){var i=+n,s=+r[++t]==0?"key":"value",o=I(e,i);switch(s){case"key":e=o;break;case"value":e=e.get(o);break}}else e=e[n]}return e},D=function(e,r,t){if(De(r),r.length===0)return t(e);for(var n=e,i=0;i<r.length-1;i++){var s=r[i];if(g(n)){var o=+s;n=n[o]}else if(_(n))n=n[s];else if(S(n)){var a=+s;n=I(n,a)}else if(x(n)){var c=i===r.length-2;if(c)break;var a=+s,y=+r[++i]==0?"key":"value",f=I(n,a);switch(y){case"key":n=f;break;case"value":n=n.get(f);break}}}var u=r[r.length-1];if(g(n)?n[+u]=t(n[+u]):_(n)&&(n[u]=t(n[u])),S(n)){var l=I(n,+u),m=t(l);l!==m&&(n.delete(l),n.add(m))}if(x(n)){var a=+r[r.length-2],p=I(n,a),y=+u==0?"key":"value";switch(y){case"key":{var A=t(p);n.set(A,n.get(p)),A!==p&&n.delete(p);break}case"value":{n.set(p,t(n.get(p)));break}}}return e}});function ce(e,r,t){if(t===void 0&&(t=[]),!!e){if(!g(e)){P(e,function(o,a){return ce(o,r,O(O([],w(t)),w(F(a))))});return}var n=w(e,2),i=n[0],s=n[1];s&&P(s,function(o,a){ce(o,r,O(O([],w(t)),w(F(a))))}),r(i,t)}}function qe(e,r,t){return ce(r,function(n,i){e=D(e,i,function(s){return Le(s,n,t)})}),e}function He(e,r){function t(o,a){var c=We(e,F(a));o.map(F).forEach(function(y){e=D(e,y,function(){return c})})}if(g(r)){var n=w(r,2),i=n[0],s=n[1];i.forEach(function(o){e=D(e,F(o),function(){return e})}),s&&P(s,t)}else P(r,t);return e}function br(e,r,t){var n=t.get(e);n?n.push(r):t.set(e,[r])}function Ge(e){var r={},t=void 0;return e.forEach(function(n){if(!(n.length<=1)){var i=w(n.map(function(a){return a.map(String)}).sort(function(a,c){return a.length-c.length})),s=i[0],o=i.slice(1);s.length===0?t=o.map(L):r[L(s)]=o.map(L)}}),t?K(r)?[t]:[t,r]:K(r)?void 0:r}var w,O,vr,le,Je=d(()=>{"use strict";$();ie();Me();z();ie();Ue();w=function(e,r){var t=typeof Symbol=="function"&&e[Symbol.iterator];if(!t)return e;var n=t.call(e),i,s=[],o;try{for(;(r===void 0||r-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(o)throw o.error}}return s},O=function(e,r){for(var t=0,n=r.length,i=e.length;t<n;t++,i++)e[i]=r[t];return e};vr=function(e,r){return _(e)||g(e)||x(e)||S(e)||ue(e,r)};le=function(e,r,t,n,i){var s;if(n===void 0&&(n=[]),i===void 0&&(i=[]),te(e)||br(e,n,r),!vr(e,t)){var o=fe(e,t);return o?{transformedValue:o.value,annotations:[o.type]}:{transformedValue:e}}if(T(i,e))return{transformedValue:null};var a=fe(e,t),c=(s=a?.value)!==null&&s!==void 0?s:e;te(e)||(i=O(O([],w(i)),[e]));var y=g(c)?[]:{},f={};return P(c,function(u,l){var m=le(u,r,t,O(O([],w(n)),[l]),i);y[l]=m.transformedValue,g(m.annotations)?f[l]=m.annotations:_(m.annotations)&&P(m.annotations,function(p,A){f[ne(l)+"."+A]=p})}),K(f)?{transformedValue:y,annotations:a?[a.type]:void 0}:{transformedValue:y,annotations:a?[a.type,f]:f}}});function W(e){return Object.prototype.toString.call(e).slice(8,-1)}function wr(e){return W(e)==="Undefined"}function Er(e){return W(e)==="Null"}function Qe(e){if(W(e)!=="Object")return!1;let r=Object.getPrototypeOf(e);return r.constructor===Object&&r===Object.prototype}function pe(e){return W(e)==="Array"}function xr(e,r,t,n,i){return s=>e(s)||r(s)||!!t&&t(s)||!!n&&n(s)||!!i&&i(s)}var mt,Xe=d(()=>{"use strict";mt=xr(Er,wr)});function Sr(e,r,t,n,i){let s={}.propertyIsEnumerable.call(n,r)?"enumerable":"nonenumerable";s==="enumerable"&&(e[r]=t),i&&s==="nonenumerable"&&Object.defineProperty(e,r,{value:t,enumerable:!1,writable:!0,configurable:!0})}function U(e,r={}){if(pe(e))return e.map(i=>U(i,r));if(!Qe(e))return e;let t=Object.getOwnPropertyNames(e),n=Object.getOwnPropertySymbols(e);return[...t,...n].reduce((i,s)=>{if(pe(r.props)&&!r.props.includes(s))return i;let o=e[s],a=U(o,r);return Sr(i,s,a,e,r.nonenumerable),i},{})}var Ye=d(()=>{"use strict";Xe()});var Ze={};me(Ze,{allowErrorProps:()=>Cr,default:()=>Nr,deserialize:()=>_r,parse:()=>kr,registerClass:()=>Tr,registerCustom:()=>Fr,registerSymbol:()=>Ir,serialize:()=>Pr,stringify:()=>Rr});var R,Or,Ar,E,Nr,Pr,_r,Rr,kr,Tr,Fr,Ir,Cr,er=d(()=>{"use strict";Oe();X();Pe();Je();Ye();R=function(){return R=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++){r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},R.apply(this,arguments)},Or=function(e,r){var t=typeof Symbol=="function"&&e[Symbol.iterator];if(!t)return e;var n=t.call(e),i,s=[],o;try{for(;(r===void 0||r-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(o)throw o.error}}return s},Ar=function(e,r){for(var t=0,n=r.length,i=e.length;t<n;t++,i++)e[i]=r[t];return e},E=function(){function e(){this.classRegistry=new Se,this.symbolRegistry=new B(function(r){var t;return(t=r.description)!==null&&t!==void 0?t:""}),this.customTransformerRegistry=new Ne,this.allowedErrorProps=[]}return e.prototype.serialize=function(r){var t=new Map,n=le(r,t,this),i={json:n.transformedValue};n.annotations&&(i.meta=R(R({},i.meta),{values:n.annotations}));var s=Ge(t);return s&&(i.meta=R(R({},i.meta),{referentialEqualities:s})),i},e.prototype.deserialize=function(r){var t=r.json,n=r.meta,i=U(t);return n?.values&&(i=qe(i,n.values,this)),n?.referentialEqualities&&(i=He(i,n.referentialEqualities)),i},e.prototype.stringify=function(r){return JSON.stringify(this.serialize(r))},e.prototype.parse=function(r){return this.deserialize(JSON.parse(r))},e.prototype.registerClass=function(r,t){this.classRegistry.register(r,t)},e.prototype.registerSymbol=function(r,t){this.symbolRegistry.register(r,t)},e.prototype.registerCustom=function(r,t){this.customTransformerRegistry.register(R({name:t},r))},e.prototype.allowErrorProps=function(){for(var r,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];(r=this.allowedErrorProps).push.apply(r,Ar([],Or(t)))},e.defaultInstance=new e,e.serialize=e.defaultInstance.serialize.bind(e.defaultInstance),e.deserialize=e.defaultInstance.deserialize.bind(e.defaultInstance),e.stringify=e.defaultInstance.stringify.bind(e.defaultInstance),e.parse=e.defaultInstance.parse.bind(e.defaultInstance),e.registerClass=e.defaultInstance.registerClass.bind(e.defaultInstance),e.registerSymbol=e.defaultInstance.registerSymbol.bind(e.defaultInstance),e.registerCustom=e.defaultInstance.registerCustom.bind(e.defaultInstance),e.allowErrorProps=e.defaultInstance.allowErrorProps.bind(e.defaultInstance),e}(),Nr=E,Pr=E.serialize,_r=E.deserialize,Rr=E.stringify,kr=E.parse,Tr=E.registerClass,Fr=E.registerCustom,Ir=E.registerSymbol,Cr=E.allowErrorProps});var Vr={};me(Vr,{edenFetch:()=>we,edenFn:()=>rr,edenTreaty:()=>be});var k=class extends Error{status;value;constructor(r,t){super(),this.status=r,this.value=t}};var de=(e,r,t)=>{if(e.endsWith("/")||(e+="/"),r==="index"&&(r=""),!t||!Object.keys(t).length)return`${e}${r}`;let n="";for(let[i,s]of Object.entries(t))n+=`${i}=${s}&`;return`${e}${r}?${n.slice(0,-1)}`};var Q=typeof FileList>"u",he=e=>Q?e instanceof Blob:e instanceof FileList||e instanceof File,ar=e=>{if(!e)return!1;for(let r in e){if(he(e[r]))return!0;if(Array.isArray(e[r])&&e[r].find(t=>he(t)))return!0}return!1},ge=e=>Q?e:new Promise(r=>{let t=new FileReader;t.onload=()=>{r(new Blob([t.result],{type:e.type}))},t.readAsArrayBuffer(e)}),J=class{ws;url;constructor(r){this.ws=new WebSocket(r),this.url=r}send(r){return Array.isArray(r)?(r.forEach(t=>this.send(t)),this):(this.ws.send(typeof r=="object"?JSON.stringify(r):r.toString()),this)}on(r,t,n){return this.addEventListener(r,t,n)}off(r,t,n){return this.ws.removeEventListener(r,t,n),this}subscribe(r,t){return this.addEventListener("message",r,t)}addEventListener(r,t,n){return this.ws.addEventListener(r,i=>{if(r==="message"){let s=i.data.toString(),o=s.charCodeAt(0);if(o===47||o===123)try{s=JSON.parse(s)}catch{}else Number.isNaN(+s)?s==="true"?s=!0:s==="fase"&&(s=!1):s=+s;t({...i,data:s})}else t(i)},n),this}removeEventListener(r,t,n){return this.off(r,t,n),this}close(){return this.ws.close(),this}},ve=(e,r="",t)=>new Proxy(()=>{},{get(n,i,s){return ve(e,`${r}/${i.toString()}`,t)},apply(n,i,[{$query:s,$fetch:o,$headers:a,...c}={$fetch:void 0,$headers:void 0,$query:void 0}]=[{}]){let y=r.lastIndexOf("/"),f=r.slice(y+1),u=de(e,y===-1?"/":r.slice(0,y),s),l=t.fetcher??fetch;return f==="subscribe"?new J(u.replace(/^([^]+):\/\//,u.startsWith("https://")?"wss://":"ws://")):(async()=>{let p,A={...t.$fetch?.headers,...o?.headers,...a};if(f!=="GET"&&f!=="HEAD"){p=Object.keys(c).length?c:void 0;let b=typeof p=="object";if(b&&ar(p)){let V=new FormData;for(let[j,N]of Object.entries(p))if(Q)V.append(j,N);else if(N instanceof File)V.append(j,await ge(N));else if(N instanceof FileList)for(let H=0;H<N.length;H++)V.append(j,await ge(N[H]));else V.append(j,N);p=V}else A["content-type"]=b?"application/json":"text/plain",b&&(p=JSON.stringify(p))}let h=await l(u,{method:f,body:p,...t.$fetch,...o,headers:A}),C;switch(h.headers.get("Content-Type")?.split(";")[0]){case"application/json":C=await h.json();break;default:C=await h.text().then(b=>Number.isNaN(+b)?b==="true"?!0:b==="false"?!1:b:+b)}return h.status>300?{data:C,error:new k(h.status,await C),status:h.status,raw:h,headers:h.headers}:{data:C,status:h.status,response:h,headers:h.headers,error:null}})()}}),be=(e,r={fetcher:fetch})=>new Proxy({},{get(t,n){return ve(e,n,r)}});var we=(e,r)=>(t,{query:n,params:i,body:s,...o}={})=>{i&&Object.entries(i).forEach(([u,l])=>{t=t.replace(`:${u}`,l)});let a=o.headers?.["Content-Type"];if(!a||a==="application/json")try{s=JSON.stringify(s)}catch{}let c=r?.fetcher||globalThis.fetch,y=n?`?${new URLSearchParams(n).toString()}`:"",f=()=>c(e+t+y,{...o,headers:s?{"content-type":"application/json",...o.headers}:o.headers,body:s}).then(async u=>{let l;switch(u.headers.get("Content-Type")?.split(";")[0]){case"application/json":l=await u.json();break;default:l=await u.text().then(m=>Number.isNaN(+m)?m==="true"?!0:m==="false"?!1:m:+m);break}return u.status>300?{data:null,status:u.status,headers:u.headers,retry:f,error:new k(u.status,l)}:{data:l,error:null,status:u.status,headers:u.headers,retry:f}});return f()};var q=class e{url;config;pendings=[];operation=null;isFetching=!1;sJson;constructor(r,t={}){this.url=r,this.config=t,this.sJson=Promise.resolve().then(()=>(er(),Ze)).then(n=>({serialize:n.serialize,deserialize:n.deserialize}))}setConfig(r){this.config=r}clone(r){return new e(this.url,r??this.config)}async run(r,t){let n=+this.pendings.length;if(this.pendings.push(t!==void 0?{n:r,p:t}:{n:r}),this.isFetching)return this.operation?.then(s=>s[n]);this.isFetching=!0,this.operation=new Promise(s=>{setTimeout(async()=>{let o=[...this.pendings];this.pendings=[];let{serialize:a,deserialize:c}=await this.sJson,f=await(this.config?.fetcher||globalThis.fetch)(`${this.url}${this.config.fn??"/~fn"}`,{method:"POST",...this.config.fetch,headers:{"content-type":"elysia/fn",...this.config.fetch?.headers},body:JSON.stringify(a(o))});f.status===200?s(f.json().then(u=>c(u))):s(Array(o.length).fill(new Error(await f.text())))},33)});let i=await this.operation.then(s=>s[n]);return this.operation=null,this.isFetching=!1,i}};var ye=(e,r,t)=>new Proxy((...n)=>{},{get(n,i,s){return ye(e,[...r,i],t)},apply(n,i,s){let o=s[0],a=r[0];if(r.length===1){if(a in Object.prototype||a in Promise.prototype)return n(...s);switch(a){case"toJSON":return n(...s);case"$set":return t.setConfig(o);case"$clone":return ye(e,[],t.clone(o))}}return t.run(r,s).then(c=>{if(c instanceof Error)throw c;return c})}}),rr=(e,r)=>ye(e,[],new q(e,r));return or(Vr);})();
1
+ "use strict";var Eden=(()=>{var x=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var R=(n,e)=>{for(var t in e)x(n,t,{get:e[t],enumerable:!0})},M=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of j(e))!C.call(n,a)&&a!==t&&x(n,a,{get:()=>e[a],enumerable:!(s=K(e,a))||s.enumerable});return n};var P=n=>M(x({},"__esModule",{value:!0}),n);var I={};R(I,{edenFetch:()=>N,edenTreaty:()=>W});var h=class extends Error{status;value;constructor(e,t){super(),this.status=e,this.value=t}};var $=(n,e,t)=>{if(n.endsWith("/")||(n+="/"),e==="index"&&(e=""),!t||!Object.keys(t).length)return`${n}${e}`;let s="";for(let[a,r]of Object.entries(t))s+=`${a}=${r}&`;return`${n}${e}?${s.slice(0,-1)}`};var F=typeof FileList>"u",A=n=>F?n instanceof Blob:n instanceof FileList||n instanceof File,B=n=>{if(!n)return!1;for(let e in n){if(A(n[e]))return!0;if(Array.isArray(n[e])&&n[e].find(t=>A(t)))return!0}return!1},L=n=>F?n:new Promise(e=>{let t=new FileReader;t.onload=()=>{e(new Blob([t.result],{type:n.type}))},t.readAsArrayBuffer(n)}),k=class{ws;url;constructor(e){this.ws=new WebSocket(e),this.url=e}send(e){return Array.isArray(e)?(e.forEach(t=>this.send(t)),this):(this.ws.send(typeof e=="object"?JSON.stringify(e):e.toString()),this)}on(e,t,s){return this.addEventListener(e,t,s)}off(e,t,s){return this.ws.removeEventListener(e,t,s),this}subscribe(e,t){return this.addEventListener("message",e,t)}addEventListener(e,t,s){return this.ws.addEventListener(e,a=>{if(e==="message"){let r=a.data.toString(),c=r.charCodeAt(0);if(c===47||c===123)try{r=JSON.parse(r)}catch{}else Number.isNaN(+r)?r==="true"?r=!0:r==="fase"&&(r=!1):r=+r;t({...a,data:r})}else t(a)},s),this}removeEventListener(e,t,s){return this.off(e,t,s),this}close(){return this.ws.close(),this}},O=(n,e="",t)=>new Proxy(()=>{},{get(s,a,r){return O(n,`${e}/${a.toString()}`,t)},apply(s,a,[{$query:r,$fetch:c,$headers:b,...S}={$fetch:void 0,$headers:void 0,$query:void 0}]=[{}]){let m=e.lastIndexOf("/"),u=e.slice(m+1),i=$(n,m===-1?"/":e.slice(0,m),r),l=t.fetcher??fetch;return u==="subscribe"?new k(i.replace(/^([^]+):\/\//,i.startsWith("https://")?"wss://":"ws://")):(async()=>{let y,T={...t.$fetch?.headers,...c?.headers,...b};if(u!=="GET"&&u!=="HEAD"){y=Object.keys(S).length?S:void 0;let f=typeof y=="object";if(f&&B(y)){let g=new FormData;for(let[w,d]of Object.entries(y))if(F)g.append(w,d);else if(d instanceof File)g.append(w,await L(d));else if(d instanceof FileList)for(let v=0;v<d.length;v++)g.append(w,await L(d[v]));else g.append(w,d);y=g}else T["content-type"]=f?"application/json":"text/plain",f&&(y=JSON.stringify(y))}let o=await l(i,{method:u,body:y,...t.$fetch,...c,headers:T}),E;switch(o.headers.get("Content-Type")?.split(";")[0]){case"application/json":E=await o.json();break;default:E=await o.text().then(f=>Number.isNaN(+f)?f==="true"?!0:f==="false"?!1:f:+f)}return o.status>300?{data:E,error:new h(o.status,await E),status:o.status,raw:o,headers:o.headers}:{data:E,status:o.status,response:o,headers:o.headers,error:null}})()}}),W=(n,e={fetcher:fetch})=>new Proxy({},{get(t,s){return O(n,s,e)}});var N=(n,e)=>(t,{query:s,params:a,body:r,...c}={})=>{a&&Object.entries(a).forEach(([i,l])=>{t=t.replace(`:${i}`,l)});let b=c.headers?.["Content-Type"];if(!b||b==="application/json")try{r=JSON.stringify(r)}catch{}let S=e?.fetcher||globalThis.fetch,m=s?`?${new URLSearchParams(s).toString()}`:"",u=()=>S(n+t+m,{...c,headers:r?{"content-type":"application/json",...c.headers}:c.headers,body:r}).then(async i=>{let l;switch(i.headers.get("Content-Type")?.split(";")[0]){case"application/json":l=await i.json();break;default:l=await i.text().then(p=>Number.isNaN(+p)?p==="true"?!0:p==="false"?!1:p:+p);break}return i.status>300?{data:null,status:i.status,headers:i.headers,retry:u,error:new h(i.status,l)}:{data:l,error:null,status:i.status,headers:i.headers,retry:u}});return u()};return P(I);})();
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var K=Object.create;var v=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var D=(n,e)=>{for(var t in e)v(n,t,{get:e[t],enumerable:!0})},O=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of J(e))!B.call(n,i)&&i!==t&&v(n,i,{get:()=>e[i],enumerable:!(s=R(e,i))||s.enumerable});return n};var q=(n,e,t)=>(t=n!=null?K(M(n)):{},O(e||!n||!n.__esModule?v(t,"default",{value:n,enumerable:!0}):t,n)),I=n=>O(v({},"__esModule",{value:!0}),n);var H={};D(H,{edenFetch:()=>P,edenFn:()=>W,edenTreaty:()=>z});module.exports=I(H);var E=class extends Error{status;value;constructor(e,t){super(),this.status=e,this.value=t}};var C=(n,e,t)=>{if(n.endsWith("/")||(n+="/"),e==="index"&&(e=""),!t||!Object.keys(t).length)return`${n}${e}`;let s="";for(let[i,r]of Object.entries(t))s+=`${i}=${r}&`;return`${n}${e}?${s.slice(0,-1)}`};var T=typeof FileList>"u",L=n=>T?n instanceof Blob:n instanceof FileList||n instanceof File,V=n=>{if(!n)return!1;for(let e in n){if(L(n[e]))return!0;if(Array.isArray(n[e])&&n[e].find(t=>L(t)))return!0}return!1},N=n=>T?n:new Promise(e=>{let t=new FileReader;t.onload=()=>{e(new Blob([t.result],{type:n.type}))},t.readAsArrayBuffer(n)}),k=class{ws;url;constructor(e){this.ws=new WebSocket(e),this.url=e}send(e){return Array.isArray(e)?(e.forEach(t=>this.send(t)),this):(this.ws.send(typeof e=="object"?JSON.stringify(e):e.toString()),this)}on(e,t,s){return this.addEventListener(e,t,s)}off(e,t,s){return this.ws.removeEventListener(e,t,s),this}subscribe(e,t){return this.addEventListener("message",e,t)}addEventListener(e,t,s){return this.ws.addEventListener(e,i=>{if(e==="message"){let r=i.data.toString(),o=r.charCodeAt(0);if(o===47||o===123)try{r=JSON.parse(r)}catch{}else Number.isNaN(+r)?r==="true"?r=!0:r==="fase"&&(r=!1):r=+r;t({...i,data:r})}else t(i)},s),this}removeEventListener(e,t,s){return this.off(e,t,s),this}close(){return this.ws.close(),this}},j=(n,e="",t)=>new Proxy(()=>{},{get(s,i,r){return j(n,`${e}/${i.toString()}`,t)},apply(s,i,[{$query:r,$fetch:o,$headers:l,...p}={$fetch:void 0,$headers:void 0,$query:void 0}]=[{}]){let g=e.lastIndexOf("/"),c=e.slice(g+1),a=C(n,g===-1?"/":e.slice(0,g),r),y=t.fetcher??fetch;return c==="subscribe"?new k(a.replace(/^([^]+):\/\//,a.startsWith("https://")?"wss://":"ws://")):(async()=>{let u,A={...t.$fetch?.headers,...o?.headers,...l};if(c!=="GET"&&c!=="HEAD"){u=Object.keys(p).length?p:void 0;let h=typeof u=="object";if(h&&V(u)){let S=new FormData;for(let[b,d]of Object.entries(u))if(T)S.append(b,d);else if(d instanceof File)S.append(b,await N(d));else if(d instanceof FileList)for(let F=0;F<d.length;F++)S.append(b,await N(d[F]));else S.append(b,d);u=S}else A["content-type"]=h?"application/json":"text/plain",h&&(u=JSON.stringify(u))}let f=await y(a,{method:c,body:u,...t.$fetch,...o,headers:A}),w;switch(f.headers.get("Content-Type")?.split(";")[0]){case"application/json":w=await f.json();break;default:w=await f.text().then(h=>Number.isNaN(+h)?h==="true"?!0:h==="false"?!1:h:+h)}return f.status>300?{data:w,error:new E(f.status,await w),status:f.status,raw:f,headers:f.headers}:{data:w,status:f.status,response:f,headers:f.headers,error:null}})()}}),z=(n,e={fetcher:fetch})=>new Proxy({},{get(t,s){return j(n,s,e)}});var P=(n,e)=>(t,{query:s,params:i,body:r,...o}={})=>{i&&Object.entries(i).forEach(([a,y])=>{t=t.replace(`:${a}`,y)});let l=o.headers?.["Content-Type"];if(!l||l==="application/json")try{r=JSON.stringify(r)}catch{}let p=e?.fetcher||globalThis.fetch,g=s?`?${new URLSearchParams(s).toString()}`:"",c=()=>p(n+t+g,{...o,headers:r?{"content-type":"application/json",...o.headers}:o.headers,body:r}).then(async a=>{let y;switch(a.headers.get("Content-Type")?.split(";")[0]){case"application/json":y=await a.json();break;default:y=await a.text().then(m=>Number.isNaN(+m)?m==="true"?!0:m==="false"?!1:m:+m);break}return a.status>300?{data:null,status:a.status,headers:a.headers,retry:c,error:new E(a.status,y)}:{data:y,error:null,status:a.status,headers:a.headers,retry:c}});return c()};var x=class n{url;config;pendings=[];operation=null;isFetching=!1;sJson;constructor(e,t={}){this.url=e,this.config=t,this.sJson=import("superjson").then(s=>({serialize:s.serialize,deserialize:s.deserialize}))}setConfig(e){this.config=e}clone(e){return new n(this.url,e??this.config)}async run(e,t){let s=+this.pendings.length;if(this.pendings.push(t!==void 0?{n:e,p:t}:{n:e}),this.isFetching)return this.operation?.then(r=>r[s]);this.isFetching=!0,this.operation=new Promise(r=>{setTimeout(async()=>{let o=[...this.pendings];this.pendings=[];let{serialize:l,deserialize:p}=await this.sJson,c=await(this.config?.fetcher||globalThis.fetch)(`${this.url}${this.config.fn??"/~fn"}`,{method:"POST",...this.config.fetch,headers:{"content-type":"elysia/fn",...this.config.fetch?.headers},body:JSON.stringify(l(o))});c.status===200?r(c.json().then(a=>p(a))):r(Array(o.length).fill(new Error(await c.text())))},33)});let i=await this.operation.then(r=>r[s]);return this.operation=null,this.isFetching=!1,i}};var $=(n,e,t)=>new Proxy((...s)=>{},{get(s,i,r){return $(n,[...e,i],t)},apply(s,i,r){let o=r[0],l=e[0];if(e.length===1){if(l in Object.prototype||l in Promise.prototype)return s(...r);switch(l){case"toJSON":return s(...r);case"$set":return t.setConfig(o);case"$clone":return $(n,[],t.clone(o))}}return t.run(e,r).then(p=>{if(p instanceof Error)throw p;return p})}}),W=(n,e)=>$(n,[],new x(n,e));0&&(module.exports={edenFetch,edenFn,edenTreaty});
1
+ "use strict";var x=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var R=(n,e)=>{for(var t in e)x(n,t,{get:e[t],enumerable:!0})},M=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of j(e))!C.call(n,a)&&a!==t&&x(n,a,{get:()=>e[a],enumerable:!(s=K(e,a))||s.enumerable});return n};var P=n=>M(x({},"__esModule",{value:!0}),n);var I={};R(I,{edenFetch:()=>N,edenTreaty:()=>W});module.exports=P(I);var h=class extends Error{status;value;constructor(e,t){super(),this.status=e,this.value=t}};var $=(n,e,t)=>{if(n.endsWith("/")||(n+="/"),e==="index"&&(e=""),!t||!Object.keys(t).length)return`${n}${e}`;let s="";for(let[a,r]of Object.entries(t))s+=`${a}=${r}&`;return`${n}${e}?${s.slice(0,-1)}`};var F=typeof FileList>"u",A=n=>F?n instanceof Blob:n instanceof FileList||n instanceof File,B=n=>{if(!n)return!1;for(let e in n){if(A(n[e]))return!0;if(Array.isArray(n[e])&&n[e].find(t=>A(t)))return!0}return!1},L=n=>F?n:new Promise(e=>{let t=new FileReader;t.onload=()=>{e(new Blob([t.result],{type:n.type}))},t.readAsArrayBuffer(n)}),k=class{ws;url;constructor(e){this.ws=new WebSocket(e),this.url=e}send(e){return Array.isArray(e)?(e.forEach(t=>this.send(t)),this):(this.ws.send(typeof e=="object"?JSON.stringify(e):e.toString()),this)}on(e,t,s){return this.addEventListener(e,t,s)}off(e,t,s){return this.ws.removeEventListener(e,t,s),this}subscribe(e,t){return this.addEventListener("message",e,t)}addEventListener(e,t,s){return this.ws.addEventListener(e,a=>{if(e==="message"){let r=a.data.toString(),c=r.charCodeAt(0);if(c===47||c===123)try{r=JSON.parse(r)}catch{}else Number.isNaN(+r)?r==="true"?r=!0:r==="fase"&&(r=!1):r=+r;t({...a,data:r})}else t(a)},s),this}removeEventListener(e,t,s){return this.off(e,t,s),this}close(){return this.ws.close(),this}},O=(n,e="",t)=>new Proxy(()=>{},{get(s,a,r){return O(n,`${e}/${a.toString()}`,t)},apply(s,a,[{$query:r,$fetch:c,$headers:b,...S}={$fetch:void 0,$headers:void 0,$query:void 0}]=[{}]){let m=e.lastIndexOf("/"),u=e.slice(m+1),i=$(n,m===-1?"/":e.slice(0,m),r),l=t.fetcher??fetch;return u==="subscribe"?new k(i.replace(/^([^]+):\/\//,i.startsWith("https://")?"wss://":"ws://")):(async()=>{let y,T={...t.$fetch?.headers,...c?.headers,...b};if(u!=="GET"&&u!=="HEAD"){y=Object.keys(S).length?S:void 0;let f=typeof y=="object";if(f&&B(y)){let g=new FormData;for(let[w,d]of Object.entries(y))if(F)g.append(w,d);else if(d instanceof File)g.append(w,await L(d));else if(d instanceof FileList)for(let v=0;v<d.length;v++)g.append(w,await L(d[v]));else g.append(w,d);y=g}else T["content-type"]=f?"application/json":"text/plain",f&&(y=JSON.stringify(y))}let o=await l(i,{method:u,body:y,...t.$fetch,...c,headers:T}),E;switch(o.headers.get("Content-Type")?.split(";")[0]){case"application/json":E=await o.json();break;default:E=await o.text().then(f=>Number.isNaN(+f)?f==="true"?!0:f==="false"?!1:f:+f)}return o.status>300?{data:E,error:new h(o.status,await E),status:o.status,raw:o,headers:o.headers}:{data:E,status:o.status,response:o,headers:o.headers,error:null}})()}}),W=(n,e={fetcher:fetch})=>new Proxy({},{get(t,s){return O(n,s,e)}});var N=(n,e)=>(t,{query:s,params:a,body:r,...c}={})=>{a&&Object.entries(a).forEach(([i,l])=>{t=t.replace(`:${i}`,l)});let b=c.headers?.["Content-Type"];if(!b||b==="application/json")try{r=JSON.stringify(r)}catch{}let S=e?.fetcher||globalThis.fetch,m=s?`?${new URLSearchParams(s).toString()}`:"",u=()=>S(n+t+m,{...c,headers:r?{"content-type":"application/json",...c.headers}:c.headers,body:r}).then(async i=>{let l;switch(i.headers.get("Content-Type")?.split(";")[0]){case"application/json":l=await i.json();break;default:l=await i.text().then(p=>Number.isNaN(+p)?p==="true"?!0:p==="false"?!1:p:+p);break}return i.status>300?{data:null,status:i.status,headers:i.headers,retry:u,error:new h(i.status,l)}:{data:l,error:null,status:i.status,headers:i.headers,retry:u}});return u()};0&&(module.exports={edenFetch,edenTreaty});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{b as e}from"./chunk-FY4RFSUV.mjs";import{a as t}from"./chunk-TUC2YNFX.mjs";import"./chunk-Y6SMVGJX.mjs";import{a as r}from"./chunk-G4C5WHQF.mjs";export{t as edenFetch,r as edenFn,e as edenTreaty};
1
+ import{b as e}from"./chunk-MCTOFP4H.mjs";import{a as t}from"./chunk-TUC2YNFX.mjs";import"./chunk-Y6SMVGJX.mjs";export{t as edenFetch,e as edenTreaty};
@@ -1,8 +1,8 @@
1
1
  /// <reference types="bun-types" />
2
- import type { Elysia, TypedSchema } from 'elysia';
2
+ import type { Elysia, InputSchema } from 'elysia';
3
3
  import type { EdenTreaty } from './types';
4
4
  export type { EdenTreaty } from './types';
5
- export declare class EdenWS<Schema extends TypedSchema<any> = TypedSchema> {
5
+ export declare class EdenWS<Schema extends InputSchema<any> = InputSchema> {
6
6
  ws: WebSocket;
7
7
  url: string;
8
8
  constructor(url: string);
@@ -14,4 +14,7 @@ export declare class EdenWS<Schema extends TypedSchema<any> = TypedSchema> {
14
14
  removeEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | EventListenerOptions): this;
15
15
  close(): this;
16
16
  }
17
- export declare const edenTreaty: <App extends Elysia<any, any>>(domain: string, config?: EdenTreaty.Config) => EdenTreaty.Create<App>;
17
+ export declare const edenTreaty: <App extends Elysia<any, any, {
18
+ type: {};
19
+ error: {};
20
+ }, {}, {}, false>>(domain: string, config?: EdenTreaty.Config) => EdenTreaty.Create<App>;
@@ -1 +1 @@
1
- "use strict";var Eden=(()=>{var v=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var N=(s,e)=>{for(var t in e)v(s,t,{get:e[t],enumerable:!0})},R=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of F(e))!K.call(s,i)&&i!==t&&v(s,i,{get:()=>e[i],enumerable:!(n=O(e,i))||n.enumerable});return s};var M=s=>R(v({},"__esModule",{value:!0}),s);var P={};N(P,{EdenWS:()=>g,edenTreaty:()=>B});var h=class extends Error{status;value;constructor(e,t){super(),this.status=e,this.value=t}};var x=(s,e,t)=>{if(s.endsWith("/")||(s+="/"),e==="index"&&(e=""),!t||!Object.keys(t).length)return`${s}${e}`;let n="";for(let[i,r]of Object.entries(t))n+=`${i}=${r}&`;return`${s}${e}?${n.slice(0,-1)}`};var S=typeof FileList>"u",$=s=>S?s instanceof Blob:s instanceof FileList||s instanceof File,j=s=>{if(!s)return!1;for(let e in s){if($(s[e]))return!0;if(Array.isArray(s[e])&&s[e].find(t=>$(t)))return!0}return!1},T=s=>S?s:new Promise(e=>{let t=new FileReader;t.onload=()=>{e(new Blob([t.result],{type:s.type}))},t.readAsArrayBuffer(s)}),g=class{ws;url;constructor(e){this.ws=new WebSocket(e),this.url=e}send(e){return Array.isArray(e)?(e.forEach(t=>this.send(t)),this):(this.ws.send(typeof e=="object"?JSON.stringify(e):e.toString()),this)}on(e,t,n){return this.addEventListener(e,t,n)}off(e,t,n){return this.ws.removeEventListener(e,t,n),this}subscribe(e,t){return this.addEventListener("message",e,t)}addEventListener(e,t,n){return this.ws.addEventListener(e,i=>{if(e==="message"){let r=i.data.toString(),u=r.charCodeAt(0);if(u===47||u===123)try{r=JSON.parse(r)}catch{}else Number.isNaN(+r)?r==="true"?r=!0:r==="fase"&&(r=!1):r=+r;t({...i,data:r})}else t(i)},n),this}removeEventListener(e,t,n){return this.off(e,t,n),this}close(){return this.ws.close(),this}},L=(s,e="",t)=>new Proxy(()=>{},{get(n,i,r){return L(s,`${e}/${i.toString()}`,t)},apply(n,i,[{$query:r,$fetch:u,$headers:W,...w}={$fetch:void 0,$headers:void 0,$query:void 0}]=[{}]){let E=e.lastIndexOf("/"),y=e.slice(E+1),b=x(s,E===-1?"/":e.slice(0,E),r),A=t.fetcher??fetch;return y==="subscribe"?new g(b.replace(/^([^]+):\/\//,b.startsWith("https://")?"wss://":"ws://")):(async()=>{let c,k={...t.$fetch?.headers,...u?.headers,...W};if(y!=="GET"&&y!=="HEAD"){c=Object.keys(w).length?w:void 0;let o=typeof c=="object";if(o&&j(c)){let l=new FormData;for(let[p,f]of Object.entries(c))if(S)l.append(p,f);else if(f instanceof File)l.append(p,await T(f));else if(f instanceof FileList)for(let m=0;m<f.length;m++)l.append(p,await T(f[m]));else l.append(p,f);c=l}else k["content-type"]=o?"application/json":"text/plain",o&&(c=JSON.stringify(c))}let a=await A(b,{method:y,body:c,...t.$fetch,...u,headers:k}),d;switch(a.headers.get("Content-Type")?.split(";")[0]){case"application/json":d=await a.json();break;default:d=await a.text().then(o=>Number.isNaN(+o)?o==="true"?!0:o==="false"?!1:o:+o)}return a.status>300?{data:d,error:new h(a.status,await d),status:a.status,raw:a,headers:a.headers}:{data:d,status:a.status,response:a,headers:a.headers,error:null}})()}}),B=(s,e={fetcher:fetch})=>new Proxy({},{get(t,n){return L(s,n,e)}});return M(P);})();
1
+ "use strict";var Eden=(()=>{var v=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var N=(s,e)=>{for(var t in e)v(s,t,{get:e[t],enumerable:!0})},R=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of K(e))!T.call(s,i)&&i!==t&&v(s,i,{get:()=>e[i],enumerable:!(n=F(e,i))||n.enumerable});return s};var M=s=>R(v({},"__esModule",{value:!0}),s);var I={};N(I,{EdenWS:()=>g,edenTreaty:()=>B});var h=class extends Error{status;value;constructor(e,t){super(),this.status=e,this.value=t}};var x=(s,e,t)=>{if(s.endsWith("/")||(s+="/"),e==="index"&&(e=""),!t||!Object.keys(t).length)return`${s}${e}`;let n="";for(let[i,r]of Object.entries(t))n+=`${i}=${r}&`;return`${s}${e}?${n.slice(0,-1)}`};var S=typeof FileList>"u",$=s=>S?s instanceof Blob:s instanceof FileList||s instanceof File,j=s=>{if(!s)return!1;for(let e in s){if($(s[e]))return!0;if(Array.isArray(s[e])&&s[e].find(t=>$(t)))return!0}return!1},L=s=>S?s:new Promise(e=>{let t=new FileReader;t.onload=()=>{e(new Blob([t.result],{type:s.type}))},t.readAsArrayBuffer(s)}),g=class{ws;url;constructor(e){this.ws=new WebSocket(e),this.url=e}send(e){return Array.isArray(e)?(e.forEach(t=>this.send(t)),this):(this.ws.send(typeof e=="object"?JSON.stringify(e):e.toString()),this)}on(e,t,n){return this.addEventListener(e,t,n)}off(e,t,n){return this.ws.removeEventListener(e,t,n),this}subscribe(e,t){return this.addEventListener("message",e,t)}addEventListener(e,t,n){return this.ws.addEventListener(e,i=>{if(e==="message"){let r=i.data.toString(),f=r.charCodeAt(0);if(f===47||f===123)try{r=JSON.parse(r)}catch{}else Number.isNaN(+r)?r==="true"?r=!0:r==="fase"&&(r=!1):r=+r;t({...i,data:r})}else t(i)},n),this}removeEventListener(e,t,n){return this.off(e,t,n),this}close(){return this.ws.close(),this}},W=(s,e="",t)=>new Proxy(()=>{},{get(n,i,r){return W(s,`${e}/${i.toString()}`,t)},apply(n,i,[{$query:r,$fetch:f,$headers:A,...w}={$fetch:void 0,$headers:void 0,$query:void 0}]=[{}]){let E=e.lastIndexOf("/"),y=e.slice(E+1),b=x(s,E===-1?"/":e.slice(0,E),r),O=t.fetcher??fetch;return y==="subscribe"?new g(b.replace(/^([^]+):\/\//,b.startsWith("https://")?"wss://":"ws://")):(async()=>{let c,k={...t.$fetch?.headers,...f?.headers,...A};if(y!=="GET"&&y!=="HEAD"){c=Object.keys(w).length?w:void 0;let o=typeof c=="object";if(o&&j(c)){let d=new FormData;for(let[p,u]of Object.entries(c))if(S)d.append(p,u);else if(u instanceof File)d.append(p,await L(u));else if(u instanceof FileList)for(let m=0;m<u.length;m++)d.append(p,await L(u[m]));else d.append(p,u);c=d}else k["content-type"]=o?"application/json":"text/plain",o&&(c=JSON.stringify(c))}let a=await O(b,{method:y,body:c,...t.$fetch,...f,headers:k}),l;switch(a.headers.get("Content-Type")?.split(";")[0]){case"application/json":l=await a.json();break;default:l=await a.text().then(o=>Number.isNaN(+o)?o==="true"?!0:o==="false"?!1:o:+o)}return a.status>300?{data:l,error:new h(a.status,await l),status:a.status,raw:a,headers:a.headers}:{data:l,status:a.status,response:a,headers:a.headers,error:null}})()}}),B=(s,e={fetcher:fetch})=>new Proxy({},{get(t,n){return W(s,n,e)}});return M(I);})();
package/dist/treaty.js CHANGED
@@ -1 +1 @@
1
- "use strict";var v=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var N=(s,e)=>{for(var t in e)v(s,t,{get:e[t],enumerable:!0})},R=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of F(e))!K.call(s,i)&&i!==t&&v(s,i,{get:()=>e[i],enumerable:!(n=O(e,i))||n.enumerable});return s};var M=s=>R(v({},"__esModule",{value:!0}),s);var P={};N(P,{EdenWS:()=>g,edenTreaty:()=>B});module.exports=M(P);var h=class extends Error{status;value;constructor(e,t){super(),this.status=e,this.value=t}};var x=(s,e,t)=>{if(s.endsWith("/")||(s+="/"),e==="index"&&(e=""),!t||!Object.keys(t).length)return`${s}${e}`;let n="";for(let[i,r]of Object.entries(t))n+=`${i}=${r}&`;return`${s}${e}?${n.slice(0,-1)}`};var S=typeof FileList>"u",$=s=>S?s instanceof Blob:s instanceof FileList||s instanceof File,j=s=>{if(!s)return!1;for(let e in s){if($(s[e]))return!0;if(Array.isArray(s[e])&&s[e].find(t=>$(t)))return!0}return!1},T=s=>S?s:new Promise(e=>{let t=new FileReader;t.onload=()=>{e(new Blob([t.result],{type:s.type}))},t.readAsArrayBuffer(s)}),g=class{ws;url;constructor(e){this.ws=new WebSocket(e),this.url=e}send(e){return Array.isArray(e)?(e.forEach(t=>this.send(t)),this):(this.ws.send(typeof e=="object"?JSON.stringify(e):e.toString()),this)}on(e,t,n){return this.addEventListener(e,t,n)}off(e,t,n){return this.ws.removeEventListener(e,t,n),this}subscribe(e,t){return this.addEventListener("message",e,t)}addEventListener(e,t,n){return this.ws.addEventListener(e,i=>{if(e==="message"){let r=i.data.toString(),u=r.charCodeAt(0);if(u===47||u===123)try{r=JSON.parse(r)}catch{}else Number.isNaN(+r)?r==="true"?r=!0:r==="fase"&&(r=!1):r=+r;t({...i,data:r})}else t(i)},n),this}removeEventListener(e,t,n){return this.off(e,t,n),this}close(){return this.ws.close(),this}},L=(s,e="",t)=>new Proxy(()=>{},{get(n,i,r){return L(s,`${e}/${i.toString()}`,t)},apply(n,i,[{$query:r,$fetch:u,$headers:W,...w}={$fetch:void 0,$headers:void 0,$query:void 0}]=[{}]){let E=e.lastIndexOf("/"),y=e.slice(E+1),b=x(s,E===-1?"/":e.slice(0,E),r),A=t.fetcher??fetch;return y==="subscribe"?new g(b.replace(/^([^]+):\/\//,b.startsWith("https://")?"wss://":"ws://")):(async()=>{let c,k={...t.$fetch?.headers,...u?.headers,...W};if(y!=="GET"&&y!=="HEAD"){c=Object.keys(w).length?w:void 0;let o=typeof c=="object";if(o&&j(c)){let l=new FormData;for(let[p,f]of Object.entries(c))if(S)l.append(p,f);else if(f instanceof File)l.append(p,await T(f));else if(f instanceof FileList)for(let m=0;m<f.length;m++)l.append(p,await T(f[m]));else l.append(p,f);c=l}else k["content-type"]=o?"application/json":"text/plain",o&&(c=JSON.stringify(c))}let a=await A(b,{method:y,body:c,...t.$fetch,...u,headers:k}),d;switch(a.headers.get("Content-Type")?.split(";")[0]){case"application/json":d=await a.json();break;default:d=await a.text().then(o=>Number.isNaN(+o)?o==="true"?!0:o==="false"?!1:o:+o)}return a.status>300?{data:d,error:new h(a.status,await d),status:a.status,raw:a,headers:a.headers}:{data:d,status:a.status,response:a,headers:a.headers,error:null}})()}}),B=(s,e={fetcher:fetch})=>new Proxy({},{get(t,n){return L(s,n,e)}});0&&(module.exports={EdenWS,edenTreaty});
1
+ "use strict";var v=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var N=(s,e)=>{for(var t in e)v(s,t,{get:e[t],enumerable:!0})},R=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of K(e))!T.call(s,i)&&i!==t&&v(s,i,{get:()=>e[i],enumerable:!(n=F(e,i))||n.enumerable});return s};var M=s=>R(v({},"__esModule",{value:!0}),s);var I={};N(I,{EdenWS:()=>g,edenTreaty:()=>B});module.exports=M(I);var h=class extends Error{status;value;constructor(e,t){super(),this.status=e,this.value=t}};var x=(s,e,t)=>{if(s.endsWith("/")||(s+="/"),e==="index"&&(e=""),!t||!Object.keys(t).length)return`${s}${e}`;let n="";for(let[i,r]of Object.entries(t))n+=`${i}=${r}&`;return`${s}${e}?${n.slice(0,-1)}`};var S=typeof FileList>"u",$=s=>S?s instanceof Blob:s instanceof FileList||s instanceof File,j=s=>{if(!s)return!1;for(let e in s){if($(s[e]))return!0;if(Array.isArray(s[e])&&s[e].find(t=>$(t)))return!0}return!1},L=s=>S?s:new Promise(e=>{let t=new FileReader;t.onload=()=>{e(new Blob([t.result],{type:s.type}))},t.readAsArrayBuffer(s)}),g=class{ws;url;constructor(e){this.ws=new WebSocket(e),this.url=e}send(e){return Array.isArray(e)?(e.forEach(t=>this.send(t)),this):(this.ws.send(typeof e=="object"?JSON.stringify(e):e.toString()),this)}on(e,t,n){return this.addEventListener(e,t,n)}off(e,t,n){return this.ws.removeEventListener(e,t,n),this}subscribe(e,t){return this.addEventListener("message",e,t)}addEventListener(e,t,n){return this.ws.addEventListener(e,i=>{if(e==="message"){let r=i.data.toString(),f=r.charCodeAt(0);if(f===47||f===123)try{r=JSON.parse(r)}catch{}else Number.isNaN(+r)?r==="true"?r=!0:r==="fase"&&(r=!1):r=+r;t({...i,data:r})}else t(i)},n),this}removeEventListener(e,t,n){return this.off(e,t,n),this}close(){return this.ws.close(),this}},W=(s,e="",t)=>new Proxy(()=>{},{get(n,i,r){return W(s,`${e}/${i.toString()}`,t)},apply(n,i,[{$query:r,$fetch:f,$headers:A,...w}={$fetch:void 0,$headers:void 0,$query:void 0}]=[{}]){let E=e.lastIndexOf("/"),y=e.slice(E+1),b=x(s,E===-1?"/":e.slice(0,E),r),O=t.fetcher??fetch;return y==="subscribe"?new g(b.replace(/^([^]+):\/\//,b.startsWith("https://")?"wss://":"ws://")):(async()=>{let c,k={...t.$fetch?.headers,...f?.headers,...A};if(y!=="GET"&&y!=="HEAD"){c=Object.keys(w).length?w:void 0;let o=typeof c=="object";if(o&&j(c)){let d=new FormData;for(let[p,u]of Object.entries(c))if(S)d.append(p,u);else if(u instanceof File)d.append(p,await L(u));else if(u instanceof FileList)for(let m=0;m<u.length;m++)d.append(p,await L(u[m]));else d.append(p,u);c=d}else k["content-type"]=o?"application/json":"text/plain",o&&(c=JSON.stringify(c))}let a=await O(b,{method:y,body:c,...t.$fetch,...f,headers:k}),l;switch(a.headers.get("Content-Type")?.split(";")[0]){case"application/json":l=await a.json();break;default:l=await a.text().then(o=>Number.isNaN(+o)?o==="true"?!0:o==="false"?!1:o:+o)}return a.status>300?{data:l,error:new h(a.status,await l),status:a.status,raw:a,headers:a.headers}:{data:l,status:a.status,response:a,headers:a.headers,error:null}})()}}),B=(s,e={fetcher:fetch})=>new Proxy({},{get(t,n){return W(s,n,e)}});0&&(module.exports={EdenWS,edenTreaty});
package/dist/treaty.mjs CHANGED
@@ -1 +1 @@
1
- import{a,b}from"./chunk-FY4RFSUV.mjs";import"./chunk-Y6SMVGJX.mjs";export{a as EdenWS,b as edenTreaty};
1
+ import{a,b}from"./chunk-MCTOFP4H.mjs";import"./chunk-Y6SMVGJX.mjs";export{a as EdenWS,b as edenTreaty};
package/package.json CHANGED
@@ -1,90 +1,80 @@
1
1
  {
2
- "name": "@elysiajs/eden",
3
- "version": "0.6.5",
4
- "description": "Fully type-safe Elysia client",
5
- "author": {
6
- "name": "saltyAom",
7
- "url": "https://github.com/SaltyAom",
8
- "email": "saltyaom@gmail.com"
9
- },
10
- "main": "./dist/index.js",
11
- "exports": {
12
- ".": {
13
- "require": "./dist/index.js",
14
- "import": "./dist/index.mjs",
15
- "node": "./dist/index.js",
16
- "default": "./dist/index.js",
17
- "types": "./dist/index.d.ts"
2
+ "name": "@elysiajs/eden",
3
+ "version": "0.7.0-beta.1",
4
+ "description": "Fully type-safe Elysia client",
5
+ "author": {
6
+ "name": "saltyAom",
7
+ "url": "https://github.com/SaltyAom",
8
+ "email": "saltyaom@gmail.com"
18
9
  },
19
- "./treaty": {
20
- "require": "./dist/treaty.js",
21
- "import": "./dist/treaty.mjs",
22
- "node": "./dist/treaty.js",
23
- "default": "./dist/treaty.js",
24
- "types": "./dist/treaty/index.d.ts"
10
+ "main": "./dist/index.js",
11
+ "exports": {
12
+ ".": {
13
+ "require": "./dist/index.js",
14
+ "import": "./dist/index.mjs",
15
+ "node": "./dist/index.js",
16
+ "default": "./dist/index.js",
17
+ "types": "./dist/index.d.ts"
18
+ },
19
+ "./treaty": {
20
+ "require": "./dist/treaty.js",
21
+ "import": "./dist/treaty.mjs",
22
+ "node": "./dist/treaty.js",
23
+ "default": "./dist/treaty.js",
24
+ "types": "./dist/treaty/index.d.ts"
25
+ },
26
+ "./fetch": {
27
+ "require": "./dist/fetch.js",
28
+ "import": "./dist/fetch.mjs",
29
+ "node": "./dist/fetch.js",
30
+ "default": "./dist/fetch.js",
31
+ "types": "./dist/fetch/index.d.ts"
32
+ }
25
33
  },
26
- "./fetch": {
27
- "require": "./dist/fetch.js",
28
- "import": "./dist/fetch.mjs",
29
- "node": "./dist/fetch.js",
30
- "default": "./dist/fetch.js",
31
- "types": "./dist/fetch/index.d.ts"
34
+ "types": "./src/index.ts",
35
+ "keywords": [
36
+ "elysia",
37
+ "eden",
38
+ "connector"
39
+ ],
40
+ "homepage": "https://github.com/elysiajs/elysia-eden",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/elysiajs/elysia-eden"
32
44
  },
33
- "./fn": {
34
- "require": "./dist/fn.js",
35
- "import": "./dist/fn.mjs",
36
- "node": "./dist/fn.js",
37
- "default": "./dist/fn.js",
38
- "types": "./dist/fn/index.d.ts"
39
- }
40
- },
41
- "types": "./src/index.ts",
42
- "keywords": [
43
- "elysia",
44
- "eden",
45
- "connector"
46
- ],
47
- "homepage": "https://github.com/elysiajs/elysia-eden",
48
- "repository": {
49
- "type": "git",
50
- "url": "https://github.com/elysiajs/elysia-eden"
51
- },
52
- "bugs": "https://github.com/elysiajs/elysia-eden/issues",
53
- "license": "MIT",
54
- "scripts": {
55
- "dev": "bun run --watch example/index.ts",
56
- "test": "bun test",
57
- "build": "tsup",
58
- "release": "npm run build && npm run test && npm publish --access public"
59
- },
60
- "peerDependencies": {
61
- "elysia": ">= 0.6.7"
62
- },
63
- "peerDependenciesMeta": {
64
- "@sinclair/typebox": {
65
- "optional": true
45
+ "bugs": "https://github.com/elysiajs/elysia-eden/issues",
46
+ "license": "MIT",
47
+ "scripts": {
48
+ "dev": "bun run --watch example/index.ts",
49
+ "test": "bun test",
50
+ "build": "tsup",
51
+ "release": "npm run build && npm run test && npm publish --access public"
52
+ },
53
+ "peerDependencies": {
54
+ "elysia": ">= 0.7.0-beta.0"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "@sinclair/typebox": {
58
+ "optional": true
59
+ }
60
+ },
61
+ "devDependencies": {
62
+ "@elysiajs/cors": "0.6.0",
63
+ "@elysiajs/fn": "^0.6.1",
64
+ "@sinclair/typebox": "^0.26.8",
65
+ "@types/node": "^18.15.5",
66
+ "bun-types": "^1.0.1",
67
+ "elysia": "0.7.0-beta.0",
68
+ "esbuild": "^0.19.2",
69
+ "eslint": "^8.26.0",
70
+ "rimraf": "^4.4.1",
71
+ "tsup": "^7.2.0",
72
+ "typescript": "^5.0.4"
73
+ },
74
+ "prettier": {
75
+ "semi": false,
76
+ "tabWidth": 4,
77
+ "singleQuote": true,
78
+ "trailingComma": "none"
66
79
  }
67
- },
68
- "devDependencies": {
69
- "@elysiajs/cors": "0.6.0",
70
- "@elysiajs/fn": "^0.6.1",
71
- "@sinclair/typebox": "^0.26.8",
72
- "@types/node": "^18.15.5",
73
- "bun-types": "^1.0.1",
74
- "elysia": "0.6.22",
75
- "esbuild": "^0.19.2",
76
- "eslint": "^8.26.0",
77
- "rimraf": "^4.4.1",
78
- "tsup": "^7.2.0",
79
- "typescript": "^5.0.4"
80
- },
81
- "dependencies": {
82
- "superjson": "^1.12.2"
83
- },
84
- "prettier": {
85
- "semi": false,
86
- "tabWidth": 4,
87
- "singleQuote": true,
88
- "trailingComma": "none"
89
- }
90
- }
80
+ }
@@ -7,11 +7,12 @@ type Prettify<T> = {
7
7
  } & {}
8
8
 
9
9
  export namespace EdenFetch {
10
- export type Create<App extends Elysia<any, any>> = App['meta'] extends {
11
- schema: infer Schema extends Record<string, any>
12
- }
13
- ? EdenFetch.Fn<Schema>
14
- : 'Please install Elysia before using Eden'
10
+ export type Create<App extends Elysia<any, any, any, any, any, any>> =
11
+ App extends {
12
+ schema: infer Schema extends Record<string, any>
13
+ }
14
+ ? EdenFetch.Fn<Schema>
15
+ : 'Please install Elysia before using Eden'
15
16
 
16
17
  export interface Config {
17
18
  fetcher?: typeof globalThis.fetch
package/src/index.ts CHANGED
@@ -2,8 +2,6 @@ import type { Elysia } from 'elysia'
2
2
 
3
3
  import type { EdenTreaty } from './treaty'
4
4
  import type { EdenFetch } from './fetch'
5
- import type { EdenFn } from './fn'
6
5
 
7
6
  export { edenTreaty } from './treaty'
8
7
  export { edenFetch } from './fetch'
9
- export { edenFn } from './fn'
@@ -1,4 +1,4 @@
1
- import type { Elysia, TypedSchema } from 'elysia'
1
+ import type { Elysia, InputSchema } from 'elysia'
2
2
 
3
3
  import { EdenFetchError } from '../errors'
4
4
 
@@ -51,7 +51,7 @@ const fileToBlob = (v: File) =>
51
51
  reader.readAsArrayBuffer(v)
52
52
  })
53
53
 
54
- export class EdenWS<Schema extends TypedSchema<any> = TypedSchema> {
54
+ export class EdenWS<Schema extends InputSchema<any> = InputSchema> {
55
55
  ws: WebSocket
56
56
  url: string
57
57
 
@@ -9,6 +9,7 @@ import type {
9
9
  } from '../types'
10
10
  import type { EdenFetchError } from '../errors'
11
11
 
12
+ // @ts-ignore
12
13
  type Files = File | FileList
13
14
 
14
15
  type Replace<RecordType, TargetType, GenericType> = {
@@ -35,18 +36,19 @@ type Prettify<T> = {
35
36
 
36
37
  type AnySchema = {
37
38
  body: unknown
38
- headers: Record<string, any> | undefined
39
- query: Record<string, any> | undefined
40
- params: Record<string, any> | undefined
39
+ headers: unknown
40
+ query: unknown
41
+ params: unknown
41
42
  response: any
42
43
  }
43
44
 
44
45
  export namespace EdenTreaty {
45
- export type Create<App extends Elysia<any, any>> = App['meta'] extends {
46
- schema: infer Schema extends Record<string, any>
47
- }
48
- ? UnionToIntersect<Sign<Schema>>
49
- : 'Please install Elysia before using Eden'
46
+ export type Create<App extends Elysia<any, any, any, any, any, any>> =
47
+ App extends {
48
+ schema: infer Schema extends Record<string, any>
49
+ }
50
+ ? UnionToIntersect<Sign<Schema>>
51
+ : 'Please install Elysia before using Eden'
50
52
 
51
53
  export interface Config {
52
54
  /**
package/tsup.config.ts CHANGED
@@ -6,8 +6,7 @@ export default defineConfig({
6
6
  entry: {
7
7
  index: resolve(__dirname, 'src/index.ts'),
8
8
  treaty: resolve(__dirname, 'src/treaty/index.ts'),
9
- fetch: resolve(__dirname, 'src/fetch/index.ts'),
10
- fn: resolve(__dirname, 'src/fn/index.ts')
9
+ fetch: resolve(__dirname, 'src/fetch/index.ts')
11
10
  },
12
11
  format: ['cjs', 'esm', 'iife'],
13
12
  globalName: 'Eden',
package/src/fn/index.ts DELETED
@@ -1,56 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import type { Elysia } from 'elysia'
3
-
4
- import { Signal } from './utils'
5
-
6
- import type { EdenFn } from './types'
7
- export type { EdenFn } from './types'
8
-
9
- const createProxy = (
10
- domain: string,
11
- procedures: string[],
12
- signal: Signal
13
- ): Record<string, unknown> =>
14
- // eslint-disable-next-line @typescript-eslint/no-empty-function
15
- new Proxy((..._: any[]) => {}, {
16
- get(target, key, value) {
17
- return createProxy(domain, [...procedures, key as string], signal)
18
- },
19
- apply(target, _, params) {
20
- const param = params[0]
21
- const procedure = procedures[0]
22
-
23
- if (procedures.length === 1) {
24
- if (
25
- procedure in Object.prototype ||
26
- procedure in Promise.prototype
27
- )
28
- return target(...params)
29
-
30
- switch (procedure) {
31
- case 'toJSON':
32
- return target(...params)
33
-
34
- case '$set':
35
- return signal.setConfig(param)
36
-
37
- case '$clone':
38
- return createProxy(domain, [], signal.clone(param))
39
- }
40
- }
41
-
42
- return signal.run(procedures, params).then((result) => {
43
- if (result instanceof Error) throw result
44
-
45
- return result
46
- })
47
- }
48
- }) as any
49
-
50
- export const edenFn = <App extends Elysia<any, any>>(
51
- domain: string,
52
- config?: EdenFn.Config
53
- ): EdenFn.Create<App> =>
54
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
55
- // @ts-ignore
56
- createProxy(domain, [], new Signal(domain, config))
package/src/fn/types.ts DELETED
@@ -1,45 +0,0 @@
1
- import type { Elysia } from 'elysia'
2
-
3
- export namespace EdenFn {
4
- export type Create<App extends Elysia<any, any>> = App['meta'] extends {
5
- exposed: infer Schema extends Record<string, any>
6
- }
7
- ? EdenFn.Compose<Schema>
8
- : 'Please install Elysia before using Eden'
9
-
10
- export interface Config {}
11
-
12
- export type Compose<Exposed extends Record<string, any>> = Fn<Exposed> & {
13
- $set(config: Config): void
14
- $clone(config?: Config): Compose<Exposed>
15
- }
16
-
17
- export type Fn<T> = T extends {
18
- exposed: any
19
- value: infer Value
20
- }
21
- ? Asynctify<Value>
22
- : Asynctify<T>
23
-
24
- export interface Config {
25
- fn?: string
26
- fetch?: Omit<RequestInit, 'body'>
27
- fetcher?: typeof globalThis.fetch
28
- }
29
- }
30
-
31
- type Promisify<T extends (...args: any[]) => any> = T extends (
32
- ...args: infer Args
33
- ) => infer Return
34
- ? Return extends Promise<any>
35
- ? T
36
- : (...args: Args) => Promise<Return>
37
- : never
38
-
39
- type Asynctify<T> = T extends infer Fn extends (...args: any) => any
40
- ? Promisify<Fn>
41
- : T extends Record<string, any>
42
- ? {
43
- [K in keyof T]: EdenFn.Fn<T[K]>
44
- }
45
- : never
package/src/fn/utils.ts DELETED
@@ -1,87 +0,0 @@
1
- import type { serialize, deserialize } from 'superjson'
2
- import type { EdenFn } from './types'
3
-
4
- export class Signal {
5
- private url: string
6
- private config: EdenFn.Config
7
-
8
- private pendings: Array<{ n: string[] } | { n: string[]; p: any }> = []
9
- private operation: Promise<any[]> | null = null
10
- private isFetching = false
11
-
12
- private sJson: Promise<{
13
- serialize: typeof serialize
14
- deserialize: typeof deserialize
15
- }>
16
-
17
- constructor(url: string, config: EdenFn.Config = {}) {
18
- this.url = url
19
- this.config = config
20
-
21
- this.sJson = import('superjson').then((superJson) => {
22
- return {
23
- serialize: superJson.serialize,
24
- deserialize: superJson.deserialize
25
- }
26
- })
27
- }
28
-
29
- setConfig(config: EdenFn.Config) {
30
- this.config = config
31
- }
32
-
33
- clone(config?: EdenFn.Config) {
34
- return new Signal(this.url, config ?? this.config)
35
- }
36
-
37
- async run(procedure: string[], params: any) {
38
- const current = +this.pendings.length
39
- this.pendings.push(
40
- params !== undefined
41
- ? { n: procedure, p: params }
42
- : { n: procedure }
43
- )
44
-
45
- if (this.isFetching) return this.operation?.then((x) => x[current])
46
- this.isFetching = true
47
-
48
- this.operation = new Promise((resolve) => {
49
- setTimeout(async () => {
50
- const requests = [...this.pendings]
51
- this.pendings = []
52
-
53
- const { serialize, deserialize } = await this.sJson
54
-
55
- const fetch = this.config?.fetcher || globalThis.fetch
56
- const results = await fetch(
57
- `${this.url}${this.config.fn ?? '/~fn'}`,
58
- {
59
- method: 'POST',
60
- ...this.config.fetch,
61
- headers: {
62
- 'content-type': 'elysia/fn',
63
- ...this.config.fetch?.headers
64
- },
65
- body: JSON.stringify(serialize(requests))
66
- }
67
- )
68
-
69
- if (results.status === 200)
70
- resolve(results.json().then((x) => deserialize(x as any)))
71
- else
72
- resolve(
73
- Array(requests.length).fill(
74
- new Error(await results.text())
75
- )
76
- )
77
- }, 33)
78
- })
79
-
80
- const result = await this.operation.then((results) => results[current])
81
-
82
- this.operation = null
83
- this.isFetching = false
84
-
85
- return result
86
- }
87
- }