kmod-cli 1.4.6 → 1.4.8
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.
|
@@ -92,7 +92,7 @@ export interface DeleteManyParams {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
export interface CustomParams {
|
|
95
|
-
url
|
|
95
|
+
url?: string;
|
|
96
96
|
method?: 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
97
97
|
payload?: any;
|
|
98
98
|
query?: Record<string, any>;
|
|
@@ -160,6 +160,8 @@ export interface UseMutationOptions<TData = any> {
|
|
|
160
160
|
onError?: (error: DataProviderError) => void;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
export type Payload = any;
|
|
164
|
+
|
|
163
165
|
// ============ UTILITY FUNCTIONS ============
|
|
164
166
|
|
|
165
167
|
/**
|
|
@@ -431,7 +433,7 @@ class DataProvider {
|
|
|
431
433
|
const response = await this.httpClient.get<T>(url, meta);
|
|
432
434
|
|
|
433
435
|
// Handle wrapped response
|
|
434
|
-
const data = (response.data as any)
|
|
436
|
+
const data = (response.data as any) || response
|
|
435
437
|
|
|
436
438
|
return { data };
|
|
437
439
|
});
|
|
@@ -489,7 +491,7 @@ class DataProvider {
|
|
|
489
491
|
const response = await this.httpClient.post<T>(url, variables, meta);
|
|
490
492
|
|
|
491
493
|
// Handle wrapped response
|
|
492
|
-
const data = (response.data as any)
|
|
494
|
+
const data = (response.data as any) || response
|
|
493
495
|
|
|
494
496
|
return { data };
|
|
495
497
|
});
|
|
@@ -544,7 +546,7 @@ class DataProvider {
|
|
|
544
546
|
const response = await this.httpClient.patch<T>(url, variables, meta);
|
|
545
547
|
|
|
546
548
|
// Handle wrapped response
|
|
547
|
-
const data = (response.data as any)
|
|
549
|
+
const data = (response.data as any) || response
|
|
548
550
|
|
|
549
551
|
return { data };
|
|
550
552
|
});
|
|
@@ -603,7 +605,7 @@ class DataProvider {
|
|
|
603
605
|
const response = await this.httpClient.delete<T>(url, meta);
|
|
604
606
|
|
|
605
607
|
// Handle wrapped response
|
|
606
|
-
const data = (response.data as any)
|
|
608
|
+
const data = (response.data as any) || response
|
|
607
609
|
|
|
608
610
|
return { data };
|
|
609
611
|
});
|
|
@@ -646,8 +648,9 @@ class DataProvider {
|
|
|
646
648
|
}
|
|
647
649
|
|
|
648
650
|
async custom<T = any>(params: CustomParams): Promise<CustomResponse<T>> {
|
|
649
|
-
const { url, method = 'get', payload, query, headers } = params;
|
|
650
|
-
|
|
651
|
+
const { url , method = 'get', payload, query, headers } = params;
|
|
652
|
+
|
|
653
|
+
if (!url) throw this.handleError("No url provided");
|
|
651
654
|
try {
|
|
652
655
|
return await this.retryRequest(async () => {
|
|
653
656
|
const fullUrl = url.startsWith('http') ? url : `${this.apiUrl}${url}`;
|
|
@@ -793,7 +796,7 @@ export function useOne<T = any>(
|
|
|
793
796
|
|
|
794
797
|
export function useCreate<T = any, V = any>(
|
|
795
798
|
resource: string,
|
|
796
|
-
options: UseMutationOptions<T>
|
|
799
|
+
options: UseMutationOptions<T>
|
|
797
800
|
) {
|
|
798
801
|
const [loading, setLoading] = useState<boolean>(false);
|
|
799
802
|
const [error, setError] = useState<DataProviderError | null>(null);
|
|
@@ -807,7 +810,9 @@ export function useCreate<T = any, V = any>(
|
|
|
807
810
|
setError(null);
|
|
808
811
|
|
|
809
812
|
try {
|
|
810
|
-
const result = await dataProvider.create<T, V>(resource, {
|
|
813
|
+
const result = await dataProvider.create<T, V>(resource, {
|
|
814
|
+
variables
|
|
815
|
+
});
|
|
811
816
|
if (onSuccess) {
|
|
812
817
|
onSuccess(result.data);
|
|
813
818
|
}
|
|
@@ -829,7 +834,7 @@ export function useCreate<T = any, V = any>(
|
|
|
829
834
|
|
|
830
835
|
export function useUpdate<T = any, V = any>(
|
|
831
836
|
resource: string,
|
|
832
|
-
options: UseMutationOptions<T>
|
|
837
|
+
options: UseMutationOptions<T>
|
|
833
838
|
) {
|
|
834
839
|
const [loading, setLoading] = useState<boolean>(false);
|
|
835
840
|
const [error, setError] = useState<DataProviderError | null>(null);
|
|
@@ -868,7 +873,7 @@ export function useUpdate<T = any, V = any>(
|
|
|
868
873
|
|
|
869
874
|
export function useDelete<T = any>(
|
|
870
875
|
resource: string,
|
|
871
|
-
options: UseMutationOptions<T>
|
|
876
|
+
options: UseMutationOptions<T>
|
|
872
877
|
) {
|
|
873
878
|
const [loading, setLoading] = useState<boolean>(false);
|
|
874
879
|
const [error, setError] = useState<DataProviderError | null>(null);
|
|
@@ -907,23 +912,29 @@ export function useDelete<T = any>(
|
|
|
907
912
|
|
|
908
913
|
export function useCustom<T = any>(
|
|
909
914
|
resource: string,
|
|
910
|
-
options: UseMutationOptions<T>
|
|
915
|
+
options: UseMutationOptions<T> & CustomParams
|
|
911
916
|
) {
|
|
912
917
|
const [loading, setLoading] = useState<boolean>(false);
|
|
913
918
|
const [error, setError] = useState<DataProviderError | null>(null);
|
|
914
919
|
const [customData, setCustomData] = useState<T | null>(null);
|
|
915
920
|
|
|
916
921
|
const dataProvider = useDataProvider();
|
|
917
|
-
|
|
922
|
+
|
|
918
923
|
const { onSuccess, onError } = options;
|
|
919
|
-
|
|
924
|
+
|
|
920
925
|
const mutate = useCallback(
|
|
921
|
-
async (variables
|
|
926
|
+
async (variables?: Payload): Promise<T> => {
|
|
922
927
|
setLoading(true);
|
|
923
928
|
setError(null);
|
|
924
|
-
|
|
929
|
+
|
|
925
930
|
try {
|
|
926
|
-
const result = await dataProvider.custom<T>({
|
|
931
|
+
const result = await dataProvider.custom<T>({
|
|
932
|
+
url: resource,
|
|
933
|
+
payload: variables || options.payload || {},
|
|
934
|
+
method: options.method,
|
|
935
|
+
headers: options.headers,
|
|
936
|
+
query: options.query,
|
|
937
|
+
});
|
|
927
938
|
if (onSuccess) {
|
|
928
939
|
onSuccess(result.data);
|
|
929
940
|
}
|
|
@@ -939,10 +950,10 @@ export function useCustom<T = any>(
|
|
|
939
950
|
} finally {
|
|
940
951
|
setLoading(false);
|
|
941
952
|
}
|
|
942
|
-
},
|
|
953
|
+
},
|
|
943
954
|
[dataProvider, resource, onSuccess, onError]
|
|
944
955
|
);
|
|
945
|
-
|
|
956
|
+
|
|
946
957
|
return { mutate, loading, error, data: customData };
|
|
947
958
|
}
|
|
948
959
|
|