UNPKG

3.51 kBTypeScriptView Raw
1/**
2 * @module botbuilder-azure
3 */
4/**
5 * Copyright (c) Microsoft Corporation. All rights reserved.
6 * Licensed under the MIT License.
7 */
8import { CosmosClientOptions } from '@azure/cosmos';
9import { Storage, StoreItems } from 'botbuilder';
10/**
11 * Cosmos DB Partitioned Storage Options.
12 */
13export interface CosmosDbPartitionedStorageOptions {
14 /**
15 * The CosmosDB endpoint.
16 */
17 cosmosDbEndpoint?: string;
18 /**
19 * The authentication key for Cosmos DB.
20 */
21 authKey?: string;
22 /**
23 * The database identifier for Cosmos DB instance.
24 */
25 databaseId: string;
26 /**
27 * The container identifier.
28 */
29 containerId: string;
30 /**
31 * The options for the CosmosClient.
32 */
33 cosmosClientOptions?: CosmosClientOptions;
34 /**
35 * The throughput set when creating the Container. Defaults to 400.
36 */
37 containerThroughput?: number;
38 /**
39 * The suffix to be added to every key. See cosmosDbKeyEscape.escapeKey
40 *
41 * Note: compatibilityMode must be set to 'false' to use a KeySuffix.
42 * When KeySuffix is used, keys will NOT be truncated but an exception will
43 * be thrown if the key length is longer than allowed by CosmosDb.
44 *
45 * The keySuffix must contain only valid CosmosDb key characters.
46 * (e.g. not: '\\', '?', '/', '#', '*')
47 */
48 keySuffix?: string;
49 /**
50 * Early version of CosmosDb had a max key length of 255. Keys longer than
51 * this were truncated in cosmosDbKeyEscape.escapeKey. This remains the default
52 * behavior of cosmosDbPartitionedStorage, but can be overridden by setting
53 * compatibilityMode to false.
54 *
55 * compatibilityMode cannot be true if keySuffix is used.
56 */
57 compatibilityMode?: boolean;
58}
59/**
60 * Implements a CosmosDB based storage provider using partitioning for a bot.
61 */
62export declare class CosmosDbPartitionedStorage implements Storage {
63 private readonly cosmosDbStorageOptions;
64 private container;
65 private client;
66 private compatibilityModePartitionKey;
67 /**
68 * Initializes a new instance of the <see cref="CosmosDbPartitionedStorage"/> class.
69 * using the provided CosmosDB credentials, database ID, and container ID.
70 *
71 * @param {CosmosDbPartitionedStorageOptions} cosmosDbStorageOptions Cosmos DB partitioned storage configuration options.
72 */
73 constructor(cosmosDbStorageOptions: CosmosDbPartitionedStorageOptions);
74 private toJSON;
75 /**
76 * Read one or more items with matching keys from the Cosmos DB container.
77 *
78 * @param {string[]} keys A collection of Ids for each item to be retrieved.
79 * @returns {Promise<StoreItems>} The read items.
80 */
81 read(keys: string[]): Promise<StoreItems>;
82 /**
83 * Insert or update one or more items into the Cosmos DB container.
84 *
85 * @param {StoreItems} changes Dictionary of items to be inserted or updated indexed by key.
86 */
87 write(changes: StoreItems): Promise<void>;
88 /**
89 * Delete one or more items from the Cosmos DB container.
90 *
91 * @param {string[]} keys Array of Ids for the items to be deleted.
92 */
93 delete(keys: string[]): Promise<void>;
94 /**
95 * Connects to the CosmosDB database and creates / gets the container.
96 */
97 initialize(): Promise<void>;
98 private getOrCreateContainer;
99 private getPartitionKey;
100 private checkForNestingError;
101 private throwInformativeError;
102}
103//# sourceMappingURL=cosmosDbPartitionedStorage.d.ts.map
\No newline at end of file