@defjs/core 0.0.0-test-003 → 0.0.0-test-005

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.min.js ADDED
@@ -0,0 +1,587 @@
1
+ const G = new Error("ERR_ABORTED"), W = new Error("ERR_TIMEOUT"), me = new Error("ERR_NETWORK"), X = new Error("ERR_NOT_FOUND_HANDLER"), z = new Error("ERR_OBSERVE"), P = new Error("ERR_NOT_SET_ALIAS"), Y = new Error("ERR_UNSUPPORTED_FIELD_TYPE"), Z = new Error("ERR_INVALID_CLIENT"), q = new Error("ERR_NOT_FOUND_GLOBAL_CLIENT"), B = new Error("ERR_INVALID_HTTP_CONTEXT_TOKEN"), Ee = new Error("ERR_UNKNOWN");
2
+ class T extends Error {
3
+ status;
4
+ statusText;
5
+ url;
6
+ headers;
7
+ body;
8
+ constructor(t) {
9
+ const r = t?.status ?? 0, n = t?.statusText ?? "", c = r >= 200 && r < 300, i = t?.headers ?? new Headers(), h = t?.url ?? "", b = t?.body ?? null;
10
+ let o;
11
+ c ? o = `Http failure during parsing for ${h}` : (o = `Http failure response for ${h || "(unknown url)"}: ${r}`, n && (o += ` - ${n}`)), super(o, { cause: t?.error }), super.name = "HttpErrorResponse", this.statusText = n, this.url = h, this.headers = i, this.status = r, this.body = b;
12
+ }
13
+ }
14
+ function ee(e) {
15
+ const t = e.get("Content-Length");
16
+ if (!t)
17
+ return 0;
18
+ const r = Number(t);
19
+ return isNaN(r) ? 0 : r;
20
+ }
21
+ function te(e) {
22
+ return e.get("Content-Type") || "";
23
+ }
24
+ function re(e) {
25
+ const { request: t, content: r, contentType: n } = e;
26
+ switch (t.responseType) {
27
+ case "json": {
28
+ const i = new TextDecoder().decode(r);
29
+ return i === "" ? null : JSON.parse(i);
30
+ }
31
+ case "text":
32
+ return new TextDecoder().decode(r);
33
+ case "blob":
34
+ return new Blob([r], { type: n });
35
+ case "arraybuffer":
36
+ return r.buffer;
37
+ default:
38
+ return null;
39
+ }
40
+ }
41
+ function ne(e, t) {
42
+ const r = new Uint8Array(t);
43
+ let n = 0;
44
+ for (const c of e)
45
+ r.set(c, n), n += c.length;
46
+ return r;
47
+ }
48
+ const $ = Symbol("HttpContextToken");
49
+ function _e(e) {
50
+ return Object.defineProperty(e, $, { value: e }), e;
51
+ }
52
+ function H(e) {
53
+ return typeof e == "function" && $ in e;
54
+ }
55
+ const U = Symbol("HttpContext");
56
+ function oe(e) {
57
+ return typeof e == "object" && e !== null && U in e;
58
+ }
59
+ function se(e) {
60
+ const t = /* @__PURE__ */ new Map();
61
+ switch (!0) {
62
+ case Array.isArray(e): {
63
+ for (const [r, n] of e)
64
+ H(r) && t.set(r, n);
65
+ break;
66
+ }
67
+ case oe(e): {
68
+ for (const [r, n] of e[U])
69
+ t.set(r, n);
70
+ break;
71
+ }
72
+ }
73
+ return {
74
+ set(r, n) {
75
+ if (!H(r))
76
+ throw B;
77
+ return t.set(r, n), this;
78
+ },
79
+ get(r) {
80
+ if (!H(r))
81
+ throw B;
82
+ return t.has(r) || t.set(r, r()), t.get(r);
83
+ },
84
+ del(r) {
85
+ return t.delete(r), this;
86
+ },
87
+ has(r) {
88
+ return t.has(r);
89
+ },
90
+ keys() {
91
+ return t.keys();
92
+ },
93
+ get length() {
94
+ return Array.from(t.keys()).length;
95
+ },
96
+ [U]: t
97
+ };
98
+ }
99
+ const x = Symbol("field");
100
+ var u = /* @__PURE__ */ ((e) => (e[e.Json = 0] = "Json", e[e.Query = 1] = "Query", e[e.Param = 2] = "Param", e[e.Header = 3] = "Header", e[e.Form = 4] = "Form", e[e.Body = 5] = "Body", e[e.UrlForm = 6] = "UrlForm", e))(u || {});
101
+ function Re(e) {
102
+ const t = {
103
+ // todo
104
+ required: typeof e < "u",
105
+ alias: /* @__PURE__ */ new Map(),
106
+ validators: [],
107
+ asyncValidator: []
108
+ }, r = () => e;
109
+ return Object.defineProperty(r, x, {
110
+ value: t
111
+ }), r.withJson = (n) => (t.alias.set(0, n), r), r.withForm = (n) => (t.alias.set(4, n), r), r.withQuery = (n) => (t.alias.set(1, n), r), r.withParam = (n) => (t.alias.set(2, n), r), r.withHeader = (n) => (t.alias.set(3, n), r), r.withUrlForm = (n) => (t.alias.set(6, n), r), r.withBody = () => (t.alias.set(5, void 0), r), r.withValidators = (...n) => (t.validators = n, r), r.withAsyncValidators = (...n) => (t.asyncValidator = n, r), r;
112
+ }
113
+ function j(e) {
114
+ return e[x];
115
+ }
116
+ async function V(e, t) {
117
+ await Promise.all(e.map((r) => r(t)));
118
+ }
119
+ function I(e) {
120
+ return !!e && typeof e == "function" && x in e;
121
+ }
122
+ function J(e) {
123
+ return !!e && typeof e == "object" && Object.entries(e).every(([, t]) => I(t));
124
+ }
125
+ let ae;
126
+ const ce = () => ae;
127
+ function ie(e) {
128
+ return e.reduceRight(
129
+ (t, r) => (n, c) => r(n, (i) => t(i, c)),
130
+ (t, r) => r(t)
131
+ );
132
+ }
133
+ function K(e) {
134
+ const t = e?.status ?? 0, r = e?.statusText ?? "", n = e?.url ?? "", c = e?.headers ?? new Headers(), i = e?.body ?? null;
135
+ return {
136
+ status: t,
137
+ statusText: r,
138
+ url: n,
139
+ headers: c,
140
+ body: i
141
+ };
142
+ }
143
+ function ue(e) {
144
+ switch (!0) {
145
+ case e instanceof FormData:
146
+ case e instanceof Blob:
147
+ case e instanceof ArrayBuffer:
148
+ case e instanceof URLSearchParams:
149
+ case typeof e == "string":
150
+ return e;
151
+ case typeof e == "object":
152
+ case typeof e == "boolean":
153
+ case typeof e == "number":
154
+ case Array.isArray(e):
155
+ return JSON.stringify(e);
156
+ default:
157
+ return null;
158
+ }
159
+ }
160
+ function le(e) {
161
+ switch (!0) {
162
+ case e instanceof FormData:
163
+ return "multipart/form-data";
164
+ case e instanceof ArrayBuffer:
165
+ return "application/octet-stream";
166
+ case e instanceof Blob:
167
+ return e.type || "application/octet-stream";
168
+ case e instanceof URLSearchParams:
169
+ return "application/x-www-form-urlencoded;charset=UTF-8";
170
+ case typeof e == "string":
171
+ return "text/plain";
172
+ case (typeof e == "object" && e !== null):
173
+ case typeof e == "number":
174
+ case typeof e == "boolean":
175
+ return "application/json";
176
+ default:
177
+ return null;
178
+ }
179
+ }
180
+ function fe(e) {
181
+ if (I(e))
182
+ return e();
183
+ if (J(e)) {
184
+ const t = {};
185
+ for (const [r, n] of Object.entries(e))
186
+ t[r] = n();
187
+ return t;
188
+ }
189
+ }
190
+ function ge(e, t) {
191
+ let r = !1, n, c = [], i = "json", h, b = "body", o = !1, l = [], f;
192
+ const a = () => {
193
+ let s, p, E;
194
+ return {
195
+ doRequest: async (...m) => {
196
+ let g, w;
197
+ switch (m.length) {
198
+ case 1: {
199
+ r ? g = m[0] : w = m[0];
200
+ break;
201
+ }
202
+ case 2: {
203
+ g = m[0], w = m[1];
204
+ break;
205
+ }
206
+ }
207
+ if (r && !g)
208
+ throw new Error("Because the request has input, the first argument must be the input value");
209
+ if (l.length > 0)
210
+ for (const k of l)
211
+ k(g);
212
+ const y = w?.timeout || 0;
213
+ w?.abort ? E = w.abort : y > 0 && (E = AbortSignal.timeout(y));
214
+ const v = M(w?.client) ? w.client : ye(), S = Q(v), L = {
215
+ host: S?.host,
216
+ method: e,
217
+ endpoint: t,
218
+ queryParams: new URLSearchParams(),
219
+ headers: new Headers(),
220
+ body: void 0,
221
+ withCredentials: o,
222
+ responseType: i,
223
+ context: h || se(),
224
+ observe: b,
225
+ uploadProgress: s,
226
+ downloadProgress: p,
227
+ timeout: y,
228
+ abort: E
229
+ }, D = w?.handler || S?.handler || ce();
230
+ if (!D)
231
+ throw X;
232
+ r && n && await de(L, n, g);
233
+ let C = await ie([...c])(L, D);
234
+ if (typeof f == "function")
235
+ try {
236
+ C = K({
237
+ ...C,
238
+ body: f(C)
239
+ });
240
+ } catch (k) {
241
+ throw new T({ error: k });
242
+ }
243
+ switch (L.observe) {
244
+ case "body":
245
+ return C.body;
246
+ case "response":
247
+ return C;
248
+ default:
249
+ throw z;
250
+ }
251
+ },
252
+ getInitValue: () => fe(n),
253
+ setUploadProgress: (m) => {
254
+ s = m;
255
+ },
256
+ setDownloadProgress: (m) => {
257
+ p = m;
258
+ }
259
+ };
260
+ };
261
+ return a.withField = (s) => (n = s, r = !0, a), a.withInterceptors = (s) => (c = s, a), a.withContext = (s) => (h = s, a), a.withCredentials = (s) => (o = s, a), a.withValidators = (s) => (l = s, a), a.withTransformResponse = (s) => (f = s, a), a.withObserve = (s) => (b = s, a), a.withResponseType = (s) => (i = s, a), a;
262
+ }
263
+ function F(e, t) {
264
+ return e.replace(/:([^\/]+)/g, (r, n) => t.get(n) ?? "undefined");
265
+ }
266
+ async function de(e, t, r) {
267
+ function n(o) {
268
+ return typeof o == "object" && o !== null;
269
+ }
270
+ function c(o) {
271
+ switch (!0) {
272
+ case Array.isArray(o):
273
+ case (typeof o == "object" && o !== null):
274
+ return JSON.stringify(o);
275
+ case (typeof o == "object" && o === null):
276
+ case typeof o == "boolean":
277
+ case typeof o == "number":
278
+ case typeof o == "string":
279
+ return String(o);
280
+ default:
281
+ throw new Error("Unsupported value type");
282
+ }
283
+ }
284
+ function i(o, l, f) {
285
+ if (Array.isArray(f))
286
+ for (const a of f)
287
+ o.append(l, c(a));
288
+ else
289
+ o.set(l, c(f));
290
+ return o;
291
+ }
292
+ function h(o, l, f) {
293
+ if (Array.isArray(f))
294
+ for (const a of f)
295
+ h(o, l, c(a));
296
+ return o.set(l, c(f)), o;
297
+ }
298
+ function b(o, l) {
299
+ switch (!0) {
300
+ case typeof o > "u":
301
+ return l;
302
+ case (typeof o == "object" && o === null):
303
+ return o;
304
+ default:
305
+ return o;
306
+ }
307
+ }
308
+ if (I(t)) {
309
+ let o, l, f, a;
310
+ const s = b(r, t()), p = j(t);
311
+ await V([...p.validators, ...p.asyncValidator], s);
312
+ for (const [E, d] of p.alias)
313
+ switch (E) {
314
+ case u.Query: {
315
+ if (!d)
316
+ throw P;
317
+ l = i(new URLSearchParams(), d, s);
318
+ break;
319
+ }
320
+ case u.Param: {
321
+ if (!d)
322
+ throw P;
323
+ o = h(/* @__PURE__ */ new Map(), d, s);
324
+ break;
325
+ }
326
+ case u.Header: {
327
+ if (!d)
328
+ throw P;
329
+ f = i(new Headers(), d, s);
330
+ break;
331
+ }
332
+ case u.Form: {
333
+ if (!d)
334
+ throw P;
335
+ a = i(new FormData(), d, s);
336
+ break;
337
+ }
338
+ case u.UrlForm: {
339
+ if (!d)
340
+ throw P;
341
+ a = i(new URLSearchParams(), d, s);
342
+ break;
343
+ }
344
+ case u.Json:
345
+ case u.Body:
346
+ a = s;
347
+ break;
348
+ }
349
+ o && (e.endpoint = F(e.endpoint, o)), e.queryParams = l, e.headers = f, e.body = a;
350
+ return;
351
+ }
352
+ if (J(t) && n(r)) {
353
+ let o = /* @__PURE__ */ new Map(), l = new URLSearchParams(), f = new Headers(), a = new URLSearchParams(), s = new FormData();
354
+ const p = {};
355
+ let E, d;
356
+ for (const [N, _] of Object.entries(t)) {
357
+ const R = j(_);
358
+ for (const [m, g] of R.alias) {
359
+ const w = g || N, y = b(r[N], _());
360
+ switch (await V([...R.validators, ...R.asyncValidator], y), m) {
361
+ case u.Json: {
362
+ Object.defineProperty(p, w, {
363
+ value: y,
364
+ writable: !0,
365
+ enumerable: !0
366
+ }), d = u.Json;
367
+ break;
368
+ }
369
+ case u.Query:
370
+ l = i(l, w, y);
371
+ break;
372
+ case u.Param:
373
+ o = h(o, w, y);
374
+ break;
375
+ case u.Header:
376
+ f = i(f, w, y);
377
+ break;
378
+ case u.Form: {
379
+ s = i(s, w, y), d = u.Form;
380
+ break;
381
+ }
382
+ case u.UrlForm: {
383
+ a = i(a, w, y), d = u.UrlForm;
384
+ break;
385
+ }
386
+ case u.Body: {
387
+ E = y, d = u.Body;
388
+ break;
389
+ }
390
+ }
391
+ }
392
+ }
393
+ switch (e.endpoint = F(e.endpoint, o), e.queryParams = l, e.headers = f, d) {
394
+ case u.Body:
395
+ e.body = E;
396
+ break;
397
+ case u.Form:
398
+ e.body = s;
399
+ break;
400
+ case u.UrlForm:
401
+ e.body = a;
402
+ break;
403
+ case u.Json:
404
+ e.body = p;
405
+ break;
406
+ }
407
+ return;
408
+ }
409
+ throw Y;
410
+ }
411
+ function he(e) {
412
+ const t = new URL(e.endpoint, e.host);
413
+ e.queryParams && (t.search = e.queryParams.toString());
414
+ const r = e.headers ?? new Headers();
415
+ if (!r.has("Content-Type")) {
416
+ const c = le(e.body);
417
+ c && r.set("Content-Type", c);
418
+ }
419
+ r.has("Accept") || r.set("Accept", "application/json, text/plain, */*");
420
+ const n = e.withCredentials ? "include" : void 0;
421
+ return new Request(t, {
422
+ headers: r,
423
+ method: e.method,
424
+ body: ue(e.body),
425
+ signal: e.abort,
426
+ credentials: n
427
+ });
428
+ }
429
+ async function we(e) {
430
+ const t = e.downloadProgress, r = he(e), n = e.abort;
431
+ let c;
432
+ try {
433
+ c = await globalThis.fetch(r);
434
+ } catch (p) {
435
+ if (n?.aborted && n.reason instanceof Error)
436
+ switch (!0) {
437
+ case n.reason.name === "AbortError":
438
+ throw new T({ error: G });
439
+ case n.reason.name === "TimeoutError":
440
+ throw new T({ error: W });
441
+ }
442
+ throw new T({ error: p });
443
+ }
444
+ const { ok: i, headers: h, status: b, statusText: o, url: l } = c, f = ee(h), a = te(h);
445
+ let s = null;
446
+ if (c.body) {
447
+ const p = [], E = c.body.getReader();
448
+ let d = 0;
449
+ for (; ; ) {
450
+ const { done: _, value: R } = await E.read();
451
+ if (_)
452
+ break;
453
+ p.push(R), d += R.length, t?.({
454
+ lengthComputable: f > 0,
455
+ loaded: d,
456
+ total: f
457
+ });
458
+ }
459
+ const N = ne(p, d);
460
+ try {
461
+ s = re({
462
+ request: e,
463
+ content: N,
464
+ contentType: a
465
+ });
466
+ } catch (_) {
467
+ throw new T({
468
+ error: _,
469
+ status: b,
470
+ statusText: o,
471
+ headers: h,
472
+ url: l
473
+ });
474
+ }
475
+ }
476
+ if (!i)
477
+ throw new T({
478
+ status: b,
479
+ statusText: o,
480
+ headers: h,
481
+ url: l,
482
+ body: s
483
+ });
484
+ return K({
485
+ url: l,
486
+ status: b,
487
+ statusText: o,
488
+ headers: h,
489
+ body: s
490
+ });
491
+ }
492
+ const A = Symbol("Client");
493
+ let O;
494
+ function M(e) {
495
+ return typeof e == "object" && e !== null && A in e;
496
+ }
497
+ function Q(e) {
498
+ if (!M(e))
499
+ throw Z;
500
+ return e[A];
501
+ }
502
+ function pe(e) {
503
+ const t = {
504
+ host: e.host,
505
+ strict: e.strict ?? !0,
506
+ interceptors: e.interceptors ?? [],
507
+ handler: e.handler || we
508
+ };
509
+ return {
510
+ [A]: t
511
+ };
512
+ }
513
+ function Te(e, t) {
514
+ const n = {
515
+ ...Q(e),
516
+ ...t
517
+ };
518
+ return {
519
+ [A]: n
520
+ };
521
+ }
522
+ function ye() {
523
+ if (!O)
524
+ throw q;
525
+ return O;
526
+ }
527
+ function Ne(e) {
528
+ O = e;
529
+ }
530
+ function Ce() {
531
+ O = void 0;
532
+ }
533
+ function Pe(e) {
534
+ O = pe(e);
535
+ }
536
+ function Oe(e, t) {
537
+ let r = t?.encode;
538
+ if (!r) {
539
+ const n = globalThis.btoa;
540
+ if (typeof n != "function")
541
+ throw new Error("BasicAuthInterceptor is not supported in this environment");
542
+ r = (c) => n(`${c.username}:${c.password}`);
543
+ }
544
+ return (n, c) => {
545
+ const i = n.headers || new Headers();
546
+ return i.set("Authorization", `Basic ${r(e())}`), n.headers = i, c(n);
547
+ };
548
+ }
549
+ const Ae = (e) => e ? null : new Error("required"), Le = (e) => typeof e != "boolean" || !e ? new Error("requiredTrue") : null, ke = (e) => (t) => typeof t != "string" ? new Error("invalid string") : t.length < e ? new Error(`minLength ${e}`) : null, He = (e) => (t) => typeof t != "string" ? new Error("invalid string") : t.length > e ? new Error(`maxLength ${e}`) : null, Ue = (e) => (t) => typeof t != "number" || isNaN(t) ? new Error("invalid number") : t < e ? new Error(`minLength ${e}`) : null, xe = (e) => (t) => typeof t != "number" || isNaN(t) ? new Error("invalid number") : t > e ? new Error(`maxLength ${e}`) : null, Ie = (e) => (t) => typeof t != "string" ? new Error("invalid string") : e.test(t) ? null : new Error("pattern");
550
+ export {
551
+ G as ERR_ABORTED,
552
+ Z as ERR_INVALID_CLIENT,
553
+ B as ERR_INVALID_HTTP_CONTEXT_TOKEN,
554
+ me as ERR_NETWORK,
555
+ q as ERR_NOT_FOUND_GLOBAL_CLIENT,
556
+ X as ERR_NOT_FOUND_HANDLER,
557
+ P as ERR_NOT_SET_ALIAS,
558
+ z as ERR_OBSERVE,
559
+ W as ERR_TIMEOUT,
560
+ Ee as ERR_UNKNOWN,
561
+ Y as ERR_UNSUPPORTED_FIELD_TYPE,
562
+ T as HttpErrorResponse,
563
+ Oe as basicAuthInterceptor,
564
+ Te as cloneClient,
565
+ pe as createClient,
566
+ Pe as createGlobalClient,
567
+ ge as defineRequest,
568
+ V as doValid,
569
+ we as fetchHandler,
570
+ Re as field,
571
+ ye as getGlobalClient,
572
+ M as isClient,
573
+ I as isField,
574
+ J as isFieldGroup,
575
+ H as isHttpContextToken,
576
+ se as makeHttpContext,
577
+ _e as makeHttpContextToken,
578
+ xe as max,
579
+ He as maxLength,
580
+ Ue as min,
581
+ ke as minLength,
582
+ Ie as pattern,
583
+ Ae as required,
584
+ Le as requiredTrue,
585
+ Ce as restGlobalClient,
586
+ Ne as setGlobalClient
587
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defjs/core",
3
- "version": "0.0.0-test-003",
3
+ "version": "0.0.0-test-005",
4
4
  "type": "module",
5
5
  "module": "index.js",
6
6
  "typings": "index.d.ts",
@@ -12,9 +12,6 @@
12
12
  "bugs": {
13
13
  "url": "https://github.com/defjs/defjs/issues"
14
14
  },
15
- "peerDependencies": {
16
- "typescript": "^5.0.0"
17
- },
18
15
  "exports": {
19
16
  "./package.json": "./package.json",
20
17
  ".": {
package/index.es.min.js DELETED
@@ -1 +0,0 @@
1
- var W=new Error("ERR_ABORTED"),X=new Error("ERR_TIMEOUT"),Ht=new Error("ERR_NETWORK"),J=new Error("ERR_NOT_FOUND_HANDLER"),Q=new Error("ERR_OBSERVE"),F=new Error("ERR_NOT_SET_ALIAS"),j=new Error("ERR_UNSUPPORTED_FIELD_TYPE"),Y=new Error("ERR_INVALID_CLIENT"),Z=new Error("ERR_NOT_FOUND_GLOBAL_CLIENT"),D=new Error("ERR_INVALID_HTTP_CONTEXT_TOKEN"),it=new Error("ERR_UNKNOWN");class _ extends Error{status;statusText;url;headers;ok;body;constructor(t){const n=t.status??0,r=t.statusText??"",o=n>=200&&n<300,s=t.headers??new Headers,c=t.url??null,w=t.body??null;let p;if(o)p=`Http failure during parsing for ${t.url||"(unknown url)"}`;else p=`Http failure response for ${t.url||"(unknown url)"}: ${t.status} ${t.statusText}`;super(p,{cause:t.error});super.name="HttpErrorResponse",this.statusText=r,this.url=c,this.headers=s,this.status=n,this.ok=o,this.body=w}}function u(t){return Object.defineProperty(t,v,{value:t}),t}function a(t){return typeof t==="function"&&v in t}function G(){const t=new Map;return{set(n,r){if(!a(n))throw D;return t.set(n,r),this},get(n){if(!a(n))throw D;if(!t.has(n))t.set(n,n());return t.get(n)},del(n){return t.delete(n),this},has(n){return t.has(n)},keys(){return t.keys()}}}var v=Symbol("HttpContextToken");function pt(t){const n={alias:new Map,validators:[],asyncValidator:[]},r=()=>t;return Object.defineProperty(r,S,{value:n}),r.withJson=(o)=>{return n.alias.set(1,o),r},r.withForm=(o)=>{return n.alias.set(5,o),r},r.withQuery=(o)=>{return n.alias.set(2,o),r},r.withParam=(o)=>{return n.alias.set(3,o),r},r.withHeader=(o)=>{return n.alias.set(4,o),r},r.withUrlForm=(o)=>{return n.alias.set(7,o),r},r.withBody=()=>{return n.alias.set(6,void 0),r},r.withValidators=(...o)=>{return n.validators=o,r},r.withAsyncValidators=(...o)=>{return n.asyncValidator=o,r},r}function z(t){return t[S]}function ft(t,n){for(let r of t){const o=r(n);if(o)throw o}}async function Rt(t,n){for(let r of t){const o=await r(n);if(o)throw o}}function g(t){return!!t&&typeof t==="function"&&S in t}function L(t){return!!t&&typeof t==="object"&&Object.entries(t).every(([,n])=>g(n))}var S=Symbol("field");var kt=void 0;var tt=()=>kt;function nt(t){return t.reduceRight((n,r)=>{return(o,s)=>r(o,(c)=>n(c,s))},(n,r)=>r(n))}function V(t){const n=t.status??0,r=t.statusText??"",o=t.url??"",s=t.headers??new Headers,c=t.body??null;return{status:n,statusText:r,url:o,headers:s,body:c}}function ot(t){switch(!0){case t instanceof FormData:case t instanceof Blob:case t instanceof ArrayBuffer:case t instanceof URLSearchParams:case typeof t==="string":return t;case typeof t==="object":case typeof t==="boolean":case typeof t==="number":case Array.isArray(t):return JSON.stringify(t);default:return null}}function xt(t){switch(!0){case t instanceof FormData:return"multipart/form-data";case t instanceof ArrayBuffer:return"application/octet-stream";case t instanceof Blob:return t.type||"application/octet-stream";case t instanceof URLSearchParams:return"application/x-www-form-urlencoded;charset=UTF-8";case typeof t==="string":return"text/plain";case(typeof t==="object"&&t!==null):case typeof t==="number":case typeof t==="boolean":return"application/json";default:return null}}function mt(t){if(g(t))return t();if(L(t)){const n={};for(let[r,o]of Object.entries(t))n[r]=o();return n}return}function Nt(t,n){let r=!1,o,s=[],c="json",w,p="body",h=!1,T=[],E;const e=()=>{let x,i,f;return{doRequest:async(...k)=>{let I,m;switch(k.length){case 1:{m=k[0];break}case 2:{I=k[0],m=k[1];break}}if(r&&!I)throw new Error("Because the request has input, the first argument must be the input value");if(T.length>0)for(let y of T)y(I);const N=m?.timeout||0;if(m?.abort)f=m.abort;else if(N>0)f=AbortSignal.timeout(N);const C=P(m?.client)?m.client:d(),O=b(C),K={host:O?.host,method:t,endpoint:n,queryParams:new URLSearchParams,headers:new Headers,body:void 0,withCredentials:h,responseType:c,context:w||G(),observe:p,uploadProgress:x,downloadProgress:i,timeout:N,abort:f},q=m?.handler||O?.handler||tt();if(!q)throw J;if(r)await Ct(K,o,I);let U=await nt([...s])(K,q);if(typeof E==="function")try{U=V({...U,body:E(U)})}catch(y){throw new _({error:y})}switch(K.observe){case"body":return U.body;case"response":return U;default:throw Q}},getInitValue:()=>mt(o),setUploadProgress:(k)=>{x=k},setDownloadProgress:(k)=>{i=k}}};return e.withField=(x)=>{return o=x,r=!0,e},e.withInterceptors=(x)=>{return s=x,e},e.withContext=(x)=>{return w=x,e},e.withCredentials=(x)=>{return h=x,e},e.withValidators=(x)=>{return T=x,e},e.withTransformResponse=(x)=>{return E=x,e},e.withObserve=(x)=>{return p=x,e},e.withResponseType=(x)=>{return c=x,e},e}function rt(t,n){return t.replace(/:([^\/]+)/g,(r,o)=>{return n.get(o)??"undefined"})}async function Ct(t,n,r){async function o(T,E){for(let e of T){const x=await e(E);if(x)return x}return}function s(T){return typeof T==="object"&&T!==null}function c(T){switch(!0){case Array.isArray(T):case(typeof T==="object"&&T!==null):return JSON.stringify(T);case(typeof T==="object"&&T===null):case typeof T==="boolean":case typeof T==="number":case typeof T==="string":return String(T);default:throw new Error("Unsupported value type")}}function w(T,E,e){if(Array.isArray(e))for(let x of e)T.append(E,c(x));else T.set(E,c(e));return T}function p(T,E,e){if(Array.isArray(e))for(let x of e)p(T,E,c(x));return T.set(E,c(e)),T}function h(T,E){switch(!0){case typeof T==="undefined":return E;case(typeof T==="object"&&T===null):return T;default:return T}}if(g(n)){let T,E,e,x=void 0;const i=h(r,n()),f=z(n),A=await o([...f.validators,...f.asyncValidator],i);if(A)throw A;for(let[R,H]of f.alias)switch(R){case 2:{if(!H)throw F;E=w(new URLSearchParams,H,i);break}case 3:{if(!H)throw F;T=p(new Map,H,i);break}case 4:{if(!H)throw F;e=w(new Headers,H,i);break}case 5:{if(!H)throw F;x=w(new FormData,H,i);break}case 7:{if(!H)throw F;x=w(new URLSearchParams,H,i);break}case 1:case 6:x=i;break}if(T)t.endpoint=rt(t.endpoint,T);t.queryParams=E,t.headers=e,t.body=x;return}if(L(n)&&s(r)){let T=new Map,E=new URLSearchParams,e=new Headers,x=new URLSearchParams,i=new FormData;const f={};let A=void 0,R;for(let[H,$]of Object.entries(n)){const k=z($);for(let[I,m]of k.alias){const N=m||H,C=h(r[H],$()),O=await o([...k.validators,...k.asyncValidator],C);if(O)throw O;switch(I){case 1:{Object.defineProperty(f,N,{value:C,writable:!0,enumerable:!0}),R=1;break}case 2:E=w(E,N,C);break;case 3:T=p(T,N,C);break;case 4:e=w(e,N,C);break;case 5:{i=w(i,N,C),R=5;break}case 7:{x=w(x,N,C),R=7;break}case 6:{A=C,R=6;break}}}}switch(t.endpoint=rt(t.endpoint,T),t.queryParams=E,t.headers=e,R){case 6:t.body=A;break;case 5:t.body=i;break;case 7:t.body=x;break;case 1:t.body=f;break}return}throw j}function Tt(t){const n=t.get("Content-Length");if(!n)return 0;const r=Number(n);if(isNaN(r))return 0;return r}function et(t){return t.get("Content-Type")||""}function ct(t){const{request:n,content:r,contentType:o}=t,s=n.responseType;if(!s)return null;switch(s){case"json":{const c=new TextDecoder().decode(r);if(c==="")return null;return JSON.parse(c)}case"text":return new TextDecoder().decode(r);case"blob":return new Blob([r],{type:o});case"arraybuffer":return r.buffer;default:return null}}function st(t,n){const r=new Uint8Array(n);let o=0;for(let s of t)r.set(s,o),o+=s.length;return r}function _t(t){const n=new URL(t.endpoint,t.host);if(t.queryParams)n.search=t.queryParams.toString();const r=t.headers??new Headers;if(!r.has("Content-Type")){const c=xt(t.body);if(c)r.set("Content-Type",c)}if(!r.has("Accept"))r.set("Accept","application/json, text/plain, */*");const o=t.withCredentials?"include":void 0,s=t.context?.get(Et)||{};return new Request(n,{...s,headers:r,method:t.method,body:ot(t.body),signal:t.abort,credentials:o})}async function l(t){const n=t.downloadProgress,r=_t(t);let o;try{o=await(globalThis||window).fetch(r)}catch(x){if(x instanceof DOMException)switch(!0){case(x.name==="AbortError"||x.code===x.ABORT_ERR):throw new _({error:W});case(x.name==="TimeoutError"||x.code===x.TIMEOUT_ERR):throw new _({error:X})}throw new _({error:x})}const{ok:s,headers:c,status:w,statusText:p,url:h}=o,T=Tt(c),E=et(c);let e=null;if(o.body){const x=[],i=o.body.getReader();let f=0;while(!0){const{done:R,value:H}=await i.read();if(R)break;x.push(H),f+=H.length,n?.({lengthComputable:T>0,loaded:f,total:T})}const A=st(x,f);try{e=ct({request:t,content:A,contentType:E})}catch(R){throw new _({error:R,status:w,statusText:p,headers:c,url:h})}}if(!s)throw new _({status:w,statusText:p,headers:c,url:h,body:e});return V({url:h,status:w,statusText:p,headers:c,body:e})}var Et=u(()=>({}));function P(t){return typeof t==="object"&&t!==null&&M in t}function b(t){if(!P(t))throw Y;return t[M]}function wt(t){const n={host:t.host,interceptors:t.interceptors??[],handler:t.handler||l};return{[M]:n}}function ht(t,n){const o={...b(t),...n};return{[M]:o}}function d(){if(!B)throw Z;return B}function At(t){B=t}function Ft(){B=void 0}function It(t){B=wt(t)}var M=Symbol("Client"),B;function Ot(t,n){let r=n?.encode;if(!r){const o=(globalThis||window).btoa;if(typeof o!=="function")throw new Error("BasicAuthInterceptor is not supported in this environment");r=(s)=>o(`${s.username}:${s.password}`)}return(o,s)=>{const c=o.headers||new Headers;return c.set("Authorization",`Basic ${r(t())}`),o.headers=c,s(o)}}var Ut=(t)=>{if(!t)return new Error("required");return null},gt=(t)=>{if(typeof t!=="boolean"||!t)return new Error("requiredTrue");return null},Bt=(t)=>{return(n)=>{if(typeof n!=="string")return new Error("invalid string");if(n.length<t)return new Error(`minLength ${t}`);return null}},Dt=(t)=>{return(n)=>{if(typeof n!=="string")return new Error("invalid string");if(n.length>t)return new Error(`maxLength ${t}`);return null}},Lt=(t)=>{return(n)=>{if(typeof n!=="number"||isNaN(n))return new Error("invalid number");if(n<t)return new Error(`minLength ${t}`);return null}},Vt=(t)=>{return(n)=>{if(typeof n!=="number"||isNaN(n))return new Error("invalid number");if(n>t)return new Error(`maxLength ${t}`);return null}},Pt=(t)=>{return(n)=>{if(typeof n!=="string")return new Error("invalid string");if(!t.test(n))return new Error("pattern");return null}};export{ft as validatorField,At as setGlobalClient,Ft as restGlobalClient,gt as requiredTrue,Ut as required,Pt as pattern,Bt as minLength,Lt as min,Dt as maxLength,Vt as max,u as makeHttpContextToken,G as makeHttpContext,a as isHttpContextToken,L as isFieldGroup,g as isField,P as isClient,d as getGlobalClient,pt as field,l as fetchHandler,Nt as defineRequest,It as createGlobalClient,wt as createClient,ht as cloneClient,Ot as basicAuthInterceptor,Rt as asyncValidatorField,_ as HttpErrorResponse,Et as FETCH_CONFIG_KEY,j as ERR_UNSUPPORTED_FIELD_TYPE,it as ERR_UNKNOWN,X as ERR_TIMEOUT,Q as ERR_OBSERVE,F as ERR_NOT_SET_ALIAS,J as ERR_NOT_FOUND_HANDLER,Z as ERR_NOT_FOUND_GLOBAL_CLIENT,Ht as ERR_NETWORK,D as ERR_INVALID_HTTP_CONTEXT_TOKEN,Y as ERR_INVALID_CLIENT,W as ERR_ABORTED};