Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-opcua-factory

Package Overview
Dependencies
Maintainers
1
Versions
183
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-opcua-factory - npm Package Compare versions

Comparing version 2.72.1 to 2.73.0

dist/base_ua_object.d.ts

19

dist/datatype_factory.d.ts
import { ExpandedNodeId, NodeId } from "node-opcua-nodeid";
import { ConstructorFunc, ConstructorFuncWithSchema } from "./constructor_type";
import { BaseUAObject } from "./factories_baseobject";
import { EnumerationDefinitionSchema } from "./factories_enumerations";
import { StructuredTypeSchema } from "./factories_structuredTypeSchema";
import { BasicTypeDefinition } from "./types";
import { EnumerationDefinitionSchema } from "./enumerations";
import { CommonInterface, StructuredTypeField, IStructuredTypeSchema, ConstructorFuncWithSchema, ConstructorFunc, IBaseUAObject } from "./types";
export declare function _findFieldSchema(typeDictionary: DataTypeFactory, field: StructuredTypeField, value: any): IStructuredTypeSchema;
export declare class DataTypeFactory {

@@ -15,9 +13,8 @@ defaultByteOrder: string;

private _enumerations;
private _simpleTypes;
private baseDataFactories;
constructor(baseDataFactories: DataTypeFactory[]);
repairBaseDataFactories(baseDataFactories: DataTypeFactory[]): void;
registerSimpleType(name: string, dataTypeNodeId: NodeId, def: BasicTypeDefinition): void;
hasSimpleType(name: string): boolean;
getSimpleType(name: string): BasicTypeDefinition;
hasBuiltInType(name: string): boolean;
getBuiltInType(name: string): CommonInterface;
getBuiltInTypeByDataType(nodeId: NodeId): CommonInterface;
registerEnumeration(enumeration: EnumerationDefinitionSchema): void;

@@ -31,3 +28,3 @@ hasEnumeration(enumName: string): boolean;

hasStructuredType(typeName: string): boolean;
getStructuredTypeSchema(typeName: string): StructuredTypeSchema;
getStructuredTypeSchema(typeName: string): IStructuredTypeSchema;
dump(): void;

@@ -37,3 +34,3 @@ registerClassDefinition(dataTypeNodeId: NodeId, className: string, classConstructor: ConstructorFuncWithSchema): void;

hasConstructor(binaryEncodingNodeId: NodeId): boolean;
constructObject(binaryEncodingNodeId: NodeId): BaseUAObject;
constructObject(binaryEncodingNodeId: NodeId): IBaseUAObject;
associateWithBinaryEncoding(className: string, expandedNodeId: ExpandedNodeId): void;

@@ -40,0 +37,0 @@ toString(): string;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataTypeFactory = void 0;
exports.DataTypeFactory = exports._findFieldSchema = void 0;
/**

@@ -11,7 +11,18 @@ * @module node-opcua-factory

const node_opcua_debug_1 = require("node-opcua-debug");
const factories_baseobject_1 = require("./factories_baseobject");
const factories_builtin_types_1 = require("./factories_builtin_types");
const factories_enumerations_1 = require("./factories_enumerations");
const node_opcua_constants_1 = require("node-opcua-constants");
const builtin_types_1 = require("./builtin_types");
const enumerations_1 = require("./enumerations");
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
function _findFieldSchema(typeDictionary, field, value) {
const fieldType = field.fieldType;
if (field.allowSubType && field.category === "complex") {
const fieldTypeConstructor = value ? value.constructor : field.fieldTypeConstructor;
const _newFieldSchema = fieldTypeConstructor.schema;
return _newFieldSchema;
}
const fieldTypeConstructor = field.fieldTypeConstructor || typeDictionary.getStructureTypeConstructor(fieldType);
return field.schema || fieldTypeConstructor.schema;
}
exports._findFieldSchema = _findFieldSchema;
class DataTypeFactory {

@@ -24,3 +35,2 @@ constructor(baseDataFactories) {

this._enumerations = new Map();
this._simpleTypes = new Map();
this.defaultByteOrder = "LittleEndian";

@@ -33,35 +43,10 @@ this.targetNamespace = "";

}
// -----------------------------
registerSimpleType(name, dataTypeNodeId, def) {
// istanbul ignore next
if (this._simpleTypes.has(name)) {
throw new Error("registerSimpleType " + name + " already register");
}
this._simpleTypes.set(name, { nodeId: dataTypeNodeId, definition: def });
hasBuiltInType(name) {
return (0, builtin_types_1.hasBuiltInType)(name);
}
hasSimpleType(name) {
if (this._simpleTypes.has(name)) {
return true;
}
for (const factory of this.baseDataFactories) {
if (factory.hasSimpleType(name)) {
return true;
}
}
const hasSimpleT = (0, factories_builtin_types_1.hasBuiltInType)(name);
if (hasSimpleT) {
return hasSimpleT;
}
return (0, factories_builtin_types_1.hasBuiltInType)(name);
getBuiltInType(name) {
return (0, builtin_types_1.getBuiltInType)(name);
}
getSimpleType(name) {
if (this._simpleTypes.has(name)) {
return this._simpleTypes.get(name).definition;
}
for (const factory of this.baseDataFactories) {
if (factory.hasSimpleType(name)) {
return factory.getSimpleType(name);
}
}
return (0, factories_builtin_types_1.getBuildInType)(name);
getBuiltInTypeByDataType(nodeId) {
return (0, builtin_types_1.getBuiltInType)(node_opcua_constants_1.DataTypeIds[nodeId.value]);
}

@@ -71,4 +56,3 @@ // -----------------------------

registerEnumeration(enumeration) {
debugLog("Registering Enumeration ", enumeration.name);
(0, node_opcua_assert_1.assert)(!this._enumerations.has(enumeration.name));
(0, node_opcua_assert_1.assert)(!this._enumerations.has(enumeration.name), "enumeration already registered");
this._enumerations.set(enumeration.name, enumeration);

@@ -86,3 +70,3 @@ }

}
if ((0, factories_enumerations_1.hasEnumeration)(enumName)) {
if ((0, enumerations_1.hasBuiltInEnumeration)(enumName)) {
return true;

@@ -103,3 +87,3 @@ }

}
const ee = (0, factories_enumerations_1.getEnumeration)(enumName);
const ee = (0, enumerations_1.getBuiltInEnumeration)(enumName);
return ee;

@@ -234,4 +218,3 @@ }

debugLog("Cannot find constructor for " + binaryEncodingNodeId.toString());
return new factories_baseobject_1.BaseUAObject();
// throw new Error("Cannot find constructor for " + expandedNodeId.toString());
throw new Error("Cannot find constructor for " + binaryEncodingNodeId.toString());
}

@@ -238,0 +221,0 @@ return new constructor();

/**
* @module node-opcua-factory
*/
export * from "./constructor_type";
export * from "./base_ua_object";
export * from "./basic_type";
export * from "./builtin_types_special";
export * from "./builtin_types";
export * from "./datatype_factory";
export * from "./factories_id_generator";
export * from "./factories_enumerations";
export * from "./factories_basic_type";
export * from "./factories_builtin_types";
export * from "./factories_builtin_types_special";
export * from "./factories_baseobject";
export * from "./enumerations";
export * from "./get_standard_data_type_factory";
export * from "./get_structured_type_schema";
export * from "./id_generator";
export * from "./nodeid_type";
export * from "./parameters";
export * from "./register_class_definition";
export * from "./schema_helpers";
export * from "./structured_type_schema";
export * from "./types";
export * from "./factories_schema_helpers";
export * from "./factories_factories";
export * from "./factories_structuredTypeSchema";

@@ -20,14 +20,17 @@ "use strict";

*/
__exportStar(require("./constructor_type"), exports);
__exportStar(require("./base_ua_object"), exports);
__exportStar(require("./basic_type"), exports);
__exportStar(require("./builtin_types_special"), exports);
__exportStar(require("./builtin_types"), exports);
__exportStar(require("./datatype_factory"), exports);
__exportStar(require("./factories_id_generator"), exports);
__exportStar(require("./factories_enumerations"), exports);
__exportStar(require("./factories_basic_type"), exports);
__exportStar(require("./factories_builtin_types"), exports);
__exportStar(require("./factories_builtin_types_special"), exports);
__exportStar(require("./factories_baseobject"), exports);
__exportStar(require("./enumerations"), exports);
__exportStar(require("./get_standard_data_type_factory"), exports);
__exportStar(require("./get_structured_type_schema"), exports);
__exportStar(require("./id_generator"), exports);
__exportStar(require("./nodeid_type"), exports);
__exportStar(require("./parameters"), exports);
__exportStar(require("./register_class_definition"), exports);
__exportStar(require("./schema_helpers"), exports);
__exportStar(require("./structured_type_schema"), exports);
__exportStar(require("./types"), exports);
__exportStar(require("./factories_schema_helpers"), exports);
__exportStar(require("./factories_factories"), exports);
__exportStar(require("./factories_structuredTypeSchema"), exports);
//# sourceMappingURL=index.js.map

@@ -0,7 +1,15 @@

/**
* @module node-opcua-factory
*/
import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
import { Enum } from "node-opcua-enum";
import { NodeId } from "node-opcua-nodeid";
import { ConstructorFunc } from "./constructor_type";
import { ExpandedNodeId, NodeId } from "node-opcua-nodeid";
export declare enum FieldCategory {
enumeration = "enumeration",
complex = "complex",
basic = "basic"
}
export interface CommonInterface {
name: string;
defaultValue?: any;
encode?: (value: any, stream: OutputBinaryStream) => void;

@@ -11,12 +19,51 @@ decode?: (stream: BinaryStream) => any;

toJSON?: (value: any) => any;
category: FieldCategory;
random?: () => any;
validate?: (value: any) => void;
defaultValue?: any;
computer_default_value(defaultValue: any): any;
subType: string;
isAbstract: boolean;
isSubTypeOf(type: CommonInterface): boolean;
}
export declare enum FieldCategory {
enumeration = "enumeration",
complex = "complex",
basic = "basic"
export interface FieldInterfaceOptions {
name: string;
defaultValue?: any | DefaultValueFunc;
fieldType: string;
isArray?: boolean;
documentation?: string;
category?: FieldCategory;
schema?: CommonInterface;
switchBit?: number;
switchValue?: number;
allowSubType?: boolean;
dataType?: NodeId;
basicDataType?: number;
}
export declare type Func1<T> = (value: any, field: StructuredTypeField, data: T, args?: any) => void;
export interface DecodeDebugOptions {
tracer: any;
name: string;
}
export interface IBaseUAObject {
schema: IStructuredTypeSchema;
encode(stream: OutputBinaryStream): void;
decode(stream: BinaryStream): void;
binaryStoreSize(): number;
toString(...args: any[]): string;
isValid(): boolean;
explore(): string;
applyOnAllFields<T>(func: Func1<T>, data: T): void;
toJSON(): any;
decodeDebug(stream: BinaryStream, options: DecodeDebugOptions): void;
clone(): IBaseUAObject;
}
declare type BaseUAObjectConstructable = new (options?: any) => IBaseUAObject;
export declare type ConstructorFunc = BaseUAObjectConstructable;
export interface ConstructorFuncWithSchema extends ConstructorFunc {
schema: IStructuredTypeSchema;
possibleFields: string[];
encodingDefaultBinary: ExpandedNodeId;
encodingDefaultXml: ExpandedNodeId;
encodingDefaultJson?: ExpandedNodeId;
}
export interface StructuredTypeField {

@@ -28,10 +75,13 @@ name: string;

category: FieldCategory;
defaultValue?: any | DefaultValueFunc;
schema: CommonInterface;
switchBit?: number;
switchValue?: number;
allowSubType?: boolean;
dataType?: NodeId;
basicDataType?: number;
fieldTypeConstructor?: ConstructorFunc;
subType?: string;
defaultValue?: any;
validate?: (value: any) => boolean;
decode?: (stream: BinaryStream) => any;
switchBit?: number;
switchValue?: number;
}

@@ -46,13 +96,2 @@ export interface FieldEnumeration extends StructuredTypeField {

export declare type DefaultValueFunc = () => any;
export interface FieldInterfaceOptions {
name: string;
fieldType: string;
isArray?: boolean;
documentation?: string;
category?: FieldCategory;
defaultValue?: any | DefaultValueFunc;
schema?: any;
switchBit?: number;
switchValue?: number;
}
export interface StructuredTypeOptions {

@@ -70,2 +109,4 @@ name: string;

name: string;
subType?: string;
isAbstract?: boolean;
category?: FieldCategory;

@@ -77,4 +118,3 @@ defaultValue?: any;

}
export interface BasicTypeDefinitionOptions extends TypeSchemaConstructorOptions {
subType: string;
export interface BasicTypeDefinitionOptionsB extends TypeSchemaConstructorOptions {
toJSON?: (value: any) => any;

@@ -84,2 +124,7 @@ random?: () => any;

}
export interface BasicTypeDefinitionOptionsBase extends BasicTypeDefinitionOptionsB {
}
export interface BasicTypeDefinitionOptions extends BasicTypeDefinitionOptionsB {
subType: string;
}
export interface BasicTypeDefinition extends CommonInterface {

@@ -94,24 +139,19 @@ subType: string;

}
export declare type TypeDefinition = BuiltInTypeDefinition | EnumerationDefinition | BasicTypeDefinition | TypeSchemaBase;
/**
* @class TypeSchemaBase
* @param options {Object}
* @constructor
* create a new type Schema
*/
export declare class TypeSchemaBase implements CommonInterface {
name: string;
defaultValue: any;
encode?: (value: any, stream: OutputBinaryStream) => void;
decode?: (stream: BinaryStream) => any;
coerce?: (value: any) => any;
toJSON?: () => string;
category: FieldCategory;
constructor(options: TypeSchemaConstructorOptions);
/**
* @method computer_default_value
* @param defaultValue {*} the default value
* @return {*}
*/
computer_default_value(defaultValue: unknown): any;
export declare type TypeDefinition = BuiltInTypeDefinition | EnumerationDefinition | BasicTypeDefinition | CommonInterface;
export interface IStructuredTypeSchema extends CommonInterface {
fields: FieldType[];
id: NodeId;
dataTypeNodeId: NodeId;
baseType: string;
_possibleFields: string[];
_baseSchema: IStructuredTypeSchema | null;
documentation?: string;
isValid?: (options: any) => boolean;
decodeDebug?: (stream: BinaryStream, options: any) => any;
constructHook?: (options: any) => any;
encodingDefaultBinary?: ExpandedNodeId;
encodingDefaultXml?: ExpandedNodeId;
encodingDefaultJson?: ExpandedNodeId;
bitFields?: any[];
}
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypeSchemaBase = exports.FieldCategory = void 0;
/**
* @module node-opcua-factory
*/
const node_opcua_assert_1 = require("node-opcua-assert");
exports.FieldCategory = void 0;
var FieldCategory;

@@ -14,40 +10,2 @@ (function (FieldCategory) {

})(FieldCategory = exports.FieldCategory || (exports.FieldCategory = {}));
/**
* @class TypeSchemaBase
* @param options {Object}
* @constructor
* create a new type Schema
*/
class TypeSchemaBase {
constructor(options) {
(0, node_opcua_assert_1.assert)(options.category !== null);
this.encode = options.encode || undefined;
this.decode = options.decode || undefined;
this.coerce = options.coerce;
this.category = options.category || FieldCategory.basic;
this.name = options.name;
for (const prop in options) {
if (Object.prototype.hasOwnProperty.call(options, prop)) {
this[prop] = options[prop];
}
}
}
/**
* @method computer_default_value
* @param defaultValue {*} the default value
* @return {*}
*/
computer_default_value(defaultValue) {
if (defaultValue === undefined) {
defaultValue = this.defaultValue;
}
if (typeof defaultValue === "function") {
// be careful not to cache this value , it must be call each time to make sure
// we do not end up with the same value/instance twice.
defaultValue = defaultValue();
}
return defaultValue;
}
}
exports.TypeSchemaBase = TypeSchemaBase;
//# sourceMappingURL=types.js.map
{
"name": "node-opcua-factory",
"version": "2.72.1",
"version": "2.73.0",
"description": "pure nodejs OPCUA SDK - module -factory",

@@ -12,3 +12,3 @@ "main": "./dist/index.js",

"clean": "npx rimraf dist *.tsbuildinfo",
"test": "echo no test"
"test": "mocha"
},

@@ -18,4 +18,5 @@ "dependencies": {

"node-opcua-assert": "2.66.0",
"node-opcua-basic-types": "2.72.1",
"node-opcua-binary-stream": "2.71.0",
"node-opcua-basic-types": "2.73.0",
"node-opcua-binary-stream": "2.73.0",
"node-opcua-constants": "2.70.0",
"node-opcua-debug": "2.71.0",

@@ -25,3 +26,3 @@ "node-opcua-enum": "2.71.0",

"node-opcua-nodeid": "2.71.0",
"node-opcua-status-code": "2.71.0",
"node-opcua-status-code": "2.73.0",
"node-opcua-utils": "2.71.0"

@@ -44,3 +45,3 @@ },

"homepage": "http://node-opcua.github.io/",
"gitHead": "ba98dd91a9eada9815268c66c98ca5391bc884e7"
"gitHead": "b23a87c1ef777c0d8b680f45ee77e2a319feb092"
}

@@ -10,9 +10,14 @@ /**

import { ExpandedNodeId, NodeId } from "node-opcua-nodeid";
import { DataTypeIds } from "node-opcua-constants";
import { ConstructorFunc, ConstructorFuncWithSchema } from "./constructor_type";
import { BaseUAObject } from "./factories_baseobject";
import { getBuildInType, hasBuiltInType } from "./factories_builtin_types";
import { EnumerationDefinitionSchema, getEnumeration, hasEnumeration } from "./factories_enumerations";
import { StructuredTypeSchema } from "./factories_structuredTypeSchema";
import { BasicTypeDefinition } from "./types";
import { getBuiltInType as getBuiltInType, hasBuiltInType } from "./builtin_types";
import { EnumerationDefinitionSchema, getBuiltInEnumeration, hasBuiltInEnumeration } from "./enumerations";
import {
CommonInterface,
StructuredTypeField,
IStructuredTypeSchema,
ConstructorFuncWithSchema,
ConstructorFunc,
IBaseUAObject
} from "./types";

@@ -22,2 +27,18 @@ const debugLog = make_debugLog(__filename);

export function _findFieldSchema(typeDictionary: DataTypeFactory, field: StructuredTypeField, value: any): IStructuredTypeSchema {
const fieldType = field.fieldType;
if (field.allowSubType && field.category === "complex") {
const fieldTypeConstructor = value ? value.constructor : field.fieldTypeConstructor;
const _newFieldSchema = fieldTypeConstructor.schema;
return _newFieldSchema as IStructuredTypeSchema;
}
const fieldTypeConstructor = field.fieldTypeConstructor || typeDictionary.getStructureTypeConstructor(fieldType);
return (field.schema as IStructuredTypeSchema) || (fieldTypeConstructor as any).schema;
}
export class DataTypeFactory {

@@ -32,3 +53,2 @@ public defaultByteOrder: string;

private _enumerations: Map<string, EnumerationDefinitionSchema> = new Map();
private _simpleTypes: Map<string, { nodeId: NodeId; definition: BasicTypeDefinition }> = new Map();

@@ -46,42 +66,19 @@ private baseDataFactories: DataTypeFactory[];

}
// -----------------------------
public registerSimpleType(name: string, dataTypeNodeId: NodeId, def: BasicTypeDefinition): void {
// istanbul ignore next
if (this._simpleTypes.has(name)) {
throw new Error("registerSimpleType " + name + " already register");
}
this._simpleTypes.set(name, { nodeId: dataTypeNodeId, definition: def });
}
public hasSimpleType(name: string): boolean {
if (this._simpleTypes.has(name)) {
return true;
}
for (const factory of this.baseDataFactories) {
if (factory.hasSimpleType(name)) {
return true;
}
}
const hasSimpleT = hasBuiltInType(name);
if (hasSimpleT) {
return hasSimpleT;
}
public hasBuiltInType(name: string): boolean {
return hasBuiltInType(name);
}
public getSimpleType(name: string): BasicTypeDefinition {
if (this._simpleTypes.has(name)) {
return this._simpleTypes.get(name)!.definition;
}
for (const factory of this.baseDataFactories) {
if (factory.hasSimpleType(name)) {
return factory.getSimpleType(name);
}
}
return getBuildInType(name);
public getBuiltInType(name: string): CommonInterface {
return getBuiltInType(name);
}
public getBuiltInTypeByDataType(nodeId: NodeId): CommonInterface {
return getBuiltInType(DataTypeIds[nodeId.value as number]);
}
// -----------------------------
// EnumerationDefinitionSchema
public registerEnumeration(enumeration: EnumerationDefinitionSchema): void {
debugLog("Registering Enumeration ", enumeration.name);
assert(!this._enumerations.has(enumeration.name));
assert(!this._enumerations.has(enumeration.name), "enumeration already registered");
this._enumerations.set(enumeration.name, enumeration);

@@ -100,3 +97,3 @@ }

}
if (hasEnumeration(enumName)) {
if (hasBuiltInEnumeration(enumName)) {
return true;

@@ -106,2 +103,3 @@ }

}
public getEnumeration(enumName: string): EnumerationDefinitionSchema | null {

@@ -118,3 +116,3 @@ if (this._enumerations.has(enumName)) {

}
const ee = getEnumeration(enumName);
const ee = getBuiltInEnumeration(enumName);
return ee;

@@ -188,3 +186,3 @@ }

public getStructuredTypeSchema(typeName: string): StructuredTypeSchema {
public getStructuredTypeSchema(typeName: string): IStructuredTypeSchema {
const constructor = this.getStructureTypeConstructor(typeName);

@@ -256,3 +254,3 @@ return constructor.schema;

public constructObject(binaryEncodingNodeId: NodeId): BaseUAObject {
public constructObject(binaryEncodingNodeId: NodeId): IBaseUAObject {
if (!verifyExpandedNodeId(binaryEncodingNodeId)) {

@@ -265,4 +263,3 @@ throw new Error(" constructObject : invalid expandedNodeId provided " + binaryEncodingNodeId.toString());

debugLog("Cannot find constructor for " + binaryEncodingNodeId.toString());
return new BaseUAObject();
// throw new Error("Cannot find constructor for " + expandedNodeId.toString());
throw new Error("Cannot find constructor for " + binaryEncodingNodeId.toString());
}

@@ -328,3 +325,3 @@ return new constructor();

function dumpSchema(schema: StructuredTypeSchema, write: any) {
function dumpSchema(schema: IStructuredTypeSchema, write: any) {
write("name ", schema.name);

@@ -331,0 +328,0 @@ write("dataType ", schema.dataTypeNodeId.toString());

/**
* @module node-opcua-factory
*/
export * from "./constructor_type";
export * from "./base_ua_object";
export * from "./basic_type";
export * from "./builtin_types_special";
export * from "./builtin_types";
export * from "./datatype_factory";
export * from "./factories_id_generator";
export * from "./factories_enumerations";
export * from "./factories_basic_type";
export * from "./factories_builtin_types";
export * from "./factories_builtin_types_special";
export * from "./factories_baseobject";
export * from "./types";
export * from "./factories_schema_helpers";
export * from "./factories_factories";
export * from "./factories_structuredTypeSchema";
export * from "./enumerations";
export * from "./get_standard_data_type_factory";
export * from "./get_structured_type_schema";
export * from "./id_generator";
export * from "./nodeid_type";
export * from "./parameters";
export * from "./register_class_definition";
export * from "./schema_helpers";
export * from "./structured_type_schema";
export * from "./types";
/**
* @module node-opcua-factory
*/
import { assert } from "node-opcua-assert";
import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
import { Enum, EnumItem } from "node-opcua-enum";
import { NodeId } from "node-opcua-nodeid";
import { ConstructorFunc } from "./constructor_type";
import { Enum } from "node-opcua-enum";
import { ExpandedNodeId, NodeId } from "node-opcua-nodeid";
export enum FieldCategory {
enumeration = "enumeration",
complex = "complex",
basic = "basic"
}
// ------------------

@@ -18,40 +22,86 @@ // @brief CommonInterface

name: string;
defaultValue?: any;
encode?: (value: any, stream: OutputBinaryStream) => void;
decode?: (stream: BinaryStream) => any;
coerce?: (value: any) => any;
coerce?: (value: any) => any;
toJSON?: (value: any) => any;
category: FieldCategory;
random?: () => any;
validate?: (value: any) => void;
computer_default_value(defaultValue: any): any;
subType: string;
isAbstract: boolean;
defaultValue?: any;
isSubTypeOf(type: CommonInterface): boolean;
}
computer_default_value(defaultValue: any): any;
export interface FieldInterfaceOptions {
name: string;
defaultValue?: any | DefaultValueFunc;
fieldType: string;
isArray?: boolean;
documentation?: string;
category?: FieldCategory;
schema?: CommonInterface;
switchBit?: number; // the bit number
switchValue?: number;
allowSubType?: boolean;
dataType?: NodeId;
basicDataType?: number;
}
export enum FieldCategory {
enumeration = "enumeration",
complex = "complex",
basic = "basic"
export type Func1<T> = (value: any, field: StructuredTypeField, data: T, args?: any) => void;
export interface DecodeDebugOptions {
tracer: any;
name: string;
}
export interface IBaseUAObject {
schema: IStructuredTypeSchema;
encode(stream: OutputBinaryStream): void;
decode(stream: BinaryStream): void;
binaryStoreSize(): number;
toString(...args: any[]): string;
isValid(): boolean;
explore(): string;
applyOnAllFields<T>(func: Func1<T>, data: T): void;
toJSON(): any;
decodeDebug(stream: BinaryStream, options: DecodeDebugOptions): void;
clone(): IBaseUAObject;
}
type BaseUAObjectConstructable = new (options?: any) => IBaseUAObject;
export type ConstructorFunc = BaseUAObjectConstructable;
// new (...args: any[]) => BaseUAObjectConstructable;
export interface ConstructorFuncWithSchema extends ConstructorFunc {
schema: IStructuredTypeSchema;
possibleFields: string[];
encodingDefaultBinary: ExpandedNodeId;
encodingDefaultXml: ExpandedNodeId;
encodingDefaultJson?: ExpandedNodeId;
}
export interface StructuredTypeField {
name: string;
fieldType: string;
isArray?: boolean;
documentation?: string;
category: FieldCategory;
defaultValue?: any | DefaultValueFunc;
schema: CommonInterface;
switchBit?: number; // the bit number
switchValue?: number;
allowSubType?: boolean;
dataType?: NodeId;
basicDataType?: number; // DataType
fieldTypeConstructor?: ConstructorFunc;
subType?: string;
defaultValue?: any;
validate?: (value: any) => boolean;
decode?: (stream: BinaryStream) => any;
switchBit?: number; // the bit number
switchValue?: number;
}

@@ -76,14 +126,2 @@

export interface FieldInterfaceOptions {
name: string;
fieldType: string;
isArray?: boolean;
documentation?: string;
category?: FieldCategory;
defaultValue?: any | DefaultValueFunc;
schema?: any;
switchBit?: number; // the bit number
switchValue?: number;
}
export interface StructuredTypeOptions {

@@ -102,2 +140,4 @@ name: string;

name: string;
subType?: string;
isAbstract?: boolean;
category?: FieldCategory;

@@ -110,4 +150,3 @@ defaultValue?: any;

export interface BasicTypeDefinitionOptions extends TypeSchemaConstructorOptions {
subType: string;
export interface BasicTypeDefinitionOptionsB extends TypeSchemaConstructorOptions {
toJSON?: (value: any) => any;

@@ -118,2 +157,10 @@ random?: () => any;

export interface BasicTypeDefinitionOptionsBase extends BasicTypeDefinitionOptionsB {
/** */
}
export interface BasicTypeDefinitionOptions extends BasicTypeDefinitionOptionsB {
subType: string;
}
export interface BasicTypeDefinition extends CommonInterface {

@@ -126,3 +173,3 @@ subType: string;

export interface EnumerationDefinition extends CommonInterface {
// enumValues: any;
// enumValues: any;
typedEnum: Enum;

@@ -132,50 +179,25 @@ documentation?: string;

export type TypeDefinition = BuiltInTypeDefinition | EnumerationDefinition | BasicTypeDefinition | TypeSchemaBase;
export type TypeDefinition = BuiltInTypeDefinition | EnumerationDefinition | BasicTypeDefinition | CommonInterface;
/**
* @class TypeSchemaBase
* @param options {Object}
* @constructor
* create a new type Schema
*/
export class TypeSchemaBase implements CommonInterface {
public name: string;
public defaultValue: any;
public encode?: (value: any, stream: OutputBinaryStream) => void;
public decode?: (stream: BinaryStream) => any;
public coerce?: (value: any) => any;
public toJSON?: () => string;
public category: FieldCategory;
export interface IStructuredTypeSchema extends CommonInterface {
fields: FieldType[];
id: NodeId;
dataTypeNodeId: NodeId;
constructor(options: TypeSchemaConstructorOptions) {
assert(options.category !== null);
this.encode = options.encode || undefined;
this.decode = options.decode || undefined;
this.coerce = options.coerce;
this.category = options.category || FieldCategory.basic;
this.name = options.name;
baseType: string;
_possibleFields: string[];
_baseSchema: IStructuredTypeSchema | null;
for (const prop in options) {
if (Object.prototype.hasOwnProperty.call(options, prop)) {
(this as any)[prop] = (options as any)[prop];
}
}
}
documentation?: string;
/**
* @method computer_default_value
* @param defaultValue {*} the default value
* @return {*}
*/
public computer_default_value(defaultValue: unknown): any {
if (defaultValue === undefined) {
defaultValue = this.defaultValue;
}
if (typeof defaultValue === "function") {
// be careful not to cache this value , it must be call each time to make sure
// we do not end up with the same value/instance twice.
defaultValue = defaultValue();
}
return defaultValue;
}
isValid?: (options: any) => boolean;
decodeDebug?: (stream: BinaryStream, options: any) => any;
constructHook?: (options: any) => any;
encodingDefaultBinary?: ExpandedNodeId;
encodingDefaultXml?: ExpandedNodeId;
encodingDefaultJson?: ExpandedNodeId;
bitFields?: any[];
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc