@midwayjs/typegoose 3.0.0-alpha.9 → 3.0.0-beta.4

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/CHANGELOG.md CHANGED
@@ -3,6 +3,49 @@
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
+ # [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
7
+
8
+ **Note:** Version bump only for package @midwayjs/typegoose
9
+
10
+
11
+
12
+
13
+
14
+ # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
15
+
16
+
17
+ ### Features
18
+
19
+ * add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
20
+
21
+
22
+
23
+
24
+
25
+ # [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
26
+
27
+ **Note:** Version bump only for package @midwayjs/typegoose
28
+
29
+
30
+
31
+
32
+
33
+ # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
34
+
35
+
36
+ ### Bug Fixes
37
+
38
+ * remove connection key ([#1337](https://github.com/midwayjs/midway/issues/1337)) ([6ac219e](https://github.com/midwayjs/midway/commit/6ac219e786792b32d19a364bffbe9e6318c2f9e1))
39
+
40
+
41
+ ### Features
42
+
43
+ * add mongoose component and support multi-instance for typegoose ([#1334](https://github.com/midwayjs/midway/issues/1334)) ([ca0b73f](https://github.com/midwayjs/midway/commit/ca0b73fec77e8871e4001b4c9d3e45397ce32450))
44
+
45
+
46
+
47
+
48
+
6
49
  ## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
7
50
 
8
51
  **Note:** Version bump only for package @midwayjs/typegoose
@@ -1,5 +1,14 @@
1
- export declare class AutoConfiguration {
2
- onReady(app: any): Promise<void>;
1
+ import * as mongoose from '@midwayjs/mongoose';
2
+ import { IMidwayApplication, MidwayDecoratorService } from '@midwayjs/core';
3
+ export declare class TypegooseConfiguration {
4
+ connectionFactory: mongoose.MongooseConnectionServiceFactory;
5
+ oldMongooseConfig: any;
6
+ legacyMode: boolean;
7
+ app: IMidwayApplication;
8
+ decoratorService: MidwayDecoratorService;
9
+ modelMap: WeakMap<object, any>;
10
+ init(): Promise<void>;
11
+ onReady(): Promise<void>;
3
12
  onStop(): Promise<void>;
4
13
  }
5
14
  //# sourceMappingURL=configuration.d.ts.map
@@ -5,24 +5,81 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  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;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
8
11
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AutoConfiguration = void 0;
12
+ exports.TypegooseConfiguration = void 0;
10
13
  const decorator_1 = require("@midwayjs/decorator");
11
- const path_1 = require("path");
12
- const mongoose = require("mongoose");
13
- let AutoConfiguration = class AutoConfiguration {
14
- async onReady(app) {
15
- await app.getAsync('mongoose:mongooseService');
14
+ const mongoose = require("@midwayjs/mongoose");
15
+ const interface_1 = require("./interface");
16
+ const typegoose_1 = require("@typegoose/typegoose");
17
+ const mongo = require("mongoose");
18
+ const core_1 = require("@midwayjs/core");
19
+ let TypegooseConfiguration = class TypegooseConfiguration {
20
+ constructor() {
21
+ this.legacyMode = false;
22
+ this.modelMap = new WeakMap();
23
+ }
24
+ async init() {
25
+ this.decoratorService.registerPropertyHandler(interface_1.ENTITY_MODEL_KEY, (propertyName, meta) => {
26
+ return this.modelMap.get(meta.modelKey);
27
+ });
28
+ }
29
+ async onReady() {
30
+ var _a, _b;
31
+ const Models = (0, decorator_1.listModule)(interface_1.ENTITY_MODEL_KEY);
32
+ for (const Model of Models) {
33
+ const metadata = (_a = (0, decorator_1.getClassMetadata)(interface_1.ENTITY_MODEL_KEY, Model)) !== null && _a !== void 0 ? _a : {};
34
+ const connectionName = (_b = metadata.connectionName) !== null && _b !== void 0 ? _b : 'default';
35
+ const conn = this.connectionFactory.get(connectionName);
36
+ if (conn) {
37
+ const model = (0, typegoose_1.getModelForClass)(Model, { existingConnection: conn });
38
+ this.modelMap.set(Model, model);
39
+ }
40
+ else {
41
+ throw new Error(`connection name ${metadata.connectionName} not found`);
42
+ }
43
+ }
44
+ // 兼容老代码
45
+ if (Models.length === 0 && this.oldMongooseConfig['uri']) {
46
+ this.legacyMode = true;
47
+ await mongo.connect(this.oldMongooseConfig.uri, this.oldMongooseConfig.options);
48
+ }
16
49
  }
17
50
  async onStop() {
18
- await mongoose.disconnect();
51
+ if (this.legacyMode) {
52
+ await mongo.disconnect();
53
+ }
19
54
  }
20
55
  };
21
- AutoConfiguration = __decorate([
22
- decorator_1.Configuration({
23
- namespace: 'mongoose',
24
- importConfigs: [path_1.join(__dirname, 'config')],
56
+ __decorate([
57
+ (0, decorator_1.Inject)(),
58
+ __metadata("design:type", mongoose.MongooseConnectionServiceFactory)
59
+ ], TypegooseConfiguration.prototype, "connectionFactory", void 0);
60
+ __decorate([
61
+ (0, decorator_1.Config)('mongoose'),
62
+ __metadata("design:type", Object)
63
+ ], TypegooseConfiguration.prototype, "oldMongooseConfig", void 0);
64
+ __decorate([
65
+ (0, decorator_1.App)(),
66
+ __metadata("design:type", Object)
67
+ ], TypegooseConfiguration.prototype, "app", void 0);
68
+ __decorate([
69
+ (0, decorator_1.Inject)(),
70
+ __metadata("design:type", core_1.MidwayDecoratorService)
71
+ ], TypegooseConfiguration.prototype, "decoratorService", void 0);
72
+ __decorate([
73
+ (0, decorator_1.Init)(),
74
+ __metadata("design:type", Function),
75
+ __metadata("design:paramtypes", []),
76
+ __metadata("design:returntype", Promise)
77
+ ], TypegooseConfiguration.prototype, "init", null);
78
+ TypegooseConfiguration = __decorate([
79
+ (0, decorator_1.Configuration)({
80
+ namespace: 'typegoose',
81
+ imports: [mongoose],
25
82
  })
26
- ], AutoConfiguration);
27
- exports.AutoConfiguration = AutoConfiguration;
83
+ ], TypegooseConfiguration);
84
+ exports.TypegooseConfiguration = TypegooseConfiguration;
28
85
  //# sourceMappingURL=configuration.js.map
@@ -0,0 +1,3 @@
1
+ import { EntityOptions } from '../interface';
2
+ export declare function EntityModel(options?: EntityOptions): ClassDecorator;
3
+ //# sourceMappingURL=entityModel.d.ts.map
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EntityModel = void 0;
4
+ const decorator_1 = require("@midwayjs/decorator");
5
+ const interface_1 = require("../interface");
6
+ function EntityModel(options) {
7
+ return (target) => {
8
+ (0, decorator_1.saveModule)(interface_1.ENTITY_MODEL_KEY, target);
9
+ (0, decorator_1.saveClassMetadata)(interface_1.ENTITY_MODEL_KEY, options, target);
10
+ };
11
+ }
12
+ exports.EntityModel = EntityModel;
13
+ //# sourceMappingURL=entityModel.js.map
@@ -0,0 +1,2 @@
1
+ export declare function InjectEntityModel(modelKey: any): PropertyDecorator;
2
+ //# sourceMappingURL=injectEntityModel.d.ts.map
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InjectEntityModel = void 0;
4
+ const decorator_1 = require("@midwayjs/decorator");
5
+ const interface_1 = require("../interface");
6
+ function InjectEntityModel(modelKey) {
7
+ return (0, decorator_1.createCustomPropertyDecorator)(interface_1.ENTITY_MODEL_KEY, {
8
+ modelKey,
9
+ });
10
+ }
11
+ exports.InjectEntityModel = InjectEntityModel;
12
+ //# sourceMappingURL=injectEntityModel.js.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- export { AutoConfiguration as Configuration } from './configuration';
2
- export * from './service/mongoose';
3
- export * from '@typegoose/typegoose';
4
- export * from './interface/config.type';
1
+ export { TypegooseConfiguration as Configuration } from './configuration';
2
+ export * from './decorator/entityModel';
3
+ export * from './decorator/injectEntityModel';
5
4
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -12,8 +12,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.Configuration = void 0;
14
14
  var configuration_1 = require("./configuration");
15
- Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.AutoConfiguration; } });
16
- __exportStar(require("./service/mongoose"), exports);
17
- __exportStar(require("@typegoose/typegoose"), exports);
18
- __exportStar(require("./interface/config.type"), exports);
15
+ Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.TypegooseConfiguration; } });
16
+ __exportStar(require("./decorator/entityModel"), exports);
17
+ __exportStar(require("./decorator/injectEntityModel"), exports);
19
18
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,5 @@
1
+ export interface EntityOptions {
2
+ connectionName: string;
3
+ }
4
+ export declare const ENTITY_MODEL_KEY = "TYPEGOOSE:MODEL";
5
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENTITY_MODEL_KEY = void 0;
4
+ exports.ENTITY_MODEL_KEY = 'TYPEGOOSE:MODEL';
5
+ //# sourceMappingURL=interface.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/typegoose",
3
- "version": "3.0.0-alpha.9+d5acc750",
3
+ "version": "3.0.0-beta.4",
4
4
  "description": "Midway Component for typegoose",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -16,15 +16,19 @@
16
16
  "dist/**/*.js",
17
17
  "dist/**/*.d.ts"
18
18
  ],
19
+ "engines": {
20
+ "node": ">=12"
21
+ },
19
22
  "license": "MIT",
23
+ "dependencies": {
24
+ "@midwayjs/mongoose": "^3.0.0-beta.4"
25
+ },
20
26
  "devDependencies": {
21
- "@midwayjs/core": "^3.0.0-alpha.9+d5acc750",
22
- "@midwayjs/decorator": "^3.0.0-alpha.2",
23
- "@midwayjs/koa": "^3.0.0-alpha.9+d5acc750",
24
- "@midwayjs/mock": "^3.0.0-alpha.9+d5acc750",
25
- "@typegoose/typegoose": "^7.4.7",
26
- "mongodb-memory-server": "^6.9.6",
27
- "mongoose": "^5.10.18"
27
+ "@midwayjs/core": "^3.0.0-beta.4",
28
+ "@midwayjs/decorator": "^3.0.0-beta.4",
29
+ "@midwayjs/mock": "^3.0.0-beta.4",
30
+ "@typegoose/typegoose": "^9.0.0",
31
+ "mongoose": "~6.0.11"
28
32
  },
29
- "gitHead": "d5acc7505275ea9d566edd38e5e0377141e0abc1"
33
+ "gitHead": "02e2144e302f807770b512b0d89da3145b1cbf2e"
30
34
  }
@@ -1,9 +0,0 @@
1
- export declare const mongoose: {
2
- uri: string;
3
- options: {
4
- useNewUrlParser: boolean;
5
- useUnifiedTopology: boolean;
6
- dbName: string;
7
- };
8
- };
9
- //# sourceMappingURL=config.default.d.ts.map
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mongoose = void 0;
4
- exports.mongoose = {
5
- uri: 'mongodb://localhost:27017/',
6
- options: { useNewUrlParser: true, useUnifiedTopology: true, dbName: 'test' },
7
- };
8
- //# sourceMappingURL=config.default.js.map
@@ -1,6 +0,0 @@
1
- import * as mongoose from 'mongoose';
2
- export declare type DefaultConfig = {
3
- uri: string;
4
- options: mongoose.ConnectionOptions;
5
- };
6
- //# sourceMappingURL=config.type.d.ts.map
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=config.type.js.map
@@ -1,5 +0,0 @@
1
- export declare class MongooseService {
2
- config: any;
3
- init(): Promise<void>;
4
- }
5
- //# sourceMappingURL=mongoose.d.ts.map
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- 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;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.MongooseService = void 0;
13
- const decorator_1 = require("@midwayjs/decorator");
14
- const mongoose = require("mongoose");
15
- let MongooseService = class MongooseService {
16
- async init() {
17
- await mongoose.connect(this.config.uri, this.config.options);
18
- }
19
- };
20
- __decorate([
21
- decorator_1.Config('mongoose'),
22
- __metadata("design:type", Object)
23
- ], MongooseService.prototype, "config", void 0);
24
- __decorate([
25
- decorator_1.Init(),
26
- __metadata("design:type", Function),
27
- __metadata("design:paramtypes", []),
28
- __metadata("design:returntype", Promise)
29
- ], MongooseService.prototype, "init", null);
30
- MongooseService = __decorate([
31
- decorator_1.Provide('mongooseService'),
32
- decorator_1.Scope(decorator_1.ScopeEnum.Singleton)
33
- ], MongooseService);
34
- exports.MongooseService = MongooseService;
35
- //# sourceMappingURL=mongoose.js.map