mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-10-21 17:11:40 -05:00
Add command to list node-persist data
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import * as path from 'node:path';
|
||||
import * as fs from 'node:fs/promises';
|
||||
import createDebug from 'debug';
|
||||
import persist from 'node-persist';
|
||||
import getPaths from 'env-paths';
|
||||
@@ -15,3 +16,16 @@ export async function initStorage(dir: string) {
|
||||
await storage.init();
|
||||
return storage;
|
||||
}
|
||||
|
||||
export async function* iterateLocalStorage(storage: persist.LocalStorage) {
|
||||
const dir = (storage as unknown as {options: persist.InitOptions}).options.dir!;
|
||||
|
||||
for await (const file of await fs.opendir(dir)) {
|
||||
if (!file.isFile()) continue;
|
||||
|
||||
const datum = await storage.readFile(path.join(dir, file.name)) as persist.Datum;
|
||||
if (!datum || !datum.key) continue;
|
||||
|
||||
yield datum;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user