@@ -34,6 +34,13 @@ It is **not** an ORM, but a high-level data protocol designed for AI agents, low
3434* This structure is optimized for LLMs (like ChatGPT/Claude) to understand schema and generate accurate, safe business logic without hallucinating SQL syntax.
3535
3636
37+ * ** ✅ Metadata-Driven Validation:**
38+ * Define validation rules declaratively in YAML/JSON metadata.
39+ * Support for field-level, cross-field, and state machine validation.
40+ * Configurable severity levels (error, warning, info) and triggers (create, update, delete).
41+ * Template messages with internationalization support.
42+
43+
3744* ** ⚡ Modern & Lightweight:**
3845* Written in 100% ** TypeScript** .
3946* ** Zero heavy legacy dependencies.** No runtime environment requirements beyond Node.js.
@@ -119,6 +126,100 @@ const resultsSql = await app.datasource('runtime').find(query);
119126
120127```
121128
129+ Both queries return the same results, but the underlying native query is optimized for MongoDB or PostgreSQL.
130+
131+ ### 3. Validation
132+
133+ Define validation rules declaratively in your object metadata:
134+
135+ ``` typescript
136+ import { ObjectConfig , Validator } from ' @objectql/core' ;
137+ import { ValidationContext } from ' @objectql/types' ;
138+
139+ // Define object with validation rules
140+ const projectObject: ObjectConfig = {
141+ name: ' project' ,
142+ fields: {
143+ name: {
144+ type: ' text' ,
145+ required: true ,
146+ validation: {
147+ min_length: 3 ,
148+ max_length: 100 ,
149+ pattern: ' ^[a-zA-Z0-9\\ s]+$'
150+ }
151+ },
152+ email: {
153+ type: ' email' ,
154+ validation: {
155+ format: ' email' ,
156+ message: ' Please enter a valid email address'
157+ }
158+ },
159+ start_date: { type: ' date' },
160+ end_date: { type: ' date' },
161+ status: {
162+ type: ' select' ,
163+ options: [
164+ { label: ' Planning' , value: ' planning' },
165+ { label: ' Active' , value: ' active' },
166+ { label: ' Completed' , value: ' completed' }
167+ ]
168+ }
169+ },
170+ validation: {
171+ rules: [
172+ // Cross-field validation
173+ {
174+ name: ' valid_date_range' ,
175+ type: ' cross_field' ,
176+ rule: {
177+ field: ' end_date' ,
178+ operator: ' >=' ,
179+ compare_to: ' start_date'
180+ },
181+ message: ' End date must be on or after start date' ,
182+ error_code: ' INVALID_DATE_RANGE'
183+ },
184+ // State machine validation
185+ {
186+ name: ' status_transition' ,
187+ type: ' state_machine' ,
188+ field: ' status' ,
189+ transitions: {
190+ planning: { allowed_next: [' active' , ' cancelled' ] },
191+ active: { allowed_next: [' completed' , ' cancelled' ] },
192+ completed: { allowed_next: [], is_terminal: true }
193+ },
194+ message: ' Invalid status transition'
195+ }
196+ ]
197+ }
198+ };
199+
200+ // Execute validation programmatically
201+ const validator = new Validator ({ language: ' en' });
202+
203+ const result = await validator .validate (
204+ projectObject .validation .rules ,
205+ {
206+ record: { start_date: ' 2024-01-01' , end_date: ' 2023-12-31' },
207+ operation: ' create'
208+ }
209+ );
210+
211+ if (! result .valid ) {
212+ console .log (' Validation errors:' , result .errors );
213+ }
214+ ```
215+
216+ ** Supported validation types:**
217+ - ** Field-level** : required, email, URL, min/max, length, pattern
218+ - ** Cross-field** : compare fields with operators (=, !=, >, >=, <, <=, in, contains, etc.)
219+ - ** State machine** : enforce valid state transitions
220+ - ** Severity levels** : error, warning, info
221+ - ** I18n** : multi-language error messages with fallback
222+
122223## 🎨 Web Console
123224
124225ObjectQL includes a beautiful web-based admin console for database management.
@@ -211,6 +312,33 @@ aggregations:
211312
212313See [Visual Reporting Guide](./docs/guide/visual-reporting.md) for complete documentation.
213314
315+ ## 📡 API Reference
316+
317+ ObjectQL provides **multiple API styles** to suit different use cases:
318+
319+ * **[Complete API Reference](./docs/api/README.md)** - Comprehensive guide to all API endpoints
320+ * **[JSON-RPC API](./docs/api/README.md#json-rpc-style-api)** - Universal protocol for all operations
321+ * **[REST API](./docs/api/README.md#rest-style-api)** - Traditional REST endpoints
322+ * **[Metadata API](./docs/api/README.md#metadata-api)** - Runtime schema discovery and introspection
323+ * **[Authentication Guide](./docs/api/authentication.md)** - Securing your APIs with JWT, API keys, and more
324+
325+ **Quick Example:**
326+ ` ` ` bash
327+ # Create a record via JSON-RPC
328+ curl -X POST http://localhost:3000/api/objectql \
329+ -H "Content-Type : application/json" \
330+ -d '{
331+ " op " : " create" ,
332+ " object " : " tasks" ,
333+ " args " : {
334+ " name " : " Complete API documentation" ,
335+ " priority " : " high"
336+ }
337+ }'
338+ ```
339+
340+ See the [ API Reference] ( ./docs/api/README.md ) for complete documentation with examples.
341+
214342## 🛣 Roadmap
215343
216344* [ ] ** Phase 1: Core Protocol:** Define stable ` UnifiedQuery ` types and AST parser.
0 commit comments