node-opcua-modeler 2.64.1 → 2.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/addExtensionObjectDataType.d.ts +21 -21
  2. package/dist/addExtensionObjectDataType.js +130 -130
  3. package/dist/build_model_inner.d.ts +17 -17
  4. package/dist/build_model_inner.js +40 -40
  5. package/dist/build_model_inner.js.map +1 -1
  6. package/dist/displayNodeElement.d.ts +5 -5
  7. package/dist/displayNodeElement.js +192 -191
  8. package/dist/displayNodeElement.js.map +1 -1
  9. package/dist/dump_state_machine_to_graphviz.d.ts +6 -6
  10. package/dist/dump_state_machine_to_graphviz.js +119 -119
  11. package/dist/generate_markdown_doc.d.ts +41 -6
  12. package/dist/generate_markdown_doc.js +314 -266
  13. package/dist/generate_markdown_doc.js.map +1 -1
  14. package/dist/index.d.ts +24 -24
  15. package/dist/index.js +52 -48
  16. package/dist/index.js.map +1 -1
  17. package/dist/promoteToMandatory.d.ts +8 -8
  18. package/dist/promoteToMandatory.js +97 -97
  19. package/dist/setNamespaceMetaData.d.ts +1 -1
  20. package/dist/setNamespaceMetaData.js +5 -5
  21. package/dist/symbol.d.ts +1 -1
  22. package/dist/symbol.js +2 -2
  23. package/dist/tableHelper.d.ts +9 -9
  24. package/dist/tableHelper.js +60 -60
  25. package/dist/to_cvs.d.ts +2 -2
  26. package/dist/to_cvs.js +11 -11
  27. package/dist/to_graphivz.d.ts +14 -14
  28. package/dist/to_graphivz.js +294 -294
  29. package/dist/types.d.ts +1 -1
  30. package/dist/types.js +2 -2
  31. package/distNodeJS/build_documentation_to_file.d.ts +3 -2
  32. package/distNodeJS/build_documentation_to_file.js +26 -26
  33. package/distNodeJS/build_documentation_to_file.js.map +1 -1
  34. package/distNodeJS/build_model.d.ts +7 -7
  35. package/distNodeJS/build_model.js +21 -21
  36. package/distNodeJS/index.d.ts +5 -5
  37. package/distNodeJS/index.js +23 -19
  38. package/distNodeJS/index.js.map +1 -1
  39. package/distNodeJS/symbol_cvs.d.ts +3 -3
  40. package/distNodeJS/symbol_cvs.js +63 -63
  41. package/package.json +20 -20
  42. package/source/build_model_inner.ts +3 -5
  43. package/source/displayNodeElement.ts +3 -3
  44. package/source/generate_markdown_doc.ts +88 -33
  45. package/source/index.ts +2 -1
  46. package/source_nodejs/build_documentation_to_file.ts +3 -3
  47. package/MyModel.NodeSet2.xml +0 -125
  48. package/dist/buildModel.d.ts +0 -16
  49. package/dist/buildModel.js +0 -91
  50. package/dist/buildModel.js.map +0 -1
  51. package/dist/display.d.ts +0 -2
  52. package/dist/display.js +0 -96
  53. package/dist/display.js.map +0 -1
  54. package/source/dump_state_machine_to_graphviz.ts +0 -164
  55. package/source/to_graphivz.ts +0 -351
@@ -1,8 +1,7 @@
1
1
  /* eslint-disable max-statements */
2
2
  import {
3
3
  BaseNode,
4
- dumpReferenceDescription,
5
- Namespace,
4
+ INamespace,
6
5
  UADataType,
7
6
  UAObject,
8
7
  UAObjectType,
@@ -12,15 +11,13 @@ import {
12
11
  } from "node-opcua-address-space";
13
12
  import { coerceUInt32 } from "node-opcua-basic-types";
14
13
  import { NodeClass } from "node-opcua-data-model";
15
- import { NodeId } from "node-opcua-nodeid";
16
14
  import { StructureField } from "node-opcua-types";
17
15
  import { DataType } from "node-opcua-variant";
18
16
 
19
17
  import { displayNodeElement } from "./displayNodeElement";
20
18
  import { TableHelper } from "./tableHelper";
21
- import { dumpClassHierachry, graphVizToPlantUml, opcuaToDot } from "./to_graphivz";
22
19
 
23
- interface NamespacePriv2 {
20
+ interface NamespacePriv2 extends INamespace {
24
21
  nodeIterator(): IterableIterator<BaseNode>;
25
22
  _objectTypeIterator(): IterableIterator<UAObjectType>;
26
23
  _objectTypeCount(): number;
@@ -33,14 +30,16 @@ interface NamespacePriv2 {
33
30
  _aliasCount(): number;
34
31
  }
35
32
  export interface IWriter {
36
- writeLine(...args: any[]): void;
33
+ // eslint-disable-next-line no-unused-vars
34
+ writeLine(_str: string): void;
37
35
  }
38
- class Writer implements IWriter {
36
+
37
+ export class Writer implements IWriter {
39
38
  private readonly stream: string[] = [];
40
39
  constructor() {
41
40
  /* empty */
42
41
  }
43
- public writeLine(str: string) {
42
+ public writeLine(str: string): void {
44
43
  this.stream.push(str);
45
44
  }
46
45
  public toString(): string {
@@ -48,17 +47,18 @@ class Writer implements IWriter {
48
47
  }
49
48
  }
50
49
 
51
- export async function buildDocumentationToString(namespace: Namespace): Promise<string> {
50
+ export interface BuildDocumentationOptions {
51
+ node?: BaseNode;
52
+
53
+ dumpGraphics? :(writer: IWriter, type: UAObjectType | UAVariableType)=>void;
54
+ }
55
+
56
+ export async function buildDocumentationToString(namespace: INamespace, options?: BuildDocumentationOptions): Promise<string> {
52
57
  const writer = new Writer();
53
- await buildDocumentation(namespace, writer);
58
+ await buildDocumentation(namespace, writer, options);
54
59
  return writer.toString();
55
60
  }
56
61
 
57
- interface V {
58
- valueRank?: number;
59
- arrayDimensions?: number[];
60
- dataType: NodeId;
61
- }
62
62
  const toDataTypeStr = (p: BaseNode): string => {
63
63
  if (p.nodeClass === NodeClass.Variable) {
64
64
  const v = p as UAVariable;
@@ -74,7 +74,6 @@ const toDataTypeStr = (p: BaseNode): string => {
74
74
  return "";
75
75
  };
76
76
  function dataTypeEnumerationToMarkdown(dataType: UADataType): string {
77
- const addressSpace = dataType.addressSpace;
78
77
  const writer = new Writer();
79
78
 
80
79
  writer.writeLine("");
@@ -217,19 +216,73 @@ function dumpReferenceType(referenceType: UAReferenceType): string {
217
216
  writer.writeLine(str);
218
217
  return writer.toString();
219
218
  }
220
- export async function buildDocumentation(namespace: Namespace, writer: IWriter): Promise<void> {
221
- const addressSpace = namespace.addressSpace;
219
+
220
+ export function extractTypes(namespace: INamespace, options?: BuildDocumentationOptions) {
221
+ const namespacePriv = namespace as unknown as NamespacePriv2;
222
+ if (!options || !options.node) {
223
+ const dataTypes = [...namespacePriv._dataTypeIterator()];
224
+ const objectTypes = [...namespacePriv._objectTypeIterator()];
225
+ const variableTypes = [...namespacePriv._variableTypeIterator()];
226
+ const referenceTypes = [...namespacePriv._referenceTypeIterator()];
227
+ return { dataTypes, variableTypes, objectTypes, referenceTypes };
228
+ }
229
+ const node = options.node;
230
+
231
+ if (node.nodeClass === NodeClass.DataType) {
232
+ const dataTypes: UADataType[] = [];
233
+ let dataType = node as UADataType;
234
+ dataTypes.push(dataType);
235
+ while (dataType.subtypeOfObj && dataType.subtypeOfObj.nodeId.namespace === namespace.index) {
236
+ dataType = dataType.subtypeOfObj;
237
+ dataTypes.push(dataType);
238
+ }
239
+ return { dataTypes, variableTypes: [], objectTypes: [], dataTypeNode: [], referenceTypes: [] };
240
+ } else if (node.nodeClass === NodeClass.ObjectType) {
241
+ const objectTypes: UAObjectType[] = [];
242
+ let objectType = node as UAObjectType;
243
+ objectTypes.push(objectType);
244
+ while (objectType.subtypeOfObj && objectType.subtypeOfObj.nodeId.namespace === namespace.index) {
245
+ objectType = objectType.subtypeOfObj;
246
+ objectTypes.push(objectType);
247
+ }
248
+ return { dataTypes: [], variableTypes: [], objectTypes, dataTypeNode: [], referenceTypes: [] };
249
+ } else if (node.nodeClass === NodeClass.VariableType) {
250
+ const variableTypes: UAVariableType[] = [];
251
+ let variableType = node as UAVariableType;
252
+ variableTypes.push(variableType);
253
+ while (variableType.subtypeOfObj && variableType.subtypeOfObj.nodeId.namespace === namespace.index) {
254
+ variableType = variableType.subtypeOfObj;
255
+ variableTypes.push(variableType);
256
+ }
257
+ return { dataTypes: [], variableTypes, objectTypes: [], dataTypeNode: [], referenceTypes: [] };
258
+ }
259
+
260
+ const dataTypes = [...namespacePriv._dataTypeIterator()];
261
+ const objectTypes = [...namespacePriv._objectTypeIterator()];
262
+ const variableTypes = [...namespacePriv._variableTypeIterator()];
263
+ const referenceTypes = [...namespacePriv._referenceTypeIterator()];
264
+ return { dataTypes, variableTypes, objectTypes, referenceTypes };
265
+ }
266
+
267
+ export async function buildDocumentation(
268
+ namespace: INamespace,
269
+ writer: IWriter,
270
+ options?: BuildDocumentationOptions
271
+ ): Promise<void> {
272
+
273
+ options = options || {};
274
+
275
+ const namespacePriv = namespace as unknown as NamespacePriv2;
222
276
 
223
277
  const namespaceUri = namespace.namespaceUri;
224
278
  // -------- Documentation
225
279
 
226
- const nsIndex = addressSpace.getNamespaceIndex(namespaceUri);
280
+ const { dataTypes, objectTypes, variableTypes } = extractTypes(namespace, options);
227
281
 
228
282
  writer.writeLine("");
229
283
  writer.writeLine("# Namespace " + namespaceUri);
230
284
  writer.writeLine("");
231
285
 
232
- const namespacePriv = namespace as unknown as NamespacePriv2;
233
286
  // -------------- writeReferences
234
287
  if (namespacePriv._referenceTypeCount() > 0) {
235
288
  writer.writeLine("");
@@ -240,32 +293,34 @@ export async function buildDocumentation(namespace: Namespace, writer: IWriter):
240
293
  dumpReferenceType(referenceType);
241
294
  }
242
295
  }
296
+
243
297
  function d(node: BaseNode): string {
244
298
  return node.description ? node.description!.text!.toString() : "";
245
299
  }
300
+
246
301
  // -------------- writeDataType
247
- if (namespacePriv._dataTypeCount() > 0) {
302
+ if (dataTypes.length > 0) {
248
303
  writer.writeLine("");
249
304
  writer.writeLine("## DataTypes");
250
305
  writer.writeLine("");
251
- for (const dataType of namespacePriv._dataTypeIterator()) {
306
+ for (const dataType of dataTypes) {
252
307
  writer.writeLine("\n\n### " + dataType.browseName.name!.toString());
253
308
  writer.writeLine("");
254
309
  writer.writeLine(dataTypeToMarkdown(dataType));
255
310
  }
256
311
  }
257
312
  // -------------- writeObjectType
258
- if (namespacePriv._objectTypeCount() > 0) {
313
+ if (objectTypes.length > 0) {
259
314
  writer.writeLine("");
260
315
  writer.writeLine("## ObjectTypes");
261
316
  writer.writeLine("");
262
- for (const objectType of namespacePriv._objectTypeIterator()) {
317
+ for (const objectType of objectTypes) {
263
318
  writer.writeLine("\n\n### " + objectType.browseName.name!.toString());
264
319
  writer.writeLine(d(objectType));
265
320
 
266
- writer.writeLine(graphVizToPlantUml(dumpClassHierachry(objectType, { showBaseType: true, depth: 2 })));
267
-
268
- writer.writeLine(graphVizToPlantUml(opcuaToDot(objectType)));
321
+ if (options.dumpGraphics) {
322
+ await options.dumpGraphics(writer, objectType);
323
+ }
269
324
 
270
325
  // enumerate components
271
326
  writer.writeLine(displayNodeElement(objectType, { format: "markdown" }));
@@ -283,19 +338,18 @@ export async function buildDocumentation(namespace: Namespace, writer: IWriter):
283
338
  }
284
339
  }
285
340
  // -------------- writeVariableType
286
- if (namespacePriv._variableTypeCount() > 0) {
341
+ if (variableTypes.length > 0) {
287
342
  writer.writeLine("");
288
343
  writer.writeLine("## VariableTypes");
289
344
  writer.writeLine("");
290
- for (const variableType of namespacePriv._variableTypeIterator()) {
345
+ for (const variableType of variableTypes) {
291
346
  writer.writeLine("\n\n### " + variableType.browseName.name!.toString());
292
347
  writer.writeLine(d(variableType));
293
348
  writer.writeLine("");
294
349
 
295
- writer.writeLine(graphVizToPlantUml(dumpClassHierachry(variableType, { showBaseType: true, depth: 2 })));
296
-
297
- writer.writeLine(graphVizToPlantUml(opcuaToDot(variableType)));
298
-
350
+ if (options.dumpGraphics) {
351
+ await options.dumpGraphics(writer, variableType);
352
+ }
299
353
  // enumerate components
300
354
  writer.writeLine(displayNodeElement(variableType, { format: "markdown" }));
301
355
  for (const reference of variableType.allReferences()) {
@@ -307,3 +361,4 @@ export async function buildDocumentation(namespace: Namespace, writer: IWriter):
307
361
  }
308
362
  }
309
363
  }
364
+
package/source/index.ts CHANGED
@@ -6,8 +6,9 @@ export * from "./build_model_inner";
6
6
  export * from "./addExtensionObjectDataType";
7
7
  export * from "./symbol";
8
8
  export * from "./to_cvs";
9
- export * from "./to_graphivz";
10
9
  export * from "./generate_markdown_doc";
10
+ export * from "./tableHelper";
11
+
11
12
  //
12
13
  export * from "node-opcua-address-space";
13
14
  export * from "node-opcua-nodesets";
@@ -1,9 +1,9 @@
1
1
  import * as fs from "fs";
2
2
  import { Namespace } from "node-opcua-address-space";
3
- import { buildDocumentationToString } from "..";
3
+ import { BuildDocumentationOptions, buildDocumentationToString } from "..";
4
4
 
5
- export async function buildDocumentationToFile(namespace: Namespace, filename: string) {
6
- const str = await buildDocumentationToString(namespace);
5
+ export async function buildDocumentationToFile(namespace: Namespace, filename: string, options?: BuildDocumentationOptions) {
6
+ const str = await buildDocumentationToString(namespace, options);
7
7
  const stream = fs.createWriteStream("documentation.md");
8
8
  stream.write(str);
9
9
  await new Promise((resolve) => {
@@ -1,125 +0,0 @@
1
- <?xml version="1.0"?>
2
- <UANodeSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd" xmlns="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd">
3
- <NamespaceUris>
4
- <Uri>http://acme.com/Boiler/V0</Uri>
5
- <Uri>http://opcfoundation.org/UA/DI/</Uri>
6
- </NamespaceUris>
7
- <Models/>
8
- <Aliases>
9
- <Alias Alias="2:DeviceHealthEnumeration">ns=2;i=6244</Alias>
10
- <Alias Alias="Boolean">i=1</Alias>
11
- <Alias Alias="DateTime">i=13</Alias>
12
- <Alias Alias="HasComponent">i=47</Alias>
13
- <Alias Alias="HasModellingRule">i=37</Alias>
14
- <Alias Alias="HasProperty">i=46</Alias>
15
- <Alias Alias="HasSubtype">i=45</Alias>
16
- <Alias Alias="HasTypeDefinition">i=40</Alias>
17
- <Alias Alias="IdType">i=256</Alias>
18
- <Alias Alias="NumericRange">i=291</Alias>
19
- <Alias Alias="Organizes">i=35</Alias>
20
- <Alias Alias="String">i=12</Alias>
21
- </Aliases>
22
- <!--ReferenceTypes-->
23
- <!--ObjectTypes-->
24
- <!--ObjectType - 1:BoilerType {{{{ -->
25
- <UAObjectType NodeId="ns=1;i=1008" BrowseName="1:BoilerType">
26
- <DisplayName>BoilerType</DisplayName>
27
- <References>
28
- <Reference ReferenceType="HasSubtype" IsForward="false">ns=2;i=1002</Reference>
29
- <Reference ReferenceType="HasComponent">ns=1;i=1009</Reference>
30
- </References>
31
- </UAObjectType>
32
- <UAVariable NodeId="ns=1;i=1009" BrowseName="2:DeviceHealth" DataType="2:DeviceHealthEnumeration">
33
- <DisplayName>DeviceHealth</DisplayName>
34
- <References>
35
- <Reference ReferenceType="HasTypeDefinition">i=63</Reference>
36
- <Reference ReferenceType="HasModellingRule">i=78</Reference>
37
- </References>
38
- </UAVariable>
39
- <!--ObjectType - 1:BoilerType }}}}-->
40
- <!--VariableTypes-->
41
- <!--Other Nodes-->
42
- <!-- StaticStringNodeIdPattern StaticNumericNodeIdRange StaticNodeIdTypes NamespaceVersion NamespaceUri NamespacePublicationDate IsNamespaceSubset http://acme.com/Boiler/V0 BoilerType DeviceHealth-->
43
- <UAVariable NodeId="ns=1;i=1007" BrowseName="StaticStringNodeIdPattern" DataType="String">
44
- <DisplayName>StaticStringNodeIdPattern</DisplayName>
45
- <Description>A regular expression which matches string node ids are the same in every server that exposes them.</Description>
46
- <References>
47
- <Reference ReferenceType="HasTypeDefinition">i=68</Reference>
48
- <Reference ReferenceType="HasModellingRule">i=78</Reference>
49
- </References>
50
- </UAVariable>
51
- <UAVariable NodeId="ns=1;i=1006" BrowseName="StaticNumericNodeIdRange" ValueRank="1" DataType="NumericRange">
52
- <DisplayName>StaticNumericNodeIdRange</DisplayName>
53
- <Description>A list of ranges for numeric node ids which are the same in every server that exposes them.</Description>
54
- <References>
55
- <Reference ReferenceType="HasTypeDefinition">i=68</Reference>
56
- <Reference ReferenceType="HasModellingRule">i=78</Reference>
57
- </References>
58
- </UAVariable>
59
- <UAVariable NodeId="ns=1;i=1005" BrowseName="StaticNodeIdTypes" ValueRank="1" DataType="IdType">
60
- <DisplayName>StaticNodeIdTypes</DisplayName>
61
- <Description>A list of IdTypes for nodes which are the same in every server that exposes them.</Description>
62
- <References>
63
- <Reference ReferenceType="HasTypeDefinition">i=68</Reference>
64
- <Reference ReferenceType="HasModellingRule">i=78</Reference>
65
- </References>
66
- </UAVariable>
67
- <UAVariable NodeId="ns=1;i=1002" BrowseName="NamespaceVersion" DataType="String">
68
- <DisplayName>NamespaceVersion</DisplayName>
69
- <Description>The human readable string representing version of the namespace.</Description>
70
- <References>
71
- <Reference ReferenceType="HasTypeDefinition">i=68</Reference>
72
- <Reference ReferenceType="HasModellingRule">i=78</Reference>
73
- </References>
74
- <Value>
75
- <String>1.0.0</String>
76
- </Value>
77
- </UAVariable>
78
- <UAVariable NodeId="ns=1;i=1001" BrowseName="NamespaceUri" DataType="String">
79
- <DisplayName>NamespaceUri</DisplayName>
80
- <Description>The URI of the namespace.</Description>
81
- <References>
82
- <Reference ReferenceType="HasTypeDefinition">i=68</Reference>
83
- <Reference ReferenceType="HasModellingRule">i=78</Reference>
84
- </References>
85
- <Value>
86
- <String>http://acme.com/Boiler/V0</String>
87
- </Value>
88
- </UAVariable>
89
- <UAVariable NodeId="ns=1;i=1003" BrowseName="NamespacePublicationDate" DataType="DateTime">
90
- <DisplayName>NamespacePublicationDate</DisplayName>
91
- <Description>The publication date for the namespace.</Description>
92
- <References>
93
- <Reference ReferenceType="HasTypeDefinition">i=68</Reference>
94
- <Reference ReferenceType="HasModellingRule">i=78</Reference>
95
- </References>
96
- <Value>
97
- <DateTime>2020-01-16T10:11:59.351Z</DateTime>
98
- </Value>
99
- </UAVariable>
100
- <UAVariable NodeId="ns=1;i=1004" BrowseName="IsNamespaceSubset" DataType="Boolean">
101
- <DisplayName>IsNamespaceSubset</DisplayName>
102
- <Description>If TRUE then the server only supports a subset of the namespace.</Description>
103
- <References>
104
- <Reference ReferenceType="HasTypeDefinition">i=68</Reference>
105
- <Reference ReferenceType="HasModellingRule">i=78</Reference>
106
- </References>
107
- </UAVariable>
108
- <!--Object - 1:http://acme.com/Boiler/V0 {{{{ -->
109
- <UAObject NodeId="ns=1;i=1000" BrowseName="1:http://acme.com/Boiler/V0">
110
- <DisplayName>http://acme.com/Boiler/V0</DisplayName>
111
- <Description>Provides the metadata for a namespace used by the server.</Description>
112
- <References>
113
- <Reference ReferenceType="HasTypeDefinition">i=11616</Reference>
114
- <Reference ReferenceType="Organizes" IsForward="false">i=11715</Reference>
115
- <Reference ReferenceType="HasProperty">ns=1;i=1001</Reference>
116
- <Reference ReferenceType="HasProperty">ns=1;i=1002</Reference>
117
- <Reference ReferenceType="HasProperty">ns=1;i=1003</Reference>
118
- <Reference ReferenceType="HasProperty">ns=1;i=1004</Reference>
119
- <Reference ReferenceType="HasProperty">ns=1;i=1005</Reference>
120
- <Reference ReferenceType="HasProperty">ns=1;i=1006</Reference>
121
- <Reference ReferenceType="HasProperty">ns=1;i=1007</Reference>
122
- </References>
123
- </UAObject>
124
- <!--Object - 1:http://acme.com/Boiler/V0 }}}} -->
125
- </UANodeSet>
@@ -1,16 +0,0 @@
1
- import { AddressSpace } from "node-opcua-address-space";
2
- export declare type Symbols = Array<[string, number, string]>;
3
- export interface BuildModelOptions {
4
- version: string;
5
- namespaceUri: string;
6
- xmlFiles: string[];
7
- createModel: (addressSpace: AddressSpace) => Promise<void>;
8
- presetSymbols?: Symbols;
9
- }
10
- export declare function buildModel(data: BuildModelOptions): Promise<{
11
- markdown: string;
12
- xmlModel: string;
13
- symbols: Symbols;
14
- }>;
15
- export declare function saveSymbolsToCSV(csvFilename: string, symbols: Symbols): Promise<void>;
16
- export declare function getPresetSymbolsFromCSV(csvFilename: string): Promise<Symbols>;
@@ -1,91 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const fs = require("fs");
13
- const node_opcua_address_space_1 = require("node-opcua-address-space");
14
- const util_1 = require("util");
15
- const writeFile = util_1.promisify(fs.writeFile);
16
- const readFile = util_1.promisify(fs.readFile);
17
- function buildModel(data) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- try {
20
- const addressSpace = node_opcua_address_space_1.AddressSpace.create();
21
- // create own namespace (before loading other xml files)
22
- const ns = addressSpace.registerNamespace(data.namespaceUri);
23
- const nodeIdManager = (ns._nodeIdManager);
24
- if (data.presetSymbols) {
25
- nodeIdManager.setSymbols(data.presetSymbols);
26
- }
27
- yield node_opcua_address_space_1.generateAddressSpace(addressSpace, data.xmlFiles);
28
- yield data.createModel(addressSpace);
29
- const xmlModel = ns.toNodeset2XML();
30
- const symbols = nodeIdManager.getSymbols();
31
- const doc = yield generate_markdown_doc_1.buildDocumentationToString(ns);
32
- addressSpace.dispose();
33
- return { xmlModel, symbols, markdown: doc };
34
- }
35
- catch (err) {
36
- // tslint:disable-next-line: no-console
37
- console.log("Error", err);
38
- throw err;
39
- }
40
- });
41
- }
42
- exports.buildModel = buildModel;
43
- const parse = require("csv-parse");
44
- const generate_markdown_doc_1 = require("./generate_markdown_doc");
45
- function toCSV(arr) {
46
- const line = [];
47
- for (const [name, value, nodeClass] of arr) {
48
- line.push([name, value, nodeClass].join(","));
49
- }
50
- return line.join("\n");
51
- }
52
- function saveSymbolsToCSV(csvFilename, symbols) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- yield writeFile(csvFilename, toCSV(symbols), "utf-8");
55
- });
56
- }
57
- exports.saveSymbolsToCSV = saveSymbolsToCSV;
58
- function getPresetSymbolsFromCSV(csvFilename) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- try {
61
- const data = yield readFile(csvFilename, "utf-8");
62
- const records = yield new Promise((resolve) => {
63
- const output = [];
64
- parse(data, {
65
- cast: (value, context) => {
66
- if (context.index === 1) {
67
- return parseInt(value, 10);
68
- }
69
- return value;
70
- }
71
- }).on("readable", function () {
72
- let record = this.read();
73
- while (record) {
74
- output.push(record);
75
- record = this.read();
76
- }
77
- }).on("end", () => {
78
- resolve(output);
79
- });
80
- });
81
- return records;
82
- }
83
- catch (err) {
84
- // tslint:disable-next-line: no-console
85
- console.log("getPresetSymbols err = ", err.message);
86
- return [];
87
- }
88
- });
89
- }
90
- exports.getPresetSymbolsFromCSV = getPresetSymbolsFromCSV;
91
- //# sourceMappingURL=buildModel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildModel.js","sourceRoot":"","sources":["../source/buildModel.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,yBAAyB;AACzB,uEAKkC;AAElC,+BAAiC;AAEjC,MAAM,SAAS,GAAG,gBAAS,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;AAC1C,MAAM,QAAQ,GAAG,gBAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;AAYxC,SAAsB,UAAU,CAAC,IAAuB;;QACpD,IAAI;YACA,MAAM,YAAY,GAAG,uCAAY,CAAC,MAAM,EAAE,CAAC;YAE3C,wDAAwD;YACxD,MAAM,EAAE,GAAG,YAAY,CAAC,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAE7D,MAAM,aAAa,GAAG,CAAE,EAAU,CAAC,cAAc,CAAkB,CAAC;YACpE,IAAI,IAAI,CAAC,aAAa,EAAE;gBACpB,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;aAChD;YAED,MAAM,+CAAoB,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAExD,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;YAErC,MAAM,QAAQ,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC;YACpC,MAAM,OAAO,GAAG,aAAa,CAAC,UAAU,EAAE,CAAC;YAC3C,MAAM,GAAG,GAAG,MAAM,kDAA0B,CAAC,EAAE,CAAC,CAAC;YACjD,YAAY,CAAC,OAAO,EAAE,CAAC;YAEvB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BACJ,CAAC,CAAC,EAAE,CAAC,UAAU,EAAE;oBACd,IAAI,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;oBACzB,OAAO,MAAM,EAAE;wBACX,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;wBACpB,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;qBACxB;gBACL,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;oBACd,OAAO,CAAC,MAAM,CAAC,CAAC;gBACpB,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;YACH,OAAO,OAAkB,CAAC;SAC7B;QAAC,OAAO,GAAG,EAAE;YACV,uCAAuC;YACvC,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;YACpD,OAAO,EAAE,CAAC;SACb;IACL,CAAC;CAAA;AA7BD,0DA6BC"}
package/dist/display.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { BaseNode } from "node-opcua-address-space";
2
- export declare function displayNodeElement(node: BaseNode): void;
package/dist/display.js DELETED
@@ -1,96 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const node_opcua_variant_1 = require("node-opcua-variant");
4
- const node_opcua_data_model_1 = require("node-opcua-data-model");
5
- const Table = require("cli-table");
6
- const a = 'ⓂⓄⓋⓥⓇ❗⟵ ⟶⟷';
7
- function symbol(nodeClass) {
8
- switch (nodeClass) {
9
- case node_opcua_data_model_1.NodeClass.DataType: return "Ⓓ";
10
- case node_opcua_data_model_1.NodeClass.ObjectType: return "<Ⓞ>";
11
- case node_opcua_data_model_1.NodeClass.VariableType: return "<Ⓥ>";
12
- case node_opcua_data_model_1.NodeClass.Method: return "Ⓜ";
13
- case node_opcua_data_model_1.NodeClass.Object: return "Ⓞ";
14
- case node_opcua_data_model_1.NodeClass.Variable: return "Ⓥ";
15
- case node_opcua_data_model_1.NodeClass.View: return "⦖";
16
- default: return "?";
17
- }
18
- }
19
- function displayNodeElement(node) {
20
- // instantiate
21
- var table = new Table({
22
- head: [
23
- 'ReferenceType', 'NodeId', 'BrowseName', 'ModellingRule', "TypeDefinition", "DataType", "Value"
24
- ],
25
- });
26
- table.push([
27
- "BrowseName: ",
28
- { colSpan: 6, content: node.browseName.toString() },
29
- ]);
30
- if (node.description) {
31
- table.push([
32
- "Description: ",
33
- node.description.toString(),
34
- ]);
35
- }
36
- const alreadyDumped = {};
37
- function dumpRefe(ref) {
38
- if (!ref.isForward) {
39
- return;
40
- }
41
- if (!ref.node) {
42
- console.log(" Halt ", ref.toString());
43
- return;
44
- }
45
- const dir = ref.isForward ? "⟶" : "⟵";
46
- const refNode = ref.node;
47
- const refType = ref._referenceType;
48
- // xx const r = refNode.findReferencesAsObject("HasModellingRule", true);
49
- const modelingRule = refNode.modellingRule || ""; // r[0] ? r[0].browseName.toString() : "/";
50
- let value = "";
51
- let dataType = "";
52
- if (refNode.nodeClass === node_opcua_data_model_1.NodeClass.Variable) {
53
- const v = refNode;
54
- const val = v.readValue().value.value;
55
- if (v.isEnumeration() && val !== null) {
56
- const a = v.readEnumValue();
57
- value = a.value + " (" + a.name + ")";
58
- }
59
- else {
60
- value = val ? val.toString() : "null";
61
- }
62
- const actualDataType = node_opcua_variant_1.DataType[v.readValue().value.dataType];
63
- dataType = v.dataTypeObj.browseName.toString();
64
- //findBasicDataType(v.dataTypeObj);
65
- }
66
- table.push([
67
- refType.browseName.toString() + dir + symbol(refNode.nodeClass),
68
- refNode.nodeId.toString(),
69
- refNode.browseName.toString(),
70
- modelingRule,
71
- refNode.typeDefinitionObj ? refNode.typeDefinitionObj.browseName.toString() : "",
72
- dataType, value
73
- ]);
74
- alreadyDumped[refNode.browseName.toString()] = 1;
75
- }
76
- const references = node.allReferences();
77
- for (const ref of references) {
78
- dumpRefe(ref);
79
- }
80
- // add property from derived type
81
- if (node.nodeClass === node_opcua_data_model_1.NodeClass.ObjectType || node.nodeClass === node_opcua_data_model_1.NodeClass.VariableType) {
82
- const curNode = node;
83
- let superType = curNode.subtypeOfObj;
84
- while (superType) {
85
- table.push([superType.browseName.toString() + ":", "--", "--", "--"]);
86
- const references = superType.allReferences();
87
- for (const ref of references) {
88
- dumpRefe(ref);
89
- }
90
- superType = superType.subtypeOfObj;
91
- }
92
- }
93
- console.log(table.toString());
94
- }
95
- exports.displayNodeElement = displayNodeElement;
96
- //# sourceMappingURL=display.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"display.js","sourceRoot":"","sources":["../source/display.ts"],"names":[],"mappings":";;AAIA,2DAA8C;AAC9C,iEAAkD;AAClD,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAGnC,MAAM,CAAC,GAAG,YAAY,CAAA;AACtB,SAAS,MAAM,CAAC,SAAoB;IAChC,QAAQ,SAAS,EAAE;QACf,KAAK,iCAAS,CAAC,QAAQ,CAAC,CAAC,OAAO,GAAG,CAAC;QACpC,KAAK,iCAAS,CAAC,UAAU,CAAC,CAAC,OAAO,KAAK,CAAC;QACxC,KAAK,iCAAS,CAAC,YAAY,CAAC,CAAC,OAAO,KAAK,CAAC;QAC1C,KAAK,iCAAS,CAAC,MAAM,CAAC,CAAC,OAAO,GAAG,CAAC;QAClC,KAAK,iCAAS,CAAC,MAAM,CAAC,CAAC,OAAO,GAAG,CAAC;QAClC,KAAK,iCAAS,CAAC,QAAQ,CAAC,CAAC,OAAO,GAAG,CAAC;QACpC,KAAK,iCAAS,CAAC,IAAI,CAAC,CAAC,OAAO,GAAG,CAAC;QAChC,OAAO,CAAC,CAAC,OAAO,GAAG,CAAA;KACtB;AACL,CAAC;AACD,SAAgB,kBAAkB,CAAC,IAAc;IAE7C,cAAc;IACd,IAAI,KAAK,GAAG,IAAI,KAAK,CAAC;QAClB,IAAI,EAAE;YACF,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,UAAU,EAAE,OAAO;SAClG;KAEJ,C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