@objectstack/driver-memory 4.0.4 → 4.0.5
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/README.md +89 -8
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +31 -6
- package/.turbo/turbo-build.log +0 -22
- package/CHANGELOG.md +0 -617
- package/objectstack.config.ts +0 -260
- package/src/in-memory-strategy.ts +0 -47
- package/src/index.ts +0 -32
- package/src/memory-analytics.test.ts +0 -346
- package/src/memory-analytics.ts +0 -518
- package/src/memory-driver.test.ts +0 -722
- package/src/memory-driver.ts +0 -1206
- package/src/memory-matcher.ts +0 -177
- package/src/persistence/file-adapter.ts +0 -103
- package/src/persistence/index.ts +0 -4
- package/src/persistence/local-storage-adapter.ts +0 -60
- package/src/persistence/persistence.test.ts +0 -298
- package/tsconfig.json +0 -27
- package/vitest.config.ts +0 -22
package/README.md
CHANGED
|
@@ -1,21 +1,102 @@
|
|
|
1
1
|
# @objectstack/driver-memory
|
|
2
2
|
|
|
3
|
-
In-
|
|
3
|
+
> In-memory ObjectQL driver for ObjectStack — zero-config storage for development, unit tests, Storybook, and browser MSW mocks.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@objectstack/driver-memory)
|
|
6
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
- **Sorting & Pagination**: Full support for `sort`, `skip`, `limit`.
|
|
9
|
-
- **Zero Config**: Perfect for prototyping, testing, and the **MSW Browser Mock**.
|
|
10
|
-
- **Stateful**: Preserves data in memory during the session.
|
|
8
|
+
## Overview
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
Implements the `IDataEngine` contract against in-memory `Map`-backed tables. Supports the full ObjectQL surface: MongoDB-style operators (`$eq`, `$ne`, `$gt`, `$lt`, `$gte`, `$lte`, `$in`, `$nin`, `$and`, `$or`, `$not`), sorting, pagination, aggregations, and joins. Optional persistence adapters serialize state to disk (Node) or `localStorage` (browser).
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @objectstack/driver-memory
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { ObjectKernel } from '@objectstack/core';
|
|
22
|
+
import memoryPlugin from '@objectstack/driver-memory';
|
|
23
|
+
|
|
24
|
+
const kernel = new ObjectKernel();
|
|
25
|
+
kernel.use(memoryPlugin); // default plugin
|
|
26
|
+
await kernel.bootstrap();
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Direct instantiation
|
|
13
30
|
|
|
14
31
|
```typescript
|
|
15
32
|
import { InMemoryDriver } from '@objectstack/driver-memory';
|
|
16
33
|
|
|
17
34
|
const driver = new InMemoryDriver();
|
|
18
35
|
await driver.connect();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### With filesystem persistence (Node)
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { InMemoryDriver, FileSystemPersistenceAdapter } from '@objectstack/driver-memory';
|
|
19
42
|
|
|
20
|
-
|
|
43
|
+
const driver = new InMemoryDriver({
|
|
44
|
+
persistence: new FileSystemPersistenceAdapter('./data/snapshot.json'),
|
|
45
|
+
});
|
|
46
|
+
await driver.connect();
|
|
21
47
|
```
|
|
48
|
+
|
|
49
|
+
### With `localStorage` persistence (browser)
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { InMemoryDriver, LocalStoragePersistenceAdapter } from '@objectstack/driver-memory';
|
|
53
|
+
|
|
54
|
+
const driver = new InMemoryDriver({
|
|
55
|
+
persistence: new LocalStoragePersistenceAdapter('objectstack:dev'),
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Key Exports
|
|
60
|
+
|
|
61
|
+
| Export | Kind | Description |
|
|
62
|
+
|:---|:---|:---|
|
|
63
|
+
| `default` | kernel plugin | Drop-in plugin. |
|
|
64
|
+
| `InMemoryDriver` | class | Driver instance for direct use. |
|
|
65
|
+
| `InMemoryStrategy` | class | Query execution strategy used by ObjectQL. |
|
|
66
|
+
| `FileSystemPersistenceAdapter` | class | Node-only persistence. |
|
|
67
|
+
| `LocalStoragePersistenceAdapter` | class | Browser-only persistence. |
|
|
68
|
+
| `MemoryAnalyticsService` | class | Adds analytics aggregations backed by memory store. |
|
|
69
|
+
| `InMemoryDriverConfig`, `PersistenceAdapterInterface`, `MemoryAnalyticsConfig` | types | Configuration shapes. |
|
|
70
|
+
|
|
71
|
+
## Configuration
|
|
72
|
+
|
|
73
|
+
| Option | Type | Default | Notes |
|
|
74
|
+
|:---|:---|:---|:---|
|
|
75
|
+
| `persistence` | `PersistenceAdapterInterface?` | `undefined` | Optional snapshot store. |
|
|
76
|
+
| `seed` | `Record<string, any[]>?` | `{}` | Initial rows keyed by object name. |
|
|
77
|
+
| `idStrategy` | `'uuid' \| 'auto'` | `'uuid'` | ID generation strategy. |
|
|
78
|
+
|
|
79
|
+
## When to use
|
|
80
|
+
|
|
81
|
+
- ✅ Development, unit tests, CI, Storybook.
|
|
82
|
+
- ✅ Browser-only demos pairing with [`@objectstack/plugin-msw`](../plugin-msw).
|
|
83
|
+
|
|
84
|
+
## When not to use
|
|
85
|
+
|
|
86
|
+
- ❌ Production — data is lost on restart without a persistence adapter; durability/concurrency guarantees are minimal.
|
|
87
|
+
- ❌ Multi-process deployments.
|
|
88
|
+
|
|
89
|
+
## Related Packages
|
|
90
|
+
|
|
91
|
+
- [`@objectstack/objectql`](../../objectql) — query engine.
|
|
92
|
+
- [`@objectstack/driver-sql`](../driver-sql), [`@objectstack/driver-turso`](../driver-turso) — production drivers.
|
|
93
|
+
- [`@objectstack/plugin-msw`](../plugin-msw) — browser mock API.
|
|
94
|
+
|
|
95
|
+
## Links
|
|
96
|
+
|
|
97
|
+
- 📖 Docs: <https://objectstack.ai/docs>
|
|
98
|
+
- 📚 API Reference: <https://objectstack.ai/docs/references>
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
Apache-2.0 © ObjectStack
|
package/dist/index.js
CHANGED
|
@@ -1416,7 +1416,20 @@ var MemoryAnalyticsService = class {
|
|
|
1416
1416
|
resolveMeasure(cube, measureName) {
|
|
1417
1417
|
const parts = measureName.split(".");
|
|
1418
1418
|
const fieldName = parts.length > 1 ? parts[1] : parts[0];
|
|
1419
|
-
|
|
1419
|
+
const direct = cube.measures[fieldName];
|
|
1420
|
+
if (direct) return direct;
|
|
1421
|
+
const aggTypes = ["count", "sum", "avg", "min", "max", "count_distinct"];
|
|
1422
|
+
for (const type of aggTypes) {
|
|
1423
|
+
const suffix = `_${type}`;
|
|
1424
|
+
if (fieldName.endsWith(suffix)) {
|
|
1425
|
+
const baseField = fieldName.slice(0, -suffix.length);
|
|
1426
|
+
const candidate = cube.measures[baseField];
|
|
1427
|
+
if (candidate && candidate.type === type) {
|
|
1428
|
+
return candidate;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
return void 0;
|
|
1420
1433
|
}
|
|
1421
1434
|
resolveDimension(cube, dimensionName) {
|
|
1422
1435
|
const parts = dimensionName.split(".");
|