Socket
Socket
Sign inDemoInstall

node-opcua-debug

Package Overview
Dependencies
5
Maintainers
1
Versions
118
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0-alpha.7 to 2.0.0-alpha.8

source/dump_if.d.ts

1

dist/display_trace.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// tslint:disable:no-console
const chalk_1 = require("chalk");

@@ -4,0 +5,0 @@ function trace_from_this_projet_only(err) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// tslint:disable:no-console
const util = require("util");

@@ -4,0 +5,0 @@ function dump(obj) {

2

dist/get_temp_filename.d.ts

@@ -1,1 +0,1 @@

export declare function getTempFilename(tmpfile: string | null): string;
export declare function getTempFilename(tmpFilename: string | null): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require("path");
const fs = require("fs");
function getTempFilename(tmpfile) {
tmpfile = tmpfile || "";
const this_dirname = __dirname;
const temporaryFolder = path.join(this_dirname, '../../../../tmp/');
function getTempFilename(tmpFilename) {
tmpFilename = tmpFilename || "";
const folderOfThisFile = __dirname;
const temporaryFolder = path.join(folderOfThisFile, "../../../../tmp/");
if (!fs.existsSync(temporaryFolder)) {
fs.mkdirSync(temporaryFolder);
}
return path.normalize(path.join(temporaryFolder, tmpfile));
return path.normalize(path.join(temporaryFolder, tmpFilename));
}
exports.getTempFilename = getTempFilename;
//# sourceMappingURL=get_temp_filename.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// tslint:disable:no-var-requires
const hexy = require("hexy");

@@ -10,6 +11,6 @@ function hexDump(buffer, width = 32, maxSize = 1024) {

if (buffer.length > maxSize) {
return hexy.hexy(buffer.slice(0, maxSize), { width: width, format: "twos" }) + "\n .... ( " + buffer.length + ")";
return hexy.hexy(buffer.slice(0, maxSize), { width, format: "twos" }) + "\n .... ( " + buffer.length + ")";
}
else {
return hexy.hexy(buffer, { width: width, format: "twos" });
return hexy.hexy(buffer, { width, format: "twos" });
}

@@ -16,0 +17,0 @@ }

@@ -1,6 +0,6 @@

export declare function setDebugFlag(scriptFullpath: string, flag: boolean): void;
export declare function checkDebugFlag(scriptFullpath: string): boolean;
export declare function setDebugFlag(scriptFullPath: string, flag: boolean): void;
export declare function checkDebugFlag(scriptFullPath: string): boolean;
/**
* @method make_debugLog
* @param scripFullpath:string
* @param scripFullPath:string
* @return returns a debugLog function that will write message to the console

@@ -10,2 +10,2 @@ * if the DEBUG environment variable indicates that the provided source file shall display debug trace

*/
export declare function make_debugLog(scripFullpath: string): (...arg: any[]) => void;
export declare function make_debugLog(scripFullPath: string): (...arg: any[]) => void;

@@ -9,7 +9,9 @@ "use strict";

const debugFlags = {};
const maxLines = (process.env && process.env.NODEOPCUA_DEBUG_MAXLINE_PER_MESSAGE) ?
parseInt(process.env.NODEOPCUA_DEBUG_MAXLINE_PER_MESSAGE, 10) : 25;
function w(str, l) {
return (str + " ").substr(0, l);
}
function setDebugFlag(scriptFullpath, flag) {
const filename = path.basename(scriptFullpath, ".js");
function setDebugFlag(scriptFullPath, flag) {
const filename = path.basename(scriptFullPath, ".js");
if (process.env.DEBUG) {

@@ -22,4 +24,4 @@ const decoratedFilename = chalk_1.default.yellow(w(filename, 30));

exports.setDebugFlag = setDebugFlag;
function checkDebugFlag(scriptFullpath) {
const filename = path.basename(scriptFullpath, ".js");
function checkDebugFlag(scriptFullPath) {
const filename = path.basename(scriptFullPath, ".js");
let doDebug = debugFlags[filename];

@@ -39,3 +41,3 @@ if (process && process.env && process.env.DEBUG && !debugFlags.hasOwnProperty(filename)) {

* @method make_debugLog
* @param scripFullpath:string
* @param scripFullPath:string
* @return returns a debugLog function that will write message to the console

@@ -45,5 +47,5 @@ * if the DEBUG environment variable indicates that the provided source file shall display debug trace

*/
function make_debugLog(scripFullpath) {
const doDebug = checkDebugFlag(scripFullpath);
const filename = path.basename(scripFullpath, ".js");
function make_debugLog(scripFullPath) {
// const doDebug: boolean = checkDebugFlag(scripFullPath);
const filename = path.basename(scripFullPath, ".js");
function debugLogFunc() {

@@ -64,3 +66,3 @@ if (debugFlags[filename]) {

i = i + 1;
if (i > 20) {
if (i > maxLines) {
const a3 = a1.concat([" .... TRUNCATED ....."]);

@@ -67,0 +69,0 @@ console.log.apply(console, a3);

/// <reference types="node" />
export declare function inlineText(f: any): string;
export declare function makebuffer_from_trace(func: any): Buffer;
export declare function makebuffer_from_trace(func: string | Function): Buffer;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_opcua_buffer_utils_1 = require("node-opcua-buffer-utils");
//xx const deprecated_trim = function (str:string):string {
//xx return str.replace(/^\s+|\s+$/g, "");
//xx };
function inlineText(f) {
let k = f.toString().
replace(/^[^\/]+\/\*!?/, '').
replace(/\*\/[^\/]+$/, '');
let k = f.toString().replace(/^[^\/]+\/\*!?/, "").replace(/\*\/[^\/]+$/, "");
k = k.split("\n").map((t) => t.trim()).join("\n");

@@ -17,3 +12,11 @@ return k;

let hexline = "";
const lines = str.split("\n");
let lines = str.split("\n");
if (lines.length === 0) {
return hexline;
}
while (lines.length && lines[0].length === 0) {
lines = lines.splice(1);
}
// find prefix
const prefixLength = lines[0].match(/[0-9a-fA-F:]*\ +/)[0].length;
for (let line of lines) {

@@ -29,6 +32,14 @@ line = line.trim();

}
else if (line.length > prefixLength) {
line = line.substr(prefixLength, prefixLength + 48).trim();
hexline = hexline ? hexline + " " + line : line;
}
}
return hexline;
}
// tslint:disable:ban-types
function makebuffer_from_trace(func) {
if (typeof func === "string") {
return node_opcua_buffer_utils_1.makeBuffer(hexString(func));
}
return node_opcua_buffer_utils_1.makeBuffer(hexString(inlineText(func)));

@@ -35,0 +46,0 @@ }

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

export declare function redirectToFile(tmpfile: string, action_func: Function, callback: Function | null): void;
/**
* @method redirectToFile
* @param tmpFile {String} log file name to redirect console output.
* @param actionFct the inner function to execute
* @param callback
*/
export declare function redirectToFile(tmpFile: string, actionFct: Function, callback: ((err?: Error) => void) | null): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// tslint:disable:no-console
// tslint:disable:ban-types
const fs = require("fs");
const _ = require("underscore");
const fs = require("fs");
const util = require("util");
const node_opcua_assert_1 = require("node-opcua-assert");
const get_temp_filename_1 = require("./get_temp_filename");
function redirectToFile(tmpfile, action_func, callback) {
let old_console_log;
node_opcua_assert_1.assert(_.isFunction(action_func));
/**
* @method redirectToFile
* @param tmpFile {String} log file name to redirect console output.
* @param actionFct the inner function to execute
* @param callback
*/
function redirectToFile(tmpFile, actionFct, callback) {
let oldConsoleLog;
node_opcua_assert_1.assert(_.isFunction(actionFct));
node_opcua_assert_1.assert(!callback || _.isFunction(callback));
const is_async = action_func && action_func.length;
const log_file = get_temp_filename_1.getTempFilename(tmpfile);
//xx console.log(" log_file ",log_file);
const f = fs.createWriteStream(log_file, { flags: "w", encoding: "ascii" });
function _write_to_file(d) {
//
const msg = util.format.apply(null, arguments);
const isAsync = actionFct && actionFct.length;
const logFile = get_temp_filename_1.getTempFilename(tmpFile);
// xx console.log(" log_file ",log_file);
const f = fs.createWriteStream(logFile, { flags: "w", encoding: "ascii" });
function _write_to_file(...args) {
const msg = util.format.apply(null, args);
f.write(msg + "\n");
if (process.env.DEBUG) {
old_console_log.call(console, msg);
oldConsoleLog.call(console, msg);
}
}
if (!is_async) {
old_console_log = console.log;
if (!isAsync) {
oldConsoleLog = console.log;
console.log = _write_to_file;
// async version
try {
action_func();
actionFct();
}
catch (err) {
console.log = old_console_log;
console.log = oldConsoleLog;
console.log("redirectToFile has intercepted an error :", err);
// we don't want the callback anymore since we got an error
// display file on screen for insvestigation
console.log(fs.readFileSync(log_file).toString("ascii"));
f.end(function () {
callback && callback(err);
// display file on screen for investigation
console.log(fs.readFileSync(logFile).toString("ascii"));
f.end(() => {
if (callback) {
callback(err);
}
});
}
console.log = old_console_log;
console.log = oldConsoleLog;
f.end(callback);
}
else {
old_console_log = console.log;
oldConsoleLog = console.log;
console.log = _write_to_file;
// async version
action_func(function (err) {
actionFct((err) => {
node_opcua_assert_1.assert(_.isFunction(callback));
console.log = old_console_log;
console.log = oldConsoleLog;
if (err) {

@@ -52,0 +61,0 @@ console.log("redirectToFile has intercepted an error");

{
"name": "node-opcua-debug",
"version": "2.0.0-alpha.7",
"version": "2.0.0-alpha.8",
"description": "pure nodejs OPCUA SDK - module -debug",

@@ -12,4 +12,4 @@ "scripts": {

"hexy": "^0.3.0",
"node-opcua-assert": "^2.0.0-alpha.7",
"node-opcua-buffer-utils": "^2.0.0-alpha.7",
"node-opcua-assert": "^2.0.0-alpha.8",
"node-opcua-buffer-utils": "^2.0.0-alpha.8",
"underscore": "^1.9.1"

@@ -38,3 +38,3 @@ },

"homepage": "http://node-opcua.github.io/",
"gitHead": "af4f00cca7a45563e759c88afa21bba73152dd03"
"gitHead": "7bbf38d5a3cd29cb6aed6ca38078f4d89d3f956a"
}

@@ -0,1 +1,2 @@

// tslint:disable:no-console
import chalk from "chalk";

@@ -13,3 +14,4 @@

if (stack) {
stack = stack.split("\n").filter((el:string) => el.match(/node-opcua/) && !el.match(/node_modules/));
stack = stack.split("\n").filter((el: string) =>
el.match(/node-opcua/) && !el.match(/node_modules/));
str.push(chalk.yellow(stack.join("\n")));

@@ -22,5 +24,4 @@ } else {

export function display_trace_from_this_projet_only(err?: Error): void {
console.log(trace_from_this_projet_only(err));
}

@@ -1,2 +0,3 @@

const util = require("util");
// tslint:disable:no-console
import * as util from "util";

@@ -3,0 +4,0 @@ export function dump(obj: any) {

@@ -1,15 +0,12 @@

const path = require("path");
const fs = require("fs");
import * as fs from "fs";
import * as path from "path";
export function getTempFilename(tmpfile:string|null):string {
tmpfile = tmpfile || "";
const this_dirname = __dirname;
const temporaryFolder = path.join(this_dirname, '../../../../tmp/');
export function getTempFilename(tmpFilename: string | null): string {
tmpFilename = tmpFilename || "";
const folderOfThisFile = __dirname;
const temporaryFolder = path.join(folderOfThisFile, "../../../../tmp/");
if (!fs.existsSync(temporaryFolder)) {
fs.mkdirSync(temporaryFolder);
}
return path.normalize(path.join(temporaryFolder,tmpfile));
return path.normalize(path.join(temporaryFolder, tmpFilename!));
}

@@ -0,1 +1,2 @@

// tslint:disable:no-var-requires
const hexy = require("hexy");

@@ -8,6 +9,6 @@ export function hexDump(buffer: Buffer | null, width: number = 32, maxSize: number = 1024) {

if (buffer.length > maxSize) {
return hexy.hexy(buffer.slice(0, maxSize), { width: width, format: "twos" }) + "\n .... ( " + buffer.length + ")";
return hexy.hexy(buffer.slice(0, maxSize), { width, format: "twos" }) + "\n .... ( " + buffer.length + ")";
} else {
return hexy.hexy(buffer, { width: width, format: "twos" });
return hexy.hexy(buffer, { width, format: "twos" });
}
}

@@ -9,2 +9,5 @@ // tslint:disable:no-console

const maxLines = (process.env && process.env.NODEOPCUA_DEBUG_MAXLINE_PER_MESSAGE) ?
parseInt(process.env.NODEOPCUA_DEBUG_MAXLINE_PER_MESSAGE , 10) : 25;
function w(str: string, l: number): string {

@@ -14,4 +17,4 @@ return (str + " ").substr(0, l);

export function setDebugFlag(scriptFullpath: string, flag: boolean) {
const filename: string = path.basename(scriptFullpath, ".js");
export function setDebugFlag(scriptFullPath: string, flag: boolean) {
const filename: string = path.basename(scriptFullPath, ".js");
if (process.env.DEBUG) {

@@ -29,4 +32,4 @@ const decoratedFilename = chalk.yellow(w(filename, 30));

export function checkDebugFlag(scriptFullpath: string): boolean {
const filename = path.basename(scriptFullpath, ".js");
export function checkDebugFlag(scriptFullPath: string): boolean {
const filename = path.basename(scriptFullPath, ".js");
let doDebug: boolean = debugFlags[filename];

@@ -47,3 +50,3 @@ if (process && process.env && process.env.DEBUG && !debugFlags.hasOwnProperty(filename)) {

* @method make_debugLog
* @param scripFullpath:string
* @param scripFullPath:string
* @return returns a debugLog function that will write message to the console

@@ -53,7 +56,7 @@ * if the DEBUG environment variable indicates that the provided source file shall display debug trace

*/
export function make_debugLog(scripFullpath: string): (...arg: any[]) => void {
export function make_debugLog(scripFullPath: string): (...arg: any[]) => void {
const doDebug: boolean = checkDebugFlag(scripFullpath);
// const doDebug: boolean = checkDebugFlag(scripFullPath);
const filename: string = path.basename(scripFullpath, ".js");
const filename: string = path.basename(scripFullPath, ".js");

@@ -68,13 +71,13 @@ function debugLogFunc() {

const a2: string[] = _.values(arguments);
const a2 = _.values(arguments) as [string, ...string[]];
const output = format.apply(null, a2 as [string, ...string[]]);
const output = format.apply(null, a2);
let i = 0;
for (const line of output.split("\n")) {
const args: string[] = ([] as string[]).concat(a1, [line]);
console.log.apply(console, args as [string, ...string[]]);
const args = ([] as string[]).concat(a1, [line]) as [string, ...string[]];
console.log.apply(console, args );
a1 = [w(" ... ", 51)];
i = i + 1;
if (i > 20) {
if (i > maxLines) {
const a3 = a1.concat([" .... TRUNCATED ....."]);

@@ -81,0 +84,0 @@ console.log.apply(console, a3 as [string, ...string[]]);

import { makeBuffer } from "node-opcua-buffer-utils";
//xx const deprecated_trim = function (str:string):string {
//xx return str.replace(/^\s+|\s+$/g, "");
//xx };
export function inlineText(f:any):string {
let k = f.toString().
replace(/^[^\/]+\/\*!?/, '').
replace(/\*\/[^\/]+$/, '');
k = k.split("\n").map((t:string)=> t.trim()).join("\n");
export function inlineText(f: any): string {
let k = f.toString().replace(/^[^\/]+\/\*!?/, "").replace(/\*\/[^\/]+$/, "");
k = k.split("\n").map((t: string) => t.trim()).join("\n");
return k;
}
function hexString(str:string):string {
function hexString(str: string): string {
let hexline:string = "";
const lines = str.split("\n");
let hexline: string = "";
let lines = str.split("\n");
if (lines.length === 0) {
return hexline;
}
while (lines.length && lines[0]!.length === 0) {
lines = lines.splice(1);
}
// find prefix
const prefixLength = lines[0]!.match(/[0-9a-fA-F:]*\ +/)![0].length;
for (let line of lines) {

@@ -27,2 +30,5 @@ line = line.trim();

hexline = hexline ? hexline + " " + line : line;
} else if (line.length > prefixLength) {
line = line.substr(prefixLength, prefixLength + 48).trim();
hexline = hexline ? hexline + " " + line : line;
}

@@ -33,4 +39,8 @@ }

export function makebuffer_from_trace(func:any):Buffer {
// tslint:disable:ban-types
export function makebuffer_from_trace(func: string | Function): Buffer {
if (typeof func === "string") {
return makeBuffer(hexString(func as string));
}
return makeBuffer(hexString(inlineText(func)));
}

@@ -1,4 +0,6 @@

const _ = require("underscore");
const fs = require("fs");
const util = require("util");
// tslint:disable:no-console
// tslint:disable:ban-types
import * as fs from "fs";
import * as _ from "underscore";
import * as util from "util";

@@ -10,34 +12,35 @@ import { assert } from "node-opcua-assert";

* @method redirectToFile
* @param tmpfile {String} log file name to redirect console output.
* @param action_func {Function} - the inner function to execute
* @param tmpFile {String} log file name to redirect console output.
* @param actionFct the inner function to execute
* @param callback
*/
declare function LogFunc(message: any): void;
export function redirectToFile(
tmpFile: string,
actionFct: Function,
callback: ((err?: Error) => void) | null
): void {
export function redirectToFile(tmpfile: string, action_func: Function, callback: Function | null): void {
let old_console_log: any;
let oldConsoleLog: any;
assert(_.isFunction(action_func));
assert(_.isFunction(actionFct));
assert(!callback || _.isFunction(callback));
const is_async = action_func && action_func.length;
const isAsync = actionFct && actionFct.length;
const log_file = getTempFilename(tmpfile);
const logFile = getTempFilename(tmpFile);
//xx console.log(" log_file ",log_file);
const f = fs.createWriteStream(log_file, { flags: "w", encoding: "ascii" });
// xx console.log(" log_file ",log_file);
const f = fs.createWriteStream(logFile, { flags: "w", encoding: "ascii" });
function _write_to_file(d: string) {
//
function _write_to_file(...args: [any, ...any[]]) {
const msg = util.format.apply(null, arguments);
const msg = util.format.apply(null, args);
f.write(msg + "\n");
if (process.env.DEBUG) {
old_console_log.call(console, msg);
oldConsoleLog.call(console, msg);
}
}
if (!is_async) {
old_console_log = console.log;
if (!isAsync) {
oldConsoleLog = console.log;

@@ -48,20 +51,22 @@ console.log = _write_to_file;

try {
action_func();
actionFct();
} catch (err) {
console.log = old_console_log;
console.log = oldConsoleLog;
console.log("redirectToFile has intercepted an error :", err);
// we don't want the callback anymore since we got an error
// display file on screen for insvestigation
// display file on screen for investigation
console.log(fs.readFileSync(log_file).toString("ascii"));
console.log(fs.readFileSync(logFile).toString("ascii"));
f.end(function() {
callback && callback(err);
f.end(() => {
if (callback) {
callback(err);
}
});
}
console.log = old_console_log;
console.log = oldConsoleLog;
f.end(callback);
} else {
old_console_log = console.log;
oldConsoleLog = console.log;
console.log = _write_to_file;

@@ -71,5 +76,5 @@

action_func(function(err: Error) {
actionFct((err: Error) => {
assert(_.isFunction(callback));
console.log = old_console_log;
console.log = oldConsoleLog;
if (err) {

@@ -76,0 +81,0 @@ console.log("redirectToFile has intercepted an error");

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

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc