mongoose 6.2.2 → 6.2.3

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.
@@ -0,0 +1,129 @@
1
+ import mongodb = require('mongodb');
2
+
3
+ declare module 'mongoose' {
4
+
5
+ class NativeError extends global.Error { }
6
+ type CallbackError = NativeError | null;
7
+
8
+ class MongooseError extends global.Error {
9
+ constructor(msg: string);
10
+
11
+ /** The type of error. "MongooseError" for generic errors. */
12
+ name: string;
13
+
14
+ static messages: any;
15
+
16
+ static Messages: any;
17
+ }
18
+
19
+ namespace Error {
20
+ export class CastError extends MongooseError {
21
+ name: 'CastError';
22
+ stringValue: string;
23
+ kind: string;
24
+ value: any;
25
+ path: string;
26
+ reason?: NativeError | null;
27
+ model?: any;
28
+
29
+ constructor(type: string, value: any, path: string, reason?: NativeError, schemaType?: SchemaType);
30
+ }
31
+ export class SyncIndexesError extends MongooseError {
32
+ name: 'SyncIndexesError';
33
+ errors?: Record<string, mongodb.MongoServerError>;
34
+
35
+ constructor(type: string, value: any, path: string, reason?: NativeError, schemaType?: SchemaType);
36
+ }
37
+
38
+ export class DisconnectedError extends MongooseError {
39
+ name: 'DisconnectedError';
40
+ }
41
+
42
+ export class DivergentArrayError extends MongooseError {
43
+ name: 'DivergentArrayError';
44
+ }
45
+
46
+ export class MissingSchemaError extends MongooseError {
47
+ name: 'MissingSchemaError';
48
+ }
49
+
50
+ export class DocumentNotFoundError extends MongooseError {
51
+ name: 'DocumentNotFoundError';
52
+ result: any;
53
+ numAffected: number;
54
+ filter: any;
55
+ query: any;
56
+ }
57
+
58
+ export class ObjectExpectedError extends MongooseError {
59
+ name: 'ObjectExpectedError';
60
+ path: string;
61
+ }
62
+
63
+ export class ObjectParameterError extends MongooseError {
64
+ name: 'ObjectParameterError';
65
+ }
66
+
67
+ export class OverwriteModelError extends MongooseError {
68
+ name: 'OverwriteModelError';
69
+ }
70
+
71
+ export class ParallelSaveError extends MongooseError {
72
+ name: 'ParallelSaveError';
73
+ }
74
+
75
+ export class ParallelValidateError extends MongooseError {
76
+ name: 'ParallelValidateError';
77
+ }
78
+
79
+ export class MongooseServerSelectionError extends MongooseError {
80
+ name: 'MongooseServerSelectionError';
81
+ }
82
+
83
+ export class StrictModeError extends MongooseError {
84
+ name: 'StrictModeError';
85
+ isImmutableError: boolean;
86
+ path: string;
87
+ }
88
+
89
+ export class ValidationError extends MongooseError {
90
+ name: 'ValidationError';
91
+
92
+ errors: { [path: string]: ValidatorError | CastError };
93
+ addError: (path: string, error: ValidatorError | CastError) => void;
94
+
95
+ constructor(instance?: MongooseError);
96
+ }
97
+
98
+ export class ValidatorError extends MongooseError {
99
+ name: 'ValidatorError';
100
+ properties: {
101
+ message: string,
102
+ type?: string,
103
+ path?: string,
104
+ value?: any,
105
+ reason?: any
106
+ };
107
+ kind: string;
108
+ path: string;
109
+ value: any;
110
+ reason?: MongooseError | null;
111
+
112
+ constructor(properties: {
113
+ message?: string,
114
+ type?: string,
115
+ path?: string,
116
+ value?: any,
117
+ reason?: any
118
+ });
119
+ }
120
+
121
+ export class VersionError extends MongooseError {
122
+ name: 'VersionError';
123
+ version: number;
124
+ modifiedPaths: Array<string>;
125
+
126
+ constructor(doc: Document, currentVersion: number, modifiedPaths: Array<string>);
127
+ }
128
+ }
129
+ }
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference path="./Error.d.ts" />
1
2
  /// <reference path="./PipelineStage.d.ts" />
2
3
 
3
4
  import events = require('events');
@@ -913,12 +914,12 @@ declare module 'mongoose' {
913
914
  init(callback?: CallbackWithoutResult): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
914
915
 
915
916
  /** Inserts one or more new documents as a single `insertMany` call to the MongoDB server. */
916
- insertMany(docs: Array<AnyKeys<T> | AnyObject>, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult>;
917
+ insertMany(docs: Array<AnyKeys<T> | AnyObject>, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult<T>>;
917
918
  insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>;
918
- insertMany(doc: AnyKeys<T> | AnyObject, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult>;
919
+ insertMany(doc: AnyKeys<T> | AnyObject, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult<T>>;
919
920
  insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
920
- insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions, callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[] | InsertManyResult>): void;
921
- insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions, callback?: Callback<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>> | InsertManyResult>): void;
921
+ insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions, callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[] | InsertManyResult<T>>): void;
922
+ insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions, callback?: Callback<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>> | InsertManyResult<T>>): void;
922
923
 
923
924
  /**
924
925
  * Lists the indexes currently defined in MongoDB. This may or may not be
@@ -1169,9 +1170,13 @@ declare module 'mongoose' {
1169
1170
  populate?: string | string[] | PopulateOptions | PopulateOptions[];
1170
1171
  }
1171
1172
 
1172
- interface InsertManyResult extends mongodb.InsertManyResult {
1173
- mongoose?: { validationErrors?: Array<Error.CastError | Error.ValidatorError> }
1174
- }
1173
+ type InferIdType<T> = T extends { _id?: any } ? T['_id'] : Types.ObjectId;
1174
+ type InsertManyResult<T> = mongodb.InsertManyResult<T> & {
1175
+ insertedIds: {
1176
+ [key: number]: InferIdType<T>;
1177
+ };
1178
+ mongoose?: { validationErrors?: Array<Error.CastError | Error.ValidatorError> };
1179
+ };
1175
1180
 
1176
1181
  interface MapReduceOptions<T, Key, Val> {
1177
1182
  map: Function | string;
@@ -1377,7 +1382,9 @@ declare module 'mongoose' {
1377
1382
 
1378
1383
  /** Defines a pre hook for the model. */
1379
1384
  pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: 'save', fn: PreSaveMiddlewareFunction<T>): this;
1385
+ pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: 'save', options: SchemaPreOptions, fn: PreSaveMiddlewareFunction<T>): this;
1380
1386
  pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PreMiddlewareFunction<T>): this;
1387
+ pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
1381
1388
  pre<T extends Query<any, any>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
1382
1389
  pre<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, fn: PreMiddlewareFunction<T>): this;
1383
1390
  pre<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
@@ -1601,6 +1608,13 @@ declare module 'mongoose' {
1601
1608
  * field names by setting timestamps.createdAt and timestamps.updatedAt.
1602
1609
  */
1603
1610
  timestamps?: boolean | SchemaTimestampsConfig;
1611
+
1612
+ /**
1613
+ * Using `save`, `isNew`, and other Mongoose reserved names as schema path names now triggers a warning, not an error.
1614
+ * You can suppress the warning by setting { supressReservedKeysWarning: true } schema options. Keep in mind that this
1615
+ * can break plugins that rely on these reserved names.
1616
+ */
1617
+ supressReservedKeysWarning?: boolean
1604
1618
  }
1605
1619
 
1606
1620
  interface SchemaTimestampsConfig {
@@ -3098,131 +3112,6 @@ declare module 'mongoose' {
3098
3112
 
3099
3113
  type CallbackWithoutResult = (error: CallbackError) => void;
3100
3114
 
3101
- class NativeError extends global.Error { }
3102
- type CallbackError = NativeError | null;
3103
-
3104
- class Error extends global.Error {
3105
- constructor(msg: string);
3106
-
3107
- /** The type of error. "MongooseError" for generic errors. */
3108
- name: string;
3109
-
3110
- static messages: any;
3111
-
3112
- static Messages: any;
3113
- }
3114
-
3115
- namespace Error {
3116
- export class CastError extends Error {
3117
- name: 'CastError';
3118
- stringValue: string;
3119
- kind: string;
3120
- value: any;
3121
- path: string;
3122
- reason?: NativeError | null;
3123
- model?: any;
3124
-
3125
- constructor(type: string, value: any, path: string, reason?: NativeError, schemaType?: SchemaType);
3126
- }
3127
- export class SyncIndexesError extends Error {
3128
- name: 'SyncIndexesError';
3129
- errors?: Record<string, mongodb.MongoServerError>;
3130
-
3131
- constructor(type: string, value: any, path: string, reason?: NativeError, schemaType?: SchemaType);
3132
- }
3133
-
3134
- export class DisconnectedError extends Error {
3135
- name: 'DisconnectedError';
3136
- }
3137
-
3138
- export class DivergentArrayError extends Error {
3139
- name: 'DivergentArrayError';
3140
- }
3141
-
3142
- export class MissingSchemaError extends Error {
3143
- name: 'MissingSchemaError';
3144
- }
3145
-
3146
- export class DocumentNotFoundError extends Error {
3147
- name: 'DocumentNotFoundError';
3148
- result: any;
3149
- numAffected: number;
3150
- filter: any;
3151
- query: any;
3152
- }
3153
-
3154
- export class ObjectExpectedError extends Error {
3155
- name: 'ObjectExpectedError';
3156
- path: string;
3157
- }
3158
-
3159
- export class ObjectParameterError extends Error {
3160
- name: 'ObjectParameterError';
3161
- }
3162
-
3163
- export class OverwriteModelError extends Error {
3164
- name: 'OverwriteModelError';
3165
- }
3166
-
3167
- export class ParallelSaveError extends Error {
3168
- name: 'ParallelSaveError';
3169
- }
3170
-
3171
- export class ParallelValidateError extends Error {
3172
- name: 'ParallelValidateError';
3173
- }
3174
-
3175
- export class MongooseServerSelectionError extends Error {
3176
- name: 'MongooseServerSelectionError';
3177
- }
3178
-
3179
- export class StrictModeError extends Error {
3180
- name: 'StrictModeError';
3181
- isImmutableError: boolean;
3182
- path: string;
3183
- }
3184
-
3185
- export class ValidationError extends Error {
3186
- name: 'ValidationError';
3187
-
3188
- errors: { [path: string]: ValidatorError | CastError | ValidationError };
3189
- addError: (path: string, error: ValidatorError | CastError | ValidationError) => void;
3190
-
3191
- constructor(instance?: Error);
3192
- }
3193
-
3194
- export class ValidatorError extends Error {
3195
- name: 'ValidatorError';
3196
- properties: {
3197
- message: string,
3198
- type?: string,
3199
- path?: string,
3200
- value?: any,
3201
- reason?: any
3202
- };
3203
- kind: string;
3204
- path: string;
3205
- value: any;
3206
- reason?: Error | null;
3207
-
3208
- constructor(properties: {
3209
- message?: string,
3210
- type?: string,
3211
- path?: string,
3212
- value?: any,
3213
- reason?: any
3214
- });
3215
- }
3216
-
3217
- export class VersionError extends Error {
3218
- name: 'VersionError';
3219
- version: number;
3220
- modifiedPaths: Array<string>;
3221
-
3222
- constructor(doc: Document, currentVersion: number, modifiedPaths: Array<string>);
3223
- }
3224
- }
3225
-
3226
3115
  /* for ts-mongoose */
3227
3116
  class mquery {}
3228
3117
  }