@defjs/core 0.0.0-test-0003 → 0.0.0-test-0005
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/dist/index.d.ts +9 -0
- package/dist/index.js +9 -9
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -111,6 +111,7 @@ export type RequestOptions<Output = unknown, Input extends Field<any> | Record<P
|
|
|
111
111
|
responseType?: HttpResponseType;
|
|
112
112
|
context?: HttpContext;
|
|
113
113
|
observe?: "body" | "response";
|
|
114
|
+
withCredentials?: boolean;
|
|
114
115
|
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
115
116
|
transformRequest?: TransformRequestFn;
|
|
116
117
|
transformResponse?: TransformResponseFn<Output>;
|
|
@@ -129,6 +130,7 @@ export declare function defineRequest<Output = unknown, Input extends Field<any>
|
|
|
129
130
|
responseType?: "json";
|
|
130
131
|
observe?: "body";
|
|
131
132
|
context?: HttpContext;
|
|
133
|
+
withCredentials?: boolean;
|
|
132
134
|
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
133
135
|
transformRequest?: TransformRequestFn;
|
|
134
136
|
transformResponse?: TransformResponseFn<Output>;
|
|
@@ -141,6 +143,7 @@ export declare function defineRequest<Input extends Field<any> | Record<Property
|
|
|
141
143
|
responseType: "text";
|
|
142
144
|
observe?: "body";
|
|
143
145
|
context?: HttpContext;
|
|
146
|
+
withCredentials?: boolean;
|
|
144
147
|
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
145
148
|
transformRequest?: TransformRequestFn;
|
|
146
149
|
transformResponse?: TransformResponseFn;
|
|
@@ -153,6 +156,7 @@ export declare function defineRequest<Input extends Field<any> | Record<Property
|
|
|
153
156
|
responseType: "blob";
|
|
154
157
|
observe?: "body";
|
|
155
158
|
context?: HttpContext;
|
|
159
|
+
withCredentials?: boolean;
|
|
156
160
|
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
157
161
|
transformRequest?: TransformRequestFn;
|
|
158
162
|
transformResponse?: TransformResponseFn;
|
|
@@ -165,6 +169,7 @@ export declare function defineRequest<Input extends Field<any> | Record<Property
|
|
|
165
169
|
responseType: "arraybuffer";
|
|
166
170
|
observe?: "body";
|
|
167
171
|
context?: HttpContext;
|
|
172
|
+
withCredentials?: boolean;
|
|
168
173
|
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
169
174
|
transformRequest?: TransformRequestFn;
|
|
170
175
|
transformResponse?: TransformResponseFn;
|
|
@@ -178,6 +183,7 @@ export declare function defineRequest<Output = unknown, Input extends Field<any>
|
|
|
178
183
|
responseType?: "json";
|
|
179
184
|
observe: "response";
|
|
180
185
|
context?: HttpContext;
|
|
186
|
+
withCredentials?: boolean;
|
|
181
187
|
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
182
188
|
transformRequest?: TransformRequestFn;
|
|
183
189
|
transformResponse?: TransformResponseFn<Output>;
|
|
@@ -190,6 +196,7 @@ export declare function defineRequest<Input extends Field<any> | Record<Property
|
|
|
190
196
|
responseType?: "text";
|
|
191
197
|
observe: "response";
|
|
192
198
|
context?: HttpContext;
|
|
199
|
+
withCredentials?: boolean;
|
|
193
200
|
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
194
201
|
transformRequest?: TransformRequestFn;
|
|
195
202
|
transformResponse?: TransformResponseFn;
|
|
@@ -202,6 +209,7 @@ export declare function defineRequest<Input extends Field<any> | Record<Property
|
|
|
202
209
|
responseType: "blob";
|
|
203
210
|
observe: "response";
|
|
204
211
|
context?: HttpContext;
|
|
212
|
+
withCredentials?: boolean;
|
|
205
213
|
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
206
214
|
transformRequest?: TransformRequestFn;
|
|
207
215
|
transformResponse?: TransformResponseFn;
|
|
@@ -214,6 +222,7 @@ export declare function defineRequest<Input extends Field<any> | Record<Property
|
|
|
214
222
|
responseType?: "arraybuffer";
|
|
215
223
|
observe: "response";
|
|
216
224
|
context?: HttpContext;
|
|
225
|
+
withCredentials?: boolean;
|
|
217
226
|
validators?: (ValidatorFn<RequestInputValue<Input>> | AsyncValidatorFn<RequestInputValue<Input>>)[];
|
|
218
227
|
transformRequest?: TransformRequestFn;
|
|
219
228
|
transformResponse?: TransformResponseFn;
|
package/dist/index.js
CHANGED
|
@@ -242,11 +242,10 @@ async function fillRequestFromField(request, fieldOrFieldGroup, input) {
|
|
|
242
242
|
const json = {};
|
|
243
243
|
let body = undefined;
|
|
244
244
|
for (const [propertyKey, field3] of Object.entries(fieldOrFieldGroup)) {
|
|
245
|
-
const defaultValue = field3();
|
|
246
245
|
const meta = getFieldMetadata(field3);
|
|
247
246
|
for (const [type, aliasName] of meta.alias) {
|
|
248
247
|
const valueKey = aliasName || propertyKey;
|
|
249
|
-
const value = input[
|
|
248
|
+
const value = input[propertyKey] || field3();
|
|
250
249
|
const err = await doValid([...meta.validators, ...meta.asyncValidator], value);
|
|
251
250
|
if (err) {
|
|
252
251
|
throw err;
|
|
@@ -294,7 +293,7 @@ async function doRequest(...args) {
|
|
|
294
293
|
const argsLength = args.length;
|
|
295
294
|
let ref;
|
|
296
295
|
let input;
|
|
297
|
-
let options
|
|
296
|
+
let options;
|
|
298
297
|
switch (argsLength) {
|
|
299
298
|
case 1: {
|
|
300
299
|
ref = args[0];
|
|
@@ -318,13 +317,13 @@ async function doRequest(...args) {
|
|
|
318
317
|
}
|
|
319
318
|
let abortController;
|
|
320
319
|
let abortSignal;
|
|
321
|
-
if (options
|
|
320
|
+
if (options?.abort) {
|
|
322
321
|
abortSignal = options.abort;
|
|
323
322
|
} else {
|
|
324
323
|
abortController = new AbortController;
|
|
325
324
|
abortSignal = abortController.signal;
|
|
326
325
|
}
|
|
327
|
-
const clientOptions = getClientConfig(options
|
|
326
|
+
const clientOptions = getClientConfig(options?.client || getGlobalClient());
|
|
328
327
|
const req = {
|
|
329
328
|
host: clientOptions?.host || "",
|
|
330
329
|
method: requestOptions.method,
|
|
@@ -332,15 +331,16 @@ async function doRequest(...args) {
|
|
|
332
331
|
queryParams: new URLSearchParams,
|
|
333
332
|
headers: new Headers,
|
|
334
333
|
body: undefined,
|
|
334
|
+
withCredentials: requestOptions.withCredentials,
|
|
335
335
|
responseType: requestOptions.responseType ?? "json",
|
|
336
336
|
context: requestOptions.context || makeHttpContext(),
|
|
337
337
|
observe: requestOptions.observe ?? "body",
|
|
338
|
-
uploadProgress: options
|
|
339
|
-
downloadProgress: options
|
|
340
|
-
timeout: options
|
|
338
|
+
uploadProgress: options?.uploadProgress,
|
|
339
|
+
downloadProgress: options?.downloadProgress,
|
|
340
|
+
timeout: options?.timeout || 0,
|
|
341
341
|
abort: abortSignal
|
|
342
342
|
};
|
|
343
|
-
const handler2 = options
|
|
343
|
+
const handler2 = options?.handler || clientOptions?.handler || getGlobalHttpHandler();
|
|
344
344
|
if (!handler2) {
|
|
345
345
|
throw new Error("no handler");
|
|
346
346
|
}
|