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

roarr

Package Overview
Dependencies
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

roarr - npm Package Compare versions

Comparing version 2.14.6 to 2.15.0

62

dist/factories/createLogger.js

@@ -10,2 +10,4 @@ "use strict";

var _detectNode = _interopRequireDefault(require("detect-node"));
var _jsonStringifySafe = _interopRequireDefault(require("json-stringify-safe"));

@@ -21,3 +23,3 @@

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

@@ -27,3 +29,38 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

const globalThis = (0, _globalthis.default)();
let domain;
if (_detectNode.default) {
// eslint-disable-next-line global-require
domain = require('domain');
}
const getParentDomainContext = () => {
if (!domain) {
return {};
}
const parentRoarrContexts = [];
let currentDomain = process.domain; // $FlowFixMe
if (!currentDomain || !currentDomain.parentDomain) {
return {};
}
while (currentDomain && currentDomain.parentDomain) {
currentDomain = currentDomain.parentDomain;
if (currentDomain.roarr && currentDomain.roarr.context) {
parentRoarrContexts.push(currentDomain.roarr.context);
}
}
let domainContext = {};
for (const parentRoarrContext of parentRoarrContexts) {
domainContext = _objectSpread({}, domainContext, {}, parentRoarrContext);
}
return domainContext;
};
const createLogger = (onMessage, parentContext) => {

@@ -38,3 +75,3 @@ // eslint-disable-next-line id-length, unicorn/prevent-abbreviations

if (typeof a === 'string') {
context = _objectSpread({}, parentContext || {});
context = _objectSpread({}, domain && process.domain && process.domain.roarr && process.domain.roarr.context, {}, parentContext || {});
message = (0, _sprintfJs.sprintf)(a, b, c, d, e, f, g, h, i, k);

@@ -46,3 +83,3 @@ } else {

context = JSON.parse((0, _jsonStringifySafe.default)(_objectSpread({}, parentContext || {}, {}, a)));
context = JSON.parse((0, _jsonStringifySafe.default)(_objectSpread({}, domain && process.domain && process.domain.roarr && process.domain.roarr.context, {}, parentContext || {}, {}, a)));
message = (0, _sprintfJs.sprintf)(b, c, d, e, f, g, h, i, k);

@@ -71,9 +108,24 @@ }

return createLogger(onMessage, _objectSpread({}, parentContext, {}, context));
return createLogger(onMessage, _objectSpread({}, domain && process.domain && process.domain.roarr && process.domain.roarr.context, {}, parentContext, {}, context));
};
log.getContext = () => {
return _objectSpread({}, parentContext || {});
return _objectSpread({}, domain && process.domain && process.domain.roarr && process.domain.roarr.context, {}, parentContext || {});
};
log.adopt = async (routine, context) => {
if (!domain) {
return routine();
}
const adoptedDomain = domain.create();
return adoptedDomain.run(() => {
// $FlowFixMe
adoptedDomain.roarr = {
context: _objectSpread({}, getParentDomainContext() || {}, {}, context)
};
return routine();
});
};
for (const logLevel of Object.keys(_constants.logLevels)) {

@@ -80,0 +132,0 @@ // eslint-disable-next-line id-length, unicorn/prevent-abbreviations

2

dist/factories/createRoarrInititialGlobalState.js

@@ -20,3 +20,3 @@ "use strict";

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

@@ -23,0 +23,0 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

@@ -8,13 +8,12 @@ {

"ava": {
"babel": {
"compileAsTests": [
"test/helpers/**/*"
]
},
"files": [
"test/**/*"
"test/roarr/**/*"
],
"helpers": [
"test/helpers/**/*"
],
"require": [
"@babel/register"
],
"sources": [
"src/**/*"
]

@@ -25,3 +24,3 @@ },

"detect-node": "^2.0.4",
"globalthis": "^1.0.0",
"globalthis": "^1.0.1",
"json-stringify-safe": "^5.0.1",

@@ -33,20 +32,22 @@ "semver-compare": "^1.0.0",

"devDependencies": {
"@babel/cli": "^7.7.0",
"@babel/core": "^7.7.2",
"@babel/node": "^7.7.0",
"@babel/plugin-transform-flow-strip-types": "^7.6.3",
"@babel/preset-env": "^7.7.1",
"@babel/register": "^7.7.0",
"ava": "^2.4.0",
"babel-plugin-istanbul": "^5.2.0",
"@ava/babel": "^1.0.0",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.4",
"@babel/node": "^7.8.4",
"@babel/plugin-transform-flow-strip-types": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"@babel/register": "^7.8.3",
"ava": "^3.1.0",
"babel-plugin-istanbul": "^6.0.0",
"babel-plugin-transform-export-default-name": "^2.0.4",
"coveralls": "^3.0.8",
"eslint": "^6.6.0",
"coveralls": "^3.0.9",
"domain-parent": "^1.0.0",
"eslint": "^6.8.0",
"eslint-config-canonical": "^18.1.0",
"flow-bin": "^0.112.0",
"flow-bin": "^0.117.0",
"flow-copy-source": "^2.0.9",
"gitdown": "^3.1.2",
"husky": "^3.1.0",
"nyc": "^14.1.1",
"semantic-release": "^15.13.31"
"husky": "^4.2.1",
"nyc": "^15.0.0",
"semantic-release": "^17.0.1"
},

@@ -93,3 +94,3 @@ "engines": {

},
"version": "2.14.6"
"version": "2.15.0"
}

@@ -21,2 +21,3 @@ <a name="roarr"></a>

* [API](#roarr-api)
* [`adopt`](#roarr-api-adopt)
* [`child`](#roarr-api-child)

@@ -243,5 +244,52 @@ * [`getContext`](#roarr-api-getcontext)

<a name="roarr-api-adopt"></a>
### <code>adopt</code>
```js
<T>(routine: () => Promise<T>, context: MessageContextType) => Promise<T>,
```
`adopt` function uses Node.js [`domain`](https://nodejs.org/api/domain.html) to pass-down context properties.
When using `adopt`, context properties will be added to all _all_ Roarr messages within the same asynchronous context, e.g.
```js
await log.adopt(
async () => {
log('foo 0');
await log.adopt(
() => {
log('foo 1');
},
{
baz: 'baz 1',
},
);
},
{
bar: 'bar 0',
},
);
// {"context":{"bar":"bar 0"},"message":"foo 0","sequence":0,"time":1531914656076,"version":"1.0.0"}
// {"context":{"bar":"bar 0","baz":"baz 1"},"message":"foo 1","sequence":1,"time":1531914656077,"version":"1.0.0"}]
```
<a name="roarr-api-adopt-requirements"></a>
#### Requirements
* `adopt` method only works in Node.js.
* You must shim Node.js using [`domain-parent`](https://github.com/gajus/domain-parent).
<a name="roarr-api-child"></a>
### <code>child</code>
```js
(context: TranslateMessageFunctionType | MessageContextType) => LoggerType,
```
The `child` function has two signatures:

@@ -248,0 +296,0 @@

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc