diff --git a/src/adapters/FsAdapter/methods/findCollection.js b/src/adapters/FsAdapter/methods/findCollection.js index 8c161fc..c661dc0 100644 --- a/src/adapters/FsAdapter/methods/findCollection.js +++ b/src/adapters/FsAdapter/methods/findCollection.js @@ -1,24 +1,25 @@ const Collection = require('../../../types/Collection/Collection'); -module.exports = async function findCollection(tyrInstance, dbName, colName, opts){ - let col = undefined; - if(!dbName){ - throw new Error("Expected dbName"); - } - if(!colName){ - throw new Error("Expected colName"); - } - const path = `${tyrInstance.options.path}/${dbName}/${colName}/meta.json` - const exists = await this.queue.add('File.exists', path).getResults(); - if(!exists){ - //This is done to match MemoryAdapter way of failing a find - return col; - } - const meta = await this.queue.add('File.read',path).getResults(); - col = new Collection(Object.assign(meta,{ adapter:this, tyrInstance}, opts)); - return new Promise((resolve)=>{ - col.emitter.on('ready', ()=>{ - return resolve(col) - }) - }) -} +module.exports = async function findCollection(tyrInstance, dbName, colName, opts) { + let col; + if (!dbName) { + throw new Error('Expected dbName'); + } + if (!colName) { + throw new Error('Expected colName'); + } + const path = `${tyrInstance.options.path}/${dbName}/${colName}/meta.json`; + let job = await this.queue.add('File.exists', path).execution(); + const exists = job.result; + if (!exists) { + // This is done to match MemoryAdapter way of failing a find + return col; + } + job = await this.queue.add('File.read', path).execution(); + const meta = job.result; + col = new Collection(Object.assign(meta, { adapter: this, tyrInstance }, opts)); + + return new Promise((resolve) => { + col.emitter.on('ready', () => resolve(col)); + }); +}; diff --git a/src/adapters/FsAdapter/methods/findDatabase.js b/src/adapters/FsAdapter/methods/findDatabase.js index fb8ab8a..bc99cb8 100644 --- a/src/adapters/FsAdapter/methods/findDatabase.js +++ b/src/adapters/FsAdapter/methods/findDatabase.js @@ -1,21 +1,24 @@ const Database = require('../../../types/Database/Database'); -module.exports = async function findDatabase(tyrInstance, dbName, opts){ - let db = undefined; - if(!dbName){ - throw new Error("Expected dbName"); + +module.exports = async function findDatabase(tyrInstance, dbName, opts) { + let db; + if (!dbName) { + throw new Error('Expected dbName'); } - const job = await this.queue.add('File.exists', `${tyrInstance.options.path}/${dbName}/meta.json`); - await job.execution(); + let job = await this.queue.add('File.exists', `${tyrInstance.options.path}/${dbName}/meta.json`).execution(); - const exists = job.results - if(!exists){ - //This is done to match MemoryAdapter way of failing a find + const exists = job.results; + if (!exists) { + // This is done to match MemoryAdapter way of failing a find return db; } - const meta = await this.queue - .add('File.read',`${tyrInstance.options.path}/${dbName}/meta.json`) - .getResults(); - db = new Database(Object.assign(meta,{ adapter:this, tyrInstance})); + job = await this.queue + .add('File.read', `${tyrInstance.options.path}/${dbName}/meta.json`) + .execution(); + + const meta = job.result; + + db = new Database(Object.assign(meta, { adapter: this, tyrInstance })); return db; -} +};