@defjs/core 0.0.0-test-001 → 0.0.0-test-003
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.d.ts +45 -148
- package/{index.js → index.es.js} +229 -129
- package/index.es.min.js +1 -0
- package/package.json +1 -1
- package/index.min.js +0 -1
package/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare const minLength: (min: number) => ValidatorFn;
|
|
|
20
20
|
export declare const maxLength: (max: number) => ValidatorFn;
|
|
21
21
|
export declare const min: (min: number) => ValidatorFn;
|
|
22
22
|
export declare const max: (max: number) => ValidatorFn;
|
|
23
|
-
export declare const pattern: (pattern:
|
|
23
|
+
export declare const pattern: (pattern: RegExp) => ValidatorFn;
|
|
24
24
|
declare const FIELD: unique symbol;
|
|
25
25
|
declare enum FieldType {
|
|
26
26
|
Json = 1,
|
|
@@ -28,7 +28,8 @@ declare enum FieldType {
|
|
|
28
28
|
Param = 3,
|
|
29
29
|
Header = 4,
|
|
30
30
|
Form = 5,
|
|
31
|
-
Body = 6
|
|
31
|
+
Body = 6,
|
|
32
|
+
UrlForm = 7
|
|
32
33
|
}
|
|
33
34
|
export interface FieldMetadata<T = undefined> {
|
|
34
35
|
alias: Map<FieldType, string | undefined>;
|
|
@@ -41,6 +42,7 @@ export type Field<T = undefined> = (() => T) & {
|
|
|
41
42
|
withQuery(alias?: string): Field<T>;
|
|
42
43
|
withParam(alias?: string): Field<T>;
|
|
43
44
|
withHeader(alias?: string): Field<T>;
|
|
45
|
+
withUrlForm(alias?: string): Field<T>;
|
|
44
46
|
withBody(): Field<T>;
|
|
45
47
|
withValidators(...fn: ValidatorFn<T>[]): Field<T>;
|
|
46
48
|
withAsyncValidators(...fn: AsyncValidatorFn<T>[]): Field<T>;
|
|
@@ -53,25 +55,13 @@ export declare function validatorField(validators: ValidatorFn<any>[], value: un
|
|
|
53
55
|
export declare function asyncValidatorField(asyncValidator: AsyncValidatorFn<any>[], value: unknown): Promise<void>;
|
|
54
56
|
export declare function isField(value: unknown): value is Field;
|
|
55
57
|
export declare function isFieldGroup(value: unknown): value is Record<PropertyKey, Field>;
|
|
56
|
-
declare const HTTP_RESPONSE: unique symbol;
|
|
57
58
|
export type HttpResponseBody = string | ArrayBuffer | Blob | object | null;
|
|
58
|
-
export type HttpResponse<R> =
|
|
59
|
-
readonly ok: true;
|
|
60
|
-
readonly error: null;
|
|
61
|
-
} | {
|
|
62
|
-
readonly ok: false;
|
|
63
|
-
readonly error: Error;
|
|
64
|
-
}) & {
|
|
59
|
+
export type HttpResponse<R> = {
|
|
65
60
|
readonly url: string;
|
|
66
61
|
readonly status: number;
|
|
67
62
|
readonly statusText: string;
|
|
68
63
|
readonly headers: Headers;
|
|
69
64
|
readonly body: R | null;
|
|
70
|
-
readonly [HTTP_RESPONSE]: unknown;
|
|
71
|
-
};
|
|
72
|
-
export declare function isHttpResponse<R>(value: unknown): value is HttpResponse<R>;
|
|
73
|
-
export declare function isHttpResponseError<R>(value: unknown): value is HttpResponse<R> & {
|
|
74
|
-
ok: false;
|
|
75
65
|
};
|
|
76
66
|
export type MakeResponseOptions<R> = {
|
|
77
67
|
status?: number;
|
|
@@ -79,9 +69,7 @@ export type MakeResponseOptions<R> = {
|
|
|
79
69
|
url?: string;
|
|
80
70
|
headers?: Headers;
|
|
81
71
|
body?: R | null;
|
|
82
|
-
error?: Error;
|
|
83
72
|
};
|
|
84
|
-
export declare function makeResponse<R>(options: MakeResponseOptions<R>): HttpResponse<R>;
|
|
85
73
|
export type InterceptorFn = (req: HttpRequest, next: HttpHandler) => Promise<HttpResponse<unknown>>;
|
|
86
74
|
export type BasicCredential = {
|
|
87
75
|
username: string;
|
|
@@ -107,13 +95,12 @@ export interface HttpProgressEvent {
|
|
|
107
95
|
readonly total: number;
|
|
108
96
|
}
|
|
109
97
|
export type HttpProgressFn = (event: HttpProgressEvent) => void;
|
|
110
|
-
export type TransformRequestFn<Input = unknown> = (input: Input, request: HttpRequest) => HttpRequest["body"];
|
|
111
98
|
export type TransformResponseFn<Output = unknown> = (response: HttpResponse<unknown>) => Output;
|
|
112
99
|
export interface HttpRequest {
|
|
113
100
|
host?: string;
|
|
114
101
|
method: string;
|
|
115
102
|
endpoint: string;
|
|
116
|
-
body?: Blob | ArrayBuffer | FormData | object | string | number | boolean | null;
|
|
103
|
+
body?: Blob | ArrayBuffer | FormData | URLSearchParams | object | string | number | boolean | null;
|
|
117
104
|
headers?: Headers;
|
|
118
105
|
queryParams?: URLSearchParams;
|
|
119
106
|
/** default:json */
|
|
@@ -126,10 +113,8 @@ export interface HttpRequest {
|
|
|
126
113
|
downloadProgress?: HttpProgressFn;
|
|
127
114
|
/**
|
|
128
115
|
* default:body
|
|
129
|
-
*
|
|
130
|
-
* @todo Implement streaming response
|
|
131
116
|
*/
|
|
132
|
-
observe?: "body" | "
|
|
117
|
+
observe?: "body" | "response";
|
|
133
118
|
abort?: AbortSignal;
|
|
134
119
|
}
|
|
135
120
|
export type RequestInputValue<T> = T extends Field<infer V> ? V : T extends {
|
|
@@ -137,29 +122,16 @@ export type RequestInputValue<T> = T extends Field<infer V> ? V : T extends {
|
|
|
137
122
|
} ? {
|
|
138
123
|
[K in keyof T]: RequestInputValue<T[K]>;
|
|
139
124
|
} : never;
|
|
140
|
-
export type RequestOptions<Output = unknown, Input extends Field<any> | Record<PropertyKey, Field<any>> | undefined = undefined> = {
|
|
141
|
-
method: string;
|
|
142
|
-
endpoint: string;
|
|
143
|
-
input?: Input;
|
|
144
|
-
interceptors?: InterceptorFn[];
|
|
145
|
-
responseType?: HttpResponseType;
|
|
146
|
-
context?: HttpContext;
|
|
147
|
-
observe?: "body" | "response";
|
|
148
|
-
withCredentials?: boolean;
|
|
149
|
-
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
150
|
-
transformRequest?: TransformRequestFn;
|
|
151
|
-
transformResponse?: TransformResponseFn<Output>;
|
|
152
|
-
};
|
|
153
125
|
export type DoRequestOptions = {
|
|
154
126
|
abort?: AbortSignal;
|
|
155
127
|
handler?: HttpHandler;
|
|
156
128
|
client?: Client;
|
|
157
129
|
timeout?: number;
|
|
158
130
|
};
|
|
159
|
-
export type
|
|
160
|
-
export type UseRequestFn<Output
|
|
161
|
-
doRequest:
|
|
162
|
-
|
|
131
|
+
export type ObserveType<Observe, Output> = Observe extends "body" ? Output : Observe extends "response" ? HttpResponse<Output> : never;
|
|
132
|
+
export type UseRequestFn<Input, Output, Observe> = {
|
|
133
|
+
doRequest: Input extends undefined ? (options?: DoRequestOptions) => Promise<ObserveType<Observe, Output>> : (input: RequestInputValue<Input>, options?: DoRequestOptions) => Promise<ObserveType<Observe, Output>>;
|
|
134
|
+
getInitValue: () => Input extends Field<infer V> ? V : Input extends {
|
|
163
135
|
[K in keyof Input]: Field<any>;
|
|
164
136
|
} ? {
|
|
165
137
|
[K in keyof Input]: RequestInputValue<Input[K]>;
|
|
@@ -167,112 +139,22 @@ export type UseRequestFn<Output = unknown, Input = unknown> = () => {
|
|
|
167
139
|
setUploadProgress: (fn: HttpProgressFn) => void;
|
|
168
140
|
setDownloadProgress: (fn: HttpProgressFn) => void;
|
|
169
141
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
endpoint: string;
|
|
187
|
-
input?: Input;
|
|
188
|
-
interceptors?: InterceptorFn[];
|
|
189
|
-
responseType: "text";
|
|
190
|
-
observe?: "body";
|
|
191
|
-
context?: HttpContext;
|
|
192
|
-
withCredentials?: boolean;
|
|
193
|
-
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
194
|
-
transformRequest?: TransformRequestFn<RequestInputValue<Input>>;
|
|
195
|
-
transformResponse?: TransformResponseFn;
|
|
196
|
-
}): UseRequestFn<string, Input>;
|
|
197
|
-
export declare function defineRequest<Input extends Field<any> | Record<PropertyKey, Field<any>> | undefined = undefined>(options: {
|
|
198
|
-
method: string;
|
|
199
|
-
endpoint: string;
|
|
200
|
-
input?: Input;
|
|
201
|
-
interceptors?: InterceptorFn[];
|
|
202
|
-
responseType: "blob";
|
|
203
|
-
observe?: "body";
|
|
204
|
-
context?: HttpContext;
|
|
205
|
-
withCredentials?: boolean;
|
|
206
|
-
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
207
|
-
transformRequest?: TransformRequestFn<RequestInputValue<Input>>;
|
|
208
|
-
transformResponse?: TransformResponseFn;
|
|
209
|
-
}): UseRequestFn<Blob, Input>;
|
|
210
|
-
export declare function defineRequest<Input extends Field<any> | Record<PropertyKey, Field<any>> | undefined = undefined>(options: {
|
|
211
|
-
method: string;
|
|
212
|
-
endpoint: string;
|
|
213
|
-
input?: Input;
|
|
214
|
-
interceptors?: InterceptorFn[];
|
|
215
|
-
responseType: "arraybuffer";
|
|
216
|
-
observe?: "body";
|
|
217
|
-
context?: HttpContext;
|
|
218
|
-
withCredentials?: boolean;
|
|
219
|
-
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
220
|
-
transformRequest?: TransformRequestFn<RequestInputValue<Input>>;
|
|
221
|
-
transformResponse?: TransformResponseFn;
|
|
222
|
-
}): UseRequestFn<ArrayBuffer, Input>;
|
|
223
|
-
/** Observe: Response */
|
|
224
|
-
export declare function defineRequest<Output = unknown, Input extends Field<any> | Record<PropertyKey, Field<any>> | undefined = undefined>(options: {
|
|
225
|
-
method: string;
|
|
226
|
-
endpoint: string;
|
|
227
|
-
input?: Input;
|
|
228
|
-
interceptors?: InterceptorFn[];
|
|
229
|
-
responseType?: "json";
|
|
230
|
-
observe: "response";
|
|
231
|
-
context?: HttpContext;
|
|
232
|
-
withCredentials?: boolean;
|
|
233
|
-
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
234
|
-
transformRequest?: TransformRequestFn<RequestInputValue<Input>>;
|
|
235
|
-
transformResponse?: TransformResponseFn<Output>;
|
|
236
|
-
}): UseRequestFn<HttpResponse<Output>, Input>;
|
|
237
|
-
export declare function defineRequest<Input extends Field<any> | Record<PropertyKey, Field<any>> | undefined = undefined>(options: {
|
|
238
|
-
method: string;
|
|
239
|
-
endpoint: string;
|
|
240
|
-
input?: Input;
|
|
241
|
-
interceptors?: InterceptorFn[];
|
|
242
|
-
responseType?: "text";
|
|
243
|
-
observe: "response";
|
|
244
|
-
context?: HttpContext;
|
|
245
|
-
withCredentials?: boolean;
|
|
246
|
-
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
247
|
-
transformRequest?: TransformRequestFn<RequestInputValue<Input>>;
|
|
248
|
-
transformResponse?: TransformResponseFn;
|
|
249
|
-
}): UseRequestFn<HttpResponse<string>, Input>;
|
|
250
|
-
export declare function defineRequest<Input extends Field<any> | Record<PropertyKey, Field<any>> | undefined = undefined>(options: {
|
|
251
|
-
method: string;
|
|
252
|
-
endpoint: string;
|
|
253
|
-
input?: Input;
|
|
254
|
-
interceptors?: InterceptorFn[];
|
|
255
|
-
responseType: "blob";
|
|
256
|
-
observe: "response";
|
|
257
|
-
context?: HttpContext;
|
|
258
|
-
withCredentials?: boolean;
|
|
259
|
-
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
260
|
-
transformRequest?: TransformRequestFn<RequestInputValue<Input>>;
|
|
261
|
-
transformResponse?: TransformResponseFn;
|
|
262
|
-
}): UseRequestFn<HttpResponse<Blob>, Input>;
|
|
263
|
-
export declare function defineRequest<Input extends Field<any> | Record<PropertyKey, Field<any>> | undefined = undefined>(options: {
|
|
264
|
-
method: string;
|
|
265
|
-
endpoint: string;
|
|
266
|
-
input?: Input;
|
|
267
|
-
interceptors?: InterceptorFn[];
|
|
268
|
-
responseType?: "arraybuffer";
|
|
269
|
-
observe: "response";
|
|
270
|
-
context?: HttpContext;
|
|
271
|
-
withCredentials?: boolean;
|
|
272
|
-
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
273
|
-
transformRequest?: TransformRequestFn<RequestInputValue<Input>>;
|
|
274
|
-
transformResponse?: TransformResponseFn;
|
|
275
|
-
}): UseRequestFn<HttpResponse<ArrayBuffer>, Input>;
|
|
142
|
+
export interface DefineRequest<Input extends Field<any> | Record<PropertyKey, Field<any>> | undefined = undefined, Output = unknown, Observe extends "body" | "response" = "body"> {
|
|
143
|
+
(): UseRequestFn<Input, Output, Observe>;
|
|
144
|
+
withField<I extends Field<any> | Record<PropertyKey, Field<any>>>(value: I): DefineRequest<I, Output, Observe>;
|
|
145
|
+
withInterceptors(value: InterceptorFn[]): DefineRequest<Input, Output, Observe>;
|
|
146
|
+
withContext(value: HttpContext): DefineRequest<Input, Output, Observe>;
|
|
147
|
+
withCredentials(value: boolean): DefineRequest<Input, Output, Observe>;
|
|
148
|
+
withValidators(value: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[]): DefineRequest<Input, Output, Observe>;
|
|
149
|
+
withTransformResponse<O>(fn: TransformResponseFn<O>): DefineRequest<Input, O, Observe>;
|
|
150
|
+
withObserve(value: "body"): DefineRequest<Input, Output, "body">;
|
|
151
|
+
withObserve(value: "response"): DefineRequest<Input, Output, "response">;
|
|
152
|
+
withResponseType(value: "json"): DefineRequest<Input, Output, Observe>;
|
|
153
|
+
withResponseType(value: "text"): DefineRequest<Input, string, Observe>;
|
|
154
|
+
withResponseType(value: "blob"): DefineRequest<Input, Blob, Observe>;
|
|
155
|
+
withResponseType(value: "arraybuffer"): DefineRequest<Input, ArrayBuffer, Observe>;
|
|
156
|
+
}
|
|
157
|
+
export declare function defineRequest<Output>(method: string, endpoint: string): DefineRequest<undefined, Output>;
|
|
276
158
|
export type HttpHandler = (req: HttpRequest) => Promise<HttpResponse<unknown>>;
|
|
277
159
|
export interface FetchConfig {
|
|
278
160
|
/** A string indicating how the request will interact with the browser's cache to set request's cache. */
|
|
@@ -309,7 +191,7 @@ export type Client = {} & {
|
|
|
309
191
|
};
|
|
310
192
|
export declare function isClient(value: unknown): value is Client;
|
|
311
193
|
export declare function createClient(options: ClientOptions): Client;
|
|
312
|
-
export declare function cloneClient(client: Client, options: ClientOptions): Client;
|
|
194
|
+
export declare function cloneClient(client: Client, options: Partial<ClientOptions>): Client;
|
|
313
195
|
export declare function getGlobalClient(): Client;
|
|
314
196
|
export declare function setGlobalClient(client: Client): void;
|
|
315
197
|
export declare function restGlobalClient(): void;
|
|
@@ -318,13 +200,28 @@ export declare const ERR_ABORTED: Error;
|
|
|
318
200
|
export declare const ERR_TIMEOUT: Error;
|
|
319
201
|
export declare const ERR_NETWORK: Error;
|
|
320
202
|
export declare const ERR_NOT_FOUND_HANDLER: Error;
|
|
321
|
-
export declare const ERR_TRANSFORM_RESPONSE: Error;
|
|
322
|
-
export declare const ERR_STREAMING_NOT_IMPLEMENTED: Error;
|
|
323
203
|
export declare const ERR_OBSERVE: Error;
|
|
324
204
|
export declare const ERR_NOT_SET_ALIAS: Error;
|
|
325
205
|
export declare const ERR_UNSUPPORTED_FIELD_TYPE: Error;
|
|
326
206
|
export declare const ERR_INVALID_CLIENT: Error;
|
|
327
207
|
export declare const ERR_NOT_FOUND_GLOBAL_CLIENT: Error;
|
|
328
208
|
export declare const ERR_INVALID_HTTP_CONTEXT_TOKEN: Error;
|
|
209
|
+
export declare const ERR_UNKNOWN: Error;
|
|
210
|
+
export declare class HttpErrorResponse extends Error {
|
|
211
|
+
readonly status: number;
|
|
212
|
+
readonly statusText: string;
|
|
213
|
+
readonly url: string | null;
|
|
214
|
+
readonly headers: Headers;
|
|
215
|
+
readonly ok: boolean;
|
|
216
|
+
readonly body: unknown;
|
|
217
|
+
constructor(init: {
|
|
218
|
+
error?: Error | string | unknown;
|
|
219
|
+
status?: number;
|
|
220
|
+
statusText?: string;
|
|
221
|
+
url?: string;
|
|
222
|
+
headers?: Headers;
|
|
223
|
+
body?: unknown;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
329
226
|
|
|
330
227
|
export {};
|
package/{index.js → index.es.js}
RENAMED
|
@@ -1,20 +1,46 @@
|
|
|
1
1
|
// src/error.ts
|
|
2
|
-
function __withErrorCause(err, cause) {
|
|
3
|
-
err.cause = cause;
|
|
4
|
-
return err;
|
|
5
|
-
}
|
|
6
2
|
var ERR_ABORTED = new Error("ERR_ABORTED");
|
|
7
3
|
var ERR_TIMEOUT = new Error("ERR_TIMEOUT");
|
|
8
4
|
var ERR_NETWORK = new Error("ERR_NETWORK");
|
|
9
5
|
var ERR_NOT_FOUND_HANDLER = new Error("ERR_NOT_FOUND_HANDLER");
|
|
10
|
-
var ERR_TRANSFORM_RESPONSE = new Error("ERR_TRANSFORM_RESPONSE");
|
|
11
|
-
var ERR_STREAMING_NOT_IMPLEMENTED = new Error("ERR_STREAMING_NOT_IMPLEMENTED");
|
|
12
6
|
var ERR_OBSERVE = new Error("ERR_OBSERVE");
|
|
13
7
|
var ERR_NOT_SET_ALIAS = new Error("ERR_NOT_SET_ALIAS");
|
|
14
8
|
var ERR_UNSUPPORTED_FIELD_TYPE = new Error("ERR_UNSUPPORTED_FIELD_TYPE");
|
|
15
9
|
var ERR_INVALID_CLIENT = new Error("ERR_INVALID_CLIENT");
|
|
16
10
|
var ERR_NOT_FOUND_GLOBAL_CLIENT = new Error("ERR_NOT_FOUND_GLOBAL_CLIENT");
|
|
17
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
|
+
ok;
|
|
20
|
+
body;
|
|
21
|
+
constructor(init) {
|
|
22
|
+
const status = init.status ?? 0;
|
|
23
|
+
const statusText = init.statusText ?? "";
|
|
24
|
+
const ok = status >= 200 && status < 300;
|
|
25
|
+
const headers = init.headers ?? new Headers;
|
|
26
|
+
const url = init.url ?? null;
|
|
27
|
+
const body = init.body ?? null;
|
|
28
|
+
let message;
|
|
29
|
+
if (ok) {
|
|
30
|
+
message = `Http failure during parsing for ${init.url || "(unknown url)"}`;
|
|
31
|
+
} else {
|
|
32
|
+
message = `Http failure response for ${init.url || "(unknown url)"}: ${init.status} ${init.statusText}`;
|
|
33
|
+
}
|
|
34
|
+
super(message, { cause: init.error });
|
|
35
|
+
super.name = "HttpErrorResponse";
|
|
36
|
+
this.statusText = statusText;
|
|
37
|
+
this.url = url;
|
|
38
|
+
this.headers = headers;
|
|
39
|
+
this.status = status;
|
|
40
|
+
this.ok = ok;
|
|
41
|
+
this.body = body;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
18
44
|
|
|
19
45
|
// src/context.ts
|
|
20
46
|
function makeHttpContextToken(defaultValue) {
|
|
@@ -88,6 +114,10 @@ function field(defaultValue) {
|
|
|
88
114
|
meta.alias.set(4 /* Header */, alias);
|
|
89
115
|
return getter;
|
|
90
116
|
};
|
|
117
|
+
getter.withUrlForm = (alias) => {
|
|
118
|
+
meta.alias.set(7 /* UrlForm */, alias);
|
|
119
|
+
return getter;
|
|
120
|
+
};
|
|
91
121
|
getter.withBody = () => {
|
|
92
122
|
meta.alias.set(6 /* Body */, undefined);
|
|
93
123
|
return getter;
|
|
@@ -141,44 +171,20 @@ function makeInterceptorChain(interceptors) {
|
|
|
141
171
|
}
|
|
142
172
|
|
|
143
173
|
// src/response.ts
|
|
144
|
-
function
|
|
145
|
-
return typeof value === "object" && value !== null && HTTP_RESPONSE in value;
|
|
146
|
-
}
|
|
147
|
-
function isHttpResponseError(value) {
|
|
148
|
-
return isHttpResponse(value) && !value.ok;
|
|
149
|
-
}
|
|
150
|
-
function makeResponse(options) {
|
|
174
|
+
function __makeResponse(options) {
|
|
151
175
|
const status = options.status ?? 0;
|
|
152
176
|
const statusText = options.statusText ?? "";
|
|
153
|
-
const ok = status >= 200 && status < 300;
|
|
154
177
|
const url = options.url ?? "";
|
|
155
178
|
const headers = options.headers ?? new Headers;
|
|
156
179
|
const body = options.body ?? null;
|
|
157
|
-
if (!ok || options.error) {
|
|
158
|
-
const error2 = options.error || new Error(`Http failure response for ${options.url}: ${status} ${statusText}`);
|
|
159
|
-
return {
|
|
160
|
-
ok: false,
|
|
161
|
-
error: error2,
|
|
162
|
-
status,
|
|
163
|
-
statusText,
|
|
164
|
-
url,
|
|
165
|
-
headers,
|
|
166
|
-
body,
|
|
167
|
-
[HTTP_RESPONSE]: null
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
180
|
return {
|
|
171
|
-
ok: true,
|
|
172
|
-
error: null,
|
|
173
181
|
status,
|
|
174
182
|
statusText,
|
|
175
183
|
url,
|
|
176
184
|
headers,
|
|
177
|
-
body
|
|
178
|
-
[HTTP_RESPONSE]: null
|
|
185
|
+
body
|
|
179
186
|
};
|
|
180
187
|
}
|
|
181
|
-
var HTTP_RESPONSE = Symbol("HTTP_RESPONSE");
|
|
182
188
|
|
|
183
189
|
// src/request.ts
|
|
184
190
|
function __serializeBody(body) {
|
|
@@ -186,6 +192,7 @@ function __serializeBody(body) {
|
|
|
186
192
|
case body instanceof FormData:
|
|
187
193
|
case body instanceof Blob:
|
|
188
194
|
case body instanceof ArrayBuffer:
|
|
195
|
+
case body instanceof URLSearchParams:
|
|
189
196
|
case typeof body === "string":
|
|
190
197
|
return body;
|
|
191
198
|
case typeof body === "object":
|
|
@@ -219,7 +226,7 @@ function __detectContentTypeHeader(body) {
|
|
|
219
226
|
return null;
|
|
220
227
|
}
|
|
221
228
|
}
|
|
222
|
-
function
|
|
229
|
+
function __buildFieldDefaultValue(input) {
|
|
223
230
|
if (isField(input)) {
|
|
224
231
|
return input();
|
|
225
232
|
}
|
|
@@ -232,21 +239,26 @@ function __buildFieldValue(input) {
|
|
|
232
239
|
}
|
|
233
240
|
return;
|
|
234
241
|
}
|
|
235
|
-
function defineRequest(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
242
|
+
function defineRequest(method, endpoint) {
|
|
243
|
+
let requiredInput = false;
|
|
244
|
+
let field3;
|
|
245
|
+
let interceptors = [];
|
|
246
|
+
let responseType = "json";
|
|
247
|
+
let context2;
|
|
248
|
+
let observe = "body";
|
|
249
|
+
let withCredentials = false;
|
|
250
|
+
let validators = [];
|
|
251
|
+
let transformResponse;
|
|
252
|
+
const fn = () => {
|
|
241
253
|
let uploadProgress;
|
|
242
254
|
let downloadProgress;
|
|
243
|
-
let abortController;
|
|
244
255
|
let abortSignal;
|
|
245
|
-
const
|
|
246
|
-
|
|
256
|
+
const getInitValue = () => __buildFieldDefaultValue(field3);
|
|
257
|
+
const setUploadProgress = (fn2) => {
|
|
258
|
+
uploadProgress = fn2;
|
|
247
259
|
};
|
|
248
|
-
const setDownloadProgress = (
|
|
249
|
-
downloadProgress =
|
|
260
|
+
const setDownloadProgress = (fn2) => {
|
|
261
|
+
downloadProgress = fn2;
|
|
250
262
|
};
|
|
251
263
|
const doRequest = async (...args) => {
|
|
252
264
|
let input;
|
|
@@ -265,28 +277,30 @@ function defineRequest(options) {
|
|
|
265
277
|
if (requiredInput && !input) {
|
|
266
278
|
throw new Error(`Because the request has input, the first argument must be the input value`);
|
|
267
279
|
}
|
|
280
|
+
if (validators.length > 0) {
|
|
281
|
+
for (const fn2 of validators) {
|
|
282
|
+
fn2(input);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
268
285
|
const timeout = doRequestOptions?.timeout || 0;
|
|
269
286
|
if (doRequestOptions?.abort) {
|
|
270
287
|
abortSignal = doRequestOptions.abort;
|
|
271
288
|
} else if (timeout > 0) {
|
|
272
289
|
abortSignal = AbortSignal.timeout(timeout);
|
|
273
|
-
} else {
|
|
274
|
-
abortController = new AbortController;
|
|
275
|
-
abortSignal = abortController.signal;
|
|
276
290
|
}
|
|
277
291
|
const client2 = isClient(doRequestOptions?.client) ? doRequestOptions.client : getGlobalClient();
|
|
278
292
|
const clientOptions = getClientConfig(client2);
|
|
279
293
|
const req = {
|
|
280
294
|
host: clientOptions?.host,
|
|
281
|
-
method
|
|
282
|
-
endpoint
|
|
295
|
+
method,
|
|
296
|
+
endpoint,
|
|
283
297
|
queryParams: new URLSearchParams,
|
|
284
298
|
headers: new Headers,
|
|
285
299
|
body: undefined,
|
|
286
|
-
withCredentials
|
|
287
|
-
responseType
|
|
288
|
-
context:
|
|
289
|
-
observe
|
|
300
|
+
withCredentials,
|
|
301
|
+
responseType,
|
|
302
|
+
context: context2 || makeHttpContext(),
|
|
303
|
+
observe,
|
|
290
304
|
uploadProgress,
|
|
291
305
|
downloadProgress,
|
|
292
306
|
timeout,
|
|
@@ -297,47 +311,23 @@ function defineRequest(options) {
|
|
|
297
311
|
throw ERR_NOT_FOUND_HANDLER;
|
|
298
312
|
}
|
|
299
313
|
if (requiredInput) {
|
|
300
|
-
await __fillRequestFromField(req,
|
|
301
|
-
}
|
|
302
|
-
if (typeof requestOptions.transformRequest === "function") {
|
|
303
|
-
req.body = requestOptions.transformRequest(input, req);
|
|
304
|
-
}
|
|
305
|
-
const chain = makeInterceptorChain([...clientOptions?.interceptors || [], ...requestOptions?.interceptors || []]);
|
|
306
|
-
let res;
|
|
307
|
-
try {
|
|
308
|
-
res = await chain(req, handler2);
|
|
309
|
-
} catch (error3) {
|
|
310
|
-
if (error3 instanceof DOMException) {
|
|
311
|
-
switch (true) {
|
|
312
|
-
case (error3.name === "AbortError" || error3.code === error3.ABORT_ERR):
|
|
313
|
-
throw ERR_ABORTED;
|
|
314
|
-
case (error3.name === "TimeoutError" || error3.code === error3.TIMEOUT_ERR):
|
|
315
|
-
throw ERR_TIMEOUT;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
throw makeResponse({
|
|
319
|
-
error: __withErrorCause(ERR_NETWORK, error3)
|
|
320
|
-
});
|
|
314
|
+
await __fillRequestFromField(req, field3, input);
|
|
321
315
|
}
|
|
322
|
-
|
|
316
|
+
const chain = makeInterceptorChain([...interceptors]);
|
|
317
|
+
let res = await chain(req, handler2);
|
|
318
|
+
if (typeof transformResponse === "function") {
|
|
323
319
|
try {
|
|
324
|
-
res =
|
|
320
|
+
res = __makeResponse({
|
|
325
321
|
...res,
|
|
326
|
-
body:
|
|
327
|
-
error: undefined
|
|
322
|
+
body: transformResponse(res)
|
|
328
323
|
});
|
|
329
324
|
} catch (error3) {
|
|
330
|
-
throw
|
|
331
|
-
...res,
|
|
332
|
-
error: __withErrorCause(ERR_TRANSFORM_RESPONSE, error3)
|
|
333
|
-
});
|
|
325
|
+
throw new HttpErrorResponse({ error: error3 });
|
|
334
326
|
}
|
|
335
327
|
}
|
|
336
328
|
switch (req.observe) {
|
|
337
329
|
case "body":
|
|
338
330
|
return res.body;
|
|
339
|
-
case "stream":
|
|
340
|
-
throw ERR_STREAMING_NOT_IMPLEMENTED;
|
|
341
331
|
case "response":
|
|
342
332
|
return res;
|
|
343
333
|
default:
|
|
@@ -346,11 +336,45 @@ function defineRequest(options) {
|
|
|
346
336
|
};
|
|
347
337
|
return {
|
|
348
338
|
doRequest,
|
|
349
|
-
|
|
339
|
+
getInitValue,
|
|
350
340
|
setUploadProgress,
|
|
351
341
|
setDownloadProgress
|
|
352
342
|
};
|
|
353
343
|
};
|
|
344
|
+
fn.withField = (value) => {
|
|
345
|
+
field3 = value;
|
|
346
|
+
requiredInput = true;
|
|
347
|
+
return fn;
|
|
348
|
+
};
|
|
349
|
+
fn.withInterceptors = (value) => {
|
|
350
|
+
interceptors = value;
|
|
351
|
+
return fn;
|
|
352
|
+
};
|
|
353
|
+
fn.withContext = (value) => {
|
|
354
|
+
context2 = value;
|
|
355
|
+
return fn;
|
|
356
|
+
};
|
|
357
|
+
fn.withCredentials = (value) => {
|
|
358
|
+
withCredentials = value;
|
|
359
|
+
return fn;
|
|
360
|
+
};
|
|
361
|
+
fn.withValidators = (value) => {
|
|
362
|
+
validators = value;
|
|
363
|
+
return fn;
|
|
364
|
+
};
|
|
365
|
+
fn.withTransformResponse = (value) => {
|
|
366
|
+
transformResponse = value;
|
|
367
|
+
return fn;
|
|
368
|
+
};
|
|
369
|
+
fn.withObserve = (value) => {
|
|
370
|
+
observe = value;
|
|
371
|
+
return fn;
|
|
372
|
+
};
|
|
373
|
+
fn.withResponseType = (value) => {
|
|
374
|
+
responseType = value;
|
|
375
|
+
return fn;
|
|
376
|
+
};
|
|
377
|
+
return fn;
|
|
354
378
|
}
|
|
355
379
|
function __fillUrl(endpoint, params) {
|
|
356
380
|
return endpoint.replace(/:([^\/]+)/g, (_, p1) => {
|
|
@@ -370,34 +394,57 @@ async function __fillRequestFromField(request, fieldOrFieldGroup, input) {
|
|
|
370
394
|
function inputIsObject(input2) {
|
|
371
395
|
return typeof input2 === "object" && input2 !== null;
|
|
372
396
|
}
|
|
397
|
+
function serializeToString(value) {
|
|
398
|
+
switch (true) {
|
|
399
|
+
case Array.isArray(value):
|
|
400
|
+
case (typeof value === "object" && value !== null):
|
|
401
|
+
return JSON.stringify(value);
|
|
402
|
+
case (typeof value === "object" && value === null):
|
|
403
|
+
case typeof value === "boolean":
|
|
404
|
+
case typeof value === "number":
|
|
405
|
+
case typeof value === "string":
|
|
406
|
+
return String(value);
|
|
407
|
+
default:
|
|
408
|
+
throw new Error("Unsupported value type");
|
|
409
|
+
}
|
|
410
|
+
}
|
|
373
411
|
function appendValue(sp, key, value) {
|
|
374
412
|
if (Array.isArray(value)) {
|
|
375
413
|
for (const v of value) {
|
|
376
|
-
sp.append(key,
|
|
414
|
+
sp.append(key, serializeToString(v));
|
|
377
415
|
}
|
|
378
416
|
} else {
|
|
379
|
-
sp.set(key,
|
|
417
|
+
sp.set(key, serializeToString(value));
|
|
380
418
|
}
|
|
381
419
|
return sp;
|
|
382
420
|
}
|
|
383
421
|
function setValue(sp, key, value) {
|
|
384
422
|
if (Array.isArray(value)) {
|
|
385
423
|
for (const v of value) {
|
|
386
|
-
sp
|
|
424
|
+
setValue(sp, key, serializeToString(v));
|
|
387
425
|
}
|
|
388
|
-
} else {
|
|
389
|
-
sp.set(key, String(value));
|
|
390
426
|
}
|
|
427
|
+
sp.set(key, serializeToString(value));
|
|
391
428
|
return sp;
|
|
392
429
|
}
|
|
430
|
+
function getValidValue(value, defaultValue) {
|
|
431
|
+
switch (true) {
|
|
432
|
+
case typeof value === "undefined":
|
|
433
|
+
return defaultValue;
|
|
434
|
+
case (typeof value === "object" && value === null):
|
|
435
|
+
return value;
|
|
436
|
+
default:
|
|
437
|
+
return value;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
393
440
|
if (isField(fieldOrFieldGroup)) {
|
|
394
441
|
let params;
|
|
395
442
|
let queryParams;
|
|
396
443
|
let headers;
|
|
397
444
|
let body = undefined;
|
|
398
|
-
const
|
|
445
|
+
const validValue = getValidValue(input, fieldOrFieldGroup());
|
|
399
446
|
const meta = __getFieldMetadata(fieldOrFieldGroup);
|
|
400
|
-
const err = await doValid([...meta.validators, ...meta.asyncValidator],
|
|
447
|
+
const err = await doValid([...meta.validators, ...meta.asyncValidator], validValue);
|
|
401
448
|
if (err) {
|
|
402
449
|
throw err;
|
|
403
450
|
}
|
|
@@ -407,33 +454,40 @@ async function __fillRequestFromField(request, fieldOrFieldGroup, input) {
|
|
|
407
454
|
if (!aliasName) {
|
|
408
455
|
throw ERR_NOT_SET_ALIAS;
|
|
409
456
|
}
|
|
410
|
-
queryParams = appendValue(new URLSearchParams, aliasName,
|
|
457
|
+
queryParams = appendValue(new URLSearchParams, aliasName, validValue);
|
|
411
458
|
break;
|
|
412
459
|
}
|
|
413
460
|
case 3 /* Param */: {
|
|
414
461
|
if (!aliasName) {
|
|
415
462
|
throw ERR_NOT_SET_ALIAS;
|
|
416
463
|
}
|
|
417
|
-
params = setValue(new Map, aliasName,
|
|
464
|
+
params = setValue(new Map, aliasName, validValue);
|
|
418
465
|
break;
|
|
419
466
|
}
|
|
420
467
|
case 4 /* Header */: {
|
|
421
468
|
if (!aliasName) {
|
|
422
469
|
throw ERR_NOT_SET_ALIAS;
|
|
423
470
|
}
|
|
424
|
-
headers = appendValue(new Headers, aliasName,
|
|
471
|
+
headers = appendValue(new Headers, aliasName, validValue);
|
|
425
472
|
break;
|
|
426
473
|
}
|
|
427
474
|
case 5 /* Form */: {
|
|
428
475
|
if (!aliasName) {
|
|
429
476
|
throw ERR_NOT_SET_ALIAS;
|
|
430
477
|
}
|
|
431
|
-
body = appendValue(new FormData, aliasName,
|
|
478
|
+
body = appendValue(new FormData, aliasName, validValue);
|
|
479
|
+
break;
|
|
480
|
+
}
|
|
481
|
+
case 7 /* UrlForm */: {
|
|
482
|
+
if (!aliasName) {
|
|
483
|
+
throw ERR_NOT_SET_ALIAS;
|
|
484
|
+
}
|
|
485
|
+
body = appendValue(new URLSearchParams, aliasName, validValue);
|
|
432
486
|
break;
|
|
433
487
|
}
|
|
434
488
|
case 1 /* Json */:
|
|
435
489
|
case 6 /* Body */:
|
|
436
|
-
body =
|
|
490
|
+
body = validValue;
|
|
437
491
|
break;
|
|
438
492
|
}
|
|
439
493
|
}
|
|
@@ -449,26 +503,30 @@ async function __fillRequestFromField(request, fieldOrFieldGroup, input) {
|
|
|
449
503
|
let params = new Map;
|
|
450
504
|
let queryParams = new URLSearchParams;
|
|
451
505
|
let headers = new Headers;
|
|
506
|
+
let urlForm = new URLSearchParams;
|
|
452
507
|
let formData = new FormData;
|
|
453
508
|
const json = {};
|
|
454
509
|
let body = undefined;
|
|
510
|
+
let lastBodyField;
|
|
455
511
|
for (const [propertyKey, field3] of Object.entries(fieldOrFieldGroup)) {
|
|
456
512
|
const meta = __getFieldMetadata(field3);
|
|
457
513
|
for (const [type, aliasName] of meta.alias) {
|
|
458
514
|
const valueKey = aliasName || propertyKey;
|
|
459
|
-
const value = input[propertyKey]
|
|
515
|
+
const value = getValidValue(input[propertyKey], field3());
|
|
460
516
|
const err = await doValid([...meta.validators, ...meta.asyncValidator], value);
|
|
461
517
|
if (err) {
|
|
462
518
|
throw err;
|
|
463
519
|
}
|
|
464
520
|
switch (type) {
|
|
465
|
-
case 1 /* Json */:
|
|
521
|
+
case 1 /* Json */: {
|
|
466
522
|
Object.defineProperty(json, valueKey, {
|
|
467
523
|
value,
|
|
468
524
|
writable: true,
|
|
469
525
|
enumerable: true
|
|
470
526
|
});
|
|
527
|
+
lastBodyField = 1 /* Json */;
|
|
471
528
|
break;
|
|
529
|
+
}
|
|
472
530
|
case 2 /* Query */:
|
|
473
531
|
queryParams = appendValue(queryParams, valueKey, value);
|
|
474
532
|
break;
|
|
@@ -478,24 +536,40 @@ async function __fillRequestFromField(request, fieldOrFieldGroup, input) {
|
|
|
478
536
|
case 4 /* Header */:
|
|
479
537
|
headers = appendValue(headers, valueKey, value);
|
|
480
538
|
break;
|
|
481
|
-
case 5 /* Form */:
|
|
539
|
+
case 5 /* Form */: {
|
|
482
540
|
formData = appendValue(formData, valueKey, value);
|
|
541
|
+
lastBodyField = 5 /* Form */;
|
|
483
542
|
break;
|
|
484
|
-
|
|
543
|
+
}
|
|
544
|
+
case 7 /* UrlForm */: {
|
|
545
|
+
urlForm = appendValue(urlForm, valueKey, value);
|
|
546
|
+
lastBodyField = 7 /* UrlForm */;
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
case 6 /* Body */: {
|
|
485
550
|
body = value;
|
|
551
|
+
lastBodyField = 6 /* Body */;
|
|
486
552
|
break;
|
|
553
|
+
}
|
|
487
554
|
}
|
|
488
555
|
}
|
|
489
556
|
}
|
|
490
557
|
request.endpoint = __fillUrl(request.endpoint, params);
|
|
491
558
|
request.queryParams = queryParams;
|
|
492
559
|
request.headers = headers;
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
560
|
+
switch (lastBodyField) {
|
|
561
|
+
case 6 /* Body */:
|
|
562
|
+
request.body = body;
|
|
563
|
+
break;
|
|
564
|
+
case 5 /* Form */:
|
|
565
|
+
request.body = formData;
|
|
566
|
+
break;
|
|
567
|
+
case 7 /* UrlForm */:
|
|
568
|
+
request.body = urlForm;
|
|
569
|
+
break;
|
|
570
|
+
case 1 /* Json */:
|
|
571
|
+
request.body = json;
|
|
572
|
+
break;
|
|
499
573
|
}
|
|
500
574
|
return;
|
|
501
575
|
}
|
|
@@ -503,7 +577,7 @@ async function __fillRequestFromField(request, fieldOrFieldGroup, input) {
|
|
|
503
577
|
}
|
|
504
578
|
|
|
505
579
|
// src/handler/util.ts
|
|
506
|
-
function
|
|
580
|
+
function __getContentLength(headers) {
|
|
507
581
|
const value = headers.get("Content-Length");
|
|
508
582
|
if (!value) {
|
|
509
583
|
return 0;
|
|
@@ -514,10 +588,10 @@ function getContentLength(headers) {
|
|
|
514
588
|
}
|
|
515
589
|
return num;
|
|
516
590
|
}
|
|
517
|
-
function
|
|
591
|
+
function __getContentType(headers) {
|
|
518
592
|
return headers.get("Content-Type") || "";
|
|
519
593
|
}
|
|
520
|
-
function
|
|
594
|
+
function __parseBody(params) {
|
|
521
595
|
const { request, content, contentType } = params;
|
|
522
596
|
const responseType = request.responseType;
|
|
523
597
|
if (!responseType) {
|
|
@@ -542,7 +616,7 @@ function parseBody(params) {
|
|
|
542
616
|
return null;
|
|
543
617
|
}
|
|
544
618
|
}
|
|
545
|
-
function
|
|
619
|
+
function __concatChunks(chunks, totalLength) {
|
|
546
620
|
const chunksAll = new Uint8Array(totalLength);
|
|
547
621
|
let position = 0;
|
|
548
622
|
for (const chunk of chunks) {
|
|
@@ -582,10 +656,23 @@ function __createRequest(request2) {
|
|
|
582
656
|
async function fetchHandler(httpRequest) {
|
|
583
657
|
const downloadProgress = httpRequest.downloadProgress;
|
|
584
658
|
const request2 = __createRequest(httpRequest);
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
659
|
+
let response3;
|
|
660
|
+
try {
|
|
661
|
+
response3 = await (globalThis || window).fetch(request2);
|
|
662
|
+
} catch (error4) {
|
|
663
|
+
if (error4 instanceof DOMException) {
|
|
664
|
+
switch (true) {
|
|
665
|
+
case (error4.name === "AbortError" || error4.code === error4.ABORT_ERR):
|
|
666
|
+
throw new HttpErrorResponse({ error: ERR_ABORTED });
|
|
667
|
+
case (error4.name === "TimeoutError" || error4.code === error4.TIMEOUT_ERR):
|
|
668
|
+
throw new HttpErrorResponse({ error: ERR_TIMEOUT });
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
throw new HttpErrorResponse({ error: error4 });
|
|
672
|
+
}
|
|
673
|
+
const { ok, headers, status, statusText, url } = response3;
|
|
674
|
+
const contentLength = __getContentLength(headers);
|
|
675
|
+
const contentType = __getContentType(headers);
|
|
589
676
|
let body = null;
|
|
590
677
|
if (response3.body) {
|
|
591
678
|
const chunks = [];
|
|
@@ -604,14 +691,33 @@ async function fetchHandler(httpRequest) {
|
|
|
604
691
|
total: contentLength
|
|
605
692
|
});
|
|
606
693
|
}
|
|
607
|
-
const chunksAll =
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
694
|
+
const chunksAll = __concatChunks(chunks, receivedLength);
|
|
695
|
+
try {
|
|
696
|
+
body = __parseBody({
|
|
697
|
+
request: httpRequest,
|
|
698
|
+
content: chunksAll,
|
|
699
|
+
contentType
|
|
700
|
+
});
|
|
701
|
+
} catch (error4) {
|
|
702
|
+
throw new HttpErrorResponse({
|
|
703
|
+
error: error4,
|
|
704
|
+
status,
|
|
705
|
+
statusText,
|
|
706
|
+
headers,
|
|
707
|
+
url
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
if (!ok) {
|
|
712
|
+
throw new HttpErrorResponse({
|
|
713
|
+
status,
|
|
714
|
+
statusText,
|
|
715
|
+
headers,
|
|
716
|
+
url,
|
|
717
|
+
body
|
|
612
718
|
});
|
|
613
719
|
}
|
|
614
|
-
return
|
|
720
|
+
return __makeResponse({
|
|
615
721
|
url,
|
|
616
722
|
status,
|
|
617
723
|
statusText,
|
|
@@ -746,9 +852,6 @@ var pattern = (pattern2) => {
|
|
|
746
852
|
if (typeof value !== "string") {
|
|
747
853
|
return new Error("invalid string");
|
|
748
854
|
}
|
|
749
|
-
if (typeof pattern2 === "string") {
|
|
750
|
-
pattern2 = new RegExp(pattern2);
|
|
751
|
-
}
|
|
752
855
|
if (!pattern2.test(value)) {
|
|
753
856
|
return new Error("pattern");
|
|
754
857
|
}
|
|
@@ -766,11 +869,8 @@ export {
|
|
|
766
869
|
min,
|
|
767
870
|
maxLength,
|
|
768
871
|
max,
|
|
769
|
-
makeResponse,
|
|
770
872
|
makeHttpContextToken,
|
|
771
873
|
makeHttpContext,
|
|
772
|
-
isHttpResponseError,
|
|
773
|
-
isHttpResponse,
|
|
774
874
|
isHttpContextToken,
|
|
775
875
|
isFieldGroup,
|
|
776
876
|
isField,
|
|
@@ -784,11 +884,11 @@ export {
|
|
|
784
884
|
cloneClient,
|
|
785
885
|
basicAuthInterceptor,
|
|
786
886
|
asyncValidatorField,
|
|
887
|
+
HttpErrorResponse,
|
|
787
888
|
FETCH_CONFIG_KEY,
|
|
788
889
|
ERR_UNSUPPORTED_FIELD_TYPE,
|
|
789
|
-
|
|
890
|
+
ERR_UNKNOWN,
|
|
790
891
|
ERR_TIMEOUT,
|
|
791
|
-
ERR_STREAMING_NOT_IMPLEMENTED,
|
|
792
892
|
ERR_OBSERVE,
|
|
793
893
|
ERR_NOT_SET_ALIAS,
|
|
794
894
|
ERR_NOT_FOUND_HANDLER,
|
package/index.es.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
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};
|
package/package.json
CHANGED
package/index.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function U(t,n){return t.cause=n,t}var l=new Error("ERR_ABORTED"),h=new Error("ERR_TIMEOUT"),L=new Error("ERR_NETWORK"),P=new Error("ERR_NOT_FOUND_HANDLER"),D=new Error("ERR_TRANSFORM_RESPONSE"),M=new Error("ERR_STREAMING_NOT_IMPLEMENTED"),d=new Error("ERR_OBSERVE"),m=new Error("ERR_NOT_SET_ALIAS"),O=new Error("ERR_UNSUPPORTED_FIELD_TYPE"),g=new Error("ERR_INVALID_CLIENT"),S=new Error("ERR_NOT_FOUND_GLOBAL_CLIENT"),u=new Error("ERR_INVALID_HTTP_CONTEXT_TOKEN");function X(t){return Object.defineProperty(t,z,{value:t}),t}function $(t){return typeof t==="function"&&z in t}function J(){const t=new Map;return{set(n,r){if(!$(n))throw u;return t.set(n,r),this},get(n){if(!$(n))throw u;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 z=Symbol("HttpContextToken");function it(t){const n={alias:new Map,validators:[],asyncValidator:[]},r=()=>t;return Object.defineProperty(r,K,{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.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 Q(t){return t[K]}function pt(t,n){for(let r of t){const o=r(n);if(o)throw o}}async function ct(t,n){for(let r of t){const o=await r(n);if(o)throw o}}function A(t){return!!t&&typeof t==="function"&&K in t}function y(t){return!!t&&typeof t==="object"&&Object.entries(t).every(([,n])=>A(n))}var K=Symbol("field");var ft=void 0;var G=()=>ft;function b(t){return t.reduceRight((n,r)=>{return(o,T)=>r(o,(x)=>n(x,T))},(n,r)=>r(n))}function v(t){return typeof t==="object"&&t!==null&&j in t}function Rt(t){return v(t)&&!t.ok}function _(t){const n=t.status??0,r=t.statusText??"",o=n>=200&&n<300,T=t.url??"",x=t.headers??new Headers,a=t.body??null;if(!o||t.error)return{ok:!1,error:t.error||new Error(`Http failure response for ${t.url}: ${n} ${r}`),status:n,statusText:r,url:T,headers:x,body:a,[j]:null};return{ok:!0,error:null,status:n,statusText:r,url:T,headers:x,body:a,[j]:null}}var j=Symbol("HTTP_RESPONSE");function tt(t){switch(!0){case t instanceof FormData:case t instanceof Blob:case t instanceof ArrayBuffer: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 nt(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 Ht(t){if(A(t))return t();if(y(t)){const n={};for(let[r,o]of Object.entries(t))n[r]=o();return n}return}function wt(t){const n={...t},r=!!n.input;return()=>{let o,T,x,a;const E=(e)=>{o=e},i=(e)=>{T=e};return{doRequest:async(...e)=>{let c,f;switch(e.length){case 1:{f=e[0];break}case 2:{c=e[0],f=e[1];break}}if(r&&!c)throw new Error("Because the request has input, the first argument must be the input value");const w=f?.timeout||0;if(f?.abort)a=f.abort;else if(w>0)a=AbortSignal.timeout(w);else x=new AbortController,a=x.signal;const F=B(f?.client)?f.client:Y(),R=W(F),k={host:R?.host,method:n.method,endpoint:n.endpoint,queryParams:new URLSearchParams,headers:new Headers,body:void 0,withCredentials:n.withCredentials,responseType:n.responseType??"json",context:n.context||J(),observe:n.observe??"body",uploadProgress:o,downloadProgress:T,timeout:w,abort:a},I=f?.handler||R?.handler||G();if(!I)throw P;if(r)await st(k,n.input,c);if(typeof n.transformRequest==="function")k.body=n.transformRequest(c,k);const N=b([...R?.interceptors||[],...n?.interceptors||[]]);let H;try{H=await N(k,I)}catch(s){if(s instanceof DOMException)switch(!0){case(s.name==="AbortError"||s.code===s.ABORT_ERR):throw l;case(s.name==="TimeoutError"||s.code===s.TIMEOUT_ERR):throw h}throw _({error:U(L,s)})}if(typeof n.transformResponse==="function")try{H=_({...H,body:n.transformResponse(H),error:void 0})}catch(s){throw _({...H,error:U(D,s)})}switch(k.observe){case"body":return H.body;case"stream":throw M;case"response":return H;default:throw d}},inputValue:Ht(n.input),setUploadProgress:E,setDownloadProgress:i}}}function q(t,n){return t.replace(/:([^\/]+)/g,(r,o)=>{return n.get(o)??"undefined"})}async function st(t,n,r){async function o(E,i){for(let p of E){const e=await p(i);if(e)return e}return}function T(E){return typeof E==="object"&&E!==null}function x(E,i,p){if(Array.isArray(p))for(let e of p)E.append(i,String(e));else E.set(i,String(p));return E}function a(E,i,p){if(Array.isArray(p))for(let e of p)E.set(i,String(e));else E.set(i,String(p));return E}if(A(n)){let E,i,p,e=void 0;const c=r??n(),f=Q(n),w=await o([...f.validators,...f.asyncValidator],c);if(w)throw w;for(let[F,R]of f.alias)switch(F){case 2:{if(!R)throw m;i=x(new URLSearchParams,R,c);break}case 3:{if(!R)throw m;E=a(new Map,R,c);break}case 4:{if(!R)throw m;p=x(new Headers,R,c);break}case 5:{if(!R)throw m;e=x(new FormData,R,c);break}case 1:case 6:e=c;break}if(E)t.endpoint=q(t.endpoint,E);t.queryParams=i,t.headers=p,t.body=e;return}if(y(n)&&T(r)){let E=new Map,i=new URLSearchParams,p=new Headers,e=new FormData;const c={};let f=void 0;for(let[w,F]of Object.entries(n)){const R=Q(F);for(let[k,I]of R.alias){const N=I||w,H=r[w]||F(),s=await o([...R.validators,...R.asyncValidator],H);if(s)throw s;switch(k){case 1:Object.defineProperty(c,N,{value:H,writable:!0,enumerable:!0});break;case 2:i=x(i,N,H);break;case 3:E=a(E,N,H);break;case 4:p=x(p,N,H);break;case 5:e=x(e,N,H);break;case 6:f=H;break}}}if(t.endpoint=q(t.endpoint,E),t.queryParams=i,t.headers=p,f)t.body=f;else if(Array.from(e.keys()).length>0)t.body=e;else if(Object.keys(c).length)t.body=c;return}throw O}function rt(t){const n=t.get("Content-Length");if(!n)return 0;const r=Number(n);if(isNaN(r))return 0;return r}function ot(t){return t.get("Content-Type")||""}function et(t){const{request:n,content:r,contentType:o}=t,T=n.responseType;if(!T)return null;switch(T){case"json":{const x=new TextDecoder().decode(r);if(x==="")return null;return JSON.parse(x)}case"text":return new TextDecoder().decode(r);case"blob":return new Blob([r],{type:o});case"arraybuffer":return r.buffer;default:return null}}function Tt(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 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 x=nt(t.body);if(x)r.set("Content-Type",x)}if(!r.has("Accept"))r.set("Accept","application/json, text/plain, */*");const o=t.withCredentials?"include":void 0,T=t.context?.get(xt)||{};return new Request(n,{...T,headers:r,method:t.method,body:tt(t.body),signal:t.abort,credentials:o})}async function Z(t){const n=t.downloadProgress,r=at(t),o=await(globalThis||window).fetch(r),{headers:T,status:x,statusText:a,url:E}=o,i=rt(T),p=ot(T);let e=null;if(o.body){const c=[],f=o.body.getReader();let w=0;while(!0){const{done:R,value:k}=await f.read();if(R)break;c.push(k),w+=k.length,n?.({lengthComputable:i>0,loaded:w,total:i})}const F=Tt(c,w);e=et({request:t,content:F,contentType:p})}return _({url:E,status:x,statusText:a,headers:T,body:e})}var xt=X(()=>({}));function B(t){return typeof t==="object"&&t!==null&&V in t}function W(t){if(!B(t))throw g;return t[V]}function Et(t){const n={host:t.host,interceptors:t.interceptors??[],handler:t.handler||Z};return{[V]:n}}function kt(t,n){const o={...W(t),...n};return{[V]:o}}function Y(){if(!C)throw S;return C}function Ft(t){C=t}function Nt(){C=void 0}function _t(t){C=Et(t)}var V=Symbol("Client"),C;function mt(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=(T)=>o(`${T.username}:${T.password}`)}return(o,T)=>{const x=o.headers||new Headers;return x.set("Authorization",`Basic ${r(t())}`),o.headers=x,T(o)}}var At=(t)=>{if(!t)return new Error("required");return null},Ct=(t)=>{if(typeof t!=="boolean"||!t)return new Error("requiredTrue");return null},It=(t)=>{return(n)=>{if(typeof n!=="string")return new Error("invalid string");if(n.length<t)return new Error(`minLength ${t}`);return null}},ut=(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}},Bt=(t)=>{return(n)=>{if(typeof n!=="number"||isNaN(n))return new Error("invalid number");if(n>t)return new Error(`maxLength ${t}`);return null}},Vt=(t)=>{return(n)=>{if(typeof n!=="string")return new Error("invalid string");if(typeof t==="string")t=new RegExp(t);if(!t.test(n))return new Error("pattern");return null}};export{pt as validatorField,Ft as setGlobalClient,Nt as restGlobalClient,Ct as requiredTrue,At as required,Vt as pattern,It as minLength,yt as min,ut as maxLength,Bt as max,_ as makeResponse,X as makeHttpContextToken,J as makeHttpContext,Rt as isHttpResponseError,v as isHttpResponse,$ as isHttpContextToken,y as isFieldGroup,A as isField,B as isClient,Y as getGlobalClient,it as field,Z as fetchHandler,wt as defineRequest,_t as createGlobalClient,Et as createClient,kt as cloneClient,mt as basicAuthInterceptor,ct as asyncValidatorField,xt as FETCH_CONFIG_KEY,O as ERR_UNSUPPORTED_FIELD_TYPE,D as ERR_TRANSFORM_RESPONSE,h as ERR_TIMEOUT,M as ERR_STREAMING_NOT_IMPLEMENTED,d as ERR_OBSERVE,m as ERR_NOT_SET_ALIAS,P as ERR_NOT_FOUND_HANDLER,S as ERR_NOT_FOUND_GLOBAL_CLIENT,L as ERR_NETWORK,u as ERR_INVALID_HTTP_CONTEXT_TOKEN,g as ERR_INVALID_CLIENT,l as ERR_ABORTED};
|