diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-07-31 01:33:23 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-07-31 01:33:23 +0200 |
commit | bcefbd7aab5f33f93d626c6421a1a1218c1a91a2 (patch) | |
tree | c0ac6e5e5fde9f51024ad5409c87b7e01c4af60a /packages/idb-bridge/src/index.ts | |
parent | 16ecbc9f177f1f71048840edf9b7af20ace3aad8 (diff) | |
download | wallet-core-bcefbd7aab5f33f93d626c6421a1a1218c1a91a2.tar.xz |
idb-bridge: test cases, package structure and missing functionality
Diffstat (limited to 'packages/idb-bridge/src/index.ts')
-rw-r--r-- | packages/idb-bridge/src/index.ts | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/packages/idb-bridge/src/index.ts b/packages/idb-bridge/src/index.ts new file mode 100644 index 000000000..a65458748 --- /dev/null +++ b/packages/idb-bridge/src/index.ts @@ -0,0 +1,60 @@ +import { BridgeIDBFactory } from "./BridgeIDBFactory"; +import { BridgeIDBCursor } from "./BridgeIDBCursor"; +import { BridgeIDBIndex } from "./BridgeIDBIndex"; +import BridgeIDBDatabase from "./BridgeIDBDatabase"; +import BridgeIDBKeyRange from "./BridgeIDBKeyRange"; +import BridgeIDBObjectStore from "./BridgeIDBObjectStore"; +import BridgeIDBOpenDBRequest from "./BridgeIDBOpenDBRequest"; +import BridgeIDBRequest from "./BridgeIDBRequest"; +import BridgeIDBTransaction from "./BridgeIDBTransaction"; +import BridgeIDBVersionChangeEvent from "./BridgeIDBVersionChangeEvent"; + +export { BridgeIDBFactory, BridgeIDBCursor }; + +export { MemoryBackend } from "./MemoryBackend"; + +// globalThis polyfill, see https://mathiasbynens.be/notes/globalthis +(function() { + if (typeof globalThis === "object") return; + Object.defineProperty(Object.prototype, "__magic__", { + get: function() { + return this; + }, + configurable: true, // This makes it possible to `delete` the getter later. + }); + // @ts-ignore: polyfill magic + __magic__.globalThis = __magic__; // lolwat + // @ts-ignore: polyfill magic + delete Object.prototype.__magic__; +})(); + +/** + * Populate the global name space such that the given IndexedDB factory is made + * available globally. + */ +export function shimIndexedDB(factory: BridgeIDBFactory): void { + // @ts-ignore: shimming + globalThis.indexedDB = factory; + // @ts-ignore: shimming + globalThis.IDBCursor = BridgeIDBCursor; + // @ts-ignore: shimming + globalThis.IDBKeyRange = BridgeIDBKeyRange; + // @ts-ignore: shimming + globalThis.IDBDatabase = BridgeIDBDatabase; + // @ts-ignore: shimming + globalThis.IDBFactory = BridgeIDBFactory; + // @ts-ignore: shimming + globalThis.IDBIndex = BridgeIDBIndex; + // @ts-ignore: shimming + globalThis.IDBKeyRange = BridgeIDBKeyRange; + // @ts-ignore: shimming + globalThis.IDBObjectStore = BridgeIDBObjectStore; + // @ts-ignore: shimming + globalThis.IDBOpenDBRequest = BridgeIDBOpenDBRequest; + // @ts-ignore: shimming + globalThis.IDBRequest = BridgeIDBRequest; + // @ts-ignore: shimming + globalThis.IDBTransaction = BridgeIDBTransaction; + // @ts-ignore: shimming + globalThis.IDBVersionChangeEvent = BridgeIDBVersionChangeEvent; +} |