fix: context value suppport both array and string (#13)
This commit is contained in:
Родитель
55c2d16217
Коммит
d87e649369
|
@ -99,8 +99,7 @@
|
|||
"compile": "tsc -p ./",
|
||||
"tslint": "tslint -t verbose src/**/*.ts",
|
||||
"test": "node ./out/test/runTest.js",
|
||||
"webpack": "webpack --mode development",
|
||||
"webpack-dev": "webpack --mode development --watch"
|
||||
"webpack": "webpack --mode development"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/fs-extra": "^7.0.0",
|
||||
|
|
|
@ -56,6 +56,5 @@ export class DigitalTwinConstants {
|
|||
public static readonly REQUIRED_PROPERTY_LABEL = "(required)";
|
||||
public static readonly IOT_MODEL_LABEL = "IoTModel";
|
||||
public static readonly CONTEXT_TEMPLATE = "http://azureiot.com/v1/contexts/IoTModel.json";
|
||||
public static readonly CONTEXT_REGEX = new RegExp("^http://azureiot.com/v[0-9]+/contexts/IoTModel.json$");
|
||||
public static readonly SUPPORT_SEMANTIC_TYPES = new Set<string>(["Telemetry", "Property"]);
|
||||
}
|
||||
|
|
|
@ -88,9 +88,15 @@ export class IntelliSenseUtility {
|
|||
* @param node json node
|
||||
*/
|
||||
public static isDigitalTwinContext(node: parser.Node): boolean {
|
||||
// assume @context is string node
|
||||
// @context accept both array and string
|
||||
if (node.type === JsonNodeType.String) {
|
||||
return DigitalTwinConstants.CONTEXT_REGEX.test(node.value as string);
|
||||
return (node.value as string) === DigitalTwinConstants.CONTEXT_TEMPLATE;
|
||||
} else if (node.type === JsonNodeType.Array && node.children) {
|
||||
for (const child of node.children) {
|
||||
if (child.type === JsonNodeType.String && (child.value as string) === DigitalTwinConstants.CONTEXT_TEMPLATE) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче