浏览代码

construct objects via options-interface; fix build

Martin Kunz 1 年之前
父节点
当前提交
beac387c0e

+ 0 - 3
src/ua/UAAccessRestriction.ts

@@ -1,4 +1 @@
-import { assert } from "@/util/assert";
-
-
 export class UAAccessRestriction  {}

+ 36 - 18
src/ua/UABaseNode.ts

@@ -10,25 +10,31 @@ import { UAWriteMask } from "./UAWriteMask"; //TODO
 import { UAAccessRestriction } from "./UAAccessRestriction"; //TODO
 
 export class UABaseNode implements IToXML{
-    constructor(public nodeId: NodeId,
-                public browseName: string,
-                public displayName: string,
-				public displayName: string, //LocText
-                public description: string, //LocText
-                public symbolicName: string, //SymbolicName
-                public releaseStatus: string, //ReleaseStatus
-                public hasNoPermissions: boolean, 
-                public writeMask: UAWriteMask, 
-                public userWriteMask: UAUserWriteMask,
-                public category: string,
-                public documentation: string,
-                public accessRestriction: UAAccessRestriction, 
-                public rolePermissions: UARolePermission[], 
-                public extensions: UAExtension[],
-                public references: UAReference[]) {
+
+    public nodeId: NodeId;
+    public browseName: string;
+    public displayName?: string; //LocText
+    public description?: string; //LocText
+    public symbolicName?: string; //SymbolicName
+    public releaseStatus?: string; //ReleaseStatus
+    public hasNoPermissions?: boolean; 
+    public writeMask?: UAWriteMask; 
+    public userWriteMask?: UAUserWriteMask;
+    public category?: string;
+    public documentation?: string;
+    public accessRestriction?: UAAccessRestriction; 
+    public rolePermissions: UARolePermission[]=[]; 
+    public extensions: UAExtension[]=[];
+    public references: UAReference[]=[];
+    
+    constructor(options: UABaseNodeOptions) {
+        this.nodeId=options.nodeId;
+        this.browseName=options.browseName;
+        this.displayName=options.displayName;
+        this.references=options.references||[];
     }
 
-    public static nullBaseNode=new UABaseNode(NodeId.nullNodeId,"","",[]);
+    public static nullBaseNode=new UABaseNode({browseName: "", nodeId: NodeId.nullNodeId});
 
     reIndex(nst: NamespaceTable, onst: NamespaceTable) {
         const nsName=onst.getUri(this.nodeId.namespace);
@@ -91,11 +97,23 @@ export class UABaseNode implements IToXML{
         for(const xmlref of xmlReferences.Reference) {
             references.push(UAReference.fromXML(xmlref, nodeId));
         }
-        const ua=new UABaseNode(nodeId, xmlObject['@_BrowseName'], xmlObject['DisplayName']['#text'], references);
+        const ua=new UABaseNode({nodeId: nodeId, 
+                                browseName: xmlObject['@_BrowseName'], 
+                                displayName: xmlObject['DisplayName']['#text'], 
+                                references: references});
         return ua;
     }
 
     toXML(): XMLElem {
         throw new Error("UABaseNode has no xml rep; implement in subtype.");
     }
+}
+
+
+export interface UABaseNodeOptions {
+    browseName: string;
+    nodeId: NodeId;
+    references?: UAReference[];
+    displayName?: string;
+    description?: string
 }

+ 0 - 3
src/ua/UAExtension.ts

@@ -1,6 +1,3 @@
-import { assert } from "@/util/assert";
-
-
 export class UAExtension  {
 
 }

+ 12 - 10
src/ua/UAObject.ts

@@ -1,19 +1,17 @@
 import { XMLElem } from "@/util/XmlElem";
-import type { NodeId } from "./NodeId";
-import { UABaseNode } from "./UABaseNode";
-import { UAReference } from "./UAReference";
+import { UABaseNode, type UABaseNodeOptions } from "./UABaseNode";
 
 export class UAObject extends UABaseNode {
-    constructor(public nodeId: NodeId,
-                public browseName: string,
-                public displayName: string,
-                public references: UAReference[]) {
-                    super(nodeId, browseName, displayName, references);
+    constructor(options: UAObjectNodeOptions) {
+                    super(options);
     }
 
     static  fromXML(uaObject: any): UAObject{
         const bn=super.fromXML(uaObject)
-        return new UAObject(bn.nodeId, bn.browseName, bn.displayName, bn.references);
+        return new UAObject({nodeId: bn.nodeId, 
+                            browseName: bn.browseName, 
+                            displayName: bn.displayName, 
+                            references: bn.references});
     }
 
 
@@ -28,4 +26,8 @@ export class UAObject extends UABaseNode {
         }
         return elem;
     }
-}
+}
+
+export interface UAObjectNodeOptions extends UABaseNodeOptions{
+
+}

+ 0 - 1
src/ua/UARolePermission.ts

@@ -1,4 +1,3 @@
-import { assert } from "@/util/assert";
 
 
 export class UARolePermission  {

+ 0 - 1
src/ua/UAUserWriteMask.ts

@@ -1,4 +1,3 @@
-import { assert } from "@/util/assert";
 
 
 export class UAUserWriteMask  {}

+ 12 - 10
src/ua/UAVariable.ts

@@ -1,19 +1,17 @@
 import { XMLElem } from "@/util/XmlElem";
-import type { NodeId } from "./NodeId";
-import { UABaseNode } from "./UABaseNode";
-import { UAReference } from "./UAReference";
+import { UABaseNode, type UABaseNodeOptions } from "./UABaseNode";
 
 export class UAVariable extends UABaseNode {
-    constructor(public nodeId: NodeId,
-                public browseName: string,
-                public displayName: string,
-                public references: UAReference[]) {
-                    super(nodeId, browseName, displayName, references);
+    constructor(options: UAVariableNodeOptions) {
+                    super(options);
     }
 
     static  fromXML(uaObject: any): UAVariable{
         const bn=super.fromXML(uaObject)
-        return new UAVariable(bn.nodeId, bn.browseName, bn.displayName, bn.references);
+        return new UAVariable({nodeId: bn.nodeId, 
+                                browseName: bn.browseName, 
+                                displayName: bn.displayName, 
+                                references: bn.references});
     }
 
     toXML(): XMLElem {
@@ -27,4 +25,8 @@ export class UAVariable extends UABaseNode {
         }
         return elem;
     }
-}
+}
+
+export interface UAVariableNodeOptions extends UABaseNodeOptions{
+
+}

+ 0 - 3
src/ua/UAWriteMask.ts

@@ -1,4 +1 @@
-import { assert } from "@/util/assert";
-
-
 export class UAWriteMask  {}

+ 3 - 1
src/util/XmlElem.ts

@@ -14,7 +14,9 @@ export class XMLElem {
         return elem;
     }
 
-    public attr(name:string, value: string|boolean): XMLElem {
+    public attr(name:string, value: string|boolean|undefined|null): XMLElem {
+        if(value===undefined||value===null)
+            return this; //skip undefined/null values
         this.attributes.push(new XmlAttr(name, value?.toString()));
         return this;
     }