@decaf-ts/core 0.7.1 → 0.7.3

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