@defjs/core 0.0.0-test-0002 → 0.0.0-test-0004
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 +4 -0
- package/dist/index.js +20 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -250,5 +250,9 @@ export type Client = {} & {
|
|
|
250
250
|
};
|
|
251
251
|
export declare function isClient(value: unknown): value is Client;
|
|
252
252
|
export declare function createClient(options: ClientOptions): Client;
|
|
253
|
+
export declare function getGlobalClient(): Client;
|
|
254
|
+
export declare function setGlobalClient(client: Client): void;
|
|
255
|
+
export declare function restGlobalClient(): void;
|
|
256
|
+
export declare function createGlobalClient(options: ClientOptions): void;
|
|
253
257
|
|
|
254
258
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -294,7 +294,7 @@ async function doRequest(...args) {
|
|
|
294
294
|
const argsLength = args.length;
|
|
295
295
|
let ref;
|
|
296
296
|
let input;
|
|
297
|
-
let options
|
|
297
|
+
let options;
|
|
298
298
|
switch (argsLength) {
|
|
299
299
|
case 1: {
|
|
300
300
|
ref = args[0];
|
|
@@ -318,13 +318,13 @@ async function doRequest(...args) {
|
|
|
318
318
|
}
|
|
319
319
|
let abortController;
|
|
320
320
|
let abortSignal;
|
|
321
|
-
if (options
|
|
321
|
+
if (options?.abort) {
|
|
322
322
|
abortSignal = options.abort;
|
|
323
323
|
} else {
|
|
324
324
|
abortController = new AbortController;
|
|
325
325
|
abortSignal = abortController.signal;
|
|
326
326
|
}
|
|
327
|
-
const clientOptions = getClientConfig(options
|
|
327
|
+
const clientOptions = getClientConfig(options?.client || getGlobalClient());
|
|
328
328
|
const req = {
|
|
329
329
|
host: clientOptions?.host || "",
|
|
330
330
|
method: requestOptions.method,
|
|
@@ -335,12 +335,12 @@ async function doRequest(...args) {
|
|
|
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
|
}
|
|
@@ -553,9 +553,20 @@ function getGlobalClient() {
|
|
|
553
553
|
}
|
|
554
554
|
return globalClient;
|
|
555
555
|
}
|
|
556
|
+
function setGlobalClient(client2) {
|
|
557
|
+
globalClient = client2;
|
|
558
|
+
}
|
|
559
|
+
function restGlobalClient() {
|
|
560
|
+
globalClient = undefined;
|
|
561
|
+
}
|
|
562
|
+
function createGlobalClient(options) {
|
|
563
|
+
globalClient = createClient(options);
|
|
564
|
+
}
|
|
556
565
|
var CLIENT = Symbol("Client");
|
|
557
566
|
var globalClient;
|
|
558
567
|
export {
|
|
568
|
+
setGlobalClient,
|
|
569
|
+
restGlobalClient,
|
|
559
570
|
makeResponse,
|
|
560
571
|
makeHttpContextToken,
|
|
561
572
|
makeHttpContext,
|
|
@@ -563,9 +574,11 @@ export {
|
|
|
563
574
|
isFieldGroup,
|
|
564
575
|
isField,
|
|
565
576
|
isClient,
|
|
577
|
+
getGlobalClient,
|
|
566
578
|
field,
|
|
567
579
|
fetchHandler,
|
|
568
580
|
doRequest,
|
|
569
581
|
defineRequest,
|
|
582
|
+
createGlobalClient,
|
|
570
583
|
createClient
|
|
571
584
|
};
|