@decaf-ts/db-decorators 0.7.13 → 0.8.0

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 (44) hide show
  1. package/README.md +1 -1
  2. package/dist/db-decorators.cjs +1 -1
  3. package/dist/db-decorators.cjs.map +1 -1
  4. package/dist/db-decorators.js +1 -1
  5. package/dist/db-decorators.js.map +1 -1
  6. package/lib/esm/index.d.ts +1 -1
  7. package/lib/esm/index.js +1 -1
  8. package/lib/esm/repository/Repository.d.ts +303 -48
  9. package/lib/esm/repository/Repository.js +370 -61
  10. package/lib/esm/repository/Repository.js.map +1 -1
  11. package/lib/esm/repository/constants.js +3 -0
  12. package/lib/esm/repository/constants.js.map +1 -1
  13. package/lib/esm/repository/index.d.ts +1 -2
  14. package/lib/esm/repository/index.js +1 -2
  15. package/lib/esm/repository/index.js.map +1 -1
  16. package/lib/esm/repository/types.d.ts +3 -0
  17. package/lib/esm/repository/utils.js +3 -3
  18. package/lib/esm/repository/utils.js.map +1 -1
  19. package/lib/esm/repository/wrappers.d.ts +1 -0
  20. package/lib/esm/repository/wrappers.js +28 -0
  21. package/lib/esm/repository/wrappers.js.map +1 -1
  22. package/lib/index.cjs +1 -1
  23. package/lib/index.d.ts +1 -1
  24. package/lib/repository/Repository.cjs +370 -61
  25. package/lib/repository/Repository.d.ts +303 -48
  26. package/lib/repository/Repository.js.map +1 -1
  27. package/lib/repository/constants.cjs +3 -0
  28. package/lib/repository/constants.js.map +1 -1
  29. package/lib/repository/index.cjs +1 -2
  30. package/lib/repository/index.d.ts +1 -2
  31. package/lib/repository/index.js.map +1 -1
  32. package/lib/repository/types.d.ts +3 -0
  33. package/lib/repository/utils.cjs +2 -2
  34. package/lib/repository/utils.js.map +1 -1
  35. package/lib/repository/wrappers.cjs +29 -0
  36. package/lib/repository/wrappers.d.ts +1 -0
  37. package/lib/repository/wrappers.js.map +1 -1
  38. package/package.json +1 -1
  39. package/lib/esm/repository/BaseRepository.d.ts +0 -352
  40. package/lib/esm/repository/BaseRepository.js +0 -423
  41. package/lib/esm/repository/BaseRepository.js.map +0 -1
  42. package/lib/repository/BaseRepository.cjs +0 -427
  43. package/lib/repository/BaseRepository.d.ts +0 -352
  44. package/lib/repository/BaseRepository.js.map +0 -1
@@ -1,17 +1,19 @@
1
+ import "./../overrides/index.js";
2
+ import { Model } from "@decaf-ts/decorator-validation";
1
3
  import { enforceDBDecorators, reduceErrorsToPrint } from "./utils.js";
2
4
  import { OperationKeys } from "./../operations/constants.js";
3
5
  import { InternalError, ValidationError } from "./errors.js";
4
- import { BaseRepository } from "./BaseRepository.js";
5
- import { Model } from "@decaf-ts/decorator-validation";
6
+ import { wrapMethodWithContext, wrapMethodWithContextForUpdate, } from "./wrappers.js";
6
7
  import { Context } from "./Context.js";
7
8
  /**
8
- * @description Concrete repository implementation with validation support.
9
- * @summary The Repository class extends BaseRepository to provide additional validation
10
- * functionality. It overrides prefix methods to perform model validation before database
11
- * operations and throws ValidationError when validation fails.
9
+ * @description Base repository implementation providing CRUD operations for models.
10
+ * @summary The BaseRepository class serves as a foundation for repository implementations, providing
11
+ * abstract and concrete methods for creating, reading, updating, and deleting model instances.
12
+ * It handles operation lifecycles including prefix and suffix operations, and enforces decorators.
12
13
  * @template M - The model type extending Model
13
14
  * @template F - The repository flags type, defaults to RepositoryFlags
14
15
  * @template C - The context type, defaults to Context<F>
16
+ * @param {Constructor<M>} clazz - The constructor for the model class
15
17
  * @class Repository
16
18
  * @example
17
19
  * class UserModel extends Model {
@@ -19,42 +21,141 @@ import { Context } from "./Context.js";
19
21
  * id: string;
20
22
  *
21
23
  * @required()
22
- * @minLength(3)
23
24
  * name: string;
24
25
  * }
25
26
  *
26
- * class UserRepository extends Repository<UserModel> {
27
+ * class UserRepository extends BaseRepository<UserModel> {
27
28
  * constructor() {
28
29
  * super(UserModel);
29
30
  * }
30
31
  *
31
32
  * async create(model: UserModel): Promise<UserModel> {
32
- * // Implementation with automatic validation
33
+ * // Implementation
33
34
  * return model;
34
35
  * }
35
- * }
36
36
  *
37
- * // Using the repository
38
- * const repo = new UserRepository();
39
- * try {
40
- * const user = await repo.create({ name: 'Jo' }); // Will throw ValidationError
41
- * } catch (error) {
42
- * console.error(error); // ValidationError: name must be at least 3 characters
37
+ * async read(key: string): Promise<UserModel> {
38
+ * // Implementation
39
+ * return new UserModel({ id: key, name: 'User' });
40
+ * }
41
+ *
42
+ * async update(model: UserModel): Promise<UserModel> {
43
+ * // Implementation
44
+ * return model;
45
+ * }
46
+ *
47
+ * async delete(key: string): Promise<UserModel> {
48
+ * // Implementation
49
+ * const model = await this.read(key);
50
+ * return model;
51
+ * }
43
52
  * }
53
+ *
54
+ * @mermaid
55
+ * sequenceDiagram
56
+ * participant C as Client
57
+ * participant R as Repository
58
+ * participant P as Prefix Methods
59
+ * participant D as Database
60
+ * participant S as Suffix Methods
61
+ * participant V as Validators/Decorators
62
+ *
63
+ * Note over C,V: Create Operation
64
+ * C->>R: create(model)
65
+ * R->>P: createPrefix(model)
66
+ * P->>V: enforceDBDecorators(ON)
67
+ * P->>D: Database operation
68
+ * D->>S: createSuffix(model)
69
+ * S->>V: enforceDBDecorators(AFTER)
70
+ * S->>C: Return model
71
+ *
72
+ * Note over C,V: Read Operation
73
+ * C->>R: read(key)
74
+ * R->>P: readPrefix(key)
75
+ * P->>V: enforceDBDecorators(ON)
76
+ * P->>D: Database operation
77
+ * D->>S: readSuffix(model)
78
+ * S->>V: enforceDBDecorators(AFTER)
79
+ * S->>C: Return model
80
+ *
81
+ * Note over C,V: Update Operation
82
+ * C->>R: update(model)
83
+ * R->>P: updatePrefix(model)
84
+ * P->>V: enforceDBDecorators(ON)
85
+ * P->>D: Database operation
86
+ * D->>S: updateSuffix(model)
87
+ * S->>V: enforceDBDecorators(AFTER)
88
+ * S->>C: Return model
89
+ *
90
+ * Note over C,V: Delete Operation
91
+ * C->>R: delete(key)
92
+ * R->>P: deletePrefix(key)
93
+ * P->>V: enforceDBDecorators(ON)
94
+ * P->>D: Database operation
95
+ * D->>S: deleteSuffix(model)
96
+ * S->>V: enforceDBDecorators(AFTER)
97
+ * S->>C: Return model
44
98
  */
45
- export class Repository extends BaseRepository {
99
+ export class Repository {
100
+ /**
101
+ * @description Gets the model class constructor.
102
+ * @summary Retrieves the constructor for the model class associated with this repository.
103
+ * Throws an error if no class definition is found.
104
+ * @return {Constructor<M>} The constructor for the model class
105
+ */
106
+ get class() {
107
+ if (!this._class)
108
+ throw new InternalError(`No class definition found for this repository`);
109
+ return this._class;
110
+ }
111
+ /**
112
+ * @description Gets the primary key property name of the model.
113
+ * @summary Retrieves the name of the property that serves as the primary key for the model.
114
+ * If not already determined, it finds the primary key using the model's decorators.
115
+ * @return The name of the primary key property
116
+ */
117
+ get pk() {
118
+ return Model.pk(this.class);
119
+ }
120
+ /**
121
+ * @description Gets the primary key properties.
122
+ * @summary Retrieves the properties associated with the primary key of the model.
123
+ * If not already determined, it triggers the pk getter to find the primary key properties.
124
+ * @return {any} The properties of the primary key
125
+ */
126
+ get pkProps() {
127
+ return Model.pkProps(this.class);
128
+ }
46
129
  constructor(clazz) {
47
- super(clazz);
130
+ if (clazz)
131
+ this._class = clazz;
132
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
133
+ const self = this;
134
+ [this.create, this.read, this.delete].forEach((m) => {
135
+ const name = m.name;
136
+ wrapMethodWithContext(self, self[name + "Prefix"], m, self[name + "Suffix"]);
137
+ });
138
+ wrapMethodWithContextForUpdate(self, self[this.update.name + "Prefix"], this.update, self[this.update.name + "Suffix"]);
48
139
  }
49
140
  /**
50
- * @description Prepares a model for creation with validation.
51
- * @summary Overrides the base createPrefix method to add validation checks.
52
- * Creates a context, instantiates a new model, enforces decorators, and validates
53
- * the model before allowing creation to proceed.
141
+ * @description Creates multiple model instances in the repository.
142
+ * @summary Persists multiple model instances to the underlying data store by calling
143
+ * the create method for each model in the array.
144
+ * @param {M[]} models - The array of model instances to create
145
+ * @param {any[]} args - Additional arguments for the create operation
146
+ * @return {Promise<M[]>} A promise that resolves to an array of created model instances
147
+ */
148
+ async createAll(models, ...args) {
149
+ return Promise.all(models.map((m) => this.create(m, ...args)));
150
+ }
151
+ /**
152
+ * @description Prepares a model for creation and executes pre-creation operations.
153
+ * @summary Processes a model before it is created in the data store. This includes
154
+ * creating a context, instantiating a new model instance, and enforcing any decorators
155
+ * that should be applied before creation.
54
156
  * @param {M} model - The model instance to prepare for creation
55
157
  * @param {any[]} args - Additional arguments for the create operation
56
- * @return A promise that resolves to an array containing the validated model and context arguments
57
- * @throws {ValidationError} If the model fails validation
158
+ * @return A promise that resolves to an array containing the prepared model and context arguments
58
159
  */
59
160
  async createPrefix(model, ...args) {
60
161
  const contextArgs = await Context.args(OperationKeys.CREATE, this.class, args);
@@ -69,14 +170,25 @@ export class Repository extends BaseRepository {
69
170
  return [model, ...contextArgs.args];
70
171
  }
71
172
  /**
72
- * @description Prepares multiple models for creation with validation.
73
- * @summary Overrides the base createAllPrefix method to add validation checks for multiple models.
74
- * Creates a context, instantiates new models, enforces decorators, and validates
75
- * each model before allowing creation to proceed. Collects validation errors from all models.
173
+ * @description Processes a model after creation and executes post-creation operations.
174
+ * @summary Finalizes a model after it has been created in the data store. This includes
175
+ * enforcing any decorators that should be applied after creation.
176
+ * @param {M} model - The model instance that was created
177
+ * @param {C} context - The context for the operation
178
+ * @return {Promise<M>} A promise that resolves to the processed model instance
179
+ */
180
+ async createSuffix(model, context) {
181
+ await enforceDBDecorators(this, context, model, OperationKeys.CREATE, OperationKeys.AFTER);
182
+ return model;
183
+ }
184
+ /**
185
+ * @description Prepares multiple models for creation and executes pre-creation operations.
186
+ * @summary Processes multiple models before they are created in the data store. This includes
187
+ * creating a context, instantiating new model instances, and enforcing any decorators
188
+ * that should be applied before creation for each model.
76
189
  * @param {M[]} models - The array of model instances to prepare for creation
77
190
  * @param {any[]} args - Additional arguments for the create operation
78
- * @return {Promise<any[]>} A promise that resolves to an array containing the validated models and context arguments
79
- * @throws {ValidationError} If any model fails validation, with details about which models failed
191
+ * @return A promise that resolves to an array containing the prepared models and context arguments
80
192
  */
81
193
  async createAllPrefix(models, ...args) {
82
194
  const contextArgs = await Context.args(OperationKeys.CREATE, this.class, args);
@@ -97,26 +209,132 @@ export class Repository extends BaseRepository {
97
209
  return [models, ...contextArgs.args];
98
210
  }
99
211
  /**
100
- * @description Prepares a model for update with validation.
101
- * @summary Overrides the base updatePrefix method to add validation checks.
102
- * Creates a context, validates the primary key, retrieves the existing model,
103
- * merges the old and new models, enforces decorators, and validates the model
104
- * before allowing the update to proceed.
212
+ * @description Processes multiple models after creation and executes post-creation operations.
213
+ * @summary Finalizes multiple models after they have been created in the data store. This includes
214
+ * enforcing any decorators that should be applied after creation for each model.
215
+ * @param {M[]} models - The array of model instances that were created
216
+ * @param {C} context - The context for the operation
217
+ * @return {Promise<M[]>} A promise that resolves to the array of processed model instances
218
+ */
219
+ async createAllSuffix(models, context) {
220
+ await Promise.all(models.map((m) => enforceDBDecorators(this, context, m, OperationKeys.CREATE, OperationKeys.AFTER)));
221
+ return models;
222
+ }
223
+ /**
224
+ * @description Retrieves multiple model instances from the repository by their primary keys.
225
+ * @summary Fetches multiple model instances from the underlying data store using their primary keys
226
+ * by calling the read method for each key in the array.
227
+ * @param {string[] | number[]} keys - The array of primary keys of the models to retrieve
228
+ * @param {any[]} args - Additional arguments for the read operation
229
+ * @return {Promise<M[]>} A promise that resolves to an array of retrieved model instances
230
+ */
231
+ async readAll(keys, ...args) {
232
+ return await Promise.all(keys.map((id) => this.read(id, ...args)));
233
+ }
234
+ /**
235
+ * @description Processes a model after retrieval and executes post-read operations.
236
+ * @summary Finalizes a model after it has been retrieved from the data store. This includes
237
+ * enforcing any decorators that should be applied after reading.
238
+ * @param {M} model - The model instance that was retrieved
239
+ * @param {C} context - The context for the operation
240
+ * @return {Promise<M>} A promise that resolves to the processed model instance
241
+ */
242
+ async readSuffix(model, context) {
243
+ await enforceDBDecorators(this, context, model, OperationKeys.READ, OperationKeys.AFTER);
244
+ return model;
245
+ }
246
+ /**
247
+ * @description Prepares for reading a model and executes pre-read operations.
248
+ * @summary Processes a key before a model is read from the data store. This includes
249
+ * creating a context, instantiating a new model instance with the key, and enforcing any decorators
250
+ * that should be applied before reading.
251
+ * @param {string} key - The primary key of the model to read
252
+ * @param {any[]} args - Additional arguments for the read operation
253
+ * @return A promise that resolves to an array containing the key and context arguments
254
+ */
255
+ async readPrefix(key, ...args) {
256
+ const contextArgs = await Context.args(OperationKeys.READ, this.class, args);
257
+ const model = new this.class();
258
+ model[this.pk] = key;
259
+ await enforceDBDecorators(this, contextArgs.context, model, OperationKeys.READ, OperationKeys.ON);
260
+ return [key, ...contextArgs.args];
261
+ }
262
+ /**
263
+ * @description Prepares for reading multiple models and executes pre-read operations.
264
+ * @summary Processes multiple keys before models are read from the data store. This includes
265
+ * creating a context, instantiating new model instances with the keys, and enforcing any decorators
266
+ * that should be applied before reading for each key.
267
+ * @param {string[] | number[]} keys - The array of primary keys of the models to read
268
+ * @param {any[]} args - Additional arguments for the read operation
269
+ * @return A promise that resolves to an array containing the keys and context arguments
270
+ */
271
+ async readAllPrefix(keys, ...args) {
272
+ const contextArgs = await Context.args(OperationKeys.READ, this.class, args);
273
+ await Promise.all(keys.map(async (k) => {
274
+ const m = new this.class();
275
+ m[this.pk] = k;
276
+ return enforceDBDecorators(this, contextArgs.context, m, OperationKeys.READ, OperationKeys.ON);
277
+ }));
278
+ return [keys, ...contextArgs.args];
279
+ }
280
+ /**
281
+ * @description Processes multiple models after retrieval and executes post-read operations.
282
+ * @summary Finalizes multiple models after they have been retrieved from the data store. This includes
283
+ * enforcing any decorators that should be applied after reading for each model.
284
+ * @param {M[]} models - The array of model instances that were retrieved
285
+ * @param {C} context - The context for the operation
286
+ * @return {Promise<M[]>} A promise that resolves to the array of processed model instances
287
+ */
288
+ async readAllSuffix(models, context) {
289
+ await Promise.all(models.map((m) => enforceDBDecorators(this, context, m, OperationKeys.READ, OperationKeys.AFTER)));
290
+ return models;
291
+ }
292
+ /**
293
+ * @description Updates multiple model instances in the repository.
294
+ * @summary Updates multiple model instances in the underlying data store by calling
295
+ * the update method for each model in the array.
296
+ * @param {M[]} models - The array of model instances to update
297
+ * @param {any[]} args - Additional arguments for the update operation
298
+ * @return {Promise<M[]>} A promise that resolves to an array of updated model instances
299
+ */
300
+ async updateAll(models, ...args) {
301
+ return Promise.all(models.map((m) => this.update(m, ...args)));
302
+ }
303
+ /**
304
+ * @description Processes a model after update and executes post-update operations.
305
+ * @summary Finalizes a model after it has been updated in the data store. This includes
306
+ * enforcing any decorators that should be applied after updating.
307
+ * @param {M} model - The model instance that was updated
308
+ * @param {C} context - The context for the operation
309
+ * @return {Promise<M>} A promise that resolves to the processed model instance
310
+ */
311
+ async updateSuffix(model, oldModel, context) {
312
+ await enforceDBDecorators(this, context, model, OperationKeys.UPDATE, OperationKeys.AFTER, oldModel);
313
+ return model;
314
+ }
315
+ /**
316
+ * @description Prepares a model for update and executes pre-update operations.
317
+ * @summary Processes a model before it is updated in the data store. This includes
318
+ * creating a context, validating the primary key, retrieving the existing model,
319
+ * and enforcing any decorators that should be applied before updating.
105
320
  * @param {M} model - The model instance to prepare for update
106
321
  * @param {any[]} args - Additional arguments for the update operation
107
- * @return A promise that resolves to an array containing the validated model and context arguments
108
- * @throws {InternalError} If the model doesn't have a primary key value
109
- * @throws {ValidationError} If the model fails validation
322
+ * @return A promise that resolves to an array containing the prepared model and context arguments
110
323
  */
111
324
  async updatePrefix(model, ...args) {
112
325
  const contextArgs = await Context.args(OperationKeys.UPDATE, this.class, args);
326
+ const context = contextArgs.context;
113
327
  const ignoreHandlers = contextArgs.context.get("ignoreHandlers");
114
328
  const ignoreValidate = contextArgs.context.get("ignoreValidation");
115
329
  const pk = model[this.pk];
116
330
  if (!pk)
117
331
  throw new InternalError(`No value for the Id is defined under the property ${this.pk}`);
118
- const oldModel = await this.read(pk);
119
- model = Model.merge(oldModel, model, this.class);
332
+ let oldModel;
333
+ if (context.get("applyUpdateValidation")) {
334
+ oldModel = await this.read(pk);
335
+ if (context.get("mergeForUpdate"))
336
+ model = Model.merge(oldModel, model, this.class);
337
+ }
120
338
  if (!ignoreHandlers)
121
339
  await enforceDBDecorators(this, contextArgs.context, model, OperationKeys.UPDATE, OperationKeys.ON, oldModel);
122
340
  if (!ignoreValidate) {
@@ -124,50 +342,141 @@ export class Repository extends BaseRepository {
124
342
  if (errors)
125
343
  throw new ValidationError(errors.toString());
126
344
  }
127
- return [model, ...contextArgs.args];
345
+ return [model, ...contextArgs.args, oldModel];
128
346
  }
129
347
  /**
130
- * @description Prepares multiple models for update with validation.
131
- * @summary Overrides the base updateAllPrefix method to add validation checks for multiple models.
132
- * Creates a context, validates primary keys, retrieves existing models, merges old and new models,
133
- * enforces decorators, and validates each model before allowing updates to proceed.
134
- * Collects validation errors from all models.
348
+ * @description Prepares multiple models for update and executes pre-update operations.
349
+ * @summary Processes multiple models before they are updated in the data store. This includes
350
+ * creating a context, instantiating new model instances, and enforcing any decorators
351
+ * that should be applied before updating for each model.
135
352
  * @param {M[]} models - The array of model instances to prepare for update
136
353
  * @param {any[]} args - Additional arguments for the update operation
137
- * @return A promise that resolves to an array containing the validated models and context arguments
138
- * @throws {InternalError} If any model doesn't have a primary key value
139
- * @throws {ValidationError} If any model fails validation, with details about which models failed
354
+ * @return A promise that resolves to an array containing the prepared models and context arguments
140
355
  */
141
356
  async updateAllPrefix(models, ...args) {
142
357
  const contextArgs = await Context.args(OperationKeys.UPDATE, this.class, args);
143
- const ignoreHandlers = contextArgs.context.get("ignoreHandlers");
144
- const ignoreValidate = contextArgs.context.get("ignoreValidation");
358
+ const context = contextArgs.context;
359
+ const ignoreHandlers = context.get("ignoreHandlers");
360
+ const ignoreValidate = context.get("ignoreValidation");
145
361
  const ids = models.map((m) => {
146
362
  const id = m[this.pk];
147
363
  if (typeof id === "undefined")
148
364
  throw new InternalError(`No value for the Id is defined under the property ${this.pk}`);
149
365
  return id;
150
366
  });
151
- const oldModels = await this.readAll(ids, ...contextArgs.args);
152
- models = models.map((m, i) => Model.merge(oldModels[i], m, this.class));
367
+ let oldModels;
368
+ if (context.get("applyUpdateValidation")) {
369
+ oldModels = await this.readAll(ids, context);
370
+ if (context.get("mergeForUpdate"))
371
+ models = models.map((m, i) => Model.merge(oldModels[i], m, this.class));
372
+ }
153
373
  if (!ignoreHandlers)
154
- await Promise.all(models.map((m, i) => enforceDBDecorators(this, contextArgs.context, m, OperationKeys.UPDATE, OperationKeys.ON, oldModels[i])));
374
+ await Promise.all(models.map((m, i) => enforceDBDecorators(this, contextArgs.context, m, OperationKeys.UPDATE, OperationKeys.ON, oldModels ? oldModels[i] : undefined)));
155
375
  if (!ignoreValidate) {
156
- const modelsValidation = await Promise.all(models.map((m, i) => Promise.resolve(m.hasErrors(oldModels[i]))));
376
+ let modelsValidation;
377
+ if (!context.get("applyUpdateValidation")) {
378
+ modelsValidation = await Promise.resolve(models.map((m) => m.hasErrors()));
379
+ }
380
+ else {
381
+ modelsValidation = await Promise.all(models.map((m, i) => Promise.resolve(m.hasErrors(oldModels[i]))));
382
+ }
157
383
  const errors = reduceErrorsToPrint(modelsValidation);
158
384
  if (errors)
159
385
  throw new ValidationError(errors);
160
386
  }
161
- return [models, ...contextArgs.args];
387
+ return [models, ...contextArgs.args, oldModels];
162
388
  }
163
- async readPrefix(key, ...args) {
164
- return super.readPrefix(key, ...args);
389
+ /**
390
+ * @description Processes multiple models after update and executes post-update operations.
391
+ * @summary Finalizes multiple models after they have been updated in the data store. This includes
392
+ * enforcing any decorators that should be applied after updating for each model.
393
+ * @param {M[]} models - The array of model instances that were updated
394
+ * @param {C} context - The context for the operation
395
+ * @return {Promise<M[]>} A promise that resolves to the array of processed model instances
396
+ */
397
+ async updateAllSuffix(models, oldModels, context) {
398
+ if (context.get("applyUpdateValidation") &&
399
+ !context.get("ignoreDevSafeGuards")) {
400
+ if (!oldModels)
401
+ throw new InternalError("No previous versions of models provided");
402
+ }
403
+ await Promise.all(models.map((m, i) => enforceDBDecorators(this, context, m, OperationKeys.UPDATE, OperationKeys.AFTER, oldModels ? oldModels[i] : undefined)));
404
+ return models;
165
405
  }
166
- async readAllPrefix(keys, ...args) {
167
- return super.readAllPrefix(keys, ...args);
406
+ /**
407
+ * @description Deletes multiple model instances from the repository by their primary keys.
408
+ * @summary Removes multiple model instances from the underlying data store using their primary keys
409
+ * by calling the delete method for each key in the array.
410
+ * @param {string[] | number[]} keys - The array of primary keys of the models to delete
411
+ * @param {any[]} args - Additional arguments for the delete operation
412
+ * @return {Promise<M[]>} A promise that resolves to an array of deleted model instances
413
+ */
414
+ async deleteAll(keys, ...args) {
415
+ return Promise.all(keys.map((k) => this.delete(k, ...args)));
416
+ }
417
+ /**
418
+ * @description Processes a model after deletion and executes post-delete operations.
419
+ * @summary Finalizes a model after it has been deleted from the data store. This includes
420
+ * enforcing any decorators that should be applied after deletion.
421
+ * @param {M} model - The model instance that was deleted
422
+ * @param {C} context - The context for the operation
423
+ * @return {Promise<M>} A promise that resolves to the processed model instance
424
+ */
425
+ async deleteSuffix(model, context) {
426
+ await enforceDBDecorators(this, context, model, OperationKeys.DELETE, OperationKeys.AFTER);
427
+ return model;
428
+ }
429
+ /**
430
+ * @description Prepares for deleting a model and executes pre-delete operations.
431
+ * @summary Processes a key before a model is deleted from the data store. This includes
432
+ * creating a context, retrieving the model to be deleted, and enforcing any decorators
433
+ * that should be applied before deletion.
434
+ * @param {any} key - The primary key of the model to delete
435
+ * @param {any[]} args - Additional arguments for the delete operation
436
+ * @return A promise that resolves to an array containing the key and context arguments
437
+ */
438
+ async deletePrefix(key, ...args) {
439
+ const contextArgs = await Context.args(OperationKeys.DELETE, this.class, args);
440
+ const model = await this.read(key, ...contextArgs.args);
441
+ await enforceDBDecorators(this, contextArgs.context, model, OperationKeys.DELETE, OperationKeys.ON);
442
+ return [key, ...contextArgs.args];
168
443
  }
444
+ /**
445
+ * @description Prepares for deleting multiple models and executes pre-delete operations.
446
+ * @summary Processes multiple keys before models are deleted from the data store. This includes
447
+ * creating a context, retrieving the models to be deleted, and enforcing any decorators
448
+ * that should be applied before deletion for each model.
449
+ * @param {string[] | number[]} keys - The array of primary keys of the models to delete
450
+ * @param {any[]} args - Additional arguments for the delete operation
451
+ * @return A promise that resolves to an array containing the keys and context arguments
452
+ */
169
453
  async deleteAllPrefix(keys, ...args) {
170
- return super.deleteAllPrefix(keys, ...args);
454
+ const contextArgs = await Context.args(OperationKeys.DELETE, this.class, args);
455
+ const models = await this.readAll(keys, ...contextArgs.args);
456
+ await Promise.all(models.map(async (m) => {
457
+ return enforceDBDecorators(this, contextArgs.context, m, OperationKeys.DELETE, OperationKeys.ON);
458
+ }));
459
+ return [keys, ...contextArgs.args];
460
+ }
461
+ /**
462
+ * @description Processes multiple models after deletion and executes post-delete operations.
463
+ * @summary Finalizes multiple models after they have been deleted from the data store. This includes
464
+ * enforcing any decorators that should be applied after deletion for each model.
465
+ * @param {M[]} models - The array of model instances that were deleted
466
+ * @param {C} context - The context for the operation
467
+ * @return {Promise<M[]>} A promise that resolves to the array of processed model instances
468
+ */
469
+ async deleteAllSuffix(models, context) {
470
+ await Promise.all(models.map((m) => enforceDBDecorators(this, context, m, OperationKeys.DELETE, OperationKeys.AFTER)));
471
+ return models;
472
+ }
473
+ /**
474
+ * @description Returns a string representation of the repository.
475
+ * @summary Creates a string that identifies this repository by the name of its model class.
476
+ * @return {string} A string representation of the repository
477
+ */
478
+ toString() {
479
+ return `${this.class.name} Repository`;
171
480
  }
172
481
  }
173
482
  //# sourceMappingURL=Repository.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Repository.js","sourceRoot":"","sources":["../../../src/repository/Repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,mBAAgB;AACnE,OAAO,EAAE,aAAa,EAAE,qCAAgC;AACxD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,oBAAiB;AAC1D,OAAO,EAAE,cAAc,EAAE,4BAAyB;AAClD,OAAO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: false,
19
19
  ignoreHandlers: false,
20
+ ignoreDevSafeGuards: false,
21
+ mergeForUpdate: true,
22
+ applyUpdateValidation: true,
20
23
  };
21
24
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/repository/constants.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAG/B;IACF,aAAa,EAAE,SAAS;IACxB,aAAa,EAAE,EAAE;IACjB,2BAA2B,EAAE,EAAE;IAC/B,QAAQ,EAAE,EAAE;IACZ,cAAc,EAAE,KAAK;IACrB,cAAc,EAAE,EAAE;IAClB,SAAS,EAAE,SAAS;IACpB,mBAAmB,EAAE,IAAI;IACzB,oBAAoB,EAAE,IAAI;IAC1B,gBAAgB,EAAE,KAAK;IACvB,cAAc,EAAE,KAAK;CACtB,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/repository/constants.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAG/B;IACF,aAAa,EAAE,SAAS;IACxB,aAAa,EAAE,EAAE;IACjB,2BAA2B,EAAE,EAAE;IAC/B,QAAQ,EAAE,EAAE;IACZ,cAAc,EAAE,KAAK;IACrB,cAAc,EAAE,EAAE;IAClB,SAAS,EAAE,SAAS;IACpB,mBAAmB,EAAE,IAAI;IACzB,oBAAoB,EAAE,IAAI;IAC1B,gBAAgB,EAAE,KAAK;IACvB,cAAc,EAAE,KAAK;IACrB,mBAAmB,EAAE,KAAK;IAC1B,cAAc,EAAE,IAAI;IACpB,qBAAqB,EAAE,IAAI;CAC5B,CAAC"}
@@ -1,8 +1,7 @@
1
- export * from "./BaseRepository";
1
+ export * from "./Repository";
2
2
  export * from "./constants";
3
3
  export * from "./Context";
4
4
  export * from "./errors";
5
- export * from "./Repository";
6
5
  export * from "./types";
7
6
  export * from "./utils";
8
7
  export * from "./wrappers";
@@ -1,8 +1,7 @@
1
- export * from "./BaseRepository.js";
1
+ export * from "./Repository.js";
2
2
  export * from "./constants.js";
3
3
  export * from "./Context.js";
4
4
  export * from "./errors.js";
5
- export * from "./Repository.js";
6
5
  export * from "./types.js";
7
6
  export * from "./utils.js";
8
7
  export * from "./wrappers.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/repository/index.ts"],"names":[],"mappings":"AAAA,oCAAiC;AACjC,+BAA4B;AAC5B,6BAA0B;AAC1B,4BAAyB;AACzB,gCAA6B;AAC7B,2BAAwB;AACxB,2BAAwB;AACxB,8BAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/repository/index.ts"],"names":[],"mappings":"AAAA,gCAA6B;AAC7B,+BAA4B;AAC5B,6BAA0B;AAC1B,4BAAyB;AACzB,2BAAwB;AACxB,2BAAwB;AACxB,8BAA2B"}
@@ -43,6 +43,9 @@ export interface RepositoryFlags<LOG extends Logger = Logger> {
43
43
  rebuildWithTransient: boolean;
44
44
  ignoreValidation: boolean;
45
45
  ignoreHandlers: boolean | string | RegExp;
46
+ ignoreDevSafeGuards: boolean;
47
+ mergeForUpdate: boolean;
48
+ applyUpdateValidation: boolean;
46
49
  logger: LOG;
47
50
  correlationId?: string;
48
51
  }
@@ -1,4 +1,4 @@
1
- import { ModelOperations, OperationKeys } from "./../operations/constants.js";
1
+ import { BulkCrudOperationKeys, ModelOperations, OperationKeys, } from "./../operations/constants.js";
2
2
  import { InternalError } from "./errors.js";
3
3
  import { getHandlersDecorators, groupDecorators, sortDecorators, } from "./../operations/decorators.js";
4
4
  import { Metadata } from "@decaf-ts/decoration";
@@ -39,7 +39,7 @@ export async function enforceDBDecorators(repo, context, model, operation, prefi
39
39
  dec.prop.length > 1 ? dec.prop : dec.prop[0],
40
40
  model,
41
41
  ];
42
- if (operation === OperationKeys.UPDATE && prefix === OperationKeys.ON) {
42
+ if ([OperationKeys.UPDATE, BulkCrudOperationKeys.UPDATE_ALL].includes(operation)) {
43
43
  if (!oldModel)
44
44
  throw new InternalError("Missing old model for update operation");
45
45
  args.push(oldModel);
@@ -51,7 +51,7 @@ export async function enforceDBDecorators(repo, context, model, operation, prefi
51
51
  const msg = `Failed to execute handler ${dec.handler.name} for ${dec.prop} on ${model.constructor.name} due to error: ${e}`;
52
52
  if (context.get("breakOnHandlerError"))
53
53
  throw new InternalError(msg);
54
- console.log(msg);
54
+ context.logger.for(enforceDBDecorators).error(msg);
55
55
  }
56
56
  }
57
57
  }