@storyous/mongodb 1.1.0 → 1.1.2

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/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { ObjectId } from 'mongodb';
2
- import appData from './appData';
3
- import fixtures from './fixtures';
4
- import getCollection from './getCollection';
5
- import getMongoLocker, { LockCallback, LockerOptions } from './getMongoLocker';
6
- import Migration from './migrations/Migration';
7
- import MigrationsStore from './migrations/MigrationsStore';
8
- import runMigrations from './migrations/runMigrations';
9
- import mongoClient from './mongoClient';
10
- import mongoLocker from './mongoLocker';
11
- import withTransaction from './withTransaction';
12
- export { appData, fixtures, getCollection, getMongoLocker, LockCallback, LockerOptions, Migration, MigrationsStore, mongoClient, mongoLocker, runMigrations, withTransaction, ObjectId, };
1
+ import { ObjectId } from 'mongodb';
2
+ import appData from './appData';
3
+ import fixtures from './fixtures';
4
+ import getCollection from './getCollection';
5
+ import getMongoLocker, { LockCallback, LockerOptions } from './getMongoLocker';
6
+ import Migration from './migrations/Migration';
7
+ import MigrationsStore from './migrations/MigrationsStore';
8
+ import runMigrations from './migrations/runMigrations';
9
+ import mongoClient from './mongoClient';
10
+ import mongoLocker from './mongoLocker';
11
+ import withTransaction from './withTransaction';
12
+ export { appData, fixtures, getCollection, getMongoLocker, LockCallback, LockerOptions, Migration, MigrationsStore, mongoClient, mongoLocker, runMigrations, withTransaction, ObjectId, };
package/lib/index.js CHANGED
@@ -1,29 +1,29 @@
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.ObjectId = exports.withTransaction = exports.runMigrations = exports.mongoLocker = exports.mongoClient = exports.MigrationsStore = exports.Migration = exports.getMongoLocker = exports.getCollection = exports.fixtures = exports.appData = void 0;
7
- const mongodb_1 = require("mongodb");
8
- Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return mongodb_1.ObjectId; } });
9
- const appData_1 = __importDefault(require("./appData"));
10
- exports.appData = appData_1.default;
11
- const fixtures_1 = __importDefault(require("./fixtures"));
12
- exports.fixtures = fixtures_1.default;
13
- const getCollection_1 = __importDefault(require("./getCollection"));
14
- exports.getCollection = getCollection_1.default;
15
- const getMongoLocker_1 = __importDefault(require("./getMongoLocker"));
16
- exports.getMongoLocker = getMongoLocker_1.default;
17
- const Migration_1 = __importDefault(require("./migrations/Migration"));
18
- exports.Migration = Migration_1.default;
19
- const MigrationsStore_1 = __importDefault(require("./migrations/MigrationsStore"));
20
- exports.MigrationsStore = MigrationsStore_1.default;
21
- const runMigrations_1 = __importDefault(require("./migrations/runMigrations"));
22
- exports.runMigrations = runMigrations_1.default;
23
- const mongoClient_1 = __importDefault(require("./mongoClient"));
24
- exports.mongoClient = mongoClient_1.default;
25
- const mongoLocker_1 = __importDefault(require("./mongoLocker"));
26
- exports.mongoLocker = mongoLocker_1.default;
27
- const withTransaction_1 = __importDefault(require("./withTransaction"));
28
- exports.withTransaction = withTransaction_1.default;
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.ObjectId = exports.withTransaction = exports.runMigrations = exports.mongoLocker = exports.mongoClient = exports.MigrationsStore = exports.Migration = exports.getMongoLocker = exports.getCollection = exports.fixtures = exports.appData = void 0;
7
+ const mongodb_1 = require("mongodb");
8
+ Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return mongodb_1.ObjectId; } });
9
+ const appData_1 = __importDefault(require("./appData"));
10
+ exports.appData = appData_1.default;
11
+ const fixtures_1 = __importDefault(require("./fixtures"));
12
+ exports.fixtures = fixtures_1.default;
13
+ const getCollection_1 = __importDefault(require("./getCollection"));
14
+ exports.getCollection = getCollection_1.default;
15
+ const getMongoLocker_1 = __importDefault(require("./getMongoLocker"));
16
+ exports.getMongoLocker = getMongoLocker_1.default;
17
+ const Migration_1 = __importDefault(require("./migrations/Migration"));
18
+ exports.Migration = Migration_1.default;
19
+ const MigrationsStore_1 = __importDefault(require("./migrations/MigrationsStore"));
20
+ exports.MigrationsStore = MigrationsStore_1.default;
21
+ const runMigrations_1 = __importDefault(require("./migrations/runMigrations"));
22
+ exports.runMigrations = runMigrations_1.default;
23
+ const mongoClient_1 = __importDefault(require("./mongoClient"));
24
+ exports.mongoClient = mongoClient_1.default;
25
+ const mongoLocker_1 = __importDefault(require("./mongoLocker"));
26
+ exports.mongoLocker = mongoLocker_1.default;
27
+ const withTransaction_1 = __importDefault(require("./withTransaction"));
28
+ exports.withTransaction = withTransaction_1.default;
29
29
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQSxxQ0FBbUM7QUF5Qi9CLHlGQXpCSyxrQkFBUSxPQXlCTDtBQXhCWix3REFBZ0M7QUFZNUIsa0JBWkcsaUJBQU8sQ0FZSDtBQVhYLDBEQUFrQztBQVk5QixtQkFaRyxrQkFBUSxDQVlIO0FBWFosb0VBQTRDO0FBWXhDLHdCQVpHLHVCQUFhLENBWUg7QUFYakIsc0VBQStFO0FBWTNFLHlCQVpHLHdCQUFjLENBWUg7QUFYbEIsdUVBQStDO0FBYzNDLG9CQWRHLG1CQUFTLENBY0g7QUFiYixtRkFBMkQ7QUFjdkQsMEJBZEcseUJBQWUsQ0FjSDtBQWJuQiwrRUFBdUQ7QUFnQm5ELHdCQWhCRyx1QkFBYSxDQWdCSDtBQWZqQixnRUFBd0M7QUFhcEMsc0JBYkcscUJBQVcsQ0FhSDtBQVpmLGdFQUF3QztBQWFwQyxzQkFiRyxxQkFBVyxDQWFIO0FBWmYsd0VBQWdEO0FBYzVDLDBCQWRHLHlCQUFlLENBY0gifQ==
@@ -1,6 +1,6 @@
1
- export default class Migration {
2
- description: string;
3
- up: Function;
4
- down: Function;
5
- constructor(description: string, up: Function, down?: () => null);
6
- }
1
+ export default class Migration {
2
+ description: string;
3
+ up: Function;
4
+ down: Function;
5
+ constructor(description: string, up: Function, down?: () => null);
6
+ }
@@ -1,22 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class Migration {
4
- constructor(description, up, down = () => null) {
5
- this.description = description;
6
- // NOTE 'up' and 'down' has to be as properties because of 'migrate' package
7
- this.up = (next) => {
8
- (async () => {
9
- await up();
10
- next();
11
- })().catch(next);
12
- };
13
- this.down = (next) => {
14
- (async () => {
15
- await down();
16
- next();
17
- })().catch(next);
18
- };
19
- }
20
- }
21
- exports.default = Migration;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class Migration {
4
+ constructor(description, up, down = () => null) {
5
+ this.description = description;
6
+ // NOTE 'up' and 'down' has to be as properties because of 'migrate' package
7
+ this.up = (next) => {
8
+ (async () => {
9
+ await up();
10
+ next();
11
+ })().catch(next);
12
+ };
13
+ this.down = (next) => {
14
+ (async () => {
15
+ await down();
16
+ next();
17
+ })().catch(next);
18
+ };
19
+ }
20
+ }
21
+ exports.default = Migration;
22
22
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiTWlncmF0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBRUEsTUFBcUIsU0FBUztJQVExQixZQUFhLFdBQW1CLEVBQUUsRUFBWSxFQUFFLElBQUksR0FBRyxHQUFHLEVBQUUsQ0FBQyxJQUFJO1FBQzdELElBQUksQ0FBQyxXQUFXLEdBQUcsV0FBVyxDQUFDO1FBRS9CLDRFQUE0RTtRQUM1RSxJQUFJLENBQUMsRUFBRSxHQUFHLENBQUMsSUFBa0IsRUFBRSxFQUFFO1lBQzdCLENBQUMsS0FBSyxJQUFJLEVBQUU7Z0JBQ1IsTUFBTSxFQUFFLEVBQUUsQ0FBQztnQkFDWCxJQUFJLEVBQUUsQ0FBQztZQUNYLENBQUMsQ0FBQyxFQUFFLENBQUMsS0FBSyxDQUFDLElBQUksQ0FBQyxDQUFDO1FBQ3JCLENBQUMsQ0FBQztRQUVGLElBQUksQ0FBQyxJQUFJLEdBQUcsQ0FBQyxJQUFrQixFQUFFLEVBQUU7WUFDL0IsQ0FBQyxLQUFLLElBQUksRUFBRTtnQkFDUixNQUFNLElBQUksRUFBRSxDQUFDO2dCQUNiLElBQUksRUFBRSxDQUFDO1lBQ1gsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLENBQUM7UUFDckIsQ0FBQyxDQUFDO0lBQ04sQ0FBQztDQUNKO0FBMUJELDRCQTBCQyJ9
@@ -1,13 +1,13 @@
1
- import { CallbackError, Migration } from 'migrate';
2
- import { Logger } from 'winston';
3
- export default class MigrationsStore {
4
- private _logger;
5
- private _safeMigration;
6
- constructor(_logger: Logger, path: string, _safeMigration: boolean);
7
- save(set: Object, cb: CallbackError): void;
8
- load(cb: (err: any, store: {
9
- lastRun?: string;
10
- migrations: Pick<Migration, 'title' | 'description' | 'timestamp'>[];
11
- }) => void): void;
12
- private _checkValidMigrations;
13
- }
1
+ import { CallbackError, Migration } from 'migrate';
2
+ import { Logger } from 'winston';
3
+ export default class MigrationsStore {
4
+ private _logger;
5
+ private _safeMigration;
6
+ constructor(_logger: Logger, path: string, _safeMigration: boolean);
7
+ save(set: Object, cb: CallbackError): void;
8
+ load(cb: (err: any, store: {
9
+ lastRun?: string;
10
+ migrations: Pick<Migration, 'title' | 'description' | 'timestamp'>[];
11
+ }) => void): void;
12
+ private _checkValidMigrations;
13
+ }
@@ -1,65 +1,65 @@
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 lodash_1 = require("lodash");
7
- const appData_1 = __importDefault(require("../appData"));
8
- const DOCUMENT_ID = 'migrations';
9
- const safeMigrationMsg = 'safeMigration is true, we do not allow empty migrations to be saved. '
10
- + 'If this is new project, feel free to enable it';
11
- class MigrationsStore {
12
- // eslint-disable-next-line no-empty-function
13
- constructor(_logger, path, _safeMigration) {
14
- this._logger = _logger;
15
- this._safeMigration = _safeMigration;
16
- }
17
- save(set, cb) {
18
- try {
19
- this._logger.info('Migration SET', set);
20
- const objToUpdate = (0, lodash_1.pick)(set, ['lastRun', 'migrations']);
21
- if (this._safeMigration) {
22
- this._checkValidMigrations(objToUpdate);
23
- const numOfValidMigrations = objToUpdate.migrations
24
- .reduce((prev, cur) => (cur.timestamp ? prev + 1 : prev), 0);
25
- // If all migrations are renewed=without timestamp (beside the first one that is trying to be applied)
26
- // There can be something wrong
27
- if (objToUpdate.migrations.length >= 3 && numOfValidMigrations <= 1) {
28
- this._logger.error(safeMigrationMsg);
29
- throw new Error(safeMigrationMsg);
30
- }
31
- }
32
- appData_1.default.updateDocument(DOCUMENT_ID, { $set: objToUpdate }, true)
33
- .then(() => { cb(null); })
34
- .catch(cb);
35
- }
36
- catch (err) {
37
- cb(err);
38
- }
39
- }
40
- load(cb) {
41
- appData_1.default.getDocument(DOCUMENT_ID)
42
- .then((state) => {
43
- if (this._safeMigration) {
44
- this._checkValidMigrations(state);
45
- }
46
- cb(null, state || {
47
- lastRun: null,
48
- migrations: [],
49
- });
50
- })
51
- .catch((err) => {
52
- cb(err, { migrations: [] });
53
- });
54
- }
55
- _checkValidMigrations(objWithMigrations) {
56
- if (!objWithMigrations
57
- || (0, lodash_1.isEmpty)(objWithMigrations.migrations)
58
- || !(0, lodash_1.isArray)(objWithMigrations.migrations)) {
59
- this._logger.error(safeMigrationMsg);
60
- throw new Error(safeMigrationMsg);
61
- }
62
- }
63
- }
64
- exports.default = MigrationsStore;
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 lodash_1 = require("lodash");
7
+ const appData_1 = __importDefault(require("../appData"));
8
+ const DOCUMENT_ID = 'migrations';
9
+ const safeMigrationMsg = 'safeMigration is true, we do not allow empty migrations to be saved. '
10
+ + 'If this is new project, feel free to enable it';
11
+ class MigrationsStore {
12
+ // eslint-disable-next-line no-empty-function
13
+ constructor(_logger, path, _safeMigration) {
14
+ this._logger = _logger;
15
+ this._safeMigration = _safeMigration;
16
+ }
17
+ save(set, cb) {
18
+ try {
19
+ this._logger.info('Migration SET', set);
20
+ const objToUpdate = (0, lodash_1.pick)(set, ['lastRun', 'migrations']);
21
+ if (this._safeMigration) {
22
+ this._checkValidMigrations(objToUpdate);
23
+ const numOfValidMigrations = objToUpdate.migrations
24
+ .reduce((prev, cur) => (cur.timestamp ? prev + 1 : prev), 0);
25
+ // If all migrations are renewed=without timestamp (beside the first one that is trying to be applied)
26
+ // There can be something wrong
27
+ if (objToUpdate.migrations.length >= 3 && numOfValidMigrations <= 1) {
28
+ this._logger.error(safeMigrationMsg);
29
+ throw new Error(safeMigrationMsg);
30
+ }
31
+ }
32
+ appData_1.default.updateDocument(DOCUMENT_ID, { $set: objToUpdate }, true)
33
+ .then(() => { cb(null); })
34
+ .catch(cb);
35
+ }
36
+ catch (err) {
37
+ cb(err);
38
+ }
39
+ }
40
+ load(cb) {
41
+ appData_1.default.getDocument(DOCUMENT_ID)
42
+ .then((state) => {
43
+ if (this._safeMigration) {
44
+ this._checkValidMigrations(state);
45
+ }
46
+ cb(null, state || {
47
+ lastRun: null,
48
+ migrations: [],
49
+ });
50
+ })
51
+ .catch((err) => {
52
+ cb(err, { migrations: [] });
53
+ });
54
+ }
55
+ _checkValidMigrations(objWithMigrations) {
56
+ if (!objWithMigrations
57
+ || (0, lodash_1.isEmpty)(objWithMigrations.migrations)
58
+ || !(0, lodash_1.isArray)(objWithMigrations.migrations)) {
59
+ this._logger.error(safeMigrationMsg);
60
+ throw new Error(safeMigrationMsg);
61
+ }
62
+ }
63
+ }
64
+ exports.default = MigrationsStore;
65
65
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uc1N0b3JlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiTWlncmF0aW9uc1N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsbUNBQWdEO0FBR2hELHlEQUFpQztBQUVqQyxNQUFNLFdBQVcsR0FBRyxZQUFZLENBQUM7QUFFakMsTUFBTSxnQkFBZ0IsR0FBRyx1RUFBdUU7TUFDMUYsZ0RBQWdELENBQUM7QUFFdkQsTUFBcUIsZUFBZTtJQUNoQyw2Q0FBNkM7SUFDN0MsWUFBcUIsT0FBZSxFQUFFLElBQVksRUFBVSxjQUF1QjtRQUE5RCxZQUFPLEdBQVAsT0FBTyxDQUFRO1FBQXdCLG1CQUFjLEdBQWQsY0FBYyxDQUFTO0lBQ25GLENBQUM7SUFFTSxJQUFJLENBQUUsR0FBVyxFQUFFLEVBQWlCO1FBQ3ZDLElBQUk7WUFDQSxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxlQUFlLEVBQUUsR0FBRyxDQUFDLENBQUM7WUFDeEMsTUFBTSxXQUFXLEdBQVEsSUFBQSxhQUFJLEVBQUMsR0FBRyxFQUFFLENBQUMsU0FBUyxFQUFFLFlBQVksQ0FBQyxDQUFDLENBQUM7WUFDOUQsSUFBSSxJQUFJLENBQUMsY0FBYyxFQUFFO2dCQUNyQixJQUFJLENBQUMscUJBQXFCLENBQUMsV0FBVyxDQUFDLENBQUM7Z0JBRXhDLE1BQU0sb0JBQW9CLEdBQUcsV0FBVyxDQUFDLFVBQVU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BQ3JDO1lBRUQsRUFBRSxDQUNFLElBQUksRUFBRSxLQUFLLElBQUk7Z0JBQ1gsT0FBTyxFQUFFLElBQUk7Z0JBQ2IsVUFBVSxFQUFFLEVBQUU7YUFDakIsQ0FDSixDQUFDO1FBQ04sQ0FBQyxDQUFDO2FBQ0QsS0FBSyxDQUFDLENBQUMsR0FBRyxFQUFFLEVBQUU7WUFDWCxFQUFFLENBQUMsR0FBRyxFQUFFLEVBQUUsVUFBVSxFQUFFLEVBQUUsRUFBRSxDQUFDLENBQUM7UUFDaEMsQ0FBQyxDQUFDLENBQUM7SUFDWCxDQUFDO0lBRU8scUJBQXFCLENBQUUsaUJBQThDO1FBQ3pFLElBQ0ksQ0FBQyxpQkFBaUI7ZUFDZixJQUFBLGdCQUFPLEVBQUMsaUJBQWlCLENBQUMsVUFBVSxDQUFDO2VBQ3JDLENBQUMsSUFBQSxnQkFBTyxFQUFDLGlCQUFpQixDQUFDLFVBQVUsQ0FBQyxFQUFFO1lBQzNDLElBQUksQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLGdCQUFnQixDQUFDLENBQUM7WUFDckMsTUFBTSxJQUFJLEtBQUssQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDO1NBQ3JDO0lBQ0wsQ0FBQztDQUNKO0FBdEVELGtDQXNFQyJ9
@@ -1,12 +1,12 @@
1
- import { Logger } from 'winston';
2
- /**
3
- * In case of fail - logs the result and returns rejected promise
4
- * @param {Logger} logger Logger
5
- * @param {string} directory Path to directory where migrations are
6
- * @param {boolean} continueOnError If app crashes on error or continue
7
- * @param {boolean} safeMigration Do not allow to rewrite all migrations with empty array
8
- */
9
- export default function runMigrations(logger: Logger, directory: string, { continueOnError, safeMigration, }: {
10
- continueOnError?: boolean | undefined;
11
- safeMigration?: boolean | undefined;
12
- }): Promise<void>;
1
+ import { Logger } from 'winston';
2
+ /**
3
+ * In case of fail - logs the result and returns rejected promise
4
+ * @param {Logger} logger Logger
5
+ * @param {string} directory Path to directory where migrations are
6
+ * @param {boolean} continueOnError If app crashes on error or continue
7
+ * @param {boolean} safeMigration Do not allow to rewrite all migrations with empty array
8
+ */
9
+ export default function runMigrations(logger: Logger, directory: string, { continueOnError, safeMigration, }: {
10
+ continueOnError?: boolean | undefined;
11
+ safeMigration?: boolean | undefined;
12
+ }): Promise<void>;
@@ -1,50 +1,50 @@
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 migrate_1 = require("migrate");
7
- const MigrationsStore_1 = __importDefault(require("./MigrationsStore"));
8
- /**
9
- * In case of fail - logs the result and returns rejected promise
10
- * @param {Logger} logger Logger
11
- * @param {string} directory Path to directory where migrations are
12
- * @param {boolean} continueOnError If app crashes on error or continue
13
- * @param {boolean} safeMigration Do not allow to rewrite all migrations with empty array
14
- */
15
- async function runMigrations(logger, directory, { continueOnError = false, safeMigration = true, }) {
16
- return new Promise((resolve, reject) => {
17
- (0, migrate_1.load)({
18
- stateStore: new MigrationsStore_1.default(logger, directory, safeMigration),
19
- migrationsDirectory: directory,
20
- filterFunction: (file) => file.endsWith('.js'),
21
- }, (err, set) => {
22
- if (err) {
23
- logger.error('Migrations did not run due to error', err);
24
- reject(err);
25
- return;
26
- }
27
- set.on('warning', (msg) => {
28
- logger.warn('warning', msg);
29
- });
30
- set.on('migration', (migration, direction) => {
31
- logger.info(`Running ${direction} migration`, { title: migration.title });
32
- });
33
- set.up((error) => {
34
- if (error) {
35
- logger.error('A migration ended with error', error);
36
- if (!continueOnError) {
37
- reject(error);
38
- return;
39
- }
40
- }
41
- else {
42
- logger.info('Migrations successfully ran');
43
- }
44
- resolve();
45
- });
46
- });
47
- });
48
- }
49
- exports.default = runMigrations;
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 migrate_1 = require("migrate");
7
+ const MigrationsStore_1 = __importDefault(require("./MigrationsStore"));
8
+ /**
9
+ * In case of fail - logs the result and returns rejected promise
10
+ * @param {Logger} logger Logger
11
+ * @param {string} directory Path to directory where migrations are
12
+ * @param {boolean} continueOnError If app crashes on error or continue
13
+ * @param {boolean} safeMigration Do not allow to rewrite all migrations with empty array
14
+ */
15
+ async function runMigrations(logger, directory, { continueOnError = false, safeMigration = true, }) {
16
+ return new Promise((resolve, reject) => {
17
+ (0, migrate_1.load)({
18
+ stateStore: new MigrationsStore_1.default(logger, directory, safeMigration),
19
+ migrationsDirectory: directory,
20
+ filterFunction: (file) => file.endsWith('.js'),
21
+ }, (err, set) => {
22
+ if (err) {
23
+ logger.error('Migrations did not run due to error', err);
24
+ reject(err);
25
+ return;
26
+ }
27
+ set.on('warning', (msg) => {
28
+ logger.warn('warning', msg);
29
+ });
30
+ set.on('migration', (migration, direction) => {
31
+ logger.info(`Running ${direction} migration`, { title: migration.title });
32
+ });
33
+ set.up((error) => {
34
+ if (error) {
35
+ logger.error('A migration ended with error', error);
36
+ if (!continueOnError) {
37
+ reject(error);
38
+ return;
39
+ }
40
+ }
41
+ else {
42
+ logger.info('Migrations successfully ran');
43
+ }
44
+ resolve();
45
+ });
46
+ });
47
+ });
48
+ }
49
+ exports.default = runMigrations;
50
50
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicnVuTWlncmF0aW9ucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInJ1bk1pZ3JhdGlvbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxxQ0FBNkM7QUFFN0Msd0VBQWdEO0FBRWhEOzs7Ozs7R0FNRztBQUNZLEtBQUssVUFBVSxhQUFhLENBQ3ZDLE1BQWMsRUFDZCxTQUFpQixFQUNqQixFQUNJLGVBQWUsR0FBRyxLQUFLLEVBQ3Z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sSUFBSSxLQUFLLEVBQUU7b0JBQ1AsTUFBTSxDQUFDLEtBQUssQ0FBQyw4QkFBOEIsRUFBRSxLQUFLLENBQUMsQ0FBQztvQkFDcEQsSUFBSSxDQUFDLGVBQWUsRUFBRTt3QkFDbEIsTUFBTSxDQUFDLEtBQUssQ0FBQyxDQUFDO3dCQUNkLE9BQU87cUJBQ1Y7aUJBQ0o7cUJBQU07b0JBQ0gsTUFBTSxDQUFDLElBQUksQ0FBQyw2QkFBNkIsQ0FBQyxDQUFDO2lCQUM5QztnQkFFRCxPQUFPLEVBQUUsQ0FBQztZQUNkLENBQUMsQ0FBQyxDQUFDO1FBQ1AsQ0FBQyxDQUFDLENBQUM7SUFDWCxDQUFDLENBQUMsQ0FBQztBQUNQLENBQUM7QUE3Q0QsZ0NBNkNDIn0=
@@ -1,3 +1,3 @@
1
- import Migration from './Migration';
2
- declare const _default: Migration;
3
- export = _default;
1
+ import Migration from './Migration';
2
+ declare const _default: Migration;
3
+ export = _default;
@@ -1,11 +1,11 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- const getCollection_1 = __importDefault(require("../getCollection"));
6
- const Migration_1 = __importDefault(require("./Migration"));
7
- module.exports = new Migration_1.default('[ADD DESCRIPTION HERE]', async () => {
8
- // add logic here
9
- await (0, getCollection_1.default)('exampleCollection');
10
- });
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const getCollection_1 = __importDefault(require("../getCollection"));
6
+ const Migration_1 = __importDefault(require("./Migration"));
7
+ module.exports = new Migration_1.default('[ADD DESCRIPTION HERE]', async () => {
8
+ // add logic here
9
+ await (0, getCollection_1.default)('exampleCollection');
10
+ });
11
11
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVtcGxhdGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJ0ZW1wbGF0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEscUVBQTZDO0FBQzdDLDREQUFvQztBQUVwQyxpQkFBUyxJQUFJLG1CQUFTLENBQUMsd0JBQXdCLEVBQUUsS0FBSyxJQUFJLEVBQUU7SUFDeEQsaUJBQWlCO0lBQ2pCLE1BQU0sSUFBQSx1QkFBYSxFQUFDLG1CQUFtQixDQUFDLENBQUM7QUFDN0MsQ0FBQyxDQUFDLENBQUMifQ==
@@ -1,8 +1,8 @@
1
- import { MongoClient, MongoClientOptions, ObjectId } from 'mongodb';
2
- export declare type Key = string | number | ObjectId;
3
- declare const mongoClient: {
4
- _client: MongoClient | null;
5
- init(mongodbUrl: string, mongoOptions?: MongoClientOptions | undefined): void;
6
- getClient(): MongoClient;
7
- };
8
- export default mongoClient;
1
+ import { MongoClient, MongoClientOptions, ObjectId } from 'mongodb';
2
+ export declare type Key = string | number | ObjectId;
3
+ declare const mongoClient: {
4
+ _client: MongoClient | null;
5
+ init(mongodbUrl: string, mongoOptions?: MongoClientOptions | undefined): void;
6
+ getClient(): MongoClient;
7
+ };
8
+ export default mongoClient;
@@ -1,18 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const lodash_1 = require("lodash");
4
- const mongodb_1 = require("mongodb");
5
- const mongoClient = {
6
- _client: null,
7
- init(mongodbUrl, mongoOptions) {
8
- this._client = new mongodb_1.MongoClient(mongodbUrl, (0, lodash_1.defaultsDeep)(mongoOptions));
9
- },
10
- getClient() {
11
- if (this._client) {
12
- return this._client;
13
- }
14
- throw new Error('MongoDb must be initialized before use.');
15
- },
16
- };
17
- exports.default = mongoClient;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const lodash_1 = require("lodash");
4
+ const mongodb_1 = require("mongodb");
5
+ const mongoClient = {
6
+ _client: null,
7
+ init(mongodbUrl, mongoOptions) {
8
+ this._client = new mongodb_1.MongoClient(mongodbUrl, (0, lodash_1.defaultsDeep)(mongoOptions));
9
+ },
10
+ getClient() {
11
+ if (this._client) {
12
+ return this._client;
13
+ }
14
+ throw new Error('MongoDb must be initialized before use.');
15
+ },
16
+ };
17
+ exports.default = mongoClient;
18
18
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9uZ29DbGllbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJtb25nb0NsaWVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLG1DQUFzQztBQUN0QyxxQ0FBb0U7QUFJcEUsTUFBTSxXQUFXLEdBQUc7SUFDaEIsT0FBTyxFQUFxQixJQUFJO0lBRWhDLElBQUksQ0FBRSxVQUFrQixFQUFFLFlBQWlDO1FBQ3ZELElBQUksQ0FBQyxPQUFPLEdBQUcsSUFBSSxxQkFBVyxDQUMxQixVQUFVLEVBQ1YsSUFBQSxxQkFBWSxFQUFDLFlBQVksQ0FBQyxDQUM3QixDQUFDO0lBQ04sQ0FBQztJQUVELFNBQVM7UUFDTCxJQUFJLElBQUksQ0FBQyxPQUFPLEVBQUU7WUFDZCxPQUFPLElBQUksQ0FBQyxPQUFPLENBQUM7U0FDdkI7UUFFRCxNQUFNLElBQUksS0FBSyxDQUFDLHlDQUF5QyxDQUFDLENBQUM7SUFDL0QsQ0FBQztDQUNKLENBQUM7QUFFRixrQkFBZSxXQUFXLENBQUMifQ==
@@ -1,6 +1,6 @@
1
- declare const mongoErrorCodes: {
2
- DUPLICATE_KEY_INSERT: number;
3
- DUPLICATE_KEY_UPDATE: number;
4
- DUPLICATE_KEY: number[];
5
- };
6
- export default mongoErrorCodes;
1
+ declare const mongoErrorCodes: {
2
+ DUPLICATE_KEY_INSERT: number;
3
+ DUPLICATE_KEY_UPDATE: number;
4
+ DUPLICATE_KEY: number[];
5
+ };
6
+ export default mongoErrorCodes;
@@ -1,11 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const DUPLICATE_KEY_INSERT = 11000;
4
- const DUPLICATE_KEY_UPDATE = 11001;
5
- const mongoErrorCodes = {
6
- DUPLICATE_KEY_INSERT,
7
- DUPLICATE_KEY_UPDATE,
8
- DUPLICATE_KEY: [DUPLICATE_KEY_INSERT, DUPLICATE_KEY_UPDATE],
9
- };
10
- exports.default = mongoErrorCodes;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const DUPLICATE_KEY_INSERT = 11000;
4
+ const DUPLICATE_KEY_UPDATE = 11001;
5
+ const mongoErrorCodes = {
6
+ DUPLICATE_KEY_INSERT,
7
+ DUPLICATE_KEY_UPDATE,
8
+ DUPLICATE_KEY: [DUPLICATE_KEY_INSERT, DUPLICATE_KEY_UPDATE],
9
+ };
10
+ exports.default = mongoErrorCodes;
11
11
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9uZ29FcnJvckNvZGVzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsibW9uZ29FcnJvckNvZGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsTUFBTSxvQkFBb0IsR0FBRyxLQUFLLENBQUM7QUFDbkMsTUFBTSxvQkFBb0IsR0FBRyxLQUFLLENBQUM7QUFFbkMsTUFBTSxlQUFlLEdBQUc7SUFDcEIsb0JBQW9CO0lBQ3BCLG9CQUFvQjtJQUNwQixhQUFhLEVBQUUsQ0FBQyxvQkFBb0IsRUFBRSxvQkFBb0IsQ0FBQztDQUM5RCxDQUFDO0FBRUYsa0JBQWUsZUFBZSxDQUFDIn0=
@@ -1,3 +1,3 @@
1
- import { LockCallback, LockerOptions } from './getMongoLocker';
2
- import { Key } from './mongoClient';
3
- export default function <T>(key: Key, callback: LockCallback<T>, options?: LockerOptions): Promise<T>;
1
+ import { LockCallback, LockerOptions } from './getMongoLocker';
2
+ import { Key } from './mongoClient';
3
+ export default function <T>(key: Key, callback: LockCallback<T>, options?: LockerOptions): Promise<T>;
@@ -1,17 +1,17 @@
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 getCollection_1 = __importDefault(require("./getCollection"));
7
- const getMongoLocker_1 = __importDefault(require("./getMongoLocker"));
8
- let lockerPromise;
9
- async function default_1(key, callback, options = {}) {
10
- if (!lockerPromise) {
11
- lockerPromise = (0, getMongoLocker_1.default)((0, getCollection_1.default)('appLocks'));
12
- }
13
- const locker = await lockerPromise;
14
- return locker(key, callback, options);
15
- }
16
- exports.default = default_1;
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 getCollection_1 = __importDefault(require("./getCollection"));
7
+ const getMongoLocker_1 = __importDefault(require("./getMongoLocker"));
8
+ let lockerPromise;
9
+ async function default_1(key, callback, options = {}) {
10
+ if (!lockerPromise) {
11
+ lockerPromise = (0, getMongoLocker_1.default)((0, getCollection_1.default)('appLocks'));
12
+ }
13
+ const locker = await lockerPromise;
14
+ return locker(key, callback, options);
15
+ }
16
+ exports.default = default_1;
17
17
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9uZ29Mb2NrZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJtb25nb0xvY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLG9FQUE0QztBQUM1QyxzRUFBK0U7QUFHL0UsSUFBSSxhQUFnRCxDQUFDO0FBRXRDLEtBQUssb0JBQWUsR0FBUSxFQUFFLFFBQXlCLEVBQUUsVUFBeUIsRUFBRTtJQUMvRixJQUFJLENBQUMsYUFBYSxFQUFFO1FBQ2hCLGFBQWEsR0FBRyxJQUFBLHdCQUFjLEVBQUMsSUFBQSx1QkFBYSxFQUFNLFVBQVUsQ0FBQyxDQUFDLENBQUM7S0FDbEU7SUFFRCxNQUFNLE1BQU0sR0FBRyxNQUFNLGFBQWEsQ0FBQztJQUVuQyxPQUFPLE1BQU0sQ0FBQyxHQUFHLEVBQUUsUUFBUSxFQUFFLE9BQU8sQ0FBQyxDQUFDO0FBQzFDLENBQUM7QUFSRCw0QkFRQyJ9
@@ -1,3 +1,3 @@
1
- import { ClientSession, TransactionOptions } from 'mongodb';
2
- declare const _default: <T>(callback: (session: ClientSession) => Promise<T>, options?: TransactionOptions | undefined) => Promise<T>;
3
- export default _default;
1
+ import { ClientSession, TransactionOptions } from 'mongodb';
2
+ declare const _default: <T>(callback: (session: ClientSession) => Promise<T>, options?: TransactionOptions | undefined) => Promise<T>;
3
+ export default _default;