UNPKG

3.02 kBPlain TextView Raw
1// Copyright (c) .NET Foundation. All rights reserved.
2// Licensed under the MIT License.
3
4import {
5 CosmosDBTrigger,
6 CosmosDBTriggerOptions,
7 EventGridTrigger,
8 EventGridTriggerOptions,
9 EventHubTrigger,
10 EventHubTriggerOptions,
11 FunctionTrigger,
12 GenericTriggerOptions,
13 HttpTrigger,
14 HttpTriggerOptions,
15 ServiceBusQueueTrigger,
16 ServiceBusQueueTriggerOptions,
17 ServiceBusTopicTrigger,
18 ServiceBusTopicTriggerOptions,
19 StorageBlobTrigger,
20 StorageBlobTriggerOptions,
21 StorageQueueTrigger,
22 StorageQueueTriggerOptions,
23 TimerTrigger,
24 TimerTriggerOptions,
25 WarmupTrigger,
26 WarmupTriggerOptions,
27} from '@azure/functions';
28import { addBindingName } from './addBindingName';
29
30export function http(options: HttpTriggerOptions): HttpTrigger {
31 return addTriggerBindingName({
32 ...options,
33 authLevel: options.authLevel || 'anonymous',
34 methods: options.methods || ['GET', 'POST'],
35 type: 'httpTrigger',
36 });
37}
38
39export function timer(options: TimerTriggerOptions): TimerTrigger {
40 return addTriggerBindingName({
41 ...options,
42 type: 'timerTrigger',
43 });
44}
45
46export function storageBlob(options: StorageBlobTriggerOptions): StorageBlobTrigger {
47 return addTriggerBindingName({
48 ...options,
49 type: 'blobTrigger',
50 });
51}
52
53export function storageQueue(options: StorageQueueTriggerOptions): StorageQueueTrigger {
54 return addTriggerBindingName({
55 ...options,
56 type: 'queueTrigger',
57 });
58}
59
60export function serviceBusQueue(options: ServiceBusQueueTriggerOptions): ServiceBusQueueTrigger {
61 return addTriggerBindingName({
62 ...options,
63 type: 'serviceBusTrigger',
64 });
65}
66
67export function serviceBusTopic(options: ServiceBusTopicTriggerOptions): ServiceBusTopicTrigger {
68 return addTriggerBindingName({
69 ...options,
70 type: 'serviceBusTrigger',
71 });
72}
73
74export function eventHub(options: EventHubTriggerOptions): EventHubTrigger {
75 return addTriggerBindingName({
76 ...options,
77 type: 'eventHubTrigger',
78 });
79}
80
81export function eventGrid(options: EventGridTriggerOptions): EventGridTrigger {
82 return addTriggerBindingName({
83 ...options,
84 type: 'eventGridTrigger',
85 });
86}
87
88export function cosmosDB(options: CosmosDBTriggerOptions): CosmosDBTrigger {
89 return addTriggerBindingName({
90 ...options,
91 type: 'cosmosDBTrigger',
92 });
93}
94
95export function warmup(options: WarmupTriggerOptions): WarmupTrigger {
96 return addTriggerBindingName({
97 ...options,
98 type: 'warmupTrigger',
99 });
100}
101
102export function generic(options: GenericTriggerOptions): FunctionTrigger {
103 return addTriggerBindingName(options);
104}
105
106function addTriggerBindingName<T extends { type: string; name?: string }>(binding: T): T & { name: string } {
107 return addBindingName(binding, 'Trigger');
108}