Skip to content

Commit 68bac51

Browse files
committed
Add implicit- and explicitSnapshots
Ref: Level/community#118 Category: addition
1 parent 1bf208c commit 68bac51

File tree

3 files changed

+46
-13
lines changed

3 files changed

+46
-13
lines changed

README.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,42 +41,42 @@ Given zero or more manifest objects, returns a merged and enriched manifest obje
4141
For future extensibility, the properties are truthy rather than strictly typed booleans. Falsy or absent properties are converted to `false`, other values are allowed:
4242

4343
```js
44-
supports().snapshots // false
45-
supports({ snapshots: true }).snapshots // true
46-
supports({ snapshots: {} }).snapshots // {}
47-
supports({ snapshots: 1 }, { snapshots: 2 }).snapshots // 2
44+
supports().seek // false
45+
supports({ seek: true }).seek // true
46+
supports({ seek: {} }).seek // {}
47+
supports({ seek: 1 }, { seek: 2 }).seek // 2
4848
```
4949

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

5252
```js
53-
if (db.supports.snapshots)
53+
if (db.supports.seek)
5454
```
5555

5656
Rather than:
5757

5858
```js
59-
if (db.supports.snapshots === true)
59+
if (db.supports.seek === true)
6060
```
6161

6262
**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.
6363

6464
## Features
6565

66-
### `snapshots` (boolean)
66+
### `implicitSnapshots` (boolean)
6767

68-
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.
69-
70-
Must be `false` if any of the following is true:
68+
Does the database read from a snapshot as described in [`abstract-level`](https://github.com/Level/abstract-level?tab=readme-ov-file#reading-from-snapshots)? Must be `false` if any of the following is true:
7169

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

73+
Aliased as `snapshots` for backwards compatibility.
74+
7575
<details>
7676
<summary>Support matrix</summary>
7777

78-
| Module | Snapshot guarantee |
79-
| :------------------- | :-------------------------- |
78+
| Module | Implicit snapshots |
79+
| :------------------- | :---------------------------- |
8080
| `classic-level` ||
8181
| `memory-level` ||
8282
| `browser-level` ||
@@ -98,6 +98,22 @@ Must be `false` if any of the following is true:
9898

9999
</details>
100100

101+
### `explicitSnapshots` (boolean)
102+
103+
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?tab=readme-ov-file#reading-from-snapshots)?
104+
105+
<details>
106+
<summary>Support matrix</summary>
107+
108+
| Module | Explicit snapshots |
109+
| :------------------- | :-------------------------- |
110+
| `classic-level` | Not yet |
111+
| `memory-level` | Not yet |
112+
| `browser-level` ||
113+
| `rave-level` | TBD |
114+
115+
</details>
116+
101117
### `permanence` (boolean)
102118

103119
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).

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
exports.supports = function supports (...manifests) {
44
const manifest = manifests.reduce((acc, m) => Object.assign(acc, m), {})
55

6+
// Snapshots is an alias for backwards compatibility
7+
const implicitSnapshots = manifest.implicitSnapshots || manifest.snapshots || false
8+
const explicitSnapshots = manifest.explicitSnapshots || false
9+
610
return Object.assign(manifest, {
7-
snapshots: manifest.snapshots || false,
11+
implicitSnapshots,
12+
explicitSnapshots,
13+
snapshots: implicitSnapshots,
814
permanence: manifest.permanence || false,
915
seek: manifest.seek || false,
1016
createIfMissing: manifest.createIfMissing || false,

test/self.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,14 @@ test('does not merge additionalMethods', function (t) {
7373
t.same(manifest.additionalMethods, { bar: true })
7474
t.end()
7575
})
76+
77+
test('adds snapshots alias', function (t) {
78+
for (const value of [true, false]) {
79+
t.is(supports({ implicitSnapshots: value }).implicitSnapshots, value)
80+
t.is(supports({ implicitSnapshots: value }).snapshots, value)
81+
t.is(supports({ snapshots: value }).implicitSnapshots, value)
82+
t.is(supports({ snapshots: value }).snapshots, value)
83+
}
84+
85+
t.end()
86+
})

0 commit comments

Comments
 (0)