node-opcua-factory 2.71.0 → 2.72.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,262 +1,262 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTypeMap = exports.findBuiltInType = exports.getBuildInType = exports.hasBuiltInType = exports.findSimpleType = exports.unregisterType = exports.registerBuiltInType = exports.registerType = exports.minDate = exports.BasicTypeSchema = void 0;
4
- /**
5
- * @module node-opcua-factory
6
- */
7
- const node_opcua_assert_1 = require("node-opcua-assert");
8
- const node_opcua_basic_types_1 = require("node-opcua-basic-types");
9
- const node_opcua_guid_1 = require("node-opcua-guid");
10
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
11
- const node_opcua_status_code_1 = require("node-opcua-status-code");
12
- const types_1 = require("./types");
13
- // eslint-disable-next-line @typescript-eslint/no-empty-function
14
- function defaultEncode(value, stream) { }
15
- function defaultDecode(stream) {
16
- return null;
17
- }
18
- class BasicTypeSchema extends types_1.TypeSchemaBase {
19
- constructor(options) {
20
- super(options);
21
- this.subType = options.subType;
22
- this.encode = options.encode || defaultEncode;
23
- this.decode = options.decode || defaultDecode;
24
- }
25
- }
26
- exports.BasicTypeSchema = BasicTypeSchema;
27
- exports.minDate = new Date(Date.UTC(1601, 0, 1, 0, 0, 0));
28
- function defaultGuidValue() {
29
- return Buffer.alloc(0);
30
- }
31
- function toJSONGuid(value) {
32
- if (typeof value === "string") {
33
- return value;
34
- }
35
- (0, node_opcua_assert_1.assert)(value instanceof Buffer);
36
- return value.toString("base64");
37
- }
38
- function encodeAny(value, stream) {
39
- (0, node_opcua_assert_1.assert)(false, "type 'Any' cannot be encoded");
40
- }
41
- function decodeAny(stream) {
42
- (0, node_opcua_assert_1.assert)(false, "type 'Any' cannot be decoded");
43
- }
44
- // eslint-disable-next-line @typescript-eslint/no-empty-function
45
- function encodeNull(value, stream) { }
46
- function decodeNull(stream) {
47
- return null;
48
- }
49
- // there are 4 types of DataTypes in opcua:
50
- // Built-In DataType
51
- // Simple DataType
52
- // Complex DataType
53
- // Enumeration
54
- const defaultXmlElement = "";
55
- // Built-In Type
56
- const _defaultType = [
57
- // Built-in DataTypes ( see OPCUA Part III v1.02 - $5.8.2 )
58
- {
59
- name: "Null",
60
- decode: decodeNull,
61
- encode: encodeNull,
62
- defaultValue: null
63
- },
64
- {
65
- name: "Any",
66
- decode: decodeAny,
67
- encode: encodeAny
68
- },
69
- {
70
- name: "Boolean",
71
- decode: node_opcua_basic_types_1.decodeBoolean,
72
- encode: node_opcua_basic_types_1.encodeBoolean,
73
- coerce: node_opcua_basic_types_1.coerceBoolean,
74
- defaultValue: false
75
- },
76
- { name: "Int8", encode: node_opcua_basic_types_1.encodeInt8, decode: node_opcua_basic_types_1.decodeInt8, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceInt8 },
77
- { name: "UInt8", encode: node_opcua_basic_types_1.encodeUInt8, decode: node_opcua_basic_types_1.decodeUInt8, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceUInt8 },
78
- { name: "SByte", encode: node_opcua_basic_types_1.encodeSByte, decode: node_opcua_basic_types_1.decodeSByte, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceSByte },
79
- { name: "Byte", encode: node_opcua_basic_types_1.encodeByte, decode: node_opcua_basic_types_1.decodeByte, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceByte },
80
- { name: "Int16", encode: node_opcua_basic_types_1.encodeInt16, decode: node_opcua_basic_types_1.decodeInt16, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceInt16 },
81
- { name: "UInt16", encode: node_opcua_basic_types_1.encodeUInt16, decode: node_opcua_basic_types_1.decodeUInt16, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceUInt16 },
82
- { name: "Int32", encode: node_opcua_basic_types_1.encodeInt32, decode: node_opcua_basic_types_1.decodeInt32, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceInt32 },
83
- { name: "UInt32", encode: node_opcua_basic_types_1.encodeUInt32, decode: node_opcua_basic_types_1.decodeUInt32, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceUInt32 },
84
- {
85
- name: "Int64",
86
- decode: node_opcua_basic_types_1.decodeInt64,
87
- encode: node_opcua_basic_types_1.encodeInt64,
88
- coerce: node_opcua_basic_types_1.coerceInt64,
89
- defaultValue: (0, node_opcua_basic_types_1.coerceInt64)(0)
90
- },
91
- {
92
- name: "UInt64",
93
- decode: node_opcua_basic_types_1.decodeUInt64,
94
- encode: node_opcua_basic_types_1.encodeUInt64,
95
- coerce: node_opcua_basic_types_1.coerceUInt64,
96
- defaultValue: (0, node_opcua_basic_types_1.coerceUInt64)(0)
97
- },
98
- {
99
- name: "Float",
100
- decode: node_opcua_basic_types_1.decodeFloat,
101
- encode: node_opcua_basic_types_1.encodeFloat,
102
- coerce: node_opcua_basic_types_1.coerceFloat,
103
- defaultValue: 0.0
104
- },
105
- {
106
- name: "Double",
107
- decode: node_opcua_basic_types_1.decodeDouble,
108
- encode: node_opcua_basic_types_1.encodeDouble,
109
- coerce: node_opcua_basic_types_1.coerceDouble,
110
- defaultValue: 0.0
111
- },
112
- {
113
- name: "String",
114
- decode: node_opcua_basic_types_1.decodeString,
115
- encode: node_opcua_basic_types_1.encodeString,
116
- defaultValue: ""
117
- },
118
- // OPC Unified Architecture, part 3.0 $8.26 page 67
119
- {
120
- name: "DateTime",
121
- decode: node_opcua_basic_types_1.decodeDateTime,
122
- encode: node_opcua_basic_types_1.encodeDateTime,
123
- coerce: node_opcua_basic_types_1.coerceDateTime,
124
- defaultValue: exports.minDate
125
- },
126
- {
127
- name: "Guid",
128
- decode: node_opcua_basic_types_1.decodeGuid,
129
- encode: node_opcua_basic_types_1.encodeGuid,
130
- defaultValue: node_opcua_guid_1.emptyGuid
131
- },
132
- {
133
- name: "ByteString",
134
- decode: node_opcua_basic_types_1.decodeByteString,
135
- encode: node_opcua_basic_types_1.encodeByteString,
136
- coerce: node_opcua_basic_types_1.coerceByteString,
137
- defaultValue: null,
138
- toJSON: toJSONGuid
139
- },
140
- {
141
- name: "XmlElement",
142
- decode: node_opcua_basic_types_1.decodeString,
143
- encode: node_opcua_basic_types_1.encodeString,
144
- defaultValue: defaultXmlElement
145
- },
146
- // see OPCUA Part 3 - V1.02 $8.2.1
147
- {
148
- name: "NodeId",
149
- decode: node_opcua_basic_types_1.decodeNodeId,
150
- encode: node_opcua_basic_types_1.encodeNodeId,
151
- coerce: node_opcua_basic_types_1.coerceNodeId,
152
- defaultValue: node_opcua_nodeid_1.makeNodeId
153
- },
154
- {
155
- name: "ExpandedNodeId",
156
- decode: node_opcua_basic_types_1.decodeExpandedNodeId,
157
- encode: node_opcua_basic_types_1.encodeExpandedNodeId,
158
- coerce: node_opcua_basic_types_1.coerceExpandedNodeId,
159
- defaultValue: node_opcua_nodeid_1.makeExpandedNodeId
160
- },
161
- // ----------------------------------------------------------------------------------------
162
- // Simple DataTypes
163
- // ( see OPCUA Part III v1.02 - $5.8.2 )
164
- // Simple DataTypes are subtypes of the Built-in DataTypes. They are handled on the wire like the
165
- // Built-in DataType, i.e. they cannot be distinguished on the wire from their Built-in super types.
166
- // Since they are handled like Built-in DataTypes regarding the encoding they cannot have encodings
167
- // defined in the AddressSpace. Clients can read the DataType Attribute of a Variable or VariableType to
168
- // identify the Simple DataType of the Value Attribute. An example of a Simple DataType is Duration. It
169
- // is handled on the wire as a Double but the Client can read the DataType Attribute and thus interpret
170
- // the value as defined by Duration
171
- //
172
- // OPC Unified Architecture, part 4.0 $7.13
173
- // IntegerID: This primitive data type is an UInt32 that is used as an identifier, such as a handle. All values,
174
- // except for 0, are valid.
175
- {
176
- name: "IntegerId",
177
- decode: node_opcua_basic_types_1.decodeUInt32,
178
- encode: node_opcua_basic_types_1.encodeUInt32,
179
- defaultValue: 0xffffffff
180
- },
181
- // The StatusCode is a 32-bit unsigned integer. The top 16 bits represent the numeric value of the
182
- // code that shall be used for detecting specific errors or conditions. The bottom 16 bits are bit flags
183
- // that contain additional information but do not affect the meaning of the StatusCode.
184
- // 7.33 Part 4 - P 143
185
- {
186
- name: "StatusCode",
187
- decode: node_opcua_status_code_1.decodeStatusCode,
188
- encode: node_opcua_status_code_1.encodeStatusCode,
189
- coerce: node_opcua_status_code_1.coerceStatusCode,
190
- defaultValue: node_opcua_status_code_1.StatusCodes.Good
191
- }
192
- ];
193
- // populate the default type map
194
- const _defaultTypeMap = new Map();
195
- _defaultType.forEach(registerType);
196
- /**
197
- * @method registerType
198
- * @param schema {TypeSchemaBase}
199
- */
200
- function registerType(schema) {
201
- (0, node_opcua_assert_1.assert)(typeof schema.name === "string");
202
- if (typeof schema.encode !== "function") {
203
- throw new Error("schema " + schema.name + " has no encode function");
204
- }
205
- if (typeof schema.decode !== "function") {
206
- throw new Error("schema " + schema.name + " has no decode function");
207
- }
208
- schema.category = types_1.FieldCategory.basic;
209
- const definition = new BasicTypeSchema(schema);
210
- _defaultTypeMap.set(schema.name, definition);
211
- }
212
- exports.registerType = registerType;
213
- exports.registerBuiltInType = registerType;
214
- function unregisterType(typeName) {
215
- _defaultTypeMap.delete(typeName);
216
- }
217
- exports.unregisterType = unregisterType;
218
- /**
219
- * @method findSimpleType
220
- * @param name
221
- * @return {TypeSchemaBase|null}
222
- */
223
- function findSimpleType(name) {
224
- const typeSchema = _defaultTypeMap.get(name);
225
- if (!typeSchema) {
226
- throw new Error("Cannot find schema for simple type " + name);
227
- }
228
- (0, node_opcua_assert_1.assert)(typeSchema instanceof types_1.TypeSchemaBase);
229
- return typeSchema;
230
- }
231
- exports.findSimpleType = findSimpleType;
232
- function hasBuiltInType(name) {
233
- return _defaultTypeMap.has(name);
234
- }
235
- exports.hasBuiltInType = hasBuiltInType;
236
- function getBuildInType(name) {
237
- return _defaultTypeMap.get(name);
238
- }
239
- exports.getBuildInType = getBuildInType;
240
- /**
241
- * @method findBuiltInType
242
- * find the Builtin Type that this
243
- * @param dataTypeName
244
- * @return {*}
245
- */
246
- function findBuiltInType(dataTypeName) {
247
- (0, node_opcua_assert_1.assert)(typeof dataTypeName === "string", "findBuiltInType : expecting a string " + dataTypeName);
248
- const t = _defaultTypeMap.get(dataTypeName);
249
- if (!t) {
250
- throw new Error("datatype " + dataTypeName + " must be registered");
251
- }
252
- if (t.subType && t.subType !== t.name /* avoid infinite recursion */) {
253
- return findBuiltInType(t.subType);
254
- }
255
- return t;
256
- }
257
- exports.findBuiltInType = findBuiltInType;
258
- function getTypeMap() {
259
- return _defaultTypeMap;
260
- }
261
- exports.getTypeMap = getTypeMap;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTypeMap = exports.findBuiltInType = exports.getBuildInType = exports.hasBuiltInType = exports.findSimpleType = exports.unregisterType = exports.registerBuiltInType = exports.registerType = exports.minDate = exports.BasicTypeSchema = void 0;
4
+ /**
5
+ * @module node-opcua-factory
6
+ */
7
+ const node_opcua_assert_1 = require("node-opcua-assert");
8
+ const node_opcua_basic_types_1 = require("node-opcua-basic-types");
9
+ const node_opcua_guid_1 = require("node-opcua-guid");
10
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
11
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
12
+ const types_1 = require("./types");
13
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
14
+ function defaultEncode(value, stream) { }
15
+ function defaultDecode(stream) {
16
+ return null;
17
+ }
18
+ class BasicTypeSchema extends types_1.TypeSchemaBase {
19
+ constructor(options) {
20
+ super(options);
21
+ this.subType = options.subType;
22
+ this.encode = options.encode || defaultEncode;
23
+ this.decode = options.decode || defaultDecode;
24
+ }
25
+ }
26
+ exports.BasicTypeSchema = BasicTypeSchema;
27
+ exports.minDate = new Date(Date.UTC(1601, 0, 1, 0, 0, 0));
28
+ function defaultGuidValue() {
29
+ return Buffer.alloc(0);
30
+ }
31
+ function toJSONGuid(value) {
32
+ if (typeof value === "string") {
33
+ return value;
34
+ }
35
+ (0, node_opcua_assert_1.assert)(value instanceof Buffer);
36
+ return value.toString("base64");
37
+ }
38
+ function encodeAny(value, stream) {
39
+ (0, node_opcua_assert_1.assert)(false, "type 'Any' cannot be encoded");
40
+ }
41
+ function decodeAny(stream) {
42
+ (0, node_opcua_assert_1.assert)(false, "type 'Any' cannot be decoded");
43
+ }
44
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
45
+ function encodeNull(value, stream) { }
46
+ function decodeNull(stream) {
47
+ return null;
48
+ }
49
+ // there are 4 types of DataTypes in opcua:
50
+ // Built-In DataType
51
+ // Simple DataType
52
+ // Complex DataType
53
+ // Enumeration
54
+ const defaultXmlElement = "";
55
+ // Built-In Type
56
+ const _defaultType = [
57
+ // Built-in DataTypes ( see OPCUA Part III v1.02 - $5.8.2 )
58
+ {
59
+ name: "Null",
60
+ decode: decodeNull,
61
+ encode: encodeNull,
62
+ defaultValue: null
63
+ },
64
+ {
65
+ name: "Any",
66
+ decode: decodeAny,
67
+ encode: encodeAny
68
+ },
69
+ {
70
+ name: "Boolean",
71
+ decode: node_opcua_basic_types_1.decodeBoolean,
72
+ encode: node_opcua_basic_types_1.encodeBoolean,
73
+ coerce: node_opcua_basic_types_1.coerceBoolean,
74
+ defaultValue: false
75
+ },
76
+ { name: "Int8", encode: node_opcua_basic_types_1.encodeInt8, decode: node_opcua_basic_types_1.decodeInt8, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceInt8 },
77
+ { name: "UInt8", encode: node_opcua_basic_types_1.encodeUInt8, decode: node_opcua_basic_types_1.decodeUInt8, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceUInt8 },
78
+ { name: "SByte", encode: node_opcua_basic_types_1.encodeSByte, decode: node_opcua_basic_types_1.decodeSByte, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceSByte },
79
+ { name: "Byte", encode: node_opcua_basic_types_1.encodeByte, decode: node_opcua_basic_types_1.decodeByte, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceByte },
80
+ { name: "Int16", encode: node_opcua_basic_types_1.encodeInt16, decode: node_opcua_basic_types_1.decodeInt16, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceInt16 },
81
+ { name: "UInt16", encode: node_opcua_basic_types_1.encodeUInt16, decode: node_opcua_basic_types_1.decodeUInt16, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceUInt16 },
82
+ { name: "Int32", encode: node_opcua_basic_types_1.encodeInt32, decode: node_opcua_basic_types_1.decodeInt32, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceInt32 },
83
+ { name: "UInt32", encode: node_opcua_basic_types_1.encodeUInt32, decode: node_opcua_basic_types_1.decodeUInt32, defaultValue: 0, coerce: node_opcua_basic_types_1.coerceUInt32 },
84
+ {
85
+ name: "Int64",
86
+ decode: node_opcua_basic_types_1.decodeInt64,
87
+ encode: node_opcua_basic_types_1.encodeInt64,
88
+ coerce: node_opcua_basic_types_1.coerceInt64,
89
+ defaultValue: (0, node_opcua_basic_types_1.coerceInt64)(0)
90
+ },
91
+ {
92
+ name: "UInt64",
93
+ decode: node_opcua_basic_types_1.decodeUInt64,
94
+ encode: node_opcua_basic_types_1.encodeUInt64,
95
+ coerce: node_opcua_basic_types_1.coerceUInt64,
96
+ defaultValue: (0, node_opcua_basic_types_1.coerceUInt64)(0)
97
+ },
98
+ {
99
+ name: "Float",
100
+ decode: node_opcua_basic_types_1.decodeFloat,
101
+ encode: node_opcua_basic_types_1.encodeFloat,
102
+ coerce: node_opcua_basic_types_1.coerceFloat,
103
+ defaultValue: 0.0
104
+ },
105
+ {
106
+ name: "Double",
107
+ decode: node_opcua_basic_types_1.decodeDouble,
108
+ encode: node_opcua_basic_types_1.encodeDouble,
109
+ coerce: node_opcua_basic_types_1.coerceDouble,
110
+ defaultValue: 0.0
111
+ },
112
+ {
113
+ name: "String",
114
+ decode: node_opcua_basic_types_1.decodeString,
115
+ encode: node_opcua_basic_types_1.encodeString,
116
+ defaultValue: ""
117
+ },
118
+ // OPC Unified Architecture, part 3.0 $8.26 page 67
119
+ {
120
+ name: "DateTime",
121
+ decode: node_opcua_basic_types_1.decodeDateTime,
122
+ encode: node_opcua_basic_types_1.encodeDateTime,
123
+ coerce: node_opcua_basic_types_1.coerceDateTime,
124
+ defaultValue: exports.minDate
125
+ },
126
+ {
127
+ name: "Guid",
128
+ decode: node_opcua_basic_types_1.decodeGuid,
129
+ encode: node_opcua_basic_types_1.encodeGuid,
130
+ defaultValue: node_opcua_guid_1.emptyGuid
131
+ },
132
+ {
133
+ name: "ByteString",
134
+ decode: node_opcua_basic_types_1.decodeByteString,
135
+ encode: node_opcua_basic_types_1.encodeByteString,
136
+ coerce: node_opcua_basic_types_1.coerceByteString,
137
+ defaultValue: null,
138
+ toJSON: toJSONGuid
139
+ },
140
+ {
141
+ name: "XmlElement",
142
+ decode: node_opcua_basic_types_1.decodeString,
143
+ encode: node_opcua_basic_types_1.encodeString,
144
+ defaultValue: defaultXmlElement
145
+ },
146
+ // see OPCUA Part 3 - V1.02 $8.2.1
147
+ {
148
+ name: "NodeId",
149
+ decode: node_opcua_basic_types_1.decodeNodeId,
150
+ encode: node_opcua_basic_types_1.encodeNodeId,
151
+ coerce: node_opcua_basic_types_1.coerceNodeId,
152
+ defaultValue: node_opcua_nodeid_1.makeNodeId
153
+ },
154
+ {
155
+ name: "ExpandedNodeId",
156
+ decode: node_opcua_basic_types_1.decodeExpandedNodeId,
157
+ encode: node_opcua_basic_types_1.encodeExpandedNodeId,
158
+ coerce: node_opcua_basic_types_1.coerceExpandedNodeId,
159
+ defaultValue: node_opcua_nodeid_1.makeExpandedNodeId
160
+ },
161
+ // ----------------------------------------------------------------------------------------
162
+ // Simple DataTypes
163
+ // ( see OPCUA Part III v1.02 - $5.8.2 )
164
+ // Simple DataTypes are subtypes of the Built-in DataTypes. They are handled on the wire like the
165
+ // Built-in DataType, i.e. they cannot be distinguished on the wire from their Built-in super types.
166
+ // Since they are handled like Built-in DataTypes regarding the encoding they cannot have encodings
167
+ // defined in the AddressSpace. Clients can read the DataType Attribute of a Variable or VariableType to
168
+ // identify the Simple DataType of the Value Attribute. An example of a Simple DataType is Duration. It
169
+ // is handled on the wire as a Double but the Client can read the DataType Attribute and thus interpret
170
+ // the value as defined by Duration
171
+ //
172
+ // OPC Unified Architecture, part 4.0 $7.13
173
+ // IntegerID: This primitive data type is an UInt32 that is used as an identifier, such as a handle. All values,
174
+ // except for 0, are valid.
175
+ {
176
+ name: "IntegerId",
177
+ decode: node_opcua_basic_types_1.decodeUInt32,
178
+ encode: node_opcua_basic_types_1.encodeUInt32,
179
+ defaultValue: 0xffffffff
180
+ },
181
+ // The StatusCode is a 32-bit unsigned integer. The top 16 bits represent the numeric value of the
182
+ // code that shall be used for detecting specific errors or conditions. The bottom 16 bits are bit flags
183
+ // that contain additional information but do not affect the meaning of the StatusCode.
184
+ // 7.33 Part 4 - P 143
185
+ {
186
+ name: "StatusCode",
187
+ decode: node_opcua_status_code_1.decodeStatusCode,
188
+ encode: node_opcua_status_code_1.encodeStatusCode,
189
+ coerce: node_opcua_status_code_1.coerceStatusCode,
190
+ defaultValue: node_opcua_status_code_1.StatusCodes.Good
191
+ }
192
+ ];
193
+ // populate the default type map
194
+ const _defaultTypeMap = new Map();
195
+ _defaultType.forEach(registerType);
196
+ /**
197
+ * @method registerType
198
+ * @param schema {TypeSchemaBase}
199
+ */
200
+ function registerType(schema) {
201
+ (0, node_opcua_assert_1.assert)(typeof schema.name === "string");
202
+ if (typeof schema.encode !== "function") {
203
+ throw new Error("schema " + schema.name + " has no encode function");
204
+ }
205
+ if (typeof schema.decode !== "function") {
206
+ throw new Error("schema " + schema.name + " has no decode function");
207
+ }
208
+ schema.category = types_1.FieldCategory.basic;
209
+ const definition = new BasicTypeSchema(schema);
210
+ _defaultTypeMap.set(schema.name, definition);
211
+ }
212
+ exports.registerType = registerType;
213
+ exports.registerBuiltInType = registerType;
214
+ function unregisterType(typeName) {
215
+ _defaultTypeMap.delete(typeName);
216
+ }
217
+ exports.unregisterType = unregisterType;
218
+ /**
219
+ * @method findSimpleType
220
+ * @param name
221
+ * @return {TypeSchemaBase|null}
222
+ */
223
+ function findSimpleType(name) {
224
+ const typeSchema = _defaultTypeMap.get(name);
225
+ if (!typeSchema) {
226
+ throw new Error("Cannot find schema for simple type " + name);
227
+ }
228
+ (0, node_opcua_assert_1.assert)(typeSchema instanceof types_1.TypeSchemaBase);
229
+ return typeSchema;
230
+ }
231
+ exports.findSimpleType = findSimpleType;
232
+ function hasBuiltInType(name) {
233
+ return _defaultTypeMap.has(name);
234
+ }
235
+ exports.hasBuiltInType = hasBuiltInType;
236
+ function getBuildInType(name) {
237
+ return _defaultTypeMap.get(name);
238
+ }
239
+ exports.getBuildInType = getBuildInType;
240
+ /**
241
+ * @method findBuiltInType
242
+ * find the Builtin Type that this
243
+ * @param dataTypeName
244
+ * @return {*}
245
+ */
246
+ function findBuiltInType(dataTypeName) {
247
+ (0, node_opcua_assert_1.assert)(typeof dataTypeName === "string", "findBuiltInType : expecting a string " + dataTypeName);
248
+ const t = _defaultTypeMap.get(dataTypeName);
249
+ if (!t) {
250
+ throw new Error("datatype " + dataTypeName + " must be registered");
251
+ }
252
+ if (t.subType && t.subType !== t.name /* avoid infinite recursion */) {
253
+ return findBuiltInType(t.subType);
254
+ }
255
+ return t;
256
+ }
257
+ exports.findBuiltInType = findBuiltInType;
258
+ function getTypeMap() {
259
+ return _defaultTypeMap;
260
+ }
261
+ exports.getTypeMap = getTypeMap;
262
262
  //# sourceMappingURL=factories_builtin_types.js.map
@@ -1,5 +1,5 @@
1
- /**
2
- * @module node-opcua-factory
3
- */
4
- import { ConstructorFunc } from "./constructor_type";
5
- export declare function registerSpecialVariantEncoder(constructor: ConstructorFunc): void;
1
+ /**
2
+ * @module node-opcua-factory
3
+ */
4
+ import { ConstructorFunc } from "./constructor_type";
5
+ export declare function registerSpecialVariantEncoder(constructor: ConstructorFunc): void;
@@ -1,46 +1,46 @@
1
- "use strict";
2
- /**
3
- * @module node-opcua-factory
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.registerSpecialVariantEncoder = void 0;
7
- const node_opcua_assert_1 = require("node-opcua-assert");
8
- const factories_builtin_types_1 = require("./factories_builtin_types");
9
- function _self_encode(constructor) {
10
- (0, node_opcua_assert_1.assert)(typeof constructor === "function");
11
- return (value, stream) => {
12
- if (!value || !value.encode) {
13
- value = new constructor(value);
14
- }
15
- value.encode(stream);
16
- };
17
- }
18
- function _self_decode(constructor) {
19
- (0, node_opcua_assert_1.assert)(typeof constructor === "function");
20
- return (stream) => {
21
- const value = new constructor();
22
- value.decode(stream);
23
- return value;
24
- };
25
- }
26
- function _self_coerce(constructor) {
27
- (0, node_opcua_assert_1.assert)(typeof constructor === "function");
28
- return (value) => {
29
- const obj = new constructor(value);
30
- return obj;
31
- };
32
- }
33
- function registerSpecialVariantEncoder(constructor) {
34
- (0, node_opcua_assert_1.assert)(typeof constructor === "function");
35
- const name = constructor.prototype.schema.name;
36
- (0, factories_builtin_types_1.registerType)({
37
- name,
38
- subType: name,
39
- encode: _self_encode(constructor),
40
- decode: _self_decode(constructor),
41
- coerce: _self_coerce(constructor),
42
- defaultValue: () => new constructor()
43
- });
44
- }
45
- exports.registerSpecialVariantEncoder = registerSpecialVariantEncoder;
1
+ "use strict";
2
+ /**
3
+ * @module node-opcua-factory
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.registerSpecialVariantEncoder = void 0;
7
+ const node_opcua_assert_1 = require("node-opcua-assert");
8
+ const factories_builtin_types_1 = require("./factories_builtin_types");
9
+ function _self_encode(constructor) {
10
+ (0, node_opcua_assert_1.assert)(typeof constructor === "function");
11
+ return (value, stream) => {
12
+ if (!value || !value.encode) {
13
+ value = new constructor(value);
14
+ }
15
+ value.encode(stream);
16
+ };
17
+ }
18
+ function _self_decode(constructor) {
19
+ (0, node_opcua_assert_1.assert)(typeof constructor === "function");
20
+ return (stream) => {
21
+ const value = new constructor();
22
+ value.decode(stream);
23
+ return value;
24
+ };
25
+ }
26
+ function _self_coerce(constructor) {
27
+ (0, node_opcua_assert_1.assert)(typeof constructor === "function");
28
+ return (value) => {
29
+ const obj = new constructor(value);
30
+ return obj;
31
+ };
32
+ }
33
+ function registerSpecialVariantEncoder(constructor) {
34
+ (0, node_opcua_assert_1.assert)(typeof constructor === "function");
35
+ const name = constructor.prototype.schema.name;
36
+ (0, factories_builtin_types_1.registerType)({
37
+ name,
38
+ subType: name,
39
+ encode: _self_encode(constructor),
40
+ decode: _self_decode(constructor),
41
+ coerce: _self_coerce(constructor),
42
+ defaultValue: () => new constructor()
43
+ });
44
+ }
45
+ exports.registerSpecialVariantEncoder = registerSpecialVariantEncoder;
46
46
  //# sourceMappingURL=factories_builtin_types_special.js.map