@defjs/core 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/index.d.ts +32 -54
  2. package/index.js +107 -159
  3. package/index.min.js +1 -1
  4. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -63,6 +63,17 @@ export declare function field<T>(defaultValue: T): Field<T>;
63
63
  export declare function doValid<T>(validators: (ValidatorFn<T> | AsyncValidatorFn<T>)[], value: T): Promise<void>;
64
64
  export declare function isField(value: unknown): value is Field;
65
65
  export declare function isFieldGroup(value: unknown): value is Record<PropertyKey, Field>;
66
+ export declare const ERR_ABORTED: Error;
67
+ export declare const ERR_TIMEOUT: Error;
68
+ export declare const ERR_NETWORK: Error;
69
+ export declare const ERR_NOT_FOUND_HANDLER: Error;
70
+ export declare const ERR_OBSERVE: Error;
71
+ export declare const ERR_NOT_SET_ALIAS: Error;
72
+ export declare const ERR_UNSUPPORTED_FIELD_TYPE: Error;
73
+ export declare const ERR_INVALID_CLIENT: Error;
74
+ export declare const ERR_NOT_FOUND_GLOBAL_CLIENT: Error;
75
+ export declare const ERR_INVALID_HTTP_CONTEXT_TOKEN: Error;
76
+ export declare const ERR_UNKNOWN: Error;
66
77
  export type HttpResponseBody = string | ArrayBuffer | Blob | object | null;
67
78
  export type HttpResponse<R> = {
68
79
  readonly url: string;
@@ -70,6 +81,7 @@ export type HttpResponse<R> = {
70
81
  readonly statusText: string;
71
82
  readonly headers: Headers;
72
83
  readonly body: R | null;
84
+ readonly error?: Error | string | unknown;
73
85
  };
74
86
  export type MakeResponseOptions<R> = {
75
87
  status?: number;
@@ -77,6 +89,7 @@ export type MakeResponseOptions<R> = {
77
89
  url?: string;
78
90
  headers?: Headers;
79
91
  body?: R | null;
92
+ error?: Error | string | unknown;
80
93
  };
81
94
  export type InterceptorFn = (req: HttpRequest, next: HttpHandler) => Promise<HttpResponse<unknown>>;
82
95
  export type BasicCredential = {
@@ -119,10 +132,6 @@ export interface HttpRequest {
119
132
  /** when use fetch handler, no upload progress */
120
133
  uploadProgress?: HttpProgressFn;
121
134
  downloadProgress?: HttpProgressFn;
122
- /**
123
- * default:body
124
- */
125
- observe?: "body" | "response";
126
135
  abort?: AbortSignal;
127
136
  }
128
137
  export type RequestInputValue<T> = T extends Field<infer V> ? V : T extends {
@@ -130,15 +139,15 @@ export type RequestInputValue<T> = T extends Field<infer V> ? V : T extends {
130
139
  } ? {
131
140
  [K in keyof T]: RequestInputValue<T[K]>;
132
141
  } : never;
133
- export type DoRequestOptions = {
142
+ export type UseRequestOptions = {
134
143
  abort?: AbortSignal;
135
144
  handler?: HttpHandler;
136
145
  client?: Client;
137
146
  timeout?: number;
138
147
  };
139
- export type ObserveType<Observe, Output> = Observe extends "body" ? Output : Observe extends "response" ? HttpResponse<Output> : never;
140
- export type UseRequestFn<Input, Output, Observe> = {
141
- doRequest: Input extends undefined ? (options?: DoRequestOptions) => Promise<ObserveType<Observe, Output>> : RequestInputValue<Input> extends RequestInputValue<Input> | undefined ? (input?: RequestInputValue<Input>, options?: DoRequestOptions) => Promise<ObserveType<Observe, Output>> : (input: RequestInputValue<Input>, options?: DoRequestOptions) => Promise<ObserveType<Observe, Output>>;
148
+ export type UseRequestFn<Input, Output> = {
149
+ doRequest: undefined extends RequestInputValue<Input> ? (input?: RequestInputValue<Input>) => Promise<HttpResponse<Output>> : (input: RequestInputValue<Input>) => Promise<HttpResponse<Output>>;
150
+ cancel: () => void;
142
151
  getInitValue: () => Input extends Field<infer V> ? V : Input extends {
143
152
  [K in keyof Input]: Field<any>;
144
153
  } ? {
@@ -147,20 +156,18 @@ export type UseRequestFn<Input, Output, Observe> = {
147
156
  setUploadProgress: (fn: HttpProgressFn) => void;
148
157
  setDownloadProgress: (fn: HttpProgressFn) => void;
149
158
  };
150
- export interface DefineRequest<Input extends Field<any> | Record<PropertyKey, Field<any>> | undefined = undefined, Output = unknown, Observe extends "body" | "response" = "body"> {
151
- (): UseRequestFn<Input, Output, Observe>;
152
- withField<I extends Field<any> | Record<PropertyKey, Field<any>>>(value: I): DefineRequest<I, Output, Observe>;
153
- withInterceptors(value: InterceptorFn[]): DefineRequest<Input, Output, Observe>;
154
- withContext(value: HttpContext): DefineRequest<Input, Output, Observe>;
155
- withCredentials(value: boolean): DefineRequest<Input, Output, Observe>;
156
- withValidators(value: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[]): DefineRequest<Input, Output, Observe>;
157
- withTransformResponse<O>(fn: TransformResponseFn<O>): DefineRequest<Input, O, Observe>;
158
- withObserve(value: "body"): DefineRequest<Input, Output, "body">;
159
- withObserve(value: "response"): DefineRequest<Input, Output, "response">;
160
- withResponseType(value: "json"): DefineRequest<Input, Output, Observe>;
161
- withResponseType(value: "text"): DefineRequest<Input, string, Observe>;
162
- withResponseType(value: "blob"): DefineRequest<Input, Blob, Observe>;
163
- withResponseType(value: "arraybuffer"): DefineRequest<Input, ArrayBuffer, Observe>;
159
+ export interface DefineRequest<Input extends Field<any> | Record<PropertyKey, Field<any>> | undefined = undefined, Output = unknown> {
160
+ (options?: UseRequestOptions): UseRequestFn<Input, Output>;
161
+ withField<I extends Field<any> | Record<PropertyKey, Field<any>>>(value: I): DefineRequest<I, Output>;
162
+ withInterceptors(value: InterceptorFn[]): DefineRequest<Input, Output>;
163
+ withContext(value: HttpContext): DefineRequest<Input, Output>;
164
+ withCredentials(value: boolean): DefineRequest<Input, Output>;
165
+ withValidators(value: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[]): DefineRequest<Input, Output>;
166
+ withTransformResponse<O>(fn: TransformResponseFn<O>): DefineRequest<Input, O>;
167
+ withResponseType(value: "json"): DefineRequest<Input, Output>;
168
+ withResponseType(value: "text"): DefineRequest<Input, string>;
169
+ withResponseType(value: "blob"): DefineRequest<Input, Blob>;
170
+ withResponseType(value: "arraybuffer"): DefineRequest<Input, ArrayBuffer>;
164
171
  }
165
172
  export declare function defineRequest<Output>(endpoint: string): DefineRequest<undefined, Output>;
166
173
  export declare function defineRequest<Output>(method: string, endpoint: string): DefineRequest<undefined, Output>;
@@ -168,17 +175,14 @@ export type HttpHandler = (req: HttpRequest) => Promise<HttpResponse<unknown>>;
168
175
  export declare function fetchHandler(httpRequest: HttpRequest): Promise<HttpResponse<unknown>>;
169
176
  export interface ClientOptions {
170
177
  host: string;
171
- /** Default: true */
172
- strict?: boolean;
173
178
  interceptors?: InterceptorFn[];
174
179
  handler?: HttpHandler;
175
180
  }
176
- export interface ClientConfig {
181
+ export type ClientConfig = {
177
182
  host: string;
178
- strict: boolean;
179
183
  handler: HttpHandler;
180
- interceptors?: InterceptorFn[];
181
- }
184
+ interceptors: InterceptorFn[];
185
+ };
182
186
  declare const CLIENT: unique symbol;
183
187
  export type Client = {
184
188
  readonly [CLIENT]: ClientConfig;
@@ -190,31 +194,5 @@ export declare function getGlobalClient(): Client;
190
194
  export declare function setGlobalClient(client: Client): void;
191
195
  export declare function restGlobalClient(): void;
192
196
  export declare function createGlobalClient(options: ClientOptions): void;
193
- export declare const ERR_ABORTED: Error;
194
- export declare const ERR_TIMEOUT: Error;
195
- export declare const ERR_NETWORK: Error;
196
- export declare const ERR_NOT_FOUND_HANDLER: Error;
197
- export declare const ERR_OBSERVE: Error;
198
- export declare const ERR_NOT_SET_ALIAS: Error;
199
- export declare const ERR_UNSUPPORTED_FIELD_TYPE: Error;
200
- export declare const ERR_INVALID_CLIENT: Error;
201
- export declare const ERR_NOT_FOUND_GLOBAL_CLIENT: Error;
202
- export declare const ERR_INVALID_HTTP_CONTEXT_TOKEN: Error;
203
- export declare const ERR_UNKNOWN: Error;
204
- export declare class HttpErrorResponse extends Error {
205
- readonly status: number;
206
- readonly statusText: string;
207
- readonly url: string;
208
- readonly headers: Headers;
209
- readonly body: unknown;
210
- constructor(init?: {
211
- error?: Error | string | unknown;
212
- status?: number;
213
- statusText?: string;
214
- url?: string;
215
- headers?: Headers;
216
- body?: unknown;
217
- });
218
- }
219
197
 
220
198
  export {};
package/index.js CHANGED
@@ -1,48 +1,3 @@
1
- // src/error.ts
2
- var ERR_ABORTED = new Error("ERR_ABORTED");
3
- var ERR_TIMEOUT = new Error("ERR_TIMEOUT");
4
- var ERR_NETWORK = new Error("ERR_NETWORK");
5
- var ERR_NOT_FOUND_HANDLER = new Error("ERR_NOT_FOUND_HANDLER");
6
- var ERR_OBSERVE = new Error("ERR_OBSERVE");
7
- var ERR_NOT_SET_ALIAS = new Error("ERR_NOT_SET_ALIAS");
8
- var ERR_UNSUPPORTED_FIELD_TYPE = new Error("ERR_UNSUPPORTED_FIELD_TYPE");
9
- var ERR_INVALID_CLIENT = new Error("ERR_INVALID_CLIENT");
10
- var ERR_NOT_FOUND_GLOBAL_CLIENT = new Error("ERR_NOT_FOUND_GLOBAL_CLIENT");
11
- var ERR_INVALID_HTTP_CONTEXT_TOKEN = new Error("ERR_INVALID_HTTP_CONTEXT_TOKEN");
12
- var ERR_UNKNOWN = new Error("ERR_UNKNOWN");
13
-
14
- class HttpErrorResponse extends Error {
15
- status;
16
- statusText;
17
- url;
18
- headers;
19
- body;
20
- constructor(init) {
21
- const status = init?.status ?? 0;
22
- const statusText = init?.statusText ?? "";
23
- const ok = status >= 200 && status < 300;
24
- const headers = init?.headers ?? new Headers;
25
- const url = init?.url ?? "";
26
- const body = init?.body ?? null;
27
- let message;
28
- if (ok) {
29
- message = `Http failure during parsing for ${url}`;
30
- } else {
31
- message = `Http failure response for ${url || "(unknown url)"}: ${status}`;
32
- if (statusText) {
33
- message += ` - ${statusText}`;
34
- }
35
- }
36
- super(message, { cause: init?.error });
37
- super.name = "HttpErrorResponse";
38
- this.statusText = statusText;
39
- this.url = url;
40
- this.headers = headers;
41
- this.status = status;
42
- this.body = body;
43
- }
44
- }
45
-
46
1
  // src/handler/util.ts
47
2
  function __getContentLength(headers) {
48
3
  const value = headers.get("Content-Length");
@@ -90,6 +45,43 @@ function __concatChunks(chunks, totalLength) {
90
45
  return chunksAll;
91
46
  }
92
47
 
48
+ // src/response.ts
49
+ function __makeResponse(options) {
50
+ const status = options?.status ?? 0;
51
+ const ok = status >= 200 && status < 300;
52
+ const statusText = options?.statusText ?? "";
53
+ const url = options?.url ?? "";
54
+ const headers = options?.headers ?? new Headers;
55
+ const body = options?.body ?? null;
56
+ let error = options?.error;
57
+ if (!error && !ok) {
58
+ let message = `Http failure response for ${url || "(unknown url)"}: ${status}`;
59
+ if (statusText) {
60
+ message += ` - ${statusText}`;
61
+ }
62
+ error = new Error(message);
63
+ }
64
+ return {
65
+ status,
66
+ statusText,
67
+ url,
68
+ headers,
69
+ body,
70
+ error
71
+ };
72
+ }
73
+ var ERR_ABORTED = new Error("ERR_ABORTED");
74
+ var ERR_TIMEOUT = new Error("ERR_TIMEOUT");
75
+ var ERR_NETWORK = new Error("ERR_NETWORK");
76
+ var ERR_NOT_FOUND_HANDLER = new Error("ERR_NOT_FOUND_HANDLER");
77
+ var ERR_OBSERVE = new Error("ERR_OBSERVE");
78
+ var ERR_NOT_SET_ALIAS = new Error("ERR_NOT_SET_ALIAS");
79
+ var ERR_UNSUPPORTED_FIELD_TYPE = new Error("ERR_UNSUPPORTED_FIELD_TYPE");
80
+ var ERR_INVALID_CLIENT = new Error("ERR_INVALID_CLIENT");
81
+ var ERR_NOT_FOUND_GLOBAL_CLIENT = new Error("ERR_NOT_FOUND_GLOBAL_CLIENT");
82
+ var ERR_INVALID_HTTP_CONTEXT_TOKEN = new Error("ERR_INVALID_HTTP_CONTEXT_TOKEN");
83
+ var ERR_UNKNOWN = new Error("ERR_UNKNOWN");
84
+
93
85
  // src/context.ts
94
86
  function makeHttpContextToken(defaultValue) {
95
87
  Object.defineProperty(defaultValue, HTTP_CONTEXT_TOKEN, { value: defaultValue });
@@ -230,22 +222,6 @@ function makeInterceptorChain(interceptors) {
230
222
  }, (req, fn) => fn(req));
231
223
  }
232
224
 
233
- // src/response.ts
234
- function __makeResponse(options) {
235
- const status = options?.status ?? 0;
236
- const statusText = options?.statusText ?? "";
237
- const url = options?.url ?? "";
238
- const headers = options?.headers ?? new Headers;
239
- const body = options?.body ?? null;
240
- return {
241
- status,
242
- statusText,
243
- url,
244
- headers,
245
- body
246
- };
247
- }
248
-
249
225
  // src/request.ts
250
226
  function __serializeBody(body) {
251
227
  switch (true) {
@@ -307,7 +283,6 @@ function defineRequest(...args) {
307
283
  let interceptors = [];
308
284
  let responseType = "json";
309
285
  let context2;
310
- let observe = "body";
311
286
  let withCredentials = false;
312
287
  let validators = [];
313
288
  let transformResponse;
@@ -325,10 +300,30 @@ function defineRequest(...args) {
325
300
  default:
326
301
  throw new Error("Invalid arguments");
327
302
  }
328
- const fn = () => {
303
+ const fn = (options) => {
304
+ const timeout = options?.timeout || 0;
305
+ const client2 = options?.client || getGlobalClient();
306
+ const clientOptions = getClientConfig(client2);
307
+ const handler2 = options?.handler || clientOptions?.handler || getGlobalHttpHandler();
308
+ if (!handler2) {
309
+ throw ERR_NOT_FOUND_HANDLER;
310
+ }
329
311
  let uploadProgress;
330
312
  let downloadProgress;
331
- let abortSignal;
313
+ let abortController;
314
+ const abortSignal = [];
315
+ if (options?.abort) {
316
+ abortSignal.push(options.abort);
317
+ } else {
318
+ abortController = new AbortController;
319
+ abortSignal.push(abortController.signal);
320
+ }
321
+ if (timeout > 0) {
322
+ abortSignal.push(AbortSignal.timeout(timeout));
323
+ }
324
+ const cancel = () => {
325
+ abortController?.abort();
326
+ };
332
327
  const getInitValue = () => __buildFieldDefaultValue(field3);
333
328
  const setUploadProgress = (fn2) => {
334
329
  uploadProgress = fn2;
@@ -337,85 +332,53 @@ function defineRequest(...args) {
337
332
  downloadProgress = fn2;
338
333
  };
339
334
  const doRequest = async (...args2) => {
340
- let input;
341
- let doRequestOptions;
342
- switch (args2.length) {
343
- case 1: {
344
- if (requiredInput) {
345
- input = args2[0];
346
- } else {
347
- doRequestOptions = args2[0];
348
- }
349
- break;
350
- }
351
- case 2: {
335
+ try {
336
+ let input;
337
+ if (requiredInput && args2.length === 1) {
352
338
  input = args2[0];
353
- doRequestOptions = args2[1];
354
- break;
355
339
  }
356
- }
357
- if (requiredInput && !input) {
358
- throw new Error(`Because the request has input, the first argument must be the input value`);
359
- }
360
- if (validators.length > 0) {
361
- for (const fn2 of validators) {
362
- fn2(input);
340
+ if (requiredInput && !input) {
341
+ throw new Error(`Because the request has input, the argument must be the input value`);
363
342
  }
364
- }
365
- const timeout = doRequestOptions?.timeout || 0;
366
- if (doRequestOptions?.abort) {
367
- abortSignal = doRequestOptions.abort;
368
- } else if (timeout > 0) {
369
- abortSignal = AbortSignal.timeout(timeout);
370
- }
371
- const client2 = isClient(doRequestOptions?.client) ? doRequestOptions.client : getGlobalClient();
372
- const clientOptions = getClientConfig(client2);
373
- const req = {
374
- host: clientOptions?.host,
375
- method,
376
- endpoint,
377
- queryParams: new URLSearchParams,
378
- headers: new Headers,
379
- body: undefined,
380
- withCredentials,
381
- responseType,
382
- context: context2 || makeHttpContext(),
383
- observe,
384
- uploadProgress,
385
- downloadProgress,
386
- timeout,
387
- abort: abortSignal
388
- };
389
- const handler2 = doRequestOptions?.handler || clientOptions?.handler || getGlobalHttpHandler();
390
- if (!handler2) {
391
- throw ERR_NOT_FOUND_HANDLER;
392
- }
393
- if (requiredInput && field3) {
394
- await __fillRequestFromField(req, field3, input);
395
- }
396
- const chain = makeInterceptorChain([...interceptors]);
397
- let res = await chain(req, handler2);
398
- if (typeof transformResponse === "function") {
399
- try {
343
+ if (validators.length > 0) {
344
+ for (const fn2 of validators) {
345
+ fn2(input);
346
+ }
347
+ }
348
+ const req = {
349
+ host: clientOptions?.host,
350
+ method,
351
+ endpoint,
352
+ queryParams: new URLSearchParams,
353
+ headers: new Headers,
354
+ body: undefined,
355
+ withCredentials,
356
+ responseType,
357
+ context: context2 || makeHttpContext(),
358
+ uploadProgress,
359
+ downloadProgress,
360
+ timeout,
361
+ abort: AbortSignal.any(abortSignal)
362
+ };
363
+ if (requiredInput && field3) {
364
+ await __fillRequestFromField(req, field3, input);
365
+ }
366
+ const chain = makeInterceptorChain([...clientOptions.interceptors, ...interceptors]);
367
+ let res = await chain(req, handler2);
368
+ if (typeof transformResponse === "function") {
400
369
  res = __makeResponse({
401
370
  ...res,
402
371
  body: transformResponse(res)
403
372
  });
404
- } catch (error3) {
405
- throw new HttpErrorResponse({ error: error3 });
406
373
  }
407
- }
408
- switch (req.observe) {
409
- case "body":
410
- return res.body;
411
- case "response":
412
- return res;
413
- default:
414
- throw ERR_OBSERVE;
374
+ return res;
375
+ } catch (error) {
376
+ return __makeResponse({ error });
415
377
  }
416
378
  };
417
379
  return {
418
380
  doRequest,
381
+ cancel,
419
382
  getInitValue,
420
383
  setUploadProgress,
421
384
  setDownloadProgress
@@ -446,10 +409,6 @@ function defineRequest(...args) {
446
409
  transformResponse = value;
447
410
  return fn;
448
411
  };
449
- fn.withObserve = (value) => {
450
- observe = value;
451
- return fn;
452
- };
453
412
  fn.withResponseType = (value) => {
454
413
  responseType = value;
455
414
  return fn;
@@ -670,27 +629,27 @@ async function fetchHandler(httpRequest) {
670
629
  const downloadProgress = httpRequest.downloadProgress;
671
630
  const request2 = __createRequest(httpRequest);
672
631
  const abortSignal = httpRequest.abort;
673
- let response3;
632
+ let response4;
674
633
  try {
675
- response3 = await globalThis.fetch(request2);
676
- } catch (error4) {
634
+ response4 = await globalThis.fetch(request2);
635
+ } catch (error) {
677
636
  if (abortSignal?.aborted && abortSignal.reason instanceof Error) {
678
637
  switch (true) {
679
638
  case abortSignal.reason.name === "AbortError":
680
- throw new HttpErrorResponse({ error: ERR_ABORTED });
639
+ return __makeResponse({ error: ERR_ABORTED });
681
640
  case abortSignal.reason.name === "TimeoutError":
682
- throw new HttpErrorResponse({ error: ERR_TIMEOUT });
641
+ return __makeResponse({ error: ERR_TIMEOUT });
683
642
  }
684
643
  }
685
- throw new HttpErrorResponse({ error: error4 });
644
+ return __makeResponse({ error });
686
645
  }
687
- const { ok, headers, status, statusText, url } = response3;
646
+ const { headers, status, statusText, url } = response4;
688
647
  const contentLength = __getContentLength(headers);
689
648
  const contentType = __getContentType(headers);
690
649
  let body = null;
691
- if (response3.body) {
650
+ if (response4.body) {
692
651
  const chunks = [];
693
- const reader = response3.body.getReader();
652
+ const reader = response4.body.getReader();
694
653
  let receivedLength = 0;
695
654
  while (true) {
696
655
  const { done, value } = await reader.read();
@@ -712,9 +671,9 @@ async function fetchHandler(httpRequest) {
712
671
  content: chunksAll,
713
672
  contentType
714
673
  });
715
- } catch (error4) {
716
- throw new HttpErrorResponse({
717
- error: error4,
674
+ } catch (error) {
675
+ return __makeResponse({
676
+ error,
718
677
  status,
719
678
  statusText,
720
679
  headers,
@@ -722,20 +681,11 @@ async function fetchHandler(httpRequest) {
722
681
  });
723
682
  }
724
683
  }
725
- if (!ok) {
726
- throw new HttpErrorResponse({
727
- status,
728
- statusText,
729
- headers,
730
- url,
731
- body
732
- });
733
- }
734
684
  return __makeResponse({
735
- url,
736
685
  status,
737
686
  statusText,
738
687
  headers,
688
+ url,
739
689
  body
740
690
  });
741
691
  }
@@ -752,7 +702,6 @@ function getClientConfig(client2) {
752
702
  function createClient(options) {
753
703
  const conf = {
754
704
  host: options.host,
755
- strict: options.strict ?? true,
756
705
  interceptors: options.interceptors ?? [],
757
706
  handler: options.handler || fetchHandler
758
707
  };
@@ -897,7 +846,6 @@ export {
897
846
  createClient,
898
847
  cloneClient,
899
848
  basicAuthInterceptor,
900
- HttpErrorResponse,
901
849
  ERR_UNSUPPORTED_FIELD_TYPE,
902
850
  ERR_UNKNOWN,
903
851
  ERR_TIMEOUT,
package/index.min.js CHANGED
@@ -1 +1 @@
1
- var X=new Error("ERR_ABORTED"),W=new Error("ERR_TIMEOUT"),wt=new Error("ERR_NETWORK"),J=new Error("ERR_NOT_FOUND_HANDLER"),j=new Error("ERR_OBSERVE"),h=new Error("ERR_NOT_SET_ALIAS"),Q=new Error("ERR_UNSUPPORTED_FIELD_TYPE"),Y=new Error("ERR_INVALID_CLIENT"),Z=new Error("ERR_NOT_FOUND_GLOBAL_CLIENT"),B=new Error("ERR_INVALID_HTTP_CONTEXT_TOKEN"),it=new Error("ERR_UNKNOWN");class m extends Error{status;statusText;url;headers;body;constructor(t){const n=t?.status??0,r=t?.statusText??"",o=n>=200&&n<300,T=t?.headers??new Headers,H=t?.url??"",f=t?.body??null;let R;if(o)R=`Http failure during parsing for ${H}`;else if(R=`Http failure response for ${H||"(unknown url)"}: ${n}`,r)R+=` - ${r}`;super(R,{cause:t?.error});super.name="HttpErrorResponse",this.statusText=r,this.url=H,this.headers=T,this.status=n,this.body=f}}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 nt(t){return t.get("Content-Type")||""}function rt(t){const{request:n,content:r,contentType:o}=t;switch(n.responseType){case"json":{const H=new TextDecoder().decode(r);if(H==="")return null;return JSON.parse(H)}case"text":return new TextDecoder().decode(r);case"blob":return new Blob([r],{type:o});case"arraybuffer":return r.buffer;default:return null}}function ot(t,n){const r=new Uint8Array(n);let o=0;for(let T of t)r.set(T,o),o+=T.length;return r}function ft(t){return Object.defineProperty(t,et,{value:t}),t}function D(t){return typeof t==="function"&&et in t}function Rt(t){return typeof t==="object"&&t!==null&&u in t}function G(t){const n=new Map;switch(!0){case Array.isArray(t):{for(let[r,o]of t)if(D(r))n.set(r,o);break}case Rt(t):{for(let[r,o]of t[u])n.set(r,o);break}}return{set(r,o){if(!D(r))throw B;return n.set(r,o),this},get(r){if(!D(r))throw B;if(!n.has(r))n.set(r,r());return n.get(r)},del(r){return n.delete(r),this},has(r){return n.has(r)},keys(){return n.keys()},get length(){return Array.from(n.keys()).length},[u]:n}}var et=Symbol("HttpContextToken"),u=Symbol("HttpContext");function kt(t){const n={required:typeof t!=="undefined",alias:new Map,validators:[],asyncValidator:[]},r=()=>t;return Object.defineProperty(r,z,{value:n}),r.withJson=(o)=>{return n.alias.set(0,o),r},r.withForm=(o)=>{return n.alias.set(4,o),r},r.withQuery=(o)=>{return n.alias.set(1,o),r},r.withParam=(o)=>{return n.alias.set(2,o),r},r.withHeader=(o)=>{return n.alias.set(3,o),r},r.withUrlForm=(o)=>{return n.alias.set(6,o),r},r.withBody=()=>{return n.alias.set(5,void 0),r},r.withValidators=(...o)=>{return n.validators=o,r},r.withAsyncValidators=(...o)=>{return n.asyncValidator=o,r},r}function a(t){return t[z]}async function L(t,n){await Promise.all(t.map((r)=>r(n)))}function F(t){return!!t&&typeof t==="function"&&z in t}function P(t){return!!t&&typeof t==="object"&&Object.entries(t).every(([,n])=>F(n))}var z=Symbol("field");var Ct=void 0;var xt=()=>Ct;function Tt(t){return t.reduceRight((n,r)=>{return(o,T)=>r(o,(H)=>n(H,T))},(n,r)=>r(n))}function y(t){const n=t?.status??0,r=t?.statusText??"",o=t?.url??"",T=t?.headers??new Headers,H=t?.body??null;return{status:n,statusText:r,url:o,headers:T,body:H}}function Ht(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 pt(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(F(t))return t();if(P(t)){const n={};for(let[r,o]of Object.entries(t))n[r]=o();return n}return}function Nt(...t){let n,r,o=!1,T,H=[],f="json",R,e="body",E=!1,s=[],w;switch(t.length){case 1:{n="GET",r=t[0];break}case 2:{n=t[0],r=t[1];break}default:throw new Error("Invalid arguments")}const x=()=>{let c,N,p;return{doRequest:async(...C)=>{let k,i;switch(C.length){case 1:{if(o)k=C[0];else i=C[0];break}case 2:{k=C[0],i=C[1];break}}if(o&&!k)throw new Error("Because the request has input, the first argument must be the input value");if(s.length>0)for(let K of s)K(k);const $=i?.timeout||0;if(i?.abort)p=i.abort;else if($>0)p=AbortSignal.timeout($);const st=V(i?.client)?i.client:b(),l=S(st),g={host:l?.host,method:n,endpoint:r,queryParams:new URLSearchParams,headers:new Headers,body:void 0,withCredentials:E,responseType:f,context:R||G(),observe:e,uploadProgress:c,downloadProgress:N,timeout:$,abort:p},v=i?.handler||l?.handler||xt();if(!v)throw J;if(o&&T)await _t(g,T,k);let I=await Tt([...H])(g,v);if(typeof w==="function")try{I=y({...I,body:w(I)})}catch(K){throw new m({error:K})}switch(g.observe){case"body":return I.body;case"response":return I;default:throw j}},getInitValue:()=>mt(T),setUploadProgress:(C)=>{c=C},setDownloadProgress:(C)=>{N=C}}};return x.withField=(c)=>{return T=c,o=!0,x},x.withInterceptors=(c)=>{return H=c,x},x.withContext=(c)=>{return R=c,x},x.withCredentials=(c)=>{return E=c,x},x.withValidators=(c)=>{return s=c,x},x.withTransformResponse=(c)=>{return w=c,x},x.withObserve=(c)=>{return e=c,x},x.withResponseType=(c)=>{return f=c,x},x}function ct(t,n){return t.replace(/:([^\/]+)/g,(r,o)=>{return n.get(o)??"undefined"})}async function _t(t,n,r){function o(e){return typeof e==="object"&&e!==null}function T(e){switch(!0){case Array.isArray(e):case(typeof e==="object"&&e!==null):return JSON.stringify(e);case(typeof e==="object"&&e===null):case typeof e==="boolean":case typeof e==="number":case typeof e==="string":return String(e);default:throw new Error("Unsupported value type")}}function H(e,E,s){if(Array.isArray(s))for(let w of s)e.append(E,T(w));else e.set(E,T(s));return e}function f(e,E,s){if(Array.isArray(s))for(let w of s)f(e,E,T(w));return e.set(E,T(s)),e}function R(e,E){switch(!0){case typeof e==="undefined":return E;case(typeof e==="object"&&e===null):return e;default:return e}}if(F(n)){let e,E,s,w=void 0;const x=R(r,n()),c=a(n);await L([...c.validators,...c.asyncValidator],x);for(let[N,p]of c.alias)switch(N){case 1:{if(!p)throw h;E=H(new URLSearchParams,p,x);break}case 2:{if(!p)throw h;e=f(new Map,p,x);break}case 3:{if(!p)throw h;s=H(new Headers,p,x);break}case 4:{if(!p)throw h;w=H(new FormData,p,x);break}case 6:{if(!p)throw h;w=H(new URLSearchParams,p,x);break}case 0:case 5:w=x;break}if(e)t.endpoint=ct(t.endpoint,e);t.queryParams=E,t.headers=s,t.body=w;return}if(P(n)&&o(r)){let e=new Map,E=new URLSearchParams,s=new Headers,w=new URLSearchParams,x=new FormData;const c={};let N=void 0,p;for(let[O,_]of Object.entries(n)){const A=a(_);for(let[q,C]of A.alias){const k=C||O,i=R(r[O],_());switch(await L([...A.validators,...A.asyncValidator],i),q){case 0:{Object.defineProperty(c,k,{value:i,writable:!0,enumerable:!0}),p=0;break}case 1:E=H(E,k,i);break;case 2:e=f(e,k,i);break;case 3:s=H(s,k,i);break;case 4:{x=H(x,k,i),p=4;break}case 6:{w=H(w,k,i),p=6;break}case 5:{N=i,p=5;break}}}}switch(t.endpoint=ct(t.endpoint,e),t.queryParams=E,t.headers=s,p){case 5:t.body=N;break;case 4:t.body=x;break;case 6:t.body=w;break;case 0:t.body=c;break}return}throw Q}function At(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 T=pt(t.body);if(T)r.set("Content-Type",T)}if(!r.has("Accept"))r.set("Accept","application/json, text/plain, */*");const o=t.withCredentials?"include":void 0;return new Request(n,{headers:r,method:t.method,body:Ht(t.body),signal:t.abort,credentials:o})}async function d(t){const n=t.downloadProgress,r=At(t),o=t.abort;let T;try{T=await globalThis.fetch(r)}catch(c){if(o?.aborted&&o.reason instanceof Error)switch(!0){case o.reason.name==="AbortError":throw new m({error:X});case o.reason.name==="TimeoutError":throw new m({error:W})}throw new m({error:c})}const{ok:H,headers:f,status:R,statusText:e,url:E}=T,s=tt(f),w=nt(f);let x=null;if(T.body){const c=[],N=T.body.getReader();let p=0;while(!0){const{done:_,value:A}=await N.read();if(_)break;c.push(A),p+=A.length,n?.({lengthComputable:s>0,loaded:p,total:s})}const O=ot(c,p);try{x=rt({request:t,content:O,contentType:w})}catch(_){throw new m({error:_,status:R,statusText:e,headers:f,url:E})}}if(!H)throw new m({status:R,statusText:e,headers:f,url:E,body:x});return y({url:E,status:R,statusText:e,headers:f,body:x})}function V(t){return typeof t==="object"&&t!==null&&M in t}function S(t){if(!V(t))throw Y;return t[M]}function Et(t){const n={host:t.host,strict:t.strict??!0,interceptors:t.interceptors??[],handler:t.handler||d};return{[M]:n}}function ht(t,n){const o={...S(t),...n};return{[M]:o}}function b(){if(!U)throw Z;return U}function Ot(t){U=t}function It(){U=void 0}function Ft(t){U=Et(t)}var M=Symbol("Client"),U;function Ut(t,n){let r=n?.encode;if(!r){const o=globalThis.btoa;if(typeof o!=="function")throw new Error("BasicAuthInterceptor is not supported in this environment");r=(T)=>o(`${T.username}:${T.password}`)}return(o,T)=>{const H=o.headers||new Headers;return H.set("Authorization",`Basic ${r(t())}`),o.headers=H,T(o)}}var Bt=(t)=>{if(!t)return new Error("required");return null},Dt=(t)=>{if(typeof t!=="boolean"||!t)return new Error("requiredTrue");return null},Lt=(t)=>{return(n)=>{if(typeof n!=="string")return new Error("invalid string");if(n.length<t)return new Error(`minLength ${t}`);return null}},Pt=(t)=>{return(n)=>{if(typeof n!=="string")return new Error("invalid string");if(n.length>t)return new Error(`maxLength ${t}`);return null}},yt=(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}},Mt=(t)=>{return(n)=>{if(typeof n!=="string")return new Error("invalid string");if(!t.test(n))return new Error("pattern");return null}};export{Ot as setGlobalClient,It as restGlobalClient,Dt as requiredTrue,Bt as required,Mt as pattern,Lt as minLength,yt as min,Pt as maxLength,Vt as max,ft as makeHttpContextToken,G as makeHttpContext,D as isHttpContextToken,P as isFieldGroup,F as isField,V as isClient,b as getGlobalClient,kt as field,d as fetchHandler,L as doValid,Nt as defineRequest,Ft as createGlobalClient,Et as createClient,ht as cloneClient,Ut as basicAuthInterceptor,m as HttpErrorResponse,Q as ERR_UNSUPPORTED_FIELD_TYPE,it as ERR_UNKNOWN,W as ERR_TIMEOUT,j as ERR_OBSERVE,h as ERR_NOT_SET_ALIAS,J as ERR_NOT_FOUND_HANDLER,Z as ERR_NOT_FOUND_GLOBAL_CLIENT,wt as ERR_NETWORK,B as ERR_INVALID_HTTP_CONTEXT_TOKEN,Y as ERR_INVALID_CLIENT,X as ERR_ABORTED};
1
+ function d(t){const n=t.get("Content-Length");if(!n)return 0;const r=Number(n);if(isNaN(r))return 0;return r}function a(t){return t.get("Content-Type")||""}function q(t){const{request:n,content:r,contentType:o}=t;switch(n.responseType){case"json":{const H=new TextDecoder().decode(r);if(H==="")return null;return JSON.parse(H)}case"text":return new TextDecoder().decode(r);case"blob":return new Blob([r],{type:o});case"arraybuffer":return r.buffer;default:return null}}function l(t,n){const r=new Uint8Array(n);let o=0;for(let T of t)r.set(T,o),o+=T.length;return r}function N(t){const n=t?.status??0,r=n>=200&&n<300,o=t?.statusText??"",T=t?.url??"",H=t?.headers??new Headers,f=t?.body??null;let R=t?.error;if(!R&&!r){let e=`Http failure response for ${T||"(unknown url)"}: ${n}`;if(o)e+=` - ${o}`;R=new Error(e)}return{status:n,statusText:o,url:T,headers:H,body:f,error:R}}var y=new Error("ERR_ABORTED"),K=new Error("ERR_TIMEOUT"),Ht=new Error("ERR_NETWORK"),X=new Error("ERR_NOT_FOUND_HANDLER"),Et=new Error("ERR_OBSERVE"),A=new Error("ERR_NOT_SET_ALIAS"),W=new Error("ERR_UNSUPPORTED_FIELD_TYPE"),J=new Error("ERR_INVALID_CLIENT"),j=new Error("ERR_NOT_FOUND_GLOBAL_CLIENT"),P=new Error("ERR_INVALID_HTTP_CONTEXT_TOKEN"),pt=new Error("ERR_UNKNOWN");function wt(t){return Object.defineProperty(t,v,{value:t}),t}function V(t){return typeof t==="function"&&v in t}function Rt(t){return typeof t==="object"&&t!==null&&Q in t}function Y(t){const n=new Map;switch(!0){case Array.isArray(t):{for(let[r,o]of t)if(V(r))n.set(r,o);break}case Rt(t):{for(let[r,o]of t[Q])n.set(r,o);break}}return{set(r,o){if(!V(r))throw P;return n.set(r,o),this},get(r){if(!V(r))throw P;if(!n.has(r))n.set(r,r());return n.get(r)},del(r){return n.delete(r),this},has(r){return n.has(r)},keys(){return n.keys()},get length(){return Array.from(n.keys()).length},[Q]:n}}var v=Symbol("HttpContextToken"),Q=Symbol("HttpContext");function it(t){const n={required:typeof t!=="undefined",alias:new Map,validators:[],asyncValidator:[]},r=()=>t;return Object.defineProperty(r,Z,{value:n}),r.withJson=(o)=>{return n.alias.set(0,o),r},r.withForm=(o)=>{return n.alias.set(4,o),r},r.withQuery=(o)=>{return n.alias.set(1,o),r},r.withParam=(o)=>{return n.alias.set(2,o),r},r.withHeader=(o)=>{return n.alias.set(3,o),r},r.withUrlForm=(o)=>{return n.alias.set(6,o),r},r.withBody=()=>{return n.alias.set(5,void 0),r},r.withValidators=(...o)=>{return n.validators=o,r},r.withAsyncValidators=(...o)=>{return n.asyncValidator=o,r},r}function G(t){return t[Z]}async function M(t,n){await Promise.all(t.map((r)=>r(n)))}function D(t){return!!t&&typeof t==="function"&&Z in t}function $(t){return!!t&&typeof t==="object"&&Object.entries(t).every(([,n])=>D(n))}var Z=Symbol("field");var ft=void 0;var tt=()=>ft;function nt(t){return t.reduceRight((n,r)=>{return(o,T)=>r(o,(H)=>n(H,T))},(n,r)=>r(n))}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 et(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 kt(t){if(D(t))return t();if($(t)){const n={};for(let[r,o]of Object.entries(t))n[r]=o();return n}return}function Ct(...t){let n,r,o=!1,T,H=[],f="json",R,e=!1,p=[],w;switch(t.length){case 1:{n="GET",r=t[0];break}case 2:{n=t[0],r=t[1];break}default:throw new Error("Invalid arguments")}const c=(x)=>{const i=x?.timeout||0,k=x?.client||S(),E=z(k),C=x?.handler||E?.handler||tt();if(!C)throw X;let m,I,B;const _=[];if(x?.abort)_.push(x.abort);else B=new AbortController,_.push(B.signal);if(i>0)_.push(AbortSignal.timeout(i));return{doRequest:async(...F)=>{try{let U;if(o&&F.length===1)U=F[0];if(o&&!U)throw new Error("Because the request has input, the argument must be the input value");if(p.length>0)for(let ct of p)ct(U);const b={host:E?.host,method:n,endpoint:r,queryParams:new URLSearchParams,headers:new Headers,body:void 0,withCredentials:e,responseType:f,context:R||Y(),uploadProgress:m,downloadProgress:I,timeout:i,abort:AbortSignal.any(_)};if(o&&T)await st(b,T,U);let h=await nt([...E.interceptors,...H])(b,C);if(typeof w==="function")h=N({...h,body:w(h)});return h}catch(U){return N({error:U})}},cancel:()=>{B?.abort()},getInitValue:()=>kt(T),setUploadProgress:(F)=>{m=F},setDownloadProgress:(F)=>{I=F}}};return c.withField=(x)=>{return T=x,o=!0,c},c.withInterceptors=(x)=>{return H=x,c},c.withContext=(x)=>{return R=x,c},c.withCredentials=(x)=>{return e=x,c},c.withValidators=(x)=>{return p=x,c},c.withTransformResponse=(x)=>{return w=x,c},c.withResponseType=(x)=>{return f=x,c},c}function rt(t,n){return t.replace(/:([^\/]+)/g,(r,o)=>{return n.get(o)??"undefined"})}async function st(t,n,r){function o(e){return typeof e==="object"&&e!==null}function T(e){switch(!0){case Array.isArray(e):case(typeof e==="object"&&e!==null):return JSON.stringify(e);case(typeof e==="object"&&e===null):case typeof e==="boolean":case typeof e==="number":case typeof e==="string":return String(e);default:throw new Error("Unsupported value type")}}function H(e,p,w){if(Array.isArray(w))for(let c of w)e.append(p,T(c));else e.set(p,T(w));return e}function f(e,p,w){if(Array.isArray(w))for(let c of w)f(e,p,T(c));return e.set(p,T(w)),e}function R(e,p){switch(!0){case typeof e==="undefined":return p;case(typeof e==="object"&&e===null):return e;default:return e}}if(D(n)){let e,p,w,c=void 0;const x=R(r,n()),i=G(n);await M([...i.validators,...i.asyncValidator],x);for(let[k,E]of i.alias)switch(k){case 1:{if(!E)throw A;p=H(new URLSearchParams,E,x);break}case 2:{if(!E)throw A;e=f(new Map,E,x);break}case 3:{if(!E)throw A;w=H(new Headers,E,x);break}case 4:{if(!E)throw A;c=H(new FormData,E,x);break}case 6:{if(!E)throw A;c=H(new URLSearchParams,E,x);break}case 0:case 5:c=x;break}if(e)t.endpoint=rt(t.endpoint,e);t.queryParams=p,t.headers=w,t.body=c;return}if($(n)&&o(r)){let e=new Map,p=new URLSearchParams,w=new Headers,c=new URLSearchParams,x=new FormData;const i={};let k=void 0,E;for(let[C,m]of Object.entries(n)){const I=G(m);for(let[B,_]of I.alias){const O=_||C,s=R(r[C],m());switch(await M([...I.validators,...I.asyncValidator],s),B){case 0:{Object.defineProperty(i,O,{value:s,writable:!0,enumerable:!0}),E=0;break}case 1:p=H(p,O,s);break;case 2:e=f(e,O,s);break;case 3:w=H(w,O,s);break;case 4:{x=H(x,O,s),E=4;break}case 6:{c=H(c,O,s),E=6;break}case 5:{k=s,E=5;break}}}}switch(t.endpoint=rt(t.endpoint,e),t.queryParams=p,t.headers=w,E){case 5:t.body=k;break;case 4:t.body=x;break;case 6:t.body=c;break;case 0:t.body=i;break}return}throw W}function Nt(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 T=et(t.body);if(T)r.set("Content-Type",T)}if(!r.has("Accept"))r.set("Accept","application/json, text/plain, */*");const o=t.withCredentials?"include":void 0;return new Request(n,{headers:r,method:t.method,body:ot(t.body),signal:t.abort,credentials:o})}async function u(t){const n=t.downloadProgress,r=Nt(t),o=t.abort;let T;try{T=await globalThis.fetch(r)}catch(x){if(o?.aborted&&o.reason instanceof Error)switch(!0){case o.reason.name==="AbortError":return N({error:y});case o.reason.name==="TimeoutError":return N({error:K})}return N({error:x})}const{headers:H,status:f,statusText:R,url:e}=T,p=d(H),w=a(H);let c=null;if(T.body){const x=[],i=T.body.getReader();let k=0;while(!0){const{done:C,value:m}=await i.read();if(C)break;x.push(m),k+=m.length,n?.({lengthComputable:p>0,loaded:k,total:p})}const E=l(x,k);try{c=q({request:t,content:E,contentType:w})}catch(C){return N({error:C,status:f,statusText:R,headers:H,url:e})}}return N({status:f,statusText:R,headers:H,url:e,body:c})}function xt(t){return typeof t==="object"&&t!==null&&g in t}function z(t){if(!xt(t))throw J;return t[g]}function Tt(t){const n={host:t.host,interceptors:t.interceptors??[],handler:t.handler||u};return{[g]:n}}function mt(t,n){const o={...z(t),...n};return{[g]:o}}function S(){if(!L)throw j;return L}function Ot(t){L=t}function At(){L=void 0}function It(t){L=Tt(t)}var g=Symbol("Client"),L;function _t(t,n){let r=n?.encode;if(!r){const o=globalThis.btoa;if(typeof o!=="function")throw new Error("BasicAuthInterceptor is not supported in this environment");r=(T)=>o(`${T.username}:${T.password}`)}return(o,T)=>{const H=o.headers||new Headers;return H.set("Authorization",`Basic ${r(t())}`),o.headers=H,T(o)}}var Ft=(t)=>{if(!t)return new Error("required");return null},Ut=(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}},ht=(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{Ot as setGlobalClient,At as restGlobalClient,Ut as requiredTrue,Ft as required,Pt as pattern,Bt as minLength,Lt as min,Dt as maxLength,ht as max,wt as makeHttpContextToken,Y as makeHttpContext,V as isHttpContextToken,$ as isFieldGroup,D as isField,xt as isClient,S as getGlobalClient,it as field,u as fetchHandler,M as doValid,Ct as defineRequest,It as createGlobalClient,Tt as createClient,mt as cloneClient,_t as basicAuthInterceptor,W as ERR_UNSUPPORTED_FIELD_TYPE,pt as ERR_UNKNOWN,K as ERR_TIMEOUT,Et as ERR_OBSERVE,A as ERR_NOT_SET_ALIAS,X as ERR_NOT_FOUND_HANDLER,j as ERR_NOT_FOUND_GLOBAL_CLIENT,Ht as ERR_NETWORK,P as ERR_INVALID_HTTP_CONTEXT_TOKEN,J as ERR_INVALID_CLIENT,y as ERR_ABORTED};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defjs/core",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "module": "index.js",
6
6
  "typings": "index.d.ts",