@objectstack/driver-memory 2.0.5 → 2.0.7

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @objectstack/driver-memory@2.0.5 build /home/runner/work/spec/spec/packages/plugins/driver-memory
2
+ > @objectstack/driver-memory@2.0.7 build /home/runner/work/spec/spec/packages/plugins/driver-memory
3
3
  > tsup --config ../../../tsup.config.ts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -10,13 +10,13 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  CJS Build start
13
- CJS dist/index.js 17.84 KB
14
- CJS dist/index.js.map 35.78 KB
15
- CJS ⚡️ Build success in 101ms
16
- ESM dist/index.mjs 16.81 KB
17
- ESM dist/index.mjs.map 35.73 KB
18
- ESM ⚡️ Build success in 101ms
13
+ ESM dist/index.mjs 24.12 KB
14
+ ESM dist/index.mjs.map 51.46 KB
15
+ ESM ⚡️ Build success in 86ms
16
+ CJS dist/index.js 25.22 KB
17
+ CJS dist/index.js.map 51.50 KB
18
+ CJS ⚡️ Build success in 89ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 9714ms
21
- DTS dist/index.d.mts 3.24 KB
22
- DTS dist/index.d.ts 3.24 KB
20
+ DTS ⚡️ Build success in 10233ms
21
+ DTS dist/index.d.mts 6.37 KB
22
+ DTS dist/index.d.ts 6.37 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @objectstack/driver-memory
2
2
 
3
+ ## 2.0.7
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @objectstack/spec@2.0.7
9
+ - @objectstack/core@2.0.7
10
+
11
+ ## 2.0.6
12
+
13
+ ### Patch Changes
14
+
15
+ - Patch release for maintenance and stability improvements
16
+ - Updated dependencies
17
+ - @objectstack/spec@2.0.6
18
+ - @objectstack/core@2.0.6
19
+
3
20
  ## 2.0.5
4
21
 
5
22
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,11 +1,33 @@
1
1
  import { QueryInput, DriverOptions } from '@objectstack/spec/data';
2
- import { DriverInterface } from '@objectstack/core';
2
+ import { DriverInterface, Logger } from '@objectstack/core';
3
3
 
4
4
  /**
5
- * Example: In-Memory Driver
5
+ * Configuration options for the InMemory driver.
6
+ * Aligned with @objectstack/spec MemoryConfigSchema.
7
+ */
8
+ interface InMemoryDriverConfig {
9
+ /** Optional: Initial data to populate the store */
10
+ initialData?: Record<string, Record<string, unknown>[]>;
11
+ /** Optional: Enable strict mode (throw on missing records) */
12
+ strictMode?: boolean;
13
+ /** Optional: Logger instance */
14
+ logger?: Logger;
15
+ }
16
+ /**
17
+ * In-Memory Driver for ObjectStack
18
+ *
19
+ * A production-ready implementation of the ObjectStack Driver Protocol
20
+ * powered by Mingo — a MongoDB-compatible query and aggregation engine.
6
21
  *
7
- * A minimal reference implementation of the ObjectStack Driver Protocol.
8
- * This driver stores data in a simple JavaScript object (Heap).
22
+ * Features:
23
+ * - MongoDB-compatible query engine (Mingo) for filtering, projection, aggregation
24
+ * - Full CRUD and bulk operations
25
+ * - Aggregation pipeline support ($match, $group, $sort, $project, $unwind, etc.)
26
+ * - Snapshot-based transactions (begin/commit/rollback)
27
+ * - Field projection and distinct values
28
+ * - Strict mode and initial data loading
29
+ *
30
+ * Reference: objectql/packages/drivers/memory
9
31
  */
10
32
  declare class InMemoryDriver implements DriverInterface {
11
33
  name: string;
@@ -13,7 +35,9 @@ declare class InMemoryDriver implements DriverInterface {
13
35
  version: string;
14
36
  private config;
15
37
  private logger;
16
- constructor(config?: any);
38
+ private idCounters;
39
+ private transactions;
40
+ constructor(config?: InMemoryDriverConfig);
17
41
  install(ctx: any): void;
18
42
  supports: {
19
43
  transactions: boolean;
@@ -66,14 +90,77 @@ declare class InMemoryDriver implements DriverInterface {
66
90
  data: Record<string, any>;
67
91
  }[], options?: DriverOptions): Promise<any[]>;
68
92
  bulkDelete(object: string, ids: (string | number)[], options?: DriverOptions): Promise<void>;
69
- syncSchema(object: string, schema: any, options?: DriverOptions): Promise<void>;
70
- dropTable(object: string, options?: DriverOptions): Promise<void>;
71
- beginTransaction(): Promise<void>;
72
- commit(): Promise<void>;
73
- rollback(): Promise<void>;
93
+ beginTransaction(): Promise<{
94
+ id: string;
95
+ }>;
96
+ commit(txHandle?: unknown): Promise<void>;
97
+ rollback(txHandle?: unknown): Promise<void>;
98
+ /**
99
+ * Remove all data from the store.
100
+ */
101
+ clear(): Promise<void>;
102
+ /**
103
+ * Get total number of records across all tables.
104
+ */
105
+ getSize(): number;
106
+ /**
107
+ * Get distinct values for a field, optionally filtered.
108
+ */
109
+ distinct(object: string, field: string, query?: QueryInput): Promise<any[]>;
110
+ /**
111
+ * Execute a MongoDB-style aggregation pipeline using Mingo.
112
+ *
113
+ * Supports all standard MongoDB pipeline stages:
114
+ * - $match, $group, $sort, $project, $unwind, $limit, $skip
115
+ * - $addFields, $replaceRoot, $lookup (limited), $count
116
+ * - Accumulator operators: $sum, $avg, $min, $max, $first, $last, $push, $addToSet
117
+ *
118
+ * @example
119
+ * // Group by status and count
120
+ * const results = await driver.aggregate('orders', [
121
+ * { $match: { status: 'completed' } },
122
+ * { $group: { _id: '$customer', totalAmount: { $sum: '$amount' } } }
123
+ * ]);
124
+ *
125
+ * @example
126
+ * // Calculate average with filter
127
+ * const results = await driver.aggregate('products', [
128
+ * { $match: { category: 'electronics' } },
129
+ * { $group: { _id: null, avgPrice: { $avg: '$price' } } }
130
+ * ]);
131
+ */
132
+ aggregate(object: string, pipeline: Record<string, any>[], options?: DriverOptions): Promise<any[]>;
133
+ /**
134
+ * Convert ObjectQL filter format to MongoDB query format for Mingo.
135
+ *
136
+ * Supports:
137
+ * 1. AST Comparison Node: { type: 'comparison', field, operator, value }
138
+ * 2. AST Logical Node: { type: 'logical', operator: 'and'|'or', conditions: [...] }
139
+ * 3. Legacy Array Format: [['field', 'op', value], 'and', ['field2', 'op', value2]]
140
+ * 4. MongoDB Format: { field: value } or { field: { $eq: value } } (passthrough)
141
+ */
142
+ private convertToMongoQuery;
143
+ /**
144
+ * Convert a single ObjectQL condition to MongoDB operator format.
145
+ */
146
+ private convertConditionToMongo;
147
+ /**
148
+ * Escape special regex characters for safe literal matching.
149
+ */
150
+ private escapeRegex;
74
151
  private performAggregation;
75
152
  private computeAggregate;
76
153
  private setValueByPath;
154
+ syncSchema(object: string, schema: any, options?: DriverOptions): Promise<void>;
155
+ dropTable(object: string, options?: DriverOptions): Promise<void>;
156
+ /**
157
+ * Apply manual sorting (Mingo sort has CJS build issues).
158
+ */
159
+ private applySort;
160
+ /**
161
+ * Project specific fields from a record.
162
+ */
163
+ private projectFields;
77
164
  private getTable;
78
165
  private generateId;
79
166
  }
@@ -84,4 +171,4 @@ declare const _default: {
84
171
  onEnable: (context: any) => Promise<void>;
85
172
  };
86
173
 
87
- export { InMemoryDriver, _default as default };
174
+ export { InMemoryDriver, type InMemoryDriverConfig, _default as default };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,33 @@
1
1
  import { QueryInput, DriverOptions } from '@objectstack/spec/data';
2
- import { DriverInterface } from '@objectstack/core';
2
+ import { DriverInterface, Logger } from '@objectstack/core';
3
3
 
4
4
  /**
5
- * Example: In-Memory Driver
5
+ * Configuration options for the InMemory driver.
6
+ * Aligned with @objectstack/spec MemoryConfigSchema.
7
+ */
8
+ interface InMemoryDriverConfig {
9
+ /** Optional: Initial data to populate the store */
10
+ initialData?: Record<string, Record<string, unknown>[]>;
11
+ /** Optional: Enable strict mode (throw on missing records) */
12
+ strictMode?: boolean;
13
+ /** Optional: Logger instance */
14
+ logger?: Logger;
15
+ }
16
+ /**
17
+ * In-Memory Driver for ObjectStack
18
+ *
19
+ * A production-ready implementation of the ObjectStack Driver Protocol
20
+ * powered by Mingo — a MongoDB-compatible query and aggregation engine.
6
21
  *
7
- * A minimal reference implementation of the ObjectStack Driver Protocol.
8
- * This driver stores data in a simple JavaScript object (Heap).
22
+ * Features:
23
+ * - MongoDB-compatible query engine (Mingo) for filtering, projection, aggregation
24
+ * - Full CRUD and bulk operations
25
+ * - Aggregation pipeline support ($match, $group, $sort, $project, $unwind, etc.)
26
+ * - Snapshot-based transactions (begin/commit/rollback)
27
+ * - Field projection and distinct values
28
+ * - Strict mode and initial data loading
29
+ *
30
+ * Reference: objectql/packages/drivers/memory
9
31
  */
10
32
  declare class InMemoryDriver implements DriverInterface {
11
33
  name: string;
@@ -13,7 +35,9 @@ declare class InMemoryDriver implements DriverInterface {
13
35
  version: string;
14
36
  private config;
15
37
  private logger;
16
- constructor(config?: any);
38
+ private idCounters;
39
+ private transactions;
40
+ constructor(config?: InMemoryDriverConfig);
17
41
  install(ctx: any): void;
18
42
  supports: {
19
43
  transactions: boolean;
@@ -66,14 +90,77 @@ declare class InMemoryDriver implements DriverInterface {
66
90
  data: Record<string, any>;
67
91
  }[], options?: DriverOptions): Promise<any[]>;
68
92
  bulkDelete(object: string, ids: (string | number)[], options?: DriverOptions): Promise<void>;
69
- syncSchema(object: string, schema: any, options?: DriverOptions): Promise<void>;
70
- dropTable(object: string, options?: DriverOptions): Promise<void>;
71
- beginTransaction(): Promise<void>;
72
- commit(): Promise<void>;
73
- rollback(): Promise<void>;
93
+ beginTransaction(): Promise<{
94
+ id: string;
95
+ }>;
96
+ commit(txHandle?: unknown): Promise<void>;
97
+ rollback(txHandle?: unknown): Promise<void>;
98
+ /**
99
+ * Remove all data from the store.
100
+ */
101
+ clear(): Promise<void>;
102
+ /**
103
+ * Get total number of records across all tables.
104
+ */
105
+ getSize(): number;
106
+ /**
107
+ * Get distinct values for a field, optionally filtered.
108
+ */
109
+ distinct(object: string, field: string, query?: QueryInput): Promise<any[]>;
110
+ /**
111
+ * Execute a MongoDB-style aggregation pipeline using Mingo.
112
+ *
113
+ * Supports all standard MongoDB pipeline stages:
114
+ * - $match, $group, $sort, $project, $unwind, $limit, $skip
115
+ * - $addFields, $replaceRoot, $lookup (limited), $count
116
+ * - Accumulator operators: $sum, $avg, $min, $max, $first, $last, $push, $addToSet
117
+ *
118
+ * @example
119
+ * // Group by status and count
120
+ * const results = await driver.aggregate('orders', [
121
+ * { $match: { status: 'completed' } },
122
+ * { $group: { _id: '$customer', totalAmount: { $sum: '$amount' } } }
123
+ * ]);
124
+ *
125
+ * @example
126
+ * // Calculate average with filter
127
+ * const results = await driver.aggregate('products', [
128
+ * { $match: { category: 'electronics' } },
129
+ * { $group: { _id: null, avgPrice: { $avg: '$price' } } }
130
+ * ]);
131
+ */
132
+ aggregate(object: string, pipeline: Record<string, any>[], options?: DriverOptions): Promise<any[]>;
133
+ /**
134
+ * Convert ObjectQL filter format to MongoDB query format for Mingo.
135
+ *
136
+ * Supports:
137
+ * 1. AST Comparison Node: { type: 'comparison', field, operator, value }
138
+ * 2. AST Logical Node: { type: 'logical', operator: 'and'|'or', conditions: [...] }
139
+ * 3. Legacy Array Format: [['field', 'op', value], 'and', ['field2', 'op', value2]]
140
+ * 4. MongoDB Format: { field: value } or { field: { $eq: value } } (passthrough)
141
+ */
142
+ private convertToMongoQuery;
143
+ /**
144
+ * Convert a single ObjectQL condition to MongoDB operator format.
145
+ */
146
+ private convertConditionToMongo;
147
+ /**
148
+ * Escape special regex characters for safe literal matching.
149
+ */
150
+ private escapeRegex;
74
151
  private performAggregation;
75
152
  private computeAggregate;
76
153
  private setValueByPath;
154
+ syncSchema(object: string, schema: any, options?: DriverOptions): Promise<void>;
155
+ dropTable(object: string, options?: DriverOptions): Promise<void>;
156
+ /**
157
+ * Apply manual sorting (Mingo sort has CJS build issues).
158
+ */
159
+ private applySort;
160
+ /**
161
+ * Project specific fields from a record.
162
+ */
163
+ private projectFields;
77
164
  private getTable;
78
165
  private generateId;
79
166
  }
@@ -84,4 +171,4 @@ declare const _default: {
84
171
  onEnable: (context: any) => Promise<void>;
85
172
  };
86
173
 
87
- export { InMemoryDriver, _default as default };
174
+ export { InMemoryDriver, type InMemoryDriverConfig, _default as default };