sliftutils 0.37.0 → 0.39.0

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
@@ -473,7 +473,7 @@ declare module "sliftutils/storage/DiskCollection" {
473
473
  constructor(collectionName: string, config?: {
474
474
  writeDelay?: number | undefined;
475
475
  cbor?: boolean | undefined;
476
- browserOnly?: boolean | undefined;
476
+ noPrompt?: boolean | undefined;
477
477
  } | undefined);
478
478
  transactionStorage: TransactionStorage | undefined;
479
479
  initStorage(): Promise<IStorage<T>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sliftutils",
3
- "version": "0.37.0",
3
+ "version": "0.39.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -9,7 +9,7 @@ export declare class DiskCollection<T> implements IStorageSync<T> {
9
9
  constructor(collectionName: string, config?: {
10
10
  writeDelay?: number | undefined;
11
11
  cbor?: boolean | undefined;
12
- browserOnly?: boolean | undefined;
12
+ noPrompt?: boolean | undefined;
13
13
  } | undefined);
14
14
  transactionStorage: TransactionStorage | undefined;
15
15
  initStorage(): Promise<IStorage<T>>;
@@ -17,7 +17,7 @@ export class DiskCollection<T> implements IStorageSync<T> {
17
17
  private config?: {
18
18
  writeDelay?: number;
19
19
  cbor?: boolean;
20
- browserOnly?: boolean;
20
+ noPrompt?: boolean;
21
21
  }
22
22
  ) {
23
23
  }
@@ -26,7 +26,7 @@ export class DiskCollection<T> implements IStorageSync<T> {
26
26
  // If a Chrome extension, just return null.
27
27
  if (isInChromeExtension()) return null as any;
28
28
  let curCollection: IStorageRaw;
29
- if (this.config?.browserOnly) {
29
+ if (this.config?.noPrompt && !isNode()) {
30
30
  curCollection = await new PrivateFileSystemStorage(`collections/${this.collectionName}`);
31
31
  } else {
32
32
  let fileStorage = await getFileStorage();
@@ -10,14 +10,17 @@ export class PrivateFileSystemStorage implements IStorageRaw {
10
10
  if (!navigator.storage?.getDirectory) {
11
11
  throw new Error("Private File System Access API not supported in this browser");
12
12
  }
13
+ if (location.protocol === "file:") {
14
+ throw new Error(`Private File System API is disallowed in file:// type locations. Either use the File System API (the use gives you access to their file system), or host on an actual domain`);
15
+ }
13
16
  this.rootHandle = await navigator.storage.getDirectory();
14
17
  }
15
18
  return this.rootHandle;
16
19
  }
17
20
 
18
21
  private async directoryExists(): Promise<boolean> {
22
+ const root = await this.ensureInitialized();
19
23
  try {
20
- const root = await this.ensureInitialized();
21
24
 
22
25
  if (!this.path || this.path === "" || this.path === "/") {
23
26
  return true; // Root always exists