@zenfs/dom 1.1.7 → 1.1.9

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/dist/IndexedDB.js CHANGED
@@ -29,7 +29,7 @@ export class IndexedDBTransaction extends Transaction {
29
29
  this._idb = tx.objectStore(store.name);
30
30
  }
31
31
  async keys() {
32
- return (await wrap(this._idb.getAllKeys())).filter(k => typeof k == 'string').map(k => Number(k));
32
+ return (await wrap(this._idb.getAllKeys())).map(Number);
33
33
  }
34
34
  async get(id) {
35
35
  const data = await wrap(this._idb.get(id));
@@ -105,6 +105,25 @@ export class IndexedDBStore {
105
105
  return new IndexedDBTransaction(tx, this);
106
106
  }
107
107
  }
108
+ /**
109
+ * Used to memoize the availability test result
110
+ */
111
+ const idbTests = new WeakMap();
112
+ async function testAvailability(idbFactory) {
113
+ if (!(idbFactory instanceof IDBFactory))
114
+ return false;
115
+ try {
116
+ const req = idbFactory.open('__zenfs_test');
117
+ await wrap(req);
118
+ return true;
119
+ }
120
+ catch {
121
+ return false;
122
+ }
123
+ finally {
124
+ idbFactory?.deleteDatabase('__zenfs_test');
125
+ }
126
+ }
108
127
  /**
109
128
  * A file system that uses the IndexedDB key value file system.
110
129
  */
@@ -115,19 +134,11 @@ const _IndexedDB = {
115
134
  idbFactory: { type: 'object', required: false },
116
135
  },
117
136
  async isAvailable({ idbFactory = globalThis.indexedDB }) {
118
- try {
119
- if (!(idbFactory instanceof IDBFactory))
120
- return false;
121
- const req = idbFactory.open('__zenfs_test');
122
- await wrap(req);
123
- return true;
124
- }
125
- catch {
126
- return false;
127
- }
128
- finally {
129
- idbFactory?.deleteDatabase('__zenfs_test');
130
- }
137
+ if (idbTests.has(idbFactory))
138
+ return idbTests.get(idbFactory);
139
+ const result = testAvailability(idbFactory);
140
+ idbTests.set(idbFactory, result);
141
+ return result;
131
142
  },
132
143
  async create(options) {
133
144
  const db = await createDB(options.storeName || 'zenfs', options.idbFactory);
package/dist/access.d.ts CHANGED
@@ -23,7 +23,7 @@ export declare class WebAccessFS extends WebAccessFS_base {
23
23
  */
24
24
  _sync: FileSystem;
25
25
  constructor(handle: FileSystemDirectoryHandle);
26
- remove(path: string): Promise<void>;
26
+ protected remove(path: string): Promise<void>;
27
27
  protected removeSync(): void;
28
28
  read(path: string, buffer: Uint8Array, offset: number, end: number): Promise<void>;
29
29
  write(path: string, buffer: Uint8Array, offset: number): Promise<void>;
package/dist/access.js CHANGED
@@ -2,6 +2,7 @@ import { Async, constants, IndexFS, InMemory, Inode } from '@zenfs/core';
2
2
  import { basename, dirname, join } from '@zenfs/core/path.js';
3
3
  import { S_IFDIR, S_IFMT } from '@zenfs/core/vfs/constants.js';
4
4
  import { log, withErrno } from 'kerium';
5
+ import { alert } from 'kerium/log';
5
6
  import { _throw } from 'utilium';
6
7
  import { convertException } from './utils.js';
7
8
  function isResizable(buffer) {
@@ -78,7 +79,7 @@ export class WebAccessFS extends Async(IndexFS) {
78
79
  const file = await handle.getFile();
79
80
  const data = await file.arrayBuffer();
80
81
  if (data.byteLength < end - offset)
81
- throw withErrno('ENODATA');
82
+ throw alert(withErrno('EIO', `Unexpected mismatch in file data size. This should not happen.\n\t\tTried to read ${end - offset} bytes but the file is ${data.byteLength} bytes.`));
82
83
  buffer.set(new Uint8Array(data, offset, end - offset));
83
84
  }
84
85
  async write(path, buffer, offset) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/dom",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "DOM backends for ZenFS",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -32,7 +32,7 @@
32
32
  "tsconfig.json"
33
33
  ],
34
34
  "engines": {
35
- "node": ">= 18"
35
+ "node": ">= 22"
36
36
  },
37
37
  "exports": {
38
38
  ".": "./dist/index.js",
@@ -53,10 +53,10 @@
53
53
  "c8": "^10.1.3",
54
54
  "eslint": "^9.12.0",
55
55
  "fake-indexeddb": "^6.0.0",
56
- "globals": "^15.10.0",
56
+ "globals": "^16.0.0",
57
57
  "prettier": "^3.2.5",
58
58
  "tsx": "^4.19.2",
59
- "typedoc": "^0.27.2",
59
+ "typedoc": "^0.28.0",
60
60
  "typescript": "^5.7.2",
61
61
  "typescript-eslint": "^8.8.1"
62
62
  },