|
@@ -12,7 +12,11 @@ const ram = require('random-access-memory')
|
12
|
12
|
const raf = require('random-access-file')
|
13
|
13
|
const level = require('level')
|
14
|
14
|
const memdb = require('memdb')
|
|
15
|
+const thunky = require('thunky')
|
15
|
16
|
const { EventEmitter } = require('events')
|
|
17
|
+const assert = require('assert')
|
|
18
|
+
|
|
19
|
+const { isFunction } = require('./util')
|
16
|
20
|
|
17
|
21
|
const crypto = Crypto()
|
18
|
22
|
|
|
@@ -21,6 +25,8 @@ const indexes = [
|
21
|
25
|
{ key: 'typ', value: [['value', 'type'], ['value', 'timestamp']] },
|
22
|
26
|
]
|
23
|
27
|
|
|
28
|
+const CALLBACK_REQUIRED = 'cobox-group: callback required'
|
|
29
|
+
|
24
|
30
|
module.exports = (storage, key, opts) => new CoBoxGroup(storage, key, opts)
|
25
|
31
|
|
26
|
32
|
class CoBoxGroup extends EventEmitter {
|
|
@@ -71,8 +77,28 @@ class CoBoxGroup extends EventEmitter {
|
71
|
77
|
})
|
72
|
78
|
|
73
|
79
|
this.core.use('query', Query(this.logDB, { indexes, validator }))
|
|
80
|
+
|
|
81
|
+ this.log = thunky(this.log.bind(this))
|
74
|
82
|
this.logs = this.core.api.query
|
75
|
83
|
}
|
|
84
|
+
|
|
85
|
+ ready (callback) {
|
|
86
|
+ if (this._isReady) return callback()
|
|
87
|
+ else this._ready(callback)
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ // TODO: we should be able to change this so once ready, the log will be the local feed
|
|
91
|
+ // That way we won't need thunky...
|
|
92
|
+ log (callback) {
|
|
93
|
+ assert(isFunction(callback), CALLBACK_REQUIRED)
|
|
94
|
+ this.core.writer('local', callback)
|
|
95
|
+ }
|
|
96
|
+
|
|
97
|
+ // ------------------------------ PRIVATE FUNCTIONS ------------------------------
|
|
98
|
+
|
|
99
|
+ _ready (callback) {
|
|
100
|
+ // make sure the core and everything is ready...
|
|
101
|
+ }
|
76
|
102
|
}
|
77
|
103
|
|
78
|
104
|
function validator (msg) {
|
|
@@ -99,7 +125,7 @@ function storeSecret (storage, pubKey, secretKey) {
|
99
|
125
|
fs.writeFileSync(path.join(SECRET_KEYS(storage), pubKey.toString('hex')), secretKey)
|
100
|
126
|
}
|
101
|
127
|
|
102
|
|
-// ------------------------------------------------------------------------------------------
|
|
128
|
+// ------------------------ MOVE TO COLLECTION CLASS IN COBOX-CORE ----------------------------
|
103
|
129
|
|
104
|
130
|
// TODO: associate group with the creating identity, take peer pubKey as a param...
|
105
|
131
|
CoBoxGroup.create = function (name, opts) {
|