Skip to content

Commit 3973c74

Browse files
committed
docs: Add info about init and options in writing adapter guide
1 parent 70f2fc1 commit 3973c74

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

writing-adapters.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,30 @@ If you want to see an example adapter, check out the default [`flat-file-db` ada
77
## Overview
88

99
The methods every adapter has to have are:
10+
- `get(key: string): Promise`: Get a value from the database
11+
- `put(key: string, value: object): Promise`: Put a value into the database
12+
- `has(key: string): Promise`: Check if the database has a value for a certain key
13+
- `getAll(options?): Promise`: Get all values from the database as JSON
1014

11-
- `get(key: string)`: Get a value from the database
12-
- `put(key: string, value: object)`: Put a value into the database
13-
- `has(key: string)`: Check if the database has a value for a certain key
14-
- `getAll(options?)`: Get all values from the database as JSON
15+
All of these methods have to return Promises. On top of that there is some optional methods:
1516

16-
All of these methods have to return Promises. On top of that there is one more method, which returns an Observer (based on the [proposed spec](https://github.com/tc39/proposal-observable))
17+
- `init(options: Object): void`: A method to setup the adapter based on
18+
- `subscribe(pathname?: string): Observer`: Subscribe to changes of all keys starting with a certain `pathname`. If no pathname is provided, subscribe to all changes. It returns an Observer (based on the [proposed spec](https://github.com/tc39/proposal-observable))
1719

18-
- `subscribe(pathname?: string)`: Subscribe to changes of all keys starting with a certain `pathname`. If no pathname is provided, subscribe to all changes.
20+
Furthermore, there are some non callable fields:
21+
- `options: Array<ArgsOption>`: An array of cli options that is needed to configure the adapter. The elements in the list should be compatible with the options of the [args library][args-options]. It is important to read environment variables and put that in the `defaultValue` field to support configuration through environment variables. The parsed options will be passed to `init` described above, thus, `init` is required when options is defined.
22+
23+
[args-options]: https://github.com/leo/args#optionslist
1924

2025
This is what the export of an adapter should thusly look like:
2126

2227
```JS
2328
// index.js
24-
const { get, put, getAll, has, subscribe } = require('./adapter')
29+
const { init, options, get, put, getAll, has, subscribe } = require('./adapter')
2530

2631
module.exports = {
32+
init,
33+
options,
2734
get,
2835
put,
2936
getAll,

0 commit comments

Comments
 (0)