@storyous/mongodb 1.0.9 → 1.0.10
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/appData/index.d.ts +12 -0
- package/dist/appData/index.js +40 -0
- package/dist/concurrentTask.d.ts +9 -0
- package/dist/concurrentTask.js +20 -0
- package/dist/fixtures.d.ts +5 -0
- package/dist/fixtures.js +28 -0
- package/dist/getCollection.d.ts +3 -0
- package/dist/getCollection.js +9 -0
- package/dist/getMongoLocker.d.ts +10 -0
- package/dist/getMongoLocker.js +53 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +27 -0
- package/dist/migrations/Migration.d.ts +6 -0
- package/dist/migrations/Migration.js +22 -0
- package/dist/migrations/MigrationsStore.d.ts +13 -0
- package/dist/migrations/MigrationsStore.js +65 -0
- package/dist/migrations/runMigrations.d.ts +12 -0
- package/dist/migrations/runMigrations.js +50 -0
- package/{__tests__/migrations/1642152064249-test.d.ts → dist/migrations/template.d.ts} +1 -1
- package/dist/migrations/template.js +11 -0
- package/dist/mongoClient.d.ts +8 -0
- package/dist/mongoClient.js +18 -0
- package/dist/mongoErrorCodes.d.ts +6 -0
- package/dist/mongoErrorCodes.js +11 -0
- package/dist/mongoLocker.d.ts +3 -0
- package/dist/mongoLocker.js +17 -0
- package/dist/withTransaction.d.ts +3 -0
- package/dist/withTransaction.js +21 -0
- package/lib/index.d.ts +1 -2
- package/lib/index.js +2 -4
- package/lib/migrations/template.d.ts +1 -1
- package/lib/migrations/template.js +8 -4
- package/lib/migrations/template.ts +2 -1
- package/package.json +14 -7
- package/__tests__/appData.test.d.ts +0 -1
- package/__tests__/appData.test.js +0 -32
- package/__tests__/appData.test.ts +0 -34
- package/__tests__/fixtures.test.d.ts +0 -1
- package/__tests__/fixtures.test.js +0 -39
- package/__tests__/fixtures.test.ts +0 -44
- package/__tests__/getMongoClient.d.ts +0 -3
- package/__tests__/getMongoClient.js +0 -19
- package/__tests__/getMongoClient.ts +0 -24
- package/__tests__/migrations/1642152064249-test.js +0 -7
- package/__tests__/migrations/1642152064249-test.ts +0 -7
- package/__tests__/mongoLocker.test.d.ts +0 -1
- package/__tests__/mongoLocker.test.js +0 -151
- package/__tests__/mongoLocker.test.ts +0 -191
- package/__tests__/runMigration.test.d.ts +0 -1
- package/__tests__/runMigration.test.js +0 -21
- package/__tests__/runMigration.test.ts +0 -22
- package/__tests__/withTransaction.test.d.ts +0 -1
- package/__tests__/withTransaction.test.js +0 -40
- package/__tests__/withTransaction.test.ts +0 -67
- package/tsconfig.json +0 -7
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
require("./getMongoClient");
|
|
7
|
-
const assert_1 = __importDefault(require("assert"));
|
|
8
|
-
const mocha_1 = require("mocha");
|
|
9
|
-
const winston_1 = require("winston");
|
|
10
|
-
const lib_1 = require("../lib");
|
|
11
|
-
(0, mocha_1.describe)('packages/mongodb/migrations', () => {
|
|
12
|
-
(0, mocha_1.before)(async () => {
|
|
13
|
-
await lib_1.appData._collection.deleteOne({ _id: 'migrations' });
|
|
14
|
-
});
|
|
15
|
-
(0, mocha_1.it)('should runMigrations works', async () => {
|
|
16
|
-
await (0, lib_1.runMigrations)((0, winston_1.createLogger)(), `${__dirname}/migrations`, { safeMigration: false });
|
|
17
|
-
const migration = await lib_1.appData.getDocument('migrations');
|
|
18
|
-
assert_1.default.deepStrictEqual(migration?.lastRun, '1642152064249-test.js');
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicnVuTWlncmF0aW9uLnRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJydW5NaWdyYXRpb24udGVzdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLDRCQUEwQjtBQUMxQixvREFBNEI7QUFDNUIsaUNBQTZDO0FBQzdDLHFDQUF1QztBQUN2QyxnQ0FBZ0Q7QUFFaEQsSUFBQSxnQkFBUSxFQUFDLDZCQUE2QixFQUFFLEdBQUcsRUFBRTtJQUN6QyxJQUFBLGNBQU0sRUFBQyxLQUFLLElBQUksRUFBRTtRQUNkLE1BQU0sYUFBTyxDQUFDLFdBQVcsQ0FBQyxTQUFTLENBQUMsRUFBRSxHQUFHLEVBQUUsWUFBWSxFQUFFLENBQUMsQ0FBQztJQUMvRCxDQUFDLENBQUMsQ0FBQztJQUVILElBQUEsVUFBRSxFQUFDLDRCQUE0QixFQUFFLEtBQUssSUFBSSxFQUFFO1FBQ3hDLE1BQU0sSUFBQSxtQkFBYSxFQUNmLElBQUEsc0JBQVksR0FBRSxFQUNkLEdBQUcsU0FBUyxhQUFhLEVBQ3pCLEVBQUUsYUFBYSxFQUFFLEtBQUssRUFBRSxDQUMzQixDQUFDO1FBRUYsTUFBTSxTQUFTLEdBQUcsTUFBTSxhQUFPLENBQUMsV0FBVyxDQUFDLFlBQVksQ0FBQyxDQUFDO1FBQzFELGdCQUFNLENBQUMsZUFBZSxDQUFDLFNBQVMsRUFBRSxPQUFPLEVBQUUsdUJBQXVCLENBQUMsQ0FBQztJQUN4RSxDQUFDLENBQUMsQ0FBQztBQUNQLENBQUMsQ0FBQyxDQUFDIn0=
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import './getMongoClient';
|
|
2
|
-
import assert from 'assert';
|
|
3
|
-
import { before, describe, it } from 'mocha';
|
|
4
|
-
import { createLogger } from 'winston';
|
|
5
|
-
import { appData, runMigrations } from '../lib';
|
|
6
|
-
|
|
7
|
-
describe('packages/mongodb/migrations', () => {
|
|
8
|
-
before(async () => {
|
|
9
|
-
await appData._collection.deleteOne({ _id: 'migrations' });
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should runMigrations works', async () => {
|
|
13
|
-
await runMigrations(
|
|
14
|
-
createLogger(),
|
|
15
|
-
`${__dirname}/migrations`,
|
|
16
|
-
{ safeMigration: false },
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
const migration = await appData.getDocument('migrations');
|
|
20
|
-
assert.deepStrictEqual(migration?.lastRun, '1642152064249-test.js');
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,40 +0,0 @@
|
|
|
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
|
-
const assert_1 = __importDefault(require("assert"));
|
|
7
|
-
const lodash_1 = require("lodash");
|
|
8
|
-
const mocha_1 = require("mocha");
|
|
9
|
-
const lib_1 = require("../lib");
|
|
10
|
-
require('./getMongoClient');
|
|
11
|
-
(0, mocha_1.describe)('packages/mongodb/withTransaction', () => {
|
|
12
|
-
let testCollection;
|
|
13
|
-
(0, mocha_1.beforeEach)(async () => {
|
|
14
|
-
testCollection = (0, lib_1.getCollection)('withTransactionTests');
|
|
15
|
-
await testCollection.drop().catch(lodash_1.noop);
|
|
16
|
-
await testCollection.insertOne({}); // ensure the collection is created before tests
|
|
17
|
-
});
|
|
18
|
-
(0, mocha_1.it)('should commit the transaction', async () => {
|
|
19
|
-
const expectedReturnValue = { some: 'value' };
|
|
20
|
-
const returnValue = await (0, lib_1.withTransaction)(async (session) => {
|
|
21
|
-
await testCollection.insertOne({}, { session });
|
|
22
|
-
await testCollection.insertOne({}, { session });
|
|
23
|
-
assert_1.default.equal(await testCollection.countDocuments({}, { session }), 3);
|
|
24
|
-
return expectedReturnValue;
|
|
25
|
-
});
|
|
26
|
-
assert_1.default.equal(await testCollection.countDocuments({}), 3, 'there should available documents after a commit');
|
|
27
|
-
assert_1.default.equal(returnValue, expectedReturnValue);
|
|
28
|
-
});
|
|
29
|
-
(0, mocha_1.it)('should rollback the transaction', async () => {
|
|
30
|
-
const error = new Error('some error');
|
|
31
|
-
await assert_1.default.rejects(() => (0, lib_1.withTransaction)(async (session) => {
|
|
32
|
-
await testCollection.insertOne({}, { session });
|
|
33
|
-
await testCollection.insertOne({}, { session });
|
|
34
|
-
assert_1.default.equal(await testCollection.countDocuments({}, { session }), 3);
|
|
35
|
-
throw error;
|
|
36
|
-
}), error);
|
|
37
|
-
assert_1.default.equal(await testCollection.countDocuments({}), 1, 'there should be no document after a rollback');
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2l0aFRyYW5zYWN0aW9uLnRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJ3aXRoVHJhbnNhY3Rpb24udGVzdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLG9EQUE0QjtBQUM1QixtQ0FBOEI7QUFDOUIsaUNBQWlEO0FBRWpELGdDQUF3RDtBQUV4RCxPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0FBQztBQUU1QixJQUFBLGdCQUFRLEVBQUMsa0NBQWtDLEVBQUUsR0FBRyxFQUFFO0lBRTlDLElBQUksY0FBK0IsQ0FBQztJQUNwQyxJQUFBLGtCQUFVLEVBQUMsS0FBSyxJQUFJLEVBQUU7UUFDbEIsY0FBYyxHQUFHLElBQUEsbUJBQWEsRUFBQyxzQkFBc0IsQ0FBQyxDQUFDO1FBQ3ZELE1BQU0sY0FBYyxDQUFDLElBQUksRUFBRSxDQUFDLEtBQUssQ0FBQyxhQUFJLENBQUMsQ0FBQztRQUN4QyxNQUFNLGNBQWMsQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFRLENBQUMsQ0FBQyxnREFBZ0Q7SUFDL0Y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BZSxFQUFDLEtBQUssRUFBRSxPQUFPLEVBQUUsRUFBRTtZQUV6RCxNQUFNLGNBQWMsQ0FBQyxTQUFTLENBQUMsRUFBRSxFQUFFLEVBQUUsT0FBTyxFQUFFLENBQUMsQ0FBQztZQUNoRCxNQUFNLGNBQWMsQ0FBQyxTQUFTLENBQUMsRUFBRSxFQUFFLEVBQUUsT0FBTyxFQUFFLENBQUMsQ0FBQztZQUVoRCxnQkFBTSxDQUFDLEtBQUssQ0FDUixNQUFNLGNBQWMsQ0FBQyxjQUFjLENBQUMsRUFBRSxFQUFFLEVBQUUsT0FBTyxFQUFFLENBQUMsRUFDcEQsQ0FBQyxDQUNKLENBQUM7WUFFRixNQUFNLEtBQUssQ0FBQztRQUVoQixDQUFDLENBQUMsRUFBRSxLQUFLLENBQUMsQ0FBQztRQUVYLGdCQUFNLENBQUMsS0FBSyxDQUNSLE1BQU0sY0FBYyxDQUFDLGNBQWMsQ0FBQyxFQUFFLENBQUMsRUFDdkMsQ0FBQyxFQUNELDhDQUE4QyxDQUNqRCxDQUFDO0lBQ04sQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDLENBQUMsQ0FBQyJ9
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
|
-
import { noop } from 'lodash';
|
|
3
|
-
import { beforeEach, describe, it } from 'mocha';
|
|
4
|
-
import { Collection } from 'mongodb';
|
|
5
|
-
import { getCollection, withTransaction } from '../lib';
|
|
6
|
-
|
|
7
|
-
require('./getMongoClient');
|
|
8
|
-
|
|
9
|
-
describe('packages/mongodb/withTransaction', () => {
|
|
10
|
-
|
|
11
|
-
let testCollection: Collection<any>;
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
testCollection = getCollection('withTransactionTests');
|
|
14
|
-
await testCollection.drop().catch(noop);
|
|
15
|
-
await testCollection.insertOne({}) as any; // ensure the collection is created before tests
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should commit the transaction', async () => {
|
|
19
|
-
|
|
20
|
-
const expectedReturnValue = { some: 'value' };
|
|
21
|
-
|
|
22
|
-
const returnValue = await withTransaction(async (session) => {
|
|
23
|
-
|
|
24
|
-
await testCollection.insertOne({}, { session });
|
|
25
|
-
await testCollection.insertOne({}, { session });
|
|
26
|
-
|
|
27
|
-
assert.equal(
|
|
28
|
-
await testCollection.countDocuments({}, { session }),
|
|
29
|
-
3,
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
return expectedReturnValue;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
assert.equal(
|
|
36
|
-
await testCollection.countDocuments({}),
|
|
37
|
-
3,
|
|
38
|
-
'there should available documents after a commit',
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
assert.equal(returnValue, expectedReturnValue);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should rollback the transaction', async () => {
|
|
45
|
-
const error = new Error('some error');
|
|
46
|
-
|
|
47
|
-
await assert.rejects(() => withTransaction(async (session) => {
|
|
48
|
-
|
|
49
|
-
await testCollection.insertOne({}, { session });
|
|
50
|
-
await testCollection.insertOne({}, { session });
|
|
51
|
-
|
|
52
|
-
assert.equal(
|
|
53
|
-
await testCollection.countDocuments({}, { session }),
|
|
54
|
-
3,
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
throw error;
|
|
58
|
-
|
|
59
|
-
}), error);
|
|
60
|
-
|
|
61
|
-
assert.equal(
|
|
62
|
-
await testCollection.countDocuments({}),
|
|
63
|
-
1,
|
|
64
|
-
'there should be no document after a rollback',
|
|
65
|
-
);
|
|
66
|
-
});
|
|
67
|
-
});
|