@opra/mongodb 1.26.2 → 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.
@@ -5,47 +5,43 @@ import { MongoAdapter } from '../adapter/mongo-adapter.js';
5
5
  import type { MongoPatchDTO } from '../types.js';
6
6
  import { MongoEntityService } from './mongo-entity-service.js';
7
7
  /**
8
- *
9
- * @namespace MongoSingletonService
8
+ * Options for MongoSingletonService.
10
9
  */
11
10
  export declare namespace MongoSingletonService {
12
11
  /**
13
- * The constructor options of MongoSingletonService.
14
- *
15
- * @interface Options
16
- * @extends MongoService.Options
12
+ * Configuration options for MongoSingletonService.
17
13
  */
18
14
  interface Options extends MongoEntityService.Options {
15
+ /**
16
+ * The unique identifier for the singleton record.
17
+ */
19
18
  _id?: MongoAdapter.AnyId;
20
19
  }
21
20
  }
22
21
  /**
23
- * A class that provides access to a MongoDB collection, with support for singleton document operations.
24
- * @class MongoSingletonService
25
- * @extends MongoService
26
- * @template T - The type of document stored in the collection
22
+ * Service for managing a single entity record backed by a MongoDB data source.
23
+ *
24
+ * @template T - The entity type managed by this service.
27
25
  */
28
26
  export declare class MongoSingletonService<T extends mongodb.Document> extends MongoEntityService<T> {
29
27
  /**
30
- * Represents a unique identifier for singleton record
31
- * @type {MongoAdapter.AnyId} _id
28
+ * The unique identifier for the singleton record.
32
29
  */
33
30
  _id: MongoAdapter.AnyId;
34
31
  /**
35
- * Constructs a new instance
32
+ * Constructs a new instance.
36
33
  *
37
- * @param {Type | string} dataType - The data type of the array elements.
38
- * @param {MongoSingletonService.Options} [options] - The options for the array service.
39
- * @constructor
34
+ * @param dataType - The entity class or its registered name.
35
+ * @param options - Options for the singleton service.
40
36
  */
41
37
  constructor(dataType: Type | string, options?: MongoSingletonService.Options);
42
38
  /**
43
39
  * Create a copy of this instance with given properties and context applied.
44
40
  *
45
- * @param {C | ServiceBase} context - The execution context or service base to associate with this instance.
46
- * @param {Nullish<P>} [overwriteProperties] - An optional object containing properties to overwrite in the current instance.
47
- * @param {Partial<C>} [overwriteContext] - An optional partial context to apply and potentially overwrite parts of the provided execution context.
48
- * @return {this & Required<P>} The current instance with the specified properties and context applied.
41
+ * @param context - The execution context or service base to associate with this instance.
42
+ * @param [overwriteProperties] - An optional object containing properties to overwrite in the current instance.
43
+ * @param [overwriteContext] - An optional partial context to apply and potentially overwrite parts of the provided execution context.
44
+ * @returns The current instance with the specified properties and context applied.
49
45
  * @template P
50
46
  * @template C
51
47
  */
@@ -53,78 +49,85 @@ export declare class MongoSingletonService<T extends mongodb.Document> extends M
53
49
  /**
54
50
  * Asserts the existence of a resource based on the given options.
55
51
  *
56
- * @param {MongoEntityService.ExistsOptions<T>} [options]
57
- * @returns {Promise<void>} A Promise that resolves when the resource exists.
58
- * @throws {ResourceNotAvailableError} If the resource does not exist.
52
+ * @param options - Optional options for checking the existence.
53
+ * @returns A Promise that resolves when the resource exists.
54
+ * @throws {@link ResourceNotAvailableError} If the resource does not exist.
59
55
  */
60
56
  assert(options?: MongoEntityService.ExistsOptions<T>): Promise<void>;
61
57
  /**
62
58
  * Creates the document in the database.
63
59
  *
64
- * @param {PartialDTO<T>} input - The partial input to create the document with.
65
- * @param {MongoEntityService.CreateOptions} [options] - The options for creating the document.
66
- * @return {Promise<PartialDTO<T>>} A promise that resolves to the partial output of the created document.
67
- * @throws {Error} Throws an error if an unknown error occurs while creating the document.
60
+ * @param input - The partial input to create the document with.
61
+ * @param options - The options for creating the document.
62
+ * @returns A promise that resolves to the partial output of the created document.
63
+ * @throws {@link Error} Throws an error if an unknown error occurs while creating the document.
68
64
  */
69
65
  create(input: PartialDTO<T>, options: RequiredSome<MongoEntityService.CreateOptions, 'projection'>): Promise<PartialDTO<T>>;
70
66
  create(input: PartialDTO<T>, options?: MongoEntityService.CreateOptions): Promise<T>;
71
67
  /**
72
68
  * Creates the document in the database.
73
69
  *
74
- * @param {PartialDTO<T>} input - The partial input to create the document with.
75
- * @param {MongoEntityService.CreateOptions} [options] - The options for creating the document.
76
- * @returns {Promise<T>} A promise that resolves create operation result
77
- * @throws {Error} Throws an error if an unknown error occurs while creating the document.
70
+ * @param input - The partial input to create the document with.
71
+ * @param options - The options for creating the document.
72
+ * @returns A promise that resolves to the created document.
73
+ * @throws {@link Error} Throws an error if an unknown error occurs while creating the document.
78
74
  */
79
75
  createOnly(input: PartialDTO<T>, options?: MongoEntityService.CreateOptions): Promise<T>;
80
76
  /**
81
77
  * Deletes a record from the database
82
78
  *
83
- * @param {MongoEntityService.DeleteOptions<T>} options - The options for deleting the record
84
- * @returns {Promise<number>} The number of records deleted
79
+ * @param options - The options for deleting the record
80
+ * @returns The number of records deleted
85
81
  */
86
82
  delete(options?: MongoEntityService.DeleteOptions<T>): Promise<number>;
87
83
  /**
88
84
  * Checks if the document exists in the database.
89
85
  *
90
- * @param {MongoEntityService.FindOneOptions<T>} [options] - The options for finding the document.
91
- * @return {Promise<boolean>} - A promise that resolves to a boolean value indicating if the document exists.
86
+ * @param [options] - The options for finding the document.
87
+ * @returns A promise that resolves to a boolean value indicating if the document exists.
92
88
  */
93
89
  exists(options?: MongoEntityService.ExistsOptions<T>): Promise<boolean>;
94
90
  /**
95
91
  * Fetches the document if it exists. Returns undefined if not found.
96
92
  *
97
- * @param {MongoEntityService.FindOneOptions<T>} [options] - The options for finding the document.
98
- * @returns {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the found document or undefined if not found.
93
+ * @param [options] - The options for finding the document.
94
+ * @returns A promise that resolves to the found document or undefined if not found.
99
95
  */
100
96
  find(options: RequiredSome<MongoEntityService.FindOneOptions<T>, 'projection'>): Promise<PartialDTO<T> | undefined>;
101
97
  find(options?: MongoEntityService.FindOneOptions<T>): Promise<T | undefined>;
102
98
  /**
103
99
  * Fetches the document from the Mongo collection service. Throws error if not found.
104
100
  *
105
- * @param {MongoEntityService.FindOneOptions<T>} options - The options to customize the query.
106
- * @return {Promise<PartialDTO<T>>} - A promise that resolves to the fetched document.
107
- * @throws {ResourceNotAvailableError} - If the document is not found in the collection
101
+ * @param options - The options to customize the query.
102
+ * @returns A promise that resolves to the fetched document.
103
+ * @throws {@link ResourceNotAvailableError} If the document is not found in the collection.
108
104
  */
109
105
  get(options: RequiredSome<MongoEntityService.FindOneOptions<T>, 'projection'>): Promise<PartialDTO<T>>;
106
+ /**
107
+ * Fetches the document from the Mongo collection service. Throws error if not found.
108
+ *
109
+ * @param options - The options to customize the query.
110
+ * @returns A promise that resolves to the fetched document.
111
+ * @throws {@link ResourceNotAvailableError} If the document is not found in the collection.
112
+ */
110
113
  get(options?: MongoEntityService.FindOneOptions<T>): Promise<T>;
111
114
  /**
112
115
  * Updates a document in the MongoDB collection
113
116
  *
114
- * @param {MongoPatchDTO<T>} input - The partial input to update the document.
115
- * @param {MongoEntityService.UpdateOneOptions<T>} [options] - The update options.
117
+ * @param input - The partial input to update the document.
118
+ * @param [options] - The update options.
116
119
  *
117
- * @return {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the updated document or undefined if not found.
120
+ * @returns A promise that resolves to the updated document or undefined if not found.
118
121
  */
119
122
  update(input: MongoPatchDTO<T> | UpdateFilter<T>, options: RequiredSome<MongoEntityService.UpdateOneOptions<T>, 'projection'>): Promise<PartialDTO<T> | undefined>;
120
123
  update(input: MongoPatchDTO<T> | UpdateFilter<T>, options?: MongoEntityService.UpdateOneOptions<T>): Promise<T | undefined>;
121
124
  /**
122
125
  * Updates a document in the MongoDB collection
123
126
  *
124
- * @param {MongoPatchDTO<T>} input - The partial input to update the document.
125
- * @param {MongoEntityService.UpdateOneOptions<T>} [options] - The update options.
127
+ * @param input - The partial input to update the document.
128
+ * @param [options] - The update options.
126
129
  *
127
- * @return {Promise<number>} - A promise that resolves to the updated document or undefined if not found.
130
+ * @returns A promise that resolves to the updated document or undefined if not found.
128
131
  */
129
132
  updateOnly(input: MongoPatchDTO<T> | UpdateFilter<T>, options?: MongoEntityService.UpdateOneOptions<T>): Promise<number>;
130
133
  }
@@ -4,23 +4,20 @@ import { ObjectId } from 'mongodb';
4
4
  import { MongoAdapter } from '../adapter/mongo-adapter.js';
5
5
  import { MongoEntityService } from './mongo-entity-service.js';
6
6
  /**
7
- * A class that provides access to a MongoDB collection, with support for singleton document operations.
8
- * @class MongoSingletonService
9
- * @extends MongoService
10
- * @template T - The type of document stored in the collection
7
+ * Service for managing a single entity record backed by a MongoDB data source.
8
+ *
9
+ * @template T - The entity type managed by this service.
11
10
  */
12
11
  export class MongoSingletonService extends MongoEntityService {
13
12
  /**
14
- * Represents a unique identifier for singleton record
15
- * @type {MongoAdapter.AnyId} _id
13
+ * The unique identifier for the singleton record.
16
14
  */
17
15
  _id;
18
16
  /**
19
- * Constructs a new instance
17
+ * Constructs a new instance.
20
18
  *
21
- * @param {Type | string} dataType - The data type of the array elements.
22
- * @param {MongoSingletonService.Options} [options] - The options for the array service.
23
- * @constructor
19
+ * @param dataType - The entity class or its registered name.
20
+ * @param options - Options for the singleton service.
24
21
  */
25
22
  constructor(dataType, options) {
26
23
  super(dataType, options);
@@ -29,10 +26,10 @@ export class MongoSingletonService extends MongoEntityService {
29
26
  /**
30
27
  * Create a copy of this instance with given properties and context applied.
31
28
  *
32
- * @param {C | ServiceBase} context - The execution context or service base to associate with this instance.
33
- * @param {Nullish<P>} [overwriteProperties] - An optional object containing properties to overwrite in the current instance.
34
- * @param {Partial<C>} [overwriteContext] - An optional partial context to apply and potentially overwrite parts of the provided execution context.
35
- * @return {this & Required<P>} The current instance with the specified properties and context applied.
29
+ * @param context - The execution context or service base to associate with this instance.
30
+ * @param [overwriteProperties] - An optional object containing properties to overwrite in the current instance.
31
+ * @param [overwriteContext] - An optional partial context to apply and potentially overwrite parts of the provided execution context.
32
+ * @returns The current instance with the specified properties and context applied.
36
33
  * @template P
37
34
  * @template C
38
35
  */
@@ -42,9 +39,9 @@ export class MongoSingletonService extends MongoEntityService {
42
39
  /**
43
40
  * Asserts the existence of a resource based on the given options.
44
41
  *
45
- * @param {MongoEntityService.ExistsOptions<T>} [options]
46
- * @returns {Promise<void>} A Promise that resolves when the resource exists.
47
- * @throws {ResourceNotAvailableError} If the resource does not exist.
42
+ * @param options - Optional options for checking the existence.
43
+ * @returns A Promise that resolves when the resource exists.
44
+ * @throws {@link ResourceNotAvailableError} If the resource does not exist.
48
45
  */
49
46
  async assert(options) {
50
47
  if (!(await this.exists(options)))
@@ -78,10 +75,10 @@ export class MongoSingletonService extends MongoEntityService {
78
75
  /**
79
76
  * Creates the document in the database.
80
77
  *
81
- * @param {PartialDTO<T>} input - The partial input to create the document with.
82
- * @param {MongoEntityService.CreateOptions} [options] - The options for creating the document.
83
- * @returns {Promise<T>} A promise that resolves create operation result
84
- * @throws {Error} Throws an error if an unknown error occurs while creating the document.
78
+ * @param input - The partial input to create the document with.
79
+ * @param options - The options for creating the document.
80
+ * @returns A promise that resolves to the created document.
81
+ * @throws {@link Error} Throws an error if an unknown error occurs while creating the document.
85
82
  */
86
83
  async createOnly(input, options) {
87
84
  const command = {
@@ -97,8 +94,8 @@ export class MongoSingletonService extends MongoEntityService {
97
94
  /**
98
95
  * Deletes a record from the database
99
96
  *
100
- * @param {MongoEntityService.DeleteOptions<T>} options - The options for deleting the record
101
- * @returns {Promise<number>} The number of records deleted
97
+ * @param options - The options for deleting the record
98
+ * @returns The number of records deleted
102
99
  */
103
100
  async delete(options) {
104
101
  const command = {
@@ -120,8 +117,8 @@ export class MongoSingletonService extends MongoEntityService {
120
117
  /**
121
118
  * Checks if the document exists in the database.
122
119
  *
123
- * @param {MongoEntityService.FindOneOptions<T>} [options] - The options for finding the document.
124
- * @return {Promise<boolean>} - A promise that resolves to a boolean value indicating if the document exists.
120
+ * @param [options] - The options for finding the document.
121
+ * @returns A promise that resolves to a boolean value indicating if the document exists.
125
122
  */
126
123
  async exists(options) {
127
124
  const command = {
@@ -201,10 +198,10 @@ export class MongoSingletonService extends MongoEntityService {
201
198
  /**
202
199
  * Updates a document in the MongoDB collection
203
200
  *
204
- * @param {MongoPatchDTO<T>} input - The partial input to update the document.
205
- * @param {MongoEntityService.UpdateOneOptions<T>} [options] - The update options.
201
+ * @param input - The partial input to update the document.
202
+ * @param [options] - The update options.
206
203
  *
207
- * @return {Promise<number>} - A promise that resolves to the updated document or undefined if not found.
204
+ * @returns A promise that resolves to the updated document or undefined if not found.
208
205
  */
209
206
  async updateOnly(input, options) {
210
207
  const command = {
package/types.d.ts CHANGED
@@ -1,19 +1,25 @@
1
1
  import type { DTO, IfNoDeepValue } from 'ts-gems';
2
+ /**
3
+ * Represents a MongoDB-specific Data Transfer Object for patch operations.
4
+ * It extends the standard patch DTO with MongoDB-specific operators like _$push and _$pull.
5
+ */
2
6
  export type MongoPatchDTO<T> = _MongoPatchDTO<DTO<T>> & PatchOperators<T>;
3
7
  /**
4
- * Returns given type as a Data Transfer Object (DTO) interface, Removes symbol keys and function properties.
5
- * @template T - The type of the data being transferred.
8
+ * Internal type for recursive MongoDB patch DTO.
6
9
  */
7
10
  type _MongoPatchDTO<T> = {
8
11
  [K in keyof T]?: Exclude<T[K], undefined> extends (infer U)[] ? _MongoPatchDTO<U>[] | null : IfNoDeepValue<NonNullable<T[K]>> extends true ? T[K] | null : // Deep process objects
9
12
  (_MongoPatchDTO<NonNullable<T[K]>> & PatchOperators<T>) | null;
10
13
  };
11
14
  /**
12
- * Pick all array properties in T
15
+ * Utility type to pick all array properties from T.
13
16
  */
14
17
  type PickArrays<T> = {
15
18
  [K in keyof T as NonNullable<T[K]> extends any[] ? K : never]: T[K];
16
19
  };
20
+ /**
21
+ * MongoDB-specific patch operators.
22
+ */
17
23
  type PatchOperators<T> = {
18
24
  _$push?: PickArrays<Partial<T>>;
19
25
  _$pull?: {