typedapi-client-helpers 0.2.1 → 0.3.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.
- package/CHANGELOG.md +72 -0
- package/README.md +231 -220
- package/dist/cjs/httpClient.js +258 -0
- package/dist/cjs/httpClient.js.map +1 -0
- package/dist/cjs/index.js +32 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/interfaces/ApiResult.js +3 -0
- package/dist/cjs/interfaces/ApiResult.js.map +1 -0
- package/dist/cjs/interfaces/Filter.js +3 -0
- package/dist/cjs/interfaces/Filter.js.map +1 -0
- package/dist/cjs/interfaces/SortType.js +3 -0
- package/dist/cjs/interfaces/SortType.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/types/ApiCallOptions.js +3 -0
- package/dist/cjs/types/ApiCallOptions.js.map +1 -0
- package/dist/cjs/types/ApiMethodArguments.js +3 -0
- package/dist/cjs/types/ApiMethodArguments.js.map +1 -0
- package/dist/cjs/types/ApiMethodOptions.js +3 -0
- package/dist/cjs/types/ApiMethodOptions.js.map +1 -0
- package/dist/cjs/types/ApiMethodTypes.js +3 -0
- package/dist/cjs/types/ApiMethodTypes.js.map +1 -0
- package/dist/cjs/types/HttpResponse.js +3 -0
- package/dist/cjs/types/HttpResponse.js.map +1 -0
- package/dist/cjs/types/httpClientTypes.js +3 -0
- package/dist/cjs/types/httpClientTypes.js.map +1 -0
- package/dist/cjs/utils/SortTypeFromSortDirection.js +43 -0
- package/dist/cjs/utils/SortTypeFromSortDirection.js.map +1 -0
- package/dist/cjs/utils/buildQuery.js +96 -0
- package/dist/cjs/utils/buildQuery.js.map +1 -0
- package/dist/cjs/utils/extractArgsCallbacksAndParams.js +51 -0
- package/dist/cjs/utils/extractArgsCallbacksAndParams.js.map +1 -0
- package/dist/cjs/utils/extractArgsToastsAndParams.js +49 -0
- package/dist/cjs/utils/extractArgsToastsAndParams.js.map +1 -0
- package/dist/cjs/utils/handleApiResponse.js +132 -0
- package/dist/cjs/utils/handleApiResponse.js.map +1 -0
- package/dist/cjs/utils/toFormData.js +58 -0
- package/dist/cjs/utils/toFormData.js.map +1 -0
- package/dist/cjs/utils/wireMapping.js +123 -0
- package/dist/cjs/utils/wireMapping.js.map +1 -0
- package/dist/esm/httpClient.js +251 -0
- package/dist/esm/httpClient.js.map +1 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/interfaces/ApiResult.js +2 -0
- package/dist/esm/interfaces/ApiResult.js.map +1 -0
- package/dist/esm/interfaces/Filter.js +2 -0
- package/dist/esm/interfaces/Filter.js.map +1 -0
- package/dist/esm/interfaces/SortType.js +2 -0
- package/dist/esm/interfaces/SortType.js.map +1 -0
- package/dist/esm/types/ApiCallOptions.js +2 -0
- package/dist/esm/types/ApiCallOptions.js.map +1 -0
- package/dist/esm/types/ApiMethodArguments.js +2 -0
- package/dist/esm/types/ApiMethodArguments.js.map +1 -0
- package/dist/esm/types/ApiMethodOptions.js +2 -0
- package/dist/esm/types/ApiMethodOptions.js.map +1 -0
- package/dist/esm/types/ApiMethodTypes.js +2 -0
- package/dist/esm/types/ApiMethodTypes.js.map +1 -0
- package/dist/esm/types/HttpResponse.js +2 -0
- package/dist/esm/types/HttpResponse.js.map +1 -0
- package/dist/esm/types/httpClientTypes.js +2 -0
- package/dist/esm/types/httpClientTypes.js.map +1 -0
- package/dist/esm/utils/SortTypeFromSortDirection.js +38 -0
- package/dist/esm/utils/SortTypeFromSortDirection.js.map +1 -0
- package/dist/esm/utils/buildQuery.js +93 -0
- package/dist/esm/utils/buildQuery.js.map +1 -0
- package/dist/esm/utils/extractArgsCallbacksAndParams.js +48 -0
- package/dist/esm/utils/extractArgsCallbacksAndParams.js.map +1 -0
- package/dist/esm/utils/extractArgsToastsAndParams.js +46 -0
- package/dist/esm/utils/extractArgsToastsAndParams.js.map +1 -0
- package/dist/esm/utils/handleApiResponse.js +128 -0
- package/dist/esm/utils/handleApiResponse.js.map +1 -0
- package/dist/esm/utils/toFormData.js +55 -0
- package/dist/esm/utils/toFormData.js.map +1 -0
- package/dist/esm/utils/wireMapping.js +119 -0
- package/dist/esm/utils/wireMapping.js.map +1 -0
- package/dist/types/httpClient.d.ts +63 -0
- package/dist/types/httpClient.d.ts.map +1 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/interfaces/ApiResult.d.ts +41 -0
- package/dist/types/interfaces/ApiResult.d.ts.map +1 -0
- package/dist/types/interfaces/Filter.d.ts +31 -0
- package/dist/types/interfaces/Filter.d.ts.map +1 -0
- package/dist/types/interfaces/SortType.d.ts +7 -0
- package/dist/types/interfaces/SortType.d.ts.map +1 -0
- package/dist/types/types/ApiCallOptions.d.ts +26 -0
- package/dist/types/types/ApiCallOptions.d.ts.map +1 -0
- package/dist/types/types/ApiMethodArguments.d.ts +6 -0
- package/dist/types/types/ApiMethodArguments.d.ts.map +1 -0
- package/dist/types/types/ApiMethodOptions.d.ts +8 -0
- package/dist/types/types/ApiMethodOptions.d.ts.map +1 -0
- package/dist/types/types/ApiMethodTypes.d.ts +47 -0
- package/dist/types/types/ApiMethodTypes.d.ts.map +1 -0
- package/dist/types/types/HttpResponse.d.ts +2 -0
- package/dist/types/types/HttpResponse.d.ts.map +1 -0
- package/dist/types/types/httpClientTypes.d.ts +2 -0
- package/dist/types/types/httpClientTypes.d.ts.map +1 -0
- package/dist/types/utils/SortTypeFromSortDirection.d.ts +13 -0
- package/dist/types/utils/SortTypeFromSortDirection.d.ts.map +1 -0
- package/dist/types/utils/buildQuery.d.ts +16 -0
- package/dist/types/utils/buildQuery.d.ts.map +1 -0
- package/dist/types/utils/extractArgsCallbacksAndParams.d.ts +22 -0
- package/dist/types/utils/extractArgsCallbacksAndParams.d.ts.map +1 -0
- package/dist/types/utils/extractArgsToastsAndParams.d.ts +20 -0
- package/dist/types/utils/extractArgsToastsAndParams.d.ts.map +1 -0
- package/dist/types/utils/handleApiResponse.d.ts +12 -0
- package/dist/types/utils/handleApiResponse.d.ts.map +1 -0
- package/dist/types/utils/toFormData.d.ts +10 -0
- package/dist/types/utils/toFormData.d.ts.map +1 -0
- package/dist/types/utils/wireMapping.d.ts +30 -0
- package/dist/types/utils/wireMapping.d.ts.map +1 -0
- package/package.json +90 -84
- package/scripts/build.mjs +74 -0
- package/scripts/generate-api-minimal.mjs +568 -476
- package/scripts/openapi-generator/controller-template.mjs +1 -1
- package/scripts/openapi-generator/index.mjs +348 -113
- package/scripts/openapi-generator/method-template.mjs +405 -440
- package/scripts/openapi-generator/names.mjs +37 -86
- package/scripts/openapi-generator/openapi-utils.mjs +411 -147
- package/scripts/openapi-generator/schema.mjs +737 -455
- package/dist/index.cjs +0 -536
- package/dist/index.d.cts +0 -285
- package/dist/index.d.ts +0 -285
- package/dist/index.js +0 -495
package/dist/index.d.cts
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
type QueryParamsType = object;
|
|
2
|
-
type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
|
|
3
|
-
type CancelToken = symbol | string | number;
|
|
4
|
-
declare const ContentType: {
|
|
5
|
-
readonly Json: "application/json";
|
|
6
|
-
readonly JsonApi: "application/vnd.api+json";
|
|
7
|
-
readonly FormData: "multipart/form-data";
|
|
8
|
-
readonly UrlEncoded: "application/x-www-form-urlencoded";
|
|
9
|
-
readonly Text: "text/plain";
|
|
10
|
-
};
|
|
11
|
-
type ContentType = (typeof ContentType)[keyof typeof ContentType];
|
|
12
|
-
interface FullRequestParams extends Omit<RequestInit, "body"> {
|
|
13
|
-
secure?: boolean;
|
|
14
|
-
path: string;
|
|
15
|
-
type?: ContentType;
|
|
16
|
-
query?: QueryParamsType;
|
|
17
|
-
format?: ResponseFormat;
|
|
18
|
-
body?: unknown;
|
|
19
|
-
baseUrl?: string;
|
|
20
|
-
cancelToken?: CancelToken;
|
|
21
|
-
}
|
|
22
|
-
type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
|
|
23
|
-
type RuntimeRequestParams = RequestParams;
|
|
24
|
-
interface ApiConfig<SecurityDataType = unknown> {
|
|
25
|
-
baseUrl?: string;
|
|
26
|
-
baseApiParams?: Omit<RequestParams, "baseUrl" | "cancelToken" | "signal">;
|
|
27
|
-
securityWorker?: (securityData: SecurityDataType | null) => Promise<RequestParams | void> | RequestParams | void;
|
|
28
|
-
customFetch?: typeof fetch;
|
|
29
|
-
}
|
|
30
|
-
interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response {
|
|
31
|
-
data: D;
|
|
32
|
-
error: E;
|
|
33
|
-
}
|
|
34
|
-
declare function createApiClient<SecurityDataType = unknown>(apiConfig?: ApiConfig<SecurityDataType>): {
|
|
35
|
-
configureApiClient: (nextConfig?: ApiConfig<SecurityDataType>) => void;
|
|
36
|
-
setSecurityData: (data: SecurityDataType | null) => void;
|
|
37
|
-
abortRequest: (cancelToken: CancelToken) => void;
|
|
38
|
-
request: <T = unknown, E = unknown>({ body, secure, path, type, query, baseUrl, cancelToken, ...params }: FullRequestParams) => Promise<HttpResponse<T, E>>;
|
|
39
|
-
toQueryString: (rawQuery?: QueryParamsType) => string;
|
|
40
|
-
};
|
|
41
|
-
declare const defaultApiClient: {
|
|
42
|
-
configureApiClient: (nextConfig?: ApiConfig<unknown>) => void;
|
|
43
|
-
setSecurityData: (data: unknown) => void;
|
|
44
|
-
abortRequest: (cancelToken: CancelToken) => void;
|
|
45
|
-
request: <T = unknown, E = unknown>({ body, secure, path, type, query, baseUrl, cancelToken, ...params }: FullRequestParams) => Promise<HttpResponse<T, E>>;
|
|
46
|
-
toQueryString: (rawQuery?: QueryParamsType) => string;
|
|
47
|
-
};
|
|
48
|
-
declare const configureApiClient: (nextConfig?: ApiConfig<unknown>) => void;
|
|
49
|
-
declare const setSecurityData: (data: unknown) => void;
|
|
50
|
-
declare const abortRequest: (cancelToken: CancelToken) => void;
|
|
51
|
-
declare const request: <T = unknown, E = unknown>({ body, secure, path, type, query, baseUrl, cancelToken, ...params }: FullRequestParams) => Promise<HttpResponse<T, E>>;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Standard result wrapper returned by generated API wrapper methods.
|
|
55
|
-
*
|
|
56
|
-
* When `ok` is true, the request succeeded and `response` contains the expected data.
|
|
57
|
-
* When `ok` is false, the request failed and `error` contains the thrown or returned error value.
|
|
58
|
-
*/
|
|
59
|
-
type ApiResult<TResponse, TError = unknown> = {
|
|
60
|
-
ok: true;
|
|
61
|
-
status: number;
|
|
62
|
-
response: TResponse;
|
|
63
|
-
error?: never;
|
|
64
|
-
} | {
|
|
65
|
-
ok: false;
|
|
66
|
-
status: number;
|
|
67
|
-
response?: undefined;
|
|
68
|
-
error: TError;
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Narrowed success branch of `ApiResult<T>`.
|
|
72
|
-
*
|
|
73
|
-
* Use this type for success callbacks or helper functions that should only receive successful API results.
|
|
74
|
-
*/
|
|
75
|
-
type ApiSuccessResult<TResponse, TError = unknown> = Extract<ApiResult<TResponse, TError>, {
|
|
76
|
-
ok: true;
|
|
77
|
-
}>;
|
|
78
|
-
/**
|
|
79
|
-
* Narrowed error branch of `ApiResult<T>`.
|
|
80
|
-
*
|
|
81
|
-
* Use this type for error callbacks or helper functions that should only receive failed API results.
|
|
82
|
-
*/
|
|
83
|
-
type ApiErrorResult<TResponse, TError = unknown> = Extract<ApiResult<TResponse, TError>, {
|
|
84
|
-
ok: false;
|
|
85
|
-
}>;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Supported filter input types used by typed filter forms.
|
|
89
|
-
*
|
|
90
|
-
* These values decide which UI input should be rendered for a filter.
|
|
91
|
-
*/
|
|
92
|
-
type FilterType = "number" | "date" | "string" | "timespan" | "boolean" | "boolean-button" | "OptionValue";
|
|
93
|
-
/**
|
|
94
|
-
* Selectable option value used by option-based filters.
|
|
95
|
-
*
|
|
96
|
-
* `name` is shown in the UI and `value` is sent as the actual filter value.
|
|
97
|
-
*/
|
|
98
|
-
interface OptionValue {
|
|
99
|
-
name: string;
|
|
100
|
-
value: number | string | Date;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Configuration for one filter field in a typed filter form.
|
|
104
|
-
*
|
|
105
|
-
* `filterName` maps the form value to a query property.
|
|
106
|
-
* `filterNameMax` can be used for range filters such as dates or numbers.
|
|
107
|
-
*/
|
|
108
|
-
interface FilterFormValues<TQuery> {
|
|
109
|
-
name: string;
|
|
110
|
-
filterName: keyof TQuery;
|
|
111
|
-
filterNameMax?: keyof TQuery;
|
|
112
|
-
type: FilterType;
|
|
113
|
-
value: number | string | Date | boolean | null | OptionValue[] | string[];
|
|
114
|
-
maxValue?: number | string | Date | null;
|
|
115
|
-
isAList: boolean;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Sort state used by UI components.
|
|
120
|
-
*
|
|
121
|
-
* `Neutral` represents an explicit neutral sorting state.
|
|
122
|
-
*/
|
|
123
|
-
type SortType = "Default" | "Neutral" | "Ascending" | "Descending";
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Extracts the successful response body type from a generated API method promise.
|
|
127
|
-
*
|
|
128
|
-
* Example: `Promise<HttpResponse<Product, Error>>` becomes `Product`.
|
|
129
|
-
*/
|
|
130
|
-
type ExtractResponse<T> = T extends Promise<HttpResponse<infer Response, unknown>> ? Response : never;
|
|
131
|
-
/**
|
|
132
|
-
* Extracts the error response body type from a generated API method promise.
|
|
133
|
-
*
|
|
134
|
-
* Example: `Promise<HttpResponse<Product, ApiError>>` becomes `ApiError`.
|
|
135
|
-
*/
|
|
136
|
-
type ExtractError<T> = T extends Promise<HttpResponse<unknown, infer Error>> ? Error : never;
|
|
137
|
-
/**
|
|
138
|
-
* Extracts the item type from an array, otherwise returns the original type.
|
|
139
|
-
*
|
|
140
|
-
* Example: `Product[]` becomes `Product`, while `Product` stays `Product`.
|
|
141
|
-
*/
|
|
142
|
-
type UnwrapArray<T> = T extends readonly (infer Item)[] ? Item : T;
|
|
143
|
-
/**
|
|
144
|
-
* Extracts the item type from common paginated response shapes.
|
|
145
|
-
*
|
|
146
|
-
* Example: `{ data?: Product[] }` becomes `Product`.
|
|
147
|
-
*/
|
|
148
|
-
type ExtractDataIfPaginated<T> = T extends {
|
|
149
|
-
data?: readonly (infer Item)[] | null;
|
|
150
|
-
} ? Item : T;
|
|
151
|
-
/**
|
|
152
|
-
* Keys that can be used as sort fields for an API response type.
|
|
153
|
-
*
|
|
154
|
-
* For paginated responses this uses the keys of the item inside `data`.
|
|
155
|
-
*/
|
|
156
|
-
type SortableKeys<T> = keyof UnwrapArray<ExtractDataIfPaginated<T>>;
|
|
157
|
-
/**
|
|
158
|
-
* Removes the optional RequestParams argument from the end
|
|
159
|
-
* of a generated API method parameter tuple.
|
|
160
|
-
*
|
|
161
|
-
* Example:
|
|
162
|
-
*
|
|
163
|
-
* [data: CreateSupplierParams, params?: RequestParams]
|
|
164
|
-
*
|
|
165
|
-
* becomes:
|
|
166
|
-
*
|
|
167
|
-
* [data: CreateSupplierParams]
|
|
168
|
-
*/
|
|
169
|
-
type WithoutRequestParams<T extends readonly unknown[]> = T extends readonly [...infer Arguments, RequestParams?] ? Arguments : T;
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Function called after a generated wrapper method receives a successful API result.
|
|
173
|
-
*
|
|
174
|
-
* The callback receives the success-only branch of `ApiResult<TResponse>`.
|
|
175
|
-
*/
|
|
176
|
-
type ApiSuccessHandler<TResponse> = (result: ApiSuccessResult<TResponse>) => void | Promise<void>;
|
|
177
|
-
/**
|
|
178
|
-
* Function called after a generated wrapper method receives a failed API result.
|
|
179
|
-
*
|
|
180
|
-
* The callback receives the error-only branch of `ApiResult<TResponse>`.
|
|
181
|
-
*/
|
|
182
|
-
type ApiErrorHandler<TResponse, TError = unknown> = (result: ApiErrorResult<TResponse, TError>) => void | Promise<void>;
|
|
183
|
-
/**
|
|
184
|
-
* Optional callback and request-parameter object accepted by generated API wrapper methods.
|
|
185
|
-
*
|
|
186
|
-
* `onSuccess` runs for successful responses, `onError` runs for failed responses,
|
|
187
|
-
* and `params` is forwarded to the generated HTTP client.
|
|
188
|
-
*/
|
|
189
|
-
type ApiMethodCallbacks<TResponse, TError = unknown, TRequestParams = RequestParams> = {
|
|
190
|
-
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
191
|
-
onError?: ApiErrorHandler<TResponse, TError>;
|
|
192
|
-
params?: TRequestParams;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
type ApiMethodOptions<TResponse, TError = unknown, TRequestParams = RuntimeRequestParams> = {
|
|
196
|
-
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
197
|
-
onError?: ApiErrorHandler<TResponse, TError>;
|
|
198
|
-
params?: TRequestParams;
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
type ApiMethodArguments<TMethod extends (...args: any[]) => unknown, TRequestParams = RuntimeRequestParams> = Parameters<TMethod> extends [
|
|
202
|
-
...infer Arguments,
|
|
203
|
-
TRequestParams?
|
|
204
|
-
] ? Arguments : Parameters<TMethod>;
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Sort direction value accepted by generated query objects.
|
|
208
|
-
*
|
|
209
|
-
* APIs often expose sort direction as either a string enum or numeric enum, so both are supported.
|
|
210
|
-
*/
|
|
211
|
-
type SortDirection = number | string;
|
|
212
|
-
/**
|
|
213
|
-
* Builds a typed query object from filter form values, pagination, and sorting.
|
|
214
|
-
*
|
|
215
|
-
* Empty filter values are ignored.
|
|
216
|
-
* List filters are converted item by item.
|
|
217
|
-
* `OptionValue` lists send their `value` fields instead of the display names.
|
|
218
|
-
*/
|
|
219
|
-
declare function buildQuery<TQuery, TSortModel = TQuery>(filters: FilterFormValues<TQuery>[], page?: number, pageSize?: number, sortBy?: keyof TSortModel | null, sortDirection?: SortDirection): Partial<TQuery>;
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Extracts wrapper-only arguments in this order:
|
|
223
|
-
* original API arguments, onSuccess, onError, request params.
|
|
224
|
-
*
|
|
225
|
-
* Kept for backwards compatibility with generated files that used toast-oriented naming.
|
|
226
|
-
*/
|
|
227
|
-
declare function extractArgsToastsAndParams<TArgs extends readonly unknown[], TResponse>(argsWithCallbacks: [
|
|
228
|
-
...TArgs,
|
|
229
|
-
ApiSuccessHandler<TResponse>?,
|
|
230
|
-
ApiErrorHandler<TResponse>?,
|
|
231
|
-
RuntimeRequestParams?
|
|
232
|
-
]): {
|
|
233
|
-
args: TArgs;
|
|
234
|
-
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
235
|
-
onError?: ApiErrorHandler<TResponse>;
|
|
236
|
-
params?: RuntimeRequestParams;
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Extracts wrapper arguments in this order:
|
|
241
|
-
*
|
|
242
|
-
* 1. Original API arguments
|
|
243
|
-
* 2. Optional success callback
|
|
244
|
-
* 3. Optional error callback
|
|
245
|
-
* 4. Optional request params
|
|
246
|
-
*/
|
|
247
|
-
declare function extractArgsCallbacksAndParams<TArgs extends unknown[], TResponse, _TError = unknown>(argsWithCallbacks: [
|
|
248
|
-
...TArgs,
|
|
249
|
-
ApiSuccessHandler<TResponse>?,
|
|
250
|
-
ApiErrorHandler<TResponse>?,
|
|
251
|
-
RuntimeRequestParams?
|
|
252
|
-
]): {
|
|
253
|
-
args: TArgs;
|
|
254
|
-
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
255
|
-
onError?: ApiErrorHandler<TResponse>;
|
|
256
|
-
params?: RuntimeRequestParams;
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
type HandleApiResponseOptions<TResponse, TError = unknown> = {
|
|
260
|
-
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
261
|
-
onError?: ApiErrorHandler<TResponse, TError>;
|
|
262
|
-
};
|
|
263
|
-
declare function handleApiResponse<TResponse, TError = unknown>(call: () => Promise<HttpResponse<TResponse, TError>>, options?: HandleApiResponseOptions<TResponse, TError>): Promise<ApiResult<TResponse, TError>>;
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Values supported by the current TypedApi .NET SortDirection enum.
|
|
267
|
-
* The legacy long names remain accepted when reading older APIs.
|
|
268
|
-
*/
|
|
269
|
-
type ApiSortDirection = "Default" | "Neutral" | "Asc" | "Desc" | "Ascending" | "Descending";
|
|
270
|
-
/** Sort states supported by TypedApi UI components. */
|
|
271
|
-
declare const sortTypes: readonly ["Default", "Neutral", "Ascending", "Descending"];
|
|
272
|
-
/** Converts API sort direction values to the sort state used by UI components. */
|
|
273
|
-
declare function getSortTypeFromSortDirection(sortDirection: ApiSortDirection | null | undefined): SortType;
|
|
274
|
-
/** Converts a UI sort state to a value accepted by the current .NET API. */
|
|
275
|
-
declare function getSortDirectionFromSortType(sortType: SortType | null | undefined): Extract<ApiSortDirection, "Default" | "Neutral" | "Asc" | "Desc">;
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Converts an object payload into `FormData`.
|
|
279
|
-
*
|
|
280
|
-
* Supports single files, file arrays, primitive values, and nested objects.
|
|
281
|
-
* Arrays are appended as repeated fields with the same key.
|
|
282
|
-
*/
|
|
283
|
-
declare function toFormData<T extends object>(payload: T): FormData;
|
|
284
|
-
|
|
285
|
-
export { type ApiConfig, type ApiErrorHandler, type ApiErrorResult, type ApiMethodArguments, type ApiMethodCallbacks, type ApiMethodOptions, type ApiResult, type ApiSortDirection, type ApiSuccessHandler, type ApiSuccessResult, type CancelToken, ContentType, type ExtractDataIfPaginated, type ExtractError, type ExtractResponse, type FilterFormValues, type FilterType, type FullRequestParams, type HandleApiResponseOptions, type HttpResponse, type OptionValue, type QueryParamsType, type RequestParams, type ResponseFormat, type RuntimeRequestParams, type SortDirection, type SortType, type SortableKeys, type UnwrapArray, type WithoutRequestParams, abortRequest, buildQuery, configureApiClient, createApiClient, defaultApiClient, extractArgsCallbacksAndParams, extractArgsToastsAndParams, getSortDirectionFromSortType, getSortTypeFromSortDirection, handleApiResponse, request, setSecurityData, sortTypes, toFormData };
|
package/dist/index.d.ts
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
type QueryParamsType = object;
|
|
2
|
-
type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
|
|
3
|
-
type CancelToken = symbol | string | number;
|
|
4
|
-
declare const ContentType: {
|
|
5
|
-
readonly Json: "application/json";
|
|
6
|
-
readonly JsonApi: "application/vnd.api+json";
|
|
7
|
-
readonly FormData: "multipart/form-data";
|
|
8
|
-
readonly UrlEncoded: "application/x-www-form-urlencoded";
|
|
9
|
-
readonly Text: "text/plain";
|
|
10
|
-
};
|
|
11
|
-
type ContentType = (typeof ContentType)[keyof typeof ContentType];
|
|
12
|
-
interface FullRequestParams extends Omit<RequestInit, "body"> {
|
|
13
|
-
secure?: boolean;
|
|
14
|
-
path: string;
|
|
15
|
-
type?: ContentType;
|
|
16
|
-
query?: QueryParamsType;
|
|
17
|
-
format?: ResponseFormat;
|
|
18
|
-
body?: unknown;
|
|
19
|
-
baseUrl?: string;
|
|
20
|
-
cancelToken?: CancelToken;
|
|
21
|
-
}
|
|
22
|
-
type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
|
|
23
|
-
type RuntimeRequestParams = RequestParams;
|
|
24
|
-
interface ApiConfig<SecurityDataType = unknown> {
|
|
25
|
-
baseUrl?: string;
|
|
26
|
-
baseApiParams?: Omit<RequestParams, "baseUrl" | "cancelToken" | "signal">;
|
|
27
|
-
securityWorker?: (securityData: SecurityDataType | null) => Promise<RequestParams | void> | RequestParams | void;
|
|
28
|
-
customFetch?: typeof fetch;
|
|
29
|
-
}
|
|
30
|
-
interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response {
|
|
31
|
-
data: D;
|
|
32
|
-
error: E;
|
|
33
|
-
}
|
|
34
|
-
declare function createApiClient<SecurityDataType = unknown>(apiConfig?: ApiConfig<SecurityDataType>): {
|
|
35
|
-
configureApiClient: (nextConfig?: ApiConfig<SecurityDataType>) => void;
|
|
36
|
-
setSecurityData: (data: SecurityDataType | null) => void;
|
|
37
|
-
abortRequest: (cancelToken: CancelToken) => void;
|
|
38
|
-
request: <T = unknown, E = unknown>({ body, secure, path, type, query, baseUrl, cancelToken, ...params }: FullRequestParams) => Promise<HttpResponse<T, E>>;
|
|
39
|
-
toQueryString: (rawQuery?: QueryParamsType) => string;
|
|
40
|
-
};
|
|
41
|
-
declare const defaultApiClient: {
|
|
42
|
-
configureApiClient: (nextConfig?: ApiConfig<unknown>) => void;
|
|
43
|
-
setSecurityData: (data: unknown) => void;
|
|
44
|
-
abortRequest: (cancelToken: CancelToken) => void;
|
|
45
|
-
request: <T = unknown, E = unknown>({ body, secure, path, type, query, baseUrl, cancelToken, ...params }: FullRequestParams) => Promise<HttpResponse<T, E>>;
|
|
46
|
-
toQueryString: (rawQuery?: QueryParamsType) => string;
|
|
47
|
-
};
|
|
48
|
-
declare const configureApiClient: (nextConfig?: ApiConfig<unknown>) => void;
|
|
49
|
-
declare const setSecurityData: (data: unknown) => void;
|
|
50
|
-
declare const abortRequest: (cancelToken: CancelToken) => void;
|
|
51
|
-
declare const request: <T = unknown, E = unknown>({ body, secure, path, type, query, baseUrl, cancelToken, ...params }: FullRequestParams) => Promise<HttpResponse<T, E>>;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Standard result wrapper returned by generated API wrapper methods.
|
|
55
|
-
*
|
|
56
|
-
* When `ok` is true, the request succeeded and `response` contains the expected data.
|
|
57
|
-
* When `ok` is false, the request failed and `error` contains the thrown or returned error value.
|
|
58
|
-
*/
|
|
59
|
-
type ApiResult<TResponse, TError = unknown> = {
|
|
60
|
-
ok: true;
|
|
61
|
-
status: number;
|
|
62
|
-
response: TResponse;
|
|
63
|
-
error?: never;
|
|
64
|
-
} | {
|
|
65
|
-
ok: false;
|
|
66
|
-
status: number;
|
|
67
|
-
response?: undefined;
|
|
68
|
-
error: TError;
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Narrowed success branch of `ApiResult<T>`.
|
|
72
|
-
*
|
|
73
|
-
* Use this type for success callbacks or helper functions that should only receive successful API results.
|
|
74
|
-
*/
|
|
75
|
-
type ApiSuccessResult<TResponse, TError = unknown> = Extract<ApiResult<TResponse, TError>, {
|
|
76
|
-
ok: true;
|
|
77
|
-
}>;
|
|
78
|
-
/**
|
|
79
|
-
* Narrowed error branch of `ApiResult<T>`.
|
|
80
|
-
*
|
|
81
|
-
* Use this type for error callbacks or helper functions that should only receive failed API results.
|
|
82
|
-
*/
|
|
83
|
-
type ApiErrorResult<TResponse, TError = unknown> = Extract<ApiResult<TResponse, TError>, {
|
|
84
|
-
ok: false;
|
|
85
|
-
}>;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Supported filter input types used by typed filter forms.
|
|
89
|
-
*
|
|
90
|
-
* These values decide which UI input should be rendered for a filter.
|
|
91
|
-
*/
|
|
92
|
-
type FilterType = "number" | "date" | "string" | "timespan" | "boolean" | "boolean-button" | "OptionValue";
|
|
93
|
-
/**
|
|
94
|
-
* Selectable option value used by option-based filters.
|
|
95
|
-
*
|
|
96
|
-
* `name` is shown in the UI and `value` is sent as the actual filter value.
|
|
97
|
-
*/
|
|
98
|
-
interface OptionValue {
|
|
99
|
-
name: string;
|
|
100
|
-
value: number | string | Date;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Configuration for one filter field in a typed filter form.
|
|
104
|
-
*
|
|
105
|
-
* `filterName` maps the form value to a query property.
|
|
106
|
-
* `filterNameMax` can be used for range filters such as dates or numbers.
|
|
107
|
-
*/
|
|
108
|
-
interface FilterFormValues<TQuery> {
|
|
109
|
-
name: string;
|
|
110
|
-
filterName: keyof TQuery;
|
|
111
|
-
filterNameMax?: keyof TQuery;
|
|
112
|
-
type: FilterType;
|
|
113
|
-
value: number | string | Date | boolean | null | OptionValue[] | string[];
|
|
114
|
-
maxValue?: number | string | Date | null;
|
|
115
|
-
isAList: boolean;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Sort state used by UI components.
|
|
120
|
-
*
|
|
121
|
-
* `Neutral` represents an explicit neutral sorting state.
|
|
122
|
-
*/
|
|
123
|
-
type SortType = "Default" | "Neutral" | "Ascending" | "Descending";
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Extracts the successful response body type from a generated API method promise.
|
|
127
|
-
*
|
|
128
|
-
* Example: `Promise<HttpResponse<Product, Error>>` becomes `Product`.
|
|
129
|
-
*/
|
|
130
|
-
type ExtractResponse<T> = T extends Promise<HttpResponse<infer Response, unknown>> ? Response : never;
|
|
131
|
-
/**
|
|
132
|
-
* Extracts the error response body type from a generated API method promise.
|
|
133
|
-
*
|
|
134
|
-
* Example: `Promise<HttpResponse<Product, ApiError>>` becomes `ApiError`.
|
|
135
|
-
*/
|
|
136
|
-
type ExtractError<T> = T extends Promise<HttpResponse<unknown, infer Error>> ? Error : never;
|
|
137
|
-
/**
|
|
138
|
-
* Extracts the item type from an array, otherwise returns the original type.
|
|
139
|
-
*
|
|
140
|
-
* Example: `Product[]` becomes `Product`, while `Product` stays `Product`.
|
|
141
|
-
*/
|
|
142
|
-
type UnwrapArray<T> = T extends readonly (infer Item)[] ? Item : T;
|
|
143
|
-
/**
|
|
144
|
-
* Extracts the item type from common paginated response shapes.
|
|
145
|
-
*
|
|
146
|
-
* Example: `{ data?: Product[] }` becomes `Product`.
|
|
147
|
-
*/
|
|
148
|
-
type ExtractDataIfPaginated<T> = T extends {
|
|
149
|
-
data?: readonly (infer Item)[] | null;
|
|
150
|
-
} ? Item : T;
|
|
151
|
-
/**
|
|
152
|
-
* Keys that can be used as sort fields for an API response type.
|
|
153
|
-
*
|
|
154
|
-
* For paginated responses this uses the keys of the item inside `data`.
|
|
155
|
-
*/
|
|
156
|
-
type SortableKeys<T> = keyof UnwrapArray<ExtractDataIfPaginated<T>>;
|
|
157
|
-
/**
|
|
158
|
-
* Removes the optional RequestParams argument from the end
|
|
159
|
-
* of a generated API method parameter tuple.
|
|
160
|
-
*
|
|
161
|
-
* Example:
|
|
162
|
-
*
|
|
163
|
-
* [data: CreateSupplierParams, params?: RequestParams]
|
|
164
|
-
*
|
|
165
|
-
* becomes:
|
|
166
|
-
*
|
|
167
|
-
* [data: CreateSupplierParams]
|
|
168
|
-
*/
|
|
169
|
-
type WithoutRequestParams<T extends readonly unknown[]> = T extends readonly [...infer Arguments, RequestParams?] ? Arguments : T;
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Function called after a generated wrapper method receives a successful API result.
|
|
173
|
-
*
|
|
174
|
-
* The callback receives the success-only branch of `ApiResult<TResponse>`.
|
|
175
|
-
*/
|
|
176
|
-
type ApiSuccessHandler<TResponse> = (result: ApiSuccessResult<TResponse>) => void | Promise<void>;
|
|
177
|
-
/**
|
|
178
|
-
* Function called after a generated wrapper method receives a failed API result.
|
|
179
|
-
*
|
|
180
|
-
* The callback receives the error-only branch of `ApiResult<TResponse>`.
|
|
181
|
-
*/
|
|
182
|
-
type ApiErrorHandler<TResponse, TError = unknown> = (result: ApiErrorResult<TResponse, TError>) => void | Promise<void>;
|
|
183
|
-
/**
|
|
184
|
-
* Optional callback and request-parameter object accepted by generated API wrapper methods.
|
|
185
|
-
*
|
|
186
|
-
* `onSuccess` runs for successful responses, `onError` runs for failed responses,
|
|
187
|
-
* and `params` is forwarded to the generated HTTP client.
|
|
188
|
-
*/
|
|
189
|
-
type ApiMethodCallbacks<TResponse, TError = unknown, TRequestParams = RequestParams> = {
|
|
190
|
-
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
191
|
-
onError?: ApiErrorHandler<TResponse, TError>;
|
|
192
|
-
params?: TRequestParams;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
type ApiMethodOptions<TResponse, TError = unknown, TRequestParams = RuntimeRequestParams> = {
|
|
196
|
-
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
197
|
-
onError?: ApiErrorHandler<TResponse, TError>;
|
|
198
|
-
params?: TRequestParams;
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
type ApiMethodArguments<TMethod extends (...args: any[]) => unknown, TRequestParams = RuntimeRequestParams> = Parameters<TMethod> extends [
|
|
202
|
-
...infer Arguments,
|
|
203
|
-
TRequestParams?
|
|
204
|
-
] ? Arguments : Parameters<TMethod>;
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Sort direction value accepted by generated query objects.
|
|
208
|
-
*
|
|
209
|
-
* APIs often expose sort direction as either a string enum or numeric enum, so both are supported.
|
|
210
|
-
*/
|
|
211
|
-
type SortDirection = number | string;
|
|
212
|
-
/**
|
|
213
|
-
* Builds a typed query object from filter form values, pagination, and sorting.
|
|
214
|
-
*
|
|
215
|
-
* Empty filter values are ignored.
|
|
216
|
-
* List filters are converted item by item.
|
|
217
|
-
* `OptionValue` lists send their `value` fields instead of the display names.
|
|
218
|
-
*/
|
|
219
|
-
declare function buildQuery<TQuery, TSortModel = TQuery>(filters: FilterFormValues<TQuery>[], page?: number, pageSize?: number, sortBy?: keyof TSortModel | null, sortDirection?: SortDirection): Partial<TQuery>;
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Extracts wrapper-only arguments in this order:
|
|
223
|
-
* original API arguments, onSuccess, onError, request params.
|
|
224
|
-
*
|
|
225
|
-
* Kept for backwards compatibility with generated files that used toast-oriented naming.
|
|
226
|
-
*/
|
|
227
|
-
declare function extractArgsToastsAndParams<TArgs extends readonly unknown[], TResponse>(argsWithCallbacks: [
|
|
228
|
-
...TArgs,
|
|
229
|
-
ApiSuccessHandler<TResponse>?,
|
|
230
|
-
ApiErrorHandler<TResponse>?,
|
|
231
|
-
RuntimeRequestParams?
|
|
232
|
-
]): {
|
|
233
|
-
args: TArgs;
|
|
234
|
-
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
235
|
-
onError?: ApiErrorHandler<TResponse>;
|
|
236
|
-
params?: RuntimeRequestParams;
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Extracts wrapper arguments in this order:
|
|
241
|
-
*
|
|
242
|
-
* 1. Original API arguments
|
|
243
|
-
* 2. Optional success callback
|
|
244
|
-
* 3. Optional error callback
|
|
245
|
-
* 4. Optional request params
|
|
246
|
-
*/
|
|
247
|
-
declare function extractArgsCallbacksAndParams<TArgs extends unknown[], TResponse, _TError = unknown>(argsWithCallbacks: [
|
|
248
|
-
...TArgs,
|
|
249
|
-
ApiSuccessHandler<TResponse>?,
|
|
250
|
-
ApiErrorHandler<TResponse>?,
|
|
251
|
-
RuntimeRequestParams?
|
|
252
|
-
]): {
|
|
253
|
-
args: TArgs;
|
|
254
|
-
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
255
|
-
onError?: ApiErrorHandler<TResponse>;
|
|
256
|
-
params?: RuntimeRequestParams;
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
type HandleApiResponseOptions<TResponse, TError = unknown> = {
|
|
260
|
-
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
261
|
-
onError?: ApiErrorHandler<TResponse, TError>;
|
|
262
|
-
};
|
|
263
|
-
declare function handleApiResponse<TResponse, TError = unknown>(call: () => Promise<HttpResponse<TResponse, TError>>, options?: HandleApiResponseOptions<TResponse, TError>): Promise<ApiResult<TResponse, TError>>;
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Values supported by the current TypedApi .NET SortDirection enum.
|
|
267
|
-
* The legacy long names remain accepted when reading older APIs.
|
|
268
|
-
*/
|
|
269
|
-
type ApiSortDirection = "Default" | "Neutral" | "Asc" | "Desc" | "Ascending" | "Descending";
|
|
270
|
-
/** Sort states supported by TypedApi UI components. */
|
|
271
|
-
declare const sortTypes: readonly ["Default", "Neutral", "Ascending", "Descending"];
|
|
272
|
-
/** Converts API sort direction values to the sort state used by UI components. */
|
|
273
|
-
declare function getSortTypeFromSortDirection(sortDirection: ApiSortDirection | null | undefined): SortType;
|
|
274
|
-
/** Converts a UI sort state to a value accepted by the current .NET API. */
|
|
275
|
-
declare function getSortDirectionFromSortType(sortType: SortType | null | undefined): Extract<ApiSortDirection, "Default" | "Neutral" | "Asc" | "Desc">;
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Converts an object payload into `FormData`.
|
|
279
|
-
*
|
|
280
|
-
* Supports single files, file arrays, primitive values, and nested objects.
|
|
281
|
-
* Arrays are appended as repeated fields with the same key.
|
|
282
|
-
*/
|
|
283
|
-
declare function toFormData<T extends object>(payload: T): FormData;
|
|
284
|
-
|
|
285
|
-
export { type ApiConfig, type ApiErrorHandler, type ApiErrorResult, type ApiMethodArguments, type ApiMethodCallbacks, type ApiMethodOptions, type ApiResult, type ApiSortDirection, type ApiSuccessHandler, type ApiSuccessResult, type CancelToken, ContentType, type ExtractDataIfPaginated, type ExtractError, type ExtractResponse, type FilterFormValues, type FilterType, type FullRequestParams, type HandleApiResponseOptions, type HttpResponse, type OptionValue, type QueryParamsType, type RequestParams, type ResponseFormat, type RuntimeRequestParams, type SortDirection, type SortType, type SortableKeys, type UnwrapArray, type WithoutRequestParams, abortRequest, buildQuery, configureApiClient, createApiClient, defaultApiClient, extractArgsCallbacksAndParams, extractArgsToastsAndParams, getSortDirectionFromSortType, getSortTypeFromSortDirection, handleApiResponse, request, setSecurityData, sortTypes, toFormData };
|