Skip to content

Commit

Permalink
Fixed linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
devconcept committed Mar 20, 2020
1 parent 9aa09be commit 79b10a5
Show file tree
Hide file tree
Showing 27 changed files with 348 additions and 240 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage/**/*
docs/**/*
examples/**

8 changes: 4 additions & 4 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class Cache {
* @param {string} opts.cacheName - The name of the cache to use
* @param {any} opts.init - The connection options provided
**/
initialize(opts) {
let {url, cacheName: name} = opts;
initialize(options) {
let {url, cacheName: name} = options;
// If the option is a falsey value or empty object use null as initial value
const init = compare(opts.init, null) ? null : opts.init;
const init = compare(options.init, null) ? null : options.init;

// If a cache under that name does not exist create one
if (!this._connections[name]) {
Expand Down Expand Up @@ -65,7 +65,7 @@ class Cache {
for (const prop in cached) {
if (hasOwn(cached, prop)) {
const current = cached[prop];
if (compare(current.init, opts.init)) {
if (compare(current.init, options.init)) {
return {
url,
name,
Expand Down
64 changes: 32 additions & 32 deletions lib/gridfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class GridFSStorage extends EventEmitter {
* @param {object} opts - The stream options
* @return {GridStoreStream|GridFSBucketWriteStream}
*/
createStream(opts) {
createStream(options) {
let gfs;
let settings;
const {GridStore} = mongodb;
Expand All @@ -268,27 +268,27 @@ class GridFSStorage extends EventEmitter {
// `disableMD5` is not supported in GridStore
settings = {
/* eslint-disable-next-line camelcase */
chunk_size: opts.chunkSize,
metadata: opts.metadata,
chunk_size: options.chunkSize,
metadata: options.metadata,
/* eslint-disable-next-line camelcase */
content_type: opts.contentType,
root: opts.bucketName,
aliases: opts.aliases
content_type: options.contentType,
root: options.bucketName,
aliases: options.aliases
};
gfs = new GridStore(this.db, opts.id, opts.filename, 'w', settings);
gfs = new GridStore(this.db, options.id, options.filename, 'w', settings);
return gfs.stream();
}

settings = {
id: opts.id,
chunkSizeBytes: opts.chunkSize,
contentType: opts.contentType,
metadata: opts.metadata,
aliases: opts.aliases,
disableMD5: opts.disableMD5
id: options.id,
chunkSizeBytes: options.chunkSize,
contentType: options.contentType,
metadata: options.metadata,
aliases: options.aliases,
disableMD5: options.disableMD5
};
gfs = new GridFSBucket(this.db, {bucketName: opts.bucketName});
return gfs.openUploadStream(opts.filename, settings);
gfs = new GridFSBucket(this.db, {bucketName: options.bucketName});
return gfs.openUploadStream(options.filename, settings);
}

/**
Expand All @@ -297,13 +297,13 @@ class GridFSStorage extends EventEmitter {
* @param {File} file - The uploaded file stream
* @param {function} cb - A standard node callback to signal the end of the upload or an error
**/
_handleFile(req, file, cb) {
_handleFile(request, file, cb) {
if (this.connecting) {
// Triggers file storage buffering if the connection is not ready yet
// Connection listeners. Only one of them fires, the other is cleaned after the event.
const connectionListener = () => {
this.removeListener('connectionFailed', failedListener);
this._store(req, file, cb);
this._store(request, file, cb);
};

const failedListener = err => {
Expand All @@ -316,7 +316,7 @@ class GridFSStorage extends EventEmitter {
} else {
this._updateConnectionStatus();
if (this.connected) {
this._store(req, file, cb);
this._store(request, file, cb);
} else {
return cb(
new Error('The database connection must be open to store files')
Expand All @@ -331,7 +331,7 @@ class GridFSStorage extends EventEmitter {
* @param {File} file - The uploaded file stream
* @param {function} cb - A standard node callback to signal the end of the upload or an error
**/
_removeFile(req, file, cb) {
_removeFile(request, file, cb) {
let bucket;
let options;
const {GridStore} = mongodb;
Expand All @@ -354,9 +354,9 @@ class GridFSStorage extends EventEmitter {
* @param {function} cb - A callback function to transfer control back to the multer module
* @private
*/
_store(req, file, cb) {
_store(request, file, cb) {
const readStream = file.stream;
this._generate(req, file)
this._generate(request, file)
/* eslint-disable-next-line promise/prefer-await-to-then */
.then(fileSettings => {
let settings;
Expand Down Expand Up @@ -384,11 +384,11 @@ class GridFSStorage extends EventEmitter {
);
})
/* eslint-disable-next-line promise/prefer-await-to-then */
.then(streamOpts => {
.then(streamOptions => {
let store;

const emitError = streamError => {
this.emit('streamError', streamError, streamOpts);
this.emit('streamError', streamError, streamOptions);
cb(streamError);
};

Expand All @@ -397,7 +397,7 @@ class GridFSStorage extends EventEmitter {
id: f._id,
filename: f.filename,
metadata: f.metadata || null,
bucketName: streamOpts.bucketName,
bucketName: streamOptions.bucketName,
chunkSize: f.chunkSize,
size: f.length,
md5: f.md5,
Expand All @@ -408,7 +408,7 @@ class GridFSStorage extends EventEmitter {
cb(null, storedFile);
};

const writeStream = this.createStream(streamOpts);
const writeStream = this.createStream(streamOptions);

// Multer already handles the error event on the readable stream(Busboy).
// Invoking the callback with an error will cause file removal and aborting routines to be called twice
Expand Down Expand Up @@ -449,7 +449,7 @@ class GridFSStorage extends EventEmitter {
* @param {File} file - The uploaded file stream as received in _handleFile
* @return {Promise<any | {}>} A promise with the value generated by the file function
**/
async _generate(req, file) {
async _generate(request, file) {
let result;
let generator;
let isGen = false;
Expand All @@ -460,15 +460,15 @@ class GridFSStorage extends EventEmitter {

if (isGeneratorFn(this._file)) {
isGen = true;
generator = this._file(req, file);
generator = this._file(request, file);
this._file = generator;
result = generator.next();
} else if (isGenerator(this._file)) {
isGen = true;
generator = this._file;
result = generator.next([req, file]);
result = generator.next([request, file]);
} else {
result = this._file(req, file);
result = this._file(request, file);
}

return GridFSStorage._handleResult(result, isGen);
Expand Down Expand Up @@ -533,17 +533,17 @@ class GridFSStorage extends EventEmitter {
*/
static async _mergeProps(extra, fileSettings) {
// If the filename is not provided generate one
const prev = await (fileSettings.filename
const previous = await (fileSettings.filename
? {}
: GridFSStorage.generateBytes());
// If no id is provided generate one
// If an error occurs the emitted file information will contain the id
const hasId = fileSettings.id;
if (!hasId) {
prev.id = new ObjectID();
previous.id = new ObjectID();
}

return {...prev, ...defaults, ...extra, ...fileSettings};
return {...previous, ...defaults, ...extra, ...fileSettings};
}

/**
Expand Down
Loading

0 comments on commit 79b10a5

Please sign in to comment.