@warlock.js/cascade 4.0.48 → 4.0.59

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,253 @@
1
+ /**
2
+ * Represents the old and new values of a dirty column.
3
+ */
4
+ type DirtyColumnValues = {
5
+ oldValue: unknown;
6
+ newValue: unknown;
7
+ };
8
+ /**
9
+ * Tracks changes to model data by maintaining snapshots of initial and current state.
10
+ *
11
+ * The tracker stores both raw (nested) and flattened (dot-notation) versions of the data
12
+ * to accurately detect modifications, additions, and removals at any nesting level.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice", age: 30 });
17
+ * tracker.mergeChanges({ age: 31 });
18
+ * console.log(tracker.hasChanges()); // true
19
+ * console.log(tracker.getDirtyColumns()); // ["age"]
20
+ * console.log(tracker.getDirtyColumnsWithValues());
21
+ * // { age: { oldValue: 30, newValue: 31 } }
22
+ * ```
23
+ */
24
+ export declare class DatabaseDirtyTracker {
25
+ /**
26
+ * The initial raw data snapshot taken at construction or last reset.
27
+ * Used as the baseline for comparison.
28
+ */
29
+ private initialRaw;
30
+ /**
31
+ * The current raw data snapshot reflecting all changes made via merge/unset.
32
+ */
33
+ private currentRaw;
34
+ /**
35
+ * Flattened version of the initial data using dot-notation keys.
36
+ * Example: { "address.city": "NYC" }
37
+ */
38
+ private initialFlattened;
39
+ /**
40
+ * Flattened version of the current data using dot-notation keys.
41
+ */
42
+ private currentFlattened;
43
+ /**
44
+ * Set of column names (dot-notation paths) that have been modified.
45
+ */
46
+ private readonly dirtyColumns;
47
+ /**
48
+ * Set of column names (dot-notation paths) that existed initially but have been removed.
49
+ */
50
+ private readonly removedColumns;
51
+ /**
52
+ * Constructs a new dirty tracker with the provided initial data.
53
+ *
54
+ * @param data - The initial data to track
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice", email: "alice@example.com" });
59
+ * ```
60
+ */
61
+ constructor(data: Record<string, unknown>);
62
+ /**
63
+ * Returns the list of dirty columns using dot-notation.
64
+ *
65
+ * A column is considered dirty if its value has changed compared to the initial snapshot.
66
+ *
67
+ * @returns An array of column names (dot-notation paths) that have been modified
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * tracker.mergeChanges({ name: "Bob", "address.city": "LA" });
72
+ * tracker.getDirtyColumns(); // ["name", "address.city"]
73
+ * ```
74
+ */
75
+ getDirtyColumns(): string[];
76
+ /**
77
+ * Determines whether there are any tracked changes.
78
+ *
79
+ * Returns `true` if any columns have been modified or removed since the initial snapshot.
80
+ *
81
+ * @returns `true` if there are changes, `false` otherwise
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice" });
86
+ * tracker.hasChanges(); // false
87
+ * tracker.mergeChanges({ name: "Bob" });
88
+ * tracker.hasChanges(); // true
89
+ * tracker.unset("name");
90
+ * tracker.hasChanges(); // true (removed column counts as a change)
91
+ * ```
92
+ */
93
+ hasChanges(): boolean;
94
+ /**
95
+ * Check if the given column is dirty (changed)
96
+ */
97
+ isDirty(column: string): boolean;
98
+ /**
99
+ * Returns the set of columns that have been removed compared to the baseline.
100
+ *
101
+ * A column is considered removed if it existed in the initial snapshot but has been
102
+ * explicitly unset or deleted from the current data.
103
+ *
104
+ * @returns An array of column names (dot-notation paths) that have been removed
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice", temp: "value" });
109
+ * tracker.unset("temp");
110
+ * tracker.getRemovedColumns(); // ["temp"]
111
+ * ```
112
+ */
113
+ getRemovedColumns(): string[];
114
+ /**
115
+ * Provides a mapping of dirty columns to their previous and current values.
116
+ *
117
+ * This is useful for generating audit logs, building partial update payloads,
118
+ * or displaying change summaries to users.
119
+ *
120
+ * @returns A record mapping each dirty column to an object containing oldValue and newValue
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice", age: 30 });
125
+ * tracker.mergeChanges({ age: 31 });
126
+ * tracker.getDirtyColumnsWithValues();
127
+ * // { age: { oldValue: 30, newValue: 31 } }
128
+ * ```
129
+ */
130
+ getDirtyColumnsWithValues(): Record<string, DirtyColumnValues>;
131
+ /**
132
+ * Replaces the current data snapshot entirely and recomputes the diff.
133
+ *
134
+ * This is useful when you want to replace all current data with a new set,
135
+ * while keeping the initial baseline for comparison.
136
+ *
137
+ * @param data - The new data to set as the current snapshot
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice" });
142
+ * tracker.replaceCurrentData({ name: "Bob", email: "bob@example.com" });
143
+ * tracker.getDirtyColumns(); // ["name", "email"]
144
+ * ```
145
+ */
146
+ replaceCurrentData(data: Record<string, unknown>): void;
147
+ /**
148
+ * Merges a partial payload into the current snapshot and recomputes the diff.
149
+ *
150
+ * This performs a deep merge, preserving existing nested structures while
151
+ * updating only the specified fields.
152
+ *
153
+ * @param partial - Partial data to merge into the current snapshot
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice", address: { city: "NYC" } });
158
+ * tracker.mergeChanges({ address: { zip: "10001" } });
159
+ * // Current data: { name: "Alice", address: { city: "NYC", zip: "10001" } }
160
+ * tracker.getDirtyColumns(); // ["address.zip"]
161
+ * ```
162
+ */
163
+ mergeChanges(partial: Record<string, unknown>): void;
164
+ /**
165
+ * Explicitly removes one or more columns from the current data.
166
+ *
167
+ * Supports both single column names and arrays of column names.
168
+ * Columns can be specified using dot-notation for nested paths.
169
+ *
170
+ * @param columns - A single column name or an array of column names to remove
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * tracker.unset("tempField");
175
+ * tracker.unset(["field1", "field2", "nested.field"]);
176
+ * tracker.getRemovedColumns(); // ["tempField", "field1", "field2", "nested.field"]
177
+ * ```
178
+ */
179
+ unset(columns: string | string[]): void;
180
+ /**
181
+ * Resets both the initial and current snapshots to the provided data.
182
+ *
183
+ * If no data is provided, the current snapshot becomes the new baseline.
184
+ * This clears all tracked changes and removed columns.
185
+ *
186
+ * @param data - Optional new data to use as the baseline. If omitted, uses current data.
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice" });
191
+ * tracker.mergeChanges({ name: "Bob" });
192
+ * tracker.hasChanges(); // true
193
+ * tracker.reset(); // Make current state the new baseline
194
+ * tracker.hasChanges(); // false
195
+ *
196
+ * // Or reset to entirely new data:
197
+ * tracker.reset({ name: "Charlie", age: 25 });
198
+ * ```
199
+ */
200
+ reset(data?: Record<string, unknown>): void;
201
+ /**
202
+ * Recomputes the dirty and removed column sets by comparing initial and current snapshots.
203
+ *
204
+ * This method is called internally after any operation that modifies the current data.
205
+ * It iterates through all keys in both flattened snapshots and determines which columns
206
+ * have been modified or removed.
207
+ *
208
+ * @private
209
+ */
210
+ private updateDirtyState;
211
+ /**
212
+ * Recursively merges source object into target object, performing a deep merge.
213
+ *
214
+ * For nested objects, the merge is recursive. For arrays and primitives, the source
215
+ * value replaces the target value. All values are cloned to prevent reference sharing.
216
+ *
217
+ * @param target - The object to merge into
218
+ * @param source - The object to merge from
219
+ * @private
220
+ */
221
+ private mergeIntoRaw;
222
+ /**
223
+ * Deletes a field from the current raw data using a dot-notation path.
224
+ *
225
+ * Supports nested paths (e.g., "address.city") and array indices (e.g., "items.0").
226
+ * If any segment in the path doesn't exist, the operation is a no-op.
227
+ *
228
+ * @param path - The dot-notation path to the field to delete
229
+ * @private
230
+ */
231
+ private deleteFromRaw;
232
+ /**
233
+ * Resolves a single segment of a dot-notation path within a container.
234
+ *
235
+ * Handles both object property access and array index access.
236
+ *
237
+ * @param container - The object or array to access
238
+ * @param segment - The property name or array index as a string
239
+ * @returns The value at the specified segment, or undefined if not found
240
+ * @private
241
+ */
242
+ private resolveSegment;
243
+ /**
244
+ * Creates a deep clone of the provided data.
245
+ *
246
+ * @param data - The data to clone
247
+ * @returns A deep clone of the data
248
+ * @private
249
+ */
250
+ private cloneData;
251
+ }
252
+ export {};
253
+ //# sourceMappingURL=database-dirty-tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-dirty-tracker.d.ts","sourceRoot":"","sources":["../src/database-dirty-tracker.ts"],"names":[],"mappings":"AAiDA;;GAEG;AACH,KAAK,iBAAiB,GAAG;IAAE,QAAQ,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAElE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,oBAAoB;IAC/B;;;OAGG;IACH,OAAO,CAAC,UAAU,CAA0B;IAE5C;;OAEG;IACH,OAAO,CAAC,UAAU,CAA0B;IAE5C;;;OAGG;IACH,OAAO,CAAC,gBAAgB,CAAa;IAErC;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAAa;IAErC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAElD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAqB;IAEpD;;;;;;;;;OASG;gBACgB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAUhD;;;;;;;;;;;;OAYG;IACI,eAAe,IAAI,MAAM,EAAE;IAIlC;;;;;;;;;;;;;;;;OAgBG;IACI,UAAU,IAAI,OAAO;IAI5B;;OAEG;IACI,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIvC;;;;;;;;;;;;;;OAcG;IACI,iBAAiB,IAAI,MAAM,EAAE;IAIpC;;;;;;;;;;;;;;;OAeG;IACI,yBAAyB,IAAI,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC;IAgBrE;;;;;;;;;;;;;;OAcG;IACI,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAM9D;;;;;;;;;;;;;;;OAeG;IACI,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAM3D;;;;;;;;;;;;;;OAcG;IACI,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI;IAW9C;;;;;;;;;;;;;;;;;;;OAmBG;IACI,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAYlD;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IA0BxB;;;;;;;;;OASG;IACH,OAAO,CAAC,YAAY;IAkBpB;;;;;;;;OAQG;IACH,OAAO,CAAC,aAAa;IA8BrB;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;IAiBtB;;;;;;OAMG;IACH,OAAO,CAAC,SAAS;CAGlB"}
@@ -0,0 +1,389 @@
1
+ import {areEqual,clone}from'@mongez/reinforcements';import {isPlainObject}from'@mongez/supportive-is';function canBeFlatten(object) {
2
+ return isPlainObject(object);
3
+ }
4
+ /**
5
+ * A fix for flatten as non-plain object is being flatten as well which it should not be
6
+ */
7
+ function flatten(object, separator = ".", keepNestedOriginalObject = false, parent, root = {}) {
8
+ if (canBeFlatten(object) === false) {
9
+ return object;
10
+ }
11
+ // object = toPlainObject(object);
12
+ for (const key of Object.keys(object)) {
13
+ const value = object[key];
14
+ const keyChain = parent ? parent + separator + key : key;
15
+ if ((Array.isArray(value) && value.length === 0) || typeof value === "function") {
16
+ root[keyChain] = value;
17
+ }
18
+ else if (canBeFlatten(value)) {
19
+ if (keepNestedOriginalObject) {
20
+ root[keyChain] = value;
21
+ }
22
+ flatten(value, separator, keepNestedOriginalObject, keyChain, root);
23
+ }
24
+ else {
25
+ root[keyChain] = value;
26
+ }
27
+ }
28
+ return root;
29
+ }
30
+ /**
31
+ * Tracks changes to model data by maintaining snapshots of initial and current state.
32
+ *
33
+ * The tracker stores both raw (nested) and flattened (dot-notation) versions of the data
34
+ * to accurately detect modifications, additions, and removals at any nesting level.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice", age: 30 });
39
+ * tracker.mergeChanges({ age: 31 });
40
+ * console.log(tracker.hasChanges()); // true
41
+ * console.log(tracker.getDirtyColumns()); // ["age"]
42
+ * console.log(tracker.getDirtyColumnsWithValues());
43
+ * // { age: { oldValue: 30, newValue: 31 } }
44
+ * ```
45
+ */
46
+ class DatabaseDirtyTracker {
47
+ /**
48
+ * The initial raw data snapshot taken at construction or last reset.
49
+ * Used as the baseline for comparison.
50
+ */
51
+ initialRaw;
52
+ /**
53
+ * The current raw data snapshot reflecting all changes made via merge/unset.
54
+ */
55
+ currentRaw;
56
+ /**
57
+ * Flattened version of the initial data using dot-notation keys.
58
+ * Example: { "address.city": "NYC" }
59
+ */
60
+ initialFlattened;
61
+ /**
62
+ * Flattened version of the current data using dot-notation keys.
63
+ */
64
+ currentFlattened;
65
+ /**
66
+ * Set of column names (dot-notation paths) that have been modified.
67
+ */
68
+ dirtyColumns = new Set();
69
+ /**
70
+ * Set of column names (dot-notation paths) that existed initially but have been removed.
71
+ */
72
+ removedColumns = new Set();
73
+ /**
74
+ * Constructs a new dirty tracker with the provided initial data.
75
+ *
76
+ * @param data - The initial data to track
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice", email: "alice@example.com" });
81
+ * ```
82
+ */
83
+ constructor(data) {
84
+ this.initialRaw = this.cloneData(data);
85
+ this.currentRaw = this.cloneData(data);
86
+ this.initialFlattened = flatten(this.initialRaw);
87
+ this.currentFlattened = { ...this.initialFlattened };
88
+ this.updateDirtyState();
89
+ }
90
+ /**
91
+ * Returns the list of dirty columns using dot-notation.
92
+ *
93
+ * A column is considered dirty if its value has changed compared to the initial snapshot.
94
+ *
95
+ * @returns An array of column names (dot-notation paths) that have been modified
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * tracker.mergeChanges({ name: "Bob", "address.city": "LA" });
100
+ * tracker.getDirtyColumns(); // ["name", "address.city"]
101
+ * ```
102
+ */
103
+ getDirtyColumns() {
104
+ return Array.from(this.dirtyColumns);
105
+ }
106
+ /**
107
+ * Determines whether there are any tracked changes.
108
+ *
109
+ * Returns `true` if any columns have been modified or removed since the initial snapshot.
110
+ *
111
+ * @returns `true` if there are changes, `false` otherwise
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice" });
116
+ * tracker.hasChanges(); // false
117
+ * tracker.mergeChanges({ name: "Bob" });
118
+ * tracker.hasChanges(); // true
119
+ * tracker.unset("name");
120
+ * tracker.hasChanges(); // true (removed column counts as a change)
121
+ * ```
122
+ */
123
+ hasChanges() {
124
+ return this.dirtyColumns.size > 0 || this.removedColumns.size > 0;
125
+ }
126
+ /**
127
+ * Check if the given column is dirty (changed)
128
+ */
129
+ isDirty(column) {
130
+ return this.dirtyColumns.has(column);
131
+ }
132
+ /**
133
+ * Returns the set of columns that have been removed compared to the baseline.
134
+ *
135
+ * A column is considered removed if it existed in the initial snapshot but has been
136
+ * explicitly unset or deleted from the current data.
137
+ *
138
+ * @returns An array of column names (dot-notation paths) that have been removed
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice", temp: "value" });
143
+ * tracker.unset("temp");
144
+ * tracker.getRemovedColumns(); // ["temp"]
145
+ * ```
146
+ */
147
+ getRemovedColumns() {
148
+ return Array.from(this.removedColumns);
149
+ }
150
+ /**
151
+ * Provides a mapping of dirty columns to their previous and current values.
152
+ *
153
+ * This is useful for generating audit logs, building partial update payloads,
154
+ * or displaying change summaries to users.
155
+ *
156
+ * @returns A record mapping each dirty column to an object containing oldValue and newValue
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice", age: 30 });
161
+ * tracker.mergeChanges({ age: 31 });
162
+ * tracker.getDirtyColumnsWithValues();
163
+ * // { age: { oldValue: 30, newValue: 31 } }
164
+ * ```
165
+ */
166
+ getDirtyColumnsWithValues() {
167
+ const result = {};
168
+ for (const column of this.dirtyColumns) {
169
+ const hasCurrent = this.currentFlattened[column] !== undefined || column in this.currentFlattened;
170
+ result[column] = {
171
+ oldValue: this.initialFlattened[column],
172
+ newValue: hasCurrent ? this.currentFlattened[column] : undefined,
173
+ };
174
+ }
175
+ return result;
176
+ }
177
+ /**
178
+ * Replaces the current data snapshot entirely and recomputes the diff.
179
+ *
180
+ * This is useful when you want to replace all current data with a new set,
181
+ * while keeping the initial baseline for comparison.
182
+ *
183
+ * @param data - The new data to set as the current snapshot
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice" });
188
+ * tracker.replaceCurrentData({ name: "Bob", email: "bob@example.com" });
189
+ * tracker.getDirtyColumns(); // ["name", "email"]
190
+ * ```
191
+ */
192
+ replaceCurrentData(data) {
193
+ this.currentRaw = this.cloneData(data);
194
+ this.currentFlattened = flatten(this.currentRaw);
195
+ this.updateDirtyState();
196
+ }
197
+ /**
198
+ * Merges a partial payload into the current snapshot and recomputes the diff.
199
+ *
200
+ * This performs a deep merge, preserving existing nested structures while
201
+ * updating only the specified fields.
202
+ *
203
+ * @param partial - Partial data to merge into the current snapshot
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice", address: { city: "NYC" } });
208
+ * tracker.mergeChanges({ address: { zip: "10001" } });
209
+ * // Current data: { name: "Alice", address: { city: "NYC", zip: "10001" } }
210
+ * tracker.getDirtyColumns(); // ["address.zip"]
211
+ * ```
212
+ */
213
+ mergeChanges(partial) {
214
+ this.mergeIntoRaw(this.currentRaw, partial);
215
+ this.currentFlattened = flatten(this.currentRaw);
216
+ this.updateDirtyState();
217
+ }
218
+ /**
219
+ * Explicitly removes one or more columns from the current data.
220
+ *
221
+ * Supports both single column names and arrays of column names.
222
+ * Columns can be specified using dot-notation for nested paths.
223
+ *
224
+ * @param columns - A single column name or an array of column names to remove
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * tracker.unset("tempField");
229
+ * tracker.unset(["field1", "field2", "nested.field"]);
230
+ * tracker.getRemovedColumns(); // ["tempField", "field1", "field2", "nested.field"]
231
+ * ```
232
+ */
233
+ unset(columns) {
234
+ const targets = Array.isArray(columns) ? columns : [columns];
235
+ for (const path of targets) {
236
+ this.deleteFromRaw(path);
237
+ }
238
+ this.currentFlattened = flatten(this.currentRaw);
239
+ this.updateDirtyState();
240
+ }
241
+ /**
242
+ * Resets both the initial and current snapshots to the provided data.
243
+ *
244
+ * If no data is provided, the current snapshot becomes the new baseline.
245
+ * This clears all tracked changes and removed columns.
246
+ *
247
+ * @param data - Optional new data to use as the baseline. If omitted, uses current data.
248
+ *
249
+ * @example
250
+ * ```typescript
251
+ * const tracker = new DatabaseDirtyTracker({ name: "Alice" });
252
+ * tracker.mergeChanges({ name: "Bob" });
253
+ * tracker.hasChanges(); // true
254
+ * tracker.reset(); // Make current state the new baseline
255
+ * tracker.hasChanges(); // false
256
+ *
257
+ * // Or reset to entirely new data:
258
+ * tracker.reset({ name: "Charlie", age: 25 });
259
+ * ```
260
+ */
261
+ reset(data) {
262
+ const source = data ?? this.currentRaw;
263
+ this.initialRaw = this.cloneData(source);
264
+ this.currentRaw = this.cloneData(source);
265
+ this.initialFlattened = flatten(this.initialRaw);
266
+ this.currentFlattened = flatten(this.currentRaw);
267
+ this.dirtyColumns.clear();
268
+ this.removedColumns.clear();
269
+ }
270
+ /**
271
+ * Recomputes the dirty and removed column sets by comparing initial and current snapshots.
272
+ *
273
+ * This method is called internally after any operation that modifies the current data.
274
+ * It iterates through all keys in both flattened snapshots and determines which columns
275
+ * have been modified or removed.
276
+ *
277
+ * @private
278
+ */
279
+ updateDirtyState() {
280
+ this.dirtyColumns.clear();
281
+ this.removedColumns.clear();
282
+ const keys = new Set([
283
+ ...Object.keys(this.initialFlattened),
284
+ ...Object.keys(this.currentFlattened),
285
+ ]);
286
+ for (const key of keys) {
287
+ const hasCurrent = this.currentFlattened[key] !== undefined || key in this.currentFlattened;
288
+ const hasInitial = this.initialFlattened[key] !== undefined || key in this.initialFlattened;
289
+ if (!hasCurrent && hasInitial) {
290
+ this.removedColumns.add(key);
291
+ }
292
+ const initialValue = this.initialFlattened[key];
293
+ const currentValue = hasCurrent ? this.currentFlattened[key] : undefined;
294
+ if (!areEqual(initialValue, currentValue)) {
295
+ this.dirtyColumns.add(key);
296
+ }
297
+ }
298
+ }
299
+ /**
300
+ * Recursively merges source object into target object, performing a deep merge.
301
+ *
302
+ * For nested objects, the merge is recursive. For arrays and primitives, the source
303
+ * value replaces the target value. All values are cloned to prevent reference sharing.
304
+ *
305
+ * @param target - The object to merge into
306
+ * @param source - The object to merge from
307
+ * @private
308
+ */
309
+ mergeIntoRaw(target, source) {
310
+ for (const [key, value] of Object.entries(source)) {
311
+ if (value &&
312
+ typeof value === "object" &&
313
+ !Array.isArray(value) &&
314
+ target[key] &&
315
+ typeof target[key] === "object" &&
316
+ !Array.isArray(target[key])) {
317
+ this.mergeIntoRaw(target[key], value);
318
+ continue;
319
+ }
320
+ target[key] = this.cloneData(value);
321
+ }
322
+ }
323
+ /**
324
+ * Deletes a field from the current raw data using a dot-notation path.
325
+ *
326
+ * Supports nested paths (e.g., "address.city") and array indices (e.g., "items.0").
327
+ * If any segment in the path doesn't exist, the operation is a no-op.
328
+ *
329
+ * @param path - The dot-notation path to the field to delete
330
+ * @private
331
+ */
332
+ deleteFromRaw(path) {
333
+ const segments = path.split(".");
334
+ let container = this.currentRaw;
335
+ for (let index = 0; index < segments.length - 1; index += 1) {
336
+ if (container === undefined || container === null) {
337
+ return;
338
+ }
339
+ container = this.resolveSegment(container, segments[index]);
340
+ }
341
+ if (container === undefined || container === null) {
342
+ return;
343
+ }
344
+ const lastSegment = segments[segments.length - 1];
345
+ if (Array.isArray(container)) {
346
+ const numericIndex = Number(lastSegment);
347
+ if (!Number.isNaN(numericIndex)) {
348
+ container.splice(numericIndex, 1);
349
+ }
350
+ return;
351
+ }
352
+ if (typeof container === "object") {
353
+ delete container[lastSegment];
354
+ }
355
+ }
356
+ /**
357
+ * Resolves a single segment of a dot-notation path within a container.
358
+ *
359
+ * Handles both object property access and array index access.
360
+ *
361
+ * @param container - The object or array to access
362
+ * @param segment - The property name or array index as a string
363
+ * @returns The value at the specified segment, or undefined if not found
364
+ * @private
365
+ */
366
+ resolveSegment(container, segment) {
367
+ if (Array.isArray(container)) {
368
+ const numericIndex = Number(segment);
369
+ if (Number.isNaN(numericIndex)) {
370
+ return undefined;
371
+ }
372
+ return container[numericIndex];
373
+ }
374
+ if (container && typeof container === "object") {
375
+ return container[segment];
376
+ }
377
+ return undefined;
378
+ }
379
+ /**
380
+ * Creates a deep clone of the provided data.
381
+ *
382
+ * @param data - The data to clone
383
+ * @returns A deep clone of the data
384
+ * @private
385
+ */
386
+ cloneData(data) {
387
+ return clone(data);
388
+ }
389
+ }export{DatabaseDirtyTracker};//# sourceMappingURL=database-dirty-tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-dirty-tracker.js","sources":["../src/database-dirty-tracker.ts"],"sourcesContent":[null],"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