@objectstack/driver-memory 3.2.9 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -11,6 +11,8 @@ export { LocalStoragePersistenceAdapter } from './persistence/local-storage-adap
11
11
  export { MemoryAnalyticsService } from './memory-analytics.js';
12
12
  export type { MemoryAnalyticsConfig } from './memory-analytics.js';
13
13
 
14
+ export { InMemoryStrategy } from './in-memory-strategy.js';
15
+
14
16
  export default {
15
17
  id: 'com.objectstack.driver.memory',
16
18
  version: '1.0.0',
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
2
2
 
3
3
  import type { QueryAST, QueryInput, DriverOptions } from '@objectstack/spec/data';
4
- import type { DriverInterface } from '@objectstack/core';
4
+ import type { IDataDriver } from '@objectstack/spec/contracts';
5
5
  import { Logger, createLogger } from '@objectstack/core';
6
6
  import { Query, Aggregator } from 'mingo';
7
7
  import { getValueByPath } from './memory-matcher.js';
@@ -79,10 +79,10 @@ interface MemoryTransaction {
79
79
  *
80
80
  * Reference: objectql/packages/drivers/memory
81
81
  */
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';
84
84
  type = 'driver';
85
- version = '1.0.0';
85
+ readonly version = '1.0.0';
86
86
  private config: InMemoryDriverConfig;
87
87
  private logger: Logger;
88
88
  private idCounters: Map<string, number> = new Map();
@@ -106,9 +106,21 @@ export class InMemoryDriver implements DriverInterface {
106
106
  }
107
107
  }
108
108
 
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
+
110
121
  // Transaction & Connection Management
111
122
  transactions: true, // Snapshot-based transactions
123
+ savepoints: false,
112
124
 
113
125
  // Query Operations
114
126
  queryFilters: true, // Implemented via memory-matcher
@@ -117,14 +129,27 @@ export class InMemoryDriver implements DriverInterface {
117
129
  queryPagination: true, // Implemented
118
130
  queryWindowFunctions: false, // @planned: Window functions (ROW_NUMBER, RANK, etc.)
119
131
  querySubqueries: false, // @planned: Subquery execution
132
+ queryCTE: false,
120
133
  joins: false, // @planned: In-memory join operations
121
134
 
122
135
  // Advanced Features
123
136
  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()
126
140
  jsonFields: true, // Native JS object support
127
141
  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,
128
153
  };
129
154
 
130
155
  /**
@@ -230,7 +255,7 @@ export class InMemoryDriver implements DriverInterface {
230
255
  // CRUD
231
256
  // ===================================
232
257
 
233
- async find(object: string, query: QueryInput, options?: DriverOptions) {
258
+ async find(object: string, query: QueryAST, options?: DriverOptions) {
234
259
  this.logger.debug('Find operation', { object, query });
235
260
 
236
261
  const table = this.getTable(object);
@@ -275,7 +300,7 @@ export class InMemoryDriver implements DriverInterface {
275
300
  return results;
276
301
  }
277
302
 
278
- async *findStream(object: string, query: QueryInput, options?: DriverOptions) {
303
+ async *findStream(object: string, query: QueryAST, options?: DriverOptions) {
279
304
  this.logger.debug('FindStream operation', { object });
280
305
 
281
306
  const results = await this.find(object, query, options);
@@ -284,7 +309,7 @@ export class InMemoryDriver implements DriverInterface {
284
309
  }
285
310
  }
286
311
 
287
- async findOne(object: string, query: QueryInput, options?: DriverOptions) {
312
+ async findOne(object: string, query: QueryAST, options?: DriverOptions) {
288
313
  this.logger.debug('FindOne operation', { object, query });
289
314
 
290
315
  const results = await this.find(object, { ...query, limit: 1 }, options);
@@ -381,7 +406,7 @@ export class InMemoryDriver implements DriverInterface {
381
406
  return true;
382
407
  }
383
408
 
384
- async count(object: string, query?: QueryInput, options?: DriverOptions) {
409
+ async count(object: string, query?: QueryAST, options?: DriverOptions) {
385
410
  let records = this.getTable(object);
386
411
  if (query?.where) {
387
412
  const mongoQuery = this.convertToMongoQuery(query.where);
@@ -406,7 +431,7 @@ export class InMemoryDriver implements DriverInterface {
406
431
  return results;
407
432
  }
408
433
 
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> {
410
435
  this.logger.debug('UpdateMany operation', { object, query });
411
436
 
412
437
  const table = this.getTable(object);
@@ -436,10 +461,10 @@ export class InMemoryDriver implements DriverInterface {
436
461
 
437
462
  if (count > 0) this.markDirty();
438
463
  this.logger.debug('UpdateMany completed', { object, count });
439
- return { count };
464
+ return count;
440
465
  }
441
466
 
442
- async deleteMany(object: string, query: QueryInput, options?: DriverOptions) {
467
+ async deleteMany(object: string, query: QueryAST, options?: DriverOptions): Promise<number> {
443
468
  this.logger.debug('DeleteMany operation', { object, query });
444
469
 
445
470
  const table = this.getTable(object);
@@ -464,7 +489,7 @@ export class InMemoryDriver implements DriverInterface {
464
489
  const count = initialLength - this.db[object].length;
465
490
  if (count > 0) this.markDirty();
466
491
  this.logger.debug('DeleteMany completed', { object, count });
467
- return { count };
492
+ return count;
468
493
  }
469
494
 
470
495
  // Compatibility aliases