1 | // Copyright (c) .NET Foundation. All rights reserved.
|
2 | // Licensed under the MIT License.
|
3 |
|
4 | import { FunctionInput, FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger, RetryOptions } from './index';
|
5 | import { InvocationContext } from './InvocationContext';
|
6 |
|
7 | export type CosmosDBv4Handler = (documents: unknown[], context: InvocationContext) => FunctionResult;
|
8 |
|
9 | export interface CosmosDBv4FunctionOptions extends CosmosDBv4TriggerOptions, Partial<FunctionOptions> {
|
10 | handler: CosmosDBv4Handler;
|
11 |
|
12 | trigger?: CosmosDBv4Trigger;
|
13 |
|
14 | /**
|
15 | * An optional retry policy to rerun a failed execution until either successful completion occurs or the maximum number of retries is reached.
|
16 | * Learn more [here](https://learn.microsoft.com/azure/azure-functions/functions-bindings-error-pages)
|
17 | */
|
18 | retry?: RetryOptions;
|
19 | }
|
20 |
|
21 | export interface CosmosDBv4InputOptions {
|
22 | /**
|
23 | * An app setting (or environment variable) with the Cosmos DB connection string
|
24 | */
|
25 | connection: string;
|
26 |
|
27 | /**
|
28 | * The name of the Azure Cosmos DB database with the container being monitored
|
29 | */
|
30 | databaseName: string;
|
31 |
|
32 | /**
|
33 | * The name of the container being monitored
|
34 | */
|
35 | containerName: string;
|
36 |
|
37 | /**
|
38 | * Specifies the partition key value for the lookup. May include binding parameters. It is required for lookups in partitioned containers
|
39 | */
|
40 | partitionKey?: string;
|
41 |
|
42 | /**
|
43 | * The ID of the document to retrieve. This property supports [binding expressions](https://docs.microsoft.com/azure/azure-functions/functions-bindings-expressions-patterns).
|
44 | * Don't set both the id and sqlQuery properties. If you don't set either one, the entire container is retrieved.
|
45 | */
|
46 | id?: string;
|
47 |
|
48 | /**
|
49 | * An Azure Cosmos DB SQL query used for retrieving multiple documents. The property supports runtime bindings, as in this example:
|
50 | * `SELECT * FROM c where c.departmentId = {departmentId}`
|
51 | * Don't set both the id and sqlQuery properties. If you don't set either one, the entire container is retrieved.
|
52 | */
|
53 | sqlQuery?: string;
|
54 |
|
55 | /**
|
56 | * Defines preferred locations (regions) for geo-replicated database accounts in the Azure Cosmos DB service.
|
57 | * Values should be comma-separated. For example, East US,South Central US,North Europe
|
58 | */
|
59 | preferredLocations?: string;
|
60 | }
|
61 | export type CosmosDBv4Input = FunctionInput & CosmosDBv4InputOptions;
|
62 |
|
63 | export interface CosmosDBv4TriggerOptions {
|
64 | /**
|
65 | * An app setting (or environment variable) with the Cosmos DB connection string
|
66 | */
|
67 | connection: string;
|
68 |
|
69 | /**
|
70 | * The name of the Azure Cosmos DB database with the container being monitored
|
71 | */
|
72 | databaseName: string;
|
73 |
|
74 | /**
|
75 | * The name of the container being monitored
|
76 | */
|
77 | containerName: string;
|
78 |
|
79 | /**
|
80 | * The name of an app setting that contains the connection string to the service which holds the lease container.
|
81 | * If not set it will connect to the service defined by `connection`
|
82 | */
|
83 | leaseConnection?: string;
|
84 |
|
85 | /**
|
86 | * The name of the database that holds the container to store leases. If not set, it will use the value of `databaseName`
|
87 | */
|
88 | leaseDatabaseName?: string;
|
89 |
|
90 | /**
|
91 | * The name of the container to store leases. If not set, it will use "leases"
|
92 | */
|
93 | leaseContainerName?: string;
|
94 |
|
95 | /**
|
96 | * Checks for existence and automatically creates the leases container. Default is `false`
|
97 | */
|
98 | createLeaseContainerIfNotExists?: boolean;
|
99 |
|
100 | /**
|
101 | * When `createLeaseContainerIfNotExists` is set to `true`, defines the amount of Request Units to assign to the created lease container
|
102 | */
|
103 | leasesContainerThroughput?: number;
|
104 |
|
105 | /**
|
106 | * When set, the value is added as a prefix to the leases created in the Lease container for this function.
|
107 | * Using a prefix allows two separate Azure Functions to share the same Lease container by using different prefixes.
|
108 | */
|
109 | leaseContainerPrefix?: string;
|
110 |
|
111 | /**
|
112 | * The time (in milliseconds) for the delay between polling a partition for new changes on the feed, after all current changes are drained.
|
113 | * Default is 5,000 milliseconds, or 5 seconds.
|
114 | */
|
115 | feedPollDelay?: number;
|
116 |
|
117 | /**
|
118 | * When set, it defines, in milliseconds, the interval to kick off a task to compute if partitions are distributed evenly among known host instances.
|
119 | * Default is 13000 (13 seconds).
|
120 | */
|
121 | leaseAcquireInterval?: number;
|
122 |
|
123 | /**
|
124 | * When set, it defines, in milliseconds, the interval for which the lease is taken on a lease representing a partition.
|
125 | * If the lease is not renewed within this interval, it will cause it to expire and ownership of the partition will move to another instance.
|
126 | * Default is 60000 (60 seconds).
|
127 | */
|
128 | leaseExpirationInterval?: number;
|
129 |
|
130 | /**
|
131 | * When set, it defines, in milliseconds, the renew interval for all leases for partitions currently held by an instance.
|
132 | * Default is 17000 (17 seconds).
|
133 | */
|
134 | leaseRenewInterval?: number;
|
135 |
|
136 | /**
|
137 | * When set, this property sets the maximum number of items received per Function call.
|
138 | * If operations in the monitored container are performed through stored procedures, transaction scope is preserved when reading items from the change feed.
|
139 | * As a result, the number of items received could be higher than the specified value so that the items changed by the same transaction are returned as part of one atomic batch.
|
140 | */
|
141 | maxItemsPerInvocation?: number;
|
142 |
|
143 | /**
|
144 | * This option tells the Trigger to read changes from the beginning of the container's change history instead of starting at the current time.
|
145 | * Reading from the beginning only works the first time the trigger starts, as in subsequent runs, the checkpoints are already stored.
|
146 | * Setting this option to true when there are leases already created has no effect.
|
147 | */
|
148 | startFromBeginning?: boolean;
|
149 |
|
150 | /**
|
151 | * Gets or sets the date and time from which to initialize the change feed read operation.
|
152 | * The recommended format is ISO 8601 with the UTC designator, such as 2021-02-16T14:19:29Z.
|
153 | * This is only used to set the initial trigger state. After the trigger has a lease state, changing this value has no effect.
|
154 | */
|
155 | startFromTime?: string;
|
156 |
|
157 | /**
|
158 | * Defines preferred locations (regions) for geo-replicated database accounts in the Azure Cosmos DB service.
|
159 | * Values should be comma-separated. For example, East US,South Central US,North Europe
|
160 | */
|
161 | preferredLocations?: string;
|
162 | }
|
163 | export type CosmosDBv4Trigger = FunctionTrigger & CosmosDBv4TriggerOptions;
|
164 |
|
165 | export interface CosmosDBv4OutputOptions {
|
166 | /**
|
167 | * An app setting (or environment variable) with the Cosmos DB connection string
|
168 | */
|
169 | connection: string;
|
170 |
|
171 | /**
|
172 | * The name of the Azure Cosmos DB database with the collection being monitored
|
173 | */
|
174 | databaseName: string;
|
175 |
|
176 | /**
|
177 | * The name of the collection being monitored
|
178 | */
|
179 | containerName: string;
|
180 |
|
181 | /**
|
182 | * A boolean value to indicate whether the collection is created when it doesn't exist.
|
183 | * 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/).
|
184 | */
|
185 | createIfNotExists?: boolean;
|
186 |
|
187 | /**
|
188 | * When `createIfNotExists` is true, it defines the partition key path for the created collection. May include binding parameters.
|
189 | */
|
190 | partitionKey?: string;
|
191 |
|
192 | /**
|
193 | * When createIfNotExists is true, it defines the [throughput](https://docs.microsoft.com/azure/cosmos-db/set-throughput) of the created collection
|
194 | */
|
195 | containerThroughput?: number;
|
196 |
|
197 | /**
|
198 | * Defines preferred locations (regions) for geo-replicated database accounts in the Azure Cosmos DB service.
|
199 | * Values should be comma-separated. For example, East US,South Central US,North Europe
|
200 | */
|
201 | preferredLocations?: string;
|
202 | }
|
203 | export type CosmosDBv4Output = FunctionOutput & CosmosDBv4OutputOptions;
|