-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmongo.zod.ts
More file actions
83 lines (69 loc) · 2.89 KB
/
mongo.zod.ts
File metadata and controls
83 lines (69 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { z } from 'zod';
import { DriverDefinitionSchema } from '../datasource.zod';
/**
* MongoDB Standard Driver Protocol
*
* Defines the strict schema for MongoDB connection and capabilities.
* This is used by the Platform to validate `datasource.config` when `driver: 'mongo'`.
*/
// ==========================================================================
// 1. Connection Configuration
// ==========================================================================
export const MongoConfigSchema = z.object({
/**
* Connection URI (Standard Connection String)
* If provided, host/port/username/password fields may be ignored or merged depending on driver logic.
* Format: mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]
*/
url: z.string().describe('Connection URI').optional(),
/**
* Database Name (Required)
* The logical database to store collections.
*/
database: z.string().min(1).describe('Database Name'),
/** Hostname (Optional if url is provided) */
host: z.string().default('127.0.0.1').describe('Host address').optional(),
/** Port (Optional, default 27017) */
port: z.number().int().default(27017).describe('Port number').optional(),
/** Username for authentication */
username: z.string().describe('Authentication Username').optional(),
/** Password for authentication */
password: z.string().describe('Authentication Password').optional(),
/** Authentication Database (Defaults to admin or database name) */
authSource: z.string().describe('Authentication Database').optional(),
/**
* Connection Options
* Passthrough options to the underlying MongoDB driver (e.g. valid certs, timeouts)
*/
options: z.record(z.string(), z.unknown()).describe('Extra driver options (ssl, poolSize, etc)').optional(),
}).describe('MongoDB Connection Configuration');
// ==========================================================================
// 2. Driver Definition (Metadata)
// ==========================================================================
/**
* The static definition of the Mongo driver's capabilities and default metadata.
* This implements the `DriverDefinitionSchema` contract.
*/
export const MongoDriverSpec = DriverDefinitionSchema.parse({
id: 'mongo',
label: 'MongoDB',
description: 'Official MongoDB Driver for ObjectStack. Supports rich queries, aggregation, and atomic updates.',
icon: 'database',
configSchema: {}, // Will be populated with JSON Schema version of MongoConfigSchema at runtime
capabilities: {
transactions: true,
// Query
queryFilters: true,
queryAggregations: true,
querySorting: true,
queryPagination: true,
fullTextSearch: true,
// Schema
dynamicSchema: true,
}
});
/**
* Derived Types
*/
export type MongoConfig = z.infer<typeof MongoConfigSchema>;