Skip to content

Commit 840a04a

Browse files
App trigger
1 parent 5d402f9 commit 840a04a

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

src/app.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
StorageQueueFunctionOptions,
1919
TimerFunctionOptions,
2020
WarmupFunctionOptions,
21+
WebPubSubFunctionOptions,
2122
} from '@azure/functions';
2223
import { FunctionCallback } from '@azure/functions-core';
2324
import { toCoreFunctionMetadata } from './converters/toCoreFunctionMetadata';
@@ -135,6 +136,10 @@ export function sql(name: string, options: SqlFunctionOptions): void {
135136
generic(name, convertToGenericOptions(options, trigger.sql));
136137
}
137138

139+
export function webPubSub(name: string, options: WebPubSubFunctionOptions): void {
140+
generic(name, convertToGenericOptions(options, trigger.webPubSub));
141+
}
142+
138143
export function generic(name: string, options: GenericFunctionOptions): void {
139144
if (!hasSetModel) {
140145
setProgrammingModel();

types/InvocationContext.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ServiceBusQueueOutput, ServiceBusTopicOutput } from './serviceBus';
1010
import { SqlInput, SqlOutput } from './sql';
1111
import { StorageBlobInput, StorageBlobOutput, StorageQueueOutput } from './storage';
1212
import { TableInput, TableOutput } from './table';
13+
import { WebPubSubOutput } from './webpubsub';
1314

1415
/**
1516
* Contains metadata and helper methods specific to this invocation
@@ -216,6 +217,13 @@ export interface InvocationContextExtraOutputs {
216217
*/
217218
set(output: EventGridOutput, events: EventGridPartialEvent | EventGridPartialEvent[]): void;
218219

220+
/**
221+
* Set a secondary Web PubSub output for this invocation
222+
* @output the configuration object for this Web PubSub output
223+
* @message the output message(s) value
224+
*/
225+
set(output: WebPubSubOutput, messages: unknown): void;
226+
219227
/**
220228
* Set a secondary generic output for this invocation
221229
* @outputOrName the configuration object or name for this output

types/app.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { SqlFunctionOptions } from './sql';
1212
import { StorageBlobFunctionOptions, StorageQueueFunctionOptions } from './storage';
1313
import { TimerFunctionOptions } from './timer';
1414
import { WarmupFunctionOptions } from './warmup';
15+
import { WebPubSubFunctionOptions } from './webpubsub';
1516

1617
/**
1718
* Optional method to configure the behavior of your app.
@@ -180,4 +181,11 @@ export function sql(name: string, options: SqlFunctionOptions): void;
180181
*/
181182
export function generic(name: string, options: GenericFunctionOptions): void;
182183

184+
/**
185+
* Registers a WebPubSub function in your app that will be triggered by WebPubSub events
186+
* @param name The name of the function. The name must be unique within your app and will mostly be used for your own tracking purposes
187+
* @param options Configuration options describing the inputs, outputs, and handler for this function
188+
*/
189+
export function webPubSub(name: string, options: WebPubSubFunctionOptions): void;
190+
183191
export * as hook from './hooks/registerHook';

types/webpubsub.d.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import { FunctionInput, FunctionOutput, FunctionTrigger } from './index';
4+
import { FunctionInput, FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger } from './index';
5+
import { InvocationContext } from './InvocationContext';
6+
7+
export type WebPubSubHandler = (message: unknown, context: InvocationContext) => FunctionResult;
8+
9+
export interface WebPubSubFunctionOptions extends WebPubSubTriggerOptions, Partial<FunctionOptions> {
10+
handler: WebPubSubHandler;
11+
12+
trigger?: WebPubSubTrigger;
13+
}
514

615
export interface WebPubSubTriggerOptions {
716
/**
@@ -42,13 +51,14 @@ export interface WebPubSubTriggerOptions {
4251
*/
4352
connection?: string | null;
4453
}
54+
4555
export type WebPubSubTrigger = FunctionTrigger & WebPubSubTriggerOptions;
4656

4757
export interface WebPubSubConnectionInputOptions {
4858
/**
4959
* Required - Variable name used in function code for input connection binding object.
5060
*/
51-
name?: string;
61+
name: string;
5262

5363
/**
5464
* Required - The name of the Web PubSub hub for the function to be triggered.

0 commit comments

Comments
 (0)