@biorate/mongodb 0.29.1 → 0.30.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.30.0](https://github.com/biorate/core/compare/v0.29.1...v0.30.0) (2022-06-20)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * *.ts into npmignore ([6a6be03](https://github.com/biorate/core/commit/6a6be030a1e8923df4b03d518f08618e759d06fa))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [0.29.1](https://github.com/biorate/core/compare/v0.29.0...v0.29.1) (2022-06-20)
7
18
 
8
19
  **Note:** Version bump only for package @biorate/mongodb
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongoDBCantConnectError = void 0;
4
+ const errors_1 = require("@biorate/errors");
5
+ class MongoDBCantConnectError extends errors_1.BaseError {
6
+ constructor(e) {
7
+ super(`Can't connect to MongoDB: [%s]`, [e.message]);
8
+ }
9
+ }
10
+ exports.MongoDBCantConnectError = MongoDBCantConnectError;
11
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AAE5C,MAAa,uBAAwB,SAAQ,kBAAS;IACpD,YAAmB,CAAQ;QACzB,KAAK,CAAC,gCAAgC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACvD,CAAC;CACF;AAJD,0DAIC"}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
14
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
18
+ };
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ var __metadata = (this && this.__metadata) || function (k, v) {
23
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.model = exports.MongoDBConnector = void 0;
27
+ const inversion_1 = require("@biorate/inversion");
28
+ const tools_1 = require("@biorate/tools");
29
+ const connector_1 = require("@biorate/connector");
30
+ const mongoose_1 = require("mongoose");
31
+ const typegoose_1 = require("@typegoose/typegoose");
32
+ const errors_1 = require("./errors");
33
+ __exportStar(require("./errors"), exports);
34
+ __exportStar(require("./interfaces"), exports);
35
+ let MongoDBConnector = class MongoDBConnector extends connector_1.Connector {
36
+ constructor() {
37
+ super(...arguments);
38
+ this.namespace = 'MongoDB';
39
+ }
40
+ async connect(config) {
41
+ let connection;
42
+ try {
43
+ connection = (0, mongoose_1.createConnection)(config.host, config.options);
44
+ await tools_1.events.once(connection, 'open');
45
+ }
46
+ catch (e) {
47
+ throw new errors_1.MongoDBCantConnectError(e);
48
+ }
49
+ return connection;
50
+ }
51
+ async initialize() {
52
+ connections = this.connections;
53
+ await super.initialize();
54
+ }
55
+ };
56
+ __decorate([
57
+ (0, inversion_1.init)(),
58
+ __metadata("design:type", Function),
59
+ __metadata("design:paramtypes", []),
60
+ __metadata("design:returntype", Promise)
61
+ ], MongoDBConnector.prototype, "initialize", null);
62
+ MongoDBConnector = __decorate([
63
+ (0, inversion_1.injectable)()
64
+ ], MongoDBConnector);
65
+ exports.MongoDBConnector = MongoDBConnector;
66
+ let connections = null;
67
+ const model = (Model, connection, options = {}) => {
68
+ return (proto, key) => {
69
+ Object.defineProperty(proto, key, {
70
+ get() {
71
+ return (0, typegoose_1.getModelForClass)(Model, {
72
+ existingConnection: connection
73
+ ? connections.get(connection)
74
+ : [...connections][0][1],
75
+ options,
76
+ });
77
+ },
78
+ configurable: false,
79
+ });
80
+ };
81
+ };
82
+ exports.model = model;
83
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAsD;AACtD,0CAAwC;AACxC,kDAA+C;AAC/C,uCAA4C;AAC5C,oDAAwD;AACxD,qCAAmD;AAGnD,2CAAyB;AACzB,+CAA6B;AA2F7B,IAAa,gBAAgB,GAA7B,MAAa,gBAAiB,SAAQ,qBAA6C;IAAnF;;QAIqB,cAAS,GAAG,SAAS,CAAC;IAqB3C,CAAC;IAjBW,KAAK,CAAC,OAAO,CAAC,MAAsB;QAC5C,IAAI,UAA8B,CAAC;QACnC,IAAI;YACF,UAAU,GAAG,IAAA,2BAAgB,EAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;YAC3D,MAAM,cAAM,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;SACvC;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,IAAI,gCAAuB,CAAC,CAAC,CAAC,CAAC;SACtC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;IAIiB,KAAK,CAAC,UAAU;QAChC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QAC/B,MAAM,KAAK,CAAC,UAAU,EAAE,CAAC;IAC3B,CAAC;CACF,CAAA;AAJS;IAAP,IAAA,gBAAI,GAAE;;;;kDAGN;AAxBU,gBAAgB;IAD5B,IAAA,sBAAU,GAAE;GACA,gBAAgB,CAyB5B;AAzBY,4CAAgB;AA6B7B,IAAI,WAAW,GAAoC,IAAI,CAAC;AAIjD,MAAM,KAAK,GAAG,CACnB,KAA8B,EAC9B,UAAmB,EACnB,UAAmC,EAAE,EACrC,EAAE;IACF,OAAO,CAAC,KAAW,EAAE,GAAY,EAAE,EAAE;QACnC,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE;YAChC,GAAG;gBACD,OAAO,IAAA,4BAAgB,EAAC,KAAK,EAAE;oBAC7B,kBAAkB,EAAE,UAAU;wBAC5B,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC;wBAC7B,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC1B,OAAO;iBACR,CAAC,CAAC;YACL,CAAC;YACD,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAlBW,QAAA,KAAK,SAkBhB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biorate/mongodb",
3
- "version": "0.29.1",
3
+ "version": "0.30.0",
4
4
  "description": "Mongodb ORM connector based on mongoose and typegoose",
5
5
  "main": "dist",
6
6
  "scripts": {
@@ -24,14 +24,14 @@
24
24
  "author": "llevkin",
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
- "@biorate/config": "0.29.1",
28
- "@biorate/connector": "0.29.1",
29
- "@biorate/errors": "0.29.0",
30
- "@biorate/inversion": "0.29.1",
31
- "@biorate/tools": "0.29.1",
27
+ "@biorate/config": "0.30.0",
28
+ "@biorate/connector": "0.30.0",
29
+ "@biorate/errors": "0.30.0",
30
+ "@biorate/inversion": "0.30.0",
31
+ "@biorate/tools": "0.30.0",
32
32
  "@typegoose/typegoose": "^9.8.1",
33
33
  "mongodb": "^4.5.0",
34
34
  "mongoose": "^6.3.1"
35
35
  },
36
- "gitHead": "5b2e555c3d82c8d276aa9385ebc0eff28c68db33"
36
+ "gitHead": "4e2b75f1a37d93bfb4854bd64ed9691781c2b800"
37
37
  }
@@ -0,0 +1,36 @@
1
+ import { use } from 'chai';
2
+ import { jestSnapshotPlugin } from 'mocha-chai-jest-snapshot';
3
+ import { inject, container, Types, Core } from '@biorate/inversion';
4
+ import { IConfig, Config } from '@biorate/config';
5
+ import { MongoDBConnector, IMongoDBConnector, model } from '../../src';
6
+ import { ReturnModelType } from '@typegoose/typegoose';
7
+ import { TestModel } from './models';
8
+
9
+ export * from './models';
10
+
11
+ use(jestSnapshotPlugin());
12
+
13
+ export const dbName = 'test';
14
+
15
+ export class Root extends Core() {
16
+ @inject(MongoDBConnector) public connector: IMongoDBConnector;
17
+ @model(TestModel) public test: ReturnModelType<typeof TestModel>;
18
+ }
19
+
20
+ container.bind<IConfig>(Types.Config).to(Config).inSingletonScope();
21
+ container.bind<IMongoDBConnector>(MongoDBConnector).toSelf().inSingletonScope();
22
+ container.bind<Root>(Root).toSelf().inSingletonScope();
23
+
24
+ container.get<IConfig>(Types.Config).merge({
25
+ MongoDB: [
26
+ {
27
+ name: 'connection',
28
+ host: 'mongodb://localhost:27017/',
29
+ options: {
30
+ useNewUrlParser: true,
31
+ useUnifiedTopology: true,
32
+ dbName,
33
+ },
34
+ },
35
+ ],
36
+ });
@@ -0,0 +1 @@
1
+ export * from './test';