Skip to content

Commit 5c17f3a

Browse files
committed
feat(mongo)!: remove exported internal types
1 parent f47246c commit 5c17f3a

40 files changed

Lines changed: 112 additions & 140 deletions

File tree

docs/docs/drivers/mongodb.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ instead of `@PrimaryColumn` or `@PrimaryGeneratedColumn`.
9797
Simple entity example:
9898

9999
```typescript
100-
import { Entity, ObjectId, ObjectIdColumn, Column } from "typeorm"
100+
import { ObjectId } from "mongodb"
101+
import { Entity, ObjectIdColumn, Column } from "typeorm"
101102

102103
@Entity()
103104
export class User {
@@ -130,7 +131,8 @@ const myDataSource = new DataSource({
130131
Since MongoDB stores objects and objects inside objects (or documents inside documents), you can do the same in TypeORM:
131132

132133
```typescript
133-
import { Entity, ObjectId, ObjectIdColumn, Column } from "typeorm"
134+
import { ObjectId } from "mongodb"
135+
import { Entity, ObjectIdColumn, Column } from "typeorm"
134136

135137
export class Profile {
136138
@Column()
@@ -145,7 +147,8 @@ export class Profile {
145147
```
146148

147149
```typescript
148-
import { Entity, ObjectId, ObjectIdColumn, Column } from "typeorm"
150+
import { ObjectId } from "mongodb"
151+
import { Entity, ObjectIdColumn, Column } from "typeorm"
149152

150153
export class Photo {
151154
@Column()

docs/docs/entity/1-entities.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ This will create following database table:
3838
```
3939

4040
Basic entities consist of columns and relations.
41-
Each entity **MUST** have a primary column (or ObjectId column if are using MongoDB).
41+
Each entity **MUST** have a primary column (or an `ObjectId` column if are using MongoDB).
4242

4343
Each entity must be registered in your data source options:
4444

docs/docs/guides/8-migration-v1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ TypeORM requires newer versions of the database client libraries.
1414

1515
The `connectorPackage` option was removed, together with the support for the old `mysql` client. The only database client supported is now `mysql2`, which TypeORM will try to load by default. If you were using `mysql` in your project, simply replace it with `mysql2`.
1616

17+
## MongoDB
18+
19+
The internal MongoDB types are no longer exported. You can import `ObjectId` from `mongodb` instead of `typeorm`.
20+
1721
## SQLite
1822

1923
Drop support to `sqlite3` in favour of `better-sqlite3` as the primary driver for `sqlite` databases:

docs/docs/help/3-decorator-reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ Learn more about [entity columns](../entity/1-entities.md#entity-columns).
246246

247247
#### `@ObjectIdColumn`
248248

249-
Marks a property in your entity as ObjectId.
249+
Marks a property in your entity as `ObjectId`.
250250
This decorator is only used in MongoDB.
251-
Every entity in MongoDB must have a ObjectId column.
251+
Every entity in MongoDB must have an `ObjectId` column.
252252
Example:
253253

254254
```typescript

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export default defineConfig([
1111
"docs/**",
1212
"node_modules/**",
1313
"sample/playground/**",
14-
"temp/**",
1514
"src/driver/mongodb/{typings.ts,bson.typings.ts}",
15+
"temp/**",
1616
]),
1717

1818
{

sample/sample34-mongodb/entity/Post.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { Column, Entity } from "../../../src/index"
2-
import { ObjectIdColumn } from "../../../src/decorator/columns/ObjectIdColumn"
3-
import { ObjectId } from "../../../src/driver/mongodb/typings"
1+
import { ObjectId } from "mongodb"
2+
import { Column, Entity, ObjectIdColumn } from "../../../src/"
43

54
@Entity("sample34_post")
65
export class Post {

src/entity-manager/MongoEntityManager.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,21 +197,21 @@ export class MongoEntityManager extends EntityManager {
197197
this.convertFindManyOptionsOrConditionsToMongodbQuery(
198198
optionsOrConditions,
199199
) || {}
200-
const objectIdInstance = PlatformTools.load("mongodb").ObjectId
200+
const objectIdClass = PlatformTools.load("mongodb").ObjectId
201201
query["_id"] = {
202202
$in: ids.map((id) => {
203203
if (typeof id === "string") {
204-
return new objectIdInstance(id)
204+
return new objectIdClass(id)
205205
}
206206

207207
if (typeof id === "object") {
208-
if (id instanceof objectIdInstance) {
208+
if (id instanceof objectIdClass) {
209209
return id
210210
}
211211

212212
const propertyName = metadata.objectIdColumn!.propertyName
213213

214-
if (id[propertyName] instanceof objectIdInstance) {
214+
if (id[propertyName] instanceof objectIdClass) {
215215
return id[propertyName]
216216
}
217217
}
@@ -1212,9 +1212,9 @@ export class MongoEntityManager extends EntityManager {
12121212
optionsOrConditions?: any,
12131213
maybeOptions?: MongoFindOneOptions<Entity>,
12141214
): Promise<Entity | null> {
1215-
const objectIdInstance = PlatformTools.load("mongodb").ObjectId
1215+
const objectIdClass = PlatformTools.load("mongodb").ObjectId
12161216
const id =
1217-
optionsOrConditions instanceof objectIdInstance ||
1217+
optionsOrConditions instanceof objectIdClass ||
12181218
typeof optionsOrConditions === "string"
12191219
? optionsOrConditions
12201220
: undefined
@@ -1227,7 +1227,7 @@ export class MongoEntityManager extends EntityManager {
12271227
) || {}
12281228
if (id) {
12291229
query["_id"] =
1230-
id instanceof objectIdInstance ? id : new objectIdInstance(id)
1230+
id instanceof objectIdClass ? id : new objectIdClass(id)
12311231
}
12321232
const cursor = this.createEntityCursor<Entity>(entityClassOrName, query)
12331233
const deleteDateColumn =

src/entity-schema/EntitySchemaColumnOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface EntitySchemaColumnOptions extends SpatialColumnOptions {
1010
primary?: boolean
1111

1212
/**
13-
* Indicates if this column is of type ObjectId
13+
* Indicates if this column is of type `ObjectId`.
1414
*/
1515
objectId?: boolean
1616

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export * from "./repository/TreeRepository"
115115
export * from "./repository/MongoRepository"
116116
export * from "./repository/RemoveOptions"
117117
export * from "./repository/SaveOptions"
118-
export { UpdateOptions as RepositoryUpdateOptions } from "./repository/UpdateOptions"
118+
export * from "./repository/UpdateOptions"
119119
export * from "./repository/UpsertOptions"
120120
export * from "./schema-builder/table/TableCheck"
121121
export * from "./schema-builder/table/TableColumn"
@@ -133,7 +133,6 @@ export * from "./schema-builder/options/TableIndexOptions"
133133
export * from "./schema-builder/options/TableOptions"
134134
export * from "./schema-builder/options/TableUniqueOptions"
135135
export * from "./schema-builder/options/ViewOptions"
136-
export * from "./driver/mongodb/typings"
137136
export * from "./driver/types/DatabaseType"
138137
export * from "./driver/types/GeoJsonTypes"
139138
export * from "./driver/types/ReplicationMode"

test/functional/mongodb/basic/array-columns/entity/Post.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { Entity } from "../../../../../../src/decorator/entity/Entity"
2-
import { Column } from "../../../../../../src/decorator/columns/Column"
3-
import { ObjectIdColumn } from "../../../../../../src/decorator/columns/ObjectIdColumn"
1+
import { ObjectId } from "mongodb"
2+
import { Column, Entity, ObjectIdColumn } from "../../../../../../src"
43
import { Counters } from "./Counters"
5-
import { ObjectId } from "../../../../../../src/driver/mongodb/typings"
64

75
@Entity()
86
export class Post {

0 commit comments

Comments
 (0)