@whaly/connector-sdk 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -0
- package/dist/index.d.mts +474 -6
- package/dist/index.d.ts +474 -6
- package/dist/index.js +1181 -162
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1146 -161
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestHeaders, AxiosResponse, AxiosRequestConfig, AxiosError } from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import Ajv, { ValidateFunction, ErrorObject } from 'ajv';
|
|
3
3
|
import { Dayjs } from 'dayjs';
|
|
4
4
|
import { WriteStream } from 'fs';
|
|
5
|
+
import { WorkBook } from 'xlsx';
|
|
6
|
+
export { WorkBook } from 'xlsx';
|
|
7
|
+
import Client from 'ssh2-sftp-client';
|
|
8
|
+
export { default as SftpClient, ConnectOptions as SftpConnectOptions } from 'ssh2-sftp-client';
|
|
9
|
+
import { File } from '@google-cloud/storage';
|
|
5
10
|
import { BigQuery, Dataset, Table } from '@google-cloud/bigquery';
|
|
6
11
|
|
|
7
12
|
declare const loadJson: (fileName: string) => any;
|
|
@@ -73,7 +78,8 @@ declare function gracefulExit(exitCode: number): Promise<void>;
|
|
|
73
78
|
|
|
74
79
|
declare enum ReplicationMethod {
|
|
75
80
|
INCREMENTAL = "INCREMENTAL",
|
|
76
|
-
FULL_TABLE = "FULL_TABLE"
|
|
81
|
+
FULL_TABLE = "FULL_TABLE",
|
|
82
|
+
APPEND = "APPEND"
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
interface HTTPHeaders {
|
|
@@ -225,6 +231,7 @@ declare abstract class StreamWarehouseSyncService {
|
|
|
225
231
|
getcolumnNameWithTypeSuffix(colName: string, warehouseType: string | undefined): string;
|
|
226
232
|
abstract getMergeQueries: () => string[];
|
|
227
233
|
abstract getReplaceQueries: () => string[];
|
|
234
|
+
abstract getAppendQueries: () => string[];
|
|
228
235
|
abstract createDatabaseAndSchemaIfNotExists: (retryCount: number) => Promise<void>;
|
|
229
236
|
abstract createTable: () => Promise<void>;
|
|
230
237
|
abstract addColumns: (fields: InternalTableField[]) => Promise<void>;
|
|
@@ -266,9 +273,12 @@ declare class StreamState$1 {
|
|
|
266
273
|
keyProperties: string[];
|
|
267
274
|
_hasBeenLoadedYetDuringThisSync: boolean;
|
|
268
275
|
replicationMethod: ReplicationMethod;
|
|
276
|
+
compiledValidateFn?: ValidateFunction;
|
|
269
277
|
constructor(streamId: StreamId, dbSync: StreamWarehouseSyncService, replicationMethod: ReplicationMethod);
|
|
270
278
|
setSchema(schema: FlattenedSchema): void;
|
|
271
279
|
getSchema(): FlattenedSchema | undefined;
|
|
280
|
+
setCompiledValidateFn(fn: ValidateFunction): void;
|
|
281
|
+
getCompiledValidateFn(): ValidateFunction | undefined;
|
|
272
282
|
getBatchDate(): string;
|
|
273
283
|
getBatchedRowCount(): number;
|
|
274
284
|
incrementBatchedRowCount(): void;
|
|
@@ -301,7 +311,7 @@ declare abstract class ITarget<C extends BaseConfig = BaseConfig> {
|
|
|
301
311
|
streams: {
|
|
302
312
|
[streamName: string]: StreamState$1;
|
|
303
313
|
};
|
|
304
|
-
|
|
314
|
+
ajv: Ajv;
|
|
305
315
|
constructor(config: C, stateProvider: StateProvider);
|
|
306
316
|
static requiredConfigKeys: string[];
|
|
307
317
|
abstract newDBSyncInstance: (streamId: StreamId, database: string, schema: string, table: string) => StreamWarehouseSyncService;
|
|
@@ -407,6 +417,7 @@ declare abstract class Stream<O = any, C = any, P = undefined> {
|
|
|
407
417
|
isSorted: boolean;
|
|
408
418
|
isSilent: boolean;
|
|
409
419
|
childConcurrency: number;
|
|
420
|
+
totalRows?: number;
|
|
410
421
|
rowsSyncedMetricsConf: MetricConfiguration;
|
|
411
422
|
executionTimeMetricsConf: MetricConfiguration;
|
|
412
423
|
constructor(config: C, tapState: InputTapState, target: ITarget, childConcurrency?: number);
|
|
@@ -588,8 +599,8 @@ declare abstract class Tap<C> {
|
|
|
588
599
|
|
|
589
600
|
declare class SchemaValidationError extends Error {
|
|
590
601
|
streamId: StreamId;
|
|
591
|
-
validationErrors:
|
|
592
|
-
constructor(message: string, streamId: StreamId, errors:
|
|
602
|
+
validationErrors: ErrorObject[];
|
|
603
|
+
constructor(message: string, streamId: StreamId, errors: ErrorObject[]);
|
|
593
604
|
}
|
|
594
605
|
declare class MissingFieldInSchemaError extends Error {
|
|
595
606
|
streamId: StreamId;
|
|
@@ -608,6 +619,461 @@ declare const flattenSchema: <T>(streamId: StreamId, schema: T) => FlattenedSche
|
|
|
608
619
|
declare const createTemporaryFileStream: (streamId: StreamId) => TempFile;
|
|
609
620
|
declare function safePath(path: string): string;
|
|
610
621
|
|
|
622
|
+
/**
|
|
623
|
+
* Field types for file processing columns.
|
|
624
|
+
* Maps to JSON Schema types via fieldTypeToJsonSchema().
|
|
625
|
+
*/
|
|
626
|
+
type FieldType = "STRING" | "FLOAT" | "TIMESTAMP";
|
|
627
|
+
declare enum FileFormat {
|
|
628
|
+
CSV = "CSV",
|
|
629
|
+
EXCEL = "EXCEL"
|
|
630
|
+
}
|
|
631
|
+
type ExcelFieldSpec = ExcelSourceColumn | ExcelDerivedField;
|
|
632
|
+
interface ExcelSourceColumn {
|
|
633
|
+
type: FieldType;
|
|
634
|
+
column: string;
|
|
635
|
+
primaryKey?: boolean;
|
|
636
|
+
}
|
|
637
|
+
interface ExcelDerivedField {
|
|
638
|
+
variableName: string;
|
|
639
|
+
primaryKey?: boolean;
|
|
640
|
+
type: FieldType;
|
|
641
|
+
}
|
|
642
|
+
interface ExcelFieldMapping {
|
|
643
|
+
[key: string]: ExcelFieldSpec;
|
|
644
|
+
}
|
|
645
|
+
type ExcelExtractionConfig = ExcelSingleSheetExtractionConfig | ExcelCustomExtractorConfig;
|
|
646
|
+
interface ExcelExtractionBaseConfig {
|
|
647
|
+
type: "single-sheet-extraction" | "processor";
|
|
648
|
+
extension: string;
|
|
649
|
+
fileNameValidator: (fileName: string) => boolean;
|
|
650
|
+
fileNameVariablesExtractor: (fileName: string, workbook?: WorkBook) => {
|
|
651
|
+
[key: string]: string | undefined;
|
|
652
|
+
};
|
|
653
|
+
tableName: string | ((fileName: string, workbook?: WorkBook, variables?: {
|
|
654
|
+
[key: string]: string | undefined;
|
|
655
|
+
}) => string);
|
|
656
|
+
replicationMethod: ReplicationMethod;
|
|
657
|
+
}
|
|
658
|
+
interface ExcelCustomExtractorConfig extends ExcelExtractionBaseConfig {
|
|
659
|
+
type: "processor";
|
|
660
|
+
processor: (workbook: WorkBook) => Promise<Record<string, string>[]>;
|
|
661
|
+
}
|
|
662
|
+
interface ExcelSingleSheetExtractionConfig extends ExcelExtractionBaseConfig {
|
|
663
|
+
type: "single-sheet-extraction";
|
|
664
|
+
columns: ExcelFieldMapping;
|
|
665
|
+
sheetName?: string;
|
|
666
|
+
numberOfRowsToSkip: number;
|
|
667
|
+
}
|
|
668
|
+
type CsvFieldsConfig = CsvFieldsArrayConfig | CsvFieldsDictConfig;
|
|
669
|
+
type CsvFieldsArrayConfig = Array<{
|
|
670
|
+
key: string;
|
|
671
|
+
valueTransformer?: (val: any) => string;
|
|
672
|
+
type: FieldType;
|
|
673
|
+
}>;
|
|
674
|
+
interface CsvFieldsDictConfig {
|
|
675
|
+
[key: string]: {
|
|
676
|
+
key: string;
|
|
677
|
+
valueTransformer?: (val: any) => string;
|
|
678
|
+
type: FieldType;
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
interface CsvFileConfig {
|
|
682
|
+
encoding?: string;
|
|
683
|
+
separator: string;
|
|
684
|
+
fields: CsvFieldsConfig;
|
|
685
|
+
addSyncedAtColumn?: boolean;
|
|
686
|
+
}
|
|
687
|
+
interface FileStreamBaseConfig {
|
|
688
|
+
streamId: string;
|
|
689
|
+
replicationMethod: ReplicationMethod;
|
|
690
|
+
primaryKeys: string[];
|
|
691
|
+
}
|
|
692
|
+
interface CsvStreamConfig extends FileStreamBaseConfig {
|
|
693
|
+
format: FileFormat.CSV;
|
|
694
|
+
csv: CsvFileConfig;
|
|
695
|
+
}
|
|
696
|
+
interface ExcelStreamConfig extends FileStreamBaseConfig {
|
|
697
|
+
format: FileFormat.EXCEL;
|
|
698
|
+
excel: ExcelExtractionConfig;
|
|
699
|
+
}
|
|
700
|
+
type FileStreamConfig = CsvStreamConfig | ExcelStreamConfig;
|
|
701
|
+
interface FileStreamEntry {
|
|
702
|
+
config: FileStreamConfig;
|
|
703
|
+
filePath: string | string[];
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
type JsonSchemaProperty = {
|
|
707
|
+
type: (string | "null")[];
|
|
708
|
+
format?: string;
|
|
709
|
+
};
|
|
710
|
+
/**
|
|
711
|
+
* Convert a FieldType to a JSON Schema property definition.
|
|
712
|
+
*/
|
|
713
|
+
declare function fieldTypeToJsonSchema(fieldType: FieldType): JsonSchemaProperty;
|
|
714
|
+
/**
|
|
715
|
+
* Convert an ExcelFieldMapping to a JSON Schema properties object.
|
|
716
|
+
*/
|
|
717
|
+
declare function excelFieldsToJsonSchema(fields: ExcelFieldMapping): {
|
|
718
|
+
type: "object";
|
|
719
|
+
properties: Record<string, JsonSchemaProperty>;
|
|
720
|
+
};
|
|
721
|
+
/**
|
|
722
|
+
* Convert a CsvFieldsConfig to a JSON Schema properties object.
|
|
723
|
+
*/
|
|
724
|
+
declare function csvFieldsToJsonSchema(config: CsvFieldsConfig): {
|
|
725
|
+
type: "object";
|
|
726
|
+
properties: Record<string, JsonSchemaProperty>;
|
|
727
|
+
};
|
|
728
|
+
/**
|
|
729
|
+
* Extract all output keys from a CsvFieldsConfig to use as composite primary keys.
|
|
730
|
+
* Useful for FULL_TABLE replication where all fields form the PK (since TRUNCATE + MERGE = INSERT).
|
|
731
|
+
*/
|
|
732
|
+
declare function extractPrimaryKeysFromCsvConfig(config: CsvFieldsConfig): string[];
|
|
733
|
+
/**
|
|
734
|
+
* Extract primary keys from an ExcelFieldMapping.
|
|
735
|
+
*/
|
|
736
|
+
declare function extractPrimaryKeysFromExcelFields(fields: ExcelFieldMapping): string[];
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Converts an Excel column letter (A, B, C, AA, AZ, etc.) to its zero-based index.
|
|
740
|
+
*/
|
|
741
|
+
declare const excelColumnToIndex: (columnLetter: string) => number;
|
|
742
|
+
/**
|
|
743
|
+
* Converts a zero-based column index to Excel column letter(s).
|
|
744
|
+
*/
|
|
745
|
+
declare const indexToExcelColumn: (columnIndex: number) => string;
|
|
746
|
+
/**
|
|
747
|
+
* Converts an Excel row number (1-based) to zero-based array index.
|
|
748
|
+
*/
|
|
749
|
+
declare const excelRowToIndex: (rowNumber: string | number) => number;
|
|
750
|
+
/**
|
|
751
|
+
* Converts a zero-based array index to Excel row number (1-based).
|
|
752
|
+
*/
|
|
753
|
+
declare const indexToExcelRow: (index: number) => number;
|
|
754
|
+
/**
|
|
755
|
+
* Parses an Excel cell reference (like "A1", "Z24", "AA100") into column and row indices.
|
|
756
|
+
*/
|
|
757
|
+
declare const parseCellReference: (cellRef: string) => {
|
|
758
|
+
columnIndex: number;
|
|
759
|
+
rowIndex: number;
|
|
760
|
+
};
|
|
761
|
+
/**
|
|
762
|
+
* Creates an Excel cell reference from column and row indices.
|
|
763
|
+
*/
|
|
764
|
+
declare const createCellReference: (columnIndex: number, rowIndex: number) => string;
|
|
765
|
+
/**
|
|
766
|
+
* Low-level Excel extractor: returns array of row records from a workbook.
|
|
767
|
+
*/
|
|
768
|
+
declare const extractExcelRows: (localFilePath: string, conf: ExcelExtractionConfig) => Promise<Record<string, string>[]>;
|
|
769
|
+
/**
|
|
770
|
+
* Validates an Excel file configuration.
|
|
771
|
+
*/
|
|
772
|
+
declare const validateExcelConfig: (config: ExcelExtractionConfig) => void;
|
|
773
|
+
/**
|
|
774
|
+
* Finds all matching configurations for a given filename.
|
|
775
|
+
*/
|
|
776
|
+
declare const findAllMatchingConfigs: (filename: string, configs: ExcelExtractionConfig[]) => ExcelExtractionConfig[];
|
|
777
|
+
/**
|
|
778
|
+
* Creates an async generator from Excel data.
|
|
779
|
+
*/
|
|
780
|
+
declare function createExcelGenerator(data: Record<string, string>[]): AsyncGenerator<Record<string, any>, void, unknown>;
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Builder pattern for creating Excel configurations.
|
|
784
|
+
*
|
|
785
|
+
* Sensible defaults:
|
|
786
|
+
* - fileNameValidator: accepts all files
|
|
787
|
+
* - fileNameVariablesExtractor: extracts nothing
|
|
788
|
+
* - replicationMethod: FULL_TABLE
|
|
789
|
+
*/
|
|
790
|
+
declare class ExcelExtractionConfigBuilder {
|
|
791
|
+
private config;
|
|
792
|
+
static create(): ExcelExtractionConfigBuilder;
|
|
793
|
+
extension(ext: string): ExcelExtractionConfigBuilder;
|
|
794
|
+
tableName(name: string | ((fileName: string, workbook?: WorkBook, variables?: {
|
|
795
|
+
[key: string]: string | undefined;
|
|
796
|
+
}) => string)): ExcelExtractionConfigBuilder;
|
|
797
|
+
fileValidator(validator: (filename: string) => boolean): ExcelExtractionConfigBuilder;
|
|
798
|
+
variablesExtractor(extractor: (filename: string, workbook?: WorkBook) => {
|
|
799
|
+
[key: string]: string | undefined;
|
|
800
|
+
}): ExcelExtractionConfigBuilder;
|
|
801
|
+
replicationMethod(method: ReplicationMethod): ExcelExtractionConfigBuilder;
|
|
802
|
+
columns(cols: {
|
|
803
|
+
[key: string]: ExcelFieldSpec;
|
|
804
|
+
}): ExcelExtractionConfigBuilder;
|
|
805
|
+
singleSheet(sheetName?: string, skipRows?: number): ExcelExtractionConfigBuilder;
|
|
806
|
+
processor(processorFn: (workbook: WorkBook) => Promise<Record<string, string>[]>): ExcelExtractionConfigBuilder;
|
|
807
|
+
build(): ExcelExtractionConfig;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Async generator that yields parsed rows from a CSV file.
|
|
812
|
+
* Supports custom separators, encoding, BOM stripping, and field transformers.
|
|
813
|
+
*/
|
|
814
|
+
declare function rowGeneratorFromCsv(path: string, fileConfig: CsvFileConfig): AsyncGenerator<Record<string, any>>;
|
|
815
|
+
/**
|
|
816
|
+
* Counts data rows in a CSV file by scanning for newline bytes.
|
|
817
|
+
* Subtracts 1 for the header row. Fast: no CSV parsing required.
|
|
818
|
+
*/
|
|
819
|
+
declare function countCsvLines(filePath: string): Promise<number>;
|
|
820
|
+
/**
|
|
821
|
+
* Validates CSV header row against expected configuration.
|
|
822
|
+
*/
|
|
823
|
+
declare const checkCsvHeaderRow: (path: string, fileConfig: CsvFileConfig) => Promise<void>;
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Writes an array of objects directly to a CSV file.
|
|
827
|
+
*/
|
|
828
|
+
declare const writeDataToCsv: (fileName: string, data: any[]) => Promise<void>;
|
|
829
|
+
/**
|
|
830
|
+
* Writes data from an async generator to CSV with batch writing (10k row batches).
|
|
831
|
+
*/
|
|
832
|
+
declare const writeGeneratorToCSV: (generator: AsyncGenerator, outputFileName: string) => Promise<number>;
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* Builder pattern for creating CSV configurations.
|
|
836
|
+
*
|
|
837
|
+
* Usage:
|
|
838
|
+
* ```ts
|
|
839
|
+
* const config = CsvExtractionConfigBuilder.create()
|
|
840
|
+
* .separator(";")
|
|
841
|
+
* .encoding("latin1")
|
|
842
|
+
* .addSyncedAtColumn()
|
|
843
|
+
* .fieldsFromDict({
|
|
844
|
+
* "Product ID": { key: "product_id", type: "STRING" },
|
|
845
|
+
* "Product Name": { key: "product_name", type: "STRING" },
|
|
846
|
+
* "Price": { key: "price", type: "FLOAT" },
|
|
847
|
+
* })
|
|
848
|
+
* .build();
|
|
849
|
+
* ```
|
|
850
|
+
*/
|
|
851
|
+
declare class CsvExtractionConfigBuilder {
|
|
852
|
+
private _separator;
|
|
853
|
+
private _encoding?;
|
|
854
|
+
private _addSyncedAtColumn?;
|
|
855
|
+
private _fields?;
|
|
856
|
+
private _fieldsMode?;
|
|
857
|
+
private _replicationMethod?;
|
|
858
|
+
private _primaryKeys?;
|
|
859
|
+
static create(): CsvExtractionConfigBuilder;
|
|
860
|
+
separator(sep: string): CsvExtractionConfigBuilder;
|
|
861
|
+
encoding(enc: string): CsvExtractionConfigBuilder;
|
|
862
|
+
addSyncedAtColumn(enabled?: boolean): CsvExtractionConfigBuilder;
|
|
863
|
+
fieldsFromDict(mapping: {
|
|
864
|
+
[header: string]: {
|
|
865
|
+
key: string;
|
|
866
|
+
valueTransformer?: (val: any) => string;
|
|
867
|
+
type: FieldType;
|
|
868
|
+
};
|
|
869
|
+
}): CsvExtractionConfigBuilder;
|
|
870
|
+
fieldsFromArray(fields: Array<{
|
|
871
|
+
key: string;
|
|
872
|
+
valueTransformer?: (val: any) => string;
|
|
873
|
+
type: FieldType;
|
|
874
|
+
}>): CsvExtractionConfigBuilder;
|
|
875
|
+
replicationMethod(method: ReplicationMethod): CsvExtractionConfigBuilder;
|
|
876
|
+
primaryKeys(keys: string[]): CsvExtractionConfigBuilder;
|
|
877
|
+
build(): CsvFileConfig;
|
|
878
|
+
buildStreamConfig(streamId: string): FileStreamConfig;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* FileStream bridges file processing (Excel/CSV) into the connector SDK pipeline.
|
|
883
|
+
*
|
|
884
|
+
* It extends Stream so it integrates with the standard Tap -> Stream -> Target flow.
|
|
885
|
+
* Each FileStream reads one file with one config and yields records.
|
|
886
|
+
*/
|
|
887
|
+
declare class FileStream extends Stream<Record<string, any>, FileStreamConfig> {
|
|
888
|
+
private localFilePaths;
|
|
889
|
+
constructor(config: FileStreamConfig, localFilePath: string | string[], tapState: InputTapState, target: ITarget);
|
|
890
|
+
/**
|
|
891
|
+
* Build JSON Schema from the file config's field definitions.
|
|
892
|
+
*/
|
|
893
|
+
getSchema(): Promise<Schema | undefined>;
|
|
894
|
+
/**
|
|
895
|
+
* Yield records from all file(s).
|
|
896
|
+
* When multiple file paths are provided, records are yielded sequentially from each file.
|
|
897
|
+
* Pre-counts total rows across all files to enable percentage progress logging.
|
|
898
|
+
*/
|
|
899
|
+
_getRecords(): AsyncIterable<Record<string, any>>;
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Create a FileStreamConfig from an ExcelExtractionConfig.
|
|
903
|
+
* Handles both single-sheet-extraction and processor config types.
|
|
904
|
+
*
|
|
905
|
+
* For single-sheet configs, primary keys are extracted from column definitions.
|
|
906
|
+
* For processor configs, primary keys default to an empty array.
|
|
907
|
+
*
|
|
908
|
+
* @param excelConfig - The Excel extraction config (single-sheet or processor)
|
|
909
|
+
* @param fileName - The base filename (used for variable extraction and table name resolution)
|
|
910
|
+
* @param localFilePath - Optional local file path; required for processor configs with dynamic table names
|
|
911
|
+
*/
|
|
912
|
+
declare function createExcelStreamConfig(excelConfig: ExcelExtractionConfig, fileName: string, localFilePath?: string): FileStreamConfig;
|
|
913
|
+
/**
|
|
914
|
+
* Create a FileStreamConfig from a CsvFileConfig.
|
|
915
|
+
*
|
|
916
|
+
* By default, uses FULL_TABLE replication and extracts all field keys as composite primary keys.
|
|
917
|
+
* Override via the options parameter.
|
|
918
|
+
*
|
|
919
|
+
* @param streamId - The stream/table name
|
|
920
|
+
* @param csvConfig - The CSV file configuration
|
|
921
|
+
* @param options - Optional overrides for replicationMethod and primaryKeys
|
|
922
|
+
*/
|
|
923
|
+
declare function createCsvStreamConfig(streamId: string, csvConfig: CsvFileConfig, options?: {
|
|
924
|
+
replicationMethod?: ReplicationMethod;
|
|
925
|
+
primaryKeys?: string[];
|
|
926
|
+
}): FileStreamConfig;
|
|
927
|
+
/**
|
|
928
|
+
* Process an array of FileStreamEntry sequentially, then signal completion to the target.
|
|
929
|
+
*
|
|
930
|
+
* This is the recommended pattern for SFTP and similar multi-file ingestion flows
|
|
931
|
+
* where FileTap isn't needed.
|
|
932
|
+
*
|
|
933
|
+
* @param entries - Array of { config, filePath } pairs
|
|
934
|
+
* @param tapState - The tap state (typically `{ bookmarks: {} }`)
|
|
935
|
+
* @param target - The target (e.g. BigQueryTarget)
|
|
936
|
+
*/
|
|
937
|
+
declare function processFileStreams(entries: FileStreamEntry[], tapState: InputTapState, target: ITarget): Promise<void>;
|
|
938
|
+
|
|
939
|
+
interface FileTapConfig {
|
|
940
|
+
[key: string]: any;
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* FileTap orchestrates multiple FileStreams.
|
|
944
|
+
*
|
|
945
|
+
* It extends Tap so it integrates with the standard Tap -> Stream -> Target flow.
|
|
946
|
+
* Provide file stream entries (config + file path pairs), and it creates a FileStream per entry.
|
|
947
|
+
*
|
|
948
|
+
* For simple sequential file processing without the Tap lifecycle, use processFileStreams() instead.
|
|
949
|
+
*/
|
|
950
|
+
declare class FileTap extends Tap<FileTapConfig> {
|
|
951
|
+
private entries;
|
|
952
|
+
constructor(target: ITarget, config: FileTapConfig, stateProvider: StateProvider, entries: FileStreamEntry[]);
|
|
953
|
+
/**
|
|
954
|
+
* Convenience constructor for the common case where all configs share the same file path.
|
|
955
|
+
*/
|
|
956
|
+
static fromConfigs(target: ITarget, config: FileTapConfig, stateProvider: StateProvider, fileConfigs: FileStreamConfig[], sharedFilePath: string): FileTap;
|
|
957
|
+
init(): Promise<void>;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* Variable extraction utilities for common filename patterns.
|
|
962
|
+
*/
|
|
963
|
+
declare class VariableExtractors {
|
|
964
|
+
/**
|
|
965
|
+
* Returns the filename as a variable.
|
|
966
|
+
*/
|
|
967
|
+
static filename(): (filename: string) => {
|
|
968
|
+
[key: string]: string | undefined;
|
|
969
|
+
};
|
|
970
|
+
/**
|
|
971
|
+
* Extracts named capture groups from a regex pattern.
|
|
972
|
+
*/
|
|
973
|
+
static regex(pattern: RegExp): (filename: string) => {
|
|
974
|
+
[key: string]: string | undefined;
|
|
975
|
+
};
|
|
976
|
+
/**
|
|
977
|
+
* Combines multiple extraction functions.
|
|
978
|
+
*/
|
|
979
|
+
static combine(...extractors: ((filename: string) => {
|
|
980
|
+
[key: string]: string | undefined;
|
|
981
|
+
})[]): (filename: string) => {
|
|
982
|
+
[key: string]: string | undefined;
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* File pattern utilities for common filename validation patterns.
|
|
987
|
+
*/
|
|
988
|
+
declare class FilePatterns {
|
|
989
|
+
/**
|
|
990
|
+
* Creates a validator for files starting with a specific prefix (case-insensitive).
|
|
991
|
+
*/
|
|
992
|
+
static startsWith(prefix: string): (filename: string) => boolean;
|
|
993
|
+
/**
|
|
994
|
+
* Creates a validator for files matching a regex pattern.
|
|
995
|
+
*/
|
|
996
|
+
static regex(pattern: RegExp): (filename: string) => boolean;
|
|
997
|
+
/**
|
|
998
|
+
* Combines multiple validators with AND logic.
|
|
999
|
+
*/
|
|
1000
|
+
static and(...validators: ((filename: string) => boolean)[]): (filename: string) => boolean;
|
|
1001
|
+
/**
|
|
1002
|
+
* Combines multiple validators with OR logic.
|
|
1003
|
+
*/
|
|
1004
|
+
static or(...validators: ((filename: string) => boolean)[]): (filename: string) => boolean;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
/**
|
|
1008
|
+
* Pre-instantiated SFTP client singleton.
|
|
1009
|
+
* @deprecated Prefer creating your own SftpClient instance for better lifecycle control.
|
|
1010
|
+
*/
|
|
1011
|
+
declare const SftpService: Client;
|
|
1012
|
+
|
|
1013
|
+
interface CloudStorageServiceOptions {
|
|
1014
|
+
processedSuffix?: string;
|
|
1015
|
+
supportedExtensions?: string[];
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* Service for interacting with Google Cloud Storage.
|
|
1019
|
+
* Supports file download, upload, listing, and marker-file-based processing tracking.
|
|
1020
|
+
*/
|
|
1021
|
+
declare class CloudStorageService {
|
|
1022
|
+
private storage;
|
|
1023
|
+
private bucket;
|
|
1024
|
+
private processedSuffix;
|
|
1025
|
+
private supportedExtensions;
|
|
1026
|
+
private path;
|
|
1027
|
+
constructor(bucketName: string, path?: string, opts?: CloudStorageServiceOptions);
|
|
1028
|
+
/**
|
|
1029
|
+
* Lists all files in the bucket with an optional prefix.
|
|
1030
|
+
*/
|
|
1031
|
+
listFiles(prefix?: string): Promise<string[]>;
|
|
1032
|
+
/**
|
|
1033
|
+
* Returns files that haven't been marked as processed.
|
|
1034
|
+
* Filters by supported extensions if configured.
|
|
1035
|
+
*/
|
|
1036
|
+
getUnprocessedFiles(): Promise<string[]>;
|
|
1037
|
+
/**
|
|
1038
|
+
* Creates a marker file to indicate a file has been processed.
|
|
1039
|
+
*/
|
|
1040
|
+
createMarkerFile(fileName: string): Promise<void>;
|
|
1041
|
+
/**
|
|
1042
|
+
* Downloads a file from GCS to a local tmp directory.
|
|
1043
|
+
* Returns the local path of the downloaded file.
|
|
1044
|
+
*/
|
|
1045
|
+
downloadFile(filePath: string, fileName: string): Promise<string>;
|
|
1046
|
+
/**
|
|
1047
|
+
* Uploads a local file to GCS.
|
|
1048
|
+
*/
|
|
1049
|
+
uploadFile(localPath: string, destPath: string): Promise<File>;
|
|
1050
|
+
/**
|
|
1051
|
+
* Reads a GCS object and returns its contents as a UTF-8 string.
|
|
1052
|
+
*/
|
|
1053
|
+
readObjectAsString(objectPath: string): Promise<string>;
|
|
1054
|
+
/**
|
|
1055
|
+
* Writes a string to a GCS object with JSON content type.
|
|
1056
|
+
*/
|
|
1057
|
+
writeStringObject(objectPath: string, contents: string): Promise<void>;
|
|
1058
|
+
/**
|
|
1059
|
+
* Uploads a local file to the bucket with a unique name based on prefix, streamId, and UUID.
|
|
1060
|
+
* Files are stored under `<prefix>/<run-id>/` when the RUN_ID env var is set,
|
|
1061
|
+
* or `<prefix>/default/` otherwise.
|
|
1062
|
+
* Returns the GCS File reference.
|
|
1063
|
+
*/
|
|
1064
|
+
uploadFileWithUniqueName(filePath: string, prefix: string, streamId: string): Promise<File>;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
/**
|
|
1068
|
+
* Extract a ZIP (or other archive) file to a target directory.
|
|
1069
|
+
* Uses the `decompress` library which supports zip, tar, gz, bz2, etc.
|
|
1070
|
+
*
|
|
1071
|
+
* @param zipFilePath - Path to the archive file
|
|
1072
|
+
* @param extractedPath - Directory to extract into (created if it doesn't exist)
|
|
1073
|
+
* @returns The output directory path
|
|
1074
|
+
*/
|
|
1075
|
+
declare const unzip: (zipFilePath: string, extractedPath: string) => Promise<string>;
|
|
1076
|
+
|
|
611
1077
|
interface BigQueryConfig extends BaseConfig {
|
|
612
1078
|
schema: string;
|
|
613
1079
|
project_id: string;
|
|
@@ -632,6 +1098,7 @@ declare class BigQueryDBSync extends StreamWarehouseSyncService {
|
|
|
632
1098
|
getWarehouseTypeFromJSONSchema: (definition: JSONSchemaFieldDefinition) => string;
|
|
633
1099
|
getMergeQueries: () => string[];
|
|
634
1100
|
getReplaceQueries: () => string[];
|
|
1101
|
+
getAppendQueries: () => string[];
|
|
635
1102
|
createDatabaseAndSchemaIfNotExists: (retryCount: number) => Promise<void>;
|
|
636
1103
|
createTable: () => Promise<void>;
|
|
637
1104
|
addColumns: (tableFields: InternalTableField[]) => Promise<void>;
|
|
@@ -669,10 +1136,11 @@ declare class BigQueryTarget extends ITarget<BigQueryConfig> {
|
|
|
669
1136
|
declare class GCSStateProvider implements StateProvider {
|
|
670
1137
|
private bucketName;
|
|
671
1138
|
private connectorId;
|
|
1139
|
+
private service;
|
|
672
1140
|
constructor(connectorId: string, bucketName: string);
|
|
673
1141
|
private getObjectPath;
|
|
674
1142
|
getState(): Promise<StateHolder>;
|
|
675
1143
|
writeState(state: string): Promise<void>;
|
|
676
1144
|
}
|
|
677
1145
|
|
|
678
|
-
export { ALL_STREAM_ID_KEYWORD, API_CALLS_METRIC_NAME, Authenticator, BATCH_INTERVAL_MS, type BaseConfig, type BigQueryConfig, BigQueryTarget, type BigqueryLocation, type Bookmark, type Bookmarks, type ColumnMappingStoreUnsafeToSafe, CounterMetric, DEFAULT_MAX_CONCURRENT_STREAMS, EXECUTION_TIME_METRIC_NAME, type ErrorType, type FlattenedSchema, GCSStateProvider, type GetConfig, type HTTPHeaders, type HTTPMethod, ITarget, type InputTapState, type InternalTableField, type JSONSchemaFieldDefinition, type Message, type MessageType, type MetricConfiguration, MissingFieldInSchemaError, MissingSchemaError, type PostConfig, type ProgressMarkers, type PropertiesMetadata, RESTStream, ROWS_SYNCED_METRIC_NAME, RecordMessage, RenameColumnStore, ReplicationMethod, ReplicationMethodMessage, type SafeColumnNameConverterFn, type Schema, SchemaMessage, SchemaValidationError, type State, type StateHolder, StateMessage, type StateProvider, StateService, Stream, type StreamId, type StreamState, StreamWarehouseSyncService, type StreamWithTempFile, type SyncOptions, Tap, type TapState, type TargetSchemaHook, type TargetSchemaHookInput, type TempFile, type URLParams, type WarehouseTableField, _greaterThan, addWhalyFields, createTemporaryFileStream, extractStateForStream, finalizeStateProgressMarkers, flattenSchema, getAllMetrics, getAxiosInstance, getCounterMetric, getCounterMetrics, getDownloadFileApiCall, getJSONApiCall, getJSONApiCallWithFullResponse, getRawJSONApiCall, gracefulExit, haltAndCatchFire, incrementStreamState, loadJson, loadSchema, logger, postFormDataApiCall, postJSONApiCall, postUrlEncodedApiCall, printMemoryFootprint, removeParasiteProperties, safePath };
|
|
1146
|
+
export { ALL_STREAM_ID_KEYWORD, API_CALLS_METRIC_NAME, Authenticator, BATCH_INTERVAL_MS, type BaseConfig, type BigQueryConfig, BigQueryTarget, type BigqueryLocation, type Bookmark, type Bookmarks, CloudStorageService, type CloudStorageServiceOptions, type ColumnMappingStoreUnsafeToSafe, CounterMetric, CsvExtractionConfigBuilder, type CsvFieldsArrayConfig, type CsvFieldsConfig, type CsvFieldsDictConfig, type CsvFileConfig, type CsvStreamConfig, DEFAULT_MAX_CONCURRENT_STREAMS, EXECUTION_TIME_METRIC_NAME, type ErrorType, type ExcelCustomExtractorConfig, type ExcelDerivedField, type ExcelExtractionBaseConfig, type ExcelExtractionConfig, ExcelExtractionConfigBuilder, type ExcelFieldMapping, type ExcelFieldSpec, type ExcelSingleSheetExtractionConfig, type ExcelSourceColumn, type ExcelStreamConfig, type FieldType, FileFormat, FilePatterns, FileStream, type FileStreamConfig, type FileStreamEntry, FileTap, type FileTapConfig, type FlattenedSchema, GCSStateProvider, type GetConfig, type HTTPHeaders, type HTTPMethod, ITarget, type InputTapState, type InternalTableField, type JSONSchemaFieldDefinition, type Message, type MessageType, type MetricConfiguration, MissingFieldInSchemaError, MissingSchemaError, type PostConfig, type ProgressMarkers, type PropertiesMetadata, RESTStream, ROWS_SYNCED_METRIC_NAME, RecordMessage, RenameColumnStore, ReplicationMethod, ReplicationMethodMessage, type SafeColumnNameConverterFn, type Schema, SchemaMessage, SchemaValidationError, SftpService, type State, type StateHolder, StateMessage, type StateProvider, StateService, Stream, type StreamId, type StreamState, StreamWarehouseSyncService, type StreamWithTempFile, type SyncOptions, Tap, type TapState, type TargetSchemaHook, type TargetSchemaHookInput, type TempFile, type URLParams, VariableExtractors, type WarehouseTableField, _greaterThan, addWhalyFields, checkCsvHeaderRow, countCsvLines, createCellReference, createCsvStreamConfig, createExcelGenerator, createExcelStreamConfig, createTemporaryFileStream, csvFieldsToJsonSchema, excelColumnToIndex, excelFieldsToJsonSchema, excelRowToIndex, extractExcelRows, extractPrimaryKeysFromCsvConfig, extractPrimaryKeysFromExcelFields, extractStateForStream, fieldTypeToJsonSchema, finalizeStateProgressMarkers, findAllMatchingConfigs, flattenSchema, getAllMetrics, getAxiosInstance, getCounterMetric, getCounterMetrics, getDownloadFileApiCall, getJSONApiCall, getJSONApiCallWithFullResponse, getRawJSONApiCall, gracefulExit, haltAndCatchFire, incrementStreamState, indexToExcelColumn, indexToExcelRow, loadJson, loadSchema, logger, parseCellReference, postFormDataApiCall, postJSONApiCall, postUrlEncodedApiCall, printMemoryFootprint, processFileStreams, removeParasiteProperties, rowGeneratorFromCsv, safePath, unzip, validateExcelConfig, writeDataToCsv, writeGeneratorToCSV };
|