@livequery/client 1.0.85 → 1.0.93
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 +6 -19
- package/build/Collection.js +9 -8
- package/package.json +1 -1
package/build/Collection.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Subject, Observable, ReplaySubject } from 'rxjs';
|
|
2
|
-
import { ErrorInfo, LivequeryBaseEntity, QueryOption, Transporter, UpdatedData } from '@livequery/types';
|
|
2
|
+
import { ErrorInfo, LivequeryBaseEntity, QueryOption, Transporter, UpdatedData, DocumentResponse } from '@livequery/types';
|
|
3
3
|
export type CollectionOption<T extends LivequeryBaseEntity = LivequeryBaseEntity> = {
|
|
4
4
|
transporter: Transporter;
|
|
5
5
|
sync_delay?: number;
|
|
@@ -16,12 +16,12 @@ export type SmartQueryItem<T> = T & {
|
|
|
16
16
|
__trigger: (name: string, payload?: any) => any;
|
|
17
17
|
__ref: string;
|
|
18
18
|
};
|
|
19
|
-
type CollectionStream<T extends LivequeryBaseEntity = LivequeryBaseEntity> = {
|
|
19
|
+
export type CollectionStream<T extends LivequeryBaseEntity = LivequeryBaseEntity> = {
|
|
20
20
|
items: SmartQueryItem<T>[];
|
|
21
21
|
error?: ErrorInfo;
|
|
22
22
|
has_more: boolean;
|
|
23
23
|
loading?: boolean;
|
|
24
|
-
|
|
24
|
+
filters: Partial<QueryOption<T>>;
|
|
25
25
|
};
|
|
26
26
|
export declare class CollectionObservable<T extends LivequeryBaseEntity = LivequeryBaseEntity> extends Observable<CollectionStream<T>> {
|
|
27
27
|
#private;
|
|
@@ -37,23 +37,10 @@ export declare class CollectionObservable<T extends LivequeryBaseEntity = Livequ
|
|
|
37
37
|
reset(): void;
|
|
38
38
|
fetch_more(): void;
|
|
39
39
|
filter(filters: Partial<QueryOption<T>>): void;
|
|
40
|
-
add<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
}>(payload: Partial<T>): Promise<R>;
|
|
45
|
-
update<R = {
|
|
46
|
-
data: {
|
|
47
|
-
item: T;
|
|
48
|
-
};
|
|
49
|
-
}>({ id: update_payload_id, ...payload }: Partial<T>): Promise<R | undefined>;
|
|
50
|
-
remove<R = {
|
|
51
|
-
data: {
|
|
52
|
-
item: T;
|
|
53
|
-
};
|
|
54
|
-
}>(remove_document_id?: string): Promise<void>;
|
|
40
|
+
add(payload: Partial<T>): Promise<DocumentResponse<T>>;
|
|
41
|
+
update({ id: update_payload_id, ...payload }: Partial<T>): Promise<DocumentResponse<T> | undefined>;
|
|
42
|
+
remove(remove_document_id?: string): Promise<void>;
|
|
55
43
|
trigger<R>(name: string, payload?: object, trigger_document_id?: string, query?: {
|
|
56
44
|
[key: string]: string | number | boolean;
|
|
57
45
|
}): Promise<R | undefined>;
|
|
58
46
|
}
|
|
59
|
-
export {};
|
package/build/Collection.js
CHANGED
|
@@ -11,7 +11,7 @@ export class CollectionObservable extends Observable {
|
|
|
11
11
|
value = {
|
|
12
12
|
has_more: false,
|
|
13
13
|
items: [],
|
|
14
|
-
|
|
14
|
+
filters: {},
|
|
15
15
|
loading: false
|
|
16
16
|
};
|
|
17
17
|
$ = new ReplaySubject(1);
|
|
@@ -27,8 +27,9 @@ export class CollectionObservable extends Observable {
|
|
|
27
27
|
});
|
|
28
28
|
this.ref = ref;
|
|
29
29
|
this.collection_options = collection_options;
|
|
30
|
+
this.collection_options.filters = this.collection_options.filters || {};
|
|
30
31
|
if (collection_options.filters)
|
|
31
|
-
this.value.
|
|
32
|
+
this.value.filters = collection_options.filters;
|
|
32
33
|
if (ref && (ref.startsWith('/') || ref.endsWith('/')))
|
|
33
34
|
throw 'INVAILD_REF_FORMAT';
|
|
34
35
|
this.#refs = this.#ref_parser(ref);
|
|
@@ -78,13 +79,13 @@ export class CollectionObservable extends Observable {
|
|
|
78
79
|
|| (
|
|
79
80
|
// Is realtime update that match filters
|
|
80
81
|
(realtime || from_local) && Object
|
|
81
|
-
.keys(this.value.
|
|
82
|
+
.keys(this.value.filters || {})
|
|
82
83
|
.filter(key => !key.includes('_'))
|
|
83
84
|
.every(key => {
|
|
84
85
|
try {
|
|
85
86
|
const [field, expression] = key.split(':');
|
|
86
87
|
const a = payload[field];
|
|
87
|
-
const b = this.value.
|
|
88
|
+
const b = this.value.filters?.[field];
|
|
88
89
|
if (!expression)
|
|
89
90
|
return a == b;
|
|
90
91
|
if (expression == 'ne')
|
|
@@ -163,7 +164,7 @@ export class CollectionObservable extends Observable {
|
|
|
163
164
|
}
|
|
164
165
|
actions.update && this.$.next(this.value);
|
|
165
166
|
}
|
|
166
|
-
fetch_data(
|
|
167
|
+
fetch_data(filters = {}, flush = false) {
|
|
167
168
|
if (!this.ref)
|
|
168
169
|
return;
|
|
169
170
|
if (this.#refs.length == 0)
|
|
@@ -182,13 +183,13 @@ export class CollectionObservable extends Observable {
|
|
|
182
183
|
items: flush ? [] : this.value.items,
|
|
183
184
|
error: undefined,
|
|
184
185
|
loading: true,
|
|
185
|
-
|
|
186
|
+
filters
|
|
186
187
|
};
|
|
187
188
|
this.$.next(this.value);
|
|
188
189
|
const queries = has_more_data_refs.map(ref => (this
|
|
189
190
|
.collection_options
|
|
190
191
|
.transporter
|
|
191
|
-
.query(ref, { ...
|
|
192
|
+
.query(ref, { ...filters, _cursor: this.#next_cursor[ref] })));
|
|
192
193
|
const reload = () => queries.map(q => q.reload());
|
|
193
194
|
const $ = merge(...queries.map((q, index) => q.pipe(map(data => ({ ...data, ref: has_more_data_refs[index] }))))).pipe(bufferTime(500), filter(list => list.length > 0), map(data => this.#sync(data)));
|
|
194
195
|
const subscription = Object.assign($.subscribe(), { reload });
|
|
@@ -201,7 +202,7 @@ export class CollectionObservable extends Observable {
|
|
|
201
202
|
this.fetch_data({}, true);
|
|
202
203
|
}
|
|
203
204
|
fetch_more() {
|
|
204
|
-
this.fetch_data(this.value?.
|
|
205
|
+
this.fetch_data(this.value?.filters);
|
|
205
206
|
}
|
|
206
207
|
filter(filters) {
|
|
207
208
|
this.fetch_data(filters, true);
|