Skip to content
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

Add support for table input & output #146

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
GenericInputOptions,
StorageBlobInput,
StorageBlobInputOptions,
TableInput,
TableInputOptions,
} from '@azure/functions';
import { addBindingName } from './addBindingName';

Expand All @@ -18,6 +20,13 @@ export function storageBlob(options: StorageBlobInputOptions): StorageBlobInput
});
}

export function table(options: TableInputOptions): TableInput {
return addInputBindingName({
...options,
type: 'table',
});
}

export function cosmosDB(options: CosmosDBInputOptions): CosmosDBInput {
return addInputBindingName({
...options,
Expand Down
9 changes: 9 additions & 0 deletions src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
StorageBlobOutputOptions,
StorageQueueOutput,
StorageQueueOutputOptions,
TableOutput,
TableOutputOptions,
} from '@azure/functions';
import { addBindingName } from './addBindingName';

Expand All @@ -37,6 +39,13 @@ export function storageBlob(options: StorageBlobOutputOptions): StorageBlobOutpu
});
}

export function table(options: TableOutputOptions): TableOutput {
return addOutputBindingName({
...options,
type: 'table',
});
}

export function storageQueue(options: StorageQueueOutputOptions): StorageQueueOutput {
return addOutputBindingName({
...options,
Expand Down
14 changes: 14 additions & 0 deletions types/InvocationContext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { HttpOutput, HttpResponse } from './http';
import { FunctionInput, FunctionOutput, FunctionTrigger } from './index';
import { ServiceBusQueueOutput, ServiceBusTopicOutput } from './serviceBus';
import { StorageBlobInput, StorageBlobOutput, StorageQueueOutput } from './storage';
import { TableInput, TableOutput } from './table';

/**
* Contains metadata and helper methods specific to this invocation
Expand Down Expand Up @@ -108,6 +109,12 @@ export interface InvocationContextExtraInputs {
*/
get(input: StorageBlobInput): unknown;

/**
* Get a secondary table input for this invocation
* @input the configuration object for this table input
*/
get(input: TableInput): unknown;

/**
* Get a secondary Cosmos DB documents input for this invocation
* @input the configuration object for this Cosmos DB input
Expand Down Expand Up @@ -146,6 +153,13 @@ export interface InvocationContextExtraOutputs {
*/
set(output: StorageBlobOutput, blob: unknown): void;

/**
* Set a secondary table output for this invocation
* @output the configuration object for this table output
* @tableEntity the table output value
*/
set(output: TableOutput, tableEntity: unknown): void;

/**
* Set a secondary storage queue entry output for this invocation
* @output the configuration object for this storage queue output
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * as input from './input';
export * as output from './output';
export * from './serviceBus';
export * from './storage';
export * from './table';
export * from './timer';
export * as trigger from './trigger';

Expand Down
6 changes: 6 additions & 0 deletions types/input.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import { CosmosDBInput, CosmosDBInputOptions } from './cosmosDB';
import { GenericInputOptions } from './generic';
import { FunctionInput } from './index';
import { StorageBlobInput, StorageBlobInputOptions } from './storage';
import { TableInput, TableInputOptions } from './table';

/**
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-blob-input?pivots=programming-language-javascript)
*/
export function storageBlob(options: StorageBlobInputOptions): StorageBlobInput;

/**
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-table-input?pivots=programming-language-javascript)
*/
export function table(options: TableInputOptions): TableInput;

/**
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-cosmosdb-v2-input?pivots=programming-language-javascript)
*/
Expand Down
6 changes: 6 additions & 0 deletions types/output.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ServiceBusTopicOutputOptions,
} from './serviceBus';
import { StorageBlobOutput, StorageBlobOutputOptions, StorageQueueOutput, StorageQueueOutputOptions } from './storage';
import { TableOutput, TableOutputOptions } from './table';

/**
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-http-webhook-output?&pivots=programming-language-javascript)
Expand All @@ -25,6 +26,11 @@ export function http(options: HttpOutputOptions): HttpOutput;
*/
export function storageBlob(options: StorageBlobOutputOptions): StorageBlobOutput;

/**
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-table-output?pivots=programming-language-javascript)
*/
export function table(options: TableOutputOptions): TableOutput;

/**
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-queue-output?pivots=programming-language-javascript)
*/
Expand Down
60 changes: 60 additions & 0 deletions types/table.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.

import { FunctionInput, FunctionOutput } from './index';

export interface TableOutputOptions {
/**
* The table name
*/
tableName: string;

/**
* An app setting (or environment variable) with the storage connection string to be used by this table output
*/
connection: string;

/**
* The partition key of the table entity to write.
*/
partitionKey?: string;

/**
* The row key of the table entity to write.
*/
rowKey?: string;
}
export type TableOutput = FunctionOutput & TableOutputOptions;

export interface TableInputOptions {
/**
* The table name
*/
tableName: string;

/**
* An app setting (or environment variable) with the storage connection string to be used by this table input
*/
connection: string;

/**
* The partition key of the table entity to read.
*/
partitionKey?: string;

/**
* The row key of the table entity to read. Can't be used with `take` or `filter`.
*/
rowKey?: string;

/**
* The maximum number of entities to return. Can't be used with `rowKey`
*/
take?: number;

/**
* An OData filter expression for the entities to return from the table. Can't be used with `rowKey`.
*/
filter?: string;
}
export type TableInput = FunctionInput & TableInputOptions;