keq 1.8.8 → 1.9.0

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
+ ## [1.9.0](https://www.github.com/keq-request/keq/compare/v1.8.9...v1.9.0) (2022-10-19)
6
+
7
+
8
+ ### Features
9
+
10
+ * add mount.method ([df215a9](https://www.github.com/keq-request/keq/commit/df215a914d40fc03b3b4cbf359fb1da014b16f4a)), closes [#35](https://www.github.com/keq-request/keq/issues/35)
11
+
12
+ ### [1.8.9](https://www.github.com/keq-request/keq/compare/v1.8.8...v1.8.9) (2022-09-08)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * unexpected querystring when invoke .query() with an object param that some value is undfined ([372e2e8](https://www.github.com/keq-request/keq/commit/372e2e867768a3512b5b562951ed5de4129a4d45))
18
+
5
19
  ### [1.8.8](https://www.github.com/keq-request/keq/compare/v1.8.7...v1.8.8) (2022-06-24)
6
20
 
7
21
 
package/es/src/keq.d.ts CHANGED
@@ -44,8 +44,8 @@ export declare class Keq<T> {
44
44
  use(middleware: Middleware): Keq<T>;
45
45
  use(host: string, middleware: Middleware): Keq<T>;
46
46
  use(matcher: MiddlewareMatcher, middleware: Middleware): Keq<T>;
47
- query(key: Record<string, string | number | string[] | number[]>): Keq<T>;
48
- query(key: string, value: string | number | string[] | number[]): Keq<T>;
47
+ query(key: Record<string, string | number | string[] | number[] | undefined>): Keq<T>;
48
+ query(key: string, value: string | number | string[] | number[] | undefined): Keq<T>;
49
49
  params(key: Record<string, string | number>): Keq<T>;
50
50
  params(key: string, value: string | number): Keq<T>;
51
51
  option(key: 'resolveWithOriginalResponse', value?: true): Keq<Response>;
package/es/src/keq.js CHANGED
@@ -167,6 +167,8 @@ export class Keq {
167
167
  }
168
168
  else if (typeof key === 'object') {
169
169
  for (const [k, v] of Object.entries(key)) {
170
+ if (v === undefined)
171
+ continue;
170
172
  this.urlObj.query[k] = Array.isArray(v) ? v.map(item => String(item)) : String(v);
171
173
  }
172
174
  }
package/es/src/mount.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Mounter } from "./types";
1
+ import { Mounter, RequestMethod } from "./types";
2
2
  /**
3
3
  * NOTE: Not work in NodeJS
4
4
  * Unable to get the host and port of the service
@@ -8,5 +8,6 @@ export declare function location(): Mounter;
8
8
  * @param matcher glob or regexp
9
9
  */
10
10
  export declare function pathname(matcher: string | RegExp): Mounter;
11
+ export declare function method(expectMethod: RequestMethod): Mounter;
11
12
  export declare function host(host: string): Mounter;
12
13
  export declare function module(moduleName: string): Mounter;
package/es/src/mount.js CHANGED
@@ -7,6 +7,7 @@ function createMounter(matcher) {
7
7
  mounter.location = () => compose(mounter, location());
8
8
  mounter.host = arg => compose(mounter, host(arg));
9
9
  mounter.module = arg => compose(mounter, module(arg));
10
+ mounter.method = arg => compose(mounter, method(arg));
10
11
  return mounter;
11
12
  }
12
13
  /**
@@ -35,6 +36,9 @@ export function pathname(matcher) {
35
36
  return matcher.test(pathname);
36
37
  });
37
38
  }
39
+ export function method(expectMethod) {
40
+ return createMounter(ctx => ctx.request.method === expectMethod);
41
+ }
38
42
  export function host(host) {
39
43
  return createMounter(ctx => ctx.url.host === host);
40
44
  }
@@ -1,5 +1,7 @@
1
1
  import { MiddlewareMatcher } from './middleware';
2
+ import { RequestMethod } from './request-method';
2
3
  export interface Mounter extends MiddlewareMatcher {
4
+ method(method: RequestMethod): Mounter;
3
5
  pathname(matcher: string | RegExp): Mounter;
4
6
  location(): Mounter;
5
7
  host(host: string): Mounter;
package/lib/src/keq.d.ts CHANGED
@@ -44,8 +44,8 @@ export declare class Keq<T> {
44
44
  use(middleware: Middleware): Keq<T>;
45
45
  use(host: string, middleware: Middleware): Keq<T>;
46
46
  use(matcher: MiddlewareMatcher, middleware: Middleware): Keq<T>;
47
- query(key: Record<string, string | number | string[] | number[]>): Keq<T>;
48
- query(key: string, value: string | number | string[] | number[]): Keq<T>;
47
+ query(key: Record<string, string | number | string[] | number[] | undefined>): Keq<T>;
48
+ query(key: string, value: string | number | string[] | number[] | undefined): Keq<T>;
49
49
  params(key: Record<string, string | number>): Keq<T>;
50
50
  params(key: string, value: string | number): Keq<T>;
51
51
  option(key: 'resolveWithOriginalResponse', value?: true): Keq<Response>;
package/lib/src/keq.js CHANGED
@@ -179,6 +179,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
179
179
  }
180
180
  else if (typeof key === 'object') {
181
181
  for (const [k, v] of Object.entries(key)) {
182
+ if (v === undefined)
183
+ continue;
182
184
  this.urlObj.query[k] = Array.isArray(v) ? v.map(item => String(item)) : String(v);
183
185
  }
184
186
  }
@@ -1,4 +1,4 @@
1
- import { Mounter } from "./types";
1
+ import { Mounter, RequestMethod } from "./types";
2
2
  /**
3
3
  * NOTE: Not work in NodeJS
4
4
  * Unable to get the host and port of the service
@@ -8,5 +8,6 @@ export declare function location(): Mounter;
8
8
  * @param matcher glob or regexp
9
9
  */
10
10
  export declare function pathname(matcher: string | RegExp): Mounter;
11
+ export declare function method(expectMethod: RequestMethod): Mounter;
11
12
  export declare function host(host: string): Mounter;
12
13
  export declare function module(moduleName: string): Mounter;
package/lib/src/mount.js CHANGED
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  })(function (require, exports) {
13
13
  "use strict";
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.module = exports.host = exports.pathname = exports.location = void 0;
15
+ exports.module = exports.host = exports.method = exports.pathname = exports.location = void 0;
16
16
  const exception_1 = require("./exception");
17
17
  const minimatch_1 = __importDefault(require("minimatch"));
18
18
  const util_1 = require("./util");
@@ -22,6 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  mounter.location = () => compose(mounter, location());
23
23
  mounter.host = arg => compose(mounter, host(arg));
24
24
  mounter.module = arg => compose(mounter, module(arg));
25
+ mounter.method = arg => compose(mounter, method(arg));
25
26
  return mounter;
26
27
  }
27
28
  /**
@@ -52,6 +53,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
52
53
  });
53
54
  }
54
55
  exports.pathname = pathname;
56
+ function method(expectMethod) {
57
+ return createMounter(ctx => ctx.request.method === expectMethod);
58
+ }
59
+ exports.method = method;
55
60
  function host(host) {
56
61
  return createMounter(ctx => ctx.url.host === host);
57
62
  }
@@ -1,5 +1,7 @@
1
1
  import { MiddlewareMatcher } from './middleware';
2
+ import { RequestMethod } from './request-method';
2
3
  export interface Mounter extends MiddlewareMatcher {
4
+ method(method: RequestMethod): Mounter;
3
5
  pathname(matcher: string | RegExp): Mounter;
4
6
  location(): Mounter;
5
7
  host(host: string): Mounter;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "lib/src/index.js",
4
4
  "module": "es/src/index.js",
5
5
  "types": "lib/src/index.d.ts",
6
- "version": "1.8.8",
6
+ "version": "1.9.0",
7
7
  "license": "MIT",
8
8
  "scripts": {
9
9
  "test": "npm run clean && npm run build:test && nyc ava",
@@ -50,6 +50,7 @@
50
50
  "lint-staged": "^11.2.6",
51
51
  "mili": "^4",
52
52
  "nyc": "^15.1.0",
53
+ "ramda": "^0.28.0",
53
54
  "sinon": "^13.0.2",
54
55
  "standard-version": "^9.3.0",
55
56
  "ts-node": "^10.7.0",