mulink 1.1.3 → 1.1.5
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-4DCGRNLY.cjs → chunk-KGPDAGXX.cjs} +64 -25
- package/dist/lib/chunk-KGPDAGXX.cjs.map +1 -0
- package/dist/lib/{chunk-6SOQENFC.js → chunk-UMUBEOOK.js} +64 -25
- package/dist/lib/chunk-UMUBEOOK.js.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-4DCGRNLY.cjs.map +0 -1
- package/dist/lib/chunk-6SOQENFC.js.map +0 -1
|
@@ -3233,10 +3233,14 @@ ${this.commentsEnabled ? " // In production, send to your logging service\n //
|
|
|
3233
3233
|
}
|
|
3234
3234
|
return parts.join("\n\n");
|
|
3235
3235
|
}
|
|
3236
|
-
buildCombinedValidationSnippet(operationName, schemaName) {
|
|
3236
|
+
buildCombinedValidationSnippet(operationName, schemaName, isMultiLine = false) {
|
|
3237
3237
|
if (this.validationEnabled) {
|
|
3238
|
+
const schemaCode = isMultiLine ? `z.object({
|
|
3239
|
+
body: ${operationName}RequestSchema,
|
|
3240
|
+
params: ${operationName}ParamsSchema
|
|
3241
|
+
})` : schemaName;
|
|
3238
3242
|
return `
|
|
3239
|
-
${this.commentLine("Validate and sanitize input payload", 6)} const { body, params } = await validateAndSanitizeInput(${
|
|
3243
|
+
${this.commentLine("Validate and sanitize input payload", 6)} const { body, params } = await validateAndSanitizeInput(${schemaCode}, parsedInput)
|
|
3240
3244
|
const validatedBody = body
|
|
3241
3245
|
const validatedParams = params as z.infer<typeof ${operationName}ParamsSchema>`;
|
|
3242
3246
|
}
|
|
@@ -3444,7 +3448,8 @@ ${actions}`;
|
|
|
3444
3448
|
body: ${operationName}RequestSchema,
|
|
3445
3449
|
params: ${operationName}ParamsSchema
|
|
3446
3450
|
})`;
|
|
3447
|
-
|
|
3451
|
+
const isMultiLineSchema = schemaName.includes("\n");
|
|
3452
|
+
parameterProcessing = this.buildCombinedValidationSnippet(operationName, schemaName, isMultiLineSchema);
|
|
3448
3453
|
requestOptionsParams = this.buildRequestOptions(pathParameters, queryParameters, true, true);
|
|
3449
3454
|
} else if (hasRequestBody) {
|
|
3450
3455
|
schemaName = `${operationName}RequestSchema`;
|
|
@@ -3459,10 +3464,7 @@ ${actions}`;
|
|
|
3459
3464
|
parameterProcessing = "";
|
|
3460
3465
|
requestOptionsParams = "";
|
|
3461
3466
|
}
|
|
3462
|
-
const parsedInputType = hasRequestBody || hasAnyParams ? schemaName.includes("\n") ? `z.infer<typeof z.object({
|
|
3463
|
-
body: ${operationName}RequestSchema,
|
|
3464
|
-
params: ${operationName}ParamsSchema
|
|
3465
|
-
})>` : `z.infer<typeof ${schemaName}>` : "void";
|
|
3467
|
+
const parsedInputType = hasRequestBody || hasAnyParams ? schemaName.includes("\n") ? `z.infer<typeof z.object({ body: ${operationName}RequestSchema, params: ${operationName}ParamsSchema })>` : `z.infer<typeof ${schemaName}>` : "void";
|
|
3466
3468
|
const ctxType = requiresAuth || hasRateLimit ? "{ user?: any; ratelimit?: { remaining: number } }" : "any";
|
|
3467
3469
|
const ctxDeclaration = requiresAuth || hasRateLimit ? `ctx: ${ctxType}` : "ctx?: any";
|
|
3468
3470
|
const actionArgsType = `{
|
|
@@ -3927,8 +3929,18 @@ export function ${hookName.replace("use", "useInfinite")}(${parameterTypes.lengt
|
|
|
3927
3929
|
initialPageParam: 1,
|
|
3928
3930
|
queryFn: async ({ pageParam = 1, signal }: { pageParam?: number; signal?: AbortSignal }) => {
|
|
3929
3931
|
try {
|
|
3930
|
-
|
|
3931
|
-
const
|
|
3932
|
+
// Build query params object with only the parameters the endpoint expects
|
|
3933
|
+
const queryParams: Record<string, any> = {}
|
|
3934
|
+
${queryParameters.map((param) => {
|
|
3935
|
+
if (param.name === "page" && hasPageParam) {
|
|
3936
|
+
return `queryParams.${param.name} = pageParam`;
|
|
3937
|
+
} else if (param.name === "limit") {
|
|
3938
|
+
return `queryParams.${param.name} = searchParams.limit`;
|
|
3939
|
+
} else {
|
|
3940
|
+
return `if ('${param.name}' in searchParams) queryParams.${param.name} = searchParams.${param.name}`;
|
|
3941
|
+
}
|
|
3942
|
+
}).join("\n ")}
|
|
3943
|
+
const result = await resolveActionResult<${returnType}>(${actionName}(${actionCallParams.replace(queryParamObject, "{ query: queryParams }")}))
|
|
3932
3944
|
return result
|
|
3933
3945
|
} catch (error) {
|
|
3934
3946
|
handleActionError(error)
|
|
@@ -4386,8 +4398,8 @@ export function useBridgeQuery<TData = unknown, TError = Error>(
|
|
|
4386
4398
|
refetchOnWindowFocus: true,
|
|
4387
4399
|
refetchOnReconnect: true,
|
|
4388
4400
|
refetchOnMount: 'always',
|
|
4389
|
-
placeholderData: (previousData
|
|
4390
|
-
retry: (failureCount: number, error:
|
|
4401
|
+
placeholderData: (previousData) => previousData as TData | undefined,
|
|
4402
|
+
retry: (failureCount: number, error: TError) => {
|
|
4391
4403
|
if (error instanceof Error && error.message.includes('4')) return false
|
|
4392
4404
|
return failureCount < 3
|
|
4393
4405
|
},
|
|
@@ -4413,7 +4425,7 @@ export function useBridgeInfiniteQuery<TData = unknown, TError = Error>(
|
|
|
4413
4425
|
refetchOnWindowFocus: true,
|
|
4414
4426
|
refetchOnReconnect: true,
|
|
4415
4427
|
refetchOnMount: 'always',
|
|
4416
|
-
retry: (failureCount: number, error:
|
|
4428
|
+
retry: (failureCount: number, error: TError) => {
|
|
4417
4429
|
if (error instanceof Error && error.message.includes('4')) return false
|
|
4418
4430
|
return failureCount < 3
|
|
4419
4431
|
},
|
|
@@ -4435,7 +4447,7 @@ export function useBridgeSuspenseQuery<TData = unknown, TError = Error>(
|
|
|
4435
4447
|
queryFn: queryFn as QueryFunction<TData, QueryKey>,
|
|
4436
4448
|
staleTime: 5 * 60 * 1000,
|
|
4437
4449
|
gcTime: 10 * 60 * 1000,
|
|
4438
|
-
retry: (failureCount: number, error:
|
|
4450
|
+
retry: (failureCount: number, error: TError) => {
|
|
4439
4451
|
if (error instanceof Error && error.message.includes('4')) return false
|
|
4440
4452
|
return failureCount < 3
|
|
4441
4453
|
},
|
|
@@ -7617,7 +7629,7 @@ var UploadGenerator = class {
|
|
|
7617
7629
|
};
|
|
7618
7630
|
const presignedEndpoint = presignedEnabled ? this.findPresignedEndpoint(schema.endpoints) || (extractedUploadConfig.presignedEndpoint ? schema.endpoints.find((e) => e.path === extractedUploadConfig.presignedEndpoint) || null : null) : null;
|
|
7619
7631
|
generatedFiles.push(this.generateUploadUtilities(uploadProvider, uploadStrategy, presignedEndpoint));
|
|
7620
|
-
generatedFiles.push(this.generateUseUploadFileHook(uploadProvider, uploadStrategy));
|
|
7632
|
+
generatedFiles.push(this.generateUseUploadFileHook(uploadProvider, uploadStrategy, context));
|
|
7621
7633
|
for (const endpoint of uploadEndpoints) {
|
|
7622
7634
|
generatedFiles.push(this.generateUploadHook(
|
|
7623
7635
|
endpoint,
|
|
@@ -8266,8 +8278,19 @@ export function ${hookName}Upload(options?: {
|
|
|
8266
8278
|
const method = this.toPascalCase(endpoint.method.toLowerCase());
|
|
8267
8279
|
return [...pathParts, method].join("");
|
|
8268
8280
|
}
|
|
8269
|
-
generateUseUploadFileHook(uploadProvider, uploadStrategy) {
|
|
8281
|
+
generateUseUploadFileHook(uploadProvider, uploadStrategy, context) {
|
|
8270
8282
|
const uploadUtilsImport = this.buildImportPath("services/uploadUtils");
|
|
8283
|
+
const uploadEndpoints = context?.schema?.endpoints?.filter(
|
|
8284
|
+
(e) => e.metadata?.fileUpload || e.path.toLowerCase().includes("upload") || e.operationId && e.operationId.toLowerCase().includes("upload")
|
|
8285
|
+
) || [];
|
|
8286
|
+
const firstUploadEndpoint = uploadEndpoints[0];
|
|
8287
|
+
let uploadMethodName = "uploadFile";
|
|
8288
|
+
let uploadClientTag = "files";
|
|
8289
|
+
if (firstUploadEndpoint) {
|
|
8290
|
+
this.getOperationName(firstUploadEndpoint);
|
|
8291
|
+
uploadMethodName = toActionName(firstUploadEndpoint.operationId || firstUploadEndpoint.id);
|
|
8292
|
+
uploadClientTag = toValidIdentifier(firstUploadEndpoint.tags[0] || "files");
|
|
8293
|
+
}
|
|
8271
8294
|
const content = `'use client'
|
|
8272
8295
|
|
|
8273
8296
|
import { useMutation } from '@tanstack/react-query'
|
|
@@ -8313,13 +8336,21 @@ export function useUploadFile(options?: {
|
|
|
8313
8336
|
// Mulink will generate the upload endpoint from your OpenAPI schema
|
|
8314
8337
|
const { apiClient } = await import('${this.buildImportPath("client")}')
|
|
8315
8338
|
|
|
8316
|
-
// Try to find upload endpoint in
|
|
8339
|
+
// Try to find upload endpoint in generated client
|
|
8317
8340
|
try {
|
|
8318
|
-
|
|
8319
|
-
|
|
8341
|
+
${firstUploadEndpoint ? `
|
|
8342
|
+
// Use the detected upload endpoint
|
|
8343
|
+
const response = await apiClient.${uploadClientTag}?.${uploadMethodName}?.({
|
|
8344
|
+
body: formData as any,
|
|
8345
|
+
params: { query: {} }
|
|
8346
|
+
})` : `
|
|
8347
|
+
// Try common upload endpoint names
|
|
8348
|
+
const response = await apiClient.files?.uploadFileApiV1FilesUploadPost?.({
|
|
8349
|
+
body: formData as any,
|
|
8350
|
+
params: { query: {} }
|
|
8320
8351
|
}) || await apiClient.default?.uploadFile?.({
|
|
8321
8352
|
body: formData as any
|
|
8322
|
-
})
|
|
8353
|
+
})`}
|
|
8323
8354
|
return response?.data?.url || response?.data?.file_url || response?.data?.url || ''
|
|
8324
8355
|
} catch (error) {
|
|
8325
8356
|
console.warn('[Mulink] Upload endpoint not found in generated client, using fallback')
|
|
@@ -8332,13 +8363,21 @@ export function useUploadFile(options?: {
|
|
|
8332
8363
|
// Mulink will generate the upload endpoint from your OpenAPI schema
|
|
8333
8364
|
const { apiClient } = await import('${this.buildImportPath("client")}')
|
|
8334
8365
|
|
|
8335
|
-
// Try to find upload endpoint in
|
|
8366
|
+
// Try to find upload endpoint in generated client
|
|
8336
8367
|
try {
|
|
8337
|
-
|
|
8338
|
-
|
|
8368
|
+
${firstUploadEndpoint ? `
|
|
8369
|
+
// Use the detected upload endpoint
|
|
8370
|
+
const response = await apiClient.${uploadClientTag}?.${uploadMethodName}?.({
|
|
8371
|
+
body: formData as any,
|
|
8372
|
+
params: { query: {} }
|
|
8373
|
+
})` : `
|
|
8374
|
+
// Try common upload endpoint names
|
|
8375
|
+
const response = await apiClient.files?.uploadFileApiV1FilesUploadPost?.({
|
|
8376
|
+
body: formData as any,
|
|
8377
|
+
params: { query: {} }
|
|
8339
8378
|
}) || await apiClient.default?.uploadFile?.({
|
|
8340
8379
|
body: formData as any
|
|
8341
|
-
})
|
|
8380
|
+
})`}
|
|
8342
8381
|
return response?.data?.url || response?.data?.file_url || response?.data?.url || ''
|
|
8343
8382
|
} catch (error) {
|
|
8344
8383
|
console.warn('[Mulink] Upload endpoint not found in generated client, using fallback')
|
|
@@ -9739,5 +9778,5 @@ ${errorMessages}`,
|
|
|
9739
9778
|
};
|
|
9740
9779
|
|
|
9741
9780
|
export { BridgeCore, BridgeError, BridgeLogger, ConfigurationLoader, FileSystemManager, GenerationError, LogLevel, NextJsCodeGenerator, OpenApiSchemaParser, SchemaParseError, ValidationError, VersionChecker, __name, checkAndNotifyUpdates, createBridgeVersionChecker };
|
|
9742
|
-
//# sourceMappingURL=chunk-
|
|
9743
|
-
//# sourceMappingURL=chunk-
|
|
9781
|
+
//# sourceMappingURL=chunk-UMUBEOOK.js.map
|
|
9782
|
+
//# sourceMappingURL=chunk-UMUBEOOK.js.map
|