@sprucelabs/data-stores 8.0.13 → 8.0.17
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/build/databases/MongoDatabase.js +1 -1
- package/build/esm/databases/MongoDatabase.js +1 -1
- package/build/esm/fixtures/DatabaseFixture.d.ts +0 -3
- package/build/esm/fixtures/DatabaseFixture.js +18 -45
- package/build/esm/tests/AbstractDatabaseTest.js +1 -1
- package/build/fixtures/DatabaseFixture.d.ts +0 -3
- package/build/fixtures/DatabaseFixture.js +18 -45
- package/build/tests/AbstractDatabaseTest.js +1 -1
- package/package.json +6 -6
|
@@ -36,7 +36,7 @@ class MongoDatabase {
|
|
|
36
36
|
this.mongo = new mongodb_1.MongoClient(url, Object.assign(Object.assign({}, (rest || {})), { serverSelectionTimeoutMS: 5000 }));
|
|
37
37
|
}
|
|
38
38
|
catch (err) {
|
|
39
|
-
if (err.message.includes('Invalid
|
|
39
|
+
if (err.message.includes('Invalid scheme')) {
|
|
40
40
|
throw new SpruceError_1.default({ code: 'INVALID_DB_CONNECTION_STRING' });
|
|
41
41
|
}
|
|
42
42
|
throw err;
|
|
@@ -39,7 +39,7 @@ export default class MongoDatabase {
|
|
|
39
39
|
this.mongo = new MongoClient(url, Object.assign(Object.assign({}, (rest || {})), { serverSelectionTimeoutMS: 5000 }));
|
|
40
40
|
}
|
|
41
41
|
catch (err) {
|
|
42
|
-
if (err.message.includes('Invalid
|
|
42
|
+
if (err.message.includes('Invalid scheme')) {
|
|
43
43
|
throw new SpruceError({ code: 'INVALID_DB_CONNECTION_STRING' });
|
|
44
44
|
}
|
|
45
45
|
throw err;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { Database } from '../types/database.types';
|
|
2
2
|
export interface DatabaseFixtureOptions {
|
|
3
|
-
shouldUseInMemoryDatabase?: boolean;
|
|
4
3
|
dbConnectionString?: string;
|
|
5
4
|
dbName?: string;
|
|
6
5
|
}
|
|
7
6
|
export default class DatabaseFixture {
|
|
8
|
-
private shouldUseInMemoryDatabase;
|
|
9
7
|
private static dbCount;
|
|
10
8
|
private dbName?;
|
|
11
9
|
private static activeDatabases;
|
|
12
10
|
private dbConnectionString?;
|
|
13
11
|
private static defaultOptions?;
|
|
14
12
|
constructor(options?: DatabaseFixtureOptions);
|
|
15
|
-
private determineInMemoryDatabase;
|
|
16
13
|
connectToDatabase(): Promise<Database>;
|
|
17
14
|
private static connect;
|
|
18
15
|
static setDefaultConnectOptions(options: DatabaseFixtureOptions): void;
|
|
@@ -10,63 +10,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { SchemaError } from '@sprucelabs/schema';
|
|
11
11
|
import { MONGO_TEST_URI } from '../databases/MongoDatabase.js';
|
|
12
12
|
import DatabaseFactory from '../factories/DatabaseFactory.js';
|
|
13
|
+
const MEMORY = 'memory://';
|
|
13
14
|
export default class DatabaseFixture {
|
|
14
15
|
constructor(options) {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
if (mixed === null || mixed === void 0 ? void 0 : mixed.dbName) {
|
|
20
|
-
unexpected.push('dbName');
|
|
21
|
-
}
|
|
22
|
-
if (mixed === null || mixed === void 0 ? void 0 : mixed.dbConnectionString) {
|
|
23
|
-
unexpected.push('dbConnectionString');
|
|
24
|
-
}
|
|
25
|
-
if (unexpected.length > 0) {
|
|
26
|
-
throw new SchemaError({
|
|
27
|
-
code: 'UNEXPECTED_PARAMETERS',
|
|
28
|
-
parameters: unexpected,
|
|
29
|
-
friendlyMessage: `You can't pass database connection settings if you are using an in memory database.`,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
16
|
+
const { dbConnectionString = MEMORY, dbName } = Object.assign(Object.assign({}, DatabaseFixture.defaultOptions), options);
|
|
17
|
+
const missing = [];
|
|
18
|
+
if (!dbConnectionString) {
|
|
19
|
+
missing.push('dbConnectionString');
|
|
32
20
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (!(mixed === null || mixed === void 0 ? void 0 : mixed.dbName)) {
|
|
36
|
-
missing.push('dbName');
|
|
37
|
-
}
|
|
38
|
-
if (!(mixed === null || mixed === void 0 ? void 0 : mixed.dbConnectionString)) {
|
|
39
|
-
missing.push('dbConnectionString');
|
|
40
|
-
}
|
|
41
|
-
if (missing.length > 0) {
|
|
42
|
-
throw new SchemaError({
|
|
43
|
-
code: 'MISSING_PARAMETERS',
|
|
44
|
-
parameters: missing,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
this.dbName = mixed === null || mixed === void 0 ? void 0 : mixed.dbName;
|
|
48
|
-
this.dbConnectionString = mixed === null || mixed === void 0 ? void 0 : mixed.dbConnectionString;
|
|
21
|
+
if (!dbName && dbConnectionString !== MEMORY) {
|
|
22
|
+
missing.push('dbName');
|
|
49
23
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if ((mixed === null || mixed === void 0 ? void 0 : mixed.dbConnectionString) && mixed.dbConnectionString !== 'memory://') {
|
|
56
|
-
return false;
|
|
24
|
+
if (missing.length > 0) {
|
|
25
|
+
throw new SchemaError({
|
|
26
|
+
code: 'MISSING_PARAMETERS',
|
|
27
|
+
parameters: missing,
|
|
28
|
+
});
|
|
57
29
|
}
|
|
58
|
-
|
|
30
|
+
this.dbName = dbName;
|
|
31
|
+
this.dbConnectionString = dbConnectionString;
|
|
59
32
|
}
|
|
60
33
|
connectToDatabase() {
|
|
61
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
35
|
const options = {};
|
|
63
|
-
if (this.
|
|
64
|
-
options.dbConnectionString = 'memory://';
|
|
65
|
-
}
|
|
66
|
-
else if (this.dbConnectionString && this.dbName) {
|
|
36
|
+
if (this.dbConnectionString && this.dbName) {
|
|
67
37
|
options.dbConnectionString = this.dbConnectionString;
|
|
68
38
|
options.dbName = this.dbName;
|
|
69
39
|
}
|
|
40
|
+
else if (this.dbConnectionString) {
|
|
41
|
+
options.dbConnectionString = this.dbConnectionString;
|
|
42
|
+
}
|
|
70
43
|
else {
|
|
71
44
|
options.dbName = this.dbName = DatabaseFixture.generateDbName();
|
|
72
45
|
options.dbConnectionString = MONGO_TEST_URI;
|
|
@@ -35,7 +35,7 @@ export default class AbstractDatabaseTest extends AbstractSpruceTest {
|
|
|
35
35
|
}
|
|
36
36
|
static DatabaseFixture(options) {
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const d = new DatabaseFixture(Object.assign({
|
|
38
|
+
const d = new DatabaseFixture(Object.assign({}, options));
|
|
39
39
|
return d;
|
|
40
40
|
});
|
|
41
41
|
}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { Database } from '../types/database.types';
|
|
2
2
|
export interface DatabaseFixtureOptions {
|
|
3
|
-
shouldUseInMemoryDatabase?: boolean;
|
|
4
3
|
dbConnectionString?: string;
|
|
5
4
|
dbName?: string;
|
|
6
5
|
}
|
|
7
6
|
export default class DatabaseFixture {
|
|
8
|
-
private shouldUseInMemoryDatabase;
|
|
9
7
|
private static dbCount;
|
|
10
8
|
private dbName?;
|
|
11
9
|
private static activeDatabases;
|
|
12
10
|
private dbConnectionString?;
|
|
13
11
|
private static defaultOptions?;
|
|
14
12
|
constructor(options?: DatabaseFixtureOptions);
|
|
15
|
-
private determineInMemoryDatabase;
|
|
16
13
|
connectToDatabase(): Promise<Database>;
|
|
17
14
|
private static connect;
|
|
18
15
|
static setDefaultConnectOptions(options: DatabaseFixtureOptions): void;
|
|
@@ -6,62 +6,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const schema_1 = require("@sprucelabs/schema");
|
|
7
7
|
const MongoDatabase_1 = require("../databases/MongoDatabase");
|
|
8
8
|
const DatabaseFactory_1 = __importDefault(require("../factories/DatabaseFactory"));
|
|
9
|
+
const MEMORY = 'memory://';
|
|
9
10
|
class DatabaseFixture {
|
|
10
11
|
constructor(options) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
if (mixed === null || mixed === void 0 ? void 0 : mixed.dbName) {
|
|
16
|
-
unexpected.push('dbName');
|
|
17
|
-
}
|
|
18
|
-
if (mixed === null || mixed === void 0 ? void 0 : mixed.dbConnectionString) {
|
|
19
|
-
unexpected.push('dbConnectionString');
|
|
20
|
-
}
|
|
21
|
-
if (unexpected.length > 0) {
|
|
22
|
-
throw new schema_1.SchemaError({
|
|
23
|
-
code: 'UNEXPECTED_PARAMETERS',
|
|
24
|
-
parameters: unexpected,
|
|
25
|
-
friendlyMessage: `You can't pass database connection settings if you are using an in memory database.`,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
const missing = [];
|
|
31
|
-
if (!(mixed === null || mixed === void 0 ? void 0 : mixed.dbName)) {
|
|
32
|
-
missing.push('dbName');
|
|
33
|
-
}
|
|
34
|
-
if (!(mixed === null || mixed === void 0 ? void 0 : mixed.dbConnectionString)) {
|
|
35
|
-
missing.push('dbConnectionString');
|
|
36
|
-
}
|
|
37
|
-
if (missing.length > 0) {
|
|
38
|
-
throw new schema_1.SchemaError({
|
|
39
|
-
code: 'MISSING_PARAMETERS',
|
|
40
|
-
parameters: missing,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
this.dbName = mixed === null || mixed === void 0 ? void 0 : mixed.dbName;
|
|
44
|
-
this.dbConnectionString = mixed === null || mixed === void 0 ? void 0 : mixed.dbConnectionString;
|
|
12
|
+
const { dbConnectionString = MEMORY, dbName } = Object.assign(Object.assign({}, DatabaseFixture.defaultOptions), options);
|
|
13
|
+
const missing = [];
|
|
14
|
+
if (!dbConnectionString) {
|
|
15
|
+
missing.push('dbConnectionString');
|
|
45
16
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (typeof (mixed === null || mixed === void 0 ? void 0 : mixed.shouldUseInMemoryDatabase) === 'boolean') {
|
|
49
|
-
return mixed === null || mixed === void 0 ? void 0 : mixed.shouldUseInMemoryDatabase;
|
|
17
|
+
if (!dbName && dbConnectionString !== MEMORY) {
|
|
18
|
+
missing.push('dbName');
|
|
50
19
|
}
|
|
51
|
-
if (
|
|
52
|
-
|
|
20
|
+
if (missing.length > 0) {
|
|
21
|
+
throw new schema_1.SchemaError({
|
|
22
|
+
code: 'MISSING_PARAMETERS',
|
|
23
|
+
parameters: missing,
|
|
24
|
+
});
|
|
53
25
|
}
|
|
54
|
-
|
|
26
|
+
this.dbName = dbName;
|
|
27
|
+
this.dbConnectionString = dbConnectionString;
|
|
55
28
|
}
|
|
56
29
|
async connectToDatabase() {
|
|
57
30
|
const options = {};
|
|
58
|
-
if (this.
|
|
59
|
-
options.dbConnectionString = 'memory://';
|
|
60
|
-
}
|
|
61
|
-
else if (this.dbConnectionString && this.dbName) {
|
|
31
|
+
if (this.dbConnectionString && this.dbName) {
|
|
62
32
|
options.dbConnectionString = this.dbConnectionString;
|
|
63
33
|
options.dbName = this.dbName;
|
|
64
34
|
}
|
|
35
|
+
else if (this.dbConnectionString) {
|
|
36
|
+
options.dbConnectionString = this.dbConnectionString;
|
|
37
|
+
}
|
|
65
38
|
else {
|
|
66
39
|
options.dbName = this.dbName = DatabaseFixture.generateDbName();
|
|
67
40
|
options.dbConnectionString = MongoDatabase_1.MONGO_TEST_URI;
|
|
@@ -20,7 +20,7 @@ class AbstractDatabaseTest extends test_1.default {
|
|
|
20
20
|
this.DB_NAME = undefined;
|
|
21
21
|
}
|
|
22
22
|
static async DatabaseFixture(options) {
|
|
23
|
-
const d = new DatabaseFixture_1.default(Object.assign({
|
|
23
|
+
const d = new DatabaseFixture_1.default(Object.assign({}, options));
|
|
24
24
|
return d;
|
|
25
25
|
}
|
|
26
26
|
static async connectToDatabase() {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "8.0.
|
|
6
|
+
"version": "8.0.17",
|
|
7
7
|
"files": [
|
|
8
8
|
"build/**/*",
|
|
9
9
|
"!build/__tests__",
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@sprucelabs/error": "^5.0.387",
|
|
75
|
-
"@sprucelabs/schema": "^26.0.
|
|
76
|
-
"@sprucelabs/spruce-core-schemas": "^23.0.
|
|
77
|
-
"@sprucelabs/spruce-skill-utils": "^24.0.
|
|
75
|
+
"@sprucelabs/schema": "^26.0.16",
|
|
76
|
+
"@sprucelabs/spruce-core-schemas": "^23.0.16",
|
|
77
|
+
"@sprucelabs/spruce-skill-utils": "^24.0.16",
|
|
78
78
|
"globby": "^11.0.4",
|
|
79
79
|
"lodash": "^4.17.21",
|
|
80
80
|
"mongodb": "^4.1.0",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@sprucelabs/esm-postbuild": "^1.0.334",
|
|
85
85
|
"@sprucelabs/jest-json-reporter": "^6.0.317",
|
|
86
|
-
"@sprucelabs/jest-sheets-reporter": "^1.
|
|
86
|
+
"@sprucelabs/jest-sheets-reporter": "^1.3.1",
|
|
87
87
|
"@sprucelabs/resolve-path-aliases": "^1.0.256",
|
|
88
88
|
"@sprucelabs/semantic-release": "^4.0.8",
|
|
89
89
|
"@sprucelabs/test": "^7.7.277",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"@types/node": "17.0.5",
|
|
94
94
|
"chokidar-cli": "^3.0.0",
|
|
95
95
|
"concurrently": "^7.0.0",
|
|
96
|
-
"dotenv": "^
|
|
96
|
+
"dotenv": "^16.0.0",
|
|
97
97
|
"eslint": "^8.8.0",
|
|
98
98
|
"eslint-config-spruce": "^10.11.2",
|
|
99
99
|
"jest": "^27.4.7",
|