node-opcua-address-space 2.186.17 → 2.187.1

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 (84) hide show
  1. package/api/address_space_public.ts +16 -0
  2. package/api/helpers/resolve_opaque_on_address_space.ts +13 -1
  3. package/api/index.ts +14 -3
  4. package/api/loader/store_record_applier.ts +267 -0
  5. package/api/session_context.ts +116 -27
  6. package/dist/api/address_space_public.d.ts +14 -0
  7. package/dist/api/address_space_public.d.ts.map +1 -1
  8. package/dist/api/address_space_public.js +3 -0
  9. package/dist/api/address_space_public.js.map +1 -1
  10. package/dist/api/helpers/resolve_opaque_on_address_space.d.ts +6 -0
  11. package/dist/api/helpers/resolve_opaque_on_address_space.d.ts.map +1 -1
  12. package/dist/api/helpers/resolve_opaque_on_address_space.js +12 -1
  13. package/dist/api/helpers/resolve_opaque_on_address_space.js.map +1 -1
  14. package/dist/api/index.d.ts +4 -3
  15. package/dist/api/index.d.ts.map +1 -1
  16. package/dist/api/index.js +4 -3
  17. package/dist/api/index.js.map +1 -1
  18. package/dist/api/loader/store_record_applier.d.ts +49 -0
  19. package/dist/api/loader/store_record_applier.d.ts.map +1 -0
  20. package/dist/api/loader/store_record_applier.js +235 -0
  21. package/dist/api/loader/store_record_applier.js.map +1 -0
  22. package/dist/api/session_context.d.ts +10 -0
  23. package/dist/api/session_context.d.ts.map +1 -1
  24. package/dist/api/session_context.js +100 -27
  25. package/dist/api/session_context.js.map +1 -1
  26. package/dist/impl/address_space.d.ts +2 -0
  27. package/dist/impl/address_space.d.ts.map +1 -1
  28. package/dist/impl/address_space.js +12 -2
  29. package/dist/impl/address_space.js.map +1 -1
  30. package/dist/impl/base_node_impl.d.ts +12 -0
  31. package/dist/impl/base_node_impl.d.ts.map +1 -1
  32. package/dist/impl/base_node_impl.js +35 -29
  33. package/dist/impl/base_node_impl.js.map +1 -1
  34. package/dist/impl/base_node_private.d.ts +5 -5
  35. package/dist/impl/base_node_private.d.ts.map +1 -1
  36. package/dist/impl/base_node_private.js +11 -5
  37. package/dist/impl/base_node_private.js.map +1 -1
  38. package/dist/impl/extension_object_array_node.d.ts +4 -2
  39. package/dist/impl/extension_object_array_node.d.ts.map +1 -1
  40. package/dist/impl/extension_object_array_node.js +5 -2
  41. package/dist/impl/extension_object_array_node.js.map +1 -1
  42. package/dist/impl/historical_access/address_space_historical_data_node.d.ts +26 -2
  43. package/dist/impl/historical_access/address_space_historical_data_node.d.ts.map +1 -1
  44. package/dist/impl/historical_access/address_space_historical_data_node.js +39 -0
  45. package/dist/impl/historical_access/address_space_historical_data_node.js.map +1 -1
  46. package/dist/impl/namespace_impl.d.ts.map +1 -1
  47. package/dist/impl/namespace_impl.js +3 -1
  48. package/dist/impl/namespace_impl.js.map +1 -1
  49. package/dist/impl/nodeid_manager.d.ts.map +1 -1
  50. package/dist/impl/nodeid_manager.js +10 -7
  51. package/dist/impl/nodeid_manager.js.map +1 -1
  52. package/dist/impl/nodeset_tools/construct_namespace_dependency.d.ts.map +1 -1
  53. package/dist/impl/nodeset_tools/construct_namespace_dependency.js +28 -0
  54. package/dist/impl/nodeset_tools/construct_namespace_dependency.js.map +1 -1
  55. package/dist/impl/reference_impl.d.ts +2 -1
  56. package/dist/impl/reference_impl.d.ts.map +1 -1
  57. package/dist/impl/reference_impl.js +6 -5
  58. package/dist/impl/reference_impl.js.map +1 -1
  59. package/dist/impl/reference_index.d.ts +22 -0
  60. package/dist/impl/reference_index.d.ts.map +1 -0
  61. package/dist/impl/reference_index.js +104 -0
  62. package/dist/impl/reference_index.js.map +1 -0
  63. package/dist/impl/ua_variable_impl.d.ts +10 -0
  64. package/dist/impl/ua_variable_impl.d.ts.map +1 -1
  65. package/dist/impl/ua_variable_impl.js +152 -106
  66. package/dist/impl/ua_variable_impl.js.map +1 -1
  67. package/dist/tsconfig_base.tsbuildinfo +1 -1
  68. package/distNodeJS/generate_address_space.d.ts +6 -1
  69. package/distNodeJS/generate_address_space.d.ts.map +1 -1
  70. package/distNodeJS/generate_address_space.js +33 -1
  71. package/distNodeJS/generate_address_space.js.map +1 -1
  72. package/impl/address_space.ts +16 -2
  73. package/impl/base_node_impl.ts +52 -30
  74. package/impl/base_node_private.ts +16 -10
  75. package/impl/extension_object_array_node.ts +12 -3
  76. package/impl/historical_access/address_space_historical_data_node.ts +64 -1
  77. package/impl/namespace_impl.ts +3 -1
  78. package/impl/nodeid_manager.ts +10 -7
  79. package/impl/nodeset_tools/construct_namespace_dependency.ts +23 -1
  80. package/impl/reference_impl.ts +6 -5
  81. package/impl/reference_index.ts +116 -0
  82. package/impl/ua_variable_impl.ts +203 -115
  83. package/package.json +34 -33
  84. package/source_nodejs/generate_address_space.ts +46 -1
@@ -3,7 +3,8 @@ import assert from "node-opcua-assert";
3
3
  import { DataType } from "node-opcua-basic-types";
4
4
  import { NodeClass } from "node-opcua-data-model";
5
5
  import { make_debugLog, make_warningLog } from "node-opcua-debug";
6
- import type { ExtensionObject } from "node-opcua-extension-object";
6
+ import { ExtensionObject } from "node-opcua-extension-object";
7
+ import { NodeId } from "node-opcua-nodeid";
7
8
  import type { StructureField } from "node-opcua-types";
8
9
  import { Variant } from "node-opcua-variant";
9
10
  import type { TranslationTable } from "../../api/xml_writer.js";
@@ -11,6 +12,7 @@ import type { BaseNodeImpl } from "../base_node_impl.js";
11
12
  import type { NamespacePrivate } from "../namespace_private.js";
12
13
  import { ReferenceImpl } from "../reference_impl.js";
13
14
  import type { UAVariableImpl } from "../ua_variable_impl.js";
15
+ import type { UAVariableTypeImpl } from "../ua_variable_type_impl.js";
14
16
 
15
17
  const warningLog = make_warningLog("construct_namespace_dependency");
16
18
  const _debugLog = make_debugLog("construct_namespace_dependency");
@@ -212,11 +214,31 @@ export function _getCompleteRequiredModelsFromValuesAndReferences(
212
214
  }
213
215
  };
214
216
 
217
+ // the exporter translates every NodeId a value holds (an Argument's DataType, a NodeId field of
218
+ // a structure, a NodeId variable), so each of their namespaces is a dependency whatever its priority
219
+ const exploreValue = (value: unknown): void => {
220
+ if (value === null || value === undefined) return;
221
+ if (value instanceof NodeId) {
222
+ consider(value.namespace);
223
+ } else if (value instanceof Variant) {
224
+ exploreValue(value.value);
225
+ } else if (Array.isArray(value)) {
226
+ for (const element of value) exploreValue(element);
227
+ } else if (value instanceof ExtensionObject) {
228
+ for (const fieldValue of Object.values(value)) exploreValue(fieldValue);
229
+ }
230
+ };
231
+
215
232
  const addressSpace = namespace.addressSpace;
216
233
  const nonHierarchicalReferencesType = addressSpace.findReferenceType("NonHierarchicalReferences");
217
234
 
218
235
  //const maxIndex = Math.max(...requiredNamespaceIndexes);
219
236
  for (const node of namespace_.nodeIterator()) {
237
+ if (node.nodeClass === NodeClass.Variable) {
238
+ exploreValue((node as UAVariableImpl).$dataValue?.value);
239
+ } else if (node.nodeClass === NodeClass.VariableType) {
240
+ exploreValue((node as UAVariableTypeImpl).value);
241
+ }
220
242
  const references = (<BaseNodeImpl>node).allReferences();
221
243
  for (const reference of references) {
222
244
  // check referenceId
@@ -157,7 +157,8 @@ export class ReferenceImpl implements UAReference {
157
157
 
158
158
  // cache
159
159
  private __hash?: string;
160
- private __key?: ReferenceKey;
160
+ /** the key this reference is indexed under, computed once by key(); read by ReferenceIndex */
161
+ public _key?: ReferenceKey;
161
162
 
162
163
  constructor(options: AddReferenceOpts | UAReference) {
163
164
  assert(options.referenceType instanceof NodeId);
@@ -209,10 +210,10 @@ export class ReferenceImpl implements UAReference {
209
210
  * the key this reference is indexed under in the node holding it, computed once
210
211
  */
211
212
  key(ordinals: ReferenceTypeOrdinals): ReferenceKey {
212
- if (this.__key === undefined) {
213
- this.__key = referenceKey(this.isForward, ordinals.referenceTypeOrdinal(this.referenceType), nodeIdKey(this.nodeId));
213
+ if (this._key === undefined) {
214
+ this._key = referenceKey(this.isForward, ordinals.referenceTypeOrdinal(this.referenceType), nodeIdKey(this.nodeId));
214
215
  }
215
- return this.__key;
216
+ return this._key;
216
217
  }
217
218
 
218
219
  /**
@@ -230,7 +231,7 @@ export class ReferenceImpl implements UAReference {
230
231
  */
231
232
  public dispose(): void {
232
233
  this.__hash = undefined;
233
- this.__key = undefined;
234
+ // _key stays: the index holding this reference finds it by that key (ReferenceIndex)
234
235
  this.node = undefined;
235
236
  /*
236
237
  this._referenceType = null;
@@ -0,0 +1,116 @@
1
+ import type { UAReference } from "node-opcua-address-space-base";
2
+ import type { ReferenceImpl, ReferenceKey } from "./reference_impl.js";
3
+
4
+ /**
5
+ * above this many references a node indexes them in a Map; below, a plain array scanned on
6
+ * lookup. A leaf node holds two or three references, and a Map with its hash table costs
7
+ * about 280 bytes even when nearly empty: a quarter of what a node weighs. On a model of a
8
+ * million nodes that is the difference between fitting in memory and not.
9
+ */
10
+ const MAP_THRESHOLD = 16;
11
+
12
+ /**
13
+ * The references a node holds, by key (see ReferenceImpl#key). It offers what the code uses of
14
+ * a Map: get, has, set, delete, values, size and iteration.
15
+ *
16
+ * The key is not stored twice: a reference caches its own key when it is indexed, and a scan
17
+ * compares that cached key.
18
+ */
19
+ export class ReferenceIndex {
20
+ #refs: UAReference[] | null = null;
21
+ #map: Map<ReferenceKey, UAReference> | null = null;
22
+
23
+ public get size(): number {
24
+ return this.#map ? this.#map.size : this.#refs ? this.#refs.length : 0;
25
+ }
26
+
27
+ #indexOf(key: ReferenceKey): number {
28
+ const refs = this.#refs as ReferenceImpl[];
29
+ for (let i = 0; i < refs.length; i++) {
30
+ if (refs[i]._key === key) {
31
+ return i;
32
+ }
33
+ }
34
+ return -1;
35
+ }
36
+
37
+ public has(key: ReferenceKey): boolean {
38
+ if (this.#map) {
39
+ return this.#map.has(key);
40
+ }
41
+ return this.#refs !== null && this.#indexOf(key) !== -1;
42
+ }
43
+
44
+ public get(key: ReferenceKey): UAReference | undefined {
45
+ if (this.#map) {
46
+ return this.#map.get(key);
47
+ }
48
+ if (this.#refs === null) {
49
+ return undefined;
50
+ }
51
+ const index = this.#indexOf(key);
52
+ return index === -1 ? undefined : this.#refs[index];
53
+ }
54
+
55
+ /** `key` must be the reference's own key (ReferenceImpl#key), which is what callers index by */
56
+ public set(key: ReferenceKey, reference: UAReference): this {
57
+ if (this.#map) {
58
+ this.#map.set(key, reference);
59
+ return this;
60
+ }
61
+ if (this.#refs === null) {
62
+ this.#refs = [reference];
63
+ return this;
64
+ }
65
+ const index = this.#indexOf(key);
66
+ if (index !== -1) {
67
+ this.#refs[index] = reference; // check-proto-pollution: ok - numeric index
68
+ return this;
69
+ }
70
+ if (this.#refs.length >= MAP_THRESHOLD) {
71
+ const map = new Map<ReferenceKey, UAReference>();
72
+ for (const ref of this.#refs) {
73
+ map.set((ref as ReferenceImpl)._key as ReferenceKey, ref);
74
+ }
75
+ map.set(key, reference);
76
+ this.#map = map;
77
+ this.#refs = null;
78
+ return this;
79
+ }
80
+ // concat allocates exactly the length needed; push would grow the backing store to 17
81
+ // slots, which is more than the Map this replaces
82
+ this.#refs = this.#refs.concat(reference);
83
+ return this;
84
+ }
85
+
86
+ public delete(key: ReferenceKey): boolean {
87
+ if (this.#map) {
88
+ return this.#map.delete(key);
89
+ }
90
+ if (this.#refs === null) {
91
+ return false;
92
+ }
93
+ const index = this.#indexOf(key);
94
+ if (index === -1) {
95
+ return false;
96
+ }
97
+ this.#refs = this.#refs.length === 1 ? null : this.#refs.filter((_r, i) => i !== index);
98
+ return true;
99
+ }
100
+
101
+ public clear(): void {
102
+ this.#refs = null;
103
+ this.#map = null;
104
+ }
105
+
106
+ public values(): IterableIterator<UAReference> {
107
+ if (this.#map) {
108
+ return this.#map.values();
109
+ }
110
+ return (this.#refs ?? []).values();
111
+ }
112
+
113
+ public [Symbol.iterator](): IterableIterator<UAReference> {
114
+ return this.values();
115
+ }
116
+ }