Skip to content

Commit

Permalink
fix: support async import for DataSource in CLI #8914 (#8917)
Browse files Browse the repository at this point in the history
* Fix: await DataSource from export file to support async loading

* fix: prettier errors

* updated code style

Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
  • Loading branch information
anton-pavlov-deel and pleerock committed Aug 22, 2022
1 parent bb33cd0 commit 15f90e0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/commands/CommandUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ export class CommandUtils {
}

const dataSourceExports = []
for (let fileExport in dataSourceFileExports) {
if (
InstanceChecker.isDataSource(dataSourceFileExports[fileExport])
) {
dataSourceExports.push(dataSourceFileExports[fileExport])
for (const fileExport of dataSourceFileExports) {
// It is necessary to await here in case of the exported async value (Promise<DataSource>).
// e.g. the DataSource is instantiated with an async factory in the source file
const awaitedFileExport =
fileExport instanceof Promise ? await fileExport : fileExport
if (InstanceChecker.isDataSource(awaitedFileExport)) {
dataSourceExports.push(awaitedFileExport)
}
}

Expand Down

0 comments on commit 15f90e0

Please sign in to comment.