Skip to content

chore: add lint rule to prevent import from bson in driver src #4285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@
"patterns": [
"**/../lib/**",
"mongodb-mock-server"
],
"paths": [
{
"name": "bson",
"message": "Import from the driver's bson.ts file instead."
}
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/beta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Document } from 'bson';
import { type Document } from './bson';

export * from './index';

Expand Down
3 changes: 3 additions & 0 deletions src/bson.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-restricted-imports */
import { BSON, type DeserializeOptions, type SerializeOptions } from 'bson';

export {
Expand All @@ -12,6 +13,7 @@ export {
DBRef,
Decimal128,
deserialize,
type DeserializeOptions,
Document,
Double,
EJSON,
Expand All @@ -21,6 +23,7 @@ export {
MaxKey,
MinKey,
ObjectId,
type ObjectIdLike,
serialize,
Timestamp,
UUID
Expand Down
3 changes: 1 addition & 2 deletions src/cmap/auth/mongodb_oidc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Document } from 'bson';

import type { Document } from '../../bson';
import { MongoInvalidArgumentError, MongoMissingCredentialsError } from '../../error';
import type { HandshakeDocument } from '../connect';
import type { Connection } from '../connection';
Expand Down
2 changes: 1 addition & 1 deletion src/cmap/auth/mongodb_oidc/callback_workflow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Document } from 'bson';
import { setTimeout } from 'timers/promises';

import { type Document } from '../../../bson';
import { MongoMissingCredentialsError } from '../../../error';
import { ns } from '../../../utils';
import type { Connection } from '../../connection';
Expand Down
3 changes: 1 addition & 2 deletions src/cmap/auth/mongodb_oidc/command_builders.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Binary, BSON, type Document } from 'bson';

import { Binary, BSON, type Document } from '../../../bson';
import { type MongoCredentials } from '../mongo_credentials';
import { AuthMechanism } from '../providers';

Expand Down
3 changes: 1 addition & 2 deletions src/cmap/auth/mongodb_oidc/human_callback_workflow.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BSON } from 'bson';

import { BSON } from '../../../bson';
import { MONGODB_ERROR_CODES, MongoError, MongoOIDCError } from '../../../error';
import { Timeout, TimeoutError } from '../../../timeout';
import { type Connection } from '../../connection';
Expand Down
2 changes: 1 addition & 1 deletion src/cmap/auth/mongodb_oidc/machine_workflow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Document } from 'bson';
import { setTimeout } from 'timers/promises';

import { type Document } from '../../../bson';
import { ns } from '../../../utils';
import type { Connection } from '../../connection';
import type { MongoCredentials } from '../mongo_credentials';
Expand Down
9 changes: 7 additions & 2 deletions src/cmap/connection.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { type DeserializeOptions } from 'bson';
import { type Readable, Transform, type TransformCallback } from 'stream';
import { clearTimeout, setTimeout } from 'timers';

import { type BSONSerializeOptions, deserialize, type Document, type ObjectId } from '../bson';
import {
type BSONSerializeOptions,
deserialize,
type DeserializeOptions,
type Document,
type ObjectId
} from '../bson';
import { type AutoEncrypter } from '../client-side-encryption/auto_encrypter';
import {
CLOSE,
Expand Down
3 changes: 1 addition & 2 deletions src/cmap/wire_protocol/on_demand/document.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { type DeserializeOptions } from 'bson';

import {
Binary,
type BSONElement,
BSONError,
BSONType,
deserialize,
type DeserializeOptions,
getBigInt64LE,
getFloat64LE,
getInt32LE,
Expand Down
3 changes: 1 addition & 2 deletions src/cmap/wire_protocol/responses.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { type DeserializeOptions } from 'bson';

import {
type BSONElement,
type BSONSerializeOptions,
BSONType,
type DeserializeOptions,
type Document,
Long,
parseToElementsToArray,
Expand Down
3 changes: 1 addition & 2 deletions src/cursor/client_bulk_write_cursor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { type Document } from 'bson';

import { type Document } from '../bson';
import { type ClientBulkWriteCursorResponse } from '../cmap/wire_protocol/responses';
import { MongoClientBulkWriteCursorError } from '../error';
import type { MongoClient } from '../mongo_client';
Expand Down
3 changes: 2 additions & 1 deletion src/mongo_types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { BSONType, ObjectIdLike } from 'bson';
import { EventEmitter } from 'events';

import type {
Binary,
BSONRegExp,
BSONType,
Decimal128,
Document,
Double,
Int32,
Long,
ObjectId,
ObjectIdLike,
Timestamp
} from './bson';
import { type CommandStartedEvent } from './cmap/command_monitoring_events';
Expand Down
3 changes: 1 addition & 2 deletions src/operations/search_indexes/create.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Document } from 'bson';

import type { Document } from '../../bson';
import type { Collection } from '../../collection';
import type { Server } from '../../sdam/server';
import type { ClientSession } from '../../sessions';
Expand Down
3 changes: 1 addition & 2 deletions src/operations/search_indexes/drop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Document } from 'bson';

import type { Document } from '../../bson';
import type { Collection } from '../../collection';
import { MONGODB_ERROR_CODES, MongoServerError } from '../../error';
import type { Server } from '../../sdam/server';
Expand Down
3 changes: 1 addition & 2 deletions src/operations/search_indexes/update.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Document } from 'bson';

import type { Document } from '../../bson';
import type { Collection } from '../../collection';
import type { Server } from '../../sdam/server';
import type { ClientSession } from '../../sessions';
Expand Down