@furystack/mongodb-store 7.0.0 → 7.0.2
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/esm/index.d.ts +3 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +3 -0
- package/esm/index.js.map +1 -0
- package/esm/mongo-client-factory.js +34 -0
- package/esm/mongo-client-factory.js.map +1 -0
- package/esm/mongodb-store.js +142 -0
- package/esm/mongodb-store.js.map +1 -0
- package/esm/store-manager-helpers.js +15 -0
- package/esm/store-manager-helpers.js.map +1 -0
- package/package.json +7 -16
- package/src/index.ts +2 -2
- package/src/store-manager-helpers.ts +2 -2
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/{types → esm}/mongo-client-factory.d.ts +0 -0
- /package/{types → esm}/mongo-client-factory.d.ts.map +0 -0
- /package/{types → esm}/mongodb-store.d.ts +0 -0
- /package/{types → esm}/mongodb-store.d.ts.map +0 -0
- /package/{types → esm}/store-manager-helpers.d.ts +0 -0
- /package/{types → esm}/store-manager-helpers.d.ts.map +0 -0
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,4BAA4B,CAAA"}
|
package/esm/index.js
ADDED
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,4BAA4B,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Injectable } from '@furystack/inject';
|
|
8
|
+
import { MongoClient } from 'mongodb';
|
|
9
|
+
/**
|
|
10
|
+
* Factory for instantiating MongoDb clients
|
|
11
|
+
*/
|
|
12
|
+
let MongoClientFactory = class MongoClientFactory {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.connections = new Map();
|
|
15
|
+
}
|
|
16
|
+
async dispose() {
|
|
17
|
+
await Promise.all([...this.connections.values()].map((c) => c.close(true)));
|
|
18
|
+
this.connections.clear();
|
|
19
|
+
}
|
|
20
|
+
async getClientFor(url, options) {
|
|
21
|
+
const existing = this.connections.get(url);
|
|
22
|
+
if (existing) {
|
|
23
|
+
return existing;
|
|
24
|
+
}
|
|
25
|
+
const client = new MongoClient(url, options);
|
|
26
|
+
this.connections.set(url, client);
|
|
27
|
+
return client;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
MongoClientFactory = __decorate([
|
|
31
|
+
Injectable({ lifetime: 'singleton' })
|
|
32
|
+
], MongoClientFactory);
|
|
33
|
+
export { MongoClientFactory };
|
|
34
|
+
//# sourceMappingURL=mongo-client-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo-client-factory.js","sourceRoot":"","sources":["../src/mongo-client-factory.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;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,WAAW,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,UAAU,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;GACzB,kBAAkB,CAkB9B;SAlBY,kBAAkB"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
import { Lock } from 'semaphore-async-await';
|
|
3
|
+
/**
|
|
4
|
+
* TypeORM Store implementation for FuryStack
|
|
5
|
+
*/
|
|
6
|
+
export class MongodbStore {
|
|
7
|
+
createIdFilter(...values) {
|
|
8
|
+
return {
|
|
9
|
+
[this.primaryKey]: {
|
|
10
|
+
$in: this.primaryKey === '_id' ? values.map((value) => new ObjectId(value)) : values,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
stringifyResultId(item) {
|
|
15
|
+
if (this.primaryKey === '_id' && item._id instanceof ObjectId) {
|
|
16
|
+
return {
|
|
17
|
+
...item,
|
|
18
|
+
_id: item._id.toHexString(),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return item;
|
|
22
|
+
}
|
|
23
|
+
parseFilter(filter) {
|
|
24
|
+
if (!filter) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
if (Object.keys(filter).includes('_id')) {
|
|
28
|
+
const f = { ...filter };
|
|
29
|
+
if (typeof f._id === 'string') {
|
|
30
|
+
return {
|
|
31
|
+
...f,
|
|
32
|
+
_id: new ObjectId(f._id),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (typeof f._id === 'object') {
|
|
36
|
+
if (f._id.$eq) {
|
|
37
|
+
f._id.$eq = new ObjectId(f._id.$eq);
|
|
38
|
+
}
|
|
39
|
+
if (f._id.$in && f._id.$in instanceof Array) {
|
|
40
|
+
f._id.$in = f._id.$in.map((id) => new ObjectId(id));
|
|
41
|
+
}
|
|
42
|
+
if (f._id.$nin && f._id.$nin instanceof Array) {
|
|
43
|
+
f._id.$nin = f._id.$nin.map((id) => new ObjectId(id));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return f;
|
|
47
|
+
}
|
|
48
|
+
return filter;
|
|
49
|
+
}
|
|
50
|
+
async getCollection() {
|
|
51
|
+
if (this.collection) {
|
|
52
|
+
return this.collection;
|
|
53
|
+
}
|
|
54
|
+
await this.initLock.acquire();
|
|
55
|
+
if (this.collection) {
|
|
56
|
+
return this.collection;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const client = await this.options.mongoClient();
|
|
60
|
+
const collection = client.db(this.options.db).collection(this.options.collection);
|
|
61
|
+
if (this.primaryKey !== '_id') {
|
|
62
|
+
await collection.createIndex({ [this.primaryKey]: 1 }, { unique: true });
|
|
63
|
+
}
|
|
64
|
+
this.collection = collection;
|
|
65
|
+
return collection;
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
this.initLock.release();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
constructor(options) {
|
|
72
|
+
this.options = options;
|
|
73
|
+
this.initLock = new Lock();
|
|
74
|
+
this.primaryKey = options.primaryKey;
|
|
75
|
+
this.model = options.model;
|
|
76
|
+
}
|
|
77
|
+
async add(...entries) {
|
|
78
|
+
const collection = await this.getCollection();
|
|
79
|
+
const result = await collection.insertMany(entries.map((e) => ({ ...e })));
|
|
80
|
+
return {
|
|
81
|
+
created: this.primaryKey === '_id'
|
|
82
|
+
? Object.values(result.insertedIds).map((insertedId, index) => this.stringifyResultId({ _id: insertedId, ...entries[index] }))
|
|
83
|
+
: Object.values(result.insertedIds).map((insertedId, index) => {
|
|
84
|
+
const entity = { _id: insertedId, ...entries[index] };
|
|
85
|
+
const { _id, ...r } = entity;
|
|
86
|
+
return r;
|
|
87
|
+
}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async update(id, data) {
|
|
91
|
+
const collection = await this.getCollection();
|
|
92
|
+
const updateResult = await collection.updateOne(this.createIdFilter(id), { $set: data });
|
|
93
|
+
if (updateResult.matchedCount < 1) {
|
|
94
|
+
throw Error(`Entity not found with id '${id}', cannot update!`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async count(filter) {
|
|
98
|
+
const collection = await this.getCollection();
|
|
99
|
+
return await collection.countDocuments(this.parseFilter(filter), {});
|
|
100
|
+
}
|
|
101
|
+
async find(filter) {
|
|
102
|
+
const collection = await this.getCollection();
|
|
103
|
+
const sort = filter.order
|
|
104
|
+
? Object.fromEntries([
|
|
105
|
+
...Object.keys(filter.order).map((key) => [
|
|
106
|
+
key,
|
|
107
|
+
filter.order[key] === 'ASC' ? 1 : -1,
|
|
108
|
+
]),
|
|
109
|
+
])
|
|
110
|
+
: {};
|
|
111
|
+
const result = await collection
|
|
112
|
+
.find(this.parseFilter(filter.filter))
|
|
113
|
+
.project(this.getProjection(filter.select))
|
|
114
|
+
.skip(filter.skip || 0)
|
|
115
|
+
.limit(filter.top || Number.MAX_SAFE_INTEGER)
|
|
116
|
+
.sort(sort)
|
|
117
|
+
.toArray();
|
|
118
|
+
return result.map((entity) => this.stringifyResultId(entity));
|
|
119
|
+
}
|
|
120
|
+
getProjection(fields) {
|
|
121
|
+
return {
|
|
122
|
+
...(this.primaryKey !== '_id' ? { _id: 0 } : {}),
|
|
123
|
+
...(fields ? Object.fromEntries(fields.map((field) => [field, 1])) : {}),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
async get(key, select) {
|
|
127
|
+
const collection = await this.getCollection();
|
|
128
|
+
const projection = this.getProjection(select);
|
|
129
|
+
const result = await collection.findOne(this.createIdFilter(key), {
|
|
130
|
+
projection,
|
|
131
|
+
});
|
|
132
|
+
return result ? this.stringifyResultId(result) : undefined;
|
|
133
|
+
}
|
|
134
|
+
async remove(...keys) {
|
|
135
|
+
const collection = await this.getCollection();
|
|
136
|
+
await collection.deleteMany(this.createIdFilter(...keys));
|
|
137
|
+
}
|
|
138
|
+
async dispose() {
|
|
139
|
+
/** */
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=mongodb-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongodb-store.js","sourceRoot":"","sources":["../src/mongodb-store.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAE5C;;GAEG;AACH,MAAM,OAAO,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,QAAQ,CAAC,KAAY,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM;aAC5F;SACW,CAAA;IAChB,CAAC;IAEO,iBAAiB,CA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;IAEO,aAAa,CAAC,MAAuB;QAC3C,OAAO;YACL,GAAG,CAAC,IAAI,CAAC,UAAU,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAChD,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;SACzE,CAAA;IACH,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,GAAmB,EAAE,MAAuB;QAC3D,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAA;QAC7C,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAC7C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { addStore } from '@furystack/core';
|
|
2
|
+
import { MongoClientFactory } from './mongo-client-factory.js';
|
|
3
|
+
import { MongodbStore } from './mongodb-store.js';
|
|
4
|
+
export const useMongoDb = ({ injector, model, primaryKey, db, collection, url, options, }) => {
|
|
5
|
+
const clientFactory = injector.getInstance(MongoClientFactory);
|
|
6
|
+
const store = new MongodbStore({
|
|
7
|
+
model,
|
|
8
|
+
primaryKey,
|
|
9
|
+
db,
|
|
10
|
+
collection,
|
|
11
|
+
mongoClient: async () => await clientFactory.getClientFor(url, options),
|
|
12
|
+
});
|
|
13
|
+
addStore(injector, store);
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=store-manager-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-manager-helpers.js","sourceRoot":"","sources":["../src/store-manager-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAG1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,MAAM,CAAC,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,kBAAkB,CAAC,CAAA;IAC9D,MAAM,KAAK,GAAG,IAAI,YAAY,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,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;AAC3B,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@furystack/mongodb-store",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.2",
|
|
4
4
|
"description": "MongoDB Store implementation for FuryStack",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -8,20 +8,11 @@
|
|
|
8
8
|
},
|
|
9
9
|
"exports": {
|
|
10
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
|
-
]
|
|
11
|
+
"import": "./esm/index.js"
|
|
21
12
|
}
|
|
22
13
|
},
|
|
23
14
|
"files": [
|
|
24
|
-
"
|
|
15
|
+
"esm",
|
|
25
16
|
"types",
|
|
26
17
|
"src"
|
|
27
18
|
],
|
|
@@ -46,14 +37,14 @@
|
|
|
46
37
|
},
|
|
47
38
|
"homepage": "https://github.com/furystack/furystack",
|
|
48
39
|
"dependencies": {
|
|
49
|
-
"@furystack/core": "^12.0.
|
|
50
|
-
"@furystack/inject": "^8.0.
|
|
51
|
-
"@furystack/utils": "^4.0.
|
|
40
|
+
"@furystack/core": "^12.0.2",
|
|
41
|
+
"@furystack/inject": "^8.0.2",
|
|
42
|
+
"@furystack/utils": "^4.0.2",
|
|
52
43
|
"mongodb": "5.3.0",
|
|
53
44
|
"semaphore-async-await": "^1.5.1"
|
|
54
45
|
},
|
|
55
46
|
"devDependencies": {
|
|
56
|
-
"@types/node": "^18.
|
|
47
|
+
"@types/node": "^18.16.2",
|
|
57
48
|
"typescript": "^5.0.4",
|
|
58
49
|
"vitest": "^0.30.1"
|
|
59
50
|
},
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './mongodb-store'
|
|
2
|
-
export * from './store-manager-helpers'
|
|
1
|
+
export * from './mongodb-store.js'
|
|
2
|
+
export * from './store-manager-helpers.js'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { addStore } from '@furystack/core'
|
|
2
2
|
import type { Constructable, Injector } from '@furystack/inject'
|
|
3
3
|
import type { MongoClientOptions } from 'mongodb'
|
|
4
|
-
import { MongoClientFactory } from './mongo-client-factory'
|
|
5
|
-
import { MongodbStore } from './mongodb-store'
|
|
4
|
+
import { MongoClientFactory } from './mongo-client-factory.js'
|
|
5
|
+
import { MongodbStore } from './mongodb-store.js'
|
|
6
6
|
|
|
7
7
|
export const useMongoDb = <T extends object>({
|
|
8
8
|
injector,
|
package/types/index.d.ts
DELETED
package/types/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,yBAAyB,CAAA"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|