diff --git a/src/addBindingName.ts b/src/addBindingName.ts new file mode 100644 index 0000000..6073e97 --- /dev/null +++ b/src/addBindingName.ts @@ -0,0 +1,32 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +export { HttpRequest } from './http/HttpRequest'; +export { HttpResponse } from './http/HttpResponse'; +export { InvocationContext } from './InvocationContext'; + +const bindingCounts: Record = {}; +/** + * If the host spawns multiple workers, it expects the metadata (including binding name) to be the same accross workers + * That means we need to generate binding names in a deterministic fashion, so we'll do that using a count + * There's a tiny risk users register bindings in a non-deterministic order (i.e. async race conditions), but it's okay considering the following: + * 1. We will track the count individually for each binding type. This makes the names more readable and reduces the chances a race condition will matter + * 2. Users can manually specify the name themselves (aka if they're doing weird async stuff) and we will respect that + * More info here: https://github.com/Azure/azure-functions-nodejs-worker/issues/638 + */ +export function addBindingName( + binding: T, + suffix: string +): T & { name: string } { + if (!binding.name) { + let bindingType = binding.type; + if (!bindingType.toLowerCase().endsWith(suffix.toLowerCase())) { + bindingType += suffix; + } + let count = bindingCounts[bindingType] || 0; + count += 1; + bindingCounts[bindingType] = count; + binding.name = bindingType + count.toString(); + } + return binding; +} diff --git a/src/app.ts b/src/app.ts new file mode 100644 index 0000000..aa2210d --- /dev/null +++ b/src/app.ts @@ -0,0 +1,244 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import { + CosmosDBFunctionOptions, + EventGridFunctionOptions, + EventHubFunctionOptions, + FunctionOptions, + HttpFunctionOptions, + HttpHandler, + HttpMethod, + HttpMethodFunctionOptions, + ServiceBusQueueFunctionOptions, + ServiceBusTopicFunctionOptions, + StorageBlobFunctionOptions, + StorageQueueFunctionOptions, + TimerFunctionOptions, +} from '@azure/functions'; +import * as coreTypes from '@azure/functions-core'; +import { CoreInvocationContext, FunctionCallback } from '@azure/functions-core'; +import { returnBindingKey, version } from './constants'; +import { InvocationModel } from './InvocationModel'; +import * as output from './output'; +import * as trigger from './trigger'; +import { isTrigger } from './utils/isTrigger'; + +let coreApi: typeof coreTypes | undefined | null; +function tryGetCoreApiLazy(): typeof coreTypes | null { + if (coreApi === undefined) { + try { + // eslint-disable-next-line @typescript-eslint/no-var-requires + coreApi = require('@azure/functions-core'); + } catch { + coreApi = null; + } + } + return coreApi; +} + +class ProgrammingModel implements coreTypes.ProgrammingModel { + name = '@azure/functions'; + version = version; + getInvocationModel(coreCtx: CoreInvocationContext): InvocationModel { + return new InvocationModel(coreCtx); + } +} + +let hasSetup = false; +function setup() { + const coreApi = tryGetCoreApiLazy(); + if (!coreApi) { + console.warn( + 'WARNING: Failed to detect the Azure Functions runtime. Switching "@azure/functions" package to test mode - not all features are supported.' + ); + } else { + coreApi.setProgrammingModel(new ProgrammingModel()); + } + hasSetup = true; +} + +function convertToHttpOptions( + optionsOrHandler: HttpFunctionOptions | HttpHandler, + method: HttpMethod +): HttpFunctionOptions { + const options: HttpFunctionOptions = + typeof optionsOrHandler === 'function' ? { handler: optionsOrHandler } : optionsOrHandler; + options.methods = [method]; + return options; +} + +export function get(name: string, optionsOrHandler: HttpMethodFunctionOptions | HttpHandler): void { + http(name, convertToHttpOptions(optionsOrHandler, 'GET')); +} + +export function put(name: string, optionsOrHandler: HttpMethodFunctionOptions | HttpHandler): void { + http(name, convertToHttpOptions(optionsOrHandler, 'PUT')); +} + +export function post(name: string, optionsOrHandler: HttpMethodFunctionOptions | HttpHandler): void { + http(name, convertToHttpOptions(optionsOrHandler, 'POST')); +} + +export function patch(name: string, optionsOrHandler: HttpMethodFunctionOptions | HttpHandler): void { + http(name, convertToHttpOptions(optionsOrHandler, 'PATCH')); +} + +export function deleteRequest(name: string, optionsOrHandler: HttpMethodFunctionOptions | HttpHandler): void { + http(name, convertToHttpOptions(optionsOrHandler, 'DELETE')); +} + +export function http(name: string, options: HttpFunctionOptions): void { + options.return ||= output.http({}); + generic(name, { + trigger: trigger.http({ + authLevel: options.authLevel, + methods: options.methods, + route: options.route, + }), + ...options, + }); +} + +export function timer(name: string, options: TimerFunctionOptions): void { + generic(name, { + trigger: trigger.timer({ + schedule: options.schedule, + runOnStartup: options.runOnStartup, + useMonitor: options.useMonitor, + }), + ...options, + }); +} + +export function storageBlob(name: string, options: StorageBlobFunctionOptions): void { + generic(name, { + trigger: trigger.storageBlob({ + connection: options.connection, + path: options.path, + }), + ...options, + }); +} + +export function storageQueue(name: string, options: StorageQueueFunctionOptions): void { + generic(name, { + trigger: trigger.storageQueue({ + connection: options.connection, + queueName: options.queueName, + }), + ...options, + }); +} + +export function serviceBusQueue(name: string, options: ServiceBusQueueFunctionOptions): void { + generic(name, { + trigger: trigger.serviceBusQueue({ + connection: options.connection, + queueName: options.queueName, + isSessionsEnabled: options.isSessionsEnabled, + }), + ...options, + }); +} + +export function serviceBusTopic(name: string, options: ServiceBusTopicFunctionOptions): void { + generic(name, { + trigger: trigger.serviceBusTopic({ + connection: options.connection, + topicName: options.topicName, + subscriptionName: options.subscriptionName, + isSessionsEnabled: options.isSessionsEnabled, + }), + ...options, + }); +} + +export function eventHub(name: string, options: EventHubFunctionOptions): void { + generic(name, { + trigger: trigger.eventHub({ + connection: options.connection, + eventHubName: options.eventHubName, + cardinality: options.cardinality, + consumerGroup: options.consumerGroup, + }), + ...options, + }); +} + +export function eventGrid(name: string, options: EventGridFunctionOptions): void { + generic(name, { + trigger: trigger.eventGrid({}), + ...options, + }); +} + +export function cosmosDB(name: string, options: CosmosDBFunctionOptions): void { + generic(name, { + trigger: trigger.cosmosDB({ + collectionName: options.collectionName, + connectionStringSetting: options.connectionStringSetting, + createLeaseCollectionIfNotExists: options.createLeaseCollectionIfNotExists, + databaseName: options.databaseName, + id: options.id, + leaseCollectionName: options.leaseCollectionName, + leaseCollectionPrefix: options.leaseCollectionPrefix, + leaseCollectionThroughput: options.leaseCollectionThroughput, + leaseConnectionStringSetting: options.leaseConnectionStringSetting, + leaseDatabaseName: options.leaseDatabaseName, + partitionKey: options.partitionKey, + sqlQuery: options.sqlQuery, + }), + ...options, + }); +} + +export function generic(name: string, options: FunctionOptions): void { + if (!hasSetup) { + setup(); + } + + const bindings: Record = {}; + + const trigger = options.trigger; + bindings[trigger.name] = { + ...trigger, + direction: 'in', + type: isTrigger(trigger.type) ? trigger.type : trigger.type + 'Trigger', + }; + + if (options.extraInputs) { + for (const input of options.extraInputs) { + bindings[input.name] = { + ...input, + direction: 'in', + }; + } + } + + if (options.return) { + options.return.name = returnBindingKey; + bindings[options.return.name] = { + ...options.return, + direction: 'out', + }; + } + + if (options.extraOutputs) { + for (const output of options.extraOutputs) { + bindings[output.name] = { + ...output, + direction: 'out', + }; + } + } + + const coreApi = tryGetCoreApiLazy(); + if (!coreApi) { + console.warn( + `WARNING: Skipping call to register function "${name}" because the "@azure/functions" package is in test mode.` + ); + } else { + coreApi.registerFunction({ name, bindings }, options.handler); + } +} diff --git a/src/index.ts b/src/index.ts index f662c1c..b06ab88 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,480 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT License. -import { - CosmosDBFunctionOptions, - CosmosDBInput, - CosmosDBInputOptions, - CosmosDBOutput, - CosmosDBOutputOptions, - CosmosDBTrigger, - CosmosDBTriggerOptions, - EventGridFunctionOptions, - EventGridOutput, - EventGridOutputOptions, - EventGridTrigger, - EventGridTriggerOptions, - EventHubFunctionOptions, - EventHubOutput, - EventHubOutputOptions, - EventHubTrigger, - EventHubTriggerOptions, - FunctionInput, - FunctionOptions, - FunctionOutput, - FunctionTrigger, - GenericInputOptions, - GenericOutputOptions, - GenericTriggerOptions, - HttpFunctionOptions, - HttpHandler, - HttpMethod, - HttpMethodFunctionOptions, - HttpOutput, - HttpOutputOptions, - HttpTrigger, - HttpTriggerOptions, - ServiceBusQueueFunctionOptions, - ServiceBusQueueOutput, - ServiceBusQueueOutputOptions, - ServiceBusQueueTrigger, - ServiceBusQueueTriggerOptions, - ServiceBusTopicFunctionOptions, - ServiceBusTopicOutput, - ServiceBusTopicOutputOptions, - ServiceBusTopicTrigger, - ServiceBusTopicTriggerOptions, - StorageBlobFunctionOptions, - StorageBlobInput, - StorageBlobInputOptions, - StorageBlobOutput, - StorageBlobOutputOptions, - StorageBlobTrigger, - StorageBlobTriggerOptions, - StorageQueueFunctionOptions, - StorageQueueOutput, - StorageQueueOutputOptions, - StorageQueueTrigger, - StorageQueueTriggerOptions, - TimerFunctionOptions, - TimerTrigger, - TimerTriggerOptions, -} from '@azure/functions'; -import * as coreTypes from '@azure/functions-core'; -import { CoreInvocationContext, FunctionCallback } from '@azure/functions-core'; -import { returnBindingKey, version } from './constants'; -import { InvocationModel } from './InvocationModel'; -import { isTrigger } from './utils/isTrigger'; - +export * as app from './app'; export { HttpRequest } from './http/HttpRequest'; export { HttpResponse } from './http/HttpResponse'; +export * as input from './input'; export { InvocationContext } from './InvocationContext'; - -let coreApi: typeof coreTypes | undefined | null; -function tryGetCoreApiLazy(): typeof coreTypes | null { - if (coreApi === undefined) { - try { - // eslint-disable-next-line @typescript-eslint/no-var-requires - coreApi = require('@azure/functions-core'); - } catch { - coreApi = null; - } - } - return coreApi; -} - -class ProgrammingModel implements coreTypes.ProgrammingModel { - name = '@azure/functions'; - version = version; - getInvocationModel(coreCtx: CoreInvocationContext): InvocationModel { - return new InvocationModel(coreCtx); - } -} - -let hasSetup = false; -function setup() { - const coreApi = tryGetCoreApiLazy(); - if (!coreApi) { - console.warn( - 'WARNING: Failed to detect the Azure Functions runtime. Switching "@azure/functions" package to test mode - not all features are supported.' - ); - } else { - coreApi.setProgrammingModel(new ProgrammingModel()); - } - hasSetup = true; -} - -function convertToHttpOptions( - optionsOrHandler: HttpFunctionOptions | HttpHandler, - method: HttpMethod -): HttpFunctionOptions { - const options: HttpFunctionOptions = - typeof optionsOrHandler === 'function' ? { handler: optionsOrHandler } : optionsOrHandler; - options.methods = [method]; - return options; -} - -export namespace app { - export function get(name: string, optionsOrHandler: HttpMethodFunctionOptions | HttpHandler): void { - http(name, convertToHttpOptions(optionsOrHandler, 'GET')); - } - - export function put(name: string, optionsOrHandler: HttpMethodFunctionOptions | HttpHandler): void { - http(name, convertToHttpOptions(optionsOrHandler, 'PUT')); - } - - export function post(name: string, optionsOrHandler: HttpMethodFunctionOptions | HttpHandler): void { - http(name, convertToHttpOptions(optionsOrHandler, 'POST')); - } - - export function patch(name: string, optionsOrHandler: HttpMethodFunctionOptions | HttpHandler): void { - http(name, convertToHttpOptions(optionsOrHandler, 'PATCH')); - } - - export function deleteRequest(name: string, optionsOrHandler: HttpMethodFunctionOptions | HttpHandler): void { - http(name, convertToHttpOptions(optionsOrHandler, 'DELETE')); - } - - export function http(name: string, options: HttpFunctionOptions): void { - options.return ||= output.http({}); - generic(name, { - trigger: trigger.http({ - authLevel: options.authLevel, - methods: options.methods, - route: options.route, - }), - ...options, - }); - } - - export function timer(name: string, options: TimerFunctionOptions): void { - generic(name, { - trigger: trigger.timer({ - schedule: options.schedule, - runOnStartup: options.runOnStartup, - useMonitor: options.useMonitor, - }), - ...options, - }); - } - - export function storageBlob(name: string, options: StorageBlobFunctionOptions): void { - generic(name, { - trigger: trigger.storageBlob({ - connection: options.connection, - path: options.path, - }), - ...options, - }); - } - - export function storageQueue(name: string, options: StorageQueueFunctionOptions): void { - generic(name, { - trigger: trigger.storageQueue({ - connection: options.connection, - queueName: options.queueName, - }), - ...options, - }); - } - - export function serviceBusQueue(name: string, options: ServiceBusQueueFunctionOptions): void { - generic(name, { - trigger: trigger.serviceBusQueue({ - connection: options.connection, - queueName: options.queueName, - isSessionsEnabled: options.isSessionsEnabled, - }), - ...options, - }); - } - - export function serviceBusTopic(name: string, options: ServiceBusTopicFunctionOptions): void { - generic(name, { - trigger: trigger.serviceBusTopic({ - connection: options.connection, - topicName: options.topicName, - subscriptionName: options.subscriptionName, - isSessionsEnabled: options.isSessionsEnabled, - }), - ...options, - }); - } - - export function eventHub(name: string, options: EventHubFunctionOptions): void { - generic(name, { - trigger: trigger.eventHub({ - connection: options.connection, - eventHubName: options.eventHubName, - cardinality: options.cardinality, - consumerGroup: options.consumerGroup, - }), - ...options, - }); - } - - export function eventGrid(name: string, options: EventGridFunctionOptions): void { - generic(name, { - trigger: trigger.eventGrid({}), - ...options, - }); - } - - export function cosmosDB(name: string, options: CosmosDBFunctionOptions): void { - generic(name, { - trigger: trigger.cosmosDB({ - collectionName: options.collectionName, - connectionStringSetting: options.connectionStringSetting, - createLeaseCollectionIfNotExists: options.createLeaseCollectionIfNotExists, - databaseName: options.databaseName, - id: options.id, - leaseCollectionName: options.leaseCollectionName, - leaseCollectionPrefix: options.leaseCollectionPrefix, - leaseCollectionThroughput: options.leaseCollectionThroughput, - leaseConnectionStringSetting: options.leaseConnectionStringSetting, - leaseDatabaseName: options.leaseDatabaseName, - partitionKey: options.partitionKey, - sqlQuery: options.sqlQuery, - }), - ...options, - }); - } - - export function generic(name: string, options: FunctionOptions): void { - if (!hasSetup) { - setup(); - } - - const bindings: Record = {}; - - const trigger = options.trigger; - bindings[trigger.name] = { - ...trigger, - direction: 'in', - type: isTrigger(trigger.type) ? trigger.type : trigger.type + 'Trigger', - }; - - if (options.extraInputs) { - for (const input of options.extraInputs) { - bindings[input.name] = { - ...input, - direction: 'in', - }; - } - } - - if (options.return) { - options.return.name = returnBindingKey; - bindings[options.return.name] = { - ...options.return, - direction: 'out', - }; - } - - if (options.extraOutputs) { - for (const output of options.extraOutputs) { - bindings[output.name] = { - ...output, - direction: 'out', - }; - } - } - - const coreApi = tryGetCoreApiLazy(); - if (!coreApi) { - console.warn( - `WARNING: Skipping call to register function "${name}" because the "@azure/functions" package is in test mode.` - ); - } else { - coreApi.registerFunction({ name, bindings }, options.handler); - } - } -} - -export namespace trigger { - export function http(options: HttpTriggerOptions): HttpTrigger { - return addTriggerBindingName({ - ...options, - authLevel: options.authLevel || 'anonymous', - methods: options.methods || ['GET', 'POST'], - type: 'httpTrigger', - }); - } - - export function timer(options: TimerTriggerOptions): TimerTrigger { - return addTriggerBindingName({ - ...options, - type: 'timerTrigger', - }); - } - - export function storageBlob(options: StorageBlobTriggerOptions): StorageBlobTrigger { - return addTriggerBindingName({ - ...options, - type: 'blobTrigger', - }); - } - - export function storageQueue(options: StorageQueueTriggerOptions): StorageQueueTrigger { - return addTriggerBindingName({ - ...options, - type: 'queueTrigger', - }); - } - - export function serviceBusQueue(options: ServiceBusQueueTriggerOptions): ServiceBusQueueTrigger { - return addTriggerBindingName({ - ...options, - type: 'serviceBusTrigger', - }); - } - - export function serviceBusTopic(options: ServiceBusTopicTriggerOptions): ServiceBusTopicTrigger { - return addTriggerBindingName({ - ...options, - type: 'serviceBusTrigger', - }); - } - - export function eventHub(options: EventHubTriggerOptions): EventHubTrigger { - return addTriggerBindingName({ - ...options, - type: 'eventHubTrigger', - }); - } - - export function eventGrid(options: EventGridTriggerOptions): EventGridTrigger { - return addTriggerBindingName({ - ...options, - type: 'eventGridTrigger', - }); - } - - export function cosmosDB(options: CosmosDBTriggerOptions): CosmosDBTrigger { - return addTriggerBindingName({ - ...options, - type: 'cosmosDBTrigger', - }); - } - - export function generic(options: GenericTriggerOptions): FunctionTrigger { - return addTriggerBindingName(options); - } -} - -export namespace input { - export function storageBlob(options: StorageBlobInputOptions): StorageBlobInput { - return addInputBindingName({ - ...options, - type: 'blob', - }); - } - - export function cosmosDB(options: CosmosDBInputOptions): CosmosDBInput { - return addInputBindingName({ - ...options, - type: 'cosmosDB', - }); - } - - export function generic(options: GenericInputOptions): FunctionInput { - return addInputBindingName(options); - } -} - -export namespace output { - export function http(options: HttpOutputOptions): HttpOutput { - return addOutputBindingName({ - ...options, - type: 'http', - }); - } - - export function storageBlob(options: StorageBlobOutputOptions): StorageBlobOutput { - return addOutputBindingName({ - ...options, - type: 'blob', - }); - } - - export function storageQueue(options: StorageQueueOutputOptions): StorageQueueOutput { - return addOutputBindingName({ - ...options, - type: 'queue', - }); - } - - export function serviceBusQueue(options: ServiceBusQueueOutputOptions): ServiceBusQueueOutput { - return addOutputBindingName({ - ...options, - type: 'serviceBus', - }); - } - - export function serviceBusTopic(options: ServiceBusTopicOutputOptions): ServiceBusTopicOutput { - return addOutputBindingName({ - ...options, - type: 'serviceBus', - }); - } - - export function eventHub(options: EventHubOutputOptions): EventHubOutput { - return addOutputBindingName({ - ...options, - type: 'eventHub', - }); - } - - export function eventGrid(options: EventGridOutputOptions): EventGridOutput { - return addOutputBindingName({ - ...options, - type: 'eventGrid', - }); - } - - export function cosmosDB(options: CosmosDBOutputOptions): CosmosDBOutput { - return addOutputBindingName({ - ...options, - type: 'cosmosDB', - }); - } - - export function generic(options: GenericOutputOptions): FunctionOutput { - return addOutputBindingName(options); - } -} - -function addInputBindingName(binding: T): T & { name: string } { - return addBindingName(binding, 'Input'); -} - -function addTriggerBindingName(binding: T): T & { name: string } { - return addBindingName(binding, 'Trigger'); -} - -function addOutputBindingName(binding: T): T & { name: string } { - return addBindingName(binding, 'Output'); -} - -const bindingCounts: Record = {}; -/** - * If the host spawns multiple workers, it expects the metadata (including binding name) to be the same accross workers - * That means we need to generate binding names in a deterministic fashion, so we'll do that using a count - * There's a tiny risk users register bindings in a non-deterministic order (i.e. async race conditions), but it's okay considering the following: - * 1. We will track the count individually for each binding type. This makes the names more readable and reduces the chances a race condition will matter - * 2. Users can manually specify the name themselves (aka if they're doing weird async stuff) and we will respect that - * More info here: https://github.com/Azure/azure-functions-nodejs-worker/issues/638 - */ -function addBindingName(binding: T, suffix: string): T & { name: string } { - if (!binding.name) { - let bindingType = binding.type; - if (!bindingType.toLowerCase().endsWith(suffix.toLowerCase())) { - bindingType += suffix; - } - let count = bindingCounts[bindingType] || 0; - count += 1; - bindingCounts[bindingType] = count; - binding.name = bindingType + count.toString(); - } - return binding; -} +export * as output from './output'; +export * as trigger from './trigger'; diff --git a/src/input.ts b/src/input.ts new file mode 100644 index 0000000..62e626d --- /dev/null +++ b/src/input.ts @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import { + CosmosDBInput, + CosmosDBInputOptions, + FunctionInput, + GenericInputOptions, + StorageBlobInput, + StorageBlobInputOptions, +} from '@azure/functions'; +import { addBindingName } from './addBindingName'; + +export function storageBlob(options: StorageBlobInputOptions): StorageBlobInput { + return addInputBindingName({ + ...options, + type: 'blob', + }); +} + +export function cosmosDB(options: CosmosDBInputOptions): CosmosDBInput { + return addInputBindingName({ + ...options, + type: 'cosmosDB', + }); +} + +export function generic(options: GenericInputOptions): FunctionInput { + return addInputBindingName(options); +} + +function addInputBindingName(binding: T): T & { name: string } { + return addBindingName(binding, 'Input'); +} diff --git a/src/output.ts b/src/output.ts new file mode 100644 index 0000000..ce40b46 --- /dev/null +++ b/src/output.ts @@ -0,0 +1,88 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import { + CosmosDBOutput, + CosmosDBOutputOptions, + EventGridOutput, + EventGridOutputOptions, + EventHubOutput, + EventHubOutputOptions, + FunctionOutput, + GenericOutputOptions, + HttpOutput, + HttpOutputOptions, + ServiceBusQueueOutput, + ServiceBusQueueOutputOptions, + ServiceBusTopicOutput, + ServiceBusTopicOutputOptions, + StorageBlobOutput, + StorageBlobOutputOptions, + StorageQueueOutput, + StorageQueueOutputOptions, +} from '@azure/functions'; +import { addBindingName } from './addBindingName'; + +export function http(options: HttpOutputOptions): HttpOutput { + return addOutputBindingName({ + ...options, + type: 'http', + }); +} + +export function storageBlob(options: StorageBlobOutputOptions): StorageBlobOutput { + return addOutputBindingName({ + ...options, + type: 'blob', + }); +} + +export function storageQueue(options: StorageQueueOutputOptions): StorageQueueOutput { + return addOutputBindingName({ + ...options, + type: 'queue', + }); +} + +export function serviceBusQueue(options: ServiceBusQueueOutputOptions): ServiceBusQueueOutput { + return addOutputBindingName({ + ...options, + type: 'serviceBus', + }); +} + +export function serviceBusTopic(options: ServiceBusTopicOutputOptions): ServiceBusTopicOutput { + return addOutputBindingName({ + ...options, + type: 'serviceBus', + }); +} + +export function eventHub(options: EventHubOutputOptions): EventHubOutput { + return addOutputBindingName({ + ...options, + type: 'eventHub', + }); +} + +export function eventGrid(options: EventGridOutputOptions): EventGridOutput { + return addOutputBindingName({ + ...options, + type: 'eventGrid', + }); +} + +export function cosmosDB(options: CosmosDBOutputOptions): CosmosDBOutput { + return addOutputBindingName({ + ...options, + type: 'cosmosDB', + }); +} + +export function generic(options: GenericOutputOptions): FunctionOutput { + return addOutputBindingName(options); +} + +function addOutputBindingName(binding: T): T & { name: string } { + return addBindingName(binding, 'Output'); +} diff --git a/src/trigger.ts b/src/trigger.ts new file mode 100644 index 0000000..bdda8ee --- /dev/null +++ b/src/trigger.ts @@ -0,0 +1,99 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import { + CosmosDBTrigger, + CosmosDBTriggerOptions, + EventGridTrigger, + EventGridTriggerOptions, + EventHubTrigger, + EventHubTriggerOptions, + FunctionTrigger, + GenericTriggerOptions, + HttpTrigger, + HttpTriggerOptions, + ServiceBusQueueTrigger, + ServiceBusQueueTriggerOptions, + ServiceBusTopicTrigger, + ServiceBusTopicTriggerOptions, + StorageBlobTrigger, + StorageBlobTriggerOptions, + StorageQueueTrigger, + StorageQueueTriggerOptions, + TimerTrigger, + TimerTriggerOptions, +} from '@azure/functions'; +import { addBindingName } from './addBindingName'; + +export function http(options: HttpTriggerOptions): HttpTrigger { + return addTriggerBindingName({ + ...options, + authLevel: options.authLevel || 'anonymous', + methods: options.methods || ['GET', 'POST'], + type: 'httpTrigger', + }); +} + +export function timer(options: TimerTriggerOptions): TimerTrigger { + return addTriggerBindingName({ + ...options, + type: 'timerTrigger', + }); +} + +export function storageBlob(options: StorageBlobTriggerOptions): StorageBlobTrigger { + return addTriggerBindingName({ + ...options, + type: 'blobTrigger', + }); +} + +export function storageQueue(options: StorageQueueTriggerOptions): StorageQueueTrigger { + return addTriggerBindingName({ + ...options, + type: 'queueTrigger', + }); +} + +export function serviceBusQueue(options: ServiceBusQueueTriggerOptions): ServiceBusQueueTrigger { + return addTriggerBindingName({ + ...options, + type: 'serviceBusTrigger', + }); +} + +export function serviceBusTopic(options: ServiceBusTopicTriggerOptions): ServiceBusTopicTrigger { + return addTriggerBindingName({ + ...options, + type: 'serviceBusTrigger', + }); +} + +export function eventHub(options: EventHubTriggerOptions): EventHubTrigger { + return addTriggerBindingName({ + ...options, + type: 'eventHubTrigger', + }); +} + +export function eventGrid(options: EventGridTriggerOptions): EventGridTrigger { + return addTriggerBindingName({ + ...options, + type: 'eventGridTrigger', + }); +} + +export function cosmosDB(options: CosmosDBTriggerOptions): CosmosDBTrigger { + return addTriggerBindingName({ + ...options, + type: 'cosmosDBTrigger', + }); +} + +export function generic(options: GenericTriggerOptions): FunctionTrigger { + return addTriggerBindingName(options); +} + +function addTriggerBindingName(binding: T): T & { name: string } { + return addBindingName(binding, 'Trigger'); +} diff --git a/types/app.d.ts b/types/app.d.ts new file mode 100644 index 0000000..41dfdba --- /dev/null +++ b/types/app.d.ts @@ -0,0 +1,152 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import { CosmosDBFunctionOptions } from './cosmosDB'; +import { EventGridFunctionOptions } from './eventGrid'; +import { EventHubFunctionOptions } from './eventHub'; +import { HttpFunctionOptions, HttpHandler, HttpMethodFunctionOptions } from './http'; +import { FunctionOptions } from './index'; +import { ServiceBusQueueFunctionOptions, ServiceBusTopicFunctionOptions } from './serviceBus'; +import { StorageBlobFunctionOptions, StorageQueueFunctionOptions } from './storage'; +import { TimerFunctionOptions } from './timer'; + +/** + * Registers an http function in your app that will be triggered by making a request to the function url + * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` + * @param options Configuration options describing the inputs, outputs, and handler for this function + */ +export function http(name: string, options: HttpFunctionOptions): void; + +/** + * Registers an http function in your app that will be triggered by making a 'GET' request to the function url + * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` + * @param handler The handler for this function + */ +export function get(name: string, handler: HttpHandler): void; + +/** + * Registers an http function in your app that will be triggered by making a 'GET' request to the function url + * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` + * @param options Configuration options describing the inputs, outputs, and handler for this function + */ +export function get(name: string, options: HttpMethodFunctionOptions): void; + +/** + * Registers an http function in your app that will be triggered by making a 'PUT' request to the function url + * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` + * @param handler The handler for this function + */ +export function put(name: string, handler: HttpHandler): void; + +/** + * Registers an http function in your app that will be triggered by making a 'PUT' request to the function url + * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` + * @param options Configuration options describing the inputs, outputs, and handler for this function + */ +export function put(name: string, options: HttpMethodFunctionOptions): void; + +/** + * Registers an http function in your app that will be triggered by making a 'POST' request to the function url + * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` + * @param handler The handler for this function + */ +export function post(name: string, handler: HttpHandler): void; + +/** + * Registers an http function in your app that will be triggered by making a 'POST' request to the function url + * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` + * @param options Configuration options describing the inputs, outputs, and handler for this function + */ +export function post(name: string, options: HttpMethodFunctionOptions): void; + +/** + * Registers an http function in your app that will be triggered by making a 'PATCH' request to the function url + * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` + * @param handler The handler for this function + */ +export function patch(name: string, handler: HttpHandler): void; + +/** + * Registers an http function in your app that will be triggered by making a 'PATCH' request to the function url + * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` + * @param options Configuration options describing the inputs, outputs, and handler for this function + */ +export function patch(name: string, options: HttpMethodFunctionOptions): void; + +/** + * Registers an http function in your app that will be triggered by making a 'DELETE' request to the function url + * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` + * @param handler The handler for this function + */ +export function deleteRequest(name: string, handler: HttpHandler): void; + +/** + * Registers an http function in your app that will be triggered by making a 'DELETE' request to the function url + * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` + * @param options Configuration options describing the inputs, outputs, and handler for this function + */ +export function deleteRequest(name: string, options: HttpMethodFunctionOptions): void; + +/** + * Registers a timer function in your app that will be triggered on a schedule + * @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 timer(name: string, options: TimerFunctionOptions): void; + +/** + * Registers a function in your app that will be triggered whenever an item is added to a storage blob path + * @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; + +/** + * 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; + +/** + * 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; + +/** + * 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; + +/** + * 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; + +/** + * 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; + +/** + * 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; + +/** + * Registers a generic function in your app that will be triggered based on the type specified in `options.trigger.type` + * Use this method if your desired trigger type does not already have its own method + * @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 generic(name: string, options: FunctionOptions): void; diff --git a/types/index.d.ts b/types/index.d.ts index 39cf769..ecfa6a1 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,355 +1,21 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT License. -import { - CosmosDBFunctionOptions, - CosmosDBInput, - CosmosDBInputOptions, - CosmosDBOutput, - CosmosDBOutputOptions, - CosmosDBTrigger, - CosmosDBTriggerOptions, -} from './cosmosDB'; -import { - EventGridFunctionOptions, - EventGridOutput, - EventGridOutputOptions, - EventGridTrigger, - EventGridTriggerOptions, -} from './eventGrid'; -import { - EventHubFunctionOptions, - EventHubOutput, - EventHubOutputOptions, - EventHubTrigger, - EventHubTriggerOptions, -} from './eventHub'; -import { GenericInputOptions, GenericOutputOptions, GenericTriggerOptions } from './generic'; -import { - HttpFunctionOptions, - HttpHandler, - HttpMethodFunctionOptions, - HttpOutput, - HttpOutputOptions, - HttpTrigger, - HttpTriggerOptions, -} from './http'; import { InvocationContext } from './InvocationContext'; -import { - ServiceBusQueueFunctionOptions, - ServiceBusQueueOutput, - ServiceBusQueueOutputOptions, - ServiceBusQueueTrigger, - ServiceBusQueueTriggerOptions, - ServiceBusTopicFunctionOptions, - ServiceBusTopicOutput, - ServiceBusTopicOutputOptions, - ServiceBusTopicTrigger, - ServiceBusTopicTriggerOptions, -} from './serviceBus'; -import { - StorageBlobFunctionOptions, - StorageBlobInput, - StorageBlobInputOptions, - StorageBlobOutput, - StorageBlobOutputOptions, - StorageBlobTrigger, - StorageBlobTriggerOptions, - StorageQueueFunctionOptions, - StorageQueueOutput, - StorageQueueOutputOptions, - StorageQueueTrigger, - StorageQueueTriggerOptions, -} from './storage'; -import { TimerFunctionOptions, TimerTrigger, TimerTriggerOptions } from './timer'; +export * as app from './app'; export * from './cosmosDB'; export * from './eventGrid'; export * from './eventHub'; export * from './generic'; export * from './http'; +export * as input from './input'; export * from './InvocationContext'; +export * as output from './output'; export * from './serviceBus'; export * from './storage'; export * from './timer'; - -/** - * The root namespace for performing operations on your Azure Function App - */ -export namespace app { - /** - * Registers an http function in your app that will be triggered by making a request to the function url - * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` - * @param options Configuration options describing the inputs, outputs, and handler for this function - */ - export function http(name: string, options: HttpFunctionOptions): void; - - /** - * Registers an http function in your app that will be triggered by making a 'GET' request to the function url - * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` - * @param handler The handler for this function - */ - export function get(name: string, handler: HttpHandler): void; - - /** - * Registers an http function in your app that will be triggered by making a 'GET' request to the function url - * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` - * @param options Configuration options describing the inputs, outputs, and handler for this function - */ - export function get(name: string, options: HttpMethodFunctionOptions): void; - - /** - * Registers an http function in your app that will be triggered by making a 'PUT' request to the function url - * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` - * @param handler The handler for this function - */ - export function put(name: string, handler: HttpHandler): void; - - /** - * Registers an http function in your app that will be triggered by making a 'PUT' request to the function url - * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` - * @param options Configuration options describing the inputs, outputs, and handler for this function - */ - export function put(name: string, options: HttpMethodFunctionOptions): void; - - /** - * Registers an http function in your app that will be triggered by making a 'POST' request to the function url - * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` - * @param handler The handler for this function - */ - export function post(name: string, handler: HttpHandler): void; - - /** - * Registers an http function in your app that will be triggered by making a 'POST' request to the function url - * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` - * @param options Configuration options describing the inputs, outputs, and handler for this function - */ - export function post(name: string, options: HttpMethodFunctionOptions): void; - - /** - * Registers an http function in your app that will be triggered by making a 'PATCH' request to the function url - * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` - * @param handler The handler for this function - */ - export function patch(name: string, handler: HttpHandler): void; - - /** - * Registers an http function in your app that will be triggered by making a 'PATCH' request to the function url - * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` - * @param options Configuration options describing the inputs, outputs, and handler for this function - */ - export function patch(name: string, options: HttpMethodFunctionOptions): void; - - /** - * Registers an http function in your app that will be triggered by making a 'DELETE' request to the function url - * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` - * @param handler The handler for this function - */ - export function deleteRequest(name: string, handler: HttpHandler): void; - - /** - * Registers an http function in your app that will be triggered by making a 'DELETE' request to the function url - * @param name The name of the function. This will be the route unless a route is explicitly configured in the `HttpTriggerOptions` - * @param options Configuration options describing the inputs, outputs, and handler for this function - */ - export function deleteRequest(name: string, options: HttpMethodFunctionOptions): void; - - /** - * Registers a timer function in your app that will be triggered on a schedule - * @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 timer(name: string, options: TimerFunctionOptions): void; - - /** - * Registers a function in your app that will be triggered whenever an item is added to a storage blob path - * @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; - - /** - * 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; - - /** - * 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; - - /** - * 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; - - /** - * 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; - - /** - * 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; - - /** - * 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; - - /** - * Registers a generic function in your app that will be triggered based on the type specified in `options.trigger.type` - * Use this method if your desired trigger type does not already have its own method - * @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 generic(name: string, options: FunctionOptions): void; -} - -/** - * The root namespace used to help create trigger configuration (the primary input) - * You can create trigger config without this namespace, but it provides features like autocomplete, better build errors, and it will set the `name` property for you - */ -export namespace trigger { - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-http-webhook-trigger?&pivots=programming-language-javascript) - */ - export function http(options: HttpTriggerOptions): HttpTrigger; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-timer?pivots=programming-language-javascript) - */ - export function timer(options: TimerTriggerOptions): TimerTrigger; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-blob-trigger?pivots=programming-language-javascript) - */ - export function storageBlob(options: StorageBlobTriggerOptions): StorageBlobTrigger; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-queue-trigger?pivots=programming-language-javascript) - */ - export function storageQueue(options: StorageQueueTriggerOptions): StorageQueueTrigger; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-service-bus-trigger?pivots=programming-language-javascript) - */ - export function serviceBusQueue(options: ServiceBusQueueTriggerOptions): ServiceBusQueueTrigger; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-service-bus-trigger?pivots=programming-language-javascript) - */ - export function serviceBusTopic(options: ServiceBusTopicTriggerOptions): ServiceBusTopicTrigger; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-event-hubs-trigger?pivots=programming-language-javascript) - */ - export function eventHub(options: EventHubTriggerOptions): EventHubTrigger; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-event-grid-trigger?pivots=programming-language-javascript) - */ - export function eventGrid(options: EventGridTriggerOptions): EventGridTrigger; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-cosmosdb-v2-trigger?pivots=programming-language-javascript) - */ - export function cosmosDB(options: CosmosDBTriggerOptions): CosmosDBTrigger; - - /** - * A generic option that can be used for any trigger type - * Use this method if your desired trigger type does not already have its own method - */ - export function generic(options: GenericTriggerOptions): FunctionTrigger; -} - -/** - * The root namespace used to help create secondary input configuration ("trigger" is the primary input) - * You can create input config without this namespace, but it provides features like autocomplete, better build errors, and it will set the `name` property for you - * NOTE: Not all triggers can be used as secondary inputs - */ -export namespace input { - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-blob-input?pivots=programming-language-javascript) - */ - export function storageBlob(options: StorageBlobInputOptions): StorageBlobInput; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-cosmosdb-v2-input?pivots=programming-language-javascript) - */ - export function cosmosDB(options: CosmosDBInputOptions): CosmosDBInput; - - /** - * A generic option that can be used for any input type - * Use this method if your desired input type does not already have its own method - */ - export function generic(options: GenericInputOptions): FunctionInput; -} - -/** - * The root namespace used to help create output configuration - * You can create output config without this namespace, but it provides features like autocomplete, better build errors, and it will set the `name` property for you - */ -export namespace output { - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-http-webhook-output?&pivots=programming-language-javascript) - */ - export function http(options: HttpOutputOptions): HttpOutput; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-blob-output?pivots=programming-language-javascript) - */ - export function storageBlob(options: StorageBlobOutputOptions): StorageBlobOutput; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-queue-output?pivots=programming-language-javascript) - */ - export function storageQueue(options: StorageQueueOutputOptions): StorageQueueOutput; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-service-bus-output?pivots=programming-language-javascript) - */ - export function serviceBusQueue(options: ServiceBusQueueOutputOptions): ServiceBusQueueOutput; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-service-bus-output?pivots=programming-language-javascript) - */ - export function serviceBusTopic(options: ServiceBusTopicOutputOptions): ServiceBusTopicOutput; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-event-hubs-output?pivots=programming-language-javascript) - */ - export function eventHub(options: EventHubOutputOptions): EventHubOutput; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-event-grid-output?pivots=programming-language-javascript) - */ - export function eventGrid(options: EventGridOutputOptions): EventGridOutput; - - /** - * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-cosmosdb-v2-output?pivots=programming-language-javascript) - */ - export function cosmosDB(options: CosmosDBOutputOptions): CosmosDBOutput; - - /** - * A generic option that can be used for any output type - * Use this method if your desired output type does not already have its own method - */ - export function generic(options: GenericOutputOptions): FunctionOutput; -} +export * as trigger from './trigger'; /** * Void if no `return` output is registered diff --git a/types/input.d.ts b/types/input.d.ts new file mode 100644 index 0000000..f62db94 --- /dev/null +++ b/types/input.d.ts @@ -0,0 +1,23 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import { CosmosDBInput, CosmosDBInputOptions } from './cosmosDB'; +import { GenericInputOptions } from './generic'; +import { FunctionInput } from './index'; +import { StorageBlobInput, StorageBlobInputOptions } from './storage'; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-blob-input?pivots=programming-language-javascript) + */ +export function storageBlob(options: StorageBlobInputOptions): StorageBlobInput; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-cosmosdb-v2-input?pivots=programming-language-javascript) + */ +export function cosmosDB(options: CosmosDBInputOptions): CosmosDBInput; + +/** + * A generic option that can be used for any input type + * Use this method if your desired input type does not already have its own method + */ +export function generic(options: GenericInputOptions): FunctionInput; diff --git a/types/output.d.ts b/types/output.d.ts new file mode 100644 index 0000000..115224f --- /dev/null +++ b/types/output.d.ts @@ -0,0 +1,62 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import { CosmosDBOutput, CosmosDBOutputOptions } from './cosmosDB'; +import { EventGridOutput, EventGridOutputOptions } from './eventGrid'; +import { EventHubOutput, EventHubOutputOptions } from './eventHub'; +import { GenericOutputOptions } from './generic'; +import { HttpOutput, HttpOutputOptions } from './http'; +import { FunctionOutput } from './index'; +import { + ServiceBusQueueOutput, + ServiceBusQueueOutputOptions, + ServiceBusTopicOutput, + ServiceBusTopicOutputOptions, +} from './serviceBus'; +import { StorageBlobOutput, StorageBlobOutputOptions, StorageQueueOutput, StorageQueueOutputOptions } from './storage'; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-http-webhook-output?&pivots=programming-language-javascript) + */ +export function http(options: HttpOutputOptions): HttpOutput; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-blob-output?pivots=programming-language-javascript) + */ +export function storageBlob(options: StorageBlobOutputOptions): StorageBlobOutput; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-queue-output?pivots=programming-language-javascript) + */ +export function storageQueue(options: StorageQueueOutputOptions): StorageQueueOutput; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-service-bus-output?pivots=programming-language-javascript) + */ +export function serviceBusQueue(options: ServiceBusQueueOutputOptions): ServiceBusQueueOutput; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-service-bus-output?pivots=programming-language-javascript) + */ +export function serviceBusTopic(options: ServiceBusTopicOutputOptions): ServiceBusTopicOutput; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-event-hubs-output?pivots=programming-language-javascript) + */ +export function eventHub(options: EventHubOutputOptions): EventHubOutput; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-event-grid-output?pivots=programming-language-javascript) + */ +export function eventGrid(options: EventGridOutputOptions): EventGridOutput; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-cosmosdb-v2-output?pivots=programming-language-javascript) + */ +export function cosmosDB(options: CosmosDBOutputOptions): CosmosDBOutput; + +/** + * A generic option that can be used for any output type + * Use this method if your desired output type does not already have its own method + */ +export function generic(options: GenericOutputOptions): FunctionOutput; diff --git a/types/trigger.d.ts b/types/trigger.d.ts new file mode 100644 index 0000000..f58af4f --- /dev/null +++ b/types/trigger.d.ts @@ -0,0 +1,73 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import { CosmosDBTrigger, CosmosDBTriggerOptions } from './cosmosDB'; +import { EventGridTrigger, EventGridTriggerOptions } from './eventGrid'; +import { EventHubTrigger, EventHubTriggerOptions } from './eventHub'; +import { GenericTriggerOptions } from './generic'; +import { HttpTrigger, HttpTriggerOptions } from './http'; +import { FunctionTrigger } from './index'; +import { + ServiceBusQueueTrigger, + ServiceBusQueueTriggerOptions, + ServiceBusTopicTrigger, + ServiceBusTopicTriggerOptions, +} from './serviceBus'; +import { + StorageBlobTrigger, + StorageBlobTriggerOptions, + StorageQueueTrigger, + StorageQueueTriggerOptions, +} from './storage'; +import { TimerTrigger, TimerTriggerOptions } from './timer'; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-http-webhook-trigger?&pivots=programming-language-javascript) + */ +export function http(options: HttpTriggerOptions): HttpTrigger; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-timer?pivots=programming-language-javascript) + */ +export function timer(options: TimerTriggerOptions): TimerTrigger; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-blob-trigger?pivots=programming-language-javascript) + */ +export function storageBlob(options: StorageBlobTriggerOptions): StorageBlobTrigger; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-queue-trigger?pivots=programming-language-javascript) + */ +export function storageQueue(options: StorageQueueTriggerOptions): StorageQueueTrigger; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-service-bus-trigger?pivots=programming-language-javascript) + */ +export function serviceBusQueue(options: ServiceBusQueueTriggerOptions): ServiceBusQueueTrigger; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-service-bus-trigger?pivots=programming-language-javascript) + */ +export function serviceBusTopic(options: ServiceBusTopicTriggerOptions): ServiceBusTopicTrigger; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-event-hubs-trigger?pivots=programming-language-javascript) + */ +export function eventHub(options: EventHubTriggerOptions): EventHubTrigger; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-event-grid-trigger?pivots=programming-language-javascript) + */ +export function eventGrid(options: EventGridTriggerOptions): EventGridTrigger; + +/** + * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-cosmosdb-v2-trigger?pivots=programming-language-javascript) + */ +export function cosmosDB(options: CosmosDBTriggerOptions): CosmosDBTrigger; + +/** + * A generic option that can be used for any trigger type + * Use this method if your desired trigger type does not already have its own method + */ +export function generic(options: GenericTriggerOptions): FunctionTrigger;