UNPKG

6.44 kBTypeScriptView Raw
1// Copyright (c) .NET Foundation. All rights reserved.
2// Licensed under the MIT License.
3
4import { InvocationContext } from './InvocationContext';
5
6export * as app from './app';
7export * from './cosmosDB';
8export * from './cosmosDB.v3';
9export * from './cosmosDB.v4';
10export * from './eventGrid';
11export * from './eventHub';
12export * from './generic';
13export * from './hooks/appHooks';
14export * from './hooks/HookContext';
15export * from './hooks/invocationHooks';
16export * from './http';
17export * as input from './input';
18export * from './InvocationContext';
19export * as output from './output';
20export * from './serviceBus';
21export * from './sql';
22export * from './storage';
23export * from './table';
24export * from './timer';
25export * as trigger from './trigger';
26export * from './warmup';
27
28/**
29 * Void if no `return` output is registered
30 * Otherwise, the registered `return` output
31 */
32export type FunctionResult<T = unknown> = T | Promise<T>;
33
34export type FunctionHandler = (triggerInput: any, context: InvocationContext) => FunctionResult<any>;
35
36/**
37 * Configures the inputs, outputs, and handler for an Azure Function
38 */
39export interface FunctionOptions {
40 /**
41 * The code that will be executed when your function is triggered
42 */
43 handler: FunctionHandler;
44
45 /**
46 * Configuration for the primary input to the function, aka the reason it will be triggered
47 * This is the only input that is passed as an argument to the function handler during invocation
48 */
49 trigger: FunctionTrigger;
50
51 /**
52 * Configuration for the optional primary output of the function
53 * This is the main output that you should set as the return value of the function handler during invocation
54 */
55 return?: FunctionOutput;
56
57 /**
58 * Configuration for an optional set of secondary inputs
59 * During invocation, get these values with `context.extraInputs.get()`
60 */
61 extraInputs?: FunctionInput[];
62
63 /**
64 * Configuration for an optional set of secondary outputs
65 * During invocation, set these values with `context.extraOutputs.set()`
66 */
67 extraOutputs?: FunctionOutput[];
68}
69
70/**
71 * Full configuration for the primary input to a function
72 */
73export interface FunctionTrigger extends Record<string, unknown> {
74 /**
75 * The type for this trigger ('httpTrigger', 'timerTrigger', etc.)
76 * If using the `trigger` namespace to create this object, the type will be set for you
77 */
78 type: string;
79
80 /**
81 * Must be unique within this function.
82 * If using the `trigger` namespace to create this object, the name will be auto-generated for you
83 */
84 name: string;
85}
86
87/**
88 * Full configuration for the secondary input to a function ("trigger" is the primary input)
89 * NOTE: Not all triggers can be used as secondary inputs
90 */
91export interface FunctionInput extends Record<string, unknown> {
92 /**
93 * The type for this trigger ('blob', 'cosmosDB', etc.)
94 * If using the `input` namespace to create this object, the type will be set for you
95 */
96 type: string;
97
98 /**
99 * Must be unique within this function.
100 * If using the `input` namespace to create this object, the name will be auto-generated for you
101 */
102 name: string;
103}
104
105/**
106 * Full configuration for the output to a function
107 */
108export interface FunctionOutput extends Record<string, unknown> {
109 /**
110 * The type for this output ('http', 'blob', 'queue', etc.)
111 * If using the `output` namespace to create this object, the type will be set for you
112 */
113 type: string;
114
115 /**
116 * Must be unique within this function.
117 * If using the `output` namespace to create this object, the name will be auto-generated for you
118 */
119 name: string;
120}
121
122export type RetryOptions = FixedDelayRetryOptions | ExponentialBackoffRetryOptions;
123
124export interface FixedDelayRetryOptions {
125 /**
126 * A specified amount of time is allowed to elapse between each retry.
127 */
128 strategy: 'fixedDelay';
129
130 /**
131 * The maximum number of retries allowed per function execution. -1 means to retry indefinitely.
132 */
133 maxRetryCount: number;
134
135 /**
136 * The delay that's used between retries.
137 * This can be a number in milliseconds or a Duration object
138 */
139 delayInterval: Duration | number;
140}
141
142export interface ExponentialBackoffRetryOptions {
143 /**
144 * The first retry waits for the minimum delay. On subsequent retries, time is added exponentially to
145 * the initial duration for each retry, until the maximum delay is reached. Exponential back-off adds
146 * some small randomization to delays to stagger retries in high-throughput scenarios.
147 */
148 strategy: 'exponentialBackoff';
149
150 /**
151 * The maximum number of retries allowed per function execution. -1 means to retry indefinitely.
152 */
153 maxRetryCount: number;
154
155 /**
156 * The minimum retry delay.
157 * This can be a number in milliseconds, or a Duration object
158 */
159 minimumInterval: Duration | number;
160
161 /**
162 * The maximum retry delay.
163 * This can be a number in milliseconds, or a Duration object
164 */
165 maximumInterval: Duration | number;
166}
167
168export interface Duration {
169 hours?: number;
170 minutes?: number;
171 seconds?: number;
172 milliseconds?: number;
173}
174
175/**
176 * Represents a type which can release resources, such as event listening or a timer.
177 */
178export declare class Disposable {
179 /**
180 * Combine many disposable-likes into one. You can use this method when having objects with a dispose function which aren't instances of `Disposable`.
181 *
182 * @param disposableLikes Objects that have at least a `dispose`-function member. Note that asynchronous dispose-functions aren't awaited.
183 * @return Returns a new disposable which, upon dispose, will dispose all provided disposables.
184 */
185 static from(...disposableLikes: { dispose: () => any }[]): Disposable;
186
187 /**
188 * Creates a new disposable that calls the provided function on dispose.
189 * *Note* that an asynchronous function is not awaited.
190 *
191 * @param callOnDispose Function that disposes something.
192 */
193 constructor(callOnDispose: () => any);
194
195 /**
196 * Dispose this object.
197 */
198 dispose(): any;
199}