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.
- package/dist/constructor_type.d.ts +15 -15
- package/dist/constructor_type.js +2 -2
- package/dist/datatype_factory.d.ts +39 -39
- package/dist/datatype_factory.js +322 -322
- package/dist/factories_baseobject.d.ts +56 -56
- package/dist/factories_baseobject.js +534 -534
- package/dist/factories_basic_type.d.ts +40 -40
- package/dist/factories_basic_type.js +135 -135
- package/dist/factories_builtin_types.d.ts +32 -32
- package/dist/factories_builtin_types.js +261 -261
- package/dist/factories_builtin_types_special.d.ts +5 -5
- package/dist/factories_builtin_types_special.js +45 -45
- package/dist/factories_enumerations.d.ts +31 -31
- package/dist/factories_enumerations.js +77 -77
- package/dist/factories_factories.d.ts +17 -17
- package/dist/factories_factories.js +53 -53
- package/dist/factories_id_generator.d.ts +3 -3
- package/dist/factories_id_generator.js +21 -21
- package/dist/factories_schema_helpers.d.ts +27 -27
- package/dist/factories_schema_helpers.js +121 -121
- package/dist/factories_structuredTypeSchema.d.ts +45 -45
- package/dist/factories_structuredTypeSchema.js +276 -276
- package/dist/index.d.ts +15 -15
- package/dist/index.js +31 -31
- package/dist/types.d.ts +110 -110
- package/dist/types.js +51 -51
- package/package.json +3 -3
|
@@ -1,277 +1,277 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildStructuredType = exports.buildStructuredType2 = exports.check_options_correctness_against_schema = exports.extract_all_fields = exports.get_base_schema = exports.StructuredTypeSchema = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @module node-opcua-factory
|
|
6
|
-
*/
|
|
7
|
-
const chalk = require("chalk");
|
|
8
|
-
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
9
|
-
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
10
|
-
const node_opcua_utils_1 = require("node-opcua-utils");
|
|
11
|
-
const factories_builtin_types_1 = require("./factories_builtin_types");
|
|
12
|
-
const factories_enumerations_1 = require("./factories_enumerations");
|
|
13
|
-
const factories_factories_1 = require("./factories_factories");
|
|
14
|
-
const factories_schema_helpers_1 = require("./factories_schema_helpers");
|
|
15
|
-
const types_1 = require("./types");
|
|
16
|
-
function figureOutFieldCategory(field) {
|
|
17
|
-
const fieldType = field.fieldType;
|
|
18
|
-
if (field.category) {
|
|
19
|
-
return field.category;
|
|
20
|
-
}
|
|
21
|
-
if ((0, factories_enumerations_1.hasEnumeration)(fieldType)) {
|
|
22
|
-
return types_1.FieldCategory.enumeration;
|
|
23
|
-
}
|
|
24
|
-
else if ((0, factories_builtin_types_1.hasBuiltInType)(fieldType)) {
|
|
25
|
-
return types_1.FieldCategory.basic;
|
|
26
|
-
}
|
|
27
|
-
else if ((0, factories_factories_1.hasStructuredType)(fieldType)) {
|
|
28
|
-
(0, node_opcua_assert_1.assert)(fieldType !== "LocalizedText"); // LocalizedText should be treated as BasicType!!!
|
|
29
|
-
return types_1.FieldCategory.complex;
|
|
30
|
-
}
|
|
31
|
-
return types_1.FieldCategory.basic;
|
|
32
|
-
}
|
|
33
|
-
const regExp = /((ns[0-9]+:)?)(.*)/;
|
|
34
|
-
function figureOutSchema(underConstructSchema, field, category) {
|
|
35
|
-
if (field.schema) {
|
|
36
|
-
return field.schema;
|
|
37
|
-
}
|
|
38
|
-
if (underConstructSchema.name === field.fieldType) {
|
|
39
|
-
return underConstructSchema;
|
|
40
|
-
}
|
|
41
|
-
let returnValue = null;
|
|
42
|
-
// may be the field.type contains a ns<X>: prefix !! like the one found in Beckhoff PLC !
|
|
43
|
-
const m = field.fieldType.match(regExp);
|
|
44
|
-
/* istanbul ignore next */
|
|
45
|
-
if (!m) {
|
|
46
|
-
throw new Error("malformed fieldType ? : " + field.fieldType);
|
|
47
|
-
}
|
|
48
|
-
const fieldTypeWithoutNS = m[3];
|
|
49
|
-
switch (category) {
|
|
50
|
-
case types_1.FieldCategory.complex:
|
|
51
|
-
if ((0, factories_factories_1.hasStructuredType)(field.fieldType)) {
|
|
52
|
-
returnValue = (0, factories_factories_1.getStructuredTypeSchema)(fieldTypeWithoutNS);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// LocalizedText etc ...
|
|
56
|
-
returnValue = (0, factories_builtin_types_1.getBuildInType)(fieldTypeWithoutNS);
|
|
57
|
-
}
|
|
58
|
-
break;
|
|
59
|
-
case types_1.FieldCategory.basic:
|
|
60
|
-
returnValue = (0, factories_builtin_types_1.getBuildInType)(fieldTypeWithoutNS);
|
|
61
|
-
if (!returnValue) {
|
|
62
|
-
returnValue = (0, factories_factories_1.getStructuredTypeSchema)(fieldTypeWithoutNS);
|
|
63
|
-
if (returnValue) {
|
|
64
|
-
console.log("Why ?");
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
68
|
-
case types_1.FieldCategory.enumeration:
|
|
69
|
-
returnValue = (0, factories_enumerations_1.getEnumeration)(fieldTypeWithoutNS);
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
if (null === returnValue || undefined === returnValue) {
|
|
73
|
-
try {
|
|
74
|
-
returnValue = (0, factories_enumerations_1.getEnumeration)(fieldTypeWithoutNS);
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
console.log(err);
|
|
78
|
-
}
|
|
79
|
-
throw new Error("Cannot find Schema for field with name " +
|
|
80
|
-
field.name +
|
|
81
|
-
" fieldTypeWithoutNS= " +
|
|
82
|
-
fieldTypeWithoutNS +
|
|
83
|
-
" with type " +
|
|
84
|
-
field.fieldType +
|
|
85
|
-
" category = " +
|
|
86
|
-
category +
|
|
87
|
-
JSON.stringify(field, null, "\t"));
|
|
88
|
-
}
|
|
89
|
-
return returnValue;
|
|
90
|
-
}
|
|
91
|
-
function buildField(underConstructSchema, fieldLight) {
|
|
92
|
-
const category = figureOutFieldCategory(fieldLight);
|
|
93
|
-
const schema = figureOutSchema(underConstructSchema, fieldLight, category);
|
|
94
|
-
/* istanbul ignore next */
|
|
95
|
-
if (!schema) {
|
|
96
|
-
throw new Error("expecting a valid schema for field with name " +
|
|
97
|
-
fieldLight.name +
|
|
98
|
-
" with type " +
|
|
99
|
-
fieldLight.fieldType +
|
|
100
|
-
" category" +
|
|
101
|
-
category);
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
name: (0, node_opcua_utils_1.lowerFirstLetter)(fieldLight.name),
|
|
105
|
-
category,
|
|
106
|
-
defaultValue: fieldLight.defaultValue,
|
|
107
|
-
isArray: fieldLight.isArray,
|
|
108
|
-
documentation: fieldLight.documentation,
|
|
109
|
-
fieldType: fieldLight.fieldType,
|
|
110
|
-
switchBit: fieldLight.switchBit,
|
|
111
|
-
switchValue: fieldLight.switchValue,
|
|
112
|
-
schema
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
class StructuredTypeSchema extends types_1.TypeSchemaBase {
|
|
116
|
-
constructor(options) {
|
|
117
|
-
super(options);
|
|
118
|
-
this.bitFields = options.bitFields;
|
|
119
|
-
this.baseType = options.baseType;
|
|
120
|
-
this.category = types_1.FieldCategory.complex;
|
|
121
|
-
if ((0, factories_builtin_types_1.hasBuiltInType)(options.name)) {
|
|
122
|
-
this.category = types_1.FieldCategory.basic;
|
|
123
|
-
}
|
|
124
|
-
this.fields = options.fields.map(buildField.bind(null, this));
|
|
125
|
-
this.id = new node_opcua_nodeid_1.NodeId();
|
|
126
|
-
this.dataTypeNodeId = new node_opcua_nodeid_1.NodeId();
|
|
127
|
-
this._possibleFields = this.fields.map((field) => field.name);
|
|
128
|
-
this._baseSchema = null;
|
|
129
|
-
}
|
|
130
|
-
toString() {
|
|
131
|
-
var _a, _b, _c;
|
|
132
|
-
const str = [];
|
|
133
|
-
str.push("name = " + this.name);
|
|
134
|
-
str.push("baseType = " + this.baseType);
|
|
135
|
-
str.push("id = " + this.id.toString());
|
|
136
|
-
str.push("bitFields = " + (this.bitFields ? this.bitFields.map((b) => b.name).join(" ") : undefined));
|
|
137
|
-
str.push("dataTypeNodeId = " + (this.dataTypeNodeId ? this.dataTypeNodeId.toString() : undefined));
|
|
138
|
-
str.push("documentation = " + this.documentation);
|
|
139
|
-
str.push("encodingDefaultBinary = " + ((_a = this.encodingDefaultBinary) === null || _a === void 0 ? void 0 : _a.toString()));
|
|
140
|
-
str.push("encodingDefaultXml = " + ((_b = this.encodingDefaultXml) === null || _b === void 0 ? void 0 : _b.toString()));
|
|
141
|
-
str.push("encodingDefaultJson = " + ((_c = this.encodingDefaultJson) === null || _c === void 0 ? void 0 : _c.toString()));
|
|
142
|
-
for (const f of this.fields) {
|
|
143
|
-
str.push(" field = " +
|
|
144
|
-
f.name.padEnd(30) +
|
|
145
|
-
" isArray= " +
|
|
146
|
-
(f.isArray ? true : false) +
|
|
147
|
-
" " +
|
|
148
|
-
f.fieldType.toString().padEnd(30) +
|
|
149
|
-
(f.switchBit !== undefined ? " switchBit " + f.switchBit : "") +
|
|
150
|
-
(f.switchValue !== undefined ? " switchValue " + f.switchValue : ""));
|
|
151
|
-
}
|
|
152
|
-
return str.join("\n");
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
exports.StructuredTypeSchema = StructuredTypeSchema;
|
|
156
|
-
/**
|
|
157
|
-
*
|
|
158
|
-
* @method get_base_schema
|
|
159
|
-
* @param schema
|
|
160
|
-
* @return {*}
|
|
161
|
-
*
|
|
162
|
-
*/
|
|
163
|
-
function get_base_schema(schema) {
|
|
164
|
-
let baseSchema = schema._baseSchema;
|
|
165
|
-
if (baseSchema) {
|
|
166
|
-
return baseSchema;
|
|
167
|
-
}
|
|
168
|
-
if (schema.baseType === "ExtensionObject" || schema.baseType === "DataTypeDefinition") {
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
if (schema.baseType === "Union") {
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
if (schema.baseType && schema.baseType !== "BaseUAObject" && schema.baseType !== "DataTypeDefinition") {
|
|
175
|
-
if (!(0, factories_factories_1.hasStructuredType)(schema.baseType)) {
|
|
176
|
-
return null;
|
|
177
|
-
}
|
|
178
|
-
const baseType = (0, factories_factories_1.getStructureTypeConstructor)(schema.baseType);
|
|
179
|
-
// istanbul ignore next
|
|
180
|
-
if (!baseType) {
|
|
181
|
-
throw new Error(" cannot find factory for " + schema.baseType);
|
|
182
|
-
}
|
|
183
|
-
if (baseType.prototype.schema) {
|
|
184
|
-
baseSchema = baseType.prototype.schema;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
// put in cache for speedup
|
|
188
|
-
schema._baseSchema = baseSchema;
|
|
189
|
-
return baseSchema;
|
|
190
|
-
}
|
|
191
|
-
exports.get_base_schema = get_base_schema;
|
|
192
|
-
/**
|
|
193
|
-
* extract a list of all possible fields for a schema
|
|
194
|
-
* (by walking up the inheritance chain)
|
|
195
|
-
*
|
|
196
|
-
*/
|
|
197
|
-
function extract_all_fields(schema) {
|
|
198
|
-
// returns cached result if any
|
|
199
|
-
// istanbul ignore next
|
|
200
|
-
if (schema._possibleFields) {
|
|
201
|
-
return schema._possibleFields;
|
|
202
|
-
}
|
|
203
|
-
// extract the possible fields from the schema.
|
|
204
|
-
let possibleFields = schema.fields.map((field) => field.name);
|
|
205
|
-
const baseSchema = get_base_schema(schema);
|
|
206
|
-
// istanbul ignore next
|
|
207
|
-
if (baseSchema) {
|
|
208
|
-
const fields = extract_all_fields(baseSchema);
|
|
209
|
-
possibleFields = fields.concat(possibleFields);
|
|
210
|
-
}
|
|
211
|
-
// put in cache to speed up
|
|
212
|
-
schema._possibleFields = possibleFields;
|
|
213
|
-
return possibleFields;
|
|
214
|
-
}
|
|
215
|
-
exports.extract_all_fields = extract_all_fields;
|
|
216
|
-
/**
|
|
217
|
-
* check correctness of option fields against scheme
|
|
218
|
-
*
|
|
219
|
-
* @method check_options_correctness_against_schema
|
|
220
|
-
*
|
|
221
|
-
*/
|
|
222
|
-
function check_options_correctness_against_schema(obj, schema, options) {
|
|
223
|
-
if (!factories_schema_helpers_1.parameters.debugSchemaHelper) {
|
|
224
|
-
return true; // ignoring set
|
|
225
|
-
}
|
|
226
|
-
options = options || {};
|
|
227
|
-
// istanbul ignore next
|
|
228
|
-
if (!(options !== null && typeof options === "object") && !(typeof options === "object")) {
|
|
229
|
-
let message = chalk.red(" Invalid options specified while trying to construct a ") + " " + chalk.yellow(schema.name);
|
|
230
|
-
message += "\n";
|
|
231
|
-
message += chalk.red(" expecting a ") + chalk.yellow(" Object ");
|
|
232
|
-
message += "\n";
|
|
233
|
-
message += chalk.red(" and got a ") + chalk.yellow(typeof options) + chalk.red(" instead ");
|
|
234
|
-
throw new Error(message);
|
|
235
|
-
}
|
|
236
|
-
// istanbul ignore next
|
|
237
|
-
if (options instanceof obj.constructor) {
|
|
238
|
-
return true;
|
|
239
|
-
}
|
|
240
|
-
// extract the possible fields from the schema.
|
|
241
|
-
const possibleFields = obj.constructor.possibleFields || schema._possibleFields;
|
|
242
|
-
// extracts the fields exposed by the option object
|
|
243
|
-
const currentFields = Object.keys(options);
|
|
244
|
-
// get a list of field that are in the 'options' object but not in schema
|
|
245
|
-
// https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore
|
|
246
|
-
function difference(a1, a2) {
|
|
247
|
-
return [a1, a2].reduce((a, b) => a.filter((value) => !b.includes(value)));
|
|
248
|
-
}
|
|
249
|
-
const invalidOptionsFields = difference(currentFields, possibleFields);
|
|
250
|
-
/* istanbul ignore next */
|
|
251
|
-
if (invalidOptionsFields.length > 0) {
|
|
252
|
-
// tslint:disable:no-console
|
|
253
|
-
console.log("expected schema", schema.name);
|
|
254
|
-
console.log(chalk.yellow("possible fields= "), possibleFields.sort().join(" "));
|
|
255
|
-
console.log(chalk.red("current fields= "), currentFields.sort().join(" "));
|
|
256
|
-
console.log(chalk.cyan("invalid_options_fields= "), invalidOptionsFields.sort().join(" "));
|
|
257
|
-
console.log("options = ", options);
|
|
258
|
-
}
|
|
259
|
-
/* istanbul ignore next */
|
|
260
|
-
if (invalidOptionsFields.length !== 0) {
|
|
261
|
-
// tslint:disable:no-console
|
|
262
|
-
console.log(chalk.yellow("possible fields= "), possibleFields.sort().join(" "));
|
|
263
|
-
console.log(chalk.red("current fields= "), currentFields.sort().join(" "));
|
|
264
|
-
throw new Error(" invalid field found in option :" + JSON.stringify(invalidOptionsFields));
|
|
265
|
-
}
|
|
266
|
-
return true;
|
|
267
|
-
}
|
|
268
|
-
exports.check_options_correctness_against_schema = check_options_correctness_against_schema;
|
|
269
|
-
function buildStructuredType2(dataTypeFactory, schemaLight) {
|
|
270
|
-
return new StructuredTypeSchema(schemaLight);
|
|
271
|
-
}
|
|
272
|
-
exports.buildStructuredType2 = buildStructuredType2;
|
|
273
|
-
function buildStructuredType(schemaLight) {
|
|
274
|
-
return new StructuredTypeSchema(schemaLight);
|
|
275
|
-
}
|
|
276
|
-
exports.buildStructuredType = buildStructuredType;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildStructuredType = exports.buildStructuredType2 = exports.check_options_correctness_against_schema = exports.extract_all_fields = exports.get_base_schema = exports.StructuredTypeSchema = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-factory
|
|
6
|
+
*/
|
|
7
|
+
const chalk = require("chalk");
|
|
8
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
9
|
+
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
10
|
+
const node_opcua_utils_1 = require("node-opcua-utils");
|
|
11
|
+
const factories_builtin_types_1 = require("./factories_builtin_types");
|
|
12
|
+
const factories_enumerations_1 = require("./factories_enumerations");
|
|
13
|
+
const factories_factories_1 = require("./factories_factories");
|
|
14
|
+
const factories_schema_helpers_1 = require("./factories_schema_helpers");
|
|
15
|
+
const types_1 = require("./types");
|
|
16
|
+
function figureOutFieldCategory(field) {
|
|
17
|
+
const fieldType = field.fieldType;
|
|
18
|
+
if (field.category) {
|
|
19
|
+
return field.category;
|
|
20
|
+
}
|
|
21
|
+
if ((0, factories_enumerations_1.hasEnumeration)(fieldType)) {
|
|
22
|
+
return types_1.FieldCategory.enumeration;
|
|
23
|
+
}
|
|
24
|
+
else if ((0, factories_builtin_types_1.hasBuiltInType)(fieldType)) {
|
|
25
|
+
return types_1.FieldCategory.basic;
|
|
26
|
+
}
|
|
27
|
+
else if ((0, factories_factories_1.hasStructuredType)(fieldType)) {
|
|
28
|
+
(0, node_opcua_assert_1.assert)(fieldType !== "LocalizedText"); // LocalizedText should be treated as BasicType!!!
|
|
29
|
+
return types_1.FieldCategory.complex;
|
|
30
|
+
}
|
|
31
|
+
return types_1.FieldCategory.basic;
|
|
32
|
+
}
|
|
33
|
+
const regExp = /((ns[0-9]+:)?)(.*)/;
|
|
34
|
+
function figureOutSchema(underConstructSchema, field, category) {
|
|
35
|
+
if (field.schema) {
|
|
36
|
+
return field.schema;
|
|
37
|
+
}
|
|
38
|
+
if (underConstructSchema.name === field.fieldType) {
|
|
39
|
+
return underConstructSchema;
|
|
40
|
+
}
|
|
41
|
+
let returnValue = null;
|
|
42
|
+
// may be the field.type contains a ns<X>: prefix !! like the one found in Beckhoff PLC !
|
|
43
|
+
const m = field.fieldType.match(regExp);
|
|
44
|
+
/* istanbul ignore next */
|
|
45
|
+
if (!m) {
|
|
46
|
+
throw new Error("malformed fieldType ? : " + field.fieldType);
|
|
47
|
+
}
|
|
48
|
+
const fieldTypeWithoutNS = m[3];
|
|
49
|
+
switch (category) {
|
|
50
|
+
case types_1.FieldCategory.complex:
|
|
51
|
+
if ((0, factories_factories_1.hasStructuredType)(field.fieldType)) {
|
|
52
|
+
returnValue = (0, factories_factories_1.getStructuredTypeSchema)(fieldTypeWithoutNS);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// LocalizedText etc ...
|
|
56
|
+
returnValue = (0, factories_builtin_types_1.getBuildInType)(fieldTypeWithoutNS);
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
case types_1.FieldCategory.basic:
|
|
60
|
+
returnValue = (0, factories_builtin_types_1.getBuildInType)(fieldTypeWithoutNS);
|
|
61
|
+
if (!returnValue) {
|
|
62
|
+
returnValue = (0, factories_factories_1.getStructuredTypeSchema)(fieldTypeWithoutNS);
|
|
63
|
+
if (returnValue) {
|
|
64
|
+
console.log("Why ?");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
case types_1.FieldCategory.enumeration:
|
|
69
|
+
returnValue = (0, factories_enumerations_1.getEnumeration)(fieldTypeWithoutNS);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
if (null === returnValue || undefined === returnValue) {
|
|
73
|
+
try {
|
|
74
|
+
returnValue = (0, factories_enumerations_1.getEnumeration)(fieldTypeWithoutNS);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
console.log(err);
|
|
78
|
+
}
|
|
79
|
+
throw new Error("Cannot find Schema for field with name " +
|
|
80
|
+
field.name +
|
|
81
|
+
" fieldTypeWithoutNS= " +
|
|
82
|
+
fieldTypeWithoutNS +
|
|
83
|
+
" with type " +
|
|
84
|
+
field.fieldType +
|
|
85
|
+
" category = " +
|
|
86
|
+
category +
|
|
87
|
+
JSON.stringify(field, null, "\t"));
|
|
88
|
+
}
|
|
89
|
+
return returnValue;
|
|
90
|
+
}
|
|
91
|
+
function buildField(underConstructSchema, fieldLight) {
|
|
92
|
+
const category = figureOutFieldCategory(fieldLight);
|
|
93
|
+
const schema = figureOutSchema(underConstructSchema, fieldLight, category);
|
|
94
|
+
/* istanbul ignore next */
|
|
95
|
+
if (!schema) {
|
|
96
|
+
throw new Error("expecting a valid schema for field with name " +
|
|
97
|
+
fieldLight.name +
|
|
98
|
+
" with type " +
|
|
99
|
+
fieldLight.fieldType +
|
|
100
|
+
" category" +
|
|
101
|
+
category);
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
name: (0, node_opcua_utils_1.lowerFirstLetter)(fieldLight.name),
|
|
105
|
+
category,
|
|
106
|
+
defaultValue: fieldLight.defaultValue,
|
|
107
|
+
isArray: fieldLight.isArray,
|
|
108
|
+
documentation: fieldLight.documentation,
|
|
109
|
+
fieldType: fieldLight.fieldType,
|
|
110
|
+
switchBit: fieldLight.switchBit,
|
|
111
|
+
switchValue: fieldLight.switchValue,
|
|
112
|
+
schema
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
class StructuredTypeSchema extends types_1.TypeSchemaBase {
|
|
116
|
+
constructor(options) {
|
|
117
|
+
super(options);
|
|
118
|
+
this.bitFields = options.bitFields;
|
|
119
|
+
this.baseType = options.baseType;
|
|
120
|
+
this.category = types_1.FieldCategory.complex;
|
|
121
|
+
if ((0, factories_builtin_types_1.hasBuiltInType)(options.name)) {
|
|
122
|
+
this.category = types_1.FieldCategory.basic;
|
|
123
|
+
}
|
|
124
|
+
this.fields = options.fields.map(buildField.bind(null, this));
|
|
125
|
+
this.id = new node_opcua_nodeid_1.NodeId();
|
|
126
|
+
this.dataTypeNodeId = new node_opcua_nodeid_1.NodeId();
|
|
127
|
+
this._possibleFields = this.fields.map((field) => field.name);
|
|
128
|
+
this._baseSchema = null;
|
|
129
|
+
}
|
|
130
|
+
toString() {
|
|
131
|
+
var _a, _b, _c;
|
|
132
|
+
const str = [];
|
|
133
|
+
str.push("name = " + this.name);
|
|
134
|
+
str.push("baseType = " + this.baseType);
|
|
135
|
+
str.push("id = " + this.id.toString());
|
|
136
|
+
str.push("bitFields = " + (this.bitFields ? this.bitFields.map((b) => b.name).join(" ") : undefined));
|
|
137
|
+
str.push("dataTypeNodeId = " + (this.dataTypeNodeId ? this.dataTypeNodeId.toString() : undefined));
|
|
138
|
+
str.push("documentation = " + this.documentation);
|
|
139
|
+
str.push("encodingDefaultBinary = " + ((_a = this.encodingDefaultBinary) === null || _a === void 0 ? void 0 : _a.toString()));
|
|
140
|
+
str.push("encodingDefaultXml = " + ((_b = this.encodingDefaultXml) === null || _b === void 0 ? void 0 : _b.toString()));
|
|
141
|
+
str.push("encodingDefaultJson = " + ((_c = this.encodingDefaultJson) === null || _c === void 0 ? void 0 : _c.toString()));
|
|
142
|
+
for (const f of this.fields) {
|
|
143
|
+
str.push(" field = " +
|
|
144
|
+
f.name.padEnd(30) +
|
|
145
|
+
" isArray= " +
|
|
146
|
+
(f.isArray ? true : false) +
|
|
147
|
+
" " +
|
|
148
|
+
f.fieldType.toString().padEnd(30) +
|
|
149
|
+
(f.switchBit !== undefined ? " switchBit " + f.switchBit : "") +
|
|
150
|
+
(f.switchValue !== undefined ? " switchValue " + f.switchValue : ""));
|
|
151
|
+
}
|
|
152
|
+
return str.join("\n");
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.StructuredTypeSchema = StructuredTypeSchema;
|
|
156
|
+
/**
|
|
157
|
+
*
|
|
158
|
+
* @method get_base_schema
|
|
159
|
+
* @param schema
|
|
160
|
+
* @return {*}
|
|
161
|
+
*
|
|
162
|
+
*/
|
|
163
|
+
function get_base_schema(schema) {
|
|
164
|
+
let baseSchema = schema._baseSchema;
|
|
165
|
+
if (baseSchema) {
|
|
166
|
+
return baseSchema;
|
|
167
|
+
}
|
|
168
|
+
if (schema.baseType === "ExtensionObject" || schema.baseType === "DataTypeDefinition") {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
if (schema.baseType === "Union") {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
if (schema.baseType && schema.baseType !== "BaseUAObject" && schema.baseType !== "DataTypeDefinition") {
|
|
175
|
+
if (!(0, factories_factories_1.hasStructuredType)(schema.baseType)) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const baseType = (0, factories_factories_1.getStructureTypeConstructor)(schema.baseType);
|
|
179
|
+
// istanbul ignore next
|
|
180
|
+
if (!baseType) {
|
|
181
|
+
throw new Error(" cannot find factory for " + schema.baseType);
|
|
182
|
+
}
|
|
183
|
+
if (baseType.prototype.schema) {
|
|
184
|
+
baseSchema = baseType.prototype.schema;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// put in cache for speedup
|
|
188
|
+
schema._baseSchema = baseSchema;
|
|
189
|
+
return baseSchema;
|
|
190
|
+
}
|
|
191
|
+
exports.get_base_schema = get_base_schema;
|
|
192
|
+
/**
|
|
193
|
+
* extract a list of all possible fields for a schema
|
|
194
|
+
* (by walking up the inheritance chain)
|
|
195
|
+
*
|
|
196
|
+
*/
|
|
197
|
+
function extract_all_fields(schema) {
|
|
198
|
+
// returns cached result if any
|
|
199
|
+
// istanbul ignore next
|
|
200
|
+
if (schema._possibleFields) {
|
|
201
|
+
return schema._possibleFields;
|
|
202
|
+
}
|
|
203
|
+
// extract the possible fields from the schema.
|
|
204
|
+
let possibleFields = schema.fields.map((field) => field.name);
|
|
205
|
+
const baseSchema = get_base_schema(schema);
|
|
206
|
+
// istanbul ignore next
|
|
207
|
+
if (baseSchema) {
|
|
208
|
+
const fields = extract_all_fields(baseSchema);
|
|
209
|
+
possibleFields = fields.concat(possibleFields);
|
|
210
|
+
}
|
|
211
|
+
// put in cache to speed up
|
|
212
|
+
schema._possibleFields = possibleFields;
|
|
213
|
+
return possibleFields;
|
|
214
|
+
}
|
|
215
|
+
exports.extract_all_fields = extract_all_fields;
|
|
216
|
+
/**
|
|
217
|
+
* check correctness of option fields against scheme
|
|
218
|
+
*
|
|
219
|
+
* @method check_options_correctness_against_schema
|
|
220
|
+
*
|
|
221
|
+
*/
|
|
222
|
+
function check_options_correctness_against_schema(obj, schema, options) {
|
|
223
|
+
if (!factories_schema_helpers_1.parameters.debugSchemaHelper) {
|
|
224
|
+
return true; // ignoring set
|
|
225
|
+
}
|
|
226
|
+
options = options || {};
|
|
227
|
+
// istanbul ignore next
|
|
228
|
+
if (!(options !== null && typeof options === "object") && !(typeof options === "object")) {
|
|
229
|
+
let message = chalk.red(" Invalid options specified while trying to construct a ") + " " + chalk.yellow(schema.name);
|
|
230
|
+
message += "\n";
|
|
231
|
+
message += chalk.red(" expecting a ") + chalk.yellow(" Object ");
|
|
232
|
+
message += "\n";
|
|
233
|
+
message += chalk.red(" and got a ") + chalk.yellow(typeof options) + chalk.red(" instead ");
|
|
234
|
+
throw new Error(message);
|
|
235
|
+
}
|
|
236
|
+
// istanbul ignore next
|
|
237
|
+
if (options instanceof obj.constructor) {
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
// extract the possible fields from the schema.
|
|
241
|
+
const possibleFields = obj.constructor.possibleFields || schema._possibleFields;
|
|
242
|
+
// extracts the fields exposed by the option object
|
|
243
|
+
const currentFields = Object.keys(options);
|
|
244
|
+
// get a list of field that are in the 'options' object but not in schema
|
|
245
|
+
// https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore
|
|
246
|
+
function difference(a1, a2) {
|
|
247
|
+
return [a1, a2].reduce((a, b) => a.filter((value) => !b.includes(value)));
|
|
248
|
+
}
|
|
249
|
+
const invalidOptionsFields = difference(currentFields, possibleFields);
|
|
250
|
+
/* istanbul ignore next */
|
|
251
|
+
if (invalidOptionsFields.length > 0) {
|
|
252
|
+
// tslint:disable:no-console
|
|
253
|
+
console.log("expected schema", schema.name);
|
|
254
|
+
console.log(chalk.yellow("possible fields= "), possibleFields.sort().join(" "));
|
|
255
|
+
console.log(chalk.red("current fields= "), currentFields.sort().join(" "));
|
|
256
|
+
console.log(chalk.cyan("invalid_options_fields= "), invalidOptionsFields.sort().join(" "));
|
|
257
|
+
console.log("options = ", options);
|
|
258
|
+
}
|
|
259
|
+
/* istanbul ignore next */
|
|
260
|
+
if (invalidOptionsFields.length !== 0) {
|
|
261
|
+
// tslint:disable:no-console
|
|
262
|
+
console.log(chalk.yellow("possible fields= "), possibleFields.sort().join(" "));
|
|
263
|
+
console.log(chalk.red("current fields= "), currentFields.sort().join(" "));
|
|
264
|
+
throw new Error(" invalid field found in option :" + JSON.stringify(invalidOptionsFields));
|
|
265
|
+
}
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
exports.check_options_correctness_against_schema = check_options_correctness_against_schema;
|
|
269
|
+
function buildStructuredType2(dataTypeFactory, schemaLight) {
|
|
270
|
+
return new StructuredTypeSchema(schemaLight);
|
|
271
|
+
}
|
|
272
|
+
exports.buildStructuredType2 = buildStructuredType2;
|
|
273
|
+
function buildStructuredType(schemaLight) {
|
|
274
|
+
return new StructuredTypeSchema(schemaLight);
|
|
275
|
+
}
|
|
276
|
+
exports.buildStructuredType = buildStructuredType;
|
|
277
277
|
//# sourceMappingURL=factories_structuredTypeSchema.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-factory
|
|
3
|
-
*/
|
|
4
|
-
export * from "./constructor_type";
|
|
5
|
-
export * from "./datatype_factory";
|
|
6
|
-
export * from "./factories_id_generator";
|
|
7
|
-
export * from "./factories_enumerations";
|
|
8
|
-
export * from "./factories_basic_type";
|
|
9
|
-
export * from "./factories_builtin_types";
|
|
10
|
-
export * from "./factories_builtin_types_special";
|
|
11
|
-
export * from "./factories_baseobject";
|
|
12
|
-
export * from "./types";
|
|
13
|
-
export * from "./factories_schema_helpers";
|
|
14
|
-
export * from "./factories_factories";
|
|
15
|
-
export * from "./factories_structuredTypeSchema";
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-factory
|
|
3
|
+
*/
|
|
4
|
+
export * from "./constructor_type";
|
|
5
|
+
export * from "./datatype_factory";
|
|
6
|
+
export * from "./factories_id_generator";
|
|
7
|
+
export * from "./factories_enumerations";
|
|
8
|
+
export * from "./factories_basic_type";
|
|
9
|
+
export * from "./factories_builtin_types";
|
|
10
|
+
export * from "./factories_builtin_types_special";
|
|
11
|
+
export * from "./factories_baseobject";
|
|
12
|
+
export * from "./types";
|
|
13
|
+
export * from "./factories_schema_helpers";
|
|
14
|
+
export * from "./factories_factories";
|
|
15
|
+
export * from "./factories_structuredTypeSchema";
|
package/dist/index.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
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-factory
|
|
19
|
-
*/
|
|
20
|
-
__exportStar(require("./constructor_type"), exports);
|
|
21
|
-
__exportStar(require("./datatype_factory"), exports);
|
|
22
|
-
__exportStar(require("./factories_id_generator"), exports);
|
|
23
|
-
__exportStar(require("./factories_enumerations"), exports);
|
|
24
|
-
__exportStar(require("./factories_basic_type"), exports);
|
|
25
|
-
__exportStar(require("./factories_builtin_types"), exports);
|
|
26
|
-
__exportStar(require("./factories_builtin_types_special"), exports);
|
|
27
|
-
__exportStar(require("./factories_baseobject"), exports);
|
|
28
|
-
__exportStar(require("./types"), exports);
|
|
29
|
-
__exportStar(require("./factories_schema_helpers"), exports);
|
|
30
|
-
__exportStar(require("./factories_factories"), exports);
|
|
31
|
-
__exportStar(require("./factories_structuredTypeSchema"), 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-factory
|
|
19
|
+
*/
|
|
20
|
+
__exportStar(require("./constructor_type"), exports);
|
|
21
|
+
__exportStar(require("./datatype_factory"), exports);
|
|
22
|
+
__exportStar(require("./factories_id_generator"), exports);
|
|
23
|
+
__exportStar(require("./factories_enumerations"), exports);
|
|
24
|
+
__exportStar(require("./factories_basic_type"), exports);
|
|
25
|
+
__exportStar(require("./factories_builtin_types"), exports);
|
|
26
|
+
__exportStar(require("./factories_builtin_types_special"), exports);
|
|
27
|
+
__exportStar(require("./factories_baseobject"), exports);
|
|
28
|
+
__exportStar(require("./types"), exports);
|
|
29
|
+
__exportStar(require("./factories_schema_helpers"), exports);
|
|
30
|
+
__exportStar(require("./factories_factories"), exports);
|
|
31
|
+
__exportStar(require("./factories_structuredTypeSchema"), exports);
|
|
32
32
|
//# sourceMappingURL=index.js.map
|