keq 2.8.4 → 2.8.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/CHANGELOG.md +7 -0
- package/dist/esm/src/keq.js +5 -5
- package/dist/esm/src/types/keq-context-request.d.ts +1 -1
- package/dist/esm/src/util/merge-keq-request-body.d.ts +2 -0
- package/dist/esm/src/util/{assign-keq-request-body.js → merge-keq-request-body.js} +14 -17
- package/dist/umd/src/keq.js +6 -6
- package/dist/umd/src/types/keq-context-request.d.ts +1 -1
- package/dist/umd/src/util/merge-keq-request-body.d.ts +2 -0
- package/dist/umd/src/util/{assign-keq-request-body.js → merge-keq-request-body.js} +16 -19
- package/package.json +6 -6
- package/dist/esm/src/util/assign-keq-request-body.d.ts +0 -2
- package/dist/umd/src/util/assign-keq-request-body.d.ts +0 -2
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.5](https://github.com/keq-request/keq/compare/v2.8.4...v2.8.5) (2024-10-25)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Performance Improvements
|
|
9
|
+
|
|
10
|
+
* support send binary body ([4f17198](https://github.com/keq-request/keq/commit/4f17198915e46bfb08a6900c2b784c5299164c2f))
|
|
11
|
+
|
|
5
12
|
## [2.8.4](https://github.com/keq-request/keq/compare/v2.8.3...v2.8.4) (2024-10-20)
|
|
6
13
|
|
|
7
14
|
|
package/dist/esm/src/keq.js
CHANGED
|
@@ -8,7 +8,7 @@ import { isFormData } from './is/is-form-data.js';
|
|
|
8
8
|
import { isHeaders } from './is/is-headers.js';
|
|
9
9
|
import { isBuffer } from './is/is-buffer.js';
|
|
10
10
|
import { isUrlSearchParams } from './is/is-url-search-params.js';
|
|
11
|
-
import {
|
|
11
|
+
import { mergeKeqRequestBody } from './util/merge-keq-request-body.js';
|
|
12
12
|
import { base64Encode } from './util/base64.js';
|
|
13
13
|
import { fixContentType } from './util/fix-content-type.js';
|
|
14
14
|
import { isValidHeaderValue } from './util/is-valid-header-value.js';
|
|
@@ -117,7 +117,7 @@ export class Keq extends Core {
|
|
|
117
117
|
void this.type(contentType);
|
|
118
118
|
}
|
|
119
119
|
send(value) {
|
|
120
|
-
this.requestContext.body =
|
|
120
|
+
this.requestContext.body = mergeKeqRequestBody(this.requestContext.body, value);
|
|
121
121
|
if (isUrlSearchParams(value)) {
|
|
122
122
|
this.setTypeIfEmpty('form');
|
|
123
123
|
}
|
|
@@ -131,10 +131,10 @@ export class Keq extends Core {
|
|
|
131
131
|
}
|
|
132
132
|
field(arg1, arg2) {
|
|
133
133
|
if (typeof arg1 === 'object') {
|
|
134
|
-
this.requestContext.body =
|
|
134
|
+
this.requestContext.body = mergeKeqRequestBody(this.requestContext.body, arg1);
|
|
135
135
|
}
|
|
136
136
|
else if (arg2) {
|
|
137
|
-
this.requestContext.body =
|
|
137
|
+
this.requestContext.body = mergeKeqRequestBody(this.requestContext.body, { [arg1]: arg2 });
|
|
138
138
|
}
|
|
139
139
|
else {
|
|
140
140
|
throw new InvalidArgumentsExceptions();
|
|
@@ -160,7 +160,7 @@ export class Keq extends Core {
|
|
|
160
160
|
else {
|
|
161
161
|
throw new InvalidArgumentsExceptions();
|
|
162
162
|
}
|
|
163
|
-
this.requestContext.body =
|
|
163
|
+
this.requestContext.body = mergeKeqRequestBody(this.requestContext.body, { [key]: file });
|
|
164
164
|
this.setTypeIfEmpty('form-data');
|
|
165
165
|
return this;
|
|
166
166
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type KeqContextRequestMethod = 'get' | 'post' | 'put' | 'delete' | 'head' | 'patch' | 'options';
|
|
2
|
-
export type KeqContextRequestBody = object | Array<any> |
|
|
2
|
+
export type KeqContextRequestBody = BodyInit | object | Array<any> | undefined;
|
|
3
3
|
export interface KeqContextRequest {
|
|
4
4
|
url: URL;
|
|
5
5
|
routeParams: Record<string, string>;
|
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
1
|
import { Exception } from '../exception/exception.js';
|
|
3
|
-
import { OverwriteArrayBodyException } from '../exception/overwrite-array-body.exception.js';
|
|
4
2
|
import { isFormData } from '../is/is-form-data.js';
|
|
5
3
|
import { isUrlSearchParams } from '../is/is-url-search-params.js';
|
|
6
|
-
export function
|
|
7
|
-
if (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (typeof right === 'string') {
|
|
20
|
-
return right;
|
|
4
|
+
export function mergeKeqRequestBody(left, right) {
|
|
5
|
+
if (right === undefined)
|
|
6
|
+
return left;
|
|
7
|
+
if (typeof right === 'number') {
|
|
8
|
+
throw new TypeError('Not support number type');
|
|
9
|
+
}
|
|
10
|
+
if (left === null ||
|
|
11
|
+
right === null ||
|
|
12
|
+
Array.isArray(left) ||
|
|
13
|
+
Array.isArray(right) ||
|
|
14
|
+
(typeof left !== 'object' && left !== undefined) ||
|
|
15
|
+
typeof right !== 'object') {
|
|
16
|
+
return Array.isArray(right) ? [...right] : right;
|
|
21
17
|
}
|
|
22
18
|
const result = left || {};
|
|
23
19
|
if (isUrlSearchParams(right)) {
|
|
@@ -45,6 +41,7 @@ export function assignKeqRequestBody(left, right) {
|
|
|
45
41
|
}
|
|
46
42
|
}
|
|
47
43
|
else if (typeof right === 'object') {
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
45
|
for (const key in right) {
|
|
49
46
|
result[key] = right[key];
|
|
50
47
|
}
|
package/dist/umd/src/keq.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", "./core.js", "./exception/exception.js", "./exception/invalid-arguments.exception.js", "./is/is-blob.js", "./is/is-file.js", "./is/is-form-data.js", "./is/is-headers.js", "./is/is-buffer.js", "./is/is-url-search-params.js", "./util/
|
|
7
|
+
define(["require", "exports", "./core.js", "./exception/exception.js", "./exception/invalid-arguments.exception.js", "./is/is-blob.js", "./is/is-file.js", "./is/is-form-data.js", "./is/is-headers.js", "./is/is-buffer.js", "./is/is-url-search-params.js", "./util/merge-keq-request-body.js", "./util/base64.js", "./util/fix-content-type.js", "./util/is-valid-header-value.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
const is_headers_js_1 = require("./is/is-headers.js");
|
|
21
21
|
const is_buffer_js_1 = require("./is/is-buffer.js");
|
|
22
22
|
const is_url_search_params_js_1 = require("./is/is-url-search-params.js");
|
|
23
|
-
const
|
|
23
|
+
const merge_keq_request_body_js_1 = require("./util/merge-keq-request-body.js");
|
|
24
24
|
const base64_js_1 = require("./util/base64.js");
|
|
25
25
|
const fix_content_type_js_1 = require("./util/fix-content-type.js");
|
|
26
26
|
const is_valid_header_value_js_1 = require("./util/is-valid-header-value.js");
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
void this.type(contentType);
|
|
130
130
|
}
|
|
131
131
|
send(value) {
|
|
132
|
-
this.requestContext.body = (0,
|
|
132
|
+
this.requestContext.body = (0, merge_keq_request_body_js_1.mergeKeqRequestBody)(this.requestContext.body, value);
|
|
133
133
|
if ((0, is_url_search_params_js_1.isUrlSearchParams)(value)) {
|
|
134
134
|
this.setTypeIfEmpty('form');
|
|
135
135
|
}
|
|
@@ -143,10 +143,10 @@
|
|
|
143
143
|
}
|
|
144
144
|
field(arg1, arg2) {
|
|
145
145
|
if (typeof arg1 === 'object') {
|
|
146
|
-
this.requestContext.body = (0,
|
|
146
|
+
this.requestContext.body = (0, merge_keq_request_body_js_1.mergeKeqRequestBody)(this.requestContext.body, arg1);
|
|
147
147
|
}
|
|
148
148
|
else if (arg2) {
|
|
149
|
-
this.requestContext.body = (0,
|
|
149
|
+
this.requestContext.body = (0, merge_keq_request_body_js_1.mergeKeqRequestBody)(this.requestContext.body, { [arg1]: arg2 });
|
|
150
150
|
}
|
|
151
151
|
else {
|
|
152
152
|
throw new invalid_arguments_exception_js_1.InvalidArgumentsExceptions();
|
|
@@ -172,7 +172,7 @@
|
|
|
172
172
|
else {
|
|
173
173
|
throw new invalid_arguments_exception_js_1.InvalidArgumentsExceptions();
|
|
174
174
|
}
|
|
175
|
-
this.requestContext.body = (0,
|
|
175
|
+
this.requestContext.body = (0, merge_keq_request_body_js_1.mergeKeqRequestBody)(this.requestContext.body, { [key]: file });
|
|
176
176
|
this.setTypeIfEmpty('form-data');
|
|
177
177
|
return this;
|
|
178
178
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type KeqContextRequestMethod = 'get' | 'post' | 'put' | 'delete' | 'head' | 'patch' | 'options';
|
|
2
|
-
export type KeqContextRequestBody = object | Array<any> |
|
|
2
|
+
export type KeqContextRequestBody = BodyInit | object | Array<any> | undefined;
|
|
3
3
|
export interface KeqContextRequest {
|
|
4
4
|
url: URL;
|
|
5
5
|
routeParams: Record<string, string>;
|
|
@@ -4,32 +4,28 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "../exception/exception.js", "../
|
|
7
|
+
define(["require", "exports", "../exception/exception.js", "../is/is-form-data.js", "../is/is-url-search-params.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
12
|
+
exports.mergeKeqRequestBody = void 0;
|
|
14
13
|
const exception_js_1 = require("../exception/exception.js");
|
|
15
|
-
const overwrite_array_body_exception_js_1 = require("../exception/overwrite-array-body.exception.js");
|
|
16
14
|
const is_form_data_js_1 = require("../is/is-form-data.js");
|
|
17
15
|
const is_url_search_params_js_1 = require("../is/is-url-search-params.js");
|
|
18
|
-
function
|
|
19
|
-
if (
|
|
20
|
-
|
|
16
|
+
function mergeKeqRequestBody(left, right) {
|
|
17
|
+
if (right === undefined)
|
|
18
|
+
return left;
|
|
19
|
+
if (typeof right === 'number') {
|
|
20
|
+
throw new TypeError('Not support number type');
|
|
21
21
|
}
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return [...right];
|
|
30
|
-
}
|
|
31
|
-
if (typeof right === 'string') {
|
|
32
|
-
return right;
|
|
22
|
+
if (left === null ||
|
|
23
|
+
right === null ||
|
|
24
|
+
Array.isArray(left) ||
|
|
25
|
+
Array.isArray(right) ||
|
|
26
|
+
(typeof left !== 'object' && left !== undefined) ||
|
|
27
|
+
typeof right !== 'object') {
|
|
28
|
+
return Array.isArray(right) ? [...right] : right;
|
|
33
29
|
}
|
|
34
30
|
const result = left || {};
|
|
35
31
|
if ((0, is_url_search_params_js_1.isUrlSearchParams)(right)) {
|
|
@@ -57,6 +53,7 @@
|
|
|
57
53
|
}
|
|
58
54
|
}
|
|
59
55
|
else if (typeof right === 'object') {
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
57
|
for (const key in right) {
|
|
61
58
|
result[key] = right[key];
|
|
62
59
|
}
|
|
@@ -66,5 +63,5 @@
|
|
|
66
63
|
}
|
|
67
64
|
return result;
|
|
68
65
|
}
|
|
69
|
-
exports.
|
|
66
|
+
exports.mergeKeqRequestBody = mergeKeqRequestBody;
|
|
70
67
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keq",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.5",
|
|
4
4
|
"description": "Request API write by Typescript for flexibility, readability, and a low learning curve.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"request",
|
|
@@ -49,14 +49,14 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@buka/eslint-config": "^2.1.1",
|
|
52
|
-
"@commitlint/cli": "^19.
|
|
53
|
-
"@commitlint/config-conventional": "^19.
|
|
52
|
+
"@commitlint/cli": "^19.5.0",
|
|
53
|
+
"@commitlint/config-conventional": "^19.5.0",
|
|
54
54
|
"@jest/globals": "^29.7.0",
|
|
55
55
|
"@types/clone": "^2.1.4",
|
|
56
56
|
"@types/minimatch": "^5.1.2",
|
|
57
57
|
"@types/node": "^20.14.1",
|
|
58
|
-
"eslint": "^9.
|
|
59
|
-
"husky": "^9.
|
|
58
|
+
"eslint": "^9.13.0",
|
|
59
|
+
"husky": "^9.1.6",
|
|
60
60
|
"is-ci": "^3.0.1",
|
|
61
61
|
"jest": "^29.7.0",
|
|
62
62
|
"jest-environment-jsdom": "^29.7.0",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"ts-node": "^10.9.2",
|
|
67
67
|
"ts-patch": "^3.2.0",
|
|
68
68
|
"typescript": "5.4.5",
|
|
69
|
-
"typescript-transform-paths": "^3.
|
|
69
|
+
"typescript-transform-paths": "^3.5.1"
|
|
70
70
|
},
|
|
71
71
|
"packageManager": "pnpm@9.12.2",
|
|
72
72
|
"engines": {
|