node-opcua-extension-object 2.64.1 → 2.66.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.
@@ -1,16 +1,16 @@
1
- /// <reference types="node" />
2
- import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
3
- import { BaseUAObject, StructuredTypeSchema } from "node-opcua-factory";
4
- import { NodeId } from "node-opcua-nodeid";
5
- export declare class ExtensionObject extends BaseUAObject {
6
- static schema: StructuredTypeSchema;
7
- constructor(options?: null | Record<string, any>);
8
- }
9
- export declare function encodeExtensionObject(object: BaseUAObject | null, stream: OutputBinaryStream): void;
10
- export declare class OpaqueStructure extends ExtensionObject {
11
- nodeId: NodeId;
12
- buffer: Buffer;
13
- constructor(nodeId: NodeId, buffer: Buffer);
14
- toString(): string;
15
- }
16
- export declare function decodeExtensionObject(stream: BinaryStream, _value?: ExtensionObject | null): ExtensionObject | null;
1
+ /// <reference types="node" />
2
+ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
3
+ import { BaseUAObject, StructuredTypeSchema } from "node-opcua-factory";
4
+ import { NodeId } from "node-opcua-nodeid";
5
+ export declare class ExtensionObject extends BaseUAObject {
6
+ static schema: StructuredTypeSchema;
7
+ constructor(options?: null | Record<string, any>);
8
+ }
9
+ export declare function encodeExtensionObject(object: BaseUAObject | null, stream: OutputBinaryStream): void;
10
+ export declare class OpaqueStructure extends ExtensionObject {
11
+ nodeId: NodeId;
12
+ buffer: Buffer;
13
+ constructor(nodeId: NodeId, buffer: Buffer);
14
+ toString(): string;
15
+ }
16
+ export declare function decodeExtensionObject(stream: BinaryStream, _value?: ExtensionObject | null): ExtensionObject | null;
@@ -1,182 +1,182 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decodeExtensionObject = exports.OpaqueStructure = exports.encodeExtensionObject = exports.ExtensionObject = void 0;
4
- /**
5
- * @module node-opcua-extension-object
6
- */
7
- const node_opcua_basic_types_1 = require("node-opcua-basic-types");
8
- const node_opcua_debug_1 = require("node-opcua-debug");
9
- const node_opcua_factory_1 = require("node-opcua-factory");
10
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
11
- const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
12
- const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
13
- const chalk = require("chalk");
14
- /* tslint:disable:no-empty */
15
- class ExtensionObject extends node_opcua_factory_1.BaseUAObject {
16
- constructor(options) {
17
- super();
18
- }
19
- }
20
- exports.ExtensionObject = ExtensionObject;
21
- ExtensionObject.schema = new node_opcua_factory_1.StructuredTypeSchema({
22
- baseType: "",
23
- documentation: "",
24
- fields: [],
25
- name: "ExtensionObject"
26
- });
27
- ExtensionObject.prototype.schema = ExtensionObject.schema;
28
- function constructEmptyExtensionObject(expandedNodeId) {
29
- return (0, node_opcua_factory_1.constructObject)(expandedNodeId);
30
- }
31
- // OPC-UA Part 6 - $5.2.2.15 ExtensionObject
32
- // An ExtensionObject is encoded as sequence of bytes prefixed by the NodeId of its
33
- // DataTypeEncoding and the number of bytes encoded.
34
- // what the specs say: OCC/UA part 6 $5.2.2.15 ExtensionObject
35
- //
36
- // TypeId | NodeId | The identifier for the DataTypeEncoding node in the Server's AddressSpace.
37
- // | ExtensionObjects defined by the OPC UA specification have a numeric node
38
- // | identifier assigned to them with a NamespaceIndex of 0. The numeric
39
- // | identifiers are defined in A.1.
40
- //
41
- // Encoding | Byte | An enumeration that indicates how the body is encoded.
42
- // | The parameter may have the following values:
43
- // | 0x00 No body is encoded.
44
- // | 0x01 The body is encoded as a ByteString.
45
- // | 0x02 The body is encoded as a XmlElement.
46
- //
47
- // Length | Int32 | The length of the object body.
48
- // | The length shall be specified if the body is encoded. <<<<<<<( WTF ?)
49
- //
50
- // Body | Byte[*] | The object body
51
- // | This field contains the raw bytes for ByteString bodies.
52
- // | For XmlElement bodies this field contains the XML encoded as a UTF-8
53
- // | string without any null terminator.
54
- //
55
- function encodeExtensionObject(object, stream) {
56
- if (!object) {
57
- (0, node_opcua_basic_types_1.encodeNodeId)((0, node_opcua_nodeid_1.makeNodeId)(0), stream);
58
- stream.writeUInt8(0x00); // no body is encoded
59
- // note : Length shall not hbe specified, end of the job!
60
- }
61
- else {
62
- if (object instanceof OpaqueStructure) {
63
- // Writing raw Opaque buffer as Opaque Structure ...
64
- (0, node_opcua_basic_types_1.encodeNodeId)(object.nodeId, stream);
65
- stream.writeUInt8(0x01); // 0x01 The body is encoded as a ByteString.
66
- stream.writeByteStream(object.buffer);
67
- return;
68
- }
69
- /* istanbul ignore next */
70
- if (!(object instanceof node_opcua_factory_1.BaseUAObject)) {
71
- throw new Error("Expecting a extension object");
72
- }
73
- // ensure we have a valid encoding Default Binary ID !!!
74
- /* istanbul ignore next */
75
- if (!object.schema) {
76
- debugLog(" object = ", object);
77
- throw new Error("object has no schema " + object.constructor.name);
78
- }
79
- const encodingDefaultBinary = object.schema.encodingDefaultBinary;
80
- /* istanbul ignore next */
81
- if (!encodingDefaultBinary) {
82
- debugLog(chalk.yellow("encoding ExtObj "), object);
83
- throw new Error("Cannot find encodingDefaultBinary for this object : " + object.schema.name);
84
- }
85
- /* istanbul ignore next */
86
- if (encodingDefaultBinary.isEmpty()) {
87
- debugLog(chalk.yellow("encoding ExtObj "), object.constructor.encodingDefaultBinary.toString());
88
- throw new Error("Cannot find encodingDefaultBinary for this object : " + object.schema.name);
89
- }
90
- /* istanbul ignore next */
91
- if ((0, node_opcua_factory_1.is_internal_id)(encodingDefaultBinary.value)) {
92
- debugLog(chalk.yellow("encoding ExtObj "), object.constructor.encodingDefaultBinary.toString(), object.schema.name);
93
- throw new Error("Cannot find valid OPCUA encodingDefaultBinary for this object : " + object.schema.name);
94
- }
95
- (0, node_opcua_basic_types_1.encodeNodeId)(encodingDefaultBinary, stream);
96
- stream.writeUInt8(0x01); // 0x01 The body is encoded as a ByteString.
97
- stream.writeUInt32(object.binaryStoreSize());
98
- object.encode(stream);
99
- }
100
- }
101
- exports.encodeExtensionObject = encodeExtensionObject;
102
- // tslint:disable:max-classes-per-file
103
- class OpaqueStructure extends ExtensionObject {
104
- constructor(nodeId, buffer) {
105
- super();
106
- this.nodeId = nodeId;
107
- this.buffer = buffer;
108
- }
109
- toString() {
110
- const str = "/* OpaqueStructure */ { \n" +
111
- "nodeId " +
112
- this.nodeId.toString() +
113
- "\n" +
114
- "buffer = \n" +
115
- (0, node_opcua_debug_1.hexDump)(this.buffer) +
116
- "\n" +
117
- "}";
118
- return str;
119
- }
120
- }
121
- exports.OpaqueStructure = OpaqueStructure;
122
- function decodeExtensionObject(stream, _value) {
123
- const nodeId = (0, node_opcua_basic_types_1.decodeNodeId)(stream);
124
- const encodingType = stream.readUInt8();
125
- if (encodingType === 0) {
126
- return null;
127
- }
128
- const length = stream.readUInt32();
129
- /* istanbul ignore next */
130
- if (nodeId.value === 0 || encodingType === 0) {
131
- return {};
132
- }
133
- // let verify that decode will use the expected number of bytes
134
- const streamLengthBefore = stream.length;
135
- let object;
136
- if (nodeId.namespace !== 0) {
137
- // this is a extension object define in a other namespace
138
- // we can only threat it as an opaque object for the time being
139
- // the caller that may now more about the namespace Array and type
140
- // definition will be able to turn the opaque object into a meaningful
141
- // structure
142
- // lets rewind before the length
143
- stream.length -= 4;
144
- object = new OpaqueStructure(nodeId, stream.readByteStream());
145
- }
146
- else {
147
- object = constructEmptyExtensionObject(nodeId);
148
- /* istanbul ignore next */
149
- if (object === null) {
150
- // this object is unknown to us ..
151
- stream.length += length;
152
- object = {};
153
- }
154
- else {
155
- try {
156
- object.decode(stream);
157
- }
158
- catch (err) {
159
- debugLog("Cannot decode object ", err);
160
- }
161
- }
162
- }
163
- if (streamLengthBefore + length !== stream.length) {
164
- // this may happen if the server or client do have a different OPCUA version
165
- // for instance SubscriptionDiagnostics structure has been changed between OPCUA version 1.01 and 1.04
166
- // causing 2 extra member to be added.
167
- debugLog(chalk.bgWhiteBright.red("========================================="));
168
- // tslint:disable-next-line:no-console
169
- warningLog("WARNING => Extension object decoding error on ", object.constructor.name, " expected size was", length, "but only this amount of bytes have been read :", stream.length - streamLengthBefore);
170
- stream.length = streamLengthBefore + length;
171
- }
172
- return object;
173
- }
174
- exports.decodeExtensionObject = decodeExtensionObject;
175
- (0, node_opcua_factory_1.registerBuiltInType)({
176
- name: "ExtensionObject",
177
- subType: "",
178
- encode: encodeExtensionObject,
179
- decode: decodeExtensionObject,
180
- defaultValue: () => null
181
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeExtensionObject = exports.OpaqueStructure = exports.encodeExtensionObject = exports.ExtensionObject = void 0;
4
+ /**
5
+ * @module node-opcua-extension-object
6
+ */
7
+ const node_opcua_basic_types_1 = require("node-opcua-basic-types");
8
+ const node_opcua_debug_1 = require("node-opcua-debug");
9
+ const node_opcua_factory_1 = require("node-opcua-factory");
10
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
11
+ const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
12
+ const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
13
+ const chalk = require("chalk");
14
+ /* tslint:disable:no-empty */
15
+ class ExtensionObject extends node_opcua_factory_1.BaseUAObject {
16
+ constructor(options) {
17
+ super();
18
+ }
19
+ }
20
+ exports.ExtensionObject = ExtensionObject;
21
+ ExtensionObject.schema = new node_opcua_factory_1.StructuredTypeSchema({
22
+ baseType: "",
23
+ documentation: "",
24
+ fields: [],
25
+ name: "ExtensionObject"
26
+ });
27
+ ExtensionObject.prototype.schema = ExtensionObject.schema;
28
+ function constructEmptyExtensionObject(expandedNodeId) {
29
+ return (0, node_opcua_factory_1.constructObject)(expandedNodeId);
30
+ }
31
+ // OPC-UA Part 6 - $5.2.2.15 ExtensionObject
32
+ // An ExtensionObject is encoded as sequence of bytes prefixed by the NodeId of its
33
+ // DataTypeEncoding and the number of bytes encoded.
34
+ // what the specs say: OCC/UA part 6 $5.2.2.15 ExtensionObject
35
+ //
36
+ // TypeId | NodeId | The identifier for the DataTypeEncoding node in the Server's AddressSpace.
37
+ // | ExtensionObjects defined by the OPC UA specification have a numeric node
38
+ // | identifier assigned to them with a NamespaceIndex of 0. The numeric
39
+ // | identifiers are defined in A.1.
40
+ //
41
+ // Encoding | Byte | An enumeration that indicates how the body is encoded.
42
+ // | The parameter may have the following values:
43
+ // | 0x00 No body is encoded.
44
+ // | 0x01 The body is encoded as a ByteString.
45
+ // | 0x02 The body is encoded as a XmlElement.
46
+ //
47
+ // Length | Int32 | The length of the object body.
48
+ // | The length shall be specified if the body is encoded. <<<<<<<( WTF ?)
49
+ //
50
+ // Body | Byte[*] | The object body
51
+ // | This field contains the raw bytes for ByteString bodies.
52
+ // | For XmlElement bodies this field contains the XML encoded as a UTF-8
53
+ // | string without any null terminator.
54
+ //
55
+ function encodeExtensionObject(object, stream) {
56
+ if (!object) {
57
+ (0, node_opcua_basic_types_1.encodeNodeId)((0, node_opcua_nodeid_1.makeNodeId)(0), stream);
58
+ stream.writeUInt8(0x00); // no body is encoded
59
+ // note : Length shall not hbe specified, end of the job!
60
+ }
61
+ else {
62
+ if (object instanceof OpaqueStructure) {
63
+ // Writing raw Opaque buffer as Opaque Structure ...
64
+ (0, node_opcua_basic_types_1.encodeNodeId)(object.nodeId, stream);
65
+ stream.writeUInt8(0x01); // 0x01 The body is encoded as a ByteString.
66
+ stream.writeByteStream(object.buffer);
67
+ return;
68
+ }
69
+ /* istanbul ignore next */
70
+ if (!(object instanceof node_opcua_factory_1.BaseUAObject)) {
71
+ throw new Error("Expecting a extension object");
72
+ }
73
+ // ensure we have a valid encoding Default Binary ID !!!
74
+ /* istanbul ignore next */
75
+ if (!object.schema) {
76
+ debugLog(" object = ", object);
77
+ throw new Error("object has no schema " + object.constructor.name);
78
+ }
79
+ const encodingDefaultBinary = object.schema.encodingDefaultBinary;
80
+ /* istanbul ignore next */
81
+ if (!encodingDefaultBinary) {
82
+ debugLog(chalk.yellow("encoding ExtObj "), object);
83
+ throw new Error("Cannot find encodingDefaultBinary for this object : " + object.schema.name);
84
+ }
85
+ /* istanbul ignore next */
86
+ if (encodingDefaultBinary.isEmpty()) {
87
+ debugLog(chalk.yellow("encoding ExtObj "), object.constructor.encodingDefaultBinary.toString());
88
+ throw new Error("Cannot find encodingDefaultBinary for this object : " + object.schema.name);
89
+ }
90
+ /* istanbul ignore next */
91
+ if ((0, node_opcua_factory_1.is_internal_id)(encodingDefaultBinary.value)) {
92
+ debugLog(chalk.yellow("encoding ExtObj "), object.constructor.encodingDefaultBinary.toString(), object.schema.name);
93
+ throw new Error("Cannot find valid OPCUA encodingDefaultBinary for this object : " + object.schema.name);
94
+ }
95
+ (0, node_opcua_basic_types_1.encodeNodeId)(encodingDefaultBinary, stream);
96
+ stream.writeUInt8(0x01); // 0x01 The body is encoded as a ByteString.
97
+ stream.writeUInt32(object.binaryStoreSize());
98
+ object.encode(stream);
99
+ }
100
+ }
101
+ exports.encodeExtensionObject = encodeExtensionObject;
102
+ // tslint:disable:max-classes-per-file
103
+ class OpaqueStructure extends ExtensionObject {
104
+ constructor(nodeId, buffer) {
105
+ super();
106
+ this.nodeId = nodeId;
107
+ this.buffer = buffer;
108
+ }
109
+ toString() {
110
+ const str = "/* OpaqueStructure */ { \n" +
111
+ "nodeId " +
112
+ this.nodeId.toString() +
113
+ "\n" +
114
+ "buffer = \n" +
115
+ (0, node_opcua_debug_1.hexDump)(this.buffer) +
116
+ "\n" +
117
+ "}";
118
+ return str;
119
+ }
120
+ }
121
+ exports.OpaqueStructure = OpaqueStructure;
122
+ function decodeExtensionObject(stream, _value) {
123
+ const nodeId = (0, node_opcua_basic_types_1.decodeNodeId)(stream);
124
+ const encodingType = stream.readUInt8();
125
+ if (encodingType === 0) {
126
+ return null;
127
+ }
128
+ const length = stream.readUInt32();
129
+ /* istanbul ignore next */
130
+ if (nodeId.value === 0 || encodingType === 0) {
131
+ return {};
132
+ }
133
+ // let verify that decode will use the expected number of bytes
134
+ const streamLengthBefore = stream.length;
135
+ let object;
136
+ if (nodeId.namespace !== 0) {
137
+ // this is a extension object define in a other namespace
138
+ // we can only threat it as an opaque object for the time being
139
+ // the caller that may now more about the namespace Array and type
140
+ // definition will be able to turn the opaque object into a meaningful
141
+ // structure
142
+ // lets rewind before the length
143
+ stream.length -= 4;
144
+ object = new OpaqueStructure(nodeId, stream.readByteStream());
145
+ }
146
+ else {
147
+ object = constructEmptyExtensionObject(nodeId);
148
+ /* istanbul ignore next */
149
+ if (object === null) {
150
+ // this object is unknown to us ..
151
+ stream.length += length;
152
+ object = {};
153
+ }
154
+ else {
155
+ try {
156
+ object.decode(stream);
157
+ }
158
+ catch (err) {
159
+ debugLog("Cannot decode object ", err);
160
+ }
161
+ }
162
+ }
163
+ if (streamLengthBefore + length !== stream.length) {
164
+ // this may happen if the server or client do have a different OPCUA version
165
+ // for instance SubscriptionDiagnostics structure has been changed between OPCUA version 1.01 and 1.04
166
+ // causing 2 extra member to be added.
167
+ debugLog(chalk.bgWhiteBright.red("========================================="));
168
+ // tslint:disable-next-line:no-console
169
+ warningLog("WARNING => Extension object decoding error on ", object.constructor.name, " expected size was", length, "but only this amount of bytes have been read :", stream.length - streamLengthBefore);
170
+ stream.length = streamLengthBefore + length;
171
+ }
172
+ return object;
173
+ }
174
+ exports.decodeExtensionObject = decodeExtensionObject;
175
+ (0, node_opcua_factory_1.registerBuiltInType)({
176
+ name: "ExtensionObject",
177
+ subType: "",
178
+ encode: encodeExtensionObject,
179
+ decode: decodeExtensionObject,
180
+ defaultValue: () => null
181
+ });
182
182
  //# sourceMappingURL=extension_object.js.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /**
2
- * @module node-opcua-extension-object
3
- */
4
- export * from "./extension_object";
1
+ /**
2
+ * @module node-opcua-extension-object
3
+ */
4
+ export * from "./extension_object";
package/dist/index.js CHANGED
@@ -1,17 +1,21 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- /**
14
- * @module node-opcua-extension-object
15
- */
16
- __exportStar(require("./extension_object"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * @module node-opcua-extension-object
19
+ */
20
+ __exportStar(require("./extension_object"), exports);
17
21
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;GAEG;AACH,qDAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,qDAAmC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-opcua-extension-object",
3
- "version": "2.64.1",
3
+ "version": "2.66.0",
4
4
  "description": "pure nodejs OPCUA SDK - module -extension-object",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -8,17 +8,17 @@
8
8
  "build": "tsc -b",
9
9
  "lint": "eslint source",
10
10
  "format": "prettier --write source",
11
- "clean": "node -e \"require('rimraf').sync('dist');\"",
11
+ "clean": "npx rimraf dist *.tsbuildinfo",
12
12
  "test": "echo no test"
13
13
  },
14
14
  "dependencies": {
15
15
  "chalk": "4.1.2",
16
- "node-opcua-assert": "2.64.1",
17
- "node-opcua-basic-types": "2.64.1",
18
- "node-opcua-binary-stream": "2.64.1",
19
- "node-opcua-debug": "2.64.1",
20
- "node-opcua-factory": "2.64.1",
21
- "node-opcua-nodeid": "2.64.1"
16
+ "node-opcua-assert": "2.66.0",
17
+ "node-opcua-basic-types": "2.66.0",
18
+ "node-opcua-binary-stream": "2.66.0",
19
+ "node-opcua-debug": "2.66.0",
20
+ "node-opcua-factory": "2.66.0",
21
+ "node-opcua-nodeid": "2.66.0"
22
22
  },
23
23
  "author": "Etienne Rossignon",
24
24
  "license": "MIT",
@@ -35,5 +35,5 @@
35
35
  "internet of things"
36
36
  ],
37
37
  "homepage": "http://node-opcua.github.io/",
38
- "gitHead": "b65b8738603cd475d7d99a2b20b0ae9d32b4110c"
38
+ "gitHead": "97f47e2e242a1fd737495fd64cb65e8fb7a9964b"
39
39
  }