diff --git a/src/parser/index.ts b/src/parser/index.ts index a44e61c..e0f8d16 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -10,15 +10,13 @@ const PARSERS: Record>> "pl.ing": PlIng }; -export async function parseTransaction(parserName: string, config: ProfileConfig, data: string[]): Promise { - const Parser = PARSERS[parserName]; +export function createParser(config: ProfileConfig): BaseTransactionParser { + const Parser = PARSERS[config.parser]; if (!Parser) { - throw new Error(`Unknown parser: ${parserName}`); + throw new Error(`Unknown parser: ${config.parser}`); } - const parser = new Parser(parserName); - - return parser.parseTransaction(config, data); + return new Parser(config.parser); } diff --git a/src/runner/index.ts b/src/runner/index.ts new file mode 100644 index 0000000..832f4ca --- /dev/null +++ b/src/runner/index.ts @@ -0,0 +1,18 @@ +import { openCsv } from "@/csv"; +import { createParser } from "@/parser"; +import { Config } from "@/types/config"; + +export function loadTransactions(file: string, profile: string, config: Config) { + const profileConfig = config.profiles[profile]; + + if (!profileConfig) { + throw new Error(`Unknown profile: ${profile}`); + } + + const parser = createParser(profileConfig); + + openCsv(file).on('data', async data => { + const transaction = await parser.parseTransaction(profileConfig, data); + console.log(transaction); + }); +} \ No newline at end of file diff --git a/src/types/config.ts b/src/types/config.ts index d26de2e..0e59a71 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -1,7 +1,12 @@ export type ProfileConfig = { - config?: object; + parser: string; + config?: ParserConfig; }; export type ParserConfig = { +}; + +export type Config = { + profiles: Record; }; \ No newline at end of file