keq 2.7.0 → 2.7.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 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
+ ## [2.7.2](https://github.com/keq-request/keq/compare/v2.7.1...v2.7.2) (2024-08-13)
6
+
7
+
8
+ ### Performance Improvements
9
+
10
+ * allow header to add number type fields ([bacacaa](https://github.com/keq-request/keq/commit/bacacaac66d9e249a6b66d539bafb94d9f064869))
11
+
12
+ ## [2.7.1](https://github.com/keq-request/keq/compare/v2.7.0...v2.7.1) (2024-07-20)
13
+
14
+
15
+ ### Performance Improvements
16
+
17
+ * remove whatwg-url because mosts browsers had support ([6877d79](https://github.com/keq-request/keq/commit/6877d79e95721ea76adcf54013c1909b0dec98a3))
18
+
5
19
  ## [2.7.0](https://github.com/keq-request/keq/compare/v2.6.10...v2.7.0) (2024-07-05)
6
20
 
7
21
 
@@ -1,4 +1,3 @@
1
- import { URL } from 'whatwg-url';
2
1
  import type { KeqContextOptions } from './types/keq-context.js';
3
2
  import type { KeqMiddleware } from './types/keq-middleware.js';
4
3
  import type { KeqInit } from './types/keq-init.js';
@@ -15,7 +14,7 @@ export declare class Core<OUTPUT> {
15
14
  protected __prepend_middlewares__: KeqMiddleware[];
16
15
  protected __append_middlewares__: KeqMiddleware[];
17
16
  protected __options__: KeqContextOptions;
18
- constructor(url: (URL | globalThis.URL), init: KeqInit, global?: Record<string, any>);
17
+ constructor(url: URL, init: KeqInit, global?: Record<string, any>);
19
18
  prependMiddlewares(...middlewares: KeqMiddleware[]): this;
20
19
  appendMiddlewares(...middlewares: KeqMiddleware[]): this;
21
20
  on<K extends keyof KeqEvents>(event: K, listener: (data: KeqEvents[K]) => void): this;
@@ -1,5 +1,4 @@
1
1
  import mitt from 'mitt';
2
- import { URL } from 'whatwg-url';
3
2
  import { Exception } from './exception/exception.js';
4
3
  import { cloneBody } from './util/clone-body.js';
5
4
  import { ABORT_PROPERTY, NEXT_INVOKED_PROPERTY, OUTPUT_PROPERTY } from './constant.js';
@@ -1,5 +1,4 @@
1
1
  /* eslint-disable @typescript-eslint/no-unsafe-return */
2
- import { URL } from 'whatwg-url';
3
2
  import { isBrowser } from './is/is-browser.js';
4
3
  import { Keq } from './keq.js';
5
4
  import { abortFlowControlMiddleware } from './middlewares/abort-flow-control-middleware.js';
@@ -39,14 +39,14 @@ export class Keq extends Core {
39
39
  if (!isValidHeaderValue(value)) {
40
40
  throw new Exception(`[Invalid header] Key: ${headersOrName} Value: ${value}`);
41
41
  }
42
- this.requestContext.headers.set(headersOrName, value);
42
+ this.requestContext.headers.set(headersOrName, String(value));
43
43
  }
44
44
  else if (typeof headersOrName === 'object') {
45
45
  for (const [key, value] of Object.entries(headersOrName)) {
46
46
  if (!isValidHeaderValue(value)) {
47
47
  throw new Exception(`[Invalid header] Key: ${key} Value: ${value}`);
48
48
  }
49
- this.requestContext.headers.set(key, value);
49
+ this.requestContext.headers.set(key, String(value));
50
50
  }
51
51
  }
52
52
  return this;
@@ -1,10 +1,9 @@
1
- import { URL } from 'whatwg-url';
2
1
  export type KeqContextRequestMethod = 'get' | 'post' | 'put' | 'delete' | 'head' | 'patch';
3
2
  export type KeqContextRequestBody = object | Array<any> | string | undefined;
4
3
  export interface KeqContextRequest {
5
- url: URL | globalThis.URL;
4
+ url: URL;
6
5
  routeParams: Record<string, string>;
7
- readonly __url__: Readonly<URL> | Readonly<globalThis.URL>;
6
+ readonly __url__: Readonly<URL>;
8
7
  method: KeqContextRequestMethod;
9
8
  headers: Headers;
10
9
  body: KeqContextRequestBody;
@@ -9,7 +9,7 @@ export interface KeqOperation {
9
9
  [key: string]: string | string[] | number;
10
10
  };
11
11
  requestHeaders: {
12
- [key: string]: string;
12
+ [key: string]: string | number;
13
13
  };
14
14
  requestBody: FormData | URLSearchParams | object | Array<any> | string;
15
15
  responseBody: any;
@@ -1,15 +1,12 @@
1
1
  import { FlattenOperations, KeqOperation, KeqOperations } from './keq-operation.js';
2
- import type { URL } from 'whatwg-url';
3
2
  import type { KeqRouter } from "../router/keq-router.js";
4
3
  import type { Keq } from "../keq.js";
5
4
  import type { KeqMiddleware } from './keq-middleware.js';
6
5
  import type { KeqInit } from './keq-init.js';
7
- type GlobalURL = globalThis.URL;
8
6
  interface KeqRequestFn<OPERATIONS extends Record<string, KeqOperation>> {
9
7
  <Path extends keyof OPERATIONS>(url: Path): Keq<OPERATIONS[Path]['responseBody'], OPERATIONS[Path]>;
10
8
  <OUTPUT = any>(url: string): Keq<OUTPUT>;
11
9
  <OUTPUT = any>(url: URL): Keq<OUTPUT>;
12
- <OUTPUT = any>(url: GlobalURL): Keq<OUTPUT>;
13
10
  }
14
11
  type PickKeqOperationsProperty<T extends KeqOperations, P extends keyof T, X extends keyof KeqOperation> = T extends {
15
12
  [Path in keyof T as Path extends P ? Path : never]: {
@@ -20,7 +17,6 @@ export interface KeqRequest<OPERATIONS extends KeqOperations = KeqOperations> {
20
17
  <Path extends keyof OPERATIONS>(url: Path, init: Omit<KeqInit, 'global'>): Keq<Exclude<PickKeqOperationsProperty<OPERATIONS, Path, 'responseBody'>, undefined>>;
21
18
  <OUTPUT = any>(url: string, init: Omit<KeqInit, 'global'>): Keq<OUTPUT>;
22
19
  <OUTPUT = any>(url: URL, init: Omit<KeqInit, 'global'>): Keq<OUTPUT>;
23
- <OUTPUT = any>(url: GlobalURL, init: Omit<KeqInit, 'global'>): Keq<OUTPUT>;
24
20
  baseOrigin: (baseOrigin: string) => void;
25
21
  get: KeqRequestFn<FlattenOperations<OPERATIONS, 'get'>>;
26
22
  post: KeqRequestFn<FlattenOperations<OPERATIONS, 'post'>>;
@@ -1,4 +1,4 @@
1
- import { isBuffer } from "../is/is-buffer.js";
1
+ import { isBuffer } from '../is/is-buffer.js';
2
2
  import { isBlob } from '../is/is-blob.js';
3
3
  import { isFile } from '../is/is-file.js';
4
4
  import { isFormData } from '../is/is-form-data.js';
@@ -1,2 +1 @@
1
- import { URL } from 'whatwg-url';
2
- export declare function compileUrl(obj: string | URL | globalThis.URL, routeParams: Record<string, string | number>): URL;
1
+ export declare function compileUrl(obj: string | URL, routeParams: Record<string, string | number>): URL;
@@ -1,4 +1,3 @@
1
- import { URL } from 'whatwg-url';
2
1
  function compilePathnameTemplate(template, params) {
3
2
  return template
4
3
  .replace(/(^|\/)(?::([^/]+)|{([^/]+)}|%7B([^/]+)%7D)(?=$|\/)/g, (_, prefix, group1, group2, group3) => {
@@ -1,4 +1,3 @@
1
- import { URL } from 'whatwg-url';
2
1
  import type { KeqContextOptions } from './types/keq-context.js';
3
2
  import type { KeqMiddleware } from './types/keq-middleware.js';
4
3
  import type { KeqInit } from './types/keq-init.js';
@@ -15,7 +14,7 @@ export declare class Core<OUTPUT> {
15
14
  protected __prepend_middlewares__: KeqMiddleware[];
16
15
  protected __append_middlewares__: KeqMiddleware[];
17
16
  protected __options__: KeqContextOptions;
18
- constructor(url: (URL | globalThis.URL), init: KeqInit, global?: Record<string, any>);
17
+ constructor(url: URL, init: KeqInit, global?: Record<string, any>);
19
18
  prependMiddlewares(...middlewares: KeqMiddleware[]): this;
20
19
  appendMiddlewares(...middlewares: KeqMiddleware[]): this;
21
20
  on<K extends keyof KeqEvents>(event: K, listener: (data: KeqEvents[K]) => void): this;
@@ -7,14 +7,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  if (v !== undefined) module.exports = v;
8
8
  }
9
9
  else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "mitt", "whatwg-url", "./exception/exception.js", "./util/clone-body.js", "./constant.js", "./util/compose-middleware.js", "./util/shallow-clone.js", "./util/compile-url.js"], factory);
10
+ define(["require", "exports", "mitt", "./exception/exception.js", "./util/clone-body.js", "./constant.js", "./util/compose-middleware.js", "./util/shallow-clone.js", "./util/compile-url.js"], factory);
11
11
  }
12
12
  })(function (require, exports) {
13
13
  "use strict";
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Core = void 0;
16
16
  const mitt_1 = __importDefault(require("mitt"));
17
- const whatwg_url_1 = require("whatwg-url");
18
17
  const exception_js_1 = require("./exception/exception.js");
19
18
  const clone_body_js_1 = require("./util/clone-body.js");
20
19
  const constant_js_1 = require("./constant.js");
@@ -43,7 +42,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
43
42
  routeParams: {},
44
43
  body: undefined,
45
44
  ...init,
46
- url: new whatwg_url_1.URL(url.href),
45
+ url: new URL(url.href),
47
46
  };
48
47
  }
49
48
  prependMiddlewares(...middlewares) {
@@ -65,7 +64,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
65
64
  headers.append(key, value);
66
65
  }
67
66
  const requestContext = {
68
- url: new whatwg_url_1.URL(this.requestContext.url.href),
67
+ url: new URL(this.requestContext.url.href),
69
68
  routeParams: (0, shallow_clone_js_1.shallowClone)(this.requestContext.routeParams),
70
69
  get __url__() {
71
70
  return (0, compile_url_js_1.compileUrl)(this.url, this.routeParams);
@@ -4,14 +4,13 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "whatwg-url", "./is/is-browser.js", "./keq.js", "./middlewares/abort-flow-control-middleware.js", "./middlewares/fetch-arguments-middleware.js", "./middlewares/fetch-middleware.js", "./middlewares/proxy-response-middleware.js", "./middlewares/retry-middleware.js", "./middlewares/serial-flow-control-middleware.js", "./router/keq-router.js", "./middlewares/timeout-middleware.js"], factory);
7
+ define(["require", "exports", "./is/is-browser.js", "./keq.js", "./middlewares/abort-flow-control-middleware.js", "./middlewares/fetch-arguments-middleware.js", "./middlewares/fetch-middleware.js", "./middlewares/proxy-response-middleware.js", "./middlewares/retry-middleware.js", "./middlewares/serial-flow-control-middleware.js", "./router/keq-router.js", "./middlewares/timeout-middleware.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.createRequest = void 0;
13
13
  /* eslint-disable @typescript-eslint/no-unsafe-return */
14
- const whatwg_url_1 = require("whatwg-url");
15
14
  const is_browser_js_1 = require("./is/is-browser.js");
16
15
  const keq_js_1 = require("./keq.js");
17
16
  const abort_flow_control_middleware_js_1 = require("./middlewares/abort-flow-control-middleware.js");
@@ -49,9 +48,9 @@
49
48
  const global = {};
50
49
  const formatUrl = (url) => {
51
50
  if (typeof url === 'string') {
52
- return new whatwg_url_1.URL(url, baseOrigin);
51
+ return new URL(url, baseOrigin);
53
52
  }
54
- return new whatwg_url_1.URL(url.href);
53
+ return new URL(url.href);
55
54
  };
56
55
  const router = new keq_router_js_1.KeqRouter(prependMiddlewares);
57
56
  const request = function (url, init) {
@@ -51,14 +51,14 @@
51
51
  if (!(0, is_valid_header_value_js_1.isValidHeaderValue)(value)) {
52
52
  throw new exception_js_1.Exception(`[Invalid header] Key: ${headersOrName} Value: ${value}`);
53
53
  }
54
- this.requestContext.headers.set(headersOrName, value);
54
+ this.requestContext.headers.set(headersOrName, String(value));
55
55
  }
56
56
  else if (typeof headersOrName === 'object') {
57
57
  for (const [key, value] of Object.entries(headersOrName)) {
58
58
  if (!(0, is_valid_header_value_js_1.isValidHeaderValue)(value)) {
59
59
  throw new exception_js_1.Exception(`[Invalid header] Key: ${key} Value: ${value}`);
60
60
  }
61
- this.requestContext.headers.set(key, value);
61
+ this.requestContext.headers.set(key, String(value));
62
62
  }
63
63
  }
64
64
  return this;
@@ -1,10 +1,9 @@
1
- import { URL } from 'whatwg-url';
2
1
  export type KeqContextRequestMethod = 'get' | 'post' | 'put' | 'delete' | 'head' | 'patch';
3
2
  export type KeqContextRequestBody = object | Array<any> | string | undefined;
4
3
  export interface KeqContextRequest {
5
- url: URL | globalThis.URL;
4
+ url: URL;
6
5
  routeParams: Record<string, string>;
7
- readonly __url__: Readonly<URL> | Readonly<globalThis.URL>;
6
+ readonly __url__: Readonly<URL>;
8
7
  method: KeqContextRequestMethod;
9
8
  headers: Headers;
10
9
  body: KeqContextRequestBody;
@@ -9,7 +9,7 @@ export interface KeqOperation {
9
9
  [key: string]: string | string[] | number;
10
10
  };
11
11
  requestHeaders: {
12
- [key: string]: string;
12
+ [key: string]: string | number;
13
13
  };
14
14
  requestBody: FormData | URLSearchParams | object | Array<any> | string;
15
15
  responseBody: any;
@@ -1,15 +1,12 @@
1
1
  import { FlattenOperations, KeqOperation, KeqOperations } from './keq-operation.js';
2
- import type { URL } from 'whatwg-url';
3
2
  import type { KeqRouter } from "../router/keq-router.js";
4
3
  import type { Keq } from "../keq.js";
5
4
  import type { KeqMiddleware } from './keq-middleware.js';
6
5
  import type { KeqInit } from './keq-init.js';
7
- type GlobalURL = globalThis.URL;
8
6
  interface KeqRequestFn<OPERATIONS extends Record<string, KeqOperation>> {
9
7
  <Path extends keyof OPERATIONS>(url: Path): Keq<OPERATIONS[Path]['responseBody'], OPERATIONS[Path]>;
10
8
  <OUTPUT = any>(url: string): Keq<OUTPUT>;
11
9
  <OUTPUT = any>(url: URL): Keq<OUTPUT>;
12
- <OUTPUT = any>(url: GlobalURL): Keq<OUTPUT>;
13
10
  }
14
11
  type PickKeqOperationsProperty<T extends KeqOperations, P extends keyof T, X extends keyof KeqOperation> = T extends {
15
12
  [Path in keyof T as Path extends P ? Path : never]: {
@@ -20,7 +17,6 @@ export interface KeqRequest<OPERATIONS extends KeqOperations = KeqOperations> {
20
17
  <Path extends keyof OPERATIONS>(url: Path, init: Omit<KeqInit, 'global'>): Keq<Exclude<PickKeqOperationsProperty<OPERATIONS, Path, 'responseBody'>, undefined>>;
21
18
  <OUTPUT = any>(url: string, init: Omit<KeqInit, 'global'>): Keq<OUTPUT>;
22
19
  <OUTPUT = any>(url: URL, init: Omit<KeqInit, 'global'>): Keq<OUTPUT>;
23
- <OUTPUT = any>(url: GlobalURL, init: Omit<KeqInit, 'global'>): Keq<OUTPUT>;
24
20
  baseOrigin: (baseOrigin: string) => void;
25
21
  get: KeqRequestFn<FlattenOperations<OPERATIONS, 'get'>>;
26
22
  post: KeqRequestFn<FlattenOperations<OPERATIONS, 'post'>>;
@@ -1,2 +1 @@
1
- import { URL } from 'whatwg-url';
2
- export declare function compileUrl(obj: string | URL | globalThis.URL, routeParams: Record<string, string | number>): URL;
1
+ export declare function compileUrl(obj: string | URL, routeParams: Record<string, string | number>): URL;
@@ -4,13 +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", "whatwg-url"], factory);
7
+ define(["require", "exports"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.compileUrl = void 0;
13
- const whatwg_url_1 = require("whatwg-url");
14
13
  function compilePathnameTemplate(template, params) {
15
14
  return template
16
15
  .replace(/(^|\/)(?::([^/]+)|{([^/]+)}|%7B([^/]+)%7D)(?=$|\/)/g, (_, prefix, group1, group2, group3) => {
@@ -27,7 +26,7 @@
27
26
  });
28
27
  }
29
28
  function compileUrl(obj, routeParams) {
30
- const url = new whatwg_url_1.URL(typeof obj === 'string' ? obj : obj.href);
29
+ const url = new URL(typeof obj === 'string' ? obj : obj.href);
31
30
  url.pathname = compilePathnameTemplate(url.pathname, routeParams);
32
31
  return url;
33
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keq",
3
- "version": "2.7.0",
3
+ "version": "2.7.2",
4
4
  "description": "Request API write by Typescript for flexibility, readability, and a low learning curve.",
5
5
  "keywords": [
6
6
  "request",
@@ -40,12 +40,10 @@
40
40
  "test": "jest"
41
41
  },
42
42
  "dependencies": {
43
- "@types/whatwg-url": "^11.0.5",
44
43
  "fastq": "^1.17.1",
45
44
  "minimatch": "^9.0.4",
46
45
  "mitt": "^3.0.1",
47
- "ts-custom-error": "^3.3.1",
48
- "whatwg-url": "^14.0.0"
46
+ "ts-custom-error": "^3.3.1"
49
47
  },
50
48
  "devDependencies": {
51
49
  "@buka/eslint-config": "^1.6.4",