feat: add connection and ssh zod schemas
This commit is contained in:
1 parent
80ba44f1ce
commit
040d9288e3
2 files changed
+88
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import * as z from 'zod'
|
||||
|
||||
export const sshConfigSchema = z.object({
|
||||
host: z.string().min(1),
|
||||
port: z.number().int().positive().default(22),
|
||||
user: z.string().min(1),
|
||||
password: z.string().optional(),
|
||||
privateKey: z.string().optional(),
|
||||
privateKeyPath: z.string().optional(),
|
||||
passphrase: z.string().optional(),
|
||||
agent: z.boolean().optional()
|
||||
})
|
||||
|
||||
export const connectionConfigSchema = z.object({
|
||||
name: z.string().regex(/^[a-zA-Z0-9_-]+$/, 'name must match [a-zA-Z0-9_-]+'),
|
||||
type: z.enum(['postgres', 'mysql']),
|
||||
host: z.string().min(1),
|
||||
port: z.number().int().positive().optional(),
|
||||
user: z.string().min(1),
|
||||
password: z.string().optional(),
|
||||
database: z.string().optional(),
|
||||
readonly: z.boolean().default(false),
|
||||
ssh: sshConfigSchema.optional()
|
||||
})
|
||||
|
||||
export type SshConfig = z.infer<typeof sshConfigSchema>
|
||||
export type ConnectionConfig = z.infer<typeof connectionConfigSchema>
|
||||
|
||||
export type ConnectionSource = 'env' | 'config' | 'store'
|
||||
|
||||
export type ResolvedConnection = {
|
||||
config: ConnectionConfig
|
||||
source: ConnectionSource
|
||||
hash: string
|
||||
}
|
||||
|
||||
export const defaultPort = (type: ConnectionConfig['type']): number =>
|
||||
type === 'postgres' ? 5432 : 3306
|
||||
Reference in new issue
Block a user