[
  {
    "path": ".github/ISSUE_TEMPLATE/bug_report.md",
    "content": "---\nname: Bug report\nabout: Create a report to help us improve\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n<!-- Bug reports without a minimal reproducible example will be closed (https://stackoverflow.com/help/minimal-reproducible-example). Ideally, the example should be accessible somewhere public, like jsbin, Glitch, jsfiddle, codepen etc etc -->\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/feature_request.md",
    "content": "---\nname: Feature request\nabout: Suggest an idea for this project\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n**Is your feature request related to a problem? Please describe.**\nA clear and concise description of what the problem is. Ex. I'm always frustrated when [...]\n\n**Describe the solution you'd like**\nA clear and concise description of what you want to happen.\n"
  },
  {
    "path": ".gitignore",
    "content": "node_modules\n.ts-tmp\nbuild\ntmp\n.idea\n.vscode\n"
  },
  {
    "path": ".prettierrc.json",
    "content": "{\n  \"singleQuote\": true,\n  \"trailingComma\": \"all\"\n}\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Breaking changes in 8.x\n\n- Finally dropped support for old EdgeHTML engine.\n- Dropped support for browsers that don't support [`cursor.request`](https://caniuse.com/mdn-api_idbcursor_request).\n- Removed separate async iterators build. It's now one build with async iterator support.\n\n# Breaking changes in 7.x\n\n- No longer committing `build` to GitHub.\n- Renamed files in dist.\n- Added conditional exports.\n- iife build is now a umd.\n\n# Breaking changes in 6.x\n\nSome TypeScript definitions changed so write-methods are missing from 'readonly' transactions. This might be backwards-incompatible with code that performs a lot of type wrangling.\n\n# Breaking changes in 5.x\n\nI moved some files around, so I bumped the major version for safety.\n\n# Changes in 4.x\n\n## Breaking changes\n\n### Opening a database\n\n```js\n// Old 3.x way\nimport { openDb } from 'idb';\n\nopenDb('db-name', 1, (upgradeDb) => {\n  console.log(upgradeDb.oldVersion);\n  console.log(upgradeDb.transaction);\n});\n```\n\n```js\n// New 4.x way\nimport { openDB } from 'idb';\n\nopenDB('db-name', 1, {\n  upgrade(db, oldVersion, newVersion, transaction) {\n    console.log(oldVersion);\n    console.log(transaction);\n  },\n});\n```\n\n- `openDb` and `deleteDb` were renamed `openDB` and `deleteDB` to be more consistent with DOM naming.\n- The signature of `openDB` changed. The third parameter used to be the upgrade callback, it's now an option object which can include an `upgrade` method.\n- There's no `UpgradeDB` anymore. You get the same database `openDB` resolves with. Versions numbers and the upgrade transaction are included as additional parameters.\n\n### Promises & throwing\n\nThe library turns all `IDBRequest` objects into promises, but it doesn't know in advance which methods may return promises.\n\nAs a result, methods such as `store.put` may throw instead of returning a promise.\n\nIf you're using async functions, there isn't a difference.\n\n### Other breaking changes\n\n- `iterateCursor` and `iterateKeyCursor` have been removed. These existed to work around browsers microtask issues which have since been fixed. Async iterators provide similar functionality.\n- All pseudo-private properties (those beginning with an underscore) are gone. Use `unwrap()` to get access to bare IDB objects.\n- `transaction.complete` was renamed to `transaction.done` to be shorter and more consistent with the DOM.\n- `getAll` is no longer polyfilled on indexes and stores.\n- The library no longer officially supports IE11.\n\n## New stuff\n\n- The library now uses proxies, so objects will include everything from their plain-IDB equivalents.\n- TypeScript support has massively improved, including the ability to provide types for your database.\n- Optional support for async iterators, which makes handling cursors much easier.\n- Database objects now have shortcuts for single actions (like `get`, `put`, `add`, `getAll` etc etc).\n- For transactions that cover a single store `transaction.store` is a reference to that store.\n- `openDB` lets you add callbacks for when your database is blocking another connection, or when you're blocked by another connection.\n\n# Changes in 3.x\n\nThe library became a module.\n\n```js\n// Old 2.x way:\nimport idb from 'idb';\nidb.open(…);\nidb.delete(…);\n\n// 3.x way:\nimport { openDb, deleteDb } from 'idb';\nopenDb(…);\ndeleteDb(…);\n```\n"
  },
  {
    "path": "LICENSE",
    "content": "ISC License (ISC)\nCopyright (c) 2016, Jake Archibald <jaffathecake@gmail.com>\n\nPermission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# IndexedDB with usability.\n\nThis is a tiny (~1.19kB brotli'd) library that mostly mirrors the IndexedDB API, but with small improvements that make a big difference to usability.\n\n1. [Installation](#installation)\n1. [Changes](#changes)\n1. [Browser support](#browser-support)\n1. [API](#api)\n   1. [`openDB`](#opendb)\n   1. [`deleteDB`](#deletedb)\n   1. [`unwrap`](#unwrap)\n   1. [`wrap`](#wrap)\n   1. [General enhancements](#general-enhancements)\n   1. [`IDBDatabase` enhancements](#idbdatabase-enhancements)\n   1. [`IDBTransaction` enhancements](#idbtransaction-enhancements)\n   1. [`IDBCursor` enhancements](#idbcursor-enhancements)\n   1. [Async iterators](#async-iterators)\n1. [Examples](#examples)\n1. [TypeScript](#typescript)\n\n# Installation\n\n## Using npm\n\n```sh\nnpm install idb\n```\n\nThen, assuming you're using a module-compatible system (like webpack, Rollup etc):\n\n```js\nimport { openDB, deleteDB, wrap, unwrap } from 'idb';\n\nasync function doDatabaseStuff() {\n  const db = await openDB(…);\n}\n```\n\n## Directly in a browser\n\n### Using the modules method directly via jsdelivr:\n\n```html\n<script type=\"module\">\n  import { openDB, deleteDB, wrap, unwrap } from 'https://cdn.jsdelivr.net/npm/idb@8/+esm';\n\n  async function doDatabaseStuff() {\n    const db = await openDB(…);\n  }\n</script>\n```\n\n### Using external script reference\n\n```html\n<script src=\"https://cdn.jsdelivr.net/npm/idb@8/build/umd.js\"></script>\n<script>\n  async function doDatabaseStuff() {\n    const db = await idb.openDB(…);\n  }\n</script>\n```\n\nA global, `idb`, will be created, containing all exports of the module version.\n\n# Changes\n\n[See details of (potentially) breaking changes](CHANGELOG.md).\n\n# Browser support\n\nThis library targets modern browsers, as in Chrome, Firefox, Safari, and other browsers that use those engines, such as Edge. IE is not supported.\n\n# API\n\n## `openDB`\n\nThis method opens a database, and returns a promise for an enhanced [`IDBDatabase`](https://w3c.github.io/IndexedDB/#database-interface).\n\n```js\nconst db = await openDB(name, version, {\n  upgrade(db, oldVersion, newVersion, transaction, event) {\n    // …\n  },\n  blocked(currentVersion, blockedVersion, event) {\n    // …\n  },\n  blocking(currentVersion, blockedVersion, event) {\n    // …\n  },\n  terminated() {\n    // …\n  },\n});\n```\n\n- `name`: Name of the database.\n- `version` (optional): Schema version, or `undefined` to open the current version.\n- `upgrade` (optional): Called if this version of the database has never been opened before. Use it to specify the schema for the database. This is similar to the [`upgradeneeded` event](https://developer.mozilla.org/en-US/docs/Web/API/IDBOpenDBRequest/upgradeneeded_event) in plain IndexedDB.\n  - `db`: An enhanced `IDBDatabase`.\n  - `oldVersion`: Last version of the database opened by the user.\n  - `newVersion`: Whatever new version you provided.\n  - `transaction`: An enhanced transaction for this upgrade. This is useful if you need to get data from other stores as part of a migration.\n  - `event`: The event object for the associated `upgradeneeded` event.\n- `blocked` (optional): Called if there are older versions of the database open on the origin, so this version cannot open. This is similar to the [`blocked` event](https://developer.mozilla.org/en-US/docs/Web/API/IDBOpenDBRequest/blocked_event) in plain IndexedDB.\n  - `currentVersion`: Version of the database that's blocking this one.\n  - `blockedVersion`: The version of the database being blocked (whatever version you provided to `openDB`).\n  - `event`: The event object for the associated `blocked` event.\n- `blocking` (optional): Called if this connection is blocking a future version of the database from opening. This is similar to the [`versionchange` event](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/versionchange_event) in plain IndexedDB.\n  - `currentVersion`: Version of the open database (whatever version you provided to `openDB`).\n  - `blockedVersion`: The version of the database that's being blocked.\n  - `event`: The event object for the associated `versionchange` event.\n- `terminated` (optional): Called if the browser abnormally terminates the connection, but not on regular closures like calling `db.close()`. This is similar to the [`close` event](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/close_event) in plain IndexedDB.\n\n## `deleteDB`\n\nDeletes a database.\n\n```js\nawait deleteDB(name, {\n  blocked() {\n    // …\n  },\n});\n```\n\n- `name`: Name of the database.\n- `blocked` (optional): Called if the database already exists and there are open connections that don’t close in response to a versionchange event, the request will be blocked until they all close.\n  - `currentVersion`: Version of the database that's blocking the delete operation.\n  - `event`: The event object for the associated 'versionchange' event.\n\n## `unwrap`\n\nTakes an enhanced IndexedDB object and returns the plain unmodified one.\n\n```js\nconst unwrapped = unwrap(wrapped);\n```\n\nThis is useful if, for some reason, you want to drop back into plain IndexedDB. Promises will also be converted back into `IDBRequest` objects.\n\n## `wrap`\n\nTakes an IDB object and returns a version enhanced by this library.\n\n```js\nconst wrapped = wrap(unwrapped);\n```\n\nThis is useful if some third party code gives you an `IDBDatabase` object and you want it to have the features of this library.\n\n## General enhancements\n\nOnce you've opened the database the API is the same as IndexedDB, except for a few changes to make things easier.\n\nFirstly, any method that usually returns an `IDBRequest` object will now return a promise for the result.\n\n```js\nconst store = db.transaction(storeName).objectStore(storeName);\nconst value = await store.get(key);\n```\n\n### Promises & throwing\n\nThe library turns all `IDBRequest` objects into promises, but it doesn't know in advance which methods may return promises.\n\nAs a result, methods such as `store.put` may throw instead of returning a promise.\n\nIf you're using async functions, there's no observable difference.\n\n### Transaction lifetime\n\nTL;DR: **Do not `await` other things between the start and end of your transaction**, otherwise the transaction will close before you're done.\n\nAn IDB transaction auto-closes if it doesn't have anything left do once microtasks have been processed. As a result, this works fine:\n\n```js\nconst tx = db.transaction('keyval', 'readwrite');\nconst store = tx.objectStore('keyval');\nconst val = (await store.get('counter')) || 0;\nawait store.put(val + 1, 'counter');\nawait tx.done;\n```\n\nBut this doesn't:\n\n```js\nconst tx = db.transaction('keyval', 'readwrite');\nconst store = tx.objectStore('keyval');\nconst val = (await store.get('counter')) || 0;\n// This is where things go wrong:\nconst newVal = await fetch('/increment?val=' + val);\n// And this throws an error:\nawait store.put(newVal, 'counter');\nawait tx.done;\n```\n\nIn this case, the transaction closes while the browser is fetching, so `store.put` fails.\n\n## `IDBDatabase` enhancements\n\n### Shortcuts to get/set from an object store\n\nIt's common to create a transaction for a single action, so helper methods are included for this:\n\n```js\n// Get a value from a store:\nconst value = await db.get(storeName, key);\n// Set a value in a store:\nawait db.put(storeName, value, key);\n```\n\nThe shortcuts are: `get`, `getKey`, `getAll`, `getAllKeys`, `count`, `put`, `add`, `delete`, and `clear`. Each method takes a `storeName` argument, the name of the object store, and the rest of the arguments are the same as the equivalent `IDBObjectStore` method.\n\n### Shortcuts to get from an index\n\nThe shortcuts are: `getFromIndex`, `getKeyFromIndex`, `getAllFromIndex`, `getAllKeysFromIndex`, and `countFromIndex`.\n\n```js\n// Get a value from an index:\nconst value = await db.getFromIndex(storeName, indexName, key);\n```\n\nEach method takes `storeName` and `indexName` arguments, followed by the rest of the arguments from the equivalent `IDBIndex` method.\n\n## `IDBTransaction` enhancements\n\n### `tx.store`\n\nIf a transaction involves a single store, the `store` property will reference that store.\n\n```js\nconst tx = db.transaction('whatever');\nconst store = tx.store;\n```\n\nIf a transaction involves multiple stores, `tx.store` is undefined, you need to use `tx.objectStore(storeName)` to get the stores.\n\n### `tx.done`\n\nTransactions have a `.done` promise which resolves when the transaction completes successfully, and otherwise rejects with the [transaction error](https://developer.mozilla.org/en-US/docs/Web/API/IDBTransaction/error).\n\n```js\nconst tx = db.transaction(storeName, 'readwrite');\nawait Promise.all([\n  tx.store.put('bar', 'foo'),\n  tx.store.put('world', 'hello'),\n  tx.done,\n]);\n```\n\nIf you're writing to the database, `tx.done` is the signal that everything was successfully committed to the database. However, it's still beneficial to await the individual operations, as you'll see the error that caused the transaction to fail.\n\n## `IDBCursor` enhancements\n\nCursor advance methods (`advance`, `continue`, `continuePrimaryKey`) return a promise for the cursor, or null if there are no further values to provide.\n\n```js\nlet cursor = await db.transaction(storeName).store.openCursor();\n\nwhile (cursor) {\n  console.log(cursor.key, cursor.value);\n  cursor = await cursor.continue();\n}\n```\n\n## Async iterators\n\nYou can iterate over stores, indexes, and cursors:\n\n```js\nconst tx = db.transaction(storeName);\n\nfor await (const cursor of tx.store) {\n  // …\n}\n```\n\nEach yielded object is an `IDBCursor`. You can optionally use the advance methods to skip items (within an async iterator they return void):\n\n```js\nconst tx = db.transaction(storeName);\n\nfor await (const cursor of tx.store) {\n  console.log(cursor.value);\n  // Skip the next item\n  cursor.advance(2);\n}\n```\n\nIf you don't manually advance the cursor, `cursor.continue()` is called for you.\n\nStores and indexes also have an `iterate` method which has the same signature as `openCursor`, but returns an async iterator:\n\n```js\nconst index = db.transaction('books').store.index('author');\n\nfor await (const cursor of index.iterate('Douglas Adams')) {\n  console.log(cursor.value);\n}\n```\n\n# Examples\n\n## Keyval store\n\nThis is very similar to `localStorage`, but async. If this is _all_ you need, you may be interested in [idb-keyval](https://www.npmjs.com/package/idb-keyval). You can always upgrade to this library later.\n\n```js\nimport { openDB } from 'idb';\n\nconst dbPromise = openDB('keyval-store', 1, {\n  upgrade(db) {\n    db.createObjectStore('keyval');\n  },\n});\n\nexport async function get(key) {\n  return (await dbPromise).get('keyval', key);\n}\nexport async function set(key, val) {\n  return (await dbPromise).put('keyval', val, key);\n}\nexport async function del(key) {\n  return (await dbPromise).delete('keyval', key);\n}\nexport async function clear() {\n  return (await dbPromise).clear('keyval');\n}\nexport async function keys() {\n  return (await dbPromise).getAllKeys('keyval');\n}\n```\n\n## Article store\n\n```js\nimport { openDB } from 'idb/with-async-ittr.js';\n\nasync function demo() {\n  const db = await openDB('Articles', 1, {\n    upgrade(db) {\n      // Create a store of objects\n      const store = db.createObjectStore('articles', {\n        // The 'id' property of the object will be the key.\n        keyPath: 'id',\n        // If it isn't explicitly set, create a value by auto incrementing.\n        autoIncrement: true,\n      });\n      // Create an index on the 'date' property of the objects.\n      store.createIndex('date', 'date');\n    },\n  });\n\n  // Add an article:\n  await db.add('articles', {\n    title: 'Article 1',\n    date: new Date('2019-01-01'),\n    body: '…',\n  });\n\n  // Add multiple articles in one transaction:\n  {\n    const tx = db.transaction('articles', 'readwrite');\n    await Promise.all([\n      tx.store.add({\n        title: 'Article 2',\n        date: new Date('2019-01-01'),\n        body: '…',\n      }),\n      tx.store.add({\n        title: 'Article 3',\n        date: new Date('2019-01-02'),\n        body: '…',\n      }),\n      tx.done,\n    ]);\n  }\n\n  // Get all the articles in date order:\n  console.log(await db.getAllFromIndex('articles', 'date'));\n\n  // Add 'And, happy new year!' to all articles on 2019-01-01:\n  {\n    const tx = db.transaction('articles', 'readwrite');\n    const index = tx.store.index('date');\n\n    for await (const cursor of index.iterate(new Date('2019-01-01'))) {\n      const article = { ...cursor.value };\n      article.body += ' And, happy new year!';\n      cursor.update(article);\n    }\n\n    await tx.done;\n  }\n}\n```\n\n# TypeScript\n\nThis library is fully typed, and you can improve things by providing types for your database:\n\n```ts\nimport { openDB, DBSchema } from 'idb';\n\ninterface MyDB extends DBSchema {\n  'favourite-number': {\n    key: string;\n    value: number;\n  };\n  products: {\n    value: {\n      name: string;\n      price: number;\n      productCode: string;\n    };\n    key: string;\n    indexes: { 'by-price': number };\n  };\n}\n\nasync function demo() {\n  const db = await openDB<MyDB>('my-db', 1, {\n    upgrade(db) {\n      db.createObjectStore('favourite-number');\n\n      const productStore = db.createObjectStore('products', {\n        keyPath: 'productCode',\n      });\n      productStore.createIndex('by-price', 'price');\n    },\n  });\n\n  // This works\n  await db.put('favourite-number', 7, 'Jen');\n  // This fails at compile time, as the 'favourite-number' store expects a number.\n  await db.put('favourite-number', 'Twelve', 'Jake');\n}\n```\n\nTo define types for your database, extend `DBSchema` with an interface where the keys are the names of your object stores.\n\nFor each value, provide an object where `value` is the type of values within the store, and `key` is the type of keys within the store.\n\nOptionally, `indexes` can contain a map of index names, to the type of key within that index.\n\nProvide this interface when calling `openDB`, and from then on your database will be strongly typed. This also allows your IDE to autocomplete the names of stores and indexes.\n\n## Opting out of types\n\nIf you call `openDB` without providing types, your database will use basic types. However, sometimes you'll need to interact with stores that aren't in your schema, perhaps during upgrades. In that case you can cast.\n\nLet's say we were renaming the 'favourite-number' store to 'fave-nums':\n\n```ts\nimport { openDB, DBSchema, IDBPDatabase } from 'idb';\n\ninterface MyDBV1 extends DBSchema {\n  'favourite-number': { key: string; value: number };\n}\n\ninterface MyDBV2 extends DBSchema {\n  'fave-num': { key: string; value: number };\n}\n\nconst db = await openDB<MyDBV2>('my-db', 2, {\n  async upgrade(db, oldVersion) {\n    // Cast a reference of the database to the old schema.\n    const v1Db = db as unknown as IDBPDatabase<MyDBV1>;\n\n    if (oldVersion < 1) {\n      v1Db.createObjectStore('favourite-number');\n    }\n    if (oldVersion < 2) {\n      const store = v1Db.createObjectStore('favourite-number');\n      store.name = 'fave-num';\n    }\n  },\n});\n```\n\nYou can also cast to a typeless database by omitting the type, eg `db as IDBPDatabase`.\n\nNote: Types like `IDBPDatabase` are used by TypeScript only. The implementation uses proxies under the hood.\n\n# Developing\n\n```sh\npnpm run dev\n```\n\nThis will also perform type testing.\n\nTo test, navigate to `build/test/` in a browser. You'll need to set up a [basic web server](https://www.npmjs.com/package/serve) for this.\n"
  },
  {
    "path": "generic-tsconfig.json",
    "content": "{\n  \"compilerOptions\": {\n    \"target\": \"ES2019\",\n    \"downlevelIteration\": true,\n    \"module\": \"esnext\",\n    \"strict\": true,\n    \"moduleResolution\": \"node\",\n    \"composite\": true,\n    \"declaration\": true,\n    \"allowSyntheticDefaultImports\": true,\n    \"noUnusedLocals\": true,\n    \"sourceMap\": false\n  }\n}\n"
  },
  {
    "path": "lib/size-report.mjs",
    "content": "/**\n * Copyright 2019 Google Inc. All Rights Reserved.\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *     http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { promisify } from 'util';\nimport { brotliCompress } from 'zlib';\nimport { promises as fsp } from 'fs';\n\nimport { glob } from 'glob';\nimport { filesize } from 'filesize';\n\nconst brCompress = promisify(brotliCompress);\n\n(async function () {\n  const paths = await glob('tmp/size-tests/*.js');\n  const entryPromises = paths.map(async (path) => {\n    const br = await brCompress(await fsp.readFile(path));\n    return [path, filesize(br.length), br.length];\n  });\n\n  for await (const entry of entryPromises) console.log(...entry);\n})();\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"idb\",\n  \"version\": \"8.0.3\",\n  \"description\": \"A small wrapper that makes IndexedDB usable\",\n  \"main\": \"./build/index.cjs\",\n  \"module\": \"./build/index.js\",\n  \"types\": \"./build/index.d.ts\",\n  \"exports\": {\n    \".\": {\n      \"types\": \"./build/index.d.ts\",\n      \"module\": \"./build/index.js\",\n      \"import\": \"./build/index.js\",\n      \"default\": \"./build/index.cjs\"\n    },\n    \"./build/*\": \"./build/*\",\n    \"./package.json\": \"./package.json\"\n  },\n  \"files\": [\n    \"build/**\",\n    \"with-*\",\n    \"CHANGELOG.md\"\n  ],\n  \"type\": \"module\",\n  \"scripts\": {\n    \"build\": \"cross-env PRODUCTION=1 rollup -c && node --experimental-modules lib/size-report.mjs\",\n    \"dev\": \"rollup -c --watch\",\n    \"prepack\": \"npm run build\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git://github.com/jakearchibald/idb.git\"\n  },\n  \"author\": \"Jake Archibald\",\n  \"license\": \"ISC\",\n  \"devDependencies\": {\n    \"@rollup/plugin-commonjs\": \"^28.0.3\",\n    \"@rollup/plugin-node-resolve\": \"^16.0.1\",\n    \"@rollup/plugin-terser\": \"^0.4.4\",\n    \"@rollup/plugin-typescript\": \"^12.1.2\",\n    \"@types/chai\": \"^5.2.2\",\n    \"@types/estree\": \"^1.0.7\",\n    \"@types/mocha\": \"^10.0.10\",\n    \"@types/node\": \"^22.15.14\",\n    \"chai\": \"^5.2.0\",\n    \"conditional-type-checks\": \"^1.0.6\",\n    \"cross-env\": \"^7.0.3\",\n    \"del\": \"^8.0.0\",\n    \"filesize\": \"^10.1.6\",\n    \"glob\": \"^11.0.2\",\n    \"mocha\": \"^11.2.2\",\n    \"prettier\": \"^3.5.3\",\n    \"rollup\": \"^4.40.2\",\n    \"tslib\": \"^2.8.1\",\n    \"typescript\": \"^5.8.3\"\n  }\n}\n"
  },
  {
    "path": "rollup.config.mjs",
    "content": "import { promises as fsp } from 'fs';\nimport { basename } from 'path';\n\nimport terser from '@rollup/plugin-terser';\nimport resolve from '@rollup/plugin-node-resolve';\nimport commonjs from '@rollup/plugin-commonjs';\nimport typescript from '@rollup/plugin-typescript';\nimport { deleteAsync } from 'del';\nimport { glob } from 'glob';\n\nexport default async function ({ watch }) {\n  await deleteAsync(['.ts-tmp', 'build', 'tmp']);\n\n  const builds = [];\n\n  // Main\n  builds.push({\n    plugins: [\n      typescript({ cacheDir: '.ts-tmp', tsconfig: 'src/tsconfig.json' }),\n    ],\n    input: ['src/index.ts'],\n    output: [\n      {\n        dir: 'build/',\n        format: 'esm',\n        entryFileNames: '[name].js',\n        chunkFileNames: '[name].js',\n      },\n      {\n        dir: 'build/',\n        format: 'cjs',\n        entryFileNames: '[name].cjs',\n        chunkFileNames: '[name].cjs',\n      },\n    ],\n  });\n\n  // Minified iife\n  builds.push({\n    input: 'build/index.js',\n    plugins: [\n      terser({\n        compress: { ecma: 2019 },\n      }),\n    ],\n    output: {\n      file: 'build/umd.js',\n      format: 'umd',\n      esModule: false,\n      name: 'idb',\n    },\n  });\n\n  // Tests\n  if (!process.env.PRODUCTION) {\n    builds.push({\n      plugins: [\n        typescript({ cacheDir: '.ts-tmp', tsconfig: 'test/tsconfig.json' }),\n        resolve(),\n        commonjs(),\n        {\n          async generateBundle() {\n            this.emitFile({\n              type: 'asset',\n              source: await fsp.readFile('test/index.html'),\n              fileName: 'index.html',\n            });\n          },\n        },\n      ],\n      input: [\n        'test/index.ts',\n        'test/main.ts',\n        'test/open.ts',\n        'test/iterate.ts',\n      ],\n      output: {\n        dir: 'build/test',\n        format: 'esm',\n      },\n    });\n  }\n\n  builds.push(\n    ...(await glob('size-tests/*.js').then((paths) =>\n      paths.map((path) => ({\n        input: path,\n        plugins: [\n          terser({\n            compress: { ecma: 2020 },\n          }),\n        ],\n        output: [\n          {\n            file: `tmp/size-tests/${basename(path)}`,\n            format: 'esm',\n          },\n        ],\n      })),\n    )),\n  );\n\n  return builds;\n}\n"
  },
  {
    "path": "size-tests/main.js",
    "content": "import { openDB } from '../build/index';\na(openDB);\n"
  },
  {
    "path": "src/async-iterators.ts",
    "content": "import { instanceOfAny, Func } from './util.js';\nimport { replaceTraps, reverseTransformCache, unwrap } from './wrap-idb-value.js';\nimport { IDBPObjectStore, IDBPIndex, IDBPCursor } from './entry.js';\n\nconst advanceMethodProps = ['continue', 'continuePrimaryKey', 'advance'];\nconst methodMap: { [s: string]: Func } = {};\nconst advanceResults = new WeakMap<IDBPCursor, Promise<IDBPCursor | null>>();\nconst ittrProxiedCursorToOriginalProxy = new WeakMap<IDBPCursor, IDBPCursor>();\n\nconst cursorIteratorTraps: ProxyHandler<any> = {\n  get(target, prop) {\n    if (!advanceMethodProps.includes(prop as string)) return target[prop];\n\n    let cachedFunc = methodMap[prop as string];\n\n    if (!cachedFunc) {\n      cachedFunc = methodMap[prop as string] = function (\n        this: IDBPCursor,\n        ...args: any\n      ) {\n        advanceResults.set(\n          this,\n          (ittrProxiedCursorToOriginalProxy.get(this) as any)[prop](...args),\n        );\n      };\n    }\n\n    return cachedFunc;\n  },\n};\n\nasync function* iterate(\n  this: IDBPObjectStore | IDBPIndex | IDBPCursor,\n  ...args: any[]\n): AsyncIterableIterator<any> {\n  // tslint:disable-next-line:no-this-assignment\n  let cursor: typeof this | null = this;\n\n  if (!(cursor instanceof IDBCursor)) {\n    cursor = await (cursor as IDBPObjectStore | IDBPIndex).openCursor(...args);\n  }\n\n  if (!cursor) return;\n\n  cursor = cursor as IDBPCursor;\n  const proxiedCursor = new Proxy(cursor, cursorIteratorTraps);\n  ittrProxiedCursorToOriginalProxy.set(proxiedCursor, cursor);\n  // Map this double-proxy back to the original, so other cursor methods work.\n  reverseTransformCache.set(proxiedCursor, unwrap(cursor));\n\n  while (cursor) {\n    yield proxiedCursor;\n    // If one of the advancing methods was not called, call continue().\n    cursor = await (advanceResults.get(proxiedCursor) || cursor.continue());\n    advanceResults.delete(proxiedCursor);\n  }\n}\n\nfunction isIteratorProp(target: any, prop: number | string | symbol) {\n  return (\n    (prop === Symbol.asyncIterator &&\n      instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor])) ||\n    (prop === 'iterate' && instanceOfAny(target, [IDBIndex, IDBObjectStore]))\n  );\n}\n\nreplaceTraps((oldTraps) => ({\n  ...oldTraps,\n  get(target, prop, receiver) {\n    if (isIteratorProp(target, prop)) return iterate;\n    return oldTraps.get!(target, prop, receiver);\n  },\n  has(target, prop) {\n    return isIteratorProp(target, prop) || oldTraps.has!(target, prop);\n  },\n}));\n"
  },
  {
    "path": "src/database-extras.ts",
    "content": "import { Func } from './util.js';\nimport { replaceTraps } from './wrap-idb-value.js';\nimport { IDBPDatabase, IDBPIndex } from './entry.js';\n\nconst readMethods = ['get', 'getKey', 'getAll', 'getAllKeys', 'count'];\nconst writeMethods = ['put', 'add', 'delete', 'clear'];\nconst cachedMethods = new Map<string, Func>();\n\nfunction getMethod(\n  target: any,\n  prop: string | number | symbol,\n): Func | undefined {\n  if (\n    !(\n      target instanceof IDBDatabase &&\n      !(prop in target) &&\n      typeof prop === 'string'\n    )\n  ) {\n    return;\n  }\n\n  if (cachedMethods.get(prop)) return cachedMethods.get(prop);\n\n  const targetFuncName: string = prop.replace(/FromIndex$/, '');\n  const useIndex = prop !== targetFuncName;\n  const isWrite = writeMethods.includes(targetFuncName);\n\n  if (\n    // Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.\n    !(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) ||\n    !(isWrite || readMethods.includes(targetFuncName))\n  ) {\n    return;\n  }\n\n  const method = async function (\n    this: IDBPDatabase,\n    storeName: string,\n    ...args: any[]\n  ) {\n    // isWrite ? 'readwrite' : undefined gzipps better, but fails in Edge :(\n    const tx = this.transaction(storeName, isWrite ? 'readwrite' : 'readonly');\n    let target:\n      | typeof tx.store\n      | IDBPIndex<unknown, string[], string, string, 'readwrite' | 'readonly'> =\n      tx.store;\n    if (useIndex) target = target.index(args.shift());\n\n    // Must reject if op rejects.\n    // If it's a write operation, must reject if tx.done rejects.\n    // Must reject with op rejection first.\n    // Must resolve with op value.\n    // Must handle both promises (no unhandled rejections)\n    return (\n      await Promise.all([\n        (target as any)[targetFuncName](...args),\n        isWrite && tx.done,\n      ])\n    )[0];\n  };\n\n  cachedMethods.set(prop, method);\n  return method;\n}\n\nreplaceTraps((oldTraps) => ({\n  ...oldTraps,\n  get: (target, prop, receiver) =>\n    getMethod(target, prop) || oldTraps.get!(target, prop, receiver),\n  has: (target, prop) =>\n    !!getMethod(target, prop) || oldTraps.has!(target, prop),\n}));\n"
  },
  {
    "path": "src/entry.ts",
    "content": "import { wrap } from './wrap-idb-value.js';\n\nexport interface OpenDBCallbacks<DBTypes extends DBSchema | unknown> {\n  /**\n   * Called if this version of the database has never been opened before. Use it to specify the\n   * schema for the database.\n   *\n   * @param database A database instance that you can use to add/remove stores and indexes.\n   * @param oldVersion Last version of the database opened by the user.\n   * @param newVersion Whatever new version you provided.\n   * @param transaction The transaction for this upgrade.\n   * This is useful if you need to get data from other stores as part of a migration.\n   * @param event The event object for the associated 'upgradeneeded' event.\n   */\n  upgrade?(\n    database: IDBPDatabase<DBTypes>,\n    oldVersion: number,\n    newVersion: number | null,\n    transaction: IDBPTransaction<\n      DBTypes,\n      StoreNames<DBTypes>[],\n      'versionchange'\n    >,\n    event: IDBVersionChangeEvent,\n  ): void;\n  /**\n   * Called if there are older versions of the database open on the origin, so this version cannot\n   * open.\n   *\n   * @param currentVersion Version of the database that's blocking this one.\n   * @param blockedVersion The version of the database being blocked (whatever version you provided to `openDB`).\n   * @param event The event object for the associated `blocked` event.\n   */\n  blocked?(\n    currentVersion: number,\n    blockedVersion: number | null,\n    event: IDBVersionChangeEvent,\n  ): void;\n  /**\n   * Called if this connection is blocking a future version of the database from opening.\n   *\n   * @param currentVersion Version of the open database (whatever version you provided to `openDB`).\n   * @param blockedVersion The version of the database that's being blocked.\n   * @param event The event object for the associated `versionchange` event.\n   */\n  blocking?(\n    currentVersion: number,\n    blockedVersion: number | null,\n    event: IDBVersionChangeEvent,\n  ): void;\n  /**\n   * Called if the browser abnormally terminates the connection.\n   * This is not called when `db.close()` is called.\n   */\n  terminated?(): void;\n}\n\n/**\n * Open a database.\n *\n * @param name Name of the database.\n * @param version Schema version.\n * @param callbacks Additional callbacks.\n */\nexport function openDB<DBTypes extends DBSchema | unknown = unknown>(\n  name: string,\n  version?: number,\n  { blocked, upgrade, blocking, terminated }: OpenDBCallbacks<DBTypes> = {},\n): Promise<IDBPDatabase<DBTypes>> {\n  const request = indexedDB.open(name, version);\n  const openPromise = wrap(request) as Promise<IDBPDatabase<DBTypes>>;\n\n  if (upgrade) {\n    request.addEventListener('upgradeneeded', (event) => {\n      upgrade(\n        wrap(request.result) as IDBPDatabase<DBTypes>,\n        event.oldVersion,\n        event.newVersion,\n        wrap(request.transaction!) as unknown as IDBPTransaction<\n          DBTypes,\n          StoreNames<DBTypes>[],\n          'versionchange'\n        >,\n        event,\n      );\n    });\n  }\n\n  if (blocked) {\n    request.addEventListener('blocked', (event) =>\n      blocked(\n        // Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405\n        (event as IDBVersionChangeEvent).oldVersion,\n        (event as IDBVersionChangeEvent).newVersion,\n        event as IDBVersionChangeEvent,\n      ),\n    );\n  }\n\n  openPromise\n    .then((db) => {\n      if (terminated) db.addEventListener('close', () => terminated());\n      if (blocking) {\n        db.addEventListener('versionchange', (event) =>\n          blocking(event.oldVersion, event.newVersion, event),\n        );\n      }\n    })\n    .catch(() => {});\n\n  return openPromise;\n}\n\nexport interface DeleteDBCallbacks {\n  /**\n   * Called if there are connections to this database open, so it cannot be deleted.\n   *\n   * @param currentVersion Version of the database that's blocking the delete operation.\n   * @param event The event object for the associated `blocked` event.\n   */\n  blocked?(currentVersion: number, event: IDBVersionChangeEvent): void;\n}\n\n/**\n * Delete a database.\n *\n * @param name Name of the database.\n */\nexport function deleteDB(\n  name: string,\n  { blocked }: DeleteDBCallbacks = {},\n): Promise<void> {\n  const request = indexedDB.deleteDatabase(name);\n\n  if (blocked) {\n    request.addEventListener('blocked', (event) =>\n      blocked(\n        // Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405\n        (event as IDBVersionChangeEvent).oldVersion,\n        event as IDBVersionChangeEvent,\n      ),\n    );\n  }\n\n  return wrap(request).then(() => undefined);\n}\n\nexport { unwrap, wrap } from './wrap-idb-value.js';\n\n// === The rest of this file is type defs ===\ntype KeyToKeyNoIndex<T> = {\n  [K in keyof T]: string extends K ? never : number extends K ? never : K;\n};\ntype ValuesOf<T> = T extends { [K in keyof T]: infer U } ? U : never;\ntype KnownKeys<T> = ValuesOf<KeyToKeyNoIndex<T>>;\n\ntype Omit<T, K> = Pick<T, Exclude<keyof T, K>>;\n\nexport interface DBSchema {\n  [s: string]: DBSchemaValue;\n}\n\ninterface IndexKeys {\n  [s: string]: IDBValidKey;\n}\n\ninterface DBSchemaValue {\n  key: IDBValidKey;\n  value: any;\n  indexes?: IndexKeys;\n}\n\n/**\n * Extract known object store names from the DB schema type.\n *\n * @template DBTypes DB schema type, or unknown if the DB isn't typed.\n */\nexport type StoreNames<DBTypes extends DBSchema | unknown> =\n  DBTypes extends DBSchema ? KnownKeys<DBTypes> : string;\n\n/**\n * Extract database value types from the DB schema type.\n *\n * @template DBTypes DB schema type, or unknown if the DB isn't typed.\n * @template StoreName Names of the object stores to get the types of.\n */\nexport type StoreValue<\n  DBTypes extends DBSchema | unknown,\n  StoreName extends StoreNames<DBTypes>,\n> = DBTypes extends DBSchema ? DBTypes[StoreName]['value'] : any;\n\n/**\n * Extract database key types from the DB schema type.\n *\n * @template DBTypes DB schema type, or unknown if the DB isn't typed.\n * @template StoreName Names of the object stores to get the types of.\n */\nexport type StoreKey<\n  DBTypes extends DBSchema | unknown,\n  StoreName extends StoreNames<DBTypes>,\n> = DBTypes extends DBSchema ? DBTypes[StoreName]['key'] : IDBValidKey;\n\n/**\n * Extract the names of indexes in certain object stores from the DB schema type.\n *\n * @template DBTypes DB schema type, or unknown if the DB isn't typed.\n * @template StoreName Names of the object stores to get the types of.\n */\nexport type IndexNames<\n  DBTypes extends DBSchema | unknown,\n  StoreName extends StoreNames<DBTypes>,\n> = DBTypes extends DBSchema ? keyof DBTypes[StoreName]['indexes'] & string : string;\n\n/**\n * Extract the types of indexes in certain object stores from the DB schema type.\n *\n * @template DBTypes DB schema type, or unknown if the DB isn't typed.\n * @template StoreName Names of the object stores to get the types of.\n * @template IndexName Names of the indexes to get the types of.\n */\nexport type IndexKey<\n  DBTypes extends DBSchema | unknown,\n  StoreName extends StoreNames<DBTypes>,\n  IndexName extends IndexNames<DBTypes, StoreName>,\n> = DBTypes extends DBSchema\n  ? IndexName extends keyof DBTypes[StoreName]['indexes']\n    ? DBTypes[StoreName]['indexes'][IndexName]\n    : IDBValidKey\n  : IDBValidKey;\n\ntype CursorSource<\n  DBTypes extends DBSchema | unknown,\n  TxStores extends ArrayLike<StoreNames<DBTypes>>,\n  StoreName extends StoreNames<DBTypes>,\n  IndexName extends IndexNames<DBTypes, StoreName> | unknown,\n  Mode extends IDBTransactionMode = 'readonly',\n> = IndexName extends IndexNames<DBTypes, StoreName>\n  ? IDBPIndex<DBTypes, TxStores, StoreName, IndexName, Mode>\n  : IDBPObjectStore<DBTypes, TxStores, StoreName, Mode>;\n\ntype CursorKey<\n  DBTypes extends DBSchema | unknown,\n  StoreName extends StoreNames<DBTypes>,\n  IndexName extends IndexNames<DBTypes, StoreName> | unknown,\n> = IndexName extends IndexNames<DBTypes, StoreName>\n  ? IndexKey<DBTypes, StoreName, IndexName>\n  : StoreKey<DBTypes, StoreName>;\n\ntype IDBPDatabaseExtends = Omit<\n  IDBDatabase,\n  'createObjectStore' | 'deleteObjectStore' | 'transaction' | 'objectStoreNames'\n>;\n\nexport type DOMStringListSymbolIteratorType = DOMStringList extends { [Symbol.iterator](): infer R } ? R : IterableIterator<string>;\n\n/**\n * A variation of DOMStringList with precise string types\n */\nexport interface TypedDOMStringList<T extends string> extends DOMStringList {\n  contains(string: T): boolean;\n  item(index: number): T | null;\n  [index: number]: T;\n\n  /**\n   * To resolve https://github.com/jakearchibald/idb/issues/327,\n   * and for compatibility with TypeScript >= 5.6 with ArrayIterator.\n   */\n  [Symbol.iterator](): IterableIterator<string> extends DOMStringListSymbolIteratorType ? IterableIterator<T> : DOMStringListSymbolIteratorType & Iterator<T>;\n}\n\ninterface IDBTransactionOptions {\n  /**\n   * The durability of the transaction.\n   *\n   * The default is \"default\". Using \"relaxed\" provides better performance, but with fewer\n   * guarantees. Web applications are encouraged to use \"relaxed\" for ephemeral data such as caches\n   * or quickly changing records, and \"strict\" in cases where reducing the risk of data loss\n   * outweighs the impact to performance and power.\n   */\n  durability?: 'default' | 'strict' | 'relaxed';\n}\n\nexport interface IDBPDatabase<DBTypes extends DBSchema | unknown = unknown>\n  extends IDBPDatabaseExtends {\n  /**\n   * The names of stores in the database.\n   */\n  readonly objectStoreNames: TypedDOMStringList<StoreNames<DBTypes>>;\n  /**\n   * Creates a new object store.\n   *\n   * Throws a \"InvalidStateError\" DOMException if not called within an upgrade transaction.\n   */\n  createObjectStore<Name extends StoreNames<DBTypes>>(\n    name: Name,\n    optionalParameters?: IDBObjectStoreParameters,\n  ): IDBPObjectStore<\n    DBTypes,\n    ArrayLike<StoreNames<DBTypes>>,\n    Name,\n    'versionchange'\n  >;\n  /**\n   * Deletes the object store with the given name.\n   *\n   * Throws a \"InvalidStateError\" DOMException if not called within an upgrade transaction.\n   */\n  deleteObjectStore(name: StoreNames<DBTypes>): void;\n  /**\n   * Start a new transaction.\n   *\n   * @param storeNames The object store(s) this transaction needs.\n   * @param mode\n   * @param options\n   */\n  transaction<\n    Name extends StoreNames<DBTypes>,\n    Mode extends IDBTransactionMode = 'readonly',\n  >(\n    storeNames: Name,\n    mode?: Mode,\n    options?: IDBTransactionOptions,\n  ): IDBPTransaction<DBTypes, [Name], Mode>;\n  transaction<\n    Names extends ArrayLike<StoreNames<DBTypes>>,\n    Mode extends IDBTransactionMode = 'readonly',\n  >(\n    storeNames: Names,\n    mode?: Mode,\n    options?: IDBTransactionOptions,\n  ): IDBPTransaction<DBTypes, Names, Mode>;\n\n  // Shortcut methods\n\n  /**\n   * Add a value to a store.\n   *\n   * Rejects if an item of a given key already exists in the store.\n   *\n   * This is a shortcut that creates a transaction for this single action. If you need to do more\n   * than one action, create a transaction instead.\n   *\n   * @param storeName Name of the store.\n   * @param value\n   * @param key\n   */\n  add<Name extends StoreNames<DBTypes>>(\n    storeName: Name,\n    value: StoreValue<DBTypes, Name>,\n    key?: StoreKey<DBTypes, Name> | IDBKeyRange,\n  ): Promise<StoreKey<DBTypes, Name>>;\n  /**\n   * Deletes all records in a store.\n   *\n   * This is a shortcut that creates a transaction for this single action. If you need to do more\n   * than one action, create a transaction instead.\n   *\n   * @param storeName Name of the store.\n   */\n  clear(name: StoreNames<DBTypes>): Promise<void>;\n  /**\n   * Retrieves the number of records matching the given query in a store.\n   *\n   * This is a shortcut that creates a transaction for this single action. If you need to do more\n   * than one action, create a transaction instead.\n   *\n   * @param storeName Name of the store.\n   * @param key\n   */\n  count<Name extends StoreNames<DBTypes>>(\n    storeName: Name,\n    key?: StoreKey<DBTypes, Name> | IDBKeyRange | null,\n  ): Promise<number>;\n  /**\n   * Retrieves the number of records matching the given query in an index.\n   *\n   * This is a shortcut that creates a transaction for this single action. If you need to do more\n   * than one action, create a transaction instead.\n   *\n   * @param storeName Name of the store.\n   * @param indexName Name of the index within the store.\n   * @param key\n   */\n  countFromIndex<\n    Name extends StoreNames<DBTypes>,\n    IndexName extends IndexNames<DBTypes, Name>,\n  >(\n    storeName: Name,\n    indexName: IndexName,\n    key?: IndexKey<DBTypes, Name, IndexName> | IDBKeyRange | null,\n  ): Promise<number>;\n  /**\n   * Deletes records in a store matching the given query.\n   *\n   * This is a shortcut that creates a transaction for this single action. If you need to do more\n   * than one action, create a transaction instead.\n   *\n   * @param storeName Name of the store.\n   * @param key\n   */\n  delete<Name extends StoreNames<DBTypes>>(\n    storeName: Name,\n    key: StoreKey<DBTypes, Name> | IDBKeyRange,\n  ): Promise<void>;\n  /**\n   * Retrieves the value of the first record in a store matching the query.\n   *\n   * Resolves with undefined if no match is found.\n   *\n   * This is a shortcut that creates a transaction for this single action. If you need to do more\n   * than one action, create a transaction instead.\n   *\n   * @param storeName Name of the store.\n   * @param query\n   */\n  get<Name extends StoreNames<DBTypes>>(\n    storeName: Name,\n    query: StoreKey<DBTypes, Name> | IDBKeyRange,\n  ): Promise<StoreValue<DBTypes, Name> | undefined>;\n  /**\n   * Retrieves the value of the first record in an index matching the query.\n   *\n   * Resolves with undefined if no match is found.\n   *\n   * This is a shortcut that creates a transaction for this single action. If you need to do more\n   * than one action, create a transaction instead.\n   *\n   * @param storeName Name of the store.\n   * @param indexName Name of the index within the store.\n   * @param query\n   */\n  getFromIndex<\n    Name extends StoreNames<DBTypes>,\n    IndexName extends IndexNames<DBTypes, Name>,\n  >(\n    storeName: Name,\n    indexName: IndexName,\n    query: IndexKey<DBTypes, Name, IndexName> | IDBKeyRange,\n  ): Promise<StoreValue<DBTypes, Name> | undefined>;\n  /**\n   * Retrieves all values in a store that match the query.\n   *\n   * This is a shortcut that creates a transaction for this single action. If you need to do more\n   * than one action, create a transaction instead.\n   *\n   * @param storeName Name of the store.\n   * @param query\n   * @param count Maximum number of values to return.\n   */\n  getAll<Name extends StoreNames<DBTypes>>(\n    storeName: Name,\n    query?: StoreKey<DBTypes, Name> | IDBKeyRange | null,\n    count?: number,\n  ): Promise<StoreValue<DBTypes, Name>[]>;\n  /**\n   * Retrieves all values in an index that match the query.\n   *\n   * This is a shortcut that creates a transaction for this single action. If you need to do more\n   * than one action, create a transaction instead.\n   *\n   * @param storeName Name of the store.\n   * @param indexName Name of the index within the store.\n   * @param query\n   * @param count Maximum number of values to return.\n   */\n  getAllFromIndex<\n    Name extends StoreNames<DBTypes>,\n    IndexName extends IndexNames<DBTypes, Name>,\n  >(\n    storeName: Name,\n    indexName: IndexName,\n    query?: IndexKey<DBTypes, Name, IndexName> | IDBKeyRange | null,\n    count?: number,\n  ): Promise<StoreValue<DBTypes, Name>[]>;\n  /**\n   * Retrieves the keys of records in a store matching the query.\n   *\n   * This is a shortcut that creates a transaction for this single action. If you need to do more\n   * than one action, create a transaction instead.\n   *\n   * @param storeName Name of the store.\n   * @param query\n   * @param count Maximum number of keys to return.\n   */\n  getAllKeys<Name extends StoreNames<DBTypes>>(\n    storeName: Name,\n    query?: StoreKey<DBTypes, Name> | IDBKeyRange | null,\n    count?: number,\n  ): Promise<StoreKey<DBTypes, Name>[]>;\n  /**\n   * Retrieves the keys of records in an index matching the query.\n   *\n   * This is a shortcut that creates a transaction for this single action. If you need to do more\n   * than one action, create a transaction instead.\n   *\n   * @param storeName Name of the store.\n   * @param indexName Name of the index within the store.\n   * @param query\n   * @param count Maximum number of keys to return.\n   */\n  getAllKeysFromIndex<\n    Name extends StoreNames<DBTypes>,\n    IndexName extends IndexNames<DBTypes, Name>,\n  >(\n    storeName: Name,\n    indexName: IndexName,\n    query?: IndexKey<DBTypes, Name, IndexName> | IDBKeyRange | null,\n    count?: number,\n  ): Promise<StoreKey<DBTypes, Name>[]>;\n  /**\n   * Retrieves the key of the first record in a store that matches the query.\n   *\n   * Resolves with undefined if no match is found.\n   *\n   * This is a shortcut that creates a transaction for this single action. If you need to do more\n   * than one action, create a transaction instead.\n   *\n   * @param storeName Name of the store.\n   * @param query\n   */\n  getKey<Name extends StoreNames<DBTypes>>(\n    storeName: Name,\n    query: StoreKey<DBTypes, Name> | IDBKeyRange,\n  ): Promise<StoreKey<DBTypes, Name> | undefined>;\n  /**\n   * Retrieves the key of the first record in an index that matches the query.\n   *\n   * Resolves with undefined if no match is found.\n   *\n   * This is a shortcut that creates a transaction for this single action. If you need to do more\n   * than one action, create a transaction instead.\n   *\n   * @param storeName Name of the store.\n   * @param indexName Name of the index within the store.\n   * @param query\n   */\n  getKeyFromIndex<\n    Name extends StoreNames<DBTypes>,\n    IndexName extends IndexNames<DBTypes, Name>,\n  >(\n    storeName: Name,\n    indexName: IndexName,\n    query: IndexKey<DBTypes, Name, IndexName> | IDBKeyRange,\n  ): Promise<StoreKey<DBTypes, Name> | undefined>;\n  /**\n   * Put an item in the database.\n   *\n   * Replaces any item with the same key.\n   *\n   * This is a shortcut that creates a transaction for this single action. If you need to do more\n   * than one action, create a transaction instead.\n   *\n   * @param storeName Name of the store.\n   * @param value\n   * @param key\n   */\n  put<Name extends StoreNames<DBTypes>>(\n    storeName: Name,\n    value: StoreValue<DBTypes, Name>,\n    key?: StoreKey<DBTypes, Name> | IDBKeyRange,\n  ): Promise<StoreKey<DBTypes, Name>>;\n}\n\ntype IDBPTransactionExtends = Omit<\n  IDBTransaction,\n  'db' | 'objectStore' | 'objectStoreNames'\n>;\n\nexport interface IDBPTransaction<\n  DBTypes extends DBSchema | unknown = unknown,\n  TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<\n    StoreNames<DBTypes>\n  >,\n  Mode extends IDBTransactionMode = 'readonly',\n> extends IDBPTransactionExtends {\n  /**\n   * The transaction's mode.\n   */\n  readonly mode: Mode;\n  /**\n   * The names of stores in scope for this transaction.\n   */\n  readonly objectStoreNames: TypedDOMStringList<TxStores[number]>;\n  /**\n   * The transaction's connection.\n   */\n  readonly db: IDBPDatabase<DBTypes>;\n  /**\n   * Promise for the completion of this transaction.\n   */\n  readonly done: Promise<void>;\n  /**\n   * The associated object store, if the transaction covers a single store, otherwise undefined.\n   */\n  readonly store: TxStores[1] extends undefined\n    ? IDBPObjectStore<DBTypes, TxStores, TxStores[0], Mode>\n    : undefined;\n  /**\n   * Returns an IDBObjectStore in the transaction's scope.\n   */\n  objectStore<StoreName extends TxStores[number]>(\n    name: StoreName,\n  ): IDBPObjectStore<DBTypes, TxStores, StoreName, Mode>;\n}\n\ntype IDBPObjectStoreExtends = Omit<\n  IDBObjectStore,\n  | 'transaction'\n  | 'add'\n  | 'clear'\n  | 'count'\n  | 'createIndex'\n  | 'delete'\n  | 'get'\n  | 'getAll'\n  | 'getAllKeys'\n  | 'getKey'\n  | 'index'\n  | 'openCursor'\n  | 'openKeyCursor'\n  | 'put'\n  | 'indexNames'\n>;\n\nexport interface IDBPObjectStore<\n  DBTypes extends DBSchema | unknown = unknown,\n  TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<\n    StoreNames<DBTypes>\n  >,\n  StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>,\n  Mode extends IDBTransactionMode = 'readonly',\n> extends IDBPObjectStoreExtends {\n  /**\n   * The names of indexes in the store.\n   */\n  readonly indexNames: TypedDOMStringList<IndexNames<DBTypes, StoreName>>;\n  /**\n   * The associated transaction.\n   */\n  readonly transaction: IDBPTransaction<DBTypes, TxStores, Mode>;\n  /**\n   * Add a value to the store.\n   *\n   * Rejects if an item of a given key already exists in the store.\n   */\n  add: Mode extends 'readonly'\n    ? undefined\n    : (\n        value: StoreValue<DBTypes, StoreName>,\n        key?: StoreKey<DBTypes, StoreName> | IDBKeyRange,\n      ) => Promise<StoreKey<DBTypes, StoreName>>;\n  /**\n   * Deletes all records in store.\n   */\n  clear: Mode extends 'readonly' ? undefined : () => Promise<void>;\n  /**\n   * Retrieves the number of records matching the given query.\n   */\n  count(\n    key?: StoreKey<DBTypes, StoreName> | IDBKeyRange | null,\n  ): Promise<number>;\n  /**\n   * Creates a new index in store.\n   *\n   * Throws an \"InvalidStateError\" DOMException if not called within an upgrade transaction.\n   */\n  createIndex: Mode extends 'versionchange'\n    ? <IndexName extends IndexNames<DBTypes, StoreName>>(\n        name: IndexName,\n        keyPath: string | string[],\n        options?: IDBIndexParameters,\n      ) => IDBPIndex<DBTypes, TxStores, StoreName, IndexName, Mode>\n    : undefined;\n  /**\n   * Deletes records in store matching the given query.\n   */\n  delete: Mode extends 'readonly'\n    ? undefined\n    : (key: StoreKey<DBTypes, StoreName> | IDBKeyRange) => Promise<void>;\n  /**\n   * Retrieves the value of the first record matching the query.\n   *\n   * Resolves with undefined if no match is found.\n   */\n  get(\n    query: StoreKey<DBTypes, StoreName> | IDBKeyRange,\n  ): Promise<StoreValue<DBTypes, StoreName> | undefined>;\n  /**\n   * Retrieves all values that match the query.\n   *\n   * @param query\n   * @param count Maximum number of values to return.\n   */\n  getAll(\n    query?: StoreKey<DBTypes, StoreName> | IDBKeyRange | null,\n    count?: number,\n  ): Promise<StoreValue<DBTypes, StoreName>[]>;\n  /**\n   * Retrieves the keys of records matching the query.\n   *\n   * @param query\n   * @param count Maximum number of keys to return.\n   */\n  getAllKeys(\n    query?: StoreKey<DBTypes, StoreName> | IDBKeyRange | null,\n    count?: number,\n  ): Promise<StoreKey<DBTypes, StoreName>[]>;\n  /**\n   * Retrieves the key of the first record that matches the query.\n   *\n   * Resolves with undefined if no match is found.\n   */\n  getKey(\n    query: StoreKey<DBTypes, StoreName> | IDBKeyRange,\n  ): Promise<StoreKey<DBTypes, StoreName> | undefined>;\n  /**\n   * Get a query of a given name.\n   */\n  index<IndexName extends IndexNames<DBTypes, StoreName>>(\n    name: IndexName,\n  ): IDBPIndex<DBTypes, TxStores, StoreName, IndexName, Mode>;\n  /**\n   * Opens a cursor over the records matching the query.\n   *\n   * Resolves with null if no matches are found.\n   *\n   * @param query If null, all records match.\n   * @param direction\n   */\n  openCursor(\n    query?: StoreKey<DBTypes, StoreName> | IDBKeyRange | null,\n    direction?: IDBCursorDirection,\n  ): Promise<IDBPCursorWithValue<\n    DBTypes,\n    TxStores,\n    StoreName,\n    unknown,\n    Mode\n  > | null>;\n  /**\n   * Opens a cursor over the keys matching the query.\n   *\n   * Resolves with null if no matches are found.\n   *\n   * @param query If null, all records match.\n   * @param direction\n   */\n  openKeyCursor(\n    query?: StoreKey<DBTypes, StoreName> | IDBKeyRange | null,\n    direction?: IDBCursorDirection,\n  ): Promise<IDBPCursor<DBTypes, TxStores, StoreName, unknown, Mode> | null>;\n  /**\n   * Put an item in the store.\n   *\n   * Replaces any item with the same key.\n   */\n  put: Mode extends 'readonly'\n    ? undefined\n    : (\n        value: StoreValue<DBTypes, StoreName>,\n        key?: StoreKey<DBTypes, StoreName> | IDBKeyRange,\n      ) => Promise<StoreKey<DBTypes, StoreName>>;\n  /**\n   * Iterate over the store.\n   */\n  [Symbol.asyncIterator](): AsyncIterableIterator<\n    IDBPCursorWithValueIteratorValue<\n      DBTypes,\n      TxStores,\n      StoreName,\n      unknown,\n      Mode\n    >\n  >;\n  /**\n   * Iterate over the records matching the query.\n   *\n   * @param query If null, all records match.\n   * @param direction\n   */\n  iterate(\n    query?: StoreKey<DBTypes, StoreName> | IDBKeyRange | null,\n    direction?: IDBCursorDirection,\n  ): AsyncIterableIterator<\n    IDBPCursorWithValueIteratorValue<\n      DBTypes,\n      TxStores,\n      StoreName,\n      unknown,\n      Mode\n    >\n  >;\n}\n\ntype IDBPIndexExtends = Omit<\n  IDBIndex,\n  | 'objectStore'\n  | 'count'\n  | 'get'\n  | 'getAll'\n  | 'getAllKeys'\n  | 'getKey'\n  | 'openCursor'\n  | 'openKeyCursor'\n>;\n\nexport interface IDBPIndex<\n  DBTypes extends DBSchema | unknown = unknown,\n  TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<\n    StoreNames<DBTypes>\n  >,\n  StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>,\n  IndexName extends IndexNames<DBTypes, StoreName> = IndexNames<\n    DBTypes,\n    StoreName\n  >,\n  Mode extends IDBTransactionMode = 'readonly',\n> extends IDBPIndexExtends {\n  /**\n   * The IDBObjectStore the index belongs to.\n   */\n  readonly objectStore: IDBPObjectStore<DBTypes, TxStores, StoreName, Mode>;\n\n  /**\n   * Retrieves the number of records matching the given query.\n   */\n  count(\n    key?: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange | null,\n  ): Promise<number>;\n  /**\n   * Retrieves the value of the first record matching the query.\n   *\n   * Resolves with undefined if no match is found.\n   */\n  get(\n    query: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange,\n  ): Promise<StoreValue<DBTypes, StoreName> | undefined>;\n  /**\n   * Retrieves all values that match the query.\n   *\n   * @param query\n   * @param count Maximum number of values to return.\n   */\n  getAll(\n    query?: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange | null,\n    count?: number,\n  ): Promise<StoreValue<DBTypes, StoreName>[]>;\n  /**\n   * Retrieves the keys of records matching the query.\n   *\n   * @param query\n   * @param count Maximum number of keys to return.\n   */\n  getAllKeys(\n    query?: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange | null,\n    count?: number,\n  ): Promise<StoreKey<DBTypes, StoreName>[]>;\n  /**\n   * Retrieves the key of the first record that matches the query.\n   *\n   * Resolves with undefined if no match is found.\n   */\n  getKey(\n    query: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange,\n  ): Promise<StoreKey<DBTypes, StoreName> | undefined>;\n  /**\n   * Opens a cursor over the records matching the query.\n   *\n   * Resolves with null if no matches are found.\n   *\n   * @param query If null, all records match.\n   * @param direction\n   */\n  openCursor(\n    query?: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange | null,\n    direction?: IDBCursorDirection,\n  ): Promise<IDBPCursorWithValue<\n    DBTypes,\n    TxStores,\n    StoreName,\n    IndexName,\n    Mode\n  > | null>;\n  /**\n   * Opens a cursor over the keys matching the query.\n   *\n   * Resolves with null if no matches are found.\n   *\n   * @param query If null, all records match.\n   * @param direction\n   */\n  openKeyCursor(\n    query?: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange | null,\n    direction?: IDBCursorDirection,\n  ): Promise<IDBPCursor<DBTypes, TxStores, StoreName, IndexName, Mode> | null>;\n  /**\n   * Iterate over the index.\n   */\n  [Symbol.asyncIterator](): AsyncIterableIterator<\n    IDBPCursorWithValueIteratorValue<\n      DBTypes,\n      TxStores,\n      StoreName,\n      IndexName,\n      Mode\n    >\n  >;\n  /**\n   * Iterate over the records matching the query.\n   *\n   * Resolves with null if no matches are found.\n   *\n   * @param query If null, all records match.\n   * @param direction\n   */\n  iterate(\n    query?: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange | null,\n    direction?: IDBCursorDirection,\n  ): AsyncIterableIterator<\n    IDBPCursorWithValueIteratorValue<\n      DBTypes,\n      TxStores,\n      StoreName,\n      IndexName,\n      Mode\n    >\n  >;\n}\n\ntype IDBPCursorExtends = Omit<\n  IDBCursor,\n  | 'key'\n  | 'primaryKey'\n  | 'source'\n  | 'advance'\n  | 'continue'\n  | 'continuePrimaryKey'\n  | 'delete'\n  | 'update'\n>;\n\nexport interface IDBPCursor<\n  DBTypes extends DBSchema | unknown = unknown,\n  TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<\n    StoreNames<DBTypes>\n  >,\n  StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>,\n  IndexName extends IndexNames<DBTypes, StoreName> | unknown = unknown,\n  Mode extends IDBTransactionMode = 'readonly',\n> extends IDBPCursorExtends {\n  /**\n   * The key of the current index or object store item.\n   */\n  readonly key: CursorKey<DBTypes, StoreName, IndexName>;\n  /**\n   * The key of the current object store item.\n   */\n  readonly primaryKey: StoreKey<DBTypes, StoreName>;\n  /**\n   * Returns the IDBObjectStore or IDBIndex the cursor was opened from.\n   */\n  readonly source: CursorSource<DBTypes, TxStores, StoreName, IndexName, Mode>;\n  /**\n   * Advances the cursor a given number of records.\n   *\n   * Resolves to null if no matching records remain.\n   */\n  advance<T>(this: T, count: number): Promise<T | null>;\n  /**\n   * Advance the cursor by one record (unless 'key' is provided).\n   *\n   * Resolves to null if no matching records remain.\n   *\n   * @param key Advance to the index or object store with a key equal to or greater than this value.\n   */\n  continue<T>(\n    this: T,\n    key?: CursorKey<DBTypes, StoreName, IndexName>,\n  ): Promise<T | null>;\n  /**\n   * Advance the cursor by given keys.\n   *\n   * The operation is 'and' – both keys must be satisfied.\n   *\n   * Resolves to null if no matching records remain.\n   *\n   * @param key Advance to the index or object store with a key equal to or greater than this value.\n   * @param primaryKey and where the object store has a key equal to or greater than this value.\n   */\n  continuePrimaryKey<T>(\n    this: T,\n    key: CursorKey<DBTypes, StoreName, IndexName>,\n    primaryKey: StoreKey<DBTypes, StoreName>,\n  ): Promise<T | null>;\n  /**\n   * Delete the current record.\n   */\n  delete: Mode extends 'readonly' ? undefined : () => Promise<void>;\n  /**\n   * Updated the current record.\n   */\n  update: Mode extends 'readonly'\n    ? undefined\n    : (\n        value: StoreValue<DBTypes, StoreName>,\n      ) => Promise<StoreKey<DBTypes, StoreName>>;\n  /**\n   * Iterate over the cursor.\n   */\n  [Symbol.asyncIterator](): AsyncIterableIterator<\n    IDBPCursorIteratorValue<DBTypes, TxStores, StoreName, IndexName, Mode>\n  >;\n}\n\ntype IDBPCursorIteratorValueExtends<\n  DBTypes extends DBSchema | unknown = unknown,\n  TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<\n    StoreNames<DBTypes>\n  >,\n  StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>,\n  IndexName extends IndexNames<DBTypes, StoreName> | unknown = unknown,\n  Mode extends IDBTransactionMode = 'readonly',\n> = Omit<\n  IDBPCursor<DBTypes, TxStores, StoreName, IndexName, Mode>,\n  'advance' | 'continue' | 'continuePrimaryKey'\n>;\n\nexport interface IDBPCursorIteratorValue<\n  DBTypes extends DBSchema | unknown = unknown,\n  TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<\n    StoreNames<DBTypes>\n  >,\n  StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>,\n  IndexName extends IndexNames<DBTypes, StoreName> | unknown = unknown,\n  Mode extends IDBTransactionMode = 'readonly',\n> extends IDBPCursorIteratorValueExtends<\n    DBTypes,\n    TxStores,\n    StoreName,\n    IndexName,\n    Mode\n  > {\n  /**\n   * Advances the cursor a given number of records.\n   */\n  advance<T>(this: T, count: number): void;\n  /**\n   * Advance the cursor by one record (unless 'key' is provided).\n   *\n   * @param key Advance to the index or object store with a key equal to or greater than this value.\n   */\n  continue<T>(this: T, key?: CursorKey<DBTypes, StoreName, IndexName>): void;\n  /**\n   * Advance the cursor by given keys.\n   *\n   * The operation is 'and' – both keys must be satisfied.\n   *\n   * @param key Advance to the index or object store with a key equal to or greater than this value.\n   * @param primaryKey and where the object store has a key equal to or greater than this value.\n   */\n  continuePrimaryKey<T>(\n    this: T,\n    key: CursorKey<DBTypes, StoreName, IndexName>,\n    primaryKey: StoreKey<DBTypes, StoreName>,\n  ): void;\n}\n\nexport interface IDBPCursorWithValue<\n  DBTypes extends DBSchema | unknown = unknown,\n  TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<\n    StoreNames<DBTypes>\n  >,\n  StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>,\n  IndexName extends IndexNames<DBTypes, StoreName> | unknown = unknown,\n  Mode extends IDBTransactionMode = 'readonly',\n> extends IDBPCursor<DBTypes, TxStores, StoreName, IndexName, Mode> {\n  /**\n   * The value of the current item.\n   */\n  readonly value: StoreValue<DBTypes, StoreName>;\n  /**\n   * Iterate over the cursor.\n   */\n  [Symbol.asyncIterator](): AsyncIterableIterator<\n    IDBPCursorWithValueIteratorValue<\n      DBTypes,\n      TxStores,\n      StoreName,\n      IndexName,\n      Mode\n    >\n  >;\n}\n\n// Some of that sweeeeet Java-esque naming.\ntype IDBPCursorWithValueIteratorValueExtends<\n  DBTypes extends DBSchema | unknown = unknown,\n  TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<\n    StoreNames<DBTypes>\n  >,\n  StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>,\n  IndexName extends IndexNames<DBTypes, StoreName> | unknown = unknown,\n  Mode extends IDBTransactionMode = 'readonly',\n> = Omit<\n  IDBPCursorWithValue<DBTypes, TxStores, StoreName, IndexName, Mode>,\n  'advance' | 'continue' | 'continuePrimaryKey'\n>;\n\nexport interface IDBPCursorWithValueIteratorValue<\n  DBTypes extends DBSchema | unknown = unknown,\n  TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<\n    StoreNames<DBTypes>\n  >,\n  StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>,\n  IndexName extends IndexNames<DBTypes, StoreName> | unknown = unknown,\n  Mode extends IDBTransactionMode = 'readonly',\n> extends IDBPCursorWithValueIteratorValueExtends<\n    DBTypes,\n    TxStores,\n    StoreName,\n    IndexName,\n    Mode\n  > {\n  /**\n   * Advances the cursor a given number of records.\n   */\n  advance<T>(this: T, count: number): void;\n  /**\n   * Advance the cursor by one record (unless 'key' is provided).\n   *\n   * @param key Advance to the index or object store with a key equal to or greater than this value.\n   */\n  continue<T>(this: T, key?: CursorKey<DBTypes, StoreName, IndexName>): void;\n  /**\n   * Advance the cursor by given keys.\n   *\n   * The operation is 'and' – both keys must be satisfied.\n   *\n   * @param key Advance to the index or object store with a key equal to or greater than this value.\n   * @param primaryKey and where the object store has a key equal to or greater than this value.\n   */\n  continuePrimaryKey<T>(\n    this: T,\n    key: CursorKey<DBTypes, StoreName, IndexName>,\n    primaryKey: StoreKey<DBTypes, StoreName>,\n  ): void;\n}\n"
  },
  {
    "path": "src/index.ts",
    "content": "export * from './entry.js';\nimport './database-extras.js';\nimport './async-iterators.js';\n"
  },
  {
    "path": "src/tsconfig.json",
    "content": "{\n  \"extends\": \"../generic-tsconfig.json\",\n  \"compilerOptions\": {\n    \"lib\": [\"esnext\", \"dom\"],\n    \"tsBuildInfoFile\": \"../.ts-tmp/.src.tsbuildinfo\",\n    \"declarationDir\": \"../build\"\n  }\n}\n"
  },
  {
    "path": "src/util.ts",
    "content": "export type Constructor = new (...args: any[]) => any;\nexport type Func = (...args: any[]) => any;\n\nexport const instanceOfAny = (\n  object: any,\n  constructors: Constructor[],\n): boolean => constructors.some((c) => object instanceof c);\n"
  },
  {
    "path": "src/wrap-idb-value.ts",
    "content": "import {\n  IDBPCursor,\n  IDBPCursorWithValue,\n  IDBPDatabase,\n  IDBPIndex,\n  IDBPObjectStore,\n  IDBPTransaction,\n} from './entry.js';\nimport { Constructor, Func, instanceOfAny } from './util.js';\n\nlet idbProxyableTypes: Constructor[];\nlet cursorAdvanceMethods: Func[];\n\n// This is a function to prevent it throwing up in node environments.\nfunction getIdbProxyableTypes(): Constructor[] {\n  return (\n    idbProxyableTypes ||\n    (idbProxyableTypes = [\n      IDBDatabase,\n      IDBObjectStore,\n      IDBIndex,\n      IDBCursor,\n      IDBTransaction,\n    ])\n  );\n}\n\n// This is a function to prevent it throwing up in node environments.\nfunction getCursorAdvanceMethods(): Func[] {\n  return (\n    cursorAdvanceMethods ||\n    (cursorAdvanceMethods = [\n      IDBCursor.prototype.advance,\n      IDBCursor.prototype.continue,\n      IDBCursor.prototype.continuePrimaryKey,\n    ])\n  );\n}\n\nconst transactionDoneMap: WeakMap<\n  IDBTransaction,\n  Promise<void>\n> = new WeakMap();\nconst transformCache = new WeakMap();\nexport const reverseTransformCache = new WeakMap();\n\nfunction promisifyRequest<T>(request: IDBRequest<T>): Promise<T> {\n  const promise = new Promise<T>((resolve, reject) => {\n    const unlisten = () => {\n      request.removeEventListener('success', success);\n      request.removeEventListener('error', error);\n    };\n    const success = () => {\n      resolve(wrap(request.result as any) as any);\n      unlisten();\n    };\n    const error = () => {\n      reject(request.error);\n      unlisten();\n    };\n    request.addEventListener('success', success);\n    request.addEventListener('error', error);\n  });\n\n  // This mapping exists in reverseTransformCache but doesn't exist in transformCache. This\n  // is because we create many promises from a single IDBRequest.\n  reverseTransformCache.set(promise, request);\n  return promise;\n}\n\nfunction cacheDonePromiseForTransaction(tx: IDBTransaction): void {\n  // Early bail if we've already created a done promise for this transaction.\n  if (transactionDoneMap.has(tx)) return;\n\n  const done = new Promise<void>((resolve, reject) => {\n    const unlisten = () => {\n      tx.removeEventListener('complete', complete);\n      tx.removeEventListener('error', error);\n      tx.removeEventListener('abort', error);\n    };\n    const complete = () => {\n      resolve();\n      unlisten();\n    };\n    const error = () => {\n      reject(tx.error || new DOMException('AbortError', 'AbortError'));\n      unlisten();\n    };\n    tx.addEventListener('complete', complete);\n    tx.addEventListener('error', error);\n    tx.addEventListener('abort', error);\n  });\n\n  // Cache it for later retrieval.\n  transactionDoneMap.set(tx, done);\n}\n\nlet idbProxyTraps: ProxyHandler<any> = {\n  get(target, prop, receiver) {\n    if (target instanceof IDBTransaction) {\n      // Special handling for transaction.done.\n      if (prop === 'done') return transactionDoneMap.get(target);\n      // Make tx.store return the only store in the transaction, or undefined if there are many.\n      if (prop === 'store') {\n        return receiver.objectStoreNames[1]\n          ? undefined\n          : receiver.objectStore(receiver.objectStoreNames[0]);\n      }\n    }\n    // Else transform whatever we get back.\n    return wrap(target[prop]);\n  },\n  set(target, prop, value) {\n    target[prop] = value;\n    return true;\n  },\n  has(target, prop) {\n    if (\n      target instanceof IDBTransaction &&\n      (prop === 'done' || prop === 'store')\n    ) {\n      return true;\n    }\n    return prop in target;\n  },\n};\n\nexport function replaceTraps(\n  callback: (currentTraps: ProxyHandler<any>) => ProxyHandler<any>,\n): void {\n  idbProxyTraps = callback(idbProxyTraps);\n}\n\nfunction wrapFunction<T extends Func>(func: T): Function {\n  // Due to expected object equality (which is enforced by the caching in `wrap`), we\n  // only create one new func per func.\n\n  // Cursor methods are special, as the behaviour is a little more different to standard IDB. In\n  // IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the\n  // cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense\n  // with real promises, so each advance methods returns a new promise for the cursor object, or\n  // undefined if the end of the cursor has been reached.\n  if (getCursorAdvanceMethods().includes(func)) {\n    return function (this: IDBPCursor, ...args: Parameters<T>) {\n      // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use\n      // the original object.\n      func.apply(unwrap(this), args);\n      return wrap(this.request);\n    };\n  }\n\n  return function (this: any, ...args: Parameters<T>) {\n    // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use\n    // the original object.\n    return wrap(func.apply(unwrap(this), args));\n  };\n}\n\nfunction transformCachableValue(value: any): any {\n  if (typeof value === 'function') return wrapFunction(value);\n\n  // This doesn't return, it just creates a 'done' promise for the transaction,\n  // which is later returned for transaction.done (see idbObjectHandler).\n  if (value instanceof IDBTransaction) cacheDonePromiseForTransaction(value);\n\n  if (instanceOfAny(value, getIdbProxyableTypes()))\n    return new Proxy(value, idbProxyTraps);\n\n  // Return the same value back if we're not going to transform it.\n  return value;\n}\n\n/**\n * Enhance an IDB object with helpers.\n *\n * @param value The thing to enhance.\n */\nexport function wrap(value: IDBDatabase): IDBPDatabase;\nexport function wrap(value: IDBIndex): IDBPIndex;\nexport function wrap(value: IDBObjectStore): IDBPObjectStore;\nexport function wrap(value: IDBTransaction): IDBPTransaction;\nexport function wrap(\n  value: IDBOpenDBRequest,\n): Promise<IDBPDatabase | undefined>;\nexport function wrap<T>(value: IDBRequest<T>): Promise<T>;\nexport function wrap(value: any): any {\n  // We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because\n  // IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.\n  if (value instanceof IDBRequest) return promisifyRequest(value);\n\n  // If we've already transformed this value before, reuse the transformed value.\n  // This is faster, but it also provides object equality.\n  if (transformCache.has(value)) return transformCache.get(value);\n  const newValue = transformCachableValue(value);\n\n  // Not all types are transformed.\n  // These may be primitive types, so they can't be WeakMap keys.\n  if (newValue !== value) {\n    transformCache.set(value, newValue);\n    reverseTransformCache.set(newValue, value);\n  }\n\n  return newValue;\n}\n\n/**\n * Revert an enhanced IDB object to a plain old miserable IDB one.\n *\n * Will also revert a promise back to an IDBRequest.\n *\n * @param value The enhanced object to revert.\n */\ninterface Unwrap {\n  (value: IDBPCursorWithValue<any, any, any, any, any>): IDBCursorWithValue;\n  (value: IDBPCursor<any, any, any, any, any>): IDBCursor;\n  (value: IDBPDatabase<any>): IDBDatabase;\n  (value: IDBPIndex<any, any, any, any, any>): IDBIndex;\n  (value: IDBPObjectStore<any, any, any, any>): IDBObjectStore;\n  (value: IDBPTransaction<any, any, any>): IDBTransaction;\n  <T extends any>(value: Promise<IDBPDatabase<T>>): IDBOpenDBRequest;\n  (value: Promise<IDBPDatabase>): IDBOpenDBRequest;\n  <T>(value: Promise<T>): IDBRequest<T>;\n}\nexport const unwrap: Unwrap = (value: any): any =>\n  reverseTransformCache.get(value);\n"
  },
  {
    "path": "test/index.html",
    "content": "<!DOCTYPE html>\n<link href=\"../../node_modules/mocha/mocha.css\" rel=\"stylesheet\" />\n<div id=\"mocha\"></div>\n<script type=\"module\" src=\"index.js\"></script>\n"
  },
  {
    "path": "test/index.ts",
    "content": "// Since this library proxies IDB, I haven't retested all of IDB. I've tried to cover parts of the\n// library that behave differently to IDB, or may cause accidental differences.\n\nimport 'mocha/mocha';\nimport { deleteDatabase } from './utils';\nmocha.setup('tdd');\n\nfunction loadScript(url: string): Promise<void> {\n  return new Promise((resolve, reject) => {\n    const script = document.createElement('script');\n    script.type = 'module';\n    script.src = url;\n    script.onload = () => resolve();\n    script.onerror = () => reject(Error('Script load error'));\n    document.body.appendChild(script);\n  });\n}\n\n(async function () {\n  const edgeCompat = navigator.userAgent.includes('Edge/');\n\n  if (!edgeCompat) await loadScript('./open.js');\n  await loadScript('./main.js');\n  if (!edgeCompat) await loadScript('./iterate.js');\n  await deleteDatabase();\n  mocha.run();\n})();\n"
  },
  {
    "path": "test/iterate.ts",
    "content": "// Since this library proxies IDB, I haven't retested all of IDB. I've tried to cover parts of the\n// library that behave differently to IDB, or may cause accidental differences.\n\nimport 'mocha/mocha';\nimport { assert } from 'chai';\nimport { IDBPDatabase, IDBPCursorWithValueIteratorValue } from '../src/';\nimport '../src/async-iterators';\nimport { assert as typeAssert, IsExact } from 'conditional-type-checks';\nimport {\n  deleteDatabase,\n  openDBWithData,\n  TestDBSchema,\n  ObjectStoreValue,\n} from './utils';\n\nsuite('Async iterators', () => {\n  let db: IDBPDatabase;\n\n  teardown('Close DB', async () => {\n    if (db) db.close();\n    await deleteDatabase();\n  });\n\n  test('object stores', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const store = schemaDB.transaction('key-val-store').store;\n      const keys = [];\n      const values = [];\n\n      assert.isTrue(Symbol.asyncIterator in store);\n\n      for await (const cursor of store) {\n        typeAssert<\n          IsExact<\n            typeof cursor,\n            IDBPCursorWithValueIteratorValue<\n              TestDBSchema,\n              ['key-val-store'],\n              'key-val-store',\n              unknown\n            >\n          >\n        >(true);\n\n        typeAssert<IsExact<typeof cursor.key, string>>(true);\n\n        typeAssert<IsExact<typeof cursor.value, number>>(true);\n\n        keys.push(cursor.key);\n        values.push(cursor.value);\n      }\n\n      assert.deepEqual(values, [456, 123, 789], 'Correct values');\n      assert.deepEqual(keys, ['bar', 'foo', 'hello'], 'Correct keys');\n    }\n    {\n      const store = db.transaction('key-val-store').store;\n      const keys = [];\n      const values = [];\n\n      for await (const cursor of store) {\n        typeAssert<\n          IsExact<\n            typeof cursor,\n            IDBPCursorWithValueIteratorValue<\n              unknown,\n              ['key-val-store'],\n              'key-val-store',\n              unknown\n            >\n          >\n        >(true);\n\n        typeAssert<IsExact<typeof cursor.key, IDBValidKey>>(true);\n\n        typeAssert<IsExact<typeof cursor.value, any>>(true);\n\n        keys.push(cursor.key);\n        values.push(cursor.value);\n      }\n\n      assert.deepEqual(values, [456, 123, 789], 'Correct values');\n      assert.deepEqual(keys, ['bar', 'foo', 'hello'], 'Correct keys');\n    }\n  });\n\n  test('object stores iterate', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const store = schemaDB.transaction('key-val-store').store;\n      assert.property(store, 'iterate');\n\n      typeAssert<\n        IsExact<\n          Parameters<typeof store.iterate>[0],\n          string | IDBKeyRange | undefined | null\n        >\n      >(true);\n\n      for await (const _ of store.iterate('blah')) {\n        assert.fail('This should not be called');\n      }\n    }\n    {\n      const store = db.transaction('key-val-store').store;\n\n      typeAssert<\n        IsExact<\n          Parameters<typeof store.iterate>[0],\n          IDBValidKey | IDBKeyRange | undefined | null\n        >\n      >(true);\n\n      for await (const _ of store.iterate('blah')) {\n        assert.fail('This should not be called');\n      }\n    }\n  });\n\n  test('Can delete during iteration', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const tx = schemaDB.transaction('key-val-store', 'readwrite');\n\n    for await (const cursor of tx.store) {\n      cursor.delete();\n    }\n\n    assert.strictEqual(await schemaDB.count('key-val-store'), 0);\n  });\n\n  test('index', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const index = schemaDB.transaction('object-store').store.index('date');\n      const keys = [];\n      const values = [];\n\n      assert.isTrue(Symbol.asyncIterator in index);\n\n      for await (const cursor of index) {\n        typeAssert<\n          IsExact<\n            typeof cursor,\n            IDBPCursorWithValueIteratorValue<\n              TestDBSchema,\n              ['object-store'],\n              'object-store',\n              'date'\n            >\n          >\n        >(true);\n\n        typeAssert<IsExact<typeof cursor.key, Date>>(true);\n\n        typeAssert<IsExact<typeof cursor.value, ObjectStoreValue>>(true);\n\n        keys.push(cursor.key);\n        values.push(cursor.value);\n      }\n\n      assert.deepEqual(\n        values,\n        [\n          {\n            id: 4,\n            title: 'Article 4',\n            date: new Date('2019-01-01'),\n          },\n          {\n            id: 3,\n            title: 'Article 3',\n            date: new Date('2019-01-02'),\n          },\n          {\n            id: 2,\n            title: 'Article 2',\n            date: new Date('2019-01-03'),\n          },\n          {\n            id: 1,\n            title: 'Article 1',\n            date: new Date('2019-01-04'),\n          },\n        ],\n        'Correct values',\n      );\n      assert.deepEqual(\n        keys,\n        [\n          new Date('2019-01-01'),\n          new Date('2019-01-02'),\n          new Date('2019-01-03'),\n          new Date('2019-01-04'),\n        ],\n        'Correct keys',\n      );\n    }\n    {\n      const index = db.transaction('object-store').store.index('title');\n      const keys = [];\n      const values = [];\n\n      assert.isTrue(Symbol.asyncIterator in index);\n\n      for await (const cursor of index) {\n        typeAssert<\n          IsExact<\n            typeof cursor,\n            IDBPCursorWithValueIteratorValue<\n              unknown,\n              ['object-store'],\n              'object-store',\n              'title'\n            >\n          >\n        >(true);\n\n        typeAssert<IsExact<typeof cursor.key, IDBValidKey>>(true);\n\n        typeAssert<IsExact<typeof cursor.value, any>>(true);\n\n        keys.push(cursor.key);\n        values.push(cursor.value);\n      }\n\n      assert.deepEqual(\n        values,\n        [\n          {\n            id: 1,\n            title: 'Article 1',\n            date: new Date('2019-01-04'),\n          },\n          {\n            id: 2,\n            title: 'Article 2',\n            date: new Date('2019-01-03'),\n          },\n          {\n            id: 3,\n            title: 'Article 3',\n            date: new Date('2019-01-02'),\n          },\n          {\n            id: 4,\n            title: 'Article 4',\n            date: new Date('2019-01-01'),\n          },\n        ],\n        'Correct values',\n      );\n      assert.deepEqual(\n        keys,\n        ['Article 1', 'Article 2', 'Article 3', 'Article 4'],\n        'Correct keys',\n      );\n    }\n  });\n\n  test('index iterate', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const index = schemaDB.transaction('object-store').store.index('date');\n      assert.property(index, 'iterate');\n\n      typeAssert<\n        IsExact<\n          Parameters<typeof index.iterate>[0],\n          Date | IDBKeyRange | undefined | null\n        >\n      >(true);\n\n      for await (const _ of index.iterate(new Date('2020-01-01'))) {\n        assert.fail('This should not be called');\n      }\n    }\n    {\n      const index = db.transaction('object-store').store.index('title');\n      assert.property(index, 'iterate');\n\n      typeAssert<\n        IsExact<\n          Parameters<typeof index.iterate>[0],\n          IDBValidKey | IDBKeyRange | undefined | null\n        >\n      >(true);\n\n      for await (const _ of index.iterate('foo')) {\n        assert.fail('This should not be called');\n      }\n    }\n  });\n\n  test('cursor', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const store = schemaDB.transaction('key-val-store').store;\n    const cursor = await store.openCursor();\n\n    if (!cursor) throw Error('expected cursor');\n\n    const keys = [];\n    const values = [];\n\n    assert.isTrue(Symbol.asyncIterator in cursor);\n\n    for await (const cursorIter of cursor) {\n      typeAssert<\n        IsExact<\n          typeof cursorIter,\n          IDBPCursorWithValueIteratorValue<\n            TestDBSchema,\n            ['key-val-store'],\n            'key-val-store',\n            unknown\n          >\n        >\n      >(true);\n\n      typeAssert<IsExact<typeof cursorIter.key, string>>(true);\n\n      typeAssert<IsExact<typeof cursorIter.value, number>>(true);\n\n      keys.push(cursorIter.key);\n      values.push(cursorIter.value);\n    }\n\n    assert.deepEqual(values, [456, 123, 789], 'Correct values');\n    assert.deepEqual(keys, ['bar', 'foo', 'hello'], 'Correct keys');\n  });\n});\n"
  },
  {
    "path": "test/main.ts",
    "content": "import 'mocha/mocha';\nimport { assert } from 'chai';\nimport {\n  IDBPDatabase,\n  IDBPTransaction,\n  wrap,\n  unwrap,\n  IDBPObjectStore,\n  IDBPCursorWithValue,\n  IDBPCursor,\n  IDBPIndex,\n  TypedDOMStringList,\n  openDB,\n  DBSchema,\n} from '../src';\nimport { assert as typeAssert, IsExact } from 'conditional-type-checks';\nimport {\n  deleteDatabase,\n  openDBWithSchema,\n  openDBWithData,\n  ObjectStoreValue,\n  TestDBSchema,\n  getNextVersion,\n  dbName,\n} from './utils';\n\nsuite('IDBPDatabase', () => {\n  let db: IDBPDatabase;\n\n  teardown('Close DB', async () => {\n    if (db) db.close();\n    await deleteDatabase();\n  });\n\n  test('objectStoreNames', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    typeAssert<\n      IsExact<\n        typeof schemaDB.objectStoreNames,\n        TypedDOMStringList<'key-val-store' | 'object-store'>\n      >\n    >(true);\n\n    typeAssert<IsExact<typeof db.objectStoreNames, TypedDOMStringList<string>>>(\n      true,\n    );\n  });\n\n  test('createObjectStore', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof schemaDB.createObjectStore>[0],\n        'key-val-store' | 'object-store'\n      >\n    >(true);\n\n    typeAssert<IsExact<Parameters<typeof db.createObjectStore>[0], string>>(\n      true,\n    );\n  });\n\n  test('deleteObjectStore', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof schemaDB.deleteObjectStore>[0],\n        'key-val-store' | 'object-store'\n      >\n    >(true);\n\n    typeAssert<IsExact<Parameters<typeof db.deleteObjectStore>[0], string>>(\n      true,\n    );\n  });\n\n  test('transaction', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof schemaDB.transaction>[0],\n        ArrayLike<'key-val-store' | 'object-store'>\n      >\n    >(true);\n\n    typeAssert<\n      IsExact<Parameters<typeof db.transaction>[0], ArrayLike<string>>\n    >(true);\n\n    // Function getters should return the same instance.\n    assert.strictEqual(db.transaction, db.transaction, 'transaction');\n  });\n\n  test('transaction - all stores', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const tx = schemaDB.transaction(schemaDB.objectStoreNames);\n    const tx2 = db.transaction(db.objectStoreNames);\n\n    typeAssert<\n      IsExact<\n        typeof tx.objectStoreNames,\n        TypedDOMStringList<'key-val-store' | 'object-store'>\n      >\n    >(true);\n\n    typeAssert<\n      IsExact<typeof tx2.objectStoreNames, TypedDOMStringList<string>>\n    >(true);\n  });\n\n  test('get', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    assert.property(schemaDB, 'get', 'Method exists');\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof schemaDB.get>[0],\n        'key-val-store' | 'object-store'\n      >\n    >(true);\n\n    const val = await schemaDB.get('key-val-store', 'foo');\n\n    typeAssert<IsExact<typeof val, number | undefined>>(true);\n\n    assert.strictEqual(val, 123, 'Correct value from store');\n\n    const val2 = await db.get('key-val-store', 'bar');\n\n    typeAssert<IsExact<typeof val2, any>>(true);\n\n    assert.strictEqual(val2, 456, 'Correct value from store');\n  });\n\n  test('getFromIndex', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    assert.property(schemaDB, 'getFromIndex', 'Method exists');\n    const val = await schemaDB.getFromIndex(\n      'object-store',\n      'title',\n      'Article 1',\n    );\n\n    typeAssert<IsExact<typeof val, ObjectStoreValue | undefined>>(true);\n\n    assert.deepStrictEqual(\n      val,\n      {\n        id: 1,\n        title: 'Article 1',\n        date: new Date('2019-01-04'),\n      },\n      'Correct value from store',\n    );\n\n    const val2 = await db.getFromIndex('object-store', 'title', 'Article 2');\n\n    typeAssert<IsExact<typeof val2, any>>(true);\n\n    assert.deepStrictEqual(\n      val2,\n      {\n        id: 2,\n        title: 'Article 2',\n        date: new Date('2019-01-03'),\n      },\n      'Correct value from store',\n    );\n  });\n\n  test('getKey', async function () {\n    if (!('getKey' in IDBObjectStore.prototype)) this.skip();\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    assert.property(schemaDB, 'getKey', 'Method exists');\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof schemaDB.getKey>[0],\n        'key-val-store' | 'object-store'\n      >\n    >(true);\n\n    const val = await schemaDB.getKey(\n      'key-val-store',\n      IDBKeyRange.lowerBound('a'),\n    );\n\n    typeAssert<IsExact<typeof val, string | undefined>>(true);\n\n    assert.strictEqual(val, 'bar', 'Correct value');\n\n    const val2 = await db.getKey('key-val-store', IDBKeyRange.lowerBound('c'));\n\n    typeAssert<IsExact<typeof val2, IDBValidKey | undefined>>(true);\n\n    assert.strictEqual(val2, 'foo', 'Correct value');\n  });\n\n  test('getKeyFromIndex', async function () {\n    if (!('getKey' in IDBObjectStore.prototype)) this.skip();\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    assert.property(schemaDB, 'getKeyFromIndex', 'Method exists');\n\n    const val = await schemaDB.getKeyFromIndex(\n      'object-store',\n      'title',\n      IDBKeyRange.lowerBound('A'),\n    );\n\n    typeAssert<IsExact<typeof val, number | undefined>>(true);\n\n    assert.strictEqual(val, 1, 'Correct value');\n\n    const val2 = await db.getKeyFromIndex(\n      'object-store',\n      'date',\n      IDBKeyRange.lowerBound(new Date('1990-01-01')),\n    );\n\n    typeAssert<IsExact<typeof val2, IDBValidKey | undefined>>(true);\n\n    assert.strictEqual(val2, 4, 'Correct value');\n  });\n\n  test('getAll', async function () {\n    if (!('getAll' in IDBObjectStore.prototype)) this.skip();\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    assert.property(schemaDB, 'getAll', 'Method exists');\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof schemaDB.getAll>[0],\n        'key-val-store' | 'object-store'\n      >\n    >(true);\n\n    const val = await schemaDB.getAll('key-val-store');\n\n    typeAssert<IsExact<typeof val, number[]>>(true);\n\n    assert.deepStrictEqual(val, [456, 123, 789], 'Correct values from store');\n\n    const val2 = await db.getAll('key-val-store');\n\n    typeAssert<IsExact<typeof val2, any[]>>(true);\n\n    assert.deepStrictEqual(val2, [456, 123, 789], 'Correct values from store');\n  });\n\n  test('getAllFromIndex', async function () {\n    if (!('getAll' in IDBObjectStore.prototype)) this.skip();\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    assert.property(schemaDB, 'getAllFromIndex', 'Method exists');\n    const val = await schemaDB.getAllFromIndex('object-store', 'date');\n\n    typeAssert<IsExact<typeof val, ObjectStoreValue[]>>(true);\n\n    assert.deepStrictEqual(\n      val,\n      [\n        {\n          id: 4,\n          title: 'Article 4',\n          date: new Date('2019-01-01'),\n        },\n        {\n          id: 3,\n          title: 'Article 3',\n          date: new Date('2019-01-02'),\n        },\n        {\n          id: 2,\n          title: 'Article 2',\n          date: new Date('2019-01-03'),\n        },\n        {\n          id: 1,\n          title: 'Article 1',\n          date: new Date('2019-01-04'),\n        },\n      ],\n      'Correct values from store',\n    );\n\n    const val2 = await db.getAllFromIndex('object-store', 'title');\n\n    typeAssert<IsExact<typeof val2, any[]>>(true);\n\n    assert.deepStrictEqual(\n      val2,\n      [\n        {\n          id: 1,\n          title: 'Article 1',\n          date: new Date('2019-01-04'),\n        },\n        {\n          id: 2,\n          title: 'Article 2',\n          date: new Date('2019-01-03'),\n        },\n        {\n          id: 3,\n          title: 'Article 3',\n          date: new Date('2019-01-02'),\n        },\n        {\n          id: 4,\n          title: 'Article 4',\n          date: new Date('2019-01-01'),\n        },\n      ],\n      'Correct values from store',\n    );\n  });\n\n  test('getAllKeys', async function () {\n    if (!('getAllKeys' in IDBObjectStore.prototype)) this.skip();\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    assert.property(schemaDB, 'getAllKeys', 'Method exists');\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof schemaDB.getAllKeys>[0],\n        'key-val-store' | 'object-store'\n      >\n    >(true);\n\n    const val = await schemaDB.getAllKeys('key-val-store');\n\n    typeAssert<IsExact<typeof val, string[]>>(true);\n\n    assert.deepStrictEqual(\n      val,\n      ['bar', 'foo', 'hello'],\n      'Correct values from store',\n    );\n\n    const val2 = await db.getAllKeys('key-val-store');\n\n    typeAssert<IsExact<typeof val2, IDBValidKey[]>>(true);\n\n    assert.deepStrictEqual(\n      val2,\n      ['bar', 'foo', 'hello'],\n      'Correct values from store',\n    );\n  });\n\n  test('getAllKeysFromIndex', async function () {\n    if (!('getAllKeys' in IDBObjectStore.prototype)) this.skip();\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    assert.property(schemaDB, 'getAllKeysFromIndex', 'Method exists');\n    const val = await schemaDB.getAllKeysFromIndex('object-store', 'date');\n\n    typeAssert<IsExact<typeof val, number[]>>(true);\n\n    assert.deepStrictEqual(val, [4, 3, 2, 1], 'Correct values from store');\n\n    const val2 = await db.getAllKeysFromIndex('object-store', 'title');\n\n    typeAssert<IsExact<typeof val2, IDBValidKey[]>>(true);\n\n    assert.deepStrictEqual(val2, [1, 2, 3, 4], 'Correct values from store');\n  });\n\n  test('count', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    assert.property(schemaDB, 'count', 'Method exists');\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof schemaDB.count>[0],\n        'key-val-store' | 'object-store'\n      >\n    >(true);\n\n    const val = await schemaDB.count('key-val-store');\n\n    typeAssert<IsExact<typeof val, number>>(true);\n\n    assert.strictEqual(val, 3, 'Correct count');\n\n    const val2 = await db.count('object-store');\n\n    typeAssert<IsExact<typeof val2, number>>(true);\n\n    assert.strictEqual(val2, 4, 'Correct count');\n  });\n\n  test('countFromIndex', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    assert.property(schemaDB, 'countFromIndex', 'Method exists');\n    const val = await schemaDB.countFromIndex('object-store', 'date');\n\n    typeAssert<IsExact<typeof val, number>>(true);\n\n    assert.strictEqual(val, 4, 'Correct count');\n\n    const val2 = await db.countFromIndex(\n      'object-store',\n      'title',\n      IDBKeyRange.lowerBound('Article 10'),\n    );\n\n    typeAssert<IsExact<typeof val2, number>>(true);\n\n    assert.strictEqual(val2, 3, 'Correct count');\n  });\n\n  test('put', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    assert.property(schemaDB, 'put', 'Method exists');\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof schemaDB.put>[0],\n        'key-val-store' | 'object-store'\n      >\n    >(true);\n\n    const key = await schemaDB.put('key-val-store', 234, 'new');\n\n    typeAssert<IsExact<typeof key, string>>(true);\n\n    assert.strictEqual(key, 'new');\n\n    const val = await schemaDB.get('key-val-store', 'new');\n\n    assert.strictEqual(val, 234, 'Correct value from store');\n\n    const key2 = await db.put('object-store', {\n      id: 5,\n      title: 'Article 5',\n      date: new Date('2018-05-09'),\n    });\n\n    typeAssert<IsExact<typeof key2, IDBValidKey>>(true);\n\n    assert.strictEqual(key2, 5);\n\n    const val2 = await db.get('object-store', 5);\n\n    typeAssert<IsExact<typeof val2, any>>(true);\n\n    assert.deepStrictEqual(\n      val2,\n      {\n        id: 5,\n        title: 'Article 5',\n        date: new Date('2018-05-09'),\n      },\n      'Correct value from store',\n    );\n  });\n\n  test('add', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    assert.property(schemaDB, 'add', 'Method exists');\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof schemaDB.add>[0],\n        'key-val-store' | 'object-store'\n      >\n    >(true);\n\n    const key = await schemaDB.add('key-val-store', 234, 'new');\n\n    typeAssert<IsExact<typeof key, string>>(true);\n\n    assert.strictEqual(key, 'new');\n\n    const val = await schemaDB.get('key-val-store', 'new');\n\n    assert.strictEqual(val, 234, 'Correct value from store');\n\n    const key2 = await db.add('object-store', {\n      id: 5,\n      title: 'Article 5',\n      date: new Date('2018-05-09'),\n    });\n\n    typeAssert<IsExact<typeof key2, IDBValidKey>>(true);\n\n    assert.strictEqual(key2, 5);\n\n    const val2 = await db.get('object-store', 5);\n\n    typeAssert<IsExact<typeof val2, any>>(true);\n\n    assert.deepStrictEqual(\n      val2,\n      {\n        id: 5,\n        title: 'Article 5',\n        date: new Date('2018-05-09'),\n      },\n      'Correct value from store',\n    );\n  });\n\n  test('add - error type', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    // This test ensures the shortcut methods correctly pass-through the\n    // error generated by the operation, rather then deferring to the\n    // transaction abort.\n    try {\n      await schemaDB.add('object-store', {\n        title: 'Foo',\n        date: new Date(),\n        id: 1,\n      });\n      const error = new Error(`Didn't throw`);\n      error.name = 'DidntThrowError';\n      throw error;\n    } catch (error) {\n      assert.instanceOf(error, DOMException);\n      assert.strictEqual((error as DOMException).name, 'ConstraintError');\n    }\n  });\n\n  test('add - avoid unhandled rejection', async () => {\n    let unhandledRejection = false;\n    let errored = false;\n    const onUnhandledRejection = () => (unhandledRejection = true);\n\n    self.addEventListener('unhandledrejection', onUnhandledRejection);\n\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    try {\n      await schemaDB.add('key-val-store', 123, 'foo');\n    } catch (err) {\n      errored = true;\n    }\n\n    // Wait for a frame so tasks are processed\n    await new Promise((r) => requestAnimationFrame(r));\n\n    assert.isTrue(errored, 'Add errored');\n    assert.isFalse(unhandledRejection, 'No unhandled rejection');\n\n    self.removeEventListener('unhandledrejection', onUnhandledRejection);\n  });\n\n  test('delete', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    assert.property(schemaDB, 'delete', 'Method exists');\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof schemaDB.delete>[0],\n        'key-val-store' | 'object-store'\n      >\n    >(true);\n\n    await schemaDB.delete('key-val-store', 'foo');\n    const val = await schemaDB.get('key-val-store', 'foo');\n\n    assert.strictEqual(val, undefined, 'Correct value from store');\n\n    await db.delete('object-store', 1);\n    const val2 = await db.get('object-store', 1);\n\n    assert.strictEqual(val2, undefined, 'Correct value from store');\n  });\n\n  test('clear', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    assert.property(schemaDB, 'clear', 'Method exists');\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof schemaDB.clear>[0],\n        'key-val-store' | 'object-store'\n      >\n    >(true);\n\n    await schemaDB.clear('key-val-store');\n    const val = await schemaDB.count('key-val-store');\n\n    assert.strictEqual(val, 0, 'Correct value from store');\n\n    await db.clear('object-store');\n    const val2 = await db.count('object-store');\n\n    assert.strictEqual(val2, 0, 'Correct value from store');\n  });\n});\n\nsuite('IDBPTransaction', () => {\n  let db: IDBPDatabase;\n\n  teardown('Close DB', async () => {\n    if (db) db.close();\n  });\n\n  test('mode', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n    const tx1 = schemaDB.transaction('key-val-store');\n    const tx2 = schemaDB.transaction('key-val-store', 'readonly');\n    const tx3 = schemaDB.transaction('key-val-store', 'readwrite');\n\n    typeAssert<IsExact<typeof tx1, typeof tx2>>(true);\n    typeAssert<IsExact<typeof tx1, typeof tx3>>(false);\n  });\n\n  test('objectStoreNames', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const tx1 = schemaDB.transaction('key-val-store');\n    const tx2 = schemaDB.transaction('object-store');\n    const tx3 = schemaDB.transaction(['object-store', 'key-val-store']);\n\n    typeAssert<\n      IsExact<typeof tx1.objectStoreNames, TypedDOMStringList<'key-val-store'>>\n    >(true);\n\n    typeAssert<\n      IsExact<typeof tx2.objectStoreNames, TypedDOMStringList<'object-store'>>\n    >(true);\n\n    typeAssert<\n      IsExact<\n        typeof tx3.objectStoreNames,\n        TypedDOMStringList<'object-store' | 'key-val-store'>\n      >\n    >(true);\n\n    // Without schema it should still work:\n    const tx4 = db.transaction('key-val-store');\n\n    typeAssert<\n      IsExact<typeof tx4.objectStoreNames, TypedDOMStringList<'key-val-store'>>\n    >(true);\n  });\n\n  test('db', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const tx = schemaDB.transaction('key-val-store');\n\n    typeAssert<IsExact<typeof tx.db, IDBPDatabase<TestDBSchema>>>(true);\n\n    const tx2 = db.transaction('key-val-store');\n\n    typeAssert<IsExact<typeof tx2.db, IDBPDatabase>>(true);\n  });\n\n  test('done', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const tx = schemaDB.transaction('key-val-store');\n    assert.property(tx, 'done');\n    assert.instanceOf(tx.done, Promise);\n  });\n\n  test('store', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const tx = schemaDB.transaction('key-val-store');\n    assert.property(tx, 'store');\n\n    typeAssert<\n      IsExact<\n        typeof tx.store,\n        IDBPObjectStore<TestDBSchema, ['key-val-store'], 'key-val-store'>\n      >\n    >(true);\n\n    assert.strictEqual(tx.store.name, 'key-val-store');\n\n    assert.instanceOf(tx.store.get('blah'), Promise, 'Is the store wrapped?');\n\n    assert.instanceOf(tx.store, IDBObjectStore);\n\n    const tx2 = schemaDB.transaction(['key-val-store', 'object-store']);\n    assert.property(tx2, 'store');\n\n    typeAssert<IsExact<typeof tx2.store, undefined>>(true);\n\n    assert.isUndefined(tx2.store);\n  });\n\n  test('objectStore', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const tx1 = schemaDB.transaction('key-val-store');\n    const tx2 = schemaDB.transaction('key-val-store');\n    const tx3 = schemaDB.transaction(['key-val-store', 'object-store']);\n    const tx4 = db.transaction('object-store');\n\n    // Functions should be equal across instances.\n    assert.strictEqual(tx1.objectStore, tx2.objectStore);\n\n    typeAssert<IsExact<Parameters<typeof tx1.objectStore>[0], 'key-val-store'>>(\n      true,\n    );\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof tx3.objectStore>[0],\n        'key-val-store' | 'object-store'\n      >\n    >(true);\n\n    typeAssert<IsExact<Parameters<typeof tx4.objectStore>[0], 'object-store'>>(\n      true,\n    );\n\n    // The spec says object stores from the same transaction should be equal.\n    assert.strictEqual(\n      tx1.objectStore('key-val-store'),\n      tx1.objectStore('key-val-store'),\n      'objectStore on same tx',\n    );\n\n    // The spec says object stores from different transaction should not be equal.\n    assert.notEqual(\n      tx1.objectStore('key-val-store'),\n      tx2.objectStore('key-val-store'),\n      'objectStore on different tx',\n    );\n\n    const store = tx1.objectStore('key-val-store');\n    const schemalessStore = tx4.objectStore('object-store');\n\n    typeAssert<\n      IsExact<\n        typeof store,\n        IDBPObjectStore<TestDBSchema, ['key-val-store'], 'key-val-store'>\n      >\n    >(true);\n\n    typeAssert<\n      IsExact<\n        typeof schemalessStore,\n        IDBPObjectStore<unknown, ['object-store'], 'object-store'>\n      >\n    >(true);\n\n    assert.strictEqual(store.name, 'key-val-store');\n    assert.strictEqual(schemalessStore.name, 'object-store');\n  });\n\n  test('abort', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const tx = schemaDB.transaction('key-val-store');\n    tx.abort();\n\n    let threw = false;\n    let error: Error | null = null;\n\n    try {\n      await tx.done;\n    } catch (e) {\n      threw = true;\n      error = e as Error;\n    }\n\n    assert(threw, 'Done threw');\n    assert.instanceOf(error, DOMException);\n    assert.strictEqual(error?.name, 'AbortError');\n  });\n\n  test('wrap', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const idb = unwrap(db);\n    const tx = idb.transaction('key-val-store');\n\n    assert.notProperty(tx, 'store');\n\n    const wrappedTx = wrap(tx);\n\n    typeAssert<\n      IsExact<typeof wrappedTx, IDBPTransaction<unknown, ArrayLike<string>>>\n    >(true);\n\n    assert.property(wrappedTx, 'store');\n  });\n\n  test('unwrap', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const tx = schemaDB.transaction('key-val-store');\n    const tx2 = db.transaction('key-val-store');\n    const tx3 = schemaDB.transaction('key-val-store', 'readwrite');\n    const unwrappedTx = unwrap(tx);\n    const unwrappedTx2 = unwrap(tx2);\n    const unwrappedTx3 = unwrap(tx3);\n\n    typeAssert<IsExact<typeof unwrappedTx, IDBTransaction>>(true);\n    typeAssert<IsExact<typeof unwrappedTx2, IDBTransaction>>(true);\n    typeAssert<IsExact<typeof unwrappedTx3, IDBTransaction>>(true);\n\n    assert.notProperty(unwrappedTx, 'store');\n    assert.notProperty(unwrappedTx2, 'store');\n    assert.notProperty(unwrappedTx3, 'store');\n  });\n});\n\nexport interface RenamedDBSchema extends DBSchema {\n  'key-val-store-renamed': {\n    key: string;\n    value: number;\n  };\n  'object-store': {\n    value: ObjectStoreValue;\n    key: number;\n    indexes: { 'date-renamed': Date; title: string };\n  };\n}\n\nsuite('IDBPObjectStore', () => {\n  let db: IDBPDatabase;\n\n  teardown('Close DB', async () => {\n    if (db) db.close();\n    await deleteDatabase();\n  });\n\n  test('mode', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n    const store1 = schemaDB.transaction('key-val-store', 'readonly').store;\n    const store2 = schemaDB.transaction('key-val-store', 'readwrite').store;\n\n    typeAssert<\n      IsExact<\n        typeof store1,\n        IDBPObjectStore<\n          TestDBSchema,\n          ['key-val-store'],\n          'key-val-store',\n          'readonly'\n        >\n      >\n    >(true);\n    typeAssert<\n      IsExact<\n        typeof store2,\n        IDBPObjectStore<\n          TestDBSchema,\n          ['key-val-store'],\n          'key-val-store',\n          'readwrite'\n        >\n      >\n    >(true);\n\n    typeAssert<IsExact<typeof store1.add, undefined>>(true);\n    typeAssert<IsExact<typeof store1.put, undefined>>(true);\n    typeAssert<IsExact<typeof store1.delete, undefined>>(true);\n    typeAssert<IsExact<typeof store1.clear, undefined>>(true);\n    typeAssert<IsExact<typeof store1.createIndex, undefined>>(true);\n\n    typeAssert<\n      IsExact<\n        typeof store2.add,\n        (\n          value: number,\n          key?: string | IDBKeyRange | undefined,\n        ) => Promise<string>\n      >\n    >(true);\n    typeAssert<\n      IsExact<\n        typeof store2.put,\n        (\n          value: number,\n          key?: string | IDBKeyRange | undefined,\n        ) => Promise<string>\n      >\n    >(true);\n    typeAssert<\n      IsExact<\n        typeof store2.delete,\n        (key: string | IDBKeyRange) => Promise<void>\n      >\n    >(true);\n    typeAssert<IsExact<typeof store2.clear, () => Promise<void>>>(true);\n    typeAssert<IsExact<typeof store2.createIndex, undefined>>(true);\n  });\n\n  test('indexNames', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const tx = schemaDB.transaction('object-store');\n    const tx2 = db.transaction('object-store');\n\n    typeAssert<\n      IsExact<typeof tx.store.indexNames, TypedDOMStringList<'date' | 'title'>>\n    >(true);\n\n    typeAssert<\n      IsExact<typeof tx2.store.indexNames, TypedDOMStringList<string>>\n    >(true);\n  });\n\n  test('set name', async () => {\n    const schemaDB = await openDBWithSchema();\n    schemaDB.close();\n\n    const newDB = await openDB<RenamedDBSchema>(dbName, getNextVersion(), {\n      upgrade(db, oldVersion, newVersion, tx) {\n        const store = (tx as unknown as IDBPTransaction).objectStore(\n          'key-val-store',\n        );\n        store.name = 'key-val-store-renamed';\n      },\n    });\n\n    db = newDB as IDBPDatabase;\n\n    assert(newDB.objectStoreNames.contains('key-val-store-renamed'));\n  });\n\n  test('transaction', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const tx = schemaDB.transaction('object-store');\n    const tx2 = db.transaction('object-store');\n    const store = schemaDB\n      .transaction(['object-store', 'key-val-store'])\n      .objectStore('object-store');\n\n    typeAssert<\n      IsExact<\n        typeof tx.store.transaction,\n        IDBPTransaction<TestDBSchema, ['object-store']>\n      >\n    >(true);\n\n    typeAssert<\n      IsExact<\n        typeof tx2.store.transaction,\n        IDBPTransaction<unknown, ['object-store']>\n      >\n    >(true);\n\n    typeAssert<\n      IsExact<\n        typeof store.transaction,\n        IDBPTransaction<TestDBSchema, ('object-store' | 'key-val-store')[]>\n      >\n    >(true);\n  });\n\n  test('add', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const store1 = schemaDB.transaction('key-val-store', 'readwrite').store;\n\n    typeAssert<IsExact<Parameters<typeof store1.add>[0], number>>(true);\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof store1.add>[1],\n        string | IDBKeyRange | undefined\n      >\n    >(true);\n\n    const key = await store1.add(234, 'new');\n\n    typeAssert<IsExact<typeof key, string>>(true);\n\n    const val = await store1.get('new');\n\n    assert.strictEqual(val, 234, 'Correct value from store');\n\n    const store2 = db.transaction('object-store', 'readwrite').store;\n\n    typeAssert<IsExact<Parameters<typeof store2.add>[0], any>>(true);\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof store2.add>[1],\n        IDBValidKey | IDBKeyRange | undefined\n      >\n    >(true);\n\n    const key2 = await store2.add({\n      id: 5,\n      title: 'Article 5',\n      date: new Date('2018-05-09'),\n    });\n\n    typeAssert<IsExact<typeof key2, IDBValidKey>>(true);\n\n    const val2 = await store2.get(5);\n\n    typeAssert<IsExact<typeof val2, any>>(true);\n\n    assert.deepStrictEqual(\n      val2,\n      {\n        id: 5,\n        title: 'Article 5',\n        date: new Date('2018-05-09'),\n      },\n      'Correct value from store',\n    );\n  });\n\n  test('clear', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const store1 = schemaDB.transaction('key-val-store', 'readwrite').store;\n\n    store1.clear();\n    const val = await store1.count();\n\n    assert.strictEqual(val, 0, 'Correct value from store');\n\n    const store2 = db.transaction('object-store', 'readwrite').store;\n\n    store2.clear();\n    const val2 = await store2.count();\n\n    assert.strictEqual(val2, 0, 'Correct value from store');\n  });\n\n  test('count', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const store1 = schemaDB.transaction('key-val-store').store;\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof store1.count>[0],\n        string | IDBKeyRange | undefined | null\n      >\n    >(true);\n\n    const val = await store1.count();\n\n    typeAssert<IsExact<typeof val, number>>(true);\n\n    assert.strictEqual(val, 3, 'Correct count');\n\n    const store2 = db.transaction('object-store').store;\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof store2.count>[0],\n        IDBValidKey | IDBKeyRange | undefined | null\n      >\n    >(true);\n\n    const val2 = await store2.count();\n\n    typeAssert<IsExact<typeof val2, number>>(true);\n\n    assert.strictEqual(val2, 4, 'Correct count');\n  });\n\n  test('createIndex (db with DBTypes)', async () => {\n    db = (await openDB<TestDBSchema>(dbName, getNextVersion(), {\n      upgrade(db, oldVersion, newVersion, tx) {\n        const store = db.createObjectStore('object-store');\n        typeAssert<\n          IsExact<Parameters<typeof store.createIndex>[0], 'date' | 'title'>\n        >(true);\n      },\n    })) as IDBPDatabase;\n  });\n\n  test('createIndex (db without DBTypes)', async () => {\n    db = (await openDB(dbName, getNextVersion(), {\n      upgrade(db, oldVersion, newVersion, tx) {\n        const store = db.createObjectStore('object-store');\n        typeAssert<IsExact<Parameters<typeof store.createIndex>[0], string>>(\n          true,\n        );\n      },\n    })) as IDBPDatabase;\n  });\n\n  test('delete', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const store1 = schemaDB.transaction('key-val-store', 'readwrite').store;\n\n    typeAssert<\n      IsExact<Parameters<typeof store1.delete>[0], string | IDBKeyRange>\n    >(true);\n\n    await store1.delete('foo');\n    const val = await store1.get('foo');\n\n    assert.strictEqual(val, undefined, 'Correct value from store');\n\n    const store2 = db.transaction('object-store', 'readwrite').store;\n\n    typeAssert<\n      IsExact<Parameters<typeof store2.delete>[0], IDBValidKey | IDBKeyRange>\n    >(true);\n\n    await store2.delete(1);\n    const val2 = await store2.get(1);\n\n    assert.strictEqual(val2, undefined, 'Correct value from store');\n  });\n\n  test('get', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const store1 = schemaDB.transaction('key-val-store').store;\n\n    typeAssert<IsExact<Parameters<typeof store1.get>[0], string | IDBKeyRange>>(\n      true,\n    );\n\n    const val = await store1.get('foo');\n\n    typeAssert<IsExact<typeof val, number | undefined>>(true);\n\n    assert.strictEqual(val, 123, 'Correct value from store');\n\n    const store2 = db.transaction('key-val-store').store;\n\n    typeAssert<\n      IsExact<Parameters<typeof store2.get>[0], IDBValidKey | IDBKeyRange>\n    >(true);\n\n    const val2 = await store2.get('bar');\n\n    typeAssert<IsExact<typeof val2, any>>(true);\n\n    assert.strictEqual(val2, 456, 'Correct value from store');\n  });\n\n  test('getAll', async function () {\n    if (!('getAll' in IDBObjectStore.prototype)) this.skip();\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const store1 = schemaDB.transaction('key-val-store').store;\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof store1.getAll>[0],\n        string | IDBKeyRange | undefined | null\n      >\n    >(true);\n\n    const val = await store1.getAll();\n\n    typeAssert<IsExact<typeof val, number[]>>(true);\n\n    assert.deepStrictEqual(val, [456, 123, 789], 'Correct values from store');\n\n    const store2 = db.transaction('key-val-store').store;\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof store2.getAll>[0],\n        IDBValidKey | IDBKeyRange | undefined | null\n      >\n    >(true);\n\n    const val2 = await store2.getAll();\n\n    typeAssert<IsExact<typeof val2, any[]>>(true);\n\n    assert.deepStrictEqual(val2, [456, 123, 789], 'Correct values from store');\n  });\n\n  test('getAllKeys', async function () {\n    if (!('getAllKeys' in IDBObjectStore.prototype)) this.skip();\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const store1 = schemaDB.transaction('key-val-store').store;\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof store1.getAllKeys>[0],\n        string | IDBKeyRange | undefined | null\n      >\n    >(true);\n\n    const val = await store1.getAllKeys();\n\n    typeAssert<IsExact<typeof val, string[]>>(true);\n\n    assert.deepStrictEqual(\n      val,\n      ['bar', 'foo', 'hello'],\n      'Correct values from store',\n    );\n\n    const store2 = db.transaction('key-val-store').store;\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof store2.getAllKeys>[0],\n        IDBValidKey | IDBKeyRange | undefined | null\n      >\n    >(true);\n\n    const val2 = await store2.getAllKeys();\n\n    typeAssert<IsExact<typeof val2, IDBValidKey[]>>(true);\n\n    assert.deepStrictEqual(\n      val2,\n      ['bar', 'foo', 'hello'],\n      'Correct values from store',\n    );\n  });\n\n  test('getKey', async function () {\n    if (!('getKey' in IDBObjectStore.prototype)) this.skip();\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const store1 = schemaDB.transaction('key-val-store').store;\n\n    typeAssert<\n      IsExact<Parameters<typeof store1.getKey>[0], string | IDBKeyRange>\n    >(true);\n\n    const val = await store1.getKey(IDBKeyRange.lowerBound('a'));\n\n    typeAssert<IsExact<typeof val, string | undefined>>(true);\n\n    assert.strictEqual(val, 'bar', 'Correct value');\n\n    const store2 = db.transaction('key-val-store').store;\n\n    typeAssert<\n      IsExact<Parameters<typeof store2.getKey>[0], IDBValidKey | IDBKeyRange>\n    >(true);\n\n    const val2 = await store2.getKey(IDBKeyRange.lowerBound('c'));\n\n    typeAssert<IsExact<typeof val2, IDBValidKey | undefined>>(true);\n\n    assert.strictEqual(val2, 'foo', 'Correct value');\n  });\n\n  test('index', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const store1 = schemaDB.transaction('object-store').store;\n\n    typeAssert<IsExact<Parameters<typeof store1.index>[0], 'date' | 'title'>>(\n      true,\n    );\n\n    const store2 = db.transaction('object-store').store;\n\n    typeAssert<IsExact<Parameters<typeof store2.index>[0], string>>(true);\n  });\n\n  test('openCursor', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const store1 = schemaDB.transaction('key-val-store').store;\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof store1.openCursor>[0],\n        string | IDBKeyRange | undefined | null\n      >\n    >(true);\n\n    const cursor1 = await store1.openCursor();\n\n    typeAssert<\n      IsExact<\n        typeof cursor1,\n        IDBPCursorWithValue<\n          TestDBSchema,\n          ['key-val-store'],\n          'key-val-store',\n          unknown\n        > | null\n      >\n    >(true);\n\n    assert.instanceOf(cursor1, IDBCursorWithValue);\n\n    const store2 = db.transaction('object-store').store;\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof store2.openCursor>[0],\n        IDBValidKey | IDBKeyRange | undefined | null\n      >\n    >(true);\n\n    const cursor2 = await store2.openCursor();\n\n    typeAssert<\n      IsExact<\n        typeof cursor2,\n        IDBPCursorWithValue<\n          unknown,\n          ['object-store'],\n          'object-store',\n          unknown\n        > | null\n      >\n    >(true);\n\n    assert.instanceOf(cursor2, IDBCursorWithValue);\n  });\n\n  test('openKeyCursor', async function () {\n    if (!('openKeyCursor' in IDBObjectStore.prototype)) this.skip();\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const store1 = schemaDB.transaction('key-val-store').store;\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof store1.openKeyCursor>[0],\n        string | IDBKeyRange | undefined | null\n      >\n    >(true);\n\n    const cursor1 = await store1.openKeyCursor();\n\n    typeAssert<\n      IsExact<\n        typeof cursor1,\n        IDBPCursor<\n          TestDBSchema,\n          ['key-val-store'],\n          'key-val-store',\n          unknown\n        > | null\n      >\n    >(true);\n\n    const store2 = db.transaction('object-store').store;\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof store2.openKeyCursor>[0],\n        IDBValidKey | IDBKeyRange | undefined | null\n      >\n    >(true);\n\n    const cursor2 = await store2.openKeyCursor();\n\n    typeAssert<\n      IsExact<\n        typeof cursor2,\n        IDBPCursor<unknown, ['object-store'], 'object-store', unknown> | null\n      >\n    >(true);\n  });\n\n  test('put', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const store1 = schemaDB.transaction('key-val-store', 'readwrite').store;\n\n    typeAssert<IsExact<Parameters<typeof store1.put>[0], number>>(true);\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof store1.put>[1],\n        string | IDBKeyRange | undefined\n      >\n    >(true);\n\n    const key = await store1.put(234, 'new');\n\n    typeAssert<IsExact<typeof key, string>>(true);\n\n    const val = await store1.get('new');\n\n    assert.strictEqual(val, 234, 'Correct value from store');\n\n    const store2 = db.transaction('object-store', 'readwrite').store;\n\n    typeAssert<IsExact<Parameters<typeof store2.put>[0], any>>(true);\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof store2.put>[1],\n        IDBValidKey | IDBKeyRange | undefined\n      >\n    >(true);\n\n    const key2 = await store2.put({\n      id: 5,\n      title: 'Article 5',\n      date: new Date('2018-05-09'),\n    });\n\n    typeAssert<IsExact<typeof key2, IDBValidKey>>(true);\n\n    const val2 = await store2.get(5);\n\n    typeAssert<IsExact<typeof val2, any>>(true);\n\n    assert.deepStrictEqual(\n      val2,\n      {\n        id: 5,\n        title: 'Article 5',\n        date: new Date('2018-05-09'),\n      },\n      'Correct value from store',\n    );\n  });\n\n  test('wrap', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const tx = schemaDB.transaction('key-val-store');\n    const idbTx = unwrap(tx);\n    const store = idbTx.objectStore('key-val-store');\n\n    assert.instanceOf(store.get('blah'), IDBRequest);\n\n    const wrappedStore = wrap(store);\n\n    typeAssert<IsExact<typeof wrappedStore, IDBPObjectStore>>(true);\n\n    assert.instanceOf(wrappedStore.get('blah'), Promise);\n  });\n\n  test('unwrap', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const store1 = schemaDB.transaction('key-val-store').store;\n    const store2 = db.transaction('key-val-store').store;\n    const store3 = schemaDB.transaction('key-val-store', 'readwrite').store;\n    const unwrappedStore1 = unwrap(store1);\n    const unwrappedStore2 = unwrap(store2);\n    const unwrappedStore3 = unwrap(store3);\n\n    typeAssert<IsExact<typeof unwrappedStore1, IDBObjectStore>>(true);\n    typeAssert<IsExact<typeof unwrappedStore2, IDBObjectStore>>(true);\n    typeAssert<IsExact<typeof unwrappedStore3, IDBObjectStore>>(true);\n\n    assert.instanceOf(unwrappedStore1.get('foo'), IDBRequest);\n    assert.instanceOf(unwrappedStore2.get('foo'), IDBRequest);\n    assert.instanceOf(unwrappedStore3.get('foo'), IDBRequest);\n  });\n});\n\nsuite('IDBPIndex', () => {\n  let db: IDBPDatabase;\n\n  teardown('Close DB', async () => {\n    if (db) db.close();\n    await deleteDatabase();\n  });\n\n  test('mode', async () => {\n    db = (await openDB<TestDBSchema>(dbName, getNextVersion(), {\n      upgrade(db, oldVersion, newVersion, tx) {\n        const store = db.createObjectStore('object-store');\n        const index = store.createIndex('date', 'date');\n        typeAssert<\n          IsExact<\n            typeof index,\n            IDBPIndex<\n              TestDBSchema,\n              ['object-store'],\n              'object-store',\n              'date',\n              'versionchange'\n            >\n          >\n        >(true);\n      },\n    })) as IDBPDatabase;\n  });\n\n  test('objectStore', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const index1 = schemaDB.transaction('object-store').store.index('date');\n    const index2 = schemaDB\n      .transaction(['object-store', 'key-val-store'])\n      .objectStore('object-store')\n      .index('date');\n    const index3 = db.transaction('object-store').store.index('date');\n\n    typeAssert<\n      IsExact<\n        typeof index1.objectStore,\n        IDBPObjectStore<TestDBSchema, ['object-store'], 'object-store'>\n      >\n    >(true);\n\n    typeAssert<\n      IsExact<\n        typeof index2.objectStore,\n        IDBPObjectStore<\n          TestDBSchema,\n          ('object-store' | 'key-val-store')[],\n          'object-store'\n        >\n      >\n    >(true);\n\n    typeAssert<\n      IsExact<\n        typeof index3.objectStore,\n        IDBPObjectStore<unknown, ['object-store'], 'object-store'>\n      >\n    >(true);\n  });\n\n  test('set name', async () => {\n    const schemaDB = await openDBWithSchema();\n    schemaDB.close();\n\n    const newDB = await openDB<RenamedDBSchema>(dbName, getNextVersion(), {\n      upgrade(db, oldVersion, newVersion, tx) {\n        const store = tx.objectStore(\n          'object-store',\n        ) as unknown as IDBObjectStore;\n        const index = store.index('date');\n        index.name = 'date-renamed';\n      },\n    });\n    db = newDB as IDBPDatabase;\n\n    const tx = newDB.transaction('object-store');\n    assert(tx.store.indexNames.contains('date-renamed'));\n  });\n\n  test('count', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const index1 = schemaDB.transaction('object-store').store.index('date');\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof index1.count>[0],\n        Date | IDBKeyRange | undefined | null\n      >\n    >(true);\n\n    const val = await index1.count();\n\n    typeAssert<IsExact<typeof val, number>>(true);\n\n    assert.strictEqual(val, 4, 'Correct count');\n\n    const index2 = db.transaction('object-store').store.index('title');\n\n    typeAssert<\n      IsExact<\n        Parameters<typeof index2.count>[0],\n        IDBValidKey | IDBKeyRange | undefined | null\n      >\n    >(true);\n\n    const val2 = await index2.count();\n\n    typeAssert<IsExact<typeof val2, number>>(true);\n\n    assert.strictEqual(val2, 4, 'Correct count');\n  });\n\n  test('get', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    const index1 = schemaDB.transaction('object-store').store.index('date');\n\n    typeAssert<IsExact<Parameters<typeof index1.get>[0], Date | IDBKeyRange>>(\n      true,\n    );\n\n    const val = await index1.get(new Date('2019-01-03'));\n\n    typeAssert<IsExact<typeof val, ObjectStoreValue | undefined>>(true);\n\n    assert.deepStrictEqual(\n      val,\n      {\n        id: 2,\n        title: 'Article 2',\n        date: new Date('2019-01-03'),\n      },\n      'Correct value from store',\n    );\n\n    const index2 = db.transaction('object-store').store.index('title');\n\n    typeAssert<\n      IsExact<Parameters<typeof index2.get>[0], IDBValidKey | IDBKeyRange>\n    >(true);\n\n    const val2 = await index2.get('Article 2');\n\n    typeAssert<IsExact<typeof val2, any>>(true);\n\n    assert.deepStrictEqual(\n      val2,\n      {\n        id: 2,\n        title: 'Article 2',\n        date: new Date('2019-01-03'),\n      },\n      'Correct value from store',\n    );\n  });\n\n  test('getAll', async function () {\n    if (!('getAll' in IDBIndex.prototype)) this.skip();\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const index = schemaDB.transaction('object-store').store.index('date');\n\n      typeAssert<\n        IsExact<\n          Parameters<typeof index.getAll>[0],\n          Date | IDBKeyRange | undefined | null\n        >\n      >(true);\n\n      const val = await index.getAll();\n\n      typeAssert<IsExact<typeof val, ObjectStoreValue[]>>(true);\n\n      assert.deepStrictEqual(\n        val,\n        [\n          {\n            id: 4,\n            title: 'Article 4',\n            date: new Date('2019-01-01'),\n          },\n          {\n            id: 3,\n            title: 'Article 3',\n            date: new Date('2019-01-02'),\n          },\n          {\n            id: 2,\n            title: 'Article 2',\n            date: new Date('2019-01-03'),\n          },\n          {\n            id: 1,\n            title: 'Article 1',\n            date: new Date('2019-01-04'),\n          },\n        ],\n        'Correct values from store',\n      );\n    }\n\n    {\n      const index = db.transaction('object-store').store.index('title');\n\n      typeAssert<\n        IsExact<\n          Parameters<typeof index.getAll>[0],\n          IDBValidKey | IDBKeyRange | undefined | null\n        >\n      >(true);\n\n      const val = await index.getAll();\n\n      typeAssert<IsExact<typeof val, any[]>>(true);\n\n      assert.deepStrictEqual(\n        val,\n        [\n          {\n            id: 1,\n            title: 'Article 1',\n            date: new Date('2019-01-04'),\n          },\n          {\n            id: 2,\n            title: 'Article 2',\n            date: new Date('2019-01-03'),\n          },\n          {\n            id: 3,\n            title: 'Article 3',\n            date: new Date('2019-01-02'),\n          },\n          {\n            id: 4,\n            title: 'Article 4',\n            date: new Date('2019-01-01'),\n          },\n        ],\n        'Correct values from store',\n      );\n    }\n  });\n\n  test('getAllKeys', async function () {\n    if (!('getAllKeys' in IDBIndex.prototype)) this.skip();\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const index = schemaDB.transaction('object-store').store.index('date');\n\n      typeAssert<\n        IsExact<\n          Parameters<typeof index.getAllKeys>[0],\n          Date | IDBKeyRange | undefined | null\n        >\n      >(true);\n\n      const val = await index.getAllKeys();\n\n      typeAssert<IsExact<typeof val, number[]>>(true);\n\n      assert.deepStrictEqual(val, [4, 3, 2, 1], 'Correct values from store');\n    }\n\n    {\n      const index = db.transaction('object-store').store.index('title');\n\n      typeAssert<\n        IsExact<\n          Parameters<typeof index.getAllKeys>[0],\n          IDBValidKey | IDBKeyRange | undefined | null\n        >\n      >(true);\n\n      const val = await index.getAllKeys();\n\n      typeAssert<IsExact<typeof val, IDBValidKey[]>>(true);\n\n      assert.deepStrictEqual(val, [1, 2, 3, 4], 'Correct values from store');\n    }\n  });\n\n  test('getKey', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const index = schemaDB.transaction('object-store').store.index('date');\n\n      typeAssert<\n        IsExact<Parameters<typeof index.getKey>[0], Date | IDBKeyRange>\n      >(true);\n\n      const val = await index.getKey(\n        IDBKeyRange.lowerBound(new Date('1990-01-01')),\n      );\n\n      typeAssert<IsExact<typeof val, number | undefined>>(true);\n\n      assert.strictEqual(val, 4, 'Correct value');\n    }\n\n    {\n      const index = db.transaction('object-store').store.index('title');\n\n      typeAssert<\n        IsExact<Parameters<typeof index.getKey>[0], IDBValidKey | IDBKeyRange>\n      >(true);\n\n      const val = await index.getKey(IDBKeyRange.lowerBound('A'));\n\n      typeAssert<IsExact<typeof val, IDBValidKey | undefined>>(true);\n\n      assert.strictEqual(val, 1, 'Correct value');\n    }\n  });\n\n  test('openCursor', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const index = schemaDB.transaction('object-store').store.index('date');\n\n      typeAssert<\n        IsExact<\n          Parameters<typeof index.openCursor>[0],\n          Date | IDBKeyRange | undefined | null\n        >\n      >(true);\n\n      const cursor = await index.openCursor();\n\n      typeAssert<\n        IsExact<\n          typeof cursor,\n          IDBPCursorWithValue<\n            TestDBSchema,\n            ['object-store'],\n            'object-store',\n            'date'\n          > | null\n        >\n      >(true);\n\n      assert.instanceOf(cursor, IDBCursorWithValue);\n    }\n\n    {\n      const index = db.transaction('object-store').store.index('title');\n\n      typeAssert<\n        IsExact<\n          Parameters<typeof index.openCursor>[0],\n          IDBValidKey | IDBKeyRange | undefined | null\n        >\n      >(true);\n\n      const cursor = await index.openCursor();\n\n      typeAssert<\n        IsExact<\n          typeof cursor,\n          IDBPCursorWithValue<\n            unknown,\n            ['object-store'],\n            'object-store',\n            'title'\n          > | null\n        >\n      >(true);\n\n      assert.instanceOf(cursor, IDBCursorWithValue);\n    }\n  });\n\n  test('openKeyCursor', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const index = schemaDB.transaction('object-store').store.index('date');\n\n      typeAssert<\n        IsExact<\n          Parameters<typeof index.openKeyCursor>[0],\n          Date | IDBKeyRange | undefined | null\n        >\n      >(true);\n\n      const cursor = await index.openKeyCursor();\n\n      typeAssert<\n        IsExact<\n          typeof cursor,\n          IDBPCursor<\n            TestDBSchema,\n            ['object-store'],\n            'object-store',\n            'date'\n          > | null\n        >\n      >(true);\n\n      assert.instanceOf(cursor, IDBCursor);\n    }\n\n    {\n      const index = db.transaction('object-store').store.index('title');\n\n      typeAssert<\n        IsExact<\n          Parameters<typeof index.openKeyCursor>[0],\n          IDBValidKey | IDBKeyRange | undefined | null\n        >\n      >(true);\n\n      const cursor = await index.openKeyCursor();\n\n      typeAssert<\n        IsExact<\n          typeof cursor,\n          IDBPCursor<unknown, ['object-store'], 'object-store', 'title'> | null\n        >\n      >(true);\n\n      assert.instanceOf(cursor, IDBCursor);\n    }\n  });\n\n  test('wrap', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const tx = schemaDB.transaction('object-store');\n    const idbTx = unwrap(tx);\n    const index = idbTx.objectStore('object-store').index('date');\n\n    assert.instanceOf(index.get('blah'), IDBRequest);\n\n    const wrappedIndex = wrap(index);\n\n    typeAssert<IsExact<typeof wrappedIndex, IDBPIndex>>(true);\n\n    assert.instanceOf(wrappedIndex.get('blah'), Promise);\n  });\n\n  test('unwrap', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n\n    const index1 = schemaDB.transaction('object-store').store.index('date');\n    const index2 = db.transaction('object-store').store.index('title');\n    const index3 = schemaDB\n      .transaction('object-store', 'readwrite')\n      .store.index('date');\n\n    const unwrappedIndex1 = unwrap(index1);\n    const unwrappedIndex2 = unwrap(index2);\n    const unwrappedIndex3 = unwrap(index3);\n\n    typeAssert<IsExact<typeof unwrappedIndex1, IDBIndex>>(true);\n    typeAssert<IsExact<typeof unwrappedIndex2, IDBIndex>>(true);\n    typeAssert<IsExact<typeof unwrappedIndex3, IDBIndex>>(true);\n\n    assert.instanceOf(unwrappedIndex1.get('foo'), IDBRequest);\n    assert.instanceOf(unwrappedIndex2.get('foo'), IDBRequest);\n    assert.instanceOf(unwrappedIndex3.get('foo'), IDBRequest);\n  });\n});\n\nsuite('IDBPCursor', () => {\n  let db: IDBPDatabase;\n\n  teardown('Close DB', async () => {\n    if (db) db.close();\n    await deleteDatabase();\n  });\n\n  test('mode', async () => {\n    const schemaDB = await openDBWithSchema();\n    db = schemaDB as IDBPDatabase;\n    const store = schemaDB.transaction('object-store', 'readwrite').store;\n    const cursor = store.openCursor();\n    typeAssert<\n      IsExact<\n        typeof cursor,\n        Promise<IDBPCursorWithValue<\n          TestDBSchema,\n          ['object-store'],\n          'object-store',\n          unknown,\n          'readwrite'\n        > | null>\n      >\n    >(true);\n  });\n\n  test('key', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const index = schemaDB.transaction('object-store').store.index('date');\n      const cursor = await index.openCursor();\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      typeAssert<IsExact<typeof cursor.key, Date>>(true);\n\n      assert.instanceOf(cursor.key, Date);\n      assert.strictEqual(\n        cursor.key.valueOf(),\n        new Date('2019-01-01').valueOf(),\n      );\n    }\n\n    {\n      const index = db.transaction('object-store').store.index('title');\n      const cursor = await index.openCursor();\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      typeAssert<IsExact<typeof cursor.key, IDBValidKey>>(true);\n\n      assert.strictEqual(cursor.key, 'Article 1');\n    }\n  });\n\n  test('primaryKey', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const index = schemaDB.transaction('object-store').store.index('date');\n      const cursor = await index.openCursor();\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      typeAssert<IsExact<typeof cursor.primaryKey, number>>(true);\n\n      assert.strictEqual(cursor.primaryKey, 4);\n    }\n\n    {\n      const index = db.transaction('object-store').store.index('title');\n      const cursor = await index.openCursor();\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      typeAssert<IsExact<typeof cursor.primaryKey, IDBValidKey>>(true);\n\n      assert.strictEqual(cursor.primaryKey, 1);\n    }\n  });\n\n  test('source', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const index = schemaDB.transaction('object-store').store.index('date');\n      const cursor = await index.openCursor();\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      typeAssert<\n        IsExact<\n          typeof cursor.source,\n          IDBPIndex<TestDBSchema, ['object-store'], 'object-store', 'date'>\n        >\n      >(true);\n    }\n\n    {\n      const index = db.transaction('object-store').store.index('title');\n      const cursor = await index.openCursor();\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      typeAssert<\n        IsExact<\n          typeof cursor.source,\n          IDBPIndex<unknown, ['object-store'], 'object-store', 'title'>\n        >\n      >(true);\n    }\n  });\n\n  test('advance', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const index = schemaDB.transaction('object-store').store.index('date');\n      let cursor = await index.openCursor();\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      cursor = await cursor.advance(2);\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      assert.strictEqual(cursor.primaryKey, 2);\n    }\n\n    {\n      const index = db.transaction('object-store').store.index('title');\n      let cursor = await index.openCursor();\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      cursor = await cursor.advance(2);\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      assert.strictEqual(cursor.primaryKey, 3);\n    }\n  });\n\n  test('continue', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const index = schemaDB.transaction('object-store').store.index('date');\n      let cursor = await index.openCursor();\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      typeAssert<\n        IsExact<Parameters<typeof cursor.continue>[0], Date | undefined>\n      >(true);\n\n      cursor = await cursor.continue(new Date('2019-01-02T05:00:00.000Z'));\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      assert.strictEqual(cursor.primaryKey, 2);\n    }\n\n    {\n      const index = db.transaction('object-store').store.index('title');\n      let cursor = await index.openCursor();\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      typeAssert<\n        IsExact<Parameters<typeof cursor.continue>[0], IDBValidKey | undefined>\n      >(true);\n\n      cursor = await cursor.continue('Article 20');\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      assert.strictEqual(cursor.primaryKey, 3);\n    }\n  });\n\n  test('continuePrimaryKey', async function () {\n    if (!('continuePrimaryKey' in IDBCursor.prototype)) this.skip();\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const index = schemaDB.transaction('object-store').store.index('date');\n      let cursor = await index.openCursor();\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      typeAssert<\n        IsExact<Parameters<typeof cursor.continuePrimaryKey>[0], Date>\n      >(true);\n\n      typeAssert<\n        IsExact<Parameters<typeof cursor.continuePrimaryKey>[1], number>\n      >(true);\n\n      cursor = await cursor.continuePrimaryKey(\n        new Date('2019-01-02T05:00:00.000Z'),\n        1.5,\n      );\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      assert.strictEqual(cursor.primaryKey, 2);\n    }\n\n    {\n      const index = db.transaction('object-store').store.index('title');\n      let cursor = await index.openCursor();\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      typeAssert<\n        IsExact<Parameters<typeof cursor.continuePrimaryKey>[0], IDBValidKey>\n      >(true);\n\n      typeAssert<\n        IsExact<Parameters<typeof cursor.continuePrimaryKey>[1], IDBValidKey>\n      >(true);\n\n      cursor = await cursor.continuePrimaryKey('Article 3', 3.5);\n\n      if (!cursor) {\n        assert.fail('Expected cursor');\n        return;\n      }\n\n      assert.strictEqual(cursor.primaryKey, 4);\n    }\n  });\n\n  test('delete', async function () {\n    if (!('delete' in IDBCursor.prototype)) this.skip();\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const store = schemaDB.transaction('key-val-store', 'readwrite').store;\n      let cursor = await store.openCursor();\n\n      while (cursor) {\n        if (cursor.value === 456) cursor.delete();\n        cursor = await cursor.continue();\n      }\n\n      assert.deepEqual(await store.getAll(), [123, 789]);\n    }\n\n    {\n      const store = db.transaction('key-val-store', 'readwrite').store;\n      let cursor = await store.openCursor();\n\n      while (cursor) {\n        if (cursor.value === 789) cursor.delete();\n        cursor = await cursor.continue();\n      }\n\n      assert.deepEqual(await store.getAll(), [123]);\n    }\n  });\n\n  test('update', async function () {\n    if (!('update' in IDBCursor.prototype)) this.skip();\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const store = schemaDB.transaction('key-val-store', 'readwrite').store;\n      let cursor = await store.openCursor();\n\n      while (cursor) {\n        typeAssert<IsExact<Parameters<typeof cursor.update>[0], number>>(true);\n\n        cursor.update(cursor.value + 1);\n        cursor = await cursor.continue();\n      }\n\n      assert.deepEqual(await store.getAll(), [457, 124, 790]);\n    }\n\n    {\n      const store = db.transaction('key-val-store', 'readwrite').store;\n      let cursor = await store.openCursor();\n\n      while (cursor) {\n        typeAssert<IsExact<Parameters<typeof cursor.update>[0], any>>(true);\n\n        cursor.update(cursor.value + 1);\n        cursor = await cursor.continue();\n      }\n\n      assert.deepEqual(await store.getAll(), [458, 125, 791]);\n    }\n  });\n\n  test('unwrap', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const cursor = await schemaDB\n        .transaction('object-store')\n        .store.openCursor();\n      if (!cursor) throw Error('expected cursor');\n      const unwrappedCursor = unwrap(cursor);\n\n      typeAssert<IsExact<typeof unwrappedCursor, IDBCursorWithValue>>(true);\n\n      assert.strictEqual(unwrappedCursor.continue(), undefined);\n    }\n\n    {\n      const cursor = await db.transaction('object-store').store.openCursor();\n      if (!cursor) throw Error('expected cursor');\n      const unwrappedCursor = unwrap(cursor);\n\n      typeAssert<IsExact<typeof unwrappedCursor, IDBCursorWithValue>>(true);\n\n      assert.strictEqual(unwrappedCursor.continue(), undefined);\n    }\n  });\n});\n\nsuite('IDBPCursorWithValue', () => {\n  let db: IDBPDatabase;\n\n  teardown('Close DB', async () => {\n    if (db) db.close();\n    await deleteDatabase();\n  });\n\n  test('unwrap', async () => {\n    const schemaDB = await openDBWithData();\n    db = schemaDB as IDBPDatabase;\n\n    {\n      const cursor = await schemaDB\n        .transaction('object-store', 'readwrite')\n        .store.openCursor();\n      if (!cursor) throw Error('expected cursor');\n      const unwrappedCursor = unwrap(cursor);\n\n      typeAssert<IsExact<typeof unwrappedCursor, IDBCursorWithValue>>(true);\n\n      assert.instanceOf(\n        unwrappedCursor.update(unwrappedCursor.value),\n        IDBRequest,\n      );\n    }\n\n    {\n      const cursor = await db\n        .transaction('object-store', 'readwrite')\n        .store.openCursor();\n      if (!cursor) throw Error('expected cursor');\n      const unwrappedCursor = unwrap(cursor);\n\n      typeAssert<IsExact<typeof unwrappedCursor, IDBCursorWithValue>>(true);\n\n      assert.instanceOf(\n        unwrappedCursor.update(unwrappedCursor.value),\n        IDBRequest,\n      );\n    }\n  });\n});\n"
  },
  {
    "path": "test/missing-types.d.ts",
    "content": "declare module 'chai/chai' {\n  var chai: typeof import('chai');\n  export default chai;\n}\n"
  },
  {
    "path": "test/open.ts",
    "content": "import 'mocha/mocha';\nimport { assert } from 'chai';\nimport { openDB, IDBPDatabase, IDBPTransaction, wrap, unwrap } from '../src/';\nimport { assert as typeAssert, IsExact } from 'conditional-type-checks';\nimport {\n  getNextVersion,\n  TestDBSchema,\n  dbName,\n  openDBWithSchema,\n  deleteDatabase,\n} from './utils';\n\nsuite('openDb', () => {\n  let db: IDBPDatabase;\n\n  teardown('Close DB', () => {\n    if (db) db.close();\n  });\n\n  test('upgrade', async () => {\n    let upgradeRun = false;\n    const version = getNextVersion();\n    db = (await openDB<TestDBSchema>(dbName, version, {\n      upgrade(db, oldVersion, newVersion, tx, event) {\n        upgradeRun = true;\n\n        typeAssert<IsExact<typeof db, IDBPDatabase<TestDBSchema>>>(true);\n        assert.instanceOf(db, IDBDatabase, 'db instance');\n\n        assert.strictEqual(oldVersion, 0);\n        assert.strictEqual(newVersion, version);\n\n        typeAssert<\n          IsExact<\n            typeof tx,\n            IDBPTransaction<\n              TestDBSchema,\n              ('key-val-store' | 'object-store')[],\n              'versionchange'\n            >\n          >\n        >(true);\n        assert.instanceOf(tx, IDBTransaction, 'transaction');\n        assert.strictEqual(tx.mode, 'versionchange', 'tx mode');\n\n        assert.instanceOf(event, IDBVersionChangeEvent, 'event');\n        typeAssert<IsExact<typeof event, IDBVersionChangeEvent>>(true);\n      },\n    })) as IDBPDatabase;\n\n    assert.isTrue(upgradeRun, 'upgrade run');\n  });\n\n  test('open without version - upgrade should not run', async () => {\n    let upgradeRun = false;\n\n    db = (await openDB<TestDBSchema>(dbName, undefined, {\n      upgrade(db, oldVersion, newVersion, tx) {\n        upgradeRun = true;\n      },\n    })) as IDBPDatabase;\n\n    assert.isFalse(upgradeRun, 'upgrade not run');\n    assert.strictEqual(db.version, 1);\n  });\n\n  test('open without version - database never existed', async () => {\n    db = (await openDB<TestDBSchema>(dbName)) as IDBPDatabase;\n\n    assert.strictEqual(db.version, 1);\n  });\n\n  test('open with undefined version - database never existed', async () => {\n    db = (await openDB<TestDBSchema>(dbName, undefined, {})) as IDBPDatabase;\n\n    assert.strictEqual(db.version, 1);\n  });\n\n  test('open without version - database previously created', async () => {\n    const version = getNextVersion();\n    db = (await openDB<TestDBSchema>(dbName, version)) as IDBPDatabase;\n    db.close();\n\n    db = (await openDB<TestDBSchema>(dbName)) as IDBPDatabase;\n\n    assert.strictEqual(db.version, version);\n  });\n\n  test('open with undefined version - database previously created', async () => {\n    const version = getNextVersion();\n    db = (await openDB<TestDBSchema>(dbName, version)) as IDBPDatabase;\n    db.close();\n\n    db = (await openDB<TestDBSchema>(dbName, undefined, {})) as IDBPDatabase;\n\n    assert.strictEqual(db.version, version);\n  });\n\n  test('upgrade - schemaless', async () => {\n    let upgradeRun = false;\n    const version = getNextVersion();\n    db = await openDB(dbName, version, {\n      upgrade(db, oldVersion, newVersion, tx) {\n        upgradeRun = true;\n        typeAssert<IsExact<typeof db, IDBPDatabase>>(true);\n        typeAssert<\n          IsExact<\n            typeof tx,\n            IDBPTransaction<unknown, string[], 'versionchange'>\n          >\n        >(true);\n      },\n    });\n\n    assert.isTrue(upgradeRun, 'upgrade run');\n  });\n\n  test('blocked and blocking', async () => {\n    let blockedCalled = false;\n    let blockingCalled = false;\n    let newDbBlockedCalled = false;\n    let newDbBlockingCalled = false;\n\n    const firstVersion = getNextVersion();\n    const nextVersion = getNextVersion();\n\n    db = (await openDB<TestDBSchema>(dbName, firstVersion, {\n      blocked() {\n        blockedCalled = true;\n      },\n      blocking(currentVersion, blockedVersion, event) {\n        blockingCalled = true;\n\n        assert.strictEqual(currentVersion, firstVersion);\n        assert.strictEqual(blockedVersion, nextVersion);\n\n        assert.instanceOf(event, IDBVersionChangeEvent, 'event');\n        typeAssert<IsExact<typeof event, IDBVersionChangeEvent>>(true);\n\n        // 'blocked' isn't called if older databases close once blocking fires.\n        // Using set timeout so closing isn't immediate.\n        setTimeout(() => db.close(), 0);\n      },\n    })) as IDBPDatabase;\n\n    assert.isFalse(blockedCalled);\n    assert.isFalse(blockingCalled);\n\n    db = (await openDB<TestDBSchema>(dbName, nextVersion, {\n      blocked(currentVersion, blockedVersion, event) {\n        newDbBlockedCalled = true;\n\n        assert.strictEqual(currentVersion, firstVersion);\n        assert.strictEqual(blockedVersion, nextVersion);\n\n        assert.instanceOf(event, IDBVersionChangeEvent, 'event');\n        typeAssert<IsExact<typeof event, IDBVersionChangeEvent>>(true);\n      },\n      blocking() {\n        newDbBlockingCalled = true;\n      },\n    })) as IDBPDatabase;\n\n    assert.isFalse(blockedCalled);\n    assert.isTrue(blockingCalled);\n    assert.isTrue(newDbBlockedCalled);\n    assert.isFalse(newDbBlockingCalled);\n  });\n\n  test('wrap', async () => {\n    let wrappedRequest: Promise<IDBPDatabase | undefined> =\n      Promise.resolve(undefined);\n\n    // Let's do it the old fashioned way\n    const idb = await new Promise<IDBDatabase>(async (resolve) => {\n      const request = indexedDB.open(dbName, getNextVersion());\n      wrappedRequest = wrap(request);\n      request.addEventListener('success', () => resolve(request.result));\n    });\n\n    assert.instanceOf(wrappedRequest, Promise, 'Wrapped request type');\n    db = wrap(idb);\n\n    typeAssert<IsExact<typeof db, IDBPDatabase>>(true);\n\n    assert.instanceOf(db, IDBDatabase, 'DB type');\n    assert.property(db, 'getAllFromIndex', 'DB looks wrapped');\n    assert.strictEqual(\n      db,\n      await wrappedRequest,\n      'Wrapped request and wrapped db are same',\n    );\n  });\n\n  test('unwrap', async () => {\n    const openPromise = openDB<TestDBSchema>(dbName, getNextVersion());\n    const request = unwrap(openPromise);\n\n    typeAssert<IsExact<typeof request, IDBOpenDBRequest>>(true);\n\n    assert.instanceOf(request, IDBOpenDBRequest, 'Request type');\n\n    const simpleDB = await openPromise;\n    simpleDB.close();\n\n    const schemaDb = await openDBWithSchema();\n    db = schemaDb as IDBPDatabase;\n    const idb = unwrap(schemaDb);\n\n    typeAssert<IsExact<typeof idb, IDBDatabase>>(true);\n\n    assert.instanceOf(idb, IDBDatabase, 'DB type');\n    assert.isFalse('getAllFromIndex' in idb, 'DB looks unwrapped');\n  });\n});\n\nsuite('deleteDb', () => {\n  let db: IDBPDatabase;\n\n  teardown('Close DB', () => {\n    if (db) db.close();\n  });\n\n  test('deleteDb', async () => {\n    db = (await openDBWithSchema()) as IDBPDatabase;\n    assert.lengthOf(db.objectStoreNames, 2, 'DB has two stores');\n    db.close();\n    await deleteDatabase();\n    db = await openDB(dbName, getNextVersion());\n    assert.lengthOf(db.objectStoreNames, 0, 'DB has no stores');\n  });\n\n  test('blocked', async () => {\n    let blockedCalled = false;\n    let blockingCalled = false;\n    let closeDbBlockedCalled = false;\n    const version = getNextVersion();\n\n    db = await openDB(dbName, version, {\n      blocked() {\n        blockedCalled = true;\n      },\n      blocking() {\n        blockingCalled = true;\n        // 'blocked' isn't called if older databases close once blocking fires.\n        // Using set timeout so closing isn't immediate.\n        setTimeout(() => db.close(), 0);\n      },\n    });\n\n    assert.isFalse(blockedCalled);\n    assert.isFalse(blockingCalled);\n\n    await deleteDatabase({\n      blocked(currentVersion, event) {\n        closeDbBlockedCalled = true;\n\n        assert.strictEqual(currentVersion, version);\n\n        assert.instanceOf(event, IDBVersionChangeEvent, 'event');\n        typeAssert<IsExact<typeof event, IDBVersionChangeEvent>>(true);\n      },\n    });\n\n    assert.isFalse(blockedCalled);\n    assert.isTrue(blockingCalled);\n    assert.isTrue(closeDbBlockedCalled);\n  });\n});\n"
  },
  {
    "path": "test/tsconfig.json",
    "content": "{\n  \"extends\": \"../generic-tsconfig.json\",\n  \"compilerOptions\": {\n    \"esModuleInterop\": true,\n    \"lib\": [\"esnext\", \"dom\"],\n    \"tsBuildInfoFile\": \"../.ts-tmp/.test.tsbuildinfo\",\n    \"declarationDir\": \"../build/test\"\n  },\n  \"references\": [{ \"path\": \"../src\" }]\n}\n"
  },
  {
    "path": "test/utils.ts",
    "content": "import {\n  DBSchema,\n  IDBPDatabase,\n  openDB,\n  DeleteDBCallbacks,\n  deleteDB,\n} from '../src/';\n\nexport interface ObjectStoreValue {\n  id: number;\n  title: string;\n  date: Date;\n}\n\nexport interface TestDBSchema extends DBSchema {\n  'key-val-store': {\n    key: string;\n    value: number;\n  };\n  'object-store': {\n    value: ObjectStoreValue;\n    key: number;\n    indexes: { date: Date; title: string };\n  };\n}\n\nexport const dbName = 'test-db';\nlet version = 0;\n\nexport function getNextVersion(): number {\n  version += 1;\n  return version;\n}\n\nlet dbWithSchemaCreated = false;\n\nexport function openDBWithSchema(): Promise<IDBPDatabase<TestDBSchema>> {\n  if (dbWithSchemaCreated) return openDB<TestDBSchema>(dbName, version);\n  dbWithSchemaCreated = true;\n  return openDB<TestDBSchema>(dbName, getNextVersion(), {\n    upgrade(db) {\n      db.createObjectStore('key-val-store');\n      const store = db.createObjectStore('object-store', { keyPath: 'id' });\n      store.createIndex('date', 'date');\n      store.createIndex('title', 'title');\n    },\n  });\n}\n\nlet dbWithDataCreated = false;\n\nexport async function openDBWithData() {\n  if (dbWithDataCreated) return openDB<TestDBSchema>(dbName, version);\n  dbWithDataCreated = true;\n  const db = await openDBWithSchema();\n  const tx = db.transaction(['key-val-store', 'object-store'], 'readwrite');\n  const keyStore = tx.objectStore('key-val-store');\n  const objStore = tx.objectStore('object-store');\n  keyStore.put(123, 'foo');\n  keyStore.put(456, 'bar');\n  keyStore.put(789, 'hello');\n  objStore.put({\n    id: 1,\n    title: 'Article 1',\n    date: new Date('2019-01-04'),\n  });\n  objStore.put({\n    id: 2,\n    title: 'Article 2',\n    date: new Date('2019-01-03'),\n  });\n  objStore.put({\n    id: 3,\n    title: 'Article 3',\n    date: new Date('2019-01-02'),\n  });\n  objStore.put({\n    id: 4,\n    title: 'Article 4',\n    date: new Date('2019-01-01'),\n  });\n  return db;\n}\n\nexport function deleteDatabase(callbacks: DeleteDBCallbacks = {}) {\n  version = 0;\n  dbWithSchemaCreated = false;\n  dbWithDataCreated = false;\n  return deleteDB(dbName, callbacks);\n}\n"
  }
]