|
1 | 1 | import { z } from 'zod'; |
| 2 | +import { DriverDefinitionSchema } from './../driver.zod'; |
2 | 3 |
|
3 | 4 | /** |
4 | | - * MongoDB Driver Configuration Schema |
5 | | - * Defines the connection settings specific to MongoDB. |
| 5 | + * MongoDB Standard Driver Protocol |
| 6 | + * |
| 7 | + * Defines the strict schema for MongoDB connection and capabilities. |
| 8 | + * This is used by the Platform to validate `datasource.config` when `driver: 'mongo'`. |
6 | 9 | */ |
7 | | -export const MongoConfigSchema = z.object({ |
8 | | - /** |
9 | | - * Connection URI. |
10 | | - * If provided, it takes precedence over host/port/database. |
11 | | - * Format: mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] |
12 | | - */ |
13 | | - url: z.string().optional().describe('Connection URI'), |
14 | 10 |
|
15 | | - /** |
16 | | - * Database Name. |
17 | | - * Required to identify which database to use within the cluster. |
18 | | - */ |
19 | | - database: z.string().describe('Database Name'), |
20 | | - |
21 | | - /** |
22 | | - * Hostname or IP address. |
23 | | - * Defaults to localhost if not specified. |
24 | | - */ |
25 | | - host: z.string().default('127.0.0.1').describe('Host address'), |
26 | | - |
27 | | - /** |
28 | | - * Port number. |
29 | | - * Defaults to 27017. |
30 | | - */ |
31 | | - port: z.number().default(27017).describe('Port number'), |
| 11 | +// ========================================================================== |
| 12 | +// 1. Connection Configuration |
| 13 | +// ========================================================================== |
32 | 14 |
|
| 15 | +export const MongoConfigSchema = z.object({ |
33 | 16 | /** |
34 | | - * Authentication Username. |
| 17 | + * Connection URI (Standard Connection String) |
| 18 | + * If provided, host/port/username/password fields may be ignored or merged depending on driver logic. |
| 19 | + * Format: mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] |
35 | 20 | */ |
36 | | - username: z.string().optional().describe('Auth User'), |
| 21 | + url: z.string().describe('Connection URI').optional(), |
37 | 22 |
|
38 | 23 | /** |
39 | | - * Authentication Password. |
| 24 | + * Database Name (Required) |
| 25 | + * The logical database to store collections. |
40 | 26 | */ |
41 | | - password: z.string().optional().describe('Auth Password'), |
| 27 | + database: z.string().min(1).describe('Database Name'), |
42 | 28 |
|
43 | | - /** |
44 | | - * Authentication Database. |
45 | | - * The database where the user credentials are stored (defaults to 'admin' or the target database). |
46 | | - */ |
47 | | - authSource: z.string().optional().describe('Authentication Database'), |
| 29 | + /** Hostname (Optional if url is provided) */ |
| 30 | + host: z.string().default('127.0.0.1').describe('Host address').optional(), |
48 | 31 |
|
49 | | - /** |
50 | | - * Enable SSL/TLS. |
51 | | - */ |
52 | | - ssl: z.boolean().default(false).describe('Enable SSL'), |
| 32 | + /** Port (Optional, default 27017) */ |
| 33 | + port: z.number().int().default(27017).describe('Port number').optional(), |
53 | 34 |
|
54 | | - /** |
55 | | - * Replica Set Name. |
56 | | - * Required if connecting to a replica set. |
57 | | - */ |
58 | | - replicaSet: z.string().optional().describe('Replica Set Name'), |
| 35 | + /** Username for authentication */ |
| 36 | + username: z.string().describe('Authentication Username').optional(), |
59 | 37 |
|
60 | | - /** |
61 | | - * Read Preference. |
62 | | - * Controls which members of the replica set usually receive read operations. |
63 | | - */ |
64 | | - readPreference: z.enum(['primary', 'primaryPreferred', 'secondary', 'secondaryPreferred', 'nearest']) |
65 | | - .default('primary') |
66 | | - .describe('Read Preference'), |
| 38 | + /** Password for authentication */ |
| 39 | + password: z.string().describe('Authentication Password').optional(), |
| 40 | + |
| 41 | + /** Authentication Database (Defaults to admin or database name) */ |
| 42 | + authSource: z.string().describe('Authentication Database').optional(), |
67 | 43 |
|
68 | 44 | /** |
69 | | - * Connection Pool Size. |
70 | | - * The maximum number of connections in the connection pool. |
| 45 | + * Connection Options |
| 46 | + * Passthrough options to the underlying MongoDB driver (e.g. valid certs, timeouts) |
71 | 47 | */ |
72 | | - maxPoolSize: z.number().optional().describe('Max Connection Pool Size'), |
| 48 | + options: z.record(z.any()).describe('Extra driver options (ssl, poolSize, etc)').optional(), |
| 49 | +}).describe('MongoDB Connection Configuration'); |
73 | 50 |
|
74 | | - /** |
75 | | - * Min Connection Pool Size. |
76 | | - * The minimum number of connections in the connection pool. |
77 | | - */ |
78 | | - minPoolSize: z.number().optional().describe('Min Connection Pool Size'), |
79 | | - |
80 | | - /** |
81 | | - * Connect Timeout (ms). |
82 | | - * How long to wait for a connection to be established before timing out. |
83 | | - */ |
84 | | - connectTimeoutMS: z.number().optional().describe('Connection Timeout (ms)'), |
| 51 | +// ========================================================================== |
| 52 | +// 2. Driver Definition (Metadata) |
| 53 | +// ========================================================================== |
85 | 54 |
|
86 | | - /** |
87 | | - * Socket Timeout (ms). |
88 | | - * How long a socket can remain idle before being closed. |
89 | | - */ |
90 | | - socketTimeoutMS: z.number().optional().describe('Socket Timeout (ms)'), |
| 55 | +/** |
| 56 | + * The static definition of the Mongo driver's capabilities and default metadata. |
| 57 | + * This implements the `DriverDefinitionSchema` contract. |
| 58 | + */ |
| 59 | +export const MongoDriverSpec = DriverDefinitionSchema.parse({ |
| 60 | + id: 'mongo', |
| 61 | + label: 'MongoDB', |
| 62 | + description: 'Official MongoDB Driver for ObjectStack. Supports rich queries, aggregation, and atomic updates.', |
| 63 | + icon: 'database', |
| 64 | + configSchema: {}, // Will be populated with JSON Schema version of MongoConfigSchema at runtime |
| 65 | + capabilities: { |
| 66 | + transactions: true, |
| 67 | + // Query |
| 68 | + fullTextSearch: true, |
| 69 | + geoSpatial: true, |
| 70 | + aggregation: true, |
| 71 | + // Schema |
| 72 | + mutableSchema: true, |
| 73 | + jsonField: true, |
| 74 | + // Relations |
| 75 | + crossObjectJoin: true |
| 76 | + } |
91 | 77 | }); |
92 | 78 |
|
| 79 | +/** |
| 80 | + * Derived Types |
| 81 | + */ |
93 | 82 | export type MongoConfig = z.infer<typeof MongoConfigSchema>; |
0 commit comments