@livequery/client 1.0.23 → 1.0.24
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 +7 -5
- package/build/Collection.js +16 -24
- package/package.json +1 -1
package/build/Collection.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export declare class CollectionObservable<T extends {
|
|
|
28
28
|
private ref;
|
|
29
29
|
private collection_options;
|
|
30
30
|
private is_collection_ref;
|
|
31
|
+
private collection_ref;
|
|
32
|
+
private document_id;
|
|
31
33
|
constructor(ref: string, collection_options: CollectionOption<T>);
|
|
32
34
|
private push_item;
|
|
33
35
|
private sync;
|
|
@@ -36,11 +38,11 @@ export declare class CollectionObservable<T extends {
|
|
|
36
38
|
reset(): void;
|
|
37
39
|
fetch_more(): void;
|
|
38
40
|
filter(filters: Partial<QueryOption<T>>): void;
|
|
39
|
-
add(payload: T
|
|
40
|
-
remove(
|
|
41
|
-
update({ id, ...payload }: {
|
|
41
|
+
add(payload: T): Promise<void>;
|
|
42
|
+
remove(remove_document_id?: string): Promise<void>;
|
|
43
|
+
update({ id: update_payload_id, ...payload }: Partial<T & {
|
|
42
44
|
id: string;
|
|
43
|
-
}
|
|
44
|
-
trigger(name: string,
|
|
45
|
+
}>): Promise<void>;
|
|
46
|
+
trigger(name: string, payload?: object, trigger_document_id?: string): Promise<unknown>;
|
|
45
47
|
}
|
|
46
48
|
export {};
|
package/build/Collection.js
CHANGED
|
@@ -38,7 +38,6 @@ exports.CollectionObservable = void 0;
|
|
|
38
38
|
const rxjs_1 = require("rxjs");
|
|
39
39
|
const get_sort_function_1 = require("./helpers/get_sort_function");
|
|
40
40
|
const operators_1 = require("rxjs/operators");
|
|
41
|
-
const uuid_1 = require("uuid");
|
|
42
41
|
class CollectionObservable extends rxjs_1.Observable {
|
|
43
42
|
constructor(ref, collection_options) {
|
|
44
43
|
super(o => {
|
|
@@ -57,12 +56,15 @@ class CollectionObservable extends rxjs_1.Observable {
|
|
|
57
56
|
_subscriptions.set(this, new Set());
|
|
58
57
|
_state.set(this, void 0);
|
|
59
58
|
_next_cursor.set(this, null);
|
|
59
|
+
if (ref.startsWith('/') || ref.endsWith('/'))
|
|
60
|
+
throw 'INVAILD_REF_FORMAT';
|
|
60
61
|
const refs = ref.split('/');
|
|
61
62
|
this.is_collection_ref = refs.length % 2 == 1;
|
|
63
|
+
this.collection_ref = refs.slice(0, refs.length - (this.is_collection_ref ? 0 : 1)).join('/');
|
|
64
|
+
this.document_id = this.is_collection_ref ? null : refs[refs.length - 1];
|
|
62
65
|
}
|
|
63
66
|
push_item(data) {
|
|
64
|
-
const { id }
|
|
65
|
-
const item = Object.assign(Object.assign({ __adding: false, __updating: true, __removing: false }, data), { __remove: () => this.remove(id), __trigger: (name, payload) => this.trigger(name, id, payload), __update: (payload) => this.update(Object.assign({ id }, payload)) });
|
|
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)) });
|
|
66
68
|
__classPrivateFieldGet(this, _state).items.push(item);
|
|
67
69
|
}
|
|
68
70
|
sync(stream) {
|
|
@@ -167,26 +169,14 @@ class CollectionObservable extends rxjs_1.Observable {
|
|
|
167
169
|
filter(filters) {
|
|
168
170
|
this.fetch_data(filters, true);
|
|
169
171
|
}
|
|
170
|
-
add(payload
|
|
172
|
+
add(payload) {
|
|
171
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
-
|
|
173
|
-
const data = Object.assign(Object.assign({ id: uuid_1.v4() }, payload), { __adding: true });
|
|
174
|
-
this.sync([{
|
|
175
|
-
data: {
|
|
176
|
-
changes: [{
|
|
177
|
-
data: Object.assign(Object.assign({}, payload), { __adding: true }),
|
|
178
|
-
ref: this.ref,
|
|
179
|
-
type: 'added'
|
|
180
|
-
}]
|
|
181
|
-
}
|
|
182
|
-
}]);
|
|
183
|
-
return yield this.collection_options.transporter.add(`${this.ref}`, data);
|
|
184
|
-
}
|
|
185
|
-
return yield this.collection_options.transporter.add(`${this.ref}`, payload);
|
|
174
|
+
return yield this.collection_options.transporter.add(`${this.collection_ref}`, payload);
|
|
186
175
|
});
|
|
187
176
|
}
|
|
188
|
-
remove(
|
|
177
|
+
remove(remove_document_id) {
|
|
189
178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
const id = remove_document_id || this.document_id;
|
|
190
180
|
this.sync([{
|
|
191
181
|
data: {
|
|
192
182
|
changes: [{
|
|
@@ -197,13 +187,14 @@ class CollectionObservable extends rxjs_1.Observable {
|
|
|
197
187
|
}
|
|
198
188
|
}]);
|
|
199
189
|
// Trigger
|
|
200
|
-
const ref = `${this.
|
|
190
|
+
const ref = `${this.collection_ref}${id ? `/${id}` : ''}`;
|
|
201
191
|
return yield this.collection_options.transporter.remove(ref);
|
|
202
192
|
});
|
|
203
193
|
}
|
|
204
194
|
update(_a) {
|
|
205
|
-
var { id } = _a, payload = __rest(_a, ["id"]);
|
|
195
|
+
var { id: update_payload_id } = _a, payload = __rest(_a, ["id"]);
|
|
206
196
|
return __awaiter(this, void 0, void 0, function* () {
|
|
197
|
+
const id = update_payload_id || this.document_id;
|
|
207
198
|
// Trigger local update
|
|
208
199
|
this.sync([{
|
|
209
200
|
data: {
|
|
@@ -214,13 +205,14 @@ class CollectionObservable extends rxjs_1.Observable {
|
|
|
214
205
|
}]
|
|
215
206
|
}
|
|
216
207
|
}]);
|
|
217
|
-
const ref = `${this.
|
|
208
|
+
const ref = `${this.collection_ref}${id ? `/${id}` : ''}`;
|
|
218
209
|
return yield this.collection_options.transporter.update(ref, payload);
|
|
219
210
|
});
|
|
220
211
|
}
|
|
221
|
-
trigger(name,
|
|
212
|
+
trigger(name, payload, trigger_document_id) {
|
|
222
213
|
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
-
const
|
|
214
|
+
const id = trigger_document_id || this.document_id;
|
|
215
|
+
const ref = `${this.collection_ref}${id ? `/${id}` : ''}`;
|
|
224
216
|
return yield this.collection_options.transporter.trigger(ref, name, {}, payload);
|
|
225
217
|
});
|
|
226
218
|
}
|