node-opcua-factory 2.51.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 (54) hide show
  1. package/LICENSE +20 -0
  2. package/dist/constructor_type.d.ts +15 -0
  3. package/dist/constructor_type.js +3 -0
  4. package/dist/constructor_type.js.map +1 -0
  5. package/dist/datatype_factory.d.ts +40 -0
  6. package/dist/datatype_factory.js +330 -0
  7. package/dist/datatype_factory.js.map +1 -0
  8. package/dist/factories_baseobject.d.ts +56 -0
  9. package/dist/factories_baseobject.js +498 -0
  10. package/dist/factories_baseobject.js.map +1 -0
  11. package/dist/factories_basic_type.d.ts +40 -0
  12. package/dist/factories_basic_type.js +136 -0
  13. package/dist/factories_basic_type.js.map +1 -0
  14. package/dist/factories_builtin_types.d.ts +32 -0
  15. package/dist/factories_builtin_types.js +262 -0
  16. package/dist/factories_builtin_types.js.map +1 -0
  17. package/dist/factories_builtin_types_special.d.ts +5 -0
  18. package/dist/factories_builtin_types_special.js +46 -0
  19. package/dist/factories_builtin_types_special.js.map +1 -0
  20. package/dist/factories_enumerations.d.ts +31 -0
  21. package/dist/factories_enumerations.js +77 -0
  22. package/dist/factories_enumerations.js.map +1 -0
  23. package/dist/factories_factories.d.ts +17 -0
  24. package/dist/factories_factories.js +54 -0
  25. package/dist/factories_factories.js.map +1 -0
  26. package/dist/factories_id_generator.d.ts +3 -0
  27. package/dist/factories_id_generator.js +22 -0
  28. package/dist/factories_id_generator.js.map +1 -0
  29. package/dist/factories_schema_helpers.d.ts +26 -0
  30. package/dist/factories_schema_helpers.js +121 -0
  31. package/dist/factories_schema_helpers.js.map +1 -0
  32. package/dist/factories_structuredTypeSchema.d.ts +46 -0
  33. package/dist/factories_structuredTypeSchema.js +269 -0
  34. package/dist/factories_structuredTypeSchema.js.map +1 -0
  35. package/dist/index.d.ts +15 -0
  36. package/dist/index.js +28 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/types.d.ts +111 -0
  39. package/dist/types.js +56 -0
  40. package/dist/types.js.map +1 -0
  41. package/package.json +41 -0
  42. package/source/constructor_type.ts +18 -0
  43. package/source/datatype_factory.ts +368 -0
  44. package/source/factories_baseobject.ts +567 -0
  45. package/source/factories_basic_type.ts +168 -0
  46. package/source/factories_builtin_types.ts +381 -0
  47. package/source/factories_builtin_types_special.ts +55 -0
  48. package/source/factories_enumerations.ts +97 -0
  49. package/source/factories_factories.ts +58 -0
  50. package/source/factories_id_generator.ts +18 -0
  51. package/source/factories_schema_helpers.ts +125 -0
  52. package/source/factories_structuredTypeSchema.ts +330 -0
  53. package/source/index.ts +15 -0
  54. package/source/types.ts +180 -0
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerBasicType = 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 factories_builtin_types_1 = require("./factories_builtin_types");
10
+ /**
11
+ * register a Basic Type ,
12
+ * A basic type is new entity type that resolved to a SubType
13
+ * @example:
14
+ *
15
+ *
16
+ * registerBasicType({name:"Duration" ,subType:"Double"});
17
+ *
18
+ * @method registerBasicType
19
+ * @param schema
20
+ * @param schema.name {String}
21
+ * @param schema.subType {String} mandatory, the basic type from which the new type derives.
22
+ *
23
+ * @param [schema.encode] {Function} optional,a specific encoder function to encode an instance of this type.
24
+ * @param schema.encode.value {*}
25
+ * @param schema.encode.stream {BinaryStream}
26
+ *
27
+ * @param [schema.decode] optional,a specific decoder function that returns the decode value out of the stream.
28
+ * @param [schema.decode.stream] {BinaryStream}
29
+ *
30
+ * @param [schema.coerce] optional, a method to convert a value into the request type.
31
+ * @param schema.coerce.value {*} the value to coerce.
32
+ *
33
+ * @param [schema.random] optional, a method to construct a random object of this type
34
+ *
35
+ * @param [schema.toJSON]optional, a method to convert a value into the request type.
36
+ */
37
+ function registerBasicType(schema) {
38
+ const exists = (0, factories_builtin_types_1.hasBuiltInType)(schema.name);
39
+ /* istanbul ignore next */
40
+ if (exists) {
41
+ // tslint:disable-next-line: no-console
42
+ console.log("registerBasicType:", schema);
43
+ throw new Error(`Basic Type ${schema.name} already registered`);
44
+ }
45
+ const name = schema.name;
46
+ const t = (0, factories_builtin_types_1.findSimpleType)(schema.subType);
47
+ /* istanbul ignore next */
48
+ if (!t) {
49
+ // tslint:disable-next-line:no-console
50
+ throw new Error(" cannot find subtype " + schema.subType);
51
+ }
52
+ (0, node_opcua_assert_1.assert)(typeof t.decode === "function");
53
+ const encodeFunc = schema.encode || t.encode;
54
+ (0, node_opcua_assert_1.assert)(typeof encodeFunc === "function");
55
+ const decodeFunc = schema.decode || t.decode;
56
+ (0, node_opcua_assert_1.assert)(typeof decodeFunc === "function");
57
+ const defaultValue = schema.defaultValue === undefined ? t.defaultValue : schema.defaultValue;
58
+ // assert(typeof defaultValue === "function");
59
+ const coerceFunc = schema.coerce || t.coerce;
60
+ const toJSONFunc = schema.toJSON || t.toJSON;
61
+ const random = schema.random || defaultValue;
62
+ const newSchema = {
63
+ name,
64
+ subType: schema.subType,
65
+ coerce: coerceFunc,
66
+ decode: decodeFunc,
67
+ encode: encodeFunc,
68
+ random,
69
+ defaultValue,
70
+ toJSON: toJSONFunc
71
+ };
72
+ (0, factories_builtin_types_1.registerType)(newSchema);
73
+ }
74
+ exports.registerBasicType = registerBasicType;
75
+ // =============================================================================================
76
+ // Registering the Basic Type already defined int the OPC-UA Specification
77
+ // =============================================================================================
78
+ registerBasicType({ name: "Counter", subType: "UInt32" });
79
+ // OPC Unified Architecture, part 3.0 $8.13 page 65
80
+ registerBasicType({ name: "Duration", subType: "Double" });
81
+ registerBasicType({ name: "UAString", subType: "String" });
82
+ registerBasicType({ name: "UABoolean", subType: "Boolean" });
83
+ registerBasicType({ name: "UtcTime", subType: "DateTime" });
84
+ // already ? registerBasicType({name: "Int8", subType: "SByte"});
85
+ // already ? registerBasicType({name: "UInt8", subType: "Byte"});
86
+ registerBasicType({ name: "Char", subType: "Byte" });
87
+ // xx registerBasicType({name:"XmlElement" ,subType:"String" });
88
+ // xx registerBasicType({ name: "Time", subType: "String" });
89
+ // string in the form "en-US" or "de-DE" or "fr" etc...
90
+ registerBasicType({
91
+ name: "LocaleId",
92
+ subType: "String",
93
+ defaultValue: null,
94
+ decode: node_opcua_basic_types_1.decodeLocaleId,
95
+ encode: node_opcua_basic_types_1.encodeLocaleId,
96
+ validate: node_opcua_basic_types_1.validateLocaleId
97
+ });
98
+ registerBasicType({ name: "ContinuationPoint", subType: "ByteString" });
99
+ registerBasicType({ name: "Image", subType: "ByteString" });
100
+ registerBasicType({ name: "NodeIdType", subType: "NodeId" });
101
+ registerBasicType({ name: "ImageBMP", subType: "Image" });
102
+ registerBasicType({ name: "ImageGIF", subType: "Image" });
103
+ registerBasicType({ name: "ImageJPG", subType: "Image" });
104
+ registerBasicType({ name: "ImagePNG", subType: "Image" });
105
+ registerBasicType({ name: "AudioDataType", subType: "ByteString" });
106
+ registerBasicType({ name: "BitFieldMaskDataType", subType: "UInt64" });
107
+ registerBasicType({ name: "DataSetFieldFlags", subType: "UInt16" });
108
+ registerBasicType({ name: "DataSetFieldContentMask", subType: "UInt32" });
109
+ registerBasicType({ name: "UadpNetworkMessageContentMask", subType: "UInt32" });
110
+ registerBasicType({ name: "UadpDataSetMessageContentMask", subType: "UInt32" });
111
+ registerBasicType({ name: "JsonNetworkMessageContentMask", subType: "UInt32" });
112
+ registerBasicType({ name: "JsonDataSetMessageContentMask", subType: "UInt32" });
113
+ registerBasicType({ name: "PermissionType", subType: "UInt32" });
114
+ registerBasicType({ name: "AccessLevelType", subType: "Byte" });
115
+ registerBasicType({ name: "AccessLevelExType", subType: "UInt32" });
116
+ registerBasicType({ name: "EventNotifierType", subType: "Byte" });
117
+ registerBasicType({ name: "AccessRestrictionType", subType: "UInt32" });
118
+ registerBasicType({ name: "NormalizedString", subType: "String" });
119
+ registerBasicType({ name: "DecimalString", subType: "String" });
120
+ registerBasicType({ name: "DurationString", subType: "String" });
121
+ registerBasicType({ name: "TimeString", subType: "String" });
122
+ registerBasicType({ name: "DateString", subType: "String" });
123
+ registerBasicType({ name: "Index", subType: "UInt32" });
124
+ registerBasicType({ name: "VersionTime", subType: "UInt32" });
125
+ registerBasicType({ name: "ApplicationInstanceCertificate", subType: "ByteString" });
126
+ registerBasicType({ name: "AttributeWriteMask", subType: "UInt32" });
127
+ registerBasicType({ name: "Date", subType: "DateTime" });
128
+ // registerBasicType({ name: "Counter", subType: "UInt32" });
129
+ // registerBasicType({ name: "IntegerId", subType: "UInt32" });
130
+ // registerBasicType({ name: "UtcTime", subType: "DateTime" });
131
+ // registerBasicType({ name: "Duration", subType: "Double" });
132
+ // registerBasicType({ name: "LocaleId", subType: "String" });
133
+ // registerBasicType({ name: "NumericRange", subType: "String" });
134
+ // registerBasicType({ name: "Time", subType: "String" });
135
+ // registerBasicType({ name: "SessionAuthenticationToken", subType: "NodeId" });
136
+ //# sourceMappingURL=factories_basic_type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factories_basic_type.js","sourceRoot":"","sources":["../source/factories_basic_type.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,yDAA2C;AAC3C,mEAA0F;AAG1F,uEAAyF;AAczF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,iBAAiB,CAAC,MAAwB;IACtD,MAAM,MAAM,GAAY,IAAA,wCAAc,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAEpD,0BAA0B;IAC1B,IAAI,MAAM,EAAE;QACR,uCAAuC;QACvC,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,cAAc,MAAM,CAAC,IAAI,qBAAqB,CAAC,CAAC;KACnE;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IAEzB,MAAM,CAAC,GAAwB,IAAA,wC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chemaBase } from "./types";
3
+ export declare class BasicTypeSchema extends TypeSchemaBase implements BasicTypeDefinition {
4
+ subType: string;
5
+ encode: (value: any, stream: OutputBinaryStream) => void;
6
+ decode: (stream: BinaryStream) => any;
7
+ constructor(options: BasicTypeDefinitionOptions);
8
+ }
9
+ export declare const minDate: Date;
10
+ /**
11
+ * @method registerType
12
+ * @param schema {TypeSchemaBase}
13
+ */
14
+ export declare function registerType(schema: BasicTypeDefinitionOptions): void;
15
+ export declare const registerBuiltInType: typeof registerType;
16
+ export declare function unregisterType(typeName: string): void;
17
+ /**
18
+ * @method findSimpleType
19
+ * @param name
20
+ * @return {TypeSchemaBase|null}
21
+ */
22
+ export declare function findSimpleType(name: string): BasicTypeDefinition;
23
+ export declare function hasBuiltInType(name: string): boolean;
24
+ export declare function getBuildInType(name: string): BasicTypeDefinition;
25
+ /**
26
+ * @method findBuiltInType
27
+ * find the Builtin Type that this
28
+ * @param dataTypeName
29
+ * @return {*}
30
+ */
31
+ export declare function findBuiltInType(dataTypeName: string): BasicTypeDefinition;
32
+ export declare function getTypeMap(): Map<string, BasicTypeSchema>;
@@ -0,0 +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
+ // tslint:disable:no-empty
14
+ // tslint:enable:no-unused-variable
15
+ function defaultEncode(value, stream) { }
16
+ function defaultDecode(stream) {
17
+ return null;
18
+ }
19
+ class BasicTypeSchema extends types_1.TypeSchemaBase {
20
+ constructor(options) {
21
+ super(options);
22
+ this.subType = options.subType;
23
+ this.encode = options.encode || defaultEncode;
24
+ this.decode = options.decode || defaultDecode;
25
+ }
26
+ }
27
+ exports.BasicTypeSchema = BasicTypeSchema;
28
+ exports.minDate = new Date(Date.UTC(1601, 0, 1, 0, 0, 0));
29
+ function defaultGuidValue() {
30
+ return Buffer.alloc(0);
31
+ }
32
+ function toJSONGuid(value) {
33
+ if (typeof value === "string") {
34
+ return value;
35
+ }
36
+ (0, node_opcua_assert_1.assert)(value instanceof Buffer);
37
+ return value.toString("base64");
38
+ }
39
+ function encodeAny(value, stream) {
40
+ (0, node_opcua_assert_1.assert)(false, "type 'Any' cannot be encoded");
41
+ }
42
+ function decodeAny(stream) {
43
+ (0, node_opcua_assert_1.assert)(false, "type 'Any' cannot be decoded");
44
+ }
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 supertypes.
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
+ /**
194
+ * @method registerType
195
+ * @param schema {TypeSchemaBase}
196
+ */
197
+ function registerType(schema) {
198
+ (0, node_opcua_assert_1.assert)(typeof schema.name === "string");
199
+ if (typeof schema.encode !== "function") {
200
+ throw new Error("schema " + schema.name + " has no encode function");
201
+ }
202
+ if (typeof schema.decode !== "function") {
203
+ throw new Error("schema " + schema.name + " has no decode function");
204
+ }
205
+ schema.category = types_1.FieldCategory.basic;
206
+ const definition = new BasicTypeSchema(schema);
207
+ _defaultTypeMap.set(schema.name, definition);
208
+ }
209
+ exports.registerType = registerType;
210
+ exports.registerBuiltInType = registerType;
211
+ function unregisterType(typeName) {
212
+ _defaultTypeMap.delete(typeName);
213
+ }
214
+ exports.unregisterType = unregisterType;
215
+ /**
216
+ * @method findSimpleType
217
+ * @param name
218
+ * @return {TypeSchemaBase|null}
219
+ */
220
+ function findSimpleType(name) {
221
+ const typeSchema = _defaultTypeMap.get(name);
222
+ if (!typeSchema) {
223
+ throw new Error("Cannot find schema for simple type " + name);
224
+ }
225
+ (0, node_opcua_assert_1.assert)(typeSchema instanceof types_1.TypeSchemaBase);
226
+ return typeSchema;
227
+ }
228
+ exports.findSimpleType = findSimpleType;
229
+ // populate the default type map
230
+ const _defaultTypeMap = new Map();
231
+ _defaultType.forEach(registerType);
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
+ //# sourceMappingURL=factories_builtin_types.js.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AY,sBAAc,CAAC,CAAC;IAC7C,OAAO,UAAiC,CAAC;AAC7C,CAAC;AAPD,wCAOC;AAED,gCAAgC;AAChC,MAAM,eAAe,GAAiC,IAAI,GAAG,EAA2B,CAAC;AACzF,YAAY,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AAEnC,SAAgB,cAAc,CAAC,IAAY;IACvC,OAAO,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACrC,CAAC;AAFD,wCAEC;AAED,SAAgB,cAAc,CAAC,IAAY;IACvC,OAAO,eAAe,CAAC,GAAG,CAAC,IAAI,CAAwB,CAAC;AAC5D,CAAC;AAFD,wCAEC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,YAAoB;IAChD,IAAA,0BAAM,EAAC,OAAO,YAAY,KAAK,QAAQ,EAAE,uCAAuC,GAAG,YAAY,CAAC,CAAC;IACjG,MAAM,CAAC,GAAG,eAAe,CAAC,GAAG,CAAC,YAAY,CAAwB,CAAC;IACnE,IAAI,CAAC,CAAC,EAAE;QACJ,MAAM,IAAI,KAAK,CAAC,WAAW,GAAG,YAAY,GAAG,qBAAqB,CAAC,CAAC;KACvE;IACD,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,IAAI,CAAC,8BAA8B,EAAE;QAClE,OAAO,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;KACrC;IACD,OAAO,CAAC,CAAC;AACb,CAAC;AAVD,0CAUC;AAED,SAAgB,UAAU;IACtB,OAAO,eAAe,CAAC;AAC3B,CAAC;AAFD,gCAEC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @module node-opcua-factory
3
+ */
4
+ import { ConstructorFunc } from "./constructor_type";
5
+ export declare function registerSpecialVariantEncoder(constructor: ConstructorFunc): void;
@@ -0,0 +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;
46
+ //# sourceMappingURL=factories_builtin_types_special.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factories_builtin_types_special.js","sourceRoot":"","sources":["../source/factories_builtin_types_special.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,yDAA2C;AAG3C,uEAAyD;AAGzD,SAAS,YAAY,CAAC,WAAgB;IAClC,IAAA,0BAAM,EAAC,OAAO,WAAW,KAAK,UAAU,CAAC,CAAC;IAC1C,OAAO,CAAC,KAAU,EAAE,MAA0B,EAAE,EAAE;QAC9C,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YACzB,KAAK,GAAG,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;SAClC;QACD,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC,CAAC;AACN,CAAC;AAED,SAAS,YAAY,CAAC,WAAgB;IAClC,IAAA,0BAAM,EAAC,OAAO,WAAW,KAAK,UAAU,CAAC,CAAC;IAC1C,OAAO,CAAC,MAAoB,EAAE,EAAE;QAC5B,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC;QAChC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACrB,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC;AACN,CAAC;AAED,SAAS,YAAY,CAAC,WAAgB;IAClC,IAAA,0BAAM,EAAC,OAAO,WAAW,KAAK,UAAU,CAAC,CAAC;IAC1C,OAAO,CAAC,KAAU,EAAE,EAAE;QAClB,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,GAAG,CAAC;IACf,CAAC,CAAC;AACN,CAAC;AAED,SAAgB,6BAA6B,CAAC,WAA4B;IACtE,IAAA,0BAAM,EAAC,OAAO,WAAW,KAAK,UAAU,CAAC,CAAC;IAE1C,MAAM,IAAI,GAAG,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;IAE/C,IAAA,sCAAY,EAAC;QACT,IAAI;QACJ,OAAO,EAAE,IAAI;QAEb,MAAM,EAAE,YAAY,CAAC,WAAW,CAAC;QAEjC,MAAM,EAAE,YAAY,CAAC,WAAW,CAAC;QAEjC,MAAM,EAAE,YAAY,CAAC,WAAW,CAAC;QAEjC,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,WAAW,EAAE;KACxC,CAAC,CAAC;AACP,CAAC;AAjBD,sEAiBC"}
@@ -0,0 +1,31 @@
1
+ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
2
+ import { Enum, EnumItem } from "node-opcua-enum";
3
+ import { EnumerationDefinition, TypeSchemaBase, TypeSchemaConstructorOptions } from "./types";
4
+ export interface EnumerationDefinitionOptions extends TypeSchemaConstructorOptions {
5
+ enumValues: any;
6
+ typedEnum?: any;
7
+ lengthInBits?: number;
8
+ defaultValue?: EnumItem;
9
+ encode?: (value: EnumItem, stream: OutputBinaryStream) => void;
10
+ decode?: (stream: BinaryStream) => EnumItem;
11
+ }
12
+ export declare class EnumerationDefinitionSchema extends TypeSchemaBase implements EnumerationDefinition {
13
+ enumValues: any;
14
+ typedEnum: Enum;
15
+ lengthInBits: number;
16
+ constructor(options: EnumerationDefinitionOptions);
17
+ }
18
+ /**
19
+ * @method registerEnumeration
20
+ * @param options
21
+ * @param options.name {string}
22
+ * @param options.enumValues [{key:Name, value:values}]
23
+ * @param options.encode
24
+ * @param options.decode
25
+ * @param options.typedEnum
26
+ * @param options.defaultValue
27
+ * @return {Enum}
28
+ */
29
+ export declare function registerEnumeration(options: EnumerationDefinitionOptions): Enum;
30
+ export declare function hasEnumeration(enumerationName: string): boolean;
31
+ export declare function getEnumeration(enumerationName: string): EnumerationDefinitionSchema;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEnumeration = exports.hasEnumeration = exports.registerEnumeration = exports.EnumerationDefinitionSchema = void 0;
4
+ /**
5
+ * @module node-opcua-factory
6
+ */
7
+ const node_opcua_assert_1 = require("node-opcua-assert");
8
+ const node_opcua_enum_1 = require("node-opcua-enum");
9
+ const types_1 = require("./types");
10
+ function _encode_enumeration(typedEnum, value, stream) {
11
+ (0, node_opcua_assert_1.assert)(typeof value === "number", "Expecting a number here");
12
+ (0, node_opcua_assert_1.assert)(typedEnum.get(value) !== undefined, "expecting a valid value");
13
+ stream.writeInteger(value);
14
+ }
15
+ function _decode_enumeration(typedEnum, stream) {
16
+ const value = stream.readInteger();
17
+ const e = typedEnum.get(value);
18
+ // istanbul ignore next
19
+ if (!e) {
20
+ throw new Error("cannot coerce value=" + value + " to " + typedEnum.constructor.name);
21
+ }
22
+ return value;
23
+ }
24
+ class EnumerationDefinitionSchema extends types_1.TypeSchemaBase {
25
+ // xx encode: (value: EnumItem, stream: OutputBinaryStream) => void;
26
+ // xx decode: (stream: BinaryStream) => EnumItem;
27
+ constructor(options) {
28
+ super(options);
29
+ // create a new Enum
30
+ const typedEnum = new node_opcua_enum_1.Enum(options.enumValues);
31
+ options.typedEnum = typedEnum;
32
+ (0, node_opcua_assert_1.assert)(!options.encode || typeof options.encode === "function");
33
+ (0, node_opcua_assert_1.assert)(!options.decode || typeof options.decode === "function");
34
+ this.encode = options.encode || _encode_enumeration.bind(null, typedEnum);
35
+ this.decode = options.decode || _decode_enumeration.bind(null, typedEnum);
36
+ this.typedEnum = options.typedEnum;
37
+ this.defaultValue = this.typedEnum.getDefaultValue().value;
38
+ this.lengthInBits = options.lengthInBits || 32;
39
+ }
40
+ }
41
+ exports.EnumerationDefinitionSchema = EnumerationDefinitionSchema;
42
+ const _enumerations = new Map();
43
+ /**
44
+ * @method registerEnumeration
45
+ * @param options
46
+ * @param options.name {string}
47
+ * @param options.enumValues [{key:Name, value:values}]
48
+ * @param options.encode
49
+ * @param options.decode
50
+ * @param options.typedEnum
51
+ * @param options.defaultValue
52
+ * @return {Enum}
53
+ */
54
+ function registerEnumeration(options) {
55
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "name"));
56
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "enumValues"));
57
+ const name = options.name;
58
+ if (_enumerations.hasOwnProperty(name)) {
59
+ throw new Error("factories.registerEnumeration : Enumeration " + options.name + " has been already inserted");
60
+ }
61
+ const enumerationDefinition = new EnumerationDefinitionSchema(options);
62
+ _enumerations.set(name, enumerationDefinition);
63
+ return enumerationDefinition.typedEnum;
64
+ }
65
+ exports.registerEnumeration = registerEnumeration;
66
+ function hasEnumeration(enumerationName) {
67
+ return _enumerations.has(enumerationName);
68
+ }
69
+ exports.hasEnumeration = hasEnumeration;
70
+ function getEnumeration(enumerationName) {
71
+ if (!exports.hasEnumeration(enumerationName)) {
72
+ throw new Error("Cannot find enumeration with type " + enumerationName);
73
+ }
74
+ return _enumerations.get(enumerationName);
75
+ }
76
+ exports.getEnumeration = getEnumeration;
77
+ //# sourceMappingURL=factories_enumerations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factories_enumerations.js","sourceRoot":"","sources":["../source/factories_enumerations.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,yDAA2C;AAG3C,qDAAiD;AACjD,mCAA8F;AAE9F,SAAS,mBAAmB,CAAC,SAAe,EAAE,KAAa,EAAE,MAA0B;IACnF,IAAA,0BAAM,EAAC,OAAO,KAAK,KAAK,QAAQ,EAAE,yBAAyB,CAAC,CAAC;IAC7D,IAAA,0BAAM,EAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,SAAS,EAAE,yBAAyB,CAAC,CAAC;IACtE,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,mBAAmB,CAAC,SAAe,EAAE,MAAoB;IAC9D,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IACnC,MAAM,CAAC,GAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAmB,CAAC;IAClD,uBAAuB;IACvB,IAAI,CAAC,CAAC,EAAE;QACJ,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;KAC1F;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAaD,MAAa,2BAA4B,SAAQ,sBAAc;IAI3D,oEAAoE;IACpE,iDAAiD;IAEjD,YAAY,OAAqC;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,oBAAoB;QACpB,MAAM,SAAS,GAAG,IAAI,sBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC/C,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;QAE9B,IAAA,0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O,CAAC,CAAC;IACvE,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;IAE/C,OAAO,qBAAqB,CAAC,SAAS,CAAC;AAC3C,CAAC;AAZD,kDAYC;AAED,SAAgB,cAAc,CAAC,eAAuB;IAClD,OAAO,aAAa,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAC9C,CAAC;AAFD,wCAEC;AAED,SAAgB,cAAc,CAAC,eAAuB;IAClD,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE;QAC1C,MAAM,IAAI,KAAK,CAAC,oCAAoC,GAAG,eAAe,CAAC,CAAC;KAC3E;IACD,OAAO,aAAa,CAAC,GAAG,CAAC,eAAe,CAAgC,CAAC;AAC7E,CAAC;AALD,wCAKC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @module node-opcua-factory
3
+ */
4
+ import { ExpandedNodeId, NodeId } from "node-opcua-nodeid";
5
+ import { DataTypeFactory } from "./datatype_factory";
6
+ import { ConstructorFuncWithSchema, ConstructorFunc } from "./constructor_type";
7
+ import { BaseUAObject } from "./factories_baseobject";
8
+ import { StructuredTypeSchema } from "./factories_structuredTypeSchema";
9
+ export declare function getStandardDataTypeFactory(): DataTypeFactory;
10
+ export declare function getStructureTypeConstructor(typeName: string): ConstructorFuncWithSchema;
11
+ export declare function hasStructuredType(typeName: string): boolean;
12
+ export declare function getStructuredTypeSchema(typeName: string): StructuredTypeSchema;
13
+ export declare function getConstructor(binaryEncodingNodeId: ExpandedNodeId): ConstructorFunc | null;
14
+ export declare function hasConstructor(binaryEncodingNodeId: ExpandedNodeId): boolean;
15
+ export declare function constructObject(binaryEncodingNodeId: ExpandedNodeId): BaseUAObject;
16
+ export declare function registerClassDefinition(dataTypeNodeId: NodeId, className: string, classConstructor: ConstructorFuncWithSchema): void;
17
+ export declare function dump(): void;