keq 2.8.1 → 2.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/esm/src/index.d.ts +1 -0
- package/dist/esm/src/index.js +1 -0
- package/dist/esm/src/is/is-buffer.d.ts +1 -0
- package/dist/esm/src/keq.d.ts +1 -0
- package/dist/esm/src/middlewares/proxy-response-middleware.js +3 -28
- package/dist/esm/src/types/keq-operation.d.ts +1 -0
- package/dist/esm/src/util/create-response-proxy.d.ts +1 -0
- package/dist/esm/src/util/create-response-proxy.js +28 -0
- package/dist/umd/src/index.d.ts +1 -0
- package/dist/umd/src/index.js +4 -2
- package/dist/umd/src/is/is-buffer.d.ts +1 -0
- package/dist/umd/src/keq.d.ts +1 -0
- package/dist/umd/src/middlewares/proxy-response-middleware.js +4 -29
- package/dist/umd/src/types/keq-operation.d.ts +1 -0
- package/dist/umd/src/util/create-response-proxy.d.ts +1 -0
- package/dist/umd/src/util/create-response-proxy.js +42 -0
- package/package.json +1 -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
|
+
## [2.8.2](https://github.com/keq-request/keq/compare/v2.8.1...v2.8.2) (2024-10-07)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Performance Improvements
|
|
9
|
+
|
|
10
|
+
* export createResponseProxy function ([261606e](https://github.com/keq-request/keq/commit/261606e74f12d32c80428eb9b20d175b60171bff))
|
|
11
|
+
|
|
5
12
|
## [2.8.1](https://github.com/keq-request/keq/compare/v2.8.0...v2.8.1) (2024-09-13)
|
|
6
13
|
|
|
7
14
|
|
package/dist/esm/src/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { Keq } from './keq.js';
|
|
|
3
3
|
export { request } from './request.js';
|
|
4
4
|
export { composeMiddleware } from './util/compose-middleware.js';
|
|
5
5
|
export { composeRoute } from './util/compose-route.js';
|
|
6
|
+
export { createResponseProxy } from './util/create-response-proxy.js';
|
|
6
7
|
export type { KeqContext, KeqContextOptions } from './types/keq-context.js';
|
|
7
8
|
export type { KeqMiddleware } from './types/keq-middleware.js';
|
|
8
9
|
export type { KeqNext } from './types/keq-next.js';
|
package/dist/esm/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { Keq } from './keq.js';
|
|
|
3
3
|
export { request } from './request.js';
|
|
4
4
|
export { composeMiddleware } from './util/compose-middleware.js';
|
|
5
5
|
export { composeRoute } from './util/compose-route.js';
|
|
6
|
+
export { createResponseProxy } from './util/create-response-proxy.js';
|
|
6
7
|
export { keqHostRoute } from './router/keq-host-route.js';
|
|
7
8
|
export { keqLocationRoute } from './router/keq-location-route.js';
|
|
8
9
|
export { keqMethodRoute } from './router/keq-method-route.js';
|
package/dist/esm/src/keq.d.ts
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
|
+
import { createResponseProxy } from "../util/create-response-proxy.js";
|
|
1
2
|
export function proxyResponseMiddleware() {
|
|
2
3
|
return async function proxyResponseMiddleware(ctx, next) {
|
|
3
4
|
await next();
|
|
4
5
|
const res = ctx.res;
|
|
5
|
-
if (res)
|
|
6
|
-
ctx.response =
|
|
7
|
-
get(res, prop) {
|
|
8
|
-
if (typeof prop === 'string') {
|
|
9
|
-
if (['json', 'text', 'arrayBuffer', 'blob', 'buffer', 'formData'].includes(prop)) {
|
|
10
|
-
/**
|
|
11
|
-
* clone when invoking body, json, text, arrayBuffer, blob, buffer, formData
|
|
12
|
-
* to avoid time-consuming cloning
|
|
13
|
-
*/
|
|
14
|
-
return new Proxy(res[prop], {
|
|
15
|
-
apply(target, thisArg, argArray) {
|
|
16
|
-
const mirror = res.clone();
|
|
17
|
-
return mirror[prop](...argArray);
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
if (prop === 'body') {
|
|
22
|
-
const mirror = res.clone();
|
|
23
|
-
return mirror.body;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (typeof res[prop] === 'function') {
|
|
27
|
-
return res[prop].bind(res);
|
|
28
|
-
}
|
|
29
|
-
return res[prop];
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
}
|
|
6
|
+
if (res)
|
|
7
|
+
ctx.response = createResponseProxy(res);
|
|
33
8
|
};
|
|
34
9
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createResponseProxy(res: Response): Response;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function createResponseProxy(res) {
|
|
2
|
+
return new Proxy(res, {
|
|
3
|
+
get(res, prop) {
|
|
4
|
+
if (typeof prop === 'string') {
|
|
5
|
+
if (['json', 'text', 'arrayBuffer', 'blob', 'buffer', 'formData'].includes(prop)) {
|
|
6
|
+
/**
|
|
7
|
+
* clone when invoking body, json, text, arrayBuffer, blob, buffer, formData
|
|
8
|
+
* to avoid time-consuming cloning
|
|
9
|
+
*/
|
|
10
|
+
return new Proxy(res[prop], {
|
|
11
|
+
apply(target, thisArg, argArray) {
|
|
12
|
+
const mirror = res.clone();
|
|
13
|
+
return mirror[prop](...argArray);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (prop === 'body') {
|
|
18
|
+
const mirror = res.clone();
|
|
19
|
+
return mirror.body;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (typeof res[prop] === 'function') {
|
|
23
|
+
return res[prop].bind(res);
|
|
24
|
+
}
|
|
25
|
+
return res[prop];
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
package/dist/umd/src/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { Keq } from './keq.js';
|
|
|
3
3
|
export { request } from './request.js';
|
|
4
4
|
export { composeMiddleware } from './util/compose-middleware.js';
|
|
5
5
|
export { composeRoute } from './util/compose-route.js';
|
|
6
|
+
export { createResponseProxy } from './util/create-response-proxy.js';
|
|
6
7
|
export type { KeqContext, KeqContextOptions } from './types/keq-context.js';
|
|
7
8
|
export type { KeqMiddleware } from './types/keq-middleware.js';
|
|
8
9
|
export type { KeqNext } from './types/keq-next.js';
|
package/dist/umd/src/index.js
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "./create-request.js", "./keq.js", "./request.js", "./util/compose-middleware.js", "./util/compose-route.js", "./router/keq-host-route.js", "./router/keq-location-route.js", "./router/keq-method-route.js", "./router/keq-module-route.js", "./router/keq-pathname-route.js", "./router/keq-router.js"], factory);
|
|
7
|
+
define(["require", "exports", "./create-request.js", "./keq.js", "./request.js", "./util/compose-middleware.js", "./util/compose-route.js", "./util/create-response-proxy.js", "./router/keq-host-route.js", "./router/keq-location-route.js", "./router/keq-method-route.js", "./router/keq-module-route.js", "./router/keq-pathname-route.js", "./router/keq-router.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.KeqRouter = exports.keqPathnameRoute = exports.keqModuleRoute = exports.keqMethodRoute = exports.keqLocationRoute = exports.keqHostRoute = exports.composeRoute = exports.composeMiddleware = exports.request = exports.Keq = exports.createRequest = void 0;
|
|
12
|
+
exports.KeqRouter = exports.keqPathnameRoute = exports.keqModuleRoute = exports.keqMethodRoute = exports.keqLocationRoute = exports.keqHostRoute = exports.createResponseProxy = exports.composeRoute = exports.composeMiddleware = exports.request = exports.Keq = exports.createRequest = void 0;
|
|
13
13
|
var create_request_js_1 = require("./create-request.js");
|
|
14
14
|
Object.defineProperty(exports, "createRequest", { enumerable: true, get: function () { return create_request_js_1.createRequest; } });
|
|
15
15
|
var keq_js_1 = require("./keq.js");
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
Object.defineProperty(exports, "composeMiddleware", { enumerable: true, get: function () { return compose_middleware_js_1.composeMiddleware; } });
|
|
21
21
|
var compose_route_js_1 = require("./util/compose-route.js");
|
|
22
22
|
Object.defineProperty(exports, "composeRoute", { enumerable: true, get: function () { return compose_route_js_1.composeRoute; } });
|
|
23
|
+
var create_response_proxy_js_1 = require("./util/create-response-proxy.js");
|
|
24
|
+
Object.defineProperty(exports, "createResponseProxy", { enumerable: true, get: function () { return create_response_proxy_js_1.createResponseProxy; } });
|
|
23
25
|
var keq_host_route_js_1 = require("./router/keq-host-route.js");
|
|
24
26
|
Object.defineProperty(exports, "keqHostRoute", { enumerable: true, get: function () { return keq_host_route_js_1.keqHostRoute; } });
|
|
25
27
|
var keq_location_route_js_1 = require("./router/keq-location-route.js");
|
package/dist/umd/src/keq.d.ts
CHANGED
|
@@ -4,44 +4,19 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"], factory);
|
|
7
|
+
define(["require", "exports", "../util/create-response-proxy.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.proxyResponseMiddleware = void 0;
|
|
13
|
+
const create_response_proxy_js_1 = require("../util/create-response-proxy.js");
|
|
13
14
|
function proxyResponseMiddleware() {
|
|
14
15
|
return async function proxyResponseMiddleware(ctx, next) {
|
|
15
16
|
await next();
|
|
16
17
|
const res = ctx.res;
|
|
17
|
-
if (res)
|
|
18
|
-
ctx.response =
|
|
19
|
-
get(res, prop) {
|
|
20
|
-
if (typeof prop === 'string') {
|
|
21
|
-
if (['json', 'text', 'arrayBuffer', 'blob', 'buffer', 'formData'].includes(prop)) {
|
|
22
|
-
/**
|
|
23
|
-
* clone when invoking body, json, text, arrayBuffer, blob, buffer, formData
|
|
24
|
-
* to avoid time-consuming cloning
|
|
25
|
-
*/
|
|
26
|
-
return new Proxy(res[prop], {
|
|
27
|
-
apply(target, thisArg, argArray) {
|
|
28
|
-
const mirror = res.clone();
|
|
29
|
-
return mirror[prop](...argArray);
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
if (prop === 'body') {
|
|
34
|
-
const mirror = res.clone();
|
|
35
|
-
return mirror.body;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (typeof res[prop] === 'function') {
|
|
39
|
-
return res[prop].bind(res);
|
|
40
|
-
}
|
|
41
|
-
return res[prop];
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
}
|
|
18
|
+
if (res)
|
|
19
|
+
ctx.response = (0, create_response_proxy_js_1.createResponseProxy)(res);
|
|
45
20
|
};
|
|
46
21
|
}
|
|
47
22
|
exports.proxyResponseMiddleware = proxyResponseMiddleware;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createResponseProxy(res: Response): Response;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createResponseProxy = void 0;
|
|
13
|
+
function createResponseProxy(res) {
|
|
14
|
+
return new Proxy(res, {
|
|
15
|
+
get(res, prop) {
|
|
16
|
+
if (typeof prop === 'string') {
|
|
17
|
+
if (['json', 'text', 'arrayBuffer', 'blob', 'buffer', 'formData'].includes(prop)) {
|
|
18
|
+
/**
|
|
19
|
+
* clone when invoking body, json, text, arrayBuffer, blob, buffer, formData
|
|
20
|
+
* to avoid time-consuming cloning
|
|
21
|
+
*/
|
|
22
|
+
return new Proxy(res[prop], {
|
|
23
|
+
apply(target, thisArg, argArray) {
|
|
24
|
+
const mirror = res.clone();
|
|
25
|
+
return mirror[prop](...argArray);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (prop === 'body') {
|
|
30
|
+
const mirror = res.clone();
|
|
31
|
+
return mirror.body;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (typeof res[prop] === 'function') {
|
|
35
|
+
return res[prop].bind(res);
|
|
36
|
+
}
|
|
37
|
+
return res[prop];
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.createResponseProxy = createResponseProxy;
|
|
42
|
+
});
|