import { Dictionary } from 'ts-essentials'; import { AirbyteLogger } from '../../logger'; import { AirbyteStream, SyncMessage, SyncMode } from '../../protocol'; export type StreamKey = string | string[] | string[][]; /** * Schema property name that opts out a stream from the data field injection. */ export declare const FAROS_SKIP_DATA_PROPERTY = "__faros_skip_data"; /** * Base abstract class for an Airbyte Stream. Makes no assumption of the * Stream's underlying transport protocol. */ export declare abstract class AirbyteStreamBase { protected readonly logger: AirbyteLogger; constructor(logger: AirbyteLogger); /** * @returns Stream name. By default this is the implementing class name, but * it can be overridden as needed. */ get name(): string; /** * Override to return a list of stream names that this stream depends on. Adding a stream * to this list will ensure that the stream is always run * (if requested in the configured catalog) before this stream. * * @returns An array of stream names that this stream depends on. */ get dependencies(): ReadonlyArray; /** * Controls whether the stream should skip the __faros_data field injection. * By default, checks if the schema has __faros_skip_data: true. * Override to opt out of the data field injection programmatically. * * @returns True if __faros_data field should NOT be added to this stream. */ get skipDataField(): boolean; /** * This method should be overridden by subclasses to read records based on the * inputs */ abstract readRecords(syncMode: SyncMode, cursorField?: string[], streamSlice?: Dictionary, streamState?: Dictionary): AsyncGenerator>; /** * @returns A dict of the JSON schema representing this stream. * TODO: get by name from resources/schemas folder */ abstract getJsonSchema(): Dictionary; asAirbyteStream(): AirbyteStream; /** * @returns True if this stream supports incrementally reading data */ get supportsIncremental(): boolean; private wrappedCursorField; /** * Override to return the default cursor field used by this stream e.g: an API * entity might always use created_at as the cursor field. * @returns The name of the field used as a cursor. If the cursor is nested, * return an array consisting of the path to the cursor. */ get cursorField(): string | string[]; /** * @returns False if the cursor can be configured by the user. */ get sourceDefinedCursor(): boolean; /** * @returns string if single primary key, list of strings if composite primary * key, list of list of strings if composite primary key consisting of nested * fields. If the stream has no primary keys, return None. */ abstract get primaryKey(): StreamKey | undefined; /** * Override to define the slices for this stream. See the stream slicing * section of the docs for more information. */ streamSlices(syncMode: SyncMode, cursorField?: string[], streamState?: Dictionary): AsyncGenerator | undefined>; /** * Percentage of slices (expressed as decimal from 0 to 1) that have to error * for the stream to count as a failure instead of a partial success. */ get sliceErrorPctForFailure(): number; /** * Percentage of slices skipped with warnings, expressed as a decimal from * 0 to 1, that should still count as a stream failure. The default fails * only when every attempted slice was skipped, which prevents silently * succeeding when credentials or source configuration cannot access any * selected data. */ get skippableSliceErrorPctForFailure(): number; /** * Returns true when the state accumulated before a slice error is safe to * persist. The default rolls the entire slice back. Streams should only opt * in for errors raised after processing records oldest-to-newest with an * inclusive cursor, so retrying cannot skip unread records. */ preserveStateOnSliceError(_error: unknown, _streamSlice?: Dictionary): boolean; /** * Decides how often to checkpoint state (i.e: emit a STATE message). E.g: if * this returns a value of 100, then state is persisted after reading 100 * records, then 200, 300, etc.. A good default value is 1000 although your * mileage may vary depending on the underlying data source. * * Checkpointing a stream avoids re-reading records in the case a sync is * failed or cancelled. * * @returns None if state should not be checkpointed e.g: because records * returned from the underlying data source are not returned in ascending * order with respect to the cursor field. This can happen if the source does * not support reading records in ascending order of created_at date (or * whatever the cursor is). In those cases, state must only be saved once the * full stream has been read. */ get stateCheckpointInterval(): number | undefined; /** * Override to extract state from the latest record. Needed to implement * incremental sync. * * Inspects the latest record extracted from the data source and the current * state object and return an updated state object. * Do not mutate the current state or its nested values, including from * readRecords. The source retains the previous object to restore state * when a slice fails. * * For example: if the state object is based on created_at timestamp, and the * current state is {'created_at': 10}, and the latest_record is {'name': * 'octavia', 'created_at': 20 } then this method would return {'created_at': * 20} to indicate state should be updated to this object. * * @param currentStreamState The stream's current state object * @param latestRecord The latest record extracted from the stream * @param streamSlice The current stream slice being processed * @returns An updated state object */ getUpdatedState(currentStreamState: Dictionary, latestRecord: Dictionary, streamSlice?: Dictionary): Dictionary; /** Finalize state only after a slice completes, including an empty slice. */ getUpdatedStateAfterSlice(currentStreamState: Dictionary, _streamSlice?: Dictionary): Dictionary; /** * Override to treat selected slice errors as warnings. When this returns a * message, the source skips the current slice and restores the stream state * to its value before the slice started. */ getSkippableSliceErrorMessage(error: unknown, streamSlice?: Dictionary): SyncMessage | undefined; /** * Override to perform any action before reading slices. */ onBeforeRead(): Promise; /** * Override to perform any action after reading all slices. */ onAfterRead(): Promise; /** * Override to return true if this full_refresh stream's state should be * preserved across syncs. Airbyte wipes state for full_refresh streams * at the start of every sync. When this is true, the CDK backs up the * stream state under an internal shared state key that Airbyte won't * wipe, and restores it at the start of the next sync. */ get preserveFullRefreshState(): boolean; /** * Override to return true if this stream's data is partitioned by bucket_id. * When true, freshness tracking uses per-bucket timestamps (e.g., "1/4"). * When false (default), freshness uses a single top-level timestamp shared * across all buckets, so the stream only syncs once within its freshness window. */ get isBucketed(): boolean; /** * Override to customize how this stream validates credential access. * The default probes streamSlices() + readRecords() with a single record. */ probe(): Promise<{ status: 'pass' | 'fail' | 'skip'; message?: string; }>; /** * @returns wrap the primary_key property in a list of list of strings * required by the Airbyte Stream object. */ static wrappedPrimaryKey(keys?: StreamKey): string[][] | undefined; } export interface StreamState { [key: string]: { cutoff: number; }; } export declare function calculateUpdatedStreamState(latestRecordCutoff: Date, currentStreamState: StreamState, key: string, cutoffLagDays?: number): StreamState;