liwi-mongo 9.2.0 → 10.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/dist/definitions/MongoBaseModel.d.ts +7 -0
- package/dist/definitions/MongoBaseModel.d.ts.map +1 -0
- package/dist/{MongoConnection.d.ts → definitions/MongoConnection.d.ts} +0 -0
- package/dist/definitions/MongoConnection.d.ts.map +1 -0
- package/dist/{MongoCursor.d.ts → definitions/MongoCursor.d.ts} +0 -0
- package/dist/definitions/MongoCursor.d.ts.map +1 -0
- package/dist/{MongoQueryCollection.d.ts → definitions/MongoQueryCollection.d.ts} +1 -1
- package/dist/definitions/MongoQueryCollection.d.ts.map +1 -0
- package/dist/{MongoQuerySingleItem.d.ts → definitions/MongoQuerySingleItem.d.ts} +1 -1
- package/dist/definitions/MongoQuerySingleItem.d.ts.map +1 -0
- package/dist/{MongoStore.d.ts → definitions/MongoStore.d.ts} +0 -0
- package/dist/definitions/MongoStore.d.ts.map +1 -0
- package/dist/{createMongoSubscribeStore.d.ts → definitions/createMongoSubscribeStore.d.ts} +0 -0
- package/dist/definitions/createMongoSubscribeStore.d.ts.map +1 -0
- package/dist/{index.d.ts → definitions/index.d.ts} +0 -0
- package/dist/definitions/index.d.ts.map +1 -0
- package/dist/{index-node14.mjs → index-node16.mjs} +13 -111
- package/dist/index-node16.mjs.map +1 -0
- package/package.json +16 -21
- package/src/.eslintrc.json +1 -1
- package/src/MongoQueryCollection.ts +1 -1
- package/dist/MongoBaseModel.d.ts +0 -7
- package/dist/MongoBaseModel.d.ts.map +0 -1
- package/dist/MongoConnection.d.ts.map +0 -1
- package/dist/MongoCursor.d.ts.map +0 -1
- package/dist/MongoQueryCollection.d.ts.map +0 -1
- package/dist/MongoQuerySingleItem.d.ts.map +0 -1
- package/dist/MongoStore.d.ts.map +0 -1
- package/dist/createMongoSubscribeStore.d.ts.map +0 -1
- package/dist/index-node14.cjs +0 -683
- package/dist/index-node14.cjs.map +0 -1
- package/dist/index-node14.mjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
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
|
+
## [10.1.1](https://github.com/liwijs/liwi/compare/v10.1.0...v10.1.1) (2022-12-10)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **liwi-mongo:** meta count using criteria ([e2347ad](https://github.com/liwijs/liwi/commit/e2347adb00e229c78a7b8523b1ac06beb6ca0545))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [10.0.0](https://github.com/liwijs/liwi/compare/v9.2.0...v10.0.0) (2022-11-27)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Code Refactoring
|
|
21
|
+
|
|
22
|
+
* drop node 14 and cjs ([b7035bd](https://github.com/liwijs/liwi/commit/b7035bd2289982ef56d3e560f4f3f308e90a555e))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* **deps:** update nightingale to v13 (major) ([#128](https://github.com/liwijs/liwi/issues/128)) ([f04d7fe](https://github.com/liwijs/liwi/commit/f04d7fe2deba3f20733ff945a35c61098139d8a9))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### BREAKING CHANGES
|
|
31
|
+
|
|
32
|
+
* dropped node 14 and cjs
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
6
38
|
# [9.2.0](https://github.com/liwijs/liwi/compare/v9.1.0...v9.2.0) (2022-10-29)
|
|
7
39
|
|
|
8
40
|
**Note:** Version bump only for package liwi-mongo
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BaseModel, AllowedKeyValue, InsertType } from 'liwi-store';
|
|
2
|
+
export type MongoKeyPath = '_id';
|
|
3
|
+
export interface MongoBaseModel<KeyValue extends AllowedKeyValue = string> extends BaseModel {
|
|
4
|
+
_id: KeyValue;
|
|
5
|
+
}
|
|
6
|
+
export type MongoInsertType<Model extends MongoBaseModel<KeyValue>, KeyValue extends AllowedKeyValue = Model[MongoKeyPath]> = InsertType<Model, MongoKeyPath>;
|
|
7
|
+
//# sourceMappingURL=MongoBaseModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoBaseModel.d.ts","sourceRoot":"","sources":["../../src/MongoBaseModel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEzE,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC;AAEjC,MAAM,WAAW,cAAc,CAAC,QAAQ,SAAS,eAAe,GAAG,MAAM,CACvE,SAAQ,SAAS;IACjB,GAAG,EAAE,QAAQ,CAAC;CACf;AAED,MAAM,MAAM,eAAe,CACzB,KAAK,SAAS,cAAc,CAAC,QAAQ,CAAC,EACtC,QAAQ,SAAS,eAAe,GAAG,KAAK,CAAC,YAAY,CAAC,IACpD,UAAU,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoConnection.d.ts","sourceRoot":"","sources":["../../src/MongoConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,OAAO,MAAM,SAAS,CAAC;AAK9B,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,kBAAkB;IAC7D,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC;IAElC,WAAW,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAE3C,gBAAgB,CAAC,E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,CAAC;IAQrC,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAKzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQtB,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAG7B"}
|
|
@@ -2,7 +2,7 @@ import type { QuerySubscription, SubscribeCallback, QueryResult, QueryParams, Qu
|
|
|
2
2
|
import { AbstractSubscribableStoreQuery } from 'liwi-subscribe-store';
|
|
3
3
|
import type { MongoBaseModel, MongoInsertType, MongoKeyPath } from './MongoBaseModel';
|
|
4
4
|
import type MongoStore from './MongoStore';
|
|
5
|
-
|
|
5
|
+
type TestCriteria = (obj: any) => boolean;
|
|
6
6
|
export default class MongoQueryCollection<Model extends MongoBaseModel<KeyValue>, Params extends QueryParams<Params> = never, KeyValue extends AllowedKeyValue = Model['_id'], Item extends Record<MongoKeyPath, KeyValue> = Model> extends AbstractSubscribableStoreQuery<MongoKeyPath, KeyValue, Model, MongoInsertType<Model, KeyValue>, Params, Item[]> {
|
|
7
7
|
private readonly store;
|
|
8
8
|
private readonly options;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoQueryCollection.d.ts","sourceRoot":"","sources":["../../src/MongoQueryCollection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,EACX,WAAW,EAEX,YAAY,EACZ,WAAW,EACX,eAAe,EAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAEtE,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,YAAY,EACb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAS3C,KAAK,YAAY,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC;AAE1C,MAAM,CAAC,OAAO,OAAO,oBAAoB,CACvC,KAAK,SAAS,cAAc,CAAC,QAAQ,CAAC,EACtC,MAAM,SAAS,WAAW,CAAC,MAAM,CAAC,GAAG,KAAK,EAC1C,QAAQ,SAAS,eAAe,GAAG,KAAK,CAAC,KAAK,CAAC,EAC/C,IAAI,SAAS,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,GAAG,KAAK,CACnD,SAAQ,8BAA8B,CACtC,YAAY,EACZ,QAAQ,EACR,KAAK,EACL,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,EAChC,MAAM,EACN,IAAI,EAAE,CACP;IACC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA8B;IAEpD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAE9C,OAAO,CAAC,YAAY,CAAC,CAAe;IAEpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA2B;gBAGrD,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,EAClC,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,EAC5B,WAAW,GAAE,WAAW,CAAC,KAAK,EAAE,IAAI,CAAuB;IAQ7D,kBAAkB,IAAI,YAAY;IAY5B,KAAK,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAiB3E,UAAU,CACR,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,EAC7C,eAAe,EAAE,OAAO,GACvB,iBAAiB;YAiHN,iBAAiB;CAkBhC"}
|
|
@@ -2,7 +2,7 @@ import type { QuerySubscription, SubscribeCallback, QueryResult, QueryParams, Qu
|
|
|
2
2
|
import { AbstractSubscribableStoreQuery } from 'liwi-subscribe-store';
|
|
3
3
|
import type { MongoBaseModel, MongoInsertType, MongoKeyPath } from './MongoBaseModel';
|
|
4
4
|
import type MongoStore from './MongoStore';
|
|
5
|
-
|
|
5
|
+
type TestCriteria = (obj: any) => boolean;
|
|
6
6
|
export default class MongoQuerySingleItem<Model extends MongoBaseModel<KeyValue>, Params extends QueryParams<Params> = never, Result extends Record<MongoKeyPath, KeyValue> | null = Model | null, KeyValue extends AllowedKeyValue = Model['_id']> extends AbstractSubscribableStoreQuery<MongoKeyPath, KeyValue, Model, MongoInsertType<Model, KeyValue>, Params, Result> {
|
|
7
7
|
private readonly store;
|
|
8
8
|
private readonly options;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoQuerySingleItem.d.ts","sourceRoot":"","sources":["../../src/MongoQuerySingleItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,EACX,WAAW,EAEX,YAAY,EACZ,WAAW,EACX,eAAe,EAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAEtE,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,YAAY,EACb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAS3C,KAAK,YAAY,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC;AAE1C,MAAM,CAAC,OAAO,OAAO,oBAAoB,CACvC,KAAK,SAAS,cAAc,CAAC,QAAQ,CAAC,EACtC,MAAM,SAAS,WAAW,CAAC,MAAM,CAAC,GAAG,KAAK,EAC1C,MAAM,SAAS,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,EACnE,QAAQ,SAAS,eAAe,GAAG,KAAK,CAAC,KAAK,CAAC,CAC/C,SAAQ,8BAA8B,CACtC,YAAY,EACZ,QAAQ,EACR,KAAK,EACL,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,EAChC,MAAM,EACN,MAAM,CACP;IACC,OAAO,CAAC,QAAQ,CA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CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,YAAY,EACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,eAAe,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAE3C,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,KAAK,SAAS,cAAc,CAAC,QAAQ,CAAC,EACtC,QAAQ,SAAS,eAAe,GAAG,KAAK,CAAC,YAAY,CAAC,EAEtD,UAAU,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,GACtC,cAAc,CACf,YAAY,EACZ,QAAQ,EACR,KAAK,EACL,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,EAChC,eAAe,EACf,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,CAC5B,CAEA"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,cAAc,EACd,YAAY,EACZ,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -6,15 +6,14 @@ import { Logger } from 'nightingale-logger';
|
|
|
6
6
|
|
|
7
7
|
class MongoCursor extends AbstractStoreCursor {
|
|
8
8
|
// key in AbstractCursor
|
|
9
|
+
|
|
9
10
|
constructor(store, cursor) {
|
|
10
11
|
super(store);
|
|
11
12
|
this.cursor = cursor;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
14
|
advance(count) {
|
|
15
15
|
this.cursor.skip(count);
|
|
16
16
|
}
|
|
17
|
-
|
|
18
17
|
next() {
|
|
19
18
|
return this.cursor.next().then(value => {
|
|
20
19
|
this._result = value;
|
|
@@ -22,35 +21,27 @@ class MongoCursor extends AbstractStoreCursor {
|
|
|
22
21
|
return this.key;
|
|
23
22
|
});
|
|
24
23
|
}
|
|
25
|
-
|
|
26
24
|
limit(newLimit) {
|
|
27
25
|
this.cursor.limit(newLimit);
|
|
28
26
|
return Promise.resolve(this);
|
|
29
27
|
}
|
|
30
|
-
|
|
31
28
|
result() {
|
|
32
29
|
if (!this._result) throw new Error('Cannot call result() before next()');
|
|
33
30
|
return Promise.resolve(this._result);
|
|
34
31
|
}
|
|
35
|
-
|
|
36
32
|
close() {
|
|
37
33
|
if (this.cursor) {
|
|
38
34
|
this.cursor.close();
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
return Promise.resolve();
|
|
42
37
|
}
|
|
43
|
-
|
|
44
38
|
toArray() {
|
|
45
39
|
return this.cursor.toArray();
|
|
46
40
|
}
|
|
47
|
-
|
|
48
41
|
}
|
|
49
42
|
|
|
50
43
|
/* eslint-disable complexity, max-lines */
|
|
51
|
-
|
|
52
44
|
const identityTransformer$1 = model => model;
|
|
53
|
-
|
|
54
45
|
class MongoQueryCollection extends AbstractSubscribableStoreQuery {
|
|
55
46
|
constructor(store, options, transformer = identityTransformer$1) {
|
|
56
47
|
super();
|
|
@@ -58,22 +49,18 @@ class MongoQueryCollection extends AbstractSubscribableStoreQuery {
|
|
|
58
49
|
this.options = options;
|
|
59
50
|
this.transformer = transformer;
|
|
60
51
|
}
|
|
61
|
-
|
|
62
52
|
createTestCriteria() {
|
|
63
53
|
if (!this.testCriteria) {
|
|
64
54
|
if (!this.options.criteria) {
|
|
65
55
|
return () => true;
|
|
66
56
|
}
|
|
67
|
-
|
|
68
57
|
const mingoQuery = new mingo.Query(this.options.criteria);
|
|
69
58
|
this.testCriteria = mingoQuery.test.bind(mingoQuery);
|
|
70
59
|
}
|
|
71
|
-
|
|
72
60
|
return this.testCriteria;
|
|
73
61
|
}
|
|
74
|
-
|
|
75
62
|
async fetch(onFulfilled) {
|
|
76
|
-
const [result, count] = await Promise.all([this.createMongoCursor().then(cursor => cursor.toArray()), this.store.count()]);
|
|
63
|
+
const [result, count] = await Promise.all([this.createMongoCursor().then(cursor => cursor.toArray()), this.store.count(this.options.criteria)]);
|
|
77
64
|
return onFulfilled({
|
|
78
65
|
result: result.map(this.transformer),
|
|
79
66
|
meta: {
|
|
@@ -86,7 +73,6 @@ class MongoQueryCollection extends AbstractSubscribableStoreQuery {
|
|
|
86
73
|
}
|
|
87
74
|
});
|
|
88
75
|
}
|
|
89
|
-
|
|
90
76
|
_subscribe(callback, _includeInitial) {
|
|
91
77
|
const store = super.getSubscribeStore();
|
|
92
78
|
const testCriteria = this.createTestCriteria();
|
|
@@ -104,36 +90,29 @@ class MongoQueryCollection extends AbstractSubscribableStoreQuery {
|
|
|
104
90
|
}) : Promise.resolve();
|
|
105
91
|
const unsubscribe = store.subscribe(action => {
|
|
106
92
|
const changes = [];
|
|
107
|
-
|
|
108
93
|
switch (action.type) {
|
|
109
94
|
case 'inserted':
|
|
110
95
|
{
|
|
111
96
|
const filtered = action.next.filter(testCriteria);
|
|
112
|
-
|
|
113
97
|
if (filtered.length > 0) {
|
|
114
98
|
changes.push({
|
|
115
99
|
type: 'inserted',
|
|
116
100
|
result: filtered.map(this.transformer)
|
|
117
101
|
});
|
|
118
102
|
}
|
|
119
|
-
|
|
120
103
|
break;
|
|
121
104
|
}
|
|
122
|
-
|
|
123
105
|
case 'deleted':
|
|
124
106
|
{
|
|
125
107
|
const filtered = action.prev.filter(testCriteria);
|
|
126
|
-
|
|
127
108
|
if (filtered.length > 0) {
|
|
128
109
|
changes.push({
|
|
129
110
|
type: 'deleted',
|
|
130
111
|
keys: filtered.map(object => object[this.store.keyPath])
|
|
131
112
|
});
|
|
132
113
|
}
|
|
133
|
-
|
|
134
114
|
break;
|
|
135
115
|
}
|
|
136
|
-
|
|
137
116
|
case 'updated':
|
|
138
117
|
{
|
|
139
118
|
const {
|
|
@@ -156,38 +135,33 @@ class MongoQueryCollection extends AbstractSubscribableStoreQuery {
|
|
|
156
135
|
inserted.push(this.transformer(nextObject));
|
|
157
136
|
}
|
|
158
137
|
});
|
|
159
|
-
|
|
160
138
|
if (deleted.length > 0) {
|
|
161
139
|
changes.push({
|
|
162
140
|
type: 'deleted',
|
|
163
141
|
keys: deleted
|
|
164
142
|
});
|
|
165
143
|
}
|
|
166
|
-
|
|
167
144
|
if (updated.length > 0) {
|
|
168
145
|
changes.push({
|
|
169
146
|
type: 'updated',
|
|
170
147
|
result: updated
|
|
171
148
|
});
|
|
172
149
|
}
|
|
173
|
-
|
|
174
150
|
if (inserted.length > 0) {
|
|
175
151
|
changes.push({
|
|
176
152
|
type: 'inserted',
|
|
177
153
|
result: inserted
|
|
178
154
|
});
|
|
179
155
|
}
|
|
180
|
-
|
|
181
156
|
break;
|
|
182
157
|
}
|
|
183
|
-
|
|
184
158
|
default:
|
|
185
159
|
throw new Error('Unsupported type');
|
|
186
160
|
}
|
|
187
|
-
|
|
188
161
|
if (changes.length === 0) return;
|
|
189
162
|
callback(null, changes);
|
|
190
|
-
});
|
|
163
|
+
});
|
|
164
|
+
// let _feed;
|
|
191
165
|
// const promise = this.queryCallback(this.store.query(), this.store.r)
|
|
192
166
|
// .changes({
|
|
193
167
|
// includeInitial: _includeInitial,
|
|
@@ -213,25 +187,19 @@ class MongoQueryCollection extends AbstractSubscribableStoreQuery {
|
|
|
213
187
|
then: (onFulfilled, onRejected) => promise.then(onFulfilled, onRejected)
|
|
214
188
|
};
|
|
215
189
|
}
|
|
216
|
-
|
|
217
190
|
async createMongoCursor() {
|
|
218
191
|
const cursor = await this.store.cursor(this.options.criteria, this.options.sort);
|
|
219
|
-
|
|
220
192
|
if (this.options.skip) {
|
|
221
193
|
cursor.advance(this.options.skip);
|
|
222
194
|
}
|
|
223
|
-
|
|
224
195
|
if (this.options.limit) {
|
|
225
196
|
await cursor.limit(this.options.limit);
|
|
226
197
|
}
|
|
227
|
-
|
|
228
198
|
return cursor;
|
|
229
199
|
}
|
|
230
|
-
|
|
231
200
|
}
|
|
232
201
|
|
|
233
202
|
const identityTransformer = model => model;
|
|
234
|
-
|
|
235
203
|
class MongoQuerySingleItem extends AbstractSubscribableStoreQuery {
|
|
236
204
|
constructor(store, options, transformer = identityTransformer) {
|
|
237
205
|
super();
|
|
@@ -239,20 +207,16 @@ class MongoQuerySingleItem extends AbstractSubscribableStoreQuery {
|
|
|
239
207
|
this.options = options;
|
|
240
208
|
this.transformer = transformer;
|
|
241
209
|
}
|
|
242
|
-
|
|
243
210
|
createMingoTestCriteria() {
|
|
244
211
|
if (!this.testCriteria) {
|
|
245
212
|
if (!this.options.criteria) {
|
|
246
213
|
return () => true;
|
|
247
214
|
}
|
|
248
|
-
|
|
249
215
|
const mingoQuery = new mingo.Query(this.options.criteria);
|
|
250
216
|
this.testCriteria = mingoQuery.test.bind(mingoQuery);
|
|
251
217
|
}
|
|
252
|
-
|
|
253
218
|
return this.testCriteria;
|
|
254
219
|
}
|
|
255
|
-
|
|
256
220
|
async fetch(onFulfilled) {
|
|
257
221
|
const cursor = await this.createMongoCursor();
|
|
258
222
|
await cursor.limit(1);
|
|
@@ -270,7 +234,6 @@ class MongoQuerySingleItem extends AbstractSubscribableStoreQuery {
|
|
|
270
234
|
});
|
|
271
235
|
});
|
|
272
236
|
}
|
|
273
|
-
|
|
274
237
|
_subscribe(callback, _includeInitial) {
|
|
275
238
|
const store = super.getSubscribeStore();
|
|
276
239
|
const testCriteria = this.createMingoTestCriteria();
|
|
@@ -288,40 +251,32 @@ class MongoQuerySingleItem extends AbstractSubscribableStoreQuery {
|
|
|
288
251
|
}) : Promise.resolve();
|
|
289
252
|
const unsubscribe = store.subscribe(async action => {
|
|
290
253
|
const changes = [];
|
|
291
|
-
|
|
292
254
|
switch (action.type) {
|
|
293
255
|
case 'inserted':
|
|
294
256
|
{
|
|
295
257
|
const filtered = action.next.filter(testCriteria);
|
|
296
|
-
|
|
297
258
|
if (filtered.length > 0) {
|
|
298
259
|
changes.push({
|
|
299
260
|
type: 'updated',
|
|
300
261
|
result: this.transformer(filtered[0])
|
|
301
262
|
});
|
|
302
263
|
}
|
|
303
|
-
|
|
304
264
|
break;
|
|
305
265
|
}
|
|
306
|
-
|
|
307
266
|
case 'deleted':
|
|
308
267
|
{
|
|
309
268
|
const filtered = action.prev.filter(testCriteria);
|
|
310
|
-
|
|
311
269
|
if (filtered.length > 0) {
|
|
312
270
|
changes.push({
|
|
313
271
|
type: 'deleted',
|
|
314
272
|
keys: filtered.map(object => object[this.store.keyPath])
|
|
315
273
|
});
|
|
316
274
|
}
|
|
317
|
-
|
|
318
275
|
break;
|
|
319
276
|
}
|
|
320
|
-
|
|
321
277
|
case 'updated':
|
|
322
278
|
{
|
|
323
279
|
const filtered = action.changes.filter(([prev, next]) => testCriteria(prev));
|
|
324
|
-
|
|
325
280
|
if (filtered.length > 0) {
|
|
326
281
|
if (this.options.sort) {
|
|
327
282
|
const {
|
|
@@ -341,14 +296,11 @@ class MongoQuerySingleItem extends AbstractSubscribableStoreQuery {
|
|
|
341
296
|
});
|
|
342
297
|
}
|
|
343
298
|
} else if (filtered.length === 0) ;
|
|
344
|
-
|
|
345
299
|
break;
|
|
346
300
|
}
|
|
347
|
-
|
|
348
301
|
default:
|
|
349
302
|
throw new Error('Unsupported type');
|
|
350
303
|
}
|
|
351
|
-
|
|
352
304
|
if (changes.length === 0) return;
|
|
353
305
|
callback(null, changes);
|
|
354
306
|
});
|
|
@@ -358,30 +310,23 @@ class MongoQuerySingleItem extends AbstractSubscribableStoreQuery {
|
|
|
358
310
|
then: (onFulfilled, onRejected) => promise.then(onFulfilled, onRejected)
|
|
359
311
|
};
|
|
360
312
|
}
|
|
361
|
-
|
|
362
313
|
async createMongoCursor() {
|
|
363
314
|
const cursor = await this.store.cursor(this.options.criteria, this.options.sort);
|
|
364
|
-
|
|
365
315
|
if (this.options.limit) {
|
|
366
316
|
await cursor.limit(this.options.limit);
|
|
367
317
|
}
|
|
368
|
-
|
|
369
318
|
return cursor;
|
|
370
319
|
}
|
|
371
|
-
|
|
372
320
|
}
|
|
373
321
|
|
|
374
322
|
/* eslint-disable max-lines */
|
|
375
323
|
class MongoStore {
|
|
376
324
|
keyPath = '_id';
|
|
377
|
-
|
|
378
325
|
constructor(connection, collectionName) {
|
|
379
326
|
this.connection = connection;
|
|
380
|
-
|
|
381
327
|
if (!collectionName) {
|
|
382
328
|
throw new Error(`Invalid collectionName: "${collectionName}"`);
|
|
383
329
|
}
|
|
384
|
-
|
|
385
330
|
this._collection = connection.getConnection().then(client => {
|
|
386
331
|
this._collection = client.db().collection(collectionName);
|
|
387
332
|
return this._collection;
|
|
@@ -390,43 +335,35 @@ class MongoStore {
|
|
|
390
335
|
return this._collection;
|
|
391
336
|
});
|
|
392
337
|
}
|
|
393
|
-
|
|
394
338
|
get collection() {
|
|
395
339
|
if (this.connection.connectionFailed) {
|
|
396
340
|
return Promise.reject(new Error('MongoDB connection failed'));
|
|
397
341
|
}
|
|
398
|
-
|
|
399
342
|
return Promise.resolve(this._collection);
|
|
400
343
|
}
|
|
401
|
-
|
|
402
344
|
createQuerySingleItem(options, transformer) {
|
|
403
345
|
return new MongoQuerySingleItem(this, options, transformer);
|
|
404
346
|
}
|
|
405
|
-
|
|
406
347
|
createQueryCollection(options, transformer) {
|
|
407
348
|
return new MongoQueryCollection(this, options, transformer);
|
|
408
349
|
}
|
|
409
|
-
|
|
410
350
|
async insertOne(object) {
|
|
411
351
|
if (!object._id) {
|
|
412
352
|
object._id = new mongodb.ObjectId().toString();
|
|
413
353
|
}
|
|
414
|
-
|
|
415
354
|
if (!object.created) object.created = new Date();
|
|
416
355
|
if (!object.updated) object.updated = new Date();
|
|
417
356
|
const collection = await this.collection;
|
|
418
357
|
const {
|
|
419
358
|
acknowledged: isAcknowledged
|
|
420
|
-
} = await collection.insertOne(
|
|
359
|
+
} = await collection.insertOne(
|
|
360
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
421
361
|
object);
|
|
422
|
-
|
|
423
362
|
if (!isAcknowledged) {
|
|
424
363
|
throw new Error('Fail to insert');
|
|
425
364
|
}
|
|
426
|
-
|
|
427
365
|
return object;
|
|
428
366
|
}
|
|
429
|
-
|
|
430
367
|
async replaceOne(object) {
|
|
431
368
|
if (!object.updated) object.updated = new Date();
|
|
432
369
|
const collection = await this.collection;
|
|
@@ -435,23 +372,20 @@ class MongoStore {
|
|
|
435
372
|
}, object);
|
|
436
373
|
return object;
|
|
437
374
|
}
|
|
438
|
-
|
|
439
375
|
async upsertOne(object, setOnInsertPartialObject) {
|
|
440
376
|
const result = await this.upsertOneWithInfo(object, setOnInsertPartialObject);
|
|
441
377
|
return result.object;
|
|
442
378
|
}
|
|
443
|
-
|
|
444
379
|
async upsertOneWithInfo(object, setOnInsertPartialObject) {
|
|
445
380
|
const $setOnInsert = {
|
|
446
381
|
created: object.created || new Date(),
|
|
447
382
|
...setOnInsertPartialObject
|
|
448
383
|
};
|
|
449
|
-
|
|
450
384
|
if (!object.updated) {
|
|
451
385
|
object.updated = new Date();
|
|
452
386
|
}
|
|
453
|
-
|
|
454
|
-
|
|
387
|
+
const $set = {
|
|
388
|
+
...object
|
|
455
389
|
};
|
|
456
390
|
delete $set.created;
|
|
457
391
|
const collection = await this.collection;
|
|
@@ -465,43 +399,36 @@ class MongoStore {
|
|
|
465
399
|
}, {
|
|
466
400
|
upsert: true
|
|
467
401
|
});
|
|
468
|
-
|
|
469
402
|
if (upsertedCount) {
|
|
470
403
|
Object.assign(object, $setOnInsert);
|
|
471
404
|
}
|
|
472
|
-
|
|
473
405
|
return {
|
|
474
406
|
object: object,
|
|
475
407
|
inserted: !!upsertedCount
|
|
476
408
|
};
|
|
477
409
|
}
|
|
478
|
-
|
|
479
410
|
replaceSeveral(objects) {
|
|
480
411
|
return Promise.all(objects.map(object => this.replaceOne(object)));
|
|
481
412
|
}
|
|
482
|
-
|
|
483
413
|
async partialUpdateByKey(key, partialUpdate, criteria) {
|
|
484
414
|
const collection = await this.collection;
|
|
485
415
|
const commandResult = await collection.updateOne({
|
|
486
416
|
_id: key,
|
|
487
417
|
...criteria
|
|
488
418
|
}, partialUpdate);
|
|
489
|
-
|
|
490
419
|
if (!commandResult.acknowledged) {
|
|
491
420
|
console.error(commandResult);
|
|
492
421
|
throw new Error('Update failed');
|
|
493
422
|
}
|
|
494
|
-
|
|
495
423
|
const object = await this.findByKey(key);
|
|
496
424
|
return object;
|
|
497
425
|
}
|
|
498
|
-
|
|
499
426
|
partialUpdateOne(object, partialUpdate) {
|
|
500
427
|
return this.partialUpdateByKey(object._id, partialUpdate);
|
|
501
428
|
}
|
|
502
|
-
|
|
503
429
|
partialUpdateMany(criteria, partialUpdate) {
|
|
504
|
-
return this.collection.then(collection =>
|
|
430
|
+
return this.collection.then(collection =>
|
|
431
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
505
432
|
collection.updateMany(criteria, partialUpdate)).then(() => undefined); // TODO return updated object
|
|
506
433
|
}
|
|
507
434
|
|
|
@@ -511,27 +438,22 @@ class MongoStore {
|
|
|
511
438
|
...criteria
|
|
512
439
|
})).then(() => undefined);
|
|
513
440
|
}
|
|
514
|
-
|
|
515
441
|
deleteOne(object) {
|
|
516
442
|
return this.deleteByKey(object._id);
|
|
517
443
|
}
|
|
518
|
-
|
|
519
444
|
deleteMany(selector) {
|
|
520
445
|
return this.collection.then(collection => collection.deleteMany(selector)).then(() => undefined);
|
|
521
446
|
}
|
|
522
|
-
|
|
523
447
|
async count(filter) {
|
|
524
448
|
const collection = await this.collection;
|
|
525
449
|
return filter ? collection.countDocuments(filter) : collection.countDocuments();
|
|
526
450
|
}
|
|
527
|
-
|
|
528
451
|
async cursor(filter, sort) {
|
|
529
452
|
const collection = await this.collection;
|
|
530
453
|
const findCursor = filter ? collection.find(filter) : collection.find();
|
|
531
454
|
if (sort) findCursor.sort(sort);
|
|
532
455
|
return new MongoCursor(this, findCursor);
|
|
533
456
|
}
|
|
534
|
-
|
|
535
457
|
async findByKey(key, criteria) {
|
|
536
458
|
const collection = await this.collection;
|
|
537
459
|
const result = await collection.findOne({
|
|
@@ -540,11 +462,9 @@ class MongoStore {
|
|
|
540
462
|
});
|
|
541
463
|
return result || undefined;
|
|
542
464
|
}
|
|
543
|
-
|
|
544
465
|
findAll(criteria, sort) {
|
|
545
466
|
return this.cursor(criteria, sort).then(cursor => cursor.toArray());
|
|
546
467
|
}
|
|
547
|
-
|
|
548
468
|
async findOne(filter, sort) {
|
|
549
469
|
const collection = await this.collection;
|
|
550
470
|
const result = await collection.findOne(filter, {
|
|
@@ -552,7 +472,6 @@ class MongoStore {
|
|
|
552
472
|
});
|
|
553
473
|
return result || undefined;
|
|
554
474
|
}
|
|
555
|
-
|
|
556
475
|
}
|
|
557
476
|
|
|
558
477
|
const logger = new Logger('liwi:mongo:MongoConnection');
|
|
@@ -560,26 +479,20 @@ class MongoConnection extends AbstractConnection {
|
|
|
560
479
|
// TODO interface
|
|
561
480
|
constructor(config) {
|
|
562
481
|
super();
|
|
563
|
-
|
|
564
482
|
if (!config.has('host')) {
|
|
565
483
|
config.set('host', 'localhost');
|
|
566
484
|
}
|
|
567
|
-
|
|
568
485
|
if (!config.has('port')) {
|
|
569
486
|
config.set('port', '27017');
|
|
570
487
|
}
|
|
571
|
-
|
|
572
488
|
if (!config.has('database')) {
|
|
573
489
|
throw new Error('Missing config database');
|
|
574
490
|
}
|
|
575
|
-
|
|
576
491
|
const buildConnectionString = redactCredentials => `mongodb://${config.has('user') ? `${redactCredentials ? `${config.get('user').slice(0, 2)}[redacted]` : config.get('user')}:${redactCredentials ? '[redacted]' : config.get('password')}@` : ''}` + `${config.get('host')}:${config.get('port')}/${config.get('database')}`;
|
|
577
|
-
|
|
578
492
|
const connectionString = buildConnectionString(false);
|
|
579
493
|
const connectionStringRedacted = buildConnectionString(true);
|
|
580
494
|
this.connect(connectionString, connectionStringRedacted);
|
|
581
495
|
}
|
|
582
|
-
|
|
583
496
|
connect(connectionString, connectionStringRedacted) {
|
|
584
497
|
logger.info('connecting', {
|
|
585
498
|
connectionStringRedacted
|
|
@@ -593,7 +506,6 @@ class MongoConnection extends AbstractConnection {
|
|
|
593
506
|
connectionStringRedacted
|
|
594
507
|
});
|
|
595
508
|
this.connectionFailed = true;
|
|
596
|
-
|
|
597
509
|
this.getConnection = () => {
|
|
598
510
|
throw new Error('MongoDB connection closed');
|
|
599
511
|
};
|
|
@@ -603,7 +515,6 @@ class MongoConnection extends AbstractConnection {
|
|
|
603
515
|
connectionStringRedacted
|
|
604
516
|
});
|
|
605
517
|
this.connectionFailed = true;
|
|
606
|
-
|
|
607
518
|
this.getConnection = () => {
|
|
608
519
|
throw new Error('MongoDB connection timeout');
|
|
609
520
|
};
|
|
@@ -613,7 +524,6 @@ class MongoConnection extends AbstractConnection {
|
|
|
613
524
|
connectionStringRedacted
|
|
614
525
|
});
|
|
615
526
|
this.connectionFailed = false;
|
|
616
|
-
|
|
617
527
|
this.getConnection = () => Promise.resolve(this._connection);
|
|
618
528
|
});
|
|
619
529
|
connection.on('error', err => {
|
|
@@ -624,35 +534,28 @@ class MongoConnection extends AbstractConnection {
|
|
|
624
534
|
});
|
|
625
535
|
this._connection = connection;
|
|
626
536
|
this._connecting = undefined;
|
|
627
|
-
|
|
628
537
|
this.getConnection = () => Promise.resolve(this._connection);
|
|
629
|
-
|
|
630
538
|
return connection;
|
|
631
539
|
}).catch(err => {
|
|
632
540
|
logger.info('not connected', {
|
|
633
541
|
connectionStringRedacted
|
|
634
542
|
});
|
|
635
|
-
console.error(err.message || err);
|
|
636
|
-
|
|
543
|
+
console.error(err.message || err);
|
|
544
|
+
// throw err;
|
|
637
545
|
process.nextTick(() => {
|
|
638
546
|
// eslint-disable-next-line unicorn/no-process-exit
|
|
639
547
|
process.exit(1);
|
|
640
548
|
});
|
|
641
549
|
throw err;
|
|
642
550
|
});
|
|
643
|
-
|
|
644
551
|
this.getConnection = () => Promise.resolve(connectPromise);
|
|
645
|
-
|
|
646
552
|
this._connecting = this.getConnection();
|
|
647
553
|
}
|
|
648
|
-
|
|
649
554
|
getConnection() {
|
|
650
555
|
throw new Error('call connect()');
|
|
651
556
|
}
|
|
652
|
-
|
|
653
557
|
async close() {
|
|
654
558
|
this.getConnection = () => Promise.reject(new Error('Connection closed'));
|
|
655
|
-
|
|
656
559
|
if (this._connection) {
|
|
657
560
|
await this._connection.close();
|
|
658
561
|
this._connection = undefined;
|
|
@@ -661,7 +564,6 @@ class MongoConnection extends AbstractConnection {
|
|
|
661
564
|
await this.close();
|
|
662
565
|
}
|
|
663
566
|
}
|
|
664
|
-
|
|
665
567
|
}
|
|
666
568
|
|
|
667
569
|
function createMongoSubscribeStore(mongoStore) {
|
|
@@ -669,4 +571,4 @@ function createMongoSubscribeStore(mongoStore) {
|
|
|
669
571
|
}
|
|
670
572
|
|
|
671
573
|
export { MongoConnection, MongoStore, createMongoSubscribeStore };
|
|
672
|
-
//# sourceMappingURL=index-
|
|
574
|
+
//# sourceMappingURL=index-node16.mjs.map
|