@objectstack/driver-memory 2.0.6 → 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.
- package/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +8 -0
- package/dist/index.d.mts +98 -11
- package/dist/index.d.ts +98 -11
- package/dist/index.js +347 -159
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +347 -159
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
- package/src/index.ts +2 -13
- package/src/memory-driver.test.ts +473 -1
- package/src/memory-driver.ts +413 -82
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @objectstack/driver-memory@2.0.
|
|
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
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
[34mCLI[39m Cleaning output folder
|
|
11
11
|
[34mESM[39m Build start
|
|
12
12
|
[34mCJS[39m Build start
|
|
13
|
-
[32mESM[39m [1mdist/index.mjs [22m[
|
|
14
|
-
[32mESM[39m [1mdist/index.mjs.map [22m[
|
|
15
|
-
[32mESM[39m ⚡️ Build success in
|
|
16
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
17
|
-
[32mCJS[39m [1mdist/index.js.map [22m[
|
|
18
|
-
[32mCJS[39m ⚡️ Build success in
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m24.12 KB[39m
|
|
14
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m51.46 KB[39m
|
|
15
|
+
[32mESM[39m ⚡️ Build success in 86ms
|
|
16
|
+
[32mCJS[39m [1mdist/index.js [22m[32m25.22 KB[39m
|
|
17
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m51.50 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 89ms
|
|
19
19
|
[34mDTS[39m Build start
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 10233ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m6.37 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m6.37 KB[39m
|
package/CHANGELOG.md
CHANGED
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
|
-
*
|
|
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
|
-
*
|
|
8
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
8
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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 };
|