api-def 0.11.1 → 0.12.0-alpha.10
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/bin/index.js +258727 -0
- package/cjs/Api.d.ts +23 -8
- package/cjs/Api.js +96 -15
- package/cjs/ApiTypes.d.ts +6 -4
- package/cjs/Endpoint.d.ts +25 -15
- package/cjs/Endpoint.js +90 -17
- package/cjs/EndpointBuilder.d.ts +11 -9
- package/cjs/EndpointBuilder.js +8 -2
- package/cjs/RequestConfig.d.ts +2 -2
- package/cjs/RequestConfig.js +3 -3
- package/cjs/RequestContext.js +2 -2
- package/cjs/Requester.js +2 -2
- package/cjs/backend/AxiosRequestBackend.js +5 -4
- package/cjs/backend/FetchRequestBackend.js +2 -2
- package/cjs/backend/MockRequestBackend.js +2 -2
- package/cjs/cache/Caching.js +2 -2
- package/cjs/cache/LocalStorageCacheBackend.js +2 -2
- package/cjs/index.d.ts +1 -1
- package/cjs/middleware/CacheMiddleware.js +2 -2
- package/esm/Api.d.ts +23 -8
- package/esm/Api.js +67 -14
- package/esm/ApiTypes.d.ts +6 -4
- package/esm/Endpoint.d.ts +25 -15
- package/esm/Endpoint.js +42 -16
- package/esm/EndpointBuilder.d.ts +11 -9
- package/esm/EndpointBuilder.js +8 -2
- package/esm/RequestConfig.d.ts +2 -2
- package/esm/RequestConfig.js +1 -1
- package/esm/backend/AxiosRequestBackend.js +2 -1
- package/esm/index.d.ts +1 -1
- package/package.json +30 -14
package/cjs/Api.d.ts
CHANGED
|
@@ -6,26 +6,41 @@ import type RequestBackend from "./backend/RequestBackend";
|
|
|
6
6
|
export declare const getRequestBackend: () => RequestBackend | null;
|
|
7
7
|
export declare const isRequestBackendDefault: () => boolean;
|
|
8
8
|
export declare const setRequestBackend: (backend: RequestBackend) => void;
|
|
9
|
-
export interface
|
|
9
|
+
export interface ApiOptions {
|
|
10
10
|
readonly name: string;
|
|
11
11
|
readonly baseUrl: string;
|
|
12
12
|
readonly middleware?: RequestMiddleware[];
|
|
13
|
+
/** @deprecated use `requestConfig` instead */
|
|
13
14
|
readonly config?: BaseRequestConfig | (() => BaseRequestConfig);
|
|
15
|
+
readonly requestConfig?: BaseRequestConfig | (() => BaseRequestConfig);
|
|
14
16
|
readonly mocking?: ApiMockingConfig;
|
|
15
17
|
readonly requestBackend?: RequestBackend;
|
|
16
18
|
}
|
|
19
|
+
export type ApiInfo = ApiOptions & Required<Pick<ApiOptions, "middleware" | "requestBackend">>;
|
|
17
20
|
export declare class Api implements ApiInfo {
|
|
18
|
-
readonly
|
|
19
|
-
readonly name: string;
|
|
20
|
-
readonly middleware: RequestMiddleware[];
|
|
21
|
-
readonly config?: BaseRequestConfig | (() => BaseRequestConfig);
|
|
22
|
-
readonly mocking?: ApiMockingConfig;
|
|
23
|
-
readonly requestBackend: RequestBackend;
|
|
21
|
+
private readonly info;
|
|
24
22
|
protected readonly endpoints: Record<string, Endpoint>;
|
|
25
|
-
constructor(
|
|
23
|
+
constructor(options: ApiOptions);
|
|
24
|
+
get requestBackend(): RequestBackend;
|
|
25
|
+
get baseUrl(): string;
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated use `requestConfig` instead
|
|
28
|
+
*/
|
|
29
|
+
get config(): BaseRequestConfig | (() => BaseRequestConfig) | undefined;
|
|
30
|
+
get requestConfig(): BaseRequestConfig | (() => BaseRequestConfig) | undefined;
|
|
31
|
+
get middleware(): RequestMiddleware[];
|
|
32
|
+
get mocking(): ApiMockingConfig | undefined;
|
|
33
|
+
get name(): string;
|
|
26
34
|
endpoint(): EndpointBuilder;
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated use `requestBackend` instead
|
|
37
|
+
*/
|
|
27
38
|
getRequestBackend(): RequestBackend;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated use `computeRequestConfig()` instead
|
|
41
|
+
*/
|
|
28
42
|
getConfig(): BaseRequestConfig;
|
|
43
|
+
computeRequestConfig(): BaseRequestConfig;
|
|
29
44
|
private hotRequest;
|
|
30
45
|
get: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
|
|
31
46
|
post: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
|
package/cjs/Api.js
CHANGED
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -75,22 +75,39 @@ var HotRequestHost = /** @class */ (function () {
|
|
|
75
75
|
configurable: true
|
|
76
76
|
});
|
|
77
77
|
HotRequestHost.prototype.computeConfig = function (config) {
|
|
78
|
-
var apiDefaults = this.api.
|
|
79
|
-
return (0, RequestConfig_1.
|
|
78
|
+
var apiDefaults = this.api.computeRequestConfig();
|
|
79
|
+
return (0, RequestConfig_1.processRequestConfigs)([apiDefaults, config]);
|
|
80
80
|
};
|
|
81
81
|
HotRequestHost.prototype.computePath = function (path, config) {
|
|
82
82
|
return path.startsWith("/") ? path : "/".concat(path);
|
|
83
83
|
};
|
|
84
84
|
HotRequestHost.prototype.getRequestBackend = function () {
|
|
85
|
-
return this.api.
|
|
85
|
+
return this.api.requestBackend;
|
|
86
86
|
};
|
|
87
87
|
return HotRequestHost;
|
|
88
88
|
}());
|
|
89
89
|
var Api = /** @class */ (function () {
|
|
90
|
-
function Api(
|
|
90
|
+
function Api(options) {
|
|
91
91
|
var _this = this;
|
|
92
92
|
var _a, _b;
|
|
93
93
|
this.endpoints = {};
|
|
94
|
+
/*reconfigure(info: Partial<ApiInfo>): void {
|
|
95
|
+
if (info.requestBackend) {
|
|
96
|
+
(this as any).requestBackend = info.requestBackend;
|
|
97
|
+
}
|
|
98
|
+
if (info.config) {
|
|
99
|
+
(this as any).config = info.config;
|
|
100
|
+
}
|
|
101
|
+
if (info.middleware) {
|
|
102
|
+
(this as any).middleware = info.middleware;
|
|
103
|
+
}
|
|
104
|
+
if (info.mocking) {
|
|
105
|
+
(this as any).mocking = info.mocking;
|
|
106
|
+
}
|
|
107
|
+
if (info.baseUrl) {
|
|
108
|
+
(this as any).baseUrl = info.baseUrl;
|
|
109
|
+
}
|
|
110
|
+
}*/
|
|
94
111
|
this.hotRequest = function (requestMethod) {
|
|
95
112
|
return function (path, config) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
96
113
|
switch (_a.label) {
|
|
@@ -104,26 +121,90 @@ var Api = /** @class */ (function () {
|
|
|
104
121
|
this.put = this.hotRequest(ApiConstants_1.RequestMethod.PUT);
|
|
105
122
|
this.delete = this.hotRequest(ApiConstants_1.RequestMethod.DELETE);
|
|
106
123
|
this.patch = this.hotRequest(ApiConstants_1.RequestMethod.PATCH);
|
|
107
|
-
|
|
108
|
-
this.baseUrl = info.baseUrl;
|
|
109
|
-
this.middleware = info.middleware || [];
|
|
110
|
-
this.endpoints = {};
|
|
111
|
-
this.config = info.config;
|
|
112
|
-
this.mocking = (_a = info.mocking) !== null && _a !== void 0 ? _a : undefined;
|
|
113
|
-
var requestBackend = (_b = info.requestBackend) !== null && _b !== void 0 ? _b : (0, exports.getRequestBackend)();
|
|
124
|
+
var requestBackend = (_a = options.requestBackend) !== null && _a !== void 0 ? _a : (0, exports.getRequestBackend)();
|
|
114
125
|
if (!requestBackend) {
|
|
115
126
|
throw new Error("[api-def] No request backend provided in either Api options or globally, use `setRequestBackend()` to set one or pass one via `requestBackend`");
|
|
116
127
|
}
|
|
117
|
-
this.
|
|
128
|
+
this.info = {
|
|
129
|
+
name: options.name,
|
|
130
|
+
baseUrl: options.baseUrl,
|
|
131
|
+
middleware: options.middleware || [],
|
|
132
|
+
config: options.config,
|
|
133
|
+
requestConfig: options.requestConfig,
|
|
134
|
+
mocking: (_b = options.mocking) !== null && _b !== void 0 ? _b : undefined,
|
|
135
|
+
requestBackend: requestBackend,
|
|
136
|
+
};
|
|
137
|
+
this.endpoints = {};
|
|
118
138
|
}
|
|
139
|
+
Object.defineProperty(Api.prototype, "requestBackend", {
|
|
140
|
+
get: function () {
|
|
141
|
+
return this.info.requestBackend;
|
|
142
|
+
},
|
|
143
|
+
enumerable: false,
|
|
144
|
+
configurable: true
|
|
145
|
+
});
|
|
146
|
+
Object.defineProperty(Api.prototype, "baseUrl", {
|
|
147
|
+
get: function () {
|
|
148
|
+
return this.info.baseUrl;
|
|
149
|
+
},
|
|
150
|
+
enumerable: false,
|
|
151
|
+
configurable: true
|
|
152
|
+
});
|
|
153
|
+
Object.defineProperty(Api.prototype, "config", {
|
|
154
|
+
/**
|
|
155
|
+
* @deprecated use `requestConfig` instead
|
|
156
|
+
*/
|
|
157
|
+
get: function () {
|
|
158
|
+
return this.info.config;
|
|
159
|
+
},
|
|
160
|
+
enumerable: false,
|
|
161
|
+
configurable: true
|
|
162
|
+
});
|
|
163
|
+
Object.defineProperty(Api.prototype, "requestConfig", {
|
|
164
|
+
get: function () {
|
|
165
|
+
return this.info.requestConfig;
|
|
166
|
+
},
|
|
167
|
+
enumerable: false,
|
|
168
|
+
configurable: true
|
|
169
|
+
});
|
|
170
|
+
Object.defineProperty(Api.prototype, "middleware", {
|
|
171
|
+
get: function () {
|
|
172
|
+
return this.info.middleware;
|
|
173
|
+
},
|
|
174
|
+
enumerable: false,
|
|
175
|
+
configurable: true
|
|
176
|
+
});
|
|
177
|
+
Object.defineProperty(Api.prototype, "mocking", {
|
|
178
|
+
get: function () {
|
|
179
|
+
return this.info.mocking;
|
|
180
|
+
},
|
|
181
|
+
enumerable: false,
|
|
182
|
+
configurable: true
|
|
183
|
+
});
|
|
184
|
+
Object.defineProperty(Api.prototype, "name", {
|
|
185
|
+
get: function () {
|
|
186
|
+
return this.info.name;
|
|
187
|
+
},
|
|
188
|
+
enumerable: false,
|
|
189
|
+
configurable: true
|
|
190
|
+
});
|
|
119
191
|
Api.prototype.endpoint = function () {
|
|
120
192
|
return new EndpointBuilder_1.default(this);
|
|
121
193
|
};
|
|
194
|
+
/**
|
|
195
|
+
* @deprecated use `requestBackend` instead
|
|
196
|
+
*/
|
|
122
197
|
Api.prototype.getRequestBackend = function () {
|
|
123
198
|
return this.requestBackend;
|
|
124
199
|
};
|
|
200
|
+
/**
|
|
201
|
+
* @deprecated use `computeRequestConfig()` instead
|
|
202
|
+
*/
|
|
125
203
|
Api.prototype.getConfig = function () {
|
|
126
|
-
return
|
|
204
|
+
return this.computeRequestConfig();
|
|
205
|
+
};
|
|
206
|
+
Api.prototype.computeRequestConfig = function () {
|
|
207
|
+
return (typeof this.requestConfig === "function" ? this.requestConfig() : this.requestConfig) || {};
|
|
127
208
|
};
|
|
128
209
|
return Api;
|
|
129
210
|
}());
|
package/cjs/ApiTypes.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export interface BaseRequestConfig {
|
|
|
43
43
|
queryParser?: QueryStringify;
|
|
44
44
|
queryHandling?: Partial<QueryHandling>;
|
|
45
45
|
}
|
|
46
|
-
export type RequestConfig<TParams extends Params | undefined = Params | undefined, TQuery extends Query | undefined = Query | undefined, TBody extends Body | undefined = Body | undefined, TState extends State = State> = (TParams extends undefined ? {
|
|
46
|
+
export type RequestConfig<TParams extends Params | undefined = Params | undefined, TQuery extends Query | undefined = Query | undefined, TBody extends Body | undefined = Body | undefined, TState extends State = State, TRequestHeaders extends RawHeaders | undefined = RawHeaders | undefined> = (TParams extends undefined ? {
|
|
47
47
|
params?: never;
|
|
48
48
|
} : {
|
|
49
49
|
params: Record<TParams extends Params ? TParams : never, string>;
|
|
@@ -59,9 +59,11 @@ export type RequestConfig<TParams extends Params | undefined = Params | undefine
|
|
|
59
59
|
state?: TState;
|
|
60
60
|
} : {
|
|
61
61
|
state: TState;
|
|
62
|
-
}) & BaseRequestConfig
|
|
62
|
+
}) & (Omit<BaseRequestConfig, "headers"> & {
|
|
63
|
+
headers?: TRequestHeaders & RawHeaders;
|
|
64
|
+
});
|
|
63
65
|
export declare const COMPUTED_CONFIG_SYMBOL: unique symbol;
|
|
64
|
-
export type ComputedRequestConfig<TParams extends Params | undefined = Params | undefined, TQuery extends Query | undefined = Query | undefined, TBody extends Body | undefined = Body | undefined, TState extends State = State> = Omit<RequestConfig<TParams, TQuery, TBody, TState>, "queryParser" | "query" | "queryHandling" | "state"> & {
|
|
66
|
+
export type ComputedRequestConfig<TParams extends Params | undefined = Params | undefined, TQuery extends Query | undefined = Query | undefined, TBody extends Body | undefined = Body | undefined, TState extends State = State, TRequestHeaders extends RawHeaders | undefined = RawHeaders | undefined> = Omit<RequestConfig<TParams, TQuery, TBody, TState, TRequestHeaders>, "queryParser" | "query" | "queryHandling" | "state"> & {
|
|
65
67
|
[COMPUTED_CONFIG_SYMBOL]: true;
|
|
66
68
|
state: TState;
|
|
67
69
|
queryObject: Record<string, any> | undefined;
|
|
@@ -97,7 +99,7 @@ export interface RequestHost {
|
|
|
97
99
|
readonly path: string;
|
|
98
100
|
readonly responseType: ResponseType | undefined;
|
|
99
101
|
readonly validation: Validation;
|
|
100
|
-
computeConfig<TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State>(config: RequestConfig<TParams, TQuery, TBody, TState>): ComputedRequestConfig<TParams, TQuery, TBody, TState>;
|
|
102
|
+
computeConfig<TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State, TRequestHeaders extends RawHeaders | undefined>(config: RequestConfig<TParams, TQuery, TBody, TState, TRequestHeaders>): ComputedRequestConfig<TParams, TQuery, TBody, TState, TRequestHeaders>;
|
|
101
103
|
computePath(path: string, config: RequestConfig): string;
|
|
102
104
|
getRequestBackend(): RequestBackend;
|
|
103
105
|
}
|
package/cjs/Endpoint.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Api } from "./Api";
|
|
2
2
|
import type { RequestMethod, ResponseType } from "./ApiConstants";
|
|
3
|
-
import type { ApiResponse, BaseRequestConfig, Body, ComputedRequestConfig, Params, Query, RequestConfig, RequestHost, State } from "./ApiTypes";
|
|
3
|
+
import type { ApiResponse, BaseRequestConfig, Body, ComputedRequestConfig, Params, Query, RawHeaders, RequestConfig, RequestHost, State } from "./ApiTypes";
|
|
4
4
|
import type * as Mocking from "./MockingTypes";
|
|
5
5
|
import type { Validation } from "./Validation";
|
|
6
6
|
import type RequestBackend from "./backend/RequestBackend";
|
|
7
|
-
export interface
|
|
7
|
+
export interface EndpointOptions<TResult, TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State = State, TPath extends string = string, TRequestHeaders extends RawHeaders | undefined = RawHeaders | undefined, TResponseHeaders extends RawHeaders | undefined = RawHeaders | undefined> {
|
|
8
8
|
readonly id: string;
|
|
9
9
|
readonly method: RequestMethod;
|
|
10
10
|
readonly path: TPath;
|
|
@@ -32,21 +32,31 @@ export interface EndpointConfig<TResult, TParams extends Params | undefined, TQu
|
|
|
32
32
|
readonly mocking?: Mocking.EndpointMockingConfig<TResult, TParams, TQuery, TBody, TState>;
|
|
33
33
|
readonly validation?: Validation<TResult, TParams, TQuery, TBody, TState>;
|
|
34
34
|
}
|
|
35
|
-
export
|
|
35
|
+
export type EndpointInfo<TResult, TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State = State, TPath extends string = string, TRequestHeaders extends RawHeaders | undefined = RawHeaders | undefined, TResponseHeaders extends RawHeaders | undefined = RawHeaders | undefined> = EndpointOptions<TResult, TParams, TQuery, TBody, TState, TPath, TRequestHeaders, TResponseHeaders> & Required<Pick<EndpointOptions<TResult, TParams, TQuery, TBody, TState, TPath, TRequestHeaders, TResponseHeaders>, "name" | "validation">>;
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use `EndpointInfo` instead
|
|
38
|
+
*/
|
|
39
|
+
export type EndpointConfig<TResult, TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State = State, TPath extends string = string, TRequestHeaders extends RawHeaders | undefined = RawHeaders | undefined, TResponseHeaders extends RawHeaders | undefined = RawHeaders | undefined> = EndpointInfo<TResult, TParams, TQuery, TBody, TState, TPath>;
|
|
40
|
+
export default class Endpoint<TResponse = any, TParams extends Params | undefined = Params | undefined, TQuery extends Query | undefined = Query | undefined, TBody extends Body | undefined = Body | undefined, TState extends State = State, TPath extends string = string, TRequestHeaders extends RawHeaders | undefined = RawHeaders | undefined, TResponseHeaders extends RawHeaders | undefined = RawHeaders | undefined> implements EndpointInfo<TResponse, TParams, TQuery, TBody, TState, TPath, TRequestHeaders, TResponseHeaders>, RequestHost {
|
|
36
41
|
readonly api: Api;
|
|
37
|
-
readonly
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
private readonly info;
|
|
43
|
+
constructor(api: Api, options: EndpointOptions<TResponse, TParams, TQuery, TBody, TState, TPath, TRequestHeaders, TResponseHeaders>);
|
|
44
|
+
get id(): string;
|
|
45
|
+
get method(): RequestMethod;
|
|
46
|
+
get path(): TPath;
|
|
47
|
+
get name(): string;
|
|
48
|
+
get description(): string | undefined;
|
|
49
|
+
get config(): BaseRequestConfig;
|
|
50
|
+
get responseType(): ResponseType | undefined;
|
|
51
|
+
get mocking(): Mocking.EndpointMockingConfig<TResponse, TParams, TQuery, TBody, TState> | undefined;
|
|
52
|
+
get validation(): Validation<TResponse, TParams, TQuery, TBody, TState>;
|
|
53
|
+
submit(config: RequestConfig<TParams, TQuery, TBody, TState, TRequestHeaders>): Promise<ApiResponse<TResponse>>;
|
|
48
54
|
computePath(path: string, request: RequestConfig): string;
|
|
49
55
|
get baseUrl(): string;
|
|
50
|
-
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated Use `computeRequestConfig` instead
|
|
58
|
+
*/
|
|
59
|
+
computeConfig<TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State, TRequestHeaders extends RawHeaders | undefined>(config: RequestConfig<TParams, TQuery, TBody, TState, TRequestHeaders>): ComputedRequestConfig<TParams, TQuery, TBody, TState, TRequestHeaders>;
|
|
60
|
+
computeRequestConfig<TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State, TRequestHeaders extends RawHeaders | undefined>(config: RequestConfig<TParams, TQuery, TBody, TState, TRequestHeaders>): ComputedRequestConfig<TParams, TQuery, TBody, TState, TRequestHeaders>;
|
|
51
61
|
getRequestBackend(): RequestBackend;
|
|
52
62
|
}
|
package/cjs/Endpoint.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -9,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
20
|
});
|
|
10
21
|
};
|
|
11
22
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
26
|
function step(op) {
|
|
16
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -39,18 +50,73 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
50
|
var Requester = require("./Requester");
|
|
40
51
|
var RequestConfig_1 = require("./RequestConfig");
|
|
41
52
|
var Endpoint = /** @class */ (function () {
|
|
42
|
-
function Endpoint(api,
|
|
53
|
+
function Endpoint(api, options) {
|
|
43
54
|
this.api = api;
|
|
44
|
-
this.
|
|
45
|
-
this.method = info.method;
|
|
46
|
-
this.name = info.name || info.id;
|
|
47
|
-
this.description = info.description;
|
|
48
|
-
this.path = info.path;
|
|
49
|
-
this.config = info.config;
|
|
50
|
-
this.responseType = info.responseType;
|
|
51
|
-
this.mocking = info.mocking;
|
|
52
|
-
this.validation = info.validation || {};
|
|
55
|
+
this.info = __assign(__assign({}, options), { name: options.name || options.id, validation: options.validation || {} });
|
|
53
56
|
}
|
|
57
|
+
Object.defineProperty(Endpoint.prototype, "id", {
|
|
58
|
+
get: function () {
|
|
59
|
+
return this.info.id;
|
|
60
|
+
},
|
|
61
|
+
enumerable: false,
|
|
62
|
+
configurable: true
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(Endpoint.prototype, "method", {
|
|
65
|
+
get: function () {
|
|
66
|
+
return this.info.method;
|
|
67
|
+
},
|
|
68
|
+
enumerable: false,
|
|
69
|
+
configurable: true
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(Endpoint.prototype, "path", {
|
|
72
|
+
get: function () {
|
|
73
|
+
return this.info.path;
|
|
74
|
+
},
|
|
75
|
+
enumerable: false,
|
|
76
|
+
configurable: true
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(Endpoint.prototype, "name", {
|
|
79
|
+
get: function () {
|
|
80
|
+
return this.info.name;
|
|
81
|
+
},
|
|
82
|
+
enumerable: false,
|
|
83
|
+
configurable: true
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(Endpoint.prototype, "description", {
|
|
86
|
+
get: function () {
|
|
87
|
+
return this.info.description;
|
|
88
|
+
},
|
|
89
|
+
enumerable: false,
|
|
90
|
+
configurable: true
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(Endpoint.prototype, "config", {
|
|
93
|
+
get: function () {
|
|
94
|
+
return this.info.config || {};
|
|
95
|
+
},
|
|
96
|
+
enumerable: false,
|
|
97
|
+
configurable: true
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(Endpoint.prototype, "responseType", {
|
|
100
|
+
get: function () {
|
|
101
|
+
return this.info.responseType;
|
|
102
|
+
},
|
|
103
|
+
enumerable: false,
|
|
104
|
+
configurable: true
|
|
105
|
+
});
|
|
106
|
+
Object.defineProperty(Endpoint.prototype, "mocking", {
|
|
107
|
+
get: function () {
|
|
108
|
+
return this.info.mocking;
|
|
109
|
+
},
|
|
110
|
+
enumerable: false,
|
|
111
|
+
configurable: true
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(Endpoint.prototype, "validation", {
|
|
114
|
+
get: function () {
|
|
115
|
+
return this.info.validation;
|
|
116
|
+
},
|
|
117
|
+
enumerable: false,
|
|
118
|
+
configurable: true
|
|
119
|
+
});
|
|
54
120
|
Endpoint.prototype.submit = function (config) {
|
|
55
121
|
return __awaiter(this, void 0, void 0, function () {
|
|
56
122
|
var mock, apiMocking, mockingEnabled;
|
|
@@ -77,10 +143,11 @@ var Endpoint = /** @class */ (function () {
|
|
|
77
143
|
var keys = Object.keys(request.params);
|
|
78
144
|
for (var i = 0; i < keys.length; i++) {
|
|
79
145
|
var argName = keys[i];
|
|
80
|
-
|
|
146
|
+
var argValue = request.params[argName];
|
|
147
|
+
computedPath = computedPath.replace(":".concat(argName), argValue).replace("{".concat(argName, "}"), argValue);
|
|
81
148
|
}
|
|
82
149
|
}
|
|
83
|
-
if (computedPath.includes(":")) {
|
|
150
|
+
if (computedPath.includes(":") || computedPath.includes("{")) {
|
|
84
151
|
throw new Error("[api-def] Not all path params have been resolved: '".concat(computedPath, "'"));
|
|
85
152
|
}
|
|
86
153
|
return computedPath;
|
|
@@ -92,12 +159,18 @@ var Endpoint = /** @class */ (function () {
|
|
|
92
159
|
enumerable: false,
|
|
93
160
|
configurable: true
|
|
94
161
|
});
|
|
162
|
+
/**
|
|
163
|
+
* @deprecated Use `computeRequestConfig` instead
|
|
164
|
+
*/
|
|
95
165
|
Endpoint.prototype.computeConfig = function (config) {
|
|
96
|
-
|
|
97
|
-
|
|
166
|
+
return this.computeRequestConfig(config);
|
|
167
|
+
};
|
|
168
|
+
Endpoint.prototype.computeRequestConfig = function (config) {
|
|
169
|
+
var apiDefaults = this.api.computeRequestConfig();
|
|
170
|
+
return (0, RequestConfig_1.processRequestConfigs)([apiDefaults, this.config, config]);
|
|
98
171
|
};
|
|
99
172
|
Endpoint.prototype.getRequestBackend = function () {
|
|
100
|
-
return this.api.
|
|
173
|
+
return this.api.requestBackend;
|
|
101
174
|
};
|
|
102
175
|
return Endpoint;
|
|
103
176
|
}());
|
package/cjs/EndpointBuilder.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import type * as zod from "zod";
|
|
2
2
|
import type { Api } from "./Api";
|
|
3
|
-
import type { Body, Params, Query, State } from "./ApiTypes";
|
|
4
|
-
import Endpoint, { type
|
|
5
|
-
export default class EndpointBuilder<TResponse = any, TParams extends Params | undefined = undefined, TQuery extends Query | undefined = undefined, TBody extends Body | undefined = undefined, TState extends State = State> {
|
|
3
|
+
import type { Body, Params, Query, RawHeaders, State } from "./ApiTypes";
|
|
4
|
+
import Endpoint, { type EndpointOptions } from "./Endpoint";
|
|
5
|
+
export default class EndpointBuilder<TResponse = any, TParams extends Params | undefined = undefined, TQuery extends Query | undefined = undefined, TBody extends Body | undefined = undefined, TState extends State = State, TRequestHeaders extends RawHeaders | undefined = RawHeaders | undefined, TResponseHeaders extends RawHeaders | undefined = RawHeaders | undefined> {
|
|
6
6
|
private api;
|
|
7
7
|
private readonly validation;
|
|
8
8
|
constructor(api: Api);
|
|
9
|
-
queryOf<TNewQuery extends Query>(schema?: zod.Schema<TNewQuery>): EndpointBuilder<TResponse, TParams, TNewQuery, TBody>;
|
|
10
|
-
paramsOf<TNewParams extends Params>(): EndpointBuilder<TResponse, TNewParams, TQuery, TBody, TState>;
|
|
11
|
-
bodyOf<TNewBody extends Body>(schema?: zod.Schema<TNewBody>): EndpointBuilder<TResponse, TParams, TQuery, TNewBody, TState>;
|
|
12
|
-
responseOf<TNewResponse>(schema?: zod.Schema<TNewResponse>): EndpointBuilder<TNewResponse, TParams, TQuery, TBody, TState>;
|
|
13
|
-
stateOf<TNewState extends State>(schema?: zod.Schema<TNewState>): EndpointBuilder<TResponse, TParams, TQuery, TBody, TNewState>;
|
|
14
|
-
|
|
9
|
+
queryOf<TNewQuery extends Query>(schema?: zod.Schema<TNewQuery>): EndpointBuilder<TResponse, TParams, TNewQuery, TBody, TState, TRequestHeaders, TResponseHeaders>;
|
|
10
|
+
paramsOf<TNewParams extends Params>(): EndpointBuilder<TResponse, TNewParams, TQuery, TBody, TState, TRequestHeaders, TResponseHeaders>;
|
|
11
|
+
bodyOf<TNewBody extends Body>(schema?: zod.Schema<TNewBody>): EndpointBuilder<TResponse, TParams, TQuery, TNewBody, TState, TRequestHeaders, TResponseHeaders>;
|
|
12
|
+
responseOf<TNewResponse>(schema?: zod.Schema<TNewResponse>): EndpointBuilder<TNewResponse, TParams, TQuery, TBody, TState, TRequestHeaders, TResponseHeaders>;
|
|
13
|
+
stateOf<TNewState extends State>(schema?: zod.Schema<TNewState>): EndpointBuilder<TResponse, TParams, TQuery, TBody, TNewState, TRequestHeaders, TResponseHeaders>;
|
|
14
|
+
requestHeadersOf<TNewRequestHeaders extends RawHeaders>(): EndpointBuilder<TResponse, TParams, TQuery, TBody, TState, TNewRequestHeaders, TResponseHeaders>;
|
|
15
|
+
responseHeadersOf<TNewResponseHeaders extends RawHeaders>(): EndpointBuilder<TResponse, TParams, TQuery, TBody, TState, TRequestHeaders, TNewResponseHeaders>;
|
|
16
|
+
build<TPath extends string>(options: Omit<EndpointOptions<TResponse, TParams, TQuery, TBody, TState, TPath, TRequestHeaders, TResponseHeaders>, "validation">): Endpoint<TResponse, TParams, TQuery, TBody, TState, TPath, TRequestHeaders, TResponseHeaders>;
|
|
15
17
|
}
|
package/cjs/EndpointBuilder.js
CHANGED
|
@@ -40,8 +40,14 @@ var EndpointBuilder = /** @class */ (function () {
|
|
|
40
40
|
this.validation.state = schema;
|
|
41
41
|
return this;
|
|
42
42
|
};
|
|
43
|
-
EndpointBuilder.prototype.
|
|
44
|
-
|
|
43
|
+
EndpointBuilder.prototype.requestHeadersOf = function () {
|
|
44
|
+
return this;
|
|
45
|
+
};
|
|
46
|
+
EndpointBuilder.prototype.responseHeadersOf = function () {
|
|
47
|
+
return this;
|
|
48
|
+
};
|
|
49
|
+
EndpointBuilder.prototype.build = function (options) {
|
|
50
|
+
var endpoint = new Endpoint_1.default(this.api, __assign(__assign({}, options), { validation: this.validation }));
|
|
45
51
|
this.api.endpoints[endpoint.id] = endpoint;
|
|
46
52
|
return endpoint;
|
|
47
53
|
};
|
package/cjs/RequestConfig.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type BaseRequestConfig, type Body, type ComputedRequestConfig, type Params, type Query, type RequestConfig, type State } from "./ApiTypes";
|
|
2
|
-
export declare const
|
|
1
|
+
import { type BaseRequestConfig, type Body, type ComputedRequestConfig, type Params, type Query, type RawHeaders, type RequestConfig, type State } from "./ApiTypes";
|
|
2
|
+
export declare const processRequestConfigs: <TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State, TRequestHeaders extends RawHeaders | undefined>(configs: (RequestConfig<TParams, TQuery, TBody, TState, TRequestHeaders> | BaseRequestConfig | undefined)[]) => ComputedRequestConfig<TParams, TQuery, TBody, TState, TRequestHeaders>;
|
package/cjs/RequestConfig.js
CHANGED
|
@@ -9,12 +9,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
9
9
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.processRequestConfigs = void 0;
|
|
13
13
|
var ApiTypes_1 = require("./ApiTypes");
|
|
14
14
|
var QueryHandling_1 = require("./QueryHandling");
|
|
15
15
|
var Utils = require("./Utils");
|
|
16
16
|
var MERGED_CONFIG_KEYS = ["headers"];
|
|
17
|
-
var
|
|
17
|
+
var processRequestConfigs = function (configs) {
|
|
18
18
|
var _a;
|
|
19
19
|
var _b, _c;
|
|
20
20
|
var computedConfig = Utils.assign.apply(Utils, __spreadArray([(_a = {},
|
|
@@ -74,4 +74,4 @@ var computeRequestConfig = function (configs) {
|
|
|
74
74
|
}
|
|
75
75
|
return computedConfig;
|
|
76
76
|
};
|
|
77
|
-
exports.
|
|
77
|
+
exports.processRequestConfigs = processRequestConfigs;
|
package/cjs/RequestContext.js
CHANGED
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
package/cjs/Requester.js
CHANGED
|
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g =
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -59,10 +59,11 @@ var AxiosRequestBackend = /** @class */ (function () {
|
|
|
59
59
|
};
|
|
60
60
|
AxiosRequestBackend.prototype.convertResponse = function (context, response) {
|
|
61
61
|
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
-
|
|
62
|
+
var _a, _b, _c, _d;
|
|
63
|
+
return __generator(this, function (_e) {
|
|
63
64
|
return [2 /*return*/, {
|
|
64
65
|
method: context.method,
|
|
65
|
-
url: response.request.res.responseUrl,
|
|
66
|
+
url: (_b = (_a = response.request.res) === null || _a === void 0 ? void 0 : _a.responseUrl) !== null && _b !== void 0 ? _b : (_d = (_c = response.request) === null || _c === void 0 ? void 0 : _c._redirectable) === null || _d === void 0 ? void 0 : _d._currentUrl,
|
|
66
67
|
data: response.data,
|
|
67
68
|
headers: response.headers,
|
|
68
69
|
status: response.status,
|
|
@@ -24,8 +24,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
24
24
|
});
|
|
25
25
|
};
|
|
26
26
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g =
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
28
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
29
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
30
|
function step(op) {
|
|
31
31
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
package/cjs/cache/Caching.js
CHANGED
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
package/cjs/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export * from "./ApiTypes";
|
|
|
3
3
|
export * from "./UtilTypes";
|
|
4
4
|
export * from "./ApiConstants";
|
|
5
5
|
export { default as retry } from "./util/retry";
|
|
6
|
-
export {
|
|
6
|
+
export type { RetryOptions } from "./util/retry/interfaces";
|
|
7
7
|
export { isRequestError, type RequestError } from "./RequestError";
|
|
8
8
|
export { default as Endpoint, type EndpointConfig } from "./Endpoint";
|
|
9
9
|
export { clearCache, setCacheBackend } from "./cache/Caching";
|