@opra/sqb 1.0.0-alpha.9 → 1.0.0-beta.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.
- package/cjs/adapter-utils/parse-filter.js +5 -5
- package/cjs/sqb-adapter.js +4 -4
- package/cjs/sqb-collection-service.js +85 -63
- package/cjs/sqb-entity-service.js +190 -74
- package/cjs/sqb-singleton-service.js +37 -61
- package/esm/adapter-utils/parse-filter.js +4 -4
- package/esm/package.json +3 -0
- package/esm/sqb-adapter.js +4 -4
- package/esm/sqb-collection-service.js +85 -63
- package/esm/sqb-entity-service.js +190 -74
- package/esm/sqb-singleton-service.js +37 -61
- package/package.json +27 -37
- package/types/index.d.cts +7 -0
- package/types/sqb-collection-service.d.ts +20 -10
- package/types/sqb-entity-service.d.ts +120 -92
- package/types/sqb-singleton-service.d.ts +13 -11
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import './augmentation/datatype-factory.augmentation.js';
|
|
2
|
+
import './augmentation/mapped-type.augmentation.js';
|
|
3
|
+
import './augmentation/mixin-type.augmentation.js';
|
|
4
|
+
export * from './sqb-adapter.js';
|
|
5
|
+
export * from './sqb-collection-service.js';
|
|
6
|
+
export * from './sqb-entity-service.js';
|
|
7
|
+
export * from './sqb-singleton-service.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PartialDTO, PatchDTO, 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
|
/**
|
|
@@ -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>['
|
|
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.
|
|
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.
|
|
80
|
+
interface UpdateOnlyOptions extends SqbEntityService.UpdateOneOptions {
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* Represents options for "updateMany" operation
|
|
@@ -122,7 +122,17 @@ export declare abstract class SqbCollectionService<T extends object = object> ex
|
|
|
122
122
|
* @returns {Promise<PartialDTO<T>>} A promise that resolves to the created resource
|
|
123
123
|
* @throws {Error} if an unknown error occurs while creating the resource
|
|
124
124
|
*/
|
|
125
|
-
create(input: PartialDTO<T>, options
|
|
125
|
+
create(input: PartialDTO<T>, options: RequiredSome<SqbCollectionService.CreateOptions, 'projection'>): Promise<PartialDTO<T>>;
|
|
126
|
+
create(input: PartialDTO<T>, options?: SqbCollectionService.CreateOptions): Promise<T>;
|
|
127
|
+
/**
|
|
128
|
+
* Creates a new resource
|
|
129
|
+
*
|
|
130
|
+
* @param {PartialDTO<T>} input - The input data
|
|
131
|
+
* @param {SqbCollectionService.CreateOptions} [options] - The options object
|
|
132
|
+
* @returns {Promise<void>} A promise that resolves create operation result
|
|
133
|
+
* @throws {Error} if an unknown error occurs while creating the resource
|
|
134
|
+
*/
|
|
135
|
+
createOnly(input: PartialDTO<T>, options?: SqbCollectionService.CreateOptions): Promise<void>;
|
|
126
136
|
/**
|
|
127
137
|
* Returns the count of records based on the provided options
|
|
128
138
|
*
|
|
@@ -163,11 +173,11 @@ export declare abstract class SqbCollectionService<T extends object = object> ex
|
|
|
163
173
|
/**
|
|
164
174
|
* Finds a record by ID.
|
|
165
175
|
*
|
|
166
|
-
* @param {SQBAdapter.
|
|
176
|
+
* @param {SQBAdapter.IdOrIds} id - The ID of the record.
|
|
167
177
|
* @param {SqbCollectionService.FindOneOptions} [options] - The options for the find query.
|
|
168
178
|
* @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
|
|
169
179
|
*/
|
|
170
|
-
findById(id: SQBAdapter.
|
|
180
|
+
findById(id: SQBAdapter.IdOrIds, options?: SqbCollectionService.FindOneOptions): Promise<PartialDTO<T> | undefined>;
|
|
171
181
|
/**
|
|
172
182
|
* Finds a record in the collection that matches the specified options.
|
|
173
183
|
*
|
|
@@ -196,13 +206,13 @@ export declare abstract class SqbCollectionService<T extends object = object> ex
|
|
|
196
206
|
/**
|
|
197
207
|
* Retrieves a records from the collection by its ID. Throws error if not found.
|
|
198
208
|
*
|
|
199
|
-
* @param {SQBAdapter.
|
|
209
|
+
* @param {SQBAdapter.IdOrIds} id - The ID of the document to retrieve.
|
|
200
210
|
* @param {SqbCollectionService.FindOneOptions} [options] - Optional options for the findOne operation.
|
|
201
211
|
* @returns {Promise<PartialDTO<T>>} - A promise that resolves to the retrieved document,
|
|
202
212
|
* or rejects with a ResourceNotFoundError if the document does not exist.
|
|
203
213
|
* @throws {ResourceNotAvailableError} - If the document with the specified ID does not exist.
|
|
204
214
|
*/
|
|
205
|
-
get(id: SQBAdapter.
|
|
215
|
+
get(id: SQBAdapter.IdOrIds, options?: SqbCollectionService.FindOneOptions): Promise<PartialDTO<T>>;
|
|
206
216
|
/**
|
|
207
217
|
* Updates a record with the given id in the collection.
|
|
208
218
|
*
|
|
@@ -221,7 +231,7 @@ export declare abstract class SqbCollectionService<T extends object = object> ex
|
|
|
221
231
|
* @param {SqbCollectionService.UpdateOptions} options - The options for updating the document.
|
|
222
232
|
* @returns {Promise<number>} - A promise that resolves to the number of documents modified.
|
|
223
233
|
*/
|
|
224
|
-
updateOnly(id: SQBAdapter.
|
|
234
|
+
updateOnly(id: SQBAdapter.IdOrIds, input: PatchDTO<T>, options?: SqbCollectionService.UpdateOnlyOptions): Promise<number>;
|
|
225
235
|
/**
|
|
226
236
|
* Updates multiple records in the collection based on the specified input and options.
|
|
227
237
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ComplexType } from '@opra/common';
|
|
2
|
-
import { ServiceBase } from '@opra/core';
|
|
2
|
+
import { HttpContext, ServiceBase } from '@opra/core';
|
|
3
3
|
import { EntityMetadata, Repository, SqbClient, SqbConnection } from '@sqb/connect';
|
|
4
|
-
import { PartialDTO, PatchDTO, 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
|
|
@@ -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>['
|
|
14
|
-
onError?: SqbEntityService<any>['
|
|
15
|
-
commonFilter?: SqbEntityService<any>['
|
|
16
|
-
interceptor?: SqbEntityService<any>['
|
|
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 {
|
|
@@ -24,6 +24,7 @@ export declare namespace SqbEntityService {
|
|
|
24
24
|
input?: Record<string, any>;
|
|
25
25
|
options?: Record<string, any>;
|
|
26
26
|
}
|
|
27
|
+
type CommonFilter = SQBAdapter.FilterInput | ((args: SqbEntityService.CommandInfo, _this: SqbEntityService<any>) => SQBAdapter.FilterInput | Promise<SQBAdapter.FilterInput> | undefined);
|
|
27
28
|
/**
|
|
28
29
|
* Represents options for "create" operation
|
|
29
30
|
*
|
|
@@ -85,14 +86,7 @@ export declare namespace SqbEntityService {
|
|
|
85
86
|
*
|
|
86
87
|
* @interface
|
|
87
88
|
*/
|
|
88
|
-
interface
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Represents options for "updateOnly" operation
|
|
92
|
-
*
|
|
93
|
-
* @interface
|
|
94
|
-
*/
|
|
95
|
-
interface UpdateOnlyOptions extends Repository.UpdateOptions {
|
|
89
|
+
interface UpdateOneOptions extends Repository.UpdateOptions {
|
|
96
90
|
}
|
|
97
91
|
/**
|
|
98
92
|
* Represents options for "updateMany" operation
|
|
@@ -101,6 +95,56 @@ export declare namespace SqbEntityService {
|
|
|
101
95
|
*/
|
|
102
96
|
interface UpdateManyOptions extends Repository.UpdateManyOptions {
|
|
103
97
|
}
|
|
98
|
+
interface CreateCommand<T> extends StrictOmit<RequiredSome<CommandInfo, 'input'>, 'documentId'> {
|
|
99
|
+
crud: 'create';
|
|
100
|
+
input: PatchDTO<T>;
|
|
101
|
+
options?: CreateOptions;
|
|
102
|
+
}
|
|
103
|
+
interface CountCommand extends StrictOmit<CommandInfo, 'documentId' | 'input'> {
|
|
104
|
+
crud: 'read';
|
|
105
|
+
options?: CountOptions;
|
|
106
|
+
}
|
|
107
|
+
interface DeleteOneCommand extends StrictOmit<CommandInfo, 'input'> {
|
|
108
|
+
crud: 'delete';
|
|
109
|
+
options?: DeleteOptions;
|
|
110
|
+
}
|
|
111
|
+
interface DeleteManyCommand extends StrictOmit<CommandInfo, 'input'> {
|
|
112
|
+
crud: 'delete';
|
|
113
|
+
options?: DeleteManyOptions;
|
|
114
|
+
}
|
|
115
|
+
interface ExistsCommand extends StrictOmit<CommandInfo, 'input'> {
|
|
116
|
+
crud: 'read';
|
|
117
|
+
options?: ExistsOptions;
|
|
118
|
+
}
|
|
119
|
+
interface FindOneCommand extends StrictOmit<CommandInfo, 'input'> {
|
|
120
|
+
crud: 'read';
|
|
121
|
+
options?: FindOneOptions;
|
|
122
|
+
}
|
|
123
|
+
interface FindManyCommand extends StrictOmit<CommandInfo, 'input'> {
|
|
124
|
+
crud: 'read';
|
|
125
|
+
options?: FindManyOptions;
|
|
126
|
+
}
|
|
127
|
+
interface UpdateOneCommand<T> extends CommandInfo {
|
|
128
|
+
crud: 'update';
|
|
129
|
+
input: PatchDTO<T>;
|
|
130
|
+
options?: UpdateOneOptions;
|
|
131
|
+
}
|
|
132
|
+
interface UpdateManyCommand<T> extends CommandInfo {
|
|
133
|
+
crud: 'update';
|
|
134
|
+
input: PatchDTO<T>;
|
|
135
|
+
options?: UpdateManyOptions;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export interface SqbEntityService {
|
|
139
|
+
/**
|
|
140
|
+
* Interceptor function for handling callback execution with provided arguments.
|
|
141
|
+
* @type Function
|
|
142
|
+
* @param next - The callback function to be intercepted.
|
|
143
|
+
* @param {SqbEntityService.CommandInfo} command - The arguments object containing the following properties:
|
|
144
|
+
* @param _this - The reference to the current object.
|
|
145
|
+
* @returns - The promise that resolves to the result of the callback execution.
|
|
146
|
+
*/
|
|
147
|
+
interceptor?(next: () => any, command: SqbEntityService.CommandInfo, _this: any): Promise<any>;
|
|
104
148
|
}
|
|
105
149
|
/**
|
|
106
150
|
* @class SqbEntityService
|
|
@@ -108,7 +152,7 @@ export declare namespace SqbEntityService {
|
|
|
108
152
|
*/
|
|
109
153
|
export declare class SqbEntityService<T extends object = object> extends ServiceBase {
|
|
110
154
|
protected _dataType_: Type | string;
|
|
111
|
-
protected _dataType
|
|
155
|
+
protected _dataType?: ComplexType;
|
|
112
156
|
protected _dataTypeClass?: Type;
|
|
113
157
|
protected _entityMetadata?: EntityMetadata;
|
|
114
158
|
protected _inputCodecs: Record<string, IsObject.Validator<T>>;
|
|
@@ -116,34 +160,25 @@ export declare class SqbEntityService<T extends object = object> extends Service
|
|
|
116
160
|
/**
|
|
117
161
|
* Represents a SqbClient or SqbConnection object
|
|
118
162
|
*/
|
|
119
|
-
db?: (SqbClient | SqbConnection) | ((_this:
|
|
163
|
+
db?: (SqbClient | SqbConnection) | ((_this: this) => SqbClient | SqbConnection);
|
|
120
164
|
/**
|
|
121
165
|
* Represents the name of a resource.
|
|
122
166
|
* @type {string}
|
|
123
167
|
*/
|
|
124
|
-
|
|
168
|
+
resourceName?: string | ((_this: this) => string);
|
|
125
169
|
/**
|
|
126
170
|
* Represents a common filter function for a service.
|
|
127
171
|
*
|
|
128
172
|
* @type {SqbEntityService.Filter | Function}
|
|
129
173
|
*/
|
|
130
|
-
|
|
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>;
|
|
174
|
+
commonFilter?: SqbEntityService.CommonFilter | SqbEntityService.CommonFilter[];
|
|
140
175
|
/**
|
|
141
176
|
* Callback function for handling errors.
|
|
142
177
|
*
|
|
143
178
|
* @param {unknown} error - The error object.
|
|
144
179
|
* @param {SqbEntityService} _this - The context object.
|
|
145
180
|
*/
|
|
146
|
-
|
|
181
|
+
onError?: (error: unknown, _this: any) => void | Promise<void>;
|
|
147
182
|
/**
|
|
148
183
|
* Constructs a new instance
|
|
149
184
|
*
|
|
@@ -170,6 +205,7 @@ export declare class SqbEntityService<T extends object = object> extends Service
|
|
|
170
205
|
* @throws {TypeError} If metadata is not available
|
|
171
206
|
*/
|
|
172
207
|
get entityMetadata(): EntityMetadata;
|
|
208
|
+
for<C extends HttpContext, P extends Partial<this>>(context: C, overwriteProperties?: Nullish<P>, overwriteContext?: Partial<C>): this & Required<P>;
|
|
173
209
|
/**
|
|
174
210
|
* Retrieves the resource name.
|
|
175
211
|
*
|
|
@@ -190,110 +226,106 @@ export declare class SqbEntityService<T extends object = object> extends Service
|
|
|
190
226
|
/**
|
|
191
227
|
* Insert a new record into database
|
|
192
228
|
*
|
|
193
|
-
* @param
|
|
194
|
-
* @
|
|
195
|
-
* @
|
|
196
|
-
|
|
229
|
+
* @param command
|
|
230
|
+
* @returns - A promise that resolves to the created resource
|
|
231
|
+
* @protected
|
|
232
|
+
*/
|
|
233
|
+
protected _create(command: SqbEntityService.CreateCommand<T>): Promise<PartialDTO<T>>;
|
|
234
|
+
/**
|
|
235
|
+
* Insert a new record into database
|
|
236
|
+
*
|
|
237
|
+
* @param command
|
|
238
|
+
* @returns - A promise that resolves to the created resource
|
|
197
239
|
* @protected
|
|
198
240
|
*/
|
|
199
|
-
protected
|
|
241
|
+
protected _createOnly(command: SqbEntityService.CreateCommand<T>): Promise<any>;
|
|
200
242
|
/**
|
|
201
243
|
* Returns the count of records based on the provided options
|
|
202
244
|
*
|
|
203
|
-
* @param
|
|
204
|
-
* @return
|
|
245
|
+
* @param command
|
|
246
|
+
* @return - A promise that resolves to the count of records
|
|
205
247
|
* @protected
|
|
206
248
|
*/
|
|
207
|
-
protected _count(
|
|
249
|
+
protected _count(command: SqbEntityService.CountCommand): Promise<number>;
|
|
208
250
|
/**
|
|
209
251
|
* Deletes a record from the collection.
|
|
210
252
|
*
|
|
211
|
-
* @param
|
|
212
|
-
* @
|
|
213
|
-
* @return {Promise<number>} - A Promise that resolves to the number of documents deleted.
|
|
253
|
+
* @param command
|
|
254
|
+
* @return - A Promise that resolves to the number of documents deleted.
|
|
214
255
|
* @protected
|
|
215
256
|
*/
|
|
216
|
-
protected _delete(
|
|
257
|
+
protected _delete(command: SqbEntityService.DeleteOneCommand): Promise<number>;
|
|
217
258
|
/**
|
|
218
259
|
* Deletes multiple documents from the collection that meet the specified filter criteria.
|
|
219
260
|
*
|
|
220
|
-
* @param
|
|
221
|
-
* @return
|
|
261
|
+
* @param command
|
|
262
|
+
* @return - A promise that resolves to the number of documents deleted.
|
|
222
263
|
* @protected
|
|
223
264
|
*/
|
|
224
|
-
protected _deleteMany(
|
|
265
|
+
protected _deleteMany(command: SqbEntityService.DeleteManyCommand): Promise<number>;
|
|
225
266
|
/**
|
|
226
267
|
* Checks if a record with the given id exists.
|
|
227
268
|
*
|
|
228
|
-
* @param
|
|
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.
|
|
269
|
+
* @param command
|
|
231
270
|
* @protected
|
|
232
271
|
*/
|
|
233
|
-
protected _exists(
|
|
272
|
+
protected _exists(command: SqbEntityService.ExistsCommand): Promise<boolean>;
|
|
234
273
|
/**
|
|
235
274
|
* Checks if a record with the given arguments exists.
|
|
236
275
|
*
|
|
237
|
-
* @param
|
|
238
|
-
* @return
|
|
276
|
+
* @param command
|
|
277
|
+
* @return - A Promise that resolves to a boolean indicating whether the record exists or not.
|
|
239
278
|
* @protected
|
|
240
279
|
*/
|
|
241
|
-
protected _existsOne(
|
|
280
|
+
protected _existsOne(command: SqbEntityService.ExistsCommand): Promise<boolean>;
|
|
242
281
|
/**
|
|
243
282
|
* Finds a record by ID.
|
|
244
283
|
*
|
|
245
|
-
* @param
|
|
246
|
-
* @
|
|
247
|
-
* @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
|
|
284
|
+
* @param command
|
|
285
|
+
* @return - A promise resolving to the found document, or undefined if not found.
|
|
248
286
|
* @protected
|
|
249
287
|
*/
|
|
250
|
-
protected _findById(
|
|
288
|
+
protected _findById(command: SqbEntityService.FindOneCommand): Promise<PartialDTO<T> | undefined>;
|
|
251
289
|
/**
|
|
252
290
|
* Finds a record in the collection that matches the specified options.
|
|
253
291
|
*
|
|
254
|
-
* @param
|
|
255
|
-
* @return
|
|
292
|
+
* @param command
|
|
293
|
+
* @return - A promise that resolves with the found document or undefined if no document is found.
|
|
256
294
|
* @protected
|
|
257
295
|
*/
|
|
258
|
-
protected _findOne(
|
|
296
|
+
protected _findOne(command: SqbEntityService.FindOneCommand): Promise<PartialDTO<T> | undefined>;
|
|
259
297
|
/**
|
|
260
298
|
* Finds multiple records in collection.
|
|
261
299
|
*
|
|
262
|
-
* @param
|
|
263
|
-
* @return A Promise that resolves to an array of partial outputs of type T.
|
|
300
|
+
* @param command
|
|
301
|
+
* @return - A Promise that resolves to an array of partial outputs of type T.
|
|
264
302
|
* @protected
|
|
265
303
|
*/
|
|
266
|
-
protected _findMany(
|
|
304
|
+
protected _findMany(command: SqbEntityService.FindManyCommand): Promise<PartialDTO<T>[]>;
|
|
267
305
|
/**
|
|
268
306
|
* Updates a record with the given id in the collection.
|
|
269
307
|
*
|
|
270
|
-
* @param
|
|
271
|
-
* @
|
|
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.
|
|
308
|
+
* @param command
|
|
309
|
+
* @returns A promise that resolves to the updated document or undefined if the document was not found.
|
|
275
310
|
* @protected
|
|
276
311
|
*/
|
|
277
|
-
protected _update(
|
|
312
|
+
protected _update(command: SqbEntityService.UpdateOneCommand<T>): Promise<PartialDTO<T> | undefined>;
|
|
278
313
|
/**
|
|
279
314
|
* Updates a record in the collection with the specified ID and returns updated record count
|
|
280
315
|
*
|
|
281
|
-
* @param
|
|
282
|
-
* @
|
|
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.
|
|
316
|
+
* @param command
|
|
317
|
+
* @returns - A promise that resolves to the number of documents modified.
|
|
285
318
|
* @protected
|
|
286
319
|
*/
|
|
287
|
-
protected _updateOnly(
|
|
320
|
+
protected _updateOnly(command: SqbEntityService.UpdateOneCommand<T>): Promise<boolean>;
|
|
288
321
|
/**
|
|
289
322
|
* Updates multiple records in the collection based on the specified input and options.
|
|
290
323
|
*
|
|
291
|
-
* @param
|
|
292
|
-
* @
|
|
293
|
-
* @return {Promise<number>} - A promise that resolves to the number of documents matched and modified.
|
|
324
|
+
* @param command
|
|
325
|
+
* @return - A promise that resolves to the number of documents matched and modified.
|
|
294
326
|
* @protected
|
|
295
327
|
*/
|
|
296
|
-
protected _updateMany(
|
|
328
|
+
protected _updateMany(command: SqbEntityService.UpdateOneCommand<T>): Promise<number>;
|
|
297
329
|
/**
|
|
298
330
|
* Acquires a connection and performs Repository.create operation
|
|
299
331
|
*
|
|
@@ -403,20 +435,16 @@ export declare class SqbEntityService<T extends object = object> extends Service
|
|
|
403
435
|
* @returns {FilterInput | Promise<FilterInput> | undefined} The common filter or a Promise
|
|
404
436
|
* that resolves to the common filter, or undefined if not available.
|
|
405
437
|
*/
|
|
406
|
-
protected _getCommonFilter(
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
protected
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
documentId?: any;
|
|
419
|
-
input?: Object;
|
|
420
|
-
options?: Record<string, any>;
|
|
421
|
-
}): Promise<any>;
|
|
438
|
+
protected _getCommonFilter(command: SqbEntityService.CommandInfo): SQBAdapter.FilterInput | Promise<SQBAdapter.FilterInput> | undefined;
|
|
439
|
+
protected _executeCommand(command: SqbEntityService.CommandInfo, commandFn: () => any): Promise<any>;
|
|
440
|
+
protected _beforeCreate(command: SqbEntityService.CreateCommand<T>): Promise<void>;
|
|
441
|
+
protected _beforeUpdate(command: SqbEntityService.UpdateOneCommand<T>): Promise<void>;
|
|
442
|
+
protected _beforeUpdateMany(command: SqbEntityService.UpdateManyCommand<T>): Promise<void>;
|
|
443
|
+
protected _beforeDelete(command: SqbEntityService.DeleteOneCommand): Promise<void>;
|
|
444
|
+
protected _beforeDeleteMany(command: SqbEntityService.DeleteManyCommand): Promise<void>;
|
|
445
|
+
protected _afterCreate(command: SqbEntityService.CreateCommand<T>, result: PartialDTO<T>): Promise<void>;
|
|
446
|
+
protected _afterUpdate(command: SqbEntityService.UpdateOneCommand<T>, result?: PartialDTO<T>): Promise<void>;
|
|
447
|
+
protected _afterUpdateMany(command: SqbEntityService.UpdateManyCommand<T>, affected: number): Promise<void>;
|
|
448
|
+
protected _afterDelete(command: SqbEntityService.DeleteOneCommand, affected: number): Promise<void>;
|
|
449
|
+
protected _afterDeleteMany(command: SqbEntityService.DeleteManyCommand, affected: number): Promise<void>;
|
|
422
450
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PartialDTO, PatchDTO, Type } from 'ts-gems';
|
|
1
|
+
import type { PartialDTO, PatchDTO, RequiredSome, Type } from 'ts-gems';
|
|
3
2
|
import { SQBAdapter } from './sqb-adapter.js';
|
|
4
3
|
import { SqbEntityService } from './sqb-entity-service.js';
|
|
5
4
|
/**
|
|
@@ -42,14 +41,14 @@ export declare namespace SqbSingletonService {
|
|
|
42
41
|
*
|
|
43
42
|
* @interface
|
|
44
43
|
*/
|
|
45
|
-
interface UpdateOptions extends SqbEntityService.
|
|
44
|
+
interface UpdateOptions extends SqbEntityService.UpdateOneOptions {
|
|
46
45
|
}
|
|
47
46
|
/**
|
|
48
47
|
* Represents options for "updateOnly" operation
|
|
49
48
|
*
|
|
50
49
|
* @interface
|
|
51
50
|
*/
|
|
52
|
-
interface UpdateOnlyOptions extends SqbEntityService.
|
|
51
|
+
interface UpdateOnlyOptions extends SqbEntityService.UpdateOneOptions {
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
/**
|
|
@@ -57,12 +56,11 @@ export declare namespace SqbSingletonService {
|
|
|
57
56
|
* @template T - The data type class type of the resource
|
|
58
57
|
*/
|
|
59
58
|
export declare abstract class SqbSingletonService<T extends object = object> extends SqbEntityService {
|
|
60
|
-
protected _primaryKeyFields?: ColumnFieldMetadata[];
|
|
61
59
|
/**
|
|
62
60
|
* Represents a unique identifier for singleton record
|
|
63
|
-
* @property {SQBAdapter.
|
|
61
|
+
* @property {SQBAdapter.IdOrIds}
|
|
64
62
|
*/
|
|
65
|
-
id: SQBAdapter.
|
|
63
|
+
id: SQBAdapter.IdOrIds;
|
|
66
64
|
/**
|
|
67
65
|
* Constructs a new instance
|
|
68
66
|
*
|
|
@@ -86,7 +84,8 @@ export declare abstract class SqbSingletonService<T extends object = object> ext
|
|
|
86
84
|
* @returns {Promise<PartialDTO<T>>} A promise that resolves to the created resource
|
|
87
85
|
* @throws {Error} if an unknown error occurs while creating the resource
|
|
88
86
|
*/
|
|
89
|
-
create(input: PartialDTO<T>, options
|
|
87
|
+
create(input: PartialDTO<T>, options: RequiredSome<SqbSingletonService.CreateOptions, 'projection'>): Promise<PartialDTO<T>>;
|
|
88
|
+
create(input: PartialDTO<T>, options?: SqbSingletonService.CreateOptions): Promise<T>;
|
|
90
89
|
/**
|
|
91
90
|
* Deletes the singleton record
|
|
92
91
|
*
|
|
@@ -107,7 +106,8 @@ export declare abstract class SqbSingletonService<T extends object = object> ext
|
|
|
107
106
|
* @param {SqbSingletonService.FindOneOptions} options - The options for the query.
|
|
108
107
|
* @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
|
|
109
108
|
*/
|
|
110
|
-
find(options
|
|
109
|
+
find(options: RequiredSome<SqbSingletonService.FindOptions, 'projection'>): Promise<PartialDTO<T> | undefined>;
|
|
110
|
+
find(options?: SqbSingletonService.FindOptions): Promise<T | undefined>;
|
|
111
111
|
/**
|
|
112
112
|
* Retrieves the singleton record. Throws error if not found.
|
|
113
113
|
*
|
|
@@ -116,7 +116,8 @@ export declare abstract class SqbSingletonService<T extends object = object> ext
|
|
|
116
116
|
* or rejects with a ResourceNotFoundError if the document does not exist.
|
|
117
117
|
* @throws {ResourceNotAvailableError} - If the document does not exist.
|
|
118
118
|
*/
|
|
119
|
-
get(options
|
|
119
|
+
get(options: RequiredSome<SqbSingletonService.FindOptions, 'projection'>): Promise<PartialDTO<T>>;
|
|
120
|
+
get(options?: SqbSingletonService.FindOptions): Promise<T>;
|
|
120
121
|
/**
|
|
121
122
|
* Updates the singleton.
|
|
122
123
|
*
|
|
@@ -125,7 +126,8 @@ export declare abstract class SqbSingletonService<T extends object = object> ext
|
|
|
125
126
|
* @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the updated document or
|
|
126
127
|
* undefined if the document was not found.
|
|
127
128
|
*/
|
|
128
|
-
update(input: PatchDTO<T>, options
|
|
129
|
+
update(input: PatchDTO<T>, options: RequiredSome<SqbSingletonService.UpdateOptions, 'projection'>): Promise<PartialDTO<T> | undefined>;
|
|
130
|
+
update(input: PatchDTO<T>, options?: SqbSingletonService.UpdateOptions): Promise<T | undefined>;
|
|
129
131
|
/**
|
|
130
132
|
* Updates the singleton and returns updated record count
|
|
131
133
|
*
|