|
| 1 | +import { z } from 'zod'; |
| 2 | +import { SnakeCaseIdentifierSchema } from '../shared/identifiers.zod'; |
| 3 | + |
| 4 | +/** |
| 5 | + * Datasource Type Enum |
| 6 | + * Supported external data connection types. |
| 7 | + */ |
| 8 | +export const DatasourceTypeSchema = z.enum([ |
| 9 | + 'postgres', |
| 10 | + 'mysql', |
| 11 | + 'sqlserver', |
| 12 | + 'oracle', |
| 13 | + 'mongodb', |
| 14 | + 'redis', |
| 15 | + 'elasticsearch', |
| 16 | + 'salesforce', |
| 17 | + 'sap', |
| 18 | + 'http', |
| 19 | + 'other' |
| 20 | +]); |
| 21 | + |
| 22 | +/** |
| 23 | + * Datasource Protocol |
| 24 | + * |
| 25 | + * Defines external data connections for the ObjectStack Runtime. |
| 26 | + * Used to virtualize data from SQL, NoSQL, and SaaS providers. |
| 27 | + */ |
| 28 | +export const DatasourceSchema = z.object({ |
| 29 | + /** |
| 30 | + * Unique machine identifier for the datasource. |
| 31 | + * Used in object definitions to reference this source. |
| 32 | + */ |
| 33 | + name: SnakeCaseIdentifierSchema.describe('Unique machine identifier (snake_case)'), |
| 34 | + |
| 35 | + /** Display label for the datasource */ |
| 36 | + label: z.string().optional().describe('Display label'), |
| 37 | + |
| 38 | + /** Description */ |
| 39 | + description: z.string().optional().describe('Description of the data source'), |
| 40 | + |
| 41 | + /** Connection Type */ |
| 42 | + type: DatasourceTypeSchema.describe('Type of data source'), |
| 43 | + |
| 44 | + /** |
| 45 | + * Connection Configuration |
| 46 | + * Driver-specific settings (host, port, credentials, connection string). |
| 47 | + * Note: Secrets should be referenced via ENV variables, not hardcoded. |
| 48 | + */ |
| 49 | + config: z.record(z.any()).default({}).describe('Driver specific configuration'), |
| 50 | + |
| 51 | + /** Enable/Disable this datasource */ |
| 52 | + enable: z.boolean().default(true).describe('Enable this datasource'), |
| 53 | + |
| 54 | + /** Read-only mode */ |
| 55 | + readOnly: z.boolean().default(false).describe('If true, writes are disabled'), |
| 56 | +}); |
| 57 | + |
| 58 | +export const Datasource = Object.assign(DatasourceSchema, { |
| 59 | + create: <T extends z.input<typeof DatasourceSchema>>(config: T) => config, |
| 60 | +}); |
| 61 | + |
| 62 | +export type DatasourceType = z.infer<typeof DatasourceTypeSchema>; |
| 63 | +export type Datasource = z.infer<typeof DatasourceSchema>; |
0 commit comments