Line data Source code
1 : /// HyperDB mounts the OPFS root of the origin at this path
2 1 : const HYPER_OPFS_MOUNT = '/mnt/fs';
3 :
4 : /// The OPFS folder of the browser tests.
5 : /// They run on the origin of the app, the dev server and the pages deployment serve tests.html next to it.
6 1 : export const OPFS_TESTS_FOLDER = 'tests';
7 :
8 : /// The OPFS folder with the files of the app, null for the OPFS root
9 1 : let appFolder: string | null = null;
10 :
11 : /// Keep the files of the app in an OPFS folder instead of the OPFS root.
12 : /// The browser tests call this before they load a test, so they never touch the files of the app.
13 1 : export function setOPFSAppFolder(folder: string | null): void {
14 1 : appFolder = folder;
15 1 : }
16 :
17 : /// The OPFS directory with the files of the app
18 1 : export async function getOPFSRoot(): Promise<FileSystemDirectoryHandle> {
19 1 : const root = await navigator.storage.getDirectory();
20 1 : return appFolder == null ? root : await root.getDirectoryHandle(appFolder, { create: true });
21 1 : }
22 :
23 : /// The Hyper path of the OPFS directory with the files of the app, e.g. `/mnt/fs`.
24 : /// Application paths are relative to this root.
25 1 : export function hyperOPFSRoot(): string {
26 1 : return appFolder == null ? HYPER_OPFS_MOUNT : `${HYPER_OPFS_MOUNT}/${appFolder}`;
27 1 : }
|