@opra/mongodb 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.
@@ -1,8 +1,7 @@
1
- import mongodb from 'mongodb';
2
- import { PartialDTO, PatchDTO, Type } from 'ts-gems';
1
+ import mongodb, { type UpdateFilter } from 'mongodb';
2
+ import type { PartialDTO, PatchDTO, RequiredSome, Type } from 'ts-gems';
3
3
  import { MongoAdapter } from './mongo-adapter.js';
4
4
  import { MongoEntityService } from './mongo-entity-service.js';
5
- import { MongoService } from './mongo-service.js';
6
5
  /**
7
6
  *
8
7
  * @namespace MongoSingletonService
@@ -17,16 +16,6 @@ export declare namespace MongoSingletonService {
17
16
  interface Options extends MongoEntityService.Options {
18
17
  _id?: MongoAdapter.AnyId;
19
18
  }
20
- interface CreateOptions extends MongoEntityService.CreateOptions {
21
- }
22
- interface DeleteOptions<T> extends MongoEntityService.DeleteOptions<T> {
23
- }
24
- interface ExistsOptions<T> extends MongoService.ExistsOptions<T> {
25
- }
26
- interface FindOneOptions<T> extends MongoEntityService.FindOneOptions<T> {
27
- }
28
- interface UpdateOptions<T> extends MongoEntityService.UpdateOptions<T> {
29
- }
30
19
  }
31
20
  /**
32
21
  * A class that provides access to a MongoDB collection, with support for singleton document operations.
@@ -51,64 +40,78 @@ export declare class MongoSingletonService<T extends mongodb.Document> extends M
51
40
  /**
52
41
  * Asserts the existence of a resource based on the given options.
53
42
  *
54
- * @param {MongoSingletonService.ExistsOptions<T>} [options]
43
+ * @param {MongoEntityService.ExistsOptions<T>} [options]
55
44
  * @returns {Promise<void>} A Promise that resolves when the resource exists.
56
45
  * @throws {ResourceNotAvailableError} If the resource does not exist.
57
46
  */
58
- assert(options?: MongoSingletonService.ExistsOptions<T>): Promise<void>;
47
+ assert(options?: MongoEntityService.ExistsOptions<T>): Promise<void>;
59
48
  /**
60
49
  * Creates the document in the database.
61
50
  *
62
51
  * @param {PartialDTO<T>} input - The partial input to create the document with.
63
- * @param {MongoSingletonService.CreateOptions} [options] - The options for creating the document.
52
+ * @param {MongoEntityService.CreateOptions} [options] - The options for creating the document.
64
53
  * @return {Promise<PartialDTO<T>>} A promise that resolves to the partial output of the created document.
65
54
  * @throws {Error} Throws an error if an unknown error occurs while creating the document.
66
55
  */
67
- create(input: PartialDTO<T>, options?: MongoSingletonService.CreateOptions): Promise<PartialDTO<T>>;
56
+ create(input: PartialDTO<T>, options: RequiredSome<MongoEntityService.CreateOptions, 'projection'>): Promise<PartialDTO<T>>;
57
+ create(input: PartialDTO<T>, options?: MongoEntityService.CreateOptions): Promise<T>;
58
+ /**
59
+ * Creates the document in the database.
60
+ *
61
+ * @param {DTO<T>} input - The partial input to create the document with.
62
+ * @param {MongoEntityService.CreateOptions} [options] - The options for creating the document.
63
+ * @returns {Promise<T>} A promise that resolves create operation result
64
+ * @throws {Error} Throws an error if an unknown error occurs while creating the document.
65
+ */
66
+ createOnly(input: PartialDTO<T>, options?: MongoEntityService.CreateOptions): Promise<T>;
68
67
  /**
69
68
  * Deletes a record from the database
70
69
  *
71
- * @param {MongoSingletonService.DeleteOptions<T>} options - The options for deleting the record
70
+ * @param {MongoEntityService.DeleteOptions<T>} options - The options for deleting the record
72
71
  * @returns {Promise<number>} The number of records deleted
73
72
  */
74
- delete(options?: MongoSingletonService.DeleteOptions<T>): Promise<number>;
73
+ delete(options?: MongoEntityService.DeleteOptions<T>): Promise<number>;
75
74
  /**
76
75
  * Checks if the document exists in the database.
77
76
  *
77
+ * @param {MongoEntityService.FindOneOptions<T>} [options] - The options for finding the document.
78
78
  * @return {Promise<boolean>} - A promise that resolves to a boolean value indicating if the document exists.
79
79
  */
80
- exists(options?: MongoSingletonService.ExistsOptions<T>): Promise<boolean>;
80
+ exists(options?: MongoEntityService.ExistsOptions<T>): Promise<boolean>;
81
81
  /**
82
82
  * Fetches the document if it exists. Returns undefined if not found.
83
83
  *
84
- * @param {MongoSingletonService.FindOneOptions<T>} [options] - The options for finding the document.
84
+ * @param {MongoEntityService.FindOneOptions<T>} [options] - The options for finding the document.
85
85
  * @returns {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the found document or undefined if not found.
86
86
  */
87
- find(options?: MongoSingletonService.FindOneOptions<T>): Promise<PartialDTO<T> | undefined>;
87
+ find(options: RequiredSome<MongoEntityService.FindOneOptions<T>, 'projection'>): Promise<PartialDTO<T> | undefined>;
88
+ find(options?: MongoEntityService.FindOneOptions<T>): Promise<T | undefined>;
88
89
  /**
89
90
  * Fetches the document from the Mongo collection service. Throws error if not found.
90
91
  *
91
- * @param {MongoSingletonService.FindOneOptions<T>} options - The options to customize the query.
92
+ * @param {MongoEntityService.FindOneOptions<T>} options - The options to customize the query.
92
93
  * @return {Promise<PartialDTO<T>>} - A promise that resolves to the fetched document.
93
94
  * @throws {ResourceNotAvailableError} - If the document is not found in the collection.
94
95
  */
95
- get(options?: MongoSingletonService.FindOneOptions<T>): Promise<PartialDTO<T>>;
96
+ get(options: RequiredSome<MongoEntityService.FindOneOptions<T>, 'projection'>): Promise<PartialDTO<T>>;
97
+ get(options?: MongoEntityService.FindOneOptions<T>): Promise<T>;
96
98
  /**
97
99
  * Updates a document in the MongoDB collection.
98
100
  *
99
101
  * @param {PatchDTO<T>} input - The partial input to update the document.
100
- * @param {MongoSingletonService.UpdateOptions<T>} [options] - The update options.
102
+ * @param {MongoEntityService.UpdateOneOptions<T>} [options] - The update options.
101
103
  *
102
- * @return {Promise<number>} - A promise that resolves to the updated document or undefined if not found.
104
+ * @return {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the updated document or undefined if not found.
103
105
  */
104
- updateOnly(input: PatchDTO<T>, options?: MongoSingletonService.UpdateOptions<T>): Promise<number>;
106
+ update(input: PatchDTO<T> | UpdateFilter<T>, options: RequiredSome<MongoEntityService.UpdateOneOptions<T>, 'projection'>): Promise<PartialDTO<T> | undefined>;
107
+ update(input: PatchDTO<T> | UpdateFilter<T>, options?: MongoEntityService.UpdateOneOptions<T>): Promise<T | undefined>;
105
108
  /**
106
109
  * Updates a document in the MongoDB collection.
107
110
  *
108
111
  * @param {PatchDTO<T>} input - The partial input to update the document.
109
- * @param {MongoSingletonService.UpdateOptions<T>} [options] - The update options.
112
+ * @param {MongoEntityService.UpdateOneOptions<T>} [options] - The update options.
110
113
  *
111
- * @return {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the updated document or undefined if not found.
114
+ * @return {Promise<number>} - A promise that resolves to the updated document or undefined if not found.
112
115
  */
113
- update(input: PatchDTO<T>, options?: MongoSingletonService.UpdateOptions<T>): Promise<PartialDTO<T> | undefined>;
116
+ updateOnly(input: PatchDTO<T> | UpdateFilter<T>, options?: MongoEntityService.UpdateOneOptions<T>): Promise<number>;
114
117
  }