chore: formatting and linting (#3261)
* chore: lint packages/payload * chore: lint packages/db-postgres * chore: lint packages/db-mongodb * chore: update eslintrc exclusion rules * chore: update eslintrc exclusion rules * chore: lint misc files * chore: run prettier through packages * chore: run eslint on payload again * chore: prettier misc files * chore: prettier docs
This commit is contained in:
@@ -1,67 +1,61 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
import type { ConnectOptions } from 'mongoose';
|
||||
import mongoose from 'mongoose';
|
||||
import type { Connect } from 'payload/database';
|
||||
import type { MongooseAdapter } from '.';
|
||||
import type { ConnectOptions } from 'mongoose'
|
||||
import type { Connect } from 'payload/database'
|
||||
|
||||
export const connect: Connect = async function connect(
|
||||
this: MongooseAdapter,
|
||||
payload,
|
||||
) {
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
import type { MongooseAdapter } from '.'
|
||||
|
||||
export const connect: Connect = async function connect(this: MongooseAdapter, payload) {
|
||||
if (this.url === false) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
if (!payload.local && typeof this.url !== 'string') {
|
||||
throw new Error('Error: missing MongoDB connection URL.');
|
||||
throw new Error('Error: missing MongoDB connection URL.')
|
||||
}
|
||||
|
||||
let urlToConnect = this.url;
|
||||
let successfulConnectionMessage = 'Connected to MongoDB server successfully!';
|
||||
let urlToConnect = this.url
|
||||
let successfulConnectionMessage = 'Connected to MongoDB server successfully!'
|
||||
|
||||
const connectionOptions: ConnectOptions & { useFacet: undefined } = {
|
||||
autoIndex: true,
|
||||
...this.connectOptions,
|
||||
useFacet: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
if (process.env.PAYLOAD_TEST_MONGO_URL) {
|
||||
urlToConnect = process.env.PAYLOAD_TEST_MONGO_URL;
|
||||
urlToConnect = process.env.PAYLOAD_TEST_MONGO_URL
|
||||
} else {
|
||||
connectionOptions.dbName = 'payloadmemory';
|
||||
const { MongoMemoryServer } = require('mongodb-memory-server');
|
||||
const getPort = require('get-port');
|
||||
connectionOptions.dbName = 'payloadmemory'
|
||||
const { MongoMemoryServer } = require('mongodb-memory-server')
|
||||
const getPort = require('get-port')
|
||||
|
||||
const port = await getPort();
|
||||
const port = await getPort()
|
||||
this.mongoMemoryServer = await MongoMemoryServer.create({
|
||||
instance: {
|
||||
dbName: 'payloadmemory',
|
||||
port,
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
urlToConnect = this.mongoMemoryServer.getUri();
|
||||
successfulConnectionMessage = 'Connected to in-memory MongoDB server successfully!';
|
||||
urlToConnect = this.mongoMemoryServer.getUri()
|
||||
successfulConnectionMessage = 'Connected to in-memory MongoDB server successfully!'
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
this.connection = (
|
||||
await mongoose.connect(urlToConnect, connectionOptions)
|
||||
).connection;
|
||||
this.connection = (await mongoose.connect(urlToConnect, connectionOptions)).connection
|
||||
|
||||
if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
|
||||
this.payload.logger.info('---- DROPPING DATABASE ----');
|
||||
await mongoose.connection.dropDatabase();
|
||||
this.payload.logger.info('---- DROPPED DATABASE ----');
|
||||
this.payload.logger.info('---- DROPPING DATABASE ----')
|
||||
await mongoose.connection.dropDatabase()
|
||||
this.payload.logger.info('---- DROPPED DATABASE ----')
|
||||
}
|
||||
this.payload.logger.info(successfulConnectionMessage);
|
||||
this.payload.logger.info(successfulConnectionMessage)
|
||||
} catch (err) {
|
||||
this.payload.logger.error(
|
||||
`Error: cannot connect to MongoDB. Details: ${err.message}`,
|
||||
err,
|
||||
);
|
||||
process.exit(1);
|
||||
this.payload.logger.error(`Error: cannot connect to MongoDB. Details: ${err.message}`, err)
|
||||
process.exit(1)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user