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 5.0.0 to 6.0.0

2

dist/src/config.d.ts
export declare const ROARR_VERSION = "5.0.0";
export declare const ROARR_LOG_FORMAT_VERSION = "1.0.0";
export declare const ROARR_LOG_FORMAT_VERSION = "2.0.0";

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

exports.ROARR_VERSION = '5.0.0';
exports.ROARR_LOG_FORMAT_VERSION = '1.0.0';
exports.ROARR_LOG_FORMAT_VERSION = '2.0.0';

@@ -21,2 +21,13 @@ "use strict";

};
const getSequence = () => {
const asyncLocalStorage = globalThis.ROARR.asyncLocalStorage;
if (!asyncLocalStorage) {
return String(globalThis.ROARR.sequence++);
}
const store = asyncLocalStorage.getStore();
if ((store === null || store === void 0 ? void 0 : store.sequenceRoot) !== undefined && (store === null || store === void 0 ? void 0 : store.sequence) !== undefined) {
return String(store.sequenceRoot) + '.' + String(store.sequence++);
}
return String(globalThis.ROARR.sequence++);
};
const defaultContext = {};

@@ -26,3 +37,3 @@ const createLogger = (onMessage, parentContext) => {

const time = Date.now();
const sequence = globalThis.ROARR.sequence++;
const sequence = getSequence();
const asyncLocalStorage = globalThis.ROARR.asyncLocalStorage;

@@ -95,3 +106,2 @@ let context;

log.adopt = async (routine, context) => {
var _a;
const asyncLocalStorage = globalThis.ROARR.asyncLocalStorage;

@@ -101,7 +111,17 @@ if (!asyncLocalStorage) {

}
const store = asyncLocalStorage.getStore();
let sequenceRoot;
if ((store === null || store === void 0 ? void 0 : store.sequenceRoot) !== undefined && (store === null || store === void 0 ? void 0 : store.sequence) !== undefined) {
sequenceRoot = String(store.sequenceRoot) + '.' + String(store.sequence++);
}
else {
sequenceRoot = String(globalThis.ROARR.sequence++);
}
return asyncLocalStorage.run({
context: {
...(_a = asyncLocalStorage.getStore()) === null || _a === void 0 ? void 0 : _a.context,
...store === null || store === void 0 ? void 0 : store.context,
...context,
},
sequence: 0,
sequenceRoot,
}, () => {

@@ -108,0 +128,0 @@ return routine();

@@ -16,3 +16,3 @@ /// <reference types="node" />

readonly message: string;
readonly sequence: number;
readonly sequence: string;
readonly time: number;

@@ -19,0 +19,0 @@ readonly version: string;

@@ -8,2 +8,3 @@ "use strict";

const ava_1 = require("ava");
const delay_1 = __importDefault(require("delay"));
const globalthis_1 = __importDefault(require("globalthis"));

@@ -13,3 +14,3 @@ const createLogger_1 = __importDefault(require("../../src/factories/createLogger"));

const time = -1;
const version = '1.0.0';
const version = '2.0.0';
ava_1.beforeEach(() => {

@@ -47,3 +48,3 @@ const globalThis = globalthis_1.default();

message: 'foo',
sequence: 0,
sequence: '0.0',
time,

@@ -79,3 +80,3 @@ version,

message: 'foo 0',
sequence: 0,
sequence: '0.0',
time,

@@ -90,3 +91,3 @@ version,

message: 'foo 1',
sequence: 1,
sequence: '0.1.0',
time,

@@ -97,1 +98,195 @@ version,

});
ava_1.serial('top-level adopt increments global sequence', async (t) => {
const log = createLoggerWithHistory();
log.adopt(() => {
log('foo');
});
log.adopt(() => {
log('bar');
});
t.deepEqual(log.messages, [
{
context: {},
message: 'foo',
sequence: '0.0',
time,
version,
},
{
context: {},
message: 'bar',
sequence: '1.0',
time,
version,
},
]);
});
ava_1.serial('logs within adopt increment local sequence', async (t) => {
const log = createLoggerWithHistory();
log.adopt(() => {
log('foo');
log('bar');
});
log.adopt(() => {
log('baz');
log('qux');
});
t.deepEqual(log.messages, [
{
context: {},
message: 'foo',
sequence: '0.0',
time,
version,
},
{
context: {},
message: 'bar',
sequence: '0.1',
time,
version,
},
{
context: {},
message: 'baz',
sequence: '1.0',
time,
version,
},
{
context: {},
message: 'qux',
sequence: '1.1',
time,
version,
},
]);
});
ava_1.serial('nested adopt increment local sequence', async (t) => {
const log = createLoggerWithHistory();
log.adopt(() => {
log('foo');
log.adopt(() => {
log('bar');
});
});
t.deepEqual(log.messages, [
{
context: {},
message: 'foo',
sequence: '0.0',
time,
version,
},
{
context: {},
message: 'bar',
sequence: '0.1.0',
time,
version,
},
]);
});
ava_1.serial('adopted scope maintains reference to local sequence', async (t) => {
const log = createLoggerWithHistory();
log.adopt(() => {
log('foo');
log.adopt(() => {
log('bar 0');
log('bar 1');
log('bar 2');
});
log('baz');
});
t.deepEqual(log.messages, [
{
context: {},
message: 'foo',
sequence: '0.0',
time,
version,
},
{
context: {},
message: 'bar 0',
sequence: '0.1.0',
time,
version,
},
{
context: {},
message: 'bar 1',
sequence: '0.1.1',
time,
version,
},
{
context: {},
message: 'bar 2',
sequence: '0.1.2',
time,
version,
},
{
context: {},
message: 'baz',
sequence: '0.2',
time,
version,
},
]);
});
ava_1.serial('maintains correct local reference in an async scope', async (t) => {
const log = createLoggerWithHistory();
log.adopt(() => {
log('foo 0');
log.adopt(() => {
log('bar 0');
log.adopt(() => {
log('baz 0');
setTimeout(() => {
log('baz 1');
}, 10);
});
log('bar 1');
});
});
await delay_1.default(20);
t.deepEqual(log.messages, [
{
context: {},
message: 'foo 0',
sequence: '0.0',
time: -1,
version: '2.0.0',
},
{
context: {},
message: 'bar 0',
sequence: '0.1.0',
time: -1,
version: '2.0.0',
},
{
context: {},
message: 'baz 0',
sequence: '0.1.1.0',
time: -1,
version: '2.0.0',
},
{
context: {},
message: 'bar 1',
sequence: '0.1.2',
time: -1,
version: '2.0.0',
},
{
context: {},
message: 'baz 1',
sequence: '0.1.1.1',
time: -1,
version: '2.0.0',
},
]);
});

@@ -29,5 +29,4 @@ "use strict";

const createRoarrInitialGlobalState_1 = __importDefault(require("../../src/factories/createRoarrInitialGlobalState"));
const sequence = 0;
const time = -1;
const version = '1.0.0';
const version = '2.0.0';
ava_1.beforeEach(() => {

@@ -55,3 +54,3 @@ const globalThis = globalthis_1.default();

message: 'foo',
sequence,
sequence: '0',
time,

@@ -77,3 +76,3 @@ version,

message: 'foo',
sequence,
sequence: '0',
time,

@@ -91,3 +90,3 @@ version,

message: 'foo bar',
sequence,
sequence: '0',
time,

@@ -105,3 +104,3 @@ version,

message: 'foo bar baz qux',
sequence,
sequence: '0',
time,

@@ -119,3 +118,3 @@ version,

message: 'foo 1 2 3',
sequence,
sequence: '0',
time,

@@ -137,3 +136,3 @@ version,

message: 'baz',
sequence,
sequence: '0',
time,

@@ -155,3 +154,3 @@ version,

message: 'baz qux',
sequence,
sequence: '0',
time,

@@ -171,3 +170,3 @@ version,

message: 'baz',
sequence,
sequence: '0',
time,

@@ -188,3 +187,3 @@ version,

message: 'quux',
sequence,
sequence: '0',
time,

@@ -204,3 +203,3 @@ version,

message: 'quux',
sequence,
sequence: '0',
time,

@@ -221,3 +220,3 @@ version,

message: 'quux',
sequence,
sequence: '0',
time,

@@ -237,3 +236,3 @@ version,

message: 'qux',
sequence,
sequence: '0',
time,

@@ -257,3 +256,3 @@ version,

message: 'foobar',
sequence,
sequence: '0',
time,

@@ -289,3 +288,3 @@ version,

message: 'foo 0',
sequence: 0,
sequence: '0',
time,

@@ -299,3 +298,3 @@ version,

message: 'foo 1',
sequence: 1,
sequence: '1',
time,

@@ -309,3 +308,3 @@ version,

message: 'foo 2',
sequence: 2,
sequence: '2',
time,

@@ -319,3 +318,3 @@ version,

message: 'foo 3',
sequence: 3,
sequence: '3',
time,

@@ -329,3 +328,3 @@ version,

message: 'foo 4',
sequence: 4,
sequence: '4',
time,

@@ -339,3 +338,3 @@ version,

message: 'foo 5',
sequence: 5,
sequence: '5',
time,

@@ -355,3 +354,3 @@ version,

message: 'http://commons.wikimedia.org/wiki/Special:FilePath/Cucumis%20anguria.JPG',
sequence: 0,
sequence: '0',
time,

@@ -358,0 +357,0 @@ version,

@@ -40,2 +40,3 @@ {

"del-cli": "^3.0.1",
"delay": "^5.0.0",
"domain-parent": "^1.0.0",

@@ -81,3 +82,3 @@ "eslint": "^7.22.0",

"typings": "./dist/src/log.d.ts",
"version": "5.0.0"
"version": "6.0.0"
}

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

};
```

@@ -199,3 +198,3 @@

|`message`|User-provided message formatted using [printf](https://en.wikipedia.org/wiki/Printf_format_string).|
|`sequence`|An incremental ID.|
|`sequence`|Incremental sequence ID (see [`adopt`](#adopt) for description of the format and its meaning).|
|`time`|Unix timestamp in milliseconds.|

@@ -206,3 +205,3 @@ |`version`|Roarr log message format version.|

```js
```json
{

@@ -216,7 +215,6 @@ "context": {

"message": "starting task ID 1",
"sequence": 0,
"sequence": "0",
"time": 1506776210000,
"version": "1.0.0"
}
```

@@ -298,8 +296,42 @@

);
```
// {"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"}]
```json
{"context":{"bar":"bar 0"},"message":"foo 0","sequence":"0","time":1506776210000,"version":"2.0.0"}
{"context":{"bar":"bar 0","baz": "baz 1"},"message":"foo 1","sequence":"0.0","time":1506776210000,"version":"2.0.0"}
```
<a name="roarr-api-adopt-sequence-value"></a>
#### <code>sequence</code> value
`sequence` represents async context hierarchy in [`ltree`](https://www.postgresql.org/docs/current/ltree.html) format, i.e.
```
<top-level sequential invocation ID>[.<async operation sequential invocation ID>]
```
Members of sequence value represent log index relative to the async execution context. This information can be used to establish the origin of the log invocation in an asynchronous context, e.g.
```js
log.adopt(() => {
log('foo 0');
log.adopt(() => {
log('bar 0');
log.adopt(() => {
log('baz 0');
log('baz 1');
});
log('bar 1');
});
});
```
```json
{"context":{},"message":"foo 0","sequence":"0.0","time":1506776210000,"version":"2.0.0"}
{"context":{},"message":"bar 0","sequence":"0.1.0","time":1506776210000,"version":"2.0.0"}
{"context":{},"message":"baz 0","sequence":"0.1.1.0","time":1506776210000,"version":"2.0.0"}
{"context":{},"message":"bar 1","sequence":"0.1.2","time":1506776210000,"version":"2.0.0"}
{"context":{},"message":"baz 1","sequence":"0.1.1.1","time":1506776210000,"version":"2.0.0"}
```
<a name="roarr-api-adopt-requirements"></a>

@@ -344,6 +376,7 @@ #### Requirements

childLog.debug('foo 2');
```
// {"context":{"logLevel":20},"message":"foo 1","sequence":0,"time":1531914529921,"version":"1.0.0"}
// {"context":{"foo":"bar","logLevel":20},"message":"foo 2","sequence":1,"time":1531914529922,"version":"1.0.0"}
```json
{"context":{"logLevel":20},"message":"foo 1","sequence":"0","time":1506776210000,"version":"2.0.0"}
{"context":{"foo":"bar","logLevel":20},"message":"foo 2","sequence":"1","time":1506776210000,"version":"2.0.0"}
```

@@ -377,6 +410,7 @@

childLog.debug('foo 2');
```
// {"context":{"logLevel":20},"message":"foo 1","sequence":0,"time":1531914656076,"version":"1.0.0"}
// {"context":{"logLevel":20},"message":"bar 2","sequence":1,"time":1531914656077,"version":"1.0.0"}
```json
{"context":{"logLevel":20},"message":"foo 1","sequence":"0","time":1506776210000,"version":"2.0.0"}
{"context":{"logLevel":20},"message":"bar 2","sequence":"1","time":1506776210000,"version":"2.0.0"}
```

@@ -434,8 +468,8 @@

```
{"context":{"logLevel":10},"message":"foo","sequence":0,"time":1506776210000,"version":"1.0.0"}
{"context":{"logLevel":20},"message":"foo","sequence":1,"time":1506776210000,"version":"1.0.0"}
{"context":{"logLevel":30},"message":"foo","sequence":2,"time":1506776210000,"version":"1.0.0"}
{"context":{"logLevel":40},"message":"foo","sequence":3,"time":1506776210000,"version":"1.0.0"}
{"context":{"logLevel":50},"message":"foo","sequence":4,"time":1506776210000,"version":"1.0.0"}
{"context":{"logLevel":60},"message":"foo","sequence":5,"time":1506776210000,"version":"1.0.0"}
{"context":{"logLevel":10},"message":"foo","sequence":"0","time":1506776210000,"version":"2.0.0"}
{"context":{"logLevel":20},"message":"foo","sequence":"1","time":1506776210000,"version":"2.0.0"}
{"context":{"logLevel":30},"message":"foo","sequence":"2","time":1506776210000,"version":"2.0.0"}
{"context":{"logLevel":40},"message":"foo","sequence":"3","time":1506776210000,"version":"2.0.0"}
{"context":{"logLevel":50},"message":"foo","sequence":"4","time":1506776210000,"version":"2.0.0"}
{"context":{"logLevel":60},"message":"foo","sequence":"5","time":1506776210000,"version":"2.0.0"}

@@ -459,6 +493,7 @@ ```

childLog.debug({error}, 'bar');
```
// {"context":{"logLevel":20,"error":{}},"message":"bar","sequence":0,"time":1531918373676,"version":"1.0.0"}
// {"context":{"logLevel":20,"error":{"name":"Error","message":"foo","stack":"[REDACTED]"}},"message":"bar","sequence":1,"time":1531918373678,"version":"1.0.0"}
```json
{"context":{"logLevel":20,"error":{}},"message":"bar","sequence":"0","time":1506776210000,"version":"2.0.0"}
{"context":{"logLevel":20,"error":{"name":"Error","message":"foo","stack":"[REDACTED]"}},"message":"bar","sequence":"1","time":1506776210000,"version":"2.0.0"}
```

@@ -465,0 +500,0 @@

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