UNPKG

3.27 kBTypeScriptView Raw
1// Copyright (c) .NET Foundation. All rights reserved.
2// Licensed under the MIT License.
3
4import { FunctionHandler } from '../index';
5import { InvocationContext } from '../InvocationContext';
6import { HookContext, HookContextInit } from './HookContext';
7
8/**
9 * Handler for pre-invocation hooks.
10 */
11export type PreInvocationHandler = (context: PreInvocationContext) => void | Promise<void>;
12
13/**
14 * Context on a function before it executes.
15 */
16export declare class PreInvocationContext extends InvocationHookContext {
17 /**
18 * For testing purposes only. This will always be constructed for you when run in the context of the Azure Functions runtime
19 */
20 constructor(init?: PreInvocationContextInit);
21
22 /**
23 * The arguments passed to this specific invocation.
24 * Changes to this array _will_ affect the inputs passed to your function
25 */
26 inputs: unknown[];
27
28 /**
29 * The function handler for this specific invocation. Changes to this value _will_ affect the function itself
30 */
31 functionHandler: FunctionHandler;
32}
33
34/**
35 * Handler for post-invocation hooks
36 */
37export type PostInvocationHandler = (context: PostInvocationContext) => void | Promise<void>;
38
39/**
40 * Context on a function after it executes.
41 */
42export declare class PostInvocationContext extends InvocationHookContext {
43 /**
44 * For testing purposes only. This will always be constructed for you when run in the context of the Azure Functions runtime
45 */
46 constructor(init?: PostInvocationContextInit);
47
48 /**
49 * The arguments passed to this specific invocation.
50 */
51 inputs: unknown[];
52
53 /**
54 * The result of the function. Changes to this value _will_ affect the overall result of the function
55 */
56 result: unknown;
57
58 /**
59 * The error thrown by the function, or null/undefined if there is no error. Changes to this value _will_ affect the overall result of the function
60 */
61 error: unknown;
62}
63
64/**
65 * Base class for all invocation hook context objects
66 */
67export declare class InvocationHookContext extends HookContext {
68 /**
69 * For testing purposes only. This will always be constructed for you when run in the context of the Azure Functions runtime
70 */
71 constructor(init?: InvocationHookContextInit);
72
73 /**
74 * The context object passed to the function.
75 * This object is readonly. You may modify it, but attempting to overwrite it will throw an error
76 */
77 readonly invocationContext: InvocationContext;
78}
79
80/**
81 * Object passed to InvocationHookContext constructors.
82 * For testing purposes only
83 */
84export interface InvocationHookContextInit extends HookContextInit {
85 inputs?: unknown[];
86
87 invocationContext?: InvocationContext;
88}
89
90/**
91 * Object passed to PreInvocationContext constructors.
92 * For testing purposes only
93 */
94export interface PreInvocationContextInit extends InvocationHookContextInit {
95 functionCallback?: FunctionHandler;
96}
97
98/**
99 * Object passed to PostInvocationContext constructors.
100 * For testing purposes only
101 */
102export interface PostInvocationContextInit extends InvocationHookContextInit {
103 result?: unknown;
104
105 error?: unknown;
106}