@livequery/client 1.0.25 → 1.0.26

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.
Files changed (2) hide show
  1. package/build/Collection.js +41 -45
  2. package/package.json +1 -1
@@ -8,18 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
12
- if (!privateMap.has(receiver)) {
13
- throw new TypeError("attempted to set private field on non-instance");
14
- }
15
- privateMap.set(receiver, value);
16
- return value;
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
17
16
  };
18
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
19
- if (!privateMap.has(receiver)) {
20
- throw new TypeError("attempted to get private field on non-instance");
21
- }
22
- return privateMap.get(receiver);
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
23
21
  };
24
22
  var __rest = (this && this.__rest) || function (s, e) {
25
23
  var t = {};
@@ -32,7 +30,7 @@ var __rest = (this && this.__rest) || function (s, e) {
32
30
  }
33
31
  return t;
34
32
  };
35
- var _$state, _subscriptions, _state, _next_cursor;
33
+ var _CollectionObservable_$state, _CollectionObservable_subscriptions, _CollectionObservable_state, _CollectionObservable_next_cursor;
36
34
  Object.defineProperty(exports, "__esModule", { value: true });
37
35
  exports.CollectionObservable = void 0;
38
36
  const rxjs_1 = require("rxjs");
@@ -41,21 +39,21 @@ const operators_1 = require("rxjs/operators");
41
39
  class CollectionObservable extends rxjs_1.Observable {
42
40
  constructor(ref, collection_options) {
43
41
  super(o => {
44
- __classPrivateFieldSet(this, _state, { items: [], options: collection_options.filters, has_more: false });
45
- const subscription = __classPrivateFieldGet(this, _$state).subscribe(o);
42
+ __classPrivateFieldSet(this, _CollectionObservable_state, { items: [], options: collection_options.filters, has_more: false }, "f");
43
+ const subscription = __classPrivateFieldGet(this, _CollectionObservable_$state, "f").subscribe(o);
46
44
  const auto_reload_interval = collection_options.reload_interval && setInterval(() => this.reload(), collection_options.reload_interval);
47
45
  return () => {
48
- __classPrivateFieldGet(this, _subscriptions).forEach(s => s.unsubscribe());
46
+ __classPrivateFieldGet(this, _CollectionObservable_subscriptions, "f").forEach(s => s.unsubscribe());
49
47
  subscription.unsubscribe();
50
48
  clearInterval(auto_reload_interval);
51
49
  };
52
50
  });
53
51
  this.ref = ref;
54
52
  this.collection_options = collection_options;
55
- _$state.set(this, new rxjs_1.Subject());
56
- _subscriptions.set(this, new Set());
57
- _state.set(this, void 0);
58
- _next_cursor.set(this, null);
53
+ _CollectionObservable_$state.set(this, new rxjs_1.Subject());
54
+ _CollectionObservable_subscriptions.set(this, new Set());
55
+ _CollectionObservable_state.set(this, void 0);
56
+ _CollectionObservable_next_cursor.set(this, null);
59
57
  if (ref.startsWith('/') || ref.endsWith('/'))
60
58
  throw 'INVAILD_REF_FORMAT';
61
59
  const refs = ref.split('/');
@@ -64,22 +62,22 @@ class CollectionObservable extends rxjs_1.Observable {
64
62
  this.document_id = this.is_collection_ref ? null : refs[refs.length - 1];
65
63
  }
66
64
  push_item(data) {
67
- const item = Object.assign(Object.assign({ __adding: false, __updating: true, __removing: false }, data), { __remove: () => this.remove(data === null || data === void 0 ? void 0 : data.id), __trigger: (name, payload) => this.trigger(name, payload, data === null || data === void 0 ? void 0 : data.id), __update: (payload) => this.update(Object.assign({ id: data === null || data === void 0 ? void 0 : data.id }, payload)) });
68
- __classPrivateFieldGet(this, _state).items.push(item);
65
+ const item = Object.assign(Object.assign({ __adding: false, __updating: false, __removing: false }, data), { __remove: () => this.remove(data === null || data === void 0 ? void 0 : data.id), __trigger: (name, payload) => this.trigger(name, payload, data === null || data === void 0 ? void 0 : data.id), __update: (payload) => this.update(Object.assign({ id: data === null || data === void 0 ? void 0 : data.id }, payload)) });
66
+ __classPrivateFieldGet(this, _CollectionObservable_state, "f").items.push(item);
69
67
  }
70
68
  sync(stream) {
71
69
  var _a, _b, _c, _d;
72
70
  for (const { data, error } of stream) {
73
71
  // Error & paging
74
- error && (__classPrivateFieldGet(this, _state).error = error);
72
+ error && (__classPrivateFieldGet(this, _CollectionObservable_state, "f").error = error);
75
73
  if (((_a = data === null || data === void 0 ? void 0 : data.paging) === null || _a === void 0 ? void 0 : _a.n) == 0) {
76
- __classPrivateFieldGet(this, _state).has_more = (_b = data === null || data === void 0 ? void 0 : data.paging) === null || _b === void 0 ? void 0 : _b.has_more;
77
- __classPrivateFieldSet(this, _next_cursor, (_c = data === null || data === void 0 ? void 0 : data.paging) === null || _c === void 0 ? void 0 : _c.next_cursor);
78
- __classPrivateFieldGet(this, _state).loading = false;
74
+ __classPrivateFieldGet(this, _CollectionObservable_state, "f").has_more = (_b = data === null || data === void 0 ? void 0 : data.paging) === null || _b === void 0 ? void 0 : _b.has_more;
75
+ __classPrivateFieldSet(this, _CollectionObservable_next_cursor, (_c = data === null || data === void 0 ? void 0 : data.paging) === null || _c === void 0 ? void 0 : _c.next_cursor, "f");
76
+ __classPrivateFieldGet(this, _CollectionObservable_state, "f").loading = false;
79
77
  }
80
78
  // Sync
81
79
  for (const { data: payload, type } of (data === null || data === void 0 ? void 0 : data.changes) || []) {
82
- const index = __classPrivateFieldGet(this, _state).items.findIndex(item => item.id == payload.id);
80
+ const index = __classPrivateFieldGet(this, _CollectionObservable_state, "f").items.findIndex(item => item.id == payload.id);
83
81
  if (index == -1 && type == 'added') {
84
82
  if (
85
83
  // Is first value from HTTP query
@@ -87,14 +85,14 @@ class CollectionObservable extends rxjs_1.Observable {
87
85
  || (
88
86
  // Is realtime update that match filters
89
87
  Object
90
- .keys(__classPrivateFieldGet(this, _state).options || {})
88
+ .keys(__classPrivateFieldGet(this, _CollectionObservable_state, "f").options || {})
91
89
  .filter(key => !key.includes('_'))
92
90
  .every(key => {
93
91
  var _a;
94
92
  try {
95
93
  const [field, expression] = key.split(':');
96
94
  const a = payload[field];
97
- const b = (_a = __classPrivateFieldGet(this, _state).options) === null || _a === void 0 ? void 0 : _a[field];
95
+ const b = (_a = __classPrivateFieldGet(this, _CollectionObservable_state, "f").options) === null || _a === void 0 ? void 0 : _a[field];
98
96
  if (!expression)
99
97
  return a == b;
100
98
  if (expression == 'ne')
@@ -126,44 +124,43 @@ class CollectionObservable extends rxjs_1.Observable {
126
124
  }
127
125
  if (index >= 0) {
128
126
  if (type == 'added' || type == 'modified') {
129
- __classPrivateFieldGet(this, _state).items[index] = Object.assign(Object.assign(Object.assign({}, __classPrivateFieldGet(this, _state).items[index]), { __adding: false, __updating: false, __removing: false }), payload);
127
+ __classPrivateFieldGet(this, _CollectionObservable_state, "f").items[index] = Object.assign(Object.assign(Object.assign({}, __classPrivateFieldGet(this, _CollectionObservable_state, "f").items[index]), { __adding: false, __updating: false, __removing: false }), payload);
130
128
  }
131
129
  if (type == 'removed') {
132
- __classPrivateFieldGet(this, _state).items.splice(index, 1);
130
+ __classPrivateFieldGet(this, _CollectionObservable_state, "f").items.splice(index, 1);
133
131
  }
134
132
  }
135
133
  }
136
134
  }
137
- const sort_function = get_sort_function_1.get_sort_function(__classPrivateFieldGet(this, _state).items[0], __classPrivateFieldGet(this, _state).options._order_by || 'created_at', __classPrivateFieldGet(this, _state).options._sort || 'desc');
138
- __classPrivateFieldGet(this, _state).items = __classPrivateFieldGet(this, _state).items.sort(sort_function);
139
- __classPrivateFieldGet(this, _$state).next(__classPrivateFieldGet(this, _state));
135
+ const sort_function = (0, get_sort_function_1.get_sort_function)(__classPrivateFieldGet(this, _CollectionObservable_state, "f").items[0], __classPrivateFieldGet(this, _CollectionObservable_state, "f").options._order_by || 'created_at', __classPrivateFieldGet(this, _CollectionObservable_state, "f").options._sort || 'desc');
136
+ __classPrivateFieldGet(this, _CollectionObservable_state, "f").items = __classPrivateFieldGet(this, _CollectionObservable_state, "f").items.sort(sort_function);
137
+ __classPrivateFieldGet(this, _CollectionObservable_$state, "f").next(__classPrivateFieldGet(this, _CollectionObservable_state, "f"));
140
138
  }
141
139
  fetch_data(options = {}, flush = false) {
142
- console.log({ ref: this.ref, options });
143
140
  if (!this.ref)
144
141
  return;
145
142
  if (flush) {
146
- __classPrivateFieldGet(this, _subscriptions).forEach(s => s.unsubscribe());
147
- __classPrivateFieldGet(this, _subscriptions).clear();
143
+ __classPrivateFieldGet(this, _CollectionObservable_subscriptions, "f").forEach(s => s.unsubscribe());
144
+ __classPrivateFieldGet(this, _CollectionObservable_subscriptions, "f").clear();
148
145
  }
149
- __classPrivateFieldSet(this, _state, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _state)), { items: flush ? [] : __classPrivateFieldGet(this, _state).items, error: null, loading: true, options }));
150
- __classPrivateFieldGet(this, _$state).next(__classPrivateFieldGet(this, _state));
146
+ __classPrivateFieldSet(this, _CollectionObservable_state, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _CollectionObservable_state, "f")), { items: flush ? [] : __classPrivateFieldGet(this, _CollectionObservable_state, "f").items, error: null, loading: true, options }), "f");
147
+ __classPrivateFieldGet(this, _CollectionObservable_$state, "f").next(__classPrivateFieldGet(this, _CollectionObservable_state, "f"));
151
148
  const query = this.collection_options.transporter.query(this.ref, options);
152
149
  const sub = Object.assign(query
153
- .pipe(operators_1.bufferTime(this.collection_options.sync_delay || 500), operators_1.filter(stream => stream.length > 0))
150
+ .pipe((0, operators_1.bufferTime)(this.collection_options.sync_delay || 500), (0, operators_1.filter)(stream => stream.length > 0))
154
151
  .subscribe(data => this.sync(data)), { reload: query.reload });
155
- __classPrivateFieldGet(this, _subscriptions).add(sub);
152
+ __classPrivateFieldGet(this, _CollectionObservable_subscriptions, "f").add(sub);
156
153
  }
157
154
  reload() {
158
- __classPrivateFieldGet(this, _subscriptions).forEach(s => s.reload());
155
+ __classPrivateFieldGet(this, _CollectionObservable_subscriptions, "f").forEach(s => s.reload());
159
156
  }
160
157
  reset() {
161
158
  this.fetch_data({}, true);
162
159
  }
163
160
  fetch_more() {
164
161
  var _a;
165
- const options = (_a = __classPrivateFieldGet(this, _state)) === null || _a === void 0 ? void 0 : _a.options;
166
- __classPrivateFieldGet(this, _next_cursor) && (options._cursor = __classPrivateFieldGet(this, _next_cursor));
162
+ const options = (_a = __classPrivateFieldGet(this, _CollectionObservable_state, "f")) === null || _a === void 0 ? void 0 : _a.options;
163
+ __classPrivateFieldGet(this, _CollectionObservable_next_cursor, "f") && (options._cursor = __classPrivateFieldGet(this, _CollectionObservable_next_cursor, "f"));
167
164
  this.fetch_data(options);
168
165
  }
169
166
  filter(filters) {
@@ -212,11 +209,10 @@ class CollectionObservable extends rxjs_1.Observable {
212
209
  trigger(name, payload, trigger_document_id) {
213
210
  return __awaiter(this, void 0, void 0, function* () {
214
211
  const id = trigger_document_id || this.document_id;
215
- console.log({ id });
216
212
  const ref = `${this.collection_ref}${id ? `/${id}` : ''}`;
217
213
  return yield this.collection_options.transporter.trigger(ref, name, {}, payload);
218
214
  });
219
215
  }
220
216
  }
221
217
  exports.CollectionObservable = CollectionObservable;
222
- _$state = new WeakMap(), _subscriptions = new WeakMap(), _state = new WeakMap(), _next_cursor = new WeakMap();
218
+ _CollectionObservable_$state = new WeakMap(), _CollectionObservable_subscriptions = new WeakMap(), _CollectionObservable_state = new WeakMap(), _CollectionObservable_next_cursor = new WeakMap();
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "repository": {
4
4
  "url": "https://github.com/livequery/client"
5
5
  },
6
- "version": "1.0.25",
6
+ "version": "1.0.26",
7
7
  "description": "",
8
8
  "main": "build/index.js",
9
9
  "types": "build/index.d.ts",