/*! * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ import { TokenCredential } from '@azure/identity'; import { QueryType } from '../query'; import { ReadonlyTask, Task } from '../task'; import { TaskEnableOptions } from '../types/public'; import { Listener } from './listener'; import ScopedTaskClient from './scoped'; import { ArrayWithContinuation, CreateTaskOptions, IterateOptions, IterateSummaryOptions, ListenOptions, ListOptions, ListPageOptions, ListSummaryOptions, ListSummaryPageOptions, TaskClientOptions, TaskHandler } from './types'; /** * The primary client for creating, updating, querying and processing tasks. It * wraps an Azure Cosmos DB collection, which is used to store the tasks. It's * recommended that you create one using the TaskClient.create method instead of * using the constructor. This will set up the database, collection and * necessary stored procedures for you. * * @public */ export default class TaskClient { private _client; private _options; private _interceptor; /** * Create a client using a pre-initialized Azure Cosmos DB client. Usage of * this API is only recommended for advanced users. Most users should use * the TaskClient.create method instead. * * @param cosmosClient - Client created from a {@link * @azure/cosmos#Container} that is scoped to the * collection/container that the tasks client * should use. * @param options - Client creation options * * @internal */ private constructor(); /** * Initializes a task client using the provided account information, * creating the specified database and collection if necessary. * * @param subscriptionId - Subscription ID of this cosmos DB * @param resourceGroupName - Resource Group of this cosmos DC * @param account - Azure Cosmos DB account url * @param database - Azure Cosmos DB database name * @param collection - Azure Cosmos DB collection/container name * @param aadCredentials - Azure Identity Library TokenCredential * @param options - Client creation options * * @returns Promise containing the initialized client * * @public */ static createFromCredential(subscriptionId: string, resourceGroupName: string, account: string, database: string, collection: string, aadCredentials: TokenCredential, options?: TaskClientOptions): Promise; /** * Initializes a task client using the provided account information, * creating the specified database and collection if necessary. * * @param account - Azure Cosmos DB account url * @param database - Azure Cosmos DB database name * @param collection - Azure Cosmos DB collection/container name * @param key - Azure Cosmos DB account key * @param options - Client creation options * * @returns Promise containing the initialized client * * @public */ static createFromKey(account: string, database: string, collection: string, key: string, options?: TaskClientOptions): Promise; /** * Returns a client with all operations automatically scoped to the provided * task type. This is useful if you have an area where you need to perform * many related operations for a single task type and don't want to have to * specify it each time. * * @param type - Task type to apply to all operations within the scoped * client. * * @public */ type(type: string): ScopedTaskClient; /** * Creates a task and saves it to the database. * * @param type - Task type * @param payload - Payload containing the data for the task * @param options - Options to configure the newly created task * * @public */ create(type: string, payload: T, options?: CreateTaskOptions): Promise>; /** * Retrieves the task of the given type with the provided id, if one exists. * If the task is not found, undefined is returned. * * @param type - Task type * @param id - The task's id * * @public */ get(type: string, id: string): Promise | undefined>; /** * Retrieves all tasks of the given type, paged using the provided list * options. * * @param type - Task type * @param options - Options controlling which tasks to retrieve * * @public */ list(type: string, options?: ListOptions): Promise[]>; /** * Retrieves a single page from the database for tasks of the given type, * optionally starting from the provided continuation token. * * @param type - Task type * @param options - Options controlling which tasks to retrieve * * @public */ listPaged(type: string, options?: ListPageOptions): Promise>>; /** * Retrieves all tasks across all types of tasks, paged using the provided * list options. * * @remarks * * Performing operations across multiple types results in cross partition * queries to Cosmos DB. This can cause a significant performance impact, * especially when paging and/or sorting results. Use this API with care. * * @param options - Options controlling which tasks to retrieve * * @public */ listAll(options?: ListOptions): Promise[]>; /** * Retrieves all tasks of the given type with the entire payload omitted by * default. This is primarily useful if you have tasks with a large amount * of data in the payload that you don't need to see in the listed results * and you want to save cost/memory. * * @remarks * * Results are paged, filtered and sorted using the provided options. You * may also specify certain properties of the payload you want to see in the * returned task through the options. * * @param type - Task type * @param options - Options controlling which tasks to retrieve * * @public */ listSummary(type: string, options?: ListSummaryOptions): Promise[]>; /** * Retrieves a single page of tasks of the given type with the entire payload * omitted by default, optionally starting from the provided continuation * token. This is primarily useful if you have tasks with a large amount of * data in the payload that you don't need to see in the listed results and * you want to save cost/memory. * * @remarks * * Results are paged, filtered and sorted using the provided options. You * may also specify certain properties of the payload you want to see in the * returned task through the options. * * @param type - Task type * @param options - Options controlling which tasks to retrieve * * @public */ listSummaryPaged(type: string, options?: ListSummaryPageOptions): Promise>>; /** * Retrieves all tasks across all types with the entire payload omitted by * default. This is primarily useful if you have tasks with a large amount * of data in the payload that you don't need to see in the listed results * and you want to save cost/memory. * * @remarks * * Results are paged, filtered and sorted using the provided options. You * may also specify certain properties of the payload you want to see in the * returned task through the options. * * Performing operations across multiple types results in cross partition * queries to Cosmos DB. This can cause a significant performance impact, * especially when paging and/or sorting results. Use this API with care. * * @param options - Options controlling which tasks to retrieve * * @public */ listAllSummary(options?: ListSummaryOptions): Promise[]>; /** * Returns an async iterator for iterating over all tasks of the given type, * optionally filtered/sorted using the provided options object. * * @remarks * * _NOTE: Asynchronous iterators are a new feature of Javascript and are * only available without a polyfill starting in Node.js 10. You can make * use of async iterators in prior versions of Node.js by using TypeScript * or Babel to downcompile the code for you: * https://node.green/#ES2018-features-Asynchronous-Iterators_ * * @param type - Task type * @param options - Options controlling which tasks to retrieve and the * order in which to receive them * * @public */ iterate(type: string, options?: IterateOptions): AsyncIterable>; /** * Returns an async iterator for iterating over all tasks across all types, * optionally filtered/sorted using the provided options object. * * @remarks * * Performing operations across multiple types results in cross partition * queries to Cosmos DB. This can cause a significant performance impact, * especially when paging and/or sorting results. Use this API with care. * * _NOTE: Asynchronous iterators are a new feature of Javascript and are * only available without a polyfill starting in Node.js 10. You can make * use of async iterators in prior versions of Node.js by using TypeScript * or Babel to downcompile the code for you: * https://node.green/#ES2018-features-Asynchronous-Iterators_ * * @param options - Options controlling which tasks to retrieve and the * order in which to receive them * * @public */ iterateAll(options?: IterateOptions): AsyncIterable>; /** * Returns an async iterator for iterating over all tasks of the given type * with the entire payload omitted by default. This is primarily useful if * you have tasks with a large amount of data in the payload that you don't * need to see in the listed results and you want to save cost/memory. * * @remarks * * Results are filtered and sorted using the provided options. You may also * specify certain properties of the payload you want to see in the returned * task through the options. * * _NOTE: Asynchronous iterators are a new feature of Javascript and are * only available without a polyfill starting in Node.js 10. You can make * use of async iterators in prior versions of Node.js by using TypeScript * or Babel to downcompile the code for you: * https://node.green/#ES2018-features-Asynchronous-Iterators_ * * @param type - Task type * @param options - Options controlling which tasks to retrieve and the * order in which to receive them * @public */ iterateSummary(type: string, options?: IterateSummaryOptions): AsyncIterable>; /** * Returns an async iterator for iterating over all tasks across all types * with the entire payload omitted by default. This is primarily useful if * you have tasks with a large amount of data in the payload that you don't * need to see in the listed results and you want to save cost/memory. * * @remarks * * Results are filtered and sorted using the provided options. You may also * specify certain properties of the payload you want to see in the returned * task through the options. * * Performing operations across multiple types results in cross partition * queries to Cosmos DB. This can cause a significant performance impact, * especially when paging and/or sorting results. Use this API with care. * * _NOTE: Asynchronous iterators are a new feature of Javascript and are * only available without a polyfill starting in Node.js 10. You can make * use of async iterators in prior versions of Node.js by using TypeScript * or Babel to downcompile the code for you: * https://node.green/#ES2018-features-Asynchronous-Iterators_ * * @param type - Task type * @param options - Options controlling which tasks to retrieve and the * order in which to receive them * @public */ iterateAllSummary(options?: IterateSummaryOptions): AsyncIterable>; /** * Compute the number of tasks of the given type that currently exist, * optionally filtered to a custom group of tasks within the type. * * @param type - Task type * @param filter - Query filter specifying which tasks within the provided * type to include */ count(type: string, filter?: QueryType.Bool): Promise; /** * Compute the number of tasks across all types that currently exist, * optionally filtered to a custom group of tasks. * * @remarks * * Performing operations across multiple types results in cross partition * queries to Cosmos DB. This can cause a significant performance impact, * especially when paging and/or sorting results. Use this API with care. * * @param filter - Query filter specifying which tasks to include */ countAll(filter?: QueryType.Bool): Promise; /** * Disables tasks of the provided type, optionally filtered to a custom group * of tasks within the type. * * @param type - Task type * @param filter - Query filter specifying which tasks within the provided * type to disable * * @public */ disable(type: string, filter?: QueryType.Bool): Promise; /** * Disables tasks across all types, optionally filtered to a custom group of * tasks. * * @remarks * * Performing operations across multiple types results in cross partition * queries to Cosmos DB. This can cause a significant performance impact, * especially when paging and/or sorting results. Use this API with care. * * @param filter - Query filter specifying which tasks to disable * * @public */ disableAll(filter?: QueryType.Bool): Promise; /** * Enables tasks of the provided type, optionally filtered to a custom group * of tasks within the type. * * @param type - Task type * @param filter - Query filter specifying which tasks within the provided * type to enable * @param options - Task enable options * * @public */ enable(type: string, filter?: QueryType.Bool, options?: TaskEnableOptions): Promise; /** * Enables tasks across all types, optionally filtered to a custom group * of tasks. * * @remarks * * Performing operations across multiple types results in cross partition * queries to Cosmos DB. This can cause a significant performance impact, * especially when paging and/or sorting results. Use this API with care. * * @param filter - Query filter specifying which tasks to enable * @param options - Task enable options * * @public */ enableAll(filter?: QueryType.Bool, options?: TaskEnableOptions): Promise; /** * Delete the task from the database. The operation is idempotent and will * succeed even if the task has already been deleted. * * @param type - Task type * @param id - The task's id * * @public */ deleteOne(type: string, id: string): Promise; /** * Deletes tasks of the provided type, optionally filtered to a custom group * of tasks within the type. * * @param type - Task type * @param filter - Query filter specifying which tasks within the provided * type to delete * * @public */ delete(type: string, filter?: QueryType.Bool): Promise; /** * Deletes tasks across all types, optionally filtered to a custom group * of tasks. * * @param filter - Query filter specifying which tasks to delete * * @public */ deleteAll(filter?: QueryType.Bool): Promise; /** * Start listening for tasks of the provided type. * * @param type - Task type * @param handler - Function to call with each task received for processing. * May be synchronous or asynchronous * @param options - Options for configuring the listener * * @public */ listen(type: string, handler: TaskHandler, options?: ListenOptions): Listener; /** * Ensures that the proper stored procedures are registered with Cosmos DB * for the client to function. You should never have to call this directly. * * @public */ registerSprocs(): Promise; private _bulkUpdate; private _iterate; private _addContinuation; } //# sourceMappingURL=client.d.ts.map