api-def 0.6.0-alpha4 → 0.6.0-alpha8
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 +1 -0
- package/cjs/Requester.js +1 -5
- package/cjs/UtilTypes.d.ts +4 -4
- package/cjs/backend/AxiosRequestBackend.js +4 -3
- package/cjs/backend/FetchRequestBackend.js +4 -3
- package/esm/Requester.js +1 -5
- package/esm/UtilTypes.d.ts +4 -4
- package/esm/backend/AxiosRequestBackend.js +4 -3
- package/esm/backend/FetchRequestBackend.js +4 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/cjs/Requester.js
CHANGED
|
@@ -60,7 +60,7 @@ var locks = {};
|
|
|
60
60
|
var runningOperations = {};
|
|
61
61
|
var MOCK_REQUEST_BACKEND = new MockRequestBackend_1.default();
|
|
62
62
|
var submit = function (host, config, mocking) { return __awaiter(void 0, void 0, void 0, function () {
|
|
63
|
-
var computedConfig, backend, context, key,
|
|
63
|
+
var computedConfig, backend, context, key, lock, lockedContext, response, successEventResult, error_1;
|
|
64
64
|
return __generator(this, function (_a) {
|
|
65
65
|
switch (_a.label) {
|
|
66
66
|
case 0:
|
|
@@ -71,10 +71,6 @@ var submit = function (host, config, mocking) { return __awaiter(void 0, void 0,
|
|
|
71
71
|
}
|
|
72
72
|
context = new RequestContext_1.default(backend, host, computedConfig, host.computePath(host.path, config), mocking);
|
|
73
73
|
key = context.key;
|
|
74
|
-
sameRequest = runningOperations[key];
|
|
75
|
-
if (sameRequest) {
|
|
76
|
-
return [2 /*return*/, sameRequest];
|
|
77
|
-
}
|
|
78
74
|
lock = (context.computedConfig || {}).lock;
|
|
79
75
|
if (lock) {
|
|
80
76
|
lockedContext = locks[lock];
|
package/cjs/UtilTypes.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Endpoint from "./Endpoint";
|
|
2
|
-
export declare type ResponseOf<E extends Endpoint
|
|
3
|
-
export declare type ParamsOf<E extends Endpoint
|
|
4
|
-
export declare type QueryOf<E extends Endpoint
|
|
5
|
-
export declare type BodyOf<E extends Endpoint
|
|
2
|
+
export declare type ResponseOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<infer R, any, any, any> ? R : never;
|
|
3
|
+
export declare type ParamsOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<any, infer P, any, any> ? P : never;
|
|
4
|
+
export declare type QueryOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<any, any, infer Q, any> ? Q : never;
|
|
5
|
+
export declare type BodyOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<any, any, any, infer B> ? B : never;
|
|
@@ -62,13 +62,14 @@ var AxiosRequestBackend = /** @class */ (function () {
|
|
|
62
62
|
};
|
|
63
63
|
AxiosRequestBackend.prototype.convertResponse = function (context, response) {
|
|
64
64
|
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
-
var inferredResponseType;
|
|
65
|
+
var contentType, inferredResponseType;
|
|
66
66
|
return __generator(this, function (_a) {
|
|
67
|
-
|
|
67
|
+
contentType = response.headers["content-type"];
|
|
68
|
+
inferredResponseType = ApiUtils_1.inferResponseType(contentType);
|
|
68
69
|
// expand to array buffer once we support that in inferResponseType
|
|
69
70
|
if (inferredResponseType === "text" && context.responseType === "json") {
|
|
70
71
|
throw RequestError_1.convertToRequestError({
|
|
71
|
-
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "'"),
|
|
72
|
+
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "' (from 'Content-Type' of '" + contentType + "')"),
|
|
72
73
|
code: RequestError_1.RequestErrorCode.REQUEST_MISMATCH_RESPONSE_TYPE,
|
|
73
74
|
});
|
|
74
75
|
}
|
|
@@ -85,16 +85,17 @@ var FetchRequestBackend = /** @class */ (function () {
|
|
|
85
85
|
};
|
|
86
86
|
FetchRequestBackend.prototype.convertResponse = function (context, response, error) {
|
|
87
87
|
return __awaiter(this, void 0, void 0, function () {
|
|
88
|
-
var data, inferredResponseType, responseType, _a, error_1, status;
|
|
88
|
+
var data, contentType, inferredResponseType, responseType, _a, error_1, status;
|
|
89
89
|
return __generator(this, function (_b) {
|
|
90
90
|
switch (_b.label) {
|
|
91
91
|
case 0:
|
|
92
|
-
|
|
92
|
+
contentType = response.headers.get("Content-Type");
|
|
93
|
+
inferredResponseType = ApiUtils_1.inferResponseType(contentType);
|
|
93
94
|
responseType = error ? inferredResponseType : context.responseType;
|
|
94
95
|
// expand to array buffer once we support that in inferResponseType
|
|
95
96
|
if (inferredResponseType === "text" && context.responseType === "json") {
|
|
96
97
|
throw RequestError_1.convertToRequestError({
|
|
97
|
-
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "'"),
|
|
98
|
+
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "' (from 'Content-Type' of '" + contentType + "')"),
|
|
98
99
|
code: RequestError_1.RequestErrorCode.REQUEST_MISMATCH_RESPONSE_TYPE,
|
|
99
100
|
});
|
|
100
101
|
}
|
package/esm/Requester.js
CHANGED
|
@@ -57,7 +57,7 @@ var locks = {};
|
|
|
57
57
|
var runningOperations = {};
|
|
58
58
|
var MOCK_REQUEST_BACKEND = new MockRequestBackend();
|
|
59
59
|
export var submit = function (host, config, mocking) { return __awaiter(void 0, void 0, void 0, function () {
|
|
60
|
-
var computedConfig, backend, context, key,
|
|
60
|
+
var computedConfig, backend, context, key, lock, lockedContext, response, successEventResult, error_1;
|
|
61
61
|
return __generator(this, function (_a) {
|
|
62
62
|
switch (_a.label) {
|
|
63
63
|
case 0:
|
|
@@ -68,10 +68,6 @@ export var submit = function (host, config, mocking) { return __awaiter(void 0,
|
|
|
68
68
|
}
|
|
69
69
|
context = new RequestContext(backend, host, computedConfig, host.computePath(host.path, config), mocking);
|
|
70
70
|
key = context.key;
|
|
71
|
-
sameRequest = runningOperations[key];
|
|
72
|
-
if (sameRequest) {
|
|
73
|
-
return [2 /*return*/, sameRequest];
|
|
74
|
-
}
|
|
75
71
|
lock = (context.computedConfig || {}).lock;
|
|
76
72
|
if (lock) {
|
|
77
73
|
lockedContext = locks[lock];
|
package/esm/UtilTypes.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Endpoint from "./Endpoint";
|
|
2
|
-
export declare type ResponseOf<E extends Endpoint
|
|
3
|
-
export declare type ParamsOf<E extends Endpoint
|
|
4
|
-
export declare type QueryOf<E extends Endpoint
|
|
5
|
-
export declare type BodyOf<E extends Endpoint
|
|
2
|
+
export declare type ResponseOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<infer R, any, any, any> ? R : never;
|
|
3
|
+
export declare type ParamsOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<any, infer P, any, any> ? P : never;
|
|
4
|
+
export declare type QueryOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<any, any, infer Q, any> ? Q : never;
|
|
5
|
+
export declare type BodyOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<any, any, any, infer B> ? B : never;
|
|
@@ -58,13 +58,14 @@ var AxiosRequestBackend = /** @class */ (function () {
|
|
|
58
58
|
};
|
|
59
59
|
AxiosRequestBackend.prototype.convertResponse = function (context, response) {
|
|
60
60
|
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
-
var inferredResponseType;
|
|
61
|
+
var contentType, inferredResponseType;
|
|
62
62
|
return __generator(this, function (_a) {
|
|
63
|
-
|
|
63
|
+
contentType = response.headers["content-type"];
|
|
64
|
+
inferredResponseType = inferResponseType(contentType);
|
|
64
65
|
// expand to array buffer once we support that in inferResponseType
|
|
65
66
|
if (inferredResponseType === "text" && context.responseType === "json") {
|
|
66
67
|
throw convertToRequestError({
|
|
67
|
-
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "'"),
|
|
68
|
+
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "' (from 'Content-Type' of '" + contentType + "')"),
|
|
68
69
|
code: RequestErrorCode.REQUEST_MISMATCH_RESPONSE_TYPE,
|
|
69
70
|
});
|
|
70
71
|
}
|
|
@@ -83,16 +83,17 @@ var FetchRequestBackend = /** @class */ (function () {
|
|
|
83
83
|
};
|
|
84
84
|
FetchRequestBackend.prototype.convertResponse = function (context, response, error) {
|
|
85
85
|
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
-
var data, inferredResponseType, responseType, _a, error_1, status;
|
|
86
|
+
var data, contentType, inferredResponseType, responseType, _a, error_1, status;
|
|
87
87
|
return __generator(this, function (_b) {
|
|
88
88
|
switch (_b.label) {
|
|
89
89
|
case 0:
|
|
90
|
-
|
|
90
|
+
contentType = response.headers.get("Content-Type");
|
|
91
|
+
inferredResponseType = inferResponseType(contentType);
|
|
91
92
|
responseType = error ? inferredResponseType : context.responseType;
|
|
92
93
|
// expand to array buffer once we support that in inferResponseType
|
|
93
94
|
if (inferredResponseType === "text" && context.responseType === "json") {
|
|
94
95
|
throw convertToRequestError({
|
|
95
|
-
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "'"),
|
|
96
|
+
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "' (from 'Content-Type' of '" + contentType + "')"),
|
|
96
97
|
code: RequestErrorCode.REQUEST_MISMATCH_RESPONSE_TYPE,
|
|
97
98
|
});
|
|
98
99
|
}
|