liwi-subscribe-store 8.3.1 → 9.1.0

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