@unchainedshop/mongodb 4.4.0 → 4.5.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/initDb.d.ts +6 -2
- package/lib/initDb.js +15 -10
- package/package.json +5 -5
package/lib/initDb.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { Db } from 'mongodb';
|
|
2
|
-
export declare const startDb: (
|
|
2
|
+
export declare const startDb: (options?: {
|
|
3
|
+
forceInMemory?: boolean;
|
|
4
|
+
}) => Promise<string>;
|
|
3
5
|
export declare const stopDb: () => Promise<void>;
|
|
4
|
-
declare const initDb: (
|
|
6
|
+
declare const initDb: (options?: {
|
|
7
|
+
forceInMemory?: boolean;
|
|
8
|
+
}) => Promise<Db>;
|
|
5
9
|
export { initDb };
|
package/lib/initDb.js
CHANGED
|
@@ -9,18 +9,21 @@ try {
|
|
|
9
9
|
}
|
|
10
10
|
catch {
|
|
11
11
|
}
|
|
12
|
-
export const startDb = async () => {
|
|
12
|
+
export const startDb = async (options) => {
|
|
13
13
|
const { mkdir } = await import('node:fs/promises');
|
|
14
14
|
const { MongoMemoryServer } = await import('mongodb-memory-server');
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const useInMemory = options?.forceInMemory || process.env.NODE_ENV === 'test';
|
|
16
|
+
if (!useInMemory) {
|
|
17
|
+
try {
|
|
18
|
+
await mkdir(`${process.cwd()}/.db`);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
}
|
|
19
22
|
}
|
|
20
23
|
try {
|
|
21
24
|
mongod = MongoMemoryServer.create({
|
|
22
|
-
instance:
|
|
23
|
-
? { dbName: 'test', port: parseInt(PORT, 10) + 1 }
|
|
25
|
+
instance: useInMemory
|
|
26
|
+
? { dbName: 'test', port: parseInt(PORT, 10) + 1, storageEngine: 'ephemeralForTest' }
|
|
24
27
|
: {
|
|
25
28
|
dbPath: `${process.cwd()}/.db`,
|
|
26
29
|
storageEngine: 'wiredTiger',
|
|
@@ -29,7 +32,7 @@ export const startDb = async () => {
|
|
|
29
32
|
});
|
|
30
33
|
const mongoInstance = await mongod;
|
|
31
34
|
if (mongoInstance) {
|
|
32
|
-
return `${mongoInstance.getUri()}${
|
|
35
|
+
return `${mongoInstance.getUri()}${useInMemory ? 'test' : 'unchained'}`;
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
catch {
|
|
@@ -44,8 +47,10 @@ export const stopDb = async () => {
|
|
|
44
47
|
catch {
|
|
45
48
|
}
|
|
46
49
|
};
|
|
47
|
-
const initDb = async () => {
|
|
48
|
-
const url =
|
|
50
|
+
const initDb = async (options) => {
|
|
51
|
+
const url = options?.forceInMemory
|
|
52
|
+
? await startDb({ forceInMemory: true })
|
|
53
|
+
: process.env.MONGO_URL || (await startDb());
|
|
49
54
|
mongoClient = new MongoClient(url, {
|
|
50
55
|
compressors: zstdEnabled ? 'zstd' : undefined,
|
|
51
56
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/mongodb",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "MongoDB provider for unchained platform",
|
|
5
5
|
"main": "lib/mongodb-index.js",
|
|
6
6
|
"types": "lib/mongodb-index.d.ts",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@unchainedshop/utils": "^4.
|
|
36
|
+
"@unchainedshop/utils": "^4.5.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@mongodb-js/zstd": ">=
|
|
40
|
-
"mongodb": ">=
|
|
41
|
-
"mongodb-memory-server": ">=
|
|
39
|
+
"@mongodb-js/zstd": ">= 7 < 8",
|
|
40
|
+
"mongodb": ">= 7 < 8",
|
|
41
|
+
"mongodb-memory-server": ">= 11 < 12"
|
|
42
42
|
},
|
|
43
43
|
"peerDependenciesMeta": {
|
|
44
44
|
"mongodb": {
|