-
Notifications
You must be signed in to change notification settings - Fork 50
/
durableClient.d.ts
476 lines (428 loc) · 14.9 KB
/
durableClient.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
import {
CosmosDBv3FunctionOptions,
CosmosDBv4FunctionOptions,
EventGridEvent,
EventGridFunctionOptions,
EventHubFunctionOptions,
FunctionInput,
FunctionOptions,
FunctionResult,
HttpFunctionOptions,
HttpRequest,
HttpResponse,
HttpResponseInit,
InvocationContext,
ServiceBusQueueFunctionOptions,
ServiceBusTopicFunctionOptions,
StorageBlobFunctionOptions,
StorageQueueFunctionOptions,
Timer,
TimerFunctionOptions,
} from "@azure/functions";
import { EntityId, EntityStateResponse } from "./entity";
import { DurableOrchestrationStatus, OrchestrationRuntimeStatus } from "./orchestration";
export interface DurableClientInput extends FunctionInput {
type: "durableClient";
}
/**
* Type of a handler function that is triggered by some trigger
* and receives a [[DurableClient]] instance as an input.
*/
export type DurableClientHandler = (
triggerInput: any,
durableClient: DurableClient,
context: InvocationContext
) => FunctionResult<any>;
/**
* Configures the inputs, outputs, and handler for a Durable Client function.
*/
export interface DurableClientOptions extends Omit<FunctionOptions, "handler"> {
handler: DurableClientHandler;
}
export type HttpDurableClientHandler = (
request: HttpRequest,
client: DurableClient,
context: InvocationContext
) => FunctionResult<HttpResponseInit | HttpResponse>;
/**
* Configures options for an HTTP-triggered Durable Client function.
*/
export interface HttpDurableClientOptions extends Omit<HttpFunctionOptions, "handler"> {
handler: HttpDurableClientHandler;
}
export type TimerDurableClientHandler = (
myTimer: Timer,
client: DurableClient,
context: InvocationContext
) => FunctionResult;
/**
* Configures options for a timer-triggered Durable Client function.
*/
export interface TimerDurableClientOptions extends Omit<TimerFunctionOptions, "handler"> {
handler: TimerDurableClientHandler;
}
export type StorageBlobDurableClientHandler = (
blob: unknown,
client: DurableClient,
context: InvocationContext
) => FunctionResult;
export interface StorageBlobDurableClientOptions
extends Omit<StorageBlobFunctionOptions, "handler"> {
handler: StorageBlobDurableClientHandler;
}
export type StorageQueueDurableClientHandler = (
queueEntry: unknown,
client: DurableClient,
context: InvocationContext
) => FunctionResult;
export interface StorageQueueDurableClientOptions
extends Omit<StorageQueueFunctionOptions, "handler"> {
handler: StorageQueueDurableClientHandler;
}
export type ServiceBusQueueDurableClientHandler = (
message: unknown,
client: DurableClient,
context: InvocationContext
) => FunctionResult;
export interface ServiceBusQueueDurableClientOptions
extends Omit<ServiceBusQueueFunctionOptions, "handler"> {
handler: ServiceBusQueueDurableClientHandler;
}
export type ServiceBusTopicDurableClientHandler = (
message: unknown,
client: DurableClient,
context: InvocationContext
) => FunctionResult;
export interface ServiceBusTopicDurableClientOptions
extends Omit<ServiceBusTopicFunctionOptions, "handler"> {
handler: ServiceBusTopicDurableClientHandler;
}
export type EventHubDurableClientHandler = (
messages: unknown,
client: DurableClient,
context: InvocationContext
) => FunctionResult;
export interface EventHubDurableClientOptions extends Omit<EventHubFunctionOptions, "handler"> {
handler: EventHubDurableClientHandler;
}
export type EventGridDurableClientHandler = (
event: EventGridEvent,
client: DurableClient,
context: InvocationContext
) => FunctionResult;
export interface EventGridDurableClientOptions extends Omit<EventGridFunctionOptions, "handler"> {
handler: EventGridDurableClientHandler;
}
export type CosmosDBDurableClientHandler = (
documents: unknown[],
client: DurableClient,
context: InvocationContext
) => FunctionResult;
export type CosmosDBDurableClientOptions =
| CosmosDBv3DurableClientOptions
| CosmosDBv4DurableClientOptions;
export interface CosmosDBv3DurableClientOptions extends Omit<CosmosDBv3FunctionOptions, "handler"> {
handler: CosmosDBDurableClientHandler;
}
export interface CosmosDBv4DurableClientOptions extends Omit<CosmosDBv4FunctionOptions, "handler"> {
handler: CosmosDBDurableClientHandler;
}
/**
* Client for starting, querying, terminating and raising events to
* orchestration and entity instances.
*/
export declare class DurableClient {
/**
* The name of the task hub configured on this orchestration client
* instance.
*/
readonly taskHubName: string;
/** @hidden */
public readonly uniqueWebhookOrigins: string[];
/**
* Creates an HTTP response that is useful for checking the status of the
* specified instance.
* @param request The HTTP request that triggered the current orchestration
* instance.
* @param instanceId The ID of the orchestration instance to check.
* @returns An HTTP 202 response with a Location header and a payload
* containing instance management URLs.
*/
createCheckStatusResponse(request: HttpRequest | undefined, instanceId: string): HttpResponse;
/**
* Creates an [[HttpManagementPayload]] object that contains instance
* management HTTP endpoints.
* @param instanceId The ID of the orchestration instance to check.
*/
createHttpManagementPayload(instanceId: string): HttpManagementPayload;
/**
* Gets the status of the specified orchestration instance.
* @param instanceId The ID of the orchestration instance to query.
* @param options options object specifying extra configuration
*/
getStatus(instanceId: string, options?: GetStatusOptions): Promise<DurableOrchestrationStatus>;
/**
* Gets the status of all orchestration instances.
*/
getStatusAll(): Promise<DurableOrchestrationStatus[]>;
/**
* Gets the status of all orchestration instances that match the specified
* conditions.
*
* @param filter the OrchestrationFilter object specifying which
* orchestrations to retrieve.
*/
getStatusBy(filter: OrchestrationFilter): Promise<DurableOrchestrationStatus[]>;
/**
* Purge the history for a specific orchestration instance.
* @param instanceId The ID of the orchestration instance to purge.
*/
purgeInstanceHistory(instanceId: string): Promise<PurgeHistoryResult>;
/**
* Purge the orchestration history for instances that match the conditions.
* @param filter the OrchestrationFilter object specifying which
* orchestrations to purge.
*/
purgeInstanceHistoryBy(filter: OrchestrationFilter): Promise<PurgeHistoryResult>;
/**
* Sends an event notification message to a waiting orchestration instance.
*
* @param instanceId The ID of the orchestration instance that will handle
* the event.
* @param eventName The name of the event.
* @param eventData The JSON-serializable data associated with the event.
* @param options object providing TaskHubName of the orchestration instance and
* the name of its associated connection string
*
* @returns A promise that resolves when the event notification message has
* been enqueued.
*
* In order to handle the event, the target orchestration instance must be
* waiting for an event named `eventName` using
* [[waitForExternalEvent]].
*
* If the specified instance is not found or not running, this operation
* will have no effect.
*/
raiseEvent(
instanceId: string,
eventName: string,
eventData: unknown,
options?: TaskHubOptions
): Promise<void>;
/**
* Tries to read the current state of an entity. Returns undefined if the
* entity does not exist, or if the JSON-serialized state of the entity is
* larger than 16KB.
*
* @param T The JSON-serializable type of the entity state.
* @param entityId The target entity.
* @param options optional object providing the TaskHubName of the target entity
* and the name of its associated connection string
*
* @returns A response containing the current state of the entity.
*/
readEntityState<T>(
entityId: EntityId,
options?: TaskHubOptions
): Promise<EntityStateResponse<T>>;
/**
* Rewinds the specified failed orchestration instance with a reason.
*
* @param instanceId The ID of the orchestration instance to rewind.
* @param reason The reason for rewinding the orchestration instance.
* @param options object providing TaskHubName of the orchestration instance and
* the name of its associated connection string
*
* @returns A promise that resolves when the rewind message is enqueued.
*
* This feature is currently in preview.
*/
rewind(instanceId: string, reason: string, options?: TaskHubOptions): Promise<void>;
/**
* Signals an entity to perform an operation.
*
* @param entityId The target entity.
* @param operationName The name of the operation.
* @param operationContent The content for the operation.
* @param options object providing TaskHubName of the entity instance and
* the name of its associated connection string
*/
signalEntity(
entityId: EntityId,
operationName?: string,
operationContent?: unknown,
options?: TaskHubOptions
): Promise<void>;
/**
* Starts a new instance of the specified orchestrator function.
*
* If an orchestration instance with the specified ID already exists, the
* existing instance will be silently replaced by this new instance.
* @param orchestratorFunctionName The name of the orchestrator function to
* start.
* @param options optional object to control the scheduled orchestrator (e.g provide input, instanceID)
* @returns The ID of the new orchestration instance.
*/
startNew(orchestratorFunctionName: string, options?: StartNewOptions): Promise<string>;
/**
* Terminates a running orchestration instance.
* @param instanceId The ID of the orchestration instance to terminate.
* @param reason The reason for terminating the orchestration instance.
* @returns A promise that resolves when the terminate message is enqueued.
*
* Terminating an orchestration instance has no effect on any in-flight
* activity function executions or sub-orchestrations that were started
* by the current orchestration instance.
*/
terminate(instanceId: string, reason: string): Promise<void>;
/**
* Creates an HTTP response which either contains a payload of management
* URLs for a non-completed instance or contains the payload containing
* the output of the completed orchestration.
*
* If the orchestration does not complete within the specified timeout,
* then the HTTP response will be identical to that of createCheckStatusResponse().
*
* @param request The HTTP request that triggered the current function.
* @param instanceId The unique ID of the instance to check.
* @param waitOptions options object specifying the timeouts for how long
* to wait for output from the durable function and how often to check for output.
*/
waitForCompletionOrCreateCheckStatusResponse(
request: HttpRequest,
instanceId: string,
waitOptions?: WaitForCompletionOptions
): Promise<HttpResponse>;
}
/**
* Options object provided as an optional second argument to the `client.startNew()` method
*/
export interface StartNewOptions {
/**
* The ID to use for the new orchestration instance. If
* no instanceId is specified, the Durable Functions extension will
* generate a random GUID (recommended).
*/
instanceId?: string;
/**
* JSON-serializable input value for the orchestrator function.
*/
input?: unknown;
}
/**
* Class to hold statistics about this execution of purge history.
* The return type of DurableClient.purgeHistory()
*/
export declare class PurgeHistoryResult {
/**
* The number of deleted instances.
*/
readonly instancesDeleted: number;
/**
* @param instancesDeleted The number of deleted instances
*/
constructor(instancesDeleted: number);
}
/**
* Data structure containing instance management HTTP endpoints.
*/
export declare class HttpManagementPayload {
/**
* The ID of the orchestration instance.
*/
readonly id: string;
/**
* The HTTP GET status query endpoint URL.
*/
readonly statusQueryGetUri: string;
/**
* The HTTP POST external event sending endpoint URL.
*/
readonly sendEventPostUri: string;
/**
* The HTTP POST instance termination endpoint URL.
*/
readonly terminatePostUri: string;
/**
* The HTTP POST instance rewind endpoint URL.
*/
readonly rewindPostUri: string;
/**
* The HTTP DELETE purge endpoint URL.
*/
readonly purgeHistoryDeleteUri: string;
}
/**
* Options object passed to client `getStatus()` method
*/
export interface GetStatusOptions {
/**
* Specifies whether execution history should be included in the response.
*/
showHistory?: boolean;
/**
* Specifies whether input and output should be included in the execution history response.
*/
showHistoryOutput?: boolean;
/**
* Specifies whether orchestration input should be included in the response.
*/
showInput?: boolean;
}
/**
* Options object passed to DurableClient APIs to specify task hub properties
*/
export interface TaskHubOptions {
/**
* The TaskHubName of the orchestration
*/
taskHubName?: string;
/**
* The name of the connection string associated with `taskHubName.`
*/
connectionName?: string;
}
/**
* Options object passed to DurableClient APIs
* to filter orchestrations on which to perform
* actions
*/
export interface OrchestrationFilter {
/**
* Select orchestration instances which were created
* after this Date.
*/
createdTimeFrom?: Date;
/**
* Select orchestration instances which were created
* before this DateTime.
*/
createdTimeTo?: Date;
/**
* Select orchestration instances which match any of
* the runtimeStatus values in this array
*/
runtimeStatus?: OrchestrationRuntimeStatus[];
}
/**
* Options object passed to the `durableClient.waitForCompletionOrCreateCheckStatusResponse()`
* method to specify timeouts for how long to wait for output from the durable function
* and how often to check for output.
*/
export interface WaitForCompletionOptions {
/**
* Total allowed timeout for output from the
* durable function.
*
* @default 10000 (10 seconds)
*/
timeoutInMilliseconds?: number;
/**
* The timeout between checks for output
* from the durable function.
*
* @default 1000 (1 second)
*/
retryIntervalInMilliseconds?: number;
}