@rpcbase/client 0.93.0 → 0.95.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/auth/SignUp/index.js +1 -1
- package/auth/index.js +9 -2
- package/auth/sign_out.js +2 -1
- package/package.json +1 -1
- package/rts/index.js +1 -3
- package/rts/store/get_collection.js +2 -1
- package/rts/store/index.js +3 -3
- package/rts/store/satisfies_projection.test.js +8 -0
- package/rts/store/update_docs.js +17 -17
package/auth/SignUp/index.js
CHANGED
|
@@ -35,7 +35,7 @@ const SignUp = ({
|
|
|
35
35
|
set_tenant_id(user_id.slice(0, 8))
|
|
36
36
|
set_is_signed_in(true)
|
|
37
37
|
|
|
38
|
-
// we must now reconnect on the websocket as we
|
|
38
|
+
// we must now reconnect on the websocket as we have a new cookie
|
|
39
39
|
rts_reconnect()
|
|
40
40
|
onSuccess()
|
|
41
41
|
page(onSuccessRedirect)
|
package/auth/index.js
CHANGED
|
@@ -107,10 +107,17 @@ export const session_restrict = (ctx, next) => {
|
|
|
107
107
|
|
|
108
108
|
|
|
109
109
|
export const get_uid = () => __user_id
|
|
110
|
-
export const set_uid = (val) =>
|
|
110
|
+
export const set_uid = (val) => {
|
|
111
|
+
__user_id = val
|
|
112
|
+
const tenant_id_prefix = val.slice(0, 8)
|
|
113
|
+
localStorage.setItem(uid_storage_key(tenant_id_prefix), val)
|
|
114
|
+
}
|
|
111
115
|
|
|
112
116
|
export const get_tenant_id = () => __tenant_id
|
|
113
|
-
export const set_tenant_id = (val) =>
|
|
117
|
+
export const set_tenant_id = (val) => {
|
|
118
|
+
__tenant_id = val
|
|
119
|
+
localStorage.setItem(LAST_TENANT_KEY, val)
|
|
120
|
+
}
|
|
114
121
|
|
|
115
122
|
export const set_is_signed_in = (val) => __is_authenticated = val
|
|
116
123
|
|
package/auth/sign_out.js
CHANGED
package/package.json
CHANGED
package/rts/index.js
CHANGED
|
@@ -27,7 +27,6 @@ const _local_txn = []
|
|
|
27
27
|
// TODO: when server disconnects / crashes and loses all server side stored queries
|
|
28
28
|
// the clients must reconnect and re-register those queries, or the page will need to be hard refreshed
|
|
29
29
|
|
|
30
|
-
|
|
31
30
|
// add_local_txn
|
|
32
31
|
// when a request is made to the server, we generate (or send if provided) the txn_id
|
|
33
32
|
// if the array becomes longer than the default buffer length we shift the array
|
|
@@ -63,7 +62,7 @@ const dispatch_query_payload = (payload) => {
|
|
|
63
62
|
|
|
64
63
|
let data
|
|
65
64
|
try {
|
|
66
|
-
// TODO: zstd
|
|
65
|
+
// TODO: zstd decompression here
|
|
67
66
|
data = JSON.parse(payload.data_buf)
|
|
68
67
|
} catch (err) {
|
|
69
68
|
console.log("Error", err)
|
|
@@ -177,7 +176,6 @@ export const register_query = (model_name, query, _options, _callback) => {
|
|
|
177
176
|
|
|
178
177
|
log("register_query", {model_name, query, options, callback})
|
|
179
178
|
|
|
180
|
-
|
|
181
179
|
if (!_socket) {
|
|
182
180
|
log("register_query: trying to use null socket", {model_name, query})
|
|
183
181
|
return
|
|
@@ -25,7 +25,8 @@ const get_collection = (col_name) => {
|
|
|
25
25
|
if (_cols_store[col_name]) {
|
|
26
26
|
return _cols_store[col_name]
|
|
27
27
|
} else {
|
|
28
|
-
|
|
28
|
+
// https://pouchdb.com/api.html#create_database
|
|
29
|
+
const col = new PouchDB(col_name, { adapter: "indexeddb", revs_limit: 1 })
|
|
29
30
|
_cols_store[col_name] = col
|
|
30
31
|
|
|
31
32
|
return col
|
package/rts/store/index.js
CHANGED
|
@@ -29,8 +29,6 @@ const log = debug("rb:rts:store")
|
|
|
29
29
|
//
|
|
30
30
|
// fn.cancel()
|
|
31
31
|
//
|
|
32
|
-
// console.log("GOT FN", fn)
|
|
33
|
-
//
|
|
34
32
|
// console.log("got res", res)
|
|
35
33
|
// _cols_store[col_name].getIndexes().then(function (result) {
|
|
36
34
|
// console.log("got indexes", result)
|
|
@@ -70,7 +68,9 @@ const run_query = async({model_name, query, query_key, options}, callback) => {
|
|
|
70
68
|
})
|
|
71
69
|
|
|
72
70
|
if (options.projection) {
|
|
73
|
-
mapped_docs = mapped_docs.filter((doc) =>
|
|
71
|
+
mapped_docs = mapped_docs.filter((doc) => {
|
|
72
|
+
return satisfies_projection(doc, options.projection)
|
|
73
|
+
})
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
callback(null, mapped_docs, {source: "cache"})
|
|
@@ -48,3 +48,11 @@ test("missing nested field", () => {
|
|
|
48
48
|
test("empty", () => {
|
|
49
49
|
expect(satisfies_projection(doc, {field1: 1})).toBe(true)
|
|
50
50
|
})
|
|
51
|
+
|
|
52
|
+
test("no fields, _id only, empty projection", () => {
|
|
53
|
+
expect(satisfies_projection({_id: "1012"}, {})).toBe(true)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test("no fields, _id only, mismatching projection", () => {
|
|
57
|
+
expect(satisfies_projection({_id: "1012"}, {doesntexist: 1})).toBe(false)
|
|
58
|
+
})
|
package/rts/store/update_docs.js
CHANGED
|
@@ -7,38 +7,38 @@ const update_docs = async(model_name, data) => {
|
|
|
7
7
|
|
|
8
8
|
const all_ids = data.map((doc) => doc._id)
|
|
9
9
|
|
|
10
|
-
// console.log("will update cache", model_name, data, all_ids)
|
|
11
|
-
|
|
12
|
-
// console.time("find")
|
|
13
|
-
|
|
14
|
-
// TODO:
|
|
15
|
-
// there is also a bulk get which could have different performance than find, try both
|
|
16
|
-
// https://pouchdb.com/api.html#bulk_get
|
|
17
|
-
|
|
18
10
|
// https://github.com/pouchdb/pouchdb/tree/master/packages/node_modules/pouchdb-find#dbcreateindexindex--callback
|
|
19
11
|
const {docs: current_docs} = await collection.find({
|
|
20
12
|
selector: {_id: {$in: all_ids}},
|
|
21
13
|
fields: ["_id", "_rev"],
|
|
22
14
|
})
|
|
23
15
|
|
|
24
|
-
|
|
16
|
+
const current_docs_by_id = current_docs.reduce((acc, val) => {
|
|
17
|
+
acc[val._id] = val
|
|
18
|
+
return acc
|
|
19
|
+
}, {})
|
|
20
|
+
|
|
21
|
+
// WARNING: tmp
|
|
22
|
+
// we don't need to remove docs that aren't present in data because queries are refined with find
|
|
25
23
|
|
|
26
24
|
const revs_map = {}
|
|
27
25
|
current_docs.forEach((doc) => revs_map[doc._id] = doc._rev)
|
|
28
26
|
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
const new_docs = data.map((mongo_doc) => {
|
|
28
|
+
const current_doc = current_docs_by_id[mongo_doc._id] || {}
|
|
29
|
+
|
|
30
|
+
const op = Object.entries(mongo_doc)
|
|
31
|
+
.reduce((new_doc, [key, value]) => {
|
|
32
|
+
let new_key = key !== "_id" && key.startsWith('_') ? `$_${key}` : key
|
|
33
|
+
new_doc[new_key] = value
|
|
34
|
+
return new_doc
|
|
35
|
+
}, current_doc)
|
|
35
36
|
|
|
36
37
|
op._rev = revs_map[mongo_doc._id]
|
|
37
38
|
return op
|
|
38
39
|
})
|
|
39
40
|
|
|
40
|
-
await collection.bulkDocs(
|
|
41
|
-
// console.timeEnd("find")
|
|
41
|
+
await collection.bulkDocs(new_docs)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export default update_docs
|