@whaly/connector-sdk 0.1.0 → 0.2.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/dist/index.d.mts CHANGED
@@ -1,26 +1,90 @@
1
- import winston from 'winston';
1
+ import { AxiosInstance, AxiosRequestHeaders, AxiosResponse, AxiosRequestConfig, AxiosError } from 'axios';
2
2
  import { Validator, ValidationError } from 'jsonschema';
3
- import moment from 'moment';
3
+ import { Dayjs } from 'dayjs';
4
4
  import { WriteStream } from 'fs';
5
- import { AxiosInstance, AxiosRequestHeaders, AxiosResponse, AxiosRequestConfig, AxiosError } from 'axios';
5
+ import { BigQuery, Dataset, Table } from '@google-cloud/bigquery';
6
6
 
7
- interface StreamRelationship {
8
- left: StreamId;
9
- right: StreamId;
10
- from: string;
11
- to: string;
12
- type: "1-1" | "1-N" | "N-1";
7
+ declare const loadJson: (fileName: string) => any;
8
+ declare const loadSchema: (streamId: string) => any;
9
+
10
+ declare const getAxiosInstance: (retryCount?: number) => AxiosInstance;
11
+ interface GetConfig {
12
+ qs?: {
13
+ [key: string]: any;
14
+ };
15
+ headers?: AxiosRequestHeaders;
16
+ retryCount?: number;
13
17
  }
14
- interface DirectionalRelationship {
15
- type: "1-N" | "N-1" | "1-1";
16
- streamId: StreamId;
17
- from: string;
18
- to: string;
18
+ declare const getRawJSONApiCall: <T>(endpoint: string, config: GetConfig, privateLogging?: boolean) => Promise<AxiosResponse<T>>;
19
+ declare const getJSONApiCallWithFullResponse: <T>(endpoint: string, config: GetConfig, privateLogging?: boolean) => Promise<AxiosResponse<any, any, {}>>;
20
+ declare const getJSONApiCall: <T>(endpoint: string, config: GetConfig, privateLogging?: boolean) => Promise<T>;
21
+ declare const getDownloadFileApiCall: <T>(endpoint: string, config: GetConfig, output: string, privateLogging?: boolean) => Promise<{
22
+ outputDir: string;
23
+ }>;
24
+ interface PostConfig {
25
+ qs?: {
26
+ [key: string]: any;
27
+ };
28
+ headers?: AxiosRequestHeaders;
29
+ retryCount?: number;
19
30
  }
20
- interface DirectionalRelationships {
21
- left: DirectionalRelationship[];
22
- right: DirectionalRelationship[];
31
+ declare const postJSONApiCall: <T>(endpoint: string, config: PostConfig, payload: any) => Promise<T>;
32
+ declare const postFormDataApiCall: <T>(endpoint: string, config: PostConfig, payload: any) => Promise<T>;
33
+ declare const postUrlEncodedApiCall: (endpoint: string, config: PostConfig, payload: any) => Promise<any>;
34
+
35
+ declare const BATCH_INTERVAL_MS = 100;
36
+ declare const logger: {
37
+ info: (message: string | any, ...args: any[]) => void;
38
+ error: (message: string | any, ...args: any[]) => void;
39
+ debug: (message: string | any, ...args: any[]) => void;
40
+ warn: (message: string | any, ...args: any[]) => void;
41
+ closeWinston: (cb: () => void) => void;
42
+ };
43
+
44
+ declare const ALL_STREAM_ID_KEYWORD = "all";
45
+ declare const ROWS_SYNCED_METRIC_NAME = "rows_synced_count";
46
+ declare const API_CALLS_METRIC_NAME = "api_calls_count";
47
+ declare const EXECUTION_TIME_METRIC_NAME = "execution_time_ms";
48
+ interface MetricConfiguration {
49
+ isEnabled: () => boolean;
50
+ getStreamIds?: () => string[];
23
51
  }
52
+ declare const getCounterMetrics: (name: string, streamIds: string[]) => CounterMetric[];
53
+ declare const getCounterMetric: (name: string, streamId?: string) => CounterMetric;
54
+ declare const getAllMetrics: () => CounterMetric[];
55
+ declare class CounterMetric {
56
+ private value;
57
+ name: string;
58
+ streamId: string;
59
+ constructor(name: string, streamId: string);
60
+ increment(inc?: number): void;
61
+ getStreamId(): string;
62
+ getName(): string;
63
+ getValue(): number;
64
+ }
65
+
66
+ declare const printMemoryFootprint: (prefix: string) => void;
67
+
68
+ type ErrorType = "unauthorized" | "unknown";
69
+
70
+ declare const haltAndCatchFire: (errorType: ErrorType, errorText: string, errorDebugText: string) => Promise<void>;
71
+
72
+ declare function gracefulExit(exitCode: number): Promise<void>;
73
+
74
+ declare enum ReplicationMethod {
75
+ INCREMENTAL = "INCREMENTAL",
76
+ FULL_TABLE = "FULL_TABLE"
77
+ }
78
+
79
+ interface HTTPHeaders {
80
+ [headerName: string]: any;
81
+ }
82
+ interface URLParams {
83
+ [paramName: string]: any;
84
+ }
85
+ type HTTPMethod = "GET" | "POST";
86
+
87
+ type StreamId = string;
24
88
 
25
89
  interface PropertiesMetadata {
26
90
  [propName: string]: {
@@ -70,7 +134,6 @@ declare class SchemaMessage implements Message {
70
134
  displayLabel: string | undefined;
71
135
  description: string | undefined;
72
136
  propertiesMetadata: PropertiesMetadata | undefined;
73
- relationships: DirectionalRelationships;
74
137
  constructor(opts: {
75
138
  stream: StreamId;
76
139
  schema: any;
@@ -78,7 +141,6 @@ declare class SchemaMessage implements Message {
78
141
  bookmarkProperties?: string[];
79
142
  displayLabel?: string;
80
143
  description?: string;
81
- relationships: DirectionalRelationships;
82
144
  propertiesMetadata?: PropertiesMetadata | undefined;
83
145
  });
84
146
  toString(): string;
@@ -94,26 +156,6 @@ interface TargetSchemaHook {
94
156
  writeSchema: (input: TargetSchemaHookInput) => Promise<void>;
95
157
  }
96
158
 
97
- type ErrorType = "unauthorized" | "unknown";
98
-
99
- declare abstract class Resolver {
100
- constructor();
101
- abstract checkIfCanSync(): Promise<boolean>;
102
- abstract markSyncStarted(): Promise<void>;
103
- abstract startVPNIfNeeded(): Promise<void>;
104
- abstract getConfig(command: ShoreCommand): Promise<ShoreConfig>;
105
- abstract writeCatalog(catalog: CatalogFile): Promise<void>;
106
- abstract writeState(state: string): Promise<void>;
107
- abstract markSyncFailed(): Promise<void>;
108
- abstract markSyncComplete(): Promise<void>;
109
- abstract markDiscoveryComplete(): Promise<void>;
110
- abstract flushMetrics(): Promise<void>;
111
- abstract onError(errorType: ErrorType, errorText: string, errorDebugText: string): Promise<void>;
112
- abstract getSchemaHooks(): TargetSchemaHook[];
113
- abstract updateSourceValue(optionKey: string, optionValue: string): Promise<void>;
114
- abstract getLogFormat(): winston.Logform.Format;
115
- }
116
-
117
159
  interface FlattenedSchema {
118
160
  [unsafePropertyName: string]: JSONSchemaFieldDefinition;
119
161
  }
@@ -140,8 +182,9 @@ interface StreamWithTempFile {
140
182
  tempFile: TempFile;
141
183
  }
142
184
  interface BaseConfig {
143
- schema: string;
185
+ connector_id: string;
144
186
  database: string;
187
+ schema: string;
145
188
  }
146
189
 
147
190
  interface ColumnMappingStoreUnsafeToSafe {
@@ -216,7 +259,7 @@ declare class StreamState$1 {
216
259
  streamId: StreamId;
217
260
  schema?: FlattenedSchema;
218
261
  dbSync: StreamWarehouseSyncService;
219
- batchDate: moment.Moment;
262
+ batchDate: Dayjs;
220
263
  batchedRowCount: number;
221
264
  fileToLoad: TempFile;
222
265
  syncedRowCount: number;
@@ -239,11 +282,19 @@ declare class StreamState$1 {
239
282
  setHasBeenLoadedYet(): void;
240
283
  }
241
284
 
285
+ interface StateHolder {
286
+ state?: any;
287
+ }
288
+ interface StateProvider {
289
+ getState(): Promise<StateHolder>;
290
+ writeState(state: string): Promise<void>;
291
+ }
292
+
242
293
  declare abstract class ITarget<C extends BaseConfig = BaseConfig> {
243
294
  config: C;
244
295
  schemaHooks: TargetSchemaHook[];
245
- resolver: Resolver;
246
- syncTime: moment.Moment;
296
+ syncTime: Dayjs;
297
+ stateProvider: StateProvider;
247
298
  batchedState: any;
248
299
  flushedState: any;
249
300
  renameColumnStore: RenameColumnStore;
@@ -251,7 +302,7 @@ declare abstract class ITarget<C extends BaseConfig = BaseConfig> {
251
302
  [streamName: string]: StreamState$1;
252
303
  };
253
304
  validator: Validator;
254
- constructor(config: C, resolver: Resolver);
305
+ constructor(config: C, stateProvider: StateProvider);
255
306
  static requiredConfigKeys: string[];
256
307
  abstract newDBSyncInstance: (streamId: StreamId, database: string, schema: string, table: string) => StreamWarehouseSyncService;
257
308
  abstract genTableName: (streamId: string) => string;
@@ -273,165 +324,6 @@ declare abstract class ITarget<C extends BaseConfig = BaseConfig> {
273
324
  static uploadSingleStreamToWarehouse: (streamState: StreamState$1) => Promise<void>;
274
325
  }
275
326
 
276
- type ReplicationMethod = "INCREMENTAL" | "FULL_TABLE" | "LOG_BASED";
277
- type SyncFunction<C> = (target: ITarget, catalogStream: CatalogStream, config: C, catalog: Catalog) => Promise<void>;
278
- type SourceType = `HUBSPOT` | `LAGROWTHMACHINE` | `SEGMENT` | `COHORT` | `AIRTABLE` | `AIRTABLE_OAUTH` | `BUBBLE` | `PIPEDRIVE` | `LINKEDIN_ADS` | `FACEBOOK_ADS` | `SEGMENT` | `SALESFORCE` | `SALESFORCE_SANDBOX` | `RECRUITCRM` | `GOOGLE_SHEETS` | `GOOGLE_ADS` | `GOOGLE_ANALYTICS` | `SLACK` | `STRIPE` | `ORBIT` | `GITHUB_STARS` | `JAFFLE_SHOP` | `POSTGRES` | `PENNYLANE` | `PENNYLANE_REDSHIFT` | `AIRCALL` | `AIRCALL_OAUTH` | `FAST_POSTGRES_FULL_TABLE` | `WOOCOMMERCE`;
279
- type DestinationType = `GOOGLE_BIGQUERY` | `SNOWFLAKE`;
280
- interface ShoreConfig {
281
- command: ShoreCommand;
282
- destination: DestinationType;
283
- config: any;
284
- targetConfig: any;
285
- state?: any;
286
- catalog?: CatalogFile;
287
- }
288
- type ShoreCommand = "READ" | "DISCOVER";
289
- type ResolverType = "WHALY" | "LOCAL";
290
-
291
- type InclusionMode = "available" | "automatic" | "unsupported";
292
- interface MetadataEntry {
293
- selected?: boolean;
294
- "replication-method"?: ReplicationMethod;
295
- "replication-key"?: string;
296
- "view-key-properties"?: string[];
297
- "inclusion"?: InclusionMode;
298
- "selected-by-default"?: boolean;
299
- "valid-replication-keys"?: string[];
300
- "forced-replication-method"?: ReplicationMethod;
301
- "forced-replication-key"?: string;
302
- "table-key-properties"?: string[];
303
- "schema-name"?: string;
304
- "is-view"?: boolean;
305
- "row-count"?: number;
306
- "database-name"?: string;
307
- "sql-datatype"?: string;
308
- "whaly-display-label"?: string;
309
- "whaly-description"?: string;
310
- "whaly-parent-stream"?: StreamId;
311
- }
312
- interface CatalogMetadata {
313
- breadcrumb: string[];
314
- metadata: MetadataEntry;
315
- }
316
- declare class MetadataMap extends Map<string[], MetadataEntry> {
317
- private areEquals;
318
- private findExistingEntry;
319
- get(key: string[]): MetadataEntry | undefined;
320
- set(key: string[], value: MetadataEntry): this;
321
- }
322
- declare class StreamMetadata {
323
- metadataByBreadcrumb: MetadataMap;
324
- constructor();
325
- fromCatalogStreamMetadata(metadataArr: CatalogMetadata[]): this;
326
- toString(): MetadataMap;
327
- get(breadcrumb: string[]): MetadataEntry | undefined;
328
- write(breadcrumb: string[], key: string, value: any): this;
329
- private getRootBreadcrumbMetadata;
330
- isStreamSelected(): boolean;
331
- getKeyProperties(): string[];
332
- getReplicationKey(): string | undefined;
333
- getReplicationMethod(): ReplicationMethod | undefined;
334
- getForcedReplicationMethod(): ReplicationMethod | undefined;
335
- toList(): CatalogMetadata[];
336
- }
337
-
338
- type StreamId = string;
339
- type StreamName = string;
340
- interface CatalogStream {
341
- tap_stream_id: StreamId;
342
- stream: StreamName;
343
- schema: any;
344
- metadata: CatalogMetadata[];
345
- }
346
- interface CatalogFile {
347
- streams: CatalogStream[];
348
- }
349
- declare class Catalog {
350
- streams?: CatalogStream[];
351
- static fromFile(fileName: string): Catalog;
352
- static fromCatalogFile(catalogFile: CatalogFile): Catalog;
353
- getSelectedStreams(): CatalogStream[];
354
- }
355
-
356
- declare const writeStateFile: (resolver: Resolver, state: string) => Promise<void>;
357
- declare const writeCatalogFile: (resolver: Resolver, catalog: CatalogFile) => Promise<void>;
358
- declare const loadShoreConfig: (resolver: Resolver) => Promise<ShoreConfig>;
359
- declare const loadJson: (fileName: string) => any;
360
- declare const loadSchema: (streamId: string) => any;
361
- declare const checkRequiredConfigKeys: (args: any, requiredConfigKeys: string[]) => void;
362
-
363
- declare const getAxiosInstance: (retryCount?: number) => AxiosInstance;
364
- interface GetConfig {
365
- qs?: {
366
- [key: string]: any;
367
- };
368
- headers?: AxiosRequestHeaders;
369
- retryCount?: number;
370
- }
371
- declare const getRawJSONApiCall: <T>(endpoint: string, config: GetConfig, privateLogging?: boolean) => Promise<AxiosResponse<T>>;
372
- declare const getJSONApiCallWithFullResponse: <T>(endpoint: string, config: GetConfig, privateLogging?: boolean) => Promise<AxiosResponse<any, any, {}>>;
373
- declare const getJSONApiCall: <T>(endpoint: string, config: GetConfig, privateLogging?: boolean) => Promise<T>;
374
- declare const getDownloadFileApiCall: <T>(endpoint: string, config: GetConfig, output: string, privateLogging?: boolean) => Promise<{
375
- outputDir: string;
376
- }>;
377
- interface PostConfig {
378
- qs?: {
379
- [key: string]: any;
380
- };
381
- headers?: AxiosRequestHeaders;
382
- retryCount?: number;
383
- }
384
- declare const postJSONApiCall: <T>(endpoint: string, config: PostConfig, payload: any) => Promise<T>;
385
- declare const postFormDataApiCall: <T>(endpoint: string, config: PostConfig, payload: any) => Promise<T>;
386
- declare const postUrlEncodedApiCall: (endpoint: string, config: PostConfig, payload: any) => Promise<any>;
387
-
388
- declare const BATCH_INTERVAL_MS = 100;
389
- declare const logger: {
390
- info: (message: string | any, ...args: any[]) => void;
391
- error: (message: string | any, ...args: any[]) => void;
392
- debug: (message: string | any, ...args: any[]) => void;
393
- warn: (message: string | any, ...args: any[]) => void;
394
- closeWinston: (cb: () => void) => void;
395
- };
396
-
397
- declare const ALL_STREAM_ID_KEYWORD = "all";
398
- declare const ROWS_SYNCED_METRIC_NAME = "rows_synced_count";
399
- declare const API_CALLS_METRIC_NAME = "api_calls_count";
400
- declare const EXECUTION_TIME_METRIC_NAME = "execution_time_ms";
401
- interface MetricConfiguration {
402
- isEnabled: () => boolean;
403
- getStreamIds?: () => string[];
404
- }
405
- declare const getCounterMetrics: (name: string, streamIds: string[]) => CounterMetric[];
406
- declare const getCounterMetric: (name: string, streamId?: string) => CounterMetric;
407
- declare const getAllMetrics: () => CounterMetric[];
408
- declare class CounterMetric {
409
- private value;
410
- name: string;
411
- streamId: string;
412
- constructor(name: string, streamId: string);
413
- increment(inc?: number): void;
414
- getStreamId(): string;
415
- getName(): string;
416
- getValue(): number;
417
- }
418
-
419
- declare const printMemoryFootprint: (prefix: string) => void;
420
-
421
- declare const haltAndCatchFire: (errorType: ErrorType, errorText: string, errorDebugText: string) => Promise<void>;
422
-
423
- declare function gracefulExit(exitCode: number): Promise<void>;
424
-
425
- declare const findRelatedRelationships: (streamId: StreamId, allRels: StreamRelationship[]) => DirectionalRelationships;
426
-
427
- interface HTTPHeaders {
428
- [headerName: string]: any;
429
- }
430
- interface URLParams {
431
- [paramName: string]: any;
432
- }
433
- type HTTPMethod = "GET" | "POST";
434
-
435
327
  interface InputTapState {
436
328
  bookmarks?: {
437
329
  [streamId: string]: StreamState;
@@ -474,11 +366,9 @@ declare class StateService {
474
366
  bookmarks: Bookmarks;
475
367
  constructor();
476
368
  static getInstance(): StateService;
477
- setBookmark(streamId: StreamId, ts: moment.Moment): void;
478
- setBookmarkV2(streamId: StreamId, streamState: StreamState): void;
479
- setBookmarkSignpostV2(streamId: StreamId, signpostValue: string): void;
480
- getBookmark(streamId: StreamId): moment.Moment;
481
- getBookmarkV2(streamId: StreamId): StreamState;
369
+ setBookmark(streamId: StreamId, streamState: StreamState): void;
370
+ setBookmarkSignpost(streamId: StreamId, signpostValue: string): void;
371
+ getBookmark(streamId: StreamId): StreamState;
482
372
  clearState(): void;
483
373
  get(): State;
484
374
  forwardStateToTarget(target: ITarget): Promise<void>;
@@ -499,13 +389,11 @@ declare class Authenticator<C> {
499
389
  * C: Type of the tap configuration
500
390
  * P: For children Streams, this is the type of the parent
501
391
  */
502
- declare abstract class StreamV2<O = any, C = any, P = undefined> {
503
- _config: C;
504
- _tapName: string;
505
- _tapState: InputTapState;
506
- _target: ITarget;
507
- rootMetadataEntry: MetadataEntry | undefined;
508
- forcedReplicationMethod: ReplicationMethod | undefined;
392
+ declare abstract class Stream<O = any, C = any, P = undefined> {
393
+ config: C;
394
+ tapState: InputTapState;
395
+ target: ITarget;
396
+ replicationMethod: ReplicationMethod | undefined;
509
397
  selectedByDefault: boolean;
510
398
  STATE_MSG_FREQUENCY: number;
511
399
  streamId: StreamId;
@@ -513,17 +401,15 @@ declare abstract class StreamV2<O = any, C = any, P = undefined> {
513
401
  displayLabel: string | undefined;
514
402
  description: string | undefined;
515
403
  primaryKey: string[];
516
- forcedReplicationKey: string | undefined;
404
+ replicationKey: string | undefined;
517
405
  useStateFromStreamId: string | undefined;
518
- relationships: StreamRelationship[];
519
- children: StreamV2<any, any, O | O[]>[];
406
+ children: Stream<any, any, O | O[]>[];
520
407
  isSorted: boolean;
521
408
  isSilent: boolean;
522
409
  childConcurrency: number;
523
410
  rowsSyncedMetricsConf: MetricConfiguration;
524
411
  executionTimeMetricsConf: MetricConfiguration;
525
- constructor(tapName: string, config: C, state: InputTapState, target: ITarget, childConcurrency?: number);
526
- setRootMetadataEntry: (rootMetadataEntry: MetadataEntry) => void;
412
+ constructor(config: C, tapState: InputTapState, target: ITarget, childConcurrency?: number);
527
413
  /**
528
414
  * Sync this stream
529
415
  * Called only for streams with no parents, aka. "root tap streams"
@@ -560,17 +446,17 @@ declare abstract class StreamV2<O = any, C = any, P = undefined> {
560
446
  * or `start_date` config if set,
561
447
  * or the UNIX Epoch
562
448
  **/
563
- getStartingTimestamp(): moment.Moment;
449
+ getStartingTimestamp(): Dayjs;
564
450
  /**
565
451
  * Return the max allowable bookmark value for this stream's replication key.
566
452
  *
567
- * For timestamp-based replication keys, this defaults to `moment()`. For
453
+ * For timestamp-based replication keys, this defaults to `dayjs()`. For
568
454
  * non-timestamp replication keys, default to `undefined`.
569
455
  *
570
456
  * Override this value to prevent bookmarks from being advanced in cases where we
571
457
  * may only have a partial set of records.
572
458
  */
573
- getReplicationKeySignpost: () => Promise<moment.Moment | undefined>;
459
+ getReplicationKeySignpost: () => Promise<Dayjs | undefined>;
574
460
  /**
575
461
  * Return the default replication method for the stream that will be used to write the catalog.
576
462
  */
@@ -615,9 +501,9 @@ declare abstract class StreamV2<O = any, C = any, P = undefined> {
615
501
  * R: Type of the API result
616
502
  * NPT: Type of the "nextPageToken"
617
503
  */
618
- declare abstract class RESTStreamV2<R, O, NPT, C, P = undefined> extends StreamV2<O, C, P> {
504
+ declare abstract class RESTStream<R, O, NPT, C, P = undefined> extends Stream<O, C, P> {
619
505
  axiosInstance: AxiosInstance | undefined;
620
- constructor(tapName: string, config: C, state: InputTapState, target: ITarget, childConcurrency?: number);
506
+ constructor(config: C, state: InputTapState, target: ITarget, childConcurrency?: number);
621
507
  /**
622
508
  * Prepare an Axios request object.
623
509
  * Pagination information can be parsed from `nextPageToken` if `nextPageToken` is not undefined.
@@ -672,7 +558,7 @@ declare abstract class RESTStreamV2<R, O, NPT, C, P = undefined> extends StreamV
672
558
  * TODO: Make URL + Path templatisable and replace those with Extractor (or Tap) config
673
559
  * @returns
674
560
  */
675
- getUrl(parent?: P): string;
561
+ getNextUrl(previousToken?: NPT, parent?: P): string;
676
562
  /**
677
563
  * Parse the response and return an iterator of result rows.
678
564
  *
@@ -683,20 +569,20 @@ declare abstract class RESTStreamV2<R, O, NPT, C, P = undefined> extends StreamV
683
569
  }
684
570
 
685
571
  declare const DEFAULT_MAX_CONCURRENT_STREAMS = 5;
572
+ type SyncOptions = {
573
+ include?: string[];
574
+ exclude?: string[];
575
+ };
686
576
  declare abstract class Tap<C> {
687
- _target: ITarget;
688
- _config: C;
689
- _streams: StreamV2[];
690
- _concurrency: number;
577
+ target: ITarget;
578
+ config: C;
579
+ streams: Stream[];
580
+ concurrency: number;
581
+ stateProvider: StateProvider;
582
+ tapState: InputTapState;
691
583
  abstract init(): Promise<void>;
692
- abstract requiredConfigKeys(): string[];
693
- constructor(target: ITarget, config: C);
694
- discover: (existingCatalog: CatalogFile | undefined) => Promise<CatalogFile>;
695
- sync: (catalog: Catalog) => Promise<void>;
696
- generateMetadataFromStream(stream: StreamV2, parentStreamId: string | undefined): Promise<{
697
- metadata: CatalogMetadata[];
698
- }>;
699
- initiateSync(catalog: Catalog): Promise<void>;
584
+ constructor(target: ITarget, config: C, stateProvider: StateProvider);
585
+ sync: (options?: SyncOptions) => Promise<void>;
700
586
  end(): Promise<void>;
701
587
  }
702
588
 
@@ -722,4 +608,71 @@ declare const flattenSchema: <T>(streamId: StreamId, schema: T) => FlattenedSche
722
608
  declare const createTemporaryFileStream: (streamId: StreamId) => TempFile;
723
609
  declare function safePath(path: string): string;
724
610
 
725
- export { ALL_STREAM_ID_KEYWORD, API_CALLS_METRIC_NAME, Authenticator, BATCH_INTERVAL_MS, type BaseConfig, type Bookmark, type Bookmarks, Catalog, type CatalogFile, type CatalogMetadata, type CatalogStream, type ColumnMappingStoreUnsafeToSafe, CounterMetric, DEFAULT_MAX_CONCURRENT_STREAMS, type DestinationType, type DirectionalRelationship, type DirectionalRelationships, EXECUTION_TIME_METRIC_NAME, type ErrorType, type FlattenedSchema, type GetConfig, type HTTPHeaders, type HTTPMethod, ITarget, type InclusionMode, type InputTapState, type InternalTableField, type JSONSchemaFieldDefinition, type Message, type MessageType, type MetadataEntry, type MetricConfiguration, MissingFieldInSchemaError, MissingSchemaError, type PostConfig, type ProgressMarkers, type PropertiesMetadata, RESTStreamV2, ROWS_SYNCED_METRIC_NAME, RecordMessage, RenameColumnStore, type ReplicationMethod, ReplicationMethodMessage, Resolver, type ResolverType, type SafeColumnNameConverterFn, type Schema, SchemaMessage, SchemaValidationError, type ShoreCommand, type ShoreConfig, type SourceType, type State, StateMessage, StateService, type StreamId, StreamMetadata, type StreamName, type StreamRelationship, type StreamState, StreamV2, StreamWarehouseSyncService, type StreamWithTempFile, type SyncFunction, Tap, type TapState, type TargetSchemaHook, type TargetSchemaHookInput, type TempFile, type URLParams, type WarehouseTableField, _greaterThan, addWhalyFields, checkRequiredConfigKeys, createTemporaryFileStream, extractStateForStream, finalizeStateProgressMarkers, findRelatedRelationships, flattenSchema, getAllMetrics, getAxiosInstance, getCounterMetric, getCounterMetrics, getDownloadFileApiCall, getJSONApiCall, getJSONApiCallWithFullResponse, getRawJSONApiCall, gracefulExit, haltAndCatchFire, incrementStreamState, loadJson, loadSchema, loadShoreConfig, logger, postFormDataApiCall, postJSONApiCall, postUrlEncodedApiCall, printMemoryFootprint, removeParasiteProperties, safePath, writeCatalogFile, writeStateFile };
611
+ interface BigQueryConfig extends BaseConfig {
612
+ schema: string;
613
+ project_id: string;
614
+ loading_deck_gcs_bucket_name: string;
615
+ location?: BigqueryLocation;
616
+ }
617
+ type BigqueryLocation = "US" | "EU";
618
+
619
+ declare class BigQueryDBSync extends StreamWarehouseSyncService {
620
+ config: BigQueryConfig;
621
+ bqClient: BigQuery;
622
+ bqDataset: Dataset;
623
+ bqTable: Table;
624
+ bqStagingTable: Table;
625
+ tableName: string;
626
+ stagingTableName: string;
627
+ sqlTableId: string;
628
+ sqlStagingTableId: string;
629
+ constructor(config: BigQueryConfig, streamId: StreamId, database: string, schema: string, table: string, renameColumnStore: RenameColumnStore);
630
+ getSerializedRecord: (record: any) => string;
631
+ safeColumnName: (key: string) => string;
632
+ getWarehouseTypeFromJSONSchema: (definition: JSONSchemaFieldDefinition) => string;
633
+ getMergeQueries: () => string[];
634
+ getReplaceQueries: () => string[];
635
+ createDatabaseAndSchemaIfNotExists: (retryCount: number) => Promise<void>;
636
+ createTable: () => Promise<void>;
637
+ addColumns: (tableFields: InternalTableField[]) => Promise<void>;
638
+ createStagingArea: () => Promise<void>;
639
+ loadStreamInStagingArea: (localFilePath: string) => Promise<void>;
640
+ deleteStagingArea: () => Promise<void>;
641
+ getTablesInSchema: () => Promise<{
642
+ tableName: string;
643
+ }[]>;
644
+ getTableColumnsFromWarehouse: () => Promise<WarehouseTableField[]>;
645
+ runQueries: (queries: string[]) => Promise<void>;
646
+ /**
647
+ *
648
+ * Generate a TableField definition object that can be passed to BigQuery APIs to define a column on a table
649
+ *
650
+ * @param colName
651
+ * @param schemaFieldDefinition
652
+ * @returns
653
+ */
654
+ private getBigqueryTableFieldFromInternalSchemaFieldDefinition;
655
+ private generateBigquerySchema;
656
+ private loadGCSFileInTable;
657
+ }
658
+
659
+ declare class BigQueryTarget extends ITarget<BigQueryConfig> {
660
+ constructor(config: BigQueryConfig, stateProvider: StateProvider);
661
+ static requiredConfigKeys: string[];
662
+ newDBSyncInstance: (streamId: StreamId, database: string, schema: string, table: string) => BigQueryDBSync;
663
+ genTableName: (key: string) => string;
664
+ safeColumnNameConverter: (key: string) => string;
665
+ validateDateRange: (record: any, schema: FlattenedSchema) => any;
666
+ convertNumberIntoDecimal: (record: any, schema: FlattenedSchema) => any;
667
+ }
668
+
669
+ declare class GCSStateProvider implements StateProvider {
670
+ private bucketName;
671
+ private connectorId;
672
+ constructor(connectorId: string, bucketName: string);
673
+ private getObjectPath;
674
+ getState(): Promise<StateHolder>;
675
+ writeState(state: string): Promise<void>;
676
+ }
677
+
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 };