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