liwi-subscribe-store 10.4.0 → 12.0.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.
package/CHANGELOG.md CHANGED
@@ -1,8 +1,35 @@
1
- # Change Log
1
+ # Changelog
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 12.0.0 (2024-03-30)
7
+
8
+
9
+ ### ⚠ BREAKING CHANGES
10
+
11
+ * update dev deps incuding babel which changes supported built files for browser
12
+
13
+ ### Miscellaneous Chores
14
+
15
+ * update dev deps incuding babel which changes supported built files for browser ([462bf2e](https://github.com/liwijs/liwi/commit/462bf2e0bb3a6b8c9304106bc447bd248e3a61c7))
16
+
17
+ Version bump for dependency: liwi-store
18
+
19
+
20
+ ## [11.0.0](https://github.com/liwijs/liwi/compare/v10.5.0...v11.0.0) (2023-07-29)
21
+
22
+
23
+ ### ⚠ BREAKING CHANGES
24
+
25
+ * drop node 16
26
+
27
+ ### Code Refactoring
28
+
29
+ * update to node 18 ([e2dcbf8](https://github.com/liwijs/liwi/commit/e2dcbf8f5f6f32da6daa583fe352a453231c0c40))
30
+
31
+
32
+
6
33
  ## [10.4.0](https://github.com/liwijs/liwi/compare/v10.3.3...v10.4.0) (2023-07-28)
7
34
 
8
35
 
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractSubscribableStoreQuery.d.ts","sourceRoot":"","sources":["../../src/AbstractSubscribableStoreQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,SAAS,EACT,UAAU,EACV,eAAe,EAChB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,8BAA8B,CAC1D,OAAO,SAAS,MAAM,KAAK,EAC3B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C,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,iBAAiB;IAI3E,QAAQ,CAAC,UAAU,CACjB,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,EAC7C,eAAe,EAAE,OAAO,GACvB,iBAAiB;CACrB"}
@@ -1,451 +1,161 @@
1
- import _extends from '@babel/runtime/helpers/esm/extends';
2
- import _regeneratorRuntime from '@babel/runtime/helpers/esm/regeneratorRuntime';
3
- import _asyncToGenerator from '@babel/runtime/helpers/esm/asyncToGenerator';
4
- import _createClass from '@babel/runtime/helpers/esm/createClass';
5
-
6
1
  /* eslint-disable max-lines */
7
- var SubscribeStore = /*#__PURE__*/function () {
8
- function SubscribeStore(store) {
2
+
3
+ class SubscribeStore {
4
+ constructor(store) {
9
5
  this.listeners = new Set();
10
6
  this.store = store;
11
7
  this.keyPath = store.keyPath;
12
8
  }
13
- var _proto = SubscribeStore.prototype;
14
- _proto.subscribe = function subscribe(callback) {
9
+ get connection() {
10
+ return this.store.connection;
11
+ }
12
+ subscribe(callback) {
15
13
  this.listeners.add(callback);
16
- return function () {
17
- return this.listeners.delete(callback);
18
- };
19
- };
20
- _proto.callSubscribed = function callSubscribed(action) {
21
- this.listeners.forEach(function (listener) {
22
- return listener(action);
23
- });
24
- };
25
- _proto.createQuerySingleItem = function createQuerySingleItem(options, transformer) {
26
- var query = this.store.createQuerySingleItem(options, transformer);
14
+ return () => this.listeners.delete(callback);
15
+ }
16
+ callSubscribed(action) {
17
+ this.listeners.forEach(listener => listener(action));
18
+ }
19
+ createQuerySingleItem(options, transformer) {
20
+ const query = this.store.createQuerySingleItem(options, transformer);
27
21
  query.setSubscribeStore(this);
28
22
  return query;
29
- };
30
- _proto.createQueryCollection = function createQueryCollection(options, transformer) {
31
- var query = this.store.createQueryCollection(options, transformer);
23
+ }
24
+ createQueryCollection(options, transformer) {
25
+ const query = this.store.createQueryCollection(options, transformer);
32
26
  query.setSubscribeStore(this);
33
27
  return query;
34
- };
35
- _proto.findAll = function findAll(criteria, sort) {
28
+ }
29
+ findAll(criteria, sort) {
36
30
  return this.store.findAll(criteria, sort);
37
- };
38
- _proto.findByKey = function findByKey(key, criteria) {
31
+ }
32
+ findByKey(key, criteria) {
39
33
  return this.store.findByKey(key, criteria);
40
- };
41
- _proto.findOne = function findOne(criteria, sort) {
34
+ }
35
+ findOne(criteria, sort) {
42
36
  return this.store.findOne(criteria, sort);
43
- };
44
- _proto.insertOne = /*#__PURE__*/function () {
45
- var _insertOne = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(object) {
46
- var inserted;
47
- return _regeneratorRuntime().wrap(function _callee$(_context) {
48
- while (1) {
49
- switch (_context.prev = _context.next) {
50
- case 0:
51
- _context.next = 2;
52
- return this.store.insertOne(object);
53
- case 2:
54
- inserted = _context.sent;
55
- this.callSubscribed({
56
- type: 'inserted',
57
- next: [inserted]
58
- });
59
- return _context.abrupt("return", inserted);
60
- case 5:
61
- case "end":
62
- return _context.stop();
63
- }
64
- }
65
- }, _callee, this);
66
- }));
67
- return function insertOne() {
68
- return _insertOne.apply(this, arguments);
69
- };
70
- }();
71
- _proto.replaceOne = /*#__PURE__*/function () {
72
- var _replaceOne = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(object) {
73
- var replaced;
74
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
75
- while (1) {
76
- switch (_context2.prev = _context2.next) {
77
- case 0:
78
- _context2.next = 2;
79
- return this.store.replaceOne(object);
80
- case 2:
81
- replaced = _context2.sent;
82
- this.callSubscribed({
83
- type: 'updated',
84
- changes: [[object, replaced]]
85
- });
86
- return _context2.abrupt("return", replaced);
87
- case 5:
88
- case "end":
89
- return _context2.stop();
90
- }
91
- }
92
- }, _callee2, this);
93
- }));
94
- return function replaceOne() {
95
- return _replaceOne.apply(this, arguments);
96
- };
97
- }();
98
- _proto.replaceSeveral = /*#__PURE__*/function () {
99
- var _replaceSeveral = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(objects) {
100
- var replacedObjects;
101
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
102
- while (1) {
103
- switch (_context3.prev = _context3.next) {
104
- case 0:
105
- _context3.next = 2;
106
- return this.store.replaceSeveral(objects);
107
- case 2:
108
- replacedObjects = _context3.sent;
109
- this.callSubscribed({
110
- type: 'updated',
111
- changes: objects.map(function (prev, index) {
112
- return [prev, replacedObjects[index]];
113
- })
114
- });
115
- return _context3.abrupt("return", replacedObjects);
116
- case 5:
117
- case "end":
118
- return _context3.stop();
119
- }
120
- }
121
- }, _callee3, this);
122
- }));
123
- return function replaceSeveral() {
124
- return _replaceSeveral.apply(this, arguments);
125
- };
126
- }();
127
- _proto.upsertOne = /*#__PURE__*/function () {
128
- var _upsertOne = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(object, setOnInsertPartialObject) {
129
- var result;
130
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
131
- while (1) {
132
- switch (_context4.prev = _context4.next) {
133
- case 0:
134
- _context4.next = 2;
135
- return this.upsertOneWithInfo(object, setOnInsertPartialObject);
136
- case 2:
137
- result = _context4.sent;
138
- return _context4.abrupt("return", result.object);
139
- case 4:
140
- case "end":
141
- return _context4.stop();
142
- }
143
- }
144
- }, _callee4, this);
145
- }));
146
- return function upsertOne() {
147
- return _upsertOne.apply(this, arguments);
148
- };
149
- }();
150
- _proto.upsertOneWithInfo = /*#__PURE__*/function () {
151
- var _upsertOneWithInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(object, setOnInsertPartialObject) {
152
- var upsertedWithInfo;
153
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
154
- while (1) {
155
- switch (_context5.prev = _context5.next) {
156
- case 0:
157
- _context5.next = 2;
158
- return this.store.upsertOneWithInfo(object, setOnInsertPartialObject);
159
- case 2:
160
- upsertedWithInfo = _context5.sent;
161
- if (!upsertedWithInfo.inserted) {
162
- _context5.next = 7;
163
- break;
164
- }
165
- this.callSubscribed({
166
- type: 'inserted',
167
- next: [upsertedWithInfo.object]
168
- });
169
- _context5.next = 8;
170
- break;
171
- case 7:
172
- throw new Error('TODO');
173
- case 8:
174
- return _context5.abrupt("return", upsertedWithInfo);
175
- case 9:
176
- case "end":
177
- return _context5.stop();
178
- }
179
- }
180
- }, _callee5, this);
181
- }));
182
- return function upsertOneWithInfo() {
183
- return _upsertOneWithInfo.apply(this, arguments);
184
- };
185
- }();
186
- _proto.partialUpdateByKey = /*#__PURE__*/function () {
187
- var _partialUpdateByKey = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(key, partialUpdate, criteria) {
188
- var _extends2;
189
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
190
- while (1) {
191
- switch (_context6.prev = _context6.next) {
192
- case 0:
193
- _context6.t0 = this;
194
- _context6.next = 3;
195
- return this.findOne(_extends((_extends2 = {}, _extends2[this.store.keyPath] = key, _extends2), criteria));
196
- case 3:
197
- _context6.t1 = _context6.sent;
198
- _context6.t2 = partialUpdate;
199
- return _context6.abrupt("return", _context6.t0.partialUpdateOne.call(_context6.t0, _context6.t1, _context6.t2));
200
- case 6:
201
- case "end":
202
- return _context6.stop();
203
- }
204
- }
205
- }, _callee6, this);
206
- }));
207
- return function partialUpdateByKey() {
208
- return _partialUpdateByKey.apply(this, arguments);
209
- };
210
- }();
211
- _proto.partialUpdateOne = /*#__PURE__*/function () {
212
- var _partialUpdateOne = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(object, partialUpdate) {
213
- var updated;
214
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
215
- while (1) {
216
- switch (_context7.prev = _context7.next) {
217
- case 0:
218
- _context7.next = 2;
219
- return this.store.partialUpdateOne(object, partialUpdate);
220
- case 2:
221
- updated = _context7.sent;
222
- this.callSubscribed({
223
- type: 'updated',
224
- changes: [[object, updated]]
225
- });
226
- return _context7.abrupt("return", updated);
227
- case 5:
228
- case "end":
229
- return _context7.stop();
230
- }
231
- }
232
- }, _callee7, this);
233
- }));
234
- return function partialUpdateOne() {
235
- return _partialUpdateOne.apply(this, arguments);
236
- };
237
- }();
238
- _proto.partialUpdateMany = /*#__PURE__*/function () {
239
- var _partialUpdateMany = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(criteria, partialUpdate) {
240
- var _this2 = this;
241
- var cursor, changes;
242
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
243
- while (1) {
244
- switch (_context9.prev = _context9.next) {
245
- case 0:
246
- _context9.next = 2;
247
- return this.store.cursor(criteria);
248
- case 2:
249
- cursor = _context9.sent;
250
- changes = [];
251
- _context9.next = 6;
252
- return cursor.forEach( /*#__PURE__*/function () {
253
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(model) {
254
- var key, updated;
255
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
256
- while (1) {
257
- switch (_context8.prev = _context8.next) {
258
- case 0:
259
- key = model[_this2.store.keyPath];
260
- _context8.next = 3;
261
- return _this2.store.partialUpdateByKey(key, partialUpdate, criteria);
262
- case 3:
263
- updated = _context8.sent;
264
- changes.push([model, updated]);
265
- case 5:
266
- case "end":
267
- return _context8.stop();
268
- }
269
- }
270
- }, _callee8);
271
- }));
272
- return function () {
273
- return _ref.apply(this, arguments);
274
- };
275
- }());
276
- case 6:
277
- this.callSubscribed({
278
- type: 'updated',
279
- changes: changes
280
- });
281
- case 7:
282
- case "end":
283
- return _context9.stop();
284
- }
285
- }
286
- }, _callee9, this);
287
- }));
288
- return function partialUpdateMany() {
289
- return _partialUpdateMany.apply(this, arguments);
290
- };
291
- }();
292
- _proto.deleteByKey = /*#__PURE__*/function () {
293
- var _deleteByKey = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(key, criteria) {
294
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
295
- while (1) {
296
- switch (_context10.prev = _context10.next) {
297
- case 0:
298
- _context10.t0 = this;
299
- _context10.next = 3;
300
- return this.findByKey(key, criteria);
301
- case 3:
302
- _context10.t1 = _context10.sent;
303
- return _context10.abrupt("return", _context10.t0.deleteOne.call(_context10.t0, _context10.t1));
304
- case 5:
305
- case "end":
306
- return _context10.stop();
307
- }
308
- }
309
- }, _callee10, this);
310
- }));
311
- return function deleteByKey() {
312
- return _deleteByKey.apply(this, arguments);
313
- };
314
- }();
315
- _proto.deleteOne = /*#__PURE__*/function () {
316
- var _deleteOne = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(object) {
317
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
318
- while (1) {
319
- switch (_context11.prev = _context11.next) {
320
- case 0:
321
- _context11.next = 2;
322
- return this.store.deleteOne(object);
323
- case 2:
324
- this.callSubscribed({
325
- type: 'deleted',
326
- prev: [object]
327
- });
328
- case 3:
329
- case "end":
330
- return _context11.stop();
331
- }
332
- }
333
- }, _callee11, this);
334
- }));
335
- return function deleteOne() {
336
- return _deleteOne.apply(this, arguments);
337
- };
338
- }();
339
- _proto.deleteMany = /*#__PURE__*/function () {
340
- var _deleteMany = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(criteria) {
341
- var cursor, prev;
342
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
343
- while (1) {
344
- switch (_context12.prev = _context12.next) {
345
- case 0:
346
- _context12.next = 2;
347
- return this.store.cursor(criteria);
348
- case 2:
349
- cursor = _context12.sent;
350
- _context12.next = 5;
351
- return cursor.toArray();
352
- case 5:
353
- prev = _context12.sent;
354
- _context12.next = 8;
355
- return this.store.deleteMany(criteria);
356
- case 8:
357
- this.callSubscribed({
358
- type: 'deleted',
359
- prev: prev
360
- });
361
- case 9:
362
- case "end":
363
- return _context12.stop();
364
- }
365
- }
366
- }, _callee12, this);
367
- }));
368
- return function deleteMany() {
369
- return _deleteMany.apply(this, arguments);
370
- };
371
- }();
372
- _proto.count = /*#__PURE__*/function () {
373
- var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(criteria) {
374
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
375
- while (1) {
376
- switch (_context13.prev = _context13.next) {
377
- case 0:
378
- return _context13.abrupt("return", this.store.count(criteria));
379
- case 1:
380
- case "end":
381
- return _context13.stop();
382
- }
383
- }
384
- }, _callee13, this);
385
- }));
386
- return function count() {
387
- return _count.apply(this, arguments);
388
- };
389
- }();
390
- _proto.cursor = /*#__PURE__*/function () {
391
- var _cursor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(criteria, sort) {
392
- var cursor;
393
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
394
- while (1) {
395
- switch (_context14.prev = _context14.next) {
396
- case 0:
397
- _context14.next = 2;
398
- return this.store.cursor(criteria, sort);
399
- case 2:
400
- cursor = _context14.sent;
401
- cursor.overrideStore(this);
402
- return _context14.abrupt("return", cursor);
403
- case 5:
404
- case "end":
405
- return _context14.stop();
406
- }
407
- }
408
- }, _callee14, this);
409
- }));
410
- return function cursor() {
411
- return _cursor.apply(this, arguments);
412
- };
413
- }();
414
- _createClass(SubscribeStore, [{
415
- key: "connection",
416
- get: function get() {
417
- return this.store.connection;
37
+ }
38
+ async insertOne(object) {
39
+ const inserted = await this.store.insertOne(object);
40
+ this.callSubscribed({
41
+ type: 'inserted',
42
+ next: [inserted]
43
+ });
44
+ return inserted;
45
+ }
46
+ async replaceOne(object) {
47
+ const replaced = await this.store.replaceOne(object);
48
+ this.callSubscribed({
49
+ type: 'updated',
50
+ changes: [[object, replaced]]
51
+ });
52
+ return replaced;
53
+ }
54
+ async replaceSeveral(objects) {
55
+ const replacedObjects = await this.store.replaceSeveral(objects);
56
+ this.callSubscribed({
57
+ type: 'updated',
58
+ changes: objects.map((prev, index) => [prev, replacedObjects[index]])
59
+ });
60
+ return replacedObjects;
61
+ }
62
+ async upsertOne(object, setOnInsertPartialObject) {
63
+ const result = await this.upsertOneWithInfo(object, setOnInsertPartialObject);
64
+ return result.object;
65
+ }
66
+ async upsertOneWithInfo(object, setOnInsertPartialObject) {
67
+ const upsertedWithInfo = await this.store.upsertOneWithInfo(object, setOnInsertPartialObject);
68
+ if (upsertedWithInfo.inserted) {
69
+ this.callSubscribed({
70
+ type: 'inserted',
71
+ next: [upsertedWithInfo.object]
72
+ });
73
+ } else {
74
+ throw new Error('TODO');
418
75
  }
419
- }]);
420
- return SubscribeStore;
421
- }();
76
+ return upsertedWithInfo;
77
+ }
78
+ async partialUpdateByKey(key, partialUpdate, criteria) {
79
+ return this.partialUpdateOne(await this.findOne({
80
+ [this.store.keyPath]: key,
81
+ ...criteria
82
+ }), partialUpdate);
83
+ }
84
+ async partialUpdateOne(object, partialUpdate) {
85
+ const updated = await this.store.partialUpdateOne(object, partialUpdate);
86
+ this.callSubscribed({
87
+ type: 'updated',
88
+ changes: [[object, updated]]
89
+ });
90
+ return updated;
91
+ }
92
+ async partialUpdateMany(criteria, partialUpdate) {
93
+ const cursor = await this.store.cursor(criteria);
94
+ const changes = [];
95
+ await cursor.forEach(async model => {
96
+ const key = model[this.store.keyPath];
97
+ const updated = await this.store.partialUpdateByKey(key, partialUpdate, criteria);
98
+ changes.push([model, updated]);
99
+ });
100
+ this.callSubscribed({
101
+ type: 'updated',
102
+ changes
103
+ });
104
+ }
105
+ async deleteByKey(key, criteria) {
106
+ return this.deleteOne(await this.findByKey(key, criteria));
107
+ }
108
+ async deleteOne(object) {
109
+ await this.store.deleteOne(object);
110
+ this.callSubscribed({
111
+ type: 'deleted',
112
+ prev: [object]
113
+ });
114
+ }
115
+ async deleteMany(criteria) {
116
+ const cursor = await this.store.cursor(criteria);
117
+ const prev = await cursor.toArray();
118
+ await this.store.deleteMany(criteria);
119
+ this.callSubscribed({
120
+ type: 'deleted',
121
+ prev
122
+ });
123
+ }
124
+ async count(criteria) {
125
+ return this.store.count(criteria);
126
+ }
127
+ async cursor(criteria, sort) {
128
+ const cursor = await this.store.cursor(criteria, sort);
129
+ cursor.overrideStore(this);
130
+ return cursor;
131
+ }
132
+ }
133
+
134
+ /* eslint-disable @typescript-eslint/class-methods-use-this */
422
135
 
423
- var AbstractSubscribableStoreQuery = /*#__PURE__*/function () {
424
- function AbstractSubscribableStoreQuery() {}
425
- var _proto = AbstractSubscribableStoreQuery.prototype;
426
- _proto.changeParams = function changeParams() {
136
+ class AbstractSubscribableStoreQuery {
137
+ changeParams() {
427
138
  throw new Error('Method not supported. Please create a new query.');
428
- };
429
- _proto.changePartialParams = function changePartialParams() {
139
+ }
140
+ changePartialParams() {
430
141
  throw new Error('Method not supported. Please create a new query.');
431
- };
432
- _proto.setSubscribeStore = function setSubscribeStore(store) {
142
+ }
143
+ setSubscribeStore(store) {
433
144
  this._subscribeStore = store;
434
- };
435
- _proto.getSubscribeStore = function getSubscribeStore() {
145
+ }
146
+ getSubscribeStore() {
436
147
  if (!this._subscribeStore) {
437
148
  throw new Error('_subscribeStore is not initialized');
438
149
  }
439
150
  return this._subscribeStore;
440
- };
441
- _proto.fetchAndSubscribe = function fetchAndSubscribe(callback) {
151
+ }
152
+ fetchAndSubscribe(callback) {
442
153
  return this._subscribe(callback, true);
443
- };
444
- _proto.subscribe = function subscribe(callback) {
154
+ }
155
+ subscribe(callback) {
445
156
  return this._subscribe(callback, false);
446
- };
447
- return AbstractSubscribableStoreQuery;
448
- }();
157
+ }
158
+ }
449
159
 
450
160
  export { AbstractSubscribableStoreQuery, SubscribeStore };
451
161
  //# sourceMappingURL=index-browser.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-browser.es.js","sources":["../src/SubscribeStore.ts","../src/AbstractSubscribableStoreQuery.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type {\n Store as StoreInterface,\n AbstractConnection,\n UpsertResult,\n SubscribableStoreQuery,\n AbstractStoreCursor,\n SubscribableStore,\n QueryParams,\n UpsertPartialObject,\n BaseModel,\n InsertType,\n Update,\n Criteria,\n Sort,\n QueryOptions,\n Transformer,\n AllowedKeyValue,\n OptionalBaseModelKeysForInsert,\n} from 'liwi-store';\n\nexport type Actions<Model> =\n | { type: 'deleted'; prev: Model[] }\n | { type: 'inserted'; next: Model[] }\n | { type: 'updated'; changes: [Model, Model][] };\n\nexport type Listener<Model> = (action: Actions<Model>) => unknown;\n\nexport default class SubscribeStore<\n KeyPath extends keyof Model,\n KeyValue extends AllowedKeyValue,\n Model extends BaseModel & Record<KeyPath, KeyValue>,\n ModelInsertType extends InsertType<Model, KeyPath>,\n Connection extends AbstractConnection,\n Store extends SubscribableStore<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n Connection\n >,\n> implements\n StoreInterface<KeyPath, KeyValue, Model, ModelInsertType, Connection>\n{\n private readonly store: Store;\n\n private readonly listeners = new Set<Listener<Model>>();\n\n readonly keyPath: KeyPath;\n\n constructor(store: Store) {\n this.store = store;\n this.keyPath = store.keyPath;\n }\n\n get connection(): Connection {\n return this.store.connection;\n }\n\n subscribe(callback: Listener<Model>): () => void {\n this.listeners.add(callback);\n return () => this.listeners.delete(callback);\n }\n\n callSubscribed(action: Actions<Model>): void {\n this.listeners.forEach((listener) => listener(action));\n }\n\n createQuerySingleItem<\n Result extends Record<KeyPath, KeyValue>,\n Params extends QueryParams<Params>,\n >(\n options: QueryOptions<Model>,\n transformer?: Transformer<Model, Result>,\n ): SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Result,\n Params\n > {\n const query: SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Result,\n Params\n > = this.store.createQuerySingleItem<Result, Params>(options, transformer);\n query.setSubscribeStore(this);\n return query;\n }\n\n createQueryCollection<\n Item extends Record<KeyPath, KeyValue>,\n Params extends QueryParams<Params>,\n >(\n options: QueryOptions<Model>,\n transformer?: Transformer<Model, Item>,\n ): SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Item[],\n Params\n > {\n const query: SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Item[],\n Params\n > = this.store.createQueryCollection<Item, Params>(options, transformer);\n query.setSubscribeStore(this);\n return query;\n }\n\n findAll(criteria?: Criteria<Model>, sort?: Sort<Model>): Promise<Model[]> {\n return this.store.findAll(criteria, sort);\n }\n\n findByKey(\n key: KeyValue,\n criteria?: Criteria<Model>,\n ): Promise<Model | undefined> {\n return this.store.findByKey(key, criteria);\n }\n\n findOne(\n criteria: Criteria<Model>,\n sort?: Sort<Model>,\n ): Promise<Model | undefined> {\n return this.store.findOne(criteria, sort);\n }\n\n async insertOne(object: ModelInsertType): Promise<Model> {\n const inserted = await this.store.insertOne(object);\n this.callSubscribed({ type: 'inserted', next: [inserted] });\n return inserted;\n }\n\n async replaceOne(object: Model): Promise<Model> {\n const replaced = await this.store.replaceOne(object);\n this.callSubscribed({ type: 'updated', changes: [[object, replaced]] });\n return replaced;\n }\n\n async replaceSeveral(objects: Model[]): Promise<Model[]> {\n const replacedObjects = await this.store.replaceSeveral(objects);\n this.callSubscribed({\n type: 'updated',\n changes: objects.map((prev, index) => [prev, replacedObjects[index]]),\n });\n return replacedObjects;\n }\n\n async upsertOne<\n K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>,\n >(\n object: UpsertPartialObject<KeyPath, KeyValue, Model, K>,\n setOnInsertPartialObject?: Update<Model>['$setOnInsert'],\n ): Promise<Model> {\n const result = await this.upsertOneWithInfo(\n object,\n setOnInsertPartialObject,\n );\n return result.object;\n }\n\n async upsertOneWithInfo<\n K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>,\n >(\n object: UpsertPartialObject<KeyPath, KeyValue, Model, K>,\n setOnInsertPartialObject?: Update<Model>['$setOnInsert'],\n ): Promise<UpsertResult<Model>> {\n const upsertedWithInfo = await this.store.upsertOneWithInfo(\n object,\n setOnInsertPartialObject,\n );\n if (upsertedWithInfo.inserted) {\n this.callSubscribed({\n type: 'inserted',\n next: [upsertedWithInfo.object],\n });\n } else {\n throw new Error('TODO');\n }\n return upsertedWithInfo;\n }\n\n async partialUpdateByKey(\n key: KeyValue,\n partialUpdate: Update<Model>,\n criteria?: Criteria<Model>,\n ): Promise<Model> {\n return this.partialUpdateOne(\n (await this.findOne({\n [this.store.keyPath]: key,\n ...criteria,\n } as Criteria<Model>))!,\n partialUpdate,\n );\n }\n\n async partialUpdateOne(\n object: Model,\n partialUpdate: Update<Model>,\n ): Promise<Model> {\n const updated = await this.store.partialUpdateOne(object, partialUpdate);\n this.callSubscribed({ type: 'updated', changes: [[object, updated]] });\n return updated;\n }\n\n async partialUpdateMany(\n criteria: Criteria<Model>,\n partialUpdate: Update<Model>,\n ): Promise<void> {\n const cursor = await this.store.cursor(criteria);\n const changes: [Model, Model][] = [];\n\n await cursor.forEach(async (model) => {\n const key = model[this.store.keyPath];\n const updated = await this.store.partialUpdateByKey(\n key,\n partialUpdate,\n criteria,\n );\n changes.push([model, updated]);\n });\n this.callSubscribed({ type: 'updated', changes });\n }\n\n async deleteByKey(key: KeyValue, criteria?: Criteria<Model>): Promise<void> {\n return this.deleteOne((await this.findByKey(key, criteria))!);\n }\n\n async deleteOne(object: Model): Promise<void> {\n await this.store.deleteOne(object);\n this.callSubscribed({ type: 'deleted', prev: [object] });\n }\n\n async deleteMany(criteria: Criteria<Model>): Promise<void> {\n const cursor = await this.store.cursor(criteria);\n const prev: Model[] = await cursor.toArray();\n await this.store.deleteMany(criteria);\n this.callSubscribed({ type: 'deleted', prev });\n }\n\n async count(criteria?: Criteria<Model>): Promise<number> {\n return this.store.count(criteria);\n }\n\n async cursor<Result extends Partial<Model> = Model>(\n criteria?: Criteria<Model>,\n sort?: Sort<Model>,\n ): Promise<AbstractStoreCursor<any, KeyValue, Model, Result>> {\n const cursor = await this.store.cursor<Result>(criteria, sort);\n cursor.overrideStore(this);\n return cursor;\n }\n}\n","import type {\n Query,\n SubscribeCallback,\n QuerySubscription,\n QueryResult,\n QueryParams,\n BaseModel,\n InsertType,\n AllowedKeyValue,\n} from 'liwi-store';\nimport type SubscribeStore from './SubscribeStore';\n\nexport default abstract class AbstractSubscribableStoreQuery<\n KeyPath extends keyof Model,\n KeyValue extends AllowedKeyValue,\n Model extends BaseModel & Record<KeyPath, KeyValue>,\n ModelInsertType extends InsertType<Model, KeyPath>,\n Params extends QueryParams<Params> = never,\n Result = Model,\n> implements Query<Result, Params, KeyValue>\n{\n changeParams(params: Params): never {\n throw new Error('Method not supported. Please create a new query.');\n }\n\n changePartialParams(\n params: Params extends undefined ? never : Partial<Params>,\n ): never {\n throw new Error('Method not supported. Please create a new query.');\n }\n\n private _subscribeStore?: SubscribeStore<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n any,\n any\n >;\n\n setSubscribeStore(\n store: SubscribeStore<KeyPath, KeyValue, Model, ModelInsertType, any, any>,\n ): void {\n this._subscribeStore = store;\n }\n\n getSubscribeStore(): SubscribeStore<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n any,\n any\n > {\n if (!this._subscribeStore) {\n throw new Error('_subscribeStore is not initialized');\n }\n return this._subscribeStore;\n }\n\n abstract fetch<T>(\n onFulfilled: (result: QueryResult<Result>) => T,\n ): Promise<T>;\n\n fetchAndSubscribe(\n callback: SubscribeCallback<KeyValue, Result>,\n ): QuerySubscription {\n return this._subscribe(callback, true);\n }\n\n subscribe(callback: SubscribeCallback<KeyValue, Result>): QuerySubscription {\n return this._subscribe(callback, false);\n }\n\n abstract _subscribe(\n callback: SubscribeCallback<KeyValue, Result>,\n _includeInitial: boolean,\n ): QuerySubscription;\n}\n"],"names":["SubscribeStore","store","listeners","Set","keyPath","_proto","prototype","subscribe","callback","add","delete","callSubscribed","action","forEach","listener","createQuerySingleItem","options","transformer","query","setSubscribeStore","createQueryCollection","findAll","criteria","sort","findByKey","key","findOne","insertOne","_insertOne","_asyncToGenerator","_regeneratorRuntime","mark","_callee","object","inserted","wrap","_callee$","_context","prev","next","sent","type","abrupt","stop","apply","arguments","replaceOne","_replaceOne","_callee2","replaced","_callee2$","_context2","changes","replaceSeveral","_replaceSeveral","_callee3","objects","replacedObjects","_callee3$","_context3","map","index","upsertOne","_upsertOne","_callee4","setOnInsertPartialObject","result","_callee4$","_context4","upsertOneWithInfo","_upsertOneWithInfo","_callee5","upsertedWithInfo","_callee5$","_context5","Error","partialUpdateByKey","_partialUpdateByKey","_callee6","partialUpdate","_extends2","_callee6$","_context6","t0","_extends","t1","t2","partialUpdateOne","call","_partialUpdateOne","_callee7","updated","_callee7$","_context7","partialUpdateMany","_partialUpdateMany","_callee9","_this2","cursor","_callee9$","_context9","_ref","_callee8","model","_callee8$","_context8","push","deleteByKey","_deleteByKey","_callee10","_callee10$","_context10","deleteOne","_deleteOne","_callee11","_callee11$","_context11","deleteMany","_deleteMany","_callee12","_callee12$","_context12","toArray","count","_count","_callee13","_callee13$","_context13","_cursor","_callee14","_callee14$","_context14","overrideStore","_createClass","get","connection","AbstractSubscribableStoreQuery","changeParams","changePartialParams","_subscribeStore","getSubscribeStore","fetchAndSubscribe","_subscribe"],"mappings":";;;;;AAAA;AAAA,IA4BqBA,cAAc,gBAAA,YAAA;EAsBjC,SAAAA,cAAAA,CAAYC,KAAY,EAAE;AAAA,IAAA,IAAA,CAJTC,SAAS,GAAG,IAAIC,GAAG,EAAmB,CAAA;IAKrD,IAAI,CAACF,KAAK,GAAGA,KAAK,CAAA;AAClB,IAAA,IAAI,CAACG,OAAO,GAAGH,KAAK,CAACG,OAAO,CAAA;AAC9B,GAAA;AAAC,EAAA,IAAAC,MAAA,GAAAL,cAAA,CAAAM,SAAA,CAAA;AAAAD,EAAAA,MAAA,CAMDE,SAAS,GAAT,SAAAA,SAAAA,CAAUC,QAAyB,EAAc;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AA,CAAA;AAAA,CAAA;;;;"}
1
+ {"version":3,"file":"index-browser.es.js","sources":["../src/SubscribeStore.ts","../src/AbstractSubscribableStoreQuery.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type {\n Store as StoreInterface,\n AbstractConnection,\n UpsertResult,\n SubscribableStoreQuery,\n AbstractStoreCursor,\n SubscribableStore,\n QueryParams,\n UpsertPartialObject,\n BaseModel,\n InsertType,\n Update,\n Criteria,\n Sort,\n QueryOptions,\n Transformer,\n AllowedKeyValue,\n OptionalBaseModelKeysForInsert,\n} from 'liwi-store';\n\nexport type Actions<Model> =\n | { type: 'deleted'; prev: Model[] }\n | { type: 'inserted'; next: Model[] }\n | { type: 'updated'; changes: [Model, Model][] };\n\nexport type Listener<Model> = (action: Actions<Model>) => unknown;\n\nexport default class SubscribeStore<\n KeyPath extends keyof Model,\n KeyValue extends AllowedKeyValue,\n Model extends BaseModel & Record<KeyPath, KeyValue>,\n ModelInsertType extends InsertType<Model, KeyPath>,\n Connection extends AbstractConnection,\n Store extends SubscribableStore<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n Connection\n >,\n> implements\n StoreInterface<KeyPath, KeyValue, Model, ModelInsertType, Connection>\n{\n private readonly store: Store;\n\n private readonly listeners = new Set<Listener<Model>>();\n\n readonly keyPath: KeyPath;\n\n constructor(store: Store) {\n this.store = store;\n this.keyPath = store.keyPath;\n }\n\n get connection(): Connection {\n return this.store.connection;\n }\n\n subscribe(callback: Listener<Model>): () => void {\n this.listeners.add(callback);\n return () => this.listeners.delete(callback);\n }\n\n callSubscribed(action: Actions<Model>): void {\n this.listeners.forEach((listener) => listener(action));\n }\n\n createQuerySingleItem<\n Result extends Record<KeyPath, KeyValue>,\n Params extends QueryParams<Params>,\n >(\n options: QueryOptions<Model>,\n transformer?: Transformer<Model, Result>,\n ): SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Result,\n Params\n > {\n const query: SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Result,\n Params\n > = this.store.createQuerySingleItem<Result, Params>(options, transformer);\n query.setSubscribeStore(this);\n return query;\n }\n\n createQueryCollection<\n Item extends Record<KeyPath, KeyValue>,\n Params extends QueryParams<Params>,\n >(\n options: QueryOptions<Model>,\n transformer?: Transformer<Model, Item>,\n ): SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Item[],\n Params\n > {\n const query: SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Item[],\n Params\n > = this.store.createQueryCollection<Item, Params>(options, transformer);\n query.setSubscribeStore(this);\n return query;\n }\n\n findAll(criteria?: Criteria<Model>, sort?: Sort<Model>): Promise<Model[]> {\n return this.store.findAll(criteria, sort);\n }\n\n findByKey(\n key: KeyValue,\n criteria?: Criteria<Model>,\n ): Promise<Model | undefined> {\n return this.store.findByKey(key, criteria);\n }\n\n findOne(\n criteria: Criteria<Model>,\n sort?: Sort<Model>,\n ): Promise<Model | undefined> {\n return this.store.findOne(criteria, sort);\n }\n\n async insertOne(object: ModelInsertType): Promise<Model> {\n const inserted = await this.store.insertOne(object);\n this.callSubscribed({ type: 'inserted', next: [inserted] });\n return inserted;\n }\n\n async replaceOne(object: Model): Promise<Model> {\n const replaced = await this.store.replaceOne(object);\n this.callSubscribed({ type: 'updated', changes: [[object, replaced]] });\n return replaced;\n }\n\n async replaceSeveral(objects: Model[]): Promise<Model[]> {\n const replacedObjects = await this.store.replaceSeveral(objects);\n this.callSubscribed({\n type: 'updated',\n changes: objects.map((prev, index) => [prev, replacedObjects[index]]),\n });\n return replacedObjects;\n }\n\n async upsertOne<\n K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>,\n >(\n object: UpsertPartialObject<KeyPath, KeyValue, Model, K>,\n setOnInsertPartialObject?: Update<Model>['$setOnInsert'],\n ): Promise<Model> {\n const result = await this.upsertOneWithInfo(\n object,\n setOnInsertPartialObject,\n );\n return result.object;\n }\n\n async upsertOneWithInfo<\n K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>,\n >(\n object: UpsertPartialObject<KeyPath, KeyValue, Model, K>,\n setOnInsertPartialObject?: Update<Model>['$setOnInsert'],\n ): Promise<UpsertResult<Model>> {\n const upsertedWithInfo = await this.store.upsertOneWithInfo(\n object,\n setOnInsertPartialObject,\n );\n if (upsertedWithInfo.inserted) {\n this.callSubscribed({\n type: 'inserted',\n next: [upsertedWithInfo.object],\n });\n } else {\n throw new Error('TODO');\n }\n return upsertedWithInfo;\n }\n\n async partialUpdateByKey(\n key: KeyValue,\n partialUpdate: Update<Model>,\n criteria?: Criteria<Model>,\n ): Promise<Model> {\n return this.partialUpdateOne(\n (await this.findOne({\n [this.store.keyPath]: key,\n ...criteria,\n } as Criteria<Model>))!,\n partialUpdate,\n );\n }\n\n async partialUpdateOne(\n object: Model,\n partialUpdate: Update<Model>,\n ): Promise<Model> {\n const updated = await this.store.partialUpdateOne(object, partialUpdate);\n this.callSubscribed({ type: 'updated', changes: [[object, updated]] });\n return updated;\n }\n\n async partialUpdateMany(\n criteria: Criteria<Model>,\n partialUpdate: Update<Model>,\n ): Promise<void> {\n const cursor = await this.store.cursor(criteria);\n const changes: [Model, Model][] = [];\n\n await cursor.forEach(async (model) => {\n const key = model[this.store.keyPath];\n const updated = await this.store.partialUpdateByKey(\n key,\n partialUpdate,\n criteria,\n );\n changes.push([model, updated]);\n });\n this.callSubscribed({ type: 'updated', changes });\n }\n\n async deleteByKey(key: KeyValue, criteria?: Criteria<Model>): Promise<void> {\n return this.deleteOne((await this.findByKey(key, criteria))!);\n }\n\n async deleteOne(object: Model): Promise<void> {\n await this.store.deleteOne(object);\n this.callSubscribed({ type: 'deleted', prev: [object] });\n }\n\n async deleteMany(criteria: Criteria<Model>): Promise<void> {\n const cursor = await this.store.cursor(criteria);\n const prev: Model[] = await cursor.toArray();\n await this.store.deleteMany(criteria);\n this.callSubscribed({ type: 'deleted', prev });\n }\n\n async count(criteria?: Criteria<Model>): Promise<number> {\n return this.store.count(criteria);\n }\n\n async cursor<Result extends Partial<Model> = Model>(\n criteria?: Criteria<Model>,\n sort?: Sort<Model>,\n ): Promise<AbstractStoreCursor<any, KeyValue, Model, Result>> {\n const cursor = await this.store.cursor<Result>(criteria, sort);\n cursor.overrideStore(this);\n return cursor;\n }\n}\n","/* eslint-disable @typescript-eslint/class-methods-use-this */\nimport type {\n Query,\n SubscribeCallback,\n QuerySubscription,\n QueryResult,\n QueryParams,\n BaseModel,\n InsertType,\n AllowedKeyValue,\n} from 'liwi-store';\nimport type SubscribeStore from './SubscribeStore';\n\nexport default abstract class AbstractSubscribableStoreQuery<\n KeyPath extends keyof Model,\n KeyValue extends AllowedKeyValue,\n Model extends BaseModel & Record<KeyPath, KeyValue>,\n ModelInsertType extends InsertType<Model, KeyPath>,\n Params extends QueryParams<Params> = never,\n Result = Model,\n> implements Query<Result, Params, KeyValue>\n{\n changeParams(params: Params): never {\n throw new Error('Method not supported. Please create a new query.');\n }\n\n changePartialParams(\n params: Params extends undefined ? never : Partial<Params>,\n ): never {\n throw new Error('Method not supported. Please create a new query.');\n }\n\n private _subscribeStore?: SubscribeStore<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n any,\n any\n >;\n\n setSubscribeStore(\n store: SubscribeStore<KeyPath, KeyValue, Model, ModelInsertType, any, any>,\n ): void {\n this._subscribeStore = store;\n }\n\n getSubscribeStore(): SubscribeStore<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n any,\n any\n > {\n if (!this._subscribeStore) {\n throw new Error('_subscribeStore is not initialized');\n }\n return this._subscribeStore;\n }\n\n abstract fetch<T>(\n onFulfilled: (result: QueryResult<Result>) => T,\n ): Promise<T>;\n\n fetchAndSubscribe(\n callback: SubscribeCallback<KeyValue, Result>,\n ): QuerySubscription {\n return this._subscribe(callback, true);\n }\n\n subscribe(callback: SubscribeCallback<KeyValue, Result>): QuerySubscription {\n return this._subscribe(callback, false);\n }\n\n abstract _subscribe(\n callback: SubscribeCallback<KeyValue, Result>,\n _includeInitial: boolean,\n ): QuerySubscription;\n}\n"],"names":["SubscribeStore","constructor","store","listeners","Set","keyPath","connection","subscribe","callback","add","delete","callSubscribed","action","forEach","listener","createQuerySingleItem","options","transformer","query","setSubscribeStore","createQueryCollection","findAll","criteria","sort","findByKey","key","findOne","insertOne","object","inserted","type","next","replaceOne","replaced","changes","replaceSeveral","objects","replacedObjects","map","prev","index","upsertOne","setOnInsertPartialObject","result","upsertOneWithInfo","upsertedWithInfo","Error","partialUpdateByKey","partialUpdate","partialUpdateOne","updated","partialUpdateMany","cursor","model","push","deleteByKey","deleteOne","deleteMany","toArray","count","overrideStore","AbstractSubscribableStoreQuery","changeParams","changePartialParams","_subscribeStore","getSubscribeStore","fetchAndSubscribe","_subscribe"],"mappings":"AAAA;;AA4Be,MAAMA,cAAc,CAenC;EAOEC,WAAWA,CAACC,KAAY,EAAE;AAAA,IAAA,IAAA,CAJTC,SAAS,GAAG,IAAIC,GAAG,EAAmB,CAAA;IAKrD,IAAI,CAACF,KAAK,GAAGA,KAAK,CAAA;AAClB,IAAA,IAAI,CAACG,OAAO,GAAGH,KAAK,CAACG,OAAO,CAAA;AAC9B,GAAA;EAEA,IAAIC,UAAUA,GAAe;AAC3B,IAAA,OAAO,IAAI,CAACJ,KAAK,CAACI,UAAU,CAAA;AAC9B,GAAA;EAEAC,SAASA,CAACC,QAAyB,EAAc;AAC/C,IAAA,IAAI,CAACL,SAAS,CAACM,GAAG,CAACD,QAAQ,CAAC,CAAA;IAC5B,OAAO,MAAM,IAAI,CAACL,SAAS,CAACO,MAAM,CAACF,QAAQ,CAAC,CAAA;AAC9C,GAAA;EAEAG,cAAcA,CAACC,MAAsB,EAAQ;IAC3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AAA,OAAO,IAAI,CAAC2D,UAAU,CAAC3D,QAAQ,EAAE,KAAK,CAAC,CAAA;AACzC,GAAA;AAMF;;;;"}
@@ -131,6 +131,8 @@ class SubscribeStore {
131
131
  }
132
132
  }
133
133
 
134
+ /* eslint-disable @typescript-eslint/class-methods-use-this */
135
+
134
136
  class AbstractSubscribableStoreQuery {
135
137
  changeParams() {
136
138
  throw new Error('Method not supported. Please create a new query.');
@@ -156,4 +158,4 @@ class AbstractSubscribableStoreQuery {
156
158
  }
157
159
 
158
160
  export { AbstractSubscribableStoreQuery, SubscribeStore };
159
- //# sourceMappingURL=index-node16.mjs.map
161
+ //# sourceMappingURL=index-node18.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-node16.mjs","sources":["../src/SubscribeStore.ts","../src/AbstractSubscribableStoreQuery.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type {\n Store as StoreInterface,\n AbstractConnection,\n UpsertResult,\n SubscribableStoreQuery,\n AbstractStoreCursor,\n SubscribableStore,\n QueryParams,\n UpsertPartialObject,\n BaseModel,\n InsertType,\n Update,\n Criteria,\n Sort,\n QueryOptions,\n Transformer,\n AllowedKeyValue,\n OptionalBaseModelKeysForInsert,\n} from 'liwi-store';\n\nexport type Actions<Model> =\n | { type: 'deleted'; prev: Model[] }\n | { type: 'inserted'; next: Model[] }\n | { type: 'updated'; changes: [Model, Model][] };\n\nexport type Listener<Model> = (action: Actions<Model>) => unknown;\n\nexport default class SubscribeStore<\n KeyPath extends keyof Model,\n KeyValue extends AllowedKeyValue,\n Model extends BaseModel & Record<KeyPath, KeyValue>,\n ModelInsertType extends InsertType<Model, KeyPath>,\n Connection extends AbstractConnection,\n Store extends SubscribableStore<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n Connection\n >,\n> implements\n StoreInterface<KeyPath, KeyValue, Model, ModelInsertType, Connection>\n{\n private readonly store: Store;\n\n private readonly listeners = new Set<Listener<Model>>();\n\n readonly keyPath: KeyPath;\n\n constructor(store: Store) {\n this.store = store;\n this.keyPath = store.keyPath;\n }\n\n get connection(): Connection {\n return this.store.connection;\n }\n\n subscribe(callback: Listener<Model>): () => void {\n this.listeners.add(callback);\n return () => this.listeners.delete(callback);\n }\n\n callSubscribed(action: Actions<Model>): void {\n this.listeners.forEach((listener) => listener(action));\n }\n\n createQuerySingleItem<\n Result extends Record<KeyPath, KeyValue>,\n Params extends QueryParams<Params>,\n >(\n options: QueryOptions<Model>,\n transformer?: Transformer<Model, Result>,\n ): SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Result,\n Params\n > {\n const query: SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Result,\n Params\n > = this.store.createQuerySingleItem<Result, Params>(options, transformer);\n query.setSubscribeStore(this);\n return query;\n }\n\n createQueryCollection<\n Item extends Record<KeyPath, KeyValue>,\n Params extends QueryParams<Params>,\n >(\n options: QueryOptions<Model>,\n transformer?: Transformer<Model, Item>,\n ): SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Item[],\n Params\n > {\n const query: SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Item[],\n Params\n > = this.store.createQueryCollection<Item, Params>(options, transformer);\n query.setSubscribeStore(this);\n return query;\n }\n\n findAll(criteria?: Criteria<Model>, sort?: Sort<Model>): Promise<Model[]> {\n return this.store.findAll(criteria, sort);\n }\n\n findByKey(\n key: KeyValue,\n criteria?: Criteria<Model>,\n ): Promise<Model | undefined> {\n return this.store.findByKey(key, criteria);\n }\n\n findOne(\n criteria: Criteria<Model>,\n sort?: Sort<Model>,\n ): Promise<Model | undefined> {\n return this.store.findOne(criteria, sort);\n }\n\n async insertOne(object: ModelInsertType): Promise<Model> {\n const inserted = await this.store.insertOne(object);\n this.callSubscribed({ type: 'inserted', next: [inserted] });\n return inserted;\n }\n\n async replaceOne(object: Model): Promise<Model> {\n const replaced = await this.store.replaceOne(object);\n this.callSubscribed({ type: 'updated', changes: [[object, replaced]] });\n return replaced;\n }\n\n async replaceSeveral(objects: Model[]): Promise<Model[]> {\n const replacedObjects = await this.store.replaceSeveral(objects);\n this.callSubscribed({\n type: 'updated',\n changes: objects.map((prev, index) => [prev, replacedObjects[index]]),\n });\n return replacedObjects;\n }\n\n async upsertOne<\n K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>,\n >(\n object: UpsertPartialObject<KeyPath, KeyValue, Model, K>,\n setOnInsertPartialObject?: Update<Model>['$setOnInsert'],\n ): Promise<Model> {\n const result = await this.upsertOneWithInfo(\n object,\n setOnInsertPartialObject,\n );\n return result.object;\n }\n\n async upsertOneWithInfo<\n K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>,\n >(\n object: UpsertPartialObject<KeyPath, KeyValue, Model, K>,\n setOnInsertPartialObject?: Update<Model>['$setOnInsert'],\n ): Promise<UpsertResult<Model>> {\n const upsertedWithInfo = await this.store.upsertOneWithInfo(\n object,\n setOnInsertPartialObject,\n );\n if (upsertedWithInfo.inserted) {\n this.callSubscribed({\n type: 'inserted',\n next: [upsertedWithInfo.object],\n });\n } else {\n throw new Error('TODO');\n }\n return upsertedWithInfo;\n }\n\n async partialUpdateByKey(\n key: KeyValue,\n partialUpdate: Update<Model>,\n criteria?: Criteria<Model>,\n ): Promise<Model> {\n return this.partialUpdateOne(\n (await this.findOne({\n [this.store.keyPath]: key,\n ...criteria,\n } as Criteria<Model>))!,\n partialUpdate,\n );\n }\n\n async partialUpdateOne(\n object: Model,\n partialUpdate: Update<Model>,\n ): Promise<Model> {\n const updated = await this.store.partialUpdateOne(object, partialUpdate);\n this.callSubscribed({ type: 'updated', changes: [[object, updated]] });\n return updated;\n }\n\n async partialUpdateMany(\n criteria: Criteria<Model>,\n partialUpdate: Update<Model>,\n ): Promise<void> {\n const cursor = await this.store.cursor(criteria);\n const changes: [Model, Model][] = [];\n\n await cursor.forEach(async (model) => {\n const key = model[this.store.keyPath];\n const updated = await this.store.partialUpdateByKey(\n key,\n partialUpdate,\n criteria,\n );\n changes.push([model, updated]);\n });\n this.callSubscribed({ type: 'updated', changes });\n }\n\n async deleteByKey(key: KeyValue, criteria?: Criteria<Model>): Promise<void> {\n return this.deleteOne((await this.findByKey(key, criteria))!);\n }\n\n async deleteOne(object: Model): Promise<void> {\n await this.store.deleteOne(object);\n this.callSubscribed({ type: 'deleted', prev: [object] });\n }\n\n async deleteMany(criteria: Criteria<Model>): Promise<void> {\n const cursor = await this.store.cursor(criteria);\n const prev: Model[] = await cursor.toArray();\n await this.store.deleteMany(criteria);\n this.callSubscribed({ type: 'deleted', prev });\n }\n\n async count(criteria?: Criteria<Model>): Promise<number> {\n return this.store.count(criteria);\n }\n\n async cursor<Result extends Partial<Model> = Model>(\n criteria?: Criteria<Model>,\n sort?: Sort<Model>,\n ): Promise<AbstractStoreCursor<any, KeyValue, Model, Result>> {\n const cursor = await this.store.cursor<Result>(criteria, sort);\n cursor.overrideStore(this);\n return cursor;\n }\n}\n","import type {\n Query,\n SubscribeCallback,\n QuerySubscription,\n QueryResult,\n QueryParams,\n BaseModel,\n InsertType,\n AllowedKeyValue,\n} from 'liwi-store';\nimport type SubscribeStore from './SubscribeStore';\n\nexport default abstract class AbstractSubscribableStoreQuery<\n KeyPath extends keyof Model,\n KeyValue extends AllowedKeyValue,\n Model extends BaseModel & Record<KeyPath, KeyValue>,\n ModelInsertType extends InsertType<Model, KeyPath>,\n Params extends QueryParams<Params> = never,\n Result = Model,\n> implements Query<Result, Params, KeyValue>\n{\n changeParams(params: Params): never {\n throw new Error('Method not supported. Please create a new query.');\n }\n\n changePartialParams(\n params: Params extends undefined ? never : Partial<Params>,\n ): never {\n throw new Error('Method not supported. Please create a new query.');\n }\n\n private _subscribeStore?: SubscribeStore<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n any,\n any\n >;\n\n setSubscribeStore(\n store: SubscribeStore<KeyPath, KeyValue, Model, ModelInsertType, any, any>,\n ): void {\n this._subscribeStore = store;\n }\n\n getSubscribeStore(): SubscribeStore<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n any,\n any\n > {\n if (!this._subscribeStore) {\n throw new Error('_subscribeStore is not initialized');\n }\n return this._subscribeStore;\n }\n\n abstract fetch<T>(\n onFulfilled: (result: QueryResult<Result>) => T,\n ): Promise<T>;\n\n fetchAndSubscribe(\n callback: SubscribeCallback<KeyValue, Result>,\n ): QuerySubscription {\n return this._subscribe(callback, true);\n }\n\n subscribe(callback: SubscribeCallback<KeyValue, Result>): QuerySubscription {\n return this._subscribe(callback, false);\n }\n\n abstract _subscribe(\n callback: SubscribeCallback<KeyValue, Result>,\n _includeInitial: boolean,\n ): QuerySubscription;\n}\n"],"names":["SubscribeStore","listeners","Set","constructor","store","keyPath","connection","subscribe","callback","add","delete","callSubscribed","action","forEach","listener","createQuerySingleItem","options","transformer","query","setSubscribeStore","createQueryCollection","findAll","criteria","sort","findByKey","key","findOne","insertOne","object","inserted","type","next","replaceOne","replaced","changes","replaceSeveral","objects","replacedObjects","map","prev","index","upsertOne","setOnInsertPartialObject","result","upsertOneWithInfo","upsertedWithInfo","Error","partialUpdateByKey","partialUpdate","partialUpdateOne","updated","partialUpdateMany","cursor","model","push","deleteByKey","deleteOne","deleteMany","toArray","count","overrideStore","AbstractSubscribableStoreQuery","changeParams","changePartialParams","_subscribeStore","getSubscribeStore","fetchAndSubscribe","_subscribe"],"mappings":"AAAA;;AA4Be,MAAMA,cAAc,CAenC;EAGmBC,SAAS,GAAG,IAAIC,GAAG,EAAmB,CAAA;EAIvDC,WAAWA,CAACC,KAAY,EAAE;IACxB,IAAI,CAACA,KAAK,GAAGA,KAAK,CAAA;AAClB,IAAA,IAAI,CAACC,OAAO,GAAGD,KAAK,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iBAAiBA,GAOf;AACA,IAAA,IAAI,CAAC,IAAI,CAACD,eAAe,EAAE;AACzB,MAAA,MAAM,IAAIlB,KAAK,CAAC,oCAAoC,CAAC,CAAA;AACvD,KAAA;IACA,OAAO,IAAI,CAACkB,eAAe,CAAA;AAC7B,GAAA;EAMAE,iBAAiBA,CACf1D,QAA6C,EAC1B;AACnB,IAAA,OAAO,IAAI,CAAC2D,UAAU,CAAC3D,QAAQ,EAAE,IAAI,CAAC,CAAA;AACxC,GAAA;EAEAD,SAASA,CAACC,QAA6C,EAAqB;AAC1E,IAAA,OAAO,IAAI,CAAC2D,UAAU,CAAC3D,QAAQ,EAAE,KAAK,CAAC,CAAA;AACzC,GAAA;AAMF;;;;"}
1
+ {"version":3,"file":"index-node18.mjs","sources":["../src/SubscribeStore.ts","../src/AbstractSubscribableStoreQuery.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type {\n Store as StoreInterface,\n AbstractConnection,\n UpsertResult,\n SubscribableStoreQuery,\n AbstractStoreCursor,\n SubscribableStore,\n QueryParams,\n UpsertPartialObject,\n BaseModel,\n InsertType,\n Update,\n Criteria,\n Sort,\n QueryOptions,\n Transformer,\n AllowedKeyValue,\n OptionalBaseModelKeysForInsert,\n} from 'liwi-store';\n\nexport type Actions<Model> =\n | { type: 'deleted'; prev: Model[] }\n | { type: 'inserted'; next: Model[] }\n | { type: 'updated'; changes: [Model, Model][] };\n\nexport type Listener<Model> = (action: Actions<Model>) => unknown;\n\nexport default class SubscribeStore<\n KeyPath extends keyof Model,\n KeyValue extends AllowedKeyValue,\n Model extends BaseModel & Record<KeyPath, KeyValue>,\n ModelInsertType extends InsertType<Model, KeyPath>,\n Connection extends AbstractConnection,\n Store extends SubscribableStore<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n Connection\n >,\n> implements\n StoreInterface<KeyPath, KeyValue, Model, ModelInsertType, Connection>\n{\n private readonly store: Store;\n\n private readonly listeners = new Set<Listener<Model>>();\n\n readonly keyPath: KeyPath;\n\n constructor(store: Store) {\n this.store = store;\n this.keyPath = store.keyPath;\n }\n\n get connection(): Connection {\n return this.store.connection;\n }\n\n subscribe(callback: Listener<Model>): () => void {\n this.listeners.add(callback);\n return () => this.listeners.delete(callback);\n }\n\n callSubscribed(action: Actions<Model>): void {\n this.listeners.forEach((listener) => listener(action));\n }\n\n createQuerySingleItem<\n Result extends Record<KeyPath, KeyValue>,\n Params extends QueryParams<Params>,\n >(\n options: QueryOptions<Model>,\n transformer?: Transformer<Model, Result>,\n ): SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Result,\n Params\n > {\n const query: SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Result,\n Params\n > = this.store.createQuerySingleItem<Result, Params>(options, transformer);\n query.setSubscribeStore(this);\n return query;\n }\n\n createQueryCollection<\n Item extends Record<KeyPath, KeyValue>,\n Params extends QueryParams<Params>,\n >(\n options: QueryOptions<Model>,\n transformer?: Transformer<Model, Item>,\n ): SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Item[],\n Params\n > {\n const query: SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Item[],\n Params\n > = this.store.createQueryCollection<Item, Params>(options, transformer);\n query.setSubscribeStore(this);\n return query;\n }\n\n findAll(criteria?: Criteria<Model>, sort?: Sort<Model>): Promise<Model[]> {\n return this.store.findAll(criteria, sort);\n }\n\n findByKey(\n key: KeyValue,\n criteria?: Criteria<Model>,\n ): Promise<Model | undefined> {\n return this.store.findByKey(key, criteria);\n }\n\n findOne(\n criteria: Criteria<Model>,\n sort?: Sort<Model>,\n ): Promise<Model | undefined> {\n return this.store.findOne(criteria, sort);\n }\n\n async insertOne(object: ModelInsertType): Promise<Model> {\n const inserted = await this.store.insertOne(object);\n this.callSubscribed({ type: 'inserted', next: [inserted] });\n return inserted;\n }\n\n async replaceOne(object: Model): Promise<Model> {\n const replaced = await this.store.replaceOne(object);\n this.callSubscribed({ type: 'updated', changes: [[object, replaced]] });\n return replaced;\n }\n\n async replaceSeveral(objects: Model[]): Promise<Model[]> {\n const replacedObjects = await this.store.replaceSeveral(objects);\n this.callSubscribed({\n type: 'updated',\n changes: objects.map((prev, index) => [prev, replacedObjects[index]]),\n });\n return replacedObjects;\n }\n\n async upsertOne<\n K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>,\n >(\n object: UpsertPartialObject<KeyPath, KeyValue, Model, K>,\n setOnInsertPartialObject?: Update<Model>['$setOnInsert'],\n ): Promise<Model> {\n const result = await this.upsertOneWithInfo(\n object,\n setOnInsertPartialObject,\n );\n return result.object;\n }\n\n async upsertOneWithInfo<\n K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>,\n >(\n object: UpsertPartialObject<KeyPath, KeyValue, Model, K>,\n setOnInsertPartialObject?: Update<Model>['$setOnInsert'],\n ): Promise<UpsertResult<Model>> {\n const upsertedWithInfo = await this.store.upsertOneWithInfo(\n object,\n setOnInsertPartialObject,\n );\n if (upsertedWithInfo.inserted) {\n this.callSubscribed({\n type: 'inserted',\n next: [upsertedWithInfo.object],\n });\n } else {\n throw new Error('TODO');\n }\n return upsertedWithInfo;\n }\n\n async partialUpdateByKey(\n key: KeyValue,\n partialUpdate: Update<Model>,\n criteria?: Criteria<Model>,\n ): Promise<Model> {\n return this.partialUpdateOne(\n (await this.findOne({\n [this.store.keyPath]: key,\n ...criteria,\n } as Criteria<Model>))!,\n partialUpdate,\n );\n }\n\n async partialUpdateOne(\n object: Model,\n partialUpdate: Update<Model>,\n ): Promise<Model> {\n const updated = await this.store.partialUpdateOne(object, partialUpdate);\n this.callSubscribed({ type: 'updated', changes: [[object, updated]] });\n return updated;\n }\n\n async partialUpdateMany(\n criteria: Criteria<Model>,\n partialUpdate: Update<Model>,\n ): Promise<void> {\n const cursor = await this.store.cursor(criteria);\n const changes: [Model, Model][] = [];\n\n await cursor.forEach(async (model) => {\n const key = model[this.store.keyPath];\n const updated = await this.store.partialUpdateByKey(\n key,\n partialUpdate,\n criteria,\n );\n changes.push([model, updated]);\n });\n this.callSubscribed({ type: 'updated', changes });\n }\n\n async deleteByKey(key: KeyValue, criteria?: Criteria<Model>): Promise<void> {\n return this.deleteOne((await this.findByKey(key, criteria))!);\n }\n\n async deleteOne(object: Model): Promise<void> {\n await this.store.deleteOne(object);\n this.callSubscribed({ type: 'deleted', prev: [object] });\n }\n\n async deleteMany(criteria: Criteria<Model>): Promise<void> {\n const cursor = await this.store.cursor(criteria);\n const prev: Model[] = await cursor.toArray();\n await this.store.deleteMany(criteria);\n this.callSubscribed({ type: 'deleted', prev });\n }\n\n async count(criteria?: Criteria<Model>): Promise<number> {\n return this.store.count(criteria);\n }\n\n async cursor<Result extends Partial<Model> = Model>(\n criteria?: Criteria<Model>,\n sort?: Sort<Model>,\n ): Promise<AbstractStoreCursor<any, KeyValue, Model, Result>> {\n const cursor = await this.store.cursor<Result>(criteria, sort);\n cursor.overrideStore(this);\n return cursor;\n }\n}\n","/* eslint-disable @typescript-eslint/class-methods-use-this */\nimport type {\n Query,\n SubscribeCallback,\n QuerySubscription,\n QueryResult,\n QueryParams,\n BaseModel,\n InsertType,\n AllowedKeyValue,\n} from 'liwi-store';\nimport type SubscribeStore from './SubscribeStore';\n\nexport default abstract class AbstractSubscribableStoreQuery<\n KeyPath extends keyof Model,\n KeyValue extends AllowedKeyValue,\n Model extends BaseModel & Record<KeyPath, KeyValue>,\n ModelInsertType extends InsertType<Model, KeyPath>,\n Params extends QueryParams<Params> = never,\n Result = Model,\n> implements Query<Result, Params, KeyValue>\n{\n changeParams(params: Params): never {\n throw new Error('Method not supported. Please create a new query.');\n }\n\n changePartialParams(\n params: Params extends undefined ? never : Partial<Params>,\n ): never {\n throw new Error('Method not supported. Please create a new query.');\n }\n\n private _subscribeStore?: SubscribeStore<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n any,\n any\n >;\n\n setSubscribeStore(\n store: SubscribeStore<KeyPath, KeyValue, Model, ModelInsertType, any, any>,\n ): void {\n this._subscribeStore = store;\n }\n\n getSubscribeStore(): SubscribeStore<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n any,\n any\n > {\n if (!this._subscribeStore) {\n throw new Error('_subscribeStore is not initialized');\n }\n return this._subscribeStore;\n }\n\n abstract fetch<T>(\n onFulfilled: (result: QueryResult<Result>) => T,\n ): Promise<T>;\n\n fetchAndSubscribe(\n callback: SubscribeCallback<KeyValue, Result>,\n ): QuerySubscription {\n return this._subscribe(callback, true);\n }\n\n subscribe(callback: SubscribeCallback<KeyValue, Result>): QuerySubscription {\n return this._subscribe(callback, false);\n }\n\n abstract _subscribe(\n callback: SubscribeCallback<KeyValue, Result>,\n _includeInitial: boolean,\n ): QuerySubscription;\n}\n"],"names":["SubscribeStore","listeners","Set","constructor","store","keyPath","connection","subscribe","callback","add","delete","callSubscribed","action","forEach","listener","createQuerySingleItem","options","transformer","query","setSubscribeStore","createQueryCollection","findAll","criteria","sort","findByKey","key","findOne","insertOne","object","inserted","type","next","replaceOne","replaced","changes","replaceSeveral","objects","replacedObjects","map","prev","index","upsertOne","setOnInsertPartialObject","result","upsertOneWithInfo","upsertedWithInfo","Error","partialUpdateByKey","partialUpdate","partialUpdateOne","updated","partialUpdateMany","cursor","model","push","deleteByKey","deleteOne","deleteMany","toArray","count","overrideStore","AbstractSubscribableStoreQuery","changeParams","changePartialParams","_subscribeStore","getSubscribeStore","fetchAndSubscribe","_subscribe"],"mappings":"AAAA;;AA4Be,MAAMA,cAAc,CAenC;AAGmBC,EAAAA,SAAS,GAAG,IAAIC,GAAG,EAAmB,CAAA;EAIvDC,WAAWA,CAACC,KAAY,EAAE;IACxB,IAAI,CAACA,KAAK,GAAGA,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e,GAAG5D,KAAK,CAAA;AAC9B,GAAA;AAEA6D,EAAAA,iBAAiBA,GAOf;AACA,IAAA,IAAI,CAAC,IAAI,CAACD,eAAe,EAAE;AACzB,MAAA,MAAM,IAAIlB,KAAK,CAAC,oCAAoC,CAAC,CAAA;AACvD,KAAA;IACA,OAAO,IAAI,CAACkB,eAAe,CAAA;AAC7B,GAAA;EAMAE,iBAAiBA,CACf1D,QAA6C,EAC1B;AACnB,IAAA,OAAO,IAAI,CAAC2D,UAAU,CAAC3D,QAAQ,EAAE,IAAI,CAAC,CAAA;AACxC,GAAA;EAEAD,SAASA,CAACC,QAA6C,EAAqB;AAC1E,IAAA,OAAO,IAAI,CAAC2D,UAAU,CAAC3D,QAAQ,EAAE,KAAK,CAAC,CAAA;AACzC,GAAA;AAMF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "liwi-subscribe-store",
3
- "version": "10.4.0",
3
+ "version": "12.0.0",
4
4
  "description": "subscribe store proxy",
5
5
  "keywords": [],
6
6
  "author": "Christophe Hurpeau <christophe@hurpeau.com> (https://christophe.hurpeau.com)",
@@ -13,18 +13,10 @@
13
13
  "homepage": "https://github.com/liwijs/liwi",
14
14
  "type": "module",
15
15
  "engines": {
16
- "node": ">=16.0.0"
16
+ "node": ">=18.12.0"
17
17
  },
18
- "browserslist": {
19
- "production": [
20
- "defaults",
21
- "> 0.2%",
22
- "not ie < 12",
23
- "not safari < 10",
24
- "not ios_saf < 10"
25
- ]
26
- },
27
- "main": "./dist/index-node16.mjs",
18
+ "sideEffects": false,
19
+ "main": "./dist/index-node18.mjs",
28
20
  "types": "./dist/definitions/index.d.ts",
29
21
  "module": "./dist/index-browser.es.js",
30
22
  "browser": "./dist/index-browser.es.js",
@@ -33,17 +25,17 @@
33
25
  ".": {
34
26
  "types": "./dist/definitions/index.d.ts",
35
27
  "node": {
36
- "import": "./dist/index-node16.mjs"
28
+ "import": "./dist/index-node18.mjs"
37
29
  },
38
30
  "browser": {
39
- "browser:modern": {
40
- "import": "./dist/index-browsermodern.es.js"
41
- },
42
31
  "import": "./dist/index-browser.es.js"
43
32
  }
44
33
  }
45
34
  },
46
- "sideEffects": false,
35
+ "files": [
36
+ "src",
37
+ "dist"
38
+ ],
47
39
  "scripts": {
48
40
  "build": "yarn clean:build && rollup --config rollup.config.mjs && yarn run build:definitions",
49
41
  "build:definitions": "tsc -p tsconfig.json",
@@ -53,16 +45,20 @@
53
45
  "lint:eslint": "yarn ../.. run eslint --report-unused-disable-directives --resolve-plugins-relative-to . --quiet packages/liwi-subscribe-store",
54
46
  "watch": "yarn clean:build && rollup --config rollup.config.mjs --watch"
55
47
  },
56
- "prettier": "@pob/root/prettier-config",
48
+ "browserslist": {
49
+ "production": [
50
+ "defaults",
51
+ "> 0.2%",
52
+ "not ie < 12",
53
+ "not safari < 10",
54
+ "not ios_saf < 10"
55
+ ]
56
+ },
57
57
  "pob": {
58
58
  "babelEnvs": [
59
59
  {
60
60
  "target": "node",
61
- "version": "16"
62
- },
63
- {
64
- "target": "browser",
65
- "version": "modern"
61
+ "version": "18"
66
62
  },
67
63
  {
68
64
  "target": "browser"
@@ -72,15 +68,15 @@
72
68
  "index"
73
69
  ]
74
70
  },
71
+ "prettier": "@pob/root/prettier-config",
75
72
  "dependencies": {
76
- "@babel/runtime": "^7.21.0",
77
- "liwi-store": "10.4.0"
73
+ "@babel/runtime": "^7.24.0",
74
+ "liwi-store": "12.0.0"
78
75
  },
79
76
  "devDependencies": {
80
- "@babel/core": "7.21.3",
81
- "@babel/preset-env": "7.20.2",
82
- "pob-babel": "35.6.2",
83
- "typescript": "4.9.5"
84
- },
85
- "gitHead": "e1ef308c87c430fb2402767fe8ca346cc1b95b95"
86
- }
77
+ "@babel/core": "7.24.3",
78
+ "@babel/preset-env": "7.24.3",
79
+ "pob-babel": "38.0.3",
80
+ "typescript": "5.3.3"
81
+ }
82
+ }
@@ -2,10 +2,14 @@
2
2
  "root": true,
3
3
  "parser": "@typescript-eslint/parser",
4
4
  "parserOptions": {
5
+ "EXPERIMENTAL_useProjectService": true,
5
6
  "project": "packages/liwi-subscribe-store/tsconfig.json"
6
7
  },
7
8
  "plugins": ["@typescript-eslint"],
8
- "extends": ["@pob/eslint-config-typescript"],
9
+ "extends": [
10
+ "@pob/eslint-config-typescript",
11
+ "@pob/eslint-config-typescript/node"
12
+ ],
9
13
  "ignorePatterns": ["*.d.ts"],
10
14
  "rules": {
11
15
  "@typescript-eslint/no-floating-promises": "warn",
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/class-methods-use-this */
1
2
  import type {
2
3
  Query,
3
4
  SubscribeCallback,
package/.editorconfig DELETED
@@ -1,13 +0,0 @@
1
- # EditorConfig helps developers define and maintain consistent
2
- # coding styles between different editors and IDEs
3
- # http://editorconfig.org
4
-
5
- root = true
6
-
7
- [*]
8
- indent_style = space
9
- indent_size = 2
10
- end_of_line = lf
11
- charset = utf-8
12
- trim_trailing_whitespace = true
13
- insert_final_newline = true
package/.eslintrc.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "root": true,
3
- "extends": ["@pob/eslint-config/root-module"],
4
- "ignorePatterns": ["*.d.ts", "/dist"]
5
- }
@@ -1,159 +0,0 @@
1
- /* eslint-disable max-lines */
2
-
3
- class SubscribeStore {
4
- listeners = new Set();
5
- constructor(store) {
6
- this.store = store;
7
- this.keyPath = store.keyPath;
8
- }
9
- get connection() {
10
- return this.store.connection;
11
- }
12
- subscribe(callback) {
13
- this.listeners.add(callback);
14
- return () => this.listeners.delete(callback);
15
- }
16
- callSubscribed(action) {
17
- this.listeners.forEach(listener => listener(action));
18
- }
19
- createQuerySingleItem(options, transformer) {
20
- const query = this.store.createQuerySingleItem(options, transformer);
21
- query.setSubscribeStore(this);
22
- return query;
23
- }
24
- createQueryCollection(options, transformer) {
25
- const query = this.store.createQueryCollection(options, transformer);
26
- query.setSubscribeStore(this);
27
- return query;
28
- }
29
- findAll(criteria, sort) {
30
- return this.store.findAll(criteria, sort);
31
- }
32
- findByKey(key, criteria) {
33
- return this.store.findByKey(key, criteria);
34
- }
35
- findOne(criteria, sort) {
36
- return this.store.findOne(criteria, sort);
37
- }
38
- async insertOne(object) {
39
- const inserted = await this.store.insertOne(object);
40
- this.callSubscribed({
41
- type: 'inserted',
42
- next: [inserted]
43
- });
44
- return inserted;
45
- }
46
- async replaceOne(object) {
47
- const replaced = await this.store.replaceOne(object);
48
- this.callSubscribed({
49
- type: 'updated',
50
- changes: [[object, replaced]]
51
- });
52
- return replaced;
53
- }
54
- async replaceSeveral(objects) {
55
- const replacedObjects = await this.store.replaceSeveral(objects);
56
- this.callSubscribed({
57
- type: 'updated',
58
- changes: objects.map((prev, index) => [prev, replacedObjects[index]])
59
- });
60
- return replacedObjects;
61
- }
62
- async upsertOne(object, setOnInsertPartialObject) {
63
- const result = await this.upsertOneWithInfo(object, setOnInsertPartialObject);
64
- return result.object;
65
- }
66
- async upsertOneWithInfo(object, setOnInsertPartialObject) {
67
- const upsertedWithInfo = await this.store.upsertOneWithInfo(object, setOnInsertPartialObject);
68
- if (upsertedWithInfo.inserted) {
69
- this.callSubscribed({
70
- type: 'inserted',
71
- next: [upsertedWithInfo.object]
72
- });
73
- } else {
74
- throw new Error('TODO');
75
- }
76
- return upsertedWithInfo;
77
- }
78
- async partialUpdateByKey(key, partialUpdate, criteria) {
79
- return this.partialUpdateOne(await this.findOne({
80
- [this.store.keyPath]: key,
81
- ...criteria
82
- }), partialUpdate);
83
- }
84
- async partialUpdateOne(object, partialUpdate) {
85
- const updated = await this.store.partialUpdateOne(object, partialUpdate);
86
- this.callSubscribed({
87
- type: 'updated',
88
- changes: [[object, updated]]
89
- });
90
- return updated;
91
- }
92
- async partialUpdateMany(criteria, partialUpdate) {
93
- const cursor = await this.store.cursor(criteria);
94
- const changes = [];
95
- await cursor.forEach(async model => {
96
- const key = model[this.store.keyPath];
97
- const updated = await this.store.partialUpdateByKey(key, partialUpdate, criteria);
98
- changes.push([model, updated]);
99
- });
100
- this.callSubscribed({
101
- type: 'updated',
102
- changes
103
- });
104
- }
105
- async deleteByKey(key, criteria) {
106
- return this.deleteOne(await this.findByKey(key, criteria));
107
- }
108
- async deleteOne(object) {
109
- await this.store.deleteOne(object);
110
- this.callSubscribed({
111
- type: 'deleted',
112
- prev: [object]
113
- });
114
- }
115
- async deleteMany(criteria) {
116
- const cursor = await this.store.cursor(criteria);
117
- const prev = await cursor.toArray();
118
- await this.store.deleteMany(criteria);
119
- this.callSubscribed({
120
- type: 'deleted',
121
- prev
122
- });
123
- }
124
- async count(criteria) {
125
- return this.store.count(criteria);
126
- }
127
- async cursor(criteria, sort) {
128
- const cursor = await this.store.cursor(criteria, sort);
129
- cursor.overrideStore(this);
130
- return cursor;
131
- }
132
- }
133
-
134
- class AbstractSubscribableStoreQuery {
135
- changeParams() {
136
- throw new Error('Method not supported. Please create a new query.');
137
- }
138
- changePartialParams() {
139
- throw new Error('Method not supported. Please create a new query.');
140
- }
141
- setSubscribeStore(store) {
142
- this._subscribeStore = store;
143
- }
144
- getSubscribeStore() {
145
- if (!this._subscribeStore) {
146
- throw new Error('_subscribeStore is not initialized');
147
- }
148
- return this._subscribeStore;
149
- }
150
- fetchAndSubscribe(callback) {
151
- return this._subscribe(callback, true);
152
- }
153
- subscribe(callback) {
154
- return this._subscribe(callback, false);
155
- }
156
- }
157
-
158
- export { AbstractSubscribableStoreQuery, SubscribeStore };
159
- //# sourceMappingURL=index-browsermodern.es.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-browsermodern.es.js","sources":["../src/SubscribeStore.ts","../src/AbstractSubscribableStoreQuery.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type {\n Store as StoreInterface,\n AbstractConnection,\n UpsertResult,\n SubscribableStoreQuery,\n AbstractStoreCursor,\n SubscribableStore,\n QueryParams,\n UpsertPartialObject,\n BaseModel,\n InsertType,\n Update,\n Criteria,\n Sort,\n QueryOptions,\n Transformer,\n AllowedKeyValue,\n OptionalBaseModelKeysForInsert,\n} from 'liwi-store';\n\nexport type Actions<Model> =\n | { type: 'deleted'; prev: Model[] }\n | { type: 'inserted'; next: Model[] }\n | { type: 'updated'; changes: [Model, Model][] };\n\nexport type Listener<Model> = (action: Actions<Model>) => unknown;\n\nexport default class SubscribeStore<\n KeyPath extends keyof Model,\n KeyValue extends AllowedKeyValue,\n Model extends BaseModel & Record<KeyPath, KeyValue>,\n ModelInsertType extends InsertType<Model, KeyPath>,\n Connection extends AbstractConnection,\n Store extends SubscribableStore<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n Connection\n >,\n> implements\n StoreInterface<KeyPath, KeyValue, Model, ModelInsertType, Connection>\n{\n private readonly store: Store;\n\n private readonly listeners = new Set<Listener<Model>>();\n\n readonly keyPath: KeyPath;\n\n constructor(store: Store) {\n this.store = store;\n this.keyPath = store.keyPath;\n }\n\n get connection(): Connection {\n return this.store.connection;\n }\n\n subscribe(callback: Listener<Model>): () => void {\n this.listeners.add(callback);\n return () => this.listeners.delete(callback);\n }\n\n callSubscribed(action: Actions<Model>): void {\n this.listeners.forEach((listener) => listener(action));\n }\n\n createQuerySingleItem<\n Result extends Record<KeyPath, KeyValue>,\n Params extends QueryParams<Params>,\n >(\n options: QueryOptions<Model>,\n transformer?: Transformer<Model, Result>,\n ): SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Result,\n Params\n > {\n const query: SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Result,\n Params\n > = this.store.createQuerySingleItem<Result, Params>(options, transformer);\n query.setSubscribeStore(this);\n return query;\n }\n\n createQueryCollection<\n Item extends Record<KeyPath, KeyValue>,\n Params extends QueryParams<Params>,\n >(\n options: QueryOptions<Model>,\n transformer?: Transformer<Model, Item>,\n ): SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Item[],\n Params\n > {\n const query: SubscribableStoreQuery<\n KeyPath,\n KeyValue,\n Model,\n SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>,\n Item[],\n Params\n > = this.store.createQueryCollection<Item, Params>(options, transformer);\n query.setSubscribeStore(this);\n return query;\n }\n\n findAll(criteria?: Criteria<Model>, sort?: Sort<Model>): Promise<Model[]> {\n return this.store.findAll(criteria, sort);\n }\n\n findByKey(\n key: KeyValue,\n criteria?: Criteria<Model>,\n ): Promise<Model | undefined> {\n return this.store.findByKey(key, criteria);\n }\n\n findOne(\n criteria: Criteria<Model>,\n sort?: Sort<Model>,\n ): Promise<Model | undefined> {\n return this.store.findOne(criteria, sort);\n }\n\n async insertOne(object: ModelInsertType): Promise<Model> {\n const inserted = await this.store.insertOne(object);\n this.callSubscribed({ type: 'inserted', next: [inserted] });\n return inserted;\n }\n\n async replaceOne(object: Model): Promise<Model> {\n const replaced = await this.store.replaceOne(object);\n this.callSubscribed({ type: 'updated', changes: [[object, replaced]] });\n return replaced;\n }\n\n async replaceSeveral(objects: Model[]): Promise<Model[]> {\n const replacedObjects = await this.store.replaceSeveral(objects);\n this.callSubscribed({\n type: 'updated',\n changes: objects.map((prev, index) => [prev, replacedObjects[index]]),\n });\n return replacedObjects;\n }\n\n async upsertOne<\n K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>,\n >(\n object: UpsertPartialObject<KeyPath, KeyValue, Model, K>,\n setOnInsertPartialObject?: Update<Model>['$setOnInsert'],\n ): Promise<Model> {\n const result = await this.upsertOneWithInfo(\n object,\n setOnInsertPartialObject,\n );\n return result.object;\n }\n\n async upsertOneWithInfo<\n K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>,\n >(\n object: UpsertPartialObject<KeyPath, KeyValue, Model, K>,\n setOnInsertPartialObject?: Update<Model>['$setOnInsert'],\n ): Promise<UpsertResult<Model>> {\n const upsertedWithInfo = await this.store.upsertOneWithInfo(\n object,\n setOnInsertPartialObject,\n );\n if (upsertedWithInfo.inserted) {\n this.callSubscribed({\n type: 'inserted',\n next: [upsertedWithInfo.object],\n });\n } else {\n throw new Error('TODO');\n }\n return upsertedWithInfo;\n }\n\n async partialUpdateByKey(\n key: KeyValue,\n partialUpdate: Update<Model>,\n criteria?: Criteria<Model>,\n ): Promise<Model> {\n return this.partialUpdateOne(\n (await this.findOne({\n [this.store.keyPath]: key,\n ...criteria,\n } as Criteria<Model>))!,\n partialUpdate,\n );\n }\n\n async partialUpdateOne(\n object: Model,\n partialUpdate: Update<Model>,\n ): Promise<Model> {\n const updated = await this.store.partialUpdateOne(object, partialUpdate);\n this.callSubscribed({ type: 'updated', changes: [[object, updated]] });\n return updated;\n }\n\n async partialUpdateMany(\n criteria: Criteria<Model>,\n partialUpdate: Update<Model>,\n ): Promise<void> {\n const cursor = await this.store.cursor(criteria);\n const changes: [Model, Model][] = [];\n\n await cursor.forEach(async (model) => {\n const key = model[this.store.keyPath];\n const updated = await this.store.partialUpdateByKey(\n key,\n partialUpdate,\n criteria,\n );\n changes.push([model, updated]);\n });\n this.callSubscribed({ type: 'updated', changes });\n }\n\n async deleteByKey(key: KeyValue, criteria?: Criteria<Model>): Promise<void> {\n return this.deleteOne((await this.findByKey(key, criteria))!);\n }\n\n async deleteOne(object: Model): Promise<void> {\n await this.store.deleteOne(object);\n this.callSubscribed({ type: 'deleted', prev: [object] });\n }\n\n async deleteMany(criteria: Criteria<Model>): Promise<void> {\n const cursor = await this.store.cursor(criteria);\n const prev: Model[] = await cursor.toArray();\n await this.store.deleteMany(criteria);\n this.callSubscribed({ type: 'deleted', prev });\n }\n\n async count(criteria?: Criteria<Model>): Promise<number> {\n return this.store.count(criteria);\n }\n\n async cursor<Result extends Partial<Model> = Model>(\n criteria?: Criteria<Model>,\n sort?: Sort<Model>,\n ): Promise<AbstractStoreCursor<any, KeyValue, Model, Result>> {\n const cursor = await this.store.cursor<Result>(criteria, sort);\n cursor.overrideStore(this);\n return cursor;\n }\n}\n","import type {\n Query,\n SubscribeCallback,\n QuerySubscription,\n QueryResult,\n QueryParams,\n BaseModel,\n InsertType,\n AllowedKeyValue,\n} from 'liwi-store';\nimport type SubscribeStore from './SubscribeStore';\n\nexport default abstract class AbstractSubscribableStoreQuery<\n KeyPath extends keyof Model,\n KeyValue extends AllowedKeyValue,\n Model extends BaseModel & Record<KeyPath, KeyValue>,\n ModelInsertType extends InsertType<Model, KeyPath>,\n Params extends QueryParams<Params> = never,\n Result = Model,\n> implements Query<Result, Params, KeyValue>\n{\n changeParams(params: Params): never {\n throw new Error('Method not supported. Please create a new query.');\n }\n\n changePartialParams(\n params: Params extends undefined ? never : Partial<Params>,\n ): never {\n throw new Error('Method not supported. Please create a new query.');\n }\n\n private _subscribeStore?: SubscribeStore<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n any,\n any\n >;\n\n setSubscribeStore(\n store: SubscribeStore<KeyPath, KeyValue, Model, ModelInsertType, any, any>,\n ): void {\n this._subscribeStore = store;\n }\n\n getSubscribeStore(): SubscribeStore<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n any,\n any\n > {\n if (!this._subscribeStore) {\n throw new Error('_subscribeStore is not initialized');\n }\n return this._subscribeStore;\n }\n\n abstract fetch<T>(\n onFulfilled: (result: QueryResult<Result>) => T,\n ): Promise<T>;\n\n fetchAndSubscribe(\n callback: SubscribeCallback<KeyValue, Result>,\n ): QuerySubscription {\n return this._subscribe(callback, true);\n }\n\n subscribe(callback: SubscribeCallback<KeyValue, Result>): QuerySubscription {\n return this._subscribe(callback, false);\n }\n\n abstract _subscribe(\n callback: SubscribeCallback<KeyValue, Result>,\n _includeInitial: boolean,\n ): QuerySubscription;\n}\n"],"names":["SubscribeStore","listeners","Set","constructor","store","keyPath","connection","subscribe","callback","add","delete","callSubscribed","action","forEach","listener","createQuerySingleItem","options","transformer","query","setSubscribeStore","createQueryCollection","findAll","criteria","sort","findByKey","key","findOne","insertOne","object","inserted","type","next","replaceOne","replaced","changes","replaceSeveral","objects","replacedObjects","map","prev","index","upsertOne","setOnInsertPartialObject","result","upsertOneWithInfo","upsertedWithInfo","Error","partialUpdateByKey","partialUpdate","partialUpdateOne","updated","partialUpdateMany","cursor","model","push","deleteByKey","deleteOne","deleteMany","toArray","count","overrideStore","AbstractSubscribableStoreQuery","changeParams","changePartialParams","_subscribeStore","getSubscribeStore","fetchAndSubscribe","_subscribe"],"mappings":"AAAA;;AA4Be,MAAMA,cAAc,CAenC;EAGmBC,SAAS,GAAG,IAAIC,GAAG,EAAmB,CAAA;EAIvDC,WAAWA,CAACC,KAAY,EAAE;IACxB,IAAI,CAACA,KAAK,GAAGA,KAAK,CAAA;AAClB,IAAA,IAAI,CAACC,OAAO,GAAGD,KAAK,CAACC,OAAO,CAAA;AAC9B,GAAA;EAEA,IAAIC,UAAUA,GAAe;AAC3B,IAAA,OAAO,IAAI,CAACF,KAAK,CAACE,UAAU,CAAA;AAC9B,GAAA;EAEAC,SAASA,CAACC,QAAyB,EAAc;AAC/C,IAAA,IAAI,CAACP,SAAS,CAACQ,GAAG,CAACD,QAAQ,CAAC,CAAA;IAC5B,OAAO,MAAM,IAAI,CAACP,SAAS,CAACS,MAAM,CAACF,QAAQ,CAAC,CAAA;AAC9C,GAAA;EAEAG,cAAcA,CAACC,MAAsB,EAAQ;IAC3C,IAAI,CAACX,SAAS,CAACY,OAAO,CAAEC,QAAQ,IAAKA,QAAQ,CAACF,MAAM,CAAC,CAAC,CAAA;AACxD,GAAA;AAEAG,EAAAA,qBAAqBA,CAInBC,OAA4B,EAC5BC,WAAwC,EAQxC;IACA,MAAMC,KAOL,GAAG,IAAI,CAACd,KAAK,CAACW,qBAAqB,CAAiBC,OAAO,EAAEC,WAAW,CAAC,CAAA;AAC1EC,IAAAA,KAAK,CAACC,iBAAiB,CAAC,IAAI,CAAC,CAAA;AAC7B,IAAA,OAAOD,KAAK,CAAA;AACd,GAAA;AAEAE,EAAAA,qBAAqBA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