api-def 0.12.0-alpha.41 → 0.12.0-alpha.43
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/ApiTypes.d.ts +2 -1
- package/cjs/RequestContext.d.ts +2 -2
- package/cjs/RequestError.d.ts +1 -1
- package/cjs/RequestError.js +1 -1
- package/cjs/Requester.js +1 -4
- package/cjs/backend/AxiosRequestBackend.js +1 -0
- package/cjs/backend/FetchRequestBackend.js +1 -0
- package/cjs/backend/MockRequestBackend.js +1 -0
- package/esm/ApiTypes.d.ts +2 -1
- package/esm/RequestContext.d.ts +2 -2
- package/esm/RequestError.d.ts +1 -1
- package/esm/RequestError.js +1 -1
- package/esm/Requester.js +0 -2
- package/esm/backend/AxiosRequestBackend.js +1 -0
- package/esm/backend/FetchRequestBackend.js +1 -0
- package/esm/backend/MockRequestBackend.js +1 -0
- package/package.json +1 -1
package/cjs/ApiTypes.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export interface ApiResponse<T = any> {
|
|
|
16
16
|
readonly data: T;
|
|
17
17
|
readonly headers: Headers;
|
|
18
18
|
readonly state: State;
|
|
19
|
+
readonly stats: RequestStats;
|
|
19
20
|
}
|
|
20
21
|
export type RequestLock = string | false;
|
|
21
22
|
export type QueryStringify = (query: any) => string;
|
|
@@ -87,7 +88,7 @@ export type RequestEventHandlers<R> = {
|
|
|
87
88
|
export type RequestMiddleware<O = undefined> = {
|
|
88
89
|
[key in RequestEvent]?: RequestEventHandler<any> | undefined | false;
|
|
89
90
|
};
|
|
90
|
-
export interface
|
|
91
|
+
export interface RequestStats {
|
|
91
92
|
cached: false | {
|
|
92
93
|
is: true;
|
|
93
94
|
by: "local" | "api";
|
package/cjs/RequestContext.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Api } from "./Api";
|
|
2
2
|
import type { RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
|
|
3
|
-
import type { ApiResponse, Body, ComputedRequestConfig, EventResult, Params, Query, RawHeaders, RequestCacheInfo,
|
|
3
|
+
import type { ApiResponse, Body, ComputedRequestConfig, EventResult, Params, Query, RawHeaders, RequestCacheInfo, RequestEventHandlers, RequestHost, RequestStats, State } from "./ApiTypes";
|
|
4
4
|
import type { EndpointMockingConfig } from "./MockingTypes";
|
|
5
5
|
import type { RequestError } from "./RequestError";
|
|
6
6
|
import type { Validation } from "./Validation";
|
|
@@ -11,7 +11,7 @@ export default class RequestContext<TResponse = any, TParams extends Params | un
|
|
|
11
11
|
private computedPath;
|
|
12
12
|
private computedBaseUrl;
|
|
13
13
|
private computedMethod;
|
|
14
|
-
readonly stats:
|
|
14
|
+
readonly stats: RequestStats;
|
|
15
15
|
private readonly host;
|
|
16
16
|
readonly eventHandlers: RequestEventHandlers<TResponse>;
|
|
17
17
|
readonly backend: RequestBackend;
|
package/cjs/RequestError.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare const RequestErrorCode: {
|
|
|
14
14
|
readonly VALIDATION_RESPONSE_VALIDATE_ERROR: "validation/response-validate-error";
|
|
15
15
|
};
|
|
16
16
|
export type RequestErrorCode = EnumOf<typeof RequestErrorCode>;
|
|
17
|
-
declare const REQUEST_ERROR_SYMBOL
|
|
17
|
+
declare const REQUEST_ERROR_SYMBOL = "isApiDefError";
|
|
18
18
|
export interface RequestError extends Error {
|
|
19
19
|
[REQUEST_ERROR_SYMBOL]: true;
|
|
20
20
|
response: ApiResponse | undefined | null;
|
package/cjs/RequestError.js
CHANGED
|
@@ -13,7 +13,7 @@ exports.RequestErrorCode = {
|
|
|
13
13
|
VALIDATION_BODY_VALIDATE_ERROR: "validation/body-validate-error",
|
|
14
14
|
VALIDATION_RESPONSE_VALIDATE_ERROR: "validation/response-validate-error",
|
|
15
15
|
};
|
|
16
|
-
var REQUEST_ERROR_SYMBOL =
|
|
16
|
+
var REQUEST_ERROR_SYMBOL = "isApiDefError";
|
|
17
17
|
var isRequestError = function (error) {
|
|
18
18
|
if (!error) {
|
|
19
19
|
return false;
|
package/cjs/Requester.js
CHANGED
|
@@ -117,10 +117,7 @@ var makeRequest = function (context) { return __awaiter(void 0, void 0, void 0,
|
|
|
117
117
|
var _a, _b, _c;
|
|
118
118
|
return __generator(this, function (_d) {
|
|
119
119
|
switch (_d.label) {
|
|
120
|
-
case 0:
|
|
121
|
-
// Set start timestamp when request begins
|
|
122
|
-
context.stats.startTimestamp = Date.now();
|
|
123
|
-
return [4 /*yield*/, context.triggerEvent(ApiConstants_1.RequestEvent.BEFORE_SEND)];
|
|
120
|
+
case 0: return [4 /*yield*/, context.triggerEvent(ApiConstants_1.RequestEvent.BEFORE_SEND)];
|
|
124
121
|
case 1:
|
|
125
122
|
beforeSendEventResult = _d.sent();
|
|
126
123
|
if (beforeSendEventResult && beforeSendEventResult.type === ApiConstants_1.EventResultType.RESPOND) {
|
|
@@ -101,6 +101,7 @@ var FetchRequestBackend = /** @class */ (function () {
|
|
|
101
101
|
status: status,
|
|
102
102
|
headers: headers,
|
|
103
103
|
state: context.requestConfig.state,
|
|
104
|
+
stats: context.stats,
|
|
104
105
|
};
|
|
105
106
|
responseType = (_a = context.responseType) !== null && _a !== void 0 ? _a : (0, ApiUtils_1.inferResponseType)(response.headers.get("Content-Type"));
|
|
106
107
|
_b.label = 1;
|
package/esm/ApiTypes.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export interface ApiResponse<T = any> {
|
|
|
16
16
|
readonly data: T;
|
|
17
17
|
readonly headers: Headers;
|
|
18
18
|
readonly state: State;
|
|
19
|
+
readonly stats: RequestStats;
|
|
19
20
|
}
|
|
20
21
|
export type RequestLock = string | false;
|
|
21
22
|
export type QueryStringify = (query: any) => string;
|
|
@@ -87,7 +88,7 @@ export type RequestEventHandlers<R> = {
|
|
|
87
88
|
export type RequestMiddleware<O = undefined> = {
|
|
88
89
|
[key in RequestEvent]?: RequestEventHandler<any> | undefined | false;
|
|
89
90
|
};
|
|
90
|
-
export interface
|
|
91
|
+
export interface RequestStats {
|
|
91
92
|
cached: false | {
|
|
92
93
|
is: true;
|
|
93
94
|
by: "local" | "api";
|
package/esm/RequestContext.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Api } from "./Api";
|
|
2
2
|
import type { RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
|
|
3
|
-
import type { ApiResponse, Body, ComputedRequestConfig, EventResult, Params, Query, RawHeaders, RequestCacheInfo,
|
|
3
|
+
import type { ApiResponse, Body, ComputedRequestConfig, EventResult, Params, Query, RawHeaders, RequestCacheInfo, RequestEventHandlers, RequestHost, RequestStats, State } from "./ApiTypes";
|
|
4
4
|
import type { EndpointMockingConfig } from "./MockingTypes";
|
|
5
5
|
import type { RequestError } from "./RequestError";
|
|
6
6
|
import type { Validation } from "./Validation";
|
|
@@ -11,7 +11,7 @@ export default class RequestContext<TResponse = any, TParams extends Params | un
|
|
|
11
11
|
private computedPath;
|
|
12
12
|
private computedBaseUrl;
|
|
13
13
|
private computedMethod;
|
|
14
|
-
readonly stats:
|
|
14
|
+
readonly stats: RequestStats;
|
|
15
15
|
private readonly host;
|
|
16
16
|
readonly eventHandlers: RequestEventHandlers<TResponse>;
|
|
17
17
|
readonly backend: RequestBackend;
|
package/esm/RequestError.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare const RequestErrorCode: {
|
|
|
14
14
|
readonly VALIDATION_RESPONSE_VALIDATE_ERROR: "validation/response-validate-error";
|
|
15
15
|
};
|
|
16
16
|
export type RequestErrorCode = EnumOf<typeof RequestErrorCode>;
|
|
17
|
-
declare const REQUEST_ERROR_SYMBOL
|
|
17
|
+
declare const REQUEST_ERROR_SYMBOL = "isApiDefError";
|
|
18
18
|
export interface RequestError extends Error {
|
|
19
19
|
[REQUEST_ERROR_SYMBOL]: true;
|
|
20
20
|
response: ApiResponse | undefined | null;
|
package/esm/RequestError.js
CHANGED
|
@@ -10,7 +10,7 @@ export const RequestErrorCode = {
|
|
|
10
10
|
VALIDATION_BODY_VALIDATE_ERROR: "validation/body-validate-error",
|
|
11
11
|
VALIDATION_RESPONSE_VALIDATE_ERROR: "validation/response-validate-error",
|
|
12
12
|
};
|
|
13
|
-
const REQUEST_ERROR_SYMBOL =
|
|
13
|
+
const REQUEST_ERROR_SYMBOL = "isApiDefError";
|
|
14
14
|
export const isRequestError = (error) => {
|
|
15
15
|
if (!error) {
|
|
16
16
|
return false;
|
package/esm/Requester.js
CHANGED
|
@@ -68,8 +68,6 @@ const parseRetryOptions = (retryConfig) => {
|
|
|
68
68
|
};
|
|
69
69
|
const makeRequest = (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
70
|
var _a, _b, _c;
|
|
71
|
-
// Set start timestamp when request begins
|
|
72
|
-
context.stats.startTimestamp = Date.now();
|
|
73
71
|
const beforeSendEventResult = yield context.triggerEvent(RequestEvent.BEFORE_SEND);
|
|
74
72
|
if (beforeSendEventResult && beforeSendEventResult.type === EventResultType.RESPOND) {
|
|
75
73
|
// Calculate duration for early responses
|
|
@@ -45,6 +45,7 @@ export default class FetchRequestBackend {
|
|
|
45
45
|
status: status,
|
|
46
46
|
headers: headers,
|
|
47
47
|
state: context.requestConfig.state,
|
|
48
|
+
stats: context.stats,
|
|
48
49
|
};
|
|
49
50
|
const responseType = (_a = context.responseType) !== null && _a !== void 0 ? _a : inferResponseType(response.headers.get("Content-Type"));
|
|
50
51
|
let text;
|