shelving 1.166.0 → 1.167.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/api/Endpoint.d.ts +18 -2
- package/api/Endpoint.js +22 -6
- package/package.json +1 -1
package/api/Endpoint.d.ts
CHANGED
|
@@ -48,11 +48,27 @@ export declare class Endpoint<P, R> {
|
|
|
48
48
|
*/
|
|
49
49
|
renderURL(payload: P, caller?: AnyCaller): string;
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
51
|
+
* Get an HTTP `Request` object for this endpoint.
|
|
52
|
+
* - Validates a payload against this endpoints payload schema
|
|
53
|
+
* - Return an HTTP `Request` that will send it the valid payload to this endpoint.
|
|
54
|
+
*
|
|
55
|
+
* @throws Feedback if the payload is invalid.
|
|
52
56
|
*/
|
|
53
57
|
request(payload: P, options?: EndpointOptions, caller?: AnyCaller): Request;
|
|
54
58
|
/**
|
|
55
|
-
*
|
|
59
|
+
* Validate an HTTP `Response` against this endpoint.
|
|
60
|
+
* @throws ResponseError if the response status is not ok (200-299)
|
|
61
|
+
* @throws ResponseError if the response content is invalid.
|
|
62
|
+
*/
|
|
63
|
+
response(response: Response, caller?: AnyCaller): Promise<R>;
|
|
64
|
+
/**
|
|
65
|
+
* Perform a fetch to this endpoint.
|
|
66
|
+
* - Validate the `payload` against this endpoint's payload schema.
|
|
67
|
+
* - Validate the returned response against this endpoint's result schema.
|
|
68
|
+
*
|
|
69
|
+
* @throws Feedback if the payload is invalid.
|
|
70
|
+
* @throws ResponseError if the response status is not ok (200-299)
|
|
71
|
+
* @throws ResponseError if the response content is invalid.
|
|
56
72
|
*/
|
|
57
73
|
fetch(payload: P, options?: EndpointOptions, caller?: AnyCaller): Promise<R>;
|
|
58
74
|
/** Convert to string, e.g. `GET https://a.com/user/{id}` */
|
package/api/Endpoint.js
CHANGED
|
@@ -70,18 +70,21 @@ export class Endpoint {
|
|
|
70
70
|
return url;
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
73
|
+
* Get an HTTP `Request` object for this endpoint.
|
|
74
|
+
* - Validates a payload against this endpoints payload schema
|
|
75
|
+
* - Return an HTTP `Request` that will send it the valid payload to this endpoint.
|
|
76
|
+
*
|
|
77
|
+
* @throws Feedback if the payload is invalid.
|
|
74
78
|
*/
|
|
75
79
|
request(payload, options = {}, caller = this.request) {
|
|
76
80
|
return createRequest(this.method, this.url, this.payload.validate(payload), options, caller);
|
|
77
81
|
}
|
|
78
82
|
/**
|
|
79
|
-
*
|
|
83
|
+
* Validate an HTTP `Response` against this endpoint.
|
|
84
|
+
* @throws ResponseError if the response status is not ok (200-299)
|
|
85
|
+
* @throws ResponseError if the response content is invalid.
|
|
80
86
|
*/
|
|
81
|
-
async
|
|
82
|
-
// Fetch the response.
|
|
83
|
-
const request = this.request(payload, options, caller);
|
|
84
|
-
const response = await fetch(request);
|
|
87
|
+
async response(response, caller = this.response) {
|
|
85
88
|
// Get the response.
|
|
86
89
|
const { ok, status } = response;
|
|
87
90
|
const content = await getResponseContent(response, caller);
|
|
@@ -91,6 +94,19 @@ export class Endpoint {
|
|
|
91
94
|
// Validate the success response.
|
|
92
95
|
return getValid(content, this.result, ResponseError, caller);
|
|
93
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Perform a fetch to this endpoint.
|
|
99
|
+
* - Validate the `payload` against this endpoint's payload schema.
|
|
100
|
+
* - Validate the returned response against this endpoint's result schema.
|
|
101
|
+
*
|
|
102
|
+
* @throws Feedback if the payload is invalid.
|
|
103
|
+
* @throws ResponseError if the response status is not ok (200-299)
|
|
104
|
+
* @throws ResponseError if the response content is invalid.
|
|
105
|
+
*/
|
|
106
|
+
async fetch(payload, options = {}, caller = this.fetch) {
|
|
107
|
+
const response = await fetch(this.request(payload, options, caller));
|
|
108
|
+
return this.response(response, caller);
|
|
109
|
+
}
|
|
94
110
|
/** Convert to string, e.g. `GET https://a.com/user/{id}` */
|
|
95
111
|
toString() {
|
|
96
112
|
return `${this.method} ${this.url}`;
|