mulink 1.0.9 → 1.1.1
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-EED6FUEW.js → chunk-ALNOUWFZ.js} +95 -11
- package/dist/lib/chunk-ALNOUWFZ.js.map +1 -0
- package/dist/lib/{chunk-7WH2SJ23.cjs → chunk-KATSH6VN.cjs} +95 -11
- package/dist/lib/chunk-KATSH6VN.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-7WH2SJ23.cjs.map +0 -1
- package/dist/lib/chunk-EED6FUEW.js.map +0 -1
|
@@ -3465,7 +3465,10 @@ ${actions}`;
|
|
|
3465
3465
|
parameterProcessing = "";
|
|
3466
3466
|
requestOptionsParams = "";
|
|
3467
3467
|
}
|
|
3468
|
-
const parsedInputType = hasRequestBody || hasAnyParams ? `z.infer<typeof
|
|
3468
|
+
const parsedInputType = hasRequestBody || hasAnyParams ? schemaName.includes("\n") ? `z.infer<typeof z.object({
|
|
3469
|
+
body: ${operationName}RequestSchema,
|
|
3470
|
+
params: ${operationName}ParamsSchema
|
|
3471
|
+
})>` : `z.infer<typeof ${schemaName}>` : "void";
|
|
3469
3472
|
const ctxType = requiresAuth || hasRateLimit ? "{ user?: any; ratelimit?: { remaining: number } }" : "any";
|
|
3470
3473
|
const ctxDeclaration = requiresAuth || hasRateLimit ? `ctx: ${ctxType}` : "ctx?: any";
|
|
3471
3474
|
const actionArgsType = `{ parsedInput: ${parsedInputType}; ${ctxDeclaration} }`;
|
|
@@ -3505,7 +3508,7 @@ ${this.commentLine("Rate limiting", 6)} const { userAgent, ip } = await get
|
|
|
3505
3508
|
try {${rateLimitCode}${parameterProcessing}
|
|
3506
3509
|
|
|
3507
3510
|
// Execute API call with enhanced error handling
|
|
3508
|
-
const response = await apiClient.${tagName}.${actionName}({${requestOptionsParams}${requestOptionsParams ? "," : ""}
|
|
3511
|
+
const response = await apiClient.${tagName}.${actionName}({${requestOptionsParams}${requestOptionsParams && !requestOptionsParams.trim().endsWith(",") ? "," : ""}
|
|
3509
3512
|
config: {
|
|
3510
3513
|
timeout: ${endpoint.metadata.timeout || this.configuration.api.timeout},
|
|
3511
3514
|
retries: ${this.configuration.api.retries},
|
|
@@ -3571,7 +3574,7 @@ ${this.commentLine("Process file with compression and validation if enabled", 10
|
|
|
3571
3574
|
try {${rateLimitCode}${parameterProcessing}${fileUploadCode}
|
|
3572
3575
|
|
|
3573
3576
|
// Execute API call with enhanced configuration
|
|
3574
|
-
const response = await apiClient.${tagName}.${actionName}({${requestOptionsParams}${requestOptionsParams ? "," : ""}
|
|
3577
|
+
const response = await apiClient.${tagName}.${actionName}({${requestOptionsParams}${requestOptionsParams && !requestOptionsParams.trim().endsWith(",") ? "," : ""}
|
|
3575
3578
|
config: {
|
|
3576
3579
|
timeout: ${endpoint.metadata.timeout || this.configuration.api.timeout},
|
|
3577
3580
|
retries: ${this.configuration.api.retries},
|
|
@@ -3751,7 +3754,7 @@ var HookGenerator = class {
|
|
|
3751
3754
|
...reactQueryImports.length > 0 ? [`import { ${reactQueryImports.join(", ")} } from '@tanstack/react-query'`] : [],
|
|
3752
3755
|
...reactImports.length > 0 ? [`import { ${reactImports.join(", ")} } from 'react'`] : [],
|
|
3753
3756
|
...hasSearchParams ? ["import { parseAsInteger, parseAsString, useQueryStates } from 'nuqs'"] : [],
|
|
3754
|
-
...hasMutations ? ["import { toast } from 'sonner'"] : [],
|
|
3757
|
+
...hasQueries || hasMutations ? ["import { toast } from 'sonner'"] : [],
|
|
3755
3758
|
`import { ${[...queries, ...mutations].map((endpoint) => toActionName(endpoint.operationId || endpoint.id)).join(", ")} } from '${actionsImport}'`,
|
|
3756
3759
|
...schemaImportsString ? [`import {
|
|
3757
3760
|
${schemaImportsString}
|
|
@@ -4084,7 +4087,7 @@ ${cancelQueriesCode}
|
|
|
4084
4087
|
// Optimistic update (if provided)
|
|
4085
4088
|
if (options?.optimisticUpdate) {
|
|
4086
4089
|
const optimisticValue = options.optimisticUpdate(variables)
|
|
4087
|
-
setOptimisticData(optimisticValue)
|
|
4090
|
+
setOptimisticData(optimisticValue as ${inputType})
|
|
4088
4091
|
}
|
|
4089
4092
|
|
|
4090
4093
|
return {}
|
|
@@ -7830,6 +7833,7 @@ export function createUploadFormData(
|
|
|
7830
7833
|
const useXHR = progressConfig?.useXHR !== false;
|
|
7831
7834
|
const presignedActionName = presignedEndpoint ? toActionName(presignedEndpoint.operationId || presignedEndpoint.id) : null;
|
|
7832
7835
|
const presignedOperationName = presignedEndpoint ? this.getOperationName(presignedEndpoint) : null;
|
|
7836
|
+
const paramsSchemaName = endpoint.parameters.length > 0 ? `${operationName}ParamsSchema` : null;
|
|
7833
7837
|
const imports = [
|
|
7834
7838
|
`'use client'`,
|
|
7835
7839
|
``,
|
|
@@ -7839,7 +7843,7 @@ export function createUploadFormData(
|
|
|
7839
7843
|
presignedEnabled && presignedActionName ? `import { ${presignedActionName} } from '${actionsImport}'` : null,
|
|
7840
7844
|
`import { validateFile, compressFile, createUploadFormData, type UploadConfig } from '${uploadUtilsImport}'`,
|
|
7841
7845
|
`import type { z } from 'zod'`,
|
|
7842
|
-
`import type { ${operationName}RequestSchema, ${operationName}ResponseSchema } from '${schemasImport}'`,
|
|
7846
|
+
`import type { ${operationName}RequestSchema, ${operationName}ResponseSchema${paramsSchemaName ? `, ${paramsSchemaName}` : ""} } from '${schemasImport}'`,
|
|
7843
7847
|
presignedEnabled && presignedOperationName ? `import type { ${presignedOperationName}RequestSchema, ${presignedOperationName}ResponseSchema } from '${schemasImport}'` : null
|
|
7844
7848
|
].filter(Boolean).join("\n");
|
|
7845
7849
|
const presignedHelpers = presignedEnabled ? `
|
|
@@ -8096,6 +8100,30 @@ async function uploadViaBackendApi(
|
|
|
8096
8100
|
${presignedHelpers}
|
|
8097
8101
|
${backendUploadHelper || ""}
|
|
8098
8102
|
|
|
8103
|
+
type ActionResultLike<T> = {
|
|
8104
|
+
data?: T
|
|
8105
|
+
serverError?: unknown
|
|
8106
|
+
validationErrors?: unknown
|
|
8107
|
+
}
|
|
8108
|
+
|
|
8109
|
+
async function resolveActionResult<T>(actionPromise: Promise<any>): Promise<T> {
|
|
8110
|
+
const result = await actionPromise
|
|
8111
|
+
if (result && typeof result === 'object') {
|
|
8112
|
+
const actionResult = result as ActionResultLike<T>
|
|
8113
|
+
if (actionResult.serverError) {
|
|
8114
|
+
const message = typeof actionResult.serverError === 'string' ? actionResult.serverError : 'Server action failed'
|
|
8115
|
+
throw new Error(message)
|
|
8116
|
+
}
|
|
8117
|
+
if (actionResult.validationErrors) {
|
|
8118
|
+
throw new Error('Validation failed, please check your input')
|
|
8119
|
+
}
|
|
8120
|
+
if (typeof actionResult.data !== 'undefined') {
|
|
8121
|
+
return actionResult.data as T
|
|
8122
|
+
}
|
|
8123
|
+
}
|
|
8124
|
+
return result as T
|
|
8125
|
+
}
|
|
8126
|
+
|
|
8099
8127
|
/**
|
|
8100
8128
|
* Upload hook for ${endpoint.method} ${endpoint.path}
|
|
8101
8129
|
* Features: ${presignedEnabled ? "Presigned URL upload (direct to S3/MinIO), " : ""}File validation, compression, progress tracking
|
|
@@ -8103,8 +8131,9 @@ ${backendUploadHelper || ""}
|
|
|
8103
8131
|
* Best Practice: ${presignedEnabled ? "Uses presigned URLs for direct uploads to S3/MinIO, reducing backend load" : "Standard FormData upload with progress tracking"}
|
|
8104
8132
|
*/
|
|
8105
8133
|
export type ${operationName}UploadInput = {
|
|
8106
|
-
file: File
|
|
8134
|
+
${endpoint.path.includes("multiple") ? "files: File[]" : "file: File"}
|
|
8107
8135
|
additionalFields?: Record<string, string | number | boolean>
|
|
8136
|
+
${paramsSchemaName ? "folder?: string" : ""}
|
|
8108
8137
|
}
|
|
8109
8138
|
|
|
8110
8139
|
${presignedEnabled && !fallbackEnabled ? `const directUploadsEnabled = process.env.NEXT_PUBLIC_ENABLE_DIRECT_UPLOADS !== "false"` : ""}
|
|
@@ -8118,7 +8147,46 @@ export function ${hookName}Upload(options?: {
|
|
|
8118
8147
|
const queryClient = useQueryClient()
|
|
8119
8148
|
|
|
8120
8149
|
return useMutation<z.infer<typeof ${operationName}ResponseSchema>, Error, ${operationName}UploadInput>({
|
|
8121
|
-
mutationFn: async ({ file, additionalFields }: ${operationName}UploadInput) => {
|
|
8150
|
+
mutationFn: async ({ ${endpoint.path.includes("multiple") ? "files" : "file"}, additionalFields, ${paramsSchemaName ? "folder" : ""} }: ${operationName}UploadInput) => {
|
|
8151
|
+
${endpoint.path.includes("multiple") ? `
|
|
8152
|
+
// Validate all files
|
|
8153
|
+
for (const file of files) {
|
|
8154
|
+
const validation = validateFile(file, options?.uploadConfig)
|
|
8155
|
+
if (!validation.valid) {
|
|
8156
|
+
throw new Error(validation.error || \`File validation failed for \${file.name}\`)
|
|
8157
|
+
}
|
|
8158
|
+
}
|
|
8159
|
+
|
|
8160
|
+
// Compress files if enabled
|
|
8161
|
+
const processedFiles = await Promise.all(
|
|
8162
|
+
files.map(file => compressFile(file, options?.uploadConfig?.compression?.formats))
|
|
8163
|
+
)
|
|
8164
|
+
|
|
8165
|
+
// Create FormData with all files
|
|
8166
|
+
const formData = new FormData()
|
|
8167
|
+
processedFiles.forEach((file, index) => {
|
|
8168
|
+
formData.append(\`file_\${index}\`, file)
|
|
8169
|
+
})
|
|
8170
|
+
|
|
8171
|
+
if (additionalFields) {
|
|
8172
|
+
Object.entries(additionalFields).forEach(([key, value]) => {
|
|
8173
|
+
formData.append(key, String(value))
|
|
8174
|
+
})
|
|
8175
|
+
}
|
|
8176
|
+
|
|
8177
|
+
// Convert FormData to the format expected by the action
|
|
8178
|
+
const actionInput = {
|
|
8179
|
+
body: formData as any,
|
|
8180
|
+
params: {
|
|
8181
|
+
query: ${paramsSchemaName ? "folder ? { folder } : undefined" : "undefined"}
|
|
8182
|
+
}
|
|
8183
|
+
}
|
|
8184
|
+
|
|
8185
|
+
// Use server action for upload and extract data from SafeActionResult
|
|
8186
|
+
const result = await resolveActionResult<z.infer<typeof ${operationName}ResponseSchema>>(
|
|
8187
|
+
${actionName}(actionInput)
|
|
8188
|
+
)
|
|
8189
|
+
return result` : presignedEnabled ? uploadLogic : `
|
|
8122
8190
|
// Validate file
|
|
8123
8191
|
const validation = validateFile(file, options?.uploadConfig)
|
|
8124
8192
|
if (!validation.valid) {
|
|
@@ -8128,7 +8196,23 @@ export function ${hookName}Upload(options?: {
|
|
|
8128
8196
|
// Compress if enabled
|
|
8129
8197
|
const processedFile = await compressFile(file, options?.uploadConfig?.compression?.formats)
|
|
8130
8198
|
|
|
8131
|
-
|
|
8199
|
+
// Create FormData for the file
|
|
8200
|
+
const formData = createUploadFormData(processedFile, additionalFields)
|
|
8201
|
+
|
|
8202
|
+
// Convert FormData to the format expected by the action
|
|
8203
|
+
const actionInput = {
|
|
8204
|
+
body: formData as any,
|
|
8205
|
+
params: {
|
|
8206
|
+
query: ${paramsSchemaName ? "folder ? { folder } : undefined" : "undefined"}
|
|
8207
|
+
}
|
|
8208
|
+
}
|
|
8209
|
+
|
|
8210
|
+
${progressEnabled && useXHR ? `return await uploadViaBackendApi(formData, options?.onProgress)` : `
|
|
8211
|
+
// Use server action for upload and extract data from SafeActionResult
|
|
8212
|
+
const result = await resolveActionResult<z.infer<typeof ${operationName}ResponseSchema>>(
|
|
8213
|
+
${actionName}(actionInput)
|
|
8214
|
+
)
|
|
8215
|
+
return result`}`}
|
|
8132
8216
|
},
|
|
8133
8217
|
|
|
8134
8218
|
onSuccess: (data: z.infer<typeof ${operationName}ResponseSchema>) => {
|
|
@@ -9654,5 +9738,5 @@ exports.VersionChecker = VersionChecker;
|
|
|
9654
9738
|
exports.__name = __name;
|
|
9655
9739
|
exports.checkAndNotifyUpdates = checkAndNotifyUpdates;
|
|
9656
9740
|
exports.createBridgeVersionChecker = createBridgeVersionChecker;
|
|
9657
|
-
//# sourceMappingURL=chunk-
|
|
9658
|
-
//# sourceMappingURL=chunk-
|
|
9741
|
+
//# sourceMappingURL=chunk-KATSH6VN.cjs.map
|
|
9742
|
+
//# sourceMappingURL=chunk-KATSH6VN.cjs.map
|