@livequery/client 1.0.27 → 1.0.28
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.d.ts +3 -3
- package/build/Collection.js +38 -43
- package/build/index.js +5 -1
- package/package.json +2 -1
package/build/Collection.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { ErrorInfo, QueryOption, Transporter } from '@livequery/types';
|
|
3
|
-
export
|
|
3
|
+
export type CollectionOption<T = any> = {
|
|
4
4
|
transporter: Transporter;
|
|
5
5
|
sync_delay?: number;
|
|
6
6
|
filters?: Partial<QueryOption<T>>;
|
|
7
7
|
reload_interval?: number;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
type CollectionStream<T> = {
|
|
10
10
|
items: SmartQueryItem<T>[];
|
|
11
11
|
error?: ErrorInfo;
|
|
12
12
|
has_more: boolean;
|
|
13
13
|
loading?: boolean;
|
|
14
14
|
options: Partial<QueryOption<T>>;
|
|
15
15
|
};
|
|
16
|
-
export
|
|
16
|
+
export type SmartQueryItem<T> = T & {
|
|
17
17
|
__removing: boolean;
|
|
18
18
|
__updating: boolean;
|
|
19
19
|
__adding: boolean;
|
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,30 +30,29 @@ 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");
|
|
39
|
-
const get_sort_function_1 = require("./helpers/get_sort_function");
|
|
40
37
|
const operators_1 = require("rxjs/operators");
|
|
41
38
|
class CollectionObservable extends rxjs_1.Observable {
|
|
42
39
|
constructor(ref, collection_options) {
|
|
43
40
|
super(o => {
|
|
44
|
-
__classPrivateFieldSet(this,
|
|
45
|
-
const subscription = __classPrivateFieldGet(this,
|
|
41
|
+
__classPrivateFieldSet(this, _CollectionObservable_state, { items: [], options: collection_options.filters, has_more: false }, "f");
|
|
42
|
+
const subscription = __classPrivateFieldGet(this, _CollectionObservable_$state, "f").subscribe(o);
|
|
46
43
|
const auto_reload_interval = collection_options.reload_interval && setInterval(() => this.reload(), collection_options.reload_interval);
|
|
47
44
|
return () => {
|
|
48
|
-
__classPrivateFieldGet(this,
|
|
45
|
+
__classPrivateFieldGet(this, _CollectionObservable_subscriptions, "f").forEach(s => s.unsubscribe());
|
|
49
46
|
subscription.unsubscribe();
|
|
50
47
|
clearInterval(auto_reload_interval);
|
|
51
48
|
};
|
|
52
49
|
});
|
|
53
50
|
this.ref = ref;
|
|
54
51
|
this.collection_options = collection_options;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
_CollectionObservable_$state.set(this, new rxjs_1.Subject());
|
|
53
|
+
_CollectionObservable_subscriptions.set(this, new Set());
|
|
54
|
+
_CollectionObservable_state.set(this, void 0);
|
|
55
|
+
_CollectionObservable_next_cursor.set(this, null);
|
|
59
56
|
if (ref.startsWith('/') || ref.endsWith('/'))
|
|
60
57
|
throw 'INVAILD_REF_FORMAT';
|
|
61
58
|
const refs = ref.split('/');
|
|
@@ -65,21 +62,21 @@ class CollectionObservable extends rxjs_1.Observable {
|
|
|
65
62
|
}
|
|
66
63
|
push_item(data) {
|
|
67
64
|
const item = Object.assign(Object.assign({}, data), { __adding: false, __updating: false, __removing: false, __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(Object.assign({}, payload), { id: data === null || data === void 0 ? void 0 : data.id })) });
|
|
68
|
-
__classPrivateFieldGet(this,
|
|
65
|
+
__classPrivateFieldGet(this, _CollectionObservable_state, "f").items.push(item);
|
|
69
66
|
}
|
|
70
67
|
sync(stream) {
|
|
71
68
|
var _a, _b, _c, _d;
|
|
72
69
|
for (const { data, error } of stream) {
|
|
73
70
|
// Error & paging
|
|
74
|
-
error && (__classPrivateFieldGet(this,
|
|
71
|
+
error && (__classPrivateFieldGet(this, _CollectionObservable_state, "f").error = error);
|
|
75
72
|
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,
|
|
73
|
+
__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;
|
|
74
|
+
__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");
|
|
75
|
+
__classPrivateFieldGet(this, _CollectionObservable_state, "f").loading = false;
|
|
79
76
|
}
|
|
80
77
|
// Sync
|
|
81
78
|
for (const { data: payload, type } of (data === null || data === void 0 ? void 0 : data.changes) || []) {
|
|
82
|
-
const index = __classPrivateFieldGet(this,
|
|
79
|
+
const index = __classPrivateFieldGet(this, _CollectionObservable_state, "f").items.findIndex(item => item.id == payload.id);
|
|
83
80
|
if (index == -1 && type == 'added') {
|
|
84
81
|
if (
|
|
85
82
|
// Is first value from HTTP query
|
|
@@ -87,14 +84,14 @@ class CollectionObservable extends rxjs_1.Observable {
|
|
|
87
84
|
|| (
|
|
88
85
|
// Is realtime update that match filters
|
|
89
86
|
Object
|
|
90
|
-
.keys(__classPrivateFieldGet(this,
|
|
87
|
+
.keys(__classPrivateFieldGet(this, _CollectionObservable_state, "f").options || {})
|
|
91
88
|
.filter(key => !key.includes('_'))
|
|
92
89
|
.every(key => {
|
|
93
90
|
var _a;
|
|
94
91
|
try {
|
|
95
92
|
const [field, expression] = key.split(':');
|
|
96
93
|
const a = payload[field];
|
|
97
|
-
const b = (_a = __classPrivateFieldGet(this,
|
|
94
|
+
const b = (_a = __classPrivateFieldGet(this, _CollectionObservable_state, "f").options) === null || _a === void 0 ? void 0 : _a[field];
|
|
98
95
|
if (!expression)
|
|
99
96
|
return a == b;
|
|
100
97
|
if (expression == 'ne')
|
|
@@ -126,43 +123,41 @@ class CollectionObservable extends rxjs_1.Observable {
|
|
|
126
123
|
}
|
|
127
124
|
if (index >= 0) {
|
|
128
125
|
if (type == 'added' || type == 'modified') {
|
|
129
|
-
__classPrivateFieldGet(this,
|
|
126
|
+
__classPrivateFieldGet(this, _CollectionObservable_state, "f").items[index] = Object.assign(Object.assign(Object.assign({}, __classPrivateFieldGet(this, _CollectionObservable_state, "f").items[index]), payload), { __adding: false, __updating: false, __removing: false });
|
|
130
127
|
}
|
|
131
128
|
if (type == 'removed') {
|
|
132
|
-
__classPrivateFieldGet(this,
|
|
129
|
+
__classPrivateFieldGet(this, _CollectionObservable_state, "f").items.splice(index, 1);
|
|
133
130
|
}
|
|
134
131
|
}
|
|
135
132
|
}
|
|
136
133
|
}
|
|
137
|
-
|
|
138
|
-
__classPrivateFieldGet(this, _state).items = __classPrivateFieldGet(this, _state).items.sort(sort_function);
|
|
139
|
-
__classPrivateFieldGet(this, _$state).next(__classPrivateFieldGet(this, _state));
|
|
134
|
+
__classPrivateFieldGet(this, _CollectionObservable_$state, "f").next(__classPrivateFieldGet(this, _CollectionObservable_state, "f"));
|
|
140
135
|
}
|
|
141
136
|
fetch_data(options = {}, flush = false) {
|
|
142
137
|
if (!this.ref)
|
|
143
138
|
return;
|
|
144
139
|
if (flush) {
|
|
145
|
-
__classPrivateFieldGet(this,
|
|
146
|
-
__classPrivateFieldGet(this,
|
|
140
|
+
__classPrivateFieldGet(this, _CollectionObservable_subscriptions, "f").forEach(s => s.unsubscribe());
|
|
141
|
+
__classPrivateFieldGet(this, _CollectionObservable_subscriptions, "f").clear();
|
|
147
142
|
}
|
|
148
|
-
__classPrivateFieldSet(this,
|
|
149
|
-
__classPrivateFieldGet(this,
|
|
143
|
+
__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");
|
|
144
|
+
__classPrivateFieldGet(this, _CollectionObservable_$state, "f").next(__classPrivateFieldGet(this, _CollectionObservable_state, "f"));
|
|
150
145
|
const query = this.collection_options.transporter.query(this.ref, options);
|
|
151
146
|
const sub = Object.assign(query
|
|
152
|
-
.pipe(operators_1.bufferTime(this.collection_options.sync_delay || 500), operators_1.filter(stream => stream.length > 0))
|
|
147
|
+
.pipe((0, operators_1.bufferTime)(this.collection_options.sync_delay || 500), (0, operators_1.filter)(stream => stream.length > 0))
|
|
153
148
|
.subscribe(data => this.sync(data)), { reload: query.reload });
|
|
154
|
-
__classPrivateFieldGet(this,
|
|
149
|
+
__classPrivateFieldGet(this, _CollectionObservable_subscriptions, "f").add(sub);
|
|
155
150
|
}
|
|
156
151
|
reload() {
|
|
157
|
-
__classPrivateFieldGet(this,
|
|
152
|
+
__classPrivateFieldGet(this, _CollectionObservable_subscriptions, "f").forEach(s => s.reload());
|
|
158
153
|
}
|
|
159
154
|
reset() {
|
|
160
155
|
this.fetch_data({}, true);
|
|
161
156
|
}
|
|
162
157
|
fetch_more() {
|
|
163
158
|
var _a;
|
|
164
|
-
const options = (_a = __classPrivateFieldGet(this,
|
|
165
|
-
__classPrivateFieldGet(this,
|
|
159
|
+
const options = (_a = __classPrivateFieldGet(this, _CollectionObservable_state, "f")) === null || _a === void 0 ? void 0 : _a.options;
|
|
160
|
+
__classPrivateFieldGet(this, _CollectionObservable_next_cursor, "f") && (options._cursor = __classPrivateFieldGet(this, _CollectionObservable_next_cursor, "f"));
|
|
166
161
|
this.fetch_data(options);
|
|
167
162
|
}
|
|
168
163
|
filter(filters) {
|
|
@@ -217,4 +212,4 @@ class CollectionObservable extends rxjs_1.Observable {
|
|
|
217
212
|
}
|
|
218
213
|
}
|
|
219
214
|
exports.CollectionObservable = CollectionObservable;
|
|
220
|
-
|
|
215
|
+
_CollectionObservable_$state = new WeakMap(), _CollectionObservable_subscriptions = new WeakMap(), _CollectionObservable_state = new WeakMap(), _CollectionObservable_next_cursor = new WeakMap();
|
package/build/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
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.
|
|
6
|
+
"version": "1.0.28",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "build/index.js",
|
|
9
9
|
"types": "build/index.d.ts",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"rxjs": "^7.1.0",
|
|
15
|
+
"typescript": "^4.9.5",
|
|
15
16
|
"uuid": "^8.3.2"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|