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 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
 
@@ -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 { assignKeqRequestBody } from './util/assign-keq-request-body.js';
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 = assignKeqRequestBody(this.requestContext.body, value);
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 = assignKeqRequestBody(this.requestContext.body, arg1);
134
+ this.requestContext.body = mergeKeqRequestBody(this.requestContext.body, arg1);
135
135
  }
136
136
  else if (arg2) {
137
- this.requestContext.body = assignKeqRequestBody(this.requestContext.body, { [arg1]: arg2 });
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 = assignKeqRequestBody(this.requestContext.body, { [key]: file });
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> | string | undefined;
2
+ export type KeqContextRequestBody = BodyInit | object | Array<any> | undefined;
3
3
  export interface KeqContextRequest {
4
4
  url: URL;
5
5
  routeParams: Record<string, string>;
@@ -0,0 +1,2 @@
1
+ import type { KeqContextRequestBody } from '../types/keq-context-request.js';
2
+ export declare function mergeKeqRequestBody(left: KeqContextRequestBody, right: KeqContextRequestBody): KeqContextRequestBody;
@@ -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 assignKeqRequestBody(left, right) {
7
- if (Array.isArray(left)) {
8
- throw new OverwriteArrayBodyException();
9
- }
10
- if (Array.isArray(right) && left) {
11
- throw new Exception(`Cannot overwrite body(${typeof right}) with array`);
12
- }
13
- if (typeof right === 'string' && left) {
14
- throw new Exception(`Cannot overwrite body(${typeof left}) with string`);
15
- }
16
- if (Array.isArray(right)) {
17
- return [...right];
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
  }
@@ -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/assign-keq-request-body.js", "./util/base64.js", "./util/fix-content-type.js", "./util/is-valid-header-value.js"], factory);
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 assign_keq_request_body_js_1 = require("./util/assign-keq-request-body.js");
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, assign_keq_request_body_js_1.assignKeqRequestBody)(this.requestContext.body, value);
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, assign_keq_request_body_js_1.assignKeqRequestBody)(this.requestContext.body, arg1);
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, assign_keq_request_body_js_1.assignKeqRequestBody)(this.requestContext.body, { [arg1]: arg2 });
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, assign_keq_request_body_js_1.assignKeqRequestBody)(this.requestContext.body, { [key]: file });
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> | string | undefined;
2
+ export type KeqContextRequestBody = BodyInit | object | Array<any> | undefined;
3
3
  export interface KeqContextRequest {
4
4
  url: URL;
5
5
  routeParams: Record<string, string>;
@@ -0,0 +1,2 @@
1
+ import type { KeqContextRequestBody } from '../types/keq-context-request.js';
2
+ export declare function mergeKeqRequestBody(left: KeqContextRequestBody, right: KeqContextRequestBody): KeqContextRequestBody;
@@ -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", "../exception/overwrite-array-body.exception.js", "../is/is-form-data.js", "../is/is-url-search-params.js"], factory);
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.assignKeqRequestBody = void 0;
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 assignKeqRequestBody(left, right) {
19
- if (Array.isArray(left)) {
20
- throw new overwrite_array_body_exception_js_1.OverwriteArrayBodyException();
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 (Array.isArray(right) && left) {
23
- throw new exception_js_1.Exception(`Cannot overwrite body(${typeof right}) with array`);
24
- }
25
- if (typeof right === 'string' && left) {
26
- throw new exception_js_1.Exception(`Cannot overwrite body(${typeof left}) with string`);
27
- }
28
- if (Array.isArray(right)) {
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.assignKeqRequestBody = assignKeqRequestBody;
66
+ exports.mergeKeqRequestBody = mergeKeqRequestBody;
70
67
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keq",
3
- "version": "2.8.4",
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.3.0",
53
- "@commitlint/config-conventional": "^19.2.2",
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.10.0",
59
- "husky": "^9.0.11",
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.4.7"
69
+ "typescript-transform-paths": "^3.5.1"
70
70
  },
71
71
  "packageManager": "pnpm@9.12.2",
72
72
  "engines": {
@@ -1,2 +0,0 @@
1
- import type { KeqContextRequestBody } from '../types/keq-context-request.js';
2
- export declare function assignKeqRequestBody(left: KeqContextRequestBody, right: object | Array<any> | FormData | URLSearchParams | string): KeqContextRequestBody;
@@ -1,2 +0,0 @@
1
- import type { KeqContextRequestBody } from '../types/keq-context-request.js';
2
- export declare function assignKeqRequestBody(left: KeqContextRequestBody, right: object | Array<any> | FormData | URLSearchParams | string): KeqContextRequestBody;