@furystack/mongodb-store 6.1.2 → 7.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/package.json +26 -9
- package/src/mongodb-store.spec.ts +3 -1
- package/src/mongodb-store.ts +2 -2
- package/types/mongodb-store.d.ts.map +1 -1
- package/dist/index.js +0 -19
- package/dist/index.js.map +0 -1
- package/dist/mongo-client-factory.js +0 -37
- package/dist/mongo-client-factory.js.map +0 -1
- package/dist/mongodb-store.js +0 -149
- package/dist/mongodb-store.js.map +0 -1
- package/dist/mongodb-store.spec.js +0 -64
- package/dist/mongodb-store.spec.js.map +0 -1
- package/dist/store-manager-helpers.js +0 -19
- package/dist/store-manager-helpers.js.map +0 -1
- package/types/mongodb-store.spec.d.ts +0 -2
- package/types/mongodb-store.spec.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@furystack/mongodb-store",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "MongoDB Store implementation for FuryStack",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build:es6": "tsc --outDir ./esm"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./esm/index.js",
|
|
12
|
+
"types": "./types/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"typesVersions": {
|
|
17
|
+
"*": {
|
|
18
|
+
"*": [
|
|
19
|
+
"types/*"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
6
23
|
"files": [
|
|
7
24
|
"dist",
|
|
8
25
|
"types",
|
|
@@ -29,16 +46,16 @@
|
|
|
29
46
|
},
|
|
30
47
|
"homepage": "https://github.com/furystack/furystack",
|
|
31
48
|
"dependencies": {
|
|
32
|
-
"@furystack/core": "^
|
|
33
|
-
"@furystack/inject": "^
|
|
34
|
-
"@furystack/utils": "^
|
|
35
|
-
"mongodb": "5.
|
|
49
|
+
"@furystack/core": "^12.0.0",
|
|
50
|
+
"@furystack/inject": "^8.0.0",
|
|
51
|
+
"@furystack/utils": "^4.0.0",
|
|
52
|
+
"mongodb": "5.3.0",
|
|
36
53
|
"semaphore-async-await": "^1.5.1"
|
|
37
54
|
},
|
|
38
55
|
"devDependencies": {
|
|
39
|
-
"@types/
|
|
40
|
-
"
|
|
56
|
+
"@types/node": "^18.15.11",
|
|
57
|
+
"typescript": "^5.0.4",
|
|
58
|
+
"vitest": "^0.30.1"
|
|
41
59
|
},
|
|
42
|
-
"typings": "./types/index.d.ts",
|
|
43
60
|
"gitHead": "1045d854bfd8c475b7035471d130d401417a2321"
|
|
44
61
|
}
|
|
@@ -4,10 +4,12 @@ global.TextEncoder = TextEncoder
|
|
|
4
4
|
global.TextDecoder = TextDecoder as any
|
|
5
5
|
|
|
6
6
|
import { Injector } from '@furystack/inject'
|
|
7
|
-
import { StoreManager
|
|
7
|
+
import { StoreManager } from '@furystack/core'
|
|
8
8
|
import { useMongoDb } from './store-manager-helpers'
|
|
9
9
|
import { MongoClientFactory } from './mongo-client-factory'
|
|
10
10
|
import { usingAsync } from '@furystack/utils'
|
|
11
|
+
import { describe, it, expect } from 'vitest'
|
|
12
|
+
import { createStoreTest, TestClass } from '@furystack/core/create-physical-store-tests'
|
|
11
13
|
|
|
12
14
|
class TestClassWithId {
|
|
13
15
|
_id!: string
|
package/src/mongodb-store.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
import type { Constructable } from '@furystack/inject'
|
|
10
10
|
import type { MongoClient, Filter, Collection, Sort, OptionalUnlessRequiredId, UpdateFilter } from 'mongodb'
|
|
11
11
|
import { ObjectId } from 'mongodb'
|
|
12
|
-
import
|
|
12
|
+
import { Lock } from 'semaphore-async-await'
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* TypeORM Store implementation for FuryStack
|
|
@@ -24,7 +24,7 @@ export class MongodbStore<
|
|
|
24
24
|
|
|
25
25
|
public readonly model: Constructable<T>
|
|
26
26
|
|
|
27
|
-
private initLock = new
|
|
27
|
+
private initLock = new Lock()
|
|
28
28
|
private collection?: Collection<T>
|
|
29
29
|
|
|
30
30
|
private createIdFilter(...values: Array<T[TPrimaryKey]>): Filter<T> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb-store.d.ts","sourceRoot":"","sources":["../src/mongodb-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,aAAa,EACb,UAAU,EACV,cAAc,EACd,YAAY,EACb,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,WAAW,EAAU,UAAU,EAAgD,MAAM,SAAS,CAAA;AAI5G;;GAEG;AACH,qBAAa,YAAY,CACvB,CAAC,SAAS,MAAM,EAChB,WAAW,SAAS,MAAM,CAAC,EAC3B,cAAc,GAAG,cAAc,CAAC,CAAC,EAAE,WAAW,CAAC,CAC/C,YAAW,aAAa,CAAC,CAAC,EAAE,WAAW,EAAE,cAAc,CAAC;IA6EtD,OAAO,CAAC,QAAQ,CAAC,OAAO;IA3E1B,SAAgB,UAAU,EAAE,WAAW,CAAA;IAEvC,SAAgB,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;IAEvC,OAAO,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"mongodb-store.d.ts","sourceRoot":"","sources":["../src/mongodb-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,aAAa,EACb,UAAU,EACV,cAAc,EACd,YAAY,EACb,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO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CAAC,EAAE,OAAO,CAAC,GAC9B,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAsB5C,OAAO,CAAC,aAAa;IAOR,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAQzE,MAAM,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrD,OAAO;CAGrB"}
|
package/dist/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./mongodb-store"), exports);
|
|
18
|
-
__exportStar(require("./store-manager-helpers"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,0DAAuC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.MongoClientFactory = void 0;
|
|
10
|
-
const inject_1 = require("@furystack/inject");
|
|
11
|
-
const mongodb_1 = require("mongodb");
|
|
12
|
-
/**
|
|
13
|
-
* Factory for instantiating MongoDb clients
|
|
14
|
-
*/
|
|
15
|
-
let MongoClientFactory = class MongoClientFactory {
|
|
16
|
-
constructor() {
|
|
17
|
-
this.connections = new Map();
|
|
18
|
-
}
|
|
19
|
-
async dispose() {
|
|
20
|
-
await Promise.all([...this.connections.values()].map((c) => c.close(true)));
|
|
21
|
-
this.connections.clear();
|
|
22
|
-
}
|
|
23
|
-
async getClientFor(url, options) {
|
|
24
|
-
const existing = this.connections.get(url);
|
|
25
|
-
if (existing) {
|
|
26
|
-
return existing;
|
|
27
|
-
}
|
|
28
|
-
const client = new mongodb_1.MongoClient(url, options);
|
|
29
|
-
this.connections.set(url, client);
|
|
30
|
-
return client;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
MongoClientFactory = __decorate([
|
|
34
|
-
(0, inject_1.Injectable)({ lifetime: 'singleton' })
|
|
35
|
-
], MongoClientFactory);
|
|
36
|
-
exports.MongoClientFactory = MongoClientFactory;
|
|
37
|
-
//# sourceMappingURL=mongo-client-factory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mongo-client-factory.js","sourceRoot":"","sources":["../src/mongo-client-factory.ts"],"names":[],"mappings":";;;;;;;;;AACA,8CAA8C;AAE9C,qCAAqC;AAErC;;GAEG;AAEH,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;IAA/B;QACU,gBAAW,GAA6B,IAAI,GAAG,EAAE,CAAA;IAiB3D,CAAC;IAfQ,KAAK,CAAC,OAAO;QAClB,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAC3E,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAA;IAC1B,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,GAAW,EAAE,OAA4B;QACjE,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC1C,IAAI,QAAQ,EAAE;YACZ,OAAO,QAAQ,CAAA;SAChB;QAED,MAAM,MAAM,GAAG,IAAI,qBAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAC5C,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACjC,OAAO,MAAM,CAAA;IACf,CAAC;CACF,CAAA;AAlBY,kBAAkB;IAD9B,IAAA,mBAAU,EAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;GACzB,kBAAkB,CAkB9B;AAlBY,gDAAkB"}
|
package/dist/mongodb-store.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.MongodbStore = void 0;
|
|
7
|
-
const mongodb_1 = require("mongodb");
|
|
8
|
-
const semaphore_async_await_1 = __importDefault(require("semaphore-async-await"));
|
|
9
|
-
/**
|
|
10
|
-
* TypeORM Store implementation for FuryStack
|
|
11
|
-
*/
|
|
12
|
-
class MongodbStore {
|
|
13
|
-
createIdFilter(...values) {
|
|
14
|
-
return {
|
|
15
|
-
[this.primaryKey]: {
|
|
16
|
-
$in: this.primaryKey === '_id' ? values.map((value) => new mongodb_1.ObjectId(value)) : values,
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
stringifyResultId(item) {
|
|
21
|
-
if (this.primaryKey === '_id' && item._id instanceof mongodb_1.ObjectId) {
|
|
22
|
-
return {
|
|
23
|
-
...item,
|
|
24
|
-
_id: item._id.toHexString(),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
return item;
|
|
28
|
-
}
|
|
29
|
-
parseFilter(filter) {
|
|
30
|
-
if (!filter) {
|
|
31
|
-
return {};
|
|
32
|
-
}
|
|
33
|
-
if (Object.keys(filter).includes('_id')) {
|
|
34
|
-
const f = { ...filter };
|
|
35
|
-
if (typeof f._id === 'string') {
|
|
36
|
-
return {
|
|
37
|
-
...f,
|
|
38
|
-
_id: new mongodb_1.ObjectId(f._id),
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
if (typeof f._id === 'object') {
|
|
42
|
-
if (f._id.$eq) {
|
|
43
|
-
f._id.$eq = new mongodb_1.ObjectId(f._id.$eq);
|
|
44
|
-
}
|
|
45
|
-
if (f._id.$in && f._id.$in instanceof Array) {
|
|
46
|
-
f._id.$in = f._id.$in.map((id) => new mongodb_1.ObjectId(id));
|
|
47
|
-
}
|
|
48
|
-
if (f._id.$nin && f._id.$nin instanceof Array) {
|
|
49
|
-
f._id.$nin = f._id.$nin.map((id) => new mongodb_1.ObjectId(id));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return f;
|
|
53
|
-
}
|
|
54
|
-
return filter;
|
|
55
|
-
}
|
|
56
|
-
async getCollection() {
|
|
57
|
-
if (this.collection) {
|
|
58
|
-
return this.collection;
|
|
59
|
-
}
|
|
60
|
-
await this.initLock.acquire();
|
|
61
|
-
if (this.collection) {
|
|
62
|
-
return this.collection;
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
const client = await this.options.mongoClient();
|
|
66
|
-
const collection = client.db(this.options.db).collection(this.options.collection);
|
|
67
|
-
if (this.primaryKey !== '_id') {
|
|
68
|
-
await collection.createIndex({ [this.primaryKey]: 1 }, { unique: true });
|
|
69
|
-
}
|
|
70
|
-
this.collection = collection;
|
|
71
|
-
return collection;
|
|
72
|
-
}
|
|
73
|
-
finally {
|
|
74
|
-
this.initLock.release();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
constructor(options) {
|
|
78
|
-
this.options = options;
|
|
79
|
-
this.initLock = new semaphore_async_await_1.default(1);
|
|
80
|
-
this.primaryKey = options.primaryKey;
|
|
81
|
-
this.model = options.model;
|
|
82
|
-
}
|
|
83
|
-
async add(...entries) {
|
|
84
|
-
const collection = await this.getCollection();
|
|
85
|
-
const result = await collection.insertMany(entries.map((e) => ({ ...e })));
|
|
86
|
-
return {
|
|
87
|
-
created: this.primaryKey === '_id'
|
|
88
|
-
? Object.values(result.insertedIds).map((insertedId, index) => this.stringifyResultId({ _id: insertedId, ...entries[index] }))
|
|
89
|
-
: Object.values(result.insertedIds).map((insertedId, index) => {
|
|
90
|
-
const entity = { _id: insertedId, ...entries[index] };
|
|
91
|
-
const { _id, ...r } = entity;
|
|
92
|
-
return r;
|
|
93
|
-
}),
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
async update(id, data) {
|
|
97
|
-
const collection = await this.getCollection();
|
|
98
|
-
const updateResult = await collection.updateOne(this.createIdFilter(id), { $set: data });
|
|
99
|
-
if (updateResult.matchedCount < 1) {
|
|
100
|
-
throw Error(`Entity not found with id '${id}', cannot update!`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
async count(filter) {
|
|
104
|
-
const collection = await this.getCollection();
|
|
105
|
-
return await collection.countDocuments(this.parseFilter(filter), {});
|
|
106
|
-
}
|
|
107
|
-
async find(filter) {
|
|
108
|
-
const collection = await this.getCollection();
|
|
109
|
-
const sort = filter.order
|
|
110
|
-
? Object.fromEntries([
|
|
111
|
-
...Object.keys(filter.order).map((key) => [
|
|
112
|
-
key,
|
|
113
|
-
filter.order[key] === 'ASC' ? 1 : -1,
|
|
114
|
-
]),
|
|
115
|
-
])
|
|
116
|
-
: {};
|
|
117
|
-
const result = await collection
|
|
118
|
-
.find(this.parseFilter(filter.filter))
|
|
119
|
-
.project(this.getProjection(filter.select))
|
|
120
|
-
.skip(filter.skip || 0)
|
|
121
|
-
.limit(filter.top || Number.MAX_SAFE_INTEGER)
|
|
122
|
-
.sort(sort)
|
|
123
|
-
.toArray();
|
|
124
|
-
return result.map((entity) => this.stringifyResultId(entity));
|
|
125
|
-
}
|
|
126
|
-
getProjection(fields) {
|
|
127
|
-
return {
|
|
128
|
-
...(this.primaryKey !== '_id' ? { _id: 0 } : {}),
|
|
129
|
-
...(fields ? Object.fromEntries(fields.map((field) => [field, 1])) : {}),
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
async get(key, select) {
|
|
133
|
-
const collection = await this.getCollection();
|
|
134
|
-
const projection = this.getProjection(select);
|
|
135
|
-
const result = await collection.findOne(this.createIdFilter(key), {
|
|
136
|
-
projection,
|
|
137
|
-
});
|
|
138
|
-
return result ? this.stringifyResultId(result) : undefined;
|
|
139
|
-
}
|
|
140
|
-
async remove(...keys) {
|
|
141
|
-
const collection = await this.getCollection();
|
|
142
|
-
await collection.deleteMany(this.createIdFilter(...keys));
|
|
143
|
-
}
|
|
144
|
-
async dispose() {
|
|
145
|
-
/** */
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
exports.MongodbStore = MongodbStore;
|
|
149
|
-
//# sourceMappingURL=mongodb-store.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb-store.js","sourceRoot":"","sources":["../src/mongodb-store.ts"],"names":[],"mappings":";;;;;;AAUA,qCAAkC;AAClC,kFAA6C;AAE7C;;GAEG;AACH,MAAa,YAAY;IAaf,cAAc,CAAC,GAAG,MAA6B;QACrD,OAAO;YACL,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;gBACjB,GAAG,EAAE,IAAI,CAAC,UAAU,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,kBAAQ,CAAC,KAAY,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM;aAC5F;SACW,CAAA;IAChB,CAAC;IAEO,iBAAiB,CAAC,IAAS;QACjC,IAAI,IAAI,CAAC,UAAU,KAAK,KAAK,IAAI,IAAI,CAAC,GAAG,YAAY,kBAAQ,EAAE;YAC7D,OAAO;gBACL,GAAG,IAAI;gBACP,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE;aAC5B,CAAA;SACF;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAEO,WAAW,CAAC,MAAsB;QACxC,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,EAAE,CAAA;SACV;QACD,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YACvC,MAAM,CAAC,GAAG,EAAE,GAAI,MAAc,EAAE,CAAA;YAChC,IAAI,OAAO,CAAC,CAAC,GAAG,KAAK,QAAQ,EAAE;gBAC7B,OAAO;oBACL,GAAG,CAAC;oBACJ,GAAG,EAAE,IAAI,kBAAQ,CAAC,CAAC,CAAC,GAAG,CAAC;iBACzB,CAAA;aACF;YAC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,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;YAChE,UAAU;SACX,CAAC,CAAA;QACF,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAC5D,CAAC;IACM,KAAK,CAAC,MAAM,CAAC,GAAG,IAA2B;QAChD,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAA;QAC7C,MAAM,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IAC3D,CAAC;IACM,KAAK,CAAC,OAAO;QAClB,MAAM;IACR,CAAC;CACF;AArKD,oCAqKC"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const util_1 = require("util");
|
|
4
|
-
global.TextEncoder = util_1.TextEncoder;
|
|
5
|
-
global.TextDecoder = util_1.TextDecoder;
|
|
6
|
-
const inject_1 = require("@furystack/inject");
|
|
7
|
-
const core_1 = require("@furystack/core");
|
|
8
|
-
const store_manager_helpers_1 = require("./store-manager-helpers");
|
|
9
|
-
const mongo_client_factory_1 = require("./mongo-client-factory");
|
|
10
|
-
const utils_1 = require("@furystack/utils");
|
|
11
|
-
class TestClassWithId {
|
|
12
|
-
}
|
|
13
|
-
let storeCount = 0;
|
|
14
|
-
const mongoDbUrl = process?.env?.MONGODB_URL || 'mongodb://localhost:27017';
|
|
15
|
-
describe('MongoDB Store', () => {
|
|
16
|
-
let dbIdx = 0;
|
|
17
|
-
const getMongoOptions = (injector) => ({
|
|
18
|
-
injector,
|
|
19
|
-
model: core_1.TestClass,
|
|
20
|
-
primaryKey: 'id',
|
|
21
|
-
collection: `furystack-mongo-store-tests-${storeCount++}`,
|
|
22
|
-
db: `furystack-mongo-store-tests-${dbIdx++}`,
|
|
23
|
-
url: mongoDbUrl,
|
|
24
|
-
options: {},
|
|
25
|
-
});
|
|
26
|
-
(0, core_1.createStoreTest)({
|
|
27
|
-
typeName: 'mongodb-store',
|
|
28
|
-
skipStringTests: true,
|
|
29
|
-
createStore: (i) => {
|
|
30
|
-
const mongoOptions = getMongoOptions(i);
|
|
31
|
-
(0, store_manager_helpers_1.useMongoDb)(mongoOptions);
|
|
32
|
-
const store = i.getInstance(core_1.StoreManager).getStoreFor(core_1.TestClass, 'id');
|
|
33
|
-
const oldDispose = i.dispose;
|
|
34
|
-
i.dispose = async () => {
|
|
35
|
-
const client = await i.getInstance(mongo_client_factory_1.MongoClientFactory).getClientFor(mongoOptions.url, mongoOptions.options);
|
|
36
|
-
const db = client.db(mongoOptions.db);
|
|
37
|
-
await db.dropDatabase();
|
|
38
|
-
oldDispose.call(i);
|
|
39
|
-
};
|
|
40
|
-
return store;
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
it('Should retrieve an entity with its id', async () => {
|
|
44
|
-
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
45
|
-
(0, store_manager_helpers_1.useMongoDb)({ ...getMongoOptions(injector), model: TestClassWithId, primaryKey: '_id' });
|
|
46
|
-
const store = injector.getInstance(core_1.StoreManager).getStoreFor(TestClassWithId, '_id');
|
|
47
|
-
const { created } = await store.add({ value: 'value1' });
|
|
48
|
-
expect(typeof created[0]._id).toBe('string');
|
|
49
|
-
const retrieved = await store.get(created[0]._id);
|
|
50
|
-
expect(retrieved).toEqual(created[0]);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
it('Should retrieve more entities with theis ids', async () => {
|
|
54
|
-
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
55
|
-
(0, store_manager_helpers_1.useMongoDb)({ ...getMongoOptions(injector), model: TestClassWithId, primaryKey: '_id' });
|
|
56
|
-
const store = injector.getInstance(core_1.StoreManager).getStoreFor(TestClassWithId, '_id');
|
|
57
|
-
const { created } = await store.add({ value: 'value1' }, { value: 'value2' }, { value: 'value3' });
|
|
58
|
-
const retrieved = await store.find({ filter: { _id: { $in: created.map((c) => c._id) } } });
|
|
59
|
-
expect(retrieved.length).toBe(3);
|
|
60
|
-
expect(retrieved).toEqual(created);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
//# sourceMappingURL=mongodb-store.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb-store.spec.js","sourceRoot":"","sources":["../src/mongodb-store.spec.ts"],"names":[],"mappings":";;AAAA,+BAA+C;AAE/C,MAAM,CAAC,WAAW,GAAG,kBAAW,CAAA;AAChC,MAAM,CAAC,WAAW,GAAG,kBAAkB,CAAA;AAEvC,8CAA4C;AAC5C,0CAA0E;AAC1E,mEAAoD;AACpD,iEAA2D;AAC3D,4CAA6C;AAE7C,MAAM,eAAe;CAGpB;AAED,IAAI,UAAU,GAAG,CAAC,CAAA;AAElB,MAAM,UAAU,GAAG,OAAO,EAAE,GAAG,EAAE,WAAW,IAAI,2BAA2B,CAAA;AAE3E,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,IAAI,KAAK,GAAG,CAAC,CAAA;IAEb,MAAM,eAAe,GAAG,CAAC,QAAkB,EAAE,EAAE,CAAC,CAAC;QAC/C,QAAQ;QACR,KAAK,EAAE,gBAAS;QAChB,UAAU,EAAE,IAAa;QACzB,UAAU,EAAE,+BAA+B,UAAU,EAAE,EAAE;QACzD,EAAE,EAAE,+BAA+B,KAAK,EAAE,EAAE;QAC5C,GAAG,EAAE,UAAU;QACf,OAAO,EAAE,EAAE;KACZ,CAAC,CAAA;IACF,IAAA,sBAAe,EAAC;QACd,QAAQ,EAAE,eAAe;QACzB,eAAe,EAAE,IAAI;QACrB,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE;YACjB,MAAM,YAAY,GAAG,eAAe,CAAC,CAAC,CAAC,CAAA;YACvC,IAAA,kCAAU,EAAC,YAAY,C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
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useMongoDb = void 0;
|
|
4
|
-
const core_1 = require("@furystack/core");
|
|
5
|
-
const mongo_client_factory_1 = require("./mongo-client-factory");
|
|
6
|
-
const mongodb_store_1 = require("./mongodb-store");
|
|
7
|
-
const useMongoDb = ({ injector, model, primaryKey, db, collection, url, options, }) => {
|
|
8
|
-
const clientFactory = injector.getInstance(mongo_client_factory_1.MongoClientFactory);
|
|
9
|
-
const store = new mongodb_store_1.MongodbStore({
|
|
10
|
-
model,
|
|
11
|
-
primaryKey,
|
|
12
|
-
db,
|
|
13
|
-
collection,
|
|
14
|
-
mongoClient: async () => await clientFactory.getClientFor(url, options),
|
|
15
|
-
});
|
|
16
|
-
(0, core_1.addStore)(injector, store);
|
|
17
|
-
};
|
|
18
|
-
exports.useMongoDb = useMongoDb;
|
|
19
|
-
//# sourceMappingURL=store-manager-helpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store-manager-helpers.js","sourceRoot":"","sources":["../src/store-manager-helpers.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAG1C,iEAA2D;AAC3D,mDAA8C;AAEvC,MAAM,UAAU,GAAG,CAAmB,EAC3C,QAAQ,EACR,KAAK,EACL,UAAU,EACV,EAAE,EACF,UAAU,EACV,GAAG,EACH,OAAO,GA+BR,EAAE,EAAE;IACH,MAAM,aAAa,GAAG,QAAQ,CAAC,WAAW,CAAC,yCAAkB,CAAC,CAAA;IAC9D,MAAM,KAAK,GAAG,IAAI,4BAAY,CAAC;QAC7B,KAAK;QACL,UAAU;QACV,EAAE;QACF,UAAU;QACV,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,aAAa,CAAC,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC;KACxE,CAAC,CAAA;IACF,IAAA,eAAQ,EAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;AAC3B,CAAC,CAAA;AAhDY,QAAA,UAAU,cAgDtB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb-store.spec.d.ts","sourceRoot":"","sources":["../src/mongodb-store.spec.ts"],"names":[],"mappings":""}
|