mulink 1.0.3 → 1.0.4
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-RGLCJDOY.cjs → chunk-GKRRC2YD.cjs} +132 -88
- package/dist/lib/chunk-GKRRC2YD.cjs.map +1 -0
- package/dist/lib/{chunk-IVMVPQUK.js → chunk-KCNMWAI2.js} +132 -88
- package/dist/lib/chunk-KCNMWAI2.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-IVMVPQUK.js.map +0 -1
- package/dist/lib/chunk-RGLCJDOY.cjs.map +0 -1
|
@@ -1032,8 +1032,8 @@ import { cache } from 'react'
|
|
|
1032
1032
|
* We use dynamic imports to avoid bundling them in the client
|
|
1033
1033
|
*/
|
|
1034
1034
|
let serverOnlyModules: {
|
|
1035
|
-
cookies?: () => import('next/headers').
|
|
1036
|
-
headers?: () => import('next/headers').
|
|
1035
|
+
cookies?: () => Awaited<ReturnType<typeof import('next/headers').cookies>>
|
|
1036
|
+
headers?: () => Awaited<ReturnType<typeof import('next/headers').headers>>
|
|
1037
1037
|
after?: (fn: () => void | Promise<void>) => void
|
|
1038
1038
|
updateTag?: (tag: string) => void
|
|
1039
1039
|
} | null = null
|
|
@@ -1336,12 +1336,14 @@ export class BaseApiClient {
|
|
|
1336
1336
|
|
|
1337
1337
|
// Try external auth service
|
|
1338
1338
|
${this.configuration.auth?.enabled ? `try {
|
|
1339
|
-
const
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1339
|
+
const authModule = await import('${authPath}').catch(() => null)
|
|
1340
|
+
if (authModule && authModule.${tokenGetter}) {
|
|
1341
|
+
const session = await authModule.${tokenGetter}()
|
|
1342
|
+
|
|
1343
|
+
if (session?.accessToken) {
|
|
1344
|
+
getAuthHeaders.Authorization = \`Bearer \${session.accessToken}\`
|
|
1345
|
+
return getAuthHeaders
|
|
1346
|
+
}
|
|
1345
1347
|
}
|
|
1346
1348
|
} catch (error) {
|
|
1347
1349
|
// Auth not available or error accessing
|
|
@@ -1540,7 +1542,9 @@ export class BaseApiClient {
|
|
|
1540
1542
|
const requestPromise = this.executeRequestInternal<TData>(
|
|
1541
1543
|
method, url, body, headers, fetchOptions, timeout, retries,
|
|
1542
1544
|
retryDelay, retryCondition, validateResponse, skipAuth,
|
|
1543
|
-
responseSchema, requestId, [...this.middleware, ...middleware]
|
|
1545
|
+
responseSchema, requestId, [...this.middleware, ...middleware],
|
|
1546
|
+
cacheTags, revalidate, connection, updateTag
|
|
1547
|
+
cacheTags, revalidate, connection, updateTag
|
|
1544
1548
|
)
|
|
1545
1549
|
|
|
1546
1550
|
requestCache.set(dedupeKey, requestPromise)
|
|
@@ -1556,7 +1560,9 @@ export class BaseApiClient {
|
|
|
1556
1560
|
return this.executeRequestInternal<TData>(
|
|
1557
1561
|
method, url, body, headers, fetchOptions, timeout, retries,
|
|
1558
1562
|
retryDelay, retryCondition, validateResponse, skipAuth,
|
|
1559
|
-
responseSchema, requestId, [...this.middleware, ...middleware]
|
|
1563
|
+
responseSchema, requestId, [...this.middleware, ...middleware],
|
|
1564
|
+
cacheTags, revalidate, connection, updateTag
|
|
1565
|
+
cacheTags, revalidate, connection, updateTag
|
|
1560
1566
|
)
|
|
1561
1567
|
}
|
|
1562
1568
|
|
|
@@ -1575,7 +1581,11 @@ export class BaseApiClient {
|
|
|
1575
1581
|
skipAuth: boolean,
|
|
1576
1582
|
responseSchema?: z.ZodSchema<TData>,
|
|
1577
1583
|
requestId?: string,
|
|
1578
|
-
middleware: RequestMiddleware[] = []
|
|
1584
|
+
middleware: RequestMiddleware[] = [],
|
|
1585
|
+
cacheTags: string[] = [],
|
|
1586
|
+
revalidate?: number | false,
|
|
1587
|
+
connection?: 'keep-alive' | 'close',
|
|
1588
|
+
updateTag?: (tag: string) => void
|
|
1579
1589
|
): Promise<ClientResponse<TData>> {
|
|
1580
1590
|
const startTime = Date.now()
|
|
1581
1591
|
|
|
@@ -1662,7 +1672,7 @@ export class BaseApiClient {
|
|
|
1662
1672
|
|
|
1663
1673
|
if (tagUpdater && typeof window === 'undefined') {
|
|
1664
1674
|
// Update cache tags on server-side only
|
|
1665
|
-
cacheTags.forEach(tag => {
|
|
1675
|
+
cacheTags.forEach((tag: string) => {
|
|
1666
1676
|
try {
|
|
1667
1677
|
tagUpdater(tag)
|
|
1668
1678
|
} catch (error) {
|
|
@@ -2549,13 +2559,23 @@ var SchemaGenerator = class {
|
|
|
2549
2559
|
const result = [];
|
|
2550
2560
|
const schemaMap = /* @__PURE__ */ new Map();
|
|
2551
2561
|
const dependencyGraph = /* @__PURE__ */ new Map();
|
|
2562
|
+
const enumSchemas = [];
|
|
2563
|
+
const otherSchemas = [];
|
|
2552
2564
|
for (const schema of schemas) {
|
|
2565
|
+
const isEnum = this.isEnumSchema(schema);
|
|
2566
|
+
if (isEnum) {
|
|
2567
|
+
enumSchemas.push(schema);
|
|
2568
|
+
} else {
|
|
2569
|
+
otherSchemas.push(schema);
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
for (const schema of [...enumSchemas, ...otherSchemas]) {
|
|
2553
2573
|
if (!schemaMap.has(schema.name)) {
|
|
2554
2574
|
schemaMap.set(schema.name, schema);
|
|
2555
2575
|
dependencyGraph.set(schema.name, /* @__PURE__ */ new Set());
|
|
2556
2576
|
}
|
|
2557
2577
|
}
|
|
2558
|
-
for (const schema of
|
|
2578
|
+
for (const schema of [...enumSchemas, ...otherSchemas]) {
|
|
2559
2579
|
const dependencies = this.findSchemaDependencies(schema);
|
|
2560
2580
|
for (const dep of dependencies) {
|
|
2561
2581
|
if (schemaMap.has(dep)) {
|
|
@@ -2585,13 +2605,25 @@ var SchemaGenerator = class {
|
|
|
2585
2605
|
visiting.delete(schemaName);
|
|
2586
2606
|
visited.add(schemaName);
|
|
2587
2607
|
}, "visit");
|
|
2588
|
-
for (const schema of
|
|
2608
|
+
for (const schema of enumSchemas) {
|
|
2609
|
+
if (!visited.has(schema.name)) {
|
|
2610
|
+
visit(schema.name);
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
for (const schema of otherSchemas) {
|
|
2589
2614
|
if (!visited.has(schema.name)) {
|
|
2590
2615
|
visit(schema.name);
|
|
2591
2616
|
}
|
|
2592
2617
|
}
|
|
2593
2618
|
return result;
|
|
2594
2619
|
}
|
|
2620
|
+
isEnumSchema(schema) {
|
|
2621
|
+
if (!schema.schema || !schema.schema._def) {
|
|
2622
|
+
return false;
|
|
2623
|
+
}
|
|
2624
|
+
const def = schema.schema._def;
|
|
2625
|
+
return def.typeName === "ZodEnum";
|
|
2626
|
+
}
|
|
2595
2627
|
findSchemaDependencies(schema) {
|
|
2596
2628
|
const dependencies = [];
|
|
2597
2629
|
const schemaObj = schema.schema;
|
|
@@ -2673,7 +2705,7 @@ var SchemaGenerator = class {
|
|
|
2673
2705
|
schemaExports.push(...endpointSchemas.exports);
|
|
2674
2706
|
}
|
|
2675
2707
|
const validationHelpers = this.generateValidationHelpers();
|
|
2676
|
-
const
|
|
2708
|
+
const contentWithImports = [
|
|
2677
2709
|
...imports,
|
|
2678
2710
|
"",
|
|
2679
2711
|
"// Generated schemas from OpenAPI specification",
|
|
@@ -2683,7 +2715,11 @@ var SchemaGenerator = class {
|
|
|
2683
2715
|
"",
|
|
2684
2716
|
validationHelpers,
|
|
2685
2717
|
""
|
|
2686
|
-
].join("\n")
|
|
2718
|
+
].join("\n");
|
|
2719
|
+
let content = this.removeUnusedCode(contentWithImports);
|
|
2720
|
+
if (!content.includes('import { z } from "zod"') && !content.includes("import { z } from 'zod'")) {
|
|
2721
|
+
content = 'import { z } from "zod"\n\n' + content;
|
|
2722
|
+
}
|
|
2687
2723
|
return {
|
|
2688
2724
|
path: "schemas/index.ts",
|
|
2689
2725
|
content,
|
|
@@ -3032,7 +3068,11 @@ export const errorMessages = {
|
|
|
3032
3068
|
const lines = content.split("\n");
|
|
3033
3069
|
const cleanedLines = [];
|
|
3034
3070
|
const usedIdentifiers = /* @__PURE__ */ new Set();
|
|
3071
|
+
usedIdentifiers.add("z");
|
|
3035
3072
|
for (const line of lines) {
|
|
3073
|
+
if (line.includes("z.")) {
|
|
3074
|
+
usedIdentifiers.add("z");
|
|
3075
|
+
}
|
|
3036
3076
|
const assignments = line.match(/(\w+)\s*[:=]/g);
|
|
3037
3077
|
if (assignments) {
|
|
3038
3078
|
assignments.forEach((match) => {
|
|
@@ -3047,6 +3087,9 @@ export const errorMessages = {
|
|
|
3047
3087
|
usedIdentifiers.add(identifier);
|
|
3048
3088
|
});
|
|
3049
3089
|
}
|
|
3090
|
+
if (line.includes("z.infer")) {
|
|
3091
|
+
usedIdentifiers.add("z");
|
|
3092
|
+
}
|
|
3050
3093
|
}
|
|
3051
3094
|
for (const line of lines) {
|
|
3052
3095
|
if (line.trim() === "" || line.trim().startsWith("//")) {
|
|
@@ -3054,6 +3097,10 @@ export const errorMessages = {
|
|
|
3054
3097
|
continue;
|
|
3055
3098
|
}
|
|
3056
3099
|
if (line.includes("import") && line.includes("from")) {
|
|
3100
|
+
if (line.includes('from "zod"') || line.includes("from 'zod'")) {
|
|
3101
|
+
cleanedLines.push(line);
|
|
3102
|
+
continue;
|
|
3103
|
+
}
|
|
3057
3104
|
const importMatch = line.match(/import\s*\{([^}]+)\}/);
|
|
3058
3105
|
if (importMatch) {
|
|
3059
3106
|
const imports = importMatch[1].split(",").map((imp) => imp.trim());
|
|
@@ -3134,7 +3181,7 @@ var ActionGenerator = class {
|
|
|
3134
3181
|
...hasStreaming ? ["import { after } from 'next/server'"] : [],
|
|
3135
3182
|
"import { headers } from 'next/headers'",
|
|
3136
3183
|
`import { apiClient } from '${clientImport}'`,
|
|
3137
|
-
`import { ${usesAuth || hasRateLimit ? "authActionClient" : "
|
|
3184
|
+
`import { actionClientWithMeta${usesAuth || hasRateLimit ? ", authActionClient" : ""}, ActionError } from '${safeActionImport}'`,
|
|
3138
3185
|
...schemaImportsString ? [`import {
|
|
3139
3186
|
${schemaImportsString}
|
|
3140
3187
|
} from '${schemasImport}'`] : [],
|
|
@@ -3281,7 +3328,7 @@ ${Object.keys(endpointsByTag).map((tag) => `export * from './${toValidIdentifier
|
|
|
3281
3328
|
// Validate and sanitize input
|
|
3282
3329
|
const { body, params } = await validateAndSanitizeInput(${schemaName}, parsedInput)
|
|
3283
3330
|
const validatedBody = body
|
|
3284
|
-
const validatedParams = params as
|
|
3331
|
+
const validatedParams = params as z.infer<typeof ${operationName}ParamsSchema>`;
|
|
3285
3332
|
requestOptionsParams = this.buildRequestOptions(pathParameters, queryParameters, true, true);
|
|
3286
3333
|
} else if (hasRequestBody) {
|
|
3287
3334
|
schemaName = `${operationName}RequestSchema`;
|
|
@@ -3293,7 +3340,7 @@ ${Object.keys(endpointsByTag).map((tag) => `export * from './${toValidIdentifier
|
|
|
3293
3340
|
schemaName = `${operationName}ParamsSchema`;
|
|
3294
3341
|
parameterProcessing = `
|
|
3295
3342
|
// Validate and sanitize parameters
|
|
3296
|
-
const validatedParams = await validateAndSanitizeInput(${schemaName}, parsedInput) as
|
|
3343
|
+
const validatedParams = await validateAndSanitizeInput(${schemaName}, parsedInput) as z.infer<typeof ${operationName}ParamsSchema>`;
|
|
3297
3344
|
requestOptionsParams = this.buildRequestOptions(pathParameters, queryParameters, false, true);
|
|
3298
3345
|
} else {
|
|
3299
3346
|
schemaName = "z.void()";
|
|
@@ -3332,7 +3379,7 @@ export const ${actionName} = cache(
|
|
|
3332
3379
|
rateLimit: { requests: ${endpoint.metadata.rateLimit?.requests || 10}, window: "${endpoint.metadata.rateLimit?.window || "1m"}" }` : ""}
|
|
3333
3380
|
})
|
|
3334
3381
|
.schema(${schemaName})
|
|
3335
|
-
.action(async ({ parsedInput, ctx }) => {
|
|
3382
|
+
.action(async ({ parsedInput, ctx }: { parsedInput: ${hasRequestBody || hasAnyParams ? `z.infer<typeof ${schemaName}>` : "void"}, ctx${requiresAuth || hasRateLimit ? ": { user?: any, ratelimit?: { remaining: number } }" : "?: any"}) => {
|
|
3336
3383
|
const startTime = Date.now()
|
|
3337
3384
|
|
|
3338
3385
|
try {${rateLimitCode}${parameterProcessing}
|
|
@@ -3423,7 +3470,7 @@ export const ${actionName} = ${clientName}
|
|
|
3423
3470
|
rateLimit: { requests: ${endpoint.metadata.rateLimit?.requests || 10}, window: "${endpoint.metadata.rateLimit?.window || "1m"}" }` : ""}
|
|
3424
3471
|
})
|
|
3425
3472
|
.schema(${schemaName})
|
|
3426
|
-
.action(async ({ parsedInput, ctx }) => {
|
|
3473
|
+
.action(async ({ parsedInput, ctx }: { parsedInput: ${hasRequestBody || hasAnyParams ? `z.infer<typeof ${schemaName}>` : "void"}, ctx${requiresAuth || hasRateLimit ? ": { user?: any, ratelimit?: { remaining: number } }" : "?: any"}) => {
|
|
3427
3474
|
const startTime = Date.now()
|
|
3428
3475
|
|
|
3429
3476
|
try {${rateLimitCode}${parameterProcessing}${fileUploadCode}
|
|
@@ -3757,14 +3804,14 @@ export function ${hookName}(${parameterTypes.length > 0 ? `${parameterTypes.join
|
|
|
3757
3804
|
refetchInterval: options?.refetchInterval, // Optional polling interval
|
|
3758
3805
|
initialDataUpdatedAt: initialData ? Date.now() : undefined,
|
|
3759
3806
|
// React Query v5: placeholderData replaces keepPreviousData
|
|
3760
|
-
placeholderData: (previousData) => previousData,
|
|
3761
|
-
retry: (failureCount, error) => {
|
|
3807
|
+
placeholderData: (previousData: ${returnType} | undefined) => previousData,
|
|
3808
|
+
retry: (failureCount: number, error: Error) => {
|
|
3762
3809
|
// Don't retry on 4xx errors (client errors)
|
|
3763
3810
|
if (error instanceof Error && error.message.includes('4')) return false
|
|
3764
3811
|
// Retry up to 3 times for network/server errors
|
|
3765
3812
|
return failureCount < 3
|
|
3766
3813
|
},
|
|
3767
|
-
initialData: initialData as
|
|
3814
|
+
initialData: initialData as ${returnType} | undefined,
|
|
3768
3815
|
...restOptions
|
|
3769
3816
|
})
|
|
3770
3817
|
}
|
|
@@ -3787,7 +3834,7 @@ export function ${hookName.replace("use", "useInfinite")}(${parameterTypes.lengt
|
|
|
3787
3834
|
handleActionError(error)
|
|
3788
3835
|
}
|
|
3789
3836
|
}, [searchParams]),
|
|
3790
|
-
getNextPageParam: (lastPage:
|
|
3837
|
+
getNextPageParam: (lastPage: ${returnType}, allPages: ${returnType}[]) => {
|
|
3791
3838
|
if (lastPage?.hasMore || (Array.isArray(lastPage) && lastPage.length === searchParams.limit)) {
|
|
3792
3839
|
return allPages.length + 1
|
|
3793
3840
|
}
|
|
@@ -3800,9 +3847,9 @@ export function ${hookName.replace("use", "useInfinite")}(${parameterTypes.lengt
|
|
|
3800
3847
|
refetchOnReconnect: true,
|
|
3801
3848
|
refetchOnMount: 'always',
|
|
3802
3849
|
initialDataUpdatedAt: initialData ? Date.now() : undefined,
|
|
3803
|
-
placeholderData: (previousData) => previousData,
|
|
3850
|
+
placeholderData: (previousData: ${returnType} | undefined) => previousData,
|
|
3804
3851
|
retry: 3,
|
|
3805
|
-
initialData: initialData as
|
|
3852
|
+
initialData: initialData as ${returnType} | undefined,
|
|
3806
3853
|
...restOptions
|
|
3807
3854
|
})
|
|
3808
3855
|
}
|
|
@@ -3821,7 +3868,7 @@ export function ${hookName.replace("use", "useSuspense")}(${parameterTypes.lengt
|
|
|
3821
3868
|
return result
|
|
3822
3869
|
}, []),
|
|
3823
3870
|
staleTime: ${staleTime},
|
|
3824
|
-
initialData: initialData as
|
|
3871
|
+
initialData: initialData as ${returnType} | undefined,
|
|
3825
3872
|
...restOptions
|
|
3826
3873
|
})
|
|
3827
3874
|
}`;
|
|
@@ -3853,14 +3900,14 @@ export function ${hookName}(${parameterTypes.length > 0 ? `${parameterTypes.join
|
|
|
3853
3900
|
refetchInterval: options?.refetchInterval, // Optional polling interval
|
|
3854
3901
|
initialDataUpdatedAt: initialData ? Date.now() : undefined,
|
|
3855
3902
|
// React Query v5: placeholderData replaces keepPreviousData
|
|
3856
|
-
placeholderData: (previousData) => previousData,
|
|
3857
|
-
retry: (failureCount, error) => {
|
|
3903
|
+
placeholderData: (previousData: ${returnType} | undefined) => previousData,
|
|
3904
|
+
retry: (failureCount: number, error: Error) => {
|
|
3858
3905
|
// Don't retry on 4xx errors (client errors)
|
|
3859
3906
|
if (error instanceof Error && error.message.includes('4')) return false
|
|
3860
3907
|
// Retry up to 3 times for network/server errors
|
|
3861
3908
|
return failureCount < 3
|
|
3862
3909
|
},
|
|
3863
|
-
initialData: initialData as
|
|
3910
|
+
initialData: initialData as ${returnType} | undefined,
|
|
3864
3911
|
...restOptions
|
|
3865
3912
|
})
|
|
3866
3913
|
}
|
|
@@ -3879,7 +3926,7 @@ export function ${hookName.replace("use", "useSuspense")}(${parameterTypes.lengt
|
|
|
3879
3926
|
return result
|
|
3880
3927
|
}, []),
|
|
3881
3928
|
staleTime: ${staleTime},
|
|
3882
|
-
initialData: initialData as
|
|
3929
|
+
initialData: initialData as ${returnType} | undefined,
|
|
3883
3930
|
...restOptions
|
|
3884
3931
|
})
|
|
3885
3932
|
}`;
|
|
@@ -3932,13 +3979,13 @@ export function ${hookName}(options?: {
|
|
|
3932
3979
|
mutationFn: async (variables: ${inputType}): Promise<${outputType}> => {
|
|
3933
3980
|
try {
|
|
3934
3981
|
const result = await ${actionName}(${variablesParam === "undefined" ? "" : "variables"})
|
|
3935
|
-
return result.data || ({} as
|
|
3982
|
+
return result.data || ({} as ${outputType})
|
|
3936
3983
|
} catch (error) {
|
|
3937
3984
|
handleActionError(error)
|
|
3938
3985
|
}
|
|
3939
3986
|
},
|
|
3940
3987
|
|
|
3941
|
-
onMutate: async (variables) => {
|
|
3988
|
+
onMutate: async (variables: ${inputType}) => {
|
|
3942
3989
|
${cancelQueriesCode}
|
|
3943
3990
|
|
|
3944
3991
|
${snapshotCode}
|
|
@@ -3949,7 +3996,7 @@ ${snapshotCode}
|
|
|
3949
3996
|
setOptimisticData(optimisticValue)
|
|
3950
3997
|
}
|
|
3951
3998
|
|
|
3952
|
-
return {
|
|
3999
|
+
return { /* Snapshot handled via query invalidation */ }
|
|
3953
4000
|
},
|
|
3954
4001
|
|
|
3955
4002
|
onSuccess: (data, variables) => {
|
|
@@ -3965,7 +4012,7 @@ ${invalidationCode}
|
|
|
3965
4012
|
options?.onSuccess?.(data, variables)
|
|
3966
4013
|
},
|
|
3967
4014
|
|
|
3968
|
-
onError: (error, variables, context) => {
|
|
4015
|
+
onError: (error: Error, variables: ${inputType}, context: any) => {
|
|
3969
4016
|
// Rollback optimistic update
|
|
3970
4017
|
${rollbackCode}
|
|
3971
4018
|
|
|
@@ -4049,29 +4096,26 @@ ${invalidationCode}
|
|
|
4049
4096
|
}
|
|
4050
4097
|
/**
|
|
4051
4098
|
* Build cancel queries code
|
|
4099
|
+
* Uses query key patterns to cancel all related queries regardless of parameters
|
|
4052
4100
|
*/
|
|
4053
4101
|
buildCancelQueriesCode(endpoint, relatedQueries) {
|
|
4054
4102
|
const cancels = [];
|
|
4055
4103
|
relatedQueries.forEach((queryEndpoint) => {
|
|
4056
|
-
const
|
|
4057
|
-
cancels.push(` await queryClient.cancelQueries({ queryKey: ${
|
|
4104
|
+
const queryKeyPrefix = `'${toActionName(queryEndpoint.operationId || queryEndpoint.id)}'`;
|
|
4105
|
+
cancels.push(` await queryClient.cancelQueries({ queryKey: [${queryKeyPrefix}] })`);
|
|
4058
4106
|
});
|
|
4059
4107
|
return cancels.length > 0 ? cancels.join("\n") : " // No queries to cancel";
|
|
4060
4108
|
}
|
|
4061
4109
|
/**
|
|
4062
4110
|
* Build snapshot code for rollback
|
|
4111
|
+
* Note: We can't snapshot specific queries with parameters in onMutate scope
|
|
4112
|
+
* Instead, we'll invalidate all related queries on error
|
|
4063
4113
|
*/
|
|
4064
4114
|
buildSnapshotCode(endpoint, relatedQueries) {
|
|
4065
4115
|
if (relatedQueries.length === 0) {
|
|
4066
4116
|
return " // No queries to snapshot";
|
|
4067
4117
|
}
|
|
4068
|
-
|
|
4069
|
-
relatedQueries.forEach((queryEndpoint, index) => {
|
|
4070
|
-
const queryKey = this.generateQueryKey(queryEndpoint);
|
|
4071
|
-
const varName = `previous${this.toPascalCase(toActionName(queryEndpoint.operationId || queryEndpoint.id))}`;
|
|
4072
|
-
snapshots.push(` const ${varName} = queryClient.getQueryData(${queryKey})`);
|
|
4073
|
-
});
|
|
4074
|
-
return snapshots.join("\n");
|
|
4118
|
+
return " // Snapshot handled via query invalidation";
|
|
4075
4119
|
}
|
|
4076
4120
|
/**
|
|
4077
4121
|
* Build rollback code
|
|
@@ -4258,8 +4302,8 @@ export function useBridgeQuery<TData = unknown, TError = Error>(
|
|
|
4258
4302
|
refetchOnWindowFocus: true,
|
|
4259
4303
|
refetchOnReconnect: true,
|
|
4260
4304
|
refetchOnMount: 'always',
|
|
4261
|
-
placeholderData: (previousData) => previousData,
|
|
4262
|
-
retry: (failureCount, error) => {
|
|
4305
|
+
placeholderData: (previousData: TData | undefined) => previousData,
|
|
4306
|
+
retry: (failureCount: number, error: Error) => {
|
|
4263
4307
|
if (error instanceof Error && error.message.includes('4')) return false
|
|
4264
4308
|
return failureCount < 3
|
|
4265
4309
|
},
|
|
@@ -4284,13 +4328,13 @@ export function useBridgeInfiniteQuery<TData = unknown, TError = Error>(
|
|
|
4284
4328
|
refetchOnWindowFocus: true,
|
|
4285
4329
|
refetchOnReconnect: true,
|
|
4286
4330
|
refetchOnMount: 'always',
|
|
4287
|
-
placeholderData: (previousData) => previousData,
|
|
4288
|
-
retry: (failureCount, error) => {
|
|
4331
|
+
placeholderData: (previousData: TData | undefined) => previousData,
|
|
4332
|
+
retry: (failureCount: number, error: Error) => {
|
|
4289
4333
|
if (error instanceof Error && error.message.includes('4')) return false
|
|
4290
4334
|
return failureCount < 3
|
|
4291
4335
|
},
|
|
4292
4336
|
...options,
|
|
4293
|
-
}
|
|
4337
|
+
})
|
|
4294
4338
|
}
|
|
4295
4339
|
|
|
4296
4340
|
/**
|
|
@@ -4307,7 +4351,7 @@ export function useBridgeSuspenseQuery<TData = unknown, TError = Error>(
|
|
|
4307
4351
|
queryFn: queryFn as QueryFunction<TData, QueryKey>,
|
|
4308
4352
|
staleTime: 5 * 60 * 1000,
|
|
4309
4353
|
gcTime: 10 * 60 * 1000,
|
|
4310
|
-
retry: (failureCount, error) => {
|
|
4354
|
+
retry: (failureCount: number, error: Error) => {
|
|
4311
4355
|
if (error instanceof Error && error.message.includes('4')) return false
|
|
4312
4356
|
return failureCount < 3
|
|
4313
4357
|
},
|
|
@@ -7522,9 +7566,6 @@ var UploadGenerator = class {
|
|
|
7522
7566
|
const compressionFormats = uploads?.compression?.formats || ["gzip", "webp"];
|
|
7523
7567
|
const content = `'use client'
|
|
7524
7568
|
|
|
7525
|
-
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
7526
|
-
import { toast } from 'sonner'
|
|
7527
|
-
|
|
7528
7569
|
/**
|
|
7529
7570
|
* Upload configuration
|
|
7530
7571
|
*/
|
|
@@ -7704,7 +7745,7 @@ export function createUploadFormData(
|
|
|
7704
7745
|
"FileValidationResult",
|
|
7705
7746
|
"UploadProgress"
|
|
7706
7747
|
],
|
|
7707
|
-
imports: [
|
|
7748
|
+
imports: [],
|
|
7708
7749
|
dependencies: []
|
|
7709
7750
|
}
|
|
7710
7751
|
};
|
|
@@ -7810,16 +7851,18 @@ async function uploadToS3(
|
|
|
7810
7851
|
xhr.send(formData)
|
|
7811
7852
|
})
|
|
7812
7853
|
}
|
|
7813
|
-
|
|
7854
|
+
` : "";
|
|
7855
|
+
const needsBackendHelper = progressEnabled && useXHR || presignedEnabled && fallbackEnabled;
|
|
7856
|
+
const backendUploadHelper = needsBackendHelper ? `
|
|
7814
7857
|
/**
|
|
7815
7858
|
* Upload via backend API with progress tracking
|
|
7816
|
-
* Uses
|
|
7859
|
+
* Uses XMLHttpRequest for progress tracking support
|
|
7817
7860
|
*/
|
|
7818
7861
|
async function uploadViaBackendApi(
|
|
7819
7862
|
formData: FormData,
|
|
7820
7863
|
onProgress?: (progress: { loaded: number; total: number; percentage: number }) => void
|
|
7821
7864
|
): Promise<z.infer<typeof ${operationName}ResponseSchema>> {
|
|
7822
|
-
|
|
7865
|
+
return new Promise((resolve, reject) => {
|
|
7823
7866
|
const xhr = new XMLHttpRequest()
|
|
7824
7867
|
|
|
7825
7868
|
if (onProgress) {
|
|
@@ -7868,13 +7911,9 @@ async function uploadViaBackendApi(
|
|
|
7868
7911
|
: '${this.configuration.api?.baseUrl || "http://localhost:8000"}'
|
|
7869
7912
|
xhr.open('POST', \`\${baseUrl}${endpoint.path}\`)
|
|
7870
7913
|
xhr.send(formData)
|
|
7871
|
-
})
|
|
7872
|
-
|
|
7873
|
-
|
|
7874
|
-
const response = await ${actionName}(formData as any)
|
|
7875
|
-
return response
|
|
7876
|
-
`}
|
|
7877
|
-
}` : "";
|
|
7914
|
+
})
|
|
7915
|
+
}
|
|
7916
|
+
` : "";
|
|
7878
7917
|
const uploadLogic = presignedEnabled ? `
|
|
7879
7918
|
let fileKey: string | null = null
|
|
7880
7919
|
let directUploadAttempted = false
|
|
@@ -7989,6 +8028,7 @@ async function uploadViaBackendApi(
|
|
|
7989
8028
|
`;
|
|
7990
8029
|
const content = `${imports}
|
|
7991
8030
|
${presignedHelpers}
|
|
8031
|
+
${backendUploadHelper || ""}
|
|
7992
8032
|
|
|
7993
8033
|
/**
|
|
7994
8034
|
* Upload hook for ${endpoint.method} ${endpoint.path}
|
|
@@ -8025,7 +8065,7 @@ export function ${hookName}Upload(options?: {
|
|
|
8025
8065
|
${uploadLogic}
|
|
8026
8066
|
},
|
|
8027
8067
|
|
|
8028
|
-
onSuccess: (data) => {
|
|
8068
|
+
onSuccess: (data: z.infer<typeof ${operationName}ResponseSchema>) => {
|
|
8029
8069
|
// Don't show toast here, let the page handle it
|
|
8030
8070
|
options?.onSuccess?.(data)
|
|
8031
8071
|
|
|
@@ -8239,7 +8279,9 @@ let toast: {
|
|
|
8239
8279
|
} | null = null
|
|
8240
8280
|
|
|
8241
8281
|
// Lazy load toast to avoid bundling issues
|
|
8242
|
-
async function getToast() {
|
|
8282
|
+
async function getToast(): Promise<{
|
|
8283
|
+
error: (message: string, options?: { duration?: number; description?: string }) => void
|
|
8284
|
+
} | null> {
|
|
8243
8285
|
if (toast !== null) return toast
|
|
8244
8286
|
|
|
8245
8287
|
try {
|
|
@@ -8333,24 +8375,26 @@ export async function handleAuthError(error: unknown, redirectTo?: string): Prom
|
|
|
8333
8375
|
const toastInstance = await getToast()
|
|
8334
8376
|
|
|
8335
8377
|
// Show appropriate error message based on error type
|
|
8336
|
-
if (
|
|
8337
|
-
|
|
8338
|
-
|
|
8339
|
-
|
|
8340
|
-
|
|
8341
|
-
|
|
8342
|
-
|
|
8343
|
-
|
|
8344
|
-
|
|
8345
|
-
|
|
8346
|
-
|
|
8347
|
-
|
|
8348
|
-
|
|
8349
|
-
|
|
8350
|
-
|
|
8351
|
-
|
|
8352
|
-
|
|
8353
|
-
|
|
8378
|
+
if (toastInstance) {
|
|
8379
|
+
if (isInactive) {
|
|
8380
|
+
toastInstance.error('Your account has been deactivated. Please contact support for assistance.', {
|
|
8381
|
+
duration: 5000,
|
|
8382
|
+
description: 'You will be redirected to the login page.',
|
|
8383
|
+
})
|
|
8384
|
+
} else if (apiError.status === 401) {
|
|
8385
|
+
toastInstance.error('Your session has expired. Please sign in again.', {
|
|
8386
|
+
duration: 4000,
|
|
8387
|
+
})
|
|
8388
|
+
} else if (apiError.status === 403) {
|
|
8389
|
+
toastInstance.error('Access denied. Your account may have been suspended.', {
|
|
8390
|
+
duration: 5000,
|
|
8391
|
+
description: 'You will be redirected to the login page.',
|
|
8392
|
+
})
|
|
8393
|
+
} else {
|
|
8394
|
+
toastInstance.error('Authentication failed. Please sign in again.', {
|
|
8395
|
+
duration: 4000,
|
|
8396
|
+
})
|
|
8397
|
+
}
|
|
8354
8398
|
}
|
|
8355
8399
|
|
|
8356
8400
|
if (typeof window !== 'undefined') {
|
|
@@ -8361,7 +8405,7 @@ export async function handleAuthError(error: unknown, redirectTo?: string): Prom
|
|
|
8361
8405
|
const { signOut } = await import('${authPath}')
|
|
8362
8406
|
signOut({
|
|
8363
8407
|
redirect: false,
|
|
8364
|
-
}).catch((signOutError) => {
|
|
8408
|
+
}).catch((signOutError: unknown) => {
|
|
8365
8409
|
console.error('[Auth Error Handler] Error during sign out (non-blocking):', signOutError)
|
|
8366
8410
|
})
|
|
8367
8411
|
} catch (importError) {
|
|
@@ -9526,5 +9570,5 @@ ${errorMessages}`,
|
|
|
9526
9570
|
};
|
|
9527
9571
|
|
|
9528
9572
|
export { BridgeCore, BridgeError, BridgeLogger, ConfigurationLoader, FileSystemManager, GenerationError, LogLevel, NextJsCodeGenerator, OpenApiSchemaParser, SchemaParseError, ValidationError, VersionChecker, __name, checkAndNotifyUpdates, createBridgeVersionChecker };
|
|
9529
|
-
//# sourceMappingURL=chunk-
|
|
9530
|
-
//# sourceMappingURL=chunk-
|
|
9573
|
+
//# sourceMappingURL=chunk-KCNMWAI2.js.map
|
|
9574
|
+
//# sourceMappingURL=chunk-KCNMWAI2.js.map
|