@storyous/mongodb 1.7.2 → 1.7.3

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.
Files changed (48) hide show
  1. package/README.md +134 -134
  2. package/lib/appData/index.d.ts +12 -12
  3. package/lib/appData/index.js +39 -39
  4. package/lib/appData/index.ts +48 -48
  5. package/lib/concurrentTask.d.ts +9 -9
  6. package/lib/concurrentTask.js +19 -19
  7. package/lib/concurrentTask.ts +30 -30
  8. package/lib/fixtures.d.ts +5 -5
  9. package/lib/fixtures.js +27 -27
  10. package/lib/fixtures.ts +36 -36
  11. package/lib/getCollection.d.ts +3 -3
  12. package/lib/getCollection.js +8 -8
  13. package/lib/getCollection.ts +5 -5
  14. package/lib/getMongoConfig.d.ts +6 -6
  15. package/lib/getMongoConfig.js +85 -85
  16. package/lib/getMongoConfig.ts +78 -78
  17. package/lib/getMongoLocker.d.ts +10 -10
  18. package/lib/getMongoLocker.js +52 -52
  19. package/lib/getMongoLocker.ts +71 -71
  20. package/lib/global-bundle.pem +2876 -2876
  21. package/lib/index.d.ts +15 -15
  22. package/lib/index.js +35 -35
  23. package/lib/index.ts +34 -34
  24. package/lib/migrations/Migration.d.ts +6 -6
  25. package/lib/migrations/Migration.js +21 -21
  26. package/lib/migrations/Migration.ts +29 -29
  27. package/lib/migrations/MigrationsStore.d.ts +13 -13
  28. package/lib/migrations/MigrationsStore.js +64 -64
  29. package/lib/migrations/MigrationsStore.ts +81 -81
  30. package/lib/migrations/runMigrations.d.ts +12 -12
  31. package/lib/migrations/runMigrations.js +49 -49
  32. package/lib/migrations/runMigrations.ts +57 -57
  33. package/lib/migrations/template.d.ts +3 -3
  34. package/lib/migrations/template.js +10 -10
  35. package/lib/migrations/template.ts +7 -7
  36. package/lib/mongoClient.d.ts +8 -8
  37. package/lib/mongoClient.js +17 -17
  38. package/lib/mongoClient.ts +25 -25
  39. package/lib/mongoErrorCodes.d.ts +6 -6
  40. package/lib/mongoErrorCodes.js +10 -10
  41. package/lib/mongoErrorCodes.ts +10 -10
  42. package/lib/mongoLocker.d.ts +3 -3
  43. package/lib/mongoLocker.js +16 -16
  44. package/lib/mongoLocker.ts +15 -15
  45. package/lib/withTransaction.d.ts +3 -3
  46. package/lib/withTransaction.js +20 -20
  47. package/lib/withTransaction.ts +24 -24
  48. package/package.json +2 -2
package/lib/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- import { Decimal128 as MongoDecimal, ObjectId } from 'mongodb';
2
- import appData from './appData';
3
- import concurrentTask from './concurrentTask';
4
- import fixtures from './fixtures';
5
- import getCollection from './getCollection';
6
- import getMongoConfig from './getMongoConfig';
7
- import getMongoLocker, { LockCallback, LockerOptions } from './getMongoLocker';
8
- import Migration from './migrations/Migration';
9
- import MigrationsStore from './migrations/MigrationsStore';
10
- import runMigrations from './migrations/runMigrations';
11
- import mongoClient from './mongoClient';
12
- import mongoErrorCodes from './mongoErrorCodes';
13
- import mongoLocker from './mongoLocker';
14
- import withTransaction from './withTransaction';
15
- export { appData, fixtures, getCollection, getMongoConfig, getMongoLocker, LockCallback, LockerOptions, Migration, MigrationsStore, mongoClient, mongoLocker, runMigrations, withTransaction, ObjectId, MongoDecimal, mongoErrorCodes, concurrentTask, };
1
+ import { Decimal128 as MongoDecimal, ObjectId } from 'mongodb';
2
+ import appData from './appData';
3
+ import concurrentTask from './concurrentTask';
4
+ import fixtures from './fixtures';
5
+ import getCollection from './getCollection';
6
+ import getMongoConfig from './getMongoConfig';
7
+ import getMongoLocker, { LockCallback, LockerOptions } from './getMongoLocker';
8
+ import Migration from './migrations/Migration';
9
+ import MigrationsStore from './migrations/MigrationsStore';
10
+ import runMigrations from './migrations/runMigrations';
11
+ import mongoClient from './mongoClient';
12
+ import mongoErrorCodes from './mongoErrorCodes';
13
+ import mongoLocker from './mongoLocker';
14
+ import withTransaction from './withTransaction';
15
+ export { appData, fixtures, getCollection, getMongoConfig, getMongoLocker, LockCallback, LockerOptions, Migration, MigrationsStore, mongoClient, mongoLocker, runMigrations, withTransaction, ObjectId, MongoDecimal, mongoErrorCodes, concurrentTask, };
package/lib/index.js CHANGED
@@ -1,36 +1,36 @@
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.concurrentTask = exports.mongoErrorCodes = exports.MongoDecimal = exports.ObjectId = exports.withTransaction = exports.runMigrations = exports.mongoLocker = exports.mongoClient = exports.MigrationsStore = exports.Migration = exports.getMongoLocker = exports.getMongoConfig = exports.getCollection = exports.fixtures = exports.appData = void 0;
7
- const mongodb_1 = require("mongodb");
8
- Object.defineProperty(exports, "MongoDecimal", { enumerable: true, get: function () { return mongodb_1.Decimal128; } });
9
- Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return mongodb_1.ObjectId; } });
10
- const appData_1 = __importDefault(require("./appData"));
11
- exports.appData = appData_1.default;
12
- const concurrentTask_1 = __importDefault(require("./concurrentTask"));
13
- exports.concurrentTask = concurrentTask_1.default;
14
- const fixtures_1 = __importDefault(require("./fixtures"));
15
- exports.fixtures = fixtures_1.default;
16
- const getCollection_1 = __importDefault(require("./getCollection"));
17
- exports.getCollection = getCollection_1.default;
18
- const getMongoConfig_1 = __importDefault(require("./getMongoConfig"));
19
- exports.getMongoConfig = getMongoConfig_1.default;
20
- const getMongoLocker_1 = __importDefault(require("./getMongoLocker"));
21
- exports.getMongoLocker = getMongoLocker_1.default;
22
- const Migration_1 = __importDefault(require("./migrations/Migration"));
23
- exports.Migration = Migration_1.default;
24
- const MigrationsStore_1 = __importDefault(require("./migrations/MigrationsStore"));
25
- exports.MigrationsStore = MigrationsStore_1.default;
26
- const runMigrations_1 = __importDefault(require("./migrations/runMigrations"));
27
- exports.runMigrations = runMigrations_1.default;
28
- const mongoClient_1 = __importDefault(require("./mongoClient"));
29
- exports.mongoClient = mongoClient_1.default;
30
- const mongoErrorCodes_1 = __importDefault(require("./mongoErrorCodes"));
31
- exports.mongoErrorCodes = mongoErrorCodes_1.default;
32
- const mongoLocker_1 = __importDefault(require("./mongoLocker"));
33
- exports.mongoLocker = mongoLocker_1.default;
34
- const withTransaction_1 = __importDefault(require("./withTransaction"));
35
- 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.concurrentTask = exports.mongoErrorCodes = exports.MongoDecimal = exports.ObjectId = exports.withTransaction = exports.runMigrations = exports.mongoLocker = exports.mongoClient = exports.MigrationsStore = exports.Migration = exports.getMongoLocker = exports.getMongoConfig = exports.getCollection = exports.fixtures = exports.appData = void 0;
7
+ const mongodb_1 = require("mongodb");
8
+ Object.defineProperty(exports, "MongoDecimal", { enumerable: true, get: function () { return mongodb_1.Decimal128; } });
9
+ Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return mongodb_1.ObjectId; } });
10
+ const appData_1 = __importDefault(require("./appData"));
11
+ exports.appData = appData_1.default;
12
+ const concurrentTask_1 = __importDefault(require("./concurrentTask"));
13
+ exports.concurrentTask = concurrentTask_1.default;
14
+ const fixtures_1 = __importDefault(require("./fixtures"));
15
+ exports.fixtures = fixtures_1.default;
16
+ const getCollection_1 = __importDefault(require("./getCollection"));
17
+ exports.getCollection = getCollection_1.default;
18
+ const getMongoConfig_1 = __importDefault(require("./getMongoConfig"));
19
+ exports.getMongoConfig = getMongoConfig_1.default;
20
+ const getMongoLocker_1 = __importDefault(require("./getMongoLocker"));
21
+ exports.getMongoLocker = getMongoLocker_1.default;
22
+ const Migration_1 = __importDefault(require("./migrations/Migration"));
23
+ exports.Migration = Migration_1.default;
24
+ const MigrationsStore_1 = __importDefault(require("./migrations/MigrationsStore"));
25
+ exports.MigrationsStore = MigrationsStore_1.default;
26
+ const runMigrations_1 = __importDefault(require("./migrations/runMigrations"));
27
+ exports.runMigrations = runMigrations_1.default;
28
+ const mongoClient_1 = __importDefault(require("./mongoClient"));
29
+ exports.mongoClient = mongoClient_1.default;
30
+ const mongoErrorCodes_1 = __importDefault(require("./mongoErrorCodes"));
31
+ exports.mongoErrorCodes = mongoErrorCodes_1.default;
32
+ const mongoLocker_1 = __importDefault(require("./mongoLocker"));
33
+ exports.mongoLocker = mongoLocker_1.default;
34
+ const withTransaction_1 = __importDefault(require("./withTransaction"));
35
+ exports.withTransaction = withTransaction_1.default;
36
36
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQSxxQ0FBK0Q7QUE4QjNELDZGQTlCbUIsb0JBQVksT0E4Qm5CO0FBRFoseUZBN0JpQyxrQkFBUSxPQTZCakM7QUE1Qlosd0RBQWdDO0FBZTVCLGtCQWZHLGlCQUFPLENBZUg7QUFkWCxzRUFBOEM7QUE4QjFDLHlCQTlCRyx3QkFBYyxDQThCSDtBQTdCbEIsMERBQWtDO0FBYzlCLG1CQWRHLGtCQUFRLENBY0g7QUFiWixvRUFBNEM7QUFjeEMsd0JBZEcsdUJBQWEsQ0FjSDtBQWJqQixzRUFBOEM7QUFjMUMseUJBZEcsd0JBQWMsQ0FjSDtBQWJsQixzRUFBK0U7QUFjM0UseUJBZEcsd0JBQWMsQ0FjSDtBQWJsQix1RUFBK0M7QUFnQjNDLG9CQWhCRyxtQkFBUyxDQWdCSDtBQWZiLG1GQUEyRDtBQWdCdkQsMEJBaEJHLHlCQUFlLENBZ0JIO0FBZm5CLCtFQUF1RDtBQWtCbkQsd0JBbEJHLHVCQUFhLENBa0JIO0FBakJqQixnRUFBd0M7QUFlcEMsc0JBZkcscUJBQVcsQ0FlSDtBQWRmLHdFQUFnRDtBQW9CNUMsMEJBcEJHLHlCQUFlLENBb0JIO0FBbkJuQixnRUFBd0M7QUFjcEMsc0JBZEcscUJBQVcsQ0FjSDtBQWJmLHdFQUFnRDtBQWU1QywwQkFmRyx5QkFBZSxDQWVIIn0=
package/lib/index.ts CHANGED
@@ -1,34 +1,34 @@
1
- import { Decimal128 as MongoDecimal, ObjectId } from 'mongodb';
2
- import appData from './appData';
3
- import concurrentTask from './concurrentTask';
4
- import fixtures from './fixtures';
5
- import getCollection from './getCollection';
6
- import getMongoConfig from './getMongoConfig';
7
- import getMongoLocker, { LockCallback, LockerOptions } from './getMongoLocker';
8
- import Migration from './migrations/Migration';
9
- import MigrationsStore from './migrations/MigrationsStore';
10
- import runMigrations from './migrations/runMigrations';
11
- import mongoClient from './mongoClient';
12
- import mongoErrorCodes from './mongoErrorCodes';
13
- import mongoLocker from './mongoLocker';
14
- import withTransaction from './withTransaction';
15
-
16
- export {
17
- appData,
18
- fixtures,
19
- getCollection,
20
- getMongoConfig,
21
- getMongoLocker,
22
- LockCallback,
23
- LockerOptions,
24
- Migration,
25
- MigrationsStore,
26
- mongoClient,
27
- mongoLocker,
28
- runMigrations,
29
- withTransaction,
30
- ObjectId,
31
- MongoDecimal,
32
- mongoErrorCodes,
33
- concurrentTask,
34
- };
1
+ import { Decimal128 as MongoDecimal, ObjectId } from 'mongodb';
2
+ import appData from './appData';
3
+ import concurrentTask from './concurrentTask';
4
+ import fixtures from './fixtures';
5
+ import getCollection from './getCollection';
6
+ import getMongoConfig from './getMongoConfig';
7
+ import getMongoLocker, { LockCallback, LockerOptions } from './getMongoLocker';
8
+ import Migration from './migrations/Migration';
9
+ import MigrationsStore from './migrations/MigrationsStore';
10
+ import runMigrations from './migrations/runMigrations';
11
+ import mongoClient from './mongoClient';
12
+ import mongoErrorCodes from './mongoErrorCodes';
13
+ import mongoLocker from './mongoLocker';
14
+ import withTransaction from './withTransaction';
15
+
16
+ export {
17
+ appData,
18
+ fixtures,
19
+ getCollection,
20
+ getMongoConfig,
21
+ getMongoLocker,
22
+ LockCallback,
23
+ LockerOptions,
24
+ Migration,
25
+ MigrationsStore,
26
+ mongoClient,
27
+ mongoLocker,
28
+ runMigrations,
29
+ withTransaction,
30
+ ObjectId,
31
+ MongoDecimal,
32
+ mongoErrorCodes,
33
+ concurrentTask,
34
+ };
@@ -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,29 +1,29 @@
1
- type NextCallback = (err?: Error) => void;
2
-
3
- export default class Migration {
4
-
5
- description: string;
6
-
7
- up: Function;
8
-
9
- down: Function;
10
-
11
- constructor (description: string, up: Function, down = () => null) {
12
- this.description = description;
13
-
14
- // NOTE 'up' and 'down' has to be as properties because of 'migrate' package
15
- this.up = (next: NextCallback) => {
16
- (async () => {
17
- await up();
18
- next();
19
- })().catch(next);
20
- };
21
-
22
- this.down = (next: NextCallback) => {
23
- (async () => {
24
- await down();
25
- next();
26
- })().catch(next);
27
- };
28
- }
29
- }
1
+ type NextCallback = (err?: Error) => void;
2
+
3
+ export default class Migration {
4
+
5
+ description: string;
6
+
7
+ up: Function;
8
+
9
+ down: Function;
10
+
11
+ constructor (description: string, up: Function, down = () => null) {
12
+ this.description = description;
13
+
14
+ // NOTE 'up' and 'down' has to be as properties because of 'migrate' package
15
+ this.up = (next: NextCallback) => {
16
+ (async () => {
17
+ await up();
18
+ next();
19
+ })().catch(next);
20
+ };
21
+
22
+ this.down = (next: NextCallback) => {
23
+ (async () => {
24
+ await down();
25
+ next();
26
+ })().catch(next);
27
+ };
28
+ }
29
+ }
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uc1N0b3JlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiTWlncmF0aW9uc1N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3M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BRU8scUJBQXFCLENBQUUsaUJBQThDO1FBQ3pFLElBQ0ksQ0FBQyxpQkFBaUI7ZUFDZixJQUFBLGdCQUFPLEVBQUMsaUJBQWlCLENBQUMsVUFBVSxDQUFDO2VBQ3JDLENBQUMsSUFBQSxnQkFBTyxFQUFDLGlCQUFpQixDQUFDLFVBQVUsQ0FBQyxFQUFFO1lBQzNDLElBQUksQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLGdCQUFnQixDQUFDLENBQUM7WUFDckMsTUFBTSxJQUFJLEtBQUssQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDO1NBQ3JDO0lBQ0wsQ0FBQztDQUNKO0FBdEVELGtDQXNFQyJ9
@@ -1,81 +1,81 @@
1
- import { isArray, isEmpty, pick } from 'lodash';
2
- import { CallbackError, Migration } from 'migrate';
3
- import { Logger } from 'winston';
4
- import appData from '../appData';
5
-
6
- const DOCUMENT_ID = 'migrations';
7
-
8
- const safeMigrationMsg = 'safeMigration is true, we do not allow empty migrations to be saved. '
9
- + 'If this is new project, feel free to enable it';
10
-
11
- export default class MigrationsStore {
12
- // eslint-disable-next-line no-empty-function
13
- constructor (private _logger: Logger, path: string, private _safeMigration: boolean) {
14
- }
15
-
16
- public save (set: Object, cb: CallbackError) {
17
- try {
18
- this._logger.info('Migration SET', set);
19
- const objToUpdate: any = pick(set, ['lastRun', 'migrations']);
20
- if (this._safeMigration) {
21
- this._checkValidMigrations(objToUpdate);
22
-
23
- const numOfValidMigrations = objToUpdate.migrations
24
- .reduce((prev: number, cur: { timestamp: any; }) => (cur.timestamp ? prev + 1 : prev), 0);
25
-
26
- // If all migrations are renewed=without timestamp (beside the first one that is trying to be applied)
27
- // There can be something wrong
28
- if (objToUpdate.migrations.length >= 3 && numOfValidMigrations <= 1) {
29
- this._logger.error(safeMigrationMsg);
30
-
31
- throw new Error(safeMigrationMsg);
32
- }
33
- }
34
-
35
- appData.updateDocument(DOCUMENT_ID, { $set: objToUpdate }, true)
36
- .then(
37
- () => { cb(null); },
38
- )
39
- .catch(cb);
40
- } catch (err) {
41
- cb(err);
42
- }
43
- }
44
-
45
- public load (
46
- cb: (
47
- err: any,
48
- store: {
49
- lastRun?: string,
50
- migrations: Pick<Migration, 'title' | 'description' | 'timestamp'>[]
51
- }
52
- ) => void,
53
- ) {
54
- appData.getDocument(DOCUMENT_ID)
55
- .then((state: any) => {
56
- if (this._safeMigration) {
57
- this._checkValidMigrations(state);
58
- }
59
-
60
- cb(
61
- null, state || {
62
- lastRun: null,
63
- migrations: [],
64
- },
65
- );
66
- })
67
- .catch((err) => {
68
- cb(err, { migrations: [] });
69
- });
70
- }
71
-
72
- private _checkValidMigrations (objWithMigrations?: { migrations: any } | null) {
73
- if (
74
- !objWithMigrations
75
- || isEmpty(objWithMigrations.migrations)
76
- || !isArray(objWithMigrations.migrations)) {
77
- this._logger.error(safeMigrationMsg);
78
- throw new Error(safeMigrationMsg);
79
- }
80
- }
81
- }
1
+ import { isArray, isEmpty, pick } from 'lodash';
2
+ import { CallbackError, Migration } from 'migrate';
3
+ import { Logger } from 'winston';
4
+ import appData from '../appData';
5
+
6
+ const DOCUMENT_ID = 'migrations';
7
+
8
+ const safeMigrationMsg = 'safeMigration is true, we do not allow empty migrations to be saved. '
9
+ + 'If this is new project, feel free to enable it';
10
+
11
+ export default class MigrationsStore {
12
+ // eslint-disable-next-line no-empty-function
13
+ constructor (private _logger: Logger, path: string, private _safeMigration: boolean) {
14
+ }
15
+
16
+ public save (set: Object, cb: CallbackError) {
17
+ try {
18
+ this._logger.info('Migration SET', set);
19
+ const objToUpdate: any = pick(set, ['lastRun', 'migrations']);
20
+ if (this._safeMigration) {
21
+ this._checkValidMigrations(objToUpdate);
22
+
23
+ const numOfValidMigrations = objToUpdate.migrations
24
+ .reduce((prev: number, cur: { timestamp: any; }) => (cur.timestamp ? prev + 1 : prev), 0);
25
+
26
+ // If all migrations are renewed=without timestamp (beside the first one that is trying to be applied)
27
+ // There can be something wrong
28
+ if (objToUpdate.migrations.length >= 3 && numOfValidMigrations <= 1) {
29
+ this._logger.error(safeMigrationMsg);
30
+
31
+ throw new Error(safeMigrationMsg);
32
+ }
33
+ }
34
+
35
+ appData.updateDocument(DOCUMENT_ID, { $set: objToUpdate }, true)
36
+ .then(
37
+ () => { cb(null); },
38
+ )
39
+ .catch(cb);
40
+ } catch (err) {
41
+ cb(err);
42
+ }
43
+ }
44
+
45
+ public load (
46
+ cb: (
47
+ err: any,
48
+ store: {
49
+ lastRun?: string,
50
+ migrations: Pick<Migration, 'title' | 'description' | 'timestamp'>[]
51
+ }
52
+ ) => void,
53
+ ) {
54
+ appData.getDocument(DOCUMENT_ID)
55
+ .then((state: any) => {
56
+ if (this._safeMigration) {
57
+ this._checkValidMigrations(state);
58
+ }
59
+
60
+ cb(
61
+ null, state || {
62
+ lastRun: null,
63
+ migrations: [],
64
+ },
65
+ );
66
+ })
67
+ .catch((err) => {
68
+ cb(err, { migrations: [] });
69
+ });
70
+ }
71
+
72
+ private _checkValidMigrations (objWithMigrations?: { migrations: any } | null) {
73
+ if (
74
+ !objWithMigrations
75
+ || isEmpty(objWithMigrations.migrations)
76
+ || !isArray(objWithMigrations.migrations)) {
77
+ this._logger.error(safeMigrationMsg);
78
+ throw new Error(safeMigrationMsg);
79
+ }
80
+ }
81
+ }
@@ -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>;