api-def 0.9.1 → 0.9.2

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 (121) hide show
  1. package/cjs/Api.d.ts +35 -35
  2. package/cjs/Api.js +140 -144
  3. package/cjs/ApiConstants.d.ts +58 -58
  4. package/cjs/ApiConstants.js +55 -55
  5. package/cjs/ApiTypes.d.ts +103 -103
  6. package/cjs/ApiTypes.js +4 -4
  7. package/cjs/ApiUtils.d.ts +6 -6
  8. package/cjs/ApiUtils.js +51 -53
  9. package/cjs/Endpoint.d.ts +52 -52
  10. package/cjs/Endpoint.js +104 -108
  11. package/cjs/EndpointBuilder.d.ts +14 -14
  12. package/cjs/EndpointBuilder.js +46 -46
  13. package/cjs/MockingTypes.d.ts +30 -30
  14. package/cjs/MockingTypes.js +2 -2
  15. package/cjs/QueryHandling.d.ts +3 -3
  16. package/cjs/QueryHandling.js +24 -24
  17. package/cjs/RequestConfig.d.ts +2 -2
  18. package/cjs/RequestConfig.js +74 -74
  19. package/cjs/RequestContext.d.ts +48 -48
  20. package/cjs/RequestContext.js +235 -238
  21. package/cjs/RequestError.d.ts +30 -30
  22. package/cjs/RequestError.js +47 -47
  23. package/cjs/Requester.d.ts +3 -3
  24. package/cjs/Requester.js +335 -336
  25. package/cjs/TextDecoding.d.ts +1 -1
  26. package/cjs/TextDecoding.js +152 -139
  27. package/cjs/UtilTypes.d.ts +5 -5
  28. package/cjs/UtilTypes.js +2 -2
  29. package/cjs/Utils.d.ts +15 -15
  30. package/cjs/Utils.js +79 -77
  31. package/cjs/Validation.d.ts +8 -8
  32. package/cjs/Validation.js +2 -2
  33. package/cjs/backend/AxiosRequestBackend.d.ts +13 -13
  34. package/cjs/backend/AxiosRequestBackend.js +99 -99
  35. package/cjs/backend/FetchRequestBackend.d.ts +15 -15
  36. package/cjs/backend/FetchRequestBackend.js +202 -202
  37. package/cjs/backend/MockRequestBackend.d.ts +11 -11
  38. package/cjs/backend/MockRequestBackend.js +164 -164
  39. package/cjs/backend/RequestBackend.d.ts +19 -19
  40. package/cjs/backend/RequestBackend.js +2 -2
  41. package/cjs/cache/CacheBackend.d.ts +6 -6
  42. package/cjs/cache/CacheBackend.js +2 -2
  43. package/cjs/cache/Caching.d.ts +10 -10
  44. package/cjs/cache/Caching.js +88 -88
  45. package/cjs/cache/LocalForageCacheBackend.d.ts +9 -9
  46. package/cjs/cache/LocalForageCacheBackend.js +24 -24
  47. package/cjs/cache/LocalStorageCacheBackend.d.ts +7 -7
  48. package/cjs/cache/LocalStorageCacheBackend.js +77 -77
  49. package/cjs/index.d.ts +13 -13
  50. package/cjs/index.js +41 -41
  51. package/cjs/middleware/CacheMiddleware.d.ts +7 -7
  52. package/cjs/middleware/CacheMiddleware.js +107 -107
  53. package/cjs/middleware/LoggingMiddleware.d.ts +6 -6
  54. package/cjs/middleware/LoggingMiddleware.js +82 -88
  55. package/cjs/util/retry/index.d.ts +3 -3
  56. package/cjs/util/retry/index.js +52 -52
  57. package/cjs/util/retry/lib/retry.d.ts +3 -3
  58. package/cjs/util/retry/lib/retry.js +50 -54
  59. package/cjs/util/retry/lib/retryOperation.d.ts +27 -27
  60. package/cjs/util/retry/lib/retryOperation.js +130 -134
  61. package/esm/Api.d.ts +35 -35
  62. package/esm/Api.js +92 -98
  63. package/esm/ApiConstants.d.ts +58 -58
  64. package/esm/ApiConstants.js +52 -52
  65. package/esm/ApiTypes.d.ts +103 -103
  66. package/esm/ApiTypes.js +1 -1
  67. package/esm/ApiUtils.d.ts +6 -6
  68. package/esm/ApiUtils.js +43 -45
  69. package/esm/Endpoint.d.ts +52 -52
  70. package/esm/Endpoint.js +66 -70
  71. package/esm/EndpointBuilder.d.ts +14 -14
  72. package/esm/EndpointBuilder.js +31 -31
  73. package/esm/MockingTypes.d.ts +30 -30
  74. package/esm/MockingTypes.js +1 -1
  75. package/esm/QueryHandling.d.ts +3 -3
  76. package/esm/QueryHandling.js +19 -19
  77. package/esm/RequestConfig.d.ts +2 -2
  78. package/esm/RequestConfig.js +56 -56
  79. package/esm/RequestContext.d.ts +48 -48
  80. package/esm/RequestContext.js +167 -170
  81. package/esm/RequestError.d.ts +30 -30
  82. package/esm/RequestError.js +42 -42
  83. package/esm/Requester.d.ts +3 -3
  84. package/esm/Requester.js +252 -253
  85. package/esm/TextDecoding.d.ts +1 -1
  86. package/esm/TextDecoding.js +148 -135
  87. package/esm/UtilTypes.d.ts +5 -5
  88. package/esm/UtilTypes.js +1 -1
  89. package/esm/Utils.d.ts +15 -15
  90. package/esm/Utils.js +66 -68
  91. package/esm/Validation.d.ts +8 -8
  92. package/esm/Validation.js +1 -1
  93. package/esm/backend/AxiosRequestBackend.d.ts +13 -13
  94. package/esm/backend/AxiosRequestBackend.js +62 -62
  95. package/esm/backend/FetchRequestBackend.d.ts +15 -15
  96. package/esm/backend/FetchRequestBackend.js +136 -136
  97. package/esm/backend/MockRequestBackend.d.ts +11 -11
  98. package/esm/backend/MockRequestBackend.js +116 -116
  99. package/esm/backend/RequestBackend.d.ts +19 -19
  100. package/esm/backend/RequestBackend.js +1 -1
  101. package/esm/cache/CacheBackend.d.ts +6 -6
  102. package/esm/cache/CacheBackend.js +1 -1
  103. package/esm/cache/Caching.d.ts +10 -10
  104. package/esm/cache/Caching.js +39 -39
  105. package/esm/cache/LocalForageCacheBackend.d.ts +9 -9
  106. package/esm/cache/LocalForageCacheBackend.js +20 -20
  107. package/esm/cache/LocalStorageCacheBackend.d.ts +7 -7
  108. package/esm/cache/LocalStorageCacheBackend.js +32 -32
  109. package/esm/index.d.ts +13 -13
  110. package/esm/index.js +14 -15
  111. package/esm/middleware/CacheMiddleware.d.ts +7 -7
  112. package/esm/middleware/CacheMiddleware.js +58 -58
  113. package/esm/middleware/LoggingMiddleware.d.ts +6 -6
  114. package/esm/middleware/LoggingMiddleware.js +77 -83
  115. package/esm/util/retry/index.d.ts +3 -3
  116. package/esm/util/retry/index.js +50 -50
  117. package/esm/util/retry/lib/retry.d.ts +3 -3
  118. package/esm/util/retry/lib/retry.js +35 -39
  119. package/esm/util/retry/lib/retryOperation.d.ts +27 -27
  120. package/esm/util/retry/lib/retryOperation.js +126 -132
  121. package/package.json +12 -32
package/cjs/ApiTypes.d.ts CHANGED
@@ -1,103 +1,103 @@
1
- import RequestContext from "./RequestContext";
2
- import { Api } from "./Api";
3
- import { CacheSource, EventResultType, RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
4
- import RequestBackend from "./backend/RequestBackend";
5
- import { Validation } from "./Validation";
6
- export declare type AcceptableStatus = number | [min: number, max: number];
7
- export declare type Headers = Record<string, string | number | boolean | null | undefined>;
8
- export declare type Params = string;
9
- export declare type Query = string | undefined | Record<string, any>;
10
- export declare type Body = string | number | Record<string, any>;
11
- export interface ApiResponse<T = any> {
12
- readonly method: RequestMethod;
13
- readonly url: string;
14
- readonly status: number;
15
- readonly data: T;
16
- readonly headers: Record<string, string>;
17
- }
18
- export declare type RequestLock = string | false;
19
- export declare type QueryStringify = (query: any) => string;
20
- export declare type QueryParse = (query: string) => any;
21
- interface QueryHandling {
22
- parse: QueryParse;
23
- stringify: QueryStringify;
24
- }
25
- export interface RetryOptions {
26
- maxAttempts: number;
27
- shouldRetry?: (error: Error) => boolean;
28
- minDelay?: number;
29
- maxDelay?: number;
30
- }
31
- export interface BaseRequestConfig {
32
- cache?: number | boolean;
33
- lock?: RequestLock;
34
- retry?: number | false | RetryOptions;
35
- headers?: Readonly<Headers>;
36
- acceptableStatus?: AcceptableStatus[];
37
- /**
38
- * @deprecated use `queryHandling.stringify` instead
39
- **/
40
- queryParser?: QueryStringify;
41
- queryHandling?: Partial<QueryHandling>;
42
- }
43
- 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 ? {
44
- params?: never;
45
- } : {
46
- params: Record<P extends Params ? P : never, string>;
47
- }) & (Q extends undefined ? {
48
- query?: never;
49
- } : {
50
- query: Q;
51
- }) & (B extends undefined ? {
52
- body?: never;
53
- } : {
54
- body: B;
55
- }) & BaseRequestConfig;
56
- export declare const COMPUTED_CONFIG_SYMBOL: unique symbol;
57
- 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"> & {
58
- [COMPUTED_CONFIG_SYMBOL]: true;
59
- queryObject: Record<string, any> | undefined;
60
- queryString: string | undefined;
61
- queryHandling: QueryHandling;
62
- };
63
- interface BaseEventResult<T extends EventResultType> {
64
- type: T;
65
- }
66
- export declare type ResponseEventResult<R> = BaseEventResult<"respond"> & {
67
- response: ApiResponse<R>;
68
- };
69
- export declare type RetryEventResult<R> = BaseEventResult<"retry">;
70
- export declare type EventResult<R> = ResponseEventResult<R> | RetryEventResult<R>;
71
- export declare type RequestEventHandler<R> = (context: RequestContext<R>) => EventResult<R> | void | Promise<EventResult<R> | void>;
72
- export declare type RequestEventHandlers<R> = {
73
- [key in RequestEvent]?: Array<RequestEventHandler<R>>;
74
- };
75
- export declare type RequestMiddleware<O = undefined> = {
76
- [key in RequestEvent]?: RequestEventHandler<any> | undefined | false;
77
- };
78
- export interface RequestContextStats {
79
- cached: false | {
80
- is: true;
81
- by: "local" | "api";
82
- };
83
- attempt: number;
84
- }
85
- export interface RequestHost {
86
- readonly method: RequestMethod;
87
- readonly api: Api;
88
- readonly baseUrl: string;
89
- readonly path: string;
90
- readonly responseType: ResponseType | undefined;
91
- readonly validation: Validation;
92
- computeConfig<P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined>(config: RequestConfig<P, Q, B>): ComputedRequestConfig<P, Q, B>;
93
- computePath(path: string, config: RequestConfig): string;
94
- getRequestBackend(): RequestBackend;
95
- }
96
- export interface CancelledRequestError extends Error {
97
- isCancelledRequest: true;
98
- }
99
- export interface RequestCacheInfo {
100
- cached: boolean;
101
- source: CacheSource | null;
102
- }
103
- export {};
1
+ import { Api } from "./Api";
2
+ import { CacheSource, EventResultType, RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
3
+ import RequestContext from "./RequestContext";
4
+ import { Validation } from "./Validation";
5
+ import RequestBackend from "./backend/RequestBackend";
6
+ export type AcceptableStatus = number | [min: number, max: number];
7
+ export type Headers = Record<string, string | number | boolean | null | undefined>;
8
+ export type Params = string;
9
+ export type Query = string | undefined | Record<string, any>;
10
+ export type Body = string | number | Record<string, any>;
11
+ export interface ApiResponse<T = any> {
12
+ readonly method: RequestMethod;
13
+ readonly url: string;
14
+ readonly status: number;
15
+ readonly data: T;
16
+ readonly headers: Record<string, string>;
17
+ }
18
+ export type RequestLock = string | false;
19
+ export type QueryStringify = (query: any) => string;
20
+ export type QueryParse = (query: string) => any;
21
+ interface QueryHandling {
22
+ parse: QueryParse;
23
+ stringify: QueryStringify;
24
+ }
25
+ export interface RetryOptions {
26
+ maxAttempts: number;
27
+ shouldRetry?: (error: Error) => boolean;
28
+ minDelay?: number;
29
+ maxDelay?: number;
30
+ }
31
+ export interface BaseRequestConfig {
32
+ cache?: number | boolean;
33
+ lock?: RequestLock;
34
+ retry?: number | false | RetryOptions;
35
+ headers?: Readonly<Headers>;
36
+ acceptableStatus?: AcceptableStatus[];
37
+ /**
38
+ * @deprecated use `queryHandling.stringify` instead
39
+ **/
40
+ queryParser?: QueryStringify;
41
+ queryHandling?: Partial<QueryHandling>;
42
+ }
43
+ export type RequestConfig<P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> = (P extends undefined ? {
44
+ params?: never;
45
+ } : {
46
+ params: Record<P extends Params ? P : never, string>;
47
+ }) & (Q extends undefined ? {
48
+ query?: never;
49
+ } : {
50
+ query: Q;
51
+ }) & (B extends undefined ? {
52
+ body?: never;
53
+ } : {
54
+ body: B;
55
+ }) & BaseRequestConfig;
56
+ export declare const COMPUTED_CONFIG_SYMBOL: unique symbol;
57
+ export 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"> & {
58
+ [COMPUTED_CONFIG_SYMBOL]: true;
59
+ queryObject: Record<string, any> | undefined;
60
+ queryString: string | undefined;
61
+ queryHandling: QueryHandling;
62
+ };
63
+ interface BaseEventResult<T extends EventResultType> {
64
+ type: T;
65
+ }
66
+ export type ResponseEventResult<R> = BaseEventResult<"respond"> & {
67
+ response: ApiResponse<R>;
68
+ };
69
+ export type RetryEventResult<R> = BaseEventResult<"retry">;
70
+ export type EventResult<R> = ResponseEventResult<R> | RetryEventResult<R>;
71
+ export type RequestEventHandler<R> = (context: RequestContext<R>) => EventResult<R> | void | Promise<EventResult<R> | void>;
72
+ export type RequestEventHandlers<R> = {
73
+ [key in RequestEvent]?: Array<RequestEventHandler<R>>;
74
+ };
75
+ export type RequestMiddleware<O = undefined> = {
76
+ [key in RequestEvent]?: RequestEventHandler<any> | undefined | false;
77
+ };
78
+ export interface RequestContextStats {
79
+ cached: false | {
80
+ is: true;
81
+ by: "local" | "api";
82
+ };
83
+ attempt: number;
84
+ }
85
+ export interface RequestHost {
86
+ readonly method: RequestMethod;
87
+ readonly api: Api;
88
+ readonly baseUrl: string;
89
+ readonly path: string;
90
+ readonly responseType: ResponseType | undefined;
91
+ readonly validation: Validation;
92
+ computeConfig<P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined>(config: RequestConfig<P, Q, B>): ComputedRequestConfig<P, Q, B>;
93
+ computePath(path: string, config: RequestConfig): string;
94
+ getRequestBackend(): RequestBackend;
95
+ }
96
+ export interface CancelledRequestError extends Error {
97
+ isCancelledRequest: true;
98
+ }
99
+ export interface RequestCacheInfo {
100
+ cached: boolean;
101
+ source: CacheSource | null;
102
+ }
103
+ export {};
package/cjs/ApiTypes.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.COMPUTED_CONFIG_SYMBOL = void 0;
4
- exports.COMPUTED_CONFIG_SYMBOL = Symbol("computed");
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.COMPUTED_CONFIG_SYMBOL = void 0;
4
+ exports.COMPUTED_CONFIG_SYMBOL = Symbol("computed");
package/cjs/ApiUtils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { AcceptableStatus, CancelledRequestError } from "./ApiTypes";
2
- import { ResponseType } from "./ApiConstants";
3
- export declare const isCancelledError: (error: Error) => error is CancelledRequestError;
4
- export declare const isNetworkError: (error: Error) => boolean;
5
- export declare const isAcceptableStatus: (status: number, acceptableStatus?: AcceptableStatus[]) => boolean;
6
- export declare const inferResponseType: (contentType: string | null | undefined) => ResponseType;
1
+ import { ResponseType } from "./ApiConstants";
2
+ import { AcceptableStatus, CancelledRequestError } from "./ApiTypes";
3
+ export declare const isCancelledError: (error: Error) => error is CancelledRequestError;
4
+ export declare const isNetworkError: (error: Error) => boolean;
5
+ export declare const isAcceptableStatus: (status: number, acceptableStatus?: AcceptableStatus[]) => boolean;
6
+ export declare const inferResponseType: (contentType: string | null | undefined) => ResponseType;
package/cjs/ApiUtils.js CHANGED
@@ -1,53 +1,51 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.inferResponseType = exports.isAcceptableStatus = exports.isNetworkError = exports.isCancelledError = void 0;
4
- var isCancelledError = function (error) {
5
- return "isCancelledRequest" in error;
6
- };
7
- exports.isCancelledError = isCancelledError;
8
- var isNetworkError = function (error) {
9
- var _a;
10
- return (error.name === "NetworkError" ||
11
- error.message === "Network Error" ||
12
- ((_a = error.constructor) === null || _a === void 0 ? void 0 : _a.name) === "NetworkError");
13
- };
14
- exports.isNetworkError = isNetworkError;
15
- var DEFAULT_ACCEPTABLE_STATUS = [[200, 299], 304];
16
- var isAcceptableStatus = function (status, acceptableStatus) {
17
- var acceptable = acceptableStatus !== null && acceptableStatus !== void 0 ? acceptableStatus : DEFAULT_ACCEPTABLE_STATUS;
18
- for (var _i = 0, acceptable_1 = acceptable; _i < acceptable_1.length; _i++) {
19
- var cmpStatus = acceptable_1[_i];
20
- if (Array.isArray(cmpStatus)) {
21
- var min = cmpStatus[0], max = cmpStatus[1];
22
- if (status >= min && status <= max) {
23
- return (true);
24
- }
25
- }
26
- else if (!isNaN(cmpStatus)) {
27
- if (status === cmpStatus) {
28
- return (true);
29
- }
30
- }
31
- }
32
- return (false);
33
- };
34
- exports.isAcceptableStatus = isAcceptableStatus;
35
- var TEXT_CONTENT_TYPES = ["text/plain", "text/html", "text/xml", "application/xml"];
36
- var JSON_CONTENT_TYPES = ["text/json", "application/json"];
37
- var ARRAY_BUFFER_CONTENT_TYPES = ["application/octet-stream"];
38
- var inferResponseType = function (contentType) {
39
- var contentTypePart = contentType === null || contentType === void 0 ? void 0 : contentType.split(";")[0].trim();
40
- if (contentTypePart) {
41
- if (TEXT_CONTENT_TYPES.includes(contentTypePart)) {
42
- return "text";
43
- }
44
- else if (JSON_CONTENT_TYPES.includes(contentTypePart)) {
45
- return "json";
46
- }
47
- else if (ARRAY_BUFFER_CONTENT_TYPES.includes(contentTypePart)) {
48
- return "arraybuffer";
49
- }
50
- }
51
- return "text";
52
- };
53
- exports.inferResponseType = inferResponseType;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inferResponseType = exports.isAcceptableStatus = exports.isNetworkError = exports.isCancelledError = void 0;
4
+ var isCancelledError = function (error) {
5
+ return "isCancelledRequest" in error;
6
+ };
7
+ exports.isCancelledError = isCancelledError;
8
+ var isNetworkError = function (error) {
9
+ var _a;
10
+ return error.name === "NetworkError" || error.message === "Network Error" || ((_a = error.constructor) === null || _a === void 0 ? void 0 : _a.name) === "NetworkError";
11
+ };
12
+ exports.isNetworkError = isNetworkError;
13
+ var DEFAULT_ACCEPTABLE_STATUS = [[200, 299], 304];
14
+ var isAcceptableStatus = function (status, acceptableStatus) {
15
+ var acceptable = acceptableStatus !== null && acceptableStatus !== void 0 ? acceptableStatus : DEFAULT_ACCEPTABLE_STATUS;
16
+ for (var _i = 0, acceptable_1 = acceptable; _i < acceptable_1.length; _i++) {
17
+ var cmpStatus = acceptable_1[_i];
18
+ if (Array.isArray(cmpStatus)) {
19
+ var min = cmpStatus[0], max = cmpStatus[1];
20
+ if (status >= min && status <= max) {
21
+ return true;
22
+ }
23
+ }
24
+ else if (!Number.isNaN(cmpStatus)) {
25
+ if (status === cmpStatus) {
26
+ return true;
27
+ }
28
+ }
29
+ }
30
+ return false;
31
+ };
32
+ exports.isAcceptableStatus = isAcceptableStatus;
33
+ var TEXT_CONTENT_TYPES = ["text/plain", "text/html", "text/xml", "application/xml"];
34
+ var JSON_CONTENT_TYPES = ["text/json", "application/json"];
35
+ var ARRAY_BUFFER_CONTENT_TYPES = ["application/octet-stream"];
36
+ var inferResponseType = function (contentType) {
37
+ var contentTypePart = contentType === null || contentType === void 0 ? void 0 : contentType.split(";")[0].trim();
38
+ if (contentTypePart) {
39
+ if (TEXT_CONTENT_TYPES.includes(contentTypePart)) {
40
+ return "text";
41
+ }
42
+ if (JSON_CONTENT_TYPES.includes(contentTypePart)) {
43
+ return "json";
44
+ }
45
+ if (ARRAY_BUFFER_CONTENT_TYPES.includes(contentTypePart)) {
46
+ return "arraybuffer";
47
+ }
48
+ }
49
+ return "text";
50
+ };
51
+ exports.inferResponseType = inferResponseType;
package/cjs/Endpoint.d.ts CHANGED
@@ -1,52 +1,52 @@
1
- import { Api } from "./Api";
2
- import { ApiResponse, BaseRequestConfig, Body, ComputedRequestConfig, Params, Query, RequestConfig, RequestHost } from "./ApiTypes";
3
- import * as Mocking from "./MockingTypes";
4
- import { RequestMethod, ResponseType } from "./ApiConstants";
5
- import RequestBackend from "./backend/RequestBackend";
6
- import { Validation } from "./Validation";
7
- export interface EndpointConfig<R, P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined, Path extends string = string> {
8
- readonly id: string;
9
- readonly method: RequestMethod;
10
- readonly path: Path;
11
- /**
12
- * Name your endpoint to help with debugging and documentation
13
- * @default `id` is used as the name if no name is supplied
14
- */
15
- readonly name?: string;
16
- /**
17
- * Describe your endpoint to help with debugging and documentation
18
- */
19
- readonly description?: string;
20
- readonly config?: BaseRequestConfig;
21
- /**
22
- * Let the backend requestor (fetch, axios, etc.) know what type of response
23
- * you are expecting from this endpoint
24
- * @default `application/json`
25
- */
26
- readonly responseType?: ResponseType;
27
- /**
28
- * Specify mocking for your endpoint upfront to help with disconnected dev,
29
- * and testing.
30
- * Enable/disable mocked returns for all endpoints on your API object.
31
- */
32
- readonly mocking?: Mocking.EndpointMockingConfig<R, P, Q, B>;
33
- readonly validation?: Validation<R, P, Q, B>;
34
- }
35
- export default class Endpoint<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> implements EndpointConfig<R, P, Q, B>, RequestHost {
36
- readonly api: Api;
37
- readonly id: string;
38
- readonly method: RequestMethod;
39
- readonly name: string;
40
- readonly description?: string;
41
- readonly path: string;
42
- readonly config?: BaseRequestConfig;
43
- readonly responseType: ResponseType | undefined;
44
- readonly mocking?: Mocking.EndpointMockingConfig<R, P, Q, B>;
45
- readonly validation: Validation<R, P, Q, B>;
46
- constructor(api: Api, info: EndpointConfig<R, P, Q, B>);
47
- submit(config: RequestConfig<P, Q, B>): Promise<ApiResponse<R>>;
48
- computePath(path: string, request: RequestConfig): string;
49
- get baseUrl(): string;
50
- computeConfig<P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined>(config: RequestConfig<P, Q, B>): ComputedRequestConfig<P, Q, B>;
51
- getRequestBackend(): RequestBackend;
52
- }
1
+ import { Api } from "./Api";
2
+ import { RequestMethod, ResponseType } from "./ApiConstants";
3
+ import { ApiResponse, BaseRequestConfig, Body, ComputedRequestConfig, Params, Query, RequestConfig, RequestHost } from "./ApiTypes";
4
+ import * as Mocking from "./MockingTypes";
5
+ import { Validation } from "./Validation";
6
+ import RequestBackend from "./backend/RequestBackend";
7
+ export interface EndpointConfig<R, P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined, Path extends string = string> {
8
+ readonly id: string;
9
+ readonly method: RequestMethod;
10
+ readonly path: Path;
11
+ /**
12
+ * Name your endpoint to help with debugging and documentation
13
+ * @default `id` is used as the name if no name is supplied
14
+ */
15
+ readonly name?: string;
16
+ /**
17
+ * Describe your endpoint to help with debugging and documentation
18
+ */
19
+ readonly description?: string;
20
+ readonly config?: BaseRequestConfig;
21
+ /**
22
+ * Let the backend requestor (fetch, axios, etc.) know what type of response
23
+ * you are expecting from this endpoint
24
+ * @default `application/json`
25
+ */
26
+ readonly responseType?: ResponseType;
27
+ /**
28
+ * Specify mocking for your endpoint upfront to help with disconnected dev,
29
+ * and testing.
30
+ * Enable/disable mocked returns for all endpoints on your API object.
31
+ */
32
+ readonly mocking?: Mocking.EndpointMockingConfig<R, P, Q, B>;
33
+ readonly validation?: Validation<R, P, Q, B>;
34
+ }
35
+ export default class Endpoint<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> implements EndpointConfig<R, P, Q, B>, RequestHost {
36
+ readonly api: Api;
37
+ readonly id: string;
38
+ readonly method: RequestMethod;
39
+ readonly name: string;
40
+ readonly description?: string;
41
+ readonly path: string;
42
+ readonly config?: BaseRequestConfig;
43
+ readonly responseType: ResponseType | undefined;
44
+ readonly mocking?: Mocking.EndpointMockingConfig<R, P, Q, B>;
45
+ readonly validation: Validation<R, P, Q, B>;
46
+ constructor(api: Api, info: EndpointConfig<R, P, Q, B>);
47
+ submit(config: RequestConfig<P, Q, B>): Promise<ApiResponse<R>>;
48
+ computePath(path: string, request: RequestConfig): string;
49
+ get baseUrl(): string;
50
+ computeConfig<P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined>(config: RequestConfig<P, Q, B>): ComputedRequestConfig<P, Q, B>;
51
+ getRequestBackend(): RequestBackend;
52
+ }