Skip to content

Commit

Permalink
feat: simplify data-source options detection
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Jan 18, 2024
1 parent 3419805 commit 328b4f0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"dependencies": {
"@faker-js/faker": "^8.3.1",
"consola": "^3.2.3",
"locter": "^1.3.0",
"locter": "^2.0.1",
"pascal-case": "^3.1.2",
"rapiq": "^0.9.0",
"reflect-metadata": "^0.2.1",
Expand Down
41 changes: 15 additions & 26 deletions src/data-source/find/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
getModuleExport,
isObject,
load,
locate,
Expand Down Expand Up @@ -101,40 +100,30 @@ export async function findDataSource(
);

if (info) {
let fileExports = await load(info);
let moduleRecord = await load(info);

if (isPromise(fileExports)) {
fileExports = await fileExports;
if (isPromise(moduleRecord)) {
moduleRecord = await moduleRecord;
}

if (InstanceChecker.isDataSource(fileExports)) {
return fileExports;
if (InstanceChecker.isDataSource(moduleRecord)) {
return moduleRecord;
}

const defaultExport = getModuleExport(fileExports);
if (isPromise(defaultExport.value)) {
defaultExport.value = await defaultExport.value;
if (!isObject(moduleRecord)) {
continue;
}

if (
defaultExport &&
InstanceChecker.isDataSource(defaultExport.value)
) {
return defaultExport.value;
}

if (isObject(fileExports)) {
const keys = Object.keys(fileExports);
for (let j = 0; j < keys.length; j++) {
let value = fileExports[keys[j]];
const keys = Object.keys(moduleRecord);
for (let j = 0; j < keys.length; j++) {
let value = moduleRecord[keys[j]];

if (isPromise(value)) {
value = await value;
}
if (isPromise(value)) {
value = await value;
}

if (InstanceChecker.isDataSource(value)) {
return value;
}
if (InstanceChecker.isDataSource(value)) {
return value;
}
}
}
Expand Down

0 comments on commit 328b4f0

Please sign in to comment.