@tsed/mongoose 8.0.0-alpha.1 → 8.0.0-alpha.10

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 (177) hide show
  1. package/lib/esm/MongooseModule.js.map +1 -1
  2. package/lib/esm/decorators/dynamicRef.js +1 -1
  3. package/lib/esm/decorators/dynamicRef.js.map +1 -1
  4. package/lib/esm/decorators/indexed.js.map +1 -1
  5. package/lib/esm/decorators/model.js +0 -2
  6. package/lib/esm/decorators/model.js.map +1 -1
  7. package/lib/esm/decorators/mongoosePlugin.js.map +1 -1
  8. package/lib/esm/decorators/numberDecimal.js +1 -1
  9. package/lib/esm/decorators/numberDecimal.js.map +1 -1
  10. package/lib/esm/decorators/objectID.js.map +1 -1
  11. package/lib/esm/decorators/postHook.js.map +1 -1
  12. package/lib/esm/decorators/preHook.js.map +1 -1
  13. package/lib/esm/decorators/ref.js.map +1 -1
  14. package/lib/esm/decorators/schema.js.map +1 -1
  15. package/lib/esm/decorators/versionKey.js.map +1 -1
  16. package/lib/esm/decorators/virtualRef.js.map +1 -1
  17. package/lib/esm/services/MongooseConnections.js +1 -1
  18. package/lib/esm/services/MongooseConnections.js.map +1 -1
  19. package/lib/esm/services/MongooseService.js.map +1 -1
  20. package/lib/esm/utils/createModel.js.map +1 -1
  21. package/lib/esm/utils/createSchema.js.map +1 -1
  22. package/lib/esm/utils/resolveRefType.js.map +1 -1
  23. package/lib/esm/utils/schemaOptions.js.map +1 -1
  24. package/lib/types/decorators/indexed.d.ts +25 -0
  25. package/lib/types/decorators/mongoosePlugin.d.ts +25 -0
  26. package/lib/types/decorators/numberDecimal.d.ts +25 -0
  27. package/lib/types/decorators/objectID.d.ts +25 -0
  28. package/lib/types/decorators/schema.d.ts +25 -0
  29. package/lib/types/interfaces/MongooseConnectionOptions.d.ts +25 -0
  30. package/lib/types/interfaces/MongooseDocument.d.ts +25 -0
  31. package/lib/types/interfaces/MongooseModel.d.ts +25 -0
  32. package/lib/types/interfaces/MongooseModelOptions.d.ts +0 -4
  33. package/lib/types/interfaces/MongooseSchemaOptions.d.ts +25 -0
  34. package/lib/types/services/MongooseService.d.ts +25 -0
  35. package/lib/types/utils/createModel.d.ts +25 -0
  36. package/lib/types/utils/createSchema.d.ts +25 -0
  37. package/lib/types/utils/schemaOptions.d.ts +25 -0
  38. package/package.json +24 -24
  39. package/vitest.config.mts +5 -5
  40. package/lib/cjs/MongooseModule.js +0 -36
  41. package/lib/cjs/MongooseModule.js.map +0 -1
  42. package/lib/cjs/constants/constants.js +0 -24
  43. package/lib/cjs/constants/constants.js.map +0 -1
  44. package/lib/cjs/decorators/auto.js +0 -28
  45. package/lib/cjs/decorators/auto.js.map +0 -1
  46. package/lib/cjs/decorators/discriminatorKey.js +0 -6
  47. package/lib/cjs/decorators/discriminatorKey.js.map +0 -1
  48. package/lib/cjs/decorators/dynamicRef.js +0 -65
  49. package/lib/cjs/decorators/dynamicRef.js.map +0 -1
  50. package/lib/cjs/decorators/excludeIndexes.js +0 -28
  51. package/lib/cjs/decorators/excludeIndexes.js.map +0 -1
  52. package/lib/cjs/decorators/expires.js +0 -28
  53. package/lib/cjs/decorators/expires.js.map +0 -1
  54. package/lib/cjs/decorators/immutable.js +0 -30
  55. package/lib/cjs/decorators/immutable.js.map +0 -1
  56. package/lib/cjs/decorators/indexed.js +0 -26
  57. package/lib/cjs/decorators/indexed.js.map +0 -1
  58. package/lib/cjs/decorators/lowercase.js +0 -28
  59. package/lib/cjs/decorators/lowercase.js.map +0 -1
  60. package/lib/cjs/decorators/model.js +0 -71
  61. package/lib/cjs/decorators/model.js.map +0 -1
  62. package/lib/cjs/decorators/mongooseIndex.js +0 -39
  63. package/lib/cjs/decorators/mongooseIndex.js.map +0 -1
  64. package/lib/cjs/decorators/mongooseIndexes.js +0 -39
  65. package/lib/cjs/decorators/mongooseIndexes.js.map +0 -1
  66. package/lib/cjs/decorators/mongoosePlugin.js +0 -22
  67. package/lib/cjs/decorators/mongoosePlugin.js.map +0 -1
  68. package/lib/cjs/decorators/numberDecimal.js +0 -78
  69. package/lib/cjs/decorators/numberDecimal.js.map +0 -1
  70. package/lib/cjs/decorators/objectID.js +0 -32
  71. package/lib/cjs/decorators/objectID.js.map +0 -1
  72. package/lib/cjs/decorators/postHook.js +0 -26
  73. package/lib/cjs/decorators/postHook.js.map +0 -1
  74. package/lib/cjs/decorators/preHook.js +0 -71
  75. package/lib/cjs/decorators/preHook.js.map +0 -1
  76. package/lib/cjs/decorators/ref.js +0 -84
  77. package/lib/cjs/decorators/ref.js.map +0 -1
  78. package/lib/cjs/decorators/schema.js +0 -32
  79. package/lib/cjs/decorators/schema.js.map +0 -1
  80. package/lib/cjs/decorators/schemaIgnore.js +0 -27
  81. package/lib/cjs/decorators/schemaIgnore.js.map +0 -1
  82. package/lib/cjs/decorators/select.js +0 -28
  83. package/lib/cjs/decorators/select.js.map +0 -1
  84. package/lib/cjs/decorators/sparse.js +0 -30
  85. package/lib/cjs/decorators/sparse.js.map +0 -1
  86. package/lib/cjs/decorators/text.js +0 -29
  87. package/lib/cjs/decorators/text.js.map +0 -1
  88. package/lib/cjs/decorators/trim.js +0 -27
  89. package/lib/cjs/decorators/trim.js.map +0 -1
  90. package/lib/cjs/decorators/unique.js +0 -27
  91. package/lib/cjs/decorators/unique.js.map +0 -1
  92. package/lib/cjs/decorators/uppercase.js +0 -28
  93. package/lib/cjs/decorators/uppercase.js.map +0 -1
  94. package/lib/cjs/decorators/versionKey.js +0 -12
  95. package/lib/cjs/decorators/versionKey.js.map +0 -1
  96. package/lib/cjs/decorators/virtualRef.js +0 -38
  97. package/lib/cjs/decorators/virtualRef.js.map +0 -1
  98. package/lib/cjs/index.js +0 -51
  99. package/lib/cjs/index.js.map +0 -1
  100. package/lib/cjs/interfaces/MongooseConnectionOptions.js +0 -3
  101. package/lib/cjs/interfaces/MongooseConnectionOptions.js.map +0 -1
  102. package/lib/cjs/interfaces/MongooseDocument.js +0 -3
  103. package/lib/cjs/interfaces/MongooseDocument.js.map +0 -1
  104. package/lib/cjs/interfaces/MongooseModel.js +0 -3
  105. package/lib/cjs/interfaces/MongooseModel.js.map +0 -1
  106. package/lib/cjs/interfaces/MongooseModelOptions.js +0 -3
  107. package/lib/cjs/interfaces/MongooseModelOptions.js.map +0 -1
  108. package/lib/cjs/interfaces/MongooseSchemaOptions.js +0 -3
  109. package/lib/cjs/interfaces/MongooseSchemaOptions.js.map +0 -1
  110. package/lib/cjs/interfaces/MongooseSchemaTypes.js +0 -10
  111. package/lib/cjs/interfaces/MongooseSchemaTypes.js.map +0 -1
  112. package/lib/cjs/interfaces/MongooseVirtualRefOptions.js +0 -3
  113. package/lib/cjs/interfaces/MongooseVirtualRefOptions.js.map +0 -1
  114. package/lib/cjs/interfaces/interfaces.js +0 -3
  115. package/lib/cjs/interfaces/interfaces.js.map +0 -1
  116. package/lib/cjs/package.json +0 -3
  117. package/lib/cjs/registries/MongooseModels.js +0 -5
  118. package/lib/cjs/registries/MongooseModels.js.map +0 -1
  119. package/lib/cjs/services/MongooseConnections.js +0 -47
  120. package/lib/cjs/services/MongooseConnections.js.map +0 -1
  121. package/lib/cjs/services/MongooseService.js +0 -78
  122. package/lib/cjs/services/MongooseService.js.map +0 -1
  123. package/lib/cjs/utils/createModel.js +0 -44
  124. package/lib/cjs/utils/createModel.js.map +0 -1
  125. package/lib/cjs/utils/createSchema.js +0 -161
  126. package/lib/cjs/utils/createSchema.js.map +0 -1
  127. package/lib/cjs/utils/resolveRefType.js +0 -19
  128. package/lib/cjs/utils/resolveRefType.js.map +0 -1
  129. package/lib/cjs/utils/schemaOptions.js +0 -60
  130. package/lib/cjs/utils/schemaOptions.js.map +0 -1
  131. package/lib/esm/package.json +0 -3
  132. package/lib/types-esm/MongooseModule.d.ts +0 -13
  133. package/lib/types-esm/constants/constants.d.ts +0 -20
  134. package/lib/types-esm/decorators/auto.d.ts +0 -20
  135. package/lib/types-esm/decorators/discriminatorKey.d.ts +0 -1
  136. package/lib/types-esm/decorators/dynamicRef.d.ts +0 -35
  137. package/lib/types-esm/decorators/excludeIndexes.d.ts +0 -20
  138. package/lib/types-esm/decorators/expires.d.ts +0 -20
  139. package/lib/types-esm/decorators/immutable.d.ts +0 -22
  140. package/lib/types-esm/decorators/indexed.d.ts +0 -19
  141. package/lib/types-esm/decorators/lowercase.d.ts +0 -20
  142. package/lib/types-esm/decorators/model.d.ts +0 -39
  143. package/lib/types-esm/decorators/mongooseIndex.d.ts +0 -27
  144. package/lib/types-esm/decorators/mongooseIndexes.d.ts +0 -32
  145. package/lib/types-esm/decorators/mongoosePlugin.d.ts +0 -11
  146. package/lib/types-esm/decorators/numberDecimal.d.ts +0 -32
  147. package/lib/types-esm/decorators/objectID.d.ts +0 -19
  148. package/lib/types-esm/decorators/postHook.d.ts +0 -48
  149. package/lib/types-esm/decorators/preHook.d.ts +0 -49
  150. package/lib/types-esm/decorators/ref.d.ts +0 -38
  151. package/lib/types-esm/decorators/schema.d.ts +0 -54
  152. package/lib/types-esm/decorators/schemaIgnore.d.ts +0 -19
  153. package/lib/types-esm/decorators/select.d.ts +0 -20
  154. package/lib/types-esm/decorators/sparse.d.ts +0 -22
  155. package/lib/types-esm/decorators/text.d.ts +0 -21
  156. package/lib/types-esm/decorators/trim.d.ts +0 -19
  157. package/lib/types-esm/decorators/unique.d.ts +0 -19
  158. package/lib/types-esm/decorators/uppercase.d.ts +0 -20
  159. package/lib/types-esm/decorators/versionKey.d.ts +0 -1
  160. package/lib/types-esm/decorators/virtualRef.d.ts +0 -26
  161. package/lib/types-esm/index.d.ts +0 -47
  162. package/lib/types-esm/interfaces/MongooseConnectionOptions.d.ts +0 -9
  163. package/lib/types-esm/interfaces/MongooseDocument.d.ts +0 -2
  164. package/lib/types-esm/interfaces/MongooseModel.d.ts +0 -8
  165. package/lib/types-esm/interfaces/MongooseModelOptions.d.ts +0 -11
  166. package/lib/types-esm/interfaces/MongooseSchemaOptions.d.ts +0 -36
  167. package/lib/types-esm/interfaces/MongooseSchemaTypes.d.ts +0 -5
  168. package/lib/types-esm/interfaces/MongooseVirtualRefOptions.d.ts +0 -9
  169. package/lib/types-esm/interfaces/interfaces.d.ts +0 -8
  170. package/lib/types-esm/registries/MongooseModels.d.ts +0 -2
  171. package/lib/types-esm/services/MongooseConnections.d.ts +0 -9
  172. package/lib/types-esm/services/MongooseService.d.ts +0 -25
  173. package/lib/types-esm/utils/createModel.d.ts +0 -18
  174. package/lib/types-esm/utils/createSchema.d.ts +0 -28
  175. package/lib/types-esm/utils/resolveRefType.d.ts +0 -5
  176. package/lib/types-esm/utils/schemaOptions.d.ts +0 -14
  177. package/vitest.setup.mts +0 -10
@@ -1 +0,0 @@
1
- {"version":3,"file":"unique.js","sourceRoot":"","sources":["../../../src/decorators/unique.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAE3C;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,MAAM,CAAC,SAAwB,IAAI;IACjD,OAAO,IAAA,0BAAc,EAAC,EAAC,MAAM,EAAC,CAAC,CAAC;AAClC,CAAC;AAFD,wBAEC"}
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Uppercase = void 0;
4
- const schema_js_1 = require("./schema.js");
5
- /**
6
- * If truthy, Mongoose will add a custom setter that uppercases this string using JavaScript's built-in String#toUpperCase().
7
- *
8
- * ### Example
9
- *
10
- * ```typescript
11
- * @Model()
12
- * export class EventModel {
13
- * @Uppercase()
14
- * field: string;
15
- * }
16
- * ```
17
- *
18
- * @param {boolean} uppercase
19
- * @returns {Function}
20
- * @decorator
21
- * @mongoose
22
- * @property
23
- */
24
- function Uppercase(uppercase = true) {
25
- return (0, schema_js_1.MongooseSchema)({ uppercase });
26
- }
27
- exports.Uppercase = Uppercase;
28
- //# sourceMappingURL=uppercase.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"uppercase.js","sourceRoot":"","sources":["../../../src/decorators/uppercase.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAE3C;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,SAAS,CAAC,YAAqB,IAAI;IACjD,OAAO,IAAA,0BAAc,EAAC,EAAC,SAAS,EAAQ,CAAC,CAAC;AAC5C,CAAC;AAFD,8BAEC"}
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VersionKey = void 0;
4
- const core_1 = require("@tsed/core");
5
- const constants_js_1 = require("../constants/constants.js");
6
- function VersionKey() {
7
- return (target, propertyKey) => {
8
- core_1.Store.from(target).merge(constants_js_1.MONGOOSE_SCHEMA_OPTIONS, { versionKey: propertyKey });
9
- };
10
- }
11
- exports.VersionKey = VersionKey;
12
- //# sourceMappingURL=versionKey.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"versionKey.js","sourceRoot":"","sources":["../../../src/decorators/versionKey.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,4DAAkE;AAElE,SAAgB,UAAU;IACxB,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,sCAAuB,EAAE,EAAC,UAAU,EAAE,WAAW,EAAC,CAAC,CAAC;IAC/E,CAAC,CAAC;AACJ,CAAC;AAJD,gCAIC"}
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VirtualRef = void 0;
4
- const core_1 = require("@tsed/core");
5
- const schema_1 = require("@tsed/schema");
6
- const constants_js_1 = require("../constants/constants.js");
7
- const MongooseModels_js_1 = require("../registries/MongooseModels.js");
8
- function getRef(opts) {
9
- const ref = opts.ref;
10
- return (0, core_1.isString)(ref) ? ref : core_1.Store.from(ref).get(constants_js_1.MONGOOSE_MODEL_NAME);
11
- }
12
- function getType(opts) {
13
- const ref = opts.ref;
14
- return !(0, core_1.isString)(ref) ? ref : MongooseModels_js_1.MongooseModels.get(ref) || (() => MongooseModels_js_1.MongooseModels.get(ref) || Object);
15
- }
16
- function getInitialOpts(options, foreignField) {
17
- return (0, core_1.isPlainObject)(options) ? options : { ref: options, foreignField };
18
- }
19
- function mapToSchema(opts) {
20
- const ref = getRef(opts);
21
- const schema = {
22
- ref,
23
- localField: opts.localField || "_id",
24
- foreignField: opts.foreignField,
25
- justOne: opts.justOne || false,
26
- count: opts.count || false,
27
- options: opts.options
28
- };
29
- return schema;
30
- }
31
- function VirtualRef(options, foreignField) {
32
- const opts = getInitialOpts(options, foreignField);
33
- const schema = mapToSchema(opts);
34
- const type = getType(opts);
35
- return (0, core_1.useDecorators)((0, core_1.StoreMerge)(constants_js_1.MONGOOSE_SCHEMA, schema), schema.count ? (0, schema_1.Property)(Number) : type && (schema.justOne ? (0, schema_1.Property)(type) : (0, schema_1.CollectionOf)(type, Array)));
36
- }
37
- exports.VirtualRef = VirtualRef;
38
- //# sourceMappingURL=virtualRef.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"virtualRef.js","sourceRoot":"","sources":["../../../src/decorators/virtualRef.ts"],"names":[],"mappings":";;;AAAA,qCAAqF;AACrF,yCAAoD;AACpD,4DAA+E;AAE/E,uEAA+D;AAE/D,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,kCAAmB,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,kCAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,kC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
package/lib/cjs/index.js DELETED
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- /**
5
- * @file Automatically generated by @tsed/barrels.
6
- */
7
- tslib_1.__exportStar(require("./constants/constants.js"), exports);
8
- tslib_1.__exportStar(require("./decorators/auto.js"), exports);
9
- tslib_1.__exportStar(require("./decorators/discriminatorKey.js"), exports);
10
- tslib_1.__exportStar(require("./decorators/dynamicRef.js"), exports);
11
- tslib_1.__exportStar(require("./decorators/excludeIndexes.js"), exports);
12
- tslib_1.__exportStar(require("./decorators/expires.js"), exports);
13
- tslib_1.__exportStar(require("./decorators/immutable.js"), exports);
14
- tslib_1.__exportStar(require("./decorators/indexed.js"), exports);
15
- tslib_1.__exportStar(require("./decorators/lowercase.js"), exports);
16
- tslib_1.__exportStar(require("./decorators/model.js"), exports);
17
- tslib_1.__exportStar(require("./decorators/mongooseIndex.js"), exports);
18
- tslib_1.__exportStar(require("./decorators/mongooseIndexes.js"), exports);
19
- tslib_1.__exportStar(require("./decorators/mongoosePlugin.js"), exports);
20
- tslib_1.__exportStar(require("./decorators/numberDecimal.js"), exports);
21
- tslib_1.__exportStar(require("./decorators/objectID.js"), exports);
22
- tslib_1.__exportStar(require("./decorators/postHook.js"), exports);
23
- tslib_1.__exportStar(require("./decorators/preHook.js"), exports);
24
- tslib_1.__exportStar(require("./decorators/ref.js"), exports);
25
- tslib_1.__exportStar(require("./decorators/schema.js"), exports);
26
- tslib_1.__exportStar(require("./decorators/schemaIgnore.js"), exports);
27
- tslib_1.__exportStar(require("./decorators/select.js"), exports);
28
- tslib_1.__exportStar(require("./decorators/sparse.js"), exports);
29
- tslib_1.__exportStar(require("./decorators/text.js"), exports);
30
- tslib_1.__exportStar(require("./decorators/trim.js"), exports);
31
- tslib_1.__exportStar(require("./decorators/unique.js"), exports);
32
- tslib_1.__exportStar(require("./decorators/uppercase.js"), exports);
33
- tslib_1.__exportStar(require("./decorators/versionKey.js"), exports);
34
- tslib_1.__exportStar(require("./decorators/virtualRef.js"), exports);
35
- tslib_1.__exportStar(require("./interfaces/interfaces.js"), exports);
36
- tslib_1.__exportStar(require("./interfaces/MongooseConnectionOptions.js"), exports);
37
- tslib_1.__exportStar(require("./interfaces/MongooseDocument.js"), exports);
38
- tslib_1.__exportStar(require("./interfaces/MongooseModel.js"), exports);
39
- tslib_1.__exportStar(require("./interfaces/MongooseModelOptions.js"), exports);
40
- tslib_1.__exportStar(require("./interfaces/MongooseSchemaOptions.js"), exports);
41
- tslib_1.__exportStar(require("./interfaces/MongooseSchemaTypes.js"), exports);
42
- tslib_1.__exportStar(require("./interfaces/MongooseVirtualRefOptions.js"), exports);
43
- tslib_1.__exportStar(require("./MongooseModule.js"), exports);
44
- tslib_1.__exportStar(require("./registries/MongooseModels.js"), exports);
45
- tslib_1.__exportStar(require("./services/MongooseConnections.js"), exports);
46
- tslib_1.__exportStar(require("./services/MongooseService.js"), exports);
47
- tslib_1.__exportStar(require("./utils/createModel.js"), exports);
48
- tslib_1.__exportStar(require("./utils/createSchema.js"), exports);
49
- tslib_1.__exportStar(require("./utils/resolveRefType.js"), exports);
50
- tslib_1.__exportStar(require("./utils/schemaOptions.js"), exports);
51
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,mEAAyC;AACzC,+DAAqC;AACrC,2EAAiD;AACjD,qEAA2C;AAC3C,yEAA+C;AAC/C,kEAAwC;AACxC,oEAA0C;AAC1C,kEAAwC;AACxC,oEAA0C;AAC1C,gEAAsC;AACtC,wEAA8C;AAC9C,0EAAgD;AAChD,yEAA+C;AAC/C,wEAA8C;AAC9C,mEAAyC;AACzC,mEAAyC;AACzC,kEAAwC;AACxC,8DAAoC;AACpC,iEAAuC;AACvC,uEAA6C;AAC7C,iEAAuC;AACvC,iEAAuC;AACvC,+DAAqC;AACrC,+DAAqC;AACrC,iEAAuC;AACvC,oEAA0C;AAC1C,qEAA2C;AAC3C,qEAA2C;AAC3C,qEAA2C;AAC3C,oFAA0D;AAC1D,2EAAiD;AACjD,wEAA8C;AAC9C,+EAAqD;AACrD,gFAAsD;AACtD,8EAAoD;AACpD,oFAA0D;AAC1D,8DAAoC;AACpC,yEAA+C;AAC/C,4EAAkD;AAClD,wEAA8C;AAC9C,iEAAuC;AACvC,kEAAwC;AACxC,oEAA0C;AAC1C,mEAAyC"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=MongooseConnectionOptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongooseConnectionOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseConnectionOptions.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=MongooseDocument.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongooseDocument.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseDocument.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=MongooseModel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongooseModel.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseModel.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=MongooseModelOptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongooseModelOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseModelOptions.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=MongooseSchemaOptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongooseSchemaOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseSchemaOptions.ts"],"names":[],"mappings":""}
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongooseSchemaTypes = void 0;
4
- var MongooseSchemaTypes;
5
- (function (MongooseSchemaTypes) {
6
- MongooseSchemaTypes["OBJECT_ID"] = "ObjectId";
7
- MongooseSchemaTypes["STRING"] = "String";
8
- MongooseSchemaTypes["NUMBER"] = "Number";
9
- })(MongooseSchemaTypes = exports.MongooseSchemaTypes || (exports.MongooseSchemaTypes = {}));
10
- //# sourceMappingURL=MongooseSchemaTypes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongooseSchemaTypes.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseSchemaTypes.ts"],"names":[],"mappings":";;;AAAA,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC7B,6CAAsB,CAAA;IACtB,wCAAiB,CAAA;IACjB,wCAAiB,CAAA;AACnB,CAAC,EAJW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAI9B"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=MongooseVirtualRefOptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongooseVirtualRefOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseVirtualRefOptions.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=interfaces.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongooseModels = void 0;
4
- exports.MongooseModels = new Map();
5
- //# sourceMappingURL=MongooseModels.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongooseModels.js","sourceRoot":"","sources":["../../../src/registries/MongooseModels.ts"],"names":[],"mappings":";;;AAEa,QAAA,cAAc,GAAsB,IAAI,GAAG,EAAE,CAAC"}
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MONGOOSE_CONNECTIONS = void 0;
4
- const di_1 = require("@tsed/di");
5
- const core_1 = require("@tsed/core");
6
- const MongooseService_js_1 = require("../services/MongooseService.js");
7
- /**
8
- * @ignore
9
- */
10
- // tslint:disable-next-line:variable-name
11
- exports.MONGOOSE_CONNECTIONS = Symbol.for("MONGOOSE_CONNECTIONS");
12
- function mapOptions(options) {
13
- if (!options) {
14
- return [];
15
- }
16
- if (!(0, core_1.isArray)(options)) {
17
- const { url, connectionOptions } = options || {};
18
- return [
19
- {
20
- id: "default",
21
- url,
22
- connectionOptions
23
- }
24
- ];
25
- }
26
- return options.map((settings) => {
27
- return {
28
- ...settings,
29
- connectionOptions: settings.connectionOptions
30
- };
31
- });
32
- }
33
- (0, di_1.registerProvider)({
34
- provide: exports.MONGOOSE_CONNECTIONS,
35
- injectable: false,
36
- deps: [di_1.Configuration, MongooseService_js_1.MongooseService],
37
- async useAsyncFactory(configuration, mongooseService) {
38
- const settings = mapOptions(configuration.get("mongoose"));
39
- let isDefault = true;
40
- for (const current of settings) {
41
- await mongooseService.connect(current.id, current.url, current.connectionOptions || {}, isDefault);
42
- isDefault = false;
43
- }
44
- return mongooseService;
45
- }
46
- });
47
- //# sourceMappingURL=MongooseConnections.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongooseConnections.js","sourceRoot":"","sources":["../../../src/services/MongooseConnections.ts"],"names":[],"mappings":";;;AAAA,iCAAyD;AACzD,qCAAmC;AAEnC,uEAA+D;AAE/D;;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,oCAAe,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,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,iBAAiB,IAAI,EAAE,EAAE,SAAS,CAAC,CAAC;YAEnG,SAAS,GAAG,KAAK,CAAC;SACnB;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;CACF,CAAC,CAAC"}
@@ -1,78 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongooseService = void 0;
4
- const tslib_1 = require("tslib");
5
- const di_1 = require("@tsed/di");
6
- const logger_1 = require("@tsed/logger");
7
- const mongoose_1 = tslib_1.__importDefault(require("mongoose"));
8
- // istanbul ignore next
9
- function asPromise(c) {
10
- return c && c.asPromise ? c.asPromise() : c;
11
- }
12
- let MongooseService = class MongooseService {
13
- constructor() {
14
- this.connections = new Map();
15
- this.defaultConnection = "default";
16
- }
17
- /**
18
- *
19
- * @returns {Promise<"mongoose".Connection>}
20
- */
21
- async connect(id, url, connectionOptions, isDefault = false) {
22
- if (this.has(id)) {
23
- return this.get(id);
24
- }
25
- this.logger.info(`Connect to mongo database: ${id}`);
26
- this.logger.debug(`Url: ${url}`);
27
- this.logger.debug(`options: ${JSON.stringify(connectionOptions)}`);
28
- try {
29
- const connection = await asPromise(mongoose_1.default.createConnection(url, connectionOptions));
30
- this.connections.set(id, connection);
31
- if (id === "default" || isDefault) {
32
- this.defaultConnection = id;
33
- }
34
- return connection;
35
- }
36
- catch (er) {
37
- /* istanbul ignore next */
38
- this.logger.error({
39
- event: "MONGO_CONNECTION_ERROR",
40
- error_name: er.name,
41
- message: er.message,
42
- stack: er.stack
43
- });
44
- /* istanbul ignore next */
45
- process.exit();
46
- }
47
- }
48
- /**
49
- *
50
- * @returns {"mongoose".Connection}
51
- */
52
- get(id) {
53
- return this.connections.get(id || this.defaultConnection);
54
- }
55
- /**
56
- *
57
- * @param {string} id
58
- * @returns {boolean}
59
- */
60
- has(id) {
61
- return this.connections.has(id || this.defaultConnection);
62
- }
63
- async closeConnections() {
64
- for (const [id, connection] of this.connections.entries()) {
65
- await connection.close();
66
- this.connections.delete(id);
67
- }
68
- }
69
- };
70
- tslib_1.__decorate([
71
- (0, di_1.Inject)(),
72
- tslib_1.__metadata("design:type", logger_1.Logger)
73
- ], MongooseService.prototype, "logger", void 0);
74
- MongooseService = tslib_1.__decorate([
75
- (0, di_1.Injectable)()
76
- ], MongooseService);
77
- exports.MongooseService = MongooseService;
78
- //# sourceMappingURL=MongooseService.js.map
@@ -1 +0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,OAAO,EAAE,EAAE;YACX,0BAA0B;YAC1B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBAChB,KAAK,EAAE,wBAAwB;gBAC/B,UAAU,EAAE,EAAE,CAAC,IAAI;gBACnB,OAAO,EAAE,EAAE,CAAC,OAAO;gBACnB,KAAK,EAAE,EAAE,CAAC,KAAK;aAChB,CAAC,CAAC;YACH,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;AA7DC;IAAC,IAAA,WAAM,GAAE;sCACD,eAAM;+CAAC;AALJ,eAAe;IAD3B,IAAA,eAAU,GAAE;GACA,eAAe,CAiE3B;AAjEY,0CAAe"}
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createModel = exports.getModelToken = void 0;
4
- const tslib_1 = require("tslib");
5
- const core_1 = require("@tsed/core");
6
- const schema_1 = require("@tsed/schema");
7
- const mongoose_1 = tslib_1.__importDefault(require("mongoose"));
8
- const constants_js_1 = require("../constants/constants.js");
9
- const MongooseModels_js_1 = require("../registries/MongooseModels.js");
10
- const createSchema_js_1 = require("./createSchema.js");
11
- function getModelToken(target, options) {
12
- const { collectionName, token } = (0, createSchema_js_1.getSchemaToken)(target, options);
13
- core_1.Store.from(target).set(constants_js_1.MONGOOSE_MODEL_NAME, collectionName);
14
- MongooseModels_js_1.MongooseModels.set(collectionName, target);
15
- return { token, collectionName };
16
- }
17
- exports.getModelToken = getModelToken;
18
- /**
19
- * Create an instance of mongoose.model from a class.
20
- *
21
- * @param {Type<any>} target Class attached to the schema and model.
22
- * @param {"mongoose".Schema} schema Schema that will be attached to the model.
23
- * @param name model name
24
- * @param collection (optional, induced from model name)
25
- * @param overwriteModels
26
- * @param connection
27
- * @returns {Model<T extends Document>}
28
- */
29
- function createModel(target, schema, name = (0, core_1.nameOf)(target), collection, overwriteModels, connection) {
30
- const entity = schema_1.JsonEntityStore.from(target);
31
- if (entity.isDiscriminatorChild) {
32
- const discriminatorName = entity.discriminatorAncestor.schema.discriminator().getDefaultValue(target);
33
- const ancestorModel = entity.discriminatorAncestor.get(constants_js_1.MONGOOSE_MODEL);
34
- // check if discriminator is already registered on model before creating it
35
- return ancestorModel.discriminators?.[discriminatorName] || ancestorModel.discriminator(discriminatorName, schema);
36
- }
37
- const opts = overwriteModels ? { overwriteModels } : undefined;
38
- const c = connection || mongoose_1.default;
39
- const model = c.model(name, schema, collection, opts);
40
- core_1.Store.from(target).set(constants_js_1.MONGOOSE_MODEL, model);
41
- return model;
42
- }
43
- exports.createModel = createModel;
44
- //# sourceMappingURL=createModel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createModel.js","sourceRoot":"","sources":["../../../src/utils/createModel.ts"],"names":[],"mappings":";;;;AAAA,qCAA+C;AAC/C,yCAA6C;AAC7C,gEAA8C;AAC9C,4DAA8E;AAC9E,uEAA+D;AAC/D,uDAAiD;AAEjD,SAAgB,aAAa,CAAC,MAAiB,EAAE,OAAY;IAC3D,MAAM,EAAC,cAAc,EAAE,KAAK,EAAC,GAAG,IAAA,gCAAc,EAAC,MAAM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,kCAyBC"}
@@ -1,161 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSchemaTypeOptions = exports.buildMongooseSchema = exports.getSchemaToken = exports.getSchema = exports.createSchema = void 0;
4
- const tslib_1 = require("tslib");
5
- const core_1 = require("@tsed/core");
6
- const json_mapper_1 = require("@tsed/json-mapper");
7
- const schema_1 = require("@tsed/schema");
8
- const change_case_1 = require("change-case");
9
- const mongoose_1 = tslib_1.__importDefault(require("mongoose"));
10
- const constants_js_1 = require("../constants/constants.js");
11
- const resolveRefType_js_1 = require("./resolveRefType.js");
12
- const schemaOptions_js_1 = require("./schemaOptions.js");
13
- /**
14
- * @ignore
15
- */
16
- function setUpSchema({ schema, virtuals }, options) {
17
- const mongooseSchema = new mongoose_1.default.Schema(schema, options);
18
- for (const [key, options] of virtuals.entries()) {
19
- mongooseSchema.virtual(key, options);
20
- }
21
- return mongooseSchema;
22
- }
23
- /**
24
- * @ignore
25
- */
26
- function isVirtualRef(target) {
27
- return !!(target.ref && target.localField && target.foreignField);
28
- }
29
- function hasVersionField(schema, versionKey) {
30
- // Check if versioning was disabled explicitly
31
- if (!versionKey)
32
- return false;
33
- // Check for alternative version field in schema
34
- return versionKey in schema.paths;
35
- }
36
- function createSchema(target, options = {}) {
37
- const entity = schema_1.JsonEntityStore.from(target);
38
- const schemaOptionsFromStore = entity.store.get(constants_js_1.MONGOOSE_SCHEMA_OPTIONS) || {};
39
- options.schemaOptions = { ...options.schemaOptions, ...schemaOptionsFromStore };
40
- if (entity.schema.isDiscriminator) {
41
- options.schemaOptions.discriminatorKey = entity.schema.discriminator().propertyName;
42
- }
43
- const schema = setUpSchema(buildMongooseSchema(target), options.schemaOptions);
44
- (0, schemaOptions_js_1.schemaOptions)(target, options);
45
- const outputVersionKey = hasVersionField(schema, options.schemaOptions?.versionKey);
46
- schema.methods.toClass = function toClass() {
47
- return (0, json_mapper_1.deserialize)(this.toObject({
48
- virtuals: true,
49
- versionKey: outputVersionKey,
50
- flattenMaps: true
51
- }), {
52
- type: target,
53
- useAlias: false,
54
- additionalProperties: true,
55
- disabledUnsecureConstructor: false,
56
- groups: false
57
- });
58
- };
59
- schema.methods.toJSON = function toJSON(options) {
60
- return (0, json_mapper_1.serialize)(this.toClass(), options);
61
- };
62
- schema.loadClass(target);
63
- core_1.Store.from(target).set(constants_js_1.MONGOOSE_SCHEMA, schema);
64
- return schema;
65
- }
66
- exports.createSchema = createSchema;
67
- /**
68
- * Get a schema already created. If the schema doesn't exists in registry, it'll be created.
69
- * @param target
70
- * @param options
71
- */
72
- function getSchema(target, options = {}) {
73
- const store = core_1.Store.from(target);
74
- if (!store.has(constants_js_1.MONGOOSE_SCHEMA)) {
75
- createSchema(target, options);
76
- }
77
- return store.get(constants_js_1.MONGOOSE_SCHEMA);
78
- }
79
- exports.getSchema = getSchema;
80
- function getSchemaToken(target, options) {
81
- const collectionName = options.name || (0, core_1.nameOf)(target);
82
- const token = Symbol.for((0, change_case_1.pascalCase)(`${collectionName}Schema`));
83
- return { token, collectionName };
84
- }
85
- exports.getSchemaToken = getSchemaToken;
86
- /**
87
- * @ignore
88
- */
89
- function buildMongooseSchema(target) {
90
- const properties = (0, schema_1.getProperties)(target, { withIgnoredProps: true, mongoose: true, groups: false });
91
- const schema = { schema: {}, virtuals: new Map() };
92
- properties.forEach((propertyMetadata, key) => {
93
- // Keeping the Mongoose Schema separate, so it can overwrite everything once schema has been built.
94
- const schemaTypeOptions = propertyMetadata.store.get(constants_js_1.MONGOOSE_SCHEMA) || {};
95
- if (schemaTypeOptions.schemaIgnore || propertyMetadata.isDiscriminatorKey() || propertyMetadata.isGetterOnly()) {
96
- return;
97
- }
98
- if (schemaTypeOptions.ref) {
99
- schemaTypeOptions.ref = (0, resolveRefType_js_1.resolveRefType)(schemaTypeOptions.ref);
100
- }
101
- if (isVirtualRef(schemaTypeOptions)) {
102
- schema.virtuals.set(key, schemaTypeOptions);
103
- return;
104
- }
105
- schema.schema[key] = createSchemaTypeOptions(propertyMetadata);
106
- });
107
- return schema;
108
- }
109
- exports.buildMongooseSchema = buildMongooseSchema;
110
- /**
111
- * @ignore
112
- */
113
- function createSchemaTypeOptions(propEntity) {
114
- const key = propEntity.propertyKey;
115
- const rawMongooseSchema = propEntity.store.get(constants_js_1.MONGOOSE_SCHEMA) || {};
116
- let schemaTypeOptions = {
117
- required: propEntity.required
118
- ? function () {
119
- return propEntity.isRequired(this[key]);
120
- }
121
- : false
122
- };
123
- if (!propEntity.isClass) {
124
- const jsonSchema = propEntity.itemSchema.toJSON();
125
- const { minimum: min, maximum: max, minLength: minlength, maxLength: maxlength } = jsonSchema;
126
- let match = jsonSchema.pattern;
127
- if (match) {
128
- match = new RegExp(match);
129
- }
130
- schemaTypeOptions = {
131
- ...schemaTypeOptions,
132
- type: propEntity.type,
133
- match: match,
134
- min,
135
- max,
136
- minlength,
137
- maxlength,
138
- enum: /*jsonSchema["enum"] instanceof JsonSchema ? jsonSchema["enum"].toJSON().enum :*/ jsonSchema["enum"],
139
- default: jsonSchema["default"]
140
- };
141
- }
142
- else if (!rawMongooseSchema.ref) {
143
- // References are handled by the final merge
144
- schemaTypeOptions = { ...schemaTypeOptions, type: getSchema(propEntity.type) };
145
- }
146
- schemaTypeOptions = (0, core_1.cleanObject)({ ...schemaTypeOptions, ...rawMongooseSchema });
147
- if (propEntity.isCollection) {
148
- if (propEntity.isArray) {
149
- return [schemaTypeOptions];
150
- }
151
- // Can be a Map or a Set;
152
- // Mongoose implements only Map;
153
- if (propEntity.collectionType !== Map) {
154
- throw new Error(`Invalid collection type. ${(0, core_1.nameOf)(propEntity.collectionType)} is not supported.`);
155
- }
156
- return { type: Map, of: schemaTypeOptions };
157
- }
158
- return schemaTypeOptions;
159
- }
160
- exports.createSchemaTypeOptions = createSchemaTypeOptions;
161
- //# sourceMappingURL=createSchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createSchema.js","sourceRoot":"","sources":["../../../src/utils/createSchema.ts"],"names":[],"mapp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,SAAS,CAAC;SAC/B,CAAC;KACH;SAAM,IAAI,CAAC,iBAAiB,CAAC,GAAG,EAAE;QACjC,4CAA4C;QAC5C,iBAAiB,GAAG,EAAC,GAAG,iBAAiB,EAAE,IAAI,EAAE,SAAS,CAAC,UAAU,CAAC,IAAI,CAAQ,EAAC,CAAC;KACrF;IAED,iBAAiB,GAAG,IAAA,kBAAW,EAAC,EAAC,GAAG,iBAAiB,EAAE,GAAG,iBAAiB,EAAC,CAAC,CAAC;IAE9E,IAAI,UAAU,CAAC,YAAY,EAAE;QAC3B,IAAI,UAAU,CAAC,OAAO,EAAE;YACtB,OAAO,CAAC,iBAAiB,CAAC,CAAC;SAC5B;QACD,yBAAyB;QACzB,gCAAgC;QAChC,IAAI,UAAU,CAAC,cAAc,KAAK,GAAG,EAAE;YACrC,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAA,aAAM,EAAC,UAAU,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC;SACpG;QAED,OAAO,EAAC,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,iBAAiB,EAAoC,CAAC;KAC9E;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AArDD,0DAqDC"}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveRefType = void 0;
4
- const core_1 = require("@tsed/core");
5
- const constants_js_1 = require("../constants/constants.js");
6
- /**
7
- * @ignore
8
- */
9
- function resolveRefType(type) {
10
- if ((0, core_1.isString)(type)) {
11
- return type;
12
- }
13
- if (!(0, core_1.isClass)(type)) {
14
- type = type();
15
- }
16
- return core_1.Store.from(type).get(constants_js_1.MONGOOSE_MODEL_NAME) || (0, core_1.nameOf)(type);
17
- }
18
- exports.resolveRefType = resolveRefType;
19
- //# sourceMappingURL=resolveRefType.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolveRefType.js","sourceRoot":"","sources":["../../../src/utils/resolveRefType.ts"],"names":[],"mappings":";;;AAAA,qCAAkE;AAClE,4DAA8D;AAE9D;;GAEG;AACH,SAAgB,cAAc,CAAC,IAA4C;IACzE,IAAI,IAAA,eAAQ,EAAC,IAAI,CAAC,EAAE;QAClB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,CAAC,IAAA,cAAO,EAAC,IAAI,CAAC,EAAE;QAClB,IAAI,GAAI,IAAY,EAAE,CAAC;KACxB;IAED,OAAO,YAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,kCAAmB,CAAC,IAAI,IAAA,aAAM,EAAC,IAAI,CAAC,CAAC;AACnE,CAAC;AAVD,wCAUC"}