@warlock.js/cascade 4.0.48 → 4.0.58

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 (401) hide show
  1. package/cjs/context/database-data-source-context.d.ts +29 -0
  2. package/cjs/context/database-data-source-context.d.ts.map +1 -0
  3. package/cjs/context/database-data-source-context.js +28 -0
  4. package/cjs/context/database-data-source-context.js.map +1 -0
  5. package/cjs/context/database-transaction-context.d.ts +31 -0
  6. package/cjs/context/database-transaction-context.d.ts.map +1 -0
  7. package/cjs/context/database-transaction-context.js +34 -0
  8. package/cjs/context/database-transaction-context.js.map +1 -0
  9. package/cjs/contracts/database-driver.contract.d.ts +143 -0
  10. package/cjs/contracts/database-driver.contract.d.ts.map +1 -0
  11. package/cjs/contracts/database-id-generator.contract.d.ts +109 -0
  12. package/cjs/contracts/database-id-generator.contract.d.ts.map +1 -0
  13. package/cjs/contracts/database-remover.contract.d.ts +104 -0
  14. package/cjs/contracts/database-remover.contract.d.ts.map +1 -0
  15. package/cjs/contracts/database-restorer.contract.d.ts +143 -0
  16. package/cjs/contracts/database-restorer.contract.d.ts.map +1 -0
  17. package/cjs/contracts/database-writer.contract.d.ts +119 -0
  18. package/cjs/contracts/database-writer.contract.d.ts.map +1 -0
  19. package/cjs/contracts/driver-blueprint.contract.d.ts +45 -0
  20. package/cjs/contracts/driver-blueprint.contract.d.ts.map +1 -0
  21. package/cjs/contracts/index.d.ts +10 -0
  22. package/cjs/contracts/index.d.ts.map +1 -0
  23. package/cjs/contracts/migration-driver.contract.d.ts +365 -0
  24. package/cjs/contracts/migration-driver.contract.d.ts.map +1 -0
  25. package/cjs/contracts/query-builder.contract.d.ts +1128 -0
  26. package/cjs/contracts/query-builder.contract.d.ts.map +1 -0
  27. package/cjs/contracts/sync-adapter.contract.d.ts +58 -0
  28. package/cjs/contracts/sync-adapter.contract.d.ts.map +1 -0
  29. package/cjs/data-source/data-source-registry.d.ts +104 -0
  30. package/cjs/data-source/data-source-registry.d.ts.map +1 -0
  31. package/cjs/data-source/data-source-registry.js +138 -0
  32. package/cjs/data-source/data-source-registry.js.map +1 -0
  33. package/cjs/data-source/data-source.d.ts +106 -0
  34. package/cjs/data-source/data-source.d.ts.map +1 -0
  35. package/cjs/data-source/data-source.js +77 -0
  36. package/cjs/data-source/data-source.js.map +1 -0
  37. package/cjs/database-dirty-tracker.d.ts +253 -0
  38. package/cjs/database-dirty-tracker.d.ts.map +1 -0
  39. package/cjs/database-dirty-tracker.js +389 -0
  40. package/cjs/database-dirty-tracker.js.map +1 -0
  41. package/cjs/drivers/mongo/mongo-id-generator.d.ts +116 -0
  42. package/cjs/drivers/mongo/mongo-id-generator.d.ts.map +1 -0
  43. package/cjs/drivers/mongo/mongo-id-generator.js +149 -0
  44. package/cjs/drivers/mongo/mongo-id-generator.js.map +1 -0
  45. package/cjs/drivers/mongo/mongo-migration-driver.d.ts +228 -0
  46. package/cjs/drivers/mongo/mongo-migration-driver.d.ts.map +1 -0
  47. package/cjs/drivers/mongo/mongo-migration-driver.js +524 -0
  48. package/cjs/drivers/mongo/mongo-migration-driver.js.map +1 -0
  49. package/cjs/drivers/mongo/mongo-query-builder.d.ts +922 -0
  50. package/cjs/drivers/mongo/mongo-query-builder.d.ts.map +1 -0
  51. package/cjs/drivers/mongo/mongo-query-builder.js +1740 -0
  52. package/cjs/drivers/mongo/mongo-query-builder.js.map +1 -0
  53. package/cjs/drivers/mongo/mongo-query-operations.d.ts +226 -0
  54. package/cjs/drivers/mongo/mongo-query-operations.d.ts.map +1 -0
  55. package/cjs/drivers/mongo/mongo-query-operations.js +270 -0
  56. package/cjs/drivers/mongo/mongo-query-operations.js.map +1 -0
  57. package/cjs/drivers/mongo/mongo-query-parser.d.ts +262 -0
  58. package/cjs/drivers/mongo/mongo-query-parser.d.ts.map +1 -0
  59. package/cjs/drivers/mongo/mongo-query-parser.js +1351 -0
  60. package/cjs/drivers/mongo/mongo-query-parser.js.map +1 -0
  61. package/cjs/drivers/mongo/mongo-sync-adapter.d.ts +79 -0
  62. package/cjs/drivers/mongo/mongo-sync-adapter.d.ts.map +1 -0
  63. package/cjs/drivers/mongo/mongo-sync-adapter.js +146 -0
  64. package/cjs/drivers/mongo/mongo-sync-adapter.js.map +1 -0
  65. package/cjs/drivers/mongo/mongodb-blueprint.d.ts +30 -0
  66. package/cjs/drivers/mongo/mongodb-blueprint.d.ts.map +1 -0
  67. package/cjs/drivers/mongo/mongodb-blueprint.js +51 -0
  68. package/cjs/drivers/mongo/mongodb-blueprint.js.map +1 -0
  69. package/cjs/drivers/mongo/mongodb-driver.d.ts +188 -0
  70. package/cjs/drivers/mongo/mongodb-driver.d.ts.map +1 -0
  71. package/cjs/drivers/mongo/mongodb-driver.js +411 -0
  72. package/cjs/drivers/mongo/mongodb-driver.js.map +1 -0
  73. package/cjs/drivers/mongo/types.d.ts +43 -0
  74. package/cjs/drivers/mongo/types.d.ts.map +1 -0
  75. package/cjs/errors/missing-data-source.error.d.ts +22 -0
  76. package/cjs/errors/missing-data-source.error.d.ts.map +1 -0
  77. package/cjs/errors/missing-data-source.error.js +29 -0
  78. package/cjs/errors/missing-data-source.error.js.map +1 -0
  79. package/cjs/events/model-events.d.ts +231 -0
  80. package/cjs/events/model-events.d.ts.map +1 -0
  81. package/cjs/events/model-events.js +259 -0
  82. package/cjs/events/model-events.js.map +1 -0
  83. package/cjs/expressions/aggregate-expressions.d.ts +215 -0
  84. package/cjs/expressions/aggregate-expressions.d.ts.map +1 -0
  85. package/cjs/expressions/aggregate-expressions.js +221 -0
  86. package/cjs/expressions/aggregate-expressions.js.map +1 -0
  87. package/cjs/expressions/index.d.ts +2 -0
  88. package/cjs/expressions/index.d.ts.map +1 -0
  89. package/cjs/index.d.ts +41 -0
  90. package/cjs/index.d.ts.map +1 -0
  91. package/cjs/index.js +1 -267
  92. package/cjs/index.js.map +1 -1
  93. package/cjs/migration/column-builder.d.ts +167 -0
  94. package/cjs/migration/column-builder.d.ts.map +1 -0
  95. package/cjs/migration/column-builder.js +217 -0
  96. package/cjs/migration/column-builder.js.map +1 -0
  97. package/cjs/migration/foreign-key-builder.d.ts +110 -0
  98. package/cjs/migration/foreign-key-builder.d.ts.map +1 -0
  99. package/cjs/migration/foreign-key-builder.js +129 -0
  100. package/cjs/migration/foreign-key-builder.js.map +1 -0
  101. package/cjs/migration/index.d.ts +6 -0
  102. package/cjs/migration/index.d.ts.map +1 -0
  103. package/cjs/migration/migration-runner.d.ts +231 -0
  104. package/cjs/migration/migration-runner.d.ts.map +1 -0
  105. package/cjs/migration/migration-runner.js +443 -0
  106. package/cjs/migration/migration-runner.js.map +1 -0
  107. package/cjs/migration/migration.js +1346 -0
  108. package/cjs/migration/migration.js.map +1 -0
  109. package/cjs/migration/types.d.ts +132 -0
  110. package/cjs/migration/types.d.ts.map +1 -0
  111. package/cjs/model/model.d.ts +1267 -0
  112. package/cjs/model/model.d.ts.map +1 -0
  113. package/cjs/model/model.js +1463 -0
  114. package/cjs/model/model.js.map +1 -0
  115. package/cjs/model/register-model.d.ts +80 -0
  116. package/cjs/model/register-model.d.ts.map +1 -0
  117. package/cjs/model/register-model.js +91 -0
  118. package/cjs/model/register-model.js.map +1 -0
  119. package/cjs/remover/database-remover.d.ts +100 -0
  120. package/cjs/remover/database-remover.d.ts.map +1 -0
  121. package/cjs/remover/database-remover.js +209 -0
  122. package/cjs/remover/database-remover.js.map +1 -0
  123. package/cjs/restorer/database-restorer.d.ts +131 -0
  124. package/cjs/restorer/database-restorer.d.ts.map +1 -0
  125. package/cjs/restorer/database-restorer.js +425 -0
  126. package/cjs/restorer/database-restorer.js.map +1 -0
  127. package/cjs/sync/index.d.ts +12 -0
  128. package/cjs/sync/index.d.ts.map +1 -0
  129. package/cjs/sync/model-events.d.ts +62 -0
  130. package/cjs/sync/model-events.d.ts.map +1 -0
  131. package/cjs/sync/model-events.js +49 -0
  132. package/cjs/sync/model-events.js.map +1 -0
  133. package/cjs/sync/model-sync-operation.d.ts +163 -0
  134. package/cjs/sync/model-sync-operation.d.ts.map +1 -0
  135. package/cjs/sync/model-sync-operation.js +292 -0
  136. package/cjs/sync/model-sync-operation.js.map +1 -0
  137. package/cjs/sync/model-sync.d.ts +130 -0
  138. package/cjs/sync/model-sync.d.ts.map +1 -0
  139. package/cjs/sync/model-sync.js +178 -0
  140. package/cjs/sync/model-sync.js.map +1 -0
  141. package/cjs/sync/sync-context.d.ts +70 -0
  142. package/cjs/sync/sync-context.d.ts.map +1 -0
  143. package/cjs/sync/sync-context.js +101 -0
  144. package/cjs/sync/sync-context.js.map +1 -0
  145. package/cjs/sync/sync-manager.d.ts +213 -0
  146. package/cjs/sync/sync-manager.d.ts.map +1 -0
  147. package/cjs/sync/sync-manager.js +689 -0
  148. package/cjs/sync/sync-manager.js.map +1 -0
  149. package/cjs/sync/types.d.ts +289 -0
  150. package/cjs/sync/types.d.ts.map +1 -0
  151. package/cjs/types.d.ts +45 -0
  152. package/cjs/types.d.ts.map +1 -0
  153. package/cjs/utils/connect-to-database.d.ts +246 -0
  154. package/cjs/utils/connect-to-database.d.ts.map +1 -0
  155. package/cjs/utils/connect-to-database.js +92 -0
  156. package/cjs/utils/connect-to-database.js.map +1 -0
  157. package/cjs/utils/database-writer.utils.d.ts +15 -0
  158. package/cjs/utils/database-writer.utils.d.ts.map +1 -0
  159. package/cjs/utils/database-writer.utils.js +14 -0
  160. package/cjs/utils/database-writer.utils.js.map +1 -0
  161. package/cjs/utils/define-model.js +100 -0
  162. package/cjs/utils/define-model.js.map +1 -0
  163. package/cjs/utils/once-connected.d.ts +146 -0
  164. package/cjs/utils/once-connected.d.ts.map +1 -0
  165. package/cjs/utils/once-connected.js +252 -0
  166. package/cjs/utils/once-connected.js.map +1 -0
  167. package/cjs/validation/database-seal-plugins.d.ts +2 -0
  168. package/cjs/validation/database-seal-plugins.d.ts.map +1 -0
  169. package/cjs/validation/database-seal-plugins.js +4 -0
  170. package/cjs/validation/database-seal-plugins.js.map +1 -0
  171. package/cjs/validation/database-writer-validation-error.d.ts +97 -0
  172. package/cjs/validation/database-writer-validation-error.d.ts.map +1 -0
  173. package/cjs/validation/database-writer-validation-error.js +160 -0
  174. package/cjs/validation/database-writer-validation-error.js.map +1 -0
  175. package/cjs/validation/index.d.ts +3 -0
  176. package/cjs/validation/index.d.ts.map +1 -0
  177. package/cjs/validation/mutators/embed-mutator.d.ts +9 -0
  178. package/cjs/validation/mutators/embed-mutator.d.ts.map +1 -0
  179. package/cjs/validation/mutators/embed-mutator.js +33 -0
  180. package/cjs/validation/mutators/embed-mutator.js.map +1 -0
  181. package/cjs/validation/plugins/embed-validator-plugin.d.ts +24 -0
  182. package/cjs/validation/plugins/embed-validator-plugin.d.ts.map +1 -0
  183. package/cjs/validation/plugins/embed-validator-plugin.js +18 -0
  184. package/cjs/validation/plugins/embed-validator-plugin.js.map +1 -0
  185. package/cjs/validation/rules/database-model-rule.d.ts +7 -0
  186. package/cjs/validation/rules/database-model-rule.d.ts.map +1 -0
  187. package/cjs/validation/rules/database-model-rule.js +27 -0
  188. package/cjs/validation/rules/database-model-rule.js.map +1 -0
  189. package/cjs/validation/transformers/embed-model-transformer.d.ts +3 -0
  190. package/cjs/validation/transformers/embed-model-transformer.d.ts.map +1 -0
  191. package/cjs/validation/transformers/embed-model-transformer.js +18 -0
  192. package/cjs/validation/transformers/embed-model-transformer.js.map +1 -0
  193. package/cjs/validation/validators/embed-validator.d.ts +21 -0
  194. package/cjs/validation/validators/embed-validator.d.ts.map +1 -0
  195. package/cjs/validation/validators/embed-validator.js +42 -0
  196. package/cjs/validation/validators/embed-validator.js.map +1 -0
  197. package/cjs/writer/database-writer.d.ts +181 -0
  198. package/cjs/writer/database-writer.d.ts.map +1 -0
  199. package/cjs/writer/database-writer.js +402 -0
  200. package/cjs/writer/database-writer.js.map +1 -0
  201. package/esm/context/database-data-source-context.d.ts +29 -0
  202. package/esm/context/database-data-source-context.d.ts.map +1 -0
  203. package/esm/context/database-data-source-context.js +28 -0
  204. package/esm/context/database-data-source-context.js.map +1 -0
  205. package/esm/context/database-transaction-context.d.ts +31 -0
  206. package/esm/context/database-transaction-context.d.ts.map +1 -0
  207. package/esm/context/database-transaction-context.js +34 -0
  208. package/esm/context/database-transaction-context.js.map +1 -0
  209. package/esm/contracts/database-driver.contract.d.ts +143 -0
  210. package/esm/contracts/database-driver.contract.d.ts.map +1 -0
  211. package/esm/contracts/database-id-generator.contract.d.ts +109 -0
  212. package/esm/contracts/database-id-generator.contract.d.ts.map +1 -0
  213. package/esm/contracts/database-remover.contract.d.ts +104 -0
  214. package/esm/contracts/database-remover.contract.d.ts.map +1 -0
  215. package/esm/contracts/database-restorer.contract.d.ts +143 -0
  216. package/esm/contracts/database-restorer.contract.d.ts.map +1 -0
  217. package/esm/contracts/database-writer.contract.d.ts +119 -0
  218. package/esm/contracts/database-writer.contract.d.ts.map +1 -0
  219. package/esm/contracts/driver-blueprint.contract.d.ts +45 -0
  220. package/esm/contracts/driver-blueprint.contract.d.ts.map +1 -0
  221. package/esm/contracts/index.d.ts +10 -0
  222. package/esm/contracts/index.d.ts.map +1 -0
  223. package/esm/contracts/migration-driver.contract.d.ts +365 -0
  224. package/esm/contracts/migration-driver.contract.d.ts.map +1 -0
  225. package/esm/contracts/query-builder.contract.d.ts +1128 -0
  226. package/esm/contracts/query-builder.contract.d.ts.map +1 -0
  227. package/esm/contracts/sync-adapter.contract.d.ts +58 -0
  228. package/esm/contracts/sync-adapter.contract.d.ts.map +1 -0
  229. package/esm/data-source/data-source-registry.d.ts +104 -0
  230. package/esm/data-source/data-source-registry.d.ts.map +1 -0
  231. package/esm/data-source/data-source-registry.js +138 -0
  232. package/esm/data-source/data-source-registry.js.map +1 -0
  233. package/esm/data-source/data-source.d.ts +106 -0
  234. package/esm/data-source/data-source.d.ts.map +1 -0
  235. package/esm/data-source/data-source.js +77 -0
  236. package/esm/data-source/data-source.js.map +1 -0
  237. package/esm/database-dirty-tracker.d.ts +253 -0
  238. package/esm/database-dirty-tracker.d.ts.map +1 -0
  239. package/esm/database-dirty-tracker.js +389 -0
  240. package/esm/database-dirty-tracker.js.map +1 -0
  241. package/esm/drivers/mongo/mongo-id-generator.d.ts +116 -0
  242. package/esm/drivers/mongo/mongo-id-generator.d.ts.map +1 -0
  243. package/esm/drivers/mongo/mongo-id-generator.js +149 -0
  244. package/esm/drivers/mongo/mongo-id-generator.js.map +1 -0
  245. package/esm/drivers/mongo/mongo-migration-driver.d.ts +228 -0
  246. package/esm/drivers/mongo/mongo-migration-driver.d.ts.map +1 -0
  247. package/esm/drivers/mongo/mongo-migration-driver.js +524 -0
  248. package/esm/drivers/mongo/mongo-migration-driver.js.map +1 -0
  249. package/esm/drivers/mongo/mongo-query-builder.d.ts +922 -0
  250. package/esm/drivers/mongo/mongo-query-builder.d.ts.map +1 -0
  251. package/esm/drivers/mongo/mongo-query-builder.js +1740 -0
  252. package/esm/drivers/mongo/mongo-query-builder.js.map +1 -0
  253. package/esm/drivers/mongo/mongo-query-operations.d.ts +226 -0
  254. package/esm/drivers/mongo/mongo-query-operations.d.ts.map +1 -0
  255. package/esm/drivers/mongo/mongo-query-operations.js +270 -0
  256. package/esm/drivers/mongo/mongo-query-operations.js.map +1 -0
  257. package/esm/drivers/mongo/mongo-query-parser.d.ts +262 -0
  258. package/esm/drivers/mongo/mongo-query-parser.d.ts.map +1 -0
  259. package/esm/drivers/mongo/mongo-query-parser.js +1351 -0
  260. package/esm/drivers/mongo/mongo-query-parser.js.map +1 -0
  261. package/esm/drivers/mongo/mongo-sync-adapter.d.ts +79 -0
  262. package/esm/drivers/mongo/mongo-sync-adapter.d.ts.map +1 -0
  263. package/esm/drivers/mongo/mongo-sync-adapter.js +146 -0
  264. package/esm/drivers/mongo/mongo-sync-adapter.js.map +1 -0
  265. package/esm/drivers/mongo/mongodb-blueprint.d.ts +30 -0
  266. package/esm/drivers/mongo/mongodb-blueprint.d.ts.map +1 -0
  267. package/esm/drivers/mongo/mongodb-blueprint.js +51 -0
  268. package/esm/drivers/mongo/mongodb-blueprint.js.map +1 -0
  269. package/esm/drivers/mongo/mongodb-driver.d.ts +188 -0
  270. package/esm/drivers/mongo/mongodb-driver.d.ts.map +1 -0
  271. package/esm/drivers/mongo/mongodb-driver.js +411 -0
  272. package/esm/drivers/mongo/mongodb-driver.js.map +1 -0
  273. package/esm/drivers/mongo/types.d.ts +43 -0
  274. package/esm/drivers/mongo/types.d.ts.map +1 -0
  275. package/esm/errors/missing-data-source.error.d.ts +22 -0
  276. package/esm/errors/missing-data-source.error.d.ts.map +1 -0
  277. package/esm/errors/missing-data-source.error.js +29 -0
  278. package/esm/errors/missing-data-source.error.js.map +1 -0
  279. package/esm/events/model-events.d.ts +231 -0
  280. package/esm/events/model-events.d.ts.map +1 -0
  281. package/esm/events/model-events.js +259 -0
  282. package/esm/events/model-events.js.map +1 -0
  283. package/esm/expressions/aggregate-expressions.d.ts +215 -0
  284. package/esm/expressions/aggregate-expressions.d.ts.map +1 -0
  285. package/esm/expressions/aggregate-expressions.js +221 -0
  286. package/esm/expressions/aggregate-expressions.js.map +1 -0
  287. package/esm/expressions/index.d.ts +2 -0
  288. package/esm/expressions/index.d.ts.map +1 -0
  289. package/esm/index.d.ts +41 -0
  290. package/esm/index.d.ts.map +1 -0
  291. package/esm/index.js +1 -40
  292. package/esm/index.js.map +1 -1
  293. package/esm/migration/column-builder.d.ts +167 -0
  294. package/esm/migration/column-builder.d.ts.map +1 -0
  295. package/esm/migration/column-builder.js +217 -0
  296. package/esm/migration/column-builder.js.map +1 -0
  297. package/esm/migration/foreign-key-builder.d.ts +110 -0
  298. package/esm/migration/foreign-key-builder.d.ts.map +1 -0
  299. package/esm/migration/foreign-key-builder.js +129 -0
  300. package/esm/migration/foreign-key-builder.js.map +1 -0
  301. package/esm/migration/index.d.ts +6 -0
  302. package/esm/migration/index.d.ts.map +1 -0
  303. package/esm/migration/migration-runner.d.ts +231 -0
  304. package/esm/migration/migration-runner.d.ts.map +1 -0
  305. package/esm/migration/migration-runner.js +443 -0
  306. package/esm/migration/migration-runner.js.map +1 -0
  307. package/esm/migration/migration.js +1346 -0
  308. package/esm/migration/migration.js.map +1 -0
  309. package/esm/migration/types.d.ts +132 -0
  310. package/esm/migration/types.d.ts.map +1 -0
  311. package/esm/model/model.d.ts +1267 -0
  312. package/esm/model/model.d.ts.map +1 -0
  313. package/esm/model/model.js +1463 -0
  314. package/esm/model/model.js.map +1 -0
  315. package/esm/model/register-model.d.ts +80 -0
  316. package/esm/model/register-model.d.ts.map +1 -0
  317. package/esm/model/register-model.js +91 -0
  318. package/esm/model/register-model.js.map +1 -0
  319. package/esm/remover/database-remover.d.ts +100 -0
  320. package/esm/remover/database-remover.d.ts.map +1 -0
  321. package/esm/remover/database-remover.js +209 -0
  322. package/esm/remover/database-remover.js.map +1 -0
  323. package/esm/restorer/database-restorer.d.ts +131 -0
  324. package/esm/restorer/database-restorer.d.ts.map +1 -0
  325. package/esm/restorer/database-restorer.js +425 -0
  326. package/esm/restorer/database-restorer.js.map +1 -0
  327. package/esm/sync/index.d.ts +12 -0
  328. package/esm/sync/index.d.ts.map +1 -0
  329. package/esm/sync/model-events.d.ts +62 -0
  330. package/esm/sync/model-events.d.ts.map +1 -0
  331. package/esm/sync/model-events.js +49 -0
  332. package/esm/sync/model-events.js.map +1 -0
  333. package/esm/sync/model-sync-operation.d.ts +163 -0
  334. package/esm/sync/model-sync-operation.d.ts.map +1 -0
  335. package/esm/sync/model-sync-operation.js +292 -0
  336. package/esm/sync/model-sync-operation.js.map +1 -0
  337. package/esm/sync/model-sync.d.ts +130 -0
  338. package/esm/sync/model-sync.d.ts.map +1 -0
  339. package/esm/sync/model-sync.js +178 -0
  340. package/esm/sync/model-sync.js.map +1 -0
  341. package/esm/sync/sync-context.d.ts +70 -0
  342. package/esm/sync/sync-context.d.ts.map +1 -0
  343. package/esm/sync/sync-context.js +101 -0
  344. package/esm/sync/sync-context.js.map +1 -0
  345. package/esm/sync/sync-manager.d.ts +213 -0
  346. package/esm/sync/sync-manager.d.ts.map +1 -0
  347. package/esm/sync/sync-manager.js +689 -0
  348. package/esm/sync/sync-manager.js.map +1 -0
  349. package/esm/sync/types.d.ts +289 -0
  350. package/esm/sync/types.d.ts.map +1 -0
  351. package/esm/types.d.ts +45 -0
  352. package/esm/types.d.ts.map +1 -0
  353. package/esm/utils/connect-to-database.d.ts +246 -0
  354. package/esm/utils/connect-to-database.d.ts.map +1 -0
  355. package/esm/utils/connect-to-database.js +92 -0
  356. package/esm/utils/connect-to-database.js.map +1 -0
  357. package/esm/utils/database-writer.utils.d.ts +15 -0
  358. package/esm/utils/database-writer.utils.d.ts.map +1 -0
  359. package/esm/utils/database-writer.utils.js +14 -0
  360. package/esm/utils/database-writer.utils.js.map +1 -0
  361. package/esm/utils/define-model.js +100 -0
  362. package/esm/utils/define-model.js.map +1 -0
  363. package/esm/utils/once-connected.d.ts +146 -0
  364. package/esm/utils/once-connected.d.ts.map +1 -0
  365. package/esm/utils/once-connected.js +252 -0
  366. package/esm/utils/once-connected.js.map +1 -0
  367. package/esm/validation/database-seal-plugins.d.ts +2 -0
  368. package/esm/validation/database-seal-plugins.d.ts.map +1 -0
  369. package/esm/validation/database-seal-plugins.js +4 -0
  370. package/esm/validation/database-seal-plugins.js.map +1 -0
  371. package/esm/validation/database-writer-validation-error.d.ts +97 -0
  372. package/esm/validation/database-writer-validation-error.d.ts.map +1 -0
  373. package/esm/validation/database-writer-validation-error.js +160 -0
  374. package/esm/validation/database-writer-validation-error.js.map +1 -0
  375. package/esm/validation/index.d.ts +3 -0
  376. package/esm/validation/index.d.ts.map +1 -0
  377. package/esm/validation/mutators/embed-mutator.d.ts +9 -0
  378. package/esm/validation/mutators/embed-mutator.d.ts.map +1 -0
  379. package/esm/validation/mutators/embed-mutator.js +33 -0
  380. package/esm/validation/mutators/embed-mutator.js.map +1 -0
  381. package/esm/validation/plugins/embed-validator-plugin.d.ts +24 -0
  382. package/esm/validation/plugins/embed-validator-plugin.d.ts.map +1 -0
  383. package/esm/validation/plugins/embed-validator-plugin.js +18 -0
  384. package/esm/validation/plugins/embed-validator-plugin.js.map +1 -0
  385. package/esm/validation/rules/database-model-rule.d.ts +7 -0
  386. package/esm/validation/rules/database-model-rule.d.ts.map +1 -0
  387. package/esm/validation/rules/database-model-rule.js +27 -0
  388. package/esm/validation/rules/database-model-rule.js.map +1 -0
  389. package/esm/validation/transformers/embed-model-transformer.d.ts +3 -0
  390. package/esm/validation/transformers/embed-model-transformer.d.ts.map +1 -0
  391. package/esm/validation/transformers/embed-model-transformer.js +18 -0
  392. package/esm/validation/transformers/embed-model-transformer.js.map +1 -0
  393. package/esm/validation/validators/embed-validator.d.ts +21 -0
  394. package/esm/validation/validators/embed-validator.d.ts.map +1 -0
  395. package/esm/validation/validators/embed-validator.js +42 -0
  396. package/esm/validation/validators/embed-validator.js.map +1 -0
  397. package/esm/writer/database-writer.d.ts +181 -0
  398. package/esm/writer/database-writer.d.ts.map +1 -0
  399. package/esm/writer/database-writer.js +402 -0
  400. package/esm/writer/database-writer.js.map +1 -0
  401. package/package.json +61 -52
@@ -0,0 +1,1267 @@
1
+ import type { ObjectValidator } from "@warlock.js/seal";
2
+ import type { RemoverResult, WriterOptions } from "../contracts";
3
+ import { QueryBuilderContract, WhereCallback, WhereObject, WhereOperator } from "../contracts";
4
+ import type { DataSource } from "../data-source/data-source";
5
+ import { DatabaseDirtyTracker } from "../database-dirty-tracker";
6
+ import type { ModelEventListener, ModelEventName } from "../events/model-events";
7
+ import { ModelEvents } from "../events/model-events";
8
+ import type { ModelSyncOperationContract } from "../sync/types";
9
+ import type { DeleteStrategy, StrictMode } from "../types";
10
+ /**
11
+ * Timing control for global scopes
12
+ */
13
+ export type ScopeTiming = "before" | "after";
14
+ /**
15
+ * Global scope definition with callback and timing
16
+ */
17
+ export type GlobalScopeDefinition = {
18
+ callback: (query: QueryBuilderContract) => void;
19
+ timing: ScopeTiming;
20
+ };
21
+ /**
22
+ * Local scope callback function
23
+ */
24
+ export type LocalScopeCallback = (query: QueryBuilderContract) => void;
25
+ /**
26
+ * Options for adding global scopes
27
+ */
28
+ export type GlobalScopeOptions = {
29
+ timing?: ScopeTiming;
30
+ };
31
+ export type ChildModel<TModel extends Model> = (new (...args: any[]) => TModel) & Pick<typeof Model, "table" | "primaryKey" | "dataSource" | "schema" | "strictMode" | "autoGenerateId" | "initialId" | "randomInitialId" | "incrementIdBy" | "resource" | "resourceColumns" | "toJsonColumns" | "randomIncrement" | "getDataSource" | "query" | "find" | "first" | "last" | "all" | "latest" | "count" | "where" | "increase" | "decrease" | "atomic" | "events" | "on" | "once" | "off" | "globalEvents" | "delete" | "deleteOne" | "deleteStrategy" | "trashTable" | "restore" | "restoreAll" | "deletedAtColumn" | "createdAtColumn" | "updatedAtColumn" | "create" | "createMany" | "sync" | "embed" | "deserialize" | "syncMany" | "addGlobalScope" | "removeGlobalScope" | "addScope" | "removeScope" | "localScopes" | "globalScopes" | "newQueryBuilder" | "builder">;
32
+ /**
33
+ * Generic schema type representing the structure of model data.
34
+ */
35
+ export type ModelSchema = Record<string, any>;
36
+ /**
37
+ * Base class that powers all Cascade models.
38
+ *
39
+ * Provides:
40
+ * - Type-safe value accessors with dot-notation support (get, set, has, unset, merge)
41
+ * - Automatic dirty tracking for efficient partial updates
42
+ * - Lifecycle event hooks (saving, created, deleting, etc.)
43
+ * - Integration with the data-source registry for multi-database support
44
+ * - Support for both per-model and global event listeners
45
+ *
46
+ * @template TSchema - The shape of the model's underlying data
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * interface UserSchema {
51
+ * id: number;
52
+ * name: string;
53
+ * email: string;
54
+ * }
55
+ *
56
+ * class User extends Model<UserSchema> {
57
+ * public static table = "users";
58
+ * }
59
+ *
60
+ * const user = new User({ name: "Alice" });
61
+ * user.set("email", "alice@example.com");
62
+ * console.log(user.hasChanges()); // true
63
+ * ```
64
+ */
65
+ export declare abstract class Model<TSchema extends ModelSchema = ModelSchema> {
66
+ /**
67
+ * The database table or collection name associated with this model.
68
+ *
69
+ * Must be defined by each concrete model subclass.
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * class User extends Model {
74
+ * public static table = "users";
75
+ * }
76
+ * ```
77
+ */
78
+ static table: string;
79
+ /**
80
+ * Resource for this model.
81
+ * It is a class that holds a toJSON function
82
+ * Called when the model is being converted to JSON (by calling toJSON or JSON.stringify(model))
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * class User extends Model {
87
+ * public static resource = UserResource;
88
+ * }
89
+ * ```
90
+ */
91
+ static resource?: any;
92
+ /**
93
+ * Resource columns
94
+ * Define what columns should be sent to the resource (if any) when converting to JSON
95
+ */
96
+ static resourceColumns?: string[];
97
+ /**
98
+ * JSON keys for this model.
99
+ * This could be used if resource is not passed
100
+ * It will select only these keys from the model
101
+ * @example
102
+ * ```typescript
103
+ * class User extends Model {
104
+ * public static toJsonColumns = ["id", "name"];
105
+ * }
106
+ * ```
107
+ */
108
+ static toJsonColumns?: string[];
109
+ /**
110
+ * Data source reference for this model.
111
+ *
112
+ * Can be:
113
+ * - A string name registered in the data-source registry
114
+ * - A DataSource instance
115
+ * - Undefined (falls back to the default data source)
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * class User extends Model {
120
+ * public static dataSource = "primary";
121
+ * }
122
+ * ```
123
+ */
124
+ static dataSource?: string | DataSource;
125
+ /**
126
+ * Query builder class
127
+ */
128
+ static builder?: new (...args: any[]) => QueryBuilderContract<Model>;
129
+ /**
130
+ * Primary key field name used to identify records.
131
+ *
132
+ * @default "id"
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * class User extends Model {
137
+ * public static primaryKey = "_id"; // MongoDB
138
+ * }
139
+ *
140
+ * class Product extends Model {
141
+ * public static primaryKey = "id"; // SQL
142
+ * }
143
+ * ```
144
+ */
145
+ static primaryKey: string;
146
+ /**
147
+ * Embeded fields when document is Being embeded
148
+ */
149
+ static embed?: string[];
150
+ /**
151
+ * Validation and casting schema using @warlock.js/seal.
152
+ *
153
+ * Defines validation rules and data transformations for the model.
154
+ * Used automatically during save operations.
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * import { v } from "@warlock.js/seal";
159
+ *
160
+ * class User extends Model {
161
+ * public static schema = v.object({
162
+ * name: v.string().required().trim(),
163
+ * age: v.number().min(0).max(120),
164
+ * email: v.string().email().required().toLowerCase(),
165
+ * createdAt: v.date().default(() => new Date()),
166
+ * });
167
+ * }
168
+ * ```
169
+ */
170
+ static schema?: ObjectValidator;
171
+ /**
172
+ * Strict mode behavior for unknown fields.
173
+ *
174
+ * - `"strip"`: Remove unknown fields silently (default, recommended for APIs)
175
+ * - `"fail"`: Throw validation error on unknown fields (strict validation)
176
+ * - `"allow"`: Allow unknown fields to pass through (permissive)
177
+ *
178
+ * @default "strip"
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * import { Model, type StrictMode } from "@warlock.js/cascade";
183
+ *
184
+ * class User extends Model {
185
+ * public static strictMode: StrictMode = "fail"; // Throw on unknown fields
186
+ * }
187
+ *
188
+ * const user = new User({ name: "Alice", unknownField: "value" });
189
+ * await user.save(); // DatabaseWriterValidationError: unknown field
190
+ * ```
191
+ */
192
+ static strictMode: StrictMode;
193
+ /**
194
+ * Auto-generate incremental `id` field on insert (NoSQL only).
195
+ *
196
+ * When enabled, the ID generator creates a sequential integer ID
197
+ * separate from the database's native ID (_id for MongoDB).
198
+ *
199
+ * **Note:** SQL databases use native AUTO_INCREMENT and don't need this.
200
+ *
201
+ * @default true
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * class User extends Model {
206
+ * public static autoGenerateId = true;
207
+ * }
208
+ *
209
+ * const user = new User({ name: "Alice" });
210
+ * await user.save();
211
+ * console.log(user.get("_id")); // ObjectId("...") - MongoDB
212
+ * console.log(user.get("id")); // 1 - Generated
213
+ * ```
214
+ */
215
+ static autoGenerateId: boolean;
216
+ /**
217
+ * Initial ID value for the first record.
218
+ *
219
+ * If not set, defaults to 1 or uses `randomInitialId`.
220
+ *
221
+ * @example
222
+ * ```typescript
223
+ * class User extends Model {
224
+ * public static initialId = 1000; // Start from 1000
225
+ * }
226
+ * ```
227
+ */
228
+ static initialId?: number;
229
+ /**
230
+ * Randomly generate the initial ID.
231
+ *
232
+ * Can be:
233
+ * - `true`: Generate random ID between 10000-499999
234
+ * - Function: Custom random ID generator
235
+ * - `false`: Use `initialId` or default to 1
236
+ *
237
+ * @default false
238
+ *
239
+ * @example
240
+ * ```typescript
241
+ * class User extends Model {
242
+ * public static randomInitialId = true; // Random 10000-499999
243
+ * }
244
+ *
245
+ * class Product extends Model {
246
+ * public static randomInitialId = () => Math.floor(Math.random() * 1000000);
247
+ * }
248
+ * ```
249
+ */
250
+ static randomInitialId?: boolean | (() => number);
251
+ /**
252
+ * Amount to increment ID by for each new record.
253
+ *
254
+ * If not set, defaults to 1 or uses `randomIncrement`.
255
+ *
256
+ * @default 1
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * class User extends Model {
261
+ * public static incrementIdBy = 5; // Increment by 5
262
+ * }
263
+ * ```
264
+ */
265
+ static incrementIdBy?: number;
266
+ /**
267
+ * Randomly generate the increment amount.
268
+ *
269
+ * Can be:
270
+ * - `true`: Generate random increment between 1-10
271
+ * - Function: Custom random increment generator
272
+ * - `false`: Use `incrementIdBy` or default to 1
273
+ *
274
+ * @default false
275
+ *
276
+ * @example
277
+ * ```typescript
278
+ * class User extends Model {
279
+ * public static randomIncrement = true; // Random 1-10
280
+ * }
281
+ *
282
+ * class Product extends Model {
283
+ * public static randomIncrement = () => Math.floor(Math.random() * 100);
284
+ * }
285
+ * ```
286
+ */
287
+ static randomIncrement?: boolean | (() => number);
288
+ /**
289
+ * Created at column name.
290
+ */
291
+ static createdAtColumn?: string | false;
292
+ /**
293
+ * Updated at column name.
294
+ */
295
+ static updatedAtColumn?: string | false;
296
+ /**
297
+ * Delete strategy for this model.
298
+ *
299
+ * Controls how models are deleted:
300
+ * - `"trash"` - Moves to trash collection, then deletes
301
+ * - `"permanent"` - Direct deletion (hard delete)
302
+ * - `"soft"` - Sets deletedAt timestamp (soft delete)
303
+ *
304
+ * Can be overridden by destroy() options.
305
+ * Falls back to data source default if not set.
306
+ *
307
+ * @example
308
+ * ```typescript
309
+ * class User extends Model {
310
+ * public static deleteStrategy: DeleteStrategy = "soft";
311
+ * }
312
+ * ```
313
+ */
314
+ static deleteStrategy?: DeleteStrategy;
315
+ /**
316
+ * Column name for soft delete timestamp.
317
+ *
318
+ * Used when delete strategy is "soft".
319
+ *
320
+ * @default "deletedAt"
321
+ *
322
+ * @example
323
+ * ```typescript
324
+ * class User extends Model {
325
+ * public static deletedAtColumn = "archivedAt";
326
+ * }
327
+ * ```
328
+ */
329
+ static deletedAtColumn: string;
330
+ /**
331
+ * Trash table/collection name override.
332
+ *
333
+ * If not set, defaults to `{table}Trash` or data source default.
334
+ * Used when delete strategy is "trash".
335
+ *
336
+ * @example
337
+ * ```typescript
338
+ * class User extends Model {
339
+ * public static trashTable = "userRecycleBin";
340
+ * }
341
+ * ```
342
+ */
343
+ static trashTable?: string;
344
+ /**
345
+ * Global scopes that are automatically applied to all queries.
346
+ * These scopes are inherited by child models.
347
+ */
348
+ static globalScopes: Map<string, GlobalScopeDefinition>;
349
+ /**
350
+ * Local scopes that can be manually applied to queries.
351
+ * These are reusable query snippets that developers opt into.
352
+ */
353
+ static localScopes: Map<string, LocalScopeCallback>;
354
+ /**
355
+ * Flag indicating whether this model instance represents a new (unsaved) record.
356
+ *
357
+ * - `true`: The model has not been persisted to the database yet
358
+ * - `false`: The model represents an existing database record
359
+ *
360
+ * This flag is used by the writer to determine whether to perform an insert or update.
361
+ */
362
+ isNew: boolean;
363
+ /**
364
+ * The raw mutable data backing this model instance.
365
+ *
366
+ * All field accessors (get, set, merge, etc.) operate on this object.
367
+ */
368
+ data: TSchema;
369
+ /**
370
+ * Dirty tracker that monitors changes to the model's data.
371
+ *
372
+ * Tracks:
373
+ * - Which fields have been modified (dirty columns)
374
+ * - Which fields have been removed
375
+ * - Original vs. current values for each dirty field
376
+ *
377
+ * Used by the writer to generate efficient partial update payloads.
378
+ */
379
+ readonly dirtyTracker: DatabaseDirtyTracker;
380
+ /**
381
+ * Constructs a new model instance with optional initial data.
382
+ *
383
+ * Initializes the dirty tracker with a snapshot of the provided data.
384
+ *
385
+ * @param initialData - Partial data to populate the model
386
+ *
387
+ * @example
388
+ * ```typescript
389
+ * const user = new User({ name: "Alice", email: "alice@example.com" });
390
+ * ```
391
+ */
392
+ constructor(initialData?: Partial<TSchema>);
393
+ /**
394
+ * Get a model class by its name from the global registry.
395
+ *
396
+ * Models must be decorated with @RegisterModel() to be available in the registry.
397
+ *
398
+ * @param name - The model class name
399
+ * @returns The model class or undefined if not found
400
+ *
401
+ * @example
402
+ * ```typescript
403
+ * const UserModel = Model.getModel("User");
404
+ * if (UserModel) {
405
+ * const user = await UserModel.find(1);
406
+ * }
407
+ * ```
408
+ */
409
+ static getModel(name: string): ChildModel<Model<ModelSchema>>;
410
+ /**
411
+ * Get all registered models from the global registry.
412
+ *
413
+ * Only models decorated with @RegisterModel() will appear here.
414
+ *
415
+ * @returns A Map of all registered model classes by name
416
+ *
417
+ * @example
418
+ * ```typescript
419
+ * const allModels = Model.getAllModels();
420
+ * for (const [name, ModelClass] of allModels) {
421
+ * console.log(`Found model: ${name} with table: ${ModelClass.table}`);
422
+ * }
423
+ * ```
424
+ */
425
+ static getAllModels(): Map<string, ChildModel<Model<ModelSchema>>>;
426
+ /**
427
+ * Create a sync operation for a single embedded document.
428
+ *
429
+ * When this model is updated, the target model's field
430
+ * will be updated with the embedded data.
431
+ *
432
+ * @param TargetModel - Target model class that receives data
433
+ * @param targetField - Field path in target model
434
+ * @returns Sync operation for chaining configuration
435
+ *
436
+ * @example
437
+ * ```typescript
438
+ * // When Category updates, update Product.category
439
+ * Category.sync(Product, "category");
440
+ * ```
441
+ */
442
+ static sync<TModel extends Model = Model>(this: ChildModel<TModel>, TargetModel: ChildModel<Model>, targetField: string): ModelSyncOperationContract;
443
+ /**
444
+ * Create a sync operation for an array of embedded documents.
445
+ *
446
+ * When this model is updated, the corresponding element
447
+ * in the target model's array field will be updated.
448
+ *
449
+ * @param TargetModel - Target model class that receives data
450
+ * @param targetField - Array field path in target model
451
+ * @returns Sync operation for chaining configuration
452
+ *
453
+ * @example
454
+ * ```typescript
455
+ * // When Tag updates, update Post.tags[i] where tags[i].id matches
456
+ * Tag.syncMany(Post, "tags").identifyBy("id");
457
+ * ```
458
+ */
459
+ static syncMany<TModel extends Model = Model>(this: ChildModel<TModel>, TargetModel: ChildModel<Model>, targetField: string): ModelSyncOperationContract;
460
+ /**
461
+ * Get model id
462
+ */
463
+ get id(): number | undefined;
464
+ /**
465
+ * Retrieves a field value from the model's data.
466
+ *
467
+ * Supports both top-level keys and dot-notation paths for nested access.
468
+ *
469
+ * @param field - The field name or dot-notation path (e.g., "address.city")
470
+ * @param defaultValue - Value to return if the field is missing
471
+ * @returns The field value or the default value if not found
472
+ *
473
+ * @example
474
+ * ```typescript
475
+ * user.get("name"); // "Alice"
476
+ * user.get("address.city", "Unknown"); // "Unknown" if address.city is missing
477
+ * ```
478
+ */
479
+ get<TKey extends keyof TSchema & string>(field: TKey): TSchema[TKey];
480
+ get<TKey extends keyof TSchema & string>(field: TKey, defaultValue: TSchema[TKey]): TSchema[TKey];
481
+ get(field: string): unknown;
482
+ get(field: string, defaultValue: unknown): unknown;
483
+ /**
484
+ * Get only the values of the given fields
485
+ */
486
+ only<TKey extends keyof TSchema & string>(fields: TKey[]): Record<TKey, TSchema[TKey]>;
487
+ only(fields: string[]): Record<string, unknown>;
488
+ /**
489
+ * Get a string value
490
+ */
491
+ string(key: string, defaultValue?: string): string | undefined;
492
+ /**
493
+ * Get a number value
494
+ */
495
+ number(key: string, defaultValue?: number): number | undefined;
496
+ /**
497
+ * Get a boolean value
498
+ */
499
+ boolean(key: string, defaultValue?: boolean): boolean | undefined;
500
+ /**
501
+ * Sets a field value in the model's data and marks it as dirty.
502
+ *
503
+ * Supports both top-level keys and dot-notation paths for nested assignment.
504
+ * Automatically updates the dirty tracker to reflect the change.
505
+ *
506
+ * @param field - The field name or dot-notation path (e.g., "address.city")
507
+ * @param value - The value to assign
508
+ * @returns The model instance for method chaining
509
+ *
510
+ * @example
511
+ * ```typescript
512
+ * user.set("name", "Bob").set("address.city", "NYC");
513
+ * ```
514
+ */
515
+ set<TKey extends keyof TSchema & string>(field: TKey, value: TSchema[TKey]): this;
516
+ set(field: string, value: unknown): this;
517
+ /**
518
+ * Checks whether a field exists in the model's data.
519
+ *
520
+ * Supports both top-level keys and dot-notation paths.
521
+ *
522
+ * @param field - The field name or dot-notation path
523
+ * @returns `true` if the field exists, `false` otherwise
524
+ *
525
+ * @example
526
+ * ```typescript
527
+ * user.has("name"); // true
528
+ * user.has("address.zipCode"); // false
529
+ * ```
530
+ */
531
+ has<TKey extends keyof TSchema & string>(field: TKey): boolean;
532
+ has(field: string): boolean;
533
+ /**
534
+ * Increment the given field by the given amount
535
+ */
536
+ increment<TKey extends keyof TSchema & string>(field: TKey, amount: number): this;
537
+ increment(field: string, amount: number): this;
538
+ /**
539
+ * Decrement the given field by the given amount
540
+ */
541
+ decrement<TKey extends keyof TSchema & string>(field: TKey, amount: number): this;
542
+ decrement(field: string, amount: number): this;
543
+ /**
544
+ * Removes one or more fields from the model's data and marks them as removed.
545
+ *
546
+ * Supports both top-level keys and dot-notation paths.
547
+ * Automatically updates the dirty tracker to reflect the removal.
548
+ *
549
+ * @param fields - One or more field names or dot-notation paths to remove
550
+ * @returns The model instance for method chaining
551
+ *
552
+ * @example
553
+ * ```typescript
554
+ * user.unset("tempField", "address.oldZip");
555
+ * ```
556
+ */
557
+ unset(...fields: (keyof TSchema & string)[]): this;
558
+ unset(...fields: string[]): this;
559
+ /**
560
+ * Merges new values into the model's data and marks changed fields as dirty.
561
+ *
562
+ * Performs a deep merge, preserving existing nested structures.
563
+ * Automatically updates the dirty tracker to reflect all changes.
564
+ *
565
+ * @param values - Partial data to merge into the model
566
+ * @returns The model instance for method chaining
567
+ *
568
+ * @example
569
+ * ```typescript
570
+ * user.merge({ name: "Charlie", address: { city: "LA" } });
571
+ * ```
572
+ */
573
+ merge(values: Partial<TSchema>): this;
574
+ merge(values: Record<string, unknown>): this;
575
+ /**
576
+ * Checks whether the model's data has changed since instantiation or last reset.
577
+ *
578
+ * @returns `true` if any fields have been modified or removed, `false` otherwise
579
+ *
580
+ * @example
581
+ * ```typescript
582
+ * const user = new User({ name: "Alice" });
583
+ * user.hasChanges(); // false
584
+ * user.set("name", "Bob");
585
+ * user.hasChanges(); // true
586
+ * ```
587
+ */
588
+ hasChanges(): boolean;
589
+ /**
590
+ * Check if the given column has been modified.
591
+ *
592
+ * @param column - The column name to check
593
+ * @returns `true` if the column has been modified, `false` otherwise
594
+ *
595
+ * @example
596
+ * ```typescript
597
+ * user.set("name", "Bob");
598
+ * user.isDirty("name"); // true
599
+ * ```
600
+ */
601
+ isDirty(column: string): boolean;
602
+ /**
603
+ * Retrieves all dirty columns with their old and new values.
604
+ *
605
+ * @returns A record mapping each dirty column to its previous and current value
606
+ *
607
+ * @example
608
+ * ```typescript
609
+ * user.set("name", "Bob");
610
+ * user.getDirtyColumnsWithValues();
611
+ * // { name: { oldValue: "Alice", newValue: "Bob" } }
612
+ * ```
613
+ */
614
+ getDirtyColumnsWithValues(): Record<string, {
615
+ oldValue: unknown;
616
+ newValue: unknown;
617
+ }>;
618
+ /**
619
+ * Lists all columns that have been removed from the model's data.
620
+ *
621
+ * @returns An array of field names that were present initially but have been unset
622
+ *
623
+ * @example
624
+ * ```typescript
625
+ * user.unset("tempField");
626
+ * user.getRemovedColumns(); // ["tempField"]
627
+ * ```
628
+ */
629
+ getRemovedColumns(): string[];
630
+ /**
631
+ * Lists all columns that have been modified since instantiation or last reset.
632
+ *
633
+ * @returns An array of field names that have changed
634
+ *
635
+ * @example
636
+ * ```typescript
637
+ * user.set("name", "Bob");
638
+ * user.getDirtyColumns(); // ["name"]
639
+ * ```
640
+ */
641
+ getDirtyColumns(): string[];
642
+ /**
643
+ * Emits a lifecycle event to both per-model and global listeners.
644
+ *
645
+ * This method is public so that external services (like the writer) can trigger
646
+ * lifecycle events when appropriate.
647
+ *
648
+ * @param event - The event name (e.g., "saving", "created", "deleting")
649
+ * @param context - Optional context data to pass to listeners
650
+ *
651
+ * @example
652
+ * ```typescript
653
+ * await user.emitEvent("saving");
654
+ * await user.emitEvent("validated", { errors: [] });
655
+ * ```
656
+ */
657
+ emitEvent<TContext = unknown>(event: ModelEventName, context?: TContext): Promise<void>;
658
+ /**
659
+ * Resolves the data source associated with this model.
660
+ *
661
+ * Resolution order:
662
+ * 1. If `dataSource` is a string, looks it up in the data-source registry
663
+ * 2. If `dataSource` is a DataSource instance, returns it directly
664
+ * 3. Otherwise, returns the default data source from the registry
665
+ *
666
+ * @returns The resolved DataSource instance
667
+ * @throws Error if no data source is found
668
+ *
669
+ * @example
670
+ * ```typescript
671
+ * class User extends Model {
672
+ * public static dataSource = "primary";
673
+ * }
674
+ *
675
+ * const ds = User.getDataSource();
676
+ * ```
677
+ */
678
+ static getDataSource(): DataSource;
679
+ /**
680
+ * Apply model defaults from data source configuration.
681
+ *
682
+ * This is called automatically by getDataSource() the first time
683
+ * a model accesses its data source. Defaults are only applied if
684
+ * the model doesn't already have its own value set.
685
+ *
686
+ * @param defaults - Model default configuration from data source
687
+ * @private
688
+ */
689
+ static applyModelDefaults(defaults: any): void;
690
+ /**
691
+ * Add a global scope that is automatically applied to all queries.
692
+ *
693
+ * Global scopes are inherited by child models and applied before query execution.
694
+ * Use for security filters, multi-tenancy, soft deletes, etc.
695
+ *
696
+ * @param name - Unique name for the scope
697
+ * @param callback - Function that modifies the query
698
+ * @param options - Scope options (timing: 'before' | 'after')
699
+ *
700
+ * @example
701
+ * ```typescript
702
+ * // Multi-tenancy scope
703
+ * Model.addGlobalScope('tenant', (query) => {
704
+ * query.where('tenantId', getCurrentTenant());
705
+ * }, { timing: 'before' });
706
+ *
707
+ * // Soft delete scope
708
+ * User.addGlobalScope('notDeleted', (query) => {
709
+ * query.whereNull('deletedAt');
710
+ * });
711
+ * ```
712
+ */
713
+ static addGlobalScope(name: string, callback: (query: QueryBuilderContract) => void, options?: GlobalScopeOptions): void;
714
+ /**
715
+ * Remove a global scope by name.
716
+ *
717
+ * @param name - Name of the scope to remove
718
+ *
719
+ * @example
720
+ * ```typescript
721
+ * Model.removeGlobalScope('tenant');
722
+ * ```
723
+ */
724
+ static removeGlobalScope(name: string): void;
725
+ /**
726
+ * Add a local scope that can be manually applied to queries.
727
+ *
728
+ * Local scopes are reusable query snippets that developers opt into.
729
+ * They are not automatically applied.
730
+ *
731
+ * @param name - Unique name for the scope
732
+ * @param callback - Function that modifies the query
733
+ *
734
+ * @example
735
+ * ```typescript
736
+ * // Define reusable scopes
737
+ * User.addScope('active', (query) => {
738
+ * query.where('isActive', true);
739
+ * });
740
+ *
741
+ * User.addScope('admins', (query) => {
742
+ * query.where('role', 'admin');
743
+ * });
744
+ *
745
+ * // Use explicitly
746
+ * await User.query().scope('active').get();
747
+ * await User.query().scope('admins').get();
748
+ * ```
749
+ */
750
+ static addScope(name: string, callback: LocalScopeCallback): void;
751
+ /**
752
+ * Remove a local scope by name.
753
+ *
754
+ * @param name - Name of the scope to remove
755
+ *
756
+ * @example
757
+ * ```typescript
758
+ * User.removeScope('active');
759
+ * ```
760
+ */
761
+ static removeScope(name: string): void;
762
+ /**
763
+ * Create a new query builder for this model
764
+ */
765
+ static query<TModel extends Model = Model>(this: ChildModel<TModel>): QueryBuilderContract<TModel>;
766
+ /**
767
+ * Create new query builder.
768
+ *
769
+ * If the model has a static `builder` property set to a query builder class,
770
+ * it will be instantiated instead of the default driver query builder.
771
+ *
772
+ * @example
773
+ * ```typescript
774
+ * class UserQueryBuilder<T = User> extends MongoQueryBuilder<T> {
775
+ * active() { return this.where("isActive", true); }
776
+ * }
777
+ *
778
+ * class User extends Model {
779
+ * static builder = UserQueryBuilder; // That's it! ✨
780
+ * }
781
+ *
782
+ * // Now User.query() returns UserQueryBuilder<User> with autocomplete!
783
+ * ```
784
+ */
785
+ static newQueryBuilder<TModel extends Model = Model>(this: ChildModel<TModel>): QueryBuilderContract<TModel>;
786
+ /**
787
+ * Get First matched record for the given filter
788
+ */
789
+ static first<TModel extends Model = Model>(this: ChildModel<TModel>, filter?: Record<string, unknown>): Promise<TModel | null>;
790
+ /**
791
+ * Get last matched record for the given filter
792
+ */
793
+ static last<TModel extends Model = Model>(this: ChildModel<TModel>, filter?: Record<string, unknown>): Promise<TModel | null>;
794
+ /**
795
+ * Use where clause directly
796
+ */
797
+ static where<TModel extends Model = Model>(this: ChildModel<TModel>, field: string, value: unknown): QueryBuilderContract<TModel>;
798
+ static where<TModel extends Model = Model>(this: ChildModel<TModel>, field: string, operator: WhereOperator, value: unknown): QueryBuilderContract<TModel>;
799
+ static where<TModel extends Model = Model>(this: (new (...args: any[]) => TModel) & Pick<typeof Model, "query" | "getDataSource" | "table">, conditions: WhereObject): QueryBuilderContract<TModel>;
800
+ static where<TModel extends Model = Model>(this: (new (...args: any[]) => TModel) & Pick<typeof Model, "query" | "getDataSource" | "table">, callback: WhereCallback<TModel>): QueryBuilderContract<TModel>;
801
+ /**
802
+ * Count the number of records in the table
803
+ * @param filter - The filter to apply to the query
804
+ */
805
+ static count<TModel extends Model = Model>(this: ChildModel<TModel>, filter?: Record<string, unknown>): Promise<number>;
806
+ /**
807
+ * Find record by id
808
+ */
809
+ static find<TModel extends Model = Model>(this: ChildModel<TModel>, id: string | number): Promise<TModel | null>;
810
+ /**
811
+ * Get all records from the table
812
+ *
813
+ * @param filter - The filter to apply to the query
814
+ * @returns All records from the table
815
+ */
816
+ static all<TModel extends Model = Model>(this: ChildModel<TModel>, filter?: Record<string, unknown>): Promise<TModel[]>;
817
+ /**
818
+ * Get latest records from the table
819
+ *
820
+ * @param filter - The filter to apply to the query
821
+ */
822
+ static latest<TModel extends Model = Model>(this: ChildModel<TModel>, filter?: Record<string, unknown>): Promise<TModel[]>;
823
+ /**
824
+ * Increment the given field by the given amount
825
+ *
826
+ * @example ```typescript
827
+ * // Increase age by 1 for user id 1
828
+ * User.increment({id: 1}, "age", 1);
829
+ * // Increase age by 1 and views by 2 for user id 1
830
+ * User.increment({id: 1}, {age: 1, views: 2});
831
+ * ```
832
+ */
833
+ static increase<TModel extends Model = Model>(this: ChildModel<TModel>, filter: Record<string, unknown>, field: string, amount: number): Promise<number>;
834
+ /**
835
+ * Decrement the given field by the given amount
836
+ * @example ```typescript
837
+ * // Decrease age by 1 for user id 1
838
+ * User.decrement({id: 1}, "age", 1);
839
+ * // Decrease age by 1 and views by 2 for user id 1
840
+ * User.decrement({id: 1}, {age: 1, views: 2});
841
+ * ```
842
+ */
843
+ static decrease<TModel extends Model = Model>(this: ChildModel<TModel>, filter: Record<string, unknown>, field: string, amount: number): Promise<number>;
844
+ /**
845
+ * Perform atomic operation
846
+ */
847
+ static atomic<TModel extends Model = Model>(this: ChildModel<TModel>, filter: Record<string, unknown>, operations: Record<string, unknown>): Promise<number>;
848
+ /**
849
+ * Destroy (delete) the current model instance from the database.
850
+ *
851
+ * Emits lifecycle events:
852
+ * - `deleting` - Before deletion
853
+ * - `deleted` - After successful deletion
854
+ *
855
+ * @param options - Destroy options (strategy override, skipEvents)
856
+ * @throws {Error} If the model is new (not saved) or if deletion fails
857
+ *
858
+ * @example
859
+ * ```typescript
860
+ * const user = await User.find(1);
861
+ * await user.destroy(); // Uses default strategy
862
+ * await user.destroy({ strategy: "permanent" }); // Override strategy
863
+ * await user.destroy({ skipEvents: true }); // Silent delete
864
+ * ```
865
+ */
866
+ destroy(options?: {
867
+ strategy?: DeleteStrategy;
868
+ skipEvents?: boolean;
869
+ }): Promise<RemoverResult>;
870
+ /**
871
+ * Get the class constructor from an instance.
872
+ *
873
+ * This helper method allows instance methods to access static properties
874
+ * and methods of the model class in a type-safe way.
875
+ *
876
+ * @returns The model class constructor
877
+ *
878
+ * @example
879
+ * ```typescript
880
+ * const constructor = this.self();
881
+ * const table = constructor.table;
882
+ * await constructor.deleteOne({ id: 1 });
883
+ * ```
884
+ */
885
+ protected self<TModel extends Model = this>(): ChildModel<TModel>;
886
+ /**
887
+ * Creates an immutable clone of the model with its current state.
888
+ *
889
+ * The cloned model:
890
+ * - Contains a deep copy of all current data
891
+ * - Has frozen (immutable) data that cannot be modified
892
+ * - Preserves the `isNew` flag from the original
893
+ * - Has no dirty changes (clean state)
894
+ * - Cannot be saved or modified
895
+ *
896
+ * This is useful for:
897
+ * - Creating snapshots of model state
898
+ * - Passing read-only model data to other parts of the application
899
+ * - Preventing accidental mutations
900
+ * - Maintaining historical records
901
+ *
902
+ * @returns A new immutable model instance with the current state
903
+ *
904
+ * @example
905
+ * ```typescript
906
+ * const user = new User({ name: "Alice", email: "alice@example.com" });
907
+ * await user.save();
908
+ *
909
+ * // Create an immutable snapshot
910
+ * const snapshot = user.clone();
911
+ *
912
+ * // This will throw an error because the clone is immutable
913
+ * snapshot.set("name", "Bob"); // TypeError: Cannot assign to read only property
914
+ *
915
+ * // Original can still be modified
916
+ * user.set("name", "Bob");
917
+ * await user.save();
918
+ * ```
919
+ */
920
+ clone(): this;
921
+ /**
922
+ * Recursively freezes an object and all its nested properties.
923
+ *
924
+ * @param obj - The object to freeze
925
+ * @returns The frozen object
926
+ * @private
927
+ */
928
+ private deepFreeze;
929
+ /**
930
+ * Get table name
931
+ */
932
+ getTableName(): string;
933
+ /**
934
+ * Get primary key name
935
+ */
936
+ getPrimaryKey(): string;
937
+ /**
938
+ * Get model schema
939
+ */
940
+ getSchema(): ObjectValidator;
941
+ /**
942
+ * Check if schema has the given key
943
+ */
944
+ schemaHas(key: string): boolean;
945
+ /**
946
+ * Get strict mode
947
+ */
948
+ getStrictMode(): StrictMode;
949
+ /**
950
+ * Get data source (Connection)
951
+ */
952
+ getConnection(): DataSource;
953
+ /**
954
+ * Delete all matching documents from the table.
955
+ */
956
+ static delete<TModel extends Model = Model>(this: ChildModel<TModel>, filter?: Record<string, unknown>): Promise<number>;
957
+ /**
958
+ * Delete a single matching document from the table.
959
+ */
960
+ static deleteOne<TModel extends Model = Model>(this: ChildModel<TModel>, filter?: Record<string, unknown>): Promise<number>;
961
+ /**
962
+ * Restore a single deleted record by its ID.
963
+ *
964
+ * Automatically detects whether the record was deleted via "trash" or "soft" strategy.
965
+ * Handles ID conflicts based on options.
966
+ *
967
+ * @param id - The primary key value of the record to restore
968
+ * @param options - Restorer options (onIdConflict, skipEvents)
969
+ * @returns The restored model instance
970
+ *
971
+ * @throws {Error} If record not found in trash or soft-deleted records
972
+ * @throws {Error} If ID conflict and onIdConflict is "fail"
973
+ *
974
+ * @example
975
+ * ```typescript
976
+ * // Restore with default options (assign new ID if conflict)
977
+ * const user = await User.restore(123);
978
+ *
979
+ * // Restore and fail if ID conflict
980
+ * const user = await User.restore(123, { onIdConflict: "fail" });
981
+ *
982
+ * // Silent restore (skip events)
983
+ * const user = await User.restore(123, { skipEvents: true });
984
+ * ```
985
+ */
986
+ static restore<TModel extends Model = Model>(this: ChildModel<TModel>, id: string | number, options?: {
987
+ onIdConflict?: "fail" | "assignNew";
988
+ skipEvents?: boolean;
989
+ }): Promise<TModel>;
990
+ /**
991
+ * Restore all deleted records for the model's table.
992
+ *
993
+ * Restores all records from the trash table (if using trash strategy)
994
+ * or all soft-deleted records (if using soft strategy).
995
+ *
996
+ * @param options - Restorer options (onIdConflict, skipEvents)
997
+ * @returns Array of restored model instances
998
+ *
999
+ * @example
1000
+ * ```typescript
1001
+ * // Restore all with default options
1002
+ * const users = await User.restoreAll();
1003
+ *
1004
+ * // Restore all and fail on any ID conflict
1005
+ * const users = await User.restoreAll({ onIdConflict: "fail" });
1006
+ * ```
1007
+ */
1008
+ static restoreAll<TModel extends Model = Model>(this: ChildModel<TModel>, options?: {
1009
+ onIdConflict?: "fail" | "assignNew";
1010
+ skipEvents?: boolean;
1011
+ }): Promise<TModel[]>;
1012
+ /**
1013
+ * Create a new record in database and return the model instance.
1014
+ *
1015
+ * The data type is automatically inferred from the model's schema type.
1016
+ *
1017
+ * @param data - Partial data matching the model's schema type
1018
+ * @returns The created model instance
1019
+ *
1020
+ * @example
1021
+ * ```typescript
1022
+ * // TypeScript automatically infers UserSchema from User model
1023
+ * const user = await User.create({
1024
+ * name: "Alice",
1025
+ * email: "alice@example.com",
1026
+ * age: 30
1027
+ * });
1028
+ * // Type: User (with UserSchema inferred)
1029
+ * ```
1030
+ */
1031
+ static create<TModel extends Model = Model, TSchema extends ModelSchema = TModel extends Model<infer S> ? S : ModelSchema>(this: ChildModel<TModel>, data: Partial<TSchema>): Promise<TModel>;
1032
+ /**
1033
+ * Create many documents and return an array of created models
1034
+ */
1035
+ static createMany<TModel extends Model = Model, TSchema extends ModelSchema = TModel extends Model<infer S> ? S : ModelSchema>(this: ChildModel<TModel>, data: Partial<TSchema>[]): Promise<TModel[]>;
1036
+ /**
1037
+ * Find a record or create it if not found.
1038
+ *
1039
+ * Does NOT update existing records - returns them as-is.
1040
+ * Useful when you want to ensure a record exists without modifying it.
1041
+ *
1042
+ * @param filter - Conditions to find by
1043
+ * @param data - Data to create if not found (merged with filter)
1044
+ * @returns Promise resolving to found or created model
1045
+ *
1046
+ * @example
1047
+ * ```typescript
1048
+ * // Ensure default admin exists (don't modify if exists)
1049
+ * const admin = await User.findOrCreate(
1050
+ * { email: "admin@example.com" },
1051
+ * { email: "admin@example.com", name: "Admin", role: "admin" }
1052
+ * );
1053
+ * // If admin exists, returns existing (password unchanged)
1054
+ * // If not found, creates new admin
1055
+ * ```
1056
+ */
1057
+ static findOrCreate<TModel extends Model = Model, TSchema extends ModelSchema = TModel extends Model<infer S> ? S : ModelSchema>(this: ChildModel<TModel>, filter: Partial<TSchema>, data: Partial<TSchema>): Promise<TModel>;
1058
+ /**
1059
+ * Update a record or create it if not found (upsert).
1060
+ *
1061
+ * DOES update existing records with new data.
1062
+ * Useful when you want to ensure a record exists with the latest data.
1063
+ *
1064
+ * Includes full Model features:
1065
+ * - ID generation (if creating)
1066
+ * - createdAt timestamp (if creating)
1067
+ * - updatedAt timestamp (always)
1068
+ * - Validation & casting
1069
+ * - Lifecycle events
1070
+ * - Sync operations
1071
+ *
1072
+ * @param filter - Conditions to find by
1073
+ * @param data - Data to update or create (merged with filter)
1074
+ * @returns Promise resolving to updated or created model
1075
+ *
1076
+ * @example
1077
+ * ```typescript
1078
+ * // Sync user from external API (update if exists, create if not)
1079
+ * const user = await User.updateOrCreate(
1080
+ * { externalId: "ext-123" },
1081
+ * {
1082
+ * externalId: "ext-123",
1083
+ * name: "John Updated",
1084
+ * email: "john.new@example.com",
1085
+ * lastSyncedAt: new Date()
1086
+ * }
1087
+ * );
1088
+ * // User always has latest data from API
1089
+ * ```
1090
+ */
1091
+ static updateOrCreate<TModel extends Model = Model, TSchema extends ModelSchema = TModel extends Model<infer S> ? S : ModelSchema>(this: ChildModel<TModel>, filter: Partial<TSchema>, data: Partial<TSchema>): Promise<TModel>;
1092
+ /**
1093
+ * Returns embedded data for sync operations.
1094
+ * Excludes internal MongoDB fields and ensures proper date serialization.
1095
+ *
1096
+ * @returns Embedded data object suitable for syncing
1097
+ *
1098
+ * @example
1099
+ * ```typescript
1100
+ * const user = await User.find(1);
1101
+ * const embedData = user.embedData;
1102
+ * // Returns: { id: 1, name: "Alice", email: "alice@example.com", ... }
1103
+ * // Excludes: _id
1104
+ * ```
1105
+ */
1106
+ get embedData(): Record<string, unknown>;
1107
+ /**
1108
+ * Accesses the event emitter dedicated to this model constructor.
1109
+ *
1110
+ * Each model subclass gets its own isolated event emitter, allowing you to
1111
+ * register lifecycle hooks that only apply to that specific model.
1112
+ *
1113
+ * @returns The ModelEvents instance for this model constructor
1114
+ *
1115
+ * @example
1116
+ * ```typescript
1117
+ * User.events().onSaving((user) => {
1118
+ * console.log("User is being saved:", user);
1119
+ * });
1120
+ * ```
1121
+ */
1122
+ static events<TModel extends Model = Model>(this: ChildModel<TModel>): ModelEvents<TModel>;
1123
+ /**
1124
+ * Cleanup model events
1125
+ */
1126
+ static $cleanup(): void;
1127
+ /**
1128
+ * Registers an event listener for this model constructor.
1129
+ *
1130
+ * Convenience shorthand for `Model.events().on(...)`.
1131
+ *
1132
+ * @param event - The event name (e.g., "saving", "created")
1133
+ * @param listener - The callback to invoke when the event fires
1134
+ * @returns An unsubscribe function
1135
+ *
1136
+ * @example
1137
+ * ```typescript
1138
+ * const unsubscribe = User.on("saving", (user) => {
1139
+ * console.log("Saving user:", user);
1140
+ * });
1141
+ * ```
1142
+ */
1143
+ static on<TModel extends Model = Model, TContext = unknown>(this: ChildModel<TModel>, event: ModelEventName, listener: ModelEventListener<TModel, TContext>): () => void;
1144
+ /**
1145
+ * Registers a one-time event listener for this model constructor.
1146
+ *
1147
+ * The listener will automatically unsubscribe after its first invocation.
1148
+ * Convenience shorthand for `Model.events().once(...)`.
1149
+ *
1150
+ * @param event - The event name (e.g., "saving", "created")
1151
+ * @param listener - The callback to invoke when the event fires
1152
+ * @returns An unsubscribe function
1153
+ *
1154
+ * @example
1155
+ * ```typescript
1156
+ * User.once("created", (user) => {
1157
+ * console.log("First user created:", user);
1158
+ * });
1159
+ * ```
1160
+ */
1161
+ static once<TModel extends Model = Model, TContext = unknown>(this: ChildModel<TModel>, event: ModelEventName, listener: ModelEventListener<TModel, TContext>): () => void;
1162
+ /**
1163
+ * Removes an event listener from this model constructor.
1164
+ *
1165
+ * Convenience shorthand for `Model.events().off(...)`.
1166
+ *
1167
+ * @param event - The event name
1168
+ * @param listener - The callback to remove
1169
+ *
1170
+ * @example
1171
+ * ```typescript
1172
+ * const listener = (user) => console.log(user);
1173
+ * User.on("saving", listener);
1174
+ * User.off("saving", listener);
1175
+ * ```
1176
+ */
1177
+ static off<TModel extends Model = Model, TContext = unknown>(this: ChildModel<TModel>, event: ModelEventName, listener: ModelEventListener<TModel, TContext>): void;
1178
+ /**
1179
+ * Accesses the global event emitter shared by all model instances.
1180
+ *
1181
+ * Use this for cross-cutting concerns like auditing, logging, or injecting
1182
+ * common fields (e.g., `createdBy`, `updatedBy`) across all models.
1183
+ *
1184
+ * @returns The global ModelEvents instance
1185
+ *
1186
+ * @example
1187
+ * ```typescript
1188
+ * Model.globalEvents().onSaving((model) => {
1189
+ * model.set("updatedAt", new Date());
1190
+ * });
1191
+ * ```
1192
+ */
1193
+ static globalEvents(): ModelEvents<Model>;
1194
+ /**
1195
+ * Replace the model's data entirely.
1196
+ *
1197
+ * Used internally by the writer after validation to update the model
1198
+ * with validated/casted data.
1199
+ *
1200
+ * **Warning:** This replaces all data and updates the dirty tracker.
1201
+ * Use with caution in application code.
1202
+ *
1203
+ * @param data - New data to replace current data
1204
+ *
1205
+ * @example
1206
+ * ```typescript
1207
+ * // Internal usage by writer
1208
+ * model.replaceData(validatedData);
1209
+ * ```
1210
+ */
1211
+ replaceData(data: Record<string, unknown>): void;
1212
+ /**
1213
+ * Save the model to the database.
1214
+ *
1215
+ * Performs insert if `isNew === true`, otherwise performs update.
1216
+ * Automatically validates, casts, generates IDs, and emits lifecycle events.
1217
+ *
1218
+ * **Features:**
1219
+ * - Validation via @warlock.js/seal schema
1220
+ * - Data casting (string → number, etc.)
1221
+ * - ID generation (NoSQL only)
1222
+ * - Partial updates (only changed fields)
1223
+ * - Lifecycle events (validating, saving, created/updated, saved)
1224
+ *
1225
+ * @param data - Optional data to merge before saving
1226
+ * @param options - Save options
1227
+ * @returns The model instance for method chaining
1228
+ *
1229
+ * @throws {ValidationError} If validation fails
1230
+ * @throws {Error} If database operation fails
1231
+ *
1232
+ * @example
1233
+ * ```typescript
1234
+ * // Simple save
1235
+ * const user = new User({ name: "Alice" });
1236
+ * await user.save();
1237
+ *
1238
+ * // Merge data before saving
1239
+ * await user.save({ age: 31, email: "alice@example.com" });
1240
+ *
1241
+ * // Silent save (no events)
1242
+ * await user.save(null, { skipEvents: true });
1243
+ *
1244
+ * // Skip validation
1245
+ * await user.save(null, { skipValidation: true });
1246
+ *
1247
+ * // Method chaining
1248
+ * await user.set("name", "Bob").save();
1249
+ * ```
1250
+ */
1251
+ save(options?: WriterOptions & {
1252
+ merge?: Partial<TSchema>;
1253
+ }): Promise<this>;
1254
+ /**
1255
+ * Serialize the model data for storage in database
1256
+ */
1257
+ serialize(): Record<string, unknown>;
1258
+ /**
1259
+ * Deseriaze the given data
1260
+ */
1261
+ static deserialize<TModel extends Model>(this: ChildModel<TModel>, data: any): TModel;
1262
+ /**
1263
+ * Convert the model into JSON
1264
+ */
1265
+ toJSON(): any;
1266
+ }
1267
+ //# sourceMappingURL=model.d.ts.map