@feathersjs/rest-client 5.0.0-pre.1 → 5.0.0-pre.15
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 +149 -0
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/lib/base.d.ts +6 -5
- package/lib/base.js +19 -5
- package/lib/base.js.map +1 -1
- package/lib/fetch.js +1 -2
- package/lib/fetch.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/superagent.js.map +1 -1
- package/package.json +20 -20
- package/src/base.ts +27 -10
- package/src/fetch.ts +1 -3
- package/src/index.ts +3 -1
- package/src/superagent.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,155 @@
|
|
|
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.15](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.14...v5.0.0-pre.15) (2021-11-27)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **typescript:** Overall typing improvements ([#2478](https://github.com/feathersjs/feathers/issues/2478)) ([b8eb804](https://github.com/feathersjs/feathers/commit/b8eb804158556d9651a8607e3c3fda15e0bfd110))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [5.0.0-pre.14](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.13...v5.0.0-pre.14) (2021-10-13)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @feathersjs/rest-client
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# [5.0.0-pre.13](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.12...v5.0.0-pre.13) (2021-10-13)
|
|
26
|
+
|
|
27
|
+
**Note:** Version bump only for package @feathersjs/rest-client
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# [5.0.0-pre.12](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.11...v5.0.0-pre.12) (2021-10-12)
|
|
34
|
+
|
|
35
|
+
**Note:** Version bump only for package @feathersjs/rest-client
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# [5.0.0-pre.11](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.10...v5.0.0-pre.11) (2021-10-06)
|
|
42
|
+
|
|
43
|
+
**Note:** Version bump only for package @feathersjs/rest-client
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# [5.0.0-pre.10](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.9...v5.0.0-pre.10) (2021-09-19)
|
|
50
|
+
|
|
51
|
+
**Note:** Version bump only for package @feathersjs/rest-client
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# [5.0.0-pre.9](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.8...v5.0.0-pre.9) (2021-08-09)
|
|
58
|
+
|
|
59
|
+
**Note:** Version bump only for package @feathersjs/rest-client
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# [5.0.0-pre.8](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.7...v5.0.0-pre.8) (2021-08-09)
|
|
66
|
+
|
|
67
|
+
**Note:** Version bump only for package @feathersjs/rest-client
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# [5.0.0-pre.7](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.6...v5.0.0-pre.7) (2021-08-09)
|
|
74
|
+
|
|
75
|
+
**Note:** Version bump only for package @feathersjs/rest-client
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# [5.0.0-pre.6](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.5...v5.0.0-pre.6) (2021-08-08)
|
|
82
|
+
|
|
83
|
+
**Note:** Version bump only for package @feathersjs/rest-client
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# [5.0.0-pre.5](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.4...v5.0.0-pre.5) (2021-06-23)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
### Features
|
|
93
|
+
|
|
94
|
+
* **adapter-commons:** Add support for params.adapter option and move memory adapter to @feathersjs/memory ([#2367](https://github.com/feathersjs/feathers/issues/2367)) ([a43e7da](https://github.com/feathersjs/feathers/commit/a43e7da22b6b981a96d1321736ea9a0cb924fb4f))
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# [5.0.0-pre.4](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.3...v5.0.0-pre.4) (2021-05-13)
|
|
101
|
+
|
|
102
|
+
**Note:** Version bump only for package @feathersjs/rest-client
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
# [5.0.0-pre.3](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.2...v5.0.0-pre.3) (2021-04-21)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
### Bug Fixes
|
|
112
|
+
|
|
113
|
+
* **typescript:** Improve TypeScript backwards compatibility ([#2310](https://github.com/feathersjs/feathers/issues/2310)) ([f33be73](https://github.com/feathersjs/feathers/commit/f33be73fc46a533efb15df9aab0658e3240d3897))
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
# [5.0.0-pre.2](https://github.com/feathersjs/feathers/compare/v5.0.0-beta.1...v5.0.0-pre.2) (2021-04-06)
|
|
120
|
+
|
|
121
|
+
**Note:** Version bump only for package @feathersjs/rest-client
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
# [5.0.0-beta.1](https://github.com/feathersjs/feathers/compare/v5.0.0-beta.0...v5.0.0-beta.1) (2021-04-03)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
### Bug Fixes
|
|
131
|
+
|
|
132
|
+
* **dependencies:** Fix transport-commons dependency and update other dependencies ([#2284](https://github.com/feathersjs/feathers/issues/2284)) ([05b03b2](https://github.com/feathersjs/feathers/commit/05b03b27b40604d956047e3021d8053c3a137616))
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
# [5.0.0-beta.0](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.1...v5.0.0-beta.0) (2021-03-28)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
### Bug Fixes
|
|
142
|
+
|
|
143
|
+
* Update Grant usage and other dependencies ([#2264](https://github.com/feathersjs/feathers/issues/2264)) ([7b0f8fa](https://github.com/feathersjs/feathers/commit/7b0f8fad252419ed0ad0bf259cdf3104d322ab60))
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
### Features
|
|
147
|
+
|
|
148
|
+
* **core:** Public custom service methods ([#2270](https://github.com/feathersjs/feathers/issues/2270)) ([e65abfb](https://github.com/feathersjs/feathers/commit/e65abfb5388df6c19a11c565cf1076a29f32668d))
|
|
149
|
+
* Feathers v5 core refactoring and features ([#2255](https://github.com/feathersjs/feathers/issues/2255)) ([2dafb7c](https://github.com/feathersjs/feathers/commit/2dafb7ce14ba57406aeec13d10ca45b1e709bee9))
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
6
155
|
# [5.0.0-pre.1](https://github.com/feathersjs/feathers/compare/v4.5.11...v5.0.0-pre.1) (2020-12-17)
|
|
7
156
|
|
|
8
157
|
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -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) 2021 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
|
|
22
22
|
|
|
23
23
|
Licensed under the [MIT license](LICENSE).
|
package/lib/base.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Params, Id, Query, NullableId } from '@feathersjs/feathers';
|
|
1
|
+
import { Params, Id, Query, NullableId, ServiceInterface } from '@feathersjs/feathers';
|
|
2
2
|
interface RestClientSettings {
|
|
3
3
|
name: string;
|
|
4
4
|
base: string;
|
|
5
5
|
connection: any;
|
|
6
6
|
options: any;
|
|
7
7
|
}
|
|
8
|
-
export declare abstract class Base {
|
|
8
|
+
export declare abstract class Base<T = any, D = Partial<T>> implements ServiceInterface<T, D> {
|
|
9
9
|
name: string;
|
|
10
10
|
base: string;
|
|
11
11
|
connection: any;
|
|
@@ -14,11 +14,12 @@ export declare abstract class Base {
|
|
|
14
14
|
makeUrl(query: Query, id?: string | number | null): string;
|
|
15
15
|
getQuery(query: Query): string;
|
|
16
16
|
abstract request(options: any, params: Params): any;
|
|
17
|
+
methods(this: any, ...names: string[]): any;
|
|
17
18
|
find(params?: Params): any;
|
|
18
19
|
get(id: Id, params?: Params): any;
|
|
19
|
-
create(body:
|
|
20
|
-
update(id: NullableId, body:
|
|
21
|
-
patch(id: NullableId, body:
|
|
20
|
+
create(body: D, params?: Params): any;
|
|
21
|
+
update(id: NullableId, body: D, params?: Params): any;
|
|
22
|
+
patch(id: NullableId, body: D, params?: Params): any;
|
|
22
23
|
remove(id: NullableId, params?: Params): any;
|
|
23
24
|
}
|
|
24
25
|
export {};
|
package/lib/base.js
CHANGED
|
@@ -7,24 +7,22 @@ exports.Base = void 0;
|
|
|
7
7
|
const qs_1 = __importDefault(require("qs"));
|
|
8
8
|
const errors_1 = require("@feathersjs/errors");
|
|
9
9
|
const commons_1 = require("@feathersjs/commons");
|
|
10
|
-
const commons_2 = require("@feathersjs/commons");
|
|
11
|
-
const errors_2 = require("@feathersjs/errors");
|
|
12
10
|
function toError(error) {
|
|
13
11
|
if (error.code === 'ECONNREFUSED') {
|
|
14
12
|
throw new errors_1.Unavailable(error.message, commons_1._.pick(error, 'address', 'port', 'config'));
|
|
15
13
|
}
|
|
16
|
-
throw
|
|
14
|
+
throw (0, errors_1.convert)(error);
|
|
17
15
|
}
|
|
18
16
|
class Base {
|
|
19
17
|
constructor(settings) {
|
|
20
|
-
this.name =
|
|
18
|
+
this.name = (0, commons_1.stripSlashes)(settings.name);
|
|
21
19
|
this.options = settings.options;
|
|
22
20
|
this.connection = settings.connection;
|
|
23
21
|
this.base = `${settings.base}/${this.name}`;
|
|
24
22
|
}
|
|
25
23
|
makeUrl(query, id) {
|
|
26
|
-
query = query || {};
|
|
27
24
|
let url = this.base;
|
|
25
|
+
query = query || {};
|
|
28
26
|
if (typeof id !== 'undefined' && id !== null) {
|
|
29
27
|
url += `/${encodeURIComponent(id)}`;
|
|
30
28
|
}
|
|
@@ -37,6 +35,22 @@ class Base {
|
|
|
37
35
|
}
|
|
38
36
|
return '';
|
|
39
37
|
}
|
|
38
|
+
methods(...names) {
|
|
39
|
+
names.forEach(method => {
|
|
40
|
+
this[method] = function (body, params = {}) {
|
|
41
|
+
return this.request({
|
|
42
|
+
body,
|
|
43
|
+
url: this.makeUrl(params.query),
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers: Object.assign({
|
|
46
|
+
'Content-Type': 'application/json',
|
|
47
|
+
'X-Service-Method': method
|
|
48
|
+
}, params.headers)
|
|
49
|
+
}, params).catch(toError);
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
40
54
|
find(params = {}) {
|
|
41
55
|
return this.request({
|
|
42
56
|
url: this.makeUrl(params.query),
|
package/lib/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAqB;
|
|
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,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;KAClF;IAED,MAAM,IAAA,gBAAO,EAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AASD,MAAsB,IAAI;IAMxB,YAAa,QAA4B;QACvC,IAAI,CAAC,IAAI,GAAG,IAAA,sBAAY,EAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;QAChC,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,GAAG,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;IAC9C,CAAC;IAED,OAAO,CAAE,KAAY,EAAE,EAAuB;QAC5C,IAAI,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;QAEpB,KAAK,GAAG,KAAK,IAAI,EAAE,CAAC;QAEpB,IAAI,OAAO,EAAE,KAAK,WAAW,IAAI,EAAE,KAAK,IAAI,EAAE;YAC5C,GAAG,IAAI,IAAI,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC;SACrC;QAED,OAAO,GAAG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C,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAE,EAAc,EAAE,IAAO,EAAE,SAAiB,EAAE;QACjD,IAAI,OAAO,EAAE,KAAK,WAAW,EAAE;YAC7B,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,qFAAqF,CAAC,CAAC,CAAC;SACzH;QAED,OAAO,IAAI,CAAC,OAAO,CAAC;YAClB,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,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM,CAAE,EAAc,EAAE,SAAiB,EAAE;QACzC,IAAI,OAAO,EAAE,KAAK,WAAW,EAAE;YAC7B,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sFAAsF,CAAC,CAAC,CAAC;SAC1H;QAED,OAAO,IAAI,CAAC,OAAO,CAAC;YAClB,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,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;CACF;AAzHD,oBAyHC"}
|
package/lib/fetch.js
CHANGED
|
@@ -12,8 +12,7 @@ class FetchClient extends base_1.Base {
|
|
|
12
12
|
if (options.body) {
|
|
13
13
|
fetchOptions.body = JSON.stringify(options.body);
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
return fetch(options.url, fetchOptions)
|
|
15
|
+
return this.connection(options.url, fetchOptions)
|
|
17
16
|
.then(this.checkStatus)
|
|
18
17
|
.then((response) => {
|
|
19
18
|
if (response.status === 204) {
|
package/lib/fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":";;;AACA,+CAA4C;AAC5C,iCAA8B;AAE9B,MAAa,WAAY,SAAQ,WAAI;IACnC,OAAO,CAAE,OAAY,EAAE,MAAc;QACnC,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,
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":";;;AACA,+CAA4C;AAC5C,iCAA8B;AAE9B,MAAa,WAAY,SAAQ,WAAI;IACnC,OAAO,CAAE,OAAY,EAAE,MAAc;QACnC,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,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,CAAC;aACb;YAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;QACzB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,WAAW,CAAE,QAAa;QACxB,IAAI,QAAQ,CAAC,EAAE,EAAE;YACf,OAAO,QAAQ,CAAC;SACjB;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;YAChC,MAAM,UAAU,GAAI,eAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC;YAE7D,OAAO,IAAI,UAAU,CAAC,oBAAoB,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAU,EAAE,EAAE;YACrB,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;YAC1B,MAAM,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AArCD,kCAqCC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Base } from './base';
|
|
1
2
|
import { AxiosClient } from './axios';
|
|
2
3
|
import { FetchClient } from './fetch';
|
|
3
4
|
import { SuperagentClient } from './superagent';
|
|
@@ -22,4 +23,5 @@ export interface Transport {
|
|
|
22
23
|
fetch: Handler;
|
|
23
24
|
axios: Handler;
|
|
24
25
|
}
|
|
26
|
+
export declare type RestService<T = any, D = Partial<any>> = Base<T, D>;
|
|
25
27
|
export default function restClient(base?: string): Transport;
|
package/lib/index.js
CHANGED
|
@@ -28,7 +28,7 @@ function restClient(base = '') {
|
|
|
28
28
|
return new Service({ base, name, connection, options });
|
|
29
29
|
};
|
|
30
30
|
const initialize = (app) => {
|
|
31
|
-
if (
|
|
31
|
+
if (app.rest !== undefined) {
|
|
32
32
|
throw new Error('Only one default client provider can be configured');
|
|
33
33
|
}
|
|
34
34
|
app.rest = connection;
|
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;
|
|
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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C,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,CAAC;YAEhC,IAAI,OAAO,CAAC,IAAI,EAAE;gBAChB,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;aAC/B;YAED,UAAU,CAAC,GAAG,CAAC,UAAU,KAAU,EAAE,GAAQ;gBAC3C,IAAI,KAAK,EAAE;oBACT,IAAI;wBACF,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;wBAChC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;wBACxC,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;qBAC3B;oBAAC,OAAO,CAAM,EAAE,GAAE;oBAEnB,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;iBACtB;gBAED,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA/BD,4CA+BC"}
|
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.
|
|
4
|
+
"version": "5.0.0-pre.15",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"keywords": [
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"url": "https://github.com/feathersjs/feathers/issues"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|
|
30
|
-
"node": ">=
|
|
30
|
+
"node": ">= 12"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"CHANGELOG.md",
|
|
@@ -50,28 +50,28 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@feathersjs/commons": "^5.0.0-pre.
|
|
54
|
-
"@feathersjs/errors": "^5.0.0-pre.
|
|
55
|
-
"@types/node-fetch": "^
|
|
56
|
-
"@types/superagent": "^4.1.
|
|
57
|
-
"qs": "^6.
|
|
53
|
+
"@feathersjs/commons": "^5.0.0-pre.15",
|
|
54
|
+
"@feathersjs/errors": "^5.0.0-pre.15",
|
|
55
|
+
"@types/node-fetch": "^3.0.2",
|
|
56
|
+
"@types/superagent": "^4.1.13",
|
|
57
|
+
"qs": "^6.10.1"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@feathersjs/
|
|
61
|
-
"@feathersjs/
|
|
62
|
-
"@feathersjs/
|
|
63
|
-
"@feathersjs/tests": "^5.0.0-pre.
|
|
64
|
-
"@types/mocha": "^
|
|
65
|
-
"@types/node": "^
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"mocha": "^
|
|
60
|
+
"@feathersjs/express": "^5.0.0-pre.15",
|
|
61
|
+
"@feathersjs/feathers": "^5.0.0-pre.15",
|
|
62
|
+
"@feathersjs/memory": "^5.0.0-pre.15",
|
|
63
|
+
"@feathersjs/tests": "^5.0.0-pre.15",
|
|
64
|
+
"@types/mocha": "^9.0.0",
|
|
65
|
+
"@types/node": "^16.11.6",
|
|
66
|
+
"@types/qs": "^6.9.7",
|
|
67
|
+
"axios": "^0.24.0",
|
|
68
|
+
"mocha": "^9.1.3",
|
|
69
69
|
"node-fetch": "^2.6.1",
|
|
70
|
-
"rxjs": "^
|
|
70
|
+
"rxjs": "^7.4.0",
|
|
71
71
|
"shx": "^0.3.3",
|
|
72
72
|
"superagent": "^6.1.0",
|
|
73
|
-
"ts-node": "^
|
|
74
|
-
"typescript": "^4.
|
|
73
|
+
"ts-node": "^10.4.0",
|
|
74
|
+
"typescript": "^4.4.4"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "8008bf4f8529a2a40b6a2f976c1f43ae13675693"
|
|
77
77
|
}
|
package/src/base.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import qs from 'qs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { stripSlashes }
|
|
5
|
-
import { convert } from '@feathersjs/errors';
|
|
6
|
-
import { Params, Id, Query, NullableId } from '@feathersjs/feathers';
|
|
2
|
+
import { Params, Id, Query, NullableId, ServiceInterface } from '@feathersjs/feathers';
|
|
3
|
+
import { Unavailable, convert } from '@feathersjs/errors';
|
|
4
|
+
import { _, stripSlashes } from '@feathersjs/commons';
|
|
7
5
|
|
|
8
6
|
function toError (error: Error & { code: string }) {
|
|
9
7
|
if (error.code === 'ECONNREFUSED') {
|
|
@@ -20,7 +18,7 @@ interface RestClientSettings {
|
|
|
20
18
|
options: any;
|
|
21
19
|
}
|
|
22
20
|
|
|
23
|
-
export abstract class Base {
|
|
21
|
+
export abstract class Base<T = any, D = Partial<T>> implements ServiceInterface<T, D> {
|
|
24
22
|
name: string;
|
|
25
23
|
base: string;
|
|
26
24
|
connection: any;
|
|
@@ -34,9 +32,10 @@ export abstract class Base {
|
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
makeUrl (query: Query, id?: string|number|null) {
|
|
37
|
-
query = query || {};
|
|
38
35
|
let url = this.base;
|
|
39
36
|
|
|
37
|
+
query = query || {};
|
|
38
|
+
|
|
40
39
|
if (typeof id !== 'undefined' && id !== null) {
|
|
41
40
|
url += `/${encodeURIComponent(id)}`;
|
|
42
41
|
}
|
|
@@ -56,6 +55,24 @@ export abstract class Base {
|
|
|
56
55
|
|
|
57
56
|
abstract request (options: any, params: Params): any;
|
|
58
57
|
|
|
58
|
+
methods (this: any, ...names: string[]) {
|
|
59
|
+
names.forEach(method => {
|
|
60
|
+
this[method] = function (body: any, params: Params = {}) {
|
|
61
|
+
return this.request({
|
|
62
|
+
body,
|
|
63
|
+
url: this.makeUrl(params.query),
|
|
64
|
+
method: 'POST',
|
|
65
|
+
headers: Object.assign({
|
|
66
|
+
'Content-Type': 'application/json',
|
|
67
|
+
'X-Service-Method': method
|
|
68
|
+
}, params.headers)
|
|
69
|
+
}, params).catch(toError);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
|
|
59
76
|
find (params: Params = {}) {
|
|
60
77
|
return this.request({
|
|
61
78
|
url: this.makeUrl(params.query),
|
|
@@ -76,7 +93,7 @@ export abstract class Base {
|
|
|
76
93
|
}, params).catch(toError);
|
|
77
94
|
}
|
|
78
95
|
|
|
79
|
-
create (body:
|
|
96
|
+
create (body: D, params: Params = {}) {
|
|
80
97
|
return this.request({
|
|
81
98
|
url: this.makeUrl(params.query),
|
|
82
99
|
body,
|
|
@@ -85,7 +102,7 @@ export abstract class Base {
|
|
|
85
102
|
}, params).catch(toError);
|
|
86
103
|
}
|
|
87
104
|
|
|
88
|
-
update (id: NullableId, body:
|
|
105
|
+
update (id: NullableId, body: D, params: Params = {}) {
|
|
89
106
|
if (typeof id === 'undefined') {
|
|
90
107
|
return Promise.reject(new Error('id for \'update\' can not be undefined, only \'null\' when updating multiple entries'));
|
|
91
108
|
}
|
|
@@ -98,7 +115,7 @@ export abstract class Base {
|
|
|
98
115
|
}, params).catch(toError);
|
|
99
116
|
}
|
|
100
117
|
|
|
101
|
-
patch (id: NullableId, body:
|
|
118
|
+
patch (id: NullableId, body: D, params: Params = {}) {
|
|
102
119
|
if (typeof id === 'undefined') {
|
|
103
120
|
return Promise.reject(new Error('id for \'patch\' can not be undefined, only \'null\' when updating multiple entries'));
|
|
104
121
|
}
|
package/src/fetch.ts
CHANGED
|
@@ -14,9 +14,7 @@ export class FetchClient extends Base {
|
|
|
14
14
|
fetchOptions.body = JSON.stringify(options.body);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return fetch(options.url, fetchOptions)
|
|
17
|
+
return this.connection(options.url, fetchOptions)
|
|
20
18
|
.then(this.checkStatus)
|
|
21
19
|
.then((response: any) => {
|
|
22
20
|
if (response.status === 204) {
|
package/src/index.ts
CHANGED
|
@@ -36,6 +36,8 @@ export interface Transport {
|
|
|
36
36
|
axios: Handler;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
export type RestService<T = any, D = Partial<any>> = Base<T, D>;
|
|
40
|
+
|
|
39
41
|
export default function restClient (base = '') {
|
|
40
42
|
const result: any = { Base };
|
|
41
43
|
|
|
@@ -55,7 +57,7 @@ export default function restClient (base = '') {
|
|
|
55
57
|
};
|
|
56
58
|
|
|
57
59
|
const initialize = (app: any) => {
|
|
58
|
-
if (
|
|
60
|
+
if (app.rest !== undefined) {
|
|
59
61
|
throw new Error('Only one default client provider can be configured');
|
|
60
62
|
}
|
|
61
63
|
|
package/src/superagent.ts
CHANGED