opcjs-base 0.1.5 → 0.1.7
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 +215 -214
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +123 -5
- package/dist/index.d.ts +123 -5
- package/dist/index.js +215 -215
- 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;
|
|
@@ -2668,6 +2454,220 @@ var BinaryWriter = class {
|
|
|
2668
2454
|
}
|
|
2669
2455
|
};
|
|
2670
2456
|
|
|
2457
|
+
// src/types/xmlElement.ts
|
|
2458
|
+
var XmlElement = class _XmlElement {
|
|
2459
|
+
/**
|
|
2460
|
+
* The XML string content
|
|
2461
|
+
*/
|
|
2462
|
+
content;
|
|
2463
|
+
/**
|
|
2464
|
+
* Create a new XmlElement
|
|
2465
|
+
*
|
|
2466
|
+
* @param content - The XML string content
|
|
2467
|
+
*/
|
|
2468
|
+
constructor(content = "") {
|
|
2469
|
+
this.content = content;
|
|
2470
|
+
}
|
|
2471
|
+
/**
|
|
2472
|
+
* Get the XML string content
|
|
2473
|
+
*
|
|
2474
|
+
* @returns The XML string
|
|
2475
|
+
*/
|
|
2476
|
+
toString() {
|
|
2477
|
+
return this.content;
|
|
2478
|
+
}
|
|
2479
|
+
/**
|
|
2480
|
+
* Get the length of the XML string
|
|
2481
|
+
*
|
|
2482
|
+
* @returns The number of characters
|
|
2483
|
+
*/
|
|
2484
|
+
get length() {
|
|
2485
|
+
return this.content.length;
|
|
2486
|
+
}
|
|
2487
|
+
/**
|
|
2488
|
+
* Validate if this XmlElement contains valid XML
|
|
2489
|
+
*
|
|
2490
|
+
* Note: This is a simple check, not a full XML validator.
|
|
2491
|
+
* For production use, consider using a proper XML parser.
|
|
2492
|
+
*
|
|
2493
|
+
* @returns true if the string appears to be valid XML
|
|
2494
|
+
*
|
|
2495
|
+
* @example
|
|
2496
|
+
* ```typescript
|
|
2497
|
+
* const xml = new XmlElement("<root></root>");
|
|
2498
|
+
* xml.isValid(); // true
|
|
2499
|
+
* ```
|
|
2500
|
+
*/
|
|
2501
|
+
isValid() {
|
|
2502
|
+
if (this.content.length === 0) {
|
|
2503
|
+
return false;
|
|
2504
|
+
}
|
|
2505
|
+
const trimmed = this.content.trim();
|
|
2506
|
+
if (!trimmed.startsWith("<") || !trimmed.endsWith(">")) {
|
|
2507
|
+
return false;
|
|
2508
|
+
}
|
|
2509
|
+
try {
|
|
2510
|
+
if (typeof globalThis !== "undefined" && "DOMParser" in globalThis) {
|
|
2511
|
+
const DOMParserConstructor = globalThis.DOMParser;
|
|
2512
|
+
const parser = new DOMParserConstructor();
|
|
2513
|
+
const doc = parser.parseFromString(this.content, "text/xml");
|
|
2514
|
+
const parserError = doc.querySelector("parsererror");
|
|
2515
|
+
return parserError === null;
|
|
2516
|
+
}
|
|
2517
|
+
} catch {
|
|
2518
|
+
}
|
|
2519
|
+
return _XmlElement.checkBasicXmlStructure(trimmed);
|
|
2520
|
+
}
|
|
2521
|
+
/**
|
|
2522
|
+
* Basic XML structure validation (for Node.js environment)
|
|
2523
|
+
* Checks for matching opening and closing tags
|
|
2524
|
+
*/
|
|
2525
|
+
static checkBasicXmlStructure(xml) {
|
|
2526
|
+
const tagStack = [];
|
|
2527
|
+
const tagRegex = /<\/?([a-zA-Z][\w:-]*)[^>]*>/g;
|
|
2528
|
+
let match;
|
|
2529
|
+
while ((match = tagRegex.exec(xml)) !== null) {
|
|
2530
|
+
const fullTag = match[0];
|
|
2531
|
+
const tagName = match[1];
|
|
2532
|
+
if (fullTag.startsWith("</")) {
|
|
2533
|
+
if (tagStack.length === 0 || tagStack.pop() !== tagName) {
|
|
2534
|
+
return false;
|
|
2535
|
+
}
|
|
2536
|
+
} else if (!fullTag.endsWith("/>")) {
|
|
2537
|
+
tagStack.push(tagName);
|
|
2538
|
+
}
|
|
2539
|
+
}
|
|
2540
|
+
return tagStack.length === 0;
|
|
2541
|
+
}
|
|
2542
|
+
/**
|
|
2543
|
+
* Escape special XML characters in text content
|
|
2544
|
+
*
|
|
2545
|
+
* @param text - Text to escape
|
|
2546
|
+
* @returns Escaped text safe for use in XML
|
|
2547
|
+
*
|
|
2548
|
+
* @example
|
|
2549
|
+
* ```typescript
|
|
2550
|
+
* XmlElement.escape("Hello & <World>"); // "Hello & <World>"
|
|
2551
|
+
* ```
|
|
2552
|
+
*/
|
|
2553
|
+
static escape(text) {
|
|
2554
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
2555
|
+
}
|
|
2556
|
+
/**
|
|
2557
|
+
* Unescape XML entities to plain text
|
|
2558
|
+
*
|
|
2559
|
+
* @param xml - XML text with entities
|
|
2560
|
+
* @returns Unescaped text
|
|
2561
|
+
*
|
|
2562
|
+
* @example
|
|
2563
|
+
* ```typescript
|
|
2564
|
+
* XmlElement.unescape("Hello & <World>"); // "Hello & <World>"
|
|
2565
|
+
* ```
|
|
2566
|
+
*/
|
|
2567
|
+
static unescape(xml) {
|
|
2568
|
+
return xml.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
2569
|
+
}
|
|
2570
|
+
/**
|
|
2571
|
+
* Create a simple XML element
|
|
2572
|
+
*
|
|
2573
|
+
* @param tagName - The XML tag name
|
|
2574
|
+
* @param content - The text content (will be escaped)
|
|
2575
|
+
* @param attributes - Optional attributes object
|
|
2576
|
+
* @returns XmlElement
|
|
2577
|
+
*
|
|
2578
|
+
* @example
|
|
2579
|
+
* ```typescript
|
|
2580
|
+
* const xml = XmlElement.create("Temperature", "25.5", { unit: "C" });
|
|
2581
|
+
* // "<Temperature unit=\"C\">25.5</Temperature>"
|
|
2582
|
+
* ```
|
|
2583
|
+
*/
|
|
2584
|
+
static create(tagName, content = "", attributes) {
|
|
2585
|
+
let attrStr = "";
|
|
2586
|
+
if (attributes) {
|
|
2587
|
+
attrStr = Object.entries(attributes).map(([key, value]) => ` ${key}="${_XmlElement.escape(value)}"`).join("");
|
|
2588
|
+
}
|
|
2589
|
+
const escapedContent = _XmlElement.escape(content);
|
|
2590
|
+
const xmlString = `<${tagName}${attrStr}>${escapedContent}</${tagName}>`;
|
|
2591
|
+
return new _XmlElement(xmlString);
|
|
2592
|
+
}
|
|
2593
|
+
/**
|
|
2594
|
+
* Create an empty XmlElement
|
|
2595
|
+
*
|
|
2596
|
+
* @returns Empty XmlElement
|
|
2597
|
+
*/
|
|
2598
|
+
static empty() {
|
|
2599
|
+
return new _XmlElement("");
|
|
2600
|
+
}
|
|
2601
|
+
/**
|
|
2602
|
+
* Check equality with another XmlElement
|
|
2603
|
+
*
|
|
2604
|
+
* @param other - The other XmlElement
|
|
2605
|
+
* @returns true if both contain the same XML string
|
|
2606
|
+
*/
|
|
2607
|
+
equals(other) {
|
|
2608
|
+
return this.content === other.content;
|
|
2609
|
+
}
|
|
2610
|
+
};
|
|
2611
|
+
|
|
2612
|
+
// src/types/primitives.ts
|
|
2613
|
+
var BuiltinTypeId = {
|
|
2614
|
+
Boolean: 1,
|
|
2615
|
+
SByte: 2,
|
|
2616
|
+
Byte: 3,
|
|
2617
|
+
Int16: 4,
|
|
2618
|
+
UInt16: 5,
|
|
2619
|
+
Int32: 6,
|
|
2620
|
+
UInt32: 7,
|
|
2621
|
+
Int64: 8,
|
|
2622
|
+
UInt64: 9,
|
|
2623
|
+
Float: 10,
|
|
2624
|
+
Double: 11,
|
|
2625
|
+
String: 12,
|
|
2626
|
+
DateTime: 13,
|
|
2627
|
+
Guid: 14,
|
|
2628
|
+
ByteString: 15,
|
|
2629
|
+
XmlElement: 16,
|
|
2630
|
+
NodeId: 17,
|
|
2631
|
+
ExpandedNodeId: 18,
|
|
2632
|
+
StatusCode: 19,
|
|
2633
|
+
QualifiedName: 20,
|
|
2634
|
+
LocalizedText: 21,
|
|
2635
|
+
ExtensionObject: 22,
|
|
2636
|
+
DataValue: 23,
|
|
2637
|
+
Variant: 24,
|
|
2638
|
+
DiagnosticInfo: 25
|
|
2639
|
+
};
|
|
2640
|
+
function getPrimitiveTypeName(typeId) {
|
|
2641
|
+
const primitiveMap = {
|
|
2642
|
+
[BuiltinTypeId.Boolean]: "boolean",
|
|
2643
|
+
[BuiltinTypeId.SByte]: "number",
|
|
2644
|
+
[BuiltinTypeId.Byte]: "number",
|
|
2645
|
+
[BuiltinTypeId.Int16]: "number",
|
|
2646
|
+
[BuiltinTypeId.UInt16]: "number",
|
|
2647
|
+
[BuiltinTypeId.Int32]: "number",
|
|
2648
|
+
[BuiltinTypeId.UInt32]: "number",
|
|
2649
|
+
[BuiltinTypeId.Int64]: "bigint",
|
|
2650
|
+
[BuiltinTypeId.UInt64]: "bigint",
|
|
2651
|
+
[BuiltinTypeId.Float]: "number",
|
|
2652
|
+
[BuiltinTypeId.ByteString]: "Uint8Array | null",
|
|
2653
|
+
[BuiltinTypeId.Double]: "number",
|
|
2654
|
+
[BuiltinTypeId.String]: "string | null",
|
|
2655
|
+
[BuiltinTypeId.DateTime]: "Date",
|
|
2656
|
+
[BuiltinTypeId.Guid]: "string"
|
|
2657
|
+
};
|
|
2658
|
+
return primitiveMap[typeId];
|
|
2659
|
+
}
|
|
2660
|
+
function isPrimitive(typeId) {
|
|
2661
|
+
return getPrimitiveTypeName(typeId) !== void 0;
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
// src/certificates/certificate.ts
|
|
2665
|
+
var Certificate = class {
|
|
2666
|
+
getBytes() {
|
|
2667
|
+
throw new Error("Method not implemented.");
|
|
2668
|
+
}
|
|
2669
|
+
};
|
|
2670
|
+
|
|
2671
2671
|
// src/schema/enums.ts
|
|
2672
2672
|
var ActionStateEnum = /* @__PURE__ */ ((ActionStateEnum2) => {
|
|
2673
2673
|
ActionStateEnum2[ActionStateEnum2["Idle"] = 0] = "Idle";
|
|
@@ -17056,6 +17056,7 @@ exports.AxisScaleEnumerationEnum = AxisScaleEnumerationEnum;
|
|
|
17056
17056
|
exports.BaseConfigurationDataType = BaseConfigurationDataType;
|
|
17057
17057
|
exports.BaseConfigurationRecordDataType = BaseConfigurationRecordDataType;
|
|
17058
17058
|
exports.BinaryReader = BinaryReader;
|
|
17059
|
+
exports.BinaryWriter = BinaryWriter;
|
|
17059
17060
|
exports.BitFieldDefinition = BitFieldDefinition;
|
|
17060
17061
|
exports.BrokerConnectionTransportDataType = BrokerConnectionTransportDataType;
|
|
17061
17062
|
exports.BrokerDataSetReaderTransportDataType = BrokerDataSetReaderTransportDataType;
|