UNPKG

hfs-utilities

Version:

Health Fund Solution's internal utilities library for Typescript projects

67 lines (66 loc) 3.45 kB
import { TableServiceClientOptions, TableEntity, TableTransactionResponse, UpdateMode, TableEntityResult } from '@azure/data-tables'; export interface TableRow extends TableEntity { [key: string]: string | null | number | boolean | undefined | unknown; } /** * AzureDataTables is a convenience wrapper around @azure/data-tables library. */ export declare class AzureDataTables { private readonly client; protected connectionString: string; protected tableName: string; protected options?: TableServiceClientOptions; private readonly serviceClient; /** * Creates a new instance of AzureDataTables. * @param connectionString Azure Data Tables connection string. * @param tableName Azure Data Tables table name. * @param options Azure Data Tables client options. */ constructor(connectionString: string, tableName: string, options?: TableServiceClientOptions); /** * @description - converts object and array properties to string as needed * @param { TableEntity } obj - object to be converted to a table row * @returns { TableRow } - returns a table row that can safely be used in a transaction */ toTableRow(obj: TableEntity): TableRow; /** * @description - determines if a table row is valid * @param { any } obj - object to be validated * @returns {boolean} - returns true if the object is a valid table record, i.e. has partitionKey and rowKey that are * strings longer than 0 and all other object values are either a string, null, number, or boolean */ isTableRecord(obj: any): boolean; /** * @description maps table rows by partition key since we need to do transactions by partitionKey. * @param tableRows Table rows to be grouped by partition key. * @returns a Map of partition key to table rows. */ private mapByPartitionKey; /** * @description updates a table row or rows. * @param {TableEntity | TableEntity[]} tableRowOrRows - one or more table rows to be updated. * @param {UpdateMode} updateMode - Mode of update. * @returns {Promise<TableTransactionResponse[]} - returns an array of TableTransactionResponse. */ upsert(tableRowOrRows: TableEntity | TableEntity[], updateMode?: UpdateMode): Promise<TableTransactionResponse[]>; /** * @description creates a table row or rows. * @param {TableEntity | TableEntity[]} tableRowOrRows - one or more table rows to be created. * @returns {Promise<TableTransactionResponse[]>} - returns an array of TableTransactionResponse. */ create(tableRowOrRows: TableEntity | TableEntity[]): Promise<TableTransactionResponse[]>; /** * @description deletes a table row or rows. * @param {TableEntity | TableEntity[]} tableRowOrRows - one or more table rows to be created. * @returns {Promise<TableTransactionResponse[]>} - returns an array of TableTransactionResponse. */ delete(tableRowOrRows: TableEntity | TableEntity[]): Promise<TableTransactionResponse[]>; /** * @desecription - returns query results. * @param query - query to be executed * @param select - an array of columns to be selected * @returns - returns a promise that resolves to an array of table rows. */ query(query: string, select?: string[]): Promise<Array<TableEntityResult<Record<string, unknown>>>>; }