typedapi-client-helpers 0.1.5 → 0.1.7
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/README.md +314 -676
- package/dist/api/generated/Import.d.ts +22 -0
- package/dist/api/generated/Import.d.ts.map +1 -0
- package/dist/api/generated/Import.js +48 -0
- package/dist/api/generated/Import.js.map +1 -0
- package/dist/api/generated/ImportRoute.d.ts +30 -0
- package/dist/api/generated/ImportRoute.d.ts.map +1 -0
- package/dist/api/generated/ImportRoute.js +13 -0
- package/dist/api/generated/ImportRoute.js.map +1 -0
- package/dist/api/generated/Order.d.ts +38 -0
- package/dist/api/generated/Order.d.ts.map +1 -0
- package/dist/api/generated/Order.js +75 -0
- package/dist/api/generated/Order.js.map +1 -0
- package/dist/api/generated/OrderRoute.d.ts +83 -0
- package/dist/api/generated/OrderRoute.d.ts.map +1 -0
- package/dist/api/generated/OrderRoute.js +13 -0
- package/dist/api/generated/OrderRoute.js.map +1 -0
- package/dist/api/generated/Product.d.ts +62 -0
- package/dist/api/generated/Product.d.ts.map +1 -0
- package/dist/api/generated/Product.js +114 -0
- package/dist/api/generated/Product.js.map +1 -0
- package/dist/api/generated/ProductRoute.d.ts +140 -0
- package/dist/api/generated/ProductRoute.d.ts.map +1 -0
- package/dist/api/generated/ProductRoute.js +13 -0
- package/dist/api/generated/ProductRoute.js.map +1 -0
- package/dist/api/generated/Report.d.ts +14 -0
- package/dist/api/generated/Report.d.ts.map +1 -0
- package/dist/api/generated/Report.js +32 -0
- package/dist/api/generated/Report.js.map +1 -0
- package/dist/api/generated/ReportRoute.d.ts +23 -0
- package/dist/api/generated/ReportRoute.d.ts.map +1 -0
- package/dist/api/generated/ReportRoute.js +13 -0
- package/dist/api/generated/ReportRoute.js.map +1 -0
- package/dist/api/generated/Supplier.d.ts +46 -0
- package/dist/api/generated/Supplier.d.ts.map +1 -0
- package/dist/api/generated/Supplier.js +87 -0
- package/dist/api/generated/Supplier.js.map +1 -0
- package/dist/api/generated/SupplierRoute.d.ts +101 -0
- package/dist/api/generated/SupplierRoute.d.ts.map +1 -0
- package/dist/api/generated/SupplierRoute.js +13 -0
- package/dist/api/generated/SupplierRoute.js.map +1 -0
- package/dist/api/generated/data-contracts.d.ts +277 -0
- package/dist/api/generated/data-contracts.d.ts.map +1 -0
- package/dist/api/generated/data-contracts.js +26 -0
- package/dist/api/generated/data-contracts.js.map +1 -0
- package/dist/api/generated/http-client.d.ts +61 -0
- package/dist/api/generated/http-client.d.ts.map +1 -0
- package/dist/api/generated/http-client.js +171 -0
- package/dist/api/generated/http-client.js.map +1 -0
- package/dist/api/index.d.ts +8 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +8 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/methods/Import.api.d.ts +6 -0
- package/dist/api/methods/Import.api.d.ts.map +1 -0
- package/dist/api/methods/Import.api.js +27 -0
- package/dist/api/methods/Import.api.js.map +1 -0
- package/dist/api/methods/Order.api.d.ts +29 -0
- package/dist/api/methods/Order.api.d.ts.map +1 -0
- package/dist/api/methods/Order.api.js +52 -0
- package/dist/api/methods/Order.api.js.map +1 -0
- package/dist/api/methods/Product.api.d.ts +39 -0
- package/dist/api/methods/Product.api.d.ts.map +1 -0
- package/dist/api/methods/Product.api.js +69 -0
- package/dist/api/methods/Product.api.js.map +1 -0
- package/dist/api/methods/Report.api.d.ts +6 -0
- package/dist/api/methods/Report.api.d.ts.map +1 -0
- package/dist/api/methods/Report.api.js +19 -0
- package/dist/api/methods/Report.api.js.map +1 -0
- package/dist/api/methods/Supplier.api.d.ts +35 -0
- package/dist/api/methods/Supplier.api.d.ts.map +1 -0
- package/dist/api/methods/Supplier.api.js +63 -0
- package/dist/api/methods/Supplier.api.js.map +1 -0
- package/dist/index.cjs +47 -551
- package/dist/index.d.cts +108 -18
- package/dist/index.d.ts +108 -18
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -551
- package/dist/index.js.map +1 -0
- package/dist/interfaces/ApiResult.d.ts +17 -0
- package/dist/interfaces/ApiResult.d.ts.map +1 -0
- package/dist/interfaces/ApiResult.js +2 -0
- package/dist/interfaces/ApiResult.js.map +1 -0
- package/dist/interfaces/Filter.d.ts +31 -0
- package/dist/interfaces/Filter.d.ts.map +1 -0
- package/dist/interfaces/Filter.js +2 -0
- package/dist/interfaces/Filter.js.map +1 -0
- package/dist/interfaces/SortType.d.ts +7 -0
- package/dist/interfaces/SortType.d.ts.map +1 -0
- package/dist/interfaces/SortType.js +2 -0
- package/dist/interfaces/SortType.js.map +1 -0
- package/dist/types/ApiCallOptions.d.ts +9 -0
- package/dist/types/ApiCallOptions.d.ts.map +1 -0
- package/dist/types/ApiCallOptions.js +2 -0
- package/dist/types/ApiCallOptions.js.map +1 -0
- package/dist/types/ApiMethodTypes.d.ts +24 -0
- package/dist/types/ApiMethodTypes.d.ts.map +1 -0
- package/dist/types/ApiMethodTypes.js +2 -0
- package/dist/types/ApiMethodTypes.js.map +1 -0
- package/dist/types/HttpResponse.d.ts +16 -0
- package/dist/types/HttpResponse.d.ts.map +1 -0
- package/dist/types/HttpResponse.js +2 -0
- package/dist/types/HttpResponse.js.map +1 -0
- package/dist/utils/SortTypeFromSortDirection.d.ts +22 -0
- package/dist/utils/SortTypeFromSortDirection.d.ts.map +1 -0
- package/dist/utils/SortTypeFromSortDirection.js +45 -0
- package/dist/utils/SortTypeFromSortDirection.js.map +1 -0
- package/dist/utils/buildQuery.d.ts +11 -0
- package/dist/utils/buildQuery.d.ts.map +1 -0
- package/dist/utils/buildQuery.js +94 -0
- package/dist/utils/buildQuery.js.map +1 -0
- package/dist/utils/extractArgsCallbacksAndParams.d.ts +22 -0
- package/dist/utils/extractArgsCallbacksAndParams.d.ts.map +1 -0
- package/dist/utils/extractArgsCallbacksAndParams.js +44 -0
- package/dist/utils/extractArgsCallbacksAndParams.js.map +1 -0
- package/dist/utils/extractArgsToastsAndParams.d.ts +18 -0
- package/dist/utils/extractArgsToastsAndParams.d.ts.map +1 -0
- package/dist/utils/extractArgsToastsAndParams.js +40 -0
- package/dist/utils/extractArgsToastsAndParams.js.map +1 -0
- package/dist/utils/handleApiResponse.d.ts +9 -0
- package/dist/utils/handleApiResponse.d.ts.map +1 -0
- package/dist/utils/handleApiResponse.js +49 -0
- package/dist/utils/handleApiResponse.js.map +1 -0
- package/dist/utils/toFormData.d.ts +8 -0
- package/dist/utils/toFormData.d.ts.map +1 -0
- package/dist/utils/toFormData.js +68 -0
- package/dist/utils/toFormData.js.map +1 -0
- package/package.json +11 -3
- package/scripts/generate-api-minimal.mjs +263 -25
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Standard result wrapper
|
|
2
|
+
* Standard result wrapper returned by generated API wrapper methods.
|
|
3
3
|
*
|
|
4
4
|
* When `ok` is true, the request succeeded and `response` contains the expected data.
|
|
5
5
|
* When `ok` is false, the request failed and `error` contains the thrown or returned error value.
|
|
@@ -14,6 +14,22 @@ type ApiResult<T> = {
|
|
|
14
14
|
response?: T;
|
|
15
15
|
error: unknown;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Narrowed success branch of `ApiResult<T>`.
|
|
19
|
+
*
|
|
20
|
+
* Use this type for success callbacks or helper functions that should only receive successful API results.
|
|
21
|
+
*/
|
|
22
|
+
type ApiSuccessResult<T> = Extract<ApiResult<T>, {
|
|
23
|
+
ok: true;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Narrowed error branch of `ApiResult<T>`.
|
|
27
|
+
*
|
|
28
|
+
* Use this type for error callbacks or helper functions that should only receive failed API results.
|
|
29
|
+
*/
|
|
30
|
+
type ApiErrorResult<T> = Extract<ApiResult<T>, {
|
|
31
|
+
ok: false;
|
|
32
|
+
}>;
|
|
17
33
|
|
|
18
34
|
/**
|
|
19
35
|
* Supported filter input types used by typed filter forms.
|
|
@@ -87,11 +103,37 @@ declare enum ContentType {
|
|
|
87
103
|
Text = "text/plain"
|
|
88
104
|
}
|
|
89
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Extracts the successful response body type from a generated API method promise.
|
|
108
|
+
*
|
|
109
|
+
* Example: `Promise<HttpResponse<Product, Error>>` becomes `Product`.
|
|
110
|
+
*/
|
|
90
111
|
type ExtractResponse<T> = T extends Promise<HttpResponse$1<infer Response, unknown>> ? Response : never;
|
|
112
|
+
/**
|
|
113
|
+
* Extracts the error response body type from a generated API method promise.
|
|
114
|
+
*
|
|
115
|
+
* Example: `Promise<HttpResponse<Product, ApiError>>` becomes `ApiError`.
|
|
116
|
+
*/
|
|
117
|
+
type ExtractError<T> = T extends Promise<HttpResponse$1<unknown, infer Error>> ? Error : never;
|
|
118
|
+
/**
|
|
119
|
+
* Extracts the item type from an array, otherwise returns the original type.
|
|
120
|
+
*
|
|
121
|
+
* Example: `Product[]` becomes `Product`, while `Product` stays `Product`.
|
|
122
|
+
*/
|
|
91
123
|
type UnwrapArray<T> = T extends readonly (infer Item)[] ? Item : T;
|
|
124
|
+
/**
|
|
125
|
+
* Extracts the item type from common paginated response shapes.
|
|
126
|
+
*
|
|
127
|
+
* Example: `{ data?: Product[] }` becomes `Product`.
|
|
128
|
+
*/
|
|
92
129
|
type ExtractDataIfPaginated<T> = T extends {
|
|
93
130
|
data?: readonly (infer Item)[] | null;
|
|
94
131
|
} ? Item : T;
|
|
132
|
+
/**
|
|
133
|
+
* Keys that can be used as sort fields for an API response type.
|
|
134
|
+
*
|
|
135
|
+
* For paginated responses this uses the keys of the item inside `data`.
|
|
136
|
+
*/
|
|
95
137
|
type SortableKeys<T> = keyof UnwrapArray<ExtractDataIfPaginated<T>>;
|
|
96
138
|
/**
|
|
97
139
|
* Removes the optional RequestParams argument from the end
|
|
@@ -105,10 +147,7 @@ type SortableKeys<T> = keyof UnwrapArray<ExtractDataIfPaginated<T>>;
|
|
|
105
147
|
*
|
|
106
148
|
* [data: CreateSupplierParams]
|
|
107
149
|
*/
|
|
108
|
-
type WithoutRequestParams<T extends readonly unknown[]> = T extends readonly [
|
|
109
|
-
...infer Arguments,
|
|
110
|
-
RequestParams?
|
|
111
|
-
] ? Arguments : T;
|
|
150
|
+
type WithoutRequestParams<T extends readonly unknown[]> = T extends readonly [...infer Arguments, RequestParams?] ? Arguments : T;
|
|
112
151
|
|
|
113
152
|
/**
|
|
114
153
|
* Extended fetch response returned by the generated HTTP client.
|
|
@@ -126,14 +165,35 @@ interface HttpResponse<D extends unknown, E extends unknown = unknown> extends R
|
|
|
126
165
|
*/
|
|
127
166
|
type RuntimeRequestParams = Record<string, unknown>;
|
|
128
167
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
168
|
+
/**
|
|
169
|
+
* Function called after a generated wrapper method receives a successful API result.
|
|
170
|
+
*
|
|
171
|
+
* The callback receives the success-only branch of `ApiResult<TResponse>`.
|
|
172
|
+
*/
|
|
173
|
+
type ApiSuccessHandler<TResponse> = (result: ApiSuccessResult<TResponse>) => void | Promise<void>;
|
|
174
|
+
/**
|
|
175
|
+
* Function called after a generated wrapper method receives a failed API result.
|
|
176
|
+
*
|
|
177
|
+
* The callback receives the error-only branch of `ApiResult<TResponse>`.
|
|
178
|
+
*/
|
|
179
|
+
type ApiErrorHandler<TResponse> = (result: ApiErrorResult<TResponse>) => void | Promise<void>;
|
|
180
|
+
/**
|
|
181
|
+
* Optional callback and request-parameter object accepted by generated API wrapper methods.
|
|
182
|
+
*
|
|
183
|
+
* `onSuccess` runs for successful responses, `onError` runs for failed responses,
|
|
184
|
+
* and `params` is forwarded to the generated HTTP client.
|
|
185
|
+
*/
|
|
186
|
+
type ApiMethodCallbacks<TResponse> = {
|
|
132
187
|
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
133
|
-
onError?: ApiErrorHandler<
|
|
188
|
+
onError?: ApiErrorHandler<TResponse>;
|
|
134
189
|
params?: RequestParams;
|
|
135
190
|
};
|
|
136
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Sort direction value accepted by generated query objects.
|
|
194
|
+
*
|
|
195
|
+
* APIs often expose sort direction as either a string enum or numeric enum, so both are supported.
|
|
196
|
+
*/
|
|
137
197
|
type SortDirection = number | string;
|
|
138
198
|
/**
|
|
139
199
|
* Builds a typed query object from filter form values, pagination, and sorting.
|
|
@@ -148,23 +208,53 @@ declare function buildQuery<TQuery, TSortModel = keyof TQuery>(filters: FilterFo
|
|
|
148
208
|
* Extracts wrapper-only arguments in this order:
|
|
149
209
|
* original API arguments, onSuccess, onError, request params.
|
|
150
210
|
*/
|
|
151
|
-
declare function
|
|
211
|
+
declare function extractArgsToastsAndParams<TArgs extends readonly unknown[], TResponse>(argsWithCallbacks: [
|
|
212
|
+
...TArgs,
|
|
213
|
+
ApiSuccessHandler<TResponse>?,
|
|
214
|
+
ApiErrorHandler<TResponse>?,
|
|
215
|
+
RuntimeRequestParams?
|
|
216
|
+
]): {
|
|
217
|
+
args: TArgs;
|
|
218
|
+
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
219
|
+
onError?: ApiErrorHandler<TResponse>;
|
|
220
|
+
params?: RuntimeRequestParams;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Extracts wrapper arguments in this order:
|
|
225
|
+
*
|
|
226
|
+
* 1. Original API arguments
|
|
227
|
+
* 2. Optional success callback
|
|
228
|
+
* 3. Optional error callback
|
|
229
|
+
* 4. Optional request params
|
|
230
|
+
*/
|
|
231
|
+
declare function extractArgsCallbacksAndParams<TArgs extends unknown[], TResponse, _TError = unknown>(argsWithCallbacks: [
|
|
152
232
|
...TArgs,
|
|
153
|
-
ApiSuccessHandler<
|
|
154
|
-
ApiErrorHandler<
|
|
233
|
+
ApiSuccessHandler<TResponse>?,
|
|
234
|
+
ApiErrorHandler<TResponse>?,
|
|
155
235
|
RuntimeRequestParams?
|
|
156
236
|
]): {
|
|
157
237
|
args: TArgs;
|
|
158
|
-
onSuccess?: ApiSuccessHandler<
|
|
159
|
-
onError?: ApiErrorHandler<
|
|
238
|
+
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
239
|
+
onError?: ApiErrorHandler<TResponse>;
|
|
160
240
|
params?: RuntimeRequestParams;
|
|
161
241
|
};
|
|
162
242
|
|
|
163
|
-
|
|
243
|
+
/**
|
|
244
|
+
* Optional callbacks used while converting a generated HTTP response into `ApiResult<TResponse>`.
|
|
245
|
+
*
|
|
246
|
+
* `onSuccess` is called with `ApiSuccessResult<TResponse>` and `onError` is called with `ApiErrorResult<TResponse>`.
|
|
247
|
+
*/
|
|
248
|
+
type HandleApiResponseOptions<TResponse> = {
|
|
164
249
|
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
165
|
-
onError?: ApiErrorHandler<
|
|
250
|
+
onError?: ApiErrorHandler<TResponse>;
|
|
166
251
|
};
|
|
167
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Executes a generated API request and converts the result into `ApiResult<TResponse>`.
|
|
254
|
+
*
|
|
255
|
+
* Successful responses return `{ ok: true, status, response }`. Failed responses and thrown errors return `{ ok: false, status, error }`.
|
|
256
|
+
*/
|
|
257
|
+
declare function handleApiResponse<TResponse, TError>(call: () => Promise<HttpResponse<TResponse, TError>>, options?: HandleApiResponseOptions<TResponse>): Promise<ApiResult<TResponse>>;
|
|
168
258
|
|
|
169
259
|
/** Values supported by the generated API SortDirection enum. */
|
|
170
260
|
type ApiSortDirection = "Default" | "Ascending" | "Descending";
|
|
@@ -195,4 +285,4 @@ declare function getSortDirectionFromSortType(sortType: SortType | null | undefi
|
|
|
195
285
|
*/
|
|
196
286
|
declare function toFormData<T extends object>(payload: T): FormData;
|
|
197
287
|
|
|
198
|
-
export { type ApiErrorHandler, type ApiMethodCallbacks, type ApiResult, type ApiSortDirection, type ApiSuccessHandler, type ExtractDataIfPaginated, 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, getSortDirectionFromSortType, getSortTypeFromSortDirection, handleApiResponse, sortTypes, toFormData };
|
|
288
|
+
export { type ApiErrorHandler, type ApiErrorResult, type ApiMethodCallbacks, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Standard result wrapper
|
|
2
|
+
* Standard result wrapper returned by generated API wrapper methods.
|
|
3
3
|
*
|
|
4
4
|
* When `ok` is true, the request succeeded and `response` contains the expected data.
|
|
5
5
|
* When `ok` is false, the request failed and `error` contains the thrown or returned error value.
|
|
@@ -14,6 +14,22 @@ type ApiResult<T> = {
|
|
|
14
14
|
response?: T;
|
|
15
15
|
error: unknown;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Narrowed success branch of `ApiResult<T>`.
|
|
19
|
+
*
|
|
20
|
+
* Use this type for success callbacks or helper functions that should only receive successful API results.
|
|
21
|
+
*/
|
|
22
|
+
type ApiSuccessResult<T> = Extract<ApiResult<T>, {
|
|
23
|
+
ok: true;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Narrowed error branch of `ApiResult<T>`.
|
|
27
|
+
*
|
|
28
|
+
* Use this type for error callbacks or helper functions that should only receive failed API results.
|
|
29
|
+
*/
|
|
30
|
+
type ApiErrorResult<T> = Extract<ApiResult<T>, {
|
|
31
|
+
ok: false;
|
|
32
|
+
}>;
|
|
17
33
|
|
|
18
34
|
/**
|
|
19
35
|
* Supported filter input types used by typed filter forms.
|
|
@@ -87,11 +103,37 @@ declare enum ContentType {
|
|
|
87
103
|
Text = "text/plain"
|
|
88
104
|
}
|
|
89
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Extracts the successful response body type from a generated API method promise.
|
|
108
|
+
*
|
|
109
|
+
* Example: `Promise<HttpResponse<Product, Error>>` becomes `Product`.
|
|
110
|
+
*/
|
|
90
111
|
type ExtractResponse<T> = T extends Promise<HttpResponse$1<infer Response, unknown>> ? Response : never;
|
|
112
|
+
/**
|
|
113
|
+
* Extracts the error response body type from a generated API method promise.
|
|
114
|
+
*
|
|
115
|
+
* Example: `Promise<HttpResponse<Product, ApiError>>` becomes `ApiError`.
|
|
116
|
+
*/
|
|
117
|
+
type ExtractError<T> = T extends Promise<HttpResponse$1<unknown, infer Error>> ? Error : never;
|
|
118
|
+
/**
|
|
119
|
+
* Extracts the item type from an array, otherwise returns the original type.
|
|
120
|
+
*
|
|
121
|
+
* Example: `Product[]` becomes `Product`, while `Product` stays `Product`.
|
|
122
|
+
*/
|
|
91
123
|
type UnwrapArray<T> = T extends readonly (infer Item)[] ? Item : T;
|
|
124
|
+
/**
|
|
125
|
+
* Extracts the item type from common paginated response shapes.
|
|
126
|
+
*
|
|
127
|
+
* Example: `{ data?: Product[] }` becomes `Product`.
|
|
128
|
+
*/
|
|
92
129
|
type ExtractDataIfPaginated<T> = T extends {
|
|
93
130
|
data?: readonly (infer Item)[] | null;
|
|
94
131
|
} ? Item : T;
|
|
132
|
+
/**
|
|
133
|
+
* Keys that can be used as sort fields for an API response type.
|
|
134
|
+
*
|
|
135
|
+
* For paginated responses this uses the keys of the item inside `data`.
|
|
136
|
+
*/
|
|
95
137
|
type SortableKeys<T> = keyof UnwrapArray<ExtractDataIfPaginated<T>>;
|
|
96
138
|
/**
|
|
97
139
|
* Removes the optional RequestParams argument from the end
|
|
@@ -105,10 +147,7 @@ type SortableKeys<T> = keyof UnwrapArray<ExtractDataIfPaginated<T>>;
|
|
|
105
147
|
*
|
|
106
148
|
* [data: CreateSupplierParams]
|
|
107
149
|
*/
|
|
108
|
-
type WithoutRequestParams<T extends readonly unknown[]> = T extends readonly [
|
|
109
|
-
...infer Arguments,
|
|
110
|
-
RequestParams?
|
|
111
|
-
] ? Arguments : T;
|
|
150
|
+
type WithoutRequestParams<T extends readonly unknown[]> = T extends readonly [...infer Arguments, RequestParams?] ? Arguments : T;
|
|
112
151
|
|
|
113
152
|
/**
|
|
114
153
|
* Extended fetch response returned by the generated HTTP client.
|
|
@@ -126,14 +165,35 @@ interface HttpResponse<D extends unknown, E extends unknown = unknown> extends R
|
|
|
126
165
|
*/
|
|
127
166
|
type RuntimeRequestParams = Record<string, unknown>;
|
|
128
167
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
168
|
+
/**
|
|
169
|
+
* Function called after a generated wrapper method receives a successful API result.
|
|
170
|
+
*
|
|
171
|
+
* The callback receives the success-only branch of `ApiResult<TResponse>`.
|
|
172
|
+
*/
|
|
173
|
+
type ApiSuccessHandler<TResponse> = (result: ApiSuccessResult<TResponse>) => void | Promise<void>;
|
|
174
|
+
/**
|
|
175
|
+
* Function called after a generated wrapper method receives a failed API result.
|
|
176
|
+
*
|
|
177
|
+
* The callback receives the error-only branch of `ApiResult<TResponse>`.
|
|
178
|
+
*/
|
|
179
|
+
type ApiErrorHandler<TResponse> = (result: ApiErrorResult<TResponse>) => void | Promise<void>;
|
|
180
|
+
/**
|
|
181
|
+
* Optional callback and request-parameter object accepted by generated API wrapper methods.
|
|
182
|
+
*
|
|
183
|
+
* `onSuccess` runs for successful responses, `onError` runs for failed responses,
|
|
184
|
+
* and `params` is forwarded to the generated HTTP client.
|
|
185
|
+
*/
|
|
186
|
+
type ApiMethodCallbacks<TResponse> = {
|
|
132
187
|
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
133
|
-
onError?: ApiErrorHandler<
|
|
188
|
+
onError?: ApiErrorHandler<TResponse>;
|
|
134
189
|
params?: RequestParams;
|
|
135
190
|
};
|
|
136
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Sort direction value accepted by generated query objects.
|
|
194
|
+
*
|
|
195
|
+
* APIs often expose sort direction as either a string enum or numeric enum, so both are supported.
|
|
196
|
+
*/
|
|
137
197
|
type SortDirection = number | string;
|
|
138
198
|
/**
|
|
139
199
|
* Builds a typed query object from filter form values, pagination, and sorting.
|
|
@@ -148,23 +208,53 @@ declare function buildQuery<TQuery, TSortModel = keyof TQuery>(filters: FilterFo
|
|
|
148
208
|
* Extracts wrapper-only arguments in this order:
|
|
149
209
|
* original API arguments, onSuccess, onError, request params.
|
|
150
210
|
*/
|
|
151
|
-
declare function
|
|
211
|
+
declare function extractArgsToastsAndParams<TArgs extends readonly unknown[], TResponse>(argsWithCallbacks: [
|
|
212
|
+
...TArgs,
|
|
213
|
+
ApiSuccessHandler<TResponse>?,
|
|
214
|
+
ApiErrorHandler<TResponse>?,
|
|
215
|
+
RuntimeRequestParams?
|
|
216
|
+
]): {
|
|
217
|
+
args: TArgs;
|
|
218
|
+
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
219
|
+
onError?: ApiErrorHandler<TResponse>;
|
|
220
|
+
params?: RuntimeRequestParams;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Extracts wrapper arguments in this order:
|
|
225
|
+
*
|
|
226
|
+
* 1. Original API arguments
|
|
227
|
+
* 2. Optional success callback
|
|
228
|
+
* 3. Optional error callback
|
|
229
|
+
* 4. Optional request params
|
|
230
|
+
*/
|
|
231
|
+
declare function extractArgsCallbacksAndParams<TArgs extends unknown[], TResponse, _TError = unknown>(argsWithCallbacks: [
|
|
152
232
|
...TArgs,
|
|
153
|
-
ApiSuccessHandler<
|
|
154
|
-
ApiErrorHandler<
|
|
233
|
+
ApiSuccessHandler<TResponse>?,
|
|
234
|
+
ApiErrorHandler<TResponse>?,
|
|
155
235
|
RuntimeRequestParams?
|
|
156
236
|
]): {
|
|
157
237
|
args: TArgs;
|
|
158
|
-
onSuccess?: ApiSuccessHandler<
|
|
159
|
-
onError?: ApiErrorHandler<
|
|
238
|
+
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
239
|
+
onError?: ApiErrorHandler<TResponse>;
|
|
160
240
|
params?: RuntimeRequestParams;
|
|
161
241
|
};
|
|
162
242
|
|
|
163
|
-
|
|
243
|
+
/**
|
|
244
|
+
* Optional callbacks used while converting a generated HTTP response into `ApiResult<TResponse>`.
|
|
245
|
+
*
|
|
246
|
+
* `onSuccess` is called with `ApiSuccessResult<TResponse>` and `onError` is called with `ApiErrorResult<TResponse>`.
|
|
247
|
+
*/
|
|
248
|
+
type HandleApiResponseOptions<TResponse> = {
|
|
164
249
|
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
165
|
-
onError?: ApiErrorHandler<
|
|
250
|
+
onError?: ApiErrorHandler<TResponse>;
|
|
166
251
|
};
|
|
167
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Executes a generated API request and converts the result into `ApiResult<TResponse>`.
|
|
254
|
+
*
|
|
255
|
+
* Successful responses return `{ ok: true, status, response }`. Failed responses and thrown errors return `{ ok: false, status, error }`.
|
|
256
|
+
*/
|
|
257
|
+
declare function handleApiResponse<TResponse, TError>(call: () => Promise<HttpResponse<TResponse, TError>>, options?: HandleApiResponseOptions<TResponse>): Promise<ApiResult<TResponse>>;
|
|
168
258
|
|
|
169
259
|
/** Values supported by the generated API SortDirection enum. */
|
|
170
260
|
type ApiSortDirection = "Default" | "Ascending" | "Descending";
|
|
@@ -195,4 +285,4 @@ declare function getSortDirectionFromSortType(sortType: SortType | null | undefi
|
|
|
195
285
|
*/
|
|
196
286
|
declare function toFormData<T extends object>(payload: T): FormData;
|
|
197
287
|
|
|
198
|
-
export { type ApiErrorHandler, type ApiMethodCallbacks, type ApiResult, type ApiSortDirection, type ApiSuccessHandler, type ExtractDataIfPaginated, 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, getSortDirectionFromSortType, getSortTypeFromSortDirection, handleApiResponse, sortTypes, toFormData };
|
|
288
|
+
export { type ApiErrorHandler, type ApiErrorResult, type ApiMethodCallbacks, 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 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oCAAoC,CAAC;AACnD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,oBAAoB,CAAC"}
|