albatross 3.6.0 → 3.7.1

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.
package/index.d.ts CHANGED
@@ -26,6 +26,10 @@ interface UpdateManyOptions extends Omit<mongodb.UpdateManyOptions, 'hint'> {
26
26
  hint?: string | object
27
27
  }
28
28
 
29
+ interface FindOneAndDeleteOption<T> extends Omit<mongodb.FindOneAndDeleteOption<T>, 'hint'> {
30
+ hint?: string | object
31
+ }
32
+
29
33
  declare function albatross (uri: string): albatross.Albatross
30
34
 
31
35
  declare namespace albatross {
@@ -71,6 +75,11 @@ declare namespace albatross {
71
75
  deleteOne (filter: mongodb.FilterQuery<TSchema>, options?: mongodb.CommonOptions & { bypassDocumentValidation?: boolean, hint?: string | object }): Promise<0 | 1>
72
76
  deleteMany (filter: mongodb.FilterQuery<TSchema>, options?: mongodb.CommonOptions & { hint?: string | object }): Promise<number>
73
77
 
78
+ findOneAndDelete (filter: mongodb.FilterQuery<TSchema>, options?: WithoutProjection<FindOneAndDeleteOption<TSchema>>): Promise<TSchema | null>
79
+ findOneAndDelete<TKey extends keyof TSchema> (filter: mongodb.FilterQuery<TSchema>, options: SpecificProjection<FindOneAndDeleteOption<TSchema>, { [key in TKey]: 1 | true } & { _id: 0 | false }>): Promise<Pick<TSchema, TKey> | null>
80
+ findOneAndDelete<TKey extends keyof TSchema> (filter: mongodb.FilterQuery<TSchema>, options: SpecificProjection<FindOneAndDeleteOption<TSchema>, { [key in TKey]: 1 | true } & { _id?: 1 | true }>): Promise<Pick<TSchema, '_id' | TKey> | null>
81
+ findOneAndDelete (filter: mongodb.FilterQuery<TSchema>, options?: FindOneAndDeleteOption<TSchema>): Promise<object | null>
82
+
74
83
  aggregate (pipeline: object[], options?: mongodb.CollectionAggregationOptions): Promise<object[]>
75
84
 
76
85
  createIndex (fieldOrSpec: string | any, options?: mongodb.IndexOptions): Promise<string>
package/lib/collection.js CHANGED
@@ -190,6 +190,20 @@ class Collection {
190
190
  }
191
191
  }
192
192
 
193
+ async findOneAndDelete (filter, opts) {
194
+ const db = await this.parent.db()
195
+
196
+ try {
197
+ this[kDebug]('findOneAndDelete(%o)', filter)
198
+ const res = await db.collection(this.name).findOneAndDelete(filter, opts)
199
+ this[kDebug](`reply OK ${res.value == null ? 0 : 1}`)
200
+ return res.value
201
+ } catch (err) {
202
+ this[kDebug]('reply ERR')
203
+ throw err
204
+ }
205
+ }
206
+
193
207
  async aggregate (pipeline, opts) {
194
208
  const db = await this.parent.db()
195
209
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "albatross",
3
- "version": "3.6.0",
3
+ "version": "3.7.1",
4
4
  "license": "MIT",
5
5
  "author": "Linus Unnebäck <linus@folkdatorn.se>",
6
6
  "repository": "LinusU/node-albatross",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@types/bson": "1.0.11",
18
- "@types/mongodb": "3.6.12",
18
+ "@types/mongodb": "3.6.20",
19
19
  "bson": "^1.1.4",
20
20
  "debug": "^4.1.1",
21
21
  "mongodb": "^3.6.0"
package/readme.md CHANGED
@@ -185,6 +185,10 @@ Deletes a single document matching `filter`. Resolves with the number of documen
185
185
 
186
186
  Deletes multiple documents matching `filter`. Resolves with the number of documents deleted.
187
187
 
188
+ #### `findOneAndDelete(filter[, opts]): Promise<object>`
189
+
190
+ Finds a document and deletes it in one atomic operation.
191
+
188
192
  #### `aggregate(pipeline[, opts]): Promise<object[]>`
189
193
 
190
194
  Executes an aggregation framework pipeline against the collection. Resolves with the aggregated objects.