node-opcua-factory 2.72.1 → 2.74.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.
Files changed (75) hide show
  1. package/LICENSE +3 -1
  2. package/dist/base_ua_object.d.ts +53 -0
  3. package/dist/base_ua_object.js +536 -0
  4. package/dist/base_ua_object.js.map +1 -0
  5. package/dist/basic_type.d.ts +40 -0
  6. package/dist/basic_type.js +119 -0
  7. package/dist/basic_type.js.map +1 -0
  8. package/dist/builtin_types.d.ts +46 -0
  9. package/dist/builtin_types.js +284 -0
  10. package/dist/builtin_types.js.map +1 -0
  11. package/dist/builtin_types_special.d.ts +5 -0
  12. package/dist/builtin_types_special.js +46 -0
  13. package/dist/builtin_types_special.js.map +1 -0
  14. package/dist/datatype_factory.d.ts +8 -11
  15. package/dist/datatype_factory.js +25 -42
  16. package/dist/datatype_factory.js.map +1 -1
  17. package/dist/encode_decode.d.ts +9 -0
  18. package/dist/encode_decode.js +40 -0
  19. package/dist/encode_decode.js.map +1 -0
  20. package/dist/enumerations.d.ts +32 -0
  21. package/dist/enumerations.js +78 -0
  22. package/dist/enumerations.js.map +1 -0
  23. package/dist/get_built_in_type.d.ts +0 -0
  24. package/dist/get_built_in_type.js +2 -0
  25. package/dist/get_built_in_type.js.map +1 -0
  26. package/dist/get_standard_data_type_factory.d.ts +12 -0
  27. package/dist/get_standard_data_type_factory.js +35 -0
  28. package/dist/get_standard_data_type_factory.js.map +1 -0
  29. package/dist/get_structured_type_schema.d.ts +4 -0
  30. package/dist/get_structured_type_schema.js +13 -0
  31. package/dist/get_structured_type_schema.js.map +1 -0
  32. package/dist/id_generator.d.ts +3 -0
  33. package/dist/id_generator.js +22 -0
  34. package/dist/id_generator.js.map +1 -0
  35. package/dist/index.d.ts +13 -10
  36. package/dist/index.js +13 -10
  37. package/dist/index.js.map +1 -1
  38. package/dist/nodeid_type.d.ts +13 -0
  39. package/dist/nodeid_type.js +19 -0
  40. package/dist/nodeid_type.js.map +1 -0
  41. package/dist/parameters.d.ts +3 -0
  42. package/dist/parameters.js +7 -0
  43. package/dist/parameters.js.map +1 -0
  44. package/dist/register_class_definition.d.ts +3 -0
  45. package/dist/register_class_definition.js +9 -0
  46. package/dist/register_class_definition.js.map +1 -0
  47. package/dist/schema_helpers.d.ts +24 -0
  48. package/dist/schema_helpers.js +100 -0
  49. package/dist/schema_helpers.js.map +1 -0
  50. package/dist/structured_type_schema.d.ts +44 -0
  51. package/dist/structured_type_schema.js +279 -0
  52. package/dist/structured_type_schema.js.map +1 -0
  53. package/dist/types.d.ts +86 -45
  54. package/dist/types.js +1 -43
  55. package/dist/types.js.map +1 -1
  56. package/package.json +13 -12
  57. package/source/{factories_baseobject.ts → base_ua_object.ts} +48 -44
  58. package/source/{factories_basic_type.ts → basic_type.ts} +7 -28
  59. package/source/{factories_builtin_types.ts → builtin_types.ts} +111 -89
  60. package/source/{factories_builtin_types_special.ts → builtin_types_special.ts} +2 -2
  61. package/source/datatype_factory.ts +44 -47
  62. package/source/encode_decode.ts +37 -0
  63. package/source/{factories_enumerations.ts → enumerations.ts} +6 -4
  64. package/source/get_built_in_type.ts +0 -0
  65. package/source/{factories_factories.ts → get_standard_data_type_factory.ts} +7 -25
  66. package/source/get_structured_type_schema.ts +10 -0
  67. package/source/{factories_id_generator.ts → id_generator.ts} +0 -0
  68. package/source/index.ts +14 -11
  69. package/source/nodeid_type.ts +17 -0
  70. package/source/parameters.ts +3 -0
  71. package/source/register_class_definition.ts +11 -0
  72. package/source/{factories_schema_helpers.ts → schema_helpers.ts} +15 -37
  73. package/source/{factories_structuredTypeSchema.ts → structured_type_schema.ts} +37 -36
  74. package/source/types.ts +104 -79
  75. package/source/constructor_type.ts +0 -18
package/source/index.ts CHANGED
@@ -1,15 +1,18 @@
1
1
  /**
2
2
  * @module node-opcua-factory
3
3
  */
4
- export * from "./constructor_type";
4
+ export * from "./base_ua_object";
5
+ export * from "./basic_type";
6
+ export * from "./builtin_types_special";
7
+ export * from "./builtin_types";
5
8
  export * from "./datatype_factory";
6
- export * from "./factories_id_generator";
7
- export * from "./factories_enumerations";
8
- export * from "./factories_basic_type";
9
- export * from "./factories_builtin_types";
10
- export * from "./factories_builtin_types_special";
11
- export * from "./factories_baseobject";
12
- export * from "./types";
13
- export * from "./factories_schema_helpers";
14
- export * from "./factories_factories";
15
- export * from "./factories_structuredTypeSchema";
9
+ export * from "./enumerations";
10
+ export * from "./get_standard_data_type_factory";
11
+ export * from "./get_structured_type_schema";
12
+ export * from "./id_generator";
13
+ export * from "./nodeid_type";
14
+ export * from "./parameters";
15
+ export * from "./register_class_definition";
16
+ export * from "./schema_helpers";
17
+ export * from "./structured_type_schema";
18
+ export * from "./types";
@@ -0,0 +1,17 @@
1
+ import { registerEnumeration } from "./enumerations";
2
+
3
+
4
+
5
+ export enum NodeIdType {
6
+ ReferenceType = 0x01,
7
+ IsForward = 0x02,
8
+ NodeClass = 0x04,
9
+ BrowseName = 0x08,
10
+ DisplayName = 0x10,
11
+ TypeDefinition = 0x20
12
+ }
13
+ export const schemaNodeIdType = {
14
+ name: "NodeIdType",
15
+ enumValues: NodeIdType
16
+ };
17
+ export const _enumerationNodeIdType = registerEnumeration(schemaNodeIdType);
@@ -0,0 +1,3 @@
1
+ export const parameters = {
2
+ debugSchemaHelper: typeof process === "object" && !!process.env.DEBUG_CLASS
3
+ };
@@ -0,0 +1,11 @@
1
+ import { NodeId } from "node-opcua-nodeid";
2
+ import { getStandardDataTypeFactory } from "./get_standard_data_type_factory";
3
+ import { ConstructorFuncWithSchema } from "./types";
4
+
5
+ export function registerClassDefinition(
6
+ dataTypeNodeId: NodeId,
7
+ className: string,
8
+ classConstructor: ConstructorFuncWithSchema
9
+ ): void {
10
+ return getStandardDataTypeFactory().registerClassDefinition(dataTypeNodeId, className, classConstructor);
11
+ }
@@ -3,14 +3,13 @@
3
3
  */
4
4
  import { assert } from "node-opcua-assert";
5
5
  import { make_debugLog } from "node-opcua-debug";
6
- import { StructuredTypeSchema } from "./factories_structuredTypeSchema";
7
- import { CommonInterface, FieldCategory, FieldType, StructuredTypeField } from "./types";
6
+ import { DataTypeIds } from "node-opcua-constants";
7
+ import { DataTypeFactory } from "./datatype_factory";
8
+ import { BaseUAObject } from "./base_ua_object";
9
+ import { FieldCategory, FieldType, IStructuredTypeSchema, StructuredTypeField } from "./types";
8
10
 
9
11
  const debugLog = make_debugLog(__filename);
10
12
 
11
- export const parameters = {
12
- debugSchemaHelper: (typeof process === "object" && !!process.env.DEBUG_CLASS)
13
- };
14
13
 
15
14
  /**
16
15
  * ensure correctness of a schema object.
@@ -19,20 +18,27 @@ export const parameters = {
19
18
  * @param schema
20
19
  *
21
20
  */
22
- export function check_schema_correctness(schema: StructuredTypeSchema): void {
21
+ export function check_schema_correctness(schema: IStructuredTypeSchema): void {
23
22
  assert(typeof schema.name === "string", " expecting schema to have a name");
24
23
  assert(schema.fields instanceof Array, " expecting schema to provide a set of fields " + schema.name);
25
24
  assert(schema.baseType === undefined || typeof schema.baseType === "string");
26
25
  }
27
26
 
27
+
28
28
  /**
29
29
  * @method initialize_value
30
30
  * @param value
31
31
  * @param defaultValue
32
32
  * @return {*}
33
33
  */
34
- export function initialize_field(field: StructuredTypeField, value: unknown): any {
34
+ export function initialize_field(field: StructuredTypeField, value: unknown, factory?: DataTypeFactory): any {
35
35
  const _t = field.schema;
36
+
37
+ if (field.allowSubType && field.category === "complex") {
38
+ if (value instanceof BaseUAObject) {
39
+ value = { dataType: DataTypeIds.Structure, value };
40
+ }
41
+ }
36
42
  if (!(_t !== null && typeof _t === "object")) {
37
43
  throw new Error(
38
44
  "initialize_field: expecting field.schema to be set field.name = '" + field.name + "' type = " + field.fieldType
@@ -71,21 +77,6 @@ export function initialize_field(field: StructuredTypeField, value: unknown): an
71
77
  return value;
72
78
  }
73
79
 
74
- function initialize_value(value: any, defaultValue: any, _t: CommonInterface) {
75
- if (value === undefined) {
76
- return defaultValue;
77
- }
78
- if (defaultValue === null) {
79
- if (value === null) {
80
- return null;
81
- }
82
- }
83
- if (_t.coerce) {
84
- value = _t.coerce(value);
85
- return value;
86
- }
87
- return value;
88
- }
89
80
  /**
90
81
  * @method initialize_field_array
91
82
  * @param field
@@ -93,7 +84,7 @@ function initialize_value(value: any, defaultValue: any, _t: CommonInterface) {
93
84
  * @return
94
85
  */
95
86
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
96
- export function initialize_field_array(field: FieldType, valueArray: any): any {
87
+ export function initialize_field_array(field: FieldType, valueArray: any, factory?: DataTypeFactory): any {
97
88
  const _t = field.schema;
98
89
 
99
90
  let value;
@@ -104,24 +95,11 @@ export function initialize_field_array(field: FieldType, valueArray: any): any {
104
95
  if (!valueArray && field.defaultValue === null) {
105
96
  return null;
106
97
  }
107
-
108
98
  valueArray = valueArray || [];
109
-
110
- let defaultValue: any;
111
- if (_t.computer_default_value) {
112
- defaultValue = _t.computer_default_value(field.defaultValue);
113
- }
114
99
  const arr: unknown[] = [];
115
100
  for (i = 0; i < valueArray.length; i++) {
116
- value = initialize_value(valueArray[i], defaultValue, _t);
101
+ value = initialize_field(field, valueArray[i], factory);
117
102
  arr.push(value);
118
103
  }
119
- if (field.validate) {
120
- for (i = 0; i < arr.length; i++) {
121
- if (!field.validate(arr[i])) {
122
- throw Error(" invalid value " + arr[i] + " for field " + field.name + " of type " + field.fieldType);
123
- }
124
- }
125
- }
126
104
  return arr;
127
105
  }
@@ -8,13 +8,19 @@ import { BinaryStream } from "node-opcua-binary-stream";
8
8
  import { ExpandedNodeId, NodeId } from "node-opcua-nodeid";
9
9
  import { lowerFirstLetter } from "node-opcua-utils";
10
10
 
11
- import { getBuildInType, hasBuiltInType } from "./factories_builtin_types";
12
- import { getEnumeration, hasEnumeration } from "./factories_enumerations";
13
- import { getStructuredTypeSchema, getStructureTypeConstructor, hasStructuredType } from "./factories_factories";
14
- import { parameters } from "./factories_schema_helpers";
15
- import { DataTypeFactory } from "./datatype_factory";
16
- import { CommonInterface, FieldCategory, FieldInterfaceOptions, FieldType, StructuredTypeOptions, TypeSchemaBase } from "./types";
17
- import { BaseUAObject } from "./factories_baseobject";
11
+ import { getBuiltInType, hasBuiltInType, TypeSchemaBase } from "./builtin_types";
12
+ import { getBuiltInEnumeration, hasBuiltInEnumeration } from "./enumerations";
13
+ import { parameters } from "./parameters";
14
+ import { getStructureTypeConstructor, hasStructuredType } from "./get_standard_data_type_factory";
15
+ import { getStructuredTypeSchema } from "./get_structured_type_schema";
16
+ import {
17
+ CommonInterface,
18
+ FieldCategory,
19
+ FieldInterfaceOptions,
20
+ FieldType,
21
+ IStructuredTypeSchema,
22
+ StructuredTypeOptions
23
+ } from "./types";
18
24
 
19
25
  function figureOutFieldCategory(field: FieldInterfaceOptions): FieldCategory {
20
26
  const fieldType = field.fieldType;
@@ -23,7 +29,7 @@ function figureOutFieldCategory(field: FieldInterfaceOptions): FieldCategory {
23
29
  return field.category;
24
30
  }
25
31
 
26
- if (hasEnumeration(fieldType)) {
32
+ if (hasBuiltInEnumeration(fieldType)) {
27
33
  return FieldCategory.enumeration;
28
34
  } else if (hasBuiltInType(fieldType)) {
29
35
  return FieldCategory.basic;
@@ -65,12 +71,12 @@ function figureOutSchema(
65
71
  returnValue = getStructuredTypeSchema(fieldTypeWithoutNS);
66
72
  } else {
67
73
  // LocalizedText etc ...
68
- returnValue = getBuildInType(fieldTypeWithoutNS);
74
+ returnValue = getBuiltInType(fieldTypeWithoutNS);
69
75
  }
70
76
  break;
71
77
  case FieldCategory.basic:
72
- returnValue = getBuildInType(fieldTypeWithoutNS);
73
- if(!returnValue) {
78
+ returnValue = getBuiltInType(fieldTypeWithoutNS);
79
+ if (!returnValue) {
74
80
  returnValue = getStructuredTypeSchema(fieldTypeWithoutNS);
75
81
  if (returnValue) {
76
82
  console.log("Why ?");
@@ -78,14 +84,13 @@ function figureOutSchema(
78
84
  }
79
85
  break;
80
86
  case FieldCategory.enumeration:
81
- returnValue = getEnumeration(fieldTypeWithoutNS);
87
+ returnValue = getBuiltInEnumeration(fieldTypeWithoutNS);
82
88
  break;
83
89
  }
84
90
  if (null === returnValue || undefined === returnValue) {
85
91
  try {
86
- returnValue = getEnumeration(fieldTypeWithoutNS);
87
- }
88
- catch(err){
92
+ returnValue = getBuiltInEnumeration(fieldTypeWithoutNS);
93
+ } catch (err) {
89
94
  console.log(err);
90
95
  }
91
96
  throw new Error(
@@ -119,32 +124,32 @@ function buildField(underConstructSchema: StructuredTypeSchema, fieldLight: Fiel
119
124
  );
120
125
  }
121
126
 
127
+ const { defaultValue, isArray, documentation, fieldType, switchBit, switchValue, allowSubType, dataType, basicDataType } =
128
+ fieldLight;
122
129
  return {
123
130
  name: lowerFirstLetter(fieldLight.name),
124
-
131
+ originalName: fieldLight.name,
125
132
  category,
126
- defaultValue: fieldLight.defaultValue,
127
- isArray: fieldLight.isArray,
128
-
129
- documentation: fieldLight.documentation,
130
- fieldType: fieldLight.fieldType,
131
-
132
- switchBit: fieldLight.switchBit,
133
-
134
- switchValue: fieldLight.switchValue,
135
-
133
+ defaultValue,
134
+ isArray,
135
+ documentation,
136
+ fieldType,
137
+ switchBit,
138
+ switchValue,
139
+ allowSubType,
140
+ dataType,
141
+ basicDataType,
136
142
  schema
137
143
  };
138
144
  }
139
-
140
- export class StructuredTypeSchema extends TypeSchemaBase {
145
+ export class StructuredTypeSchema extends TypeSchemaBase implements IStructuredTypeSchema {
141
146
  public fields: FieldType[];
142
147
  public id: NodeId;
143
148
  public dataTypeNodeId: NodeId;
144
149
 
145
150
  public baseType: string;
146
151
  public _possibleFields: string[];
147
- public _baseSchema: StructuredTypeSchema | null;
152
+ public _baseSchema: IStructuredTypeSchema | null;
148
153
 
149
154
  public documentation?: string;
150
155
 
@@ -211,7 +216,7 @@ export class StructuredTypeSchema extends TypeSchemaBase {
211
216
  * @return {*}
212
217
  *
213
218
  */
214
- export function get_base_schema(schema: StructuredTypeSchema): StructuredTypeSchema | null {
219
+ export function get_base_schema(schema: IStructuredTypeSchema): IStructuredTypeSchema | null {
215
220
  let baseSchema = schema._baseSchema;
216
221
  if (baseSchema) {
217
222
  return baseSchema;
@@ -248,7 +253,7 @@ export function get_base_schema(schema: StructuredTypeSchema): StructuredTypeSch
248
253
  * (by walking up the inheritance chain)
249
254
  *
250
255
  */
251
- export function extract_all_fields(schema: StructuredTypeSchema): string[] {
256
+ export function extract_all_fields(schema: IStructuredTypeSchema): string[] {
252
257
  // returns cached result if any
253
258
  // istanbul ignore next
254
259
  if (schema._possibleFields) {
@@ -276,7 +281,7 @@ export function extract_all_fields(schema: StructuredTypeSchema): string[] {
276
281
  * @method check_options_correctness_against_schema
277
282
  *
278
283
  */
279
- export function check_options_correctness_against_schema(obj: any, schema: StructuredTypeSchema, options: any): boolean {
284
+ export function check_options_correctness_against_schema(obj: any, schema: IStructuredTypeSchema, options: any): boolean {
280
285
  if (!parameters.debugSchemaHelper) {
281
286
  return true; // ignoring set
282
287
  }
@@ -330,10 +335,6 @@ export function check_options_correctness_against_schema(obj: any, schema: Struc
330
335
  return true;
331
336
  }
332
337
 
333
- export function buildStructuredType2(dataTypeFactory: DataTypeFactory, schemaLight: StructuredTypeOptions): StructuredTypeSchema {
334
- return new StructuredTypeSchema(schemaLight);
335
- }
336
-
337
338
  export function buildStructuredType(schemaLight: StructuredTypeOptions): StructuredTypeSchema {
338
339
  return new StructuredTypeSchema(schemaLight);
339
340
  }
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
- }