@defjs/core 0.0.0-test-002 → 0.0.0-test-004
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 +292 -226
- package/index.js +257 -289
- package/index.min.js +587 -0
- package/package.json +1 -4
- package/index.es.min.js +0 -1
package/index.d.ts
CHANGED
|
@@ -1,227 +1,293 @@
|
|
|
1
|
-
declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export type
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export declare
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
export declare function
|
|
58
|
-
|
|
59
|
-
export type
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
export
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
export
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
export
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
export
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
export
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
export declare
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
1
|
+
export declare type AsyncValidatorFn<T = unknown> = (value: T) => Promise<void>;
|
|
2
|
+
|
|
3
|
+
export declare function basicAuthInterceptor(fn: () => BasicCredential, options?: BasicAuthInterceptorOptions): InterceptorFn;
|
|
4
|
+
|
|
5
|
+
export declare type BasicAuthInterceptorOptions = {
|
|
6
|
+
encode?: (credential: BasicCredential) => string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
declare type BasicCredential = {
|
|
10
|
+
username: string;
|
|
11
|
+
password: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
declare const CLIENT: unique symbol;
|
|
15
|
+
|
|
16
|
+
export declare type Client = {
|
|
17
|
+
readonly [CLIENT]: ClientConfig;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export declare interface ClientConfig {
|
|
21
|
+
host: string;
|
|
22
|
+
strict: boolean;
|
|
23
|
+
handler: HttpHandler;
|
|
24
|
+
interceptors?: InterceptorFn[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export declare interface ClientOptions {
|
|
28
|
+
host: string;
|
|
29
|
+
/** Default: true */
|
|
30
|
+
strict?: boolean;
|
|
31
|
+
interceptors?: InterceptorFn[];
|
|
32
|
+
handler?: HttpHandler;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export declare function cloneClient(client: Client, options: Partial<ClientOptions>): Client;
|
|
36
|
+
|
|
37
|
+
export declare function createClient(options: ClientOptions): Client;
|
|
38
|
+
|
|
39
|
+
export declare function createGlobalClient(options: ClientOptions): void;
|
|
40
|
+
|
|
41
|
+
declare interface DefineRequest<Input extends Field<any> | Record<PropertyKey, Field<any>> | undefined = undefined, Output = unknown, Observe extends 'body' | 'response' = 'body'> {
|
|
42
|
+
(): UseRequestFn<Input, Output, Observe>;
|
|
43
|
+
withField<I extends Field<any> | Record<PropertyKey, Field<any>>>(value: I): DefineRequest<I, Output, Observe>;
|
|
44
|
+
withInterceptors(value: InterceptorFn[]): DefineRequest<Input, Output, Observe>;
|
|
45
|
+
withContext(value: HttpContext): DefineRequest<Input, Output, Observe>;
|
|
46
|
+
withCredentials(value: boolean): DefineRequest<Input, Output, Observe>;
|
|
47
|
+
withValidators(value: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[]): DefineRequest<Input, Output, Observe>;
|
|
48
|
+
withTransformResponse<O>(fn: TransformResponseFn<O>): DefineRequest<Input, O, Observe>;
|
|
49
|
+
withObserve(value: 'body'): DefineRequest<Input, Output, 'body'>;
|
|
50
|
+
withObserve(value: 'response'): DefineRequest<Input, Output, 'response'>;
|
|
51
|
+
withResponseType(value: 'json'): DefineRequest<Input, Output, Observe>;
|
|
52
|
+
withResponseType(value: 'text'): DefineRequest<Input, string, Observe>;
|
|
53
|
+
withResponseType(value: 'blob'): DefineRequest<Input, Blob, Observe>;
|
|
54
|
+
withResponseType(value: 'arraybuffer'): DefineRequest<Input, ArrayBuffer, Observe>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export declare function defineRequest<Output>(method: string, endpoint: string): DefineRequest<undefined, Output>;
|
|
58
|
+
|
|
59
|
+
export declare type DoRequestOptions = {
|
|
60
|
+
abort?: AbortSignal;
|
|
61
|
+
handler?: HttpHandler;
|
|
62
|
+
client?: Client;
|
|
63
|
+
timeout?: number;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export declare function doValid<T>(validators: (ValidatorFn<T> | AsyncValidatorFn<T>)[], value: T): Promise<void>;
|
|
67
|
+
|
|
68
|
+
export declare const ERR_ABORTED: Error;
|
|
69
|
+
|
|
70
|
+
export declare const ERR_INVALID_CLIENT: Error;
|
|
71
|
+
|
|
72
|
+
export declare const ERR_INVALID_HTTP_CONTEXT_TOKEN: Error;
|
|
73
|
+
|
|
74
|
+
export declare const ERR_NETWORK: Error;
|
|
75
|
+
|
|
76
|
+
export declare const ERR_NOT_FOUND_GLOBAL_CLIENT: Error;
|
|
77
|
+
|
|
78
|
+
export declare const ERR_NOT_FOUND_HANDLER: Error;
|
|
79
|
+
|
|
80
|
+
export declare const ERR_NOT_SET_ALIAS: Error;
|
|
81
|
+
|
|
82
|
+
export declare const ERR_OBSERVE: Error;
|
|
83
|
+
|
|
84
|
+
export declare const ERR_TIMEOUT: Error;
|
|
85
|
+
|
|
86
|
+
export declare const ERR_UNKNOWN: Error;
|
|
87
|
+
|
|
88
|
+
export declare const ERR_UNSUPPORTED_FIELD_TYPE: Error;
|
|
89
|
+
|
|
90
|
+
export declare function fetchHandler(httpRequest: HttpRequest): Promise<HttpResponse<unknown>>;
|
|
91
|
+
|
|
92
|
+
declare const FIELD: unique symbol;
|
|
93
|
+
|
|
94
|
+
export declare type Field<T = undefined> = (() => T) & {
|
|
95
|
+
withJson(alias?: string): Field<T>;
|
|
96
|
+
withForm(alias?: string): Field<T>;
|
|
97
|
+
withQuery(alias?: string): Field<T>;
|
|
98
|
+
withParam(alias?: string): Field<T>;
|
|
99
|
+
withHeader(alias?: string): Field<T>;
|
|
100
|
+
withUrlForm(alias?: string): Field<T>;
|
|
101
|
+
withBody(): Field<T>;
|
|
102
|
+
withValidators(...fn: ValidatorFn<T>[]): Field<T>;
|
|
103
|
+
withAsyncValidators(...fn: AsyncValidatorFn<T>[]): Field<T>;
|
|
104
|
+
readonly [FIELD]: FieldMetadata<T>;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export declare function field(): Field;
|
|
108
|
+
|
|
109
|
+
export declare function field<T>(): Field<T | undefined>;
|
|
110
|
+
|
|
111
|
+
export declare function field<T>(defaultValue: T): Field<T>;
|
|
112
|
+
|
|
113
|
+
declare interface FieldMetadata<T = undefined> {
|
|
114
|
+
required: boolean;
|
|
115
|
+
alias: Map<FieldType, string | undefined>;
|
|
116
|
+
validators: ValidatorFn<T>[];
|
|
117
|
+
asyncValidator: AsyncValidatorFn<T>[];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
declare enum FieldType {
|
|
121
|
+
Json = 0,
|
|
122
|
+
Query = 1,
|
|
123
|
+
Param = 2,
|
|
124
|
+
Header = 3,
|
|
125
|
+
Form = 4,
|
|
126
|
+
Body = 5,
|
|
127
|
+
UrlForm = 6
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export declare function getGlobalClient(): Client;
|
|
131
|
+
|
|
132
|
+
declare const HTTP_CONTEXT: unique symbol;
|
|
133
|
+
|
|
134
|
+
declare const HTTP_CONTEXT_TOKEN: unique symbol;
|
|
135
|
+
|
|
136
|
+
export declare type HttpContext = {
|
|
137
|
+
set<T>(token: HttpContextToken<T>, value: T): HttpContext;
|
|
138
|
+
get<T>(token: HttpContextToken<T>): T;
|
|
139
|
+
del(token: HttpContextToken<unknown>): HttpContext;
|
|
140
|
+
has(token: HttpContextToken<unknown>): boolean;
|
|
141
|
+
keys(): IterableIterator<HttpContextToken<unknown>>;
|
|
142
|
+
get length(): number;
|
|
143
|
+
readonly [HTTP_CONTEXT]: Map<HttpContextToken<unknown>, unknown>;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export declare type HttpContextToken<T> = (() => T) & {
|
|
147
|
+
readonly [HTTP_CONTEXT_TOKEN]: () => T;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export declare class HttpErrorResponse extends Error {
|
|
151
|
+
readonly status: number;
|
|
152
|
+
readonly statusText: string;
|
|
153
|
+
readonly url: string;
|
|
154
|
+
readonly headers: Headers;
|
|
155
|
+
readonly body: unknown;
|
|
156
|
+
constructor(init?: {
|
|
157
|
+
error?: Error | string | unknown;
|
|
158
|
+
status?: number;
|
|
159
|
+
statusText?: string;
|
|
160
|
+
url?: string;
|
|
161
|
+
headers?: Headers;
|
|
162
|
+
body?: unknown;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export declare type HttpHandler = (req: HttpRequest) => Promise<HttpResponse<unknown>>;
|
|
167
|
+
|
|
168
|
+
export declare interface HttpProgressEvent {
|
|
169
|
+
/**
|
|
170
|
+
* Indicates whether the resources associated with Progress have a computable length.
|
|
171
|
+
* Otherwise, the Progress.total attribute will be a meaningless value.
|
|
172
|
+
*/
|
|
173
|
+
readonly lengthComputable: boolean;
|
|
174
|
+
/** Indicates the workload of the underlying process. */
|
|
175
|
+
readonly loaded: number;
|
|
176
|
+
/**
|
|
177
|
+
* The total size of the data being processed or transmitted.
|
|
178
|
+
* If the Progress.lengthComputable attribute is false, this value is meaningless and should be ignored.
|
|
179
|
+
*/
|
|
180
|
+
readonly total: number;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export declare type HttpProgressFn = (event: HttpProgressEvent) => void;
|
|
184
|
+
|
|
185
|
+
export declare interface HttpRequest {
|
|
186
|
+
host?: string;
|
|
187
|
+
method: string;
|
|
188
|
+
endpoint: string;
|
|
189
|
+
body?: Blob | ArrayBuffer | FormData | URLSearchParams | object | string | number | boolean | null;
|
|
190
|
+
headers?: Headers;
|
|
191
|
+
queryParams?: URLSearchParams;
|
|
192
|
+
/** default:json */
|
|
193
|
+
responseType?: HttpResponseType;
|
|
194
|
+
context?: HttpContext;
|
|
195
|
+
timeout?: number;
|
|
196
|
+
withCredentials?: boolean;
|
|
197
|
+
/** when use fetch handler, no upload progress */
|
|
198
|
+
uploadProgress?: HttpProgressFn;
|
|
199
|
+
downloadProgress?: HttpProgressFn;
|
|
200
|
+
/**
|
|
201
|
+
* default:body
|
|
202
|
+
*/
|
|
203
|
+
observe?: 'body' | 'response';
|
|
204
|
+
abort?: AbortSignal;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export declare type HttpResponse<R> = {
|
|
208
|
+
readonly url: string;
|
|
209
|
+
readonly status: number;
|
|
210
|
+
readonly statusText: string;
|
|
211
|
+
readonly headers: Headers;
|
|
212
|
+
readonly body: R | null;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export declare type HttpResponseBody = string | ArrayBuffer | Blob | object | null;
|
|
216
|
+
|
|
217
|
+
export declare type HttpResponseType = 'arraybuffer' | 'blob' | 'json' | 'text';
|
|
218
|
+
|
|
219
|
+
export declare type InterceptorFn = (req: HttpRequest, next: HttpHandler) => Promise<HttpResponse<unknown>>;
|
|
220
|
+
|
|
221
|
+
export declare function isClient(value: unknown): value is Client;
|
|
222
|
+
|
|
223
|
+
export declare function isField(value: unknown): value is Field;
|
|
224
|
+
|
|
225
|
+
export declare function isFieldGroup(value: unknown): value is Record<PropertyKey, Field>;
|
|
226
|
+
|
|
227
|
+
export declare function isHttpContextToken(value: unknown): value is HttpContextToken<unknown>;
|
|
228
|
+
|
|
229
|
+
export declare function makeHttpContext(): HttpContext;
|
|
230
|
+
|
|
231
|
+
export declare function makeHttpContext(entries?: readonly (readonly [HttpContextToken<unknown>, unknown])[]): HttpContext;
|
|
232
|
+
|
|
233
|
+
export declare function makeHttpContext(context?: HttpContext): HttpContext;
|
|
234
|
+
|
|
235
|
+
export declare function makeHttpContextToken<T>(defaultValue: () => T): HttpContextToken<T>;
|
|
236
|
+
|
|
237
|
+
export declare type MakeResponseOptions<R> = {
|
|
238
|
+
status?: number;
|
|
239
|
+
statusText?: string;
|
|
240
|
+
url?: string;
|
|
241
|
+
headers?: Headers;
|
|
242
|
+
body?: R | null;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
export declare const max: (max: number) => ValidatorFn;
|
|
246
|
+
|
|
247
|
+
export declare const maxLength: (max: number) => ValidatorFn;
|
|
248
|
+
|
|
249
|
+
export declare const min: (min: number) => ValidatorFn;
|
|
250
|
+
|
|
251
|
+
export declare const minLength: (min: number) => ValidatorFn;
|
|
252
|
+
|
|
253
|
+
declare type ObserveType<Observe, Output> = Observe extends 'body' ? Output : Observe extends 'response' ? HttpResponse<Output> : never;
|
|
254
|
+
|
|
255
|
+
export declare const pattern: (pattern: RegExp) => ValidatorFn;
|
|
256
|
+
|
|
257
|
+
export declare type RequestInputValue<T> = T extends Field<infer V> ? V : T extends {
|
|
258
|
+
[K in keyof T]: Field<any>;
|
|
259
|
+
} ? {
|
|
260
|
+
[K in keyof T]: RequestInputValue<T[K]>;
|
|
261
|
+
} : never;
|
|
262
|
+
|
|
263
|
+
export declare const required: ValidatorFn;
|
|
264
|
+
|
|
265
|
+
export declare const requiredTrue: ValidatorFn;
|
|
266
|
+
|
|
267
|
+
export declare function restGlobalClient(): void;
|
|
268
|
+
|
|
269
|
+
export declare function setGlobalClient(client: Client): void;
|
|
270
|
+
|
|
271
|
+
declare type TransformResponseFn<Output = unknown> = (response: HttpResponse<unknown>) => Output;
|
|
272
|
+
|
|
273
|
+
export declare type UseRequestFn<Input, Output, Observe> = {
|
|
274
|
+
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>>;
|
|
275
|
+
getInitValue: () => Input extends Field<infer V> ? V : Input extends {
|
|
276
|
+
[K in keyof Input]: Field<any>;
|
|
277
|
+
} ? {
|
|
278
|
+
[K in keyof Input]: RequestInputValue<Input[K]>;
|
|
279
|
+
} : undefined;
|
|
280
|
+
setUploadProgress: (fn: HttpProgressFn) => void;
|
|
281
|
+
setDownloadProgress: (fn: HttpProgressFn) => void;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
export declare type ValidatorFn<T = unknown> = (value: T) => void;
|
|
285
|
+
|
|
286
|
+
export { }
|
|
226
287
|
|
|
227
|
-
|
|
288
|
+
|
|
289
|
+
declare module 'vitest' {
|
|
290
|
+
interface ProvidedContext {
|
|
291
|
+
testServerHost: string;
|
|
292
|
+
}
|
|
293
|
+
}
|