typeorm 0.3.15-dev.3a72e35 → 0.3.15-dev.f6a3ce7

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.
Files changed (89) hide show
  1. package/README.md +1 -1
  2. package/browser/data-source/DataSource.js +1 -2
  3. package/browser/data-source/DataSource.js.map +1 -1
  4. package/browser/driver/mongodb/MongoDriver.js +12 -19
  5. package/browser/driver/mongodb/MongoDriver.js.map +1 -1
  6. package/browser/driver/mongodb/MongoQueryRunner.d.ts +34 -78
  7. package/browser/driver/mongodb/MongoQueryRunner.js +43 -74
  8. package/browser/driver/mongodb/MongoQueryRunner.js.map +1 -1
  9. package/browser/driver/mongodb/bson.typings.d.ts +1084 -0
  10. package/browser/driver/mongodb/bson.typings.js +3 -0
  11. package/browser/driver/mongodb/bson.typings.js.map +1 -0
  12. package/browser/driver/mongodb/typings.d.ts +4882 -4718
  13. package/browser/driver/mongodb/typings.js +23 -1
  14. package/browser/driver/mongodb/typings.js.map +1 -1
  15. package/browser/entity-manager/EntityManager.d.ts +6 -6
  16. package/browser/entity-manager/EntityManager.js.map +1 -1
  17. package/browser/entity-manager/MongoEntityManager.d.ts +46 -92
  18. package/browser/entity-manager/MongoEntityManager.js +66 -133
  19. package/browser/entity-manager/MongoEntityManager.js.map +1 -1
  20. package/browser/entity-schema/EntitySchemaColumnOptions.d.ts +1 -1
  21. package/browser/entity-schema/EntitySchemaColumnOptions.js.map +1 -1
  22. package/browser/find-options/FindOptionsOrder.d.ts +2 -2
  23. package/browser/find-options/FindOptionsOrder.js.map +1 -1
  24. package/browser/find-options/FindOptionsRelations.d.ts +2 -2
  25. package/browser/find-options/FindOptionsRelations.js.map +1 -1
  26. package/browser/find-options/FindOptionsSelect.d.ts +2 -2
  27. package/browser/find-options/FindOptionsSelect.js.map +1 -1
  28. package/browser/find-options/FindOptionsWhere.d.ts +2 -2
  29. package/browser/find-options/FindOptionsWhere.js.map +1 -1
  30. package/browser/migration/MigrationExecutor.js +2 -4
  31. package/browser/migration/MigrationExecutor.js.map +1 -1
  32. package/browser/query-builder/transformer/DocumentToEntityTransformer.js +13 -6
  33. package/browser/query-builder/transformer/DocumentToEntityTransformer.js.map +1 -1
  34. package/browser/repository/BaseEntity.d.ts +4 -4
  35. package/browser/repository/BaseEntity.js.map +1 -1
  36. package/browser/repository/EntityId.d.ts +2 -2
  37. package/browser/repository/EntityId.js.map +1 -1
  38. package/browser/repository/MongoRepository.d.ts +30 -72
  39. package/browser/repository/MongoRepository.js +1 -38
  40. package/browser/repository/MongoRepository.js.map +1 -1
  41. package/browser/repository/Repository.d.ts +6 -6
  42. package/browser/repository/Repository.js.map +1 -1
  43. package/browser/schema-builder/MongoSchemaBuilder.js.map +1 -1
  44. package/commands/InitCommand.js +3 -3
  45. package/commands/InitCommand.js.map +1 -1
  46. package/data-source/DataSource.js +7 -8
  47. package/data-source/DataSource.js.map +1 -1
  48. package/driver/mongodb/MongoDriver.js +12 -19
  49. package/driver/mongodb/MongoDriver.js.map +1 -1
  50. package/driver/mongodb/MongoQueryRunner.d.ts +34 -78
  51. package/driver/mongodb/MongoQueryRunner.js +43 -74
  52. package/driver/mongodb/MongoQueryRunner.js.map +1 -1
  53. package/driver/mongodb/bson.typings.d.ts +1084 -0
  54. package/driver/mongodb/bson.typings.js +5 -0
  55. package/driver/mongodb/bson.typings.js.map +1 -0
  56. package/driver/mongodb/typings.d.ts +4882 -4718
  57. package/driver/mongodb/typings.js +19 -0
  58. package/driver/mongodb/typings.js.map +1 -1
  59. package/entity-manager/EntityManager.d.ts +6 -6
  60. package/entity-manager/EntityManager.js.map +1 -1
  61. package/entity-manager/MongoEntityManager.d.ts +46 -92
  62. package/entity-manager/MongoEntityManager.js +66 -133
  63. package/entity-manager/MongoEntityManager.js.map +1 -1
  64. package/entity-schema/EntitySchemaColumnOptions.d.ts +1 -1
  65. package/entity-schema/EntitySchemaColumnOptions.js.map +1 -1
  66. package/find-options/FindOptionsOrder.d.ts +2 -2
  67. package/find-options/FindOptionsOrder.js.map +1 -1
  68. package/find-options/FindOptionsRelations.d.ts +2 -2
  69. package/find-options/FindOptionsRelations.js.map +1 -1
  70. package/find-options/FindOptionsSelect.d.ts +2 -2
  71. package/find-options/FindOptionsSelect.js.map +1 -1
  72. package/find-options/FindOptionsWhere.d.ts +2 -2
  73. package/find-options/FindOptionsWhere.js.map +1 -1
  74. package/index.mjs +34 -0
  75. package/migration/MigrationExecutor.js +2 -4
  76. package/migration/MigrationExecutor.js.map +1 -1
  77. package/package.json +1 -1
  78. package/query-builder/transformer/DocumentToEntityTransformer.js +13 -6
  79. package/query-builder/transformer/DocumentToEntityTransformer.js.map +1 -1
  80. package/repository/BaseEntity.d.ts +4 -4
  81. package/repository/BaseEntity.js.map +1 -1
  82. package/repository/EntityId.d.ts +2 -2
  83. package/repository/EntityId.js.map +1 -1
  84. package/repository/MongoRepository.d.ts +30 -72
  85. package/repository/MongoRepository.js +1 -38
  86. package/repository/MongoRepository.js.map +1 -1
  87. package/repository/Repository.d.ts +6 -6
  88. package/repository/Repository.js.map +1 -1
  89. package/schema-builder/MongoSchemaBuilder.js.map +1 -1
@@ -1,18 +1,18 @@
1
- import { DataSource } from "../data-source/DataSource";
2
1
  import { EntityManager } from "./EntityManager";
3
2
  import { EntityTarget } from "../common/EntityTarget";
4
- import { AggregationCursor, BulkWriteOpResultObject, ChangeStream, ChangeStreamOptions, Code, Collection, CollectionAggregationOptions, CollectionBulkWriteOptions, CollectionInsertManyOptions, CollectionInsertOneOptions, CollectionOptions, CollStats, CommandCursor, Cursor, DeleteWriteOpResultObject, FindAndModifyWriteOpResultObject, FindOneAndReplaceOption, GeoHaystackSearchOptions, GeoNearOptions, InsertOneWriteOpResult, InsertWriteOpResult, MapReduceOptions, MongoCountPreferences, MongodbIndexOptions, ObjectID, OrderedBulkOperation, ParallelCollectionScanOptions, ReadPreference, ReplaceOneOptions, UnorderedBulkOperation, UpdateWriteOpResult } from "../driver/mongodb/typings";
5
3
  import { ObjectLiteral } from "../common/ObjectLiteral";
6
4
  import { MongoQueryRunner } from "../driver/mongodb/MongoQueryRunner";
5
+ import { FindManyOptions } from "../find-options/FindManyOptions";
7
6
  import { QueryDeepPartialEntity } from "../query-builder/QueryPartialEntity";
8
7
  import { InsertResult } from "../query-builder/result/InsertResult";
9
8
  import { UpdateResult } from "../query-builder/result/UpdateResult";
10
9
  import { DeleteResult } from "../query-builder/result/DeleteResult";
11
10
  import { EntityMetadata } from "../metadata/EntityMetadata";
12
- import { FindOptionsWhere } from "../find-options/FindOptionsWhere";
13
- import { FindOptionsSelect, FindOptionsSelectByString } from "../find-options/FindOptionsSelect";
11
+ import { BulkWriteResult, AggregationCursor, Collection, FindCursor, Document, AggregateOptions, AnyBulkWriteOperation, BulkWriteOptions, Filter, CountOptions, IndexSpecification, CreateIndexesOptions, IndexDescription, DeleteResult as DeleteResultMongoDb, DeleteOptions, CommandOperationOptions, FindOneAndDeleteOptions, FindOneAndReplaceOptions, UpdateFilter, FindOneAndUpdateOptions, RenameOptions, ReplaceOptions, UpdateResult as UpdateResultMongoDb, CollStats, CollStatsOptions, ChangeStreamOptions, ChangeStream, UpdateOptions, ListIndexesOptions, ListIndexesCursor, OptionalId, InsertOneOptions, InsertOneResult, InsertManyResult, UnorderedBulkOperation, OrderedBulkOperation, IndexInformationOptions, ObjectId, FilterOperators } from "../driver/mongodb/typings";
12
+ import { DataSource } from "../data-source/DataSource";
14
13
  import { MongoFindManyOptions } from "../find-options/mongodb/MongoFindManyOptions";
15
14
  import { MongoFindOneOptions } from "../find-options/mongodb/MongoFindOneOptions";
15
+ import { FindOptionsSelect, FindOptionsSelectByString } from "../find-options/FindOptionsSelect";
16
16
  import { ColumnMetadata } from "../metadata/ColumnMetadata";
17
17
  /**
18
18
  * Entity manager supposed to work with any entity, automatically find its repository and call its methods,
@@ -27,13 +27,14 @@ export declare class MongoEntityManager extends EntityManager {
27
27
  /**
28
28
  * Finds entities that match given find options.
29
29
  */
30
- find<Entity>(entityClassOrName: EntityTarget<Entity>, options?: MongoFindManyOptions<Entity>): Promise<Entity[]>;
31
30
  /**
32
- * Finds entities that match given conditions.
31
+ * Finds entities that match given find options or conditions.
33
32
  */
34
- findBy<Entity>(entityClassOrName: EntityTarget<Entity>, where: any): Promise<Entity[]>;
33
+ find<Entity>(entityClassOrName: EntityTarget<Entity>, optionsOrConditions?: FindManyOptions<Entity> | Partial<Entity> | FilterOperators<Entity>): Promise<Entity[]>;
35
34
  /**
36
- * Finds entities that match given find options.
35
+ * Finds entities that match given find options or conditions.
36
+ * Also counts all entities that match given conditions,
37
+ * but ignores pagination settings (from and take options).
37
38
  */
38
39
  findAndCount<Entity>(entityClassOrName: EntityTarget<Entity>, options?: MongoFindManyOptions<Entity>): Promise<[Entity[], number]>;
39
40
  /**
@@ -46,9 +47,9 @@ export declare class MongoEntityManager extends EntityManager {
46
47
  *
47
48
  * @deprecated use `findBy` method instead.
48
49
  */
49
- findByIds<Entity>(entityClassOrName: EntityTarget<Entity>, ids: any[], optionsOrConditions?: any): Promise<Entity[]>;
50
+ findByIds<Entity>(entityClassOrName: EntityTarget<Entity>, ids: any[], optionsOrConditions?: FindManyOptions<Entity> | Partial<Entity>): Promise<Entity[]>;
50
51
  /**
51
- * Finds first entity that matches given find options.
52
+ * Finds first entity that matches given conditions and/or find options.
52
53
  */
53
54
  findOne<Entity>(entityClassOrName: EntityTarget<Entity>, options: MongoFindOneOptions<Entity>): Promise<Entity | null>;
54
55
  /**
@@ -64,7 +65,7 @@ export declare class MongoEntityManager extends EntityManager {
64
65
  * id: 1 // where "id" is your primary column name
65
66
  * })
66
67
  */
67
- findOneById<Entity>(entityClassOrName: EntityTarget<Entity>, id: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[]): Promise<Entity | null>;
68
+ findOneById<Entity>(entityClassOrName: EntityTarget<Entity>, id: string | number | Date | ObjectId): Promise<Entity | null>;
68
69
  /**
69
70
  * Inserts a given entity into the database.
70
71
  * Unlike save method executes a primitive operation without cascades, relations and other operations included.
@@ -79,72 +80,70 @@ export declare class MongoEntityManager extends EntityManager {
79
80
  * Executes fast and efficient UPDATE query.
80
81
  * Does not check if entity exist in the database.
81
82
  */
82
- update<Entity>(target: EntityTarget<Entity>, criteria: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | FindOptionsWhere<Entity>, partialEntity: QueryDeepPartialEntity<Entity>): Promise<UpdateResult>;
83
+ update<Entity>(target: EntityTarget<Entity>, criteria: string | string[] | number | number[] | Date | Date[] | ObjectId | ObjectId[] | ObjectLiteral, partialEntity: QueryDeepPartialEntity<Entity>): Promise<UpdateResult>;
83
84
  /**
84
85
  * Deletes entities by a given conditions.
85
86
  * Unlike save method executes a primitive operation without cascades, relations and other operations included.
86
87
  * Executes fast and efficient DELETE query.
87
88
  * Does not check if entity exist in the database.
88
89
  */
89
- delete<Entity>(target: EntityTarget<Entity>, criteria: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | FindOptionsWhere<Entity>): Promise<DeleteResult>;
90
+ delete<Entity>(target: EntityTarget<Entity>, criteria: string | string[] | number | number[] | Date | Date[] | ObjectId | ObjectId[] | ObjectLiteral[]): Promise<DeleteResult>;
90
91
  /**
91
92
  * Creates a cursor for a query that can be used to iterate over results from MongoDB.
92
93
  */
93
- createCursor<Entity, T = any>(entityClassOrName: EntityTarget<Entity>, query?: ObjectLiteral): Cursor<T>;
94
+ createCursor<Entity, T = any>(entityClassOrName: EntityTarget<Entity>, query?: ObjectLiteral): FindCursor<T>;
94
95
  /**
95
96
  * Creates a cursor for a query that can be used to iterate over results from MongoDB.
96
97
  * This returns modified version of cursor that transforms each result into Entity model.
97
98
  */
98
- createEntityCursor<Entity>(entityClassOrName: EntityTarget<Entity>, query?: ObjectLiteral): Cursor<Entity>;
99
+ createEntityCursor<Entity>(entityClassOrName: EntityTarget<Entity>, query?: ObjectLiteral): FindCursor<Entity>;
99
100
  /**
100
101
  * Execute an aggregation framework pipeline against the collection.
101
102
  */
102
- aggregate<Entity, R = any>(entityClassOrName: EntityTarget<Entity>, pipeline: ObjectLiteral[], options?: CollectionAggregationOptions): AggregationCursor<R>;
103
+ aggregate<Entity, R = any>(entityClassOrName: EntityTarget<Entity>, pipeline: Document[], options?: AggregateOptions): AggregationCursor<R>;
103
104
  /**
104
105
  * Execute an aggregation framework pipeline against the collection.
105
106
  * This returns modified version of cursor that transforms each result into Entity model.
106
107
  */
107
- aggregateEntity<Entity>(entityClassOrName: EntityTarget<Entity>, pipeline: ObjectLiteral[], options?: CollectionAggregationOptions): AggregationCursor<Entity>;
108
+ aggregateEntity<Entity>(entityClassOrName: EntityTarget<Entity>, pipeline: Document[], options?: AggregateOptions): AggregationCursor<Entity>;
108
109
  /**
109
110
  * Perform a bulkWrite operation without a fluent API.
110
111
  */
111
- bulkWrite<Entity>(entityClassOrName: EntityTarget<Entity>, operations: ObjectLiteral[], options?: CollectionBulkWriteOptions): Promise<BulkWriteOpResultObject>;
112
+ bulkWrite<Entity>(entityClassOrName: EntityTarget<Entity>, operations: AnyBulkWriteOperation<Document>[], options?: BulkWriteOptions): Promise<BulkWriteResult>;
112
113
  /**
113
114
  * Count number of matching documents in the db to a query.
114
115
  */
115
- count<Entity>(entityClassOrName: EntityTarget<Entity>, query?: ObjectLiteral, options?: MongoCountPreferences): Promise<number>;
116
+ count<Entity>(entityClassOrName: EntityTarget<Entity>, query?: Filter<Document>, options?: CountOptions): Promise<number>;
116
117
  /**
117
118
  * Count number of matching documents in the db to a query.
118
119
  */
119
- countBy<Entity>(entityClassOrName: EntityTarget<Entity>, query?: ObjectLiteral, options?: MongoCountPreferences): Promise<number>;
120
+ countBy<Entity>(entityClassOrName: EntityTarget<Entity>, query?: ObjectLiteral, options?: CountOptions): Promise<number>;
120
121
  /**
121
122
  * Creates an index on the db and collection.
122
123
  */
123
- createCollectionIndex<Entity>(entityClassOrName: EntityTarget<Entity>, fieldOrSpec: string | any, options?: MongodbIndexOptions): Promise<string>;
124
+ createCollectionIndex<Entity>(entityClassOrName: EntityTarget<Entity>, fieldOrSpec: IndexSpecification, options?: CreateIndexesOptions): Promise<string>;
124
125
  /**
125
126
  * Creates multiple indexes in the collection, this method is only supported for MongoDB 2.6 or higher.
126
127
  * Earlier version of MongoDB will throw a command not supported error.
127
128
  * Index specifications are defined at http://docs.mongodb.org/manual/reference/command/createIndexes/.
128
129
  */
129
- createCollectionIndexes<Entity>(entityClassOrName: EntityTarget<Entity>, indexSpecs: ObjectLiteral[]): Promise<void>;
130
+ createCollectionIndexes<Entity>(entityClassOrName: EntityTarget<Entity>, indexSpecs: IndexDescription[]): Promise<string[]>;
130
131
  /**
131
132
  * Delete multiple documents on MongoDB.
132
133
  */
133
- deleteMany<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, options?: CollectionOptions): Promise<DeleteWriteOpResultObject>;
134
+ deleteMany<Entity>(entityClassOrName: EntityTarget<Entity>, query: Filter<Document>, options?: DeleteOptions): Promise<DeleteResultMongoDb>;
134
135
  /**
135
136
  * Delete a document on MongoDB.
136
137
  */
137
- deleteOne<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, options?: CollectionOptions): Promise<DeleteWriteOpResultObject>;
138
+ deleteOne<Entity>(entityClassOrName: EntityTarget<Entity>, query: Filter<Document>, options?: DeleteOptions): Promise<DeleteResultMongoDb>;
138
139
  /**
139
140
  * The distinct command returns returns a list of distinct values for the given key across a collection.
140
141
  */
141
- distinct<Entity>(entityClassOrName: EntityTarget<Entity>, key: string, query: ObjectLiteral, options?: {
142
- readPreference?: ReadPreference | string;
143
- }): Promise<any>;
142
+ distinct<Entity>(entityClassOrName: EntityTarget<Entity>, key: string, query: Filter<Document>, options?: CommandOperationOptions): Promise<any>;
144
143
  /**
145
144
  * Drops an index from this collection.
146
145
  */
147
- dropCollectionIndex<Entity>(entityClassOrName: EntityTarget<Entity>, indexName: string, options?: CollectionOptions): Promise<any>;
146
+ dropCollectionIndex<Entity>(entityClassOrName: EntityTarget<Entity>, indexName: string, options?: CommandOperationOptions): Promise<any>;
148
147
  /**
149
148
  * Drops all indexes from the collection.
150
149
  */
@@ -152,37 +151,19 @@ export declare class MongoEntityManager extends EntityManager {
152
151
  /**
153
152
  * Find a document and delete it in one atomic operation, requires a write lock for the duration of the operation.
154
153
  */
155
- findOneAndDelete<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, options?: {
156
- projection?: Object;
157
- sort?: Object;
158
- maxTimeMS?: number;
159
- }): Promise<FindAndModifyWriteOpResultObject>;
154
+ findOneAndDelete<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, options?: FindOneAndDeleteOptions): Promise<Document>;
160
155
  /**
161
156
  * Find a document and replace it in one atomic operation, requires a write lock for the duration of the operation.
162
157
  */
163
- findOneAndReplace<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, replacement: Object, options?: FindOneAndReplaceOption): Promise<FindAndModifyWriteOpResultObject>;
158
+ findOneAndReplace<Entity>(entityClassOrName: EntityTarget<Entity>, query: Filter<Document>, replacement: Document, options?: FindOneAndReplaceOptions): Promise<Document>;
164
159
  /**
165
160
  * Find a document and update it in one atomic operation, requires a write lock for the duration of the operation.
166
161
  */
167
- findOneAndUpdate<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, update: Object, options?: FindOneAndReplaceOption): Promise<FindAndModifyWriteOpResultObject>;
168
- /**
169
- * Execute a geo search using a geo haystack index on a collection.
170
- */
171
- geoHaystackSearch<Entity>(entityClassOrName: EntityTarget<Entity>, x: number, y: number, options?: GeoHaystackSearchOptions): Promise<any>;
172
- /**
173
- * Execute the geoNear command to search for items in the collection.
174
- */
175
- geoNear<Entity>(entityClassOrName: EntityTarget<Entity>, x: number, y: number, options?: GeoNearOptions): Promise<any>;
176
- /**
177
- * Run a group command across a collection.
178
- */
179
- group<Entity>(entityClassOrName: EntityTarget<Entity>, keys: Object | Array<any> | Function | Code, condition: Object, initial: Object, reduce: Function | Code, finalize: Function | Code, command: boolean, options?: {
180
- readPreference?: ReadPreference | string;
181
- }): Promise<any>;
162
+ findOneAndUpdate<Entity>(entityClassOrName: EntityTarget<Entity>, query: Filter<Document>, update: UpdateFilter<Document>, options?: FindOneAndUpdateOptions): Promise<Document>;
182
163
  /**
183
164
  * Retrieve all the indexes on the collection.
184
165
  */
185
- collectionIndexes<Entity>(entityClassOrName: EntityTarget<Entity>): Promise<any>;
166
+ collectionIndexes<Entity>(entityClassOrName: EntityTarget<Entity>): Promise<Document>;
186
167
  /**
187
168
  * Retrieve all the indexes on the collection.
188
169
  */
@@ -190,25 +171,23 @@ export declare class MongoEntityManager extends EntityManager {
190
171
  /**
191
172
  * Retrieves this collections index info.
192
173
  */
193
- collectionIndexInformation<Entity>(entityClassOrName: EntityTarget<Entity>, options?: {
194
- full: boolean;
195
- }): Promise<any>;
174
+ collectionIndexInformation<Entity>(entityClassOrName: EntityTarget<Entity>, options?: IndexInformationOptions): Promise<any>;
196
175
  /**
197
176
  * Initiate an In order bulk write operation, operations will be serially executed in the order they are added, creating a new operation for each switch in types.
198
177
  */
199
- initializeOrderedBulkOp<Entity>(entityClassOrName: EntityTarget<Entity>, options?: CollectionOptions): OrderedBulkOperation;
178
+ initializeOrderedBulkOp<Entity>(entityClassOrName: EntityTarget<Entity>, options?: BulkWriteOptions): OrderedBulkOperation;
200
179
  /**
201
180
  * Initiate a Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order.
202
181
  */
203
- initializeUnorderedBulkOp<Entity>(entityClassOrName: EntityTarget<Entity>, options?: CollectionOptions): UnorderedBulkOperation;
182
+ initializeUnorderedBulkOp<Entity>(entityClassOrName: EntityTarget<Entity>, options?: BulkWriteOptions): UnorderedBulkOperation;
204
183
  /**
205
184
  * Inserts an array of documents into MongoDB.
206
185
  */
207
- insertMany<Entity>(entityClassOrName: EntityTarget<Entity>, docs: ObjectLiteral[], options?: CollectionInsertManyOptions): Promise<InsertWriteOpResult>;
186
+ insertMany<Entity>(entityClassOrName: EntityTarget<Entity>, docs: OptionalId<Document>[], options?: BulkWriteOptions): Promise<InsertManyResult>;
208
187
  /**
209
188
  * Inserts a single document into MongoDB.
210
189
  */
211
- insertOne<Entity>(entityClassOrName: EntityTarget<Entity>, doc: ObjectLiteral, options?: CollectionInsertOneOptions): Promise<InsertOneWriteOpResult>;
190
+ insertOne<Entity>(entityClassOrName: EntityTarget<Entity>, doc: OptionalId<Document>, options?: InsertOneOptions): Promise<InsertOneResult>;
212
191
  /**
213
192
  * Returns if the collection is a capped collection.
214
193
  */
@@ -216,57 +195,32 @@ export declare class MongoEntityManager extends EntityManager {
216
195
  /**
217
196
  * Get the list of all indexes information for the collection.
218
197
  */
219
- listCollectionIndexes<Entity>(entityClassOrName: EntityTarget<Entity>, options?: {
220
- batchSize?: number;
221
- readPreference?: ReadPreference | string;
222
- }): CommandCursor;
223
- /**
224
- * Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.
225
- */
226
- mapReduce<Entity>(entityClassOrName: EntityTarget<Entity>, map: Function | string, reduce: Function | string, options?: MapReduceOptions): Promise<any>;
227
- /**
228
- * Return N number of parallel cursors for a collection allowing parallel reading of entire collection.
229
- * There are no ordering guarantees for returned results.
230
- */
231
- parallelCollectionScan<Entity>(entityClassOrName: EntityTarget<Entity>, options?: ParallelCollectionScanOptions): Promise<Cursor<Entity>[]>;
232
- /**
233
- * Reindex all indexes on the collection Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
234
- */
235
- reIndex<Entity>(entityClassOrName: EntityTarget<Entity>): Promise<any>;
198
+ listCollectionIndexes<Entity>(entityClassOrName: EntityTarget<Entity>, options?: ListIndexesOptions): ListIndexesCursor;
236
199
  /**
237
200
  * Reindex all indexes on the collection Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
238
201
  */
239
- rename<Entity>(entityClassOrName: EntityTarget<Entity>, newName: string, options?: {
240
- dropTarget?: boolean;
241
- }): Promise<Collection<any>>;
202
+ rename<Entity>(entityClassOrName: EntityTarget<Entity>, newName: string, options?: RenameOptions): Promise<Collection<Document>>;
242
203
  /**
243
204
  * Replace a document on MongoDB.
244
205
  */
245
- replaceOne<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, doc: ObjectLiteral, options?: ReplaceOneOptions): Promise<UpdateWriteOpResult>;
206
+ replaceOne<Entity>(entityClassOrName: EntityTarget<Entity>, query: Filter<Document>, doc: Document, options?: ReplaceOptions): Promise<Document | UpdateResultMongoDb>;
246
207
  /**
247
208
  * Get all the collection statistics.
248
209
  */
249
- stats<Entity>(entityClassOrName: EntityTarget<Entity>, options?: {
250
- scale: number;
251
- }): Promise<CollStats>;
252
- watch<Entity>(entityClassOrName: EntityTarget<Entity>, pipeline?: Object[], options?: ChangeStreamOptions): ChangeStream;
210
+ stats<Entity>(entityClassOrName: EntityTarget<Entity>, options?: CollStatsOptions): Promise<CollStats>;
211
+ watch<Entity>(entityClassOrName: EntityTarget<Entity>, pipeline?: Document[], options?: ChangeStreamOptions): ChangeStream;
253
212
  /**
254
213
  * Update multiple documents on MongoDB.
255
214
  */
256
- updateMany<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, update: ObjectLiteral, options?: {
257
- upsert?: boolean;
258
- w?: any;
259
- wtimeout?: number;
260
- j?: boolean;
261
- }): Promise<UpdateWriteOpResult>;
215
+ updateMany<Entity>(entityClassOrName: EntityTarget<Entity>, query: Filter<Document>, update: UpdateFilter<Document>, options?: UpdateOptions): Promise<Document | UpdateResultMongoDb>;
262
216
  /**
263
217
  * Update a single document on MongoDB.
264
218
  */
265
- updateOne<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, update: ObjectLiteral, options?: ReplaceOneOptions): Promise<UpdateWriteOpResult>;
219
+ updateOne<Entity>(entityClassOrName: EntityTarget<Entity>, query: Filter<Document>, update: UpdateFilter<Document>, options?: UpdateOptions): Promise<Document | UpdateResultMongoDb>;
266
220
  /**
267
221
  * Converts FindManyOptions to mongodb query.
268
222
  */
269
- protected convertFindManyOptionsOrConditionsToMongodbQuery<Entity>(optionsOrConditions: MongoFindManyOptions<Entity> | Partial<Entity> | any[] | undefined): ObjectLiteral | undefined;
223
+ protected convertFindManyOptionsOrConditionsToMongodbQuery<Entity>(optionsOrConditions: MongoFindManyOptions<Entity> | Partial<Entity> | FilterOperators<Entity> | any[] | undefined): ObjectLiteral | undefined;
270
224
  /**
271
225
  * Converts FindOneOptions to mongodb query.
272
226
  */
@@ -286,8 +240,8 @@ export declare class MongoEntityManager extends EntityManager {
286
240
  /**
287
241
  * Overrides cursor's toArray and next methods to convert results to entity automatically.
288
242
  */
289
- protected applyEntityTransformationToCursor<Entity extends ObjectLiteral>(metadata: EntityMetadata, cursor: Cursor<Entity> | AggregationCursor<Entity>): void;
290
- protected filterSoftDeleted<Entity>(cursor: Cursor<Entity>, deleteDateColumn: ColumnMetadata, query?: ObjectLiteral): void;
243
+ protected applyEntityTransformationToCursor<Entity extends ObjectLiteral>(metadata: EntityMetadata, cursor: FindCursor<Entity> | AggregationCursor<Entity>): void;
244
+ protected filterSoftDeleted<Entity>(cursor: FindCursor<Entity>, deleteDateColumn: ColumnMetadata, query?: ObjectLiteral): void;
291
245
  /**
292
246
  * Finds first entity that matches given conditions and/or find options.
293
247
  */
@@ -5,6 +5,7 @@ import { PlatformTools } from "../platform/PlatformTools";
5
5
  import { InsertResult } from "../query-builder/result/InsertResult";
6
6
  import { UpdateResult } from "../query-builder/result/UpdateResult";
7
7
  import { DeleteResult } from "../query-builder/result/DeleteResult";
8
+ import { ObjectId, } from "../driver/mongodb/typings";
8
9
  import { ObjectUtils } from "../util/ObjectUtils";
9
10
  /**
10
11
  * Entity manager supposed to work with any entity, automatically find its repository and call its methods,
@@ -30,17 +31,35 @@ export class MongoEntityManager extends EntityManager {
30
31
  /**
31
32
  * Finds entities that match given find options.
32
33
  */
33
- async find(entityClassOrName, options) {
34
- return this.executeFind(entityClassOrName, options);
35
- }
36
34
  /**
37
- * Finds entities that match given conditions.
35
+ * Finds entities that match given find options or conditions.
38
36
  */
39
- async findBy(entityClassOrName, where) {
40
- return this.executeFind(entityClassOrName, where);
37
+ async find(entityClassOrName, optionsOrConditions) {
38
+ const query = this.convertFindManyOptionsOrConditionsToMongodbQuery(optionsOrConditions);
39
+ const cursor = this.createEntityCursor(entityClassOrName, query);
40
+ const deleteDateColumn = this.connection.getMetadata(entityClassOrName).deleteDateColumn;
41
+ if (FindOptionsUtils.isFindManyOptions(optionsOrConditions)) {
42
+ if (optionsOrConditions.select)
43
+ cursor.project(this.convertFindOptionsSelectToProjectCriteria(optionsOrConditions.select));
44
+ if (optionsOrConditions.skip)
45
+ cursor.skip(optionsOrConditions.skip);
46
+ if (optionsOrConditions.take)
47
+ cursor.limit(optionsOrConditions.take);
48
+ if (optionsOrConditions.order)
49
+ cursor.sort(this.convertFindOptionsOrderToOrderCriteria(optionsOrConditions.order));
50
+ if (deleteDateColumn && !optionsOrConditions.withDeleted) {
51
+ this.filterSoftDeleted(cursor, deleteDateColumn, query);
52
+ }
53
+ }
54
+ else if (deleteDateColumn) {
55
+ this.filterSoftDeleted(cursor, deleteDateColumn, query);
56
+ }
57
+ return cursor.toArray();
41
58
  }
42
59
  /**
43
- * Finds entities that match given find options.
60
+ * Finds entities that match given find options or conditions.
61
+ * Also counts all entities that match given conditions,
62
+ * but ignores pagination settings (from and take options).
44
63
  */
45
64
  async findAndCount(entityClassOrName, options) {
46
65
  return this.executeFindAndCount(entityClassOrName, options);
@@ -60,13 +79,13 @@ export class MongoEntityManager extends EntityManager {
60
79
  async findByIds(entityClassOrName, ids, optionsOrConditions) {
61
80
  const metadata = this.connection.getMetadata(entityClassOrName);
62
81
  const query = this.convertFindManyOptionsOrConditionsToMongodbQuery(optionsOrConditions) || {};
63
- const objectIdInstance = PlatformTools.load("mongodb").ObjectID;
82
+ const objectIdInstance = PlatformTools.load("mongodb").ObjectId;
64
83
  query["_id"] = {
65
84
  $in: ids.map((id) => {
66
85
  if (typeof id === "string") {
67
86
  return new objectIdInstance(id);
68
87
  }
69
- if (ObjectUtils.isObject(id)) {
88
+ if (typeof id === "object") {
70
89
  if (id instanceof objectIdInstance) {
71
90
  return id;
72
91
  }
@@ -77,8 +96,7 @@ export class MongoEntityManager extends EntityManager {
77
96
  }
78
97
  }),
79
98
  };
80
- const cursor = await this.createEntityCursor(entityClassOrName, query);
81
- const deleteDateColumn = this.connection.getMetadata(entityClassOrName).deleteDateColumn;
99
+ const cursor = this.createEntityCursor(entityClassOrName, query);
82
100
  if (FindOptionsUtils.isFindManyOptions(optionsOrConditions)) {
83
101
  if (optionsOrConditions.select)
84
102
  cursor.project(this.convertFindOptionsSelectToProjectCriteria(optionsOrConditions.select));
@@ -88,17 +106,11 @@ export class MongoEntityManager extends EntityManager {
88
106
  cursor.limit(optionsOrConditions.take);
89
107
  if (optionsOrConditions.order)
90
108
  cursor.sort(this.convertFindOptionsOrderToOrderCriteria(optionsOrConditions.order));
91
- if (deleteDateColumn && !optionsOrConditions.withDeleted) {
92
- this.filterSoftDeleted(cursor, deleteDateColumn, query);
93
- }
94
- }
95
- else if (deleteDateColumn) {
96
- this.filterSoftDeleted(cursor, deleteDateColumn, query);
97
109
  }
98
- return await cursor.toArray();
110
+ return cursor.toArray();
99
111
  }
100
112
  /**
101
- * Finds first entity that matches given find options.
113
+ * Finds first entity that matches given conditions and/or find options.
102
114
  */
103
115
  async findOne(entityClassOrName, options) {
104
116
  return this.executeFindOne(entityClassOrName, options);
@@ -202,7 +214,7 @@ export class MongoEntityManager extends EntityManager {
202
214
  /**
203
215
  * Creates a cursor for a query that can be used to iterate over results from MongoDB.
204
216
  */
205
- createCursor(entityClassOrName, query) {
217
+ createCursor(entityClassOrName, query = {}) {
206
218
  const metadata = this.connection.getMetadata(entityClassOrName);
207
219
  return this.mongoQueryRunner.cursor(metadata.tableName, query);
208
220
  }
@@ -210,7 +222,7 @@ export class MongoEntityManager extends EntityManager {
210
222
  * Creates a cursor for a query that can be used to iterate over results from MongoDB.
211
223
  * This returns modified version of cursor that transforms each result into Entity model.
212
224
  */
213
- createEntityCursor(entityClassOrName, query) {
225
+ createEntityCursor(entityClassOrName, query = {}) {
214
226
  const metadata = this.connection.getMetadata(entityClassOrName);
215
227
  const cursor = this.createCursor(entityClassOrName, query);
216
228
  this.applyEntityTransformationToCursor(metadata, cursor);
@@ -243,7 +255,7 @@ export class MongoEntityManager extends EntityManager {
243
255
  /**
244
256
  * Count number of matching documents in the db to a query.
245
257
  */
246
- count(entityClassOrName, query, options) {
258
+ count(entityClassOrName, query = {}, options = {}) {
247
259
  const metadata = this.connection.getMetadata(entityClassOrName);
248
260
  return this.mongoQueryRunner.count(metadata.tableName, query, options);
249
261
  }
@@ -272,14 +284,14 @@ export class MongoEntityManager extends EntityManager {
272
284
  /**
273
285
  * Delete multiple documents on MongoDB.
274
286
  */
275
- deleteMany(entityClassOrName, query, options) {
287
+ deleteMany(entityClassOrName, query, options = {}) {
276
288
  const metadata = this.connection.getMetadata(entityClassOrName);
277
289
  return this.mongoQueryRunner.deleteMany(metadata.tableName, query, options);
278
290
  }
279
291
  /**
280
292
  * Delete a document on MongoDB.
281
293
  */
282
- deleteOne(entityClassOrName, query, options) {
294
+ deleteOne(entityClassOrName, query, options = {}) {
283
295
  const metadata = this.connection.getMetadata(entityClassOrName);
284
296
  return this.mongoQueryRunner.deleteOne(metadata.tableName, query, options);
285
297
  }
@@ -325,27 +337,6 @@ export class MongoEntityManager extends EntityManager {
325
337
  const metadata = this.connection.getMetadata(entityClassOrName);
326
338
  return this.mongoQueryRunner.findOneAndUpdate(metadata.tableName, query, update, options);
327
339
  }
328
- /**
329
- * Execute a geo search using a geo haystack index on a collection.
330
- */
331
- geoHaystackSearch(entityClassOrName, x, y, options) {
332
- const metadata = this.connection.getMetadata(entityClassOrName);
333
- return this.mongoQueryRunner.geoHaystackSearch(metadata.tableName, x, y, options);
334
- }
335
- /**
336
- * Execute the geoNear command to search for items in the collection.
337
- */
338
- geoNear(entityClassOrName, x, y, options) {
339
- const metadata = this.connection.getMetadata(entityClassOrName);
340
- return this.mongoQueryRunner.geoNear(metadata.tableName, x, y, options);
341
- }
342
- /**
343
- * Run a group command across a collection.
344
- */
345
- group(entityClassOrName, keys, condition, initial, reduce, finalize, command, options) {
346
- const metadata = this.connection.getMetadata(entityClassOrName);
347
- return this.mongoQueryRunner.group(metadata.tableName, keys, condition, initial, reduce, finalize, command, options);
348
- }
349
340
  /**
350
341
  * Retrieve all the indexes on the collection.
351
342
  */
@@ -409,28 +400,6 @@ export class MongoEntityManager extends EntityManager {
409
400
  const metadata = this.connection.getMetadata(entityClassOrName);
410
401
  return this.mongoQueryRunner.listCollectionIndexes(metadata.tableName, options);
411
402
  }
412
- /**
413
- * Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.
414
- */
415
- mapReduce(entityClassOrName, map, reduce, options) {
416
- const metadata = this.connection.getMetadata(entityClassOrName);
417
- return this.mongoQueryRunner.mapReduce(metadata.tableName, map, reduce, options);
418
- }
419
- /**
420
- * Return N number of parallel cursors for a collection allowing parallel reading of entire collection.
421
- * There are no ordering guarantees for returned results.
422
- */
423
- parallelCollectionScan(entityClassOrName, options) {
424
- const metadata = this.connection.getMetadata(entityClassOrName);
425
- return this.mongoQueryRunner.parallelCollectionScan(metadata.tableName, options);
426
- }
427
- /**
428
- * Reindex all indexes on the collection Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
429
- */
430
- reIndex(entityClassOrName) {
431
- const metadata = this.connection.getMetadata(entityClassOrName);
432
- return this.mongoQueryRunner.reIndex(metadata.tableName);
433
- }
434
403
  /**
435
404
  * Reindex all indexes on the collection Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
436
405
  */
@@ -538,7 +507,7 @@ export class MongoEntityManager extends EntityManager {
538
507
  * Ensures given id is an id for query.
539
508
  */
540
509
  convertMixedCriteria(metadata, idMap) {
541
- const objectIdInstance = PlatformTools.load("mongodb").ObjectID;
510
+ const objectIdInstance = PlatformTools.load("mongodb").ObjectId;
542
511
  // check first if it's ObjectId compatible:
543
512
  // string, number, Buffer, ObjectId or ObjectId-like
544
513
  if (objectIdInstance.isValid(idMap)) {
@@ -556,7 +525,7 @@ export class MongoEntityManager extends EntityManager {
556
525
  return query;
557
526
  }, {});
558
527
  }
559
- // last resort: try to convert it to an ObjectID anyway
528
+ // last resort: try to convert it to an ObjectId anyway
560
529
  // most likely it will fail, but we want to be backwards compatible and keep the same thrown Errors.
561
530
  // it can still pass with null/undefined
562
531
  return {
@@ -567,68 +536,32 @@ export class MongoEntityManager extends EntityManager {
567
536
  * Overrides cursor's toArray and next methods to convert results to entity automatically.
568
537
  */
569
538
  applyEntityTransformationToCursor(metadata, cursor) {
570
- // mongdb-3.7 exports Cursor, mongodb-4.2 exports FindCursor, provide support for both.
571
- const ParentCursor = PlatformTools.load("mongodb").Cursor ||
572
- PlatformTools.load("mongodb").FindCursor;
573
539
  const queryRunner = this.mongoQueryRunner;
574
- cursor.toArray = function (callback) {
575
- if (callback) {
576
- ParentCursor.prototype.toArray.call(this, (error, results) => {
577
- if (error) {
578
- callback(error, results);
579
- return;
580
- }
581
- const transformer = new DocumentToEntityTransformer();
582
- const entities = transformer.transformAll(results, metadata);
583
- // broadcast "load" events
584
- queryRunner.broadcaster
585
- .broadcast("Load", metadata, entities)
586
- .then(() => callback(error, entities));
587
- });
588
- }
589
- else {
590
- return ParentCursor.prototype.toArray
591
- .call(this)
592
- .then((results) => {
593
- const transformer = new DocumentToEntityTransformer();
594
- const entities = transformer.transformAll(results, metadata);
595
- // broadcast "load" events
596
- return queryRunner.broadcaster
597
- .broadcast("Load", metadata, entities)
598
- .then(() => entities);
599
- });
600
- }
601
- };
602
- cursor.next = function (callback) {
603
- if (callback) {
604
- ParentCursor.prototype.next.call(this, (error, result) => {
605
- if (error || !result) {
606
- callback(error, result);
607
- return;
608
- }
609
- const transformer = new DocumentToEntityTransformer();
610
- const entity = transformer.transform(result, metadata);
611
- // broadcast "load" events
612
- queryRunner.broadcaster
613
- .broadcast("Load", metadata, [entity])
614
- .then(() => callback(error, entity));
615
- });
616
- }
617
- else {
618
- return ParentCursor.prototype.next
619
- .call(this)
620
- .then((result) => {
621
- if (!result)
622
- return result;
623
- const transformer = new DocumentToEntityTransformer();
624
- const entity = transformer.transform(result, metadata);
625
- // broadcast "load" events
626
- return queryRunner.broadcaster
627
- .broadcast("Load", metadata, [entity])
628
- .then(() => entity);
629
- });
540
+ cursor.toArray = () => cursor
541
+ .clone()
542
+ .toArray()
543
+ .then(async (results) => {
544
+ const transformer = new DocumentToEntityTransformer();
545
+ const entities = transformer.transformAll(results, metadata);
546
+ // broadcast "load" events
547
+ await queryRunner.broadcaster.broadcast("Load", metadata, entities);
548
+ return entities;
549
+ });
550
+ cursor.next = () => cursor
551
+ .clone()
552
+ .next()
553
+ .then(async (result) => {
554
+ if (!result) {
555
+ return result;
630
556
  }
631
- };
557
+ const transformer = new DocumentToEntityTransformer();
558
+ const entity = transformer.transform(result, metadata);
559
+ // broadcast "load" events
560
+ await queryRunner.broadcaster.broadcast("Load", metadata, [
561
+ entity,
562
+ ]);
563
+ return entity;
564
+ });
632
565
  }
633
566
  filterSoftDeleted(cursor, deleteDateColumn, query) {
634
567
  const { $or, ...restQuery } = query !== null && query !== void 0 ? query : {};
@@ -644,7 +577,7 @@ export class MongoEntityManager extends EntityManager {
644
577
  * Finds first entity that matches given conditions and/or find options.
645
578
  */
646
579
  async executeFindOne(entityClassOrName, optionsOrConditions, maybeOptions) {
647
- const objectIdInstance = PlatformTools.load("mongodb").ObjectID;
580
+ const objectIdInstance = PlatformTools.load("mongodb").ObjectId;
648
581
  const id = optionsOrConditions instanceof objectIdInstance ||
649
582
  typeof optionsOrConditions === "string"
650
583
  ? optionsOrConditions
@@ -653,9 +586,9 @@ export class MongoEntityManager extends EntityManager {
653
586
  const query = this.convertFindOneOptionsOrConditionsToMongodbQuery(findOneOptionsOrConditions) || {};
654
587
  if (id) {
655
588
  query["_id"] =
656
- id instanceof objectIdInstance ? id : new objectIdInstance(id);
589
+ id instanceof objectIdInstance ? id : new ObjectId(id);
657
590
  }
658
- const cursor = await this.createEntityCursor(entityClassOrName, query);
591
+ const cursor = this.createEntityCursor(entityClassOrName, query);
659
592
  const deleteDateColumn = this.connection.getMetadata(entityClassOrName).deleteDateColumn;
660
593
  if (FindOptionsUtils.isFindOneOptions(findOneOptionsOrConditions)) {
661
594
  if (findOneOptionsOrConditions.select)
@@ -675,7 +608,7 @@ export class MongoEntityManager extends EntityManager {
675
608
  }
676
609
  async executeFind(entityClassOrName, optionsOrConditions) {
677
610
  const query = this.convertFindManyOptionsOrConditionsToMongodbQuery(optionsOrConditions);
678
- const cursor = await this.createEntityCursor(entityClassOrName, query);
611
+ const cursor = this.createEntityCursor(entityClassOrName, query);
679
612
  const deleteDateColumn = this.connection.getMetadata(entityClassOrName).deleteDateColumn;
680
613
  if (FindOptionsUtils.isFindManyOptions(optionsOrConditions)) {
681
614
  if (optionsOrConditions.select)