@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.
- package/dist/IndexedDB.js +24 -13
- 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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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);
|