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.
- package/.editorconfig +0 -4
- package/.eslintignore +1 -2
- package/.husky/pre-commit +0 -2
- package/.milirc.yml +4 -9
- package/CHANGELOG.md +14 -0
- package/README.md +4 -3
- package/build/tsconfig.es.json +1 -1
- package/build/tsconfig.lib.json +1 -1
- package/es/index.js +1 -0
- package/es/package.json +16 -16
- package/es/src/exception/exception.d.ts +4 -0
- package/es/src/exception/exception.js +7 -0
- package/es/src/exception/file-expected.exception.d.ts +4 -0
- package/es/src/exception/file-expected.exception.js +6 -0
- package/es/src/exception/file-expected.exception.ts +8 -0
- package/es/src/exception/index.d.ts +4 -0
- package/es/src/exception/index.js +4 -0
- package/es/src/exception/overwrite-array-body.exception.d.ts +4 -0
- package/es/src/exception/overwrite-array-body.exception.js +6 -0
- package/es/src/exception/overwrite-array-body.exception.ts +8 -0
- package/es/src/exception/unknow-content-type.exception.d.ts +4 -0
- package/es/src/exception/unknow-content-type.exception.js +6 -0
- package/es/src/exception/unknow-content-type.exception.ts +8 -0
- package/es/src/form-data-node/index.js +1 -1
- package/es/src/form-data-node/util/file.js +1 -1
- package/es/src/form-data-node/util/get-length.js +3 -2
- package/es/src/form-data-node/util/get-stream-iterator.js +1 -1
- package/es/src/form-data-node/util/to-file.js +1 -1
- package/es/src/index.d.ts +2 -3
- package/es/src/index.js +2 -4
- package/es/src/keq.d.ts +1 -7
- package/es/src/keq.js +28 -33
- package/es/src/middleware.d.ts +1 -4
- package/es/src/middleware.js +2 -1
- package/es/src/mount.d.ts +4 -8
- package/es/src/mount.js +5 -1
- package/es/src/polyfill.js +2 -2
- package/es/src/request.d.ts +1 -24
- package/es/src/types/context.d.ts +27 -0
- package/es/src/{context.js → types/context.js} +0 -0
- package/es/src/types/index.d.ts +11 -0
- package/es/src/types/index.js +11 -0
- package/es/src/types/keq-body.d.ts +1 -0
- package/es/src/{form-data-fields.js → types/keq-body.js} +0 -0
- package/es/src/types/keq-url.d.ts +5 -0
- package/es/src/types/keq-url.js +1 -0
- package/es/src/types/middleware.d.ts +4 -0
- package/es/src/types/middleware.js +1 -0
- package/es/src/types/mounter.d.ts +7 -0
- package/es/src/types/mounter.js +1 -0
- package/es/src/{context.d.ts → types/options.d.ts} +8 -32
- package/es/src/types/options.js +1 -0
- package/es/src/types/request-creator.d.ts +25 -0
- package/es/src/types/request-creator.js +1 -0
- package/es/src/types/request-method.d.ts +1 -0
- package/es/src/types/request-method.js +1 -0
- package/es/src/types/retry-callback.d.ts +1 -0
- package/es/src/types/retry-callback.js +1 -0
- package/es/src/types/serialize-body-fn.d.ts +3 -0
- package/es/src/types/serialize-body-fn.js +1 -0
- package/es/src/{fix-type.d.ts → types/shorthand-content-type.d.ts} +0 -1
- package/es/src/types/shorthand-content-type.js +1 -0
- package/es/src/{base64.d.ts → util/encode-base64.d.ts} +0 -0
- package/es/src/util/encode-base64.js +4 -0
- package/es/src/util/fix-content-type.d.ts +2 -0
- package/es/src/{fix-type.js → util/fix-content-type.js} +1 -1
- package/es/src/util/get-boundary-by-content-type.d.ts +1 -0
- package/es/src/util/get-boundary-by-content-type.js +10 -0
- package/es/src/util/index.d.ts +8 -0
- package/es/src/util/index.js +8 -0
- package/es/src/util/infer-content-type-by-body.d.ts +2 -0
- package/es/src/{get-type-by-body.js → util/infer-content-type-by-body.js} +1 -4
- package/es/src/{form-data-node/util → util}/is/index.d.ts +3 -0
- package/es/src/{form-data-node/util → util}/is/index.js +3 -0
- package/es/src/{form-data-node/util → util}/is/is-blob.d.ts +0 -0
- package/es/src/{form-data-node/util → util}/is/is-blob.js +0 -0
- package/es/src/util/is/is-browser.d.ts +1 -0
- package/es/src/util/is/is-browser.js +3 -0
- package/es/src/util/is/is-file.d.ts +1 -0
- package/es/src/util/is/is-file.js +7 -0
- package/es/src/util/is/is-form-data.d.ts +1 -0
- package/es/src/util/is/is-form-data.js +12 -0
- package/es/src/{form-data-node/util → util}/is/is-function.d.ts +0 -0
- package/es/src/{form-data-node/util → util}/is/is-function.js +0 -0
- package/es/src/{form-data-node/util → util}/is/is-object.d.ts +0 -0
- package/es/src/{form-data-node/util → util}/is/is-object.js +0 -0
- package/es/src/{form-data-node/util → util}/is/is-read-stream.d.ts +0 -0
- package/es/src/{form-data-node/util → util}/is/is-read-stream.js +0 -0
- package/es/src/{form-data-node/util → util}/is/is-readable.d.ts +0 -0
- package/es/src/{form-data-node/util → util}/is/is-readable.js +0 -0
- package/es/src/{form-data-node/util → util}/is/is-stream.d.ts +0 -0
- package/es/src/{form-data-node/util → util}/is/is-stream.js +0 -0
- package/es/src/{form-data-node/util → util}/is/is-string.d.ts +0 -0
- package/es/src/{form-data-node/util → util}/is/is-string.js +0 -0
- package/es/src/{form-data-node/util → util}/is/is-whatwg-readable.d.ts +0 -0
- package/es/src/{form-data-node/util → util}/is/is-whatwg-readable.js +0 -0
- package/es/src/{parse-form-data.d.ts → util/parse-form-data.d.ts} +0 -1
- package/es/src/{parse-form-data.js → util/parse-form-data.js} +3 -11
- package/es/src/util/serialize-body.d.ts +6 -0
- package/es/src/{serialize.js → util/serialize-body.js} +11 -13
- package/es/src/{sleep.d.ts → util/sleep.d.ts} +0 -0
- package/es/src/{sleep.js → util/sleep.js} +0 -0
- package/index.ts +1 -0
- package/lib/index.js +17 -6
- package/lib/package.json +16 -16
- package/lib/src/exception/exception.d.ts +4 -0
- package/lib/src/exception/exception.js +21 -0
- package/lib/src/exception/file-expected.exception.d.ts +4 -0
- package/lib/src/exception/file-expected.exception.js +20 -0
- package/lib/src/exception/file-expected.exception.ts +8 -0
- package/lib/src/exception/index.d.ts +4 -0
- package/lib/src/exception/index.js +26 -0
- package/lib/src/exception/overwrite-array-body.exception.d.ts +4 -0
- package/lib/src/exception/overwrite-array-body.exception.js +20 -0
- package/lib/src/exception/overwrite-array-body.exception.ts +8 -0
- package/lib/src/exception/unknow-content-type.exception.d.ts +4 -0
- package/lib/src/exception/unknow-content-type.exception.js +20 -0
- package/lib/src/exception/unknow-content-type.exception.ts +8 -0
- package/lib/src/form-data-node/index.js +395 -385
- package/lib/src/form-data-node/util/boundary.js +19 -9
- package/lib/src/form-data-node/util/file.js +65 -55
- package/lib/src/form-data-node/util/get-length.js +44 -33
- package/lib/src/form-data-node/util/get-stream-iterator.js +27 -17
- package/lib/src/form-data-node/util/get-type.js +38 -28
- package/lib/src/form-data-node/util/read-only.js +19 -9
- package/lib/src/form-data-node/util/readable-stream-iterator.js +30 -20
- package/lib/src/form-data-node/util/to-file.js +33 -23
- package/lib/src/index.d.ts +2 -3
- package/lib/src/index.js +20 -11
- package/lib/src/keq.d.ts +1 -7
- package/lib/src/keq.js +373 -368
- package/lib/src/middleware.d.ts +1 -4
- package/lib/src/middleware.js +46 -35
- package/lib/src/mount.d.ts +4 -8
- package/lib/src/mount.js +59 -45
- package/lib/src/polyfill.js +20 -10
- package/lib/src/request.d.ts +1 -24
- package/lib/src/request.js +65 -55
- package/lib/src/types/context.d.ts +27 -0
- package/lib/src/types/context.js +12 -0
- package/lib/src/types/index.d.ts +11 -0
- package/lib/src/types/index.js +33 -0
- package/lib/src/types/keq-body.d.ts +1 -0
- package/lib/src/types/keq-body.js +12 -0
- package/lib/src/types/keq-url.d.ts +5 -0
- package/lib/src/types/keq-url.js +12 -0
- package/lib/src/types/middleware.d.ts +4 -0
- package/lib/src/types/middleware.js +12 -0
- package/lib/src/types/mounter.d.ts +7 -0
- package/lib/src/types/mounter.js +12 -0
- package/lib/src/{context.d.ts → types/options.d.ts} +8 -32
- package/lib/src/types/options.js +12 -0
- package/lib/src/types/request-creator.d.ts +25 -0
- package/lib/src/types/request-creator.js +12 -0
- package/lib/src/types/request-method.d.ts +1 -0
- package/lib/src/types/request-method.js +12 -0
- package/lib/src/types/retry-callback.d.ts +1 -0
- package/lib/src/types/retry-callback.js +12 -0
- package/lib/src/types/serialize-body-fn.d.ts +3 -0
- package/lib/src/types/serialize-body-fn.js +12 -0
- package/lib/src/{fix-type.d.ts → types/shorthand-content-type.d.ts} +0 -1
- package/lib/src/types/shorthand-content-type.js +12 -0
- package/lib/src/{base64.d.ts → util/encode-base64.d.ts} +0 -0
- package/lib/src/util/encode-base64.js +18 -0
- package/lib/src/util/fix-content-type.d.ts +2 -0
- package/lib/src/util/fix-content-type.js +30 -0
- package/lib/src/util/get-boundary-by-content-type.d.ts +1 -0
- package/lib/src/util/get-boundary-by-content-type.js +24 -0
- package/lib/src/util/index.d.ts +8 -0
- package/lib/src/util/index.js +30 -0
- package/lib/src/util/infer-content-type-by-body.d.ts +2 -0
- package/lib/src/util/infer-content-type-by-body.js +21 -0
- package/lib/src/{form-data-node/util → util}/is/index.d.ts +3 -0
- package/lib/src/util/is/index.js +33 -0
- package/lib/src/{form-data-node/util → util}/is/is-blob.d.ts +0 -0
- package/lib/src/util/is/is-blob.js +30 -0
- package/lib/src/util/is/is-browser.d.ts +1 -0
- package/lib/src/util/is/is-browser.js +17 -0
- package/lib/src/util/is/is-file.d.ts +1 -0
- package/lib/src/util/is/is-file.js +21 -0
- package/lib/src/util/is/is-form-data.d.ts +1 -0
- package/lib/src/util/is/is-form-data.js +26 -0
- package/lib/src/{form-data-node/util → util}/is/is-function.d.ts +0 -0
- package/lib/src/util/is/is-function.js +17 -0
- package/lib/src/{form-data-node/util → util}/is/is-object.d.ts +0 -0
- package/lib/src/util/is/is-object.js +17 -0
- package/lib/src/{form-data-node/util → util}/is/is-read-stream.d.ts +0 -0
- package/lib/src/util/is/is-read-stream.js +26 -0
- package/lib/src/{form-data-node/util → util}/is/is-readable.d.ts +0 -0
- package/lib/src/util/is/is-readable.js +18 -0
- package/lib/src/{form-data-node/util → util}/is/is-stream.d.ts +0 -0
- package/lib/src/util/is/is-stream.js +23 -0
- package/lib/src/{form-data-node/util → util}/is/is-string.d.ts +0 -0
- package/lib/src/util/is/is-string.js +17 -0
- package/lib/src/{form-data-node/util → util}/is/is-whatwg-readable.d.ts +0 -0
- package/lib/src/util/is/is-whatwg-readable.js +34 -0
- package/lib/src/{parse-form-data.d.ts → util/parse-form-data.d.ts} +0 -1
- package/lib/src/util/parse-form-data.js +143 -0
- package/lib/src/util/serialize-body.d.ts +6 -0
- package/lib/src/util/serialize-body.js +67 -0
- package/lib/src/{sleep.d.ts → util/sleep.d.ts} +0 -0
- package/lib/src/util/sleep.js +17 -0
- package/package.json +16 -16
- package/es/src/base64.js +0 -4
- package/es/src/const.d.ts +0 -5
- package/es/src/const.js +0 -5
- package/es/src/form-data-fields.d.ts +0 -6
- package/es/src/get-type-by-body.d.ts +0 -5
- package/es/src/serialize.d.ts +0 -8
- package/es/src/utils.d.ts +0 -3
- package/es/src/utils.js +0 -37
- package/lib/src/base64.js +0 -8
- package/lib/src/const.d.ts +0 -5
- package/lib/src/const.js +0 -8
- package/lib/src/context.js +0 -2
- package/lib/src/fix-type.js +0 -20
- package/lib/src/form-data-fields.d.ts +0 -6
- package/lib/src/form-data-fields.js +0 -2
- package/lib/src/form-data-node/util/is/index.js +0 -20
- package/lib/src/form-data-node/util/is/is-blob.js +0 -20
- package/lib/src/form-data-node/util/is/is-function.js +0 -7
- package/lib/src/form-data-node/util/is/is-object.js +0 -7
- package/lib/src/form-data-node/util/is/is-read-stream.js +0 -16
- package/lib/src/form-data-node/util/is/is-readable.js +0 -8
- package/lib/src/form-data-node/util/is/is-stream.js +0 -13
- package/lib/src/form-data-node/util/is/is-string.js +0 -7
- package/lib/src/form-data-node/util/is/is-whatwg-readable.js +0 -24
- package/lib/src/get-type-by-body.d.ts +0 -5
- package/lib/src/get-type-by-body.js +0 -14
- package/lib/src/parse-form-data.js +0 -142
- package/lib/src/serialize.d.ts +0 -8
- package/lib/src/serialize.js +0 -59
- package/lib/src/sleep.js +0 -7
- package/lib/src/utils.d.ts +0 -3
- 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
package/.husky/pre-commit
CHANGED
package/.milirc.yml
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
8
|
-
standardVersion: true
|
|
9
|
-
lint: true
|
|
4
|
+
travis: true
|
|
10
5
|
lock: false
|
|
11
|
-
module:
|
|
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
|
[](https://www.npmjs.com/package/keq)
|
|
10
10
|
[](https://www.npmjs.com/package/keq)
|
|
11
11
|
[](https://www.npmjs.com/package/keq)
|
|
12
|
-
[](https://www.npmjs.com/package/keq)
|
|
13
|
+
[](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
|
[](https://www.patreon.com/bePatron?u=22478507)
|
|
491
|
+
<!-- addition -->
|
|
492
|
+
|
|
492
493
|
|
|
493
494
|
## Contributing & Development
|
|
494
495
|
|
package/build/tsconfig.es.json
CHANGED
package/build/tsconfig.lib.json
CHANGED
package/es/index.js
CHANGED
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.
|
|
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
|
|
16
|
+
"release": "standard-version",
|
|
17
17
|
"release:alpha": "standard-version --prerelease alpha",
|
|
18
18
|
"release:first": "standard-version --first-release",
|
|
19
|
-
"prepublishOnly": "npm
|
|
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.
|
|
34
|
-
"@commitlint/config-conventional": "^12.
|
|
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
|
|
39
|
+
"ajv": "^8",
|
|
40
40
|
"ava": "^3.10.1",
|
|
41
|
-
"commitizen": "^4.2.
|
|
41
|
+
"commitizen": "^4.2.4",
|
|
42
42
|
"copyfiles": "^2.4.1",
|
|
43
43
|
"coveralls": "^3.1.0",
|
|
44
|
-
"cz-conventional-changelog": "^3.
|
|
44
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
45
45
|
"eslint": "^7.20.0",
|
|
46
|
-
"husky": "^5.
|
|
46
|
+
"husky": "^5.2.0",
|
|
47
47
|
"is-ci": "^3.0.0",
|
|
48
48
|
"lint-staged": "^11.0.0",
|
|
49
|
-
"mili": "^
|
|
49
|
+
"mili": "^4",
|
|
50
50
|
"nyc": "^15.1.0",
|
|
51
|
-
"pinst": "^2.1.6",
|
|
52
51
|
"sinon": "^10.0.0",
|
|
53
|
-
"standard-version": "^9.
|
|
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.
|
|
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.",
|
|
@@ -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 "
|
|
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 "
|
|
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
|
|
32
|
+
throw new Exception('Read Stream is not supported by Keq FormData');
|
|
32
33
|
}
|
|
33
34
|
if (isBuffer(value)) {
|
|
34
35
|
return value.length;
|
package/es/src/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export * from "./request";
|
|
2
|
-
export
|
|
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 "./
|
|
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 "./
|
|
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 =
|
|
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 =
|
|
51
|
+
const type = fixContentType(contentType);
|
|
58
52
|
if (!type)
|
|
59
|
-
throw new
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
139
|
+
throw new OverwriteArrayBodyException();
|
|
146
140
|
if (!this.body)
|
|
147
141
|
this.body = {};
|
|
148
142
|
if (!isFile(file))
|
|
149
|
-
throw new
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
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',
|
|
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
|
|
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
|
});
|
package/es/src/middleware.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { Context } from "./
|
|
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;
|
package/es/src/middleware.js
CHANGED
|
@@ -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
|
|
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++) {
|