custom-functions-metadata
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -40,3 +40,3 @@ #!/usr/bin/env node | ||
}; | ||
const TYPE_CUSTOM_FUNCTIONS = { | ||
const TYPE_CUSTOM_FUNCTIONS_STREAMING = { | ||
["customfunctions.streaminghandler<string>"]: "string", | ||
@@ -46,4 +46,12 @@ ["customfunctions.streaminghandler<number>"]: "number", | ||
["customfunctions.streaminghandler<any>"]: "any", | ||
["customfunctions.streaminginvocation<string>"]: "string", | ||
["customfunctions.streaminginvocation<number>"]: "number", | ||
["customfunctions.streaminginvocation<boolean>"]: "boolean", | ||
["customfunctions.streaminginvocation<any>"]: "any", | ||
}; | ||
const TYPE_CUSTOM_FUNCTION_CANCELABLE = "customfunctions.cancelablehandler"; | ||
const TYPE_CUSTOM_FUNCTION_CANCELABLE = { | ||
["customfunctions.cancelablehandler"]: 1, | ||
["customfunctions.cancelableinvocation"]: 2, | ||
}; | ||
const TYPE_CUSTOM_FUNCTION_INVOCATION = "customfunctions.invocation"; | ||
/** | ||
@@ -118,5 +126,6 @@ * Check the error log and return true if any errors found | ||
const [lastParameter] = functionDeclaration.parameters.slice(-1); | ||
const isStreamingFunction = isLastParameterStreaming(lastParameter, jsDocParamTypeInfo); | ||
const isCancelableFunction = isCancelable(lastParameter, jsDocParamTypeInfo); | ||
const paramsToParse = (isStreamingFunction || isCancelableFunction) | ||
const isStreamingFunction = hasStreamingInvocationParameter(lastParameter, jsDocParamTypeInfo); | ||
const isCancelableFunction = hasCancelableInvocationParameter(lastParameter, jsDocParamTypeInfo); | ||
const isInvocationFunction = hasInvocationParameter(lastParameter, jsDocParamTypeInfo); | ||
const paramsToParse = (isStreamingFunction || isCancelableFunction || isInvocationFunction) | ||
? functionDeclaration.parameters.slice(0, functionDeclaration.parameters.length - 1) | ||
@@ -128,3 +137,3 @@ : functionDeclaration.parameters.slice(0, functionDeclaration.parameters.length); | ||
const result = getResults(functionDeclaration, isStreamingFunction, lastParameter, jsDocParamTypeInfo); | ||
const options = getOptions(functionDeclaration, isStreamingFunction, isCancelableFunction); | ||
const options = getOptions(functionDeclaration, isStreamingFunction, isCancelableFunction, isInvocationFunction); | ||
const funcName = (functionDeclaration.name) ? functionDeclaration.name.text : ""; | ||
@@ -144,3 +153,3 @@ const id = normalizeCustomFunctionId(idNameArray[0] || funcName); | ||
}; | ||
if (!options.volatile && !options.stream && !options.cancelable) { | ||
if (!options.volatile && !options.stream && !options.cancelable && !options.requiresAddress) { | ||
delete functionMetadata.options; | ||
@@ -208,9 +217,14 @@ } | ||
*/ | ||
function getOptions(func, isStreamingFunction, isCancelableFunction) { | ||
function getOptions(func, isStreamingFunction, isCancelableFunction, isInvocationFunction) { | ||
const optionsItem = { | ||
cancelable: isCancelableTag(func, isCancelableFunction), | ||
requiresAddress: isRequiresAddress(func), | ||
requiresAddress: isAddressRequired(func), | ||
stream: isStreaming(func, isStreamingFunction), | ||
volatile: isVolatile(func), | ||
}; | ||
if (optionsItem.requiresAddress) { | ||
if (!isStreamingFunction && !isCancelableFunction && !isInvocationFunction) { | ||
logError("Since @requiresAddress is present, the last function parameter should be of type CustomFunctions.Invocation."); | ||
} | ||
} | ||
return optionsItem; | ||
@@ -239,3 +253,3 @@ } | ||
// @ts-ignore | ||
resultType = TYPE_CUSTOM_FUNCTIONS[ptype.toLocaleLowerCase()]; | ||
resultType = TYPE_CUSTOM_FUNCTIONS_STREAMING[ptype.toLocaleLowerCase()]; | ||
const paramResultItem = { | ||
@@ -403,3 +417,3 @@ dimensionality: resultDim, | ||
*/ | ||
function isRequiresAddress(node) { | ||
function isAddressRequired(node) { | ||
return hasTag(node, REQUIRESADDRESS); | ||
@@ -514,3 +528,3 @@ } | ||
*/ | ||
function isLastParameterStreaming(param, jsDocParamTypeInfo) { | ||
function hasStreamingInvocationParameter(param, jsDocParamTypeInfo) { | ||
const isTypeReferenceNode = param && param.type && ts.isTypeReferenceNode(param.type); | ||
@@ -524,3 +538,3 @@ if (param) { | ||
// @ts-ignore | ||
const typecheck = TYPE_CUSTOM_FUNCTIONS[ptype.toLocaleLowerCase()]; | ||
const typecheck = TYPE_CUSTOM_FUNCTIONS_STREAMING[ptype.toLocaleLowerCase()]; | ||
if (typecheck) { | ||
@@ -536,4 +550,6 @@ return true; | ||
const typeRef = param.type; | ||
return (typeRef.typeName.getText() === "CustomFunctions.StreamingHandler" || | ||
typeRef.typeName.getText() === "IStreamingCustomFunctionHandler" /* older version*/); | ||
const typeName = typeRef.typeName.getText(); | ||
return (typeName === "CustomFunctions.StreamingInvocation" || | ||
typeName === "CustomFunctions.StreamingHandler" || | ||
typeName === "IStreamingCustomFunctionHandler" /* older version*/); | ||
} | ||
@@ -545,3 +561,3 @@ /** | ||
*/ | ||
function isCancelable(param, jsDocParamTypeInfo) { | ||
function hasCancelableInvocationParameter(param, jsDocParamTypeInfo) { | ||
const isTypeReferenceNode = param && param.type && ts.isTypeReferenceNode(param.type); | ||
@@ -554,3 +570,5 @@ if (param) { | ||
if (ptype) { | ||
if (ptype.toLocaleLowerCase() === TYPE_CUSTOM_FUNCTION_CANCELABLE) { | ||
// @ts-ignore | ||
const cancelableTypeCheck = TYPE_CUSTOM_FUNCTION_CANCELABLE[ptype.toLocaleLowerCase()]; | ||
if (cancelableTypeCheck) { | ||
return true; | ||
@@ -565,5 +583,32 @@ } | ||
const typeRef = param.type; | ||
return (typeRef.typeName.getText() === "CustomFunctions.CancelableHandler"); | ||
const typeName = typeRef.typeName.getText(); | ||
return (typeName === "CustomFunctions.CancelableHandler" || | ||
typeName === "CustomFunctions.CancelableInvocation"); | ||
} | ||
/** | ||
* Determines if the last parameter is of type invocation | ||
* @param param ParameterDeclaration | ||
* @param jsDocParamTypeInfo | ||
*/ | ||
function hasInvocationParameter(param, jsDocParamTypeInfo) { | ||
const isTypeReferenceNode = param && param.type && ts.isTypeReferenceNode(param.type); | ||
if (param) { | ||
const name = param.name.text; | ||
if (name) { | ||
const ptype = jsDocParamTypeInfo[name]; | ||
// Check to see if the invocation parameter is defined in the comment section | ||
if (ptype) { | ||
if (ptype.toLocaleLowerCase() === TYPE_CUSTOM_FUNCTION_INVOCATION) { | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
if (!isTypeReferenceNode) { | ||
return false; | ||
} | ||
const typeRef = param.type; | ||
return (typeRef.typeName.getText() === "CustomFunctions.Invocation"); | ||
} | ||
/** | ||
* Gets the parameter type of the node | ||
@@ -570,0 +615,0 @@ * @param t TypeNode |
{ | ||
"name": "custom-functions-metadata", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Generate metadata for Excel Custom Functions.", | ||
@@ -54,3 +54,3 @@ "main": "./lib/custom-functions-metadata.js", | ||
}, | ||
"gitHead": "b364426ef196e950f7fe8f11328c6e4e2aeec32d" | ||
"gitHead": "670600e51e41855c8657efbffb238a8eaa5481fc" | ||
} |
@@ -74,3 +74,3 @@ #!/usr/bin/env node | ||
const TYPE_CUSTOM_FUNCTIONS = { | ||
const TYPE_CUSTOM_FUNCTIONS_STREAMING = { | ||
["customfunctions.streaminghandler<string>"]: "string", | ||
@@ -80,5 +80,13 @@ ["customfunctions.streaminghandler<number>"]: "number", | ||
["customfunctions.streaminghandler<any>"]: "any", | ||
["customfunctions.streaminginvocation<string>"]: "string", | ||
["customfunctions.streaminginvocation<number>"]: "number", | ||
["customfunctions.streaminginvocation<boolean>"]: "boolean", | ||
["customfunctions.streaminginvocation<any>"]: "any", | ||
}; | ||
const TYPE_CUSTOM_FUNCTION_CANCELABLE = "customfunctions.cancelablehandler"; | ||
const TYPE_CUSTOM_FUNCTION_CANCELABLE = { | ||
["customfunctions.cancelablehandler"]: 1, | ||
["customfunctions.cancelableinvocation"]: 2, | ||
}; | ||
const TYPE_CUSTOM_FUNCTION_INVOCATION = "customfunctions.invocation"; | ||
@@ -161,6 +169,7 @@ type CustomFunctionsSchemaDimensionality = "invalid" | "scalar" | "matrix"; | ||
const [lastParameter] = functionDeclaration.parameters.slice(-1); | ||
const isStreamingFunction = isLastParameterStreaming(lastParameter, jsDocParamTypeInfo); | ||
const isCancelableFunction = isCancelable(lastParameter, jsDocParamTypeInfo); | ||
const isStreamingFunction = hasStreamingInvocationParameter(lastParameter, jsDocParamTypeInfo); | ||
const isCancelableFunction = hasCancelableInvocationParameter(lastParameter, jsDocParamTypeInfo); | ||
const isInvocationFunction = hasInvocationParameter(lastParameter, jsDocParamTypeInfo); | ||
const paramsToParse = (isStreamingFunction || isCancelableFunction) | ||
const paramsToParse = (isStreamingFunction || isCancelableFunction || isInvocationFunction) | ||
? functionDeclaration.parameters.slice(0, functionDeclaration.parameters.length - 1) | ||
@@ -176,3 +185,3 @@ : functionDeclaration.parameters.slice(0, functionDeclaration.parameters.length); | ||
const options = getOptions(functionDeclaration, isStreamingFunction, isCancelableFunction); | ||
const options = getOptions(functionDeclaration, isStreamingFunction, isCancelableFunction, isInvocationFunction); | ||
@@ -195,3 +204,3 @@ const funcName: string = (functionDeclaration.name) ? functionDeclaration.name.text : ""; | ||
if (!options.volatile && !options.stream && !options.cancelable) { | ||
if (!options.volatile && !options.stream && !options.cancelable && !options.requiresAddress) { | ||
delete functionMetadata.options; | ||
@@ -263,9 +272,16 @@ } | ||
*/ | ||
function getOptions(func: ts.FunctionDeclaration, isStreamingFunction: boolean, isCancelableFunction: boolean): IFunctionOptions { | ||
function getOptions(func: ts.FunctionDeclaration, isStreamingFunction: boolean, isCancelableFunction: boolean, isInvocationFunction: boolean): IFunctionOptions { | ||
const optionsItem: IFunctionOptions = { | ||
cancelable: isCancelableTag(func, isCancelableFunction), | ||
requiresAddress: isRequiresAddress(func), | ||
requiresAddress: isAddressRequired(func), | ||
stream: isStreaming(func, isStreamingFunction), | ||
volatile: isVolatile(func), | ||
}; | ||
if (optionsItem.requiresAddress) { | ||
if (!isStreamingFunction && !isCancelableFunction && !isInvocationFunction) { | ||
logError("Since @requiresAddress is present, the last function parameter should be of type CustomFunctions.Invocation."); | ||
} | ||
} | ||
return optionsItem; | ||
@@ -296,3 +312,3 @@ } | ||
// @ts-ignore | ||
resultType = TYPE_CUSTOM_FUNCTIONS[ptype.toLocaleLowerCase()]; | ||
resultType = TYPE_CUSTOM_FUNCTIONS_STREAMING[ptype.toLocaleLowerCase()]; | ||
const paramResultItem: IFunctionResult = { | ||
@@ -476,3 +492,3 @@ dimensionality: resultDim, | ||
*/ | ||
function isRequiresAddress(node: ts.Node): boolean { | ||
function isAddressRequired(node: ts.Node): boolean { | ||
return hasTag(node, REQUIRESADDRESS); | ||
@@ -608,3 +624,3 @@ } | ||
*/ | ||
function isLastParameterStreaming(param: ts.ParameterDeclaration, jsDocParamTypeInfo: { [key: string]: string }): boolean { | ||
function hasStreamingInvocationParameter(param: ts.ParameterDeclaration, jsDocParamTypeInfo: { [key: string]: string }): boolean { | ||
const isTypeReferenceNode = param && param.type && ts.isTypeReferenceNode(param.type); | ||
@@ -619,3 +635,3 @@ | ||
// @ts-ignore | ||
const typecheck = TYPE_CUSTOM_FUNCTIONS[ptype.toLocaleLowerCase()]; | ||
const typecheck = TYPE_CUSTOM_FUNCTIONS_STREAMING[ptype.toLocaleLowerCase()]; | ||
if (typecheck) { | ||
@@ -633,5 +649,7 @@ return true; | ||
const typeRef = param.type as ts.TypeReferenceNode; | ||
const typeName = typeRef.typeName.getText(); | ||
return ( | ||
typeRef.typeName.getText() === "CustomFunctions.StreamingHandler" || | ||
typeRef.typeName.getText() === "IStreamingCustomFunctionHandler" /* older version*/ | ||
typeName === "CustomFunctions.StreamingInvocation" || | ||
typeName === "CustomFunctions.StreamingHandler" || | ||
typeName === "IStreamingCustomFunctionHandler" /* older version*/ | ||
); | ||
@@ -645,3 +663,3 @@ } | ||
*/ | ||
function isCancelable(param: ts.ParameterDeclaration, jsDocParamTypeInfo: { [key: string]: string }): boolean { | ||
function hasCancelableInvocationParameter(param: ts.ParameterDeclaration, jsDocParamTypeInfo: { [key: string]: string }): boolean { | ||
const isTypeReferenceNode = param && param.type && ts.isTypeReferenceNode(param.type); | ||
@@ -655,3 +673,5 @@ | ||
if (ptype) { | ||
if (ptype.toLocaleLowerCase() === TYPE_CUSTOM_FUNCTION_CANCELABLE ) { | ||
// @ts-ignore | ||
const cancelableTypeCheck = TYPE_CUSTOM_FUNCTION_CANCELABLE[ptype.toLocaleLowerCase()]; | ||
if (cancelableTypeCheck ) { | ||
return true; | ||
@@ -668,4 +688,6 @@ } | ||
const typeRef = param.type as ts.TypeReferenceNode; | ||
const typeName = typeRef.typeName.getText(); | ||
return ( | ||
typeRef.typeName.getText() === "CustomFunctions.CancelableHandler" | ||
typeName === "CustomFunctions.CancelableHandler" || | ||
typeName === "CustomFunctions.CancelableInvocation" | ||
); | ||
@@ -675,2 +697,33 @@ } | ||
/** | ||
* Determines if the last parameter is of type invocation | ||
* @param param ParameterDeclaration | ||
* @param jsDocParamTypeInfo | ||
*/ | ||
function hasInvocationParameter(param: ts.ParameterDeclaration, jsDocParamTypeInfo: { [key: string]: string }): boolean { | ||
const isTypeReferenceNode = param && param.type && ts.isTypeReferenceNode(param.type); | ||
if (param) { | ||
const name = (param.name as ts.Identifier).text; | ||
if (name) { | ||
const ptype = jsDocParamTypeInfo[name]; | ||
// Check to see if the invocation parameter is defined in the comment section | ||
if (ptype) { | ||
if (ptype.toLocaleLowerCase() === TYPE_CUSTOM_FUNCTION_INVOCATION ) { | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
if (!isTypeReferenceNode) { | ||
return false; | ||
} | ||
const typeRef = param.type as ts.TypeReferenceNode; | ||
return ( | ||
typeRef.typeName.getText() === "CustomFunctions.Invocation" | ||
); | ||
} | ||
/** | ||
* Gets the parameter type of the node | ||
@@ -677,0 +730,0 @@ * @param t TypeNode |
@@ -28,2 +28,10 @@ /** | ||
*/ | ||
function badName(){} | ||
function badName(){} | ||
/** | ||
* requiresAddress tag requires parmeter to be of type Invocation | ||
* @param {string} x | ||
* @CustomFunction | ||
* @requiresAddress | ||
*/ | ||
function missingInvocationType(x){} |
@@ -70,2 +70,26 @@ /** | ||
*/ | ||
function customIdNameTest(x){} | ||
function customIdNameTest(x){} | ||
/** | ||
* Test the new invocation type | ||
* @param {CustomFunctions.Invocation} inv | ||
* @CustomFunction | ||
* @requiresAddress | ||
*/ | ||
function customInvocationTest(inv){} | ||
/** | ||
* Test streaming handler function | ||
* @param {string} x | ||
* @param {CustomFunctions.StreamingInvocation<string>} handler | ||
* @CustomFunction | ||
*/ | ||
function testStreamingInvocation(x, handler){} | ||
/** | ||
* Test the cancelable handler | ||
* @param {string} x | ||
* @param {CustomFunctions.CancelableInvocation} chandler | ||
* @CustomFunction | ||
*/ | ||
function testCancelInvocation(x, chandler){} |
@@ -60,2 +60,7 @@ import * as assert from "assert"; | ||
assert.strictEqual(j.functions[15].options.requiresAddress, true, "requiresAddress tag not created properly"); | ||
assert.strictEqual(j.functions[16].options.requiresAddress, true, "CustomFunctions.Invocation requiresAddress tag not created properly"); | ||
assert.strictEqual(j.functions[17].options.cancelable, true, "CustomFunctions.CancelableInvocation type not created properly"); | ||
assert.strictEqual(j.functions[17].options.requiresAddress, true, "CustomFunctions.CancelableInvocation requiresAdress type not created properly"); | ||
assert.strictEqual(j.functions[18].options.stream, true, "CustomFunctions.StreamingInvocation - options stream not created properly"); | ||
assert.strictEqual(j.functions[18].options.requiresAddress, true, "CustomFunctions.StreamingInvocation requiresAddress - options stream not created properly"); | ||
}); | ||
@@ -102,2 +107,5 @@ }); | ||
assert.strictEqual(j.functions[8].name, "newName", "@CustomFunction id name not created properly"); | ||
assert.strictEqual(j.functions[9].options.requiresAddress, true, "CustomFunctions.Invocation set requiresAddress not created properly"); | ||
assert.strictEqual(j.functions[10].options.stream, true, "CustomFunctions.StreamingInvocation type any not created properly"); | ||
assert.strictEqual(j.functions[11].options.cancelable, true, "CustomFunctions.CancelableInvocation type any not created properly"); | ||
}); | ||
@@ -116,5 +124,7 @@ }); | ||
const errorstring = "Unsupported type in code comment:badtype"; | ||
const errorRequiresAddress = "@requiresAddress"; | ||
assert.equal(errtest[0].includes(errorstring), true, "Unsupported type found"); | ||
assert.equal(errtest[2].includes(errorIdBad), true, "Invalid id found"); | ||
assert.equal(errtest[4].includes(errorNameBad), true, "Invalid name found"); | ||
assert.equal(errtest[5].includes(errorRequiresAddress), true, "Missing Invocation type"); | ||
assert.strictEqual(fs.existsSync(output), false, "json file created"); | ||
@@ -121,0 +131,0 @@ }); |
@@ -149,3 +149,29 @@ /** | ||
/** | ||
* Test the CustomFunctions.Invocation type | ||
* @CustomFunction | ||
* @param invocation Invocation parameter | ||
* @requiresAddress | ||
*/ | ||
function customFunctionInvocationTest(x: string, invocation: CustomFunctions.Invocation){} | ||
/** | ||
* Test the new cancelable type | ||
* @param x string | ||
* @param cancel CustomFunctions.CancelableInvocation type | ||
* @CustomFunction | ||
* @requiresAddress | ||
*/ | ||
function customFunctionCancelableInvocationTest(x: string, cancel: CustomFunctions.CancelableInvocation){} | ||
/** | ||
* Test the new streaming invocation type | ||
* @param x string | ||
* @param stream StreamingInvocation type | ||
* @CustomFunction | ||
* @requiresAddress | ||
*/ | ||
function customFunctionStreamingInvocationTest(x: string, stream: CustomFunctions.StreamingInvocation<string>){} | ||
CustomFunctionMappings.ADD=add; | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118751
2247