Skip to content

Commit d2becdd

Browse files
committed
added support of @requiresStreamAddress and @requiresStreamParameterAddresses
1 parent 78dec82 commit d2becdd

13 files changed

Lines changed: 516 additions & 85 deletions

File tree

package-lock.json

Lines changed: 339 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/custom-functions-metadata/src/parseTree.ts

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ const EXCLUDEFROMAUTOCOMPLETE = "excludefromautocomplete";
133133
const HELPURL_PARAM = "helpurl";
134134
const LINKEDENTITYLOADSERVICE = "linkedentityloadservice";
135135
const REQUIRESADDRESS = "requiresaddress";
136+
const REQUIRESSTREAMADDRESS = "requiresstreamaddress";
136137
const REQUIRESPARAMETERADDRESSES = "requiresparameteraddresses";
138+
const REQUIRESSTREAMPARAMETERADDRESSES = "requiresstreamparameteraddresses";
137139
const STREAMING = "streaming";
138140
const VOLATILE = "volatile";
139141
const SUPPORT_SYNC = "supportsync";
@@ -688,27 +690,46 @@ function getOptions(
688690
isInvocationFunction: boolean,
689691
extra: IFunctionExtras
690692
): IFunctionOptions {
693+
const addressRequired = isAddressRequired(func);
694+
const streamAddressRequired = isStreamAddressRequired(func);
695+
const parameterAddressesRequired = isRequiresParameterAddresses(func);
696+
const streamParameterAddressesRequired = isRequiresStreamParameterAddresses(func);
697+
const hasStreamingTag = hasTag(func, STREAMING);
698+
const streamEnabled = isStreaming(func, isStreamingFunction);
699+
691700
const optionsItem: IFunctionOptions = {
692701
cancelable: isCancelableTag(func, isCancelableFunction),
693-
requiresAddress: isAddressRequired(func) && !isStreaming(func, isStreamingFunction),
694-
requiresStreamAddress: isAddressRequired(func) && isStreaming(func, isStreamingFunction),
695-
stream: isStreaming(func, isStreamingFunction),
702+
requiresAddress: addressRequired && !streamEnabled,
703+
requiresStreamAddress: streamAddressRequired || (addressRequired && streamEnabled),
704+
stream: streamEnabled,
696705
volatile: isVolatile(func),
697-
requiresParameterAddresses:
698-
isRequiresParameterAddresses(func) && !isStreaming(func, isStreamingFunction),
706+
requiresParameterAddresses: parameterAddressesRequired && !streamEnabled,
699707
requiresStreamParameterAddresses:
700-
isRequiresParameterAddresses(func) && isStreaming(func, isStreamingFunction),
708+
streamParameterAddressesRequired || (parameterAddressesRequired && streamEnabled),
701709
excludeFromAutoComplete: isExcludedFromAutoComplete(func),
702710
linkedEntityLoadService: isLinkedEntityLoadService(func),
703711
capturesCallingObject: capturesCallingObject(func),
704712
supportSync: supportSync(func),
705713
action: isAction(func),
706714
};
707715

708-
if (isAddressRequired(func) || isRequiresParameterAddresses(func)) {
709-
let errorParam: string = isAddressRequired(func)
710-
? "@requiresAddress"
711-
: "@requiresParameterAddresses";
716+
if (
717+
addressRequired ||
718+
streamAddressRequired ||
719+
parameterAddressesRequired ||
720+
streamParameterAddressesRequired
721+
) {
722+
let errorParam: string = "";
723+
724+
if (streamAddressRequired) {
725+
errorParam = "@requiresStreamAddress";
726+
} else if (addressRequired) {
727+
errorParam = "@requiresAddress";
728+
} else if (streamParameterAddressesRequired) {
729+
errorParam = "@requiresStreamParameterAddresses";
730+
} else {
731+
errorParam = "@requiresParameterAddresses";
732+
}
712733

713734
if (!isStreamingFunction && !isCancelableFunction && !isInvocationFunction) {
714735
const functionPosition = getPosition(func, func.parameters.end);
@@ -717,13 +738,28 @@ function getOptions(
717738
}
718739
}
719740

741+
if (streamAddressRequired && !hasStreamingTag) {
742+
const functionPosition = getPosition(func, func.parameters.end);
743+
const errorString = "@requiresStreamAddress can only be used with @streaming.";
744+
extra.errors.push(logError(errorString, functionPosition));
745+
}
746+
747+
if (streamParameterAddressesRequired && !hasStreamingTag) {
748+
const functionPosition = getPosition(func, func.parameters.end);
749+
const errorString =
750+
"@requiresStreamParameterAddresses can only be used with @streaming.";
751+
extra.errors.push(logError(errorString, functionPosition));
752+
}
753+
720754
if (
721755
optionsItem.linkedEntityLoadService &&
722756
(optionsItem.excludeFromAutoComplete ||
723757
optionsItem.volatile ||
724758
optionsItem.stream ||
725759
optionsItem.requiresAddress ||
760+
optionsItem.requiresStreamAddress ||
726761
optionsItem.requiresParameterAddresses ||
762+
optionsItem.requiresStreamParameterAddresses ||
727763
optionsItem.capturesCallingObject)
728764
) {
729765
let errorParam: string = "";
@@ -737,8 +773,12 @@ function getOptions(
737773
errorParam = "@streaming";
738774
} else if (optionsItem.requiresAddress) {
739775
errorParam = "@requiresAddress";
776+
} else if (optionsItem.requiresStreamAddress) {
777+
errorParam = "@requiresStreamAddress";
740778
} else if (optionsItem.requiresParameterAddresses) {
741779
errorParam = "@requiresParameterAddresses";
780+
} else if (optionsItem.requiresStreamParameterAddresses) {
781+
errorParam = "@requiresStreamParameterAddresses";
742782
} else if (optionsItem.capturesCallingObject) {
743783
errorParam = "@capturesCallingObject";
744784
}
@@ -760,7 +800,9 @@ function getOptions(
760800
optionsItem.volatile ||
761801
optionsItem.stream ||
762802
optionsItem.requiresAddress ||
803+
optionsItem.requiresStreamAddress ||
763804
optionsItem.requiresParameterAddresses ||
805+
optionsItem.requiresStreamParameterAddresses ||
764806
optionsItem.capturesCallingObject ||
765807
optionsItem.linkedEntityLoadService ||
766808
optionsItem.supportSync)
@@ -776,8 +818,12 @@ function getOptions(
776818
errorParam = "@streaming";
777819
} else if (optionsItem.requiresAddress) {
778820
errorParam = "@requiresAddress";
821+
} else if (optionsItem.requiresStreamAddress) {
822+
errorParam = "@requiresStreamAddress";
779823
} else if (optionsItem.requiresParameterAddresses) {
780824
errorParam = "@requiresParameterAddresses";
825+
} else if (optionsItem.requiresStreamParameterAddresses) {
826+
errorParam = "@requiresStreamParameterAddresses";
781827
} else if (optionsItem.capturesCallingObject) {
782828
errorParam = "@capturesCallingObject";
783829
} else if (optionsItem.linkedEntityLoadService) {
@@ -1109,6 +1155,14 @@ function isAddressRequired(node: ts.Node): boolean {
11091155
return hasTag(node, REQUIRESADDRESS);
11101156
}
11111157

1158+
/**
1159+
* Returns true if requiresStreamAddress tag found in comments
1160+
* @param node jsDocs node
1161+
*/
1162+
function isStreamAddressRequired(node: ts.Node): boolean {
1163+
return hasTag(node, REQUIRESSTREAMADDRESS);
1164+
}
1165+
11121166
/**
11131167
* Returns true if RequiresParameterAddresses tag found in comments
11141168
* @param node jsDocs node
@@ -1117,6 +1171,14 @@ function isRequiresParameterAddresses(node: ts.Node): boolean {
11171171
return hasTag(node, REQUIRESPARAMETERADDRESSES);
11181172
}
11191173

1174+
/**
1175+
* Returns true if requiresStreamParameterAddresses tag found in comments
1176+
* @param node jsDocs node
1177+
*/
1178+
function isRequiresStreamParameterAddresses(node: ts.Node): boolean {
1179+
return hasTag(node, REQUIRESSTREAMPARAMETERADDRESSES);
1180+
}
1181+
11201182
/**
11211183
* Returns true if excludedFromAutoComplete tag found in comments
11221184
* @param node jsDocs node
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@requiresStreamAddress can only be used with @streaming. (10,53)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@requiresStreamAddress can only be used with @streaming. (10,98)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
/**
5+
* Test requires stream address without the @streaming tag.
6+
* @param {CustomFunctions.StreamingInvocation<string>} invocation stream invocation
7+
* @customfunction
8+
* @requiresStreamAddress
9+
*/
10+
function streamAddressMissingStreamingTag(invocation) {
11+
// Empty
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
/**
5+
* Test requires stream address without the @streaming tag.
6+
* @param invocation stream invocation
7+
* @customfunction
8+
* @requiresStreamAddress
9+
*/
10+
function streamAddressMissingStreamingTag(invocation: CustomFunctions.StreamingInvocation<string>) {
11+
// Empty
12+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@requiresStreamAddress can only be used with @streaming. (12,58)
2+
@requiresStreamParameterAddresses can only be used with @streaming. (12,58)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@requiresStreamAddress can only be used with @streaming. (12,94)
2+
@requiresStreamParameterAddresses can only be used with @streaming. (12,94)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
/**
5+
* Test requires stream addresses without streaming.
6+
* @param {string} x string
7+
* @param {CustomFunctions.Invocation} invocation invocation
8+
* @customfunction
9+
* @requiresStreamAddress
10+
* @requiresStreamParameterAddresses
11+
*/
12+
function streamAddressRequiresStreamingTest(x, invocation) {
13+
// Empty
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
/**
5+
* Test requires stream addresses without streaming.
6+
* @param x string
7+
* @param invocation invocation
8+
* @customfunction
9+
* @requiresStreamAddress
10+
* @requiresStreamParameterAddresses
11+
*/
12+
function streamAddressRequiresStreamingTest(x: string, invocation: CustomFunctions.Invocation) {
13+
// Empty
14+
}

0 commit comments

Comments
 (0)