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,122 +1,122 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initialize_field_array = exports.initialize_field = exports.check_schema_correctness = exports.parameters = 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 types_1 = require("./types");
|
|
10
|
-
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
11
|
-
exports.parameters = {
|
|
12
|
-
debugSchemaHelper: (typeof process === "object" && !!process.env.DEBUG_CLASS)
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* ensure correctness of a schema object.
|
|
16
|
-
*
|
|
17
|
-
* @method check_schema_correctness
|
|
18
|
-
* @param schema
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
function check_schema_correctness(schema) {
|
|
22
|
-
(0, node_opcua_assert_1.assert)(typeof schema.name === "string", " expecting schema to have a name");
|
|
23
|
-
(0, node_opcua_assert_1.assert)(schema.fields instanceof Array, " expecting schema to provide a set of fields " + schema.name);
|
|
24
|
-
(0, node_opcua_assert_1.assert)(schema.baseType === undefined || typeof schema.baseType === "string");
|
|
25
|
-
}
|
|
26
|
-
exports.check_schema_correctness = check_schema_correctness;
|
|
27
|
-
/**
|
|
28
|
-
* @method initialize_value
|
|
29
|
-
* @param value
|
|
30
|
-
* @param defaultValue
|
|
31
|
-
* @return {*}
|
|
32
|
-
*/
|
|
33
|
-
function initialize_field(field, value) {
|
|
34
|
-
const _t = field.schema;
|
|
35
|
-
if (!(_t !== null && typeof _t === "object")) {
|
|
36
|
-
throw new Error("initialize_field: expecting field.schema to be set field.name = '" + field.name + "' type = " + field.fieldType);
|
|
37
|
-
}
|
|
38
|
-
if (field.category === types_1.FieldCategory.complex) {
|
|
39
|
-
if (field.fieldTypeConstructor) {
|
|
40
|
-
return new field.fieldTypeConstructor(value);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
debugLog("xxxx => missing constructor for field type", field.fieldType);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (value === undefined || value === null) {
|
|
47
|
-
const defaultValue = _t.computer_default_value ? _t.computer_default_value(field.defaultValue) : field.defaultValue;
|
|
48
|
-
if (value === undefined) {
|
|
49
|
-
if (_t.coerce) {
|
|
50
|
-
return _t.coerce(defaultValue);
|
|
51
|
-
}
|
|
52
|
-
return defaultValue;
|
|
53
|
-
}
|
|
54
|
-
if (defaultValue === null) {
|
|
55
|
-
if (value === null) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (_t.coerce) {
|
|
61
|
-
value = _t.coerce(value);
|
|
62
|
-
}
|
|
63
|
-
if (field.validate) {
|
|
64
|
-
if (!field.validate(value)) {
|
|
65
|
-
throw Error(" invalid value " + value + " for field " + field.name + " of type " + field.fieldType);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return value;
|
|
69
|
-
}
|
|
70
|
-
exports.initialize_field = initialize_field;
|
|
71
|
-
function initialize_value(value, defaultValue, _t) {
|
|
72
|
-
if (value === undefined) {
|
|
73
|
-
return defaultValue;
|
|
74
|
-
}
|
|
75
|
-
if (defaultValue === null) {
|
|
76
|
-
if (value === null) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (_t.coerce) {
|
|
81
|
-
value = _t.coerce(value);
|
|
82
|
-
return value;
|
|
83
|
-
}
|
|
84
|
-
return value;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* @method initialize_field_array
|
|
88
|
-
* @param field
|
|
89
|
-
* @param valueArray
|
|
90
|
-
* @return
|
|
91
|
-
*/
|
|
92
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
93
|
-
function initialize_field_array(field, valueArray) {
|
|
94
|
-
const _t = field.schema;
|
|
95
|
-
let value;
|
|
96
|
-
let i;
|
|
97
|
-
(0, node_opcua_assert_1.assert)(field !== null && typeof field === "object");
|
|
98
|
-
(0, node_opcua_assert_1.assert)(field.isArray);
|
|
99
|
-
if (!valueArray && field.defaultValue === null) {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
valueArray = valueArray || [];
|
|
103
|
-
let defaultValue;
|
|
104
|
-
if (_t.computer_default_value) {
|
|
105
|
-
defaultValue = _t.computer_default_value(field.defaultValue);
|
|
106
|
-
}
|
|
107
|
-
const arr = [];
|
|
108
|
-
for (i = 0; i < valueArray.length; i++) {
|
|
109
|
-
value = initialize_value(valueArray[i], defaultValue, _t);
|
|
110
|
-
arr.push(value);
|
|
111
|
-
}
|
|
112
|
-
if (field.validate) {
|
|
113
|
-
for (i = 0; i < arr.length; i++) {
|
|
114
|
-
if (!field.validate(arr[i])) {
|
|
115
|
-
throw Error(" invalid value " + arr[i] + " for field " + field.name + " of type " + field.fieldType);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return arr;
|
|
120
|
-
}
|
|
121
|
-
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 = exports.parameters = 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 types_1 = require("./types");
|
|
10
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
11
|
+
exports.parameters = {
|
|
12
|
+
debugSchemaHelper: (typeof process === "object" && !!process.env.DEBUG_CLASS)
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* ensure correctness of a schema object.
|
|
16
|
+
*
|
|
17
|
+
* @method check_schema_correctness
|
|
18
|
+
* @param schema
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
function check_schema_correctness(schema) {
|
|
22
|
+
(0, node_opcua_assert_1.assert)(typeof schema.name === "string", " expecting schema to have a name");
|
|
23
|
+
(0, node_opcua_assert_1.assert)(schema.fields instanceof Array, " expecting schema to provide a set of fields " + schema.name);
|
|
24
|
+
(0, node_opcua_assert_1.assert)(schema.baseType === undefined || typeof schema.baseType === "string");
|
|
25
|
+
}
|
|
26
|
+
exports.check_schema_correctness = check_schema_correctness;
|
|
27
|
+
/**
|
|
28
|
+
* @method initialize_value
|
|
29
|
+
* @param value
|
|
30
|
+
* @param defaultValue
|
|
31
|
+
* @return {*}
|
|
32
|
+
*/
|
|
33
|
+
function initialize_field(field, value) {
|
|
34
|
+
const _t = field.schema;
|
|
35
|
+
if (!(_t !== null && typeof _t === "object")) {
|
|
36
|
+
throw new Error("initialize_field: expecting field.schema to be set field.name = '" + field.name + "' type = " + field.fieldType);
|
|
37
|
+
}
|
|
38
|
+
if (field.category === types_1.FieldCategory.complex) {
|
|
39
|
+
if (field.fieldTypeConstructor) {
|
|
40
|
+
return new field.fieldTypeConstructor(value);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
debugLog("xxxx => missing constructor for field type", field.fieldType);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (value === undefined || value === null) {
|
|
47
|
+
const defaultValue = _t.computer_default_value ? _t.computer_default_value(field.defaultValue) : field.defaultValue;
|
|
48
|
+
if (value === undefined) {
|
|
49
|
+
if (_t.coerce) {
|
|
50
|
+
return _t.coerce(defaultValue);
|
|
51
|
+
}
|
|
52
|
+
return defaultValue;
|
|
53
|
+
}
|
|
54
|
+
if (defaultValue === null) {
|
|
55
|
+
if (value === null) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (_t.coerce) {
|
|
61
|
+
value = _t.coerce(value);
|
|
62
|
+
}
|
|
63
|
+
if (field.validate) {
|
|
64
|
+
if (!field.validate(value)) {
|
|
65
|
+
throw Error(" invalid value " + value + " for field " + field.name + " of type " + field.fieldType);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
exports.initialize_field = initialize_field;
|
|
71
|
+
function initialize_value(value, defaultValue, _t) {
|
|
72
|
+
if (value === undefined) {
|
|
73
|
+
return defaultValue;
|
|
74
|
+
}
|
|
75
|
+
if (defaultValue === null) {
|
|
76
|
+
if (value === null) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (_t.coerce) {
|
|
81
|
+
value = _t.coerce(value);
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @method initialize_field_array
|
|
88
|
+
* @param field
|
|
89
|
+
* @param valueArray
|
|
90
|
+
* @return
|
|
91
|
+
*/
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
93
|
+
function initialize_field_array(field, valueArray) {
|
|
94
|
+
const _t = field.schema;
|
|
95
|
+
let value;
|
|
96
|
+
let i;
|
|
97
|
+
(0, node_opcua_assert_1.assert)(field !== null && typeof field === "object");
|
|
98
|
+
(0, node_opcua_assert_1.assert)(field.isArray);
|
|
99
|
+
if (!valueArray && field.defaultValue === null) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
valueArray = valueArray || [];
|
|
103
|
+
let defaultValue;
|
|
104
|
+
if (_t.computer_default_value) {
|
|
105
|
+
defaultValue = _t.computer_default_value(field.defaultValue);
|
|
106
|
+
}
|
|
107
|
+
const arr = [];
|
|
108
|
+
for (i = 0; i < valueArray.length; i++) {
|
|
109
|
+
value = initialize_value(valueArray[i], defaultValue, _t);
|
|
110
|
+
arr.push(value);
|
|
111
|
+
}
|
|
112
|
+
if (field.validate) {
|
|
113
|
+
for (i = 0; i < arr.length; i++) {
|
|
114
|
+
if (!field.validate(arr[i])) {
|
|
115
|
+
throw Error(" invalid value " + arr[i] + " for field " + field.name + " of type " + field.fieldType);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return arr;
|
|
120
|
+
}
|
|
121
|
+
exports.initialize_field_array = initialize_field_array;
|
|
122
122
|
//# sourceMappingURL=factories_schema_helpers.js.map
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { BinaryStream } from "node-opcua-binary-stream";
|
|
2
|
-
import { ExpandedNodeId, NodeId } from "node-opcua-nodeid";
|
|
3
|
-
import { DataTypeFactory } from "./datatype_factory";
|
|
4
|
-
import { FieldType, StructuredTypeOptions, TypeSchemaBase } from "./types";
|
|
5
|
-
export declare class StructuredTypeSchema extends TypeSchemaBase {
|
|
6
|
-
fields: FieldType[];
|
|
7
|
-
id: NodeId;
|
|
8
|
-
dataTypeNodeId: NodeId;
|
|
9
|
-
baseType: string;
|
|
10
|
-
_possibleFields: string[];
|
|
11
|
-
_baseSchema: StructuredTypeSchema | 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: StructuredTypeSchema): StructuredTypeSchema | 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: StructuredTypeSchema): 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: StructuredTypeSchema, options: any): boolean;
|
|
44
|
-
export declare function buildStructuredType2(dataTypeFactory: DataTypeFactory, schemaLight: StructuredTypeOptions): StructuredTypeSchema;
|
|
45
|
-
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 { DataTypeFactory } from "./datatype_factory";
|
|
4
|
+
import { FieldType, StructuredTypeOptions, TypeSchemaBase } from "./types";
|
|
5
|
+
export declare class StructuredTypeSchema extends TypeSchemaBase {
|
|
6
|
+
fields: FieldType[];
|
|
7
|
+
id: NodeId;
|
|
8
|
+
dataTypeNodeId: NodeId;
|
|
9
|
+
baseType: string;
|
|
10
|
+
_possibleFields: string[];
|
|
11
|
+
_baseSchema: StructuredTypeSchema | 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: StructuredTypeSchema): StructuredTypeSchema | 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: StructuredTypeSchema): 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: StructuredTypeSchema, options: any): boolean;
|
|
44
|
+
export declare function buildStructuredType2(dataTypeFactory: DataTypeFactory, schemaLight: StructuredTypeOptions): StructuredTypeSchema;
|
|
45
|
+
export declare function buildStructuredType(schemaLight: StructuredTypeOptions): StructuredTypeSchema;
|