@opra/sqb 1.26.3 → 1.26.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,26 @@
1
1
  # @opra/sqb
2
2
 
3
- OPRA SQB package.
3
+ [![NPM Version][npm-image]][npm-url]
4
+ [![NPM Downloads][downloads-image]][downloads-url]
5
+ [![CI Tests][ci-test-image]][ci-test-url]
6
+ [![Test Coverage][coveralls-image]][coveralls-url]
7
+
8
+
9
+ ## Support
10
+ You can report bugs and discuss features on the [GitHub issues](https://github.com/panates/opra/issues) page.
11
+
12
+ ## Node Compatibility
13
+ - node >= 20.x
14
+
15
+
16
+ ## License
17
+ Available under [MIT](LICENSE) license.
18
+
19
+ [npm-image]: https://img.shields.io/npm/v/@opra/sqb
20
+ [npm-url]: https://npmjs.org/package/@opra/sqb
21
+ [downloads-image]: https://img.shields.io/npm/dm/@opra/sqb.svg
22
+ [downloads-url]: https://npmjs.org/package/@opra/sqb
23
+ [ci-test-image]: https://github.com/panates/opra/actions/workflows/test.yml/badge.svg
24
+ [ci-test-url]: https://github.com/panates/opra/actions/workflows/test.yml
25
+ [coveralls-image]: https://coveralls.io/repos/github/panates/opra/badge.svg?branch=main
26
+ [coveralls-url]: https://coveralls.io/github/panates/opra?branch=main
@@ -1,10 +1,9 @@
1
1
  import '@opra/core';
2
2
  import type { SQBAdapter } from '../sqb-adapter.js';
3
3
  /**
4
- * Prepare the SQB filter based on the provided filters and options.
4
+ * Prepares the SQB filter based on the provided filters and options.
5
5
  *
6
- * @param {SQBAdapter.FilterInput|SQBAdapter.FilterInput[]} filters - The filter(s) to be applied.
7
- *
8
- * @returns {Expression} - The prepared SQB Expression.
6
+ * @param filters - The filter(s) to be applied. Can be a single filter or an array of filters.
7
+ * @returns The prepared SQB Expression, or `undefined` if no filters are provided.
9
8
  */
10
9
  export default function prepareFilter(filters: SQBAdapter.FilterInput | SQBAdapter.FilterInput[]): any;
@@ -3,11 +3,10 @@ import { OpraFilter } from '@opra/common';
3
3
  import * as sqb from '@sqb/builder';
4
4
  import { vg } from 'valgen';
5
5
  /**
6
- * Prepare the SQB filter based on the provided filters and options.
6
+ * Prepares the SQB filter based on the provided filters and options.
7
7
  *
8
- * @param {SQBAdapter.FilterInput|SQBAdapter.FilterInput[]} filters - The filter(s) to be applied.
9
- *
10
- * @returns {Expression} - The prepared SQB Expression.
8
+ * @param filters - The filter(s) to be applied. Can be a single filter or an array of filters.
9
+ * @returns The prepared SQB Expression, or `undefined` if no filters are provided.
11
10
  */
12
11
  export default function prepareFilter(filters) {
13
12
  const filtersArray = Array.isArray(filters) ? filters : [filters];
@@ -13,7 +13,7 @@ DataTypeFactory._prepareComplexTypeArgs = async function (context, owner, initAr
13
13
  const sqbField = sqbMeta && EntityMetadata.getField(sqbMeta, fieldName);
14
14
  if (!sqbField)
15
15
  continue;
16
- /** Copy type information from sqb metadata to opra */
16
+ /* Copy type information from sqb metadata to opra */
17
17
  if (!fieldSchema.type || fieldSchema.type === Object) {
18
18
  if (isAssociationField(sqbField)) {
19
19
  if (!fieldSchema.type) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/sqb",
3
- "version": "1.26.3",
3
+ "version": "1.26.4",
4
4
  "description": "Opra SQB adapter package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -10,8 +10,8 @@
10
10
  "valgen": "^6.0.3"
11
11
  },
12
12
  "peerDependencies": {
13
- "@opra/core": "^1.26.3",
14
- "@opra/http": "^1.26.3",
13
+ "@opra/core": "^1.26.4",
14
+ "@opra/http": "^1.26.4",
15
15
  "@sqb/builder": ">4.0.0 <5",
16
16
  "@sqb/connect": ">4.0.0 <5"
17
17
  },
package/sqb-adapter.d.ts CHANGED
@@ -2,20 +2,60 @@ import type { OpraFilter } from '@opra/common';
2
2
  import type { ExecutionContext } from '@opra/core';
3
3
  import { type Repository } from '@sqb/connect';
4
4
  import _prepareFilter from './adapter-utils/prepare-filter.js';
5
+ /**
6
+ * SQBAdapter namespace provides types and utility functions for integrating SQB with Opra.
7
+ */
5
8
  export declare namespace SQBAdapter {
9
+ /**
10
+ * Represents a single identifier type.
11
+ */
6
12
  type Id = string | number | boolean | Date;
13
+ /**
14
+ * Represents a single identifier or a composite key.
15
+ */
7
16
  type IdOrIds = Id | Record<string, Id>;
17
+ /**
18
+ * Represents the input for a filter, which can be an Opra filter expression,
19
+ * a SQB filter object, a string, or undefined.
20
+ */
8
21
  type FilterInput = OpraFilter.Expression | Repository.FindManyOptions['filter'] | string | undefined;
9
22
  /**
10
- * @deprecated Use prepareFilter instead
23
+ * Parses the given filter input into a SQB filter expression.
24
+ * @deprecated Use {@link prepareFilter} instead.
11
25
  */
12
26
  const parseFilter: typeof _prepareFilter;
27
+ /**
28
+ * Prepares the given filter input into a SQB filter expression.
29
+ */
13
30
  const prepareFilter: typeof _prepareFilter;
31
+ /**
32
+ * Represents a request that has been transformed for SQB operations.
33
+ */
14
34
  interface TransformedRequest {
35
+ /**
36
+ * The operation method name.
37
+ */
15
38
  method: 'create' | 'delete' | 'deleteMany' | 'get' | 'replace' | 'findMany' | 'update' | 'updateMany';
39
+ /**
40
+ * The primary key for the operation, if applicable.
41
+ */
16
42
  key?: any;
43
+ /**
44
+ * The data object for create or update operations.
45
+ */
17
46
  data?: any;
47
+ /**
48
+ * Additional options for the SQB operation.
49
+ */
18
50
  options: any;
19
51
  }
52
+ /**
53
+ * Parses an execution context and transforms it into a SQB-compatible request.
54
+ *
55
+ * @param context - The execution context to parse.
56
+ * @returns A promise that resolves to the transformed request.
57
+ * @throws {TypeError} If the context transport is not 'http'.
58
+ * @throws {Error} If the operation is not compatible with SQB Adapter.
59
+ */
20
60
  function parseRequest(context: ExecutionContext): Promise<TransformedRequest>;
21
61
  }
package/sqb-adapter.js CHANGED
@@ -1,12 +1,27 @@
1
1
  import { EntityMetadata } from '@sqb/connect';
2
2
  import _prepareFilter from './adapter-utils/prepare-filter.js';
3
+ /**
4
+ * SQBAdapter namespace provides types and utility functions for integrating SQB with Opra.
5
+ */
3
6
  export var SQBAdapter;
4
7
  (function (SQBAdapter) {
5
8
  /**
6
- * @deprecated Use prepareFilter instead
9
+ * Parses the given filter input into a SQB filter expression.
10
+ * @deprecated Use {@link prepareFilter} instead.
7
11
  */
8
12
  SQBAdapter.parseFilter = _prepareFilter;
13
+ /**
14
+ * Prepares the given filter input into a SQB filter expression.
15
+ */
9
16
  SQBAdapter.prepareFilter = _prepareFilter;
17
+ /**
18
+ * Parses an execution context and transforms it into a SQB-compatible request.
19
+ *
20
+ * @param context - The execution context to parse.
21
+ * @returns A promise that resolves to the transformed request.
22
+ * @throws {TypeError} If the context transport is not 'http'.
23
+ * @throws {Error} If the operation is not compatible with SQB Adapter.
24
+ */
10
25
  async function parseRequest(context) {
11
26
  if (context.transport !== 'http') {
12
27
  throw new TypeError('SQBAdapter can parse only HttpContext');
@@ -37,7 +52,7 @@ export var SQBAdapter;
37
52
  controller.parameters.find(p => p.keyParam);
38
53
  const key = keyParam && ctx.pathParams[String(keyParam.name)];
39
54
  const options = {
40
- filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
55
+ filter: SQBAdapter.prepareFilter(ctx.queryParams.filter),
41
56
  };
42
57
  return {
43
58
  method: 'delete',
@@ -47,14 +62,14 @@ export var SQBAdapter;
47
62
  }
48
63
  case 'Entity.DeleteMany': {
49
64
  const options = {
50
- filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
65
+ filter: SQBAdapter.prepareFilter(ctx.queryParams.filter),
51
66
  };
52
67
  return { method: 'deleteMany', options };
53
68
  }
54
69
  case 'Entity.FindMany': {
55
70
  const options = {
56
71
  count: ctx.queryParams.count,
57
- filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
72
+ filter: SQBAdapter.prepareFilter(ctx.queryParams.filter),
58
73
  projection: ctx.queryParams.projection ||
59
74
  __oprDef.compositionOptions.defaultProjection,
60
75
  limit: ctx.queryParams.limit || __oprDef.compositionOptions.defaultLimit,
@@ -96,7 +111,7 @@ export var SQBAdapter;
96
111
  const key = keyParam && ctx.pathParams[String(keyParam.name)];
97
112
  const options = {
98
113
  projection: ctx.queryParams.projection,
99
- filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
114
+ filter: SQBAdapter.prepareFilter(ctx.queryParams.filter),
100
115
  };
101
116
  return {
102
117
  method: 'update',
@@ -108,7 +123,7 @@ export var SQBAdapter;
108
123
  case 'Entity.UpdateMany': {
109
124
  const data = await ctx.getBody();
110
125
  const options = {
111
- filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
126
+ filter: SQBAdapter.prepareFilter(ctx.queryParams.filter),
112
127
  };
113
128
  return {
114
129
  method: 'updateMany',
@@ -1,243 +1,225 @@
1
- import type { PartialDTO, PatchDTO, RequiredSome, Type } from 'ts-gems';
1
+ import type { DTO, 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
  /**
5
- * @namespace SqbCollectionService
5
+ * Options for SqbCollectionService.
6
6
  */
7
7
  export declare namespace SqbCollectionService {
8
+ /**
9
+ * Configuration options for SqbCollectionService.
10
+ */
8
11
  interface Options extends SqbEntityService.Options {
12
+ /**
13
+ * Default maximum number of records returned by `findMany`.
14
+ */
9
15
  defaultLimit?: SqbCollectionService<any>['defaultLimit'];
16
+ /**
17
+ * Optional interceptor for the service operations.
18
+ */
10
19
  interceptor?: SqbCollectionService<any>['interceptor'];
11
20
  }
21
+ }
22
+ /**
23
+ * Service for managing a collection of entities backed by an SQB data source.
24
+ *
25
+ * @typeParam T - The entity type managed by this service
26
+ */
27
+ export declare class SqbCollectionService<T extends object = object> extends SqbEntityService<T> {
12
28
  /**
13
- * Represents options for "create" operation
14
- *
15
- * @interface
29
+ * Default maximum number of records returned by `findMany`.
16
30
  */
17
- interface CreateOptions extends SqbEntityService.CreateOptions {
18
- }
31
+ defaultLimit: number;
19
32
  /**
20
- * Represents options for "count" operation
33
+ * Constructs a new instance.
21
34
  *
22
- * @interface
35
+ * @param dataType - The data type of the collection elements.
36
+ * @param options - Options for the collection service.
23
37
  */
24
- interface CountOptions extends SqbEntityService.CountOptions {
25
- }
38
+ constructor(dataType: Type<T> | string, options?: SqbCollectionService.Options);
26
39
  /**
27
- * Represents options for "delete" operation
40
+ * Asserts that a resource with the given ID exists.
41
+ * Throws {@link ResourceNotAvailableError} if it does not.
28
42
  *
29
- * @interface
43
+ * @param id - The ID of the resource to check.
44
+ * @param options - Optional existence check options.
45
+ * @throws {@link ResourceNotAvailableError} If the resource does not exist.
30
46
  */
31
- interface DeleteOptions extends SqbEntityService.DeleteOptions {
32
- }
47
+ assert(id: SQBAdapter.IdOrIds, options?: SqbEntityService.ExistsOptions): Promise<void>;
33
48
  /**
34
- * Represents options for "deleteMany" operation
49
+ * Creates a new resource and returns it with the requested projection.
35
50
  *
36
- * @interface
51
+ * @param input - The input data for the new resource.
52
+ * @param options - Options including a required `projection`.
53
+ * @returns The created resource as a partial DTO.
37
54
  */
38
- interface DeleteManyOptions extends SqbEntityService.DeleteManyOptions {
39
- }
55
+ create(input: PartialDTO<T>, options: RequiredSome<SqbEntityService.CreateOptions, 'projection'>): Promise<PartialDTO<T>>;
40
56
  /**
41
- * Represents options for "exists" operation
57
+ * Creates a new resource and returns the full DTO.
42
58
  *
43
- * @interface
59
+ * @param input - The input data for the new resource.
60
+ * @param options - Optional create options.
61
+ * @returns The created resource as a full DTO.
44
62
  */
45
- interface ExistsOptions extends SqbEntityService.ExistsOptions {
46
- }
63
+ create(input: PartialDTO<T>, options?: SqbEntityService.CreateOptions): Promise<T>;
47
64
  /**
48
- * Represents options for "existsOne" operation
65
+ * Creates a new resource without returning it.
49
66
  *
50
- * @interface
67
+ * @param input - The input data for the new resource.
68
+ * @param options - Optional create options.
51
69
  */
52
- interface ExistsOneOptions extends SqbEntityService.ExistsOptions {
53
- }
70
+ createOnly(input: PartialDTO<T>, options?: SqbEntityService.CreateOptions): Promise<void>;
54
71
  /**
55
- * Represents options for "findOne" operation
72
+ * Returns the number of records matching the given options.
56
73
  *
57
- * @interface
74
+ * @param options - Options for the count operation.
75
+ * @returns The number of matching records.
58
76
  */
59
- interface FindOneOptions extends SqbEntityService.FindOneOptions {
60
- }
77
+ count(options?: SqbEntityService.CountOptions): Promise<number>;
61
78
  /**
62
- * Represents options for "findMany" operation
79
+ * Deletes the record with the given ID.
63
80
  *
64
- * @interface
81
+ * @param id - The ID of the record to delete.
82
+ * @param options - Optional delete options.
83
+ * @returns The number of records deleted.
65
84
  */
66
- interface FindManyOptions extends SqbEntityService.FindManyOptions {
67
- }
85
+ delete(id: SQBAdapter.IdOrIds, options?: SqbEntityService.DeleteOptions): Promise<number>;
68
86
  /**
69
- * Represents options for "update" operation
87
+ * Deletes all records matching the given options.
70
88
  *
71
- * @interface
89
+ * @param options - Options including filter criteria.
90
+ * @returns The number of records deleted.
72
91
  */
73
- interface UpdateOptions extends SqbEntityService.UpdateOneOptions {
74
- }
92
+ deleteMany(options?: SqbEntityService.DeleteManyOptions): Promise<number>;
75
93
  /**
76
- * Represents options for "updateOnly" operation
94
+ * Checks whether a record with the given ID exists.
77
95
  *
78
- * @interface
96
+ * @param id - The ID to check.
97
+ * @param options - Optional query options.
98
+ * @returns `true` if the record exists, `false` otherwise.
79
99
  */
80
- interface UpdateOnlyOptions extends SqbEntityService.UpdateOneOptions {
81
- }
100
+ exists(id: SQBAdapter.IdOrIds, options?: SqbEntityService.ExistsOptions): Promise<boolean>;
82
101
  /**
83
- * Represents options for "updateMany" operation
102
+ * Checks whether any record matching the given options exists.
84
103
  *
85
- * @interface
104
+ * @param options - Optional query options.
105
+ * @returns `true` if at least one matching record exists, `false` otherwise.
86
106
  */
87
- interface UpdateManyOptions extends SqbEntityService.UpdateManyOptions {
88
- }
89
- }
90
- /**
91
- * @class SqbCollectionService
92
- * @template T - The data type class type of the resource
93
- */
94
- export declare class SqbCollectionService<T extends object = object> extends SqbEntityService<T> {
95
- /**
96
- * Represents default limit for findMany operation
97
- */
98
- defaultLimit: number;
99
- /**
100
- * Constructs a new instance
101
- *
102
- * @param {Type | string} dataType - The data type of the array elements.
103
- * @param {SqbCollectionService.Options} [options] - The options for the array service.
104
- * @constructor
105
- */
106
- constructor(dataType: Type<T> | string, options?: SqbCollectionService.Options);
107
- /**
108
- * Asserts the existence of a resource with the given ID.
109
- * Throws a ResourceNotFoundError if the resource does not exist.
110
- *
111
- * @param {SQBAdapter.IdOrIds} id - The ID of the resource to assert.
112
- * @param {SqbCollectionService.ExistsOptions} [options] - Optional options for checking the existence.
113
- * @returns {Promise<void>} - A Promise that resolves when the resource exists.
114
- * @throws {ResourceNotAvailableError} - If the resource does not exist.
115
- */
116
- assert(id: SQBAdapter.IdOrIds, options?: SqbCollectionService.ExistsOptions): Promise<void>;
107
+ existsOne(options?: SqbEntityService.ExistsOptions): Promise<boolean>;
117
108
  /**
118
- * Creates a new resource
109
+ * Finds a record by ID and returns it with the requested projection.
119
110
  *
120
- * @param {PartialDTO<T>} input - The input data
121
- * @param {SqbCollectionService.CreateOptions} [options] - The options object
122
- * @returns {Promise<PartialDTO<T>>} A promise that resolves to the created resource
123
- * @throws {Error} if an unknown error occurs while creating the resource
111
+ * @param id - The ID of the record.
112
+ * @param options - Options including a required `projection`.
113
+ * @returns The found record as a partial DTO, or `undefined` if not found.
124
114
  */
125
- create(input: PartialDTO<T>, options: RequiredSome<SqbCollectionService.CreateOptions, 'projection'>): Promise<PartialDTO<T>>;
126
- create(input: PartialDTO<T>, options?: SqbCollectionService.CreateOptions): Promise<T>;
115
+ findById(id: SQBAdapter.IdOrIds, options?: RequiredSome<SqbEntityService.FindOneOptions, 'projection'>): Promise<PartialDTO<T> | undefined>;
127
116
  /**
128
- * Creates a new resource
117
+ * Finds a record by ID and returns the whole DTO.
129
118
  *
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
119
+ * @param id - The ID of the record.
120
+ * @param options - Optional query options.
121
+ * @returns The found record, or `undefined` if not found.
134
122
  */
135
- createOnly(input: PartialDTO<T>, options?: SqbCollectionService.CreateOptions): Promise<void>;
123
+ findById(id: SQBAdapter.IdOrIds, options?: SqbEntityService.FindOneOptions): Promise<DTO<T> | undefined>;
136
124
  /**
137
- * Returns the count of records based on the provided options
125
+ * Finds the first record matching the given options and returns it with the requested projection.
138
126
  *
139
- * @param {SqbCollectionService.CountOptions} options - The options for the count operation.
140
- * @return {Promise<number>} - A promise that resolves to the count of records
127
+ * @param options - Options including a required `projection`.
128
+ * @returns A promise that resolves to the found record as a partial DTO, or `undefined` if not found.
141
129
  */
142
- count(options?: SqbCollectionService.CountOptions): Promise<number>;
130
+ findOne(options: RequiredSome<SqbEntityService.FindOneOptions, 'projection'>): Promise<PartialDTO<T> | undefined>;
143
131
  /**
144
- * Deletes a record from the collection.
132
+ * Finds the first record matching the given options and returns the whole DTO.
145
133
  *
146
- * @param {SQBAdapter.IdOrIds} id - The ID of the document to delete.
147
- * @param {SqbCollectionService.DeleteOptions} [options] - Optional delete options.
148
- * @return {Promise<number>} - A Promise that resolves to the number of documents deleted.
134
+ * @param options - Optional query options.
135
+ * @returns A promise that resolves to the found record, or `undefined` if not found.
149
136
  */
150
- delete(id: SQBAdapter.IdOrIds, options?: SqbCollectionService.DeleteOptions): Promise<number>;
137
+ findOne(options?: SqbEntityService.FindOneOptions): Promise<DTO<T> | undefined>;
151
138
  /**
152
- * Deletes multiple documents from the collection that meet the specified filter criteria.
139
+ * Finds multiple records matching the given options and returns partial DTOs.
153
140
  *
154
- * @param {SqbCollectionService.DeleteManyOptions} options - The options for the delete operation.
155
- * @return {Promise<number>} - A promise that resolves to the number of documents deleted.
141
+ * @param options - Options including a required `projection`.
142
+ * @returns An array of matching records as partial DTOs.
156
143
  */
157
- deleteMany(options?: SqbCollectionService.DeleteManyOptions): Promise<number>;
144
+ findMany(options?: RequiredSome<SqbEntityService.FindManyOptions, 'projection'>): Promise<PartialDTO<T>[]>;
158
145
  /**
159
- * Checks if a record with the given id exists.
146
+ * Finds multiple records matching the given options and returns whole DTOs.
160
147
  *
161
- * @param {SQBAdapter.IdOrIds} id - The id of the object to check.
162
- * @param {SqbCollectionService.ExistsOptions} [options] - The options for the query (optional).
163
- * @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
148
+ * @param options - Optional query options.
149
+ * @returns An array of matching records as full DTOs.
164
150
  */
165
- exists(id: SQBAdapter.IdOrIds, options?: SqbCollectionService.ExistsOptions): Promise<boolean>;
151
+ findMany(options?: SqbEntityService.FindManyOptions): Promise<DTO<T>[]>;
166
152
  /**
167
- * Checks if a record with the given arguments exists.
153
+ * Finds multiple records and returns them together with the total count of matches.
168
154
  *
169
- * @param {SqbCollectionService.ExistsOneOptions} [options] - The options for the query (optional).
170
- * @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
155
+ * @param options - Options including a required `projection`.
156
+ * @returns An object with `items` (partial DTOs) and `count` (total matches).
171
157
  */
172
- existsOne(options?: SqbCollectionService.ExistsOneOptions): Promise<boolean>;
173
- /**
174
- * Finds a record by ID.
175
- *
176
- * @param {SQBAdapter.IdOrIds} id - The ID of the record.
177
- * @param {SqbCollectionService.FindOneOptions} [options] - The options for the find query.
178
- * @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
179
- */
180
- findById(id: SQBAdapter.IdOrIds, options?: SqbCollectionService.FindOneOptions): Promise<PartialDTO<T> | undefined>;
158
+ findManyWithCount(options?: RequiredSome<SqbEntityService.FindManyOptions, 'projection'>): Promise<{
159
+ count: number;
160
+ items: PartialDTO<T>[];
161
+ }>;
181
162
  /**
182
- * Finds a record in the collection that matches the specified options.
163
+ * Finds multiple records and returns them together with the total count of matches.
183
164
  *
184
- * @param {SqbCollectionService.FindOneOptions} options - The options for the query.
185
- * @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
165
+ * @param options - Optional query options.
166
+ * @returns An object with `items` (full DTOs) and `count` (total matches).
186
167
  */
187
- findOne(options?: SqbCollectionService.FindOneOptions): Promise<PartialDTO<T> | undefined>;
168
+ findManyWithCount(options?: SqbEntityService.FindManyOptions): Promise<{
169
+ count: number;
170
+ items: DTO<T>[];
171
+ }>;
188
172
  /**
189
- * Finds multiple records in collection.
173
+ * Retrieves a record by ID. Throws if the record does not exist.
190
174
  *
191
- * @param {SqbCollectionService.FindManyOptions} options - The options for the find operation.
192
- * @return A Promise that resolves to an array of partial outputs of type T.
175
+ * @param id - The ID of the record to retrieve.
176
+ * @param options - Options including a required `projection`.
177
+ * @returns The record as a partial DTO.
178
+ * @throws {@link ResourceNotAvailableError} If the record does not exist.
193
179
  */
194
- findMany(options?: SqbCollectionService.FindManyOptions): Promise<PartialDTO<T>[]>;
180
+ get(id: SQBAdapter.IdOrIds, options?: RequiredSome<SqbEntityService.FindOneOptions, 'projection'>): Promise<PartialDTO<T>>;
195
181
  /**
196
- * Finds multiple records in the collection and returns both records (max limit)
197
- * and total count that matched the given criteria
182
+ * Retrieves a record by ID. Throws if the record does not exist.
198
183
  *
199
- * @param {SqbCollectionService.FindManyOptions} options - The options for the find operation.
200
- * @return A Promise that resolves to an array of partial outputs of type T and total count.
184
+ * @param id - The ID of the record to retrieve.
185
+ * @param options - Optional query options.
186
+ * @returns The record as a full DTO.
187
+ * @throws {@link ResourceNotAvailableError} If the record does not exist.
201
188
  */
202
- findManyWithCount(options?: SqbCollectionService.FindManyOptions): Promise<{
203
- count: number;
204
- items: PartialDTO<T>[];
205
- }>;
189
+ get(id: SQBAdapter.IdOrIds, options?: SqbEntityService.FindOneOptions): Promise<DTO<T>>;
206
190
  /**
207
- * Retrieves a records from the collection by its ID. Throws error if not found.
191
+ * Updates a record by ID and returns the updated record with the requested projection.
208
192
  *
209
- * @param {SQBAdapter.IdOrIds} id - The ID of the document to retrieve.
210
- * @param {SqbCollectionService.FindOneOptions} [options] - Optional options for the findOne operation.
211
- * @returns {Promise<PartialDTO<T>>} - A promise that resolves to the retrieved document,
212
- * or rejects with a ResourceNotFoundError if the document does not exist.
213
- * @throws {ResourceNotAvailableError} - If the document with the specified ID does not exist.
193
+ * @param id - The ID of the record to update.
194
+ * @param input - The fields to update.
195
+ * @param options - Options including a required `projection`.
196
+ * @returns The updated record as a partial DTO, or `undefined` if not found.
214
197
  */
215
- get(id: SQBAdapter.IdOrIds, options?: SqbCollectionService.FindOneOptions): Promise<PartialDTO<T>>;
198
+ update(id: SQBAdapter.IdOrIds, input: PatchDTO<T>, options?: RequiredSome<SqbEntityService.UpdateOneOptions, 'projection'>): Promise<PartialDTO<T> | undefined>;
216
199
  /**
217
- * Updates a record with the given id in the collection.
200
+ * Updates a record by ID and returns the full updated DTO.
218
201
  *
219
- * @param {SQBAdapter.IdOrIds} id - The id of the document to update.
220
- * @param {PatchDTO<T>} input - The partial input object containing the fields to update.
221
- * @param {SqbCollectionService.UpdateOptions} [options] - The options for the update operation.
222
- * @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the updated document or
223
- * undefined if the document was not found.
202
+ * @param id - The ID of the record to update.
203
+ * @param input - The fields to update.
204
+ * @param options - Optional update options.
205
+ * @returns The updated record as a full DTO, or `undefined` if not found.
224
206
  */
225
- update(id: SQBAdapter.IdOrIds, input: PatchDTO<T>, options?: SqbCollectionService.UpdateOptions): Promise<PartialDTO<T> | undefined>;
207
+ update(id: SQBAdapter.IdOrIds, input: PatchDTO<T>, options?: SqbEntityService.UpdateOneOptions): Promise<DTO<T> | undefined>;
226
208
  /**
227
- * Updates a record in the collection with the specified ID and returns updated record count
209
+ * Updates a record by ID without returning it.
228
210
  *
229
- * @param {any} id - The ID of the document to update.
230
- * @param {PatchDTO<T>} input - The partial input data to update the document with.
231
- * @param {SqbCollectionService.UpdateOptions} options - The options for updating the document.
232
- * @returns {Promise<number>} - A promise that resolves to the number of documents modified.
211
+ * @param id - The ID of the record to update.
212
+ * @param input - The fields to update.
213
+ * @param options - Optional update options.
214
+ * @returns The number of records modified.
233
215
  */
234
- updateOnly(id: SQBAdapter.IdOrIds, input: PatchDTO<T>, options?: SqbCollectionService.UpdateOnlyOptions): Promise<number>;
216
+ updateOnly(id: SQBAdapter.IdOrIds, input: PatchDTO<T>, options?: SqbEntityService.UpdateOneOptions): Promise<number>;
235
217
  /**
236
- * Updates multiple records in the collection based on the specified input and options.
218
+ * Updates all records matching the given options.
237
219
  *
238
- * @param {PatchDTO<T>} input - The partial input to update the documents with.
239
- * @param {SqbCollectionService.UpdateManyOptions} options - The options for updating the documents.
240
- * @return {Promise<number>} - A promise that resolves to the number of documents matched and modified.
220
+ * @param input - The fields to update.
221
+ * @param options - Options including filter criteria.
222
+ * @returns The number of records modified.
241
223
  */
242
- updateMany(input: PatchDTO<T>, options?: SqbCollectionService.UpdateManyOptions): Promise<number>;
224
+ updateMany(input: PatchDTO<T>, options?: SqbEntityService.UpdateManyOptions): Promise<number>;
243
225
  }