node-opcua-variant 2.183.0 → 2.184.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.
package/dist/variant.js CHANGED
@@ -1,38 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VARIANT_TYPE_MASK = exports.VARIANT_ARRAY_DIMENSIONS_MASK = exports.VARIANT_ARRAY_MASK = exports.Variant = exports.VariantArrayType = void 0;
4
- exports.encodeVariant = encodeVariant;
5
- exports.decodeVariant = decodeVariant;
6
- exports.coerceVariantType = coerceVariantType;
7
- exports.isValidVariant = isValidVariant;
8
- exports.buildVariantArray = buildVariantArray;
9
- exports.sameVariant = sameVariant;
10
1
  /**
11
2
  * @module node-opcua-variant
12
3
  */
13
- const node_opcua_assert_1 = require("node-opcua-assert");
14
- const node_opcua_basic_types_1 = require("node-opcua-basic-types");
15
- const node_opcua_data_model_1 = require("node-opcua-data-model");
16
- const node_opcua_debug_1 = require("node-opcua-debug");
17
- const node_opcua_factory_1 = require("node-opcua-factory");
18
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
19
- const node_opcua_utils_1 = require("node-opcua-utils");
20
- const DataType_enum_js_1 = require("./DataType_enum.js");
21
- const VariantArrayType_enum_js_1 = require("./VariantArrayType_enum.js");
22
- Object.defineProperty(exports, "VariantArrayType", { enumerable: true, get: function () { return VariantArrayType_enum_js_1.VariantArrayType; } });
23
- const warningLog = (0, node_opcua_debug_1.make_warningLog)("variant");
24
- const schemaVariant = (0, node_opcua_factory_1.buildStructuredType)({
4
+ import { assert } from "node-opcua-assert";
5
+ import { coerceInt64, coerceUInt64, decodeUInt8, decodeUInt32, encodeUInt8, encodeUInt32, isValidBoolean, isValidByteString, isValidInt8, isValidInt16, isValidInt32, isValidInt64, isValidNodeId, isValidUInt8, isValidUInt16, isValidUInt32, isValidUInt64 } from "node-opcua-basic-types";
6
+ import { LocalizedText, QualifiedName } from "node-opcua-data-model";
7
+ import { make_warningLog } from "node-opcua-debug";
8
+ import { BaseUAObject, buildStructuredType, FieldCategory, findBuiltInType, initialize_field, onBuiltInTypeRegistryChanged, registerSpecialVariantEncoder, registerType } from "node-opcua-factory";
9
+ import { NodeId } from "node-opcua-nodeid";
10
+ import { isNullOrUndefined } from "node-opcua-utils";
11
+ import { DataType } from "./DataType_enum.js";
12
+ import { VariantArrayType } from "./VariantArrayType_enum.js";
13
+ export { VariantArrayType };
14
+ const warningLog = make_warningLog("variant");
15
+ const schemaVariant = buildStructuredType({
25
16
  baseType: "BaseUAObject",
26
- category: node_opcua_factory_1.FieldCategory.basic,
17
+ category: FieldCategory.basic,
27
18
  fields: [
28
19
  {
29
- defaultValue: DataType_enum_js_1.DataType.Null,
20
+ defaultValue: DataType.Null,
30
21
  documentation: "the variant type.",
31
22
  fieldType: "DataType",
32
23
  name: "dataType"
33
24
  },
34
25
  {
35
- defaultValue: VariantArrayType_enum_js_1.VariantArrayType.Scalar,
26
+ defaultValue: VariantArrayType.Scalar,
36
27
  fieldType: "VariantArrayType",
37
28
  name: "arrayType"
38
29
  },
@@ -66,9 +57,9 @@ function cloneVariantElement(dataType, value) {
66
57
  return value;
67
58
  }
68
59
  switch (dataType) {
69
- case DataType_enum_js_1.DataType.ByteString:
60
+ case DataType.ByteString:
70
61
  return Buffer.isBuffer(value) ? Buffer.from(value) : value;
71
- case DataType_enum_js_1.DataType.DateTime: {
62
+ case DataType.DateTime: {
72
63
  if (!(value instanceof Date)) {
73
64
  return value;
74
65
  }
@@ -82,41 +73,41 @@ function cloneVariantElement(dataType, value) {
82
73
  }
83
74
  return copy;
84
75
  }
85
- case DataType_enum_js_1.DataType.NodeId:
86
- case DataType_enum_js_1.DataType.ExpandedNodeId: {
76
+ case DataType.NodeId:
77
+ case DataType.ExpandedNodeId: {
87
78
  const nodeId = value;
88
- if (!(nodeId instanceof node_opcua_nodeid_1.NodeId)) {
79
+ if (!(nodeId instanceof NodeId)) {
89
80
  return value;
90
81
  }
91
82
  // a ByteString identifier is itself a Buffer and needs copying too
92
83
  const identifier = Buffer.isBuffer(nodeId.value) ? Buffer.from(nodeId.value) : nodeId.value;
93
- return new node_opcua_nodeid_1.NodeId(nodeId.identifierType, identifier, nodeId.namespace);
84
+ return new NodeId(nodeId.identifierType, identifier, nodeId.namespace);
94
85
  }
95
86
  // LocalizedText and QualifiedName are copied field by field rather than through
96
87
  // their option constructors: those default with `options.text || null`, so an
97
88
  // empty string - a perfectly valid value, and what an uncommented Condition
98
89
  // carries - would come back as null.
99
- case DataType_enum_js_1.DataType.LocalizedText: {
100
- if (!(value instanceof node_opcua_data_model_1.LocalizedText)) {
90
+ case DataType.LocalizedText: {
91
+ if (!(value instanceof LocalizedText)) {
101
92
  return value;
102
93
  }
103
- const localizedText = new node_opcua_data_model_1.LocalizedText(null);
94
+ const localizedText = new LocalizedText(null);
104
95
  localizedText.locale = value.locale;
105
96
  localizedText.text = value.text;
106
97
  return localizedText;
107
98
  }
108
- case DataType_enum_js_1.DataType.QualifiedName: {
109
- if (!(value instanceof node_opcua_data_model_1.QualifiedName)) {
99
+ case DataType.QualifiedName: {
100
+ if (!(value instanceof QualifiedName)) {
110
101
  return value;
111
102
  }
112
- const qualifiedName = new node_opcua_data_model_1.QualifiedName(null);
103
+ const qualifiedName = new QualifiedName(null);
113
104
  qualifiedName.namespaceIndex = value.namespaceIndex;
114
105
  qualifiedName.name = value.name;
115
106
  return qualifiedName;
116
107
  }
117
- case DataType_enum_js_1.DataType.Variant:
108
+ case DataType.Variant:
118
109
  return value instanceof Variant ? value.clone() : value;
119
- case DataType_enum_js_1.DataType.ExtensionObject: {
110
+ case DataType.ExtensionObject: {
120
111
  const extensionObject = value;
121
112
  return extensionObject?.constructor ? new extensionObject.constructor(value) : value;
122
113
  }
@@ -161,14 +152,14 @@ function cloneVariantValue(dataType, value) {
161
152
  /** the data types whose elements cloneVariantElement copies rather than returns as they are */
162
153
  function hasMutableElements(dataType) {
163
154
  switch (dataType) {
164
- case DataType_enum_js_1.DataType.ByteString:
165
- case DataType_enum_js_1.DataType.DateTime:
166
- case DataType_enum_js_1.DataType.NodeId:
167
- case DataType_enum_js_1.DataType.ExpandedNodeId:
168
- case DataType_enum_js_1.DataType.LocalizedText:
169
- case DataType_enum_js_1.DataType.QualifiedName:
170
- case DataType_enum_js_1.DataType.Variant:
171
- case DataType_enum_js_1.DataType.ExtensionObject:
155
+ case DataType.ByteString:
156
+ case DataType.DateTime:
157
+ case DataType.NodeId:
158
+ case DataType.ExpandedNodeId:
159
+ case DataType.LocalizedText:
160
+ case DataType.QualifiedName:
161
+ case DataType.Variant:
162
+ case DataType.ExtensionObject:
172
163
  return true;
173
164
  default:
174
165
  return false;
@@ -178,12 +169,12 @@ function _coerceVariant(variantLike) {
178
169
  const value = variantLike instanceof Variant ? variantLike : new Variant(variantLike);
179
170
  return value;
180
171
  }
181
- class Variant extends node_opcua_factory_1.BaseUAObject {
172
+ export class Variant extends BaseUAObject {
182
173
  static maxTypedArrayLength = 16 * 1024 * 1024;
183
174
  static maxArrayLength = 1 * 1024 * 1024;
184
175
  static schema = schemaVariant;
185
176
  static coerce = _coerceVariant;
186
- static computer_default_value = () => new Variant({ dataType: DataType_enum_js_1.DataType.Null });
177
+ static computer_default_value = () => new Variant({ dataType: DataType.Null });
187
178
  dataType;
188
179
  arrayType;
189
180
  // biome-ignore lint/suspicious/noExplicitAny: intentionally using any here
@@ -196,24 +187,24 @@ class Variant extends node_opcua_factory_1.BaseUAObject {
196
187
  // values via constructHook({}) + initialize_field, at ~12x the cost - which the
197
188
  // decoders pay on every value, since they overwrite these fields immediately.
198
189
  if (options === null || options === undefined) {
199
- this.dataType = DataType_enum_js_1.DataType.Null;
200
- this.arrayType = VariantArrayType_enum_js_1.VariantArrayType.Scalar;
190
+ this.dataType = DataType.Null;
191
+ this.arrayType = VariantArrayType.Scalar;
201
192
  this.value = null;
202
193
  this.dimensions = null;
203
194
  return;
204
195
  }
205
196
  const options2 = constructHook(options || {});
206
- this.dataType = DataType_enum_js_1.DataType.Null;
207
- this.arrayType = VariantArrayType_enum_js_1.VariantArrayType.Scalar;
197
+ this.dataType = DataType.Null;
198
+ this.arrayType = VariantArrayType.Scalar;
208
199
  const schema = schemaVariant;
209
200
  this.dataType = options2.dataType;
210
201
  this.arrayType = options2.arrayType;
211
- this.value = (0, node_opcua_factory_1.initialize_field)(schema.fields[2], options2.value);
202
+ this.value = initialize_field(schema.fields[2], options2.value);
212
203
  this.dimensions = options2.dimensions || null;
213
- if (this.dataType === DataType_enum_js_1.DataType.ExtensionObject) {
214
- if (this.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Scalar) {
204
+ if (this.dataType === DataType.ExtensionObject) {
205
+ if (this.arrayType === VariantArrayType.Scalar) {
215
206
  /* c8 ignore start */
216
- if (this.value && !(this.value instanceof node_opcua_factory_1.BaseUAObject)) {
207
+ if (this.value && !(this.value instanceof BaseUAObject)) {
217
208
  throw new Error(`A variant with DataType.ExtensionObject must have a ExtensionObject value.\nMake sure that you specify a valid ExtensionObject to the value options in the Variant Constructor`);
218
209
  }
219
210
  /* c8 ignore stop */
@@ -222,7 +213,7 @@ class Variant extends node_opcua_factory_1.BaseUAObject {
222
213
  if (this.value) {
223
214
  /* c8 ignore start */
224
215
  for (const e of this.value) {
225
- if (e && !(e instanceof node_opcua_factory_1.BaseUAObject)) {
216
+ if (e && !(e instanceof BaseUAObject)) {
226
217
  throw new Error("A variant with DataType.ExtensionObject must have a ExtensionObject value\nMake sure that you specify a valid ExtensionObject for all element of the value array passed to the Variant Constructor`");
227
218
  }
228
219
  }
@@ -265,18 +256,17 @@ class Variant extends node_opcua_factory_1.BaseUAObject {
265
256
  return variant;
266
257
  }
267
258
  }
268
- exports.Variant = Variant;
269
259
  Variant.prototype.schema = schemaVariant;
270
260
  function variantToString(self, _options) {
271
261
  function asString(value) {
272
262
  switch (self.dataType) {
273
- case DataType_enum_js_1.DataType.ByteString:
263
+ case DataType.ByteString:
274
264
  return value ? `0x${value.toString("hex")}` : "<null>";
275
- case DataType_enum_js_1.DataType.NodeId:
276
- return value instanceof node_opcua_nodeid_1.NodeId ? value.displayText() : value ? String(value) : "";
277
- case DataType_enum_js_1.DataType.Boolean:
265
+ case DataType.NodeId:
266
+ return value instanceof NodeId ? value.displayText() : value ? String(value) : "";
267
+ case DataType.Boolean:
278
268
  return String(value);
279
- case DataType_enum_js_1.DataType.DateTime:
269
+ case DataType.DateTime:
280
270
  return value
281
271
  ? typeof value.toISOString === "function"
282
272
  ? value.toISOString()
@@ -292,21 +282,21 @@ function variantToString(self, _options) {
292
282
  }
293
283
  return asString(value);
294
284
  }
295
- let data = VariantArrayType_enum_js_1.VariantArrayType[self.arrayType];
285
+ let data = VariantArrayType[self.arrayType];
296
286
  if (self.dimensions && self.dimensions.length >= 0) {
297
287
  data += `[ ${self.dimensions.join(",")} ]`;
298
288
  }
299
- data += `<${DataType_enum_js_1.DataType[self.dataType]}>`;
300
- if (self.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Scalar) {
289
+ data += `<${DataType[self.dataType]}>`;
290
+ if (self.arrayType === VariantArrayType.Scalar) {
301
291
  data += `, value: ${f(self.value)}`;
302
292
  }
303
- else if (self.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Array || self.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Matrix) {
293
+ else if (self.arrayType === VariantArrayType.Array || self.arrayType === VariantArrayType.Matrix) {
304
294
  if (!self.value) {
305
295
  data += ", null";
306
296
  }
307
297
  else {
308
298
  const a = [];
309
- (0, node_opcua_assert_1.assert)(Array.isArray(self.value) || self.value.buffer instanceof ArrayBuffer);
299
+ assert(Array.isArray(self.value) || self.value.buffer instanceof ArrayBuffer);
310
300
  for (let i = 0; i < Math.min(10, self.value.length); i++) {
311
301
  a[i] = self.value[i];
312
302
  }
@@ -321,26 +311,26 @@ function variantToString(self, _options) {
321
311
  /***
322
312
  * @private
323
313
  */
324
- exports.VARIANT_ARRAY_MASK = 0x80;
314
+ export const VARIANT_ARRAY_MASK = 0x80;
325
315
  /***
326
316
  * @private
327
317
  */
328
- exports.VARIANT_ARRAY_DIMENSIONS_MASK = 0x40;
318
+ export const VARIANT_ARRAY_DIMENSIONS_MASK = 0x40;
329
319
  /***
330
320
  * @private
331
321
  */
332
- exports.VARIANT_TYPE_MASK = 0x3f;
333
- const nullVariant = new Variant({ dataType: DataType_enum_js_1.DataType.Null });
322
+ export const VARIANT_TYPE_MASK = 0x3f;
323
+ const nullVariant = new Variant({ dataType: DataType.Null });
334
324
  /***
335
325
  * @private
336
326
  */
337
- function encodeVariant(variant, stream) {
327
+ export function encodeVariant(variant, stream) {
338
328
  if (!variant) {
339
329
  variant = nullVariant;
340
330
  }
341
331
  let encodingByte = variant.dataType;
342
332
  let dimensions = variant.dimensions;
343
- if (variant.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Matrix && dimensions && dimensions.length > 0) {
333
+ if (variant.arrayType === VariantArrayType.Matrix && dimensions && dimensions.length > 0) {
344
334
  // Defensive guard: an empty Matrix value (value.length === 0) combined with non-zero declared
345
335
  // dimensions would encode as a spec-violating wire form (ArraySize 0 followed by non-empty
346
336
  // ArrayDimensions whose product !== 0), which strict clients - including node-opcua's own
@@ -350,29 +340,29 @@ function encodeVariant(variant, stream) {
350
340
  dimensions = [];
351
341
  }
352
342
  }
353
- if (variant.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Array || variant.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Matrix) {
354
- encodingByte |= exports.VARIANT_ARRAY_MASK;
343
+ if (variant.arrayType === VariantArrayType.Array || variant.arrayType === VariantArrayType.Matrix) {
344
+ encodingByte |= VARIANT_ARRAY_MASK;
355
345
  }
356
- if (dimensions && variant.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Matrix) {
357
- (0, node_opcua_assert_1.assert)(dimensions.length >= 0);
358
- encodingByte |= exports.VARIANT_ARRAY_DIMENSIONS_MASK;
346
+ if (dimensions && variant.arrayType === VariantArrayType.Matrix) {
347
+ assert(dimensions.length >= 0);
348
+ encodingByte |= VARIANT_ARRAY_DIMENSIONS_MASK;
359
349
  }
360
- (0, node_opcua_basic_types_1.encodeUInt8)(encodingByte, stream);
361
- if (variant.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Array || variant.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Matrix) {
350
+ encodeUInt8(encodingByte, stream);
351
+ if (variant.arrayType === VariantArrayType.Array || variant.arrayType === VariantArrayType.Matrix) {
362
352
  encodeVariantArray(variant.dataType, stream, variant.value);
363
353
  }
364
354
  else {
365
- const encode = get_encoder(variant.dataType || DataType_enum_js_1.DataType.Null);
355
+ const encode = get_encoder(variant.dataType || DataType.Null);
366
356
  encode(variant.value, stream);
367
357
  }
368
- if ((encodingByte & exports.VARIANT_ARRAY_DIMENSIONS_MASK) === exports.VARIANT_ARRAY_DIMENSIONS_MASK && dimensions) {
358
+ if ((encodingByte & VARIANT_ARRAY_DIMENSIONS_MASK) === VARIANT_ARRAY_DIMENSIONS_MASK && dimensions) {
369
359
  encodeDimension(dimensions, stream);
370
360
  }
371
361
  }
372
362
  /* c8 ignore start */
373
363
  function _decodeVariantArrayDebug(stream, decode, tracer, dataType) {
374
364
  let cursorBefore = stream.length;
375
- const length = (0, node_opcua_basic_types_1.decodeUInt32)(stream);
365
+ const length = decodeUInt32(stream);
376
366
  let i = 0;
377
367
  let element;
378
368
  tracer.trace("start_array", "Variant", -1, cursorBefore, stream.length);
@@ -388,7 +378,7 @@ function _decodeVariantArrayDebug(stream, decode, tracer, dataType) {
388
378
  cursorBefore = stream.length;
389
379
  element = decode(stream);
390
380
  // arr.push(element);
391
- tracer.trace("member", "Variant", element, cursorBefore, stream.length, DataType_enum_js_1.DataType[dataType]);
381
+ tracer.trace("member", "Variant", element, cursorBefore, stream.length, DataType[dataType]);
392
382
  tracer.trace("end_element", "", i);
393
383
  }
394
384
  // keep reading
@@ -397,34 +387,34 @@ function _decodeVariantArrayDebug(stream, decode, tracer, dataType) {
397
387
  decode(stream);
398
388
  }
399
389
  tracer.trace("start_element", "", n1);
400
- tracer.trace("member", "Variant", "...", cursorBefore, stream.length, DataType_enum_js_1.DataType[dataType]);
390
+ tracer.trace("member", "Variant", "...", cursorBefore, stream.length, DataType[dataType]);
401
391
  tracer.trace("end_element", "", n1);
402
392
  }
403
393
  tracer.trace("end_array", "Variant", stream.length);
404
394
  }
405
395
  function decodeDebugVariant(self, stream, options) {
406
396
  const tracer = options.tracer;
407
- const encodingByte = (0, node_opcua_basic_types_1.decodeUInt8)(stream);
408
- const isArray = (encodingByte & exports.VARIANT_ARRAY_MASK) === exports.VARIANT_ARRAY_MASK;
409
- const hasDimension = (encodingByte & exports.VARIANT_ARRAY_DIMENSIONS_MASK) === exports.VARIANT_ARRAY_DIMENSIONS_MASK;
410
- self.dataType = (encodingByte & exports.VARIANT_TYPE_MASK);
397
+ const encodingByte = decodeUInt8(stream);
398
+ const isArray = (encodingByte & VARIANT_ARRAY_MASK) === VARIANT_ARRAY_MASK;
399
+ const hasDimension = (encodingByte & VARIANT_ARRAY_DIMENSIONS_MASK) === VARIANT_ARRAY_DIMENSIONS_MASK;
400
+ self.dataType = (encodingByte & VARIANT_TYPE_MASK);
411
401
  tracer.dump("dataType: ", self.dataType);
412
402
  tracer.dump("isArray: ", isArray ? "true" : "false");
413
403
  tracer.dump("dimension: ", hasDimension);
414
- const decode = (0, node_opcua_factory_1.findBuiltInType)(DataType_enum_js_1.DataType[self.dataType]).decode;
404
+ const decode = findBuiltInType(DataType[self.dataType]).decode;
415
405
  /* c8 ignore next */
416
406
  if (!decode) {
417
- throw new Error(`Variant.decode : cannot find decoder for type ${DataType_enum_js_1.DataType[self.dataType]}`);
407
+ throw new Error(`Variant.decode : cannot find decoder for type ${DataType[self.dataType]}`);
418
408
  }
419
409
  const cursorBefore = stream.length;
420
410
  if (isArray) {
421
- self.arrayType = hasDimension ? VariantArrayType_enum_js_1.VariantArrayType.Matrix : VariantArrayType_enum_js_1.VariantArrayType.Array;
411
+ self.arrayType = hasDimension ? VariantArrayType.Matrix : VariantArrayType.Array;
422
412
  _decodeVariantArrayDebug(stream, decode, tracer, self.dataType);
423
413
  }
424
414
  else {
425
- self.arrayType = VariantArrayType_enum_js_1.VariantArrayType.Scalar;
415
+ self.arrayType = VariantArrayType.Scalar;
426
416
  self.value = decode(stream);
427
- tracer.trace("member", "Variant", self.value, cursorBefore, stream.length, DataType_enum_js_1.DataType[self.dataType]);
417
+ tracer.trace("member", "Variant", self.value, cursorBefore, stream.length, DataType[self.dataType]);
428
418
  }
429
419
  // ArrayDimensions
430
420
  // Int32[]
@@ -441,16 +431,16 @@ function decodeDebugVariant(self, stream, options) {
441
431
  }
442
432
  /* c8 ignore stop */
443
433
  function internalDecodeVariant(self, stream) {
444
- const encodingByte = (0, node_opcua_basic_types_1.decodeUInt8)(stream);
445
- const isArray = (encodingByte & exports.VARIANT_ARRAY_MASK) === exports.VARIANT_ARRAY_MASK;
446
- const hasDimension = (encodingByte & exports.VARIANT_ARRAY_DIMENSIONS_MASK) === exports.VARIANT_ARRAY_DIMENSIONS_MASK;
447
- self.dataType = (encodingByte & exports.VARIANT_TYPE_MASK);
434
+ const encodingByte = decodeUInt8(stream);
435
+ const isArray = (encodingByte & VARIANT_ARRAY_MASK) === VARIANT_ARRAY_MASK;
436
+ const hasDimension = (encodingByte & VARIANT_ARRAY_DIMENSIONS_MASK) === VARIANT_ARRAY_DIMENSIONS_MASK;
437
+ self.dataType = (encodingByte & VARIANT_TYPE_MASK);
448
438
  if (isArray) {
449
- self.arrayType = hasDimension ? VariantArrayType_enum_js_1.VariantArrayType.Matrix : VariantArrayType_enum_js_1.VariantArrayType.Array;
439
+ self.arrayType = hasDimension ? VariantArrayType.Matrix : VariantArrayType.Array;
450
440
  self.value = decodeVariantArray(self.dataType, stream);
451
441
  }
452
442
  else {
453
- self.arrayType = VariantArrayType_enum_js_1.VariantArrayType.Scalar;
443
+ self.arrayType = VariantArrayType.Scalar;
454
444
  const decode = get_decoder(self.dataType);
455
445
  self.value = decode(stream);
456
446
  }
@@ -467,7 +457,7 @@ function internalDecodeVariant(self, stream) {
467
457
  /***
468
458
  * @private
469
459
  */
470
- function decodeVariant(stream, value) {
460
+ export function decodeVariant(stream, value) {
471
461
  value = value || new Variant(null);
472
462
  value.decode(stream);
473
463
  return value;
@@ -481,8 +471,8 @@ function constructHook(options) {
481
471
  dimensions: options.dimensions,
482
472
  value: options.value
483
473
  };
484
- if (opts.dataType === DataType_enum_js_1.DataType.ExtensionObject) {
485
- if (opts.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Scalar) {
474
+ if (opts.dataType === DataType.ExtensionObject) {
475
+ if (opts.arrayType === VariantArrayType.Scalar) {
486
476
  if (opts?.value?.constructor) {
487
477
  opts.value = new opts.value.constructor(opts.value);
488
478
  }
@@ -498,25 +488,25 @@ function constructHook(options) {
498
488
  }
499
489
  }
500
490
  }
501
- else if (opts.arrayType !== VariantArrayType_enum_js_1.VariantArrayType.Scalar) {
491
+ else if (opts.arrayType !== VariantArrayType.Scalar) {
502
492
  opts.value = coerceVariantArray(opts.dataType, options.value);
503
493
  }
504
494
  return opts;
505
495
  }
506
- options.dataType = options.dataType || DataType_enum_js_1.DataType.Null;
496
+ options.dataType = options.dataType || DataType.Null;
507
497
  // dataType could be a string
508
498
  if (typeof options.dataType === "string") {
509
- const d = (0, node_opcua_factory_1.findBuiltInType)(options.dataType);
499
+ const d = findBuiltInType(options.dataType);
510
500
  /* c8 ignore start */
511
501
  if (!d) {
512
502
  throw new Error(`Cannot find Built-In data type or any DataType resolving to ${options.dataType}`);
513
503
  }
514
504
  /* c8 ignore stop */
515
- options.dataType = DataType_enum_js_1.DataType[d.name];
505
+ options.dataType = DataType[d.name];
516
506
  }
517
507
  // array type could be a string
518
508
  if (typeof options.arrayType === "string") {
519
- const at = VariantArrayType_enum_js_1.VariantArrayType[options.arrayType];
509
+ const at = VariantArrayType[options.arrayType];
520
510
  /* c8 ignore start */
521
511
  if (at === undefined) {
522
512
  throw new Error(`ArrayType: invalid ${options.arrayType}`);
@@ -527,27 +517,27 @@ function constructHook(options) {
527
517
  if (isArrayTypeUnspecified && Array.isArray(options.value)) {
528
518
  // when using UInt64 ou Int64 arrayType must be specified , as automatic detection cannot be made
529
519
  /* c8 ignore start */
530
- if (options.dataType === DataType_enum_js_1.DataType.UInt64 || options.dataType === DataType_enum_js_1.DataType.Int64) {
520
+ if (options.dataType === DataType.UInt64 || options.dataType === DataType.Int64) {
531
521
  // we do nothing here ....
532
522
  throw new Error("Variant#constructor : when using UInt64 ou Int64" +
533
523
  " arrayType must be specified , as automatic detection cannot be made");
534
524
  }
535
525
  else {
536
526
  /* c8 ignore stop */
537
- options.arrayType = VariantArrayType_enum_js_1.VariantArrayType.Array;
527
+ options.arrayType = VariantArrayType.Array;
538
528
  isArrayTypeUnspecified = false;
539
529
  }
540
530
  }
541
- if (options.arrayType !== VariantArrayType_enum_js_1.VariantArrayType.Scalar && !isArrayTypeUnspecified) {
542
- (0, node_opcua_assert_1.assert)(options.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Array || options.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Matrix);
543
- if (options.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Array) {
531
+ if (options.arrayType !== VariantArrayType.Scalar && !isArrayTypeUnspecified) {
532
+ assert(options.arrayType === VariantArrayType.Array || options.arrayType === VariantArrayType.Matrix);
533
+ if (options.arrayType === VariantArrayType.Array) {
544
534
  const value1 = coerceVariantArray(options.dataType, options.value);
545
- (0, node_opcua_assert_1.assert)(value1 === null || value1 !== options.value);
535
+ assert(value1 === null || value1 !== options.value);
546
536
  options.value = value1;
547
537
  }
548
538
  else {
549
539
  /* c8 ignore start */
550
- (0, node_opcua_assert_1.assert)(options.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Matrix);
540
+ assert(options.arrayType === VariantArrayType.Matrix);
551
541
  options.value = options.value || [];
552
542
  options.value = coerceVariantArray(options.dataType, options.value);
553
543
  if (!options.dimensions) {
@@ -560,19 +550,19 @@ function constructHook(options) {
560
550
  /* c8 ignore stop */
561
551
  }
562
552
  else {
563
- (0, node_opcua_assert_1.assert)(options.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Scalar || options.arrayType === undefined);
564
- options.arrayType = VariantArrayType_enum_js_1.VariantArrayType.Scalar;
553
+ assert(options.arrayType === VariantArrayType.Scalar || options.arrayType === undefined);
554
+ options.arrayType = VariantArrayType.Scalar;
565
555
  const _tmp = options.value;
566
556
  // scalar
567
557
  options.value = coerceVariantType(options.dataType, options.value);
568
558
  /* c8 ignore start */
569
559
  if (!isValidVariant(options.arrayType, options.dataType, options.value, null)) {
570
- throw new Error(`Invalid variant arrayType: ${VariantArrayType_enum_js_1.VariantArrayType[options.arrayType]} dataType: ${DataType_enum_js_1.DataType[options.dataType]} value:${options.value} (javascript type = ${typeof options.value} )`);
560
+ throw new Error(`Invalid variant arrayType: ${VariantArrayType[options.arrayType]} dataType: ${DataType[options.dataType]} value:${options.value} (javascript type = ${typeof options.value} )`);
571
561
  }
572
562
  /* c8 ignore stop */
573
563
  }
574
564
  if (options.dimensions) {
575
- (0, node_opcua_assert_1.assert)(options.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Matrix, "dimension can only provided if variant is a matrix");
565
+ assert(options.arrayType === VariantArrayType.Matrix, "dimension can only provided if variant is a matrix");
576
566
  }
577
567
  return options;
578
568
  }
@@ -596,7 +586,7 @@ function calculate_product(array) {
596
586
  const encoderTable = new Array(64);
597
587
  const decoderTable = new Array(64);
598
588
  // registerType/unregisterType are public API, so a memoised function can go stale.
599
- (0, node_opcua_factory_1.onBuiltInTypeRegistryChanged)(() => {
589
+ onBuiltInTypeRegistryChanged(() => {
600
590
  encoderTable.fill(undefined);
601
591
  decoderTable.fill(undefined);
602
592
  });
@@ -613,11 +603,11 @@ function get_encoder(dataType) {
613
603
  }
614
604
  // a hand-built Variant may carry a string dataType; the constructor normalises it,
615
605
  // so this is a fallback rather than a hot path, and it is deliberately not memoised.
616
- const dataTypeAsString = typeof dataType === "string" ? dataType : DataType_enum_js_1.DataType[dataType];
606
+ const dataTypeAsString = typeof dataType === "string" ? dataType : DataType[dataType];
617
607
  if (!dataTypeAsString) {
618
608
  throw new Error(`Variant.encode : invalid dataType ${dataType}`);
619
609
  }
620
- const encode = (0, node_opcua_factory_1.findBuiltInType)(dataTypeAsString).encode;
610
+ const encode = findBuiltInType(dataTypeAsString).encode;
621
611
  /* c8 ignore start */
622
612
  if (!encode) {
623
613
  throw new Error(`Cannot find encode function for dataType ${dataTypeAsString}`);
@@ -636,14 +626,14 @@ function get_decoder(dataType) {
636
626
  return cached;
637
627
  }
638
628
  }
639
- const dataTypeAsString = DataType_enum_js_1.DataType[dataType];
629
+ const dataTypeAsString = DataType[dataType];
640
630
  // the wire carries 6 bits of DataType but only 0..25 are defined: reject the rest
641
631
  // with a real Error, so "bad input from the peer" stays distinguishable from a
642
632
  // TypeError raised by calling an undefined table entry.
643
633
  if (!dataTypeAsString) {
644
634
  throw new Error(`Variant.decode : cannot find decoder for type ${dataType}`);
645
635
  }
646
- const decode = (0, node_opcua_factory_1.findBuiltInType)(dataTypeAsString).decode;
636
+ const decode = findBuiltInType(dataTypeAsString).decode;
647
637
  /* c8 ignore start */
648
638
  if (!decode) {
649
639
  throw new Error(`Variant.decode : cannot find decoder for type ${dataTypeAsString}`);
@@ -674,7 +664,7 @@ function convertTo(dataType, arrayTypeConstructor, value) {
674
664
  }
675
665
  // c8 ignore next
676
666
  if (arrayTypeConstructor && displayWarning && n > 10) {
677
- warningLog(`Warning ! an array containing ${DataType_enum_js_1.DataType[dataType]} elements has been provided as a generic array. `);
667
+ warningLog(`Warning ! an array containing ${DataType[dataType]} elements has been provided as a generic array. `);
678
668
  warningLog(" This is inefficient as every array value will have to be coerced and verified against the expected type");
679
669
  warningLog(" It is highly recommended that you use a typed array ", arrayTypeConstructor.constructor.name, " instead");
680
670
  }
@@ -706,18 +696,18 @@ function coerceVariantArray(dataType, value) {
706
696
  }
707
697
  function encodeTypedArray(arrayTypeConstructor, stream, value) {
708
698
  const typedValue = value;
709
- (0, node_opcua_assert_1.assert)(typedValue instanceof arrayTypeConstructor);
710
- (0, node_opcua_assert_1.assert)(typedValue.buffer instanceof ArrayBuffer);
711
- (0, node_opcua_basic_types_1.encodeUInt32)(typedValue.length, stream);
699
+ assert(typedValue instanceof arrayTypeConstructor);
700
+ assert(typedValue.buffer instanceof ArrayBuffer);
701
+ encodeUInt32(typedValue.length, stream);
712
702
  stream.writeArrayBuffer(typedValue.buffer, typedValue.byteOffset, typedValue.byteLength);
713
703
  }
714
704
  function encodeGeneralArray(dataType, stream, value) {
715
705
  if (!value) {
716
- (0, node_opcua_assert_1.assert)(value === null);
717
- (0, node_opcua_basic_types_1.encodeUInt32)(0xffffffff, stream);
706
+ assert(value === null);
707
+ encodeUInt32(0xffffffff, stream);
718
708
  return;
719
709
  }
720
- (0, node_opcua_basic_types_1.encodeUInt32)(value.length, stream);
710
+ encodeUInt32(value.length, stream);
721
711
  const encode = get_encoder(dataType);
722
712
  for (const e of value) {
723
713
  encode(e, stream);
@@ -736,7 +726,7 @@ function encodeVariantArray(dataType, stream, value) {
736
726
  return encodeGeneralArray(dataType, stream, value);
737
727
  }
738
728
  function decodeTypedArray(arrayTypeConstructor, stream) {
739
- const length = (0, node_opcua_basic_types_1.decodeUInt32)(stream);
729
+ const length = decodeUInt32(stream);
740
730
  /* c8 ignore next */
741
731
  if (length === 0xffffffff) {
742
732
  return null;
@@ -753,7 +743,7 @@ function decodeTypedArray(arrayTypeConstructor, stream) {
753
743
  return new arrayTypeConstructor(copy.buffer, copy.byteOffset, length);
754
744
  }
755
745
  function decodeGeneralArray(dataType, stream) {
756
- const length = (0, node_opcua_basic_types_1.decodeUInt32)(stream);
746
+ const length = decodeUInt32(stream);
757
747
  /* c8 ignore next */
758
748
  if (length === 0xffffffff) {
759
749
  return null;
@@ -784,19 +774,19 @@ function _declareTypeArrayHelper(dataType, typedArrayConstructor) {
784
774
  encode: encodeTypedArray.bind(null, typedArrayConstructor)
785
775
  };
786
776
  }
787
- _declareTypeArrayHelper(DataType_enum_js_1.DataType.Float, Float32Array);
788
- _declareTypeArrayHelper(DataType_enum_js_1.DataType.Double, Float64Array);
789
- _declareTypeArrayHelper(DataType_enum_js_1.DataType.SByte, Int8Array);
790
- _declareTypeArrayHelper(DataType_enum_js_1.DataType.Byte, Uint8Array);
791
- _declareTypeArrayHelper(DataType_enum_js_1.DataType.Int16, Int16Array);
792
- _declareTypeArrayHelper(DataType_enum_js_1.DataType.Int32, Int32Array);
793
- _declareTypeArrayHelper(DataType_enum_js_1.DataType.UInt16, Uint16Array);
794
- _declareTypeArrayHelper(DataType_enum_js_1.DataType.UInt32, Uint32Array);
777
+ _declareTypeArrayHelper(DataType.Float, Float32Array);
778
+ _declareTypeArrayHelper(DataType.Double, Float64Array);
779
+ _declareTypeArrayHelper(DataType.SByte, Int8Array);
780
+ _declareTypeArrayHelper(DataType.Byte, Uint8Array);
781
+ _declareTypeArrayHelper(DataType.Int16, Int16Array);
782
+ _declareTypeArrayHelper(DataType.Int32, Int32Array);
783
+ _declareTypeArrayHelper(DataType.UInt16, Uint16Array);
784
+ _declareTypeArrayHelper(DataType.UInt32, Uint32Array);
795
785
  function decodeDimension(stream) {
796
- return decodeGeneralArray(DataType_enum_js_1.DataType.UInt32, stream);
786
+ return decodeGeneralArray(DataType.UInt32, stream);
797
787
  }
798
788
  function encodeDimension(dimensions, stream) {
799
- return encodeGeneralArray(DataType_enum_js_1.DataType.UInt32, stream, dimensions);
789
+ return encodeGeneralArray(DataType.UInt32, stream, dimensions);
800
790
  }
801
791
  function isEnumerationItem(value) {
802
792
  return (value instanceof Object &&
@@ -805,7 +795,7 @@ function isEnumerationItem(value) {
805
795
  value.constructor.name === "EnumValueType");
806
796
  }
807
797
  // biome-ignore lint/suspicious/noExplicitAny: intentional
808
- function coerceVariantType(dataType, value) {
798
+ export function coerceVariantType(dataType, value) {
809
799
  /* eslint max-statements: ["error",1000], complexity: ["error",1000]*/
810
800
  if (value === undefined) {
811
801
  value = null;
@@ -814,30 +804,30 @@ function coerceVariantType(dataType, value) {
814
804
  if (isEnumerationItem(value)) {
815
805
  // OPCUA Specification 1.0.3 5.8.2 encoding rules for various dataType:
816
806
  // [...]Enumeration are always encoded as Int32 on the wire [...]
817
- if (dataType !== DataType_enum_js_1.DataType.Int32 && dataType !== DataType_enum_js_1.DataType.ExtensionObject) {
807
+ if (dataType !== DataType.Int32 && dataType !== DataType.ExtensionObject) {
818
808
  throw new Error(`expecting DataType.Int32 for enumeration values ; got DataType.${dataType.toString()} instead`);
819
809
  }
820
810
  }
821
811
  /* c8 ignore stop */
822
812
  switch (dataType) {
823
- case DataType_enum_js_1.DataType.Null:
813
+ case DataType.Null:
824
814
  value = null;
825
815
  break;
826
- case DataType_enum_js_1.DataType.LocalizedText:
827
- if (!value?.schema || value.schema !== node_opcua_data_model_1.LocalizedText.schema) {
828
- value = new node_opcua_data_model_1.LocalizedText(value);
816
+ case DataType.LocalizedText:
817
+ if (!value?.schema || value.schema !== LocalizedText.schema) {
818
+ value = new LocalizedText(value);
829
819
  }
830
820
  break;
831
- case DataType_enum_js_1.DataType.QualifiedName:
832
- if (!value?.schema || value.schema !== node_opcua_data_model_1.QualifiedName.schema) {
833
- value = new node_opcua_data_model_1.QualifiedName(value);
821
+ case DataType.QualifiedName:
822
+ if (!value?.schema || value.schema !== QualifiedName.schema) {
823
+ value = new QualifiedName(value);
834
824
  }
835
825
  break;
836
- case DataType_enum_js_1.DataType.Int32:
837
- case DataType_enum_js_1.DataType.Int16:
838
- case DataType_enum_js_1.DataType.UInt32:
839
- case DataType_enum_js_1.DataType.UInt16:
840
- (0, node_opcua_assert_1.assert)(value !== undefined);
826
+ case DataType.Int32:
827
+ case DataType.Int16:
828
+ case DataType.UInt32:
829
+ case DataType.UInt16:
830
+ assert(value !== undefined);
841
831
  value = parseInt(value, 10);
842
832
  /* c8 ignore start */
843
833
  if (!Number.isFinite(value)) {
@@ -845,69 +835,69 @@ function coerceVariantType(dataType, value) {
845
835
  }
846
836
  /* c8 ignore stop */
847
837
  break;
848
- case DataType_enum_js_1.DataType.UInt64:
849
- value = (0, node_opcua_basic_types_1.coerceUInt64)(value);
838
+ case DataType.UInt64:
839
+ value = coerceUInt64(value);
850
840
  break;
851
- case DataType_enum_js_1.DataType.Int64:
852
- value = (0, node_opcua_basic_types_1.coerceInt64)(value);
841
+ case DataType.Int64:
842
+ value = coerceInt64(value);
853
843
  break;
854
- case DataType_enum_js_1.DataType.ExtensionObject:
844
+ case DataType.ExtensionObject:
855
845
  break;
856
- case DataType_enum_js_1.DataType.DateTime:
857
- (0, node_opcua_assert_1.assert)(value === null || !!value.getTime);
846
+ case DataType.DateTime:
847
+ assert(value === null || !!value.getTime);
858
848
  break;
859
- case DataType_enum_js_1.DataType.String:
860
- (0, node_opcua_assert_1.assert)(typeof value === "string" || value === null);
849
+ case DataType.String:
850
+ assert(typeof value === "string" || value === null);
861
851
  break;
862
- case DataType_enum_js_1.DataType.ByteString:
852
+ case DataType.ByteString:
863
853
  value = typeof value === "string" ? Buffer.from(value) : value;
864
854
  /* c8 ignore start */
865
855
  if (!(value === null || value instanceof Buffer)) {
866
856
  throw new Error("ByteString should be null or a Buffer");
867
857
  }
868
858
  /* c8 ignore stop */
869
- (0, node_opcua_assert_1.assert)(value === null || value instanceof Buffer);
859
+ assert(value === null || value instanceof Buffer);
870
860
  break;
871
861
  default:
872
- (0, node_opcua_assert_1.assert)(dataType !== undefined && dataType !== null, "Invalid DataType");
862
+ assert(dataType !== undefined && dataType !== null, "Invalid DataType");
873
863
  break;
874
864
  }
875
865
  return value;
876
866
  }
877
867
  // biome-ignore lint/suspicious/noExplicitAny: intentionally using an y here
878
868
  function isValidScalarVariant(dataType, value) {
879
- (0, node_opcua_assert_1.assert)(value === null ||
880
- DataType_enum_js_1.DataType.Int64 === dataType ||
881
- DataType_enum_js_1.DataType.ByteString === dataType ||
882
- DataType_enum_js_1.DataType.UInt64 === dataType ||
869
+ assert(value === null ||
870
+ DataType.Int64 === dataType ||
871
+ DataType.ByteString === dataType ||
872
+ DataType.UInt64 === dataType ||
883
873
  !Array.isArray(value));
884
- (0, node_opcua_assert_1.assert)(value === null || !(value instanceof Int32Array));
885
- (0, node_opcua_assert_1.assert)(value === null || !(value instanceof Uint32Array));
874
+ assert(value === null || !(value instanceof Int32Array));
875
+ assert(value === null || !(value instanceof Uint32Array));
886
876
  switch (dataType) {
887
- case DataType_enum_js_1.DataType.NodeId:
888
- return (0, node_opcua_basic_types_1.isValidNodeId)(value);
889
- case DataType_enum_js_1.DataType.String:
890
- return typeof value === "string" || (0, node_opcua_utils_1.isNullOrUndefined)(value);
891
- case DataType_enum_js_1.DataType.Int64:
892
- return (0, node_opcua_basic_types_1.isValidInt64)(value);
893
- case DataType_enum_js_1.DataType.UInt64:
894
- return (0, node_opcua_basic_types_1.isValidUInt64)(value);
895
- case DataType_enum_js_1.DataType.UInt32:
896
- return (0, node_opcua_basic_types_1.isValidUInt32)(value);
897
- case DataType_enum_js_1.DataType.Int32:
898
- return (0, node_opcua_basic_types_1.isValidInt32)(value);
899
- case DataType_enum_js_1.DataType.UInt16:
900
- return (0, node_opcua_basic_types_1.isValidUInt16)(value);
901
- case DataType_enum_js_1.DataType.Int16:
902
- return (0, node_opcua_basic_types_1.isValidInt16)(value);
903
- case DataType_enum_js_1.DataType.Byte:
904
- return (0, node_opcua_basic_types_1.isValidUInt8)(value);
905
- case DataType_enum_js_1.DataType.SByte:
906
- return (0, node_opcua_basic_types_1.isValidInt8)(value);
907
- case DataType_enum_js_1.DataType.Boolean:
908
- return (0, node_opcua_basic_types_1.isValidBoolean)(value);
909
- case DataType_enum_js_1.DataType.ByteString:
910
- return (0, node_opcua_basic_types_1.isValidByteString)(value);
877
+ case DataType.NodeId:
878
+ return isValidNodeId(value);
879
+ case DataType.String:
880
+ return typeof value === "string" || isNullOrUndefined(value);
881
+ case DataType.Int64:
882
+ return isValidInt64(value);
883
+ case DataType.UInt64:
884
+ return isValidUInt64(value);
885
+ case DataType.UInt32:
886
+ return isValidUInt32(value);
887
+ case DataType.Int32:
888
+ return isValidInt32(value);
889
+ case DataType.UInt16:
890
+ return isValidUInt16(value);
891
+ case DataType.Int16:
892
+ return isValidInt16(value);
893
+ case DataType.Byte:
894
+ return isValidUInt8(value);
895
+ case DataType.SByte:
896
+ return isValidInt8(value);
897
+ case DataType.Boolean:
898
+ return isValidBoolean(value);
899
+ case DataType.ByteString:
900
+ return isValidByteString(value);
911
901
  default:
912
902
  return true;
913
903
  }
@@ -917,32 +907,32 @@ function isValidArrayVariant(dataType, value) {
917
907
  if (value === null) {
918
908
  return true;
919
909
  }
920
- if (dataType === DataType_enum_js_1.DataType.Float && value instanceof Float32Array) {
910
+ if (dataType === DataType.Float && value instanceof Float32Array) {
921
911
  return true;
922
912
  }
923
- else if (dataType === DataType_enum_js_1.DataType.Double && value instanceof Float64Array) {
913
+ else if (dataType === DataType.Double && value instanceof Float64Array) {
924
914
  return true;
925
915
  }
926
- else if (dataType === DataType_enum_js_1.DataType.SByte && value instanceof Int8Array) {
916
+ else if (dataType === DataType.SByte && value instanceof Int8Array) {
927
917
  return true;
928
918
  }
929
- else if (dataType === DataType_enum_js_1.DataType.Byte && (value instanceof Buffer || value instanceof Uint8Array)) {
919
+ else if (dataType === DataType.Byte && (value instanceof Buffer || value instanceof Uint8Array)) {
930
920
  return true;
931
921
  }
932
- else if (dataType === DataType_enum_js_1.DataType.Int16 && value instanceof Int16Array) {
922
+ else if (dataType === DataType.Int16 && value instanceof Int16Array) {
933
923
  return true;
934
924
  }
935
- else if (dataType === DataType_enum_js_1.DataType.Int32 && value instanceof Int32Array) {
925
+ else if (dataType === DataType.Int32 && value instanceof Int32Array) {
936
926
  return true;
937
927
  }
938
- else if (dataType === DataType_enum_js_1.DataType.UInt16 && value instanceof Uint16Array) {
928
+ else if (dataType === DataType.UInt16 && value instanceof Uint16Array) {
939
929
  return true;
940
930
  }
941
- else if (dataType === DataType_enum_js_1.DataType.UInt32 && value instanceof Uint32Array) {
931
+ else if (dataType === DataType.UInt32 && value instanceof Uint32Array) {
942
932
  return true;
943
933
  }
944
934
  // array values can be store in Buffer, Float32Array
945
- (0, node_opcua_assert_1.assert)(Array.isArray(value));
935
+ assert(Array.isArray(value));
946
936
  for (const valueItem of value) {
947
937
  if (!isValidScalarVariant(dataType, valueItem)) {
948
938
  return false;
@@ -962,42 +952,42 @@ function isValidMatrixVariant(dataType, value, dimensions) {
962
952
  return true;
963
953
  }
964
954
  /* c8 ignore stop */
965
- function isValidVariant(arrayType, dataType, value, dimensions) {
955
+ export function isValidVariant(arrayType, dataType, value, dimensions) {
966
956
  switch (arrayType) {
967
- case VariantArrayType_enum_js_1.VariantArrayType.Scalar:
957
+ case VariantArrayType.Scalar:
968
958
  return isValidScalarVariant(dataType, value);
969
- case VariantArrayType_enum_js_1.VariantArrayType.Array:
959
+ case VariantArrayType.Array:
970
960
  return isValidArrayVariant(dataType, value);
971
961
  default:
972
- (0, node_opcua_assert_1.assert)(arrayType === VariantArrayType_enum_js_1.VariantArrayType.Matrix);
962
+ assert(arrayType === VariantArrayType.Matrix);
973
963
  return isValidMatrixVariant(dataType, value, dimensions ?? null);
974
964
  }
975
965
  }
976
- function buildVariantArray(dataType, nbElements, defaultValue) {
966
+ export function buildVariantArray(dataType, nbElements, defaultValue) {
977
967
  let value;
978
968
  switch (dataType) {
979
- case DataType_enum_js_1.DataType.Float:
969
+ case DataType.Float:
980
970
  value = new Float32Array(nbElements);
981
971
  break;
982
- case DataType_enum_js_1.DataType.Double:
972
+ case DataType.Double:
983
973
  value = new Float64Array(nbElements);
984
974
  break;
985
- case DataType_enum_js_1.DataType.UInt32:
975
+ case DataType.UInt32:
986
976
  value = new Uint32Array(nbElements);
987
977
  break;
988
- case DataType_enum_js_1.DataType.Int32:
978
+ case DataType.Int32:
989
979
  value = new Int32Array(nbElements);
990
980
  break;
991
- case DataType_enum_js_1.DataType.UInt16:
981
+ case DataType.UInt16:
992
982
  value = new Uint16Array(nbElements);
993
983
  break;
994
- case DataType_enum_js_1.DataType.Int16:
984
+ case DataType.Int16:
995
985
  value = new Int16Array(nbElements);
996
986
  break;
997
- case DataType_enum_js_1.DataType.Byte:
987
+ case DataType.Byte:
998
988
  value = new Uint8Array(nbElements);
999
989
  break;
1000
- case DataType_enum_js_1.DataType.SByte:
990
+ case DataType.SByte:
1001
991
  value = new Int8Array(nbElements);
1002
992
  break;
1003
993
  default:
@@ -1083,7 +1073,7 @@ function __check_same_array(arr1, arr2) {
1083
1073
  if (!oldNodeVersion && arr1.buffer) {
1084
1074
  // v1 and v2 are TypedArray (such as Int32Array...)
1085
1075
  // this is the most efficient way to compare 2 buffers but it doesn't work with node <= 0.12
1086
- (0, node_opcua_assert_1.assert)(arr2.buffer && __type(arr2.buffer) === "[object ArrayBuffer]");
1076
+ assert(arr2.buffer && __type(arr2.buffer) === "[object ArrayBuffer]");
1087
1077
  // compare byte by byte
1088
1078
  const b1 = Buffer.from(arr1.buffer, arr1.byteOffset, arr1.byteLength);
1089
1079
  const b2 = Buffer.from(arr2.buffer, arr2.byteOffset, arr2.byteLength);
@@ -1102,7 +1092,7 @@ function __check_same_array(arr1, arr2) {
1102
1092
  * @param v1 the first variant to compare
1103
1093
  * @param v2 the variant to compare with
1104
1094
  */
1105
- function sameVariant(v1, v2) {
1095
+ export function sameVariant(v1, v2) {
1106
1096
  if (v1 === v2) {
1107
1097
  return true;
1108
1098
  }
@@ -1118,8 +1108,8 @@ function sameVariant(v1, v2) {
1118
1108
  if (v1.value === v2.value) {
1119
1109
  return true;
1120
1110
  }
1121
- if (v1.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Scalar) {
1122
- if (v1.dataType === DataType_enum_js_1.DataType.ExtensionObject) {
1111
+ if (v1.arrayType === VariantArrayType.Scalar) {
1112
+ if (v1.dataType === DataType.ExtensionObject) {
1123
1113
  // compare two extension objects
1124
1114
  return __check_same_object(v1.value, v2.value);
1125
1115
  }
@@ -1138,10 +1128,10 @@ function sameVariant(v1, v2) {
1138
1128
  return __check_same_object(v1.value, v2.value);
1139
1129
  }
1140
1130
  }
1141
- if (v1.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Array) {
1131
+ if (v1.arrayType === VariantArrayType.Array) {
1142
1132
  return __check_same_array(v1.value, v2.value);
1143
1133
  }
1144
- else if (v1.arrayType === VariantArrayType_enum_js_1.VariantArrayType.Matrix) {
1134
+ else if (v1.arrayType === VariantArrayType.Matrix) {
1145
1135
  if (!__check_same_array(v1.dimensions, v2.dimensions)) {
1146
1136
  return false;
1147
1137
  }
@@ -1150,8 +1140,8 @@ function sameVariant(v1, v2) {
1150
1140
  return false;
1151
1141
  }
1152
1142
  // ---------------------------------------------------------------------------------------------------------
1153
- (0, node_opcua_factory_1.registerSpecialVariantEncoder)(Variant);
1154
- (0, node_opcua_factory_1.registerType)({
1143
+ registerSpecialVariantEncoder(Variant);
1144
+ registerType({
1155
1145
  name: "Variant",
1156
1146
  subType: "",
1157
1147
  coerce: _coerceVariant,