@elysiajs/eden 0.6.4 → 0.7.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-FY4RFSUV.mjs +1 -0
- package/dist/chunk-MCTOFP4H.mjs +1 -0
- package/dist/fetch/index.d.ts +4 -1
- package/dist/fetch/types.d.ts +5 -4
- package/dist/fetch.global.js +1 -0
- package/dist/fetch.js +1 -1
- package/dist/fn/index.d.ts +4 -1
- package/dist/fn/types.d.ts +1 -0
- package/dist/fn.global.js +1 -0
- package/dist/fn.js +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.global.js +1 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/treaty/index.d.ts +7 -3
- package/dist/treaty.global.js +1 -0
- package/dist/treaty.js +1 -1
- package/dist/treaty.mjs +1 -1
- package/package.json +78 -84
- package/src/fetch/types.ts +11 -10
- package/src/index.ts +0 -27
- package/src/treaty/index.ts +6 -4
- package/src/treaty/types.ts +10 -8
- package/tsup.config.ts +8 -8
- package/src/fn/index.ts +0 -56
- package/src/fn/types.ts +0 -45
- package/src/fn/utils.ts +0 -87
|
@@ -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,A=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}},T=(n,e="",t)=>new Proxy(()=>{},{get(r,o,s){return T(n,`${e}/${o.toString()}`,t)},apply(r,o,[{$query:s,$fetch:d,$headers:L,...m}={$fetch:void 0,$headers:void 0,$query:void 0}]=[{}]){let h=e.lastIndexOf("/"),u=e.slice(h+1),g=k(n,h===-1?"/":e.slice(0,h),s),W=t.fetcher??fetch;return u==="subscribe"?new b(g.replace(/^([^]+):\/\//,g.startsWith("https://")?"wss://":"ws://")):(async()=>{let c,w={...t.$fetch?.headers,...d?.headers,...L};if(u!=="GET"&&u!=="HEAD"){c=Object.keys(m).length?m:void 0;let a=typeof c=="object";if(a&&A(c)){let y=new FormData;for(let[p,f]of Object.entries(c))if(v)y.append(p,f);else if(f instanceof File)y.append(p,await $(f));else if(f instanceof FileList)for(let E=0;E<f.length;E++)y.append(p,await $(f[E]));else y.append(p,f);c=y}else w["content-type"]=a?"application/json":"text/plain",a&&(c=JSON.stringify(c))}let i=await W(g,{method:u,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 T(n,r,e)}});export{b as a,M as b};
|
|
@@ -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};
|
package/dist/fetch/index.d.ts
CHANGED
|
@@ -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
|
|
4
|
+
export declare const edenFetch: <App extends Elysia<any, any, {
|
|
5
|
+
type: {};
|
|
6
|
+
error: {};
|
|
7
|
+
}, {}, {}, false>>(server: string, config?: EdenFetch.Config) => EdenFetch.Create<App>;
|
package/dist/fetch/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bun-types" />
|
|
1
2
|
import type { Elysia } from 'elysia';
|
|
2
3
|
import type { EdenFetchError } from '../errors';
|
|
3
4
|
import type { MapError, IsUnknown, IsNever } from '../types';
|
|
@@ -5,16 +6,16 @@ type Prettify<T> = {
|
|
|
5
6
|
[K in keyof T]: T[K];
|
|
6
7
|
} & {};
|
|
7
8
|
export declare namespace EdenFetch {
|
|
8
|
-
type Create<App extends Elysia<any, any>> = App
|
|
9
|
+
type Create<App extends Elysia<any, any, any, any, any, any>> = App extends {
|
|
9
10
|
schema: infer Schema extends Record<string, any>;
|
|
10
11
|
} ? EdenFetch.Fn<Schema> : 'Please install Elysia before using Eden';
|
|
11
12
|
interface Config {
|
|
12
13
|
fetcher?: typeof globalThis.fetch;
|
|
13
14
|
}
|
|
14
|
-
type Fn<Schema extends Record<string, any>> = <Endpoint extends keyof Schema, Method extends Extract<keyof Schema[Endpoint], string
|
|
15
|
-
method?:
|
|
15
|
+
type Fn<Schema extends Record<string, any>> = <Endpoint extends keyof Schema, Method extends Uppercase<Extract<keyof Schema[Endpoint], string>>, Route extends Schema[Endpoint][Lowercase<Method>]>(endpoint: Endpoint, options: Omit<RequestInit, 'body' | 'method' | 'headers'> & ('GET' extends Method ? {
|
|
16
|
+
method?: Method;
|
|
16
17
|
} : {
|
|
17
|
-
method:
|
|
18
|
+
method: Method;
|
|
18
19
|
}) & (IsNever<keyof Route['params']> extends true ? {
|
|
19
20
|
params?: Record<never, string>;
|
|
20
21
|
} : {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var Eden=(()=>{var p=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var E=(r,e)=>{for(var a in e)p(r,a,{get:e[a],enumerable:!0})},S=(r,e,a,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of g(e))!x.call(r,s)&&s!==a&&p(r,s,{get:()=>e[s],enumerable:!(u=m(e,s))||u.enumerable});return r};var j=r=>S(p({},"__esModule",{value:!0}),r);var b={};E(b,{edenFetch:()=>w});var h=class extends Error{status;value;constructor(e,a){super(),this.status=e,this.value=a}};var w=(r,e)=>(a,{query:u,params:s,body:c,...o}={})=>{s&&Object.entries(s).forEach(([t,n])=>{a=a.replace(`:${t}`,n)});let f=o.headers?.["Content-Type"];if(!f||f==="application/json")try{c=JSON.stringify(c)}catch{}let y=e?.fetcher||globalThis.fetch,d=u?`?${new URLSearchParams(u).toString()}`:"",l=()=>y(r+a+d,{...o,headers:c?{"content-type":"application/json",...o.headers}:o.headers,body:c}).then(async t=>{let n;switch(t.headers.get("Content-Type")?.split(";")[0]){case"application/json":n=await t.json();break;default:n=await t.text().then(i=>Number.isNaN(+i)?i==="true"?!0:i==="false"?!1:i:+i);break}return t.status>300?{data:null,status:t.status,headers:t.headers,retry:l,error:new h(t.status,n)}:{data:n,error:null,status:t.status,headers:t.headers,retry:l}});return l()};return j(b);})();
|
package/dist/fetch.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var p=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var E=(r,e)=>{for(var a in e)p(r,a,{get:e[a],enumerable:!0})},S=(r,e,a,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of g(e))!x.call(r,s)&&s!==a&&p(r,s,{get:()=>e[s],enumerable:!(u=m(e,s))||u.enumerable});return r};var j=r=>S(p({},"__esModule",{value:!0}),r);var b={};E(b,{edenFetch:()=>w});module.exports=j(b);var h=class extends Error{status;value;constructor(e,a){super(),this.status=e,this.value=a}};var w=(r,e)=>(a,{query:u,params:s,body:c,...o}={})=>{s&&Object.entries(s).forEach(([t,n])=>{a=a.replace(`:${t}`,n)});let f=o.headers?.["Content-Type"];if(!f||f==="application/json")try{c=JSON.stringify(c)}catch{}let y=e?.fetcher||globalThis.fetch,d=u?`?${new URLSearchParams(u).toString()}`:"",l=()=>y(r+a+d,{...o,headers:c?{"content-type":"application/json",...o.headers}:o.headers,body:c}).then(async t=>{let n;switch(t.headers.get("Content-Type")?.split(";")[0]){case"application/json":n=await t.json();break;default:n=await t.text().then(i=>Number.isNaN(+i)?i==="true"?!0:i==="false"?!1:i:+i);break}return t.status>300?{data:null,status:t.status,headers:t.headers,retry:l,error:new h(t.status,n)}:{data:n,error:null,status:t.status,headers:t.headers,retry:l}});return l()};0&&(module.exports={edenFetch});
|
|
1
|
+
"use strict";var p=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var E=(r,e)=>{for(var a in e)p(r,a,{get:e[a],enumerable:!0})},S=(r,e,a,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of g(e))!x.call(r,s)&&s!==a&&p(r,s,{get:()=>e[s],enumerable:!(u=m(e,s))||u.enumerable});return r};var j=r=>S(p({},"__esModule",{value:!0}),r);var b={};E(b,{edenFetch:()=>w});module.exports=j(b);var h=class extends Error{status;value;constructor(e,a){super(),this.status=e,this.value=a}};var w=(r,e)=>(a,{query:u,params:s,body:c,...o}={})=>{s&&Object.entries(s).forEach(([t,n])=>{a=a.replace(`:${t}`,n)});let f=o.headers?.["Content-Type"];if(!f||f==="application/json")try{c=JSON.stringify(c)}catch{}let y=e?.fetcher||globalThis.fetch,d=u?`?${new URLSearchParams(u).toString()}`:"",l=()=>y(r+a+d,{...o,headers:c?{"content-type":"application/json",...o.headers}:o.headers,body:c}).then(async t=>{let n;switch(t.headers.get("Content-Type")?.split(";")[0]){case"application/json":n=await t.json();break;default:n=await t.text().then(i=>Number.isNaN(+i)?i==="true"?!0:i==="false"?!1:i:+i);break}return t.status>300?{data:null,status:t.status,headers:t.headers,retry:l,error:new h(t.status,n)}:{data:n,error:null,status:t.status,headers:t.headers,retry:l}});return l()};0&&(module.exports={edenFetch});
|
package/dist/fn/index.d.ts
CHANGED
|
@@ -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
|
|
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/fn/types.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var Eden=(()=>{var U=Object.defineProperty;var Dr=Object.getOwnPropertyDescriptor;var Ur=Object.getOwnPropertyNames;var Mr=Object.prototype.hasOwnProperty;var f=(r,t)=>()=>(r&&(t=r(r=0)),t);var ir=(r,t)=>{for(var e in t)U(r,e,{get:t[e],enumerable:!0})},Kr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ur(t))!Mr.call(r,i)&&i!==e&&U(r,i,{get:()=>t[i],enumerable:!(n=Dr(t,i))||n.enumerable});return r};var qr=r=>Kr(U({},"__esModule",{value:!0}),r);var or,sr=f(()=>{"use strict";or=function(){function r(){this.keyToValue=new Map,this.valueToKey=new Map}return r.prototype.set=function(t,e){this.keyToValue.set(t,e),this.valueToKey.set(e,t)},r.prototype.getByKey=function(t){return this.keyToValue.get(t)},r.prototype.getByValue=function(t){return this.valueToKey.get(t)},r.prototype.clear=function(){this.keyToValue.clear(),this.valueToKey.clear()},r}()});var T,M=f(()=>{"use strict";sr();T=function(){function r(t){this.generateIdentifier=t,this.kv=new or}return r.prototype.register=function(t,e){this.kv.getByValue(t)||(e||(e=this.generateIdentifier(t)),this.kv.set(e,t))},r.prototype.clear=function(){this.kv.clear()},r.prototype.getIdentifier=function(t){return this.kv.getByValue(t)},r.prototype.getValue=function(t){return this.kv.getByKey(t)},r}()});var Lr,ar,ur=f(()=>{"use strict";M();Lr=function(){var r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&(n[o]=i[o])},r(t,e)};return function(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");r(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}}(),ar=function(r){Lr(t,r);function t(){var e=r.call(this,function(n){return n.name})||this;return e.classToAllowedProps=new Map,e}return t.prototype.register=function(e,n){typeof n=="object"?(n.allowProps&&this.classToAllowedProps.set(e,n.allowProps),r.prototype.register.call(this,e,n.identifier)):r.prototype.register.call(this,e,n)},t.prototype.getAllowedProps=function(e){return this.classToAllowedProps.get(e)},t}(T)});function $r(r){if("values"in Object)return Object.values(r);var t=[];for(var e in r)r.hasOwnProperty(e)&&t.push(r[e]);return t}function fr(r,t){var e=$r(r);if("find"in e)return e.find(t);for(var n=e,i=0;i<n.length;i++){var o=n[i];if(t(o))return o}}function O(r,t){Object.entries(r).forEach(function(e){var n=Wr(e,2),i=n[0],o=n[1];return t(o,i)})}function S(r,t){return r.indexOf(t)!==-1}function K(r,t){for(var e=0;e<r.length;e++){var n=r[e];if(t(n))return n}}var Wr,N=f(()=>{"use strict";Wr=function(r,t){var e=typeof Symbol=="function"&&r[Symbol.iterator];if(!e)return r;var n=e.call(r),i,o=[],s;try{for(;(t===void 0||t-- >0)&&!(i=n.next()).done;)o.push(i.value)}catch(a){s={error:a}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(s)throw s.error}}return o}});var lr,cr=f(()=>{"use strict";N();lr=function(){function r(){this.transfomers={}}return r.prototype.register=function(t){this.transfomers[t.name]=t},r.prototype.findApplicable=function(t){return fr(this.transfomers,function(e){return e.isApplicable(t)})},r.prototype.findByName=function(t){return this.transfomers[t]},r}()});var Gr,q,Hr,A,V,c,Qr,Xr,Yr,pr,w,x,L,yr,mr,W,$,vr,gr,hr,dr,z=f(()=>{"use strict";Gr=function(r){return Object.prototype.toString.call(r).slice(8,-1)},q=function(r){return typeof r>"u"},Hr=function(r){return r===null},A=function(r){return typeof r!="object"||r===null||r===Object.prototype?!1:Object.getPrototypeOf(r)===null?!0:r.constructor===Object&&Object.getPrototypeOf(r)===Object.prototype},V=function(r){return A(r)&&Object.keys(r).length===0},c=function(r){return Array.isArray(r)},Qr=function(r){return typeof r=="string"},Xr=function(r){return typeof r=="number"&&!isNaN(r)},Yr=function(r){return typeof r=="boolean"},pr=function(r){return r instanceof RegExp},w=function(r){return r instanceof Map},x=function(r){return r instanceof Set},L=function(r){return Gr(r)==="Symbol"},yr=function(r){return r instanceof Date&&!isNaN(r.valueOf())},mr=function(r){return r instanceof Error},W=function(r){return typeof r=="number"&&isNaN(r)},$=function(r){return Yr(r)||Hr(r)||q(r)||Xr(r)||Qr(r)||L(r)},vr=function(r){return typeof r=="bigint"},gr=function(r){return r===1/0||r===-1/0},hr=function(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)},dr=function(r){return r instanceof URL}});var G,k,P,H=f(()=>{"use strict";G=function(r){return r.replace(/\./g,"\\.")},k=function(r){return r.map(String).map(G).join(".")},P=function(r){for(var t=[],e="",n=0;n<r.length;n++){var i=r.charAt(n),o=i==="\\"&&r.charAt(n+1)===".";if(o){e+=".",n++;continue}var s=i===".";if(s){t.push(e),e="";continue}e+=i}var a=e;return t.push(a),t}});function m(r,t,e,n){return{isApplicable:r,annotation:t,transform:e,untransform:n}}function C(r,t,e,n){return{isApplicable:r,annotation:t,transform:e,untransform:n}}function Z(r,t){if(r?.constructor){var e=!!t.classRegistry.getIdentifier(r.constructor);return e}return!1}var Q,X,Y,br,wr,Zr,xr,Er,Or,Jr,J,Ar,_r,Sr=f(()=>{"use strict";z();N();Q=function(){return Q=Object.assign||function(r){for(var t,e=1,n=arguments.length;e<n;e++){t=arguments[e];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(r[i]=t[i])}return r},Q.apply(this,arguments)},X=function(r,t){var e=typeof Symbol=="function"&&r[Symbol.iterator];if(!e)return r;var n=e.call(r),i,o=[],s;try{for(;(t===void 0||t-- >0)&&!(i=n.next()).done;)o.push(i.value)}catch(a){s={error:a}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(s)throw s.error}}return o},Y=function(r,t){for(var e=0,n=t.length,i=r.length;e<n;e++,i++)r[i]=t[e];return r};br=[m(q,"undefined",function(){return null},function(){}),m(vr,"bigint",function(r){return r.toString()},function(r){return typeof BigInt<"u"?BigInt(r):(console.error("Please add a BigInt polyfill."),r)}),m(yr,"Date",function(r){return r.toISOString()},function(r){return new Date(r)}),m(mr,"Error",function(r,t){var e={name:r.name,message:r.message};return t.allowedErrorProps.forEach(function(n){e[n]=r[n]}),e},function(r,t){var e=new Error(r.message);return e.name=r.name,e.stack=r.stack,t.allowedErrorProps.forEach(function(n){e[n]=r[n]}),e}),m(pr,"regexp",function(r){return""+r},function(r){var t=r.slice(1,r.lastIndexOf("/")),e=r.slice(r.lastIndexOf("/")+1);return new RegExp(t,e)}),m(x,"set",function(r){return Y([],X(r.values()))},function(r){return new Set(r)}),m(w,"map",function(r){return Y([],X(r.entries()))},function(r){return new Map(r)}),m(function(r){return W(r)||gr(r)},"number",function(r){return W(r)?"NaN":r>0?"Infinity":"-Infinity"},Number),m(function(r){return r===0&&1/r===-1/0},"number",function(){return"-0"},Number),m(dr,"URL",function(r){return r.toString()},function(r){return new URL(r)})];wr=C(function(r,t){if(L(r)){var e=!!t.symbolRegistry.getIdentifier(r);return e}return!1},function(r,t){var e=t.symbolRegistry.getIdentifier(r);return["symbol",e]},function(r){return r.description},function(r,t,e){var n=e.symbolRegistry.getValue(t[1]);if(!n)throw new Error("Trying to deserialize unknown symbol");return n}),Zr=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Uint8ClampedArray].reduce(function(r,t){return r[t.name]=t,r},{}),xr=C(hr,function(r){return["typed-array",r.constructor.name]},function(r){return Y([],X(r))},function(r,t){var e=Zr[t[1]];if(!e)throw new Error("Trying to deserialize unknown typed array");return new e(r)});Er=C(Z,function(r,t){var e=t.classRegistry.getIdentifier(r.constructor);return["class",e]},function(r,t){var e=t.classRegistry.getAllowedProps(r.constructor);if(!e)return Q({},r);var n={};return e.forEach(function(i){n[i]=r[i]}),n},function(r,t,e){var n=e.classRegistry.getValue(t[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),r)}),Or=C(function(r,t){return!!t.customTransformerRegistry.findApplicable(r)},function(r,t){var e=t.customTransformerRegistry.findApplicable(r);return["custom",e.name]},function(r,t){var e=t.customTransformerRegistry.findApplicable(r);return e.serialize(r)},function(r,t,e){var n=e.customTransformerRegistry.findByName(t[1]);if(!n)throw new Error("Trying to deserialize unknown custom value");return n.deserialize(r)}),Jr=[Er,wr,Or,xr],J=function(r,t){var e=K(Jr,function(i){return i.isApplicable(r,t)});if(e)return{value:e.transform(r,t),type:e.annotation(r,t)};var n=K(br,function(i){return i.isApplicable(r,t)});if(n)return{value:n.transform(r,t),type:n.annotation}},Ar={};br.forEach(function(r){Ar[r.annotation]=r});_r=function(r,t,e){if(c(t))switch(t[0]){case"symbol":return wr.untransform(r,t,e);case"class":return Er.untransform(r,t,e);case"custom":return Or.untransform(r,t,e);case"typed-array":return xr.untransform(r,t,e);default:throw new Error("Unknown transformation: "+t)}else{var n=Ar[t];if(!n)throw new Error("Unknown transformation: "+t);return n.untransform(r,e)}}});function Pr(r){if(S(r,"__proto__"))throw new Error("__proto__ is not allowed as a property");if(S(r,"prototype"))throw new Error("prototype is not allowed as a property");if(S(r,"constructor"))throw new Error("constructor is not allowed as a property")}var R,Rr,F,Nr=f(()=>{"use strict";z();N();R=function(r,t){for(var e=r.keys();t>0;)e.next(),t--;return e.next().value};Rr=function(r,t){Pr(t);for(var e=0;e<t.length;e++){var n=t[e];if(x(r))r=R(r,+n);else if(w(r)){var i=+n,o=+t[++e]==0?"key":"value",s=R(r,i);switch(o){case"key":r=s;break;case"value":r=r.get(s);break}}else r=r[n]}return r},F=function(r,t,e){if(Pr(t),t.length===0)return e(r);for(var n=r,i=0;i<t.length-1;i++){var o=t[i];if(c(n)){var s=+o;n=n[s]}else if(A(n))n=n[o];else if(x(n)){var a=+o;n=R(n,a)}else if(w(n)){var u=i===t.length-2;if(u)break;var a=+o,p=+t[++i]==0?"key":"value",l=R(n,a);switch(p){case"key":n=l;break;case"value":n=n.get(l);break}}}var y=t[t.length-1];if(c(n)?n[+y]=e(n[+y]):A(n)&&(n[y]=e(n[y])),x(n)){var h=R(n,+y),d=e(h);h!==d&&(n.delete(h),n.add(d))}if(w(n)){var a=+t[t.length-2],b=R(n,a),p=+y==0?"key":"value";switch(p){case"key":{var I=e(b);n.set(I,n.get(b)),I!==b&&n.delete(b);break}case"value":{n.set(b,e(n.get(b)));break}}}return r}});function rr(r,t,e){if(e===void 0&&(e=[]),!!r){if(!c(r)){O(r,function(s,a){return rr(s,t,E(E([],v(e)),v(P(a))))});return}var n=v(r,2),i=n[0],o=n[1];o&&O(o,function(s,a){rr(s,t,E(E([],v(e)),v(P(a))))}),t(i,e)}}function Ir(r,t,e){return rr(t,function(n,i){r=F(r,i,function(o){return _r(o,n,e)})}),r}function Tr(r,t){function e(s,a){var u=Rr(r,P(a));s.map(P).forEach(function(p){r=F(r,p,function(){return u})})}if(c(t)){var n=v(t,2),i=n[0],o=n[1];i.forEach(function(s){r=F(r,P(s),function(){return r})}),o&&O(o,e)}else O(t,e);return r}function tt(r,t,e){var n=e.get(r);n?n.push(t):e.set(r,[t])}function Vr(r){var t={},e=void 0;return r.forEach(function(n){if(!(n.length<=1)){var i=v(n.map(function(a){return a.map(String)}).sort(function(a,u){return a.length-u.length})),o=i[0],s=i.slice(1);o.length===0?e=s.map(k):t[k(o)]=s.map(k)}}),e?V(t)?[e]:[e,t]:V(t)?void 0:t}var v,E,rt,tr,zr=f(()=>{"use strict";z();H();Sr();N();H();Nr();v=function(r,t){var e=typeof Symbol=="function"&&r[Symbol.iterator];if(!e)return r;var n=e.call(r),i,o=[],s;try{for(;(t===void 0||t-- >0)&&!(i=n.next()).done;)o.push(i.value)}catch(a){s={error:a}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(s)throw s.error}}return o},E=function(r,t){for(var e=0,n=t.length,i=r.length;e<n;e++,i++)r[i]=t[e];return r};rt=function(r,t){return A(r)||c(r)||w(r)||x(r)||Z(r,t)};tr=function(r,t,e,n,i){var o;if(n===void 0&&(n=[]),i===void 0&&(i=[]),$(r)||tt(r,n,t),!rt(r,e)){var s=J(r,e);return s?{transformedValue:s.value,annotations:[s.type]}:{transformedValue:r}}if(S(i,r))return{transformedValue:null};var a=J(r,e),u=(o=a?.value)!==null&&o!==void 0?o:r;$(r)||(i=E(E([],v(i)),[r]));var p=c(u)?[]:{},l={};return O(u,function(y,h){var d=tr(y,t,e,E(E([],v(n)),[h]),i);p[h]=d.transformedValue,c(d.annotations)?l[h]=d.annotations:A(d.annotations)&&O(d.annotations,function(b,I){l[G(h)+"."+I]=b})}),V(l)?{transformedValue:p,annotations:a?[a.type]:void 0}:{transformedValue:p,annotations:a?[a.type,l]:l}}});function B(r){return Object.prototype.toString.call(r).slice(8,-1)}function et(r){return B(r)==="Undefined"}function nt(r){return B(r)==="Null"}function kr(r){if(B(r)!=="Object")return!1;let t=Object.getPrototypeOf(r);return t.constructor===Object&&t===Object.prototype}function er(r){return B(r)==="Array"}function it(r,t,e,n,i){return o=>r(o)||t(o)||!!e&&e(o)||!!n&&n(o)||!!i&&i(o)}var qt,Cr=f(()=>{"use strict";qt=it(nt,et)});function ot(r,t,e,n,i){let o={}.propertyIsEnumerable.call(n,t)?"enumerable":"nonenumerable";o==="enumerable"&&(r[t]=e),i&&o==="nonenumerable"&&Object.defineProperty(r,t,{value:e,enumerable:!1,writable:!0,configurable:!0})}function j(r,t={}){if(er(r))return r.map(i=>j(i,t));if(!kr(r))return r;let e=Object.getOwnPropertyNames(r),n=Object.getOwnPropertySymbols(r);return[...e,...n].reduce((i,o)=>{if(er(t.props)&&!t.props.includes(o))return i;let s=r[o],a=j(s,t);return ot(i,o,a,r,t.nonenumerable),i},{})}var Fr=f(()=>{"use strict";Cr()});var Br={};ir(Br,{allowErrorProps:()=>gt,default:()=>ut,deserialize:()=>lt,parse:()=>pt,registerClass:()=>yt,registerCustom:()=>mt,registerSymbol:()=>vt,serialize:()=>ft,stringify:()=>ct});var _,st,at,g,ut,ft,lt,ct,pt,yt,mt,vt,gt,jr=f(()=>{"use strict";ur();M();cr();zr();Fr();_=function(){return _=Object.assign||function(r){for(var t,e=1,n=arguments.length;e<n;e++){t=arguments[e];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(r[i]=t[i])}return r},_.apply(this,arguments)},st=function(r,t){var e=typeof Symbol=="function"&&r[Symbol.iterator];if(!e)return r;var n=e.call(r),i,o=[],s;try{for(;(t===void 0||t-- >0)&&!(i=n.next()).done;)o.push(i.value)}catch(a){s={error:a}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(s)throw s.error}}return o},at=function(r,t){for(var e=0,n=t.length,i=r.length;e<n;e++,i++)r[i]=t[e];return r},g=function(){function r(){this.classRegistry=new ar,this.symbolRegistry=new T(function(t){var e;return(e=t.description)!==null&&e!==void 0?e:""}),this.customTransformerRegistry=new lr,this.allowedErrorProps=[]}return r.prototype.serialize=function(t){var e=new Map,n=tr(t,e,this),i={json:n.transformedValue};n.annotations&&(i.meta=_(_({},i.meta),{values:n.annotations}));var o=Vr(e);return o&&(i.meta=_(_({},i.meta),{referentialEqualities:o})),i},r.prototype.deserialize=function(t){var e=t.json,n=t.meta,i=j(e);return n?.values&&(i=Ir(i,n.values,this)),n?.referentialEqualities&&(i=Tr(i,n.referentialEqualities)),i},r.prototype.stringify=function(t){return JSON.stringify(this.serialize(t))},r.prototype.parse=function(t){return this.deserialize(JSON.parse(t))},r.prototype.registerClass=function(t,e){this.classRegistry.register(t,e)},r.prototype.registerSymbol=function(t,e){this.symbolRegistry.register(t,e)},r.prototype.registerCustom=function(t,e){this.customTransformerRegistry.register(_({name:e},t))},r.prototype.allowErrorProps=function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];(t=this.allowedErrorProps).push.apply(t,at([],st(e)))},r.defaultInstance=new r,r.serialize=r.defaultInstance.serialize.bind(r.defaultInstance),r.deserialize=r.defaultInstance.deserialize.bind(r.defaultInstance),r.stringify=r.defaultInstance.stringify.bind(r.defaultInstance),r.parse=r.defaultInstance.parse.bind(r.defaultInstance),r.registerClass=r.defaultInstance.registerClass.bind(r.defaultInstance),r.registerSymbol=r.defaultInstance.registerSymbol.bind(r.defaultInstance),r.registerCustom=r.defaultInstance.registerCustom.bind(r.defaultInstance),r.allowErrorProps=r.defaultInstance.allowErrorProps.bind(r.defaultInstance),r}(),ut=g,ft=g.serialize,lt=g.deserialize,ct=g.stringify,pt=g.parse,yt=g.registerClass,mt=g.registerCustom,vt=g.registerSymbol,gt=g.allowErrorProps});var dt={};ir(dt,{edenFn:()=>ht});var D=class r{url;config;pendings=[];operation=null;isFetching=!1;sJson;constructor(t,e={}){this.url=t,this.config=e,this.sJson=Promise.resolve().then(()=>(jr(),Br)).then(n=>({serialize:n.serialize,deserialize:n.deserialize}))}setConfig(t){this.config=t}clone(t){return new r(this.url,t??this.config)}async run(t,e){let n=+this.pendings.length;if(this.pendings.push(e!==void 0?{n:t,p:e}:{n:t}),this.isFetching)return this.operation?.then(o=>o[n]);this.isFetching=!0,this.operation=new Promise(o=>{setTimeout(async()=>{let s=[...this.pendings];this.pendings=[];let{serialize:a,deserialize:u}=await this.sJson,l=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(s))});l.status===200?o(l.json().then(y=>u(y))):o(Array(s.length).fill(new Error(await l.text())))},33)});let i=await this.operation.then(o=>o[n]);return this.operation=null,this.isFetching=!1,i}};var nr=(r,t,e)=>new Proxy((...n)=>{},{get(n,i,o){return nr(r,[...t,i],e)},apply(n,i,o){let s=o[0],a=t[0];if(t.length===1){if(a in Object.prototype||a in Promise.prototype)return n(...o);switch(a){case"toJSON":return n(...o);case"$set":return e.setConfig(s);case"$clone":return nr(r,[],e.clone(s))}}return e.run(t,o).then(u=>{if(u instanceof Error)throw u;return u})}}),ht=(r,t)=>nr(r,[],new D(r,t));return qr(dt);})();
|
package/dist/fn.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var u=Object.create;var c=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var w=(n,e)=>{for(var t in e)c(n,t,{get:e[t],enumerable:!0})},g=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of F(e))!E.call(n,r)&&r!==t&&c(n,r,{get:()=>e[r],enumerable:!(i=d(e,r))||i.enumerable});return n};var z=(n,e,t)=>(t=n!=null?u(m(n)):{},g(e||!n||!n.__esModule?c(t,"default",{value:n,enumerable:!0}):t,n)),C=n=>g(c({},"__esModule",{value:!0}),n);var P={};w(P,{edenFn:()=>x});module.exports=C(P);var f=class n{url;config;pendings=[];operation=null;isFetching=!1;sJson;constructor(e,t={}){this.url=e,this.config=t,this.sJson=import("superjson").then(i=>({serialize:i.serialize,deserialize:i.deserialize}))}setConfig(e){this.config=e}clone(e){return new n(this.url,e??this.config)}async run(e,t){let i=+this.pendings.length;if(this.pendings.push(t!==void 0?{n:e,p:t}:{n:e}),this.isFetching)return this.operation?.then(s=>s[i]);this.isFetching=!0,this.operation=new Promise(s=>{setTimeout(async()=>{let o=[...this.pendings];this.pendings=[];let{serialize:a,deserialize:h}=await this.sJson,p=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))});p.status===200?s(p.json().then(y=>h(y))):s(Array(o.length).fill(new Error(await p.text())))},33)});let r=await this.operation.then(s=>s[i]);return this.operation=null,this.isFetching=!1,r}};var l=(n,e,t)=>new Proxy((...i)=>{},{get(i,r,s){return l(n,[...e,r],t)},apply(i,r,s){let o=s[0],a=e[0];if(e.length===1){if(a in Object.prototype||a in Promise.prototype)return i(...s);switch(a){case"toJSON":return i(...s);case"$set":return t.setConfig(o);case"$clone":return l(n,[],t.clone(o))}}return t.run(e,s).then(h=>{if(h instanceof Error)throw h;return h})}}),x=(n,e)=>l(n,[],new f(n,e));0&&(module.exports={edenFn});
|
|
1
|
+
"use strict";var u=Object.create;var c=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var w=(n,e)=>{for(var t in e)c(n,t,{get:e[t],enumerable:!0})},g=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of F(e))!E.call(n,r)&&r!==t&&c(n,r,{get:()=>e[r],enumerable:!(i=d(e,r))||i.enumerable});return n};var z=(n,e,t)=>(t=n!=null?u(m(n)):{},g(e||!n||!n.__esModule?c(t,"default",{value:n,enumerable:!0}):t,n)),C=n=>g(c({},"__esModule",{value:!0}),n);var P={};w(P,{edenFn:()=>x});module.exports=C(P);var f=class n{url;config;pendings=[];operation=null;isFetching=!1;sJson;constructor(e,t={}){this.url=e,this.config=t,this.sJson=import("superjson").then(i=>({serialize:i.serialize,deserialize:i.deserialize}))}setConfig(e){this.config=e}clone(e){return new n(this.url,e??this.config)}async run(e,t){let i=+this.pendings.length;if(this.pendings.push(t!==void 0?{n:e,p:t}:{n:e}),this.isFetching)return this.operation?.then(s=>s[i]);this.isFetching=!0,this.operation=new Promise(s=>{setTimeout(async()=>{let o=[...this.pendings];this.pendings=[];let{serialize:a,deserialize:h}=await this.sJson,p=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))});p.status===200?s(p.json().then(y=>h(y))):s(Array(o.length).fill(new Error(await p.text())))},33)});let r=await this.operation.then(s=>s[i]);return this.operation=null,this.isFetching=!1,r}};var l=(n,e,t)=>new Proxy((...i)=>{},{get(i,r,s){return l(n,[...e,r],t)},apply(i,r,s){let o=s[0],a=e[0];if(e.length===1){if(a in Object.prototype||a in Promise.prototype)return i(...s);switch(a){case"toJSON":return i(...s);case"$set":return t.setConfig(o);case"$clone":return l(n,[],t.clone(o))}}return t.run(e,s).then(h=>{if(h instanceof Error)throw h;return h})}}),x=(n,e)=>l(n,[],new f(n,e));0&&(module.exports={edenFn});
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
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
|
-
|
|
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-
|
|
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};
|
package/dist/treaty/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="bun-types" />
|
|
2
|
+
import type { Elysia, InputSchema } from 'elysia';
|
|
2
3
|
import type { EdenTreaty } from './types';
|
|
3
4
|
export type { EdenTreaty } from './types';
|
|
4
|
-
export declare class EdenWS<Schema extends
|
|
5
|
+
export declare class EdenWS<Schema extends InputSchema<any> = InputSchema> {
|
|
5
6
|
ws: WebSocket;
|
|
6
7
|
url: string;
|
|
7
8
|
constructor(url: string);
|
|
@@ -13,4 +14,7 @@ export declare class EdenWS<Schema extends TypedSchema<any> = TypedSchema> {
|
|
|
13
14
|
removeEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | EventListenerOptions): this;
|
|
14
15
|
close(): this;
|
|
15
16
|
}
|
|
16
|
-
export declare const edenTreaty: <App extends Elysia<any, any
|
|
17
|
+
export declare const edenTreaty: <App extends Elysia<any, any, {
|
|
18
|
+
type: {};
|
|
19
|
+
error: {};
|
|
20
|
+
}, {}, {}, false>>(domain: string, config?: EdenTreaty.Config) => EdenTreaty.Create<App>;
|
|
@@ -0,0 +1 @@
|
|
|
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
|
-
var
|
|
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-
|
|
1
|
+
import{a,b}from"./chunk-MCTOFP4H.mjs";import"./chunk-Y6SMVGJX.mjs";export{a as EdenWS,b as edenTreaty};
|
package/package.json
CHANGED
|
@@ -1,89 +1,83 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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.0",
|
|
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
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
+
"dependencies": {
|
|
75
|
+
"superjson": "^1.12.2"
|
|
76
|
+
},
|
|
77
|
+
"prettier": {
|
|
78
|
+
"semi": false,
|
|
79
|
+
"tabWidth": 4,
|
|
80
|
+
"singleQuote": true,
|
|
81
|
+
"trailingComma": "none"
|
|
66
82
|
}
|
|
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
|
-
"elysia": "0.6.10",
|
|
74
|
-
"esbuild": "^0.19.2",
|
|
75
|
-
"eslint": "^8.26.0",
|
|
76
|
-
"rimraf": "^4.4.1",
|
|
77
|
-
"tsup": "^7.2.0",
|
|
78
|
-
"typescript": "^5.0.4"
|
|
79
|
-
},
|
|
80
|
-
"dependencies": {
|
|
81
|
-
"superjson": "^1.12.2"
|
|
82
|
-
},
|
|
83
|
-
"prettier": {
|
|
84
|
-
"semi": false,
|
|
85
|
-
"tabWidth": 4,
|
|
86
|
-
"singleQuote": true,
|
|
87
|
-
"trailingComma": "none"
|
|
88
|
-
}
|
|
89
|
-
}
|
|
83
|
+
}
|
package/src/fetch/types.ts
CHANGED
|
@@ -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
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
|
@@ -19,17 +20,17 @@ export namespace EdenFetch {
|
|
|
19
20
|
|
|
20
21
|
export type Fn<Schema extends Record<string, any>> = <
|
|
21
22
|
Endpoint extends keyof Schema,
|
|
22
|
-
Method extends Extract<keyof Schema[Endpoint], string
|
|
23
|
-
Route extends Schema[Endpoint][Method]
|
|
23
|
+
Method extends Uppercase<Extract<keyof Schema[Endpoint], string>>,
|
|
24
|
+
Route extends Schema[Endpoint][Lowercase<Method>]
|
|
24
25
|
>(
|
|
25
26
|
endpoint: Endpoint,
|
|
26
27
|
options: Omit<RequestInit, 'body' | 'method' | 'headers'> &
|
|
27
|
-
('
|
|
28
|
+
('GET' extends Method
|
|
28
29
|
? {
|
|
29
|
-
method?:
|
|
30
|
+
method?: Method
|
|
30
31
|
}
|
|
31
32
|
: {
|
|
32
|
-
method:
|
|
33
|
+
method: Method
|
|
33
34
|
}) &
|
|
34
35
|
(IsNever<keyof Route['params']> extends true
|
|
35
36
|
? {
|
package/src/index.ts
CHANGED
|
@@ -2,33 +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'
|
|
10
|
-
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
// export const eden: Eden = (domain: string) => ({
|
|
13
|
-
// treaty(config) {
|
|
14
|
-
// return import('./treaty').then((x) => x.edenTreaty(domain, config))
|
|
15
|
-
// },
|
|
16
|
-
// fn(config) {
|
|
17
|
-
// return import('./fn').then((x) => x.edenFn(domain, config))
|
|
18
|
-
// },
|
|
19
|
-
// fetch(config) {
|
|
20
|
-
// return import('./fetch').then((x) => x.edenFetch(domain, config))
|
|
21
|
-
// }
|
|
22
|
-
// })
|
|
23
|
-
|
|
24
|
-
// type Eden = (domain: string) => {
|
|
25
|
-
// treaty<App extends Elysia<any>>(
|
|
26
|
-
// config?: EdenTreaty.Config
|
|
27
|
-
// ): EdenTreaty.Create<App>
|
|
28
|
-
|
|
29
|
-
// fetch<App extends Elysia<any>>(
|
|
30
|
-
// config?: EdenFetch.Config
|
|
31
|
-
// ): EdenFetch.Create<App>
|
|
32
|
-
|
|
33
|
-
// fn<App extends Elysia<any>>(config?: EdenFn.Config): EdenFn.Create<App>
|
|
34
|
-
// }
|
package/src/treaty/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { 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
|
|
54
|
+
export class EdenWS<Schema extends InputSchema<any> = InputSchema> {
|
|
55
55
|
ws: WebSocket
|
|
56
56
|
url: string
|
|
57
57
|
|
|
@@ -179,7 +179,9 @@ const createProxy = (
|
|
|
179
179
|
) {
|
|
180
180
|
const i = path.lastIndexOf('/'),
|
|
181
181
|
method = path.slice(i + 1),
|
|
182
|
-
url = composePath(domain, path.slice(0, i), $query)
|
|
182
|
+
url = composePath(domain, i === -1 ? '/' : path.slice(0, i), $query)
|
|
183
|
+
|
|
184
|
+
const fetcher = config.fetcher ?? fetch
|
|
183
185
|
|
|
184
186
|
if (method === 'subscribe')
|
|
185
187
|
return new EdenWS(
|
|
@@ -240,7 +242,7 @@ const createProxy = (
|
|
|
240
242
|
}
|
|
241
243
|
}
|
|
242
244
|
|
|
243
|
-
const response = await
|
|
245
|
+
const response = await fetcher(url, {
|
|
244
246
|
method,
|
|
245
247
|
body,
|
|
246
248
|
...config.$fetch,
|
package/src/treaty/types.ts
CHANGED
|
@@ -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:
|
|
39
|
-
query:
|
|
40
|
-
params:
|
|
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
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { defineConfig } from 'tsup'
|
|
2
|
-
import { resolve } from 'path'
|
|
3
|
-
import {exec} from 'child_process'
|
|
1
|
+
import { defineConfig } from 'tsup'
|
|
2
|
+
import { resolve } from 'path'
|
|
3
|
+
import { exec } from 'child_process'
|
|
4
4
|
|
|
5
5
|
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
|
-
format: ['cjs', 'esm'],
|
|
11
|
+
format: ['cjs', 'esm', 'iife'],
|
|
12
|
+
globalName: 'Eden',
|
|
13
13
|
minify: true,
|
|
14
14
|
external: ['elysia', 'superjson'],
|
|
15
15
|
async onSuccess() {
|
|
16
16
|
exec('tsc --emitDeclarationOnly --declaration', {
|
|
17
|
-
cwd: resolve(__dirname, 'dist')
|
|
17
|
+
cwd: resolve(__dirname, 'dist')
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
|
-
})
|
|
20
|
+
})
|
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
|
-
}
|