liwi-subscribe-store 8.3.0 → 8.3.1
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/CHANGELOG.md +8 -0
- package/dist/index-browser-dev.cjs.js +143 -479
- package/dist/index-browser-dev.cjs.js.map +1 -1
- package/dist/index-browser-dev.es.js +143 -472
- package/dist/index-browser-dev.es.js.map +1 -1
- package/dist/index-browser.cjs.js +143 -479
- package/dist/index-browser.cjs.js.map +1 -1
- package/dist/index-browser.es.js +143 -472
- package/dist/index-browser.es.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,514 +1,185 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import _createClass from '@babel/runtime/helpers/esm/createClass';
|
|
4
|
-
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
5
|
-
|
|
6
|
-
var AbstractSubscribableStoreQuery = /*#__PURE__*/function () {
|
|
7
|
-
function AbstractSubscribableStoreQuery() {}
|
|
8
|
-
|
|
9
|
-
var _proto = AbstractSubscribableStoreQuery.prototype;
|
|
10
|
-
|
|
11
|
-
_proto.changeParams = function changeParams() {
|
|
1
|
+
class AbstractSubscribableStoreQuery {
|
|
2
|
+
changeParams() {
|
|
12
3
|
throw new Error('Method not supported. Please create a new query.');
|
|
13
|
-
}
|
|
4
|
+
}
|
|
14
5
|
|
|
15
|
-
|
|
6
|
+
changePartialParams() {
|
|
16
7
|
throw new Error('Method not supported. Please create a new query.');
|
|
17
|
-
}
|
|
8
|
+
}
|
|
18
9
|
|
|
19
|
-
|
|
10
|
+
setSubscribeStore(store) {
|
|
20
11
|
this._subscribeStore = store;
|
|
21
|
-
}
|
|
12
|
+
}
|
|
22
13
|
|
|
23
|
-
|
|
14
|
+
getSubscribeStore() {
|
|
24
15
|
if (!this._subscribeStore) {
|
|
25
16
|
throw new Error('_subscribeStore is not initialized');
|
|
26
17
|
}
|
|
27
18
|
|
|
28
19
|
return this._subscribeStore;
|
|
29
|
-
}
|
|
20
|
+
}
|
|
30
21
|
|
|
31
|
-
|
|
22
|
+
fetchAndSubscribe(callback) {
|
|
32
23
|
return this._subscribe(callback, true);
|
|
33
|
-
}
|
|
24
|
+
}
|
|
34
25
|
|
|
35
|
-
|
|
26
|
+
subscribe(callback) {
|
|
36
27
|
return this._subscribe(callback, false);
|
|
37
|
-
}
|
|
28
|
+
}
|
|
38
29
|
|
|
39
|
-
|
|
40
|
-
}();
|
|
30
|
+
}
|
|
41
31
|
|
|
42
32
|
/* eslint-disable max-lines */
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
class SubscribeStore {
|
|
34
|
+
constructor(store) {
|
|
45
35
|
this.listeners = new Set();
|
|
46
36
|
this.store = store;
|
|
47
37
|
this.keyPath = store.keyPath;
|
|
48
38
|
}
|
|
49
39
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var _this = this;
|
|
40
|
+
get connection() {
|
|
41
|
+
return this.store.connection;
|
|
42
|
+
}
|
|
54
43
|
|
|
44
|
+
subscribe(callback) {
|
|
55
45
|
this.listeners.add(callback);
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
_proto.callSubscribed = function callSubscribed(action) {
|
|
62
|
-
this.listeners.forEach(function (listener) {
|
|
63
|
-
return listener(action);
|
|
64
|
-
});
|
|
65
|
-
};
|
|
46
|
+
return () => this.listeners.delete(callback);
|
|
47
|
+
}
|
|
66
48
|
|
|
67
|
-
|
|
68
|
-
|
|
49
|
+
callSubscribed(action) {
|
|
50
|
+
this.listeners.forEach(listener => listener(action));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
createQuerySingleItem(options, transformer) {
|
|
54
|
+
const query = this.store.createQuerySingleItem(options, transformer);
|
|
69
55
|
query.setSubscribeStore(this);
|
|
70
56
|
return query;
|
|
71
|
-
}
|
|
57
|
+
}
|
|
72
58
|
|
|
73
|
-
|
|
74
|
-
|
|
59
|
+
createQueryCollection(options, transformer) {
|
|
60
|
+
const query = this.store.createQueryCollection(options, transformer);
|
|
75
61
|
query.setSubscribeStore(this);
|
|
76
62
|
return query;
|
|
77
|
-
}
|
|
63
|
+
}
|
|
78
64
|
|
|
79
|
-
|
|
65
|
+
findAll(criteria, sort) {
|
|
80
66
|
return this.store.findAll(criteria, sort);
|
|
81
|
-
}
|
|
67
|
+
}
|
|
82
68
|
|
|
83
|
-
|
|
69
|
+
findByKey(key, criteria) {
|
|
84
70
|
return this.store.findByKey(key, criteria);
|
|
85
|
-
}
|
|
71
|
+
}
|
|
86
72
|
|
|
87
|
-
|
|
73
|
+
findOne(criteria, sort) {
|
|
88
74
|
return this.store.findOne(criteria, sort);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
replaced = _context2.sent;
|
|
134
|
-
this.callSubscribed({
|
|
135
|
-
type: 'updated',
|
|
136
|
-
changes: [[object, replaced]]
|
|
137
|
-
});
|
|
138
|
-
return _context2.abrupt("return", replaced);
|
|
139
|
-
|
|
140
|
-
case 5:
|
|
141
|
-
case "end":
|
|
142
|
-
return _context2.stop();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}, _callee2, this);
|
|
146
|
-
}));
|
|
147
|
-
|
|
148
|
-
return function replaceOne() {
|
|
149
|
-
return _replaceOne.apply(this, arguments);
|
|
150
|
-
};
|
|
151
|
-
}();
|
|
152
|
-
|
|
153
|
-
_proto.replaceSeveral = /*#__PURE__*/function () {
|
|
154
|
-
var _replaceSeveral = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(objects) {
|
|
155
|
-
var replacedObjects;
|
|
156
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
157
|
-
while (1) {
|
|
158
|
-
switch (_context3.prev = _context3.next) {
|
|
159
|
-
case 0:
|
|
160
|
-
_context3.next = 2;
|
|
161
|
-
return this.store.replaceSeveral(objects);
|
|
162
|
-
|
|
163
|
-
case 2:
|
|
164
|
-
replacedObjects = _context3.sent;
|
|
165
|
-
this.callSubscribed({
|
|
166
|
-
type: 'updated',
|
|
167
|
-
changes: objects.map(function (prev, index) {
|
|
168
|
-
return [prev, replacedObjects[index]];
|
|
169
|
-
})
|
|
170
|
-
});
|
|
171
|
-
return _context3.abrupt("return", replacedObjects);
|
|
172
|
-
|
|
173
|
-
case 5:
|
|
174
|
-
case "end":
|
|
175
|
-
return _context3.stop();
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}, _callee3, this);
|
|
179
|
-
}));
|
|
180
|
-
|
|
181
|
-
return function replaceSeveral() {
|
|
182
|
-
return _replaceSeveral.apply(this, arguments);
|
|
183
|
-
};
|
|
184
|
-
}();
|
|
185
|
-
|
|
186
|
-
_proto.upsertOne = /*#__PURE__*/function () {
|
|
187
|
-
var _upsertOne = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(object, setOnInsertPartialObject) {
|
|
188
|
-
var result;
|
|
189
|
-
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
190
|
-
while (1) {
|
|
191
|
-
switch (_context4.prev = _context4.next) {
|
|
192
|
-
case 0:
|
|
193
|
-
_context4.next = 2;
|
|
194
|
-
return this.upsertOneWithInfo(object, setOnInsertPartialObject);
|
|
195
|
-
|
|
196
|
-
case 2:
|
|
197
|
-
result = _context4.sent;
|
|
198
|
-
return _context4.abrupt("return", result.object);
|
|
199
|
-
|
|
200
|
-
case 4:
|
|
201
|
-
case "end":
|
|
202
|
-
return _context4.stop();
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}, _callee4, this);
|
|
206
|
-
}));
|
|
207
|
-
|
|
208
|
-
return function upsertOne() {
|
|
209
|
-
return _upsertOne.apply(this, arguments);
|
|
210
|
-
};
|
|
211
|
-
}();
|
|
212
|
-
|
|
213
|
-
_proto.upsertOneWithInfo = /*#__PURE__*/function () {
|
|
214
|
-
var _upsertOneWithInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(object, setOnInsertPartialObject) {
|
|
215
|
-
var upsertedWithInfo;
|
|
216
|
-
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
217
|
-
while (1) {
|
|
218
|
-
switch (_context5.prev = _context5.next) {
|
|
219
|
-
case 0:
|
|
220
|
-
_context5.next = 2;
|
|
221
|
-
return this.store.upsertOneWithInfo(object, setOnInsertPartialObject);
|
|
222
|
-
|
|
223
|
-
case 2:
|
|
224
|
-
upsertedWithInfo = _context5.sent;
|
|
225
|
-
|
|
226
|
-
if (!upsertedWithInfo.inserted) {
|
|
227
|
-
_context5.next = 7;
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
this.callSubscribed({
|
|
232
|
-
type: 'inserted',
|
|
233
|
-
next: [upsertedWithInfo.object]
|
|
234
|
-
});
|
|
235
|
-
_context5.next = 8;
|
|
236
|
-
break;
|
|
237
|
-
|
|
238
|
-
case 7:
|
|
239
|
-
throw new Error('TODO');
|
|
240
|
-
|
|
241
|
-
case 8:
|
|
242
|
-
return _context5.abrupt("return", upsertedWithInfo);
|
|
243
|
-
|
|
244
|
-
case 9:
|
|
245
|
-
case "end":
|
|
246
|
-
return _context5.stop();
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}, _callee5, this);
|
|
250
|
-
}));
|
|
251
|
-
|
|
252
|
-
return function upsertOneWithInfo() {
|
|
253
|
-
return _upsertOneWithInfo.apply(this, arguments);
|
|
254
|
-
};
|
|
255
|
-
}();
|
|
256
|
-
|
|
257
|
-
_proto.partialUpdateByKey = /*#__PURE__*/function () {
|
|
258
|
-
var _partialUpdateByKey = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(key, partialUpdate, criteria) {
|
|
259
|
-
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
260
|
-
while (1) {
|
|
261
|
-
switch (_context6.prev = _context6.next) {
|
|
262
|
-
case 0:
|
|
263
|
-
_context6.t0 = this;
|
|
264
|
-
_context6.next = 3;
|
|
265
|
-
return this.findOne(_extends({
|
|
266
|
-
[this.store.keyPath]: key
|
|
267
|
-
}, criteria));
|
|
268
|
-
|
|
269
|
-
case 3:
|
|
270
|
-
_context6.t1 = _context6.sent;
|
|
271
|
-
_context6.t2 = partialUpdate;
|
|
272
|
-
return _context6.abrupt("return", _context6.t0.partialUpdateOne.call(_context6.t0, _context6.t1, _context6.t2));
|
|
273
|
-
|
|
274
|
-
case 6:
|
|
275
|
-
case "end":
|
|
276
|
-
return _context6.stop();
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}, _callee6, this);
|
|
280
|
-
}));
|
|
281
|
-
|
|
282
|
-
return function partialUpdateByKey() {
|
|
283
|
-
return _partialUpdateByKey.apply(this, arguments);
|
|
284
|
-
};
|
|
285
|
-
}();
|
|
286
|
-
|
|
287
|
-
_proto.partialUpdateOne = /*#__PURE__*/function () {
|
|
288
|
-
var _partialUpdateOne = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(object, partialUpdate) {
|
|
289
|
-
var updated;
|
|
290
|
-
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
291
|
-
while (1) {
|
|
292
|
-
switch (_context7.prev = _context7.next) {
|
|
293
|
-
case 0:
|
|
294
|
-
_context7.next = 2;
|
|
295
|
-
return this.store.partialUpdateOne(object, partialUpdate);
|
|
296
|
-
|
|
297
|
-
case 2:
|
|
298
|
-
updated = _context7.sent;
|
|
299
|
-
this.callSubscribed({
|
|
300
|
-
type: 'updated',
|
|
301
|
-
changes: [[object, updated]]
|
|
302
|
-
});
|
|
303
|
-
return _context7.abrupt("return", updated);
|
|
304
|
-
|
|
305
|
-
case 5:
|
|
306
|
-
case "end":
|
|
307
|
-
return _context7.stop();
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}, _callee7, this);
|
|
311
|
-
}));
|
|
312
|
-
|
|
313
|
-
return function partialUpdateOne() {
|
|
314
|
-
return _partialUpdateOne.apply(this, arguments);
|
|
315
|
-
};
|
|
316
|
-
}();
|
|
317
|
-
|
|
318
|
-
_proto.partialUpdateMany = /*#__PURE__*/function () {
|
|
319
|
-
var _partialUpdateMany = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(criteria, partialUpdate) {
|
|
320
|
-
var _this2 = this;
|
|
321
|
-
|
|
322
|
-
var cursor, changes;
|
|
323
|
-
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
324
|
-
while (1) {
|
|
325
|
-
switch (_context9.prev = _context9.next) {
|
|
326
|
-
case 0:
|
|
327
|
-
_context9.next = 2;
|
|
328
|
-
return this.store.cursor(criteria);
|
|
329
|
-
|
|
330
|
-
case 2:
|
|
331
|
-
cursor = _context9.sent;
|
|
332
|
-
changes = [];
|
|
333
|
-
_context9.next = 6;
|
|
334
|
-
return cursor.forEach( /*#__PURE__*/function () {
|
|
335
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(model) {
|
|
336
|
-
var key, updated;
|
|
337
|
-
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
338
|
-
while (1) {
|
|
339
|
-
switch (_context8.prev = _context8.next) {
|
|
340
|
-
case 0:
|
|
341
|
-
key = model[_this2.store.keyPath];
|
|
342
|
-
_context8.next = 3;
|
|
343
|
-
return _this2.store.partialUpdateByKey(key, partialUpdate, criteria);
|
|
344
|
-
|
|
345
|
-
case 3:
|
|
346
|
-
updated = _context8.sent;
|
|
347
|
-
changes.push([model, updated]);
|
|
348
|
-
|
|
349
|
-
case 5:
|
|
350
|
-
case "end":
|
|
351
|
-
return _context8.stop();
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}, _callee8);
|
|
355
|
-
}));
|
|
356
|
-
|
|
357
|
-
return function () {
|
|
358
|
-
return _ref.apply(this, arguments);
|
|
359
|
-
};
|
|
360
|
-
}());
|
|
361
|
-
|
|
362
|
-
case 6:
|
|
363
|
-
this.callSubscribed({
|
|
364
|
-
type: 'updated',
|
|
365
|
-
changes: changes
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
case 7:
|
|
369
|
-
case "end":
|
|
370
|
-
return _context9.stop();
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}, _callee9, this);
|
|
374
|
-
}));
|
|
375
|
-
|
|
376
|
-
return function partialUpdateMany() {
|
|
377
|
-
return _partialUpdateMany.apply(this, arguments);
|
|
378
|
-
};
|
|
379
|
-
}();
|
|
380
|
-
|
|
381
|
-
_proto.deleteByKey = /*#__PURE__*/function () {
|
|
382
|
-
var _deleteByKey = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(key, criteria) {
|
|
383
|
-
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
384
|
-
while (1) {
|
|
385
|
-
switch (_context10.prev = _context10.next) {
|
|
386
|
-
case 0:
|
|
387
|
-
_context10.t0 = this;
|
|
388
|
-
_context10.next = 3;
|
|
389
|
-
return this.findByKey(key, criteria);
|
|
390
|
-
|
|
391
|
-
case 3:
|
|
392
|
-
_context10.t1 = _context10.sent;
|
|
393
|
-
return _context10.abrupt("return", _context10.t0.deleteOne.call(_context10.t0, _context10.t1));
|
|
394
|
-
|
|
395
|
-
case 5:
|
|
396
|
-
case "end":
|
|
397
|
-
return _context10.stop();
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}, _callee10, this);
|
|
401
|
-
}));
|
|
402
|
-
|
|
403
|
-
return function deleteByKey() {
|
|
404
|
-
return _deleteByKey.apply(this, arguments);
|
|
405
|
-
};
|
|
406
|
-
}();
|
|
407
|
-
|
|
408
|
-
_proto.deleteOne = /*#__PURE__*/function () {
|
|
409
|
-
var _deleteOne = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(object) {
|
|
410
|
-
return _regeneratorRuntime.wrap(function _callee11$(_context11) {
|
|
411
|
-
while (1) {
|
|
412
|
-
switch (_context11.prev = _context11.next) {
|
|
413
|
-
case 0:
|
|
414
|
-
_context11.next = 2;
|
|
415
|
-
return this.store.deleteOne(object);
|
|
416
|
-
|
|
417
|
-
case 2:
|
|
418
|
-
this.callSubscribed({
|
|
419
|
-
type: 'deleted',
|
|
420
|
-
prev: [object]
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
case 3:
|
|
424
|
-
case "end":
|
|
425
|
-
return _context11.stop();
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}, _callee11, this);
|
|
429
|
-
}));
|
|
430
|
-
|
|
431
|
-
return function deleteOne() {
|
|
432
|
-
return _deleteOne.apply(this, arguments);
|
|
433
|
-
};
|
|
434
|
-
}();
|
|
435
|
-
|
|
436
|
-
_proto.deleteMany = /*#__PURE__*/function () {
|
|
437
|
-
var _deleteMany = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(criteria) {
|
|
438
|
-
var cursor, prev;
|
|
439
|
-
return _regeneratorRuntime.wrap(function _callee12$(_context12) {
|
|
440
|
-
while (1) {
|
|
441
|
-
switch (_context12.prev = _context12.next) {
|
|
442
|
-
case 0:
|
|
443
|
-
_context12.next = 2;
|
|
444
|
-
return this.store.cursor(criteria);
|
|
445
|
-
|
|
446
|
-
case 2:
|
|
447
|
-
cursor = _context12.sent;
|
|
448
|
-
_context12.next = 5;
|
|
449
|
-
return cursor.toArray();
|
|
450
|
-
|
|
451
|
-
case 5:
|
|
452
|
-
prev = _context12.sent;
|
|
453
|
-
_context12.next = 8;
|
|
454
|
-
return this.store.deleteMany(criteria);
|
|
455
|
-
|
|
456
|
-
case 8:
|
|
457
|
-
this.callSubscribed({
|
|
458
|
-
type: 'deleted',
|
|
459
|
-
prev: prev
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
case 9:
|
|
463
|
-
case "end":
|
|
464
|
-
return _context12.stop();
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}, _callee12, this);
|
|
468
|
-
}));
|
|
469
|
-
|
|
470
|
-
return function deleteMany() {
|
|
471
|
-
return _deleteMany.apply(this, arguments);
|
|
472
|
-
};
|
|
473
|
-
}();
|
|
474
|
-
|
|
475
|
-
_proto.cursor = /*#__PURE__*/function () {
|
|
476
|
-
var _cursor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(criteria, sort) {
|
|
477
|
-
var cursor;
|
|
478
|
-
return _regeneratorRuntime.wrap(function _callee13$(_context13) {
|
|
479
|
-
while (1) {
|
|
480
|
-
switch (_context13.prev = _context13.next) {
|
|
481
|
-
case 0:
|
|
482
|
-
_context13.next = 2;
|
|
483
|
-
return this.store.cursor(criteria, sort);
|
|
484
|
-
|
|
485
|
-
case 2:
|
|
486
|
-
cursor = _context13.sent;
|
|
487
|
-
cursor.overrideStore(this);
|
|
488
|
-
return _context13.abrupt("return", cursor);
|
|
489
|
-
|
|
490
|
-
case 5:
|
|
491
|
-
case "end":
|
|
492
|
-
return _context13.stop();
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
}, _callee13, this);
|
|
496
|
-
}));
|
|
497
|
-
|
|
498
|
-
return function cursor() {
|
|
499
|
-
return _cursor.apply(this, arguments);
|
|
500
|
-
};
|
|
501
|
-
}();
|
|
502
|
-
|
|
503
|
-
_createClass(SubscribeStore, [{
|
|
504
|
-
key: "connection",
|
|
505
|
-
get: function get() {
|
|
506
|
-
return this.store.connection;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async insertOne(object) {
|
|
78
|
+
const inserted = await this.store.insertOne(object);
|
|
79
|
+
this.callSubscribed({
|
|
80
|
+
type: 'inserted',
|
|
81
|
+
next: [inserted]
|
|
82
|
+
});
|
|
83
|
+
return inserted;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async replaceOne(object) {
|
|
87
|
+
const replaced = await this.store.replaceOne(object);
|
|
88
|
+
this.callSubscribed({
|
|
89
|
+
type: 'updated',
|
|
90
|
+
changes: [[object, replaced]]
|
|
91
|
+
});
|
|
92
|
+
return replaced;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async replaceSeveral(objects) {
|
|
96
|
+
const replacedObjects = await this.store.replaceSeveral(objects);
|
|
97
|
+
this.callSubscribed({
|
|
98
|
+
type: 'updated',
|
|
99
|
+
changes: objects.map((prev, index) => [prev, replacedObjects[index]])
|
|
100
|
+
});
|
|
101
|
+
return replacedObjects;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async upsertOne(object, setOnInsertPartialObject) {
|
|
105
|
+
const result = await this.upsertOneWithInfo(object, setOnInsertPartialObject);
|
|
106
|
+
return result.object;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async upsertOneWithInfo(object, setOnInsertPartialObject) {
|
|
110
|
+
const upsertedWithInfo = await this.store.upsertOneWithInfo(object, setOnInsertPartialObject);
|
|
111
|
+
|
|
112
|
+
if (upsertedWithInfo.inserted) {
|
|
113
|
+
this.callSubscribed({
|
|
114
|
+
type: 'inserted',
|
|
115
|
+
next: [upsertedWithInfo.object]
|
|
116
|
+
});
|
|
117
|
+
} else {
|
|
118
|
+
throw new Error('TODO');
|
|
507
119
|
}
|
|
508
|
-
}]);
|
|
509
120
|
|
|
510
|
-
|
|
511
|
-
}
|
|
121
|
+
return upsertedWithInfo;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async partialUpdateByKey(key, partialUpdate, criteria) {
|
|
125
|
+
return this.partialUpdateOne(await this.findOne({
|
|
126
|
+
[this.store.keyPath]: key,
|
|
127
|
+
...criteria
|
|
128
|
+
}), partialUpdate);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async partialUpdateOne(object, partialUpdate) {
|
|
132
|
+
const updated = await this.store.partialUpdateOne(object, partialUpdate);
|
|
133
|
+
this.callSubscribed({
|
|
134
|
+
type: 'updated',
|
|
135
|
+
changes: [[object, updated]]
|
|
136
|
+
});
|
|
137
|
+
return updated;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async partialUpdateMany(criteria, partialUpdate) {
|
|
141
|
+
const cursor = await this.store.cursor(criteria);
|
|
142
|
+
const changes = [];
|
|
143
|
+
await cursor.forEach(async model => {
|
|
144
|
+
const key = model[this.store.keyPath];
|
|
145
|
+
const updated = await this.store.partialUpdateByKey(key, partialUpdate, criteria);
|
|
146
|
+
changes.push([model, updated]);
|
|
147
|
+
});
|
|
148
|
+
this.callSubscribed({
|
|
149
|
+
type: 'updated',
|
|
150
|
+
changes
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async deleteByKey(key, criteria) {
|
|
155
|
+
return this.deleteOne(await this.findByKey(key, criteria));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async deleteOne(object) {
|
|
159
|
+
await this.store.deleteOne(object);
|
|
160
|
+
this.callSubscribed({
|
|
161
|
+
type: 'deleted',
|
|
162
|
+
prev: [object]
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async deleteMany(criteria) {
|
|
167
|
+
const cursor = await this.store.cursor(criteria);
|
|
168
|
+
const prev = await cursor.toArray();
|
|
169
|
+
await this.store.deleteMany(criteria);
|
|
170
|
+
this.callSubscribed({
|
|
171
|
+
type: 'deleted',
|
|
172
|
+
prev
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async cursor(criteria, sort) {
|
|
177
|
+
const cursor = await this.store.cursor(criteria, sort);
|
|
178
|
+
cursor.overrideStore(this);
|
|
179
|
+
return cursor;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
}
|
|
512
183
|
|
|
513
184
|
export { AbstractSubscribableStoreQuery, SubscribeStore };
|
|
514
185
|
//# sourceMappingURL=index-browser-dev.es.js.map
|