Skip to content

Commit f6ed8d8

Browse files
committed
Add JSON Schema definitions for NoSQL and SQL configurations
- Introduced NoSQL data type mappings, database types, driver configurations, index definitions, operation types, query options, transaction options, replication configurations, and sharding configurations. - Added SQL dialects and driver configurations with capabilities and data type mappings. - Included SSL and sharding configuration schemas to enhance database connection security and management. - Defined transformation types for data processing.
1 parent cd96c2e commit f6ed8d8

28 files changed

Lines changed: 2696 additions & 134 deletions
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
---
2+
title: Driver Nosql
3+
description: Driver Nosql protocol schemas
4+
---
5+
6+
# Driver Nosql
7+
8+
<Callout type="info">
9+
**Source:** `packages/spec/src/data/driver-nosql.zod.ts`
10+
</Callout>
11+
12+
## TypeScript Usage
13+
14+
```typescript
15+
import { AggregationPipelineSchema, AggregationStageSchema, ConsistencyLevelSchema, DocumentValidationSchemaSchema, NoSQLDataTypeMappingSchema, NoSQLDatabaseTypeSchema, NoSQLDriverConfigSchema, NoSQLIndexSchema, NoSQLIndexTypeSchema, NoSQLOperationTypeSchema, NoSQLQueryOptionsSchema, NoSQLTransactionOptionsSchema, ReplicationConfigSchema, ShardingConfigSchema } from '@objectstack/spec/data';
16+
import type { AggregationPipeline, AggregationStage, ConsistencyLevel, DocumentValidationSchema, NoSQLDataTypeMapping, NoSQLDatabaseType, NoSQLDriverConfig, NoSQLIndex, NoSQLIndexType, NoSQLOperationType, NoSQLQueryOptions, NoSQLTransactionOptions, ReplicationConfig, ShardingConfig } from '@objectstack/spec/data';
17+
18+
// Validate data
19+
const result = AggregationPipelineSchema.parse(data);
20+
```
21+
22+
---
23+
24+
## AggregationPipeline
25+
26+
### Properties
27+
28+
| Property | Type | Required | Description |
29+
| :--- | :--- | :--- | :--- |
30+
| **collection** | `string` || Collection/table name |
31+
| **stages** | `object[]` || Aggregation pipeline stages |
32+
| **options** | `object` | optional | Query options |
33+
34+
---
35+
36+
## AggregationStage
37+
38+
### Properties
39+
40+
| Property | Type | Required | Description |
41+
| :--- | :--- | :--- | :--- |
42+
| **operator** | `string` || Aggregation operator (e.g., $match, $group, $sort) |
43+
| **options** | `Record<string, any>` || Stage-specific options |
44+
45+
---
46+
47+
## ConsistencyLevel
48+
49+
### Allowed Values
50+
51+
* `all`
52+
* `quorum`
53+
* `one`
54+
* `local_quorum`
55+
* `each_quorum`
56+
* `eventual`
57+
58+
---
59+
60+
## DocumentValidationSchema
61+
62+
### Properties
63+
64+
| Property | Type | Required | Description |
65+
| :--- | :--- | :--- | :--- |
66+
| **enabled** | `boolean` | optional | Enable schema validation |
67+
| **validationLevel** | `Enum<'strict' \| 'moderate' \| 'off'>` | optional | Validation strictness |
68+
| **validationAction** | `Enum<'error' \| 'warn'>` | optional | Action on validation failure |
69+
| **jsonSchema** | `Record<string, any>` | optional | JSON Schema for validation |
70+
71+
---
72+
73+
## NoSQLDataTypeMapping
74+
75+
### Properties
76+
77+
| Property | Type | Required | Description |
78+
| :--- | :--- | :--- | :--- |
79+
| **text** | `string` || NoSQL type for text fields |
80+
| **number** | `string` || NoSQL type for number fields |
81+
| **boolean** | `string` || NoSQL type for boolean fields |
82+
| **date** | `string` || NoSQL type for date fields |
83+
| **datetime** | `string` || NoSQL type for datetime fields |
84+
| **json** | `string` | optional | NoSQL type for JSON/object fields |
85+
| **uuid** | `string` | optional | NoSQL type for UUID fields |
86+
| **binary** | `string` | optional | NoSQL type for binary fields |
87+
| **array** | `string` | optional | NoSQL type for array fields |
88+
| **objectId** | `string` | optional | NoSQL type for ObjectID fields (MongoDB) |
89+
| **geopoint** | `string` | optional | NoSQL type for geospatial point fields |
90+
91+
---
92+
93+
## NoSQLDatabaseType
94+
95+
### Allowed Values
96+
97+
* `mongodb`
98+
* `couchdb`
99+
* `dynamodb`
100+
* `cassandra`
101+
* `redis`
102+
* `elasticsearch`
103+
* `neo4j`
104+
* `orientdb`
105+
106+
---
107+
108+
## NoSQLDriverConfig
109+
110+
### Properties
111+
112+
| Property | Type | Required | Description |
113+
| :--- | :--- | :--- | :--- |
114+
| **name** | `string` || Driver instance name |
115+
| **type** | `string` || Driver type must be "nosql" |
116+
| **capabilities** | `object` || Driver capability flags |
117+
| **connectionString** | `string` | optional | Database connection string (driver-specific format) |
118+
| **poolConfig** | `object` | optional | Connection pool configuration |
119+
| **databaseType** | `Enum<'mongodb' \| 'couchdb' \| 'dynamodb' \| 'cassandra' \| 'redis' \| 'elasticsearch' \| 'neo4j' \| 'orientdb'>` || Specific NoSQL database type |
120+
| **dataTypeMapping** | `object` || NoSQL data type mapping configuration |
121+
| **consistency** | `Enum<'all' \| 'quorum' \| 'one' \| 'local_quorum' \| 'each_quorum' \| 'eventual'>` | optional | Consistency level for operations |
122+
| **replication** | `object` | optional | Replication configuration |
123+
| **sharding** | `object` | optional | Sharding configuration |
124+
| **schemaValidation** | `object` | optional | Document schema validation |
125+
| **region** | `string` | optional | AWS region (for managed NoSQL services) |
126+
| **accessKeyId** | `string` | optional | AWS access key ID |
127+
| **secretAccessKey** | `string` | optional | AWS secret access key |
128+
| **ttlField** | `string` | optional | Field name for TTL (auto-deletion) |
129+
| **maxDocumentSize** | `integer` | optional | Maximum document size in bytes |
130+
| **collectionPrefix** | `string` | optional | Prefix for collection/table names |
131+
132+
---
133+
134+
## NoSQLIndex
135+
136+
### Properties
137+
138+
| Property | Type | Required | Description |
139+
| :--- | :--- | :--- | :--- |
140+
| **name** | `string` || Index name |
141+
| **type** | `Enum<'single' \| 'compound' \| 'unique' \| 'text' \| 'geospatial' \| 'hashed' \| 'ttl' \| 'sparse'>` || Index type |
142+
| **fields** | `object[]` || Fields to index |
143+
| **unique** | `boolean` | optional | Enforce uniqueness |
144+
| **sparse** | `boolean` | optional | Sparse index |
145+
| **expireAfterSeconds** | `integer` | optional | TTL in seconds |
146+
| **partialFilterExpression** | `Record<string, any>` | optional | Partial index filter |
147+
| **background** | `boolean` | optional | Create index in background |
148+
149+
---
150+
151+
## NoSQLIndexType
152+
153+
### Allowed Values
154+
155+
* `single`
156+
* `compound`
157+
* `unique`
158+
* `text`
159+
* `geospatial`
160+
* `hashed`
161+
* `ttl`
162+
* `sparse`
163+
164+
---
165+
166+
## NoSQLOperationType
167+
168+
### Allowed Values
169+
170+
* `find`
171+
* `findOne`
172+
* `insert`
173+
* `update`
174+
* `delete`
175+
* `aggregate`
176+
* `mapReduce`
177+
* `count`
178+
* `distinct`
179+
* `createIndex`
180+
* `dropIndex`
181+
182+
---
183+
184+
## NoSQLQueryOptions
185+
186+
### Properties
187+
188+
| Property | Type | Required | Description |
189+
| :--- | :--- | :--- | :--- |
190+
| **consistency** | `Enum<'all' \| 'quorum' \| 'one' \| 'local_quorum' \| 'each_quorum' \| 'eventual'>` | optional | Consistency level override |
191+
| **readFromSecondary** | `boolean` | optional | Allow reading from secondary replicas |
192+
| **projection** | `Record<string, Enum<'0' \| '1'>>` | optional | Field projection |
193+
| **timeout** | `integer` | optional | Query timeout (ms) |
194+
| **useCursor** | `boolean` | optional | Use cursor instead of loading all results |
195+
| **batchSize** | `integer` | optional | Cursor batch size |
196+
| **profile** | `boolean` | optional | Enable query profiling |
197+
| **hint** | `string` | optional | Index hint for query optimization |
198+
199+
---
200+
201+
## NoSQLTransactionOptions
202+
203+
### Properties
204+
205+
| Property | Type | Required | Description |
206+
| :--- | :--- | :--- | :--- |
207+
| **readConcern** | `Enum<'local' \| 'majority' \| 'linearizable' \| 'snapshot'>` | optional | Read concern level |
208+
| **writeConcern** | `Enum<'majority' \| 'acknowledged' \| 'unacknowledged'>` | optional | Write concern level |
209+
| **readPreference** | `Enum<'primary' \| 'primaryPreferred' \| 'secondary' \| 'secondaryPreferred' \| 'nearest'>` | optional | Read preference |
210+
| **maxCommitTimeMS** | `integer` | optional | Transaction commit timeout (ms) |
211+
212+
---
213+
214+
## ReplicationConfig
215+
216+
### Properties
217+
218+
| Property | Type | Required | Description |
219+
| :--- | :--- | :--- | :--- |
220+
| **enabled** | `boolean` | optional | Enable replication |
221+
| **replicaSetName** | `string` | optional | Replica set name |
222+
| **replicas** | `integer` | optional | Number of replicas |
223+
| **readPreference** | `Enum<'primary' \| 'primaryPreferred' \| 'secondary' \| 'secondaryPreferred' \| 'nearest'>` | optional | Read preference for replica set |
224+
| **writeConcern** | `Enum<'majority' \| 'acknowledged' \| 'unacknowledged'>` | optional | Write concern level |
225+
226+
---
227+
228+
## ShardingConfig
229+
230+
### Properties
231+
232+
| Property | Type | Required | Description |
233+
| :--- | :--- | :--- | :--- |
234+
| **enabled** | `boolean` | optional | Enable sharding |
235+
| **shardKey** | `string` | optional | Field to use as shard key |
236+
| **shardingStrategy** | `Enum<'hash' \| 'range' \| 'zone'>` | optional | Sharding strategy |
237+
| **numShards** | `integer` | optional | Number of shards |
238+
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: Driver Sql
3+
description: Driver Sql protocol schemas
4+
---
5+
6+
# Driver Sql
7+
8+
<Callout type="info">
9+
**Source:** `packages/spec/src/data/driver-sql.zod.ts`
10+
</Callout>
11+
12+
## TypeScript Usage
13+
14+
```typescript
15+
import { DataTypeMappingSchema, SQLDialectSchema, SQLDriverConfigSchema, SSLConfigSchema } from '@objectstack/spec/data';
16+
import type { DataTypeMapping, SQLDialect, SQLDriverConfig, SSLConfig } from '@objectstack/spec/data';
17+
18+
// Validate data
19+
const result = DataTypeMappingSchema.parse(data);
20+
```
21+
22+
---
23+
24+
## DataTypeMapping
25+
26+
### Properties
27+
28+
| Property | Type | Required | Description |
29+
| :--- | :--- | :--- | :--- |
30+
| **text** | `string` || SQL type for text fields (e.g., VARCHAR, TEXT) |
31+
| **number** | `string` || SQL type for number fields (e.g., NUMERIC, DECIMAL, INT) |
32+
| **boolean** | `string` || SQL type for boolean fields (e.g., BOOLEAN, BIT) |
33+
| **date** | `string` || SQL type for date fields (e.g., DATE) |
34+
| **datetime** | `string` || SQL type for datetime fields (e.g., TIMESTAMP, DATETIME) |
35+
| **json** | `string` | optional | SQL type for JSON fields (e.g., JSON, JSONB) |
36+
| **uuid** | `string` | optional | SQL type for UUID fields (e.g., UUID, CHAR(36)) |
37+
| **binary** | `string` | optional | SQL type for binary fields (e.g., BLOB, BYTEA) |
38+
39+
---
40+
41+
## SQLDialect
42+
43+
### Allowed Values
44+
45+
* `postgresql`
46+
* `mysql`
47+
* `sqlite`
48+
* `mssql`
49+
* `oracle`
50+
* `mariadb`
51+
52+
---
53+
54+
## SQLDriverConfig
55+
56+
### Properties
57+
58+
| Property | Type | Required | Description |
59+
| :--- | :--- | :--- | :--- |
60+
| **name** | `string` || Driver instance name |
61+
| **type** | `string` || Driver type must be "sql" |
62+
| **capabilities** | `object` || Driver capability flags |
63+
| **connectionString** | `string` | optional | Database connection string (driver-specific format) |
64+
| **poolConfig** | `object` | optional | Connection pool configuration |
65+
| **dialect** | `Enum<'postgresql' \| 'mysql' \| 'sqlite' \| 'mssql' \| 'oracle' \| 'mariadb'>` || SQL database dialect |
66+
| **dataTypeMapping** | `object` || SQL data type mapping configuration |
67+
| **ssl** | `boolean` | optional | Enable SSL/TLS connection |
68+
| **sslConfig** | `object` | optional | SSL/TLS configuration (required when ssl is true) |
69+
70+
---
71+
72+
## SSLConfig
73+
74+
### Properties
75+
76+
| Property | Type | Required | Description |
77+
| :--- | :--- | :--- | :--- |
78+
| **rejectUnauthorized** | `boolean` | optional | Reject connections with invalid certificates |
79+
| **ca** | `string` | optional | CA certificate file path or content |
80+
| **cert** | `string` | optional | Client certificate file path or content |
81+
| **key** | `string` | optional | Client private key file path or content |
82+

content/docs/references/data/external-lookup.mdx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ description: External Lookup protocol schemas
1212
## TypeScript Usage
1313

1414
```typescript
15-
import { ExternalDataSourceSchema, ExternalLookupSchema } from '@objectstack/spec/data';
16-
import type { ExternalDataSource, ExternalLookup } from '@objectstack/spec/data';
15+
import { ExternalDataSourceSchema, ExternalFieldMappingSchema, ExternalLookupSchema } from '@objectstack/spec/data';
16+
import type { ExternalDataSource, ExternalFieldMapping, ExternalLookup } from '@objectstack/spec/data';
1717

1818
// Validate data
1919
const result = ExternalDataSourceSchema.parse(data);
@@ -35,6 +35,21 @@ const result = ExternalDataSourceSchema.parse(data);
3535

3636
---
3737

38+
## ExternalFieldMapping
39+
40+
### Properties
41+
42+
| Property | Type | Required | Description |
43+
| :--- | :--- | :--- | :--- |
44+
| **source** | `string` || Source field name |
45+
| **target** | `string` || Target field name |
46+
| **transform** | `object \| object \| object \| object \| object` | optional | Transformation to apply |
47+
| **defaultValue** | `any` | optional | Default if source is null/undefined |
48+
| **type** | `string` | optional | Field type |
49+
| **readonly** | `boolean` | optional | Read-only field |
50+
51+
---
52+
3853
## ExternalLookup
3954

4055
### Properties

0 commit comments

Comments
 (0)