Skip to content

Commit 7797b0d

Browse files
authored
Merge pull request orbitdb-archive#12 from orbitdb/feat/full-op
Add possibility to return the full operation data in addition to value
2 parents 26f5e36 + d154d17 commit 7797b0d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/DocumentIndex.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ class DocumentIndex {
55
this._index = {}
66
}
77

8-
get(key) {
9-
return this._index[key]
8+
get(key, fullOp = false) {
9+
return fullOp
10+
? this._index[key]
11+
: this._index[key].payload.value
1012
}
1113

1214
updateIndex(oplog, onProgressCallback) {
@@ -16,7 +18,7 @@ class DocumentIndex {
1618
// handled.push(item.payload.key)
1719
handled[item.payload.key] = true
1820
if(item.payload.op === 'PUT') {
19-
this._index[item.payload.key] = item.payload.value
21+
this._index[item.payload.key] = item
2022
} else if (item.payload.op === 'DEL') {
2123
delete this._index[item.payload.key]
2224
}

src/DocumentStore.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ class DocumentStore extends Store {
3737
.map(mapper)
3838
}
3939

40-
query(mapper) {
40+
query(mapper, options = {}) {
41+
// Whether we return the full operation data or just the db value
42+
const fullOp = options ? options.fullOp : false
43+
4144
return Object.keys(this._index._index)
42-
.map((e) => this._index.get(e))
45+
.map((e) => this._index.get(e, fullOp))
4346
.filter((e) => mapper(e))
4447
}
4548

0 commit comments

Comments
 (0)