@@ -4,10 +4,10 @@ This document explains the integration of `@objectstack/runtime` and `@objectsta
44
55## Overview
66
7- As of version 3.0.1, ObjectQL core integrates with the latest ObjectStack runtime packages:
7+ As of version 3.0.1, ObjectQL core natively uses the ObjectStack runtime packages:
88
9- - ** @objectstack/spec @0.1.2** : Protocol specification with TypeScript interfaces
10- - ** @objectstack/objectql @0.1.1** : Core ObjectQL engine with basic driver management
9+ - ** @objectstack/spec @0.1.2** : Protocol specification with standard ` DriverInterface `
10+ - ** @objectstack/objectql @0.1.1** : Core ObjectQL engine with driver management
1111- ** @objectstack/runtime @0.1.1** : Runtime kernel with application lifecycle orchestration
1212
1313## Architecture
@@ -16,17 +16,42 @@ As of version 3.0.1, ObjectQL core integrates with the latest ObjectStack runtim
1616
1717```
1818@objectql/core (this package)
19- ├── Extends/complements @objectstack/objectql
20- ├── Uses types from @objectstack/spec
19+ ├── Uses @objectstack/objectql for driver management
20+ ├── Natively uses @objectstack/spec.DriverInterface (no wrapper)
2121└── Re-exports types from @objectstack/runtime
2222```
2323
24+ ### Driver Management Integration
25+
26+ ** Breaking Change (v3.0.1):** The core package now ** natively uses** ` DriverInterface ` from ` @objectstack/spec ` :
27+
28+ ``` typescript
29+ import { ObjectQL } from ' @objectql/core' ;
30+ import type { DriverInterface } from ' @objectstack/spec' ;
31+
32+ // Drivers must implement DriverInterface from @objectstack/spec
33+ const app = new ObjectQL ({
34+ datasources: {
35+ default: myDriver // Must be DriverInterface
36+ }
37+ });
38+
39+ await app .init ();
40+ ```
41+
2442### Type Exports
2543
26- The core package exports types from the runtime packages for API compatibility :
44+ The core package exports types from the ObjectStack packages:
2745
2846``` typescript
29- // Type-only exports to avoid runtime issues
47+ // Driver development types
48+ export type {
49+ DriverInterface ,
50+ DriverOptions ,
51+ QueryAST
52+ } from ' @objectstack/spec' ;
53+
54+ // Runtime integration types
3055export type {
3156 ObjectStackKernel ,
3257 ObjectStackRuntimeProtocol
@@ -51,27 +76,151 @@ The current `ObjectQL` class in this package is a **production-ready, feature-ri
5176- Repository pattern
5277- Formula engine
5378- AI integration
79+ - ** Native driver management via @objectstack/objectql **
5480
5581The ` ObjectQLEngine ` from ` @objectstack/objectql ` is a ** simpler, lightweight** implementation suitable for:
5682
5783- Basic CRUD operations
5884- Simple driver management
5985- Minimal runtime overhead
6086
61- ### Why Type-Only Exports?
87+ ### Driver Management (No Compatibility Layer)
88+
89+ ObjectQL now directly uses drivers conforming to ` @objectstack/spec.DriverInterface ` :
90+
91+ ``` typescript
92+ // In @objectql/core
93+ import { DriverInterface } from ' @objectstack/spec' ;
94+
95+ private datasources : Record < string , DriverInterface > = {};
96+ private stackEngine : ObjectStackEngine ;
97+
98+ constructor (config : ObjectQLConfig ) {
99+ this .stackEngine = new ObjectStackEngine ({});
100+
101+ // Register drivers directly (no wrapping)
102+ for (const [name, driver] of Object .entries (config .datasources )) {
103+ this .stackEngine .registerDriver (driver , name === ' default' );
104+ }
105+ }
106+ ```
107+
108+ ### Simplified Lifecycle
109+
110+ The ObjectStack engine handles all driver lifecycle management:
111+
112+ ``` typescript
113+ async close () {
114+ // ObjectStack engine manages all driver disconnect logic
115+ await this .stackEngine .destroy ();
116+ }
117+ ```
118+
119+ ### Custom Driver Development
120+
121+ To build custom drivers for ObjectStack, implement ` DriverInterface ` from ` @objectstack/spec ` :
122+
123+ ``` typescript
124+ import { DriverInterface , QueryAST } from ' @objectstack/spec' ;
125+
126+ export class MyCustomDriver implements DriverInterface {
127+ name = ' MyDriver' ;
128+ version = ' 1.0.0' ;
129+
130+ async connect() {
131+ // Initialize connection
132+ }
133+
134+ async disconnect() {
135+ // Close connection
136+ }
137+
138+ async find(object : string , query : QueryAST , options ? : any ) {
139+ // Query implementation
140+ return [];
141+ }
142+
143+ async create(object : string , data : any , options ? : any ) {
144+ // Create implementation
145+ return data ;
146+ }
147+
148+ async update(object : string , id : string , data : any , options ? : any ) {
149+ // Update implementation
150+ return data ;
151+ }
152+
153+ async delete(object : string , id : string , options ? : any ) {
154+ // Delete implementation
155+ }
156+ }
157+ ```
158+
159+ Register with ObjectQL:
160+
161+ ``` typescript
162+ import { ObjectQL } from ' @objectql/core' ;
163+ import { MyCustomDriver } from ' ./my-driver' ;
164+
165+ const app = new ObjectQL ({
166+ datasources: {
167+ default: new MyCustomDriver ()
168+ }
169+ });
170+
171+ // Or register dynamically
172+ app .registerDriver (' mydb' , new MyCustomDriver (), false );
173+ ```
174+
175+ ## Breaking Changes
176+
177+ ### v3.0.1: Native DriverInterface Adoption
62178
63- The ` @objectstack/objectql ` package currently has a configuration issue where it points to source files instead of compiled dist files. To avoid runtime errors, we use ** type-only imports** which provide TypeScript type checking without executing the runtime code.
179+ ** What Changed:**
180+ - ` ObjectQLConfig.datasources ` now requires ` Record<string, DriverInterface> ` (from ` @objectstack/spec ` )
181+ - Removed compatibility wrapper for old ` Driver ` type
182+ - ` app.registerDriver() ` now accepts ` DriverInterface ` instead of legacy ` Driver `
183+ - ` app.datasource() ` now returns ` DriverInterface `
184+ - Driver lifecycle is fully managed by ObjectStack engine
185+
186+ ** Migration Guide:**
187+
188+ Old code (deprecated):
189+ ``` typescript
190+ import { Driver } from ' @objectql/types' ;
191+
192+ class MyDriver implements Driver {
193+ // Old Driver interface
194+ }
195+ ```
196+
197+ New code (required):
198+ ``` typescript
199+ import { DriverInterface , QueryAST } from ' @objectstack/spec' ;
200+
201+ class MyDriver implements DriverInterface {
202+ name = ' MyDriver' ;
203+ version = ' 1.0.0' ;
204+
205+ async connect() { }
206+ async disconnect() { }
207+ async find(object : string , query : QueryAST , options ? : any ) { }
208+ async create(object : string , data : any , options ? : any ) { }
209+ async update(object : string , id : string , data : any , options ? : any ) { }
210+ async delete(object : string , id : string , options ? : any ) { }
211+ }
212+ ```
64213
65214## Usage
66215
67216### Using the Full-Featured ObjectQL (Recommended)
68217
69218``` typescript
70219import { ObjectQL } from ' @objectql/core' ;
220+ import { MemoryDriver } from ' @objectql/driver-memory' ;
71221
72222const app = new ObjectQL ({
73- registry: new MetadataRegistry (),
74- datasources: { default: driver }
223+ datasources: { default: new MemoryDriver () }
75224});
76225
77226await app .init ();
@@ -80,42 +229,37 @@ const repo = ctx.object('todo');
80229const items = await repo .find ({});
81230```
82231
83- ### Using Type Definitions from Runtime
232+ ### Using Type Definitions
84233
85234``` typescript
86- import type { ObjectStackKernel , SchemaRegistry } from ' @objectql/core' ;
235+ import type { DriverInterface , QueryAST } from ' @objectql/core' ;
87236
88- // Use types for compile-time checking
89- function processKernel( kernel : ObjectStackKernel ) {
90- // Your code here
237+ // Use types for compile-time checking (type-only import)
238+ function validateQuery( query : QueryAST ) : boolean {
239+ return query . object !== undefined ;
91240}
92241```
93242
94- ## Migration Path
95-
96- If you want to use the simpler ` @objectstack/objectql ` implementation:
97-
98- 1 . Install it directly: ` npm install @objectstack/objectql `
99- 2 . Import from the package: ` import { ObjectQL } from '@objectstack/objectql' `
100- 3 . Note: Ensure the package is properly built before use
101-
102243## Compatibility
103244
104- - ** @objectstack/spec @0.1.2** : Introduces ` searchable ` field requirement on FieldConfig
105- - ** Backward Compatible** : All existing ObjectQL APIs remain unchanged
106- - ** Tests** : 236 tests pass successfully, confirming backward compatibility
245+ - ** @objectstack/spec @0.1.2** : Standard ` DriverInterface ` protocol
246+ - ** @objectstack/objectql @0.1.1** : Provides driver registration and lifecycle management
247+ - ** Breaking Change** : Old ` Driver ` type from ` @objectql/types ` is no longer supported
248+ - ** Tests** : All tests updated to use ` DriverInterface `
107249
108250## Future Plans
109251
110- Once the ` @objectstack/objectql ` package configuration is fixed, we may :
252+ The native integration with ` @objectstack/objectql ` enables :
111253
112- 1 . Use it as a base class for our ObjectQL implementation
113- 2 . Move framework-specific features to plugins
114- 3 . Provide both lightweight and full-featured options
254+ 1 . Standardized driver interface across the ObjectStack ecosystem
255+ 2 . Plugin system for extending driver capabilities
256+ 3 . Unified driver management across multiple packages
257+ 4 . Driver marketplace and discovery
115258
116259## Related Documentation
117260
118261- [ ObjectQL Types] ( ../types/README.md )
119262- [ ObjectQL Platform Node] ( ../platform-node/README.md )
120263- [ @objectstack/spec on npm] ( https://www.npmjs.com/package/@objectstack/spec )
121264- [ @objectstack/runtime on npm] ( https://www.npmjs.com/package/@objectstack/runtime )
265+ - [ @objectstack/objectql on npm] ( https://www.npmjs.com/package/@objectstack/objectql )
0 commit comments