11// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22
33import type { QueryAST , QueryInput , DriverOptions } from '@objectstack/spec/data' ;
4- import type { DriverInterface } from '@objectstack/core ' ;
4+ import type { IDataDriver } from '@objectstack/spec/contracts ' ;
55import { Logger , createLogger } from '@objectstack/core' ;
66import { Query , Aggregator } from 'mingo' ;
77import { getValueByPath } from './memory-matcher.js' ;
@@ -79,10 +79,10 @@ interface MemoryTransaction {
7979 *
8080 * Reference: objectql/packages/drivers/memory
8181 */
82- export class InMemoryDriver implements DriverInterface {
83- name = 'com.objectstack.driver.memory' ;
82+ export class InMemoryDriver implements IDataDriver {
83+ readonly name = 'com.objectstack.driver.memory' ;
8484 type = 'driver' ;
85- version = '1.0.0' ;
85+ readonly version = '1.0.0' ;
8686 private config : InMemoryDriverConfig ;
8787 private logger : Logger ;
8888 private idCounters : Map < string , number > = new Map ( ) ;
@@ -106,9 +106,21 @@ export class InMemoryDriver implements DriverInterface {
106106 }
107107 }
108108
109- supports = {
109+ readonly supports = {
110+ // Basic CRUD Operations
111+ create : true ,
112+ read : true ,
113+ update : true ,
114+ delete : true ,
115+
116+ // Bulk Operations
117+ bulkCreate : true ,
118+ bulkUpdate : true ,
119+ bulkDelete : true ,
120+
110121 // Transaction & Connection Management
111122 transactions : true , // Snapshot-based transactions
123+ savepoints : false ,
112124
113125 // Query Operations
114126 queryFilters : true , // Implemented via memory-matcher
@@ -117,14 +129,27 @@ export class InMemoryDriver implements DriverInterface {
117129 queryPagination : true , // Implemented
118130 queryWindowFunctions : false , // @planned : Window functions (ROW_NUMBER, RANK, etc.)
119131 querySubqueries : false , // @planned : Subquery execution
132+ queryCTE : false ,
120133 joins : false , // @planned : In-memory join operations
121134
122135 // Advanced Features
123136 fullTextSearch : false , // @planned : Text tokenization + matching
124- vectorSearch : false , // @planned : Cosine similarity search
125- geoSpatial : false , // @planned : Distance/within calculations
137+ jsonQuery : false ,
138+ geospatialQuery : false ,
139+ streaming : true , // Implemented via findStream()
126140 jsonFields : true , // Native JS object support
127141 arrayFields : true , // Native JS array support
142+ vectorSearch : false , // @planned : Cosine similarity search
143+
144+ // Schema Management
145+ schemaSync : true , // Implemented via syncSchema()
146+ migrations : false ,
147+ indexes : false ,
148+
149+ // Performance & Optimization
150+ connectionPooling : false ,
151+ preparedStatements : false ,
152+ queryCache : false ,
128153 } ;
129154
130155 /**
@@ -230,7 +255,7 @@ export class InMemoryDriver implements DriverInterface {
230255 // CRUD
231256 // ===================================
232257
233- async find ( object : string , query : QueryInput , options ?: DriverOptions ) {
258+ async find ( object : string , query : QueryAST , options ?: DriverOptions ) {
234259 this . logger . debug ( 'Find operation' , { object, query } ) ;
235260
236261 const table = this . getTable ( object ) ;
@@ -275,7 +300,7 @@ export class InMemoryDriver implements DriverInterface {
275300 return results ;
276301 }
277302
278- async * findStream ( object : string , query : QueryInput , options ?: DriverOptions ) {
303+ async * findStream ( object : string , query : QueryAST , options ?: DriverOptions ) {
279304 this . logger . debug ( 'FindStream operation' , { object } ) ;
280305
281306 const results = await this . find ( object , query , options ) ;
@@ -284,7 +309,7 @@ export class InMemoryDriver implements DriverInterface {
284309 }
285310 }
286311
287- async findOne ( object : string , query : QueryInput , options ?: DriverOptions ) {
312+ async findOne ( object : string , query : QueryAST , options ?: DriverOptions ) {
288313 this . logger . debug ( 'FindOne operation' , { object, query } ) ;
289314
290315 const results = await this . find ( object , { ...query , limit : 1 } , options ) ;
@@ -381,7 +406,7 @@ export class InMemoryDriver implements DriverInterface {
381406 return true ;
382407 }
383408
384- async count ( object : string , query ?: QueryInput , options ?: DriverOptions ) {
409+ async count ( object : string , query ?: QueryAST , options ?: DriverOptions ) {
385410 let records = this . getTable ( object ) ;
386411 if ( query ?. where ) {
387412 const mongoQuery = this . convertToMongoQuery ( query . where ) ;
@@ -406,7 +431,7 @@ export class InMemoryDriver implements DriverInterface {
406431 return results ;
407432 }
408433
409- async updateMany ( object : string , query : QueryInput , data : Record < string , any > , options ?: DriverOptions ) {
434+ async updateMany ( object : string , query : QueryAST , data : Record < string , any > , options ?: DriverOptions ) : Promise < number > {
410435 this . logger . debug ( 'UpdateMany operation' , { object, query } ) ;
411436
412437 const table = this . getTable ( object ) ;
@@ -436,10 +461,10 @@ export class InMemoryDriver implements DriverInterface {
436461
437462 if ( count > 0 ) this . markDirty ( ) ;
438463 this . logger . debug ( 'UpdateMany completed' , { object, count } ) ;
439- return { count } ;
464+ return count ;
440465 }
441466
442- async deleteMany ( object : string , query : QueryInput , options ?: DriverOptions ) {
467+ async deleteMany ( object : string , query : QueryAST , options ?: DriverOptions ) : Promise < number > {
443468 this . logger . debug ( 'DeleteMany operation' , { object, query } ) ;
444469
445470 const table = this . getTable ( object ) ;
@@ -464,7 +489,7 @@ export class InMemoryDriver implements DriverInterface {
464489 const count = initialLength - this . db [ object ] . length ;
465490 if ( count > 0 ) this . markDirty ( ) ;
466491 this . logger . debug ( 'DeleteMany completed' , { object, count } ) ;
467- return { count } ;
492+ return count ;
468493 }
469494
470495 // Compatibility aliases
0 commit comments