Skip to content

Commit e9e8bf5

Browse files
chore: add lint rule to prevent import from bson in driver src (#4285)
1 parent a7d1d43 commit e9e8bf5

File tree

16 files changed

+30
-24
lines changed

16 files changed

+30
-24
lines changed

.eslintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@
266266
"patterns": [
267267
"**/../lib/**",
268268
"mongodb-mock-server"
269+
],
270+
"paths": [
271+
{
272+
"name": "bson",
273+
"message": "Import from the driver's bson.ts file instead."
274+
}
269275
]
270276
}
271277
]

src/beta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Document } from 'bson';
1+
import { type Document } from './bson';
22

33
export * from './index';
44

src/bson.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-restricted-imports */
12
import { BSON, type DeserializeOptions, type SerializeOptions } from 'bson';
23

34
export {
@@ -12,6 +13,7 @@ export {
1213
DBRef,
1314
Decimal128,
1415
deserialize,
16+
type DeserializeOptions,
1517
Document,
1618
Double,
1719
EJSON,
@@ -21,6 +23,7 @@ export {
2123
MaxKey,
2224
MinKey,
2325
ObjectId,
26+
type ObjectIdLike,
2427
serialize,
2528
Timestamp,
2629
UUID

src/cmap/auth/mongodb_oidc.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { Document } from 'bson';
2-
1+
import type { Document } from '../../bson';
32
import { MongoInvalidArgumentError, MongoMissingCredentialsError } from '../../error';
43
import type { HandshakeDocument } from '../connect';
54
import type { Connection } from '../connection';

src/cmap/auth/mongodb_oidc/callback_workflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { type Document } from 'bson';
21
import { setTimeout } from 'timers/promises';
32

3+
import { type Document } from '../../../bson';
44
import { MongoMissingCredentialsError } from '../../../error';
55
import { ns } from '../../../utils';
66
import type { Connection } from '../../connection';

src/cmap/auth/mongodb_oidc/command_builders.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Binary, BSON, type Document } from 'bson';
2-
1+
import { Binary, BSON, type Document } from '../../../bson';
32
import { type MongoCredentials } from '../mongo_credentials';
43
import { AuthMechanism } from '../providers';
54

src/cmap/auth/mongodb_oidc/human_callback_workflow.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { BSON } from 'bson';
2-
1+
import { BSON } from '../../../bson';
32
import { MONGODB_ERROR_CODES, MongoError, MongoOIDCError } from '../../../error';
43
import { Timeout, TimeoutError } from '../../../timeout';
54
import { type Connection } from '../../connection';

src/cmap/auth/mongodb_oidc/machine_workflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { type Document } from 'bson';
21
import { setTimeout } from 'timers/promises';
32

3+
import { type Document } from '../../../bson';
44
import { ns } from '../../../utils';
55
import type { Connection } from '../../connection';
66
import type { MongoCredentials } from '../mongo_credentials';

src/cmap/connection.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import { type DeserializeOptions } from 'bson';
21
import { type Readable, Transform, type TransformCallback } from 'stream';
32
import { clearTimeout, setTimeout } from 'timers';
43

5-
import { type BSONSerializeOptions, deserialize, type Document, type ObjectId } from '../bson';
4+
import {
5+
type BSONSerializeOptions,
6+
deserialize,
7+
type DeserializeOptions,
8+
type Document,
9+
type ObjectId
10+
} from '../bson';
611
import { type AutoEncrypter } from '../client-side-encryption/auto_encrypter';
712
import {
813
CLOSE,

src/cmap/wire_protocol/on_demand/document.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { type DeserializeOptions } from 'bson';
2-
31
import {
42
Binary,
53
type BSONElement,
64
BSONError,
75
BSONType,
86
deserialize,
7+
type DeserializeOptions,
98
getBigInt64LE,
109
getFloat64LE,
1110
getInt32LE,

src/cmap/wire_protocol/responses.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { type DeserializeOptions } from 'bson';
2-
31
import {
42
type BSONElement,
53
type BSONSerializeOptions,
64
BSONType,
5+
type DeserializeOptions,
76
type Document,
87
Long,
98
parseToElementsToArray,

src/cursor/client_bulk_write_cursor.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { type Document } from 'bson';
2-
1+
import { type Document } from '../bson';
32
import { type ClientBulkWriteCursorResponse } from '../cmap/wire_protocol/responses';
43
import type { MongoClient } from '../mongo_client';
54
import { ClientBulkWriteOperation } from '../operations/client_bulk_write/client_bulk_write';

src/mongo_types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import type { BSONType, ObjectIdLike } from 'bson';
21
import { EventEmitter } from 'events';
32

43
import type {
54
Binary,
65
BSONRegExp,
6+
BSONType,
77
Decimal128,
88
Document,
99
Double,
1010
Int32,
1111
Long,
1212
ObjectId,
13+
ObjectIdLike,
1314
Timestamp
1415
} from './bson';
1516
import { type CommandStartedEvent } from './cmap/command_monitoring_events';

src/operations/search_indexes/create.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { Document } from 'bson';
2-
1+
import type { Document } from '../../bson';
32
import type { Collection } from '../../collection';
43
import type { Server } from '../../sdam/server';
54
import type { ClientSession } from '../../sessions';

src/operations/search_indexes/drop.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { Document } from 'bson';
2-
1+
import type { Document } from '../../bson';
32
import type { Collection } from '../../collection';
43
import { MONGODB_ERROR_CODES, MongoServerError } from '../../error';
54
import type { Server } from '../../sdam/server';

src/operations/search_indexes/update.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { Document } from 'bson';
2-
1+
import type { Document } from '../../bson';
32
import type { Collection } from '../../collection';
43
import type { Server } from '../../sdam/server';
54
import type { ClientSession } from '../../sessions';

0 commit comments

Comments
 (0)