From cf9918a5fc6edbe110fc3aefa8918ec3d838d7cb Mon Sep 17 00:00:00 2001 From: Swapnil Nagar Date: Fri, 21 Nov 2025 11:38:05 -0800 Subject: [PATCH] Interfaces with Generics --- types/app.d.ts | 29 +++++++++++++++++------------ types/cosmosDB.d.ts | 4 ++-- types/cosmosDB.v3.d.ts | 6 +++--- types/cosmosDB.v4.d.ts | 6 +++--- types/eventGrid.d.ts | 8 +++++--- types/eventHub.d.ts | 6 +++--- types/mcpTool.d.ts | 6 +++--- types/mySql.d.ts | 10 +++++----- types/serviceBus.d.ts | 16 ++++++++++------ types/sql.d.ts | 10 +++++----- types/storage.d.ts | 12 ++++++------ types/webpubsub.d.ts | 6 +++--- 12 files changed, 65 insertions(+), 54 deletions(-) diff --git a/types/app.d.ts b/types/app.d.ts index db3e059d..b49952cd 100644 --- a/types/app.d.ts +++ b/types/app.d.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import { CosmosDBFunctionOptions } from './cosmosDB'; -import { EventGridFunctionOptions } from './eventGrid'; +import { EventGridEvent, EventGridFunctionOptions } from './eventGrid'; import { EventHubFunctionOptions } from './eventHub'; import { GenericFunctionOptions } from './generic'; import { HttpFunctionOptions, HttpHandler, HttpMethodFunctionOptions } from './http'; @@ -112,49 +112,49 @@ export function timer(name: string, options: TimerFunctionOptions): void; * @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 storageBlob(name: string, options: StorageBlobFunctionOptions): void; +export function storageBlob(name: string, options: StorageBlobFunctionOptions): void; /** * Registers a function in your app that will be triggered whenever an item is added to a storage queue * @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 storageQueue(name: string, options: StorageQueueFunctionOptions): void; +export function storageQueue(name: string, options: StorageQueueFunctionOptions): void; /** * Registers a function in your app that will be triggered whenever a message is added to a service bus queue * @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 serviceBusQueue(name: string, options: ServiceBusQueueFunctionOptions): void; +export function serviceBusQueue(name: string, options: ServiceBusQueueFunctionOptions): void; /** * Registers a function in your app that will be triggered whenever a message is added to a service bus topic * @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 serviceBusTopic(name: string, options: ServiceBusTopicFunctionOptions): void; +export function serviceBusTopic(name: string, options: ServiceBusTopicFunctionOptions): void; /** * Registers a function in your app that will be triggered whenever a message is added to an event hub * @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 eventHub(name: string, options: EventHubFunctionOptions): void; +export function eventHub(name: string, options: EventHubFunctionOptions): void; /** * Registers a function in your app that will be triggered whenever an event is sent by an event grid source * @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 eventGrid(name: string, options: EventGridFunctionOptions): void; +export function eventGrid(name: string, options: EventGridFunctionOptions): void; /** * Registers a Cosmos DB function in your app that will be triggered whenever inserts and updates occur (not deletions) * @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 cosmosDB(name: string, options: CosmosDBFunctionOptions): void; +export function cosmosDB(name: string, options: CosmosDBFunctionOptions): void; /** * Registers a function in your app that will be triggered when an instance is added to scale a running function app. @@ -173,14 +173,14 @@ export function warmup(name: string, options: WarmupFunctionOptions): void; * @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 sql(name: string, options: SqlFunctionOptions): void; +export function sql(name: string, options: SqlFunctionOptions): void; /** * Registers a MySql function in your app that will be triggered when a row is created or updated * @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 mySql(name: string, options: MySqlFunctionOptions): void; +export function mySql(name: string, options: MySqlFunctionOptions): void; /** * Registers a generic function in your app that will be triggered based on the type specified in `options.trigger.type` @@ -195,8 +195,13 @@ export function generic(name: string, options: GenericFunctionOptions): void; * @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 function webPubSub(name: string, options: WebPubSubFunctionOptions): void; -export function mcpTool(name: string, options: McpToolFunctionOptions): void; +/** + * Registers an MCP Tool function in your app + * @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 mcpTool(name: string, options: McpToolFunctionOptions): void; export * as hook from './hooks/registerHook'; diff --git a/types/cosmosDB.d.ts b/types/cosmosDB.d.ts index 8aecad9c..2f8398e3 100644 --- a/types/cosmosDB.d.ts +++ b/types/cosmosDB.d.ts @@ -22,9 +22,9 @@ import { CosmosDBv4TriggerOptions, } from './cosmosDB.v4'; -export type CosmosDBHandler = CosmosDBv3Handler | CosmosDBv4Handler; +export type CosmosDBHandler = CosmosDBv3Handler | CosmosDBv4Handler; -export type CosmosDBFunctionOptions = CosmosDBv3FunctionOptions | CosmosDBv4FunctionOptions; +export type CosmosDBFunctionOptions = CosmosDBv3FunctionOptions | CosmosDBv4FunctionOptions; export type CosmosDBInputOptions = CosmosDBv3InputOptions | CosmosDBv4InputOptions; export type CosmosDBInput = CosmosDBv3Input | CosmosDBv4Input; diff --git a/types/cosmosDB.v3.d.ts b/types/cosmosDB.v3.d.ts index 4fec1f16..00de85f8 100644 --- a/types/cosmosDB.v3.d.ts +++ b/types/cosmosDB.v3.d.ts @@ -4,10 +4,10 @@ import { FunctionInput, FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger, RetryOptions } from './index'; import { InvocationContext } from './InvocationContext'; -export type CosmosDBv3Handler = (documents: unknown[], context: InvocationContext) => FunctionResult; +export type CosmosDBv3Handler = (documents: T[], context: InvocationContext) => FunctionResult; -export interface CosmosDBv3FunctionOptions extends CosmosDBv3TriggerOptions, Partial { - handler: CosmosDBv3Handler; +export interface CosmosDBv3FunctionOptions extends CosmosDBv3TriggerOptions, Partial { + handler: CosmosDBv3Handler; trigger?: CosmosDBv3Trigger; diff --git a/types/cosmosDB.v4.d.ts b/types/cosmosDB.v4.d.ts index f62162c5..f9015bba 100644 --- a/types/cosmosDB.v4.d.ts +++ b/types/cosmosDB.v4.d.ts @@ -4,10 +4,10 @@ import { FunctionInput, FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger, RetryOptions } from './index'; import { InvocationContext } from './InvocationContext'; -export type CosmosDBv4Handler = (documents: unknown[], context: InvocationContext) => FunctionResult; +export type CosmosDBv4Handler = (documents: T[], context: InvocationContext) => FunctionResult; -export interface CosmosDBv4FunctionOptions extends CosmosDBv4TriggerOptions, Partial { - handler: CosmosDBv4Handler; +export interface CosmosDBv4FunctionOptions extends CosmosDBv4TriggerOptions, Partial { + handler: CosmosDBv4Handler; trigger?: CosmosDBv4Trigger; diff --git a/types/eventGrid.d.ts b/types/eventGrid.d.ts index 039bc62e..12ceafea 100644 --- a/types/eventGrid.d.ts +++ b/types/eventGrid.d.ts @@ -4,10 +4,12 @@ import { FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger } from './index'; import { InvocationContext } from './InvocationContext'; -export type EventGridHandler = (event: EventGridEvent, context: InvocationContext) => FunctionResult; +export type EventGridHandler = (event: T, context: InvocationContext) => FunctionResult; -export interface EventGridFunctionOptions extends EventGridTriggerOptions, Partial { - handler: EventGridHandler; +export interface EventGridFunctionOptions + extends EventGridTriggerOptions, + Partial { + handler: EventGridHandler; trigger?: EventGridTrigger; } diff --git a/types/eventHub.d.ts b/types/eventHub.d.ts index 2e1ddcb7..d6a96cd1 100644 --- a/types/eventHub.d.ts +++ b/types/eventHub.d.ts @@ -4,10 +4,10 @@ import { FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger, RetryOptions } from './index'; import { InvocationContext } from './InvocationContext'; -export type EventHubHandler = (messages: unknown, context: InvocationContext) => FunctionResult; +export type EventHubHandler = (messages: T, context: InvocationContext) => FunctionResult; -export interface EventHubFunctionOptions extends EventHubTriggerOptions, Partial { - handler: EventHubHandler; +export interface EventHubFunctionOptions extends EventHubTriggerOptions, Partial { + handler: EventHubHandler; trigger?: EventHubTrigger; diff --git a/types/mcpTool.d.ts b/types/mcpTool.d.ts index ce1b669f..7f4eedf6 100644 --- a/types/mcpTool.d.ts +++ b/types/mcpTool.d.ts @@ -11,17 +11,17 @@ import { InvocationContext } from './InvocationContext'; * @param context - The invocation context for the function. * @returns A result that can be a promise or a synchronous value. */ -export type McpToolTriggerHandler = (messages: unknown, context: InvocationContext) => FunctionResult; +export type McpToolTriggerHandler = (messages: T, context: InvocationContext) => FunctionResult; /** * Configuration options for an MCP Tool function. * This includes trigger-specific options and general function options. */ -export interface McpToolFunctionOptions extends McpToolTriggerOptions, Partial { +export interface McpToolFunctionOptions extends McpToolTriggerOptions, Partial { /** * The handler function to execute when the trigger is invoked. */ - handler: McpToolTriggerHandler; + handler: McpToolTriggerHandler; /** * The trigger configuration for the MCP Tool. diff --git a/types/mySql.d.ts b/types/mySql.d.ts index 82eb69db..1f600e31 100644 --- a/types/mySql.d.ts +++ b/types/mySql.d.ts @@ -4,10 +4,10 @@ import { FunctionInput, FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger } from './index'; import { InvocationContext } from './InvocationContext'; -export type MySqlHandler = (changes: MySqlChange[], context: InvocationContext) => FunctionResult; +export type MySqlHandler = (changes: MySqlChange[], context: InvocationContext) => FunctionResult; -export interface MySqlFunctionOptions extends MySqlTriggerOptions, Partial { - handler: MySqlHandler; +export interface MySqlFunctionOptions extends MySqlTriggerOptions, Partial { + handler: MySqlHandler; trigger?: MySqlTrigger; } @@ -25,8 +25,8 @@ export interface MySqlTriggerOptions { } export type MySqlTrigger = FunctionTrigger & MySqlTriggerOptions; -export interface MySqlChange { - Item: unknown; +export interface MySqlChange { + Item: T; Operation: MySqlChangeOperation; } diff --git a/types/serviceBus.d.ts b/types/serviceBus.d.ts index 41d3f740..69dbbb28 100644 --- a/types/serviceBus.d.ts +++ b/types/serviceBus.d.ts @@ -4,10 +4,12 @@ import { FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger } from './index'; import { InvocationContext } from './InvocationContext'; -export type ServiceBusQueueHandler = (messages: unknown | any, context: InvocationContext) => FunctionResult; +export type ServiceBusQueueHandler = (messages: T, context: InvocationContext) => FunctionResult; -export interface ServiceBusQueueFunctionOptions extends ServiceBusQueueTriggerOptions, Partial { - handler: ServiceBusQueueHandler; +export interface ServiceBusQueueFunctionOptions + extends ServiceBusQueueTriggerOptions, + Partial { + handler: ServiceBusQueueHandler; trigger?: ServiceBusQueueTrigger; } @@ -60,10 +62,12 @@ export interface ServiceBusQueueOutputOptions { } export type ServiceBusQueueOutput = FunctionOutput & ServiceBusQueueOutputOptions; -export type ServiceBusTopicHandler = (message: unknown, context: InvocationContext) => FunctionResult; +export type ServiceBusTopicHandler = (message: T, context: InvocationContext) => FunctionResult; -export interface ServiceBusTopicFunctionOptions extends ServiceBusTopicTriggerOptions, Partial { - handler: ServiceBusTopicHandler; +export interface ServiceBusTopicFunctionOptions + extends ServiceBusTopicTriggerOptions, + Partial { + handler: ServiceBusTopicHandler; trigger?: ServiceBusTopicTrigger; } diff --git a/types/sql.d.ts b/types/sql.d.ts index 5614d022..74f4f8c9 100644 --- a/types/sql.d.ts +++ b/types/sql.d.ts @@ -4,10 +4,10 @@ import { FunctionInput, FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger } from './index'; import { InvocationContext } from './InvocationContext'; -export type SqlHandler = (changes: SqlChange[], context: InvocationContext) => FunctionResult; +export type SqlHandler = (changes: SqlChange[], context: InvocationContext) => FunctionResult; -export interface SqlFunctionOptions extends SqlTriggerOptions, Partial { - handler: SqlHandler; +export interface SqlFunctionOptions extends SqlTriggerOptions, Partial { + handler: SqlHandler; trigger?: SqlTrigger; } @@ -25,8 +25,8 @@ export interface SqlTriggerOptions { } export type SqlTrigger = FunctionTrigger & SqlTriggerOptions; -export interface SqlChange { - Item: unknown; +export interface SqlChange { + Item: T; Operation: SqlChangeOperation; } diff --git a/types/storage.d.ts b/types/storage.d.ts index e59c2581..264a81ec 100644 --- a/types/storage.d.ts +++ b/types/storage.d.ts @@ -4,17 +4,17 @@ import { FunctionInput, FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger } from './index'; import { InvocationContext } from './InvocationContext'; -export type StorageBlobHandler = (blob: unknown, context: InvocationContext) => FunctionResult; -export type StorageQueueHandler = (queueEntry: unknown, context: InvocationContext) => FunctionResult; +export type StorageBlobHandler = (blob: T, context: InvocationContext) => FunctionResult; +export type StorageQueueHandler = (queueEntry: T, context: InvocationContext) => FunctionResult; -export interface StorageBlobFunctionOptions extends StorageBlobTriggerOptions, Partial { - handler: StorageBlobHandler; +export interface StorageBlobFunctionOptions extends StorageBlobTriggerOptions, Partial { + handler: StorageBlobHandler; trigger?: StorageBlobTrigger; } -export interface StorageQueueFunctionOptions extends StorageQueueTriggerOptions, Partial { - handler: StorageQueueHandler; +export interface StorageQueueFunctionOptions extends StorageQueueTriggerOptions, Partial { + handler: StorageQueueHandler; trigger?: StorageQueueTrigger; } diff --git a/types/webpubsub.d.ts b/types/webpubsub.d.ts index e86ac46f..c6c9be50 100644 --- a/types/webpubsub.d.ts +++ b/types/webpubsub.d.ts @@ -4,10 +4,10 @@ import { FunctionInput, FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger } from './index'; import { InvocationContext } from './InvocationContext'; -export type WebPubSubHandler = (message: unknown, context: InvocationContext) => FunctionResult; +export type WebPubSubHandler = (message: T, context: InvocationContext) => FunctionResult; -export interface WebPubSubFunctionOptions extends WebPubSubTriggerOptions, Partial { - handler: WebPubSubHandler; +export interface WebPubSubFunctionOptions extends WebPubSubTriggerOptions, Partial { + handler: WebPubSubHandler; trigger?: WebPubSubTrigger; }