Skip to content

Commit

Permalink
feat: compatibility with Bun
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowplay1 committed Mar 30, 2024
1 parent a4b9b52 commit 896d0db
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ dist/

# miscellaneous
misc/

# bun lock file
bun.lockb
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

## 🕘 | Changelog

**v2.0.8**
- Updated dependencies.
- Removed unnecessary internal MongoDB configuration.
- Added compatibility with **Bun**.
- Fixed a bug when running `QuickMongo.clear()` method was nuking data in the **whole MongoDB cluster** instead of data in **specific QuickMongo collection**.
- Added a new optional `mongoClientOptions` parameter in `QuickMongoClient` constructor to allow passing specific MongoDB client options into the `mongodb` module.

**v2.0.7**
- Small bug fixes.

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quick-mongo-super",
"version": "2.0.7",
"version": "2.0.8",
"description": "Quick Mongo Super is a light-weight and easy-to-use Node.js module written in TypeScript to work with MongoDB.",
"main": "./dist/src/index.js",
"types": "./dist/typings/src/index.d.ts",
Expand All @@ -14,7 +14,7 @@
"author": "shadowplay1 <shadowplay483@gmail.com>",
"license": "MIT",
"dependencies": {
"mongoose": "5.13"
"mongoose": "^8.2.4"
},
"directories": {
"lib": "./dist",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/QuickMongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ export class QuickMongo<K extends string = string, V = any> {
}

this._cache.clear()
await this._model.deleteMany()
await this._model.collection.deleteMany()

return true
}
Expand Down
23 changes: 19 additions & 4 deletions src/lib/QuickMongoClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { connect, disconnect } from 'mongoose'
import { MongoClientOptions } from 'mongodb'

import { IQuickMongoEvents } from '../types/Database'
import { Emitter } from './utils/Emitter'

import { QuickMongo } from './QuickMongo'

/**
Expand Down Expand Up @@ -60,6 +62,12 @@ export class QuickMongoClient<
*/
public initialDatabaseData: TInitialDatabaseData

/**
* MongoDB client connection options.
* @type {MongoClientOptions}
*/
public mongoClientOptions?: MongoClientOptions

readonly [Symbol.toStringTag] = 'QuickMongoClient'

/**
Expand All @@ -73,6 +81,8 @@ export class QuickMongoClient<
* @param {TInitialDatabaseData} initialDatabaseData
* The database object to set in database if the database is empty on initialation.
*
* @param {MongoClientOptions} mongoClientOptions MongoDB client connection options.
*
* @template TInitialDatabaseData (object) - The type of the object to be set in new empty databases.
*
* @example
Expand All @@ -93,13 +103,19 @@ export class QuickMongoClient<
* collectionName: 'collectionName' // optional
* })
*/
public constructor(connectionURI: string, initialDatabaseData?: TInitialDatabaseData) {
public constructor(
connectionURI: string,
initialDatabaseData?: TInitialDatabaseData,
mongoClientOptions?: MongoClientOptions
) {
super()

this.databases = []

this.initialDatabaseData = initialDatabaseData
this._connectionURI = connectionURI
this.mongoClientOptions = mongoClientOptions

this.initialDatabaseData = initialDatabaseData
}

/**
Expand All @@ -108,8 +124,7 @@ export class QuickMongoClient<
*/
public async connect(): Promise<QuickMongoClient<TInitialDatabaseData>> {
await connect(this._connectionURI, {
useNewUrlParser: true,
useUnifiedTopology: true
...this.mongoClientOptions
})

this.connected = true
Expand Down

0 comments on commit 896d0db

Please sign in to comment.