node-opcua-factory 2.71.0 → 2.73.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.
Files changed (94) hide show
  1. package/dist/base_ua_object.d.ts +53 -0
  2. package/dist/base_ua_object.js +536 -0
  3. package/dist/base_ua_object.js.map +1 -0
  4. package/dist/basic_type.d.ts +40 -0
  5. package/dist/basic_type.js +119 -0
  6. package/dist/basic_type.js.map +1 -0
  7. package/dist/builtin_types.d.ts +46 -0
  8. package/dist/builtin_types.js +284 -0
  9. package/dist/builtin_types.js.map +1 -0
  10. package/dist/builtin_types_special.d.ts +5 -0
  11. package/dist/builtin_types_special.js +46 -0
  12. package/dist/builtin_types_special.js.map +1 -0
  13. package/dist/constructor_type.d.ts +15 -15
  14. package/dist/constructor_type.js +2 -2
  15. package/dist/datatype_factory.d.ts +36 -39
  16. package/dist/datatype_factory.js +305 -322
  17. package/dist/datatype_factory.js.map +1 -1
  18. package/dist/encode_decode.d.ts +9 -0
  19. package/dist/encode_decode.js +40 -0
  20. package/dist/encode_decode.js.map +1 -0
  21. package/dist/enumerations.d.ts +32 -0
  22. package/dist/enumerations.js +78 -0
  23. package/dist/enumerations.js.map +1 -0
  24. package/dist/factories_baseobject.d.ts +56 -56
  25. package/dist/factories_baseobject.js +534 -534
  26. package/dist/factories_basic_type.d.ts +40 -40
  27. package/dist/factories_basic_type.js +135 -135
  28. package/dist/factories_builtin_types.d.ts +32 -32
  29. package/dist/factories_builtin_types.js +261 -261
  30. package/dist/factories_builtin_types_special.d.ts +5 -5
  31. package/dist/factories_builtin_types_special.js +45 -45
  32. package/dist/factories_enumerations.d.ts +31 -31
  33. package/dist/factories_enumerations.js +77 -77
  34. package/dist/factories_factories.d.ts +17 -17
  35. package/dist/factories_factories.js +53 -53
  36. package/dist/factories_id_generator.d.ts +3 -3
  37. package/dist/factories_id_generator.js +21 -21
  38. package/dist/factories_schema_helpers.d.ts +27 -27
  39. package/dist/factories_schema_helpers.js +121 -121
  40. package/dist/factories_structuredTypeSchema.d.ts +45 -45
  41. package/dist/factories_structuredTypeSchema.js +276 -276
  42. package/dist/get_built_in_type.d.ts +0 -0
  43. package/dist/get_built_in_type.js +2 -0
  44. package/dist/get_built_in_type.js.map +1 -0
  45. package/dist/get_standard_data_type_factory.d.ts +12 -0
  46. package/dist/get_standard_data_type_factory.js +35 -0
  47. package/dist/get_standard_data_type_factory.js.map +1 -0
  48. package/dist/get_structured_type_schema.d.ts +4 -0
  49. package/dist/get_structured_type_schema.js +13 -0
  50. package/dist/get_structured_type_schema.js.map +1 -0
  51. package/dist/id_generator.d.ts +3 -0
  52. package/dist/id_generator.js +22 -0
  53. package/dist/id_generator.js.map +1 -0
  54. package/dist/index.d.ts +18 -15
  55. package/dist/index.js +34 -31
  56. package/dist/index.js.map +1 -1
  57. package/dist/nodeid_type.d.ts +13 -0
  58. package/dist/nodeid_type.js +19 -0
  59. package/dist/nodeid_type.js.map +1 -0
  60. package/dist/parameters.d.ts +3 -0
  61. package/dist/parameters.js +7 -0
  62. package/dist/parameters.js.map +1 -0
  63. package/dist/register_class_definition.d.ts +3 -0
  64. package/dist/register_class_definition.js +9 -0
  65. package/dist/register_class_definition.js.map +1 -0
  66. package/dist/schema_helpers.d.ts +24 -0
  67. package/dist/schema_helpers.js +100 -0
  68. package/dist/schema_helpers.js.map +1 -0
  69. package/dist/structured_type_schema.d.ts +44 -0
  70. package/dist/structured_type_schema.js +279 -0
  71. package/dist/structured_type_schema.js.map +1 -0
  72. package/dist/types.d.ts +151 -110
  73. package/dist/types.js +9 -51
  74. package/dist/types.js.map +1 -1
  75. package/package.json +7 -6
  76. package/source/{factories_baseobject.ts → base_ua_object.ts} +48 -44
  77. package/source/{factories_basic_type.ts → basic_type.ts} +7 -28
  78. package/source/{factories_builtin_types.ts → builtin_types.ts} +111 -89
  79. package/source/{factories_builtin_types_special.ts → builtin_types_special.ts} +2 -2
  80. package/source/datatype_factory.ts +44 -47
  81. package/source/encode_decode.ts +37 -0
  82. package/source/{factories_enumerations.ts → enumerations.ts} +6 -4
  83. package/source/get_built_in_type.ts +0 -0
  84. package/source/{factories_factories.ts → get_standard_data_type_factory.ts} +7 -25
  85. package/source/get_structured_type_schema.ts +10 -0
  86. package/source/{factories_id_generator.ts → id_generator.ts} +0 -0
  87. package/source/index.ts +14 -11
  88. package/source/nodeid_type.ts +17 -0
  89. package/source/parameters.ts +3 -0
  90. package/source/register_class_definition.ts +11 -0
  91. package/source/{factories_schema_helpers.ts → schema_helpers.ts} +15 -37
  92. package/source/{factories_structuredTypeSchema.ts → structured_type_schema.ts} +37 -36
  93. package/source/types.ts +104 -79
  94. package/source/constructor_type.ts +0 -18
package/source/types.ts CHANGED
@@ -1,11 +1,15 @@
1
1
  /**
2
2
  * @module node-opcua-factory
3
3
  */
4
- import { assert } from "node-opcua-assert";
5
4
  import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
6
- import { Enum, EnumItem } from "node-opcua-enum";
7
- import { NodeId } from "node-opcua-nodeid";
8
- import { ConstructorFunc } from "./constructor_type";
5
+ import { Enum } from "node-opcua-enum";
6
+ import { ExpandedNodeId, NodeId } from "node-opcua-nodeid";
7
+
8
+ export enum FieldCategory {
9
+ enumeration = "enumeration",
10
+ complex = "complex",
11
+ basic = "basic"
12
+ }
9
13
 
10
14
  // ------------------
11
15
  // @brief CommonInterface
@@ -15,44 +19,93 @@ import { ConstructorFunc } from "./constructor_type";
15
19
  //
16
20
  export interface CommonInterface {
17
21
  name: string;
22
+ defaultValue?: any;
18
23
 
19
24
  encode?: (value: any, stream: OutputBinaryStream) => void;
20
25
  decode?: (stream: BinaryStream) => any;
21
-
22
26
  coerce?: (value: any) => any;
27
+
23
28
  toJSON?: (value: any) => any;
29
+ category: FieldCategory;
30
+
24
31
  random?: () => any;
25
32
  validate?: (value: any) => void;
33
+ computer_default_value(defaultValue: any): any;
34
+ subType: string;
35
+ isAbstract: boolean;
26
36
 
27
- defaultValue?: any;
37
+ isSubTypeOf(type: CommonInterface): boolean;
38
+ }
28
39
 
29
- computer_default_value(defaultValue: any): any;
40
+ export interface FieldInterfaceOptions {
41
+ name: string;
42
+ defaultValue?: any | DefaultValueFunc;
43
+
44
+ fieldType: string;
45
+ isArray?: boolean;
46
+ documentation?: string;
47
+ category?: FieldCategory;
48
+ schema?: CommonInterface;
49
+ switchBit?: number; // the bit number
50
+ switchValue?: number;
51
+ allowSubType?: boolean;
52
+ dataType?: NodeId;
53
+ basicDataType?: number;
30
54
  }
31
55
 
32
- export enum FieldCategory {
33
- enumeration = "enumeration",
34
- complex = "complex",
35
- basic = "basic"
56
+ export type Func1<T> = (value: any, field: StructuredTypeField, data: T, args?: any) => void;
57
+ export interface DecodeDebugOptions {
58
+ tracer: any;
59
+ name: string;
60
+ }
61
+
62
+ export interface IBaseUAObject {
63
+ schema: IStructuredTypeSchema;
64
+ encode(stream: OutputBinaryStream): void;
65
+ decode(stream: BinaryStream): void;
66
+ binaryStoreSize(): number;
67
+ toString(...args: any[]): string;
68
+ isValid(): boolean;
69
+ explore(): string;
70
+ applyOnAllFields<T>(func: Func1<T>, data: T): void;
71
+ toJSON(): any;
72
+ decodeDebug(stream: BinaryStream, options: DecodeDebugOptions): void;
73
+ clone(): IBaseUAObject;
74
+ }
75
+ type BaseUAObjectConstructable = new (options?: any) => IBaseUAObject;
76
+ export type ConstructorFunc = BaseUAObjectConstructable;
77
+ // new (...args: any[]) => BaseUAObjectConstructable;
78
+
79
+ export interface ConstructorFuncWithSchema extends ConstructorFunc {
80
+ schema: IStructuredTypeSchema;
81
+ possibleFields: string[];
82
+ encodingDefaultBinary: ExpandedNodeId;
83
+ encodingDefaultXml: ExpandedNodeId;
84
+ encodingDefaultJson?: ExpandedNodeId;
36
85
  }
37
86
 
38
87
  export interface StructuredTypeField {
39
- name: string;
88
+
89
+ name: string; // the name that may have been lowercased
90
+ originalName: string; // the orignal name from the raw OPCUA description
40
91
 
41
92
  fieldType: string;
42
-
43
93
  isArray?: boolean;
44
94
  documentation?: string;
45
95
  category: FieldCategory;
96
+ defaultValue?: any | DefaultValueFunc;
46
97
  schema: CommonInterface;
98
+ switchBit?: number; // the bit number
99
+ switchValue?: number;
100
+ allowSubType?: boolean;
101
+ dataType?: NodeId;
102
+ basicDataType?: number; // DataType
47
103
 
48
104
  fieldTypeConstructor?: ConstructorFunc;
105
+
49
106
  subType?: string;
50
- defaultValue?: any;
51
107
  validate?: (value: any) => boolean;
52
108
  decode?: (stream: BinaryStream) => any;
53
-
54
- switchBit?: number; // the bit number
55
- switchValue?: number;
56
109
  }
57
110
 
58
111
  // tslint:disable:no-empty-interface
@@ -72,18 +125,6 @@ export type FieldType = FieldEnumeration | FieldComplex | FieldBasic;
72
125
 
73
126
  export type DefaultValueFunc = () => any;
74
127
 
75
- export interface FieldInterfaceOptions {
76
- name: string;
77
- fieldType: string;
78
- isArray?: boolean;
79
- documentation?: string;
80
- category?: FieldCategory;
81
- defaultValue?: any | DefaultValueFunc;
82
- schema?: any;
83
- switchBit?: number; // the bit number
84
- switchValue?: number;
85
- }
86
-
87
128
  export interface StructuredTypeOptions {
88
129
  name: string;
89
130
  id?: number | NodeId;
@@ -97,6 +138,8 @@ export interface StructuredTypeOptions {
97
138
 
98
139
  export interface TypeSchemaConstructorOptions {
99
140
  name: string;
141
+ subType?: string;
142
+ isAbstract?: boolean;
100
143
  category?: FieldCategory;
101
144
  defaultValue?: any;
102
145
  encode?: (value: any, stream: OutputBinaryStream) => void;
@@ -104,13 +147,20 @@ export interface TypeSchemaConstructorOptions {
104
147
  coerce?: (value: any) => any;
105
148
  }
106
149
 
107
- export interface BasicTypeDefinitionOptions extends TypeSchemaConstructorOptions {
108
- subType: string;
150
+ export interface BasicTypeDefinitionOptionsB extends TypeSchemaConstructorOptions {
109
151
  toJSON?: (value: any) => any;
110
152
  random?: () => any;
111
153
  validate?: (value: any) => void;
112
154
  }
113
155
 
156
+ export interface BasicTypeDefinitionOptionsBase extends BasicTypeDefinitionOptionsB {
157
+ /** */
158
+ }
159
+
160
+ export interface BasicTypeDefinitionOptions extends BasicTypeDefinitionOptionsB {
161
+ subType: string;
162
+ }
163
+
114
164
  export interface BasicTypeDefinition extends CommonInterface {
115
165
  subType: string;
116
166
  }
@@ -118,57 +168,32 @@ export interface BasicTypeDefinition extends CommonInterface {
118
168
  export interface BuiltInTypeDefinition extends BasicTypeDefinition {}
119
169
 
120
170
  export interface EnumerationDefinition extends CommonInterface {
121
- // enumValues: any;
171
+ // enumValues: any;
122
172
  typedEnum: Enum;
123
173
  documentation?: string;
124
174
  }
125
175
 
126
- export type TypeDefinition = BuiltInTypeDefinition | EnumerationDefinition | BasicTypeDefinition | TypeSchemaBase;
176
+ export type TypeDefinition = BuiltInTypeDefinition | EnumerationDefinition | BasicTypeDefinition | CommonInterface;
127
177
 
128
- /**
129
- * @class TypeSchemaBase
130
- * @param options {Object}
131
- * @constructor
132
- * create a new type Schema
133
- */
134
- export class TypeSchemaBase implements CommonInterface {
135
- public name: string;
136
- public defaultValue: any;
137
- public encode?: (value: any, stream: OutputBinaryStream) => void;
138
- public decode?: (stream: BinaryStream) => any;
139
- public coerce?: (value: any) => any;
140
- public toJSON?: () => string;
141
- public category: FieldCategory;
142
-
143
- constructor(options: TypeSchemaConstructorOptions) {
144
- assert(options.category !== null);
145
- this.encode = options.encode || undefined;
146
- this.decode = options.decode || undefined;
147
- this.coerce = options.coerce;
148
- this.category = options.category || FieldCategory.basic;
149
- this.name = options.name;
150
-
151
- for (const prop in options) {
152
- if (Object.prototype.hasOwnProperty.call(options, prop)) {
153
- (this as any)[prop] = (options as any)[prop];
154
- }
155
- }
156
- }
157
-
158
- /**
159
- * @method computer_default_value
160
- * @param defaultValue {*} the default value
161
- * @return {*}
162
- */
163
- public computer_default_value(defaultValue: unknown): any {
164
- if (defaultValue === undefined) {
165
- defaultValue = this.defaultValue;
166
- }
167
- if (typeof defaultValue === "function") {
168
- // be careful not to cache this value , it must be call each time to make sure
169
- // we do not end up with the same value/instance twice.
170
- defaultValue = defaultValue();
171
- }
172
- return defaultValue;
173
- }
178
+ export interface IStructuredTypeSchema extends CommonInterface {
179
+ fields: FieldType[];
180
+ id: NodeId;
181
+ dataTypeNodeId: NodeId;
182
+
183
+ baseType: string;
184
+ _possibleFields: string[];
185
+ _baseSchema: IStructuredTypeSchema | null;
186
+
187
+ documentation?: string;
188
+
189
+ isValid?: (options: any) => boolean;
190
+
191
+ decodeDebug?: (stream: BinaryStream, options: any) => any;
192
+ constructHook?: (options: any) => any;
193
+
194
+ encodingDefaultBinary?: ExpandedNodeId;
195
+ encodingDefaultXml?: ExpandedNodeId;
196
+ encodingDefaultJson?: ExpandedNodeId;
197
+
198
+ bitFields?: any[];
174
199
  }
@@ -1,18 +0,0 @@
1
- /**
2
- * @module node-opcua-factory
3
- */
4
- import { ExpandedNodeId } from "node-opcua-nodeid";
5
-
6
- import { BaseUAObject } from "./factories_baseobject";
7
- import { StructuredTypeSchema } from "./factories_structuredTypeSchema";
8
-
9
- type BaseUAObjectConstructable = new (options?: any) => BaseUAObject;
10
- export type ConstructorFunc = BaseUAObjectConstructable;
11
- // new (...args: any[]) => BaseUAObjectConstructable;
12
-
13
- export interface ConstructorFuncWithSchema extends ConstructorFunc {
14
- schema: StructuredTypeSchema;
15
- possibleFields: string[];
16
- encodingDefaultBinary: ExpandedNodeId;
17
- encodingDefaultXml: ExpandedNodeId;
18
- }