@objectstack/driver-memory 3.2.9 → 3.3.1

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,28 @@ 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
+ batchSchemaSync: false,
147
+ migrations: false,
148
+ indexes: false,
149
+
150
+ // Performance & Optimization
151
+ connectionPooling: false,
152
+ preparedStatements: false,
153
+ queryCache: false,
128
154
  };
129
155
 
130
156
  /**
@@ -230,7 +256,7 @@ export class InMemoryDriver implements DriverInterface {
230
256
  // CRUD
231
257
  // ===================================
232
258
 
233
- async find(object: string, query: QueryInput, options?: DriverOptions) {
259
+ async find(object: string, query: QueryAST, options?: DriverOptions) {
234
260
  this.logger.debug('Find operation', { object, query });
235
261
 
236
262
  const table = this.getTable(object);
@@ -275,7 +301,7 @@ export class InMemoryDriver implements DriverInterface {
275
301
  return results;
276
302
  }
277
303
 
278
- async *findStream(object: string, query: QueryInput, options?: DriverOptions) {
304
+ async *findStream(object: string, query: QueryAST, options?: DriverOptions) {
279
305
  this.logger.debug('FindStream operation', { object });
280
306
 
281
307
  const results = await this.find(object, query, options);
@@ -284,7 +310,7 @@ export class InMemoryDriver implements DriverInterface {
284
310
  }
285
311
  }
286
312
 
287
- async findOne(object: string, query: QueryInput, options?: DriverOptions) {
313
+ async findOne(object: string, query: QueryAST, options?: DriverOptions) {
288
314
  this.logger.debug('FindOne operation', { object, query });
289
315
 
290
316
  const results = await this.find(object, { ...query, limit: 1 }, options);
@@ -381,7 +407,7 @@ export class InMemoryDriver implements DriverInterface {
381
407
  return true;
382
408
  }
383
409
 
384
- async count(object: string, query?: QueryInput, options?: DriverOptions) {
410
+ async count(object: string, query?: QueryAST, options?: DriverOptions) {
385
411
  let records = this.getTable(object);
386
412
  if (query?.where) {
387
413
  const mongoQuery = this.convertToMongoQuery(query.where);
@@ -406,7 +432,7 @@ export class InMemoryDriver implements DriverInterface {
406
432
  return results;
407
433
  }
408
434
 
409
- async updateMany(object: string, query: QueryInput, data: Record<string, any>, options?: DriverOptions) {
435
+ async updateMany(object: string, query: QueryAST, data: Record<string, any>, options?: DriverOptions): Promise<number> {
410
436
  this.logger.debug('UpdateMany operation', { object, query });
411
437
 
412
438
  const table = this.getTable(object);
@@ -436,10 +462,10 @@ export class InMemoryDriver implements DriverInterface {
436
462
 
437
463
  if (count > 0) this.markDirty();
438
464
  this.logger.debug('UpdateMany completed', { object, count });
439
- return { count };
465
+ return count;
440
466
  }
441
467
 
442
- async deleteMany(object: string, query: QueryInput, options?: DriverOptions) {
468
+ async deleteMany(object: string, query: QueryAST, options?: DriverOptions): Promise<number> {
443
469
  this.logger.debug('DeleteMany operation', { object, query });
444
470
 
445
471
  const table = this.getTable(object);
@@ -464,7 +490,7 @@ export class InMemoryDriver implements DriverInterface {
464
490
  const count = initialLength - this.db[object].length;
465
491
  if (count > 0) this.markDirty();
466
492
  this.logger.debug('DeleteMany completed', { object, count });
467
- return { count };
493
+ return count;
468
494
  }
469
495
 
470
496
  // Compatibility aliases