mulink 1.0.7 → 1.0.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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/lib/{chunk-FHGHNZLL.js → chunk-MEK5NG2G.js} +34 -10
- package/dist/lib/chunk-MEK5NG2G.js.map +1 -0
- package/dist/lib/{chunk-TAYTUTVA.cjs → chunk-PSLYNNKP.cjs} +34 -10
- package/dist/lib/chunk-PSLYNNKP.cjs.map +1 -0
- package/dist/lib/cli.cjs +16 -16
- package/dist/lib/cli.js +1 -1
- package/dist/lib/client.cjs +18 -18
- package/dist/lib/client.js +2 -2
- package/dist/lib/index.cjs +15 -15
- package/dist/lib/index.js +1 -1
- package/package.json +1 -1
- package/dist/lib/chunk-FHGHNZLL.js.map +0 -1
- package/dist/lib/chunk-TAYTUTVA.cjs.map +0 -1
|
@@ -3775,12 +3775,36 @@ const searchParamsParser = {
|
|
|
3775
3775
|
filter: parseAsString.withDefault(''),
|
|
3776
3776
|
}` : ""}
|
|
3777
3777
|
|
|
3778
|
-
|
|
3778
|
+
// Error handling utility
|
|
3779
3779
|
function handleActionError(error: unknown): never {
|
|
3780
3780
|
const message = error instanceof Error ? error.message : 'An unexpected error occurred'
|
|
3781
3781
|
toast.error(message)
|
|
3782
3782
|
throw new Error(message)
|
|
3783
|
-
}
|
|
3783
|
+
}
|
|
3784
|
+
|
|
3785
|
+
type ActionResultLike<T> = {
|
|
3786
|
+
data?: T
|
|
3787
|
+
serverError?: unknown
|
|
3788
|
+
validationErrors?: unknown
|
|
3789
|
+
}
|
|
3790
|
+
|
|
3791
|
+
async function resolveActionResult<T>(actionPromise: Promise<any>): Promise<T> {
|
|
3792
|
+
const result = await actionPromise
|
|
3793
|
+
if (result && typeof result === 'object') {
|
|
3794
|
+
const actionResult = result as ActionResultLike<T>
|
|
3795
|
+
if (actionResult.serverError) {
|
|
3796
|
+
const message = typeof actionResult.serverError === 'string' ? actionResult.serverError : 'Server action failed'
|
|
3797
|
+
throw new Error(message)
|
|
3798
|
+
}
|
|
3799
|
+
if (actionResult.validationErrors) {
|
|
3800
|
+
throw new Error('Validation failed, please check your input')
|
|
3801
|
+
}
|
|
3802
|
+
if (typeof actionResult.data !== 'undefined') {
|
|
3803
|
+
return actionResult.data as T
|
|
3804
|
+
}
|
|
3805
|
+
}
|
|
3806
|
+
return result as T
|
|
3807
|
+
}
|
|
3784
3808
|
|
|
3785
3809
|
${queryHooks}
|
|
3786
3810
|
|
|
@@ -3863,7 +3887,7 @@ export function ${hookName}(${parameterTypes.length > 0 ? `${parameterTypes.join
|
|
|
3863
3887
|
queryKey: [...${queryKey}, searchParams],
|
|
3864
3888
|
queryFn: async ({ signal }: { signal?: AbortSignal }) => {
|
|
3865
3889
|
try {
|
|
3866
|
-
const result = await ${actionName}(${actionCallParams.replace(queryParamObject, "{ ...searchParams }")})
|
|
3890
|
+
const result = await resolveActionResult<${returnType}>(${actionName}(${actionCallParams.replace(queryParamObject, "{ ...searchParams }")}))
|
|
3867
3891
|
return result
|
|
3868
3892
|
} catch (error) {
|
|
3869
3893
|
handleActionError(error)
|
|
@@ -3901,7 +3925,7 @@ export function ${hookName.replace("use", "useInfinite")}(${parameterTypes.lengt
|
|
|
3901
3925
|
queryKey: [...${queryKey}, 'infinite', searchParams],
|
|
3902
3926
|
queryFn: async ({ pageParam = 1, signal }: { pageParam?: number; signal?: AbortSignal }) => {
|
|
3903
3927
|
try {
|
|
3904
|
-
const result = await ${actionName}(${actionCallParams.replace(queryParamObject, "{ ...searchParams, page: pageParam, limit: searchParams.limit }")})
|
|
3928
|
+
const result = await resolveActionResult<${returnType}>(${actionName}(${actionCallParams.replace(queryParamObject, "{ ...searchParams, page: pageParam, limit: searchParams.limit }")}))
|
|
3905
3929
|
return result
|
|
3906
3930
|
} catch (error) {
|
|
3907
3931
|
handleActionError(error)
|
|
@@ -3936,7 +3960,7 @@ export function ${hookName.replace("use", "useSuspense")}(${parameterTypes.lengt
|
|
|
3936
3960
|
return useSuspenseQuery({
|
|
3937
3961
|
queryKey: ${queryKey},
|
|
3938
3962
|
queryFn: async () => {
|
|
3939
|
-
const result = await ${actionName}(${actionCallParams})
|
|
3963
|
+
const result = await resolveActionResult<${returnType}>(${actionName}(${actionCallParams}))
|
|
3940
3964
|
return result
|
|
3941
3965
|
},
|
|
3942
3966
|
staleTime: ${staleTime},
|
|
@@ -3957,7 +3981,7 @@ export function ${hookName}(${parameterTypes.length > 0 ? `${parameterTypes.join
|
|
|
3957
3981
|
queryKey: ${queryKey},
|
|
3958
3982
|
queryFn: async ({ signal }: { signal?: AbortSignal }) => {
|
|
3959
3983
|
try {
|
|
3960
|
-
const result = await ${actionName}(${actionCallParams})
|
|
3984
|
+
const result = await resolveActionResult<${returnType}>(${actionCallParams === "{}" ? `${actionName}()` : `${actionName}(${actionCallParams})`})
|
|
3961
3985
|
return result
|
|
3962
3986
|
} catch (error) {
|
|
3963
3987
|
handleActionError(error)
|
|
@@ -3993,7 +4017,7 @@ export function ${hookName.replace("use", "useSuspense")}(${parameterTypes.lengt
|
|
|
3993
4017
|
return useSuspenseQuery({
|
|
3994
4018
|
queryKey: ${queryKey},
|
|
3995
4019
|
queryFn: async () => {
|
|
3996
|
-
const result = await ${actionName}(${actionCallParams})
|
|
4020
|
+
const result = await resolveActionResult<${returnType}>(${actionCallParams === "{}" ? `${actionName}()` : `${actionName}(${actionCallParams})`})
|
|
3997
4021
|
return result
|
|
3998
4022
|
},
|
|
3999
4023
|
staleTime: ${staleTime},
|
|
@@ -4047,7 +4071,7 @@ export function ${hookName}(options?: {
|
|
|
4047
4071
|
const mutation = useMutation({
|
|
4048
4072
|
mutationFn: async (variables: ${inputType}): Promise<${outputType}> => {
|
|
4049
4073
|
try {
|
|
4050
|
-
const result = await ${actionName}(${variablesParam === "undefined" ? "" : "variables"})
|
|
4074
|
+
const result = await resolveActionResult<${outputType}>(${actionName}(${variablesParam === "undefined" ? "" : "variables"}))
|
|
4051
4075
|
return (result ?? ({} as ${outputType}))
|
|
4052
4076
|
} catch (error) {
|
|
4053
4077
|
handleActionError(error)
|
|
@@ -9630,5 +9654,5 @@ exports.VersionChecker = VersionChecker;
|
|
|
9630
9654
|
exports.__name = __name;
|
|
9631
9655
|
exports.checkAndNotifyUpdates = checkAndNotifyUpdates;
|
|
9632
9656
|
exports.createBridgeVersionChecker = createBridgeVersionChecker;
|
|
9633
|
-
//# sourceMappingURL=chunk-
|
|
9634
|
-
//# sourceMappingURL=chunk-
|
|
9657
|
+
//# sourceMappingURL=chunk-PSLYNNKP.cjs.map
|
|
9658
|
+
//# sourceMappingURL=chunk-PSLYNNKP.cjs.map
|