|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import { FunctionInput, FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger } from './index'; |
| 5 | +import { InvocationContext } from './InvocationContext'; |
| 6 | + |
| 7 | +export type CosmosDBHandler = (documents: unknown[], context: InvocationContext) => FunctionResult; |
| 8 | + |
| 9 | +export interface CosmosDBFunctionOptions extends CosmosDBTriggerOptions, Partial<FunctionOptions> { |
| 10 | + handler: CosmosDBHandler; |
| 11 | + |
| 12 | + trigger?: CosmosDBTrigger; |
| 13 | +} |
| 14 | + |
| 15 | +export interface CosmosDBInputOptions { |
| 16 | + /** |
| 17 | + * An app setting (or environment variable) with the Cosmos DB connection string |
| 18 | + */ |
| 19 | + connectionStringSetting: string; |
| 20 | + |
| 21 | + /** |
| 22 | + * The name of the Azure Cosmos DB database with the collection being monitored |
| 23 | + */ |
| 24 | + databaseName: string; |
| 25 | + |
| 26 | + /** |
| 27 | + * The name of the collection being monitored |
| 28 | + */ |
| 29 | + collectionName: string; |
| 30 | + |
| 31 | + /** |
| 32 | + * Specifies the partition key value for the lookup. May include binding parameters. It is required for lookups in partitioned collections |
| 33 | + */ |
| 34 | + partitionKey?: string; |
| 35 | + |
| 36 | + /** |
| 37 | + * The ID of the document to retrieve. This property supports [binding expressions](https://docs.microsoft.com/azure/azure-functions/functions-bindings-expressions-patterns). |
| 38 | + * Don't set both the id and sqlQuery properties. If you don't set either one, the entire collection is retrieved. |
| 39 | + */ |
| 40 | + id?: string; |
| 41 | + |
| 42 | + /** |
| 43 | + * An Azure Cosmos DB SQL query used for retrieving multiple documents. The property supports runtime bindings, as in this example: |
| 44 | + * `SELECT * FROM c where c.departmentId = {departmentId}` |
| 45 | + * Don't set both the id and sqlQuery properties. If you don't set either one, the entire collection is retrieved. |
| 46 | + */ |
| 47 | + sqlQuery?: string; |
| 48 | +} |
| 49 | +export type CosmosDBInput = FunctionInput & CosmosDBInputOptions; |
| 50 | + |
| 51 | +export interface CosmosDBTriggerOptions extends CosmosDBInputOptions { |
| 52 | + /** |
| 53 | + * The name of an app setting that contains the connection string to the service which holds the lease collection. |
| 54 | + * If not set it will connect to the service defined by `connectionStringSetting` |
| 55 | + */ |
| 56 | + leaseConnectionStringSetting?: string; |
| 57 | + |
| 58 | + /** |
| 59 | + * The name of the database that holds the collection to store leases. If not set, it will use the value of `databaseName` |
| 60 | + */ |
| 61 | + leaseDatabaseName?: string; |
| 62 | + |
| 63 | + /** |
| 64 | + * The name of the collection to store leases. If not set, it will use "leases" |
| 65 | + */ |
| 66 | + leaseCollectionName?: string; |
| 67 | + |
| 68 | + /** |
| 69 | + * Checks for existence and automatically creates the leases collection. Default is `false` |
| 70 | + */ |
| 71 | + createLeaseCollectionIfNotExists?: boolean; |
| 72 | + |
| 73 | + /** |
| 74 | + * When `createLeaseCollectionIfNotExists` is set to `true`, defines the amount of Request Units to assign to the created lease collection |
| 75 | + */ |
| 76 | + leaseCollectionThroughput?: number; |
| 77 | + |
| 78 | + /** |
| 79 | + * When set, the value is added as a prefix to the leases created in the Lease collection for this function. |
| 80 | + * Using a prefix allows two separate Azure Functions to share the same Lease collection by using different prefixes. |
| 81 | + */ |
| 82 | + leaseCollectionPrefix?: string; |
| 83 | +} |
| 84 | +export type CosmosDBTrigger = FunctionTrigger & CosmosDBTriggerOptions; |
| 85 | + |
| 86 | +export interface CosmosDBOutputOptions { |
| 87 | + /** |
| 88 | + * An app setting (or environment variable) with the Cosmos DB connection string |
| 89 | + */ |
| 90 | + connectionStringSetting: string; |
| 91 | + |
| 92 | + /** |
| 93 | + * The name of the Azure Cosmos DB database with the collection being monitored |
| 94 | + */ |
| 95 | + databaseName: string; |
| 96 | + |
| 97 | + /** |
| 98 | + * The name of the collection being monitored |
| 99 | + */ |
| 100 | + collectionName: string; |
| 101 | + |
| 102 | + /** |
| 103 | + * A boolean value to indicate whether the collection is created when it doesn't exist. |
| 104 | + * The default is false because new collections are created with reserved throughput, which has cost implications. For more information, see the [pricing page](https://azure.microsoft.com/pricing/details/cosmos-db/). |
| 105 | + */ |
| 106 | + createIfNotExists?: boolean; |
| 107 | + |
| 108 | + /** |
| 109 | + * When `createIfNotExists` is true, it defines the partition key path for the created collection. May include binding parameters. |
| 110 | + */ |
| 111 | + partitionKey?: string; |
| 112 | + |
| 113 | + /** |
| 114 | + * When createIfNotExists is true, it defines the [throughput](https://docs.microsoft.com/azure/cosmos-db/set-throughput) of the created collection |
| 115 | + */ |
| 116 | + collectionThroughput?: number; |
| 117 | +} |
| 118 | +export type CosmosDBOutput = FunctionOutput & CosmosDBOutputOptions; |
0 commit comments