From 6f8ade46878ce20d2ba38f385dd1b4b9ec669378 Mon Sep 17 00:00:00 2001 From: Xindi Date: Fri, 7 Jun 2024 15:57:54 +0800 Subject: [PATCH 1/4] move cell value type to subtype --- .../src/parseTree.ts | 7 +++ .../expected.json | 48 ++++++++++++------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/packages/custom-functions-metadata/src/parseTree.ts b/packages/custom-functions-metadata/src/parseTree.ts index eab4b2e7f..fb677f8f9 100644 --- a/packages/custom-functions-metadata/src/parseTree.ts +++ b/packages/custom-functions-metadata/src/parseTree.ts @@ -34,6 +34,7 @@ export interface IFunctionParameter { name: string; description?: string; type: string; + subtype?: string; dimensionality?: string; optional?: boolean; repeating?: boolean; @@ -697,6 +698,12 @@ function getParameters(parameterItem: IGetParametersArguments): IFunctionParamet type: ptype, }; + // for backward compatibility, we put cell value type in subtype instead of type. + if (Object.values(CELLVALUETYPE_MAPPINGS).includes(ptype)) { + pMetadataItem.type = "any"; + pMetadataItem.subtype = ptype + } + // Only return dimensionality = matrix. Default assumed scalar if (pMetadataItem.dimensionality === "scalar") { delete pMetadataItem.dimensionality; diff --git a/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json b/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json index 40c3a334f..7f7005ee9 100644 --- a/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json +++ b/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json @@ -8,7 +8,8 @@ "parameters": [ { "name": "x", - "type": "cellvalue" + "type": "any", + "subtype": "cellvalue" } ], "result": {} @@ -20,7 +21,8 @@ "parameters": [ { "name": "x", - "type": "booleancellvalue" + "type": "any", + "subtype": "booleancellvalue" } ], "result": {} @@ -32,7 +34,8 @@ "parameters": [ { "name": "x", - "type": "doublecellvalue" + "type": "any", + "subtype": "doublecellvalue" } ], "result": {} @@ -44,7 +47,8 @@ "parameters": [ { "name": "x", - "type": "entitycellvalue" + "type": "any", + "subtype": "entitycellvalue" } ], "result": {} @@ -56,7 +60,8 @@ "parameters": [ { "name": "x", - "type": "errorcellvalue" + "type": "any", + "subtype": "errorcellvalue" } ], "result": {} @@ -68,7 +73,8 @@ "parameters": [ { "name": "x", - "type": "formattednumbercellvalue" + "type": "any", + "subtype": "formattednumbercellvalue" } ], "result": {} @@ -80,7 +86,8 @@ "parameters": [ { "name": "x", - "type": "linkedentitycellvalue" + "type": "any", + "subtype": "linkedentitycellvalue" } ], "result": {} @@ -92,7 +99,8 @@ "parameters": [ { "name": "x", - "type": "localimagecellvalue" + "type": "any", + "subtype": "localimagecellvalue" } ], "result": {} @@ -104,7 +112,8 @@ "parameters": [ { "name": "x", - "type": "stringcellvalue" + "type": "any", + "subtype": "stringcellvalue" } ], "result": {} @@ -116,7 +125,8 @@ "parameters": [ { "name": "x", - "type": "webimagecellvalue" + "type": "any", + "subtype": "webimagecellvalue" } ], "result": {} @@ -129,7 +139,8 @@ { "name": "x", "repeating": true, - "type": "booleancellvalue" + "type": "any", + "subtype": "booleancellvalue" } ], "result": {} @@ -142,7 +153,8 @@ { "dimensionality": "matrix", "name": "x", - "type": "booleancellvalue" + "type": "any", + "subtype": "booleancellvalue" } ], "result": {} @@ -156,7 +168,8 @@ "dimensionality": "matrix", "name": "x", "repeating": true, - "type": "booleancellvalue" + "type": "any", + "subtype": "booleancellvalue" } ], "result": {} @@ -169,7 +182,8 @@ { "name": "x", "repeating": true, - "type": "booleancellvalue" + "type": "any", + "subtype": "booleancellvalue" } ], "result": {} @@ -182,7 +196,8 @@ { "dimensionality": "matrix", "name": "x", - "type": "booleancellvalue" + "type": "any", + "subtype": "booleancellvalue" } ], "result": {} @@ -196,7 +211,8 @@ "dimensionality": "matrix", "name": "x", "repeating": true, - "type": "booleancellvalue" + "type": "any", + "subtype": "booleancellvalue" } ], "result": {} From 48d14f94d5fa08193a53937eb8982e46a2353459 Mon Sep 17 00:00:00 2001 From: Xindi Date: Tue, 18 Jun 2024 16:22:19 +0800 Subject: [PATCH 2/4] rename subtype to cellvaluetype --- .../src/parseTree.ts | 6 ++-- .../expected.json | 32 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/custom-functions-metadata/src/parseTree.ts b/packages/custom-functions-metadata/src/parseTree.ts index fb677f8f9..7c1951cf0 100644 --- a/packages/custom-functions-metadata/src/parseTree.ts +++ b/packages/custom-functions-metadata/src/parseTree.ts @@ -34,7 +34,7 @@ export interface IFunctionParameter { name: string; description?: string; type: string; - subtype?: string; + cellValueType?: string; dimensionality?: string; optional?: boolean; repeating?: boolean; @@ -698,10 +698,10 @@ function getParameters(parameterItem: IGetParametersArguments): IFunctionParamet type: ptype, }; - // for backward compatibility, we put cell value type in subtype instead of type. + // for backward compatibility, we put cell value type in cellValueType instead of type. if (Object.values(CELLVALUETYPE_MAPPINGS).includes(ptype)) { pMetadataItem.type = "any"; - pMetadataItem.subtype = ptype + pMetadataItem.cellValueType = ptype } // Only return dimensionality = matrix. Default assumed scalar diff --git a/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json b/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json index 7f7005ee9..3313fe0f0 100644 --- a/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json +++ b/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json @@ -9,7 +9,7 @@ { "name": "x", "type": "any", - "subtype": "cellvalue" + "cellValueType": "cellvalue" } ], "result": {} @@ -22,7 +22,7 @@ { "name": "x", "type": "any", - "subtype": "booleancellvalue" + "cellValueType": "booleancellvalue" } ], "result": {} @@ -35,7 +35,7 @@ { "name": "x", "type": "any", - "subtype": "doublecellvalue" + "cellValueType": "doublecellvalue" } ], "result": {} @@ -48,7 +48,7 @@ { "name": "x", "type": "any", - "subtype": "entitycellvalue" + "cellValueType": "entitycellvalue" } ], "result": {} @@ -61,7 +61,7 @@ { "name": "x", "type": "any", - "subtype": "errorcellvalue" + "cellValueType": "errorcellvalue" } ], "result": {} @@ -74,7 +74,7 @@ { "name": "x", "type": "any", - "subtype": "formattednumbercellvalue" + "cellValueType": "formattednumbercellvalue" } ], "result": {} @@ -87,7 +87,7 @@ { "name": "x", "type": "any", - "subtype": "linkedentitycellvalue" + "cellValueType": "linkedentitycellvalue" } ], "result": {} @@ -100,7 +100,7 @@ { "name": "x", "type": "any", - "subtype": "localimagecellvalue" + "cellValueType": "localimagecellvalue" } ], "result": {} @@ -113,7 +113,7 @@ { "name": "x", "type": "any", - "subtype": "stringcellvalue" + "cellValueType": "stringcellvalue" } ], "result": {} @@ -126,7 +126,7 @@ { "name": "x", "type": "any", - "subtype": "webimagecellvalue" + "cellValueType": "webimagecellvalue" } ], "result": {} @@ -140,7 +140,7 @@ "name": "x", "repeating": true, "type": "any", - "subtype": "booleancellvalue" + "cellValueType": "booleancellvalue" } ], "result": {} @@ -154,7 +154,7 @@ "dimensionality": "matrix", "name": "x", "type": "any", - "subtype": "booleancellvalue" + "cellValueType": "booleancellvalue" } ], "result": {} @@ -169,7 +169,7 @@ "name": "x", "repeating": true, "type": "any", - "subtype": "booleancellvalue" + "cellValueType": "booleancellvalue" } ], "result": {} @@ -183,7 +183,7 @@ "name": "x", "repeating": true, "type": "any", - "subtype": "booleancellvalue" + "cellValueType": "booleancellvalue" } ], "result": {} @@ -197,7 +197,7 @@ "dimensionality": "matrix", "name": "x", "type": "any", - "subtype": "booleancellvalue" + "cellValueType": "booleancellvalue" } ], "result": {} @@ -212,7 +212,7 @@ "name": "x", "repeating": true, "type": "any", - "subtype": "booleancellvalue" + "cellValueType": "booleancellvalue" } ], "result": {} From 5e147cfb08bb2ebeb796d19c50801f3e68860d12 Mon Sep 17 00:00:00 2001 From: Xindi Ai Date: Wed, 28 Aug 2024 18:36:32 +0800 Subject: [PATCH 3/4] change to first parsing cellValueType. Change fallbacks accordingly --- .../custom-functions-metadata/src/parseTree.ts | 16 +++++++++++++++- .../expected.json | 18 +++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/packages/custom-functions-metadata/src/parseTree.ts b/packages/custom-functions-metadata/src/parseTree.ts index 7c1951cf0..e2f8dcdd7 100644 --- a/packages/custom-functions-metadata/src/parseTree.ts +++ b/packages/custom-functions-metadata/src/parseTree.ts @@ -160,6 +160,19 @@ const CELLVALUETYPE_MAPPINGS = { "Excel.ValueTypeNotAvailableCellValue": "unsupported", }; +const CELLVALUETYPE_TO_BASICTYPE_MAPPINGS = { + "cellvalue": "any", + "booleancellvalue": "boolean", + "doublecellvalue": "number", + "entitycellvalue": "any", + "errorcellvalue": "any", + "formattednumbercellvalue": "any", + "linkedentitycellvalue": "any", + "localimagecellvalue": "any", + "stringcellvalue": "string", + "webimagecellvalue": "any", +}; + type CustomFunctionsSchemaDimensionality = "invalid" | "scalar" | "matrix"; /** @@ -700,7 +713,8 @@ function getParameters(parameterItem: IGetParametersArguments): IFunctionParamet // for backward compatibility, we put cell value type in cellValueType instead of type. if (Object.values(CELLVALUETYPE_MAPPINGS).includes(ptype)) { - pMetadataItem.type = "any"; + // @ts-ignore + pMetadataItem.type = CELLVALUETYPE_TO_BASICTYPE_MAPPINGS[ptype]; pMetadataItem.cellValueType = ptype } diff --git a/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json b/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json index 3313fe0f0..994634b0a 100644 --- a/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json +++ b/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json @@ -21,7 +21,7 @@ "parameters": [ { "name": "x", - "type": "any", + "type": "boolean", "cellValueType": "booleancellvalue" } ], @@ -34,7 +34,7 @@ "parameters": [ { "name": "x", - "type": "any", + "type": "number", "cellValueType": "doublecellvalue" } ], @@ -112,7 +112,7 @@ "parameters": [ { "name": "x", - "type": "any", + "type": "string", "cellValueType": "stringcellvalue" } ], @@ -139,7 +139,7 @@ { "name": "x", "repeating": true, - "type": "any", + "type": "boolean", "cellValueType": "booleancellvalue" } ], @@ -153,7 +153,7 @@ { "dimensionality": "matrix", "name": "x", - "type": "any", + "type": "boolean", "cellValueType": "booleancellvalue" } ], @@ -168,7 +168,7 @@ "dimensionality": "matrix", "name": "x", "repeating": true, - "type": "any", + "type": "boolean", "cellValueType": "booleancellvalue" } ], @@ -182,7 +182,7 @@ { "name": "x", "repeating": true, - "type": "any", + "type": "boolean", "cellValueType": "booleancellvalue" } ], @@ -196,7 +196,7 @@ { "dimensionality": "matrix", "name": "x", - "type": "any", + "type": "boolean", "cellValueType": "booleancellvalue" } ], @@ -211,7 +211,7 @@ "dimensionality": "matrix", "name": "x", "repeating": true, - "type": "any", + "type": "boolean", "cellValueType": "booleancellvalue" } ], From a0cbae4b8630cca673f4a4468889d6fd25ac1e75 Mon Sep 17 00:00:00 2001 From: Xindi Date: Thu, 29 Aug 2024 14:38:17 +0800 Subject: [PATCH 4/4] update formattednumber fallback --- packages/custom-functions-metadata/src/parseTree.ts | 2 +- .../test/cases/input-parameter-types-cellvalue/expected.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/custom-functions-metadata/src/parseTree.ts b/packages/custom-functions-metadata/src/parseTree.ts index e2f8dcdd7..9f2df91e7 100644 --- a/packages/custom-functions-metadata/src/parseTree.ts +++ b/packages/custom-functions-metadata/src/parseTree.ts @@ -166,7 +166,7 @@ const CELLVALUETYPE_TO_BASICTYPE_MAPPINGS = { "doublecellvalue": "number", "entitycellvalue": "any", "errorcellvalue": "any", - "formattednumbercellvalue": "any", + "formattednumbercellvalue": "number", "linkedentitycellvalue": "any", "localimagecellvalue": "any", "stringcellvalue": "string", diff --git a/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json b/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json index 994634b0a..f496bfcf0 100644 --- a/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json +++ b/packages/custom-functions-metadata/test/cases/input-parameter-types-cellvalue/expected.json @@ -73,7 +73,7 @@ "parameters": [ { "name": "x", - "type": "any", + "type": "number", "cellValueType": "formattednumbercellvalue" } ],