@opra/sqb 0.26.3 → 0.26.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,32 +12,32 @@ class SqbCollection {
12
12
  async create(ctx) {
13
13
  const prepared = await this._prepare(ctx);
14
14
  const service = await this.getService(ctx);
15
- return service.with(ctx).create(prepared.data, prepared.options);
15
+ return service.create(prepared.data, prepared.options);
16
16
  }
17
17
  async delete(ctx) {
18
18
  const prepared = await this._prepare(ctx);
19
19
  const service = await this.getService(ctx);
20
- return service.with(ctx).delete(prepared.key, prepared.options);
20
+ return service.delete(prepared.key, prepared.options);
21
21
  }
22
22
  async deleteMany(ctx) {
23
23
  const prepared = await this._prepare(ctx);
24
24
  const service = await this.getService(ctx);
25
- return service.with(ctx).deleteMany(prepared.options);
25
+ return service.deleteMany(prepared.options);
26
26
  }
27
27
  async get(ctx) {
28
28
  const prepared = await this._prepare(ctx);
29
29
  const service = await this.getService(ctx);
30
- return service.with(ctx).find(prepared.key, prepared.options);
30
+ return service.find(prepared.key, prepared.options);
31
31
  }
32
32
  async update(ctx) {
33
33
  const prepared = await this._prepare(ctx);
34
34
  const service = await this.getService(ctx);
35
- return service.with(ctx).update(prepared.key, prepared.data, prepared.options);
35
+ return service.update(prepared.key, prepared.data, prepared.options);
36
36
  }
37
37
  async updateMany(ctx) {
38
38
  const prepared = await this._prepare(ctx);
39
39
  const service = await this.getService(ctx);
40
- return service.with(ctx).updateMany(prepared.data, prepared.options);
40
+ return service.updateMany(prepared.data, prepared.options);
41
41
  }
42
42
  async findMany(ctx) {
43
43
  const prepared = await this._prepare(ctx);
@@ -51,7 +51,7 @@ class SqbCollection {
51
51
  return items;
52
52
  }
53
53
  else
54
- return service.with(ctx).findMany(prepared.options);
54
+ return service.findMany(prepared.options);
55
55
  }
56
56
  async _prepare(ctx) {
57
57
  const prepared = sqb_adapter_js_1.SQBAdapter.transformRequest(ctx.request);
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SqbEntityService = void 0;
4
+ const core_1 = require("@opra/core");
4
5
  const connect_1 = require("@sqb/connect");
5
- class SqbEntityService {
6
+ class SqbEntityService extends core_1.ApiService {
6
7
  constructor(typeClass, options) {
8
+ super();
7
9
  this.typeClass = typeClass;
8
10
  const metadata = connect_1.EntityMetadata.get(typeClass);
9
11
  if (!metadata)
@@ -154,14 +156,8 @@ class SqbEntityService {
154
156
  return this.forContext(context, db);
155
157
  }
156
158
  forContext(context, db) {
157
- if (this.context === context && this.db === db)
158
- return this;
159
- const instance = { context };
160
- // Should reset session if db changed
161
- if (db) {
162
- instance.db = db;
163
- }
164
- Object.setPrototypeOf(instance, this);
159
+ const instance = super.forContext(context);
160
+ instance.db = db || this.db;
165
161
  return instance;
166
162
  }
167
163
  async _onError(error) {
@@ -8,23 +8,23 @@ class SqbSingleton {
8
8
  async create(ctx) {
9
9
  const prepared = await this._prepare(ctx);
10
10
  const service = await this.getService(ctx);
11
- return service.with(ctx).create(prepared.data, prepared.options);
11
+ return service.create(prepared.data, prepared.options);
12
12
  }
13
13
  async delete(ctx) {
14
14
  const prepared = await this._prepare(ctx);
15
15
  const service = await this.getService(ctx);
16
- return await service.with(ctx).deleteMany(prepared.options);
16
+ return await service.deleteMany(prepared.options);
17
17
  }
18
18
  async get(ctx) {
19
19
  const prepared = await this._prepare(ctx);
20
20
  const service = await this.getService(ctx);
21
- return service.with(ctx).findOne(prepared.options);
21
+ return service.findOne(prepared.options);
22
22
  }
23
23
  async update(ctx) {
24
24
  const prepared = await this._prepare(ctx);
25
25
  const service = await this.getService(ctx);
26
- await service.with(ctx).updateMany(prepared.data, prepared.options);
27
- return service.with(ctx).findOne(prepared.options);
26
+ await service.updateMany(prepared.data, prepared.options);
27
+ return service.findOne(prepared.options);
28
28
  }
29
29
  async _prepare(ctx) {
30
30
  const prepared = sqb_adapter_js_1.SQBAdapter.transformRequest(ctx.request);
@@ -9,32 +9,32 @@ export class SqbCollection {
9
9
  async create(ctx) {
10
10
  const prepared = await this._prepare(ctx);
11
11
  const service = await this.getService(ctx);
12
- return service.with(ctx).create(prepared.data, prepared.options);
12
+ return service.create(prepared.data, prepared.options);
13
13
  }
14
14
  async delete(ctx) {
15
15
  const prepared = await this._prepare(ctx);
16
16
  const service = await this.getService(ctx);
17
- return service.with(ctx).delete(prepared.key, prepared.options);
17
+ return service.delete(prepared.key, prepared.options);
18
18
  }
19
19
  async deleteMany(ctx) {
20
20
  const prepared = await this._prepare(ctx);
21
21
  const service = await this.getService(ctx);
22
- return service.with(ctx).deleteMany(prepared.options);
22
+ return service.deleteMany(prepared.options);
23
23
  }
24
24
  async get(ctx) {
25
25
  const prepared = await this._prepare(ctx);
26
26
  const service = await this.getService(ctx);
27
- return service.with(ctx).find(prepared.key, prepared.options);
27
+ return service.find(prepared.key, prepared.options);
28
28
  }
29
29
  async update(ctx) {
30
30
  const prepared = await this._prepare(ctx);
31
31
  const service = await this.getService(ctx);
32
- return service.with(ctx).update(prepared.key, prepared.data, prepared.options);
32
+ return service.update(prepared.key, prepared.data, prepared.options);
33
33
  }
34
34
  async updateMany(ctx) {
35
35
  const prepared = await this._prepare(ctx);
36
36
  const service = await this.getService(ctx);
37
- return service.with(ctx).updateMany(prepared.data, prepared.options);
37
+ return service.updateMany(prepared.data, prepared.options);
38
38
  }
39
39
  async findMany(ctx) {
40
40
  const prepared = await this._prepare(ctx);
@@ -48,7 +48,7 @@ export class SqbCollection {
48
48
  return items;
49
49
  }
50
50
  else
51
- return service.with(ctx).findMany(prepared.options);
51
+ return service.findMany(prepared.options);
52
52
  }
53
53
  async _prepare(ctx) {
54
54
  const prepared = SQBAdapter.transformRequest(ctx.request);
@@ -1,6 +1,8 @@
1
+ import { ApiService } from '@opra/core';
1
2
  import { EntityMetadata } from '@sqb/connect';
2
- export class SqbEntityService {
3
+ export class SqbEntityService extends ApiService {
3
4
  constructor(typeClass, options) {
5
+ super();
4
6
  this.typeClass = typeClass;
5
7
  const metadata = EntityMetadata.get(typeClass);
6
8
  if (!metadata)
@@ -151,14 +153,8 @@ export class SqbEntityService {
151
153
  return this.forContext(context, db);
152
154
  }
153
155
  forContext(context, db) {
154
- if (this.context === context && this.db === db)
155
- return this;
156
- const instance = { context };
157
- // Should reset session if db changed
158
- if (db) {
159
- instance.db = db;
160
- }
161
- Object.setPrototypeOf(instance, this);
156
+ const instance = super.forContext(context);
157
+ instance.db = db || this.db;
162
158
  return instance;
163
159
  }
164
160
  async _onError(error) {
@@ -5,23 +5,23 @@ export class SqbSingleton {
5
5
  async create(ctx) {
6
6
  const prepared = await this._prepare(ctx);
7
7
  const service = await this.getService(ctx);
8
- return service.with(ctx).create(prepared.data, prepared.options);
8
+ return service.create(prepared.data, prepared.options);
9
9
  }
10
10
  async delete(ctx) {
11
11
  const prepared = await this._prepare(ctx);
12
12
  const service = await this.getService(ctx);
13
- return await service.with(ctx).deleteMany(prepared.options);
13
+ return await service.deleteMany(prepared.options);
14
14
  }
15
15
  async get(ctx) {
16
16
  const prepared = await this._prepare(ctx);
17
17
  const service = await this.getService(ctx);
18
- return service.with(ctx).findOne(prepared.options);
18
+ return service.findOne(prepared.options);
19
19
  }
20
20
  async update(ctx) {
21
21
  const prepared = await this._prepare(ctx);
22
22
  const service = await this.getService(ctx);
23
- await service.with(ctx).updateMany(prepared.data, prepared.options);
24
- return service.with(ctx).findOne(prepared.options);
23
+ await service.updateMany(prepared.data, prepared.options);
24
+ return service.findOne(prepared.options);
25
25
  }
26
26
  async _prepare(ctx) {
27
27
  const prepared = SQBAdapter.transformRequest(ctx.request);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/sqb",
3
- "version": "0.26.3",
3
+ "version": "0.26.4",
4
4
  "description": "Opra SQB adapter package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -37,7 +37,7 @@
37
37
  "ts-gems": "^2.5.0"
38
38
  },
39
39
  "peerDependencies": {
40
- "@opra/core": "^0.26.3",
40
+ "@opra/core": "^0.26.4",
41
41
  "@sqb/connect": ">= 4.9.0"
42
42
  },
43
43
  "type": "module",
@@ -1,5 +1,5 @@
1
1
  import { Maybe, Type } from 'ts-gems';
2
- import { PartialInput, PartialOutput, RequestContext } from '@opra/core';
2
+ import { ApiService, PartialInput, PartialOutput, RequestContext } from '@opra/core';
3
3
  import { EntityInput, Repository, SqbClient, SqbConnection } from '@sqb/connect';
4
4
  export declare namespace SqbEntityService {
5
5
  interface Options {
@@ -7,9 +7,8 @@ export declare namespace SqbEntityService {
7
7
  defaultLimit?: number;
8
8
  }
9
9
  }
10
- export declare class SqbEntityService<T> {
10
+ export declare class SqbEntityService<T> extends ApiService {
11
11
  readonly typeClass: Type<T>;
12
- context: RequestContext;
13
12
  defaultLimit: number;
14
13
  db?: SqbClient | SqbConnection;
15
14
  constructor(typeClass: Type<T>, options?: SqbEntityService.Options);
@@ -24,7 +23,7 @@ export declare class SqbEntityService<T> {
24
23
  update(keyValue: any, data: EntityInput<T>, options?: Repository.UpdateOptions): Promise<Maybe<PartialOutput<T>>>;
25
24
  updateMany(data: PartialInput<T>, options?: Repository.UpdateManyOptions): Promise<number>;
26
25
  with(context: RequestContext, db?: SqbClient | SqbConnection): SqbEntityService<T>;
27
- forContext(context: RequestContext, db?: SqbClient | SqbConnection): SqbEntityService<T>;
26
+ forContext(context: RequestContext, db?: SqbClient | SqbConnection): typeof this;
28
27
  protected _onError(error: unknown): Promise<void>;
29
28
  protected getConnection(): SqbConnection | SqbClient | Promise<SqbConnection | SqbClient>;
30
29
  protected onError?(error: unknown): void | Promise<void>;