Skip to content

Commit 5d402f9

Browse files
Init: input/output/trigger
1 parent 5a93c76 commit 5d402f9

File tree

8 files changed

+179
-1
lines changed

8 files changed

+179
-1
lines changed

src/input.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import {
1212
StorageBlobInputOptions,
1313
TableInput,
1414
TableInputOptions,
15+
WebPubSubConnectionInput,
16+
WebPubSubConnectionInputOptions,
17+
WebPubSubContextInput,
18+
WebPubSubContextInputOptions,
1519
} from '@azure/functions';
1620
import { addBindingName } from './addBindingName';
1721

@@ -43,6 +47,20 @@ export function sql(options: SqlInputOptions): SqlInput {
4347
});
4448
}
4549

50+
export function webPubSubConnection(options: WebPubSubConnectionInputOptions): WebPubSubConnectionInput {
51+
return addInputBindingName({
52+
...options,
53+
type: 'webPubSubConnection',
54+
});
55+
}
56+
57+
export function webPubSubContext(options: WebPubSubContextInputOptions): WebPubSubContextInput {
58+
return addInputBindingName({
59+
...options,
60+
type: 'webPubSubContext',
61+
});
62+
}
63+
4664
export function generic(options: GenericInputOptions): FunctionInput {
4765
return addInputBindingName(options);
4866
}

src/output.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
StorageQueueOutputOptions,
2525
TableOutput,
2626
TableOutputOptions,
27+
WebPubSubOutput,
28+
WebPubSubOutputOptions,
2729
} from '@azure/functions';
2830
import { addBindingName } from './addBindingName';
2931

@@ -97,6 +99,13 @@ export function sql(options: SqlOutputOptions): SqlOutput {
9799
});
98100
}
99101

102+
export function webPubSub(options: WebPubSubOutputOptions): WebPubSubOutput {
103+
return addOutputBindingName({
104+
...options,
105+
type: 'webPubSub',
106+
});
107+
}
108+
100109
export function generic(options: GenericOutputOptions): FunctionOutput {
101110
return addOutputBindingName(options);
102111
}

src/trigger.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
TimerTriggerOptions,
2727
WarmupTrigger,
2828
WarmupTriggerOptions,
29+
WebPubSubTrigger,
30+
WebPubSubTriggerOptions,
2931
} from '@azure/functions';
3032
import { addBindingName } from './addBindingName';
3133

@@ -108,6 +110,13 @@ export function sql(options: SqlTriggerOptions): SqlTrigger {
108110
});
109111
}
110112

113+
export function webPubSub(options: WebPubSubTriggerOptions): WebPubSubTrigger {
114+
return addTriggerBindingName({
115+
...options,
116+
type: 'webPubSubTrigger',
117+
});
118+
}
119+
111120
export function generic(options: GenericTriggerOptions): FunctionTrigger {
112121
return addTriggerBindingName(options);
113122
}

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export * from './table';
2626
export * from './timer';
2727
export * as trigger from './trigger';
2828
export * from './warmup';
29+
export * from './webpubsub';
2930

3031
/**
3132
* Void if no `return` output is registered

types/input.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import { FunctionInput } from './index';
77
import { SqlInput, SqlInputOptions } from './sql';
88
import { StorageBlobInput, StorageBlobInputOptions } from './storage';
99
import { TableInput, TableInputOptions } from './table';
10+
import {
11+
WebPubSubConnectionInput,
12+
WebPubSubConnectionInputOptions,
13+
WebPubSubContextInput,
14+
WebPubSubContextInputOptions,
15+
} from './webpubsub';
1016

1117
/**
1218
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-blob-input?pivots=programming-language-javascript)
@@ -28,6 +34,16 @@ export function cosmosDB(options: CosmosDBInputOptions): CosmosDBInput;
2834
*/
2935
export function sql(options: SqlInputOptions): SqlInput;
3036

37+
/**
38+
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-web-pubsub-input?pivots=programming-language-javascript)
39+
*/
40+
export function webPubSubConnection(options: WebPubSubConnectionInputOptions): WebPubSubConnectionInput;
41+
42+
/**
43+
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-web-pubsub-input?pivots=programming-language-javascript)
44+
*/
45+
export function webPubSubContext(options: WebPubSubContextInputOptions): WebPubSubContextInput;
46+
3147
/**
3248
* A generic option that can be used for any input type
3349
* Use this method if your desired input type does not already have its own method

types/output.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import { SqlOutput, SqlOutputOptions } from './sql';
1717
import { StorageBlobOutput, StorageBlobOutputOptions, StorageQueueOutput, StorageQueueOutputOptions } from './storage';
1818
import { TableOutput, TableOutputOptions } from './table';
19+
import { WebPubSubOutput, WebPubSubOutputOptions } from './webpubsub';
1920

2021
/**
2122
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-http-webhook-output?&pivots=programming-language-javascript)
@@ -67,6 +68,11 @@ export function cosmosDB(options: CosmosDBOutputOptions): CosmosDBOutput;
6768
*/
6869
export function sql(options: SqlOutputOptions): SqlOutput;
6970

71+
/**
72+
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-web-pubsub-output?pivots=programming-language-javascript)
73+
*/
74+
export function webPubSub(options: WebPubSubOutputOptions): WebPubSubOutput;
75+
7076
/**
7177
* A generic option that can be used for any output type
7278
* Use this method if your desired output type does not already have its own method

types/trigger.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from './storage';
2323
import { TimerTrigger, TimerTriggerOptions } from './timer';
2424
import { WarmupTrigger, WarmupTriggerOptions } from './warmup';
25-
25+
import { WebPubSubTrigger, WebPubSubTriggerOptions } from './webpubsub';
2626
/**
2727
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-http-webhook-trigger?&pivots=programming-language-javascript)
2828
*/
@@ -78,6 +78,11 @@ export function warmup(options: WarmupTriggerOptions): WarmupTrigger;
7878
*/
7979
export function sql(options: SqlTriggerOptions): SqlTrigger;
8080

81+
/**
82+
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-web-pubsub-trigger?pivots=programming-language-javascript)
83+
*/
84+
export function webPubSub(options: WebPubSubTriggerOptions): WebPubSubTrigger;
85+
8186
/**
8287
* A generic option that can be used for any trigger type
8388
* Use this method if your desired trigger type does not already have its own method

types/webpubsub.d.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
import { FunctionInput, FunctionOutput, FunctionTrigger } from './index';
5+
6+
export interface WebPubSubTriggerOptions {
7+
/**
8+
* Required - The variable name used in function code for the parameter that receives the event data
9+
*/
10+
name: string;
11+
12+
/**
13+
* Required - The name of the hub to which the function is bound
14+
*/
15+
hub: string;
16+
17+
/**
18+
* Required - The type of event to which the function should respond
19+
* Must be either 'user' or 'system'
20+
*/
21+
eventType: 'user' | 'system';
22+
23+
/**
24+
* Required - The name of the event to which the function should respond
25+
* For system event type: 'connect', 'connected', or 'disconnected'
26+
* For user-defined subprotocols: 'message'
27+
* For system supported subprotocol json.webpubsub.azure.v1: user-defined event name
28+
*/
29+
eventName: string;
30+
31+
/**
32+
* Optional - Specifies which client protocol can trigger the Web PubSub trigger functions
33+
* Default is 'all'
34+
*/
35+
clientProtocols?: 'all' | 'webPubSub' | 'mqtt';
36+
37+
/**
38+
* Optional - The name of an app setting or setting collection that specifies the upstream Azure Web PubSub service
39+
* Used for signature validation
40+
* Defaults to "WebPubSubConnectionString" if not specified
41+
* Set to null to disable validation
42+
*/
43+
connection?: string | null;
44+
}
45+
export type WebPubSubTrigger = FunctionTrigger & WebPubSubTriggerOptions;
46+
47+
export interface WebPubSubConnectionInputOptions {
48+
/**
49+
* Required - Variable name used in function code for input connection binding object.
50+
*/
51+
name?: string;
52+
53+
/**
54+
* Required - The name of the Web PubSub hub for the function to be triggered.
55+
* Can be set in the attribute (higher priority) or in app settings as a global value.
56+
*/
57+
hub: string;
58+
59+
/**
60+
* Optional - The value of the user identifier claim to be set in the access key token.
61+
*/
62+
userId?: string;
63+
64+
/**
65+
* Optional - The client protocol type.
66+
* Valid values are 'default' and 'mqtt'.
67+
* For MQTT clients, you must set it to 'mqtt'.
68+
* For other clients, you can omit the property or set it to 'default'.
69+
*/
70+
clientProtocol?: 'default' | 'mqtt';
71+
72+
/**
73+
* Optional - The name of the app setting that contains the Web PubSub Service connection string.
74+
* Defaults to "WebPubSubConnectionString".
75+
*/
76+
connection?: string;
77+
}
78+
export type WebPubSubConnectionInput = FunctionInput & WebPubSubConnectionInputOptions;
79+
80+
export interface WebPubSubContextInputOptions {
81+
/**
82+
* Required - Variable name used in function code for input Web PubSub request.
83+
*/
84+
name: string;
85+
86+
/**
87+
* Optional - The name of an app settings or setting collection that specifies the upstream Azure Web PubSub service.
88+
* The value is used for Abuse Protection and Signature validation.
89+
* The value is auto resolved with "WebPubSubConnectionString" by default.
90+
* Null means the validation isn't needed and always succeeds.
91+
*/
92+
connection?: string;
93+
}
94+
export type WebPubSubContextInput = FunctionInput & WebPubSubContextInputOptions;
95+
96+
export interface WebPubSubOutputOptions {
97+
/**
98+
* Required - Variable name used in function code for output binding object.
99+
*/
100+
name: string;
101+
102+
/**
103+
* Required - The name of the hub to which the function is bound.
104+
* Can be set in the attribute (higher priority) or in app settings as a global value.
105+
*/
106+
hub: string;
107+
108+
/**
109+
* Optional - The name of the app setting that contains the Web PubSub Service connection string.
110+
* Defaults to "WebPubSubConnectionString".
111+
*/
112+
connection?: string;
113+
}
114+
export type WebPubSubOutput = FunctionOutput & WebPubSubOutputOptions;

0 commit comments

Comments
 (0)