@@ -6,17 +6,19 @@ import * as coreTypes from '@azure/functions-core';
66import { returnBindingKey } from '../constants' ;
77import { AzFuncSystemError } from '../errors' ;
88import { isTrigger } from '../utils/isTrigger' ;
9+ import { workerSystemLog } from '../utils/workerSystemLog' ;
910import { toRpcDuration } from './toRpcDuration' ;
1011
1112export function toCoreFunctionMetadata ( name : string , options : GenericFunctionOptions ) : coreTypes . FunctionMetadata {
1213 const bindings : Record < string , coreTypes . RpcBindingInfo > = { } ;
1314 const bindingNames : string [ ] = [ ] ;
14-
1515 const trigger = options . trigger ;
16+
1617 bindings [ trigger . name ] = {
1718 ...trigger ,
1819 direction : 'in' ,
1920 type : isTrigger ( trigger . type ) ? trigger . type : trigger . type + 'Trigger' ,
21+ properties : addSdkBindingsFlag ( options . trigger ?. sdkBinding , name , trigger . type , trigger . name , false ) ,
2022 } ;
2123 bindingNames . push ( trigger . name ) ;
2224
@@ -25,6 +27,7 @@ export function toCoreFunctionMetadata(name: string, options: GenericFunctionOpt
2527 bindings [ input . name ] = {
2628 ...input ,
2729 direction : 'in' ,
30+ properties : addSdkBindingsFlag ( input ?. sdkBinding , name , input . type , input . name , true ) ,
2831 } ;
2932 bindingNames . push ( input . name ) ;
3033 }
@@ -74,3 +77,45 @@ export function toCoreFunctionMetadata(name: string, options: GenericFunctionOpt
7477
7578 return { name, bindings, retryOptions } ;
7679}
80+
81+ /**
82+ * Adds the deferred binding flags to function bindings based on the binding configuration
83+ * @param sdkBindingType Boolean indicating if this is an SDK binding
84+ * @param functionName The name of the function for logging purposes
85+ * @param triggerType The type of the trigger or binding
86+ * @param bindingOrTriggerName The name of the trigger or binding
87+ * @param isBinding Boolean indicating if this is a binding (vs a trigger)
88+ * @returns Object with supportsDeferredBinding property set to 'true' or 'false'
89+ */
90+ export function addSdkBindingsFlag (
91+ sdkBindingType ?: boolean | unknown ,
92+ functionName ?: string ,
93+ triggerType ?: string ,
94+ bindingOrTriggerName ?: string ,
95+ isBinding ?: boolean
96+ ) : { [ key : string ] : string } {
97+ // Ensure that trigger type is valid and supported
98+ if ( sdkBindingType !== undefined && sdkBindingType === true ) {
99+ const entityType = isBinding ? 'binding' : 'trigger' ;
100+
101+ // Create structured JSON log entry
102+ const logData = {
103+ operation : 'EnableDeferredBinding' ,
104+ properties : {
105+ functionName : functionName || 'unknown' ,
106+ entityType : entityType ,
107+ triggerType : triggerType || 'unknown' ,
108+ bindingOrTriggerName : bindingOrTriggerName || 'unknown' ,
109+ supportsDeferredBinding : true ,
110+ } ,
111+ message : `Enabled Deferred Binding of type '${ triggerType || 'unknown' } ' for function '${
112+ functionName || 'unknown'
113+ } '`,
114+ } ;
115+ // Log both the structured data
116+ workerSystemLog ( 'information' , JSON . stringify ( logData ) ) ;
117+ return { supportsDeferredBinding : 'true' } ;
118+ }
119+
120+ return { supportsDeferredBinding : 'false' } ;
121+ }
0 commit comments