@feathersjs/rest-client 5.0.0-pre.6 → 5.0.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 +145 -180
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/lib/axios.d.ts +3 -3
- package/lib/axios.js +3 -2
- package/lib/axios.js.map +1 -1
- package/lib/base.d.ts +11 -8
- package/lib/base.js +13 -13
- package/lib/base.js.map +1 -1
- package/lib/fetch.d.ts +3 -3
- package/lib/fetch.js +5 -2
- package/lib/fetch.js.map +1 -1
- package/lib/index.d.ts +8 -21
- package/lib/index.js +8 -1
- package/lib/index.js.map +1 -1
- package/lib/superagent.d.ts +3 -3
- package/lib/superagent.js.map +1 -1
- package/package.json +27 -23
- package/src/axios.ts +24 -16
- package/src/base.ts +124 -88
- package/src/fetch.ts +32 -25
- package/src/index.ts +44 -48
- package/src/superagent.ts +19 -15
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @feathersjs/rest-client
|
|
2
2
|
|
|
3
3
|
[](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI)
|
|
4
|
-
[](https://david-dm.org/feathersjs/feathers?path=packages/rest-client)
|
|
5
4
|
[](https://www.npmjs.com/package/@feathersjs/rest-client)
|
|
5
|
+
[](https://discord.gg/qa8kez8QBx)
|
|
6
6
|
|
|
7
7
|
> REST client services for different Ajax libraries
|
|
8
8
|
|
|
@@ -18,6 +18,6 @@ Refer to the [Feathers REST client API documentation](https://docs.feathersjs.co
|
|
|
18
18
|
|
|
19
19
|
## License
|
|
20
20
|
|
|
21
|
-
Copyright (c)
|
|
21
|
+
Copyright (c) 2023 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
|
|
22
22
|
|
|
23
23
|
Licensed under the [MIT license](LICENSE).
|
package/lib/axios.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Params } from '@feathersjs/feathers';
|
|
2
|
-
import { Base } from './base';
|
|
3
|
-
export declare class AxiosClient extends Base {
|
|
4
|
-
request(options: any, params:
|
|
2
|
+
import { Base, RestClientParams } from './base';
|
|
3
|
+
export declare class AxiosClient<T = any, D = Partial<T>, P extends Params = RestClientParams> extends Base<T, D, P> {
|
|
4
|
+
request(options: any, params: RestClientParams): any;
|
|
5
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
|
|
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 :
|
|
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":";;;AACA,
|
|
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
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Params, Id, Query, NullableId, ServiceInterface } from '@feathersjs/feathers';
|
|
2
|
+
export interface RestClientParams extends Params {
|
|
3
|
+
connection?: any;
|
|
4
|
+
}
|
|
2
5
|
interface RestClientSettings {
|
|
3
6
|
name: string;
|
|
4
7
|
base: string;
|
|
5
8
|
connection: any;
|
|
6
9
|
options: any;
|
|
7
10
|
}
|
|
8
|
-
export declare abstract class Base<T = any, D = Partial<T
|
|
11
|
+
export declare abstract class Base<T = any, D = Partial<T>, P extends Params = RestClientParams> implements ServiceInterface<T, D, P> {
|
|
9
12
|
name: string;
|
|
10
13
|
base: string;
|
|
11
14
|
connection: any;
|
|
@@ -13,13 +16,13 @@ export declare abstract class Base<T = any, D = Partial<T>> implements ServiceIn
|
|
|
13
16
|
constructor(settings: RestClientSettings);
|
|
14
17
|
makeUrl(query: Query, id?: string | number | null): string;
|
|
15
18
|
getQuery(query: Query): string;
|
|
16
|
-
abstract request(options: any, params:
|
|
19
|
+
abstract request(options: any, params: P): any;
|
|
17
20
|
methods(this: any, ...names: string[]): any;
|
|
18
|
-
find(params?:
|
|
19
|
-
get(id: Id, params?:
|
|
20
|
-
create(body: D, params?:
|
|
21
|
-
update(id: NullableId, body: D, params?:
|
|
22
|
-
patch(id: NullableId, body: D, params?:
|
|
23
|
-
remove(id: NullableId, params?:
|
|
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;
|
|
24
27
|
}
|
|
25
28
|
export {};
|
package/lib/base.js
CHANGED
|
@@ -11,11 +11,11 @@ function toError(error) {
|
|
|
11
11
|
if (error.code === 'ECONNREFUSED') {
|
|
12
12
|
throw new errors_1.Unavailable(error.message, commons_1._.pick(error, 'address', 'port', 'config'));
|
|
13
13
|
}
|
|
14
|
-
throw errors_1.convert(error);
|
|
14
|
+
throw (0, errors_1.convert)(error);
|
|
15
15
|
}
|
|
16
16
|
class Base {
|
|
17
17
|
constructor(settings) {
|
|
18
|
-
this.name = commons_1.stripSlashes(settings.name);
|
|
18
|
+
this.name = (0, commons_1.stripSlashes)(settings.name);
|
|
19
19
|
this.options = settings.options;
|
|
20
20
|
this.connection = settings.connection;
|
|
21
21
|
this.base = `${settings.base}/${this.name}`;
|
|
@@ -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(
|
|
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(
|
|
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(
|
|
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(
|
|
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,
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AAEnB,+CAAyD;AACzD,iDAAqD;AAErD,SAAS,OAAO,CAAC,KAA+B;IAC9C,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE;QACjC,MAAM,IAAI,oBAAW,CAAC,KAAK,CAAC,OAAO,EAAE,WAAC,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAA;KACjF;IAED,MAAM,IAAA,gBAAO,EAAC,KAAK,CAAC,CAAA;AACtB,CAAC;AAaD,MAAsB,IAAI;IAQxB,YAAY,QAA4B;QACtC,IAAI,CAAC,IAAI,GAAG,IAAA,sBAAY,EAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QACvC,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAA;QAC/B,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAA;QACrC,IAAI,CAAC,IAAI,GAAG,GAAG,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAA;IAC7C,CAAC;IAED,OAAO,CAAC,KAAY,EAAE,EAA2B;QAC/C,IAAI,GAAG,GAAG,IAAI,CAAC,IAAI,CAAA;QAEnB,KAAK,GAAG,KAAK,IAAI,EAAE,CAAA;QAEnB,IAAI,OAAO,EAAE,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,EAAE,kBAAkB,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC;SAC/E,EACD,MAAM,CACP,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAClB,CAAC;IAED,KAAK,CAAC,EAAc,EAAE,IAAO,EAAE,MAAU;QACvC,IAAI,OAAO,EAAE,KAAK,WAAW,EAAE;YAC7B,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,iFAAiF,CAAC,CAC7F,CAAA;SACF;QAED,OAAO,IAAI,CAAC,OAAO,CACjB;YACE,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;YACnC,IAAI;YACJ,MAAM,EAAE,OAAO;YACf,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,kBAAkB,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC;SAC/E,EACD,MAAM,CACP,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAClB,CAAC;IAED,MAAM,CAAC,EAAc,EAAE,MAAU;QAC/B,IAAI,OAAO,EAAE,KAAK,WAAW,EAAE;YAC7B,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAC9F,CAAA;SACF;QAED,OAAO,IAAI,CAAC,OAAO,CACjB;YACE,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;YACnC,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC;SAC3C,EACD,MAAM,CACP,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAClB,CAAC;CACF;AAzJD,oBAyJC"}
|
package/lib/fetch.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Params } from '@feathersjs/feathers';
|
|
2
|
-
import { Base } from './base';
|
|
3
|
-
export declare class FetchClient extends Base {
|
|
4
|
-
request(options: any, params:
|
|
2
|
+
import { Base, RestClientParams } from './base';
|
|
3
|
+
export declare class FetchClient<T = any, D = Partial<T>, P extends Params = RestClientParams> extends Base<T, D, P> {
|
|
4
|
+
request(options: any, params: RestClientParams): any;
|
|
5
5
|
checkStatus(response: any): any;
|
|
6
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
|
|
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
|
-
})
|
|
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":";;;
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAE3C,iCAA+C;AAE/C,MAAa,WAA0E,SAAQ,WAAa;IAC1G,OAAO,CAAC,OAAY,EAAE,MAAwB;QAC5C,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;QAElE,YAAY,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAClC;YACE,MAAM,EAAE,kBAAkB;SAC3B,EACD,IAAI,CAAC,OAAO,CAAC,OAAO,EACpB,YAAY,CAAC,OAAO,CACrB,CAAA;QAED,IAAI,OAAO,CAAC,IAAI,EAAE;YAChB,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.d.ts
CHANGED
|
@@ -1,27 +1,14 @@
|
|
|
1
|
+
import { TransportConnection } from '@feathersjs/feathers';
|
|
1
2
|
import { Base } from './base';
|
|
2
3
|
import { AxiosClient } from './axios';
|
|
3
4
|
import { FetchClient } from './fetch';
|
|
4
5
|
import { SuperagentClient } from './superagent';
|
|
5
6
|
export { AxiosClient, FetchClient, SuperagentClient };
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Transport Service
|
|
13
|
-
*/
|
|
14
|
-
Service: any;
|
|
15
|
-
/**
|
|
16
|
-
* default Service
|
|
17
|
-
*/
|
|
18
|
-
service: any;
|
|
7
|
+
export type Handler<ServiceTypes> = (connection: any, options?: any, Service?: any) => TransportConnection<ServiceTypes>;
|
|
8
|
+
export interface Transport<ServiceTypes> {
|
|
9
|
+
superagent: Handler<ServiceTypes>;
|
|
10
|
+
fetch: Handler<ServiceTypes>;
|
|
11
|
+
axios: Handler<ServiceTypes>;
|
|
19
12
|
}
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
superagent: Handler;
|
|
23
|
-
fetch: Handler;
|
|
24
|
-
axios: Handler;
|
|
25
|
-
}
|
|
26
|
-
export declare type RestService<T = any, D = Partial<any>> = Base<T, D>;
|
|
27
|
-
export default function restClient(base?: string): Transport;
|
|
13
|
+
export type RestService<T = any, D = Partial<any>> = Base<T, D>;
|
|
14
|
+
export default function restClient<ServiceTypes = any>(base?: string): Transport<ServiceTypes>;
|
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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAA8F;AAE9F,iCAA6B;AAC7B,mCAAqC;AAI5B,4FAJA,mBAAW,OAIA;AAHpB,mCAAqC;AAGf,4FAHb,mBAAW,OAGa;AAFjC,6CAA+C;AAEZ,iGAF1B,6BAAgB,OAE0B;AAEnD,MAAM,UAAU,GAAG;IACjB,UAAU,EAAE,6BAAgB;IAC5B,KAAK,EAAE,mBAAW;IAClB,KAAK,EAAE,mBAAW;CACnB,CAAA;AAgBD,SAAwB,UAAU,CAAqB,IAAI,GAAG,EAAE;IAC9D,MAAM,MAAM,GAAQ,EAAE,IAAI,EAAJ,WAAI,EAAE,CAAA;IAE5B,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACtC,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,CAAA;aAC9D;YAED,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;gBACjC,OAAO,GAAG,OAAO,CAAA;gBACjB,OAAO,GAAG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|
|
|
1
1
|
import { Params } from '@feathersjs/feathers';
|
|
2
|
-
import { Base } from './base';
|
|
3
|
-
export declare class SuperagentClient extends Base {
|
|
4
|
-
request(options: any, params:
|
|
2
|
+
import { Base, RestClientParams } from './base';
|
|
3
|
+
export declare class SuperagentClient<T = any, D = Partial<T>, P extends Params = RestClientParams> extends Base<T, D, P> {
|
|
4
|
+
request(options: any, params: RestClientParams): Promise<unknown>;
|
|
5
5
|
}
|
package/lib/superagent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superagent.js","sourceRoot":"","sources":["../src/superagent.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"superagent.js","sourceRoot":"","sources":["../src/superagent.ts"],"names":[],"mappings":";;;AACA,iCAA+C;AAE/C,MAAa,gBAA+E,SAAQ,WAInG;IACC,OAAO,CAAC,OAAY,EAAE,MAAwB;QAC5C,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,CAAA;QAE/B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,UAAU,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,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feathersjs/rest-client",
|
|
3
3
|
"description": "REST client services for different Ajax libraries",
|
|
4
|
-
"version": "5.0.0
|
|
4
|
+
"version": "5.0.0",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
|
-
"main": "lib/
|
|
6
|
+
"main": "lib/",
|
|
7
|
+
"types": "lib/",
|
|
7
8
|
"keywords": [
|
|
8
9
|
"feathers",
|
|
9
10
|
"feathers-plugin"
|
|
@@ -15,7 +16,8 @@
|
|
|
15
16
|
},
|
|
16
17
|
"repository": {
|
|
17
18
|
"type": "git",
|
|
18
|
-
"url": "git://github.com/feathersjs/feathers.git"
|
|
19
|
+
"url": "git://github.com/feathersjs/feathers.git",
|
|
20
|
+
"directory": "packages/rest-client"
|
|
19
21
|
},
|
|
20
22
|
"author": {
|
|
21
23
|
"name": "Feathers contributors",
|
|
@@ -40,7 +42,8 @@
|
|
|
40
42
|
],
|
|
41
43
|
"scripts": {
|
|
42
44
|
"prepublish": "npm run compile",
|
|
43
|
-
"
|
|
45
|
+
"pack": "npm pack --pack-destination ../generators/test/build",
|
|
46
|
+
"compile": "shx rm -rf lib/ && tsc && npm run pack",
|
|
44
47
|
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
|
|
45
48
|
},
|
|
46
49
|
"directories": {
|
|
@@ -50,27 +53,28 @@
|
|
|
50
53
|
"access": "public"
|
|
51
54
|
},
|
|
52
55
|
"dependencies": {
|
|
53
|
-
"@feathersjs/commons": "^5.0.0
|
|
54
|
-
"@feathersjs/errors": "^5.0.0
|
|
55
|
-
"@
|
|
56
|
-
"@types/superagent": "^4.1.
|
|
57
|
-
"qs": "^6.
|
|
56
|
+
"@feathersjs/commons": "^5.0.0",
|
|
57
|
+
"@feathersjs/errors": "^5.0.0",
|
|
58
|
+
"@feathersjs/feathers": "^5.0.0",
|
|
59
|
+
"@types/superagent": "^4.1.16",
|
|
60
|
+
"qs": "^6.11.0"
|
|
58
61
|
},
|
|
59
62
|
"devDependencies": {
|
|
60
|
-
"@feathersjs/express": "^5.0.0
|
|
61
|
-
"@feathersjs/
|
|
62
|
-
"@feathersjs/
|
|
63
|
-
"@
|
|
64
|
-
"@types/
|
|
65
|
-
"@types/node": "^
|
|
66
|
-
"
|
|
67
|
-
"
|
|
63
|
+
"@feathersjs/express": "^5.0.0",
|
|
64
|
+
"@feathersjs/memory": "^5.0.0",
|
|
65
|
+
"@feathersjs/tests": "^5.0.0",
|
|
66
|
+
"@types/mocha": "^10.0.1",
|
|
67
|
+
"@types/node": "^18.14.1",
|
|
68
|
+
"@types/node-fetch": "^2.6.2",
|
|
69
|
+
"@types/qs": "^6.9.7",
|
|
70
|
+
"axios": "^1.3.4",
|
|
71
|
+
"mocha": "^10.2.0",
|
|
68
72
|
"node-fetch": "^2.6.1",
|
|
69
|
-
"rxjs": "^7.
|
|
70
|
-
"shx": "^0.3.
|
|
71
|
-
"superagent": "^
|
|
72
|
-
"ts-node": "^10.1
|
|
73
|
-
"typescript": "^4.
|
|
73
|
+
"rxjs": "^7.8.0",
|
|
74
|
+
"shx": "^0.3.4",
|
|
75
|
+
"superagent": "^8.0.9",
|
|
76
|
+
"ts-node": "^10.9.1",
|
|
77
|
+
"typescript": "^4.9.5"
|
|
74
78
|
},
|
|
75
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "90caf635aec850550b9d37bea2762af959d9e8d5"
|
|
76
80
|
}
|
package/src/axios.ts
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
import { Params } from '@feathersjs/feathers'
|
|
2
|
-
import { Base } from './base'
|
|
1
|
+
import { Params } from '@feathersjs/feathers'
|
|
2
|
+
import { Base, RestClientParams } from './base'
|
|
3
3
|
|
|
4
|
-
export class AxiosClient extends Base {
|
|
5
|
-
request
|
|
6
|
-
const config = Object.assign(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
)
|
|
14
21
|
|
|
15
|
-
return this.connection
|
|
22
|
+
return this.connection
|
|
23
|
+
.request(config)
|
|
16
24
|
.then((res: any) => res.data)
|
|
17
25
|
.catch((error: any) => {
|
|
18
|
-
const response = error.response || error
|
|
26
|
+
const response = error.response || error
|
|
19
27
|
|
|
20
|
-
throw response instanceof Error ? response :
|
|
21
|
-
})
|
|
28
|
+
throw response instanceof Error ? response : response.data || response
|
|
29
|
+
})
|
|
22
30
|
}
|
|
23
31
|
}
|