mulink 1.1.7 → 1.1.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.
@@ -3470,10 +3470,15 @@ ${actions}`;
3470
3470
  parameterProcessing = "";
3471
3471
  requestOptionsParams = "";
3472
3472
  }
3473
- const parsedInputType = hasRequestBody || hasAnyParams ? schemaName.includes("\n") ? `z.infer<typeof z.object({ body: ${operationName}RequestSchema, params: ${operationName}ParamsSchema })>` : `z.infer<typeof ${schemaName}>` : "void";
3473
+ const schemaConstantName = hasRequestBody && hasAnyParams ? `${operationName}InputSchema` : null;
3474
+ const schemaConstantDefinition = schemaConstantName ? `const ${schemaConstantName} = z.object({ body: ${operationName}RequestSchema, params: ${operationName}ParamsSchema })
3475
+
3476
+ ` : "";
3477
+ const parsedInputType = hasRequestBody || hasAnyParams ? schemaConstantName ? `z.infer<typeof ${schemaConstantName}>` : `z.infer<typeof ${schemaName}>` : "void";
3474
3478
  const ctxType = requiresAuth || hasRateLimit ? "{ user?: any; ratelimit?: { remaining: number } }" : "any";
3475
3479
  const ctxDeclaration = requiresAuth || hasRateLimit ? `ctx: ${ctxType}` : "ctx?: any";
3476
- const actionArgsType = schemaName.includes("\n") ? `{ parsedInput: z.infer<typeof z.object({ body: ${operationName}RequestSchema, params: ${operationName}ParamsSchema })>; ${ctxDeclaration} }` : `{ parsedInput: ${parsedInputType}; ${ctxDeclaration} }`;
3480
+ const actionArgsType = schemaConstantName ? `{ parsedInput: z.infer<typeof ${schemaConstantName}>; ${ctxDeclaration} }` : `{ parsedInput: ${parsedInputType}; ${ctxDeclaration} }`;
3481
+ const actionArgsTypeForTemplate = actionArgsType.replace(/\n/g, " ").replace(/\s+/g, " ").trim();
3477
3482
  const clientName = requiresAuth || hasRateLimit ? "authActionClient" : "actionClientWithMeta";
3478
3483
  const rateLimitCode = hasRateLimit ? `
3479
3484
  ${this.commentLine("Rate limiting", 6)} const { userAgent, ip } = await getClientInfo()
@@ -3496,15 +3501,15 @@ ${this.commentLine("Rate limiting", 6)} const { userAgent, ip } = await get
3496
3501
  endpoint,
3497
3502
  "React cache, input validation, error handling"
3498
3503
  );
3499
- return `${docBlock}export const ${actionName} = cache(
3504
+ return `${docBlock}${schemaConstantDefinition}export const ${actionName} = cache(
3500
3505
  ${clientName}
3501
3506
  .metadata({
3502
3507
  name: "${kebabActionName}",
3503
3508
  requiresAuth: ${requiresAuth}${hasRateLimit ? `,
3504
3509
  rateLimit: { requests: ${endpoint.metadata.rateLimit?.requests || 10}, window: "${endpoint.metadata.rateLimit?.window || "1m"}" }` : ""}
3505
3510
  })
3506
- .schema(${schemaName.includes("\n") ? `z.object({ body: ${operationName}RequestSchema, params: ${operationName}ParamsSchema })` : schemaName})
3507
- .action(async ({ parsedInput, ctx }: ${actionArgsType}) => {
3511
+ .schema(${schemaConstantName || schemaName})
3512
+ .action(async ({ parsedInput, ctx }: ${actionArgsTypeForTemplate}) => {
3508
3513
  const startTime = Date.now()
3509
3514
 
3510
3515
  try {${rateLimitCode}${parameterProcessing}
@@ -3563,14 +3568,14 @@ ${this.commentLine("Process file with compression and validation if enabled", 10
3563
3568
  endpoint,
3564
3569
  "Input validation, revalidation, error handling"
3565
3570
  );
3566
- return `${mutationDocBlock}export const ${actionName} = ${clientName}
3571
+ return `${mutationDocBlock}${schemaConstantDefinition}export const ${actionName} = ${clientName}
3567
3572
  .metadata({
3568
3573
  name: "${kebabActionName}",
3569
3574
  requiresAuth: ${requiresAuth}${hasRateLimit ? `,
3570
3575
  rateLimit: { requests: ${endpoint.metadata.rateLimit?.requests || 10}, window: "${endpoint.metadata.rateLimit?.window || "1m"}" }` : ""}
3571
3576
  })
3572
- .schema(${schemaName.includes("\n") ? `z.object({ body: ${operationName}RequestSchema, params: ${operationName}ParamsSchema })` : schemaName})
3573
- .action(async ({ parsedInput, ctx }: ${actionArgsType}) => {
3577
+ .schema(${schemaConstantName || schemaName})
3578
+ .action(async ({ parsedInput, ctx }: ${actionArgsTypeForTemplate}) => {
3574
3579
  const startTime = Date.now()
3575
3580
 
3576
3581
  try {${rateLimitCode}${parameterProcessing}${fileUploadCode}
@@ -3879,6 +3884,23 @@ ${Object.keys(endpointsByTag).map((tag) => `export * from './${toValidIdentifier
3879
3884
  const enabledCondition = pathParameters.length > 0 ? `!!${pathParameters.map((parameter) => parameter.name).join(" && !!")}` : "true";
3880
3885
  const actionCallParams = this.buildActionCallParams(endpoint, false);
3881
3886
  if (hasSearchParams) {
3887
+ const queryParamTypes = queryParameters.map((param) => {
3888
+ const isRequired = param.required;
3889
+ const paramType = this.getTypeFromZodSchema(param.schema);
3890
+ return `${param.name}${isRequired ? "" : "?"}: ${paramType}`;
3891
+ }).join("; ");
3892
+ const queryParamsBuild = queryParameters.length > 0 ? `// Build query params object with only the parameters the endpoint expects
3893
+ const queryParams: { ${queryParamTypes} } = {
3894
+ ${queryParameters.map((param) => {
3895
+ if (param.name === "query") {
3896
+ return `${param.name}: ${param.name} || searchParams.search || ''`;
3897
+ } else if (param.name === "limit") {
3898
+ return `${param.name}: ${param.name} !== undefined ? ${param.name} : searchParams.limit`;
3899
+ } else {
3900
+ return `${param.name}: ${param.name} !== undefined ? ${param.name} : undefined`;
3901
+ }
3902
+ }).join(",\n ")}
3903
+ }` : "";
3882
3904
  const queryParamObject = queryParameters.length > 0 ? `{ ${queryParameters.map((param) => `${param.name}`).join(", ")} }` : "{}";
3883
3905
  return `/**
3884
3906
  * Optimized query hook for ${endpoint.method} ${endpoint.path}
@@ -3893,7 +3915,8 @@ export function ${hookName}(${parameterTypes.length > 0 ? `${parameterTypes.join
3893
3915
  queryKey: [...${queryKey}, searchParams],
3894
3916
  queryFn: async ({ signal }: { signal?: AbortSignal }) => {
3895
3917
  try {
3896
- const result = await resolveActionResult<${returnType}>(${actionName}(${actionCallParams.replace(queryParamObject, "{ ...searchParams }")}))
3918
+ ${queryParamsBuild}
3919
+ const result = await resolveActionResult<${returnType}>(${actionName}(${actionCallParams.replace(queryParamObject, "queryParams")}))
3897
3920
  return result
3898
3921
  } catch (error) {
3899
3922
  handleActionError(error)
@@ -3933,16 +3956,19 @@ export function ${hookName.replace("use", "useInfinite")}(${parameterTypes.lengt
3933
3956
  queryFn: async ({ pageParam = 1, signal }: { pageParam?: number; signal?: AbortSignal }) => {
3934
3957
  try {
3935
3958
  // Build query params object with only the parameters the endpoint expects
3936
- const queryParams: Record<string, any> = {}
3937
- ${queryParameters.map((param) => {
3959
+ const queryParams: { ${queryParamTypes} } = {
3960
+ ${queryParameters.map((param) => {
3938
3961
  if (param.name === "page" && hasPageParam) {
3939
- return `queryParams.${param.name} = pageParam`;
3962
+ return `${param.name}: pageParam`;
3963
+ } else if (param.name === "query") {
3964
+ return `${param.name}: ${param.name} || searchParams.search || ''`;
3940
3965
  } else if (param.name === "limit") {
3941
- return `queryParams.${param.name} = searchParams.limit`;
3966
+ return `${param.name}: ${param.name} !== undefined ? ${param.name} : searchParams.limit`;
3942
3967
  } else {
3943
- return `if ('${param.name}' in searchParams) queryParams.${param.name} = searchParams.${param.name}`;
3968
+ return `${param.name}: ${param.name} !== undefined ? ${param.name} : undefined`;
3969
+ }
3970
+ }).join(",\n ")}
3944
3971
  }
3945
- }).join("\n ")}
3946
3972
  const result = await resolveActionResult<${returnType}>(${actionName}(${actionCallParams.replace(queryParamObject, "queryParams")}))
3947
3973
  return result
3948
3974
  } catch (error) {
@@ -4401,14 +4427,8 @@ export function useBridgeQuery<TData = unknown, TError = Error>(
4401
4427
  refetchOnWindowFocus: true,
4402
4428
  refetchOnReconnect: true,
4403
4429
  refetchOnMount: 'always',
4404
- // React Query v5: placeholderData cannot be a function type
4405
- // Use keepPreviousData pattern: return previousData if it exists and is not a function
4406
- placeholderData: (previousData) => {
4407
- if (previousData === undefined) return undefined
4408
- // Type guard: ensure we don't return a function (React Query v5 requirement)
4409
- if (typeof previousData === 'function') return undefined
4410
- return previousData
4411
- } as any,
4430
+ // React Query v5: placeholderData returns previous data if available
4431
+ placeholderData: (previousData) => previousData,
4412
4432
  retry: (failureCount: number, error: TError) => {
4413
4433
  if (error instanceof Error && error.message.includes('4')) return false
4414
4434
  return failureCount < 3
@@ -4421,15 +4441,17 @@ export function useBridgeQuery<TData = unknown, TError = Error>(
4421
4441
  * Enhanced infinite query wrapper
4422
4442
  * React Query v5: Optimized for paginated data with infinite scrolling
4423
4443
  */
4424
- export function useBridgeInfiniteQuery<TData = unknown, TError = Error>(
4444
+ export function useBridgeInfiniteQuery<TData = unknown, TError = Error, TPageParam = number>(
4425
4445
  queryKey: QueryKey,
4426
- queryFn: QueryFunction<TData, QueryKey>,
4427
- options?: Partial<UseInfiniteQueryOptions<TData, TError, TData, QueryKey>>
4446
+ queryFn: QueryFunction<TData, QueryKey, TPageParam>,
4447
+ options?: Partial<UseInfiniteQueryOptions<TData, TError, TData, QueryKey, TPageParam>> & {
4448
+ getNextPageParam?: (lastPage: TData, allPages: TData[]) => TPageParam | undefined
4449
+ }
4428
4450
  ) {
4429
- return useInfiniteQuery<TData, TError>({
4451
+ return useInfiniteQuery<TData, TError, TData, QueryKey, TPageParam>({
4430
4452
  queryKey,
4431
- initialPageParam: 1,
4432
- queryFn: queryFn as QueryFunction<TData, QueryKey>,
4453
+ initialPageParam: 1 as TPageParam,
4454
+ queryFn,
4433
4455
  staleTime: 5 * 60 * 1000,
4434
4456
  gcTime: 10 * 60 * 1000,
4435
4457
  refetchOnWindowFocus: true,
@@ -4439,6 +4461,8 @@ export function useBridgeInfiniteQuery<TData = unknown, TError = Error>(
4439
4461
  if (error instanceof Error && error.message.includes('4')) return false
4440
4462
  return failureCount < 3
4441
4463
  },
4464
+ // Provide default getNextPageParam if not provided
4465
+ getNextPageParam: options?.getNextPageParam || (() => undefined),
4442
4466
  ...options,
4443
4467
  })
4444
4468
  }
@@ -8501,7 +8525,7 @@ async function getToast(): Promise<{
8501
8525
  try {
8502
8526
  // Try to import sonner (common toast library)
8503
8527
  const sonner = await import('sonner')
8504
- toast = sonner
8528
+ toast = sonner.toast
8505
8529
  return toast
8506
8530
  } catch {
8507
8531
  // Fallback to console if toast library not available
@@ -9802,5 +9826,5 @@ exports.VersionChecker = VersionChecker;
9802
9826
  exports.__name = __name;
9803
9827
  exports.checkAndNotifyUpdates = checkAndNotifyUpdates;
9804
9828
  exports.createBridgeVersionChecker = createBridgeVersionChecker;
9805
- //# sourceMappingURL=chunk-RGFU7SMN.cjs.map
9806
- //# sourceMappingURL=chunk-RGFU7SMN.cjs.map
9829
+ //# sourceMappingURL=chunk-SSMOIVFN.cjs.map
9830
+ //# sourceMappingURL=chunk-SSMOIVFN.cjs.map