From 328b4f065beb8c47096e7f1abd92b5d55e6a24dd Mon Sep 17 00:00:00 2001 From: tada5hi Date: Thu, 18 Jan 2024 11:23:40 +0100 Subject: [PATCH] feat: simplify data-source options detection --- package-lock.json | 8 +++---- package.json | 2 +- src/data-source/find/module.ts | 41 +++++++++++++--------------------- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index 52bd6724..298e8185 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,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", @@ -9617,9 +9617,9 @@ } }, "node_modules/locter": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/locter/-/locter-1.3.0.tgz", - "integrity": "sha512-HfyXUmhGZNSvWIgyjZBrFQQ1zH06Yy+4ucKV1ujwMxfGxscwzwi2p6r+FXX/ivD9xxflQwSrB7UYpZNFYPONbw==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/locter/-/locter-2.0.1.tgz", + "integrity": "sha512-Adl/AY/Cn3dR4tWYFhLveErQ5BgkUSgRpbDyhqzy73QP2fp6lZRr4mqhWmla5agttZFzXMkykKB5sH6FBjRSww==", "dependencies": { "destr": "^2.0.2", "ebec": "^2.3.0", diff --git a/package.json b/package.json index e808c236..37264719 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/data-source/find/module.ts b/src/data-source/find/module.ts index 1b42b19b..6e8e74bb 100644 --- a/src/data-source/find/module.ts +++ b/src/data-source/find/module.ts @@ -1,5 +1,4 @@ import { - getModuleExport, isObject, load, locate, @@ -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; } } }