@live-change/db 0.6.23 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +8 -8
- package/lib/AtomicWriter.js +1 -1
- package/lib/ChangeStream.js +1 -1
- package/lib/Database.js +11 -10
- package/lib/Index.js +12 -10
- package/lib/Log.js +3 -3
- package/lib/OpLogger.js +1 -1
- package/lib/ScriptContext.js +6 -5
- package/lib/Table.js +4 -4
- package/lib/WebScriptContext.js +1 -1
- package/lib/profileLog.js +1 -1
- package/lib/queryGet.js +3 -3
- package/lib/queryObservable.js +3 -3
- package/lib/queryUpdate.js +1 -1
- package/package.json +7 -6
- package/tests/index.js +6 -7
- package/tests/log.js +7 -7
- package/tests/query-get.js +6 -7
- package/tests/query-observable.js +6 -7
- package/tests/table.js +6 -7
- package/tests/utils/createDb.js +8 -6
- package/tests/utils/createStore.level.js +5 -6
- package/tests/utils/createStore.lmdb.js +4 -4
package/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import Log from "./lib/Log.js"
|
|
2
|
+
import Table from "./lib/Table.js"
|
|
3
|
+
import OpLogger from "./lib/OpLogger.js"
|
|
4
|
+
import Index from "./lib/Index.js"
|
|
5
|
+
import AtomicWriter from "./lib/AtomicWriter.js"
|
|
6
|
+
import Database from "./lib/Database.js"
|
|
7
|
+
import profileLog from './lib/profileLog.js'
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
export {
|
|
10
10
|
Log, Table, OpLogger, Index, AtomicWriter, Database, profileLog
|
|
11
11
|
}
|
package/lib/AtomicWriter.js
CHANGED
package/lib/ChangeStream.js
CHANGED
package/lib/Database.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import Table from './Table.js'
|
|
2
|
+
import Index from './Index.js'
|
|
3
|
+
import Log from './Log.js'
|
|
4
|
+
import queryGet from './queryGet.js'
|
|
5
|
+
import queryObservable from './queryObservable.js'
|
|
6
|
+
import getRandomValues from 'get-random-values'
|
|
7
|
+
import nextTick from 'next-tick'
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
import ReactiveDao from "@live-change/dao"
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
import Debug from 'debug'
|
|
12
|
+
const debug = Debug('db')
|
|
12
13
|
|
|
13
14
|
class Database {
|
|
14
15
|
constructor(config, storeFactory, saveConfig, deleteStore, name, createScriptContext) {
|
|
@@ -300,4 +301,4 @@ class Database {
|
|
|
300
301
|
}
|
|
301
302
|
}
|
|
302
303
|
|
|
303
|
-
|
|
304
|
+
export default Database
|
package/lib/Index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import IntervalTreeLib from 'node-interval-tree'
|
|
2
|
+
const IntervalTree = IntervalTreeLib.default || IntervalTreeLib
|
|
3
|
+
import ReactiveDao from "@live-change/dao"
|
|
4
|
+
import Table from './Table.js'
|
|
5
|
+
import queryGet from './queryGet.js'
|
|
6
|
+
import profileLog from './profileLog.js'
|
|
7
|
+
import nextTick from 'next-tick'
|
|
8
|
+
import { ChangeStream } from './ChangeStream.js'
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
import Debug from 'debug'
|
|
12
|
+
const debug = Debug('db')
|
|
11
13
|
|
|
12
14
|
const opLogBatchSize = 128 /// TODO: incrase after testing
|
|
13
15
|
|
|
@@ -526,4 +528,4 @@ class Index extends Table {
|
|
|
526
528
|
}
|
|
527
529
|
}
|
|
528
530
|
|
|
529
|
-
|
|
531
|
+
export default Index
|
package/lib/Log.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import AtomicWriter from './AtomicWriter.js'
|
|
2
|
+
import ReactiveDao from "@live-change/dao"
|
|
3
3
|
|
|
4
4
|
class Log {
|
|
5
5
|
constructor(database, name, config) {
|
|
@@ -61,4 +61,4 @@ class Log {
|
|
|
61
61
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
export default Log
|
package/lib/OpLogger.js
CHANGED
package/lib/ScriptContext.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import vm from 'vm'
|
|
2
|
+
import crypto from 'crypto'
|
|
3
|
+
import { ChangeStreamPipe } from './ChangeStream.js'
|
|
4
|
+
import pref_hooks from 'perf_hooks'
|
|
4
5
|
|
|
5
6
|
const defaultNativeGlobals = [
|
|
6
7
|
'Array', 'ArrayBuffer',
|
|
@@ -34,7 +35,7 @@ const defaultContext = {
|
|
|
34
35
|
pipe() {
|
|
35
36
|
return new ChangeStreamPipe()
|
|
36
37
|
},
|
|
37
|
-
'performance':
|
|
38
|
+
'performance': pref_hooks.performance,
|
|
38
39
|
constructor: null
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -103,4 +104,4 @@ class ScriptContext {
|
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
|
|
107
|
+
export default ScriptContext
|
package/lib/Table.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import OpLogger from './OpLogger.js'
|
|
2
|
+
import AtomicWriter from './AtomicWriter.js'
|
|
3
|
+
import ReactiveDao from '@live-change/dao'
|
|
4
4
|
|
|
5
5
|
function opLogWritter(store) {
|
|
6
6
|
let lastTime = Date.now()
|
|
@@ -143,4 +143,4 @@ class Table {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
export default Table
|
package/lib/WebScriptContext.js
CHANGED
package/lib/profileLog.js
CHANGED
package/lib/queryGet.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { TableWriter, LogWriter } from './queryUpdate.js'
|
|
2
|
+
import { ChangeStream } from './ChangeStream.js'
|
|
3
3
|
|
|
4
4
|
const maxGetLimit = 256
|
|
5
5
|
|
|
@@ -194,4 +194,4 @@ queryGet.single = querySingleGet
|
|
|
194
194
|
queryGet.QueryWriter = QueryWriter
|
|
195
195
|
queryGet.QueryReader = QueryReader
|
|
196
196
|
|
|
197
|
-
|
|
197
|
+
export default queryGet
|
package/lib/queryObservable.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import ReactiveDao from "@live-change/dao"
|
|
2
|
+
import { ChangeStream } from './ChangeStream.js'
|
|
3
3
|
|
|
4
4
|
class ObjectObserver {
|
|
5
5
|
#callback = null
|
|
@@ -486,4 +486,4 @@ queryObservable.single = querySingleObservable
|
|
|
486
486
|
queryObservable.QueryWriter = QueryWriter
|
|
487
487
|
queryObservable.QueryReader = QueryReader
|
|
488
488
|
|
|
489
|
-
|
|
489
|
+
export default queryObservable
|
package/lib/queryUpdate.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Database with observable data for live queries",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,15 +19,16 @@
|
|
|
19
19
|
"bugs": {
|
|
20
20
|
"url": "https://github.com/live-change/live-change-db/issues"
|
|
21
21
|
},
|
|
22
|
+
"type": "module",
|
|
22
23
|
"homepage": "https://github.com/live-change/live-change-db",
|
|
23
24
|
"devDependencies": {
|
|
24
|
-
"@live-change/db-store-level": "^0.
|
|
25
|
-
"@live-change/db-store-lmdb": "^0.
|
|
25
|
+
"@live-change/db-store-level": "^0.7.0",
|
|
26
|
+
"@live-change/db-store-lmdb": "^0.7.0",
|
|
26
27
|
"minimist": ">=1.2.3",
|
|
27
28
|
"next-tick": "^1.1.0",
|
|
28
|
-
"rimraf": "^
|
|
29
|
+
"rimraf": "^5.0.5",
|
|
29
30
|
"sockjs": "^0.3.24",
|
|
30
|
-
"tape": "^5.
|
|
31
|
+
"tape": "^5.7.4",
|
|
31
32
|
"websocket-extensions": ">=0.1.4"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
@@ -35,5 +36,5 @@
|
|
|
35
36
|
"get-random-values": "^1.2.2",
|
|
36
37
|
"node-interval-tree": "^1.3.3"
|
|
37
38
|
},
|
|
38
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "b372725d436e29f7cc66b811533009c9ea5330a1"
|
|
39
40
|
}
|
package/tests/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import test from 'tape'
|
|
2
|
+
import { rimraf } from "rimraf"
|
|
3
|
+
import createDb from './utils/createDb.js'
|
|
3
4
|
|
|
4
5
|
const dbPath = `./test.i.db`
|
|
5
6
|
rimraf.sync(dbPath)
|
|
@@ -37,7 +38,7 @@ test("index", t => {
|
|
|
37
38
|
|
|
38
39
|
t.test('open database', async t => {
|
|
39
40
|
t.plan(1)
|
|
40
|
-
db =
|
|
41
|
+
db = createDb(dbPath)
|
|
41
42
|
t.pass('opened')
|
|
42
43
|
})
|
|
43
44
|
|
|
@@ -191,9 +192,7 @@ test("index", t => {
|
|
|
191
192
|
t.plan(2)
|
|
192
193
|
await db.close()
|
|
193
194
|
t.pass('closed')
|
|
194
|
-
rimraf(dbPath
|
|
195
|
-
|
|
196
|
-
t.pass('removed')
|
|
197
|
-
})
|
|
195
|
+
await rimraf(dbPath)
|
|
196
|
+
t.pass('removed')
|
|
198
197
|
})
|
|
199
198
|
})
|
package/tests/log.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import test from 'tape'
|
|
2
|
+
import { rimraf } from "rimraf"
|
|
3
|
+
import createDb from './utils/createDb.js'
|
|
3
4
|
|
|
4
5
|
const dbPath = `./test.l.db`
|
|
5
6
|
rimraf.sync(dbPath)
|
|
@@ -19,7 +20,7 @@ test("store range observable", t => {
|
|
|
19
20
|
|
|
20
21
|
t.test('open database', async t => {
|
|
21
22
|
t.plan(1)
|
|
22
|
-
db =
|
|
23
|
+
db = createDb(dbPath)
|
|
23
24
|
t.pass('opened')
|
|
24
25
|
})
|
|
25
26
|
|
|
@@ -39,9 +40,8 @@ test("store range observable", t => {
|
|
|
39
40
|
t.plan(2)
|
|
40
41
|
await db.close()
|
|
41
42
|
t.pass('closed')
|
|
42
|
-
rimraf(dbPath
|
|
43
|
-
|
|
44
|
-
t.pass('removed')
|
|
45
|
-
})
|
|
43
|
+
await rimraf(dbPath)
|
|
44
|
+
t.pass('removed')
|
|
46
45
|
})
|
|
46
|
+
|
|
47
47
|
})
|
package/tests/query-get.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import test from 'tape'
|
|
2
|
+
import { rimraf } from "rimraf"
|
|
3
|
+
import createDb from './utils/createDb.js'
|
|
3
4
|
|
|
4
5
|
const dbPath = `./test.qg.db`
|
|
5
|
-
const db =
|
|
6
|
+
const db = createDb(dbPath)
|
|
6
7
|
|
|
7
8
|
const users = [
|
|
8
9
|
{ id: '1', name: 'david' },
|
|
@@ -109,9 +110,7 @@ test("store range observable", t => {
|
|
|
109
110
|
|
|
110
111
|
t.test("close and remove database", async t => {
|
|
111
112
|
t.plan(1)
|
|
112
|
-
rimraf(dbPath
|
|
113
|
-
|
|
114
|
-
t.pass('removed')
|
|
115
|
-
})
|
|
113
|
+
await rimraf(dbPath)
|
|
114
|
+
t.pass('removed')
|
|
116
115
|
})
|
|
117
116
|
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import test from 'tape'
|
|
2
|
+
import { rimraf } from "rimraf"
|
|
3
|
+
import createDb from './utils/createDb.js'
|
|
3
4
|
|
|
4
5
|
const dbPath = `./test.qo.db`
|
|
5
6
|
rimraf.sync(dbPath)
|
|
@@ -37,7 +38,7 @@ test("query observable", t => {
|
|
|
37
38
|
|
|
38
39
|
t.test('open database', async t => {
|
|
39
40
|
t.plan(1)
|
|
40
|
-
db =
|
|
41
|
+
db = createDb(dbPath)
|
|
41
42
|
t.pass('opened')
|
|
42
43
|
})
|
|
43
44
|
|
|
@@ -236,9 +237,7 @@ test("query observable", t => {
|
|
|
236
237
|
t.plan(2)
|
|
237
238
|
await db.close()
|
|
238
239
|
t.pass('closed')
|
|
239
|
-
rimraf(dbPath
|
|
240
|
-
|
|
241
|
-
t.pass('removed')
|
|
242
|
-
})
|
|
240
|
+
await rimraf(dbPath)
|
|
241
|
+
t.pass('removed')
|
|
243
242
|
})
|
|
244
243
|
})
|
package/tests/table.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import test from 'tape'
|
|
2
|
+
import { rimraf } from "rimraf"
|
|
3
|
+
import createDb from './utils/createDb.js'
|
|
3
4
|
|
|
4
5
|
const dbPath = `./test.t.db`
|
|
5
6
|
rimraf.sync(dbPath)
|
|
@@ -26,7 +27,7 @@ test("store range observable", t => {
|
|
|
26
27
|
|
|
27
28
|
t.test('open database', async t => {
|
|
28
29
|
t.plan(1)
|
|
29
|
-
db =
|
|
30
|
+
db = createDb(dbPath)
|
|
30
31
|
t.pass('opened')
|
|
31
32
|
})
|
|
32
33
|
|
|
@@ -48,9 +49,7 @@ test("store range observable", t => {
|
|
|
48
49
|
t.plan(2)
|
|
49
50
|
await db.close()
|
|
50
51
|
t.pass('closed')
|
|
51
|
-
rimraf(dbPath
|
|
52
|
-
|
|
53
|
-
t.pass('removed')
|
|
54
|
-
})
|
|
52
|
+
await rimraf(dbPath)
|
|
53
|
+
t.pass('removed')
|
|
55
54
|
})
|
|
56
55
|
})
|
package/tests/utils/createDb.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { rimrafSync } from "rimraf"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import Database from "../../lib/Database.js"
|
|
4
|
+
import createStoreLevel from "./createStore.level.js"
|
|
5
|
+
import createStoreLmdb from "./createStore.lmdb.js"
|
|
4
6
|
|
|
5
7
|
function createDb(dbPath) {
|
|
6
|
-
|
|
8
|
+
rimrafSync(dbPath)
|
|
7
9
|
const db = new Database({}, (name, config) => {
|
|
8
10
|
let store
|
|
9
11
|
if(process.env.DB=='level') {
|
|
10
|
-
store =
|
|
12
|
+
store = createStoreLmdb(dbPath, name)
|
|
11
13
|
} else if(process.env.DB=='lmdb' || !process.env.DB) {
|
|
12
|
-
store =
|
|
14
|
+
store = createStoreLevel(dbPath, name)
|
|
13
15
|
} else {
|
|
14
16
|
console.error("Unknown database " + process.env.DB)
|
|
15
17
|
throw new Error("Unknown database " + process.env.DB)
|
|
@@ -24,4 +26,4 @@ function createDb(dbPath) {
|
|
|
24
26
|
return db
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
export default createDb
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const encoding = require('encoding-down')
|
|
1
|
+
import levelup from 'levelup'
|
|
2
|
+
import leveldown from 'leveldown'
|
|
3
|
+
import subleveldown from 'subleveldown'
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
import Store from '@live-change/db-store-level'
|
|
7
6
|
|
|
8
7
|
const levels = new Map()
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
export default function(dbPath, name) {
|
|
11
10
|
let level = levels.get(dbPath)
|
|
12
11
|
if(!level) {
|
|
13
12
|
level = levelup(leveldown(dbPath))
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import lmdb from 'node-lmdb'
|
|
2
|
+
import fs from 'fs'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import Store from '@live-change/db-store-lmdb'
|
|
5
5
|
|
|
6
6
|
const envs = new Map()
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
export default function(dbPath, name) {
|
|
9
9
|
let env = envs.get(dbPath)
|
|
10
10
|
if(!env) {
|
|
11
11
|
fs.mkdirSync(dbPath)
|