@livequery/client 1.0.92 → 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 +8 -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);
|
|
@@ -29,7 +29,7 @@ export class CollectionObservable extends Observable {
|
|
|
29
29
|
this.collection_options = collection_options;
|
|
30
30
|
this.collection_options.filters = this.collection_options.filters || {};
|
|
31
31
|
if (collection_options.filters)
|
|
32
|
-
this.value.
|
|
32
|
+
this.value.filters = collection_options.filters;
|
|
33
33
|
if (ref && (ref.startsWith('/') || ref.endsWith('/')))
|
|
34
34
|
throw 'INVAILD_REF_FORMAT';
|
|
35
35
|
this.#refs = this.#ref_parser(ref);
|
|
@@ -79,13 +79,13 @@ export class CollectionObservable extends Observable {
|
|
|
79
79
|
|| (
|
|
80
80
|
// Is realtime update that match filters
|
|
81
81
|
(realtime || from_local) && Object
|
|
82
|
-
.keys(this.value.
|
|
82
|
+
.keys(this.value.filters || {})
|
|
83
83
|
.filter(key => !key.includes('_'))
|
|
84
84
|
.every(key => {
|
|
85
85
|
try {
|
|
86
86
|
const [field, expression] = key.split(':');
|
|
87
87
|
const a = payload[field];
|
|
88
|
-
const b = this.value.
|
|
88
|
+
const b = this.value.filters?.[field];
|
|
89
89
|
if (!expression)
|
|
90
90
|
return a == b;
|
|
91
91
|
if (expression == 'ne')
|
|
@@ -164,7 +164,7 @@ export class CollectionObservable extends Observable {
|
|
|
164
164
|
}
|
|
165
165
|
actions.update && this.$.next(this.value);
|
|
166
166
|
}
|
|
167
|
-
fetch_data(
|
|
167
|
+
fetch_data(filters = {}, flush = false) {
|
|
168
168
|
if (!this.ref)
|
|
169
169
|
return;
|
|
170
170
|
if (this.#refs.length == 0)
|
|
@@ -183,13 +183,13 @@ export class CollectionObservable extends Observable {
|
|
|
183
183
|
items: flush ? [] : this.value.items,
|
|
184
184
|
error: undefined,
|
|
185
185
|
loading: true,
|
|
186
|
-
|
|
186
|
+
filters
|
|
187
187
|
};
|
|
188
188
|
this.$.next(this.value);
|
|
189
189
|
const queries = has_more_data_refs.map(ref => (this
|
|
190
190
|
.collection_options
|
|
191
191
|
.transporter
|
|
192
|
-
.query(ref, { ...
|
|
192
|
+
.query(ref, { ...filters, _cursor: this.#next_cursor[ref] })));
|
|
193
193
|
const reload = () => queries.map(q => q.reload());
|
|
194
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)));
|
|
195
195
|
const subscription = Object.assign($.subscribe(), { reload });
|
|
@@ -202,7 +202,7 @@ export class CollectionObservable extends Observable {
|
|
|
202
202
|
this.fetch_data({}, true);
|
|
203
203
|
}
|
|
204
204
|
fetch_more() {
|
|
205
|
-
this.fetch_data(this.value?.
|
|
205
|
+
this.fetch_data(this.value?.filters);
|
|
206
206
|
}
|
|
207
207
|
filter(filters) {
|
|
208
208
|
this.fetch_data(filters, true);
|