node-opcua-xml2json 2.64.0 → 2.64.1

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.
@@ -1,240 +1,240 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeExtensionObjectReader = void 0;
4
- const node_opcua_utils_1 = require("node-opcua-utils");
5
- const xml2json_1 = require("./xml2json");
6
- function BasicType_parser(dataType, parseFunc) {
7
- const r = {
8
- init(elementName, attrs) {
9
- this.value = undefined;
10
- },
11
- finish() {
12
- this.value = parseFunc.call(this, this.text);
13
- }
14
- };
15
- const _parser = {};
16
- _parser[dataType] = r;
17
- return _parser;
18
- }
19
- function ListOf(dataType, parseFunc) {
20
- return {
21
- init() {
22
- this.value = [];
23
- },
24
- parser: BasicType_parser(dataType, parseFunc),
25
- finish() {
26
- /** empty */
27
- },
28
- endElement(elementName) {
29
- this.value.push(this.parser[elementName].value);
30
- }
31
- };
32
- }
33
- const localizedTextReader = {
34
- init() {
35
- this.localizedText = {};
36
- },
37
- parser: {
38
- Locale: {
39
- finish() {
40
- this.parent.localizedText = this.parent.localizedText || {};
41
- this.parent.localizedText.locale = this.text.trim();
42
- }
43
- },
44
- Text: {
45
- finish() {
46
- this.parent.localizedText = this.parent.localizedText || {};
47
- this.parent.localizedText.text = this.text.trim();
48
- }
49
- }
50
- },
51
- finish() {
52
- this.value = this.localizedText;
53
- }
54
- };
55
- const partials = {
56
- LocalizedText: localizedTextReader,
57
- String: {
58
- finish() {
59
- this.value = this.text;
60
- }
61
- },
62
- Boolean: {
63
- finish() {
64
- this.value = this.text.toLowerCase() === "true";
65
- }
66
- },
67
- ByteString: {
68
- init() {
69
- this.value = null;
70
- },
71
- finish() {
72
- const base64text = this.text;
73
- const byteString = Buffer.from(base64text, "base64");
74
- this.value = byteString;
75
- }
76
- },
77
- Float: {
78
- finish() {
79
- this.value = parseFloat(this.text);
80
- }
81
- },
82
- Double: {
83
- finish() {
84
- this.value = parseFloat(this.text);
85
- }
86
- },
87
- Int8: {
88
- finish() {
89
- this.value = parseInt(this.text, 10);
90
- }
91
- },
92
- Int16: {
93
- finish() {
94
- this.value = parseInt(this.text, 10);
95
- }
96
- },
97
- Int32: {
98
- finish() {
99
- this.value = parseInt(this.text, 10);
100
- }
101
- },
102
- Int64: {
103
- finish() {
104
- this.value = parseInt(this.text, 10);
105
- }
106
- },
107
- UInt8: {
108
- finish() {
109
- this.value = parseInt(this.text, 10);
110
- }
111
- },
112
- UInt16: {
113
- finish() {
114
- this.value = parseInt(this.text, 10);
115
- }
116
- },
117
- UInt32: {
118
- finish() {
119
- this.value = parseInt(this.text, 10);
120
- }
121
- },
122
- UInt64: {
123
- finish() {
124
- this.value = parseInt(this.text, 10);
125
- }
126
- },
127
- ListOfLocalizedText: {
128
- init() {
129
- this.value = [];
130
- },
131
- parser: { LocalizedText: localizedTextReader },
132
- finish() {
133
- /** empty */
134
- },
135
- endElement() {
136
- this.value.push(this.parser.LocalizedText.value);
137
- }
138
- },
139
- ListOfDouble: ListOf("Double", parseFloat),
140
- ListOfFloat: ListOf("Float", parseFloat),
141
- ListOfInt32: ListOf("Int32", parseInt),
142
- ListOfInt16: ListOf("Int16", parseInt),
143
- ListOfInt8: ListOf("Int8", parseInt),
144
- ListOfUint32: ListOf("Uint32", parseInt),
145
- ListOfUint16: ListOf("Uint16", parseInt),
146
- ListOfUint8: ListOf("Uint8", parseInt)
147
- };
148
- function _clone(a) {
149
- if (typeof a === "string" || typeof a === "number" || typeof a === "boolean") {
150
- return a;
151
- }
152
- if (a instanceof Array) {
153
- return a.map((x) => _clone(x));
154
- }
155
- return Object.assign({}, a);
156
- }
157
- function _makeExtensionObjectReader(definitionName, definitionMap, readerMap) {
158
- // is it a basic type ?
159
- if (Object.prototype.hasOwnProperty.call(partials, definitionName)) {
160
- return partials[definitionName];
161
- }
162
- let reader = readerMap[definitionName];
163
- if (reader) {
164
- return reader;
165
- }
166
- const definition = definitionMap.findDefinition(definitionName);
167
- if (!definition) {
168
- throw new Error("cannot find definition for " + definitionName);
169
- }
170
- reader = {
171
- finish() {
172
- /** empty */
173
- },
174
- parser: {}
175
- };
176
- for (const field of definition.fields) {
177
- const fieldReader = _makeExtensionObjectReader(field.dataType, definitionMap, readerMap);
178
- if (!fieldReader) {
179
- throw new Error(" Cannot find reader for dataType " + field.dataType);
180
- }
181
- if (field.valueRank === undefined || field.valueRank === -1) {
182
- const parser = fieldReader;
183
- if (!parser) {
184
- throw new Error("??? " + field.dataType + " " + field.name);
185
- }
186
- reader.parser[field.name] = {
187
- parser: fieldReader.parser,
188
- // endElement: fieldReader.endElement,
189
- finish() {
190
- const elName = (0, node_opcua_utils_1.lowerFirstLetter)(field.name);
191
- fieldReader.finish.call(this);
192
- this.parent.value = this.parent.value || {};
193
- this.parent.value[elName] = _clone(this.value);
194
- }
195
- };
196
- }
197
- else if (field.valueRank === 1) {
198
- const listReader = {
199
- init() {
200
- this.value = [];
201
- },
202
- parser: {},
203
- finish() {
204
- const elName = (0, node_opcua_utils_1.lowerFirstLetter)(this.name);
205
- this.parent.value = this.parent.value || {};
206
- this.parent.value[elName] = this.value;
207
- this.value = undefined;
208
- },
209
- startElement(name, attrs) {
210
- // empty
211
- },
212
- endElement(element) {
213
- this.value.push(_clone(this.parser[element].value));
214
- }
215
- };
216
- listReader.parser[field.dataType] = fieldReader;
217
- reader.parser[field.name] = listReader;
218
- }
219
- else {
220
- throw new Error("Unsupported ValueRank !");
221
- }
222
- }
223
- // xx const parser: ParserLike = {};
224
- // xx parser[definition.name] = reader;
225
- readerMap[definitionName] = reader;
226
- return reader;
227
- }
228
- function makeExtensionObjectReader(definitionName, definitionMap, readerMap) {
229
- const reader1 = {
230
- parser: {},
231
- endElement() {
232
- // console.log(this.parser[definitionName].value);
233
- this._pojo = this.parser[definitionName].value;
234
- }
235
- };
236
- reader1.parser[definitionName] = _makeExtensionObjectReader(definitionName, definitionMap, readerMap);
237
- return new xml2json_1.ReaderState(reader1);
238
- }
239
- exports.makeExtensionObjectReader = makeExtensionObjectReader;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeExtensionObjectReader = void 0;
4
+ const node_opcua_utils_1 = require("node-opcua-utils");
5
+ const xml2json_1 = require("./xml2json");
6
+ function BasicType_parser(dataType, parseFunc) {
7
+ const r = {
8
+ init(elementName, attrs) {
9
+ this.value = undefined;
10
+ },
11
+ finish() {
12
+ this.value = parseFunc.call(this, this.text);
13
+ }
14
+ };
15
+ const _parser = {};
16
+ _parser[dataType] = r;
17
+ return _parser;
18
+ }
19
+ function ListOf(dataType, parseFunc) {
20
+ return {
21
+ init() {
22
+ this.value = [];
23
+ },
24
+ parser: BasicType_parser(dataType, parseFunc),
25
+ finish() {
26
+ /** empty */
27
+ },
28
+ endElement(elementName) {
29
+ this.value.push(this.parser[elementName].value);
30
+ }
31
+ };
32
+ }
33
+ const localizedTextReader = {
34
+ init() {
35
+ this.localizedText = {};
36
+ },
37
+ parser: {
38
+ Locale: {
39
+ finish() {
40
+ this.parent.localizedText = this.parent.localizedText || {};
41
+ this.parent.localizedText.locale = this.text.trim();
42
+ }
43
+ },
44
+ Text: {
45
+ finish() {
46
+ this.parent.localizedText = this.parent.localizedText || {};
47
+ this.parent.localizedText.text = this.text.trim();
48
+ }
49
+ }
50
+ },
51
+ finish() {
52
+ this.value = this.localizedText;
53
+ }
54
+ };
55
+ const partials = {
56
+ LocalizedText: localizedTextReader,
57
+ String: {
58
+ finish() {
59
+ this.value = this.text;
60
+ }
61
+ },
62
+ Boolean: {
63
+ finish() {
64
+ this.value = this.text.toLowerCase() === "true";
65
+ }
66
+ },
67
+ ByteString: {
68
+ init() {
69
+ this.value = null;
70
+ },
71
+ finish() {
72
+ const base64text = this.text;
73
+ const byteString = Buffer.from(base64text, "base64");
74
+ this.value = byteString;
75
+ }
76
+ },
77
+ Float: {
78
+ finish() {
79
+ this.value = parseFloat(this.text);
80
+ }
81
+ },
82
+ Double: {
83
+ finish() {
84
+ this.value = parseFloat(this.text);
85
+ }
86
+ },
87
+ Int8: {
88
+ finish() {
89
+ this.value = parseInt(this.text, 10);
90
+ }
91
+ },
92
+ Int16: {
93
+ finish() {
94
+ this.value = parseInt(this.text, 10);
95
+ }
96
+ },
97
+ Int32: {
98
+ finish() {
99
+ this.value = parseInt(this.text, 10);
100
+ }
101
+ },
102
+ Int64: {
103
+ finish() {
104
+ this.value = parseInt(this.text, 10);
105
+ }
106
+ },
107
+ UInt8: {
108
+ finish() {
109
+ this.value = parseInt(this.text, 10);
110
+ }
111
+ },
112
+ UInt16: {
113
+ finish() {
114
+ this.value = parseInt(this.text, 10);
115
+ }
116
+ },
117
+ UInt32: {
118
+ finish() {
119
+ this.value = parseInt(this.text, 10);
120
+ }
121
+ },
122
+ UInt64: {
123
+ finish() {
124
+ this.value = parseInt(this.text, 10);
125
+ }
126
+ },
127
+ ListOfLocalizedText: {
128
+ init() {
129
+ this.value = [];
130
+ },
131
+ parser: { LocalizedText: localizedTextReader },
132
+ finish() {
133
+ /** empty */
134
+ },
135
+ endElement() {
136
+ this.value.push(this.parser.LocalizedText.value);
137
+ }
138
+ },
139
+ ListOfDouble: ListOf("Double", parseFloat),
140
+ ListOfFloat: ListOf("Float", parseFloat),
141
+ ListOfInt32: ListOf("Int32", parseInt),
142
+ ListOfInt16: ListOf("Int16", parseInt),
143
+ ListOfInt8: ListOf("Int8", parseInt),
144
+ ListOfUint32: ListOf("Uint32", parseInt),
145
+ ListOfUint16: ListOf("Uint16", parseInt),
146
+ ListOfUint8: ListOf("Uint8", parseInt)
147
+ };
148
+ function _clone(a) {
149
+ if (typeof a === "string" || typeof a === "number" || typeof a === "boolean") {
150
+ return a;
151
+ }
152
+ if (a instanceof Array) {
153
+ return a.map((x) => _clone(x));
154
+ }
155
+ return Object.assign({}, a);
156
+ }
157
+ function _makeExtensionObjectReader(definitionName, definitionMap, readerMap) {
158
+ // is it a basic type ?
159
+ if (Object.prototype.hasOwnProperty.call(partials, definitionName)) {
160
+ return partials[definitionName];
161
+ }
162
+ let reader = readerMap[definitionName];
163
+ if (reader) {
164
+ return reader;
165
+ }
166
+ const definition = definitionMap.findDefinition(definitionName);
167
+ if (!definition) {
168
+ throw new Error("cannot find definition for " + definitionName);
169
+ }
170
+ reader = {
171
+ finish() {
172
+ /** empty */
173
+ },
174
+ parser: {}
175
+ };
176
+ for (const field of definition.fields) {
177
+ const fieldReader = _makeExtensionObjectReader(field.dataType, definitionMap, readerMap);
178
+ if (!fieldReader) {
179
+ throw new Error(" Cannot find reader for dataType " + field.dataType);
180
+ }
181
+ if (field.valueRank === undefined || field.valueRank === -1) {
182
+ const parser = fieldReader;
183
+ if (!parser) {
184
+ throw new Error("??? " + field.dataType + " " + field.name);
185
+ }
186
+ reader.parser[field.name] = {
187
+ parser: fieldReader.parser,
188
+ // endElement: fieldReader.endElement,
189
+ finish() {
190
+ const elName = (0, node_opcua_utils_1.lowerFirstLetter)(field.name);
191
+ fieldReader.finish.call(this);
192
+ this.parent.value = this.parent.value || {};
193
+ this.parent.value[elName] = _clone(this.value);
194
+ }
195
+ };
196
+ }
197
+ else if (field.valueRank === 1) {
198
+ const listReader = {
199
+ init() {
200
+ this.value = [];
201
+ },
202
+ parser: {},
203
+ finish() {
204
+ const elName = (0, node_opcua_utils_1.lowerFirstLetter)(this.name);
205
+ this.parent.value = this.parent.value || {};
206
+ this.parent.value[elName] = this.value;
207
+ this.value = undefined;
208
+ },
209
+ startElement(name, attrs) {
210
+ // empty
211
+ },
212
+ endElement(element) {
213
+ this.value.push(_clone(this.parser[element].value));
214
+ }
215
+ };
216
+ listReader.parser[field.dataType] = fieldReader;
217
+ reader.parser[field.name] = listReader;
218
+ }
219
+ else {
220
+ throw new Error("Unsupported ValueRank !");
221
+ }
222
+ }
223
+ // xx const parser: ParserLike = {};
224
+ // xx parser[definition.name] = reader;
225
+ readerMap[definitionName] = reader;
226
+ return reader;
227
+ }
228
+ function makeExtensionObjectReader(definitionName, definitionMap, readerMap) {
229
+ const reader1 = {
230
+ parser: {},
231
+ endElement() {
232
+ // console.log(this.parser[definitionName].value);
233
+ this._pojo = this.parser[definitionName].value;
234
+ }
235
+ };
236
+ reader1.parser[definitionName] = _makeExtensionObjectReader(definitionName, definitionMap, readerMap);
237
+ return new xml2json_1.ReaderState(reader1);
238
+ }
239
+ exports.makeExtensionObjectReader = makeExtensionObjectReader;
240
240
  //# sourceMappingURL=extension_object_parser.js.map
@@ -0,0 +1,20 @@
1
+ import { Xml2Json, XmlAttributes, IReaderState } from "./xml2json";
2
+ export declare class InternalFragmentClonerReaderState implements IReaderState {
3
+ private _xw;
4
+ value: any;
5
+ initLevel: number;
6
+ engine?: Xml2Json;
7
+ _on_startElement(level: number, elementName: string, attrs: XmlAttributes): void;
8
+ _on_endElement(level: number, elementName: string): void;
9
+ _on_init(elementName: string, attrs: XmlAttributes, parent: IReaderState, level: number, engine: Xml2Json): void;
10
+ _on_finish(): void;
11
+ _on_endElement2(level: number, elementName: string): void;
12
+ _on_text(text: string): void;
13
+ }
14
+ export declare class FragmentClonerParser {
15
+ value: any;
16
+ private _cloneFragment?;
17
+ constructor();
18
+ startElement(this: any, elementName: string, attrs: XmlAttributes): void;
19
+ finish(): void;
20
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const XMLWriter = require("xml-writer");
4
+ class InternalFragmentClonerReaderState {
5
+ constructor() {
6
+ this._xw = new XMLWriter(true);
7
+ this.initLevel = 0;
8
+ }
9
+ _on_startElement(level, elementName, attrs) {
10
+ this._xw.startElement(elementName);
11
+ for (const [attName, attValue] of Object.entries(attrs)) {
12
+ this._xw.writeAttribute(attName, attValue);
13
+ }
14
+ }
15
+ _on_endElement(level, elementName) {
16
+ this._xw.endElement();
17
+ if (this.initLevel === level) {
18
+ this.value = this._xw.toString();
19
+ this.engine._demote(this, this.engine.currentLevel, elementName);
20
+ this.engine = undefined;
21
+ this._on_finish();
22
+ }
23
+ }
24
+ _on_init(elementName, attrs, parent, level, engine) {
25
+ this.engine = engine;
26
+ this.initLevel = level;
27
+ this._xw = new XMLWriter(true);
28
+ this._xw.startElement(elementName);
29
+ for (const [attName, attValue] of Object.entries(attrs)) {
30
+ this._xw.writeAttribute(attName, attValue);
31
+ }
32
+ }
33
+ _on_finish() {
34
+ }
35
+ _on_endElement2(level, elementName) {
36
+ }
37
+ _on_text(text) {
38
+ this._xw.text(text);
39
+ }
40
+ }
41
+ exports.InternalFragmentClonerReaderState = InternalFragmentClonerReaderState;
42
+ class FragmentClonerParser {
43
+ constructor() {
44
+ }
45
+ startElement(elementName, attrs) {
46
+ this._cloneFragment = new InternalFragmentClonerReaderState();
47
+ this.engine._promote(this._cloneFragment, this.engine.currentLevel, elementName, attrs);
48
+ }
49
+ finish() {
50
+ this.value = this._cloneFragment.value;
51
+ this._cloneFragment.value = null;
52
+ }
53
+ }
54
+ exports.FragmentClonerParser = FragmentClonerParser;
55
+ //# sourceMappingURL=fragmentCloner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fragmentCloner.js","sourceRoot":"","sources":["../../source/fragmentCloner.ts"],"names":[],"mappings":";;AAkBA,MAAM,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAExC,MAAa,iCAAiC;IAA9C;QACY,QAAG,GAAc,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;QAEtC,cAAS,GAAU,CAAC,CAAC;IAkChC,CAAC;IA/BU,gBAAgB,CAAC,KAAa,EAAE,WAAmB,EAAE,KAAoB;QAC5E,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QACnC,KAAI,MAAM,CAAE,OAAO,EAAE,QAAQ,CAAE,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACtD,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;SAC9C;IACL,CAAC;IACM,cAAc,CAAC,KAAa,EAAE,WAAmB;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Ac,EAAE,IAAI,CAAC,MAAO,CAAC,YAAY,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;IAC9F,CAAC;IACM,MAAM;QACT,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,cAAe,CAAC,KAAK,CAAC;QACxC,IAAI,CAAC,cAAe,CAAC,KAAK,GAAG,IAAI,CAAC;IACtC,CAAC;CACJ;AAdD,oDAcC"}
@@ -1,13 +1,13 @@
1
- import { Xml2Json, XmlAttributes, IReaderState } from "./xml2json";
2
- export declare class InternalFragmentClonerReaderState implements IReaderState {
3
- private _xw;
4
- value: any;
5
- initLevel: number;
6
- engine?: Xml2Json;
7
- _on_startElement(level: number, elementName: string, attrs: XmlAttributes): void;
8
- _on_endElement(level: number, elementName: string): void;
9
- _on_init(elementName: string, attrs: XmlAttributes, parent: IReaderState, level: number, engine: Xml2Json): void;
10
- _on_finish(): void;
11
- _on_endElement2(level: number, elementName: string): void;
12
- _on_text(text: string): void;
13
- }
1
+ import { Xml2Json, XmlAttributes, IReaderState } from "./xml2json";
2
+ export declare class InternalFragmentClonerReaderState implements IReaderState {
3
+ private _xw;
4
+ value: any;
5
+ initLevel: number;
6
+ engine?: Xml2Json;
7
+ _on_startElement(level: number, elementName: string, attrs: XmlAttributes): void;
8
+ _on_endElement(level: number, elementName: string): void;
9
+ _on_init(elementName: string, attrs: XmlAttributes, parent: IReaderState, level: number, engine: Xml2Json): void;
10
+ _on_finish(): void;
11
+ _on_endElement2(level: number, elementName: string): void;
12
+ _on_text(text: string): void;
13
+ }