node-opcua-factory 2.73.1 → 2.76.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.
- package/LICENSE +3 -1
- package/dist/base_ua_object.d.ts +53 -53
- package/dist/base_ua_object.js +535 -535
- package/dist/basic_type.d.ts +40 -40
- package/dist/basic_type.js +118 -118
- package/dist/builtin_types.d.ts +46 -46
- package/dist/builtin_types.js +283 -283
- package/dist/builtin_types_special.d.ts +5 -5
- package/dist/builtin_types_special.js +45 -45
- package/dist/datatype_factory.d.ts +36 -36
- package/dist/datatype_factory.js +307 -305
- package/dist/datatype_factory.js.map +1 -1
- package/dist/encode_decode.d.ts +9 -9
- package/dist/encode_decode.js +39 -39
- package/dist/enumerations.d.ts +32 -32
- package/dist/enumerations.js +77 -77
- package/dist/get_built_in_type.js +1 -1
- package/dist/get_standard_data_type_factory.d.ts +12 -12
- package/dist/get_standard_data_type_factory.js +34 -34
- package/dist/get_structured_type_schema.d.ts +4 -4
- package/dist/get_structured_type_schema.js +12 -12
- package/dist/id_generator.d.ts +3 -3
- package/dist/id_generator.js +21 -21
- package/dist/index.d.ts +18 -18
- package/dist/index.js +34 -34
- package/dist/nodeid_type.d.ts +13 -13
- package/dist/nodeid_type.js +18 -18
- package/dist/parameters.d.ts +3 -3
- package/dist/parameters.js +6 -6
- package/dist/register_class_definition.d.ts +3 -3
- package/dist/register_class_definition.js +8 -8
- package/dist/schema_helpers.d.ts +24 -24
- package/dist/schema_helpers.js +99 -99
- package/dist/structured_type_schema.d.ts +44 -44
- package/dist/structured_type_schema.js +278 -278
- package/dist/types.d.ts +151 -151
- package/dist/types.js +9 -9
- package/package.json +15 -12
- package/source/datatype_factory.ts +8 -5
- package/dist/constructor_type.d.ts +0 -15
- package/dist/constructor_type.js +0 -3
- package/dist/constructor_type.js.map +0 -1
- package/dist/factories_baseobject.d.ts +0 -56
- package/dist/factories_baseobject.js +0 -535
- package/dist/factories_baseobject.js.map +0 -1
- package/dist/factories_basic_type.d.ts +0 -40
- package/dist/factories_basic_type.js +0 -136
- package/dist/factories_basic_type.js.map +0 -1
- package/dist/factories_builtin_types.d.ts +0 -32
- package/dist/factories_builtin_types.js +0 -262
- package/dist/factories_builtin_types.js.map +0 -1
- package/dist/factories_builtin_types_special.d.ts +0 -5
- package/dist/factories_builtin_types_special.js +0 -46
- package/dist/factories_builtin_types_special.js.map +0 -1
- package/dist/factories_enumerations.d.ts +0 -31
- package/dist/factories_enumerations.js +0 -78
- package/dist/factories_enumerations.js.map +0 -1
- package/dist/factories_factories.d.ts +0 -17
- package/dist/factories_factories.js +0 -54
- package/dist/factories_factories.js.map +0 -1
- package/dist/factories_id_generator.d.ts +0 -3
- package/dist/factories_id_generator.js +0 -22
- package/dist/factories_id_generator.js.map +0 -1
- package/dist/factories_schema_helpers.d.ts +0 -27
- package/dist/factories_schema_helpers.js +0 -122
- package/dist/factories_schema_helpers.js.map +0 -1
- package/dist/factories_structuredTypeSchema.d.ts +0 -45
- package/dist/factories_structuredTypeSchema.js +0 -277
- package/dist/factories_structuredTypeSchema.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
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("./base_ua_object"), exports);
|
|
21
|
-
__exportStar(require("./basic_type"), exports);
|
|
22
|
-
__exportStar(require("./builtin_types_special"), exports);
|
|
23
|
-
__exportStar(require("./builtin_types"), exports);
|
|
24
|
-
__exportStar(require("./datatype_factory"), exports);
|
|
25
|
-
__exportStar(require("./enumerations"), exports);
|
|
26
|
-
__exportStar(require("./get_standard_data_type_factory"), exports);
|
|
27
|
-
__exportStar(require("./get_structured_type_schema"), exports);
|
|
28
|
-
__exportStar(require("./id_generator"), exports);
|
|
29
|
-
__exportStar(require("./nodeid_type"), exports);
|
|
30
|
-
__exportStar(require("./parameters"), exports);
|
|
31
|
-
__exportStar(require("./register_class_definition"), exports);
|
|
32
|
-
__exportStar(require("./schema_helpers"), exports);
|
|
33
|
-
__exportStar(require("./structured_type_schema"), exports);
|
|
34
|
-
__exportStar(require("./types"), 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("./base_ua_object"), exports);
|
|
21
|
+
__exportStar(require("./basic_type"), exports);
|
|
22
|
+
__exportStar(require("./builtin_types_special"), exports);
|
|
23
|
+
__exportStar(require("./builtin_types"), exports);
|
|
24
|
+
__exportStar(require("./datatype_factory"), exports);
|
|
25
|
+
__exportStar(require("./enumerations"), exports);
|
|
26
|
+
__exportStar(require("./get_standard_data_type_factory"), exports);
|
|
27
|
+
__exportStar(require("./get_structured_type_schema"), exports);
|
|
28
|
+
__exportStar(require("./id_generator"), exports);
|
|
29
|
+
__exportStar(require("./nodeid_type"), exports);
|
|
30
|
+
__exportStar(require("./parameters"), exports);
|
|
31
|
+
__exportStar(require("./register_class_definition"), exports);
|
|
32
|
+
__exportStar(require("./schema_helpers"), exports);
|
|
33
|
+
__exportStar(require("./structured_type_schema"), exports);
|
|
34
|
+
__exportStar(require("./types"), exports);
|
|
35
35
|
//# sourceMappingURL=index.js.map
|
package/dist/nodeid_type.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export declare enum NodeIdType {
|
|
2
|
-
ReferenceType = 1,
|
|
3
|
-
IsForward = 2,
|
|
4
|
-
NodeClass = 4,
|
|
5
|
-
BrowseName = 8,
|
|
6
|
-
DisplayName = 16,
|
|
7
|
-
TypeDefinition = 32
|
|
8
|
-
}
|
|
9
|
-
export declare const schemaNodeIdType: {
|
|
10
|
-
name: string;
|
|
11
|
-
enumValues: typeof NodeIdType;
|
|
12
|
-
};
|
|
13
|
-
export declare const _enumerationNodeIdType: import("node-opcua-enum").Enum;
|
|
1
|
+
export declare enum NodeIdType {
|
|
2
|
+
ReferenceType = 1,
|
|
3
|
+
IsForward = 2,
|
|
4
|
+
NodeClass = 4,
|
|
5
|
+
BrowseName = 8,
|
|
6
|
+
DisplayName = 16,
|
|
7
|
+
TypeDefinition = 32
|
|
8
|
+
}
|
|
9
|
+
export declare const schemaNodeIdType: {
|
|
10
|
+
name: string;
|
|
11
|
+
enumValues: typeof NodeIdType;
|
|
12
|
+
};
|
|
13
|
+
export declare const _enumerationNodeIdType: import("node-opcua-enum").Enum;
|
package/dist/nodeid_type.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._enumerationNodeIdType = exports.schemaNodeIdType = exports.NodeIdType = void 0;
|
|
4
|
-
const enumerations_1 = require("./enumerations");
|
|
5
|
-
var NodeIdType;
|
|
6
|
-
(function (NodeIdType) {
|
|
7
|
-
NodeIdType[NodeIdType["ReferenceType"] = 1] = "ReferenceType";
|
|
8
|
-
NodeIdType[NodeIdType["IsForward"] = 2] = "IsForward";
|
|
9
|
-
NodeIdType[NodeIdType["NodeClass"] = 4] = "NodeClass";
|
|
10
|
-
NodeIdType[NodeIdType["BrowseName"] = 8] = "BrowseName";
|
|
11
|
-
NodeIdType[NodeIdType["DisplayName"] = 16] = "DisplayName";
|
|
12
|
-
NodeIdType[NodeIdType["TypeDefinition"] = 32] = "TypeDefinition";
|
|
13
|
-
})(NodeIdType = exports.NodeIdType || (exports.NodeIdType = {}));
|
|
14
|
-
exports.schemaNodeIdType = {
|
|
15
|
-
name: "NodeIdType",
|
|
16
|
-
enumValues: NodeIdType
|
|
17
|
-
};
|
|
18
|
-
exports._enumerationNodeIdType = (0, enumerations_1.registerEnumeration)(exports.schemaNodeIdType);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._enumerationNodeIdType = exports.schemaNodeIdType = exports.NodeIdType = void 0;
|
|
4
|
+
const enumerations_1 = require("./enumerations");
|
|
5
|
+
var NodeIdType;
|
|
6
|
+
(function (NodeIdType) {
|
|
7
|
+
NodeIdType[NodeIdType["ReferenceType"] = 1] = "ReferenceType";
|
|
8
|
+
NodeIdType[NodeIdType["IsForward"] = 2] = "IsForward";
|
|
9
|
+
NodeIdType[NodeIdType["NodeClass"] = 4] = "NodeClass";
|
|
10
|
+
NodeIdType[NodeIdType["BrowseName"] = 8] = "BrowseName";
|
|
11
|
+
NodeIdType[NodeIdType["DisplayName"] = 16] = "DisplayName";
|
|
12
|
+
NodeIdType[NodeIdType["TypeDefinition"] = 32] = "TypeDefinition";
|
|
13
|
+
})(NodeIdType = exports.NodeIdType || (exports.NodeIdType = {}));
|
|
14
|
+
exports.schemaNodeIdType = {
|
|
15
|
+
name: "NodeIdType",
|
|
16
|
+
enumValues: NodeIdType
|
|
17
|
+
};
|
|
18
|
+
exports._enumerationNodeIdType = (0, enumerations_1.registerEnumeration)(exports.schemaNodeIdType);
|
|
19
19
|
//# sourceMappingURL=nodeid_type.js.map
|
package/dist/parameters.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const parameters: {
|
|
2
|
-
debugSchemaHelper: boolean;
|
|
3
|
-
};
|
|
1
|
+
export declare const parameters: {
|
|
2
|
+
debugSchemaHelper: boolean;
|
|
3
|
+
};
|
package/dist/parameters.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parameters = void 0;
|
|
4
|
-
exports.parameters = {
|
|
5
|
-
debugSchemaHelper: typeof process === "object" && !!process.env.DEBUG_CLASS
|
|
6
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parameters = void 0;
|
|
4
|
+
exports.parameters = {
|
|
5
|
+
debugSchemaHelper: typeof process === "object" && !!process.env.DEBUG_CLASS
|
|
6
|
+
};
|
|
7
7
|
//# sourceMappingURL=parameters.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { NodeId } from "node-opcua-nodeid";
|
|
2
|
-
import { ConstructorFuncWithSchema } from "./types";
|
|
3
|
-
export declare function registerClassDefinition(dataTypeNodeId: NodeId, className: string, classConstructor: ConstructorFuncWithSchema): void;
|
|
1
|
+
import { NodeId } from "node-opcua-nodeid";
|
|
2
|
+
import { ConstructorFuncWithSchema } from "./types";
|
|
3
|
+
export declare function registerClassDefinition(dataTypeNodeId: NodeId, className: string, classConstructor: ConstructorFuncWithSchema): void;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerClassDefinition = void 0;
|
|
4
|
-
const get_standard_data_type_factory_1 = require("./get_standard_data_type_factory");
|
|
5
|
-
function registerClassDefinition(dataTypeNodeId, className, classConstructor) {
|
|
6
|
-
return (0, get_standard_data_type_factory_1.getStandardDataTypeFactory)().registerClassDefinition(dataTypeNodeId, className, classConstructor);
|
|
7
|
-
}
|
|
8
|
-
exports.registerClassDefinition = registerClassDefinition;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerClassDefinition = void 0;
|
|
4
|
+
const get_standard_data_type_factory_1 = require("./get_standard_data_type_factory");
|
|
5
|
+
function registerClassDefinition(dataTypeNodeId, className, classConstructor) {
|
|
6
|
+
return (0, get_standard_data_type_factory_1.getStandardDataTypeFactory)().registerClassDefinition(dataTypeNodeId, className, classConstructor);
|
|
7
|
+
}
|
|
8
|
+
exports.registerClassDefinition = registerClassDefinition;
|
|
9
9
|
//# sourceMappingURL=register_class_definition.js.map
|
package/dist/schema_helpers.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { DataTypeFactory } from "./datatype_factory";
|
|
2
|
-
import { FieldType, IStructuredTypeSchema, StructuredTypeField } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* ensure correctness of a schema object.
|
|
5
|
-
*
|
|
6
|
-
* @method check_schema_correctness
|
|
7
|
-
* @param schema
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
export declare function check_schema_correctness(schema: IStructuredTypeSchema): void;
|
|
11
|
-
/**
|
|
12
|
-
* @method initialize_value
|
|
13
|
-
* @param value
|
|
14
|
-
* @param defaultValue
|
|
15
|
-
* @return {*}
|
|
16
|
-
*/
|
|
17
|
-
export declare function initialize_field(field: StructuredTypeField, value: unknown, factory?: DataTypeFactory): any;
|
|
18
|
-
/**
|
|
19
|
-
* @method initialize_field_array
|
|
20
|
-
* @param field
|
|
21
|
-
* @param valueArray
|
|
22
|
-
* @return
|
|
23
|
-
*/
|
|
24
|
-
export declare function initialize_field_array(field: FieldType, valueArray: any, factory?: DataTypeFactory): any;
|
|
1
|
+
import { DataTypeFactory } from "./datatype_factory";
|
|
2
|
+
import { FieldType, IStructuredTypeSchema, StructuredTypeField } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* ensure correctness of a schema object.
|
|
5
|
+
*
|
|
6
|
+
* @method check_schema_correctness
|
|
7
|
+
* @param schema
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
export declare function check_schema_correctness(schema: IStructuredTypeSchema): void;
|
|
11
|
+
/**
|
|
12
|
+
* @method initialize_value
|
|
13
|
+
* @param value
|
|
14
|
+
* @param defaultValue
|
|
15
|
+
* @return {*}
|
|
16
|
+
*/
|
|
17
|
+
export declare function initialize_field(field: StructuredTypeField, value: unknown, factory?: DataTypeFactory): any;
|
|
18
|
+
/**
|
|
19
|
+
* @method initialize_field_array
|
|
20
|
+
* @param field
|
|
21
|
+
* @param valueArray
|
|
22
|
+
* @return
|
|
23
|
+
*/
|
|
24
|
+
export declare function initialize_field_array(field: FieldType, valueArray: any, factory?: DataTypeFactory): any;
|
package/dist/schema_helpers.js
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initialize_field_array = exports.initialize_field = exports.check_schema_correctness = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @module node-opcua-factory
|
|
6
|
-
*/
|
|
7
|
-
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
8
|
-
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
9
|
-
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
10
|
-
const base_ua_object_1 = require("./base_ua_object");
|
|
11
|
-
const types_1 = require("./types");
|
|
12
|
-
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
13
|
-
/**
|
|
14
|
-
* ensure correctness of a schema object.
|
|
15
|
-
*
|
|
16
|
-
* @method check_schema_correctness
|
|
17
|
-
* @param schema
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
function check_schema_correctness(schema) {
|
|
21
|
-
(0, node_opcua_assert_1.assert)(typeof schema.name === "string", " expecting schema to have a name");
|
|
22
|
-
(0, node_opcua_assert_1.assert)(schema.fields instanceof Array, " expecting schema to provide a set of fields " + schema.name);
|
|
23
|
-
(0, node_opcua_assert_1.assert)(schema.baseType === undefined || typeof schema.baseType === "string");
|
|
24
|
-
}
|
|
25
|
-
exports.check_schema_correctness = check_schema_correctness;
|
|
26
|
-
/**
|
|
27
|
-
* @method initialize_value
|
|
28
|
-
* @param value
|
|
29
|
-
* @param defaultValue
|
|
30
|
-
* @return {*}
|
|
31
|
-
*/
|
|
32
|
-
function initialize_field(field, value, factory) {
|
|
33
|
-
const _t = field.schema;
|
|
34
|
-
if (field.allowSubType && field.category === "complex") {
|
|
35
|
-
if (value instanceof base_ua_object_1.BaseUAObject) {
|
|
36
|
-
value = { dataType: node_opcua_constants_1.DataTypeIds.Structure, value };
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (!(_t !== null && typeof _t === "object")) {
|
|
40
|
-
throw new Error("initialize_field: expecting field.schema to be set field.name = '" + field.name + "' type = " + field.fieldType);
|
|
41
|
-
}
|
|
42
|
-
if (field.category === types_1.FieldCategory.complex) {
|
|
43
|
-
if (field.fieldTypeConstructor) {
|
|
44
|
-
return new field.fieldTypeConstructor(value);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
debugLog("xxxx => missing constructor for field type", field.fieldType);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (value === undefined || value === null) {
|
|
51
|
-
const defaultValue = _t.computer_default_value ? _t.computer_default_value(field.defaultValue) : field.defaultValue;
|
|
52
|
-
if (value === undefined) {
|
|
53
|
-
if (_t.coerce) {
|
|
54
|
-
return _t.coerce(defaultValue);
|
|
55
|
-
}
|
|
56
|
-
return defaultValue;
|
|
57
|
-
}
|
|
58
|
-
if (defaultValue === null) {
|
|
59
|
-
if (value === null) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (_t.coerce) {
|
|
65
|
-
value = _t.coerce(value);
|
|
66
|
-
}
|
|
67
|
-
if (field.validate) {
|
|
68
|
-
if (!field.validate(value)) {
|
|
69
|
-
throw Error(" invalid value " + value + " for field " + field.name + " of type " + field.fieldType);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return value;
|
|
73
|
-
}
|
|
74
|
-
exports.initialize_field = initialize_field;
|
|
75
|
-
/**
|
|
76
|
-
* @method initialize_field_array
|
|
77
|
-
* @param field
|
|
78
|
-
* @param valueArray
|
|
79
|
-
* @return
|
|
80
|
-
*/
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
82
|
-
function initialize_field_array(field, valueArray, factory) {
|
|
83
|
-
const _t = field.schema;
|
|
84
|
-
let value;
|
|
85
|
-
let i;
|
|
86
|
-
(0, node_opcua_assert_1.assert)(field !== null && typeof field === "object");
|
|
87
|
-
(0, node_opcua_assert_1.assert)(field.isArray);
|
|
88
|
-
if (!valueArray && field.defaultValue === null) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
valueArray = valueArray || [];
|
|
92
|
-
const arr = [];
|
|
93
|
-
for (i = 0; i < valueArray.length; i++) {
|
|
94
|
-
value = initialize_field(field, valueArray[i], factory);
|
|
95
|
-
arr.push(value);
|
|
96
|
-
}
|
|
97
|
-
return arr;
|
|
98
|
-
}
|
|
99
|
-
exports.initialize_field_array = initialize_field_array;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initialize_field_array = exports.initialize_field = exports.check_schema_correctness = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-factory
|
|
6
|
+
*/
|
|
7
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
8
|
+
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
9
|
+
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
10
|
+
const base_ua_object_1 = require("./base_ua_object");
|
|
11
|
+
const types_1 = require("./types");
|
|
12
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
13
|
+
/**
|
|
14
|
+
* ensure correctness of a schema object.
|
|
15
|
+
*
|
|
16
|
+
* @method check_schema_correctness
|
|
17
|
+
* @param schema
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
function check_schema_correctness(schema) {
|
|
21
|
+
(0, node_opcua_assert_1.assert)(typeof schema.name === "string", " expecting schema to have a name");
|
|
22
|
+
(0, node_opcua_assert_1.assert)(schema.fields instanceof Array, " expecting schema to provide a set of fields " + schema.name);
|
|
23
|
+
(0, node_opcua_assert_1.assert)(schema.baseType === undefined || typeof schema.baseType === "string");
|
|
24
|
+
}
|
|
25
|
+
exports.check_schema_correctness = check_schema_correctness;
|
|
26
|
+
/**
|
|
27
|
+
* @method initialize_value
|
|
28
|
+
* @param value
|
|
29
|
+
* @param defaultValue
|
|
30
|
+
* @return {*}
|
|
31
|
+
*/
|
|
32
|
+
function initialize_field(field, value, factory) {
|
|
33
|
+
const _t = field.schema;
|
|
34
|
+
if (field.allowSubType && field.category === "complex") {
|
|
35
|
+
if (value instanceof base_ua_object_1.BaseUAObject) {
|
|
36
|
+
value = { dataType: node_opcua_constants_1.DataTypeIds.Structure, value };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!(_t !== null && typeof _t === "object")) {
|
|
40
|
+
throw new Error("initialize_field: expecting field.schema to be set field.name = '" + field.name + "' type = " + field.fieldType);
|
|
41
|
+
}
|
|
42
|
+
if (field.category === types_1.FieldCategory.complex) {
|
|
43
|
+
if (field.fieldTypeConstructor) {
|
|
44
|
+
return new field.fieldTypeConstructor(value);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
debugLog("xxxx => missing constructor for field type", field.fieldType);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (value === undefined || value === null) {
|
|
51
|
+
const defaultValue = _t.computer_default_value ? _t.computer_default_value(field.defaultValue) : field.defaultValue;
|
|
52
|
+
if (value === undefined) {
|
|
53
|
+
if (_t.coerce) {
|
|
54
|
+
return _t.coerce(defaultValue);
|
|
55
|
+
}
|
|
56
|
+
return defaultValue;
|
|
57
|
+
}
|
|
58
|
+
if (defaultValue === null) {
|
|
59
|
+
if (value === null) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (_t.coerce) {
|
|
65
|
+
value = _t.coerce(value);
|
|
66
|
+
}
|
|
67
|
+
if (field.validate) {
|
|
68
|
+
if (!field.validate(value)) {
|
|
69
|
+
throw Error(" invalid value " + value + " for field " + field.name + " of type " + field.fieldType);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
exports.initialize_field = initialize_field;
|
|
75
|
+
/**
|
|
76
|
+
* @method initialize_field_array
|
|
77
|
+
* @param field
|
|
78
|
+
* @param valueArray
|
|
79
|
+
* @return
|
|
80
|
+
*/
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
82
|
+
function initialize_field_array(field, valueArray, factory) {
|
|
83
|
+
const _t = field.schema;
|
|
84
|
+
let value;
|
|
85
|
+
let i;
|
|
86
|
+
(0, node_opcua_assert_1.assert)(field !== null && typeof field === "object");
|
|
87
|
+
(0, node_opcua_assert_1.assert)(field.isArray);
|
|
88
|
+
if (!valueArray && field.defaultValue === null) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
valueArray = valueArray || [];
|
|
92
|
+
const arr = [];
|
|
93
|
+
for (i = 0; i < valueArray.length; i++) {
|
|
94
|
+
value = initialize_field(field, valueArray[i], factory);
|
|
95
|
+
arr.push(value);
|
|
96
|
+
}
|
|
97
|
+
return arr;
|
|
98
|
+
}
|
|
99
|
+
exports.initialize_field_array = initialize_field_array;
|
|
100
100
|
//# sourceMappingURL=schema_helpers.js.map
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { BinaryStream } from "node-opcua-binary-stream";
|
|
2
|
-
import { ExpandedNodeId, NodeId } from "node-opcua-nodeid";
|
|
3
|
-
import { TypeSchemaBase } from "./builtin_types";
|
|
4
|
-
import { FieldType, IStructuredTypeSchema, StructuredTypeOptions } from "./types";
|
|
5
|
-
export declare class StructuredTypeSchema extends TypeSchemaBase implements IStructuredTypeSchema {
|
|
6
|
-
fields: FieldType[];
|
|
7
|
-
id: NodeId;
|
|
8
|
-
dataTypeNodeId: NodeId;
|
|
9
|
-
baseType: string;
|
|
10
|
-
_possibleFields: string[];
|
|
11
|
-
_baseSchema: IStructuredTypeSchema | null;
|
|
12
|
-
documentation?: string;
|
|
13
|
-
isValid?: (options: any) => boolean;
|
|
14
|
-
decodeDebug?: (stream: BinaryStream, options: any) => any;
|
|
15
|
-
constructHook?: (options: any) => any;
|
|
16
|
-
encodingDefaultBinary?: ExpandedNodeId;
|
|
17
|
-
encodingDefaultXml?: ExpandedNodeId;
|
|
18
|
-
encodingDefaultJson?: ExpandedNodeId;
|
|
19
|
-
bitFields?: any[];
|
|
20
|
-
constructor(options: StructuredTypeOptions);
|
|
21
|
-
toString(): string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
* @method get_base_schema
|
|
26
|
-
* @param schema
|
|
27
|
-
* @return {*}
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
export declare function get_base_schema(schema: IStructuredTypeSchema): IStructuredTypeSchema | null;
|
|
31
|
-
/**
|
|
32
|
-
* extract a list of all possible fields for a schema
|
|
33
|
-
* (by walking up the inheritance chain)
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
|
-
export declare function extract_all_fields(schema: IStructuredTypeSchema): string[];
|
|
37
|
-
/**
|
|
38
|
-
* check correctness of option fields against scheme
|
|
39
|
-
*
|
|
40
|
-
* @method check_options_correctness_against_schema
|
|
41
|
-
*
|
|
42
|
-
*/
|
|
43
|
-
export declare function check_options_correctness_against_schema(obj: any, schema: IStructuredTypeSchema, options: any): boolean;
|
|
44
|
-
export declare function buildStructuredType(schemaLight: StructuredTypeOptions): StructuredTypeSchema;
|
|
1
|
+
import { BinaryStream } from "node-opcua-binary-stream";
|
|
2
|
+
import { ExpandedNodeId, NodeId } from "node-opcua-nodeid";
|
|
3
|
+
import { TypeSchemaBase } from "./builtin_types";
|
|
4
|
+
import { FieldType, IStructuredTypeSchema, StructuredTypeOptions } from "./types";
|
|
5
|
+
export declare class StructuredTypeSchema extends TypeSchemaBase implements IStructuredTypeSchema {
|
|
6
|
+
fields: FieldType[];
|
|
7
|
+
id: NodeId;
|
|
8
|
+
dataTypeNodeId: NodeId;
|
|
9
|
+
baseType: string;
|
|
10
|
+
_possibleFields: string[];
|
|
11
|
+
_baseSchema: IStructuredTypeSchema | null;
|
|
12
|
+
documentation?: string;
|
|
13
|
+
isValid?: (options: any) => boolean;
|
|
14
|
+
decodeDebug?: (stream: BinaryStream, options: any) => any;
|
|
15
|
+
constructHook?: (options: any) => any;
|
|
16
|
+
encodingDefaultBinary?: ExpandedNodeId;
|
|
17
|
+
encodingDefaultXml?: ExpandedNodeId;
|
|
18
|
+
encodingDefaultJson?: ExpandedNodeId;
|
|
19
|
+
bitFields?: any[];
|
|
20
|
+
constructor(options: StructuredTypeOptions);
|
|
21
|
+
toString(): string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @method get_base_schema
|
|
26
|
+
* @param schema
|
|
27
|
+
* @return {*}
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
export declare function get_base_schema(schema: IStructuredTypeSchema): IStructuredTypeSchema | null;
|
|
31
|
+
/**
|
|
32
|
+
* extract a list of all possible fields for a schema
|
|
33
|
+
* (by walking up the inheritance chain)
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
export declare function extract_all_fields(schema: IStructuredTypeSchema): string[];
|
|
37
|
+
/**
|
|
38
|
+
* check correctness of option fields against scheme
|
|
39
|
+
*
|
|
40
|
+
* @method check_options_correctness_against_schema
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
export declare function check_options_correctness_against_schema(obj: any, schema: IStructuredTypeSchema, options: any): boolean;
|
|
44
|
+
export declare function buildStructuredType(schemaLight: StructuredTypeOptions): StructuredTypeSchema;
|