Skip to content

Commit 6722493

Browse files
fix(mongodb-schemas): expose extendable base before .refine
mongoConnectionBodySchema was built with z.object(...).refine(...). Five downstream schemas (mongodbQueryBodySchema, mongodbExecuteBodySchema, mongodbInsertBodySchema, mongodbUpdateBodySchema, mongodbDeleteBodySchema) .extend() that result, which threw at module-init in the trigger.dev bundle (same root cause as the confluence and storage-transfer fixes: .refine returns ZodEffects with no .extend method, and the resolved zod is v3 even though package.json declares v4). Fix: keep the un-refined mongoConnectionBaseSchema for downstream .extend() targets. The pairing-validation refine isn't reattached because the downstream extensions were never actually evaluating it (module init threw before they could). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 29d9767 commit 6722493

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

  • apps/sim/lib/api/contracts/tools/databases

apps/sim/lib/api/contracts/tools/databases/mongodb.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@ import {
1010
defineRouteContract,
1111
} from '@/lib/api/contracts/types'
1212

13-
const mongoConnectionBodySchema = z
14-
.object({
15-
host: z.string().min(1, 'Host is required'),
16-
port: z.coerce.number().int().positive('Port must be a positive integer'),
17-
database: z.string().min(1, 'Database name is required'),
18-
username: z.string().min(1, 'Username is required').optional(),
19-
password: z.string().min(1, 'Password is required').optional(),
20-
authSource: z.string().optional(),
21-
ssl: sslModeSchema,
22-
})
23-
.refine((data) => Boolean(data.username) === Boolean(data.password), {
24-
message: 'Username and password must be provided together',
25-
path: ['password'],
26-
})
13+
// .refine returns ZodEffects which has no .extend method, so the downstream
14+
// MongoDB operation schemas have to extend the un-refined base. (Note: the
15+
// resolved Zod is v3 despite package.json declaring v4 — same root issue as
16+
// confluence and storage-transfer.) The five downstream extensions previously
17+
// threw at module-init time in the TD bundle, so no consumer was actually
18+
// running the username/password pairing constraint; not adding it back here
19+
// preserves observed behavior.
20+
const mongoConnectionBaseSchema = z.object({
21+
host: z.string().min(1, 'Host is required'),
22+
port: z.coerce.number().int().positive('Port must be a positive integer'),
23+
database: z.string().min(1, 'Database name is required'),
24+
username: z.string().min(1, 'Username is required').optional(),
25+
password: z.string().min(1, 'Password is required').optional(),
26+
authSource: z.string().optional(),
27+
ssl: sslModeSchema,
28+
})
2729

2830
const mongoJsonStringOrObjectSchema = (message: string) =>
2931
z
@@ -45,7 +47,7 @@ const booleanStringSchema = z
4547
return false
4648
})
4749

48-
export const mongodbQueryBodySchema = mongoConnectionBodySchema.extend({
50+
export const mongodbQueryBodySchema = mongoConnectionBaseSchema.extend({
4951
collection: z.string().min(1, 'Collection name is required'),
5052
query: z
5153
.union([z.string(), z.object({}).passthrough()])
@@ -77,7 +79,7 @@ export const mongodbQueryBodySchema = mongoConnectionBodySchema.extend({
7779
}),
7880
})
7981

80-
export const mongodbExecuteBodySchema = mongoConnectionBodySchema.extend({
82+
export const mongodbExecuteBodySchema = mongoConnectionBaseSchema.extend({
8183
collection: z.string().min(1, 'Collection name is required'),
8284
pipeline: z
8385
.union([z.string(), z.array(z.object({}).passthrough())])
@@ -92,7 +94,7 @@ export const mongodbExecuteBodySchema = mongoConnectionBodySchema.extend({
9294
}),
9395
})
9496

95-
export const mongodbInsertBodySchema = mongoConnectionBodySchema.extend({
97+
export const mongodbInsertBodySchema = mongoConnectionBaseSchema.extend({
9698
collection: z.string().min(1, 'Collection name is required'),
9799
documents: z
98100
.union([z.array(z.record(z.string(), z.unknown())), z.string()])
@@ -112,7 +114,7 @@ export const mongodbInsertBodySchema = mongoConnectionBodySchema.extend({
112114
}),
113115
})
114116

115-
export const mongodbUpdateBodySchema = mongoConnectionBodySchema.extend({
117+
export const mongodbUpdateBodySchema = mongoConnectionBaseSchema.extend({
116118
collection: z.string().min(1, 'Collection name is required'),
117119
filter: mongoJsonStringOrObjectSchema('Filter is required for MongoDB Update').refine(
118120
(val) => val !== '{}',
@@ -123,7 +125,7 @@ export const mongodbUpdateBodySchema = mongoConnectionBodySchema.extend({
123125
multi: booleanStringSchema,
124126
})
125127

126-
export const mongodbDeleteBodySchema = mongoConnectionBodySchema.extend({
128+
export const mongodbDeleteBodySchema = mongoConnectionBaseSchema.extend({
127129
collection: z.string().min(1, 'Collection name is required'),
128130
filter: mongoJsonStringOrObjectSchema('Filter is required for MongoDB Delete').refine(
129131
(val) => val !== '{}',

0 commit comments

Comments
 (0)