@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.
- package/build/Collection.js +41 -45
- package/package.json +1 -1
package/build/Collection.js
CHANGED
|
@@ -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,
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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,
|
|
19
|
-
if (!
|
|
20
|
-
|
|
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
|
|
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,
|
|
45
|
-
const subscription = __classPrivateFieldGet(this,
|
|
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,
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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:
|
|
68
|
-
__classPrivateFieldGet(this,
|
|
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,
|
|
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,
|
|
77
|
-
__classPrivateFieldSet(this,
|
|
78
|
-
__classPrivateFieldGet(this,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
138
|
-
__classPrivateFieldGet(this,
|
|
139
|
-
__classPrivateFieldGet(this,
|
|
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,
|
|
147
|
-
__classPrivateFieldGet(this,
|
|
143
|
+
__classPrivateFieldGet(this, _CollectionObservable_subscriptions, "f").forEach(s => s.unsubscribe());
|
|
144
|
+
__classPrivateFieldGet(this, _CollectionObservable_subscriptions, "f").clear();
|
|
148
145
|
}
|
|
149
|
-
__classPrivateFieldSet(this,
|
|
150
|
-
__classPrivateFieldGet(this,
|
|
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,
|
|
152
|
+
__classPrivateFieldGet(this, _CollectionObservable_subscriptions, "f").add(sub);
|
|
156
153
|
}
|
|
157
154
|
reload() {
|
|
158
|
-
__classPrivateFieldGet(this,
|
|
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,
|
|
166
|
-
__classPrivateFieldGet(this,
|
|
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
|
-
|
|
218
|
+
_CollectionObservable_$state = new WeakMap(), _CollectionObservable_subscriptions = new WeakMap(), _CollectionObservable_state = new WeakMap(), _CollectionObservable_next_cursor = new WeakMap();
|