@decaf-ts/core 0.24.0 → 0.25.1

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 (340) hide show
  1. package/lib/cjs/index.cjs +1 -1
  2. package/lib/esm/index.js +1 -1
  3. package/lib/types/auth/decorators.d.cts +2 -2
  4. package/lib/types/auth/decorators.d.mts +2 -2
  5. package/lib/types/auth/index.d.cts +2 -2
  6. package/lib/types/auth/index.d.mts +2 -2
  7. package/lib/types/fs/FilesystemAdapter.d.cts +5 -5
  8. package/lib/types/fs/FilesystemAdapter.d.mts +5 -5
  9. package/lib/types/fs/FsDispatch.d.cts +4 -4
  10. package/lib/types/fs/FsDispatch.d.mts +4 -4
  11. package/lib/types/fs/index.d.cts +4 -4
  12. package/lib/types/fs/index.d.mts +4 -4
  13. package/lib/types/fs/indexStore.d.cts +2 -2
  14. package/lib/types/fs/indexStore.d.mts +2 -2
  15. package/lib/types/fs/types.d.cts +2 -2
  16. package/lib/types/fs/types.d.mts +2 -2
  17. package/lib/types/identity/decorators.d.cts +3 -3
  18. package/lib/types/identity/decorators.d.mts +3 -3
  19. package/lib/types/identity/index.d.cts +1 -1
  20. package/lib/types/identity/index.d.mts +1 -1
  21. package/lib/types/index.d.cts +13 -13
  22. package/lib/types/index.d.mts +13 -13
  23. package/lib/types/interfaces/ContextuallyLogged.d.cts +2 -2
  24. package/lib/types/interfaces/ContextuallyLogged.d.mts +2 -2
  25. package/lib/types/interfaces/Observable.d.cts +1 -1
  26. package/lib/types/interfaces/Observable.d.mts +1 -1
  27. package/lib/types/interfaces/Paginatable.d.cts +1 -1
  28. package/lib/types/interfaces/Paginatable.d.mts +1 -1
  29. package/lib/types/interfaces/Queriable.d.cts +2 -2
  30. package/lib/types/interfaces/Queriable.d.mts +2 -2
  31. package/lib/types/interfaces/RawExecutor.d.cts +1 -1
  32. package/lib/types/interfaces/RawExecutor.d.mts +1 -1
  33. package/lib/types/interfaces/index.d.cts +7 -7
  34. package/lib/types/interfaces/index.d.mts +7 -7
  35. package/lib/types/migrations/Migration.d.cts +4 -4
  36. package/lib/types/migrations/Migration.d.mts +4 -4
  37. package/lib/types/migrations/MigrationService.d.cts +7 -7
  38. package/lib/types/migrations/MigrationService.d.mts +7 -7
  39. package/lib/types/migrations/MigrationTaskBuilder.d.cts +3 -3
  40. package/lib/types/migrations/MigrationTaskBuilder.d.mts +3 -3
  41. package/lib/types/migrations/MigrationTasks.d.cts +2 -2
  42. package/lib/types/migrations/MigrationTasks.d.mts +2 -2
  43. package/lib/types/migrations/SemverMigrationVersioning.d.cts +1 -1
  44. package/lib/types/migrations/SemverMigrationVersioning.d.mts +1 -1
  45. package/lib/types/migrations/StandardMigrationVersioning.d.cts +1 -1
  46. package/lib/types/migrations/StandardMigrationVersioning.d.mts +1 -1
  47. package/lib/types/migrations/constants.d.cts +1 -1
  48. package/lib/types/migrations/constants.d.mts +1 -1
  49. package/lib/types/migrations/decorators.d.cts +1 -1
  50. package/lib/types/migrations/decorators.d.mts +1 -1
  51. package/lib/types/migrations/index.d.cts +9 -9
  52. package/lib/types/migrations/index.d.mts +9 -9
  53. package/lib/types/migrations/types.d.cts +5 -5
  54. package/lib/types/migrations/types.d.mts +5 -5
  55. package/lib/types/model/SequenceModel.d.cts +1 -1
  56. package/lib/types/model/SequenceModel.d.mts +1 -1
  57. package/lib/types/model/construction.d.cts +4 -4
  58. package/lib/types/model/construction.d.mts +4 -4
  59. package/lib/types/model/decorators.d.cts +4 -4
  60. package/lib/types/model/decorators.d.mts +4 -4
  61. package/lib/types/model/index.d.cts +6 -6
  62. package/lib/types/model/index.d.mts +6 -6
  63. package/lib/types/model/indexing.d.cts +1 -1
  64. package/lib/types/model/indexing.d.mts +1 -1
  65. package/lib/types/model/types.d.cts +2 -2
  66. package/lib/types/model/types.d.mts +2 -2
  67. package/lib/types/overrides/Metadata.d.cts +6 -6
  68. package/lib/types/overrides/Metadata.d.mts +6 -6
  69. package/lib/types/overrides/Model.d.cts +3 -3
  70. package/lib/types/overrides/Model.d.mts +3 -3
  71. package/lib/types/overrides/index.d.cts +5 -5
  72. package/lib/types/overrides/index.d.mts +5 -5
  73. package/lib/types/overrides/injectables.d.cts +2 -2
  74. package/lib/types/overrides/injectables.d.mts +2 -2
  75. package/lib/types/persistence/Adapter.d.cts +15 -15
  76. package/lib/types/persistence/Adapter.d.mts +15 -15
  77. package/lib/types/persistence/Context.d.cts +1 -1
  78. package/lib/types/persistence/Context.d.mts +1 -1
  79. package/lib/types/persistence/ContextLock.d.cts +1 -1
  80. package/lib/types/persistence/ContextLock.d.mts +1 -1
  81. package/lib/types/persistence/Dispatch.d.cts +4 -4
  82. package/lib/types/persistence/Dispatch.d.mts +4 -4
  83. package/lib/types/persistence/ObserverHandler.d.cts +4 -4
  84. package/lib/types/persistence/ObserverHandler.d.mts +4 -4
  85. package/lib/types/persistence/Sequence.d.cts +7 -7
  86. package/lib/types/persistence/Sequence.d.mts +7 -7
  87. package/lib/types/persistence/constants.d.cts +2 -2
  88. package/lib/types/persistence/constants.d.mts +2 -2
  89. package/lib/types/persistence/decorators.d.cts +3 -3
  90. package/lib/types/persistence/decorators.d.mts +3 -3
  91. package/lib/types/persistence/event-filters.d.cts +2 -2
  92. package/lib/types/persistence/event-filters.d.mts +2 -2
  93. package/lib/types/persistence/index.d.cts +13 -13
  94. package/lib/types/persistence/index.d.mts +13 -13
  95. package/lib/types/persistence/transactions.d.cts +2 -2
  96. package/lib/types/persistence/transactions.d.mts +2 -2
  97. package/lib/types/persistence/types.d.cts +8 -8
  98. package/lib/types/persistence/types.d.mts +8 -8
  99. package/lib/types/query/Condition.d.cts +2 -2
  100. package/lib/types/query/Condition.d.mts +2 -2
  101. package/lib/types/query/MethodQueryBuilder.d.cts +1 -1
  102. package/lib/types/query/MethodQueryBuilder.d.mts +1 -1
  103. package/lib/types/query/Paginator.d.cts +3 -3
  104. package/lib/types/query/Paginator.d.mts +3 -3
  105. package/lib/types/query/Statement.d.cts +11 -11
  106. package/lib/types/query/Statement.d.mts +11 -11
  107. package/lib/types/query/decorators.d.cts +3 -3
  108. package/lib/types/query/decorators.d.mts +3 -3
  109. package/lib/types/query/index.d.cts +11 -11
  110. package/lib/types/query/index.d.mts +11 -11
  111. package/lib/types/query/options.d.cts +4 -4
  112. package/lib/types/query/options.d.mts +4 -4
  113. package/lib/types/query/selectors.d.cts +1 -1
  114. package/lib/types/query/selectors.d.mts +1 -1
  115. package/lib/types/query/types.d.cts +3 -3
  116. package/lib/types/query/types.d.mts +3 -3
  117. package/lib/types/query/utils.d.cts +1 -1
  118. package/lib/types/query/utils.d.mts +1 -1
  119. package/lib/types/ram/RamAdapter.d.cts +7 -7
  120. package/lib/types/ram/RamAdapter.d.mts +7 -7
  121. package/lib/types/ram/RamPaginator.d.cts +4 -4
  122. package/lib/types/ram/RamPaginator.d.mts +4 -4
  123. package/lib/types/ram/RamStatement.d.cts +5 -5
  124. package/lib/types/ram/RamStatement.d.mts +5 -5
  125. package/lib/types/ram/handlers.d.cts +3 -3
  126. package/lib/types/ram/handlers.d.mts +3 -3
  127. package/lib/types/ram/index.d.cts +6 -6
  128. package/lib/types/ram/index.d.mts +6 -6
  129. package/lib/types/ram/types.d.cts +3 -3
  130. package/lib/types/ram/types.d.mts +3 -3
  131. package/lib/types/repository/Repository.d.cts +14 -14
  132. package/lib/types/repository/Repository.d.mts +14 -14
  133. package/lib/types/repository/constants.d.cts +1 -1
  134. package/lib/types/repository/constants.d.mts +1 -1
  135. package/lib/types/repository/index.d.cts +7 -7
  136. package/lib/types/repository/index.d.mts +7 -7
  137. package/lib/types/repository/types.d.cts +1 -1
  138. package/lib/types/repository/types.d.mts +1 -1
  139. package/lib/types/services/ModelService.d.cts +8 -8
  140. package/lib/types/services/ModelService.d.mts +8 -8
  141. package/lib/types/services/PersistenceService.d.cts +4 -4
  142. package/lib/types/services/PersistenceService.d.mts +4 -4
  143. package/lib/types/services/index.d.cts +3 -3
  144. package/lib/types/services/index.d.mts +3 -3
  145. package/lib/types/services/services.d.cts +5 -5
  146. package/lib/types/services/services.d.mts +5 -5
  147. package/lib/types/tasks/CleanUpTask.d.cts +5 -5
  148. package/lib/types/tasks/CleanUpTask.d.mts +5 -5
  149. package/lib/types/tasks/TaskContext.d.cts +7 -7
  150. package/lib/types/tasks/TaskContext.d.mts +7 -7
  151. package/lib/types/tasks/TaskEngine.d.cts +18 -18
  152. package/lib/types/tasks/TaskEngine.d.mts +18 -18
  153. package/lib/types/tasks/TaskErrors.d.cts +2 -2
  154. package/lib/types/tasks/TaskErrors.d.mts +2 -2
  155. package/lib/types/tasks/TaskEventBus.d.cts +7 -7
  156. package/lib/types/tasks/TaskEventBus.d.mts +7 -7
  157. package/lib/types/tasks/TaskEventService.d.cts +3 -3
  158. package/lib/types/tasks/TaskEventService.d.mts +3 -3
  159. package/lib/types/tasks/TaskHandler.d.cts +3 -3
  160. package/lib/types/tasks/TaskHandler.d.mts +3 -3
  161. package/lib/types/tasks/TaskHandlerRegistry.d.cts +1 -1
  162. package/lib/types/tasks/TaskHandlerRegistry.d.mts +1 -1
  163. package/lib/types/tasks/TaskService.d.cts +15 -15
  164. package/lib/types/tasks/TaskService.d.mts +15 -15
  165. package/lib/types/tasks/TaskStateChangeError.d.cts +2 -2
  166. package/lib/types/tasks/TaskStateChangeError.d.mts +2 -2
  167. package/lib/types/tasks/TaskTracker.d.cts +8 -8
  168. package/lib/types/tasks/TaskTracker.d.mts +8 -8
  169. package/lib/types/tasks/builder.d.cts +4 -4
  170. package/lib/types/tasks/builder.d.mts +4 -4
  171. package/lib/types/tasks/constants.d.cts +1 -1
  172. package/lib/types/tasks/constants.d.mts +1 -1
  173. package/lib/types/tasks/index.d.cts +17 -17
  174. package/lib/types/tasks/index.d.mts +17 -17
  175. package/lib/types/tasks/logging.d.cts +1 -1
  176. package/lib/types/tasks/logging.d.mts +1 -1
  177. package/lib/types/tasks/models/TaskBackoffModel.d.cts +1 -1
  178. package/lib/types/tasks/models/TaskBackoffModel.d.mts +1 -1
  179. package/lib/types/tasks/models/TaskEventModel.d.cts +1 -1
  180. package/lib/types/tasks/models/TaskEventModel.d.mts +1 -1
  181. package/lib/types/tasks/models/TaskModel.d.cts +6 -6
  182. package/lib/types/tasks/models/TaskModel.d.mts +6 -6
  183. package/lib/types/tasks/models/TaskStepResultModel.d.cts +2 -2
  184. package/lib/types/tasks/models/TaskStepResultModel.d.mts +2 -2
  185. package/lib/types/tasks/models/index.d.cts +8 -8
  186. package/lib/types/tasks/models/index.d.mts +8 -8
  187. package/lib/types/tasks/types.d.cts +10 -10
  188. package/lib/types/tasks/types.d.mts +10 -10
  189. package/lib/types/tasks/utils.d.cts +2 -2
  190. package/lib/types/tasks/utils.d.mts +2 -2
  191. package/lib/types/utils/ContextualLoggedClass.d.cts +4 -4
  192. package/lib/types/utils/ContextualLoggedClass.d.mts +4 -4
  193. package/lib/types/utils/decorators.d.cts +1 -1
  194. package/lib/types/utils/decorators.d.mts +1 -1
  195. package/lib/types/utils/index.d.cts +6 -6
  196. package/lib/types/utils/index.d.mts +6 -6
  197. package/lib/types/workers/TaskEngine.d.cts +6 -6
  198. package/lib/types/workers/TaskEngine.d.mts +6 -6
  199. package/lib/types/workers/WorkThreadEnvironment.d.cts +1 -1
  200. package/lib/types/workers/WorkThreadEnvironment.d.mts +1 -1
  201. package/lib/types/workers/index.d.cts +4 -4
  202. package/lib/types/workers/index.d.mts +4 -4
  203. package/lib/types/workers/messages.d.cts +1 -1
  204. package/lib/types/workers/messages.d.mts +1 -1
  205. package/lib/types/workers/types.d.cts +3 -3
  206. package/lib/types/workers/types.d.mts +3 -3
  207. package/package.json +1 -1
  208. package/lib/types/auth/constants.d.ts +0 -5
  209. package/lib/types/auth/decorators.d.ts +0 -5
  210. package/lib/types/auth/index.d.ts +0 -2
  211. package/lib/types/fs/FilesystemAdapter.d.ts +0 -70
  212. package/lib/types/fs/FsDispatch.d.ts +0 -7
  213. package/lib/types/fs/helpers.d.ts +0 -17
  214. package/lib/types/fs/index.d.ts +0 -4
  215. package/lib/types/fs/indexStore.d.ts +0 -28
  216. package/lib/types/fs/locks/FilesystemLock.d.ts +0 -13
  217. package/lib/types/fs/locks/FilesystemMultiLock.d.ts +0 -8
  218. package/lib/types/fs/types.d.ts +0 -40
  219. package/lib/types/identity/decorators.d.ts +0 -72
  220. package/lib/types/identity/index.d.ts +0 -6
  221. package/lib/types/index.d.ts +0 -34
  222. package/lib/types/interfaces/ContextuallyLogged.d.ts +0 -8
  223. package/lib/types/interfaces/ErrorParser.d.ts +0 -16
  224. package/lib/types/interfaces/Executor.d.ts +0 -16
  225. package/lib/types/interfaces/Observable.d.ts +0 -33
  226. package/lib/types/interfaces/Observer.d.ts +0 -15
  227. package/lib/types/interfaces/Paginatable.d.ts +0 -20
  228. package/lib/types/interfaces/Queriable.d.ts +0 -47
  229. package/lib/types/interfaces/RawExecutor.d.ts +0 -28
  230. package/lib/types/interfaces/SequenceOptions.d.ts +0 -79
  231. package/lib/types/interfaces/index.d.ts +0 -12
  232. package/lib/types/migrations/Migration.d.ts +0 -19
  233. package/lib/types/migrations/MigrationService.d.ts +0 -63
  234. package/lib/types/migrations/MigrationTaskBuilder.d.ts +0 -10
  235. package/lib/types/migrations/MigrationTasks.d.ts +0 -9
  236. package/lib/types/migrations/MigrationVersioning.d.ts +0 -7
  237. package/lib/types/migrations/SemverMigrationVersioning.d.ts +0 -10
  238. package/lib/types/migrations/StandardMigrationVersioning.d.ts +0 -12
  239. package/lib/types/migrations/constants.d.ts +0 -2
  240. package/lib/types/migrations/decorators.d.ts +0 -12
  241. package/lib/types/migrations/index.d.ts +0 -15
  242. package/lib/types/migrations/types.d.ts +0 -46
  243. package/lib/types/model/BaseModel.d.ts +0 -37
  244. package/lib/types/model/SequenceModel.d.ts +0 -32
  245. package/lib/types/model/construction.d.ts +0 -455
  246. package/lib/types/model/decorators.d.ts +0 -237
  247. package/lib/types/model/index.d.ts +0 -11
  248. package/lib/types/model/indexing.d.ts +0 -20
  249. package/lib/types/model/types.d.ts +0 -60
  250. package/lib/types/overrides/Metadata.d.ts +0 -22
  251. package/lib/types/overrides/Model.d.ts +0 -94
  252. package/lib/types/overrides/ModelBuilder.d.ts +0 -31
  253. package/lib/types/overrides/index.d.ts +0 -11
  254. package/lib/types/overrides/injectables.d.ts +0 -10
  255. package/lib/types/overrides/overrides.d.ts +0 -1
  256. package/lib/types/persistence/Adapter.d.ts +0 -469
  257. package/lib/types/persistence/Context.d.ts +0 -16
  258. package/lib/types/persistence/ContextLock.d.ts +0 -18
  259. package/lib/types/persistence/Dispatch.d.ts +0 -128
  260. package/lib/types/persistence/ObserverHandler.d.ts +0 -111
  261. package/lib/types/persistence/Sequence.d.ts +0 -126
  262. package/lib/types/persistence/constants.d.ts +0 -74
  263. package/lib/types/persistence/decorators.d.ts +0 -28
  264. package/lib/types/persistence/errors.d.ts +0 -33
  265. package/lib/types/persistence/event-filters.d.ts +0 -20
  266. package/lib/types/persistence/generators.d.ts +0 -14
  267. package/lib/types/persistence/index.d.ts +0 -18
  268. package/lib/types/persistence/transactions.d.ts +0 -4
  269. package/lib/types/persistence/types.d.ts +0 -86
  270. package/lib/types/query/Condition.d.ts +0 -131
  271. package/lib/types/query/MethodQueryBuilder.d.ts +0 -185
  272. package/lib/types/query/Paginator.d.ts +0 -105
  273. package/lib/types/query/Statement.d.ts +0 -136
  274. package/lib/types/query/constants.d.ts +0 -69
  275. package/lib/types/query/decorators.d.ts +0 -8
  276. package/lib/types/query/errors.d.ts +0 -21
  277. package/lib/types/query/index.d.ts +0 -16
  278. package/lib/types/query/options.d.ts +0 -393
  279. package/lib/types/query/selectors.d.ts +0 -39
  280. package/lib/types/query/types.d.ts +0 -158
  281. package/lib/types/query/utils.d.ts +0 -40
  282. package/lib/types/ram/RamAdapter.d.ts +0 -341
  283. package/lib/types/ram/RamPaginator.d.ts +0 -54
  284. package/lib/types/ram/RamStatement.d.ts +0 -92
  285. package/lib/types/ram/constants.d.ts +0 -8
  286. package/lib/types/ram/handlers.d.ts +0 -24
  287. package/lib/types/ram/index.d.ts +0 -12
  288. package/lib/types/ram/types.d.ts +0 -50
  289. package/lib/types/repository/Repository.d.ts +0 -501
  290. package/lib/types/repository/constants.d.ts +0 -36
  291. package/lib/types/repository/decorators.d.ts +0 -30
  292. package/lib/types/repository/errors.d.ts +0 -19
  293. package/lib/types/repository/index.d.ts +0 -12
  294. package/lib/types/repository/injectables.d.ts +0 -95
  295. package/lib/types/repository/types.d.ts +0 -28
  296. package/lib/types/repository/utils.d.ts +0 -36
  297. package/lib/types/services/ModelService.d.ts +0 -45
  298. package/lib/types/services/PersistenceService.d.ts +0 -17
  299. package/lib/types/services/index.d.ts +0 -8
  300. package/lib/types/services/services.d.ts +0 -96
  301. package/lib/types/tasks/CleanUpTask.d.ts +0 -15
  302. package/lib/types/tasks/TaskContext.d.ts +0 -30
  303. package/lib/types/tasks/TaskEngine.d.ts +0 -97
  304. package/lib/types/tasks/TaskErrors.d.ts +0 -65
  305. package/lib/types/tasks/TaskEventBus.d.ts +0 -17
  306. package/lib/types/tasks/TaskEventService.d.ts +0 -7
  307. package/lib/types/tasks/TaskHandler.d.ts +0 -12
  308. package/lib/types/tasks/TaskHandlerRegistry.d.ts +0 -8
  309. package/lib/types/tasks/TaskService.d.ts +0 -65
  310. package/lib/types/tasks/TaskStateChangeError.d.ts +0 -11
  311. package/lib/types/tasks/TaskTracker.d.ts +0 -47
  312. package/lib/types/tasks/builder.d.ts +0 -72
  313. package/lib/types/tasks/constants.d.ts +0 -31
  314. package/lib/types/tasks/decorators.d.ts +0 -4
  315. package/lib/types/tasks/index.d.ts +0 -23
  316. package/lib/types/tasks/logging.d.ts +0 -31
  317. package/lib/types/tasks/models/TaskBackoffModel.d.ts +0 -9
  318. package/lib/types/tasks/models/TaskErrorModel.d.ts +0 -8
  319. package/lib/types/tasks/models/TaskEventModel.d.ts +0 -11
  320. package/lib/types/tasks/models/TaskIOSerializer.d.ts +0 -33
  321. package/lib/types/tasks/models/TaskLogEntryModel.d.ts +0 -10
  322. package/lib/types/tasks/models/TaskModel.d.ts +0 -43
  323. package/lib/types/tasks/models/TaskStepResultModel.d.ts +0 -9
  324. package/lib/types/tasks/models/TaskStepSpecModel.d.ts +0 -9
  325. package/lib/types/tasks/models/index.d.ts +0 -8
  326. package/lib/types/tasks/types.d.ts +0 -71
  327. package/lib/types/tasks/utils.d.ts +0 -5
  328. package/lib/types/utils/ContextualLoggedClass.d.ts +0 -37
  329. package/lib/types/utils/decorators.d.ts +0 -27
  330. package/lib/types/utils/errors.d.ts +0 -56
  331. package/lib/types/utils/index.d.ts +0 -11
  332. package/lib/types/utils/throttling.d.ts +0 -9
  333. package/lib/types/utils/types.d.ts +0 -23
  334. package/lib/types/utils/utils.d.ts +0 -22
  335. package/lib/types/workers/TaskEngine.d.ts +0 -40
  336. package/lib/types/workers/WorkThreadEnvironment.d.ts +0 -35
  337. package/lib/types/workers/index.d.ts +0 -5
  338. package/lib/types/workers/messages.d.ts +0 -69
  339. package/lib/types/workers/types.d.ts +0 -41
  340. package/lib/types/workers/workerThread.d.ts +0 -1
@@ -1,469 +0,0 @@
1
- import { BaseError, BulkCrudOperationKeys, OperationKeys, PrimaryKeyType } from "@decaf-ts/db-decorators";
2
- import { type Observer } from "../interfaces/Observer";
3
- import { Model, ModelConstructor } from "@decaf-ts/decorator-validation";
4
- import { SequenceOptions } from "../interfaces/SequenceOptions";
5
- import { RawPagedExecutor } from "../interfaces/RawExecutor";
6
- import type { Repository } from "../repository/Repository";
7
- import type { Sequence } from "./Sequence";
8
- import { ErrorParser } from "../interfaces";
9
- import { Statement } from "../query/Statement";
10
- import { Impersonatable, Logger } from "@decaf-ts/logging";
11
- import { Lock } from "@decaf-ts/transactional-decorators";
12
- import type { Dispatch } from "./Dispatch";
13
- import { AdapterDispatch, type AdapterFlags, AllOperationKeys, type EventIds, FlagsOf, type ObserverFilter, PersistenceObservable, PersistenceObserver, PreparedModel, RawResult } from "./types";
14
- import { ObserverHandler } from "./ObserverHandler";
15
- import { Context } from "./Context";
16
- import { type Constructor } from "@decaf-ts/decoration";
17
- import { AbsContextual, ContextualArgs, ContextualizedArgs, MaybeContextualArg, MethodOrOperation } from "../utils/ContextualLoggedClass";
18
- import { Paginator } from "../query/Paginator";
19
- import { PreparedStatement } from "../query/types";
20
- import { AdapterTransaction } from "./ContextLock";
21
- export declare function resolveBulkSequenceResult<T>(result: T[] | PromiseSettledResult<T>[], continueOnError: boolean, log: Logger, operation: string): T[];
22
- export type AdapterSubClass<A> = A extends Adapter<any, any, any, any> ? A : never;
23
- /**
24
- * @description Abstract Facade class for persistence adapters
25
- * @summary Provides the foundation for all database adapters in the persistence layer. This class
26
- * implements several interfaces to provide a consistent API for database operations, observer
27
- * pattern support, and error handling. It manages adapter registration, CRUD operations, and
28
- * observer notifications.
29
- * @template CONFIG - The underlying persistence driver config
30
- * @template QUERY - The query object type used by the adapter
31
- * @template FLAGS - The repository flags type
32
- * @template CONTEXT - The context type
33
- * @param {CONFIG} _config - The underlying persistence driver config
34
- * @param {string} flavour - The identifier for this adapter type
35
- * @param {string} [_alias] - Optional alternative name for this adapter
36
- * @class Adapter
37
- * @example
38
- * ```typescript
39
- * // Implementing a concrete adapter
40
- * class PostgresAdapter extends Adapter<pg.PoolConfig, pg.Query, PostgresFlags, PostgresContext> {
41
- * constructor(client: pg.PoolConfig) {
42
- * super(client, 'postgres');
43
- * }
44
- *
45
- * async initialize() {
46
- * // Set up the adapter
47
- * await this.native.connect();
48
- * }
49
- *
50
- * async create(tableName, id, model) {
51
- * // Implementation for creating records
52
- * const columns = Object.keys(model).join(', ');
53
- * const values = Object.values(model);
54
- * const placeholders = values.map((_, i) => `$${i+1}`).join(', ');
55
- *
56
- * const query = `INSERT INTO ${tableName} (${columns}) VALUES (${placeholders}) RETURNING *`;
57
- * const result = await this.native.query(query, values);
58
- * return result.rows[0];
59
- * }
60
- *
61
- * // Other required method implementations...
62
- * }
63
- *
64
- * // Using the adapter
65
- * const pgClient = new pg.Client(connectionString);
66
- * const adapter = new PostgresAdapter(pgClient);
67
- * await adapter.initialize();
68
- *
69
- * // Set as the default adapter
70
- * Adapter.setCurrent('postgres');
71
- *
72
- * // Perform operations
73
- * const user = await adapter.create('users', 1, { name: 'John', email: 'john@example.com' });
74
- * ```
75
- * @mermaid
76
- * classDiagram
77
- * class Adapter {
78
- * +Y native
79
- * +string flavour
80
- * +string alias
81
- * +create(tableName, id, model)
82
- * +read(tableName, id)
83
- * +update(tableName, id, model)
84
- * +delete(tableName, id)
85
- * +observe(observer, filter)
86
- * +unObserve(observer)
87
- * +static current
88
- * +static get(flavour)
89
- * +static setCurrent(flavour)
90
- * }
91
- *
92
- * class RawExecutor {
93
- * +raw(query)
94
- * }
95
- *
96
- * class Observable {
97
- * +observe(observer, filter)
98
- * +unObserve(observer)
99
- * +updateObservers(table, event, id)
100
- * }
101
- *
102
- * class Observer {
103
- * +refresh(table, event, id)
104
- * }
105
- *
106
- * class ErrorParser {
107
- * +parseError(err)
108
- * }
109
- *
110
- * Adapter --|> RawExecutor
111
- * Adapter --|> Observable
112
- * Adapter --|> Observer
113
- * Adapter --|> ErrorParser
114
- */
115
- export declare abstract class Adapter<CONF, CONN, QUERY, CONTEXT extends Context<AdapterFlags> = Context<AdapterFlags>> extends AbsContextual<CONTEXT> implements RawPagedExecutor<QUERY>, PersistenceObservable<CONTEXT>, PersistenceObserver<CONTEXT>, Impersonatable<any, [Partial<CONF>, ...any[]]>, ErrorParser {
116
- private readonly _config;
117
- readonly flavour: string;
118
- private readonly _alias?;
119
- private static _currentFlavour?;
120
- private static _cache;
121
- private static _baseRepository;
122
- private static _baseSequence;
123
- private static _baseDispatch;
124
- protected dispatch?: AdapterDispatch<Adapter<CONF, CONN, QUERY, CONTEXT>>;
125
- protected readonly observerHandler?: ObserverHandler;
126
- protected _client?: CONN;
127
- protected shutdownPromise?: Promise<void>;
128
- /**
129
- * @summary Internal lock for shutdown mechanisms
130
- * @private
131
- */
132
- protected internalLock: Lock;
133
- /**
134
- * @description Gets the native persistence config
135
- * @summary Provides access to the underlying persistence driver config
136
- * @template CONF
137
- * @return {CONF} The native persistence driver config
138
- */
139
- get config(): CONF;
140
- /**
141
- * @description Gets the adapter's alias or flavor name
142
- * @summary Returns the alias if set, otherwise returns the flavor name
143
- * @return {string} The adapter's identifier
144
- */
145
- get alias(): string;
146
- /**
147
- * @description Gets the repository constructor for this adapter
148
- * @summary Returns the constructor for creating repositories that work with this adapter
149
- * @template M - The model type
150
- * @return {Constructor<Repository<any, Adapter<CONF, CONN, QUERY, CONTEXT>>>} The repository constructor
151
- */
152
- repository<R extends Repository<any, Adapter<CONF, CONN, QUERY, CONTEXT>>>(): Constructor<R>;
153
- transactionLock(...args: any[]): AdapterTransaction<this>;
154
- protected shutdownProxies(...args: ContextualArgs<any>): Promise<void>;
155
- protected shutdownProxies(k: string, ...args: ContextualArgs<any>): Promise<void>;
156
- /**
157
- * @description Shuts down the adapter
158
- * @summary Performs any necessary cleanup tasks, such as closing connections
159
- * When overriding this method, ensure to call the base method first
160
- * @return {Promise<void>} A promise that resolves when shutdown is complete
161
- */
162
- shutdown(...args: MaybeContextualArg<CONTEXT>): Promise<void>;
163
- /**
164
- * @description Creates a new adapter instance
165
- * @summary Initializes the adapter with the native driver and registers it in the adapter cache
166
- */
167
- protected constructor(_config: CONF, flavour: string, _alias?: string | undefined);
168
- /**
169
- * @description Creates a new statement builder for a model
170
- * @summary Returns a statement builder that can be used to construct queries for a specific model
171
- * @template M - The model type
172
- * @return {Statement} A statement builder for the model
173
- */
174
- abstract Statement<M extends Model>(overrides?: Partial<AdapterFlags>): Statement<M, Adapter<CONF, CONN, QUERY, CONTEXT>, any>;
175
- abstract Paginator<M extends Model>(query: QUERY | PreparedStatement<M>, size: number, clazz: Constructor<M>): Paginator<M, any, QUERY>;
176
- /**
177
- * @description Creates a new dispatch instance
178
- * @summary Factory method that creates a dispatch instance for this adapter
179
- * @return {Dispatch} A new dispatch instance
180
- */
181
- protected Dispatch(): Dispatch<Adapter<CONF, CONN, QUERY, CONTEXT>>;
182
- /**
183
- * @description Creates a new observer handler
184
- * @summary Factory method that creates an observer handler for this adapter
185
- * @return {ObserverHandler} A new observer handler instance
186
- */
187
- protected ObserverHandler(): ObserverHandler;
188
- /**
189
- * @description Checks if an attribute name is reserved
190
- * @summary Determines if a given attribute name is reserved and cannot be used as a column name
191
- * @param {string} attr - The attribute name to check
192
- * @return {boolean} True if the attribute is reserved, false otherwise
193
- */
194
- protected isReserved(attr: string): boolean;
195
- /**
196
- * @description Parses a database error into a standardized error
197
- * @summary Converts database-specific errors into standardized application errors
198
- * @param {Error} err - The original database error
199
- * @param args
200
- * @return {BaseError} A standardized error
201
- */
202
- abstract parseError<E extends BaseError>(err: Error, ...args: any[]): E;
203
- /**
204
- * @description Initializes the adapter
205
- * @summary Performs any necessary setup for the adapter, such as establishing connections
206
- * @param {...any[]} args - Initialization arguments
207
- * @return {Promise<void>} A promise that resolves when initialization is complete
208
- */
209
- initialize(...args: any[]): Promise<void>;
210
- /**
211
- * @description Creates a sequence generator
212
- * @summary Factory method that creates a sequence generator for generating sequential values
213
- * @param {SequenceOptions} options - Configuration options for the sequence
214
- * @return {Promise<Sequence>} A promise that resolves to a new sequence instance
215
- */
216
- Sequence(options: SequenceOptions, overrides?: Partial<FlagsOf<CONTEXT>>): Promise<Sequence>;
217
- /**
218
- * @description Creates repository flags for an operation
219
- * @summary Generates a set of flags that describe a database operation, combining default flags with overrides
220
- * @template F - The Repository Flags type
221
- * @template M - The model type
222
- * @param {OperationKeys} operation - The type of operation being performed
223
- * @param {Constructor<M>} model - The model constructor
224
- * @param {Partial<F>} flags - Custom flag overrides
225
- * @param {...any[]} args - Additional arguments
226
- * @return {Promise<F>} The complete set of flags
227
- */
228
- protected flags<M extends Model>(operation: OperationKeys | string, model: Constructor<M> | Constructor<M>[] | undefined, flags: Partial<FlagsOf<CONTEXT>>, ...args: MaybeContextualArg<CONTEXT>): Promise<FlagsOf<CONTEXT>>;
229
- /**
230
- * @description The context constructor for this adapter
231
- * @summary Reference to the context class constructor used by this adapter
232
- */
233
- protected get Context(): Constructor<CONTEXT>;
234
- /**
235
- * @description Creates a context for a database operation
236
- * @summary Generates a context object that describes a database operation, used for tracking and auditing
237
- * @template F - The Repository flags type
238
- * @template M - The model type
239
- * @param {OperationKeys.CREATE|OperationKeys.READ|OperationKeys.UPDATE|OperationKeys.DELETE} operation - The type of operation
240
- * @param {Partial<F>} overrides - Custom flag overrides
241
- * @param {Constructor<M>} model - The model constructor
242
- * @param {...any[]} args - Additional arguments
243
- * @return {Promise<C>} A promise that resolves to the context object
244
- */
245
- context<M extends Model>(operation: ((...args: any[]) => any) | AllOperationKeys, overrides: Partial<FlagsOf<CONTEXT>>, model: Constructor<M> | Constructor<M>[], ...args: MaybeContextualArg<Context<any>>): Promise<CONTEXT>;
246
- /**
247
- * @description Prepares a model for persistence
248
- * @summary Converts a model instance into a format suitable for database storage,
249
- * handling column mapping and separating transient properties
250
- * handling column mapping and separating transient properties
251
- * @template M - The model type
252
- * @param {M} model - The model instance to prepare
253
- * @param args - optional args for subclassing purposes
254
- * @return The prepared data
255
- */
256
- prepare<M extends Model>(model: M, ...args: ContextualArgs<CONTEXT>): PreparedModel;
257
- /**
258
- * @description Converts database data back into a model instance
259
- * @summary Reconstructs a model instance from database data, handling column mapping
260
- * and reattaching transient properties
261
- * @template M - The model type
262
- * @param obj - The database record
263
- * @param {Constructor<M>} clazz - The model class or name
264
- * @param pk - The primary key property name
265
- * @param {string|number|bigint} id - The primary key value
266
- * @param [transient] - Transient properties to reattach
267
- * @param [args] - options args for subclassing purposes
268
- * @return {M} The reconstructed model instance
269
- */
270
- revert<M extends Model>(obj: Record<string, any>, clazz: Constructor<M>, id: PrimaryKeyType, transient?: Record<string, any>, ...args: ContextualArgs<CONTEXT>): M;
271
- /**
272
- * @description Creates a new record in the database
273
- * @summary Inserts a new record with the given ID and data into the specified table
274
- * @param {string} clazz - The name of the table to insert into
275
- * @param {PrimaryKeyType} id - The identifier for the new record
276
- * @param model - The data to insert
277
- * @param {any[]} args - Additional arguments specific to the adapter implementation
278
- * @return A promise that resolves to the created record
279
- */
280
- abstract create<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>>;
281
- /**
282
- * @description Creates multiple records in the database
283
- * @summary Inserts multiple records with the given IDs and data into the specified table
284
- * @param {string} tableName - The name of the table to insert into
285
- * @param id - The identifiers for the new records
286
- * @param model - The data to insert for each record
287
- * @param {...any[]} args - Additional arguments specific to the adapter implementation
288
- * @return A promise that resolves to an array of created records
289
- */
290
- createAll<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType[], model: Record<string, any>[], ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>[]>;
291
- /**
292
- * @description Retrieves a record from the database
293
- * @summary Fetches a record with the given ID from the specified table
294
- * @param {string} tableName - The name of the table to read from
295
- * @param {string|number|bigint} id - The identifier of the record to retrieve
296
- * @param {...any[]} args - Additional arguments specific to the adapter implementation
297
- * @return A promise that resolves to the retrieved record
298
- */
299
- abstract read<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>>;
300
- /**
301
- * @description Retrieves multiple records from the database
302
- * @summary Fetches multiple records with the given IDs from the specified table
303
- * @param {string} tableName - The name of the table to read from
304
- * @param id - The identifiers of the records to retrieve
305
- * @param {...any[]} args - Additional arguments specific to the adapter implementation
306
- * @return A promise that resolves to an array of retrieved records
307
- */
308
- readAll<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType[], ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>[]>;
309
- /**
310
- * @description Updates a record in the database
311
- * @summary Modifies an existing record with the given ID in the specified table
312
- * @template M - The model type
313
- * @param {Constructor<M>} tableName - The name of the table to update
314
- * @param {PrimaryKeyType} id - The identifier of the record to update
315
- * @param model - The new data for the record
316
- * @param {...any[]} args - Additional arguments specific to the adapter implementation
317
- * @return A promise that resolves to the updated record
318
- */
319
- abstract update<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>>;
320
- /**
321
- * @description Updates multiple records in the database
322
- * @summary Modifies multiple existing records with the given IDs in the specified table
323
- * @param {Constructor<M>} tableName - The name of the table to update
324
- * @param {string[]|number[]} id - The identifiers of the records to update
325
- * @param model - The new data for each record
326
- * @param {...any[]} args - Additional arguments specific to the adapter implementation
327
- * @return A promise that resolves to an array of updated records
328
- */
329
- updateAll<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType[], model: Record<string, any>[], ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>[]>;
330
- /**
331
- * @description Deletes a record from the database
332
- * @summary Removes a record with the given ID from the specified table
333
- * @param {string} tableName - The name of the table to delete from
334
- * @param {string|number|bigint} id - The identifier of the record to delete
335
- * @param {...any[]} args - Additional arguments specific to the adapter implementation
336
- * @return A promise that resolves to the deleted record
337
- */
338
- abstract delete<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>>;
339
- /**
340
- * @description Deletes multiple records from the database
341
- * @summary Removes multiple records with the given IDs from the specified table
342
- * @param {string} tableName - The name of the table to delete from
343
- * @param id - The identifiers of the records to delete
344
- * @param {...any[]} args - Additional arguments specific to the adapter implementation
345
- * @return A promise that resolves to an array of deleted records
346
- */
347
- deleteAll<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType[], ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>[]>;
348
- /**
349
- * @description Executes a raw query against the database
350
- * @summary Allows executing database-specific queries directly
351
- * @template Q - The raw query type
352
- * @template R - The return type of the query
353
- * @param {Q} rawInput - The query to execute
354
- * @param {...any[]} args - Additional arguments specific to the adapter implementation
355
- * @return {Promise<R>} A promise that resolves to the query result
356
- */
357
- abstract raw<R, D extends boolean>(rawInput: QUERY, docsOnly: D, ...args: ContextualArgs<CONTEXT>): Promise<RawResult<R, D>>;
358
- /**
359
- * @description Registers an observer for database events
360
- * @summary Adds an observer to be notified about database changes. The observer can optionally
361
- * provide a filter function to receive only specific events.
362
- * @param {Observer} observer - The observer to register
363
- * @param {ObserverFilter} [filter] - Optional filter function to determine which events the observer receives
364
- * @return {void}
365
- */
366
- observe(observer: Observer, filter?: ObserverFilter): () => void;
367
- /**
368
- * @description Unregisters an observer
369
- * @summary Removes a previously registered observer so it no longer receives database event notifications
370
- * @param {Observer} observer - The observer to unregister
371
- * @return {void}
372
- */
373
- unObserve(observer: Observer): void;
374
- /**
375
- * @description Notifies all observers about a database event
376
- * @summary Sends notifications to all registered observers about a change in the database,
377
- * filtering based on each observer's filter function
378
- * @param {string} table - The name of the table where the change occurred
379
- * @param {OperationKeys|BulkCrudOperationKeys|string} event - The type of operation that occurred
380
- * @param {EventIds} id - The identifier(s) of the affected record(s)
381
- * @param {...any[]} args - Additional arguments to pass to the observers
382
- * @return {Promise<void>} A promise that resolves when all observers have been notified
383
- */
384
- updateObservers<M extends Model>(table: Constructor<M> | string, event: OperationKeys | BulkCrudOperationKeys | string, id: EventIds, ...args: ContextualArgs<CONTEXT>): Promise<void>;
385
- /**
386
- * @description Refreshes data based on a database event
387
- * @summary Implementation of the Observer interface method that delegates to updateObservers
388
- * @param {string} table - The name of the table where the change occurred
389
- * @param {OperationKeys|BulkCrudOperationKeys|string} event - The type of operation that occurred
390
- * @param {EventIds} id - The identifier(s) of the affected record(s)
391
- * @param {...any[]} args - Additional arguments related to the event
392
- * @return {Promise<void>} A promise that resolves when the refresh is complete
393
- */
394
- refresh<M extends Model>(table: Constructor<M> | string, event: OperationKeys | BulkCrudOperationKeys | string, id: EventIds, ...args: ContextualArgs<CONTEXT>): Promise<void>;
395
- /**
396
- * @description Gets a string representation of the adapter
397
- * @summary Returns a human-readable string identifying this adapter
398
- * @return {string} A string representation of the adapter
399
- */
400
- toString(): string;
401
- /**
402
- * @description Gets the adapter flavor associated with a model
403
- * @summary Retrieves the adapter flavor that should be used for a specific model class
404
- * @template M - The model type
405
- * @param {Constructor<M>} model - The model constructor
406
- * @return {string} The adapter flavor name
407
- */
408
- static flavourOf<M extends Model>(model: Constructor<M>): string;
409
- static get currentFlavour(): string;
410
- /**
411
- * @description Gets the current default adapter
412
- * @summary Retrieves the adapter that is currently set as the default for operations
413
- * @return {Adapter<any, any, any, any>} The current adapter
414
- */
415
- static get current(): Adapter<any, any, any, any> | undefined;
416
- /**
417
- * @description Unregisters an adapter by alias
418
- * @summary Removes the adapter instance associated with the given alias from the cache
419
- * @param {string} alias - The alias that was used to register the adapter
420
- */
421
- static unregister(alias?: string): void;
422
- /**
423
- * @description Gets an adapter by flavor
424
- * @summary Retrieves a registered adapter by its flavor name
425
- * @template CONF - The database driver config
426
- * @template CONN - The database driver instance
427
- * @template QUERY - The query type
428
- * @template CONTEXT - The context type
429
- * @param {string} flavour - The flavor name of the adapter to retrieve
430
- * @return {Adapter<CONF, CONN, QUERY, CONTEXT> | undefined} The adapter instance or undefined if not found
431
- */
432
- static get<A extends Adapter<any, any, any, any>>(flavour?: any): A | undefined;
433
- /**
434
- * @description Sets the current default adapter
435
- * @summary Changes which adapter is used as the default for operations
436
- * @param {string} flavour - The flavor name of the adapter to set as current
437
- * @return {void}
438
- */
439
- static setCurrent(flavour: string): void;
440
- /**
441
- * @description Gets all models associated with an adapter flavor
442
- * @summary Retrieves all model constructors that are configured to use a specific adapter flavor
443
- * @template M - The model type
444
- * @param {string} flavour - The adapter flavor to find models for
445
- * @return An array of model constructors
446
- */
447
- static models<M extends Model>(flavour: string): ModelConstructor<M>[];
448
- static decoration(): void;
449
- protected proxies?: Record<string, typeof this>;
450
- /**
451
- * @description Returns the client instance for the adapter
452
- * @summary This method should be overridden by subclasses to return the client instance for the adapter.
453
- * @template CON - The type of the client instance
454
- * @return {CON} The client instance for the adapter
455
- * @abstract
456
- * @function getClient
457
- * @memberOf module:core
458
- * @instance
459
- * @protected
460
- */
461
- protected abstract getClient(): CONN;
462
- get client(): CONN;
463
- for(config: Partial<CONF>, ...args: any[]): this;
464
- migrations(): Constructor<import("..").Migration<any, this>>[];
465
- protected getQueryRunner(): Promise<CONN>;
466
- protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<CONTEXT, ARGS>, operation: METHOD): ContextualizedArgs<CONTEXT, ARGS, METHOD extends string ? true : false>;
467
- protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<CONTEXT, ARGS>, operation: METHOD, allowCreate: false): ContextualizedArgs<CONTEXT, ARGS, METHOD extends string ? true : false>;
468
- protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<CONTEXT, ARGS>, operation: METHOD, allowCreate: true, overrides?: Partial<FlagsOf<CONTEXT>>): Promise<ContextualizedArgs<CONTEXT, ARGS, METHOD extends string ? true : false>>;
469
- }
@@ -1,16 +0,0 @@
1
- import { Context as Ctx, type ContextFactory, type FlagsOfContext, OperationKeys } from "@decaf-ts/db-decorators";
2
- import type { Constructor } from "@decaf-ts/decoration";
3
- import type { Model } from "@decaf-ts/decorator-validation";
4
- import { AdapterFlags, ContextFlags } from "./types";
5
- export declare class Context<F extends ContextFlags<any> = AdapterFlags<any>> extends Ctx<F> {
6
- constructor(ctx?: Context<any>);
7
- static factory: ContextFactory<any>;
8
- static from<M extends Model, C extends Ctx<any>>(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE | string, overrides: Partial<FlagsOfContext<C>>, model: Constructor<M>, ...args: any[]): Promise<C>;
9
- pushPending(key: string, id: string): void;
10
- getFromChildren<K extends keyof F>(key: K, visited?: Set<Context<any>>): F[K] | undefined;
11
- pending(): Record<string, string[]> | undefined;
12
- getOrUndefined<K extends keyof F>(key: K): F[K] | undefined;
13
- override(conf: Partial<F>): this;
14
- toOverrides(): Record<string, any>;
15
- accumulate<V extends object>(value: V): Context<F & V>;
16
- }
@@ -1,18 +0,0 @@
1
- import { Lock } from "@decaf-ts/transactional-decorators";
2
- import { type Adapter } from "./Adapter";
3
- export declare class AdapterTransaction<A extends Adapter<any, any, any, any>> {
4
- protected adapter: A;
5
- constructor(adapter: A, ...args: any[]);
6
- begin(...args: any[]): Promise<void>;
7
- commit(...args: any[]): Promise<void>;
8
- rollback(...args: any[]): Promise<void>;
9
- }
10
- export declare class ContextLock extends Lock {
11
- protected adapterTransaction: AdapterTransaction<any>;
12
- private acquireCount;
13
- protected readonly lock: Lock;
14
- constructor(adapterTransaction: AdapterTransaction<any>);
15
- acquire(...args: any[]): Promise<void>;
16
- release(...args: any[]): Promise<void>;
17
- rollback(e: Error, ...args: any[]): Promise<void>;
18
- }
@@ -1,128 +0,0 @@
1
- import { BulkCrudOperationKeys, OperationKeys } from "@decaf-ts/db-decorators";
2
- import { ModelConstructor } from "@decaf-ts/decorator-validation";
3
- import { Observer } from "../interfaces";
4
- import { Adapter } from "./Adapter";
5
- import { AdapterDispatch, ContextOf, EventIds } from "./types";
6
- import { Constructor } from "@decaf-ts/decoration";
7
- import { ContextualArgs, ContextualizedArgs, ContextualLoggedClass, MaybeContextualArg, MethodOrOperation } from "../utils/ContextualLoggedClass";
8
- /**
9
- * @description Dispatches database operation events to observers
10
- * @summary The Dispatch class implements the Observable interface and is responsible for intercepting
11
- * database operations from an Adapter and notifying observers when changes occur. It uses proxies to
12
- * wrap the adapter's CRUD methods and automatically trigger observer updates after operations complete.
13
- * @template Y - The native database driver type
14
- * @param {void} - No constructor parameters
15
- * @class Dispatch
16
- * @example
17
- * ```typescript
18
- * // Creating and using a Dispatch instance
19
- * const dispatch = new Dispatch<PostgresDriver>();
20
- *
21
- * // Connect it to an adapter
22
- * const adapter = new PostgresAdapter(connection);
23
- * dispatch.observe(adapter);
24
- *
25
- * // Now any CRUD operations on the adapter will automatically
26
- * // trigger observer notifications
27
- * await adapter.create('users', 123, userModel);
28
- * // Observers will be notified about the creation
29
- *
30
- * // When done, you can disconnect
31
- * dispatch.unObserve(adapter);
32
- * ```
33
- */
34
- export declare class Dispatch<A extends Adapter<any, any, any, any>> extends ContextualLoggedClass<ContextOf<A>> implements AdapterDispatch<A> {
35
- private isSameObservedAdapter;
36
- /**
37
- * Indicates whether the dispatcher has already been initialized.
38
- *
39
- * @description Tracks the initialization state to prevent duplicate setup
40
- * @summary Whether the dispatcher is initialized and ready to observe adapter operations
41
- */
42
- protected initialized: boolean;
43
- /**
44
- * @description The adapter being observed
45
- * @summary Reference to the database adapter whose operations are being monitored
46
- */
47
- protected adapter?: A;
48
- /**
49
- * @description List of model constructors
50
- * @summary Array of model constructors that are registered with the adapter
51
- */
52
- protected models: ModelConstructor<any>[];
53
- /**
54
- * @description Creates a new Dispatch instance
55
- * @summary Initializes a new Dispatch instance without any adapter
56
- */
57
- constructor();
58
- protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<ContextOf<A>, ARGS>, operation: METHOD): ContextualizedArgs<ContextOf<A>, ARGS, METHOD extends string ? true : false>;
59
- protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<ContextOf<A>, ARGS>, operation: METHOD, allowCreate: false): ContextualizedArgs<ContextOf<A>, ARGS, METHOD extends string ? true : false>;
60
- protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<ContextOf<A>, ARGS>, operation: METHOD, allowCreate: true): Promise<ContextualizedArgs<ContextOf<A>, ARGS, METHOD extends string ? true : false>>;
61
- /**
62
- * @description Initializes the dispatch by proxying adapter methods
63
- * @summary Sets up proxies on the adapter's CRUD methods to intercept operations and notify observers.
64
- * This method is called automatically when an adapter is observed.
65
- * @return {Promise<void>} A promise that resolves when initialization is complete
66
- * @mermaid
67
- * sequenceDiagram
68
- * participant Dispatch
69
- * participant Adapter
70
- * participant Proxy
71
- *
72
- * Dispatch->>Dispatch: initialize()
73
- * Dispatch->>Dispatch: Check if adapter exists
74
- * alt No adapter
75
- * Dispatch-->>Dispatch: Throw InternalError
76
- * end
77
- *
78
- * loop For each CRUD method
79
- * Dispatch->>Adapter: Check if method exists
80
- * alt Method doesn't exist
81
- * Dispatch-->>Dispatch: Throw InternalError
82
- * end
83
- *
84
- * Dispatch->>Adapter: Get property descriptor
85
- * loop While descriptor not found
86
- * Dispatch->>Adapter: Check prototype chain
87
- * end
88
- *
89
- * alt Descriptor not found or not writable
90
- * Dispatch->>Dispatch: Log error and continue
91
- * else Descriptor found and writable
92
- * Dispatch->>Proxy: Create proxy for method
93
- * Dispatch->>Adapter: Replace method with proxy
94
- * end
95
- * end
96
- */
97
- protected initialize(...args: MaybeContextualArg<ContextOf<A>>): Promise<void>;
98
- /**
99
- * @description Closes the dispatch
100
- * @summary Performs any necessary cleanup when the dispatch is no longer needed
101
- * @return {Promise<void>} A promise that resolves when closing is complete
102
- */
103
- close(...ctxArgs: ContextualArgs<ContextOf<A>>): Promise<void>;
104
- /**
105
- * @description Starts observing an adapter
106
- * @summary Connects this dispatch to an adapter to monitor its operations
107
- * @param {Adapter<any, any, any, any>} observer - The adapter to observe
108
- * @return {void}
109
- */
110
- observe(observer: A): () => void;
111
- /**
112
- * @description Stops observing an adapter
113
- * @summary Disconnects this dispatch from an adapter
114
- * @param {Observer} observer - The adapter to stop observing
115
- * @return {void}
116
- */
117
- unObserve(observer: Observer): void;
118
- /**
119
- * @description Updates observers about a database event
120
- * @summary Notifies observers about a change in the database
121
- * @param {string} table - The name of the table where the change occurred
122
- * @param {OperationKeys|BulkCrudOperationKeys|string} event - The type of operation that occurred
123
- * @param {EventIds} id - The identifier(s) of the affected record(s)
124
- * @return {Promise<void>} A promise that resolves when all observers have been notified
125
- */
126
- updateObservers(model: Constructor<any> | string, event: OperationKeys | BulkCrudOperationKeys | string, id: EventIds, ...args: ContextualArgs<ContextOf<A>>): Promise<void>;
127
- toString(): string;
128
- }