@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
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicnVuTWlncmF0aW9ucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInJ1bk1pZ3JhdGlvbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxxQ0FBNkM7QUFFN0Msd0VBQWdEO0FBRWhEOzs7Ozs7R0FNRztBQUNZLEtBQUssVUFBVSxhQUFhLENBQ3ZDLE1BQWMsRUFDZCxTQUFpQixFQUNqQixFQUNJLGVBQWUsR0FBRyxLQUFLLEVBQ3ZCLGFBQWEsR0FBRyxJQUFJLEdBQ3ZCO0lBRUQsT0FBTyxJQUFJLE9BQU8sQ0FBTyxDQUFDLE9BQU8sRUFBRSxNQUFNLEVBQUUsRUFBRTtRQUN6QyxJQUFBLGNBQUksRUFDQTtZQUNJLFVBQVUsRUFBRSxJQUFJLHlCQUFlLENBQUMsTUFBTSxFQUFFLFNBQVMsRUFBRSxhQUFhLENBQUM7WUFDakUsbUJBQW1CLEVBQUUsU0FBUztZQUM5QixjQUFjLEVBQUUsQ0FBQyxJQUFZLEVBQUUsRUFBRSxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUMsS0FBSyxDQUFDO1NBQ3pELEVBQ0QsQ0FBQyxHQUFpQixFQUFFLEdBQWlCLEVBQUUsRUFBRTtZQUNyQyxJQUFJLEdBQUcsRUFBRTtnQkFDTCxNQUFNLENBQUMsS0FBSyxDQUFDLHFDQUFxQyxFQUFFLEdBQUcsQ0FBQyxDQUFDO2dCQUN6RCxNQUFNLENBQUMsR0FBRyxDQUFDLENBQUM7Z0JBQ1osT0FBTzthQUNWO1lBRUQsR0FBRyxDQUFDLEVBQUUsQ0FBQyxTQUFTLEVBQUUsQ0FBQyxHQUFXLEVBQUUsRUFBRTtnQkFDOUIsTUFBTSxDQUFDLElBQUksQ0FBQyxTQUFTLEVBQUUsR0FBRyxDQUFDLENBQUM7WUFDaEMsQ0FBQyxDQUFDLENBQUM7WUFFSCxHQUFHLENBQUMsRUFBRSxDQUFDLFdBQVcsRUFBRSxDQUFDLFNBQWMsRUFBRSxTQUFpQixFQUFFLEVBQUU7Z0JBQ3RELE1BQU0sQ0FBQyxJQUFJLENBQUMsV0FBVyxTQUFTLFlBQVksRUFBRSxFQUFFLEtBQUssRUFBRSxTQUFTLENBQUMsS0FBSyxFQUFFLENBQUMsQ0FBQztZQUM5RSxDQUFDLENBQUMsQ0FBQztZQUVILEdBQUcsQ0FBQyxFQUFFLENBQUMsQ0FBQyxLQUFhLEVBQUUsRUFBRTtnQkFDckIsSUFBSSxLQUFLLEVBQUU7b0JBQ1AsTUFBTSxDQUFDLEtBQUssQ0FBQyw4QkFBOEIsRUFBRSxLQUFLLENBQUMsQ0FBQztvQkFDcEQsSUFBSSxDQUFDLGVBQWUsRUFBRTt3QkFDbEIsTUFBTSxDQUFDLEtBQUssQ0FBQyxDQUFDO3dCQUNkLE9BQU87cUJBQ1Y7aUJBQ0o7cUJBQU07b0JBQ0gsTUFBTSxDQUFDLElBQUksQ0FBQyw2QkFBNkIsQ0FBQyxDQUFDO2lCQUM5QztnQkFFRCxPQUFPLEVBQUUsQ0FBQztZQUNkLENBQUMsQ0FBQyxDQUFDO1FBQ1AsQ0FBQyxDQUFDLENBQUM7SUFDWCxDQUFDLENBQUMsQ0FBQztBQUNQLENBQUM7QUE3Q0QsZ0NBNkNDIn0=
@@ -1,57 +1,57 @@
1
- import { load, MigrationSet } from 'migrate';
2
- import { Logger } from 'winston';
3
- import MigrationsStore from './MigrationsStore';
4
-
5
- /**
6
- * In case of fail - logs the result and returns rejected promise
7
- * @param {Logger} logger Logger
8
- * @param {string} directory Path to directory where migrations are
9
- * @param {boolean} continueOnError If app crashes on error or continue
10
- * @param {boolean} safeMigration Do not allow to rewrite all migrations with empty array
11
- */
12
- export default async function runMigrations (
13
- logger: Logger,
14
- directory: string,
15
- {
16
- continueOnError = false,
17
- safeMigration = true,
18
- },
19
- ) {
20
- return new Promise<void>((resolve, reject) => {
21
- load(
22
- {
23
- stateStore: new MigrationsStore(logger, directory, safeMigration),
24
- migrationsDirectory: directory,
25
- filterFunction: (file: string) => file.endsWith('.js'),
26
- },
27
- (err: Error | null, set: MigrationSet) => {
28
- if (err) {
29
- logger.error('Migrations did not run due to error', err);
30
- reject(err);
31
- return;
32
- }
33
-
34
- set.on('warning', (msg: string) => {
35
- logger.warn('warning', msg);
36
- });
37
-
38
- set.on('migration', (migration: any, direction: string) => {
39
- logger.info(`Running ${direction} migration`, { title: migration.title });
40
- });
41
-
42
- set.up((error?: Error) => {
43
- if (error) {
44
- logger.error('A migration ended with error', error);
45
- if (!continueOnError) {
46
- reject(error);
47
- return;
48
- }
49
- } else {
50
- logger.info('Migrations successfully ran');
51
- }
52
-
53
- resolve();
54
- });
55
- });
56
- });
57
- }
1
+ import { load, MigrationSet } from 'migrate';
2
+ import { Logger } from 'winston';
3
+ import MigrationsStore from './MigrationsStore';
4
+
5
+ /**
6
+ * In case of fail - logs the result and returns rejected promise
7
+ * @param {Logger} logger Logger
8
+ * @param {string} directory Path to directory where migrations are
9
+ * @param {boolean} continueOnError If app crashes on error or continue
10
+ * @param {boolean} safeMigration Do not allow to rewrite all migrations with empty array
11
+ */
12
+ export default async function runMigrations (
13
+ logger: Logger,
14
+ directory: string,
15
+ {
16
+ continueOnError = false,
17
+ safeMigration = true,
18
+ },
19
+ ) {
20
+ return new Promise<void>((resolve, reject) => {
21
+ load(
22
+ {
23
+ stateStore: new MigrationsStore(logger, directory, safeMigration),
24
+ migrationsDirectory: directory,
25
+ filterFunction: (file: string) => file.endsWith('.js'),
26
+ },
27
+ (err: Error | null, set: MigrationSet) => {
28
+ if (err) {
29
+ logger.error('Migrations did not run due to error', err);
30
+ reject(err);
31
+ return;
32
+ }
33
+
34
+ set.on('warning', (msg: string) => {
35
+ logger.warn('warning', msg);
36
+ });
37
+
38
+ set.on('migration', (migration: any, direction: string) => {
39
+ logger.info(`Running ${direction} migration`, { title: migration.title });
40
+ });
41
+
42
+ set.up((error?: Error) => {
43
+ if (error) {
44
+ logger.error('A migration ended with error', error);
45
+ if (!continueOnError) {
46
+ reject(error);
47
+ return;
48
+ }
49
+ } else {
50
+ logger.info('Migrations successfully ran');
51
+ }
52
+
53
+ resolve();
54
+ });
55
+ });
56
+ });
57
+ }
@@ -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,7 +1,7 @@
1
- import getCollection from '../getCollection';
2
- import Migration from './Migration';
3
-
4
- export = new Migration('[ADD DESCRIPTION HERE]', async () => {
5
- // add logic here
6
- await getCollection('exampleCollection');
7
- });
1
+ import getCollection from '../getCollection';
2
+ import Migration from './Migration';
3
+
4
+ export = new Migration('[ADD DESCRIPTION HERE]', async () => {
5
+ // add logic here
6
+ await getCollection('exampleCollection');
7
+ });
@@ -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,25 +1,25 @@
1
- import { defaultsDeep } from 'lodash';
2
- import { MongoClient, MongoClientOptions, ObjectId } from 'mongodb';
3
-
4
- export type Key = string | number | ObjectId;
5
-
6
- const mongoClient = {
7
- _client: <MongoClient|null> null,
8
-
9
- init (mongodbUrl: string, mongoOptions?: MongoClientOptions) {
10
- this._client = new MongoClient(
11
- mongodbUrl,
12
- defaultsDeep(mongoOptions),
13
- );
14
- },
15
-
16
- getClient () {
17
- if (this._client) {
18
- return this._client;
19
- }
20
-
21
- throw new Error('MongoDb must be initialized before use.');
22
- },
23
- };
24
-
25
- export default mongoClient;
1
+ import { defaultsDeep } from 'lodash';
2
+ import { MongoClient, MongoClientOptions, ObjectId } from 'mongodb';
3
+
4
+ export type Key = string | number | ObjectId;
5
+
6
+ const mongoClient = {
7
+ _client: <MongoClient|null> null,
8
+
9
+ init (mongodbUrl: string, mongoOptions?: MongoClientOptions) {
10
+ this._client = new MongoClient(
11
+ mongodbUrl,
12
+ defaultsDeep(mongoOptions),
13
+ );
14
+ },
15
+
16
+ getClient () {
17
+ if (this._client) {
18
+ return this._client;
19
+ }
20
+
21
+ throw new Error('MongoDb must be initialized before use.');
22
+ },
23
+ };
24
+
25
+ export default mongoClient;
@@ -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,10 +1,10 @@
1
- const DUPLICATE_KEY_INSERT = 11000;
2
- const DUPLICATE_KEY_UPDATE = 11001;
3
-
4
- const mongoErrorCodes = {
5
- DUPLICATE_KEY_INSERT,
6
- DUPLICATE_KEY_UPDATE,
7
- DUPLICATE_KEY: [DUPLICATE_KEY_INSERT, DUPLICATE_KEY_UPDATE],
8
- };
9
-
10
- export default mongoErrorCodes;
1
+ const DUPLICATE_KEY_INSERT = 11000;
2
+ const DUPLICATE_KEY_UPDATE = 11001;
3
+
4
+ const mongoErrorCodes = {
5
+ DUPLICATE_KEY_INSERT,
6
+ DUPLICATE_KEY_UPDATE,
7
+ DUPLICATE_KEY: [DUPLICATE_KEY_INSERT, DUPLICATE_KEY_UPDATE],
8
+ };
9
+
10
+ export default mongoErrorCodes;
@@ -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,15 +1,15 @@
1
- import getCollection from './getCollection';
2
- import getMongoLocker, { LockCallback, LockerOptions } from './getMongoLocker';
3
- import { Key } from './mongoClient';
4
-
5
- let lockerPromise: ReturnType<typeof getMongoLocker>;
6
-
7
- export default async function <T> (key: Key, callback: LockCallback<T>, options: LockerOptions = {}): Promise<T> {
8
- if (!lockerPromise) {
9
- lockerPromise = getMongoLocker(getCollection<any>('appLocks'));
10
- }
11
-
12
- const locker = await lockerPromise;
13
-
14
- return locker(key, callback, options);
15
- }
1
+ import getCollection from './getCollection';
2
+ import getMongoLocker, { LockCallback, LockerOptions } from './getMongoLocker';
3
+ import { Key } from './mongoClient';
4
+
5
+ let lockerPromise: ReturnType<typeof getMongoLocker>;
6
+
7
+ export default async function <T> (key: Key, callback: LockCallback<T>, options: LockerOptions = {}): Promise<T> {
8
+ if (!lockerPromise) {
9
+ lockerPromise = getMongoLocker(getCollection<any>('appLocks'));
10
+ }
11
+
12
+ const locker = await lockerPromise;
13
+
14
+ return locker(key, callback, options);
15
+ }
@@ -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;
@@ -1,21 +1,21 @@
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 mongoClient_1 = __importDefault(require("./mongoClient"));
7
- exports.default = async (callback, options) => {
8
- const session = mongoClient_1.default.getClient().startSession();
9
- try {
10
- let result;
11
- await session.withTransaction(async () => {
12
- result = await callback(session);
13
- }, options);
14
- // @ts-ignore
15
- return result;
16
- }
17
- finally {
18
- await session.endSession();
19
- }
20
- };
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 mongoClient_1 = __importDefault(require("./mongoClient"));
7
+ exports.default = async (callback, options) => {
8
+ const session = mongoClient_1.default.getClient().startSession();
9
+ try {
10
+ let result;
11
+ await session.withTransaction(async () => {
12
+ result = await callback(session);
13
+ }, options);
14
+ // @ts-ignore
15
+ return result;
16
+ }
17
+ finally {
18
+ await session.endSession();
19
+ }
20
+ };
21
21
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2l0aFRyYW5zYWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsid2l0aFRyYW5zYWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQ0EsZ0VBQXdDO0FBRXhDLGtCQUFlLEtBQUssRUFDaEIsUUFBZ0QsRUFDaEQsT0FBNEIsRUFDbEIsRUFBRTtJQUVaLE1BQU0sT0FBTyxHQUFHLHFCQUFXLENBQUMsU0FBUyxFQUFFLENBQUMsWUFBWSxFQUFFLENBQUM7SUFFdkQsSUFBSTtRQUNBLElBQUksTUFBUyxDQUFDO1FBRWQsTUFBTSxPQUFPLENBQUMsZUFBZSxDQUFDLEtBQUssSUFBSSxFQUFFO1lBQ3JDLE1BQU0sR0FBRyxNQUFNLFFBQVEsQ0FBQyxPQUFPLENBQUMsQ0FBQztRQUNyQyxDQUFDLEVBQUUsT0FBTyxDQUFDLENBQUM7UUFFWixhQUFhO1FBQ2IsT0FBTyxNQUFNLENBQUM7S0FFakI7WUFBUztRQUNOLE1BQU0sT0FBTyxDQUFDLFVBQVUsRUFBRSxDQUFDO0tBQzlCO0FBQ0wsQ0FBQyxDQUFDIn0=
@@ -1,24 +1,24 @@
1
- import { ClientSession, TransactionOptions } from 'mongodb';
2
- import mongoClient from './mongoClient';
3
-
4
- export default async <T> (
5
- callback: (session: ClientSession) => Promise<T>,
6
- options?: TransactionOptions,
7
- ): Promise<T> => {
8
-
9
- const session = mongoClient.getClient().startSession();
10
-
11
- try {
12
- let result: T;
13
-
14
- await session.withTransaction(async () => {
15
- result = await callback(session);
16
- }, options);
17
-
18
- // @ts-ignore
19
- return result;
20
-
21
- } finally {
22
- await session.endSession();
23
- }
24
- };
1
+ import { ClientSession, TransactionOptions } from 'mongodb';
2
+ import mongoClient from './mongoClient';
3
+
4
+ export default async <T> (
5
+ callback: (session: ClientSession) => Promise<T>,
6
+ options?: TransactionOptions,
7
+ ): Promise<T> => {
8
+
9
+ const session = mongoClient.getClient().startSession();
10
+
11
+ try {
12
+ let result: T;
13
+
14
+ await session.withTransaction(async () => {
15
+ result = await callback(session);
16
+ }, options);
17
+
18
+ // @ts-ignore
19
+ return result;
20
+
21
+ } finally {
22
+ await session.endSession();
23
+ }
24
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyous/mongodb",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/Storyous/mono-utils#readme",
6
6
  "license": "ISC",
@@ -46,5 +46,5 @@
46
46
  "peerDependencies": {
47
47
  "mongodb": ">=4 <5"
48
48
  },
49
- "gitHead": "54a86d4148c85f9368e6c1b2a32802851d651d5f"
49
+ "gitHead": "9b0a09c2919784b0dd8dce0c497a35bca76a083d"
50
50
  }