@opra/sqb 1.0.0-alpha.2 → 1.0.0-alpha.21

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.
@@ -37,27 +37,29 @@ export class SqbSingletonService extends SqbEntityService {
37
37
  * @throws {Error} if an unknown error occurs while creating the resource
38
38
  */
39
39
  async create(input, options) {
40
- const info = {
40
+ const command = {
41
41
  crud: 'create',
42
42
  method: 'create',
43
43
  byId: false,
44
44
  input,
45
45
  options,
46
46
  };
47
- return this._intercept(async () => {
47
+ return this._executeCommand(command, async () => {
48
48
  const primaryFields = EntityMetadata.getPrimaryIndexColumns(this.entityMetadata);
49
- const data = { ...input };
49
+ const data = { ...command.input };
50
50
  if (primaryFields.length > 1) {
51
- if (typeof primaryFields !== 'object')
51
+ if (typeof primaryFields !== 'object') {
52
52
  throw new TypeError(`"${this.entityMetadata.name}" should has multiple primary key fields. So you should provide and object that contains key fields`);
53
+ }
53
54
  for (const field of primaryFields) {
54
55
  data[field.name] = this.id[field.name];
55
56
  }
56
57
  }
57
58
  else
58
59
  data[primaryFields[0].name] = this.id;
59
- return await this._create(data, options);
60
- }, info);
60
+ command.input = data;
61
+ return await this._create(command);
62
+ });
61
63
  }
62
64
  /**
63
65
  * Deletes the singleton record
@@ -66,17 +68,18 @@ export class SqbSingletonService extends SqbEntityService {
66
68
  * @return {Promise<number>} - A Promise that resolves to the number of records deleted
67
69
  */
68
70
  async delete(options) {
69
- const info = {
71
+ const command = {
70
72
  crud: 'delete',
71
73
  method: 'delete',
72
74
  byId: true,
73
75
  documentId: this.id,
74
76
  options,
75
77
  };
76
- return this._intercept(async () => {
77
- const filter = SQBAdapter.parseFilter([await this._getCommonFilter(info), options?.filter]);
78
- return this._delete(this.id, { ...options, filter });
79
- }, info);
78
+ return this._executeCommand(command, async () => {
79
+ const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
80
+ command.options = { ...command.options, filter };
81
+ return this._delete(command);
82
+ });
80
83
  }
81
84
  /**
82
85
  * Checks if the singleton record exists.
@@ -85,17 +88,18 @@ export class SqbSingletonService extends SqbEntityService {
85
88
  * @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
86
89
  */
87
90
  async exists(options) {
88
- const info = {
91
+ const command = {
89
92
  crud: 'read',
90
93
  method: 'exists',
91
94
  byId: true,
92
95
  documentId: this.id,
93
96
  options,
94
97
  };
95
- return this._intercept(async () => {
96
- const filter = SQBAdapter.parseFilter([await this._getCommonFilter(info), options?.filter]);
97
- return this._exists(this.id, { ...options, filter });
98
- }, info);
98
+ return this._executeCommand(command, async () => {
99
+ const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
100
+ command.options = { ...command.options, filter };
101
+ return this._exists(command);
102
+ });
99
103
  }
100
104
  /**
101
105
  * Finds the singleton record. Returns `undefined` if not found
@@ -104,17 +108,18 @@ export class SqbSingletonService extends SqbEntityService {
104
108
  * @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
105
109
  */
106
110
  async find(options) {
107
- const info = {
111
+ const command = {
108
112
  crud: 'read',
109
113
  method: 'findById',
110
114
  byId: true,
111
115
  documentId: this.id,
112
116
  options,
113
117
  };
114
- return this._intercept(async () => {
115
- const filter = SQBAdapter.parseFilter([await this._getCommonFilter(info), options?.filter]);
116
- return this._findById(this.id, { ...options, filter });
117
- }, info);
118
+ return this._executeCommand(command, async () => {
119
+ const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
120
+ command.options = { ...command.options, filter };
121
+ return this._findById(command);
122
+ });
118
123
  }
119
124
  /**
120
125
  * Retrieves the singleton record. Throws error if not found.
@@ -139,7 +144,7 @@ export class SqbSingletonService extends SqbEntityService {
139
144
  * undefined if the document was not found.
140
145
  */
141
146
  async update(input, options) {
142
- const info = {
147
+ const command = {
143
148
  crud: 'update',
144
149
  method: 'update',
145
150
  documentId: this.id,
@@ -147,10 +152,11 @@ export class SqbSingletonService extends SqbEntityService {
147
152
  input,
148
153
  options,
149
154
  };
150
- return this._intercept(async () => {
151
- const filter = SQBAdapter.parseFilter([await this._getCommonFilter(info), options?.filter]);
152
- return this._update(this.id, input, { ...options, filter });
153
- }, info);
155
+ return this._executeCommand(command, async () => {
156
+ const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
157
+ command.options = { ...command.options, filter };
158
+ return this._update(command);
159
+ });
154
160
  }
155
161
  /**
156
162
  * Updates the singleton and returns updated record count
@@ -160,7 +166,7 @@ export class SqbSingletonService extends SqbEntityService {
160
166
  * @returns {Promise<number>} - A promise that resolves to the number of documents modified.
161
167
  */
162
168
  async updateOnly(input, options) {
163
- const info = {
169
+ const command = {
164
170
  crud: 'update',
165
171
  method: 'update',
166
172
  documentId: this.id,
@@ -168,9 +174,10 @@ export class SqbSingletonService extends SqbEntityService {
168
174
  input,
169
175
  options,
170
176
  };
171
- return this._intercept(async () => {
172
- const filter = SQBAdapter.parseFilter([await this._getCommonFilter(info), options?.filter]);
173
- return this._updateOnly(this.id, input, { ...options, filter });
174
- }, info);
177
+ return this._executeCommand(command, async () => {
178
+ const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
179
+ command.options = { ...command.options, filter };
180
+ return this._updateOnly(command);
181
+ });
175
182
  }
176
183
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/sqb",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.21",
4
4
  "description": "Opra SQB adapter package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -17,25 +17,29 @@
17
17
  "build:esm": "tsc -b tsconfig-build-esm.json",
18
18
  "postbuild": "cp README.md package.json ../../LICENSE ../../build/sqb && cp ../../package.cjs.json ../../build/sqb/cjs/package.json",
19
19
  "lint": "eslint . --max-warnings=0",
20
+ "lint:fix": "eslint . --max-warnings=0 --fix",
20
21
  "format": "prettier . --write --log-level=warn",
21
- "test": "jest",
22
- "cover": "jest --collect-coverage",
22
+ "test": "jest --passWithNoTests",
23
+ "cover": "jest --passWithNoTests --collect-coverage",
23
24
  "clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
24
25
  "clean:src": "ts-cleanup -s src --all",
25
26
  "clean:test": "ts-cleanup -s test --all",
26
27
  "clean:dist": "rimraf ../../build/client",
27
28
  "clean:cover": "rimraf ../../coverage/client"
28
29
  },
30
+ "dependencies": {
31
+ "reflect-metadata": "^0.2.2"
32
+ },
29
33
  "devDependencies": {
30
34
  "@faker-js/faker": "^8.4.1",
31
- "@sqb/builder": "^4.12.0",
32
- "@sqb/connect": "^4.12.0",
33
- "@sqb/postgres": "^4.12.0",
34
- "postgresql-client": "^2.11.0",
35
+ "@sqb/builder": "^4.12.1",
36
+ "@sqb/connect": "^4.12.1",
37
+ "@sqb/postgres": "^4.12.1",
38
+ "postgresql-client": "^2.12.0",
35
39
  "ts-gems": "^3.4.0"
36
40
  },
37
41
  "peerDependencies": {
38
- "@opra/core": "^1.0.0-alpha.2",
42
+ "@opra/core": "^1.0.0-alpha.21",
39
43
  "@sqb/connect": ">= 4.10.6"
40
44
  },
41
45
  "type": "module",
@@ -7,7 +7,7 @@ import { SqbEntityService } from './sqb-entity-service.js';
7
7
  export declare namespace SqbCollectionService {
8
8
  interface Options extends SqbEntityService.Options {
9
9
  defaultLimit?: SqbCollectionService<any>['defaultLimit'];
10
- interceptor?: SqbCollectionService<any>['$interceptor'];
10
+ interceptor?: SqbCollectionService<any>['interceptor'];
11
11
  }
12
12
  /**
13
13
  * Represents options for "create" operation
@@ -70,14 +70,14 @@ export declare namespace SqbCollectionService {
70
70
  *
71
71
  * @interface
72
72
  */
73
- interface UpdateOptions extends SqbEntityService.UpdateOptions {
73
+ interface UpdateOptions extends SqbEntityService.UpdateOneOptions {
74
74
  }
75
75
  /**
76
76
  * Represents options for "updateOnly" operation
77
77
  *
78
78
  * @interface
79
79
  */
80
- interface UpdateOnlyOptions extends SqbEntityService.UpdateOptions {
80
+ interface UpdateOnlyOptions extends SqbEntityService.UpdateOneOptions {
81
81
  }
82
82
  /**
83
83
  * Represents options for "updateMany" operation
@@ -163,11 +163,11 @@ export declare abstract class SqbCollectionService<T extends object = object> ex
163
163
  /**
164
164
  * Finds a record by ID.
165
165
  *
166
- * @param {SQBAdapter.Id} id - The ID of the record.
166
+ * @param {SQBAdapter.IdOrIds} id - The ID of the record.
167
167
  * @param {SqbCollectionService.FindOneOptions} [options] - The options for the find query.
168
168
  * @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
169
169
  */
170
- findById(id: SQBAdapter.Id, options?: SqbCollectionService.FindOneOptions): Promise<PartialDTO<T> | undefined>;
170
+ findById(id: SQBAdapter.IdOrIds, options?: SqbCollectionService.FindOneOptions): Promise<PartialDTO<T> | undefined>;
171
171
  /**
172
172
  * Finds a record in the collection that matches the specified options.
173
173
  *
@@ -196,13 +196,13 @@ export declare abstract class SqbCollectionService<T extends object = object> ex
196
196
  /**
197
197
  * Retrieves a records from the collection by its ID. Throws error if not found.
198
198
  *
199
- * @param {SQBAdapter.Id} id - The ID of the document to retrieve.
199
+ * @param {SQBAdapter.IdOrIds} id - The ID of the document to retrieve.
200
200
  * @param {SqbCollectionService.FindOneOptions} [options] - Optional options for the findOne operation.
201
201
  * @returns {Promise<PartialDTO<T>>} - A promise that resolves to the retrieved document,
202
202
  * or rejects with a ResourceNotFoundError if the document does not exist.
203
203
  * @throws {ResourceNotAvailableError} - If the document with the specified ID does not exist.
204
204
  */
205
- get(id: SQBAdapter.Id, options?: SqbCollectionService.FindOneOptions): Promise<PartialDTO<T>>;
205
+ get(id: SQBAdapter.IdOrIds, options?: SqbCollectionService.FindOneOptions): Promise<PartialDTO<T>>;
206
206
  /**
207
207
  * Updates a record with the given id in the collection.
208
208
  *
@@ -221,7 +221,7 @@ export declare abstract class SqbCollectionService<T extends object = object> ex
221
221
  * @param {SqbCollectionService.UpdateOptions} options - The options for updating the document.
222
222
  * @returns {Promise<number>} - A promise that resolves to the number of documents modified.
223
223
  */
224
- updateOnly(id: SQBAdapter.Id, input: PatchDTO<T>, options?: SqbCollectionService.UpdateOnlyOptions): Promise<number>;
224
+ updateOnly(id: SQBAdapter.IdOrIds, input: PatchDTO<T>, options?: SqbCollectionService.UpdateOnlyOptions): Promise<number>;
225
225
  /**
226
226
  * Updates multiple records in the collection based on the specified input and options.
227
227
  *
@@ -1,8 +1,8 @@
1
- import { PartialDTO, PatchDTO, Type } from 'ts-gems';
2
- import { IsObject } from 'valgen';
3
1
  import { ComplexType } from '@opra/common';
4
2
  import { ServiceBase } from '@opra/core';
5
3
  import { EntityMetadata, Repository, SqbClient, SqbConnection } from '@sqb/connect';
4
+ import { PartialDTO, PatchDTO, RequiredSome, StrictOmit, Type } from 'ts-gems';
5
+ import { IsObject } from 'valgen';
6
6
  import { SQBAdapter } from './sqb-adapter.js';
7
7
  /**
8
8
  * @namespace SqbEntityService
@@ -10,10 +10,10 @@ import { SQBAdapter } from './sqb-adapter.js';
10
10
  export declare namespace SqbEntityService {
11
11
  interface Options {
12
12
  db?: SqbEntityService<any>['db'];
13
- resourceName?: SqbEntityService<any>['$resourceName'];
14
- onError?: SqbEntityService<any>['$onError'];
15
- commonFilter?: SqbEntityService<any>['$commonFilter'];
16
- interceptor?: SqbEntityService<any>['$interceptor'];
13
+ resourceName?: SqbEntityService<any>['resourceName'];
14
+ onError?: SqbEntityService<any>['onError'];
15
+ commonFilter?: SqbEntityService<any>['commonFilter'];
16
+ interceptor?: SqbEntityService<any>['interceptor'];
17
17
  }
18
18
  type CrudOp = 'create' | 'read' | 'update' | 'delete';
19
19
  interface CommandInfo {
@@ -85,14 +85,7 @@ export declare namespace SqbEntityService {
85
85
  *
86
86
  * @interface
87
87
  */
88
- interface UpdateOptions extends Repository.UpdateOptions {
89
- }
90
- /**
91
- * Represents options for "updateOnly" operation
92
- *
93
- * @interface
94
- */
95
- interface UpdateOnlyOptions extends Repository.UpdateOptions {
88
+ interface UpdateOneOptions extends Repository.UpdateOptions {
96
89
  }
97
90
  /**
98
91
  * Represents options for "updateMany" operation
@@ -101,6 +94,55 @@ export declare namespace SqbEntityService {
101
94
  */
102
95
  interface UpdateManyOptions extends Repository.UpdateManyOptions {
103
96
  }
97
+ interface CreateCommand extends StrictOmit<RequiredSome<CommandInfo, 'input'>, 'documentId'> {
98
+ crud: 'create';
99
+ options?: CreateOptions;
100
+ }
101
+ interface CountCommand extends StrictOmit<CommandInfo, 'documentId' | 'input'> {
102
+ crud: 'read';
103
+ options?: CountOptions;
104
+ }
105
+ interface DeleteOneCommand extends StrictOmit<CommandInfo, 'input'> {
106
+ crud: 'delete';
107
+ options?: DeleteOptions;
108
+ }
109
+ interface DeleteManyCommand extends StrictOmit<CommandInfo, 'input'> {
110
+ crud: 'delete';
111
+ options?: DeleteManyOptions;
112
+ }
113
+ interface ExistsCommand extends StrictOmit<CommandInfo, 'input'> {
114
+ crud: 'read';
115
+ options?: ExistsOptions;
116
+ }
117
+ interface FindOneCommand extends StrictOmit<CommandInfo, 'input'> {
118
+ crud: 'read';
119
+ options?: FindOneOptions;
120
+ }
121
+ interface FindManyCommand extends StrictOmit<CommandInfo, 'input'> {
122
+ crud: 'read';
123
+ options?: FindManyOptions;
124
+ }
125
+ interface UpdateOneCommand<T> extends CommandInfo {
126
+ crud: 'update';
127
+ input: PatchDTO<T>;
128
+ options?: UpdateOneOptions;
129
+ }
130
+ interface UpdateManyCommand<T> extends CommandInfo {
131
+ crud: 'update';
132
+ input: PatchDTO<T>;
133
+ options?: UpdateManyOptions;
134
+ }
135
+ }
136
+ export interface SqbEntityService {
137
+ /**
138
+ * Interceptor function for handling callback execution with provided arguments.
139
+ * @type Function
140
+ * @param next - The callback function to be intercepted.
141
+ * @param {SqbEntityService.CommandInfo} command - The arguments object containing the following properties:
142
+ * @param _this - The reference to the current object.
143
+ * @returns - The promise that resolves to the result of the callback execution.
144
+ */
145
+ interceptor?(next: () => any, command: SqbEntityService.CommandInfo, _this: any): Promise<any>;
104
146
  }
105
147
  /**
106
148
  * @class SqbEntityService
@@ -111,8 +153,8 @@ export declare class SqbEntityService<T extends object = object> extends Service
111
153
  protected _dataType: ComplexType;
112
154
  protected _dataTypeClass?: Type;
113
155
  protected _entityMetadata?: EntityMetadata;
114
- protected _encoders: Record<string, IsObject.Validator<T>>;
115
- protected _decoder?: IsObject.Validator<T>;
156
+ protected _inputCodecs: Record<string, IsObject.Validator<T>>;
157
+ protected _outputCodecs: Record<string, IsObject.Validator<T>>;
116
158
  /**
117
159
  * Represents a SqbClient or SqbConnection object
118
160
  */
@@ -121,29 +163,20 @@ export declare class SqbEntityService<T extends object = object> extends Service
121
163
  * Represents the name of a resource.
122
164
  * @type {string}
123
165
  */
124
- $resourceName?: string | ((_this: any) => string);
166
+ resourceName?: string | ((_this: any) => string);
125
167
  /**
126
168
  * Represents a common filter function for a service.
127
169
  *
128
170
  * @type {SqbEntityService.Filter | Function}
129
171
  */
130
- $commonFilter?: SQBAdapter.FilterInput | ((args: SqbEntityService.CommandInfo, _this: this) => SQBAdapter.FilterInput | Promise<SQBAdapter.FilterInput> | undefined);
131
- /**
132
- * Interceptor function for handling callback execution with provided arguments.
133
- *
134
- * @param {Function} callback - The callback function to be intercepted.
135
- * @param {SqbEntityService.CommandInfo} info - The arguments object containing the following properties:
136
- * @param {SqbEntityService} _this - The reference to the current object.
137
- * @returns - The promise that resolves to the result of the callback execution.
138
- */
139
- $interceptor?: (callback: () => any, info: SqbEntityService.CommandInfo, _this: any) => Promise<any>;
172
+ commonFilter?: SQBAdapter.FilterInput | ((args: SqbEntityService.CommandInfo, _this: this) => SQBAdapter.FilterInput | Promise<SQBAdapter.FilterInput> | undefined);
140
173
  /**
141
174
  * Callback function for handling errors.
142
175
  *
143
176
  * @param {unknown} error - The error object.
144
177
  * @param {SqbEntityService} _this - The context object.
145
178
  */
146
- $onError?: (error: unknown, _this: any) => void | Promise<void>;
179
+ onError?: (error: unknown, _this: any) => void | Promise<void>;
147
180
  /**
148
181
  * Constructs a new instance
149
182
  *
@@ -178,122 +211,110 @@ export declare class SqbEntityService<T extends object = object> extends Service
178
211
  */
179
212
  getResourceName(): string;
180
213
  /**
181
- * Retrieves the encoder for the specified operation.
214
+ * Retrieves the codec for the specified operation.
182
215
  *
183
216
  * @param operation - The operation to retrieve the encoder for. Valid values are 'create' and 'update'.
184
217
  */
185
- getEncoder(operation: 'create' | 'update'): IsObject.Validator<T>;
218
+ getInputCodec(operation: string): IsObject.Validator<T>;
186
219
  /**
187
- * Retrieves the decoder.
220
+ * Retrieves the codec.
188
221
  */
189
- getDecoder(): IsObject.Validator<T>;
222
+ getOutputCodec(operation: string): IsObject.Validator<T>;
190
223
  /**
191
224
  * Insert a new record into database
192
225
  *
193
- * @param {PartialDTO<T>} input - The input data
194
- * @param {SqbEntityService.CreateOptions} [options] - The options object
195
- * @returns {Promise<PartialDTO<T>>} A promise that resolves to the created resource
196
- * @throws {InternalServerError} if an unknown error occurs while creating the resource
226
+ * @param command
227
+ * @returns - A promise that resolves to the created resource
197
228
  * @protected
198
229
  */
199
- protected _create(input: PartialDTO<T>, options?: SqbEntityService.CreateOptions): Promise<PartialDTO<T>>;
230
+ protected _create(command: SqbEntityService.CreateCommand): Promise<PartialDTO<T>>;
200
231
  /**
201
232
  * Returns the count of records based on the provided options
202
233
  *
203
- * @param {SqbEntityService.CountOptions} options - The options for the count operation.
204
- * @return {Promise<number>} - A promise that resolves to the count of records
234
+ * @param command
235
+ * @return - A promise that resolves to the count of records
205
236
  * @protected
206
237
  */
207
- protected _count(options?: SqbEntityService.CountOptions): Promise<number>;
238
+ protected _count(command: SqbEntityService.CountCommand): Promise<number>;
208
239
  /**
209
240
  * Deletes a record from the collection.
210
241
  *
211
- * @param {SQBAdapter.IdOrIds} id - The ID of the document to delete.
212
- * @param {SqbEntityService.DeleteOptions} [options] - Optional delete options.
213
- * @return {Promise<number>} - A Promise that resolves to the number of documents deleted.
242
+ * @param command
243
+ * @return - A Promise that resolves to the number of documents deleted.
214
244
  * @protected
215
245
  */
216
- protected _delete(id: SQBAdapter.IdOrIds, options?: SqbEntityService.DeleteOptions): Promise<number>;
246
+ protected _delete(command: SqbEntityService.DeleteOneCommand): Promise<number>;
217
247
  /**
218
248
  * Deletes multiple documents from the collection that meet the specified filter criteria.
219
249
  *
220
- * @param {SqbEntityService.DeleteManyOptions} options - The options for the delete operation.
221
- * @return {Promise<number>} - A promise that resolves to the number of documents deleted.
250
+ * @param command
251
+ * @return - A promise that resolves to the number of documents deleted.
222
252
  * @protected
223
253
  */
224
- protected _deleteMany(options?: SqbEntityService.DeleteManyOptions): Promise<number>;
254
+ protected _deleteMany(command: SqbEntityService.DeleteManyCommand): Promise<number>;
225
255
  /**
226
256
  * Checks if a record with the given id exists.
227
257
  *
228
- * @param {SQBAdapter.IdOrIds} id - The id of the object to check.
229
- * @param {SqbEntityService.ExistsOptions} [options] - The options for the query (optional).
230
- * @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
258
+ * @param command
231
259
  * @protected
232
260
  */
233
- protected _exists(id: SQBAdapter.IdOrIds, options?: SqbEntityService.ExistsOptions): Promise<boolean>;
261
+ protected _exists(command: SqbEntityService.ExistsCommand): Promise<boolean>;
234
262
  /**
235
263
  * Checks if a record with the given arguments exists.
236
264
  *
237
- * @param {SqbEntityService.ExistsOneOptions} [options] - The options for the query (optional).
238
- * @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
265
+ * @param command
266
+ * @return - A Promise that resolves to a boolean indicating whether the record exists or not.
239
267
  * @protected
240
268
  */
241
- protected _existsOne(options?: SqbEntityService.ExistsOptions): Promise<boolean>;
269
+ protected _existsOne(command: SqbEntityService.ExistsCommand): Promise<boolean>;
242
270
  /**
243
271
  * Finds a record by ID.
244
272
  *
245
- * @param {SQBAdapter.Id} id - The ID of the record.
246
- * @param {SqbEntityService.FindOneOptions} [options] - The options for the find query.
247
- * @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
273
+ * @param command
274
+ * @return - A promise resolving to the found document, or undefined if not found.
248
275
  * @protected
249
276
  */
250
- protected _findById(id: SQBAdapter.Id, options?: SqbEntityService.FindOneOptions): Promise<PartialDTO<T> | undefined>;
277
+ protected _findById(command: SqbEntityService.FindOneCommand): Promise<PartialDTO<T> | undefined>;
251
278
  /**
252
279
  * Finds a record in the collection that matches the specified options.
253
280
  *
254
- * @param {SqbEntityService.FindOneOptions} [options] - The options for the query.
255
- * @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
281
+ * @param command
282
+ * @return - A promise that resolves with the found document or undefined if no document is found.
256
283
  * @protected
257
284
  */
258
- protected _findOne(options?: SqbEntityService.FindOneOptions): Promise<PartialDTO<T> | undefined>;
285
+ protected _findOne(command: SqbEntityService.FindOneCommand): Promise<PartialDTO<T> | undefined>;
259
286
  /**
260
287
  * Finds multiple records in collection.
261
288
  *
262
- * @param {SqbEntityService.FindManyOptions} [options] - The options for the find operation.
263
- * @return A Promise that resolves to an array of partial outputs of type T.
289
+ * @param command
290
+ * @return - A Promise that resolves to an array of partial outputs of type T.
264
291
  * @protected
265
292
  */
266
- protected _findMany(options?: SqbEntityService.FindManyOptions): Promise<PartialDTO<T>[]>;
293
+ protected _findMany(command: SqbEntityService.FindManyCommand): Promise<PartialDTO<T>[]>;
267
294
  /**
268
295
  * Updates a record with the given id in the collection.
269
296
  *
270
- * @param {SQBAdapter.IdOrIds} id - The id of the document to update.
271
- * @param {PatchDTO<T>} input - The partial input object containing the fields to update.
272
- * @param {SqbEntityService.UpdateOptions} [options] - The options for the update operation.
273
- * @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the updated document or
274
- * undefined if the document was not found.
297
+ * @param command
298
+ * @returns A promise that resolves to the updated document or undefined if the document was not found.
275
299
  * @protected
276
300
  */
277
- protected _update(id: SQBAdapter.IdOrIds, input: PatchDTO<T>, options?: SqbEntityService.UpdateOptions): Promise<PartialDTO<T> | undefined>;
301
+ protected _update(command: SqbEntityService.UpdateOneCommand<T>): Promise<PartialDTO<T> | undefined>;
278
302
  /**
279
303
  * Updates a record in the collection with the specified ID and returns updated record count
280
304
  *
281
- * @param {any} id - The ID of the document to update.
282
- * @param {PatchDTO<T>} input - The partial input data to update the document with.
283
- * @param {SqbEntityService.UpdateOptions} options - The options for updating the document.
284
- * @returns {Promise<number>} - A promise that resolves to the number of documents modified.
305
+ * @param command
306
+ * @returns - A promise that resolves to the number of documents modified.
285
307
  * @protected
286
308
  */
287
- protected _updateOnly(id: SQBAdapter.IdOrIds, input: PatchDTO<T>, options?: SqbEntityService.UpdateOptions): Promise<boolean>;
309
+ protected _updateOnly(command: SqbEntityService.UpdateOneCommand<T>): Promise<boolean>;
288
310
  /**
289
311
  * Updates multiple records in the collection based on the specified input and options.
290
312
  *
291
- * @param {PatchDTO<T>} input - The partial input to update the documents with.
292
- * @param {SqbEntityService.UpdateManyOptions} options - The options for updating the documents.
293
- * @return {Promise<number>} - A promise that resolves to the number of documents matched and modified.
313
+ * @param command
314
+ * @return - A promise that resolves to the number of documents matched and modified.
294
315
  * @protected
295
316
  */
296
- protected _updateMany(input: PatchDTO<T>, options?: SqbEntityService.UpdateManyOptions): Promise<number>;
317
+ protected _updateMany(command: SqbEntityService.UpdateOneCommand<T>): Promise<number>;
297
318
  /**
298
319
  * Acquires a connection and performs Repository.create operation
299
320
  *
@@ -411,12 +432,5 @@ export declare class SqbEntityService<T extends object = object> extends Service
411
432
  input?: Object;
412
433
  options?: Record<string, any>;
413
434
  }): SQBAdapter.FilterInput | Promise<SQBAdapter.FilterInput> | undefined;
414
- protected _intercept(callback: (...args: any[]) => any, args: {
415
- crud: SqbEntityService.CrudOp;
416
- method: string;
417
- byId: boolean;
418
- documentId?: any;
419
- input?: Object;
420
- options?: Record<string, any>;
421
- }): Promise<any>;
435
+ protected _executeCommand(command: SqbEntityService.CommandInfo, commandFn: () => any): Promise<any>;
422
436
  }
@@ -1,5 +1,5 @@
1
- import { PartialDTO, PatchDTO, Type } from 'ts-gems';
2
1
  import { ColumnFieldMetadata } from '@sqb/connect';
2
+ import { PartialDTO, PatchDTO, Type } from 'ts-gems';
3
3
  import { SQBAdapter } from './sqb-adapter.js';
4
4
  import { SqbEntityService } from './sqb-entity-service.js';
5
5
  /**
@@ -42,14 +42,14 @@ export declare namespace SqbSingletonService {
42
42
  *
43
43
  * @interface
44
44
  */
45
- interface UpdateOptions extends SqbEntityService.UpdateOptions {
45
+ interface UpdateOptions extends SqbEntityService.UpdateOneOptions {
46
46
  }
47
47
  /**
48
48
  * Represents options for "updateOnly" operation
49
49
  *
50
50
  * @interface
51
51
  */
52
- interface UpdateOnlyOptions extends SqbEntityService.UpdateOptions {
52
+ interface UpdateOnlyOptions extends SqbEntityService.UpdateOneOptions {
53
53
  }
54
54
  }
55
55
  /**
@@ -60,9 +60,9 @@ export declare abstract class SqbSingletonService<T extends object = object> ext
60
60
  protected _primaryKeyFields?: ColumnFieldMetadata[];
61
61
  /**
62
62
  * Represents a unique identifier for singleton record
63
- * @property {SQBAdapter.Id}
63
+ * @property {SQBAdapter.IdOrIds}
64
64
  */
65
- id: SQBAdapter.Id;
65
+ id: SQBAdapter.IdOrIds;
66
66
  /**
67
67
  * Constructs a new instance
68
68
  *