indexeddbshim 12.0.0 → 13.0.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/README.md +1 -1
- package/badges/licenses-badge-dev.svg +1 -1
- package/dist/CFG.d.ts +80 -0
- package/dist/CFG.d.ts.map +1 -0
- package/dist/DOMException.d.ts +71 -0
- package/dist/DOMException.d.ts.map +1 -0
- package/dist/DOMStringList.d.ts +20 -0
- package/dist/DOMStringList.d.ts.map +1 -0
- package/dist/Event.d.ts +21 -0
- package/dist/Event.d.ts.map +1 -0
- package/dist/IDBCursor.d.ts +288 -0
- package/dist/IDBCursor.d.ts.map +1 -0
- package/dist/IDBDatabase.d.ts +143 -0
- package/dist/IDBDatabase.d.ts.map +1 -0
- package/dist/IDBFactory.d.ts +96 -0
- package/dist/IDBFactory.d.ts.map +1 -0
- package/dist/IDBIndex.d.ts +243 -0
- package/dist/IDBIndex.d.ts.map +1 -0
- package/dist/IDBKeyRange.d.ts +79 -0
- package/dist/IDBKeyRange.d.ts.map +1 -0
- package/dist/IDBObjectStore.d.ts +273 -0
- package/dist/IDBObjectStore.d.ts.map +1 -0
- package/dist/IDBRequest.d.ts +88 -0
- package/dist/IDBRequest.d.ts.map +1 -0
- package/dist/IDBTransaction.d.ts +270 -0
- package/dist/IDBTransaction.d.ts.map +1 -0
- package/dist/IDBVersionChangeEvent.d.ts +22 -0
- package/dist/IDBVersionChangeEvent.d.ts.map +1 -0
- package/dist/Key.d.ts +214 -0
- package/dist/Key.d.ts.map +1 -0
- package/dist/Sca.d.ts +31 -0
- package/dist/Sca.d.ts.map +1 -0
- package/dist/UnicodeIdentifiers.d.ts +3 -0
- package/dist/UnicodeIdentifiers.d.ts.map +1 -0
- package/dist/browser-UnicodeIdentifiers.d.ts +2 -0
- package/dist/browser-UnicodeIdentifiers.d.ts.map +1 -0
- package/dist/browser-noninvasive.d.ts +3 -0
- package/dist/browser-noninvasive.d.ts.map +1 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/cmp.d.ts +9 -0
- package/dist/cmp.d.ts.map +1 -0
- package/dist/indexeddbshim-Key.js +553 -252
- package/dist/indexeddbshim-Key.js.map +1 -1
- package/dist/indexeddbshim-Key.min.js +2 -2
- package/dist/indexeddbshim-Key.min.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs +17560 -1302
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.js +4367 -1604
- package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js +2 -2
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
- package/dist/indexeddbshim-node.cjs +17556 -1302
- package/dist/indexeddbshim-node.cjs.map +1 -1
- package/dist/indexeddbshim-noninvasive.js +4362 -1604
- package/dist/indexeddbshim-noninvasive.js.map +1 -1
- package/dist/indexeddbshim-noninvasive.min.js +2 -2
- package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
- package/dist/indexeddbshim.js +4362 -1604
- package/dist/indexeddbshim.js.map +1 -1
- package/dist/indexeddbshim.min.js +2 -2
- package/dist/indexeddbshim.min.js.map +1 -1
- package/dist/node-UnicodeIdentifiers.d.ts +8 -0
- package/dist/node-UnicodeIdentifiers.d.ts.map +1 -0
- package/dist/node.d.ts +8 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/nodeWebSQL.d.ts +3 -0
- package/dist/nodeWebSQL.d.ts.map +1 -0
- package/dist/setGlobalVars.d.ts +79 -0
- package/dist/setGlobalVars.d.ts.map +1 -0
- package/dist/unicode-regex.d.ts +3 -0
- package/dist/unicode-regex.d.ts.map +1 -0
- package/dist/util.d.ts +174 -0
- package/dist/util.d.ts.map +1 -0
- package/index.html +1 -1
- package/package.json +51 -37
- package/src/CFG.js +89 -11
- package/src/DOMException.js +117 -31
- package/src/DOMStringList.js +93 -3
- package/src/Event.js +19 -4
- package/src/IDBCursor.js +350 -76
- package/src/IDBDatabase.js +88 -10
- package/src/IDBFactory.js +331 -61
- package/src/IDBIndex.js +393 -110
- package/src/IDBKeyRange.js +90 -17
- package/src/IDBObjectStore.js +347 -86
- package/src/IDBRequest.js +59 -1
- package/src/IDBTransaction.js +254 -46
- package/src/IDBVersionChangeEvent.js +28 -3
- package/src/Key.d.ts +1 -0
- package/src/Key.js +272 -162
- package/src/Sca.js +29 -4
- package/src/browser-UnicodeIdentifiers.js +5 -1
- package/src/cmp.js +5 -5
- package/src/node-UnicodeIdentifiers.js +9 -0
- package/src/node.js +5 -0
- package/src/nodeWebSQL.js +11 -5
- package/src/setGlobalVars.js +159 -22
- package/src/unicode-regex.js +2 -0
- package/src/util.js +229 -40
- package/typings/shimIndexedDB.d.ts +9 -0
package/src/Sca.js
CHANGED
|
@@ -8,13 +8,24 @@ import {createDOMException, ShimDOMException} from './DOMException.js';
|
|
|
8
8
|
|
|
9
9
|
let typeson = new Typeson().register(structuredCloningThrowing);
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* @param {(preset: import('typeson-registry').Preset) =>
|
|
13
|
+
* import('typeson-registry').Preset} func
|
|
14
|
+
* @returns {void}
|
|
15
|
+
*/
|
|
11
16
|
function register (func) {
|
|
12
17
|
typeson = new Typeson().register(func(structuredCloningThrowing));
|
|
13
18
|
}
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
/**
|
|
21
|
+
* We are keeping the callback approach for now in case we wish to reexpose
|
|
22
|
+
* `Blob`, `File`, `FileList` asynchronously (though in such a case, we
|
|
23
|
+
* should probably refactor as a Promise).
|
|
24
|
+
* @param {AnyValue} obj
|
|
25
|
+
* @param {(str: string) => void} [func]
|
|
26
|
+
* @throws {Error}
|
|
27
|
+
* @returns {string}
|
|
28
|
+
*/
|
|
18
29
|
function encode (obj, func) {
|
|
19
30
|
let ret;
|
|
20
31
|
try {
|
|
@@ -34,14 +45,28 @@ function encode (obj, func) {
|
|
|
34
45
|
// throwing getters (as in the W3C test, key-conversion-exceptions.htm)
|
|
35
46
|
throw err;
|
|
36
47
|
}
|
|
37
|
-
if (func)
|
|
48
|
+
if (func) {
|
|
49
|
+
func(ret);
|
|
50
|
+
}
|
|
38
51
|
return ret;
|
|
39
52
|
}
|
|
40
53
|
|
|
54
|
+
/**
|
|
55
|
+
* @typedef {any} AnyValue
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param {string} obj
|
|
60
|
+
* @returns {AnyValue}
|
|
61
|
+
*/
|
|
41
62
|
function decode (obj) {
|
|
42
63
|
return typeson.parse(obj);
|
|
43
64
|
}
|
|
44
65
|
|
|
66
|
+
/**
|
|
67
|
+
* @param {AnyValue} val
|
|
68
|
+
* @returns {AnyValue}
|
|
69
|
+
*/
|
|
45
70
|
function clone (val) {
|
|
46
71
|
// We don't return the intermediate `encode` as we'll need to reencode
|
|
47
72
|
// the clone as it may differ
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-env browser, worker */
|
|
2
|
-
/*
|
|
2
|
+
/* globals shimIndexedDB */
|
|
3
3
|
import * as UnicodeIdentifiers from './UnicodeIdentifiers.js';
|
|
4
4
|
|
|
5
5
|
// BEGIN: Same code as in browser.js
|
|
@@ -14,6 +14,10 @@ setGlobalVars();
|
|
|
14
14
|
const __setUnicodeIdentifiers = shimIndexedDB.__setUnicodeIdentifiers.bind(
|
|
15
15
|
shimIndexedDB
|
|
16
16
|
);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @returns {void}
|
|
20
|
+
*/
|
|
17
21
|
shimIndexedDB.__setUnicodeIdentifiers = function () {
|
|
18
22
|
__setUnicodeIdentifiers(UnicodeIdentifiers);
|
|
19
23
|
};
|
package/src/cmp.js
CHANGED
|
@@ -3,13 +3,13 @@ import {encode as keyEncode, decode as keyDecode} from './Key.js';
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Compares two keys.
|
|
6
|
-
* @param first
|
|
7
|
-
* @param second
|
|
8
|
-
* @returns {
|
|
6
|
+
* @param {import('./Key.js').Key} first
|
|
7
|
+
* @param {import('./Key.js').Key} second
|
|
8
|
+
* @returns {0|1|-1}
|
|
9
9
|
*/
|
|
10
10
|
function cmp (first, second) {
|
|
11
|
-
const encodedKey1 = keyEncode(first);
|
|
12
|
-
const encodedKey2 = keyEncode(second);
|
|
11
|
+
const encodedKey1 = /** @type {string} */ (keyEncode(first));
|
|
12
|
+
const encodedKey2 = /** @type {string} */ (keyEncode(second));
|
|
13
13
|
const result = encodedKey1 > encodedKey2
|
|
14
14
|
? 1
|
|
15
15
|
: encodedKey1 === encodedKey2 ? 0 : -1;
|
|
@@ -7,8 +7,17 @@ import * as UnicodeIdentifiers from './UnicodeIdentifiers.js';
|
|
|
7
7
|
|
|
8
8
|
CFG.win = {openDatabase: nodeWebSQL};
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @param {import('./setGlobalVars.js').ShimmedObject} idb
|
|
12
|
+
* @param {import('./CFG.js').default} initialConfig
|
|
13
|
+
* @returns {{}|Window}
|
|
14
|
+
*/
|
|
10
15
|
const __setGlobalVars = function (idb, initialConfig = {}) {
|
|
11
16
|
const obj = setGlobalVars(idb, {fs, ...initialConfig});
|
|
17
|
+
/* istanbul ignore next -- TS guard */
|
|
18
|
+
if (!obj.shimIndexedDB) {
|
|
19
|
+
return obj;
|
|
20
|
+
}
|
|
12
21
|
obj.shimIndexedDB.__setUnicodeIdentifiers(UnicodeIdentifiers);
|
|
13
22
|
|
|
14
23
|
return obj;
|
package/src/node.js
CHANGED
|
@@ -6,6 +6,11 @@ import CFG from './CFG.js';
|
|
|
6
6
|
|
|
7
7
|
CFG.win = {openDatabase: nodeWebSQL};
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @param {import('./setGlobalVars.js').ShimmedObject} idb
|
|
11
|
+
* @param {import('./CFG.js').default} initialConfig
|
|
12
|
+
* @returns {{}|Window}
|
|
13
|
+
*/
|
|
9
14
|
const __setGlobalVars = function (idb, initialConfig = {}) {
|
|
10
15
|
return setGlobalVars(idb, {fs, ...initialConfig});
|
|
11
16
|
};
|
package/src/nodeWebSQL.js
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
import customOpenDatabase from 'websql/custom/index.js';
|
|
2
|
-
import SQLiteDatabase from 'websql/lib/sqlite/SQLiteDatabase.js';
|
|
1
|
+
import customOpenDatabase from 'websql-configurable/custom/index.js';
|
|
2
|
+
import SQLiteDatabase from 'websql-configurable/lib/sqlite/SQLiteDatabase.js';
|
|
3
3
|
import CFG from './CFG.js';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} name
|
|
7
|
+
* @returns {SQLiteDatabase}
|
|
8
|
+
*/
|
|
5
9
|
function wrappedSQLiteDatabase (name) {
|
|
6
|
-
const db = new SQLiteDatabase(name);
|
|
10
|
+
const db = new SQLiteDatabase(name, {});
|
|
7
11
|
if (CFG.sqlBusyTimeout) {
|
|
8
|
-
db._db.configure('busyTimeout', CFG.sqlBusyTimeout); // Default is 1000
|
|
12
|
+
db._db.configure('busyTimeout', /** @type {number} */ (CFG.sqlBusyTimeout)); // Default is 1000
|
|
9
13
|
}
|
|
10
14
|
if (CFG.sqlTrace) {
|
|
15
|
+
// @ts-expect-error native API?
|
|
11
16
|
db._db.configure('trace', CFG.sqlTrace);
|
|
12
17
|
}
|
|
13
18
|
if (CFG.sqlProfile) {
|
|
19
|
+
// @ts-expect-error native API?
|
|
14
20
|
db._db.configure('profile', CFG.sqlProfile);
|
|
15
21
|
}
|
|
16
22
|
return db;
|
|
17
23
|
}
|
|
18
24
|
|
|
19
|
-
const nodeWebSQL = customOpenDatabase(wrappedSQLiteDatabase);
|
|
25
|
+
const nodeWebSQL = customOpenDatabase(wrappedSQLiteDatabase, {});
|
|
20
26
|
export default nodeWebSQL;
|
package/src/setGlobalVars.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* globals self */
|
|
2
1
|
import {setPrototypeOfCustomEvent} from 'eventtargeter';
|
|
3
2
|
import shimIDBVersionChangeEvent from './IDBVersionChangeEvent.js';
|
|
4
3
|
import {IDBCursor as shimIDBCursor, IDBCursorWithValue as shimIDBCursorWithValue} from './IDBCursor.js';
|
|
@@ -16,37 +15,135 @@ import shimIDBDatabase from './IDBDatabase.js';
|
|
|
16
15
|
import CFG from './CFG.js';
|
|
17
16
|
import {isNullish} from './util.js';
|
|
18
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {any} AnyValue
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @callback SetConfig
|
|
24
|
+
* @param {import('./CFG.js').KeyofConfigValues|
|
|
25
|
+
* Partial<import('./CFG.js').ConfigValues>} prop
|
|
26
|
+
* @param {AnyValue} [val]
|
|
27
|
+
* @throws {Error}
|
|
28
|
+
* @returns {void}
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/** @type {SetConfig} */
|
|
19
32
|
function setConfig (prop, val) {
|
|
20
33
|
if (prop && typeof prop === 'object') {
|
|
21
34
|
Object.entries(prop).forEach(([p, val]) => {
|
|
22
|
-
setConfig(
|
|
35
|
+
setConfig(
|
|
36
|
+
/** @type {import('./CFG.js').KeyofConfigValues} */
|
|
37
|
+
(p),
|
|
38
|
+
val
|
|
39
|
+
);
|
|
23
40
|
});
|
|
24
41
|
return;
|
|
25
42
|
}
|
|
26
43
|
if (!(prop in CFG)) {
|
|
27
44
|
throw new Error(prop + ' is not a valid configuration property');
|
|
28
45
|
}
|
|
46
|
+
// @ts-expect-error Should not be `never` here!
|
|
29
47
|
CFG[prop] = val;
|
|
30
48
|
if (prop === 'registerSCA' && typeof val === 'function') {
|
|
31
|
-
register(
|
|
49
|
+
register(
|
|
50
|
+
/**
|
|
51
|
+
* @type {(
|
|
52
|
+
* preset: import('typeson').Preset
|
|
53
|
+
* ) => import('typeson').Preset}
|
|
54
|
+
*/ (
|
|
55
|
+
val
|
|
56
|
+
)
|
|
57
|
+
);
|
|
32
58
|
}
|
|
33
59
|
}
|
|
34
60
|
|
|
61
|
+
/**
|
|
62
|
+
* @typedef {(
|
|
63
|
+
* prop: import('./CFG.js').KeyofConfigValues
|
|
64
|
+
* ) => import('../src/CFG.js').ConfigValue} GetConfig
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @typedef {(cfg: {
|
|
69
|
+
* UnicodeIDStart: string,
|
|
70
|
+
* UnicodeIDContinue: string
|
|
71
|
+
* }) => void} SetUnicodeIdentifiers
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @typedef {(IDBFactory|object) & {
|
|
76
|
+
* __useShim: () => void,
|
|
77
|
+
* __debug: (val: boolean) => void,
|
|
78
|
+
* __setConfig: SetConfig,
|
|
79
|
+
* __getConfig: GetConfig,
|
|
80
|
+
* __setUnicodeIdentifiers: SetUnicodeIdentifiers,
|
|
81
|
+
* __setConnectionQueueOrigin: (origin?: string) => void
|
|
82
|
+
* }} ShimIndexedDB
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @typedef {number} Integer
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @typedef {(typeof globalThis|object) & {
|
|
91
|
+
* indexedDB?: Partial<IDBFactory>,
|
|
92
|
+
* IDBFactory: typeof IDBFactory,
|
|
93
|
+
* IDBOpenDBRequest: typeof IDBOpenDBRequest,
|
|
94
|
+
* IDBRequest: typeof IDBRequest,
|
|
95
|
+
* IDBCursorWithValue: typeof IDBCursorWithValue,
|
|
96
|
+
* IDBCursor: typeof IDBCursor,
|
|
97
|
+
* IDBDatabase: typeof IDBDatabase,
|
|
98
|
+
* IDBTransaction: typeof IDBTransaction,
|
|
99
|
+
* IDBKeyRange: typeof IDBKeyRange,
|
|
100
|
+
* shimIndexedDB?: ShimIndexedDB
|
|
101
|
+
* }} ShimmedObject
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
*
|
|
106
|
+
* @param {ShimmedObject} [idb]
|
|
107
|
+
* @param {import('./CFG.js').ConfigValues} [initialConfig]
|
|
108
|
+
* @returns {ShimmedObject}
|
|
109
|
+
*/
|
|
35
110
|
function setGlobalVars (idb, initialConfig) {
|
|
36
111
|
if (initialConfig) {
|
|
37
112
|
setConfig(initialConfig);
|
|
38
113
|
}
|
|
39
|
-
const IDB = idb ||
|
|
114
|
+
const IDB = idb || globalThis || {};
|
|
115
|
+
/**
|
|
116
|
+
* @typedef {any} AnyClass
|
|
117
|
+
*/
|
|
118
|
+
/**
|
|
119
|
+
* @typedef {any} AnyValue
|
|
120
|
+
*/
|
|
121
|
+
/**
|
|
122
|
+
* @typedef {Function} AnyFunction
|
|
123
|
+
*/
|
|
124
|
+
/**
|
|
125
|
+
* @param {string} name
|
|
126
|
+
* @param {AnyClass} value
|
|
127
|
+
* @param {PropertyDescriptor & {
|
|
128
|
+
* shimNS?: object
|
|
129
|
+
* }|undefined} [propDesc]
|
|
130
|
+
* @returns {void}
|
|
131
|
+
*/
|
|
40
132
|
function shim (name, value, propDesc) {
|
|
41
133
|
if (!propDesc || !Object.defineProperty) {
|
|
42
134
|
try {
|
|
43
135
|
// Try setting the property. This will fail if the property is read-only.
|
|
136
|
+
// @ts-expect-error It's ok
|
|
44
137
|
IDB[name] = value;
|
|
45
138
|
} catch (e) {
|
|
46
139
|
console.log(e);
|
|
47
140
|
}
|
|
48
141
|
}
|
|
49
|
-
if (
|
|
142
|
+
if (
|
|
143
|
+
// @ts-expect-error It's ok
|
|
144
|
+
IDB[name] !== value &&
|
|
145
|
+
Object.defineProperty
|
|
146
|
+
) {
|
|
50
147
|
// Setting a read-only property failed, so try re-defining the property
|
|
51
148
|
try {
|
|
52
149
|
let desc = propDesc || {};
|
|
@@ -59,11 +156,20 @@ function setGlobalVars (idb, initialConfig) {
|
|
|
59
156
|
}
|
|
60
157
|
} else {
|
|
61
158
|
const o = {
|
|
159
|
+
/**
|
|
160
|
+
* @returns {AnyValue}
|
|
161
|
+
*/
|
|
62
162
|
get [name] () {
|
|
63
|
-
return
|
|
163
|
+
return /** @type {AnyFunction} */ (
|
|
164
|
+
/** @type {PropertyDescriptor} */ (
|
|
165
|
+
propDesc
|
|
166
|
+
).get
|
|
167
|
+
).call(this);
|
|
64
168
|
}
|
|
65
169
|
};
|
|
66
|
-
desc =
|
|
170
|
+
desc = /** @type {PropertyDescriptor} */ (
|
|
171
|
+
Object.getOwnPropertyDescriptor(o, name)
|
|
172
|
+
);
|
|
67
173
|
}
|
|
68
174
|
Object.defineProperty(IDB, name, desc);
|
|
69
175
|
} catch (e) {
|
|
@@ -72,8 +178,12 @@ function setGlobalVars (idb, initialConfig) {
|
|
|
72
178
|
// get here since no WebSQL to use for shimming)
|
|
73
179
|
}
|
|
74
180
|
}
|
|
181
|
+
|
|
182
|
+
// @ts-expect-error It's ok
|
|
75
183
|
if (IDB[name] !== value) {
|
|
76
|
-
typeof console !== 'undefined' && console.warn
|
|
184
|
+
if (typeof console !== 'undefined' && console.warn) {
|
|
185
|
+
console.warn('Unable to shim ' + name);
|
|
186
|
+
}
|
|
77
187
|
}
|
|
78
188
|
}
|
|
79
189
|
if (CFG.win.openDatabase !== undefined) {
|
|
@@ -82,8 +192,13 @@ function setGlobalVars (idb, initialConfig) {
|
|
|
82
192
|
configurable: true
|
|
83
193
|
});
|
|
84
194
|
}
|
|
85
|
-
if (IDB.shimIndexedDB) {
|
|
195
|
+
if ('shimIndexedDB' in IDB && IDB.shimIndexedDB) {
|
|
86
196
|
IDB.shimIndexedDB.__useShim = function () {
|
|
197
|
+
/**
|
|
198
|
+
*
|
|
199
|
+
* @param {"Shim"|""} [prefix]
|
|
200
|
+
* @returns {void}
|
|
201
|
+
*/
|
|
87
202
|
function setNonIDBGlobals (prefix = '') {
|
|
88
203
|
shim(prefix + 'DOMException', ShimDOMException);
|
|
89
204
|
shim(prefix + 'DOMStringList', DOMStringList, {
|
|
@@ -125,7 +240,8 @@ function setGlobalVars (idb, initialConfig) {
|
|
|
125
240
|
return shimIndexedDB;
|
|
126
241
|
}
|
|
127
242
|
});
|
|
128
|
-
[
|
|
243
|
+
/** @type {[string, any][]} */
|
|
244
|
+
([
|
|
129
245
|
['IDBFactory', shimIDBFactory],
|
|
130
246
|
['IDBDatabase', shimIDBDatabase],
|
|
131
247
|
['IDBObjectStore', shimIDBObjectStore],
|
|
@@ -137,7 +253,7 @@ function setGlobalVars (idb, initialConfig) {
|
|
|
137
253
|
['IDBRequest', shimIDBRequest],
|
|
138
254
|
['IDBOpenDBRequest', shimIDBOpenDBRequest],
|
|
139
255
|
['IDBVersionChangeEvent', shimIDBVersionChangeEvent]
|
|
140
|
-
].forEach(([prop, obj]) => {
|
|
256
|
+
]).forEach(([prop, obj]) => {
|
|
141
257
|
shim(prop, obj, {
|
|
142
258
|
enumerable: false,
|
|
143
259
|
configurable: true
|
|
@@ -172,6 +288,10 @@ function setGlobalVars (idb, initialConfig) {
|
|
|
172
288
|
setNonIDBGlobals();
|
|
173
289
|
}
|
|
174
290
|
}
|
|
291
|
+
/* istanbul ignore next -- TS guard */
|
|
292
|
+
if (!IDB.shimIndexedDB) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
175
295
|
IDB.shimIndexedDB.__setConnectionQueueOrigin();
|
|
176
296
|
}
|
|
177
297
|
};
|
|
@@ -180,22 +300,31 @@ function setGlobalVars (idb, initialConfig) {
|
|
|
180
300
|
CFG.DEBUG = val;
|
|
181
301
|
};
|
|
182
302
|
IDB.shimIndexedDB.__setConfig = setConfig;
|
|
303
|
+
|
|
304
|
+
/** @type {GetConfig} */
|
|
183
305
|
IDB.shimIndexedDB.__getConfig = function (prop) {
|
|
184
306
|
if (!(prop in CFG)) {
|
|
185
307
|
throw new Error(prop + ' is not a valid configuration property');
|
|
186
308
|
}
|
|
187
309
|
return CFG[prop];
|
|
188
310
|
};
|
|
189
|
-
|
|
311
|
+
|
|
312
|
+
/** @type {SetUnicodeIdentifiers} */
|
|
313
|
+
IDB.shimIndexedDB.__setUnicodeIdentifiers = function ({
|
|
314
|
+
UnicodeIDStart, UnicodeIDContinue
|
|
315
|
+
}) {
|
|
190
316
|
setConfig({UnicodeIDStart, UnicodeIDContinue});
|
|
191
317
|
};
|
|
192
318
|
} else {
|
|
193
319
|
// We no-op the harmless set-up properties and methods with a warning; the `IDBFactory` methods,
|
|
194
320
|
// however (including our non-standard methods), are not stubbed as they ought
|
|
195
321
|
// to fail earlier rather than potentially having side effects.
|
|
196
|
-
IDB.shimIndexedDB = {};
|
|
197
|
-
|
|
198
|
-
|
|
322
|
+
IDB.shimIndexedDB = /** @type {ShimIndexedDB} */ ({});
|
|
323
|
+
/** @type {const} */ ([
|
|
324
|
+
'__useShim', '__debug', '__setConfig',
|
|
325
|
+
'__getConfig', '__setUnicodeIdentifiers'
|
|
326
|
+
]).forEach((prop) => {
|
|
327
|
+
/** @type {ShimIndexedDB} */ (IDB.shimIndexedDB)[prop] = /** @type {() => any} */ function () {
|
|
199
328
|
console.warn('This browser does not have WebSQL to shim.');
|
|
200
329
|
};
|
|
201
330
|
});
|
|
@@ -203,7 +332,11 @@ function setGlobalVars (idb, initialConfig) {
|
|
|
203
332
|
|
|
204
333
|
// Workaround to prevent an error in Firefox
|
|
205
334
|
if (!('indexedDB' in IDB) && typeof window !== 'undefined') { // 2nd condition avoids problems in Node
|
|
206
|
-
IDB.indexedDB =
|
|
335
|
+
IDB.indexedDB = /** @type {IDBFactory} */ (IDB.indexedDB ||
|
|
336
|
+
('webkitIndexedDB' in IDB && IDB.webkitIndexedDB) ||
|
|
337
|
+
('mozIndexedDB' in IDB && IDB.mozIndexedDB) ||
|
|
338
|
+
('oIndexedDB' in IDB && IDB.oIndexedDB) ||
|
|
339
|
+
('msIndexedDB' in IDB && IDB.msIndexedDB));
|
|
207
340
|
}
|
|
208
341
|
|
|
209
342
|
// Detect browsers with known IndexedDB issues (e.g. Android pre-4.4)
|
|
@@ -224,7 +357,7 @@ function setGlobalVars (idb, initialConfig) {
|
|
|
224
357
|
// Detect iOS: http://stackoverflow.com/questions/9038625/detect-if-device-is-ios/9039885#9039885
|
|
225
358
|
// and detect version 9: http://stackoverflow.com/a/26363560/271577
|
|
226
359
|
(/(iPad|iPhone|iPod).* os 9_/ui).test(navigator.userAgent) &&
|
|
227
|
-
!
|
|
360
|
+
!('MSStream' in window) // But avoid IE11
|
|
228
361
|
)
|
|
229
362
|
)
|
|
230
363
|
) {
|
|
@@ -251,12 +384,16 @@ function setGlobalVars (idb, initialConfig) {
|
|
|
251
384
|
) {
|
|
252
385
|
IDB.shimIndexedDB.__useShim();
|
|
253
386
|
} else {
|
|
254
|
-
IDB.IDBDatabase = IDB.IDBDatabase ||
|
|
255
|
-
|
|
256
|
-
IDB.
|
|
257
|
-
|
|
387
|
+
IDB.IDBDatabase = IDB.IDBDatabase ||
|
|
388
|
+
('webkitIDBDatabase' in IDB && IDB.webkitIDBDatabase);
|
|
389
|
+
IDB.IDBTransaction = IDB.IDBTransaction ||
|
|
390
|
+
('webkitIDBTransaction' in IDB && IDB.webkitIDBTransaction) || {};
|
|
391
|
+
IDB.IDBCursor = IDB.IDBCursor ||
|
|
392
|
+
('webkitIDBCursor' in IDB && IDB.webkitIDBCursor);
|
|
393
|
+
IDB.IDBKeyRange = IDB.IDBKeyRange ||
|
|
394
|
+
('webkitIDBKeyRange' in IDB && IDB.webkitIDBKeyRange);
|
|
258
395
|
}
|
|
259
|
-
return IDB;
|
|
396
|
+
return /** @type {ShimmedObject} */ (IDB);
|
|
260
397
|
}
|
|
261
398
|
|
|
262
399
|
// Expose for ease in simulating such exceptions during testing
|