typedapi-client-helpers 0.1.16 → 0.2.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/LICENSE +21 -0
- package/README.md +220 -490
- package/dist/index.cjs +274 -47
- package/dist/index.d.cts +79 -95
- package/dist/index.d.ts +79 -95
- package/dist/index.js +267 -47
- package/package.json +32 -13
- package/scripts/generate-api-minimal.mjs +158 -785
- package/scripts/openapi-generator/controller-template.mjs +246 -0
- package/scripts/openapi-generator/http-client-template.mjs +34 -0
- package/scripts/openapi-generator/index.mjs +113 -0
- package/scripts/openapi-generator/method-template.mjs +440 -0
- package/scripts/openapi-generator/names.mjs +145 -0
- package/scripts/openapi-generator/openapi-utils.mjs +147 -0
- package/scripts/openapi-generator/schema.mjs +455 -0
- package/bin/typedapi-generate.js +0 -3
- package/dist/api/generated/Import.d.ts +0 -22
- package/dist/api/generated/Import.d.ts.map +0 -1
- package/dist/api/generated/Import.js +0 -48
- package/dist/api/generated/Import.js.map +0 -1
- package/dist/api/generated/ImportRoute.d.ts +0 -30
- package/dist/api/generated/ImportRoute.d.ts.map +0 -1
- package/dist/api/generated/ImportRoute.js +0 -13
- package/dist/api/generated/ImportRoute.js.map +0 -1
- package/dist/api/generated/Order.d.ts +0 -38
- package/dist/api/generated/Order.d.ts.map +0 -1
- package/dist/api/generated/Order.js +0 -75
- package/dist/api/generated/Order.js.map +0 -1
- package/dist/api/generated/OrderRoute.d.ts +0 -83
- package/dist/api/generated/OrderRoute.d.ts.map +0 -1
- package/dist/api/generated/OrderRoute.js +0 -13
- package/dist/api/generated/OrderRoute.js.map +0 -1
- package/dist/api/generated/Product.d.ts +0 -62
- package/dist/api/generated/Product.d.ts.map +0 -1
- package/dist/api/generated/Product.js +0 -114
- package/dist/api/generated/Product.js.map +0 -1
- package/dist/api/generated/ProductRoute.d.ts +0 -140
- package/dist/api/generated/ProductRoute.d.ts.map +0 -1
- package/dist/api/generated/ProductRoute.js +0 -13
- package/dist/api/generated/ProductRoute.js.map +0 -1
- package/dist/api/generated/Report.d.ts +0 -14
- package/dist/api/generated/Report.d.ts.map +0 -1
- package/dist/api/generated/Report.js +0 -32
- package/dist/api/generated/Report.js.map +0 -1
- package/dist/api/generated/ReportRoute.d.ts +0 -23
- package/dist/api/generated/ReportRoute.d.ts.map +0 -1
- package/dist/api/generated/ReportRoute.js +0 -13
- package/dist/api/generated/ReportRoute.js.map +0 -1
- package/dist/api/generated/Supplier.d.ts +0 -46
- package/dist/api/generated/Supplier.d.ts.map +0 -1
- package/dist/api/generated/Supplier.js +0 -87
- package/dist/api/generated/Supplier.js.map +0 -1
- package/dist/api/generated/SupplierRoute.d.ts +0 -101
- package/dist/api/generated/SupplierRoute.d.ts.map +0 -1
- package/dist/api/generated/SupplierRoute.js +0 -13
- package/dist/api/generated/SupplierRoute.js.map +0 -1
- package/dist/api/generated/data-contracts.d.ts +0 -277
- package/dist/api/generated/data-contracts.d.ts.map +0 -1
- package/dist/api/generated/data-contracts.js +0 -26
- package/dist/api/generated/data-contracts.js.map +0 -1
- package/dist/api/generated/http-client.d.ts +0 -61
- package/dist/api/generated/http-client.d.ts.map +0 -1
- package/dist/api/generated/http-client.js +0 -171
- package/dist/api/generated/http-client.js.map +0 -1
- package/dist/api/index.d.ts +0 -8
- package/dist/api/index.d.ts.map +0 -1
- package/dist/api/index.js +0 -8
- package/dist/api/index.js.map +0 -1
- package/dist/api/methods/Import.api.d.ts +0 -6
- package/dist/api/methods/Import.api.d.ts.map +0 -1
- package/dist/api/methods/Import.api.js +0 -27
- package/dist/api/methods/Import.api.js.map +0 -1
- package/dist/api/methods/Order.api.d.ts +0 -29
- package/dist/api/methods/Order.api.d.ts.map +0 -1
- package/dist/api/methods/Order.api.js +0 -52
- package/dist/api/methods/Order.api.js.map +0 -1
- package/dist/api/methods/Product.api.d.ts +0 -39
- package/dist/api/methods/Product.api.d.ts.map +0 -1
- package/dist/api/methods/Product.api.js +0 -69
- package/dist/api/methods/Product.api.js.map +0 -1
- package/dist/api/methods/Report.api.d.ts +0 -6
- package/dist/api/methods/Report.api.d.ts.map +0 -1
- package/dist/api/methods/Report.api.js +0 -19
- package/dist/api/methods/Report.api.js.map +0 -1
- package/dist/api/methods/Supplier.api.d.ts +0 -35
- package/dist/api/methods/Supplier.api.d.ts.map +0 -1
- package/dist/api/methods/Supplier.api.js +0 -63
- package/dist/api/methods/Supplier.api.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/interfaces/ApiResult.d.ts +0 -17
- package/dist/interfaces/ApiResult.d.ts.map +0 -1
- package/dist/interfaces/ApiResult.js +0 -2
- package/dist/interfaces/ApiResult.js.map +0 -1
- package/dist/interfaces/Filter.d.ts +0 -31
- package/dist/interfaces/Filter.d.ts.map +0 -1
- package/dist/interfaces/Filter.js +0 -2
- package/dist/interfaces/Filter.js.map +0 -1
- package/dist/interfaces/SortType.d.ts +0 -7
- package/dist/interfaces/SortType.d.ts.map +0 -1
- package/dist/interfaces/SortType.js +0 -2
- package/dist/interfaces/SortType.js.map +0 -1
- package/dist/types/ApiCallOptions.d.ts +0 -9
- package/dist/types/ApiCallOptions.d.ts.map +0 -1
- package/dist/types/ApiCallOptions.js +0 -2
- package/dist/types/ApiCallOptions.js.map +0 -1
- package/dist/types/ApiMethodTypes.d.ts +0 -24
- package/dist/types/ApiMethodTypes.d.ts.map +0 -1
- package/dist/types/ApiMethodTypes.js +0 -2
- package/dist/types/ApiMethodTypes.js.map +0 -1
- package/dist/types/HttpResponse.d.ts +0 -16
- package/dist/types/HttpResponse.d.ts.map +0 -1
- package/dist/types/HttpResponse.js +0 -2
- package/dist/types/HttpResponse.js.map +0 -1
- package/dist/utils/SortTypeFromSortDirection.d.ts +0 -22
- package/dist/utils/SortTypeFromSortDirection.d.ts.map +0 -1
- package/dist/utils/SortTypeFromSortDirection.js +0 -45
- package/dist/utils/SortTypeFromSortDirection.js.map +0 -1
- package/dist/utils/buildQuery.d.ts +0 -11
- package/dist/utils/buildQuery.d.ts.map +0 -1
- package/dist/utils/buildQuery.js +0 -94
- package/dist/utils/buildQuery.js.map +0 -1
- package/dist/utils/extractArgsCallbacksAndParams.d.ts +0 -22
- package/dist/utils/extractArgsCallbacksAndParams.d.ts.map +0 -1
- package/dist/utils/extractArgsCallbacksAndParams.js +0 -44
- package/dist/utils/extractArgsCallbacksAndParams.js.map +0 -1
- package/dist/utils/extractArgsToastsAndParams.d.ts +0 -18
- package/dist/utils/extractArgsToastsAndParams.d.ts.map +0 -1
- package/dist/utils/extractArgsToastsAndParams.js +0 -40
- package/dist/utils/extractArgsToastsAndParams.js.map +0 -1
- package/dist/utils/handleApiResponse.d.ts +0 -9
- package/dist/utils/handleApiResponse.d.ts.map +0 -1
- package/dist/utils/handleApiResponse.js +0 -49
- package/dist/utils/handleApiResponse.js.map +0 -1
- package/dist/utils/toFormData.d.ts +0 -8
- package/dist/utils/toFormData.d.ts.map +0 -1
- package/dist/utils/toFormData.js +0 -68
- package/dist/utils/toFormData.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,25 +1,78 @@
|
|
|
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
|
+
|
|
1
53
|
/**
|
|
2
54
|
* Standard result wrapper returned by generated API wrapper methods.
|
|
3
55
|
*
|
|
4
56
|
* When `ok` is true, the request succeeded and `response` contains the expected data.
|
|
5
57
|
* When `ok` is false, the request failed and `error` contains the thrown or returned error value.
|
|
6
58
|
*/
|
|
7
|
-
type ApiResult<
|
|
59
|
+
type ApiResult<TResponse, TError = unknown> = {
|
|
8
60
|
ok: true;
|
|
9
61
|
status: number;
|
|
10
|
-
response:
|
|
62
|
+
response: TResponse;
|
|
63
|
+
error?: never;
|
|
11
64
|
} | {
|
|
12
65
|
ok: false;
|
|
13
66
|
status: number;
|
|
14
|
-
response?:
|
|
15
|
-
error:
|
|
67
|
+
response?: undefined;
|
|
68
|
+
error: TError;
|
|
16
69
|
};
|
|
17
70
|
/**
|
|
18
71
|
* Narrowed success branch of `ApiResult<T>`.
|
|
19
72
|
*
|
|
20
73
|
* Use this type for success callbacks or helper functions that should only receive successful API results.
|
|
21
74
|
*/
|
|
22
|
-
type ApiSuccessResult<
|
|
75
|
+
type ApiSuccessResult<TResponse, TError = unknown> = Extract<ApiResult<TResponse, TError>, {
|
|
23
76
|
ok: true;
|
|
24
77
|
}>;
|
|
25
78
|
/**
|
|
@@ -27,7 +80,7 @@ type ApiSuccessResult<T> = Extract<ApiResult<T>, {
|
|
|
27
80
|
*
|
|
28
81
|
* Use this type for error callbacks or helper functions that should only receive failed API results.
|
|
29
82
|
*/
|
|
30
|
-
type ApiErrorResult<
|
|
83
|
+
type ApiErrorResult<TResponse, TError = unknown> = Extract<ApiResult<TResponse, TError>, {
|
|
31
84
|
ok: false;
|
|
32
85
|
}>;
|
|
33
86
|
|
|
@@ -65,56 +118,22 @@ interface FilterFormValues<TQuery> {
|
|
|
65
118
|
/**
|
|
66
119
|
* Sort state used by UI components.
|
|
67
120
|
*
|
|
68
|
-
* `Neutral` represents
|
|
121
|
+
* `Neutral` represents an explicit neutral sorting state.
|
|
69
122
|
*/
|
|
70
123
|
type SortType = "Default" | "Neutral" | "Ascending" | "Descending";
|
|
71
124
|
|
|
72
|
-
type QueryParamsType = Record<string | number, any>;
|
|
73
|
-
type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
|
|
74
|
-
interface FullRequestParams extends Omit<RequestInit, "body"> {
|
|
75
|
-
/** set parameter to `true` for call `securityWorker` for this request */
|
|
76
|
-
secure?: boolean;
|
|
77
|
-
/** request path */
|
|
78
|
-
path: string;
|
|
79
|
-
/** content type of request body */
|
|
80
|
-
type?: ContentType;
|
|
81
|
-
/** query params */
|
|
82
|
-
query?: QueryParamsType;
|
|
83
|
-
/** format of response (i.e. response.json() -> format: "json") */
|
|
84
|
-
format?: ResponseFormat;
|
|
85
|
-
/** request body */
|
|
86
|
-
body?: unknown;
|
|
87
|
-
/** base url */
|
|
88
|
-
baseUrl?: string;
|
|
89
|
-
/** request cancellation token */
|
|
90
|
-
cancelToken?: CancelToken;
|
|
91
|
-
}
|
|
92
|
-
type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
|
|
93
|
-
interface HttpResponse$1<D extends unknown, E extends unknown = unknown> extends Response {
|
|
94
|
-
data: D;
|
|
95
|
-
error: E;
|
|
96
|
-
}
|
|
97
|
-
type CancelToken = Symbol | string | number;
|
|
98
|
-
declare enum ContentType {
|
|
99
|
-
Json = "application/json",
|
|
100
|
-
JsonApi = "application/vnd.api+json",
|
|
101
|
-
FormData = "multipart/form-data",
|
|
102
|
-
UrlEncoded = "application/x-www-form-urlencoded",
|
|
103
|
-
Text = "text/plain"
|
|
104
|
-
}
|
|
105
|
-
|
|
106
125
|
/**
|
|
107
126
|
* Extracts the successful response body type from a generated API method promise.
|
|
108
127
|
*
|
|
109
128
|
* Example: `Promise<HttpResponse<Product, Error>>` becomes `Product`.
|
|
110
129
|
*/
|
|
111
|
-
type ExtractResponse<T> = T extends Promise<HttpResponse
|
|
130
|
+
type ExtractResponse<T> = T extends Promise<HttpResponse<infer Response, unknown>> ? Response : never;
|
|
112
131
|
/**
|
|
113
132
|
* Extracts the error response body type from a generated API method promise.
|
|
114
133
|
*
|
|
115
134
|
* Example: `Promise<HttpResponse<Product, ApiError>>` becomes `ApiError`.
|
|
116
135
|
*/
|
|
117
|
-
type ExtractError<T> = T extends Promise<HttpResponse
|
|
136
|
+
type ExtractError<T> = T extends Promise<HttpResponse<unknown, infer Error>> ? Error : never;
|
|
118
137
|
/**
|
|
119
138
|
* Extracts the item type from an array, otherwise returns the original type.
|
|
120
139
|
*
|
|
@@ -149,22 +168,6 @@ type SortableKeys<T> = keyof UnwrapArray<ExtractDataIfPaginated<T>>;
|
|
|
149
168
|
*/
|
|
150
169
|
type WithoutRequestParams<T extends readonly unknown[]> = T extends readonly [...infer Arguments, RequestParams?] ? Arguments : T;
|
|
151
170
|
|
|
152
|
-
/**
|
|
153
|
-
* Extended fetch response returned by the generated HTTP client.
|
|
154
|
-
*
|
|
155
|
-
* `data` contains the successful response body and `error` contains the error body when available.
|
|
156
|
-
*/
|
|
157
|
-
interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response {
|
|
158
|
-
data: D;
|
|
159
|
-
error: E;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Runtime request options that can be passed to generated API methods.
|
|
163
|
-
*
|
|
164
|
-
* Used for extra request configuration such as headers, query values, or fetch options.
|
|
165
|
-
*/
|
|
166
|
-
type RuntimeRequestParams = Record<string, unknown>;
|
|
167
|
-
|
|
168
171
|
/**
|
|
169
172
|
* Function called after a generated wrapper method receives a successful API result.
|
|
170
173
|
*
|
|
@@ -176,22 +179,22 @@ type ApiSuccessHandler<TResponse> = (result: ApiSuccessResult<TResponse>) => voi
|
|
|
176
179
|
*
|
|
177
180
|
* The callback receives the error-only branch of `ApiResult<TResponse>`.
|
|
178
181
|
*/
|
|
179
|
-
type ApiErrorHandler<TResponse> = (result: ApiErrorResult<TResponse>) => void | Promise<void>;
|
|
182
|
+
type ApiErrorHandler<TResponse, TError = unknown> = (result: ApiErrorResult<TResponse, TError>) => void | Promise<void>;
|
|
180
183
|
/**
|
|
181
184
|
* Optional callback and request-parameter object accepted by generated API wrapper methods.
|
|
182
185
|
*
|
|
183
186
|
* `onSuccess` runs for successful responses, `onError` runs for failed responses,
|
|
184
187
|
* and `params` is forwarded to the generated HTTP client.
|
|
185
188
|
*/
|
|
186
|
-
type ApiMethodCallbacks<TResponse> = {
|
|
189
|
+
type ApiMethodCallbacks<TResponse, TError = unknown, TRequestParams = RequestParams> = {
|
|
187
190
|
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
188
|
-
onError?: ApiErrorHandler<TResponse>;
|
|
189
|
-
params?:
|
|
191
|
+
onError?: ApiErrorHandler<TResponse, TError>;
|
|
192
|
+
params?: TRequestParams;
|
|
190
193
|
};
|
|
191
194
|
|
|
192
195
|
type ApiMethodOptions<TResponse, TError = unknown, TRequestParams = RuntimeRequestParams> = {
|
|
193
196
|
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
194
|
-
onError?: ApiErrorHandler<TError>;
|
|
197
|
+
onError?: ApiErrorHandler<TResponse, TError>;
|
|
195
198
|
params?: TRequestParams;
|
|
196
199
|
};
|
|
197
200
|
|
|
@@ -213,7 +216,7 @@ type SortDirection = number | string;
|
|
|
213
216
|
* List filters are converted item by item.
|
|
214
217
|
* `OptionValue` lists send their `value` fields instead of the display names.
|
|
215
218
|
*/
|
|
216
|
-
declare function buildQuery<TQuery, TSortModel =
|
|
219
|
+
declare function buildQuery<TQuery, TSortModel = TQuery>(filters: FilterFormValues<TQuery>[], page?: number, pageSize?: number, sortBy?: keyof TSortModel | null, sortDirection?: SortDirection): Partial<TQuery>;
|
|
217
220
|
|
|
218
221
|
/**
|
|
219
222
|
* Extracts wrapper-only arguments in this order:
|
|
@@ -253,42 +256,23 @@ declare function extractArgsCallbacksAndParams<TArgs extends unknown[], TRespons
|
|
|
253
256
|
params?: RuntimeRequestParams;
|
|
254
257
|
};
|
|
255
258
|
|
|
256
|
-
|
|
257
|
-
* Optional callbacks used while converting a generated HTTP response into `ApiResult<TResponse>`.
|
|
258
|
-
*
|
|
259
|
-
* `onSuccess` is called with `ApiSuccessResult<TResponse>` and `onError` is called with `ApiErrorResult<TResponse>`.
|
|
260
|
-
*/
|
|
261
|
-
type HandleApiResponseOptions<TResponse> = {
|
|
259
|
+
type HandleApiResponseOptions<TResponse, TError = unknown> = {
|
|
262
260
|
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
263
|
-
onError?: ApiErrorHandler<TResponse>;
|
|
261
|
+
onError?: ApiErrorHandler<TResponse, TError>;
|
|
264
262
|
};
|
|
265
|
-
|
|
266
|
-
* Executes a generated API request and converts the result into `ApiResult<TResponse>`.
|
|
267
|
-
*
|
|
268
|
-
* Successful responses return `{ ok: true, status, response }`. Failed responses and thrown errors return `{ ok: false, status, error }`.
|
|
269
|
-
*/
|
|
270
|
-
declare function handleApiResponse<TResponse, TError = unknown>(call: () => Promise<HttpResponse<TResponse, TError>>, options?: HandleApiResponseOptions<TResponse>): Promise<ApiResult<TResponse>>;
|
|
263
|
+
declare function handleApiResponse<TResponse, TError = unknown>(call: () => Promise<HttpResponse<TResponse, TError>>, options?: HandleApiResponseOptions<TResponse, TError>): Promise<ApiResult<TResponse, TError>>;
|
|
271
264
|
|
|
272
|
-
/** Values supported by the generated API SortDirection enum. */
|
|
273
|
-
type ApiSortDirection = "Default" | "Ascending" | "Descending";
|
|
274
265
|
/**
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
* Includes `Neutral`, which is a UI-only state and is sent to the API as `Default`.
|
|
266
|
+
* Values supported by the current TypedApi .NET SortDirection enum.
|
|
267
|
+
* The legacy long names remain accepted when reading older APIs.
|
|
278
268
|
*/
|
|
269
|
+
type ApiSortDirection = "Default" | "Neutral" | "Asc" | "Desc" | "Ascending" | "Descending";
|
|
270
|
+
/** Sort states supported by TypedApi UI components. */
|
|
279
271
|
declare const sortTypes: readonly ["Default", "Neutral", "Ascending", "Descending"];
|
|
280
|
-
/**
|
|
281
|
-
* Converts an API sort direction to the sort state used by UI components.
|
|
282
|
-
*
|
|
283
|
-
* Unknown or missing values safely fall back to `Default`.
|
|
284
|
-
*/
|
|
272
|
+
/** Converts API sort direction values to the sort state used by UI components. */
|
|
285
273
|
declare function getSortTypeFromSortDirection(sortDirection: ApiSortDirection | null | undefined): SortType;
|
|
286
|
-
/**
|
|
287
|
-
|
|
288
|
-
*
|
|
289
|
-
* `Neutral` means no explicit sorting is active, so it maps to `Default`.
|
|
290
|
-
*/
|
|
291
|
-
declare function getSortDirectionFromSortType(sortType: SortType | null | undefined): ApiSortDirection;
|
|
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">;
|
|
292
276
|
|
|
293
277
|
/**
|
|
294
278
|
* Converts an object payload into `FormData`.
|
|
@@ -298,4 +282,4 @@ declare function getSortDirectionFromSortType(sortType: SortType | null | undefi
|
|
|
298
282
|
*/
|
|
299
283
|
declare function toFormData<T extends object>(payload: T): FormData;
|
|
300
284
|
|
|
301
|
-
export { type ApiErrorHandler, type ApiErrorResult, type ApiMethodArguments, type ApiMethodCallbacks, type ApiMethodOptions, type ApiResult, type ApiSortDirection, type ApiSuccessHandler, type ApiSuccessResult, type ExtractDataIfPaginated, type ExtractError, type ExtractResponse, type FilterFormValues, type FilterType, type HandleApiResponseOptions, type HttpResponse, type OptionValue, type RuntimeRequestParams, type SortDirection, type SortType, type SortableKeys, type UnwrapArray, type WithoutRequestParams, buildQuery, extractArgsCallbacksAndParams, extractArgsToastsAndParams, getSortDirectionFromSortType, getSortTypeFromSortDirection, handleApiResponse, sortTypes, toFormData };
|
|
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
CHANGED
|
@@ -1,25 +1,78 @@
|
|
|
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
|
+
|
|
1
53
|
/**
|
|
2
54
|
* Standard result wrapper returned by generated API wrapper methods.
|
|
3
55
|
*
|
|
4
56
|
* When `ok` is true, the request succeeded and `response` contains the expected data.
|
|
5
57
|
* When `ok` is false, the request failed and `error` contains the thrown or returned error value.
|
|
6
58
|
*/
|
|
7
|
-
type ApiResult<
|
|
59
|
+
type ApiResult<TResponse, TError = unknown> = {
|
|
8
60
|
ok: true;
|
|
9
61
|
status: number;
|
|
10
|
-
response:
|
|
62
|
+
response: TResponse;
|
|
63
|
+
error?: never;
|
|
11
64
|
} | {
|
|
12
65
|
ok: false;
|
|
13
66
|
status: number;
|
|
14
|
-
response?:
|
|
15
|
-
error:
|
|
67
|
+
response?: undefined;
|
|
68
|
+
error: TError;
|
|
16
69
|
};
|
|
17
70
|
/**
|
|
18
71
|
* Narrowed success branch of `ApiResult<T>`.
|
|
19
72
|
*
|
|
20
73
|
* Use this type for success callbacks or helper functions that should only receive successful API results.
|
|
21
74
|
*/
|
|
22
|
-
type ApiSuccessResult<
|
|
75
|
+
type ApiSuccessResult<TResponse, TError = unknown> = Extract<ApiResult<TResponse, TError>, {
|
|
23
76
|
ok: true;
|
|
24
77
|
}>;
|
|
25
78
|
/**
|
|
@@ -27,7 +80,7 @@ type ApiSuccessResult<T> = Extract<ApiResult<T>, {
|
|
|
27
80
|
*
|
|
28
81
|
* Use this type for error callbacks or helper functions that should only receive failed API results.
|
|
29
82
|
*/
|
|
30
|
-
type ApiErrorResult<
|
|
83
|
+
type ApiErrorResult<TResponse, TError = unknown> = Extract<ApiResult<TResponse, TError>, {
|
|
31
84
|
ok: false;
|
|
32
85
|
}>;
|
|
33
86
|
|
|
@@ -65,56 +118,22 @@ interface FilterFormValues<TQuery> {
|
|
|
65
118
|
/**
|
|
66
119
|
* Sort state used by UI components.
|
|
67
120
|
*
|
|
68
|
-
* `Neutral` represents
|
|
121
|
+
* `Neutral` represents an explicit neutral sorting state.
|
|
69
122
|
*/
|
|
70
123
|
type SortType = "Default" | "Neutral" | "Ascending" | "Descending";
|
|
71
124
|
|
|
72
|
-
type QueryParamsType = Record<string | number, any>;
|
|
73
|
-
type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
|
|
74
|
-
interface FullRequestParams extends Omit<RequestInit, "body"> {
|
|
75
|
-
/** set parameter to `true` for call `securityWorker` for this request */
|
|
76
|
-
secure?: boolean;
|
|
77
|
-
/** request path */
|
|
78
|
-
path: string;
|
|
79
|
-
/** content type of request body */
|
|
80
|
-
type?: ContentType;
|
|
81
|
-
/** query params */
|
|
82
|
-
query?: QueryParamsType;
|
|
83
|
-
/** format of response (i.e. response.json() -> format: "json") */
|
|
84
|
-
format?: ResponseFormat;
|
|
85
|
-
/** request body */
|
|
86
|
-
body?: unknown;
|
|
87
|
-
/** base url */
|
|
88
|
-
baseUrl?: string;
|
|
89
|
-
/** request cancellation token */
|
|
90
|
-
cancelToken?: CancelToken;
|
|
91
|
-
}
|
|
92
|
-
type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
|
|
93
|
-
interface HttpResponse$1<D extends unknown, E extends unknown = unknown> extends Response {
|
|
94
|
-
data: D;
|
|
95
|
-
error: E;
|
|
96
|
-
}
|
|
97
|
-
type CancelToken = Symbol | string | number;
|
|
98
|
-
declare enum ContentType {
|
|
99
|
-
Json = "application/json",
|
|
100
|
-
JsonApi = "application/vnd.api+json",
|
|
101
|
-
FormData = "multipart/form-data",
|
|
102
|
-
UrlEncoded = "application/x-www-form-urlencoded",
|
|
103
|
-
Text = "text/plain"
|
|
104
|
-
}
|
|
105
|
-
|
|
106
125
|
/**
|
|
107
126
|
* Extracts the successful response body type from a generated API method promise.
|
|
108
127
|
*
|
|
109
128
|
* Example: `Promise<HttpResponse<Product, Error>>` becomes `Product`.
|
|
110
129
|
*/
|
|
111
|
-
type ExtractResponse<T> = T extends Promise<HttpResponse
|
|
130
|
+
type ExtractResponse<T> = T extends Promise<HttpResponse<infer Response, unknown>> ? Response : never;
|
|
112
131
|
/**
|
|
113
132
|
* Extracts the error response body type from a generated API method promise.
|
|
114
133
|
*
|
|
115
134
|
* Example: `Promise<HttpResponse<Product, ApiError>>` becomes `ApiError`.
|
|
116
135
|
*/
|
|
117
|
-
type ExtractError<T> = T extends Promise<HttpResponse
|
|
136
|
+
type ExtractError<T> = T extends Promise<HttpResponse<unknown, infer Error>> ? Error : never;
|
|
118
137
|
/**
|
|
119
138
|
* Extracts the item type from an array, otherwise returns the original type.
|
|
120
139
|
*
|
|
@@ -149,22 +168,6 @@ type SortableKeys<T> = keyof UnwrapArray<ExtractDataIfPaginated<T>>;
|
|
|
149
168
|
*/
|
|
150
169
|
type WithoutRequestParams<T extends readonly unknown[]> = T extends readonly [...infer Arguments, RequestParams?] ? Arguments : T;
|
|
151
170
|
|
|
152
|
-
/**
|
|
153
|
-
* Extended fetch response returned by the generated HTTP client.
|
|
154
|
-
*
|
|
155
|
-
* `data` contains the successful response body and `error` contains the error body when available.
|
|
156
|
-
*/
|
|
157
|
-
interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response {
|
|
158
|
-
data: D;
|
|
159
|
-
error: E;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Runtime request options that can be passed to generated API methods.
|
|
163
|
-
*
|
|
164
|
-
* Used for extra request configuration such as headers, query values, or fetch options.
|
|
165
|
-
*/
|
|
166
|
-
type RuntimeRequestParams = Record<string, unknown>;
|
|
167
|
-
|
|
168
171
|
/**
|
|
169
172
|
* Function called after a generated wrapper method receives a successful API result.
|
|
170
173
|
*
|
|
@@ -176,22 +179,22 @@ type ApiSuccessHandler<TResponse> = (result: ApiSuccessResult<TResponse>) => voi
|
|
|
176
179
|
*
|
|
177
180
|
* The callback receives the error-only branch of `ApiResult<TResponse>`.
|
|
178
181
|
*/
|
|
179
|
-
type ApiErrorHandler<TResponse> = (result: ApiErrorResult<TResponse>) => void | Promise<void>;
|
|
182
|
+
type ApiErrorHandler<TResponse, TError = unknown> = (result: ApiErrorResult<TResponse, TError>) => void | Promise<void>;
|
|
180
183
|
/**
|
|
181
184
|
* Optional callback and request-parameter object accepted by generated API wrapper methods.
|
|
182
185
|
*
|
|
183
186
|
* `onSuccess` runs for successful responses, `onError` runs for failed responses,
|
|
184
187
|
* and `params` is forwarded to the generated HTTP client.
|
|
185
188
|
*/
|
|
186
|
-
type ApiMethodCallbacks<TResponse> = {
|
|
189
|
+
type ApiMethodCallbacks<TResponse, TError = unknown, TRequestParams = RequestParams> = {
|
|
187
190
|
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
188
|
-
onError?: ApiErrorHandler<TResponse>;
|
|
189
|
-
params?:
|
|
191
|
+
onError?: ApiErrorHandler<TResponse, TError>;
|
|
192
|
+
params?: TRequestParams;
|
|
190
193
|
};
|
|
191
194
|
|
|
192
195
|
type ApiMethodOptions<TResponse, TError = unknown, TRequestParams = RuntimeRequestParams> = {
|
|
193
196
|
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
194
|
-
onError?: ApiErrorHandler<TError>;
|
|
197
|
+
onError?: ApiErrorHandler<TResponse, TError>;
|
|
195
198
|
params?: TRequestParams;
|
|
196
199
|
};
|
|
197
200
|
|
|
@@ -213,7 +216,7 @@ type SortDirection = number | string;
|
|
|
213
216
|
* List filters are converted item by item.
|
|
214
217
|
* `OptionValue` lists send their `value` fields instead of the display names.
|
|
215
218
|
*/
|
|
216
|
-
declare function buildQuery<TQuery, TSortModel =
|
|
219
|
+
declare function buildQuery<TQuery, TSortModel = TQuery>(filters: FilterFormValues<TQuery>[], page?: number, pageSize?: number, sortBy?: keyof TSortModel | null, sortDirection?: SortDirection): Partial<TQuery>;
|
|
217
220
|
|
|
218
221
|
/**
|
|
219
222
|
* Extracts wrapper-only arguments in this order:
|
|
@@ -253,42 +256,23 @@ declare function extractArgsCallbacksAndParams<TArgs extends unknown[], TRespons
|
|
|
253
256
|
params?: RuntimeRequestParams;
|
|
254
257
|
};
|
|
255
258
|
|
|
256
|
-
|
|
257
|
-
* Optional callbacks used while converting a generated HTTP response into `ApiResult<TResponse>`.
|
|
258
|
-
*
|
|
259
|
-
* `onSuccess` is called with `ApiSuccessResult<TResponse>` and `onError` is called with `ApiErrorResult<TResponse>`.
|
|
260
|
-
*/
|
|
261
|
-
type HandleApiResponseOptions<TResponse> = {
|
|
259
|
+
type HandleApiResponseOptions<TResponse, TError = unknown> = {
|
|
262
260
|
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
263
|
-
onError?: ApiErrorHandler<TResponse>;
|
|
261
|
+
onError?: ApiErrorHandler<TResponse, TError>;
|
|
264
262
|
};
|
|
265
|
-
|
|
266
|
-
* Executes a generated API request and converts the result into `ApiResult<TResponse>`.
|
|
267
|
-
*
|
|
268
|
-
* Successful responses return `{ ok: true, status, response }`. Failed responses and thrown errors return `{ ok: false, status, error }`.
|
|
269
|
-
*/
|
|
270
|
-
declare function handleApiResponse<TResponse, TError = unknown>(call: () => Promise<HttpResponse<TResponse, TError>>, options?: HandleApiResponseOptions<TResponse>): Promise<ApiResult<TResponse>>;
|
|
263
|
+
declare function handleApiResponse<TResponse, TError = unknown>(call: () => Promise<HttpResponse<TResponse, TError>>, options?: HandleApiResponseOptions<TResponse, TError>): Promise<ApiResult<TResponse, TError>>;
|
|
271
264
|
|
|
272
|
-
/** Values supported by the generated API SortDirection enum. */
|
|
273
|
-
type ApiSortDirection = "Default" | "Ascending" | "Descending";
|
|
274
265
|
/**
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
* Includes `Neutral`, which is a UI-only state and is sent to the API as `Default`.
|
|
266
|
+
* Values supported by the current TypedApi .NET SortDirection enum.
|
|
267
|
+
* The legacy long names remain accepted when reading older APIs.
|
|
278
268
|
*/
|
|
269
|
+
type ApiSortDirection = "Default" | "Neutral" | "Asc" | "Desc" | "Ascending" | "Descending";
|
|
270
|
+
/** Sort states supported by TypedApi UI components. */
|
|
279
271
|
declare const sortTypes: readonly ["Default", "Neutral", "Ascending", "Descending"];
|
|
280
|
-
/**
|
|
281
|
-
* Converts an API sort direction to the sort state used by UI components.
|
|
282
|
-
*
|
|
283
|
-
* Unknown or missing values safely fall back to `Default`.
|
|
284
|
-
*/
|
|
272
|
+
/** Converts API sort direction values to the sort state used by UI components. */
|
|
285
273
|
declare function getSortTypeFromSortDirection(sortDirection: ApiSortDirection | null | undefined): SortType;
|
|
286
|
-
/**
|
|
287
|
-
|
|
288
|
-
*
|
|
289
|
-
* `Neutral` means no explicit sorting is active, so it maps to `Default`.
|
|
290
|
-
*/
|
|
291
|
-
declare function getSortDirectionFromSortType(sortType: SortType | null | undefined): ApiSortDirection;
|
|
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">;
|
|
292
276
|
|
|
293
277
|
/**
|
|
294
278
|
* Converts an object payload into `FormData`.
|
|
@@ -298,4 +282,4 @@ declare function getSortDirectionFromSortType(sortType: SortType | null | undefi
|
|
|
298
282
|
*/
|
|
299
283
|
declare function toFormData<T extends object>(payload: T): FormData;
|
|
300
284
|
|
|
301
|
-
export { type ApiErrorHandler, type ApiErrorResult, type ApiMethodArguments, type ApiMethodCallbacks, type ApiMethodOptions, type ApiResult, type ApiSortDirection, type ApiSuccessHandler, type ApiSuccessResult, type ExtractDataIfPaginated, type ExtractError, type ExtractResponse, type FilterFormValues, type FilterType, type HandleApiResponseOptions, type HttpResponse, type OptionValue, type RuntimeRequestParams, type SortDirection, type SortType, type SortableKeys, type UnwrapArray, type WithoutRequestParams, buildQuery, extractArgsCallbacksAndParams, extractArgsToastsAndParams, getSortDirectionFromSortType, getSortTypeFromSortDirection, handleApiResponse, sortTypes, toFormData };
|
|
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 };
|