@defjs/core 0.0.0-test-0001 → 0.0.0-test-0002
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 +1 -1
- package/dist/index.js +22 -13
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -248,7 +248,7 @@ declare const CLIENT: unique symbol;
|
|
|
248
248
|
export type Client = {} & {
|
|
249
249
|
readonly [CLIENT]: ClientConfig;
|
|
250
250
|
};
|
|
251
|
-
export declare function isClient(value:
|
|
251
|
+
export declare function isClient(value: unknown): value is Client;
|
|
252
252
|
export declare function createClient(options: ClientOptions): Client;
|
|
253
253
|
|
|
254
254
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -296,12 +296,12 @@ async function doRequest(...args) {
|
|
|
296
296
|
let input;
|
|
297
297
|
let options = {};
|
|
298
298
|
switch (argsLength) {
|
|
299
|
-
case
|
|
299
|
+
case 1: {
|
|
300
300
|
ref = args[0];
|
|
301
301
|
options = args[1];
|
|
302
302
|
break;
|
|
303
303
|
}
|
|
304
|
-
case
|
|
304
|
+
case 2: {
|
|
305
305
|
ref = args[0];
|
|
306
306
|
input = args[1];
|
|
307
307
|
options = args[2];
|
|
@@ -324,7 +324,7 @@ async function doRequest(...args) {
|
|
|
324
324
|
abortController = new AbortController;
|
|
325
325
|
abortSignal = abortController.signal;
|
|
326
326
|
}
|
|
327
|
-
const clientOptions = getClientConfig(options.client);
|
|
327
|
+
const clientOptions = getClientConfig(options.client || getGlobalClient());
|
|
328
328
|
const req = {
|
|
329
329
|
host: clientOptions?.host || "",
|
|
330
330
|
method: requestOptions.method,
|
|
@@ -340,14 +340,7 @@ async function doRequest(...args) {
|
|
|
340
340
|
timeout: options.timeout || 0,
|
|
341
341
|
abort: abortSignal
|
|
342
342
|
};
|
|
343
|
-
|
|
344
|
-
if (options.handler) {
|
|
345
|
-
handler2 = options.handler;
|
|
346
|
-
} else if (clientOptions?.handler) {
|
|
347
|
-
handler2 = clientOptions.handler;
|
|
348
|
-
} else {
|
|
349
|
-
handler2 = getGlobalHttpHandler();
|
|
350
|
-
}
|
|
343
|
+
const handler2 = options.handler || clientOptions?.handler || getGlobalHttpHandler();
|
|
351
344
|
if (!handler2) {
|
|
352
345
|
throw new Error("no handler");
|
|
353
346
|
}
|
|
@@ -367,7 +360,16 @@ async function doRequest(...args) {
|
|
|
367
360
|
if (typeof requestOptions.transformResponse === "function") {
|
|
368
361
|
res.body = requestOptions.transformResponse(res);
|
|
369
362
|
}
|
|
370
|
-
|
|
363
|
+
switch (req.observe) {
|
|
364
|
+
case "body":
|
|
365
|
+
return res.body;
|
|
366
|
+
case "stream":
|
|
367
|
+
throw new Error("streaming not implemented");
|
|
368
|
+
case "response":
|
|
369
|
+
return res;
|
|
370
|
+
default:
|
|
371
|
+
throw new Error("invalid observe");
|
|
372
|
+
}
|
|
371
373
|
}
|
|
372
374
|
var REQUEST_REF = Symbol("RequestRef");
|
|
373
375
|
|
|
@@ -527,7 +529,7 @@ var FETCH_CONFIG_KEY = makeHttpContextToken(() => ({}));
|
|
|
527
529
|
var fetchHandler = _request;
|
|
528
530
|
// src/client.ts
|
|
529
531
|
function isClient(value) {
|
|
530
|
-
return typeof value === "object" && CLIENT in value;
|
|
532
|
+
return typeof value === "object" && value !== null && CLIENT in value;
|
|
531
533
|
}
|
|
532
534
|
function getClientConfig(client2) {
|
|
533
535
|
if (!isClient(client2)) {
|
|
@@ -545,7 +547,14 @@ function createClient(options) {
|
|
|
545
547
|
[CLIENT]: conf
|
|
546
548
|
};
|
|
547
549
|
}
|
|
550
|
+
function getGlobalClient() {
|
|
551
|
+
if (!globalClient) {
|
|
552
|
+
throw new Error("Global client not set");
|
|
553
|
+
}
|
|
554
|
+
return globalClient;
|
|
555
|
+
}
|
|
548
556
|
var CLIENT = Symbol("Client");
|
|
557
|
+
var globalClient;
|
|
549
558
|
export {
|
|
550
559
|
makeResponse,
|
|
551
560
|
makeHttpContextToken,
|