@orion-js/mongodb 3.0.42 → 3.1.0-alpha.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/lib/connect/getMongoConnection.d.ts +1 -0
- package/lib/connect/getMongoConnection.js +3 -1
- package/lib/connect/index.d.ts +2 -2
- package/lib/connect/index.js +2 -1
- package/lib/createCollection/createIndexPromisesTest.d.ts +1 -0
- package/lib/createCollection/createIndexPromisesTest.js +12 -0
- package/lib/createCollection/createIndexesPromise.test.d.ts +1 -1
- package/lib/createCollection/createIndexesPromise.test.js +9 -3
- package/lib/createCollection/index.js +10 -3
- package/lib/types/index.d.ts +6 -0
- package/package.json +3 -3
|
@@ -3,17 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getMongoConnection = void 0;
|
|
6
|
+
exports.getMongoConnection = exports.allConnectionPromises = void 0;
|
|
7
7
|
const mongodb_1 = require("mongodb");
|
|
8
8
|
const connections_1 = require("./connections");
|
|
9
9
|
const getDBName_1 = __importDefault(require("./getDBName"));
|
|
10
10
|
const getMongoURLFromEnv_1 = require("./getMongoURLFromEnv");
|
|
11
|
+
exports.allConnectionPromises = [];
|
|
11
12
|
const getMongoConnection = ({ name, uri }) => {
|
|
12
13
|
uri = uri || (0, getMongoURLFromEnv_1.getMongoURLFromEnv)(name);
|
|
13
14
|
if (connections_1.connections[name])
|
|
14
15
|
return connections_1.connections[name];
|
|
15
16
|
const client = new mongodb_1.MongoClient(uri);
|
|
16
17
|
const connectionPromise = client.connect();
|
|
18
|
+
exports.allConnectionPromises.push(connectionPromise);
|
|
17
19
|
const dbName = (0, getDBName_1.default)(uri);
|
|
18
20
|
const db = client.db(dbName);
|
|
19
21
|
const mongoClient = {
|
package/lib/connect/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { connections } from './connections';
|
|
2
2
|
import { OrionMongoClient } from './connections';
|
|
3
|
-
import { getMongoConnection } from './getMongoConnection';
|
|
4
|
-
export { OrionMongoClient, getMongoConnection, connections };
|
|
3
|
+
import { allConnectionPromises, getMongoConnection } from './getMongoConnection';
|
|
4
|
+
export { OrionMongoClient, getMongoConnection, connections, allConnectionPromises };
|
package/lib/connect/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.connections = exports.getMongoConnection = void 0;
|
|
3
|
+
exports.allConnectionPromises = exports.connections = exports.getMongoConnection = void 0;
|
|
4
4
|
const connections_1 = require("./connections");
|
|
5
5
|
Object.defineProperty(exports, "connections", { enumerable: true, get: function () { return connections_1.connections; } });
|
|
6
6
|
const getMongoConnection_1 = require("./getMongoConnection");
|
|
7
|
+
Object.defineProperty(exports, "allConnectionPromises", { enumerable: true, get: function () { return getMongoConnection_1.allConnectionPromises; } });
|
|
7
8
|
Object.defineProperty(exports, "getMongoConnection", { enumerable: true, get: function () { return getMongoConnection_1.getMongoConnection; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MockTests: import("..").Collection<any>;
|
|
@@ -0,0 +1,12 @@
|
|
|
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.MockTests = void 0;
|
|
7
|
+
const helpers_1 = require("@orion-js/helpers");
|
|
8
|
+
const _1 = __importDefault(require("."));
|
|
9
|
+
exports.MockTests = (0, _1.default)({
|
|
10
|
+
name: (0, helpers_1.generateId)(),
|
|
11
|
+
indexes: [{ keys: { a: 1 }, options: { unique: true } }]
|
|
12
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare const Tests: import("..").Collection<any>;
|
|
@@ -3,18 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Tests = void 0;
|
|
6
7
|
const helpers_1 = require("@orion-js/helpers");
|
|
7
8
|
const _1 = __importDefault(require("."));
|
|
8
|
-
const
|
|
9
|
+
const __1 = require("..");
|
|
10
|
+
jest.mock('./createIndexPromisesTest');
|
|
11
|
+
exports.Tests = (0, _1.default)({
|
|
9
12
|
name: (0, helpers_1.generateId)(),
|
|
10
13
|
indexes: [{ keys: { a: 1 }, options: { unique: true } }]
|
|
11
14
|
});
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
await Promise.all(__1.allConnectionPromises);
|
|
17
|
+
});
|
|
12
18
|
describe('createIndexesPromise', () => {
|
|
13
19
|
it('should correctly handle the promise for tests', async () => {
|
|
14
|
-
const userId = await Tests.insertOne({
|
|
20
|
+
const userId = await exports.Tests.insertOne({
|
|
15
21
|
name: 'Nico'
|
|
16
22
|
});
|
|
17
|
-
const user = await Tests.findOne(userId);
|
|
23
|
+
const user = await exports.Tests.findOne(userId);
|
|
18
24
|
expect(user.name).toBe('Nico');
|
|
19
25
|
});
|
|
20
26
|
it('should be able to close the index handlers on the global config', async () => {
|
|
@@ -65,9 +65,16 @@ const createCollection = (options) => {
|
|
|
65
65
|
collection.loadById = (0, dataLoader_1.loadById)(collection);
|
|
66
66
|
collection.loadOne = (0, dataLoader_1.loadOne)(collection);
|
|
67
67
|
collection.loadMany = (0, dataLoader_1.loadMany)(collection);
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
const createIndexes = async () => {
|
|
69
|
+
const createIndexPromise = (0, createIndexes_1.loadIndexes)(collection);
|
|
70
|
+
exports.createIndexesPromises.push(createIndexPromise);
|
|
71
|
+
collection.createIndexesPromise = createIndexPromise;
|
|
72
|
+
return createIndexPromise;
|
|
73
|
+
};
|
|
74
|
+
collection.createIndexes = createIndexes;
|
|
75
|
+
if (!process.env.DONT_CREATE_INDEXES_AUTOMATICALLY) {
|
|
76
|
+
createIndexes();
|
|
77
|
+
}
|
|
71
78
|
return collection;
|
|
72
79
|
};
|
|
73
80
|
exports.default = createCollection;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -116,6 +116,12 @@ export interface Collection<ModelClass = any> {
|
|
|
116
116
|
loadOne: DataLoader.LoadOne<ModelClass>;
|
|
117
117
|
loadMany: DataLoader.LoadMany<ModelClass>;
|
|
118
118
|
loadById: DataLoader.LoadById<ModelClass>;
|
|
119
|
+
/**
|
|
120
|
+
* Use this function if you are using tests and you pass the
|
|
121
|
+
* env var DONT_CREATE_INDEXES_AUTOMATICALLY and you need to
|
|
122
|
+
* create the indexes for this collection
|
|
123
|
+
*/
|
|
124
|
+
createIndexes: () => Promise<string[]>;
|
|
119
125
|
createIndexesPromise: Promise<string[]>;
|
|
120
126
|
connectionPromise: Promise<MongoDB.MongoClient>;
|
|
121
127
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/mongodb",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.1.0-alpha.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@orion-js/models": "^3.0.38",
|
|
22
22
|
"@orion-js/resolvers": "^3.0.37",
|
|
23
23
|
"@orion-js/schema": "^3.0.37",
|
|
24
|
-
"@orion-js/typed-model": "^3.0.
|
|
24
|
+
"@orion-js/typed-model": "^3.1.0-alpha.0",
|
|
25
25
|
"dataloader": "2.0.0",
|
|
26
26
|
"dot-object": "2.1.4",
|
|
27
27
|
"mongodb": "4.1.4"
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "67abbfa1d2e0a3eed10e20966c656a53652b9d89"
|
|
42
42
|
}
|