sliftutils 1.1.43 → 1.1.44
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/index.d.ts
CHANGED
|
@@ -1217,6 +1217,14 @@ declare module "sliftutils/storage/FileFolderAPI" {
|
|
|
1217
1217
|
getAllKeys(): string[];
|
|
1218
1218
|
get(key: string): Promise<FileStorage> | undefined;
|
|
1219
1219
|
};
|
|
1220
|
+
export declare const getFileStorageNested2: {
|
|
1221
|
+
(key: string): Promise<FileStorage>;
|
|
1222
|
+
clear(key: string): void;
|
|
1223
|
+
clearAll(): void;
|
|
1224
|
+
forceSet(key: string, value: Promise<FileStorage>): void;
|
|
1225
|
+
getAllKeys(): string[];
|
|
1226
|
+
get(key: string): Promise<FileStorage> | undefined;
|
|
1227
|
+
};
|
|
1220
1228
|
export declare const getFileStorage: {
|
|
1221
1229
|
(): Promise<FileStorage>;
|
|
1222
1230
|
reset(): void;
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getFileStorageNested } from "../FileFolderAPI";
|
|
1
|
+
import { getFileStorageNested, getFileStorageNested2 } from "../FileFolderAPI";
|
|
2
2
|
import { sort } from "socket-function/src/misc";
|
|
3
3
|
import { getTimeUnique } from "socket-function/src/bits";
|
|
4
4
|
import { BaseBulkDatabaseReader, buildFileBuffer, EMPTY_BUFFER, loadBulkDatabase } from "./BulkDatabaseFormat";
|
|
@@ -75,7 +75,7 @@ export class BulkDatabase2<T extends { key: string }> {
|
|
|
75
75
|
blockCache.clear();
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
private storage = lazy(async () =>
|
|
78
|
+
private storage = lazy(async () => getFileStorageNested2(`${BULK_ROOT_FOLDER}/${this.name}`));
|
|
79
79
|
|
|
80
80
|
// In-memory overlay of pending writes/deletes, observable so reads re-render when it changes. It
|
|
81
81
|
// takes priority over the loaded readers, so writes are reflected in reads without reloading.
|
|
@@ -129,6 +129,14 @@ export declare const getFileStorageNested: {
|
|
|
129
129
|
getAllKeys(): string[];
|
|
130
130
|
get(key: string): Promise<FileStorage> | undefined;
|
|
131
131
|
};
|
|
132
|
+
export declare const getFileStorageNested2: {
|
|
133
|
+
(key: string): Promise<FileStorage>;
|
|
134
|
+
clear(key: string): void;
|
|
135
|
+
clearAll(): void;
|
|
136
|
+
forceSet(key: string, value: Promise<FileStorage>): void;
|
|
137
|
+
getAllKeys(): string[];
|
|
138
|
+
get(key: string): Promise<FileStorage> | undefined;
|
|
139
|
+
};
|
|
132
140
|
export declare const getFileStorage: {
|
|
133
141
|
(): Promise<FileStorage>;
|
|
134
142
|
reset(): void;
|
|
@@ -379,6 +379,33 @@ export const getFileStorageNested = cache(async function getFileStorage(path: st
|
|
|
379
379
|
}
|
|
380
380
|
return wrapHandle(base);
|
|
381
381
|
});
|
|
382
|
+
// Supports if the user selects the folder that contains the data folder or the data folder directly. If pathStr is an absolute path (and we're in nodejs) we use it directly.
|
|
383
|
+
export const getFileStorageNested2 = cache(async function getFileStorage(pathStr: string): Promise<FileStorage> {
|
|
384
|
+
let base: DirectoryWrapper;
|
|
385
|
+
pathStr = pathStr.replaceAll("\\", "/");
|
|
386
|
+
if (isNode()) {
|
|
387
|
+
if (path.isAbsolute(pathStr)) {
|
|
388
|
+
return wrapHandle(new NodeJSDirectoryHandleWrapper(pathStr));
|
|
389
|
+
}
|
|
390
|
+
base = new NodeJSDirectoryHandleWrapper(path.resolve("./data/"));
|
|
391
|
+
} else {
|
|
392
|
+
base = await getDirectoryHandle();
|
|
393
|
+
let dirs: string[] = [];
|
|
394
|
+
for await (const [name, entry] of base) {
|
|
395
|
+
if (entry.kind === "directory") {
|
|
396
|
+
dirs.push(name);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
if (dirs.includes(".git") || dirs.includes("data")) {
|
|
400
|
+
base = await base.getDirectoryHandle("data", { create: true });
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
for (let part of pathStr.split("/")) {
|
|
404
|
+
if (!part) continue;
|
|
405
|
+
base = await base.getDirectoryHandle(part, { create: true });
|
|
406
|
+
}
|
|
407
|
+
return wrapHandle(base);
|
|
408
|
+
});
|
|
382
409
|
export const getFileStorage = lazy(async function getFileStorage(): Promise<FileStorage> {
|
|
383
410
|
if (USE_INDEXED_DB) {
|
|
384
411
|
return await getFileStorageIndexDB();
|