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

timer-logs

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timer-logs - npm Package Compare versions

Comparing version 1.7.5 to 2.0.0

8

dist/index.d.ts

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

import { PostgresError } from "./types/dataStructures/Errors";
import { Config } from "./types/dataStructures/Config";
import { Severity } from "./types/enums/Severity";
export default class Timer {
import type { PostgresError } from "./types/dataStructures/Errors";
import type { Config } from "./types/dataStructures/Config.js";
import { Severity } from "./types/enums/Severity.js";
export declare class Timer {
private readonly startTime;

@@ -6,0 +6,0 @@ private finishTime?;

@@ -1,11 +0,9 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const crypto = require("crypto");
const Environment_1 = require("./types/enums/Environment");
const Severity_1 = require("./types/enums/Severity");
const BrowserPresenter_1 = require("./src/presenters/BrowserPresenter");
const DevelopmentPresenter_1 = require("./src/presenters/DevelopmentPresenter");
const ProductionPresenter_1 = require("./src/presenters/ProductionPresenter");
const sqlPresenter_1 = require("./src/presenters/sqlPresenter");
class Timer {
import * as crypto from "crypto";
import { Environment } from "./types/enums/Environment.js";
import { Severity } from "./types/enums/Severity.js";
import { BrowserPresenter } from "./src/presenters/BrowserPresenter.js";
import { DevelopmentPresenter } from "./src/presenters/DevelopmentPresenter.js";
import { ProductionPresenter } from "./src/presenters/ProductionPresenter.js";
import { PresentSql, valueToString } from "./src/presenters/sqlPresenter.js";
export class Timer {
constructor(config) {

@@ -23,3 +21,3 @@ var _a, _b, _c, _d, _e, _f, _g, _h, _j;

this.omitStackTrace = (_e = config.omitStackTrace) !== null && _e !== void 0 ? _e : false;
this._severity = Severity_1.Severity[(_f = config.severity) !== null && _f !== void 0 ? _f : Severity_1.Severity.DEFAULT];
this._severity = Severity[(_f = config.severity) !== null && _f !== void 0 ? _f : Severity.DEFAULT];
this.uniqueId = crypto.randomBytes(8).toString("hex");

@@ -29,3 +27,3 @@ this.start("operationTime");

if (typeof window !== "undefined")
this.environment = Environment_1.Environment.BROWSER;
this.environment = Environment.BROWSER;
else {

@@ -35,13 +33,13 @@ const coalescedEnv = (_j = (_h = (_g = config.environment) !== null && _g !== void 0 ? _g : process.env.LOGGING_ENV) !== null && _h !== void 0 ? _h : process.env.NODE_ENV) !== null && _j !== void 0 ? _j : "production";

case "browser":
this.environment = Environment_1.Environment.BROWSER;
this.environment = Environment.BROWSER;
break;
case "development":
this.environment = Environment_1.Environment.DEVELOPMENT;
this.environment = Environment.DEVELOPMENT;
break;
case "production":
this.environment = Environment_1.Environment.PRODUCTION;
this.environment = Environment.PRODUCTION;
break;
default:
console.log(`Invalid logging environment '${coalescedEnv}', using 'production' instead.`);
this.environment = Environment_1.Environment.PRODUCTION;
this.environment = Environment.PRODUCTION;
break;

@@ -121,3 +119,3 @@ }

.join(" ");
this.printLog(new Map([["message", concatenatedMessage]]), Severity_1.Severity.INFO);
this.printLog(new Map([["message", concatenatedMessage]]), Severity.INFO);
}

@@ -128,3 +126,3 @@ warn(message, ...messages) {

.join(" ");
this.printLog(new Map([["message", concatenatedMessage]]), Severity_1.Severity.WARNING);
this.printLog(new Map([["message", concatenatedMessage]]), Severity.WARNING);
}

@@ -135,11 +133,11 @@ alert(message, ...messages) {

.join(" ");
this.printLog(new Map([["message", concatenatedMessage]]), Severity_1.Severity.ALERT);
this.printLog(new Map([["message", concatenatedMessage]]), Severity.ALERT);
}
tlog(strings, ...values) {
const message = strings
.flatMap((s, i) => [s, i < values.length && (0, sqlPresenter_1.valueToString)(values[i])].filter((s) => s))
.flatMap((s, i) => [s, i < values.length && valueToString(values[i])].filter((s) => s))
.join("");
this.printLog(new Map(Object.entries({
message,
})), Severity_1.Severity.INFO);
})), Severity.INFO);
}

@@ -150,6 +148,6 @@ tsql(strings, ...values) {

: `${query} ${phrase}`, "");
if (this.environment === Environment_1.Environment.DEVELOPMENT) {
if (this.environment === Environment.DEVELOPMENT) {
const logMap = new Map();
logMap.set("message", (0, sqlPresenter_1.PresentSql)(queryText, values));
this.printLog(logMap, Severity_1.Severity.DEBUG);
logMap.set("message", PresentSql(queryText, values));
this.printLog(logMap, Severity.DEBUG);
}

@@ -159,3 +157,3 @@ }

const errorDetails = new Map(Object.entries({ message }));
this.printLog(errorDetails, Severity_1.Severity.ERROR);
this.printLog(errorDetails, Severity.ERROR);
}

@@ -192,3 +190,3 @@ postgresError(e) {

}
this.printLog(errorDetails, Severity_1.Severity.ERROR);
this.printLog(errorDetails, Severity.ERROR);
}

@@ -201,13 +199,13 @@ genericErrorCustomMessage(message) {

switch (this.environment) {
case Environment_1.Environment.BROWSER:
logPresenter = BrowserPresenter_1.BrowserPresenter;
case Environment.BROWSER:
logPresenter = BrowserPresenter;
break;
case Environment_1.Environment.DEVELOPMENT:
logPresenter = DevelopmentPresenter_1.DevelopmentPresenter;
case Environment.DEVELOPMENT:
logPresenter = DevelopmentPresenter;
break;
case Environment_1.Environment.PRODUCTION:
logPresenter = ProductionPresenter_1.ProductionPresenter;
case Environment.PRODUCTION:
logPresenter = ProductionPresenter;
break;
default:
logPresenter = ProductionPresenter_1.ProductionPresenter;
logPresenter = ProductionPresenter;
break;

@@ -222,3 +220,3 @@ }

errorDetails.set("databaseType", "postgres");
this.printLog(errorDetails, Severity_1.Severity.ERROR);
this.printLog(errorDetails, Severity.ERROR);
return returnVal;

@@ -250,2 +248,1 @@ }

}
exports.default = Timer;

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

import { LogPresenter } from "../../types/interfaces/LogPresenter";
import type { LogPresenter } from "../../types/interfaces/LogPresenter";
/**

@@ -3,0 +3,0 @@ * Logging optimised for the browser dev tools console.

@@ -1,27 +0,24 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BrowserPresenter = void 0;
const Severity_1 = require("../../types/enums/Severity");
const BrowserPresenter = (log) => {
import { Severity } from "../../types/enums/Severity.js";
export const BrowserPresenter = (log) => {
var _a;
const logString = JSON.stringify(log);
const severity = (_a = log.severity) !== null && _a !== void 0 ? _a : Severity_1.Severity.DEFAULT;
const severity = (_a = log.severity) !== null && _a !== void 0 ? _a : Severity.DEFAULT;
switch (severity) {
case Severity_1.Severity.DEBUG:
case Severity.DEBUG:
console.debug(logString);
break;
case Severity_1.Severity.DEFAULT:
case Severity.DEFAULT:
console.log(logString);
break;
case Severity_1.Severity.INFO:
case Severity_1.Severity.NOTICE:
case Severity.INFO:
case Severity.NOTICE:
console.info(logString);
break;
case Severity_1.Severity.WARNING:
case Severity.WARNING:
console.warn(logString);
break;
case Severity_1.Severity.ERROR:
case Severity_1.Severity.CRITICAL:
case Severity_1.Severity.ALERT:
case Severity_1.Severity.EMERGENCY:
case Severity.ERROR:
case Severity.CRITICAL:
case Severity.ALERT:
case Severity.EMERGENCY:
console.error(logString);

@@ -34,2 +31,1 @@ break;

};
exports.BrowserPresenter = BrowserPresenter;

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

import { ColourConverter } from "../../../types/interfaces/ColourConverter";
import { ColourConverter } from "../../../types/interfaces/ColourConverter.js";
export declare const red: ColourConverter;

@@ -3,0 +3,0 @@ export declare const pink: ColourConverter;

@@ -1,45 +0,32 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.colourTable = exports.rgb = exports.wrap = exports.lightBlue = exports.yellow = exports.green = exports.blue = exports.purple = exports.orange = exports.pink = exports.red = void 0;
const red = (message) => {
return wrap(message, exports.colourTable["red"]);
export const red = (message) => {
return wrap(message, colourTable["red"]);
};
exports.red = red;
const pink = (message) => {
return wrap(message, exports.colourTable["pink"]);
export const pink = (message) => {
return wrap(message, colourTable["pink"]);
};
exports.pink = pink;
const orange = (message) => {
return wrap(message, exports.colourTable["orange"]);
export const orange = (message) => {
return wrap(message, colourTable["orange"]);
};
exports.orange = orange;
const purple = (message) => {
return wrap(message, exports.colourTable["purple"]);
export const purple = (message) => {
return wrap(message, colourTable["purple"]);
};
exports.purple = purple;
const blue = (message) => {
return wrap(message, exports.colourTable["blue"]);
export const blue = (message) => {
return wrap(message, colourTable["blue"]);
};
exports.blue = blue;
const green = (message) => {
return wrap(message, exports.colourTable["green"]);
export const green = (message) => {
return wrap(message, colourTable["green"]);
};
exports.green = green;
const yellow = (message) => {
return wrap(message, exports.colourTable["yellow"]);
export const yellow = (message) => {
return wrap(message, colourTable["yellow"]);
};
exports.yellow = yellow;
const lightBlue = (message) => {
return wrap(message, exports.colourTable["lightBlue"]);
export const lightBlue = (message) => {
return wrap(message, colourTable["lightBlue"]);
};
exports.lightBlue = lightBlue;
function wrap(message, colour) {
export function wrap(message, colour) {
return `${colour}${message}\x1b[0m`;
}
exports.wrap = wrap;
function rgb(r, g, b) {
export function rgb(r, g, b) {
return `\x1b[38;2;${r};${g};${b}m`;
}
exports.rgb = rgb;
exports.colourTable = {
export const colourTable = {
red: rgb(235, 77, 75),

@@ -46,0 +33,0 @@ pink: rgb(255, 121, 121),

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

import { Severity } from "../../../types/enums/Severity";
import { ColourConverter } from "../../../types/interfaces/ColourConverter";
import { Severity } from "../../../types/enums/Severity.js";
import { ColourConverter } from "../../../types/interfaces/ColourConverter.js";
export declare const SeverityColours: Map<Severity, ColourConverter>;

@@ -1,16 +0,13 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SeverityColours = void 0;
const Severity_1 = require("../../../types/enums/Severity");
const ColourConverters_1 = require("./ColourConverters");
exports.SeverityColours = new Map([
[Severity_1.Severity.DEFAULT, ColourConverters_1.lightBlue],
[Severity_1.Severity.DEBUG, ColourConverters_1.pink],
[Severity_1.Severity.INFO, ColourConverters_1.lightBlue],
[Severity_1.Severity.NOTICE, ColourConverters_1.lightBlue],
[Severity_1.Severity.WARNING, ColourConverters_1.orange],
[Severity_1.Severity.ERROR, ColourConverters_1.red],
[Severity_1.Severity.CRITICAL, ColourConverters_1.red],
[Severity_1.Severity.ALERT, ColourConverters_1.red],
[Severity_1.Severity.EMERGENCY, ColourConverters_1.red],
import { Severity } from "../../../types/enums/Severity.js";
import { lightBlue, orange, pink, red } from "./ColourConverters.js";
export const SeverityColours = new Map([
[Severity.DEFAULT, lightBlue],
[Severity.DEBUG, pink],
[Severity.INFO, lightBlue],
[Severity.NOTICE, lightBlue],
[Severity.WARNING, orange],
[Severity.ERROR, red],
[Severity.CRITICAL, red],
[Severity.ALERT, red],
[Severity.EMERGENCY, red],
]);

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

import { SqlColourPalette } from "../../../types/dataStructures/SqlColourPalette";
import type { SqlColourPalette } from "../../../types/dataStructures/SqlColourPalette";
export declare const defaultSqlColourPalette: SqlColourPalette;
export declare const altSqlColourPalette: SqlColourPalette;

@@ -1,16 +0,13 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.altSqlColourPalette = exports.defaultSqlColourPalette = void 0;
const ColourConverters_1 = require("./ColourConverters");
exports.defaultSqlColourPalette = {
keywords: ColourConverters_1.colourTable.orange,
numbers: ColourConverters_1.colourTable.blue,
strings: ColourConverters_1.colourTable.green,
punctuation: ColourConverters_1.colourTable.yellow,
import { colourTable, rgb } from "./ColourConverters.js";
export const defaultSqlColourPalette = {
keywords: colourTable.orange,
numbers: colourTable.blue,
strings: colourTable.green,
punctuation: colourTable.yellow,
};
exports.altSqlColourPalette = {
keywords: (0, ColourConverters_1.rgb)(250, 130, 49),
numbers: (0, ColourConverters_1.rgb)(15, 185, 177),
strings: (0, ColourConverters_1.rgb)(32, 191, 107),
punctuation: (0, ColourConverters_1.rgb)(119, 140, 163),
export const altSqlColourPalette = {
keywords: rgb(250, 130, 49),
numbers: rgb(15, 185, 177),
strings: rgb(32, 191, 107),
punctuation: rgb(119, 140, 163),
};

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DevelopmentPresenter = void 0;
const ColourConverters_1 = require("./colours/ColourConverters");
const SeverityColours_1 = require("./colours/SeverityColours");
import { lightBlue, purple, red } from "./colours/ColourConverters.js";
import { SeverityColours } from "./colours/SeverityColours.js";
let longestFilename = 0;

@@ -10,3 +7,3 @@ const MAX_FILENAME_LENGTH = 50;

const severityWidth = 7;
const DevelopmentPresenter = async (log) => {
export const DevelopmentPresenter = async (log) => {
if (log.filename.length > longestFilename) {

@@ -27,3 +24,2 @@ longestFilename = Math.min(log.filename.length, MAX_FILENAME_LENGTH);

};
exports.DevelopmentPresenter = DevelopmentPresenter;
const splitByWidth = (message, maxWidth) => {

@@ -57,3 +53,3 @@ var _a;

let severities = centerMultilineLog([
((_a = SeverityColours_1.SeverityColours.get(severity)) !== null && _a !== void 0 ? _a : ColourConverters_1.red)(`${severity.padEnd(severityWidth, " ")}`),
((_a = SeverityColours.get(severity)) !== null && _a !== void 0 ? _a : red)(`${severity.padEnd(severityWidth, " ")}`),
], lineCount);

@@ -65,6 +61,6 @@ severities = centerMultilineLog([severity], lineCount, severityWidth);

[
(0, ColourConverters_1.purple)(timestamps[index]),
purple(timestamps[index]),
severities[index],
...linesArray.map((lines) => centerMultilineLog(lines, lineCount)[index]),
].join((0, ColourConverters_1.lightBlue)(" | ")) + "\n";
].join(lightBlue(" | ")) + "\n";
}

@@ -71,0 +67,0 @@ await new Promise((resolve) => process.stdout.write(output, resolve));

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

import { LogPresenter } from "../../types/interfaces/LogPresenter";
import type { LogPresenter } from "../../types/interfaces/LogPresenter";
/**

@@ -3,0 +3,0 @@ * JSON formatted string log output, suitable for logging on Google Cloud.

@@ -1,8 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProductionPresenter = void 0;
const ProductionPresenter = async (log) => {
export const ProductionPresenter = async (log) => {
const logString = JSON.stringify(log) + "\n";
await new Promise((resolve) => process.stdout.write(logString, resolve));
};
exports.ProductionPresenter = ProductionPresenter;

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PresentSql = exports.limitLength = exports.valueToString = void 0;
const SqlColourPalettes_1 = require("./colours/SqlColourPalettes");
const ColourConverters_1 = require("./colours/ColourConverters");
function valueToString(value, lengthLimit) {
import { altSqlColourPalette, defaultSqlColourPalette, } from "./colours/SqlColourPalettes.js";
import { wrap } from "./colours/ColourConverters.js";
export function valueToString(value, lengthLimit) {
if (typeof value === "number")

@@ -22,4 +19,3 @@ return value.toString();

}
exports.valueToString = valueToString;
function limitLength(str, len) {
export function limitLength(str, len) {
if (str.length < len)

@@ -30,3 +26,2 @@ return str;

}
exports.limitLength = limitLength;
function subParameterisedQuery(query, values) {

@@ -64,3 +59,3 @@ return query.replace(/\$[0-9]+/gm, (dollarN) => {

function highlightSql(query, palette) {
const cPalette = palette !== null && palette !== void 0 ? palette : SqlColourPalettes_1.defaultSqlColourPalette;
const cPalette = palette !== null && palette !== void 0 ? palette : defaultSqlColourPalette;
const sqlKeywords = [

@@ -97,9 +92,9 @@ "SELECT",

const highlightedQuery = query
.replace(isNumber, (num) => (0, ColourConverters_1.wrap)(num, cPalette.numbers))
.replace(isIn(sqlKeywords), (keyword) => (0, ColourConverters_1.wrap)(keyword.toUpperCase(), cPalette.keywords))
.replace(isString, (str) => (0, ColourConverters_1.wrap)(str, cPalette.strings))
.replace(isPunctuation, (punc) => { var _a; return (0, ColourConverters_1.wrap)(punc, (_a = cPalette === null || cPalette === void 0 ? void 0 : cPalette.punctuation) !== null && _a !== void 0 ? _a : cPalette.keywords); });
.replace(isNumber, (num) => wrap(num, cPalette.numbers))
.replace(isIn(sqlKeywords), (keyword) => wrap(keyword.toUpperCase(), cPalette.keywords))
.replace(isString, (str) => wrap(str, cPalette.strings))
.replace(isPunctuation, (punc) => { var _a; return wrap(punc, (_a = cPalette === null || cPalette === void 0 ? void 0 : cPalette.punctuation) !== null && _a !== void 0 ? _a : cPalette.keywords); });
return highlightedQuery;
}
function PresentSql(query, values) {
export function PresentSql(query, values) {
let sql = query;

@@ -109,5 +104,4 @@ if (values)

sql = formatSql(sql);
sql = highlightSql(sql, SqlColourPalettes_1.altSqlColourPalette);
sql = highlightSql(sql, altSqlColourPalette);
return sql;
}
exports.PresentSql = PresentSql;

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Environment = void 0;
var Environment;
export var Environment;
(function (Environment) {

@@ -9,2 +6,2 @@ Environment[Environment["DEVELOPMENT"] = 0] = "DEVELOPMENT";

Environment[Environment["PRODUCTION"] = 2] = "PRODUCTION";
})(Environment = exports.Environment || (exports.Environment = {}));
})(Environment || (Environment = {}));

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Severity = void 0;
var Severity;
export var Severity;
(function (Severity) {

@@ -15,2 +12,2 @@ Severity["DEFAULT"] = "DEFAULT";

Severity["EMERGENCY"] = "EMERGENCY";
})(Severity = exports.Severity || (exports.Severity = {}));
})(Severity || (Severity = {}));

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};
{
"name": "timer-logs",
"version": "1.7.5",
"version": "2.0.0",
"files": [

@@ -10,3 +10,3 @@ "dist"

"prettier": "^2.3.2",
"typescript": "^4.5.5"
"typescript": "^4.6.4"
},

@@ -24,3 +24,3 @@ "author": {

},
"type": "commonjs",
"type": "module",
"keywords": [

@@ -27,0 +27,0 @@ "nodejs",

@@ -18,3 +18,3 @@ # Timer logs

```typescript
import Timer from 'timer-logs'
import { Timer } from 'timer-logs'

@@ -151,2 +151,2 @@ const webservice = async () => {

}
```
```
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