@livequery/client 2.0.25 → 2.0.31

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.
@@ -18,6 +18,7 @@ export type SmartQueryItem<T> = T & {
18
18
  toJson: () => T;
19
19
  };
20
20
  export type CollectionStream<T extends LivequeryBaseEntity = LivequeryBaseEntity> = {
21
+ n: number;
21
22
  items: SmartQueryItem<T>[];
22
23
  paging: Partial<Paging>;
23
24
  loading?: LoadingIndicator;
@@ -15,6 +15,7 @@ export class CollectionObservable extends BehaviorSubject {
15
15
  }
16
16
  constructor(ref, collection_options) {
17
17
  super({
18
+ n: 0,
18
19
  items: [],
19
20
  loading: false,
20
21
  paging: {},
@@ -50,6 +51,7 @@ export class CollectionObservable extends BehaviorSubject {
50
51
  for (const { data, error, code, message, } of stream) {
51
52
  if (from == 'request') {
52
53
  state.loading = false;
54
+ state.n = state.n + 1;
53
55
  }
54
56
  // Error & paging
55
57
  if (error) {
@@ -75,13 +77,12 @@ export class CollectionObservable extends BehaviorSubject {
75
77
  // Is realtime update that match filters
76
78
  from == 'realtime' && Object
77
79
  .keys(state.options || {})
78
- .filter(key => !key.includes('_'))
80
+ .filter(key => !key.startsWith(':'))
79
81
  .every(key => {
80
82
  const [field, expression] = key.split(':');
81
83
  const a = payload[field];
82
84
  const b = state.options?.[field];
83
85
  const map = {
84
- 'default': () => a == b,
85
86
  eq: () => a == b,
86
87
  ne: () => a != b,
87
88
  lt: () => typeof a == 'number' && typeof b == 'number' && a < b,
@@ -93,12 +94,12 @@ export class CollectionObservable extends BehaviorSubject {
93
94
  between: () => typeof a == 'number' && Array.isArray(b) && typeof b[0] == 'number' && b[0] <= a && typeof b[1] == 'number' && a <= b[1]
94
95
  };
95
96
  try {
96
- const fn = map[expression || 'default'];
97
- if (fn)
98
- return fn();
97
+ const expr = expression == '' ? 'eq' : expression;
98
+ if (map[expr])
99
+ return map[expr]();
99
100
  }
100
101
  catch (e) { }
101
- return false;
102
+ return true;
102
103
  }))) {
103
104
  const item = {
104
105
  ...payload,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "repository": {
5
5
  "url": "https://github.com/livequery/client"
6
6
  },
7
- "version": "2.0.25",
7
+ "version": "2.0.31",
8
8
  "description": "",
9
9
  "main": "build/index.js",
10
10
  "types": "build/index.d.ts",