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

@compas/stdlib

Package Overview
Dependencies
Maintainers
1
Versions
196
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@compas/stdlib - npm Package Compare versions

Comparing version 0.0.150 to 0.0.151

8

package.json
{
"name": "@compas/stdlib",
"version": "0.0.150",
"version": "0.0.151",
"description": "All kinds of utility functions",

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

"dependencies": {
"@types/node": "15.12.5",
"@types/node": "16.0.1",
"dotenv": "10.0.0",

@@ -41,5 +41,5 @@ "lodash.merge": "4.6.2"

"engines": {
"node": ">=15"
"node": ">=16"
},
"gitHead": "6bbe148c5e4f643ed7db0bc22fc439091f0fc34a"
"gitHead": "04f772827440bd9c8a782cf109c8b147f728d204"
}
import { inspect } from "util";
import { AppError } from "./error.js";
import { isNil } from "./lodash.js";

@@ -34,2 +35,4 @@

const _this = this;
/** @type {Logger} */

@@ -51,12 +54,12 @@ this.log = logger;

function calculateDuration() {
if (this.callStack[0]?.type !== "start") {
if (_this.callStack[0]?.type !== "start") {
return;
}
const lastIdx = this.callStack.length - 1;
const lastType = this.callStack[lastIdx]?.type;
const lastIdx = _this.callStack.length - 1;
const lastType = _this.callStack[lastIdx]?.type;
if (lastType === "stop" || lastType === "aborted") {
this.callStack[0].duration =
this.callStack[lastIdx].time - this.callStack[0].time;
_this.callStack[0].duration =
_this.callStack[lastIdx].time - _this.callStack[0].time;
}

@@ -66,7 +69,7 @@ }

function print() {
this.log.info({
return {
type: "event_callstack",
aborted: !!this.signal?.aborted,
callStack: this.callStack,
});
aborted: !!_this.signal?.aborted,
callStack: _this.callStack,
};
}

@@ -106,3 +109,6 @@

event.calculateDuration();
throw new TimeoutError(event);
throw AppError.serverError({
message: "Operation aborted",
event: getEventRoot(event).toJSON(),
});
}

@@ -138,3 +144,6 @@

});
throw new TimeoutError(event);
throw AppError.serverError({
message: "Operation aborted",
event: getEventRoot(event).toJSON(),
});
}

@@ -174,3 +183,6 @@

event.calculateDuration();
throw new TimeoutError(event);
throw AppError.serverError({
message: "Operation aborted",
event: getEventRoot(event).toJSON(),
});
}

@@ -196,6 +208,3 @@ }

if (isNil(event.root)) {
event.log.info({
type: "event_callstack",
callStack: event.callStack,
});
event.log.info(event);
}

@@ -205,52 +214,8 @@ }

/**
* Timeout error, shaped like an @compas/stdlib AppError
*
* @since 0.1.0
* @class
* Get the root event from the provided event
* @param {InsightEvent} event
* @returns {InsightEvent}
*/
export class TimeoutError extends Error {
/**
*
* @param {InsightEvent} event
*/
constructor(event) {
super();
const getEventRoot = (event) =>
isNil(event.parent) ? event : getEventRoot(event.parent);
this.key = "error.server.internal";
this.status = 500;
this.info = {
message: "Operation aborted",
rootEvent: getEventRoot(event),
};
Object.setPrototypeOf(this, TimeoutError.prototype);
}
/**
* Format as object when the TimeoutError is passed to console.log / console.error.
* This works because it uses `util.inspect` under the hood.
* Util#inspect checks if the Symbol `util.inspect.custom` is available.
*/
[inspect.custom]() {
return {
key: this.key,
status: this.status,
info: this.info,
};
}
/**
* Format as object when the TimeoutError is passed to JSON.stringify().
* This is used in the compas insight logger in production mode.
*/
toJSON() {
return {
key: this.key,
status: this.status,
info: this.info,
};
}
function getEventRoot(event) {
return isNil(event.parent) ? event : getEventRoot(event.parent);
}
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