opcjs-base 0.1.34-alpha → 0.1.36-alpha

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/index.d.cts CHANGED
@@ -1197,14 +1197,30 @@ declare class Variant {
1197
1197
  */
1198
1198
  toString(): string;
1199
1199
  /**
1200
- * Union of all OPC UA built-in types accepted by {@link Variant.newFrom}.
1200
+ * Creates a {@link Variant} from any OPC UA built-in scalar value or a
1201
+ * homogeneous array of such values.
1201
1202
  *
1202
- * Includes both the tagged numeric primitives from `UaPrimitive` (which carry
1203
- * a `BuiltInType` discriminant so the exact numeric encoding is known) and the
1204
- * class-based built-in types that are identified unambiguously at runtime via
1205
- * `instanceof`.
1203
+ * **Scalar usage** pass any concrete OPC UA type and the BuiltInType is
1204
+ * inferred automatically:
1205
+ * ```ts
1206
+ * Variant.newFrom('hello') // String
1207
+ * Variant.newFrom(uaDouble(3.14)) // Double
1208
+ * Variant.newFrom(new LocalizedText('en', 'Hi'))
1209
+ * ```
1210
+ *
1211
+ * **Array usage** — pass a plain JS array of a single homogeneous element type:
1212
+ * ```ts
1213
+ * Variant.newFrom([uaDouble(1.0), uaDouble(2.0)]) // Double[]
1214
+ * Variant.newFrom([new LocalizedText('en', 'A'), ...]) // LocalizedText[]
1215
+ * ```
1216
+ *
1217
+ * Throws if the array is empty (element type cannot be inferred), if the
1218
+ * first element is null/undefined, or if elements have mixed types.
1219
+ *
1220
+ * Note: `Variant` itself is excluded from the accepted types intentionally —
1221
+ * callers should work with concrete OPC UA types.
1206
1222
  */
1207
- static newFrom(value: UaPrimitive | NodeId | ExpandedNodeId | QualifiedName | LocalizedText | XmlElement | ExtensionObject | DataValue | DiagnosticInfo | Variant | null | undefined): Variant;
1223
+ static newFrom(value: UaPrimitive | NodeId | ExpandedNodeId | QualifiedName | LocalizedText | XmlElement | ExtensionObject | DataValue | DiagnosticInfo | null | undefined | UaPrimitive[] | NodeId[] | ExpandedNodeId[] | QualifiedName[] | LocalizedText[] | XmlElement[] | ExtensionObject[] | DataValue[] | DiagnosticInfo[]): Variant;
1208
1224
  /**
1209
1225
  * Creates a undefined variant.
1210
1226
  *
package/dist/index.d.ts CHANGED
@@ -1197,14 +1197,30 @@ declare class Variant {
1197
1197
  */
1198
1198
  toString(): string;
1199
1199
  /**
1200
- * Union of all OPC UA built-in types accepted by {@link Variant.newFrom}.
1200
+ * Creates a {@link Variant} from any OPC UA built-in scalar value or a
1201
+ * homogeneous array of such values.
1201
1202
  *
1202
- * Includes both the tagged numeric primitives from `UaPrimitive` (which carry
1203
- * a `BuiltInType` discriminant so the exact numeric encoding is known) and the
1204
- * class-based built-in types that are identified unambiguously at runtime via
1205
- * `instanceof`.
1203
+ * **Scalar usage** pass any concrete OPC UA type and the BuiltInType is
1204
+ * inferred automatically:
1205
+ * ```ts
1206
+ * Variant.newFrom('hello') // String
1207
+ * Variant.newFrom(uaDouble(3.14)) // Double
1208
+ * Variant.newFrom(new LocalizedText('en', 'Hi'))
1209
+ * ```
1210
+ *
1211
+ * **Array usage** — pass a plain JS array of a single homogeneous element type:
1212
+ * ```ts
1213
+ * Variant.newFrom([uaDouble(1.0), uaDouble(2.0)]) // Double[]
1214
+ * Variant.newFrom([new LocalizedText('en', 'A'), ...]) // LocalizedText[]
1215
+ * ```
1216
+ *
1217
+ * Throws if the array is empty (element type cannot be inferred), if the
1218
+ * first element is null/undefined, or if elements have mixed types.
1219
+ *
1220
+ * Note: `Variant` itself is excluded from the accepted types intentionally —
1221
+ * callers should work with concrete OPC UA types.
1206
1222
  */
1207
- static newFrom(value: UaPrimitive | NodeId | ExpandedNodeId | QualifiedName | LocalizedText | XmlElement | ExtensionObject | DataValue | DiagnosticInfo | Variant | null | undefined): Variant;
1223
+ static newFrom(value: UaPrimitive | NodeId | ExpandedNodeId | QualifiedName | LocalizedText | XmlElement | ExtensionObject | DataValue | DiagnosticInfo | null | undefined | UaPrimitive[] | NodeId[] | ExpandedNodeId[] | QualifiedName[] | LocalizedText[] | XmlElement[] | ExtensionObject[] | DataValue[] | DiagnosticInfo[]): Variant;
1208
1224
  /**
1209
1225
  * Creates a undefined variant.
1210
1226
  *
package/dist/index.js CHANGED
@@ -1862,6 +1862,25 @@ var DiagnosticInfo = class _DiagnosticInfo {
1862
1862
  };
1863
1863
 
1864
1864
  // src/types/variant.ts
1865
+ function inferBuiltInType(element) {
1866
+ if (typeof element === "boolean") return { type: 1 /* Boolean */, rawValue: element };
1867
+ if (typeof element === "string") return { type: 12 /* String */, rawValue: element };
1868
+ if (element instanceof Uint8Array) return { type: 15 /* ByteString */, rawValue: element };
1869
+ if (element instanceof Date) return { type: 13 /* DateTime */, rawValue: element };
1870
+ if (element instanceof ExpandedNodeId) return { type: 18 /* ExpandedNodeId */, rawValue: element };
1871
+ if (element instanceof NodeId) return { type: 17 /* NodeId */, rawValue: element };
1872
+ if (element instanceof QualifiedName) return { type: 20 /* QualifiedName */, rawValue: element };
1873
+ if (element instanceof LocalizedText) return { type: 21 /* LocalizedText */, rawValue: element };
1874
+ if (element instanceof XmlElement) return { type: 16 /* XmlElement */, rawValue: element };
1875
+ if (element instanceof ExtensionObject) return { type: 22 /* ExtensionObject */, rawValue: element };
1876
+ if (element instanceof DataValue) return { type: 23 /* DataValue */, rawValue: element };
1877
+ if (element instanceof DiagnosticInfo) return { type: 25 /* DiagnosticInfo */, rawValue: element };
1878
+ if (typeof element === "object" && element !== null && "type" in element) {
1879
+ const tagged = element;
1880
+ return { type: tagged.type, rawValue: tagged.value };
1881
+ }
1882
+ throw new Error(`newFrom: unhandled array element: ${JSON.stringify(element)}`);
1883
+ }
1865
1884
  var Variant = class _Variant {
1866
1885
  /**
1867
1886
  * The variant type identifier.
@@ -1954,14 +1973,55 @@ var Variant = class _Variant {
1954
1973
  return `Variant(${typeName}: ${String(this.value)})`;
1955
1974
  }
1956
1975
  /**
1957
- * Union of all OPC UA built-in types accepted by {@link Variant.newFrom}.
1976
+ * Creates a {@link Variant} from any OPC UA built-in scalar value or a
1977
+ * homogeneous array of such values.
1978
+ *
1979
+ * **Scalar usage** — pass any concrete OPC UA type and the BuiltInType is
1980
+ * inferred automatically:
1981
+ * ```ts
1982
+ * Variant.newFrom('hello') // String
1983
+ * Variant.newFrom(uaDouble(3.14)) // Double
1984
+ * Variant.newFrom(new LocalizedText('en', 'Hi'))
1985
+ * ```
1986
+ *
1987
+ * **Array usage** — pass a plain JS array of a single homogeneous element type:
1988
+ * ```ts
1989
+ * Variant.newFrom([uaDouble(1.0), uaDouble(2.0)]) // Double[]
1990
+ * Variant.newFrom([new LocalizedText('en', 'A'), ...]) // LocalizedText[]
1991
+ * ```
1992
+ *
1993
+ * Throws if the array is empty (element type cannot be inferred), if the
1994
+ * first element is null/undefined, or if elements have mixed types.
1958
1995
  *
1959
- * Includes both the tagged numeric primitives from `UaPrimitive` (which carry
1960
- * a `BuiltInType` discriminant so the exact numeric encoding is known) and the
1961
- * class-based built-in types that are identified unambiguously at runtime via
1962
- * `instanceof`.
1996
+ * Note: `Variant` itself is excluded from the accepted types intentionally —
1997
+ * callers should work with concrete OPC UA types.
1963
1998
  */
1964
1999
  static newFrom(value) {
2000
+ if (Array.isArray(value)) {
2001
+ if (value.length === 0) {
2002
+ throw new Error(
2003
+ "newFrom: cannot create an array Variant from an empty array \u2014 the element type cannot be inferred. Use new Variant(type, []) directly."
2004
+ );
2005
+ }
2006
+ const firstElement = value[0];
2007
+ if (firstElement === null || firstElement === void 0) {
2008
+ throw new Error(
2009
+ "newFrom: the first array element must not be null or undefined \u2014 the element type cannot be inferred."
2010
+ );
2011
+ }
2012
+ const { type } = inferBuiltInType(firstElement);
2013
+ const rawValues = value.map((el, index) => {
2014
+ if (el === null || el === void 0) return el;
2015
+ const { type: elType, rawValue } = inferBuiltInType(el);
2016
+ if (elType !== type) {
2017
+ throw new Error(
2018
+ `newFrom: mixed-type arrays are not supported. Expected ${BuiltInType[type]} but got ${BuiltInType[elType]} at index ${index}.`
2019
+ );
2020
+ }
2021
+ return rawValue;
2022
+ });
2023
+ return new _Variant(type, rawValues);
2024
+ }
1965
2025
  if (value === null || value === void 0) {
1966
2026
  return _Variant.newNull();
1967
2027
  }
@@ -2001,9 +2061,6 @@ var Variant = class _Variant {
2001
2061
  if (value instanceof DiagnosticInfo) {
2002
2062
  return new _Variant(25 /* DiagnosticInfo */, value);
2003
2063
  }
2004
- if (value instanceof _Variant) {
2005
- return new _Variant(24 /* Variant */, value);
2006
- }
2007
2064
  if (typeof value === "object" && "type" in value) {
2008
2065
  const tagged = value;
2009
2066
  return new _Variant(tagged.type, tagged.value);
@@ -17853,6 +17910,7 @@ var SecureChannelMessageDecoder = class extends TransformStream {
17853
17910
  this.logger.warn("SecureChannel received Abort message");
17854
17911
  const secHeader = MsgSecurityHeaderSymmetric.decode(buffer);
17855
17912
  const msgSym = MsgSymmetric.decode(buffer, header, secHeader, this.context.securityAlgorithm);
17913
+ if (!this.validateSequenceNumber(msgSym.sequenceHeader.sequenceNumber, controller)) return;
17856
17914
  controller.enqueue(msgSym);
17857
17915
  break;
17858
17916
  }