opcjs-base 0.1.5 → 0.1.9
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.cjs +247 -238
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +125 -5
- package/dist/index.d.ts +125 -5
- package/dist/index.js +247 -239
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1821,220 +1821,6 @@ var BinaryReader = class _BinaryReader {
|
|
|
1821
1821
|
}
|
|
1822
1822
|
};
|
|
1823
1823
|
|
|
1824
|
-
// src/types/xmlElement.ts
|
|
1825
|
-
var XmlElement = class _XmlElement {
|
|
1826
|
-
/**
|
|
1827
|
-
* The XML string content
|
|
1828
|
-
*/
|
|
1829
|
-
content;
|
|
1830
|
-
/**
|
|
1831
|
-
* Create a new XmlElement
|
|
1832
|
-
*
|
|
1833
|
-
* @param content - The XML string content
|
|
1834
|
-
*/
|
|
1835
|
-
constructor(content = "") {
|
|
1836
|
-
this.content = content;
|
|
1837
|
-
}
|
|
1838
|
-
/**
|
|
1839
|
-
* Get the XML string content
|
|
1840
|
-
*
|
|
1841
|
-
* @returns The XML string
|
|
1842
|
-
*/
|
|
1843
|
-
toString() {
|
|
1844
|
-
return this.content;
|
|
1845
|
-
}
|
|
1846
|
-
/**
|
|
1847
|
-
* Get the length of the XML string
|
|
1848
|
-
*
|
|
1849
|
-
* @returns The number of characters
|
|
1850
|
-
*/
|
|
1851
|
-
get length() {
|
|
1852
|
-
return this.content.length;
|
|
1853
|
-
}
|
|
1854
|
-
/**
|
|
1855
|
-
* Validate if this XmlElement contains valid XML
|
|
1856
|
-
*
|
|
1857
|
-
* Note: This is a simple check, not a full XML validator.
|
|
1858
|
-
* For production use, consider using a proper XML parser.
|
|
1859
|
-
*
|
|
1860
|
-
* @returns true if the string appears to be valid XML
|
|
1861
|
-
*
|
|
1862
|
-
* @example
|
|
1863
|
-
* ```typescript
|
|
1864
|
-
* const xml = new XmlElement("<root></root>");
|
|
1865
|
-
* xml.isValid(); // true
|
|
1866
|
-
* ```
|
|
1867
|
-
*/
|
|
1868
|
-
isValid() {
|
|
1869
|
-
if (this.content.length === 0) {
|
|
1870
|
-
return false;
|
|
1871
|
-
}
|
|
1872
|
-
const trimmed = this.content.trim();
|
|
1873
|
-
if (!trimmed.startsWith("<") || !trimmed.endsWith(">")) {
|
|
1874
|
-
return false;
|
|
1875
|
-
}
|
|
1876
|
-
try {
|
|
1877
|
-
if (typeof globalThis !== "undefined" && "DOMParser" in globalThis) {
|
|
1878
|
-
const DOMParserConstructor = globalThis.DOMParser;
|
|
1879
|
-
const parser = new DOMParserConstructor();
|
|
1880
|
-
const doc = parser.parseFromString(this.content, "text/xml");
|
|
1881
|
-
const parserError = doc.querySelector("parsererror");
|
|
1882
|
-
return parserError === null;
|
|
1883
|
-
}
|
|
1884
|
-
} catch {
|
|
1885
|
-
}
|
|
1886
|
-
return _XmlElement.checkBasicXmlStructure(trimmed);
|
|
1887
|
-
}
|
|
1888
|
-
/**
|
|
1889
|
-
* Basic XML structure validation (for Node.js environment)
|
|
1890
|
-
* Checks for matching opening and closing tags
|
|
1891
|
-
*/
|
|
1892
|
-
static checkBasicXmlStructure(xml) {
|
|
1893
|
-
const tagStack = [];
|
|
1894
|
-
const tagRegex = /<\/?([a-zA-Z][\w:-]*)[^>]*>/g;
|
|
1895
|
-
let match;
|
|
1896
|
-
while ((match = tagRegex.exec(xml)) !== null) {
|
|
1897
|
-
const fullTag = match[0];
|
|
1898
|
-
const tagName = match[1];
|
|
1899
|
-
if (fullTag.startsWith("</")) {
|
|
1900
|
-
if (tagStack.length === 0 || tagStack.pop() !== tagName) {
|
|
1901
|
-
return false;
|
|
1902
|
-
}
|
|
1903
|
-
} else if (!fullTag.endsWith("/>")) {
|
|
1904
|
-
tagStack.push(tagName);
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
return tagStack.length === 0;
|
|
1908
|
-
}
|
|
1909
|
-
/**
|
|
1910
|
-
* Escape special XML characters in text content
|
|
1911
|
-
*
|
|
1912
|
-
* @param text - Text to escape
|
|
1913
|
-
* @returns Escaped text safe for use in XML
|
|
1914
|
-
*
|
|
1915
|
-
* @example
|
|
1916
|
-
* ```typescript
|
|
1917
|
-
* XmlElement.escape("Hello & <World>"); // "Hello & <World>"
|
|
1918
|
-
* ```
|
|
1919
|
-
*/
|
|
1920
|
-
static escape(text) {
|
|
1921
|
-
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1922
|
-
}
|
|
1923
|
-
/**
|
|
1924
|
-
* Unescape XML entities to plain text
|
|
1925
|
-
*
|
|
1926
|
-
* @param xml - XML text with entities
|
|
1927
|
-
* @returns Unescaped text
|
|
1928
|
-
*
|
|
1929
|
-
* @example
|
|
1930
|
-
* ```typescript
|
|
1931
|
-
* XmlElement.unescape("Hello & <World>"); // "Hello & <World>"
|
|
1932
|
-
* ```
|
|
1933
|
-
*/
|
|
1934
|
-
static unescape(xml) {
|
|
1935
|
-
return xml.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
1936
|
-
}
|
|
1937
|
-
/**
|
|
1938
|
-
* Create a simple XML element
|
|
1939
|
-
*
|
|
1940
|
-
* @param tagName - The XML tag name
|
|
1941
|
-
* @param content - The text content (will be escaped)
|
|
1942
|
-
* @param attributes - Optional attributes object
|
|
1943
|
-
* @returns XmlElement
|
|
1944
|
-
*
|
|
1945
|
-
* @example
|
|
1946
|
-
* ```typescript
|
|
1947
|
-
* const xml = XmlElement.create("Temperature", "25.5", { unit: "C" });
|
|
1948
|
-
* // "<Temperature unit=\"C\">25.5</Temperature>"
|
|
1949
|
-
* ```
|
|
1950
|
-
*/
|
|
1951
|
-
static create(tagName, content = "", attributes) {
|
|
1952
|
-
let attrStr = "";
|
|
1953
|
-
if (attributes) {
|
|
1954
|
-
attrStr = Object.entries(attributes).map(([key, value]) => ` ${key}="${_XmlElement.escape(value)}"`).join("");
|
|
1955
|
-
}
|
|
1956
|
-
const escapedContent = _XmlElement.escape(content);
|
|
1957
|
-
const xmlString = `<${tagName}${attrStr}>${escapedContent}</${tagName}>`;
|
|
1958
|
-
return new _XmlElement(xmlString);
|
|
1959
|
-
}
|
|
1960
|
-
/**
|
|
1961
|
-
* Create an empty XmlElement
|
|
1962
|
-
*
|
|
1963
|
-
* @returns Empty XmlElement
|
|
1964
|
-
*/
|
|
1965
|
-
static empty() {
|
|
1966
|
-
return new _XmlElement("");
|
|
1967
|
-
}
|
|
1968
|
-
/**
|
|
1969
|
-
* Check equality with another XmlElement
|
|
1970
|
-
*
|
|
1971
|
-
* @param other - The other XmlElement
|
|
1972
|
-
* @returns true if both contain the same XML string
|
|
1973
|
-
*/
|
|
1974
|
-
equals(other) {
|
|
1975
|
-
return this.content === other.content;
|
|
1976
|
-
}
|
|
1977
|
-
};
|
|
1978
|
-
|
|
1979
|
-
// src/types/primitives.ts
|
|
1980
|
-
var BuiltinTypeId = {
|
|
1981
|
-
Boolean: 1,
|
|
1982
|
-
SByte: 2,
|
|
1983
|
-
Byte: 3,
|
|
1984
|
-
Int16: 4,
|
|
1985
|
-
UInt16: 5,
|
|
1986
|
-
Int32: 6,
|
|
1987
|
-
UInt32: 7,
|
|
1988
|
-
Int64: 8,
|
|
1989
|
-
UInt64: 9,
|
|
1990
|
-
Float: 10,
|
|
1991
|
-
Double: 11,
|
|
1992
|
-
String: 12,
|
|
1993
|
-
DateTime: 13,
|
|
1994
|
-
Guid: 14,
|
|
1995
|
-
ByteString: 15,
|
|
1996
|
-
XmlElement: 16,
|
|
1997
|
-
NodeId: 17,
|
|
1998
|
-
ExpandedNodeId: 18,
|
|
1999
|
-
StatusCode: 19,
|
|
2000
|
-
QualifiedName: 20,
|
|
2001
|
-
LocalizedText: 21,
|
|
2002
|
-
ExtensionObject: 22,
|
|
2003
|
-
DataValue: 23,
|
|
2004
|
-
Variant: 24,
|
|
2005
|
-
DiagnosticInfo: 25
|
|
2006
|
-
};
|
|
2007
|
-
function getPrimitiveTypeName(typeId) {
|
|
2008
|
-
const primitiveMap = {
|
|
2009
|
-
[BuiltinTypeId.Boolean]: "boolean",
|
|
2010
|
-
[BuiltinTypeId.SByte]: "number",
|
|
2011
|
-
[BuiltinTypeId.Byte]: "number",
|
|
2012
|
-
[BuiltinTypeId.Int16]: "number",
|
|
2013
|
-
[BuiltinTypeId.UInt16]: "number",
|
|
2014
|
-
[BuiltinTypeId.Int32]: "number",
|
|
2015
|
-
[BuiltinTypeId.UInt32]: "number",
|
|
2016
|
-
[BuiltinTypeId.Int64]: "bigint",
|
|
2017
|
-
[BuiltinTypeId.UInt64]: "bigint",
|
|
2018
|
-
[BuiltinTypeId.Float]: "number",
|
|
2019
|
-
[BuiltinTypeId.ByteString]: "Uint8Array | null",
|
|
2020
|
-
[BuiltinTypeId.Double]: "number",
|
|
2021
|
-
[BuiltinTypeId.String]: "string | null",
|
|
2022
|
-
[BuiltinTypeId.DateTime]: "Date",
|
|
2023
|
-
[BuiltinTypeId.Guid]: "string"
|
|
2024
|
-
};
|
|
2025
|
-
return primitiveMap[typeId];
|
|
2026
|
-
}
|
|
2027
|
-
function isPrimitive(typeId) {
|
|
2028
|
-
return getPrimitiveTypeName(typeId) !== void 0;
|
|
2029
|
-
}
|
|
2030
|
-
|
|
2031
|
-
// src/certificates/certificate.ts
|
|
2032
|
-
var Certificate = class {
|
|
2033
|
-
getBytes() {
|
|
2034
|
-
throw new Error("Method not implemented.");
|
|
2035
|
-
}
|
|
2036
|
-
};
|
|
2037
|
-
|
|
2038
1824
|
// src/codecs/binary/binaryWriter.ts
|
|
2039
1825
|
var EPOCH_DIFF_MS2 = 11644473600000n;
|
|
2040
1826
|
var TICKS_PER_MS2 = 10000n;
|
|
@@ -2093,7 +1879,9 @@ var VariantMask2 = {
|
|
|
2093
1879
|
};
|
|
2094
1880
|
var BinaryWriter = class {
|
|
2095
1881
|
buffer;
|
|
1882
|
+
view;
|
|
2096
1883
|
position;
|
|
1884
|
+
growthFactor = 2;
|
|
2097
1885
|
getData() {
|
|
2098
1886
|
return this.buffer.subarray(0, this.position);
|
|
2099
1887
|
}
|
|
@@ -2137,23 +1925,25 @@ var BinaryWriter = class {
|
|
|
2137
1925
|
if (!Number.isInteger(value) || value < 0 || value > 4294967295) {
|
|
2138
1926
|
throw new CodecError(`UInt32 value ${value} out of range [0, 4294967295]`);
|
|
2139
1927
|
}
|
|
2140
|
-
this.
|
|
1928
|
+
this.view.setUint32(offset, value, true);
|
|
2141
1929
|
}
|
|
2142
1930
|
/**
|
|
2143
1931
|
* Ensure buffer has enough capacity, growing if necessary.
|
|
2144
1932
|
*/
|
|
2145
1933
|
ensureCapacity(additionalBytes) {
|
|
2146
|
-
const
|
|
2147
|
-
if (
|
|
2148
|
-
const newSize = Math.max(
|
|
2149
|
-
const newBuffer =
|
|
2150
|
-
this.buffer.
|
|
1934
|
+
const requiredSize = this.position + additionalBytes;
|
|
1935
|
+
if (requiredSize > this.buffer.length) {
|
|
1936
|
+
const newSize = Math.max(this.buffer.length * this.growthFactor, requiredSize);
|
|
1937
|
+
const newBuffer = new Uint8Array(newSize);
|
|
1938
|
+
newBuffer.set(this.buffer.subarray(0, this.position), 0);
|
|
2151
1939
|
this.buffer = newBuffer;
|
|
1940
|
+
this.view = new DataView(newBuffer.buffer, newBuffer.byteOffset, newBuffer.byteLength);
|
|
1941
|
+
console.log(`BufferWriter: resized buffer to ${newSize} bytes`);
|
|
2152
1942
|
}
|
|
2153
1943
|
}
|
|
2154
1944
|
writeBoolean(value) {
|
|
2155
1945
|
this.ensureCapacity(1);
|
|
2156
|
-
this.
|
|
1946
|
+
this.view.setUint8(this.position, value ? 1 : 0);
|
|
2157
1947
|
this.position += 1;
|
|
2158
1948
|
}
|
|
2159
1949
|
writeByte(value) {
|
|
@@ -2161,7 +1951,7 @@ var BinaryWriter = class {
|
|
|
2161
1951
|
throw new CodecError(`Byte value ${value} out of range [0, 255]`);
|
|
2162
1952
|
}
|
|
2163
1953
|
this.ensureCapacity(1);
|
|
2164
|
-
this.
|
|
1954
|
+
this.view.setUint8(this.position, value);
|
|
2165
1955
|
this.position += 1;
|
|
2166
1956
|
}
|
|
2167
1957
|
writeSByte(value) {
|
|
@@ -2169,7 +1959,7 @@ var BinaryWriter = class {
|
|
|
2169
1959
|
throw new CodecError(`SByte value ${value} out of range [-128, 127]`);
|
|
2170
1960
|
}
|
|
2171
1961
|
this.ensureCapacity(1);
|
|
2172
|
-
this.
|
|
1962
|
+
this.view.setInt8(this.position, value);
|
|
2173
1963
|
this.position += 1;
|
|
2174
1964
|
}
|
|
2175
1965
|
writeInt16(value) {
|
|
@@ -2177,7 +1967,7 @@ var BinaryWriter = class {
|
|
|
2177
1967
|
throw new CodecError(`Int16 value ${value} out of range [-32768, 32767]`);
|
|
2178
1968
|
}
|
|
2179
1969
|
this.ensureCapacity(2);
|
|
2180
|
-
this.
|
|
1970
|
+
this.view.setInt16(this.position, value, true);
|
|
2181
1971
|
this.position += 2;
|
|
2182
1972
|
}
|
|
2183
1973
|
writeUInt16(value) {
|
|
@@ -2185,7 +1975,7 @@ var BinaryWriter = class {
|
|
|
2185
1975
|
throw new CodecError(`UInt16 value ${value} out of range [0, 65535]`);
|
|
2186
1976
|
}
|
|
2187
1977
|
this.ensureCapacity(2);
|
|
2188
|
-
this.
|
|
1978
|
+
this.view.setUint16(this.position, value, true);
|
|
2189
1979
|
this.position += 2;
|
|
2190
1980
|
}
|
|
2191
1981
|
writeInt32(value) {
|
|
@@ -2193,7 +1983,7 @@ var BinaryWriter = class {
|
|
|
2193
1983
|
throw new CodecError(`Int32 value ${value} out of range [-2147483648, 2147483647]`);
|
|
2194
1984
|
}
|
|
2195
1985
|
this.ensureCapacity(4);
|
|
2196
|
-
this.
|
|
1986
|
+
this.view.setInt32(this.position, value, true);
|
|
2197
1987
|
this.position += 4;
|
|
2198
1988
|
}
|
|
2199
1989
|
writeUInt32(value) {
|
|
@@ -2201,27 +1991,27 @@ var BinaryWriter = class {
|
|
|
2201
1991
|
throw new CodecError(`UInt32 value ${value} out of range [0, 4294967295]`);
|
|
2202
1992
|
}
|
|
2203
1993
|
this.ensureCapacity(4);
|
|
2204
|
-
this.
|
|
1994
|
+
this.view.setUint32(this.position, value, true);
|
|
2205
1995
|
this.position += 4;
|
|
2206
1996
|
}
|
|
2207
1997
|
writeInt64(value) {
|
|
2208
1998
|
this.ensureCapacity(8);
|
|
2209
|
-
this.
|
|
1999
|
+
this.view.setBigInt64(this.position, value, true);
|
|
2210
2000
|
this.position += 8;
|
|
2211
2001
|
}
|
|
2212
2002
|
writeUInt64(value) {
|
|
2213
2003
|
this.ensureCapacity(8);
|
|
2214
|
-
this.
|
|
2004
|
+
this.view.setBigUint64(this.position, value, true);
|
|
2215
2005
|
this.position += 8;
|
|
2216
2006
|
}
|
|
2217
2007
|
writeFloat(value) {
|
|
2218
2008
|
this.ensureCapacity(4);
|
|
2219
|
-
this.
|
|
2009
|
+
this.view.setFloat32(this.position, value, true);
|
|
2220
2010
|
this.position += 4;
|
|
2221
2011
|
}
|
|
2222
2012
|
writeDouble(value) {
|
|
2223
2013
|
this.ensureCapacity(8);
|
|
2224
|
-
this.
|
|
2014
|
+
this.view.setFloat64(this.position, value, true);
|
|
2225
2015
|
this.position += 8;
|
|
2226
2016
|
}
|
|
2227
2017
|
writeString(value) {
|
|
@@ -2254,14 +2044,14 @@ var BinaryWriter = class {
|
|
|
2254
2044
|
}
|
|
2255
2045
|
this.ensureCapacity(16);
|
|
2256
2046
|
const data1 = parseInt(hex.substr(0, 8), 16);
|
|
2257
|
-
this.
|
|
2047
|
+
this.view.setUint32(this.position, data1, true);
|
|
2258
2048
|
const data2 = parseInt(hex.substr(8, 4), 16);
|
|
2259
|
-
this.
|
|
2049
|
+
this.view.setUint16(this.position + 4, data2, true);
|
|
2260
2050
|
const data3 = parseInt(hex.substr(12, 4), 16);
|
|
2261
|
-
this.
|
|
2051
|
+
this.view.setUint16(this.position + 6, data3, true);
|
|
2262
2052
|
for (let i = 0; i < 8; i++) {
|
|
2263
2053
|
const byte = parseInt(hex.substr(16 + i * 2, 2), 16);
|
|
2264
|
-
this.
|
|
2054
|
+
this.view.setUint8(this.position + 8 + i, byte);
|
|
2265
2055
|
}
|
|
2266
2056
|
this.position += 16;
|
|
2267
2057
|
}
|
|
@@ -2432,20 +2222,22 @@ var BinaryWriter = class {
|
|
|
2432
2222
|
switch (value.encoding) {
|
|
2433
2223
|
case 0 /* None */:
|
|
2434
2224
|
break;
|
|
2435
|
-
case 1 /* Binary */:
|
|
2225
|
+
case 1 /* Binary */: {
|
|
2436
2226
|
if (!value.data) {
|
|
2437
2227
|
throw new CodecError("ExtensionObject with Binary encoding must have data");
|
|
2438
2228
|
}
|
|
2439
2229
|
const binaryData = encoder.encodeWithoutId(value.data, "binary");
|
|
2440
2230
|
this.writeByteString(binaryData);
|
|
2441
2231
|
break;
|
|
2442
|
-
|
|
2232
|
+
}
|
|
2233
|
+
case 2 /* Xml */: {
|
|
2443
2234
|
if (!value.data) {
|
|
2444
2235
|
throw new CodecError("ExtensionObject with Xml encoding must have data");
|
|
2445
2236
|
}
|
|
2446
2237
|
const xmlString = encoder.encodeWithoutId(value.data, "xml");
|
|
2447
2238
|
this.writeXmlElement(xmlString);
|
|
2448
2239
|
break;
|
|
2240
|
+
}
|
|
2449
2241
|
default:
|
|
2450
2242
|
throw new CodecError(`Invalid ExtensionObject encoding: ${value.encoding}`);
|
|
2451
2243
|
}
|
|
@@ -2663,11 +2455,227 @@ var BinaryWriter = class {
|
|
|
2663
2455
|
}
|
|
2664
2456
|
}
|
|
2665
2457
|
constructor(initialSize = 1024) {
|
|
2666
|
-
|
|
2458
|
+
const data = Buffer.allocUnsafe(initialSize);
|
|
2459
|
+
this.buffer = data;
|
|
2460
|
+
this.view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
2667
2461
|
this.position = 0;
|
|
2668
2462
|
}
|
|
2669
2463
|
};
|
|
2670
2464
|
|
|
2465
|
+
// src/types/xmlElement.ts
|
|
2466
|
+
var XmlElement = class _XmlElement {
|
|
2467
|
+
/**
|
|
2468
|
+
* The XML string content
|
|
2469
|
+
*/
|
|
2470
|
+
content;
|
|
2471
|
+
/**
|
|
2472
|
+
* Create a new XmlElement
|
|
2473
|
+
*
|
|
2474
|
+
* @param content - The XML string content
|
|
2475
|
+
*/
|
|
2476
|
+
constructor(content = "") {
|
|
2477
|
+
this.content = content;
|
|
2478
|
+
}
|
|
2479
|
+
/**
|
|
2480
|
+
* Get the XML string content
|
|
2481
|
+
*
|
|
2482
|
+
* @returns The XML string
|
|
2483
|
+
*/
|
|
2484
|
+
toString() {
|
|
2485
|
+
return this.content;
|
|
2486
|
+
}
|
|
2487
|
+
/**
|
|
2488
|
+
* Get the length of the XML string
|
|
2489
|
+
*
|
|
2490
|
+
* @returns The number of characters
|
|
2491
|
+
*/
|
|
2492
|
+
get length() {
|
|
2493
|
+
return this.content.length;
|
|
2494
|
+
}
|
|
2495
|
+
/**
|
|
2496
|
+
* Validate if this XmlElement contains valid XML
|
|
2497
|
+
*
|
|
2498
|
+
* Note: This is a simple check, not a full XML validator.
|
|
2499
|
+
* For production use, consider using a proper XML parser.
|
|
2500
|
+
*
|
|
2501
|
+
* @returns true if the string appears to be valid XML
|
|
2502
|
+
*
|
|
2503
|
+
* @example
|
|
2504
|
+
* ```typescript
|
|
2505
|
+
* const xml = new XmlElement("<root></root>");
|
|
2506
|
+
* xml.isValid(); // true
|
|
2507
|
+
* ```
|
|
2508
|
+
*/
|
|
2509
|
+
isValid() {
|
|
2510
|
+
if (this.content.length === 0) {
|
|
2511
|
+
return false;
|
|
2512
|
+
}
|
|
2513
|
+
const trimmed = this.content.trim();
|
|
2514
|
+
if (!trimmed.startsWith("<") || !trimmed.endsWith(">")) {
|
|
2515
|
+
return false;
|
|
2516
|
+
}
|
|
2517
|
+
try {
|
|
2518
|
+
if (typeof globalThis !== "undefined" && "DOMParser" in globalThis) {
|
|
2519
|
+
const DOMParserConstructor = globalThis.DOMParser;
|
|
2520
|
+
const parser = new DOMParserConstructor();
|
|
2521
|
+
const doc = parser.parseFromString(this.content, "text/xml");
|
|
2522
|
+
const parserError = doc.querySelector("parsererror");
|
|
2523
|
+
return parserError === null;
|
|
2524
|
+
}
|
|
2525
|
+
} catch {
|
|
2526
|
+
}
|
|
2527
|
+
return _XmlElement.checkBasicXmlStructure(trimmed);
|
|
2528
|
+
}
|
|
2529
|
+
/**
|
|
2530
|
+
* Basic XML structure validation (for Node.js environment)
|
|
2531
|
+
* Checks for matching opening and closing tags
|
|
2532
|
+
*/
|
|
2533
|
+
static checkBasicXmlStructure(xml) {
|
|
2534
|
+
const tagStack = [];
|
|
2535
|
+
const tagRegex = /<\/?([a-zA-Z][\w:-]*)[^>]*>/g;
|
|
2536
|
+
let match;
|
|
2537
|
+
while ((match = tagRegex.exec(xml)) !== null) {
|
|
2538
|
+
const fullTag = match[0];
|
|
2539
|
+
const tagName = match[1];
|
|
2540
|
+
if (fullTag.startsWith("</")) {
|
|
2541
|
+
if (tagStack.length === 0 || tagStack.pop() !== tagName) {
|
|
2542
|
+
return false;
|
|
2543
|
+
}
|
|
2544
|
+
} else if (!fullTag.endsWith("/>")) {
|
|
2545
|
+
tagStack.push(tagName);
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
return tagStack.length === 0;
|
|
2549
|
+
}
|
|
2550
|
+
/**
|
|
2551
|
+
* Escape special XML characters in text content
|
|
2552
|
+
*
|
|
2553
|
+
* @param text - Text to escape
|
|
2554
|
+
* @returns Escaped text safe for use in XML
|
|
2555
|
+
*
|
|
2556
|
+
* @example
|
|
2557
|
+
* ```typescript
|
|
2558
|
+
* XmlElement.escape("Hello & <World>"); // "Hello & <World>"
|
|
2559
|
+
* ```
|
|
2560
|
+
*/
|
|
2561
|
+
static escape(text) {
|
|
2562
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
2563
|
+
}
|
|
2564
|
+
/**
|
|
2565
|
+
* Unescape XML entities to plain text
|
|
2566
|
+
*
|
|
2567
|
+
* @param xml - XML text with entities
|
|
2568
|
+
* @returns Unescaped text
|
|
2569
|
+
*
|
|
2570
|
+
* @example
|
|
2571
|
+
* ```typescript
|
|
2572
|
+
* XmlElement.unescape("Hello & <World>"); // "Hello & <World>"
|
|
2573
|
+
* ```
|
|
2574
|
+
*/
|
|
2575
|
+
static unescape(xml) {
|
|
2576
|
+
return xml.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
2577
|
+
}
|
|
2578
|
+
/**
|
|
2579
|
+
* Create a simple XML element
|
|
2580
|
+
*
|
|
2581
|
+
* @param tagName - The XML tag name
|
|
2582
|
+
* @param content - The text content (will be escaped)
|
|
2583
|
+
* @param attributes - Optional attributes object
|
|
2584
|
+
* @returns XmlElement
|
|
2585
|
+
*
|
|
2586
|
+
* @example
|
|
2587
|
+
* ```typescript
|
|
2588
|
+
* const xml = XmlElement.create("Temperature", "25.5", { unit: "C" });
|
|
2589
|
+
* // "<Temperature unit=\"C\">25.5</Temperature>"
|
|
2590
|
+
* ```
|
|
2591
|
+
*/
|
|
2592
|
+
static create(tagName, content = "", attributes) {
|
|
2593
|
+
let attrStr = "";
|
|
2594
|
+
if (attributes) {
|
|
2595
|
+
attrStr = Object.entries(attributes).map(([key, value]) => ` ${key}="${_XmlElement.escape(value)}"`).join("");
|
|
2596
|
+
}
|
|
2597
|
+
const escapedContent = _XmlElement.escape(content);
|
|
2598
|
+
const xmlString = `<${tagName}${attrStr}>${escapedContent}</${tagName}>`;
|
|
2599
|
+
return new _XmlElement(xmlString);
|
|
2600
|
+
}
|
|
2601
|
+
/**
|
|
2602
|
+
* Create an empty XmlElement
|
|
2603
|
+
*
|
|
2604
|
+
* @returns Empty XmlElement
|
|
2605
|
+
*/
|
|
2606
|
+
static empty() {
|
|
2607
|
+
return new _XmlElement("");
|
|
2608
|
+
}
|
|
2609
|
+
/**
|
|
2610
|
+
* Check equality with another XmlElement
|
|
2611
|
+
*
|
|
2612
|
+
* @param other - The other XmlElement
|
|
2613
|
+
* @returns true if both contain the same XML string
|
|
2614
|
+
*/
|
|
2615
|
+
equals(other) {
|
|
2616
|
+
return this.content === other.content;
|
|
2617
|
+
}
|
|
2618
|
+
};
|
|
2619
|
+
|
|
2620
|
+
// src/types/primitives.ts
|
|
2621
|
+
var BuiltinTypeId = {
|
|
2622
|
+
Boolean: 1,
|
|
2623
|
+
SByte: 2,
|
|
2624
|
+
Byte: 3,
|
|
2625
|
+
Int16: 4,
|
|
2626
|
+
UInt16: 5,
|
|
2627
|
+
Int32: 6,
|
|
2628
|
+
UInt32: 7,
|
|
2629
|
+
Int64: 8,
|
|
2630
|
+
UInt64: 9,
|
|
2631
|
+
Float: 10,
|
|
2632
|
+
Double: 11,
|
|
2633
|
+
String: 12,
|
|
2634
|
+
DateTime: 13,
|
|
2635
|
+
Guid: 14,
|
|
2636
|
+
ByteString: 15,
|
|
2637
|
+
XmlElement: 16,
|
|
2638
|
+
NodeId: 17,
|
|
2639
|
+
ExpandedNodeId: 18,
|
|
2640
|
+
StatusCode: 19,
|
|
2641
|
+
QualifiedName: 20,
|
|
2642
|
+
LocalizedText: 21,
|
|
2643
|
+
ExtensionObject: 22,
|
|
2644
|
+
DataValue: 23,
|
|
2645
|
+
Variant: 24,
|
|
2646
|
+
DiagnosticInfo: 25
|
|
2647
|
+
};
|
|
2648
|
+
function getPrimitiveTypeName(typeId) {
|
|
2649
|
+
const primitiveMap = {
|
|
2650
|
+
[BuiltinTypeId.Boolean]: "boolean",
|
|
2651
|
+
[BuiltinTypeId.SByte]: "number",
|
|
2652
|
+
[BuiltinTypeId.Byte]: "number",
|
|
2653
|
+
[BuiltinTypeId.Int16]: "number",
|
|
2654
|
+
[BuiltinTypeId.UInt16]: "number",
|
|
2655
|
+
[BuiltinTypeId.Int32]: "number",
|
|
2656
|
+
[BuiltinTypeId.UInt32]: "number",
|
|
2657
|
+
[BuiltinTypeId.Int64]: "bigint",
|
|
2658
|
+
[BuiltinTypeId.UInt64]: "bigint",
|
|
2659
|
+
[BuiltinTypeId.Float]: "number",
|
|
2660
|
+
[BuiltinTypeId.ByteString]: "Uint8Array | null",
|
|
2661
|
+
[BuiltinTypeId.Double]: "number",
|
|
2662
|
+
[BuiltinTypeId.String]: "string | null",
|
|
2663
|
+
[BuiltinTypeId.DateTime]: "Date",
|
|
2664
|
+
[BuiltinTypeId.Guid]: "string"
|
|
2665
|
+
};
|
|
2666
|
+
return primitiveMap[typeId];
|
|
2667
|
+
}
|
|
2668
|
+
function isPrimitive(typeId) {
|
|
2669
|
+
return getPrimitiveTypeName(typeId) !== void 0;
|
|
2670
|
+
}
|
|
2671
|
+
|
|
2672
|
+
// src/certificates/certificate.ts
|
|
2673
|
+
var Certificate = class {
|
|
2674
|
+
getBytes() {
|
|
2675
|
+
throw new Error("Method not implemented.");
|
|
2676
|
+
}
|
|
2677
|
+
};
|
|
2678
|
+
|
|
2671
2679
|
// src/schema/enums.ts
|
|
2672
2680
|
var ActionStateEnum = /* @__PURE__ */ ((ActionStateEnum2) => {
|
|
2673
2681
|
ActionStateEnum2[ActionStateEnum2["Idle"] = 0] = "Idle";
|
|
@@ -17056,6 +17064,7 @@ exports.AxisScaleEnumerationEnum = AxisScaleEnumerationEnum;
|
|
|
17056
17064
|
exports.BaseConfigurationDataType = BaseConfigurationDataType;
|
|
17057
17065
|
exports.BaseConfigurationRecordDataType = BaseConfigurationRecordDataType;
|
|
17058
17066
|
exports.BinaryReader = BinaryReader;
|
|
17067
|
+
exports.BinaryWriter = BinaryWriter;
|
|
17059
17068
|
exports.BitFieldDefinition = BitFieldDefinition;
|
|
17060
17069
|
exports.BrokerConnectionTransportDataType = BrokerConnectionTransportDataType;
|
|
17061
17070
|
exports.BrokerDataSetReaderTransportDataType = BrokerDataSetReaderTransportDataType;
|