node-opcua-json 0.19.1 → 2.182.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.
Files changed (78) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +141 -4
  3. package/dist/decode_opcua_json.d.ts +31 -0
  4. package/dist/decode_opcua_json.js +61 -0
  5. package/dist/decode_opcua_json.js.map +1 -0
  6. package/dist/extension_object_constructor.d.ts +46 -0
  7. package/dist/extension_object_constructor.js +26 -0
  8. package/dist/extension_object_constructor.js.map +1 -0
  9. package/dist/index.d.ts +38 -0
  10. package/dist/index.js +66 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/json_basic_encoding_body_functor.d.ts +34 -0
  13. package/dist/json_basic_encoding_body_functor.js +170 -0
  14. package/dist/json_basic_encoding_body_functor.js.map +1 -0
  15. package/dist/json_basic_encoding_decoding_byte_string.d.ts +27 -0
  16. package/dist/json_basic_encoding_decoding_byte_string.js +27 -0
  17. package/dist/json_basic_encoding_decoding_byte_string.js.map +1 -0
  18. package/dist/json_basic_encoding_decoding_data_value.d.ts +80 -0
  19. package/dist/json_basic_encoding_decoding_data_value.js +289 -0
  20. package/dist/json_basic_encoding_decoding_data_value.js.map +1 -0
  21. package/dist/json_basic_encoding_decoding_date_time.d.ts +26 -0
  22. package/dist/json_basic_encoding_decoding_date_time.js +43 -0
  23. package/dist/json_basic_encoding_decoding_date_time.js.map +1 -0
  24. package/dist/json_basic_encoding_decoding_extension_object.d.ts +65 -0
  25. package/dist/json_basic_encoding_decoding_extension_object.js +461 -0
  26. package/dist/json_basic_encoding_decoding_extension_object.js.map +1 -0
  27. package/dist/json_basic_encoding_decoding_int64.d.ts +30 -0
  28. package/dist/json_basic_encoding_decoding_int64.js +56 -0
  29. package/dist/json_basic_encoding_decoding_int64.js.map +1 -0
  30. package/dist/json_basic_encoding_decoding_localizedtext.d.ts +33 -0
  31. package/dist/json_basic_encoding_decoding_localizedtext.js +62 -0
  32. package/dist/json_basic_encoding_decoding_localizedtext.js.map +1 -0
  33. package/dist/json_basic_encoding_decoding_nodeid.d.ts +42 -0
  34. package/dist/json_basic_encoding_decoding_nodeid.js +298 -0
  35. package/dist/json_basic_encoding_decoding_nodeid.js.map +1 -0
  36. package/dist/json_basic_encoding_decoding_qualifiedname.d.ts +35 -0
  37. package/dist/json_basic_encoding_decoding_qualifiedname.js +126 -0
  38. package/dist/json_basic_encoding_decoding_qualifiedname.js.map +1 -0
  39. package/dist/json_basic_encoding_decoding_statuscode.d.ts +39 -0
  40. package/dist/json_basic_encoding_decoding_statuscode.js +139 -0
  41. package/dist/json_basic_encoding_decoding_statuscode.js.map +1 -0
  42. package/dist/json_basic_encoding_decoding_variant.d.ts +101 -0
  43. package/dist/json_basic_encoding_decoding_variant.js +234 -0
  44. package/dist/json_basic_encoding_decoding_variant.js.map +1 -0
  45. package/dist/json_encoding_scheme.d.ts +50 -0
  46. package/dist/json_encoding_scheme.js +117 -0
  47. package/dist/json_encoding_scheme.js.map +1 -0
  48. package/package.json +57 -37
  49. package/source/decode_opcua_json.ts +67 -0
  50. package/source/extension_object_constructor.ts +48 -0
  51. package/source/index.ts +59 -0
  52. package/source/json_basic_encoding_body_functor.ts +190 -0
  53. package/source/json_basic_encoding_decoding_byte_string.ts +52 -0
  54. package/source/json_basic_encoding_decoding_data_value.ts +392 -0
  55. package/source/json_basic_encoding_decoding_date_time.ts +42 -0
  56. package/source/json_basic_encoding_decoding_extension_object.ts +531 -0
  57. package/source/json_basic_encoding_decoding_int64.ts +74 -0
  58. package/source/json_basic_encoding_decoding_localizedtext.ts +69 -0
  59. package/source/json_basic_encoding_decoding_nodeid.ts +356 -0
  60. package/source/json_basic_encoding_decoding_qualifiedname.ts +144 -0
  61. package/source/json_basic_encoding_decoding_statuscode.ts +151 -0
  62. package/source/json_basic_encoding_decoding_variant.ts +339 -0
  63. package/source/json_encoding_scheme.ts +114 -0
  64. package/LICENSE.md +0 -40
  65. package/dist2/decode_opcua_json.d.ts +0 -12
  66. package/dist2/index.d.ts +0 -17
  67. package/dist2/index.js +0 -1
  68. package/dist2/json_basic_encoding_body_functor.d.ts +0 -15
  69. package/dist2/json_basic_encoding_decoding_byte_string.d.ts +0 -8
  70. package/dist2/json_basic_encoding_decoding_data_value.d.ts +0 -26
  71. package/dist2/json_basic_encoding_decoding_date_time.d.ts +0 -6
  72. package/dist2/json_basic_encoding_decoding_extension_object.d.ts +0 -32
  73. package/dist2/json_basic_encoding_decoding_int64.d.ts +0 -9
  74. package/dist2/json_basic_encoding_decoding_localizedtext.d.ts +0 -14
  75. package/dist2/json_basic_encoding_decoding_nodeid.d.ts +0 -33
  76. package/dist2/json_basic_encoding_decoding_qualifiedname.d.ts +0 -14
  77. package/dist2/json_basic_encoding_decoding_statuscode.d.ts +0 -16
  78. package/dist2/json_basic_encoding_decoding_variant.d.ts +0 -0
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.opcuaJsonEncodeQualifiedName = opcuaJsonEncodeQualifiedName;
4
+ exports.opcuaJsonEncodeQualifiedNameAsString = opcuaJsonEncodeQualifiedNameAsString;
5
+ exports.opcuaJsonDecodeQualifiedName = opcuaJsonDecodeQualifiedName;
6
+ /**
7
+ * ==========================================================================
8
+ * Copyright (c) 2021-2026 Sterfive - etienne.rossignon@sterfive.com
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ * of this software and associated documentation files (the "Software"), to deal
12
+ * in the Software without restriction, including without limitation the rights
13
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ * copies of the Software, and to permit persons to whom the Software is
15
+ * furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in
18
+ * all copies or substantial portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26
+ * IN THE SOFTWARE.
27
+ * ==========================================================================
28
+ */
29
+ const node_opcua_data_model_1 = require("node-opcua-data-model");
30
+ const json_basic_encoding_decoding_nodeid_js_1 = require("./json_basic_encoding_decoding_nodeid.js");
31
+ const json_encoding_scheme_js_1 = require("./json_encoding_scheme.js");
32
+ function opcuaJsonEncodeQualifiedName(qualifiedName, scheme = json_encoding_scheme_js_1.JsonEncodingScheme.Compact, namespaceArray) {
33
+ if (!qualifiedName.name || !qualifiedName.namespaceIndex) {
34
+ if (scheme === json_encoding_scheme_js_1.JsonEncodingScheme.Compact) {
35
+ // Compact encoding does not encode empty QualifiedName
36
+ return undefined;
37
+ }
38
+ }
39
+ const pojo = {
40
+ Name: qualifiedName.name || ""
41
+ };
42
+ /**
43
+ * The NamespaceIndex component of the QualifiedName encoded as a JSON number.
44
+ * The Uri field is omitted if the NamespaceIndex equals 0.
45
+ * For the non-reversible form, the NamespaceUri associated with the NamespaceIndex
46
+ * portion of the QualifiedName is encoded as JSON string unless
47
+ * the NamespaceIndex is 1 or if NamespaceUri is unknown.
48
+ * In these cases, the NamespaceIndex is encoded as a JSON number.
49
+ */
50
+ if (qualifiedName.namespaceIndex === 0) {
51
+ return pojo;
52
+ }
53
+ const reversible = !(scheme === json_encoding_scheme_js_1.JsonEncodingScheme.DeprecatedNonReversible);
54
+ if (reversible || !namespaceArray || qualifiedName.namespaceIndex === 1) {
55
+ pojo.Uri = qualifiedName.namespaceIndex;
56
+ return pojo;
57
+ }
58
+ pojo.Uri = namespaceArray[qualifiedName.namespaceIndex];
59
+ return pojo;
60
+ }
61
+ function opcuaJsonEncodeQualifiedNameAsString(qualifiedName, scheme = json_encoding_scheme_js_1.JsonEncodingScheme.Compact, namespaceArray) {
62
+ const pojo = opcuaJsonEncodeQualifiedName(qualifiedName, scheme, namespaceArray);
63
+ if (!pojo) {
64
+ return "";
65
+ }
66
+ if (!pojo.Uri) {
67
+ // if Uri is not defined, it means namespaceIndex is 0
68
+ return pojo.Name;
69
+ }
70
+ const namespaceIndex = typeof pojo.Uri === "number" ? pojo.Uri : namespaceArray?.indexOf(pojo.Uri);
71
+ if (namespaceIndex !== undefined && namespaceIndex >= 0) {
72
+ const namespaceUri = namespaceArray ? namespaceArray[namespaceIndex] : pojo.Uri;
73
+ const encodedUri = (0, json_basic_encoding_decoding_nodeid_js_1.opcuaEncodeURIComponent)(namespaceUri);
74
+ return `nsu=${encodedUri};${pojo.Name}`;
75
+ }
76
+ return pojo.Name;
77
+ }
78
+ function opcuaJsonDecodeQualifiedName(pojo, builder, namespaceArray) {
79
+ builder; // unused parameter,
80
+ if (!pojo) {
81
+ return new node_opcua_data_model_1.QualifiedName();
82
+ }
83
+ if (typeof pojo === "string") {
84
+ // example:
85
+ // - Hello
86
+ // - Hello;World
87
+ // - 3:Hello:World
88
+ // - nsu=http://widgets.com/schemas/hello;Hello;World
89
+ // - nsu=tag:acme.com,2023:schemas:data#off%3B;Boiler2
90
+ // check if starts with number + ":"
91
+ if (/^\d+:/.test(pojo)) {
92
+ const parts = pojo.split(":");
93
+ const namespaceIndex = parseInt(parts[0], 10);
94
+ const name = parts.slice(1).join(":");
95
+ return new node_opcua_data_model_1.QualifiedName({
96
+ name,
97
+ namespaceIndex
98
+ });
99
+ }
100
+ // check if starts with "nsu=" up tot he next ";"
101
+ if (pojo.startsWith("nsu=")) {
102
+ const endIndex = pojo.indexOf(";");
103
+ if (endIndex === -1) {
104
+ throw new Error(`Invalid QualifiedName format: ${pojo}`);
105
+ }
106
+ const namespaceUri = (0, json_basic_encoding_decoding_nodeid_js_1.opcuaDecodeURIComponent)(pojo.substring(4, endIndex));
107
+ const name = pojo.substring(endIndex + 1);
108
+ const namespaceIndex = namespaceArray ? namespaceArray.indexOf(namespaceUri) : 0;
109
+ return new node_opcua_data_model_1.QualifiedName({
110
+ name,
111
+ namespaceIndex
112
+ });
113
+ }
114
+ // otherwise, treat as a simple name
115
+ return new node_opcua_data_model_1.QualifiedName({
116
+ name: pojo,
117
+ namespaceIndex: 0
118
+ });
119
+ }
120
+ const namespaceIndex = pojo.Uri && typeof pojo.Uri === "number" ? pojo.Uri : 0;
121
+ return new node_opcua_data_model_1.QualifiedName({
122
+ name: pojo.Name,
123
+ namespaceIndex
124
+ });
125
+ }
126
+ //# sourceMappingURL=json_basic_encoding_decoding_qualifiedname.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json_basic_encoding_decoding_qualifiedname.js","sourceRoot":"","sources":["../source/json_basic_encoding_decoding_qualifiedname.ts"],"names":[],"mappings":";;AAiCA,oEAiCC;AACD,oFAqBC;AAED,oEAqDC;AA/ID;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,iEAAsD;AAEtD,qGAA4G;AAC5G,uEAA+D;AAO/D,SAAgB,4BAA4B,CACxC,aAA4B,EAC5B,MAAM,GAAG,4CAAkB,CAAC,OAAO,EACnC,cAAyB;IAEzB,IAAI,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE,CAAC;QACvD,IAAI,MAAM,KAAK,4CAAkB,CAAC,OAAO,EAAE,CAAC;YACxC,uDAAuD;YACvD,OAAO,SAAS,CAAC;QACrB,CAAC;IACL,CAAC;IACD,MAAM,IAAI,GAAsB;QAC5B,IAAI,EAAE,aAAa,CAAC,IAAI,IAAI,EAAE;KACjC,CAAC;IACF;;;;;;;OAOG;IACH,IAAI,aAAa,CAAC,cAAc,KAAK,CAAC,EAAE,CAAC;QACrC,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,MAAM,UAAU,GAA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AAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACjF,OAAO,IAAI,qCAAa,CAAC;gBACrB,IAAI;gBACJ,cAAc;aACjB,CAAC,CAAC;QACP,CAAC;QACD,oCAAoC;QACpC,OAAO,IAAI,qCAAa,CAAC;YACrB,IAAI,EAAE,IAAI;YACV,cAAc,EAAE,CAAC;SACpB,CAAC,CAAC;IACP,CAAC;IACD,MAAM,cAAc,GAAW,IAAI,CAAC,GAAG,IAAI,OAAO,IAAI,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACvF,OAAO,IAAI,qCAAa,CAAC;QACrB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,cAAc;KACjB,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * ==========================================================================
3
+ * Copyright (c) 2021-2026 Sterfive - etienne.rossignon@sterfive.com
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
+ * IN THE SOFTWARE.
22
+ * ==========================================================================
23
+ */
24
+ import { type StatusCode, StatusCodes } from "node-opcua-status-code";
25
+ import { JsonEncoderMode104, JsonEncoderMode105, JsonEncodingScheme } from "./json_encoding_scheme.js";
26
+ export interface StatusCodeJSON {
27
+ Code?: number | keyof StatusCodes;
28
+ Symbol?: string;
29
+ }
30
+ export declare function opcuaJsonEncodeStatusCode104(statusCode: StatusCode, mode: JsonEncoderMode104): StatusCodeJSON | number | undefined;
31
+ export declare function opcuaJsonEncodeStatusCode105(statusCode: StatusCode, mode: JsonEncoderMode105): StatusCodeJSON | number | undefined;
32
+ export declare function opcuaJsonEncodeStatusCode(statusCode: StatusCode, scheme: JsonEncodingScheme): number | StatusCodeJSON | undefined;
33
+ /**
34
+ *
35
+ * @param pojo
36
+ *
37
+ * @returns
38
+ */
39
+ export declare function opcuaJsonDecodeStatusCode(pojo: StatusCodeJSON | number | null | undefined): StatusCode;
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.opcuaJsonEncodeStatusCode104 = opcuaJsonEncodeStatusCode104;
4
+ exports.opcuaJsonEncodeStatusCode105 = opcuaJsonEncodeStatusCode105;
5
+ exports.opcuaJsonEncodeStatusCode = opcuaJsonEncodeStatusCode;
6
+ exports.opcuaJsonDecodeStatusCode = opcuaJsonDecodeStatusCode;
7
+ /**
8
+ * ==========================================================================
9
+ * Copyright (c) 2021-2026 Sterfive - etienne.rossignon@sterfive.com
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights
14
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ * copies of the Software, and to permit persons to whom the Software is
16
+ * furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in
19
+ * all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27
+ * IN THE SOFTWARE.
28
+ * ==========================================================================
29
+ */
30
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
31
+ const json_encoding_scheme_js_1 = require("./json_encoding_scheme.js");
32
+ function opcuaJsonEncodeStatusCode104(statusCode, mode) {
33
+ /*
34
+ * StatusCode values shall be encoded as a JSON number for the reversible encoding.
35
+ */
36
+ if (mode === json_encoding_scheme_js_1.JsonEncoderMode104.Reversible) {
37
+ return statusCode.value;
38
+ }
39
+ /*
40
+ * reference: https://reference.opcfoundation.org/Core/Part6/v104/docs/5.4.2.12
41
+ *
42
+ * For the non-reversible form, StatusCode values shall be encoded as a JSON object with the fields defined in Table
43
+ *
44
+ * Symbol The string literal associated with the numeric code encoded as JSON string.
45
+ *
46
+ * e.g. 0x80AB0000 has the associated literal “BadInvalidArgument”.
47
+ * Any InfoBits in the StatusCode are ignored when looking up the symbol.
48
+ * If the string literal is not known to the encoder the field is omitted.
49
+ * The field is omitted in the CompactEncoding.
50
+ * The field is omitted if the numeric code is 0 (Good).
51
+ */
52
+ /**
53
+ * A StatusCode of Good (0) is treated like a NULL and not encoded.
54
+ * (If it is an element of an JSON array it is encoded as the JSON literal ‘null’. )
55
+ */
56
+ if (statusCode.value === 0) {
57
+ return undefined;
58
+ }
59
+ const pojo = {};
60
+ // The Code is omitted if the numeric code is 0(Good).
61
+ if (statusCode.value !== 0) {
62
+ // The numeric code encoded as a JSON number.
63
+ pojo.Code = statusCode.value;
64
+ }
65
+ // The string literal associated with the numeric code encoded as JSON string.
66
+ // e.g. 0x80AB0000 has the associated literal “BadInvalidArgument”.
67
+ //
68
+ // The Symbol is omitted if the numeric code is 0(Good).
69
+ if (statusCode.value === 0) {
70
+ return pojo; // Good
71
+ }
72
+ const c = (0, node_opcua_status_code_1.coerceStatusCode)(statusCode.value & 0xffff0000); // remove InfoBits and OverflowBit
73
+ pojo.Symbol = c.name;
74
+ return pojo;
75
+ }
76
+ function opcuaJsonEncodeStatusCode105(statusCode, mode) {
77
+ /*
78
+ * For the non-reversible form, StatusCode values shall be encoded as a JSON object with the fields defined in Table
79
+ *
80
+ * Symbol The string literal associated with the numeric code encoded as JSON string.
81
+ */
82
+ const pojo = {};
83
+ if (statusCode.value !== 0) {
84
+ pojo.Code = statusCode.value;
85
+ }
86
+ /*
87
+ * e.g. 0x80AB0000 has the associated literal “BadInvalidArgument”.
88
+ * Any InfoBits in the StatusCode are ignored when looking up the symbol.
89
+ * If the string literal is not known to the encoder the field is omitted.
90
+ * The field is omitted in the CompactEncoding.
91
+ * The field is omitted if the numeric code is 0 (Good).
92
+ */
93
+ if (mode === json_encoding_scheme_js_1.JsonEncoderMode105.Verbose) {
94
+ if (statusCode.value !== 0) {
95
+ const c = (0, node_opcua_status_code_1.coerceStatusCode)(statusCode.value & 0xffff0000); // remove InfoBits and OverflowBit
96
+ if (c?.name) {
97
+ pojo.Symbol = c.name;
98
+ }
99
+ }
100
+ }
101
+ return pojo;
102
+ }
103
+ function opcuaJsonEncodeStatusCode(statusCode, scheme) {
104
+ switch (scheme) {
105
+ case json_encoding_scheme_js_1.JsonEncodingScheme.DeprecatedNonReversible:
106
+ return opcuaJsonEncodeStatusCode104(statusCode, json_encoding_scheme_js_1.JsonEncoderMode104.NonReversible);
107
+ case json_encoding_scheme_js_1.JsonEncodingScheme.DeprecatedReversible:
108
+ return opcuaJsonEncodeStatusCode104(statusCode, json_encoding_scheme_js_1.JsonEncoderMode104.Reversible);
109
+ case json_encoding_scheme_js_1.JsonEncodingScheme.Compact:
110
+ return opcuaJsonEncodeStatusCode105(statusCode, json_encoding_scheme_js_1.JsonEncoderMode105.Compact);
111
+ case json_encoding_scheme_js_1.JsonEncodingScheme.Verbose:
112
+ return opcuaJsonEncodeStatusCode105(statusCode, json_encoding_scheme_js_1.JsonEncoderMode105.Verbose);
113
+ default:
114
+ throw new Error("Unknown JsonEncodingScheme");
115
+ }
116
+ }
117
+ /**
118
+ *
119
+ * @param pojo
120
+ *
121
+ * @returns
122
+ */
123
+ function opcuaJsonDecodeStatusCode(pojo) {
124
+ if (!pojo) {
125
+ return node_opcua_status_code_1.StatusCodes.Good;
126
+ }
127
+ if (typeof pojo === "number") {
128
+ return (0, node_opcua_status_code_1.coerceStatusCode)(pojo);
129
+ }
130
+ if (typeof pojo.Code === "number") {
131
+ return (0, node_opcua_status_code_1.coerceStatusCode)(pojo.Code);
132
+ }
133
+ if (!pojo.Code) {
134
+ // to trap undefined or null Code
135
+ return node_opcua_status_code_1.StatusCodes.Good;
136
+ }
137
+ return (0, node_opcua_status_code_1.coerceStatusCode)(pojo.Code);
138
+ }
139
+ //# sourceMappingURL=json_basic_encoding_decoding_statuscode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json_basic_encoding_decoding_statuscode.js","sourceRoot":"","sources":["../source/json_basic_encoding_decoding_statuscode.ts"],"names":[],"mappings":";;AA+BA,oEAgDC;AAED,oEA+BC;AAED,8DAaC;AAQD,8DAeC;AAtJD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,mEAAwF;AACxF,uEAAuG;AAOvG,SAAgB,4BAA4B,CACxC,UAAsB,EACtB,IAAwB;IAExB;;OAEG;IACH,IAAI,IAAI,KAAK,4CAAkB,CAAC,UAAU,EAAE,CAAC;QACzC,OAAO,UAAU,CAAC,KAAK,CAAC;IAC5B,C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================================================
3
+ * Copyright (c) 2021-2026 Sterfive - etienne.rossignon@sterfive.com
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
+ * IN THE SOFTWARE.
22
+ * ==========================================================================
23
+ */
24
+ import { DataType, Variant } from "node-opcua-variant";
25
+ import type { Pojo } from "./decode_opcua_json.js";
26
+ import { type ExtensionObjectBuilder } from "./json_basic_encoding_body_functor.js";
27
+ import { JsonEncoderMode104, JsonEncoderMode105, JsonEncodingScheme } from "./json_encoding_scheme.js";
28
+ export type VariantJSONBodyScalar = Pojo | number | string | boolean | null | Date;
29
+ export type VariantJSONBody = VariantJSONBodyScalar | VariantJSONBodyScalar[];
30
+ export interface VariantJSON104 {
31
+ /**
32
+ * The Built-in type for the value contained in the Body encoded as JSON number.
33
+ * If type is 0 (NULL) the Variant contains a NULL value and the containing JSON
34
+ * object shall be omitted or replaced by the JSON literal ‘null’ (when an element of a JSON array).
35
+ */
36
+ Type: DataType;
37
+ /**
38
+ * If the value is a scalar it is encoded using the rules for type specified for the Type.
39
+ * If the value is a one-dimensional array it is encoded as JSON array.
40
+ * Multi-dimensional arrays are encoded as a one dimensional JSON array which is
41
+ * reconstructed using the value of the Dimensions field (see 5.2.2.16).
42
+ */
43
+ Body: VariantJSONBody;
44
+ /**
45
+ * The dimensions of the array encoded as an JSON array of JSON numbers.
46
+ * The Dimensions are omitted for scalar and one-dimensional array values.
47
+ */
48
+ Dimensions?: number[];
49
+ }
50
+ export interface VariantJSON105 {
51
+ /**
52
+ * The Built-in type for the value contained in the Body (see Table 1) encoded as JSON number.
53
+ */
54
+ UaType: DataType;
55
+ /**
56
+ * If the value is a scalar, it is encoded using the rules for type specified for the Type.
57
+ *
58
+ * If the value is a one-dimensional array it is e const Value = body(variant, scheme, builder, namespaceArray);
59
+ ncoded as JSON array (see 5.4.5)
60
+ *
61
+ * Multi-dimensional arrays are encoded as a JSON array containing all elements.
62
+ * The mapping of a multidimensional array to a flat list is described in 5.2.2.16.
63
+ * The field is not encoded if the value is a NULL for nullable Built-in types (see Table 1)
64
+ *
65
+ * 5.4.5
66
+ *
67
+ * One dimensional Arrays shall be encoded as JSON arrays.
68
+ * If an element is NULL, the element shall be encoded as the JSON literal ‘null’.
69
+ * Otherwise, the element is encoded according to the rules defined for the type.
70
+ *
71
+ * Multidimensional Arrays are encoded as JSON object with the fields defined in
72
+ * Table 43.
73
+ *
74
+ * Table 43.
75
+ * Name Description const Value = body(variant, scheme, builder, namespaceArray);
76
+
77
+ * --------- ---------------------------------------------------
78
+ * Array Multi-dimensional arrays are encoded as a one-dimensional
79
+ * JSON array which is reconstructed using the value of the
80
+ * Dimensions field (see 5.2.2.16).
81
+ * Dimensions The dimensions of the array encoded as a JSON array of JSON numbers.
82
+ */
83
+ Value?: VariantJSONBody;
84
+ /**
85
+ * The dimensions of the array encoded as a JSON array of JSON numbers.
86
+ */
87
+ UaDimensions?: number[];
88
+ }
89
+ export type VariantJSON = (VariantJSON104 & {
90
+ UaType: undefined;
91
+ }) | (VariantJSON105 & {
92
+ Type: undefined;
93
+ });
94
+ export declare function opcuaJsonEncodeVariant105(variant: Variant, mode: JsonEncoderMode105, namespaceArray?: string[]): VariantJSON105;
95
+ export declare function opcuaJsonEncodeVariant104(variant: Variant, mode: JsonEncoderMode104 | undefined, namespaceArray: string[]): VariantJSON104 | VariantJSONBody | null;
96
+ export declare function opcuaJsonEncodeVariant(variant: Variant, scheme: JsonEncodingScheme.Compact | JsonEncodingScheme.Verbose, namespaceArray: string[]): VariantJSONBody | null;
97
+ export declare function opcuaJsonEncodeVariant(variant: Variant, scheme: JsonEncodingScheme.Verbose, namespaceArray: string[]): VariantJSON105;
98
+ export declare function opcuaJsonEncodeVariant(variant: Variant, scheme: JsonEncodingScheme.DeprecatedNonReversible | JsonEncodingScheme.DeprecatedReversible, namespaceArray: string[]): VariantJSON104 | null;
99
+ export declare function opcuaJsonDecodeVariant104(pojo: VariantJSON104 | null | undefined, builder: ExtensionObjectBuilder, namespaceArray: string[]): Variant;
100
+ export declare function opcuaJsonDecodeVariant105(pojo: VariantJSON105 | null | undefined, builder: ExtensionObjectBuilder, namespaceArray: string[]): Variant;
101
+ export declare function opcuaJsonDecodeVariant(pojo: VariantJSON105 | VariantJSON104 | null | undefined, builder: ExtensionObjectBuilder, namespaceArray: string[]): Variant;
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.opcuaJsonEncodeVariant105 = opcuaJsonEncodeVariant105;
4
+ exports.opcuaJsonEncodeVariant104 = opcuaJsonEncodeVariant104;
5
+ exports.opcuaJsonEncodeVariant = opcuaJsonEncodeVariant;
6
+ exports.opcuaJsonDecodeVariant104 = opcuaJsonDecodeVariant104;
7
+ exports.opcuaJsonDecodeVariant105 = opcuaJsonDecodeVariant105;
8
+ exports.opcuaJsonDecodeVariant = opcuaJsonDecodeVariant;
9
+ /**
10
+ * ==========================================================================
11
+ * Copyright (c) 2021-2026 Sterfive - etienne.rossignon@sterfive.com
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ * copies of the Software, and to permit persons to whom the Software is
18
+ * furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in
21
+ * all copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29
+ * IN THE SOFTWARE.
30
+ * ==========================================================================
31
+ */
32
+ const node_opcua_variant_1 = require("node-opcua-variant");
33
+ const json_basic_encoding_body_functor_js_1 = require("./json_basic_encoding_body_functor.js");
34
+ const json_encoding_scheme_js_1 = require("./json_encoding_scheme.js");
35
+ // Array
36
+ // If an element is NULL, the element shall be encoded as the JSON literal ‘null’.
37
+ // Otherwise, the element is encoded according to the rules defined for the type.
38
+ // Multi-dimensional Arrays are encoded as nested JSON arrays.
39
+ // The outer array is the first dimension and the innermost array is the last dimension.
40
+ function body(variant, scheme, namespaceArray) {
41
+ const f = (0, json_basic_encoding_body_functor_js_1.bodyEncodeFunctor)(variant.dataType);
42
+ if (variant.arrayType === node_opcua_variant_1.VariantArrayType.Scalar) {
43
+ return f(variant.value, scheme, namespaceArray);
44
+ }
45
+ else {
46
+ const array = [];
47
+ for (const e of variant.value) {
48
+ array.push(f(e, scheme, namespaceArray));
49
+ }
50
+ return array;
51
+ }
52
+ }
53
+ function opcuaJsonEncodeVariant105(variant, mode, namespaceArray) {
54
+ /**
55
+ * For the non-reversible form, Variant values shall be encoded as a JSON object containing only
56
+ * the value of the Body field. The Type and Dimensions fields are dropped. Multi-dimensional
57
+ * arrays are encoded as a multi dimensional JSON array.
58
+ */
59
+ if (variant.dataType === node_opcua_variant_1.DataType.Null && variant.arrayType === node_opcua_variant_1.VariantArrayType.Scalar) {
60
+ if (mode === json_encoding_scheme_js_1.JsonEncoderMode105.Compact) {
61
+ return {
62
+ UaType: node_opcua_variant_1.DataType.Null
63
+ };
64
+ }
65
+ else {
66
+ return { UaType: node_opcua_variant_1.DataType.Null, Value: null };
67
+ }
68
+ }
69
+ const scheme = mode === json_encoding_scheme_js_1.JsonEncoderMode105.Compact ? json_encoding_scheme_js_1.JsonEncodingScheme.Compact : json_encoding_scheme_js_1.JsonEncodingScheme.Verbose;
70
+ const Value = body(variant, scheme, namespaceArray);
71
+ const pojo = {
72
+ UaType: variant.dataType
73
+ // Value: body(variant, scheme, namespaceArray),
74
+ };
75
+ if (Value !== undefined) {
76
+ pojo.Value = Value;
77
+ }
78
+ if (variant.arrayType === node_opcua_variant_1.VariantArrayType.Matrix && variant.dimensions) {
79
+ pojo.UaDimensions = [...variant.dimensions];
80
+ }
81
+ if (mode === json_encoding_scheme_js_1.JsonEncoderMode105.Compact && variant.arrayType === node_opcua_variant_1.VariantArrayType.Scalar) {
82
+ // remove default values for compact encoding
83
+ switch (variant.dataType) {
84
+ case node_opcua_variant_1.DataType.Boolean:
85
+ if (pojo.Value === false) {
86
+ // remove false value for compact encoding
87
+ delete pojo.Value;
88
+ }
89
+ break;
90
+ case node_opcua_variant_1.DataType.SByte:
91
+ case node_opcua_variant_1.DataType.Byte:
92
+ case node_opcua_variant_1.DataType.Int16:
93
+ case node_opcua_variant_1.DataType.UInt16:
94
+ case node_opcua_variant_1.DataType.Int32:
95
+ case node_opcua_variant_1.DataType.UInt32:
96
+ case node_opcua_variant_1.DataType.Float:
97
+ case node_opcua_variant_1.DataType.Double:
98
+ if (pojo.Value === 0) {
99
+ // remove 0 value for compact encoding
100
+ delete pojo.Value;
101
+ }
102
+ break;
103
+ case node_opcua_variant_1.DataType.String:
104
+ if (pojo.Value === "") {
105
+ // remove empty string for compact encoding
106
+ delete pojo.Value;
107
+ }
108
+ break;
109
+ case node_opcua_variant_1.DataType.Int64:
110
+ case node_opcua_variant_1.DataType.UInt64:
111
+ case node_opcua_variant_1.DataType.DateTime:
112
+ case node_opcua_variant_1.DataType.Guid:
113
+ case node_opcua_variant_1.DataType.ByteString:
114
+ case node_opcua_variant_1.DataType.XmlElement:
115
+ case node_opcua_variant_1.DataType.NodeId:
116
+ case node_opcua_variant_1.DataType.QualifiedName:
117
+ case node_opcua_variant_1.DataType.LocalizedText:
118
+ case node_opcua_variant_1.DataType.ExtensionObject:
119
+ case node_opcua_variant_1.DataType.StatusCode:
120
+ // these are all scalar types, so we can remove the UaType
121
+ // delete pojo.UaType;
122
+ break;
123
+ }
124
+ }
125
+ return pojo;
126
+ }
127
+ function opcuaJsonEncodeVariant104(variant, mode = json_encoding_scheme_js_1.JsonEncoderMode104.NonReversible, namespaceArray) {
128
+ /**
129
+ * For the non-reversible form, Variant values shall be encoded as a JSON object containing only
130
+ * the value of the Body field. The Type and Dimensions fields are dropped. Multi-dimensional
131
+ * arrays are encoded as a multi dimensional JSON array.
132
+ */
133
+ if (variant.dataType === node_opcua_variant_1.DataType.Null) {
134
+ return null;
135
+ }
136
+ const reversible = mode === json_encoding_scheme_js_1.JsonEncoderMode104.Reversible;
137
+ const scheme = mode === json_encoding_scheme_js_1.JsonEncoderMode104.Reversible
138
+ ? json_encoding_scheme_js_1.JsonEncodingScheme.DeprecatedReversible
139
+ : json_encoding_scheme_js_1.JsonEncodingScheme.DeprecatedNonReversible;
140
+ if (!reversible && variant.arrayType !== node_opcua_variant_1.VariantArrayType.Matrix) {
141
+ return body(variant, scheme, namespaceArray);
142
+ }
143
+ const pojo = {
144
+ Type: variant.dataType,
145
+ Body: body(variant, scheme, namespaceArray)
146
+ };
147
+ if (variant.arrayType === node_opcua_variant_1.VariantArrayType.Matrix && variant.dimensions) {
148
+ pojo.Dimensions = [...variant.dimensions];
149
+ }
150
+ return pojo;
151
+ }
152
+ function opcuaJsonEncodeVariant(variant, scheme = json_encoding_scheme_js_1.JsonEncodingScheme.Compact, namespaceArray) {
153
+ switch (scheme) {
154
+ case json_encoding_scheme_js_1.JsonEncodingScheme.Compact:
155
+ return opcuaJsonEncodeVariant105(variant, json_encoding_scheme_js_1.JsonEncoderMode105.Compact, namespaceArray);
156
+ case json_encoding_scheme_js_1.JsonEncodingScheme.Verbose:
157
+ return opcuaJsonEncodeVariant105(variant, json_encoding_scheme_js_1.JsonEncoderMode105.Verbose, namespaceArray);
158
+ case json_encoding_scheme_js_1.JsonEncodingScheme.DeprecatedReversible:
159
+ return opcuaJsonEncodeVariant104(variant, json_encoding_scheme_js_1.JsonEncoderMode104.Reversible, namespaceArray);
160
+ case json_encoding_scheme_js_1.JsonEncodingScheme.DeprecatedNonReversible:
161
+ return opcuaJsonEncodeVariant104(variant, json_encoding_scheme_js_1.JsonEncoderMode104.NonReversible, namespaceArray);
162
+ default:
163
+ throw new Error("Unknown JsonEncodingScheme");
164
+ }
165
+ }
166
+ function opcuaJsonDecodeVariant104(pojo, builder, namespaceArray) {
167
+ if (!pojo) {
168
+ return new node_opcua_variant_1.Variant({ dataType: node_opcua_variant_1.DataType.Null });
169
+ }
170
+ const dataType = pojo.Type;
171
+ const f = (0, json_basic_encoding_body_functor_js_1.bodyDecodeFunctor)(dataType);
172
+ if (Array.isArray(pojo.Body)) {
173
+ const value = pojo.Body.map((a) => f(a, builder, namespaceArray));
174
+ if (pojo.Dimensions) {
175
+ return new node_opcua_variant_1.Variant({
176
+ arrayType: node_opcua_variant_1.VariantArrayType.Matrix,
177
+ dimensions: pojo.Dimensions,
178
+ dataType,
179
+ value
180
+ });
181
+ }
182
+ return new node_opcua_variant_1.Variant({
183
+ arrayType: node_opcua_variant_1.VariantArrayType.Array,
184
+ dataType,
185
+ value
186
+ });
187
+ }
188
+ return new node_opcua_variant_1.Variant({
189
+ dataType,
190
+ arrayType: node_opcua_variant_1.VariantArrayType.Scalar,
191
+ value: f ? f(pojo.Body, builder, namespaceArray) : null
192
+ });
193
+ }
194
+ function opcuaJsonDecodeVariant105(pojo, builder, namespaceArray) {
195
+ if (!pojo) {
196
+ return new node_opcua_variant_1.Variant({ dataType: node_opcua_variant_1.DataType.Null });
197
+ }
198
+ const dataType = pojo.UaType;
199
+ const f = (0, json_basic_encoding_body_functor_js_1.bodyDecodeFunctor)(dataType);
200
+ if (Array.isArray(pojo.Value)) {
201
+ const value = pojo.Value.map((a) => f(a, builder, namespaceArray));
202
+ if (pojo.UaDimensions) {
203
+ return new node_opcua_variant_1.Variant({
204
+ arrayType: node_opcua_variant_1.VariantArrayType.Matrix,
205
+ dimensions: pojo.UaDimensions,
206
+ dataType,
207
+ value
208
+ });
209
+ }
210
+ return new node_opcua_variant_1.Variant({
211
+ arrayType: node_opcua_variant_1.VariantArrayType.Array,
212
+ dataType,
213
+ value
214
+ });
215
+ }
216
+ return new node_opcua_variant_1.Variant({
217
+ dataType,
218
+ arrayType: node_opcua_variant_1.VariantArrayType.Scalar,
219
+ value: f ? f(pojo.Value, builder, namespaceArray) : null
220
+ });
221
+ }
222
+ function opcuaJsonDecodeVariant(pojo, builder, namespaceArray) {
223
+ if (!pojo) {
224
+ return new node_opcua_variant_1.Variant({ dataType: node_opcua_variant_1.DataType.Null });
225
+ }
226
+ if ("Type" in pojo || !("UaType" in pojo)) {
227
+ return opcuaJsonDecodeVariant104(pojo, builder, namespaceArray);
228
+ }
229
+ else if ("UaType" in pojo) {
230
+ return opcuaJsonDecodeVariant105(pojo, builder, namespaceArray);
231
+ }
232
+ throw new Error("Invalid Variant JSON format");
233
+ }
234
+ //# sourceMappingURL=json_basic_encoding_decoding_variant.js.map