api-def 0.7.4 → 0.8.1

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.
Files changed (49) hide show
  1. package/cjs/Api.js +6 -2
  2. package/cjs/ApiTypes.d.ts +30 -10
  3. package/cjs/ApiTypes.js +2 -0
  4. package/cjs/ApiUtils.js +1 -1
  5. package/cjs/Endpoint.d.ts +3 -3
  6. package/cjs/Endpoint.js +13 -8
  7. package/cjs/QueryHandling.d.ts +3 -0
  8. package/cjs/QueryHandling.js +24 -0
  9. package/cjs/RequestConfig.d.ts +2 -0
  10. package/cjs/RequestConfig.js +74 -0
  11. package/cjs/RequestContext.d.ts +4 -4
  12. package/cjs/RequestContext.js +5 -24
  13. package/cjs/RequestError.js +1 -1
  14. package/cjs/Requester.d.ts +1 -1
  15. package/cjs/Requester.js +2 -2
  16. package/cjs/Utils.js +1 -1
  17. package/cjs/backend/AxiosRequestBackend.js +4 -4
  18. package/cjs/backend/FetchRequestBackend.js +4 -3
  19. package/cjs/backend/MockRequestBackend.js +3 -1
  20. package/esm/Api.js +34 -70
  21. package/esm/ApiConstants.js +5 -5
  22. package/esm/ApiTypes.d.ts +30 -10
  23. package/esm/ApiTypes.js +1 -1
  24. package/esm/ApiUtils.js +12 -13
  25. package/esm/Endpoint.d.ts +3 -3
  26. package/esm/Endpoint.js +42 -74
  27. package/esm/EndpointBuilder.js +14 -16
  28. package/esm/QueryHandling.d.ts +3 -0
  29. package/esm/QueryHandling.js +19 -0
  30. package/esm/RequestConfig.d.ts +2 -0
  31. package/esm/RequestConfig.js +56 -0
  32. package/esm/RequestContext.d.ts +4 -4
  33. package/esm/RequestContext.js +71 -148
  34. package/esm/RequestError.js +7 -7
  35. package/esm/Requester.d.ts +1 -1
  36. package/esm/Requester.js +182 -266
  37. package/esm/TextDecoding.js +20 -20
  38. package/esm/Utils.js +16 -16
  39. package/esm/backend/AxiosRequestBackend.js +34 -67
  40. package/esm/backend/FetchRequestBackend.js +66 -134
  41. package/esm/backend/MockRequestBackend.js +92 -136
  42. package/esm/cache/Caching.js +24 -66
  43. package/esm/cache/LocalForageCacheBackend.js +11 -13
  44. package/esm/cache/LocalStorageCacheBackend.js +19 -62
  45. package/esm/middleware/CacheMiddleware.js +44 -91
  46. package/esm/middleware/LoggingMiddleware.js +36 -39
  47. package/esm/util/retry/index.js +8 -8
  48. package/esm/util/retry/lib/retry.js +11 -22
  49. package/package.json +4 -2
@@ -1,4 +1,4 @@
1
- export var RequestMethod = {
1
+ export const RequestMethod = {
2
2
  /** @deprecated use 'POST' */
3
3
  Post: "post",
4
4
  /** @deprecated use 'GET' */
@@ -9,7 +9,7 @@ export var RequestMethod = {
9
9
  DELETE: "delete",
10
10
  PATCH: "patch",
11
11
  };
12
- export var RequestEvent = {
12
+ export const RequestEvent = {
13
13
  /** @deprecated use 'BEFORE_SEND' */
14
14
  BeforeSend: "beforeSend",
15
15
  /** @deprecated use 'SUCCESS' */
@@ -23,7 +23,7 @@ export var RequestEvent = {
23
23
  ERROR: "error",
24
24
  UNRECOVERABLE_ERROR: "unrecoverableError",
25
25
  };
26
- export var EventResultType = {
26
+ export const EventResultType = {
27
27
  /** @deprecated use 'RESPOND' */
28
28
  Respond: "respond",
29
29
  /** @deprecated use 'RETRY' */
@@ -31,7 +31,7 @@ export var EventResultType = {
31
31
  RESPOND: "respond",
32
32
  RETRY: "retry",
33
33
  };
34
- export var CacheSource = {
34
+ export const CacheSource = {
35
35
  /** @deprecated use 'API' */
36
36
  Api: "api",
37
37
  /** @deprecated use 'LOCAL' */
@@ -39,7 +39,7 @@ export var CacheSource = {
39
39
  API: "api",
40
40
  LOCAL: "local",
41
41
  };
42
- export var ResponseType = {
42
+ export const ResponseType = {
43
43
  /** @deprecated use 'JSON' */
44
44
  Json: "json",
45
45
  /** @deprecated use 'TEXT' */
package/esm/ApiTypes.d.ts CHANGED
@@ -4,20 +4,33 @@ import { CacheSource, EventResultType, RequestEvent, RequestMethod, ResponseType
4
4
  export declare type AcceptableStatus = number | [min: number, max: number];
5
5
  export declare type Headers = Record<string, string | number | boolean | null | undefined>;
6
6
  export declare type Params = string;
7
- export declare type Query = Record<string, any>;
7
+ export declare type Query = string | undefined | Record<string, any>;
8
8
  export declare type Body = string | number | Record<string, any>;
9
9
  export interface ApiResponse<T = any> {
10
- status: number;
11
- data: T;
12
- headers: Record<string, string>;
10
+ readonly method: RequestMethod;
11
+ readonly url: string;
12
+ readonly status: number;
13
+ readonly data: T;
14
+ readonly headers: Record<string, string>;
15
+ }
16
+ export declare type RequestLock = string | false;
17
+ export declare type QueryStringify = (query: any) => string;
18
+ export declare type QueryParse = (query: string) => any;
19
+ interface QueryHandling {
20
+ parse: QueryParse;
21
+ stringify: QueryStringify;
13
22
  }
14
23
  export interface BaseRequestConfig {
15
24
  cache?: number | boolean;
16
- lock?: string | false;
25
+ lock?: RequestLock;
17
26
  retry?: number | false;
18
27
  headers?: Readonly<Headers>;
19
28
  acceptableStatus?: AcceptableStatus[];
20
- queryParser?: (query: any) => string;
29
+ /**
30
+ * @deprecated use `queryHandling.stringify` instead
31
+ **/
32
+ queryParser?: QueryStringify;
33
+ queryHandling?: Partial<QueryHandling>;
21
34
  }
22
35
  export declare type RequestConfig<P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> = (P extends undefined ? {
23
36
  params?: never;
@@ -32,13 +45,20 @@ export declare type RequestConfig<P extends Params | undefined = Params | undefi
32
45
  } : {
33
46
  body: B;
34
47
  }) & BaseRequestConfig;
48
+ export declare const COMPUTED_CONFIG_SYMBOL: unique symbol;
49
+ export declare type ComputedRequestConfig<P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> = Omit<RequestConfig<P, Q, B>, "queryParser" | "query" | "queryHandling"> & {
50
+ [COMPUTED_CONFIG_SYMBOL]: true;
51
+ queryObject: Record<string, any> | undefined;
52
+ queryString: string | undefined;
53
+ queryHandling: QueryHandling;
54
+ };
35
55
  interface BaseEventResult<T extends EventResultType> {
36
56
  type: T;
37
57
  }
38
- export declare type ResponseEventResult<R> = BaseEventResult<typeof EventResultType.Respond> & {
58
+ export declare type ResponseEventResult<R> = BaseEventResult<"respond"> & {
39
59
  response: ApiResponse<R>;
40
60
  };
41
- export declare type RetryEventResult<R> = BaseEventResult<typeof EventResultType.Retry>;
61
+ export declare type RetryEventResult<R> = BaseEventResult<"retry">;
42
62
  export declare type EventResult<R> = ResponseEventResult<R> | RetryEventResult<R>;
43
63
  export declare type RequestEventHandler<R> = (context: RequestContext<R>) => EventResult<R> | void | Promise<EventResult<R> | void>;
44
64
  export declare type RequestEventHandlers<R> = {
@@ -59,8 +79,8 @@ export interface RequestHost {
59
79
  readonly api: Api;
60
80
  readonly baseUrl: string;
61
81
  readonly path: string;
62
- readonly responseType: ResponseType;
63
- computeConfig<P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined>(config: RequestConfig<P, Q, B>): RequestConfig<P, Q, B>;
82
+ readonly responseType: ResponseType | undefined;
83
+ computeConfig<P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined>(config: RequestConfig<P, Q, B>): ComputedRequestConfig<P, Q, B>;
64
84
  computePath(path: string, config: RequestConfig): string;
65
85
  }
66
86
  export interface CancelledRequestError extends Error {
package/esm/ApiTypes.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export const COMPUTED_CONFIG_SYMBOL = Symbol("computed");
package/esm/ApiUtils.js CHANGED
@@ -1,19 +1,18 @@
1
- export var isCancelledError = function (error) {
1
+ export const isCancelledError = (error) => {
2
2
  return "isCancelledRequest" in error;
3
3
  };
4
- export var isNetworkError = function (error) {
4
+ export const isNetworkError = (error) => {
5
5
  var _a;
6
6
  return (error.name === "NetworkError" ||
7
7
  error.message === "Network Error" ||
8
8
  ((_a = error.constructor) === null || _a === void 0 ? void 0 : _a.name) === "NetworkError");
9
9
  };
10
- var DEFAULT_ACCEPTABLE_STATUS = [[200, 299], 304];
11
- export var isAcceptableStatus = function (status, acceptableStatus) {
12
- var acceptable = acceptableStatus !== null && acceptableStatus !== void 0 ? acceptableStatus : DEFAULT_ACCEPTABLE_STATUS;
13
- for (var _i = 0, acceptable_1 = acceptable; _i < acceptable_1.length; _i++) {
14
- var cmpStatus = acceptable_1[_i];
10
+ const DEFAULT_ACCEPTABLE_STATUS = [[200, 299], 304];
11
+ export const isAcceptableStatus = (status, acceptableStatus) => {
12
+ const acceptable = acceptableStatus !== null && acceptableStatus !== void 0 ? acceptableStatus : DEFAULT_ACCEPTABLE_STATUS;
13
+ for (const cmpStatus of acceptable) {
15
14
  if (Array.isArray(cmpStatus)) {
16
- var min = cmpStatus[0], max = cmpStatus[1];
15
+ const [min, max] = cmpStatus;
17
16
  if (status >= min && status <= max) {
18
17
  return (true);
19
18
  }
@@ -26,11 +25,11 @@ export var isAcceptableStatus = function (status, acceptableStatus) {
26
25
  }
27
26
  return (false);
28
27
  };
29
- var TEXT_CONTENT_TYPES = ["text/plain"];
30
- var JSON_CONTENT_TYPES = ["text/json", "application/json"];
31
- var ARRAY_BUFFER_CONTENT_TYPES = ["application/octet-stream"];
32
- export var inferResponseType = function (contentType) {
33
- var contentTypePart = contentType === null || contentType === void 0 ? void 0 : contentType.split(";")[0].trim();
28
+ const TEXT_CONTENT_TYPES = ["text/plain", "text/html", "text/xml", "application/xml"];
29
+ const JSON_CONTENT_TYPES = ["text/json", "application/json"];
30
+ const ARRAY_BUFFER_CONTENT_TYPES = ["application/octet-stream"];
31
+ export const inferResponseType = (contentType) => {
32
+ const contentTypePart = contentType === null || contentType === void 0 ? void 0 : contentType.split(";")[0].trim();
34
33
  if (contentTypePart) {
35
34
  if (TEXT_CONTENT_TYPES.includes(contentTypePart)) {
36
35
  return "text";
package/esm/Endpoint.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Api } from "./Api";
2
- import { ApiResponse, BaseRequestConfig, Body, Params, Query, RequestConfig, RequestHost } from "./ApiTypes";
2
+ import { ApiResponse, BaseRequestConfig, Body, ComputedRequestConfig, Params, Query, RequestConfig, RequestHost } from "./ApiTypes";
3
3
  import * as Mocking from "./MockingTypes";
4
4
  import { RequestMethod, ResponseType } from "./ApiConstants";
5
5
  export interface EndpointConfig<R, P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined> {
@@ -37,11 +37,11 @@ export default class Endpoint<R = any, P extends Params | undefined = Params | u
37
37
  readonly description?: string;
38
38
  readonly path: string;
39
39
  readonly config?: BaseRequestConfig;
40
- readonly responseType: ResponseType;
40
+ readonly responseType: ResponseType | undefined;
41
41
  readonly mocking?: Mocking.EndpointMockingConfig<R, P, Q, B>;
42
42
  constructor(api: Api, info: EndpointConfig<R, P, Q, B>);
43
43
  submit(config: RequestConfig<P, Q, B>): Promise<ApiResponse<R>>;
44
44
  computePath(path: string, request: RequestConfig): string;
45
45
  get baseUrl(): string;
46
- computeConfig<P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined>(config: RequestConfig<P, Q, B>): RequestConfig<P, Q, B>;
46
+ computeConfig<P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined>(config: RequestConfig<P, Q, B>): ComputedRequestConfig<P, Q, B>;
47
47
  }
package/esm/Endpoint.js CHANGED
@@ -7,38 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
10
  import * as Requester from "./Requester";
11
+ import { COMPUTED_CONFIG_SYMBOL, } from "./ApiTypes";
38
12
  import * as Utils from "./Utils";
39
- import { ResponseType } from "./ApiConstants";
40
- var Endpoint = /** @class */ (function () {
41
- function Endpoint(api, info) {
13
+ import { computeRequestConfig } from "./RequestConfig";
14
+ export default class Endpoint {
15
+ constructor(api, info) {
42
16
  this.api = api;
43
17
  this.id = info.id;
44
18
  this.method = info.method;
@@ -46,60 +20,54 @@ var Endpoint = /** @class */ (function () {
46
20
  this.description = info.description;
47
21
  this.path = info.path;
48
22
  this.config = info.config;
49
- this.responseType = info.responseType || ResponseType.Json;
23
+ this.responseType = info.responseType;
50
24
  this.mocking = info.mocking;
51
25
  }
52
- Endpoint.prototype.submit = function (config) {
26
+ submit(config) {
53
27
  var _a, _b;
54
- return __awaiter(this, void 0, void 0, function () {
55
- var mock, apiMocking, mockingEnabled;
56
- return __generator(this, function (_c) {
57
- mock = false;
58
- apiMocking = this.api.mocking;
59
- if (apiMocking) {
60
- mockingEnabled = (_a = (typeof apiMocking.enabled === "function" ? apiMocking.enabled() : apiMocking.enabled)) !== null && _a !== void 0 ? _a : false;
61
- if (mockingEnabled) {
62
- if (!((_b = this.mocking) === null || _b === void 0 ? void 0 : _b.handler)) {
63
- throw new Error("[api-def] Endpoint for '".concat(this.path, "' has no mocking"));
64
- }
65
- mock = true;
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ let mock = false;
30
+ const apiMocking = this.api.mocking;
31
+ if (apiMocking) {
32
+ const mockingEnabled = (_a = (typeof apiMocking.enabled === "function" ? apiMocking.enabled() : apiMocking.enabled)) !== null && _a !== void 0 ? _a : false;
33
+ if (mockingEnabled) {
34
+ if (!((_b = this.mocking) === null || _b === void 0 ? void 0 : _b.handler)) {
35
+ throw new Error(`[api-def] Endpoint for '${this.path}' has no mocking`);
66
36
  }
37
+ mock = true;
67
38
  }
68
- return [2 /*return*/, Requester.submit(this, config, mock ? this.mocking : null)];
69
- });
39
+ }
40
+ return Requester.submit(this, config, mock ? this.mocking : null);
70
41
  });
71
- };
72
- Endpoint.prototype.computePath = function (path, request) {
73
- var computedPath = path.startsWith("/") ? path : "/".concat(path);
42
+ }
43
+ computePath(path, request) {
44
+ let computedPath = path.startsWith("/") ? path : `/${path}`;
74
45
  if (request.params) {
75
- var keys = Object.keys(request.params);
76
- for (var i = 0; i < keys.length; i++) {
77
- var argName = keys[i];
78
- computedPath = computedPath.replace(":".concat(argName), request.params[argName]);
46
+ const keys = Object.keys(request.params);
47
+ for (let i = 0; i < keys.length; i++) {
48
+ const argName = keys[i];
49
+ computedPath = computedPath.replace(`:${argName}`, request.params[argName]);
79
50
  }
80
51
  }
81
52
  if (computedPath.includes(":")) {
82
- throw new Error("[api-def] Not all path params have been resolved: '".concat(computedPath, "'"));
53
+ throw new Error(`[api-def] Not all path params have been resolved: '${computedPath}'`);
83
54
  }
84
55
  return computedPath;
85
- };
86
- Object.defineProperty(Endpoint.prototype, "baseUrl", {
87
- get: function () {
88
- return this.api.baseUrl;
89
- },
90
- enumerable: false,
91
- configurable: true
92
- });
93
- Endpoint.prototype.computeConfig = function (config) {
94
- var apiDefaults = this.api.getConfig();
95
- var computedConfig = Utils.assign({}, apiDefaults, this.config, config);
96
- // merge other values
97
- for (var _i = 0, _a = ["headers"]; _i < _a.length; _i++) {
98
- var key = _a[_i];
99
- computedConfig[key] = Utils.assign({}, apiDefaults[key], this.config ? this.config[key] : undefined, config[key]);
100
- }
56
+ }
57
+ get baseUrl() {
58
+ return this.api.baseUrl;
59
+ }
60
+ computeConfig(config) {
61
+ const apiDefaults = this.api.getConfig();
62
+ const computedConfig = Utils.assign({
63
+ [COMPUTED_CONFIG_SYMBOL]: true,
64
+ }, apiDefaults, this.config, config);
65
+ return computeRequestConfig([
66
+ apiDefaults,
67
+ this.config,
68
+ config,
69
+ ]);
70
+ delete computedConfig.queryParser;
101
71
  return computedConfig;
102
- };
103
- return Endpoint;
104
- }());
105
- export default Endpoint;
72
+ }
73
+ }
@@ -1,25 +1,23 @@
1
1
  import Endpoint from "./Endpoint";
2
- var EndpointBuilder = /** @class */ (function () {
3
- function EndpointBuilder(api) {
2
+ export default class EndpointBuilder {
3
+ constructor(api) {
4
4
  this.api = api;
5
5
  }
6
- EndpointBuilder.prototype.queryOf = function () {
6
+ queryOf() {
7
7
  return this;
8
- };
9
- EndpointBuilder.prototype.paramsOf = function () {
8
+ }
9
+ paramsOf() {
10
10
  return this;
11
- };
12
- EndpointBuilder.prototype.bodyOf = function () {
11
+ }
12
+ bodyOf() {
13
13
  return this;
14
- };
15
- EndpointBuilder.prototype.responseOf = function () {
14
+ }
15
+ responseOf() {
16
16
  return this;
17
- };
18
- EndpointBuilder.prototype.build = function (config) {
19
- var endpoint = new Endpoint(this.api, config);
17
+ }
18
+ build(config) {
19
+ const endpoint = new Endpoint(this.api, config);
20
20
  this.api.endpoints[endpoint.id] = endpoint;
21
21
  return endpoint;
22
- };
23
- return EndpointBuilder;
24
- }());
25
- export default EndpointBuilder;
22
+ }
23
+ }
@@ -0,0 +1,3 @@
1
+ import { QueryStringify } from "./ApiTypes";
2
+ export declare const DEFAULT_QUERY_STRINGIFY: QueryStringify;
3
+ export declare const DEFAULT_QUERY_PARSE: (queryString: string) => Record<string, any>;
@@ -0,0 +1,19 @@
1
+ export const DEFAULT_QUERY_STRINGIFY = (query) => {
2
+ var _a, _b;
3
+ const queryStrings = [];
4
+ const queryKeys = Object.keys(query);
5
+ for (let i = 0; i < queryKeys.length; i++) {
6
+ const key = queryKeys[i];
7
+ queryStrings.push(`${key}=${(_b = (_a = query[key]) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ""}`);
8
+ }
9
+ return queryStrings.join("&");
10
+ };
11
+ export const DEFAULT_QUERY_PARSE = (queryString) => {
12
+ const query = {};
13
+ const queryStrings = queryString.split("&");
14
+ for (let i = 0; i < queryStrings.length; i++) {
15
+ const [key, value] = queryStrings[i].split("=");
16
+ query[key] = !(value === null || value === void 0 ? void 0 : value.length) ? true : value;
17
+ }
18
+ return query;
19
+ };
@@ -0,0 +1,2 @@
1
+ import { BaseRequestConfig, Body, ComputedRequestConfig, Query, RequestConfig } from "./ApiTypes";
2
+ export declare const computeRequestConfig: <P extends string | undefined, Q extends Query, B extends Body | undefined>(configs: (BaseRequestConfig | RequestConfig<P, Q, B> | undefined)[]) => ComputedRequestConfig<P, Q, B>;
@@ -0,0 +1,56 @@
1
+ import { COMPUTED_CONFIG_SYMBOL, } from "./ApiTypes";
2
+ import * as Utils from "./Utils";
3
+ import { DEFAULT_QUERY_PARSE, DEFAULT_QUERY_STRINGIFY } from "./QueryHandling";
4
+ const MERGED_CONFIG_KEYS = ["headers"];
5
+ export const computeRequestConfig = (configs) => {
6
+ var _a, _b;
7
+ const computedConfig = Utils.assign({
8
+ [COMPUTED_CONFIG_SYMBOL]: true,
9
+ }, ...configs);
10
+ // merge other values
11
+ for (const key of MERGED_CONFIG_KEYS) {
12
+ computedConfig[key] = Utils.assign({}, ...configs.reduce((acc, config) => {
13
+ if (config === null || config === void 0 ? void 0 : config[key]) {
14
+ acc.push(config[key]);
15
+ }
16
+ return acc;
17
+ }, []));
18
+ }
19
+ computedConfig.queryHandling = {
20
+ parse: ((_a = computedConfig.queryHandling) === null || _a === void 0 ? void 0 : _a.parse) || DEFAULT_QUERY_PARSE,
21
+ stringify: ((_b = computedConfig.queryHandling) === null || _b === void 0 ? void 0 : _b.stringify) || computedConfig.queryParser || DEFAULT_QUERY_STRINGIFY,
22
+ };
23
+ delete computedConfig.queryParser;
24
+ const query = computedConfig.query;
25
+ let queryString;
26
+ let queryObject;
27
+ if (query) {
28
+ Object.defineProperty(computedConfig, "queryString", {
29
+ get() {
30
+ if (queryString) {
31
+ return queryString;
32
+ }
33
+ if (typeof query === "string") {
34
+ return queryString = query;
35
+ }
36
+ return queryString = computedConfig.queryHandling.stringify(query);
37
+ },
38
+ });
39
+ Object.defineProperty(computedConfig, "queryObject", {
40
+ get() {
41
+ if (queryObject) {
42
+ return queryObject;
43
+ }
44
+ if (typeof query === "string") {
45
+ return queryObject = computedConfig.queryHandling.parse(query);
46
+ }
47
+ return queryObject = query;
48
+ },
49
+ set(value) {
50
+ queryObject = value;
51
+ queryString = computedConfig.queryHandling.stringify(value);
52
+ },
53
+ });
54
+ }
55
+ return computedConfig;
56
+ };
@@ -1,4 +1,4 @@
1
- import { ApiResponse, Body, EventResult, Headers, Params, Query, RequestCacheInfo, RequestConfig, RequestContextStats, RequestEventHandlers, RequestHost } from "./ApiTypes";
1
+ import { ApiResponse, Body, ComputedRequestConfig, EventResult, Headers, Params, Query, RequestCacheInfo, RequestContextStats, RequestEventHandlers, RequestHost } from "./ApiTypes";
2
2
  import { Api } from "./Api";
3
3
  import { RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
4
4
  import { EndpointMockingConfig } from "./MockingTypes";
@@ -17,14 +17,14 @@ export default class RequestContext<R = any, P extends Params | undefined = Para
17
17
  error: RequestError | null;
18
18
  readonly cacheInfo: RequestCacheInfo;
19
19
  cancelled: boolean;
20
- readonly computedConfig: RequestConfig<P, Q, B>;
20
+ readonly computedConfig: ComputedRequestConfig<P, Q, B>;
21
21
  readonly mocking: EndpointMockingConfig<R, P, Q, B> | null | undefined;
22
22
  private parsedBody;
23
- constructor(backend: RequestBackend, host: RequestHost, config: RequestConfig<P, Q, B>, computedPath: string, mocking: EndpointMockingConfig<R, P, Q, B> | null | undefined);
23
+ constructor(backend: RequestBackend, host: RequestHost, config: ComputedRequestConfig<P, Q, B>, computedPath: string, mocking: EndpointMockingConfig<R, P, Q, B> | null | undefined);
24
24
  get method(): RequestMethod;
25
25
  get api(): Api;
26
26
  get baseUrl(): string;
27
- get responseType(): ResponseType;
27
+ get responseType(): ResponseType | undefined;
28
28
  private initMiddleware;
29
29
  private generateKey;
30
30
  updateHeaders(newHeaders: Headers): this;