@rpcbase/client 0.62.0 → 0.64.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.62.0",
3
+ "version": "0.64.0",
4
4
  "scripts": {
5
5
  "test": "jest"
6
6
  },
@@ -8,7 +8,7 @@ import _omit from "lodash/omit"
8
8
 
9
9
  import get_uid from "../auth/get_uid"
10
10
 
11
- import cacheStorage from "./cacheStorage"
11
+ // import cacheStorage from "./cacheStorage"
12
12
 
13
13
 
14
14
  const log = debug("rb:rts:useQuery")
@@ -45,7 +45,7 @@ const getUseQuery = (register_query) => (
45
45
  sort = {},
46
46
  } = options
47
47
 
48
- const storageKey = `${uid}.${key}.${model_name}.${JSON.stringify(query)}.${JSON.stringify(projection)}.${JSON.stringify(sort)}`
48
+ // const storageKey = `${uid}.${key}.${model_name}.${JSON.stringify(query)}.${JSON.stringify(projection)}.${JSON.stringify(sort)}`
49
49
 
50
50
  useEffect(() => {
51
51
  if (options.debug) {
@@ -53,27 +53,23 @@ const getUseQuery = (register_query) => (
53
53
  }
54
54
  }, [])
55
55
 
56
- useEffect(() => {
57
- const load = async() => {
58
- const val = await cacheStorage.get(storageKey)
59
- // TODO: rm this
60
- // always initially apply when first load here
61
- if (val) {
62
- console.log("Will set val from cache storage")
63
- setData(val)
64
- setLoading(false)
65
- }
66
- }
67
-
68
- load()
69
- }, [storageKey])
56
+ // useEffect(() => {
57
+ // const load = async() => {
58
+ // const val = await cacheStorage.get(storageKey)
59
+ // // TODO: rm this
60
+ // // always initially apply when first load here
61
+ // if (val) {
62
+ // console.log("Will set val from cache storage")
63
+ // setData(val)
64
+ // setLoading(false)
65
+ // }
66
+ // }
67
+ //
68
+ // load()
69
+ // }, [storageKey])
70
70
 
71
71
  const applyNewData = (newData, context) => {
72
72
  setData(newData)
73
- // write data to storage
74
- // TODO: is there a better way than doing it on every update ?
75
- // should this be throttled
76
- cacheStorage.set(storageKey, newData)
77
73
 
78
74
  if (newData?.length > 0) {
79
75
  lastDocRef.current = newData[newData.length - 1]
@@ -161,7 +157,7 @@ const getUseQuery = (register_query) => (
161
157
  log && log("useQuery cleanup unsubscribe()")
162
158
  unsubscribe()
163
159
  }
164
- }, [JSON.stringify(query), key, storageKey])
160
+ }, [JSON.stringify(query), key])
165
161
 
166
162
 
167
163
  const loadNextPage = useCallback(() => {
package/rts/index.js CHANGED
@@ -184,7 +184,7 @@ export const register_query = (model_name, query, _options, _callback) => {
184
184
  }
185
185
 
186
186
  const key = options.key || ""
187
- const query_key = `${key}${JSON.stringify(query)}`
187
+ const query_key = `${key}${JSON.stringify(query)}${options.projection ? JSON.stringify(options.projection) : ""}`
188
188
  log("registering query with key", key, model_name, query, query_key)
189
189
 
190
190
  // save callback to update hooks
@@ -67,7 +67,6 @@ const run_query = async({model_name, query, query_key, options}, callback) => {
67
67
  return remapped_doc
68
68
  })
69
69
 
70
-
71
70
  if (options.projection) {
72
71
  mapped_docs = mapped_docs.filter((doc) => satisfies_projection(doc, options.projection))
73
72
  }
@@ -30,6 +30,14 @@ test("missing field", () => {
30
30
  })).toBe(false)
31
31
  })
32
32
 
33
+ test("matching and missing field", () => {
34
+ expect(satisfies_projection(doc, {
35
+ field1: true,
36
+ missing_field: 1,
37
+ ...projection
38
+ })).toBe(false)
39
+ })
40
+
33
41
  test("missing nested field", () => {
34
42
  expect(satisfies_projection(doc, {
35
43
  "missing_field.missing_nested": 1,