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

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,119 @@
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.12](https://github.com/midwayjs/midway/compare/v3.0.0-beta.11...v3.0.0-beta.12) (2021-12-28)
7
+
8
+
9
+ ### Features
10
+
11
+ * custom error code & add @Files/@Fields ([#1438](https://github.com/midwayjs/midway/issues/1438)) ([b0032af](https://github.com/midwayjs/midway/commit/b0032afd2fa9ea0416fe69f4bd0c1a58bea5314e))
12
+
13
+
14
+
15
+
16
+
17
+ # [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
18
+
19
+ **Note:** Version bump only for package @midwayjs/typegoose
20
+
21
+
22
+
23
+
24
+
25
+ # [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
26
+
27
+ **Note:** Version bump only for package @midwayjs/typegoose
28
+
29
+
30
+
31
+
32
+
33
+ # [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
34
+
35
+ **Note:** Version bump only for package @midwayjs/typegoose
36
+
37
+
38
+
39
+
40
+
41
+ # [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
42
+
43
+
44
+ ### Bug Fixes
45
+
46
+ * mongoose remote config bug ([#1399](https://github.com/midwayjs/midway/issues/1399)) ([e37602d](https://github.com/midwayjs/midway/commit/e37602d54ae503aeee48afa320709aae3d18b329))
47
+
48
+
49
+
50
+
51
+
52
+ # [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
53
+
54
+ **Note:** Version bump only for package @midwayjs/typegoose
55
+
56
+
57
+
58
+
59
+
60
+ # [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
61
+
62
+ **Note:** Version bump only for package @midwayjs/typegoose
63
+
64
+
65
+
66
+
67
+
68
+ # [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
69
+
70
+ **Note:** Version bump only for package @midwayjs/typegoose
71
+
72
+
73
+
74
+
75
+
76
+ # [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
77
+
78
+ **Note:** Version bump only for package @midwayjs/typegoose
79
+
80
+
81
+
82
+
83
+
84
+ # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
85
+
86
+
87
+ ### Features
88
+
89
+ * add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
90
+
91
+
92
+
93
+
94
+
95
+ # [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
96
+
97
+ **Note:** Version bump only for package @midwayjs/typegoose
98
+
99
+
100
+
101
+
102
+
103
+ # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
104
+
105
+
106
+ ### Bug Fixes
107
+
108
+ * remove connection key ([#1337](https://github.com/midwayjs/midway/issues/1337)) ([6ac219e](https://github.com/midwayjs/midway/commit/6ac219e786792b32d19a364bffbe9e6318c2f9e1))
109
+
110
+
111
+ ### Features
112
+
113
+ * 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))
114
+
115
+
116
+
117
+
118
+
6
119
  ## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
7
120
 
8
121
  **Note:** Version bump only for package @midwayjs/typegoose
@@ -1,5 +1,12 @@
1
- export declare class AutoConfiguration {
2
- onReady(app: any): Promise<void>;
1
+ import { IMidwayApplication, MidwayDecoratorService } from '@midwayjs/core';
2
+ export declare class TypegooseConfiguration {
3
+ oldMongooseConfig: any;
4
+ legacyMode: boolean;
5
+ app: IMidwayApplication;
6
+ decoratorService: MidwayDecoratorService;
7
+ modelMap: WeakMap<object, any>;
8
+ init(): Promise<void>;
9
+ onReady(container: any): Promise<void>;
3
10
  onStop(): Promise<void>;
4
11
  }
5
12
  //# sourceMappingURL=configuration.d.ts.map
@@ -5,24 +5,78 @@ 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(container) {
30
+ var _a, _b;
31
+ const connectionFactory = await container.getAsync(mongoose.MongooseConnectionServiceFactory);
32
+ const Models = (0, decorator_1.listModule)(interface_1.ENTITY_MODEL_KEY);
33
+ for (const Model of Models) {
34
+ const metadata = (_a = (0, decorator_1.getClassMetadata)(interface_1.ENTITY_MODEL_KEY, Model)) !== null && _a !== void 0 ? _a : {};
35
+ const connectionName = (_b = metadata.connectionName) !== null && _b !== void 0 ? _b : 'default';
36
+ const conn = connectionFactory.get(connectionName);
37
+ if (conn) {
38
+ const model = (0, typegoose_1.getModelForClass)(Model, { existingConnection: conn });
39
+ this.modelMap.set(Model, model);
40
+ }
41
+ else {
42
+ throw new Error(`connection name ${metadata.connectionName} not found`);
43
+ }
44
+ }
45
+ // 兼容老代码
46
+ if (Models.length === 0 && this.oldMongooseConfig['uri']) {
47
+ this.legacyMode = true;
48
+ await mongo.connect(this.oldMongooseConfig.uri, this.oldMongooseConfig.options);
49
+ }
16
50
  }
17
51
  async onStop() {
18
- await mongoose.disconnect();
52
+ if (this.legacyMode) {
53
+ await mongo.disconnect();
54
+ }
19
55
  }
20
56
  };
21
- AutoConfiguration = __decorate([
22
- decorator_1.Configuration({
23
- namespace: 'mongoose',
24
- importConfigs: [path_1.join(__dirname, 'config')],
57
+ __decorate([
58
+ (0, decorator_1.Config)('mongoose'),
59
+ __metadata("design:type", Object)
60
+ ], TypegooseConfiguration.prototype, "oldMongooseConfig", void 0);
61
+ __decorate([
62
+ (0, decorator_1.App)(),
63
+ __metadata("design:type", Object)
64
+ ], TypegooseConfiguration.prototype, "app", void 0);
65
+ __decorate([
66
+ (0, decorator_1.Inject)(),
67
+ __metadata("design:type", core_1.MidwayDecoratorService)
68
+ ], TypegooseConfiguration.prototype, "decoratorService", void 0);
69
+ __decorate([
70
+ (0, decorator_1.Init)(),
71
+ __metadata("design:type", Function),
72
+ __metadata("design:paramtypes", []),
73
+ __metadata("design:returntype", Promise)
74
+ ], TypegooseConfiguration.prototype, "init", null);
75
+ TypegooseConfiguration = __decorate([
76
+ (0, decorator_1.Configuration)({
77
+ namespace: 'typegoose',
78
+ imports: [mongoose],
25
79
  })
26
- ], AutoConfiguration);
27
- exports.AutoConfiguration = AutoConfiguration;
80
+ ], TypegooseConfiguration);
81
+ exports.TypegooseConfiguration = TypegooseConfiguration;
28
82
  //# 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.12",
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.12"
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.12",
28
+ "@midwayjs/decorator": "^3.0.0-beta.12",
29
+ "@midwayjs/mock": "^3.0.0-beta.12",
30
+ "@typegoose/typegoose": "^9.0.0",
31
+ "mongoose": "^6.1.3"
28
32
  },
29
- "gitHead": "d5acc7505275ea9d566edd38e5e0377141e0abc1"
33
+ "gitHead": "1c46e53eb934248007eeb7fe3920f5ac24e272c6"
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