liwi-subscribe-store 12.0.0 → 13.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/definitions/AbstractSubscribableStoreQuery.d.ts +2 -2
- package/dist/definitions/AbstractSubscribableStoreQuery.d.ts.map +1 -1
- package/dist/definitions/SubscribeStore.d.ts +8 -8
- package/dist/definitions/SubscribeStore.d.ts.map +1 -1
- package/dist/definitions/index.d.ts +3 -3
- package/dist/index-browser.es.js +44 -50
- package/dist/index-browser.es.js.map +1 -1
- package/dist/{index-node18.mjs → index-node.mjs} +45 -51
- package/dist/index-node.mjs.map +1 -0
- package/package.json +40 -37
- package/src/AbstractSubscribableStoreQuery.ts +12 -14
- package/src/SubscribeStore.ts +39 -39
- package/src/index.ts +3 -3
- package/CHANGELOG.md +0 -489
- package/dist/index-node18.mjs.map +0 -1
- package/src/.eslintrc.json +0 -38
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
<
|
|
1
|
+
<h1 align="center">
|
|
2
2
|
liwi-subscribe-store
|
|
3
|
-
</
|
|
3
|
+
</h1>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
subscribe store proxy
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
|
-
<a href="https://npmjs.org/package/liwi-subscribe-store"><img src="https://img.shields.io/npm/v/liwi-subscribe-store.svg?style=flat-square"></a>
|
|
11
|
-
<a href="https://npmjs.org/package/liwi-subscribe-store"><img src="https://img.shields.io/npm/dw/liwi-subscribe-store.svg?style=flat-square"></a>
|
|
12
|
-
<a href="https://npmjs.org/package/liwi-subscribe-store"><img src="https://img.shields.io/node/v/liwi-subscribe-store.svg?style=flat-square"></a>
|
|
13
|
-
<a href="https://npmjs.org/package/liwi-subscribe-store"><img src="https://img.shields.io/npm/types/liwi-subscribe-store.svg?style=flat-square"></a>
|
|
10
|
+
<a href="https://npmjs.org/package/liwi-subscribe-store"><img src="https://img.shields.io/npm/v/liwi-subscribe-store.svg?style=flat-square" alt="npm version"></a>
|
|
11
|
+
<a href="https://npmjs.org/package/liwi-subscribe-store"><img src="https://img.shields.io/npm/dw/liwi-subscribe-store.svg?style=flat-square" alt="npm downloads"></a>
|
|
12
|
+
<a href="https://npmjs.org/package/liwi-subscribe-store"><img src="https://img.shields.io/node/v/liwi-subscribe-store.svg?style=flat-square" alt="node version"></a>
|
|
13
|
+
<a href="https://npmjs.org/package/liwi-subscribe-store"><img src="https://img.shields.io/npm/types/liwi-subscribe-store.svg?style=flat-square" alt="types"></a>
|
|
14
14
|
</p>
|
|
15
15
|
|
|
16
16
|
## Install
|
|
@@ -22,7 +22,7 @@ npm install --save liwi-subscribe-store
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
24
|
```js
|
|
25
|
-
import liwiStore from
|
|
25
|
+
import liwiStore from "liwi-subscribe-store";
|
|
26
26
|
|
|
27
27
|
console.log(liwiStore);
|
|
28
28
|
```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type SubscribeStore from
|
|
1
|
+
import type { AllowedKeyValue, BaseModel, InsertType, Query, QueryParams, QueryResult, QuerySubscription, SubscribeCallback } from "liwi-store";
|
|
2
|
+
import type SubscribeStore from "./SubscribeStore";
|
|
3
3
|
export default abstract class AbstractSubscribableStoreQuery<KeyPath extends keyof Model, KeyValue extends AllowedKeyValue, Model extends BaseModel & Record<KeyPath, KeyValue>, ModelInsertType extends InsertType<Model, KeyPath>, Params extends QueryParams<Params> = never, Result = Model> implements Query<Result, Params, KeyValue> {
|
|
4
4
|
changeParams(params: Params): never;
|
|
5
5
|
changePartialParams(params: Params extends undefined ? never : Partial<Params>): never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractSubscribableStoreQuery.d.ts","sourceRoot":"","sources":["../../src/AbstractSubscribableStoreQuery.ts"],"names":[],"mappings":"
|
|
1
|
+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,EAAE,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,GAC5C,iBAAiB;IAIpB,SAAS,CAAC,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,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AbstractConnection, AbstractStoreCursor, AllowedKeyValue, BaseModel, CreateQueryOptions, Criteria, InsertType, OptionalBaseModelKeysForInsert, QueryParams, Sort, Store as StoreInterface, SubscribableStore, SubscribableStoreQuery, Update, UpsertPartialObject, UpsertResult } from "liwi-store";
|
|
2
2
|
export type Actions<Model> = {
|
|
3
|
-
type:
|
|
3
|
+
type: "deleted";
|
|
4
4
|
prev: Model[];
|
|
5
5
|
} | {
|
|
6
|
-
type:
|
|
6
|
+
type: "inserted";
|
|
7
7
|
next: Model[];
|
|
8
8
|
} | {
|
|
9
|
-
type:
|
|
9
|
+
type: "updated";
|
|
10
10
|
changes: [Model, Model][];
|
|
11
11
|
};
|
|
12
12
|
export type Listener<Model> = (action: Actions<Model>) => unknown;
|
|
@@ -18,16 +18,16 @@ export default class SubscribeStore<KeyPath extends keyof Model, KeyValue extend
|
|
|
18
18
|
get connection(): Connection;
|
|
19
19
|
subscribe(callback: Listener<Model>): () => void;
|
|
20
20
|
callSubscribed(action: Actions<Model>): void;
|
|
21
|
-
createQuerySingleItem<Result extends Record<KeyPath, KeyValue>, Params extends QueryParams<Params>>(options:
|
|
22
|
-
createQueryCollection<Item extends Record<KeyPath, KeyValue>, Params extends QueryParams<Params>>(options:
|
|
21
|
+
createQuerySingleItem<Result extends Record<KeyPath, KeyValue>, Params extends QueryParams<Params>>(options: CreateQueryOptions<Model, Result>): SubscribableStoreQuery<KeyPath, KeyValue, Model, SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>, Result, Params>;
|
|
22
|
+
createQueryCollection<Item extends Record<KeyPath, KeyValue>, Params extends QueryParams<Params>>(options: CreateQueryOptions<Model, Item>): SubscribableStoreQuery<KeyPath, KeyValue, Model, SubscribableStore<KeyPath, KeyValue, Model, ModelInsertType, Connection>, Item[], Params>;
|
|
23
23
|
findAll(criteria?: Criteria<Model>, sort?: Sort<Model>): Promise<Model[]>;
|
|
24
24
|
findByKey(key: KeyValue, criteria?: Criteria<Model>): Promise<Model | undefined>;
|
|
25
25
|
findOne(criteria: Criteria<Model>, sort?: Sort<Model>): Promise<Model | undefined>;
|
|
26
26
|
insertOne(object: ModelInsertType): Promise<Model>;
|
|
27
27
|
replaceOne(object: Model): Promise<Model>;
|
|
28
28
|
replaceSeveral(objects: Model[]): Promise<Model[]>;
|
|
29
|
-
upsertOne<K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>>(object: UpsertPartialObject<KeyPath, KeyValue, Model, K>, setOnInsertPartialObject?: Update<Model>[
|
|
30
|
-
upsertOneWithInfo<K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>>(object: UpsertPartialObject<KeyPath, KeyValue, Model, K>, setOnInsertPartialObject?: Update<Model>[
|
|
29
|
+
upsertOne<K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>>(object: UpsertPartialObject<KeyPath, KeyValue, Model, K>, setOnInsertPartialObject?: Update<Model>["$setOnInsert"]): Promise<Model>;
|
|
30
|
+
upsertOneWithInfo<K extends Exclude<keyof Model, KeyPath | OptionalBaseModelKeysForInsert>>(object: UpsertPartialObject<KeyPath, KeyValue, Model, K>, setOnInsertPartialObject?: Update<Model>["$setOnInsert"]): Promise<UpsertResult<Model>>;
|
|
31
31
|
partialUpdateByKey(key: KeyValue, partialUpdate: Update<Model>, criteria?: Criteria<Model>): Promise<Model>;
|
|
32
32
|
partialUpdateOne(object: Model, partialUpdate: Update<Model>): Promise<Model>;
|
|
33
33
|
partialUpdateMany(criteria: Criteria<Model>, partialUpdate: Update<Model>): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscribeStore.d.ts","sourceRoot":"","sources":["../../src/SubscribeStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SubscribeStore.d.ts","sourceRoot":"","sources":["../../src/SubscribeStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,SAAS,EACT,kBAAkB,EAClB,QAAQ,EACR,UAAU,EACV,8BAA8B,EAC9B,WAAW,EACX,IAAI,EACJ,KAAK,IAAI,cAAc,EACvB,iBAAiB,EACjB,sBAAsB,EACtB,MAAM,EACN,mBAAmB,EACnB,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,OAAO,CAAC,KAAK,IACrB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,KAAK,EAAE,CAAA;CAAE,GAClC;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,CAAC;AAEnD,MAAM,MAAM,QAAQ,CAAC,KAAK,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC;AAElE,MAAM,CAAC,OAAO,OAAO,cAAc,CACjC,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,UAAU,SAAS,kBAAkB,EACrC,KAAK,SAAS,iBAAiB,CAC7B,OAAO,EACP,QAAQ,EACR,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UX,gBAAgB,CACpB,MAAM,EAAE,KAAK,EACb,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,GAC3B,OAAO,CAAC,KAAK,CAAC;IAMX,iBAAiB,CACrB,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,EACzB,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,GAC3B,OAAO,CAAC,IAAI,CAAC;IAgBV,WAAW,CAAC,GAAG,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrE,SAAS,CAAC,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAKvC,UAAU,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAOpD,KAAK,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlD,MAAM,CAAC,MAAM,SAAS,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,EAChD,QAAQ,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,EAC1B,IAAI,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GACjB,OAAO,CAAC,mBAAmB,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;CAK9D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { Actions, Listener } from
|
|
2
|
-
export { default as SubscribeStore } from
|
|
3
|
-
export { default as AbstractSubscribableStoreQuery } from
|
|
1
|
+
export type { Actions, Listener } from "./SubscribeStore";
|
|
2
|
+
export { default as SubscribeStore } from "./SubscribeStore";
|
|
3
|
+
export { default as AbstractSubscribableStoreQuery } from "./AbstractSubscribableStoreQuery";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index-browser.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/* eslint-disable max-lines */
|
|
2
|
-
|
|
3
1
|
class SubscribeStore {
|
|
2
|
+
store;
|
|
3
|
+
listeners = /* @__PURE__ */ new Set();
|
|
4
|
+
keyPath;
|
|
4
5
|
constructor(store) {
|
|
5
|
-
this.listeners = new Set();
|
|
6
6
|
this.store = store;
|
|
7
7
|
this.keyPath = store.keyPath;
|
|
8
8
|
}
|
|
@@ -14,15 +14,15 @@ class SubscribeStore {
|
|
|
14
14
|
return () => this.listeners.delete(callback);
|
|
15
15
|
}
|
|
16
16
|
callSubscribed(action) {
|
|
17
|
-
this.listeners.forEach(listener => listener(action));
|
|
17
|
+
this.listeners.forEach((listener) => listener(action));
|
|
18
18
|
}
|
|
19
|
-
createQuerySingleItem(options
|
|
20
|
-
const query = this.store.createQuerySingleItem(options
|
|
19
|
+
createQuerySingleItem(options) {
|
|
20
|
+
const query = this.store.createQuerySingleItem(options);
|
|
21
21
|
query.setSubscribeStore(this);
|
|
22
22
|
return query;
|
|
23
23
|
}
|
|
24
|
-
createQueryCollection(options
|
|
25
|
-
const query = this.store.createQueryCollection(options
|
|
24
|
+
createQueryCollection(options) {
|
|
25
|
+
const query = this.store.createQueryCollection(options);
|
|
26
26
|
query.setSubscribeStore(this);
|
|
27
27
|
return query;
|
|
28
28
|
}
|
|
@@ -37,89 +37,84 @@ class SubscribeStore {
|
|
|
37
37
|
}
|
|
38
38
|
async insertOne(object) {
|
|
39
39
|
const inserted = await this.store.insertOne(object);
|
|
40
|
-
this.callSubscribed({
|
|
41
|
-
type: 'inserted',
|
|
42
|
-
next: [inserted]
|
|
43
|
-
});
|
|
40
|
+
this.callSubscribed({ type: "inserted", next: [inserted] });
|
|
44
41
|
return inserted;
|
|
45
42
|
}
|
|
46
43
|
async replaceOne(object) {
|
|
47
44
|
const replaced = await this.store.replaceOne(object);
|
|
48
|
-
this.callSubscribed({
|
|
49
|
-
type: 'updated',
|
|
50
|
-
changes: [[object, replaced]]
|
|
51
|
-
});
|
|
45
|
+
this.callSubscribed({ type: "updated", changes: [[object, replaced]] });
|
|
52
46
|
return replaced;
|
|
53
47
|
}
|
|
54
48
|
async replaceSeveral(objects) {
|
|
55
49
|
const replacedObjects = await this.store.replaceSeveral(objects);
|
|
56
50
|
this.callSubscribed({
|
|
57
|
-
type:
|
|
51
|
+
type: "updated",
|
|
58
52
|
changes: objects.map((prev, index) => [prev, replacedObjects[index]])
|
|
59
53
|
});
|
|
60
54
|
return replacedObjects;
|
|
61
55
|
}
|
|
62
56
|
async upsertOne(object, setOnInsertPartialObject) {
|
|
63
|
-
const result = await this.upsertOneWithInfo(
|
|
57
|
+
const result = await this.upsertOneWithInfo(
|
|
58
|
+
object,
|
|
59
|
+
setOnInsertPartialObject
|
|
60
|
+
);
|
|
64
61
|
return result.object;
|
|
65
62
|
}
|
|
66
63
|
async upsertOneWithInfo(object, setOnInsertPartialObject) {
|
|
67
|
-
const upsertedWithInfo = await this.store.upsertOneWithInfo(
|
|
64
|
+
const upsertedWithInfo = await this.store.upsertOneWithInfo(
|
|
65
|
+
object,
|
|
66
|
+
setOnInsertPartialObject
|
|
67
|
+
);
|
|
68
68
|
if (upsertedWithInfo.inserted) {
|
|
69
69
|
this.callSubscribed({
|
|
70
|
-
type:
|
|
70
|
+
type: "inserted",
|
|
71
71
|
next: [upsertedWithInfo.object]
|
|
72
72
|
});
|
|
73
73
|
} else {
|
|
74
|
-
throw new Error(
|
|
74
|
+
throw new Error("TODO");
|
|
75
75
|
}
|
|
76
76
|
return upsertedWithInfo;
|
|
77
77
|
}
|
|
78
78
|
async partialUpdateByKey(key, partialUpdate, criteria) {
|
|
79
|
-
return this.partialUpdateOne(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
return this.partialUpdateOne(
|
|
80
|
+
await this.findOne({
|
|
81
|
+
[this.store.keyPath]: key,
|
|
82
|
+
...criteria
|
|
83
|
+
}),
|
|
84
|
+
partialUpdate
|
|
85
|
+
);
|
|
83
86
|
}
|
|
84
87
|
async partialUpdateOne(object, partialUpdate) {
|
|
85
88
|
const updated = await this.store.partialUpdateOne(object, partialUpdate);
|
|
86
|
-
this.callSubscribed({
|
|
87
|
-
type: 'updated',
|
|
88
|
-
changes: [[object, updated]]
|
|
89
|
-
});
|
|
89
|
+
this.callSubscribed({ type: "updated", changes: [[object, updated]] });
|
|
90
90
|
return updated;
|
|
91
91
|
}
|
|
92
92
|
async partialUpdateMany(criteria, partialUpdate) {
|
|
93
93
|
const cursor = await this.store.cursor(criteria);
|
|
94
94
|
const changes = [];
|
|
95
|
-
await cursor.forEach(async model => {
|
|
95
|
+
await cursor.forEach(async (model) => {
|
|
96
96
|
const key = model[this.store.keyPath];
|
|
97
|
-
const updated = await this.store.partialUpdateByKey(
|
|
97
|
+
const updated = await this.store.partialUpdateByKey(
|
|
98
|
+
key,
|
|
99
|
+
partialUpdate,
|
|
100
|
+
criteria
|
|
101
|
+
);
|
|
98
102
|
changes.push([model, updated]);
|
|
99
103
|
});
|
|
100
|
-
this.callSubscribed({
|
|
101
|
-
type: 'updated',
|
|
102
|
-
changes
|
|
103
|
-
});
|
|
104
|
+
this.callSubscribed({ type: "updated", changes });
|
|
104
105
|
}
|
|
105
106
|
async deleteByKey(key, criteria) {
|
|
106
107
|
return this.deleteOne(await this.findByKey(key, criteria));
|
|
107
108
|
}
|
|
108
109
|
async deleteOne(object) {
|
|
109
110
|
await this.store.deleteOne(object);
|
|
110
|
-
this.callSubscribed({
|
|
111
|
-
type: 'deleted',
|
|
112
|
-
prev: [object]
|
|
113
|
-
});
|
|
111
|
+
this.callSubscribed({ type: "deleted", prev: [object] });
|
|
114
112
|
}
|
|
115
113
|
async deleteMany(criteria) {
|
|
116
114
|
const cursor = await this.store.cursor(criteria);
|
|
117
115
|
const prev = await cursor.toArray();
|
|
118
116
|
await this.store.deleteMany(criteria);
|
|
119
|
-
this.callSubscribed({
|
|
120
|
-
type: 'deleted',
|
|
121
|
-
prev
|
|
122
|
-
});
|
|
117
|
+
this.callSubscribed({ type: "deleted", prev });
|
|
123
118
|
}
|
|
124
119
|
async count(criteria) {
|
|
125
120
|
return this.store.count(criteria);
|
|
@@ -131,21 +126,20 @@ class SubscribeStore {
|
|
|
131
126
|
}
|
|
132
127
|
}
|
|
133
128
|
|
|
134
|
-
/* eslint-disable @typescript-eslint/class-methods-use-this */
|
|
135
|
-
|
|
136
129
|
class AbstractSubscribableStoreQuery {
|
|
137
|
-
changeParams() {
|
|
138
|
-
throw new Error(
|
|
130
|
+
changeParams(params) {
|
|
131
|
+
throw new Error("Method not supported. Please create a new query.");
|
|
139
132
|
}
|
|
140
|
-
changePartialParams() {
|
|
141
|
-
throw new Error(
|
|
133
|
+
changePartialParams(params) {
|
|
134
|
+
throw new Error("Method not supported. Please create a new query.");
|
|
142
135
|
}
|
|
136
|
+
_subscribeStore;
|
|
143
137
|
setSubscribeStore(store) {
|
|
144
138
|
this._subscribeStore = store;
|
|
145
139
|
}
|
|
146
140
|
getSubscribeStore() {
|
|
147
141
|
if (!this._subscribeStore) {
|
|
148
|
-
throw new Error(
|
|
142
|
+
throw new Error("_subscribeStore is not initialized");
|
|
149
143
|
}
|
|
150
144
|
return this._subscribeStore;
|
|
151
145
|
}
|
|
@@ -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","/* 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;IAC3C,IAAI,CAACT,SAAS,CAACU,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,CAAChB,KAAK,CAACa,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,CAInBJ,OAA4B,EAC5BC,WAAsC,EAQtC;IACA,MAAMC,KAOL,GAAG,IAAI,CAAChB,KAAK,CAACkB,qBAAqB,CAAeJ,OAA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MAAM,CAAA;AACf,GAAA;AACF;;ACvQA;;AAae,MAAeS,8BAA8B,CAQ5D;AACEC,EAAAA,YAAYA,GAAwB;AAClC,IAAA,MAAM,IAAIhB,KAAK,CAAC,kDAAkD,CAAC,CAAA;AACrE,GAAA;AAEAiB,EAAAA,mBAAmBA,GAEV;AACP,IAAA,MAAM,IAAIjB,KAAK,CAAC,kDAAkD,CAAC,CAAA;AACrE,GAAA;EAWA3B,iBAAiBA,CACfjB,KAA0E,EACpE;IACN,IAAI,CAAC8D,eAAe,GAAG9D,KAAK,CAAA;AAC9B,GAAA;AAEA+D,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;;;;"}
|
|
1
|
+
{"version":3,"file":"index-browser.es.js","sources":["../src/SubscribeStore.ts","../src/AbstractSubscribableStoreQuery.ts"],"sourcesContent":["import type {\n AbstractConnection,\n AbstractStoreCursor,\n AllowedKeyValue,\n BaseModel,\n CreateQueryOptions,\n Criteria,\n InsertType,\n OptionalBaseModelKeysForInsert,\n QueryParams,\n Sort,\n Store as StoreInterface,\n SubscribableStore,\n SubscribableStoreQuery,\n Update,\n UpsertPartialObject,\n UpsertResult,\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 StoreInterface<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n 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: CreateQueryOptions<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);\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: CreateQueryOptions<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);\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 }))!,\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 AllowedKeyValue,\n BaseModel,\n InsertType,\n Query,\n QueryParams,\n QueryResult,\n QuerySubscription,\n SubscribeCallback,\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 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":[],"mappings":"AA0BA,MAAqB,cAAA,CAmBnB;AAAA,EACiB,KAAA;AAAA,EAEA,SAAA,uBAAgB,GAAA,EAAqB;AAAA,EAE7C,OAAA;AAAA,EAET,YAAY,KAAA,EAAc;AACxB,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AACb,IAAA,IAAA,CAAK,UAAU,KAAA,CAAM,OAAA;AAAA,EACvB;AAAA,EAEA,I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CAAA;AACzB,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;AC3PA,MAA8B,8BAAA,CAOe;AAAA,EAC3C,aAAa,MAAA,EAAuB;AAClC,IAAA,MAAM,IAAI,MAAM,kDAAkD,CAAA;AAAA,EACpE;AAAA,EAEA,oBACE,MAAA,EACO;AACP,IAAA,MAAM,IAAI,MAAM,kDAAkD,CAAA;AAAA,EACpE;AAAA,EAEQ,eAAA;AAAA,EASR,kBACE,KAAA,EACM;AACN,IAAA,IAAA,CAAK,eAAA,GAAkB,KAAA;AAAA,EACzB;AAAA,EAEA,iBAAA,GAOE;AACA,IAAA,IAAI,CAAC,KAAK,eAAA,EAAiB;AACzB,MAAA,MAAM,IAAI,MAAM,oCAAoC,CAAA;AAAA,IACtD;AACA,IAAA,OAAO,IAAA,CAAK,eAAA;AAAA,EACd;AAAA,EAMA,kBACE,QAAA,EACmB;AACnB,IAAA,OAAO,IAAA,CAAK,UAAA,CAAW,QAAA,EAAU,IAAI,CAAA;AAAA,EACvC;AAAA,EAEA,UAAU,QAAA,EAAkE;AAC1E,IAAA,OAAO,IAAA,CAAK,UAAA,CAAW,QAAA,EAAU,KAAK,CAAA;AAAA,EACxC;AAMF;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/* eslint-disable max-lines */
|
|
2
|
-
|
|
3
1
|
class SubscribeStore {
|
|
4
|
-
|
|
2
|
+
store;
|
|
3
|
+
listeners = /* @__PURE__ */ new Set();
|
|
4
|
+
keyPath;
|
|
5
5
|
constructor(store) {
|
|
6
6
|
this.store = store;
|
|
7
7
|
this.keyPath = store.keyPath;
|
|
@@ -14,15 +14,15 @@ class SubscribeStore {
|
|
|
14
14
|
return () => this.listeners.delete(callback);
|
|
15
15
|
}
|
|
16
16
|
callSubscribed(action) {
|
|
17
|
-
this.listeners.forEach(listener => listener(action));
|
|
17
|
+
this.listeners.forEach((listener) => listener(action));
|
|
18
18
|
}
|
|
19
|
-
createQuerySingleItem(options
|
|
20
|
-
const query = this.store.createQuerySingleItem(options
|
|
19
|
+
createQuerySingleItem(options) {
|
|
20
|
+
const query = this.store.createQuerySingleItem(options);
|
|
21
21
|
query.setSubscribeStore(this);
|
|
22
22
|
return query;
|
|
23
23
|
}
|
|
24
|
-
createQueryCollection(options
|
|
25
|
-
const query = this.store.createQueryCollection(options
|
|
24
|
+
createQueryCollection(options) {
|
|
25
|
+
const query = this.store.createQueryCollection(options);
|
|
26
26
|
query.setSubscribeStore(this);
|
|
27
27
|
return query;
|
|
28
28
|
}
|
|
@@ -37,89 +37,84 @@ class SubscribeStore {
|
|
|
37
37
|
}
|
|
38
38
|
async insertOne(object) {
|
|
39
39
|
const inserted = await this.store.insertOne(object);
|
|
40
|
-
this.callSubscribed({
|
|
41
|
-
type: 'inserted',
|
|
42
|
-
next: [inserted]
|
|
43
|
-
});
|
|
40
|
+
this.callSubscribed({ type: "inserted", next: [inserted] });
|
|
44
41
|
return inserted;
|
|
45
42
|
}
|
|
46
43
|
async replaceOne(object) {
|
|
47
44
|
const replaced = await this.store.replaceOne(object);
|
|
48
|
-
this.callSubscribed({
|
|
49
|
-
type: 'updated',
|
|
50
|
-
changes: [[object, replaced]]
|
|
51
|
-
});
|
|
45
|
+
this.callSubscribed({ type: "updated", changes: [[object, replaced]] });
|
|
52
46
|
return replaced;
|
|
53
47
|
}
|
|
54
48
|
async replaceSeveral(objects) {
|
|
55
49
|
const replacedObjects = await this.store.replaceSeveral(objects);
|
|
56
50
|
this.callSubscribed({
|
|
57
|
-
type:
|
|
51
|
+
type: "updated",
|
|
58
52
|
changes: objects.map((prev, index) => [prev, replacedObjects[index]])
|
|
59
53
|
});
|
|
60
54
|
return replacedObjects;
|
|
61
55
|
}
|
|
62
56
|
async upsertOne(object, setOnInsertPartialObject) {
|
|
63
|
-
const result = await this.upsertOneWithInfo(
|
|
57
|
+
const result = await this.upsertOneWithInfo(
|
|
58
|
+
object,
|
|
59
|
+
setOnInsertPartialObject
|
|
60
|
+
);
|
|
64
61
|
return result.object;
|
|
65
62
|
}
|
|
66
63
|
async upsertOneWithInfo(object, setOnInsertPartialObject) {
|
|
67
|
-
const upsertedWithInfo = await this.store.upsertOneWithInfo(
|
|
64
|
+
const upsertedWithInfo = await this.store.upsertOneWithInfo(
|
|
65
|
+
object,
|
|
66
|
+
setOnInsertPartialObject
|
|
67
|
+
);
|
|
68
68
|
if (upsertedWithInfo.inserted) {
|
|
69
69
|
this.callSubscribed({
|
|
70
|
-
type:
|
|
70
|
+
type: "inserted",
|
|
71
71
|
next: [upsertedWithInfo.object]
|
|
72
72
|
});
|
|
73
73
|
} else {
|
|
74
|
-
throw new Error(
|
|
74
|
+
throw new Error("TODO");
|
|
75
75
|
}
|
|
76
76
|
return upsertedWithInfo;
|
|
77
77
|
}
|
|
78
78
|
async partialUpdateByKey(key, partialUpdate, criteria) {
|
|
79
|
-
return this.partialUpdateOne(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
return this.partialUpdateOne(
|
|
80
|
+
await this.findOne({
|
|
81
|
+
[this.store.keyPath]: key,
|
|
82
|
+
...criteria
|
|
83
|
+
}),
|
|
84
|
+
partialUpdate
|
|
85
|
+
);
|
|
83
86
|
}
|
|
84
87
|
async partialUpdateOne(object, partialUpdate) {
|
|
85
88
|
const updated = await this.store.partialUpdateOne(object, partialUpdate);
|
|
86
|
-
this.callSubscribed({
|
|
87
|
-
type: 'updated',
|
|
88
|
-
changes: [[object, updated]]
|
|
89
|
-
});
|
|
89
|
+
this.callSubscribed({ type: "updated", changes: [[object, updated]] });
|
|
90
90
|
return updated;
|
|
91
91
|
}
|
|
92
92
|
async partialUpdateMany(criteria, partialUpdate) {
|
|
93
93
|
const cursor = await this.store.cursor(criteria);
|
|
94
94
|
const changes = [];
|
|
95
|
-
await cursor.forEach(async model => {
|
|
95
|
+
await cursor.forEach(async (model) => {
|
|
96
96
|
const key = model[this.store.keyPath];
|
|
97
|
-
const updated = await this.store.partialUpdateByKey(
|
|
97
|
+
const updated = await this.store.partialUpdateByKey(
|
|
98
|
+
key,
|
|
99
|
+
partialUpdate,
|
|
100
|
+
criteria
|
|
101
|
+
);
|
|
98
102
|
changes.push([model, updated]);
|
|
99
103
|
});
|
|
100
|
-
this.callSubscribed({
|
|
101
|
-
type: 'updated',
|
|
102
|
-
changes
|
|
103
|
-
});
|
|
104
|
+
this.callSubscribed({ type: "updated", changes });
|
|
104
105
|
}
|
|
105
106
|
async deleteByKey(key, criteria) {
|
|
106
107
|
return this.deleteOne(await this.findByKey(key, criteria));
|
|
107
108
|
}
|
|
108
109
|
async deleteOne(object) {
|
|
109
110
|
await this.store.deleteOne(object);
|
|
110
|
-
this.callSubscribed({
|
|
111
|
-
type: 'deleted',
|
|
112
|
-
prev: [object]
|
|
113
|
-
});
|
|
111
|
+
this.callSubscribed({ type: "deleted", prev: [object] });
|
|
114
112
|
}
|
|
115
113
|
async deleteMany(criteria) {
|
|
116
114
|
const cursor = await this.store.cursor(criteria);
|
|
117
115
|
const prev = await cursor.toArray();
|
|
118
116
|
await this.store.deleteMany(criteria);
|
|
119
|
-
this.callSubscribed({
|
|
120
|
-
type: 'deleted',
|
|
121
|
-
prev
|
|
122
|
-
});
|
|
117
|
+
this.callSubscribed({ type: "deleted", prev });
|
|
123
118
|
}
|
|
124
119
|
async count(criteria) {
|
|
125
120
|
return this.store.count(criteria);
|
|
@@ -131,21 +126,20 @@ class SubscribeStore {
|
|
|
131
126
|
}
|
|
132
127
|
}
|
|
133
128
|
|
|
134
|
-
/* eslint-disable @typescript-eslint/class-methods-use-this */
|
|
135
|
-
|
|
136
129
|
class AbstractSubscribableStoreQuery {
|
|
137
|
-
changeParams() {
|
|
138
|
-
throw new Error(
|
|
130
|
+
changeParams(params) {
|
|
131
|
+
throw new Error("Method not supported. Please create a new query.");
|
|
139
132
|
}
|
|
140
|
-
changePartialParams() {
|
|
141
|
-
throw new Error(
|
|
133
|
+
changePartialParams(params) {
|
|
134
|
+
throw new Error("Method not supported. Please create a new query.");
|
|
142
135
|
}
|
|
136
|
+
_subscribeStore;
|
|
143
137
|
setSubscribeStore(store) {
|
|
144
138
|
this._subscribeStore = store;
|
|
145
139
|
}
|
|
146
140
|
getSubscribeStore() {
|
|
147
141
|
if (!this._subscribeStore) {
|
|
148
|
-
throw new Error(
|
|
142
|
+
throw new Error("_subscribeStore is not initialized");
|
|
149
143
|
}
|
|
150
144
|
return this._subscribeStore;
|
|
151
145
|
}
|
|
@@ -158,4 +152,4 @@ class AbstractSubscribableStoreQuery {
|
|
|
158
152
|
}
|
|
159
153
|
|
|
160
154
|
export { AbstractSubscribableStoreQuery, SubscribeStore };
|
|
161
|
-
//# sourceMappingURL=index-
|
|
155
|
+
//# sourceMappingURL=index-node.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-node.mjs","sources":["../src/SubscribeStore.ts","../src/AbstractSubscribableStoreQuery.ts"],"sourcesContent":["import type {\n AbstractConnection,\n AbstractStoreCursor,\n AllowedKeyValue,\n BaseModel,\n CreateQueryOptions,\n Criteria,\n InsertType,\n OptionalBaseModelKeysForInsert,\n QueryParams,\n Sort,\n Store as StoreInterface,\n SubscribableStore,\n SubscribableStoreQuery,\n Update,\n UpsertPartialObject,\n UpsertResult,\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 StoreInterface<\n KeyPath,\n KeyValue,\n Model,\n ModelInsertType,\n 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: CreateQueryOptions<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);\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: CreateQueryOptions<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);\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 }))!,\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 AllowedKeyValue,\n BaseModel,\n InsertType,\n Query,\n QueryParams,\n QueryResult,\n QuerySubscription,\n SubscribeCallback,\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 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":[],"mappings":"AA0BA,MAAqB,cAAA,CAmBnB;AAAA,EACiB,KAAA;AAAA,EAEA,SAAA,uBAAgB,GAAA,EAAqB;AAAA,EAE7C,OAAA;AAAA,EAET,YAAY,KAAA,EAAc;AACxB,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AACb,IAAA,IAAA,CAAK,UAAU,KAAA,CAAM,OAAA;AAAA,EACvB;AAAA,EAEA,IAAI,UAAA,GAAyB;AAC3B,IAAA,OAAO,KAAK,KAAA,CAAM,UAAA;AAAA,EACpB;AAAA,EAEA,UAAU,QAAA,EAAuC;AAC/C,IAAA,IAAA,CAAK,SAAA,CAAU,IAAI,QAAQ,CAAA;AAC3B,IAAA,OAAO,MAAM,IAAA,CAAK,SAAA,CAAU,MAAA,CAAO,QAAQ,CAAA;AAAA,EAC7C;AAAA,EAEA,eAAe,MAAA,EAA8B;AAC3C,IAAA,IAAA,CAAK,UAAU,OAAA,CAAQ,CAAC,QAAA,KAAa,QAAA,CAAS,MAAM,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