@livequery/client 1.0.51 → 1.0.53
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 -11
- package/build/Collection.js +147 -172
- package/build/helpers/get_sort_function.js +2 -6
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -17
- package/package.json +3 -2
package/build/Collection.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Subject, Observable } from 'rxjs';
|
|
2
|
-
import { ErrorInfo, QueryOption, Transporter, UpdatedData } from '@livequery/types';
|
|
3
|
-
export type CollectionOption<T =
|
|
2
|
+
import { ErrorInfo, LivequeryBaseEntity, QueryOption, Transporter, UpdatedData } from '@livequery/types';
|
|
3
|
+
export type CollectionOption<T extends LivequeryBaseEntity = LivequeryBaseEntity> = {
|
|
4
4
|
transporter: Transporter;
|
|
5
5
|
sync_delay?: number;
|
|
6
6
|
filters?: Partial<QueryOption<T>>;
|
|
@@ -14,18 +14,16 @@ export type SmartQueryItem<T> = T & {
|
|
|
14
14
|
__remove: Function;
|
|
15
15
|
__update: (data: Partial<T>) => any;
|
|
16
16
|
__trigger: (name: string, payload?: any) => any;
|
|
17
|
-
|
|
17
|
+
__ref: string;
|
|
18
18
|
};
|
|
19
|
-
type CollectionStream<T> = {
|
|
19
|
+
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
|
options: Partial<QueryOption<T>>;
|
|
25
25
|
};
|
|
26
|
-
export declare class CollectionObservable<T extends {
|
|
27
|
-
id: string;
|
|
28
|
-
}> extends Observable<CollectionStream<T>> {
|
|
26
|
+
export declare class CollectionObservable<T extends LivequeryBaseEntity = LivequeryBaseEntity> extends Observable<CollectionStream<T>> {
|
|
29
27
|
#private;
|
|
30
28
|
private ref;
|
|
31
29
|
private collection_options;
|
|
@@ -38,14 +36,12 @@ export declare class CollectionObservable<T extends {
|
|
|
38
36
|
reset(): void;
|
|
39
37
|
fetch_more(): void;
|
|
40
38
|
filter(filters: Partial<QueryOption<T>>): void;
|
|
41
|
-
add(payload: T): Promise<{
|
|
39
|
+
add(payload: Partial<T>): Promise<{
|
|
42
40
|
data: {
|
|
43
41
|
item: T;
|
|
44
42
|
};
|
|
45
43
|
}>;
|
|
46
|
-
update({ id: update_payload_id, ...payload }: Partial<T
|
|
47
|
-
id: string;
|
|
48
|
-
}>): Promise<any>;
|
|
44
|
+
update({ id: update_payload_id, ...payload }: Partial<T>): Promise<any>;
|
|
49
45
|
remove(remove_document_id?: string): Promise<void>;
|
|
50
46
|
trigger<T>(name: string, payload?: object, trigger_document_id?: string): Promise<T>;
|
|
51
47
|
}
|
package/build/Collection.js
CHANGED
|
@@ -1,108 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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;
|
|
16
|
-
};
|
|
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);
|
|
21
|
-
};
|
|
22
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
23
|
-
var t = {};
|
|
24
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
25
|
-
t[p] = s[p];
|
|
26
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
27
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
28
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
29
|
-
t[p[i]] = s[p[i]];
|
|
30
|
-
}
|
|
31
|
-
return t;
|
|
32
|
-
};
|
|
33
|
-
var _CollectionObservable_instances, _CollectionObservable_$state, _CollectionObservable_subscriptions, _CollectionObservable_state, _CollectionObservable_next_cursor, _CollectionObservable_IdMap, _CollectionObservable_refs, _CollectionObservable_ref_parser, _CollectionObservable_find_ref_by_id;
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.CollectionObservable = void 0;
|
|
36
|
-
const rxjs_1 = require("rxjs");
|
|
37
|
-
const get_sort_function_1 = require("./helpers/get_sort_function");
|
|
38
|
-
const operators_1 = require("rxjs/operators");
|
|
39
|
-
class CollectionObservable extends rxjs_1.Observable {
|
|
1
|
+
import { Subject, Observable, merge } from 'rxjs';
|
|
2
|
+
import { get_sort_function } from './helpers/get_sort_function.js';
|
|
3
|
+
import { bufferTime, filter, map } from 'rxjs/operators';
|
|
4
|
+
export class CollectionObservable extends Observable {
|
|
5
|
+
ref;
|
|
6
|
+
collection_options;
|
|
7
|
+
$changes = new Subject();
|
|
8
|
+
#$state = new Subject();
|
|
9
|
+
#subscriptions = new Set();
|
|
10
|
+
#state;
|
|
11
|
+
#next_cursor = {};
|
|
12
|
+
#IdMap = new Map();
|
|
13
|
+
#refs = [];
|
|
40
14
|
constructor(ref, collection_options) {
|
|
41
15
|
super(o => {
|
|
42
|
-
|
|
43
|
-
const subscription =
|
|
16
|
+
this.#state = { items: [], options: collection_options.filters, has_more: false };
|
|
17
|
+
const subscription = this.#$state.subscribe(o);
|
|
44
18
|
const auto_reload_interval = collection_options.reload_interval && setInterval(() => this.reload(), collection_options.reload_interval);
|
|
45
19
|
return () => {
|
|
46
|
-
|
|
20
|
+
this.#subscriptions.forEach(s => s.unsubscribe());
|
|
47
21
|
subscription.unsubscribe();
|
|
48
22
|
clearInterval(auto_reload_interval);
|
|
49
23
|
};
|
|
50
24
|
});
|
|
51
25
|
this.ref = ref;
|
|
52
26
|
this.collection_options = collection_options;
|
|
53
|
-
_CollectionObservable_instances.add(this);
|
|
54
|
-
this.$changes = new rxjs_1.Subject();
|
|
55
|
-
_CollectionObservable_$state.set(this, new rxjs_1.Subject());
|
|
56
|
-
_CollectionObservable_subscriptions.set(this, new Set());
|
|
57
|
-
_CollectionObservable_state.set(this, void 0);
|
|
58
|
-
_CollectionObservable_next_cursor.set(this, {});
|
|
59
|
-
_CollectionObservable_IdMap.set(this, new Map());
|
|
60
|
-
_CollectionObservable_refs.set(this, []);
|
|
61
27
|
if (ref.startsWith('/') || ref.endsWith('/'))
|
|
62
28
|
throw 'INVAILD_REF_FORMAT';
|
|
63
|
-
|
|
29
|
+
this.#refs = this.#ref_parser(ref);
|
|
30
|
+
}
|
|
31
|
+
#ref_parser(path) {
|
|
32
|
+
if (!path)
|
|
33
|
+
return [];
|
|
34
|
+
const refs_builder = (paths) => {
|
|
35
|
+
const [a, b, ...c] = paths;
|
|
36
|
+
if (!b)
|
|
37
|
+
return paths;
|
|
38
|
+
const r = a.map(aa => b.map(bb => `${aa}/${bb}`)).flat(2);
|
|
39
|
+
const d = [r, ...c];
|
|
40
|
+
return refs_builder(d);
|
|
41
|
+
};
|
|
42
|
+
return path.split(',').map(f => refs_builder(f.trim().split('/').map(l => l.split('|')))).flat(2);
|
|
64
43
|
}
|
|
65
44
|
set_realtime(realtime) {
|
|
66
45
|
this.collection_options.realtime = realtime;
|
|
67
46
|
}
|
|
68
47
|
sync(stream, from_local = false) {
|
|
69
|
-
|
|
70
|
-
const realtime = (_a = this.collection_options.realtime) !== null && _a !== void 0 ? _a : true;
|
|
48
|
+
const realtime = this.collection_options.realtime ?? true;
|
|
71
49
|
const actions = { update: false, reindex: false };
|
|
72
50
|
for (const { data, error, ref } of stream) {
|
|
73
51
|
// Error & paging
|
|
74
52
|
if (error) {
|
|
75
|
-
|
|
53
|
+
this.#state.error = error;
|
|
76
54
|
actions.update = true;
|
|
77
55
|
}
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
56
|
+
if (data?.paging?.n == 0) {
|
|
57
|
+
this.#next_cursor[ref] = data?.paging?.next_cursor;
|
|
58
|
+
this.#state.has_more = Object.values(this.#next_cursor).some(v => v && v != '#');
|
|
59
|
+
this.#state.loading = false;
|
|
82
60
|
actions.update = true;
|
|
83
61
|
}
|
|
84
62
|
// Sync
|
|
85
|
-
for (const change of
|
|
86
|
-
if (!
|
|
63
|
+
for (const change of data?.changes || []) {
|
|
64
|
+
if (!change?.data?.id)
|
|
87
65
|
continue;
|
|
88
66
|
const { data: payload, type } = change;
|
|
89
67
|
this.$changes.next(change);
|
|
90
|
-
const index =
|
|
68
|
+
const index = this.#IdMap.get(payload.id) ?? -1;
|
|
91
69
|
if (index == -1 && type == 'added') {
|
|
92
70
|
if (
|
|
93
71
|
// Is first value from HTTP query
|
|
94
|
-
|
|
72
|
+
data?.paging?.n == 0
|
|
95
73
|
|| (
|
|
96
74
|
// Is realtime update that match filters
|
|
97
75
|
(realtime || from_local) && Object
|
|
98
|
-
.keys(
|
|
76
|
+
.keys(this.#state.options || {})
|
|
99
77
|
.filter(key => !key.includes('_'))
|
|
100
78
|
.every(key => {
|
|
101
|
-
var _a;
|
|
102
79
|
try {
|
|
103
80
|
const [field, expression] = key.split(':');
|
|
104
81
|
const a = payload[field];
|
|
105
|
-
const b =
|
|
82
|
+
const b = this.#state.options?.[field];
|
|
106
83
|
if (!expression)
|
|
107
84
|
return a == b;
|
|
108
85
|
if (expression == 'ne')
|
|
@@ -116,11 +93,11 @@ class CollectionObservable extends rxjs_1.Observable {
|
|
|
116
93
|
if (expression == 'gte')
|
|
117
94
|
return a >= b;
|
|
118
95
|
if (expression == 'in-array')
|
|
119
|
-
return a
|
|
96
|
+
return a?.includes(b);
|
|
120
97
|
if (expression == 'contains')
|
|
121
|
-
return a
|
|
98
|
+
return a?.some(e => b?.includes(e));
|
|
122
99
|
if (expression == 'not-contains')
|
|
123
|
-
return a
|
|
100
|
+
return a?.every(e => !b?.includes(e));
|
|
124
101
|
if (expression == 'between')
|
|
125
102
|
return (b[0] <= a && a <= b[1]);
|
|
126
103
|
if (expression == 'like')
|
|
@@ -129,7 +106,16 @@ class CollectionObservable extends rxjs_1.Observable {
|
|
|
129
106
|
catch (e) { }
|
|
130
107
|
return false;
|
|
131
108
|
}))) {
|
|
132
|
-
|
|
109
|
+
this.#state.items.push({
|
|
110
|
+
...payload,
|
|
111
|
+
__adding: false,
|
|
112
|
+
__updating: false,
|
|
113
|
+
__removing: false,
|
|
114
|
+
__remove: () => this.remove(payload?.id),
|
|
115
|
+
__trigger: (name, input) => this.trigger(name, input, payload?.id),
|
|
116
|
+
__update: (input) => this.update({ ...input, id: payload?.id }),
|
|
117
|
+
__ref: change.ref
|
|
118
|
+
});
|
|
133
119
|
actions.reindex = true;
|
|
134
120
|
actions.update = true;
|
|
135
121
|
}
|
|
@@ -137,165 +123,154 @@ class CollectionObservable extends rxjs_1.Observable {
|
|
|
137
123
|
if (index >= 0 && (realtime || from_local)) {
|
|
138
124
|
if (type == 'added' || type == 'modified') {
|
|
139
125
|
actions.update = true;
|
|
140
|
-
if (Object.keys(payload).some(key =>
|
|
126
|
+
if (Object.keys(payload).some(key => ['created_at', this.collection_options?.filters?._order_by].includes(key))) {
|
|
141
127
|
actions.reindex = true;
|
|
142
128
|
}
|
|
143
|
-
|
|
129
|
+
this.#state.items[index] = {
|
|
130
|
+
...this.#state.items[index],
|
|
131
|
+
__adding: false,
|
|
132
|
+
__updating: false,
|
|
133
|
+
__removing: false,
|
|
134
|
+
...payload
|
|
135
|
+
};
|
|
144
136
|
}
|
|
145
137
|
if (type == 'removed') {
|
|
146
138
|
actions.reindex = true;
|
|
147
139
|
actions.update = true;
|
|
148
|
-
|
|
149
|
-
for (const [document_id, i] of
|
|
150
|
-
i == index &&
|
|
151
|
-
i > index &&
|
|
140
|
+
this.#state.items.splice(index, 1);
|
|
141
|
+
for (const [document_id, i] of this.#IdMap) {
|
|
142
|
+
i == index && this.#IdMap.delete(document_id);
|
|
143
|
+
i > index && this.#IdMap.set(document_id, i - 1);
|
|
152
144
|
}
|
|
153
145
|
}
|
|
154
146
|
}
|
|
155
147
|
}
|
|
156
148
|
}
|
|
157
149
|
if (actions.reindex) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
150
|
+
this.#state.items = this.#state.items.sort(get_sort_function(this.#state.items[0], this.collection_options?.filters?._order_by || 'created_at', this.collection_options?.filters?._sort));
|
|
151
|
+
this.#IdMap.clear();
|
|
152
|
+
this.#state.items.map((item, index) => this.#IdMap.set(item.id, index));
|
|
161
153
|
}
|
|
162
|
-
actions.update &&
|
|
154
|
+
actions.update && this.#$state.next(this.#state);
|
|
163
155
|
}
|
|
164
156
|
fetch_data(options = {}, flush = false) {
|
|
165
|
-
if (
|
|
157
|
+
if (this.#refs.length == 0)
|
|
166
158
|
return;
|
|
167
159
|
if (flush) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
160
|
+
this.#next_cursor = {};
|
|
161
|
+
this.#subscriptions.forEach(s => s.unsubscribe());
|
|
162
|
+
this.#subscriptions.clear();
|
|
163
|
+
this.#IdMap.clear();
|
|
172
164
|
}
|
|
173
|
-
const has_more_data_refs =
|
|
165
|
+
const has_more_data_refs = this.#refs.filter(ref => this.#next_cursor[ref] === undefined || (this.#next_cursor[ref] && this.#next_cursor[ref] != '#'));
|
|
174
166
|
// Load more but no more data || loading
|
|
175
|
-
if (!flush && (has_more_data_refs.length == 0 ||
|
|
167
|
+
if (!flush && (has_more_data_refs.length == 0 || this.#state.loading))
|
|
176
168
|
return;
|
|
177
|
-
|
|
178
|
-
|
|
169
|
+
this.#state = {
|
|
170
|
+
...this.#state,
|
|
171
|
+
items: flush ? [] : this.#state.items,
|
|
172
|
+
error: null,
|
|
173
|
+
loading: true,
|
|
174
|
+
options
|
|
175
|
+
};
|
|
176
|
+
this.#$state.next(this.#state);
|
|
179
177
|
const queries = has_more_data_refs.map(ref => (this
|
|
180
178
|
.collection_options
|
|
181
179
|
.transporter
|
|
182
|
-
.query(ref,
|
|
180
|
+
.query(ref, { ...options, _cursor: this.#next_cursor[ref] })));
|
|
183
181
|
const reload = () => queries.map(q => q.reload());
|
|
184
|
-
const $ =
|
|
182
|
+
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)));
|
|
185
183
|
const subscription = Object.assign($.subscribe(), { reload });
|
|
186
|
-
|
|
184
|
+
this.#subscriptions.add(subscription);
|
|
187
185
|
}
|
|
188
186
|
reload() {
|
|
189
|
-
|
|
187
|
+
this.#subscriptions.forEach(s => s.reload());
|
|
190
188
|
}
|
|
191
189
|
reset() {
|
|
192
190
|
this.fetch_data({}, true);
|
|
193
191
|
}
|
|
194
192
|
fetch_more() {
|
|
195
|
-
|
|
196
|
-
this.fetch_data((_a = __classPrivateFieldGet(this, _CollectionObservable_state, "f")) === null || _a === void 0 ? void 0 : _a.options);
|
|
193
|
+
this.fetch_data(this.#state?.options);
|
|
197
194
|
}
|
|
198
195
|
filter(filters) {
|
|
199
196
|
this.fetch_data(filters, true);
|
|
200
197
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
198
|
+
#find_ref_by_id(id) {
|
|
199
|
+
if (!id)
|
|
200
|
+
return { ref: this.ref, collection_ref: this.ref };
|
|
201
|
+
const origin_ref = this.#state.items[this.#IdMap.get(id)].__ref;
|
|
202
|
+
if (!origin_ref)
|
|
203
|
+
throw 'COLLECTION_REF_NOT_FOUND';
|
|
204
|
+
const refs = origin_ref.split('/');
|
|
205
|
+
const collection_ref = refs.slice(0, refs.length - (refs.length % 2 == 1 ? 0 : 1)).join('/');
|
|
206
|
+
const ref = `${collection_ref}/${id}`;
|
|
207
|
+
return { ref, id, collection_ref };
|
|
207
208
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
async add(payload) {
|
|
210
|
+
return await this.collection_options.transporter.add(`${this.ref}`, payload);
|
|
211
|
+
}
|
|
212
|
+
async update({ id: update_payload_id, ...payload }) {
|
|
213
|
+
const { id, ref } = this.#find_ref_by_id(update_payload_id);
|
|
214
|
+
// Trigger local update
|
|
215
|
+
this.sync([{
|
|
216
|
+
ref,
|
|
217
|
+
data: {
|
|
218
|
+
changes: [{
|
|
219
|
+
data: { ...payload, id, __updating: true },
|
|
220
|
+
ref,
|
|
221
|
+
type: 'modified'
|
|
222
|
+
}]
|
|
223
|
+
}
|
|
224
|
+
}], true);
|
|
225
|
+
try {
|
|
226
|
+
return await this.collection_options.transporter.update(ref, payload);
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
213
229
|
this.sync([{
|
|
214
230
|
ref,
|
|
215
231
|
data: {
|
|
216
232
|
changes: [{
|
|
217
|
-
data:
|
|
233
|
+
data: { id, __updating: false },
|
|
218
234
|
ref,
|
|
219
235
|
type: 'modified'
|
|
220
236
|
}]
|
|
221
237
|
}
|
|
222
238
|
}], true);
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
catch (e) {
|
|
227
|
-
this.sync([{
|
|
228
|
-
ref,
|
|
229
|
-
data: {
|
|
230
|
-
changes: [{
|
|
231
|
-
data: { id, __updating: false },
|
|
232
|
-
ref,
|
|
233
|
-
type: 'modified'
|
|
234
|
-
}]
|
|
235
|
-
}
|
|
236
|
-
}], true);
|
|
237
|
-
throw e;
|
|
238
|
-
}
|
|
239
|
-
});
|
|
239
|
+
throw e;
|
|
240
|
+
}
|
|
240
241
|
}
|
|
241
|
-
remove(remove_document_id) {
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
async remove(remove_document_id) {
|
|
243
|
+
const { id, ref } = this.#find_ref_by_id(remove_document_id);
|
|
244
|
+
this.sync([{
|
|
245
|
+
ref,
|
|
246
|
+
data: {
|
|
247
|
+
changes: [{
|
|
248
|
+
data: { id, __removing: true },
|
|
249
|
+
ref,
|
|
250
|
+
type: 'modified'
|
|
251
|
+
}]
|
|
252
|
+
}
|
|
253
|
+
}], true);
|
|
254
|
+
// Trigger
|
|
255
|
+
try {
|
|
256
|
+
return await this.collection_options.transporter.remove(ref);
|
|
257
|
+
}
|
|
258
|
+
catch (e) {
|
|
244
259
|
this.sync([{
|
|
245
260
|
ref,
|
|
246
261
|
data: {
|
|
247
262
|
changes: [{
|
|
248
|
-
data: { id, __removing:
|
|
263
|
+
data: { id, __removing: false },
|
|
249
264
|
ref,
|
|
250
265
|
type: 'modified'
|
|
251
266
|
}]
|
|
252
267
|
}
|
|
253
268
|
}], true);
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return yield this.collection_options.transporter.remove(ref);
|
|
257
|
-
}
|
|
258
|
-
catch (e) {
|
|
259
|
-
this.sync([{
|
|
260
|
-
ref,
|
|
261
|
-
data: {
|
|
262
|
-
changes: [{
|
|
263
|
-
data: { id, __removing: false },
|
|
264
|
-
ref,
|
|
265
|
-
type: 'modified'
|
|
266
|
-
}]
|
|
267
|
-
}
|
|
268
|
-
}], true);
|
|
269
|
-
throw e;
|
|
270
|
-
}
|
|
271
|
-
});
|
|
269
|
+
throw e;
|
|
270
|
+
}
|
|
272
271
|
}
|
|
273
|
-
trigger(name, payload, trigger_document_id) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
return yield this.collection_options.transporter.trigger(ref, name, {}, payload);
|
|
277
|
-
});
|
|
272
|
+
async trigger(name, payload, trigger_document_id) {
|
|
273
|
+
const { ref } = this.#find_ref_by_id(trigger_document_id);
|
|
274
|
+
return await this.collection_options.transporter.trigger(ref, name, {}, payload);
|
|
278
275
|
}
|
|
279
276
|
}
|
|
280
|
-
exports.CollectionObservable = CollectionObservable;
|
|
281
|
-
_CollectionObservable_$state = new WeakMap(), _CollectionObservable_subscriptions = new WeakMap(), _CollectionObservable_state = new WeakMap(), _CollectionObservable_next_cursor = new WeakMap(), _CollectionObservable_IdMap = new WeakMap(), _CollectionObservable_refs = new WeakMap(), _CollectionObservable_instances = new WeakSet(), _CollectionObservable_ref_parser = function _CollectionObservable_ref_parser(path) {
|
|
282
|
-
if (!path)
|
|
283
|
-
return [];
|
|
284
|
-
const refs_builder = (paths) => {
|
|
285
|
-
const [a, b, ...c] = paths;
|
|
286
|
-
if (!b)
|
|
287
|
-
return paths;
|
|
288
|
-
const r = a.map(aa => b.map(bb => `${aa}/${bb}`)).flat(2);
|
|
289
|
-
const d = [r, ...c];
|
|
290
|
-
return refs_builder(d);
|
|
291
|
-
};
|
|
292
|
-
return path.split(',').map(f => refs_builder(f.trim().split('/').map(l => l.split('|')))).flat(2);
|
|
293
|
-
}, _CollectionObservable_find_ref_by_id = function _CollectionObservable_find_ref_by_id(id) {
|
|
294
|
-
if (!id)
|
|
295
|
-
throw 'ID_NOT_FOUND';
|
|
296
|
-
const collection_ref = __classPrivateFieldGet(this, _CollectionObservable_state, "f").items[__classPrivateFieldGet(this, _CollectionObservable_IdMap, "f").get(id)].__collection_ref;
|
|
297
|
-
if (!collection_ref)
|
|
298
|
-
throw 'COLLECTION_REF_NOT_FOUND';
|
|
299
|
-
const ref = `${collection_ref}${id ? `/${id}` : ''}`;
|
|
300
|
-
return { ref, id, collection_ref };
|
|
301
|
-
};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.get_sort_function = void 0;
|
|
4
|
-
function get_sort_function(data, key, order = 'desc') {
|
|
5
|
-
const type = typeof (data === null || data === void 0 ? void 0 : data[key]);
|
|
1
|
+
export function get_sort_function(data, key, order = 'desc') {
|
|
2
|
+
const type = typeof data?.[key];
|
|
6
3
|
if (type == 'bigint' || type == 'number') {
|
|
7
4
|
if (order == 'asc')
|
|
8
5
|
return (a, b) => a[key] - b[key] || ((a.created_at || 1) - (b.created_at || 0));
|
|
@@ -17,4 +14,3 @@ function get_sort_function(data, key, order = 'desc') {
|
|
|
17
14
|
}
|
|
18
15
|
return () => 1;
|
|
19
16
|
}
|
|
20
|
-
exports.get_sort_function = get_sort_function;
|
package/build/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './Collection';
|
|
1
|
+
export * from './Collection.js';
|
package/build/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./Collection"), exports);
|
|
1
|
+
export * from './Collection.js';
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livequery/client",
|
|
3
|
+
"type": "module",
|
|
3
4
|
"repository": {
|
|
4
5
|
"url": "https://github.com/livequery/client"
|
|
5
6
|
},
|
|
6
|
-
"version": "1.0.
|
|
7
|
+
"version": "1.0.53",
|
|
7
8
|
"description": "",
|
|
8
9
|
"main": "build/index.js",
|
|
9
10
|
"types": "build/index.d.ts",
|
|
@@ -16,7 +17,7 @@
|
|
|
16
17
|
"uuid": "^8.3.2"
|
|
17
18
|
},
|
|
18
19
|
"devDependencies": {
|
|
19
|
-
"@livequery/types": "^1.0.
|
|
20
|
+
"@livequery/types": "^1.0.79"
|
|
20
21
|
},
|
|
21
22
|
"scripts": {
|
|
22
23
|
"test": "echo \"Error: no test specified\" && exit 1",
|