node-opcua-factory 2.51.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 +20 -0
- package/dist/constructor_type.d.ts +15 -0
- package/dist/constructor_type.js +3 -0
- package/dist/constructor_type.js.map +1 -0
- package/dist/datatype_factory.d.ts +40 -0
- package/dist/datatype_factory.js +330 -0
- package/dist/datatype_factory.js.map +1 -0
- package/dist/factories_baseobject.d.ts +56 -0
- package/dist/factories_baseobject.js +498 -0
- package/dist/factories_baseobject.js.map +1 -0
- package/dist/factories_basic_type.d.ts +40 -0
- package/dist/factories_basic_type.js +136 -0
- package/dist/factories_basic_type.js.map +1 -0
- package/dist/factories_builtin_types.d.ts +32 -0
- package/dist/factories_builtin_types.js +262 -0
- package/dist/factories_builtin_types.js.map +1 -0
- package/dist/factories_builtin_types_special.d.ts +5 -0
- package/dist/factories_builtin_types_special.js +46 -0
- package/dist/factories_builtin_types_special.js.map +1 -0
- package/dist/factories_enumerations.d.ts +31 -0
- package/dist/factories_enumerations.js +77 -0
- package/dist/factories_enumerations.js.map +1 -0
- package/dist/factories_factories.d.ts +17 -0
- package/dist/factories_factories.js +54 -0
- package/dist/factories_factories.js.map +1 -0
- package/dist/factories_id_generator.d.ts +3 -0
- package/dist/factories_id_generator.js +22 -0
- package/dist/factories_id_generator.js.map +1 -0
- package/dist/factories_schema_helpers.d.ts +26 -0
- package/dist/factories_schema_helpers.js +121 -0
- package/dist/factories_schema_helpers.js.map +1 -0
- package/dist/factories_structuredTypeSchema.d.ts +46 -0
- package/dist/factories_structuredTypeSchema.js +269 -0
- package/dist/factories_structuredTypeSchema.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +111 -0
- package/dist/types.js +56 -0
- package/dist/types.js.map +1 -0
- package/package.json +41 -0
- package/source/constructor_type.ts +18 -0
- package/source/datatype_factory.ts +368 -0
- package/source/factories_baseobject.ts +567 -0
- package/source/factories_basic_type.ts +168 -0
- package/source/factories_builtin_types.ts +381 -0
- package/source/factories_builtin_types_special.ts +55 -0
- package/source/factories_enumerations.ts +97 -0
- package/source/factories_factories.ts +58 -0
- package/source/factories_id_generator.ts +18 -0
- package/source/factories_schema_helpers.ts +125 -0
- package/source/factories_structuredTypeSchema.ts +330 -0
- package/source/index.ts +15 -0
- package/source/types.ts +180 -0
package/source/types.ts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-factory
|
|
3
|
+
*/
|
|
4
|
+
import { assert } from "node-opcua-assert";
|
|
5
|
+
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";
|
|
9
|
+
|
|
10
|
+
// ------------------
|
|
11
|
+
// @brief CommonInterface
|
|
12
|
+
// BasicTypeDefinition
|
|
13
|
+
// StructuredType ( Schema)
|
|
14
|
+
// EnumerationDefinition
|
|
15
|
+
//
|
|
16
|
+
export interface CommonInterface {
|
|
17
|
+
name: string;
|
|
18
|
+
|
|
19
|
+
encode?: (value: any, stream: OutputBinaryStream) => void;
|
|
20
|
+
decode?: (stream: BinaryStream) => any;
|
|
21
|
+
|
|
22
|
+
coerce?: (value: any) => any;
|
|
23
|
+
toJSON?: (value: any) => any;
|
|
24
|
+
random?: () => any;
|
|
25
|
+
validate?: (value: any) => void;
|
|
26
|
+
|
|
27
|
+
defaultValue?: any;
|
|
28
|
+
|
|
29
|
+
computer_default_value(defaultValue: any): any;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export enum FieldCategory {
|
|
33
|
+
enumeration = "enumeration",
|
|
34
|
+
complex = "complex",
|
|
35
|
+
basic = "basic"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface StructuredTypeField {
|
|
39
|
+
name: string;
|
|
40
|
+
|
|
41
|
+
fieldType: string;
|
|
42
|
+
|
|
43
|
+
isArray?: boolean;
|
|
44
|
+
documentation?: string;
|
|
45
|
+
category: FieldCategory;
|
|
46
|
+
schema: CommonInterface;
|
|
47
|
+
|
|
48
|
+
fieldTypeConstructor?: ConstructorFunc;
|
|
49
|
+
subType?: string;
|
|
50
|
+
defaultValue?: any;
|
|
51
|
+
validate?: (value: any) => boolean;
|
|
52
|
+
decode?: (stream: BinaryStream) => any;
|
|
53
|
+
|
|
54
|
+
switchBit?: number; // the bit number
|
|
55
|
+
switchValue?: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// tslint:disable:no-empty-interface
|
|
59
|
+
export interface FieldEnumeration extends StructuredTypeField {
|
|
60
|
+
// xx category: FieldCategory.enumeration;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface FieldComplex extends StructuredTypeField {
|
|
64
|
+
// xx category: FieldCategory.complex;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface FieldBasic extends StructuredTypeField {
|
|
68
|
+
// xx category: FieldCategory.basic;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type FieldType = FieldEnumeration | FieldComplex | FieldBasic;
|
|
72
|
+
|
|
73
|
+
export type DefaultValueFunc = () => any;
|
|
74
|
+
|
|
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
|
+
export interface StructuredTypeOptions {
|
|
88
|
+
name: string;
|
|
89
|
+
id?: number | NodeId;
|
|
90
|
+
fields: FieldInterfaceOptions[];
|
|
91
|
+
documentation?: string;
|
|
92
|
+
baseType: string;
|
|
93
|
+
_resolved?: boolean;
|
|
94
|
+
bitFields?: any[];
|
|
95
|
+
base?: StructuredTypeOptions;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface TypeSchemaConstructorOptions {
|
|
99
|
+
name: string;
|
|
100
|
+
category?: FieldCategory;
|
|
101
|
+
defaultValue?: any;
|
|
102
|
+
encode?: (value: any, stream: OutputBinaryStream) => void;
|
|
103
|
+
decode?: (stream: BinaryStream) => any;
|
|
104
|
+
coerce?: (value: any) => any;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface BasicTypeDefinitionOptions extends TypeSchemaConstructorOptions {
|
|
108
|
+
subType: string;
|
|
109
|
+
toJSON?: (value: any) => any;
|
|
110
|
+
random?: () => any;
|
|
111
|
+
validate?: (value: any) => void;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface BasicTypeDefinition extends CommonInterface {
|
|
115
|
+
subType: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface BuiltInTypeDefinition extends BasicTypeDefinition {}
|
|
119
|
+
|
|
120
|
+
export interface EnumerationDefinition extends CommonInterface {
|
|
121
|
+
enumValues: any;
|
|
122
|
+
typedEnum: Enum;
|
|
123
|
+
documentation?: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export type TypeDefinition = BuiltInTypeDefinition | EnumerationDefinition | BasicTypeDefinition | TypeSchemaBase;
|
|
127
|
+
|
|
128
|
+
// tslint:disable-next-line:no-empty
|
|
129
|
+
function defaultEncode(value: any, stream: BinaryStream): void {}
|
|
130
|
+
|
|
131
|
+
// tslint:disable-next-line:no-empty
|
|
132
|
+
function defaultDecode(stream: BinaryStream): void {}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @class TypeSchemaBase
|
|
136
|
+
* @param options {Object}
|
|
137
|
+
* @constructor
|
|
138
|
+
* create a new type Schema
|
|
139
|
+
*/
|
|
140
|
+
export class TypeSchemaBase implements CommonInterface {
|
|
141
|
+
public name: string;
|
|
142
|
+
public defaultValue: any;
|
|
143
|
+
public encode?: (value: any, stream: OutputBinaryStream) => void;
|
|
144
|
+
public decode?: (stream: BinaryStream) => any;
|
|
145
|
+
public coerce?: (value: any) => any;
|
|
146
|
+
public toJSON?: () => string;
|
|
147
|
+
public category: FieldCategory;
|
|
148
|
+
|
|
149
|
+
constructor(options: TypeSchemaConstructorOptions) {
|
|
150
|
+
assert(options.category !== null);
|
|
151
|
+
this.encode = options.encode || undefined;
|
|
152
|
+
this.decode = options.decode || undefined;
|
|
153
|
+
this.coerce = options.coerce;
|
|
154
|
+
this.category = options.category || FieldCategory.basic;
|
|
155
|
+
this.name = options.name;
|
|
156
|
+
|
|
157
|
+
for (const prop in options) {
|
|
158
|
+
if (Object.prototype.hasOwnProperty.call(options,prop)) {
|
|
159
|
+
(this as any)[prop] = (options as any)[prop];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @method computer_default_value
|
|
166
|
+
* @param defaultValue {*} the default value
|
|
167
|
+
* @return {*}
|
|
168
|
+
*/
|
|
169
|
+
public computer_default_value(defaultValue: any): any {
|
|
170
|
+
if (defaultValue === undefined) {
|
|
171
|
+
defaultValue = this.defaultValue;
|
|
172
|
+
}
|
|
173
|
+
if (typeof defaultValue === "function") {
|
|
174
|
+
// be careful not to cache this value , it must be call each time to make sure
|
|
175
|
+
// we do not end up with the same value/instance twice.
|
|
176
|
+
defaultValue = defaultValue();
|
|
177
|
+
}
|
|
178
|
+
return defaultValue;
|
|
179
|
+
}
|
|
180
|
+
}
|