node-opcua-factory 2.64.1 → 2.68.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 (33) hide show
  1. package/dist/constructor_type.d.ts +15 -15
  2. package/dist/constructor_type.js +2 -2
  3. package/dist/datatype_factory.d.ts +39 -39
  4. package/dist/datatype_factory.js +322 -322
  5. package/dist/factories_baseobject.d.ts +56 -56
  6. package/dist/factories_baseobject.js +534 -512
  7. package/dist/factories_baseobject.js.map +1 -1
  8. package/dist/factories_basic_type.d.ts +40 -40
  9. package/dist/factories_basic_type.js +135 -135
  10. package/dist/factories_builtin_types.d.ts +32 -32
  11. package/dist/factories_builtin_types.js +261 -261
  12. package/dist/factories_builtin_types_special.d.ts +5 -5
  13. package/dist/factories_builtin_types_special.js +45 -45
  14. package/dist/factories_enumerations.d.ts +31 -31
  15. package/dist/factories_enumerations.js +77 -76
  16. package/dist/factories_enumerations.js.map +1 -1
  17. package/dist/factories_factories.d.ts +17 -17
  18. package/dist/factories_factories.js +53 -53
  19. package/dist/factories_id_generator.d.ts +3 -3
  20. package/dist/factories_id_generator.js +21 -21
  21. package/dist/factories_schema_helpers.d.ts +27 -27
  22. package/dist/factories_schema_helpers.js +121 -121
  23. package/dist/factories_structuredTypeSchema.d.ts +45 -45
  24. package/dist/factories_structuredTypeSchema.js +265 -265
  25. package/dist/index.d.ts +15 -15
  26. package/dist/index.js +31 -27
  27. package/dist/index.js.map +1 -1
  28. package/dist/types.d.ts +110 -111
  29. package/dist/types.js +51 -51
  30. package/package.json +12 -12
  31. package/source/factories_baseobject.ts +51 -24
  32. package/source/factories_enumerations.ts +7 -4
  33. package/source/types.ts +1 -1
package/dist/types.d.ts CHANGED
@@ -1,111 +1,110 @@
1
- import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
2
- import { Enum } from "node-opcua-enum";
3
- import { NodeId } from "node-opcua-nodeid";
4
- import { ConstructorFunc } from "./constructor_type";
5
- export interface CommonInterface {
6
- name: string;
7
- encode?: (value: any, stream: OutputBinaryStream) => void;
8
- decode?: (stream: BinaryStream) => any;
9
- coerce?: (value: any) => any;
10
- toJSON?: (value: any) => any;
11
- random?: () => any;
12
- validate?: (value: any) => void;
13
- defaultValue?: any;
14
- computer_default_value(defaultValue: any): any;
15
- }
16
- export declare enum FieldCategory {
17
- enumeration = "enumeration",
18
- complex = "complex",
19
- basic = "basic"
20
- }
21
- export interface StructuredTypeField {
22
- name: string;
23
- fieldType: string;
24
- isArray?: boolean;
25
- documentation?: string;
26
- category: FieldCategory;
27
- schema: CommonInterface;
28
- fieldTypeConstructor?: ConstructorFunc;
29
- subType?: string;
30
- defaultValue?: any;
31
- validate?: (value: any) => boolean;
32
- decode?: (stream: BinaryStream) => any;
33
- switchBit?: number;
34
- switchValue?: number;
35
- }
36
- export interface FieldEnumeration extends StructuredTypeField {
37
- }
38
- export interface FieldComplex extends StructuredTypeField {
39
- }
40
- export interface FieldBasic extends StructuredTypeField {
41
- }
42
- export declare type FieldType = FieldEnumeration | FieldComplex | FieldBasic;
43
- export declare type DefaultValueFunc = () => any;
44
- export interface FieldInterfaceOptions {
45
- name: string;
46
- fieldType: string;
47
- isArray?: boolean;
48
- documentation?: string;
49
- category?: FieldCategory;
50
- defaultValue?: any | DefaultValueFunc;
51
- schema?: any;
52
- switchBit?: number;
53
- switchValue?: number;
54
- }
55
- export interface StructuredTypeOptions {
56
- name: string;
57
- id?: number | NodeId;
58
- fields: FieldInterfaceOptions[];
59
- documentation?: string;
60
- baseType: string;
61
- _resolved?: boolean;
62
- bitFields?: any[];
63
- base?: StructuredTypeOptions;
64
- }
65
- export interface TypeSchemaConstructorOptions {
66
- name: string;
67
- category?: FieldCategory;
68
- defaultValue?: any;
69
- encode?: (value: any, stream: OutputBinaryStream) => void;
70
- decode?: (stream: BinaryStream) => any;
71
- coerce?: (value: any) => any;
72
- }
73
- export interface BasicTypeDefinitionOptions extends TypeSchemaConstructorOptions {
74
- subType: string;
75
- toJSON?: (value: any) => any;
76
- random?: () => any;
77
- validate?: (value: any) => void;
78
- }
79
- export interface BasicTypeDefinition extends CommonInterface {
80
- subType: string;
81
- }
82
- export interface BuiltInTypeDefinition extends BasicTypeDefinition {
83
- }
84
- export interface EnumerationDefinition extends CommonInterface {
85
- enumValues: any;
86
- typedEnum: Enum;
87
- documentation?: string;
88
- }
89
- export declare type TypeDefinition = BuiltInTypeDefinition | EnumerationDefinition | BasicTypeDefinition | TypeSchemaBase;
90
- /**
91
- * @class TypeSchemaBase
92
- * @param options {Object}
93
- * @constructor
94
- * create a new type Schema
95
- */
96
- export declare class TypeSchemaBase implements CommonInterface {
97
- name: string;
98
- defaultValue: any;
99
- encode?: (value: any, stream: OutputBinaryStream) => void;
100
- decode?: (stream: BinaryStream) => any;
101
- coerce?: (value: any) => any;
102
- toJSON?: () => string;
103
- category: FieldCategory;
104
- constructor(options: TypeSchemaConstructorOptions);
105
- /**
106
- * @method computer_default_value
107
- * @param defaultValue {*} the default value
108
- * @return {*}
109
- */
110
- computer_default_value(defaultValue: unknown): any;
111
- }
1
+ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
2
+ import { Enum } from "node-opcua-enum";
3
+ import { NodeId } from "node-opcua-nodeid";
4
+ import { ConstructorFunc } from "./constructor_type";
5
+ export interface CommonInterface {
6
+ name: string;
7
+ encode?: (value: any, stream: OutputBinaryStream) => void;
8
+ decode?: (stream: BinaryStream) => any;
9
+ coerce?: (value: any) => any;
10
+ toJSON?: (value: any) => any;
11
+ random?: () => any;
12
+ validate?: (value: any) => void;
13
+ defaultValue?: any;
14
+ computer_default_value(defaultValue: any): any;
15
+ }
16
+ export declare enum FieldCategory {
17
+ enumeration = "enumeration",
18
+ complex = "complex",
19
+ basic = "basic"
20
+ }
21
+ export interface StructuredTypeField {
22
+ name: string;
23
+ fieldType: string;
24
+ isArray?: boolean;
25
+ documentation?: string;
26
+ category: FieldCategory;
27
+ schema: CommonInterface;
28
+ fieldTypeConstructor?: ConstructorFunc;
29
+ subType?: string;
30
+ defaultValue?: any;
31
+ validate?: (value: any) => boolean;
32
+ decode?: (stream: BinaryStream) => any;
33
+ switchBit?: number;
34
+ switchValue?: number;
35
+ }
36
+ export interface FieldEnumeration extends StructuredTypeField {
37
+ }
38
+ export interface FieldComplex extends StructuredTypeField {
39
+ }
40
+ export interface FieldBasic extends StructuredTypeField {
41
+ }
42
+ export declare type FieldType = FieldEnumeration | FieldComplex | FieldBasic;
43
+ export declare type DefaultValueFunc = () => any;
44
+ export interface FieldInterfaceOptions {
45
+ name: string;
46
+ fieldType: string;
47
+ isArray?: boolean;
48
+ documentation?: string;
49
+ category?: FieldCategory;
50
+ defaultValue?: any | DefaultValueFunc;
51
+ schema?: any;
52
+ switchBit?: number;
53
+ switchValue?: number;
54
+ }
55
+ export interface StructuredTypeOptions {
56
+ name: string;
57
+ id?: number | NodeId;
58
+ fields: FieldInterfaceOptions[];
59
+ documentation?: string;
60
+ baseType: string;
61
+ _resolved?: boolean;
62
+ bitFields?: any[];
63
+ base?: StructuredTypeOptions;
64
+ }
65
+ export interface TypeSchemaConstructorOptions {
66
+ name: string;
67
+ category?: FieldCategory;
68
+ defaultValue?: any;
69
+ encode?: (value: any, stream: OutputBinaryStream) => void;
70
+ decode?: (stream: BinaryStream) => any;
71
+ coerce?: (value: any) => any;
72
+ }
73
+ export interface BasicTypeDefinitionOptions extends TypeSchemaConstructorOptions {
74
+ subType: string;
75
+ toJSON?: (value: any) => any;
76
+ random?: () => any;
77
+ validate?: (value: any) => void;
78
+ }
79
+ export interface BasicTypeDefinition extends CommonInterface {
80
+ subType: string;
81
+ }
82
+ export interface BuiltInTypeDefinition extends BasicTypeDefinition {
83
+ }
84
+ export interface EnumerationDefinition extends CommonInterface {
85
+ typedEnum: Enum;
86
+ documentation?: string;
87
+ }
88
+ export declare type TypeDefinition = BuiltInTypeDefinition | EnumerationDefinition | BasicTypeDefinition | TypeSchemaBase;
89
+ /**
90
+ * @class TypeSchemaBase
91
+ * @param options {Object}
92
+ * @constructor
93
+ * create a new type Schema
94
+ */
95
+ export declare class TypeSchemaBase implements CommonInterface {
96
+ name: string;
97
+ defaultValue: any;
98
+ encode?: (value: any, stream: OutputBinaryStream) => void;
99
+ decode?: (stream: BinaryStream) => any;
100
+ coerce?: (value: any) => any;
101
+ toJSON?: () => string;
102
+ category: FieldCategory;
103
+ constructor(options: TypeSchemaConstructorOptions);
104
+ /**
105
+ * @method computer_default_value
106
+ * @param defaultValue {*} the default value
107
+ * @return {*}
108
+ */
109
+ computer_default_value(defaultValue: unknown): any;
110
+ }
package/dist/types.js CHANGED
@@ -1,52 +1,52 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TypeSchemaBase = exports.FieldCategory = void 0;
4
- /**
5
- * @module node-opcua-factory
6
- */
7
- const node_opcua_assert_1 = require("node-opcua-assert");
8
- var FieldCategory;
9
- (function (FieldCategory) {
10
- FieldCategory["enumeration"] = "enumeration";
11
- FieldCategory["complex"] = "complex";
12
- FieldCategory["basic"] = "basic";
13
- })(FieldCategory = exports.FieldCategory || (exports.FieldCategory = {}));
14
- /**
15
- * @class TypeSchemaBase
16
- * @param options {Object}
17
- * @constructor
18
- * create a new type Schema
19
- */
20
- class TypeSchemaBase {
21
- constructor(options) {
22
- (0, node_opcua_assert_1.assert)(options.category !== null);
23
- this.encode = options.encode || undefined;
24
- this.decode = options.decode || undefined;
25
- this.coerce = options.coerce;
26
- this.category = options.category || FieldCategory.basic;
27
- this.name = options.name;
28
- for (const prop in options) {
29
- if (Object.prototype.hasOwnProperty.call(options, prop)) {
30
- this[prop] = options[prop];
31
- }
32
- }
33
- }
34
- /**
35
- * @method computer_default_value
36
- * @param defaultValue {*} the default value
37
- * @return {*}
38
- */
39
- computer_default_value(defaultValue) {
40
- if (defaultValue === undefined) {
41
- defaultValue = this.defaultValue;
42
- }
43
- if (typeof defaultValue === "function") {
44
- // be careful not to cache this value , it must be call each time to make sure
45
- // we do not end up with the same value/instance twice.
46
- defaultValue = defaultValue();
47
- }
48
- return defaultValue;
49
- }
50
- }
51
- exports.TypeSchemaBase = TypeSchemaBase;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeSchemaBase = exports.FieldCategory = void 0;
4
+ /**
5
+ * @module node-opcua-factory
6
+ */
7
+ const node_opcua_assert_1 = require("node-opcua-assert");
8
+ var FieldCategory;
9
+ (function (FieldCategory) {
10
+ FieldCategory["enumeration"] = "enumeration";
11
+ FieldCategory["complex"] = "complex";
12
+ FieldCategory["basic"] = "basic";
13
+ })(FieldCategory = exports.FieldCategory || (exports.FieldCategory = {}));
14
+ /**
15
+ * @class TypeSchemaBase
16
+ * @param options {Object}
17
+ * @constructor
18
+ * create a new type Schema
19
+ */
20
+ class TypeSchemaBase {
21
+ constructor(options) {
22
+ (0, node_opcua_assert_1.assert)(options.category !== null);
23
+ this.encode = options.encode || undefined;
24
+ this.decode = options.decode || undefined;
25
+ this.coerce = options.coerce;
26
+ this.category = options.category || FieldCategory.basic;
27
+ this.name = options.name;
28
+ for (const prop in options) {
29
+ if (Object.prototype.hasOwnProperty.call(options, prop)) {
30
+ this[prop] = options[prop];
31
+ }
32
+ }
33
+ }
34
+ /**
35
+ * @method computer_default_value
36
+ * @param defaultValue {*} the default value
37
+ * @return {*}
38
+ */
39
+ computer_default_value(defaultValue) {
40
+ if (defaultValue === undefined) {
41
+ defaultValue = this.defaultValue;
42
+ }
43
+ if (typeof defaultValue === "function") {
44
+ // be careful not to cache this value , it must be call each time to make sure
45
+ // we do not end up with the same value/instance twice.
46
+ defaultValue = defaultValue();
47
+ }
48
+ return defaultValue;
49
+ }
50
+ }
51
+ exports.TypeSchemaBase = TypeSchemaBase;
52
52
  //# sourceMappingURL=types.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-opcua-factory",
3
- "version": "2.64.1",
3
+ "version": "2.68.0",
4
4
  "description": "pure nodejs OPCUA SDK - module -factory",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -8,20 +8,20 @@
8
8
  "build": "tsc -b",
9
9
  "lint": "eslint source",
10
10
  "format": "prettier --write source",
11
- "clean": "node -e \"require('rimraf').sync('dist');\"",
11
+ "clean": "npx rimraf dist *.tsbuildinfo",
12
12
  "test": "echo no test"
13
13
  },
14
14
  "dependencies": {
15
15
  "chalk": "4.1.2",
16
- "node-opcua-assert": "2.64.1",
17
- "node-opcua-basic-types": "2.64.1",
18
- "node-opcua-binary-stream": "2.64.1",
19
- "node-opcua-debug": "2.64.1",
20
- "node-opcua-enum": "2.64.1",
21
- "node-opcua-guid": "2.64.1",
22
- "node-opcua-nodeid": "2.64.1",
23
- "node-opcua-status-code": "2.64.1",
24
- "node-opcua-utils": "2.64.1"
16
+ "node-opcua-assert": "2.66.0",
17
+ "node-opcua-basic-types": "2.68.0",
18
+ "node-opcua-binary-stream": "2.67.0",
19
+ "node-opcua-debug": "2.68.0",
20
+ "node-opcua-enum": "2.67.0",
21
+ "node-opcua-guid": "2.66.0",
22
+ "node-opcua-nodeid": "2.68.0",
23
+ "node-opcua-status-code": "2.67.0",
24
+ "node-opcua-utils": "2.67.0"
25
25
  },
26
26
  "author": "Etienne Rossignon",
27
27
  "license": "MIT",
@@ -38,5 +38,5 @@
38
38
  "internet of things"
39
39
  ],
40
40
  "homepage": "http://node-opcua.github.io/",
41
- "gitHead": "b65b8738603cd475d7d99a2b20b0ae9d32b4110c"
41
+ "gitHead": "363b466440d0910acddd0cde2c37792ce4724d76"
42
42
  }
@@ -20,7 +20,7 @@ import { get_base_schema, StructuredTypeSchema } from "./factories_structuredTyp
20
20
  import { EnumerationDefinition, FieldCategory, StructuredTypeField, BuiltInTypeDefinition, FieldType } from "./types";
21
21
 
22
22
  function r(str: string, length = 30) {
23
- return (str + " ").substr(0, length);
23
+ return (str + " ").substring(0, length);
24
24
  }
25
25
 
26
26
  function _decode_member_(value: any, field: StructuredTypeField, stream: BinaryStream, options: DecodeDebugOptions) {
@@ -73,8 +73,8 @@ function applyOnAllSchemaFields(self: BaseUAObject, schema: StructuredTypeSchema
73
73
  }
74
74
  }
75
75
 
76
- const _nbElements = (typeof process === "object") ? (process.env.ARRAYLENGTH ? parseInt(process.env.ARRAYLENGTH, 10) : 10) : 10;
77
- const fullBuffer = (typeof process === "object") ? !!(process.env?.FULLBUFFER) : false;
76
+ const _nbElements = typeof process === "object" ? (process.env.ARRAYLENGTH ? parseInt(process.env.ARRAYLENGTH, 10) : 10) : 10;
77
+ const fullBuffer = typeof process === "object" ? !!process.env?.FULLBUFFER : false;
78
78
 
79
79
  function _arrayEllipsis(value: any[] | null, data: ExploreParams): string {
80
80
  if (!value) {
@@ -190,6 +190,48 @@ function _exploreObject(self: BaseUAObject, field: StructuredTypeField, data: Ex
190
190
  return;
191
191
  }
192
192
 
193
+ function _dump_enumeration_value(
194
+ self: BaseUAObject,
195
+ field: StructuredTypeField,
196
+ data: ExploreParams,
197
+ value: any,
198
+ fieldType: string
199
+ ) {
200
+ const s = field.schema as EnumerationDefinition;
201
+
202
+ // istanbul ignore next
203
+ if (!s.typedEnum) {
204
+ // tslint:disable:no-console
205
+ console.log("xxxx cannot find typeEnum", s);
206
+ }
207
+ const convert = (value: number) => {
208
+ // istanbul ignore next
209
+ if (!s.typedEnum.get(value)) {
210
+ return [value, s.typedEnum.get(value)] as [number, any];
211
+ } else {
212
+ return [value, s.typedEnum.get(value)!.key] as [number, any];
213
+ }
214
+ };
215
+ const toS = ([n, s]: [number, any]) => `${n} /*(${s})*/`;
216
+ if (field.isArray) {
217
+ str =
218
+ fieldNameF +
219
+ " " +
220
+ fieldTypeF +
221
+ ": [" +
222
+ value
223
+ .map((c: number) => convert(c))
224
+ .map(toS)
225
+ .join(", ") +
226
+ "]";
227
+ data.lines.push(str);
228
+ } else {
229
+ const c = convert(value);
230
+ str = `${fieldNameF} ${fieldTypeF}: ${toS(c)}`;
231
+ data.lines.push(str);
232
+ }
233
+ }
234
+
193
235
  function _dump_simple_value(
194
236
  self: BaseUAObject,
195
237
  field: StructuredTypeField,
@@ -222,7 +264,11 @@ function _exploreObject(self: BaseUAObject, field: StructuredTypeField, data: Ex
222
264
  value = "" + value + " " + extra;
223
265
  }
224
266
  } else if (fieldType === "DateTime" || fieldType === "UtcTime") {
225
- value = value && value.toISOString ? value.toISOString() : value;
267
+ try {
268
+ value = value && value.toISOString ? value.toISOString() : value;
269
+ } catch {
270
+ value = chalk.red(value?.toString() + " *** ERROR ***");
271
+ }
226
272
  } else if (typeof value === "object" && value !== null && value !== undefined) {
227
273
  // eslint-disable-next-line prefer-spread
228
274
  value = value.toString.apply(value, args);
@@ -306,26 +352,7 @@ function _exploreObject(self: BaseUAObject, field: StructuredTypeField, data: Ex
306
352
 
307
353
  switch (category) {
308
354
  case FieldCategory.enumeration:
309
- {
310
- const s = field.schema as EnumerationDefinition;
311
-
312
- // istanbul ignore next
313
- if (!s.typedEnum) {
314
- // tslint:disable:no-console
315
- console.log("xxxx cannot find typeEnum", s);
316
- }
317
- // istanbul ignore next
318
- if (!s.typedEnum.get(value)) {
319
- // tslint:disable:no-console
320
- (s.typedEnum as any)._isFlaggable = true;
321
- console.log("xxxx cannot find typeEnum value ", value);
322
- str = fieldNameF + " " + fieldTypeF + ": " + s.name + "." + s.typedEnum.get(value) + " ( " + value + ")";
323
- data.lines.push(str);
324
- } else {
325
- str = fieldNameF + " " + fieldTypeF + ": " + s.name + "." + s.typedEnum.get(value)!.key + " ( " + value + ")";
326
- data.lines.push(str);
327
- }
328
- }
355
+ _dump_enumeration_value(self, field, data, value, fieldType);
329
356
  break;
330
357
  case FieldCategory.basic:
331
358
  _dump_simple_value(self, field, data, value, fieldType);
@@ -4,7 +4,7 @@
4
4
  import { assert } from "node-opcua-assert";
5
5
 
6
6
  import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
7
- import { Enum, EnumItem } from "node-opcua-enum";
7
+ import { Enum, EnumItem, _TypescriptEnum , adaptTypescriptEnum} from "node-opcua-enum";
8
8
  import { EnumerationDefinition, TypeSchemaBase, TypeSchemaConstructorOptions } from "./types";
9
9
 
10
10
  function _encode_enumeration(typedEnum: Enum, value: number, stream: OutputBinaryStream): void {
@@ -23,9 +23,10 @@ function _decode_enumeration(typedEnum: Enum, stream: BinaryStream): number {
23
23
  return value;
24
24
  }
25
25
 
26
+
26
27
  export interface EnumerationDefinitionOptions extends TypeSchemaConstructorOptions {
27
- enumValues: any;
28
- typedEnum?: any;
28
+ enumValues: _TypescriptEnum | string[];
29
+ typedEnum?: Enum;
29
30
  lengthInBits?: number;
30
31
 
31
32
  // specialized methods
@@ -34,8 +35,9 @@ export interface EnumerationDefinitionOptions extends TypeSchemaConstructorOptio
34
35
  decode?: (stream: BinaryStream) => EnumItem;
35
36
  }
36
37
 
38
+
37
39
  export class EnumerationDefinitionSchema extends TypeSchemaBase implements EnumerationDefinition {
38
- public enumValues: any;
40
+ public enumValues: _TypescriptEnum;
39
41
  public typedEnum: Enum;
40
42
  public lengthInBits: number;
41
43
  // xx encode: (value: EnumItem, stream: OutputBinaryStream) => void;
@@ -44,6 +46,7 @@ export class EnumerationDefinitionSchema extends TypeSchemaBase implements Enume
44
46
  constructor(options: EnumerationDefinitionOptions) {
45
47
  super(options);
46
48
  // create a new Enum
49
+ this.enumValues = adaptTypescriptEnum(options.enumValues);
47
50
  const typedEnum = new Enum(options.enumValues);
48
51
  options.typedEnum = typedEnum;
49
52
 
package/source/types.ts CHANGED
@@ -118,7 +118,7 @@ export interface BasicTypeDefinition extends CommonInterface {
118
118
  export interface BuiltInTypeDefinition extends BasicTypeDefinition {}
119
119
 
120
120
  export interface EnumerationDefinition extends CommonInterface {
121
- enumValues: any;
121
+ // enumValues: any;
122
122
  typedEnum: Enum;
123
123
  documentation?: string;
124
124
  }