@opra/sqb 0.31.0 → 0.31.2

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.
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SqbCollection = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@opra/common");
6
4
  const sqb_adapter_js_1 = require("./sqb-adapter.js");
7
5
  // noinspection TypeScriptAbstractClassConstructorCanBeMadeProtected
8
6
  class SqbCollection {
@@ -80,24 +78,3 @@ class SqbCollection {
80
78
  }
81
79
  }
82
80
  exports.SqbCollection = SqbCollection;
83
- tslib_1.__decorate([
84
- common_1.Collection.Create()
85
- ], SqbCollection.prototype, "create", null);
86
- tslib_1.__decorate([
87
- common_1.Collection.Delete()
88
- ], SqbCollection.prototype, "delete", null);
89
- tslib_1.__decorate([
90
- common_1.Collection.DeleteMany()
91
- ], SqbCollection.prototype, "deleteMany", null);
92
- tslib_1.__decorate([
93
- common_1.Collection.Get()
94
- ], SqbCollection.prototype, "get", null);
95
- tslib_1.__decorate([
96
- common_1.Collection.Update()
97
- ], SqbCollection.prototype, "update", null);
98
- tslib_1.__decorate([
99
- common_1.Collection.UpdateMany()
100
- ], SqbCollection.prototype, "updateMany", null);
101
- tslib_1.__decorate([
102
- common_1.Collection.FindMany()
103
- ], SqbCollection.prototype, "findMany", null);
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SqbEntityServiceBase = void 0;
4
+ const core_1 = require("@opra/core");
5
+ const connect_1 = require("@sqb/connect");
6
+ class SqbEntityServiceBase extends core_1.ApiService {
7
+ constructor(typeClass, options) {
8
+ super();
9
+ this.typeClass = typeClass;
10
+ const metadata = connect_1.EntityMetadata.get(typeClass);
11
+ if (!metadata)
12
+ throw new TypeError(`Class ${typeClass} is not decorated with $Entity() decorator`);
13
+ this.db = options?.db;
14
+ this.defaultLimit = options?.defaultLimit || 10;
15
+ }
16
+ async _count(options) {
17
+ const conn = await this.getConnection();
18
+ const repo = conn.getRepository(this.typeClass);
19
+ try {
20
+ return await repo.count(options);
21
+ }
22
+ catch (e) {
23
+ await this._onError(e);
24
+ throw e;
25
+ }
26
+ }
27
+ async _create(data, options) {
28
+ const conn = await this.getConnection();
29
+ const repo = conn.getRepository(this.typeClass);
30
+ let out;
31
+ try {
32
+ out = await repo.create(data, options);
33
+ }
34
+ catch (e) {
35
+ await this._onError(e);
36
+ throw e;
37
+ }
38
+ if (out && this.transformData)
39
+ out = this.transformData(out);
40
+ if (!out)
41
+ throw new Error('"create" endpoint returned no result!');
42
+ return out;
43
+ }
44
+ async _delete(keyValue, options) {
45
+ const conn = await this.getConnection();
46
+ const repo = conn.getRepository(this.typeClass);
47
+ try {
48
+ return await repo.delete(keyValue, options) ? 1 : 0;
49
+ }
50
+ catch (e) {
51
+ await this._onError(e);
52
+ throw e;
53
+ }
54
+ }
55
+ async _deleteMany(options) {
56
+ const conn = await this.getConnection();
57
+ const repo = conn.getRepository(this.typeClass);
58
+ try {
59
+ return await repo.deleteMany(options);
60
+ }
61
+ catch (e) {
62
+ await this._onError(e);
63
+ throw e;
64
+ }
65
+ }
66
+ async _find(keyValue, options) {
67
+ const conn = await this.getConnection();
68
+ const repo = conn.getRepository(this.typeClass);
69
+ let out;
70
+ try {
71
+ out = await repo.find(keyValue, options);
72
+ }
73
+ catch (e) {
74
+ await this._onError(e);
75
+ throw e;
76
+ }
77
+ if (out && this.transformData)
78
+ out = this.transformData(out);
79
+ return out;
80
+ }
81
+ async _findOne(options) {
82
+ const conn = await this.getConnection();
83
+ const repo = conn.getRepository(this.typeClass);
84
+ let out;
85
+ try {
86
+ out = await repo.findOne(options);
87
+ }
88
+ catch (e) {
89
+ await this._onError(e);
90
+ throw e;
91
+ }
92
+ if (out && this.transformData)
93
+ out = this.transformData(out);
94
+ return out;
95
+ }
96
+ async _findMany(options) {
97
+ const conn = await this.getConnection();
98
+ const repo = conn.getRepository(this.typeClass);
99
+ let items;
100
+ try {
101
+ items = await repo.findMany(options);
102
+ }
103
+ catch (e) {
104
+ await this._onError(e);
105
+ throw e;
106
+ }
107
+ if (items.length && this.transformData) {
108
+ const newItems = [];
109
+ for (const item of items) {
110
+ const v = this.transformData(item);
111
+ if (v)
112
+ newItems.push(v);
113
+ }
114
+ return newItems;
115
+ }
116
+ return items;
117
+ }
118
+ async _exists(options) {
119
+ const conn = await this.getConnection();
120
+ const repo = conn.getRepository(this.typeClass);
121
+ try {
122
+ return await repo.exists(options);
123
+ }
124
+ catch (e) {
125
+ await this._onError(e);
126
+ throw e;
127
+ }
128
+ }
129
+ async _update(keyValue, data, options) {
130
+ const conn = await this.getConnection();
131
+ const repo = conn.getRepository(this.typeClass);
132
+ let out;
133
+ try {
134
+ out = await repo.update(keyValue, data, options);
135
+ }
136
+ catch (e) {
137
+ await this._onError(e);
138
+ throw e;
139
+ }
140
+ if (out && this.transformData)
141
+ out = this.transformData(out);
142
+ return out;
143
+ }
144
+ async _updateMany(data, options) {
145
+ const conn = await this.getConnection();
146
+ const repo = conn.getRepository(this.typeClass);
147
+ try {
148
+ return await repo.updateMany(data, options);
149
+ }
150
+ catch (e) {
151
+ await this._onError(e);
152
+ throw e;
153
+ }
154
+ }
155
+ forContext(context, db) {
156
+ const instance = super.forContext(context);
157
+ instance.db = db || this.db;
158
+ return instance;
159
+ }
160
+ async _onError(error) {
161
+ if (this.onError)
162
+ await this.onError(error);
163
+ }
164
+ getConnection() {
165
+ if (!this.context)
166
+ throw new Error(`Context not set!`);
167
+ if (!this.db)
168
+ throw new Error(`Database not set!`);
169
+ return this.db;
170
+ }
171
+ }
172
+ exports.SqbEntityServiceBase = SqbEntityServiceBase;
@@ -1,175 +1,41 @@
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");
5
- const connect_1 = require("@sqb/connect");
6
- class SqbEntityService extends core_1.ApiService {
4
+ const sqb_entity_service_base_js_1 = require("./sqb-entity-service-base.js");
5
+ class SqbEntityService extends sqb_entity_service_base_js_1.SqbEntityServiceBase {
7
6
  constructor(typeClass, options) {
8
- super();
7
+ super(typeClass, options);
9
8
  this.typeClass = typeClass;
10
- const metadata = connect_1.EntityMetadata.get(typeClass);
11
- if (!metadata)
12
- throw new TypeError(`Class ${typeClass} is not decorated with $Entity() decorator`);
13
- this.db = options?.db;
14
- this.defaultLimit = options?.defaultLimit || 10;
15
9
  }
16
10
  async count(options) {
17
- const conn = await this.getConnection();
18
- const repo = conn.getRepository(this.typeClass);
19
- try {
20
- return await repo.count(options);
21
- }
22
- catch (e) {
23
- await this._onError(e);
24
- throw e;
25
- }
11
+ return super._count(options);
26
12
  }
27
13
  async create(data, options) {
28
- const conn = await this.getConnection();
29
- const repo = conn.getRepository(this.typeClass);
30
- let out;
31
- try {
32
- out = await repo.create(data, options);
33
- }
34
- catch (e) {
35
- await this._onError(e);
36
- throw e;
37
- }
38
- if (out && this.transformData)
39
- out = this.transformData(out);
40
- if (!out)
41
- throw new Error('"create" endpoint returned no result!');
42
- return out;
14
+ return super._create(data, options);
43
15
  }
44
16
  async delete(keyValue, options) {
45
- const conn = await this.getConnection();
46
- const repo = conn.getRepository(this.typeClass);
47
- try {
48
- return await repo.delete(keyValue, options) ? 1 : 0;
49
- }
50
- catch (e) {
51
- await this._onError(e);
52
- throw e;
53
- }
17
+ return super._delete(keyValue, options);
54
18
  }
55
19
  async deleteMany(options) {
56
- const conn = await this.getConnection();
57
- const repo = conn.getRepository(this.typeClass);
58
- try {
59
- return await repo.deleteMany(options);
60
- }
61
- catch (e) {
62
- await this._onError(e);
63
- throw e;
64
- }
20
+ return super._deleteMany(options);
65
21
  }
66
22
  async find(keyValue, options) {
67
- const conn = await this.getConnection();
68
- const repo = conn.getRepository(this.typeClass);
69
- let out;
70
- try {
71
- out = await repo.find(keyValue, options);
72
- }
73
- catch (e) {
74
- await this._onError(e);
75
- throw e;
76
- }
77
- if (out && this.transformData)
78
- out = this.transformData(out);
79
- return out;
23
+ return super._find(keyValue, options);
80
24
  }
81
25
  async findOne(options) {
82
- const conn = await this.getConnection();
83
- const repo = conn.getRepository(this.typeClass);
84
- let out;
85
- try {
86
- out = await repo.findOne(options);
87
- }
88
- catch (e) {
89
- await this._onError(e);
90
- throw e;
91
- }
92
- if (out && this.transformData)
93
- out = this.transformData(out);
94
- return out;
26
+ return super._findOne(options);
95
27
  }
96
28
  async findMany(options) {
97
- const conn = await this.getConnection();
98
- const repo = conn.getRepository(this.typeClass);
99
- let items;
100
- try {
101
- items = await repo.findMany(options);
102
- }
103
- catch (e) {
104
- await this._onError(e);
105
- throw e;
106
- }
107
- if (items.length && this.transformData) {
108
- const newItems = [];
109
- for (const item of items) {
110
- const v = this.transformData(item);
111
- if (v)
112
- newItems.push(v);
113
- }
114
- return newItems;
115
- }
116
- return items;
29
+ return super._findMany(options);
117
30
  }
118
31
  async exists(options) {
119
- const conn = await this.getConnection();
120
- const repo = conn.getRepository(this.typeClass);
121
- try {
122
- return await repo.exists(options);
123
- }
124
- catch (e) {
125
- await this._onError(e);
126
- throw e;
127
- }
32
+ return super._exists(options);
128
33
  }
129
34
  async update(keyValue, data, options) {
130
- const conn = await this.getConnection();
131
- const repo = conn.getRepository(this.typeClass);
132
- let out;
133
- try {
134
- out = await repo.update(keyValue, data, options);
135
- }
136
- catch (e) {
137
- await this._onError(e);
138
- throw e;
139
- }
140
- if (out && this.transformData)
141
- out = this.transformData(out);
142
- return out;
35
+ return super._update(keyValue, data, options);
143
36
  }
144
37
  async updateMany(data, options) {
145
- const conn = await this.getConnection();
146
- const repo = conn.getRepository(this.typeClass);
147
- try {
148
- return await repo.updateMany(data, options);
149
- }
150
- catch (e) {
151
- await this._onError(e);
152
- throw e;
153
- }
154
- }
155
- with(context, db) {
156
- return this.forContext(context, db);
157
- }
158
- forContext(context, db) {
159
- const instance = super.forContext(context);
160
- instance.db = db || this.db;
161
- return instance;
162
- }
163
- async _onError(error) {
164
- if (this.onError)
165
- await this.onError(error);
166
- }
167
- getConnection() {
168
- if (!this.context)
169
- throw new Error(`Context not set!`);
170
- if (!this.db)
171
- throw new Error(`Database not set!`);
172
- return this.db;
38
+ return super._updateMany(data, options);
173
39
  }
174
40
  }
175
41
  exports.SqbEntityService = SqbEntityService;
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SqbSingleton = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@opra/common");
6
4
  const sqb_adapter_js_1 = require("./sqb-adapter.js");
7
5
  class SqbSingleton {
8
6
  async create(ctx) {
@@ -44,15 +42,3 @@ class SqbSingleton {
44
42
  }
45
43
  }
46
44
  exports.SqbSingleton = SqbSingleton;
47
- tslib_1.__decorate([
48
- common_1.Singleton.Create()
49
- ], SqbSingleton.prototype, "create", null);
50
- tslib_1.__decorate([
51
- common_1.Singleton.Delete()
52
- ], SqbSingleton.prototype, "delete", null);
53
- tslib_1.__decorate([
54
- common_1.Singleton.Get()
55
- ], SqbSingleton.prototype, "get", null);
56
- tslib_1.__decorate([
57
- common_1.Singleton.Update()
58
- ], SqbSingleton.prototype, "update", null);
@@ -1,5 +1,3 @@
1
- import { __decorate } from "tslib";
2
- import { Collection } from '@opra/common';
3
1
  import { SQBAdapter } from './sqb-adapter.js';
4
2
  // noinspection TypeScriptAbstractClassConstructorCanBeMadeProtected
5
3
  export class SqbCollection {
@@ -76,24 +74,3 @@ export class SqbCollection {
76
74
  return (this.onPrepare && await this.onPrepare(ctx, prepared)) || prepared;
77
75
  }
78
76
  }
79
- __decorate([
80
- Collection.Create()
81
- ], SqbCollection.prototype, "create", null);
82
- __decorate([
83
- Collection.Delete()
84
- ], SqbCollection.prototype, "delete", null);
85
- __decorate([
86
- Collection.DeleteMany()
87
- ], SqbCollection.prototype, "deleteMany", null);
88
- __decorate([
89
- Collection.Get()
90
- ], SqbCollection.prototype, "get", null);
91
- __decorate([
92
- Collection.Update()
93
- ], SqbCollection.prototype, "update", null);
94
- __decorate([
95
- Collection.UpdateMany()
96
- ], SqbCollection.prototype, "updateMany", null);
97
- __decorate([
98
- Collection.FindMany()
99
- ], SqbCollection.prototype, "findMany", null);
@@ -0,0 +1,168 @@
1
+ import { ApiService } from '@opra/core';
2
+ import { EntityMetadata } from '@sqb/connect';
3
+ export class SqbEntityServiceBase extends ApiService {
4
+ constructor(typeClass, options) {
5
+ super();
6
+ this.typeClass = typeClass;
7
+ const metadata = EntityMetadata.get(typeClass);
8
+ if (!metadata)
9
+ throw new TypeError(`Class ${typeClass} is not decorated with $Entity() decorator`);
10
+ this.db = options?.db;
11
+ this.defaultLimit = options?.defaultLimit || 10;
12
+ }
13
+ async _count(options) {
14
+ const conn = await this.getConnection();
15
+ const repo = conn.getRepository(this.typeClass);
16
+ try {
17
+ return await repo.count(options);
18
+ }
19
+ catch (e) {
20
+ await this._onError(e);
21
+ throw e;
22
+ }
23
+ }
24
+ async _create(data, options) {
25
+ const conn = await this.getConnection();
26
+ const repo = conn.getRepository(this.typeClass);
27
+ let out;
28
+ try {
29
+ out = await repo.create(data, options);
30
+ }
31
+ catch (e) {
32
+ await this._onError(e);
33
+ throw e;
34
+ }
35
+ if (out && this.transformData)
36
+ out = this.transformData(out);
37
+ if (!out)
38
+ throw new Error('"create" endpoint returned no result!');
39
+ return out;
40
+ }
41
+ async _delete(keyValue, options) {
42
+ const conn = await this.getConnection();
43
+ const repo = conn.getRepository(this.typeClass);
44
+ try {
45
+ return await repo.delete(keyValue, options) ? 1 : 0;
46
+ }
47
+ catch (e) {
48
+ await this._onError(e);
49
+ throw e;
50
+ }
51
+ }
52
+ async _deleteMany(options) {
53
+ const conn = await this.getConnection();
54
+ const repo = conn.getRepository(this.typeClass);
55
+ try {
56
+ return await repo.deleteMany(options);
57
+ }
58
+ catch (e) {
59
+ await this._onError(e);
60
+ throw e;
61
+ }
62
+ }
63
+ async _find(keyValue, options) {
64
+ const conn = await this.getConnection();
65
+ const repo = conn.getRepository(this.typeClass);
66
+ let out;
67
+ try {
68
+ out = await repo.find(keyValue, options);
69
+ }
70
+ catch (e) {
71
+ await this._onError(e);
72
+ throw e;
73
+ }
74
+ if (out && this.transformData)
75
+ out = this.transformData(out);
76
+ return out;
77
+ }
78
+ async _findOne(options) {
79
+ const conn = await this.getConnection();
80
+ const repo = conn.getRepository(this.typeClass);
81
+ let out;
82
+ try {
83
+ out = await repo.findOne(options);
84
+ }
85
+ catch (e) {
86
+ await this._onError(e);
87
+ throw e;
88
+ }
89
+ if (out && this.transformData)
90
+ out = this.transformData(out);
91
+ return out;
92
+ }
93
+ async _findMany(options) {
94
+ const conn = await this.getConnection();
95
+ const repo = conn.getRepository(this.typeClass);
96
+ let items;
97
+ try {
98
+ items = await repo.findMany(options);
99
+ }
100
+ catch (e) {
101
+ await this._onError(e);
102
+ throw e;
103
+ }
104
+ if (items.length && this.transformData) {
105
+ const newItems = [];
106
+ for (const item of items) {
107
+ const v = this.transformData(item);
108
+ if (v)
109
+ newItems.push(v);
110
+ }
111
+ return newItems;
112
+ }
113
+ return items;
114
+ }
115
+ async _exists(options) {
116
+ const conn = await this.getConnection();
117
+ const repo = conn.getRepository(this.typeClass);
118
+ try {
119
+ return await repo.exists(options);
120
+ }
121
+ catch (e) {
122
+ await this._onError(e);
123
+ throw e;
124
+ }
125
+ }
126
+ async _update(keyValue, data, options) {
127
+ const conn = await this.getConnection();
128
+ const repo = conn.getRepository(this.typeClass);
129
+ let out;
130
+ try {
131
+ out = await repo.update(keyValue, data, options);
132
+ }
133
+ catch (e) {
134
+ await this._onError(e);
135
+ throw e;
136
+ }
137
+ if (out && this.transformData)
138
+ out = this.transformData(out);
139
+ return out;
140
+ }
141
+ async _updateMany(data, options) {
142
+ const conn = await this.getConnection();
143
+ const repo = conn.getRepository(this.typeClass);
144
+ try {
145
+ return await repo.updateMany(data, options);
146
+ }
147
+ catch (e) {
148
+ await this._onError(e);
149
+ throw e;
150
+ }
151
+ }
152
+ forContext(context, db) {
153
+ const instance = super.forContext(context);
154
+ instance.db = db || this.db;
155
+ return instance;
156
+ }
157
+ async _onError(error) {
158
+ if (this.onError)
159
+ await this.onError(error);
160
+ }
161
+ getConnection() {
162
+ if (!this.context)
163
+ throw new Error(`Context not set!`);
164
+ if (!this.db)
165
+ throw new Error(`Database not set!`);
166
+ return this.db;
167
+ }
168
+ }
@@ -1,171 +1,37 @@
1
- import { ApiService } from '@opra/core';
2
- import { EntityMetadata } from '@sqb/connect';
3
- export class SqbEntityService extends ApiService {
1
+ import { SqbEntityServiceBase } from './sqb-entity-service-base.js';
2
+ export class SqbEntityService extends SqbEntityServiceBase {
4
3
  constructor(typeClass, options) {
5
- super();
4
+ super(typeClass, options);
6
5
  this.typeClass = typeClass;
7
- const metadata = EntityMetadata.get(typeClass);
8
- if (!metadata)
9
- throw new TypeError(`Class ${typeClass} is not decorated with $Entity() decorator`);
10
- this.db = options?.db;
11
- this.defaultLimit = options?.defaultLimit || 10;
12
6
  }
13
7
  async count(options) {
14
- const conn = await this.getConnection();
15
- const repo = conn.getRepository(this.typeClass);
16
- try {
17
- return await repo.count(options);
18
- }
19
- catch (e) {
20
- await this._onError(e);
21
- throw e;
22
- }
8
+ return super._count(options);
23
9
  }
24
10
  async create(data, options) {
25
- const conn = await this.getConnection();
26
- const repo = conn.getRepository(this.typeClass);
27
- let out;
28
- try {
29
- out = await repo.create(data, options);
30
- }
31
- catch (e) {
32
- await this._onError(e);
33
- throw e;
34
- }
35
- if (out && this.transformData)
36
- out = this.transformData(out);
37
- if (!out)
38
- throw new Error('"create" endpoint returned no result!');
39
- return out;
11
+ return super._create(data, options);
40
12
  }
41
13
  async delete(keyValue, options) {
42
- const conn = await this.getConnection();
43
- const repo = conn.getRepository(this.typeClass);
44
- try {
45
- return await repo.delete(keyValue, options) ? 1 : 0;
46
- }
47
- catch (e) {
48
- await this._onError(e);
49
- throw e;
50
- }
14
+ return super._delete(keyValue, options);
51
15
  }
52
16
  async deleteMany(options) {
53
- const conn = await this.getConnection();
54
- const repo = conn.getRepository(this.typeClass);
55
- try {
56
- return await repo.deleteMany(options);
57
- }
58
- catch (e) {
59
- await this._onError(e);
60
- throw e;
61
- }
17
+ return super._deleteMany(options);
62
18
  }
63
19
  async find(keyValue, options) {
64
- const conn = await this.getConnection();
65
- const repo = conn.getRepository(this.typeClass);
66
- let out;
67
- try {
68
- out = await repo.find(keyValue, options);
69
- }
70
- catch (e) {
71
- await this._onError(e);
72
- throw e;
73
- }
74
- if (out && this.transformData)
75
- out = this.transformData(out);
76
- return out;
20
+ return super._find(keyValue, options);
77
21
  }
78
22
  async findOne(options) {
79
- const conn = await this.getConnection();
80
- const repo = conn.getRepository(this.typeClass);
81
- let out;
82
- try {
83
- out = await repo.findOne(options);
84
- }
85
- catch (e) {
86
- await this._onError(e);
87
- throw e;
88
- }
89
- if (out && this.transformData)
90
- out = this.transformData(out);
91
- return out;
23
+ return super._findOne(options);
92
24
  }
93
25
  async findMany(options) {
94
- const conn = await this.getConnection();
95
- const repo = conn.getRepository(this.typeClass);
96
- let items;
97
- try {
98
- items = await repo.findMany(options);
99
- }
100
- catch (e) {
101
- await this._onError(e);
102
- throw e;
103
- }
104
- if (items.length && this.transformData) {
105
- const newItems = [];
106
- for (const item of items) {
107
- const v = this.transformData(item);
108
- if (v)
109
- newItems.push(v);
110
- }
111
- return newItems;
112
- }
113
- return items;
26
+ return super._findMany(options);
114
27
  }
115
28
  async exists(options) {
116
- const conn = await this.getConnection();
117
- const repo = conn.getRepository(this.typeClass);
118
- try {
119
- return await repo.exists(options);
120
- }
121
- catch (e) {
122
- await this._onError(e);
123
- throw e;
124
- }
29
+ return super._exists(options);
125
30
  }
126
31
  async update(keyValue, data, options) {
127
- const conn = await this.getConnection();
128
- const repo = conn.getRepository(this.typeClass);
129
- let out;
130
- try {
131
- out = await repo.update(keyValue, data, options);
132
- }
133
- catch (e) {
134
- await this._onError(e);
135
- throw e;
136
- }
137
- if (out && this.transformData)
138
- out = this.transformData(out);
139
- return out;
32
+ return super._update(keyValue, data, options);
140
33
  }
141
34
  async updateMany(data, options) {
142
- const conn = await this.getConnection();
143
- const repo = conn.getRepository(this.typeClass);
144
- try {
145
- return await repo.updateMany(data, options);
146
- }
147
- catch (e) {
148
- await this._onError(e);
149
- throw e;
150
- }
151
- }
152
- with(context, db) {
153
- return this.forContext(context, db);
154
- }
155
- forContext(context, db) {
156
- const instance = super.forContext(context);
157
- instance.db = db || this.db;
158
- return instance;
159
- }
160
- async _onError(error) {
161
- if (this.onError)
162
- await this.onError(error);
163
- }
164
- getConnection() {
165
- if (!this.context)
166
- throw new Error(`Context not set!`);
167
- if (!this.db)
168
- throw new Error(`Database not set!`);
169
- return this.db;
35
+ return super._updateMany(data, options);
170
36
  }
171
37
  }
@@ -1,5 +1,3 @@
1
- import { __decorate } from "tslib";
2
- import { Singleton } from '@opra/common';
3
1
  import { SQBAdapter } from './sqb-adapter.js';
4
2
  export class SqbSingleton {
5
3
  async create(ctx) {
@@ -40,15 +38,3 @@ export class SqbSingleton {
40
38
  return (this.onPrepare && await this.onPrepare(ctx, prepared)) || prepared;
41
39
  }
42
40
  }
43
- __decorate([
44
- Singleton.Create()
45
- ], SqbSingleton.prototype, "create", null);
46
- __decorate([
47
- Singleton.Delete()
48
- ], SqbSingleton.prototype, "delete", null);
49
- __decorate([
50
- Singleton.Get()
51
- ], SqbSingleton.prototype, "get", null);
52
- __decorate([
53
- Singleton.Update()
54
- ], SqbSingleton.prototype, "update", null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/sqb",
3
- "version": "0.31.0",
3
+ "version": "0.31.2",
4
4
  "description": "Opra SQB adapter package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  "ts-gems": "^2.5.0"
40
40
  },
41
41
  "peerDependencies": {
42
- "@opra/core": "^0.31.0",
42
+ "@opra/core": "^0.31.2",
43
43
  "@sqb/connect": ">= 4.9.0"
44
44
  },
45
45
  "type": "module",
@@ -0,0 +1,30 @@
1
+ import { Maybe, Type } from 'ts-gems';
2
+ import { ApiService, PartialInput, PartialOutput, RequestContext } from '@opra/core';
3
+ import { EntityInput, Repository, SqbClient, SqbConnection } from '@sqb/connect';
4
+ export declare namespace SqbEntityServiceBase {
5
+ interface Options {
6
+ db?: SqbClient | SqbConnection;
7
+ defaultLimit?: number;
8
+ }
9
+ }
10
+ export declare class SqbEntityServiceBase<T> extends ApiService {
11
+ readonly typeClass: Type<T>;
12
+ defaultLimit: number;
13
+ db?: SqbClient | SqbConnection;
14
+ constructor(typeClass: Type<T>, options?: SqbEntityServiceBase.Options);
15
+ protected _count(options?: Repository.CountOptions): Promise<number>;
16
+ protected _create(data: PartialInput<T>, options?: Repository.CreateOptions): Promise<PartialOutput<T>>;
17
+ protected _delete(keyValue: any, options?: Repository.DeleteOptions): Promise<number>;
18
+ protected _deleteMany(options?: Repository.DeleteManyOptions): Promise<number>;
19
+ protected _find(keyValue: any, options?: Repository.FindOptions): Promise<Maybe<PartialOutput<T>>>;
20
+ protected _findOne(options?: Repository.FindOneOptions): Promise<Maybe<PartialOutput<T>>>;
21
+ protected _findMany(options?: Repository.FindManyOptions): Promise<PartialOutput<T>[]>;
22
+ protected _exists(options?: Repository.ExistsOptions): Promise<boolean>;
23
+ protected _update(keyValue: any, data: EntityInput<T>, options?: Repository.UpdateOptions): Promise<Maybe<PartialOutput<T>>>;
24
+ protected _updateMany(data: PartialInput<T>, options?: Repository.UpdateManyOptions): Promise<number>;
25
+ forContext(context: RequestContext, db?: SqbClient | SqbConnection): this;
26
+ protected _onError(error: unknown): Promise<void>;
27
+ protected getConnection(): SqbConnection | SqbClient | Promise<SqbConnection | SqbClient>;
28
+ protected onError?(error: unknown): void | Promise<void>;
29
+ protected transformData?(row: PartialOutput<T>): PartialOutput<T>;
30
+ }
@@ -1,16 +1,13 @@
1
1
  import { Maybe, Type } from 'ts-gems';
2
- import { ApiService, PartialInput, PartialOutput, RequestContext } from '@opra/core';
3
- import { EntityInput, Repository, SqbClient, SqbConnection } from '@sqb/connect';
2
+ import { PartialInput, PartialOutput } from '@opra/core';
3
+ import { EntityInput, Repository } from '@sqb/connect';
4
+ import { SqbEntityServiceBase } from './sqb-entity-service-base.js';
4
5
  export declare namespace SqbEntityService {
5
- interface Options {
6
- db?: SqbClient | SqbConnection;
7
- defaultLimit?: number;
6
+ interface Options extends SqbEntityServiceBase.Options {
8
7
  }
9
8
  }
10
- export declare class SqbEntityService<T> extends ApiService {
9
+ export declare class SqbEntityService<T> extends SqbEntityServiceBase<T> {
11
10
  readonly typeClass: Type<T>;
12
- defaultLimit: number;
13
- db?: SqbClient | SqbConnection;
14
11
  constructor(typeClass: Type<T>, options?: SqbEntityService.Options);
15
12
  count(options?: Repository.CountOptions): Promise<number>;
16
13
  create(data: PartialInput<T>, options?: Repository.CreateOptions): Promise<PartialOutput<T>>;
@@ -22,10 +19,4 @@ export declare class SqbEntityService<T> extends ApiService {
22
19
  exists(options?: Repository.ExistsOptions): Promise<boolean>;
23
20
  update(keyValue: any, data: EntityInput<T>, options?: Repository.UpdateOptions): Promise<Maybe<PartialOutput<T>>>;
24
21
  updateMany(data: PartialInput<T>, options?: Repository.UpdateManyOptions): Promise<number>;
25
- with(context: RequestContext, db?: SqbClient | SqbConnection): SqbEntityService<T>;
26
- forContext(context: RequestContext, db?: SqbClient | SqbConnection): this;
27
- protected _onError(error: unknown): Promise<void>;
28
- protected getConnection(): SqbConnection | SqbClient | Promise<SqbConnection | SqbClient>;
29
- protected onError?(error: unknown): void | Promise<void>;
30
- protected transformData?(row: PartialOutput<T>): PartialOutput<T>;
31
22
  }