Esposter
    Preparing search index...

    Class MockTableClient

    An in-memory mock of the Azure TableClient. It uses a Map to simulate table storage and correctly implements the TableClient interface.

    const mockTableClient = new MockTableClient("", "hello world");
    await mockTableClient.createEntity({ partitionKey: "partitionKey", rowKey: "rowKey" });
    const entity = await mockTableClient.getEntity("partitionKey", "rowKey");

    Implements

    • Except<TableClient, "pipeline">
    Index

    Constructors

    • Parameters

      • _url: string
      • tableName: string

      Returns MockTableClient

    Properties

    tableName: string

    Name of the table to perform operations on.

    url: string

    Table Account URL

    Accessors

    • get table(): Map<string>

      Returns Map<string>

    Methods

    • Insert entity in the table.

      Type Parameters

      • T extends object

      Parameters

      • entity: TableEntity<T>

        The properties for the table entity.

      Returns Promise<TableInsertEntityHeaders>

    • Creates a table with the tableName passed to the client constructor

      Returns Promise<void>

    • Deletes the specified entity in the table.

      Parameters

      • partitionKey: string

        The partition key of the entity.

      • rowKey: string

        The row key of the entity.

      Returns Promise<TableDeleteEntityHeaders>

    • Permanently deletes the current table with all of its entities.

      Returns Promise<void>

    • Retrieves details about any stored access policies specified on the table that may be used with Shared Access Signatures.

      Returns Promise<GetAccessPolicyResponse>

    • Returns a single entity in the table.

      Type Parameters

      • T extends object = Record<string, unknown>

      Parameters

      • partitionKey: string

        The partition key of the entity.

      • rowKey: string

        The row key of the entity.

      Returns Promise<GetTableEntityResponse<TableEntityResult<T>>>

    • Queries entities in a table.

      Type Parameters

      • T extends object

      Parameters

      • Optionaloptions: ListTableEntitiesOptions

        The options parameters.

        Example listing entities

        import { DefaultAzureCredential } from "@azure/identity";
        import { TableClient } from "@azure/data-tables";

        const account = "<account>";
        const accountKey = "<accountkey>";
        const tableName = "<tableName>";

        const credential = new DefaultAzureCredential();
        const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

        let i = 0;
        const entities = client.listEntities();
        for await (const entity of entities) {
        console.log(`Entity${++i}: PartitionKey: ${entity.partitionKey} RowKey: ${entity.rowKey}`);
        }

      Returns PagedAsyncIterableIterator<TableEntityResult<T>, TableEntityResultPage<T>>

    • Sets stored access policies for the table that may be used with Shared Access Signatures.

      Returns Promise<TableSetAccessPolicyHeaders>

    • Submits a Transaction which is composed of a set of actions. You can provide the actions as a list or you can use TableTransaction to help building the transaction.

      Example usage:

      import { DefaultAzureCredential } from "@azure/identity";
      import { TableClient, TransactionAction } from "@azure/data-tables";

      const account = "<account>";
      const accountKey = "<accountkey>";
      const tableName = "<tableName>";

      const credential = new DefaultAzureCredential();
      const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

      const actions: TransactionAction[] = [
      ["create", { partitionKey: "p1", rowKey: "1", data: "test1" }],
      ["delete", { partitionKey: "p1", rowKey: "2" }],
      ["update", { partitionKey: "p1", rowKey: "3", data: "newTest" }, "Merge"],
      ];
      const result = await client.submitTransaction(actions);

      Example usage with TableTransaction:

      import { DefaultAzureCredential } from "@azure/identity";
      import { TableClient, TableTransaction } from "@azure/data-tables";

      const account = "<account>";
      const accountKey = "<accountkey>";
      const tableName = "<tableName>";

      const credential = new DefaultAzureCredential();
      const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

      const transaction = new TableTransaction();

      // Call the available action in the TableTransaction object
      transaction.createEntity({ partitionKey: "p1", rowKey: "1", data: "test1" });
      transaction.deleteEntity("p1", "2");
      transaction.updateEntity({ partitionKey: "p1", rowKey: "3", data: "newTest" }, "Merge");

      // submitTransaction with the actions list on the transaction.
      const result = await client.submitTransaction(transaction.actions);

      Returns Promise<TableTransactionResponse>

    • Update an entity in the table.

      Type Parameters

      • T extends object

      Parameters

      • entity: TableEntity<T>

        The properties of the entity to be updated.

      • mode: UpdateMode = "Merge"

        The different modes for updating the entity: - Merge: Updates an entity by updating the entity's properties without replacing the existing entity. - Replace: Updates an existing entity by replacing the entire entity.

      Returns Promise<TableMergeEntityHeaders>

    • Upsert an entity in the table.

      Type Parameters

      • T extends object

      Parameters

      • entity: TableEntity<T>

        The properties for the table entity.

      • mode: UpdateMode = "Merge"

        The different modes for updating the entity: - Merge: Updates an entity by updating the entity's properties without replacing the existing entity. - Replace: Updates an existing entity by replacing the entire entity.

      Returns Promise<TableMergeEntityHeaders>