@objectstack/driver-memory 3.0.10 → 3.0.11
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 +126 -1
- package/dist/index.d.ts +126 -1
- package/dist/index.js +304 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +299 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +4 -1
- package/src/memory-driver.test.ts +1 -1
- package/src/memory-driver.ts +179 -0
- package/src/persistence/file-adapter.ts +103 -0
- package/src/persistence/index.ts +4 -0
- package/src/persistence/local-storage-adapter.ts +60 -0
- package/src/persistence/persistence.test.ts +215 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @objectstack/driver-memory@3.0.
|
|
2
|
+
> @objectstack/driver-memory@3.0.11 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[32m47.36 KB[39m
|
|
14
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m94.51 KB[39m
|
|
15
|
+
[32mESM[39m ⚡️ Build success in 173ms
|
|
16
|
+
[32mCJS[39m [1mdist/index.js [22m[32m49.04 KB[39m
|
|
17
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m94.56 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 176ms
|
|
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 15528ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m12.48 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m12.48 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,19 @@ import { QueryInput, DriverOptions, Cube, AnalyticsQuery } from '@objectstack/sp
|
|
|
2
2
|
import { DriverInterface, Logger } from '@objectstack/core';
|
|
3
3
|
import { IAnalyticsService, AnalyticsResult, CubeMeta } from '@objectstack/spec/contracts';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Persistence adapter interface.
|
|
7
|
+
* Matches the PersistenceAdapterSchema contract from @objectstack/spec.
|
|
8
|
+
*/
|
|
9
|
+
interface PersistenceAdapterInterface {
|
|
10
|
+
load(): Promise<Record<string, any[]> | null>;
|
|
11
|
+
save(db: Record<string, any[]>): Promise<void>;
|
|
12
|
+
flush(): Promise<void>;
|
|
13
|
+
/** Optional: Start periodic auto-save (used by FileSystemPersistenceAdapter). */
|
|
14
|
+
startAutoSave?(): void;
|
|
15
|
+
/** Optional: Stop auto-save timer and flush pending writes. */
|
|
16
|
+
stopAutoSave?(): Promise<void>;
|
|
17
|
+
}
|
|
5
18
|
/**
|
|
6
19
|
* Configuration options for the InMemory driver.
|
|
7
20
|
* Aligned with @objectstack/spec MemoryConfigSchema.
|
|
@@ -13,6 +26,24 @@ interface InMemoryDriverConfig {
|
|
|
13
26
|
strictMode?: boolean;
|
|
14
27
|
/** Optional: Logger instance */
|
|
15
28
|
logger?: Logger;
|
|
29
|
+
/**
|
|
30
|
+
* Persistence configuration. Defaults to `'auto'`.
|
|
31
|
+
* - `'auto'` (default) — Auto-detect environment (browser → localStorage, Node.js → file)
|
|
32
|
+
* - `'file'` — File-system persistence with defaults (Node.js only)
|
|
33
|
+
* - `'local'` — localStorage persistence with defaults (Browser only)
|
|
34
|
+
* - `{ type: 'file', path?: string, autoSaveInterval?: number }` — File-system with options
|
|
35
|
+
* - `{ type: 'local', key?: string }` — localStorage with options
|
|
36
|
+
* - `{ type: 'auto', path?: string, key?: string, autoSaveInterval?: number }` — Auto-detect with options
|
|
37
|
+
* - `{ adapter: PersistenceAdapterInterface }` — Custom adapter
|
|
38
|
+
* - `false` — Disable persistence (pure in-memory)
|
|
39
|
+
*/
|
|
40
|
+
persistence?: string | false | {
|
|
41
|
+
type?: 'file' | 'local' | 'auto';
|
|
42
|
+
path?: string;
|
|
43
|
+
key?: string;
|
|
44
|
+
autoSaveInterval?: number;
|
|
45
|
+
adapter?: PersistenceAdapterInterface;
|
|
46
|
+
};
|
|
16
47
|
}
|
|
17
48
|
/**
|
|
18
49
|
* In-Memory Driver for ObjectStack
|
|
@@ -38,6 +69,7 @@ declare class InMemoryDriver implements DriverInterface {
|
|
|
38
69
|
private logger;
|
|
39
70
|
private idCounters;
|
|
40
71
|
private transactions;
|
|
72
|
+
private persistenceAdapter;
|
|
41
73
|
constructor(config?: InMemoryDriverConfig);
|
|
42
74
|
install(ctx: any): void;
|
|
43
75
|
supports: {
|
|
@@ -164,6 +196,99 @@ declare class InMemoryDriver implements DriverInterface {
|
|
|
164
196
|
private projectFields;
|
|
165
197
|
private getTable;
|
|
166
198
|
private generateId;
|
|
199
|
+
/**
|
|
200
|
+
* Mark the database as dirty, triggering persistence save.
|
|
201
|
+
*/
|
|
202
|
+
private markDirty;
|
|
203
|
+
/**
|
|
204
|
+
* Flush pending persistence writes to ensure data is safely stored.
|
|
205
|
+
*/
|
|
206
|
+
flush(): Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Detect whether the current runtime is a browser environment.
|
|
209
|
+
*/
|
|
210
|
+
private isBrowserEnvironment;
|
|
211
|
+
/**
|
|
212
|
+
* Initialize the persistence adapter based on configuration.
|
|
213
|
+
* Defaults to 'auto' when persistence is not specified.
|
|
214
|
+
* Use `persistence: false` to explicitly disable persistence.
|
|
215
|
+
*/
|
|
216
|
+
private initPersistence;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* FileSystemPersistenceAdapter
|
|
221
|
+
*
|
|
222
|
+
* Persists the in-memory database to a JSON file on disk.
|
|
223
|
+
* Supports atomic writes (write to temp file then rename) and auto-save with dirty tracking.
|
|
224
|
+
*
|
|
225
|
+
* Node.js only — will throw if used in non-Node.js environments.
|
|
226
|
+
*/
|
|
227
|
+
declare class FileSystemPersistenceAdapter {
|
|
228
|
+
private readonly filePath;
|
|
229
|
+
private readonly autoSaveInterval;
|
|
230
|
+
private dirty;
|
|
231
|
+
private timer;
|
|
232
|
+
private currentDb;
|
|
233
|
+
constructor(options?: {
|
|
234
|
+
path?: string;
|
|
235
|
+
autoSaveInterval?: number;
|
|
236
|
+
});
|
|
237
|
+
/**
|
|
238
|
+
* Load persisted data from disk.
|
|
239
|
+
* Returns null if no file exists.
|
|
240
|
+
*/
|
|
241
|
+
load(): Promise<Record<string, any[]> | null>;
|
|
242
|
+
/**
|
|
243
|
+
* Save data to disk using atomic write (temp file + rename).
|
|
244
|
+
*/
|
|
245
|
+
save(db: Record<string, any[]>): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* Flush pending writes to disk immediately.
|
|
248
|
+
*/
|
|
249
|
+
flush(): Promise<void>;
|
|
250
|
+
/**
|
|
251
|
+
* Start the auto-save timer.
|
|
252
|
+
*/
|
|
253
|
+
startAutoSave(): void;
|
|
254
|
+
/**
|
|
255
|
+
* Stop the auto-save timer and flush pending writes.
|
|
256
|
+
*/
|
|
257
|
+
stopAutoSave(): Promise<void>;
|
|
258
|
+
/**
|
|
259
|
+
* Atomic write: write to temp file, then rename.
|
|
260
|
+
*/
|
|
261
|
+
private writeToDisk;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* LocalStoragePersistenceAdapter
|
|
266
|
+
*
|
|
267
|
+
* Persists the in-memory database to browser localStorage.
|
|
268
|
+
* Synchronous storage with a ~5MB size limit warning.
|
|
269
|
+
*
|
|
270
|
+
* Browser only — will throw if used in non-browser environments.
|
|
271
|
+
*/
|
|
272
|
+
declare class LocalStoragePersistenceAdapter {
|
|
273
|
+
private readonly storageKey;
|
|
274
|
+
private static readonly SIZE_WARNING_BYTES;
|
|
275
|
+
constructor(options?: {
|
|
276
|
+
key?: string;
|
|
277
|
+
});
|
|
278
|
+
/**
|
|
279
|
+
* Load persisted data from localStorage.
|
|
280
|
+
* Returns null if no data exists.
|
|
281
|
+
*/
|
|
282
|
+
load(): Promise<Record<string, any[]> | null>;
|
|
283
|
+
/**
|
|
284
|
+
* Save data to localStorage.
|
|
285
|
+
* Warns if data size approaches the ~5MB localStorage limit.
|
|
286
|
+
*/
|
|
287
|
+
save(db: Record<string, any[]>): Promise<void>;
|
|
288
|
+
/**
|
|
289
|
+
* Flush is a no-op for localStorage (writes are synchronous).
|
|
290
|
+
*/
|
|
291
|
+
flush(): Promise<void>;
|
|
167
292
|
}
|
|
168
293
|
|
|
169
294
|
/**
|
|
@@ -237,4 +362,4 @@ declare const _default: {
|
|
|
237
362
|
onEnable: (context: any) => Promise<void>;
|
|
238
363
|
};
|
|
239
364
|
|
|
240
|
-
export { InMemoryDriver, type InMemoryDriverConfig, type MemoryAnalyticsConfig, MemoryAnalyticsService, _default as default };
|
|
365
|
+
export { FileSystemPersistenceAdapter, InMemoryDriver, type InMemoryDriverConfig, LocalStoragePersistenceAdapter, type MemoryAnalyticsConfig, MemoryAnalyticsService, type PersistenceAdapterInterface, _default as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,19 @@ import { QueryInput, DriverOptions, Cube, AnalyticsQuery } from '@objectstack/sp
|
|
|
2
2
|
import { DriverInterface, Logger } from '@objectstack/core';
|
|
3
3
|
import { IAnalyticsService, AnalyticsResult, CubeMeta } from '@objectstack/spec/contracts';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Persistence adapter interface.
|
|
7
|
+
* Matches the PersistenceAdapterSchema contract from @objectstack/spec.
|
|
8
|
+
*/
|
|
9
|
+
interface PersistenceAdapterInterface {
|
|
10
|
+
load(): Promise<Record<string, any[]> | null>;
|
|
11
|
+
save(db: Record<string, any[]>): Promise<void>;
|
|
12
|
+
flush(): Promise<void>;
|
|
13
|
+
/** Optional: Start periodic auto-save (used by FileSystemPersistenceAdapter). */
|
|
14
|
+
startAutoSave?(): void;
|
|
15
|
+
/** Optional: Stop auto-save timer and flush pending writes. */
|
|
16
|
+
stopAutoSave?(): Promise<void>;
|
|
17
|
+
}
|
|
5
18
|
/**
|
|
6
19
|
* Configuration options for the InMemory driver.
|
|
7
20
|
* Aligned with @objectstack/spec MemoryConfigSchema.
|
|
@@ -13,6 +26,24 @@ interface InMemoryDriverConfig {
|
|
|
13
26
|
strictMode?: boolean;
|
|
14
27
|
/** Optional: Logger instance */
|
|
15
28
|
logger?: Logger;
|
|
29
|
+
/**
|
|
30
|
+
* Persistence configuration. Defaults to `'auto'`.
|
|
31
|
+
* - `'auto'` (default) — Auto-detect environment (browser → localStorage, Node.js → file)
|
|
32
|
+
* - `'file'` — File-system persistence with defaults (Node.js only)
|
|
33
|
+
* - `'local'` — localStorage persistence with defaults (Browser only)
|
|
34
|
+
* - `{ type: 'file', path?: string, autoSaveInterval?: number }` — File-system with options
|
|
35
|
+
* - `{ type: 'local', key?: string }` — localStorage with options
|
|
36
|
+
* - `{ type: 'auto', path?: string, key?: string, autoSaveInterval?: number }` — Auto-detect with options
|
|
37
|
+
* - `{ adapter: PersistenceAdapterInterface }` — Custom adapter
|
|
38
|
+
* - `false` — Disable persistence (pure in-memory)
|
|
39
|
+
*/
|
|
40
|
+
persistence?: string | false | {
|
|
41
|
+
type?: 'file' | 'local' | 'auto';
|
|
42
|
+
path?: string;
|
|
43
|
+
key?: string;
|
|
44
|
+
autoSaveInterval?: number;
|
|
45
|
+
adapter?: PersistenceAdapterInterface;
|
|
46
|
+
};
|
|
16
47
|
}
|
|
17
48
|
/**
|
|
18
49
|
* In-Memory Driver for ObjectStack
|
|
@@ -38,6 +69,7 @@ declare class InMemoryDriver implements DriverInterface {
|
|
|
38
69
|
private logger;
|
|
39
70
|
private idCounters;
|
|
40
71
|
private transactions;
|
|
72
|
+
private persistenceAdapter;
|
|
41
73
|
constructor(config?: InMemoryDriverConfig);
|
|
42
74
|
install(ctx: any): void;
|
|
43
75
|
supports: {
|
|
@@ -164,6 +196,99 @@ declare class InMemoryDriver implements DriverInterface {
|
|
|
164
196
|
private projectFields;
|
|
165
197
|
private getTable;
|
|
166
198
|
private generateId;
|
|
199
|
+
/**
|
|
200
|
+
* Mark the database as dirty, triggering persistence save.
|
|
201
|
+
*/
|
|
202
|
+
private markDirty;
|
|
203
|
+
/**
|
|
204
|
+
* Flush pending persistence writes to ensure data is safely stored.
|
|
205
|
+
*/
|
|
206
|
+
flush(): Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Detect whether the current runtime is a browser environment.
|
|
209
|
+
*/
|
|
210
|
+
private isBrowserEnvironment;
|
|
211
|
+
/**
|
|
212
|
+
* Initialize the persistence adapter based on configuration.
|
|
213
|
+
* Defaults to 'auto' when persistence is not specified.
|
|
214
|
+
* Use `persistence: false` to explicitly disable persistence.
|
|
215
|
+
*/
|
|
216
|
+
private initPersistence;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* FileSystemPersistenceAdapter
|
|
221
|
+
*
|
|
222
|
+
* Persists the in-memory database to a JSON file on disk.
|
|
223
|
+
* Supports atomic writes (write to temp file then rename) and auto-save with dirty tracking.
|
|
224
|
+
*
|
|
225
|
+
* Node.js only — will throw if used in non-Node.js environments.
|
|
226
|
+
*/
|
|
227
|
+
declare class FileSystemPersistenceAdapter {
|
|
228
|
+
private readonly filePath;
|
|
229
|
+
private readonly autoSaveInterval;
|
|
230
|
+
private dirty;
|
|
231
|
+
private timer;
|
|
232
|
+
private currentDb;
|
|
233
|
+
constructor(options?: {
|
|
234
|
+
path?: string;
|
|
235
|
+
autoSaveInterval?: number;
|
|
236
|
+
});
|
|
237
|
+
/**
|
|
238
|
+
* Load persisted data from disk.
|
|
239
|
+
* Returns null if no file exists.
|
|
240
|
+
*/
|
|
241
|
+
load(): Promise<Record<string, any[]> | null>;
|
|
242
|
+
/**
|
|
243
|
+
* Save data to disk using atomic write (temp file + rename).
|
|
244
|
+
*/
|
|
245
|
+
save(db: Record<string, any[]>): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* Flush pending writes to disk immediately.
|
|
248
|
+
*/
|
|
249
|
+
flush(): Promise<void>;
|
|
250
|
+
/**
|
|
251
|
+
* Start the auto-save timer.
|
|
252
|
+
*/
|
|
253
|
+
startAutoSave(): void;
|
|
254
|
+
/**
|
|
255
|
+
* Stop the auto-save timer and flush pending writes.
|
|
256
|
+
*/
|
|
257
|
+
stopAutoSave(): Promise<void>;
|
|
258
|
+
/**
|
|
259
|
+
* Atomic write: write to temp file, then rename.
|
|
260
|
+
*/
|
|
261
|
+
private writeToDisk;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* LocalStoragePersistenceAdapter
|
|
266
|
+
*
|
|
267
|
+
* Persists the in-memory database to browser localStorage.
|
|
268
|
+
* Synchronous storage with a ~5MB size limit warning.
|
|
269
|
+
*
|
|
270
|
+
* Browser only — will throw if used in non-browser environments.
|
|
271
|
+
*/
|
|
272
|
+
declare class LocalStoragePersistenceAdapter {
|
|
273
|
+
private readonly storageKey;
|
|
274
|
+
private static readonly SIZE_WARNING_BYTES;
|
|
275
|
+
constructor(options?: {
|
|
276
|
+
key?: string;
|
|
277
|
+
});
|
|
278
|
+
/**
|
|
279
|
+
* Load persisted data from localStorage.
|
|
280
|
+
* Returns null if no data exists.
|
|
281
|
+
*/
|
|
282
|
+
load(): Promise<Record<string, any[]> | null>;
|
|
283
|
+
/**
|
|
284
|
+
* Save data to localStorage.
|
|
285
|
+
* Warns if data size approaches the ~5MB localStorage limit.
|
|
286
|
+
*/
|
|
287
|
+
save(db: Record<string, any[]>): Promise<void>;
|
|
288
|
+
/**
|
|
289
|
+
* Flush is a no-op for localStorage (writes are synchronous).
|
|
290
|
+
*/
|
|
291
|
+
flush(): Promise<void>;
|
|
167
292
|
}
|
|
168
293
|
|
|
169
294
|
/**
|
|
@@ -237,4 +362,4 @@ declare const _default: {
|
|
|
237
362
|
onEnable: (context: any) => Promise<void>;
|
|
238
363
|
};
|
|
239
364
|
|
|
240
|
-
export { InMemoryDriver, type InMemoryDriverConfig, type MemoryAnalyticsConfig, MemoryAnalyticsService, _default as default };
|
|
365
|
+
export { FileSystemPersistenceAdapter, InMemoryDriver, type InMemoryDriverConfig, LocalStoragePersistenceAdapter, type MemoryAnalyticsConfig, MemoryAnalyticsService, type PersistenceAdapterInterface, _default as default };
|