or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

authentication.mdindex.mdsas.mdtable-client.mdtable-service-client.mdtable-transaction.mdtypes.md
tile.json

table-service-client.mddocs/

Table Service Client

The TableServiceClient provides service-level operations for the Azure Tables service, including table management, service statistics, and configuration.

Capabilities

TableServiceClient Class

A client for performing operations on the Azure Tables service at the account level.

/**
 * A client for performing operations on the Azure Tables service, allowing management of tables and service-level operations.
 */
class TableServiceClient {
  /** Table Account URL */
  readonly url: string;
  /** HTTP request pipeline */
  readonly pipeline: Pipeline;

  /** Create with Named Key credential */
  constructor(url: string, credential: NamedKeyCredential, options?: TableServiceClientOptions);
  /** Create with SAS credential */
  constructor(url: string, credential: SASCredential, options?: TableServiceClientOptions);
  /** Create with Token credential */
  constructor(url: string, credential: TokenCredential, options?: TableServiceClientOptions);
  /** Create with anonymous access */
  constructor(url: string, options?: TableServiceClientOptions);

  /** Create client from connection string */
  static fromConnectionString(connectionString: string, options?: TableServiceClientOptions): TableServiceClient;
}

interface TableServiceClientOptions extends CommonClientOptions {
  /** Service endpoint URL */
  endpoint?: string;
  /** API version to use */
  version?: string;
}

Table Management

Create, delete, and list tables in the storage account.

/**
 * Creates a new table in the storage account
 * @param name - The name of the table to create
 * @param options - Optional parameters for the operation
 */
createTable(name: string, options?: OperationOptions): Promise<void>;

/**
 * Deletes a table from the storage account
 * @param name - The name of the table to delete
 * @param options - Optional parameters for the operation
 */
deleteTable(name: string, options?: OperationOptions): Promise<void>;

/**
 * Lists all tables in the storage account
 * @param options - Optional parameters including filtering and pagination
 * @returns Pageable iterator of table items
 */
listTables(options?: ListTableItemsOptions): PagedAsyncIterableIterator<TableItem, TableItem[]>;

interface ListTableItemsOptions extends OperationOptions {
  /** OData query options */
  queryOptions?: TableQueryOptions;
}

interface TableQueryOptions {
  /** OData filter expression */
  filter?: string;
}

interface TableItem {
  /** The name of the table */
  name?: string;
}

Usage Examples:

import { TableServiceClient, AzureNamedKeyCredential } from "@azure/data-tables";

const credential = new AzureNamedKeyCredential("accountName", "accountKey");
const serviceClient = new TableServiceClient("https://myaccount.table.core.windows.net", credential);

// Create a table
await serviceClient.createTable("Customers");

// List all tables
const tables = serviceClient.listTables();
for await (const table of tables) {
  console.log(`Table: ${table.name}`);
}

// List tables with filtering
const filteredTables = serviceClient.listTables({
  queryOptions: {
    filter: "TableName ge 'A' and TableName lt 'D'"
  }
});

// Delete a table
await serviceClient.deleteTable("OldTable");

Service Statistics

Retrieve service-level statistics and geo-replication information.

/**
 * Gets statistics related to replication for the Table service
 * @param options - Optional parameters for the operation
 * @returns Statistics about the service replication
 */
getStatistics(options?: OperationOptions): Promise<GetStatisticsResponse>;

interface GetStatisticsResponse {
  /** Service statistics */
  serviceStats?: TableServiceStats;
  /** Response headers */
  _response: HttpResponse;
}

interface TableServiceStats {
  /** Geo-replication statistics */
  geoReplication?: GeoReplication;
}

interface GeoReplication {
  /** The status of the geo-replication */
  status: GeoReplicationStatusType;
  /** The last sync time */
  lastSyncTime?: Date;
}

type GeoReplicationStatusType = "live" | "bootstrap" | "unavailable";

Service Properties

Get and set service-level configuration including CORS rules, logging, and metrics.

/**
 * Gets the properties of the Table service
 * @param options - Optional parameters for the operation
 * @returns Current service properties
 */
getProperties(options?: OperationOptions): Promise<GetPropertiesResponse>;

/**
 * Sets the properties of the Table service
 * @param properties - Service properties to set
 * @param options - Optional parameters for the operation
 */
setProperties(properties: ServiceProperties, options?: SetPropertiesOptions): Promise<SetPropertiesResponse>;

interface GetPropertiesResponse {
  /** Service properties */
  serviceProperties?: ServiceProperties;
  /** Response headers */
  _response: HttpResponse;
}

interface SetPropertiesOptions extends OperationOptions {
  /** Request timeout in seconds */
  timeoutInSeconds?: number;
}

interface SetPropertiesResponse {
  /** Response headers */
  _response: HttpResponse;
}

interface ServiceProperties {
  /** CORS rules */
  cors?: CorsRule[];
  /** Hour metrics configuration */
  hourMetrics?: Metrics;
  /** Logging configuration */
  logging?: Logging;
  /** Minute metrics configuration */
  minuteMetrics?: Metrics;
}

interface CorsRule {
  /** Allowed origins */
  allowedOrigins: string;
  /** Allowed methods */
  allowedMethods: string;
  /** Allowed headers */
  allowedHeaders: string;
  /** Exposed headers */
  exposedHeaders: string;
  /** Max age in seconds */
  maxAgeInSeconds: number;
}

interface Metrics {
  /** Version of metrics */
  version?: string;
  /** Whether metrics are enabled */
  enabled?: boolean;
  /** Whether to include APIs in metrics */
  includeApis?: boolean;
  /** Retention policy */
  retentionPolicy?: RetentionPolicy;
}

interface Logging {
  /** Version of logging */
  version?: string;
  /** Whether delete operations are logged */
  delete?: boolean;
  /** Whether read operations are logged */
  read?: boolean;
  /** Whether write operations are logged */
  write?: boolean;
  /** Retention policy */
  retentionPolicy?: RetentionPolicy;
}

interface RetentionPolicy {
  /** Whether retention is enabled */
  enabled?: boolean;
  /** Number of days to retain */
  days?: number;
}

Usage Examples:

// Get service statistics
const stats = await serviceClient.getStatistics();
if (stats.serviceStats?.geoReplication) {
  console.log(`Geo-replication status: ${stats.serviceStats.geoReplication.status}`);
  console.log(`Last sync: ${stats.serviceStats.geoReplication.lastSyncTime}`);
}

// Get current properties
const properties = await serviceClient.getProperties();
console.log("Current CORS rules:", properties.serviceProperties?.cors);

// Set service properties
await serviceClient.setProperties({
  cors: [{
    allowedOrigins: "*",
    allowedMethods: "GET,POST,PUT,DELETE",
    allowedHeaders: "*",
    exposedHeaders: "*",
    maxAgeInSeconds: 3600
  }],
  logging: {
    version: "1.0",
    delete: true,
    read: true,
    write: true,
    retentionPolicy: {
      enabled: true,
      days: 7
    }
  }
});

Common Types

interface OperationOptions {
  /** A function to be called each time a response is received from the server */
  onResponse?: (response: RawResponseCallback) => void;
  /** Options used when creating and sending HTTP requests */
  requestOptions?: OperationRequestOptions;
  /** Options used when tracing is enabled */
  tracingOptions?: OperationTracingOptions;
  /** Abort signal for canceling the operation */
  abortSignal?: AbortSignalLike;
}

type NamedKeyCredential = AzureNamedKeyCredential;
type SASCredential = AzureSASCredential;

// From @azure/core-client
interface CommonClientOptions {
  /** Additional policies to add to the pipeline */
  additionalPolicies?: AdditionalPolicyConfig[];
  /** Allow insecure connections when using HTTP */
  allowInsecureConnection?: boolean;
  /** HTTP client implementation */
  httpClient?: HttpClient;
  /** Proxy configuration */
  proxyOptions?: ProxySettings;
  /** Retry policy configuration */
  retryOptions?: PipelineRetryOptions;
  /** Telemetry options */
  telemetryOptions?: TelemetryOptions;
  /** User agent policy configuration */
  userAgentOptions?: UserAgentPolicyOptions;
}