@elysiajs/eden 0.6.3 → 0.6.4

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 (48) hide show
  1. package/dist/chunk-G4C5WHQF.mjs +1 -0
  2. package/dist/chunk-TUC2YNFX.mjs +1 -0
  3. package/dist/chunk-X77HNZQV.mjs +1 -0
  4. package/dist/chunk-Y6SMVGJX.mjs +1 -0
  5. package/dist/errors.d.ts +5 -0
  6. package/dist/fetch/index.d.ts +4 -0
  7. package/dist/fetch/types.d.ts +46 -0
  8. package/dist/fetch.js +1 -1
  9. package/dist/fetch.mjs +1 -52
  10. package/dist/fn/index.d.ts +4 -0
  11. package/dist/fn/types.d.ts +26 -0
  12. package/dist/fn/utils.d.ts +13 -0
  13. package/dist/fn.js +1 -1
  14. package/dist/fn.mjs +1 -93
  15. package/dist/index.d.ts +3 -0
  16. package/dist/index.js +1 -25
  17. package/dist/index.mjs +1 -9
  18. package/dist/treaty/index.d.ts +16 -0
  19. package/dist/treaty/types.d.ts +75 -0
  20. package/dist/treaty/utils.d.ts +1 -0
  21. package/dist/treaty.js +1 -1
  22. package/dist/treaty.mjs +1 -173
  23. package/dist/types.d.ts +25 -0
  24. package/package.json +5 -5
  25. package/tsup.config.ts +20 -0
  26. package/dist/errors-5a40996f.mjs +0 -14
  27. package/dist/errors-a2cfc56a.js +0 -1
  28. package/dist/errors.js +0 -10
  29. package/dist/errors.js.map +0 -1
  30. package/dist/fetch/index.js +0 -67
  31. package/dist/fetch/index.js.map +0 -1
  32. package/dist/fetch/types.js +0 -2
  33. package/dist/fetch/types.js.map +0 -1
  34. package/dist/fn/index.js +0 -35
  35. package/dist/fn/index.js.map +0 -1
  36. package/dist/fn/types.js +0 -2
  37. package/dist/fn/types.js.map +0 -1
  38. package/dist/fn/utils.js +0 -59
  39. package/dist/fn/utils.js.map +0 -1
  40. package/dist/index.js.map +0 -1
  41. package/dist/treaty/index.js +0 -205
  42. package/dist/treaty/index.js.map +0 -1
  43. package/dist/treaty/types.js +0 -2
  44. package/dist/treaty/types.js.map +0 -1
  45. package/dist/treaty/utils.js +0 -13
  46. package/dist/treaty/utils.js.map +0 -1
  47. package/dist/types.js +0 -2
  48. package/dist/types.js.map +0 -1
package/dist/treaty.mjs CHANGED
@@ -1,173 +1 @@
1
- var A = Object.defineProperty;
2
- var O = (s, e, t) => e in s ? A(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var b = (s, e, t) => (O(s, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { E as k } from "./errors-5a40996f.mjs";
5
- const j = (s, e, t) => {
6
- if (s.endsWith("/") || (s += "/"), e === "index" && (e = ""), !t || !Object.keys(t).length)
7
- return `${s}${e}`;
8
- let n = "";
9
- for (const [o, r] of Object.entries(t))
10
- n += `${o}=${r}&`;
11
- return `${s}${e}?${n.slice(0, -1)}`;
12
- }, g = typeof FileList > "u", L = (s) => g ? s instanceof Blob : s instanceof FileList || s instanceof File, B = (s) => {
13
- if (!s)
14
- return !1;
15
- for (const e in s) {
16
- if (L(s[e]))
17
- return !0;
18
- if (Array.isArray(s[e]) && s[e].find((t) => L(t)))
19
- return !0;
20
- }
21
- return !1;
22
- }, N = (s) => g ? s : new Promise((e) => {
23
- const t = new FileReader();
24
- t.onload = () => {
25
- e(new Blob([t.result], { type: s.type }));
26
- }, t.readAsArrayBuffer(s);
27
- });
28
- class P {
29
- constructor(e) {
30
- b(this, "ws");
31
- b(this, "url");
32
- this.ws = new WebSocket(e), this.url = e;
33
- }
34
- send(e) {
35
- return Array.isArray(e) ? (e.forEach((t) => this.send(t)), this) : (this.ws.send(
36
- typeof e == "object" ? JSON.stringify(e) : e.toString()
37
- ), this);
38
- }
39
- on(e, t, n) {
40
- return this.addEventListener(e, t, n);
41
- }
42
- off(e, t, n) {
43
- return this.ws.removeEventListener(e, t, n), this;
44
- }
45
- subscribe(e, t) {
46
- return this.addEventListener("message", e, t);
47
- }
48
- addEventListener(e, t, n) {
49
- return this.ws.addEventListener(
50
- e,
51
- (o) => {
52
- if (e === "message") {
53
- let r = o.data.toString();
54
- const c = r.charCodeAt(0);
55
- if (c === 47 || c === 123)
56
- try {
57
- r = JSON.parse(r);
58
- } catch {
59
- }
60
- else
61
- Number.isNaN(+r) ? r === "true" ? r = !0 : r === "fase" && (r = !1) : r = +r;
62
- t({
63
- ...o,
64
- data: r
65
- });
66
- } else
67
- t(o);
68
- },
69
- n
70
- ), this;
71
- }
72
- removeEventListener(e, t, n) {
73
- return this.off(e, t, n), this;
74
- }
75
- close() {
76
- return this.ws.close(), this;
77
- }
78
- }
79
- const S = (s, e = "", t) => new Proxy(() => {
80
- }, {
81
- get(n, o, r) {
82
- return S(s, `${e}/${o.toString()}`, t);
83
- },
84
- apply(n, o, [
85
- { $query: r, $fetch: c, $headers: $, ...E } = {
86
- $fetch: void 0,
87
- $headers: void 0,
88
- $query: void 0
89
- }
90
- ] = [{}]) {
91
- const F = e.lastIndexOf("/"), h = e.slice(F + 1), w = j(s, e.slice(0, F), r);
92
- return h === "subscribe" ? new P(
93
- w.replace(
94
- /^([^]+):\/\//,
95
- w.startsWith("https://") ? "wss://" : "ws://"
96
- )
97
- ) : (async () => {
98
- var m, x;
99
- let f;
100
- const v = {
101
- ...(m = t.$fetch) == null ? void 0 : m.headers,
102
- ...c == null ? void 0 : c.headers,
103
- ...$
104
- };
105
- if (h !== "GET" && h !== "HEAD") {
106
- f = Object.keys(E).length ? E : void 0;
107
- const a = typeof f == "object";
108
- if (a && B(f)) {
109
- const d = new FormData();
110
- for (const [y, l] of Object.entries(f))
111
- if (g)
112
- d.append(y, l);
113
- else if (l instanceof File)
114
- d.append(
115
- y,
116
- await N(l)
117
- );
118
- else if (l instanceof FileList)
119
- for (let p = 0; p < l.length; p++)
120
- d.append(
121
- y,
122
- await N(l[p])
123
- );
124
- else
125
- d.append(y, l);
126
- f = d;
127
- } else
128
- v["content-type"] = a ? "application/json" : "text/plain", a && (f = JSON.stringify(f));
129
- }
130
- const i = await (t.fetcher ?? fetch)(w, {
131
- method: h,
132
- body: f,
133
- ...t.$fetch,
134
- ...c,
135
- headers: v
136
- });
137
- let u;
138
- switch ((x = i.headers.get("Content-Type")) == null ? void 0 : x.split(";")[0]) {
139
- case "application/json":
140
- u = await i.json();
141
- break;
142
- default:
143
- u = await i.text().then((a) => Number.isNaN(+a) ? a === "true" ? !0 : a === "false" ? !1 : a : +a);
144
- }
145
- return i.status > 300 ? {
146
- data: u,
147
- error: new k(i.status, await u),
148
- status: i.status,
149
- raw: i,
150
- headers: i.headers
151
- } : {
152
- data: u,
153
- status: i.status,
154
- response: i,
155
- headers: i.headers,
156
- error: null
157
- };
158
- })();
159
- }
160
- }), C = (s, e = {
161
- fetcher: fetch
162
- }) => new Proxy(
163
- {},
164
- {
165
- get(t, n) {
166
- return S(s, n, e);
167
- }
168
- }
169
- );
170
- export {
171
- P as EdenWS,
172
- C as edenTreaty
173
- };
1
+ import{a,b}from"./chunk-X77HNZQV.mjs";import"./chunk-Y6SMVGJX.mjs";export{a as EdenWS,b as edenTreaty};
@@ -0,0 +1,25 @@
1
+ import type { EdenFetchError } from './errors';
2
+ type Range<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
3
+ type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc['length']]>;
4
+ type ErrorRange = Range<300, 599>;
5
+ export type MapError<T extends Record<number, unknown>> = [
6
+ {
7
+ [K in keyof T]-?: K extends ErrorRange ? K : never;
8
+ }[keyof T]
9
+ ] extends [infer A extends number] ? {
10
+ [K in A]: EdenFetchError<K, T[K]>;
11
+ }[A] : false;
12
+ export type UnionToIntersect<U> = (U extends unknown ? (arg: U) => 0 : never) extends (arg: infer I) => 0 ? I : never;
13
+ export type IsAny<T> = 0 extends 1 & T ? true : false;
14
+ export type IsNever<T> = [T] extends [never] ? true : false;
15
+ export type IsUnknown<T> = IsAny<T> extends true ? false : unknown extends T ? true : false;
16
+ export type AnyTypedRoute = {
17
+ body: unknown;
18
+ headers: Record<string, any> | undefined;
19
+ query: Record<string, any> | undefined;
20
+ params: Record<string, any> | undefined;
21
+ response: Record<string, unknown> & {
22
+ '200': unknown;
23
+ };
24
+ };
25
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elysiajs/eden",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "Fully type-safe Elysia client",
5
5
  "author": {
6
6
  "name": "saltyAom",
@@ -54,7 +54,7 @@
54
54
  "scripts": {
55
55
  "dev": "bun run --hot example/index.ts",
56
56
  "test": "bun wiptest",
57
- "build": "vite build && tsc",
57
+ "build": "tsup",
58
58
  "release": "npm run build && npm run test && npm publish --access public"
59
59
  },
60
60
  "peerDependencies": {
@@ -71,11 +71,11 @@
71
71
  "@sinclair/typebox": "^0.26.8",
72
72
  "@types/node": "^18.15.5",
73
73
  "elysia": "0.6.10",
74
+ "esbuild": "^0.19.2",
74
75
  "eslint": "^8.26.0",
75
76
  "rimraf": "^4.4.1",
76
- "typescript": "^5.0.4",
77
- "vite": "^4.4.9",
78
- "vite-plugin-dts": "^2.3.0"
77
+ "tsup": "^7.2.0",
78
+ "typescript": "^5.0.4"
79
79
  },
80
80
  "dependencies": {
81
81
  "superjson": "^1.12.2"
package/tsup.config.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { defineConfig } from 'tsup';
2
+ import { resolve } from 'path';
3
+ import {exec} from 'child_process'
4
+
5
+ export default defineConfig({
6
+ entry: {
7
+ index: resolve(__dirname, 'src/index.ts'),
8
+ treaty: resolve(__dirname, 'src/treaty/index.ts'),
9
+ fetch: resolve(__dirname, 'src/fetch/index.ts'),
10
+ fn: resolve(__dirname, 'src/fn/index.ts')
11
+ },
12
+ format: ['cjs', 'esm'],
13
+ minify: true,
14
+ external: ['elysia', 'superjson'],
15
+ async onSuccess() {
16
+ exec('tsc --emitDeclarationOnly --declaration', {
17
+ cwd: resolve(__dirname, 'dist'),
18
+ })
19
+ }
20
+ })
@@ -1,14 +0,0 @@
1
- var u = Object.defineProperty;
2
- var o = (r, s, t) => s in r ? u(r, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[s] = t;
3
- var e = (r, s, t) => (o(r, typeof s != "symbol" ? s + "" : s, t), t);
4
- class E extends Error {
5
- constructor(t, a) {
6
- super();
7
- e(this, "status");
8
- e(this, "value");
9
- this.status = t, this.value = a;
10
- }
11
- }
12
- export {
13
- E
14
- };
@@ -1 +0,0 @@
1
- "use strict";var c=Object.defineProperty;var a=(t,r,s)=>r in t?c(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s;var e=(t,r,s)=>(a(t,typeof r!="symbol"?r+"":r,s),s);class o extends Error{constructor(s,u){super();e(this,"status");e(this,"value");this.status=s,this.value=u}}exports.EdenFetchError=o;
package/dist/errors.js DELETED
@@ -1,10 +0,0 @@
1
- export class EdenFetchError extends Error {
2
- status;
3
- value;
4
- constructor(status, value) {
5
- super();
6
- this.status = status;
7
- this.value = value;
8
- }
9
- }
10
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,cAGX,SAAQ,KAAK;IACX,MAAM,CAAQ;IACd,KAAK,CAAO;IAEZ,YAAY,MAAc,EAAE,KAAY;QACpC,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACtB,CAAC;CACJ"}
@@ -1,67 +0,0 @@
1
- import { EdenFetchError } from '../errors';
2
- export const edenFetch = (server, config) =>
3
- // @ts-ignore
4
- (endpoint, { query, params, body, ...options } = {}) => {
5
- if (params)
6
- Object.entries(params).forEach(([key, value]) => {
7
- endpoint = endpoint.replace(`:${key}`, value);
8
- });
9
- const contentType = options.headers?.['Content-Type'];
10
- if (!contentType || contentType === 'application/json')
11
- try {
12
- body = JSON.stringify(body);
13
- }
14
- catch (error) {
15
- //
16
- }
17
- const fetch = config?.fetcher || globalThis.fetch;
18
- const queryStr = query
19
- ? `?${new URLSearchParams(query).toString()}`
20
- : '';
21
- // @ts-ignore
22
- const execute = () => fetch(server + endpoint + queryStr, {
23
- ...options,
24
- headers: body
25
- ? {
26
- 'content-type': 'application/json',
27
- ...options.headers
28
- }
29
- : options.headers,
30
- body: body
31
- }).then(async (res) => {
32
- let data;
33
- switch (res.headers.get('Content-Type')?.split(';')[0]) {
34
- case 'application/json':
35
- data = await res.json();
36
- break;
37
- default:
38
- data = await res.text().then((d) => {
39
- if (!Number.isNaN(+d))
40
- return +d;
41
- if (d === 'true')
42
- return true;
43
- if (d === 'false')
44
- return false;
45
- return d;
46
- });
47
- break;
48
- }
49
- if (res.status > 300)
50
- return {
51
- data: null,
52
- status: res.status,
53
- headers: res.headers,
54
- retry: execute,
55
- error: new EdenFetchError(res.status, data)
56
- };
57
- return {
58
- data,
59
- error: null,
60
- status: res.status,
61
- headers: res.headers,
62
- retry: execute
63
- };
64
- });
65
- return execute();
66
- };
67
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fetch/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAI1C,MAAM,CAAC,MAAM,SAAS,GAClB,CACI,MAAc,EACd,MAAyB,EACJ,EAAE;AAC3B,aAAa;AACb,CAAC,QAAgB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE;IAC3D,IAAI,MAAM;QACN,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC5C,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,I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CAAC,CAAC,CAAC;wBAAE,OAAO,CAAC,CAAC,CAAA;oBAChC,IAAI,CAAC,KAAK,MAAM;wBAAE,OAAO,IAAI,CAAA;oBAC7B,IAAI,CAAC,KAAK,OAAO;wBAAE,OAAO,KAAK,CAAA;oBAE/B,OAAO,CAAC,CAAA;gBACZ,CAAC,CAAC,CAAA;gBACF,MAAK;SACZ;QAED,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG;YAChB,OAAO;gBACH,IAAI,EAAE,IAAI;gBACV,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,OAAO,EAAE,GAAG,CAAC,OAAO;gBACpB,KAAK,EAAE,OAAO;gBACd,KAAK,EAAE,IAAI,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC;aAC9C,CAAA;QAEL,OAAO;YACH,IAAI;YACJ,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,KAAK,EAAE,OAAO;SACjB,CAAA;IACL,CAAC,CAAC,CAAA;IAEF,OAAO,OAAO,EAAE,CAAA;AACpB,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/fetch/types.ts"],"names":[],"mappings":""}
package/dist/fn/index.js DELETED
@@ -1,35 +0,0 @@
1
- import { Signal } from './utils';
2
- const createProxy = (domain, procedures, signal) =>
3
- // eslint-disable-next-line @typescript-eslint/no-empty-function
4
- new Proxy((..._) => { }, {
5
- get(target, key, value) {
6
- return createProxy(domain, [...procedures, key], signal);
7
- },
8
- apply(target, _, params) {
9
- const param = params[0];
10
- const procedure = procedures[0];
11
- if (procedures.length === 1) {
12
- if (procedure in Object.prototype ||
13
- procedure in Promise.prototype)
14
- return target(...params);
15
- switch (procedure) {
16
- case 'toJSON':
17
- return target(...params);
18
- case '$set':
19
- return signal.setConfig(param);
20
- case '$clone':
21
- return createProxy(domain, [], signal.clone(param));
22
- }
23
- }
24
- return signal.run(procedures, params).then((result) => {
25
- if (result instanceof Error)
26
- throw result;
27
- return result;
28
- });
29
- }
30
- });
31
- export const edenFn = (domain, config) =>
32
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
33
- // @ts-ignore
34
- createProxy(domain, [], new Signal(domain, config));
35
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fn/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAKhC,MAAM,WAAW,GAAG,CAChB,MAAc,EACd,UAAoB,EACpB,MAAc,EACS,EAAE;AACzB,gEAAgE;AAChE,IAAI,KAAK,CAAC,CAAC,GAAG,CAAQ,EAAE,EAAE,GAAE,CAAC,EAAE;IAC3B,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK;QAClB,OAAO,WAAW,CAAC,MAAM,EAAE,CAAC,GAAG,UAAU,EAAE,GAAa,CAAC,EAAE,MAAM,CAAC,CAAA;IACtE,CAAC;IACD,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM;QACnB,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;QACvB,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;QAE/B,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;YACzB,IACI,SAAS,IAAI,MAAM,CAAC,SAAS;gBAC7B,SAAS,IAAI,OAAO,CAAC,SAAS;gBAE9B,OAAO,MAAM,CAAC,GAAG,MAAM,CAAC,CAAA;YAE5B,QAAQ,SAAS,EAAE;gBACf,KAAK,QAAQ;oBACT,OAAO,MAAM,CAAC,GAAG,MAAM,CAAC,CAAA;gBAE5B,KAAK,MAAM;oBACP,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;gBAElC,KAAK,QAAQ;oBACT,OAAO,WAAW,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;aAC1D;SACJ;QAED,OAAO,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YAClD,IAAI,MAAM,YAAY,KAAK;gBAAE,MAAM,MAAM,CAAA;YAEzC,OAAO,MAAM,CAAA;QACjB,CAAC,CAAC,CAAA;IACN,CAAC;CACJ,CAAQ,CAAA;AAEb,MAAM,CAAC,MAAM,MAAM,GAAG,CAClB,MAAc,EACd,MAAsB,EACJ,EAAE;AACpB,6DAA6D;AAC7D,aAAa;AACb,WAAW,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA"}
package/dist/fn/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/fn/types.ts"],"names":[],"mappings":""}
package/dist/fn/utils.js DELETED
@@ -1,59 +0,0 @@
1
- export class Signal {
2
- url;
3
- config;
4
- pendings = [];
5
- operation = null;
6
- isFetching = false;
7
- sJson;
8
- constructor(url, config = {}) {
9
- this.url = url;
10
- this.config = config;
11
- this.sJson = import('superjson').then((superJson) => {
12
- return {
13
- serialize: superJson.serialize,
14
- deserialize: superJson.deserialize
15
- };
16
- });
17
- }
18
- setConfig(config) {
19
- this.config = config;
20
- }
21
- clone(config) {
22
- return new Signal(this.url, config ?? this.config);
23
- }
24
- async run(procedure, params) {
25
- const current = +this.pendings.length;
26
- this.pendings.push(params !== undefined
27
- ? { n: procedure, p: params }
28
- : { n: procedure });
29
- if (this.isFetching)
30
- return this.operation?.then((x) => x[current]);
31
- this.isFetching = true;
32
- this.operation = new Promise((resolve) => {
33
- setTimeout(async () => {
34
- const requests = [...this.pendings];
35
- this.pendings = [];
36
- const { serialize, deserialize } = await this.sJson;
37
- const fetch = this.config?.fetcher || globalThis.fetch;
38
- const results = await fetch(`${this.url}${this.config.fn ?? '/~fn'}`, {
39
- method: 'POST',
40
- ...this.config.fetch,
41
- headers: {
42
- 'content-type': 'elysia/fn',
43
- ...this.config.fetch?.headers
44
- },
45
- body: JSON.stringify(serialize(requests))
46
- });
47
- if (results.status === 200)
48
- resolve(results.json().then((x) => deserialize(x)));
49
- else
50
- resolve(Array(requests.length).fill(new Error(await results.text())));
51
- }, 33);
52
- });
53
- const result = await this.operation.then((results) => results[current]);
54
- this.operation = null;
55
- this.isFetching = false;
56
- return result;
57
- }
58
- }
59
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/fn/utils.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,MAAM;IACP,GAAG,CAAQ;IACX,MAAM,CAAe;IAErB,QAAQ,GAAqD,EAAE,CAAA;IAC/D,SAAS,GAA0B,IAAI,CAAA;IACvC,UAAU,GAAG,KAAK,CAAA;IAElB,KAAK,CAGX;IAEF,YAAY,GAAW,EAAE,SAAwB,EAAE;QAC/C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QAEpB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE;YAChD,OAAO;gBACH,SAAS,EAAE,SAAS,CAAC,SAAS;gBAC9B,WAAW,EAAE,SAAS,CAAC,WAAW;aACrC,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC;IAED,SAAS,CAAC,MAAqB;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,MAAsB;QACxB,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,IAA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