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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +29 -23
  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,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NumberDecimal = exports.DecimalFormat = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const ajv_1 = require("@tsed/ajv");
6
+ const core_1 = require("@tsed/core");
7
+ const json_mapper_1 = require("@tsed/json-mapper");
8
+ const schema_1 = require("@tsed/schema");
9
+ const mongoose_1 = require("mongoose");
10
+ const constants_1 = require("../constants/constants");
11
+ let DecimalFormat = class DecimalFormat {
12
+ validate(num) {
13
+ return (0, core_1.isString)(num) || (0, core_1.isNumber)(num);
14
+ }
15
+ };
16
+ DecimalFormat = tslib_1.__decorate([
17
+ (0, ajv_1.Formats)("decimal", { type: "number" })
18
+ ], DecimalFormat);
19
+ exports.DecimalFormat = DecimalFormat;
20
+ function isDecimal(value) {
21
+ return value && value._bsontype === "Decimal128";
22
+ }
23
+ /**
24
+ * Tell Mongoose whether to define an Decimal128 property.
25
+ * Will be serialized as `number` with format as `decimal`.
26
+ * ### Example
27
+ *
28
+ * ```typescript
29
+ * @Model()
30
+ * export class PriceModel {
31
+ * @NumberDecimal()
32
+ * price: Decimal128;
33
+ * }
34
+ * ```
35
+ * Optionally using custom decimal type, such as `Big` from big.js
36
+ * ```typescript
37
+ * @Model()
38
+ * export class PriceModel {
39
+ * @NumberDecimal(Big)
40
+ * price: Big;
41
+ * }
42
+ * ```
43
+ * @param type Optional decimal type constructor
44
+ * @decorator
45
+ * @mongoose
46
+ * @schema
47
+ */
48
+ function NumberDecimal(type) {
49
+ const schema = {
50
+ type: mongoose_1.Schema.Types.Decimal128
51
+ };
52
+ if (type) {
53
+ // Define property getter to convert Decimal128 to custom type
54
+ schema.get = (value) => {
55
+ return isDecimal(value) ? new type(value) : value;
56
+ };
57
+ }
58
+ return (0, core_1.useDecorators)((0, schema_1.Property)(Number), (0, schema_1.Format)("decimal"), (0, schema_1.Example)(12.34), (0, core_1.StoreMerge)(constants_1.MONGOOSE_SCHEMA, schema),
59
+ // Deserialize number value from JSON to Decimal128
60
+ (0, json_mapper_1.OnDeserialize)((value) => {
61
+ if (value === undefined) {
62
+ return undefined;
63
+ }
64
+ if (type) {
65
+ return new type(value);
66
+ }
67
+ if ((0, core_1.isString)(value)) {
68
+ return mongoose_1.Types.Decimal128.fromString(value);
69
+ }
70
+ return mongoose_1.Types.Decimal128.fromString(`${value}`);
71
+ }),
72
+ // Serialize decimal value to floating point number
73
+ (0, json_mapper_1.OnSerialize)((value, ctx) => {
74
+ return value && Number(value);
75
+ }));
76
+ }
77
+ exports.NumberDecimal = NumberDecimal;
78
+ //# sourceMappingURL=numberDecimal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numberDecimal.js","sourceRoot":"","sources":["../../../src/decorators/numberDecimal.ts"],"names":[],"mappings":";;;;AAAA,mCAAkD;AAClD,qCAAyE;AACzE,mDAA6D;AAC7D,yCAAuD;AACvD,uCAA4E;AAC5E,sDAAuD;AAGvD,IAAa,aAAa,GAA1B,MAAa,aAAa;IACxB,QAAQ,CAAC,GAAoB;QAC3B,OAAO,IAAA,eAAQ,EAAC,GAAG,CAAC,IAAI,IAAA,eAAQ,EAAC,GAAG,CAAC,CAAC;IACxC,CAAC;CACF,CAAA;AAJY,aAAa;IADzB,IAAA,aAAO,EAAC,SAAS,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC,CAAC;GACxB,aAAa,CAIzB;AAJY,sCAAa;AAM1B,SAAS,SAAS,CAAC,KAA+B;IAChD,OAAO,KAAK,IAAI,KAAK,CAAC,SAAS,KAAK,YAAY,CAAC;AACnD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,aAAa,CAAC,IAAU;IACtC,MAAM,MAAM,GAAkC;QAC5C,IAAI,EAAE,iBAAc,CAAC,KAAK,CAAC,UAAU;KACtC,CAAC;IAEF,IAAI,IAAI,EAAE;QACR,8DAA8D;QAC9D,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,EAAE,EAAE;YACrB,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACpD,CAAC,CAAC;KACH;IAED,OAAO,IAAA,oBAAa,EAClB,IAAA,iBAAQ,EAAC,MAAM,CAAC,EAChB,IAAA,eAAM,EAAC,SAAS,CAAC,EACjB,IAAA,gBAAO,EAAC,KAAK,CAAC,EACd,IAAA,iBAAU,EAAC,2BAAe,EAAE,MAAM,CAAC;IAEnC,mDAAmD;IACnD,IAAA,2BAAa,EAAC,CAAC,KAAK,EAAE,EAAE;QACtB,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,OAAO,SAAS,CAAC;SAClB;QACD,IAAI,IAAI,EAAE;YACR,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;SACxB;QACD,IAAI,IAAA,eAAQ,EAAC,KAAK,CAAC,EAAE;YACnB,OAAO,gBAAK,CAAC,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;SAC3C;QACD,OAAO,gBAAK,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;IACjD,CAAC,CAAC;IAEF,mDAAmD;IACnD,IAAA,yBAAW,EAAC,CAAC,KAAU,EAAE,GAAG,EAAE,EAAE;QAC9B,OAAO,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AArCD,sCAqCC","sourcesContent":["import {Formats, FormatsMethods} from \"@tsed/ajv\";\nimport {isNumber, isString, StoreMerge, useDecorators} from \"@tsed/core\";\nimport {OnDeserialize, OnSerialize} from \"@tsed/json-mapper\";\nimport {Example, Format, Property} from \"@tsed/schema\";\nimport {Types, Schema as MongooseSchema, SchemaTypeOptions} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants/constants\";\n\n@Formats(\"decimal\", {type: \"number\"})\nexport class DecimalFormat implements FormatsMethods<string | number> {\n validate(num: string | number): boolean {\n return isString(num) || isNumber(num);\n }\n}\n\nfunction isDecimal(value: undefined | number | any) {\n return value && value._bsontype === \"Decimal128\";\n}\n\n/**\n * Tell Mongoose whether to define an Decimal128 property.\n * Will be serialized as `number` with format as `decimal`.\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class PriceModel {\n * @NumberDecimal()\n * price: Decimal128;\n * }\n * ```\n * Optionally using custom decimal type, such as `Big` from big.js\n * ```typescript\n * @Model()\n * export class PriceModel {\n * @NumberDecimal(Big)\n * price: Big;\n * }\n * ```\n * @param type Optional decimal type constructor\n * @decorator\n * @mongoose\n * @schema\n */\nexport function NumberDecimal(type?: any) {\n const schema: SchemaTypeOptions<Decimal128> = {\n type: MongooseSchema.Types.Decimal128\n };\n\n if (type) {\n // Define property getter to convert Decimal128 to custom type\n schema.get = (value) => {\n return isDecimal(value) ? new type(value) : value;\n };\n }\n\n return useDecorators(\n Property(Number),\n Format(\"decimal\"),\n Example(12.34),\n StoreMerge(MONGOOSE_SCHEMA, schema),\n\n // Deserialize number value from JSON to Decimal128\n OnDeserialize((value) => {\n if (value === undefined) {\n return undefined;\n }\n if (type) {\n return new type(value);\n }\n if (isString(value)) {\n return Types.Decimal128.fromString(value);\n }\n return Types.Decimal128.fromString(`${value}`);\n }),\n\n // Serialize decimal value to floating point number\n OnSerialize((value: any, ctx) => {\n return value && Number(value);\n })\n );\n}\n\nexport type Decimal128 = Types.Decimal128;\n"]}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ObjectID = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ const schema_1 = require("@tsed/schema");
6
+ /**
7
+ * Tell Mongoose whether to define an ObjectId property.
8
+ * ### Example
9
+ *
10
+ * ```typescript
11
+ * @Model()
12
+ * export class EventModel {
13
+ * @ObjectId('id')
14
+ * _id: string;
15
+ * }
16
+ * ```
17
+ * @param name
18
+ * @decorator
19
+ * @mongoose
20
+ * @schema
21
+ */
22
+ function ObjectID(name) {
23
+ return (0, core_1.useDecorators)(name && (0, schema_1.Name)(name), (0, schema_1.Pattern)(/^[0-9a-fA-F]{24}$/), (0, schema_1.Description)("Mongoose ObjectId"), (0, schema_1.Example)("5ce7ad3028890bd71749d477"));
24
+ }
25
+ exports.ObjectID = ObjectID;
26
+ //# sourceMappingURL=objectID.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectID.js","sourceRoot":"","sources":["../../../src/decorators/objectID.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACzC,yCAAiE;AAGjE;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,QAAQ,CAAC,IAAa;IACpC,OAAO,IAAA,oBAAa,EAClB,IAAI,IAAI,IAAA,aAAI,EAAC,IAAI,CAAC,EAClB,IAAA,gBAAO,EAAC,mBAAmB,CAAC,EAC5B,IAAA,oBAAW,EAAC,mBAAmB,CAAC,EAChC,IAAA,gBAAO,EAAC,0BAA0B,CAAC,CACpC,CAAC;AACJ,CAAC;AAPD,4BAOC","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,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PostHook = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ const schemaOptions_1 = require("../utils/schemaOptions");
6
+ function PostHook(method, ...params) {
7
+ return ((...args) => {
8
+ let options = params[1];
9
+ let fn = params[0];
10
+ if ((0, core_1.decoratorTypeOf)(args) === core_1.DecoratorTypes.METHOD_STC) {
11
+ options = params[0];
12
+ fn = args[0][args[1]].bind(args[0]);
13
+ }
14
+ (0, schemaOptions_1.schemaOptions)(args[0], {
15
+ post: [
16
+ {
17
+ method,
18
+ fn,
19
+ options
20
+ }
21
+ ]
22
+ });
23
+ });
24
+ }
25
+ exports.PostHook = PostHook;
26
+ //# sourceMappingURL=postHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postHook.js","sourceRoot":"","sources":["../../../src/decorators/postHook.ts"],"names":[],"mappings":";;;AAAA,qCAAkF;AAElF,0DAAqD;AAgDrD,SAAgB,QAAQ,CAAU,MAAc,EAAE,GAAG,MAAa;IAChE,OAAO,CAAC,CAAC,GAAG,IAAW,EAAE,EAAE;QACzB,IAAI,OAAO,GAAwB,MAAM,CAAC,CAAC,CAAC,CAAC;QAC7C,IAAI,EAAE,GAA0B,MAAM,CAAC,CAAC,CAAC,CAAC;QAE1C,IAAI,IAAA,sBAAe,EAAC,IAAI,CAAC,KAAK,qBAAc,CAAC,UAAU,EAAE;YACvD,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACpB,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACrC;QAED,IAAA,6BAAa,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YACrB,IAAI,EAAE;gBACJ;oBACE,MAAM;oBACN,EAAE;oBACF,OAAO;iBACR;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAQ,CAAC;AACZ,CAAC;AApBD,4BAoBC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, StaticMethodDecorator} from \"@tsed/core\";\nimport {MongooseHookOptions, MongoosePostHookCB} from \"../interfaces/MongooseSchemaOptions\";\nimport {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n * We can simply attach a `@PostHook` decorator to your model class and\n * define the hook function like you normally would in Mongoose.\n *\n * ```typescript\n * import {Ignore, Required} from \"@tsed/common\";\n * import {PostHook, Model} from \"@tsed/mongoose\";\n *\n * @Model()\n * @PostHook(\"save\", (car: CarModel) => {\n * if (car.topSpeedInKmH > 300) {\n * console.log(car.model, 'is fast!');\n * }\n * })\n * export class CarModel {\n * @Ignore()\n * _id: string;\n *\n * @Required()\n * model: string;\n *\n * @Required()\n * isFast: boolean;\n *\n * // or Prehook on static method\n * @PostHook(\"save\")\n * static postSave(car: CarModel) {\n * if (car.topSpeedInKmH > 300) {\n * console.log(car.model, 'is fast!');\n * }\n * }\n * }\n * ```\n *\n * This will execute the post-save hook each time a `CarModel` document is saved.\n *\n * @param {string} method\n * @param fn\n * @returns {Function}\n * @decorator\n * @mongoose\n * @class\n */\nexport function PostHook<T = any>(method: string, fn: MongoosePostHookCB<T>): ClassDecorator;\nexport function PostHook<T = any>(method: string, fn: MongoosePostHookCB<T>, options: MongooseHookOptions): ClassDecorator;\nexport function PostHook<T = any>(method: string, options: MongooseHookOptions): StaticMethodDecorator;\nexport function PostHook<T = any>(method: string, ...params: any[]): Function {\n return ((...args: any[]) => {\n let options: MongooseHookOptions = params[1];\n let fn: MongoosePostHookCB<T> = params[0];\n\n if (decoratorTypeOf(args) === DecoratorTypes.METHOD_STC) {\n options = params[0];\n fn = args[0][args[1]].bind(args[0]);\n }\n\n schemaOptions(args[0], {\n post: [\n {\n method,\n fn,\n options\n }\n ]\n });\n }) as any;\n}\n"]}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PreHook = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ const schemaOptions_1 = require("../utils/schemaOptions");
6
+ /**
7
+ *
8
+ * We can simply attach a `@PreHook` decorator to your model class and
9
+ * define the hook function like you normally would in Mongoose.
10
+ *
11
+ * ```typescript
12
+ * import {Ignore, Required} from "@tsed/common";
13
+ * import {PreHook, Model} from "@tsed/mongoose";
14
+ *
15
+ * @Model()
16
+ * @PreHook("save", (car: CarModel, next) => {
17
+ * if (car.model === 'Tesla') {
18
+ * car.isFast = true;
19
+ * }
20
+ * next();
21
+ *})
22
+ * export class CarModel {
23
+ *
24
+ * @Ignore()
25
+ * _id: string;
26
+ *
27
+ * @Required()
28
+ * model: string;
29
+ *
30
+ * @Required()
31
+ * isFast: boolean;
32
+ *
33
+ * // or Prehook on static method
34
+ * @PreHook("save")
35
+ * static preSave(car: CarModel, next) {
36
+ * if (car.model === 'Tesla') {
37
+ * car.isFast = true;
38
+ * }
39
+ * next();
40
+ * }
41
+ * }
42
+ * ```
43
+ *
44
+ * This will execute the pre-save hook each time a `CarModel` document is saved.
45
+ *
46
+ * @param {string} method
47
+ * @param fn
48
+ * @param options
49
+ * @returns {Function}
50
+ * @decorator
51
+ * @class
52
+ */
53
+ function PreHook(method, fn, options) {
54
+ return (...args) => {
55
+ if ((0, core_1.decoratorTypeOf)(args) === core_1.DecoratorTypes.METHOD_STC) {
56
+ options = fn;
57
+ fn = args[0][args[1]].bind(args[0]);
58
+ }
59
+ (0, schemaOptions_1.schemaOptions)(args[0], {
60
+ pre: [
61
+ {
62
+ method,
63
+ fn: fn,
64
+ options
65
+ }
66
+ ]
67
+ });
68
+ };
69
+ }
70
+ exports.PreHook = PreHook;
71
+ //# sourceMappingURL=preHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preHook.js","sourceRoot":"","sources":["../../../src/decorators/preHook.ts"],"names":[],"mappings":";;;AAAA,qCAA2D;AAE3D,0DAAqD;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,SAAgB,OAAO,CAAU,MAAc,EAAE,EAA+C,EAAE,OAA6B;IAC7H,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE;QACxB,IAAI,IAAA,sBAAe,EAAC,IAAI,CAAC,KAAK,qBAAc,CAAC,UAAU,EAAE;YACvD,OAAO,GAAG,EAAyB,CAAC;YACpC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACrC;QAED,IAAA,6BAAa,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YACrB,GAAG,EAAE;gBACH;oBACE,MAAM;oBACN,EAAE,EAAE,EAA0B;oBAC9B,OAAO;iBACR;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAjBD,0BAiBC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes} from \"@tsed/core\";\nimport {MongooseHookOptions, MongoosePreHookCB} from \"../interfaces/MongooseSchemaOptions\";\nimport {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n *\n * We can simply attach a `@PreHook` decorator to your model class and\n * define the hook function like you normally would in Mongoose.\n *\n * ```typescript\n * import {Ignore, Required} from \"@tsed/common\";\n * import {PreHook, Model} from \"@tsed/mongoose\";\n *\n * @Model()\n * @PreHook(\"save\", (car: CarModel, next) => {\n * if (car.model === 'Tesla') {\n * car.isFast = true;\n * }\n * next();\n *})\n * export class CarModel {\n *\n * @Ignore()\n * _id: string;\n *\n * @Required()\n * model: string;\n *\n * @Required()\n * isFast: boolean;\n *\n * // or Prehook on static method\n * @PreHook(\"save\")\n * static preSave(car: CarModel, next) {\n * if (car.model === 'Tesla') {\n * car.isFast = true;\n * }\n * next();\n * }\n * }\n * ```\n *\n * This will execute the pre-save hook each time a `CarModel` document is saved.\n *\n * @param {string} method\n * @param fn\n * @param options\n * @returns {Function}\n * @decorator\n * @class\n */\nexport function PreHook<T = any>(method: string, fn?: MongoosePreHookCB<T> | MongooseHookOptions, options?: MongooseHookOptions): Function {\n return (...args: any[]) => {\n if (decoratorTypeOf(args) === DecoratorTypes.METHOD_STC) {\n options = fn as MongooseHookOptions;\n fn = args[0][args[1]].bind(args[0]);\n }\n\n schemaOptions(args[0], {\n pre: [\n {\n method,\n fn: fn as MongoosePreHookCB<T>,\n options\n }\n ]\n });\n };\n}\n"]}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Ref = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ const json_mapper_1 = require("@tsed/json-mapper");
6
+ const schema_1 = require("@tsed/schema");
7
+ const mongoose_1 = require("mongoose");
8
+ const constants_1 = require("../constants/constants");
9
+ const MongooseSchemaTypes_1 = require("../interfaces/MongooseSchemaTypes");
10
+ const MongooseModels_1 = require("../registries/MongooseModels");
11
+ function isRef(value) {
12
+ return (value && value._bsontype) || (0, core_1.isString)(value);
13
+ }
14
+ function PopulateGroups(populatedGroups) {
15
+ return (0, core_1.useDecorators)((0, schema_1.ForwardGroups)(true), (0, schema_1.JsonEntityFn)((store) => {
16
+ store.schema.$hooks.on("oneOf", (obj, givenGroups) => {
17
+ if ((0, schema_1.matchGroups)(populatedGroups, givenGroups)) {
18
+ return obj.filter((x) => x.type === "string"); // keep the object id;
19
+ }
20
+ else {
21
+ return obj.filter((x) => x.type !== "string"); // keep the ref definition
22
+ }
23
+ });
24
+ }));
25
+ }
26
+ /**
27
+ * Define a property as mongoose reference to other Model (decorated with @Model).
28
+ *
29
+ * ### Example
30
+ *
31
+ * ```typescript
32
+ *
33
+ * @Model()
34
+ * class FooModel {
35
+ *
36
+ * @Ref(Foo2Model)
37
+ * field: Ref<Foo2Model>
38
+ *
39
+ * @Ref(Foo2Model)
40
+ * list: Ref<Foo2Model>[]
41
+ * }
42
+ *
43
+ * @Model()
44
+ * class Foo2Model {
45
+ * }
46
+ * ```
47
+ *
48
+ * @param model
49
+ * @param options
50
+ * @returns {Function}
51
+ * @decorator
52
+ * @mongoose
53
+ * @property
54
+ */
55
+ function Ref(model, options = MongooseSchemaTypes_1.MongooseSchemaTypes.OBJECT_ID) {
56
+ const getType = () => ((0, core_1.isString)(model) ? MongooseModels_1.MongooseModels.get(model) : (0, core_1.isArrowFn)(model) ? model() : model);
57
+ const populatedGroups = ((0, core_1.isObject)(options) && options.populatedGroups) || [];
58
+ return (0, core_1.useDecorators)((0, schema_1.Property)(Object), (0, core_1.StoreMerge)(constants_1.MONGOOSE_SCHEMA, {
59
+ type: mongoose_1.Schema.Types[(0, core_1.isObject)(options) ? options.type || MongooseSchemaTypes_1.MongooseSchemaTypes.OBJECT_ID : options],
60
+ ref: model
61
+ }), (0, json_mapper_1.OnDeserialize)((value) => {
62
+ if (isRef(value)) {
63
+ return value.toString();
64
+ }
65
+ return value;
66
+ }), (0, json_mapper_1.OnSerialize)((value, ctx) => {
67
+ if (isRef(value)) {
68
+ return value.toString();
69
+ }
70
+ const type = getType();
71
+ return (0, json_mapper_1.serialize)(value, { ...ctx, type });
72
+ }), (0, schema_1.OneOf)((0, schema_1.string)().example("5ce7ad3028890bd71749d477").description("Mongoose Ref ObjectId"), (0, schema_1.lazyRef)(getType)), populatedGroups.length && PopulateGroups(populatedGroups));
73
+ }
74
+ exports.Ref = Ref;
75
+ //# sourceMappingURL=ref.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/decorators/ref.ts"],"names":[],"mappings":";;;AAAA,qCAA0F;AAC1F,mDAAwE;AACxE,yCAAwG;AACxG,uCAAkD;AAClD,sDAAuD;AACvD,2EAAsE;AACtE,iEAA4D;AAO5D,SAAS,KAAK,CAAC,KAA+B;IAC5C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,cAAc,CAAC,eAAyB;IAC/C,OAAO,IAAA,oBAAa,EAClB,IAAA,sBAAa,EAAC,IAAI,CAAC,EACnB,IAAA,qBAAY,EAAC,CAAC,KAAK,EAAE,EAAE;QACrB,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,WAAqB,EAAE,EAAE;YACpE,IAAI,IAAA,oBAAW,EAAC,eAAe,EAAE,WAAW,CAAC,EAAE;gBAC7C,OAAO,GAAG,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,SAAgB,GAAG,CACjB,KAAkC,EAClC,UAA4C,yCAAmB,CAAC,SAAS;IAEzE,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,+BAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAA,gBAAS,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACzG,MAAM,eAAe,GAAG,CAAC,IAAA,eAAQ,EAAC,OAAO,CAAC,IAAI,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;IAE7E,OAAO,IAAA,oBAAa,EAClB,IAAA,iBAAQ,EAAC,MAAM,CAAC,EAChB,IAAA,iBAAU,EAAC,2BAAe,EAAE;QAC1B,IAAI,EAAE,iBAAc,CAAC,KAAK,CAAC,IAAA,eAAQ,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,yCAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;QACvG,GAAG,EAAE,KAAK;KACX,CAAC,EACF,IAAA,2BAAa,EAAC,CAAC,KAAK,EAAE,EAAE;QACtB,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzB;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,EACF,IAAA,yBAAW,EAAC,CAAC,KAAU,EAAE,GAAG,EAAE,EAAE;QAC9B,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzB;QACD,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;QAEvB,OAAO,IAAA,uBAAS,EAAC,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,IAAI,EAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,EACF,IAAA,cAAK,EAAC,IAAA,eAAM,GAAE,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC,WAAW,CAAC,uBAAuB,CAAC,EAAE,IAAA,gBAAO,EAAC,OAAO,CAAC,CAAC,EAC1G,eAAe,CAAC,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,CACrC,CAAC;AACzB,CAAC;AA/BD,kBA+BC","sourcesContent":["import {isArrowFn, isObject, isString, StoreMerge, Type, useDecorators} from \"@tsed/core\";\nimport {OnDeserialize, OnSerialize, serialize} from \"@tsed/json-mapper\";\nimport {ForwardGroups, JsonEntityFn, lazyRef, matchGroups, OneOf, Property, string} from \"@tsed/schema\";\nimport {Schema as MongooseSchema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants/constants\";\nimport {MongooseSchemaTypes} from \"../interfaces/MongooseSchemaTypes\";\nimport {MongooseModels} from \"../registries/MongooseModels\";\n\ninterface RefOptions {\n type?: MongooseSchemaTypes;\n populatedGroups?: string[];\n}\n\nfunction isRef(value: undefined | string | any) {\n return (value && value._bsontype) || isString(value);\n}\n\nfunction PopulateGroups(populatedGroups: string[]) {\n return useDecorators(\n ForwardGroups(true),\n JsonEntityFn((store) => {\n store.schema.$hooks.on(\"oneOf\", (obj: any[], givenGroups: string[]) => {\n if (matchGroups(populatedGroups, givenGroups)) {\n return obj.filter((x) => x.type === \"string\"); // keep the object id;\n } else {\n return obj.filter((x) => x.type !== \"string\"); // keep the ref definition\n }\n });\n })\n );\n}\n\n/**\n * Define a property as mongoose reference to other Model (decorated with @Model).\n *\n * ### Example\n *\n * ```typescript\n *\n * @Model()\n * class FooModel {\n *\n * @Ref(Foo2Model)\n * field: Ref<Foo2Model>\n *\n * @Ref(Foo2Model)\n * list: Ref<Foo2Model>[]\n * }\n *\n * @Model()\n * class Foo2Model {\n * }\n * ```\n *\n * @param model\n * @param options\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Ref(\n model: string | (() => Type) | any,\n options: RefOptions | MongooseSchemaTypes = MongooseSchemaTypes.OBJECT_ID\n): PropertyDecorator {\n const getType = () => (isString(model) ? MongooseModels.get(model) : isArrowFn(model) ? model() : model);\n const populatedGroups = (isObject(options) && options.populatedGroups) || [];\n\n return useDecorators(\n Property(Object),\n StoreMerge(MONGOOSE_SCHEMA, {\n type: MongooseSchema.Types[isObject(options) ? options.type || MongooseSchemaTypes.OBJECT_ID : options],\n ref: model\n }),\n OnDeserialize((value) => {\n if (isRef(value)) {\n return value.toString();\n }\n\n return value;\n }),\n OnSerialize((value: any, ctx) => {\n if (isRef(value)) {\n return value.toString();\n }\n const type = getType();\n\n return serialize(value, {...ctx, type});\n }),\n OneOf(string().example(\"5ce7ad3028890bd71749d477\").description(\"Mongoose Ref ObjectId\"), lazyRef(getType)),\n populatedGroups.length && PopulateGroups(populatedGroups)\n ) as PropertyDecorator;\n}\n\nexport type Ref<T> = T | string;\n"]}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongooseSchema = exports.Schema = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ const di_1 = require("@tsed/di");
6
+ const schema_1 = require("@tsed/schema");
7
+ const constants_1 = require("../constants/constants");
8
+ const createSchema_1 = require("../utils/createSchema");
9
+ function Schema(options = {}) {
10
+ return (...parameters) => {
11
+ switch ((0, core_1.decoratorTypeOf)(parameters)) {
12
+ case "property":
13
+ return (0, core_1.useDecorators)((0, schema_1.Property)(), (0, core_1.StoreMerge)(constants_1.MONGOOSE_SCHEMA, options))(parameters[0], parameters[1], parameters[2]);
14
+ case "class":
15
+ const { token } = (0, createSchema_1.getSchemaToken)(parameters[0], options);
16
+ (0, di_1.registerProvider)({
17
+ provide: token,
18
+ deps: [],
19
+ useFactory() {
20
+ return (0, createSchema_1.getSchema)(parameters[0], options);
21
+ }
22
+ });
23
+ break;
24
+ }
25
+ };
26
+ }
27
+ exports.Schema = Schema;
28
+ function MongooseSchema(options = {}) {
29
+ return Schema(options);
30
+ }
31
+ exports.MongooseSchema = MongooseSchema;
32
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/decorators/schema.ts"],"names":[],"mappings":";;;AAAA,qCAAsE;AACtE,iCAA0C;AAC1C,yCAAsC;AAEtC,sDAAuD;AAEvD,wDAAgE;AA4BhE,SAAgB,MAAM,CAAC,UAA0D,EAAE;IACjF,OAAO,CAAC,GAAG,UAAiB,EAAE,EAAE;QAC9B,QAAQ,IAAA,sBAAe,EAAC,UAAU,CAAC,EAAE;YACnC,KAAK,UAAU;gBACb,OAAO,IAAA,oBAAa,EAAC,IAAA,iBAAQ,GAAE,EAAE,IAAA,iBAAU,EAAC,2BAAe,EAAE,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;YAEtH,KAAK,OAAO;gBACV,MAAM,EAAC,KAAK,EAAC,GAAG,IAAA,6BAAc,EAAC,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;gBAEvD,IAAA,qBAAgB,EAAC;oBACf,OAAO,EAAE,KAAK;oBACd,IAAI,EAAE,EAAE;oBACR,UAAU;wBACR,OAAO,IAAA,wBAAS,EAAC,UAAU,CAAC,CAAC,CAAC,EAAE,OAAc,CAAC,CAAC;oBAClD,CAAC;iBACF,CAAC,CAAC;gBACH,MAAM;SACT;IACH,CAAC,CAAC;AACJ,CAAC;AAnBD,wBAmBC;AA4BD,SAAgB,cAAc,CAAC,UAA0D,EAAE;IACzF,OAAO,MAAM,CAAC,OAAc,CAAC,CAAC;AAChC,CAAC;AAFD,wCAEC","sourcesContent":["import {decoratorTypeOf, StoreMerge, useDecorators} from \"@tsed/core\";\nimport {registerProvider} from \"@tsed/di\";\nimport {Property} from \"@tsed/schema\";\nimport {SchemaTypeOptions} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants/constants\";\nimport {MongooseSchemaOptions} from \"../interfaces/MongooseSchemaOptions\";\nimport {getSchema, getSchemaToken} from \"../utils/createSchema\";\n\n/**\n * Define a class as a Mongoose Schema ready to be used to compose other schemes and models.\n *\n * ### Example\n *\n * ```typescript\n * @MongooseSchema()\n * export class EventSchema {\n * @Property()\n * field: string;\n * }\n * ```\n *\n * ### Options\n *\n * - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.\n *\n * @param {MongooseSchemaOptions | undefined} options\n * @returns {(target: any) => void}\n * @decorator\n * @mongoose\n * @property\n * @class\n */\nexport function Schema(options?: MongooseSchemaOptions): (target: any) => void;\nexport function Schema(definition: SchemaTypeOptions<any>): Function;\nexport function Schema(options: MongooseSchemaOptions | SchemaTypeOptions<any> = {}) {\n return (...parameters: any[]) => {\n switch (decoratorTypeOf(parameters)) {\n case \"property\":\n return useDecorators(Property(), StoreMerge(MONGOOSE_SCHEMA, options))(parameters[0], parameters[1], parameters[2]);\n\n case \"class\":\n const {token} = getSchemaToken(parameters[0], options);\n\n registerProvider({\n provide: token,\n deps: [],\n useFactory() {\n return getSchema(parameters[0], options as any);\n }\n });\n break;\n }\n };\n}\n\n/**\n * Define a class as a Mongoose Schema ready to be used to compose other schemes and models.\n *\n * ### Example\n *\n * ```typescript\n * @MongooseSchema()\n * export class EventSchema {\n * @Property()\n * field: string;\n * }\n * ```\n *\n * ### Options\n *\n * - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.\n *\n * @param {MongooseSchemaOptions | undefined} options\n * @returns {(target: any) => void}\n * @decorator\n * @mongoose\n * @property\n * @class\n */\nexport function MongooseSchema(options?: MongooseSchemaOptions): (target: any) => void;\nexport function MongooseSchema(definition: SchemaTypeOptions<any>): Function;\nexport function MongooseSchema(options: MongooseSchemaOptions | SchemaTypeOptions<any> = {}) {\n return Schema(options as any);\n}\n"]}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaIgnore = void 0;
4
+ const schema_1 = require("./schema");
5
+ /**
6
+ * Do not apply this property to schema (create virtual property)
7
+ *
8
+ * ### Example
9
+ *
10
+ * ```typescript
11
+ * @Model()
12
+ * @SchemaIgnore()
13
+ * @Property()
14
+ * kind: string;
15
+ *
16
+ * ```
17
+ *
18
+ * @returns {Function}
19
+ * @decorator
20
+ * @mongoose
21
+ * @class
22
+ */
23
+ function SchemaIgnore() {
24
+ return (0, schema_1.MongooseSchema)({ schemaIgnore: true });
25
+ }
26
+ exports.SchemaIgnore = SchemaIgnore;
27
+ //# sourceMappingURL=schemaIgnore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaIgnore.js","sourceRoot":"","sources":["../../../src/decorators/schemaIgnore.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AAEH,SAAgB,YAAY;IAC1B,OAAO,IAAA,uBAAc,EAAC,EAAC,YAAY,EAAE,IAAI,EAAQ,CAAC,CAAC;AACrD,CAAC;AAFD,oCAEC","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,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Select = void 0;
4
+ const schema_1 = require("./schema");
5
+ /**
6
+ * Tell Mongoose to set default select() behavior for this path.
7
+ *
8
+ * ### Example
9
+ *
10
+ * ```typescript
11
+ * @Model()
12
+ * export class EventModel {
13
+ * @Select()
14
+ * field: string;
15
+ * }
16
+ * ```
17
+ *
18
+ * @param {boolean | any} select
19
+ * @returns {Function}
20
+ * @decorator
21
+ * @mongoose
22
+ * @property
23
+ */
24
+ function Select(select = true) {
25
+ return (0, schema_1.MongooseSchema)({ select });
26
+ }
27
+ exports.Select = Select;
28
+ //# sourceMappingURL=select.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select.js","sourceRoot":"","sources":["../../../src/decorators/select.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,MAAM,CAAC,SAAwB,IAAI;IACjD,OAAO,IAAA,uBAAc,EAAC,EAAC,MAAM,EAAC,CAAC,CAAC;AAClC,CAAC;AAFD,wBAEC","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,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Sparse = void 0;
4
+ const schema_1 = require("./schema");
5
+ /**
6
+ * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will
7
+ * disallow changes to this path once the document is saved to the database for the first time. Read more
8
+ * about [immutability in Mongoose here](http://thecodebarbarian.com/whats-new-in-mongoose-5-6-immutable-properties.html).
9
+ *
10
+ * ### Example
11
+ *
12
+ * ```typescript
13
+ * @Model()
14
+ * export class EventModel {
15
+ * @Sparse()
16
+ * field: string;
17
+ * }
18
+ * ```
19
+ *
20
+ * @param {boolean | number} sparse
21
+ * @returns {Function}
22
+ * @decorator
23
+ * @mongoose
24
+ * @property
25
+ */
26
+ function Sparse(sparse = true) {
27
+ return (0, schema_1.MongooseSchema)({ sparse });
28
+ }
29
+ exports.Sparse = Sparse;
30
+ //# sourceMappingURL=sparse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sparse.js","sourceRoot":"","sources":["../../../src/decorators/sparse.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAExC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,MAAM,CAAC,SAA2B,IAAI;IACpD,OAAO,IAAA,uBAAc,EAAC,EAAC,MAAM,EAAQ,CAAC,CAAC;AACzC,CAAC;AAFD,wBAEC","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,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Text = void 0;
4
+ const schema_1 = require("./schema");
5
+ /**
6
+ * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose
7
+ * will build a text index on this path.
8
+ *
9
+ * ### Example
10
+ *
11
+ * ```typescript
12
+ * @Model()
13
+ * export class EventModel {
14
+ * @Text()
15
+ * field: string;
16
+ * }
17
+ * ```
18
+ *
19
+ * @param {boolean | number | any} text
20
+ * @returns {Function}
21
+ * @decorator
22
+ * @mongoose
23
+ * @property
24
+ */
25
+ function Text(text = true) {
26
+ return (0, schema_1.MongooseSchema)({ text });
27
+ }
28
+ exports.Text = Text;
29
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/decorators/text.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAExC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,IAAI,CAAC,OAA+B,IAAI;IACtD,OAAO,IAAA,uBAAc,EAAC,EAAC,IAAI,EAAQ,CAAC,CAAC;AACvC,CAAC;AAFD,oBAEC","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,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Trim = void 0;
4
+ const schema_1 = require("./schema");
5
+ /**
6
+ * Tell Mongoose to make the property trimmable.
7
+ *
8
+ * ### Example
9
+ *
10
+ * ```typescript
11
+ * @Model()
12
+ * export class EventModel {
13
+ * @Trim()
14
+ * name: string;
15
+ * }
16
+ * ```
17
+ *
18
+ * @returns {Function}
19
+ * @decorator
20
+ * @mongoose
21
+ * @property
22
+ */
23
+ function Trim() {
24
+ return (0, schema_1.MongooseSchema)({ trim: true });
25
+ }
26
+ exports.Trim = Trim;
27
+ //# sourceMappingURL=trim.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trim.js","sourceRoot":"","sources":["../../../src/decorators/trim.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,IAAI;IAClB,OAAO,IAAA,uBAAc,EAAC,EAAC,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;AACtC,CAAC;AAFD,oBAEC","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,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Unique = void 0;
4
+ const schema_1 = require("./schema");
5
+ /**
6
+ * Tell Mongoose to ensure a unique index is created for this path.
7
+ *
8
+ * ### Example
9
+ *
10
+ * ```typescript
11
+ * @Model()
12
+ * export class EventModel {
13
+ * @Unique()
14
+ * index: string;
15
+ * }
16
+ * ```
17
+ *
18
+ * @param {boolean | any} unique
19
+ * @returns {Function}
20
+ * @decorator
21
+ * @mongoose
22
+ */
23
+ function Unique(unique = true) {
24
+ return (0, schema_1.MongooseSchema)({ unique });
25
+ }
26
+ exports.Unique = Unique;
27
+ //# sourceMappingURL=unique.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unique.js","sourceRoot":"","sources":["../../../src/decorators/unique.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,MAAM,CAAC,SAAwB,IAAI;IACjD,OAAO,IAAA,uBAAc,EAAC,EAAC,MAAM,EAAC,CAAC,CAAC;AAClC,CAAC;AAFD,wBAEC","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,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Uppercase = void 0;
4
+ const schema_1 = require("./schema");
5
+ /**
6
+ * If truthy, Mongoose will add a custom setter that uppercases this string using JavaScript's built-in String#toUpperCase().
7
+ *
8
+ * ### Example
9
+ *
10
+ * ```typescript
11
+ * @Model()
12
+ * export class EventModel {
13
+ * @Uppercase()
14
+ * field: string;
15
+ * }
16
+ * ```
17
+ *
18
+ * @param {boolean} uppercase
19
+ * @returns {Function}
20
+ * @decorator
21
+ * @mongoose
22
+ * @property
23
+ */
24
+ function Uppercase(uppercase = true) {
25
+ return (0, schema_1.MongooseSchema)({ uppercase });
26
+ }
27
+ exports.Uppercase = Uppercase;
28
+ //# sourceMappingURL=uppercase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uppercase.js","sourceRoot":"","sources":["../../../src/decorators/uppercase.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,SAAS,CAAC,YAAqB,IAAI;IACjD,OAAO,IAAA,uBAAc,EAAC,EAAC,SAAS,EAAQ,CAAC,CAAC;AAC5C,CAAC;AAFD,8BAEC","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,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VersionKey = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ const constants_1 = require("../constants/constants");
6
+ function VersionKey() {
7
+ return (target, propertyKey) => {
8
+ core_1.Store.from(target).merge(constants_1.MONGOOSE_SCHEMA_OPTIONS, { versionKey: propertyKey });
9
+ };
10
+ }
11
+ exports.VersionKey = VersionKey;
12
+ //# sourceMappingURL=versionKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"versionKey.js","sourceRoot":"","sources":["../../../src/decorators/versionKey.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,sDAA+D;AAE/D,SAAgB,UAAU;IACxB,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,mCAAuB,EAAE,EAAC,UAAU,EAAE,WAAW,EAAC,CAAC,CAAC;IAC/E,CAAC,CAAC;AACJ,CAAC;AAJD,gCAIC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {MONGOOSE_SCHEMA_OPTIONS} from \"../constants/constants\";\n\nexport function VersionKey(): PropertyDecorator {\n return (target: any, propertyKey: string) => {\n Store.from(target).merge(MONGOOSE_SCHEMA_OPTIONS, {versionKey: propertyKey});\n };\n}\n"]}