@decaf-ts/core 0.7.2 → 0.7.4

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 (246) hide show
  1. package/README.md +6 -1
  2. package/dist/core.cjs +1 -1
  3. package/dist/core.cjs.map +1 -1
  4. package/dist/core.js +1 -1
  5. package/dist/core.js.map +1 -1
  6. package/lib/esm/identity/decorators.d.ts +3 -4
  7. package/lib/esm/identity/decorators.js +5 -11
  8. package/lib/esm/identity/decorators.js.map +1 -1
  9. package/lib/esm/identity/index.d.ts +0 -1
  10. package/lib/esm/identity/index.js +0 -1
  11. package/lib/esm/identity/index.js.map +1 -1
  12. package/lib/esm/index.d.ts +1 -1
  13. package/lib/esm/index.js +1 -1
  14. package/lib/esm/interfaces/ContextuallyLogged.d.ts +8 -0
  15. package/lib/esm/interfaces/ContextuallyLogged.js +2 -0
  16. package/lib/esm/interfaces/ContextuallyLogged.js.map +1 -0
  17. package/lib/esm/interfaces/ErrorParser.d.ts +2 -2
  18. package/lib/esm/interfaces/Executor.d.ts +1 -1
  19. package/lib/esm/interfaces/Observable.d.ts +8 -8
  20. package/lib/esm/interfaces/Observer.d.ts +2 -2
  21. package/lib/esm/interfaces/RawExecutor.d.ts +1 -1
  22. package/lib/esm/model/BaseModel.d.ts +2 -2
  23. package/lib/esm/model/BaseModel.js +2 -2
  24. package/lib/esm/{ram/model/RamSequenceModel.d.ts → model/SequenceModel.d.ts} +3 -3
  25. package/lib/esm/{ram/model/RamSequenceModel.js → model/SequenceModel.js} +12 -11
  26. package/lib/esm/model/SequenceModel.js.map +1 -0
  27. package/lib/esm/model/construction.d.ts +9 -8
  28. package/lib/esm/model/construction.js +2 -2
  29. package/lib/esm/model/construction.js.map +1 -1
  30. package/lib/esm/model/decorators.d.ts +5 -4
  31. package/lib/esm/model/decorators.js +3 -3
  32. package/lib/esm/model/decorators.js.map +1 -1
  33. package/lib/esm/model/index.d.ts +1 -0
  34. package/lib/esm/model/index.js +1 -0
  35. package/lib/esm/model/index.js.map +1 -1
  36. package/lib/esm/overrides/Metadata.d.ts +1 -8
  37. package/lib/esm/overrides/Model.d.ts +75 -0
  38. package/lib/esm/overrides/Model.js +2 -0
  39. package/lib/esm/overrides/Model.js.map +1 -0
  40. package/lib/esm/overrides/index.d.ts +2 -0
  41. package/lib/esm/overrides/index.js +2 -0
  42. package/lib/esm/overrides/index.js.map +1 -1
  43. package/lib/esm/overrides/injectables.d.ts +10 -0
  44. package/lib/esm/overrides/injectables.js +2 -0
  45. package/lib/esm/overrides/injectables.js.map +1 -0
  46. package/lib/esm/overrides/overrides.js +45 -3
  47. package/lib/esm/overrides/overrides.js.map +1 -1
  48. package/lib/esm/persistence/Adapter.d.ts +55 -53
  49. package/lib/esm/persistence/Adapter.js +85 -61
  50. package/lib/esm/persistence/Adapter.js.map +1 -1
  51. package/lib/esm/persistence/Dispatch.d.ts +7 -6
  52. package/lib/esm/persistence/Dispatch.js +25 -18
  53. package/lib/esm/persistence/Dispatch.js.map +1 -1
  54. package/lib/esm/persistence/ObserverHandler.d.ts +7 -6
  55. package/lib/esm/persistence/ObserverHandler.js +5 -4
  56. package/lib/esm/persistence/ObserverHandler.js.map +1 -1
  57. package/lib/esm/persistence/Sequence.d.ts +34 -25
  58. package/lib/esm/persistence/Sequence.js +136 -15
  59. package/lib/esm/persistence/Sequence.js.map +1 -1
  60. package/lib/esm/persistence/constants.d.ts +1 -0
  61. package/lib/esm/persistence/constants.js +1 -0
  62. package/lib/esm/persistence/constants.js.map +1 -1
  63. package/lib/esm/persistence/generators.d.ts +14 -0
  64. package/lib/esm/persistence/generators.js +31 -0
  65. package/lib/esm/persistence/generators.js.map +1 -0
  66. package/lib/esm/persistence/index.d.ts +1 -0
  67. package/lib/esm/persistence/index.js +1 -0
  68. package/lib/esm/persistence/index.js.map +1 -1
  69. package/lib/esm/persistence/migrations.d.ts +8 -8
  70. package/lib/esm/persistence/migrations.js +8 -9
  71. package/lib/esm/persistence/migrations.js.map +1 -1
  72. package/lib/esm/persistence/types.d.ts +38 -20
  73. package/lib/esm/query/Paginator.d.ts +6 -5
  74. package/lib/esm/query/Paginator.js +4 -4
  75. package/lib/esm/query/Paginator.js.map +1 -1
  76. package/lib/esm/query/Statement.d.ts +9 -8
  77. package/lib/esm/query/Statement.js +23 -10
  78. package/lib/esm/query/Statement.js.map +1 -1
  79. package/lib/esm/ram/RamAdapter.d.ts +22 -31
  80. package/lib/esm/ram/RamAdapter.js +36 -34
  81. package/lib/esm/ram/RamAdapter.js.map +1 -1
  82. package/lib/esm/ram/RamPaginator.d.ts +2 -1
  83. package/lib/esm/ram/RamPaginator.js +5 -3
  84. package/lib/esm/ram/RamPaginator.js.map +1 -1
  85. package/lib/esm/ram/RamStatement.d.ts +7 -7
  86. package/lib/esm/ram/RamStatement.js.map +1 -1
  87. package/lib/esm/ram/handlers.d.ts +3 -4
  88. package/lib/esm/ram/handlers.js.map +1 -1
  89. package/lib/esm/ram/index.d.ts +0 -3
  90. package/lib/esm/ram/index.js +0 -3
  91. package/lib/esm/ram/index.js.map +1 -1
  92. package/lib/esm/ram/types.d.ts +4 -12
  93. package/lib/esm/repository/Repository.d.ts +31 -95
  94. package/lib/esm/repository/Repository.js +107 -203
  95. package/lib/esm/repository/Repository.js.map +1 -1
  96. package/lib/esm/repository/decorators.js +4 -3
  97. package/lib/esm/repository/decorators.js.map +1 -1
  98. package/lib/esm/repository/utils.d.ts +1 -1
  99. package/lib/esm/repository/utils.js +2 -3
  100. package/lib/esm/repository/utils.js.map +1 -1
  101. package/lib/esm/utils/ContextualLoggedClass.d.ts +16 -0
  102. package/lib/esm/utils/ContextualLoggedClass.js +29 -0
  103. package/lib/esm/utils/ContextualLoggedClass.js.map +1 -0
  104. package/lib/esm/utils/Services.d.ts +50 -0
  105. package/lib/esm/utils/Services.js +154 -0
  106. package/lib/esm/utils/Services.js.map +1 -0
  107. package/lib/esm/utils/decorators.d.ts +1 -9
  108. package/lib/esm/utils/decorators.js +26 -15
  109. package/lib/esm/utils/decorators.js.map +1 -1
  110. package/lib/esm/utils/index.d.ts +2 -1
  111. package/lib/esm/utils/index.js +2 -1
  112. package/lib/esm/utils/index.js.map +1 -1
  113. package/lib/identity/decorators.cjs +5 -11
  114. package/lib/identity/decorators.d.ts +3 -4
  115. package/lib/identity/decorators.js.map +1 -1
  116. package/lib/identity/index.cjs +0 -1
  117. package/lib/identity/index.d.ts +0 -1
  118. package/lib/identity/index.js.map +1 -1
  119. package/lib/index.cjs +1 -1
  120. package/lib/index.d.ts +1 -1
  121. package/lib/interfaces/ContextuallyLogged.cjs +3 -0
  122. package/lib/interfaces/ContextuallyLogged.d.ts +8 -0
  123. package/lib/interfaces/ContextuallyLogged.js.map +1 -0
  124. package/lib/interfaces/ErrorParser.d.ts +2 -2
  125. package/lib/interfaces/Executor.d.ts +1 -1
  126. package/lib/interfaces/Observable.d.ts +8 -8
  127. package/lib/interfaces/Observer.d.ts +2 -2
  128. package/lib/interfaces/RawExecutor.d.ts +1 -1
  129. package/lib/model/BaseModel.cjs +2 -2
  130. package/lib/model/BaseModel.d.ts +2 -2
  131. package/lib/{ram/model/RamSequenceModel.cjs → model/SequenceModel.cjs} +14 -13
  132. package/lib/{ram/model/RamSequenceModel.d.ts → model/SequenceModel.d.ts} +3 -3
  133. package/lib/model/SequenceModel.js.map +1 -0
  134. package/lib/model/construction.cjs +2 -2
  135. package/lib/model/construction.d.ts +9 -8
  136. package/lib/model/construction.js.map +1 -1
  137. package/lib/model/decorators.cjs +3 -3
  138. package/lib/model/decorators.d.ts +5 -4
  139. package/lib/model/decorators.js.map +1 -1
  140. package/lib/model/index.cjs +1 -0
  141. package/lib/model/index.d.ts +1 -0
  142. package/lib/model/index.js.map +1 -1
  143. package/lib/overrides/Metadata.d.ts +1 -8
  144. package/lib/overrides/Model.cjs +4 -0
  145. package/lib/overrides/Model.d.ts +75 -0
  146. package/lib/overrides/Model.js.map +1 -0
  147. package/lib/overrides/index.cjs +2 -0
  148. package/lib/overrides/index.d.ts +2 -0
  149. package/lib/overrides/index.js.map +1 -1
  150. package/lib/overrides/injectables.cjs +4 -0
  151. package/lib/overrides/injectables.d.ts +10 -0
  152. package/lib/overrides/injectables.js.map +1 -0
  153. package/lib/overrides/overrides.cjs +43 -1
  154. package/lib/overrides/overrides.js.map +1 -1
  155. package/lib/persistence/Adapter.cjs +90 -66
  156. package/lib/persistence/Adapter.d.ts +55 -53
  157. package/lib/persistence/Adapter.js.map +1 -1
  158. package/lib/persistence/Dispatch.cjs +25 -18
  159. package/lib/persistence/Dispatch.d.ts +7 -6
  160. package/lib/persistence/Dispatch.js.map +1 -1
  161. package/lib/persistence/ObserverHandler.cjs +5 -4
  162. package/lib/persistence/ObserverHandler.d.ts +7 -6
  163. package/lib/persistence/ObserverHandler.js.map +1 -1
  164. package/lib/persistence/Sequence.cjs +136 -15
  165. package/lib/persistence/Sequence.d.ts +34 -25
  166. package/lib/persistence/Sequence.js.map +1 -1
  167. package/lib/persistence/constants.cjs +1 -0
  168. package/lib/persistence/constants.d.ts +1 -0
  169. package/lib/persistence/constants.js.map +1 -1
  170. package/lib/persistence/generators.cjs +36 -0
  171. package/lib/persistence/generators.d.ts +14 -0
  172. package/lib/persistence/generators.js.map +1 -0
  173. package/lib/persistence/index.cjs +1 -0
  174. package/lib/persistence/index.d.ts +1 -0
  175. package/lib/persistence/index.js.map +1 -1
  176. package/lib/persistence/migrations.cjs +7 -8
  177. package/lib/persistence/migrations.d.ts +8 -8
  178. package/lib/persistence/migrations.js.map +1 -1
  179. package/lib/persistence/types.d.ts +38 -20
  180. package/lib/query/Paginator.cjs +4 -4
  181. package/lib/query/Paginator.d.ts +6 -5
  182. package/lib/query/Paginator.js.map +1 -1
  183. package/lib/query/Statement.cjs +34 -21
  184. package/lib/query/Statement.d.ts +9 -8
  185. package/lib/query/Statement.js.map +1 -1
  186. package/lib/ram/RamAdapter.cjs +35 -33
  187. package/lib/ram/RamAdapter.d.ts +22 -31
  188. package/lib/ram/RamAdapter.js.map +1 -1
  189. package/lib/ram/RamPaginator.cjs +5 -3
  190. package/lib/ram/RamPaginator.d.ts +2 -1
  191. package/lib/ram/RamPaginator.js.map +1 -1
  192. package/lib/ram/RamStatement.d.ts +7 -7
  193. package/lib/ram/RamStatement.js.map +1 -1
  194. package/lib/ram/handlers.d.ts +3 -4
  195. package/lib/ram/handlers.js.map +1 -1
  196. package/lib/ram/index.cjs +0 -3
  197. package/lib/ram/index.d.ts +0 -3
  198. package/lib/ram/index.js.map +1 -1
  199. package/lib/ram/types.d.ts +4 -12
  200. package/lib/repository/Repository.cjs +108 -204
  201. package/lib/repository/Repository.d.ts +31 -95
  202. package/lib/repository/Repository.js.map +1 -1
  203. package/lib/repository/decorators.cjs +2 -1
  204. package/lib/repository/decorators.js.map +1 -1
  205. package/lib/repository/utils.cjs +2 -3
  206. package/lib/repository/utils.d.ts +1 -1
  207. package/lib/repository/utils.js.map +1 -1
  208. package/lib/utils/ContextualLoggedClass.cjs +33 -0
  209. package/lib/utils/ContextualLoggedClass.d.ts +16 -0
  210. package/lib/utils/ContextualLoggedClass.js.map +1 -0
  211. package/lib/utils/Services.cjs +159 -0
  212. package/lib/utils/Services.d.ts +50 -0
  213. package/lib/utils/Services.js.map +1 -0
  214. package/lib/utils/decorators.cjs +27 -16
  215. package/lib/utils/decorators.d.ts +1 -9
  216. package/lib/utils/decorators.js.map +1 -1
  217. package/lib/utils/index.cjs +2 -1
  218. package/lib/utils/index.d.ts +2 -1
  219. package/lib/utils/index.js.map +1 -1
  220. package/package.json +1 -1
  221. package/lib/esm/identity/utils.d.ts +0 -24
  222. package/lib/esm/identity/utils.js +0 -44
  223. package/lib/esm/identity/utils.js.map +0 -1
  224. package/lib/esm/ram/RamContext.d.ts +0 -28
  225. package/lib/esm/ram/RamContext.js +0 -30
  226. package/lib/esm/ram/RamContext.js.map +0 -1
  227. package/lib/esm/ram/RamSequence.d.ts +0 -75
  228. package/lib/esm/ram/RamSequence.js +0 -145
  229. package/lib/esm/ram/RamSequence.js.map +0 -1
  230. package/lib/esm/ram/model/RamSequenceModel.js.map +0 -1
  231. package/lib/esm/ram/model/index.d.ts +0 -1
  232. package/lib/esm/ram/model/index.js +0 -2
  233. package/lib/esm/ram/model/index.js.map +0 -1
  234. package/lib/identity/utils.cjs +0 -49
  235. package/lib/identity/utils.d.ts +0 -24
  236. package/lib/identity/utils.js.map +0 -1
  237. package/lib/ram/RamContext.cjs +0 -34
  238. package/lib/ram/RamContext.d.ts +0 -28
  239. package/lib/ram/RamContext.js.map +0 -1
  240. package/lib/ram/RamSequence.cjs +0 -149
  241. package/lib/ram/RamSequence.d.ts +0 -75
  242. package/lib/ram/RamSequence.js.map +0 -1
  243. package/lib/ram/model/RamSequenceModel.js.map +0 -1
  244. package/lib/ram/model/index.cjs +0 -18
  245. package/lib/ram/model/index.d.ts +0 -1
  246. package/lib/ram/model/index.js.map +0 -1
@@ -1,19 +1,20 @@
1
- import { BaseError, Context, OperationKeys, RepositoryFlags, Contextual, BulkCrudOperationKeys } from "@decaf-ts/db-decorators";
1
+ import { BaseError, Context, OperationKeys, Contextual, BulkCrudOperationKeys, PrimaryKeyType } from "@decaf-ts/db-decorators";
2
2
  import { type Observer } from "../interfaces/Observer";
3
3
  import { Model, ModelConstructor } from "@decaf-ts/decorator-validation";
4
4
  import { SequenceOptions } from "../interfaces/SequenceOptions";
5
5
  import { RawExecutor } from "../interfaces/RawExecutor";
6
- import { Observable } from "../interfaces/Observable";
7
6
  import type { Repository } from "../repository/Repository";
8
- import { Sequence } from "./Sequence";
7
+ import type { Sequence } from "./Sequence";
9
8
  import { ErrorParser } from "../interfaces";
10
9
  import { Statement } from "../query/Statement";
11
10
  import type { Dispatch } from "./Dispatch";
12
- import { type EventIds, Migration, type ObserverFilter } from "./types";
11
+ import { type EventIds, FlagsOf, Migration, type ObserverFilter, PersistenceObservable, PersistenceObserver, PreparedModel } from "./types";
13
12
  import { ObserverHandler } from "./ObserverHandler";
14
- import { LoggedClass } from "@decaf-ts/logging";
13
+ import { Impersonatable } from "@decaf-ts/logging";
15
14
  import { AdapterDispatch } from "./types";
16
15
  import { type Constructor } from "@decaf-ts/decoration";
16
+ import { ContextualArgs, ContextualizedArgs, ContextualLoggedClass } from "../utils/ContextualLoggedClass";
17
+ export type AdapterSubClass<A> = A extends Adapter<any, any, any, any> ? A : never;
17
18
  /**
18
19
  * @description Abstract Facade class for persistence adapters
19
20
  * @summary Provides the foundation for all database adapters in the persistence layer. This class
@@ -106,15 +107,16 @@ import { type Constructor } from "@decaf-ts/decoration";
106
107
  * Adapter --|> Observer
107
108
  * Adapter --|> ErrorParser
108
109
  */
109
- export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends RepositoryFlags = RepositoryFlags, CONTEXT extends Context<FLAGS> = Context<FLAGS>> extends LoggedClass implements RawExecutor<QUERY>, Contextual<FLAGS, CONTEXT>, Observable, Observer, ErrorParser {
110
+ export declare abstract class Adapter<CONF, CONN, QUERY, CONTEXT extends Context<any> = Context> extends ContextualLoggedClass<CONTEXT> implements RawExecutor<QUERY>, Contextual<CONTEXT>, PersistenceObservable<CONTEXT>, PersistenceObserver<CONTEXT>, Impersonatable<any, [Partial<CONF>, ...any[]]>, ErrorParser {
110
111
  private readonly _config;
111
112
  readonly flavour: string;
112
113
  private readonly _alias?;
113
114
  private static _currentFlavour;
114
115
  private static _cache;
115
116
  private static _baseRepository;
117
+ private static _baseSequence;
116
118
  private static _baseDispatch;
117
- protected dispatch?: AdapterDispatch;
119
+ protected dispatch?: AdapterDispatch<typeof this>;
118
120
  protected readonly observerHandler?: ObserverHandler;
119
121
  protected _client?: CONN;
120
122
  /**
@@ -134,9 +136,9 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
134
136
  * @description Gets the repository constructor for this adapter
135
137
  * @summary Returns the constructor for creating repositories that work with this adapter
136
138
  * @template M - The model type
137
- * @return {Constructor<Repository<M, QUERY, Adapter<CONF, CONN, QUERY, FLAGS, CONTEXT>, FLAGS, CONTEXT>>} The repository constructor
139
+ * @return {Constructor<Repository<any, Adapter<CONF, CONN, QUERY, CONTEXT>>>} The repository constructor
138
140
  */
139
- repository<M extends Model<boolean>>(): Constructor<Repository<M, QUERY, Adapter<CONF, CONN, QUERY, FLAGS, CONTEXT>, FLAGS, CONTEXT>>;
141
+ repository<R extends Repository<any, Adapter<CONF, CONN, QUERY, CONTEXT>>>(): Constructor<R>;
140
142
  protected shutdownProxies(k?: string): Promise<void>;
141
143
  /**
142
144
  * @description Shuts down the adapter
@@ -156,13 +158,13 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
156
158
  * @template M - The model type
157
159
  * @return {Statement} A statement builder for the model
158
160
  */
159
- abstract Statement<M extends Model>(): Statement<QUERY, M, any>;
161
+ abstract Statement<M extends Model>(): Statement<M, Adapter<CONF, CONN, QUERY, CONTEXT>, any>;
160
162
  /**
161
163
  * @description Creates a new dispatch instance
162
164
  * @summary Factory method that creates a dispatch instance for this adapter
163
165
  * @return {Dispatch} A new dispatch instance
164
166
  */
165
- protected Dispatch(): Dispatch;
167
+ protected Dispatch(): Dispatch<Adapter<CONF, CONN, QUERY, CONTEXT>>;
166
168
  /**
167
169
  * @description Creates a new observer handler
168
170
  * @summary Factory method that creates an observer handler for this adapter
@@ -180,9 +182,10 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
180
182
  * @description Parses a database error into a standardized error
181
183
  * @summary Converts database-specific errors into standardized application errors
182
184
  * @param {Error} err - The original database error
185
+ * @param args
183
186
  * @return {BaseError} A standardized error
184
187
  */
185
- abstract parseError(err: Error): BaseError;
188
+ abstract parseError<E extends BaseError>(err: Error, ...args: any[]): E;
186
189
  /**
187
190
  * @description Initializes the adapter
188
191
  * @summary Performs any necessary setup for the adapter, such as establishing connections
@@ -196,7 +199,7 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
196
199
  * @param {SequenceOptions} options - Configuration options for the sequence
197
200
  * @return {Promise<Sequence>} A promise that resolves to a new sequence instance
198
201
  */
199
- abstract Sequence(options: SequenceOptions): Promise<Sequence>;
202
+ Sequence(options: SequenceOptions): Promise<Sequence>;
200
203
  /**
201
204
  * @description Creates repository flags for an operation
202
205
  * @summary Generates a set of flags that describe a database operation, combining default flags with overrides
@@ -208,18 +211,12 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
208
211
  * @param {...any[]} args - Additional arguments
209
212
  * @return {Promise<F>} The complete set of flags
210
213
  */
211
- protected flags<M extends Model>(operation: OperationKeys, model: Constructor<M>, flags: Partial<FLAGS>, ...args: any[]): Promise<FLAGS>;
214
+ protected flags<M extends Model>(operation: OperationKeys | string, model: Constructor<M> | Constructor<M>[], flags: Partial<FlagsOf<CONTEXT>>, ...args: any[]): Promise<FlagsOf<CONTEXT>>;
212
215
  /**
213
216
  * @description The context constructor for this adapter
214
217
  * @summary Reference to the context class constructor used by this adapter
215
218
  */
216
- protected Context: {
217
- new (): Context<FLAGS>;
218
- factory: import("@decaf-ts/db-decorators").ContextFactory<any>;
219
- childFrom<F extends RepositoryFlags, C extends Context<F>>(context: C, overrides?: Partial<F>): C;
220
- from<M extends Model, F extends RepositoryFlags, C extends Context<F>>(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE, overrides: Partial<F>, model: Constructor<M>, ...args: any[]): Promise<C>;
221
- args<M extends Model<any>, C extends Context<F>, F extends RepositoryFlags>(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE, model: Constructor<M>, args: any[], contextual?: Contextual<F>, overrides?: Partial<F>): Promise<import("@decaf-ts/db-decorators").ContextArgs<F, C>>;
222
- };
219
+ protected readonly Context: Constructor<CONTEXT>;
223
220
  /**
224
221
  * @description Creates a context for a database operation
225
222
  * @summary Generates a context object that describes a database operation, used for tracking and auditing
@@ -231,46 +228,42 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
231
228
  * @param {...any[]} args - Additional arguments
232
229
  * @return {Promise<C>} A promise that resolves to the context object
233
230
  */
234
- context<M extends Model>(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE, overrides: Partial<FLAGS>, model: Constructor<M>, ...args: any[]): Promise<CONTEXT>;
231
+ context<M extends Model>(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE | string, overrides: Partial<FlagsOf<CONTEXT>>, model: Constructor<M> | Constructor<M>[], ...args: any[]): Promise<CONTEXT>;
235
232
  /**
236
233
  * @description Prepares a model for persistence
237
234
  * @summary Converts a model instance into a format suitable for database storage,
238
235
  * handling column mapping and separating transient properties
236
+ * handling column mapping and separating transient properties
239
237
  * @template M - The model type
240
238
  * @param {M} model - The model instance to prepare
241
- * @param pk - The primary key property name
242
239
  * @param args - optional args for subclassing purposes
243
240
  * @return The prepared data
244
241
  */
245
- prepare<M extends Model>(model: M, pk: keyof M, ...args: any[]): {
246
- record: Record<string, any>;
247
- id: string;
248
- transient?: Record<string, any>;
249
- };
242
+ prepare<M extends Model>(model: M, ...args: ContextualArgs<CONTEXT>): PreparedModel;
250
243
  /**
251
244
  * @description Converts database data back into a model instance
252
245
  * @summary Reconstructs a model instance from database data, handling column mapping
253
246
  * and reattaching transient properties
254
247
  * @template M - The model type
255
248
  * @param obj - The database record
256
- * @param {string|Constructor<M>} clazz - The model class or name
249
+ * @param {Constructor<M>} clazz - The model class or name
257
250
  * @param pk - The primary key property name
258
251
  * @param {string|number|bigint} id - The primary key value
259
252
  * @param [transient] - Transient properties to reattach
260
253
  * @param [args] - options args for subclassing purposes
261
254
  * @return {M} The reconstructed model instance
262
255
  */
263
- revert<M extends Model>(obj: Record<string, any>, clazz: string | Constructor<M>, pk: keyof M, id: string | number | bigint, transient?: Record<string, any>, ...args: any[]): M;
256
+ revert<M extends Model>(obj: Record<string, any>, clazz: Constructor<M>, id: PrimaryKeyType, transient?: Record<string, any>, ...args: ContextualArgs<CONTEXT>): M;
264
257
  /**
265
258
  * @description Creates a new record in the database
266
259
  * @summary Inserts a new record with the given ID and data into the specified table
267
- * @param {string} tableName - The name of the table to insert into
268
- * @param {string|number} id - The identifier for the new record
260
+ * @param {string} clazz - The name of the table to insert into
261
+ * @param {PrimaryKeyType} id - The identifier for the new record
269
262
  * @param model - The data to insert
270
263
  * @param {any[]} args - Additional arguments specific to the adapter implementation
271
264
  * @return A promise that resolves to the created record
272
265
  */
273
- abstract create(tableName: string, id: string | number, model: Record<string, any>, ...args: any[]): Promise<Record<string, any>>;
266
+ abstract create<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>>;
274
267
  /**
275
268
  * @description Creates multiple records in the database
276
269
  * @summary Inserts multiple records with the given IDs and data into the specified table
@@ -280,7 +273,7 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
280
273
  * @param {...any[]} args - Additional arguments specific to the adapter implementation
281
274
  * @return A promise that resolves to an array of created records
282
275
  */
283
- createAll(tableName: string, id: (string | number)[], model: Record<string, any>[], ...args: any[]): Promise<Record<string, any>[]>;
276
+ createAll<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType[], model: Record<string, any>[], ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>[]>;
284
277
  /**
285
278
  * @description Retrieves a record from the database
286
279
  * @summary Fetches a record with the given ID from the specified table
@@ -289,7 +282,7 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
289
282
  * @param {...any[]} args - Additional arguments specific to the adapter implementation
290
283
  * @return A promise that resolves to the retrieved record
291
284
  */
292
- abstract read(tableName: string, id: string | number | bigint, ...args: any[]): Promise<Record<string, any>>;
285
+ abstract read<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>>;
293
286
  /**
294
287
  * @description Retrieves multiple records from the database
295
288
  * @summary Fetches multiple records with the given IDs from the specified table
@@ -298,27 +291,28 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
298
291
  * @param {...any[]} args - Additional arguments specific to the adapter implementation
299
292
  * @return A promise that resolves to an array of retrieved records
300
293
  */
301
- readAll(tableName: string, id: (string | number | bigint)[], ...args: any[]): Promise<Record<string, any>[]>;
294
+ readAll<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType[], ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>[]>;
302
295
  /**
303
296
  * @description Updates a record in the database
304
297
  * @summary Modifies an existing record with the given ID in the specified table
305
- * @param {string} tableName - The name of the table to update
306
- * @param {string|number} id - The identifier of the record to update
298
+ * @template M - The model type
299
+ * @param {Constructor<M>} tableName - The name of the table to update
300
+ * @param {PrimaryKeyType} id - The identifier of the record to update
307
301
  * @param model - The new data for the record
308
302
  * @param {...any[]} args - Additional arguments specific to the adapter implementation
309
303
  * @return A promise that resolves to the updated record
310
304
  */
311
- abstract update(tableName: string, id: string | number, model: Record<string, any>, ...args: any[]): Promise<Record<string, any>>;
305
+ abstract update<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>>;
312
306
  /**
313
307
  * @description Updates multiple records in the database
314
308
  * @summary Modifies multiple existing records with the given IDs in the specified table
315
- * @param {string} tableName - The name of the table to update
309
+ * @param {Constructor<M>} tableName - The name of the table to update
316
310
  * @param {string[]|number[]} id - The identifiers of the records to update
317
311
  * @param model - The new data for each record
318
312
  * @param {...any[]} args - Additional arguments specific to the adapter implementation
319
313
  * @return A promise that resolves to an array of updated records
320
314
  */
321
- updateAll(tableName: string, id: string[] | number[], model: Record<string, any>[], ...args: any[]): Promise<Record<string, any>[]>;
315
+ updateAll<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType[], model: Record<string, any>[], ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>[]>;
322
316
  /**
323
317
  * @description Deletes a record from the database
324
318
  * @summary Removes a record with the given ID from the specified table
@@ -327,7 +321,7 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
327
321
  * @param {...any[]} args - Additional arguments specific to the adapter implementation
328
322
  * @return A promise that resolves to the deleted record
329
323
  */
330
- abstract delete(tableName: string, id: string | number | bigint, ...args: any[]): Promise<Record<string, any>>;
324
+ abstract delete<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>>;
331
325
  /**
332
326
  * @description Deletes multiple records from the database
333
327
  * @summary Removes multiple records with the given IDs from the specified table
@@ -336,7 +330,7 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
336
330
  * @param {...any[]} args - Additional arguments specific to the adapter implementation
337
331
  * @return A promise that resolves to an array of deleted records
338
332
  */
339
- deleteAll(tableName: string, id: (string | number | bigint)[], ...args: any[]): Promise<Record<string, any>[]>;
333
+ deleteAll<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType[], ...args: ContextualArgs<CONTEXT>): Promise<Record<string, any>[]>;
340
334
  /**
341
335
  * @description Executes a raw query against the database
342
336
  * @summary Allows executing database-specific queries directly
@@ -346,7 +340,7 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
346
340
  * @param {...any[]} args - Additional arguments specific to the adapter implementation
347
341
  * @return {Promise<R>} A promise that resolves to the query result
348
342
  */
349
- abstract raw<R>(rawInput: QUERY, ...args: any[]): Promise<R>;
343
+ abstract raw<R>(rawInput: QUERY, ...args: ContextualArgs<CONTEXT>): Promise<R>;
350
344
  /**
351
345
  * @description Registers an observer for database events
352
346
  * @summary Adds an observer to be notified about database changes. The observer can optionally
@@ -373,7 +367,7 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
373
367
  * @param {...any[]} args - Additional arguments to pass to the observers
374
368
  * @return {Promise<void>} A promise that resolves when all observers have been notified
375
369
  */
376
- updateObservers(table: string, event: OperationKeys | BulkCrudOperationKeys | string, id: EventIds, ...args: any[]): Promise<void>;
370
+ updateObservers<M extends Model>(table: Constructor<M> | string, event: OperationKeys | BulkCrudOperationKeys | string, id: EventIds, ...args: ContextualArgs<CONTEXT>): Promise<void>;
377
371
  /**
378
372
  * @description Refreshes data based on a database event
379
373
  * @summary Implementation of the Observer interface method that delegates to updateObservers
@@ -383,7 +377,7 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
383
377
  * @param {...any[]} args - Additional arguments related to the event
384
378
  * @return {Promise<void>} A promise that resolves when the refresh is complete
385
379
  */
386
- refresh(table: string, event: OperationKeys | BulkCrudOperationKeys | string, id: EventIds, ...args: any[]): Promise<void>;
380
+ refresh<M extends Model>(table: Constructor<M> | string, event: OperationKeys | BulkCrudOperationKeys | string, id: EventIds, ...args: ContextualArgs<CONTEXT>): Promise<void>;
387
381
  /**
388
382
  * @description Gets a string representation of the adapter
389
383
  * @summary Returns a human-readable string identifying this adapter
@@ -411,12 +405,11 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
411
405
  * @template CONF - The database driver config
412
406
  * @template CONN - The database driver instance
413
407
  * @template QUERY - The query type
414
- * @template CCONTEXT - The context type
415
- * @template FLAGS - The repository flags type
408
+ * @template CONTEXT - The context type
416
409
  * @param {string} flavour - The flavor name of the adapter to retrieve
417
- * @return {Adapter<CONF, CONN, QUERY, CONTEXT, FLAGS> | undefined} The adapter instance or undefined if not found
410
+ * @return {Adapter<CONF, CONN, QUERY, CONTEXT> | undefined} The adapter instance or undefined if not found
418
411
  */
419
- static get<CONF, CONN, QUERY, CONTEXT extends Context<FLAGS>, FLAGS extends RepositoryFlags>(flavour?: any): Adapter<CONF, CONN, QUERY, FLAGS, CONTEXT> | undefined;
412
+ static get<A extends Adapter<any, any, any, any>>(flavour?: any): A | undefined;
420
413
  /**
421
414
  * @description Sets the current default adapter
422
415
  * @summary Changes which adapter is used as the default for operations
@@ -433,6 +426,14 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
433
426
  */
434
427
  static models<M extends Model>(flavour: string): ModelConstructor<M>[];
435
428
  static decoration(): void;
429
+ /**
430
+ * @description retrieves the context from args and returns it, the logger and the args (with context at the end)
431
+ * @summary NOTE: if the last argument was a context, this removes the context from the arg list
432
+ * @param args
433
+ * @param method
434
+ */
435
+ static logCtx<CONTEXT extends Context<any>, ARGS extends any[] = any[]>(this: any, args: ARGS, method: string): ContextualizedArgs<CONTEXT, ARGS>;
436
+ static logCtx<CONTEXT extends Context<any>, ARGS extends any[] = any[]>(this: any, args: ARGS, method: (...args: any[]) => any): ContextualizedArgs<CONTEXT, ARGS>;
436
437
  protected proxies?: Record<string, typeof this>;
437
438
  /**
438
439
  * @description Returns the client instance for the adapter
@@ -447,7 +448,8 @@ export declare abstract class Adapter<CONF, CONN, QUERY, FLAGS extends Repositor
447
448
  */
448
449
  protected abstract getClient(): CONN;
449
450
  get client(): CONN;
450
- for(config: Partial<CONF>, ...args: any[]): typeof this;
451
- migrations(): Constructor<Migration<any, this, unknown, unknown, unknown, RepositoryFlags, Context<RepositoryFlags>>>[];
452
- migrate(migrations?: Constructor<Migration<any, any, any, any, any>>[]): Promise<void>;
451
+ for(config: Partial<CONF>, ...args: any[]): this;
452
+ migrations(): Constructor<Migration<any, this>>[];
453
+ protected getQueryRunner(): Promise<CONN>;
454
+ migrate(...args: [...any[], CONTEXT]): Promise<void>;
453
455
  }
@@ -10,12 +10,12 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  import { InternalError, Context, OperationKeys, DefaultRepositoryFlags, } from "@decaf-ts/db-decorators";
11
11
  import { hashObj, Model, } from "@decaf-ts/decorator-validation";
12
12
  import { PersistenceKeys } from "./constants.js";
13
- import { final } from "./../utils/index.js";
13
+ import { final } from "@decaf-ts/logging";
14
14
  import { ObserverHandler } from "./ObserverHandler.js";
15
- import { LoggedClass } from "@decaf-ts/logging";
16
- import { getColumnName, getTableName } from "./../identity/utils.js";
15
+ import { Logging } from "@decaf-ts/logging";
17
16
  import { Decoration, DefaultFlavour, Metadata, } from "@decaf-ts/decoration";
18
17
  import { MigrationError } from "./errors.js";
18
+ import { ContextualLoggedClass, } from "./../utils/ContextualLoggedClass.js";
19
19
  const flavourResolver = Decoration["flavourResolver"].bind(Decoration);
20
20
  Decoration["flavourResolver"] = (obj) => {
21
21
  try {
@@ -135,7 +135,7 @@ Decoration["flavourResolver"] = (obj) => {
135
135
  * Adapter --|> Observer
136
136
  * Adapter --|> ErrorParser
137
137
  */
138
- export class Adapter extends LoggedClass {
138
+ export class Adapter extends ContextualLoggedClass {
139
139
  static { this._cache = {}; }
140
140
  /**
141
141
  * @description Gets the native persistence config
@@ -158,7 +158,7 @@ export class Adapter extends LoggedClass {
158
158
  * @description Gets the repository constructor for this adapter
159
159
  * @summary Returns the constructor for creating repositories that work with this adapter
160
160
  * @template M - The model type
161
- * @return {Constructor<Repository<M, QUERY, Adapter<CONF, CONN, QUERY, FLAGS, CONTEXT>, FLAGS, CONTEXT>>} The repository constructor
161
+ * @return {Constructor<Repository<any, Adapter<CONF, CONN, QUERY, CONTEXT>>>} The repository constructor
162
162
  */
163
163
  repository() {
164
164
  if (!Adapter._baseRepository)
@@ -259,6 +259,15 @@ export class Adapter extends LoggedClass {
259
259
  */
260
260
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
261
261
  async initialize(...args) { }
262
+ /**
263
+ * @description Creates a sequence generator
264
+ * @summary Factory method that creates a sequence generator for generating sequential values
265
+ * @param {SequenceOptions} options - Configuration options for the sequence
266
+ * @return {Promise<Sequence>} A promise that resolves to a new sequence instance
267
+ */
268
+ async Sequence(options) {
269
+ return new Adapter._baseSequence(options, this);
270
+ }
262
271
  /**
263
272
  * @description Creates repository flags for an operation
264
273
  * @summary Generates a set of flags that describe a database operation, combining default flags with overrides
@@ -273,12 +282,18 @@ export class Adapter extends LoggedClass {
273
282
  async flags(operation, model, flags,
274
283
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
275
284
  ...args) {
285
+ let log = (flags.logger || Logging.for(this.toString()));
286
+ if (flags.correlationId)
287
+ log = log.for({ correlationId: flags.correlationId });
276
288
  return Object.assign({}, DefaultRepositoryFlags, flags, {
277
- affectedTables: getTableName(model),
289
+ affectedTables: (Array.isArray(model) ? model : [model]).map(Model.tableName),
278
290
  writeOperation: operation !== OperationKeys.READ,
279
291
  timestamp: new Date(),
280
292
  operation: operation,
281
- ignoredValidationProperties: Metadata.validationExceptions(model, operation),
293
+ ignoredValidationProperties: Array.isArray(model)
294
+ ? []
295
+ : Metadata.validationExceptions(model, operation),
296
+ logger: log,
282
297
  });
283
298
  }
284
299
  /**
@@ -294,7 +309,7 @@ export class Adapter extends LoggedClass {
294
309
  */
295
310
  async context(operation, overrides, model, ...args) {
296
311
  const log = this.log.for(this.context);
297
- log.debug(`Creating new context for ${operation} operation on ${model.name} model with flag overrides: ${JSON.stringify(overrides)}`);
312
+ log.debug(`Creating new context for ${operation} operation on ${Array.isArray(model) ? model.map((m) => m.name) : model.name} model with flag overrides: ${JSON.stringify(overrides)}`);
298
313
  const flags = await this.flags(operation, model, overrides, ...args);
299
314
  return new this.Context().accumulate(flags);
300
315
  }
@@ -302,38 +317,37 @@ export class Adapter extends LoggedClass {
302
317
  * @description Prepares a model for persistence
303
318
  * @summary Converts a model instance into a format suitable for database storage,
304
319
  * handling column mapping and separating transient properties
320
+ * handling column mapping and separating transient properties
305
321
  * @template M - The model type
306
322
  * @param {M} model - The model instance to prepare
307
- * @param pk - The primary key property name
308
323
  * @param args - optional args for subclassing purposes
309
324
  * @return The prepared data
310
325
  */
311
- prepare(model, pk,
312
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
313
- ...args) {
314
- const log = this.log.for(this.prepare);
326
+ prepare(model, ...args) {
327
+ const { log } = this.logCtx(args, this.prepare);
315
328
  const split = model.segregate();
316
329
  const result = Object.entries(split.model).reduce((accum, [key, val]) => {
317
330
  if (typeof val === "undefined")
318
331
  return accum;
319
- const mappedProp = getColumnName(model, key);
332
+ const mappedProp = Model.columnName(model.constructor, key);
320
333
  if (this.isReserved(mappedProp))
321
334
  throw new InternalError(`Property name ${mappedProp} is reserved`);
322
335
  accum[mappedProp] = val;
323
336
  return accum;
324
337
  }, {});
325
338
  if (model[PersistenceKeys.METADATA]) {
339
+ // TODO movo to couchdb
326
340
  log.silly(`Passing along persistence metadata for ${model[PersistenceKeys.METADATA]}`);
327
341
  Object.defineProperty(result, PersistenceKeys.METADATA, {
328
342
  enumerable: false,
329
- writable: false,
343
+ writable: true,
330
344
  configurable: true,
331
345
  value: model[PersistenceKeys.METADATA],
332
346
  });
333
347
  }
334
348
  return {
335
349
  record: result,
336
- id: model[pk],
350
+ id: model[Model.pk(model.constructor)],
337
351
  transient: split.transient,
338
352
  };
339
353
  }
@@ -343,29 +357,29 @@ export class Adapter extends LoggedClass {
343
357
  * and reattaching transient properties
344
358
  * @template M - The model type
345
359
  * @param obj - The database record
346
- * @param {string|Constructor<M>} clazz - The model class or name
360
+ * @param {Constructor<M>} clazz - The model class or name
347
361
  * @param pk - The primary key property name
348
362
  * @param {string|number|bigint} id - The primary key value
349
363
  * @param [transient] - Transient properties to reattach
350
364
  * @param [args] - options args for subclassing purposes
351
365
  * @return {M} The reconstructed model instance
352
366
  */
353
- revert(obj, clazz, pk, id, transient,
354
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
355
- ...args) {
356
- const log = this.log.for(this.revert);
367
+ revert(obj, clazz, id, transient, ...args) {
368
+ const { log, ctx } = this.logCtx(args, this.revert);
357
369
  const ob = {};
370
+ const pk = Model.pk(clazz);
358
371
  ob[pk] = id;
359
- const m = (typeof clazz === "string" ? Model.build(ob, clazz) : new clazz(ob));
372
+ const m = new clazz(ob);
360
373
  log.silly(`Rebuilding model ${m.constructor.name} id ${id}`);
361
- const metadata = obj[PersistenceKeys.METADATA];
374
+ const metadata = obj[PersistenceKeys.METADATA]; // TODO move to couchdb
362
375
  const result = Object.keys(m).reduce((accum, key) => {
363
376
  if (key === pk)
364
377
  return accum;
365
- accum[key] = obj[getColumnName(accum, key)];
378
+ accum[key] =
379
+ obj[Model.columnName(clazz, key)];
366
380
  return accum;
367
381
  }, m);
368
- if (transient) {
382
+ if (ctx.get("rebuildWithTransient") && transient) {
369
383
  log.verbose(`re-adding transient properties: ${Object.keys(transient).join(", ")}`);
370
384
  Object.entries(transient).forEach(([key, val]) => {
371
385
  if (key in result)
@@ -374,11 +388,12 @@ export class Adapter extends LoggedClass {
374
388
  });
375
389
  }
376
390
  if (metadata) {
391
+ // TODO move to couchdb
377
392
  log.silly(`Passing along ${this.flavour} persistence metadata for ${m.constructor.name} id ${id}: ${metadata}`);
378
393
  Object.defineProperty(result, PersistenceKeys.METADATA, {
379
394
  enumerable: false,
380
- configurable: false,
381
- writable: false,
395
+ configurable: true,
396
+ writable: true,
382
397
  value: metadata,
383
398
  });
384
399
  }
@@ -393,13 +408,13 @@ export class Adapter extends LoggedClass {
393
408
  * @param {...any[]} args - Additional arguments specific to the adapter implementation
394
409
  * @return A promise that resolves to an array of created records
395
410
  */
396
- async createAll(tableName, id, model, ...args) {
411
+ async createAll(clazz, id, model, ...args) {
397
412
  if (id.length !== model.length)
398
413
  throw new InternalError("Ids and models must have the same length");
399
- const log = this.log.for(this.createAll);
400
- log.verbose(`Creating ${id.length} entries ${tableName} table`);
401
- log.debug(`pks: ${id}`);
402
- return Promise.all(id.map((i, count) => this.create(tableName, i, model[count], ...args)));
414
+ const { log, ctxArgs } = this.logCtx(args, this.createAll);
415
+ const tableLabel = Model.tableName(clazz);
416
+ log.debug(`Creating ${id.length} entries ${tableLabel} table`);
417
+ return Promise.all(id.map((i, count) => this.create(clazz, i, model[count], ...ctxArgs)));
403
418
  }
404
419
  /**
405
420
  * @description Retrieves multiple records from the database
@@ -409,28 +424,28 @@ export class Adapter extends LoggedClass {
409
424
  * @param {...any[]} args - Additional arguments specific to the adapter implementation
410
425
  * @return A promise that resolves to an array of retrieved records
411
426
  */
412
- async readAll(tableName, id, ...args) {
413
- const log = this.log.for(this.readAll);
414
- log.verbose(`Reading ${id.length} entries ${tableName} table`);
415
- log.debug(`pks: ${id}`);
416
- return Promise.all(id.map((i) => this.read(tableName, i, ...args)));
427
+ async readAll(clazz, id, ...args) {
428
+ const { log, ctxArgs } = this.logCtx(args, this.readAll);
429
+ const tableName = Model.tableName(clazz);
430
+ log.debug(`Reading ${id.length} entries ${tableName} table`);
431
+ return Promise.all(id.map((i) => this.read(clazz, i, ...ctxArgs)));
417
432
  }
418
433
  /**
419
434
  * @description Updates multiple records in the database
420
435
  * @summary Modifies multiple existing records with the given IDs in the specified table
421
- * @param {string} tableName - The name of the table to update
436
+ * @param {Constructor<M>} tableName - The name of the table to update
422
437
  * @param {string[]|number[]} id - The identifiers of the records to update
423
438
  * @param model - The new data for each record
424
439
  * @param {...any[]} args - Additional arguments specific to the adapter implementation
425
440
  * @return A promise that resolves to an array of updated records
426
441
  */
427
- async updateAll(tableName, id, model, ...args) {
442
+ async updateAll(clazz, id, model, ...args) {
428
443
  if (id.length !== model.length)
429
444
  throw new InternalError("Ids and models must have the same length");
430
- const log = this.log.for(this.updateAll);
431
- log.verbose(`Updating ${id.length} entries ${tableName} table`);
432
- log.debug(`pks: ${id}`);
433
- return Promise.all(id.map((i, count) => this.update(tableName, i, model[count], ...args)));
445
+ const { log, ctxArgs } = this.logCtx(args, this.updateAll);
446
+ const tableLabel = Model.tableName(clazz);
447
+ log.debug(`Updating ${id.length} entries ${tableLabel} table`);
448
+ return Promise.all(id.map((i, count) => this.update(clazz, i, model[count], ...ctxArgs)));
434
449
  }
435
450
  /**
436
451
  * @description Deletes multiple records from the database
@@ -441,10 +456,9 @@ export class Adapter extends LoggedClass {
441
456
  * @return A promise that resolves to an array of deleted records
442
457
  */
443
458
  async deleteAll(tableName, id, ...args) {
444
- const log = this.log.for(this.createAll);
445
- log.verbose(`Deleting ${id.length} entries ${tableName} table`);
446
- log.debug(`pks: ${id}`);
447
- return Promise.all(id.map((i) => this.delete(tableName, i, ...args)));
459
+ const { log, ctxArgs } = Adapter.logCtx(args, this.deleteAll);
460
+ log.verbose(`Deleting ${id.length} entries from ${tableName} table`);
461
+ return Promise.all(id.map((i) => this.delete(tableName, i, ...ctxArgs)));
448
462
  }
449
463
  /**
450
464
  * @description Registers an observer for database events
@@ -461,11 +475,10 @@ export class Adapter extends LoggedClass {
461
475
  writable: false,
462
476
  });
463
477
  this.observerHandler.observe(observer, filter);
464
- this.log
465
- .for(this.observe)
466
- .verbose(`Registering new observer ${observer.toString()}`);
478
+ const log = this.log.for(this.observe);
479
+ log.verbose(`Registering new observer ${observer.toString()}`);
467
480
  if (!this.dispatch) {
468
- this.log.for(this.observe).info(`Creating dispatch for ${this.alias}`);
481
+ log.info(`Creating dispatch for ${this.alias}`);
469
482
  this.dispatch = this.Dispatch();
470
483
  this.dispatch.observe(this);
471
484
  }
@@ -497,9 +510,9 @@ export class Adapter extends LoggedClass {
497
510
  async updateObservers(table, event, id, ...args) {
498
511
  if (!this.observerHandler)
499
512
  throw new InternalError("ObserverHandler not initialized. Did you register any observables?");
500
- const log = this.log.for(this.updateObservers);
501
- log.verbose(`Updating ${this.observerHandler.count()} observers for adapter ${this.alias}`);
502
- await this.observerHandler.updateObservers(this.log, table, event, id, ...args);
513
+ const { log, ctxArgs } = Adapter.logCtx(args, this.updateObservers);
514
+ log.verbose(`Updating ${this.observerHandler.count()} observers for adapter ${this.alias}: Event: `);
515
+ await this.observerHandler.updateObservers(table, event, id, ...ctxArgs);
503
516
  }
504
517
  /**
505
518
  * @description Refreshes data based on a database event
@@ -519,7 +532,7 @@ export class Adapter extends LoggedClass {
519
532
  * @return {string} A string representation of the adapter
520
533
  */
521
534
  toString() {
522
- return `${this.flavour} persistence Adapter`;
535
+ return `${this.flavour} adapter`;
523
536
  }
524
537
  /**
525
538
  * @description Gets the adapter flavor associated with a model
@@ -550,10 +563,9 @@ export class Adapter extends LoggedClass {
550
563
  * @template CONF - The database driver config
551
564
  * @template CONN - The database driver instance
552
565
  * @template QUERY - The query type
553
- * @template CCONTEXT - The context type
554
- * @template FLAGS - The repository flags type
566
+ * @template CONTEXT - The context type
555
567
  * @param {string} flavour - The flavor name of the adapter to retrieve
556
- * @return {Adapter<CONF, CONN, QUERY, CONTEXT, FLAGS> | undefined} The adapter instance or undefined if not found
568
+ * @return {Adapter<CONF, CONN, QUERY, CONTEXT> | undefined} The adapter instance or undefined if not found
557
569
  */
558
570
  static get(flavour) {
559
571
  if (!flavour)
@@ -587,6 +599,9 @@ export class Adapter extends LoggedClass {
587
599
  }
588
600
  }
589
601
  static decoration() { }
602
+ static logCtx(args, method) {
603
+ return super.logCtx(args, method);
604
+ }
590
605
  get client() {
591
606
  if (!this._client) {
592
607
  this._client = this.getClient();
@@ -626,12 +641,21 @@ export class Adapter extends LoggedClass {
626
641
  migrations() {
627
642
  return Metadata.migrationsFor(this);
628
643
  }
629
- async migrate(migrations = this.migrations()) {
644
+ async getQueryRunner() {
645
+ return this;
646
+ }
647
+ async migrate(migrations = this.migrations(), ...args) {
648
+ if (migrations instanceof Context) {
649
+ args = [migrations];
650
+ migrations = this.migrations();
651
+ }
652
+ const { ctx } = Adapter.logCtx(args, this.migrate);
653
+ const qr = await this.getQueryRunner();
630
654
  for (const migration of migrations) {
631
655
  try {
632
656
  const m = new migration();
633
- await m.up(this, this, this.log);
634
- await m.down(this, this, this.log);
657
+ await m.up(qr, this, ctx);
658
+ await m.down(qr, this, ctx);
635
659
  }
636
660
  catch (e) {
637
661
  throw new MigrationError(e);