Skip to content

Commit f2497df

Browse files
committed
feat: Add Datasource and Manifest schemas for ObjectStack configuration
1 parent 74af573 commit f2497df

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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>;

packages/spec/src/system/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*/
99

1010
export * from './audit.zod';
11+
export * from './manifest.zod';
12+
export * from './datasource.zod';
1113
export * from './translation.zod';
1214
export * from './events.zod';
1315
export * from './job.zod';
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { z } from 'zod';
2+
import { SnakeCaseIdentifierSchema } from '../shared/identifiers.zod';
3+
import { DatasourceSchema } from './datasource.zod';
4+
import { AppSchema } from '../ui/app.zod';
5+
6+
/**
7+
* ObjectStack Manifest Protocol
8+
*
9+
* The root configuration for an ObjectStack Package or Project.
10+
* Typically defined in `objectstack.config.ts`.
11+
*
12+
* Acts as the entry point for the runtime to discover:
13+
* - Apps
14+
* - Datasources
15+
* - Objects (often referenced within Apps, but can be top-level)
16+
* - Policies & Permissions
17+
*/
18+
export const ManifestSchema = z.object({
19+
/** Package Name */
20+
name: SnakeCaseIdentifierSchema.describe('Package machine name'),
21+
22+
/** Semantic Version */
23+
version: z.string().regex(/^\d+\.\d+\.\d+$/).describe('Semantic version (x.y.z)'),
24+
25+
/** Display Label */
26+
label: z.string().optional().describe('Package display label'),
27+
28+
/** Package Description */
29+
description: z.string().optional().describe('Package description'),
30+
31+
/**
32+
* Included Apps
33+
* Applications provide the UI and navigation structure.
34+
*/
35+
apps: z.array(AppSchema).optional().describe('Applications included in this package'),
36+
37+
/**
38+
* System Datasources
39+
* External connections utilized by objects in this package.
40+
*/
41+
datasources: z.array(DatasourceSchema).optional().describe('Datasources defined in this package'),
42+
43+
/**
44+
* Global Configuration
45+
*/
46+
config: z.record(z.any()).optional().describe('Global package configuration'),
47+
48+
/**
49+
* Plugins
50+
* List of plugins to load.
51+
*/
52+
plugins: z.array(z.string()).optional().describe('List of plugin names (npm packages)'),
53+
});
54+
55+
export const Manifest = Object.assign(ManifestSchema, {
56+
create: <T extends z.input<typeof ManifestSchema>>(config: T) => config,
57+
});
58+
59+
export type Manifest = z.infer<typeof ManifestSchema>;

0 commit comments

Comments
 (0)