Skip to content

Commit

Permalink
refactor: improve reusability
Browse files Browse the repository at this point in the history
  • Loading branch information
shah committed Dec 30, 2023
1 parent f60753f commit 1c7eec3
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions pattern/ingest/duckdb/notebook.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -19,12 +19,12 @@ export const DETERMINISTIC_UUID_NAMESPACE =
export let deterministicUuidCounter = 0;

export interface IngestSourceStructAssuranceContext {
readonly sessionEntryDML: () =>
readonly sessionEntryInsertDML: () =>
| Promise<
ReturnType<IngestGovernance["ingestSessionEntryCRF"]["insertDML"]>
>
| ReturnType<IngestGovernance["ingestSessionEntryCRF"]["insertDML"]>;
readonly structuralIssueDML: (message: string, nature?: string) =>
readonly issueInsertDML: (message: string, nature?: string) =>
| Promise<
ReturnType<IngestGovernance["ingestSessionIssueCRF"]["insertDML"]>
>
Expand Down Expand Up @@ -68,6 +68,23 @@ export interface ExcelSheetIngestSource<
readonly tableName: TableName;
}

export interface IngestSourcesSupplier<
PotentialIngestSource,
Args extends Any[] = [],
> {
readonly sources: (...args: Args) =>
| Promise<Iterable<PotentialIngestSource>>
| Iterable<PotentialIngestSource>;
}

export interface IngestFsPatternSourcesSupplier<PotentialIngestSource>
extends IngestSourcesSupplier<PotentialIngestSource, [fs.WalkEntry]> {
readonly pattern: RegExp;
readonly sources: (entry: fs.WalkEntry) =>
| Promise<Iterable<PotentialIngestSource>>
| Iterable<PotentialIngestSource>;
}

export class ErrorIngestSource implements InvalidIngestSource {
readonly nature = "ERROR";
readonly tableName = "ERROR";
Expand All @@ -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: () =>
Expand Down

0 comments on commit 1c7eec3

Please sign in to comment.