api-def 0.6.0-alpha6 → 0.6.0-alpha7
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/cjs/ApiUtils.js +1 -0
- package/cjs/UtilTypes.d.ts +5 -0
- package/cjs/UtilTypes.js +2 -0
- package/cjs/backend/AxiosRequestBackend.js +4 -3
- package/cjs/backend/FetchRequestBackend.js +4 -3
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +1 -0
- package/esm/ApiUtils.js +1 -0
- package/esm/UtilTypes.d.ts +5 -0
- package/esm/UtilTypes.js +1 -0
- package/esm/backend/AxiosRequestBackend.js +4 -3
- package/esm/backend/FetchRequestBackend.js +4 -3
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/package.json +1 -1
package/cjs/ApiUtils.js
CHANGED
|
@@ -51,6 +51,7 @@ var isAcceptableStatus = function (status, acceptableStatus) {
|
|
|
51
51
|
exports.isAcceptableStatus = isAcceptableStatus;
|
|
52
52
|
var JSON_CONTENT_TYPES = ["text/json", "application/json"];
|
|
53
53
|
var inferResponseType = function (contentType) {
|
|
54
|
+
console.log(contentType);
|
|
54
55
|
var contentTypePart = contentType === null || contentType === void 0 ? void 0 : contentType.split(";")[0].trim();
|
|
55
56
|
if (contentTypePart && JSON_CONTENT_TYPES.includes(contentTypePart)) {
|
|
56
57
|
return "json";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import Endpoint from "./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;
|
package/cjs/UtilTypes.js
ADDED
|
@@ -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/cjs/index.d.ts
CHANGED
package/cjs/index.js
CHANGED
|
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.LoggingMiddleware = exports.CacheMiddleware = exports.FetchRequestBackend = exports.AxiosRequestBackend = exports.LocaleForageCacheBackend = exports.LocalStorageCacheBackend = exports.setCacheBackend = exports.clearCache = exports.isRequestError = void 0;
|
|
15
15
|
__exportStar(require("./Api"), exports);
|
|
16
16
|
__exportStar(require("./ApiTypes"), exports);
|
|
17
|
+
__exportStar(require("./UtilTypes"), exports);
|
|
17
18
|
__exportStar(require("./ApiConstants"), exports);
|
|
18
19
|
var RequestError_1 = require("./RequestError");
|
|
19
20
|
Object.defineProperty(exports, "isRequestError", { enumerable: true, get: function () { return RequestError_1.isRequestError; } });
|
package/esm/ApiUtils.js
CHANGED
|
@@ -44,6 +44,7 @@ export var isAcceptableStatus = function (status, acceptableStatus) {
|
|
|
44
44
|
};
|
|
45
45
|
var JSON_CONTENT_TYPES = ["text/json", "application/json"];
|
|
46
46
|
export var inferResponseType = function (contentType) {
|
|
47
|
+
console.log(contentType);
|
|
47
48
|
var contentTypePart = contentType === null || contentType === void 0 ? void 0 : contentType.split(";")[0].trim();
|
|
48
49
|
if (contentTypePart && JSON_CONTENT_TYPES.includes(contentTypePart)) {
|
|
49
50
|
return "json";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import Endpoint from "./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;
|
package/esm/UtilTypes.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
}
|
package/esm/index.d.ts
CHANGED
package/esm/index.js
CHANGED