From 1c7eec332874ff10617386fd28224cc63ed88b3e Mon Sep 17 00:00:00 2001 From: "Shahid N. Shah" Date: Sat, 30 Dec 2023 09:51:39 -0500 Subject: [PATCH] refactor: improve reusability --- pattern/ingest/duckdb/notebook.ts | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/pattern/ingest/duckdb/notebook.ts b/pattern/ingest/duckdb/notebook.ts index 36879e47..3f491de1 100644 --- a/pattern/ingest/duckdb/notebook.ts +++ b/pattern/ingest/duckdb/notebook.ts @@ -1,4 +1,4 @@ -import { uuid } from "./deps.ts"; +import { fs, uuid } from "./deps.ts"; import * as chainNB from "../../../lib/notebook/chain-of-responsibility.ts"; import * as qs from "../../../lib/quality-system/mod.ts"; import * as ws from "../../../lib/universal/whitespace.ts"; @@ -19,12 +19,12 @@ export const DETERMINISTIC_UUID_NAMESPACE = export let deterministicUuidCounter = 0; export interface IngestSourceStructAssuranceContext { - readonly sessionEntryDML: () => + readonly sessionEntryInsertDML: () => | Promise< ReturnType > | ReturnType; - readonly structuralIssueDML: (message: string, nature?: string) => + readonly issueInsertDML: (message: string, nature?: string) => | Promise< ReturnType > @@ -68,6 +68,23 @@ export interface ExcelSheetIngestSource< readonly tableName: TableName; } +export interface IngestSourcesSupplier< + PotentialIngestSource, + Args extends Any[] = [], +> { + readonly sources: (...args: Args) => + | Promise> + | Iterable; +} + +export interface IngestFsPatternSourcesSupplier + extends IngestSourcesSupplier { + readonly pattern: RegExp; + readonly sources: (entry: fs.WalkEntry) => + | Promise> + | Iterable; +} + export class ErrorIngestSource implements InvalidIngestSource { readonly nature = "ERROR"; readonly tableName = "ERROR"; @@ -85,8 +102,8 @@ export class ErrorIngestSource implements InvalidIngestSource { // deno-fmt-ignore this.govn.SQL` -- required by IngestEngine, setup the ingestion entry for logging - ${await issac.sessionEntryDML()} - ${await issac.structuralIssueDML(this.error.message, this.issueType)}; + ${await issac.sessionEntryInsertDML()} + ${await issac.issueInsertDML(this.error.message, this.issueType)}; -- required by IngestEngine, emit the errors for the given session (file) so it can be picked up ${issac.selectEntryIssues()}`, assuranceSQL: () =>