@fastify/mongodb
Advanced tools
Comparing version 9.0.1 to 9.0.2
{ | ||
"name": "@fastify/mongodb", | ||
"version": "9.0.1", | ||
"version": "9.0.2", | ||
"description": "Fastify MongoDB connection plugin", | ||
@@ -10,8 +10,8 @@ "main": "index.js", | ||
"coverage": "npm run unit -- --cov --coverage-report=html", | ||
"lint": "standard", | ||
"lint:fix": "standard --fix", | ||
"lint": "eslint", | ||
"lint:fix": "eslint --fix", | ||
"mongo": "docker run --rm -d -p 27017:27017 mongo:5.0.0", | ||
"test": "npm run test:unit && npm run test:typescript", | ||
"test:typescript": "tsd", | ||
"test:unit": "tap" | ||
"test:unit": "c8 --100 node --test" | ||
}, | ||
@@ -30,2 +30,22 @@ "repository": { | ||
"author": "Tomas Della Vedova - @delvedor (https://delvedor.dev)", | ||
"contributors": [ | ||
{ | ||
"name": "Matteo Collina", | ||
"email": "hello@matteocollina.com" | ||
}, | ||
{ | ||
"name": "Manuel Spigolon", | ||
"email": "behemoth89@gmail.com" | ||
}, | ||
{ | ||
"name": "KaKa Ng", | ||
"email": "kaka@kakang.dev", | ||
"url": "https://github.com/climba03003" | ||
}, | ||
{ | ||
"name": "Frazer Smith", | ||
"email": "frazer.dev@icloud.com", | ||
"url": "https://github.com/fdawgs" | ||
} | ||
], | ||
"license": "MIT", | ||
@@ -36,8 +56,19 @@ "bugs": { | ||
"homepage": "https://github.com/fastify/fastify-mongodb#readme", | ||
"funding": [ | ||
{ | ||
"type": "github", | ||
"url": "https://github.com/sponsors/fastify" | ||
}, | ||
{ | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/fastify" | ||
} | ||
], | ||
"devDependencies": { | ||
"@fastify/pre-commit": "^2.1.0", | ||
"@types/node": "^22.0.0", | ||
"c8": "^10.1.2", | ||
"eslint": "^9.17.0", | ||
"fastify": "^5.0.0", | ||
"standard": "^17.1.0", | ||
"tap": "^18.7.1", | ||
"neostandard": "^0.12.0", | ||
"tsd": "^0.31.0" | ||
@@ -44,0 +75,0 @@ }, |
# @fastify/mongodb | ||
![CI](https://github.com/fastify/fastify-mongodb/workflows/CI/badge.svg) | ||
[![CI](https://github.com/fastify/fastify-mongodb/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-mongodb/actions/workflows/ci.yml) | ||
[![NPM version](https://img.shields.io/npm/v/@fastify/mongodb.svg?style=flat)](https://www.npmjs.com/package/@fastify/mongodb) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) | ||
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard) | ||
@@ -22,3 +22,3 @@ Fastify MongoDB connection plugin; with this you can share the same MongoDB connection pool in every part of your server. | ||
## Usage | ||
Add it to your project with `register` and you are done! | ||
Add it to your project with `register` and you are done! | ||
@@ -32,3 +32,3 @@ ```js | ||
forceClose: true, | ||
url: 'mongodb://mongo/mydb' | ||
@@ -78,7 +78,7 @@ }) | ||
Notes: | ||
Notes: | ||
* the passed `client` connection will **not** be closed when the Fastify server | ||
shuts down. | ||
* in order to terminate the MongoDB connection you have to manually call the [fastify.close](https://fastify.dev/docs/latest/Reference/Server/#close) method (for example for testing purposes, otherwise the test will hang). | ||
* `mongodb` connection timeout is reduce from 30s (default) to 7.5s in order throw error before `fastify` plugin timeout. | ||
* to terminate the MongoDB connection you have to manually call the [fastify.close](https://fastify.dev/docs/latest/Reference/Server/#close) method (for example for testing purposes, otherwise the test will hang). | ||
* `mongodb` connection timeout is reduced from 30s (default) to 7.5s to throw an error before `fastify` plugin timeout. | ||
@@ -106,3 +106,3 @@ ## Reference | ||
A `name` option can be used in order to connect to multiple MongoDB clusters. | ||
A `name` option can be used to connect to multiple MongoDB clusters. | ||
@@ -130,3 +130,3 @@ ```js | ||
## Acknowledgements | ||
## Acknowledgments | ||
@@ -133,0 +133,0 @@ This project is kindly sponsored by: |
'use strict' | ||
const t = require('tap') | ||
const { test } = t | ||
const { test } = require('node:test') | ||
const Fastify = require('fastify') | ||
@@ -10,3 +9,2 @@ const fastifyMongo = require('..') | ||
const mongodb = require('mongodb') | ||
const assert = require('node:assert') | ||
@@ -25,13 +23,13 @@ const NO_DATABASE_MONGODB_URL = 'mongodb://127.0.0.1' | ||
const obj1 = new ObjectId() | ||
t.ok(obj1) | ||
t.assert.ok(obj1) | ||
const obj2 = new ObjectId(obj1) | ||
t.ok(obj2) | ||
t.ok(obj1.equals(obj2)) | ||
t.assert.ok(obj2) | ||
t.assert.ok(obj1.equals(obj2)) | ||
const obj3 = new ObjectId() | ||
t.ok(!obj1.equals(obj3)) | ||
t.assert.ok(!obj1.equals(obj3)) | ||
} | ||
function clientTest (t, client, message) { | ||
async function clientTest (t, client, message) { | ||
t.plan(1) | ||
@@ -43,9 +41,7 @@ message = message || 'expect client' | ||
t.resolves(async () => { | ||
const r = await col.insertMany([{ a: 1 }]) | ||
assert.strictEqual(1, r.insertedCount) | ||
}, message) | ||
const r = await col.insertMany([{ a: 1 }]) | ||
t.assert.strictEqual(1, r.insertedCount) | ||
} | ||
function databaseTest (t, db, message) { | ||
async function databaseTest (t, db, message) { | ||
t.plan(1) | ||
@@ -56,6 +52,4 @@ message = message || 'expect database' | ||
t.resolves(async () => { | ||
const r = await col.insertMany([{ a: 1 }]) | ||
assert.deepEqual(1, r.insertedCount) | ||
}, message) | ||
const r = await col.insertMany([{ a: 1 }]) | ||
t.assert.strictEqual(1, r.insertedCount) | ||
} | ||
@@ -65,3 +59,3 @@ | ||
t.plan(1) | ||
t.test(async t => objectIdTest(t, fastifyMongo.ObjectId)) | ||
await t.test(async t => objectIdTest(t, fastifyMongo.ObjectId)) | ||
}) | ||
@@ -71,3 +65,3 @@ | ||
t.plan(1) | ||
t.test(async t => objectIdTest(t, ObjectId)) | ||
await t.test(async t => objectIdTest(t, ObjectId)) | ||
}) | ||
@@ -77,4 +71,4 @@ | ||
t.plan(2) | ||
t.same(typeof fastifyMongo.mongodb.ObjectId, 'function') | ||
t.same(fastifyMongo.mongodb.BSONType.array, 4) | ||
t.assert.strictEqual(typeof fastifyMongo.mongodb.ObjectId, 'function') | ||
t.assert.strictEqual(fastifyMongo.mongodb.BSONType.array, 4) | ||
}) | ||
@@ -87,9 +81,9 @@ | ||
t.ok(fastify.mongo) | ||
t.ok(fastify.mongo.client) | ||
t.ok(fastify.mongo.ObjectId) | ||
t.notOk(fastify.mongo.db) | ||
t.assert.ok(fastify.mongo) | ||
t.assert.ok(fastify.mongo.client) | ||
t.assert.ok(fastify.mongo.ObjectId) | ||
t.assert.ifError(fastify.mongo.db) | ||
t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo.client)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo.client)) | ||
}) | ||
@@ -101,11 +95,11 @@ | ||
const fastify = await register(t, { url: MONGODB_URL }) | ||
t.ok(fastify.mongo) | ||
t.ok(fastify.mongo.client) | ||
t.ok(fastify.mongo.ObjectId) | ||
t.ok(fastify.mongo.db) | ||
t.equal(fastify.mongo.db.databaseName, DATABASE_NAME) | ||
t.assert.ok(fastify.mongo) | ||
t.assert.ok(fastify.mongo.client) | ||
t.assert.ok(fastify.mongo.ObjectId) | ||
t.assert.ok(fastify.mongo.db) | ||
t.assert.strictEqual(fastify.mongo.db.databaseName, DATABASE_NAME) | ||
t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo.client)) | ||
t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo.client)) | ||
await t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
}) | ||
@@ -117,16 +111,16 @@ | ||
const fastify = await register(t, { url: NO_DATABASE_MONGODB_URL, name: CLIENT_NAME }) | ||
t.ok(fastify.mongo) | ||
t.ok(fastify.mongo.client) | ||
t.ok(fastify.mongo.ObjectId) | ||
t.notOk(fastify.mongo.db) | ||
t.assert.ok(fastify.mongo) | ||
t.assert.ok(fastify.mongo.client) | ||
t.assert.ok(fastify.mongo.ObjectId) | ||
t.assert.ifError(fastify.mongo.db) | ||
t.ok(fastify.mongo[CLIENT_NAME].client) | ||
t.ok(fastify.mongo[CLIENT_NAME].ObjectId) | ||
t.notOk(fastify.mongo[CLIENT_NAME].db) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].client) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].ObjectId) | ||
t.assert.ifError(fastify.mongo[CLIENT_NAME].db) | ||
t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo.client)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo.client)) | ||
t.test(async t => objectIdTest(t, fastify.mongo[CLIENT_NAME].ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo[CLIENT_NAME].client)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo[CLIENT_NAME].ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo[CLIENT_NAME].client)) | ||
}) | ||
@@ -138,20 +132,20 @@ | ||
const fastify = await register(t, { url: MONGODB_URL, name: CLIENT_NAME }) | ||
t.ok(fastify.mongo) | ||
t.ok(fastify.mongo.client) | ||
t.ok(fastify.mongo.ObjectId) | ||
t.ok(fastify.mongo.db) | ||
t.equal(fastify.mongo.db.databaseName, DATABASE_NAME) | ||
t.assert.ok(fastify.mongo) | ||
t.assert.ok(fastify.mongo.client) | ||
t.assert.ok(fastify.mongo.ObjectId) | ||
t.assert.ok(fastify.mongo.db) | ||
t.assert.strictEqual(fastify.mongo.db.databaseName, DATABASE_NAME) | ||
t.ok(fastify.mongo[CLIENT_NAME].client) | ||
t.ok(fastify.mongo[CLIENT_NAME].ObjectId) | ||
t.ok(fastify.mongo[CLIENT_NAME].db) | ||
t.equal(fastify.mongo[CLIENT_NAME].db.databaseName, DATABASE_NAME) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].client) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].ObjectId) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].db) | ||
t.assert.strictEqual(fastify.mongo[CLIENT_NAME].db.databaseName, DATABASE_NAME) | ||
t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo.client)) | ||
t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo.client)) | ||
await t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
t.test(async t => objectIdTest(t, fastify.mongo[CLIENT_NAME].ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo[CLIENT_NAME].client)) | ||
t.test(async t => databaseTest(t, fastify.mongo[CLIENT_NAME].db)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo[CLIENT_NAME].ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo[CLIENT_NAME].client)) | ||
await t.test(async t => databaseTest(t, fastify.mongo[CLIENT_NAME].db)) | ||
}) | ||
@@ -163,20 +157,20 @@ | ||
const fastify = await register(t, { url: NO_DATABASE_MONGODB_URL, name: CLIENT_NAME, database: ANOTHER_DATABASE_NAME }) | ||
t.ok(fastify.mongo) | ||
t.ok(fastify.mongo.client) | ||
t.ok(fastify.mongo.ObjectId) | ||
t.ok(fastify.mongo.db) | ||
t.equal(fastify.mongo.db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.assert.ok(fastify.mongo) | ||
t.assert.ok(fastify.mongo.client) | ||
t.assert.ok(fastify.mongo.ObjectId) | ||
t.assert.ok(fastify.mongo.db) | ||
t.assert.strictEqual(fastify.mongo.db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.ok(fastify.mongo[CLIENT_NAME].client) | ||
t.ok(fastify.mongo[CLIENT_NAME].ObjectId) | ||
t.ok(fastify.mongo[CLIENT_NAME].db) | ||
t.equal(fastify.mongo[CLIENT_NAME].db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].client) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].ObjectId) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].db) | ||
t.assert.strictEqual(fastify.mongo[CLIENT_NAME].db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo.client)) | ||
t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo.client)) | ||
await t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
t.test(async t => objectIdTest(t, fastify.mongo[CLIENT_NAME].ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo[CLIENT_NAME].client)) | ||
t.test(async t => databaseTest(t, fastify.mongo[CLIENT_NAME].db)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo[CLIENT_NAME].ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo[CLIENT_NAME].client)) | ||
await t.test(async t => databaseTest(t, fastify.mongo[CLIENT_NAME].db)) | ||
}) | ||
@@ -188,20 +182,20 @@ | ||
const fastify = await register(t, { url: MONGODB_URL, name: CLIENT_NAME, database: ANOTHER_DATABASE_NAME }) | ||
t.ok(fastify.mongo) | ||
t.ok(fastify.mongo.client) | ||
t.ok(fastify.mongo.ObjectId) | ||
t.ok(fastify.mongo.db) | ||
t.equal(fastify.mongo.db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.assert.ok(fastify.mongo) | ||
t.assert.ok(fastify.mongo.client) | ||
t.assert.ok(fastify.mongo.ObjectId) | ||
t.assert.ok(fastify.mongo.db) | ||
t.assert.strictEqual(fastify.mongo.db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.ok(fastify.mongo[CLIENT_NAME].client) | ||
t.ok(fastify.mongo[CLIENT_NAME].ObjectId) | ||
t.ok(fastify.mongo[CLIENT_NAME].db) | ||
t.equal(fastify.mongo[CLIENT_NAME].db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].client) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].ObjectId) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].db) | ||
t.assert.strictEqual(fastify.mongo[CLIENT_NAME].db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo.client)) | ||
t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo.client)) | ||
await t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
t.test(async t => objectIdTest(t, fastify.mongo[CLIENT_NAME].ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo[CLIENT_NAME].client)) | ||
t.test(async t => databaseTest(t, fastify.mongo[CLIENT_NAME].db)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo[CLIENT_NAME].ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo[CLIENT_NAME].client)) | ||
await t.test(async t => databaseTest(t, fastify.mongo[CLIENT_NAME].db)) | ||
}) | ||
@@ -213,11 +207,11 @@ | ||
const fastify = await register(t, { url: NO_DATABASE_MONGODB_URL, database: ANOTHER_DATABASE_NAME }) | ||
t.ok(fastify.mongo) | ||
t.ok(fastify.mongo.client) | ||
t.ok(fastify.mongo.ObjectId) | ||
t.ok(fastify.mongo.db) | ||
t.equal(fastify.mongo.db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.assert.ok(fastify.mongo) | ||
t.assert.ok(fastify.mongo.client) | ||
t.assert.ok(fastify.mongo.ObjectId) | ||
t.assert.ok(fastify.mongo.db) | ||
t.assert.strictEqual(fastify.mongo.db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo.client)) | ||
t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo.client)) | ||
await t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
}) | ||
@@ -229,11 +223,11 @@ | ||
const fastify = await register(t, { url: MONGODB_URL, name: CLIENT_NAME, database: ANOTHER_DATABASE_NAME }) | ||
t.ok(fastify.mongo) | ||
t.ok(fastify.mongo.client) | ||
t.ok(fastify.mongo.ObjectId) | ||
t.ok(fastify.mongo.db) | ||
t.equal(fastify.mongo.db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.assert.ok(fastify.mongo) | ||
t.assert.ok(fastify.mongo.client) | ||
t.assert.ok(fastify.mongo.ObjectId) | ||
t.assert.ok(fastify.mongo.db) | ||
t.assert.strictEqual(fastify.mongo.db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo.client)) | ||
t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo.client)) | ||
await t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
}) | ||
@@ -245,12 +239,12 @@ | ||
const client = await mongodb.MongoClient.connect(NO_DATABASE_MONGODB_URL) | ||
t.teardown(client.close.bind(client)) | ||
t.after(() => client.close()) | ||
const fastify = await register(t, { client }) | ||
t.ok(fastify.mongo) | ||
t.ok(fastify.mongo.client) | ||
t.ok(fastify.mongo.ObjectId) | ||
t.notOk(fastify.mongo.db) | ||
t.assert.ok(fastify.mongo) | ||
t.assert.ok(fastify.mongo.client) | ||
t.assert.ok(fastify.mongo.ObjectId) | ||
t.assert.ifError(fastify.mongo.db) | ||
t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo.client)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo.client)) | ||
}) | ||
@@ -262,14 +256,14 @@ | ||
const client = await mongodb.MongoClient.connect(NO_DATABASE_MONGODB_URL) | ||
t.teardown(client.close.bind(client)) | ||
t.after(() => client.close()) | ||
const fastify = await register(t, { client, database: ANOTHER_DATABASE_NAME }) | ||
t.ok(fastify.mongo) | ||
t.ok(fastify.mongo.client) | ||
t.ok(fastify.mongo.ObjectId) | ||
t.ok(fastify.mongo.db) | ||
t.equal(fastify.mongo.db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.assert.ok(fastify.mongo) | ||
t.assert.ok(fastify.mongo.client) | ||
t.assert.ok(fastify.mongo.ObjectId) | ||
t.assert.ok(fastify.mongo.db) | ||
t.assert.strictEqual(fastify.mongo.db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo.client)) | ||
t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo.client)) | ||
await t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
}) | ||
@@ -281,19 +275,19 @@ | ||
const client = await mongodb.MongoClient.connect(NO_DATABASE_MONGODB_URL) | ||
t.teardown(client.close.bind(client)) | ||
t.after(() => client.close()) | ||
const fastify = await register(t, { client, name: CLIENT_NAME }) | ||
t.ok(fastify.mongo) | ||
t.ok(fastify.mongo.client) | ||
t.ok(fastify.mongo.ObjectId) | ||
t.notOk(fastify.mongo.db) | ||
t.assert.ok(fastify.mongo) | ||
t.assert.ok(fastify.mongo.client) | ||
t.assert.ok(fastify.mongo.ObjectId) | ||
t.assert.ifError(fastify.mongo.db) | ||
t.ok(fastify.mongo[CLIENT_NAME].client) | ||
t.ok(fastify.mongo[CLIENT_NAME].ObjectId) | ||
t.notOk(fastify.mongo[CLIENT_NAME].db) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].client) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].ObjectId) | ||
t.assert.ifError(fastify.mongo[CLIENT_NAME].db) | ||
t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo.client)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo.client)) | ||
t.test(async t => objectIdTest(t, fastify.mongo[CLIENT_NAME].ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo[CLIENT_NAME].client)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo[CLIENT_NAME].ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo[CLIENT_NAME].client)) | ||
}) | ||
@@ -305,23 +299,23 @@ | ||
const client = await mongodb.MongoClient.connect(NO_DATABASE_MONGODB_URL) | ||
t.teardown(client.close.bind(client)) | ||
t.after(() => client.close()) | ||
const fastify = await register(t, { client, name: CLIENT_NAME, database: ANOTHER_DATABASE_NAME }) | ||
t.ok(fastify.mongo) | ||
t.ok(fastify.mongo.client) | ||
t.ok(fastify.mongo.ObjectId) | ||
t.ok(fastify.mongo.db) | ||
t.equal(fastify.mongo.db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.assert.ok(fastify.mongo) | ||
t.assert.ok(fastify.mongo.client) | ||
t.assert.ok(fastify.mongo.ObjectId) | ||
t.assert.ok(fastify.mongo.db) | ||
t.assert.strictEqual(fastify.mongo.db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.ok(fastify.mongo[CLIENT_NAME].client) | ||
t.ok(fastify.mongo[CLIENT_NAME].ObjectId) | ||
t.ok(fastify.mongo[CLIENT_NAME].db) | ||
t.equal(fastify.mongo[CLIENT_NAME].db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].client) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].ObjectId) | ||
t.assert.ok(fastify.mongo[CLIENT_NAME].db) | ||
t.assert.strictEqual(fastify.mongo[CLIENT_NAME].db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo.client)) | ||
t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo.client)) | ||
await t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
t.test(async t => objectIdTest(t, fastify.mongo[CLIENT_NAME].ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo[CLIENT_NAME].client)) | ||
t.test(async t => databaseTest(t, fastify.mongo[CLIENT_NAME].db)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo[CLIENT_NAME].ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo[CLIENT_NAME].client)) | ||
await t.test(async t => databaseTest(t, fastify.mongo[CLIENT_NAME].db)) | ||
}) | ||
@@ -331,3 +325,3 @@ | ||
const client = await mongodb.MongoClient.connect(NO_DATABASE_MONGODB_URL) | ||
t.teardown(client.close.bind(client)) | ||
t.after(() => client.close()) | ||
@@ -339,3 +333,3 @@ const fastify = Fastify() | ||
t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
await t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
}) | ||
@@ -348,4 +342,4 @@ | ||
} catch (err) { | ||
t.ok(err) | ||
t.equal(err.message, '`url` parameter is mandatory if no client is provided') | ||
t.assert.ok(err) | ||
t.assert.strictEqual(err.message, '`url` parameter is mandatory if no client is provided') | ||
} | ||
@@ -359,4 +353,4 @@ }) | ||
} catch (err) { | ||
t.ok(err) | ||
t.match(err.message, /expected connection string/) | ||
t.assert.ok(err) | ||
t.assert.match(err.message, /expected connection string/) | ||
} | ||
@@ -369,3 +363,3 @@ }) | ||
const fastify = Fastify() | ||
t.teardown(fastify.close.bind(fastify)) | ||
t.after(() => fastify.close()) | ||
@@ -378,4 +372,4 @@ try { | ||
} catch (err) { | ||
t.ok(err) | ||
t.equal(err.message, 'fastify-mongodb has already registered') | ||
t.assert.ok(err) | ||
t.assert.strictEqual(err.message, 'fastify-mongodb has already registered') | ||
} | ||
@@ -388,3 +382,3 @@ }) | ||
const fastify = Fastify() | ||
t.teardown(fastify.close.bind(fastify)) | ||
t.after(() => fastify.close()) | ||
@@ -396,30 +390,30 @@ await fastify | ||
t.ok(fastify.mongo) | ||
t.assert.ok(fastify.mongo) | ||
t.ok(fastify.mongo.client) | ||
t.ok(fastify.mongo.ObjectId) | ||
t.ok(fastify.mongo.db) | ||
t.equal(fastify.mongo.db.databaseName, DATABASE_NAME) | ||
t.assert.ok(fastify.mongo.client) | ||
t.assert.ok(fastify.mongo.ObjectId) | ||
t.assert.ok(fastify.mongo.db) | ||
t.assert.strictEqual(fastify.mongo.db.databaseName, DATABASE_NAME) | ||
t.ok(fastify.mongo.client1.client) | ||
t.ok(fastify.mongo.client1.ObjectId) | ||
t.ok(fastify.mongo.client1.db) | ||
t.equal(fastify.mongo.client1.db.databaseName, DATABASE_NAME) | ||
t.assert.ok(fastify.mongo.client1.client) | ||
t.assert.ok(fastify.mongo.client1.ObjectId) | ||
t.assert.ok(fastify.mongo.client1.db) | ||
t.assert.strictEqual(fastify.mongo.client1.db.databaseName, DATABASE_NAME) | ||
t.ok(fastify.mongo.client2.client) | ||
t.ok(fastify.mongo.client2.ObjectId) | ||
t.ok(fastify.mongo.client2.db) | ||
t.equal(fastify.mongo.client2.db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.assert.ok(fastify.mongo.client2.client) | ||
t.assert.ok(fastify.mongo.client2.ObjectId) | ||
t.assert.ok(fastify.mongo.client2.db) | ||
t.assert.strictEqual(fastify.mongo.client2.db.databaseName, ANOTHER_DATABASE_NAME) | ||
t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo.client)) | ||
t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo.ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo.client)) | ||
await t.test(async t => databaseTest(t, fastify.mongo.db)) | ||
t.test(async t => objectIdTest(t, fastify.mongo.client1.ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo.client1.client)) | ||
t.test(async t => databaseTest(t, fastify.mongo.client1.db)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo.client1.ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo.client1.client)) | ||
await t.test(async t => databaseTest(t, fastify.mongo.client1.db)) | ||
t.test(async t => objectIdTest(t, fastify.mongo.client2.ObjectId)) | ||
t.test(async t => clientTest(t, fastify.mongo.client2.client)) | ||
t.test(async t => databaseTest(t, fastify.mongo.client2.db)) | ||
await t.test(async t => objectIdTest(t, fastify.mongo.client2.ObjectId)) | ||
await t.test(async t => clientTest(t, fastify.mongo.client2.client)) | ||
await t.test(async t => databaseTest(t, fastify.mongo.client2.db)) | ||
}) | ||
@@ -431,3 +425,3 @@ | ||
const fastify = Fastify() | ||
t.teardown(fastify.close.bind(fastify)) | ||
t.after(() => fastify.close()) | ||
@@ -440,4 +434,4 @@ try { | ||
} catch (err) { | ||
t.ok(err) | ||
t.equal(err.message, 'Connection name already registered: ' + CLIENT_NAME) | ||
t.assert.ok(err) | ||
t.assert.strictEqual(err.message, 'Connection name already registered: ' + CLIENT_NAME) | ||
} | ||
@@ -451,3 +445,3 @@ }) | ||
await register(t, given) | ||
t.same(given, { | ||
t.assert.deepStrictEqual(given, { | ||
url: MONGODB_URL, | ||
@@ -463,3 +457,3 @@ name: CLIENT_NAME, | ||
const fastify = Fastify() | ||
t.teardown(fastify.close.bind(fastify)) | ||
t.after(() => fastify.close()) | ||
@@ -471,4 +465,4 @@ try { | ||
} catch (err) { | ||
t.ok(err) | ||
t.equal(err.message, 'connect ECONNREFUSED 127.0.0.1:9999') | ||
t.assert.ok(err) | ||
t.assert.strictEqual(err.message, 'connect ECONNREFUSED 127.0.0.1:9999') | ||
} | ||
@@ -479,3 +473,3 @@ }) | ||
const fastify = Fastify() | ||
t.teardown(fastify.close.bind(fastify)) | ||
t.after(() => fastify.close()) | ||
@@ -482,0 +476,0 @@ fastify.register(fastifyMongo, options) |
@@ -1,5 +0,4 @@ | ||
import type { FastifyPluginAsync } from 'fastify'; | ||
import type { Db, MongoClient, MongoClientOptions } from 'mongodb'; | ||
import mongodb from 'mongodb'; | ||
import { ObjectId } from 'mongodb'; | ||
import type { FastifyPluginAsync } from 'fastify' | ||
import type { Db, MongoClient, MongoClientOptions } from 'mongodb' | ||
import mongodb, { ObjectId } from 'mongodb' | ||
@@ -12,3 +11,3 @@ declare module 'fastify' { | ||
type FastifyMongodb = FastifyPluginAsync<fastifyMongodb.FastifyMongodbOptions>; | ||
type FastifyMongodb = FastifyPluginAsync<fastifyMongodb.FastifyMongodbOptions> | ||
@@ -63,3 +62,3 @@ declare namespace fastifyMongodb { | ||
declare function fastifyMongodb(...params: Parameters<FastifyMongodb>): ReturnType<FastifyMongodb> | ||
declare function fastifyMongodb (...params: Parameters<FastifyMongodb>): ReturnType<FastifyMongodb> | ||
export = fastifyMongodb |
@@ -1,7 +0,7 @@ | ||
import { ObjectId } from 'bson'; | ||
import fastify from 'fastify'; | ||
import { expectType } from "tsd"; | ||
import fastifyMongodb, { mongodb, ObjectId as reExportedObjectId } from '..'; | ||
import { ObjectId } from 'bson' | ||
import fastify from 'fastify' | ||
import { expectNotType, expectType } from 'tsd' | ||
import fastifyMongodb, { mongodb, ObjectId as ReExportedObjectId } from '..' | ||
const app = fastify(); | ||
const app = fastify() | ||
@@ -14,11 +14,11 @@ app | ||
}) | ||
.after((err) => { | ||
app.mongo.client.db('test'); | ||
app.mongo.db!; | ||
const ObjectId = app.mongo.ObjectId; | ||
expectType<ObjectId>(new reExportedObjectId('aaaa')) | ||
.after((_err) => { | ||
app.mongo.client.db('test') | ||
expectNotType<undefined>(app.mongo.db) | ||
const ObjectId = app.mongo.ObjectId | ||
expectType<ObjectId>(new ReExportedObjectId('aaaa')) | ||
expectType<ObjectId>(new ObjectId('aaa')) | ||
}); | ||
}) | ||
expectType<typeof reExportedObjectId>(mongodb.ObjectId) | ||
expectType<typeof ReExportedObjectId>(mongodb.ObjectId) | ||
expectType<4>(mongodb.BSONType.array) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28324
7
499