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.
- package/README.md +1 -1
- package/browser/data-source/DataSource.js +1 -2
- package/browser/data-source/DataSource.js.map +1 -1
- package/browser/driver/mongodb/MongoDriver.js +12 -19
- package/browser/driver/mongodb/MongoDriver.js.map +1 -1
- package/browser/driver/mongodb/MongoQueryRunner.d.ts +34 -78
- package/browser/driver/mongodb/MongoQueryRunner.js +43 -74
- package/browser/driver/mongodb/MongoQueryRunner.js.map +1 -1
- package/browser/driver/mongodb/bson.typings.d.ts +1084 -0
- package/browser/driver/mongodb/bson.typings.js +3 -0
- package/browser/driver/mongodb/bson.typings.js.map +1 -0
- package/browser/driver/mongodb/typings.d.ts +4882 -4718
- package/browser/driver/mongodb/typings.js +23 -1
- package/browser/driver/mongodb/typings.js.map +1 -1
- package/browser/entity-manager/EntityManager.d.ts +6 -6
- package/browser/entity-manager/EntityManager.js.map +1 -1
- package/browser/entity-manager/MongoEntityManager.d.ts +46 -92
- package/browser/entity-manager/MongoEntityManager.js +66 -133
- package/browser/entity-manager/MongoEntityManager.js.map +1 -1
- package/browser/entity-schema/EntitySchemaColumnOptions.d.ts +1 -1
- package/browser/entity-schema/EntitySchemaColumnOptions.js.map +1 -1
- package/browser/find-options/FindOptionsOrder.d.ts +2 -2
- package/browser/find-options/FindOptionsOrder.js.map +1 -1
- package/browser/find-options/FindOptionsRelations.d.ts +2 -2
- package/browser/find-options/FindOptionsRelations.js.map +1 -1
- package/browser/find-options/FindOptionsSelect.d.ts +2 -2
- package/browser/find-options/FindOptionsSelect.js.map +1 -1
- package/browser/find-options/FindOptionsWhere.d.ts +2 -2
- package/browser/find-options/FindOptionsWhere.js.map +1 -1
- package/browser/migration/MigrationExecutor.js +2 -4
- package/browser/migration/MigrationExecutor.js.map +1 -1
- package/browser/query-builder/transformer/DocumentToEntityTransformer.js +13 -6
- package/browser/query-builder/transformer/DocumentToEntityTransformer.js.map +1 -1
- package/browser/repository/BaseEntity.d.ts +4 -4
- package/browser/repository/BaseEntity.js.map +1 -1
- package/browser/repository/EntityId.d.ts +2 -2
- package/browser/repository/EntityId.js.map +1 -1
- package/browser/repository/MongoRepository.d.ts +30 -72
- package/browser/repository/MongoRepository.js +1 -38
- package/browser/repository/MongoRepository.js.map +1 -1
- package/browser/repository/Repository.d.ts +6 -6
- package/browser/repository/Repository.js.map +1 -1
- package/browser/schema-builder/MongoSchemaBuilder.js.map +1 -1
- package/commands/InitCommand.js +3 -3
- package/commands/InitCommand.js.map +1 -1
- package/data-source/DataSource.js +7 -8
- package/data-source/DataSource.js.map +1 -1
- package/driver/mongodb/MongoDriver.js +12 -19
- package/driver/mongodb/MongoDriver.js.map +1 -1
- package/driver/mongodb/MongoQueryRunner.d.ts +34 -78
- package/driver/mongodb/MongoQueryRunner.js +43 -74
- package/driver/mongodb/MongoQueryRunner.js.map +1 -1
- package/driver/mongodb/bson.typings.d.ts +1084 -0
- package/driver/mongodb/bson.typings.js +5 -0
- package/driver/mongodb/bson.typings.js.map +1 -0
- package/driver/mongodb/typings.d.ts +4882 -4718
- package/driver/mongodb/typings.js +19 -0
- package/driver/mongodb/typings.js.map +1 -1
- package/entity-manager/EntityManager.d.ts +6 -6
- package/entity-manager/EntityManager.js.map +1 -1
- package/entity-manager/MongoEntityManager.d.ts +46 -92
- package/entity-manager/MongoEntityManager.js +66 -133
- package/entity-manager/MongoEntityManager.js.map +1 -1
- package/entity-schema/EntitySchemaColumnOptions.d.ts +1 -1
- package/entity-schema/EntitySchemaColumnOptions.js.map +1 -1
- package/find-options/FindOptionsOrder.d.ts +2 -2
- package/find-options/FindOptionsOrder.js.map +1 -1
- package/find-options/FindOptionsRelations.d.ts +2 -2
- package/find-options/FindOptionsRelations.js.map +1 -1
- package/find-options/FindOptionsSelect.d.ts +2 -2
- package/find-options/FindOptionsSelect.js.map +1 -1
- package/find-options/FindOptionsWhere.d.ts +2 -2
- package/find-options/FindOptionsWhere.js.map +1 -1
- package/index.mjs +34 -0
- package/migration/MigrationExecutor.js +2 -4
- package/migration/MigrationExecutor.js.map +1 -1
- package/package.json +1 -1
- package/query-builder/transformer/DocumentToEntityTransformer.js +13 -6
- package/query-builder/transformer/DocumentToEntityTransformer.js.map +1 -1
- package/repository/BaseEntity.d.ts +4 -4
- package/repository/BaseEntity.js.map +1 -1
- package/repository/EntityId.d.ts +2 -2
- package/repository/EntityId.js.map +1 -1
- package/repository/MongoRepository.d.ts +30 -72
- package/repository/MongoRepository.js +1 -38
- package/repository/MongoRepository.js.map +1 -1
- package/repository/Repository.d.ts +6 -6
- package/repository/Repository.js.map +1 -1
- 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 {
|
|
13
|
-
import {
|
|
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
|
-
|
|
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?:
|
|
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 |
|
|
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[] |
|
|
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[] |
|
|
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):
|
|
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):
|
|
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:
|
|
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:
|
|
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:
|
|
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?:
|
|
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?:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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?:
|
|
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:
|
|
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:
|
|
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<
|
|
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?:
|
|
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?:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
290
|
-
protected filterSoftDeleted<Entity>(cursor:
|
|
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
|
*/
|
|
@@ -8,6 +8,7 @@ const PlatformTools_1 = require("../platform/PlatformTools");
|
|
|
8
8
|
const InsertResult_1 = require("../query-builder/result/InsertResult");
|
|
9
9
|
const UpdateResult_1 = require("../query-builder/result/UpdateResult");
|
|
10
10
|
const DeleteResult_1 = require("../query-builder/result/DeleteResult");
|
|
11
|
+
const typings_1 = require("../driver/mongodb/typings");
|
|
11
12
|
const ObjectUtils_1 = require("../util/ObjectUtils");
|
|
12
13
|
/**
|
|
13
14
|
* Entity manager supposed to work with any entity, automatically find its repository and call its methods,
|
|
@@ -33,17 +34,35 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
33
34
|
/**
|
|
34
35
|
* Finds entities that match given find options.
|
|
35
36
|
*/
|
|
36
|
-
async find(entityClassOrName, options) {
|
|
37
|
-
return this.executeFind(entityClassOrName, options);
|
|
38
|
-
}
|
|
39
37
|
/**
|
|
40
|
-
* Finds entities that match given conditions.
|
|
38
|
+
* Finds entities that match given find options or conditions.
|
|
41
39
|
*/
|
|
42
|
-
async
|
|
43
|
-
|
|
40
|
+
async find(entityClassOrName, optionsOrConditions) {
|
|
41
|
+
const query = this.convertFindManyOptionsOrConditionsToMongodbQuery(optionsOrConditions);
|
|
42
|
+
const cursor = this.createEntityCursor(entityClassOrName, query);
|
|
43
|
+
const deleteDateColumn = this.connection.getMetadata(entityClassOrName).deleteDateColumn;
|
|
44
|
+
if (FindOptionsUtils_1.FindOptionsUtils.isFindManyOptions(optionsOrConditions)) {
|
|
45
|
+
if (optionsOrConditions.select)
|
|
46
|
+
cursor.project(this.convertFindOptionsSelectToProjectCriteria(optionsOrConditions.select));
|
|
47
|
+
if (optionsOrConditions.skip)
|
|
48
|
+
cursor.skip(optionsOrConditions.skip);
|
|
49
|
+
if (optionsOrConditions.take)
|
|
50
|
+
cursor.limit(optionsOrConditions.take);
|
|
51
|
+
if (optionsOrConditions.order)
|
|
52
|
+
cursor.sort(this.convertFindOptionsOrderToOrderCriteria(optionsOrConditions.order));
|
|
53
|
+
if (deleteDateColumn && !optionsOrConditions.withDeleted) {
|
|
54
|
+
this.filterSoftDeleted(cursor, deleteDateColumn, query);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (deleteDateColumn) {
|
|
58
|
+
this.filterSoftDeleted(cursor, deleteDateColumn, query);
|
|
59
|
+
}
|
|
60
|
+
return cursor.toArray();
|
|
44
61
|
}
|
|
45
62
|
/**
|
|
46
|
-
* Finds entities that match given find options.
|
|
63
|
+
* Finds entities that match given find options or conditions.
|
|
64
|
+
* Also counts all entities that match given conditions,
|
|
65
|
+
* but ignores pagination settings (from and take options).
|
|
47
66
|
*/
|
|
48
67
|
async findAndCount(entityClassOrName, options) {
|
|
49
68
|
return this.executeFindAndCount(entityClassOrName, options);
|
|
@@ -63,13 +82,13 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
63
82
|
async findByIds(entityClassOrName, ids, optionsOrConditions) {
|
|
64
83
|
const metadata = this.connection.getMetadata(entityClassOrName);
|
|
65
84
|
const query = this.convertFindManyOptionsOrConditionsToMongodbQuery(optionsOrConditions) || {};
|
|
66
|
-
const objectIdInstance = PlatformTools_1.PlatformTools.load("mongodb").
|
|
85
|
+
const objectIdInstance = PlatformTools_1.PlatformTools.load("mongodb").ObjectId;
|
|
67
86
|
query["_id"] = {
|
|
68
87
|
$in: ids.map((id) => {
|
|
69
88
|
if (typeof id === "string") {
|
|
70
89
|
return new objectIdInstance(id);
|
|
71
90
|
}
|
|
72
|
-
if (
|
|
91
|
+
if (typeof id === "object") {
|
|
73
92
|
if (id instanceof objectIdInstance) {
|
|
74
93
|
return id;
|
|
75
94
|
}
|
|
@@ -80,8 +99,7 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
80
99
|
}
|
|
81
100
|
}),
|
|
82
101
|
};
|
|
83
|
-
const cursor =
|
|
84
|
-
const deleteDateColumn = this.connection.getMetadata(entityClassOrName).deleteDateColumn;
|
|
102
|
+
const cursor = this.createEntityCursor(entityClassOrName, query);
|
|
85
103
|
if (FindOptionsUtils_1.FindOptionsUtils.isFindManyOptions(optionsOrConditions)) {
|
|
86
104
|
if (optionsOrConditions.select)
|
|
87
105
|
cursor.project(this.convertFindOptionsSelectToProjectCriteria(optionsOrConditions.select));
|
|
@@ -91,17 +109,11 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
91
109
|
cursor.limit(optionsOrConditions.take);
|
|
92
110
|
if (optionsOrConditions.order)
|
|
93
111
|
cursor.sort(this.convertFindOptionsOrderToOrderCriteria(optionsOrConditions.order));
|
|
94
|
-
if (deleteDateColumn && !optionsOrConditions.withDeleted) {
|
|
95
|
-
this.filterSoftDeleted(cursor, deleteDateColumn, query);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else if (deleteDateColumn) {
|
|
99
|
-
this.filterSoftDeleted(cursor, deleteDateColumn, query);
|
|
100
112
|
}
|
|
101
|
-
return
|
|
113
|
+
return cursor.toArray();
|
|
102
114
|
}
|
|
103
115
|
/**
|
|
104
|
-
* Finds first entity that matches given find options.
|
|
116
|
+
* Finds first entity that matches given conditions and/or find options.
|
|
105
117
|
*/
|
|
106
118
|
async findOne(entityClassOrName, options) {
|
|
107
119
|
return this.executeFindOne(entityClassOrName, options);
|
|
@@ -205,7 +217,7 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
205
217
|
/**
|
|
206
218
|
* Creates a cursor for a query that can be used to iterate over results from MongoDB.
|
|
207
219
|
*/
|
|
208
|
-
createCursor(entityClassOrName, query) {
|
|
220
|
+
createCursor(entityClassOrName, query = {}) {
|
|
209
221
|
const metadata = this.connection.getMetadata(entityClassOrName);
|
|
210
222
|
return this.mongoQueryRunner.cursor(metadata.tableName, query);
|
|
211
223
|
}
|
|
@@ -213,7 +225,7 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
213
225
|
* Creates a cursor for a query that can be used to iterate over results from MongoDB.
|
|
214
226
|
* This returns modified version of cursor that transforms each result into Entity model.
|
|
215
227
|
*/
|
|
216
|
-
createEntityCursor(entityClassOrName, query) {
|
|
228
|
+
createEntityCursor(entityClassOrName, query = {}) {
|
|
217
229
|
const metadata = this.connection.getMetadata(entityClassOrName);
|
|
218
230
|
const cursor = this.createCursor(entityClassOrName, query);
|
|
219
231
|
this.applyEntityTransformationToCursor(metadata, cursor);
|
|
@@ -246,7 +258,7 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
246
258
|
/**
|
|
247
259
|
* Count number of matching documents in the db to a query.
|
|
248
260
|
*/
|
|
249
|
-
count(entityClassOrName, query, options) {
|
|
261
|
+
count(entityClassOrName, query = {}, options = {}) {
|
|
250
262
|
const metadata = this.connection.getMetadata(entityClassOrName);
|
|
251
263
|
return this.mongoQueryRunner.count(metadata.tableName, query, options);
|
|
252
264
|
}
|
|
@@ -275,14 +287,14 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
275
287
|
/**
|
|
276
288
|
* Delete multiple documents on MongoDB.
|
|
277
289
|
*/
|
|
278
|
-
deleteMany(entityClassOrName, query, options) {
|
|
290
|
+
deleteMany(entityClassOrName, query, options = {}) {
|
|
279
291
|
const metadata = this.connection.getMetadata(entityClassOrName);
|
|
280
292
|
return this.mongoQueryRunner.deleteMany(metadata.tableName, query, options);
|
|
281
293
|
}
|
|
282
294
|
/**
|
|
283
295
|
* Delete a document on MongoDB.
|
|
284
296
|
*/
|
|
285
|
-
deleteOne(entityClassOrName, query, options) {
|
|
297
|
+
deleteOne(entityClassOrName, query, options = {}) {
|
|
286
298
|
const metadata = this.connection.getMetadata(entityClassOrName);
|
|
287
299
|
return this.mongoQueryRunner.deleteOne(metadata.tableName, query, options);
|
|
288
300
|
}
|
|
@@ -328,27 +340,6 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
328
340
|
const metadata = this.connection.getMetadata(entityClassOrName);
|
|
329
341
|
return this.mongoQueryRunner.findOneAndUpdate(metadata.tableName, query, update, options);
|
|
330
342
|
}
|
|
331
|
-
/**
|
|
332
|
-
* Execute a geo search using a geo haystack index on a collection.
|
|
333
|
-
*/
|
|
334
|
-
geoHaystackSearch(entityClassOrName, x, y, options) {
|
|
335
|
-
const metadata = this.connection.getMetadata(entityClassOrName);
|
|
336
|
-
return this.mongoQueryRunner.geoHaystackSearch(metadata.tableName, x, y, options);
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* Execute the geoNear command to search for items in the collection.
|
|
340
|
-
*/
|
|
341
|
-
geoNear(entityClassOrName, x, y, options) {
|
|
342
|
-
const metadata = this.connection.getMetadata(entityClassOrName);
|
|
343
|
-
return this.mongoQueryRunner.geoNear(metadata.tableName, x, y, options);
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Run a group command across a collection.
|
|
347
|
-
*/
|
|
348
|
-
group(entityClassOrName, keys, condition, initial, reduce, finalize, command, options) {
|
|
349
|
-
const metadata = this.connection.getMetadata(entityClassOrName);
|
|
350
|
-
return this.mongoQueryRunner.group(metadata.tableName, keys, condition, initial, reduce, finalize, command, options);
|
|
351
|
-
}
|
|
352
343
|
/**
|
|
353
344
|
* Retrieve all the indexes on the collection.
|
|
354
345
|
*/
|
|
@@ -412,28 +403,6 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
412
403
|
const metadata = this.connection.getMetadata(entityClassOrName);
|
|
413
404
|
return this.mongoQueryRunner.listCollectionIndexes(metadata.tableName, options);
|
|
414
405
|
}
|
|
415
|
-
/**
|
|
416
|
-
* Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.
|
|
417
|
-
*/
|
|
418
|
-
mapReduce(entityClassOrName, map, reduce, options) {
|
|
419
|
-
const metadata = this.connection.getMetadata(entityClassOrName);
|
|
420
|
-
return this.mongoQueryRunner.mapReduce(metadata.tableName, map, reduce, options);
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Return N number of parallel cursors for a collection allowing parallel reading of entire collection.
|
|
424
|
-
* There are no ordering guarantees for returned results.
|
|
425
|
-
*/
|
|
426
|
-
parallelCollectionScan(entityClassOrName, options) {
|
|
427
|
-
const metadata = this.connection.getMetadata(entityClassOrName);
|
|
428
|
-
return this.mongoQueryRunner.parallelCollectionScan(metadata.tableName, options);
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* 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.
|
|
432
|
-
*/
|
|
433
|
-
reIndex(entityClassOrName) {
|
|
434
|
-
const metadata = this.connection.getMetadata(entityClassOrName);
|
|
435
|
-
return this.mongoQueryRunner.reIndex(metadata.tableName);
|
|
436
|
-
}
|
|
437
406
|
/**
|
|
438
407
|
* 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.
|
|
439
408
|
*/
|
|
@@ -541,7 +510,7 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
541
510
|
* Ensures given id is an id for query.
|
|
542
511
|
*/
|
|
543
512
|
convertMixedCriteria(metadata, idMap) {
|
|
544
|
-
const objectIdInstance = PlatformTools_1.PlatformTools.load("mongodb").
|
|
513
|
+
const objectIdInstance = PlatformTools_1.PlatformTools.load("mongodb").ObjectId;
|
|
545
514
|
// check first if it's ObjectId compatible:
|
|
546
515
|
// string, number, Buffer, ObjectId or ObjectId-like
|
|
547
516
|
if (objectIdInstance.isValid(idMap)) {
|
|
@@ -559,7 +528,7 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
559
528
|
return query;
|
|
560
529
|
}, {});
|
|
561
530
|
}
|
|
562
|
-
// last resort: try to convert it to an
|
|
531
|
+
// last resort: try to convert it to an ObjectId anyway
|
|
563
532
|
// most likely it will fail, but we want to be backwards compatible and keep the same thrown Errors.
|
|
564
533
|
// it can still pass with null/undefined
|
|
565
534
|
return {
|
|
@@ -570,68 +539,32 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
570
539
|
* Overrides cursor's toArray and next methods to convert results to entity automatically.
|
|
571
540
|
*/
|
|
572
541
|
applyEntityTransformationToCursor(metadata, cursor) {
|
|
573
|
-
// mongdb-3.7 exports Cursor, mongodb-4.2 exports FindCursor, provide support for both.
|
|
574
|
-
const ParentCursor = PlatformTools_1.PlatformTools.load("mongodb").Cursor ||
|
|
575
|
-
PlatformTools_1.PlatformTools.load("mongodb").FindCursor;
|
|
576
542
|
const queryRunner = this.mongoQueryRunner;
|
|
577
|
-
cursor.toArray =
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
return ParentCursor.prototype.toArray
|
|
594
|
-
.call(this)
|
|
595
|
-
.then((results) => {
|
|
596
|
-
const transformer = new DocumentToEntityTransformer_1.DocumentToEntityTransformer();
|
|
597
|
-
const entities = transformer.transformAll(results, metadata);
|
|
598
|
-
// broadcast "load" events
|
|
599
|
-
return queryRunner.broadcaster
|
|
600
|
-
.broadcast("Load", metadata, entities)
|
|
601
|
-
.then(() => entities);
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
cursor.next = function (callback) {
|
|
606
|
-
if (callback) {
|
|
607
|
-
ParentCursor.prototype.next.call(this, (error, result) => {
|
|
608
|
-
if (error || !result) {
|
|
609
|
-
callback(error, result);
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
const transformer = new DocumentToEntityTransformer_1.DocumentToEntityTransformer();
|
|
613
|
-
const entity = transformer.transform(result, metadata);
|
|
614
|
-
// broadcast "load" events
|
|
615
|
-
queryRunner.broadcaster
|
|
616
|
-
.broadcast("Load", metadata, [entity])
|
|
617
|
-
.then(() => callback(error, entity));
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
else {
|
|
621
|
-
return ParentCursor.prototype.next
|
|
622
|
-
.call(this)
|
|
623
|
-
.then((result) => {
|
|
624
|
-
if (!result)
|
|
625
|
-
return result;
|
|
626
|
-
const transformer = new DocumentToEntityTransformer_1.DocumentToEntityTransformer();
|
|
627
|
-
const entity = transformer.transform(result, metadata);
|
|
628
|
-
// broadcast "load" events
|
|
629
|
-
return queryRunner.broadcaster
|
|
630
|
-
.broadcast("Load", metadata, [entity])
|
|
631
|
-
.then(() => entity);
|
|
632
|
-
});
|
|
543
|
+
cursor.toArray = () => cursor
|
|
544
|
+
.clone()
|
|
545
|
+
.toArray()
|
|
546
|
+
.then(async (results) => {
|
|
547
|
+
const transformer = new DocumentToEntityTransformer_1.DocumentToEntityTransformer();
|
|
548
|
+
const entities = transformer.transformAll(results, metadata);
|
|
549
|
+
// broadcast "load" events
|
|
550
|
+
await queryRunner.broadcaster.broadcast("Load", metadata, entities);
|
|
551
|
+
return entities;
|
|
552
|
+
});
|
|
553
|
+
cursor.next = () => cursor
|
|
554
|
+
.clone()
|
|
555
|
+
.next()
|
|
556
|
+
.then(async (result) => {
|
|
557
|
+
if (!result) {
|
|
558
|
+
return result;
|
|
633
559
|
}
|
|
634
|
-
|
|
560
|
+
const transformer = new DocumentToEntityTransformer_1.DocumentToEntityTransformer();
|
|
561
|
+
const entity = transformer.transform(result, metadata);
|
|
562
|
+
// broadcast "load" events
|
|
563
|
+
await queryRunner.broadcaster.broadcast("Load", metadata, [
|
|
564
|
+
entity,
|
|
565
|
+
]);
|
|
566
|
+
return entity;
|
|
567
|
+
});
|
|
635
568
|
}
|
|
636
569
|
filterSoftDeleted(cursor, deleteDateColumn, query) {
|
|
637
570
|
const { $or, ...restQuery } = query !== null && query !== void 0 ? query : {};
|
|
@@ -647,7 +580,7 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
647
580
|
* Finds first entity that matches given conditions and/or find options.
|
|
648
581
|
*/
|
|
649
582
|
async executeFindOne(entityClassOrName, optionsOrConditions, maybeOptions) {
|
|
650
|
-
const objectIdInstance = PlatformTools_1.PlatformTools.load("mongodb").
|
|
583
|
+
const objectIdInstance = PlatformTools_1.PlatformTools.load("mongodb").ObjectId;
|
|
651
584
|
const id = optionsOrConditions instanceof objectIdInstance ||
|
|
652
585
|
typeof optionsOrConditions === "string"
|
|
653
586
|
? optionsOrConditions
|
|
@@ -656,9 +589,9 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
656
589
|
const query = this.convertFindOneOptionsOrConditionsToMongodbQuery(findOneOptionsOrConditions) || {};
|
|
657
590
|
if (id) {
|
|
658
591
|
query["_id"] =
|
|
659
|
-
id instanceof objectIdInstance ? id : new
|
|
592
|
+
id instanceof objectIdInstance ? id : new typings_1.ObjectId(id);
|
|
660
593
|
}
|
|
661
|
-
const cursor =
|
|
594
|
+
const cursor = this.createEntityCursor(entityClassOrName, query);
|
|
662
595
|
const deleteDateColumn = this.connection.getMetadata(entityClassOrName).deleteDateColumn;
|
|
663
596
|
if (FindOptionsUtils_1.FindOptionsUtils.isFindOneOptions(findOneOptionsOrConditions)) {
|
|
664
597
|
if (findOneOptionsOrConditions.select)
|
|
@@ -678,7 +611,7 @@ class MongoEntityManager extends EntityManager_1.EntityManager {
|
|
|
678
611
|
}
|
|
679
612
|
async executeFind(entityClassOrName, optionsOrConditions) {
|
|
680
613
|
const query = this.convertFindManyOptionsOrConditionsToMongodbQuery(optionsOrConditions);
|
|
681
|
-
const cursor =
|
|
614
|
+
const cursor = this.createEntityCursor(entityClassOrName, query);
|
|
682
615
|
const deleteDateColumn = this.connection.getMetadata(entityClassOrName).deleteDateColumn;
|
|
683
616
|
if (FindOptionsUtils_1.FindOptionsUtils.isFindManyOptions(optionsOrConditions)) {
|
|
684
617
|
if (optionsOrConditions.select)
|