Skip to content

Commit

Permalink
chore: clean-up imports
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Nov 20, 2023
1 parent 4192e06 commit 874a9c8
Show file tree
Hide file tree
Showing 175 changed files with 359 additions and 417 deletions.
4 changes: 2 additions & 2 deletions packages/fix_tsconfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import * as fs from "fs";
import * as path from "path";
import fs from "fs";
import path from "path";

const readdir = fs.promises.readdir;
const readFileSync = fs.promises.readFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*
*/

import * as path from "path";
import * as fs from "fs";
import path from "path";
import fs from "fs";

import { assert } from "node-opcua-assert";
import { coerceNodeId, makeNodeId, NodeIdLike } from "node-opcua-nodeid";
Expand All @@ -18,6 +18,7 @@ import { AccessLevelFlag, makeAccessLevelFlag } from "node-opcua-data-model";
import { Variant, DataType, VariantArrayType, buildVariantArray } from "node-opcua-variant";
import { findBuiltInType } from "node-opcua-factory";
import { DataValue } from "node-opcua-data-value";
import { emptyGuid, isValidBoolean, isValidUInt16, randomString } from "node-opcua-basic-types";
import * as ec from "node-opcua-basic-types";
import { QualifiedName, LocalizedText } from "node-opcua-data-model";
import { standardUnits } from "node-opcua-data-access";
Expand Down Expand Up @@ -57,16 +58,16 @@ function getRandomFuncForType(dataType: DataType): () => any {
};
case "QualifiedName":
return () => {
return new QualifiedName({ name: ec.randomString() });
return new QualifiedName({ name: randomString() });
};
case "LocalizedText":
return () => {
return new LocalizedText({ text: ec.randomString() });
return new LocalizedText({ text: randomString() });
};
case "XmlElement":
return () => {
const element = ec.randomString();
const content = ec.randomString();
const element = randomString();
const content = randomString();
return "<" + element + ">" + content + "</" + element + ">";
};
default:
Expand Down Expand Up @@ -306,7 +307,7 @@ const typeAndDefaultValue = [
{ type: "DateTime", defaultValue: DateTime_Min },
{ type: "Double", defaultValue: 0.0 },
{ type: "Float", defaultValue: 0.0 },
{ type: "Guid", defaultValue: ec.emptyGuid },
{ type: "Guid", defaultValue: emptyGuid },
{ type: "SByte", defaultValue: 0 },
{ type: "Int16", defaultValue: 0 },
{ type: "Int32", defaultValue: 0 },
Expand Down Expand Up @@ -452,7 +453,7 @@ function add_simulation_variables(namespace: Namespace, scalarFolder: UAObject):
intervalVariable.on("value_changed", (dataValue /*,indexRange*/) => {
const variant = dataValue.value;
assert(variant instanceof Variant);
assert(ec.isValidUInt16(variant.value), " value must be valid for dataType");
assert(isValidUInt16(variant.value), " value must be valid for dataType");
interval = variant.value;
install_Timer();
});
Expand All @@ -473,7 +474,7 @@ function add_simulation_variables(namespace: Namespace, scalarFolder: UAObject):
enabledVariable.on("value_changed", (dataValue /*,indexRange*/) => {
const variant = dataValue.value;
assert(variant instanceof Variant);
assert(ec.isValidBoolean(variant.value), " value must be valid for dataType");
assert(isValidBoolean(variant.value), " value must be valid for dataType");
enabled = variant.value;
install_Timer();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/node-opcua-address-space/source/pseudo_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @module node-opcua-address-space
*/
import { promisify } from "util";
import * as async from "async";
import async from "async";

import { assert } from "node-opcua-assert";
import { DataValue } from "node-opcua-data-value";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as fs from "fs";
import fs from "fs";
import { callbackify } from "util";

import { checkDebugFlag, make_debugLog, make_errorLog } from "node-opcua-debug";
Expand Down
4 changes: 2 additions & 2 deletions packages/node-opcua-address-space/src/address_space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
ModelChangeStructureDataType,
RelativePathElement
} from "node-opcua-types";
import * as utils from "node-opcua-utils";
import { isNullOrUndefined } from "node-opcua-utils";
import { lowerFirstLetter } from "node-opcua-utils";
import { DataType, Variant, VariantArrayType, VariantOptions, VariantT } from "node-opcua-variant";
import {
Expand Down Expand Up @@ -1303,7 +1303,7 @@ export class AddressSpace implements AddressSpacePrivate {
}
// ----------------------------------------------- handle is forward
assert(params.isForward === undefined || typeof params.isForward === "boolean");
params.isForward = utils.isNullOrUndefined(params.isForward) ? true : !!params.isForward;
params.isForward = isNullOrUndefined(params.isForward) ? true : !!params.isForward;

// referenceType = Organizes , isForward = true => referenceType = Organizes , isForward = true
// referenceType = Organizes , isForward = false => referenceType = Organizes , isForward = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { DataValue } from "node-opcua-data-value";
import { NodeId, NodeIdLike } from "node-opcua-nodeid";

import { UAOffNormalAlarm_Base } from "node-opcua-nodeset-ua";
import { NumericalRangeInvalid } from "node-opcua-numeric-range";
import { StatusCodes } from "node-opcua-status-code";
import * as utils from "node-opcua-utils";
import { isNullOrUndefined } from "node-opcua-utils";
import { DataType, VariantOptions } from "node-opcua-variant";
import { InstantiateOffNormalAlarmOptions } from "../../source/interfaces/alarms_and_conditions/instantiate_off_normal_alarm_options";
import { UADiscreteAlarmEx } from "../../source/interfaces/alarms_and_conditions/ua_discrete_alarm_ex";
Expand Down Expand Up @@ -181,7 +179,7 @@ export class UAOffNormalAlarmImpl extends UADiscreteAlarmImpl implements UAOffNo
}

private _mayBe_updateAlarmState(normalStateValue?: any, inputValue?: any): void {
if (utils.isNullOrUndefined(normalStateValue) || utils.isNullOrUndefined(inputValue)) {
if (isNullOrUndefined(normalStateValue) || isNullOrUndefined(inputValue)) {
this.activeState.setValue(false);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/node-opcua-address-space/src/base_node_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import { XmlWriter } from "../source/xml_writer";
import { dumpReferenceDescriptions, dumpReferences } from "../source/helpers/dump_tools";
import { SessionContext, WellKnownRolesNodeId } from "../source/session_context";
import { AddressSpace } from "../src/address_space";
import * as cetools from "./address_space_change_event_tools";
import { _handle_add_reference_change_event } from "./address_space_change_event_tools";
import { AddressSpacePrivate } from "./address_space_private";
import {
_constructReferenceDescription,
Expand Down Expand Up @@ -928,7 +928,7 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {

_propagate_ref.call(this, addressSpace, referenceNode);
this.install_extra_properties();
cetools._handle_add_reference_change_event(this, referenceNode.nodeId);
_handle_add_reference_change_event(this, referenceNode.nodeId);
}

public removeReference(referenceOpts: AddReferenceOpts): void {
Expand Down
12 changes: 5 additions & 7 deletions packages/node-opcua-address-space/src/namespace_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
RolePermissionType,
RolePermissionTypeOptions
} from "node-opcua-types";
import * as utils from "node-opcua-utils";
import { isNullOrUndefined } from "node-opcua-utils";
import { DataType, Variant, VariantArrayType, VariantOptions, verifyRankAndDimensions } from "node-opcua-variant";
import {
AddBaseNodeOptions,
Expand All @@ -45,7 +45,6 @@ import {
CreateDataTypeOptions,
CreateNodeOptions,
EnumerationItem,
INamespace,
RequiredModel,
UADataType,
UAEventType,
Expand All @@ -58,7 +57,7 @@ import {
UAVariableType,
UAView
} from "node-opcua-address-space-base";
import { UAAnalogItem, UADataItem, UAInitialState, UAState, UAYArrayItem } from "node-opcua-nodeset-ua";
import { UAAnalogItem, UADataItem, UAInitialState, UAState } from "node-opcua-nodeset-ua";

import {
AddMultiStateDiscreteOptions,
Expand All @@ -70,13 +69,12 @@ import { UAStateMachineEx } from "../source/interfaces/state_machine/ua_state_ma
import { UATransitionEx } from "../source/interfaces/state_machine/ua_transition_ex";
import {
InstantiateAlarmConditionOptions,
InstantiateExclusiveLimitAlarmOptions,
InstantiateLimitAlarmOptions,
InstantiateOffNormalAlarmOptions,
UATwoStateDiscreteEx,
UAYArrayItemEx
} from "../source";
import { AddAnalogDataItemOptions, AddDataItemOptions, UAAnalogItemEx } from "../source/namespace_data_access";
import { AddAnalogDataItemOptions, AddDataItemOptions } from "../source/namespace_data_access";
import { UATwoStateVariableEx } from "../source/ua_two_state_variable_ex";
import { UAMultiStateValueDiscreteEx } from "../source/interfaces/data_access/ua_multistate_value_discrete_ex";
import { UAAlarmConditionEx } from "../source/interfaces/alarms_and_conditions/ua_alarm_condition_ex";
Expand Down Expand Up @@ -1076,7 +1074,7 @@ export class NamespaceImpl implements NamespacePrivate {

function coerceAxisScale(value: any) {
const ret = AxisScaleEnumeration[value];
assert(!utils.isNullOrUndefined(ret));
assert(!isNullOrUndefined(ret));
return ret;
}

Expand Down Expand Up @@ -1982,7 +1980,7 @@ export class NamespaceImpl implements NamespacePrivate {
// ------------------------------------------ DataType
options.dataType = addressSpace._coerce_DataType(options.dataType!);

options.valueRank = utils.isNullOrUndefined(options.valueRank)
options.valueRank = isNullOrUndefined(options.valueRank)
? options.arrayDimensions
? options.arrayDimensions.length
: -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
QualifiedName
} from "node-opcua-data-model";
import { ExpandedNodeId, NodeId, NodeIdType, resolveNodeId } from "node-opcua-nodeid";
import * as utils from "node-opcua-utils";
import { lowerFirstLetter, isNullOrUndefined } from "node-opcua-utils";
import { Variant, VariantArrayType, DataType } from "node-opcua-variant";
import {
IAddressSpace,
Expand Down Expand Up @@ -105,7 +105,6 @@ function b(xw: XmlWriter, browseName: QualifiedName): string {
return translateBrowseName(xw, browseName).toString().replace("ns=0;", "");
}


function hasHigherPriorityThan(namespaceIndex1: number, namespaceIndex2: number, priorityTable: number[]) {
const order1 = priorityTable[namespaceIndex1];
const order2 = priorityTable[namespaceIndex2];
Expand Down Expand Up @@ -335,7 +334,7 @@ function _dumpVariantInnerExtensionObject(
const dataTypeNodeId = field.dataType;

const fieldName = field.name!;
const lowerFieldName = utils.lowerFirstLetter(fieldName);
const lowerFieldName = lowerFirstLetter(fieldName);
const v = (value as unknown as Record<string, unknown>)[lowerFieldName];
if (v !== null && v !== undefined) {
if (
Expand Down Expand Up @@ -855,7 +854,7 @@ function _dumpEnumDefinition(xw: XmlWriter, enumDefinition: EnumDefinition) {
for (const defItem of enumDefinition.fields!) {
xw.startElement("Field");
xw.writeAttribute("Name", defItem.name as string);
if (!utils.isNullOrUndefined(defItem.value)) {
if (!isNullOrUndefined(defItem.value)) {
xw.writeAttribute("Value", coerceInt64ToInt32(defItem.value));
}
_dumpDescription(xw, defItem);
Expand Down
4 changes: 2 additions & 2 deletions packages/node-opcua-address-space/src/reference_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import chalk from "chalk";
import { AddReferenceOpts, UAReference, BaseNode, UAReferenceType } from "node-opcua-address-space-base";
import { assert } from "node-opcua-assert";
import { coerceNodeId, NodeId, NodeIdLike, sameNodeId } from "node-opcua-nodeid";
import * as utils from "node-opcua-utils";
import { isNullOrUndefined } from "node-opcua-utils";

export function isNodeIdString(str: string): boolean {
assert(typeof str === "string");
Expand All @@ -17,7 +17,7 @@ function is_valid_reference(ref: UAReference): boolean {
const hasRequestedProperties =
Object.prototype.hasOwnProperty.call(ref, "referenceType") &&
Object.prototype.hasOwnProperty.call(ref, "nodeId") &&
!utils.isNullOrUndefined(ref.isForward);
!isNullOrUndefined(ref.isForward);

if (!hasRequestedProperties) {
return false;
Expand Down
29 changes: 14 additions & 15 deletions packages/node-opcua-address-space/src/ua_data_type_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import {
import { DataType } from "node-opcua-variant";
import { UAObject, ISessionContext, UADataType, UAVariable, BaseNode } from "node-opcua-address-space-base";
import { DataTypeIds } from "node-opcua-constants";
import { Int64, coerceInt32, coerceInt64, coerceInt64toInt32 } from "node-opcua-basic-types";

import { SessionContext } from "../source/session_context";
import { ExtensionObjectConstructorFuncWithSchema } from "../source/interfaces/extension_object_constructor";
import { BaseNodeImpl, InternalBaseNodeOptions } from "./base_node_impl";
import { BaseNode_References_toString, BaseNode_toString, ToStringBuilder, ToStringOption } from "./base_node_private";
import * as tools from "./tool_isSubtypeOf";
import { construct_isSubtypeOf } from "./tool_isSubtypeOf";
import { get_subtypeOf } from "./tool_isSubtypeOf";
import { get_subtypeOfObj } from "./tool_isSubtypeOf";
import { BaseNode_getCache } from "./base_node_private";
import { Int64, coerceInt32, coerceInt64, coerceInt64toInt32 } from "node-opcua-basic-types";

export interface UADataTypeImpl {
_extensionObjectConstructor: ExtensionObjectConstructorFuncWithSchema;
Expand Down Expand Up @@ -76,8 +76,8 @@ export class UADataTypeImpl extends BaseNodeImpl implements UADataType {
}

/** @deprecated */
public isSupertypeOf = tools.construct_isSubtypeOf<UADataType>(UADataTypeImpl);
public isSubtypeOf = tools.construct_isSubtypeOf<UADataType>(UADataTypeImpl);
public isSupertypeOf = construct_isSubtypeOf<UADataType>(UADataTypeImpl);
public isSubtypeOf = construct_isSubtypeOf<UADataType>(UADataTypeImpl);

public readonly isAbstract: boolean;

Expand Down Expand Up @@ -370,24 +370,24 @@ export function DataType_toString(this: UADataTypeImpl, options: ToStringOption)

options.add(
options.padding +
chalk.yellow(" binaryEncodingNodeId: ") +
(this.binaryEncodingNodeId ? this.binaryEncodingNodeId.toString() : "<none>")
chalk.yellow(" binaryEncodingNodeId: ") +
(this.binaryEncodingNodeId ? this.binaryEncodingNodeId.toString() : "<none>")
);
options.add(
options.padding +
chalk.yellow(" xmlEncodingNodeId : ") +
(this.xmlEncodingNodeId ? this.xmlEncodingNodeId.toString() : "<none>")
chalk.yellow(" xmlEncodingNodeId : ") +
(this.xmlEncodingNodeId ? this.xmlEncodingNodeId.toString() : "<none>")
);
options.add(
options.padding +
chalk.yellow(" jsonEncodingNodeId : ") +
(this.jsonEncodingNodeId ? this.jsonEncodingNodeId.toString() : "<none>")
chalk.yellow(" jsonEncodingNodeId : ") +
(this.jsonEncodingNodeId ? this.jsonEncodingNodeId.toString() : "<none>")
);
if (this.subtypeOfObj) {
options.add(
options.padding +
chalk.yellow(" subtypeOfObj : ") +
(this.subtypeOfObj ? this.subtypeOfObj.browseName.toString() : "")
chalk.yellow(" subtypeOfObj : ") +
(this.subtypeOfObj ? this.subtypeOfObj.browseName.toString() : "")
);
}
// references
Expand All @@ -396,7 +396,6 @@ export function DataType_toString(this: UADataTypeImpl, options: ToStringOption)
dataTypeDefinition_toString.call(this, options);
}


const defaultEnumValue: Int64 = coerceInt64(-1);

function makeEnumDefinition(definitionFields: EnumFieldOptions[]) {
Expand Down Expand Up @@ -424,8 +423,8 @@ function makeStructureDefinition(
const structureType = isUnion
? StructureType.Union
: hasOptionalFields
? StructureType.StructureWithOptionalFields
: StructureType.Structure;
? StructureType.StructureWithOptionalFields
: StructureType.Structure;

const sd = new StructureDefinition({
baseDataType,
Expand Down
12 changes: 6 additions & 6 deletions packages/node-opcua-address-space/src/ua_object_type_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AttributeIds } from "node-opcua-data-model";
import { DataValue, DataValueLike } from "node-opcua-data-value";
import { NodeId } from "node-opcua-nodeid";
import { StatusCodes } from "node-opcua-status-code";
import * as utils from "node-opcua-utils";
import { isNullOrUndefined } from "node-opcua-utils";
import { DataType } from "node-opcua-variant";
import {
AddObjectOptions,
Expand All @@ -21,8 +21,8 @@ import {
import { SessionContext } from "../source/session_context";
import { BaseNodeImpl } from "./base_node_impl";
import { ToStringBuilder, UAObjectType_toString } from "./base_node_private";
import { get_subtypeOf, get_subtypeOfObj } from "./tool_isSubtypeOf";
import * as tools from "./tool_isSubtypeOf";
import { construct_isSubtypeOf, get_subtypeOf, get_subtypeOfObj } from "./tool_isSubtypeOf";
import { } from "./tool_isSubtypeOf";
import {
assertUnusedChildBrowseName,
topMostParentIsObjectTypeOrVariableType
Expand All @@ -49,13 +49,13 @@ export class UAObjectTypeImpl extends BaseNodeImpl implements UAObjectType {
}


public isSubtypeOf = tools.construct_isSubtypeOf<UAObjectType>(UAObjectTypeImpl);
public isSubtypeOf = construct_isSubtypeOf<UAObjectType>(UAObjectTypeImpl);
/** @deprecated - use isSubtypeOf instead */
public isSupertypeOf = tools.construct_isSubtypeOf<UAObjectType>(UAObjectTypeImpl);
public isSupertypeOf = construct_isSubtypeOf<UAObjectType>(UAObjectTypeImpl);

constructor(options: any) {
super(options);
this.isAbstract = utils.isNullOrUndefined(options.isAbstract) ? false : options.isAbstract;
this.isAbstract = isNullOrUndefined(options.isAbstract) ? false : options.isAbstract;
}

public readAttribute(context: ISessionContext, attributeId: AttributeIds): DataValue {
Expand Down

0 comments on commit 874a9c8

Please sign in to comment.