Skip to content

Commit d757046

Browse files
committed
No need to expose snapshot.db
1 parent cacb061 commit d757046

File tree

4 files changed

+4
-18
lines changed

4 files changed

+4
-18
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -723,10 +723,6 @@ Free up underlying resources. Be sure to call this when the snapshot is no longe
723723

724724
After `snapshot.close()` has been called, no further operations are allowed. For example, `db.get(key, { snapshot })` will throw an error with code [`LEVEL_SNAPSHOT_NOT_OPEN`](#level_snapshot_not_open).
725725

726-
#### `snapshot.db`
727-
728-
A reference to the database that created this snapshot. This refers to the [root database](#subleveldb) when the snapshot was created via a sublevel (which plays no role in snapshots).
729-
730726
### Encodings
731727

732728
Any database method that takes a `key` argument, `value` argument or range options like `gte`, hereby jointly referred to as `data`, runs that `data` through an _encoding_. This means to encode input `data` and decode output `data`.
@@ -1774,7 +1770,7 @@ The default `_close()` returns a resolved promise. Overriding is optional.
17741770

17751771
### `snapshot = new AbstractSnapshot(db)`
17761772

1777-
The first argument to this constructor must be an instance of the relevant `AbstractLevel` implementation. The constructor will set `snapshot.db` which ensures that `db` will not be garbage collected in case there are no other references to it.
1773+
The first argument to this constructor must be an instance of the relevant `AbstractLevel` implementation.
17781774

17791775
#### `snapshot._close()`
17801776

abstract-snapshot.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ class AbstractSnapshot {
1616
throw new TypeError(`The first argument must be an abstract-level database, received ${hint}`)
1717
}
1818

19+
// Also ensures db will not be garbage collected yet
1920
this.#root = db
2021
this.#root.attachResource(this)
2122
}
2223

23-
get db () {
24-
return this.#root
25-
}
26-
2724
ref () {
2825
if (!this.#open) {
2926
throw new ModuleError('Snapshot is not open: cannot use snapshot after close()', {

types/abstract-level.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ declare class AbstractLevel<TFormat, KDefault = string, VDefault = string>
242242
*
243243
* Don't forget to call `snapshot.close()` when done.
244244
*/
245-
snapshot (): AbstractSnapshot<typeof this>
245+
snapshot (): AbstractSnapshot
246246

247247
/**
248248
* Call the function {@link fn} at a later time when {@link status} changes to

types/abstract-snapshot.d.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
/**
22
* A lightweight token that represents a version of a database at a particular point in
33
* time.
4-
*
5-
* @template TDatabase Type of the database that created this snapshot.
64
*/
7-
export class AbstractSnapshot<TDatabase> {
8-
/**
9-
* A reference to the database that created this snapshot.
10-
*/
11-
db: TDatabase
12-
5+
export class AbstractSnapshot {
136
/**
147
* Increment reference count, to register work that should delay closing until
158
* {@link unref} is called an equal amount of times. The promise that will be returned

0 commit comments

Comments
 (0)