@tableau/taco-toolkit
Version:
Tableau Connector Toolkit
99 lines (98 loc) • 5.06 kB
TypeScript
import { RequestOptions } from '../../../../shared/app-transport/request';
import { TacoFileParserName } from '../../../../shared/enums/taco-file-parser';
import { DataRow } from '../../../../shared/types/data-row';
import { BasicHandlerInput, FileBasedHandlerInput } from '../../../../shared/types/handler-input';
import { HTTPMethod } from '../../../../shared/types/http';
import { Permission } from '../../../../shared/types/permission';
import { NetworkAdapter, NetworkAdapterFetchOptions } from '../../../modules/network-adapter';
import { TempDataManager } from '../../../modules/temp-data-manager';
import SandboxVM from '../../sandbox-vm';
import { SandboxPlugin } from '../sandbox-plugin';
/**
* Request options for fetchJson and fetchArrayBuffer
*/
export interface FetchRequestOptions extends RequestOptions {
/** HTTP method, GET or POST. Default value is GET. */
method?: Extract<HTTPMethod, 'GET' | 'POST'>;
/**
* Request body.
*
* When an object is provided for body, it will be serialized into JSON string by default.
* When application/x-www-form-urlencoded header is provided, the object will be serialized as query params.
*/
body?: string | object;
}
export interface LoadDataOptions extends RequestOptions {
headers?: Record<string, string>;
method?: Extract<HTTPMethod, 'GET' | 'POST'>;
body?: string | object;
}
export interface LoadCsvDataOptions extends LoadDataOptions {
/**
* If this attribute is set to true, it will remove subsequent column headers from next chunk before writing to disk
*/
trimColumnHeader?: boolean;
}
/**
* The type for the request options of {@link FetchUtils.fetchJson}.
*/
export type FetchJsonOptions = FetchRequestOptions;
/**
* The type for the request options of {@link FetchUtils.fetchArrayBuffer}.
*/
export type FetchArrayBufferOptions = FetchRequestOptions;
export type fetchJsonType = ReturnType<InstanceType<typeof FetchUtilsPlugin>['createFetchJson']>;
export type fetchArrayBufferType = ReturnType<InstanceType<typeof FetchUtilsPlugin>['createFetchArrayBuffer']>;
export type loadCsvDataType = ReturnType<InstanceType<typeof FetchUtilsPlugin>['createLoadCsvData']>;
export type loadExcelDataType = ReturnType<InstanceType<typeof FetchUtilsPlugin>['createLoadExcelData']>;
export type loadParquetDataType = ReturnType<InstanceType<typeof FetchUtilsPlugin>['createLoadParquetData']>;
export type ingestDataRowsType = ReturnType<InstanceType<typeof FetchUtilsPlugin>['createIngestDataRows']>;
type FetchUtilsPluginConfig = {
extractorId: string;
permission: Permission;
} | {
extractorId: string;
permission: Permission;
handlerInput: BasicHandlerInput<unknown> | FileBasedHandlerInput<unknown>;
} | {
extractorId: string;
permission: Permission;
tableName: string;
};
interface FetchUtilsPluginState {
parser?: TacoFileParserName;
}
export declare class FetchUtilsPlugin extends SandboxPlugin {
private config;
private networkAdapter;
private tempDataManager;
readonly state: FetchUtilsPluginState;
private extractorId;
private permission;
constructor(config: FetchUtilsPluginConfig, networkAdapter: NetworkAdapter, tempDataManager: TempDataManager);
getState(): Readonly<FetchUtilsPluginState>;
registerClass(sandbox: SandboxVM): void;
private createFetchJson;
private createFetchArrayBuffer;
private createLoadData;
private createLoadExcelData;
private createLoadCsvData;
private createLoadParquetData;
private createIngestDataRows;
private setParser;
}
export declare function fetchJson<D>(networkAdapter: NetworkAdapter, url: string, options?: FetchJsonOptions): Promise<D>;
export declare function fetchArrayBuffer(networkAdapter: NetworkAdapter, url: string, options?: FetchArrayBufferOptions): Promise<Uint8Array>;
export declare function loadCsvData(extractorId: string, fileName: string, tempDataManager: TempDataManager, networkAdapter: NetworkAdapter, url: string, options?: LoadCsvDataOptions): Promise<void>;
export declare function loadData(extractorId: string, fileName: string, tempDataManager: TempDataManager, networkAdapter: NetworkAdapter, url: string, options?: LoadDataOptions): Promise<void>;
export declare function loadParquetData(extractorId: string, fileName: string, tempDataManager: TempDataManager, networkAdapter: NetworkAdapter, tableFileCounter: Record<string, number>, url: string, options?: LoadDataOptions): Promise<void>;
/**
* Using HandlerInput for now because we are getting HandlerInput via sandbox during runtime, and the type is HandlerInput.
* When we export the API from SDK we should use FileBasedHandlerInput instead.
*/
export declare function ingestDataRows(extractorId: string, fileName: string, tempDataManager: TempDataManager, rows: DataRow[]): Promise<void>;
export declare function getFetchParams(urlString: string, options: LoadDataOptions | FetchRequestOptions | undefined): {
urlWithQuery: string;
options: NetworkAdapterFetchOptions;
};
export {};