typedapi-client-helpers 0.1.12 → 0.1.14
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/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/package.json +1 -1
- package/scripts/generate-api-minimal.mjs +39 -55
package/dist/index.d.cts
CHANGED
|
@@ -189,6 +189,17 @@ type ApiMethodCallbacks<TResponse> = {
|
|
|
189
189
|
params?: RequestParams;
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
+
type ApiMethodOptions<TResponse, TError = unknown, TRequestParams = RuntimeRequestParams> = {
|
|
193
|
+
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
194
|
+
onError?: ApiErrorHandler<TError>;
|
|
195
|
+
params?: TRequestParams;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
type ApiMethodArguments<TMethod extends (...args: any[]) => unknown, TRequestParams = RuntimeRequestParams> = Parameters<TMethod> extends [
|
|
199
|
+
...infer Arguments,
|
|
200
|
+
TRequestParams?
|
|
201
|
+
] ? Arguments : Parameters<TMethod>;
|
|
202
|
+
|
|
192
203
|
/**
|
|
193
204
|
* Sort direction value accepted by generated query objects.
|
|
194
205
|
*
|
|
@@ -287,4 +298,4 @@ declare function getSortDirectionFromSortType(sortType: SortType | null | undefi
|
|
|
287
298
|
*/
|
|
288
299
|
declare function toFormData<T extends object>(payload: T): FormData;
|
|
289
300
|
|
|
290
|
-
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 };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -189,6 +189,17 @@ type ApiMethodCallbacks<TResponse> = {
|
|
|
189
189
|
params?: RequestParams;
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
+
type ApiMethodOptions<TResponse, TError = unknown, TRequestParams = RuntimeRequestParams> = {
|
|
193
|
+
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
194
|
+
onError?: ApiErrorHandler<TError>;
|
|
195
|
+
params?: TRequestParams;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
type ApiMethodArguments<TMethod extends (...args: any[]) => unknown, TRequestParams = RuntimeRequestParams> = Parameters<TMethod> extends [
|
|
199
|
+
...infer Arguments,
|
|
200
|
+
TRequestParams?
|
|
201
|
+
] ? Arguments : Parameters<TMethod>;
|
|
202
|
+
|
|
192
203
|
/**
|
|
193
204
|
* Sort direction value accepted by generated query objects.
|
|
194
205
|
*
|
|
@@ -287,4 +298,4 @@ declare function getSortDirectionFromSortType(sortType: SortType | null | undefi
|
|
|
287
298
|
*/
|
|
288
299
|
declare function toFormData<T extends object>(payload: T): FormData;
|
|
289
300
|
|
|
290
|
-
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 };
|
|
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 };
|
package/package.json
CHANGED
|
@@ -33,16 +33,16 @@ const config = {
|
|
|
33
33
|
const swaggerFile =
|
|
34
34
|
process.env.SWAGGER_FILE ??
|
|
35
35
|
process.env.npm_config_swagger_file ??
|
|
36
|
-
config.swaggerFile
|
|
37
|
-
"swagger/swagger.json";
|
|
36
|
+
config.swaggerFile;
|
|
38
37
|
|
|
39
38
|
const swaggerUrl =
|
|
40
39
|
process.env.SWAGGER_URL ??
|
|
41
40
|
process.env.npm_config_swagger_url ??
|
|
42
|
-
config.swaggerUrl
|
|
43
|
-
"https://localhost:7000/swagger/v1/swagger.json";
|
|
41
|
+
config.swaggerUrl;
|
|
44
42
|
|
|
45
|
-
const swaggerInput = swaggerFile
|
|
43
|
+
const swaggerInput = swaggerFile
|
|
44
|
+
? path.resolve(cwd, swaggerFile)
|
|
45
|
+
: (swaggerUrl ?? path.resolve(cwd, "swagger/swagger.json"));
|
|
46
46
|
|
|
47
47
|
const apiRoot = path.resolve(
|
|
48
48
|
cwd,
|
|
@@ -112,10 +112,6 @@ function toQueryName(methodName) {
|
|
|
112
112
|
return `${pascalCase(methodName)}Query`;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
function toOptionsName(methodName) {
|
|
116
|
-
return `${pascalCase(methodName)}Options`;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
115
|
function cleanDirectory(directory) {
|
|
120
116
|
if (fs.existsSync(directory)) {
|
|
121
117
|
fs.rmSync(directory, { recursive: true, force: true });
|
|
@@ -552,22 +548,6 @@ export type ${toQueryName(methodName)} =
|
|
|
552
548
|
NonNullable<
|
|
553
549
|
Parameters<${className}["${methodName}"]>[0]
|
|
554
550
|
>;
|
|
555
|
-
`.trim(),
|
|
556
|
-
)
|
|
557
|
-
.join("\n\n");
|
|
558
|
-
|
|
559
|
-
const methodOptionTypes = generatedMethods
|
|
560
|
-
.map(({ methodName }) =>
|
|
561
|
-
`
|
|
562
|
-
export type ${toOptionsName(methodName)} = {
|
|
563
|
-
onSuccess?: ApiSuccessHandler<
|
|
564
|
-
ExtractResponse<ReturnType<${className}["${methodName}"]>>
|
|
565
|
-
>;
|
|
566
|
-
onError?: ApiErrorHandler<
|
|
567
|
-
ExtractError<ReturnType<${className}["${methodName}"]>>
|
|
568
|
-
>;
|
|
569
|
-
params?: RequestParams;
|
|
570
|
-
};
|
|
571
551
|
`.trim(),
|
|
572
552
|
)
|
|
573
553
|
.join("\n\n");
|
|
@@ -594,7 +574,11 @@ export async function ${methodName}(
|
|
|
594
574
|
ExtractResponse<ReturnType<${className}["${methodName}"]>>
|
|
595
575
|
> | null = null,
|
|
596
576
|
sortDirection?: SortDirection,
|
|
597
|
-
options:
|
|
577
|
+
options: ApiMethodOptions<
|
|
578
|
+
ExtractResponse<ReturnType<${className}["${methodName}"]>>,
|
|
579
|
+
ExtractError<ReturnType<${className}["${methodName}"]>>,
|
|
580
|
+
RequestParams
|
|
581
|
+
> = {}
|
|
598
582
|
): Promise<ApiResult<ExtractResponse<ReturnType<${className}["${methodName}"]>>>> {
|
|
599
583
|
const { onSuccess, onError, params } = options;
|
|
600
584
|
|
|
@@ -620,7 +604,11 @@ export async function ${methodName}(
|
|
|
620
604
|
return `
|
|
621
605
|
export async function ${methodName}(
|
|
622
606
|
query?: ${toQueryName(methodName)},
|
|
623
|
-
options:
|
|
607
|
+
options: ApiMethodOptions<
|
|
608
|
+
ExtractResponse<ReturnType<${className}["${methodName}"]>>,
|
|
609
|
+
ExtractError<ReturnType<${className}["${methodName}"]>>,
|
|
610
|
+
RequestParams
|
|
611
|
+
> = {}
|
|
624
612
|
): Promise<ApiResult<ExtractResponse<ReturnType<${className}["${methodName}"]>>>> {
|
|
625
613
|
const { onSuccess, onError, params } = options;
|
|
626
614
|
|
|
@@ -642,7 +630,11 @@ export async function ${methodName}(
|
|
|
642
630
|
`
|
|
643
631
|
export async function ${methodName}(
|
|
644
632
|
query?: ${toQueryName(methodName)},
|
|
645
|
-
options:
|
|
633
|
+
options: ApiMethodOptions<
|
|
634
|
+
ExtractResponse<ReturnType<${className}["${methodName}"]>>,
|
|
635
|
+
ExtractError<ReturnType<${className}["${methodName}"]>>,
|
|
636
|
+
RequestParams
|
|
637
|
+
> = {}
|
|
646
638
|
): Promise<
|
|
647
639
|
ApiResult<
|
|
648
640
|
ExtractResponse<
|
|
@@ -675,7 +667,11 @@ export async function ${methodName}(
|
|
|
675
667
|
data: Parameters<
|
|
676
668
|
${className}["${methodName}"]
|
|
677
669
|
>[0],
|
|
678
|
-
options:
|
|
670
|
+
options: ApiMethodOptions<
|
|
671
|
+
ExtractResponse<ReturnType<${className}["${methodName}"]>>,
|
|
672
|
+
ExtractError<ReturnType<${className}["${methodName}"]>>,
|
|
673
|
+
RequestParams
|
|
674
|
+
> = {}
|
|
679
675
|
): Promise<
|
|
680
676
|
ApiResult<
|
|
681
677
|
ExtractResponse<
|
|
@@ -706,9 +702,14 @@ export async function ${methodName}(
|
|
|
706
702
|
export async function ${methodName}(
|
|
707
703
|
...argsWithOptions: [
|
|
708
704
|
...ApiMethodArguments<
|
|
709
|
-
${className}["${methodName}"]
|
|
705
|
+
${className}["${methodName}"],
|
|
706
|
+
RequestParams
|
|
710
707
|
>,
|
|
711
|
-
|
|
708
|
+
ApiMethodOptions<
|
|
709
|
+
ExtractResponse<ReturnType<${className}["${methodName}"]>>,
|
|
710
|
+
ExtractError<ReturnType<${className}["${methodName}"]>>,
|
|
711
|
+
RequestParams
|
|
712
|
+
>?
|
|
712
713
|
]
|
|
713
714
|
): Promise<
|
|
714
715
|
ApiResult<
|
|
@@ -723,7 +724,11 @@ export async function ${methodName}(
|
|
|
723
724
|
|
|
724
725
|
const options =
|
|
725
726
|
args.length > ${methodArgumentCount}
|
|
726
|
-
? (args.pop() as
|
|
727
|
+
? (args.pop() as ApiMethodOptions<
|
|
728
|
+
ExtractResponse<ReturnType<${className}["${methodName}"]>>,
|
|
729
|
+
ExtractError<ReturnType<${className}["${methodName}"]>>,
|
|
730
|
+
RequestParams
|
|
731
|
+
>)
|
|
727
732
|
: {};
|
|
728
733
|
|
|
729
734
|
const { onSuccess, onError, params } = options ?? {};
|
|
@@ -755,8 +760,8 @@ export async function ${methodName}(
|
|
|
755
760
|
|
|
756
761
|
const runtimeTypeImportNames = [
|
|
757
762
|
"ApiResult",
|
|
758
|
-
"
|
|
759
|
-
"
|
|
763
|
+
"ApiMethodOptions",
|
|
764
|
+
...(hasRegularNonQueryMethods ? ["ApiMethodArguments"] : []),
|
|
760
765
|
"ExtractResponse",
|
|
761
766
|
"ExtractError",
|
|
762
767
|
|
|
@@ -812,20 +817,6 @@ export async function ${methodName}(
|
|
|
812
817
|
})
|
|
813
818
|
: "";
|
|
814
819
|
|
|
815
|
-
const apiMethodArgumentsType = hasRegularNonQueryMethods
|
|
816
|
-
? `
|
|
817
|
-
type ApiMethodArguments<
|
|
818
|
-
TMethod extends (...args: any[]) => unknown
|
|
819
|
-
> =
|
|
820
|
-
Parameters<TMethod> extends [
|
|
821
|
-
...infer Arguments,
|
|
822
|
-
RequestParams?
|
|
823
|
-
]
|
|
824
|
-
? Arguments
|
|
825
|
-
: Parameters<TMethod>;
|
|
826
|
-
`.trim()
|
|
827
|
-
: "";
|
|
828
|
-
|
|
829
820
|
const content = `
|
|
830
821
|
${runtimeValueImports}
|
|
831
822
|
|
|
@@ -837,18 +828,11 @@ ${generatedValueImports}
|
|
|
837
828
|
|
|
838
829
|
${generatedTypeImports}
|
|
839
830
|
|
|
840
|
-
${apiMethodArgumentsType}
|
|
841
|
-
|
|
842
831
|
/* =======================
|
|
843
832
|
Query Types
|
|
844
833
|
======================= */
|
|
845
834
|
${queryTypes}
|
|
846
835
|
|
|
847
|
-
/* =======================
|
|
848
|
-
Method Option Types
|
|
849
|
-
======================= */
|
|
850
|
-
${methodOptionTypes}
|
|
851
|
-
|
|
852
836
|
/* =======================
|
|
853
837
|
API Instance
|
|
854
838
|
======================= */
|