diff --git a/src/app.ts b/src/app.ts index 4473f1a..602d6ea 100644 --- a/src/app.ts +++ b/src/app.ts @@ -78,6 +78,14 @@ function convertToGenericOptions & Pa }; } +function addDeferredBindingsFlag(triggerType: string): { [key: string]: string } { + if (triggerType === 'blobTrigger') { + return { supportsDeferredBinding: 'true' }; + } + + return { supportsDeferredBinding: 'false' }; +} + export function get(name: string, optionsOrHandler: HttpMethodFunctionOptions | HttpHandler): void { http(name, convertToHttpOptions(optionsOrHandler, 'GET')); } @@ -152,6 +160,7 @@ export function generic(name: string, options: GenericFunctionOptions): void { ...trigger, direction: 'in', type: isTrigger(trigger.type) ? trigger.type : trigger.type + 'Trigger', + properties: addDeferredBindingsFlag(options.trigger.type), }; if (options.extraInputs) { diff --git a/src/converters/fromRpcTypedData.ts b/src/converters/fromRpcTypedData.ts index a8ed963..16c21b4 100644 --- a/src/converters/fromRpcTypedData.ts +++ b/src/converters/fromRpcTypedData.ts @@ -3,6 +3,7 @@ import { RpcTypedData } from '@azure/functions-core'; import { HttpRequest } from '../http/HttpRequest'; +import { ConnectionInfo } from '../utils/ConnectionInfo'; import { isDefined } from '../utils/nonNull'; export function fromRpcTypedData(data: RpcTypedData | null | undefined): unknown { @@ -30,6 +31,8 @@ export function fromRpcTypedData(data: RpcTypedData | null | undefined): unknown return data.collectionDouble.double; } else if (data.collectionSint64 && isDefined(data.collectionSint64.sint64)) { return data.collectionSint64.sint64; + } else if (data.modelBindingData && isDefined(data.modelBindingData.content)) { + return new ConnectionInfo(data.modelBindingData); } else { return undefined; } diff --git a/src/index.ts b/src/index.ts index 761f676..df1efe2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,4 +14,5 @@ export * as input from './input'; export { InvocationContext } from './InvocationContext'; export * as output from './output'; export * as trigger from './trigger'; +export { ConnectionInfo } from './utils/ConnectionInfo'; export { Disposable } from './utils/Disposable'; diff --git a/src/utils/ConnectionInfo.ts b/src/utils/ConnectionInfo.ts new file mode 100644 index 0000000..f6bbdb1 --- /dev/null +++ b/src/utils/ConnectionInfo.ts @@ -0,0 +1,26 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import { ModelBindingData } from '@azure/functions-core'; + +export interface ConnectionInfoContent { + Connection: string; + ContainerName: string; + BlobName: string; +} + +export class ConnectionInfo { + version: string; + source: string; + contentType: string; + content: ConnectionInfoContent | undefined; + + constructor(modelBindingData: ModelBindingData) { + this.version = modelBindingData.version as string; + this.source = modelBindingData.source as string; + this.contentType = modelBindingData.contentType as string; + this.content = modelBindingData.content + ? (JSON.parse(modelBindingData.content.toString()) as ConnectionInfoContent) + : undefined; + } +} diff --git a/types-core/index.d.ts b/types-core/index.d.ts index 20d118b..10b8fa8 100644 --- a/types-core/index.d.ts +++ b/types-core/index.d.ts @@ -353,12 +353,18 @@ declare module '@azure/functions-core' { direction?: RpcBindingDirection | null; dataType?: RpcBindingDataType | null; + + properties?: RpcBindingProperties | null; } type RpcBindingDirection = 'in' | 'out' | 'inout'; type RpcBindingDataType = 'undefined' | 'string' | 'binary' | 'stream'; + interface RpcBindingProperties { + supportsDeferredBinding?: 'true' | 'false' | null; + } + interface RpcRetryOptions { maxRetryCount?: number | null; @@ -395,24 +401,33 @@ declare module '@azure/functions-core' { collectionDouble?: RpcCollectionDouble | null; collectionSint64?: RpcCollectionSInt64 | null; + + modelBindingData?: ModelBindingData | null; } - interface RpcCollectionSInt64 { - sint64?: (number | Long)[] | null; + interface RpcCollectionBytes { + bytes?: Uint8Array[] | null; } interface RpcCollectionString { string?: string[] | null; } - interface RpcCollectionBytes { - bytes?: Uint8Array[] | null; - } - interface RpcCollectionDouble { double?: number[] | null; } + interface RpcCollectionSInt64 { + sint64?: (number | Long)[] | null; + } + + interface ModelBindingData { + content?: Buffer | null; + contentType?: string | null; + source?: string | null; + version?: string | null; + } + interface RpcInvocationRequest { invocationId?: string | null; diff --git a/types/connectionInfo.d.ts b/types/connectionInfo.d.ts new file mode 100644 index 0000000..76be7d8 --- /dev/null +++ b/types/connectionInfo.d.ts @@ -0,0 +1,24 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +export interface ModelBindingData { + content?: Buffer | null; + contentType?: string | null; + source?: string | null; + version?: string | null; +} + +export interface ConnectionInfoContent { + Connection: string; + ContainerName: string; + BlobName: string; +} + +export declare class ConnectionInfo { + version: string; + source: string; + contentType: string; + content: ConnectionInfoContent | undefined; + + constructor(modelBindingData: ModelBindingData); +} diff --git a/types/index.d.ts b/types/index.d.ts index 2fc5406..2f1e740 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -4,6 +4,7 @@ import { InvocationContext } from './InvocationContext'; export * as app from './app'; +export * from './connectionInfo'; export * from './cosmosDB'; export * from './cosmosDB.v3'; export * from './cosmosDB.v4';