@zenfs/dom 1.1.8 → 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.
Files changed (2) hide show
  1. package/dist/IndexedDB.js +24 -13
  2. package/package.json +1 -1
package/dist/IndexedDB.js CHANGED
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/dom",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "DOM backends for ZenFS",
5
5
  "funding": {
6
6
  "type": "individual",