Skip to content

Commit

Permalink
App trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
phanthaiduong22 committed Oct 23, 2024
1 parent 5d402f9 commit 840a04a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
StorageQueueFunctionOptions,
TimerFunctionOptions,
WarmupFunctionOptions,
WebPubSubFunctionOptions,
} from '@azure/functions';
import { FunctionCallback } from '@azure/functions-core';
import { toCoreFunctionMetadata } from './converters/toCoreFunctionMetadata';
Expand Down Expand Up @@ -135,6 +136,10 @@ export function sql(name: string, options: SqlFunctionOptions): void {
generic(name, convertToGenericOptions(options, trigger.sql));
}

export function webPubSub(name: string, options: WebPubSubFunctionOptions): void {
generic(name, convertToGenericOptions(options, trigger.webPubSub));
}

export function generic(name: string, options: GenericFunctionOptions): void {
if (!hasSetModel) {
setProgrammingModel();
Expand Down
8 changes: 8 additions & 0 deletions types/InvocationContext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ServiceBusQueueOutput, ServiceBusTopicOutput } from './serviceBus';
import { SqlInput, SqlOutput } from './sql';
import { StorageBlobInput, StorageBlobOutput, StorageQueueOutput } from './storage';
import { TableInput, TableOutput } from './table';
import { WebPubSubOutput } from './webpubsub';

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

/**
* Set a secondary Web PubSub output for this invocation
* @output the configuration object for this Web PubSub output
* @message the output message(s) value
*/
set(output: WebPubSubOutput, messages: unknown): void;

/**
* Set a secondary generic output for this invocation
* @outputOrName the configuration object or name for this output
Expand Down
8 changes: 8 additions & 0 deletions types/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SqlFunctionOptions } from './sql';
import { StorageBlobFunctionOptions, StorageQueueFunctionOptions } from './storage';
import { TimerFunctionOptions } from './timer';
import { WarmupFunctionOptions } from './warmup';
import { WebPubSubFunctionOptions } from './webpubsub';

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

/**
* Registers a WebPubSub function in your app that will be triggered by WebPubSub events
* @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
* @param options Configuration options describing the inputs, outputs, and handler for this function
*/
export function webPubSub(name: string, options: WebPubSubFunctionOptions): void;

export * as hook from './hooks/registerHook';
14 changes: 12 additions & 2 deletions types/webpubsub.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.

import { FunctionInput, FunctionOutput, FunctionTrigger } from './index';
import { FunctionInput, FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger } from './index';
import { InvocationContext } from './InvocationContext';

export type WebPubSubHandler = (message: unknown, context: InvocationContext) => FunctionResult;

export interface WebPubSubFunctionOptions extends WebPubSubTriggerOptions, Partial<FunctionOptions> {
handler: WebPubSubHandler;

trigger?: WebPubSubTrigger;
}

export interface WebPubSubTriggerOptions {
/**
Expand Down Expand Up @@ -42,13 +51,14 @@ export interface WebPubSubTriggerOptions {
*/
connection?: string | null;
}

export type WebPubSubTrigger = FunctionTrigger & WebPubSubTriggerOptions;

export interface WebPubSubConnectionInputOptions {
/**
* Required - Variable name used in function code for input connection binding object.
*/
name?: string;
name: string;

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

0 comments on commit 840a04a

Please sign in to comment.