@opra/sqb 1.0.0-alpha.36 → 1.0.0-alpha.37

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.
@@ -473,7 +473,36 @@ class SqbEntityService extends core_1.ServiceBase {
473
473
  if (!(proto instanceof SqbEntityService))
474
474
  break;
475
475
  }
476
- return commandFn();
476
+ if (command.crud === 'create')
477
+ await this._beforeCreate(command);
478
+ else if (command.crud === 'update' && command.byId) {
479
+ await this._beforeUpdate(command);
480
+ }
481
+ else if (command.crud === 'update' && !command.byId) {
482
+ await this._beforeUpdate(command);
483
+ }
484
+ else if (command.crud === 'delete' && command.byId) {
485
+ await this._beforeDelete(command);
486
+ }
487
+ else if (command.crud === 'delete' && !command.byId) {
488
+ await this._beforeDeleteMany(command);
489
+ }
490
+ const result = await commandFn();
491
+ if (command.crud === 'create')
492
+ await this._afterCreate(command, result);
493
+ else if (command.crud === 'update' && command.byId) {
494
+ await this._afterUpdate(command, result);
495
+ }
496
+ else if (command.crud === 'update' && !command.byId) {
497
+ await this._afterUpdate(command, result);
498
+ }
499
+ else if (command.crud === 'delete' && command.byId) {
500
+ await this._afterDelete(command, result);
501
+ }
502
+ else if (command.crud === 'delete' && !command.byId) {
503
+ await this._afterDeleteMany(command, result);
504
+ }
505
+ return result;
477
506
  };
478
507
  try {
479
508
  return await next();
@@ -484,5 +513,45 @@ class SqbEntityService extends core_1.ServiceBase {
484
513
  throw e;
485
514
  }
486
515
  }
516
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
517
+ async _beforeCreate(command) {
518
+ // Do nothing
519
+ }
520
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
521
+ async _beforeUpdate(command) {
522
+ // Do nothing
523
+ }
524
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
525
+ async _beforeUpdateMany(command) {
526
+ // Do nothing
527
+ }
528
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
529
+ async _beforeDelete(command) {
530
+ // Do nothing
531
+ }
532
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
533
+ async _beforeDeleteMany(command) {
534
+ // Do nothing
535
+ }
536
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
537
+ async _afterCreate(command, result) {
538
+ // Do nothing
539
+ }
540
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
541
+ async _afterUpdate(command, result) {
542
+ // Do nothing
543
+ }
544
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
545
+ async _afterUpdateMany(command, affected) {
546
+ // Do nothing
547
+ }
548
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
549
+ async _afterDelete(command, affected) {
550
+ // Do nothing
551
+ }
552
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
553
+ async _afterDeleteMany(command, affected) {
554
+ // Do nothing
555
+ }
487
556
  }
488
557
  exports.SqbEntityService = SqbEntityService;
@@ -470,7 +470,36 @@ export class SqbEntityService extends ServiceBase {
470
470
  if (!(proto instanceof SqbEntityService))
471
471
  break;
472
472
  }
473
- return commandFn();
473
+ if (command.crud === 'create')
474
+ await this._beforeCreate(command);
475
+ else if (command.crud === 'update' && command.byId) {
476
+ await this._beforeUpdate(command);
477
+ }
478
+ else if (command.crud === 'update' && !command.byId) {
479
+ await this._beforeUpdate(command);
480
+ }
481
+ else if (command.crud === 'delete' && command.byId) {
482
+ await this._beforeDelete(command);
483
+ }
484
+ else if (command.crud === 'delete' && !command.byId) {
485
+ await this._beforeDeleteMany(command);
486
+ }
487
+ const result = await commandFn();
488
+ if (command.crud === 'create')
489
+ await this._afterCreate(command, result);
490
+ else if (command.crud === 'update' && command.byId) {
491
+ await this._afterUpdate(command, result);
492
+ }
493
+ else if (command.crud === 'update' && !command.byId) {
494
+ await this._afterUpdate(command, result);
495
+ }
496
+ else if (command.crud === 'delete' && command.byId) {
497
+ await this._afterDelete(command, result);
498
+ }
499
+ else if (command.crud === 'delete' && !command.byId) {
500
+ await this._afterDeleteMany(command, result);
501
+ }
502
+ return result;
474
503
  };
475
504
  try {
476
505
  return await next();
@@ -481,4 +510,44 @@ export class SqbEntityService extends ServiceBase {
481
510
  throw e;
482
511
  }
483
512
  }
513
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
514
+ async _beforeCreate(command) {
515
+ // Do nothing
516
+ }
517
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
518
+ async _beforeUpdate(command) {
519
+ // Do nothing
520
+ }
521
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
522
+ async _beforeUpdateMany(command) {
523
+ // Do nothing
524
+ }
525
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
526
+ async _beforeDelete(command) {
527
+ // Do nothing
528
+ }
529
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
530
+ async _beforeDeleteMany(command) {
531
+ // Do nothing
532
+ }
533
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
534
+ async _afterCreate(command, result) {
535
+ // Do nothing
536
+ }
537
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
538
+ async _afterUpdate(command, result) {
539
+ // Do nothing
540
+ }
541
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
542
+ async _afterUpdateMany(command, affected) {
543
+ // Do nothing
544
+ }
545
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
546
+ async _afterDelete(command, affected) {
547
+ // Do nothing
548
+ }
549
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
550
+ async _afterDeleteMany(command, affected) {
551
+ // Do nothing
552
+ }
484
553
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/sqb",
3
- "version": "1.0.0-alpha.36",
3
+ "version": "1.0.0-alpha.37",
4
4
  "description": "Opra SQB adapter package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -10,7 +10,7 @@
10
10
  "valgen": "^5.9.0"
11
11
  },
12
12
  "peerDependencies": {
13
- "@opra/core": "^1.0.0-alpha.36",
13
+ "@opra/core": "^1.0.0-alpha.37",
14
14
  "@sqb/connect": ">= 4.10.6"
15
15
  },
16
16
  "type": "module",
@@ -428,4 +428,14 @@ export declare class SqbEntityService<T extends object = object> extends Service
428
428
  */
429
429
  protected _getCommonFilter(command: SqbEntityService.CommandInfo): SQBAdapter.FilterInput | Promise<SQBAdapter.FilterInput> | undefined;
430
430
  protected _executeCommand(command: SqbEntityService.CommandInfo, commandFn: () => any): Promise<any>;
431
+ protected _beforeCreate(command: SqbEntityService.CreateCommand): Promise<void>;
432
+ protected _beforeUpdate(command: SqbEntityService.UpdateOneCommand<T>): Promise<void>;
433
+ protected _beforeUpdateMany(command: SqbEntityService.UpdateManyCommand<T>): Promise<void>;
434
+ protected _beforeDelete(command: SqbEntityService.DeleteOneCommand): Promise<void>;
435
+ protected _beforeDeleteMany(command: SqbEntityService.DeleteManyCommand): Promise<void>;
436
+ protected _afterCreate(command: SqbEntityService.CreateCommand, result: PartialDTO<T>): Promise<void>;
437
+ protected _afterUpdate(command: SqbEntityService.UpdateOneCommand<T>, result?: PartialDTO<T>): Promise<void>;
438
+ protected _afterUpdateMany(command: SqbEntityService.UpdateManyCommand<T>, affected: number): Promise<void>;
439
+ protected _afterDelete(command: SqbEntityService.DeleteOneCommand, affected: number): Promise<void>;
440
+ protected _afterDeleteMany(command: SqbEntityService.DeleteManyCommand, affected: number): Promise<void>;
431
441
  }