Skip to content

Commit eb819a6

Browse files
committed
Breaking: change encodings and events to always be objects
Rather than truthy values. This change is not compatible with `abstract-leveldown` or its dependents.
1 parent d82cb54 commit eb819a6

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,13 @@ await db.put('key', 'value')
316316

317317
</details>
318318

319-
### `events` (boolean or object)
319+
### `events` (object)
320320

321-
Is db an event emitter, as indicated by a truthy value? And does it support specific events as indicated by nested properties?
321+
Which events does the database emit, as indicated by nested properties? For example:
322322

323323
```js
324-
if (db.supports.events && db.supports.events.open) {
325-
db.once('open', () => { /* .. */})
324+
if (db.supports.events.put) {
325+
db.on('put', () => { /* .. */})
326326
}
327327
```
328328

@@ -353,23 +353,26 @@ Does db have the methods `createReadStream`, `createKeyStream` and `createValueS
353353

354354
</details>
355355

356-
### `encodings` (boolean or object)
356+
### `encodings` (object)
357357

358-
Do all relevant db methods take `keyEncoding` and `valueEncoding` options? If truthy, the db must use a default encoding of utf8 and all its operations must return strings rather than buffers by default.
359-
360-
Support of individual encodings may also be indicated by adding their names as nested properties. For example:
358+
Which encodings (by name) does the database support, as indicated by nested properties? For example:
361359

362360
```js
363361
{
364362
encodings: {
365-
utf8: true
363+
utf8: true,
364+
json: true
366365
}
367366
}
368367
```
369368

369+
As the `encodings` property cannot be false (anymore, since `level-supports` v3.0.0) it implies that the database supports `keyEncoding` and `valueEncoding` options on all relevant methods, uses a default encoding of utf8 and that hence all of its read operations return strings rather than buffers by default.
370+
370371
<details>
371372
<summary>Support matrix</summary>
372373

374+
At the moment, this matrix just indicates general support of encodings, not that the listed modules support the `encodings` property exactly as described above.
375+
373376
| Module | Support |
374377
| :------------------- | :------ |
375378
| `abstract-leveldown` ||

index.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,8 @@ module.exports = function supports (...manifests) {
3131
openCallback: manifest.openCallback || false,
3232
promises: manifest.promises || false,
3333
streams: manifest.streams || false,
34-
encodings: maybeObject(manifest.encodings),
35-
events: maybeObject(manifest.events),
36-
37-
// Methods that are not part of abstract-leveldown or levelup
34+
encodings: Object.assign({}, manifest.encodings),
35+
events: Object.assign({}, manifest.events),
3836
additionalMethods: Object.assign({}, manifest.additionalMethods)
3937
})
4038
}
41-
42-
function maybeObject (value) {
43-
return !value ? false : Object.assign({}, value)
44-
}

0 commit comments

Comments
 (0)