UNPKG

@tableau/taco-toolkit

Version:
170 lines (169 loc) 6.48 kB
import type { ColumnHeader } from '../../../types/column-header'; import type { DataContainer } from '../../../../shared/types/data-container'; import type { DataRow } from '../../../../shared/types/data-row'; import type { DataTable } from '../../../../shared/types/data-table'; import type { HandlerInput } from '../../../../shared/types/handler-input'; export interface ParseOptions { dataContainer: DataContainer; handlerInput: HandlerInput; } declare abstract class BaseParser { /** * A static method to create a DataContainerBuilder instance based on the provided dataContainer object. */ static createContainerBuilder(dataContainer: DataContainer): DataContainerBuilder; } /** * An abstract class for the implementation of connector custom parsing that synchronously parses the results yielded from the Fetcher. * * For TypeScript, the fetcherResult type can be provided via the type parameter. By default, fetcherResult is typed as `any`. * * @example * ```ts * export default class MyParser extends Parser<Uint8Array> { * parse(fetcherResult: Uint8Array, options: ParseOptions): DataContainer { * // ... * } * } * ``` */ export declare abstract class Parser<FetchResult = any> extends BaseParser { /** * The method to implement the parsing logic for transforming the fetcherResult into a DataContainer. * When a custom parser is defined, the connector must implement this method to perform data parsing. */ abstract parse(fetcherResult: FetchResult, options: ParseOptions): DataContainer; } /** * An abstract class for the implementation of connector custom parsing that asynchronously parses the results yielded from the Fetcher. * * For TypeScript, the fetcherResult type can be provided via the type parameter. By default, fetcherResult is typed as `any`. * * @example * ```ts * export default class MyParser extends AsyncParser<Uint8Array> { * async parse(fetcherResult: Uint8Array, options: ParseOptions): Promise<DataContainer> { * // ... * } * } * ``` */ export declare abstract class AsyncParser<FetchResult = any> extends BaseParser { /** * The method to implement the parsing logic for transforming the fetcherResult into a DataContainer. * When a custom parser is defined, the connector must implement this method to perform data parsing. */ abstract parse(fetcherResult: FetchResult, options: ParseOptions): Promise<DataContainer>; } /** * A builder class for constructing and modifying a DataContainer instance. * * This class provides methods to retrieve, and append tables within a DataContainer. * * @example * ```ts * const dataContainerBuilder = Parser.createContainerBuilder(initialDataContainer) * * // Create or get a table and add columns or rows * const { tableBuilder, isNew } = dataContainerBuilder.getTable('myTable') * tableBuilder.addColumnHeader({ name: 'column1', dataType: 'string' }); * tableBuilder.addColumnHeader({ name: 'column2', dataType: 'string' }); * tableBuilder.addRow({ column1: 'value1', column2: 'value2' }); * * // Get the final DataContainer * const finalDataContainer = dataContainerBuilder.getDataContainer() * ``` */ export declare class DataContainerBuilder { private dataContainer; /** @ignore */ constructor(dataContainer: DataContainer); /** * Retrieves a table builder for the specified table name. If the table does not exist, * a new table is created within the DataContainer. * * @param {string} name - The name of the table. * @returns {{ tableBuilder: DataTableBuilder; isNew: boolean }} An object containing the table builder * and a boolean indicating whether the table is newly created. */ getTable(name: string): { tableBuilder: DataTableBuilder; isNew: boolean; }; /** * Appends an array of DataTable instances to the DataContainer. * * @param {DataTable[]} tables - An array of DataTable instances to append. */ /** @ignore */ appendTables(tables: DataTable[]): void; /** * Appends a DataTable instance to the DataContainer. * * @param {DataTable} table - The DataTable instance to append. * @throws {Error} Throws an error if a table with the same name already exists in the DataContainer. */ /** @ignore */ appendTable(table: DataTable): void; /** * Gets the final DataContainer instance after building and modifying it. * * @returns {DataContainer} The constructed DataContainer instance. */ getDataContainer(): DataContainer; } /** * A builder class for constructing and modifying a DataTable instance within a DataContainer. * * This class provides methods to add row/s and add column header/s to a DataTable. * * @example * ```ts * const dataContainerBuilder = Parser.createContainerBuilder(initialDataContainer); * const { tableBuilder } = dataContainerBuilder.getTable('myTable'); * * // Add row and column header for a specific table * tableBuilder.addColumnHeader({ name: 'column1', dataType: 'string' }); * tableBuilder.addColumnHeader({ name: 'column2', dataType: 'string' }); * tableBuilder.addRow({ column1: 'value1', column2: 'value2' }); * * // Get the final DataContainer * const finalDataContainer = dataContainerBuilder.getDataContainer(); * ``` */ export declare class DataTableBuilder { private dataTable; /** @ignore */ constructor(dataTable: DataTable); /** @ignore */ setId(id: string): void; /** @ignore */ setProperties(properties: Record<string, unknown>): void; /** @ignore */ setDeferHandler(handlerInput: HandlerInput): void; /** * Adds a single row to the DataTable. * * @param {DataRow} row - The row to add to the DataTable. */ addRow(row: DataRow): void; /** * Adds multiple rows to the DataTable. * * @param {DataRow[]} rows - The array of rows to add to the DataTable. */ addRows(rows: DataRow[]): void; /** * Adds a single column header to the DataTable. * * @param {ColumnHeader} column - The column header to add to the DataTable. */ addColumnHeader(column: ColumnHeader): void; /** * Adds multiple column headers to the DataTable. * * @param {ColumnHeader[]} colHeaders - The array of column headers to add to the DataTable. */ addColumnHeaders(colHeaders: ColumnHeader[]): void; } export {};