Skip to content

Commit

Permalink
Add implicit- and explicitSnapshots
Browse files Browse the repository at this point in the history
Ref: Level/community#118
Category: addition
  • Loading branch information
vweevers committed Dec 21, 2024
1 parent 1bf208c commit e4b5378
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
40 changes: 28 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,42 @@ Given zero or more manifest objects, returns a merged and enriched manifest obje
For future extensibility, the properties are truthy rather than strictly typed booleans. Falsy or absent properties are converted to `false`, other values are allowed:

```js
supports().snapshots // false
supports({ snapshots: true }).snapshots // true
supports({ snapshots: {} }).snapshots // {}
supports({ snapshots: 1 }, { snapshots: 2 }).snapshots // 2
supports().seek // false
supports({ seek: true }).seek // true
supports({ seek: {} }).seek // {}
supports({ seek: 1 }, { seek: 2 }).seek // 2
```

For consumers of the manifest this means they should check support like so:

```js
if (db.supports.snapshots)
if (db.supports.seek)
```

Rather than:

```js
if (db.supports.snapshots === true)
if (db.supports.seek === true)
```

**Note:** the manifest describes high-level features that typically encompass multiple methods of a db. It is currently not a goal to describe a full API, or versions of it.

## Features

### `snapshots` (boolean)
### `implicitSnapshots` (boolean)

Does the database have snapshot guarantees? Meaning that reads are unaffected by simultaneous writes. For example, an iterator should read from a snapshot of the database, created at the time `db.iterator()` was called. This means the iterator will not see the data of simultaneous write operations.

Must be `false` if any of the following is true:
Does the database read from a snapshot as described in [`abstract-level`](https://github.com/Level/abstract-level#reading-from-snapshots)? Must be `false` if any of the following is true:

- Reads don't operate on a snapshot
- Snapshots are created asynchronously.

Aliased as `snapshots` for backwards compatibility.

<details>
<summary>Support matrix</summary>

| Module | Snapshot guarantee |
| :------------------- | :-------------------------- |
| Module | Implicit snapshots |
| :------------------- | :---------------------------- |
| `classic-level` ||
| `memory-level` ||
| `browser-level` ||
Expand All @@ -98,6 +98,22 @@ Must be `false` if any of the following is true:

</details>

### `explicitSnapshots` (boolean)

Does the database implement `db.snapshot()` and do read methods accept a `snapshot` option as described in [`abstract-level`](https://github.com/Level/abstract-level#reading-from-snapshots)?

<details>
<summary>Support matrix</summary>

| Module | Explicit snapshots |
| :------------------- | :-------------------------- |
| `classic-level` | Not yet |
| `memory-level` | Not yet |
| `browser-level` ||
| `rave-level` | TBD |

</details>

### `permanence` (boolean)

Does data survive after process (or environment) exit? Typically true. False for [`memory-level`](https://github.com/Level/memory-level) and [`memdown`](https://github.com/Level/memdown).
Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
exports.supports = function supports (...manifests) {
const manifest = manifests.reduce((acc, m) => Object.assign(acc, m), {})

// Snapshots is an alias for backwards compatibility
const implicitSnapshots = manifest.implicitSnapshots || manifest.snapshots || false
const explicitSnapshots = manifest.explicitSnapshots || false

return Object.assign(manifest, {
snapshots: manifest.snapshots || false,
implicitSnapshots,
explicitSnapshots,
snapshots: implicitSnapshots,
permanence: manifest.permanence || false,
seek: manifest.seek || false,
createIfMissing: manifest.createIfMissing || false,
Expand Down
11 changes: 11 additions & 0 deletions test/self.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,14 @@ test('does not merge additionalMethods', function (t) {
t.same(manifest.additionalMethods, { bar: true })
t.end()
})

test('adds snapshots alias', function (t) {
for (const value of [true, false]) {
t.is(supports({ implicitSnapshots: value }).implicitSnapshots, value)
t.is(supports({ implicitSnapshots: value }).snapshots, value)
t.is(supports({ snapshots: value }).implicitSnapshots, value)
t.is(supports({ snapshots: value }).snapshots, value)
}

t.end()
})

0 comments on commit e4b5378

Please sign in to comment.