import fs from "fs"; import { Document } from ".."; export interface Loader { load(): Promise; } export class FileLoader implements Loader { path: string; meta?: Record; constructor(path: string, meta?: Record) { this.path = path; this.meta = meta; } /** * Load a file from the filesystem * * @returns {Promise} A promise that resolves to an array of documents */ async load(): Promise { const content = await fs.promises.readFile(this.path, "utf-8"); return [ { content, meta: { source: this.path, ...this.meta, }, }, ]; } }