-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdriver-sql.zod.ts
More file actions
159 lines (151 loc) · 4.82 KB
/
driver-sql.zod.ts
File metadata and controls
159 lines (151 loc) · 4.82 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
import { z } from 'zod';
import { DriverConfigSchema } from './driver.zod';
/**
* SQL Dialect Enumeration
* Supported SQL database dialects
*/
export const SQLDialectSchema = z.enum([
'postgresql',
'mysql',
'sqlite',
'mssql',
'oracle',
'mariadb',
]);
export type SQLDialect = z.infer<typeof SQLDialectSchema>;
/**
* Data Type Mapping Schema
* Maps ObjectStack field types to SQL-specific data types
*
* @example PostgreSQL data type mapping
* {
* text: 'VARCHAR(255)',
* number: 'NUMERIC',
* boolean: 'BOOLEAN',
* date: 'DATE',
* datetime: 'TIMESTAMP',
* json: 'JSONB',
* uuid: 'UUID',
* binary: 'BYTEA'
* }
*/
export const DataTypeMappingSchema = z.object({
text: z.string().describe('SQL type for text fields (e.g., VARCHAR, TEXT)'),
number: z.string().describe('SQL type for number fields (e.g., NUMERIC, DECIMAL, INT)'),
boolean: z.string().describe('SQL type for boolean fields (e.g., BOOLEAN, BIT)'),
date: z.string().describe('SQL type for date fields (e.g., DATE)'),
datetime: z.string().describe('SQL type for datetime fields (e.g., TIMESTAMP, DATETIME)'),
json: z.string().optional().describe('SQL type for JSON fields (e.g., JSON, JSONB)'),
uuid: z.string().optional().describe('SQL type for UUID fields (e.g., UUID, CHAR(36))'),
binary: z.string().optional().describe('SQL type for binary fields (e.g., BLOB, BYTEA)'),
});
export type DataTypeMapping = z.infer<typeof DataTypeMappingSchema>;
/**
* SSL Configuration Schema
* SSL/TLS connection configuration for secure database connections
*
* @example PostgreSQL SSL configuration
* {
* rejectUnauthorized: true,
* ca: '/path/to/ca-cert.pem',
* cert: '/path/to/client-cert.pem',
* key: '/path/to/client-key.pem'
* }
*/
export const SSLConfigSchema = z.object({
rejectUnauthorized: z.boolean().default(true).describe('Reject connections with invalid certificates'),
ca: z.string().optional().describe('CA certificate file path or content'),
cert: z.string().optional().describe('Client certificate file path or content'),
key: z.string().optional().describe('Client private key file path or content'),
}).refine((data) => {
// If cert is provided, key must also be provided, and vice versa
const hasCert = data.cert !== undefined;
const hasKey = data.key !== undefined;
return hasCert === hasKey;
}, {
message: 'Client certificate (cert) and private key (key) must be provided together',
});
export type SSLConfig = z.infer<typeof SSLConfigSchema>;
/**
* SQL Driver Configuration Schema
* Extended driver configuration specific to SQL databases
*
* @example PostgreSQL driver configuration
* {
* name: 'primary-db',
* type: 'sql',
* dialect: 'postgresql',
* connectionString: 'postgresql://user:pass@localhost:5432/mydb',
* dataTypeMapping: {
* text: 'VARCHAR(255)',
* number: 'NUMERIC',
* boolean: 'BOOLEAN',
* date: 'DATE',
* datetime: 'TIMESTAMP',
* json: 'JSONB',
* uuid: 'UUID',
* binary: 'BYTEA'
* },
* ssl: true,
* sslConfig: {
* rejectUnauthorized: true,
* ca: '/etc/ssl/certs/ca.pem'
* },
* poolConfig: {
* min: 2,
* max: 10,
* idleTimeoutMillis: 30000,
* connectionTimeoutMillis: 5000
* },
* capabilities: {
* create: true,
* read: true,
* update: true,
* delete: true,
* bulkCreate: true,
* bulkUpdate: true,
* bulkDelete: true,
* transactions: true,
* savepoints: true,
* isolationLevels: ['read-committed', 'repeatable-read', 'serializable'],
* queryFilters: true,
* queryAggregations: true,
* querySorting: true,
* queryPagination: true,
* queryWindowFunctions: true,
* querySubqueries: true,
* queryCTE: true,
* joins: true,
* fullTextSearch: true,
* jsonQuery: true,
* geospatialQuery: false,
* streaming: true,
* jsonFields: true,
* arrayFields: true,
* vectorSearch: true,
* geoSpatial: false,
* schemaSync: true,
* migrations: true,
* indexes: true,
* connectionPooling: true,
* preparedStatements: true,
* queryCache: false
* }
* }
*/
export const SQLDriverConfigSchema = DriverConfigSchema.extend({
type: z.literal('sql').describe('Driver type must be "sql"'),
dialect: SQLDialectSchema.describe('SQL database dialect'),
dataTypeMapping: DataTypeMappingSchema.describe('SQL data type mapping configuration'),
ssl: z.boolean().default(false).describe('Enable SSL/TLS connection'),
sslConfig: SSLConfigSchema.optional().describe('SSL/TLS configuration (required when ssl is true)'),
}).refine((data) => {
// If ssl is enabled, sslConfig must be provided
if (data.ssl && !data.sslConfig) {
return false;
}
return true;
}, {
message: 'sslConfig is required when ssl is true',
});
export type SQLDriverConfig = z.infer<typeof SQLDriverConfigSchema>;