From 8acffcb4a94297a8e1a39df745fe2000bce7ff8f Mon Sep 17 00:00:00 2001 From: denis Date: Thu, 11 Jan 2024 18:02:44 +0300 Subject: [PATCH] 123 --- .idea/.gitignore | 5 +++++ .idea/modules.xml | 8 ++++++++ .idea/refdb.iml | 12 ++++++++++++ .idea/vcs.xml | 6 ++++++ docs/readme.md | 10 ++++++++++ src/DataBase.ts | 17 ++++++++++++----- 6 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/modules.xml create mode 100644 .idea/refdb.iml create mode 100644 .idea/vcs.xml create mode 100644 docs/readme.md diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ea7ed09 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..759eec2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/refdb.iml b/.idea/refdb.iml new file mode 100644 index 0000000..0b872d8 --- /dev/null +++ b/.idea/refdb.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..c8397c9 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 0000000..680d672 --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,10 @@ + + +## Node +Узел, имеет атрибуты id, value, valueType + +## Edge +Связь двух узлов, имеет атрибуты id, in_id, out_id + +## Expression +Выражение \ No newline at end of file diff --git a/src/DataBase.ts b/src/DataBase.ts index 494f85b..f34819e 100644 --- a/src/DataBase.ts +++ b/src/DataBase.ts @@ -29,7 +29,8 @@ export class DataBase { this.setMap.get(nodeParams.set)?.add(uuid); switch (nodeParams.valueType) { case "expression": { - this.expressionMap.set(nodeParams.id, uuid); + const {id} = nodeParams as ExpressionNode; + this.expressionMap.set(id, uuid); break; } } @@ -62,7 +63,7 @@ export class DataBase { return Array.from(uuids).map(u => this.get(u)); } - getExpression(id: string): ExpressionResult { + getExpression(id: ExpressionNode["id"]): ExpressionResult { const uuid = this.expressionMap.get(id); if (uuid == null) { return null; @@ -75,7 +76,7 @@ export class DataBase { if (cache != null) { return cache; } - const result = this.calculateExpression(node); + const result = this.calculateExpression(node as ExpressionNode); this.expressionCacheMap.set(node.uuid, result); return result; } @@ -88,7 +89,10 @@ export class DataBase { return set.length; } if (node.value.hasOwnProperty("expression")) { - const exprNode: ExpressionNode = this.nodeMap.get((node.value as CountWithExpression).expression); + const exprNode: ExpressionNode | undefined = this.nodeMap.get((node.value as CountWithExpression).expression) as ExpressionNode; + if (exprNode == null) { + return null; + } const expressionValue = this.getExpression(exprNode.id); if (expressionValue instanceof Array) { return expressionValue.length; @@ -112,7 +116,10 @@ export class DataBase { }) as ExpressionResult; } if (node.value.hasOwnProperty("expression")) { - const exprNode: ExpressionNode = this.nodeMap.get((node.value as FilterWithExpression).expression); + const exprNode: ExpressionNode | undefined = this.nodeMap.get((node.value as FilterWithExpression).expression) as ExpressionNode; + if (!exprNode) { + return null; + } const expressionValue = this.getExpression(exprNode.id); if (expressionValue instanceof Array) { return expressionValue.length;