@nimbus-cqrs/mongodb 2.0.0-beta.0

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 (121) hide show
  1. package/LICENSE +85 -0
  2. package/README.md +26 -0
  3. package/esm/_dnt.shims.d.ts +2 -0
  4. package/esm/_dnt.shims.d.ts.map +1 -0
  5. package/esm/_dnt.shims.js +57 -0
  6. package/esm/deps/jsr.io/@std/fmt/1.0.10/colors.d.ts +700 -0
  7. package/esm/deps/jsr.io/@std/fmt/1.0.10/colors.d.ts.map +1 -0
  8. package/esm/deps/jsr.io/@std/fmt/1.0.10/colors.js +903 -0
  9. package/esm/deps/jsr.io/@std/text/1.0.18/_util.d.ts +3 -0
  10. package/esm/deps/jsr.io/@std/text/1.0.18/_util.d.ts.map +1 -0
  11. package/esm/deps/jsr.io/@std/text/1.0.18/_util.js +13 -0
  12. package/esm/deps/jsr.io/@std/text/1.0.18/closest_string.d.ts +42 -0
  13. package/esm/deps/jsr.io/@std/text/1.0.18/closest_string.d.ts.map +1 -0
  14. package/esm/deps/jsr.io/@std/text/1.0.18/closest_string.js +46 -0
  15. package/esm/deps/jsr.io/@std/text/1.0.18/compare_similarity.d.ts +47 -0
  16. package/esm/deps/jsr.io/@std/text/1.0.18/compare_similarity.d.ts.map +1 -0
  17. package/esm/deps/jsr.io/@std/text/1.0.18/compare_similarity.js +39 -0
  18. package/esm/deps/jsr.io/@std/text/1.0.18/levenshtein_distance.d.ts +23 -0
  19. package/esm/deps/jsr.io/@std/text/1.0.18/levenshtein_distance.d.ts.map +1 -0
  20. package/esm/deps/jsr.io/@std/text/1.0.18/levenshtein_distance.js +127 -0
  21. package/esm/deps/jsr.io/@std/text/1.0.18/mod.d.ts +26 -0
  22. package/esm/deps/jsr.io/@std/text/1.0.18/mod.d.ts.map +1 -0
  23. package/esm/deps/jsr.io/@std/text/1.0.18/mod.js +27 -0
  24. package/esm/deps/jsr.io/@std/text/1.0.18/to_camel_case.d.ts +16 -0
  25. package/esm/deps/jsr.io/@std/text/1.0.18/to_camel_case.d.ts.map +1 -0
  26. package/esm/deps/jsr.io/@std/text/1.0.18/to_camel_case.js +22 -0
  27. package/esm/deps/jsr.io/@std/text/1.0.18/to_kebab_case.d.ts +16 -0
  28. package/esm/deps/jsr.io/@std/text/1.0.18/to_kebab_case.d.ts.map +1 -0
  29. package/esm/deps/jsr.io/@std/text/1.0.18/to_kebab_case.js +21 -0
  30. package/esm/deps/jsr.io/@std/text/1.0.18/to_pascal_case.d.ts +16 -0
  31. package/esm/deps/jsr.io/@std/text/1.0.18/to_pascal_case.d.ts.map +1 -0
  32. package/esm/deps/jsr.io/@std/text/1.0.18/to_pascal_case.js +21 -0
  33. package/esm/deps/jsr.io/@std/text/1.0.18/to_snake_case.d.ts +16 -0
  34. package/esm/deps/jsr.io/@std/text/1.0.18/to_snake_case.d.ts.map +1 -0
  35. package/esm/deps/jsr.io/@std/text/1.0.18/to_snake_case.js +21 -0
  36. package/esm/deps/jsr.io/@std/text/1.0.18/word_similarity_sort.d.ts +42 -0
  37. package/esm/deps/jsr.io/@std/text/1.0.18/word_similarity_sort.d.ts.map +1 -0
  38. package/esm/deps/jsr.io/@std/text/1.0.18/word_similarity_sort.js +43 -0
  39. package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts +14 -0
  40. package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts.map +1 -0
  41. package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.js +65 -0
  42. package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts +20 -0
  43. package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts.map +1 -0
  44. package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.js +43 -0
  45. package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts +44 -0
  46. package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts.map +1 -0
  47. package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.js +47 -0
  48. package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts +44 -0
  49. package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts.map +1 -0
  50. package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.js +51 -0
  51. package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts +31 -0
  52. package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts.map +1 -0
  53. package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.js +37 -0
  54. package/esm/index.d.ts +21 -0
  55. package/esm/index.d.ts.map +1 -0
  56. package/esm/index.js +20 -0
  57. package/esm/lib/crud/aggregate.d.ts +31 -0
  58. package/esm/lib/crud/aggregate.d.ts.map +1 -0
  59. package/esm/lib/crud/aggregate.js +37 -0
  60. package/esm/lib/crud/bulkWrite.d.ts +25 -0
  61. package/esm/lib/crud/bulkWrite.d.ts.map +1 -0
  62. package/esm/lib/crud/bulkWrite.js +22 -0
  63. package/esm/lib/crud/countDocuments.d.ts +25 -0
  64. package/esm/lib/crud/countDocuments.d.ts.map +1 -0
  65. package/esm/lib/crud/countDocuments.js +22 -0
  66. package/esm/lib/crud/deleteMany.d.ts +25 -0
  67. package/esm/lib/crud/deleteMany.d.ts.map +1 -0
  68. package/esm/lib/crud/deleteMany.js +22 -0
  69. package/esm/lib/crud/deleteOne.d.ts +25 -0
  70. package/esm/lib/crud/deleteOne.d.ts.map +1 -0
  71. package/esm/lib/crud/deleteOne.js +22 -0
  72. package/esm/lib/crud/find.d.ts +39 -0
  73. package/esm/lib/crud/find.d.ts.map +1 -0
  74. package/esm/lib/crud/find.js +53 -0
  75. package/esm/lib/crud/findOne.d.ts +29 -0
  76. package/esm/lib/crud/findOne.d.ts.map +1 -0
  77. package/esm/lib/crud/findOne.js +38 -0
  78. package/esm/lib/crud/findOneAndDelete.d.ts +31 -0
  79. package/esm/lib/crud/findOneAndDelete.d.ts.map +1 -0
  80. package/esm/lib/crud/findOneAndDelete.js +44 -0
  81. package/esm/lib/crud/findOneAndReplace.d.ts +33 -0
  82. package/esm/lib/crud/findOneAndReplace.d.ts.map +1 -0
  83. package/esm/lib/crud/findOneAndReplace.js +45 -0
  84. package/esm/lib/crud/findOneAndUpdate.d.ts +33 -0
  85. package/esm/lib/crud/findOneAndUpdate.d.ts.map +1 -0
  86. package/esm/lib/crud/findOneAndUpdate.js +45 -0
  87. package/esm/lib/crud/insertMany.d.ts +25 -0
  88. package/esm/lib/crud/insertMany.d.ts.map +1 -0
  89. package/esm/lib/crud/insertMany.js +22 -0
  90. package/esm/lib/crud/insertOne.d.ts +25 -0
  91. package/esm/lib/crud/insertOne.d.ts.map +1 -0
  92. package/esm/lib/crud/insertOne.js +22 -0
  93. package/esm/lib/crud/replaceOne.d.ts +27 -0
  94. package/esm/lib/crud/replaceOne.d.ts.map +1 -0
  95. package/esm/lib/crud/replaceOne.js +23 -0
  96. package/esm/lib/crud/updateMany.d.ts +27 -0
  97. package/esm/lib/crud/updateMany.d.ts.map +1 -0
  98. package/esm/lib/crud/updateMany.js +23 -0
  99. package/esm/lib/crud/updateOne.d.ts +27 -0
  100. package/esm/lib/crud/updateOne.d.ts.map +1 -0
  101. package/esm/lib/crud/updateOne.js +23 -0
  102. package/esm/lib/deployCollection.d.ts +33 -0
  103. package/esm/lib/deployCollection.d.ts.map +1 -0
  104. package/esm/lib/deployCollection.js +125 -0
  105. package/esm/lib/handleMongoError.d.ts +10 -0
  106. package/esm/lib/handleMongoError.d.ts.map +1 -0
  107. package/esm/lib/handleMongoError.js +29 -0
  108. package/esm/lib/mongoConnectionManager.d.ts +107 -0
  109. package/esm/lib/mongoConnectionManager.d.ts.map +1 -0
  110. package/esm/lib/mongoConnectionManager.js +195 -0
  111. package/esm/lib/mongoJSON.d.ts +36 -0
  112. package/esm/lib/mongoJSON.d.ts.map +1 -0
  113. package/esm/lib/mongoJSON.js +96 -0
  114. package/esm/lib/repository.d.ts +145 -0
  115. package/esm/lib/repository.d.ts.map +1 -0
  116. package/esm/lib/repository.js +235 -0
  117. package/esm/lib/tracing.d.ts +17 -0
  118. package/esm/lib/tracing.d.ts.map +1 -0
  119. package/esm/lib/tracing.js +62 -0
  120. package/esm/package.json +3 -0
  121. package/package.json +35 -0
@@ -0,0 +1,25 @@
1
+ import type { Collection, CountDocumentsOptions, Document, Filter } from 'mongodb';
2
+ /**
3
+ * Type to define the input for the countDocuments function.
4
+ */
5
+ export type CountDocumentsInput = {
6
+ collection: Collection<Document>;
7
+ filter: Filter<Document>;
8
+ options?: CountDocumentsOptions;
9
+ };
10
+ /**
11
+ * Type to define the countDocuments function.
12
+ */
13
+ export type CountDocuments = (input: CountDocumentsInput) => Promise<number>;
14
+ /**
15
+ * Count the number of documents in a MongoDB collection.
16
+ *
17
+ * @param {CountDocumentsInput} input - The input object.
18
+ * @param input.collection - The collection to count documents in.
19
+ * @param input.filter - The filter for the count operation.
20
+ * @param [input.options] - The count options.
21
+ *
22
+ * @returns {Promise<number>} The number of documents.
23
+ */
24
+ export declare const countDocuments: CountDocuments;
25
+ //# sourceMappingURL=countDocuments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"countDocuments.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/countDocuments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,MAAM,EACT,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAC9B,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzB,OAAO,CAAC,EAAE,qBAAqB,CAAC;CACnC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CACzB,KAAK,EAAE,mBAAmB,KACzB,OAAO,CAAC,MAAM,CAAC,CAAC;AAErB;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,EAAE,cAY5B,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { handleMongoError } from '../handleMongoError.js';
2
+ import { withSpan } from '../tracing.js';
3
+ /**
4
+ * Count the number of documents in a MongoDB collection.
5
+ *
6
+ * @param {CountDocumentsInput} input - The input object.
7
+ * @param input.collection - The collection to count documents in.
8
+ * @param input.filter - The filter for the count operation.
9
+ * @param [input.options] - The count options.
10
+ *
11
+ * @returns {Promise<number>} The number of documents.
12
+ */
13
+ export const countDocuments = ({ collection, filter, options, }) => {
14
+ return withSpan('countDocuments', collection, async () => {
15
+ try {
16
+ return await collection.countDocuments(filter, options);
17
+ }
18
+ catch (error) {
19
+ throw handleMongoError(error);
20
+ }
21
+ });
22
+ };
@@ -0,0 +1,25 @@
1
+ import type { Collection, DeleteOptions, DeleteResult, Document, Filter } from 'mongodb';
2
+ /**
3
+ * Type to define the input for the deleteMany function.
4
+ */
5
+ export type DeleteManyInput = {
6
+ collection: Collection<Document>;
7
+ filter: Filter<Document>;
8
+ options?: DeleteOptions;
9
+ };
10
+ /**
11
+ * Type to define the deleteMany function.
12
+ */
13
+ export type DeleteMany = (input: DeleteManyInput) => Promise<DeleteResult>;
14
+ /**
15
+ * Deletes multiple documents from a MongoDB collection.
16
+ *
17
+ * @param {DeleteManyInput} input - The input object.
18
+ * @param input.collection - The collection to delete from.
19
+ * @param input.filter - The filter for the delete operation.
20
+ * @param [input.options] - The delete options.
21
+ *
22
+ * @returns {Promise<DeleteResult>} The result of the delete operation.
23
+ */
24
+ export declare const deleteMany: DeleteMany;
25
+ //# sourceMappingURL=deleteMany.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/deleteMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EACV,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,MAAM,EACT,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC1B,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzB,OAAO,CAAC,EAAE,aAAa,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,CACrB,KAAK,EAAE,eAAe,KACrB,OAAO,CAAC,YAAY,CAAC,CAAC;AAE3B;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,EAAE,UAYxB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { handleMongoError } from '../handleMongoError.js';
2
+ import { withSpan } from '../tracing.js';
3
+ /**
4
+ * Deletes multiple documents from a MongoDB collection.
5
+ *
6
+ * @param {DeleteManyInput} input - The input object.
7
+ * @param input.collection - The collection to delete from.
8
+ * @param input.filter - The filter for the delete operation.
9
+ * @param [input.options] - The delete options.
10
+ *
11
+ * @returns {Promise<DeleteResult>} The result of the delete operation.
12
+ */
13
+ export const deleteMany = ({ collection, filter, options, }) => {
14
+ return withSpan('deleteMany', collection, async () => {
15
+ try {
16
+ return await collection.deleteMany(filter, options);
17
+ }
18
+ catch (error) {
19
+ throw handleMongoError(error);
20
+ }
21
+ });
22
+ };
@@ -0,0 +1,25 @@
1
+ import type { Collection, DeleteOptions, DeleteResult, Document, Filter } from 'mongodb';
2
+ /**
3
+ * Type to define the input for the deleteOne function.
4
+ */
5
+ export type DeleteOneInput = {
6
+ collection: Collection<Document>;
7
+ filter: Filter<Document>;
8
+ options?: DeleteOptions;
9
+ };
10
+ /**
11
+ * Type to define the deleteOne function.
12
+ */
13
+ export type DeleteOne = (input: DeleteOneInput) => Promise<DeleteResult>;
14
+ /**
15
+ * Deletes a single document from a MongoDB collection.
16
+ *
17
+ * @param {DeleteOneInput} input - The input object.
18
+ * @param input.collection - The collection to delete from.
19
+ * @param input.filter - The filter for the delete operation.
20
+ * @param [input.options] - The delete options.
21
+ *
22
+ * @returns {Promise<DeleteResult>} The result of the delete operation.
23
+ */
24
+ export declare const deleteOne: DeleteOne;
25
+ //# sourceMappingURL=deleteOne.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/deleteOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EACV,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,MAAM,EACT,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IACzB,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzB,OAAO,CAAC,EAAE,aAAa,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,CACpB,KAAK,EAAE,cAAc,KACpB,OAAO,CAAC,YAAY,CAAC,CAAC;AAE3B;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,EAAE,SAYvB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { handleMongoError } from '../handleMongoError.js';
2
+ import { withSpan } from '../tracing.js';
3
+ /**
4
+ * Deletes a single document from a MongoDB collection.
5
+ *
6
+ * @param {DeleteOneInput} input - The input object.
7
+ * @param input.collection - The collection to delete from.
8
+ * @param input.filter - The filter for the delete operation.
9
+ * @param [input.options] - The delete options.
10
+ *
11
+ * @returns {Promise<DeleteResult>} The result of the delete operation.
12
+ */
13
+ export const deleteOne = ({ collection, filter, options, }) => {
14
+ return withSpan('deleteOne', collection, async () => {
15
+ try {
16
+ return await collection.deleteOne(filter, options);
17
+ }
18
+ catch (error) {
19
+ throw handleMongoError(error);
20
+ }
21
+ });
22
+ };
@@ -0,0 +1,39 @@
1
+ import type { Collection, Document, Filter, FindOptions, Sort } from 'mongodb';
2
+ import type { ZodType } from 'zod';
3
+ /**
4
+ * Type to define the input for the find function.
5
+ */
6
+ export type FindInput<TData> = {
7
+ collection: Collection<Document>;
8
+ filter: Filter<Document>;
9
+ limit?: number;
10
+ skip?: number;
11
+ sort?: Sort;
12
+ project?: Document;
13
+ mapDocument: (document: Document) => TData;
14
+ outputType: ZodType;
15
+ options?: FindOptions;
16
+ };
17
+ /**
18
+ * Type to define the find function.
19
+ */
20
+ export type Find = <TData>(input: FindInput<TData>) => Promise<TData[]>;
21
+ /**
22
+ * Finds documents in a MongoDB collection and returns
23
+ * the result as an array of the specified output type.
24
+ *
25
+ * @param {FindInput} input - The input object.
26
+ * @param input.collection - The collection to find documents in.
27
+ * @param input.filter - The filter for the find operation.
28
+ * @param [input.limit] - The maximum number of documents to return.
29
+ * @param [input.skip] - The number of documents to skip.
30
+ * @param [input.sort] - The sort order.
31
+ * @param [input.project] - The projection document.
32
+ * @param input.mapDocument - The function to map the documents to the output type.
33
+ * @param input.outputType - The output zod type.
34
+ * @param [input.options] - MongoDB find options.
35
+ *
36
+ * @returns {Promise<TData[]>} The found documents.
37
+ */
38
+ export declare const find: Find;
39
+ //# sourceMappingURL=find.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,UAAU,EACV,QAAQ,EACR,MAAM,EACN,WAAW,EACX,IAAI,EAEP,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAInC;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,KAAK,IAAI;IAC3B,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,KAAK,CAAC;IAC3C,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,WAAW,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,KAAK,EACrB,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,KACtB,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;AAEtB;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,IAAI,EAAE,IAkDlB,CAAC"}
@@ -0,0 +1,53 @@
1
+ import { GenericException } from '../../deps/jsr.io/@nimbus/core/2.0.0/src/index.js';
2
+ import { handleMongoError } from '../handleMongoError.js';
3
+ import { withSpan } from '../tracing.js';
4
+ /**
5
+ * Finds documents in a MongoDB collection and returns
6
+ * the result as an array of the specified output type.
7
+ *
8
+ * @param {FindInput} input - The input object.
9
+ * @param input.collection - The collection to find documents in.
10
+ * @param input.filter - The filter for the find operation.
11
+ * @param [input.limit] - The maximum number of documents to return.
12
+ * @param [input.skip] - The number of documents to skip.
13
+ * @param [input.sort] - The sort order.
14
+ * @param [input.project] - The projection document.
15
+ * @param input.mapDocument - The function to map the documents to the output type.
16
+ * @param input.outputType - The output zod type.
17
+ * @param [input.options] - MongoDB find options.
18
+ *
19
+ * @returns {Promise<TData[]>} The found documents.
20
+ */
21
+ export const find = ({ collection, filter, limit, skip, sort, project, mapDocument, outputType, options, }) => {
22
+ return withSpan('find', collection, async () => {
23
+ let res = [];
24
+ try {
25
+ const findRes = collection.find(filter, options);
26
+ if (limit !== undefined) {
27
+ findRes.limit(limit);
28
+ }
29
+ if (skip !== undefined) {
30
+ findRes.skip(skip);
31
+ }
32
+ if (sort !== undefined) {
33
+ findRes.sort(sort);
34
+ }
35
+ if (project !== undefined) {
36
+ findRes.project(project);
37
+ }
38
+ res = await findRes.toArray();
39
+ }
40
+ catch (error) {
41
+ throw handleMongoError(error);
42
+ }
43
+ try {
44
+ return res.map((item) => outputType.parse(mapDocument(item)));
45
+ }
46
+ catch (error) {
47
+ const exception = error instanceof Error
48
+ ? new GenericException().fromError(error)
49
+ : new GenericException();
50
+ throw exception;
51
+ }
52
+ });
53
+ };
@@ -0,0 +1,29 @@
1
+ import type { Collection, Document, Filter } from 'mongodb';
2
+ import type { ZodType } from 'zod';
3
+ /**
4
+ * Type to define the input for the findOne function.
5
+ */
6
+ export type FindOneInput<TData> = {
7
+ collection: Collection<Document>;
8
+ filter: Filter<Document>;
9
+ mapDocument: (document: Document) => TData;
10
+ outputType: ZodType;
11
+ };
12
+ /**
13
+ * Type to define the findOne function.
14
+ */
15
+ export type FindOne = <TData>(input: FindOneInput<TData>) => Promise<TData>;
16
+ /**
17
+ * Finds a single document in a MongoDB collection and returns
18
+ * the result as the specified output type.
19
+ *
20
+ * @param {FindOneInput} input - The input object.
21
+ * @param input.collection - The collection to find documents in.
22
+ * @param input.filter - The filter for the find operation.
23
+ * @param input.mapDocument - The function to map the document to the output type.
24
+ * @param input.outputType - The output zod type.
25
+ *
26
+ * @returns {Promise<TData>} The found document.
27
+ */
28
+ export declare const findOne: FindOne;
29
+ //# sourceMappingURL=findOne.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/findOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAU,MAAM,SAAS,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAInC;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,KAAK,IAAI;IAC9B,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzB,WAAW,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,KAAK,CAAC;IAC3C,UAAU,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,KAAK,EACxB,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,KACzB,OAAO,CAAC,KAAK,CAAC,CAAC;AAEpB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,OAAO,EAAE,OA6BrB,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { GenericException, NotFoundException } from '../../deps/jsr.io/@nimbus/core/2.0.0/src/index.js';
2
+ import { handleMongoError } from '../handleMongoError.js';
3
+ import { withSpan } from '../tracing.js';
4
+ /**
5
+ * Finds a single document in a MongoDB collection and returns
6
+ * the result as the specified output type.
7
+ *
8
+ * @param {FindOneInput} input - The input object.
9
+ * @param input.collection - The collection to find documents in.
10
+ * @param input.filter - The filter for the find operation.
11
+ * @param input.mapDocument - The function to map the document to the output type.
12
+ * @param input.outputType - The output zod type.
13
+ *
14
+ * @returns {Promise<TData>} The found document.
15
+ */
16
+ export const findOne = ({ collection, filter, mapDocument, outputType, }) => {
17
+ return withSpan('findOne', collection, async () => {
18
+ let res = null;
19
+ try {
20
+ res = await collection.findOne(filter);
21
+ }
22
+ catch (error) {
23
+ throw handleMongoError(error);
24
+ }
25
+ if (!res) {
26
+ throw new NotFoundException('Document not found');
27
+ }
28
+ try {
29
+ return outputType.parse(mapDocument(res));
30
+ }
31
+ catch (error) {
32
+ const exception = error instanceof Error
33
+ ? new GenericException().fromError(error)
34
+ : new GenericException();
35
+ throw exception;
36
+ }
37
+ });
38
+ };
@@ -0,0 +1,31 @@
1
+ import type { Collection, Document, Filter, FindOneAndDeleteOptions } from 'mongodb';
2
+ import type { ZodType } from 'zod';
3
+ /**
4
+ * Type to define the input for the findOneAndDelete function.
5
+ */
6
+ export type FindOneAndDeleteInput<TData> = {
7
+ collection: Collection<Document>;
8
+ filter: Filter<Document>;
9
+ mapDocument: (document: Document) => TData;
10
+ outputType: ZodType;
11
+ options?: FindOneAndDeleteOptions;
12
+ };
13
+ /**
14
+ * Type to define the findOneAndDelete function.
15
+ */
16
+ export type FindOneAndDelete = <TData>(input: FindOneAndDeleteInput<TData>) => Promise<TData>;
17
+ /**
18
+ * Finds a single document in a MongoDB collection, deletes it,
19
+ * and returns the result as the specified output type.
20
+ *
21
+ * @param {FindOneAndDeleteInput} input - The input object.
22
+ * @param input.collection - The collection to find and delete from.
23
+ * @param input.filter - The filter for the find operation.
24
+ * @param input.mapDocument - The function to map the document to the output type.
25
+ * @param input.outputType - The output zod type.
26
+ * @param [input.options] - MongoDB find and delete options.
27
+ *
28
+ * @returns {Promise<TData>} The found and deleted document.
29
+ */
30
+ export declare const findOneAndDelete: FindOneAndDelete;
31
+ //# sourceMappingURL=findOneAndDelete.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findOneAndDelete.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/findOneAndDelete.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,UAAU,EACV,QAAQ,EACR,MAAM,EACN,uBAAuB,EAE1B,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAInC;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,KAAK,IAAI;IACvC,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzB,WAAW,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,KAAK,CAAC;IAC3C,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,uBAAuB,CAAC;CACrC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EACjC,KAAK,EAAE,qBAAqB,CAAC,KAAK,CAAC,KAClC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEpB;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,EAAE,gBAkC9B,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { GenericException, NotFoundException } from '../../deps/jsr.io/@nimbus/core/2.0.0/src/index.js';
2
+ import { handleMongoError } from '../handleMongoError.js';
3
+ import { withSpan } from '../tracing.js';
4
+ /**
5
+ * Finds a single document in a MongoDB collection, deletes it,
6
+ * and returns the result as the specified output type.
7
+ *
8
+ * @param {FindOneAndDeleteInput} input - The input object.
9
+ * @param input.collection - The collection to find and delete from.
10
+ * @param input.filter - The filter for the find operation.
11
+ * @param input.mapDocument - The function to map the document to the output type.
12
+ * @param input.outputType - The output zod type.
13
+ * @param [input.options] - MongoDB find and delete options.
14
+ *
15
+ * @returns {Promise<TData>} The found and deleted document.
16
+ */
17
+ export const findOneAndDelete = ({ collection, filter, mapDocument, outputType, options, }) => {
18
+ return withSpan('findOneAndDelete', collection, async () => {
19
+ let res = null;
20
+ try {
21
+ if (options) {
22
+ res = await collection.findOneAndDelete(filter, options);
23
+ }
24
+ else {
25
+ res = await collection.findOneAndDelete(filter);
26
+ }
27
+ }
28
+ catch (error) {
29
+ throw handleMongoError(error);
30
+ }
31
+ if (!res) {
32
+ throw new NotFoundException('Document not found');
33
+ }
34
+ try {
35
+ return outputType.parse(mapDocument(res));
36
+ }
37
+ catch (error) {
38
+ const exception = error instanceof Error
39
+ ? new GenericException().fromError(error)
40
+ : new GenericException();
41
+ throw exception;
42
+ }
43
+ });
44
+ };
@@ -0,0 +1,33 @@
1
+ import type { Collection, Document, Filter, FindOneAndReplaceOptions, WithoutId } from 'mongodb';
2
+ import type { ZodType } from 'zod';
3
+ /**
4
+ * Type to define the input for the findOneAndReplace function.
5
+ */
6
+ export type FindOneAndReplaceInput<TData> = {
7
+ collection: Collection<Document>;
8
+ filter: Filter<Document>;
9
+ replacement: WithoutId<Document>;
10
+ mapDocument: (document: Document) => TData;
11
+ outputType: ZodType;
12
+ options?: FindOneAndReplaceOptions;
13
+ };
14
+ /**
15
+ * Type to define the findOneAndReplace function.
16
+ */
17
+ export type FindOneAndReplace = <TData>(input: FindOneAndReplaceInput<TData>) => Promise<TData>;
18
+ /**
19
+ * Finds a single document in a MongoDB collection, replaces it,
20
+ * and returns the result as the specified output type.
21
+ *
22
+ * @param {FindOneAndReplaceInput} input - The input object.
23
+ * @param input.collection - The collection to find and replace in.
24
+ * @param input.filter - The filter for the find operation.
25
+ * @param input.replacement - The replacement document.
26
+ * @param input.mapDocument - The function to map the document to the output type.
27
+ * @param input.outputType - The output zod type.
28
+ * @param [input.options] - MongoDB find and replace options.
29
+ *
30
+ * @returns {Promise<TData>} The found and replaced document.
31
+ */
32
+ export declare const findOneAndReplace: FindOneAndReplace;
33
+ //# sourceMappingURL=findOneAndReplace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findOneAndReplace.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/findOneAndReplace.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,UAAU,EACV,QAAQ,EACR,MAAM,EACN,wBAAwB,EAExB,SAAS,EACZ,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAInC;;GAEG;AACH,MAAM,MAAM,sBAAsB,CAAC,KAAK,IAAI;IACxC,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzB,WAAW,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;IACjC,WAAW,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,KAAK,CAAC;IAC3C,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,wBAAwB,CAAC;CACtC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAClC,KAAK,EAAE,sBAAsB,CAAC,KAAK,CAAC,KACnC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEpB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,EAAE,iBAuC/B,CAAC"}
@@ -0,0 +1,45 @@
1
+ import { GenericException, NotFoundException } from '../../deps/jsr.io/@nimbus/core/2.0.0/src/index.js';
2
+ import { handleMongoError } from '../handleMongoError.js';
3
+ import { withSpan } from '../tracing.js';
4
+ /**
5
+ * Finds a single document in a MongoDB collection, replaces it,
6
+ * and returns the result as the specified output type.
7
+ *
8
+ * @param {FindOneAndReplaceInput} input - The input object.
9
+ * @param input.collection - The collection to find and replace in.
10
+ * @param input.filter - The filter for the find operation.
11
+ * @param input.replacement - The replacement document.
12
+ * @param input.mapDocument - The function to map the document to the output type.
13
+ * @param input.outputType - The output zod type.
14
+ * @param [input.options] - MongoDB find and replace options.
15
+ *
16
+ * @returns {Promise<TData>} The found and replaced document.
17
+ */
18
+ export const findOneAndReplace = ({ collection, filter, replacement, mapDocument, outputType, options, }) => {
19
+ return withSpan('findOneAndReplace', collection, async () => {
20
+ let res = null;
21
+ try {
22
+ if (options) {
23
+ res = await collection.findOneAndReplace(filter, replacement, options);
24
+ }
25
+ else {
26
+ res = await collection.findOneAndReplace(filter, replacement);
27
+ }
28
+ }
29
+ catch (error) {
30
+ throw handleMongoError(error);
31
+ }
32
+ if (!res) {
33
+ throw new NotFoundException('Document not found');
34
+ }
35
+ try {
36
+ return outputType.parse(mapDocument(res));
37
+ }
38
+ catch (error) {
39
+ const exception = error instanceof Error
40
+ ? new GenericException().fromError(error)
41
+ : new GenericException();
42
+ throw exception;
43
+ }
44
+ });
45
+ };
@@ -0,0 +1,33 @@
1
+ import type { Collection, Document, Filter, FindOneAndUpdateOptions, UpdateFilter } from 'mongodb';
2
+ import type { ZodType } from 'zod';
3
+ /**
4
+ * Type to define the input for the findOneAndUpdate function.
5
+ */
6
+ export type FindOneAndUpdateInput<TData> = {
7
+ collection: Collection<Document>;
8
+ filter: Filter<Document>;
9
+ update: UpdateFilter<Document>;
10
+ mapDocument: (document: Document) => TData;
11
+ outputType: ZodType;
12
+ options?: FindOneAndUpdateOptions;
13
+ };
14
+ /**
15
+ * Type to define the findOneAndUpdate function.
16
+ */
17
+ export type FindOneAndUpdate = <TData>(input: FindOneAndUpdateInput<TData>) => Promise<TData>;
18
+ /**
19
+ * Finds a single document in a MongoDB collection, updates it,
20
+ * and returns the result as the specified output type.
21
+ *
22
+ * @param {FindOneAndUpdateInput} input - The input object.
23
+ * @param input.collection - The collection to find and update in.
24
+ * @param input.filter - The filter for the find operation.
25
+ * @param input.update - The update filter.
26
+ * @param input.mapDocument - The function to map the document to the output type.
27
+ * @param input.outputType - The output zod type.
28
+ * @param [input.options] - MongoDB find and update options.
29
+ *
30
+ * @returns {Promise<TData>} The found and updated document.
31
+ */
32
+ export declare const findOneAndUpdate: FindOneAndUpdate;
33
+ //# sourceMappingURL=findOneAndUpdate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findOneAndUpdate.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/findOneAndUpdate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,UAAU,EACV,QAAQ,EACR,MAAM,EACN,uBAAuB,EACvB,YAAY,EAEf,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAInC;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,KAAK,IAAI;IACvC,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzB,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC/B,WAAW,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,KAAK,CAAC;IAC3C,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,uBAAuB,CAAC;CACrC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EACjC,KAAK,EAAE,qBAAqB,CAAC,KAAK,CAAC,KAClC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEpB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,EAAE,gBAuC9B,CAAC"}
@@ -0,0 +1,45 @@
1
+ import { GenericException, NotFoundException } from '../../deps/jsr.io/@nimbus/core/2.0.0/src/index.js';
2
+ import { handleMongoError } from '../handleMongoError.js';
3
+ import { withSpan } from '../tracing.js';
4
+ /**
5
+ * Finds a single document in a MongoDB collection, updates it,
6
+ * and returns the result as the specified output type.
7
+ *
8
+ * @param {FindOneAndUpdateInput} input - The input object.
9
+ * @param input.collection - The collection to find and update in.
10
+ * @param input.filter - The filter for the find operation.
11
+ * @param input.update - The update filter.
12
+ * @param input.mapDocument - The function to map the document to the output type.
13
+ * @param input.outputType - The output zod type.
14
+ * @param [input.options] - MongoDB find and update options.
15
+ *
16
+ * @returns {Promise<TData>} The found and updated document.
17
+ */
18
+ export const findOneAndUpdate = ({ collection, filter, update, mapDocument, outputType, options, }) => {
19
+ return withSpan('findOneAndUpdate', collection, async () => {
20
+ let res = null;
21
+ try {
22
+ if (options) {
23
+ res = await collection.findOneAndUpdate(filter, update, options);
24
+ }
25
+ else {
26
+ res = await collection.findOneAndUpdate(filter, update);
27
+ }
28
+ }
29
+ catch (error) {
30
+ throw handleMongoError(error);
31
+ }
32
+ if (!res) {
33
+ throw new NotFoundException('Document not found');
34
+ }
35
+ try {
36
+ return outputType.parse(mapDocument(res));
37
+ }
38
+ catch (error) {
39
+ const exception = error instanceof Error
40
+ ? new GenericException().fromError(error)
41
+ : new GenericException();
42
+ throw exception;
43
+ }
44
+ });
45
+ };
@@ -0,0 +1,25 @@
1
+ import type { BulkWriteOptions, Collection, Document, InsertManyResult, OptionalUnlessRequiredId } from 'mongodb';
2
+ /**
3
+ * Type to define the input for the insertMany function.
4
+ */
5
+ export type InsertManyInput = {
6
+ collection: Collection<Document>;
7
+ documents: OptionalUnlessRequiredId<Document>[];
8
+ options?: BulkWriteOptions;
9
+ };
10
+ /**
11
+ * Type to define the insertMany function.
12
+ */
13
+ export type InsertMany = (input: InsertManyInput) => Promise<InsertManyResult<Document>>;
14
+ /**
15
+ * Inserts multiple documents into a MongoDB collection.
16
+ *
17
+ * @param {InsertManyInput} input - The input object.
18
+ * @param input.collection - The collection to insert into.
19
+ * @param input.documents - The documents to insert.
20
+ * @param [input.options] - The insert options.
21
+ *
22
+ * @returns {Promise<InsertManyResult<Document>} The result of the insert operation.
23
+ */
24
+ export declare const insertMany: InsertMany;
25
+ //# sourceMappingURL=insertMany.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insertMany.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/insertMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,wBAAwB,EAC3B,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC1B,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACjC,SAAS,EAAE,wBAAwB,CAAC,QAAQ,CAAC,EAAE,CAAC;IAChD,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC9B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,CACrB,KAAK,EAAE,eAAe,KACrB,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;AAEzC;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,EAAE,UAYxB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { handleMongoError } from '../handleMongoError.js';
2
+ import { withSpan } from '../tracing.js';
3
+ /**
4
+ * Inserts multiple documents into a MongoDB collection.
5
+ *
6
+ * @param {InsertManyInput} input - The input object.
7
+ * @param input.collection - The collection to insert into.
8
+ * @param input.documents - The documents to insert.
9
+ * @param [input.options] - The insert options.
10
+ *
11
+ * @returns {Promise<InsertManyResult<Document>} The result of the insert operation.
12
+ */
13
+ export const insertMany = ({ collection, documents, options, }) => {
14
+ return withSpan('insertMany', collection, async () => {
15
+ try {
16
+ return await collection.insertMany(documents, options);
17
+ }
18
+ catch (error) {
19
+ throw handleMongoError(error);
20
+ }
21
+ });
22
+ };