node-opcua-schemas
Advanced tools
Comparing version 2.6.0-alpha.7 to 2.6.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createDynamicObjectConstructor = exports.DynamicExtensionObject = exports.getOrCreateConstructor = void 0; | ||
/** | ||
* @module node-opcua-schemas | ||
*/ | ||
const node_opcua_assert_1 = require("node-opcua-assert"); | ||
@@ -16,2 +19,3 @@ const node_opcua_debug_1 = require("node-opcua-debug"); | ||
const schema = dataTypeFactory.getStructuredTypeSchema(dataTypeName); | ||
// istanbul ignore next | ||
if (!schema) { | ||
@@ -24,5 +28,7 @@ throw new Error("Unknown type in dictionary " + dataTypeName); | ||
} | ||
// istanbul ignore next | ||
if (!dataTypeFactory.hasStructuredType(dataTypeName)) { | ||
dataTypeFactory.registerClassDefinition(schema.id, dataTypeName, constructor); | ||
return constructor; | ||
// hrow new Error("constructor should now be registered - " + fieldType); | ||
} | ||
@@ -63,2 +69,3 @@ if (encodingDefaultBinary && encodingDefaultBinary.value !== 0) { | ||
if (!obj[field.name].encode) { | ||
// tslint:disable:no-console | ||
console.log(obj.schema.fields, field); | ||
@@ -85,2 +92,3 @@ throw new Error("encodeArrayOrElement: object field " | ||
else { | ||
// construct an instance | ||
const constructor = factory.getStructureTypeConstructor(field.fieldType); | ||
@@ -113,2 +121,3 @@ const element = new constructor({}); | ||
const constructor = factory.getStructureTypeConstructor(field.fieldType); | ||
// getOrCreateConstructor(field.fieldType, factory) || BaseUAObject; | ||
if (field.isArray) { | ||
@@ -124,2 +133,3 @@ const arr = options[name] || []; | ||
} | ||
// xx processStructuredType(fieldSchema); | ||
break; | ||
@@ -138,8 +148,18 @@ } | ||
} | ||
/** | ||
* @private | ||
* @param thisAny | ||
* @param options | ||
* @param schema | ||
* @param factory | ||
*/ | ||
function initializeFields(thisAny, options, schema, factory) { | ||
// initialize base class first | ||
if (schema._baseSchema && schema._baseSchema.fields.length) { | ||
initializeFields(thisAny, options, schema._baseSchema, factory); | ||
} | ||
// finding fields that are in options but not in schema! | ||
for (const field of schema.fields) { | ||
const name = field.name; | ||
// dealing with optional fields | ||
if (field.switchBit !== undefined && options[field.name] === undefined) { | ||
@@ -159,2 +179,3 @@ (thisAny)[name] = undefined; | ||
function _internal_encodeFields(thisAny, schema, stream) { | ||
// encodeFields base class first | ||
if (schema._baseSchema && schema._baseSchema.fields.length) { | ||
@@ -164,2 +185,3 @@ _internal_encodeFields(thisAny, schema._baseSchema, stream); | ||
for (const field of schema.fields) { | ||
// ignore | ||
if (field.switchBit !== undefined && (thisAny)[field.name] === undefined) { | ||
@@ -177,2 +199,3 @@ continue; | ||
default: | ||
/* istanbul ignore next*/ | ||
throw new Error("Invalid category " + field.category + " " + node_opcua_factory_1.FieldCategory[field.category]); | ||
@@ -183,2 +206,3 @@ } | ||
function makeBitField(thisAny, schema, bo) { | ||
// tslint:disable-next-line: prefer-const | ||
let { bitField, offset, allOptional } = schema._baseSchema ? makeBitField(thisAny, schema._baseSchema, bo) : bo; | ||
@@ -195,2 +219,3 @@ let nbOptionalFields = 0; | ||
} | ||
// tslint:disable-next-line:no-bitwise | ||
bitField |= (1 << (field.switchBit + offset)); | ||
@@ -202,2 +227,3 @@ } | ||
const hasOptionalFields = hasOptionalFieldsF(schema); | ||
// ============ Deal with switchBits | ||
if (hasOptionalFields) { | ||
@@ -212,2 +238,3 @@ const { bitField, allOptional } = makeBitField(thisAny, schema, { bitField: 0, offset: 0, allOptional: true }); | ||
function internal_decodeFields(thisAny, bitField, hasOptionalFields, schema, stream, factory) { | ||
// encodeFields base class first | ||
if (schema._baseSchema && schema._baseSchema.fields.length) { | ||
@@ -217,3 +244,5 @@ internal_decodeFields(thisAny, bitField, hasOptionalFields, schema._baseSchema, stream, factory); | ||
for (const field of schema.fields) { | ||
// ignore fields that have a switch bit when bit is not set | ||
if (hasOptionalFields && field.switchBit !== undefined) { | ||
// tslint:disable-next-line:no-bitwise | ||
if ((bitField & (1 << field.switchBit)) === 0) { | ||
@@ -225,2 +254,3 @@ (thisAny)[field.name] = undefined; | ||
if (field.category === node_opcua_factory_1.FieldCategory.complex && (thisAny)[field.name] === undefined) { | ||
// need to create empty structure for deserialisation | ||
initializeField(field, thisAny, {}, schema, factory); | ||
@@ -239,2 +269,3 @@ } | ||
default: | ||
/* istanbul ignore next*/ | ||
throw new Error("Invalid category " + field.category + " " + node_opcua_factory_1.FieldCategory[field.category]); | ||
@@ -245,2 +276,3 @@ } | ||
function decodeFields(thisAny, schema, stream, factory) { | ||
// ============ Deal with switchBits | ||
const hasOptionalFields = hasOptionalFieldsF(schema); | ||
@@ -263,2 +295,3 @@ let bitField = 0; | ||
default: | ||
/* istanbul ignore next*/ | ||
throw new Error("Invalid category " + field.category + " " + node_opcua_factory_1.FieldCategory[field.category]); | ||
@@ -290,3 +323,3 @@ } | ||
const _private = new WeakMap(); | ||
let DynamicExtensionObject = (() => { | ||
let DynamicExtensionObject = /** @class */ (() => { | ||
class DynamicExtensionObject extends node_opcua_extension_object_1.ExtensionObject { | ||
@@ -329,2 +362,3 @@ constructor(options, schema, factory) { | ||
exports.DynamicExtensionObject = DynamicExtensionObject; | ||
// tslint:disable-next-line:max-classes-per-file | ||
class UnionBaseClass extends node_opcua_factory_1.BaseUAObject { | ||
@@ -340,5 +374,7 @@ constructor(options, schema, factory) { | ||
let switchFieldName = ""; | ||
// finding fields that are in options but not in schema! | ||
for (const field of this.schema.fields) { | ||
const name = field.name; | ||
if (field.switchValue === undefined) { | ||
// this is the switch value field | ||
switchFieldName = field.name; | ||
@@ -349,3 +385,6 @@ continue; | ||
node_opcua_assert_1.assert(field.switchValue !== undefined, "union schema must only have one switched value field"); | ||
// dealing with optional fields | ||
/* istanbul ignore next */ | ||
if (uniqueFieldHasBeenFound && options[field.name] !== undefined) { | ||
// let try to be helpful for the developper by providing some hint | ||
debugLog(this.schema); | ||
@@ -357,2 +396,3 @@ throw new Error("union must have only one choice in " + JSON.stringify(options) + | ||
if (options[switchFieldName] !== undefined) { | ||
// then options[switchFieldName] must equal | ||
if (options[switchFieldName] !== field.switchValue) { | ||
@@ -363,2 +403,3 @@ continue; | ||
else { | ||
// the is no switchFieldName , in this case the i | ||
if (options[name] === undefined) { | ||
@@ -373,2 +414,3 @@ continue; | ||
const constuctor = factory.getStructureTypeConstructor(field.fieldType); | ||
// getOrCreateConstructor(field.fieldType, factory) || BaseUAObject; | ||
if (field.isArray) { | ||
@@ -380,2 +422,3 @@ this[name] = (options[name] || []).map((x) => constuctor ? new constuctor(x) : null); | ||
} | ||
// xx processStructuredType(fieldSchema); | ||
break; | ||
@@ -400,4 +443,7 @@ } | ||
const r = schema.fields.filter((f) => f.switchValue !== undefined).map((f) => f.name).join(" , "); | ||
// it is possible also that the switchfield value do not correspond to a valid field | ||
const foundFieldForSwitchValue = schema.fields.findIndex((f) => f.switchValue !== undefined && f.switchValue === options[switchFieldName]); | ||
if (foundFieldForSwitchValue) { | ||
// throw new Error(this.schema.name + ": cannot find field with value " | ||
// + options[switchFieldName]); | ||
} | ||
@@ -430,2 +476,3 @@ else { | ||
default: | ||
/* istanbul ignore next*/ | ||
throw new Error("Invalid category " + field.category + " " + node_opcua_factory_1.FieldCategory[field.category]); | ||
@@ -454,2 +501,3 @@ } | ||
default: | ||
/* istanbul ignore next*/ | ||
throw new Error("Invalid category " + field.category + " " + node_opcua_factory_1.FieldCategory[field.category]); | ||
@@ -490,3 +538,4 @@ } | ||
const possibleFields = schema.fields.map((x) => x.name); | ||
let UNION = (() => { | ||
// tslint:disable-next-line:max-classes-per-file | ||
let UNION = /** @class */ (() => { | ||
class UNION extends UnionBaseClass { | ||
@@ -502,2 +551,3 @@ constructor(options) { | ||
})(); | ||
// to do : may be remove DataType suffix here ? | ||
Object.defineProperty(UNION, "name", { value: schema.name }); | ||
@@ -529,2 +579,3 @@ return UNION; | ||
if (((_a = baseSchema.encodingDefaultBinary) === null || _a === void 0 ? void 0 : _a.value) === 0) { | ||
// is abstract | ||
} | ||
@@ -543,5 +594,7 @@ else { | ||
catch (err) { | ||
// xx console.log("createDynamicObjectConstructor err= ", err.message); | ||
} | ||
} | ||
let EXTENSION = (() => { | ||
// tslint:disable-next-line:max-classes-per-file | ||
let EXTENSION = /** @class */ (() => { | ||
class EXTENSION extends BaseClass { | ||
@@ -572,2 +625,3 @@ constructor(options, schema2, factory2) { | ||
})(); | ||
// to do : may be remove DataType suffix here ? | ||
Object.defineProperty(EXTENSION, "name", { value: schema.name }); | ||
@@ -574,0 +628,0 @@ schemaPriv.$Constructor = EXTENSION; |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @module node-opcua-schemas | ||
*/ | ||
import { DataTypeFactory } from "node-opcua-factory"; | ||
@@ -2,0 +5,0 @@ import { NodeId } from "node-opcua-nodeid"; |
"use strict"; | ||
/** | ||
* @module node-opcua-schemas | ||
*/ | ||
// tslint:disable:no-console | ||
// tslint:disable:object-literal-sort-keys | ||
// tslint:disable:no-empty | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -90,2 +96,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
exports.TypeDictionary = TypeDictionary; | ||
/* tslint:disable:object-literal-shorthand */ | ||
const state0 = { | ||
@@ -108,2 +115,3 @@ init: () => { | ||
finish: function () { | ||
// _register_namespace_uri(this.text); | ||
if (doDebug) { | ||
@@ -175,2 +183,3 @@ debugLog("Import NameSpace = ", this.attrs.Namespace, " Location", this.attrs.Location); | ||
if (this.attrs.SourceType) { | ||
// ignore this field, This is a repetition of the base type field with same name | ||
return; | ||
@@ -188,2 +197,3 @@ } | ||
if (field.fieldType === "opc:Bit") { | ||
// do something to collect bits but ignore them as field | ||
structuredType.bitFields = structuredType.bitFields || []; | ||
@@ -203,4 +213,6 @@ const length = this.attrs.Length || 1; | ||
if (this.attrs.SwitchField) { | ||
// field is optional and can be omitted | ||
const switchField = this.attrs.SwitchField; | ||
if (this.attrs.SwitchValue) { | ||
// we are in a union | ||
field.switchValue = parseInt(this.attrs.SwitchValue, 10); | ||
@@ -236,2 +248,3 @@ if (doDebug) { | ||
parser.parseString(xmlString, (err) => { | ||
// resolve and prepare enumerations | ||
for (const key in typeDictionary.enumeratedTypesRaw) { | ||
@@ -252,2 +265,3 @@ if (!typeDictionary.enumeratedTypesRaw.hasOwnProperty(key)) { | ||
} | ||
// create area in navigation order | ||
function createExplorationOrder() { | ||
@@ -289,2 +303,3 @@ const array = []; | ||
} | ||
// resolve complex types | ||
const schemaInVisitingOrder = createExplorationOrder(); | ||
@@ -291,0 +306,0 @@ for (const structuredType of schemaInVisitingOrder) { |
@@ -18,2 +18,3 @@ "use strict"; | ||
function _adjustFieldTypeName(fieldTypeName) { | ||
// special cases | ||
if (fieldTypeName === "String" || fieldTypeName === "CharArray") { | ||
@@ -32,2 +33,3 @@ fieldTypeName = "UAString"; | ||
} | ||
// construct it ! | ||
const structuredType = typeDictionary.getStructuredTypesRawByName(_name); | ||
@@ -53,5 +55,7 @@ if (!structuredType) { | ||
else { | ||
// must be a structure then .... | ||
field.category = node_opcua_factory_1.FieldCategory.complex; | ||
field.schema = _getOrCreateStructuredTypeSchema(fieldTypeName); | ||
if (!field.schema) { | ||
// tslint:disable-next-line:no-console | ||
console.log("cannot find schema for ", fieldTypeName); | ||
@@ -73,4 +77,6 @@ } | ||
field.category = node_opcua_factory_1.FieldCategory.basic; | ||
// try in this | ||
field.schema = _getOrCreateStructuredTypeSchema(fieldTypeName); | ||
if (!field.schema) { | ||
// tslint:disable-next-line:no-console | ||
console.log("What should I do ??", fieldTypeName, " ", node_opcua_factory_1.hasStructuredType(fieldTypeName)); | ||
@@ -91,2 +97,3 @@ } | ||
field.fieldType = "NumericRange"; | ||
// xx console.log(" NumericRange detected here !"); | ||
} | ||
@@ -93,0 +100,0 @@ else { |
@@ -15,4 +15,6 @@ "use strict"; | ||
const l = []; | ||
// enumeration | ||
for (const e of Object.values(enumeratedTypes)) { | ||
l.push(`export enum ${e.name} {`); | ||
// console.log((e.typedEnum as any).enumItems); | ||
for (const v of Object.entries(e.enumValues)) { | ||
@@ -30,2 +32,3 @@ const vv = parseInt(v[0], 10); | ||
var _a; | ||
// base type first | ||
const b = o.baseType; | ||
@@ -41,4 +44,6 @@ const bt = (_a = structuredTypes[b]) === null || _a === void 0 ? void 0 : _a.schema; | ||
let switchFieldName = ""; | ||
// find switchFieldName | ||
for (const field of o.fields) { | ||
if (field.switchValue === undefined) { | ||
// this is the switch value field | ||
switchFieldName = field.name; | ||
@@ -48,2 +53,3 @@ break; | ||
} | ||
// export all flavors | ||
for (const field of o.fields) { | ||
@@ -86,2 +92,3 @@ const name = field.name; | ||
} | ||
// objects | ||
for (const o of Object.values(structuredTypes)) { | ||
@@ -88,0 +95,0 @@ if (alreadyDone[o.schema.name]) { |
{ | ||
"name": "node-opcua-schemas", | ||
"version": "2.6.0-alpha.7", | ||
"version": "2.6.1", | ||
"description": "pure nodejs OPCUA SDK - module -schemas", | ||
@@ -13,17 +13,17 @@ "main": "dist/source/index.js", | ||
"dependencies": { | ||
"node-opcua-assert": "^2.6.0-alpha.1", | ||
"node-opcua-binary-stream": "^2.6.0-alpha.1", | ||
"node-opcua-data-model": "^2.6.0-alpha.7", | ||
"node-opcua-debug": "^2.6.0-alpha.1", | ||
"node-opcua-enum": "^2.6.0-alpha.1", | ||
"node-opcua-extension-object": "^2.6.0-alpha.7", | ||
"node-opcua-factory": "^2.6.0-alpha.7", | ||
"node-opcua-nodeid": "^2.6.0-alpha.1", | ||
"node-opcua-utils": "^2.6.0-alpha.1", | ||
"node-opcua-variant": "^2.6.0-alpha.7", | ||
"node-opcua-xml2json": "^2.6.0-alpha.7", | ||
"node-opcua-assert": "^2.6.1", | ||
"node-opcua-binary-stream": "^2.6.1", | ||
"node-opcua-data-model": "^2.6.1", | ||
"node-opcua-debug": "^2.6.1", | ||
"node-opcua-enum": "^2.6.1", | ||
"node-opcua-extension-object": "^2.6.1", | ||
"node-opcua-factory": "^2.6.1", | ||
"node-opcua-nodeid": "^2.6.1", | ||
"node-opcua-utils": "^2.6.1", | ||
"node-opcua-variant": "^2.6.1", | ||
"node-opcua-xml2json": "^2.6.1", | ||
"thenify": "^3.3.0" | ||
}, | ||
"devDependencies": { | ||
"node-opcua-packet-analyzer": "^2.6.0-alpha.7" | ||
"node-opcua-packet-analyzer": "^2.6.1" | ||
}, | ||
@@ -45,3 +45,3 @@ "author": "Etienne Rossignon", | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "6af0c6f183dcb96ddc5a2befc98851d0960c5fd0" | ||
"gitHead": "15f0c0f83232fc63310dc04fea187048c7a01e4b" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
147728
2475
1
Updatednode-opcua-assert@^2.6.1
Updatednode-opcua-data-model@^2.6.1
Updatednode-opcua-debug@^2.6.1
Updatednode-opcua-enum@^2.6.1
Updatednode-opcua-factory@^2.6.1
Updatednode-opcua-nodeid@^2.6.1
Updatednode-opcua-utils@^2.6.1
Updatednode-opcua-variant@^2.6.1
Updatednode-opcua-xml2json@^2.6.1