keq 2.0.0 → 2.0.2

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.
Files changed (91) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/esm/src/index.d.ts +1 -0
  3. package/dist/esm/src/index.js +1 -0
  4. package/dist/umd/src/constant.d.ts +1 -0
  5. package/dist/umd/src/constant.js +14 -0
  6. package/dist/umd/src/core.d.ts +28 -0
  7. package/dist/umd/src/core.js +125 -0
  8. package/dist/umd/src/exception/exception.d.ts +4 -0
  9. package/dist/umd/src/exception/exception.js +21 -0
  10. package/dist/umd/src/exception/invalid-arguments.exception.d.ts +4 -0
  11. package/dist/umd/src/exception/invalid-arguments.exception.js +20 -0
  12. package/dist/umd/src/exception/overwrite-array-body.exception.d.ts +4 -0
  13. package/dist/umd/src/exception/overwrite-array-body.exception.js +20 -0
  14. package/dist/umd/src/is/is-blob.d.ts +4 -0
  15. package/dist/umd/src/is/is-blob.js +32 -0
  16. package/dist/umd/src/is/is-browser.d.ts +1 -0
  17. package/dist/umd/src/is/is-browser.js +17 -0
  18. package/dist/umd/src/is/is-file.d.ts +1 -0
  19. package/dist/umd/src/is/is-file.js +21 -0
  20. package/dist/umd/src/is/is-form-data.d.ts +1 -0
  21. package/dist/umd/src/is/is-form-data.js +30 -0
  22. package/dist/umd/src/is/is-function.d.ts +1 -0
  23. package/dist/umd/src/is/is-function.js +17 -0
  24. package/dist/umd/src/is/is-headers.d.ts +1 -0
  25. package/dist/umd/src/is/is-headers.js +33 -0
  26. package/dist/umd/src/is/is-object.d.ts +1 -0
  27. package/dist/umd/src/is/is-object.js +17 -0
  28. package/dist/umd/src/is/is-string.d.ts +1 -0
  29. package/dist/umd/src/is/is-string.js +17 -0
  30. package/dist/umd/src/is/is-url-search-params.d.ts +1 -0
  31. package/dist/umd/src/is/is-url-search-params.js +36 -0
  32. package/dist/umd/src/keq.d.ts +70 -0
  33. package/dist/umd/src/keq.js +193 -0
  34. package/dist/umd/src/middleware.d.ts +2 -0
  35. package/dist/umd/src/middleware.js +27 -0
  36. package/dist/umd/src/middlewares/fetch-arguments-middleware.d.ts +2 -0
  37. package/dist/umd/src/middlewares/fetch-arguments-middleware.js +96 -0
  38. package/dist/umd/src/middlewares/fetch-middleware.d.ts +5 -0
  39. package/dist/umd/src/middlewares/fetch-middleware.js +29 -0
  40. package/dist/umd/src/middlewares/proxy-response-middleware.d.ts +2 -0
  41. package/dist/umd/src/middlewares/proxy-response-middleware.js +27 -0
  42. package/dist/umd/src/middlewares/retry-middleware.d.ts +2 -0
  43. package/dist/umd/src/middlewares/retry-middleware.js +51 -0
  44. package/dist/umd/src/router/keq-host-router.d.ts +7 -0
  45. package/dist/umd/src/router/keq-host-router.js +33 -0
  46. package/dist/umd/src/router/keq-location-router.d.ts +6 -0
  47. package/dist/umd/src/router/keq-location-router.js +32 -0
  48. package/dist/umd/src/router/keq-method-router.d.ts +8 -0
  49. package/dist/umd/src/router/keq-method-router.js +33 -0
  50. package/dist/umd/src/router/keq-module-router.d.ts +7 -0
  51. package/dist/umd/src/router/keq-module-router.js +37 -0
  52. package/dist/umd/src/router/keq-pathname-router.d.ts +7 -0
  53. package/dist/umd/src/router/keq-pathname-router.js +34 -0
  54. package/dist/umd/src/router/keq-router.d.ts +7 -0
  55. package/dist/umd/src/router/keq-router.js +24 -0
  56. package/dist/umd/src/types/keq-context.d.ts +41 -0
  57. package/dist/umd/src/types/keq-context.js +13 -0
  58. package/dist/umd/src/types/keq-middleware.d.ts +3 -0
  59. package/dist/umd/src/types/keq-middleware.js +12 -0
  60. package/dist/umd/src/types/keq-next.d.ts +1 -0
  61. package/dist/umd/src/types/keq-next.js +12 -0
  62. package/dist/umd/src/types/keq-options.d.ts +38 -0
  63. package/dist/umd/src/types/keq-options.js +12 -0
  64. package/dist/umd/src/types/keq-request-body.d.ts +1 -0
  65. package/dist/umd/src/types/keq-request-body.js +12 -0
  66. package/dist/umd/src/types/keq-request-init.d.ts +2 -0
  67. package/dist/umd/src/types/keq-request-init.js +12 -0
  68. package/dist/umd/src/types/keq-request-method.d.ts +1 -0
  69. package/dist/umd/src/types/keq-request-method.js +12 -0
  70. package/dist/umd/src/types/keq-request.d.ts +21 -0
  71. package/dist/umd/src/types/keq-request.js +12 -0
  72. package/dist/umd/src/types/keq-retry-delay.d.ts +2 -0
  73. package/dist/umd/src/types/keq-retry-delay.js +12 -0
  74. package/dist/umd/src/types/keq-retry-on.d.ts +2 -0
  75. package/dist/umd/src/types/keq-retry-on.js +12 -0
  76. package/dist/umd/src/types/router-map.d.ts +9 -0
  77. package/dist/umd/src/types/router-map.js +12 -0
  78. package/dist/umd/src/types/shorthand-content-type.d.ts +1 -0
  79. package/dist/umd/src/types/shorthand-content-type.js +12 -0
  80. package/dist/umd/src/util/assign-keq-request-body.d.ts +2 -0
  81. package/dist/umd/src/util/assign-keq-request-body.js +70 -0
  82. package/dist/umd/src/util/base64.d.ts +2 -0
  83. package/dist/umd/src/util/base64.js +15 -0
  84. package/dist/umd/src/util/clone.d.ts +1 -0
  85. package/dist/umd/src/util/clone.js +38 -0
  86. package/dist/umd/src/util/fix-content-type.d.ts +2 -0
  87. package/dist/umd/src/util/fix-content-type.js +35 -0
  88. package/dist/umd/src/util/shadow-clone.d.ts +4 -0
  89. package/dist/umd/src/util/shadow-clone.js +27 -0
  90. package/package.json +1 -1
  91. package/tsconfig.json +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [2.0.2](https://www.github.com/keq-request/keq/compare/v2.0.1...v2.0.2) (2023-09-27)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * cannot import umd package ([4eb05b3](https://www.github.com/keq-request/keq/commit/4eb05b35a41fd7b00e21ae5978eb3dc3900a3bdc))
11
+
12
+ ### [2.0.1](https://www.github.com/keq-request/keq/compare/v2.0.0...v2.0.1) (2023-09-27)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * cannot import createRequest ([2acdc47](https://www.github.com/keq-request/keq/commit/2acdc47200c36c83d7539f7d3b68d8df7bb49803))
18
+
5
19
  ## [2.0.0](https://www.github.com/keq-request/keq/compare/v1.10.1...v2.0.0) (2023-09-25)
6
20
 
7
21
 
@@ -1,3 +1,4 @@
1
+ export { createRequest } from './create-request';
1
2
  export { Keq } from './keq';
2
3
  export { composeMiddleware } from './middleware';
3
4
  export { request } from './request';
@@ -1,3 +1,4 @@
1
+ export { createRequest } from './create-request';
1
2
  export { Keq } from './keq';
2
3
  export { composeMiddleware } from './middleware';
3
4
  export { request } from './request';
@@ -0,0 +1 @@
1
+ export declare const OUTPUT_PROPERTY: unique symbol;
@@ -0,0 +1,14 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OUTPUT_PROPERTY = void 0;
13
+ exports.OUTPUT_PROPERTY = Symbol('outputProperty');
14
+ });
@@ -0,0 +1,28 @@
1
+ import { URL } from 'whatwg-url';
2
+ import { KeqRequestContext } from './types/keq-context';
3
+ import { KeqMiddleware } from './types/keq-middleware';
4
+ import { KeqOptions } from './types/keq-options';
5
+ import { KeqRequestInit } from './types/keq-request-init';
6
+ /**
7
+ * @description Keq 核心 API,发送请求必要的原子化的API
8
+ */
9
+ export declare class Core<T> {
10
+ private requestPromise?;
11
+ protected requestContext: KeqRequestContext;
12
+ protected __prepend_middlewares__: KeqMiddleware[];
13
+ protected __append_middlewares__: KeqMiddleware[];
14
+ protected __options__: KeqOptions;
15
+ constructor(url: (URL | globalThis.URL), init: KeqRequestInit);
16
+ prependMiddlewares(...middlewares: KeqMiddleware[]): this;
17
+ appendMiddlewares(...middlewares: KeqMiddleware[]): this;
18
+ private run;
19
+ end(): Promise<T>;
20
+ /**
21
+ * Attaches callbacks for the resolution and/or rejection of the Promise.
22
+ * @param onfulfilled The callback to execute when the Promise is resolved.
23
+ * @param onrejected The callback to execute when the Promise is rejected.
24
+ * @returns A Promise for the completion of which ever callback is executed.
25
+ */
26
+ then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
27
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>;
28
+ }
@@ -0,0 +1,125 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "whatwg-url", "./exception/exception", "./util/clone", "./constant", "./middleware", "./util/shadow-clone"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Core = void 0;
13
+ const whatwg_url_1 = require("whatwg-url");
14
+ const exception_1 = require("./exception/exception");
15
+ const clone_1 = require("./util/clone");
16
+ const constant_1 = require("./constant");
17
+ const middleware_1 = require("./middleware");
18
+ const shadow_clone_1 = require("./util/shadow-clone");
19
+ /**
20
+ * @description Keq 核心 API,发送请求必要的原子化的API
21
+ */
22
+ class Core {
23
+ requestPromise;
24
+ requestContext;
25
+ __prepend_middlewares__ = [];
26
+ __append_middlewares__ = [];
27
+ __options__ = { resolveWithFullResponse: false };
28
+ constructor(url, init) {
29
+ this.requestContext = {
30
+ method: 'get',
31
+ headers: new Headers(),
32
+ routeParams: {},
33
+ body: undefined,
34
+ ...init,
35
+ url: new whatwg_url_1.URL(url.href),
36
+ };
37
+ }
38
+ prependMiddlewares(...middlewares) {
39
+ this.__prepend_middlewares__.push(...middlewares);
40
+ return this;
41
+ }
42
+ appendMiddlewares(...middlewares) {
43
+ this.__append_middlewares__.unshift(...middlewares);
44
+ return this;
45
+ }
46
+ async run() {
47
+ const headers = new Headers();
48
+ for (const [key, value] of this.requestContext.headers.entries()) {
49
+ headers.append(key, value);
50
+ }
51
+ const requestContext = {
52
+ method: this.requestContext.method,
53
+ url: new whatwg_url_1.URL(this.requestContext.url.href),
54
+ headers,
55
+ routeParams: (0, shadow_clone_1.shadowClone)(this.requestContext.routeParams),
56
+ body: (0, clone_1.clone)(this.requestContext.body),
57
+ };
58
+ const options = (0, shadow_clone_1.shadowClone)(this.__options__);
59
+ const ctx = {
60
+ request: requestContext,
61
+ options,
62
+ get output() {
63
+ throw new exception_1.Exception('output property is write-only');
64
+ },
65
+ set output(value) {
66
+ this[constant_1.OUTPUT_PROPERTY] = value;
67
+ },
68
+ };
69
+ const middleware = (0, middleware_1.composeMiddleware)([...this.__prepend_middlewares__, ...this.__append_middlewares__]);
70
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
71
+ await middleware(ctx, async () => { });
72
+ let output = ctx[constant_1.OUTPUT_PROPERTY];
73
+ if (ctx.options.resolveWithFullResponse) {
74
+ return ctx.response;
75
+ }
76
+ if (!(constant_1.OUTPUT_PROPERTY in ctx)) {
77
+ const response = ctx.response;
78
+ if (response?.status === 204) {
79
+ // 204: NO CONTENT
80
+ output = response && response.body;
81
+ }
82
+ else {
83
+ const headers = response?.headers;
84
+ const contentType = headers?.get('content-type') || '';
85
+ try {
86
+ if (contentType.includes('application/json')) {
87
+ output = ctx.response && await ctx.response.json();
88
+ }
89
+ else if (contentType.includes('multipart/form-data')) {
90
+ output = ctx.response && await ctx.response.formData();
91
+ }
92
+ else if (contentType.includes('plain/text')) {
93
+ output = ctx.response && await ctx.response.text();
94
+ }
95
+ else {
96
+ output = ctx.response && ctx.response.body;
97
+ }
98
+ }
99
+ catch (e) {
100
+ console.warn('Failed to auto parse response body', e);
101
+ }
102
+ }
103
+ }
104
+ return output;
105
+ }
106
+ async end() {
107
+ return this.run();
108
+ }
109
+ /**
110
+ * Attaches callbacks for the resolution and/or rejection of the Promise.
111
+ * @param onfulfilled The callback to execute when the Promise is resolved.
112
+ * @param onrejected The callback to execute when the Promise is rejected.
113
+ * @returns A Promise for the completion of which ever callback is executed.
114
+ */
115
+ then(onfulfilled, onrejected) {
116
+ if (!this.requestPromise)
117
+ this.requestPromise = this.end();
118
+ return this.requestPromise.then(onfulfilled, onrejected);
119
+ }
120
+ catch(onrejected) {
121
+ return this.end().catch(onrejected);
122
+ }
123
+ }
124
+ exports.Core = Core;
125
+ });
@@ -0,0 +1,4 @@
1
+ import { CustomError } from 'ts-custom-error';
2
+ export declare class Exception extends CustomError {
3
+ constructor(message?: string);
4
+ }
@@ -0,0 +1,21 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "ts-custom-error"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Exception = void 0;
13
+ const ts_custom_error_1 = require("ts-custom-error");
14
+ class Exception extends ts_custom_error_1.CustomError {
15
+ constructor(message) {
16
+ super(message);
17
+ Object.defineProperty(this, 'name', { value: 'KeqError' });
18
+ }
19
+ }
20
+ exports.Exception = Exception;
21
+ });
@@ -0,0 +1,4 @@
1
+ import { Exception } from './exception';
2
+ export declare class InvalidArgumentsExceptions extends Exception {
3
+ constructor();
4
+ }
@@ -0,0 +1,20 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./exception"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.InvalidArgumentsExceptions = void 0;
13
+ const exception_1 = require("./exception");
14
+ class InvalidArgumentsExceptions extends exception_1.Exception {
15
+ constructor() {
16
+ super('Invalid arguments');
17
+ }
18
+ }
19
+ exports.InvalidArgumentsExceptions = InvalidArgumentsExceptions;
20
+ });
@@ -0,0 +1,4 @@
1
+ import { Exception } from './exception';
2
+ export declare class OverwriteArrayBodyException extends Exception {
3
+ constructor();
4
+ }
@@ -0,0 +1,20 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./exception"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OverwriteArrayBodyException = void 0;
13
+ const exception_1 = require("./exception");
14
+ class OverwriteArrayBodyException extends exception_1.Exception {
15
+ constructor() {
16
+ super('Cannot merge or overwrite body, because it has been set as an array. Please use .body(arr) instead');
17
+ }
18
+ }
19
+ exports.OverwriteArrayBodyException = OverwriteArrayBodyException;
20
+ });
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Check if given valie is Blob or File -like object
3
+ */
4
+ export declare function isBlob(value: any): value is Blob;
@@ -0,0 +1,32 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./is-function", "./is-object", "./is-string"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isBlob = void 0;
13
+ const is_function_1 = require("./is-function");
14
+ const is_object_1 = require("./is-object");
15
+ const is_string_1 = require("./is-string");
16
+ const names = ['Blob', 'File'];
17
+ /**
18
+ * Check if given valie is Blob or File -like object
19
+ */
20
+ function isBlob(value) {
21
+ if (value instanceof Blob)
22
+ return true;
23
+ return (0, is_object_1.isObject)(value)
24
+ && (0, is_string_1.isString)(value.type)
25
+ && (0, is_function_1.isFunction)(value.arrayBuffer)
26
+ && (0, is_function_1.isFunction)(value.stream)
27
+ && (0, is_function_1.isFunction)(value.constructor)
28
+ && names.includes(value.constructor.name)
29
+ && 'size' in value;
30
+ }
31
+ exports.isBlob = isBlob;
32
+ });
@@ -0,0 +1 @@
1
+ export declare function isBrowser(): boolean;
@@ -0,0 +1,17 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isBrowser = void 0;
13
+ function isBrowser() {
14
+ return typeof window !== 'undefined';
15
+ }
16
+ exports.isBrowser = isBrowser;
17
+ });
@@ -0,0 +1 @@
1
+ export declare function isFile(object: any): object is File;
@@ -0,0 +1,21 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./is-blob", "./is-browser"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isFile = void 0;
13
+ const is_blob_1 = require("./is-blob");
14
+ const is_browser_1 = require("./is-browser");
15
+ function isFile(object) {
16
+ if ((0, is_browser_1.isBrowser)())
17
+ return object instanceof Blob;
18
+ return (0, is_blob_1.isBlob)(object);
19
+ }
20
+ exports.isFile = isFile;
21
+ });
@@ -0,0 +1 @@
1
+ export declare function isFormData(object: any): object is FormData;
@@ -0,0 +1,30 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./is-function", "./is-object"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isFormData = void 0;
13
+ const is_function_1 = require("./is-function");
14
+ const is_object_1 = require("./is-object");
15
+ function isFormData(object) {
16
+ if (object instanceof FormData)
17
+ return true;
18
+ return ((0, is_object_1.isObject)(object) &&
19
+ (0, is_function_1.isFunction)(object.append) &&
20
+ (0, is_function_1.isFunction)(object.delete) &&
21
+ (0, is_function_1.isFunction)(object.get) &&
22
+ (0, is_function_1.isFunction)(object.getAll) &&
23
+ (0, is_function_1.isFunction)(object.has) &&
24
+ (0, is_function_1.isFunction)(object.set) &&
25
+ (0, is_function_1.isFunction)(object.entries) &&
26
+ (0, is_function_1.isFunction)(object.keys) &&
27
+ (0, is_function_1.isFunction)(object.values));
28
+ }
29
+ exports.isFormData = isFormData;
30
+ });
@@ -0,0 +1 @@
1
+ export declare function isFunction(value: any): boolean;
@@ -0,0 +1,17 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isFunction = void 0;
13
+ function isFunction(value) {
14
+ return typeof value === 'function';
15
+ }
16
+ exports.isFunction = isFunction;
17
+ });
@@ -0,0 +1 @@
1
+ export declare function isHeaders(obj: any): obj is Headers;
@@ -0,0 +1,33 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./is-function", "./is-object"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isHeaders = void 0;
13
+ const is_function_1 = require("./is-function");
14
+ const is_object_1 = require("./is-object");
15
+ function isHeaders(obj) {
16
+ if (obj instanceof Headers)
17
+ return true;
18
+ if ((0, is_object_1.isObject)(obj) &&
19
+ (0, is_function_1.isFunction)(obj.forEach) &&
20
+ (0, is_function_1.isFunction)(obj.get) &&
21
+ (0, is_function_1.isFunction)(obj.has) &&
22
+ (0, is_function_1.isFunction)(obj.set) &&
23
+ (0, is_function_1.isFunction)(obj.append) &&
24
+ (0, is_function_1.isFunction)(obj.delete) &&
25
+ (0, is_function_1.isFunction)(obj.entries) &&
26
+ (0, is_function_1.isFunction)(obj.keys) &&
27
+ (0, is_function_1.isFunction)(obj.values)) {
28
+ return true;
29
+ }
30
+ return false;
31
+ }
32
+ exports.isHeaders = isHeaders;
33
+ });
@@ -0,0 +1 @@
1
+ export declare function isObject(value: any): boolean;
@@ -0,0 +1,17 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isObject = void 0;
13
+ function isObject(value) {
14
+ return typeof value === 'object' && value !== null;
15
+ }
16
+ exports.isObject = isObject;
17
+ });
@@ -0,0 +1 @@
1
+ export declare function isString(value: any): boolean;
@@ -0,0 +1,17 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isString = void 0;
13
+ function isString(value) {
14
+ return typeof value === 'string';
15
+ }
16
+ exports.isString = isString;
17
+ });
@@ -0,0 +1 @@
1
+ export declare function isUrlSearchParams(obj: any): obj is URLSearchParams;
@@ -0,0 +1,36 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./is-function", "./is-object"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isUrlSearchParams = void 0;
13
+ const is_function_1 = require("./is-function");
14
+ const is_object_1 = require("./is-object");
15
+ function isUrlSearchParams(obj) {
16
+ if (obj instanceof URLSearchParams)
17
+ return true;
18
+ if ((0, is_object_1.isObject)(obj) &&
19
+ (0, is_function_1.isFunction)(obj.append) &&
20
+ (0, is_function_1.isFunction)(obj.delete) &&
21
+ (0, is_function_1.isFunction)(obj.entrie) &&
22
+ (0, is_function_1.isFunction)(obj.forEac) &&
23
+ (0, is_function_1.isFunction)(obj.get) &&
24
+ (0, is_function_1.isFunction)(obj.getAll) &&
25
+ (0, is_function_1.isFunction)(obj.has) &&
26
+ (0, is_function_1.isFunction)(obj.keys) &&
27
+ (0, is_function_1.isFunction)(obj.set) &&
28
+ (0, is_function_1.isFunction)(obj.values) &&
29
+ (0, is_function_1.isFunction)(obj.sort) &&
30
+ (0, is_function_1.isFunction)(obj.toStri)) {
31
+ return true;
32
+ }
33
+ return false;
34
+ }
35
+ exports.isUrlSearchParams = isUrlSearchParams;
36
+ });
@@ -0,0 +1,70 @@
1
+ /// <reference types="node" />
2
+ import { Core } from './core';
3
+ import { KeqMiddleware } from './types/keq-middleware';
4
+ import { KeqBuildInOptions, KeqOptions, KeqOptionsWithFullResponse, KeqOptionsWithoutFullResponse } from './types/keq-options';
5
+ import { KeqRequestBody } from './types/keq-request-body';
6
+ import { KeqRetryDelay } from './types/keq-retry-delay';
7
+ import { KeqRetryOn } from './types/keq-retry-on';
8
+ import { ShorthandContentType } from './types/shorthand-content-type';
9
+ /**
10
+ * @description Keq 扩展 API,人性化的常用的API
11
+ */
12
+ export declare class Keq<T> extends Core<T> {
13
+ use(...middlewares: KeqMiddleware[]): this;
14
+ option(key: 'resolveWithFullResponse', value?: true): Core<Response>;
15
+ option<K extends keyof KeqBuildInOptions>(key: K, value?: KeqBuildInOptions[K]): this;
16
+ option(key: string, value?: any): this;
17
+ options(opts: KeqOptionsWithoutFullResponse): this;
18
+ options(opts: KeqOptionsWithFullResponse): Core<Response>;
19
+ options(opts: KeqOptions): this;
20
+ /**
21
+ * Set request header
22
+ *
23
+ * @description 设置请求头
24
+ */
25
+ set(headers: Headers): this;
26
+ set(headers: Record<string, string>): this;
27
+ set(name: string, value: string): this;
28
+ /**
29
+ * Set request query/searchParams
30
+ */
31
+ query(key: Record<string, string | number | string[] | number[] | undefined>): this;
32
+ query(key: string, value: string | number | string[] | number[] | undefined): this;
33
+ /**
34
+ * Set request route params
35
+ */
36
+ params(key: Record<string, string | number>): this;
37
+ params(key: string, value: string | number): this;
38
+ /**
39
+ * Set request body
40
+ */
41
+ body(value: KeqRequestBody): this;
42
+ /**
43
+ * Setting the Content-Type
44
+ */
45
+ type(contentType: ShorthandContentType | string): this;
46
+ /**
47
+ * Http Basic Authentication
48
+ */
49
+ auth(username: string, password: string): this;
50
+ private setTypeIfEmpty;
51
+ /**
52
+ * set request body
53
+ */
54
+ send(value: FormData | URLSearchParams | object | Array<any> | string): this;
55
+ field(arg1: string, value: string | string[]): this;
56
+ field(arg1: Record<string, string>): this;
57
+ attach(key: string, value: Blob | File | Buffer): this;
58
+ attach(key: string, value: Blob | File | Buffer, filename: string): this;
59
+ attach(key: string, value: Blob | File | Buffer): this;
60
+ /**
61
+ *
62
+ * @param retryTimes Max number of retries per call
63
+ * @param retryDelay Initial value used to calculate the retry in milliseconds (This is still randomized following the randomization factor)
64
+ * @param retryCallback Will be called after request failed
65
+ */
66
+ retry(retryTimes: number, retryDelay?: KeqRetryDelay, retryOn?: KeqRetryOn): Keq<T>;
67
+ redirect(mod: RequestRedirect): this;
68
+ credentials(mod: RequestCredentials): this;
69
+ mode(mod: RequestMode): this;
70
+ }