@feathersjs/rest-client 5.0.0-pre.20 → 5.0.0-pre.23

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
@@ -3,6 +3,38 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [5.0.0-pre.23](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.22...v5.0.0-pre.23) (2022-06-06)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **express:** Ensure Express options can be set before configuring REST transport ([#2655](https://github.com/feathersjs/feathers/issues/2655)) ([c9b8f74](https://github.com/feathersjs/feathers/commit/c9b8f74a0196acb99be44ac5e0fff3f1128288cd))
12
+
13
+
14
+ ### Features
15
+
16
+ * **client:** Improve client side custom method support ([#2654](https://github.com/feathersjs/feathers/issues/2654)) ([c138acf](https://github.com/feathersjs/feathers/commit/c138acf50affbe6b66177d084d3c7a3e9220f09f))
17
+
18
+
19
+
20
+
21
+
22
+ # [5.0.0-pre.22](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.21...v5.0.0-pre.22) (2022-05-24)
23
+
24
+ **Note:** Version bump only for package @feathersjs/rest-client
25
+
26
+
27
+
28
+
29
+
30
+ # [5.0.0-pre.21](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.20...v5.0.0-pre.21) (2022-05-23)
31
+
32
+ **Note:** Version bump only for package @feathersjs/rest-client
33
+
34
+
35
+
36
+
37
+
6
38
  # [5.0.0-pre.20](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.19...v5.0.0-pre.20) (2022-05-04)
7
39
 
8
40
 
package/lib/axios.d.ts CHANGED
@@ -1,4 +1,5 @@
1
+ import { Params } from '@feathersjs/feathers';
1
2
  import { Base, RestClientParams } from './base';
2
- export declare class AxiosClient extends Base {
3
+ export declare class AxiosClient<T = any, D = Partial<T>, P extends Params = RestClientParams> extends Base<T, D, P> {
3
4
  request(options: any, params: RestClientParams): any;
4
5
  }
package/lib/axios.js CHANGED
@@ -12,11 +12,12 @@ class AxiosClient extends base_1.Base {
12
12
  Accept: 'application/json'
13
13
  }, this.options.headers, options.headers)
14
14
  }, params.connection);
15
- return this.connection.request(config)
15
+ return this.connection
16
+ .request(config)
16
17
  .then((res) => res.data)
17
18
  .catch((error) => {
18
19
  const response = error.response || error;
19
- throw response instanceof Error ? response : (response.data || response);
20
+ throw response instanceof Error ? response : response.data || response;
20
21
  });
21
22
  }
22
23
  }
package/lib/axios.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"axios.js","sourceRoot":"","sources":["../src/axios.ts"],"names":[],"mappings":";;;AAAA,iCAAgD;AAEhD,MAAa,WAAY,SAAQ,WAAI;IACnC,OAAO,CAAE,OAAY,EAAE,MAAwB;QAC7C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;YAC3B,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;gBACrB,MAAM,EAAE,kBAAkB;aAC3B,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;SAC1C,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QAEtB,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC;aACnC,IAAI,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC;aAC5B,KAAK,CAAC,CAAC,KAAU,EAAE,EAAE;YACpB,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC;YAEzC,MAAM,QAAQ,YAAY,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,CAAC;QAC3E,CAAC,CAAC,CAAC;IACP,CAAC;CACF;AAnBD,kCAmBC"}
1
+ {"version":3,"file":"axios.js","sourceRoot":"","sources":["../src/axios.ts"],"names":[],"mappings":";;;AACA,iCAA+C;AAE/C,MAAa,WAA0E,SAAQ,WAAa;IAC1G,OAAO,CAAC,OAAY,EAAE,MAAwB;QAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAC1B;YACE,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,OAAO,EAAE,MAAM,CAAC,MAAM,CACpB;gBACE,MAAM,EAAE,kBAAkB;aAC3B,EACD,IAAI,CAAC,OAAO,CAAC,OAAO,EACpB,OAAO,CAAC,OAAO,CAChB;SACF,EACD,MAAM,CAAC,UAAU,CAClB,CAAA;QAED,OAAO,IAAI,CAAC,UAAU;aACnB,OAAO,CAAC,MAAM,CAAC;aACf,IAAI,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC;aAC5B,KAAK,CAAC,CAAC,KAAU,EAAE,EAAE;YACpB,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAA;YAExC,MAAM,QAAQ,YAAY,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAA;QACxE,CAAC,CAAC,CAAA;IACN,CAAC;CACF;AA3BD,kCA2BC"}
package/lib/base.d.ts CHANGED
@@ -8,7 +8,7 @@ interface RestClientSettings {
8
8
  connection: any;
9
9
  options: any;
10
10
  }
11
- export declare abstract class Base<T = any, D = Partial<T>> implements ServiceInterface<T, D> {
11
+ export declare abstract class Base<T = any, D = Partial<T>, P extends Params = RestClientParams> implements ServiceInterface<T, D, P> {
12
12
  name: string;
13
13
  base: string;
14
14
  connection: any;
@@ -16,13 +16,13 @@ export declare abstract class Base<T = any, D = Partial<T>> implements ServiceIn
16
16
  constructor(settings: RestClientSettings);
17
17
  makeUrl(query: Query, id?: string | number | null): string;
18
18
  getQuery(query: Query): string;
19
- abstract request(options: any, params: Params): any;
19
+ abstract request(options: any, params: P): any;
20
20
  methods(this: any, ...names: string[]): any;
21
- find(params?: RestClientParams): any;
22
- get(id: Id, params?: RestClientParams): any;
23
- create(body: D, params?: RestClientParams): any;
24
- update(id: NullableId, body: D, params?: RestClientParams): any;
25
- patch(id: NullableId, body: D, params?: RestClientParams): any;
26
- remove(id: NullableId, params?: RestClientParams): any;
21
+ find(params?: P): any;
22
+ get(id: Id, params?: P): any;
23
+ create(body: D, params?: P): any;
24
+ update(id: NullableId, body: D, params?: P): any;
25
+ patch(id: NullableId, body: D, params?: P): any;
26
+ remove(id: NullableId, params?: P): any;
27
27
  }
28
28
  export {};
package/lib/base.js CHANGED
@@ -36,7 +36,7 @@ class Base {
36
36
  return '';
37
37
  }
38
38
  methods(...names) {
39
- names.forEach(method => {
39
+ names.forEach((method) => {
40
40
  this[method] = function (body, params = {}) {
41
41
  return this.request({
42
42
  body,
@@ -51,16 +51,16 @@ class Base {
51
51
  });
52
52
  return this;
53
53
  }
54
- find(params = {}) {
54
+ find(params) {
55
55
  return this.request({
56
56
  url: this.makeUrl(params.query),
57
57
  method: 'GET',
58
58
  headers: Object.assign({}, params.headers)
59
59
  }, params).catch(toError);
60
60
  }
61
- get(id, params = {}) {
61
+ get(id, params) {
62
62
  if (typeof id === 'undefined') {
63
- return Promise.reject(new Error('id for \'get\' can not be undefined'));
63
+ return Promise.reject(new Error("id for 'get' can not be undefined"));
64
64
  }
65
65
  return this.request({
66
66
  url: this.makeUrl(params.query, id),
@@ -68,7 +68,7 @@ class Base {
68
68
  headers: Object.assign({}, params.headers)
69
69
  }, params).catch(toError);
70
70
  }
71
- create(body, params = {}) {
71
+ create(body, params) {
72
72
  return this.request({
73
73
  url: this.makeUrl(params.query),
74
74
  body,
@@ -76,9 +76,9 @@ class Base {
76
76
  headers: Object.assign({ 'Content-Type': 'application/json' }, params.headers)
77
77
  }, params).catch(toError);
78
78
  }
79
- update(id, body, params = {}) {
79
+ update(id, body, params) {
80
80
  if (typeof id === 'undefined') {
81
- return Promise.reject(new Error('id for \'update\' can not be undefined, only \'null\' when updating multiple entries'));
81
+ return Promise.reject(new Error("id for 'update' can not be undefined, only 'null' when updating multiple entries"));
82
82
  }
83
83
  return this.request({
84
84
  url: this.makeUrl(params.query, id),
@@ -87,9 +87,9 @@ class Base {
87
87
  headers: Object.assign({ 'Content-Type': 'application/json' }, params.headers)
88
88
  }, params).catch(toError);
89
89
  }
90
- patch(id, body, params = {}) {
90
+ patch(id, body, params) {
91
91
  if (typeof id === 'undefined') {
92
- return Promise.reject(new Error('id for \'patch\' can not be undefined, only \'null\' when updating multiple entries'));
92
+ return Promise.reject(new Error("id for 'patch' can not be undefined, only 'null' when updating multiple entries"));
93
93
  }
94
94
  return this.request({
95
95
  url: this.makeUrl(params.query, id),
@@ -98,9 +98,9 @@ class Base {
98
98
  headers: Object.assign({ 'Content-Type': 'application/json' }, params.headers)
99
99
  }, params).catch(toError);
100
100
  }
101
- remove(id, params = {}) {
101
+ remove(id, params) {
102
102
  if (typeof id === 'undefined') {
103
- return Promise.reject(new Error('id for \'remove\' can not be undefined, only \'null\' when removing multiple entries'));
103
+ return Promise.reject(new Error("id for 'remove' can not be undefined, only 'null' when removing multiple entries"));
104
104
  }
105
105
  return this.request({
106
106
  url: this.makeUrl(params.query, id),
package/lib/base.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAqB;AAErB,+CAA2D;AAC3D,iDAAsD;AAEtD,SAAS,OAAO,CAAE,KAA+B;IAC/C,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE;QACjC,MAAM,IAAI,oBAAW,CAAC,KAAK,CAAC,OAAO,EAAE,WAAC,CAAC,IAAI,CA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AC3C,EACD,MAAM,CACP,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAClB,CAAC;CACF;AAzJD,oBAyJC"}
package/lib/fetch.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import { Params } from '@feathersjs/feathers';
1
2
  import { Base, RestClientParams } from './base';
2
- export declare class FetchClient extends Base {
3
+ export declare class FetchClient<T = any, D = Partial<T>, P extends Params = RestClientParams> extends Base<T, D, P> {
3
4
  request(options: any, params: RestClientParams): any;
4
5
  checkStatus(response: any): any;
5
6
  }
package/lib/fetch.js CHANGED
@@ -25,10 +25,13 @@ class FetchClient extends base_1.Base {
25
25
  if (response.ok) {
26
26
  return response;
27
27
  }
28
- return response.json().catch(() => {
28
+ return response
29
+ .json()
30
+ .catch(() => {
29
31
  const ErrorClass = errors_1.errors[response.status] || Error;
30
32
  return new ErrorClass('JSON parsing error');
31
- }).then((error) => {
33
+ })
34
+ .then((error) => {
32
35
  error.response = response;
33
36
  throw error;
34
37
  });
package/lib/fetch.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAC5C,iCAAgD;AAEhD,MAAa,WAAY,SAAQ,WAAI;IACnC,OAAO,CAAE,OAAY,EAAE,MAAwB;QAC7C,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QAEnE,YAAY,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;YACnC,MAAM,EAAE,kBAAkB;SAC3B,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;QAE/C,IAAI,OAAO,CAAC,IAAI,EAAE;YAChB,YAAY,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SAClD;QAED,OAAO,IAAI,CAAC,UA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ChB,YAAY,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;SACjD;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC;aAC9C,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;aACtB,IAAI,CAAC,CAAC,QAAa,EAAE,EAAE;YACtB,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;gBAC3B,OAAO,IAAI,CAAA;aACZ;YAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;QACxB,CAAC,CAAC,CAAA;IACN,CAAC;IAED,WAAW,CAAC,QAAa;QACvB,IAAI,QAAQ,CAAC,EAAE,EAAE;YACf,OAAO,QAAQ,CAAA;SAChB;QAED,OAAO,QAAQ;aACZ,IAAI,EAAE;aACN,KAAK,CAAC,GAAG,EAAE;YACV,MAAM,UAAU,GAAI,eAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,KAAK,CAAA;YAE5D,OAAO,IAAI,UAAU,CAAC,oBAAoB,CAAC,CAAA;QAC7C,CAAC,CAAC;aACD,IAAI,CAAC,CAAC,KAAU,EAAE,EAAE;YACnB,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAA;YACzB,MAAM,KAAK,CAAA;QACb,CAAC,CAAC,CAAA;IACN,CAAC;CACF;AA5CD,kCA4CC"}
package/lib/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SuperagentClient = exports.FetchClient = exports.AxiosClient = void 0;
4
+ const feathers_1 = require("@feathersjs/feathers");
4
5
  const base_1 = require("./base");
5
6
  const axios_1 = require("./axios");
6
7
  Object.defineProperty(exports, "AxiosClient", { enumerable: true, get: function () { return axios_1.AxiosClient; } });
@@ -15,7 +16,7 @@ const transports = {
15
16
  };
16
17
  function restClient(base = '') {
17
18
  const result = { Base: base_1.Base };
18
- Object.keys(transports).forEach(key => {
19
+ Object.keys(transports).forEach((key) => {
19
20
  result[key] = function (connection, options = {}, Service = transports[key]) {
20
21
  if (!connection) {
21
22
  throw new Error(`${key} has to be provided to feathers-rest`);
@@ -33,6 +34,12 @@ function restClient(base = '') {
33
34
  }
34
35
  app.rest = connection;
35
36
  app.defaultService = defaultService;
37
+ app.mixins.unshift((service, _location, options) => {
38
+ if (options && options.methods && service instanceof base_1.Base) {
39
+ const customMethods = options.methods.filter((name) => !feathers_1.defaultServiceMethods.includes(name));
40
+ service.methods(...customMethods);
41
+ }
42
+ });
36
43
  };
37
44
  initialize.Service = Service;
38
45
  initialize.service = defaultService;
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAC9B,mCAAsC;AAI7B,4FAJA,mBAAW,OAIA;AAHpB,mCAAsC;AAGhB,4FAHb,mBAAW,OAGa;AAFjC,6CAAgD;AAEb,iGAF1B,6BAAgB,OAE0B;AAEnD,MAAM,UAAU,GAAG;IACjB,UAAU,EAAE,6BAAgB;IAC5B,KAAK,EAAE,mBAAW;IAClB,KAAK,EAAE,mBAAW;CACnB,CAAC;AA6BF,SAAwB,UAAU,CAAE,IAAI,GAAG,EAAE;IAC3C,MAAM,MAAM,GAAQ,EAAE,IAAI,EAAJ,WAAI,EAAE,CAAC;IAE7B,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACpC,MAAM,CAAC,GAAG,CAAC,GAAG,UAAU,UAAe,EAAE,UAAe,EAAE,EAAE,UAAiB,UAAkB,CAAC,GAAG,CAAC;YAClG,IAAI,CAAC,UAAU,EAAE;gBACf,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,sCAAsC,CAAC,CAAC;aAC/D;YAED,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;gBACjC,OAAO,GAAG,OAAO,CAAC;gB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;YAED,UAAU,CAAC,OAAO,GAAG,OAAO,CAAA;YAC5B,UAAU,CAAC,OAAO,GAAG,cAAc,CAAA;YAEnC,OAAO,UAAU,CAAA;QACnB,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,MAAmB,CAAA;AAC5B,CAAC;AA1CD,6BA0CC;AAED,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;CAC3D"}
@@ -1,4 +1,5 @@
1
+ import { Params } from '@feathersjs/feathers';
1
2
  import { Base, RestClientParams } from './base';
2
- export declare class SuperagentClient extends Base {
3
+ export declare class SuperagentClient<T = any, D = Partial<T>, P extends Params = RestClientParams> extends Base<T, D, P> {
3
4
  request(options: any, params: RestClientParams): Promise<unknown>;
4
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"superagent.js","sourceRoot":"","sources":["../src/superagent.ts"],"names":[],"mappings":";;;AAAA,iCAAgD;AAEhD,MAAa,gBAAiB,SAAQ,WAAI;IACxC,OAAO,CAAE,OAAY,EAAE,MAAwB;QAC7C,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC;aAC5D,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;aAC/B,GAAG,CAAC,QAAQ,EAAE,kBAAkB,CAAC;aACjC,GAAG,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC;aAC5B,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;aAC1B,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC;QAEhC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC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AAU,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;YAE/B,IAAI,OAAO,CAAC,IAAI,EAAE;gBAChB,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;aAC9B;YAED,UAAU,CAAC,GAAG,CAAC,UAAU,KAAU,EAAE,GAAQ;gBAC3C,IAAI,KAAK,EAAE;oBACT,IAAI;wBACF,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAA;wBAC/B,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;wBACvC,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAA;qBAC1B;oBAAC,OAAO,CAAM,EAAE,GAAE;oBAEnB,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;iBACrB;gBAED,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAA;YAC1B,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAnCD,4CAmCC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@feathersjs/rest-client",
3
3
  "description": "REST client services for different Ajax libraries",
4
- "version": "5.0.0-pre.20",
4
+ "version": "5.0.0-pre.23",
5
5
  "homepage": "https://feathersjs.com",
6
6
  "main": "lib/",
7
7
  "types": "lib/",
@@ -52,28 +52,28 @@
52
52
  "access": "public"
53
53
  },
54
54
  "dependencies": {
55
- "@feathersjs/commons": "^5.0.0-pre.20",
56
- "@feathersjs/errors": "^5.0.0-pre.20",
57
- "@types/node-fetch": "^3.0.2",
55
+ "@feathersjs/commons": "^5.0.0-pre.23",
56
+ "@feathersjs/errors": "^5.0.0-pre.23",
57
+ "@feathersjs/feathers": "^5.0.0-pre.23",
58
58
  "@types/superagent": "^4.1.15",
59
59
  "qs": "^6.10.3"
60
60
  },
61
61
  "devDependencies": {
62
- "@feathersjs/express": "^5.0.0-pre.20",
63
- "@feathersjs/feathers": "^5.0.0-pre.20",
64
- "@feathersjs/memory": "^5.0.0-pre.20",
65
- "@feathersjs/tests": "^5.0.0-pre.20",
62
+ "@feathersjs/express": "^5.0.0-pre.23",
63
+ "@feathersjs/memory": "^5.0.0-pre.23",
64
+ "@feathersjs/tests": "^5.0.0-pre.23",
66
65
  "@types/mocha": "^9.1.1",
67
- "@types/node": "^17.0.31",
66
+ "@types/node": "^17.0.40",
67
+ "@types/node-fetch": "^2.6.1",
68
68
  "@types/qs": "^6.9.7",
69
69
  "axios": "^0.27.2",
70
70
  "mocha": "^10.0.0",
71
71
  "node-fetch": "^2.6.1",
72
72
  "rxjs": "^7.5.5",
73
73
  "shx": "^0.3.4",
74
- "superagent": "^7.1.3",
75
- "ts-node": "^10.7.0",
76
- "typescript": "^4.6.4"
74
+ "superagent": "^7.1.6",
75
+ "ts-node": "^10.8.1",
76
+ "typescript": "^4.7.3"
77
77
  },
78
- "gitHead": "54de749a0b392c7da726c668002b50cafaca530c"
78
+ "gitHead": "a60910bd730b88053ca6648337095f1ca1e3b39f"
79
79
  }
package/src/axios.ts CHANGED
@@ -1,22 +1,31 @@
1
- import { Base, RestClientParams } from './base';
1
+ import { Params } from '@feathersjs/feathers'
2
+ import { Base, RestClientParams } from './base'
2
3
 
3
- export class AxiosClient extends Base {
4
- request (options: any, params: RestClientParams) {
5
- const config = Object.assign({
6
- url: options.url,
7
- method: options.method,
8
- data: options.body,
9
- headers: Object.assign({
10
- Accept: 'application/json'
11
- }, this.options.headers, options.headers)
12
- }, params.connection);
4
+ export class AxiosClient<T = any, D = Partial<T>, P extends Params = RestClientParams> extends Base<T, D, P> {
5
+ request(options: any, params: RestClientParams) {
6
+ const config = Object.assign(
7
+ {
8
+ url: options.url,
9
+ method: options.method,
10
+ data: options.body,
11
+ headers: Object.assign(
12
+ {
13
+ Accept: 'application/json'
14
+ },
15
+ this.options.headers,
16
+ options.headers
17
+ )
18
+ },
19
+ params.connection
20
+ )
13
21
 
14
- return this.connection.request(config)
22
+ return this.connection
23
+ .request(config)
15
24
  .then((res: any) => res.data)
16
25
  .catch((error: any) => {
17
- const response = error.response || error;
26
+ const response = error.response || error
18
27
 
19
- throw response instanceof Error ? response : (response.data || response);
20
- });
28
+ throw response instanceof Error ? response : response.data || response
29
+ })
21
30
  }
22
31
  }
package/src/base.ts CHANGED
@@ -1,146 +1,178 @@
1
- import qs from 'qs';
2
- import { Params, Id, Query, NullableId, ServiceInterface } from '@feathersjs/feathers';
3
- import { Unavailable, convert } from '@feathersjs/errors';
4
- import { _, stripSlashes } from '@feathersjs/commons';
1
+ import qs from 'qs'
2
+ import { Params, Id, Query, NullableId, ServiceInterface } from '@feathersjs/feathers'
3
+ import { Unavailable, convert } from '@feathersjs/errors'
4
+ import { _, stripSlashes } from '@feathersjs/commons'
5
5
 
6
- function toError (error: Error & { code: string }) {
6
+ function toError(error: Error & { code: string }) {
7
7
  if (error.code === 'ECONNREFUSED') {
8
- throw new Unavailable(error.message, _.pick(error, 'address', 'port', 'config'));
8
+ throw new Unavailable(error.message, _.pick(error, 'address', 'port', 'config'))
9
9
  }
10
10
 
11
- throw convert(error);
11
+ throw convert(error)
12
12
  }
13
13
 
14
14
  export interface RestClientParams extends Params {
15
- connection?: any;
15
+ connection?: any
16
16
  }
17
17
 
18
18
  interface RestClientSettings {
19
- name: string;
20
- base: string;
21
- connection: any;
22
- options: any;
19
+ name: string
20
+ base: string
21
+ connection: any
22
+ options: any
23
23
  }
24
24
 
25
- export abstract class Base<T = any, D = Partial<T>> implements ServiceInterface<T, D> {
26
- name: string;
27
- base: string;
28
- connection: any;
29
- options: any;
30
-
31
- constructor (settings: RestClientSettings) {
32
- this.name = stripSlashes(settings.name);
33
- this.options = settings.options;
34
- this.connection = settings.connection;
35
- this.base = `${settings.base}/${this.name}`;
25
+ export abstract class Base<T = any, D = Partial<T>, P extends Params = RestClientParams>
26
+ implements ServiceInterface<T, D, P>
27
+ {
28
+ name: string
29
+ base: string
30
+ connection: any
31
+ options: any
32
+
33
+ constructor(settings: RestClientSettings) {
34
+ this.name = stripSlashes(settings.name)
35
+ this.options = settings.options
36
+ this.connection = settings.connection
37
+ this.base = `${settings.base}/${this.name}`
36
38
  }
37
39
 
38
- makeUrl (query: Query, id?: string|number|null) {
39
- let url = this.base;
40
+ makeUrl(query: Query, id?: string | number | null) {
41
+ let url = this.base
40
42
 
41
- query = query || {};
43
+ query = query || {}
42
44
 
43
45
  if (typeof id !== 'undefined' && id !== null) {
44
- url += `/${encodeURIComponent(id)}`;
46
+ url += `/${encodeURIComponent(id)}`
45
47
  }
46
48
 
47
- return url + this.getQuery(query);
49
+ return url + this.getQuery(query)
48
50
  }
49
51
 
50
- getQuery (query: Query) {
52
+ getQuery(query: Query) {
51
53
  if (Object.keys(query).length !== 0) {
52
- const queryString = qs.stringify(query);
54
+ const queryString = qs.stringify(query)
53
55
 
54
- return `?${queryString}`;
56
+ return `?${queryString}`
55
57
  }
56
58
 
57
- return '';
59
+ return ''
58
60
  }
59
61
 
60
- abstract request (options: any, params: Params): any;
62
+ abstract request(options: any, params: P): any
61
63
 
62
- methods (this: any, ...names: string[]) {
63
- names.forEach(method => {
64
+ methods(this: any, ...names: string[]) {
65
+ names.forEach((method) => {
64
66
  this[method] = function (body: any, params: Params = {}) {
65
- return this.request({
66
- body,
67
- url: this.makeUrl(params.query),
68
- method: 'POST',
69
- headers: Object.assign({
70
- 'Content-Type': 'application/json',
71
- 'X-Service-Method': method
72
- }, params.headers)
73
- }, params).catch(toError);
67
+ return this.request(
68
+ {
69
+ body,
70
+ url: this.makeUrl(params.query),
71
+ method: 'POST',
72
+ headers: Object.assign(
73
+ {
74
+ 'Content-Type': 'application/json',
75
+ 'X-Service-Method': method
76
+ },
77
+ params.headers
78
+ )
79
+ },
80
+ params
81
+ ).catch(toError)
74
82
  }
75
- });
83
+ })
76
84
 
77
- return this;
85
+ return this
78
86
  }
79
87
 
80
- find (params: RestClientParams = {}) {
81
- return this.request({
82
- url: this.makeUrl(params.query),
83
- method: 'GET',
84
- headers: Object.assign({}, params.headers)
85
- }, params).catch(toError);
88
+ find(params?: P) {
89
+ return this.request(
90
+ {
91
+ url: this.makeUrl(params.query),
92
+ method: 'GET',
93
+ headers: Object.assign({}, params.headers)
94
+ },
95
+ params
96
+ ).catch(toError)
86
97
  }
87
98
 
88
- get (id: Id, params: RestClientParams = {}) {
99
+ get(id: Id, params?: P) {
89
100
  if (typeof id === 'undefined') {
90
- return Promise.reject(new Error('id for \'get\' can not be undefined'));
101
+ return Promise.reject(new Error("id for 'get' can not be undefined"))
91
102
  }
92
103
 
93
- return this.request({
94
- url: this.makeUrl(params.query, id),
95
- method: 'GET',
96
- headers: Object.assign({}, params.headers)
97
- }, params).catch(toError);
104
+ return this.request(
105
+ {
106
+ url: this.makeUrl(params.query, id),
107
+ method: 'GET',
108
+ headers: Object.assign({}, params.headers)
109
+ },
110
+ params
111
+ ).catch(toError)
98
112
  }
99
113
 
100
- create (body: D, params: RestClientParams = {}) {
101
- return this.request({
102
- url: this.makeUrl(params.query),
103
- body,
104
- method: 'POST',
105
- headers: Object.assign({ 'Content-Type': 'application/json' }, params.headers)
106
- }, params).catch(toError);
114
+ create(body: D, params?: P) {
115
+ return this.request(
116
+ {
117
+ url: this.makeUrl(params.query),
118
+ body,
119
+ method: 'POST',
120
+ headers: Object.assign({ 'Content-Type': 'application/json' }, params.headers)
121
+ },
122
+ params
123
+ ).catch(toError)
107
124
  }
108
125
 
109
- update (id: NullableId, body: D, params: RestClientParams = {}) {
126
+ update(id: NullableId, body: D, params?: P) {
110
127
  if (typeof id === 'undefined') {
111
- return Promise.reject(new Error('id for \'update\' can not be undefined, only \'null\' when updating multiple entries'));
128
+ return Promise.reject(
129
+ new Error("id for 'update' can not be undefined, only 'null' when updating multiple entries")
130
+ )
112
131
  }
113
132
 
114
- return this.request({
115
- url: this.makeUrl(params.query, id),
116
- body,
117
- method: 'PUT',
118
- headers: Object.assign({ 'Content-Type': 'application/json' }, params.headers)
119
- }, params).catch(toError);
133
+ return this.request(
134
+ {
135
+ url: this.makeUrl(params.query, id),
136
+ body,
137
+ method: 'PUT',
138
+ headers: Object.assign({ 'Content-Type': 'application/json' }, params.headers)
139
+ },
140
+ params
141
+ ).catch(toError)
120
142
  }
121
143
 
122
- patch (id: NullableId, body: D, params: RestClientParams = {}) {
144
+ patch(id: NullableId, body: D, params?: P) {
123
145
  if (typeof id === 'undefined') {
124
- return Promise.reject(new Error('id for \'patch\' can not be undefined, only \'null\' when updating multiple entries'));
146
+ return Promise.reject(
147
+ new Error("id for 'patch' can not be undefined, only 'null' when updating multiple entries")
148
+ )
125
149
  }
126
150
 
127
- return this.request({
128
- url: this.makeUrl(params.query, id),
129
- body,
130
- method: 'PATCH',
131
- headers: Object.assign({ 'Content-Type': 'application/json' }, params.headers)
132
- }, params).catch(toError);
151
+ return this.request(
152
+ {
153
+ url: this.makeUrl(params.query, id),
154
+ body,
155
+ method: 'PATCH',
156
+ headers: Object.assign({ 'Content-Type': 'application/json' }, params.headers)
157
+ },
158
+ params
159
+ ).catch(toError)
133
160
  }
134
161
 
135
- remove (id: NullableId, params: RestClientParams = {}) {
162
+ remove(id: NullableId, params?: P) {
136
163
  if (typeof id === 'undefined') {
137
- return Promise.reject(new Error('id for \'remove\' can not be undefined, only \'null\' when removing multiple entries'));
164
+ return Promise.reject(
165
+ new Error("id for 'remove' can not be undefined, only 'null' when removing multiple entries")
166
+ )
138
167
  }
139
168
 
140
- return this.request({
141
- url: this.makeUrl(params.query, id),
142
- method: 'DELETE',
143
- headers: Object.assign({}, params.headers)
144
- }, params).catch(toError);
169
+ return this.request(
170
+ {
171
+ url: this.makeUrl(params.query, id),
172
+ method: 'DELETE',
173
+ headers: Object.assign({}, params.headers)
174
+ },
175
+ params
176
+ ).catch(toError)
145
177
  }
146
178
  }
package/src/fetch.ts CHANGED
@@ -1,41 +1,49 @@
1
- import { errors } from '@feathersjs/errors';
2
- import { Base, RestClientParams } from './base';
3
-
4
- export class FetchClient extends Base {
5
- request (options: any, params: RestClientParams) {
6
- const fetchOptions = Object.assign({}, options, params.connection);
7
-
8
- fetchOptions.headers = Object.assign({
9
- Accept: 'application/json'
10
- }, this.options.headers, fetchOptions.headers);
1
+ import { errors } from '@feathersjs/errors'
2
+ import { Params } from '@feathersjs/feathers'
3
+ import { Base, RestClientParams } from './base'
4
+
5
+ export class FetchClient<T = any, D = Partial<T>, P extends Params = RestClientParams> extends Base<T, D, P> {
6
+ request(options: any, params: RestClientParams) {
7
+ const fetchOptions = Object.assign({}, options, params.connection)
8
+
9
+ fetchOptions.headers = Object.assign(
10
+ {
11
+ Accept: 'application/json'
12
+ },
13
+ this.options.headers,
14
+ fetchOptions.headers
15
+ )
11
16
 
12
17
  if (options.body) {
13
- fetchOptions.body = JSON.stringify(options.body);
18
+ fetchOptions.body = JSON.stringify(options.body)
14
19
  }
15
20
 
16
21
  return this.connection(options.url, fetchOptions)
17
22
  .then(this.checkStatus)
18
23
  .then((response: any) => {
19
24
  if (response.status === 204) {
20
- return null;
25
+ return null
21
26
  }
22
27
 
23
- return response.json();
24
- });
28
+ return response.json()
29
+ })
25
30
  }
26
31
 
27
- checkStatus (response: any) {
32
+ checkStatus(response: any) {
28
33
  if (response.ok) {
29
- return response;
34
+ return response
30
35
  }
31
36
 
32
- return response.json().catch(() => {
33
- const ErrorClass = (errors as any)[response.status] || Error;
34
-
35
- return new ErrorClass('JSON parsing error');
36
- }).then((error: any) => {
37
- error.response = response;
38
- throw error;
39
- });
37
+ return response
38
+ .json()
39
+ .catch(() => {
40
+ const ErrorClass = (errors as any)[response.status] || Error
41
+
42
+ return new ErrorClass('JSON parsing error')
43
+ })
44
+ .then((error: any) => {
45
+ error.response = response
46
+ throw error
47
+ })
40
48
  }
41
49
  }
package/src/index.ts CHANGED
@@ -1,80 +1,89 @@
1
- import { Base } from './base';
2
- import { AxiosClient } from './axios';
3
- import { FetchClient } from './fetch';
4
- import { SuperagentClient } from './superagent';
1
+ import { Application, defaultServiceMethods } from '@feathersjs/feathers'
5
2
 
6
- export { AxiosClient, FetchClient, SuperagentClient };
3
+ import { Base } from './base'
4
+ import { AxiosClient } from './axios'
5
+ import { FetchClient } from './fetch'
6
+ import { SuperagentClient } from './superagent'
7
+
8
+ export { AxiosClient, FetchClient, SuperagentClient }
7
9
 
8
10
  const transports = {
9
11
  superagent: SuperagentClient,
10
12
  fetch: FetchClient,
11
13
  axios: AxiosClient
12
- };
14
+ }
13
15
 
14
16
  interface HandlerResult extends Function {
15
17
  /**
16
18
  * initialize service
17
19
  */
18
- (): void;
20
+ (): void
19
21
 
20
22
  /**
21
23
  * Transport Service
22
24
  */
23
- Service: any;
25
+ Service: any
24
26
 
25
27
  /**
26
28
  * default Service
27
29
  */
28
- service: any;
30
+ service: any
29
31
  }
30
32
 
31
- export type Handler = (connection: any, options?: any, Service?: any) => HandlerResult;
33
+ export type Handler = (connection: any, options?: any, Service?: any) => HandlerResult
32
34
 
33
35
  export interface Transport {
34
- superagent: Handler;
35
- fetch: Handler;
36
- axios: Handler;
36
+ superagent: Handler
37
+ fetch: Handler
38
+ axios: Handler
37
39
  }
38
40
 
39
- export type RestService<T = any, D = Partial<any>> = Base<T, D>;
41
+ export type RestService<T = any, D = Partial<any>> = Base<T, D>
40
42
 
41
- export default function restClient (base = '') {
42
- const result: any = { Base };
43
+ export default function restClient(base = '') {
44
+ const result: any = { Base }
43
45
 
44
- Object.keys(transports).forEach(key => {
46
+ Object.keys(transports).forEach((key) => {
45
47
  result[key] = function (connection: any, options: any = {}, Service: Base = (transports as any)[key]) {
46
48
  if (!connection) {
47
- throw new Error(`${key} has to be provided to feathers-rest`);
49
+ throw new Error(`${key} has to be provided to feathers-rest`)
48
50
  }
49
51
 
50
52
  if (typeof options === 'function') {
51
- Service = options;
52
- options = {};
53
+ Service = options
54
+ options = {}
53
55
  }
54
56
 
55
57
  const defaultService = function (name: string) {
56
- return new (Service as any)({ base, name, connection, options });
57
- };
58
+ return new (Service as any)({ base, name, connection, options })
59
+ }
58
60
 
59
- const initialize = (app: any) => {
61
+ const initialize = (app: Application & { rest: any }) => {
60
62
  if (app.rest !== undefined) {
61
- throw new Error('Only one default client provider can be configured');
63
+ throw new Error('Only one default client provider can be configured')
62
64
  }
63
65
 
64
- app.rest = connection;
65
- app.defaultService = defaultService;
66
- };
66
+ app.rest = connection
67
+ app.defaultService = defaultService
68
+ app.mixins.unshift((service, _location, options) => {
69
+ if (options && options.methods && service instanceof Base) {
70
+ const customMethods = options.methods.filter((name) => !defaultServiceMethods.includes(name))
71
+
72
+ service.methods(...customMethods)
73
+ }
74
+ })
75
+ }
67
76
 
68
- initialize.Service = Service;
69
- initialize.service = defaultService;
77
+ initialize.Service = Service
78
+ initialize.service = defaultService
70
79
 
71
- return initialize;
72
- };
73
- });
80
+ return initialize
81
+ }
82
+ })
74
83
 
75
- return result as Transport;
84
+ return result as Transport
76
85
  }
77
86
 
78
87
  if (typeof module !== 'undefined') {
79
- module.exports = Object.assign(restClient, module.exports);
88
+ module.exports = Object.assign(restClient, module.exports)
80
89
  }
package/src/superagent.ts CHANGED
@@ -1,34 +1,39 @@
1
- import { Base, RestClientParams } from './base';
1
+ import { Params } from '@feathersjs/feathers'
2
+ import { Base, RestClientParams } from './base'
2
3
 
3
- export class SuperagentClient extends Base {
4
- request (options: any, params: RestClientParams) {
4
+ export class SuperagentClient<T = any, D = Partial<T>, P extends Params = RestClientParams> extends Base<
5
+ T,
6
+ D,
7
+ P
8
+ > {
9
+ request(options: any, params: RestClientParams) {
5
10
  const superagent = this.connection(options.method, options.url)
6
11
  .set(this.options.headers || {})
7
12
  .set('Accept', 'application/json')
8
13
  .set(params.connection || {})
9
14
  .set(options.headers || {})
10
- .type(options.type || 'json');
15
+ .type(options.type || 'json')
11
16
 
12
17
  return new Promise((resolve, reject) => {
13
- superagent.set(options.headers);
18
+ superagent.set(options.headers)
14
19
 
15
20
  if (options.body) {
16
- superagent.send(options.body);
21
+ superagent.send(options.body)
17
22
  }
18
23
 
19
24
  superagent.end(function (error: any, res: any) {
20
25
  if (error) {
21
26
  try {
22
- const response = error.response;
23
- error = JSON.parse(error.response.text);
24
- error.response = response;
27
+ const response = error.response
28
+ error = JSON.parse(error.response.text)
29
+ error.response = response
25
30
  } catch (e: any) {}
26
31
 
27
- return reject(error);
32
+ return reject(error)
28
33
  }
29
34
 
30
- resolve(res && res.body);
31
- });
32
- });
35
+ resolve(res && res.body)
36
+ })
37
+ })
33
38
  }
34
39
  }