keq 1.6.3 → 1.6.5

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 (235) hide show
  1. package/.editorconfig +0 -4
  2. package/.eslintignore +1 -2
  3. package/.husky/pre-commit +0 -2
  4. package/.milirc.yml +4 -9
  5. package/CHANGELOG.md +14 -0
  6. package/README.md +4 -3
  7. package/build/tsconfig.es.json +1 -1
  8. package/build/tsconfig.lib.json +1 -1
  9. package/es/index.js +1 -0
  10. package/es/package.json +16 -16
  11. package/es/src/exception/exception.d.ts +4 -0
  12. package/es/src/exception/exception.js +7 -0
  13. package/es/src/exception/file-expected.exception.d.ts +4 -0
  14. package/es/src/exception/file-expected.exception.js +6 -0
  15. package/es/src/exception/file-expected.exception.ts +8 -0
  16. package/es/src/exception/index.d.ts +4 -0
  17. package/es/src/exception/index.js +4 -0
  18. package/es/src/exception/overwrite-array-body.exception.d.ts +4 -0
  19. package/es/src/exception/overwrite-array-body.exception.js +6 -0
  20. package/es/src/exception/overwrite-array-body.exception.ts +8 -0
  21. package/es/src/exception/unknow-content-type.exception.d.ts +4 -0
  22. package/es/src/exception/unknow-content-type.exception.js +6 -0
  23. package/es/src/exception/unknow-content-type.exception.ts +8 -0
  24. package/es/src/form-data-node/index.js +1 -1
  25. package/es/src/form-data-node/util/file.js +1 -1
  26. package/es/src/form-data-node/util/get-length.js +3 -2
  27. package/es/src/form-data-node/util/get-stream-iterator.js +1 -1
  28. package/es/src/form-data-node/util/to-file.js +1 -1
  29. package/es/src/index.d.ts +2 -3
  30. package/es/src/index.js +2 -4
  31. package/es/src/keq.d.ts +1 -7
  32. package/es/src/keq.js +28 -33
  33. package/es/src/middleware.d.ts +1 -4
  34. package/es/src/middleware.js +2 -1
  35. package/es/src/mount.d.ts +4 -8
  36. package/es/src/mount.js +5 -1
  37. package/es/src/polyfill.js +2 -2
  38. package/es/src/request.d.ts +1 -24
  39. package/es/src/types/context.d.ts +27 -0
  40. package/es/src/{context.js → types/context.js} +0 -0
  41. package/es/src/types/index.d.ts +11 -0
  42. package/es/src/types/index.js +11 -0
  43. package/es/src/types/keq-body.d.ts +1 -0
  44. package/es/src/{form-data-fields.js → types/keq-body.js} +0 -0
  45. package/es/src/types/keq-url.d.ts +5 -0
  46. package/es/src/types/keq-url.js +1 -0
  47. package/es/src/types/middleware.d.ts +4 -0
  48. package/es/src/types/middleware.js +1 -0
  49. package/es/src/types/mounter.d.ts +7 -0
  50. package/es/src/types/mounter.js +1 -0
  51. package/es/src/{context.d.ts → types/options.d.ts} +8 -32
  52. package/es/src/types/options.js +1 -0
  53. package/es/src/types/request-creator.d.ts +25 -0
  54. package/es/src/types/request-creator.js +1 -0
  55. package/es/src/types/request-method.d.ts +1 -0
  56. package/es/src/types/request-method.js +1 -0
  57. package/es/src/types/retry-callback.d.ts +1 -0
  58. package/es/src/types/retry-callback.js +1 -0
  59. package/es/src/types/serialize-body-fn.d.ts +3 -0
  60. package/es/src/types/serialize-body-fn.js +1 -0
  61. package/es/src/{fix-type.d.ts → types/shorthand-content-type.d.ts} +0 -1
  62. package/es/src/types/shorthand-content-type.js +1 -0
  63. package/es/src/{base64.d.ts → util/encode-base64.d.ts} +0 -0
  64. package/es/src/util/encode-base64.js +4 -0
  65. package/es/src/util/fix-content-type.d.ts +2 -0
  66. package/es/src/{fix-type.js → util/fix-content-type.js} +1 -1
  67. package/es/src/util/get-boundary-by-content-type.d.ts +1 -0
  68. package/es/src/util/get-boundary-by-content-type.js +10 -0
  69. package/es/src/util/index.d.ts +8 -0
  70. package/es/src/util/index.js +8 -0
  71. package/es/src/util/infer-content-type-by-body.d.ts +2 -0
  72. package/es/src/{get-type-by-body.js → util/infer-content-type-by-body.js} +1 -4
  73. package/es/src/{form-data-node/util → util}/is/index.d.ts +3 -0
  74. package/es/src/{form-data-node/util → util}/is/index.js +3 -0
  75. package/es/src/{form-data-node/util → util}/is/is-blob.d.ts +0 -0
  76. package/es/src/{form-data-node/util → util}/is/is-blob.js +0 -0
  77. package/es/src/util/is/is-browser.d.ts +1 -0
  78. package/es/src/util/is/is-browser.js +3 -0
  79. package/es/src/util/is/is-file.d.ts +1 -0
  80. package/es/src/util/is/is-file.js +7 -0
  81. package/es/src/util/is/is-form-data.d.ts +1 -0
  82. package/es/src/util/is/is-form-data.js +12 -0
  83. package/es/src/{form-data-node/util → util}/is/is-function.d.ts +0 -0
  84. package/es/src/{form-data-node/util → util}/is/is-function.js +0 -0
  85. package/es/src/{form-data-node/util → util}/is/is-object.d.ts +0 -0
  86. package/es/src/{form-data-node/util → util}/is/is-object.js +0 -0
  87. package/es/src/{form-data-node/util → util}/is/is-read-stream.d.ts +0 -0
  88. package/es/src/{form-data-node/util → util}/is/is-read-stream.js +0 -0
  89. package/es/src/{form-data-node/util → util}/is/is-readable.d.ts +0 -0
  90. package/es/src/{form-data-node/util → util}/is/is-readable.js +0 -0
  91. package/es/src/{form-data-node/util → util}/is/is-stream.d.ts +0 -0
  92. package/es/src/{form-data-node/util → util}/is/is-stream.js +0 -0
  93. package/es/src/{form-data-node/util → util}/is/is-string.d.ts +0 -0
  94. package/es/src/{form-data-node/util → util}/is/is-string.js +0 -0
  95. package/es/src/{form-data-node/util → util}/is/is-whatwg-readable.d.ts +0 -0
  96. package/es/src/{form-data-node/util → util}/is/is-whatwg-readable.js +0 -0
  97. package/es/src/{parse-form-data.d.ts → util/parse-form-data.d.ts} +0 -1
  98. package/es/src/{parse-form-data.js → util/parse-form-data.js} +3 -11
  99. package/es/src/util/serialize-body.d.ts +6 -0
  100. package/es/src/{serialize.js → util/serialize-body.js} +11 -13
  101. package/es/src/{sleep.d.ts → util/sleep.d.ts} +0 -0
  102. package/es/src/{sleep.js → util/sleep.js} +0 -0
  103. package/index.ts +1 -0
  104. package/lib/index.js +17 -6
  105. package/lib/package.json +16 -16
  106. package/lib/src/exception/exception.d.ts +4 -0
  107. package/lib/src/exception/exception.js +21 -0
  108. package/lib/src/exception/file-expected.exception.d.ts +4 -0
  109. package/lib/src/exception/file-expected.exception.js +20 -0
  110. package/lib/src/exception/file-expected.exception.ts +8 -0
  111. package/lib/src/exception/index.d.ts +4 -0
  112. package/lib/src/exception/index.js +26 -0
  113. package/lib/src/exception/overwrite-array-body.exception.d.ts +4 -0
  114. package/lib/src/exception/overwrite-array-body.exception.js +20 -0
  115. package/lib/src/exception/overwrite-array-body.exception.ts +8 -0
  116. package/lib/src/exception/unknow-content-type.exception.d.ts +4 -0
  117. package/lib/src/exception/unknow-content-type.exception.js +20 -0
  118. package/lib/src/exception/unknow-content-type.exception.ts +8 -0
  119. package/lib/src/form-data-node/index.js +395 -385
  120. package/lib/src/form-data-node/util/boundary.js +19 -9
  121. package/lib/src/form-data-node/util/file.js +65 -55
  122. package/lib/src/form-data-node/util/get-length.js +44 -33
  123. package/lib/src/form-data-node/util/get-stream-iterator.js +27 -17
  124. package/lib/src/form-data-node/util/get-type.js +38 -28
  125. package/lib/src/form-data-node/util/read-only.js +19 -9
  126. package/lib/src/form-data-node/util/readable-stream-iterator.js +30 -20
  127. package/lib/src/form-data-node/util/to-file.js +33 -23
  128. package/lib/src/index.d.ts +2 -3
  129. package/lib/src/index.js +20 -11
  130. package/lib/src/keq.d.ts +1 -7
  131. package/lib/src/keq.js +373 -368
  132. package/lib/src/middleware.d.ts +1 -4
  133. package/lib/src/middleware.js +46 -35
  134. package/lib/src/mount.d.ts +4 -8
  135. package/lib/src/mount.js +59 -45
  136. package/lib/src/polyfill.js +20 -10
  137. package/lib/src/request.d.ts +1 -24
  138. package/lib/src/request.js +65 -55
  139. package/lib/src/types/context.d.ts +27 -0
  140. package/lib/src/types/context.js +12 -0
  141. package/lib/src/types/index.d.ts +11 -0
  142. package/lib/src/types/index.js +33 -0
  143. package/lib/src/types/keq-body.d.ts +1 -0
  144. package/lib/src/types/keq-body.js +12 -0
  145. package/lib/src/types/keq-url.d.ts +5 -0
  146. package/lib/src/types/keq-url.js +12 -0
  147. package/lib/src/types/middleware.d.ts +4 -0
  148. package/lib/src/types/middleware.js +12 -0
  149. package/lib/src/types/mounter.d.ts +7 -0
  150. package/lib/src/types/mounter.js +12 -0
  151. package/lib/src/{context.d.ts → types/options.d.ts} +8 -32
  152. package/lib/src/types/options.js +12 -0
  153. package/lib/src/types/request-creator.d.ts +25 -0
  154. package/lib/src/types/request-creator.js +12 -0
  155. package/lib/src/types/request-method.d.ts +1 -0
  156. package/lib/src/types/request-method.js +12 -0
  157. package/lib/src/types/retry-callback.d.ts +1 -0
  158. package/lib/src/types/retry-callback.js +12 -0
  159. package/lib/src/types/serialize-body-fn.d.ts +3 -0
  160. package/lib/src/types/serialize-body-fn.js +12 -0
  161. package/lib/src/{fix-type.d.ts → types/shorthand-content-type.d.ts} +0 -1
  162. package/lib/src/types/shorthand-content-type.js +12 -0
  163. package/lib/src/{base64.d.ts → util/encode-base64.d.ts} +0 -0
  164. package/lib/src/util/encode-base64.js +18 -0
  165. package/lib/src/util/fix-content-type.d.ts +2 -0
  166. package/lib/src/util/fix-content-type.js +30 -0
  167. package/lib/src/util/get-boundary-by-content-type.d.ts +1 -0
  168. package/lib/src/util/get-boundary-by-content-type.js +24 -0
  169. package/lib/src/util/index.d.ts +8 -0
  170. package/lib/src/util/index.js +30 -0
  171. package/lib/src/util/infer-content-type-by-body.d.ts +2 -0
  172. package/lib/src/util/infer-content-type-by-body.js +21 -0
  173. package/lib/src/{form-data-node/util → util}/is/index.d.ts +3 -0
  174. package/lib/src/util/is/index.js +33 -0
  175. package/lib/src/{form-data-node/util → util}/is/is-blob.d.ts +0 -0
  176. package/lib/src/util/is/is-blob.js +30 -0
  177. package/lib/src/util/is/is-browser.d.ts +1 -0
  178. package/lib/src/util/is/is-browser.js +17 -0
  179. package/lib/src/util/is/is-file.d.ts +1 -0
  180. package/lib/src/util/is/is-file.js +21 -0
  181. package/lib/src/util/is/is-form-data.d.ts +1 -0
  182. package/lib/src/util/is/is-form-data.js +26 -0
  183. package/lib/src/{form-data-node/util → util}/is/is-function.d.ts +0 -0
  184. package/lib/src/util/is/is-function.js +17 -0
  185. package/lib/src/{form-data-node/util → util}/is/is-object.d.ts +0 -0
  186. package/lib/src/util/is/is-object.js +17 -0
  187. package/lib/src/{form-data-node/util → util}/is/is-read-stream.d.ts +0 -0
  188. package/lib/src/util/is/is-read-stream.js +26 -0
  189. package/lib/src/{form-data-node/util → util}/is/is-readable.d.ts +0 -0
  190. package/lib/src/util/is/is-readable.js +18 -0
  191. package/lib/src/{form-data-node/util → util}/is/is-stream.d.ts +0 -0
  192. package/lib/src/util/is/is-stream.js +23 -0
  193. package/lib/src/{form-data-node/util → util}/is/is-string.d.ts +0 -0
  194. package/lib/src/util/is/is-string.js +17 -0
  195. package/lib/src/{form-data-node/util → util}/is/is-whatwg-readable.d.ts +0 -0
  196. package/lib/src/util/is/is-whatwg-readable.js +34 -0
  197. package/lib/src/{parse-form-data.d.ts → util/parse-form-data.d.ts} +0 -1
  198. package/lib/src/util/parse-form-data.js +143 -0
  199. package/lib/src/util/serialize-body.d.ts +6 -0
  200. package/lib/src/util/serialize-body.js +67 -0
  201. package/lib/src/{sleep.d.ts → util/sleep.d.ts} +0 -0
  202. package/lib/src/util/sleep.js +17 -0
  203. package/package.json +16 -16
  204. package/es/src/base64.js +0 -4
  205. package/es/src/const.d.ts +0 -5
  206. package/es/src/const.js +0 -5
  207. package/es/src/form-data-fields.d.ts +0 -6
  208. package/es/src/get-type-by-body.d.ts +0 -5
  209. package/es/src/serialize.d.ts +0 -8
  210. package/es/src/utils.d.ts +0 -3
  211. package/es/src/utils.js +0 -37
  212. package/lib/src/base64.js +0 -8
  213. package/lib/src/const.d.ts +0 -5
  214. package/lib/src/const.js +0 -8
  215. package/lib/src/context.js +0 -2
  216. package/lib/src/fix-type.js +0 -20
  217. package/lib/src/form-data-fields.d.ts +0 -6
  218. package/lib/src/form-data-fields.js +0 -2
  219. package/lib/src/form-data-node/util/is/index.js +0 -20
  220. package/lib/src/form-data-node/util/is/is-blob.js +0 -20
  221. package/lib/src/form-data-node/util/is/is-function.js +0 -7
  222. package/lib/src/form-data-node/util/is/is-object.js +0 -7
  223. package/lib/src/form-data-node/util/is/is-read-stream.js +0 -16
  224. package/lib/src/form-data-node/util/is/is-readable.js +0 -8
  225. package/lib/src/form-data-node/util/is/is-stream.js +0 -13
  226. package/lib/src/form-data-node/util/is/is-string.js +0 -7
  227. package/lib/src/form-data-node/util/is/is-whatwg-readable.js +0 -24
  228. package/lib/src/get-type-by-body.d.ts +0 -5
  229. package/lib/src/get-type-by-body.js +0 -14
  230. package/lib/src/parse-form-data.js +0 -142
  231. package/lib/src/serialize.d.ts +0 -8
  232. package/lib/src/serialize.js +0 -59
  233. package/lib/src/sleep.js +0 -7
  234. package/lib/src/utils.d.ts +0 -3
  235. package/lib/src/utils.js +0 -42
package/.editorconfig CHANGED
@@ -1,6 +1,3 @@
1
- # This file is for unifying the coding style for different editors and IDEs
2
- # editorconfig.org
3
-
4
1
  root = true
5
2
 
6
3
  [{**,[!node_modules/**]}]
@@ -9,5 +6,4 @@ end_of_line = lf
9
6
  indent_size = 2
10
7
  indent_style = space
11
8
  insert_final_newline = true
12
- # 设为true表示会除去换行行首的任意空白字符
13
9
  trim_trailing_whitespace = true
package/.eslintignore CHANGED
@@ -1,4 +1,3 @@
1
- # Dist
2
1
  /lib
3
2
  /es
4
- *.js
3
+ /dist
package/.husky/pre-commit CHANGED
@@ -1,6 +1,4 @@
1
1
  #!/bin/sh
2
2
  . "$(dirname "$0")/_/husky.sh"
3
3
 
4
- npm test
5
4
  npx --no-install lint-staged
6
- npx --no-install mili check --diff --no-deps --ignore "**/node_modules"
package/.milirc.yml CHANGED
@@ -1,11 +1,6 @@
1
- mili:
2
- version: 3.9.2
3
- template:
4
- repository: 'npm:@mtpl/component'
5
- version: 3.1.0
1
+ template: npm:@mtpl/component
2
+ version: 4.2.0
6
3
  answers:
7
- ci: true
8
- standardVersion: true
9
- lint: true
4
+ travis: true
10
5
  lock: false
11
- module: commonjs
6
+ module: umd
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
+ ### [1.6.5](https://www.github.com/keq-request/keq/compare/v1.6.4...v1.6.5) (2021-12-13)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * iterator cannot be looped ([022ca72](https://www.github.com/keq-request/keq/commit/022ca72f88788980207bcb36114138ef292230cd))
11
+
12
+ ### [1.6.4](https://www.github.com/keq-request/keq/compare/v1.6.3...v1.6.4) (2021-12-13)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * the default array formatting of query is nonstandard ([229e08c](https://www.github.com/keq-request/keq/commit/229e08c79881fd332784b7f1c3207c410f985f89))
18
+
5
19
  ### [1.6.3](https://www.github.com/keq-request/keq/compare/v1.6.2...v1.6.3) (2021-12-07)
6
20
 
7
21
 
package/README.md CHANGED
@@ -9,8 +9,8 @@
9
9
  [![version](https://img.shields.io/npm/v/keq.svg?style=flat-square)](https://www.npmjs.com/package/keq)
10
10
  [![downloads](https://img.shields.io/npm/dm/keq.svg?style=flat-square)](https://www.npmjs.com/package/keq)
11
11
  [![license](https://img.shields.io/npm/l/keq.svg?style=flat-square)](https://www.npmjs.com/package/keq)
12
- [![dependencies](https://img.shields.io/david/Val-istar-Guo/keq.svg?style=flat-square)](https://www.npmjs.com/package/keq)
13
- [![coveralls](https://img.shields.io/coveralls/github/Val-istar-Guo/keq.svg?style=flat-square)](https://coveralls.io/github/Val-istar-Guo/keq)
12
+ [![dependencies](https://img.shields.io/david/keq-request/keq.svg?style=flat-square)](https://www.npmjs.com/package/keq)
13
+ [![coveralls](https://img.shields.io/coveralls/github/keq-request/keq.svg?style=flat-square)](https://coveralls.io/github/keq-request/keq)
14
14
 
15
15
 
16
16
 
@@ -482,13 +482,14 @@ Keq is inspired by SuperAgent and Koa.
482
482
 
483
483
  - [Superagent](https://visionmedia.github.io/superagent/#test-documentation)
484
484
  - [Koa](https://koajs.com/)
485
- <!-- addition -->
486
485
 
487
486
  ## Sponsor
488
487
 
489
488
  Support code development on patron.
490
489
 
491
490
  [![patron](https://c5.patreon.com/external/logo/become_a_patron_button@2x.png)](https://www.patreon.com/bePatron?u=22478507)
491
+ <!-- addition -->
492
+
492
493
 
493
494
  ## Contributing & Development
494
495
 
@@ -2,7 +2,7 @@
2
2
  "extends": "../tsconfig.json",
3
3
  "compilerOptions": {
4
4
  "outDir": "../es",
5
- "module": "es6",
5
+ "module": "esnext",
6
6
  "target": "es6"
7
7
  }
8
8
  }
@@ -2,7 +2,7 @@
2
2
  "extends": "../tsconfig.json",
3
3
  "compilerOptions": {
4
4
  "outDir": "../lib",
5
- "module": "commonjs",
5
+ "module": "umd",
6
6
  "target": "es6"
7
7
  }
8
8
  }
package/es/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./src/index";
2
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
3
  /** @ts-ignore */
3
4
  import defaultExport from "./src/index";
4
5
  export default defaultExport;
package/es/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "keq",
3
3
  "main": "lib/index.js",
4
4
  "module": "es/index.js",
5
- "version": "1.6.3",
5
+ "version": "1.6.5",
6
6
  "license": "MIT",
7
7
  "types": "lib/index.d.ts",
8
8
  "scripts": {
@@ -13,44 +13,43 @@
13
13
  "coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
14
14
  "ci": "git-cz",
15
15
  "ca": "git add -A && git-cz -av",
16
- "release": "standard-version --no-verify",
16
+ "release": "standard-version",
17
17
  "release:alpha": "standard-version --prerelease alpha",
18
18
  "release:first": "standard-version --first-release",
19
- "prepublishOnly": "npm test && npm run build && pinst --disable",
20
- "postpublish": "pinst --enable && git push",
19
+ "prepublishOnly": "npm run build",
21
20
  "clean": "rm -rf ./lib/*",
22
21
  "prebuild": "npm run clean",
23
22
  "build:es": "ttsc -p build/tsconfig.es.json && npm run copyfile:es",
24
23
  "build:lib": "ttsc -p build/tsconfig.lib.json && npm run copyfile:lib",
25
24
  "build": "npm run build:lib && npm run build:es",
26
25
  "watch": "NODE_ENV=development ttsc -p build/tsconfig.lib.json -w",
27
- "postinstall": "is-ci || husky install",
28
26
  "copyfile:es": "copyfiles -e \"@(build|es|lib|node_modules|tests|doc)/**/*.!(ts)\" -e \"@(README.md|CHANGELOG.md|ava.config.js|backers.md)\" \"**/*.!(ts)\" es",
29
27
  "copyfile:lib": "copyfiles -e \"@(build|es|lib|node_modules|tests|doc)/**/*.!(ts)\" -e \"@(README.md|CHANGELOG.md|ava.config.js|backers.md)\" \"**/*.!(ts)\" lib",
30
- "prewatch": "npm run copyfile:lib"
28
+ "prewatch": "npm run copyfile:lib",
29
+ "lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\" --fix",
30
+ "prepare": "is-ci || husky install"
31
31
  },
32
32
  "devDependencies": {
33
- "@commitlint/cli": "^12.0.0",
34
- "@commitlint/config-conventional": "^12.0.0",
33
+ "@commitlint/cli": "^12.1.4",
34
+ "@commitlint/config-conventional": "^12.1.4",
35
35
  "@istanbuljs/nyc-config-typescript": "^1.0.1",
36
36
  "@types/sinon": "^9.0.4",
37
37
  "@typescript-eslint/eslint-plugin": "^4.15.2",
38
38
  "@typescript-eslint/parser": "^4.15.2",
39
- "ajv": "^8.6.3",
39
+ "ajv": "^8",
40
40
  "ava": "^3.10.1",
41
- "commitizen": "^4.2.3",
41
+ "commitizen": "^4.2.4",
42
42
  "copyfiles": "^2.4.1",
43
43
  "coveralls": "^3.1.0",
44
- "cz-conventional-changelog": "^3.2.0",
44
+ "cz-conventional-changelog": "^3.3.0",
45
45
  "eslint": "^7.20.0",
46
- "husky": "^5.1.1",
46
+ "husky": "^5.2.0",
47
47
  "is-ci": "^3.0.0",
48
48
  "lint-staged": "^11.0.0",
49
- "mili": "^3.9.3",
49
+ "mili": "^4",
50
50
  "nyc": "^15.1.0",
51
- "pinst": "^2.1.6",
52
51
  "sinon": "^10.0.0",
53
- "standard-version": "^9.1.1",
52
+ "standard-version": "^9.3.0",
54
53
  "ts-node": "^9.1.1",
55
54
  "ttypescript": "^1.5.12",
56
55
  "typescript": "^4.2.2",
@@ -61,12 +60,13 @@
61
60
  "blob": "^0.1.0",
62
61
  "clone": "^2.1.2",
63
62
  "cross-fetch": "^3.0.6",
64
- "formidable": "^2.0.0-canary.20200226.1",
63
+ "formidable": "^2.0.1",
65
64
  "mime-types": "^2.1.27",
66
65
  "nanoid": "^3.1.10",
67
66
  "path-to-regexp": "^6.2.0",
68
67
  "picomatch": "^2.2.2",
69
68
  "querystring": "^0.2.0",
69
+ "ts-custom-error": "^3.2.0",
70
70
  "url": "^0.11.0"
71
71
  },
72
72
  "description": "Request API write by Typescript for flexibility, readability, and a low learning curve.",
@@ -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,7 @@
1
+ import { CustomError } from 'ts-custom-error';
2
+ export class Exception extends CustomError {
3
+ constructor(message) {
4
+ super(message);
5
+ Object.defineProperty(this, 'name', { value: 'KeqError' });
6
+ }
7
+ }
@@ -0,0 +1,4 @@
1
+ import { Exception } from "./exception";
2
+ export declare class FileExpectedException extends Exception {
3
+ constructor();
4
+ }
@@ -0,0 +1,6 @@
1
+ import { Exception } from "./exception";
2
+ export class FileExpectedException extends Exception {
3
+ constructor() {
4
+ super('File/Blob (Browser) or Buffer (NodeJS) expected');
5
+ }
6
+ }
@@ -0,0 +1,8 @@
1
+ import { Exception } from './exception'
2
+
3
+
4
+ export class FileExpectedException extends Exception {
5
+ constructor() {
6
+ super('File/Blob (Browser) or Buffer (NodeJS) expected')
7
+ }
8
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./exception";
2
+ export * from "./file-expected.exception";
3
+ export * from "./overwrite-array-body.exception";
4
+ export * from "./unknow-content-type.exception";
@@ -0,0 +1,4 @@
1
+ export * from "./exception";
2
+ export * from "./file-expected.exception";
3
+ export * from "./overwrite-array-body.exception";
4
+ export * from "./unknow-content-type.exception";
@@ -0,0 +1,4 @@
1
+ import { Exception } from "./exception";
2
+ export declare class OverwriteArrayBodyException extends Exception {
3
+ constructor();
4
+ }
@@ -0,0 +1,6 @@
1
+ import { Exception } from "./exception";
2
+ export class OverwriteArrayBodyException extends Exception {
3
+ constructor() {
4
+ super('Cannot merge or overwrite body. Because it has been set as an array.');
5
+ }
6
+ }
@@ -0,0 +1,8 @@
1
+ import { Exception } from './exception'
2
+
3
+
4
+ export class OverwriteArrayBodyException extends Exception {
5
+ constructor() {
6
+ super('Cannot merge or overwrite body. Because it has been set as an array.')
7
+ }
8
+ }
@@ -0,0 +1,4 @@
1
+ import { Exception } from "./exception";
2
+ export declare class UnknowContentTypeException extends Exception {
3
+ constructor();
4
+ }
@@ -0,0 +1,6 @@
1
+ import { Exception } from "./exception";
2
+ export class UnknowContentTypeException extends Exception {
3
+ constructor() {
4
+ super('Unknow Content-Type');
5
+ }
6
+ }
@@ -0,0 +1,8 @@
1
+ import { Exception } from './exception'
2
+
3
+
4
+ export class UnknowContentTypeException extends Exception {
5
+ constructor() {
6
+ super('Unknow Content-Type')
7
+ }
8
+ }
@@ -38,9 +38,9 @@ import { basename } from 'path';
38
38
  import * as mimes from 'mime-types';
39
39
  import getStreamIterator from "./util/get-stream-iterator";
40
40
  import getLength from "./util/get-length";
41
- import { isObject, isStream, isBlob } from "./util/is";
42
41
  import boundary from "./util/boundary";
43
42
  import toFile from "./util/to-file";
43
+ import { isObject, isStream, isBlob } from "../util/is";
44
44
  const { isBuffer } = Buffer;
45
45
  const { isArray } = Array;
46
46
  const { freeze } = Object;
@@ -17,7 +17,7 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
17
17
  import { Readable } from 'stream';
18
18
  import * as mime from 'mime-types';
19
19
  import getStreamIterator from "./get-stream-iterator";
20
- import { isBlob } from "./is";
20
+ import { isBlob } from "../../util";
21
21
  const { isBuffer } = Buffer;
22
22
  /**
23
23
  * @api private
@@ -8,7 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- import { isReadStream, isStream, isBlob } from "./is";
11
+ import { isReadStream, isStream, isBlob } from "../../util";
12
+ import { Exception } from "../../exception";
12
13
  const { isBuffer } = Buffer;
13
14
  /**
14
15
  * Get lenght of given value (in bytes)
@@ -28,7 +29,7 @@ function getLength(value) {
28
29
  /**
29
30
  * In order to compatible browser
30
31
  */
31
- throw new Error('Read Stream is not supported by Keq FormData');
32
+ throw new Exception('Read Stream is not supported by Keq FormData');
32
33
  }
33
34
  if (isBuffer(value)) {
34
35
  return value.length;
@@ -1,5 +1,5 @@
1
1
  import readableStreamIterator from "./readable-stream-iterator";
2
- import { isWHATWGReadable } from "./is";
2
+ import { isWHATWGReadable } from "../../util";
3
3
  /**
4
4
  * Returns stream iterator for given stream-like object
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable eqeqeq */
2
- import { isBlob } from "./is";
2
+ import { isBlob } from "../../util";
3
3
  import File from "./file";
4
4
  const { isBuffer } = Buffer;
5
5
  /**
package/es/src/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  export * from "./request";
2
- export { Middleware, MiddlewareMatcher, compose } from "./middleware";
2
+ export * from "./types";
3
+ export { compose } from "./middleware";
3
4
  export * from "./keq";
4
- export * from "./context";
5
5
  export * from "./polyfill";
6
- export * from "./form-data-fields";
7
6
  export * as mount from "./mount";
package/es/src/index.js CHANGED
@@ -1,8 +1,6 @@
1
1
  export * from "./request";
2
+ export * from "./types";
2
3
  export { compose } from "./middleware";
3
4
  export * from "./keq";
4
- export * from "./context";
5
5
  export * from "./polyfill";
6
- export * from "./form-data-fields";
7
- import * as mount_1 from "./mount";
8
- export { mount_1 as mount };
6
+ export * as mount from "./mount";
package/es/src/keq.d.ts CHANGED
@@ -1,11 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { Middleware, MiddlewareMatcher } from "./middleware";
3
- import { Options, RequestMethod, BuildInOptions, OptionsWithFullResponse, OptionsWithoutFullResponse, KeqURL } from "./context";
4
- import { SerializeBodyFn } from "./serialize";
5
- import { FormDataFieldOptions } from "./form-data-fields";
6
- import { ShorthandContentType } from "./fix-type";
2
+ import { KeqURL, SerializeBodyFn, RequestMethod, Options, BuildInOptions, OptionsWithFullResponse, OptionsWithoutFullResponse, Middleware, MiddlewareMatcher, ShorthandContentType, FormDataFieldOptions, RetryCallback } from "./types";
7
3
  import { Stream } from 'stream';
8
- declare type RetryCallback = (error: Error) => void | boolean | Promise<void | boolean>;
9
4
  export declare class Keq<T> {
10
5
  private requestPromise?;
11
6
  private urlObj;
@@ -81,4 +76,3 @@ export declare class Keq<T> {
81
76
  then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
82
77
  catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>;
83
78
  }
84
- export {};
package/es/src/keq.js CHANGED
@@ -10,24 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import * as url from 'url';
11
11
  import fetch, { Headers } from 'cross-fetch';
12
12
  import * as clone from 'clone';
13
+ import * as R from 'ramda';
14
+ import { Exception, FileExpectedException, OverwriteArrayBodyException, UnknowContentTypeException, } from "./exception";
15
+ import { isFormData, isFile, isBrowser, encodeBase64, sleep, inferContentTypeByBody, fixContentType, getBoundaryByContentType, parseFormData, serializeBody, } from "./util";
13
16
  import { matchHost, matchMiddleware, compose } from "./middleware";
14
- import { serializeBodyByMap, serializeMap } from "./serialize";
15
- import { encodeBase64 } from "./base64";
16
- import { messages } from "./const";
17
17
  import { FormData } from "./polyfill";
18
- import { isFormData, isFile, isBrowser } from "./utils";
19
- import { fixType } from "./fix-type";
20
- import { getTypeByBody } from "./get-type-by-body";
21
- import { getBoundaryByContentType, parseFormData } from "./parse-form-data";
22
18
  import { compile } from 'path-to-regexp';
23
- import * as R from 'ramda';
24
- import { sleep } from "./sleep";
25
19
  export class Keq {
26
20
  constructor(urlObj, method, middlewares) {
27
21
  this.headers = new Headers();
28
22
  this.middlewares = [];
29
23
  this.opts = { resolveWithFullResponse: false, resolveWithOriginalResponse: false };
30
- this.serializeBodyFn = serializeBodyByMap(serializeMap);
24
+ this.serializeBodyFn = serializeBody;
31
25
  this.retryTimes = 0;
32
26
  this.initialRetryTime = 0;
33
27
  this.urlObj = urlObj;
@@ -54,9 +48,9 @@ export class Keq {
54
48
  * Setting the Content-Type
55
49
  */
56
50
  type(contentType) {
57
- const type = fixType(contentType);
51
+ const type = fixContentType(contentType);
58
52
  if (!type)
59
- throw new Error(messages.unknowContentType);
53
+ throw new UnknowContentTypeException();
60
54
  this.headers.set('Content-Type', type);
61
55
  return this;
62
56
  }
@@ -86,7 +80,7 @@ export class Keq {
86
80
  }
87
81
  setType(contentType) {
88
82
  if (!this.headers.has('Content-Type'))
89
- this.type(contentType);
83
+ void this.type(contentType);
90
84
  }
91
85
  /**
92
86
  * set request body
@@ -94,11 +88,11 @@ export class Keq {
94
88
  */
95
89
  send(value) {
96
90
  if (Array.isArray(this.body)) {
97
- throw new Error('Cannot merge or overwrite body. Because it has been set as an array. ');
91
+ throw new Exception('Cannot merge or overwrite body. Because it has been set as an array. ');
98
92
  }
99
93
  if (isFormData(value)) {
100
94
  if (Array.isArray(this.body))
101
- throw new Error(messages.overwriteArrayBodyError);
95
+ throw new OverwriteArrayBodyException();
102
96
  this.appendFormDate(value);
103
97
  this.setType('form-data');
104
98
  }
@@ -112,7 +106,7 @@ export class Keq {
112
106
  else if (typeof value === 'string') {
113
107
  const arr = value.split('=');
114
108
  if (arr.length !== 2)
115
- throw new Error('string is not expect');
109
+ throw new Exception('string is not expect');
116
110
  if (!this.body)
117
111
  this.body = {};
118
112
  this.body[arr[0]] = arr[1];
@@ -122,7 +116,7 @@ export class Keq {
122
116
  }
123
117
  field(arg1, arg2) {
124
118
  if (Array.isArray(this.body)) {
125
- throw new Error('Cannot merge or overwrite body. Because it has been set as an array. ');
119
+ throw new Exception('Cannot merge or overwrite body. Because it has been set as an array. ');
126
120
  }
127
121
  const formData = new FormData();
128
122
  if (typeof arg1 === 'object') {
@@ -134,7 +128,7 @@ export class Keq {
134
128
  formData.append(arg1, arg2);
135
129
  }
136
130
  else {
137
- throw new Error('Need value');
131
+ throw new Exception('Need value');
138
132
  }
139
133
  this.appendFormDate(formData);
140
134
  this.setType('form-data');
@@ -142,13 +136,13 @@ export class Keq {
142
136
  }
143
137
  attach(key, file, arg3 = 'blob') {
144
138
  if (Array.isArray(this.body))
145
- throw new Error(messages.overwriteArrayBodyError);
139
+ throw new OverwriteArrayBodyException();
146
140
  if (!this.body)
147
141
  this.body = {};
148
142
  if (!isFile(file))
149
- throw new Error(messages.fileExpected);
143
+ throw new FileExpectedException();
150
144
  const formData = new FormData();
151
- if (isBrowser && typeof arg3 === 'object')
145
+ if (isBrowser() && typeof arg3 === 'object')
152
146
  formData.set(key, file, arg3.filename);
153
147
  else
154
148
  formData.set(key, file, arg3);
@@ -171,18 +165,18 @@ export class Keq {
171
165
  }
172
166
  query(key, value) {
173
167
  if (typeof key === 'string' && value !== undefined) {
174
- this.urlObj.query[key] = String(value);
168
+ this.urlObj.query[key] = Array.isArray(value) ? value.map(item => String(item)) : String(value);
175
169
  }
176
170
  else if (typeof key === 'string' && value === undefined) {
177
171
  // ignore query
178
172
  }
179
173
  else if (typeof key === 'object') {
180
174
  for (const [k, v] of Object.entries(key)) {
181
- this.urlObj.query[k] = String(v);
175
+ this.urlObj.query[k] = Array.isArray(v) ? v.map(item => String(item)) : String(v);
182
176
  }
183
177
  }
184
178
  else {
185
- throw new Error('please set query value');
179
+ throw new Exception('please set query value');
186
180
  }
187
181
  return this;
188
182
  }
@@ -199,7 +193,7 @@ export class Keq {
199
193
  }
200
194
  }
201
195
  else {
202
- throw new Error('please set params value');
196
+ throw new Exception('please set params value');
203
197
  }
204
198
  return this;
205
199
  }
@@ -208,7 +202,7 @@ export class Keq {
208
202
  return this;
209
203
  }
210
204
  options(opts) {
211
- this.opts = Object.assign(Object.assign({}, this.options), opts);
205
+ this.opts = Object.assign(Object.assign({}, this.opts), opts);
212
206
  return this;
213
207
  }
214
208
  retry(retryTimes, initialRetryTimeOrRetryCallback, retryCallback) {
@@ -232,13 +226,13 @@ export class Keq {
232
226
  urlobj.pathname = toPath(ctx.request.url.params);
233
227
  }
234
228
  catch (e) {
235
- throw new Error(`Cannot compile the params in ${urlobj.pathname}, Because ${(_a = e) === null || _a === void 0 ? void 0 : _a.message}.`);
229
+ throw new Exception(`Cannot compile the params in ${urlobj.pathname}, Because ${(_a = e) === null || _a === void 0 ? void 0 : _a.message}.`);
236
230
  }
237
231
  }
238
232
  const uri = url.format(urlobj);
239
233
  const fetchOptions = Object.assign({ method: ctx.request.method.toUpperCase(), headers: ctx.request.headers, body: this.serializeBodyFn(ctx.request.body, ctx) }, ctx.request.options);
240
234
  if (!fetchOptions.headers.has('Content-Type') && fetchOptions.body) {
241
- fetchOptions.headers.set('Content-Type', getTypeByBody(fetchOptions.body));
235
+ fetchOptions.headers.set('Content-Type', inferContentTypeByBody(fetchOptions.body));
242
236
  }
243
237
  if (ctx.options.highWaterMark) {
244
238
  fetchOptions['highWaterMark'] = ctx.options.highWaterMark;
@@ -251,14 +245,14 @@ export class Keq {
251
245
  fetchOptions.headers.delete('content-type');
252
246
  }
253
247
  const res = yield ctx.options.fetchAPI(uri, fetchOptions);
254
- if (!isBrowser) {
248
+ if (!isBrowser()) {
255
249
  // node-fetch does not implement Response.formData()
256
250
  res.formData = function () {
257
251
  return __awaiter(this, void 0, void 0, function* () {
258
252
  const str = yield this.text();
259
253
  const contentType = this.headers.get('content-type');
260
254
  if (!contentType)
261
- throw new Error('Cannot parse form-data body without content-type');
255
+ throw new Exception('Cannot parse form-data body without content-type');
262
256
  const boundary = getBoundaryByContentType(contentType);
263
257
  return parseFormData(str, boundary);
264
258
  });
@@ -267,15 +261,16 @@ export class Keq {
267
261
  const cache = {};
268
262
  ctx.res = new Proxy(res, {
269
263
  get(target, property) {
270
- if (!(typeof property === 'string' && ['json', 'formData', 'text', 'blob'].includes(property)))
264
+ if (!(typeof property === 'string' && ['json', 'formData', 'text', 'blob'].includes(property))) {
271
265
  return target[property];
266
+ }
272
267
  return () => {
273
268
  if (!(property in cache))
274
269
  cache[property] = target[property]();
275
270
  return cache[property].then(data => {
276
- if (!isBrowser && data instanceof Buffer)
271
+ if (!isBrowser() && data instanceof Buffer)
277
272
  return Buffer.from(data);
278
- else if (isBrowser && data instanceof Blob)
273
+ else if (isBrowser() && data instanceof Blob)
279
274
  return data.slice();
280
275
  return R.clone(data);
281
276
  });
@@ -1,7 +1,4 @@
1
- import { Context } from "./context";
2
- export declare type InnerMiddleware = () => Promise<void>;
3
- export declare type Middleware = (ctx: Context, next: InnerMiddleware) => Promise<void>;
4
- export declare type MiddlewareMatcher = (ctx: Context) => boolean;
1
+ import { Context, InnerMiddleware, Middleware, MiddlewareMatcher } from "./types";
5
2
  export declare const matchHost: (host: string) => MiddlewareMatcher;
6
3
  export declare function matchMiddleware(matcher: MiddlewareMatcher, middleware: Middleware): Middleware;
7
4
  export declare function wrapMiddleware(middleware: Middleware, ctx: Context, next: InnerMiddleware): InnerMiddleware;
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { Exception } from "./exception";
10
11
  export const matchHost = (host) => ctx => ctx.request.url.host === host;
11
12
  export function matchMiddleware(matcher, middleware) {
12
13
  return (ctx, next) => __awaiter(this, void 0, void 0, function* () {
@@ -23,7 +24,7 @@ export function wrapMiddleware(middleware, ctx, next) {
23
24
  }
24
25
  export function compose(middlewares) {
25
26
  if (!middlewares.length)
26
- throw new Error('At least one middleware');
27
+ throw new Exception('At least one middleware');
27
28
  let result = middlewares[0];
28
29
  const len = middlewares.length;
29
30
  for (let i = 1; i < len; i++) {