-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatasource.zod.ts
More file actions
167 lines (134 loc) · 6.23 KB
/
datasource.zod.ts
File metadata and controls
167 lines (134 loc) · 6.23 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { z } from 'zod';
/**
* Driver Identifier
* Can be a built-in driver or a plugin-contributed driver (e.g., "com.vendor.snowflake").
*/
export const DriverType = z.string().describe('Underlying driver identifier');
/**
* Driver Definition Schema
* Metadata describing a Database Driver.
* Plugins use this to register new connectivity options.
*/
export const DriverDefinitionSchema = z.object({
id: z.string().describe('Unique driver identifier (e.g. "postgres")'),
label: z.string().describe('Display label (e.g. "PostgreSQL")'),
description: z.string().optional(),
icon: z.string().optional(),
/**
* Configuration Schema (JSON Schema)
* Describes the structure of the `config` object needed for this driver.
* Used by the UI to generate the connection form.
*/
configSchema: z.record(z.string(), z.unknown()).describe('JSON Schema for connection configuration'),
/**
* Default Capabilities
* What this driver supports out-of-the-box.
*/
capabilities: z.lazy(() => DatasourceCapabilities).optional(),
});
/**
* Datasource Capabilities Schema
* Declares what this datasource naturally supports.
* The ObjectQL engine uses this to determine what logic to push down
* and what to compute in memory.
*/
export const DatasourceCapabilities = z.object({
// ============================================================================
// Transaction & Connection Management
// ============================================================================
/** Can handle ACID transactions? */
transactions: z.boolean().default(false),
// ============================================================================
// Query Operations
// ============================================================================
/** Can execute WHERE clause filters natively? */
queryFilters: z.boolean().default(false),
/** Can perform aggregation (group by, sum, avg)? */
queryAggregations: z.boolean().default(false),
/** Can perform ORDER BY sorting? */
querySorting: z.boolean().default(false),
/** Can perform LIMIT/OFFSET pagination? */
queryPagination: z.boolean().default(false),
/** Can perform window functions? */
queryWindowFunctions: z.boolean().default(false),
/** Can perform subqueries? */
querySubqueries: z.boolean().default(false),
/** Can execute SQL-like joins natively? */
joins: z.boolean().default(false),
// ============================================================================
// Advanced Features
// ============================================================================
/** Can perform full-text search? */
fullTextSearch: z.boolean().default(false),
/** Is read-only? */
readOnly: z.boolean().default(false),
/** Is scheme-less (needs schema inference)? */
dynamicSchema: z.boolean().default(false),
});
/**
* Datasource Schema
* Represents a connection to an external data store.
*/
export const DatasourceSchema = z.object({
/** Machine Name */
name: z.string().regex(/^[a-z_][a-z0-9_]*$/).describe('Unique datasource identifier'),
/** Human Label */
label: z.string().optional().describe('Display label'),
/** Driver */
driver: DriverType.describe('Underlying driver type'),
/**
* Connection Configuration
* Specific to the driver (e.g., host, port, user, password, bucket, etc.)
* Stored securely (passwords usually interpolated from ENV).
*/
config: z.record(z.string(), z.unknown()).describe('Driver specific configuration'),
/**
* Connection Pool Configuration
* Standard connection pooling settings.
*/
pool: z.object({
min: z.number().default(0).describe('Minimum connections'),
max: z.number().default(10).describe('Maximum connections'),
idleTimeoutMillis: z.number().default(30000).describe('Idle timeout'),
connectionTimeoutMillis: z.number().default(3000).describe('Connection establishment timeout'),
}).optional().describe('Connection pool settings'),
/**
* Read Replicas
* Optional list of duplicate configurations for read-only operations.
* Useful for scaling read throughput.
*/
readReplicas: z.array(z.record(z.string(), z.unknown())).optional().describe('Read-only replica configurations'),
/**
* Capability Overrides
* Manually override what the driver claims to support.
*/
capabilities: DatasourceCapabilities.optional().describe('Capability overrides'),
/** Health Check */
healthCheck: z.object({
enabled: z.boolean().default(true).describe('Enable health check endpoint'),
intervalMs: z.number().default(30000).describe('Health check interval in milliseconds'),
timeoutMs: z.number().default(5000).describe('Health check timeout in milliseconds'),
}).optional().describe('Datasource health check configuration'),
/** SSL/TLS Configuration */
ssl: z.object({
enabled: z.boolean().default(false).describe('Enable SSL/TLS for database connection'),
rejectUnauthorized: z.boolean().default(true).describe('Reject connections with invalid/self-signed certificates'),
ca: z.string().optional().describe('CA certificate (PEM format or path to file)'),
cert: z.string().optional().describe('Client certificate (PEM format or path to file)'),
key: z.string().optional().describe('Client private key (PEM format or path to file)'),
}).optional().describe('SSL/TLS configuration for secure database connections'),
/** Retry Policy */
retryPolicy: z.object({
maxRetries: z.number().default(3).describe('Maximum number of retry attempts'),
baseDelayMs: z.number().default(1000).describe('Base delay between retries in milliseconds'),
maxDelayMs: z.number().default(30000).describe('Maximum delay between retries in milliseconds'),
backoffMultiplier: z.number().default(2).describe('Exponential backoff multiplier'),
}).optional().describe('Connection retry policy for transient failures'),
/** Description */
description: z.string().optional().describe('Internal description'),
/** Is enabled? */
active: z.boolean().default(true).describe('Is datasource enabled'),
});
export type Datasource = z.infer<typeof DatasourceSchema>;
export type DatasourceCapabilitiesType = z.infer<typeof DatasourceCapabilities>;