@live-change/db-web 0.9.227 → 0.9.229
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/lib/dbDao.js +24 -33
- package/package.json +7 -7
package/lib/dbDao.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import ReactiveDao from "@live-change/dao"
|
|
2
2
|
|
|
3
|
-
function
|
|
3
|
+
function observableFromAsync(fn) {
|
|
4
|
+
const obs = new ReactiveDao.ObservableValue(undefined)
|
|
5
|
+
Promise.resolve().then(() => fn()).then(
|
|
6
|
+
value => obs.set(value),
|
|
7
|
+
error => obs.error(error)
|
|
8
|
+
)
|
|
9
|
+
return obs
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function getDatabaseStorageStats(server, dbName) {
|
|
4
13
|
const db = server.databases.get(dbName)
|
|
5
14
|
if(!db) throw new Error('databaseNotFound')
|
|
6
|
-
const stats = db.storageStats()
|
|
15
|
+
const stats = await db.storageStats()
|
|
7
16
|
return {
|
|
8
17
|
env: { available: false },
|
|
9
18
|
stores: stats.stores,
|
|
@@ -12,7 +21,7 @@ function getDatabaseStorageStats(server, dbName) {
|
|
|
12
21
|
}
|
|
13
22
|
}
|
|
14
23
|
|
|
15
|
-
function getTableStorageStats(server, dbName, tableName) {
|
|
24
|
+
async function getTableStorageStats(server, dbName, tableName) {
|
|
16
25
|
const db = server.databases.get(dbName)
|
|
17
26
|
if(!db) throw new Error('databaseNotFound')
|
|
18
27
|
const table = db.table(tableName)
|
|
@@ -20,7 +29,7 @@ function getTableStorageStats(server, dbName, tableName) {
|
|
|
20
29
|
return table.storeStats()
|
|
21
30
|
}
|
|
22
31
|
|
|
23
|
-
function getIndexStorageStats(server, dbName, indexName) {
|
|
32
|
+
async function getIndexStorageStats(server, dbName, indexName) {
|
|
24
33
|
const db = server.databases.get(dbName)
|
|
25
34
|
if(!db) throw new Error('databaseNotFound')
|
|
26
35
|
const config = db.config.indexes[indexName]
|
|
@@ -28,7 +37,7 @@ function getIndexStorageStats(server, dbName, indexName) {
|
|
|
28
37
|
return db.storageStatsForConfig('index', indexName, config)
|
|
29
38
|
}
|
|
30
39
|
|
|
31
|
-
function getLogStorageStats(server, dbName, logName) {
|
|
40
|
+
async function getLogStorageStats(server, dbName, logName) {
|
|
32
41
|
const db = server.databases.get(dbName)
|
|
33
42
|
if(!db) throw new Error('databaseNotFound')
|
|
34
43
|
const log = db.log(logName)
|
|
@@ -761,43 +770,25 @@ function localReads(server, scriptContext) {
|
|
|
761
770
|
}
|
|
762
771
|
},
|
|
763
772
|
databaseStorageStats: {
|
|
764
|
-
observable: (dbName) =>
|
|
765
|
-
try {
|
|
766
|
-
return new ReactiveDao.ObservableValue(getDatabaseStorageStats(server, dbName))
|
|
767
|
-
} catch(e) {
|
|
768
|
-
return new ReactiveDao.ObservableError(e.message || e)
|
|
769
|
-
}
|
|
770
|
-
},
|
|
773
|
+
observable: (dbName) => observableFromAsync(() => getDatabaseStorageStats(server, dbName)),
|
|
771
774
|
get: async (dbName) => getDatabaseStorageStats(server, dbName)
|
|
772
775
|
},
|
|
773
776
|
tableStorageStats: {
|
|
774
|
-
observable: (dbName, tableName) =>
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
} catch(e) {
|
|
778
|
-
return new ReactiveDao.ObservableError(e.message || e)
|
|
779
|
-
}
|
|
780
|
-
},
|
|
777
|
+
observable: (dbName, tableName) => observableFromAsync(
|
|
778
|
+
() => getTableStorageStats(server, dbName, tableName)
|
|
779
|
+
),
|
|
781
780
|
get: async (dbName, tableName) => getTableStorageStats(server, dbName, tableName)
|
|
782
781
|
},
|
|
783
782
|
indexStorageStats: {
|
|
784
|
-
observable: (dbName, indexName) =>
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
} catch(e) {
|
|
788
|
-
return new ReactiveDao.ObservableError(e.message || e)
|
|
789
|
-
}
|
|
790
|
-
},
|
|
783
|
+
observable: (dbName, indexName) => observableFromAsync(
|
|
784
|
+
() => getIndexStorageStats(server, dbName, indexName)
|
|
785
|
+
),
|
|
791
786
|
get: async (dbName, indexName) => getIndexStorageStats(server, dbName, indexName)
|
|
792
787
|
},
|
|
793
788
|
logStorageStats: {
|
|
794
|
-
observable: (dbName, logName) =>
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
} catch(e) {
|
|
798
|
-
return new ReactiveDao.ObservableError(e.message || e)
|
|
799
|
-
}
|
|
800
|
-
},
|
|
789
|
+
observable: (dbName, logName) => observableFromAsync(
|
|
790
|
+
() => getLogStorageStats(server, dbName, logName)
|
|
791
|
+
),
|
|
801
792
|
get: async (dbName, logName) => getLogStorageStats(server, dbName, logName)
|
|
802
793
|
},
|
|
803
794
|
query: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/db-web",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.229",
|
|
4
4
|
"author": {
|
|
5
5
|
"email": "michal@laszczewski.com",
|
|
6
6
|
"name": "Michał Łaszczewski",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
},
|
|
30
30
|
"type": "module",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@live-change/dao": "^0.9.
|
|
33
|
-
"@live-change/db": "^0.9.
|
|
34
|
-
"@live-change/db-store-indexeddb": "^0.9.
|
|
35
|
-
"@live-change/db-store-localstorage": "^0.9.
|
|
36
|
-
"@live-change/db-store-rbtree": "^0.9.
|
|
32
|
+
"@live-change/dao": "^0.9.229",
|
|
33
|
+
"@live-change/db": "^0.9.229",
|
|
34
|
+
"@live-change/db-store-indexeddb": "^0.9.229",
|
|
35
|
+
"@live-change/db-store-localstorage": "^0.9.229",
|
|
36
|
+
"@live-change/db-store-rbtree": "^0.9.229",
|
|
37
37
|
"debug": "^4.3.4"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "10de6af051ea567a0ae917d34ac08378da5465ea"
|
|
40
40
|
}
|