mongolite-ts 0.6.2 → 0.7.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,5 +1,5 @@
1
1
  import { SQLiteDB } from './db.js';
2
- import { DocumentWithId, Filter, UpdateFilter, InsertOneResult, UpdateResult, DeleteResult, Projection, IndexSpecification, CreateIndexOptions, CreateIndexResult, DropIndexResult, IndexInfo } from './types.js';
2
+ import { DocumentWithId, Filter, UpdateFilter, InsertOneResult, InsertManyResult, UpdateResult, DeleteResult, Projection, IndexSpecification, CreateIndexOptions, CreateIndexResult, DropIndexResult, IndexInfo, FindOneAndUpdateOptions, FindOneAndDeleteOptions, FindOneAndReplaceOptions, ReplaceOptions, AggregationPipeline } from './types.js';
3
3
  import { FindCursor } from './cursors/findCursor.js';
4
4
  import { ChangeStream, ChangeStreamOptions } from './changeStream.js';
5
5
  /**
@@ -33,11 +33,11 @@ export declare class MongoLiteCollection<T extends DocumentWithId> {
33
33
  * If any document does not have an `_id`, a UUID will be generated.
34
34
  * Uses batch insert with transactions for improved performance.
35
35
  * @param docs An array of documents to insert.
36
- * @returns {Promise<InsertOneResult[]>} An array of results for each insert operation.
36
+ * @returns {Promise<InsertManyResult>} An object containing the outcome of all insert operations.
37
37
  * */
38
38
  insertMany(docs: (Omit<T, '_id'> & {
39
39
  _id?: string;
40
- })[]): Promise<InsertOneResult[]>;
40
+ })[]): Promise<InsertManyResult>;
41
41
  /**
42
42
  * Inserts a batch of documents using a single transaction for optimal performance.
43
43
  * @private
@@ -48,8 +48,11 @@ export declare class MongoLiteCollection<T extends DocumentWithId> {
48
48
  * @param filter The query criteria.
49
49
  * @param projection Optional. Specifies the fields to return.
50
50
  * @returns {Promise<T | null>} The found document or `null`.
51
+ * @remarks When using a projection, some fields may be undefined at runtime despite the
52
+ * return type being `T`. This provides better ergonomics for the common case where no
53
+ * projection is used.
51
54
  */
52
- findOne(filter: Filter<T>, projection?: Projection<T>): Promise<Partial<T> | null>;
55
+ findOne(filter: Filter<T>, projection?: Projection<T>): Promise<T | null>;
53
56
  /**
54
57
  * Finds multiple documents matching the filter and returns a cursor.
55
58
  * @param filter The query criteria.
@@ -148,6 +151,90 @@ export declare class MongoLiteCollection<T extends DocumentWithId> {
148
151
  * @returns {Promise<number>} The count of matching documents.
149
152
  */
150
153
  countDocuments(filter?: Filter<T>): Promise<number>;
154
+ /**
155
+ * Returns the number of documents in the collection.
156
+ * This is an estimate and may not reflect the exact count in concurrent environments.
157
+ * @returns {Promise<number>} The estimated count.
158
+ */
159
+ estimatedDocumentCount(): Promise<number>;
160
+ /**
161
+ * Finds a single document matching the filter, applies the update, and returns the document.
162
+ * @param filter The selection criteria.
163
+ * @param update The modifications to apply.
164
+ * @param options Options including returnDocument ('before'|'after') and upsert.
165
+ * @returns {Promise<T | null>} The document before or after the update, or null.
166
+ */
167
+ findOneAndUpdate(filter: Filter<T>, update: UpdateFilter<T>, options?: FindOneAndUpdateOptions<T>): Promise<T | null>;
168
+ /**
169
+ * Finds a single document matching the filter, deletes it, and returns it.
170
+ * @param filter The selection criteria.
171
+ * @param options Options including field projection.
172
+ * @returns {Promise<T | null>} The deleted document or null.
173
+ */
174
+ findOneAndDelete(filter: Filter<T>, options?: FindOneAndDeleteOptions<T>): Promise<T | null>;
175
+ /**
176
+ * Finds a single document matching the filter and replaces it entirely.
177
+ * @param filter The selection criteria.
178
+ * @param replacement The replacement document (replaces all fields except _id).
179
+ * @param options Options including returnDocument, upsert, and projection.
180
+ * @returns {Promise<T | null>} The document before or after the replacement, or null.
181
+ */
182
+ findOneAndReplace(filter: Filter<T>, replacement: Omit<T, '_id'>, options?: FindOneAndReplaceOptions<T>): Promise<T | null>;
183
+ /**
184
+ * Replaces a single document matching the filter.
185
+ * @param filter The selection criteria.
186
+ * @param replacement The replacement document (replaces all fields except _id).
187
+ * @param options Options including upsert.
188
+ * @returns {Promise<UpdateResult>} An object describing the outcome.
189
+ */
190
+ replaceOne(filter: Filter<T>, replacement: Omit<T, '_id'>, options?: ReplaceOptions): Promise<UpdateResult>;
191
+ /**
192
+ * Returns distinct values for a field across all documents matching the filter.
193
+ * @param field The field to find distinct values for.
194
+ * @param filter Optional filter to narrow the documents.
195
+ * @returns {Promise<unknown[]>} An array of distinct values.
196
+ */
197
+ distinct(field: string, filter?: Filter<T>): Promise<unknown[]>;
198
+ /**
199
+ * Drops the entire collection (table) from the database.
200
+ * @returns {Promise<void>}
201
+ */
202
+ drop(): Promise<void>;
203
+ /**
204
+ * Executes an aggregation pipeline on the collection.
205
+ * Supports: $match, $project, $sort, $limit, $skip, $count, $group, $unwind, $addFields.
206
+ * @param pipeline An array of pipeline stage documents.
207
+ * @returns An object with a toArray() method that returns the aggregation result.
208
+ */
209
+ aggregate(pipeline: AggregationPipeline): {
210
+ toArray: () => Promise<Record<string, unknown>[]>;
211
+ };
212
+ /**
213
+ * Runs an aggregation pipeline and returns results.
214
+ * @private
215
+ */
216
+ private runAggregationPipeline;
217
+ /**
218
+ * Applies a $group pipeline stage.
219
+ * @private
220
+ */
221
+ private applyGroupStage;
222
+ /**
223
+ * Applies a $project stage to a document.
224
+ * @private
225
+ */
226
+ private applyAggregateProjection;
227
+ /**
228
+ * Checks if a document matches a filter (for in-memory aggregation stages).
229
+ * Uses the same logic as FindCursor but applied in JavaScript.
230
+ * @private
231
+ */
232
+ private matchesFilter;
233
+ /**
234
+ * Checks if a value matches a set of query operators (for in-memory filtering).
235
+ * @private
236
+ */
237
+ private matchesOperators;
151
238
  /**
152
239
  * Opens a change stream to watch for changes on this collection.
153
240
  * Returns a ChangeStream that emits events when documents are inserted, updated, or deleted.