Skip to content

Adding ServiceBus Trigger Chnages #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: v4.x-preview
Choose a base branch
from

Conversation

swapnil-nagar
Copy link
Contributor

@swapnil-nagar swapnil-nagar commented Jun 23, 2025

Summary

This PR adds support for the autoCompleteMessages configuration option to Service Bus triggers, allowing developers to control whether messages are automatically completed after successful processing.

Background

Currently, the Service Bus trigger in Azure Functions for Node.js lacks explicit control over message completion behavior. This enhancement brings parity with other Azure Functions runtimes by introducing the autoCompleteMessages option that was already defined in the TypeScript definitions but not fully implemented.

Changes Made
Type Definitions (already present)
ServiceBusQueueTriggerOptions.autoCompleteMessages?: boolean - Controls automatic message completion for queue triggers
Enhanced JSDoc documentation referencing official Azure documentation

@swapnil-nagar swapnil-nagar marked this pull request as ready for review June 26, 2025 05:45
@swapnil-nagar swapnil-nagar requested a review from a team as a code owner June 26, 2025 05:45
@swapnil-nagar swapnil-nagar requested a review from Copilot June 26, 2025 05:45
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR extends fromRpcTypedData to handle the collectionModelBindingData case and adds comprehensive tests for this new path.

  • Implements a new branch in fromRpcTypedData to create clients from collectionModelBindingData
  • Adds unit tests covering valid, edge, and error scenarios for collectionModelBindingData
  • Ensures fallback behavior remains unchanged

Reviewed Changes

Copilot reviewed 2 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/converters/fromRpcTypedData.ts Added else if branch for collectionModelBindingData handling and error wrapping
test/converters/fromRpcTypedData.test.ts Introduced tests for successful client creation, undefined source, thrown errors, and non-Error exceptions in the new path


it('should handle non-Error exceptions by converting to string for collectionModelBindingData', () => {
const mockResolver = {
createClient: sinon.stub().throws('String exception for collection'), // Non-Error exception
Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stubbed exception message ('String exception for collection') does not match the expected test assertion ('Sinon-provided String exception for collection'). Update either the thrown string to 'Sinon-provided String exception for collection' or adjust the expected error message in the test.

Suggested change
createClient: sinon.stub().throws('String exception for collection'), // Non-Error exception
createClient: sinon.stub().throws('Sinon-provided String exception for collection'), // Non-Error exception

Copilot uses AI. Check for mistakes.

Comment on lines +50 to +51
data?.collectionModelBindingData?.modelBindingData[0]?.source,
data?.collectionModelBindingData?.modelBindingData
Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The optional chaining on data and its properties is unnecessary here since the enclosing else if ensures collectionModelBindingData and modelBindingData are defined. You can simplify this to data.collectionModelBindingData.modelBindingData[0].source.

Suggested change
data?.collectionModelBindingData?.modelBindingData[0]?.source,
data?.collectionModelBindingData?.modelBindingData
data.collectionModelBindingData.modelBindingData[0].source,
data.collectionModelBindingData.modelBindingData

Copilot uses AI. Check for mistakes.

Comment on lines +45 to +51
} else if (data.collectionModelBindingData && isDefined(data.collectionModelBindingData.modelBindingData)) {
try {
const resourceFactoryResolver: ResourceFactoryResolver = ResourceFactoryResolver.getInstance();
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
return resourceFactoryResolver.createClient(
data?.collectionModelBindingData?.modelBindingData[0]?.source,
data?.collectionModelBindingData?.modelBindingData
Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider validating that modelBindingData is non-empty before accessing the first element. If the array is empty, calling createClient with an undefined source may lead to unintended behavior.

Suggested change
} else if (data.collectionModelBindingData && isDefined(data.collectionModelBindingData.modelBindingData)) {
try {
const resourceFactoryResolver: ResourceFactoryResolver = ResourceFactoryResolver.getInstance();
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
return resourceFactoryResolver.createClient(
data?.collectionModelBindingData?.modelBindingData[0]?.source,
data?.collectionModelBindingData?.modelBindingData
} else if (
data.collectionModelBindingData &&
isDefined(data.collectionModelBindingData.modelBindingData) &&
data.collectionModelBindingData.modelBindingData.length > 0
) {
try {
const resourceFactoryResolver: ResourceFactoryResolver = ResourceFactoryResolver.getInstance();
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
return resourceFactoryResolver.createClient(
data.collectionModelBindingData.modelBindingData[0].source,
data.collectionModelBindingData.modelBindingData

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant