44
55namespace Patchlevel \Rango ;
66
7- class Collection
7+ /**
8+ * @template T of array
9+ */
10+ final class Collection
811{
912 public function __construct (
1013 private readonly Client $ client ,
@@ -26,7 +29,7 @@ public function countDocuments(array $filter = [], array $options = []): int
2629 * @param array<string, mixed> $filter
2730 * @param array<string, mixed> $options
2831 */
29- public function deleteMany (array $ filter , array $ options = []): Result
32+ public function deleteMany (array $ filter , array $ options = []): DeleteResult
3033 {
3134 return $ this ->client ->run (new Operation \Delete ($ this ->databaseName , $ this ->collectionName , $ filter , true ));
3235 }
@@ -35,7 +38,7 @@ public function deleteMany(array $filter, array $options = []): Result
3538 * @param array<string, mixed> $filter
3639 * @param array<string, mixed> $options
3740 */
38- public function deleteOne (array $ filter , array $ options = []): Result
41+ public function deleteOne (array $ filter , array $ options = []): DeleteResult
3942 {
4043 return $ this ->client ->run (new Operation \Delete ($ this ->databaseName , $ this ->collectionName , $ filter , false ));
4144 }
@@ -48,21 +51,25 @@ public function drop(): void
4851 /**
4952 * @param array<string, mixed> $filter
5053 * @param array<string, mixed> $options
54+ *
55+ * @return Cursor<T>
5156 */
52- public function find (array $ filter = [], array $ options = []): Result
57+ public function find (array $ filter = [], array $ options = []): Cursor
5358 {
5459 return $ this ->client ->run (new Operation \Find ($ this ->databaseName , $ this ->collectionName , $ filter , $ options ));
5560 }
5661
5762 /**
5863 * @param array<string, mixed> $filter
5964 * @param array<string, mixed> $options
65+ *
66+ * @return T|null
6067 */
61- public function findOne (array $ filter = [], array $ options = []): array |object | null
68+ public function findOne (array $ filter = [], array $ options = []): array |null
6269 {
6370 $ result = $ this ->client ->run (new Operation \FindOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ options ));
6471
65- if (!$ result instanceof Result ) {
72+ if (!$ result instanceof Cursor ) {
6673 return null ;
6774 }
6875
@@ -75,7 +82,7 @@ public function findOne(array $filter = [], array $options = []): array|object|n
7582 * @param list<array<string, mixed>> $documents
7683 * @param array<string, mixed> $options
7784 */
78- public function insertMany (array $ documents , array $ options = []): Result
85+ public function insertMany (array $ documents , array $ options = []): InsertManyResult
7986 {
8087 return $ this ->client ->run (new Operation \InsertMany ($ this ->databaseName , $ this ->collectionName , $ documents , $ options ));
8188 }
@@ -84,7 +91,7 @@ public function insertMany(array $documents, array $options = []): Result
8491 * @param array<string, mixed> $document
8592 * @param array<string, mixed> $options
8693 */
87- public function insertOne (array $ document , array $ options = []): Result
94+ public function insertOne (array $ document , array $ options = []): InsertOneResult
8895 {
8996 return $ this ->client ->run (new Operation \InsertOne ($ this ->databaseName , $ this ->collectionName , $ document , $ options ));
9097 }
@@ -94,7 +101,7 @@ public function insertOne(array $document, array $options = []): Result
94101 * @param array<string, mixed> $replacement
95102 * @param array<string, mixed> $options
96103 */
97- public function replaceOne (array $ filter , array $ replacement , array $ options = []): Result
104+ public function replaceOne (array $ filter , array $ replacement , array $ options = []): UpdateResult
98105 {
99106 return $ this ->client ->run (new Operation \ReplaceOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ replacement , $ options ));
100107 }
@@ -104,7 +111,7 @@ public function replaceOne(array $filter, array $replacement, array $options = [
104111 * @param array<string, mixed> $update
105112 * @param array<string, mixed> $options
106113 */
107- public function updateMany (array $ filter , array $ update , array $ options = []): Result
114+ public function updateMany (array $ filter , array $ update , array $ options = []): UpdateResult
108115 {
109116 return $ this ->client ->run (new Operation \Update ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options , true ));
110117 }
@@ -114,16 +121,18 @@ public function updateMany(array $filter, array $update, array $options = []): R
114121 * @param array<string, mixed> $update
115122 * @param array<string, mixed> $options
116123 */
117- public function updateOne (array $ filter , array $ update , array $ options = []): Result
124+ public function updateOne (array $ filter , array $ update , array $ options = []): UpdateResult
118125 {
119126 return $ this ->client ->run (new Operation \Update ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options , false ));
120127 }
121128
122129 /**
123130 * @param list<array<string, mixed>> $pipeline
124131 * @param array<string, mixed> $options
132+ *
133+ * @return Cursor<T>
125134 */
126- public function aggregate (array $ pipeline , array $ options = []): Result
135+ public function aggregate (array $ pipeline , array $ options = []): Cursor
127136 {
128137 return $ this ->client ->run (new Operation \Aggregate ($ this ->databaseName , $ this ->collectionName , $ pipeline , $ options ));
129138 }
@@ -142,12 +151,14 @@ public function distinct(string $fieldName, array $filter = [], array $options =
142151 /**
143152 * @param array<string, mixed> $filter
144153 * @param array<string, mixed> $options
154+ *
155+ * @return T|null
145156 */
146- public function findOneAndDelete (array $ filter , array $ options = []): array |object | null
157+ public function findOneAndDelete (array $ filter , array $ options = []): array |null
147158 {
148159 $ result = $ this ->client ->run (new Operation \FindOneAndDelete ($ this ->databaseName , $ this ->collectionName , $ filter , $ options ));
149160
150- if (!$ result instanceof Result ) {
161+ if (!$ result instanceof Cursor ) {
151162 return null ;
152163 }
153164
@@ -160,12 +171,14 @@ public function findOneAndDelete(array $filter, array $options = []): array|obje
160171 * @param array<string, mixed> $filter
161172 * @param array<string, mixed> $replacement
162173 * @param array<string, mixed> $options
174+ *
175+ * @return T|null
163176 */
164- public function findOneAndReplace (array $ filter , array $ replacement , array $ options = []): array |object | null
177+ public function findOneAndReplace (array $ filter , array $ replacement , array $ options = []): array |null
165178 {
166179 $ result = $ this ->client ->run (new Operation \FindOneAndReplace ($ this ->databaseName , $ this ->collectionName , $ filter , $ replacement , $ options ));
167180
168- if (!$ result instanceof Result ) {
181+ if (!$ result instanceof Cursor ) {
169182 return null ;
170183 }
171184
@@ -178,12 +191,14 @@ public function findOneAndReplace(array $filter, array $replacement, array $opti
178191 * @param array<string, mixed> $filter
179192 * @param array<string, mixed> $update
180193 * @param array<string, mixed> $options
194+ *
195+ * @return T|null
181196 */
182- public function findOneAndUpdate (array $ filter , array $ update , array $ options = []): array |object | null
197+ public function findOneAndUpdate (array $ filter , array $ update , array $ options = []): array |null
183198 {
184199 $ result = $ this ->client ->run (new Operation \FindOneAndUpdate ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options ));
185200
186- if (!$ result instanceof Result ) {
201+ if (!$ result instanceof Cursor ) {
187202 return null ;
188203 }
189204
@@ -196,9 +211,9 @@ public function findOneAndUpdate(array $filter, array $update, array $options =
196211 * @param list<array<string, array<string, mixed>>> $operations
197212 * @param array<string, mixed> $options
198213 */
199- public function bulkWrite (array $ operations , array $ options = []): void
214+ public function bulkWrite (array $ operations , array $ options = []): BulkWriteResult
200215 {
201- $ this ->client ->run (new Operation \BulkWrite ($ this ->databaseName , $ this ->collectionName , $ operations , $ options ));
216+ return $ this ->client ->run (new Operation \BulkWrite ($ this ->databaseName , $ this ->collectionName , $ operations , $ options ));
202217 }
203218
204219 /**
0 commit comments