keq 1.7.2 → 1.7.3
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 +7 -0
- package/es/package.json +2 -1
- package/es/src/keq-url.js +1 -2
- package/es/src/keq.js +1 -1
- package/es/src/mount.d.ts +4 -0
- package/es/src/mount.js +14 -1
- package/es/src/types/context.d.ts +1 -1
- package/es/src/util/clone.d.ts +1 -0
- package/es/src/util/clone.js +14 -0
- package/lib/index.js +5 -1
- package/lib/package.json +2 -1
- package/lib/src/exception/index.js +5 -1
- package/lib/src/index.js +5 -1
- package/lib/src/keq-url.js +1 -2
- package/lib/src/keq.js +4 -4
- package/lib/src/mount.d.ts +4 -0
- package/lib/src/mount.js +15 -2
- package/lib/src/types/context.d.ts +1 -1
- package/lib/src/types/index.js +5 -1
- package/lib/src/util/clone.d.ts +1 -0
- package/lib/src/util/clone.js +28 -0
- package/lib/src/util/index.js +5 -1
- package/lib/src/util/is/index.js +5 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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.7.3](https://www.github.com/keq-request/keq/compare/v1.7.2...v1.7.3) (2022-03-08)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* unable to send formdate request with file ([a4ed415](https://www.github.com/keq-request/keq/commit/a4ed41560aacb67a49d8159b453ddf69bce56799))
|
|
11
|
+
|
|
5
12
|
### [1.7.2](https://www.github.com/keq-request/keq/compare/v1.7.1...v1.7.2) (2022-02-25)
|
|
6
13
|
|
|
7
14
|
|
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.7.
|
|
5
|
+
"version": "1.7.3",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
"formidable": "^2.0.1",
|
|
65
65
|
"mime-types": "^2.1.27",
|
|
66
66
|
"nanoid": "^3.1.10",
|
|
67
|
+
"object.fromentries": "^2.0.5",
|
|
67
68
|
"path-to-regexp": "^6.2.0",
|
|
68
69
|
"picomatch": "^2.2.2",
|
|
69
70
|
"querystring": "^0.2.0",
|
package/es/src/keq-url.js
CHANGED
|
@@ -61,14 +61,13 @@ export class KeqURL extends URL {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
toPath() {
|
|
64
|
-
var _a;
|
|
65
64
|
const uri = new URL(this.href);
|
|
66
65
|
try {
|
|
67
66
|
const toPath = compile(uri.pathname, { encode: encodeURIComponent });
|
|
68
67
|
uri.pathname = toPath(this.params);
|
|
69
68
|
}
|
|
70
69
|
catch (e) {
|
|
71
|
-
throw new Exception(`Cannot compile the params in ${uri.pathname}, Because ${
|
|
70
|
+
throw new Exception(`Cannot compile the params in ${uri.pathname}, Because ${e === null || e === void 0 ? void 0 : e.message}.`);
|
|
72
71
|
}
|
|
73
72
|
return uri.href;
|
|
74
73
|
}
|
package/es/src/keq.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import fetch, { Headers } from 'cross-fetch';
|
|
11
|
-
import
|
|
11
|
+
import { clone } from "./util/clone";
|
|
12
12
|
import { Exception, FileExpectedException, OverwriteArrayBodyException, UnknowContentTypeException, } from "./exception";
|
|
13
13
|
import { isFormData, isFile, isBrowser, encodeBase64, sleep, inferContentTypeByBody, fixContentType, getBoundaryByContentType, parseFormData, serializeBody, } from "./util";
|
|
14
14
|
import { matchHost, matchMiddleware, compose } from "./middleware";
|
package/es/src/mount.d.ts
CHANGED
package/es/src/mount.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Exception } from "./exception";
|
|
2
2
|
import * as picomatch from 'picomatch';
|
|
3
|
+
import { isBrowser } from "./util";
|
|
3
4
|
function createMounter(matcher) {
|
|
4
5
|
const mounter = ctx => matcher(ctx);
|
|
5
6
|
mounter.pathname = arg => compose(mounter, pathname(arg));
|
|
@@ -8,8 +9,20 @@ function createMounter(matcher) {
|
|
|
8
9
|
mounter.module = arg => compose(mounter, module(arg));
|
|
9
10
|
return mounter;
|
|
10
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* NOTE: Not work in NodeJS
|
|
14
|
+
* Unable to get the host and port of the service
|
|
15
|
+
*/
|
|
11
16
|
export function location() {
|
|
12
|
-
return createMounter((ctx) =>
|
|
17
|
+
return createMounter((ctx) => {
|
|
18
|
+
if (!ctx.request.url.host)
|
|
19
|
+
return true;
|
|
20
|
+
if (isBrowser()) {
|
|
21
|
+
if (ctx.request.url.host === window.location.host)
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
});
|
|
13
26
|
}
|
|
14
27
|
/**
|
|
15
28
|
* @param matcher glob or regexp
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function clone<T>(obj: T): T;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as deepClone from 'clone';
|
|
2
|
+
import { isBlob } from "./is";
|
|
3
|
+
import * as fromEntries from 'object.fromentries';
|
|
4
|
+
export function clone(obj) {
|
|
5
|
+
if (typeof obj === 'object' && !Array.isArray(obj)) {
|
|
6
|
+
const entries = Object.entries(obj)
|
|
7
|
+
.map(([key, value]) => ([
|
|
8
|
+
key,
|
|
9
|
+
isBlob(value) ? value : deepClone(value),
|
|
10
|
+
]));
|
|
11
|
+
return fromEntries(entries);
|
|
12
|
+
}
|
|
13
|
+
return deepClone(obj);
|
|
14
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
2
|
if (k2 === undefined) k2 = k;
|
|
3
|
-
Object.
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
4
8
|
}) : (function(o, m, k, k2) {
|
|
5
9
|
if (k2 === undefined) k2 = k;
|
|
6
10
|
o[k2] = m[k];
|
package/lib/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.7.
|
|
5
|
+
"version": "1.7.3",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
"formidable": "^2.0.1",
|
|
65
65
|
"mime-types": "^2.1.27",
|
|
66
66
|
"nanoid": "^3.1.10",
|
|
67
|
+
"object.fromentries": "^2.0.5",
|
|
67
68
|
"path-to-regexp": "^6.2.0",
|
|
68
69
|
"picomatch": "^2.2.2",
|
|
69
70
|
"querystring": "^0.2.0",
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
2
|
if (k2 === undefined) k2 = k;
|
|
3
|
-
Object.
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
4
8
|
}) : (function(o, m, k, k2) {
|
|
5
9
|
if (k2 === undefined) k2 = k;
|
|
6
10
|
o[k2] = m[k];
|
package/lib/src/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
2
|
if (k2 === undefined) k2 = k;
|
|
3
|
-
Object.
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
4
8
|
}) : (function(o, m, k, k2) {
|
|
5
9
|
if (k2 === undefined) k2 = k;
|
|
6
10
|
o[k2] = m[k];
|
package/lib/src/keq-url.js
CHANGED
|
@@ -73,14 +73,13 @@
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
toPath() {
|
|
76
|
-
var _a;
|
|
77
76
|
const uri = new whatwg_url_1.URL(this.href);
|
|
78
77
|
try {
|
|
79
78
|
const toPath = (0, path_to_regexp_1.compile)(uri.pathname, { encode: encodeURIComponent });
|
|
80
79
|
uri.pathname = toPath(this.params);
|
|
81
80
|
}
|
|
82
81
|
catch (e) {
|
|
83
|
-
throw new exception_1.Exception(`Cannot compile the params in ${uri.pathname}, Because ${
|
|
82
|
+
throw new exception_1.Exception(`Cannot compile the params in ${uri.pathname}, Because ${e === null || e === void 0 ? void 0 : e.message}.`);
|
|
84
83
|
}
|
|
85
84
|
return uri.href;
|
|
86
85
|
}
|
package/lib/src/keq.js
CHANGED
|
@@ -13,14 +13,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
13
13
|
if (v !== undefined) module.exports = v;
|
|
14
14
|
}
|
|
15
15
|
else if (typeof define === "function" && define.amd) {
|
|
16
|
-
define(["require", "exports", "cross-fetch", "clone", "./exception", "./util", "./middleware", "./polyfill"], factory);
|
|
16
|
+
define(["require", "exports", "cross-fetch", "./util/clone", "./exception", "./util", "./middleware", "./polyfill"], factory);
|
|
17
17
|
}
|
|
18
18
|
})(function (require, exports) {
|
|
19
19
|
"use strict";
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
exports.Keq = void 0;
|
|
22
22
|
const cross_fetch_1 = require("cross-fetch");
|
|
23
|
-
const
|
|
23
|
+
const clone_1 = require("./util/clone");
|
|
24
24
|
const exception_1 = require("./exception");
|
|
25
25
|
const util_1 = require("./util");
|
|
26
26
|
const middleware_1 = require("./middleware");
|
|
@@ -314,14 +314,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
314
314
|
urlObj.params = value.params;
|
|
315
315
|
},
|
|
316
316
|
headers,
|
|
317
|
-
body: clone(this.body),
|
|
317
|
+
body: (0, clone_1.clone)(this.body),
|
|
318
318
|
options: {},
|
|
319
319
|
};
|
|
320
320
|
if (this.opts.redirect)
|
|
321
321
|
request.options.redirect = this.opts.redirect;
|
|
322
322
|
const ctx = {
|
|
323
323
|
request,
|
|
324
|
-
options: clone(Object.assign(Object.assign({}, this.opts), { fetchAPI: this.opts.fetchAPI || cross_fetch_1.default })),
|
|
324
|
+
options: (0, clone_1.clone)(Object.assign(Object.assign({}, this.opts), { fetchAPI: this.opts.fetchAPI || cross_fetch_1.default })),
|
|
325
325
|
output: undefined,
|
|
326
326
|
get url() {
|
|
327
327
|
return this.request.url;
|
package/lib/src/mount.d.ts
CHANGED
package/lib/src/mount.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "./exception", "picomatch"], factory);
|
|
7
|
+
define(["require", "exports", "./exception", "picomatch", "./util"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
exports.module = exports.host = exports.pathname = exports.location = void 0;
|
|
13
13
|
const exception_1 = require("./exception");
|
|
14
14
|
const picomatch = require("picomatch");
|
|
15
|
+
const util_1 = require("./util");
|
|
15
16
|
function createMounter(matcher) {
|
|
16
17
|
const mounter = ctx => matcher(ctx);
|
|
17
18
|
mounter.pathname = arg => compose(mounter, pathname(arg));
|
|
@@ -20,8 +21,20 @@
|
|
|
20
21
|
mounter.module = arg => compose(mounter, module(arg));
|
|
21
22
|
return mounter;
|
|
22
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* NOTE: Not work in NodeJS
|
|
26
|
+
* Unable to get the host and port of the service
|
|
27
|
+
*/
|
|
23
28
|
function location() {
|
|
24
|
-
return createMounter((ctx) =>
|
|
29
|
+
return createMounter((ctx) => {
|
|
30
|
+
if (!ctx.request.url.host)
|
|
31
|
+
return true;
|
|
32
|
+
if ((0, util_1.isBrowser)()) {
|
|
33
|
+
if (ctx.request.url.host === window.location.host)
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
});
|
|
25
38
|
}
|
|
26
39
|
exports.location = location;
|
|
27
40
|
/**
|
package/lib/src/types/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
2
|
if (k2 === undefined) k2 = k;
|
|
3
|
-
Object.
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
4
8
|
}) : (function(o, m, k, k2) {
|
|
5
9
|
if (k2 === undefined) k2 = k;
|
|
6
10
|
o[k2] = m[k];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function clone<T>(obj: T): T;
|
|
@@ -0,0 +1,28 @@
|
|
|
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", "clone", "./is", "object.fromentries"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.clone = void 0;
|
|
13
|
+
const deepClone = require("clone");
|
|
14
|
+
const is_1 = require("./is");
|
|
15
|
+
const fromEntries = require("object.fromentries");
|
|
16
|
+
function clone(obj) {
|
|
17
|
+
if (typeof obj === 'object' && !Array.isArray(obj)) {
|
|
18
|
+
const entries = Object.entries(obj)
|
|
19
|
+
.map(([key, value]) => ([
|
|
20
|
+
key,
|
|
21
|
+
(0, is_1.isBlob)(value) ? value : deepClone(value),
|
|
22
|
+
]));
|
|
23
|
+
return fromEntries(entries);
|
|
24
|
+
}
|
|
25
|
+
return deepClone(obj);
|
|
26
|
+
}
|
|
27
|
+
exports.clone = clone;
|
|
28
|
+
});
|
package/lib/src/util/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
2
|
if (k2 === undefined) k2 = k;
|
|
3
|
-
Object.
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
4
8
|
}) : (function(o, m, k, k2) {
|
|
5
9
|
if (k2 === undefined) k2 = k;
|
|
6
10
|
o[k2] = m[k];
|
package/lib/src/util/is/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
2
|
if (k2 === undefined) k2 = k;
|
|
3
|
-
Object.
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
4
8
|
}) : (function(o, m, k, k2) {
|
|
5
9
|
if (k2 === undefined) k2 = k;
|
|
6
10
|
o[k2] = m[k];
|
package/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.7.
|
|
5
|
+
"version": "1.7.3",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
"formidable": "^2.0.1",
|
|
65
65
|
"mime-types": "^2.1.27",
|
|
66
66
|
"nanoid": "^3.1.10",
|
|
67
|
+
"object.fromentries": "^2.0.5",
|
|
67
68
|
"path-to-regexp": "^6.2.0",
|
|
68
69
|
"picomatch": "^2.2.2",
|
|
69
70
|
"querystring": "^0.2.0",
|