@opra/sqb 0.33.13 → 1.0.0-alpha.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.
Files changed (43) hide show
  1. package/cjs/{transform-filter.js → adapter-utils/parse-filter.js} +37 -12
  2. package/cjs/augmentation/datatype-factory.augmentation.js +75 -0
  3. package/cjs/augmentation/mixin-type.augmentation.js +5 -3
  4. package/cjs/index.js +3 -4
  5. package/cjs/sqb-adapter.js +66 -100
  6. package/cjs/sqb-collection-service.js +297 -0
  7. package/cjs/sqb-entity-service.js +444 -25
  8. package/cjs/sqb-singleton-service.js +180 -0
  9. package/esm/{transform-filter.js → adapter-utils/parse-filter.js} +36 -11
  10. package/esm/augmentation/datatype-factory.augmentation.js +73 -0
  11. package/esm/augmentation/mapped-type.augmentation.js +1 -1
  12. package/esm/augmentation/mixin-type.augmentation.js +6 -4
  13. package/esm/index.js +3 -4
  14. package/esm/sqb-adapter.js +66 -100
  15. package/esm/sqb-collection-service.js +293 -0
  16. package/esm/sqb-entity-service.js +444 -25
  17. package/esm/sqb-singleton-service.js +176 -0
  18. package/package.json +10 -9
  19. package/types/adapter-utils/parse-filter.d.ts +10 -0
  20. package/types/index.d.ts +3 -4
  21. package/types/sqb-adapter.d.ts +10 -8
  22. package/types/sqb-collection-service.d.ts +233 -0
  23. package/types/sqb-entity-service.d.ts +418 -18
  24. package/types/sqb-singleton-service.d.ts +137 -0
  25. package/cjs/augmentation/api-document-factory.augmentation.js +0 -20
  26. package/cjs/augmentation/type-document-factory.augmentation.js +0 -99
  27. package/cjs/sqb-collection.js +0 -80
  28. package/cjs/sqb-entity-service-base.js +0 -170
  29. package/cjs/sqb-singleton.js +0 -44
  30. package/cjs/transform-key-values.js +0 -14
  31. package/esm/augmentation/api-document-factory.augmentation.js +0 -18
  32. package/esm/augmentation/type-document-factory.augmentation.js +0 -97
  33. package/esm/sqb-collection.js +0 -76
  34. package/esm/sqb-entity-service-base.js +0 -166
  35. package/esm/sqb-singleton.js +0 -40
  36. package/esm/transform-key-values.js +0 -11
  37. package/types/augmentation/type-document-factory.augmentation.d.ts +0 -1
  38. package/types/sqb-collection.d.ts +0 -31
  39. package/types/sqb-entity-service-base.d.ts +0 -31
  40. package/types/sqb-singleton.d.ts +0 -18
  41. package/types/transform-filter.d.ts +0 -3
  42. package/types/transform-key-values.d.ts +0 -3
  43. /package/types/augmentation/{api-document-factory.augmentation.d.ts → datatype-factory.augmentation.d.ts} +0 -0
@@ -1,22 +1,422 @@
1
- import { Type } from 'ts-gems';
2
- import { DTO, PartialDTO, PatchDTO } from '@opra/common';
3
- import { EntityInput, Repository } from '@sqb/connect';
4
- import { SqbEntityServiceBase } from './sqb-entity-service-base.js';
1
+ import { PartialDTO, PatchDTO, Type } from 'ts-gems';
2
+ import { IsObject } from 'valgen';
3
+ import { ComplexType } from '@opra/common';
4
+ import { ServiceBase } from '@opra/core';
5
+ import { EntityMetadata, Repository, SqbClient, SqbConnection } from '@sqb/connect';
6
+ import { SQBAdapter } from './sqb-adapter.js';
7
+ /**
8
+ * @namespace SqbEntityService
9
+ */
5
10
  export declare namespace SqbEntityService {
6
- interface Options extends SqbEntityServiceBase.Options {
11
+ interface Options {
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'];
17
+ }
18
+ type CrudOp = 'create' | 'read' | 'update' | 'delete';
19
+ interface CommandInfo {
20
+ crud: SqbEntityService.CrudOp;
21
+ method: string;
22
+ byId: boolean;
23
+ documentId?: SQBAdapter.IdOrIds;
24
+ input?: Record<string, any>;
25
+ options?: Record<string, any>;
26
+ }
27
+ /**
28
+ * Represents options for "create" operation
29
+ *
30
+ * @interface
31
+ */
32
+ interface CreateOptions extends Repository.CreateOptions {
33
+ }
34
+ /**
35
+ * Represents options for "count" operation
36
+ *
37
+ * @interface
38
+ */
39
+ interface CountOptions extends Repository.CountOptions {
40
+ }
41
+ /**
42
+ * Represents options for "delete" operation
43
+ *
44
+ * @interface
45
+ */
46
+ interface DeleteOptions extends Repository.DeleteOptions {
47
+ }
48
+ /**
49
+ * Represents options for "deleteMany" operation
50
+ *
51
+ * @interface
52
+ */
53
+ interface DeleteManyOptions extends Repository.DeleteManyOptions {
54
+ }
55
+ /**
56
+ * Represents options for "exists" operation
57
+ *
58
+ * @interface
59
+ */
60
+ interface ExistsOptions extends Repository.ExistsOptions {
61
+ }
62
+ /**
63
+ * Represents options for "existsOne" operation
64
+ *
65
+ * @interface
66
+ */
67
+ interface ExistsOneOptions extends Repository.ExistsOptions {
68
+ }
69
+ /**
70
+ * Represents options for "findOne" operation
71
+ *
72
+ * @interface
73
+ */
74
+ interface FindOneOptions extends Repository.FindOneOptions {
75
+ }
76
+ /**
77
+ * Represents options for "findMany" operation
78
+ *
79
+ * @interface
80
+ */
81
+ interface FindManyOptions extends Repository.FindManyOptions {
82
+ }
83
+ /**
84
+ * Represents options for "update" operation
85
+ *
86
+ * @interface
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 {
96
+ }
97
+ /**
98
+ * Represents options for "updateMany" operation
99
+ *
100
+ * @interface
101
+ */
102
+ interface UpdateManyOptions extends Repository.UpdateManyOptions {
7
103
  }
8
104
  }
9
- export declare class SqbEntityService<T> extends SqbEntityServiceBase<T> {
10
- readonly typeClass: Type<T>;
11
- constructor(typeClass: Type<T>, options?: SqbEntityService.Options);
12
- count(options?: Repository.CountOptions): Promise<number>;
13
- create(data: DTO<T>, options?: Repository.CreateOptions): Promise<PartialDTO<T>>;
14
- delete(keyValue: any, options?: Repository.DeleteOptions): Promise<number>;
15
- deleteMany(options?: Repository.DeleteManyOptions): Promise<number>;
16
- find(keyValue: any, options?: Repository.FindOptions): Promise<PartialDTO<T> | undefined>;
17
- findOne(options?: Repository.FindOneOptions): Promise<PartialDTO<T> | undefined>;
18
- findMany(options?: Repository.FindManyOptions): Promise<PartialDTO<T>[]>;
19
- exists(options?: Repository.ExistsOptions): Promise<boolean>;
20
- update(keyValue: any, data: EntityInput<T>, options?: Repository.UpdateOptions): Promise<PartialDTO<T> | undefined>;
21
- updateMany(data: PatchDTO<T>, options?: Repository.UpdateManyOptions): Promise<number>;
105
+ /**
106
+ * @class SqbEntityService
107
+ * @template T - The data type class type of the resource
108
+ */
109
+ export declare class SqbEntityService<T extends object = object> extends ServiceBase {
110
+ protected _dataType_: Type | string;
111
+ protected _dataType: ComplexType;
112
+ protected _dataTypeClass?: Type;
113
+ protected _entityMetadata?: EntityMetadata;
114
+ protected _encoders: Record<string, IsObject.Validator<T>>;
115
+ protected _decoder?: IsObject.Validator<T>;
116
+ /**
117
+ * Represents a SqbClient or SqbConnection object
118
+ */
119
+ db?: (SqbClient | SqbConnection) | ((_this: any) => SqbClient | SqbConnection);
120
+ /**
121
+ * Represents the name of a resource.
122
+ * @type {string}
123
+ */
124
+ $resourceName?: string | ((_this: any) => string);
125
+ /**
126
+ * Represents a common filter function for a service.
127
+ *
128
+ * @type {SqbEntityService.Filter | Function}
129
+ */
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>;
140
+ /**
141
+ * Callback function for handling errors.
142
+ *
143
+ * @param {unknown} error - The error object.
144
+ * @param {SqbEntityService} _this - The context object.
145
+ */
146
+ $onError?: (error: unknown, _this: any) => void | Promise<void>;
147
+ /**
148
+ * Constructs a new instance
149
+ *
150
+ * @param dataType - The data type of the returning results
151
+ * @param [options] - The options for the service.
152
+ * @constructor
153
+ */
154
+ constructor(dataType: Type<T> | string, options?: SqbEntityService.Options);
155
+ /**
156
+ * Retrieves the OPRA data type
157
+ *
158
+ * @throws {NotAcceptableError} If the data type is not a ComplexType.
159
+ */
160
+ get dataType(): ComplexType;
161
+ /**
162
+ * Retrieves the Class of the data type
163
+ *
164
+ * @throws {NotAcceptableError} If the data type is not a ComplexType.
165
+ */
166
+ get dataTypeClass(): Type;
167
+ /**
168
+ * Retrieves the SQB entity metadata object
169
+ *
170
+ * @throws {TypeError} If metadata is not available
171
+ */
172
+ get entityMetadata(): EntityMetadata;
173
+ /**
174
+ * Retrieves the resource name.
175
+ *
176
+ * @returns {string} The resource name.
177
+ * @throws {Error} If the collection name is not defined.
178
+ */
179
+ getResourceName(): string;
180
+ /**
181
+ * Retrieves the encoder for the specified operation.
182
+ *
183
+ * @param operation - The operation to retrieve the encoder for. Valid values are 'create' and 'update'.
184
+ */
185
+ getEncoder(operation: 'create' | 'update'): IsObject.Validator<T>;
186
+ /**
187
+ * Retrieves the decoder.
188
+ */
189
+ getDecoder(): IsObject.Validator<T>;
190
+ /**
191
+ * Insert a new record into database
192
+ *
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
197
+ * @protected
198
+ */
199
+ protected _create(input: PartialDTO<T>, options?: SqbEntityService.CreateOptions): Promise<PartialDTO<T>>;
200
+ /**
201
+ * Returns the count of records based on the provided options
202
+ *
203
+ * @param {SqbEntityService.CountOptions} options - The options for the count operation.
204
+ * @return {Promise<number>} - A promise that resolves to the count of records
205
+ * @protected
206
+ */
207
+ protected _count(options?: SqbEntityService.CountOptions): Promise<number>;
208
+ /**
209
+ * Deletes a record from the collection.
210
+ *
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.
214
+ * @protected
215
+ */
216
+ protected _delete(id: SQBAdapter.IdOrIds, options?: SqbEntityService.DeleteOptions): Promise<number>;
217
+ /**
218
+ * Deletes multiple documents from the collection that meet the specified filter criteria.
219
+ *
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.
222
+ * @protected
223
+ */
224
+ protected _deleteMany(options?: SqbEntityService.DeleteManyOptions): Promise<number>;
225
+ /**
226
+ * Checks if a record with the given id exists.
227
+ *
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.
231
+ * @protected
232
+ */
233
+ protected _exists(id: SQBAdapter.IdOrIds, options?: SqbEntityService.ExistsOptions): Promise<boolean>;
234
+ /**
235
+ * Checks if a record with the given arguments exists.
236
+ *
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.
239
+ * @protected
240
+ */
241
+ protected _existsOne(options?: SqbEntityService.ExistsOptions): Promise<boolean>;
242
+ /**
243
+ * Finds a record by ID.
244
+ *
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.
248
+ * @protected
249
+ */
250
+ protected _findById(id: SQBAdapter.Id, options?: SqbEntityService.FindOneOptions): Promise<PartialDTO<T> | undefined>;
251
+ /**
252
+ * Finds a record in the collection that matches the specified options.
253
+ *
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.
256
+ * @protected
257
+ */
258
+ protected _findOne(options?: SqbEntityService.FindOneOptions): Promise<PartialDTO<T> | undefined>;
259
+ /**
260
+ * Finds multiple records in collection.
261
+ *
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.
264
+ * @protected
265
+ */
266
+ protected _findMany(options?: SqbEntityService.FindManyOptions): Promise<PartialDTO<T>[]>;
267
+ /**
268
+ * Updates a record with the given id in the collection.
269
+ *
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.
275
+ * @protected
276
+ */
277
+ protected _update(id: SQBAdapter.IdOrIds, input: PatchDTO<T>, options?: SqbEntityService.UpdateOptions): Promise<PartialDTO<T> | undefined>;
278
+ /**
279
+ * Updates a record in the collection with the specified ID and returns updated record count
280
+ *
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.
285
+ * @protected
286
+ */
287
+ protected _updateOnly(id: SQBAdapter.IdOrIds, input: PatchDTO<T>, options?: SqbEntityService.UpdateOptions): Promise<boolean>;
288
+ /**
289
+ * Updates multiple records in the collection based on the specified input and options.
290
+ *
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.
294
+ * @protected
295
+ */
296
+ protected _updateMany(input: PatchDTO<T>, options?: SqbEntityService.UpdateManyOptions): Promise<number>;
297
+ /**
298
+ * Acquires a connection and performs Repository.create operation
299
+ *
300
+ * @param input - The document to insert
301
+ * @param options - Optional settings for the command
302
+ * @protected
303
+ */
304
+ protected _dbCreate(input: PartialDTO<T>, options?: Repository.CreateOptions): Promise<PartialDTO<T>>;
305
+ /**
306
+ * Acquires a connection and performs Repository.count operation
307
+ *
308
+ * @param options - The options for counting documents.
309
+ * @protected
310
+ */
311
+ protected _dbCount(options?: Repository.CountOptions): Promise<number>;
312
+ /**
313
+ * Acquires a connection and performs Repository.delete operation
314
+ *
315
+ * @param id - Value of the key field used to select the record
316
+ * @param options - Optional settings for the command
317
+ * @protected
318
+ */
319
+ protected _dbDelete(id: SQBAdapter.IdOrIds, options?: Repository.DeleteOptions): Promise<number>;
320
+ /**
321
+ * Acquires a connection and performs Repository.deleteMany operation
322
+ *
323
+ * @param options - Optional settings for the command
324
+ * @protected
325
+ */
326
+ protected _dbDeleteMany(options?: Repository.DeleteManyOptions): Promise<number>;
327
+ /**
328
+ * Acquires a connection and performs Repository.exists operation
329
+ *
330
+ * @param id - Value of the key field used to select the record
331
+ * @param options - Optional settings for the command
332
+ * @protected
333
+ */
334
+ protected _dbExists(id: SQBAdapter.IdOrIds, options?: Repository.ExistsOptions): Promise<boolean>;
335
+ /**
336
+ * Acquires a connection and performs Repository.existsOne operation
337
+ *
338
+ * @param options - Optional settings for the command
339
+ * @protected
340
+ */
341
+ protected _dbExistsOne(options?: Repository.ExistsOptions): Promise<boolean>;
342
+ /**
343
+ * Acquires a connection and performs Repository.findById operation
344
+ *
345
+ * @param id - Value of the key field used to select the record
346
+ * @param options - Optional settings for the command
347
+ * @protected
348
+ */
349
+ protected _dbFindById(id: SQBAdapter.IdOrIds, options?: Repository.FindOptions): Promise<PartialDTO<T> | undefined>;
350
+ /**
351
+ * Acquires a connection and performs Repository.findOne operation
352
+ *
353
+ * @param options - Optional settings for the command
354
+ * @protected
355
+ */
356
+ protected _dbFindOne(options?: Repository.FindOneOptions): Promise<PartialDTO<T> | undefined>;
357
+ /**
358
+ * Acquires a connection and performs Repository.findMany operation
359
+ *
360
+ * @param options - Optional settings for the command
361
+ * @protected
362
+ */
363
+ protected _dbFindMany(options?: Repository.FindManyOptions): Promise<PartialDTO<T>[]>;
364
+ /**
365
+ * Acquires a connection and performs Repository.update operation
366
+ *
367
+ * @param id - Value of the key field used to select the record
368
+ * @param data - The update values to be applied to the document
369
+ * @param options - Optional settings for the command
370
+ * @protected
371
+ */
372
+ protected _dbUpdate(id: SQBAdapter.IdOrIds, data: PatchDTO<T>, options?: Repository.UpdateOptions): Promise<PartialDTO<T> | undefined>;
373
+ /**
374
+ * Acquires a connection and performs Repository.updateOnly operation
375
+ *
376
+ * @param id - Value of the key field used to select the record
377
+ * @param data - The update values to be applied to the document
378
+ * @param options - Optional settings for the command
379
+ * @protected
380
+ */
381
+ protected _dbUpdateOnly(id: SQBAdapter.IdOrIds, data: PatchDTO<T>, options?: Repository.UpdateOptions): Promise<boolean>;
382
+ /**
383
+ * Acquires a connection and performs Repository.updateMany operation
384
+ *
385
+ * @param data - The update values to be applied to the document
386
+ * @param options - Optional settings for the command
387
+ * @protected
388
+ */
389
+ protected _dbUpdateMany(data: PatchDTO<T>, options?: Repository.UpdateManyOptions): Promise<number>;
390
+ /**
391
+ * Retrieves the database connection.
392
+ *
393
+ * @protected
394
+ *
395
+ * @throws {Error} If the context or database is not set.
396
+ */
397
+ protected getConnection(): SqbConnection | SqbClient | Promise<SqbConnection | SqbClient>;
398
+ /**
399
+ * Retrieves the common filter used for querying documents.
400
+ * This method is mostly used for security issues like securing multi-tenant applications.
401
+ *
402
+ * @protected
403
+ * @returns {FilterInput | Promise<FilterInput> | undefined} The common filter or a Promise
404
+ * that resolves to the common filter, or undefined if not available.
405
+ */
406
+ protected _getCommonFilter(args: {
407
+ crud: SqbEntityService.CrudOp;
408
+ method: string;
409
+ byId: boolean;
410
+ documentId?: SQBAdapter.IdOrIds;
411
+ input?: Object;
412
+ options?: Record<string, any>;
413
+ }): 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>;
22
422
  }
@@ -0,0 +1,137 @@
1
+ import { PartialDTO, PatchDTO, Type } from 'ts-gems';
2
+ import { ColumnFieldMetadata } from '@sqb/connect';
3
+ import { SQBAdapter } from './sqb-adapter.js';
4
+ import { SqbEntityService } from './sqb-entity-service.js';
5
+ /**
6
+ * @namespace SqbSingletonService
7
+ */
8
+ export declare namespace SqbSingletonService {
9
+ interface Options extends SqbEntityService.Options {
10
+ id?: SqbSingletonService<any>['id'];
11
+ }
12
+ /**
13
+ * Represents options for "create" operation
14
+ *
15
+ * @interface
16
+ */
17
+ interface CreateOptions extends SqbEntityService.CreateOptions {
18
+ }
19
+ /**
20
+ * Represents options for "delete" operation
21
+ *
22
+ * @interface
23
+ */
24
+ interface DeleteOptions extends SqbEntityService.DeleteOptions {
25
+ }
26
+ /**
27
+ * Represents options for "exists" operation
28
+ *
29
+ * @interface
30
+ */
31
+ interface ExistsOptions extends SqbEntityService.ExistsOptions {
32
+ }
33
+ /**
34
+ * Represents options for "find" operation
35
+ *
36
+ * @interface
37
+ */
38
+ interface FindOptions extends SqbEntityService.FindOneOptions {
39
+ }
40
+ /**
41
+ * Represents options for "update" operation
42
+ *
43
+ * @interface
44
+ */
45
+ interface UpdateOptions extends SqbEntityService.UpdateOptions {
46
+ }
47
+ /**
48
+ * Represents options for "updateOnly" operation
49
+ *
50
+ * @interface
51
+ */
52
+ interface UpdateOnlyOptions extends SqbEntityService.UpdateOptions {
53
+ }
54
+ }
55
+ /**
56
+ * @class SqbSingletonService
57
+ * @template T - The data type class type of the resource
58
+ */
59
+ export declare abstract class SqbSingletonService<T extends object = object> extends SqbEntityService {
60
+ protected _primaryKeyFields?: ColumnFieldMetadata[];
61
+ /**
62
+ * Represents a unique identifier for singleton record
63
+ * @property {SQBAdapter.Id}
64
+ */
65
+ id: SQBAdapter.Id;
66
+ /**
67
+ * Constructs a new instance
68
+ *
69
+ * @param {Type | string} dataType - The data type of the array elements.
70
+ * @param {SqbSingletonService.Options} [options] - The options for the array service.
71
+ * @constructor
72
+ */
73
+ constructor(dataType: Type<T> | string, options?: SqbSingletonService.Options);
74
+ /**
75
+ * Asserts the existence of a resource based on the given options.
76
+ *
77
+ * @returns {Promise<void>} A Promise that resolves when the resource exists.
78
+ * @throws {ResourceNotAvailableError} If the resource does not exist.
79
+ */
80
+ assert(options?: SqbSingletonService.ExistsOptions): Promise<void>;
81
+ /**
82
+ * Inserts a single record into the database.
83
+ *
84
+ * @param {PartialDTO<T>} input - The input data
85
+ * @param {SqbSingletonService.CreateOptions} [options] - The options object
86
+ * @returns {Promise<PartialDTO<T>>} A promise that resolves to the created resource
87
+ * @throws {Error} if an unknown error occurs while creating the resource
88
+ */
89
+ create(input: PartialDTO<T>, options?: SqbSingletonService.CreateOptions): Promise<PartialDTO<T>>;
90
+ /**
91
+ * Deletes the singleton record
92
+ *
93
+ * @param {SqbSingletonService.DeleteOptions} [options] - The options object
94
+ * @return {Promise<number>} - A Promise that resolves to the number of records deleted
95
+ */
96
+ delete(options?: SqbSingletonService.DeleteOptions): Promise<number>;
97
+ /**
98
+ * Checks if the singleton record exists.
99
+ *
100
+ * @param {SqbSingletonService.ExistsOptions} [options] - The options for the query (optional).
101
+ * @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
102
+ */
103
+ exists(options?: SqbSingletonService.ExistsOptions): Promise<boolean>;
104
+ /**
105
+ * Finds the singleton record. Returns `undefined` if not found
106
+ *
107
+ * @param {SqbSingletonService.FindOneOptions} options - The options for the query.
108
+ * @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
109
+ */
110
+ find(options?: SqbSingletonService.FindOptions): Promise<PartialDTO<T> | undefined>;
111
+ /**
112
+ * Retrieves the singleton record. Throws error if not found.
113
+ *
114
+ * @param {SqbSingletonService.FindOptions} [options] - Optional options for the `find` operation.
115
+ * @returns {Promise<PartialDTO<T>>} - A promise that resolves to the retrieved document,
116
+ * or rejects with a ResourceNotFoundError if the document does not exist.
117
+ * @throws {ResourceNotAvailableError} - If the document does not exist.
118
+ */
119
+ get(options?: SqbSingletonService.FindOptions): Promise<PartialDTO<T>>;
120
+ /**
121
+ * Updates the singleton.
122
+ *
123
+ * @param {PatchDTO<T>} input - The partial input object containing the fields to update.
124
+ * @param {SqbSingletonService.UpdateOptions} [options] - The options for the update operation.
125
+ * @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the updated document or
126
+ * undefined if the document was not found.
127
+ */
128
+ update(input: PatchDTO<T>, options?: SqbSingletonService.UpdateOptions): Promise<PartialDTO<T> | undefined>;
129
+ /**
130
+ * Updates the singleton and returns updated record count
131
+ *
132
+ * @param {PatchDTO<T>} input - The partial input data to update the document with.
133
+ * @param {SqbSingletonService.UpdateOptions} options - The options for updating the document.
134
+ * @returns {Promise<number>} - A promise that resolves to the number of documents modified.
135
+ */
136
+ updateOnly(input: PatchDTO<T>, options?: SqbSingletonService.UpdateOnlyOptions): Promise<number>;
137
+ }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const common_1 = require("@opra/common");
4
- const connect_1 = require("@sqb/connect");
5
- // @ts-ignore
6
- const _createResource = common_1.ApiDocumentFactory.prototype.createResource;
7
- // @ts-ignore
8
- common_1.ApiDocumentFactory.prototype.createResource = function (container, initArguments) {
9
- // Determine primaryKey if not defined
10
- if (initArguments.kind === 'Collection' && !initArguments.primaryKey && initArguments.type.ctor) {
11
- const entityMetadata = connect_1.EntityMetadata.get(initArguments.type.ctor);
12
- if (entityMetadata?.indexes) {
13
- const primaryIndex = entityMetadata.indexes.find(x => x.primary);
14
- if (primaryIndex) {
15
- initArguments.primaryKey = primaryIndex.columns;
16
- }
17
- }
18
- }
19
- return _createResource.call(this, container, initArguments);
20
- };