Skip to content

Commit

Permalink
fix: return container and storage
Browse files Browse the repository at this point in the history
  • Loading branch information
devtin committed Feb 20, 2021
1 parent 6daf21f commit 52f8bb1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/lib/duck-storage-di.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export const getResolvers = async (directory, {
modelPath,
storageOptions
}) => {
const availableRacks = getAvailableRacks(directory)
const racksPath = path.resolve(baseDir, directory)
const availableRacks = getAvailableRacks(racksPath)
const removeSuffix = (nameWithSuffix) => {
const removePattern = new RegExp(`${suffix}$`)
return nameWithSuffix.replace(removePattern, '')
Expand All @@ -84,6 +85,7 @@ export const getResolvers = async (directory, {
let racks

return {
storage,
resolvers: {
[suffix] (rackName) {
const rackNameWithoutSuffix = removeSuffix(rackName)
Expand All @@ -95,7 +97,7 @@ export const getResolvers = async (directory, {
},
async registerContainer (container) {
racks = await loadRacks({
dir: path.resolve(baseDir, directory),
dir: racksPath,
racksNames: availableRacks,
methodsPath,
modelPath,
Expand All @@ -118,7 +120,7 @@ export const getResolvers = async (directory, {
* @param {String} [methodsPath=methods]
* @param {String} [suffix=Rack]
* @param {Object} [storageOptions]
* @return {Object} container
* @return {{ container, storage }} container and storage
*/
export const duckStorageDi = async (directory, {
baseDir = process.cwd(),
Expand All @@ -127,7 +129,7 @@ export const duckStorageDi = async (directory, {
methodsPath = 'methods',
storageOptions
} = {}) => {
const { resolvers, registerContainer } = await getResolvers(directory, {
const { resolvers, registerContainer, storage } = await getResolvers(directory, {
baseDir,
suffix,
modelPath,
Expand All @@ -136,5 +138,5 @@ export const duckStorageDi = async (directory, {
})
const container = pleasureDi(resolvers)
await registerContainer(container)
return container
return { container, storage }
}
4 changes: 2 additions & 2 deletions src/lib/duck-storage-di.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { duckStorageDi } from './duck-storage-di.js'
let container

test.before(async () => {
container = await duckStorageDi(path.join(__dirname, './__tests__/fixtures'), {
({ container } = await duckStorageDi(path.join(__dirname, './__tests__/fixtures'), {
storageOptions: {
plugins: [plugins.InMemory()]
}
})
}))
})

test('Loads entities from directory', async (t) => {
Expand Down

0 comments on commit 52f8bb1

Please sign in to comment.