@warlock.js/cascade 4.0.30 → 4.0.39

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 (533) hide show
  1. package/cjs/index.js +15 -1
  2. package/cjs/index.js.map +1 -1
  3. package/esm/index.js +15 -1
  4. package/esm/index.js.map +1 -1
  5. package/package.json +52 -61
  6. package/cjs/aggregate/DeselectPipeline.d.ts +0 -10
  7. package/cjs/aggregate/DeselectPipeline.d.ts.map +0 -1
  8. package/cjs/aggregate/DeselectPipeline.js +0 -17
  9. package/cjs/aggregate/DeselectPipeline.js.map +0 -1
  10. package/cjs/aggregate/GeoNearPipeline.d.ts +0 -34
  11. package/cjs/aggregate/GeoNearPipeline.d.ts.map +0 -1
  12. package/cjs/aggregate/GeoNearPipeline.js +0 -44
  13. package/cjs/aggregate/GeoNearPipeline.js.map +0 -1
  14. package/cjs/aggregate/GroupByPipeline.d.ts +0 -12
  15. package/cjs/aggregate/GroupByPipeline.d.ts.map +0 -1
  16. package/cjs/aggregate/GroupByPipeline.js +0 -28
  17. package/cjs/aggregate/GroupByPipeline.js.map +0 -1
  18. package/cjs/aggregate/LimitPipeline.d.ts +0 -10
  19. package/cjs/aggregate/LimitPipeline.d.ts.map +0 -1
  20. package/cjs/aggregate/LimitPipeline.js +0 -14
  21. package/cjs/aggregate/LimitPipeline.js.map +0 -1
  22. package/cjs/aggregate/LookupPipeline.d.ts +0 -19
  23. package/cjs/aggregate/LookupPipeline.d.ts.map +0 -1
  24. package/cjs/aggregate/LookupPipeline.js +0 -23
  25. package/cjs/aggregate/LookupPipeline.js.map +0 -1
  26. package/cjs/aggregate/OrWherePipeline.d.ts +0 -21
  27. package/cjs/aggregate/OrWherePipeline.d.ts.map +0 -1
  28. package/cjs/aggregate/OrWherePipeline.js +0 -63
  29. package/cjs/aggregate/OrWherePipeline.js.map +0 -1
  30. package/cjs/aggregate/SelectPipeline.d.ts +0 -10
  31. package/cjs/aggregate/SelectPipeline.d.ts.map +0 -1
  32. package/cjs/aggregate/SelectPipeline.js +0 -26
  33. package/cjs/aggregate/SelectPipeline.js.map +0 -1
  34. package/cjs/aggregate/SkipPipeline.d.ts +0 -10
  35. package/cjs/aggregate/SkipPipeline.d.ts.map +0 -1
  36. package/cjs/aggregate/SkipPipeline.js +0 -14
  37. package/cjs/aggregate/SkipPipeline.js.map +0 -1
  38. package/cjs/aggregate/SortByPipeline.d.ts +0 -10
  39. package/cjs/aggregate/SortByPipeline.d.ts.map +0 -1
  40. package/cjs/aggregate/SortByPipeline.js +0 -18
  41. package/cjs/aggregate/SortByPipeline.js.map +0 -1
  42. package/cjs/aggregate/SortPipeline.d.ts +0 -11
  43. package/cjs/aggregate/SortPipeline.d.ts.map +0 -1
  44. package/cjs/aggregate/SortPipeline.js +0 -18
  45. package/cjs/aggregate/SortPipeline.js.map +0 -1
  46. package/cjs/aggregate/SortRandomPipeline.d.ts +0 -10
  47. package/cjs/aggregate/SortRandomPipeline.d.ts.map +0 -1
  48. package/cjs/aggregate/SortRandomPipeline.js +0 -16
  49. package/cjs/aggregate/SortRandomPipeline.js.map +0 -1
  50. package/cjs/aggregate/UnwindPipeline.d.ts +0 -14
  51. package/cjs/aggregate/UnwindPipeline.d.ts.map +0 -1
  52. package/cjs/aggregate/UnwindPipeline.js +0 -19
  53. package/cjs/aggregate/UnwindPipeline.js.map +0 -1
  54. package/cjs/aggregate/WhereExpression.d.ts +0 -17
  55. package/cjs/aggregate/WhereExpression.d.ts.map +0 -1
  56. package/cjs/aggregate/WhereExpression.js +0 -149
  57. package/cjs/aggregate/WhereExpression.js.map +0 -1
  58. package/cjs/aggregate/WhereExpressionPipeline.d.ts +0 -10
  59. package/cjs/aggregate/WhereExpressionPipeline.d.ts.map +0 -1
  60. package/cjs/aggregate/WhereExpressionPipeline.js +0 -15
  61. package/cjs/aggregate/WhereExpressionPipeline.js.map +0 -1
  62. package/cjs/aggregate/WherePipeline.d.ts +0 -13
  63. package/cjs/aggregate/WherePipeline.d.ts.map +0 -1
  64. package/cjs/aggregate/WherePipeline.js +0 -12
  65. package/cjs/aggregate/WherePipeline.js.map +0 -1
  66. package/cjs/aggregate/aggregate.d.ts +0 -409
  67. package/cjs/aggregate/aggregate.d.ts.map +0 -1
  68. package/cjs/aggregate/aggregate.js +0 -911
  69. package/cjs/aggregate/aggregate.js.map +0 -1
  70. package/cjs/aggregate/expressions.d.ts +0 -361
  71. package/cjs/aggregate/expressions.d.ts.map +0 -1
  72. package/cjs/aggregate/expressions.js +0 -536
  73. package/cjs/aggregate/expressions.js.map +0 -1
  74. package/cjs/aggregate/filters/apply-filters.d.ts +0 -3
  75. package/cjs/aggregate/filters/apply-filters.d.ts.map +0 -1
  76. package/cjs/aggregate/filters/apply-filters.js +0 -75
  77. package/cjs/aggregate/filters/apply-filters.js.map +0 -1
  78. package/cjs/aggregate/filters/boolean-filters.d.ts +0 -3
  79. package/cjs/aggregate/filters/boolean-filters.d.ts.map +0 -1
  80. package/cjs/aggregate/filters/boolean-filters.js +0 -33
  81. package/cjs/aggregate/filters/boolean-filters.js.map +0 -1
  82. package/cjs/aggregate/filters/date-filters.d.ts +0 -3
  83. package/cjs/aggregate/filters/date-filters.d.ts.map +0 -1
  84. package/cjs/aggregate/filters/date-filters.js +0 -128
  85. package/cjs/aggregate/filters/date-filters.js.map +0 -1
  86. package/cjs/aggregate/filters/index.d.ts +0 -3
  87. package/cjs/aggregate/filters/index.d.ts.map +0 -1
  88. package/cjs/aggregate/filters/numeric-filters.d.ts +0 -3
  89. package/cjs/aggregate/filters/numeric-filters.d.ts.map +0 -1
  90. package/cjs/aggregate/filters/numeric-filters.js +0 -99
  91. package/cjs/aggregate/filters/numeric-filters.js.map +0 -1
  92. package/cjs/aggregate/filters/types.d.ts +0 -46
  93. package/cjs/aggregate/filters/types.d.ts.map +0 -1
  94. package/cjs/aggregate/filters/utils.d.ts +0 -13
  95. package/cjs/aggregate/filters/utils.d.ts.map +0 -1
  96. package/cjs/aggregate/filters/utils.js +0 -38
  97. package/cjs/aggregate/filters/utils.js.map +0 -1
  98. package/cjs/aggregate/index.d.ts +0 -21
  99. package/cjs/aggregate/index.d.ts.map +0 -1
  100. package/cjs/aggregate/parsePipelines.d.ts +0 -5
  101. package/cjs/aggregate/parsePipelines.d.ts.map +0 -1
  102. package/cjs/aggregate/parsePipelines.js +0 -6
  103. package/cjs/aggregate/parsePipelines.js.map +0 -1
  104. package/cjs/aggregate/pipeline.d.ts +0 -31
  105. package/cjs/aggregate/pipeline.d.ts.map +0 -1
  106. package/cjs/aggregate/pipeline.js +0 -42
  107. package/cjs/aggregate/pipeline.js.map +0 -1
  108. package/cjs/aggregate/types.d.ts +0 -8
  109. package/cjs/aggregate/types.d.ts.map +0 -1
  110. package/cjs/aggregate/types.js +0 -31
  111. package/cjs/aggregate/types.js.map +0 -1
  112. package/cjs/blueprint/blueprint-column.d.ts +0 -82
  113. package/cjs/blueprint/blueprint-column.d.ts.map +0 -1
  114. package/cjs/blueprint/blueprint.d.ts +0 -162
  115. package/cjs/blueprint/blueprint.d.ts.map +0 -1
  116. package/cjs/blueprint/blueprint.js +0 -340
  117. package/cjs/blueprint/blueprint.js.map +0 -1
  118. package/cjs/blueprint/index.d.ts +0 -3
  119. package/cjs/blueprint/index.d.ts.map +0 -1
  120. package/cjs/blueprint/model-blueprint.d.ts +0 -15
  121. package/cjs/blueprint/model-blueprint.d.ts.map +0 -1
  122. package/cjs/blueprint/model-blueprint.js +0 -16
  123. package/cjs/blueprint/model-blueprint.js.map +0 -1
  124. package/cjs/casts/arrayOf.d.ts +0 -5
  125. package/cjs/casts/arrayOf.d.ts.map +0 -1
  126. package/cjs/casts/arrayOf.js +0 -18
  127. package/cjs/casts/arrayOf.js.map +0 -1
  128. package/cjs/casts/cast-email.d.ts +0 -2
  129. package/cjs/casts/cast-email.d.ts.map +0 -1
  130. package/cjs/casts/cast-email.js +0 -5
  131. package/cjs/casts/cast-email.js.map +0 -1
  132. package/cjs/casts/castModel.d.ts +0 -3
  133. package/cjs/casts/castModel.d.ts.map +0 -1
  134. package/cjs/casts/castModel.js +0 -49
  135. package/cjs/casts/castModel.js.map +0 -1
  136. package/cjs/casts/expiresAfter.d.ts +0 -3
  137. package/cjs/casts/expiresAfter.d.ts.map +0 -1
  138. package/cjs/casts/expiresAfter.js +0 -5
  139. package/cjs/casts/expiresAfter.js.map +0 -1
  140. package/cjs/casts/index.d.ts +0 -9
  141. package/cjs/casts/index.d.ts.map +0 -1
  142. package/cjs/casts/oneOf.d.ts +0 -3
  143. package/cjs/casts/oneOf.d.ts.map +0 -1
  144. package/cjs/casts/oneOf.js +0 -22
  145. package/cjs/casts/oneOf.js.map +0 -1
  146. package/cjs/casts/random-string.d.ts +0 -2
  147. package/cjs/casts/random-string.d.ts.map +0 -1
  148. package/cjs/casts/random-string.js +0 -5
  149. package/cjs/casts/random-string.js.map +0 -1
  150. package/cjs/casts/randomInteger.d.ts +0 -2
  151. package/cjs/casts/randomInteger.d.ts.map +0 -1
  152. package/cjs/casts/randomInteger.js +0 -7
  153. package/cjs/casts/randomInteger.js.map +0 -1
  154. package/cjs/casts/shapedArray.d.ts +0 -26
  155. package/cjs/casts/shapedArray.d.ts.map +0 -1
  156. package/cjs/casts/shapedArray.js +0 -100
  157. package/cjs/casts/shapedArray.js.map +0 -1
  158. package/cjs/config.d.ts +0 -6
  159. package/cjs/config.d.ts.map +0 -1
  160. package/cjs/config.js +0 -16
  161. package/cjs/config.js.map +0 -1
  162. package/cjs/connection.d.ts +0 -49
  163. package/cjs/connection.d.ts.map +0 -1
  164. package/cjs/connection.js +0 -108
  165. package/cjs/connection.js.map +0 -1
  166. package/cjs/database.d.ts +0 -97
  167. package/cjs/database.d.ts.map +0 -1
  168. package/cjs/database.js +0 -164
  169. package/cjs/database.js.map +0 -1
  170. package/cjs/index.d.ts +0 -13
  171. package/cjs/index.d.ts.map +0 -1
  172. package/cjs/migration/index.d.ts +0 -4
  173. package/cjs/migration/index.d.ts.map +0 -1
  174. package/cjs/migration/migrate.d.ts +0 -13
  175. package/cjs/migration/migrate.d.ts.map +0 -1
  176. package/cjs/migration/migrate.js +0 -72
  177. package/cjs/migration/migrate.js.map +0 -1
  178. package/cjs/migration/migration-office.d.ts +0 -21
  179. package/cjs/migration/migration-office.d.ts.map +0 -1
  180. package/cjs/migration/migration-office.js +0 -39
  181. package/cjs/migration/migration-office.js.map +0 -1
  182. package/cjs/migration/migration-officer.d.ts +0 -33
  183. package/cjs/migration/migration-officer.d.ts.map +0 -1
  184. package/cjs/migration/migration-officer.js +0 -55
  185. package/cjs/migration/migration-officer.js.map +0 -1
  186. package/cjs/migration/types.d.ts +0 -34
  187. package/cjs/migration/types.d.ts.map +0 -1
  188. package/cjs/model/ModelAggregate.d.ts +0 -114
  189. package/cjs/model/ModelAggregate.d.ts.map +0 -1
  190. package/cjs/model/ModelAggregate.js +0 -182
  191. package/cjs/model/ModelAggregate.js.map +0 -1
  192. package/cjs/model/ModelSync.d.ts +0 -73
  193. package/cjs/model/ModelSync.d.ts.map +0 -1
  194. package/cjs/model/ModelSync.js +0 -215
  195. package/cjs/model/ModelSync.js.map +0 -1
  196. package/cjs/model/RelationshipWithMany.d.ts +0 -24
  197. package/cjs/model/RelationshipWithMany.d.ts.map +0 -1
  198. package/cjs/model/RelationshipWithMany.js +0 -42
  199. package/cjs/model/RelationshipWithMany.js.map +0 -1
  200. package/cjs/model/base-model.d.ts +0 -161
  201. package/cjs/model/base-model.d.ts.map +0 -1
  202. package/cjs/model/base-model.js +0 -265
  203. package/cjs/model/base-model.js.map +0 -1
  204. package/cjs/model/crud-model.d.ts +0 -122
  205. package/cjs/model/crud-model.d.ts.map +0 -1
  206. package/cjs/model/crud-model.js +0 -366
  207. package/cjs/model/crud-model.js.map +0 -1
  208. package/cjs/model/index.d.ts +0 -10
  209. package/cjs/model/index.d.ts.map +0 -1
  210. package/cjs/model/joinable.d.ts +0 -87
  211. package/cjs/model/joinable.d.ts.map +0 -1
  212. package/cjs/model/joinable.js +0 -158
  213. package/cjs/model/joinable.js.map +0 -1
  214. package/cjs/model/master-mind.d.ts +0 -44
  215. package/cjs/model/master-mind.d.ts.map +0 -1
  216. package/cjs/model/master-mind.js +0 -118
  217. package/cjs/model/master-mind.js.map +0 -1
  218. package/cjs/model/model-events.d.ts +0 -57
  219. package/cjs/model/model-events.d.ts.map +0 -1
  220. package/cjs/model/model-events.js +0 -102
  221. package/cjs/model/model-events.js.map +0 -1
  222. package/cjs/model/model.d.ts +0 -464
  223. package/cjs/model/model.d.ts.map +0 -1
  224. package/cjs/model/model.js +0 -1134
  225. package/cjs/model/model.js.map +0 -1
  226. package/cjs/model/types.d.ts +0 -149
  227. package/cjs/model/types.d.ts.map +0 -1
  228. package/cjs/model/types.js +0 -11
  229. package/cjs/model/types.js.map +0 -1
  230. package/cjs/query/index.d.ts +0 -2
  231. package/cjs/query/index.d.ts.map +0 -1
  232. package/cjs/query/query.d.ts +0 -218
  233. package/cjs/query/query.d.ts.map +0 -1
  234. package/cjs/query/query.js +0 -672
  235. package/cjs/query/query.js.map +0 -1
  236. package/cjs/query/types.d.ts +0 -60
  237. package/cjs/query/types.d.ts.map +0 -1
  238. package/cjs/types.d.ts +0 -75
  239. package/cjs/types.d.ts.map +0 -1
  240. package/cjs/utils/connectToDatabase.d.ts +0 -3
  241. package/cjs/utils/connectToDatabase.d.ts.map +0 -1
  242. package/cjs/utils/connectToDatabase.js +0 -3
  243. package/cjs/utils/connectToDatabase.js.map +0 -1
  244. package/cjs/utils/deep-diff.d.ts +0 -9
  245. package/cjs/utils/deep-diff.d.ts.map +0 -1
  246. package/cjs/utils/deep-diff.js +0 -44
  247. package/cjs/utils/deep-diff.js.map +0 -1
  248. package/cjs/utils/dropAllDatabaseIndexes.d.ts +0 -2
  249. package/cjs/utils/dropAllDatabaseIndexes.d.ts.map +0 -1
  250. package/cjs/utils/dropAllDatabaseIndexes.js +0 -10
  251. package/cjs/utils/dropAllDatabaseIndexes.js.map +0 -1
  252. package/cjs/utils/index.d.ts +0 -6
  253. package/cjs/utils/index.d.ts.map +0 -1
  254. package/cjs/utils/joinable-proxy.d.ts +0 -3
  255. package/cjs/utils/joinable-proxy.d.ts.map +0 -1
  256. package/cjs/utils/joinable-proxy.js +0 -14
  257. package/cjs/utils/joinable-proxy.js.map +0 -1
  258. package/cjs/utils/listDatabaseIndexes.d.ts +0 -4
  259. package/cjs/utils/listDatabaseIndexes.d.ts.map +0 -1
  260. package/cjs/utils/listDatabaseIndexes.js +0 -101
  261. package/cjs/utils/listDatabaseIndexes.js.map +0 -1
  262. package/cjs/utils/onceConnected.d.ts +0 -2
  263. package/cjs/utils/onceConnected.d.ts.map +0 -1
  264. package/cjs/utils/onceConnected.js +0 -8
  265. package/cjs/utils/onceConnected.js.map +0 -1
  266. package/cjs/utils/sync-with.d.ts +0 -27
  267. package/cjs/utils/sync-with.d.ts.map +0 -1
  268. package/cjs/utils/sync-with.js +0 -60
  269. package/cjs/utils/sync-with.js.map +0 -1
  270. package/esm/aggregate/DeselectPipeline.d.ts +0 -10
  271. package/esm/aggregate/DeselectPipeline.d.ts.map +0 -1
  272. package/esm/aggregate/DeselectPipeline.js +0 -17
  273. package/esm/aggregate/DeselectPipeline.js.map +0 -1
  274. package/esm/aggregate/GeoNearPipeline.d.ts +0 -34
  275. package/esm/aggregate/GeoNearPipeline.d.ts.map +0 -1
  276. package/esm/aggregate/GeoNearPipeline.js +0 -44
  277. package/esm/aggregate/GeoNearPipeline.js.map +0 -1
  278. package/esm/aggregate/GroupByPipeline.d.ts +0 -12
  279. package/esm/aggregate/GroupByPipeline.d.ts.map +0 -1
  280. package/esm/aggregate/GroupByPipeline.js +0 -28
  281. package/esm/aggregate/GroupByPipeline.js.map +0 -1
  282. package/esm/aggregate/LimitPipeline.d.ts +0 -10
  283. package/esm/aggregate/LimitPipeline.d.ts.map +0 -1
  284. package/esm/aggregate/LimitPipeline.js +0 -14
  285. package/esm/aggregate/LimitPipeline.js.map +0 -1
  286. package/esm/aggregate/LookupPipeline.d.ts +0 -19
  287. package/esm/aggregate/LookupPipeline.d.ts.map +0 -1
  288. package/esm/aggregate/LookupPipeline.js +0 -23
  289. package/esm/aggregate/LookupPipeline.js.map +0 -1
  290. package/esm/aggregate/OrWherePipeline.d.ts +0 -21
  291. package/esm/aggregate/OrWherePipeline.d.ts.map +0 -1
  292. package/esm/aggregate/OrWherePipeline.js +0 -63
  293. package/esm/aggregate/OrWherePipeline.js.map +0 -1
  294. package/esm/aggregate/SelectPipeline.d.ts +0 -10
  295. package/esm/aggregate/SelectPipeline.d.ts.map +0 -1
  296. package/esm/aggregate/SelectPipeline.js +0 -26
  297. package/esm/aggregate/SelectPipeline.js.map +0 -1
  298. package/esm/aggregate/SkipPipeline.d.ts +0 -10
  299. package/esm/aggregate/SkipPipeline.d.ts.map +0 -1
  300. package/esm/aggregate/SkipPipeline.js +0 -14
  301. package/esm/aggregate/SkipPipeline.js.map +0 -1
  302. package/esm/aggregate/SortByPipeline.d.ts +0 -10
  303. package/esm/aggregate/SortByPipeline.d.ts.map +0 -1
  304. package/esm/aggregate/SortByPipeline.js +0 -18
  305. package/esm/aggregate/SortByPipeline.js.map +0 -1
  306. package/esm/aggregate/SortPipeline.d.ts +0 -11
  307. package/esm/aggregate/SortPipeline.d.ts.map +0 -1
  308. package/esm/aggregate/SortPipeline.js +0 -18
  309. package/esm/aggregate/SortPipeline.js.map +0 -1
  310. package/esm/aggregate/SortRandomPipeline.d.ts +0 -10
  311. package/esm/aggregate/SortRandomPipeline.d.ts.map +0 -1
  312. package/esm/aggregate/SortRandomPipeline.js +0 -16
  313. package/esm/aggregate/SortRandomPipeline.js.map +0 -1
  314. package/esm/aggregate/UnwindPipeline.d.ts +0 -14
  315. package/esm/aggregate/UnwindPipeline.d.ts.map +0 -1
  316. package/esm/aggregate/UnwindPipeline.js +0 -19
  317. package/esm/aggregate/UnwindPipeline.js.map +0 -1
  318. package/esm/aggregate/WhereExpression.d.ts +0 -17
  319. package/esm/aggregate/WhereExpression.d.ts.map +0 -1
  320. package/esm/aggregate/WhereExpression.js +0 -149
  321. package/esm/aggregate/WhereExpression.js.map +0 -1
  322. package/esm/aggregate/WhereExpressionPipeline.d.ts +0 -10
  323. package/esm/aggregate/WhereExpressionPipeline.d.ts.map +0 -1
  324. package/esm/aggregate/WhereExpressionPipeline.js +0 -15
  325. package/esm/aggregate/WhereExpressionPipeline.js.map +0 -1
  326. package/esm/aggregate/WherePipeline.d.ts +0 -13
  327. package/esm/aggregate/WherePipeline.d.ts.map +0 -1
  328. package/esm/aggregate/WherePipeline.js +0 -12
  329. package/esm/aggregate/WherePipeline.js.map +0 -1
  330. package/esm/aggregate/aggregate.d.ts +0 -409
  331. package/esm/aggregate/aggregate.d.ts.map +0 -1
  332. package/esm/aggregate/aggregate.js +0 -911
  333. package/esm/aggregate/aggregate.js.map +0 -1
  334. package/esm/aggregate/expressions.d.ts +0 -361
  335. package/esm/aggregate/expressions.d.ts.map +0 -1
  336. package/esm/aggregate/expressions.js +0 -536
  337. package/esm/aggregate/expressions.js.map +0 -1
  338. package/esm/aggregate/filters/apply-filters.d.ts +0 -3
  339. package/esm/aggregate/filters/apply-filters.d.ts.map +0 -1
  340. package/esm/aggregate/filters/apply-filters.js +0 -75
  341. package/esm/aggregate/filters/apply-filters.js.map +0 -1
  342. package/esm/aggregate/filters/boolean-filters.d.ts +0 -3
  343. package/esm/aggregate/filters/boolean-filters.d.ts.map +0 -1
  344. package/esm/aggregate/filters/boolean-filters.js +0 -33
  345. package/esm/aggregate/filters/boolean-filters.js.map +0 -1
  346. package/esm/aggregate/filters/date-filters.d.ts +0 -3
  347. package/esm/aggregate/filters/date-filters.d.ts.map +0 -1
  348. package/esm/aggregate/filters/date-filters.js +0 -128
  349. package/esm/aggregate/filters/date-filters.js.map +0 -1
  350. package/esm/aggregate/filters/index.d.ts +0 -3
  351. package/esm/aggregate/filters/index.d.ts.map +0 -1
  352. package/esm/aggregate/filters/numeric-filters.d.ts +0 -3
  353. package/esm/aggregate/filters/numeric-filters.d.ts.map +0 -1
  354. package/esm/aggregate/filters/numeric-filters.js +0 -99
  355. package/esm/aggregate/filters/numeric-filters.js.map +0 -1
  356. package/esm/aggregate/filters/types.d.ts +0 -46
  357. package/esm/aggregate/filters/types.d.ts.map +0 -1
  358. package/esm/aggregate/filters/utils.d.ts +0 -13
  359. package/esm/aggregate/filters/utils.d.ts.map +0 -1
  360. package/esm/aggregate/filters/utils.js +0 -38
  361. package/esm/aggregate/filters/utils.js.map +0 -1
  362. package/esm/aggregate/index.d.ts +0 -21
  363. package/esm/aggregate/index.d.ts.map +0 -1
  364. package/esm/aggregate/parsePipelines.d.ts +0 -5
  365. package/esm/aggregate/parsePipelines.d.ts.map +0 -1
  366. package/esm/aggregate/parsePipelines.js +0 -6
  367. package/esm/aggregate/parsePipelines.js.map +0 -1
  368. package/esm/aggregate/pipeline.d.ts +0 -31
  369. package/esm/aggregate/pipeline.d.ts.map +0 -1
  370. package/esm/aggregate/pipeline.js +0 -42
  371. package/esm/aggregate/pipeline.js.map +0 -1
  372. package/esm/aggregate/types.d.ts +0 -8
  373. package/esm/aggregate/types.d.ts.map +0 -1
  374. package/esm/aggregate/types.js +0 -31
  375. package/esm/aggregate/types.js.map +0 -1
  376. package/esm/blueprint/blueprint-column.d.ts +0 -82
  377. package/esm/blueprint/blueprint-column.d.ts.map +0 -1
  378. package/esm/blueprint/blueprint.d.ts +0 -162
  379. package/esm/blueprint/blueprint.d.ts.map +0 -1
  380. package/esm/blueprint/blueprint.js +0 -340
  381. package/esm/blueprint/blueprint.js.map +0 -1
  382. package/esm/blueprint/index.d.ts +0 -3
  383. package/esm/blueprint/index.d.ts.map +0 -1
  384. package/esm/blueprint/model-blueprint.d.ts +0 -15
  385. package/esm/blueprint/model-blueprint.d.ts.map +0 -1
  386. package/esm/blueprint/model-blueprint.js +0 -16
  387. package/esm/blueprint/model-blueprint.js.map +0 -1
  388. package/esm/casts/arrayOf.d.ts +0 -5
  389. package/esm/casts/arrayOf.d.ts.map +0 -1
  390. package/esm/casts/arrayOf.js +0 -18
  391. package/esm/casts/arrayOf.js.map +0 -1
  392. package/esm/casts/cast-email.d.ts +0 -2
  393. package/esm/casts/cast-email.d.ts.map +0 -1
  394. package/esm/casts/cast-email.js +0 -5
  395. package/esm/casts/cast-email.js.map +0 -1
  396. package/esm/casts/castModel.d.ts +0 -3
  397. package/esm/casts/castModel.d.ts.map +0 -1
  398. package/esm/casts/castModel.js +0 -49
  399. package/esm/casts/castModel.js.map +0 -1
  400. package/esm/casts/expiresAfter.d.ts +0 -3
  401. package/esm/casts/expiresAfter.d.ts.map +0 -1
  402. package/esm/casts/expiresAfter.js +0 -5
  403. package/esm/casts/expiresAfter.js.map +0 -1
  404. package/esm/casts/index.d.ts +0 -9
  405. package/esm/casts/index.d.ts.map +0 -1
  406. package/esm/casts/oneOf.d.ts +0 -3
  407. package/esm/casts/oneOf.d.ts.map +0 -1
  408. package/esm/casts/oneOf.js +0 -22
  409. package/esm/casts/oneOf.js.map +0 -1
  410. package/esm/casts/random-string.d.ts +0 -2
  411. package/esm/casts/random-string.d.ts.map +0 -1
  412. package/esm/casts/random-string.js +0 -5
  413. package/esm/casts/random-string.js.map +0 -1
  414. package/esm/casts/randomInteger.d.ts +0 -2
  415. package/esm/casts/randomInteger.d.ts.map +0 -1
  416. package/esm/casts/randomInteger.js +0 -7
  417. package/esm/casts/randomInteger.js.map +0 -1
  418. package/esm/casts/shapedArray.d.ts +0 -26
  419. package/esm/casts/shapedArray.d.ts.map +0 -1
  420. package/esm/casts/shapedArray.js +0 -100
  421. package/esm/casts/shapedArray.js.map +0 -1
  422. package/esm/config.d.ts +0 -6
  423. package/esm/config.d.ts.map +0 -1
  424. package/esm/config.js +0 -16
  425. package/esm/config.js.map +0 -1
  426. package/esm/connection.d.ts +0 -49
  427. package/esm/connection.d.ts.map +0 -1
  428. package/esm/connection.js +0 -108
  429. package/esm/connection.js.map +0 -1
  430. package/esm/database.d.ts +0 -97
  431. package/esm/database.d.ts.map +0 -1
  432. package/esm/database.js +0 -164
  433. package/esm/database.js.map +0 -1
  434. package/esm/index.d.ts +0 -13
  435. package/esm/index.d.ts.map +0 -1
  436. package/esm/migration/index.d.ts +0 -4
  437. package/esm/migration/index.d.ts.map +0 -1
  438. package/esm/migration/migrate.d.ts +0 -13
  439. package/esm/migration/migrate.d.ts.map +0 -1
  440. package/esm/migration/migrate.js +0 -72
  441. package/esm/migration/migrate.js.map +0 -1
  442. package/esm/migration/migration-office.d.ts +0 -21
  443. package/esm/migration/migration-office.d.ts.map +0 -1
  444. package/esm/migration/migration-office.js +0 -39
  445. package/esm/migration/migration-office.js.map +0 -1
  446. package/esm/migration/migration-officer.d.ts +0 -33
  447. package/esm/migration/migration-officer.d.ts.map +0 -1
  448. package/esm/migration/migration-officer.js +0 -55
  449. package/esm/migration/migration-officer.js.map +0 -1
  450. package/esm/migration/types.d.ts +0 -34
  451. package/esm/migration/types.d.ts.map +0 -1
  452. package/esm/model/ModelAggregate.d.ts +0 -114
  453. package/esm/model/ModelAggregate.d.ts.map +0 -1
  454. package/esm/model/ModelAggregate.js +0 -182
  455. package/esm/model/ModelAggregate.js.map +0 -1
  456. package/esm/model/ModelSync.d.ts +0 -73
  457. package/esm/model/ModelSync.d.ts.map +0 -1
  458. package/esm/model/ModelSync.js +0 -215
  459. package/esm/model/ModelSync.js.map +0 -1
  460. package/esm/model/RelationshipWithMany.d.ts +0 -24
  461. package/esm/model/RelationshipWithMany.d.ts.map +0 -1
  462. package/esm/model/RelationshipWithMany.js +0 -42
  463. package/esm/model/RelationshipWithMany.js.map +0 -1
  464. package/esm/model/base-model.d.ts +0 -161
  465. package/esm/model/base-model.d.ts.map +0 -1
  466. package/esm/model/base-model.js +0 -265
  467. package/esm/model/base-model.js.map +0 -1
  468. package/esm/model/crud-model.d.ts +0 -122
  469. package/esm/model/crud-model.d.ts.map +0 -1
  470. package/esm/model/crud-model.js +0 -366
  471. package/esm/model/crud-model.js.map +0 -1
  472. package/esm/model/index.d.ts +0 -10
  473. package/esm/model/index.d.ts.map +0 -1
  474. package/esm/model/joinable.d.ts +0 -87
  475. package/esm/model/joinable.d.ts.map +0 -1
  476. package/esm/model/joinable.js +0 -158
  477. package/esm/model/joinable.js.map +0 -1
  478. package/esm/model/master-mind.d.ts +0 -44
  479. package/esm/model/master-mind.d.ts.map +0 -1
  480. package/esm/model/master-mind.js +0 -118
  481. package/esm/model/master-mind.js.map +0 -1
  482. package/esm/model/model-events.d.ts +0 -57
  483. package/esm/model/model-events.d.ts.map +0 -1
  484. package/esm/model/model-events.js +0 -102
  485. package/esm/model/model-events.js.map +0 -1
  486. package/esm/model/model.d.ts +0 -464
  487. package/esm/model/model.d.ts.map +0 -1
  488. package/esm/model/model.js +0 -1134
  489. package/esm/model/model.js.map +0 -1
  490. package/esm/model/types.d.ts +0 -149
  491. package/esm/model/types.d.ts.map +0 -1
  492. package/esm/model/types.js +0 -11
  493. package/esm/model/types.js.map +0 -1
  494. package/esm/query/index.d.ts +0 -2
  495. package/esm/query/index.d.ts.map +0 -1
  496. package/esm/query/query.d.ts +0 -218
  497. package/esm/query/query.d.ts.map +0 -1
  498. package/esm/query/query.js +0 -672
  499. package/esm/query/query.js.map +0 -1
  500. package/esm/query/types.d.ts +0 -60
  501. package/esm/query/types.d.ts.map +0 -1
  502. package/esm/types.d.ts +0 -75
  503. package/esm/types.d.ts.map +0 -1
  504. package/esm/utils/connectToDatabase.d.ts +0 -3
  505. package/esm/utils/connectToDatabase.d.ts.map +0 -1
  506. package/esm/utils/connectToDatabase.js +0 -3
  507. package/esm/utils/connectToDatabase.js.map +0 -1
  508. package/esm/utils/deep-diff.d.ts +0 -9
  509. package/esm/utils/deep-diff.d.ts.map +0 -1
  510. package/esm/utils/deep-diff.js +0 -44
  511. package/esm/utils/deep-diff.js.map +0 -1
  512. package/esm/utils/dropAllDatabaseIndexes.d.ts +0 -2
  513. package/esm/utils/dropAllDatabaseIndexes.d.ts.map +0 -1
  514. package/esm/utils/dropAllDatabaseIndexes.js +0 -10
  515. package/esm/utils/dropAllDatabaseIndexes.js.map +0 -1
  516. package/esm/utils/index.d.ts +0 -6
  517. package/esm/utils/index.d.ts.map +0 -1
  518. package/esm/utils/joinable-proxy.d.ts +0 -3
  519. package/esm/utils/joinable-proxy.d.ts.map +0 -1
  520. package/esm/utils/joinable-proxy.js +0 -14
  521. package/esm/utils/joinable-proxy.js.map +0 -1
  522. package/esm/utils/listDatabaseIndexes.d.ts +0 -4
  523. package/esm/utils/listDatabaseIndexes.d.ts.map +0 -1
  524. package/esm/utils/listDatabaseIndexes.js +0 -101
  525. package/esm/utils/listDatabaseIndexes.js.map +0 -1
  526. package/esm/utils/onceConnected.d.ts +0 -2
  527. package/esm/utils/onceConnected.d.ts.map +0 -1
  528. package/esm/utils/onceConnected.js +0 -8
  529. package/esm/utils/onceConnected.js.map +0 -1
  530. package/esm/utils/sync-with.d.ts +0 -27
  531. package/esm/utils/sync-with.d.ts.map +0 -1
  532. package/esm/utils/sync-with.js +0 -60
  533. package/esm/utils/sync-with.js.map +0 -1
@@ -1,1134 +0,0 @@
1
- import {clone,get,except,only,set,merge,areEqual}from'@mongez/reinforcements';import {isEmpty,isPlainObject}from'@mongez/supportive-is';import {toUTC}from'@mongez/time-wizard';import dayjs from'dayjs';import {ObjectId,MongoServerError}from'mongodb';import {castModel}from'../casts/castModel.js';import {castEnum}from'../casts/oneOf.js';import {deepDiff}from'../utils/deep-diff.js';import {joinableProxy}from'../utils/joinable-proxy.js';import {CrudModel}from'./crud-model.js';import {Joinable}from'./joinable.js';import {ModelAggregate}from'./ModelAggregate.js';import {ModelSync}from'./ModelSync.js';import {RelationshipWithMany}from'./RelationshipWithMany.js';import {ModelDeleteStrategy}from'./types.js';class Model
2
- // <
3
- // ModelDocument extends Document = any,
4
- // Schema extends Schema<ModelDocument> = any,
5
- // >
6
- extends CrudModel {
7
- /**
8
- * Model Initial Document data
9
- */
10
- initialData = {};
11
- /**
12
- * Model relationships defined using the joinable API.
13
- *
14
- * Each key represents a relationship name that can be referenced when running queries.
15
- * Each value defines how to join another collection to the current model.
16
- *
17
- * @example
18
- * Basic definition:
19
- * ```ts
20
- * public static relations = {
21
- * // Join users collection where local createdBy.id matches user's id
22
- * author: User.joinable("createdBy.id", "id").single().as("author"),
23
- * }
24
- * ```
25
- * @usage
26
- * Example of calling:
27
- * ```ts
28
- * Post.aggregate().joining("author").get(); // use `joining` method to join the `author` relationship
29
- * // Where `author` is the name of the relationship defined in the `relations` property
30
- * ```
31
- */
32
- static relations = {};
33
- /**
34
- * Model Document data
35
- */
36
- data;
37
- /**
38
- * Define Default value data that will be merged with the models' data
39
- * on the create process
40
- */
41
- defaultValue = {};
42
- /**
43
- * A flag to determine if the model is being restored
44
- */
45
- isRestored = false;
46
- /**
47
- * Model casts types
48
- */
49
- casts = {};
50
- /**
51
- * Sync with list
52
- */
53
- syncWith = [];
54
- /**
55
- * Set custom casts that will be used to cast the model's data are not related to the current value of the collection's column
56
- *
57
- * For example: `name` is not a column in the given data, but it will be concatenation of `firstName` and `lastName`
58
- */
59
- customCasts = {};
60
- /**
61
- * Guarded fields
62
- */
63
- guarded = [];
64
- /**
65
- * Fillable fields
66
- */
67
- filled = [];
68
- /**
69
- * Embedded columns
70
- */
71
- embedded = [];
72
- /**
73
- * Embed all columns except the given columns
74
- */
75
- embedAllExcept = [];
76
- /**
77
- * Embed all columns except timestamps and created|updated|deleted by columns
78
- */
79
- embedAllExceptTimestampsAndUserColumns = false;
80
- /**
81
- * Created at column
82
- */
83
- createdAtColumn = "createdAt";
84
- /**
85
- * Updated at column
86
- */
87
- updatedAtColumn = "updatedAt";
88
- /**
89
- * Deleted at column
90
- */
91
- deletedAtColumn = "deletedAt";
92
- /**
93
- * Created by column
94
- */
95
- createdByColumn = "createdBy";
96
- /**
97
- * Updated by column
98
- */
99
- updatedByColumn = "updatedBy";
100
- /**
101
- * Deleted by column
102
- */
103
- deletedByColumn = "deletedBy";
104
- /**
105
- * Date format
106
- */
107
- dateFormat = "DD-MM-YYYY";
108
- /**
109
- * A flag to determine if the id is auto generated not added manually
110
- */
111
- autoGeneratedId = false;
112
- /**
113
- * Is active column
114
- */
115
- isActiveColumn = "isActive";
116
- /**
117
- * Original data
118
- */
119
- originalData = {};
120
- /**
121
- * List of dirty columns
122
- */
123
- dirtyColumns = {};
124
- /**
125
- * Constructor
126
- */
127
- constructor(originalData = {}) {
128
- super();
129
- if (originalData instanceof Model) {
130
- this.originalData = clone(originalData.data);
131
- }
132
- else {
133
- this.originalData = clone(originalData);
134
- }
135
- if (typeof this.originalData._id === "string") {
136
- this.originalData._id = new ObjectId(this.originalData._id);
137
- }
138
- this.data = clone(this.originalData);
139
- this.initialData = clone(this.originalData);
140
- }
141
- /**
142
- * Get save columns which are the casts keys
143
- */
144
- get castColumns() {
145
- return Object.keys(this.casts);
146
- }
147
- /**
148
- * Get value from original data
149
- */
150
- original(key, defaultValue) {
151
- return get(this.originalData, key, defaultValue);
152
- }
153
- /**
154
- * Get all data except the guarded fields
155
- */
156
- get publicData() {
157
- return except(this.data, this.guarded);
158
- }
159
- /**
160
- * Get guarded data
161
- */
162
- get guardedData() {
163
- return only(this.data, this.guarded);
164
- }
165
- /**
166
- * Get the model's id
167
- */
168
- get id() {
169
- return this.get("id");
170
- }
171
- /**
172
- * Check if current model is active
173
- */
174
- get isActive() {
175
- return this.bool(this.isActiveColumn);
176
- }
177
- /**
178
- * Check if current model created by the given user (user model)
179
- */
180
- isCreatedBy(user) {
181
- return this.get("createdBy.id") === user.id;
182
- }
183
- /**
184
- * Check if current model last updated by the given user (user model)
185
- */
186
- isUpdatedBy(user) {
187
- return this.get("updatedBy.id") === user.id;
188
- }
189
- /**
190
- * Get mongodb id
191
- */
192
- get _id() {
193
- return this.get("_id");
194
- }
195
- /**
196
- * Mark the current model as being restored
197
- */
198
- markAsRestored() {
199
- this.isRestored = true;
200
- }
201
- /**
202
- * Set a column in the model data
203
- */
204
- set(column, value) {
205
- const currentValue = this.get(column);
206
- this.data = set(this.data, column, value);
207
- if (currentValue !== value) {
208
- set(this.dirtyColumns, column, {
209
- oldValue: currentValue,
210
- newValue: value,
211
- });
212
- }
213
- return this;
214
- }
215
- /**
216
- * Increment the given column by the given value
217
- */
218
- increment(column, value = 1) {
219
- return this.set(column, this.get(column, 0) + value);
220
- }
221
- /**
222
- * Decrement the given column by the given value
223
- */
224
- decrement(column, value = 1) {
225
- return this.set(column, this.get(column, 0) - value);
226
- }
227
- /**
228
- * Get initial value of the given column
229
- */
230
- getInitial(column, defaultValue) {
231
- return get(this.initialData, column, defaultValue);
232
- }
233
- /**
234
- * Get value of the given column
235
- */
236
- get(column, defaultValue) {
237
- return get(this.data, column, defaultValue);
238
- }
239
- /**
240
- * Return the value of the given column as a string
241
- */
242
- string(column, defaultValue) {
243
- return String(this.get(column, defaultValue));
244
- }
245
- /**
246
- * Return the value of the given column as an integer
247
- */
248
- int(column, defaultValue) {
249
- return parseInt(this.get(column, defaultValue));
250
- }
251
- /**
252
- * Return the value of the given column as a float
253
- */
254
- float(column, defaultValue) {
255
- return parseFloat(this.get(column, defaultValue));
256
- }
257
- /**
258
- * Return the value of the given column as a number
259
- */
260
- number(column, defaultValue) {
261
- return Number(this.get(column, defaultValue));
262
- }
263
- /**
264
- * Return the value of the given column as a boolean
265
- */
266
- bool(column, defaultValue) {
267
- return Boolean(this.get(column, defaultValue));
268
- }
269
- /**
270
- * Determine whether the given column exists in the document
271
- */
272
- has(column) {
273
- return get(this.data, column) !== undefined;
274
- }
275
- /**
276
- * Get all columns except the given ones
277
- */
278
- except(columns) {
279
- return except(this.data, columns);
280
- }
281
- /**
282
- * Get only the given columns
283
- */
284
- only(columns) {
285
- return only(this.data, columns);
286
- }
287
- /**
288
- * Get only id
289
- */
290
- get onlyId() {
291
- return this.only(["id"]);
292
- }
293
- /**
294
- * Unset or remove the given columns from the data
295
- */
296
- unset(...columns) {
297
- const currentValues = this.only(columns);
298
- this.data = except(this.data, columns);
299
- for (const column in currentValues) {
300
- set(this.dirtyColumns, column, {
301
- oldValue: currentValues[column],
302
- newValue: undefined,
303
- });
304
- }
305
- return this;
306
- }
307
- /**
308
- * Get the value of the given column and remove it from the data
309
- */
310
- pluck(column) {
311
- const value = this.get(column);
312
- this.unset(column);
313
- return value;
314
- }
315
- /**
316
- * Replace the entire document data with the given new data
317
- */
318
- replaceWith(data) {
319
- if (!data.id && this.data.id) {
320
- data.id = this.data.id;
321
- }
322
- if (!data._id && this.data._id) {
323
- data._id = this.data._id;
324
- }
325
- const currentData = clone(data);
326
- this.data = data;
327
- const dirtyValues = deepDiff(currentData, this.data);
328
- merge(this.dirtyColumns, dirtyValues);
329
- return this;
330
- }
331
- /**
332
- * Merge the given documents to current document
333
- */
334
- merge(data) {
335
- const currentData = clone(this.data);
336
- this.data = merge(this.data, data);
337
- const dirtyValues = deepDiff(currentData, this.data);
338
- merge(this.dirtyColumns, dirtyValues);
339
- for (const column in this.data) {
340
- if (this.data[column] !== currentData[column]) {
341
- set(this.dirtyColumns, column, {
342
- oldValue: currentData[column],
343
- newValue: this.data[column],
344
- });
345
- }
346
- }
347
- return this;
348
- }
349
- /**
350
- * Push the given values to the given column
351
- * If the given column does not exists, it will be created
352
- * If the given value exists but not an array it will be ignored
353
- */
354
- push(column, ...values) {
355
- const currentValue = this.get(column);
356
- if (Array.isArray(currentValue)) {
357
- this.set(column, [...currentValue, ...values]);
358
- }
359
- else if (!currentValue) {
360
- this.set(column, values);
361
- }
362
- return this;
363
- }
364
- /**
365
- * Push the given values to the given column only if not exists
366
- */
367
- pushOnce(column, ...values) {
368
- const currentValue = this.get(column);
369
- if (Array.isArray(currentValue)) {
370
- const newValues = Array.from(new Set([...currentValue, ...values]));
371
- this.set(column, newValues);
372
- }
373
- else if (!currentValue) {
374
- this.set(column, values);
375
- }
376
- return this;
377
- }
378
- /**
379
- * Add the given values to the beginning of the given column
380
- * If the given column does not exists, it will be created
381
- * If the given value exists but not an array it will be ignored
382
- */
383
- unshift(column, ...values) {
384
- const currentValue = this.get(column);
385
- if (Array.isArray(currentValue)) {
386
- this.set(column, [...values, ...currentValue]);
387
- }
388
- else if (!currentValue) {
389
- this.set(column, values);
390
- }
391
- return this;
392
- }
393
- /**
394
- * Add the given values to the beginning of the given column only if not exists
395
- */
396
- unshiftOnce(column, ...values) {
397
- const currentValue = this.get(column);
398
- if (Array.isArray(currentValue)) {
399
- const newValues = Array.from(new Set([...values, ...currentValue]));
400
- this.set(column, newValues);
401
- }
402
- else if (!currentValue) {
403
- this.set(column, values);
404
- }
405
- return this;
406
- }
407
- async prepareDataForCreating(cast = true, triggerEvents = true) {
408
- // await this.getDatabase().startSessionContext(async ({ session }) => {
409
- // check for default values and merge it with the data
410
- await this.checkDefaultValues();
411
- // if the column does not exist, then create it
412
- if ((!this.data.id || !this.autoGeneratedId) &&
413
- this.getStaticProperty("autoGenerateId")) {
414
- this.autoGeneratedId = true;
415
- await this.generateNextId();
416
- }
417
- const now = new Date();
418
- const createdAtColumn = this.createdAtColumn;
419
- // if the column does not exist, then create it
420
- if (createdAtColumn && !this.data[createdAtColumn]) {
421
- this.data[createdAtColumn] = now;
422
- }
423
- // if the column does not exist, then create it
424
- const updatedAtColumn = this.updatedAtColumn;
425
- if (updatedAtColumn) {
426
- this.data[updatedAtColumn] = now;
427
- }
428
- if (cast) {
429
- await this.castData();
430
- }
431
- if (triggerEvents) {
432
- const selfModelEvents = this.getModelEvents();
433
- const ModelEvents = this.getBaseModelEvents();
434
- await this.onSaving();
435
- await this.onCreating();
436
- await selfModelEvents.trigger("creating", this);
437
- await selfModelEvents.trigger("saving", this);
438
- await ModelEvents.trigger("creating", this);
439
- await ModelEvents.trigger("saving", this);
440
- }
441
- }
442
- /**
443
- * Perform saving operation either by updating or creating a new record in database
444
- */
445
- async save(mergedData, { triggerEvents = true, cast = true, forceUpdate = false, } = {}) {
446
- const isNewModel = this.isNewModel();
447
- try {
448
- if (mergedData) {
449
- this.merge(mergedData);
450
- }
451
- // const logLevel = getDatabaseDebugLevel();
452
- let currentModel;
453
- // check if the data contains the primary id column
454
- if (!isNewModel) {
455
- // perform an update operation
456
- // check if the data has changed
457
- // if not changed, then do not do anything
458
- if (cast) {
459
- // this.logInfo("Casting data before saving");
460
- await this.castData(forceUpdate);
461
- // this.logInfo("Data has been casted");
462
- }
463
- if (this.shouldUpdate(this.originalData, this.data) === false) {
464
- return this;
465
- }
466
- currentModel = new this.constructor(this.originalData);
467
- const updatedAtColumn = this.updatedAtColumn;
468
- if (updatedAtColumn) {
469
- // updateAtColumn is supposed to be part of the Schema
470
- this.data[updatedAtColumn] = new Date();
471
- }
472
- if (triggerEvents) {
473
- const selfModelEvents = this.getModelEvents();
474
- const ModelEvents = this.getBaseModelEvents();
475
- await this.onSaving();
476
- await this.onUpdating();
477
- await selfModelEvents.trigger("updating", this, currentModel);
478
- await selfModelEvents.trigger("saving", this, currentModel);
479
- await ModelEvents.trigger("updating", this, currentModel);
480
- await ModelEvents.trigger("saving", this, currentModel);
481
- }
482
- // const data = { ...this.data };
483
- // if (isPlainObject(data._id)) {
484
- // delete data._id;
485
- // }
486
- const filter = {};
487
- if (isEmpty(this._id)) {
488
- filter._id = this.data._id;
489
- }
490
- else {
491
- filter.id = this.id;
492
- }
493
- await this.getQuery().replace(this.getCollection(), filter, this.data);
494
- if (triggerEvents) {
495
- this.triggerUpdatedEvents(currentModel);
496
- }
497
- }
498
- else {
499
- let tries = 3;
500
- while (tries > 0) {
501
- try {
502
- await this.prepareDataForCreating(cast, triggerEvents);
503
- this.data = (await this.getQuery().create(this.getCollection(), this.data));
504
- if (triggerEvents) {
505
- this.triggerCreatedEvents();
506
- }
507
- break;
508
- }
509
- catch (error) {
510
- console.log(error);
511
- // Handle duplicate key error
512
- if (error instanceof MongoServerError && error.code === 11000) {
513
- if (tries < 2) {
514
- const duplicateField = error.keyValue;
515
- const fieldName = Object.keys(duplicateField)[0];
516
- const errorMessage = `A record with the same ${fieldName} already exists.`;
517
- if (this.autoGeneratedId) {
518
- this.unset("id");
519
- }
520
- throw new Error(errorMessage);
521
- }
522
- else {
523
- tries--;
524
- }
525
- }
526
- throw error;
527
- }
528
- }
529
- }
530
- if (!this.data.id)
531
- return this;
532
- this.originalData = clone(this.data);
533
- // @see constructor
534
- this.originalData._id = this.data._id;
535
- return this;
536
- }
537
- catch (error) {
538
- console.log("Error in " + this.constructor.name + ".save()");
539
- console.log(error);
540
- throw error;
541
- }
542
- }
543
- /**
544
- * Serialize the model data for storage in database
545
- */
546
- serialize() {
547
- return {
548
- ...this.data,
549
- _id: this.data._id ? this.data._id.toString() : undefined,
550
- };
551
- }
552
- /**
553
- * Generate and return next id
554
- */
555
- async generateNextId() {
556
- this.set("id", await this.getStaticProperty("genNextId").bind(this.constructor)());
557
- return this.id;
558
- }
559
- /**
560
- * Trigger created events
561
- */
562
- triggerCreatedEvents() {
563
- const selfModelEvents = this.getModelEvents();
564
- const ModelEvents = this.getBaseModelEvents();
565
- this.onSaved();
566
- this.onCreated();
567
- selfModelEvents.trigger("created", this);
568
- selfModelEvents.trigger("saved", this);
569
- ModelEvents.trigger("created", this);
570
- ModelEvents.trigger("saved", this);
571
- this.startSyncing("create");
572
- }
573
- /**
574
- * Trigger updated events
575
- */
576
- triggerUpdatedEvents(oldModel) {
577
- const selfModelEvents = this.getModelEvents();
578
- const ModelEvents = this.getBaseModelEvents();
579
- this.onSaved();
580
- this.onUpdated();
581
- selfModelEvents.trigger("updated", this, oldModel);
582
- selfModelEvents.trigger("saved", this, oldModel);
583
- ModelEvents.trigger("updated", this, oldModel);
584
- ModelEvents.trigger("saved", this, oldModel);
585
- this.startSyncing("update", oldModel);
586
- }
587
- /**
588
- * Perform saving but without any events triggers
589
- */
590
- async silentSaving(mergedData, options) {
591
- return await this.save(mergedData, {
592
- triggerEvents: false,
593
- ...(options || {}),
594
- });
595
- }
596
- /**
597
- * Determine whether the model should be updated or not
598
- */
599
- shouldUpdate(originalData, data) {
600
- return areEqual(originalData, data) === false;
601
- }
602
- /**
603
- * Triggered before saving the model either by creating or updating
604
- */
605
- async onSaving() {
606
- //
607
- }
608
- /**
609
- * Triggered after saving the model either by creating or updating
610
- */
611
- async onSaved() {
612
- //
613
- }
614
- /**
615
- * Triggered before creating the model
616
- */
617
- async onCreating() {
618
- //
619
- }
620
- /**
621
- * Triggered after creating the model
622
- */
623
- async onCreated() {
624
- //
625
- }
626
- /**
627
- * Triggered before updating the model
628
- */
629
- async onUpdating() {
630
- //
631
- }
632
- /**
633
- * Triggered after updating the model
634
- */
635
- async onUpdated() {
636
- //
637
- }
638
- /**
639
- * Triggered before deleting the model
640
- */
641
- async onDeleting() {
642
- //
643
- }
644
- /**
645
- * Triggered after deleting the model
646
- */
647
- async onDeleted() {
648
- //
649
- }
650
- /**
651
- * Cast data before saving
652
- */
653
- async castData(forceUpdate = false) {
654
- for (const column in this.casts) {
655
- if (!forceUpdate && !this.isDirty(column)) {
656
- continue;
657
- }
658
- let value = this.get(column);
659
- if (value === undefined)
660
- continue;
661
- const castType = this.casts[column];
662
- const castValue = async (value) => {
663
- if (castType.prototype instanceof Model) {
664
- // if cast type is passed as model class, then get its embedded data
665
- value = await castModel(castType)(value);
666
- }
667
- else if (castType?.model) {
668
- // it means the user is passing a custom model embedding i.e Model.embed('embedToProduct') => Product to embed from the getter property
669
- // embedToProduct
670
- // @see EmbeddedModel
671
- value = await castModel(castType.model, castType.embeddedKey)(value);
672
- }
673
- else if (typeof castType === "object") {
674
- // it means the user is passing an enum object
675
- value = await castEnum(castType)(value);
676
- }
677
- else if (value instanceof Model) {
678
- value = value.embeddedData;
679
- }
680
- else if (typeof castType === "function") {
681
- value = await castType(value, column, this);
682
- }
683
- else {
684
- value = this.castValue(value, castType);
685
- }
686
- return value;
687
- };
688
- // if the cast type is passed in array
689
- // it means we just need to pass the value to the first function
690
- // second argument will be the column name
691
- // and the third argument will be the model instance
692
- if (Array.isArray(castType)) {
693
- value = await castType[0](value, column, this);
694
- }
695
- else if (Array.isArray(value) && castType !== "localized") {
696
- // if cast type is array, then we'll keep the value as it is
697
- // now we want to add a new validation rule that to check
698
- // if the value is an array of localized objects
699
- // if so, then each value in the array should have `localeCode` and `value` keys
700
- // if so, then it will be cast only to the value key inside each object
701
- // so the final output will be localeCode and `castValue` of the value key
702
- if (castType === "array") ;
703
- else if (value[0]?.localeCode && value[0]?.value) {
704
- value = await Promise.all(value.map(async (item) => {
705
- return {
706
- localeCode: item.localeCode,
707
- value: await castValue(item.value),
708
- };
709
- }));
710
- }
711
- else {
712
- value = await Promise.all(value.map(async (item) => {
713
- return await castValue(item);
714
- }));
715
- }
716
- }
717
- else {
718
- value = await castValue(value);
719
- }
720
- if (Array.isArray(value)) {
721
- value = value.filter(value => value !== null && value !== undefined);
722
- }
723
- if (value !== undefined) {
724
- this.set(column, value);
725
- }
726
- else {
727
- this.unset(column);
728
- }
729
- }
730
- for (const column in this.customCasts) {
731
- const castType = this.customCasts[column];
732
- const value = await castType(this, column);
733
- if (value !== undefined) {
734
- this.set(column, value);
735
- }
736
- else {
737
- this.unset(column);
738
- }
739
- }
740
- }
741
- /**
742
- * Return only the given columns to be used in output
743
- */
744
- outputOnly(columns) {
745
- return this.clone(this.only(columns));
746
- }
747
- /**
748
- * Return all columns except the given columns to be used in output
749
- */
750
- outputExcept(columns) {
751
- return this.clone(this.except(columns));
752
- }
753
- /**
754
- * Cast the given value based on the given cast type
755
- */
756
- castValue(value, castType) {
757
- const isEmptyValue = isEmpty(value);
758
- if (typeof value === "object") {
759
- if (value === null)
760
- return undefined;
761
- }
762
- else if (isEmptyValue)
763
- return undefined;
764
- switch (castType) {
765
- case "string":
766
- return isEmptyValue ? "" : String(value).trim();
767
- case "localized":
768
- // if (isEmptyValue) return [];
769
- // if (!Array.isArray(value)) return [];
770
- if (!Array.isArray(value))
771
- return undefined;
772
- return value
773
- .filter(value => !isEmpty(value) && isPlainObject(value))
774
- .map(item => {
775
- return {
776
- localeCode: item.localeCode,
777
- value: item.value,
778
- };
779
- });
780
- case "number":
781
- // return isEmptyValue ? 0 : Number(value);
782
- return Number(value);
783
- case "int":
784
- case "integer":
785
- // return isEmptyValue ? 0 : parseInt(value);
786
- return parseInt(value);
787
- case "float":
788
- // return isEmptyValue ? 0 : parseFloat(value);
789
- return parseFloat(value);
790
- case "bool":
791
- case "boolean": {
792
- // if (isEmptyValue) return false;
793
- if (value === "true")
794
- return true;
795
- if (value === "false" || value === "0" || value === 0)
796
- return false;
797
- return Boolean(value);
798
- }
799
- case "date": {
800
- if (dayjs.isDayjs(value)) {
801
- value = value.toDate();
802
- }
803
- if (value instanceof Date) {
804
- return toUTC(value);
805
- }
806
- return toUTC(new Date(value));
807
- }
808
- case "location": {
809
- // if (isEmptyValue) return null;
810
- const lat = value?.[0] || value?.lat;
811
- const lng = value?.[1] || value?.lng;
812
- const address = value?.address || value?.formattedAddress;
813
- return {
814
- type: "Point",
815
- coordinates: [Number(lat), Number(lng)],
816
- address,
817
- };
818
- }
819
- case "object": {
820
- // if (isEmptyValue) return {};
821
- if (typeof value === "string") {
822
- try {
823
- return JSON.parse(value);
824
- }
825
- catch (error) {
826
- return undefined;
827
- }
828
- }
829
- return value;
830
- }
831
- case "array": {
832
- // if (isEmptyValue) return [];
833
- if (typeof value === "string") {
834
- return JSON.parse(value);
835
- }
836
- return value;
837
- }
838
- case "mixed":
839
- case "any":
840
- default:
841
- return value;
842
- }
843
- }
844
- /**
845
- * Check for default values
846
- */
847
- checkDefaultValues() {
848
- // if default value is empty, then do nothing
849
- if (isEmpty(this.defaultValue))
850
- return;
851
- const defaultValue = { ...this.defaultValue };
852
- for (const key in defaultValue) {
853
- const value = defaultValue[key];
854
- if (typeof value === "function") {
855
- defaultValue[key] = value(this);
856
- }
857
- }
858
- // merge the data with default value
859
- this.data = merge(defaultValue, this.data);
860
- }
861
- /**
862
- * Destroy the model and delete it from database collection
863
- */
864
- async destroy() {
865
- if (!this.data._id)
866
- return;
867
- if (this.deletedAtColumn) {
868
- this.set(this.deletedAtColumn, new Date());
869
- }
870
- const deleteStrategy = this.getStaticProperty("deleteStrategy");
871
- if (deleteStrategy === ModelDeleteStrategy.moveToTrash) {
872
- const collectionName = this.getCollection();
873
- class Trash extends Model {
874
- static collection = collectionName + "Trash";
875
- }
876
- // we need to wrap the trash collection inside a model class so it get a generated timestamps and id
877
- Trash.create({
878
- document: this.data,
879
- });
880
- }
881
- const selfModelEvents = this.getModelEvents();
882
- const ModelEvents = this.getBaseModelEvents();
883
- await this.onDeleting();
884
- await selfModelEvents.trigger("deleting", this);
885
- await ModelEvents.trigger("deleting", this);
886
- // the document will be deleted from database collection if the delete strategy is not soft delete
887
- if (deleteStrategy !== ModelDeleteStrategy.softDelete) {
888
- await this.getQuery().deleteOne(this.getCollection(), {
889
- _id: this.data._id,
890
- });
891
- }
892
- else if (deleteStrategy === ModelDeleteStrategy.softDelete) {
893
- await this.getQuery().updateOne(this.getCollection(), {
894
- _id: this.data._id,
895
- }, this.data);
896
- }
897
- this.onDeleted();
898
- selfModelEvents.trigger("deleted", this);
899
- ModelEvents.trigger("deleted", this);
900
- this.syncDestruction();
901
- }
902
- /**
903
- * Determine if the given column is dirty column
904
- *
905
- * Dirty columns are columns that their values have been changed from the original data
906
- */
907
- isDirty(column) {
908
- if (!column) {
909
- return areEqual(clone(this.data), clone(this.originalData)) === false;
910
- }
911
- if (this.isNewModel())
912
- return true;
913
- const currentValue = get(this.data, column);
914
- const originalValue = get(this.originalData, column);
915
- return areEqual(clone(currentValue), clone(originalValue)) === false;
916
- }
917
- /**
918
- * Check if current model is a new model
919
- */
920
- isNewModel() {
921
- // Check initial data instead of current data since it represents
922
- // the original state when the model was instantiated
923
- const hasMongoId = Boolean(this.data._id) && !this.isRestored;
924
- // Check for numeric id in initial data
925
- // const hasNumericId = Boolean(this.data?.id) && !this.isRestored;
926
- return !hasMongoId;
927
- }
928
- /**
929
- * Get embedded data
930
- */
931
- get embeddedData() {
932
- if (this.embedAllExcept.length > 0) {
933
- return except(this.data, this.embedAllExcept);
934
- }
935
- if (this.embedAllExceptTimestampsAndUserColumns) {
936
- return except(this.data, [
937
- this.createdAtColumn,
938
- this.updatedAtColumn,
939
- this.deletedAtColumn,
940
- this.createdByColumn,
941
- this.updatedByColumn,
942
- this.deletedByColumn,
943
- ]);
944
- }
945
- return this.embedded.length > 0 ? this.only(this.embedded) : this.data;
946
- }
947
- /**
948
- * Clone the model
949
- */
950
- clone(data = this.data) {
951
- return new this.constructor(clone(data));
952
- }
953
- /**
954
- * Get relationship with the given model class
955
- */
956
- hasMany(modelClass, column) {
957
- return new RelationshipWithMany(this, modelClass, column);
958
- }
959
- /**
960
- * Get new aggregate for current model
961
- */
962
- static aggregate() {
963
- return new ModelAggregate(this);
964
- }
965
- /**
966
- * @alias aggregate
967
- */
968
- static newQuery() {
969
- return this.aggregate();
970
- }
971
- /**
972
- * Get query builder
973
- * @alias aggregate
974
- */
975
- static queryBuilder() {
976
- return new ModelAggregate(this);
977
- }
978
- /**
979
- * Sync with the given model
980
- */
981
- static sync(columns, embedMethod = "embedData") {
982
- return new ModelSync(this, columns, embedMethod);
983
- }
984
- /**
985
- * Sync data on saving
986
- */
987
- startSyncing(saveMode, oldModel) {
988
- for (const modelSync of this.syncWith) {
989
- modelSync.sync(this, saveMode, oldModel);
990
- }
991
- }
992
- /**
993
- * Sync destruction
994
- * Called when destroy method is called
995
- */
996
- syncDestruction() {
997
- for (const modelSync of this.syncWith) {
998
- modelSync.syncDestruction(this);
999
- }
1000
- }
1001
- /**
1002
- * The syncing model (That calls startSyncing) is being embedded in multiple documents of current model
1003
- * I.e Country.syncMany('cities') while current model is City
1004
- */
1005
- static syncMany(columns, embedMethod = "embedData") {
1006
- return new ModelSync(this, columns, embedMethod).syncMany();
1007
- }
1008
- /**
1009
- * Reassociate a model/object/document with the current model
1010
- * If the model is already associated, it will be updated
1011
- * If not, it will be associated
1012
- * the model/document must have an id
1013
- *
1014
- * If it is a model, you can set the embed method to use
1015
- */
1016
- reassociate(column, model, embedWith) {
1017
- const columnValue = model instanceof Model
1018
- ? embedWith
1019
- ? model[embedWith]()
1020
- : model.embeddedData
1021
- : model;
1022
- if (columnValue === undefined)
1023
- return this;
1024
- // make a deep copy so when changing the data, it won't affect the original data
1025
- const documentsList = clone(this.get(column, []));
1026
- const index = documentsList.findIndex((doc) => (doc?.id || doc) === (columnValue?.id || columnValue));
1027
- if (index === -1) {
1028
- documentsList.push(columnValue);
1029
- }
1030
- else {
1031
- documentsList[index] = columnValue;
1032
- }
1033
- this.set(column, [...documentsList]);
1034
- return this;
1035
- }
1036
- /**
1037
- * Associate a model with the current model
1038
- */
1039
- associate(column, model, embedWith) {
1040
- const columnValue = model instanceof Model
1041
- ? embedWith
1042
- ? model[embedWith]()
1043
- : model.embeddedData
1044
- : model;
1045
- if (columnValue === undefined)
1046
- return this;
1047
- const documentsList = this.get(column, []);
1048
- documentsList.push(columnValue);
1049
- this.set(column, documentsList);
1050
- return this;
1051
- }
1052
- /**
1053
- * Disassociate a model with the current model
1054
- */
1055
- disassociate(column, model) {
1056
- const columnValue = model instanceof Model ? model.embeddedData : model;
1057
- if (columnValue === undefined)
1058
- return this;
1059
- const documentsList = this.get(column, []);
1060
- if (!Array.isArray(documentsList))
1061
- return this;
1062
- const index = documentsList.findIndex((doc) => (doc?.id || doc) === (columnValue?.id || columnValue));
1063
- if (index !== -1) {
1064
- documentsList.splice(index, 1);
1065
- }
1066
- this.set(column, documentsList);
1067
- return this;
1068
- }
1069
- /**
1070
- * Refresh the model with new data from database
1071
- * This method will update the current data with the new data from database
1072
- */
1073
- async refresh() {
1074
- const key = this.data._id ? "_id" : "id";
1075
- const value = this.data._id ?? this.data.id;
1076
- const data = await this.getQuery().first(this.getCollection(), {
1077
- [key]: value,
1078
- });
1079
- if (!data)
1080
- return;
1081
- this.data = data;
1082
- return this;
1083
- }
1084
- /**
1085
- * Fetch data from database and return it in a new model
1086
- */
1087
- async reload() {
1088
- const key = this.data._id ? "_id" : "id";
1089
- const value = this.data._id ?? this.data.id;
1090
- if (!value) {
1091
- throw new Error("Model ID is required to reload the model");
1092
- }
1093
- const data = await this.getQuery().first(this.getCollection(), {
1094
- [key]: value,
1095
- });
1096
- return new this.constructor(data);
1097
- }
1098
- /**
1099
- * Make a wrapper to list when models should be updated when only one of the given columns is updated
1100
- */
1101
- syncUpdateWhenChange(columns, syncModels) {
1102
- return syncModels.map(syncModel => {
1103
- syncModel.updateWhenChange(columns);
1104
- return syncModel;
1105
- });
1106
- }
1107
- /**
1108
- * Get a Joinable instance for current model
1109
- */
1110
- static joinable(
1111
- /**
1112
- * Local field to the current model
1113
- */
1114
- localField,
1115
- /**
1116
- * Foreign field in the joinable model
1117
- */
1118
- foreignField, single, as) {
1119
- const joinable = new Joinable(this);
1120
- if (localField) {
1121
- joinable.localField(localField);
1122
- }
1123
- if (foreignField) {
1124
- joinable.foreignField(foreignField);
1125
- }
1126
- if (single) {
1127
- joinable.single(single);
1128
- }
1129
- if (as) {
1130
- joinable.as(as);
1131
- }
1132
- return joinableProxy(joinable);
1133
- }
1134
- }export{Model};//# sourceMappingURL=model.js.map