keq 2.0.2 → 2.0.7

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/CHANGELOG.md CHANGED
@@ -2,6 +2,41 @@
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.7](https://github.com/keq-request/keq/compare/v2.0.6...v2.0.7) (2023-11-09)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * wrong repo address in package.json ([1101a79](https://github.com/keq-request/keq/commit/1101a79d12c3c96aba45167ab60f1ef1a8b6b4a7))
11
+
12
+ ## [2.0.6](https://github.com/keq-request/keq/compare/v2.0.5...v2.0.6) (2023-11-08)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * npm publish error ([14a3b93](https://github.com/keq-request/keq/commit/14a3b931d72c105f9c4bdf56d90516f2052b217b))
18
+
19
+ ## [2.0.5](https://github.com/keq-request/keq/compare/v2.0.4...v2.0.5) (2023-11-08)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * unable build ([5731cab](https://github.com/keq-request/keq/commit/5731cab1e62bc23d2ddb9522e607e3bdfa12db4d))
25
+
26
+ ## [2.0.4](https://github.com/keq-request/keq/compare/v2.0.3...v2.0.4) (2023-11-08)
27
+
28
+
29
+ ### Performance Improvements
30
+
31
+ * add package provenance ([ab5c99e](https://github.com/keq-request/keq/commit/ab5c99ed89809f244172263623732ea0d963ab36))
32
+
33
+ ### [2.0.3](https://www.github.com/keq-request/keq/compare/v2.0.2...v2.0.3) (2023-09-27)
34
+
35
+
36
+ ### Bug Fixes
37
+
38
+ * cannot find dist/umd/src/index.js ([9264923](https://www.github.com/keq-request/keq/commit/9264923e606fc5bc28675c751910e1eb3a30b864))
39
+
5
40
  ### [2.0.2](https://www.github.com/keq-request/keq/compare/v2.0.1...v2.0.2) (2023-09-27)
6
41
 
7
42
 
package/README.md CHANGED
@@ -6,12 +6,11 @@
6
6
  <h1 align="center" style="text-align: center">KEQ</h1>
7
7
  <!-- title -->
8
8
 
9
- [![version](https://img.shields.io/npm/v/keq.svg?style=for-the-badge)](https://www.npmjs.com/package/keq)
10
- [![downloads](https://img.shields.io/npm/dm/keq.svg?style=for-the-badge)](https://www.npmjs.com/package/keq)
11
- [![license](https://img.shields.io/npm/l/keq.svg?style=for-the-badge)](https://www.npmjs.com/package/keq)
12
- [![dependencies](https://img.shields.io/librariesio/release/npm/keq-cli?style=for-the-badge)](https://www.npmjs.com/package/keq)
13
-
14
- <!-- [![coveralls](https://img.shields.io/coveralls/github/keq-request/keq.svg?style=for-the-badge)](https://coveralls.io/github/keq-request/keq) -->
9
+ [![version](https://img.shields.io/npm/v/keq.svg?logo=npm&style=for-the-badge)](https://www.npmjs.com/package/keq)
10
+ [![downloads](https://img.shields.io/npm/dm/keq.svg?logo=npm&style=for-the-badge)](https://www.npmjs.com/package/keq)
11
+ [![dependencies](https://img.shields.io/librariesio/release/npm/keq?logo=npm&style=for-the-badge)](https://www.npmjs.com/package/keq)
12
+ [![license](https://img.shields.io/npm/l/keq.svg?logo=github&style=for-the-badge)](https://www.npmjs.com/package/keq)
13
+ [![Codecov](https://img.shields.io/codecov/c/gh/keq-request/keq?logo=codecov&token=PLF0DT6869&style=for-the-badge)](https://codecov.io/gh/keq-request/keq)
15
14
 
16
15
  <!-- description -->
17
16
 
@@ -21,11 +20,8 @@
21
20
  [FormData MDN]: https://developer.mozilla.org/en-US/docs/Web/API/FormData
22
21
  [URL MDN]: https://developer.mozilla.org/en-US/docs/Web/API/URL
23
22
 
24
-
25
23
  Keq is a request API write by Typescript for flexibility, readability, and a low learning curve. It also works with Node.js!
26
-
27
- Keq wraps the [cross-fetch](https://www.npmjs.com/package/cross-fetch) and use Fetch APIs whenever possible.
28
- Like [`Headers`][Headers MDN], [`Response`][Response MDN], [`FormData`][FormData MDN] objects.
24
+ Keq wraps the Fetch APIs, adding chain calls and middleware functions.
29
25
 
30
26
  <!-- description -->
31
27
 
@@ -40,45 +36,45 @@ then calling `.then()` (or `.end()` or `await`) to send the request.
40
36
  For example a simple GET request:
41
37
 
42
38
  ```javascript
43
- import { request } from "keq"
39
+ import { request } from "keq";
44
40
 
45
41
  const body = await request
46
42
  .get("/search")
47
43
  .set("X-Origin-Host", "https://example.com")
48
- .query("key1", "value1")
44
+ .query("key1", "value1");
49
45
  ```
50
46
 
51
47
  Request can be initiated by:
52
48
 
53
49
  ```javascript
54
- import { request } from "keq"
50
+ import { request } from "keq";
55
51
 
56
52
  const body = await request({
57
53
  url: "/search",
58
54
  method: "get",
59
- })
55
+ });
60
56
  ```
61
57
 
62
58
  Absolute URLs can be used.
63
59
  In web browsers absolute URLs work only if the server implements CORS.
64
60
 
65
61
  ```javascript
66
- import { request } from "keq"
62
+ import { request } from "keq";
67
63
 
68
- const body = await request.get("https://example.com/search")
64
+ const body = await request.get("https://example.com/search");
69
65
  ```
70
66
 
71
67
  **DELETE**, **HEAD**, **PATCH**, **POST**, and **PUT** requests can also be used, simply change the method name:
72
68
 
73
69
  ```javascript
74
- import { request } from "keq"
75
-
76
- await request.head("https://example.com/search")
77
- await request.patch("https://example.com/search")
78
- await request.post("https://example.com/search")
79
- await request.put("https://example.com/search")
80
- await request.delete("https://example.com/search")
81
- await request.del("https://example.com/search")
70
+ import { request } from "keq";
71
+
72
+ await request.head("https://example.com/search");
73
+ await request.patch("https://example.com/search");
74
+ await request.post("https://example.com/search");
75
+ await request.put("https://example.com/search");
76
+ await request.delete("https://example.com/search");
77
+ await request.del("https://example.com/search");
82
78
  ```
83
79
 
84
80
  > `.del()` is the alias of `.delete()`.
@@ -88,13 +84,13 @@ and return `body` of [`Response`][Response MDN] by defaulted.
88
84
  Add option `resolveWithFullResponse` to get the origin [`Response`][Response MDN] Object.
89
85
 
90
86
  ```javascript
91
- import { request } from "keq"
87
+ import { request } from "keq";
92
88
 
93
89
  const response = await request
94
90
  .get("http://test.com")
95
- .option("resolveWithFullResponse")
91
+ .option("resolveWithFullResponse");
96
92
 
97
- const body = await response.json()
93
+ const body = await response.json();
98
94
  ```
99
95
 
100
96
  ###### `Keq` won't auto parse body, if response.status is 204. The HTTP 204 No Content success status response code indicates that server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation
@@ -104,23 +100,23 @@ const body = await response.json()
104
100
  Setting header fields is simple, invoke `.set()` with a field name and value:
105
101
 
106
102
  ```javascript
107
- import { request } from "keq"
103
+ import { request } from "keq";
108
104
 
109
105
  await request
110
106
  .get("/search")
111
107
  .set("X-Origin-Host", "https://example.com")
112
- .set("Accept", "application/json")
108
+ .set("Accept", "application/json");
113
109
  ```
114
110
 
115
111
  You may also pass an object or `Headers` to set several fields in a single call:
116
112
 
117
113
  ```javascript
118
- import { request } from "keq"
114
+ import { request } from "keq";
119
115
 
120
116
  await request.get("/search").set({
121
117
  "X-Origin-Host": "https://example.com",
122
118
  Accept: "application/json",
123
- })
119
+ });
124
120
  ```
125
121
 
126
122
  ### Request query
@@ -130,23 +126,23 @@ which when used with the GET method will form a query-string.
130
126
  The following will produce the path `/search?query=Manny&range=1..5&order=desc.`
131
127
 
132
128
  ```javascript
133
- import { request } from "keq"
129
+ import { request } from "keq";
134
130
 
135
131
  await request
136
132
  .get("/search")
137
133
  .query({ query: "Manny" })
138
134
  .query({ range: "1..5" })
139
- .query("order", "desc")
135
+ .query("order", "desc");
140
136
  ```
141
137
 
142
138
  Or as a single object:
143
139
 
144
140
  ```javascript
145
- import { request } from "keq"
141
+ import { request } from "keq";
146
142
 
147
143
  await request
148
144
  .get("/search")
149
- .query({ query: "Manny", range: "1..5", order: "desc" })
145
+ .query({ query: "Manny", range: "1..5", order: "desc" });
150
146
  ```
151
147
 
152
148
  ### Request routing parameters
@@ -155,21 +151,17 @@ The `.params()` method accepts key and value, which when used for the request wi
155
151
  The follwing will produce the path `/search/keq`.
156
152
 
157
153
  ```javascript
158
- import { request } from "keq"
154
+ import { request } from "keq";
159
155
 
160
- await request
161
- .get("/search/:searchKey")
162
- .params("searchKey", "keq")
156
+ await request.get("/search/:searchKey").params("searchKey", "keq");
163
157
  ```
164
158
 
165
159
  Or as a single object:
166
160
 
167
161
  ```javascript
168
- import { request } from "keq"
162
+ import { request } from "keq";
169
163
 
170
- await request
171
- .get("/search/:searchKey")
172
- .params({ searchKey: "keq" })
164
+ await request.get("/search/:searchKey").params({ searchKey: "keq" });
173
165
  ```
174
166
 
175
167
  ### JSON Request
@@ -178,12 +170,12 @@ A typical JSON POST request might look a little like the following,
178
170
  where we set the `Content-Type` header field appropriately:
179
171
 
180
172
  ```javascript
181
- import { request } from "keq"
173
+ import { request } from "keq";
182
174
 
183
175
  await request
184
176
  .post("/user")
185
177
  .set("Content-Type", "application/json")
186
- .send({ name: "tj", pet: "tobi" })
178
+ .send({ name: "tj", pet: "tobi" });
187
179
  ```
188
180
 
189
181
  When passed an `object` to `.send()`, it will auto set `Content-Type` to `application/json`
@@ -193,13 +185,13 @@ When passed an `object` to `.send()`, it will auto set `Content-Type` to `applic
193
185
  A typical Form POST request might look a little like the following:
194
186
 
195
187
  ```javascript
196
- import { request } from "keq"
188
+ import { request } from "keq";
197
189
 
198
190
  await request
199
191
  .post("/user")
200
192
  .type("form")
201
193
  .send({ name: "tj", pet: "tobi" })
202
- .send("pet=tobi")
194
+ .send("pet=tobi");
203
195
  ```
204
196
 
205
197
  To send the data as `application/x-www-form-urlencoded` simply invoke `.type()` with "form".
@@ -212,11 +204,11 @@ When passed an `string` to `.send()`, it will auto set `Content-Type` to `applic
212
204
  A typical Form POST request might look a little like the following:
213
205
 
214
206
  ```javascript
215
- import { request } from "keq"
207
+ import { request } from "keq";
216
208
 
217
- const form = new FormData()
218
- form.append("name", "tj")
219
- form.append("pet", "tobi")
209
+ const form = new FormData();
210
+ form.append("name", "tj");
211
+ form.append("pet", "tobi");
220
212
 
221
213
  // prettier-ignore
222
214
  await request
@@ -230,13 +222,13 @@ When passed an `FormData` object to `.send()`, it will auto set `Content-Type` t
230
222
  You can append field by invoke `.field()` and `.attach()`
231
223
 
232
224
  ```javascript
233
- import { request } from "keq"
225
+ import { request } from "keq";
234
226
 
235
227
  await request
236
228
  .post("/user")
237
229
  .field("name", "tj")
238
230
  .field("pet", "tobi")
239
- .attach("file", new Blob(["I am tj"]))
231
+ .attach("file", new Blob(["I am tj"]));
240
232
  ```
241
233
 
242
234
  ### Setting the Content-Type
@@ -244,7 +236,7 @@ await request
244
236
  The obvious solution is to use the .set() method:
245
237
 
246
238
  ```javascript
247
- import { request } from "keq"
239
+ import { request } from "keq";
248
240
 
249
241
  // prettier-ignore
250
242
  await request
@@ -257,11 +249,9 @@ accepting the canonicalized MIME type name complete with type/subtype,
257
249
  or simply the extension name such as "xml", "json", "png", etc:
258
250
 
259
251
  ```javascript
260
- import { request } from "keq"
252
+ import { request } from "keq";
261
253
 
262
- await request
263
- .post("/user")
264
- .type("json")
254
+ await request.post("/user").type("json");
265
255
  ```
266
256
 
267
257
  | **Shorthand** | **Mime Type** |
@@ -284,18 +274,16 @@ No retry by default, invoke `.retry(retryTimes[, retryDelay[, retryOn]])` to set
284
274
  | retryOn | Will be called after request used to control whether the next retry runs. If it return `false`, stop retrying. |
285
275
 
286
276
  ```javascript
287
- import { request } from "keq"
277
+ import { request } from "keq";
288
278
 
289
- await request
290
- .get("http://test.com")
291
- .retry(2, 1000, (attempt, err, ctx) => {
292
- if (err) {
293
- console.log('an error throw')
294
- return true
295
- }
296
-
297
- return false
298
- })
279
+ await request.get("http://test.com").retry(2, 1000, (attempt, err, ctx) => {
280
+ if (err) {
281
+ console.log("an error throw");
282
+ return true;
283
+ }
284
+
285
+ return false;
286
+ });
299
287
  ```
300
288
 
301
289
  ### Set Request Redirect mode
@@ -303,11 +291,9 @@ await request
303
291
  Follow redirect by default, invoke `.redirect(mode)` to set the redirect mode. Allow values are `"error"`, `"manual"` and `"follow"`.
304
292
 
305
293
  ```javascript
306
- import { request } from "keq"
294
+ import { request } from "keq";
307
295
 
308
- await request
309
- .get("http://test.com")
310
- .redirect("manual")
296
+ await request.get("http://test.com").redirect("manual");
311
297
  ```
312
298
 
313
299
  ### Set Request Credentials And Mode
@@ -315,12 +301,9 @@ await request
315
301
  These two parameters are used to control cross-domain requests.
316
302
 
317
303
  ```javascript
318
- import { request } from "keq"
304
+ import { request } from "keq";
319
305
 
320
- await request
321
- .get("http://test.com")
322
- .mode("cors")
323
- .credentials("include")
306
+ await request.get("http://test.com").mode("cors").credentials("include");
324
307
  ```
325
308
 
326
309
  ### Keq Internal Options
@@ -328,7 +311,7 @@ await request
328
311
  Invoke `.option()` add options.
329
312
 
330
313
  ```javascript
331
- import { request } from "keq"
314
+ import { request } from "keq";
332
315
 
333
316
  const response = await request
334
317
  .get("http://test.com")
@@ -337,20 +320,18 @@ const response = await request
337
320
  * when set resolveWithFullResponse
338
321
  */
339
322
  .option("resolveWithFullResponse")
340
- .option("middlewareOption", "value")
323
+ .option("middlewareOption", "value");
341
324
  ```
342
325
 
343
326
  Or as a single object:
344
327
 
345
328
  ```javascript
346
- import { request } from "keq"
329
+ import { request } from "keq";
347
330
 
348
- await request
349
- .get("http://test.com")
350
- .options({
351
- resolveWithFullResponse: true,
352
- middlewareOption: "value",
353
- })
331
+ await request.get("http://test.com").options({
332
+ resolveWithFullResponse: true,
333
+ middlewareOption: "value",
334
+ });
354
335
  ```
355
336
 
356
337
  | **Option** | **Description** |
@@ -462,9 +443,9 @@ Keq's context object has many parameters. The following lists all the built-in c
462
443
 
463
444
  This is the utils used to route middleware.
464
445
 
465
- | **Method** |
466
- | :------------------------------------- |
467
- | `.location(...middlewares)` |
446
+ | **Method** |
447
+ | :------------------------------------------------------- |
448
+ | `.location(...middlewares)` |
468
449
  | `.method(method: string[, ...middlewares])` |
469
450
  | `.pathname(matcher: string \| Regexp[, ...middlewares])` |
470
451
  | `.host(host: string[, ...middlewares])` |
@@ -475,16 +456,14 @@ This is the utils used to route middleware.
475
456
  If you want to create a request instance, you can invoke `request.create()`:
476
457
 
477
458
  ```typescript
478
- import { createRequest } from "keq"
459
+ import { createRequest } from "keq";
479
460
 
480
- const customRequest = createRequest()
461
+ const customRequest = createRequest();
481
462
 
482
463
  // Middleware only takes effect on customRequests
483
- customRequest
484
- .use(/** some middleware */)
464
+ customRequest.use(/** some middleware */);
485
465
 
486
- const body = await customRequest
487
- .get("http://test.com")
466
+ const body = await customRequest.get("http://test.com");
488
467
  ```
489
468
 
490
469
  > The gloabl request instance is created by `request.create()` too.
@@ -505,16 +484,16 @@ The difference between the two is that when called multiple times.
505
484
  `.end ()` will send a request for each call.
506
485
 
507
486
  ```javascript
508
- import { request } from "keq"
487
+ import { request } from "keq";
509
488
 
510
- const keq = request.get("http://test.com")
489
+ const keq = request.get("http://test.com");
511
490
 
512
- keq.then(onfulfilled, onrejected)
491
+ keq.then(onfulfilled, onrejected);
513
492
  // Won't send request, and will use the last request result.
514
- keq.then(onfulfilled, onrejected)
493
+ keq.then(onfulfilled, onrejected);
515
494
 
516
- keq.end()
517
- keq.end()
495
+ keq.end();
496
+ keq.end();
518
497
  ```
519
498
 
520
499
  ### The diffirent between `ctx.res` and `ctx.response`
@@ -535,4 +514,3 @@ Keq is inspired by SuperAgent and Koa.
535
514
  ## Contributing & Development
536
515
 
537
516
  If there is any doubt, it is very welcome to discuss the issue together.
538
- Please read [Contributor Covenant Code of Conduct](.github/CODE_OF_CONDUCT.md) and [CONTRIBUTING](.github/CONTRIBUTING.md).
@@ -0,0 +1,8 @@
1
+ import { KeqMiddleware } from './types/keq-middleware';
2
+ import { KeqRequest } from './types/keq-request';
3
+ interface CreateRequestOptions {
4
+ initMiddlewares?: KeqMiddleware[];
5
+ baseOrigin?: string;
6
+ }
7
+ export declare function createRequest(options?: CreateRequestOptions): KeqRequest;
8
+ export {};
@@ -0,0 +1,126 @@
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", "./router/keq-host-router", "./router/keq-location-router", "./router/keq-method-router", "./router/keq-module-router", "./router/keq-pathname-router", "./is/is-browser", "./keq", "./middlewares/fetch-arguments-middleware", "./middlewares/fetch-middleware", "./middlewares/proxy-response-middleware", "./middlewares/retry-middleware"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createRequest = void 0;
13
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
14
+ const whatwg_url_1 = require("whatwg-url");
15
+ const keq_host_router_1 = require("./router/keq-host-router");
16
+ const keq_location_router_1 = require("./router/keq-location-router");
17
+ const keq_method_router_1 = require("./router/keq-method-router");
18
+ const keq_module_router_1 = require("./router/keq-module-router");
19
+ const keq_pathname_router_1 = require("./router/keq-pathname-router");
20
+ const is_browser_1 = require("./is/is-browser");
21
+ const keq_1 = require("./keq");
22
+ const fetch_arguments_middleware_1 = require("./middlewares/fetch-arguments-middleware");
23
+ const fetch_middleware_1 = require("./middlewares/fetch-middleware");
24
+ const proxy_response_middleware_1 = require("./middlewares/proxy-response-middleware");
25
+ const retry_middleware_1 = require("./middlewares/retry-middleware");
26
+ function createRequest(options) {
27
+ let baseOrigin = options?.baseOrigin;
28
+ if ((0, is_browser_1.isBrowser)() && !baseOrigin)
29
+ baseOrigin = location.origin;
30
+ const appendMiddlewares = options?.initMiddlewares ? [...options.initMiddlewares] : [
31
+ (0, proxy_response_middleware_1.proxyResponseMiddleware)(),
32
+ (0, fetch_arguments_middleware_1.fetchArgumentsMiddleware)(),
33
+ (0, retry_middleware_1.retryMiddleware)(),
34
+ (0, fetch_middleware_1.fetchMiddleware)(),
35
+ ];
36
+ const prependMiddlewares = [];
37
+ const formatUrl = (url) => {
38
+ if (typeof url === 'string') {
39
+ return new whatwg_url_1.URL(url, baseOrigin);
40
+ }
41
+ return new whatwg_url_1.URL(url.href);
42
+ };
43
+ const routerMap = {
44
+ host: (host, ...middlewares) => {
45
+ const route = new keq_host_router_1.KeqHostRouter(host, middlewares);
46
+ prependMiddlewares.push(route.routes());
47
+ return routerMap;
48
+ },
49
+ method: (method, ...middlewares) => {
50
+ const route = new keq_method_router_1.KeqMethodRouter(method, middlewares);
51
+ prependMiddlewares.push(route.routes());
52
+ return routerMap;
53
+ },
54
+ pathname: (pathname, ...middlewares) => {
55
+ const route = new keq_pathname_router_1.KeqPathnameRouter(pathname, middlewares);
56
+ prependMiddlewares.push(route.routes());
57
+ return routerMap;
58
+ },
59
+ location: (...middlewares) => {
60
+ const route = new keq_location_router_1.KeqLocationRouter(middlewares);
61
+ prependMiddlewares.push(route.routes());
62
+ return routerMap;
63
+ },
64
+ module: (moduleName, ...middlewares) => {
65
+ const route = new keq_module_router_1.KeqModuleRouter(moduleName, middlewares);
66
+ prependMiddlewares.push(route.routes());
67
+ return routerMap;
68
+ },
69
+ };
70
+ const request = function (url, init) {
71
+ const keq = new keq_1.Keq(formatUrl(url), init);
72
+ keq.appendMiddlewares(...appendMiddlewares);
73
+ keq.prependMiddlewares(...prependMiddlewares);
74
+ return keq;
75
+ };
76
+ request.baseOrigin = (origin) => {
77
+ baseOrigin = origin;
78
+ };
79
+ request.useRouter = function useRouter() {
80
+ return routerMap;
81
+ };
82
+ request.get = function (url) {
83
+ const keq = new keq_1.Keq(formatUrl(url), { method: 'get' });
84
+ keq.appendMiddlewares(...appendMiddlewares);
85
+ keq.prependMiddlewares(...prependMiddlewares);
86
+ return keq;
87
+ };
88
+ request.put = function (url) {
89
+ const keq = new keq_1.Keq(formatUrl(url), { method: 'put' });
90
+ keq.appendMiddlewares(...appendMiddlewares);
91
+ keq.prependMiddlewares(...prependMiddlewares);
92
+ return keq;
93
+ };
94
+ request.delete = function (url) {
95
+ const keq = new keq_1.Keq(formatUrl(url), { method: 'delete' });
96
+ keq.appendMiddlewares(...appendMiddlewares);
97
+ keq.prependMiddlewares(...prependMiddlewares);
98
+ return keq;
99
+ };
100
+ request.del = request.delete;
101
+ request.post = function (url) {
102
+ const keq = new keq_1.Keq(formatUrl(url), { method: 'post' });
103
+ keq.appendMiddlewares(...appendMiddlewares);
104
+ keq.prependMiddlewares(...prependMiddlewares);
105
+ return keq;
106
+ };
107
+ request.head = function (url) {
108
+ const keq = new keq_1.Keq(formatUrl(url), { method: 'head' });
109
+ keq.appendMiddlewares(...appendMiddlewares);
110
+ keq.prependMiddlewares(...prependMiddlewares);
111
+ return keq;
112
+ };
113
+ request.patch = function (url) {
114
+ const keq = new keq_1.Keq(formatUrl(url), { method: 'patch' });
115
+ keq.appendMiddlewares(...appendMiddlewares);
116
+ keq.prependMiddlewares(...prependMiddlewares);
117
+ return keq;
118
+ };
119
+ request.use = function use(middleware, ...middlewares) {
120
+ prependMiddlewares.push(middleware, ...middlewares);
121
+ return request;
122
+ };
123
+ return request;
124
+ }
125
+ exports.createRequest = createRequest;
126
+ });
@@ -0,0 +1,4 @@
1
+ import { Exception } from './exception';
2
+ export declare class FileExpectedException 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.FileExpectedException = void 0;
13
+ const exception_1 = require("./exception");
14
+ class FileExpectedException extends exception_1.Exception {
15
+ constructor() {
16
+ super('File/Blob (Browser) or Buffer (NodeJS) expected');
17
+ }
18
+ }
19
+ exports.FileExpectedException = FileExpectedException;
20
+ });
@@ -0,0 +1,13 @@
1
+ export { createRequest } from './create-request';
2
+ export { Keq } from './keq';
3
+ export { composeMiddleware } from './middleware';
4
+ export { request } from './request';
5
+ export { KeqContext } from './types/keq-context';
6
+ export { KeqMiddleware } from './types/keq-middleware';
7
+ export { KeqNext } from './types/keq-next';
8
+ export { KeqOptions } from './types/keq-options';
9
+ export { KeqRequest } from './types/keq-request';
10
+ export { KeqRequestBody } from './types/keq-request-body';
11
+ export { KeqRequestInit } from './types/keq-request-init';
12
+ export { KeqRetryDelay } from './types/keq-retry-delay';
13
+ export { KeqRetryOn } from './types/keq-retry-on';
@@ -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", "./create-request", "./keq", "./middleware", "./request"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.request = exports.composeMiddleware = exports.Keq = exports.createRequest = void 0;
13
+ var create_request_1 = require("./create-request");
14
+ Object.defineProperty(exports, "createRequest", { enumerable: true, get: function () { return create_request_1.createRequest; } });
15
+ var keq_1 = require("./keq");
16
+ Object.defineProperty(exports, "Keq", { enumerable: true, get: function () { return keq_1.Keq; } });
17
+ var middleware_1 = require("./middleware");
18
+ Object.defineProperty(exports, "composeMiddleware", { enumerable: true, get: function () { return middleware_1.composeMiddleware; } });
19
+ var request_1 = require("./request");
20
+ Object.defineProperty(exports, "request", { enumerable: true, get: function () { return request_1.request; } });
21
+ });
@@ -0,0 +1 @@
1
+ export declare const request: import(".").KeqRequest;
@@ -0,0 +1,15 @@
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", "./create-request"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.request = void 0;
13
+ const create_request_1 = require("./create-request");
14
+ exports.request = (0, create_request_1.createRequest)();
15
+ });
package/package.json CHANGED
@@ -1,9 +1,6 @@
1
1
  {
2
2
  "name": "keq",
3
- "version": "2.0.2",
4
- "main": "dist/umd/src/index.js",
5
- "types": "dist/esm/src/index.d.ts",
6
- "module": "dist/esm/src/index.js",
3
+ "version": "2.0.7",
7
4
  "description": "Request API write by Typescript for flexibility, readability, and a low learning curve.",
8
5
  "keywords": [
9
6
  "request",
@@ -15,62 +12,67 @@
15
12
  "middleware",
16
13
  "middlewares"
17
14
  ],
18
- "homepage": "https://github.com/Val-istar-Guo/keq#readme",
15
+ "homepage": "https://github.com/keq-request/keq#readme",
19
16
  "bugs": {
20
- "url": "https://github.com/Val-istar-Guo/keq/issues"
17
+ "url": "https://github.com/keq-request/keq/issues"
21
18
  },
22
19
  "repository": {
23
20
  "type": "git",
24
- "url": "git+https://github.com/Val-istar-Guo/keq.git"
21
+ "url": "git+https://github.com/keq-request/keq.git"
25
22
  },
26
23
  "license": "MIT",
27
24
  "author": "Val.istar.Guo <val.istar.guo@gmail.com>",
25
+ "main": "dist/umd/src/index.js",
26
+ "module": "dist/esm/src/index.js",
27
+ "types": "dist/esm/src/index.d.ts",
28
28
  "directories": {
29
29
  "doc": "doc",
30
30
  "test": "test"
31
31
  },
32
- "engines": {
33
- "node": ">=18.0.0"
34
- },
35
32
  "scripts": {
33
+ "build": "npm run clean && ./build/build.sh",
34
+ "clean": "rm -rf ./dist/*",
35
+ "dev": "npm run clean && ./build/watch.sh",
36
36
  "prepare": "ts-patch install -s && is-ci || husky install",
37
+ "prepublishOnly": "npm run build",
37
38
  "release": "standard-version",
38
39
  "release:alpha": "standard-version --prerelease alpha",
39
- "test": "jest",
40
- "prepublishOnly": "npm run build",
41
- "clean": "rm -rf ./dist/*",
42
- "build": "npm run clean && ./build/build.sh",
43
- "dev": "npm run clean && ./build/watch.sh"
40
+ "test": "jest"
41
+ },
42
+ "dependencies": {
43
+ "clone": "^2.1.2",
44
+ "minimatch": "^9.0.3",
45
+ "object.fromentries": "^2.0.7",
46
+ "path-to-regexp": "^6.2.1",
47
+ "ts-custom-error": "^3.3.1",
48
+ "whatwg-url": "^14.0.0"
44
49
  },
45
50
  "devDependencies": {
46
- "@buka/eslint-config": "^1.4.1",
47
- "@commitlint/cli": "^17.7.1",
48
- "@commitlint/config-conventional": "^17.7.0",
51
+ "@buka/eslint-config": "^1.5.0",
52
+ "@commitlint/cli": "^18.2.0",
53
+ "@commitlint/config-conventional": "^18.1.0",
49
54
  "@jest/globals": "^29.7.0",
50
- "@rushstack/eslint-patch": "^1.4.0",
51
- "@types/clone": "^2.1.2",
55
+ "@rushstack/eslint-patch": "^1.5.1",
56
+ "@types/clone": "^2.1.4",
52
57
  "@types/minimatch": "^5.1.2",
53
- "@types/node": "^20.6.5",
54
- "@types/whatwg-url": "^11.0.0",
55
- "@typescript-eslint/eslint-plugin": "^6.7.2",
56
- "@typescript-eslint/parser": "^6.7.2",
57
- "eslint": "^8.50.0",
58
+ "@types/node": "^20.9.0",
59
+ "@types/whatwg-url": "^11.0.3",
60
+ "@typescript-eslint/eslint-plugin": "^6.10.0",
61
+ "@typescript-eslint/parser": "^6.10.0",
62
+ "eslint": "^8.53.0",
58
63
  "husky": "^8.0.3",
59
64
  "is-ci": "^3.0.1",
60
65
  "jest": "^29.7.0",
61
66
  "jest-mock": "^29.7.0",
62
67
  "standard-version": "^9.5.0",
63
68
  "ts-jest": "^29.1.1",
69
+ "ts-node": "^10.9.1",
64
70
  "ts-patch": "^3.0.2",
65
71
  "typescript": "^5.2.2",
66
72
  "typescript-transform-paths": "^3.4.6"
67
73
  },
68
- "dependencies": {
69
- "clone": "^2.1.2",
70
- "minimatch": "^9.0.3",
71
- "object.fromentries": "^2.0.7",
72
- "path-to-regexp": "^6.2.1",
73
- "ts-custom-error": "^3.3.1",
74
- "whatwg-url": "^13.0.0"
74
+ "packageManager": "pnpm@8.7.6",
75
+ "engines": {
76
+ "node": ">=18.0.0"
75
77
  }
76
78
  }
package/tsconfig.json CHANGED
@@ -6,6 +6,7 @@
6
6
  "noImplicitAny": false,
7
7
  "declaration": true,
8
8
  "noEmitOnError": true,
9
+ "resolveJsonModule": true,
9
10
  "skipLibCheck": true,
10
11
  "moduleResolution": "node",
11
12
  "module": "ESNext",