@tsed/mongoose 7.0.0-beta.2 → 7.0.0-beta.5

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 (133) hide show
  1. package/jest.config.js +1 -1
  2. package/lib/cjs/MongooseModule.js +3 -3
  3. package/lib/cjs/MongooseModule.js.map +1 -1
  4. package/lib/cjs/constants/{index.js → constants.js} +1 -1
  5. package/lib/cjs/constants/constants.js.map +1 -0
  6. package/lib/cjs/decorators/discriminatorKey.js +1 -1
  7. package/lib/cjs/decorators/discriminatorKey.js.map +1 -1
  8. package/lib/cjs/decorators/dynamicRef.js +24 -5
  9. package/lib/cjs/decorators/dynamicRef.js.map +1 -1
  10. package/lib/cjs/decorators/model.js +5 -4
  11. package/lib/cjs/decorators/model.js.map +1 -1
  12. package/lib/cjs/decorators/numberDecimal.js +2 -2
  13. package/lib/cjs/decorators/numberDecimal.js.map +1 -1
  14. package/lib/cjs/decorators/postHook.js.map +1 -1
  15. package/lib/cjs/decorators/preHook.js.map +1 -1
  16. package/lib/cjs/decorators/ref.js +1 -1
  17. package/lib/cjs/decorators/ref.js.map +1 -1
  18. package/lib/cjs/decorators/schema.js +1 -1
  19. package/lib/cjs/decorators/schema.js.map +1 -1
  20. package/lib/cjs/decorators/versionKey.js +1 -1
  21. package/lib/cjs/decorators/versionKey.js.map +1 -1
  22. package/lib/cjs/decorators/virtualRef.js +1 -1
  23. package/lib/cjs/decorators/virtualRef.js.map +1 -1
  24. package/lib/cjs/index.js +47 -6
  25. package/lib/cjs/index.js.map +1 -1
  26. package/lib/cjs/interfaces/MongooseModel.js.map +1 -1
  27. package/lib/cjs/interfaces/MongooseModelOptions.js.map +1 -1
  28. package/lib/cjs/interfaces/MongooseSchemaOptions.js.map +1 -1
  29. package/lib/cjs/interfaces/interfaces.js +3 -0
  30. package/lib/cjs/interfaces/interfaces.js.map +1 -0
  31. package/lib/cjs/package.json +3 -0
  32. package/lib/cjs/services/MongooseConnections.js +1 -5
  33. package/lib/cjs/services/MongooseConnections.js.map +1 -1
  34. package/lib/cjs/services/MongooseService.js +4 -4
  35. package/lib/cjs/services/MongooseService.js.map +1 -1
  36. package/lib/cjs/utils/createModel.js +7 -11
  37. package/lib/cjs/utils/createModel.js.map +1 -1
  38. package/lib/cjs/utils/createSchema.js +2 -2
  39. package/lib/cjs/utils/createSchema.js.map +1 -1
  40. package/lib/cjs/utils/resolveRefType.js +1 -1
  41. package/lib/cjs/utils/resolveRefType.js.map +1 -1
  42. package/lib/cjs/utils/schemaOptions.js +1 -1
  43. package/lib/cjs/utils/schemaOptions.js.map +1 -1
  44. package/lib/esm/MongooseModule.js +2 -2
  45. package/lib/esm/constants/{index.js → constants.js} +1 -1
  46. package/lib/esm/constants/constants.js.map +1 -0
  47. package/lib/esm/decorators/auto.js +1 -1
  48. package/lib/esm/decorators/discriminatorKey.js +2 -2
  49. package/lib/esm/decorators/discriminatorKey.js.map +1 -1
  50. package/lib/esm/decorators/dynamicRef.js +26 -7
  51. package/lib/esm/decorators/dynamicRef.js.map +1 -1
  52. package/lib/esm/decorators/excludeIndexes.js +1 -1
  53. package/lib/esm/decorators/expires.js +1 -1
  54. package/lib/esm/decorators/immutable.js +1 -1
  55. package/lib/esm/decorators/indexed.js +1 -1
  56. package/lib/esm/decorators/lowercase.js +1 -1
  57. package/lib/esm/decorators/model.js +5 -4
  58. package/lib/esm/decorators/model.js.map +1 -1
  59. package/lib/esm/decorators/mongooseIndex.js +1 -1
  60. package/lib/esm/decorators/mongooseIndexes.js +1 -1
  61. package/lib/esm/decorators/mongoosePlugin.js +1 -1
  62. package/lib/esm/decorators/numberDecimal.js +1 -1
  63. package/lib/esm/decorators/numberDecimal.js.map +1 -1
  64. package/lib/esm/decorators/postHook.js +1 -1
  65. package/lib/esm/decorators/postHook.js.map +1 -1
  66. package/lib/esm/decorators/preHook.js +1 -1
  67. package/lib/esm/decorators/preHook.js.map +1 -1
  68. package/lib/esm/decorators/ref.js +3 -3
  69. package/lib/esm/decorators/ref.js.map +1 -1
  70. package/lib/esm/decorators/schema.js +2 -2
  71. package/lib/esm/decorators/schema.js.map +1 -1
  72. package/lib/esm/decorators/schemaIgnore.js +1 -1
  73. package/lib/esm/decorators/select.js +1 -1
  74. package/lib/esm/decorators/sparse.js +1 -1
  75. package/lib/esm/decorators/text.js +1 -1
  76. package/lib/esm/decorators/trim.js +1 -1
  77. package/lib/esm/decorators/unique.js +1 -1
  78. package/lib/esm/decorators/uppercase.js +1 -1
  79. package/lib/esm/decorators/versionKey.js +1 -1
  80. package/lib/esm/decorators/versionKey.js.map +1 -1
  81. package/lib/esm/decorators/virtualRef.js +2 -2
  82. package/lib/esm/decorators/virtualRef.js.map +1 -1
  83. package/lib/esm/index.js +47 -6
  84. package/lib/esm/index.js.map +1 -1
  85. package/lib/esm/interfaces/MongooseModel.js.map +1 -1
  86. package/lib/esm/interfaces/MongooseModelOptions.js.map +1 -1
  87. package/lib/esm/interfaces/MongooseSchemaOptions.js.map +1 -1
  88. package/lib/esm/interfaces/interfaces.js +2 -0
  89. package/lib/esm/interfaces/interfaces.js.map +1 -0
  90. package/lib/esm/package.json +3 -0
  91. package/lib/esm/services/MongooseConnections.js +2 -6
  92. package/lib/esm/services/MongooseConnections.js.map +1 -1
  93. package/lib/esm/utils/createModel.js +8 -12
  94. package/lib/esm/utils/createModel.js.map +1 -1
  95. package/lib/esm/utils/createSchema.js +3 -3
  96. package/lib/esm/utils/createSchema.js.map +1 -1
  97. package/lib/esm/utils/resolveRefType.js +1 -1
  98. package/lib/esm/utils/resolveRefType.js.map +1 -1
  99. package/lib/esm/utils/schemaOptions.js +1 -1
  100. package/lib/esm/utils/schemaOptions.js.map +1 -1
  101. package/lib/types/constants/{index.d.ts → constants.d.ts} +0 -0
  102. package/lib/types/decorators/dynamicRef.d.ts +4 -2
  103. package/lib/types/decorators/postHook.d.ts +1 -1
  104. package/lib/types/decorators/preHook.d.ts +1 -1
  105. package/lib/types/decorators/schema.d.ts +1 -1
  106. package/lib/types/decorators/virtualRef.d.ts +0 -4
  107. package/lib/types/index.d.ts +46 -5
  108. package/lib/types/interfaces/MongooseModel.d.ts +1 -2
  109. package/lib/types/interfaces/MongooseModelOptions.d.ts +1 -1
  110. package/lib/types/interfaces/MongooseSchemaOptions.d.ts +1 -1
  111. package/lib/types/interfaces/{index.d.ts → interfaces.d.ts} +0 -6
  112. package/lib/types/utils/createModel.d.ts +2 -2
  113. package/lib/types/utils/createSchema.d.ts +1 -1
  114. package/lib/types/utils/schemaOptions.d.ts +1 -1
  115. package/package.json +20 -18
  116. package/readme.md +124 -134
  117. package/tsconfig.compile.esm.json +2 -12
  118. package/lib/cjs/constants/index.js.map +0 -1
  119. package/lib/cjs/decorators/index.js +0 -30
  120. package/lib/cjs/decorators/index.js.map +0 -1
  121. package/lib/cjs/interfaces/index.js +0 -10
  122. package/lib/cjs/interfaces/index.js.map +0 -1
  123. package/lib/cjs/utils/index.js +0 -6
  124. package/lib/cjs/utils/index.js.map +0 -1
  125. package/lib/esm/constants/index.js.map +0 -1
  126. package/lib/esm/decorators/index.js +0 -27
  127. package/lib/esm/decorators/index.js.map +0 -1
  128. package/lib/esm/interfaces/index.js +0 -7
  129. package/lib/esm/interfaces/index.js.map +0 -1
  130. package/lib/esm/utils/index.js +0 -3
  131. package/lib/esm/utils/index.js.map +0 -1
  132. package/lib/types/decorators/index.d.ts +0 -26
  133. package/lib/types/utils/index.d.ts +0 -2
package/jest.config.js CHANGED
@@ -5,7 +5,7 @@ module.exports = {
5
5
  ...require("@tsed/jest-config")(__dirname, "mongoose"),
6
6
  coverageThreshold: {
7
7
  global: {
8
- branches: 94.67,
8
+ branches: 93.45,
9
9
  functions: 98.9,
10
10
  lines: 98.9,
11
11
  statements: 98.93
@@ -25,12 +25,12 @@ let MongooseModule = class MongooseModule {
25
25
  return this.mongooseService.closeConnections();
26
26
  }
27
27
  };
28
- MongooseModule = (0, tslib_1.__decorate)([
28
+ MongooseModule = tslib_1.__decorate([
29
29
  (0, di_2.Module)({
30
30
  imports: [MongooseConnections_1.MONGOOSE_CONNECTIONS]
31
31
  }),
32
- (0, tslib_1.__param)(1, (0, di_1.Configuration)()),
33
- (0, tslib_1.__metadata)("design:paramtypes", [MongooseService_1.MongooseService, Object])
32
+ tslib_1.__param(1, (0, di_1.Configuration)()),
33
+ tslib_1.__metadata("design:paramtypes", [MongooseService_1.MongooseService, Object])
34
34
  ], MongooseModule);
35
35
  exports.MongooseModule = MongooseModule;
36
36
  //# sourceMappingURL=MongooseModule.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MongooseModule.js","sourceRoot":"","sources":["../../src/MongooseModule.ts"],"names":[],"mappings":";;;;AAAA,iCAA+C;AAC/C,iCAA2C;AAC3C,wEAAoE;AACpE,gEAA2D;AAE3D;;GAEG;AAIH,IAAa,cAAc,GAA3B,MAAa,cAAc;IACzB,YAAoB,eAAgC,EAA2B,QAAuB;QAAlF,oBAAe,GAAf,eAAe,CAAiB;QAA2B,aAAQ,GAAR,QAAQ,CAAe;QACpG,6EAA6E;QAC7E,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAM,OAAO,CAAC,CAAC;QAE9C,uBAAuB;QACvB,IAAI,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,EAAE;YACnB,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC;SAC/C;IACH,CAAC;IAED,OAAO,KAAyB,CAAC;IAEjC,UAAU;QACR,OAAO,IAAI,CAAC,eAAe,CAAC,gBAAgB,EAAE,CAAC;IACjD,CAAC;CACF,CAAA;AAhBY,cAAc;IAH1B,IAAA,WAAM,EAAC;QACN,OAAO,EAAE,CAAC,0CAAoB,CAAC;KAChC,CAAC;IAEuD,wBAAA,IAAA,kBAAa,GAAE,CAAA;kDAAjC,iCAAe;GADzC,cAAc,CAgB1B;AAhBY,wCAAc","sourcesContent":["import {Configuration, OnInit} from \"@tsed/di\";\nimport {Module, OnDestroy} from \"@tsed/di\";\nimport {MONGOOSE_CONNECTIONS} from \"./services/MongooseConnections\";\nimport {MongooseService} from \"./services/MongooseService\";\n\n/**\n * @ignore\n */\n@Module({\n imports: [MONGOOSE_CONNECTIONS]\n})\nexport class MongooseModule implements OnDestroy, OnInit {\n constructor(private mongooseService: MongooseService, @Configuration() private settings: Configuration) {\n // auto configure the cache manager when mongoose is used with @tsed/mongoose\n const cache = this.settings.get<any>(\"cache\");\n\n // istanbul ignore next\n if (cache?.mongoose) {\n cache.connection = this.mongooseService.get();\n }\n }\n\n $onInit(): void | Promise<any> {}\n\n $onDestroy(): Promise<any> | void {\n return this.mongooseService.closeConnections();\n }\n}\n"]}
1
+ {"version":3,"file":"MongooseModule.js","sourceRoot":"","sources":["../../src/MongooseModule.ts"],"names":[],"mappings":";;;;AAAA,iCAA+C;AAC/C,iCAA2C;AAC3C,wEAAoE;AACpE,gEAA2D;AAE3D;;GAEG;AAIH,IAAa,cAAc,GAA3B,MAAa,cAAc;IACzB,YAAoB,eAAgC,EAA2B,QAAuB;QAAlF,oBAAe,GAAf,eAAe,CAAiB;QAA2B,aAAQ,GAAR,QAAQ,CAAe;QACpG,6EAA6E;QAC7E,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAM,OAAO,CAAC,CAAC;QAE9C,uBAAuB;QACvB,IAAI,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,EAAE;YACnB,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC;SAC/C;IACH,CAAC;IAED,OAAO,KAAyB,CAAC;IAEjC,UAAU;QACR,OAAO,IAAI,CAAC,eAAe,CAAC,gBAAgB,EAAE,CAAC;IACjD,CAAC;CACF,CAAA;AAhBY,cAAc;IAH1B,IAAA,WAAM,EAAC;QACN,OAAO,EAAE,CAAC,0CAAoB,CAAC;KAChC,CAAC;IAEuD,mBAAA,IAAA,kBAAa,GAAE,CAAA;6CAAjC,iCAAe;GADzC,cAAc,CAgB1B;AAhBY,wCAAc","sourcesContent":["import {Configuration, OnInit} from \"@tsed/di\";\nimport {Module, OnDestroy} from \"@tsed/di\";\nimport {MONGOOSE_CONNECTIONS} from \"./services/MongooseConnections\";\nimport {MongooseService} from \"./services/MongooseService\";\n\n/**\n * @ignore\n */\n@Module({\n imports: [MONGOOSE_CONNECTIONS]\n})\nexport class MongooseModule implements OnDestroy, OnInit {\n constructor(private mongooseService: MongooseService, @Configuration() private settings: Configuration) {\n // auto configure the cache manager when mongoose is used with @tsed/mongoose\n const cache = this.settings.get<any>(\"cache\");\n\n // istanbul ignore next\n if (cache?.mongoose) {\n cache.connection = this.mongooseService.get();\n }\n }\n\n $onInit(): void | Promise<any> {}\n\n $onDestroy(): Promise<any> | void {\n return this.mongooseService.closeConnections();\n }\n}\n"]}
@@ -21,4 +21,4 @@ exports.MONGOOSE_MODEL = "tsed:mongoose:model";
21
21
  * @type {string}
22
22
  */
23
23
  exports.MONGOOSE_MODEL_NAME = "tsed:mongoose:model:name";
24
- //# sourceMappingURL=index.js.map
24
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,eAAe,GAAG,sBAAsB,CAAC;AACtD;;;GAGG;AACU,QAAA,uBAAuB,GAAG,8BAA8B,CAAC;AACtE;;;GAGG;AACU,QAAA,cAAc,GAAG,qBAAqB,CAAC;AACpD;;;GAGG;AACU,QAAA,mBAAmB,GAAG,0BAA0B,CAAC","sourcesContent":["/**\n *\n * @type {string}\n */\nexport const MONGOOSE_SCHEMA = \"tsed:mongoose:schema\";\n/**\n *\n * @type {string}\n */\nexport const MONGOOSE_SCHEMA_OPTIONS = \"tsed:mongoose:schema:options\";\n/**\n *\n * @type {string}\n */\nexport const MONGOOSE_MODEL = \"tsed:mongoose:model\";\n/**\n *\n * @type {string}\n */\nexport const MONGOOSE_MODEL_NAME = \"tsed:mongoose:model:name\";\n"]}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DiscriminatorKey = void 0;
4
4
  const core_1 = require("@tsed/core");
5
- const constants_1 = require("../constants");
5
+ const constants_1 = require("../constants/constants");
6
6
  const schemaIgnore_1 = require("./schemaIgnore");
7
7
  const schema_1 = require("@tsed/schema");
8
8
  function DiscriminatorKey() {
@@ -1 +1 @@
1
- {"version":3,"file":"discriminatorKey.js","sourceRoot":"","sources":["../../../src/decorators/discriminatorKey.ts"],"names":[],"mappings":";;;AAAA,qCAAgD;AAChD,4CAAqD;AACrD,iDAA4C;AAC5C,yCAAsC;AAEtC,SAAgB,gBAAgB;IAC9B,OAAO,IAAA,oBAAa,EAAC,IAAA,iBAAQ,GAAE,EAAE,IAAA,2BAAY,GAAE,EAAE,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QACpF,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,mCAAuB,EAAE,EAAC,gBAAgB,EAAE,WAAW,EAAC,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;AACL,CAAC;AAJD,4CAIC","sourcesContent":["import {Store, useDecorators} from \"@tsed/core\";\nimport {MONGOOSE_SCHEMA_OPTIONS} from \"../constants\";\nimport {SchemaIgnore} from \"./schemaIgnore\";\nimport {Property} from \"@tsed/schema\";\n\nexport function DiscriminatorKey(): PropertyDecorator {\n return useDecorators(Property(), SchemaIgnore(), (target: any, propertyKey: string) => {\n Store.from(target).merge(MONGOOSE_SCHEMA_OPTIONS, {discriminatorKey: propertyKey});\n });\n}\n"]}
1
+ {"version":3,"file":"discriminatorKey.js","sourceRoot":"","sources":["../../../src/decorators/discriminatorKey.ts"],"names":[],"mappings":";;;AAAA,qCAAgD;AAChD,sDAA+D;AAC/D,iDAA4C;AAC5C,yCAAsC;AAEtC,SAAgB,gBAAgB;IAC9B,OAAO,IAAA,oBAAa,EAAC,IAAA,iBAAQ,GAAE,EAAE,IAAA,2BAAY,GAAE,EAAE,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QACpF,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,mCAAuB,EAAE,EAAC,gBAAgB,EAAE,WAAW,EAAC,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;AACL,CAAC;AAJD,4CAIC","sourcesContent":["import {Store, useDecorators} from \"@tsed/core\";\nimport {MONGOOSE_SCHEMA_OPTIONS} from \"../constants/constants\";\nimport {SchemaIgnore} from \"./schemaIgnore\";\nimport {Property} from \"@tsed/schema\";\n\nexport function DiscriminatorKey(): PropertyDecorator {\n return useDecorators(Property(), SchemaIgnore(), (target: any, propertyKey: string) => {\n Store.from(target).merge(MONGOOSE_SCHEMA_OPTIONS, {discriminatorKey: propertyKey});\n });\n}\n"]}
@@ -4,7 +4,15 @@ exports.DynamicRef = void 0;
4
4
  const core_1 = require("@tsed/core");
5
5
  const schema_1 = require("@tsed/schema");
6
6
  const mongoose_1 = require("mongoose");
7
- const constants_1 = require("../constants");
7
+ const constants_1 = require("../constants/constants");
8
+ const json_mapper_1 = require("@tsed/json-mapper");
9
+ const MongooseModels_1 = require("../registries/MongooseModels");
10
+ function isRef(value) {
11
+ return (value && value._bsontype) || (0, core_1.isString)(value);
12
+ }
13
+ function getType(refPath, ctx) {
14
+ return ((ctx === null || ctx === void 0 ? void 0 : ctx.self[refPath]) && MongooseModels_1.MongooseModels.get(ctx.self[refPath])) || Object;
15
+ }
8
16
  /**
9
17
  * Define a property as mongoose reference to other Model (decorated with @Model).
10
18
  *
@@ -30,17 +38,28 @@ const constants_1 = require("../constants");
30
38
  * }
31
39
  * ```
32
40
  *
33
- * @param refPath
41
+ * @param refPath {String} the path to apply the correct model
42
+ * @param types {Type} the classes to generate the correct json schema
34
43
  * @returns {Function}
35
44
  * @decorator
36
45
  * @mongoose
37
46
  * @property
38
47
  */
39
- function DynamicRef(refPath) {
40
- return (0, core_1.useDecorators)((0, schema_1.Property)(String), (0, schema_1.Example)("5ce7ad3028890bd71749d477"), (0, schema_1.Description)("Mongoose Ref ObjectId"), (0, core_1.StoreMerge)(constants_1.MONGOOSE_SCHEMA, {
48
+ function DynamicRef(refPath, ...types) {
49
+ return (0, core_1.useDecorators)((0, schema_1.Property)(Object), (0, schema_1.Example)("5ce7ad3028890bd71749d477"), (0, schema_1.Description)("Mongoose Ref ObjectId"), (0, core_1.StoreMerge)(constants_1.MONGOOSE_SCHEMA, {
41
50
  type: mongoose_1.Schema.Types.ObjectId,
42
51
  refPath
43
- }));
52
+ }), (0, json_mapper_1.OnDeserialize)((value, ctx) => {
53
+ if (isRef(value)) {
54
+ return value.toString();
55
+ }
56
+ return (0, json_mapper_1.deserialize)(value, { ...ctx, type: getType(refPath, ctx) });
57
+ }), (0, json_mapper_1.OnSerialize)((value, ctx) => {
58
+ if (isRef(value)) {
59
+ return value.toString();
60
+ }
61
+ return (0, json_mapper_1.serialize)(value, { ...ctx, type: getType(refPath, ctx) });
62
+ }), (0, schema_1.OneOf)((0, schema_1.string)().example("5ce7ad3028890bd71749d477").description("Mongoose Ref ObjectId"), ...types));
44
63
  }
45
64
  exports.DynamicRef = DynamicRef;
46
65
  //# sourceMappingURL=dynamicRef.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dynamicRef.js","sourceRoot":"","sources":["../../../src/decorators/dynamicRef.ts"],"names":[],"mappings":";;;AAAA,qCAAqD;AACrD,yCAA4D;AAC5D,uCAAkD;AAClD,4CAA6C;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,SAAgB,UAAU,CAAC,OAAe;IACxC,OAAO,IAAA,oBAAa,EAClB,IAAA,iBAAQ,EAAC,MAAM,CAAC,EAChB,IAAA,gBAAO,EAAC,0BAA0B,CAAC,EACnC,IAAA,oBAAW,EAAC,uBAAuB,CAAC,EACpC,IAAA,iBAAU,EAAC,2BAAe,EAAE;QAC1B,IAAI,EAAE,iBAAc,CAAC,KAAK,CAAC,QAAQ;QACnC,OAAO;KACR,CAAC,CACkB,CAAC;AACzB,CAAC;AAVD,gCAUC","sourcesContent":["import {StoreMerge, useDecorators} from \"@tsed/core\";\nimport {Description, Example, Property} from \"@tsed/schema\";\nimport {Schema as MongooseSchema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants\";\n\n/**\n * Define a property as mongoose reference to other Model (decorated with @Model).\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * class FooModel {\n *\n * @DynamicRef('type')\n * field: DynamicRef<OtherFooModel | OtherModel>\n *\n * @Enum(['OtherFooModel', 'OtherModel'])\n * type: string\n * }\n *\n * @Model()\n * class OtherFooModel {\n * }\n *\n * @Model()\n * class OtherModel {\n * }\n * ```\n *\n * @param refPath\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function DynamicRef(refPath: string): PropertyDecorator {\n return useDecorators(\n Property(String),\n Example(\"5ce7ad3028890bd71749d477\"),\n Description(\"Mongoose Ref ObjectId\"),\n StoreMerge(MONGOOSE_SCHEMA, {\n type: MongooseSchema.Types.ObjectId,\n refPath\n })\n ) as PropertyDecorator;\n}\n\nexport type DynamicRef<T> = T | string;\n"]}
1
+ {"version":3,"file":"dynamicRef.js","sourceRoot":"","sources":["../../../src/decorators/dynamicRef.ts"],"names":[],"mappings":";;;AAAA,qCAAyF;AACzF,yCAA4F;AAC5F,uCAAkD;AAClD,sDAAuD;AACvD,mDAAqF;AACrF,iEAA4D;AAE5D,SAAS,KAAK,CAAC,KAA+B;IAC5C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,OAAO,CAAC,OAAe,EAAE,GAAoB;IACpD,OAAO,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC,OAAO,CAAC,KAAI,+BAAc,CAA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ent":["import {classOf, isArrowFn, isString, StoreMerge, Type, useDecorators} from \"@tsed/core\";\nimport {Description, Example, JsonHookContext, OneOf, Property, string} from \"@tsed/schema\";\nimport {Schema as MongooseSchema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants/constants\";\nimport {deserialize, OnDeserialize, OnSerialize, serialize} from \"@tsed/json-mapper\";\nimport {MongooseModels} from \"../registries/MongooseModels\";\n\nfunction isRef(value: undefined | string | any) {\n return (value && value._bsontype) || isString(value);\n}\n\nfunction getType(refPath: string, ctx: JsonHookContext) {\n return (ctx?.self[refPath] && MongooseModels.get(ctx.self[refPath] as string)) || Object;\n}\n\n/**\n * Define a property as mongoose reference to other Model (decorated with @Model).\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * class FooModel {\n *\n * @DynamicRef('type')\n * field: DynamicRef<OtherFooModel | OtherModel>\n *\n * @Enum(['OtherFooModel', 'OtherModel'])\n * type: string\n * }\n *\n * @Model()\n * class OtherFooModel {\n * }\n *\n * @Model()\n * class OtherModel {\n * }\n * ```\n *\n * @param refPath {String} the path to apply the correct model\n * @param types {Type} the classes to generate the correct json schema\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function DynamicRef(refPath: string, ...types: Type<any>[]): PropertyDecorator {\n return useDecorators(\n Property(Object),\n Example(\"5ce7ad3028890bd71749d477\"),\n Description(\"Mongoose Ref ObjectId\"),\n StoreMerge(MONGOOSE_SCHEMA, {\n type: MongooseSchema.Types.ObjectId,\n refPath\n }),\n OnDeserialize((value, ctx) => {\n if (isRef(value)) {\n return value.toString();\n }\n\n return deserialize(value, {...ctx, type: getType(refPath, ctx)});\n }),\n OnSerialize((value: any, ctx) => {\n if (isRef(value)) {\n return value.toString();\n }\n\n return serialize(value, {...ctx, type: getType(refPath, ctx)});\n }),\n OneOf(string().example(\"5ce7ad3028890bd71749d477\").description(\"Mongoose Ref ObjectId\"), ...types)\n ) as PropertyDecorator;\n}\n\nexport type DynamicRef<T> = T | string;\n"]}
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Model = void 0;
4
4
  const di_1 = require("@tsed/di");
5
5
  const MongooseConnections_1 = require("../services/MongooseConnections");
6
- const utils_1 = require("../utils");
6
+ const createModel_1 = require("../utils/createModel");
7
+ const createSchema_1 = require("../utils/createSchema");
7
8
  const schemaOptions_1 = require("../utils/schemaOptions");
8
9
  /**
9
10
  * Define a class as a Mongoose Model. The model can be injected to the Service, Controller, Middleware, Converters or Filter with
@@ -44,12 +45,12 @@ const schemaOptions_1 = require("../utils/schemaOptions");
44
45
  */
45
46
  function Model(options = {}) {
46
47
  return (target) => {
47
- const { token, collectionName } = (0, utils_1.getModelToken)(target, options);
48
+ const { token, collectionName } = (0, createModel_1.getModelToken)(target, options);
48
49
  (0, di_1.registerProvider)({
49
50
  provide: token,
50
51
  deps: [],
51
52
  useFactory() {
52
- return (0, utils_1.getSchema)(target, options);
53
+ return (0, createSchema_1.getSchema)(target, options);
53
54
  }
54
55
  });
55
56
  (0, di_1.registerProvider)({
@@ -58,7 +59,7 @@ function Model(options = {}) {
58
59
  deps: [MongooseConnections_1.MONGOOSE_CONNECTIONS, token],
59
60
  useFactory(connections, schema) {
60
61
  (0, schemaOptions_1.applySchemaOptions)(schema, (0, schemaOptions_1.schemaOptions)(target));
61
- return (0, utils_1.createModel)(target, schema, collectionName, options.collection, options.skipInit, connections.get(options.connection), options.discriminatorValue);
62
+ return (0, createModel_1.createModel)(target, schema, collectionName, options.collection, options.overwriteModels, connections.get(options.connection), options.discriminatorValue);
62
63
  }
63
64
  });
64
65
  };
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","sourceRoot":"","sources":["../../../src/decorators/model.ts"],"names":[],"mappings":";;;AAAA,iCAA0C;AAG1C,yEAAqE;AACrE,oCAA+D;AAC/D,0DAAyE;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,SAAgB,KAAK,CAAC,UAAgC,EAAE;IACtD,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,MAAM,EAAC,KAAK,EAAE,cAAc,EAAC,GAAG,IAAA,qBAAa,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE/D,IAAA,qBAAgB,EAAC;YACf,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,EAAE;YACR,UAAU;gBACR,OAAO,IAAA,iBAAS,EAAC,MAAM,EAAE,OAAc,CAAC,CAAC;YAC3C,CAAC;SACF,CAAC,CAAC;QAEH,IAAA,qBAAgB,EAAC;YACf,OAAO,EAAE,MAAM;YACf,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,CAAC,0CAAoB,EAAE,KAAK,CAAC;YACnC,UAAU,CAAC,WAAiC,EAAE,MAAc;gBAC1D,IAAA,kCAAkB,EAAC,MAAM,EAAE,IAAA,6BAAa,EAAC,MAAM,CAAC,CAAC,CAAC;gBAClD,OAAO,IAAA,mBAAW,EAChB,MAAM,EACN,MAAM,EACN,cAAc,EACd,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,QAAQ,EAChB,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EACnC,OAAO,CAAC,kBAAkB,CAC3B,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AA9BD,sBA8BC","sourcesContent":["import {registerProvider} from \"@tsed/di\";\nimport {Schema} from \"mongoose\";\nimport {MongooseModelOptions} from \"../interfaces/MongooseModelOptions\";\nimport {MONGOOSE_CONNECTIONS} from \"../services/MongooseConnections\";\nimport {createModel, getModelToken, getSchema} from \"../utils\";\nimport {applySchemaOptions, schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n * Define a class as a Mongoose Model. The model can be injected to the Service, Controller, Middleware, Converters or Filter with\n * `@Inject` annotation.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Property()\n * field: string;\n * }\n * ```\n *\n * Then inject the model into a service:\n *\n * ```typescript\n * class MyService {\n * constructor(@Inject(EventModel) eventModel: MongooseModel<EventModel>) {\n * eventModel.findById().exec();\n * }\n * }\n * ```\n *\n * ### Options\n *\n * - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.\n * - `name` (String): model name.\n * - `collection` (String): collection (optional, induced from model name).\n * - `skipInit` (Boolean): skipInit whether to skip initialization (defaults to false).\n *\n * @param {MongooseModelOptions} options\n * @returns {(target: any) => void}\n * @decorator\n * @mongoose\n * @class\n */\nexport function Model(options: MongooseModelOptions = {}) {\n return (target: any) => {\n const {token, collectionName} = getModelToken(target, options);\n\n registerProvider({\n provide: token,\n deps: [],\n useFactory() {\n return getSchema(target, options as any);\n }\n });\n\n registerProvider({\n provide: target,\n type: \"mongoose:model\",\n deps: [MONGOOSE_CONNECTIONS, token],\n useFactory(connections: MONGOOSE_CONNECTIONS, schema: Schema) {\n applySchemaOptions(schema, schemaOptions(target));\n return createModel(\n target,\n schema,\n collectionName,\n options.collection,\n options.skipInit,\n connections.get(options.connection),\n options.discriminatorValue\n );\n }\n });\n };\n}\n"]}
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../../src/decorators/model.ts"],"names":[],"mappings":";;;AAAA,iCAA0C;AAG1C,yEAAqE;AACrE,sDAAgE;AAChE,wDAAgD;AAChD,0DAAyE;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,SAAgB,KAAK,CAAC,UAAgC,EAAE;IACtD,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,MAAM,EAAC,KAAK,EAAE,cAAc,EAAC,GAAG,IAAA,2BAAa,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE/D,IAAA,qBAAgB,EAAC;YACf,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,EAAE;YACR,UAAU;gBACR,OAAO,IAAA,wBAAS,EAAC,MAAM,EAAE,OAAc,CAAC,CAAC;YAC3C,CAAC;SACF,CAAC,CAAC;QAEH,IAAA,qBAAgB,EAAC;YACf,OAAO,EAAE,MAAM;YACf,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,CAAC,0CAAoB,EAAE,KAAK,CAAC;YACnC,UAAU,CAAC,WAAiC,EAAE,MAAc;gBAC1D,IAAA,kCAAkB,EAAC,MAAM,EAAE,IAAA,6BAAa,EAAC,MAAM,CAAC,CAAC,CAAC;gBAClD,OAAO,IAAA,yBAAW,EAChB,MAAM,EACN,MAAM,EACN,cAAc,EACd,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,eAAe,EACvB,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EACnC,OAAO,CAAC,kBAAkB,CAC3B,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AA9BD,sBA8BC","sourcesContent":["import {registerProvider} from \"@tsed/di\";\nimport {Schema} from \"mongoose\";\nimport {MongooseModelOptions} from \"../interfaces/MongooseModelOptions\";\nimport {MONGOOSE_CONNECTIONS} from \"../services/MongooseConnections\";\nimport {createModel, getModelToken} from \"../utils/createModel\";\nimport {getSchema} from \"../utils/createSchema\";\nimport {applySchemaOptions, schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n * Define a class as a Mongoose Model. The model can be injected to the Service, Controller, Middleware, Converters or Filter with\n * `@Inject` annotation.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Property()\n * field: string;\n * }\n * ```\n *\n * Then inject the model into a service:\n *\n * ```typescript\n * class MyService {\n * constructor(@Inject(EventModel) eventModel: MongooseModel<EventModel>) {\n * eventModel.findById().exec();\n * }\n * }\n * ```\n *\n * ### Options\n *\n * - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.\n * - `name` (String): model name.\n * - `collection` (String): collection (optional, induced from model name).\n * - `skipInit` (Boolean): skipInit whether to skip initialization (defaults to false).\n *\n * @param {MongooseModelOptions} options\n * @returns {(target: any) => void}\n * @decorator\n * @mongoose\n * @class\n */\nexport function Model(options: MongooseModelOptions = {}) {\n return (target: any) => {\n const {token, collectionName} = getModelToken(target, options);\n\n registerProvider({\n provide: token,\n deps: [],\n useFactory() {\n return getSchema(target, options as any);\n }\n });\n\n registerProvider({\n provide: target,\n type: \"mongoose:model\",\n deps: [MONGOOSE_CONNECTIONS, token],\n useFactory(connections: MONGOOSE_CONNECTIONS, schema: Schema) {\n applySchemaOptions(schema, schemaOptions(target));\n return createModel(\n target,\n schema,\n collectionName,\n options.collection,\n options.overwriteModels,\n connections.get(options.connection),\n options.discriminatorValue\n );\n }\n });\n };\n}\n"]}
@@ -7,13 +7,13 @@ const core_1 = require("@tsed/core");
7
7
  const json_mapper_1 = require("@tsed/json-mapper");
8
8
  const schema_1 = require("@tsed/schema");
9
9
  const mongoose_1 = require("mongoose");
10
- const constants_1 = require("../constants");
10
+ const constants_1 = require("../constants/constants");
11
11
  let DecimalFormat = class DecimalFormat {
12
12
  validate(num) {
13
13
  return (0, core_1.isString)(num) || (0, core_1.isNumber)(num);
14
14
  }
15
15
  };
16
- DecimalFormat = (0, tslib_1.__decorate)([
16
+ DecimalFormat = tslib_1.__decorate([
17
17
  (0, ajv_1.Formats)("decimal", { type: "number" })
18
18
  ], DecimalFormat);
19
19
  exports.DecimalFormat = DecimalFormat;
@@ -1 +1 @@
1
- {"version":3,"file":"numberDecimal.js","sourceRoot":"","sources":["../../../src/decorators/numberDecimal.ts"],"names":[],"mappings":";;;;AAAA,mCAAkD;AAClD,qCAAyE;AACzE,mDAA6D;AAC7D,yCAAuD;AACvD,uCAA4E;AAC5E,4CAA6C;AAG7C,IAAa,aAAa,GAA1B,MAAa,aAAa;IACxB,QAAQ,CAAC,GAAoB;QAC3B,OAAO,IAAA,eAAQ,EAAC,GAAG,CAAC,IAAI,IAAA,eAAQ,EAAC,GAAG,CAAC,CAAC;IACxC,CAAC;CACF,CAAA;AAJY,aAAa;IADzB,IAAA,aAAO,EAAC,SAAS,EAAE,EAAC,IAAI,EAAE,QAAQ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,OAAO,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AArCD,sCAqCC","sourcesContent":["import {Formats, FormatsMethods} from \"@tsed/ajv\";\nimport {isNumber, isString, StoreMerge, useDecorators} from \"@tsed/core\";\nimport {OnDeserialize, OnSerialize} from \"@tsed/json-mapper\";\nimport {Example, Format, Property} from \"@tsed/schema\";\nimport {Types, Schema as MongooseSchema, SchemaTypeOptions} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants\";\n\n@Formats(\"decimal\", {type: \"number\"})\nexport class DecimalFormat implements FormatsMethods<string | number> {\n validate(num: string | number): boolean {\n return isString(num) || isNumber(num);\n }\n}\n\nfunction isDecimal(value: undefined | number | any) {\n return value && value._bsontype === \"Decimal128\";\n}\n\n/**\n * Tell Mongoose whether to define an Decimal128 property.\n * Will be serialized as `number` with format as `decimal`.\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class PriceModel {\n * @NumberDecimal()\n * price: Decimal128;\n * }\n * ```\n * Optionally using custom decimal type, such as `Big` from big.js\n * ```typescript\n * @Model()\n * export class PriceModel {\n * @NumberDecimal(Big)\n * price: Big;\n * }\n * ```\n * @param type Optional decimal type constructor\n * @decorator\n * @mongoose\n * @schema\n */\nexport function NumberDecimal(type?: any) {\n const schema: SchemaTypeOptions<Decimal128> = {\n type: MongooseSchema.Types.Decimal128\n };\n\n if (type) {\n // Define property getter to convert Decimal128 to custom type\n schema.get = (value) => {\n return isDecimal(value) ? new type(value) : value;\n };\n }\n\n return useDecorators(\n Property(Number),\n Format(\"decimal\"),\n Example(12.34),\n StoreMerge(MONGOOSE_SCHEMA, schema),\n\n // Deserialize number value from JSON to Decimal128\n OnDeserialize((value) => {\n if (value === undefined) {\n return undefined;\n }\n if (type) {\n return new type(value);\n }\n if (isString(value)) {\n return Types.Decimal128.fromString(value);\n }\n return Types.Decimal128.fromString(`${value}`);\n }),\n\n // Serialize decimal value to floating point number\n OnSerialize((value: any, ctx) => {\n return value && Number(value);\n })\n );\n}\n\nexport type Decimal128 = Types.Decimal128;\n"]}
1
+ {"version":3,"file":"numberDecimal.js","sourceRoot":"","sources":["../../../src/decorators/numberDecimal.ts"],"names":[],"mappings":";;;;AAAA,mCAAkD;AAClD,qCAAyE;AACzE,mDAA6D;AAC7D,yCAAuD;AACvD,uCAA4E;AAC5E,sDAAuD;AAGvD,IAAa,aAAa,GAA1B,MAAa,aAAa;IACxB,QAAQ,CAAC,GAAoB;QAC3B,OAAO,IAAA,eAAQ,EAAC,GAAG,CAAC,IAAI,IAAA,eAAQ,EAAC,GAAG,CAAC,CAAC;IACxC,CAAC;CACF,CAAA;AAJY,aAAa;IADzB,IAAA,aAAO,EAAC,SAAS,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC,CAAC;GACxB,aAAa,CAIzB;AAJY,sCAAa;AAM1B,SAAS,SAAS,CAAC,KAA+B;IAChD,OAAO,KAAK,IAAI,KAAK,CAAC,SAAS,KAAK,YAAY,CAAC;AACnD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,aAAa,CAAC,IAAU;IACtC,MAAM,MAAM,GAAkC;QAC5C,IAAI,EAAE,iBAAc,CAAC,KAAK,CAAC,UAAU;KACtC,CAAC;IAEF,IAAI,IAAI,EAAE;QACR,8DAA8D;QAC9D,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,EAAE,EAAE;YACrB,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACpD,CAAC,CAAC;KACH;IAED,OAAO,IAAA,oBAAa,EAClB,IAAA,iBAAQ,EAAC,MAAM,CAAC,EAChB,IAAA,eAAM,EAAC,SAAS,CAAC,EACjB,IAAA,gBAAO,EAAC,KAAK,CAAC,EACd,IAAA,iBAAU,EAAC,2BAAe,EAAE,MAAM,CAAC;IAEnC,mDAAmD;IACnD,IAAA,2BAAa,EAAC,CAAC,KAAK,EAAE,EAAE;QACtB,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,OAAO,SAAS,CAAC;SAClB;QACD,IAAI,IAAI,EAAE;YACR,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;SACxB;QACD,IAAI,IAAA,eAAQ,EAAC,KAAK,CAAC,EAAE;YACnB,OAAO,gBAAK,CAAC,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;SAC3C;QACD,OAAO,gBAAK,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;IACjD,CAAC,CAAC;IAEF,mDAAmD;IACnD,IAAA,yBAAW,EAAC,CAAC,KAAU,EAAE,GAAG,EAAE,EAAE;QAC9B,OAAO,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AArCD,sCAqCC","sourcesContent":["import {Formats, FormatsMethods} from \"@tsed/ajv\";\nimport {isNumber, isString, StoreMerge, useDecorators} from \"@tsed/core\";\nimport {OnDeserialize, OnSerialize} from \"@tsed/json-mapper\";\nimport {Example, Format, Property} from \"@tsed/schema\";\nimport {Types, Schema as MongooseSchema, SchemaTypeOptions} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants/constants\";\n\n@Formats(\"decimal\", {type: \"number\"})\nexport class DecimalFormat implements FormatsMethods<string | number> {\n validate(num: string | number): boolean {\n return isString(num) || isNumber(num);\n }\n}\n\nfunction isDecimal(value: undefined | number | any) {\n return value && value._bsontype === \"Decimal128\";\n}\n\n/**\n * Tell Mongoose whether to define an Decimal128 property.\n * Will be serialized as `number` with format as `decimal`.\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class PriceModel {\n * @NumberDecimal()\n * price: Decimal128;\n * }\n * ```\n * Optionally using custom decimal type, such as `Big` from big.js\n * ```typescript\n * @Model()\n * export class PriceModel {\n * @NumberDecimal(Big)\n * price: Big;\n * }\n * ```\n * @param type Optional decimal type constructor\n * @decorator\n * @mongoose\n * @schema\n */\nexport function NumberDecimal(type?: any) {\n const schema: SchemaTypeOptions<Decimal128> = {\n type: MongooseSchema.Types.Decimal128\n };\n\n if (type) {\n // Define property getter to convert Decimal128 to custom type\n schema.get = (value) => {\n return isDecimal(value) ? new type(value) : value;\n };\n }\n\n return useDecorators(\n Property(Number),\n Format(\"decimal\"),\n Example(12.34),\n StoreMerge(MONGOOSE_SCHEMA, schema),\n\n // Deserialize number value from JSON to Decimal128\n OnDeserialize((value) => {\n if (value === undefined) {\n return undefined;\n }\n if (type) {\n return new type(value);\n }\n if (isString(value)) {\n return Types.Decimal128.fromString(value);\n }\n return Types.Decimal128.fromString(`${value}`);\n }),\n\n // Serialize decimal value to floating point number\n OnSerialize((value: any, ctx) => {\n return value && Number(value);\n })\n );\n}\n\nexport type Decimal128 = Types.Decimal128;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"postHook.js","sourceRoot":"","sources":["../../../src/decorators/postHook.ts"],"names":[],"mappings":";;;AAAA,qCAAkF;AAElF,0DAAqD;AAgDrD,SAAgB,QAAQ,CAAU,MAAc,EAAE,GAAG,MAAa;IAChE,OAAO,CAAC,CAAC,GAAG,IAAW,EAAE,EAAE;QACzB,IAAI,OAAO,GAAwB,MAAM,CAAC,CAAC,CAAC,CAAC;QAC7C,IAAI,EAAE,GAA0B,MAAM,CAAC,CAAC,CAAC,CAAC;QAE1C,IAAI,IAAA,sBAAe,EAAC,IAAI,CAAC,KAAK,qBAAc,CAAC,UAAU,EAAE;YACvD,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACpB,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACrC;QAED,IAAA,6BAAa,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YACrB,IAAI,EAAE;gBACJ;oBACE,MAAM;oBACN,EAAE;oBACF,OAAO;iBACR;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAQ,CAAC;AACZ,CAAC;AApBD,4BAoBC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, StaticMethodDecorator} from \"@tsed/core\";\nimport {MongooseHookOptions, MongoosePostHookCB} from \"../interfaces\";\nimport {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n * We can simply attach a `@PostHook` decorator to your model class and\n * define the hook function like you normally would in Mongoose.\n *\n * ```typescript\n * import {Ignore, Required} from \"@tsed/common\";\n * import {PostHook, Model} from \"@tsed/mongoose\";\n *\n * @Model()\n * @PostHook(\"save\", (car: CarModel) => {\n * if (car.topSpeedInKmH > 300) {\n * console.log(car.model, 'is fast!');\n * }\n * })\n * export class CarModel {\n * @Ignore()\n * _id: string;\n *\n * @Required()\n * model: string;\n *\n * @Required()\n * isFast: boolean;\n *\n * // or Prehook on static method\n * @PostHook(\"save\")\n * static postSave(car: CarModel) {\n * if (car.topSpeedInKmH > 300) {\n * console.log(car.model, 'is fast!');\n * }\n * }\n * }\n * ```\n *\n * This will execute the post-save hook each time a `CarModel` document is saved.\n *\n * @param {string} method\n * @param fn\n * @returns {Function}\n * @decorator\n * @mongoose\n * @class\n */\nexport function PostHook<T = any>(method: string, fn: MongoosePostHookCB<T>): ClassDecorator;\nexport function PostHook<T = any>(method: string, fn: MongoosePostHookCB<T>, options: MongooseHookOptions): ClassDecorator;\nexport function PostHook<T = any>(method: string, options: MongooseHookOptions): StaticMethodDecorator;\nexport function PostHook<T = any>(method: string, ...params: any[]): Function {\n return ((...args: any[]) => {\n let options: MongooseHookOptions = params[1];\n let fn: MongoosePostHookCB<T> = params[0];\n\n if (decoratorTypeOf(args) === DecoratorTypes.METHOD_STC) {\n options = params[0];\n fn = args[0][args[1]].bind(args[0]);\n }\n\n schemaOptions(args[0], {\n post: [\n {\n method,\n fn,\n options\n }\n ]\n });\n }) as any;\n}\n"]}
1
+ {"version":3,"file":"postHook.js","sourceRoot":"","sources":["../../../src/decorators/postHook.ts"],"names":[],"mappings":";;;AAAA,qCAAkF;AAElF,0DAAqD;AAgDrD,SAAgB,QAAQ,CAAU,MAAc,EAAE,GAAG,MAAa;IAChE,OAAO,CAAC,CAAC,GAAG,IAAW,EAAE,EAAE;QACzB,IAAI,OAAO,GAAwB,MAAM,CAAC,CAAC,CAAC,CAAC;QAC7C,IAAI,EAAE,GAA0B,MAAM,CAAC,CAAC,CAAC,CAAC;QAE1C,IAAI,IAAA,sBAAe,EAAC,IAAI,CAAC,KAAK,qBAAc,CAAC,UAAU,EAAE;YACvD,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACpB,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACrC;QAED,IAAA,6BAAa,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YACrB,IAAI,EAAE;gBACJ;oBACE,MAAM;oBACN,EAAE;oBACF,OAAO;iBACR;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAQ,CAAC;AACZ,CAAC;AApBD,4BAoBC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, StaticMethodDecorator} from \"@tsed/core\";\nimport {MongooseHookOptions, MongoosePostHookCB} from \"../interfaces/MongooseSchemaOptions\";\nimport {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n * We can simply attach a `@PostHook` decorator to your model class and\n * define the hook function like you normally would in Mongoose.\n *\n * ```typescript\n * import {Ignore, Required} from \"@tsed/common\";\n * import {PostHook, Model} from \"@tsed/mongoose\";\n *\n * @Model()\n * @PostHook(\"save\", (car: CarModel) => {\n * if (car.topSpeedInKmH > 300) {\n * console.log(car.model, 'is fast!');\n * }\n * })\n * export class CarModel {\n * @Ignore()\n * _id: string;\n *\n * @Required()\n * model: string;\n *\n * @Required()\n * isFast: boolean;\n *\n * // or Prehook on static method\n * @PostHook(\"save\")\n * static postSave(car: CarModel) {\n * if (car.topSpeedInKmH > 300) {\n * console.log(car.model, 'is fast!');\n * }\n * }\n * }\n * ```\n *\n * This will execute the post-save hook each time a `CarModel` document is saved.\n *\n * @param {string} method\n * @param fn\n * @returns {Function}\n * @decorator\n * @mongoose\n * @class\n */\nexport function PostHook<T = any>(method: string, fn: MongoosePostHookCB<T>): ClassDecorator;\nexport function PostHook<T = any>(method: string, fn: MongoosePostHookCB<T>, options: MongooseHookOptions): ClassDecorator;\nexport function PostHook<T = any>(method: string, options: MongooseHookOptions): StaticMethodDecorator;\nexport function PostHook<T = any>(method: string, ...params: any[]): Function {\n return ((...args: any[]) => {\n let options: MongooseHookOptions = params[1];\n let fn: MongoosePostHookCB<T> = params[0];\n\n if (decoratorTypeOf(args) === DecoratorTypes.METHOD_STC) {\n options = params[0];\n fn = args[0][args[1]].bind(args[0]);\n }\n\n schemaOptions(args[0], {\n post: [\n {\n method,\n fn,\n options\n }\n ]\n });\n }) as any;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"preHook.js","sourceRoot":"","sources":["../../../src/decorators/preHook.ts"],"names":[],"mappings":";;;AAAA,qCAA2D;AAE3D,0DAAqD;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,SAAgB,OAAO,CAAU,MAAc,EAAE,EAA+C,EAAE,OAA6B;IAC7H,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE;QACxB,IAAI,IAAA,sBAAe,EAAC,IAAI,CAAC,KAAK,qBAAc,CAAC,UAAU,EAAE;YACvD,OAAO,GAAG,EAAyB,CAAC;YACpC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACrC;QAED,IAAA,6BAAa,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YACrB,GAAG,EAAE;gBACH;oBACE,MAAM;oBACN,EAAE,EAAE,EAA0B;oBAC9B,OAAO;iBACR;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAjBD,0BAiBC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes} from \"@tsed/core\";\nimport {MongooseHookOptions, MongoosePreHookCB} from \"../interfaces\";\nimport {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n *\n * We can simply attach a `@PreHook` decorator to your model class and\n * define the hook function like you normally would in Mongoose.\n *\n * ```typescript\n * import {Ignore, Required} from \"@tsed/common\";\n * import {PreHook, Model} from \"@tsed/mongoose\";\n *\n * @Model()\n * @PreHook(\"save\", (car: CarModel, next) => {\n * if (car.model === 'Tesla') {\n * car.isFast = true;\n * }\n * next();\n *})\n * export class CarModel {\n *\n * @Ignore()\n * _id: string;\n *\n * @Required()\n * model: string;\n *\n * @Required()\n * isFast: boolean;\n *\n * // or Prehook on static method\n * @PreHook(\"save\")\n * static preSave(car: CarModel, next) {\n * if (car.model === 'Tesla') {\n * car.isFast = true;\n * }\n * next();\n * }\n * }\n * ```\n *\n * This will execute the pre-save hook each time a `CarModel` document is saved.\n *\n * @param {string} method\n * @param fn\n * @param options\n * @returns {Function}\n * @decorator\n * @class\n */\nexport function PreHook<T = any>(method: string, fn?: MongoosePreHookCB<T> | MongooseHookOptions, options?: MongooseHookOptions): Function {\n return (...args: any[]) => {\n if (decoratorTypeOf(args) === DecoratorTypes.METHOD_STC) {\n options = fn as MongooseHookOptions;\n fn = args[0][args[1]].bind(args[0]);\n }\n\n schemaOptions(args[0], {\n pre: [\n {\n method,\n fn: fn as MongoosePreHookCB<T>,\n options\n }\n ]\n });\n };\n}\n"]}
1
+ {"version":3,"file":"preHook.js","sourceRoot":"","sources":["../../../src/decorators/preHook.ts"],"names":[],"mappings":";;;AAAA,qCAA2D;AAE3D,0DAAqD;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,SAAgB,OAAO,CAAU,MAAc,EAAE,EAA+C,EAAE,OAA6B;IAC7H,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE;QACxB,IAAI,IAAA,sBAAe,EAAC,IAAI,CAAC,KAAK,qBAAc,CAAC,UAAU,EAAE;YACvD,OAAO,GAAG,EAAyB,CAAC;YACpC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACrC;QAED,IAAA,6BAAa,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YACrB,GAAG,EAAE;gBACH;oBACE,MAAM;oBACN,EAAE,EAAE,EAA0B;oBAC9B,OAAO;iBACR;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAjBD,0BAiBC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes} from \"@tsed/core\";\nimport {MongooseHookOptions, MongoosePreHookCB} from \"../interfaces/MongooseSchemaOptions\";\nimport {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n *\n * We can simply attach a `@PreHook` decorator to your model class and\n * define the hook function like you normally would in Mongoose.\n *\n * ```typescript\n * import {Ignore, Required} from \"@tsed/common\";\n * import {PreHook, Model} from \"@tsed/mongoose\";\n *\n * @Model()\n * @PreHook(\"save\", (car: CarModel, next) => {\n * if (car.model === 'Tesla') {\n * car.isFast = true;\n * }\n * next();\n *})\n * export class CarModel {\n *\n * @Ignore()\n * _id: string;\n *\n * @Required()\n * model: string;\n *\n * @Required()\n * isFast: boolean;\n *\n * // or Prehook on static method\n * @PreHook(\"save\")\n * static preSave(car: CarModel, next) {\n * if (car.model === 'Tesla') {\n * car.isFast = true;\n * }\n * next();\n * }\n * }\n * ```\n *\n * This will execute the pre-save hook each time a `CarModel` document is saved.\n *\n * @param {string} method\n * @param fn\n * @param options\n * @returns {Function}\n * @decorator\n * @class\n */\nexport function PreHook<T = any>(method: string, fn?: MongoosePreHookCB<T> | MongooseHookOptions, options?: MongooseHookOptions): Function {\n return (...args: any[]) => {\n if (decoratorTypeOf(args) === DecoratorTypes.METHOD_STC) {\n options = fn as MongooseHookOptions;\n fn = args[0][args[1]].bind(args[0]);\n }\n\n schemaOptions(args[0], {\n pre: [\n {\n method,\n fn: fn as MongoosePreHookCB<T>,\n options\n }\n ]\n });\n };\n}\n"]}
@@ -5,7 +5,7 @@ const core_1 = require("@tsed/core");
5
5
  const json_mapper_1 = require("@tsed/json-mapper");
6
6
  const schema_1 = require("@tsed/schema");
7
7
  const mongoose_1 = require("mongoose");
8
- const constants_1 = require("../constants");
8
+ const constants_1 = require("../constants/constants");
9
9
  const MongooseSchemaTypes_1 = require("../interfaces/MongooseSchemaTypes");
10
10
  const MongooseModels_1 = require("../registries/MongooseModels");
11
11
  function isRef(value) {
@@ -1 +1 @@
1
- {"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/decorators/ref.ts"],"names":[],"mappings":";;;AAAA,qCAA0F;AAC1F,mDAAwE;AACxE,yCAAwG;AACxG,uCAAkD;AAClD,4CAA6C;AAC7C,2EAAsE;AACtE,iEAA4D;AAO5D,SAAS,KAAK,CAAC,KAA+B;IAC5C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,cAAc,CAAC,eAAyB;IAC/C,OAAO,IAAA,oBAAa,EAClB,IAAA,sBAAa,EAAC,IAAI,CAAC,EACnB,IAAA,qBAAY,EAAC,CAAC,KAAK,EAAE,EAAE;QACrB,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,WAAqB,EAAE,EAAE;YACpE,IAAI,IAAA,oBAAW,EAAC,eAAe,EAAE,WAAW,CAAC,EAAE;gBAC7C,OAAO,GAAG,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ED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,EACF,IAAA,yBAAW,EAAC,CAAC,KAAU,EAAE,GAAG,EAAE,EAAE;QAC9B,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzB;QACD,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;QAEvB,OAAO,IAAA,uBAAS,EAAC,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,IAAI,EAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,EACF,IAAA,cAAK,EAAC,IAAA,eAAM,GAAE,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC,WAAW,CAAC,uBAAuB,CAAC,EAAE,IAAA,gBAAO,EAAC,OAAO,CAAC,CAAC,EAC1G,eAAe,CAAC,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,CACrC,CAAC;AACzB,CAAC;AA/BD,kBA+BC","sourcesContent":["import {isArrowFn, isObject, isString, StoreMerge, Type, useDecorators} from \"@tsed/core\";\nimport {OnDeserialize, OnSerialize, serialize} from \"@tsed/json-mapper\";\nimport {ForwardGroups, JsonEntityFn, lazyRef, matchGroups, OneOf, Property, string} from \"@tsed/schema\";\nimport {Schema as MongooseSchema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants\";\nimport {MongooseSchemaTypes} from \"../interfaces/MongooseSchemaTypes\";\nimport {MongooseModels} from \"../registries/MongooseModels\";\n\ninterface RefOptions {\n type?: MongooseSchemaTypes;\n populatedGroups?: string[];\n}\n\nfunction isRef(value: undefined | string | any) {\n return (value && value._bsontype) || isString(value);\n}\n\nfunction PopulateGroups(populatedGroups: string[]) {\n return useDecorators(\n ForwardGroups(true),\n JsonEntityFn((store) => {\n store.schema.$hooks.on(\"oneOf\", (obj: any[], givenGroups: string[]) => {\n if (matchGroups(populatedGroups, givenGroups)) {\n return obj.filter((x) => x.type === \"string\"); // keep the object id;\n } else {\n return obj.filter((x) => x.type !== \"string\"); // keep the ref definition\n }\n });\n })\n );\n}\n\n/**\n * Define a property as mongoose reference to other Model (decorated with @Model).\n *\n * ### Example\n *\n * ```typescript\n *\n * @Model()\n * class FooModel {\n *\n * @Ref(Foo2Model)\n * field: Ref<Foo2Model>\n *\n * @Ref(Foo2Model)\n * list: Ref<Foo2Model>[]\n * }\n *\n * @Model()\n * class Foo2Model {\n * }\n * ```\n *\n * @param model\n * @param options\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Ref(\n model: string | (() => Type) | any,\n options: RefOptions | MongooseSchemaTypes = MongooseSchemaTypes.OBJECT_ID\n): PropertyDecorator {\n const getType = () => (isString(model) ? MongooseModels.get(model) : isArrowFn(model) ? model() : model);\n const populatedGroups = (isObject(options) && options.populatedGroups) || [];\n\n return useDecorators(\n Property(Object),\n StoreMerge(MONGOOSE_SCHEMA, {\n type: MongooseSchema.Types[isObject(options) ? options.type || MongooseSchemaTypes.OBJECT_ID : options],\n ref: model\n }),\n OnDeserialize((value) => {\n if (isRef(value)) {\n return value.toString();\n }\n\n return value;\n }),\n OnSerialize((value: any, ctx) => {\n if (isRef(value)) {\n return value.toString();\n }\n const type = getType();\n\n return serialize(value, {...ctx, type});\n }),\n OneOf(string().example(\"5ce7ad3028890bd71749d477\").description(\"Mongoose Ref ObjectId\"), lazyRef(getType)),\n populatedGroups.length && PopulateGroups(populatedGroups)\n ) as PropertyDecorator;\n}\n\nexport type Ref<T> = T | string;\n"]}
1
+ {"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/decorators/ref.ts"],"names":[],"mappings":";;;AAAA,qCAA0F;AAC1F,mDAAwE;AACxE,yCAAwG;AACxG,uCAAkD;AAClD,sDAAuD;AACvD,2EAAsE;AACtE,iEAA4D;AAO5D,SAAS,KAAK,CAAC,KAA+B;IAC5C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAC;AACvD,CAAC;A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,iBAAc,CAAC,KAAK,CAAC,IAAA,eAAQ,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,yCAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;QACvG,GAAG,EAAE,KAAK;KACX,CAAC,EACF,IAAA,2BAAa,EAAC,CAAC,KAAK,EAAE,EAAE;QACtB,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzB;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,EACF,IAAA,yBAAW,EAAC,CAAC,KAAU,EAAE,GAAG,EAAE,EAAE;QAC9B,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzB;QACD,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;QAEvB,OAAO,IAAA,uBAAS,EAAC,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,IAAI,EAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,EACF,IAAA,cAAK,EAAC,IAAA,eAAM,GAAE,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC,WAAW,CAAC,uBAAuB,CAAC,EAAE,IAAA,gBAAO,EAAC,OAAO,CAAC,CAAC,EAC1G,eAAe,CAAC,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,CACrC,CAAC;AACzB,CAAC;AA/BD,kBA+BC","sourcesContent":["import {isArrowFn, isObject, isString, StoreMerge, Type, useDecorators} from \"@tsed/core\";\nimport {OnDeserialize, OnSerialize, serialize} from \"@tsed/json-mapper\";\nimport {ForwardGroups, JsonEntityFn, lazyRef, matchGroups, OneOf, Property, string} from \"@tsed/schema\";\nimport {Schema as MongooseSchema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants/constants\";\nimport {MongooseSchemaTypes} from \"../interfaces/MongooseSchemaTypes\";\nimport {MongooseModels} from \"../registries/MongooseModels\";\n\ninterface RefOptions {\n type?: MongooseSchemaTypes;\n populatedGroups?: string[];\n}\n\nfunction isRef(value: undefined | string | any) {\n return (value && value._bsontype) || isString(value);\n}\n\nfunction PopulateGroups(populatedGroups: string[]) {\n return useDecorators(\n ForwardGroups(true),\n JsonEntityFn((store) => {\n store.schema.$hooks.on(\"oneOf\", (obj: any[], givenGroups: string[]) => {\n if (matchGroups(populatedGroups, givenGroups)) {\n return obj.filter((x) => x.type === \"string\"); // keep the object id;\n } else {\n return obj.filter((x) => x.type !== \"string\"); // keep the ref definition\n }\n });\n })\n );\n}\n\n/**\n * Define a property as mongoose reference to other Model (decorated with @Model).\n *\n * ### Example\n *\n * ```typescript\n *\n * @Model()\n * class FooModel {\n *\n * @Ref(Foo2Model)\n * field: Ref<Foo2Model>\n *\n * @Ref(Foo2Model)\n * list: Ref<Foo2Model>[]\n * }\n *\n * @Model()\n * class Foo2Model {\n * }\n * ```\n *\n * @param model\n * @param options\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Ref(\n model: string | (() => Type) | any,\n options: RefOptions | MongooseSchemaTypes = MongooseSchemaTypes.OBJECT_ID\n): PropertyDecorator {\n const getType = () => (isString(model) ? MongooseModels.get(model) : isArrowFn(model) ? model() : model);\n const populatedGroups = (isObject(options) && options.populatedGroups) || [];\n\n return useDecorators(\n Property(Object),\n StoreMerge(MONGOOSE_SCHEMA, {\n type: MongooseSchema.Types[isObject(options) ? options.type || MongooseSchemaTypes.OBJECT_ID : options],\n ref: model\n }),\n OnDeserialize((value) => {\n if (isRef(value)) {\n return value.toString();\n }\n\n return value;\n }),\n OnSerialize((value: any, ctx) => {\n if (isRef(value)) {\n return value.toString();\n }\n const type = getType();\n\n return serialize(value, {...ctx, type});\n }),\n OneOf(string().example(\"5ce7ad3028890bd71749d477\").description(\"Mongoose Ref ObjectId\"), lazyRef(getType)),\n populatedGroups.length && PopulateGroups(populatedGroups)\n ) as PropertyDecorator;\n}\n\nexport type Ref<T> = T | string;\n"]}
@@ -4,7 +4,7 @@ exports.MongooseSchema = exports.Schema = void 0;
4
4
  const core_1 = require("@tsed/core");
5
5
  const di_1 = require("@tsed/di");
6
6
  const schema_1 = require("@tsed/schema");
7
- const constants_1 = require("../constants");
7
+ const constants_1 = require("../constants/constants");
8
8
  const createSchema_1 = require("../utils/createSchema");
9
9
  function Schema(options = {}) {
10
10
  return (...parameters) => {
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/decorators/schema.ts"],"names":[],"mappings":";;;AAAA,qCAAsE;AACtE,iCAA0C;AAC1C,yCAAsC;AAEtC,4CAA6C;AAE7C,wDAAgE;AA4BhE,SAAgB,MAAM,CAAC,UAA0D,EAAE;IACjF,OAAO,CAAC,GAAG,UAAiB,EAAE,EAAE;QAC9B,QAAQ,IAAA,sBAAe,EAAC,UAAU,CAAC,EAAE;YACnC,KAAK,UAAU;gBACb,OAAO,IAAA,oBAAa,EAAC,IAAA,iBAAQ,GAAE,EAAE,IAAA,iBAAU,EAAC,2BAAe,EAAE,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;YAEtH,KAAK,OAAO;gBACV,MAAM,EAAC,KAAK,EAAC,GAAG,IAAA,6BAAc,EAAC,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;gBAEvD,IAAA,qBAAgB,EAAC;oBACf,OAAO,EAAE,KAAK;oBACd,IAAI,EAAE,EAAE;oBACR,UAAU;wBACR,OAAO,IAAA,wBAAS,EAAC,UAAU,CAAC,CAAC,CAAC,EAAE,OAAc,CAAC,CAAC;oBAClD,CAAC;iBACF,CAAC,CAAC;gBACH,MAAM;SACT;IACH,CAAC,CAAC;AACJ,CAAC;AAnBD,wBAmBC;AA4BD,SAAgB,cAAc,CAAC,UAA0D,EAAE;IACzF,OAAO,MAAM,CAAC,OAAc,CAAC,CAAC;AAChC,CAAC;AAFD,wCAEC","sourcesContent":["import {decoratorTypeOf, StoreMerge, useDecorators} from \"@tsed/core\";\nimport {registerProvider} from \"@tsed/di\";\nimport {Property} from \"@tsed/schema\";\nimport {SchemaTypeOptions} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants\";\nimport {MongooseSchemaOptions} from \"../interfaces\";\nimport {getSchema, getSchemaToken} from \"../utils/createSchema\";\n\n/**\n * Define a class as a Mongoose Schema ready to be used to compose other schemes and models.\n *\n * ### Example\n *\n * ```typescript\n * @MongooseSchema()\n * export class EventSchema {\n * @Property()\n * field: string;\n * }\n * ```\n *\n * ### Options\n *\n * - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.\n *\n * @param {MongooseSchemaOptions | undefined} options\n * @returns {(target: any) => void}\n * @decorator\n * @mongoose\n * @property\n * @class\n */\nexport function Schema(options?: MongooseSchemaOptions): (target: any) => void;\nexport function Schema(definition: SchemaTypeOptions<any>): Function;\nexport function Schema(options: MongooseSchemaOptions | SchemaTypeOptions<any> = {}) {\n return (...parameters: any[]) => {\n switch (decoratorTypeOf(parameters)) {\n case \"property\":\n return useDecorators(Property(), StoreMerge(MONGOOSE_SCHEMA, options))(parameters[0], parameters[1], parameters[2]);\n\n case \"class\":\n const {token} = getSchemaToken(parameters[0], options);\n\n registerProvider({\n provide: token,\n deps: [],\n useFactory() {\n return getSchema(parameters[0], options as any);\n }\n });\n break;\n }\n };\n}\n\n/**\n * Define a class as a Mongoose Schema ready to be used to compose other schemes and models.\n *\n * ### Example\n *\n * ```typescript\n * @MongooseSchema()\n * export class EventSchema {\n * @Property()\n * field: string;\n * }\n * ```\n *\n * ### Options\n *\n * - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.\n *\n * @param {MongooseSchemaOptions | undefined} options\n * @returns {(target: any) => void}\n * @decorator\n * @mongoose\n * @property\n * @class\n */\nexport function MongooseSchema(options?: MongooseSchemaOptions): (target: any) => void;\nexport function MongooseSchema(definition: SchemaTypeOptions<any>): Function;\nexport function MongooseSchema(options: MongooseSchemaOptions | SchemaTypeOptions<any> = {}) {\n return Schema(options as any);\n}\n"]}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/decorators/schema.ts"],"names":[],"mappings":";;;AAAA,qCAAsE;AACtE,iCAA0C;AAC1C,yCAAsC;AAEtC,sDAAuD;AAEvD,wDAAgE;AA4BhE,SAAgB,MAAM,CAAC,UAA0D,EAAE;IACjF,OAAO,CAAC,GAAG,UAAiB,EAAE,EAAE;QAC9B,QAAQ,IAAA,sBAAe,EAAC,UAAU,CAAC,EAAE;YACnC,KAAK,UAAU;gBACb,OAAO,IAAA,oBAAa,EAAC,IAAA,iBAAQ,GAAE,EAAE,IAAA,iBAAU,EAAC,2BAAe,EAAE,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;YAEtH,KAAK,OAAO;gBACV,MAAM,EAAC,KAAK,EAAC,GAAG,IAAA,6BAAc,EAAC,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;gBAEvD,IAAA,qBAAgB,EAAC;oBACf,OAAO,EAAE,KAAK;oBACd,IAAI,EAAE,EAAE;oBACR,UAAU;wBACR,OAAO,IAAA,wBAAS,EAAC,UAAU,CAAC,CAAC,CAAC,EAAE,OAAc,CAAC,CAAC;oBAClD,CAAC;iBACF,CAAC,CAAC;gBACH,MAAM;SACT;IACH,CAAC,CAAC;AACJ,CAAC;AAnBD,wBAmBC;AA4BD,SAAgB,cAAc,CAAC,UAA0D,EAAE;IACzF,OAAO,MAAM,CAAC,OAAc,CAAC,CAAC;AAChC,CAAC;AAFD,wCAEC","sourcesContent":["import {decoratorTypeOf, StoreMerge, useDecorators} from \"@tsed/core\";\nimport {registerProvider} from \"@tsed/di\";\nimport {Property} from \"@tsed/schema\";\nimport {SchemaTypeOptions} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants/constants\";\nimport {MongooseSchemaOptions} from \"../interfaces/MongooseSchemaOptions\";\nimport {getSchema, getSchemaToken} from \"../utils/createSchema\";\n\n/**\n * Define a class as a Mongoose Schema ready to be used to compose other schemes and models.\n *\n * ### Example\n *\n * ```typescript\n * @MongooseSchema()\n * export class EventSchema {\n * @Property()\n * field: string;\n * }\n * ```\n *\n * ### Options\n *\n * - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.\n *\n * @param {MongooseSchemaOptions | undefined} options\n * @returns {(target: any) => void}\n * @decorator\n * @mongoose\n * @property\n * @class\n */\nexport function Schema(options?: MongooseSchemaOptions): (target: any) => void;\nexport function Schema(definition: SchemaTypeOptions<any>): Function;\nexport function Schema(options: MongooseSchemaOptions | SchemaTypeOptions<any> = {}) {\n return (...parameters: any[]) => {\n switch (decoratorTypeOf(parameters)) {\n case \"property\":\n return useDecorators(Property(), StoreMerge(MONGOOSE_SCHEMA, options))(parameters[0], parameters[1], parameters[2]);\n\n case \"class\":\n const {token} = getSchemaToken(parameters[0], options);\n\n registerProvider({\n provide: token,\n deps: [],\n useFactory() {\n return getSchema(parameters[0], options as any);\n }\n });\n break;\n }\n };\n}\n\n/**\n * Define a class as a Mongoose Schema ready to be used to compose other schemes and models.\n *\n * ### Example\n *\n * ```typescript\n * @MongooseSchema()\n * export class EventSchema {\n * @Property()\n * field: string;\n * }\n * ```\n *\n * ### Options\n *\n * - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.\n *\n * @param {MongooseSchemaOptions | undefined} options\n * @returns {(target: any) => void}\n * @decorator\n * @mongoose\n * @property\n * @class\n */\nexport function MongooseSchema(options?: MongooseSchemaOptions): (target: any) => void;\nexport function MongooseSchema(definition: SchemaTypeOptions<any>): Function;\nexport function MongooseSchema(options: MongooseSchemaOptions | SchemaTypeOptions<any> = {}) {\n return Schema(options as any);\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VersionKey = void 0;
4
4
  const core_1 = require("@tsed/core");
5
- const constants_1 = require("../constants");
5
+ const constants_1 = require("../constants/constants");
6
6
  function VersionKey() {
7
7
  return (target, propertyKey) => {
8
8
  core_1.Store.from(target).merge(constants_1.MONGOOSE_SCHEMA_OPTIONS, { versionKey: propertyKey });
@@ -1 +1 @@
1
- {"version":3,"file":"versionKey.js","sourceRoot":"","sources":["../../../src/decorators/versionKey.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,4CAAqD;AAErD,SAAgB,UAAU;IACxB,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,mCAAuB,EAAE,EAAC,UAAU,EAAE,WAAW,EAAC,CAAC,CAAC;IAC/E,CAAC,CAAC;AACJ,CAAC;AAJD,gCAIC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {MONGOOSE_SCHEMA_OPTIONS} from \"../constants\";\n\nexport function VersionKey(): PropertyDecorator {\n return (target: any, propertyKey: string) => {\n Store.from(target).merge(MONGOOSE_SCHEMA_OPTIONS, {versionKey: propertyKey});\n };\n}\n"]}
1
+ {"version":3,"file":"versionKey.js","sourceRoot":"","sources":["../../../src/decorators/versionKey.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,sDAA+D;AAE/D,SAAgB,UAAU;IACxB,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,mCAAuB,EAAE,EAAC,UAAU,EAAE,WAAW,EAAC,CAAC,CAAC;IAC/E,CAAC,CAAC;AACJ,CAAC;AAJD,gCAIC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {MONGOOSE_SCHEMA_OPTIONS} from \"../constants/constants\";\n\nexport function VersionKey(): PropertyDecorator {\n return (target: any, propertyKey: string) => {\n Store.from(target).merge(MONGOOSE_SCHEMA_OPTIONS, {versionKey: propertyKey});\n };\n}\n"]}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VirtualRef = void 0;
4
4
  const core_1 = require("@tsed/core");
5
5
  const schema_1 = require("@tsed/schema");
6
- const constants_1 = require("../constants");
6
+ const constants_1 = require("../constants/constants");
7
7
  const MongooseModels_1 = require("../registries/MongooseModels");
8
8
  function getRef(opts) {
9
9
  const ref = opts.ref;
@@ -1 +1 @@
1
- {"version":3,"file":"virtualRef.js","sourceRoot":"","sources":["../../../src/decorators/virtualRef.ts"],"names":[],"mappings":";;;AAAA,qCAAqF;AACrF,yCAAoD;AACpD,4CAAkE;AAElE,iEAA4D;AAE5D,SAAS,MAAM,CAAC,IAAS;IACvB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IAErB,OAAO,IAAA,eAAQ,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,+BAAmB,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,OAAO,CAAC,IAAS;IACxB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IACrB,OAAO,CAAC,IAAA,eAAQ,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,+BAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,+BAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,CAAC;AACrG,CAAC;AAED,SAAS,cAAc,CAAC,OAA2C,EAAE,YAAqB;IACxF,OAAO,IAAA,oBAAa,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAC,GAAG,EAAE,OAAc,EAAE,YAAY,EAAC,CAAC;AAChF,CAAC;AAED,SAAS,WAAW,CAAC,IAAS;IAC5B,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAEzB,MAAM,MAAM,GAAQ;QAClB,GAAG;QACH,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,KAAK;QACpC,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,KAAK;QAC9B,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,KAAK;QAC1B,OAAO,EAAE,IAAI,CAAC,OAAO;KACtB,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC;AA0BD,SAAgB,UAAU,CAAC,OAA2C,EAAE,YAAqB;IAC3F,MAAM,IAAI,GAAG,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3B,OAAO,IAAA,oBAAa,EAClB,IAAA,iBAAU,EAAC,2BAAe,EAAE,MAAM,CAAC,EACnC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAA,iBAAQ,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAA,iBAAQ,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,qBAAY,EAAC,IAAI,CAAC,CAAC,CACjG,CAAC;AACJ,CAAC;AATD,gCASC","sourcesContent":["import {isPlainObject, isString, Store, StoreMerge, useDecorators} from \"@tsed/core\";\nimport {CollectionOf, Property} from \"@tsed/schema\";\nimport {MONGOOSE_MODEL_NAME, MONGOOSE_SCHEMA} from \"../constants\";\nimport {MongooseVirtualRefOptions} from \"../interfaces/MongooseVirtualRefOptions\";\nimport {MongooseModels} from \"../registries/MongooseModels\";\n\nfunction getRef(opts: any) {\n const ref = opts.ref;\n\n return isString(ref) ? ref : Store.from(ref).get(MONGOOSE_MODEL_NAME);\n}\n\nfunction getType(opts: any) {\n const ref = opts.ref;\n return !isString(ref) ? ref : MongooseModels.get(ref) || (() => MongooseModels.get(ref) || Object);\n}\n\nfunction getInitialOpts(options: string | MongooseVirtualRefOptions, foreignField?: string): any {\n return isPlainObject(options) ? options : {ref: options as any, foreignField};\n}\n\nfunction mapToSchema(opts: any) {\n const ref = getRef(opts);\n\n const schema: any = {\n ref,\n localField: opts.localField || \"_id\",\n foreignField: opts.foreignField,\n justOne: opts.justOne || false,\n count: opts.count || false,\n options: opts.options\n };\n\n return schema;\n}\n\n/**\n * Define a property as mongoose virtual reference to other Model (decorated with @Model).\n *\n * ::: warning\n * To avoid circular dependencies, do not use the virtual reference model in\n * anything except a type declaration. Using the virtual reference model will prevent\n * typescript transpiler from stripping away the import statement and cause a circular\n * import in node.\n * :::\n *\n * ### Example\n *\n * <<< @/tutorials/snippets/mongoose/virtual-references.ts\n *\n * @param ref\n * @param foreignField\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function VirtualRef(ref: string, foreignField: string): Function;\nexport function VirtualRef(options: MongooseVirtualRefOptions): Function;\nexport function VirtualRef(options: string | MongooseVirtualRefOptions, foreignField?: string): Function;\nexport function VirtualRef(options: string | MongooseVirtualRefOptions, foreignField?: string): Function {\n const opts = getInitialOpts(options, foreignField);\n const schema = mapToSchema(opts);\n const type = getType(opts);\n\n return useDecorators(\n StoreMerge(MONGOOSE_SCHEMA, schema),\n schema.count ? Property(Number) : type && (schema.justOne ? Property(type) : CollectionOf(type))\n );\n}\n\nexport type VirtualRef<T> = T | null;\nexport type VirtualRefs<T> = T[];\n"]}
1
+ {"version":3,"file":"virtualRef.js","sourceRoot":"","sources":["../../../src/decorators/virtualRef.ts"],"names":[],"mappings":";;;AAAA,qCAAqF;AACrF,yCAAoD;AACpD,sDAA4E;AAE5E,iEAA4D;AAE5D,SAAS,MAAM,CAAC,IAAS;IACvB,MAAM,GAAG,GAAG,IAA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AAI,CAAC,CAAC;IACjC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3B,OAAO,IAAA,oBAAa,EAClB,IAAA,iBAAU,EAAC,2BAAe,EAAE,MAAM,CAAC,EACnC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAA,iBAAQ,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAA,iBAAQ,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,qBAAY,EAAC,IAAI,CAAC,CAAC,CACjG,CAAC;AACJ,CAAC;AATD,gCASC","sourcesContent":["import {isPlainObject, isString, Store, StoreMerge, useDecorators} from \"@tsed/core\";\nimport {CollectionOf, Property} from \"@tsed/schema\";\nimport {MONGOOSE_MODEL_NAME, MONGOOSE_SCHEMA} from \"../constants/constants\";\nimport {MongooseVirtualRefOptions} from \"../interfaces/MongooseVirtualRefOptions\";\nimport {MongooseModels} from \"../registries/MongooseModels\";\n\nfunction getRef(opts: any) {\n const ref = opts.ref;\n\n return isString(ref) ? ref : Store.from(ref).get(MONGOOSE_MODEL_NAME);\n}\n\nfunction getType(opts: any) {\n const ref = opts.ref;\n return !isString(ref) ? ref : MongooseModels.get(ref) || (() => MongooseModels.get(ref) || Object);\n}\n\nfunction getInitialOpts(options: string | MongooseVirtualRefOptions, foreignField?: string): any {\n return isPlainObject(options) ? options : {ref: options as any, foreignField};\n}\n\nfunction mapToSchema(opts: any) {\n const ref = getRef(opts);\n\n const schema: any = {\n ref,\n localField: opts.localField || \"_id\",\n foreignField: opts.foreignField,\n justOne: opts.justOne || false,\n count: opts.count || false,\n options: opts.options\n };\n\n return schema;\n}\n\n/**\n * Define a property as mongoose virtual reference to other Model (decorated with @Model).\n *\n * ::: warning\n * To avoid circular dependencies, do not use the virtual reference model in\n * anything except a type declaration. Using the virtual reference model will prevent\n * typescript transpiler from stripping away the import statement and cause a circular\n * import in node.\n * :::\n *\n * @param ref\n * @param foreignField\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function VirtualRef(ref: string, foreignField: string): Function;\nexport function VirtualRef(options: MongooseVirtualRefOptions): Function;\nexport function VirtualRef(options: string | MongooseVirtualRefOptions, foreignField?: string): Function;\nexport function VirtualRef(options: string | MongooseVirtualRefOptions, foreignField?: string): Function {\n const opts = getInitialOpts(options, foreignField);\n const schema = mapToSchema(opts);\n const type = getType(opts);\n\n return useDecorators(\n StoreMerge(MONGOOSE_SCHEMA, schema),\n schema.count ? Property(Number) : type && (schema.justOne ? Property(type) : CollectionOf(type))\n );\n}\n\nexport type VirtualRef<T> = T | null;\nexport type VirtualRefs<T> = T[];\n"]}
package/lib/cjs/index.js CHANGED
@@ -1,10 +1,51 @@
1
1
  "use strict";
2
+ /**
3
+ * @file Automatically generated by barrelsby.
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./interfaces"), exports);
5
- (0, tslib_1.__exportStar)(require("./constants"), exports);
6
- (0, tslib_1.__exportStar)(require("./services/MongooseService"), exports);
7
- (0, tslib_1.__exportStar)(require("./MongooseModule"), exports);
8
- (0, tslib_1.__exportStar)(require("./utils"), exports);
9
- (0, tslib_1.__exportStar)(require("./decorators"), exports);
7
+ tslib_1.__exportStar(require("./MongooseModule"), exports);
8
+ tslib_1.__exportStar(require("./constants/constants"), exports);
9
+ tslib_1.__exportStar(require("./decorators/auto"), exports);
10
+ tslib_1.__exportStar(require("./decorators/discriminatorKey"), exports);
11
+ tslib_1.__exportStar(require("./decorators/dynamicRef"), exports);
12
+ tslib_1.__exportStar(require("./decorators/excludeIndexes"), exports);
13
+ tslib_1.__exportStar(require("./decorators/expires"), exports);
14
+ tslib_1.__exportStar(require("./decorators/immutable"), exports);
15
+ tslib_1.__exportStar(require("./decorators/indexed"), exports);
16
+ tslib_1.__exportStar(require("./decorators/lowercase"), exports);
17
+ tslib_1.__exportStar(require("./decorators/model"), exports);
18
+ tslib_1.__exportStar(require("./decorators/mongooseIndex"), exports);
19
+ tslib_1.__exportStar(require("./decorators/mongooseIndexes"), exports);
20
+ tslib_1.__exportStar(require("./decorators/mongoosePlugin"), exports);
21
+ tslib_1.__exportStar(require("./decorators/numberDecimal"), exports);
22
+ tslib_1.__exportStar(require("./decorators/objectID"), exports);
23
+ tslib_1.__exportStar(require("./decorators/postHook"), exports);
24
+ tslib_1.__exportStar(require("./decorators/preHook"), exports);
25
+ tslib_1.__exportStar(require("./decorators/ref"), exports);
26
+ tslib_1.__exportStar(require("./decorators/schema"), exports);
27
+ tslib_1.__exportStar(require("./decorators/schemaIgnore"), exports);
28
+ tslib_1.__exportStar(require("./decorators/select"), exports);
29
+ tslib_1.__exportStar(require("./decorators/sparse"), exports);
30
+ tslib_1.__exportStar(require("./decorators/text"), exports);
31
+ tslib_1.__exportStar(require("./decorators/trim"), exports);
32
+ tslib_1.__exportStar(require("./decorators/unique"), exports);
33
+ tslib_1.__exportStar(require("./decorators/uppercase"), exports);
34
+ tslib_1.__exportStar(require("./decorators/versionKey"), exports);
35
+ tslib_1.__exportStar(require("./decorators/virtualRef"), exports);
36
+ tslib_1.__exportStar(require("./interfaces/MongooseConnectionOptions"), exports);
37
+ tslib_1.__exportStar(require("./interfaces/MongooseDocument"), exports);
38
+ tslib_1.__exportStar(require("./interfaces/MongooseModel"), exports);
39
+ tslib_1.__exportStar(require("./interfaces/MongooseModelOptions"), exports);
40
+ tslib_1.__exportStar(require("./interfaces/MongooseSchemaOptions"), exports);
41
+ tslib_1.__exportStar(require("./interfaces/MongooseSchemaTypes"), exports);
42
+ tslib_1.__exportStar(require("./interfaces/MongooseVirtualRefOptions"), exports);
43
+ tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
44
+ tslib_1.__exportStar(require("./registries/MongooseModels"), exports);
45
+ tslib_1.__exportStar(require("./services/MongooseConnections"), exports);
46
+ tslib_1.__exportStar(require("./services/MongooseService"), exports);
47
+ tslib_1.__exportStar(require("./utils/createModel"), exports);
48
+ tslib_1.__exportStar(require("./utils/createSchema"), exports);
49
+ tslib_1.__exportStar(require("./utils/resolveRefType"), exports);
50
+ tslib_1.__exportStar(require("./utils/schemaOptions"), exports);
10
51
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,4DAA6B;AAC7B,2DAA4B;AAC5B,0EAA2C;AAC3C,gEAAiC;AACjC,uDAAwB;AACxB,4DAA6B","sourcesContent":["export * from \"./interfaces\";\nexport * from \"./constants\";\nexport * from \"./services/MongooseService\";\nexport * from \"./MongooseModule\";\nexport * from \"./utils\";\nexport * from \"./decorators\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,2DAAiC;AACjC,gEAAsC;AACtC,4DAAkC;AAClC,wEAA8C;AAC9C,kEAAwC;AACxC,sEAA4C;AAC5C,+DAAqC;AACrC,iEAAuC;AACvC,+DAAqC;AACrC,iEAAuC;AACvC,6DAAmC;AACnC,qEAA2C;AAC3C,uEAA6C;AAC7C,sEAA4C;AAC5C,qEAA2C;AAC3C,gEAAsC;AACtC,gEAAsC;AACtC,+DAAqC;AACrC,2DAAiC;AACjC,8DAAoC;AACpC,oEAA0C;AAC1C,8DAAoC;AACpC,8DAAoC;AACpC,4DAAkC;AAClC,4DAAkC;AAClC,8DAAoC;AACpC,iEAAuC;AACvC,kEAAwC;AACxC,kEAAwC;AACxC,iFAAuD;AACvD,wEAA8C;AAC9C,qEAA2C;AAC3C,4EAAkD;AAClD,6EAAmD;AACnD,2EAAiD;AACjD,iFAAuD;AACvD,kEAAwC;AACxC,sEAA4C;AAC5C,yEAA+C;AAC/C,qEAA2C;AAC3C,8DAAoC;AACpC,+DAAqC;AACrC,iEAAuC;AACvC,gEAAsC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./MongooseModule\";\nexport * from \"./constants/constants\";\nexport * from \"./decorators/auto\";\nexport * from \"./decorators/discriminatorKey\";\nexport * from \"./decorators/dynamicRef\";\nexport * from \"./decorators/excludeIndexes\";\nexport * from \"./decorators/expires\";\nexport * from \"./decorators/immutable\";\nexport * from \"./decorators/indexed\";\nexport * from \"./decorators/lowercase\";\nexport * from \"./decorators/model\";\nexport * from \"./decorators/mongooseIndex\";\nexport * from \"./decorators/mongooseIndexes\";\nexport * from \"./decorators/mongoosePlugin\";\nexport * from \"./decorators/numberDecimal\";\nexport * from \"./decorators/objectID\";\nexport * from \"./decorators/postHook\";\nexport * from \"./decorators/preHook\";\nexport * from \"./decorators/ref\";\nexport * from \"./decorators/schema\";\nexport * from \"./decorators/schemaIgnore\";\nexport * from \"./decorators/select\";\nexport * from \"./decorators/sparse\";\nexport * from \"./decorators/text\";\nexport * from \"./decorators/trim\";\nexport * from \"./decorators/unique\";\nexport * from \"./decorators/uppercase\";\nexport * from \"./decorators/versionKey\";\nexport * from \"./decorators/virtualRef\";\nexport * from \"./interfaces/MongooseConnectionOptions\";\nexport * from \"./interfaces/MongooseDocument\";\nexport * from \"./interfaces/MongooseModel\";\nexport * from \"./interfaces/MongooseModelOptions\";\nexport * from \"./interfaces/MongooseSchemaOptions\";\nexport * from \"./interfaces/MongooseSchemaTypes\";\nexport * from \"./interfaces/MongooseVirtualRefOptions\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./registries/MongooseModels\";\nexport * from \"./services/MongooseConnections\";\nexport * from \"./services/MongooseService\";\nexport * from \"./utils/createModel\";\nexport * from \"./utils/createSchema\";\nexport * from \"./utils/resolveRefType\";\nexport * from \"./utils/schemaOptions\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MongooseModel.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseModel.ts"],"names":[],"mappings":"","sourcesContent":["import {JsonDeserializerOptions} from \"@tsed/json-mapper\";\nimport {Document, Model} from \"mongoose\";\n\n// TODO since v5.11.5 Model require Document with id, See issue https://github.com/Automattic/mongoose/issues/9684\nexport type MongooseMergedDocument<T> = {[K in keyof T]: T[K]};\n\nexport interface MongooseDocumentMethods<T> {\n toClass(): T;\n}\n\nexport interface MongooseModel<T> extends Model<MongooseMergedDocument<Document & T & MongooseDocumentMethods<T>>> {}\n"]}
1
+ {"version":3,"file":"MongooseModel.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseModel.ts"],"names":[],"mappings":"","sourcesContent":["import {Document, Model} from \"mongoose\";\n\n// TODO since v5.11.5 Model require Document with id, See issue https://github.com/Automattic/mongoose/issues/9684\nexport type MongooseMergedDocument<T> = {[K in keyof T]: T[K]};\n\nexport interface MongooseDocumentMethods<T> {\n toClass(): T;\n}\n\nexport type MongooseModel<T> = Model<MongooseMergedDocument<Document & T & MongooseDocumentMethods<T>>>;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MongooseModelOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseModelOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {MongooseSchemaOptions} from \"./MongooseSchemaOptions\";\n\nexport interface MongooseModelOptions extends MongooseSchemaOptions {\n name?: string;\n connection?: string;\n collection?: string;\n skipInit?: boolean;\n discriminatorValue?: string;\n}\n"]}
1
+ {"version":3,"file":"MongooseModelOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseModelOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {MongooseSchemaOptions} from \"./MongooseSchemaOptions\";\nimport {CompileModelOptions} from \"mongoose\";\n\nexport interface MongooseModelOptions extends MongooseSchemaOptions {\n name?: string;\n connection?: string;\n collection?: string;\n overwriteModels?: boolean;\n discriminatorValue?: string;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MongooseSchemaOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseSchemaOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {NativeError, Schema, SchemaOptions} from \"mongoose\";\nimport {MongooseDocument} from \"./MongooseDocument\";\n\nexport type MongooseNextCB = (err?: NativeError) => void;\n\nexport interface MongooseHookOptions {\n document?: boolean;\n query?: boolean;\n parallel?: boolean;\n}\n\nexport type MongoosePreHookCB<T = any> =\n | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>) => Promise<void> | void);\n\nexport type MongoosePostHookCB<T = any> =\n | ((doc: T | MongooseDocument<T>, error: NativeError, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>, error: NativeError) => Promise<void> | void)\n | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>) => Promise<void> | void);\n\nexport interface MongoosePreHook<T = any> {\n method: string | RegExp;\n fn: MongoosePreHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePostHook<T = any> {\n method: string | RegExp;\n fn: MongoosePostHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePluginOptions {\n plugin: (schema: Schema, options?: any) => void;\n options?: Record<string, unknown>;\n}\n\nexport interface MongooseIndexOptions {\n fields: object;\n options?: Record<string, unknown>;\n}\n\nexport interface MongooseSchemaOptions {\n schemaOptions?: SchemaOptions;\n plugins?: MongoosePluginOptions[];\n indexes?: MongooseIndexOptions[];\n pre?: MongoosePreHook[];\n post?: MongoosePostHook[];\n}\n"]}
1
+ {"version":3,"file":"MongooseSchemaOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseSchemaOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {NativeError, Schema, SchemaOptions} from \"mongoose\";\nimport {MongooseDocument} from \"./MongooseDocument\";\n\nexport type MongooseNextCB = (err?: NativeError) => void;\n\nexport interface MongooseHookOptions {\n document?: boolean;\n query?: boolean;\n parallel?: boolean;\n}\n\nexport type MongoosePreHookCB<T = any> =\n | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>) => Promise<void> | void);\n\nexport type MongoosePostHookCB<T = any> =\n | ((doc: T | MongooseDocument<T>, error: NativeError, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>, error: NativeError) => Promise<void> | void)\n | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>) => Promise<void> | void);\n\nexport interface MongoosePreHook<T = any> {\n method: string | RegExp;\n fn: MongoosePreHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePostHook<T = any> {\n method: string | RegExp;\n fn: MongoosePostHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePluginOptions {\n plugin: (schema: Schema, options?: any) => void;\n options?: Record<string, unknown>;\n}\n\nexport interface MongooseIndexOptions {\n fields: Record<any, any>;\n options?: Record<string, unknown>;\n}\n\nexport interface MongooseSchemaOptions {\n schemaOptions?: SchemaOptions;\n plugins?: MongoosePluginOptions[];\n indexes?: MongooseIndexOptions[];\n pre?: MongoosePreHook[];\n post?: MongoosePostHook[];\n}\n"]}
@@ -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/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import {MongooseConnectionOptions} from \"./MongooseConnectionOptions\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n mongoose: Omit<MongooseConnectionOptions, \"id\"> | MongooseConnectionOptions[];\n }\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -38,11 +38,7 @@ function mapOptions(options) {
38
38
  const settings = mapOptions(configuration.get("mongoose"));
39
39
  let isDefault = true;
40
40
  for (const current of settings) {
41
- await mongooseService.connect(current.id, current.url, current.connectionOptions || {
42
- useCreateIndex: true,
43
- useNewUrlParser: true,
44
- useUnifiedTopology: true
45
- }, isDefault);
41
+ await mongooseService.connect(current.id, current.url, current.connectionOptions || {}, isDefault);
46
42
  isDefault = false;
47
43
  }
48
44
  return mongooseService;
@@ -1 +1 @@
1
- {"version":3,"file":"MongooseConnections.js","sourceRoot":"","sources":["../../../src/services/MongooseConnections.ts"],"names":[],"mappings":";;;AAAA,iCAAyD;AACzD,qCAAmC;AAEnC,iEAA4D;AAE5D;;GAEG;AACH,yCAAyC;AAC5B,QAAA,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAMvE,SAAS,UAAU,CAAC,OAA4E;IAC9F,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,EAAE,CAAC;KACX;IAED,IAAI,CAAC,IAAA,cAAO,EAAC,OAAO,CAAC,EAAE;QACrB,MAAM,EAAC,GAAG,EAAE,iBAAiB,EAAC,GAAG,OAAO,IAAI,EAAE,CAAC;QAE/C,OAAO;YACL;gBACE,EAAE,EAAE,SAAS;gBACb,GAAG;gBACH,iBAAiB;aAClB;SACF,CAAC;KACH;IAED,OAAQ,OAAuC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC/D,OAAO;YACL,GAAG,QAAQ;YACX,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB;SAC9C,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,IAAA,qBAAgB,EAAC;IACf,OAAO,EAAE,4BAAoB;IAC7B,UAAU,EAAE,KAAK;IACjB,IAAI,EAAE,CAAC,kBAAa,EAAE,iCAAe,CAAC;IACtC,KAAK,CAAC,eAAe,CAAC,aAA4B,EAAE,eAAgC;QAClF,MAAM,QAAQ,GAAG,UAAU,CAAC,aAAa,CAAC,GAAG,CAA0D,UAAU,CAAC,CAAC,CAAC;QACpH,IAAI,SAAS,GAAG,IAAI,CAAC;QAErB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC9B,MAAM,eAAe,CAAC,OAAO,CAC3B,OAAO,CAAC,EAAE,EACV,OAAO,CAAC,GAAG,EACX,OAAO,CAAC,iBAAiB,IAAI;gBAC3B,cAAc,EAAE,IAAI;gBACpB,eAAe,EAAE,IAAI;gBACrB,kBAAkB,EAAE,IAAI;aACzB,EACD,SAAS,CACV,CAAC;YAEF,SAAS,GAAG,KAAK,CAAC;SACnB;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;CACF,CAAC,CAAC","sourcesContent":["import {Configuration, registerProvider} from \"@tsed/di\";\nimport {isArray} from \"@tsed/core\";\nimport {MongooseConnectionOptions} from \"../interfaces\";\nimport {MongooseService} from \"../services/MongooseService\";\n\n/**\n * @ignore\n */\n// tslint:disable-next-line:variable-name\nexport const MONGOOSE_CONNECTIONS = Symbol.for(\"MONGOOSE_CONNECTIONS\");\n/**\n * @ignore\n */\nexport type MONGOOSE_CONNECTIONS = MongooseService;\n\nfunction mapOptions(options: Omit<MongooseConnectionOptions, \"id\"> | MongooseConnectionOptions[]): MongooseConnectionOptions[] {\n if (!options) {\n return [];\n }\n\n if (!isArray(options)) {\n const {url, connectionOptions} = options || {};\n\n return [\n {\n id: \"default\",\n url,\n connectionOptions\n }\n ];\n }\n\n return (options as MongooseConnectionOptions[]).map((settings) => {\n return {\n ...settings,\n connectionOptions: settings.connectionOptions\n };\n });\n}\n\nregisterProvider({\n provide: MONGOOSE_CONNECTIONS,\n injectable: false,\n deps: [Configuration, MongooseService],\n async useAsyncFactory(configuration: Configuration, mongooseService: MongooseService) {\n const settings = mapOptions(configuration.get<MongooseConnectionOptions | MongooseConnectionOptions[]>(\"mongoose\"));\n let isDefault = true;\n\n for (const current of settings) {\n await mongooseService.connect(\n current.id,\n current.url,\n current.connectionOptions || {\n useCreateIndex: true,\n useNewUrlParser: true,\n useUnifiedTopology: true\n },\n isDefault\n );\n\n isDefault = false;\n }\n\n return mongooseService;\n }\n});\n"]}
1
+ {"version":3,"file":"MongooseConnections.js","sourceRoot":"","sources":["../../../src/services/MongooseConnections.ts"],"names":[],"mappings":";;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erProvider} from \"@tsed/di\";\nimport {isArray} from \"@tsed/core\";\nimport {MongooseConnectionOptions} from \"../interfaces/MongooseConnectionOptions\";\nimport {MongooseService} from \"../services/MongooseService\";\n\n/**\n * @ignore\n */\n// tslint:disable-next-line:variable-name\nexport const MONGOOSE_CONNECTIONS = Symbol.for(\"MONGOOSE_CONNECTIONS\");\n/**\n * @ignore\n */\nexport type MONGOOSE_CONNECTIONS = MongooseService;\n\nfunction mapOptions(options: Omit<MongooseConnectionOptions, \"id\"> | MongooseConnectionOptions[]): MongooseConnectionOptions[] {\n if (!options) {\n return [];\n }\n\n if (!isArray(options)) {\n const {url, connectionOptions} = options || {};\n\n return [\n {\n id: \"default\",\n url,\n connectionOptions\n }\n ];\n }\n\n return (options as MongooseConnectionOptions[]).map((settings) => {\n return {\n ...settings,\n connectionOptions: settings.connectionOptions\n };\n });\n}\n\nregisterProvider({\n provide: MONGOOSE_CONNECTIONS,\n injectable: false,\n deps: [Configuration, MongooseService],\n async useAsyncFactory(configuration: Configuration, mongooseService: MongooseService) {\n const settings = mapOptions(configuration.get<MongooseConnectionOptions | MongooseConnectionOptions[]>(\"mongoose\"));\n let isDefault = true;\n\n for (const current of settings) {\n await mongooseService.connect(current.id, current.url, current.connectionOptions || {}, isDefault);\n\n isDefault = false;\n }\n\n return mongooseService;\n }\n});\n"]}
@@ -4,7 +4,7 @@ exports.MongooseService = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const di_1 = require("@tsed/di");
6
6
  const logger_1 = require("@tsed/logger");
7
- const mongoose_1 = (0, tslib_1.__importDefault)(require("mongoose"));
7
+ const mongoose_1 = tslib_1.__importDefault(require("mongoose"));
8
8
  // istanbul ignore next
9
9
  function asPromise(c) {
10
10
  return c && c.asPromise ? c.asPromise() : c;
@@ -62,11 +62,11 @@ let MongooseService = class MongooseService {
62
62
  }
63
63
  }
64
64
  };
65
- (0, tslib_1.__decorate)([
65
+ tslib_1.__decorate([
66
66
  (0, di_1.Inject)(),
67
- (0, tslib_1.__metadata)("design:type", logger_1.Logger)
67
+ tslib_1.__metadata("design:type", logger_1.Logger)
68
68
  ], MongooseService.prototype, "logger", void 0);
69
- MongooseService = (0, tslib_1.__decorate)([
69
+ MongooseService = tslib_1.__decorate([
70
70
  (0, di_1.Injectable)()
71
71
  ], MongooseService);
72
72
  exports.MongooseService = MongooseService;
@@ -1 +1 @@
1
- {"version":3,"file":"MongooseService.js","sourceRoot":"","sources":["../../../src/services/MongooseService.ts"],"names":[],"mappings":";;;;AAAA,iCAA4C;AAC5C,yCAAoC;AACpC,qEAAgC;AAGhC,uBAAuB;AACvB,SAAS,SAAS,CAAC,CAAM;IACvB,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC;AAGD,IAAa,eAAe,GAA5B,MAAa,eAAe;IAA5B;QACW,gBAAW,GAAqC,IAAI,GAAG,EAAE,CAAC;QAC3D,sBAAiB,GAAW,SAAS,CAAC;IA0DhD,CAAC;IArDC;;;OAGG;IACH,KAAK,CAAC,OAAO,CAAC,EAAU,EAAE,GAAW,EAAE,iBAAiC,EAAE,SAAS,GAAG,KAAK;QACzF,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAChB,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC;SAC5B;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,8BAA8B,EAAE,EAAE,CAAC,CAAC;QACrD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;QAEnE,IAAI;YACF,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,kBAAQ,CAAC,gBAAgB,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC;YACtF,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;YAErC,IAAI,EAAE,KAAK,SAAS,IAAI,SAAS,EAAE;gBACjC,IAAI,CAAC,iBAAiB,GAAG,EAAE,CAAC;aAC7B;YAED,OAAO,UAAU,CAAC;SACnB;QAAC,OAAO,EAAE,EAAE;YACX,0BAA0B;YAC1B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACtB,0BAA0B;YAC1B,OAAO,CAAC,IAAI,EAAE,CAAC;SAChB;IACH,CAAC;IAED;;;OAGG;IACH,GAAG,CAAC,EAAW;QACb,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAC5D,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,EAAW;QACb,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,KAAK,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE;YACzD,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SAC7B;IACH,CAAC;CACF,CAAA;AAvDC;IADC,IAAA,WAAM,GAAE;2CACD,eAAM;+CAAC;AALJ,eAAe;IAD3B,IAAA,eAAU,GAAE;GACA,eAAe,CA4D3B;AA5DY,0CAAe","sourcesContent":["import {Inject, Injectable} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport Mongoose from \"mongoose\";\nimport {ConnectOptions} from \"mongoose\";\n\n// istanbul ignore next\nfunction asPromise(c: any) {\n return c && c.asPromise ? c.asPromise() : c;\n}\n\n@Injectable()\nexport class MongooseService {\n readonly connections: Map<string, Mongoose.Connection> = new Map();\n private defaultConnection: string = \"default\";\n\n @Inject()\n logger: Logger;\n\n /**\n *\n * @returns {Promise<\"mongoose\".Connection>}\n */\n async connect(id: string, url: string, connectionOptions: ConnectOptions, isDefault = false): Promise<any> {\n if (this.has(id)) {\n return await this.get(id)!;\n }\n\n this.logger.info(`Connect to mongo database: ${id}`);\n this.logger.debug(`Url: ${url}`);\n this.logger.debug(`options: ${JSON.stringify(connectionOptions)}`);\n\n try {\n const connection = await asPromise(Mongoose.createConnection(url, connectionOptions));\n this.connections.set(id, connection);\n\n if (id === \"default\" || isDefault) {\n this.defaultConnection = id;\n }\n\n return connection;\n } catch (er) {\n /* istanbul ignore next */\n this.logger.error(er);\n /* istanbul ignore next */\n process.exit();\n }\n }\n\n /**\n *\n * @returns {\"mongoose\".Connection}\n */\n get(id?: string): Mongoose.Connection | undefined {\n return this.connections.get(id || this.defaultConnection);\n }\n\n /**\n *\n * @param {string} id\n * @returns {boolean}\n */\n has(id?: string): boolean {\n return this.connections.has(id || this.defaultConnection);\n }\n\n async closeConnections() {\n for (const [id, connection] of this.connections.entries()) {\n await connection.close();\n this.connections.delete(id);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"MongooseService.js","sourceRoot":"","sources":["../../../src/services/MongooseService.ts"],"names":[],"mappings":";;;;AAAA,iCAA4C;AAC5C,yCAAoC;AACpC,gEAAgC;AAGhC,uBAAuB;AACvB,SAAS,SAAS,CAAC,CAAM;IACvB,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC;AAGD,IAAa,eAAe,GAA5B,MAAa,eAAe;IAA5B;QACW,gBAAW,GAAqC,IAAI,GAAG,EAAE,CAAC;QAC3D,sBAAiB,GAAW,SAAS,CAAC;IA0DhD,CAAC;IArDC;;;OAGG;IACH,KAAK,CAAC,OA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AAgB;QACpB,KAAK,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE;YACzD,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SAC7B;IACH,CAAC;CACF,CAAA;AAvDC;IADC,IAAA,WAAM,GAAE;sCACD,eAAM;+CAAC;AALJ,eAAe;IAD3B,IAAA,eAAU,GAAE;GACA,eAAe,CA4D3B;AA5DY,0CAAe","sourcesContent":["import {Inject, Injectable} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport Mongoose from \"mongoose\";\nimport {ConnectOptions} from \"mongoose\";\n\n// istanbul ignore next\nfunction asPromise(c: any) {\n return c && c.asPromise ? c.asPromise() : c;\n}\n\n@Injectable()\nexport class MongooseService {\n readonly connections: Map<string, Mongoose.Connection> = new Map();\n private defaultConnection: string = \"default\";\n\n @Inject()\n logger: Logger;\n\n /**\n *\n * @returns {Promise<\"mongoose\".Connection>}\n */\n async connect(id: string, url: string, connectionOptions: ConnectOptions, isDefault = false): Promise<any> {\n if (this.has(id)) {\n return await this.get(id)!;\n }\n\n this.logger.info(`Connect to mongo database: ${id}`);\n this.logger.debug(`Url: ${url}`);\n this.logger.debug(`options: ${JSON.stringify(connectionOptions)}`);\n\n try {\n const connection = await asPromise(Mongoose.createConnection(url, connectionOptions));\n this.connections.set(id, connection);\n\n if (id === \"default\" || isDefault) {\n this.defaultConnection = id;\n }\n\n return connection;\n } catch (er) {\n /* istanbul ignore next */\n this.logger.error(er);\n /* istanbul ignore next */\n process.exit();\n }\n }\n\n /**\n *\n * @returns {\"mongoose\".Connection}\n */\n get(id?: string): Mongoose.Connection | undefined {\n return this.connections.get(id || this.defaultConnection);\n }\n\n /**\n *\n * @param {string} id\n * @returns {boolean}\n */\n has(id?: string): boolean {\n return this.connections.has(id || this.defaultConnection);\n }\n\n async closeConnections() {\n for (const [id, connection] of this.connections.entries()) {\n await connection.close();\n this.connections.delete(id);\n }\n }\n}\n"]}