├── .airtap.yml ├── .github ├── dependabot.yml └── workflows │ ├── release.yml │ └── test.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── UPGRADING.md ├── browser.js ├── index.d.ts ├── index.js ├── package.json ├── test.js └── tsconfig.json /.airtap.yml: -------------------------------------------------------------------------------- 1 | providers: 2 | - airtap-playwright 3 | 4 | browsers: 5 | - name: chromium 6 | - name: firefox 7 | - name: webkit 8 | 9 | # Until airtap switches to rollup 10 | browserify: 11 | - transform: babelify 12 | global: true 13 | presets: ["@babel/preset-env"] 14 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: / 5 | schedule: 6 | interval: monthly 7 | ignore: 8 | - dependency-name: standard 9 | - dependency-name: hallmark 10 | - package-ecosystem: github-actions 11 | directory: / 12 | schedule: 13 | interval: monthly 14 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | on: 3 | push: 4 | tags: ['*'] 5 | permissions: 6 | contents: write 7 | jobs: 8 | release: 9 | name: Release 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v4 14 | - name: Create GitHub release 15 | uses: docker://antonyurchenko/git-release:v4 16 | env: 17 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 18 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | on: [push, pull_request] 3 | jobs: 4 | test: 5 | runs-on: ubuntu-latest 6 | strategy: 7 | matrix: 8 | node: [18, 20, 22] 9 | name: Node ${{ matrix.node }} 10 | steps: 11 | - name: Checkout 12 | uses: actions/checkout@v4 13 | - name: Use node ${{ matrix.node }} 14 | uses: actions/setup-node@v4 15 | with: 16 | node-version: ${{ matrix.node }} 17 | - name: Install 18 | run: npm install --ignore-scripts 19 | - name: Install Playwright 20 | if: matrix.node == 22 21 | run: npx playwright install --with-deps 22 | - name: Test 23 | run: npm test 24 | - name: Test browsers 25 | if: matrix.node == 22 26 | run: npm run test-browsers-local 27 | - name: Coverage 28 | run: npm run coverage 29 | - name: Codecov 30 | uses: codecov/codecov-action@v5 31 | with: 32 | files: coverage/lcov.info 33 | token: ${{ secrets.CODECOV_TOKEN }} 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | .nyc_output/ 4 | coverage 5 | db/ 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [10.0.0] - 2025-04-20 4 | 5 | _If you are upgrading: please see [`UPGRADING.md`](UPGRADING.md)._ 6 | 7 | ### Changed 8 | 9 | - **Breaking:** upgrade to abstract-level 3 ([#248](https://github.com/Level/level/issues/248)) ([`b27277c`](https://github.com/Level/level/commit/b27277c)) (Vincent Weevers) 10 | 11 | ## [9.0.0] - 2024-12-01 12 | 13 | _If you are upgrading: please see [`UPGRADING.md`](UPGRADING.md)._ 14 | 15 | ### Changed 16 | 17 | - **Breaking:** upgrade to `abstract-level` 2 ([#247](https://github.com/Level/level/issues/247)) ([`7d8c962`](https://github.com/Level/level/commit/7d8c962)) (Vincent Weevers) 18 | 19 | ## [8.0.1] - 2024-01-27 20 | 21 | ### Fixed 22 | 23 | - Explicitly depend on abstract-level for TypeScript ([#241](https://github.com/Level/level/issues/241)) ([`c501868`](https://github.com/Level/level/commit/c501868)) (Hanxx). 24 | 25 | ## [8.0.0] - 2022-03-25 26 | 27 | _If you are upgrading: please see [`UPGRADING.md`](UPGRADING.md)._ 28 | 29 | ### Changed 30 | 31 | - **Breaking:** switch to `classic-level` and `browser-level` ([#215](https://github.com/Level/level/issues/215)) ([`ad22b21`](https://github.com/Level/level/commit/ad22b21)) (Vincent Weevers). 32 | 33 | ## [7.0.1] - 2021-10-02 34 | 35 | ### Added 36 | 37 | - Document new features ([#207](https://github.com/Level/level/issues/207)) ([`ad8f924`](https://github.com/Level/level/commit/ad8f924)) (Vincent Weevers) 38 | 39 | ### Fixed 40 | 41 | - Bump dependencies to prevent dedupe ([`7083ec6`](https://github.com/Level/level/commit/7083ec6)) (Vincent Weevers) 42 | - Clarify `close()` documentation ([#197](https://github.com/Level/level/issues/197)) ([`c82fdbc`](https://github.com/Level/level/commit/c82fdbc)) (Vincent Weevers) 43 | 44 | ## [7.0.0] - 2021-04-17 45 | 46 | _If you are upgrading: please see [`UPGRADING.md`](UPGRADING.md)._ 47 | 48 | ### Changed 49 | 50 | - **Breaking:** bump `leveldown` and `level-packager` ([`53bd922`](https://github.com/Level/level/commit/53bd922)) (Vincent Weevers) 51 | - **Breaking:** bump `level-js` from 5.x to 6.x ([#194](https://github.com/Level/level/issues/194)) ([`1f6c603`](https://github.com/Level/level/commit/1f6c603)) (Alex Potsides) 52 | - **Breaking:** modernize syntax ([Level/community#98](https://github.com/Level/community/issues/98)) ([`d001b2c`](https://github.com/Level/level/commit/d001b2c)) (Vincent Weevers) 53 | - Add `files` to `package.json` and remove `.npmignore` ([`329e1f5`](https://github.com/Level/level/commit/329e1f5)) (Vincent Weevers) 54 | 55 | ### Added 56 | 57 | - Document chained batch encoding options ([Level/levelup#633](https://github.com/Level/levelup/issues/633)) ([`0b3c11d`](https://github.com/Level/level/commit/0b3c11d)) (Vincent Weevers) 58 | - Document the `clear` event ([Level/community#79](https://github.com/Level/community/issues/79)) ([`52314bf`](https://github.com/Level/level/commit/52314bf)) (Vincent Weevers) 59 | 60 | ### Removed 61 | 62 | - **Breaking:** drop node 8 ([Level/community#98](https://github.com/Level/community/issues/98)) ([`f8a0047`](https://github.com/Level/level/commit/f8a0047), [`31317a6`](https://github.com/Level/level/commit/31317a6)) (Vincent Weevers) 63 | - Remove legacy range options from README ([Level/community#86](https://github.com/Level/community/issues/86)) ([`e56c6b1`](https://github.com/Level/level/commit/e56c6b1)) (Vincent Weevers) 64 | 65 | ## [6.0.1] - 2020-03-04 66 | 67 | ### Changed 68 | 69 | - Switch from `opencollective-postinstall` to npm `funding` ([#173](https://github.com/Level/level/issues/173)) ([**@Richienb**](https://github.com/Richienb)) 70 | - Upgrade `nyc` devDependency from `^14.0.0` to `^15.0.0` ([#169](https://github.com/Level/level/issues/169)) ([**@vweevers**](https://github.com/vweevers)) 71 | - Upgrade `airtap` devDependency from `^2.0.1` to `^3.0.0` ([#171](https://github.com/Level/level/issues/171)) ([**@vweevers**](https://github.com/vweevers)) 72 | 73 | ## [6.0.0] - 2019-10-19 74 | 75 | _If you are upgrading: please see [`UPGRADING.md`](UPGRADING.md)._ 76 | 77 | ### Changed 78 | 79 | - **Breaking:** upgrade `level-js` from `^4.0.0` to `^5.0.0` ([#158](https://github.com/Level/level/issues/158)) ([**@vweevers**](https://github.com/vweevers)) 80 | - Upgrade `hallmark` devDependency from `^0.1.0` to `^2.0.0` ([#152](https://github.com/Level/level/issues/152), [#157](https://github.com/Level/level/issues/157)) ([**@vweevers**](https://github.com/vweevers)) 81 | - Upgrade `standard` devDependency from `^12.0.0` to `^14.0.0` ([#151](https://github.com/Level/level/issues/151), [#155](https://github.com/Level/level/issues/155)) ([**@vweevers**](https://github.com/vweevers)) 82 | - Upgrade `nyc` devDependency from `^13.2.0` to `^14.0.0` ([#147](https://github.com/Level/level/issues/147)) ([**@vweevers**](https://github.com/vweevers)) 83 | 84 | ### Added 85 | 86 | - Document manifest, `iterator()` and `clear()` ([#162](https://github.com/Level/level/issues/162)) ([**@vweevers**](https://github.com/vweevers)) 87 | - Add links to `browserify-starter` and `webpack-starter` ([`6ff1802`](https://github.com/Level/level/commit/6ff1802)) ([**@vweevers**](https://github.com/vweevers)) 88 | 89 | ### Fixed 90 | 91 | - Bump `leveldown` and `level-packager` to prevent dedupe ([`5efdc82`](https://github.com/Level/level/commit/5efdc82), [`a9656c3`](https://github.com/Level/level/commit/a9656c3), [`97cb31c`](https://github.com/Level/level/commit/97cb31c)) ([**@vweevers**](https://github.com/vweevers)) 92 | 93 | ## [5.0.1] - 2019-03-29 94 | 95 | ### Fixed 96 | 97 | - Temporarily skip `hallmark` test because it breaks CITGM ([#145](https://github.com/Level/level/issues/145)) ([**@vweevers**](https://github.com/vweevers)) 98 | 99 | ## [5.0.0] - 2019-03-29 100 | 101 | _If you are upgrading: please see [`UPGRADING.md`](UPGRADING.md)._ 102 | 103 | ### Changed 104 | 105 | - Upgrade `leveldown` from `^4.0.0` to `^5.0.0` ([#133](https://github.com/Level/level/issues/133), [#144](https://github.com/Level/level/issues/144)) ([**@vweevers**](https://github.com/vweevers)) 106 | - Upgrade `level-packager` from `^3.0.0` to `^5.0.0` ([#113](https://github.com/Level/level/issues/113), [#131](https://github.com/Level/level/issues/131)) ([**@ralphtheninja**](https://github.com/ralphtheninja), [**@vweevers**](https://github.com/vweevers)) 107 | - Prefer `var` over `const` in README ([`f032b6c`](https://github.com/Level/level/commit/f032b6c)) ([**@ralphtheninja**](https://github.com/ralphtheninja)) 108 | - Upgrade `standard` devDependency from `^11.0.0` to `^12.0.0` ([#118](https://github.com/Level/level/issues/118)) ([**@ralphtheninja**](https://github.com/ralphtheninja)) 109 | - Tweak copyright years for less maintenance ([`0b9c8ad`](https://github.com/Level/level/commit/0b9c8ad)) ([**@ralphtheninja**](https://github.com/ralphtheninja)) 110 | - Tweak Open Collective documentation ([#137](https://github.com/Level/level/issues/137)) ([**@vweevers**](https://github.com/vweevers)) 111 | - Apply common project tweaks ([#136](https://github.com/Level/level/issues/136), [#138](https://github.com/Level/level/issues/138)) ([**@vweevers**](https://github.com/vweevers)) 112 | - Add `.travis.yml` and `appveyor.yml` to `.npmignore` ([`7b5c340`](https://github.com/Level/level/commit/7b5c340)) ([**@vweevers**](https://github.com/vweevers)) 113 | 114 | ### Added 115 | 116 | - Integrate `level-js` for browser support ([#135](https://github.com/Level/level/issues/135)) ([**@vweevers**](https://github.com/vweevers)) 117 | - Add appveyor ([#112](https://github.com/Level/level/issues/112)) ([**@ralphtheninja**](https://github.com/ralphtheninja)) 118 | - Enable OSX on Travis ([#111](https://github.com/Level/level/issues/111)) ([**@ralphtheninja**](https://github.com/ralphtheninja)) 119 | - Add `nyc` and `coveralls` devDependencies ([#115](https://github.com/Level/level/issues/115), [#143](https://github.com/Level/level/issues/143)) ([**@ralphtheninja**](https://github.com/ralphtheninja), [**@vweevers**](https://github.com/vweevers)) 120 | - Add `hallmark` devDependency ([#134](https://github.com/Level/level/issues/134)) ([**@vweevers**](https://github.com/vweevers)) 121 | - Add note about Rollup to `README.md` ([#139](https://github.com/Level/level/issues/139)) ([**@vweevers**](https://github.com/vweevers)) 122 | 123 | ### Removed 124 | 125 | - Remove node 6 and 9 ([#129](https://github.com/Level/level/issues/129), [`2bf1d3f`](https://github.com/Level/level/commit/2bf1d3f)) ([**@ralphtheninja**](https://github.com/ralphtheninja)) 126 | - Remove contributors from `package.json` ([`f37252d`](https://github.com/Level/level/commit/f37252d)) ([**@ralphtheninja**](https://github.com/ralphtheninja)) 127 | 128 | ## [4.0.0] - 2018-05-23 129 | 130 | _If you are upgrading: please see [`UPGRADING.md`](UPGRADING.md)._ 131 | 132 | ### Changed 133 | 134 | - Update `leveldown` to `^4.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 135 | - Update `level-packager` to `^3.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 136 | - Switch to `opencollective-postinstall` ([**@mateodelnorte**](https://github.com/mateodelnorte)) 137 | 138 | ### Removed 139 | 140 | - Remove node 4 from Travis ([**@ralphtheninja**](https://github.com/ralphtheninja)) 141 | 142 | ## [3.0.2] - 2018-05-23 143 | 144 | ### Changed 145 | 146 | - Switch to `opencollective-postinstall` ([**@mateodelnorte**](https://github.com/mateodelnorte)) 147 | 148 | ## [3.0.1] - 2018-05-05 149 | 150 | ### Added 151 | 152 | - Travis: add 10 ([**@ralphtheninja**](https://github.com/ralphtheninja)) 153 | 154 | ### Changed 155 | 156 | - Update `standard` to `^11.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 157 | - Fix typo in README ([**@rasmuserik**](https://github.com/rasmuserik)) 158 | 159 | ### Fixed 160 | 161 | - Fix postinstall failures with OpenCollective ([**@vweevers**](https://github.com/vweevers)) 162 | 163 | ## [3.0.0] - 2018-02-17 164 | 165 | _If you are upgrading: please see [`UPGRADING.md`](UPGRADING.md)._ 166 | 167 | ### Added 168 | 169 | - Travis: add 9 ([**@ralphtheninja**](https://github.com/ralphtheninja)) 170 | - README: add table of contents ([**@ralphtheninja**](https://github.com/ralphtheninja)) 171 | 172 | ### Changed 173 | 174 | - Update `leveldown` to `^3.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 175 | 176 | ## [2.1.2] - 2018-01-26 177 | 178 | ### Added 179 | 180 | - Add OpenCollective ([**@monkeywithacupcake**](https://github.com/monkeywithacupcake)) 181 | 182 | ### Changed 183 | 184 | - README: change Travis badge from png to svg ([**@ralphtheninja**](https://github.com/ralphtheninja)) 185 | 186 | ## [2.1.1] - 2017-12-13 187 | 188 | ### Changed 189 | 190 | - README: document `.errors` property ([**@ralphtheninja**](https://github.com/ralphtheninja)) 191 | 192 | ## [2.1.0] - 2017-12-06 193 | 194 | ### Changed 195 | 196 | - Update `level-packager` to `^2.0.2` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 197 | - Update `leveldown` to `^2.1.1` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 198 | 199 | ## [2.0.1] - 2017-11-11 200 | 201 | ### Changed 202 | 203 | - Restore node 4 ([**@vweevers**](https://github.com/vweevers)) 204 | 205 | ## [2.0.0] - 2017-10-17 206 | 207 | _If you are upgrading: please see [`UPGRADING.md`](UPGRADING.md)._ 208 | 209 | ### Added 210 | 211 | - Add `standard` for linting ([**@ralphtheninja**](https://github.com/ralphtheninja)) 212 | - README: copy over docs from `levelup` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 213 | - README: add node badge ([**@ralphtheninja**](https://github.com/ralphtheninja)) 214 | 215 | ### Changed 216 | 217 | - Update `level-packager` to `~2.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 218 | - Update `leveldown` to `~2.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 219 | 220 | ## [2.0.0-rc3] - 2017-09-16 221 | 222 | ### Changed 223 | 224 | - Update `level-packager` to `2.0.0-rc3` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 225 | - Update `leveldown` to `~1.8.0` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 226 | 227 | ## [2.0.0-rc2] - 2017-09-12 228 | 229 | ### Changed 230 | 231 | - Update `level-packager` to `2.0.0-rc2` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 232 | - Update `leveldown` to `~1.7.2` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 233 | 234 | ## [2.0.0-rc1] - 2017-09-06 235 | 236 | ### Added 237 | 238 | - README: add Greenkeeper badge ([**@ralphtheninja**](https://github.com/ralphtheninja)) 239 | - Travis: add 8 ([**@ralphtheninja**](https://github.com/ralphtheninja)) 240 | 241 | ### Changed 242 | 243 | - Update `level-packager` to `2.0.0-rc1` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 244 | 245 | ### Removed 246 | 247 | - Travis: remove 0.12, 4, 5, and 7 ([**@ralphtheninja**](https://github.com/ralphtheninja)) 248 | 249 | ## [1.7.0] - 2017-05-17 250 | 251 | ### Changed 252 | 253 | - Update `leveldown` to `~1.7.0` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 254 | 255 | ## [1.6.0] - 2017-02-06 256 | 257 | ### Added 258 | 259 | - Travis: add 7 ([**@ralphtheninja**](https://github.com/ralphtheninja)) 260 | 261 | ### Changed 262 | 263 | - Update copyright year to 2017 ([**@ralphtheninja**](https://github.com/ralphtheninja)) 264 | - Update `leveldown` to `~1.6.0` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 265 | 266 | ### Removed 267 | 268 | - Travis: remove 0.10 ([**@ralphtheninja**](https://github.com/ralphtheninja)) 269 | 270 | ## [1.5.0] - 2016-10-16 271 | 272 | ### Added 273 | 274 | - Travis: add 6 ([**@ralphtheninja**](https://github.com/ralphtheninja)) 275 | 276 | ### Changed 277 | 278 | - Use gcc 4.8 on Travis 279 | - Update `leveldown` to `~1.5.0` ([**@juliangruber**](https://github.com/juliangruber)) 280 | 281 | ### Removed 282 | 283 | - Travis: remove 1.0, 1.8, 2 and 3 ([**@ralphtheninja**](https://github.com/ralphtheninja)) 284 | 285 | ## [1.4.0] - 2015-11-27 286 | 287 | ### Added 288 | 289 | - Travis: add 1.0, 2, 3, 4 and 5 ([**@ralphtheninja**](https://github.com/ralphtheninja)) 290 | - README: add dependency badge ([**@ralphtheninja**](https://github.com/ralphtheninja)) 291 | 292 | ### Changed 293 | 294 | - Update `level-packager` to `~1.2.0` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 295 | 296 | ## [1.3.0] - 2015-07-29 297 | 298 | ### Changed 299 | 300 | - Update `leveldown` to `~1.4.0` ([**@ArtskydJ**](https://github.com/ArtskydJ)) 301 | 302 | ## [1.2.0] - 2015-06-24 303 | 304 | ### Changed 305 | 306 | - Update `level-packager` to `~1.1.0` ([**@timoxley**](https://github.com/timoxley)) 307 | - Update `leveldown` to `~1.3.0` ([**@timoxley**](https://github.com/timoxley)) 308 | 309 | ## [1.1.0] - 2015-06-02 310 | 311 | ### Changed 312 | 313 | - Update `leveldown` to `~1.2.2` for prebuilt binaries ([**@ralphtheninja**](https://github.com/ralphtheninja)) 314 | 315 | ## [1.0.0] - 2015-05-19 316 | 317 | ### Changed 318 | 319 | - Update `level-packager` to `~1.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 320 | 321 | ## [1.0.0-0] - 2015-05-16 322 | 323 | ### Changed 324 | 325 | - Use `nvm` again on Travis ([**@ralphtheninja**](https://github.com/ralphtheninja)) 326 | - Moved `CONTRIBUTING.md` and contributors to `level/community` repository ([**@ralphtheninja**](https://github.com/ralphtheninja)) 327 | - Use `level-packager@next` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 328 | - Update `leveldown` to `~1.0.6` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 329 | 330 | ## [0.19.1] - 2015-05-05 331 | 332 | ### Changed 333 | 334 | - Use `n` instead of `nvm` on Travis for iojs support on native modules ([**@ralphtheninja**](https://github.com/ralphtheninja)) 335 | 336 | ## [0.19.0] - 2015-05-05 337 | 338 | ### Changed 339 | 340 | - Switch to plain MIT license ([**@andrewrk**](https://github.com/andrewrk)) 341 | - README: update nodeico badge ([**@rvagg**](https://github.com/rvagg)) 342 | - README: update logo and copyright ([**@ralphtheninja**](https://github.com/ralphtheninja)) 343 | - Update `level-packager` to `~0.19.0` ([**@ralphtheninja**](https://github.com/ralphtheninja)) 344 | 345 | ## [0.18.0] - 2013-11-18 346 | 347 | ### Added 348 | 349 | - Add Travis ([**@rvagg**](https://github.com/rvagg)) 350 | 351 | ### Changed 352 | 353 | - Update `level-packager` to `~0.18.0` ([**@rvagg**](https://github.com/rvagg)) 354 | - Update `leveldown` to `~0.10.0` ([**@rvagg**](https://github.com/rvagg)) 355 | 356 | ## [0.17.0] - 2013-10-01 357 | 358 | _0.17.0 and 0.17.0-1 are listed out of order here, due to 0.17.0-1 not adhering to the semver rules that we follow today._ 359 | 360 | ### Changed 361 | 362 | - Update `levelup` to `~0.17.0` ([**@rvagg**](https://github.com/rvagg)) 363 | - Update `leveldown` to `~0.9.0` ([**@rvagg**](https://github.com/rvagg)) 364 | 365 | ## [0.17.0-1] - 2013-10-09 366 | 367 | ### Changed 368 | 369 | - Use `level-packager` instead of `levelup` ([**@rvagg**](https://github.com/rvagg)) 370 | - Run tests in `level-packager` using `tape` ([**@rvagg**](https://github.com/rvagg)) 371 | 372 | ## [0.16.0] - 2013-09-10 373 | 374 | ### Added 375 | 376 | - Add [**@substack**](https://github.com/substack) to contributors ([**@rvagg**](https://github.com/rvagg)) 377 | 378 | ### Changed 379 | 380 | - Update `levelup` to `~0.16.0` ([**@rvagg**](https://github.com/rvagg)) 381 | - Update repository and homepage in `package.json` ([**@rvagg**](https://github.com/rvagg)) 382 | 383 | ## [0.15.0] - 2013-08-26 384 | 385 | ### Changed 386 | 387 | - README: tweaks ([**@rvagg**](https://github.com/rvagg)) 388 | - Update `levelup` to `~0.15.0` ([**@rvagg**](https://github.com/rvagg)) 389 | - Update `leveldown` to `~0.8.0` ([**@rvagg**](https://github.com/rvagg)) 390 | 391 | ## [0.14.0] - 2013-08-19 392 | 393 | ### Added 394 | 395 | - README: add npm downloads badge ([**@rvagg**](https://github.com/rvagg)) 396 | 397 | ### Changed 398 | 399 | - Update `levelup` to `~0.14.0` ([**@rvagg**](https://github.com/rvagg)) 400 | 401 | ## [0.13.0] - 2013-08-11 402 | 403 | ### Changed 404 | 405 | - Update `levelup` to `~0.13.0` ([**@rvagg**](https://github.com/rvagg)) 406 | - Update `leveldown` to `~0.7.0` ([**@rvagg**](https://github.com/rvagg)) 407 | 408 | ## [0.12.0] - 2013-07-25 409 | 410 | ### Changed 411 | 412 | - Update `levelup` to `~0.12.0` ([**@rvagg**](https://github.com/rvagg)) 413 | - Update `leveldown` to `~0.6.2` ([**@rvagg**](https://github.com/rvagg)) 414 | 415 | ## [0.11.0] - 2013-07-17 416 | 417 | ### Added 418 | 419 | - Add [**@pgte**](https://github.com/pgte) to contributors ([**@rvagg**](https://github.com/rvagg)) 420 | - README: add npm badge ([**@rvagg**](https://github.com/rvagg)) 421 | 422 | ### Changed 423 | 424 | - Update `levelup` to `~0.11.0` ([**@rvagg**](https://github.com/rvagg)) 425 | 426 | ## [0.10.0] - 2013-06-14 427 | 428 | ### Changed 429 | 430 | - Update `levelup` to `~0.10.0` ([**@rvagg**](https://github.com/rvagg)) 431 | - Update `leveldown` to `~0.6.0` ([**@rvagg**](https://github.com/rvagg)) 432 | 433 | ## [0.9.0] - 2013-05-27 434 | 435 | ### Changed 436 | 437 | - Update `levelup` to `~0.9.0` ([**@rvagg**](https://github.com/rvagg)) 438 | - Update `leveldown` to `~0.5.0` ([**@rvagg**](https://github.com/rvagg)) 439 | 440 | ## [0.8.0] - 2013-05-19 441 | 442 | :seedling: Initial release. 443 | 444 | [10.0.0]: https://github.com/Level/level/releases/tag/v10.0.0 445 | 446 | [9.0.0]: https://github.com/Level/level/releases/tag/v9.0.0 447 | 448 | [8.0.1]: https://github.com/Level/level/releases/tag/v8.0.1 449 | 450 | [8.0.0]: https://github.com/Level/level/releases/tag/v8.0.0 451 | 452 | [7.0.1]: https://github.com/Level/level/releases/tag/v7.0.1 453 | 454 | [7.0.0]: https://github.com/Level/level/releases/tag/v7.0.0 455 | 456 | [6.0.1]: https://github.com/Level/level/releases/tag/v6.0.1 457 | 458 | [6.0.0]: https://github.com/Level/level/releases/tag/v6.0.0 459 | 460 | [5.0.1]: https://github.com/Level/level/releases/tag/v5.0.1 461 | 462 | [5.0.0]: https://github.com/Level/level/releases/tag/v5.0.0 463 | 464 | [4.0.0]: https://github.com/Level/level/releases/tag/v4.0.0 465 | 466 | [3.0.2]: https://github.com/Level/level/releases/tag/v3.0.2 467 | 468 | [3.0.1]: https://github.com/Level/level/releases/tag/v3.0.1 469 | 470 | [3.0.0]: https://github.com/Level/level/releases/tag/v3.0.0 471 | 472 | [2.1.2]: https://github.com/Level/level/releases/tag/v2.1.2 473 | 474 | [2.1.1]: https://github.com/Level/level/releases/tag/v2.1.1 475 | 476 | [2.1.0]: https://github.com/Level/level/releases/tag/v2.1.0 477 | 478 | [2.0.1]: https://github.com/Level/level/releases/tag/v2.0.1 479 | 480 | [2.0.0]: https://github.com/Level/level/releases/tag/v2.0.0 481 | 482 | [2.0.0-rc3]: https://github.com/Level/level/releases/tag/v2.0.0-rc3 483 | 484 | [2.0.0-rc2]: https://github.com/Level/level/releases/tag/v2.0.0-rc2 485 | 486 | [2.0.0-rc1]: https://github.com/Level/level/releases/tag/v2.0.0-rc1 487 | 488 | [1.7.0]: https://github.com/Level/level/releases/tag/v1.7.0 489 | 490 | [1.6.0]: https://github.com/Level/level/releases/tag/v1.6.0 491 | 492 | [1.5.0]: https://github.com/Level/level/releases/tag/v1.5.0 493 | 494 | [1.4.0]: https://github.com/Level/level/releases/tag/v1.4.0 495 | 496 | [1.3.0]: https://github.com/Level/level/releases/tag/v1.3.0 497 | 498 | [1.2.0]: https://github.com/Level/level/releases/tag/v1.2.0 499 | 500 | [1.1.0]: https://github.com/Level/level/releases/tag/v1.1.0 501 | 502 | [1.0.0]: https://github.com/Level/level/releases/tag/v1.0.0 503 | 504 | [1.0.0-0]: https://github.com/Level/level/releases/tag/v1.0.0-0 505 | 506 | [0.19.1]: https://github.com/Level/level/releases/tag/v0.19.1 507 | 508 | [0.19.0]: https://github.com/Level/level/releases/tag/v0.19.0 509 | 510 | [0.18.0]: https://github.com/Level/level/releases/tag/0.18.0 511 | 512 | [0.17.0]: https://github.com/Level/level/releases/tag/0.17.0 513 | 514 | [0.17.0-1]: https://github.com/Level/level/releases/tag/0.17.0-1 515 | 516 | [0.16.0]: https://github.com/Level/level/releases/tag/0.16.0 517 | 518 | [0.15.0]: https://github.com/Level/level/releases/tag/0.15.0 519 | 520 | [0.14.0]: https://github.com/Level/level/releases/tag/0.14.0 521 | 522 | [0.13.0]: https://github.com/Level/level/releases/tag/0.13.0 523 | 524 | [0.12.0]: https://github.com/Level/level/releases/tag/0.12.0 525 | 526 | [0.11.0]: https://github.com/Level/level/releases/tag/0.11.0 527 | 528 | [0.10.0]: https://github.com/Level/level/releases/tag/0.10.0 529 | 530 | [0.9.0]: https://github.com/Level/level/releases/tag/0.9.0 531 | 532 | [0.8.0]: https://github.com/Level/level/releases/tag/0.8.0 533 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2013 Rod Vagg and the contributors to level. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # level 2 | 3 | **Universal [`abstract-level`](https://github.com/Level/abstract-level) database for Node.js and browsers.** This is a convenience package that exports [`classic-level`](https://github.com/Level/classic-level) in Node.js and [`browser-level`](https://github.com/Level/browser-level) in browsers, making it an ideal entry point to start creating lexicographically sorted key-value databases. 4 | 5 | > :pushpin: Which module should I use? What is `abstract-level`? Head over to the [FAQ](https://github.com/Level/community#faq). 6 | 7 | [![level badge][level-badge]](https://github.com/Level/awesome) 8 | [![npm](https://img.shields.io/npm/v/level.svg)](https://www.npmjs.com/package/level) 9 | [![Node version](https://img.shields.io/node/v/level.svg)](https://www.npmjs.com/package/level) 10 | [![Test](https://img.shields.io/github/actions/workflow/status/Level/level/test.yml?branch=master&label=test)](https://github.com/Level/level/actions/workflows/test.yml) 11 | [![Coverage](https://img.shields.io/codecov/c/github/Level/level?label=\&logo=codecov\&logoColor=fff)](https://codecov.io/gh/Level/level) 12 | [![Standard](https://img.shields.io/badge/standard-informational?logo=javascript\&logoColor=fff)](https://standardjs.com) 13 | [![Common Changelog](https://common-changelog.org/badge.svg)](https://common-changelog.org) 14 | [![Community](https://img.shields.io/badge/community-join-%2370B99E?logo=github)](https://github.com/Level/community/issues) 15 | [![Donate](https://img.shields.io/badge/donate-orange?logo=open-collective\&logoColor=fff)](https://opencollective.com/level) 16 | 17 | ## Usage 18 | 19 | _If you are upgrading: please see [`UPGRADING.md`](UPGRADING.md)._ 20 | 21 | ```js 22 | const { Level } = require('level') 23 | 24 | // Create a database 25 | const db = new Level('example', { valueEncoding: 'json' }) 26 | 27 | // Add an entry with key 'a' and value 1 28 | await db.put('a', 1) 29 | 30 | // Add multiple entries 31 | await db.batch([{ type: 'put', key: 'b', value: 2 }]) 32 | 33 | // Get value of key 'a': 1 34 | const value = await db.get('a') 35 | 36 | // Iterate entries with keys that are greater than 'a' 37 | for await (const [key, value] of db.iterator({ gt: 'a' })) { 38 | console.log(value) // 2 39 | } 40 | ``` 41 | 42 | TypeScript type declarations are included and cover the methods that are common between `classic-level` and `browser-level`. Usage from TypeScript requires generic type parameters. 43 | 44 |
TypeScript example 45 | 46 | ```ts 47 | // Specify types of keys and values (any, in the case of json). 48 | // The generic type parameters default to Level. 49 | const db = new Level('./db', { valueEncoding: 'json' }) 50 | 51 | // All relevant methods then use those types 52 | await db.put('a', { x: 123 }) 53 | 54 | // Specify different types when overriding encoding per operation 55 | await db.get('a', { valueEncoding: 'utf8' }) 56 | 57 | // Though in some cases TypeScript can infer them 58 | await db.get('a', { valueEncoding: db.valueEncoding('utf8') }) 59 | 60 | // It works the same for sublevels 61 | const abc = db.sublevel('abc') 62 | const xyz = db.sublevel('xyz', { valueEncoding: 'json' }) 63 | ``` 64 | 65 |
66 | 67 | ## Install 68 | 69 | With [npm](https://npmjs.org) do: 70 | 71 | ```bash 72 | npm install level 73 | ``` 74 | 75 | For use in browsers, this package is best used with [`browserify`](https://github.com/browserify/browserify), [`webpack`](https://webpack.js.org/), [`rollup`](https://rollupjs.org/) or similar bundlers. For a quick start, visit [`browserify-starter`](https://github.com/Level/browserify-starter) or [`webpack-starter`](https://github.com/Level/webpack-starter). 76 | 77 | ## Supported Platforms 78 | 79 | At the time of writing, `level` works in Node.js 18+ and Electron 30+ on Linux, Mac OS and Windows, including any future Node.js and Electron release thanks to [Node-API](https://nodejs.org/api/n-api.html), including ARM platforms like Raspberry Pi and Android, as well as in Chromium, Firefox and Safari. For details, see [Supported Platforms](https://github.com/Level/classic-level#supported-platforms) of `classic-level` and [Browser Support](https://github.com/Level/browser-level#browser-support) of `browser-level`. 80 | 81 | Binary keys and values are supported across the board. 82 | 83 | ## API 84 | 85 | The API of `level` follows that of [`abstract-level`](https://github.com/Level/abstract-level). For additional options and methods specific to [`classic-level`](https://github.com/Level/classic-level) or [`browser-level`](https://github.com/Level/browser-level), please see their respective READMEs. The documentation below only covers the common constructor. 86 | 87 | ### `db = new Level(location[, options])` 88 | 89 | Create a new database or open an existing database. The `location` argument must be a directory path (relative or absolute) where LevelDB will store its files, or in browsers, the name of the [`IDBDatabase`](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase) to be opened. 90 | 91 | ## Contributing 92 | 93 | [`Level/level`](https://github.com/Level/level) is an **OPEN Open Source Project**. This means that: 94 | 95 | > Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project. 96 | 97 | See the [Contribution Guide](https://github.com/Level/community/blob/master/CONTRIBUTING.md) for more details. 98 | 99 | ## Donate 100 | 101 | Support us with a monthly donation on [Open Collective](https://opencollective.com/level) and help us continue our work. 102 | 103 | ## License 104 | 105 | [MIT](LICENSE) 106 | 107 | [level-badge]: https://leveljs.org/img/badge.svg 108 | -------------------------------------------------------------------------------- /UPGRADING.md: -------------------------------------------------------------------------------- 1 | # Upgrade Guide 2 | 3 | This document describes breaking changes and how to upgrade. For a complete list of changes including minor and patch releases, please refer to the [changelog](CHANGELOG.md). 4 | 5 | ## 10.0.0 6 | 7 | This release upgrades to `abstract-level` 3. Please see its [upgrade guide](https://github.com/Level/abstract-level/blob/v3.0.0/UPGRADING.md). 8 | 9 | Not mentioned in that guide is the later addition of `db.getSync()`. This new method blocks the event loop but can be significantly faster than `db.get()`: 10 | 11 | ```js 12 | const value = db.getSync('example') 13 | ``` 14 | 15 | It is only supported in Node.js (via `classic-level`) and not in browsers. 16 | 17 | ## 9.0.0 18 | 19 | This release upgrades to `abstract-level` 2.0.0 which adds [hooks](https://github.com/Level/abstract-level#hooks) and drops callbacks and not-found errors. Please refer to the [upgrade guide of `abstract-level`](https://github.com/Level/abstract-level/blob/v2.0.0/UPGRADING.md) for details. The only thing to add is that this release ends support of Node.js < 18 and Electron < 30. 20 | 21 | ## 8.0.0 22 | 23 | **This release replaces `leveldown` and `level-js` with [`classic-level`](https://github.com/Level/classic-level) and [`browser-level`](https://github.com/Level/browser-level). These modules implement the [`abstract-level`](https://github.com/Level/abstract-level) interface instead of [`abstract-leveldown`](https://github.com/Level/abstract-leveldown). This gives them the same API as `level@7` without having to be wrapped with [`levelup`](https://github.com/Level/levelup) or [`encoding-down`](https://github.com/Level/encoding-down). In addition, you can now choose to use Uint8Array instead of Buffer. Sublevels are built-in.** 24 | 25 | We've put together several upgrade guides for different modules. See the [FAQ](https://github.com/Level/community#faq) to find the best upgrade guide for you. This one describes how to upgrade `level`. 26 | 27 | Support of Node.js 10 has been dropped. 28 | 29 | ### Changes to initialization 30 | 31 | We started using classes, which means using `new` is now required. If you previously did: 32 | 33 | ```js 34 | const level = require('level') 35 | const db = level('db') 36 | ``` 37 | 38 | You must now do: 39 | 40 | ```js 41 | const { Level } = require('level') 42 | const db = new Level('db') 43 | ``` 44 | 45 | ### TypeScript makes a win 46 | 47 | TypeScript type declarations are now included in the npm package(s). For `level` it's an intersection of `classic-level` and `browser-level` types that includes their options but excludes methods like `compactRange()` that can only be found in either. JavaScript folks using VSCode will also benefit from the new types because they enable auto-completion and now include documentation. 48 | 49 | ### Waking up from limbo 50 | 51 | Deferred open - meaning that a database opens itself and any operations made in the mean time are queued up in memory - remains built-in. A new behavior is that those operations will yield errors if opening failed. They'd previously end up in limbo. 52 | 53 | An `abstract-level` and thus `level` database is not "patch-safe". If some form of plugin monkey-patches a database method, it must now also take the responsibility of deferring the operation (as well as handling promises and callbacks) using [`db.defer()`](https://github.com/Level/abstract-level#dbdeferfn). 54 | 55 | ### Creating the location recursively 56 | 57 | To align behavior between platforms, `classic-level` and therefore `level@8` creates the location directory recursively. While `leveldown` and therefore `level@7` would only do so on Windows. In the following example, the `foo` directory does not have to exist beforehand: 58 | 59 | ```js 60 | const db = new Level('foo/bar') 61 | ``` 62 | 63 | This new behavior may break expectations, given typical filesystem behavior, or it could be a convenient feature, if the database is considered to abstract away the filesystem. We're [collecting feedback](https://github.com/Level/classic-level/issues/7) to determine what to do in a next (major) version. Your vote is most welcome! 64 | 65 | ### No constructor callback 66 | 67 | The database constructor no longer takes a callback argument. Instead call `db.open()` if you wish to wait for opening (which is not necessary to use the database) or to capture an error. If that's your reason for using the callback and you previously initialized a database like so: 68 | 69 | ```js 70 | level('fruits', function (err, db) { 71 | // .. 72 | }) 73 | ``` 74 | 75 | You must now do one of: 76 | 77 | ```js 78 | db.open(callback) 79 | await db.open() 80 | ``` 81 | 82 | ### There is only encodings 83 | 84 | Encodings have a new home in `abstract-level` and are now powered by [`level-transcoder`](https://github.com/Level/transcoder). The main change is that logic from the existing public API has been expanded down into the storage layer. There are however a few differences from `level@7`. Some breaking: 85 | 86 | - The lesser-used `'id'`, `'ascii'`, `'ucs2'` and `'utf16le'` encodings are not supported 87 | - The undocumented `encoding` option (as an alias for `valueEncoding`) is not supported. 88 | 89 | And some non-breaking: 90 | 91 | - The `'binary'` encoding has been renamed to `'buffer'`, with `'binary'` as an alias 92 | - The `'utf8'` encoding previously did not touch Buffers. Now it will call `buffer.toString('utf8')` for consistency. Consumers can use the `'buffer'` encoding to avoid this conversion. 93 | 94 | Both `classic-level` and `browser-level` support Uint8Array data, in addition to Buffer. It's a separate encoding called `'view'` that can be used interchangeably: 95 | 96 | ```js 97 | const db = new Level('people', { valueEncoding: 'view' }) 98 | 99 | await db.put('elena', new Uint8Array([97, 98, 99])) 100 | await db.get('elena') // Uint8Array 101 | await db.get('elena', { valueEncoding: 'utf8' }) // 'abc' 102 | await db.get('elena', { valueEncoding: 'buffer' }) // Buffer 103 | ``` 104 | 105 | For browsers you can choose to use Uint8Array exclusively and omit the [`buffer`](https://github.com/feross/buffer) shim from your JavaScript bundle (through configuration of Webpack, Browserify or other). 106 | 107 | ### Streams have moved 108 | 109 | Node.js readable streams must now be created with a new standalone module called [`level-read-stream`](https://github.com/Level/read-stream) rather than database methods like `db.createReadStream()`. For browsers you might prefer [`level-web-stream`](https://github.com/Level/web-stream) which does not require bundling the [`buffer`](https://github.com/feross/buffer) or [`readable-stream`](https://github.com/nodejs/readable-stream) shims. Both `level-read-stream` and `level-web-stream` can be used in Node.js and browsers. The former is significantly faster (also compared to `level@7`, thanks to a new `nextv()` method on iterators). The latter is a step towards a standard library for JavaScript across Node.js, Deno and browsers. 110 | 111 | To offer an alternative to `db.createKeyStream()` and `db.createValueStream()`, two new types of iterators have been added: `db.keys()` and `db.values()`. 112 | 113 | ### State checks for safety 114 | 115 | On any operation, an `abstract-level` and thus `level` database checks if it's open. If not, it will either throw an error (if the relevant API is synchronous) or asynchronously yield an error. For example: 116 | 117 | ```js 118 | await db.close() 119 | 120 | try { 121 | db.iterator() 122 | } catch (err) { 123 | console.log(err.code) // LEVEL_DATABASE_NOT_OPEN 124 | } 125 | ``` 126 | 127 | _Errors now have a `code` property. More on that below\._ 128 | 129 | ### Zero-length keys and range options are now valid 130 | 131 | These keys sort before anything else. Historically they weren't supported for causing segmentation faults in `leveldown`. That doesn't apply to today's codebase. You can now do: 132 | 133 | ```js 134 | await db.put('', 'abc') 135 | 136 | console.log(await db.get('')) // 'abc' 137 | console.log(await db.get(new Uint8Array(0), { keyEncoding: 'view' })) // 'abc' 138 | 139 | for await (const [key, value] of db.iterator({ lte: '' })) { 140 | console.log(value) // 'abc' 141 | } 142 | ``` 143 | 144 | ### It doesn't end there 145 | 146 | The `iterator.end()` method has been renamed to `iterator.close()`, with `end()` being an alias until a next major version. The term "close" makes it easier to differentiate between the iterator having reached its natural end (data-wise) versus closing it to cleanup resources. If you previously did: 147 | 148 | ```js 149 | const iterator = db.iterator() 150 | iterator.end(callback) 151 | ``` 152 | 153 | You should now do one of: 154 | 155 | ```js 156 | iterator.close(callback) 157 | await iterator.close() 158 | ``` 159 | 160 | On `db.close()`, non-closed iterators are now automatically closed (only for safety reasons). If a call like `next()` is in progress, closing the iterator or database will wait for that. Calling `iterator.close()` more than once is now allowed and makes no difference. 161 | 162 | ### Other changes to iterators 163 | 164 | - In browsers, backpressure is now preferred over snapshot guarantees. For details, please see [`browser-level@1`](https://github.com/Level/browser-level/blob/main/UPGRADING.md#100). On the flip side, `iterator.seek()` now also works in browsers. 165 | - Use of [`level-concat-iterator`](https://github.com/Level/concat-iterator) can be replaced with [`iterator.all()`](https://github.com/Level/level#iteratoralloptions-callback). The former does support `abstract-level` databases but the latter is optimized and always has snapshot guarantees. 166 | - The previously undocumented `highWaterMark` option of `leveldown` is called [`highWaterMarkBytes`](https://github.com/Level/classic-level#about-high-water) in `classic-level` to remove a conflict with streams. 167 | - On iterators with `{ keys: false }` or `{ values: false }` options, the yielded key or value is now consistently `undefined`. 168 | 169 | ### A chained batch should be closed 170 | 171 | Chained batch has a new method `close()` which is an idempotent operation and automatically called after `write()` (for backwards compatibility) or on `db.close()`. This to ensure batches can't be used after closing and reopening a db. If a `write()` is in progress, closing will wait for that. If `write()` is never called then `close()` must be and that's a breaking change because inaction will cause memory leaks. For example: 172 | 173 | ```js 174 | const batch = db.batch() 175 | .put('elena', 'abc') 176 | .del('steve') 177 | 178 | if (someCondition) { 179 | await batch.write() 180 | } else { 181 | // Decided not to commit 182 | await batch.close() 183 | } 184 | 185 | // In either case this will throw 186 | batch.put('daniel', 'xyz') 187 | ``` 188 | 189 | ### Errors now use codes 190 | 191 | The [`level-errors`](https://github.com/Level/errors) module is no longer used or exposed by `level@8`. Instead errors thrown or yielded from a database [have a `code` property](https://github.com/Level/abstract-level#errors). Going forward, the semver contract will be on `code` and error messages will change without a semver-major bump. 192 | 193 | To minimize breakage, the most used error as yielded by `get()` when an entry is not found, has the same properties that `level-errors` added (`notFound` and `status`) in addition to code `LEVEL_NOT_FOUND`. Those properties will be removed in a future version. If you previously did: 194 | 195 | ```js 196 | db.get('abc', function (err, value) { 197 | if (err && err.notFound) { 198 | // Handle missing entry 199 | } 200 | }) 201 | ``` 202 | 203 | That will still work but it's preferred to do: 204 | 205 | ```js 206 | db.get('abc', function (err, value) { 207 | if (err && err.code === 'LEVEL_NOT_FOUND') { 208 | // Handle missing entry 209 | } 210 | }) 211 | ``` 212 | 213 | Or using promises: 214 | 215 | ```js 216 | try { 217 | const value = await db.get('abc') 218 | } catch (err) { 219 | if (err.code === 'LEVEL_NOT_FOUND') { 220 | // Handle missing entry 221 | } 222 | } 223 | ``` 224 | 225 | Side note: it's been suggested more than once to remove this error altogether and we likely will after the dust has settled on `abstract-level`. 226 | 227 | ### Changes to lesser-used properties and methods 228 | 229 | The following properties and methods can no longer be accessed, as they've been removed, renamed or replaced with internal [symbols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol). 230 | 231 | | Object | Property or method | Original module | New module | 232 | | :------------ | :------------------------ | :------------------- | :--------------- | 233 | | db | `_setupIteratorOptions()` | `abstract-leveldown` | `abstract-level` | 234 | | db | `prefix` 1 | `level-js` | `browser-level` | 235 | | db | `upgrade()` | `level-js` | `browser-level` | 236 | | iterator | `_nexting` | `abstract-leveldown` | `abstract-level` | 237 | | iterator | `_ended` | `abstract-leveldown` | `abstract-level` | 238 | | iterator | `cache` 2 | `leveldown` | `classic-level` | 239 | | iterator | `finished` | `leveldown` | `classic-level` | 240 | | chained batch | `_written` | `abstract-leveldown` | `abstract-level` | 241 | | chained batch | `_checkWritten()` | `abstract-leveldown` | `abstract-level` | 242 | | chained batch | `_operations` | `abstract-leveldown` | `abstract-level` | 243 | 244 | 245 | 246 | 1. Conflicted with the `db.prefix` property of sublevels. Renamed to `db.namePrefix`. 247 | 2. If you were using this then you'll want to checkout the new [`nextv()`](https://github.com/Level/level#iteratornextvsize-options-callback) method. 248 | 249 | 250 | 251 | The following properties are now read-only getters. 252 | 253 | | Object | Property | Original module | New module | 254 | | :------------ | :----------------- | :------------------- | :--------------- | 255 | | db | `status` | `abstract-leveldown` | `abstract-level` | 256 | | db | `location` | `leveldown` | `classic-level` | 257 | | db | `location` | `level-js` | `browser-level` | 258 | | db | `namePrefix` | `level-js` | `browser-level` | 259 | | db | `version` | `level-js` | `browser-level` | 260 | | db | `db` (IDBDatabase) | `level-js` | `browser-level` | 261 | | chained batch | `length` | `levelup` | `abstract-level` | 262 | 263 | ### Sublevels are built-in 264 | 265 | _This section is only relevant if you use [`subleveldown`](https://github.com/Level/subleveldown), which can not wrap a `level@8` database._ 266 | 267 | If you previously did: 268 | 269 | ```js 270 | const sub = require('subleveldown') 271 | const example1 = sub(db, 'example1') 272 | const example2 = sub(db, 'example2', { valueEncoding: 'json' }) 273 | ``` 274 | 275 | You must now do: 276 | 277 | ```js 278 | const example1 = db.sublevel('example1') 279 | const example2 = db.sublevel('example2', { valueEncoding: 'json' }) 280 | ``` 281 | 282 | The key structure is equal to that of `subleveldown`. This means that a sublevel can read sublevels previously created with (and populated by) `subleveldown`. There are some new features: 283 | 284 | - `db.batch(..)` takes a `sublevel` option on operations, to atomically commit data to multiple sublevels 285 | - Sublevels support Uint8Array in addition to Buffer. 286 | 287 | To reduce function overloads, the prefix argument (`example1` above) is now required and it's called `name` here. If you previously did one of the following, resulting in an empty name: 288 | 289 | ```js 290 | subleveldown(db) 291 | subleveldown(db, { separator: '@' }) 292 | ``` 293 | 294 | You must now use an explicit empty name: 295 | 296 | ```js 297 | db.sublevel('') 298 | db.sublevel('', { separator: '@' }) 299 | ``` 300 | 301 | The string shorthand for `{ separator }` has also been removed. If you previously did: 302 | 303 | ```js 304 | subleveldown(db, 'example', '@') 305 | ``` 306 | 307 | You must now do: 308 | 309 | ```js 310 | db.sublevel('example', { separator: '@' }) 311 | ``` 312 | 313 | Third, the `open` option has been removed. If you need an asynchronous open hook, feel free to open an issue to discuss restoring this API. 314 | 315 | Lastly, the error message `Parent database is not open` (courtesy of `subleveldown` which had to check open state to prevent segmentation faults from underlying databases) changed to error code [`LEVEL_DATABASE_NOT_OPEN`](https://github.com/Level/abstract-level#errors) (courtesy of `abstract-level` which does those checks on any database). 316 | 317 | ## 7.0.0 318 | 319 | Legacy range options have been removed ([Level/community#86](https://github.com/Level/community/issues/86)). If you previously did: 320 | 321 | ```js 322 | db.createReadStream({ start: 'a', end: 'z' }) 323 | ``` 324 | 325 | An error would now be thrown and you must instead do: 326 | 327 | ```js 328 | db.createReadStream({ gte: 'a', lte: 'z' }) 329 | ``` 330 | 331 | The same applies to `db.iterator()`, `db.createKeyStream()` and `db.createValueStream()`. 332 | 333 | This release also drops support of legacy runtime environments ([Level/community#98](https://github.com/Level/community/issues/98)): 334 | 335 | - Node.js 6 and 8 336 | - Internet Explorer 11 337 | - Safari 9-11 338 | - Stock Android browser (AOSP). 339 | 340 | Lastly, in browsers, the [`immediate`](https://github.com/calvinmetcalf/immediate) and `process` browser shims for `process.nextTick()` have been replaced with the smaller [`queue-microtask`](https://github.com/feross/queue-microtask), except in streams. In the future we might use `queueMicrotask()` in Node.js too. 341 | 342 | ## 6.0.0 343 | 344 | **No breaking changes to the `level` API. If you're only using `level` in Node.js or Electron, you can upgrade without thinking twice.** 345 | 346 | The major bump is for browsers, because `level` upgraded to [`level-js@5`](https://github.com/Level/level-js): 347 | 348 | > Support of keys & values other than strings and Buffers has been dropped. Internally `level-js` now stores keys & values as binary which solves a number of compatibility issues ([Level/memdown#186](https://github.com/Level/memdown/issues/186)). If you pass in a key or value that isn't a string or Buffer, it will be irreversibly stringified. 349 | > 350 | > Existing IndexedDB databases created with `level-js@4` \[via `level@5`] can be read only if they used binary keys and string or binary values. Other types will come out stringified, and string keys will sort incorrectly. Use the included `upgrade()` utility to convert stored data to binary (in so far the environment supports it): 351 | > 352 | > ```js 353 | > var level = require('level') 354 | > var reachdown = require('reachdown') 355 | > var db = level('my-db') 356 | > 357 | > db.open(function (err) { 358 | > if (err) throw err 359 | > 360 | > reachdown(db, 'level-js').upgrade(function (err) { 361 | > if (err) throw err 362 | > }) 363 | > }) 364 | > ``` 365 | 366 | ### New Features :sparkles: 367 | 368 | In case you missed it (a few of these already floated into `level@5`) some exciting new features are now available in all environments: 369 | 370 | - Added [`db.clear()`](https://github.com/Level/level#dbclearoptions-callback) to delete all entries or a range! Also works in [`subleveldown`](https://github.com/Level/subleveldown) - empty that bucket! 371 | - Check out [`db.supports`](https://github.com/Level/level#supports): a manifest describing the features of a db! 372 | - Glorious: `leveldown` ships a prebuilt binary for Linux that is now [compatible with Debian 8, Ubuntu 14.04, RHEL 7, CentOS 7 and other flavors with an old glibc](https://github.com/Level/leveldown/pull/674)! 373 | - With thanks to [Cirrus CI](https://cirrus-ci.org/), `leveldown` is now [continuously tested in FreeBSD](https://github.com/Level/leveldown/pull/678)! 374 | 375 | Go forth and build amazing things. 376 | 377 | ## 5.0.0 378 | 379 | Upgraded to [`leveldown@5.0.0`](https://github.com/Level/leveldown/blob/v5.0.0/UPGRADING.md#v5) and (through `level-packager@5`) [`levelup@4`](https://github.com/Level/levelup/blob/v4.0.0/UPGRADING.md#v4) and [`encoding-down@6`](https://github.com/Level/encoding-down/blob/v6.0.0/UPGRADING.md#v6). Please follow these links for more information. A quick summary: range options (e.g. `gt`) are now serialized the same as keys, `{ gt: undefined }` is not the same as `{}`, nullish values are now rejected and streams are backed by [`readable-stream@3`](https://github.com/nodejs/readable-stream#version-3xx). 380 | 381 | In addition, `level` got browser support! It uses [`leveldown`](https://github.com/Level/leveldown) in node and [`level-js`](https://github.com/Level/level-js) in browsers (backed by [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API)). As such, [`level-browserify`](https://github.com/Level/level-browserify) is not needed anymore and will be deprecated later on. To learn what the integration of `level-js` means for platform, browser and type support, please see the updated [README](README.md#supported-platforms). 382 | 383 | ## 4.0.0 384 | 385 | Dropped support for node 4. No other breaking changes. 386 | 387 | ## 3.0.0 388 | 389 | No breaking changes to the `level` API. 390 | 391 | This is an upgrade to `leveldown@^3.0.0` which is based on `abstract-leveldown@~4.0.0` which in turn contains breaking changes to [`.batch()`](https://github.com/Level/abstract-leveldown/commit/a2621ad70571f6ade9d2be42632ece042e068805). Though this is negated by `levelup`, we decided to release a new major version in the event of dependents reaching down into `db.db`. 392 | 393 | ## 2.0.0 394 | 395 | No breaking changes to the `level` API. 396 | 397 | The parts that make up `level` have been refactored to increase modularity. This is an upgrade to `leveldown@~2.0.0` and `level-packager@~2.0.0`, which in turn upgraded to `levelup@^2.0.0`. The responsibility of encoding keys and values moved from [`levelup`](https://github.com/Level/levelup) to [`encoding-down`](https://github.com/Level/encoding-down), which comes bundled with [`level-packager`](https://github.com/Level/packager). 398 | 399 | Being a convenience package, `level` glues the parts back together to form a drop-in replacement for the users of `levelup@1`, while staying fully compatible with `level@1`. One thing we do get for free, is native Promise support. 400 | 401 | ```js 402 | const db = level('db') 403 | await db.put('foo', 'bar') 404 | console.log(await db.get('foo')) 405 | ``` 406 | 407 | This does not affect the existing callback API, functionality-wise or performance-wise. 408 | 409 | For more information please check the corresponding `CHANGELOG.md` for: 410 | 411 | - [`levelup`](https://github.com/Level/levelup/blob/master/CHANGELOG.md) 412 | - [`leveldown`](https://github.com/Level/leveldown/blob/master/CHANGELOG.md) 413 | - [`level-packager`](https://github.com/Level/packager/blob/master/CHANGELOG.md) 414 | -------------------------------------------------------------------------------- /browser.js: -------------------------------------------------------------------------------- 1 | exports.Level = require('browser-level').BrowserLevel 2 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | import * as AbstractLevel from 'abstract-level' 2 | import * as ClassicLevel from 'classic-level' 3 | import * as BrowserLevel from 'browser-level' 4 | 5 | /** 6 | * Universal {@link AbstractLevel} database for Node.js and browsers. 7 | * 8 | * @template KDefault The default type of keys if not overridden on operations. 9 | * @template VDefault The default type of values if not overridden on operations. 10 | */ 11 | export class Level 12 | extends AbstractLevel.AbstractLevel { 13 | /** 14 | * Database constructor. 15 | * 16 | * @param location Directory path (relative or absolute) where LevelDB will store its 17 | * files, or in browsers, the name of the 18 | * [`IDBDatabase`](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase) to be 19 | * opened. 20 | * @param options Options, of which some will be forwarded to {@link open}. 21 | */ 22 | constructor (location: string, options?: DatabaseOptions | undefined) 23 | 24 | /** 25 | * Location that was passed to the constructor. 26 | */ 27 | get location (): string 28 | 29 | open (): Promise 30 | open (options: OpenOptions): Promise 31 | 32 | get (key: KDefault): Promise 33 | get (key: K, options: GetOptions): Promise 34 | 35 | getMany (keys: KDefault[]): Promise 36 | getMany (keys: K[], options: GetManyOptions): Promise 37 | 38 | put (key: KDefault, value: VDefault): Promise 39 | put (key: K, value: V, options: PutOptions): Promise 40 | 41 | del (key: KDefault): Promise 42 | del (key: K, options: DelOptions): Promise 43 | 44 | batch (operations: Array>): Promise 45 | batch (operations: Array>, options: BatchOptions): Promise 46 | batch (): ChainedBatch 47 | 48 | iterator (): Iterator 49 | iterator (options: IteratorOptions): Iterator 50 | 51 | keys (): KeyIterator 52 | keys (options: KeyIteratorOptions): KeyIterator 53 | 54 | values (): ValueIterator 55 | values (options: ValueIteratorOptions): ValueIterator 56 | } 57 | 58 | export type DatabaseOptions = ClassicLevel.DatabaseOptions & BrowserLevel.DatabaseOptions 59 | export type OpenOptions = ClassicLevel.OpenOptions & BrowserLevel.OpenOptions 60 | export type GetOptions = ClassicLevel.GetOptions & BrowserLevel.GetOptions 61 | export type GetManyOptions = ClassicLevel.GetManyOptions & BrowserLevel.GetManyOptions 62 | export type PutOptions = ClassicLevel.PutOptions & BrowserLevel.PutOptions 63 | export type DelOptions = ClassicLevel.DelOptions & BrowserLevel.DelOptions 64 | 65 | export type BatchOptions = ClassicLevel.BatchOptions & BrowserLevel.BatchOptions 66 | export type BatchOperation = ClassicLevel.BatchOperation & BrowserLevel.BatchOperation 67 | export type ChainedBatch = ClassicLevel.ChainedBatch & BrowserLevel.ChainedBatch 68 | 69 | export type Iterator = ClassicLevel.Iterator & BrowserLevel.Iterator 70 | export type KeyIterator = ClassicLevel.KeyIterator & BrowserLevel.KeyIterator 71 | export type ValueIterator = ClassicLevel.ValueIterator & BrowserLevel.ValueIterator 72 | 73 | export type IteratorOptions = ClassicLevel.IteratorOptions & BrowserLevel.IteratorOptions 74 | export type KeyIteratorOptions = ClassicLevel.KeyIteratorOptions & BrowserLevel.KeyIteratorOptions 75 | export type ValueIteratorOptions = ClassicLevel.ValueIteratorOptions & BrowserLevel.ValueIteratorOptions 76 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | exports.Level = require('classic-level').ClassicLevel 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "level", 3 | "version": "10.0.0", 4 | "description": "Universal abstract-level database for Node.js and browsers", 5 | "license": "MIT", 6 | "main": "index.js", 7 | "types": "./index.d.ts", 8 | "scripts": { 9 | "test": "standard && nyc node test.js", 10 | "test-browsers-local": "airtap --coverage test.js && nyc report", 11 | "coverage": "nyc report -r lcovonly" 12 | }, 13 | "files": [ 14 | "browser.js", 15 | "index.js", 16 | "index.d.ts", 17 | "CHANGELOG.md", 18 | "UPGRADING.md" 19 | ], 20 | "browser": "browser.js", 21 | "dependencies": { 22 | "abstract-level": "^3.1.0", 23 | "browser-level": "^3.0.0", 24 | "classic-level": "^3.0.0" 25 | }, 26 | "devDependencies": { 27 | "@babel/preset-env": "^7.26.9", 28 | "@types/node": "^22.10.1", 29 | "@voxpelli/tsconfig": "^15.1.0", 30 | "airtap": "^5.0.0", 31 | "airtap-playwright": "^1.0.1", 32 | "babelify": "^10.0.0", 33 | "hallmark": "^5.0.1", 34 | "nyc": "^17.1.0", 35 | "standard": "^17.1.2", 36 | "tape": "^5.9.0", 37 | "typescript": "^5.7.2", 38 | "uuid": "^11.1.0" 39 | }, 40 | "funding": { 41 | "type": "opencollective", 42 | "url": "https://opencollective.com/level" 43 | }, 44 | "repository": { 45 | "type": "git", 46 | "url": "https://github.com/Level/level.git" 47 | }, 48 | "homepage": "https://github.com/Level/level", 49 | "keywords": [ 50 | "level", 51 | "leveldb", 52 | "stream", 53 | "database", 54 | "db", 55 | "store", 56 | "storage", 57 | "json" 58 | ], 59 | "engines": { 60 | "node": ">=18" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const test = require('tape') 4 | const { v4: uuid } = require('uuid') 5 | const { Level } = require('.') 6 | 7 | // Because we directly export classic-level or browser-level 8 | // without wrapping them, there's no need for further tests here. 9 | test('smoke test', async function (t) { 10 | const db = new Level('db/' + uuid()) 11 | await db.put('abc', '123') 12 | t.is(await db.get('abc'), '123') 13 | return db.close() 14 | }) 15 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@voxpelli/tsconfig/node18.json", 3 | "compilerOptions": { 4 | "checkJs": false 5 | }, 6 | "include": ["*.ts", "types/*.ts"] 7 | } 8 | --------------------------------------------------------------------------------