Skip to content

Commit 033cd8d

Browse files
committed
Add Safari fix to builds
1 parent 73fd81e commit 033cd8d

21 files changed

+2683
-3508
lines changed

‎README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
This is a super-simple promise-based keyval store implemented with IndexedDB, originally based on [async-storage by Mozilla](https://github.com/mozilla-b2g/gaia/blob/master/shared/js/async_storage.js).
66

7-
It's small and tree-shakeable. If you only use get/set, the library is ~250 bytes (brotli'd), if you use all methods it's ~450 bytes.
7+
It's small and tree-shakeable. If you only use get/set, the library is ~370 bytes (brotli'd), if you use all methods it's ~560 bytes.
8+
9+
Although this is tiny, it's a little larger than previous versions due to a [massive bug in Safari](https://bugs.webkit.org/show_bug.cgi?id=226547). Hopefully this fix can be removed in the not-too-distant future, when a version of Safari without the bug reaches enough users.
810

911
[localForage](https://github.com/localForage/localForage) offers similar functionality, but supports older browsers with broken/absent IDB implementations. Because of that, it's orders of magnitude bigger (~7k).
1012

‎dist/cjs-compat/index.d.ts.map

+1-1
Original file line numberDiff line numberDiff line change

‎dist/cjs-compat/index.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
'use strict';
22

3+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4+
35
Object.defineProperty(exports, '__esModule', {
46
value: true
57
});
68

9+
var safariFix = require('dist/cjs-compat/index.js');
10+
11+
function _interopDefaultLegacy(e) {
12+
return e && _typeof(e) === 'object' && 'default' in e ? e : {
13+
'default': e
14+
};
15+
}
16+
17+
var safariFix__default = /*#__PURE__*/_interopDefaultLegacy(safariFix);
18+
719
function promisifyRequest(request) {
820
return new Promise(function (resolve, reject) {
921
// @ts-ignore - file size hacks
@@ -19,13 +31,15 @@ function promisifyRequest(request) {
1931
}
2032

2133
function createStore(dbName, storeName) {
22-
var request = indexedDB.open(dbName);
34+
var dbp = safariFix__default['default']().then(function () {
35+
var request = indexedDB.open(dbName);
2336

24-
request.onupgradeneeded = function () {
25-
return request.result.createObjectStore(storeName);
26-
};
37+
request.onupgradeneeded = function () {
38+
return request.result.createObjectStore(storeName);
39+
};
2740

28-
var dbp = promisifyRequest(request);
41+
return promisifyRequest(request);
42+
});
2943
return function (txMode, callback) {
3044
return dbp.then(function (db) {
3145
return callback(db.transaction(storeName, txMode).objectStore(storeName));

‎dist/cjs-compat/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/cjs/index.d.ts.map

+1-1
Original file line numberDiff line numberDiff line change

‎dist/cjs/index.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Object.defineProperty(exports, '__esModule', { value: true });
44

5+
var safariFix = require('safari-14-idb-fix');
6+
7+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8+
9+
var safariFix__default = /*#__PURE__*/_interopDefaultLegacy(safariFix);
10+
511
function promisifyRequest(request) {
612
return new Promise((resolve, reject) => {
713
// @ts-ignore - file size hacks
@@ -11,9 +17,11 @@ function promisifyRequest(request) {
1117
});
1218
}
1319
function createStore(dbName, storeName) {
14-
const request = indexedDB.open(dbName);
15-
request.onupgradeneeded = () => request.result.createObjectStore(storeName);
16-
const dbp = promisifyRequest(request);
20+
const dbp = safariFix__default['default']().then(() => {
21+
const request = indexedDB.open(dbName);
22+
request.onupgradeneeded = () => request.result.createObjectStore(storeName);
23+
return promisifyRequest(request);
24+
});
1725
return (txMode, callback) => dbp.then((db) => callback(db.transaction(storeName, txMode).objectStore(storeName)));
1826
}
1927
let defaultGetStoreFunc;

0 commit comments

Comments
 (0)