Skip to content

Commit

Permalink
chore: remove use of console.log #1279
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Jun 10, 2023
1 parent b542b87 commit 65deea0
Show file tree
Hide file tree
Showing 37 changed files with 219 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { getMiniAddressSpace } from "node-opcua-address-space/testHelpers";
import { ObjectIds, DataTypeIds, ReferenceTypeIds } from "node-opcua-constants";
import { BrowseDirection, NodeClass } from "node-opcua-data-model";
import { makeNodeId, NodeId, resolveNodeId } from "node-opcua-nodeid";
import {
DataType,
ReferenceDescription} from "node-opcua-client";
import { DataType, ReferenceDescription } from "node-opcua-client";
import { checkDebugFlag, make_debugLog } from "node-opcua-debug";

import { CacheNode, NodeCrawlerBase, UserData } from "..";
Expand Down Expand Up @@ -115,7 +113,6 @@ describe("NodeCrawlerBase", function (this: any) {
// }
}


it("CRAWL1 should crawl on a PseudoSession", async () => {
const session = new PseudoSession($.addressSpace);

Expand All @@ -138,21 +135,21 @@ describe("NodeCrawlerBase", function (this: any) {
.join(" ")
.should.eql(
"HasComponent HasProperty " +
"LocaleIdArray " +
"MaxMonitoredItemsPerCall " +
"MaxNodesPerBrowse " +
"MaxNodesPerHistoryReadData " +
"MaxNodesPerHistoryReadEvents " +
"MaxNodesPerHistoryUpdateData " +
"MaxNodesPerHistoryUpdateEvents " +
"MaxNodesPerMethodCall " +
"MaxNodesPerNodeManagement " +
"MaxNodesPerRead " +
"MaxNodesPerRegisterNodes " +
"MaxNodesPerTranslateBrowsePathsToNodeIds " +
"MaxNodesPerWrite " +
"OperationLimits " +
"ServerCapabilities"
"LocaleIdArray " +
"MaxMonitoredItemsPerCall " +
"MaxNodesPerBrowse " +
"MaxNodesPerHistoryReadData " +
"MaxNodesPerHistoryReadEvents " +
"MaxNodesPerHistoryUpdateData " +
"MaxNodesPerHistoryUpdateEvents " +
"MaxNodesPerMethodCall " +
"MaxNodesPerNodeManagement " +
"MaxNodesPerRead " +
"MaxNodesPerRegisterNodes " +
"MaxNodesPerTranslateBrowsePathsToNodeIds " +
"MaxNodesPerWrite " +
"OperationLimits " +
"ServerCapabilities"
);

crawler.dispose();
Expand Down Expand Up @@ -184,9 +181,9 @@ describe("NodeCrawlerBase", function (this: any) {
.join(" ")
.should.eql(
"1:Group 1:Object0 1:Object1 " +
"1:Object2 1:Object3 1:Object4 " +
"1:Object5 1:Object6 1:Object7 " +
"1:Object8 1:Object9 Organizes"
"1:Object2 1:Object3 1:Object4 " +
"1:Object5 1:Object6 1:Object7 " +
"1:Object8 1:Object9 Organizes"
);

// tslint:disable: no-console
Expand Down Expand Up @@ -436,7 +433,7 @@ describe("NodeCrawlerBase", function (this: any) {
(session as any).browse = sinon.spy(session, "browse");
(session as any).browseNext = sinon.spy(session, "browseNext");
(session as any).read = sinon.spy(session, "read");

const crawler = new NodeCrawlerBase(session);

const results: { browseName: string; nodeClass: string; nodeId: NodeId; references: ReferenceDescription[] }[] = [];
Expand All @@ -456,8 +453,6 @@ describe("NodeCrawlerBase", function (this: any) {
crawler.maxNodesPerRead = 100;
session.requestedMaxReferencesPerNode = 10;
await crawler.crawl($.strangeObjectNodeId, data);

console.log("Here !");
crawler.dispose();
for (const r of results) {
// console.log(r.browseName.toString(), r.nodeId.toString(), r.references.length);
Expand All @@ -467,6 +462,5 @@ describe("NodeCrawlerBase", function (this: any) {
console.log("read ", (session as any).read.callCount);
console.log("browse ", (session as any).browse.callCount);
console.log("browseNext", (session as any).browseNext.callCount);

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function findSuperType(session: IBasicSession, dataTypeNodeId: NodeId): Pr

/* istanbul ignore next */
if (result3.references.length !== 1) {
console.log(result3.toString());
errorLog("Invalid dataType with more than one (or 0) superType", result3.toString());
throw new Error(
"Invalid dataType with more than one (or 0) superType " + dataTypeNodeId.toString() + " l=" + result3.references.length
);
Expand Down Expand Up @@ -391,7 +391,6 @@ export async function convertDataTypeDefinitionToStructureTypeSchema(

switch (definition.structureType) {
case StructureType.Union:
// xx console.log("Union Found : ", name);
fields.push({
fieldType: "UInt32",
name: "SwitchField"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ async function serverImplementsDataTypeDefinition(session: IBasicSession): Promi

const dataValues = await session.read(nodesToRead);

// for (let i = 0; i < dataValues.length; i++) {
// console.log(i, " | ", nodesToRead[i].nodeId.toString().padEnd(40), references[i].browseName.toString().padEnd(50), dataValues[i].statusCode.toString());
// }

const countOK = dataValues.reduce((prev, a) => prev + (a.statusCode.isGood() ? 1 : 0), 0);
if (countOK === dataValues.length) {
return true;
Expand All @@ -71,13 +67,9 @@ async function serverImplementsDataTypeDefinition(session: IBasicSession): Promi
return false;
}

export async function populateDataTypeManager(
session: IBasicSession,
dataTypeManager: ExtraDataTypeManager,
): Promise<void> {
export async function populateDataTypeManager(session: IBasicSession, dataTypeManager: ExtraDataTypeManager): Promise<void> {
const force104 = await serverImplementsDataTypeDefinition(session);
if (force104) {
// console.log("xxxxxxx! using 1.04");
await populateDataTypeManager104(session, dataTypeManager);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export async function _findEncodings(session: IBasicSession, dataTypeNodeId: Nod
encodings.jsonEncodingNodeId = ref.nodeId;
break;
default:
console.log(" ignoring encoding ", ref.browseName.toString());
// warningLog(" ignoring encoding ", ref.browseName.toString());
break;
}
}
return encodings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ async function _enrichWithDescriptionOf(session: IBasicSession, dataTypeDescript
const binaryEncodings = [];
const nodesToBrowseDataType: BrowseDescriptionOptions[] = [];

for (let i=0;i< results3.length;i++) {

for (let i = 0; i < results3.length; i++) {
const result3 = results3[i];
const dataTypeDescription = dataTypeDescriptions[i];

Expand All @@ -135,7 +134,7 @@ async function _enrichWithDescriptionOf(session: IBasicSession, dataTypeDescript
}
if (result3.references.length !== 1) {
warningLog("_enrichWithDescriptionOf : expecting 1 reference for ", dataTypeDescription.browseName.toString());
warningLog(result3.toString());
warningLog(result3.toString());
continue;
}
for (const ref of result3.references) {
Expand Down Expand Up @@ -164,9 +163,8 @@ async function _enrichWithDescriptionOf(session: IBasicSession, dataTypeDescript

if (nodesToBrowseDataType.length > 0) {
const results4 = await browseAll(session, nodesToBrowseDataType);
for (let i=0;i< results4.length; i++) {

const result4 =results4[i];
for (let i = 0; i < results4.length; i++) {
const result4 = results4[i];
result4.references = result4.references || [];

/* istanbul ignore next */
Expand All @@ -176,13 +174,13 @@ async function _enrichWithDescriptionOf(session: IBasicSession, dataTypeDescript

const ref = result4.references![0];
const dataTypeNodeId = ref.nodeId;
dataTypeNodeIds[i]= dataTypeNodeId;
dataTypeNodeIds[i] = dataTypeNodeId;
const dataTypeDescription = dataTypeDescriptions[i];
dataTypeDescription.encodings!.dataTypeNodeId = dataTypeNodeId;
}
}

const otherEncodingBrowse = dataTypeNodeIds.map((dataTypeNodeId)=>({
const otherEncodingBrowse = dataTypeNodeIds.map((dataTypeNodeId) => ({
browseDirection: BrowseDirection.Forward,
includeSubtypes: false,
nodeClassMask: NodeClassMask.Object,
Expand All @@ -193,11 +191,11 @@ async function _enrichWithDescriptionOf(session: IBasicSession, dataTypeDescript
}));

const results5 = await browseAll(session, otherEncodingBrowse);
for (let i=0;i<results5.length;i++) {
const result5= results5[i];
for (let i = 0; i < results5.length; i++) {
const result5 = results5[i];
const dataTypeDescription = dataTypeDescriptions[i];
for (const ref of result5.references || []) {
switch(ref.browseName.name) {
switch (ref.browseName.name) {
case "Default XML":
dataTypeDescription.encodings!.xmlEncodingNodeId = ref.nodeId;
break;
Expand All @@ -209,7 +207,7 @@ async function _enrichWithDescriptionOf(session: IBasicSession, dataTypeDescript
break;
default:
errorLog("Cannot handle unknown encoding", ref.browseName.name);
}
}
}
}
return dataTypeNodeIds;
Expand Down Expand Up @@ -338,9 +336,9 @@ async function _extractDataTypeDictionaryFromDefinition(
const Constructor = createDynamicObjectConstructor(schema, dataTypeFactory) as unknown as ConstructorFuncWithSchema;
assert(Constructor.schema === schema);
} catch (err) {
console.log("Constructor verification err: ", (<Error>err).message);
console.log("For this reason class " + className + " has not been registered");
console.log(err);
errorLog("Constructor verification err: ", (<Error>err).message);
errorLog("For this reason class " + className + " has not been registered");
errorLog(err);
}
}
}
Expand Down Expand Up @@ -379,7 +377,7 @@ interface TypeDictionaryInfo {
function _isOldDataTypeDictionary(d: TypeDictionaryInfo) {
const isDictionaryDeprecated = d.isDictionaryDeprecated; // await _readDeprecatedFlag(session, dataTypeDictionaryNodeId);
const rawSchema = d.rawSchema; // DataValue = await session.read({ nodeId: dataTypeDictionaryNodeId, attributeId: AttributeIds.Value });
return !isDictionaryDeprecated && rawSchema.length >=0;
return !isDictionaryDeprecated && rawSchema.length >= 0;
}
async function _extractDataTypeDictionary(
session: IBasicSession,
Expand Down Expand Up @@ -472,7 +470,7 @@ async function _exploreDataTypeDefinition(

/* istanbul ignore next */
if (doDebug) {
console.log(chalk.bgWhite.red("testing new constructors"));
debugLog(chalk.bgWhite.red("testing new constructors"));
for (let i = 0; i < references.length; i++) {
const ref = references[i];
const binaryEncoding = binaryEncodingNodeIds[i];
Expand Down Expand Up @@ -620,7 +618,7 @@ export async function populateDataTypeManager103(session: IBasicSession, dataTyp

if (!isDictionaryDeprecated && rawSchema.length > 0) {
if (doDebug) {
console.log("schema", rawSchema);
debugLog("schema", rawSchema);
}
const matches = rawSchema.match(/<opc:TypeDictionary([^>]+)>/);
if (matches) {
Expand Down Expand Up @@ -703,7 +701,6 @@ export async function populateDataTypeManager103(session: IBasicSession, dataTyp
}
const baseDataFactory = map[namespace];
if (!baseDataFactory) {
// xx console.log("xxxxx baseDataFactory = ", namespace);
continue;
}
const namespaceIndex = baseDataFactory.dataTypeDictionaryNodeId.namespace;
Expand Down Expand Up @@ -750,7 +747,6 @@ export async function populateDataTypeManager103(session: IBasicSession, dataTyp
for (const d of dataTypeDictionaryInfo) {
try {
await processReferenceOnDataTypeDictionaryType(d).catch((e) => {
console.log(e);
debugLog("processReferenceOnDataTypeDictionaryType has failed ");
debugLog("Error", e.message);
debugLog(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async function applyOnReferenceRecursively(
browseDescriptionTemplate: BrowseDescriptionOptions,
action: (ref: ReferenceDescription) => Promise<void>
): Promise<void> {
const taskMananager = new TaskMan();
const taskManager = new TaskMan();

let pendingNodesToBrowse: BrowseDescriptionOptions[] = [];

Expand All @@ -152,7 +152,7 @@ async function applyOnReferenceRecursively(
for (const r of result.references || []) {
// also explore sub types
browseSubDataTypeRecursively(r.nodeId);
taskMananager.registerTask(async () => await action(r));
taskManager.registerTask(async () => await action(r));
}
} else {
errorLog(
Expand All @@ -168,9 +168,8 @@ async function applyOnReferenceRecursively(
if (pendingNodesToBrowse.length) {
const nodesToBrowse = pendingNodesToBrowse;
pendingNodesToBrowse = [];
taskMananager.registerTask(async () => {
taskManager.registerTask(async () => {
try {
// YY console.log(" reading ", nodesToBrowse.length);
const browseResults = await browseAll(session, nodesToBrowse);
processBrowseResults(nodesToBrowse, browseResults);
} catch (err) {
Expand All @@ -187,10 +186,10 @@ async function applyOnReferenceRecursively(
nodeId
};
pendingNodesToBrowse.push(nodeToBrowse);
taskMananager.registerTask(async () => flushBrowse());
taskManager.registerTask(async () => flushBrowse());
}
browseSubDataTypeRecursively(nodeId);
await taskMananager.waitForCompletion();
await taskManager.waitForCompletion();
}
export async function populateDataTypeManager104(session: IBasicSession, dataTypeManager: ExtraDataTypeManager): Promise<void> {
const cache: { [key: string]: CacheForFieldResolution } = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ async function getOrExtractConstructor(
binaryEncodingNodeId: NodeId,
dataTypeManager: ExtraDataTypeManager
): Promise<ConstructorFunc> {

const dataTypeFactory = dataTypeManager.getDataTypeFactoryForNamespace(binaryEncodingNodeId.namespace);


const Constructor = dataTypeFactory.getConstructor(binaryEncodingNodeId);
if (Constructor) {
return Constructor;
Expand Down Expand Up @@ -89,7 +87,6 @@ export async function resolveOpaqueStructureInExtentionObject(
if (field.category === "basic" && field.fieldType !== "Variant") {
return;
}
console.log("field", field.name, field.category, field.fieldType);
const a = object[field.name];
if (!a) {
return;
Expand All @@ -116,26 +113,6 @@ export async function resolveOpaqueStructureInExtentionObject(
await Promise.all(promises);
}

// async function resolveInnerVariantType(session: IBasicSession, object: ExtensionObject, dataTypeManager: ExtraDataTypeManager) {
// console.log("object = ", object.constructor.name);

// const fields = object.schema.fields;
// const _object = object as unknown as Record<string, unknown>;
// for (const field of fields) {
// console.log("field = ", field.name);
// if (field.category !== "complex") continue;
// const p = _object[field.name];
// if (p === undefined || p === null) continue;
// console.log("=>", field.name, (p as any).toString());
// if (p instanceof ExtensionObject) {
// resolveInnerVariantType(session, p, dataTypeManager);
// }
// if (p instanceof Variant && p.value instanceof OpaqueStructure) {
// console.log("§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§");
// p.value = resolveDynamicExtensionObjectV(session, p.value, dataTypeManager);
// }
// }
// }
async function resolveDynamicExtensionObjectV(
session: IBasicSession,
opaque: OpaqueStructure,
Expand Down

0 comments on commit 65deea0

Please sign in to comment.