albatross 3.5.0 → 3.6.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.
- package/index.d.ts +39 -21
- package/lib/collection.js +19 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -10,6 +10,22 @@ type FlattenIfArray<T> = T extends Array<infer R> ? R : T
|
|
|
10
10
|
type SpecificProjection<T, TProjection> = Omit<T, 'projection'> & { projection: TProjection }
|
|
11
11
|
type WithoutProjection<T> = T & { fields?: undefined, projection?: undefined }
|
|
12
12
|
|
|
13
|
+
interface FindOneOptions<T> extends Omit<mongodb.FindOneOptions<T>, 'hint'> {
|
|
14
|
+
hint?: string | object
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface FindOneAndUpdateOption<T> extends Omit<mongodb.FindOneAndUpdateOption<T>, 'hint'> {
|
|
18
|
+
hint?: string | object
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface UpdateOneOptions extends Omit<mongodb.UpdateOneOptions, 'hint'> {
|
|
22
|
+
hint?: string | object
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface UpdateManyOptions extends Omit<mongodb.UpdateManyOptions, 'hint'> {
|
|
26
|
+
hint?: string | object
|
|
27
|
+
}
|
|
28
|
+
|
|
13
29
|
declare function albatross (uri: string): albatross.Albatross
|
|
14
30
|
|
|
15
31
|
declare namespace albatross {
|
|
@@ -17,45 +33,47 @@ declare namespace albatross {
|
|
|
17
33
|
readonly parent: Albatross
|
|
18
34
|
id (hexString?: mongodb.ObjectId | string): mongodb.ObjectId
|
|
19
35
|
|
|
20
|
-
findOne (filter: mongodb.FilterQuery<TSchema>, options?: WithoutProjection<
|
|
21
|
-
findOne<TKey extends keyof TSchema> (filter: mongodb.FilterQuery<TSchema>, options: SpecificProjection<
|
|
22
|
-
findOne<TKey extends keyof TSchema> (filter: mongodb.FilterQuery<TSchema>, options: SpecificProjection<
|
|
23
|
-
findOne (filter: mongodb.FilterQuery<TSchema>, options:
|
|
36
|
+
findOne (filter: mongodb.FilterQuery<TSchema>, options?: WithoutProjection<FindOneOptions<TSchema>>): Promise<TSchema | null>
|
|
37
|
+
findOne<TKey extends keyof TSchema> (filter: mongodb.FilterQuery<TSchema>, options: SpecificProjection<FindOneOptions<TSchema>, { [key in TKey]: 1 | true } & { _id: 0 | false }>): Promise<Pick<TSchema, TKey> | null>
|
|
38
|
+
findOne<TKey extends keyof TSchema> (filter: mongodb.FilterQuery<TSchema>, options: SpecificProjection<FindOneOptions<TSchema>, { [key in TKey]: 1 | true } & { _id?: 1 | true }>): Promise<Pick<TSchema, '_id' | TKey> | null>
|
|
39
|
+
findOne (filter: mongodb.FilterQuery<TSchema>, options: FindOneOptions<TSchema>): Promise<object | null>
|
|
24
40
|
|
|
25
|
-
find (query: mongodb.FilterQuery<TSchema>, options?: WithoutProjection<
|
|
26
|
-
find<TKey extends keyof TSchema> (query: mongodb.FilterQuery<TSchema>, options: SpecificProjection<
|
|
27
|
-
find<TKey extends keyof TSchema> (query: mongodb.FilterQuery<TSchema>, options: SpecificProjection<
|
|
28
|
-
find (query: mongodb.FilterQuery<TSchema>, options:
|
|
41
|
+
find (query: mongodb.FilterQuery<TSchema>, options?: WithoutProjection<FindOneOptions<TSchema>>): Promise<TSchema[]>
|
|
42
|
+
find<TKey extends keyof TSchema> (query: mongodb.FilterQuery<TSchema>, options: SpecificProjection<FindOneOptions<TSchema>, { [key in TKey]: 1 | true } & { _id: 0 | false }>): Promise<Array<Pick<TSchema, TKey>>>
|
|
43
|
+
find<TKey extends keyof TSchema> (query: mongodb.FilterQuery<TSchema>, options: SpecificProjection<FindOneOptions<TSchema>, { [key in TKey]: 1 | true } & { _id?: 1 | true }>): Promise<Array<Pick<TSchema, '_id' | TKey>>>
|
|
44
|
+
find (query: mongodb.FilterQuery<TSchema>, options: FindOneOptions<TSchema>): Promise<object[]>
|
|
29
45
|
|
|
30
46
|
count (query?: mongodb.FilterQuery<TSchema>, options?: mongodb.MongoCountPreferences): Promise<number>
|
|
31
47
|
|
|
32
48
|
distinct<TKey extends keyof mongodb.WithId<TSchema>> (key: TKey, query?: mongodb.FilterQuery<TSchema>, options?: { readPreference?: mongodb.ReadPreference | string, maxTimeMS?: number, session?: mongodb.ClientSession }): Promise<Array<FlattenIfArray<mongodb.WithId<TSchema>[TKey]>>>
|
|
33
49
|
distinct (key: string, query?: mongodb.FilterQuery<TSchema>, options?: { readPreference?: mongodb.ReadPreference | string, maxTimeMS?: number, session?: mongodb.ClientSession }): Promise<any[]>
|
|
34
50
|
|
|
35
|
-
exists (query?: mongodb.FilterQuery<TSchema
|
|
51
|
+
exists (query?: mongodb.FilterQuery<TSchema>, options?: { hint?: string | object }): Promise<boolean>
|
|
36
52
|
|
|
37
53
|
insert (doc: DeepReadonly<mongodb.OptionalId<TSchema>>, options?: mongodb.CollectionInsertOneOptions): Promise<mongodb.WithId<TSchema>>
|
|
38
54
|
insert (docs: DeepReadonly<mongodb.OptionalId<TSchema>>[], options?: mongodb.CollectionInsertManyOptions): Promise<mongodb.WithId<TSchema>[]>
|
|
39
55
|
|
|
40
|
-
findOneAndUpdate (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options: WithoutProjection<
|
|
41
|
-
findOneAndUpdate (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options?: WithoutProjection<
|
|
56
|
+
findOneAndUpdate (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options: WithoutProjection<FindOneAndUpdateOption<TSchema> & { returnOriginal: false, upsert: true }>): Promise<TSchema>
|
|
57
|
+
findOneAndUpdate (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options?: WithoutProjection<FindOneAndUpdateOption<TSchema>>): Promise<TSchema | null>
|
|
42
58
|
|
|
43
|
-
findOneAndUpdate<TKey extends keyof TSchema> (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options: SpecificProjection<
|
|
44
|
-
findOneAndUpdate<TKey extends keyof TSchema> (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options: SpecificProjection<
|
|
59
|
+
findOneAndUpdate<TKey extends keyof TSchema> (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options: SpecificProjection<FindOneAndUpdateOption<TSchema> & { returnOriginal: false, upsert: true }, { [key in TKey]: 1 | true } & { _id: 0 | false }>): Promise<Pick<TSchema, TKey>>
|
|
60
|
+
findOneAndUpdate<TKey extends keyof TSchema> (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options: SpecificProjection<FindOneAndUpdateOption<TSchema>, { [key in TKey]: 1 | true } & { _id: 0 | false }>): Promise<Pick<TSchema, TKey> | null>
|
|
45
61
|
|
|
46
|
-
findOneAndUpdate<TKey extends keyof TSchema> (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options: SpecificProjection<
|
|
47
|
-
findOneAndUpdate<TKey extends keyof TSchema> (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options: SpecificProjection<
|
|
62
|
+
findOneAndUpdate<TKey extends keyof TSchema> (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options: SpecificProjection<FindOneAndUpdateOption<TSchema> & { returnOriginal: false, upsert: true }, { [key in TKey]: 1 | true } & { _id?: 1 | true }>): Promise<Pick<TSchema, '_id' | TKey>>
|
|
63
|
+
findOneAndUpdate<TKey extends keyof TSchema> (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options: SpecificProjection<FindOneAndUpdateOption<TSchema>, { [key in TKey]: 1 | true } & { _id?: 1 | true }>): Promise<Pick<TSchema, '_id' | TKey> | null>
|
|
48
64
|
|
|
49
|
-
findOneAndUpdate (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options:
|
|
50
|
-
findOneAndUpdate (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options?:
|
|
65
|
+
findOneAndUpdate (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options: FindOneAndUpdateOption<TSchema> & { returnOriginal: false, upsert: true }): Promise<object>
|
|
66
|
+
findOneAndUpdate (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options?: FindOneAndUpdateOption<TSchema>): Promise<object | null>
|
|
51
67
|
|
|
52
|
-
updateOne (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options?:
|
|
53
|
-
updateMany (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options?:
|
|
68
|
+
updateOne (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options?: UpdateOneOptions): Promise<{ matched: 0 | 1, modified: 0 | 1 }>
|
|
69
|
+
updateMany (filter: mongodb.FilterQuery<TSchema>, update: mongodb.UpdateQuery<TSchema> | Partial<TSchema>, options?: UpdateManyOptions): Promise<{ matched: number, modified: number }>
|
|
54
70
|
|
|
55
|
-
deleteOne (filter: mongodb.FilterQuery<TSchema>, options?: mongodb.CommonOptions & { bypassDocumentValidation?: boolean }): Promise<0 | 1>
|
|
56
|
-
deleteMany (filter: mongodb.FilterQuery<TSchema>, options?: mongodb.CommonOptions): Promise<number>
|
|
71
|
+
deleteOne (filter: mongodb.FilterQuery<TSchema>, options?: mongodb.CommonOptions & { bypassDocumentValidation?: boolean, hint?: string | object }): Promise<0 | 1>
|
|
72
|
+
deleteMany (filter: mongodb.FilterQuery<TSchema>, options?: mongodb.CommonOptions & { hint?: string | object }): Promise<number>
|
|
57
73
|
|
|
58
74
|
aggregate (pipeline: object[], options?: mongodb.CollectionAggregationOptions): Promise<object[]>
|
|
75
|
+
|
|
76
|
+
createIndex (fieldOrSpec: string | any, options?: mongodb.IndexOptions): Promise<string>
|
|
59
77
|
}
|
|
60
78
|
|
|
61
79
|
interface FileInfo {
|
package/lib/collection.js
CHANGED
|
@@ -76,12 +76,16 @@ class Collection {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
async exists (query) {
|
|
79
|
+
async exists (query, opts) {
|
|
80
80
|
const db = await this.parent.db()
|
|
81
81
|
|
|
82
82
|
// https://blog.serverdensity.com/checking-if-a-document-exists-mongodb-slow-findone-vs-find/
|
|
83
83
|
const cursor = db.collection(this.name).find(query, { projection: { _id: 1 }, limit: 1 })
|
|
84
84
|
|
|
85
|
+
if (opts && opts.hint) {
|
|
86
|
+
cursor.hint(opts.hint)
|
|
87
|
+
}
|
|
88
|
+
|
|
85
89
|
try {
|
|
86
90
|
this[kDebug]('exists(%o)', query)
|
|
87
91
|
const res = await cursor.hasNext()
|
|
@@ -199,6 +203,20 @@ class Collection {
|
|
|
199
203
|
throw err
|
|
200
204
|
}
|
|
201
205
|
}
|
|
206
|
+
|
|
207
|
+
async createIndex (fieldOrSpec, opts) {
|
|
208
|
+
const db = await this.parent.db()
|
|
209
|
+
|
|
210
|
+
try {
|
|
211
|
+
this[kDebug]('createIndex(%o, %o)', fieldOrSpec, opts)
|
|
212
|
+
const res = await db.collection(this.name).createIndex(fieldOrSpec, opts)
|
|
213
|
+
this[kDebug]('reply OK')
|
|
214
|
+
return res
|
|
215
|
+
} catch (err) {
|
|
216
|
+
this[kDebug]('reply ERR')
|
|
217
|
+
throw err
|
|
218
|
+
}
|
|
219
|
+
}
|
|
202
220
|
}
|
|
203
221
|
|
|
204
222
|
module.exports = Collection
|