@tsed/mongoose 7.0.0-alpha.1 → 7.0.0-beta.3

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 (244) 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/index.js +24 -0
  5. package/lib/cjs/constants/index.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 +46 -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/index.js +30 -0
  19. package/lib/cjs/decorators/index.js.map +1 -0
  20. package/lib/cjs/decorators/indexed.js +26 -0
  21. package/lib/cjs/decorators/indexed.js.map +1 -0
  22. package/lib/cjs/decorators/lowercase.js +28 -0
  23. package/lib/cjs/decorators/lowercase.js.map +1 -0
  24. package/lib/cjs/decorators/model.js +67 -0
  25. package/lib/cjs/decorators/model.js.map +1 -0
  26. package/lib/cjs/decorators/mongooseIndex.js +39 -0
  27. package/lib/cjs/decorators/mongooseIndex.js.map +1 -0
  28. package/lib/cjs/decorators/mongooseIndexes.js +39 -0
  29. package/lib/cjs/decorators/mongooseIndexes.js.map +1 -0
  30. package/lib/cjs/decorators/mongoosePlugin.js +22 -0
  31. package/lib/cjs/decorators/mongoosePlugin.js.map +1 -0
  32. package/lib/cjs/decorators/numberDecimal.js +78 -0
  33. package/lib/cjs/decorators/numberDecimal.js.map +1 -0
  34. package/lib/cjs/decorators/objectID.js +26 -0
  35. package/lib/cjs/decorators/objectID.js.map +1 -0
  36. package/lib/cjs/decorators/postHook.js +26 -0
  37. package/lib/cjs/decorators/postHook.js.map +1 -0
  38. package/lib/cjs/decorators/preHook.js +71 -0
  39. package/lib/cjs/decorators/preHook.js.map +1 -0
  40. package/lib/cjs/decorators/ref.js +75 -0
  41. package/lib/cjs/decorators/ref.js.map +1 -0
  42. package/lib/cjs/decorators/schema.js +32 -0
  43. package/lib/cjs/decorators/schema.js.map +1 -0
  44. package/lib/cjs/decorators/schemaIgnore.js +27 -0
  45. package/lib/cjs/decorators/schemaIgnore.js.map +1 -0
  46. package/lib/cjs/decorators/select.js +28 -0
  47. package/lib/cjs/decorators/select.js.map +1 -0
  48. package/lib/cjs/decorators/sparse.js +30 -0
  49. package/lib/cjs/decorators/sparse.js.map +1 -0
  50. package/lib/cjs/decorators/text.js +29 -0
  51. package/lib/cjs/decorators/text.js.map +1 -0
  52. package/lib/cjs/decorators/trim.js +27 -0
  53. package/lib/cjs/decorators/trim.js.map +1 -0
  54. package/lib/cjs/decorators/unique.js +27 -0
  55. package/lib/cjs/decorators/unique.js.map +1 -0
  56. package/lib/cjs/decorators/uppercase.js +28 -0
  57. package/lib/cjs/decorators/uppercase.js.map +1 -0
  58. package/lib/cjs/decorators/versionKey.js +12 -0
  59. package/lib/cjs/decorators/versionKey.js.map +1 -0
  60. package/lib/cjs/decorators/virtualRef.js +38 -0
  61. package/lib/cjs/decorators/virtualRef.js.map +1 -0
  62. package/lib/cjs/index.js +10 -0
  63. package/lib/cjs/index.js.map +1 -0
  64. package/lib/cjs/interfaces/MongooseConnectionOptions.js +3 -0
  65. package/lib/cjs/interfaces/MongooseConnectionOptions.js.map +1 -0
  66. package/lib/cjs/interfaces/MongooseDocument.js +3 -0
  67. package/lib/cjs/interfaces/MongooseDocument.js.map +1 -0
  68. package/lib/cjs/interfaces/MongooseModel.js +3 -0
  69. package/lib/cjs/interfaces/MongooseModel.js.map +1 -0
  70. package/lib/cjs/interfaces/MongooseModelOptions.js +3 -0
  71. package/lib/cjs/interfaces/MongooseModelOptions.js.map +1 -0
  72. package/lib/cjs/interfaces/MongooseSchemaOptions.js +3 -0
  73. package/lib/cjs/interfaces/MongooseSchemaOptions.js.map +1 -0
  74. package/lib/cjs/interfaces/MongooseSchemaTypes.js +10 -0
  75. package/lib/cjs/interfaces/MongooseSchemaTypes.js.map +1 -0
  76. package/lib/cjs/interfaces/MongooseVirtualRefOptions.js +3 -0
  77. package/lib/cjs/interfaces/MongooseVirtualRefOptions.js.map +1 -0
  78. package/lib/cjs/interfaces/index.js +10 -0
  79. package/lib/cjs/interfaces/index.js.map +1 -0
  80. package/lib/cjs/registries/MongooseModels.js +5 -0
  81. package/lib/cjs/registries/MongooseModels.js.map +1 -0
  82. package/lib/cjs/services/MongooseConnections.js +51 -0
  83. package/lib/cjs/services/MongooseConnections.js.map +1 -0
  84. package/lib/cjs/services/MongooseService.js +73 -0
  85. package/lib/cjs/services/MongooseService.js.map +1 -0
  86. package/lib/cjs/utils/createModel.js +58 -0
  87. package/lib/cjs/utils/createModel.js.map +1 -0
  88. package/lib/cjs/utils/createSchema.js +160 -0
  89. package/lib/cjs/utils/createSchema.js.map +1 -0
  90. package/lib/cjs/utils/index.js +6 -0
  91. package/lib/cjs/utils/index.js.map +1 -0
  92. package/lib/cjs/utils/resolveRefType.js +19 -0
  93. package/lib/cjs/utils/resolveRefType.js.map +1 -0
  94. package/lib/cjs/utils/schemaOptions.js +60 -0
  95. package/lib/cjs/utils/schemaOptions.js.map +1 -0
  96. package/lib/esm/MongooseModule.js +33 -0
  97. package/lib/esm/MongooseModule.js.map +1 -0
  98. package/lib/esm/constants/index.js +21 -0
  99. package/lib/esm/constants/index.js.map +1 -0
  100. package/lib/esm/decorators/auto.js +24 -0
  101. package/lib/esm/decorators/auto.js.map +1 -0
  102. package/lib/esm/decorators/discriminatorKey.js +10 -0
  103. package/lib/esm/decorators/discriminatorKey.js.map +1 -0
  104. package/lib/esm/decorators/dynamicRef.js +42 -0
  105. package/lib/esm/decorators/dynamicRef.js.map +1 -0
  106. package/lib/esm/decorators/excludeIndexes.js +24 -0
  107. package/lib/esm/decorators/excludeIndexes.js.map +1 -0
  108. package/lib/esm/decorators/expires.js +24 -0
  109. package/lib/esm/decorators/expires.js.map +1 -0
  110. package/lib/esm/decorators/immutable.js +26 -0
  111. package/lib/esm/decorators/immutable.js.map +1 -0
  112. package/lib/esm/decorators/index.js +27 -0
  113. package/lib/esm/decorators/index.js.map +1 -0
  114. package/lib/esm/decorators/indexed.js +22 -0
  115. package/lib/esm/decorators/indexed.js.map +1 -0
  116. package/lib/esm/decorators/lowercase.js +24 -0
  117. package/lib/esm/decorators/lowercase.js.map +1 -0
  118. package/lib/esm/decorators/model.js +63 -0
  119. package/lib/esm/decorators/model.js.map +1 -0
  120. package/lib/esm/decorators/mongooseIndex.js +35 -0
  121. package/lib/esm/decorators/mongooseIndex.js.map +1 -0
  122. package/lib/esm/decorators/mongooseIndexes.js +35 -0
  123. package/lib/esm/decorators/mongooseIndexes.js.map +1 -0
  124. package/lib/esm/decorators/mongoosePlugin.js +18 -0
  125. package/lib/esm/decorators/mongoosePlugin.js.map +1 -0
  126. package/lib/esm/decorators/numberDecimal.js +74 -0
  127. package/lib/esm/decorators/numberDecimal.js.map +1 -0
  128. package/lib/esm/decorators/objectID.js +22 -0
  129. package/lib/esm/decorators/objectID.js.map +1 -0
  130. package/lib/esm/decorators/postHook.js +22 -0
  131. package/lib/esm/decorators/postHook.js.map +1 -0
  132. package/lib/esm/decorators/preHook.js +67 -0
  133. package/lib/esm/decorators/preHook.js.map +1 -0
  134. package/lib/esm/decorators/ref.js +71 -0
  135. package/lib/esm/decorators/ref.js.map +1 -0
  136. package/lib/esm/decorators/schema.js +27 -0
  137. package/lib/esm/decorators/schema.js.map +1 -0
  138. package/lib/esm/decorators/schemaIgnore.js +23 -0
  139. package/lib/esm/decorators/schemaIgnore.js.map +1 -0
  140. package/lib/esm/decorators/select.js +24 -0
  141. package/lib/esm/decorators/select.js.map +1 -0
  142. package/lib/esm/decorators/sparse.js +26 -0
  143. package/lib/esm/decorators/sparse.js.map +1 -0
  144. package/lib/esm/decorators/text.js +25 -0
  145. package/lib/esm/decorators/text.js.map +1 -0
  146. package/lib/esm/decorators/trim.js +23 -0
  147. package/lib/esm/decorators/trim.js.map +1 -0
  148. package/lib/esm/decorators/unique.js +23 -0
  149. package/lib/esm/decorators/unique.js.map +1 -0
  150. package/lib/esm/decorators/uppercase.js +24 -0
  151. package/lib/esm/decorators/uppercase.js.map +1 -0
  152. package/lib/esm/decorators/versionKey.js +8 -0
  153. package/lib/esm/decorators/versionKey.js.map +1 -0
  154. package/lib/esm/decorators/virtualRef.js +34 -0
  155. package/lib/esm/decorators/virtualRef.js.map +1 -0
  156. package/lib/esm/index.js +7 -0
  157. package/lib/esm/index.js.map +1 -0
  158. package/lib/esm/interfaces/MongooseConnectionOptions.js +2 -0
  159. package/lib/esm/interfaces/MongooseConnectionOptions.js.map +1 -0
  160. package/lib/esm/interfaces/MongooseDocument.js +2 -0
  161. package/lib/esm/interfaces/MongooseDocument.js.map +1 -0
  162. package/lib/esm/interfaces/MongooseModel.js +2 -0
  163. package/lib/esm/interfaces/MongooseModel.js.map +1 -0
  164. package/lib/esm/interfaces/MongooseModelOptions.js +2 -0
  165. package/lib/esm/interfaces/MongooseModelOptions.js.map +1 -0
  166. package/lib/esm/interfaces/MongooseSchemaOptions.js +2 -0
  167. package/lib/esm/interfaces/MongooseSchemaOptions.js.map +1 -0
  168. package/lib/esm/interfaces/MongooseSchemaTypes.js +7 -0
  169. package/lib/esm/interfaces/MongooseSchemaTypes.js.map +1 -0
  170. package/lib/esm/interfaces/MongooseVirtualRefOptions.js +2 -0
  171. package/lib/esm/interfaces/MongooseVirtualRefOptions.js.map +1 -0
  172. package/lib/esm/interfaces/index.js +7 -0
  173. package/lib/esm/interfaces/index.js.map +1 -0
  174. package/lib/esm/registries/MongooseModels.js +2 -0
  175. package/lib/esm/registries/MongooseModels.js.map +1 -0
  176. package/lib/esm/services/MongooseConnections.js +48 -0
  177. package/lib/esm/services/MongooseConnections.js.map +1 -0
  178. package/lib/esm/services/MongooseService.js +70 -0
  179. package/lib/esm/services/MongooseService.js.map +1 -0
  180. package/lib/esm/utils/createModel.js +52 -0
  181. package/lib/esm/utils/createModel.js.map +1 -0
  182. package/lib/esm/utils/createSchema.js +151 -0
  183. package/lib/esm/utils/createSchema.js.map +1 -0
  184. package/lib/esm/utils/index.js +3 -0
  185. package/lib/esm/utils/index.js.map +1 -0
  186. package/lib/esm/utils/resolveRefType.js +15 -0
  187. package/lib/esm/utils/resolveRefType.js.map +1 -0
  188. package/lib/esm/utils/schemaOptions.js +54 -0
  189. package/lib/esm/utils/schemaOptions.js.map +1 -0
  190. package/lib/{MongooseModule.d.ts → types/MongooseModule.d.ts} +0 -0
  191. package/lib/{constants → types/constants}/index.d.ts +0 -0
  192. package/lib/{decorators → types/decorators}/auto.d.ts +0 -0
  193. package/lib/{decorators → types/decorators}/discriminatorKey.d.ts +0 -0
  194. package/lib/{decorators → types/decorators}/dynamicRef.d.ts +0 -0
  195. package/lib/{decorators → types/decorators}/excludeIndexes.d.ts +0 -0
  196. package/lib/{decorators → types/decorators}/expires.d.ts +0 -0
  197. package/lib/{decorators → types/decorators}/immutable.d.ts +0 -0
  198. package/lib/{decorators → types/decorators}/index.d.ts +0 -0
  199. package/lib/{decorators → types/decorators}/indexed.d.ts +0 -0
  200. package/lib/{decorators → types/decorators}/lowercase.d.ts +0 -0
  201. package/lib/{decorators → types/decorators}/model.d.ts +0 -0
  202. package/lib/{decorators → types/decorators}/mongooseIndex.d.ts +0 -0
  203. package/lib/types/decorators/mongooseIndexes.d.ts +32 -0
  204. package/lib/{decorators → types/decorators}/mongoosePlugin.d.ts +0 -0
  205. package/lib/{decorators → types/decorators}/numberDecimal.d.ts +0 -0
  206. package/lib/{decorators → types/decorators}/objectID.d.ts +0 -0
  207. package/lib/{decorators → types/decorators}/postHook.d.ts +0 -0
  208. package/lib/{decorators → types/decorators}/preHook.d.ts +0 -0
  209. package/lib/{decorators → types/decorators}/ref.d.ts +7 -2
  210. package/lib/{decorators → types/decorators}/schema.d.ts +0 -0
  211. package/lib/{decorators → types/decorators}/schemaIgnore.d.ts +0 -0
  212. package/lib/{decorators → types/decorators}/select.d.ts +0 -0
  213. package/lib/{decorators → types/decorators}/sparse.d.ts +0 -0
  214. package/lib/{decorators → types/decorators}/text.d.ts +0 -0
  215. package/lib/{decorators → types/decorators}/trim.d.ts +0 -0
  216. package/lib/{decorators → types/decorators}/unique.d.ts +0 -0
  217. package/lib/{decorators → types/decorators}/uppercase.d.ts +0 -0
  218. package/lib/{decorators → types/decorators}/versionKey.d.ts +0 -0
  219. package/lib/{decorators → types/decorators}/virtualRef.d.ts +0 -0
  220. package/lib/{index.d.ts → types/index.d.ts} +0 -0
  221. package/lib/{interfaces → types/interfaces}/MongooseConnectionOptions.d.ts +0 -0
  222. package/lib/{interfaces → types/interfaces}/MongooseDocument.d.ts +0 -0
  223. package/lib/{interfaces → types/interfaces}/MongooseModel.d.ts +0 -0
  224. package/lib/{interfaces → types/interfaces}/MongooseModelOptions.d.ts +0 -0
  225. package/lib/{interfaces → types/interfaces}/MongooseSchemaOptions.d.ts +0 -0
  226. package/lib/{interfaces → types/interfaces}/MongooseSchemaTypes.d.ts +0 -0
  227. package/lib/{interfaces → types/interfaces}/MongooseVirtualRefOptions.d.ts +1 -0
  228. package/lib/{interfaces → types/interfaces}/index.d.ts +0 -0
  229. package/lib/{registries → types/registries}/MongooseModels.d.ts +0 -0
  230. package/lib/{services → types/services}/MongooseConnections.d.ts +0 -0
  231. package/lib/{services → types/services}/MongooseService.d.ts +0 -0
  232. package/lib/{utils → types/utils}/createModel.d.ts +2 -1
  233. package/lib/{utils → types/utils}/createSchema.d.ts +0 -0
  234. package/lib/{utils → types/utils}/index.d.ts +0 -0
  235. package/lib/{utils → types/utils}/resolveRefType.d.ts +0 -0
  236. package/lib/{utils → types/utils}/schemaOptions.d.ts +0 -0
  237. package/package.json +25 -21
  238. package/tsconfig.compile.esm.json +23 -0
  239. package/.mocharc.js +0 -5
  240. package/.nycrc +0 -27
  241. package/lib/index.js +0 -1402
  242. package/lib/index.js.map +0 -1
  243. package/lib/index.modern.js +0 -1362
  244. package/lib/index.modern.js.map +0 -1
@@ -0,0 +1,74 @@
1
+ import { __decorate } from "tslib";
2
+ import { Formats } from "@tsed/ajv";
3
+ import { isNumber, isString, StoreMerge, useDecorators } from "@tsed/core";
4
+ import { OnDeserialize, OnSerialize } from "@tsed/json-mapper";
5
+ import { Example, Format, Property } from "@tsed/schema";
6
+ import { Types, Schema as MongooseSchema } from "mongoose";
7
+ import { MONGOOSE_SCHEMA } from "../constants";
8
+ let DecimalFormat = class DecimalFormat {
9
+ validate(num) {
10
+ return isString(num) || isNumber(num);
11
+ }
12
+ };
13
+ DecimalFormat = __decorate([
14
+ Formats("decimal", { type: "number" })
15
+ ], DecimalFormat);
16
+ export { DecimalFormat };
17
+ function isDecimal(value) {
18
+ return value && value._bsontype === "Decimal128";
19
+ }
20
+ /**
21
+ * Tell Mongoose whether to define an Decimal128 property.
22
+ * Will be serialized as `number` with format as `decimal`.
23
+ * ### Example
24
+ *
25
+ * ```typescript
26
+ * @Model()
27
+ * export class PriceModel {
28
+ * @NumberDecimal()
29
+ * price: Decimal128;
30
+ * }
31
+ * ```
32
+ * Optionally using custom decimal type, such as `Big` from big.js
33
+ * ```typescript
34
+ * @Model()
35
+ * export class PriceModel {
36
+ * @NumberDecimal(Big)
37
+ * price: Big;
38
+ * }
39
+ * ```
40
+ * @param type Optional decimal type constructor
41
+ * @decorator
42
+ * @mongoose
43
+ * @schema
44
+ */
45
+ export function NumberDecimal(type) {
46
+ const schema = {
47
+ type: MongooseSchema.Types.Decimal128
48
+ };
49
+ if (type) {
50
+ // Define property getter to convert Decimal128 to custom type
51
+ schema.get = (value) => {
52
+ return isDecimal(value) ? new type(value) : value;
53
+ };
54
+ }
55
+ return useDecorators(Property(Number), Format("decimal"), Example(12.34), StoreMerge(MONGOOSE_SCHEMA, schema),
56
+ // Deserialize number value from JSON to Decimal128
57
+ OnDeserialize((value) => {
58
+ if (value === undefined) {
59
+ return undefined;
60
+ }
61
+ if (type) {
62
+ return new type(value);
63
+ }
64
+ if (isString(value)) {
65
+ return Types.Decimal128.fromString(value);
66
+ }
67
+ return Types.Decimal128.fromString(`${value}`);
68
+ }),
69
+ // Serialize decimal value to floating point number
70
+ OnSerialize((value, ctx) => {
71
+ return value && Number(value);
72
+ }));
73
+ }
74
+ //# sourceMappingURL=numberDecimal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numberDecimal.js","sourceRoot":"","sources":["../../../src/decorators/numberDecimal.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAiB,MAAM,WAAW,CAAC;AAClD,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACzE,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AACvD,OAAO,EAAC,KAAK,EAAE,MAAM,IAAI,cAAc,EAAoB,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AAG7C,IAAa,aAAa,GAA1B,MAAa,aAAa;IACxB,QAAQ,CAAC,GAAoB;QAC3B,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC;IACxC,CAAC;CACF,CAAA;AAJY,aAAa;IADzB,OAAO,CAAC,SAAS,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC,CAAC;GACxB,aAAa,CAIzB;SAJY,aAAa;AAM1B,SAAS,SAAS,CAAC,KAA+B;IAChD,OAAO,KAAK,IAAI,KAAK,CAAC,SAAS,KAAK,YAAY,CAAC;AACnD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,aAAa,CAAC,IAAU;IACtC,MAAM,MAAM,GAAkC;QAC5C,IAAI,EAAE,cAAc,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,aAAa,CAClB,QAAQ,CAAC,MAAM,CAAC,EAChB,MAAM,CAAC,SAAS,CAAC,EACjB,OAAO,CAAC,KAAK,CAAC,EACd,UAAU,CAAC,eAAe,EAAE,MAAM,CAAC;IAEnC,mDAAmD;IACnD,aAAa,CAAC,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,QAAQ,CAAC,KAAK,CAAC,EAAE;YACnB,OAAO,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;SAC3C;QACD,OAAO,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;IACjD,CAAC,CAAC;IAEF,mDAAmD;IACnD,WAAW,CAAC,CAAC,KAAU,EAAE,GAAG,EAAE,EAAE;QAC9B,OAAO,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","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"]}
@@ -0,0 +1,22 @@
1
+ import { useDecorators } from "@tsed/core";
2
+ import { Description, Example, Name, Pattern } from "@tsed/schema";
3
+ /**
4
+ * Tell Mongoose whether to define an ObjectId property.
5
+ * ### Example
6
+ *
7
+ * ```typescript
8
+ * @Model()
9
+ * export class EventModel {
10
+ * @ObjectId('id')
11
+ * _id: string;
12
+ * }
13
+ * ```
14
+ * @param name
15
+ * @decorator
16
+ * @mongoose
17
+ * @schema
18
+ */
19
+ export function ObjectID(name) {
20
+ return useDecorators(name && Name(name), Pattern(/^[0-9a-fA-F]{24}$/), Description("Mongoose ObjectId"), Example("5ce7ad3028890bd71749d477"));
21
+ }
22
+ //# sourceMappingURL=objectID.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectID.js","sourceRoot":"","sources":["../../../src/decorators/objectID.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAC,MAAM,cAAc,CAAC;AAGjE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAa;IACpC,OAAO,aAAa,CAClB,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,EAClB,OAAO,CAAC,mBAAmB,CAAC,EAC5B,WAAW,CAAC,mBAAmB,CAAC,EAChC,OAAO,CAAC,0BAA0B,CAAC,CACpC,CAAC;AACJ,CAAC","sourcesContent":["import {useDecorators} from \"@tsed/core\";\nimport {Description, Example, Name, Pattern} from \"@tsed/schema\";\nimport {Types} from \"mongoose\";\n\n/**\n * Tell Mongoose whether to define an ObjectId property.\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @ObjectId('id')\n * _id: string;\n * }\n * ```\n * @param name\n * @decorator\n * @mongoose\n * @schema\n */\nexport function ObjectID(name?: string) {\n return useDecorators(\n name && Name(name),\n Pattern(/^[0-9a-fA-F]{24}$/),\n Description(\"Mongoose ObjectId\"),\n Example(\"5ce7ad3028890bd71749d477\")\n );\n}\n\nexport type ObjectID = Types.ObjectId;\n"]}
@@ -0,0 +1,22 @@
1
+ import { decoratorTypeOf, DecoratorTypes } from "@tsed/core";
2
+ import { schemaOptions } from "../utils/schemaOptions";
3
+ export function PostHook(method, ...params) {
4
+ return ((...args) => {
5
+ let options = params[1];
6
+ let fn = params[0];
7
+ if (decoratorTypeOf(args) === DecoratorTypes.METHOD_STC) {
8
+ options = params[0];
9
+ fn = args[0][args[1]].bind(args[0]);
10
+ }
11
+ schemaOptions(args[0], {
12
+ post: [
13
+ {
14
+ method,
15
+ fn,
16
+ options
17
+ }
18
+ ]
19
+ });
20
+ });
21
+ }
22
+ //# sourceMappingURL=postHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postHook.js","sourceRoot":"","sources":["../../../src/decorators/postHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAwB,MAAM,YAAY,CAAC;AAElF,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAgDrD,MAAM,UAAU,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,eAAe,CAAC,IAAI,CAAC,KAAK,cAAc,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,aAAa,CAAC,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","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"]}
@@ -0,0 +1,67 @@
1
+ import { decoratorTypeOf, DecoratorTypes } from "@tsed/core";
2
+ import { schemaOptions } from "../utils/schemaOptions";
3
+ /**
4
+ *
5
+ * We can simply attach a `@PreHook` decorator to your model class and
6
+ * define the hook function like you normally would in Mongoose.
7
+ *
8
+ * ```typescript
9
+ * import {Ignore, Required} from "@tsed/common";
10
+ * import {PreHook, Model} from "@tsed/mongoose";
11
+ *
12
+ * @Model()
13
+ * @PreHook("save", (car: CarModel, next) => {
14
+ * if (car.model === 'Tesla') {
15
+ * car.isFast = true;
16
+ * }
17
+ * next();
18
+ *})
19
+ * export class CarModel {
20
+ *
21
+ * @Ignore()
22
+ * _id: string;
23
+ *
24
+ * @Required()
25
+ * model: string;
26
+ *
27
+ * @Required()
28
+ * isFast: boolean;
29
+ *
30
+ * // or Prehook on static method
31
+ * @PreHook("save")
32
+ * static preSave(car: CarModel, next) {
33
+ * if (car.model === 'Tesla') {
34
+ * car.isFast = true;
35
+ * }
36
+ * next();
37
+ * }
38
+ * }
39
+ * ```
40
+ *
41
+ * This will execute the pre-save hook each time a `CarModel` document is saved.
42
+ *
43
+ * @param {string} method
44
+ * @param fn
45
+ * @param options
46
+ * @returns {Function}
47
+ * @decorator
48
+ * @class
49
+ */
50
+ export function PreHook(method, fn, options) {
51
+ return (...args) => {
52
+ if (decoratorTypeOf(args) === DecoratorTypes.METHOD_STC) {
53
+ options = fn;
54
+ fn = args[0][args[1]].bind(args[0]);
55
+ }
56
+ schemaOptions(args[0], {
57
+ pre: [
58
+ {
59
+ method,
60
+ fn: fn,
61
+ options
62
+ }
63
+ ]
64
+ });
65
+ };
66
+ }
67
+ //# sourceMappingURL=preHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preHook.js","sourceRoot":"","sources":["../../../src/decorators/preHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAC,MAAM,YAAY,CAAC;AAE3D,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,UAAU,OAAO,CAAU,MAAc,EAAE,EAA+C,EAAE,OAA6B;IAC7H,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE;QACxB,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,cAAc,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,aAAa,CAAC,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","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"]}
@@ -0,0 +1,71 @@
1
+ import { isArrowFn, isObject, isString, StoreMerge, useDecorators } from "@tsed/core";
2
+ import { OnDeserialize, OnSerialize, serialize } from "@tsed/json-mapper";
3
+ import { ForwardGroups, JsonEntityFn, lazyRef, matchGroups, OneOf, Property, string } from "@tsed/schema";
4
+ import { Schema as MongooseSchema } from "mongoose";
5
+ import { MONGOOSE_SCHEMA } from "../constants";
6
+ import { MongooseSchemaTypes } from "../interfaces/MongooseSchemaTypes";
7
+ import { MongooseModels } from "../registries/MongooseModels";
8
+ function isRef(value) {
9
+ return (value && value._bsontype) || isString(value);
10
+ }
11
+ function PopulateGroups(populatedGroups) {
12
+ return useDecorators(ForwardGroups(true), JsonEntityFn((store) => {
13
+ store.schema.$hooks.on("oneOf", (obj, givenGroups) => {
14
+ if (matchGroups(populatedGroups, givenGroups)) {
15
+ return obj.filter((x) => x.type === "string"); // keep the object id;
16
+ }
17
+ else {
18
+ return obj.filter((x) => x.type !== "string"); // keep the ref definition
19
+ }
20
+ });
21
+ }));
22
+ }
23
+ /**
24
+ * Define a property as mongoose reference to other Model (decorated with @Model).
25
+ *
26
+ * ### Example
27
+ *
28
+ * ```typescript
29
+ *
30
+ * @Model()
31
+ * class FooModel {
32
+ *
33
+ * @Ref(Foo2Model)
34
+ * field: Ref<Foo2Model>
35
+ *
36
+ * @Ref(Foo2Model)
37
+ * list: Ref<Foo2Model>[]
38
+ * }
39
+ *
40
+ * @Model()
41
+ * class Foo2Model {
42
+ * }
43
+ * ```
44
+ *
45
+ * @param model
46
+ * @param options
47
+ * @returns {Function}
48
+ * @decorator
49
+ * @mongoose
50
+ * @property
51
+ */
52
+ export function Ref(model, options = MongooseSchemaTypes.OBJECT_ID) {
53
+ const getType = () => (isString(model) ? MongooseModels.get(model) : isArrowFn(model) ? model() : model);
54
+ const populatedGroups = (isObject(options) && options.populatedGroups) || [];
55
+ return useDecorators(Property(Object), StoreMerge(MONGOOSE_SCHEMA, {
56
+ type: MongooseSchema.Types[isObject(options) ? options.type || MongooseSchemaTypes.OBJECT_ID : options],
57
+ ref: model
58
+ }), OnDeserialize((value) => {
59
+ if (isRef(value)) {
60
+ return value.toString();
61
+ }
62
+ return value;
63
+ }), OnSerialize((value, ctx) => {
64
+ if (isRef(value)) {
65
+ return value.toString();
66
+ }
67
+ const type = getType();
68
+ return serialize(value, { ...ctx, type });
69
+ }), OneOf(string().example("5ce7ad3028890bd71749d477").description("Mongoose Ref ObjectId"), lazyRef(getType)), populatedGroups.length && PopulateGroups(populatedGroups));
70
+ }
71
+ //# sourceMappingURL=ref.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/decorators/ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAQ,aAAa,EAAC,MAAM,YAAY,CAAC;AAC1F,OAAO,EAAC,aAAa,EAAE,WAAW,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAC,aAAa,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAC,MAAM,cAAc,CAAC;AACxG,OAAO,EAAC,MAAM,IAAI,cAAc,EAAC,MAAM,UAAU,CAAC;AAClD,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAC,mBAAmB,EAAC,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAC,cAAc,EAAC,MAAM,8BAA8B,CAAC;AAO5D,SAAS,KAAK,CAAC,KAA+B;IAC5C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,cAAc,CAAC,eAAyB;IAC/C,OAAO,aAAa,CAClB,aAAa,CAAC,IAAI,CAAC,EACnB,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE;QACrB,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,WAAqB,EAAE,EAAE;YACpE,IAAI,WAAW,CAAC,eAAe,EAAE,WAAW,CAAC,EAAE;gBAC7C,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,sBAAsB;aACtE;iBAAM;gBACL,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,0BAA0B;aAC1E;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,GAAG,CACjB,KAAkC,EAClC,UAA4C,mBAAmB,CAAC,SAAS;IAEzE,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACzG,MAAM,eAAe,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;IAE7E,OAAO,aAAa,CAClB,QAAQ,CAAC,MAAM,CAAC,EAChB,UAAU,CAAC,eAAe,EAAE;QAC1B,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;QACvG,GAAG,EAAE,KAAK;KACX,CAAC,EACF,aAAa,CAAC,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,WAAW,CAAC,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,SAAS,CAAC,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,IAAI,EAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,EACF,KAAK,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC,WAAW,CAAC,uBAAuB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,EAC1G,eAAe,CAAC,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,CACrC,CAAC;AACzB,CAAC","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"]}
@@ -0,0 +1,27 @@
1
+ import { decoratorTypeOf, StoreMerge, useDecorators } from "@tsed/core";
2
+ import { registerProvider } from "@tsed/di";
3
+ import { Property } from "@tsed/schema";
4
+ import { MONGOOSE_SCHEMA } from "../constants";
5
+ import { getSchema, getSchemaToken } from "../utils/createSchema";
6
+ export function Schema(options = {}) {
7
+ return (...parameters) => {
8
+ switch (decoratorTypeOf(parameters)) {
9
+ case "property":
10
+ return useDecorators(Property(), StoreMerge(MONGOOSE_SCHEMA, options))(parameters[0], parameters[1], parameters[2]);
11
+ case "class":
12
+ const { token } = getSchemaToken(parameters[0], options);
13
+ registerProvider({
14
+ provide: token,
15
+ deps: [],
16
+ useFactory() {
17
+ return getSchema(parameters[0], options);
18
+ }
19
+ });
20
+ break;
21
+ }
22
+ };
23
+ }
24
+ export function MongooseSchema(options = {}) {
25
+ return Schema(options);
26
+ }
27
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/decorators/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,UAAU,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACtE,OAAO,EAAC,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAC,SAAS,EAAE,cAAc,EAAC,MAAM,uBAAuB,CAAC;AA4BhE,MAAM,UAAU,MAAM,CAAC,UAA0D,EAAE;IACjF,OAAO,CAAC,GAAG,UAAiB,EAAE,EAAE;QAC9B,QAAQ,eAAe,CAAC,UAAU,CAAC,EAAE;YACnC,KAAK,UAAU;gBACb,OAAO,aAAa,CAAC,QAAQ,EAAE,EAAE,UAAU,CAAC,eAAe,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,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;gBAEvD,gBAAgB,CAAC;oBACf,OAAO,EAAE,KAAK;oBACd,IAAI,EAAE,EAAE;oBACR,UAAU;wBACR,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,OAAc,CAAC,CAAC;oBAClD,CAAC;iBACF,CAAC,CAAC;gBACH,MAAM;SACT;IACH,CAAC,CAAC;AACJ,CAAC;AA4BD,MAAM,UAAU,cAAc,CAAC,UAA0D,EAAE;IACzF,OAAO,MAAM,CAAC,OAAc,CAAC,CAAC;AAChC,CAAC","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"]}
@@ -0,0 +1,23 @@
1
+ import { MongooseSchema } from "./schema";
2
+ /**
3
+ * Do not apply this property to schema (create virtual property)
4
+ *
5
+ * ### Example
6
+ *
7
+ * ```typescript
8
+ * @Model()
9
+ * @SchemaIgnore()
10
+ * @Property()
11
+ * kind: string;
12
+ *
13
+ * ```
14
+ *
15
+ * @returns {Function}
16
+ * @decorator
17
+ * @mongoose
18
+ * @class
19
+ */
20
+ export function SchemaIgnore() {
21
+ return MongooseSchema({ schemaIgnore: true });
22
+ }
23
+ //# sourceMappingURL=schemaIgnore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaIgnore.js","sourceRoot":"","sources":["../../../src/decorators/schemaIgnore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,UAAU,YAAY;IAC1B,OAAO,cAAc,CAAC,EAAC,YAAY,EAAE,IAAI,EAAQ,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * Do not apply this property to schema (create virtual property)\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * @SchemaIgnore()\n * @Property()\n * kind: string;\n *\n * ```\n *\n * @returns {Function}\n * @decorator\n * @mongoose\n * @class\n */\n\nexport function SchemaIgnore(): Function {\n return MongooseSchema({schemaIgnore: true} as any);\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import { MongooseSchema } from "./schema";
2
+ /**
3
+ * Tell Mongoose to set default select() behavior for this path.
4
+ *
5
+ * ### Example
6
+ *
7
+ * ```typescript
8
+ * @Model()
9
+ * export class EventModel {
10
+ * @Select()
11
+ * field: string;
12
+ * }
13
+ * ```
14
+ *
15
+ * @param {boolean | any} select
16
+ * @returns {Function}
17
+ * @decorator
18
+ * @mongoose
19
+ * @property
20
+ */
21
+ export function Select(select = true) {
22
+ return MongooseSchema({ select });
23
+ }
24
+ //# sourceMappingURL=select.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select.js","sourceRoot":"","sources":["../../../src/decorators/select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,MAAM,CAAC,SAAwB,IAAI;IACjD,OAAO,cAAc,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC;AAClC,CAAC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * Tell Mongoose to set default select() behavior for this path.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Select()\n * field: string;\n * }\n * ```\n *\n * @param {boolean | any} select\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Select(select: boolean | any = true) {\n return MongooseSchema({select});\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import { MongooseSchema } from "./schema";
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
+ * @Sparse()
13
+ * field: string;
14
+ * }
15
+ * ```
16
+ *
17
+ * @param {boolean | number} sparse
18
+ * @returns {Function}
19
+ * @decorator
20
+ * @mongoose
21
+ * @property
22
+ */
23
+ export function Sparse(sparse = true) {
24
+ return MongooseSchema({ sparse });
25
+ }
26
+ //# sourceMappingURL=sparse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sparse.js","sourceRoot":"","sources":["../../../src/decorators/sparse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,MAAM,CAAC,SAA2B,IAAI;IACpD,OAAO,cAAc,CAAC,EAAC,MAAM,EAAQ,CAAC,CAAC;AACzC,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 * @Sparse()\n * field: string;\n * }\n * ```\n *\n * @param {boolean | number} sparse\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Sparse(sparse: boolean | number = true): PropertyDecorator {\n return MongooseSchema({sparse} as any);\n}\n"]}
@@ -0,0 +1,25 @@
1
+ import { MongooseSchema } from "./schema";
2
+ /**
3
+ * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose
4
+ * will build a text index on this path.
5
+ *
6
+ * ### Example
7
+ *
8
+ * ```typescript
9
+ * @Model()
10
+ * export class EventModel {
11
+ * @Text()
12
+ * field: string;
13
+ * }
14
+ * ```
15
+ *
16
+ * @param {boolean | number | any} text
17
+ * @returns {Function}
18
+ * @decorator
19
+ * @mongoose
20
+ * @property
21
+ */
22
+ export function Text(text = true) {
23
+ return MongooseSchema({ text });
24
+ }
25
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/decorators/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,IAAI,CAAC,OAA+B,IAAI;IACtD,OAAO,cAAc,CAAC,EAAC,IAAI,EAAQ,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose\n * will build a text index on this path.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Text()\n * field: string;\n * }\n * ```\n *\n * @param {boolean | number | any} text\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Text(text: boolean | number | any = true): PropertyDecorator {\n return MongooseSchema({text} as any);\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import { MongooseSchema } from "./schema";
2
+ /**
3
+ * Tell Mongoose to make the property trimmable.
4
+ *
5
+ * ### Example
6
+ *
7
+ * ```typescript
8
+ * @Model()
9
+ * export class EventModel {
10
+ * @Trim()
11
+ * name: string;
12
+ * }
13
+ * ```
14
+ *
15
+ * @returns {Function}
16
+ * @decorator
17
+ * @mongoose
18
+ * @property
19
+ */
20
+ export function Trim() {
21
+ return MongooseSchema({ trim: true });
22
+ }
23
+ //# sourceMappingURL=trim.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trim.js","sourceRoot":"","sources":["../../../src/decorators/trim.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,IAAI;IAClB,OAAO,cAAc,CAAC,EAAC,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * Tell Mongoose to make the property trimmable.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Trim()\n * name: string;\n * }\n * ```\n *\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Trim() {\n return MongooseSchema({trim: true});\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import { MongooseSchema } from "./schema";
2
+ /**
3
+ * Tell Mongoose to ensure a unique index is created for this path.
4
+ *
5
+ * ### Example
6
+ *
7
+ * ```typescript
8
+ * @Model()
9
+ * export class EventModel {
10
+ * @Unique()
11
+ * index: string;
12
+ * }
13
+ * ```
14
+ *
15
+ * @param {boolean | any} unique
16
+ * @returns {Function}
17
+ * @decorator
18
+ * @mongoose
19
+ */
20
+ export function Unique(unique = true) {
21
+ return MongooseSchema({ unique });
22
+ }
23
+ //# sourceMappingURL=unique.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unique.js","sourceRoot":"","sources":["../../../src/decorators/unique.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,MAAM,CAAC,SAAwB,IAAI;IACjD,OAAO,cAAc,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC;AAClC,CAAC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * Tell Mongoose to ensure a unique index is created for this path.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Unique()\n * index: string;\n * }\n * ```\n *\n * @param {boolean | any} unique\n * @returns {Function}\n * @decorator\n * @mongoose\n */\nexport function Unique(unique: boolean | any = true) {\n return MongooseSchema({unique});\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import { MongooseSchema } from "./schema";
2
+ /**
3
+ * If truthy, Mongoose will add a custom setter that uppercases this string using JavaScript's built-in String#toUpperCase().
4
+ *
5
+ * ### Example
6
+ *
7
+ * ```typescript
8
+ * @Model()
9
+ * export class EventModel {
10
+ * @Uppercase()
11
+ * field: string;
12
+ * }
13
+ * ```
14
+ *
15
+ * @param {boolean} uppercase
16
+ * @returns {Function}
17
+ * @decorator
18
+ * @mongoose
19
+ * @property
20
+ */
21
+ export function Uppercase(uppercase = true) {
22
+ return MongooseSchema({ uppercase });
23
+ }
24
+ //# sourceMappingURL=uppercase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uppercase.js","sourceRoot":"","sources":["../../../src/decorators/uppercase.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 uppercases this string using JavaScript's built-in String#toUpperCase().\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Uppercase()\n * field: string;\n * }\n * ```\n *\n * @param {boolean} uppercase\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Uppercase(uppercase: boolean = true): PropertyDecorator {\n return MongooseSchema({uppercase} as any);\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { Store } from "@tsed/core";
2
+ import { MONGOOSE_SCHEMA_OPTIONS } from "../constants";
3
+ export function VersionKey() {
4
+ return (target, propertyKey) => {
5
+ Store.from(target).merge(MONGOOSE_SCHEMA_OPTIONS, { versionKey: propertyKey });
6
+ };
7
+ }
8
+ //# sourceMappingURL=versionKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"versionKey.js","sourceRoot":"","sources":["../../../src/decorators/versionKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AACjC,OAAO,EAAC,uBAAuB,EAAC,MAAM,cAAc,CAAC;AAErD,MAAM,UAAU,UAAU;IACxB,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,uBAAuB,EAAE,EAAC,UAAU,EAAE,WAAW,EAAC,CAAC,CAAC;IAC/E,CAAC,CAAC;AACJ,CAAC","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"]}
@@ -0,0 +1,34 @@
1
+ import { isPlainObject, isString, Store, StoreMerge, useDecorators } from "@tsed/core";
2
+ import { CollectionOf, Property } from "@tsed/schema";
3
+ import { MONGOOSE_MODEL_NAME, MONGOOSE_SCHEMA } from "../constants";
4
+ import { MongooseModels } from "../registries/MongooseModels";
5
+ function getRef(opts) {
6
+ const ref = opts.ref;
7
+ return isString(ref) ? ref : Store.from(ref).get(MONGOOSE_MODEL_NAME);
8
+ }
9
+ function getType(opts) {
10
+ const ref = opts.ref;
11
+ return !isString(ref) ? ref : MongooseModels.get(ref) || (() => MongooseModels.get(ref) || Object);
12
+ }
13
+ function getInitialOpts(options, foreignField) {
14
+ return isPlainObject(options) ? options : { ref: options, foreignField };
15
+ }
16
+ function mapToSchema(opts) {
17
+ const ref = getRef(opts);
18
+ const schema = {
19
+ ref,
20
+ localField: opts.localField || "_id",
21
+ foreignField: opts.foreignField,
22
+ justOne: opts.justOne || false,
23
+ count: opts.count || false,
24
+ options: opts.options
25
+ };
26
+ return schema;
27
+ }
28
+ export function VirtualRef(options, foreignField) {
29
+ const opts = getInitialOpts(options, foreignField);
30
+ const schema = mapToSchema(opts);
31
+ const type = getType(opts);
32
+ return useDecorators(StoreMerge(MONGOOSE_SCHEMA, schema), schema.count ? Property(Number) : type && (schema.justOne ? Property(type) : CollectionOf(type)));
33
+ }
34
+ //# sourceMappingURL=virtualRef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"virtualRef.js","sourceRoot":"","sources":["../../../src/decorators/virtualRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACrF,OAAO,EAAC,YAAY,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AACpD,OAAO,EAAC,mBAAmB,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC;AAElE,OAAO,EAAC,cAAc,EAAC,MAAM,8BAA8B,CAAC;AAE5D,SAAS,MAAM,CAAC,IAAS;IACvB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IAErB,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,OAAO,CAAC,IAAS;IACxB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IACrB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,CAAC;AACrG,CAAC;AAED,SAAS,cAAc,CAAC,OAA2C,EAAE,YAAqB;IACxF,OAAO,aAAa,CAAC,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,MAAM,UAAU,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,aAAa,CAClB,UAAU,CAAC,eAAe,EAAE,MAAM,CAAC,EACnC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CACjG,CAAC;AACJ,CAAC","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"]}
@@ -0,0 +1,7 @@
1
+ export * from "./interfaces";
2
+ export * from "./constants";
3
+ export * from "./services/MongooseService";
4
+ export * from "./MongooseModule";
5
+ export * from "./utils";
6
+ export * from "./decorators";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC","sourcesContent":["export * from \"./interfaces\";\nexport * from \"./constants\";\nexport * from \"./services/MongooseService\";\nexport * from \"./MongooseModule\";\nexport * from \"./utils\";\nexport * from \"./decorators\";\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=MongooseConnectionOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MongooseConnectionOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseConnectionOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {ConnectOptions} from \"mongoose\";\n\nexport interface MongooseConnectionOptions {\n url: string;\n /**\n * The connection ID\n */\n id: string;\n connectionOptions?: ConnectOptions;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=MongooseDocument.js.map