forked from ipfs/interface-datastore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (51 loc) · 1.44 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* @flow */
'use strict'
const Key = require('./key')
const MemoryDatastore = require('./memory')
const utils = require('./utils')
exports.Key = Key
exports.MemoryDatastore = MemoryDatastore
exports.utils = utils
/* ::
// -- Basics
export type Callback<Value> = (err: ?Error, ?Value) => void
// eslint-disable-next-line
export interface Datastore<Value> {
// eslint-disable-next-line
put(Key, Value, Callback<void>): void;
// eslint-disable-next-line
get(Key, Callback<Value>): void;
has(Key, Callback<bool>): void;
delete(Key, Callback<void>): void;
// eslint-disable-next-line
query(Query<Value>): QueryResult<Value>;
// eslint-disable-next-line
batch(): Batch<Value>;
close(Callback<void>): void;
open(Callback<void>): void;
}
// -- Batch
export type Batch<Value> = {
put(Key, Value): void,
delete(Key): void,
commit(Callback<void>): void
}
// -- Query
export type Query<Value> = {
prefix?: string,
filters?: Array<Filter<Value>>,
orders?: Array<Order<Value>>,
limit?: number,
offset?: number,
keysOnly?: bool
}
export type PullEnd = bool | Error
export type PullSource<Val> = (end: ?PullEnd, (end: ?PullEnd, Val) => void) => void
export type QueryResult<Value> = PullSource<QueryEntry<Value>>
export type QueryEntry<Value> = {
key: Key,
value?: Value
}
export type Filter<Value> = (QueryEntry<Value>, Callback<bool>) => void
export type Order<Value> = (QueryResult<Value>, Callback<QueryResult<Value>>) => void
*/