Skip to content

Dc/sdk bindings #337

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

Draft
wants to merge 13 commits into
base: v4.x
Choose a base branch
from
9 changes: 9 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ function convertToGenericOptions<T extends Omit<FunctionOptions, 'trigger'> & 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'));
}
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/converters/fromRpcTypedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
26 changes: 26 additions & 0 deletions src/utils/ConnectionInfo.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
27 changes: 21 additions & 6 deletions types-core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
24 changes: 24 additions & 0 deletions types/connectionInfo.d.ts
Original file line number Diff line number Diff line change
@@ -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);
}
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down