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

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,13 +473,14 @@ class SqbEntityService extends core_1.ServiceBase {
473
473
  if (!(proto instanceof SqbEntityService))
474
474
  break;
475
475
  }
476
+ /** Call before[X] hooks */
476
477
  if (command.crud === 'create')
477
478
  await this._beforeCreate(command);
478
479
  else if (command.crud === 'update' && command.byId) {
479
480
  await this._beforeUpdate(command);
480
481
  }
481
482
  else if (command.crud === 'update' && !command.byId) {
482
- await this._beforeUpdate(command);
483
+ await this._beforeUpdateMany(command);
483
484
  }
484
485
  else if (command.crud === 'delete' && command.byId) {
485
486
  await this._beforeDelete(command);
@@ -487,14 +488,19 @@ class SqbEntityService extends core_1.ServiceBase {
487
488
  else if (command.crud === 'delete' && !command.byId) {
488
489
  await this._beforeDeleteMany(command);
489
490
  }
490
- const result = await commandFn();
491
+ /** Call command function */
492
+ return commandFn();
493
+ };
494
+ try {
495
+ const result = await next();
496
+ /** Call after[X] hooks */
491
497
  if (command.crud === 'create')
492
498
  await this._afterCreate(command, result);
493
499
  else if (command.crud === 'update' && command.byId) {
494
500
  await this._afterUpdate(command, result);
495
501
  }
496
502
  else if (command.crud === 'update' && !command.byId) {
497
- await this._afterUpdate(command, result);
503
+ await this._afterUpdateMany(command, result);
498
504
  }
499
505
  else if (command.crud === 'delete' && command.byId) {
500
506
  await this._afterDelete(command, result);
@@ -503,9 +509,6 @@ class SqbEntityService extends core_1.ServiceBase {
503
509
  await this._afterDeleteMany(command, result);
504
510
  }
505
511
  return result;
506
- };
507
- try {
508
- return await next();
509
512
  }
510
513
  catch (e) {
511
514
  Error.captureStackTrace(e, this._executeCommand);
@@ -470,13 +470,14 @@ export class SqbEntityService extends ServiceBase {
470
470
  if (!(proto instanceof SqbEntityService))
471
471
  break;
472
472
  }
473
+ /** Call before[X] hooks */
473
474
  if (command.crud === 'create')
474
475
  await this._beforeCreate(command);
475
476
  else if (command.crud === 'update' && command.byId) {
476
477
  await this._beforeUpdate(command);
477
478
  }
478
479
  else if (command.crud === 'update' && !command.byId) {
479
- await this._beforeUpdate(command);
480
+ await this._beforeUpdateMany(command);
480
481
  }
481
482
  else if (command.crud === 'delete' && command.byId) {
482
483
  await this._beforeDelete(command);
@@ -484,14 +485,19 @@ export class SqbEntityService extends ServiceBase {
484
485
  else if (command.crud === 'delete' && !command.byId) {
485
486
  await this._beforeDeleteMany(command);
486
487
  }
487
- const result = await commandFn();
488
+ /** Call command function */
489
+ return commandFn();
490
+ };
491
+ try {
492
+ const result = await next();
493
+ /** Call after[X] hooks */
488
494
  if (command.crud === 'create')
489
495
  await this._afterCreate(command, result);
490
496
  else if (command.crud === 'update' && command.byId) {
491
497
  await this._afterUpdate(command, result);
492
498
  }
493
499
  else if (command.crud === 'update' && !command.byId) {
494
- await this._afterUpdate(command, result);
500
+ await this._afterUpdateMany(command, result);
495
501
  }
496
502
  else if (command.crud === 'delete' && command.byId) {
497
503
  await this._afterDelete(command, result);
@@ -500,9 +506,6 @@ export class SqbEntityService extends ServiceBase {
500
506
  await this._afterDeleteMany(command, result);
501
507
  }
502
508
  return result;
503
- };
504
- try {
505
- return await next();
506
509
  }
507
510
  catch (e) {
508
511
  Error.captureStackTrace(e, this._executeCommand);
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@opra/sqb",
3
- "version": "1.0.0-alpha.37",
3
+ "version": "1.0.0-alpha.39",
4
4
  "description": "Opra SQB adapter package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
8
  "reflect-metadata": "^0.2.2",
9
- "tslib": "^2.6.3",
9
+ "tslib": "^2.7.0",
10
10
  "valgen": "^5.9.0"
11
11
  },
12
12
  "peerDependencies": {
13
- "@opra/core": "^1.0.0-alpha.37",
13
+ "@opra/core": "^1.0.0-alpha.39",
14
14
  "@sqb/connect": ">= 4.10.6"
15
15
  },
16
16
  "type": "module",
@@ -1,4 +1,4 @@
1
- import { PartialDTO, PatchDTO, RequiredSome, Type } from 'ts-gems';
1
+ import type { PartialDTO, PatchDTO, RequiredSome, Type } from 'ts-gems';
2
2
  import { SQBAdapter } from './sqb-adapter.js';
3
3
  import { SqbEntityService } from './sqb-entity-service.js';
4
4
  /**
@@ -1,8 +1,8 @@
1
1
  import { ComplexType } from '@opra/common';
2
2
  import { HttpContext, ServiceBase } from '@opra/core';
3
3
  import { EntityMetadata, Repository, SqbClient, SqbConnection } from '@sqb/connect';
4
- import { Nullish, PartialDTO, PatchDTO, RequiredSome, StrictOmit, Type } from 'ts-gems';
5
- import { IsObject } from 'valgen';
4
+ import type { Nullish, PartialDTO, PatchDTO, RequiredSome, StrictOmit, Type } from 'ts-gems';
5
+ import { type IsObject } from 'valgen';
6
6
  import { SQBAdapter } from './sqb-adapter.js';
7
7
  /**
8
8
  * @namespace SqbEntityService
@@ -95,8 +95,9 @@ export declare namespace SqbEntityService {
95
95
  */
96
96
  interface UpdateManyOptions extends Repository.UpdateManyOptions {
97
97
  }
98
- interface CreateCommand extends StrictOmit<RequiredSome<CommandInfo, 'input'>, 'documentId'> {
98
+ interface CreateCommand<T> extends StrictOmit<RequiredSome<CommandInfo, 'input'>, 'documentId'> {
99
99
  crud: 'create';
100
+ input: PatchDTO<T>;
100
101
  options?: CreateOptions;
101
102
  }
102
103
  interface CountCommand extends StrictOmit<CommandInfo, 'documentId' | 'input'> {
@@ -229,7 +230,7 @@ export declare class SqbEntityService<T extends object = object> extends Service
229
230
  * @returns - A promise that resolves to the created resource
230
231
  * @protected
231
232
  */
232
- protected _create(command: SqbEntityService.CreateCommand): Promise<PartialDTO<T>>;
233
+ protected _create(command: SqbEntityService.CreateCommand<T>): Promise<PartialDTO<T>>;
233
234
  /**
234
235
  * Returns the count of records based on the provided options
235
236
  *
@@ -428,12 +429,12 @@ export declare class SqbEntityService<T extends object = object> extends Service
428
429
  */
429
430
  protected _getCommonFilter(command: SqbEntityService.CommandInfo): SQBAdapter.FilterInput | Promise<SQBAdapter.FilterInput> | undefined;
430
431
  protected _executeCommand(command: SqbEntityService.CommandInfo, commandFn: () => any): Promise<any>;
431
- protected _beforeCreate(command: SqbEntityService.CreateCommand): Promise<void>;
432
+ protected _beforeCreate(command: SqbEntityService.CreateCommand<T>): Promise<void>;
432
433
  protected _beforeUpdate(command: SqbEntityService.UpdateOneCommand<T>): Promise<void>;
433
434
  protected _beforeUpdateMany(command: SqbEntityService.UpdateManyCommand<T>): Promise<void>;
434
435
  protected _beforeDelete(command: SqbEntityService.DeleteOneCommand): Promise<void>;
435
436
  protected _beforeDeleteMany(command: SqbEntityService.DeleteManyCommand): Promise<void>;
436
- protected _afterCreate(command: SqbEntityService.CreateCommand, result: PartialDTO<T>): Promise<void>;
437
+ protected _afterCreate(command: SqbEntityService.CreateCommand<T>, result: PartialDTO<T>): Promise<void>;
437
438
  protected _afterUpdate(command: SqbEntityService.UpdateOneCommand<T>, result?: PartialDTO<T>): Promise<void>;
438
439
  protected _afterUpdateMany(command: SqbEntityService.UpdateManyCommand<T>, affected: number): Promise<void>;
439
440
  protected _afterDelete(command: SqbEntityService.DeleteOneCommand, affected: number): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { PartialDTO, PatchDTO, RequiredSome, Type } from 'ts-gems';
1
+ import type { PartialDTO, PatchDTO, RequiredSome, Type } from 'ts-gems';
2
2
  import { SQBAdapter } from './sqb-adapter.js';
3
3
  import { SqbEntityService } from './sqb-entity-service.js';
4
4
  /**