@furystack/mongodb-store 4.0.33 → 5.0.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/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mongodb-store.spec.js +12 -12
- package/dist/mongodb-store.spec.js.map +1 -1
- package/dist/{store-manager-extensions.js → store-manager-helpers.js} +7 -6
- package/dist/store-manager-helpers.js.map +1 -0
- package/package.json +11 -12
- package/src/index.ts +1 -1
- package/src/mongodb-store.spec.ts +11 -10
- package/src/store-manager-helpers.ts +55 -0
- package/types/index.d.ts +3 -0
- package/{dist → types}/index.d.ts.map +1 -1
- package/{dist → types}/mongo-client-factory.d.ts +0 -0
- package/{dist → types}/mongo-client-factory.d.ts.map +0 -0
- package/{dist → types}/mongodb-store.d.ts +0 -0
- package/{dist → types}/mongodb-store.d.ts.map +0 -0
- package/types/mongodb-store.spec.d.ts +2 -0
- package/{dist → types}/mongodb-store.spec.d.ts.map +1 -1
- package/types/store-manager-helpers.d.ts +33 -0
- package/types/store-manager-helpers.d.ts.map +1 -0
- package/dist/index.d.ts +0 -3
- package/dist/mongodb-store.spec.d.ts +0 -2
- package/dist/store-manager-extensions.d.ts +0 -39
- package/dist/store-manager-extensions.d.ts.map +0 -1
- package/dist/store-manager-extensions.js.map +0 -1
- package/src/store-manager-extensions.ts +0 -56
package/dist/index.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./mongodb-store"), exports);
|
|
5
|
-
require("./store-manager-
|
|
5
|
+
tslib_1.__exportStar(require("./store-manager-helpers"), exports);
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,0DAA+B;AAC/B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,0DAA+B;AAC/B,kEAAuC"}
|
|
@@ -5,29 +5,29 @@ global.TextEncoder = util_1.TextEncoder;
|
|
|
5
5
|
global.TextDecoder = util_1.TextDecoder;
|
|
6
6
|
const inject_1 = require("@furystack/inject");
|
|
7
7
|
const core_1 = require("@furystack/core");
|
|
8
|
-
const
|
|
9
|
-
const uuid_1 = require("uuid");
|
|
10
|
-
require("./store-manager-extensions");
|
|
8
|
+
const store_manager_helpers_1 = require("./store-manager-helpers");
|
|
11
9
|
const mongo_client_factory_1 = require("./mongo-client-factory");
|
|
12
10
|
const utils_1 = require("@furystack/utils");
|
|
13
11
|
class TestClassWithId {
|
|
14
12
|
}
|
|
13
|
+
let storeCount = 0;
|
|
15
14
|
describe('MongoDB Store', () => {
|
|
16
15
|
let dbIdx = 0;
|
|
17
|
-
const getMongoOptions = () => ({
|
|
18
|
-
|
|
16
|
+
const getMongoOptions = (injector) => ({
|
|
17
|
+
injector,
|
|
18
|
+
model: core_1.TestClass,
|
|
19
19
|
primaryKey: 'id',
|
|
20
|
-
collection: `furystack-mongo-store-tests-${
|
|
20
|
+
collection: `furystack-mongo-store-tests-${storeCount++}`,
|
|
21
21
|
db: `furystack-mongo-store-tests-${dbIdx++}`,
|
|
22
22
|
url: 'mongodb://localhost:27017',
|
|
23
23
|
options: {},
|
|
24
24
|
});
|
|
25
|
-
(0,
|
|
25
|
+
(0, core_1.createStoreTest)({
|
|
26
26
|
typeName: 'mongodb-store',
|
|
27
27
|
createStore: (i) => {
|
|
28
|
-
const mongoOptions = getMongoOptions();
|
|
29
|
-
|
|
30
|
-
const store = i.getInstance(core_1.StoreManager).getStoreFor(
|
|
28
|
+
const mongoOptions = getMongoOptions(i);
|
|
29
|
+
(0, store_manager_helpers_1.useMongoDb)(mongoOptions);
|
|
30
|
+
const store = i.getInstance(core_1.StoreManager).getStoreFor(core_1.TestClass, 'id');
|
|
31
31
|
const oldDispose = i.dispose;
|
|
32
32
|
i.dispose = async () => {
|
|
33
33
|
const client = await i.getInstance(mongo_client_factory_1.MongoClientFactory).getClientFor(mongoOptions.url, mongoOptions.options);
|
|
@@ -40,7 +40,7 @@ describe('MongoDB Store', () => {
|
|
|
40
40
|
});
|
|
41
41
|
it('Should retrieve an entity with its id', async () => {
|
|
42
42
|
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
43
|
-
|
|
43
|
+
(0, store_manager_helpers_1.useMongoDb)({ ...getMongoOptions(injector), model: TestClassWithId, primaryKey: '_id' });
|
|
44
44
|
const store = injector.getInstance(core_1.StoreManager).getStoreFor(TestClassWithId, '_id');
|
|
45
45
|
const { created } = await store.add({ value: 'value1' });
|
|
46
46
|
expect(typeof created[0]._id).toBe('string');
|
|
@@ -50,7 +50,7 @@ describe('MongoDB Store', () => {
|
|
|
50
50
|
});
|
|
51
51
|
it('Should retrieve more entities with theis ids', async () => {
|
|
52
52
|
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
53
|
-
|
|
53
|
+
(0, store_manager_helpers_1.useMongoDb)({ ...getMongoOptions(injector), model: TestClassWithId, primaryKey: '_id' });
|
|
54
54
|
const store = injector.getInstance(core_1.StoreManager).getStoreFor(TestClassWithId, '_id');
|
|
55
55
|
const { created } = await store.add({ value: 'value1' }, { value: 'value2' }, { value: 'value3' });
|
|
56
56
|
const retrieved = await store.find({ filter: { _id: { $in: created.map((c) => c._id) } } });
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
1
|
+
{"version":3,"file":"mongodb-store.spec.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AC,EAAE,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAA;YACvF,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,CAAC,mBAAY,CAAC,CAAC,WAAW,CAAC,eAAe,EAAE,KAAK,CAAC,CAAA;YACpF,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAA;YAClG,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;YAC3F,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YAChC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QACpC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.useMongoDb = void 0;
|
|
4
|
+
const core_1 = require("@furystack/core");
|
|
4
5
|
const mongo_client_factory_1 = require("./mongo-client-factory");
|
|
5
6
|
const mongodb_store_1 = require("./mongodb-store");
|
|
6
|
-
|
|
7
|
-
const clientFactory =
|
|
7
|
+
const useMongoDb = ({ injector, model, primaryKey, db, collection, url, options, }) => {
|
|
8
|
+
const clientFactory = injector.getInstance(mongo_client_factory_1.MongoClientFactory);
|
|
8
9
|
const store = new mongodb_store_1.MongodbStore({
|
|
9
10
|
model,
|
|
10
11
|
primaryKey,
|
|
@@ -12,7 +13,7 @@ store_manager_1.StoreManager.prototype.useMongoDb = function ({ model, primaryKe
|
|
|
12
13
|
collection,
|
|
13
14
|
mongoClient: async () => await clientFactory.getClientFor(url, options),
|
|
14
15
|
});
|
|
15
|
-
|
|
16
|
-
return this;
|
|
16
|
+
(0, core_1.addStore)(injector, store);
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
exports.useMongoDb = useMongoDb;
|
|
19
|
+
//# 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,0CAA0C;AAG1C,iEAA2D;AAC3D,mDAA8C;AAEvC,MAAM,UAAU,GAAG,CAAI,EAC5B,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"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@furystack/mongodb-store",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "MongoDB Store implementation for FuryStack",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
8
|
+
"types",
|
|
8
9
|
"src"
|
|
9
10
|
],
|
|
10
11
|
"repository": {
|
|
@@ -28,20 +29,18 @@
|
|
|
28
29
|
},
|
|
29
30
|
"homepage": "https://github.com/furystack/furystack",
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@furystack/core": "^
|
|
32
|
-
"@furystack/inject": "^
|
|
33
|
-
"@furystack/logging": "^
|
|
34
|
-
"@furystack/utils": "^
|
|
35
|
-
"mongodb": "^4.
|
|
32
|
+
"@furystack/core": "^11.0.1",
|
|
33
|
+
"@furystack/inject": "^6.0.1",
|
|
34
|
+
"@furystack/logging": "^3.0.1",
|
|
35
|
+
"@furystack/utils": "^3.0.1",
|
|
36
|
+
"mongodb": "^4.5.0",
|
|
36
37
|
"semaphore-async-await": "^1.5.1",
|
|
37
|
-
"tslib": "^2.
|
|
38
|
+
"tslib": "^2.4.0"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@types/jest": "^27.
|
|
41
|
-
"@types/node": "^17.0.
|
|
42
|
-
"@types/uuid": "^8.3.4",
|
|
43
|
-
"uuid": "^8.3.2"
|
|
41
|
+
"@types/jest": "^27.5.0",
|
|
42
|
+
"@types/node": "^17.0.31"
|
|
44
43
|
},
|
|
45
|
-
"typings": "./
|
|
44
|
+
"typings": "./types/index.d.ts",
|
|
46
45
|
"gitHead": "1045d854bfd8c475b7035471d130d401417a2321"
|
|
47
46
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './mongodb-store'
|
|
2
|
-
|
|
2
|
+
export * from './store-manager-helpers'
|
|
@@ -4,10 +4,8 @@ global.TextEncoder = TextEncoder
|
|
|
4
4
|
global.TextDecoder = TextDecoder as any
|
|
5
5
|
|
|
6
6
|
import { Injector } from '@furystack/inject'
|
|
7
|
-
import { StoreManager } from '@furystack/core'
|
|
8
|
-
import {
|
|
9
|
-
import { v4 } from 'uuid'
|
|
10
|
-
import './store-manager-extensions'
|
|
7
|
+
import { StoreManager, TestClass, createStoreTest } from '@furystack/core'
|
|
8
|
+
import { useMongoDb } from './store-manager-helpers'
|
|
11
9
|
import { MongoClientFactory } from './mongo-client-factory'
|
|
12
10
|
import { usingAsync } from '@furystack/utils'
|
|
13
11
|
|
|
@@ -16,12 +14,15 @@ class TestClassWithId {
|
|
|
16
14
|
value!: string
|
|
17
15
|
}
|
|
18
16
|
|
|
17
|
+
let storeCount = 0
|
|
18
|
+
|
|
19
19
|
describe('MongoDB Store', () => {
|
|
20
20
|
let dbIdx = 0
|
|
21
|
-
const getMongoOptions = () => ({
|
|
21
|
+
const getMongoOptions = (injector: Injector) => ({
|
|
22
|
+
injector,
|
|
22
23
|
model: TestClass,
|
|
23
24
|
primaryKey: 'id' as const,
|
|
24
|
-
collection: `furystack-mongo-store-tests-${
|
|
25
|
+
collection: `furystack-mongo-store-tests-${storeCount++}`,
|
|
25
26
|
db: `furystack-mongo-store-tests-${dbIdx++}`,
|
|
26
27
|
url: 'mongodb://localhost:27017',
|
|
27
28
|
options: {},
|
|
@@ -29,8 +30,8 @@ describe('MongoDB Store', () => {
|
|
|
29
30
|
createStoreTest({
|
|
30
31
|
typeName: 'mongodb-store',
|
|
31
32
|
createStore: (i) => {
|
|
32
|
-
const mongoOptions = getMongoOptions()
|
|
33
|
-
|
|
33
|
+
const mongoOptions = getMongoOptions(i)
|
|
34
|
+
useMongoDb(mongoOptions)
|
|
34
35
|
const store = i.getInstance(StoreManager).getStoreFor(TestClass, 'id')
|
|
35
36
|
const oldDispose = i.dispose
|
|
36
37
|
i.dispose = async () => {
|
|
@@ -45,7 +46,7 @@ describe('MongoDB Store', () => {
|
|
|
45
46
|
|
|
46
47
|
it('Should retrieve an entity with its id', async () => {
|
|
47
48
|
await usingAsync(new Injector(), async (injector) => {
|
|
48
|
-
|
|
49
|
+
useMongoDb({ ...getMongoOptions(injector), model: TestClassWithId, primaryKey: '_id' })
|
|
49
50
|
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id')
|
|
50
51
|
const { created } = await store.add({ value: 'value1' })
|
|
51
52
|
|
|
@@ -58,7 +59,7 @@ describe('MongoDB Store', () => {
|
|
|
58
59
|
|
|
59
60
|
it('Should retrieve more entities with theis ids', async () => {
|
|
60
61
|
await usingAsync(new Injector(), async (injector) => {
|
|
61
|
-
|
|
62
|
+
useMongoDb({ ...getMongoOptions(injector), model: TestClassWithId, primaryKey: '_id' })
|
|
62
63
|
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id')
|
|
63
64
|
const { created } = await store.add({ value: 'value1' }, { value: 'value2' }, { value: 'value3' })
|
|
64
65
|
const retrieved = await store.find({ filter: { _id: { $in: created.map((c) => c._id) } } })
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { addStore } from '@furystack/core'
|
|
2
|
+
import { Constructable, Injector } from '@furystack/inject'
|
|
3
|
+
import { MongoClientOptions } from 'mongodb'
|
|
4
|
+
import { MongoClientFactory } from './mongo-client-factory'
|
|
5
|
+
import { MongodbStore } from './mongodb-store'
|
|
6
|
+
|
|
7
|
+
export const useMongoDb = <T>({
|
|
8
|
+
injector,
|
|
9
|
+
model,
|
|
10
|
+
primaryKey,
|
|
11
|
+
db,
|
|
12
|
+
collection,
|
|
13
|
+
url,
|
|
14
|
+
options,
|
|
15
|
+
}: {
|
|
16
|
+
/**
|
|
17
|
+
* The Injector instance to use
|
|
18
|
+
*/
|
|
19
|
+
injector: Injector
|
|
20
|
+
/**
|
|
21
|
+
* The constructable model class
|
|
22
|
+
*/
|
|
23
|
+
model: Constructable<T>
|
|
24
|
+
/**
|
|
25
|
+
* The name of the Primary Key property
|
|
26
|
+
*/
|
|
27
|
+
primaryKey: keyof T
|
|
28
|
+
/**
|
|
29
|
+
* Url of the MongoDb repository
|
|
30
|
+
*/
|
|
31
|
+
url: string
|
|
32
|
+
/**
|
|
33
|
+
* MongoDb Database name
|
|
34
|
+
*/
|
|
35
|
+
db: string
|
|
36
|
+
/**
|
|
37
|
+
* MongoDb Collection name
|
|
38
|
+
*/
|
|
39
|
+
collection: string
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Optional options for the MongoDb Client
|
|
43
|
+
*/
|
|
44
|
+
options?: MongoClientOptions
|
|
45
|
+
}) => {
|
|
46
|
+
const clientFactory = injector.getInstance(MongoClientFactory)
|
|
47
|
+
const store = new MongodbStore({
|
|
48
|
+
model,
|
|
49
|
+
primaryKey,
|
|
50
|
+
db,
|
|
51
|
+
collection,
|
|
52
|
+
mongoClient: async () => await clientFactory.getClientFor(url, options),
|
|
53
|
+
})
|
|
54
|
+
addStore(injector, store)
|
|
55
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,
|
|
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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb-store.spec.d.ts","sourceRoot":"","sources":["../src/mongodb-store.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mongodb-store.spec.d.ts","sourceRoot":"","sources":["../src/mongodb-store.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Constructable, Injector } from '@furystack/inject';
|
|
2
|
+
import { MongoClientOptions } from 'mongodb';
|
|
3
|
+
export declare const useMongoDb: <T>({ injector, model, primaryKey, db, collection, url, options, }: {
|
|
4
|
+
/**
|
|
5
|
+
* The Injector instance to use
|
|
6
|
+
*/
|
|
7
|
+
injector: Injector;
|
|
8
|
+
/**
|
|
9
|
+
* The constructable model class
|
|
10
|
+
*/
|
|
11
|
+
model: Constructable<T>;
|
|
12
|
+
/**
|
|
13
|
+
* The name of the Primary Key property
|
|
14
|
+
*/
|
|
15
|
+
primaryKey: keyof T;
|
|
16
|
+
/**
|
|
17
|
+
* Url of the MongoDb repository
|
|
18
|
+
*/
|
|
19
|
+
url: string;
|
|
20
|
+
/**
|
|
21
|
+
* MongoDb Database name
|
|
22
|
+
*/
|
|
23
|
+
db: string;
|
|
24
|
+
/**
|
|
25
|
+
* MongoDb Collection name
|
|
26
|
+
*/
|
|
27
|
+
collection: string;
|
|
28
|
+
/**
|
|
29
|
+
* Optional options for the MongoDb Client
|
|
30
|
+
*/
|
|
31
|
+
options?: MongoClientOptions | undefined;
|
|
32
|
+
}) => void;
|
|
33
|
+
//# sourceMappingURL=store-manager-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-manager-helpers.d.ts","sourceRoot":"","sources":["../src/store-manager-helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAI5C,eAAO,MAAM,UAAU;IASrB;;OAEG;cACO,QAAQ;IAClB;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;SACE,MAAM;IACX;;OAEG;QACC,MAAM;IACV;;OAEG;gBACS,MAAM;IAElB;;OAEG;;UAYJ,CAAA"}
|
package/dist/index.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Constructable } from '@furystack/inject';
|
|
2
|
-
import { MongoClientOptions } from 'mongodb';
|
|
3
|
-
declare module '@furystack/core/dist/store-manager' {
|
|
4
|
-
/**
|
|
5
|
-
* Defines an extended Injector instance
|
|
6
|
-
*/
|
|
7
|
-
interface StoreManager {
|
|
8
|
-
/**
|
|
9
|
-
* Registers a MongoDb store to the StoreManager instance with the provided model.
|
|
10
|
-
*/
|
|
11
|
-
useMongoDb: <T>(options: {
|
|
12
|
-
/**
|
|
13
|
-
* The constructable model class
|
|
14
|
-
*/
|
|
15
|
-
model: Constructable<T>;
|
|
16
|
-
/**
|
|
17
|
-
* The name of the Primary Key property
|
|
18
|
-
*/
|
|
19
|
-
primaryKey: keyof T;
|
|
20
|
-
/**
|
|
21
|
-
* Url of the MongoDb repository
|
|
22
|
-
*/
|
|
23
|
-
url: string;
|
|
24
|
-
/**
|
|
25
|
-
* MongoDb Database name
|
|
26
|
-
*/
|
|
27
|
-
db: string;
|
|
28
|
-
/**
|
|
29
|
-
* MongoDb Collection name
|
|
30
|
-
*/
|
|
31
|
-
collection: string;
|
|
32
|
-
/**
|
|
33
|
-
* Optional options for the MongoDb Client
|
|
34
|
-
*/
|
|
35
|
-
options?: MongoClientOptions;
|
|
36
|
-
}) => this;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=store-manager-extensions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store-manager-extensions.d.ts","sourceRoot":"","sources":["../src/store-manager-extensions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAI5C,OAAO,QAAQ,oCAAoC,CAAC;IAClD;;OAEG;IACH,UAAU,YAAY;QACpB;;WAEG;QACH,UAAU,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE;YACvB;;eAEG;YACH,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;YACvB;;eAEG;YACH,UAAU,EAAE,MAAM,CAAC,CAAA;YACnB;;eAEG;YACH,GAAG,EAAE,MAAM,CAAA;YACX;;eAEG;YACH,EAAE,EAAE,MAAM,CAAA;YACV;;eAEG;YACH,UAAU,EAAE,MAAM,CAAA;YAElB;;eAEG;YACH,OAAO,CAAC,EAAE,kBAAkB,CAAA;SAC7B,KAAK,IAAI,CAAA;KACX;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store-manager-extensions.js","sourceRoot":"","sources":["../src/store-manager-extensions.ts"],"names":[],"mappings":";;AAAA,sEAAiE;AAGjE,iEAA2D;AAC3D,mDAA8C;AAwC9C,4BAAY,CAAC,SAAS,CAAC,UAAU,GAAG,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE;IAC/F,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,yCAAkB,CAAC,CAAA;IACnE,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,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACpB,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { StoreManager } from '@furystack/core/dist/store-manager'
|
|
2
|
-
import { Constructable } from '@furystack/inject'
|
|
3
|
-
import { MongoClientOptions } from 'mongodb'
|
|
4
|
-
import { MongoClientFactory } from './mongo-client-factory'
|
|
5
|
-
import { MongodbStore } from './mongodb-store'
|
|
6
|
-
|
|
7
|
-
declare module '@furystack/core/dist/store-manager' {
|
|
8
|
-
/**
|
|
9
|
-
* Defines an extended Injector instance
|
|
10
|
-
*/
|
|
11
|
-
interface StoreManager {
|
|
12
|
-
/**
|
|
13
|
-
* Registers a MongoDb store to the StoreManager instance with the provided model.
|
|
14
|
-
*/
|
|
15
|
-
useMongoDb: <T>(options: {
|
|
16
|
-
/**
|
|
17
|
-
* The constructable model class
|
|
18
|
-
*/
|
|
19
|
-
model: Constructable<T>
|
|
20
|
-
/**
|
|
21
|
-
* The name of the Primary Key property
|
|
22
|
-
*/
|
|
23
|
-
primaryKey: keyof T
|
|
24
|
-
/**
|
|
25
|
-
* Url of the MongoDb repository
|
|
26
|
-
*/
|
|
27
|
-
url: string
|
|
28
|
-
/**
|
|
29
|
-
* MongoDb Database name
|
|
30
|
-
*/
|
|
31
|
-
db: string
|
|
32
|
-
/**
|
|
33
|
-
* MongoDb Collection name
|
|
34
|
-
*/
|
|
35
|
-
collection: string
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Optional options for the MongoDb Client
|
|
39
|
-
*/
|
|
40
|
-
options?: MongoClientOptions
|
|
41
|
-
}) => this
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
StoreManager.prototype.useMongoDb = function ({ model, primaryKey, db, collection, url, options }) {
|
|
46
|
-
const clientFactory = this.injector.getInstance(MongoClientFactory)
|
|
47
|
-
const store = new MongodbStore({
|
|
48
|
-
model,
|
|
49
|
-
primaryKey,
|
|
50
|
-
db,
|
|
51
|
-
collection,
|
|
52
|
-
mongoClient: async () => await clientFactory.getClientFor(url, options),
|
|
53
|
-
})
|
|
54
|
-
this.addStore(store)
|
|
55
|
-
return this
|
|
56
|
-
}
|