node-opcua-schemas
Advanced tools
Comparing version 2.73.0 to 2.73.1
@@ -9,3 +9,3 @@ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream"; | ||
static possibleFields: string[]; | ||
constructor(options: any, schema: IStructuredTypeSchema, factory: DataTypeFactory); | ||
constructor(options: Record<string, unknown>, schema: IStructuredTypeSchema, factory: DataTypeFactory); | ||
encode(stream: OutputBinaryStream): void; | ||
@@ -12,0 +12,0 @@ decode(stream: BinaryStream): void; |
@@ -193,12 +193,13 @@ "use strict"; | ||
const name = field.name; | ||
const value = getFieldValue(field, options); | ||
switch (field.category) { | ||
case node_opcua_factory_1.FieldCategory.complex: { | ||
if (field.allowSubType) { | ||
validateSubTypeA(factory, field, options[name]); | ||
validateSubTypeA(factory, field, value); | ||
if (field.isArray) { | ||
const arr = options[name] || []; | ||
const arr = value || []; | ||
thisAny[name] = arr.map((x) => x.clone()); | ||
} | ||
else { | ||
const e = options[name]; | ||
const e = value; | ||
if (e !== null && !(e instanceof node_opcua_extension_object_1.ExtensionObject)) { | ||
@@ -214,7 +215,7 @@ errorLog("initializeField: array element is not an ExtensionObject"); | ||
if (field.isArray) { | ||
const arr = options[name] || []; | ||
const arr = value || []; | ||
thisAny[name] = arr.map((x) => (constructor ? new constructor(x) : null)); | ||
} | ||
else { | ||
thisAny[name] = constructor ? new constructor(options[name]) : null; | ||
thisAny[name] = constructor ? new constructor(value) : null; | ||
} | ||
@@ -229,9 +230,9 @@ } | ||
if (field.allowSubType) { | ||
validateSubTypeA(factory, field, options[name]); | ||
validateSubTypeA(factory, field, value); | ||
} | ||
if (field.isArray) { | ||
thisAny[name] = (0, node_opcua_factory_1.initialize_field_array)(field, options[name], factory); | ||
thisAny[name] = (0, node_opcua_factory_1.initialize_field_array)(field, value, factory); | ||
} | ||
else { | ||
thisAny[name] = (0, node_opcua_factory_1.initialize_field)(field, options[name], factory); | ||
thisAny[name] = (0, node_opcua_factory_1.initialize_field)(field, value, factory); | ||
} | ||
@@ -241,13 +242,9 @@ break; | ||
} | ||
/** | ||
* @private | ||
* @param thisAny | ||
* @param options | ||
* @param schema | ||
* @param factory | ||
*/ | ||
function initializeFields(thisAny, options, schema, factory) { | ||
function getFieldValue(field, options) { | ||
return options[field.name] !== undefined ? options[field.name] : options[field.originalName]; | ||
} | ||
function initializeFields(thisAny, options, schema, factory, params) { | ||
// initialize base class first | ||
if (schema._baseSchema && schema._baseSchema.fields.length) { | ||
initializeFields(thisAny, options, schema._baseSchema, factory); | ||
initializeFields(thisAny, options, schema._baseSchema, factory, params); | ||
} | ||
@@ -257,4 +254,5 @@ // finding fields that are in options but not in schema! | ||
const name = field.name; | ||
const value = getFieldValue(field, options); | ||
// dealing with optional fields | ||
if (field.switchBit !== undefined && options[field.name] === undefined) { | ||
if (field.switchBit !== undefined && value === undefined) { | ||
thisAny[name] = undefined; | ||
@@ -412,3 +410,3 @@ continue; | ||
(0, node_opcua_factory_1.check_options_correctness_against_schema)(this, this.schema, options); | ||
initializeFields(this, options, this.schema, factory); | ||
initializeFields(this, options, this.schema, factory, { caseInsensitive: true }); | ||
} | ||
@@ -459,4 +457,5 @@ encode(stream) { | ||
// dealing with optional fields | ||
const value = getFieldValue(field, options); | ||
/* istanbul ignore next */ | ||
if (uniqueFieldHasBeenFound && options[field.name] !== undefined) { | ||
if (uniqueFieldHasBeenFound && value !== undefined) { | ||
// let try to be helpful for the developper by providing some hint | ||
@@ -479,3 +478,3 @@ debugLog(this.schema); | ||
// the is no switchFieldName , in this case the i | ||
if (options[name] === undefined) { | ||
if (value === undefined) { | ||
continue; | ||
@@ -491,6 +490,6 @@ } | ||
if (field.isArray) { | ||
this[name] = (options[name] || []).map((x) => (constuctor ? new constuctor(x) : null)); | ||
this[name] = (value || []).map((x) => (constuctor ? new constuctor(x) : null)); | ||
} | ||
else { | ||
this[name] = constuctor ? new constuctor(options[name]) : null; | ||
this[name] = constuctor ? new constuctor(value) : null; | ||
} | ||
@@ -503,6 +502,6 @@ // xx processStructuredType(fieldSchema); | ||
if (field.isArray) { | ||
this[name] = (0, node_opcua_factory_1.initialize_field_array)(field, options[name]); | ||
this[name] = (0, node_opcua_factory_1.initialize_field_array)(field, value); | ||
} | ||
else { | ||
this[name] = (0, node_opcua_factory_1.initialize_field)(field, options[name]); | ||
this[name] = (0, node_opcua_factory_1.initialize_field)(field, value); | ||
} | ||
@@ -605,3 +604,3 @@ break; | ||
} | ||
pojo[field.name] = fieldToJSON(field, value); | ||
pojo[field.originalName] = fieldToJSON(field, value); | ||
break; | ||
@@ -608,0 +607,0 @@ } |
{ | ||
"name": "node-opcua-schemas", | ||
"version": "2.73.0", | ||
"version": "2.73.1", | ||
"description": "pure nodejs OPCUA SDK - module -schemas", | ||
@@ -17,10 +17,10 @@ "main": "dist/source/index.js", | ||
"node-opcua-binary-stream": "2.73.0", | ||
"node-opcua-data-model": "2.73.0", | ||
"node-opcua-data-model": "2.73.1", | ||
"node-opcua-debug": "2.71.0", | ||
"node-opcua-enum": "2.71.0", | ||
"node-opcua-extension-object": "2.73.0", | ||
"node-opcua-factory": "2.73.0", | ||
"node-opcua-extension-object": "2.73.1", | ||
"node-opcua-factory": "2.73.1", | ||
"node-opcua-nodeid": "2.71.0", | ||
"node-opcua-utils": "2.71.0", | ||
"node-opcua-variant": "2.73.0", | ||
"node-opcua-variant": "2.73.1", | ||
"node-opcua-xml2json": "2.73.0", | ||
@@ -30,3 +30,3 @@ "thenify": "^3.3.1" | ||
"devDependencies": { | ||
"node-opcua-packet-analyzer": "2.73.0" | ||
"node-opcua-packet-analyzer": "2.73.1" | ||
}, | ||
@@ -48,3 +48,3 @@ "author": "Etienne Rossignon", | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "b23a87c1ef777c0d8b680f45ee77e2a319feb092" | ||
"gitHead": "684a796e88e1732f418f2ada6aca2808e0115de8" | ||
} |
@@ -239,2 +239,3 @@ /** | ||
const name = field.name; | ||
const value = getFieldValue(field, options); | ||
@@ -244,8 +245,8 @@ switch (field.category) { | ||
if (field.allowSubType) { | ||
validateSubTypeA(factory, field, options[name]); | ||
validateSubTypeA(factory, field, value); | ||
if (field.isArray) { | ||
const arr = (options[name] as unknown[]) || []; | ||
const arr = (value as unknown[]) || []; | ||
thisAny[name] = arr.map((x: any) => x.clone()); | ||
} else { | ||
const e = options[name] as ExtensionObject; | ||
const e = value as ExtensionObject; | ||
if (e !== null && !(e instanceof ExtensionObject)) { | ||
@@ -260,6 +261,6 @@ errorLog("initializeField: array element is not an ExtensionObject"); | ||
if (field.isArray) { | ||
const arr = (options[name] as unknown[]) || []; | ||
const arr = (value as unknown[]) || []; | ||
thisAny[name] = arr.map((x: any) => (constructor ? new constructor(x) : null)); | ||
} else { | ||
thisAny[name] = constructor ? new constructor(options[name]) : null; | ||
thisAny[name] = constructor ? new constructor(value) : null; | ||
} | ||
@@ -274,8 +275,8 @@ } | ||
if (field.allowSubType) { | ||
validateSubTypeA(factory, field, options[name]); | ||
validateSubTypeA(factory, field, value); | ||
} | ||
if (field.isArray) { | ||
thisAny[name] = initialize_field_array(field, options[name], factory); | ||
thisAny[name] = initialize_field_array(field, value, factory); | ||
} else { | ||
thisAny[name] = initialize_field(field, options[name], factory); | ||
thisAny[name] = initialize_field(field, value, factory); | ||
} | ||
@@ -285,13 +286,21 @@ break; | ||
} | ||
/** | ||
* @private | ||
* @param thisAny | ||
* @param options | ||
* @param schema | ||
* @param factory | ||
*/ | ||
function initializeFields(thisAny: any, options: Record<string, unknown>, schema: IStructuredTypeSchema, factory: DataTypeFactory) { | ||
interface InitializeFieldOptions { | ||
caseInsensitive?: boolean; | ||
} | ||
function getFieldValue(field: FieldType, options: Record<string, unknown>) { | ||
return options[field.name] !== undefined ? options[field.name] : options[field.originalName]; | ||
} | ||
function initializeFields( | ||
thisAny: any, | ||
options: Record<string, unknown>, | ||
schema: IStructuredTypeSchema, | ||
factory: DataTypeFactory, | ||
params: InitializeFieldOptions | ||
) { | ||
// initialize base class first | ||
if (schema._baseSchema && schema._baseSchema.fields.length) { | ||
initializeFields(thisAny, options, schema._baseSchema!, factory); | ||
initializeFields(thisAny, options, schema._baseSchema!, factory, params); | ||
} | ||
@@ -301,5 +310,6 @@ // finding fields that are in options but not in schema! | ||
const name = field.name; | ||
const value = getFieldValue(field, options); | ||
// dealing with optional fields | ||
if (field.switchBit !== undefined && options[field.name] === undefined) { | ||
if (field.switchBit !== undefined && value === undefined) { | ||
thisAny[name] = undefined; | ||
@@ -479,3 +489,3 @@ continue; | ||
constructor(options: any, schema: IStructuredTypeSchema, factory: DataTypeFactory) { | ||
constructor(options: Record<string, unknown>, schema: IStructuredTypeSchema, factory: DataTypeFactory) { | ||
assert(schema, "expecting a schema here "); | ||
@@ -491,3 +501,3 @@ assert(factory, "expecting a DataTypeFactory"); | ||
initializeFields(this as any, options, this.schema, factory); | ||
initializeFields(this as any, options, this.schema, factory, { caseInsensitive: true }); | ||
} | ||
@@ -555,4 +565,5 @@ | ||
const value = getFieldValue(field, options); | ||
/* istanbul ignore next */ | ||
if (uniqueFieldHasBeenFound && options[field.name] !== undefined) { | ||
if (uniqueFieldHasBeenFound && value !== undefined) { | ||
// let try to be helpful for the developper by providing some hint | ||
@@ -577,3 +588,3 @@ debugLog(this.schema); | ||
// the is no switchFieldName , in this case the i | ||
if (options[name] === undefined) { | ||
if (value === undefined) { | ||
continue; | ||
@@ -590,5 +601,5 @@ } | ||
if (field.isArray) { | ||
(this as any)[name] = (options[name] || []).map((x: any) => (constuctor ? new constuctor(x) : null)); | ||
(this as any)[name] = ((value as any) || []).map((x: any) => (constuctor ? new constuctor(x) : null)); | ||
} else { | ||
(this as any)[name] = constuctor ? new constuctor(options[name]) : null; | ||
(this as any)[name] = constuctor ? new constuctor(value) : null; | ||
} | ||
@@ -601,5 +612,5 @@ // xx processStructuredType(fieldSchema); | ||
if (field.isArray) { | ||
(this as any)[name] = initialize_field_array(field, options[name]); | ||
(this as any)[name] = initialize_field_array(field, value); | ||
} else { | ||
(this as any)[name] = initialize_field(field, options[name]); | ||
(this as any)[name] = initialize_field(field, value); | ||
} | ||
@@ -717,3 +728,3 @@ break; | ||
} | ||
pojo[field.name] = fieldToJSON(field, value); | ||
pojo[field.originalName] = fieldToJSON(field, value); | ||
break; | ||
@@ -745,3 +756,6 @@ } | ||
export function createDynamicObjectConstructor(schema: IStructuredTypeSchema, dataTypeFactory: DataTypeFactory): AnyConstructorFunc { | ||
export function createDynamicObjectConstructor( | ||
schema: IStructuredTypeSchema, | ||
dataTypeFactory: DataTypeFactory | ||
): AnyConstructorFunc { | ||
const schemaPriv = schema as any; | ||
@@ -748,0 +762,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
169743
2838
+ Addednode-opcua-data-model@2.73.1(transitive)
+ Addednode-opcua-extension-object@2.73.1(transitive)
+ Addednode-opcua-factory@2.73.1(transitive)
+ Addednode-opcua-variant@2.73.1(transitive)
- Removednode-opcua-data-model@2.73.0(transitive)
- Removednode-opcua-extension-object@2.73.0(transitive)
- Removednode-opcua-factory@2.73.0(transitive)
- Removednode-opcua-variant@2.73.0(transitive)
Updatednode-opcua-data-model@2.73.1
Updatednode-opcua-factory@2.73.1
Updatednode-opcua-variant@2.73.1