@elysiajs/eden 0.6.3 → 0.6.5

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.
Files changed (56) hide show
  1. package/dist/chunk-FY4RFSUV.mjs +1 -0
  2. package/dist/chunk-G4C5WHQF.mjs +1 -0
  3. package/dist/chunk-TUC2YNFX.mjs +1 -0
  4. package/dist/chunk-X77HNZQV.mjs +1 -0
  5. package/dist/chunk-Y6SMVGJX.mjs +1 -0
  6. package/dist/errors.d.ts +5 -0
  7. package/dist/fetch/index.d.ts +4 -0
  8. package/dist/fetch/types.d.ts +47 -0
  9. package/dist/fetch.global.js +1 -0
  10. package/dist/fetch.js +1 -1
  11. package/dist/fetch.mjs +1 -52
  12. package/dist/fn/index.d.ts +4 -0
  13. package/dist/fn/types.d.ts +27 -0
  14. package/dist/fn/utils.d.ts +13 -0
  15. package/dist/fn.global.js +1 -0
  16. package/dist/fn.js +1 -1
  17. package/dist/fn.mjs +1 -93
  18. package/dist/index.d.ts +3 -0
  19. package/dist/index.global.js +1 -0
  20. package/dist/index.js +1 -25
  21. package/dist/index.mjs +1 -9
  22. package/dist/treaty/index.d.ts +17 -0
  23. package/dist/treaty/types.d.ts +75 -0
  24. package/dist/treaty/utils.d.ts +1 -0
  25. package/dist/treaty.global.js +1 -0
  26. package/dist/treaty.js +1 -1
  27. package/dist/treaty.mjs +1 -173
  28. package/dist/types.d.ts +25 -0
  29. package/package.json +9 -8
  30. package/src/fetch/types.ts +5 -5
  31. package/src/index.ts +0 -25
  32. package/src/treaty/index.ts +4 -2
  33. package/tsup.config.ts +21 -0
  34. package/dist/errors-5a40996f.mjs +0 -14
  35. package/dist/errors-a2cfc56a.js +0 -1
  36. package/dist/errors.js +0 -10
  37. package/dist/errors.js.map +0 -1
  38. package/dist/fetch/index.js +0 -67
  39. package/dist/fetch/index.js.map +0 -1
  40. package/dist/fetch/types.js +0 -2
  41. package/dist/fetch/types.js.map +0 -1
  42. package/dist/fn/index.js +0 -35
  43. package/dist/fn/index.js.map +0 -1
  44. package/dist/fn/types.js +0 -2
  45. package/dist/fn/types.js.map +0 -1
  46. package/dist/fn/utils.js +0 -59
  47. package/dist/fn/utils.js.map +0 -1
  48. package/dist/index.js.map +0 -1
  49. package/dist/treaty/index.js +0 -205
  50. package/dist/treaty/index.js.map +0 -1
  51. package/dist/treaty/types.js +0 -2
  52. package/dist/treaty/types.js.map +0 -1
  53. package/dist/treaty/utils.js +0 -13
  54. package/dist/treaty/utils.js.map +0 -1
  55. package/dist/types.js +0 -2
  56. package/dist/types.js.map +0 -1
@@ -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
+ var c=class s{url;config;pendings=[];operation=null;isFetching=!1;sJson;constructor(e,i={}){this.url=e,this.config=i,this.sJson=import("superjson").then(t=>({serialize:t.serialize,deserialize:t.deserialize}))}setConfig(e){this.config=e}clone(e){return new s(this.url,e??this.config)}async run(e,i){let t=+this.pendings.length;if(this.pendings.push(i!==void 0?{n:e,p:i}:{n:e}),this.isFetching)return this.operation?.then(n=>n[t]);this.isFetching=!0,this.operation=new Promise(n=>{setTimeout(async()=>{let r=[...this.pendings];this.pendings=[];let{serialize:o,deserialize:a}=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(o(r))});f.status===200?n(f.json().then(l=>a(l))):n(Array(r.length).fill(new Error(await f.text())))},33)});let h=await this.operation.then(n=>n[t]);return this.operation=null,this.isFetching=!1,h}};var p=(s,e,i)=>new Proxy((...t)=>{},{get(t,h,n){return p(s,[...e,h],i)},apply(t,h,n){let r=n[0],o=e[0];if(e.length===1){if(o in Object.prototype||o in Promise.prototype)return t(...n);switch(o){case"toJSON":return t(...n);case"$set":return i.setConfig(r);case"$clone":return p(s,[],i.clone(r))}}return i.run(e,n).then(a=>{if(a instanceof Error)throw a;return a})}}),d=(s,e)=>p(s,[],new c(s,e));export{d as a};
@@ -0,0 +1 @@
1
+ import{a as p}from"./chunk-Y6SMVGJX.mjs";var E=(u,f)=>(s,{query:i,params:h,body:a,...n}={})=>{h&&Object.entries(h).forEach(([e,t])=>{s=s.replace(`:${e}`,t)});let o=n.headers?.["Content-Type"];if(!o||o==="application/json")try{a=JSON.stringify(a)}catch{}let l=f?.fetcher||globalThis.fetch,y=i?`?${new URLSearchParams(i).toString()}`:"",c=()=>l(u+s+y,{...n,headers:a?{"content-type":"application/json",...n.headers}:n.headers,body:a}).then(async e=>{let t;switch(e.headers.get("Content-Type")?.split(";")[0]){case"application/json":t=await e.json();break;default:t=await e.text().then(r=>Number.isNaN(+r)?r==="true"?!0:r==="false"?!1:r:+r);break}return e.status>300?{data:null,status:e.status,headers:e.headers,retry:c,error:new p(e.status,t)}:{data:t,error:null,status:e.status,headers:e.headers,retry:c}});return c()};export{E as a};
@@ -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 b=typeof FileList>"u",x=n=>b?n instanceof Blob:n instanceof FileList||n instanceof File,W=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=>b?n:new Promise(e=>{let t=new FileReader;t.onload=()=>{e(new Blob([t.result],{type:n.type}))},t.readAsArrayBuffer(n)}),E=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,...v}={$fetch:void 0,$headers:void 0,$query:void 0}]=[{}]){let m=e.lastIndexOf("/"),u=e.slice(m+1),h=k(n,e.slice(0,m),s);return u==="subscribe"?new E(h.replace(/^([^]+):\/\//,h.startsWith("https://")?"wss://":"ws://")):(async()=>{let c,w={...t.$fetch?.headers,...d?.headers,...L};if(u!=="GET"&&u!=="HEAD"){c=Object.keys(v).length?v:void 0;let a=typeof c=="object";if(a&&W(c)){let y=new FormData;for(let[p,f]of Object.entries(c))if(b)y.append(p,f);else if(f instanceof File)y.append(p,await $(f));else if(f instanceof FileList)for(let g=0;g<f.length;g++)y.append(p,await $(f[g]));else y.append(p,f);c=y}else w["content-type"]=a?"application/json":"text/plain",a&&(c=JSON.stringify(c))}let i=await(t.fetcher??fetch)(h,{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}})()}}),R=(n,e={fetcher:fetch})=>new Proxy({},{get(t,r){return T(n,r,e)}});export{E as a,R as b};
@@ -0,0 +1 @@
1
+ var s=class extends Error{status;value;constructor(e,t){super(),this.status=e,this.value=t}};export{s as a};
@@ -0,0 +1,5 @@
1
+ export declare class EdenFetchError<Status extends number = number, Value = unknown> extends Error {
2
+ status: Status;
3
+ value: Value;
4
+ constructor(status: Status, value: Value);
5
+ }
@@ -0,0 +1,4 @@
1
+ import type { Elysia } from 'elysia';
2
+ import type { EdenFetch } from './types';
3
+ export type { EdenFetch } from './types';
4
+ export declare const edenFetch: <App extends Elysia<any, any>>(server: string, config?: EdenFetch.Config) => EdenFetch.Create<App>;
@@ -0,0 +1,47 @@
1
+ /// <reference types="bun-types" />
2
+ import type { Elysia } from 'elysia';
3
+ import type { EdenFetchError } from '../errors';
4
+ import type { MapError, IsUnknown, IsNever } from '../types';
5
+ type Prettify<T> = {
6
+ [K in keyof T]: T[K];
7
+ } & {};
8
+ export declare namespace EdenFetch {
9
+ type Create<App extends Elysia<any, any>> = App['meta'] extends {
10
+ schema: infer Schema extends Record<string, any>;
11
+ } ? EdenFetch.Fn<Schema> : 'Please install Elysia before using Eden';
12
+ interface Config {
13
+ fetcher?: typeof globalThis.fetch;
14
+ }
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;
17
+ } : {
18
+ method: Method;
19
+ }) & (IsNever<keyof Route['params']> extends true ? {
20
+ params?: Record<never, string>;
21
+ } : {
22
+ params: Route['params'];
23
+ }) & (IsNever<keyof Route['query']> extends true ? {
24
+ query?: Record<never, string>;
25
+ } : {
26
+ query: Route['query'];
27
+ }) & (undefined extends Route['headers'] ? {
28
+ headers?: Record<string, string>;
29
+ } : {
30
+ headers: Route['headers'];
31
+ }) & (IsUnknown<Route['body']> extends false ? {
32
+ body: Route['body'];
33
+ } : {
34
+ body?: unknown;
35
+ })) => Promise<Prettify<({
36
+ data: Awaited<Route['response']['200']>;
37
+ error: null;
38
+ } | {
39
+ data: null;
40
+ error: MapError<Route['response']> extends infer Errors ? IsNever<Errors> extends true ? EdenFetchError<number, string> : Errors : EdenFetchError<number, string>;
41
+ }) & {
42
+ status: number;
43
+ response: Response;
44
+ headers: Record<string, string>;
45
+ }>>;
46
+ }
47
+ export {};
@@ -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
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("./errors-a2cfc56a.js"),S=(d,n)=>(c,{query:h,params:l,body:a,...s}={})=>{var o;l&&Object.entries(l).forEach(([e,t])=>{c=c.replace(`:${e}`,t)});const i=(o=s.headers)==null?void 0:o["Content-Type"];if(!i||i==="application/json")try{a=JSON.stringify(a)}catch{}const y=(n==null?void 0:n.fetcher)||globalThis.fetch,p=h?`?${new URLSearchParams(h).toString()}`:"",u=()=>y(d+c+p,{...s,headers:a?{"content-type":"application/json",...s.headers}:s.headers,body:a}).then(async e=>{var f;let t;switch((f=e.headers.get("Content-Type"))==null?void 0:f.split(";")[0]){case"application/json":t=await e.json();break;default:t=await e.text().then(r=>Number.isNaN(+r)?r==="true"?!0:r==="false"?!1:r:+r);break}return e.status>300?{data:null,status:e.status,headers:e.headers,retry:u,error:new j.EdenFetchError(e.status,t)}:{data:t,error:null,status:e.status,headers:e.headers,retry:u}});return u()};exports.edenFetch=S;
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/fetch.mjs CHANGED
@@ -1,52 +1 @@
1
- import { E as j } from "./errors-5a40996f.mjs";
2
- const E = (p, n) => (
3
- // @ts-ignore
4
- (c, { query: u, params: l, body: a, ...s } = {}) => {
5
- var f;
6
- l && Object.entries(l).forEach(([t, e]) => {
7
- c = c.replace(`:${t}`, e);
8
- });
9
- const i = (f = s.headers) == null ? void 0 : f["Content-Type"];
10
- if (!i || i === "application/json")
11
- try {
12
- a = JSON.stringify(a);
13
- } catch {
14
- }
15
- const y = (n == null ? void 0 : n.fetcher) || globalThis.fetch, d = u ? `?${new URLSearchParams(u).toString()}` : "", h = () => y(p + c + d, {
16
- ...s,
17
- headers: a ? {
18
- "content-type": "application/json",
19
- ...s.headers
20
- } : s.headers,
21
- body: a
22
- }).then(async (t) => {
23
- var o;
24
- let e;
25
- switch ((o = t.headers.get("Content-Type")) == null ? void 0 : o.split(";")[0]) {
26
- case "application/json":
27
- e = await t.json();
28
- break;
29
- default:
30
- e = await t.text().then((r) => Number.isNaN(+r) ? r === "true" ? !0 : r === "false" ? !1 : r : +r);
31
- break;
32
- }
33
- return t.status > 300 ? {
34
- data: null,
35
- status: t.status,
36
- headers: t.headers,
37
- retry: h,
38
- error: new j(t.status, e)
39
- } : {
40
- data: e,
41
- error: null,
42
- status: t.status,
43
- headers: t.headers,
44
- retry: h
45
- };
46
- });
47
- return h();
48
- }
49
- );
50
- export {
51
- E as edenFetch
52
- };
1
+ import{a}from"./chunk-TUC2YNFX.mjs";import"./chunk-Y6SMVGJX.mjs";export{a as edenFetch};
@@ -0,0 +1,4 @@
1
+ import type { Elysia } from 'elysia';
2
+ import type { EdenFn } from './types';
3
+ export type { EdenFn } from './types';
4
+ export declare const edenFn: <App extends Elysia<any, any>>(domain: string, config?: EdenFn.Config) => EdenFn.Create<App>;
@@ -0,0 +1,27 @@
1
+ /// <reference types="bun-types" />
2
+ import type { Elysia } from 'elysia';
3
+ export declare namespace EdenFn {
4
+ type Create<App extends Elysia<any, any>> = App['meta'] extends {
5
+ exposed: infer Schema extends Record<string, any>;
6
+ } ? EdenFn.Compose<Schema> : 'Please install Elysia before using Eden';
7
+ interface Config {
8
+ }
9
+ type Compose<Exposed extends Record<string, any>> = Fn<Exposed> & {
10
+ $set(config: Config): void;
11
+ $clone(config?: Config): Compose<Exposed>;
12
+ };
13
+ type Fn<T> = T extends {
14
+ exposed: any;
15
+ value: infer Value;
16
+ } ? Asynctify<Value> : Asynctify<T>;
17
+ interface Config {
18
+ fn?: string;
19
+ fetch?: Omit<RequestInit, 'body'>;
20
+ fetcher?: typeof globalThis.fetch;
21
+ }
22
+ }
23
+ type Promisify<T extends (...args: any[]) => any> = T extends (...args: infer Args) => infer Return ? Return extends Promise<any> ? T : (...args: Args) => Promise<Return> : never;
24
+ type Asynctify<T> = T extends infer Fn extends (...args: any) => any ? Promisify<Fn> : T extends Record<string, any> ? {
25
+ [K in keyof T]: EdenFn.Fn<T[K]>;
26
+ } : never;
27
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { EdenFn } from './types';
2
+ export declare class Signal {
3
+ private url;
4
+ private config;
5
+ private pendings;
6
+ private operation;
7
+ private isFetching;
8
+ private sJson;
9
+ constructor(url: string, config?: EdenFn.Config);
10
+ setConfig(config: EdenFn.Config): void;
11
+ clone(config?: EdenFn.Config): Signal;
12
+ run(procedure: string[], params: any): Promise<any>;
13
+ }
@@ -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
- "use strict";var z=Object.create;var a=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var S=(e,t,n)=>t in e?a(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var J=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of P(t))!O.call(e,s)&&s!==n&&a(e,s,{get:()=>t[s],enumerable:!(i=F(t,s))||i.enumerable});return e};var T=(e,t,n)=>(n=e!=null?z(b(e)):{},J(t||!e||!e.__esModule?a(n,"default",{value:e,enumerable:!0}):n,e));var h=(e,t,n)=>(S(e,typeof t!="symbol"?t+"":t,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class g{constructor(t,n={}){h(this,"url");h(this,"config");h(this,"pendings",[]);h(this,"operation",null);h(this,"isFetching",!1);h(this,"sJson");this.url=t,this.config=n,this.sJson=import("superjson").then(i=>({serialize:i.serialize,deserialize:i.deserialize}))}setConfig(t){this.config=t}clone(t){return new g(this.url,t??this.config)}async run(t,n){var o;const i=+this.pendings.length;if(this.pendings.push(n!==void 0?{n:t,p:n}:{n:t}),this.isFetching)return(o=this.operation)==null?void 0:o.then(r=>r[i]);this.isFetching=!0,this.operation=new Promise(r=>{setTimeout(async()=>{var p,y;const c=[...this.pendings];this.pendings=[];const{serialize:f,deserialize:d}=await this.sJson,l=await(((p=this.config)==null?void 0:p.fetcher)||globalThis.fetch)(`${this.url}${this.config.fn??"/~fn"}`,{method:"POST",...this.config.fetch,headers:{"content-type":"elysia/fn",...(y=this.config.fetch)==null?void 0:y.headers},body:JSON.stringify(f(c))});l.status===200?r(l.json().then(w=>d(w))):r(Array(c.length).fill(new Error(await l.text())))},33)});const s=await this.operation.then(r=>r[i]);return this.operation=null,this.isFetching=!1,s}}const u=(e,t,n)=>new Proxy((...i)=>{},{get(i,s,o){return u(e,[...t,s],n)},apply(i,s,o){const r=o[0],c=t[0];if(t.length===1){if(c in Object.prototype||c in Promise.prototype)return i(...o);switch(c){case"toJSON":return i(...o);case"$set":return n.setConfig(r);case"$clone":return u(e,[],n.clone(r))}}return n.run(t,o).then(f=>{if(f instanceof Error)throw f;return f})}}),$=(e,t)=>u(e,[],new g(e,t));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/fn.mjs CHANGED
@@ -1,93 +1 @@
1
- var d = Object.defineProperty;
2
- var z = (n, t, e) => t in n ? d(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var o = (n, t, e) => (z(n, typeof t != "symbol" ? t + "" : t, e), e);
4
- class u {
5
- constructor(t, e = {}) {
6
- o(this, "url");
7
- o(this, "config");
8
- o(this, "pendings", []);
9
- o(this, "operation", null);
10
- o(this, "isFetching", !1);
11
- o(this, "sJson");
12
- this.url = t, this.config = e, this.sJson = import("superjson").then((i) => ({
13
- serialize: i.serialize,
14
- deserialize: i.deserialize
15
- }));
16
- }
17
- setConfig(t) {
18
- this.config = t;
19
- }
20
- clone(t) {
21
- return new u(this.url, t ?? this.config);
22
- }
23
- async run(t, e) {
24
- var r;
25
- const i = +this.pendings.length;
26
- if (this.pendings.push(
27
- e !== void 0 ? { n: t, p: e } : { n: t }
28
- ), this.isFetching)
29
- return (r = this.operation) == null ? void 0 : r.then((s) => s[i]);
30
- this.isFetching = !0, this.operation = new Promise((s) => {
31
- setTimeout(async () => {
32
- var g, p;
33
- const h = [...this.pendings];
34
- this.pendings = [];
35
- const { serialize: c, deserialize: y } = await this.sJson, l = await (((g = this.config) == null ? void 0 : g.fetcher) || globalThis.fetch)(
36
- `${this.url}${this.config.fn ?? "/~fn"}`,
37
- {
38
- method: "POST",
39
- ...this.config.fetch,
40
- headers: {
41
- "content-type": "elysia/fn",
42
- ...(p = this.config.fetch) == null ? void 0 : p.headers
43
- },
44
- body: JSON.stringify(c(h))
45
- }
46
- );
47
- l.status === 200 ? s(l.json().then((w) => y(w))) : s(
48
- Array(h.length).fill(
49
- new Error(await l.text())
50
- )
51
- );
52
- }, 33);
53
- });
54
- const f = await this.operation.then((s) => s[i]);
55
- return this.operation = null, this.isFetching = !1, f;
56
- }
57
- }
58
- const a = (n, t, e) => (
59
- // eslint-disable-next-line @typescript-eslint/no-empty-function
60
- new Proxy((...i) => {
61
- }, {
62
- get(i, f, r) {
63
- return a(n, [...t, f], e);
64
- },
65
- apply(i, f, r) {
66
- const s = r[0], h = t[0];
67
- if (t.length === 1) {
68
- if (h in Object.prototype || h in Promise.prototype)
69
- return i(...r);
70
- switch (h) {
71
- case "toJSON":
72
- return i(...r);
73
- case "$set":
74
- return e.setConfig(s);
75
- case "$clone":
76
- return a(n, [], e.clone(s));
77
- }
78
- }
79
- return e.run(t, r).then((c) => {
80
- if (c instanceof Error)
81
- throw c;
82
- return c;
83
- });
84
- }
85
- })
86
- ), x = (n, t) => (
87
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
88
- // @ts-ignore
89
- a(n, [], new u(n, t))
90
- );
91
- export {
92
- x as edenFn
93
- };
1
+ import{a}from"./chunk-G4C5WHQF.mjs";export{a as edenFn};
@@ -0,0 +1,3 @@
1
+ export { edenTreaty } from './treaty';
2
+ export { edenFetch } from './fetch';
3
+ export { edenFn } from './fn';
@@ -0,0 +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);})();
package/dist/index.js CHANGED
@@ -1,25 +1 @@
1
- export { edenTreaty } from './treaty';
2
- export { edenFetch } from './fetch';
3
- export { edenFn } from './fn';
4
- // @ts-ignore
5
- // export const eden: Eden = (domain: string) => ({
6
- // treaty(config) {
7
- // return import('./treaty').then((x) => x.edenTreaty(domain, config))
8
- // },
9
- // fn(config) {
10
- // return import('./fn').then((x) => x.edenFn(domain, config))
11
- // },
12
- // fetch(config) {
13
- // return import('./fetch').then((x) => x.edenFetch(domain, config))
14
- // }
15
- // })
16
- // type Eden = (domain: string) => {
17
- // treaty<App extends Elysia<any>>(
18
- // config?: EdenTreaty.Config
19
- // ): EdenTreaty.Create<App>
20
- // fetch<App extends Elysia<any>>(
21
- // config?: EdenFetch.Config
22
- // ): EdenFetch.Create<App>
23
- // fn<App extends Elysia<any>>(config?: EdenFn.Config): EdenFn.Create<App>
24
- // }
25
- //# sourceMappingURL=index.js.map
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});
package/dist/index.mjs CHANGED
@@ -1,9 +1 @@
1
- import { edenTreaty as t } from "./treaty.mjs";
2
- import { edenFetch as n } from "./fetch.mjs";
3
- import { edenFn as d } from "./fn.mjs";
4
- import "./errors-5a40996f.mjs";
5
- export {
6
- n as edenFetch,
7
- d as edenFn,
8
- t as edenTreaty
9
- };
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};
@@ -0,0 +1,17 @@
1
+ /// <reference types="bun-types" />
2
+ import type { Elysia, TypedSchema } from 'elysia';
3
+ import type { EdenTreaty } from './types';
4
+ export type { EdenTreaty } from './types';
5
+ export declare class EdenWS<Schema extends TypedSchema<any> = TypedSchema> {
6
+ ws: WebSocket;
7
+ url: string;
8
+ constructor(url: string);
9
+ send(data: Schema['body'] | Schema['body'][]): this;
10
+ on<K extends keyof WebSocketEventMap>(type: K, listener: (event: EdenTreaty.WSEvent<K, Schema['response']>) => void, options?: boolean | AddEventListenerOptions): this;
11
+ off<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | EventListenerOptions): this;
12
+ subscribe(onMessage: (event: EdenTreaty.WSEvent<'message', Schema['response']>) => void, options?: boolean | AddEventListenerOptions): this;
13
+ addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (event: EdenTreaty.WSEvent<K, Schema['response']>) => void, options?: boolean | AddEventListenerOptions): this;
14
+ removeEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | EventListenerOptions): this;
15
+ close(): this;
16
+ }
17
+ export declare const edenTreaty: <App extends Elysia<any, any>>(domain: string, config?: EdenTreaty.Config) => EdenTreaty.Create<App>;
@@ -0,0 +1,75 @@
1
+ import type { Elysia } from 'elysia';
2
+ import type { EdenWS } from './index';
3
+ import type { IsUnknown, IsNever, UnionToIntersect, MapError } from '../types';
4
+ import type { EdenFetchError } from '../errors';
5
+ type Files = File | FileList;
6
+ type Replace<RecordType, TargetType, GenericType> = {
7
+ [K in keyof RecordType]: RecordType[K] extends TargetType ? GenericType : RecordType[K];
8
+ };
9
+ type Split<S extends string> = S extends `${infer Head}/${infer Tail}` ? Head extends '' ? Tail extends '' ? [] : Split<Tail> : [Head, ...Split<Tail>] : S extends `/` ? [] : S extends `${infer Head}/` ? [Head] : [S];
10
+ type Prettify<T> = {
11
+ [K in keyof T]: T[K];
12
+ } & {};
13
+ type AnySchema = {
14
+ body: unknown;
15
+ headers: Record<string, any> | undefined;
16
+ query: Record<string, any> | undefined;
17
+ params: Record<string, any> | undefined;
18
+ response: any;
19
+ };
20
+ export declare namespace EdenTreaty {
21
+ type Create<App extends Elysia<any, any>> = App['meta'] extends {
22
+ schema: infer Schema extends Record<string, any>;
23
+ } ? UnionToIntersect<Sign<Schema>> : 'Please install Elysia before using Eden';
24
+ interface Config {
25
+ /**
26
+ * Default options to pass to fetch
27
+ */
28
+ $fetch?: RequestInit;
29
+ fetcher?: typeof fetch;
30
+ }
31
+ type Sign<Schema extends Record<string, Record<string, unknown>>, Paths extends (string | number)[] = Split<keyof Schema>, Carry extends string = ''> = Paths extends [
32
+ infer Prefix extends string | number,
33
+ ...infer Rest extends (string | number)[]
34
+ ] ? {
35
+ [Key in Prefix as Prefix extends `:${string}` ? (string & {}) | number | Prefix : Prefix]: Sign<Schema, Rest, `${Carry}/${Key}`>;
36
+ } : Schema[Carry extends '' ? '/' : Carry] extends infer Routes ? {
37
+ [Method in keyof Routes]: Routes[Method] extends infer Route extends AnySchema ? Method extends 'subscribe' ? undefined extends Route['query'] ? (params?: {
38
+ $query?: Record<string, string>;
39
+ }) => EdenWS<Route> : (params: {
40
+ $query: Route['query'];
41
+ }) => EdenWS<Route> : ((params: {
42
+ $fetch?: RequestInit;
43
+ } & (IsUnknown<Route['body']> extends false ? Replace<Route['body'], Blob | Blob[], Files> : {}) & (undefined extends Route['query'] ? {
44
+ $query?: Record<string, string>;
45
+ } : {
46
+ $query: Route['query'];
47
+ }) & (undefined extends Route['headers'] ? {
48
+ $headers?: Record<string, unknown>;
49
+ } : {
50
+ $headers: Route['headers'];
51
+ })) => Promise<({
52
+ data: Route['response'] extends {
53
+ 200: infer ReturnedType;
54
+ } ? Awaited<ReturnedType> : unknown;
55
+ error: null;
56
+ } | {
57
+ data: null;
58
+ error: MapError<Route['response']> extends infer Errors ? IsNever<Errors> extends true ? EdenFetchError<number, string> : Errors : EdenFetchError<number, string>;
59
+ }) & {
60
+ status: number;
61
+ response: Response;
62
+ headers: Record<string, string>;
63
+ }>) extends (params: infer Params) => infer Response ? {
64
+ $params: undefined;
65
+ $headers: undefined;
66
+ $query: undefined;
67
+ } extends Params ? (params?: Prettify<Params>) => Response : (params: Prettify<Params>) => Response : never : never;
68
+ } : {};
69
+ interface OnMessage<Data = unknown> extends MessageEvent {
70
+ data: Data;
71
+ rawData: MessageEvent['data'];
72
+ }
73
+ type WSEvent<K extends keyof WebSocketEventMap, Data = unknown> = K extends 'message' ? OnMessage<Data> : WebSocketEventMap[K];
74
+ }
75
+ export {};
@@ -0,0 +1 @@
1
+ export declare const composePath: (domain: string, path: string, query: Record<string, string> | undefined) => string;
@@ -0,0 +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);})();