@tsed/mongoose 7.0.0-alpha.2 → 7.0.0-beta.11

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 (240) hide show
  1. package/jest.config.js +14 -0
  2. package/lib/cjs/MongooseModule.js +36 -0
  3. package/lib/cjs/MongooseModule.js.map +1 -0
  4. package/lib/cjs/constants/constants.js +24 -0
  5. package/lib/cjs/constants/constants.js.map +1 -0
  6. package/lib/cjs/decorators/auto.js +28 -0
  7. package/lib/cjs/decorators/auto.js.map +1 -0
  8. package/lib/cjs/decorators/discriminatorKey.js +14 -0
  9. package/lib/cjs/decorators/discriminatorKey.js.map +1 -0
  10. package/lib/cjs/decorators/dynamicRef.js +65 -0
  11. package/lib/cjs/decorators/dynamicRef.js.map +1 -0
  12. package/lib/cjs/decorators/excludeIndexes.js +28 -0
  13. package/lib/cjs/decorators/excludeIndexes.js.map +1 -0
  14. package/lib/cjs/decorators/expires.js +28 -0
  15. package/lib/cjs/decorators/expires.js.map +1 -0
  16. package/lib/cjs/decorators/immutable.js +30 -0
  17. package/lib/cjs/decorators/immutable.js.map +1 -0
  18. package/lib/cjs/decorators/indexed.js +26 -0
  19. package/lib/cjs/decorators/indexed.js.map +1 -0
  20. package/lib/cjs/decorators/lowercase.js +28 -0
  21. package/lib/cjs/decorators/lowercase.js.map +1 -0
  22. package/lib/cjs/decorators/model.js +68 -0
  23. package/lib/cjs/decorators/model.js.map +1 -0
  24. package/lib/cjs/decorators/mongooseIndex.js +39 -0
  25. package/lib/cjs/decorators/mongooseIndex.js.map +1 -0
  26. package/lib/cjs/decorators/mongooseIndexes.js +39 -0
  27. package/lib/cjs/decorators/mongooseIndexes.js.map +1 -0
  28. package/lib/cjs/decorators/mongoosePlugin.js +22 -0
  29. package/lib/cjs/decorators/mongoosePlugin.js.map +1 -0
  30. package/lib/cjs/decorators/numberDecimal.js +78 -0
  31. package/lib/cjs/decorators/numberDecimal.js.map +1 -0
  32. package/lib/cjs/decorators/objectID.js +26 -0
  33. package/lib/cjs/decorators/objectID.js.map +1 -0
  34. package/lib/cjs/decorators/postHook.js +26 -0
  35. package/lib/cjs/decorators/postHook.js.map +1 -0
  36. package/lib/cjs/decorators/preHook.js +71 -0
  37. package/lib/cjs/decorators/preHook.js.map +1 -0
  38. package/lib/cjs/decorators/ref.js +75 -0
  39. package/lib/cjs/decorators/ref.js.map +1 -0
  40. package/lib/cjs/decorators/schema.js +32 -0
  41. package/lib/cjs/decorators/schema.js.map +1 -0
  42. package/lib/cjs/decorators/schemaIgnore.js +27 -0
  43. package/lib/cjs/decorators/schemaIgnore.js.map +1 -0
  44. package/lib/cjs/decorators/select.js +28 -0
  45. package/lib/cjs/decorators/select.js.map +1 -0
  46. package/lib/cjs/decorators/sparse.js +30 -0
  47. package/lib/cjs/decorators/sparse.js.map +1 -0
  48. package/lib/cjs/decorators/text.js +29 -0
  49. package/lib/cjs/decorators/text.js.map +1 -0
  50. package/lib/cjs/decorators/trim.js +27 -0
  51. package/lib/cjs/decorators/trim.js.map +1 -0
  52. package/lib/cjs/decorators/unique.js +27 -0
  53. package/lib/cjs/decorators/unique.js.map +1 -0
  54. package/lib/cjs/decorators/uppercase.js +28 -0
  55. package/lib/cjs/decorators/uppercase.js.map +1 -0
  56. package/lib/cjs/decorators/versionKey.js +12 -0
  57. package/lib/cjs/decorators/versionKey.js.map +1 -0
  58. package/lib/cjs/decorators/virtualRef.js +38 -0
  59. package/lib/cjs/decorators/virtualRef.js.map +1 -0
  60. package/lib/cjs/index.js +51 -0
  61. package/lib/cjs/index.js.map +1 -0
  62. package/lib/cjs/interfaces/MongooseConnectionOptions.js +3 -0
  63. package/lib/cjs/interfaces/MongooseConnectionOptions.js.map +1 -0
  64. package/lib/cjs/interfaces/MongooseDocument.js +3 -0
  65. package/lib/cjs/interfaces/MongooseDocument.js.map +1 -0
  66. package/lib/cjs/interfaces/MongooseModel.js +3 -0
  67. package/lib/cjs/interfaces/MongooseModel.js.map +1 -0
  68. package/lib/cjs/interfaces/MongooseModelOptions.js +3 -0
  69. package/lib/cjs/interfaces/MongooseModelOptions.js.map +1 -0
  70. package/lib/cjs/interfaces/MongooseSchemaOptions.js +3 -0
  71. package/lib/cjs/interfaces/MongooseSchemaOptions.js.map +1 -0
  72. package/lib/cjs/interfaces/MongooseSchemaTypes.js +10 -0
  73. package/lib/cjs/interfaces/MongooseSchemaTypes.js.map +1 -0
  74. package/lib/cjs/interfaces/MongooseVirtualRefOptions.js +3 -0
  75. package/lib/cjs/interfaces/MongooseVirtualRefOptions.js.map +1 -0
  76. package/lib/cjs/interfaces/interfaces.js +3 -0
  77. package/lib/cjs/interfaces/interfaces.js.map +1 -0
  78. package/lib/cjs/package.json +3 -0
  79. package/lib/cjs/registries/MongooseModels.js +5 -0
  80. package/lib/cjs/registries/MongooseModels.js.map +1 -0
  81. package/lib/cjs/services/MongooseConnections.js +47 -0
  82. package/lib/cjs/services/MongooseConnections.js.map +1 -0
  83. package/lib/cjs/services/MongooseService.js +73 -0
  84. package/lib/cjs/services/MongooseService.js.map +1 -0
  85. package/lib/cjs/utils/createModel.js +54 -0
  86. package/lib/cjs/utils/createModel.js.map +1 -0
  87. package/lib/cjs/utils/createSchema.js +160 -0
  88. package/lib/cjs/utils/createSchema.js.map +1 -0
  89. package/lib/cjs/utils/resolveRefType.js +19 -0
  90. package/lib/cjs/utils/resolveRefType.js.map +1 -0
  91. package/lib/cjs/utils/schemaOptions.js +60 -0
  92. package/lib/cjs/utils/schemaOptions.js.map +1 -0
  93. package/lib/esm/MongooseModule.js +33 -0
  94. package/lib/esm/MongooseModule.js.map +1 -0
  95. package/lib/esm/constants/constants.js +21 -0
  96. package/lib/esm/constants/constants.js.map +1 -0
  97. package/lib/esm/decorators/auto.js +24 -0
  98. package/lib/esm/decorators/auto.js.map +1 -0
  99. package/lib/esm/decorators/discriminatorKey.js +10 -0
  100. package/lib/esm/decorators/discriminatorKey.js.map +1 -0
  101. package/lib/esm/decorators/dynamicRef.js +61 -0
  102. package/lib/esm/decorators/dynamicRef.js.map +1 -0
  103. package/lib/esm/decorators/excludeIndexes.js +24 -0
  104. package/lib/esm/decorators/excludeIndexes.js.map +1 -0
  105. package/lib/esm/decorators/expires.js +24 -0
  106. package/lib/esm/decorators/expires.js.map +1 -0
  107. package/lib/esm/decorators/immutable.js +26 -0
  108. package/lib/esm/decorators/immutable.js.map +1 -0
  109. package/lib/esm/decorators/indexed.js +22 -0
  110. package/lib/esm/decorators/indexed.js.map +1 -0
  111. package/lib/esm/decorators/lowercase.js +24 -0
  112. package/lib/esm/decorators/lowercase.js.map +1 -0
  113. package/lib/esm/decorators/model.js +64 -0
  114. package/lib/esm/decorators/model.js.map +1 -0
  115. package/lib/esm/decorators/mongooseIndex.js +35 -0
  116. package/lib/esm/decorators/mongooseIndex.js.map +1 -0
  117. package/lib/esm/decorators/mongooseIndexes.js +35 -0
  118. package/lib/esm/decorators/mongooseIndexes.js.map +1 -0
  119. package/lib/esm/decorators/mongoosePlugin.js +18 -0
  120. package/lib/esm/decorators/mongoosePlugin.js.map +1 -0
  121. package/lib/esm/decorators/numberDecimal.js +74 -0
  122. package/lib/esm/decorators/numberDecimal.js.map +1 -0
  123. package/lib/esm/decorators/objectID.js +22 -0
  124. package/lib/esm/decorators/objectID.js.map +1 -0
  125. package/lib/esm/decorators/postHook.js +22 -0
  126. package/lib/esm/decorators/postHook.js.map +1 -0
  127. package/lib/esm/decorators/preHook.js +67 -0
  128. package/lib/esm/decorators/preHook.js.map +1 -0
  129. package/lib/esm/decorators/ref.js +71 -0
  130. package/lib/esm/decorators/ref.js.map +1 -0
  131. package/lib/esm/decorators/schema.js +27 -0
  132. package/lib/esm/decorators/schema.js.map +1 -0
  133. package/lib/esm/decorators/schemaIgnore.js +23 -0
  134. package/lib/esm/decorators/schemaIgnore.js.map +1 -0
  135. package/lib/esm/decorators/select.js +24 -0
  136. package/lib/esm/decorators/select.js.map +1 -0
  137. package/lib/esm/decorators/sparse.js +26 -0
  138. package/lib/esm/decorators/sparse.js.map +1 -0
  139. package/lib/esm/decorators/text.js +25 -0
  140. package/lib/esm/decorators/text.js.map +1 -0
  141. package/lib/esm/decorators/trim.js +23 -0
  142. package/lib/esm/decorators/trim.js.map +1 -0
  143. package/lib/esm/decorators/unique.js +23 -0
  144. package/lib/esm/decorators/unique.js.map +1 -0
  145. package/lib/esm/decorators/uppercase.js +24 -0
  146. package/lib/esm/decorators/uppercase.js.map +1 -0
  147. package/lib/esm/decorators/versionKey.js +8 -0
  148. package/lib/esm/decorators/versionKey.js.map +1 -0
  149. package/lib/esm/decorators/virtualRef.js +34 -0
  150. package/lib/esm/decorators/virtualRef.js.map +1 -0
  151. package/lib/esm/index.js +48 -0
  152. package/lib/esm/index.js.map +1 -0
  153. package/lib/esm/interfaces/MongooseConnectionOptions.js +2 -0
  154. package/lib/esm/interfaces/MongooseConnectionOptions.js.map +1 -0
  155. package/lib/esm/interfaces/MongooseDocument.js +2 -0
  156. package/lib/esm/interfaces/MongooseDocument.js.map +1 -0
  157. package/lib/esm/interfaces/MongooseModel.js +2 -0
  158. package/lib/esm/interfaces/MongooseModel.js.map +1 -0
  159. package/lib/esm/interfaces/MongooseModelOptions.js +2 -0
  160. package/lib/esm/interfaces/MongooseModelOptions.js.map +1 -0
  161. package/lib/esm/interfaces/MongooseSchemaOptions.js +2 -0
  162. package/lib/esm/interfaces/MongooseSchemaOptions.js.map +1 -0
  163. package/lib/esm/interfaces/MongooseSchemaTypes.js +7 -0
  164. package/lib/esm/interfaces/MongooseSchemaTypes.js.map +1 -0
  165. package/lib/esm/interfaces/MongooseVirtualRefOptions.js +2 -0
  166. package/lib/esm/interfaces/MongooseVirtualRefOptions.js.map +1 -0
  167. package/lib/esm/interfaces/interfaces.js +2 -0
  168. package/lib/esm/interfaces/interfaces.js.map +1 -0
  169. package/lib/esm/package.json +3 -0
  170. package/lib/esm/registries/MongooseModels.js +2 -0
  171. package/lib/esm/registries/MongooseModels.js.map +1 -0
  172. package/lib/esm/services/MongooseConnections.js +44 -0
  173. package/lib/esm/services/MongooseConnections.js.map +1 -0
  174. package/lib/esm/services/MongooseService.js +70 -0
  175. package/lib/esm/services/MongooseService.js.map +1 -0
  176. package/lib/esm/utils/createModel.js +48 -0
  177. package/lib/esm/utils/createModel.js.map +1 -0
  178. package/lib/esm/utils/createSchema.js +151 -0
  179. package/lib/esm/utils/createSchema.js.map +1 -0
  180. package/lib/esm/utils/resolveRefType.js +15 -0
  181. package/lib/esm/utils/resolveRefType.js.map +1 -0
  182. package/lib/esm/utils/schemaOptions.js +54 -0
  183. package/lib/esm/utils/schemaOptions.js.map +1 -0
  184. package/lib/{MongooseModule.d.ts → types/MongooseModule.d.ts} +0 -0
  185. package/lib/{constants/index.d.ts → types/constants/constants.d.ts} +0 -0
  186. package/lib/{decorators → types/decorators}/auto.d.ts +0 -0
  187. package/lib/{decorators → types/decorators}/discriminatorKey.d.ts +0 -0
  188. package/lib/{decorators → types/decorators}/dynamicRef.d.ts +4 -2
  189. package/lib/{decorators → types/decorators}/excludeIndexes.d.ts +0 -0
  190. package/lib/{decorators → types/decorators}/expires.d.ts +0 -0
  191. package/lib/{decorators → types/decorators}/immutable.d.ts +0 -0
  192. package/lib/{decorators → types/decorators}/indexed.d.ts +0 -0
  193. package/lib/{decorators → types/decorators}/lowercase.d.ts +0 -0
  194. package/lib/{decorators → types/decorators}/model.d.ts +0 -0
  195. package/lib/{decorators → types/decorators}/mongooseIndex.d.ts +0 -0
  196. package/lib/types/decorators/mongooseIndexes.d.ts +32 -0
  197. package/lib/{decorators → types/decorators}/mongoosePlugin.d.ts +0 -0
  198. package/lib/{decorators → types/decorators}/numberDecimal.d.ts +0 -0
  199. package/lib/{decorators → types/decorators}/objectID.d.ts +0 -0
  200. package/lib/{decorators → types/decorators}/postHook.d.ts +1 -1
  201. package/lib/{decorators → types/decorators}/preHook.d.ts +1 -1
  202. package/lib/{decorators → types/decorators}/ref.d.ts +7 -2
  203. package/lib/{decorators → types/decorators}/schema.d.ts +1 -1
  204. package/lib/{decorators → types/decorators}/schemaIgnore.d.ts +0 -0
  205. package/lib/{decorators → types/decorators}/select.d.ts +0 -0
  206. package/lib/{decorators → types/decorators}/sparse.d.ts +0 -0
  207. package/lib/{decorators → types/decorators}/text.d.ts +0 -0
  208. package/lib/{decorators → types/decorators}/trim.d.ts +0 -0
  209. package/lib/{decorators → types/decorators}/unique.d.ts +0 -0
  210. package/lib/{decorators → types/decorators}/uppercase.d.ts +0 -0
  211. package/lib/{decorators → types/decorators}/versionKey.d.ts +0 -0
  212. package/lib/{decorators → types/decorators}/virtualRef.d.ts +0 -4
  213. package/lib/types/index.d.ts +47 -0
  214. package/lib/{interfaces → types/interfaces}/MongooseConnectionOptions.d.ts +0 -0
  215. package/lib/{interfaces → types/interfaces}/MongooseDocument.d.ts +0 -0
  216. package/lib/{interfaces → types/interfaces}/MongooseModel.d.ts +1 -2
  217. package/lib/{interfaces → types/interfaces}/MongooseModelOptions.d.ts +1 -1
  218. package/lib/{interfaces → types/interfaces}/MongooseSchemaOptions.d.ts +1 -1
  219. package/lib/{interfaces → types/interfaces}/MongooseSchemaTypes.d.ts +0 -0
  220. package/lib/{interfaces → types/interfaces}/MongooseVirtualRefOptions.d.ts +1 -0
  221. package/lib/{interfaces/index.d.ts → types/interfaces/interfaces.d.ts} +0 -6
  222. package/lib/{registries → types/registries}/MongooseModels.d.ts +0 -0
  223. package/lib/{services → types/services}/MongooseConnections.d.ts +0 -0
  224. package/lib/{services → types/services}/MongooseService.d.ts +0 -0
  225. package/lib/{utils → types/utils}/createModel.d.ts +3 -2
  226. package/lib/{utils → types/utils}/createSchema.d.ts +1 -1
  227. package/lib/{utils → types/utils}/resolveRefType.d.ts +0 -0
  228. package/lib/{utils → types/utils}/schemaOptions.d.ts +1 -1
  229. package/package.json +30 -27
  230. package/readme.md +124 -134
  231. package/tsconfig.compile.esm.json +13 -0
  232. package/.mocharc.js +0 -5
  233. package/.nycrc +0 -27
  234. package/lib/decorators/index.d.ts +0 -26
  235. package/lib/index.d.ts +0 -6
  236. package/lib/index.js +0 -1402
  237. package/lib/index.js.map +0 -1
  238. package/lib/index.modern.js +0 -1362
  239. package/lib/index.modern.js.map +0 -1
  240. package/lib/utils/index.d.ts +0 -2
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applySchemaOptions = exports.buildPreHook = exports.schemaOptions = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ const constants_1 = require("../constants/constants");
6
+ /**
7
+ * @ignore
8
+ */
9
+ function schemaOptions(target, options) {
10
+ const store = core_1.Store.from(target);
11
+ if (!store.has(constants_1.MONGOOSE_SCHEMA_OPTIONS)) {
12
+ store.set(constants_1.MONGOOSE_SCHEMA_OPTIONS, {});
13
+ }
14
+ if (options) {
15
+ store.set(constants_1.MONGOOSE_SCHEMA_OPTIONS, (0, core_1.deepMerge)(store.get(constants_1.MONGOOSE_SCHEMA_OPTIONS), options));
16
+ }
17
+ return store.get(constants_1.MONGOOSE_SCHEMA_OPTIONS);
18
+ }
19
+ exports.schemaOptions = schemaOptions;
20
+ function mapHookArgs(hook) {
21
+ return [hook.method, hook.options || hook.fn, hook.options ? hook.fn : undefined].filter(Boolean);
22
+ }
23
+ /**
24
+ * @ignore
25
+ */
26
+ function buildPreHook(fn) {
27
+ return fn.length === 2
28
+ ? function (next) {
29
+ return fn(this, next);
30
+ }
31
+ : function (next, options) {
32
+ return fn(this, next, options);
33
+ };
34
+ }
35
+ exports.buildPreHook = buildPreHook;
36
+ /**
37
+ * @ignore
38
+ */
39
+ function applySchemaOptions(schema, options) {
40
+ if (options.plugins) {
41
+ options.plugins.forEach((item) => schema.plugin(item.plugin, item.options));
42
+ }
43
+ if (options.indexes) {
44
+ options.indexes.forEach((item) => schema.index(item.fields, item.options));
45
+ }
46
+ if (options.pre) {
47
+ options.pre.forEach((item) => {
48
+ item = {
49
+ ...item,
50
+ fn: buildPreHook(item.fn)
51
+ };
52
+ schema.pre(...mapHookArgs(item));
53
+ });
54
+ }
55
+ if (options.post) {
56
+ options.post.forEach((item) => schema.post(...mapHookArgs(item)));
57
+ }
58
+ }
59
+ exports.applySchemaOptions = applySchemaOptions;
60
+ //# sourceMappingURL=schemaOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaOptions.js","sourceRoot":"","sources":["../../../src/utils/schemaOptions.ts"],"names":[],"mappings":";;;AAAA,qCAA4C;AAE5C,sDAA+D;AAG/D;;GAEG;AACH,SAAgB,aAAa,CAAC,MAAW,EAAE,OAA+B;IACxE,MAAM,KAAK,GAAG,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEjC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,mCAAuB,CAAC,EAAE;QACvC,KAAK,CAAC,GAAG,CAAC,mCAAuB,EAAE,EAAE,CAAC,CAAC;KACxC;IAED,IAAI,OAAO,EAAE;QACX,KAAK,CAAC,GAAG,CAAC,mCAAuB,EAAE,IAAA,gBAAS,EAAC,KAAK,CAAC,GAAG,CAAC,mCAAuB,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;KAC5F;IAED,OAAO,KAAK,CAAC,GAAG,CAAC,mCAAuB,CAAC,CAAC;AAC5C,CAAC;AAZD,sCAYC;AAED,SAAS,WAAW,CAAC,IAAwC;IAC3D,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAQ,CAAC;AAC3G,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,EAAY;IACvC,OAAO,EAAE,CAAC,MAAM,KAAK,CAAC;QACpB,CAAC,CAAC,UAAU,IAAoB;YAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACxB,CAAC;QACH,CAAC,CAAC,UAAU,IAAoB,EAAE,OAAY;YAC1C,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACjC,CAAC,CAAC;AACR,CAAC;AARD,oCAQC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,MAAc,EAAE,OAA8B;IAC/E,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;KAC7E;IAED,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;KAC5E;IAED,IAAI,OAAO,CAAC,GAAG,EAAE;QACf,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC3B,IAAI,GAAG;gBACL,GAAG,IAAI;gBACP,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;aAC1B,CAAC;YAED,MAAM,CAAC,GAAW,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;KACJ;IAED,IAAI,OAAO,CAAC,IAAI,EAAE;QAChB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAE,MAAM,CAAC,IAAY,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAC5E;AACH,CAAC;AAvBD,gDAuBC","sourcesContent":["import {deepMerge, Store} from \"@tsed/core\";\nimport {Schema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA_OPTIONS} from \"../constants/constants\";\nimport {MongooseNextCB, MongoosePostHook, MongoosePreHook, MongooseSchemaOptions} from \"../interfaces/MongooseSchemaOptions\";\n\n/**\n * @ignore\n */\nexport function schemaOptions(target: any, options?: MongooseSchemaOptions) {\n const store = Store.from(target);\n\n if (!store.has(MONGOOSE_SCHEMA_OPTIONS)) {\n store.set(MONGOOSE_SCHEMA_OPTIONS, {});\n }\n\n if (options) {\n store.set(MONGOOSE_SCHEMA_OPTIONS, deepMerge(store.get(MONGOOSE_SCHEMA_OPTIONS), options));\n }\n\n return store.get(MONGOOSE_SCHEMA_OPTIONS);\n}\n\nfunction mapHookArgs(hook: MongoosePreHook | MongoosePostHook): [string | RegExp, Function] {\n return [hook.method, hook.options || hook.fn, hook.options ? hook.fn : undefined].filter(Boolean) as any;\n}\n\n/**\n * @ignore\n */\nexport function buildPreHook(fn: Function) {\n return fn.length === 2\n ? function (next: MongooseNextCB) {\n return fn(this, next);\n }\n : function (next: MongooseNextCB, options: any) {\n return fn(this, next, options);\n };\n}\n\n/**\n * @ignore\n */\nexport function applySchemaOptions(schema: Schema, options: MongooseSchemaOptions) {\n if (options.plugins) {\n options.plugins.forEach((item) => schema.plugin(item.plugin, item.options));\n }\n\n if (options.indexes) {\n options.indexes.forEach((item) => schema.index(item.fields, item.options));\n }\n\n if (options.pre) {\n options.pre.forEach((item) => {\n item = {\n ...item,\n fn: buildPreHook(item.fn)\n };\n\n (schema.pre as any)(...mapHookArgs(item));\n });\n }\n\n if (options.post) {\n options.post.forEach((item) => (schema.post as any)(...mapHookArgs(item)));\n }\n}\n"]}
@@ -0,0 +1,33 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { Configuration } from "@tsed/di";
3
+ import { Module } from "@tsed/di";
4
+ import { MONGOOSE_CONNECTIONS } from "./services/MongooseConnections.js";
5
+ import { MongooseService } from "./services/MongooseService.js";
6
+ /**
7
+ * @ignore
8
+ */
9
+ let MongooseModule = class MongooseModule {
10
+ constructor(mongooseService, settings) {
11
+ this.mongooseService = mongooseService;
12
+ this.settings = settings;
13
+ // auto configure the cache manager when mongoose is used with @tsed/mongoose
14
+ const cache = this.settings.get("cache");
15
+ // istanbul ignore next
16
+ if (cache === null || cache === void 0 ? void 0 : cache.mongoose) {
17
+ cache.connection = this.mongooseService.get();
18
+ }
19
+ }
20
+ $onInit() { }
21
+ $onDestroy() {
22
+ return this.mongooseService.closeConnections();
23
+ }
24
+ };
25
+ MongooseModule = __decorate([
26
+ Module({
27
+ imports: [MONGOOSE_CONNECTIONS]
28
+ }),
29
+ __param(1, Configuration()),
30
+ __metadata("design:paramtypes", [MongooseService, Object])
31
+ ], MongooseModule);
32
+ export { MongooseModule };
33
+ //# sourceMappingURL=MongooseModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MongooseModule.js","sourceRoot":"","sources":["../../src/MongooseModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,aAAa,EAAS,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAC,MAAM,EAAY,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;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,MAAM,CAAC;QACN,OAAO,EAAE,CAAC,oBAAoB,CAAC;KAChC,CAAC;IAEuD,WAAA,aAAa,EAAE,CAAA;qCAAjC,eAAe;GADzC,cAAc,CAgB1B;SAhBY,cAAc","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"]}
@@ -0,0 +1,21 @@
1
+ /**
2
+ *
3
+ * @type {string}
4
+ */
5
+ export const MONGOOSE_SCHEMA = "tsed:mongoose:schema";
6
+ /**
7
+ *
8
+ * @type {string}
9
+ */
10
+ export const MONGOOSE_SCHEMA_OPTIONS = "tsed:mongoose:schema:options";
11
+ /**
12
+ *
13
+ * @type {string}
14
+ */
15
+ export const MONGOOSE_MODEL = "tsed:mongoose:model";
16
+ /**
17
+ *
18
+ * @type {string}
19
+ */
20
+ export const MONGOOSE_MODEL_NAME = "tsed:mongoose:model:name";
21
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,sBAAsB,CAAC;AACtD;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;AACtE;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAC;AACpD;;;GAGG;AACH,MAAM,CAAC,MAAM,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"]}
@@ -0,0 +1,24 @@
1
+ import { MongooseSchema } from "./schema.js";
2
+ /**
3
+ * If true, uses Mongoose's default _id settings. Only allowed for ObjectIds
4
+ *
5
+ * ### Example
6
+ *
7
+ * ```typescript
8
+ * @Model()
9
+ * export class EventModel {
10
+ * @ExcludeIndexes()
11
+ * field: string;
12
+ * }
13
+ * ```
14
+ *
15
+ * @param {boolean} auto
16
+ * @returns {Function}
17
+ * @decorator
18
+ * @mongoose
19
+ * @property
20
+ */
21
+ export function Auto(auto = true) {
22
+ return MongooseSchema({ auto });
23
+ }
24
+ //# sourceMappingURL=auto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto.js","sourceRoot":"","sources":["../../../src/decorators/auto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,IAAI,CAAC,OAAgB,IAAI;IACvC,OAAO,cAAc,CAAC,EAAC,IAAI,EAAQ,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * If true, uses Mongoose's default _id settings. Only allowed for ObjectIds\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @ExcludeIndexes()\n * field: string;\n * }\n * ```\n *\n * @param {boolean} auto\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Auto(auto: boolean = true): PropertyDecorator {\n return MongooseSchema({auto} as any);\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { Store, useDecorators } from "@tsed/core";
2
+ import { MONGOOSE_SCHEMA_OPTIONS } from "../constants/constants.js";
3
+ import { SchemaIgnore } from "./schemaIgnore.js";
4
+ import { Property } from "@tsed/schema";
5
+ export function DiscriminatorKey() {
6
+ return useDecorators(Property(), SchemaIgnore(), (target, propertyKey) => {
7
+ Store.from(target).merge(MONGOOSE_SCHEMA_OPTIONS, { discriminatorKey: propertyKey });
8
+ });
9
+ }
10
+ //# sourceMappingURL=discriminatorKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discriminatorKey.js","sourceRoot":"","sources":["../../../src/decorators/discriminatorKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AAChD,OAAO,EAAC,uBAAuB,EAAC,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAEtC,MAAM,UAAU,gBAAgB;IAC9B,OAAO,aAAa,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,EAAE,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QACpF,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,uBAAuB,EAAE,EAAC,gBAAgB,EAAE,WAAW,EAAC,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;AACL,CAAC","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"]}
@@ -0,0 +1,61 @@
1
+ import { isString, StoreMerge, useDecorators } from "@tsed/core";
2
+ import { Description, Example, OneOf, Property, string } from "@tsed/schema";
3
+ import { Schema as MongooseSchema } from "mongoose";
4
+ import { MONGOOSE_SCHEMA } from "../constants/constants.js";
5
+ import { deserialize, OnDeserialize, OnSerialize, serialize } from "@tsed/json-mapper";
6
+ import { MongooseModels } from "../registries/MongooseModels.js";
7
+ function isRef(value) {
8
+ return (value && value._bsontype) || isString(value);
9
+ }
10
+ function getType(refPath, ctx) {
11
+ return ((ctx === null || ctx === void 0 ? void 0 : ctx.self[refPath]) && MongooseModels.get(ctx.self[refPath])) || Object;
12
+ }
13
+ /**
14
+ * Define a property as mongoose reference to other Model (decorated with @Model).
15
+ *
16
+ * ### Example
17
+ *
18
+ * ```typescript
19
+ * @Model()
20
+ * class FooModel {
21
+ *
22
+ * @DynamicRef('type')
23
+ * field: DynamicRef<OtherFooModel | OtherModel>
24
+ *
25
+ * @Enum(['OtherFooModel', 'OtherModel'])
26
+ * type: string
27
+ * }
28
+ *
29
+ * @Model()
30
+ * class OtherFooModel {
31
+ * }
32
+ *
33
+ * @Model()
34
+ * class OtherModel {
35
+ * }
36
+ * ```
37
+ *
38
+ * @param refPath {String} the path to apply the correct model
39
+ * @param types {Type} the classes to generate the correct json schema
40
+ * @returns {Function}
41
+ * @decorator
42
+ * @mongoose
43
+ * @property
44
+ */
45
+ export function DynamicRef(refPath, ...types) {
46
+ return useDecorators(Property(Object), Example("5ce7ad3028890bd71749d477"), Description("Mongoose Ref ObjectId"), StoreMerge(MONGOOSE_SCHEMA, {
47
+ type: MongooseSchema.Types.ObjectId,
48
+ refPath
49
+ }), OnDeserialize((value, ctx) => {
50
+ if (isRef(value)) {
51
+ return value.toString();
52
+ }
53
+ return deserialize(value, { ...ctx, type: getType(refPath, ctx) });
54
+ }), OnSerialize((value, ctx) => {
55
+ if (isRef(value)) {
56
+ return value.toString();
57
+ }
58
+ return serialize(value, { ...ctx, type: getType(refPath, ctx) });
59
+ }), OneOf(string().example("5ce7ad3028890bd71749d477").description("Mongoose Ref ObjectId"), ...types));
60
+ }
61
+ //# sourceMappingURL=dynamicRef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamicRef.js","sourceRoot":"","sources":["../../../src/decorators/dynamicRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,UAAU,EAAQ,aAAa,EAAC,MAAM,YAAY,CAAC;AACzF,OAAO,EAAC,WAAW,EAAE,OAAO,EAAmB,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAC,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAC,MAAM,IAAI,cAAc,EAAC,MAAM,UAAU,CAAC;AAClD,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAC,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AACrF,OAAO,EAAC,cAAc,EAAC,MAAM,8BAA8B,CAAC;AAE5D,SAAS,KAAK,CAAC,KAA+B;IAC5C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,QAAQ,CAAC,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,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAW,CAAC,CAAC,IAAI,MAAM,CAAC;AAC3F,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,GAAG,KAAkB;IAC/D,OAAO,aAAa,CAClB,QAAQ,CAAC,MAAM,CAAC,EAChB,OAAO,CAAC,0BAA0B,CAAC,EACnC,WAAW,CAAC,uBAAuB,CAAC,EACpC,UAAU,CAAC,eAAe,EAAE;QAC1B,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC,QAAQ;QACnC,OAAO;KACR,CAAC,EACF,aAAa,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAC3B,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzB;QAED,OAAO,WAAW,CAAC,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,EAAC,CAAC,CAAC;IACnE,CAAC,CAAC,EACF,WAAW,CAAC,CAAC,KAAU,EAAE,GAAG,EAAE,EAAE;QAC9B,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzB;QAED,OAAO,SAAS,CAAC,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,EAAC,CAAC,CAAC;IACjE,CAAC,CAAC,EACF,KAAK,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC,WAAW,CAAC,uBAAuB,CAAC,EAAE,GAAG,KAAK,CAAC,CAC9E,CAAC;AACzB,CAAC","sourcesContent":["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"]}
@@ -0,0 +1,24 @@
1
+ import { MongooseSchema } from "./schema.js";
2
+ /**
3
+ * If true, Mongoose will skip gathering indexes on subpaths. Only allowed for subdocuments and subdocument arrays.
4
+ *
5
+ * ### Example
6
+ *
7
+ * ```typescript
8
+ * @Model()
9
+ * export class EventModel {
10
+ * @ExcludeIndexes()
11
+ * field: string;
12
+ * }
13
+ * ```
14
+ *
15
+ * @param {boolean} excludeIndexes
16
+ * @returns {Function}
17
+ * @decorator
18
+ * @mongoose
19
+ * @property
20
+ */
21
+ export function ExcludeIndexes(excludeIndexes = true) {
22
+ return MongooseSchema({ excludeIndexes });
23
+ }
24
+ //# sourceMappingURL=excludeIndexes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"excludeIndexes.js","sourceRoot":"","sources":["../../../src/decorators/excludeIndexes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,cAAc,CAAC,iBAA0B,IAAI;IAC3D,OAAO,cAAc,CAAC,EAAC,cAAc,EAAQ,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * If true, Mongoose will skip gathering indexes on subpaths. Only allowed for subdocuments and subdocument arrays.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @ExcludeIndexes()\n * field: string;\n * }\n * ```\n *\n * @param {boolean} excludeIndexes\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function ExcludeIndexes(excludeIndexes: boolean = true): PropertyDecorator {\n return MongooseSchema({excludeIndexes} as any);\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import { MongooseSchema } from "./schema.js";
2
+ /**
3
+ * Defines a TTL index on this path. Only allowed for dates.
4
+ *
5
+ * ### Example
6
+ *
7
+ * ```typescript
8
+ * @Model()
9
+ * export class EventModel {
10
+ * @Expires('5d')
11
+ * field: string;
12
+ * }
13
+ * ```
14
+ *
15
+ * @param {boolean | any} expires
16
+ * @returns {Function}
17
+ * @decorator
18
+ * @mongoose
19
+ * @property
20
+ */
21
+ export function Expires(expires) {
22
+ return MongooseSchema({ expires });
23
+ }
24
+ //# sourceMappingURL=expires.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expires.js","sourceRoot":"","sources":["../../../src/decorators/expires.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,OAAO,CAAC,OAA+B;IACrD,OAAO,cAAc,CAAC,EAAC,OAAO,EAAQ,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * Defines a TTL index on this path. Only allowed for dates.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Expires('5d')\n * field: string;\n * }\n * ```\n *\n * @param {boolean | any} expires\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Expires(expires: number | string | Date): PropertyDecorator {\n return MongooseSchema({expires} as any);\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import { MongooseSchema } from "./schema.js";
2
+ /**
3
+ * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will
4
+ * disallow changes to this path once the document is saved to the database for the first time. Read more
5
+ * about [immutability in Mongoose here](http://thecodebarbarian.com/whats-new-in-mongoose-5-6-immutable-properties.html).
6
+ *
7
+ * ### Example
8
+ *
9
+ * ```typescript
10
+ * @Model()
11
+ * export class EventModel {
12
+ * @Immutable()
13
+ * field: string;
14
+ * }
15
+ * ```
16
+ *
17
+ * @param {boolean | any} immutable
18
+ * @returns {Function}
19
+ * @decorator
20
+ * @mongoose
21
+ * @property
22
+ */
23
+ export function Immutable(immutable = true) {
24
+ return MongooseSchema({ immutable });
25
+ }
26
+ //# sourceMappingURL=immutable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"immutable.js","sourceRoot":"","sources":["../../../src/decorators/immutable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,SAAS,CAAC,YAA0D,IAAI;IACtF,OAAO,cAAc,CAAC,EAAC,SAAS,EAAQ,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will\n * disallow changes to this path once the document is saved to the database for the first time. Read more\n * about [immutability in Mongoose here](http://thecodebarbarian.com/whats-new-in-mongoose-5-6-immutable-properties.html).\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Immutable()\n * field: string;\n * }\n * ```\n *\n * @param {boolean | any} immutable\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Immutable(immutable: boolean | ((this: any, doc: any) => boolean) = true): PropertyDecorator {\n return MongooseSchema({immutable} as any);\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import { MongooseSchema } from "./schema.js";
2
+ /**
3
+ * Tell Mongoose whether to define an index for the property.
4
+ * ### Example
5
+ *
6
+ * ```typescript
7
+ * @Model()
8
+ * export class EventModel {
9
+ * @Indexed()
10
+ * field: string;
11
+ * }
12
+ * ```
13
+ *
14
+ * @returns {Function}
15
+ * @decorator
16
+ * @mongoose
17
+ * @property
18
+ */
19
+ export function Indexed(index = true) {
20
+ return MongooseSchema({ index });
21
+ }
22
+ //# sourceMappingURL=indexed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexed.js","sourceRoot":"","sources":["../../../src/decorators/indexed.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,OAAO,CAAC,QAAyC,IAAI;IACnE,OAAO,cAAc,CAAC,EAAC,KAAK,EAAQ,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import {IndexOptions} from \"mongoose\";\nimport {MongooseSchema} from \"./schema\";\n\n/**\n * Tell Mongoose whether to define an index for the property.\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Indexed()\n * field: string;\n * }\n * ```\n *\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Indexed(index: IndexOptions | boolean | string = true): PropertyDecorator {\n return MongooseSchema({index} as any);\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import { MongooseSchema } from "./schema.js";
2
+ /**
3
+ * If truthy, Mongoose will add a custom setter that lowercases this string using JavaScript's built-in String#toLowerCase().
4
+ *
5
+ * ### Example
6
+ *
7
+ * ```typescript
8
+ * @Model()
9
+ * export class EventModel {
10
+ * @Lowercase()
11
+ * field: string;
12
+ * }
13
+ * ```
14
+ *
15
+ * @param {boolean} lowercase
16
+ * @returns {Function}
17
+ * @decorator
18
+ * @mongoose
19
+ * @property
20
+ */
21
+ export function Lowercase(lowercase = true) {
22
+ return MongooseSchema({ lowercase });
23
+ }
24
+ //# sourceMappingURL=lowercase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lowercase.js","sourceRoot":"","sources":["../../../src/decorators/lowercase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,SAAS,CAAC,YAAqB,IAAI;IACjD,OAAO,cAAc,CAAC,EAAC,SAAS,EAAQ,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * If truthy, Mongoose will add a custom setter that lowercases this string using JavaScript's built-in String#toLowerCase().\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Lowercase()\n * field: string;\n * }\n * ```\n *\n * @param {boolean} lowercase\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Lowercase(lowercase: boolean = true): PropertyDecorator {\n return MongooseSchema({lowercase} as any);\n}\n"]}
@@ -0,0 +1,64 @@
1
+ import { registerProvider } from "@tsed/di";
2
+ import { MONGOOSE_CONNECTIONS } from "../services/MongooseConnections.js";
3
+ import { createModel, getModelToken } from "../utils/createModel.js";
4
+ import { getSchema } from "../utils/createSchema.js";
5
+ import { applySchemaOptions, schemaOptions } from "../utils/schemaOptions.js";
6
+ /**
7
+ * Define a class as a Mongoose Model. The model can be injected to the Service, Controller, Middleware, Converters or Filter with
8
+ * `@Inject` annotation.
9
+ *
10
+ * ### Example
11
+ *
12
+ * ```typescript
13
+ * @Model()
14
+ * export class EventModel {
15
+ * @Property()
16
+ * field: string;
17
+ * }
18
+ * ```
19
+ *
20
+ * Then inject the model into a service:
21
+ *
22
+ * ```typescript
23
+ * class MyService {
24
+ * constructor(@Inject(EventModel) eventModel: MongooseModel<EventModel>) {
25
+ * eventModel.findById().exec();
26
+ * }
27
+ * }
28
+ * ```
29
+ *
30
+ * ### Options
31
+ *
32
+ * - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.
33
+ * - `name` (String): model name.
34
+ * - `collection` (String): collection (optional, induced from model name).
35
+ * - `skipInit` (Boolean): skipInit whether to skip initialization (defaults to false).
36
+ *
37
+ * @param {MongooseModelOptions} options
38
+ * @returns {(target: any) => void}
39
+ * @decorator
40
+ * @mongoose
41
+ * @class
42
+ */
43
+ export function Model(options = {}) {
44
+ return (target) => {
45
+ const { token, collectionName } = getModelToken(target, options);
46
+ registerProvider({
47
+ provide: token,
48
+ deps: [],
49
+ useFactory() {
50
+ return getSchema(target, options);
51
+ }
52
+ });
53
+ registerProvider({
54
+ provide: target,
55
+ type: "mongoose:model",
56
+ deps: [MONGOOSE_CONNECTIONS, token],
57
+ useFactory(connections, schema) {
58
+ applySchemaOptions(schema, schemaOptions(target));
59
+ return createModel(target, schema, collectionName, options.collection, options.overwriteModels, connections.get(options.connection), options.discriminatorValue);
60
+ }
61
+ });
62
+ };
63
+ }
64
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../../src/decorators/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAG1C,OAAO,EAAC,oBAAoB,EAAC,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAC,WAAW,EAAE,aAAa,EAAC,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAC,kBAAkB,EAAE,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,UAAU,KAAK,CAAC,UAAgC,EAAE;IACtD,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,MAAM,EAAC,KAAK,EAAE,cAAc,EAAC,GAAG,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE/D,gBAAgB,CAAC;YACf,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,EAAE;YACR,UAAU;gBACR,OAAO,SAAS,CAAC,MAAM,EAAE,OAAc,CAAC,CAAC;YAC3C,CAAC;SACF,CAAC,CAAC;QAEH,gBAAgB,CAAC;YACf,OAAO,EAAE,MAAM;YACf,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,CAAC,oBAAoB,EAAE,KAAK,CAAC;YACnC,UAAU,CAAC,WAAiC,EAAE,MAAc;gBAC1D,kBAAkB,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;gBAClD,OAAO,WAAW,CAChB,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","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"]}
@@ -0,0 +1,35 @@
1
+ import { schemaOptions } from "../utils/schemaOptions.js";
2
+ /**
3
+ * Calls schema.index() to define an index (most likely compound) for the schema.
4
+ *
5
+ * ### Example
6
+ *
7
+ * ```typescript
8
+ * @Model()
9
+ * @MongooseIndex({first: 1, second: 1}, {unique: 1})
10
+ * export class EventModel {
11
+ *
12
+ * @Property()
13
+ * first: string;
14
+ *
15
+ * @Property()
16
+ * second: string;
17
+ *
18
+ * }
19
+ * ```
20
+ *
21
+ * @param fields
22
+ * @param options
23
+ * @returns {Function}
24
+ * @decorator
25
+ * @mongoose
26
+ * @class
27
+ */
28
+ export function MongooseIndex(fields, options) {
29
+ return (target) => {
30
+ schemaOptions(target, {
31
+ indexes: [{ fields, options }]
32
+ });
33
+ };
34
+ }
35
+ //# sourceMappingURL=mongooseIndex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongooseIndex.js","sourceRoot":"","sources":["../../../src/decorators/mongooseIndex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,OAAa;IACzD,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,aAAa,CAAC,MAAM,EAAE;YACpB,OAAO,EAAE,CAAC,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC;SAC7B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n * Calls schema.index() to define an index (most likely compound) for the schema.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * @MongooseIndex({first: 1, second: 1}, {unique: 1})\n * export class EventModel {\n *\n * @Property()\n * first: string;\n *\n * @Property()\n * second: string;\n *\n * }\n * ```\n *\n * @param fields\n * @param options\n * @returns {Function}\n * @decorator\n * @mongoose\n * @class\n */\nexport function MongooseIndex(fields: object, options?: any): Function {\n return (target: any) => {\n schemaOptions(target, {\n indexes: [{fields, options}]\n });\n };\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { schemaOptions } from "../utils/schemaOptions.js";
2
+ /**
3
+ * Calls schema.index() to define multiple indexes (most likely compound) for the schema.
4
+ *
5
+ * ### Example
6
+ *
7
+ * ```typescript
8
+ * @Model()
9
+ * @MongooseIndexes([{fields: {first: 1, second: 1}, options:{unique: 1}}, {fields: {first: 1, third: 1}, options:{unique: 1}}])
10
+ * export class EventModel {
11
+ *
12
+ * @Property()
13
+ * first: string;
14
+ *
15
+ * @Property()
16
+ * second: string;
17
+ *
18
+ * @Property()
19
+ * third: string;
20
+ *
21
+ * }
22
+ * ```
23
+ *
24
+ * @param indexes - define multiple mongoose indexes
25
+ * @returns {Function}
26
+ * @decorator
27
+ * @mongoose
28
+ * @class
29
+ */
30
+ export function MongooseIndexes(indexes) {
31
+ return (target) => {
32
+ schemaOptions(target, { indexes });
33
+ };
34
+ }
35
+ //# sourceMappingURL=mongooseIndexes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongooseIndexes.js","sourceRoot":"","sources":["../../../src/decorators/mongooseIndexes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,eAAe,CAAC,OAA+C;IAC7E,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,aAAa,CAAC,MAAM,EAAE,EAAC,OAAO,EAAC,CAAC,CAAC;IACnC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n * Calls schema.index() to define multiple indexes (most likely compound) for the schema.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * @MongooseIndexes([{fields: {first: 1, second: 1}, options:{unique: 1}}, {fields: {first: 1, third: 1}, options:{unique: 1}}])\n * export class EventModel {\n *\n * @Property()\n * first: string;\n *\n * @Property()\n * second: string;\n *\n * @Property()\n * third: string;\n *\n * }\n * ```\n *\n * @param indexes - define multiple mongoose indexes\n * @returns {Function}\n * @decorator\n * @mongoose\n * @class\n */\nexport function MongooseIndexes(indexes: Array<{fields: object; options?: any}>): Function {\n return (target: any) => {\n schemaOptions(target, {indexes});\n };\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import { schemaOptions } from "../utils/schemaOptions.js";
2
+ /**
3
+ *
4
+ * @param {(schema: "mongoose".Schema, options?: any) => void} plugin
5
+ * @param options
6
+ * @returns {Function}
7
+ * @decorator
8
+ * @mongoose
9
+ * @class
10
+ */
11
+ export function MongoosePlugin(plugin, options) {
12
+ return (target) => {
13
+ schemaOptions(target, {
14
+ plugins: [{ plugin, options }]
15
+ });
16
+ };
17
+ }
18
+ //# sourceMappingURL=mongoosePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoosePlugin.js","sourceRoot":"","sources":["../../../src/decorators/mongoosePlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAErD;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,MAAwD,EAAE,OAAa;IACpG,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,aAAa,CAAC,MAAM,EAAE;YACpB,OAAO,EAAE,CAAC,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC;SAC7B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import mongoose from \"mongoose\";\nimport {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n *\n * @param {(schema: \"mongoose\".Schema, options?: any) => void} plugin\n * @param options\n * @returns {Function}\n * @decorator\n * @mongoose\n * @class\n */\nexport function MongoosePlugin(plugin: (schema: mongoose.Schema, options?: any) => void, options?: any): Function {\n return (target: any) => {\n schemaOptions(target, {\n plugins: [{plugin, options}]\n });\n };\n}\n"]}