@whaly/connector-sdk 0.2.0 → 0.3.0
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 +458 -2
- package/dist/index.d.ts +458 -2
- package/dist/index.js +1181 -148
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1147 -147
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -5
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ import { AxiosInstance, AxiosRequestHeaders, AxiosResponse, AxiosRequestConfig,
|
|
|
2
2
|
import { Validator, ValidationError } from 'jsonschema';
|
|
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>;
|
|
@@ -608,6 +615,453 @@ declare const flattenSchema: <T>(streamId: StreamId, schema: T) => FlattenedSche
|
|
|
608
615
|
declare const createTemporaryFileStream: (streamId: StreamId) => TempFile;
|
|
609
616
|
declare function safePath(path: string): string;
|
|
610
617
|
|
|
618
|
+
/**
|
|
619
|
+
* Field types for file processing columns.
|
|
620
|
+
* Maps to JSON Schema types via fieldTypeToJsonSchema().
|
|
621
|
+
*/
|
|
622
|
+
type FieldType = "STRING" | "FLOAT" | "TIMESTAMP";
|
|
623
|
+
declare enum FileFormat {
|
|
624
|
+
CSV = "CSV",
|
|
625
|
+
EXCEL = "EXCEL"
|
|
626
|
+
}
|
|
627
|
+
type ExcelFieldSpec = ExcelSourceColumn | ExcelDerivedField;
|
|
628
|
+
interface ExcelSourceColumn {
|
|
629
|
+
type: FieldType;
|
|
630
|
+
column: string;
|
|
631
|
+
primaryKey?: boolean;
|
|
632
|
+
}
|
|
633
|
+
interface ExcelDerivedField {
|
|
634
|
+
variableName: string;
|
|
635
|
+
primaryKey?: boolean;
|
|
636
|
+
type: FieldType;
|
|
637
|
+
}
|
|
638
|
+
interface ExcelFieldMapping {
|
|
639
|
+
[key: string]: ExcelFieldSpec;
|
|
640
|
+
}
|
|
641
|
+
type ExcelExtractionConfig = ExcelSingleSheetExtractionConfig | ExcelCustomExtractorConfig;
|
|
642
|
+
interface ExcelExtractionBaseConfig {
|
|
643
|
+
type: "single-sheet-extraction" | "processor";
|
|
644
|
+
extension: string;
|
|
645
|
+
fileNameValidator: (fileName: string) => boolean;
|
|
646
|
+
fileNameVariablesExtractor: (fileName: string, workbook?: WorkBook) => {
|
|
647
|
+
[key: string]: string | undefined;
|
|
648
|
+
};
|
|
649
|
+
tableName: string | ((fileName: string, workbook?: WorkBook, variables?: {
|
|
650
|
+
[key: string]: string | undefined;
|
|
651
|
+
}) => string);
|
|
652
|
+
replicationMethod: ReplicationMethod;
|
|
653
|
+
}
|
|
654
|
+
interface ExcelCustomExtractorConfig extends ExcelExtractionBaseConfig {
|
|
655
|
+
type: "processor";
|
|
656
|
+
processor: (workbook: WorkBook) => Promise<Record<string, string>[]>;
|
|
657
|
+
}
|
|
658
|
+
interface ExcelSingleSheetExtractionConfig extends ExcelExtractionBaseConfig {
|
|
659
|
+
type: "single-sheet-extraction";
|
|
660
|
+
columns: ExcelFieldMapping;
|
|
661
|
+
sheetName?: string;
|
|
662
|
+
numberOfRowsToSkip: number;
|
|
663
|
+
}
|
|
664
|
+
type CsvFieldsConfig = CsvFieldsArrayConfig | CsvFieldsDictConfig;
|
|
665
|
+
type CsvFieldsArrayConfig = Array<{
|
|
666
|
+
key: string;
|
|
667
|
+
valueTransformer?: (val: any) => string;
|
|
668
|
+
type: FieldType;
|
|
669
|
+
}>;
|
|
670
|
+
interface CsvFieldsDictConfig {
|
|
671
|
+
[key: string]: {
|
|
672
|
+
key: string;
|
|
673
|
+
valueTransformer?: (val: any) => string;
|
|
674
|
+
type: FieldType;
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
interface CsvFileConfig {
|
|
678
|
+
encoding?: string;
|
|
679
|
+
separator: string;
|
|
680
|
+
fields: CsvFieldsConfig;
|
|
681
|
+
addSyncedAtColumn?: boolean;
|
|
682
|
+
}
|
|
683
|
+
interface FileStreamBaseConfig {
|
|
684
|
+
streamId: string;
|
|
685
|
+
replicationMethod: ReplicationMethod;
|
|
686
|
+
primaryKeys: string[];
|
|
687
|
+
}
|
|
688
|
+
interface CsvStreamConfig extends FileStreamBaseConfig {
|
|
689
|
+
format: FileFormat.CSV;
|
|
690
|
+
csv: CsvFileConfig;
|
|
691
|
+
}
|
|
692
|
+
interface ExcelStreamConfig extends FileStreamBaseConfig {
|
|
693
|
+
format: FileFormat.EXCEL;
|
|
694
|
+
excel: ExcelExtractionConfig;
|
|
695
|
+
}
|
|
696
|
+
type FileStreamConfig = CsvStreamConfig | ExcelStreamConfig;
|
|
697
|
+
interface FileStreamEntry {
|
|
698
|
+
config: FileStreamConfig;
|
|
699
|
+
filePath: string | string[];
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
type JsonSchemaProperty = {
|
|
703
|
+
type: (string | "null")[];
|
|
704
|
+
format?: string;
|
|
705
|
+
};
|
|
706
|
+
/**
|
|
707
|
+
* Convert a FieldType to a JSON Schema property definition.
|
|
708
|
+
*/
|
|
709
|
+
declare function fieldTypeToJsonSchema(fieldType: FieldType): JsonSchemaProperty;
|
|
710
|
+
/**
|
|
711
|
+
* Convert an ExcelFieldMapping to a JSON Schema properties object.
|
|
712
|
+
*/
|
|
713
|
+
declare function excelFieldsToJsonSchema(fields: ExcelFieldMapping): {
|
|
714
|
+
type: "object";
|
|
715
|
+
properties: Record<string, JsonSchemaProperty>;
|
|
716
|
+
};
|
|
717
|
+
/**
|
|
718
|
+
* Convert a CsvFieldsConfig to a JSON Schema properties object.
|
|
719
|
+
*/
|
|
720
|
+
declare function csvFieldsToJsonSchema(config: CsvFieldsConfig): {
|
|
721
|
+
type: "object";
|
|
722
|
+
properties: Record<string, JsonSchemaProperty>;
|
|
723
|
+
};
|
|
724
|
+
/**
|
|
725
|
+
* Extract all output keys from a CsvFieldsConfig to use as composite primary keys.
|
|
726
|
+
* Useful for FULL_TABLE replication where all fields form the PK (since TRUNCATE + MERGE = INSERT).
|
|
727
|
+
*/
|
|
728
|
+
declare function extractPrimaryKeysFromCsvConfig(config: CsvFieldsConfig): string[];
|
|
729
|
+
/**
|
|
730
|
+
* Extract primary keys from an ExcelFieldMapping.
|
|
731
|
+
*/
|
|
732
|
+
declare function extractPrimaryKeysFromExcelFields(fields: ExcelFieldMapping): string[];
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Converts an Excel column letter (A, B, C, AA, AZ, etc.) to its zero-based index.
|
|
736
|
+
*/
|
|
737
|
+
declare const excelColumnToIndex: (columnLetter: string) => number;
|
|
738
|
+
/**
|
|
739
|
+
* Converts a zero-based column index to Excel column letter(s).
|
|
740
|
+
*/
|
|
741
|
+
declare const indexToExcelColumn: (columnIndex: number) => string;
|
|
742
|
+
/**
|
|
743
|
+
* Converts an Excel row number (1-based) to zero-based array index.
|
|
744
|
+
*/
|
|
745
|
+
declare const excelRowToIndex: (rowNumber: string | number) => number;
|
|
746
|
+
/**
|
|
747
|
+
* Converts a zero-based array index to Excel row number (1-based).
|
|
748
|
+
*/
|
|
749
|
+
declare const indexToExcelRow: (index: number) => number;
|
|
750
|
+
/**
|
|
751
|
+
* Parses an Excel cell reference (like "A1", "Z24", "AA100") into column and row indices.
|
|
752
|
+
*/
|
|
753
|
+
declare const parseCellReference: (cellRef: string) => {
|
|
754
|
+
columnIndex: number;
|
|
755
|
+
rowIndex: number;
|
|
756
|
+
};
|
|
757
|
+
/**
|
|
758
|
+
* Creates an Excel cell reference from column and row indices.
|
|
759
|
+
*/
|
|
760
|
+
declare const createCellReference: (columnIndex: number, rowIndex: number) => string;
|
|
761
|
+
/**
|
|
762
|
+
* Low-level Excel extractor: returns array of row records from a workbook.
|
|
763
|
+
*/
|
|
764
|
+
declare const extractExcelRows: (localFilePath: string, conf: ExcelExtractionConfig) => Promise<Record<string, string>[]>;
|
|
765
|
+
/**
|
|
766
|
+
* Validates an Excel file configuration.
|
|
767
|
+
*/
|
|
768
|
+
declare const validateExcelConfig: (config: ExcelExtractionConfig) => void;
|
|
769
|
+
/**
|
|
770
|
+
* Finds all matching configurations for a given filename.
|
|
771
|
+
*/
|
|
772
|
+
declare const findAllMatchingConfigs: (filename: string, configs: ExcelExtractionConfig[]) => ExcelExtractionConfig[];
|
|
773
|
+
/**
|
|
774
|
+
* Creates an async generator from Excel data.
|
|
775
|
+
*/
|
|
776
|
+
declare function createExcelGenerator(data: Record<string, string>[]): AsyncGenerator<Record<string, any>, void, unknown>;
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Builder pattern for creating Excel configurations.
|
|
780
|
+
*
|
|
781
|
+
* Sensible defaults:
|
|
782
|
+
* - fileNameValidator: accepts all files
|
|
783
|
+
* - fileNameVariablesExtractor: extracts nothing
|
|
784
|
+
* - replicationMethod: FULL_TABLE
|
|
785
|
+
*/
|
|
786
|
+
declare class ExcelExtractionConfigBuilder {
|
|
787
|
+
private config;
|
|
788
|
+
static create(): ExcelExtractionConfigBuilder;
|
|
789
|
+
extension(ext: string): ExcelExtractionConfigBuilder;
|
|
790
|
+
tableName(name: string | ((fileName: string, workbook?: WorkBook, variables?: {
|
|
791
|
+
[key: string]: string | undefined;
|
|
792
|
+
}) => string)): ExcelExtractionConfigBuilder;
|
|
793
|
+
fileValidator(validator: (filename: string) => boolean): ExcelExtractionConfigBuilder;
|
|
794
|
+
variablesExtractor(extractor: (filename: string, workbook?: WorkBook) => {
|
|
795
|
+
[key: string]: string | undefined;
|
|
796
|
+
}): ExcelExtractionConfigBuilder;
|
|
797
|
+
replicationMethod(method: ReplicationMethod): ExcelExtractionConfigBuilder;
|
|
798
|
+
columns(cols: {
|
|
799
|
+
[key: string]: ExcelFieldSpec;
|
|
800
|
+
}): ExcelExtractionConfigBuilder;
|
|
801
|
+
singleSheet(sheetName?: string, skipRows?: number): ExcelExtractionConfigBuilder;
|
|
802
|
+
processor(processorFn: (workbook: WorkBook) => Promise<Record<string, string>[]>): ExcelExtractionConfigBuilder;
|
|
803
|
+
build(): ExcelExtractionConfig;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* Async generator that yields parsed rows from a CSV file.
|
|
808
|
+
* Supports custom separators, encoding, BOM stripping, and field transformers.
|
|
809
|
+
*/
|
|
810
|
+
declare function rowGeneratorFromCsv(path: string, fileConfig: CsvFileConfig): AsyncGenerator<Record<string, any>>;
|
|
811
|
+
/**
|
|
812
|
+
* Validates CSV header row against expected configuration.
|
|
813
|
+
*/
|
|
814
|
+
declare const checkCsvHeaderRow: (path: string, fileConfig: CsvFileConfig) => Promise<void>;
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* Writes an array of objects directly to a CSV file.
|
|
818
|
+
*/
|
|
819
|
+
declare const writeDataToCsv: (fileName: string, data: any[]) => Promise<void>;
|
|
820
|
+
/**
|
|
821
|
+
* Writes data from an async generator to CSV with batch writing (10k row batches).
|
|
822
|
+
*/
|
|
823
|
+
declare const writeGeneratorToCSV: (generator: AsyncGenerator, outputFileName: string) => Promise<number>;
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Builder pattern for creating CSV configurations.
|
|
827
|
+
*
|
|
828
|
+
* Usage:
|
|
829
|
+
* ```ts
|
|
830
|
+
* const config = CsvExtractionConfigBuilder.create()
|
|
831
|
+
* .separator(";")
|
|
832
|
+
* .encoding("latin1")
|
|
833
|
+
* .addSyncedAtColumn()
|
|
834
|
+
* .fieldsFromDict({
|
|
835
|
+
* "Product ID": { key: "product_id", type: "STRING" },
|
|
836
|
+
* "Product Name": { key: "product_name", type: "STRING" },
|
|
837
|
+
* "Price": { key: "price", type: "FLOAT" },
|
|
838
|
+
* })
|
|
839
|
+
* .build();
|
|
840
|
+
* ```
|
|
841
|
+
*/
|
|
842
|
+
declare class CsvExtractionConfigBuilder {
|
|
843
|
+
private _separator;
|
|
844
|
+
private _encoding?;
|
|
845
|
+
private _addSyncedAtColumn?;
|
|
846
|
+
private _fields?;
|
|
847
|
+
private _fieldsMode?;
|
|
848
|
+
private _replicationMethod?;
|
|
849
|
+
private _primaryKeys?;
|
|
850
|
+
static create(): CsvExtractionConfigBuilder;
|
|
851
|
+
separator(sep: string): CsvExtractionConfigBuilder;
|
|
852
|
+
encoding(enc: string): CsvExtractionConfigBuilder;
|
|
853
|
+
addSyncedAtColumn(enabled?: boolean): CsvExtractionConfigBuilder;
|
|
854
|
+
fieldsFromDict(mapping: {
|
|
855
|
+
[header: string]: {
|
|
856
|
+
key: string;
|
|
857
|
+
valueTransformer?: (val: any) => string;
|
|
858
|
+
type: FieldType;
|
|
859
|
+
};
|
|
860
|
+
}): CsvExtractionConfigBuilder;
|
|
861
|
+
fieldsFromArray(fields: Array<{
|
|
862
|
+
key: string;
|
|
863
|
+
valueTransformer?: (val: any) => string;
|
|
864
|
+
type: FieldType;
|
|
865
|
+
}>): CsvExtractionConfigBuilder;
|
|
866
|
+
replicationMethod(method: ReplicationMethod): CsvExtractionConfigBuilder;
|
|
867
|
+
primaryKeys(keys: string[]): CsvExtractionConfigBuilder;
|
|
868
|
+
build(): CsvFileConfig;
|
|
869
|
+
buildStreamConfig(streamId: string): FileStreamConfig;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* FileStream bridges file processing (Excel/CSV) into the connector SDK pipeline.
|
|
874
|
+
*
|
|
875
|
+
* It extends Stream so it integrates with the standard Tap -> Stream -> Target flow.
|
|
876
|
+
* Each FileStream reads one file with one config and yields records.
|
|
877
|
+
*/
|
|
878
|
+
declare class FileStream extends Stream<Record<string, any>, FileStreamConfig> {
|
|
879
|
+
private localFilePaths;
|
|
880
|
+
constructor(config: FileStreamConfig, localFilePath: string | string[], tapState: InputTapState, target: ITarget);
|
|
881
|
+
/**
|
|
882
|
+
* Build JSON Schema from the file config's field definitions.
|
|
883
|
+
*/
|
|
884
|
+
getSchema(): Promise<Schema | undefined>;
|
|
885
|
+
/**
|
|
886
|
+
* Yield records from all file(s).
|
|
887
|
+
* When multiple file paths are provided, records are yielded sequentially from each file.
|
|
888
|
+
*/
|
|
889
|
+
_getRecords(): AsyncIterable<Record<string, any>>;
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Create a FileStreamConfig from an ExcelExtractionConfig.
|
|
893
|
+
* Handles both single-sheet-extraction and processor config types.
|
|
894
|
+
*
|
|
895
|
+
* For single-sheet configs, primary keys are extracted from column definitions.
|
|
896
|
+
* For processor configs, primary keys default to an empty array.
|
|
897
|
+
*
|
|
898
|
+
* @param excelConfig - The Excel extraction config (single-sheet or processor)
|
|
899
|
+
* @param fileName - The base filename (used for variable extraction and table name resolution)
|
|
900
|
+
* @param localFilePath - Optional local file path; required for processor configs with dynamic table names
|
|
901
|
+
*/
|
|
902
|
+
declare function createExcelStreamConfig(excelConfig: ExcelExtractionConfig, fileName: string, localFilePath?: string): FileStreamConfig;
|
|
903
|
+
/**
|
|
904
|
+
* Create a FileStreamConfig from a CsvFileConfig.
|
|
905
|
+
*
|
|
906
|
+
* By default, uses FULL_TABLE replication and extracts all field keys as composite primary keys.
|
|
907
|
+
* Override via the options parameter.
|
|
908
|
+
*
|
|
909
|
+
* @param streamId - The stream/table name
|
|
910
|
+
* @param csvConfig - The CSV file configuration
|
|
911
|
+
* @param options - Optional overrides for replicationMethod and primaryKeys
|
|
912
|
+
*/
|
|
913
|
+
declare function createCsvStreamConfig(streamId: string, csvConfig: CsvFileConfig, options?: {
|
|
914
|
+
replicationMethod?: ReplicationMethod;
|
|
915
|
+
primaryKeys?: string[];
|
|
916
|
+
}): FileStreamConfig;
|
|
917
|
+
/**
|
|
918
|
+
* Process an array of FileStreamEntry sequentially, then signal completion to the target.
|
|
919
|
+
*
|
|
920
|
+
* This is the recommended pattern for SFTP and similar multi-file ingestion flows
|
|
921
|
+
* where FileTap isn't needed.
|
|
922
|
+
*
|
|
923
|
+
* @param entries - Array of { config, filePath } pairs
|
|
924
|
+
* @param tapState - The tap state (typically `{ bookmarks: {} }`)
|
|
925
|
+
* @param target - The target (e.g. BigQueryTarget)
|
|
926
|
+
*/
|
|
927
|
+
declare function processFileStreams(entries: FileStreamEntry[], tapState: InputTapState, target: ITarget): Promise<void>;
|
|
928
|
+
|
|
929
|
+
interface FileTapConfig {
|
|
930
|
+
[key: string]: any;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* FileTap orchestrates multiple FileStreams.
|
|
934
|
+
*
|
|
935
|
+
* It extends Tap so it integrates with the standard Tap -> Stream -> Target flow.
|
|
936
|
+
* Provide file stream entries (config + file path pairs), and it creates a FileStream per entry.
|
|
937
|
+
*
|
|
938
|
+
* For simple sequential file processing without the Tap lifecycle, use processFileStreams() instead.
|
|
939
|
+
*/
|
|
940
|
+
declare class FileTap extends Tap<FileTapConfig> {
|
|
941
|
+
private entries;
|
|
942
|
+
constructor(target: ITarget, config: FileTapConfig, stateProvider: StateProvider, entries: FileStreamEntry[]);
|
|
943
|
+
/**
|
|
944
|
+
* Convenience constructor for the common case where all configs share the same file path.
|
|
945
|
+
*/
|
|
946
|
+
static fromConfigs(target: ITarget, config: FileTapConfig, stateProvider: StateProvider, fileConfigs: FileStreamConfig[], sharedFilePath: string): FileTap;
|
|
947
|
+
init(): Promise<void>;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/**
|
|
951
|
+
* Variable extraction utilities for common filename patterns.
|
|
952
|
+
*/
|
|
953
|
+
declare class VariableExtractors {
|
|
954
|
+
/**
|
|
955
|
+
* Returns the filename as a variable.
|
|
956
|
+
*/
|
|
957
|
+
static filename(): (filename: string) => {
|
|
958
|
+
[key: string]: string | undefined;
|
|
959
|
+
};
|
|
960
|
+
/**
|
|
961
|
+
* Extracts named capture groups from a regex pattern.
|
|
962
|
+
*/
|
|
963
|
+
static regex(pattern: RegExp): (filename: string) => {
|
|
964
|
+
[key: string]: string | undefined;
|
|
965
|
+
};
|
|
966
|
+
/**
|
|
967
|
+
* Combines multiple extraction functions.
|
|
968
|
+
*/
|
|
969
|
+
static combine(...extractors: ((filename: string) => {
|
|
970
|
+
[key: string]: string | undefined;
|
|
971
|
+
})[]): (filename: string) => {
|
|
972
|
+
[key: string]: string | undefined;
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* File pattern utilities for common filename validation patterns.
|
|
977
|
+
*/
|
|
978
|
+
declare class FilePatterns {
|
|
979
|
+
/**
|
|
980
|
+
* Creates a validator for files starting with a specific prefix (case-insensitive).
|
|
981
|
+
*/
|
|
982
|
+
static startsWith(prefix: string): (filename: string) => boolean;
|
|
983
|
+
/**
|
|
984
|
+
* Creates a validator for files matching a regex pattern.
|
|
985
|
+
*/
|
|
986
|
+
static regex(pattern: RegExp): (filename: string) => boolean;
|
|
987
|
+
/**
|
|
988
|
+
* Combines multiple validators with AND logic.
|
|
989
|
+
*/
|
|
990
|
+
static and(...validators: ((filename: string) => boolean)[]): (filename: string) => boolean;
|
|
991
|
+
/**
|
|
992
|
+
* Combines multiple validators with OR logic.
|
|
993
|
+
*/
|
|
994
|
+
static or(...validators: ((filename: string) => boolean)[]): (filename: string) => boolean;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
* Pre-instantiated SFTP client singleton.
|
|
999
|
+
* @deprecated Prefer creating your own SftpClient instance for better lifecycle control.
|
|
1000
|
+
*/
|
|
1001
|
+
declare const SftpService: Client;
|
|
1002
|
+
|
|
1003
|
+
interface CloudStorageServiceOptions {
|
|
1004
|
+
processedSuffix?: string;
|
|
1005
|
+
supportedExtensions?: string[];
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* Service for interacting with Google Cloud Storage.
|
|
1009
|
+
* Supports file download, upload, listing, and marker-file-based processing tracking.
|
|
1010
|
+
*/
|
|
1011
|
+
declare class CloudStorageService {
|
|
1012
|
+
private storage;
|
|
1013
|
+
private bucket;
|
|
1014
|
+
private processedSuffix;
|
|
1015
|
+
private supportedExtensions;
|
|
1016
|
+
private path;
|
|
1017
|
+
constructor(bucketName: string, path?: string, opts?: CloudStorageServiceOptions);
|
|
1018
|
+
/**
|
|
1019
|
+
* Lists all files in the bucket with an optional prefix.
|
|
1020
|
+
*/
|
|
1021
|
+
listFiles(prefix?: string): Promise<string[]>;
|
|
1022
|
+
/**
|
|
1023
|
+
* Returns files that haven't been marked as processed.
|
|
1024
|
+
* Filters by supported extensions if configured.
|
|
1025
|
+
*/
|
|
1026
|
+
getUnprocessedFiles(): Promise<string[]>;
|
|
1027
|
+
/**
|
|
1028
|
+
* Creates a marker file to indicate a file has been processed.
|
|
1029
|
+
*/
|
|
1030
|
+
createMarkerFile(fileName: string): Promise<void>;
|
|
1031
|
+
/**
|
|
1032
|
+
* Downloads a file from GCS to a local tmp directory.
|
|
1033
|
+
* Returns the local path of the downloaded file.
|
|
1034
|
+
*/
|
|
1035
|
+
downloadFile(filePath: string, fileName: string): Promise<string>;
|
|
1036
|
+
/**
|
|
1037
|
+
* Uploads a local file to GCS.
|
|
1038
|
+
*/
|
|
1039
|
+
uploadFile(localPath: string, destPath: string): Promise<File>;
|
|
1040
|
+
/**
|
|
1041
|
+
* Reads a GCS object and returns its contents as a UTF-8 string.
|
|
1042
|
+
*/
|
|
1043
|
+
readObjectAsString(objectPath: string): Promise<string>;
|
|
1044
|
+
/**
|
|
1045
|
+
* Writes a string to a GCS object with JSON content type.
|
|
1046
|
+
*/
|
|
1047
|
+
writeStringObject(objectPath: string, contents: string): Promise<void>;
|
|
1048
|
+
/**
|
|
1049
|
+
* Uploads a local file to the bucket with a unique name based on prefix, streamId, and UUID.
|
|
1050
|
+
* Returns the GCS File reference.
|
|
1051
|
+
*/
|
|
1052
|
+
uploadFileWithUniqueName(filePath: string, prefix: string, streamId: string): Promise<File>;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* Extract a ZIP (or other archive) file to a target directory.
|
|
1057
|
+
* Uses the `decompress` library which supports zip, tar, gz, bz2, etc.
|
|
1058
|
+
*
|
|
1059
|
+
* @param zipFilePath - Path to the archive file
|
|
1060
|
+
* @param extractedPath - Directory to extract into (created if it doesn't exist)
|
|
1061
|
+
* @returns The output directory path
|
|
1062
|
+
*/
|
|
1063
|
+
declare const unzip: (zipFilePath: string, extractedPath: string) => Promise<string>;
|
|
1064
|
+
|
|
611
1065
|
interface BigQueryConfig extends BaseConfig {
|
|
612
1066
|
schema: string;
|
|
613
1067
|
project_id: string;
|
|
@@ -632,6 +1086,7 @@ declare class BigQueryDBSync extends StreamWarehouseSyncService {
|
|
|
632
1086
|
getWarehouseTypeFromJSONSchema: (definition: JSONSchemaFieldDefinition) => string;
|
|
633
1087
|
getMergeQueries: () => string[];
|
|
634
1088
|
getReplaceQueries: () => string[];
|
|
1089
|
+
getAppendQueries: () => string[];
|
|
635
1090
|
createDatabaseAndSchemaIfNotExists: (retryCount: number) => Promise<void>;
|
|
636
1091
|
createTable: () => Promise<void>;
|
|
637
1092
|
addColumns: (tableFields: InternalTableField[]) => Promise<void>;
|
|
@@ -669,10 +1124,11 @@ declare class BigQueryTarget extends ITarget<BigQueryConfig> {
|
|
|
669
1124
|
declare class GCSStateProvider implements StateProvider {
|
|
670
1125
|
private bucketName;
|
|
671
1126
|
private connectorId;
|
|
1127
|
+
private service;
|
|
672
1128
|
constructor(connectorId: string, bucketName: string);
|
|
673
1129
|
private getObjectPath;
|
|
674
1130
|
getState(): Promise<StateHolder>;
|
|
675
1131
|
writeState(state: string): Promise<void>;
|
|
676
1132
|
}
|
|
677
1133
|
|
|
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 };
|
|
1134
|
+
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, 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 };
|