diff --git a/package-lock.json b/package-lock.json index 5ebf0834..762fe3ba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@azure/functions", - "version": "4.15.0", + "version": "4.16.0-preview", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@azure/functions", - "version": "4.15.0", + "version": "4.16.0-preview", "license": "MIT", "dependencies": { "@azure/functions-extensions-base": "0.2.0", @@ -6723,4 +6723,4 @@ } } } -} +} diff --git a/package.json b/package.json index 04574b47..099c1e32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@azure/functions", - "version": "4.15.0", + "version": "4.16.0-preview", "description": "Microsoft Azure Functions NodeJS Framework", "keywords": [ "azure", @@ -85,4 +85,4 @@ "webpack": "^5.74.0", "webpack-cli": "^4.10.0" } -} +} diff --git a/scripts/validateRelease.ts b/scripts/validateRelease.ts index 751cbf14..91563ff2 100644 --- a/scripts/validateRelease.ts +++ b/scripts/validateRelease.ts @@ -32,8 +32,8 @@ function validateRelease(publishTag: string, dropPath: string): void { let expectedFormat: string; switch (publishTag) { case 'preview': - regex = /^[0-9]+\.[0-9]+\.[0-9]+-alpha\.[0-9]+$/; - expectedFormat = 'x.x.x-alpha.x'; + regex = /^[0-9]+\.[0-9]+\.[0-9]+-preview$/; + expectedFormat = 'x.x.x-preview'; break; case 'latest': case 'legacy': @@ -48,4 +48,4 @@ function validateRelease(publishTag: string, dropPath: string): void { `Version number for tag "${publishTag}" should be in format "${expectedFormat}". Instead got "${versionNumber}"` ); } -} +} diff --git a/src/app.ts b/src/app.ts index 20e2f02a..315e870c 100644 --- a/src/app.ts +++ b/src/app.ts @@ -4,6 +4,7 @@ import { ConnectorTriggerFunctionOptions, CosmosDBFunctionOptions, + CosmosDBMongoFunctionOptions, EventGridFunctionOptions, EventHubFunctionOptions, FunctionTrigger, @@ -137,6 +138,11 @@ export function cosmosDB(name: string, options: CosmosDBFunctionOptions): void { generic(name, convertToGenericOptions(options, trigger.cosmosDB)); } +export function cosmosDBMongo(name: string, options: CosmosDBMongoFunctionOptions): void { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + generic(name, convertToGenericOptions(options, trigger.cosmosDBMongo)); +} + export function warmup(name: string, options: WarmupFunctionOptions): void { generic(name, convertToGenericOptions(options, trigger.warmup)); } diff --git a/src/constants.ts b/src/constants.ts index 41c91c40..5436e9b2 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,6 +1,6 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the MIT License. - -export const version = '4.15.0'; - -export const returnBindingKey = '$return'; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +export const version = '4.16.0-preview'; + +export const returnBindingKey = '$return'; diff --git a/src/input.ts b/src/input.ts index f319a12f..7d212ffd 100644 --- a/src/input.ts +++ b/src/input.ts @@ -4,6 +4,8 @@ import { CosmosDBInput, CosmosDBInputOptions, + CosmosDBMongoInput, + CosmosDBMongoInputOptions, FunctionInput, GenericInputOptions, MySqlInput, @@ -42,6 +44,13 @@ export function cosmosDB(options: CosmosDBInputOptions): CosmosDBInput { }); } +export function cosmosDBMongo(options: CosmosDBMongoInputOptions): CosmosDBMongoInput { + return addInputBindingName({ + ...options, + type: 'cosmosDBMongo', + }); +} + export function sql(options: SqlInputOptions): SqlInput { return addInputBindingName({ ...options, diff --git a/src/output.ts b/src/output.ts index 0f0a781c..c41ba8dc 100644 --- a/src/output.ts +++ b/src/output.ts @@ -1,124 +1,133 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the MIT License. - -import { - CosmosDBOutput, - CosmosDBOutputOptions, - EventGridOutput, - EventGridOutputOptions, - EventHubOutput, - EventHubOutputOptions, - FunctionOutput, - GenericOutputOptions, - HttpOutput, - HttpOutputOptions, - MySqlOutput, - MySqlOutputOptions, - ServiceBusQueueOutput, - ServiceBusQueueOutputOptions, - ServiceBusTopicOutput, - ServiceBusTopicOutputOptions, - SqlOutput, - SqlOutputOptions, - StorageBlobOutput, - StorageBlobOutputOptions, - StorageQueueOutput, - StorageQueueOutputOptions, - TableOutput, - TableOutputOptions, - WebPubSubOutput, - WebPubSubOutputOptions, -} 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 table(options: TableOutputOptions): TableOutput { - return addOutputBindingName({ - ...options, - type: 'table', - }); -} - -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 sql(options: SqlOutputOptions): SqlOutput { - return addOutputBindingName({ - ...options, - type: 'sql', - }); -} - -export function mySql(options: MySqlOutputOptions): MySqlOutput { - return addOutputBindingName({ - ...options, - type: 'mysql', - }); -} - -export function webPubSub(options: WebPubSubOutputOptions): WebPubSubOutput { - return addOutputBindingName({ - ...options, - type: 'webPubSub', - }); -} - -export function generic(options: GenericOutputOptions): FunctionOutput { - return addOutputBindingName(options); -} - -function addOutputBindingName(binding: T): T & { name: string } { - return addBindingName(binding, 'Output'); -} +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import { + CosmosDBMongoOutput, + CosmosDBMongoOutputOptions, + CosmosDBOutput, + CosmosDBOutputOptions, + EventGridOutput, + EventGridOutputOptions, + EventHubOutput, + EventHubOutputOptions, + FunctionOutput, + GenericOutputOptions, + HttpOutput, + HttpOutputOptions, + MySqlOutput, + MySqlOutputOptions, + ServiceBusQueueOutput, + ServiceBusQueueOutputOptions, + ServiceBusTopicOutput, + ServiceBusTopicOutputOptions, + SqlOutput, + SqlOutputOptions, + StorageBlobOutput, + StorageBlobOutputOptions, + StorageQueueOutput, + StorageQueueOutputOptions, + TableOutput, + TableOutputOptions, + WebPubSubOutput, + WebPubSubOutputOptions, +} 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 table(options: TableOutputOptions): TableOutput { + return addOutputBindingName({ + ...options, + type: 'table', + }); +} + +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 cosmosDBMongo(options: CosmosDBMongoOutputOptions): CosmosDBMongoOutput { + return addOutputBindingName({ + ...options, + type: 'cosmosDBMongo', + }); +} + +export function sql(options: SqlOutputOptions): SqlOutput { + return addOutputBindingName({ + ...options, + type: 'sql', + }); +} + +export function mySql(options: MySqlOutputOptions): MySqlOutput { + return addOutputBindingName({ + ...options, + type: 'mysql', + }); +} + +export function webPubSub(options: WebPubSubOutputOptions): WebPubSubOutput { + return addOutputBindingName({ + ...options, + type: 'webPubSub', + }); +} + +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 index 59305e39..c89a9f5b 100644 --- a/src/trigger.ts +++ b/src/trigger.ts @@ -4,6 +4,8 @@ import { ConnectorTrigger, ConnectorTriggerOptions, + CosmosDBMongoTrigger, + CosmosDBMongoTriggerOptions, CosmosDBTrigger, CosmosDBTriggerOptions, EventGridTrigger, @@ -109,6 +111,13 @@ export function cosmosDB(options: CosmosDBTriggerOptions): CosmosDBTrigger { }); } +export function cosmosDBMongo(options: CosmosDBMongoTriggerOptions): CosmosDBMongoTrigger { + return addTriggerBindingName({ + ...options, + type: 'cosmosDBMongoTrigger', + }); +} + export function warmup(options: WarmupTriggerOptions): WarmupTrigger { return addTriggerBindingName({ ...options, diff --git a/test/cosmosDBMongo.test.ts b/test/cosmosDBMongo.test.ts new file mode 100644 index 00000000..b7b26477 --- /dev/null +++ b/test/cosmosDBMongo.test.ts @@ -0,0 +1,250 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import 'mocha'; +import { expect } from 'chai'; +import Module = require('module'); +import { input, output, trigger } from '../src'; +import { toCoreFunctionMetadata } from '../src/converters/toCoreFunctionMetadata'; +import { InvocationContext } from '../types'; + +describe('cosmosDBMongo bindings', () => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const handler = (_doc: unknown, _context: InvocationContext) => {}; + + const minimalTriggerOptions = { + connectionStringSetting: 'CosmosDBMongo', + databaseName: 'MyDatabase', + collectionName: 'MyCollection', + leaseDatabaseName: 'MyDatabase', + leaseCollectionName: 'leases', + }; + + // ------------------------------------------------------------------------- + // trigger + // ------------------------------------------------------------------------- + + describe('trigger.cosmosDBMongo', () => { + it('produces correct type string', () => { + const trig = trigger.cosmosDBMongo(minimalTriggerOptions); + expect(trig.type).to.equal('cosmosDBMongoTrigger'); + }); + + it('copies all trigger options onto the binding object', () => { + const trig = trigger.cosmosDBMongo({ + connectionStringSetting: 'CosmosDBMongo', + databaseName: 'db', + collectionName: 'coll', + createIfNotExists: true, + triggerLevel: 'Database', + leaseDatabaseName: 'leaseDb', + leaseCollectionName: 'leases', + leaseConnectionStringSetting: 'LeaseConn', + tenantId: 'tenant-abc', + managedIdentityClientId: 'mi-abc', + leaseTenantId: 'lease-tenant', + leaseManagedIdentityClientId: 'lease-mi', + }); + expect(trig.connectionStringSetting).to.equal('CosmosDBMongo'); + expect(trig.databaseName).to.equal('db'); + expect(trig.collectionName).to.equal('coll'); + expect(trig.createIfNotExists).to.equal(true); + expect(trig.triggerLevel).to.equal('Database'); + expect(trig.leaseDatabaseName).to.equal('leaseDb'); + expect(trig.leaseCollectionName).to.equal('leases'); + expect(trig.leaseConnectionStringSetting).to.equal('LeaseConn'); + expect(trig.tenantId).to.equal('tenant-abc'); + expect(trig.managedIdentityClientId).to.equal('mi-abc'); + expect(trig.leaseTenantId).to.equal('lease-tenant'); + expect(trig.leaseManagedIdentityClientId).to.equal('lease-mi'); + }); + + it('generates a deterministic binding name with Trigger suffix', () => { + const trig1 = trigger.cosmosDBMongo(minimalTriggerOptions); + const trig2 = trigger.cosmosDBMongo(minimalTriggerOptions); + expect(trig1.name).to.equal(trig2.name); + expect(trig1.name).to.include('cosmosDBMongoTrigger'); + }); + + it('sets direction = in via toCoreFunctionMetadata', () => { + const result = toCoreFunctionMetadata('mongoTrigFunc', { + handler, + trigger: trigger.cosmosDBMongo(minimalTriggerOptions), + }); + const bindingValues = Object.values(result.bindings) as Record[]; + const trig = bindingValues.find((b) => b['type'] === 'cosmosDBMongoTrigger'); + expect(trig).to.exist; + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + expect(trig!['direction']).to.equal('in'); + }); + }); + + describe('app.cosmosDBMongo', () => { + it('registers a function through the public wrapper', async () => { + const registerCalls: Array<{ metadata: { bindings: Record }; handler: unknown }> = []; + const fakeCoreApi = { + registerFunction: (metadata: { bindings: Record }, registeredHandler: unknown) => { + registerCalls.push({ metadata, handler: registeredHandler }); + }, + setProgrammingModel: () => {}, + }; + + const moduleCtor = Module as unknown as { _load: (...args: unknown[]) => unknown }; + const originalLoad = moduleCtor._load; + const appPath = require.resolve('../src/app'); + const coreApiPath = require.resolve('../src/utils/tryGetCoreApiLazy'); + + delete require.cache[appPath]; + delete require.cache[coreApiPath]; + + moduleCtor._load = function (...args: unknown[]) { + if (args[0] === '@azure/functions-core') { + return fakeCoreApi; + } + return originalLoad.apply(this, args); + }; + + try { + const appModule = await import('../src/app'); + const appHandler = (_doc: unknown, _context: InvocationContext) => {}; + + appModule.cosmosDBMongo('mongoAppFunc', { + ...minimalTriggerOptions, + handler: appHandler, + }); + + expect(registerCalls).to.have.lengthOf(1); + const registerCall = registerCalls[0]; + if (!registerCall) { + throw new Error('Expected app.cosmosDBMongo to register a function.'); + } + expect(registerCall.handler).to.equal(appHandler); + + const bindingValues = Object.values(registerCall.metadata.bindings) as Record[]; + const triggerBinding = bindingValues.find((b) => b['type'] === 'cosmosDBMongoTrigger'); + expect(triggerBinding).to.exist; + expect(triggerBinding?.['direction']).to.equal('in'); + } finally { + moduleCtor._load = originalLoad; + delete require.cache[appPath]; + delete require.cache[coreApiPath]; + } + }); + }); + + // ------------------------------------------------------------------------- + // input + // ------------------------------------------------------------------------- + + describe('input.cosmosDBMongo', () => { + it('produces correct type string', () => { + const inp = input.cosmosDBMongo({ + connectionStringSetting: 'CosmosDBMongo', + databaseName: 'db', + collectionName: 'coll', + }); + expect(inp.type).to.equal('cosmosDBMongo'); + }); + + it('copies all input options onto the binding object', () => { + const inp = input.cosmosDBMongo({ + connectionStringSetting: 'CosmosDBMongo', + databaseName: 'db', + collectionName: 'coll', + queryString: '{"status": "active"}', + createIfNotExists: false, + tenantId: 'tenant-xyz', + managedIdentityClientId: 'mi-xyz', + }); + expect(inp.connectionStringSetting).to.equal('CosmosDBMongo'); + expect(inp.databaseName).to.equal('db'); + expect(inp.collectionName).to.equal('coll'); + expect(inp.queryString).to.equal('{"status": "active"}'); + expect(inp.createIfNotExists).to.equal(false); + expect(inp.tenantId).to.equal('tenant-xyz'); + expect(inp.managedIdentityClientId).to.equal('mi-xyz'); + }); + + it('generates a deterministic binding name with Input suffix', () => { + const inp = input.cosmosDBMongo({ + connectionStringSetting: 'CosmosDBMongo', + databaseName: 'db', + collectionName: 'coll', + }); + expect(inp.name).to.include('Input'); + }); + + it('sets direction = in via toCoreFunctionMetadata extra input', () => { + const inp = input.cosmosDBMongo({ + connectionStringSetting: 'CosmosDBMongo', + databaseName: 'db', + collectionName: 'coll', + }); + const result = toCoreFunctionMetadata('mongoInputFunc', { + handler: () => {}, + trigger: trigger.cosmosDBMongo(minimalTriggerOptions), + extraInputs: [inp], + }); + const bindingValues = Object.values(result.bindings) as Record[]; + const inputBinding = bindingValues.find((b) => b['type'] === 'cosmosDBMongo' && b['direction'] === 'in'); + expect(inputBinding).to.exist; + }); + }); + + // ------------------------------------------------------------------------- + // output + // ------------------------------------------------------------------------- + + describe('output.cosmosDBMongo', () => { + it('produces correct type string', () => { + const out = output.cosmosDBMongo({ + connectionStringSetting: 'CosmosDBMongo', + databaseName: 'db', + collectionName: 'coll', + }); + expect(out.type).to.equal('cosmosDBMongo'); + }); + + it('copies all output options onto the binding object', () => { + const out = output.cosmosDBMongo({ + connectionStringSetting: 'CosmosDBMongo', + databaseName: 'db', + collectionName: 'coll', + createIfNotExists: true, + tenantId: 'tenant-out', + managedIdentityClientId: 'mi-out', + }); + expect(out.connectionStringSetting).to.equal('CosmosDBMongo'); + expect(out.databaseName).to.equal('db'); + expect(out.collectionName).to.equal('coll'); + expect(out.createIfNotExists).to.equal(true); + expect(out.tenantId).to.equal('tenant-out'); + expect(out.managedIdentityClientId).to.equal('mi-out'); + }); + + it('generates a deterministic binding name with Output suffix', () => { + const out = output.cosmosDBMongo({ + connectionStringSetting: 'CosmosDBMongo', + databaseName: 'db', + collectionName: 'coll', + }); + expect(out.name).to.include('Output'); + }); + + it('sets direction = out via toCoreFunctionMetadata extra output', () => { + const out = output.cosmosDBMongo({ + connectionStringSetting: 'CosmosDBMongo', + databaseName: 'db', + collectionName: 'coll', + }); + const result = toCoreFunctionMetadata('mongoOutputFunc', { + handler: () => {}, + trigger: trigger.cosmosDBMongo(minimalTriggerOptions), + extraOutputs: [out], + }); + const bindingValues = Object.values(result.bindings) as Record[]; + const outputBinding = bindingValues.find((b) => b['type'] === 'cosmosDBMongo' && b['direction'] === 'out'); + expect(outputBinding).to.exist; + }); + }); +}); diff --git a/types/app.d.ts b/types/app.d.ts index 9b59e4d7..94951409 100644 --- a/types/app.d.ts +++ b/types/app.d.ts @@ -3,6 +3,7 @@ import { ConnectorTriggerFunctionOptions } from './connectorTrigger'; import { CosmosDBFunctionOptions } from './cosmosDB'; +import { CosmosDBMongoFunctionOptions } from './cosmosDBMongo'; import { EventGridEvent, EventGridFunctionOptions } from './eventGrid'; import { EventHubFunctionOptions } from './eventHub'; import { GenericFunctionOptions } from './generic'; @@ -159,6 +160,13 @@ export function eventGrid(name: string, options: EventGridFu */ export function cosmosDB(name: string, options: CosmosDBFunctionOptions): void; +/** + * Registers an Azure Cosmos DB for MongoDB function in your app that will be triggered whenever change stream events occur + * @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 cosmosDBMongo(name: string, options: CosmosDBMongoFunctionOptions): void; + /** * Registers a connector trigger function in your app that will be triggered by Azure Logic Apps connector 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 diff --git a/types/cosmosDBMongo.d.ts b/types/cosmosDBMongo.d.ts new file mode 100644 index 00000000..d6ea4cb5 --- /dev/null +++ b/types/cosmosDBMongo.d.ts @@ -0,0 +1,189 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import { FunctionInput, FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger, RetryOptions } from './index'; +import { InvocationContext } from './InvocationContext'; + +/** + * Handler type for CosmosDB Mongo trigger functions. + * The trigger delivers the change stream document serialized as JSON. + */ +export type CosmosDBMongoHandler = (documents: T, context: InvocationContext) => FunctionResult; + +/** + * Options for registering a CosmosDB Mongo-triggered function via `app.cosmosDBMongo()`. + */ +export interface CosmosDBMongoFunctionOptions + extends CosmosDBMongoTriggerOptions, + Partial { + handler: CosmosDBMongoHandler; + + trigger?: CosmosDBMongoTrigger; + + /** + * An optional retry policy to rerun a failed execution until either successful completion occurs + * or the maximum number of retries is reached. + * Learn more [here](https://learn.microsoft.com/azure/azure-functions/functions-bindings-error-pages) + */ + retry?: RetryOptions; +} + +/** + * Options for configuring a CosmosDB Mongo trigger binding. + */ +export interface CosmosDBMongoTriggerOptions { + /** + * An app setting (or environment variable) with the MongoDB connection string. + * Defaults to "CosmosDBMongo" if not specified. + */ + connectionStringSetting: string; + + /** + * The name of the database being monitored. + */ + databaseName: string; + + /** + * The name of the collection being monitored. + * Optional when triggerLevel is "Database" or "Cluster". + */ + collectionName?: string; + + /** + * Whether to create the collection and lease collection if they do not exist. + * Default is false. + */ + createIfNotExists?: boolean; + + /** + * The level at which the trigger monitors for changes. + * Accepted values: "Collection" | "Database" | "Cluster". + * Default is "Collection". + */ + triggerLevel?: 'Collection' | 'Database' | 'Cluster'; + + /** + * The name of the database that holds the lease collection. + * The name of the database that holds the lease collection. + */ + leaseDatabaseName: string; + + /** + * The name of the collection used to store leases. + * The name of the collection used to store leases. + */ + leaseCollectionName: string; + + /** + * An app setting name for the connection string of the lease account. + * If not set, uses the monitored account connection string. + */ + leaseConnectionStringSetting?: string; + + /** + * The Azure AD tenant ID used for managed identity authentication on the monitored account. + */ + tenantId?: string; + + /** + * The managed identity client ID for the monitored account. + * Used for user-assigned managed identity authentication. + */ + managedIdentityClientId?: string; + + /** + * The Azure AD tenant ID used for managed identity authentication on the lease account. + */ + leaseTenantId?: string; + + /** + * The managed identity client ID for the lease account. + */ + leaseManagedIdentityClientId?: string; +} + +export type CosmosDBMongoTrigger = FunctionTrigger & CosmosDBMongoTriggerOptions; + +/** + * Options for configuring a CosmosDB Mongo input binding. + */ +export interface CosmosDBMongoInputOptions { + /** + * An app setting (or environment variable) with the MongoDB connection string. + * Defaults to "CosmosDBMongo" if not specified. + */ + connectionStringSetting: string; + + /** + * The name of the database to read from. + */ + databaseName: string; + + /** + * The name of the collection to read from. + */ + collectionName: string; + + /** + * An optional MongoDB filter document as a JSON string. + * Supports binding expressions, e.g. {"id": "{Query.id}"}. + */ + queryString?: string; + + /** + * Whether to create the collection if it does not exist. + * Default is false. + */ + createIfNotExists?: boolean; + + /** + * The Azure AD tenant ID used for managed identity authentication. + */ + tenantId?: string; + + /** + * The managed identity client ID for user-assigned managed identity authentication. + */ + managedIdentityClientId?: string; +} + +export type CosmosDBMongoInput = FunctionInput & CosmosDBMongoInputOptions; + +/** + * Options for configuring a CosmosDB Mongo output binding. + */ +export interface CosmosDBMongoOutputOptions { + /** + * An app setting (or environment variable) with the MongoDB connection string. + * Defaults to "CosmosDBMongo" if not specified. + */ + connectionStringSetting: string; + + /** + * The name of the database to write to. + */ + databaseName: string; + + /** + * The name of the collection to write to. + */ + collectionName: string; + + /** + * Whether to create the collection if it does not exist. + * Default is false. + */ + createIfNotExists?: boolean; + + /** + * The Azure AD tenant ID used for managed identity authentication. + */ + tenantId?: string; + + /** + * The managed identity client ID for user-assigned managed identity authentication. + */ + managedIdentityClientId?: string; +} + +export type CosmosDBMongoOutput = FunctionOutput & CosmosDBMongoOutputOptions; diff --git a/types/index.d.ts b/types/index.d.ts index 3c3ca572..5746a4d2 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -8,6 +8,7 @@ export * from './connectorTrigger'; export * from './cosmosDB'; export * from './cosmosDB.v3'; export * from './cosmosDB.v4'; +export * from './cosmosDBMongo'; export * from './eventGrid'; export * from './eventHub'; export * from './generic'; diff --git a/types/input.d.ts b/types/input.d.ts index b264405f..0769a7ec 100644 --- a/types/input.d.ts +++ b/types/input.d.ts @@ -2,6 +2,7 @@ // Licensed under the MIT License. import { CosmosDBInput, CosmosDBInputOptions } from './cosmosDB'; +import { CosmosDBMongoInput, CosmosDBMongoInputOptions } from './cosmosDBMongo'; import { GenericInputOptions } from './generic'; import { FunctionInput } from './index'; import { MySqlInput, MySqlInputOptions } from './mySql'; @@ -30,6 +31,11 @@ export function table(options: TableInputOptions): TableInput; */ export function cosmosDB(options: CosmosDBInputOptions): CosmosDBInput; +/** + * [Link to docs and examples](tdb, will update later) + */ +export function cosmosDBMongo(options: CosmosDBMongoInputOptions): CosmosDBMongoInput; + /** * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-azure-sql-input?pivots=programming-language-javascript) */ diff --git a/types/output.d.ts b/types/output.d.ts index e9e08d9e..0abccc1b 100644 --- a/types/output.d.ts +++ b/types/output.d.ts @@ -2,6 +2,7 @@ // Licensed under the MIT License. import { CosmosDBOutput, CosmosDBOutputOptions } from './cosmosDB'; +import { CosmosDBMongoOutput, CosmosDBMongoOutputOptions } from './cosmosDBMongo'; import { EventGridOutput, EventGridOutputOptions } from './eventGrid'; import { EventHubOutput, EventHubOutputOptions } from './eventHub'; import { GenericOutputOptions } from './generic'; @@ -64,6 +65,11 @@ export function eventGrid(options: EventGridOutputOptions): EventGridOutput; */ export function cosmosDB(options: CosmosDBOutputOptions): CosmosDBOutput; +/** + * [Link to docs and examples](tdb, will update later) + */ +export function cosmosDBMongo(options: CosmosDBMongoOutputOptions): CosmosDBMongoOutput; + /** * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-azure-sql-output?pivots=programming-language-javascript) */ diff --git a/types/trigger.d.ts b/types/trigger.d.ts index efde1f01..8206f0e9 100644 --- a/types/trigger.d.ts +++ b/types/trigger.d.ts @@ -3,6 +3,7 @@ import { ConnectorTrigger, ConnectorTriggerOptions } from './connectorTrigger'; import { CosmosDBTrigger, CosmosDBTriggerOptions } from './cosmosDB'; +import { CosmosDBMongoTrigger, CosmosDBMongoTriggerOptions } from './cosmosDBMongo'; import { EventGridTrigger, EventGridTriggerOptions } from './eventGrid'; import { EventHubTrigger, EventHubTriggerOptions } from './eventHub'; import { GenericTriggerOptions } from './generic'; @@ -74,6 +75,11 @@ export function eventGrid(options: EventGridTriggerOptions): EventGridTrigger; */ export function cosmosDB(options: CosmosDBTriggerOptions): CosmosDBTrigger; +/** + * [Link to docs and examples](tdb, will update later) + */ +export function cosmosDBMongo(options: CosmosDBMongoTriggerOptions): CosmosDBMongoTrigger; + /** * [Link to docs and examples](https://learn.microsoft.com/azure/azure-functions/functions-bindings-warmup?tabs=isolated-process&pivots=programming-language-javascript) */ diff --git a/types/webpubsub.d.ts b/types/webpubsub.d.ts index 5b9b2bac..b72cd0dc 100644 --- a/types/webpubsub.d.ts +++ b/types/webpubsub.d.ts @@ -44,7 +44,8 @@ export interface WebPubSubTriggerOptions { clientProtocols?: 'all' | 'webPubSub' | 'mqtt'; /** - * Optional - The names of app settings or setting collections that specify the upstream Azure Web PubSub services + * Optional - The names of app settings or app setting collections (for identity-based grouped settings) + * that specify the upstream Azure Web PubSub services. * Used for signature validation * Defaults to "WebPubSubConnectionString" if not specified */ @@ -101,8 +102,10 @@ export interface WebPubSubContextInputOptions { /** * Optional - The names of app settings or setting collections that specify the upstream Azure Web PubSub services. - * The value is used for Abuse Protection and Signature validation. - * The value is auto resolved with "WebPubSubConnectionString" by default. + * This replaces the deprecated `connection` option. + * The values are used for Abuse Protection and Signature validation. + * When multiple values are provided, each configured service is considered during signature validation. + * The values are auto resolved with "WebPubSubConnectionString" by default. */ connections?: string[];