liwi-subscribe-store 8.1.0 → 9.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/.eslintrc.json +1 -1
- package/CHANGELOG.md +37 -0
- package/dist/AbstractSubscribableStoreQuery.d.ts.map +1 -1
- package/dist/SubscribeStore.d.ts +6 -5
- package/dist/SubscribeStore.d.ts.map +1 -1
- package/dist/index-browser.cjs.js +72 -51
- package/dist/index-browser.cjs.js.map +1 -1
- package/dist/index-browser.es.js +70 -49
- package/dist/index-browser.es.js.map +1 -1
- package/dist/index-browsermodern.es.js +37 -32
- package/dist/index-browsermodern.es.js.map +1 -1
- package/dist/{index-node12.cjs.js → index-node14.cjs} +38 -33
- package/dist/index-node14.cjs.map +1 -0
- package/dist/{index-browsermodern-dev.es.js → index-node14.mjs} +38 -33
- package/dist/index-node14.mjs.map +1 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/package.json +25 -42
- package/rollup.config.mjs +5 -0
- package/src/.eslintrc.json +19 -2
- package/src/AbstractSubscribableStoreQuery.ts +3 -2
- package/src/SubscribeStore.ts +19 -11
- package/src/index.ts +3 -4
- package/tsconfig.eslint.json +7 -0
- package/dist/index-browser-dev.cjs.js +0 -526
- package/dist/index-browser-dev.cjs.js.map +0 -1
- package/dist/index-browser-dev.es.js +0 -514
- package/dist/index-browser-dev.es.js.map +0 -1
- package/dist/index-browsermodern-dev.es.js.map +0 -1
- package/dist/index-node12-dev.cjs.js +0 -190
- package/dist/index-node12-dev.cjs.js.map +0 -1
- package/dist/index-node12-dev.es.js +0 -185
- package/dist/index-node12-dev.es.js.map +0 -1
- package/dist/index-node12-dev.mjs +0 -185
- package/dist/index-node12-dev.mjs.map +0 -1
- package/dist/index-node12.cjs.js.map +0 -1
- package/dist/index-node12.es.js +0 -185
- package/dist/index-node12.es.js.map +0 -1
- package/dist/index-node12.mjs +0 -185
- package/dist/index-node12.mjs.map +0 -1
- package/index.js +0 -6
package/.eslintrc.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,43 @@
|
|
|
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
|
+
# [9.0.0](https://github.com/liwijs/liwi/compare/v8.3.1...v9.0.0) (2022-03-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **deps:** update dependency mongodb to v4 ([#22](https://github.com/liwijs/liwi/issues/22)) ([cdf9204](https://github.com/liwijs/liwi/commit/cdf920461156e5dd6dceaf5bf26b24c206385634))
|
|
12
|
+
* refactor and use node 14 ([101c861](https://github.com/liwijs/liwi/commit/101c861063420fc5a83ff5a45322b9529962dcc2))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### BREAKING CHANGES
|
|
16
|
+
|
|
17
|
+
* **deps:** cursor.count() is removed and replaced by store.count()
|
|
18
|
+
* requires node 14
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## [8.3.1](https://github.com/liwijs/liwi/compare/v8.3.0...v8.3.1) (2021-11-28)
|
|
25
|
+
|
|
26
|
+
**Note:** Version bump only for package liwi-subscribe-store
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# [8.3.0](https://github.com/liwijs/liwi/compare/v8.2.1...v8.3.0) (2021-11-22)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### Bug Fixes
|
|
36
|
+
|
|
37
|
+
* update pob-babel and bring back webpack 4 compat ([135caf3](https://github.com/liwijs/liwi/commit/135caf3c2d1693ae39d33e7527f16392720865a5))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
6
43
|
# [8.1.0](https://github.com/liwijs/liwi/compare/v8.0.4...v8.1.0) (2021-03-28)
|
|
7
44
|
|
|
8
45
|
**Note:** Version bump only for package liwi-subscribe-store
|
|
@@ -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,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,8BAA8B,CAC1D,OAAO,SAAS,MAAM,KAAK,EAC3B,QAAQ,SAAS,eAAe,EAChC,KAAK,SAAS,SAAS,GAAG,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,EACnD,eAAe,SAAS,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,EAClD,MAAM,SAAS,WAAW,CAAC,MAAM,CAAC,GAAG,KAAK,EAC1C,MAAM,GAAG,KAAK,CACd,YAAW,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;
|
|
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,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,8BAA8B,CAC1D,OAAO,SAAS,MAAM,KAAK,EAC3B,QAAQ,SAAS,eAAe,EAChC,KAAK,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em<Result extends Record<KeyPath, KeyValue>, Params extends QueryParams<Params>>(options: QueryOptions<Model>, transformer?: Transformer<Model, Result>): SubscribableStoreQuery<KeyPath, KeyValue, Model, SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>, Result, Params>;
|
|
23
23
|
createQueryCollection<Item extends Record<KeyPath, KeyValue>, Params extends QueryParams<Params>>(options: QueryOptions<Model>, transformer?: Transformer<Model, Item>): SubscribableStoreQuery<KeyPath, KeyValue, Model, SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>, Item[], Params>;
|
|
24
24
|
findAll(criteria?: Criteria<Model>, sort?: Sort<Model>): Promise<Model[]>;
|
|
25
|
-
findByKey(key:
|
|
25
|
+
findByKey(key: KeyValue, criteria?: Criteria<Model>): Promise<Model | undefined>;
|
|
26
26
|
findOne(criteria: Criteria<Model>, sort?: Sort<Model>): Promise<Model | undefined>;
|
|
27
27
|
insertOne(object: ModelInsertType): Promise<Model>;
|
|
28
28
|
replaceOne(object: Model): Promise<Model>;
|
|
29
29
|
replaceSeveral(objects: Model[]): Promise<Model[]>;
|
|
30
|
-
upsertOne<K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>>(object: UpsertPartialObject<KeyPath, KeyValue, Model, K>, setOnInsertPartialObject?:
|
|
31
|
-
upsertOneWithInfo<K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>>(object: UpsertPartialObject<KeyPath, KeyValue, Model, K>, setOnInsertPartialObject?:
|
|
32
|
-
partialUpdateByKey(key:
|
|
30
|
+
upsertOne<K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>>(object: UpsertPartialObject<KeyPath, KeyValue, Model, K>, setOnInsertPartialObject?: Update<Model>['$setOnInsert']): Promise<Model>;
|
|
31
|
+
upsertOneWithInfo<K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>>(object: UpsertPartialObject<KeyPath, KeyValue, Model, K>, setOnInsertPartialObject?: Update<Model>['$setOnInsert']): Promise<UpsertResult<Model>>;
|
|
32
|
+
partialUpdateByKey(key: KeyValue, partialUpdate: Update<Model>, criteria?: Criteria<Model>): Promise<Model>;
|
|
33
33
|
partialUpdateOne(object: Model, partialUpdate: Update<Model>): Promise<Model>;
|
|
34
34
|
partialUpdateMany(criteria: Criteria<Model>, partialUpdate: Update<Model>): Promise<void>;
|
|
35
|
-
deleteByKey(key:
|
|
35
|
+
deleteByKey(key: KeyValue, criteria?: Criteria<Model>): Promise<void>;
|
|
36
36
|
deleteOne(object: Model): Promise<void>;
|
|
37
37
|
deleteMany(criteria: Criteria<Model>): Promise<void>;
|
|
38
|
+
count(criteria?: Criteria<Model>): Promise<number>;
|
|
38
39
|
cursor<Result = Model>(criteria?: Criteria<Model>, sort?: Sort<Model>): Promise<AbstractStoreCursor<any, KeyValue, Model, Result>>;
|
|
39
40
|
}
|
|
40
41
|
//# sourceMappingURL=SubscribeStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscribeStore.d.ts","sourceRoot":"","sources":["../src/SubscribeStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,KAAK,IAAI,cAAc,EACvB,kBAAkB,EAClB,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,EACX,mBAAmB,EACpB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,YAAY,EACZ,WAAW,EACX,eAAe,EACf,8BAA8B,EAC/B,MAAM,YAAY,CAAC;AAEpB,oBAAY,OAAO,CAAC,KAAK,IACrB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,KAAK,EAAE,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAA;CAAE,GAC9C;IAAE,IAAI,E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,EAC1B,IAAI,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GACjB,OAAO,CAAC,mBAAmB,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;CAK9D"}
|
|
@@ -3,52 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var _extends = require('@babel/runtime/helpers/esm/extends');
|
|
6
|
-
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
7
6
|
var _asyncToGenerator = require('@babel/runtime/helpers/esm/asyncToGenerator');
|
|
8
7
|
var _createClass = require('@babel/runtime/helpers/esm/createClass');
|
|
8
|
+
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
9
9
|
|
|
10
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e[
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
11
11
|
|
|
12
12
|
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
13
|
-
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
|
|
14
13
|
var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
|
|
15
14
|
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
|
|
16
|
-
|
|
17
|
-
var AbstractSubscribableStoreQuery = /*#__PURE__*/function () {
|
|
18
|
-
function AbstractSubscribableStoreQuery() {}
|
|
19
|
-
|
|
20
|
-
var _proto = AbstractSubscribableStoreQuery.prototype;
|
|
21
|
-
|
|
22
|
-
_proto.changeParams = function changeParams() {
|
|
23
|
-
throw new Error('Method not supported. Please create a new query.');
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
_proto.changePartialParams = function changePartialParams() {
|
|
27
|
-
throw new Error('Method not supported. Please create a new query.');
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
_proto.setSubscribeStore = function setSubscribeStore(store) {
|
|
31
|
-
this._subscribeStore = store;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
_proto.getSubscribeStore = function getSubscribeStore() {
|
|
35
|
-
if (!this._subscribeStore) {
|
|
36
|
-
throw new Error('_subscribeStore is not initialized');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return this._subscribeStore;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
_proto.fetchAndSubscribe = function fetchAndSubscribe(callback) {
|
|
43
|
-
return this._subscribe(callback, true);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
_proto.subscribe = function subscribe(callback) {
|
|
47
|
-
return this._subscribe(callback, false);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
return AbstractSubscribableStoreQuery;
|
|
51
|
-
}();
|
|
15
|
+
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
|
|
52
16
|
|
|
53
17
|
/* eslint-disable max-lines */
|
|
54
18
|
var SubscribeStore = /*#__PURE__*/function () {
|
|
@@ -65,7 +29,7 @@ var SubscribeStore = /*#__PURE__*/function () {
|
|
|
65
29
|
|
|
66
30
|
this.listeners.add(callback);
|
|
67
31
|
return function () {
|
|
68
|
-
return _this.listeners
|
|
32
|
+
return _this.listeners["delete"](callback);
|
|
69
33
|
};
|
|
70
34
|
};
|
|
71
35
|
|
|
@@ -267,15 +231,15 @@ var SubscribeStore = /*#__PURE__*/function () {
|
|
|
267
231
|
|
|
268
232
|
_proto.partialUpdateByKey = /*#__PURE__*/function () {
|
|
269
233
|
var _partialUpdateByKey = _asyncToGenerator__default( /*#__PURE__*/_regeneratorRuntime__default.mark(function _callee6(key, partialUpdate, criteria) {
|
|
234
|
+
var _extends2;
|
|
235
|
+
|
|
270
236
|
return _regeneratorRuntime__default.wrap(function _callee6$(_context6) {
|
|
271
237
|
while (1) {
|
|
272
238
|
switch (_context6.prev = _context6.next) {
|
|
273
239
|
case 0:
|
|
274
240
|
_context6.t0 = this;
|
|
275
241
|
_context6.next = 3;
|
|
276
|
-
return this.findOne(_extends__default({
|
|
277
|
-
[this.store.keyPath]: key
|
|
278
|
-
}, criteria));
|
|
242
|
+
return this.findOne(_extends__default((_extends2 = {}, _extends2[this.store.keyPath] = key, _extends2), criteria));
|
|
279
243
|
|
|
280
244
|
case 3:
|
|
281
245
|
_context6.t1 = _context6.sent;
|
|
@@ -483,27 +447,48 @@ var SubscribeStore = /*#__PURE__*/function () {
|
|
|
483
447
|
};
|
|
484
448
|
}();
|
|
485
449
|
|
|
486
|
-
_proto.
|
|
487
|
-
var
|
|
488
|
-
var cursor;
|
|
450
|
+
_proto.count = /*#__PURE__*/function () {
|
|
451
|
+
var _count = _asyncToGenerator__default( /*#__PURE__*/_regeneratorRuntime__default.mark(function _callee13(criteria) {
|
|
489
452
|
return _regeneratorRuntime__default.wrap(function _callee13$(_context13) {
|
|
490
453
|
while (1) {
|
|
491
454
|
switch (_context13.prev = _context13.next) {
|
|
492
455
|
case 0:
|
|
493
|
-
_context13.
|
|
456
|
+
return _context13.abrupt("return", this.store.count(criteria));
|
|
457
|
+
|
|
458
|
+
case 1:
|
|
459
|
+
case "end":
|
|
460
|
+
return _context13.stop();
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}, _callee13, this);
|
|
464
|
+
}));
|
|
465
|
+
|
|
466
|
+
return function count() {
|
|
467
|
+
return _count.apply(this, arguments);
|
|
468
|
+
};
|
|
469
|
+
}();
|
|
470
|
+
|
|
471
|
+
_proto.cursor = /*#__PURE__*/function () {
|
|
472
|
+
var _cursor = _asyncToGenerator__default( /*#__PURE__*/_regeneratorRuntime__default.mark(function _callee14(criteria, sort) {
|
|
473
|
+
var cursor;
|
|
474
|
+
return _regeneratorRuntime__default.wrap(function _callee14$(_context14) {
|
|
475
|
+
while (1) {
|
|
476
|
+
switch (_context14.prev = _context14.next) {
|
|
477
|
+
case 0:
|
|
478
|
+
_context14.next = 2;
|
|
494
479
|
return this.store.cursor(criteria, sort);
|
|
495
480
|
|
|
496
481
|
case 2:
|
|
497
|
-
cursor =
|
|
482
|
+
cursor = _context14.sent;
|
|
498
483
|
cursor.overrideStore(this);
|
|
499
|
-
return
|
|
484
|
+
return _context14.abrupt("return", cursor);
|
|
500
485
|
|
|
501
486
|
case 5:
|
|
502
487
|
case "end":
|
|
503
|
-
return
|
|
488
|
+
return _context14.stop();
|
|
504
489
|
}
|
|
505
490
|
}
|
|
506
|
-
},
|
|
491
|
+
}, _callee14, this);
|
|
507
492
|
}));
|
|
508
493
|
|
|
509
494
|
return function cursor() {
|
|
@@ -521,6 +506,42 @@ var SubscribeStore = /*#__PURE__*/function () {
|
|
|
521
506
|
return SubscribeStore;
|
|
522
507
|
}();
|
|
523
508
|
|
|
509
|
+
var AbstractSubscribableStoreQuery = /*#__PURE__*/function () {
|
|
510
|
+
function AbstractSubscribableStoreQuery() {}
|
|
511
|
+
|
|
512
|
+
var _proto = AbstractSubscribableStoreQuery.prototype;
|
|
513
|
+
|
|
514
|
+
_proto.changeParams = function changeParams() {
|
|
515
|
+
throw new Error('Method not supported. Please create a new query.');
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
_proto.changePartialParams = function changePartialParams() {
|
|
519
|
+
throw new Error('Method not supported. Please create a new query.');
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
_proto.setSubscribeStore = function setSubscribeStore(store) {
|
|
523
|
+
this._subscribeStore = store;
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
_proto.getSubscribeStore = function getSubscribeStore() {
|
|
527
|
+
if (!this._subscribeStore) {
|
|
528
|
+
throw new Error('_subscribeStore is not initialized');
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
return this._subscribeStore;
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
_proto.fetchAndSubscribe = function fetchAndSubscribe(callback) {
|
|
535
|
+
return this._subscribe(callback, true);
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
_proto.subscribe = function subscribe(callback) {
|
|
539
|
+
return this._subscribe(callback, false);
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
return AbstractSubscribableStoreQuery;
|
|
543
|
+
}();
|
|
544
|
+
|
|
524
545
|
exports.AbstractSubscribableStoreQuery = AbstractSubscribableStoreQuery;
|
|
525
546
|
exports.SubscribeStore = SubscribeStore;
|
|
526
547
|
//# sourceMappingURL=index-browser.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browser.cjs.js","sources":["../src/AbstractSubscribableStoreQuery.ts","../src/SubscribeStore.ts"],"sourcesContent":["import type {\n Query,\n SubscribeCallback,\n QuerySubscription,\n QueryResult,\n QueryParams,\n} from 'liwi-store';\nimport type { BaseModel, InsertType, AllowedKeyValue } from 'liwi-types';\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 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","/* 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} from 'liwi-store';\nimport type {\n BaseModel,\n InsertType,\n Update,\n Criteria,\n Sort,\n QueryOptions,\n Transformer,\n AllowedKeyValue,\n OptionalBaseModelKeysForInsert,\n} from 'liwi-types';\n\nexport type Actions<Model> =\n | { type: 'inserted'; next: Model[] }\n | { type: 'updated'; changes: [Model, Model][] }\n | { type: 'deleted'; prev: 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 private readonly store: Store;\n\n private readonly listeners: Set<Listener<Model>> = new Set();\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(key: any, criteria?: Criteria<Model>): 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?: Pick<Model, K>,\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?: Pick<Model, K>,\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: any,\n partialUpdate: Update<Model>,\n criteria?: Criteria<Model>,\n ): Promise<Model> {\n return this.partialUpdateOne(\n (await this.findOne({ [this.store.keyPath]: key, ...criteria }))!,\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: any, 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 cursor<Result = 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"],"names":["AbstractSubscribableStoreQuery","changeParams","Error","changePartialParams","setSubscribeStore","store","_subscribeStore","getSubscribeStore","fetchAndSubscribe","callback","_subscribe","subscribe","SubscribeStore","listeners","Set","keyPath","add","delete","callSubscribed","action","forEach","listener","createQuerySingleItem","options","transformer","query","createQueryCollection","findAll","criteria","sort","findByKey","key","findOne","insertOne","object","inserted","type","next","replaceOne","replaced","changes","replaceSeveral","objects","replacedObjects","map","prev","index","upsertOne","setOnInsertPartialObject","upsertOneWithInfo","result","upsertedWithInfo","partialUpdateByKey","partialUpdate","partialUpdateOne","updated","partialUpdateMany","cursor","model","push","deleteByKey","deleteOne","deleteMany","toArray","overrideStore","connection"],"mappings":";;;;;;;;;;;;;;;;IAU8BA;;;;;SAQ5BC,eAAA,wBAAoC;AAClC,UAAM,IAAIC,KAAJ,CAAU,kDAAV,CAAN;AACD;;SAEDC,sBAAA,+BAES;AACP,UAAM,IAAID,KAAJ,CAAU,kDAAV,CAAN;AACD;;SAWDE,oBAAA,2BACEC,KADF,EAEQ;AACN,SAAKC,eAAL,GAAuBD,KAAvB;AACD;;SAEDE,oBAAA,6BAOE;AACA,QAAI,CAAC,KAAKD,eAAV,EAA2B;AACzB,YAAM,IAAIJ,KAAJ,CAAU,oCAAV,CAAN;AACD;;AACD,WAAO,KAAKI,eAAZ;AACD;;SAMDE,oBAAA,2BACEC,QADF,EAEqB;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IuB,KAAKxB,KAAL,CAAWoD,MAAX,CAA0B7B,QAA1B,EAAoCC,IAApC,CAJvB;;AAAA;AAIQ4B,cAAAA,MAJR;AAKEA,cAAAA,MAAM,CAACO,aAAP,CAAqB,IAArB;AALF,iDAMSP,MANT;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;;;;SA9LA,eAA6B;AAC3B,aAAO,KAAKpD,KAAL,CAAW4D,UAAlB;AACD;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index-browser.cjs.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} from 'liwi-store';\nimport type {\n BaseModel,\n InsertType,\n Update,\n Criteria,\n Sort,\n QueryOptions,\n Transformer,\n AllowedKeyValue,\n OptionalBaseModelKeysForInsert,\n} from 'liwi-types';\n\nexport type Actions<Model> =\n | { type: 'inserted'; next: Model[] }\n | { type: 'updated'; changes: [Model, Model][] }\n | { type: 'deleted'; prev: 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: Set<Listener<Model>> = new Set();\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({ [this.store.keyPath]: key, ...criteria }))!,\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 = 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} from 'liwi-store';\nimport type { BaseModel, InsertType, AllowedKeyValue } from 'liwi-types';\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","subscribe","callback","add","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","upsertOneWithInfo","result","upsertedWithInfo","Error","partialUpdateByKey","partialUpdate","partialUpdateOne","updated","partialUpdateMany","cursor","model","push","deleteByKey","deleteOne","deleteMany","toArray","count","overrideStore","connection","AbstractSubscribableStoreQuery","changeParams","changePartialParams","_subscribeStore","getSubscribeStore","fetchAndSubscribe","_subscribe"],"mappings":";;;;;;;;;;;;;;;;AAAA;IA8BqBA;AAsBnB,0BAAYC,KAAZ,EAA0B;AAAA,SAJTC,SAIS,GAJyB,IAAIC,GAAJ,EAIzB;AACxB,SAAKF,KAAL,GAAaA,KAAb;AACA,SAAKG,OAAL,GAAeH,KAAK,CAACG,OAArB;AACD;;;;SAMDC,YAAA,mBAAUC,QAAV,EAAiD;AAAA;;AAC/C,SAAKJ,SAAL,CAAeK,GAAf,CAAmBD,QAAnB;AACA,WAAO;AAAA,aAAM,KAAI,CAACJ,SAAL,WA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B,KAAJ,CAAU,kDAAV,CAAN;AACD;;SAEDkB,sBAAA,+BAES;AACP,UAAM,IAAIlB,KAAJ,CAAU,kDAAV,CAAN;AACD;;SAWD3B,oBAAA,2BACEf,KADF,EAEQ;AACN,SAAK6D,eAAL,GAAuB7D,KAAvB;AACD;;SAED8D,oBAAA,6BAOE;AACA,QAAI,CAAC,KAAKD,eAAV,EAA2B;AACzB,YAAM,IAAInB,KAAJ,CAAU,oCAAV,CAAN;AACD;;AACD,WAAO,KAAKmB,eAAZ;AACD;;SAMDE,oBAAA,2BACE1D,QADF,EAEqB;AACnB,WAAO,KAAK2D,UAAL,CAAgB3D,QAAhB,EAA0B,IAA1B,CAAP;AACD;;SAEDD,YAAA,mBAAUC,QAAV,EAA4E;AAC1E,WAAO,KAAK2D,UAAL,CAAgB3D,QAAhB,EAA0B,KAA1B,CAAP;AACD;;;;;;;;"}
|
package/dist/index-browser.es.js
CHANGED
|
@@ -1,43 +1,7 @@
|
|
|
1
1
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
-
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
3
2
|
import _asyncToGenerator from '@babel/runtime/helpers/esm/asyncToGenerator';
|
|
4
3
|
import _createClass from '@babel/runtime/helpers/esm/createClass';
|
|
5
|
-
|
|
6
|
-
var AbstractSubscribableStoreQuery = /*#__PURE__*/function () {
|
|
7
|
-
function AbstractSubscribableStoreQuery() {}
|
|
8
|
-
|
|
9
|
-
var _proto = AbstractSubscribableStoreQuery.prototype;
|
|
10
|
-
|
|
11
|
-
_proto.changeParams = function changeParams() {
|
|
12
|
-
throw new Error('Method not supported. Please create a new query.');
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
_proto.changePartialParams = function changePartialParams() {
|
|
16
|
-
throw new Error('Method not supported. Please create a new query.');
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
_proto.setSubscribeStore = function setSubscribeStore(store) {
|
|
20
|
-
this._subscribeStore = store;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
_proto.getSubscribeStore = function getSubscribeStore() {
|
|
24
|
-
if (!this._subscribeStore) {
|
|
25
|
-
throw new Error('_subscribeStore is not initialized');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return this._subscribeStore;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
_proto.fetchAndSubscribe = function fetchAndSubscribe(callback) {
|
|
32
|
-
return this._subscribe(callback, true);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
_proto.subscribe = function subscribe(callback) {
|
|
36
|
-
return this._subscribe(callback, false);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
return AbstractSubscribableStoreQuery;
|
|
40
|
-
}();
|
|
4
|
+
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
41
5
|
|
|
42
6
|
/* eslint-disable max-lines */
|
|
43
7
|
var SubscribeStore = /*#__PURE__*/function () {
|
|
@@ -54,7 +18,7 @@ var SubscribeStore = /*#__PURE__*/function () {
|
|
|
54
18
|
|
|
55
19
|
this.listeners.add(callback);
|
|
56
20
|
return function () {
|
|
57
|
-
return _this.listeners
|
|
21
|
+
return _this.listeners["delete"](callback);
|
|
58
22
|
};
|
|
59
23
|
};
|
|
60
24
|
|
|
@@ -256,15 +220,15 @@ var SubscribeStore = /*#__PURE__*/function () {
|
|
|
256
220
|
|
|
257
221
|
_proto.partialUpdateByKey = /*#__PURE__*/function () {
|
|
258
222
|
var _partialUpdateByKey = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(key, partialUpdate, criteria) {
|
|
223
|
+
var _extends2;
|
|
224
|
+
|
|
259
225
|
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
260
226
|
while (1) {
|
|
261
227
|
switch (_context6.prev = _context6.next) {
|
|
262
228
|
case 0:
|
|
263
229
|
_context6.t0 = this;
|
|
264
230
|
_context6.next = 3;
|
|
265
|
-
return this.findOne(_extends({
|
|
266
|
-
[this.store.keyPath]: key
|
|
267
|
-
}, criteria));
|
|
231
|
+
return this.findOne(_extends((_extends2 = {}, _extends2[this.store.keyPath] = key, _extends2), criteria));
|
|
268
232
|
|
|
269
233
|
case 3:
|
|
270
234
|
_context6.t1 = _context6.sent;
|
|
@@ -472,27 +436,48 @@ var SubscribeStore = /*#__PURE__*/function () {
|
|
|
472
436
|
};
|
|
473
437
|
}();
|
|
474
438
|
|
|
475
|
-
_proto.
|
|
476
|
-
var
|
|
477
|
-
var cursor;
|
|
439
|
+
_proto.count = /*#__PURE__*/function () {
|
|
440
|
+
var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(criteria) {
|
|
478
441
|
return _regeneratorRuntime.wrap(function _callee13$(_context13) {
|
|
479
442
|
while (1) {
|
|
480
443
|
switch (_context13.prev = _context13.next) {
|
|
481
444
|
case 0:
|
|
482
|
-
_context13.
|
|
445
|
+
return _context13.abrupt("return", this.store.count(criteria));
|
|
446
|
+
|
|
447
|
+
case 1:
|
|
448
|
+
case "end":
|
|
449
|
+
return _context13.stop();
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}, _callee13, this);
|
|
453
|
+
}));
|
|
454
|
+
|
|
455
|
+
return function count() {
|
|
456
|
+
return _count.apply(this, arguments);
|
|
457
|
+
};
|
|
458
|
+
}();
|
|
459
|
+
|
|
460
|
+
_proto.cursor = /*#__PURE__*/function () {
|
|
461
|
+
var _cursor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(criteria, sort) {
|
|
462
|
+
var cursor;
|
|
463
|
+
return _regeneratorRuntime.wrap(function _callee14$(_context14) {
|
|
464
|
+
while (1) {
|
|
465
|
+
switch (_context14.prev = _context14.next) {
|
|
466
|
+
case 0:
|
|
467
|
+
_context14.next = 2;
|
|
483
468
|
return this.store.cursor(criteria, sort);
|
|
484
469
|
|
|
485
470
|
case 2:
|
|
486
|
-
cursor =
|
|
471
|
+
cursor = _context14.sent;
|
|
487
472
|
cursor.overrideStore(this);
|
|
488
|
-
return
|
|
473
|
+
return _context14.abrupt("return", cursor);
|
|
489
474
|
|
|
490
475
|
case 5:
|
|
491
476
|
case "end":
|
|
492
|
-
return
|
|
477
|
+
return _context14.stop();
|
|
493
478
|
}
|
|
494
479
|
}
|
|
495
|
-
},
|
|
480
|
+
}, _callee14, this);
|
|
496
481
|
}));
|
|
497
482
|
|
|
498
483
|
return function cursor() {
|
|
@@ -510,5 +495,41 @@ var SubscribeStore = /*#__PURE__*/function () {
|
|
|
510
495
|
return SubscribeStore;
|
|
511
496
|
}();
|
|
512
497
|
|
|
498
|
+
var AbstractSubscribableStoreQuery = /*#__PURE__*/function () {
|
|
499
|
+
function AbstractSubscribableStoreQuery() {}
|
|
500
|
+
|
|
501
|
+
var _proto = AbstractSubscribableStoreQuery.prototype;
|
|
502
|
+
|
|
503
|
+
_proto.changeParams = function changeParams() {
|
|
504
|
+
throw new Error('Method not supported. Please create a new query.');
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
_proto.changePartialParams = function changePartialParams() {
|
|
508
|
+
throw new Error('Method not supported. Please create a new query.');
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
_proto.setSubscribeStore = function setSubscribeStore(store) {
|
|
512
|
+
this._subscribeStore = store;
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
_proto.getSubscribeStore = function getSubscribeStore() {
|
|
516
|
+
if (!this._subscribeStore) {
|
|
517
|
+
throw new Error('_subscribeStore is not initialized');
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
return this._subscribeStore;
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
_proto.fetchAndSubscribe = function fetchAndSubscribe(callback) {
|
|
524
|
+
return this._subscribe(callback, true);
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
_proto.subscribe = function subscribe(callback) {
|
|
528
|
+
return this._subscribe(callback, false);
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
return AbstractSubscribableStoreQuery;
|
|
532
|
+
}();
|
|
533
|
+
|
|
513
534
|
export { AbstractSubscribableStoreQuery, SubscribeStore };
|
|
514
535
|
//# sourceMappingURL=index-browser.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browser.es.js","sources":["../src/AbstractSubscribableStoreQuery.ts","../src/SubscribeStore.ts"],"sourcesContent":["import type {\n Query,\n SubscribeCallback,\n QuerySubscription,\n QueryResult,\n QueryParams,\n} from 'liwi-store';\nimport type { BaseModel, InsertType, AllowedKeyValue } from 'liwi-types';\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 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","/* 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} from 'liwi-store';\nimport type {\n BaseModel,\n InsertType,\n Update,\n Criteria,\n Sort,\n QueryOptions,\n Transformer,\n AllowedKeyValue,\n OptionalBaseModelKeysForInsert,\n} from 'liwi-types';\n\nexport type Actions<Model> =\n | { type: 'inserted'; next: Model[] }\n | { type: 'updated'; changes: [Model, Model][] }\n | { type: 'deleted'; prev: 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 private readonly store: Store;\n\n private readonly listeners: Set<Listener<Model>> = new Set();\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(key: any, criteria?: Criteria<Model>): 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?: Pick<Model, K>,\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?: Pick<Model, K>,\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: any,\n partialUpdate: Update<Model>,\n criteria?: Criteria<Model>,\n ): Promise<Model> {\n return this.partialUpdateOne(\n (await this.findOne({ [this.store.keyPath]: key, ...criteria }))!,\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: any, 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 cursor<Result = 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"],"names":["AbstractSubscribableStoreQuery","changeParams","Error","changePartialParams","setSubscribeStore","store","_subscribeStore","getSubscribeStore","fetchAndSubscribe","callback","_subscribe","subscribe","SubscribeStore","listeners","Set","keyPath","add","delete","callSubscribed","action","forEach","listener","createQuerySingleItem","options","transformer","query","createQueryCollection","findAll","criteria","sort","findByKey","key","findOne","insertOne","object","inserted","type","next","replaceOne","replaced","changes","replaceSeveral","objects","replacedObjects","map","prev","index","upsertOne","setOnInsertPartialObject","upsertOneWithInfo","result","upsertedWithInfo","partialUpdateByKey","partialUpdate","partialUpdateOne","updated","partialUpdateMany","cursor","model","push","deleteByKey","deleteOne","deleteMany","toArray","overrideStore","connection"],"mappings":";;;;;IAU8BA;;;;;SAQ5BC,eAAA,wBAAoC;AAClC,UAAM,IAAIC,KAAJ,CAAU,kDAAV,CAAN;AACD;;SAEDC,sBAAA,+BAES;AACP,UAAM,IAAID,KAAJ,CAAU,kDAAV,CAAN;AACD;;SAWDE,oBAAA,2BACEC,KADF,EAEQ;AACN,SAAKC,eAAL,GAAuBD,KAAvB;AACD;;SAEDE,oBAAA,6BAOE;AACA,QAAI,CAAC,KAAKD,eAAV,EAA2B;AACzB,YAAM,IAAIJ,KAAJ,CAAU,oCAAV,CAAN;AACD;;AACD,WAAO,KAAKI,eAAZ;AACD;;SAMDE,oBAAA,2BACEC,QADF,EAEqB;AACnB,WAAO,KAAKC,UAAL,CAAgBD,QAAhB,EAA0B,IAA1B,CAAP;AACD;;SAEDE,YAAA,mBAAUF,QAAV,EAA4E;AAC1E,WAAO,KAAKC,UAAL,CAAgBD,QAAhB,EAA0B,KAA1B,CAAP;AACD;;;;;ACrEH;IA8BqBG;A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AAA;AAAA;AAAA;;;;;;;;;SA9LA,eAA6B;AAC3B,aAAO,KAAKpD,KAAL,CAAW4D,UAAlB;AACD;;;;;;;;"}
|
|
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} from 'liwi-store';\nimport type {\n BaseModel,\n InsertType,\n Update,\n Criteria,\n Sort,\n QueryOptions,\n Transformer,\n AllowedKeyValue,\n OptionalBaseModelKeysForInsert,\n} from 'liwi-types';\n\nexport type Actions<Model> =\n | { type: 'inserted'; next: Model[] }\n | { type: 'updated'; changes: [Model, Model][] }\n | { type: 'deleted'; prev: 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: Set<Listener<Model>> = new Set();\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({ [this.store.keyPath]: key, ...criteria }))!,\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 = 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} from 'liwi-store';\nimport type { BaseModel, InsertType, AllowedKeyValue } from 'liwi-types';\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","subscribe","callback","add","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","upsertOneWithInfo","result","upsertedWithInfo","Error","partialUpdateByKey","partialUpdate","partialUpdateOne","updated","partialUpdateMany","cursor","model","push","deleteByKey","deleteOne","deleteMany","toArray","count","overrideStore","connection","AbstractSubscribableStoreQuery","changeParams","changePartialParams","_subscribeStore","getSubscribeStore","fetchAndSubscribe","_subscribe"],"mappings":";;;;;AAAA;IA8BqBA;AAsBnB,0BAAYC,KAAZ,EAA0B;AAAA,SAJTC,SAIS,GAJyB,IAAIC,GAAJ,EAIzB;AACxB,SAAKF,KAAL,GAAaA,KAAb;AACA,SAAKG,OAAL,GAAeH,KAAK,CAACG,OAArB;AACD;;;;SAMDC,YAAA,mBAAUC,QAAV,EAAiD;AAAA;;AAC/C,SAAKJ,SAAL,CAAeK,GAAf,CAAmBD,QAAnB;AACA,WAAO;AAAA,aAAM,KAAI,CAACJ,SAAL,WAAsBI,QAAtB,CAAN;AAAA,KAAP;AACD;;SAEDE,iBAAA,wBAAeC,MAAf,EAA6C;AAC3C,SAAKP,SAAL,CAAeQ,OAAf,CAAuB,UAACC,QAAD;AAAA,aAAcA,QAAQ,CAACF,MAAD,CAAtB;AAAA,KAAvB;AACD;;SAEDG,wBAAA,+BAIEC,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