This commit is contained in:
2022-09-30 05:39:11 +00:00
parent 41ee9463ae
commit 4687fa49bc
11418 changed files with 1312504 additions and 0 deletions

24
buildfiles/node_modules/roarr/LICENSE generated vendored Normal file
View File

@ -0,0 +1,24 @@
Copyright (c) 2019, Gajus Kuizinas (http://gajus.com/)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Gajus Kuizinas (http://gajus.com/) nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ANUARY BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

689
buildfiles/node_modules/roarr/README.md generated vendored Normal file
View File

@ -0,0 +1,689 @@
<a name="roarr"></a>
# Roarr
[![GitSpo Mentions](https://gitspo.com/badges/mentions/gajus/roarr?style=flat-square)](https://gitspo.com/mentions/gajus/roarr)
[![Travis build status](http://img.shields.io/travis/gajus/roarr/master.svg?style=flat-square)](https://travis-ci.org/gajus/roarr)
[![Coveralls](https://img.shields.io/coveralls/gajus/roarr.svg?style=flat-square)](https://coveralls.io/github/gajus/roarr)
[![NPM version](http://img.shields.io/npm/v/roarr.svg?style=flat-square)](https://www.npmjs.org/package/roarr)
[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)
[![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social&label=Follow)](https://twitter.com/kuizinas)
JSON logger for Node.js and browser.
* [Roarr](#roarr)
* [Motivation](#roarr-motivation)
* [Usage](#roarr-usage)
* [Producing logs](#roarr-usage-producing-logs)
* [Consuming logs](#roarr-usage-consuming-logs)
* [Filtering logs](#roarr-usage-filtering-logs)
* [Log message format](#roarr-log-message-format)
* [API](#roarr-api)
* [`adopt`](#roarr-api-adopt)
* [`child`](#roarr-api-child)
* [`getContext`](#roarr-api-getcontext)
* [`trace`](#roarr-api-trace)
* [`debug`](#roarr-api-debug)
* [`info`](#roarr-api-info)
* [`warn`](#roarr-api-warn)
* [`error`](#roarr-api-error)
* [`fatal`](#roarr-api-fatal)
* [Middlewares](#roarr-middlewares)
* [CLI program](#roarr-cli-program)
* [Transports](#roarr-transports)
* [Node.js environment variables](#roarr-node-js-environment-variables)
* [Conventions](#roarr-conventions)
* [Context property names](#roarr-conventions-context-property-names)
* [Using Roarr in an application](#roarr-conventions-using-roarr-in-an-application)
* [Recipes](#roarr-recipes)
* [Logging errors](#roarr-recipes-logging-errors)
* [Using with Elasticsearch](#roarr-recipes-using-with-elasticsearch)
* [Using with Scalyr](#roarr-recipes-using-with-scalyr)
* [Documenting use of Roarr](#roarr-recipes-documenting-use-of-roarr)
<a name="roarr-motivation"></a>
## Motivation
For a long time I have been a big fan of using [`debug`](https://github.com/visionmedia/debug). `debug` is simple to use, works in Node.js and browser, does not require configuration and it is fast. However, problems arise when you need to parse logs. Anything but one-line text messages cannot be parsed in a safe way.
To log structured data, I have been using [Winston](https://github.com/winstonjs/winston) and [Bunyan](https://github.com/trentm/node-bunyan). These packages are great for application-level logging. I have preferred Bunyan because of the [Bunyan CLI program](https://github.com/trentm/node-bunyan#cli-usage) used to pretty-print logs. However, these packages require program-level configuration  when constructing an instance of a logger, you need to define the transport and the log-level. This makes them unsuitable for use in code designed to be consumed by other applications.
Then there is [pino](https://github.com/pinojs/pino). pino is fast JSON logger, it has CLI program equivalent to Bunyan, it decouples transports, and it has sane default configuration. Unfortunately, you still need to instantiate logger instance at the application-level. This makes it more suitable for application-level logging just like Winston and Bunyan.
I needed a logger that:
* Does not block the event cycle (=fast).
* Does not require initialisation.
* Produces structured data.
* [Decouples transports](#transports).
* Has a [CLI program](#cli-program).
* Works in Node.js and browser.
* Configurable using environment variables.
In other words,
* a logger that I can use in an application code and in dependencies.
* a logger that allows to correlate logs between the main application code and the dependency code.
* a logger that works well with transports in external processes.
Roarr is this logger.
<a name="roarr-usage"></a>
## Usage
<a name="roarr-usage-producing-logs"></a>
### Producing logs
Roarr logger API for producing logs is the same in Node.js and browser.
1. Import `roarr`
2. Use any of the [API](#api) methods to log messages.
Example:
```js
import log from 'roarr';
log('foo');
```
<a name="roarr-usage-consuming-logs"></a>
### Consuming logs
Roarr logs are consumed differently in Node.js and browser.
<a name="roarr-usage-consuming-logs-node-js"></a>
#### Node.js
In Node.js, Roarr logging is disabled by default. To enable logging, you must start program with an environment variable `ROARR_LOG` set to `true`, e.g.
```bash
ROARR_LOG=true node ./index.js
```
All logs will be written to stdout.
<a name="roarr-usage-consuming-logs-browser"></a>
#### Browser
In a browser, you must implement `ROARR.write` method to read logs, e.g.
```js
import {
ROARR,
} from 'roarr';
ROARR.write = () => {};
```
The API of the `ROARR.write` is:
```js
(message: string) => void;
```
Example implementation:
```js
import {
ROARR,
} from 'roarr';
ROARR.write = (message) => {
console.log(JSON.parse(message));
};
```
or if you are initializing `ROARR.write` _before_ `roarr` is loaded:
```js
// Ensure that `globalThis.ROARR` is configured.
const ROARR = globalThis.ROARR = globalThis.ROARR || {};
ROARR.write = (message) => {
console.log(JSON.parse(message));
};
```
If your platform does not support [`globalThis`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis), use [`globalthis` polyfill](https://www.npmjs.com/package/globalthis).
<a name="roarr-usage-filtering-logs"></a>
### Filtering logs
<a name="roarr-usage-filtering-logs-node-js-1"></a>
#### Node.js
In Node.js, Roarr prints all or none logs (refer to the [`ROARR_LOG` environment variable](#environment-variables) documentation).
Use [`roarr filter` CLI program](#filter-program) to filter the logs that are written to stdout by the program, e.g.
```bash
ROARR_LOG=true node ./index.js | roarr filter '{"context.logLevel":{gt:30}}'
```
Alternatively, use a JSON processor such as [jq](https://stedolan.github.io/jq/)
<a name="roarr-usage-filtering-logs-browser-1"></a>
#### Browser
In a browser, Roarr calls `globalThis.ROARR.write` for every log message. Implement your own custom logic to filter logs, e.g.
```js
globalThis.ROARR.write = (message) => {
const payload = JSON.parse(message);
if (payload.context.logLevel > 30) {
console.log(payload);
}
};
```
<a name="roarr-log-message-format"></a>
## Log message format
|Property name|Contents|
|---|---|
|`context`|Arbitrary, user-provided structured data. See [context property names](#context-property-names).|
|`message`|User-provided message formatted using [printf](https://en.wikipedia.org/wiki/Printf_format_string).|
|`sequence`|An incremental ID.|
|`time`|Unix timestamp in milliseconds.|
|`version`|Roarr log message format version.|
Example:
```js
{
"context": {
"application": "task-runner",
"hostname": "curiosity.local",
"instanceId": "01BVBK4ZJQ182ZWF6FK4EC8FEY",
"taskId": 1
},
"message": "starting task ID 1",
"sequence": 0,
"time": 1506776210000,
"version": "1.0.0"
}
```
<a name="roarr-api"></a>
## API
`roarr` package exports a function with the following API:
```js
export type LoggerType =
(
context: MessageContextType,
message: string,
c?: SprintfArgumentType,
d?: SprintfArgumentType,
e?: SprintfArgumentType,
f?: SprintfArgumentType,
g?: SprintfArgumentType,
h?: SprintfArgumentType,
i?: SprintfArgumentType,
k?: SprintfArgumentType
) => void |
(
message: string,
b?: SprintfArgumentType,
c?: SprintfArgumentType,
d?: SprintfArgumentType,
e?: SprintfArgumentType,
f?: SprintfArgumentType,
g?: SprintfArgumentType,
h?: SprintfArgumentType,
i?: SprintfArgumentType,
k?: SprintfArgumentType
) => void;
```
To put it into words:
* First parameter can be either a string (message) or an object.
* If first parameter is an object (context), the second parameter must be a string (message).
* Arguments after the message parameter are used to enable [printf message formatting](https://en.wikipedia.org/wiki/Printf_format_string).
* Printf arguments must be of a primitive type (`string | number | boolean | null`).
* There can be up to 9 printf arguments (or 8 if the first parameter is the context object).
Refer to the [Usage documentation](#usage) for common usage examples.
<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:
1. Accepts an object.
2. Accepts a function.
<a name="roarr-api-child-object-parameter"></a>
#### Object parameter
```js
(context: MessageContextType) => LoggerType;
```
Creates a child logger appending the provided `context` object to the previous logger context.
Example:
```js
import log from 'roarr';
const childLog = log.child({
foo: 'bar'
});
log.debug('foo 1');
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"}
```
Refer to [middlewares](#middlewares) documentation for use case examples.
<a name="roarr-api-child-function-parameter"></a>
#### Function parameter
```js
(translateMessage: TranslateMessageFunctionType) => LoggerType;
```
Creates a child logger where every message is intercepted.
Example:
```js
import log from 'roarr';
const childLog = log.child((message) => {
return {
...message,
message: message.message.replace('foo', 'bar'),
}
});
log.debug('foo 1');
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"}
```
<a name="roarr-api-getcontext"></a>
### <code>getContext</code>
Returns the current context.
Example:
```js
import log from 'roarr';
const childLogger = log.child({
foo: 'bar'
});
childLogger.getContext();
// {foo: 'bar'}
```
<a name="roarr-api-trace"></a>
### <code>trace</code>
<a name="roarr-api-debug"></a>
### <code>debug</code>
<a name="roarr-api-info"></a>
### <code>info</code>
<a name="roarr-api-warn"></a>
### <code>warn</code>
<a name="roarr-api-error"></a>
### <code>error</code>
<a name="roarr-api-fatal"></a>
### <code>fatal</code>
Convenience methods for logging a message with `logLevel` context property value set to a numeric value representing the [log level](#log-levels), e.g.
```js
import log from 'roarr';
log.trace('foo');
log.debug('foo');
log.info('foo');
log.warn('foo');
log.error('foo');
log.fatal('foo');
```
Produces output:
```
{"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"}
```
<a name="roarr-middlewares"></a>
## Middlewares
Roarr logger supports middlewares implemented as [`child`](#child) message translate functions, e.g.
```js
import log from 'roarr';
import createSerializeErrorMiddleware from '@roarr/middleware-serialize-error';
const childLog = log.child(createSerializeErrorMiddleware());
const error = new Error('foo');
log.debug({error}, 'bar');
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"}
```
Roarr middlwares enable translation of every bit of information that is used to construct a log message.
The following are the official middlewares:
* [`@roarr/middleware-serialize-error`](https://github.com/gajus/roarr-middleware-serialize-error)
Raise an issue to add your middleware of your own creation.
<a name="roarr-cli-program"></a>
## CLI program
Roarr CLI program provides ability to filter and pretty-print Roarr logs.
![CLI output demo](./.README/cli-output-demo.png)
CLI program has been moved to a separate package [`@roarr/cli`](https://github.com/gajus/roarr-cli).
```bash
npm install @roarr/cli -g
```
Explore all CLI commands and options using `roarr --help` or refer to [`@roarr/cli`](https://github.com/gajus/roarr-cli) documentation.
<a name="roarr-transports"></a>
## Transports
A transport in most logging libraries is something that runs in-process to perform some operation with the finalised log line. For example, a transport might send the log line to a standard syslog server after processing the log line and reformatting it.
Roarr does not support in-process transports.
Roarr does not support in-process transports because Node processes are single threaded processes (ignoring some technical details). Given this restriction, Roarr purposefully offloads handling of the logs to external processes so that the threading capabilities of the OS can be used (or other CPUs).
Depending on your configuration, consider one of the following log transports:
* [Beats](https://www.elastic.co/products/beats) for aggregating at a process level (written in Go).
* [logagent](https://github.com/sematext/logagent-js) for aggregating at a process level (written in JavaScript).
* [Fluentd](https://www.fluentd.org/) for aggregating logs at a container orchestration level (e.g. Kubernetes) (written in Ruby).
<a name="roarr-node-js-environment-variables"></a>
## Node.js environment variables
Use environment variables to control `roarr` behaviour.
|Name|Type|Function|Default|
|---|---|---|---|
|`ROARR_LOG`|Boolean|Enables/ disables logging.|`false`|
|`ROARR_STREAM`|`STDOUT`, `STDERR`|Name of the stream where the logs will be written.|`STDOUT`|
When using `ROARR_STREAM=STDERR`, use [`3>&1 1>&2 2>&3 3>&-`](https://stackoverflow.com/a/2381643/368691) to pipe stderr output.
<a name="roarr-conventions"></a>
## Conventions
<a name="roarr-conventions-context-property-names"></a>
### Context property names
Roarr does not have reserved context property names. However, I encourage use of the following conventions:
|Context property name|Use case|
|---|---|
|`application`|Name of the application (do not use in code intended for distribution; see `package` property instead).|
|`logLevel`|A numeric value indicating the [log level](#log-levels). See [API](#api) for the build-in loggers with a pre-set log-level.|
|`namespace`|Namespace within a package, e.g. function name. Treat the same way that you would construct namespaces when using the [`debug`](https://github.com/visionmedia/debug) package.|
|`package`|Name of the NPM package.|
The `roarr pretty-print` [CLI program](#cli-program) is using the context property names suggested in the conventions to pretty-print the logs for the developer inspection purposes.
<a name="roarr-conventions-context-property-names-log-levels"></a>
#### Log levels
The `roarr pretty-print` [CLI program](#cli-program) translates `logLevel` values to the following human-readable names:
|`logLevel`|Human-readable name|
|---|---|
|10|TRACE|
|20|DEBUG|
|30|INFO|
|40|WARN|
|50|ERROR|
|60|FATAL|
<a name="roarr-conventions-using-roarr-in-an-application"></a>
### Using Roarr in an application
To avoid code duplication, you can use a singleton pattern to export a logger instance with predefined context properties (e.g. describing the application).
I recommend to create a file `Logger.js` in the project directory. Inside this file create and export a child instance of Roarr with context parameters describing the project and the script instance, e.g.
```js
/**
* @file Example contents of a Logger.js file.
*/
import log from 'roarr';
const Logger = log.child({
// .foo property is going to appear only in the logs that are created using
// the current instance of a Roarr logger.
foo: 'bar'
});
export default Logger;
```
Roarr does not have reserved context property names. However, I encourage use of the [conventions](#conventions).
<a name="roarr-recipes"></a>
## Recipes
<a name="roarr-recipes-logging-errors"></a>
### Logging errors
This is not specific to Roarr this suggestion applies to any kind of logging.
If you want to include an instance of [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) in the context, you must serialize the error.
The least-error prone way to do this is to use an existing library, e.g. [`serialize-error`](https://www.npmjs.com/package/serialize-error).
```js
import log from 'roarr';
import serializeError from 'serialize-error';
// [..]
send((error, result) => {
if (error) {
log.error({
error: serializeError(error)
}, 'message not sent due to a remote error');
return;
}
// [..]
});
```
Without using serialisation, your errors will be logged without the error name and stack trace.
<a name="roarr-recipes-using-with-elasticsearch"></a>
### Using with Elasticsearch
If you are using [Elasticsearch](https://www.elastic.co/products/elasticsearch), you will want to create an [index template](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html).
The following serves as the ground work for the index template. It includes the main Roarr log message properties (context, message, time) and the context properties suggested in the [conventions](#conventions).
```json
{
"mappings": {
"log_message": {
"_source": {
"enabled": true
},
"dynamic": "strict",
"properties": {
"context": {
"dynamic": true,
"properties": {
"application": {
"type": "keyword"
},
"hostname": {
"type": "keyword"
},
"instanceId": {
"type": "keyword"
},
"logLevel": {
"type": "integer"
},
"namespace": {
"type": "text"
},
"package": {
"type": "text"
}
}
},
"message": {
"type": "text"
},
"time": {
"format": "epoch_millis",
"type": "date"
}
}
}
},
"template": "logstash-*"
}
```
<a name="roarr-recipes-using-with-scalyr"></a>
### Using with Scalyr
If you are using [Scalyr](https://www.scalyr.com/), you will want to create a custom parser `RoarrLogger`:
```js
{
patterns: {
tsPattern: "\\w{3},\\s\\d{2}\\s\\w{3}\\s\\d{4}\\s[\\d:]+",
tsPattern_8601: "\\d{4}-\\d{2}-\\d{2}T[\\d:.]+Z"
}
formats: [
{format: "${parse=json}$"},
{format: ".*\"time\":$timestamp=number$,.*"},
{format: "$timestamp=tsPattern$ GMT $detail$"},
{format: "$timestamp=tsPattern_8601$ $detail$"}
]
}
```
and configure the individual programs to use `RoarrLogger`. In case of Kubernetes, this means adding a `log.config.scalyr.com/attributes.parser: RoarrLogger` annotation to the associated deployment, pod or container.
<a name="roarr-recipes-documenting-use-of-roarr"></a>
### Documenting use of Roarr
If your package is using Roarr, include instructions in `README.md` describing how to enable logging, e.g.
```md
## Logging
This package is using [`roarr`](https://www.npmjs.com/package/roarr) logger to log the program's state.
Export `ROARR_LOG=true` environment variable to enable log printing to stdout.
Use [`roarr-cli`](https://github.com/gajus/roarr-cli) program to pretty-print the logs.
```

16
buildfiles/node_modules/roarr/dist/constants.js generated vendored Normal file
View File

@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.logLevels = void 0;
const logLevels = {
debug: 20,
error: 50,
fatal: 60,
info: 30,
trace: 10,
warn: 40
};
exports.logLevels = logLevels;
//# sourceMappingURL=constants.js.map

10
buildfiles/node_modules/roarr/dist/constants.js.flow generated vendored Normal file
View File

@ -0,0 +1,10 @@
// @flow
export const logLevels = {
debug: 20,
error: 50,
fatal: 60,
info: 30,
trace: 10,
warn: 40,
};

1
buildfiles/node_modules/roarr/dist/constants.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"sources":["../src/constants.js"],"names":["logLevels","debug","error","fatal","info","trace","warn"],"mappings":";;;;;;AAEO,MAAMA,SAAS,GAAG;AACvBC,EAAAA,KAAK,EAAE,EADgB;AAEvBC,EAAAA,KAAK,EAAE,EAFgB;AAGvBC,EAAAA,KAAK,EAAE,EAHgB;AAIvBC,EAAAA,IAAI,EAAE,EAJiB;AAKvBC,EAAAA,KAAK,EAAE,EALgB;AAMvBC,EAAAA,IAAI,EAAE;AANiB,CAAlB","sourcesContent":["// @flow\n\nexport const logLevels = {\n debug: 20,\n error: 50,\n fatal: 60,\n info: 30,\n trace: 10,\n warn: 40,\n};\n"],"file":"constants.js"}

View File

@ -0,0 +1,192 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _detectNode = _interopRequireDefault(require("detect-node"));
var _globalthis = _interopRequireDefault(require("globalthis"));
var _jsonStringifySafe = _interopRequireDefault(require("json-stringify-safe"));
var _sprintfJs = require("sprintf-js");
var _constants = require("../constants");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
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; }
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(_objectSpread({}, domainContext), parentRoarrContext);
}
return domainContext;
};
const getFirstParentDomainContext = () => {
if (!domain) {
return {};
}
let currentDomain = process.domain; // $FlowFixMe
if (currentDomain && currentDomain.roarr && currentDomain.roarr.context) {
return currentDomain.roarr.context;
} // $FlowFixMe
if (!currentDomain || !currentDomain.parentDomain) {
return {};
}
while (currentDomain && currentDomain.parentDomain) {
currentDomain = currentDomain.parentDomain;
if (currentDomain.roarr && currentDomain.roarr.context) {
return currentDomain.roarr.context;
}
}
return {};
};
const createLogger = (onMessage, parentContext) => {
// eslint-disable-next-line id-length, unicorn/prevent-abbreviations
const log = (a, b, c, d, e, f, g, h, i, k) => {
const time = Date.now();
const sequence = globalThis.ROARR.sequence++;
let context;
let message;
if (typeof a === 'string') {
context = _objectSpread(_objectSpread({}, getFirstParentDomainContext()), parentContext || {}); // eslint-disable-next-line id-length, object-property-newline
const args = _extends({}, {
a,
b,
c,
d,
e,
f,
g,
h,
i,
k
});
const values = Object.keys(args).map(key => {
return args[key];
}); // eslint-disable-next-line unicorn/no-reduce
const hasOnlyOneParameterValued = 1 === values.reduce((accumulator, value) => {
// eslint-disable-next-line no-return-assign, no-param-reassign
return accumulator += typeof value === 'undefined' ? 0 : 1;
}, 0);
message = hasOnlyOneParameterValued ? (0, _sprintfJs.sprintf)('%s', a) : (0, _sprintfJs.sprintf)(a, b, c, d, e, f, g, h, i, k);
} else {
if (typeof b !== 'string') {
throw new TypeError('Message must be a string.');
}
context = JSON.parse((0, _jsonStringifySafe.default)(_objectSpread(_objectSpread(_objectSpread({}, getFirstParentDomainContext()), parentContext || {}), a)));
message = (0, _sprintfJs.sprintf)(b, c, d, e, f, g, h, i, k);
}
onMessage({
context,
message,
sequence,
time,
version: '1.0.0'
});
};
log.child = context => {
if (typeof context === 'function') {
return createLogger(message => {
if (typeof context !== 'function') {
throw new TypeError('Unexpected state.');
}
onMessage(context(message));
}, parentContext);
}
return createLogger(onMessage, _objectSpread(_objectSpread(_objectSpread({}, getFirstParentDomainContext()), parentContext), context));
};
log.getContext = () => {
return _objectSpread(_objectSpread({}, getFirstParentDomainContext()), parentContext || {});
};
log.adopt = async (routine, context) => {
if (!domain) {
return routine();
}
const adoptedDomain = domain.create();
return adoptedDomain.run(() => {
// $FlowFixMe
adoptedDomain.roarr = {
context: _objectSpread(_objectSpread({}, getParentDomainContext()), context)
};
return routine();
});
};
for (const logLevel of Object.keys(_constants.logLevels)) {
// eslint-disable-next-line id-length, unicorn/prevent-abbreviations
log[logLevel] = (a, b, c, d, e, f, g, h, i, k) => {
return log.child({
logLevel: _constants.logLevels[logLevel]
})(a, b, c, d, e, f, g, h, i, k);
};
} // @see https://github.com/facebook/flow/issues/6705
// $FlowFixMe
return log;
};
var _default = createLogger;
exports.default = _default;
//# sourceMappingURL=createLogger.js.map

View File

@ -0,0 +1,197 @@
// @flow
import environmentIsNode from 'detect-node';
import createGlobalThis from 'globalthis';
import stringify from 'json-stringify-safe';
import {
sprintf,
} from 'sprintf-js';
import {
logLevels,
} from '../constants';
import type {
LoggerType,
MessageContextType,
MessageEventHandlerType,
TranslateMessageFunctionType,
} from '../types';
const globalThis = createGlobalThis();
let domain;
if (environmentIsNode) {
// 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 = {
...domainContext,
...parentRoarrContext,
};
}
return domainContext;
};
const getFirstParentDomainContext = () => {
if (!domain) {
return {};
}
let currentDomain = process.domain;
// $FlowFixMe
if (currentDomain && currentDomain.roarr && currentDomain.roarr.context) {
return currentDomain.roarr.context;
}
// $FlowFixMe
if (!currentDomain || !currentDomain.parentDomain) {
return {};
}
while (currentDomain && currentDomain.parentDomain) {
currentDomain = currentDomain.parentDomain;
if (currentDomain.roarr && currentDomain.roarr.context) {
return currentDomain.roarr.context;
}
}
return {};
};
const createLogger = (onMessage: MessageEventHandlerType, parentContext?: MessageContextType): LoggerType => {
// eslint-disable-next-line id-length, unicorn/prevent-abbreviations
const log = (a, b, c, d, e, f, g, h, i, k) => {
const time = Date.now();
const sequence = globalThis.ROARR.sequence++;
let context;
let message;
if (typeof a === 'string') {
context = {
...getFirstParentDomainContext(),
...parentContext || {},
};
// eslint-disable-next-line id-length, object-property-newline
const {...args} = {a, b, c, d, e, f, g, h, i, k};
const values = Object.keys(args).map((key) => {
return args[key];
});
// eslint-disable-next-line unicorn/no-reduce
const hasOnlyOneParameterValued = 1 === values.reduce((accumulator, value) => {
// eslint-disable-next-line no-return-assign, no-param-reassign
return accumulator += typeof value === 'undefined' ? 0 : 1;
}, 0);
message = hasOnlyOneParameterValued ? sprintf('%s', a) : sprintf(a, b, c, d, e, f, g, h, i, k);
} else {
if (typeof b !== 'string') {
throw new TypeError('Message must be a string.');
}
context = JSON.parse(stringify({
...getFirstParentDomainContext(),
...parentContext || {},
...a,
}));
message = sprintf(b, c, d, e, f, g, h, i, k);
}
onMessage({
context,
message,
sequence,
time,
version: '1.0.0',
});
};
log.child = (context: TranslateMessageFunctionType | MessageContextType): LoggerType => {
if (typeof context === 'function') {
return createLogger((message) => {
if (typeof context !== 'function') {
throw new TypeError('Unexpected state.');
}
onMessage(context(message));
}, parentContext);
}
return createLogger(onMessage, {
...getFirstParentDomainContext(),
...parentContext,
...context,
});
};
log.getContext = (): MessageContextType => {
return {
...getFirstParentDomainContext(),
...parentContext || {},
};
};
log.adopt = async (routine, context) => {
if (!domain) {
return routine();
}
const adoptedDomain = domain.create();
return adoptedDomain
.run(() => {
// $FlowFixMe
adoptedDomain.roarr = {
context: {
...getParentDomainContext(),
...context,
},
};
return routine();
});
};
for (const logLevel of Object.keys(logLevels)) {
// eslint-disable-next-line id-length, unicorn/prevent-abbreviations
log[logLevel] = (a, b, c, d, e, f, g, h, i, k) => {
return log.child({
logLevel: logLevels[logLevel],
})(a, b, c, d, e, f, g, h, i, k);
};
}
// @see https://github.com/facebook/flow/issues/6705
// $FlowFixMe
return log;
};
export default createLogger;

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _constants = require("../constants");
const createMockLogger = (onMessage, parentContext) => {
// eslint-disable-next-line id-length, unicorn/prevent-abbreviations, no-unused-vars
const log = (a, b, c, d, e, f, g, h, i, k) => {//
};
log.adopt = async routine => {
return routine();
}; // eslint-disable-next-line no-unused-vars
log.child = context => {
return createMockLogger(onMessage, parentContext);
};
log.getContext = () => {
return {};
};
for (const logLevel of Object.keys(_constants.logLevels)) {
// eslint-disable-next-line id-length, unicorn/prevent-abbreviations
log[logLevel] = (a, b, c, d, e, f, g, h, i, k) => {
return log.child({
logLevel: _constants.logLevels[logLevel]
})(a, b, c, d, e, f, g, h, i, k);
};
} // @see https://github.com/facebook/flow/issues/6705
// $FlowFixMe
return log;
};
var _default = createMockLogger;
exports.default = _default;
//# sourceMappingURL=createMockLogger.js.map

View File

@ -0,0 +1,46 @@
// @flow
import {
logLevels,
} from '../constants';
import type {
LoggerType,
MessageContextType,
MessageEventHandlerType,
TranslateMessageFunctionType,
} from '../types';
const createMockLogger = (onMessage: MessageEventHandlerType, parentContext?: MessageContextType): LoggerType => {
// eslint-disable-next-line id-length, unicorn/prevent-abbreviations, no-unused-vars
const log = (a, b, c, d, e, f, g, h, i, k) => {
//
};
log.adopt = async (routine) => {
return routine();
};
// eslint-disable-next-line no-unused-vars
log.child = (context: TranslateMessageFunctionType | MessageContextType): LoggerType => {
return createMockLogger(onMessage, parentContext);
};
log.getContext = (): MessageContextType => {
return {};
};
for (const logLevel of Object.keys(logLevels)) {
// eslint-disable-next-line id-length, unicorn/prevent-abbreviations
log[logLevel] = (a, b, c, d, e, f, g, h, i, k) => {
return log.child({
logLevel: logLevels[logLevel],
})(a, b, c, d, e, f, g, h, i, k);
};
}
// @see https://github.com/facebook/flow/issues/6705
// $FlowFixMe
return log;
};
export default createMockLogger;

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/factories/createMockLogger.js"],"names":["createMockLogger","onMessage","parentContext","log","a","b","c","d","e","f","g","h","i","k","adopt","routine","child","context","getContext","logLevel","Object","keys","logLevels"],"mappings":";;;;;;;AAEA;;AAUA,MAAMA,gBAAgB,GAAG,CAACC,SAAD,EAAqCC,aAArC,KAAwF;AAC/G;AACA,QAAMC,GAAG,GAAG,CAACC,CAAD,EAAIC,CAAJ,EAAOC,CAAP,EAAUC,CAAV,EAAaC,CAAb,EAAgBC,CAAhB,EAAmBC,CAAnB,EAAsBC,CAAtB,EAAyBC,CAAzB,EAA4BC,CAA5B,KAAkC,CAC5C;AACD,GAFD;;AAIAV,EAAAA,GAAG,CAACW,KAAJ,GAAY,MAAOC,OAAP,IAAmB;AAC7B,WAAOA,OAAO,EAAd;AACD,GAFD,CAN+G,CAU/G;;;AACAZ,EAAAA,GAAG,CAACa,KAAJ,GAAaC,OAAD,IAA4E;AACtF,WAAOjB,gBAAgB,CAACC,SAAD,EAAYC,aAAZ,CAAvB;AACD,GAFD;;AAIAC,EAAAA,GAAG,CAACe,UAAJ,GAAiB,MAA0B;AACzC,WAAO,EAAP;AACD,GAFD;;AAIA,OAAK,MAAMC,QAAX,IAAuBC,MAAM,CAACC,IAAP,CAAYC,oBAAZ,CAAvB,EAA+C;AAC7C;AACAnB,IAAAA,GAAG,CAACgB,QAAD,CAAH,GAAgB,CAACf,CAAD,EAAIC,CAAJ,EAAOC,CAAP,EAAUC,CAAV,EAAaC,CAAb,EAAgBC,CAAhB,EAAmBC,CAAnB,EAAsBC,CAAtB,EAAyBC,CAAzB,EAA4BC,CAA5B,KAAkC;AAChD,aAAOV,GAAG,CAACa,KAAJ,CAAU;AACfG,QAAAA,QAAQ,EAAEG,qBAAUH,QAAV;AADK,OAAV,EAEJf,CAFI,EAEDC,CAFC,EAEEC,CAFF,EAEKC,CAFL,EAEQC,CAFR,EAEWC,CAFX,EAEcC,CAFd,EAEiBC,CAFjB,EAEoBC,CAFpB,EAEuBC,CAFvB,CAAP;AAGD,KAJD;AAKD,GA1B8G,CA4B/G;AACA;;;AACA,SAAOV,GAAP;AACD,CA/BD;;eAiCeH,gB","sourcesContent":["// @flow\n\nimport {\n logLevels,\n} from '../constants';\nimport type {\n LoggerType,\n MessageContextType,\n MessageEventHandlerType,\n TranslateMessageFunctionType,\n} from '../types';\n\nconst createMockLogger = (onMessage: MessageEventHandlerType, parentContext?: MessageContextType): LoggerType => {\n // eslint-disable-next-line id-length, unicorn/prevent-abbreviations, no-unused-vars\n const log = (a, b, c, d, e, f, g, h, i, k) => {\n //\n };\n\n log.adopt = async (routine) => {\n return routine();\n };\n\n // eslint-disable-next-line no-unused-vars\n log.child = (context: TranslateMessageFunctionType | MessageContextType): LoggerType => {\n return createMockLogger(onMessage, parentContext);\n };\n\n log.getContext = (): MessageContextType => {\n return {};\n };\n\n for (const logLevel of Object.keys(logLevels)) {\n // eslint-disable-next-line id-length, unicorn/prevent-abbreviations\n log[logLevel] = (a, b, c, d, e, f, g, h, i, k) => {\n return log.child({\n logLevel: logLevels[logLevel],\n })(a, b, c, d, e, f, g, h, i, k);\n };\n }\n\n // @see https://github.com/facebook/flow/issues/6705\n // $FlowFixMe\n return log;\n};\n\nexport default createMockLogger;\n"],"file":"createMockLogger.js"}

View File

@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
const createBlockingWriter = stream => {
return {
write: message => {
stream.write(message + '\n');
}
};
};
const createNodeWriter = () => {
// eslint-disable-next-line no-process-env
const targetStream = (process.env.ROARR_STREAM || 'STDOUT').toUpperCase();
const stream = targetStream.toUpperCase() === 'STDOUT' ? process.stdout : process.stderr;
return createBlockingWriter(stream);
};
var _default = createNodeWriter;
exports.default = _default;
//# sourceMappingURL=createNodeWriter.js.map

View File

@ -0,0 +1,22 @@
// @flow
import type {
WriterType,
} from '../types';
const createBlockingWriter = (stream: stream$Writable): WriterType => {
return {
write: (message: string) => {
stream.write(message + '\n');
},
};
};
export default (): WriterType => {
// eslint-disable-next-line no-process-env
const targetStream = (process.env.ROARR_STREAM || 'STDOUT').toUpperCase();
const stream = targetStream.toUpperCase() === 'STDOUT' ? process.stdout : process.stderr;
return createBlockingWriter(stream);
};

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/factories/createNodeWriter.js"],"names":["createBlockingWriter","stream","write","message","targetStream","process","env","ROARR_STREAM","toUpperCase","stdout","stderr"],"mappings":";;;;;;;AAMA,MAAMA,oBAAoB,GAAIC,MAAD,IAAyC;AACpE,SAAO;AACLC,IAAAA,KAAK,EAAGC,OAAD,IAAqB;AAC1BF,MAAAA,MAAM,CAACC,KAAP,CAAaC,OAAO,GAAG,IAAvB;AACD;AAHI,GAAP;AAKD,CAND;;+BAQiC;AAC/B;AACA,QAAMC,YAAY,GAAG,CAACC,OAAO,CAACC,GAAR,CAAYC,YAAZ,IAA4B,QAA7B,EAAuCC,WAAvC,EAArB;AAEA,QAAMP,MAAM,GAAGG,YAAY,CAACI,WAAb,OAA+B,QAA/B,GAA0CH,OAAO,CAACI,MAAlD,GAA2DJ,OAAO,CAACK,MAAlF;AAEA,SAAOV,oBAAoB,CAACC,MAAD,CAA3B;AACD,C","sourcesContent":["// @flow\n\nimport type {\n WriterType,\n} from '../types';\n\nconst createBlockingWriter = (stream: stream$Writable): WriterType => {\n return {\n write: (message: string) => {\n stream.write(message + '\\n');\n },\n };\n};\n\nexport default (): WriterType => {\n // eslint-disable-next-line no-process-env\n const targetStream = (process.env.ROARR_STREAM || 'STDOUT').toUpperCase();\n\n const stream = targetStream.toUpperCase() === 'STDOUT' ? process.stdout : process.stderr;\n\n return createBlockingWriter(stream);\n};\n"],"file":"createNodeWriter.js"}

View File

@ -0,0 +1,53 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _detectNode = _interopRequireDefault(require("detect-node"));
var _semverCompare = _interopRequireDefault(require("semver-compare"));
var _package = require("../../package.json");
var _createNodeWriter = _interopRequireDefault(require("./createNodeWriter"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
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; }
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; }
// eslint-disable-next-line flowtype/no-weak-types
const createRoarrInititialGlobalState = currentState => {
const versions = (currentState.versions || []).concat();
versions.sort(_semverCompare.default);
const currentIsLatestVersion = !versions.length || (0, _semverCompare.default)(_package.version, versions[versions.length - 1]) === 1;
if (!versions.includes(_package.version)) {
versions.push(_package.version);
}
versions.sort(_semverCompare.default);
let newState = _objectSpread(_objectSpread({
sequence: 0
}, currentState), {}, {
versions
});
if (_detectNode.default) {
if (currentIsLatestVersion || !newState.write) {
newState = _objectSpread(_objectSpread({}, newState), (0, _createNodeWriter.default)());
}
}
return newState;
};
var _default = createRoarrInititialGlobalState;
exports.default = _default;
//# sourceMappingURL=createRoarrInititialGlobalState.js.map

View File

@ -0,0 +1,43 @@
// @flow
import environmentIsNode from 'detect-node';
import cmp from 'semver-compare';
import {
version,
} from '../../package.json';
import type {
RoarrGlobalStateType,
} from '../types';
import createNodeWriter from './createNodeWriter';
// eslint-disable-next-line flowtype/no-weak-types
export default (currentState: Object): RoarrGlobalStateType => {
const versions = (currentState.versions || []).concat();
versions.sort(cmp);
const currentIsLatestVersion = !versions.length || cmp(version, versions[versions.length - 1]) === 1;
if (!versions.includes(version)) {
versions.push(version);
}
versions.sort(cmp);
let newState = {
sequence: 0,
...currentState,
versions,
};
if (environmentIsNode) {
if (currentIsLatestVersion || !newState.write) {
newState = {
...newState,
...createNodeWriter(),
};
}
}
return newState;
};

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/factories/createRoarrInititialGlobalState.js"],"names":["currentState","versions","concat","sort","cmp","currentIsLatestVersion","length","version","includes","push","newState","sequence","environmentIsNode","write"],"mappings":";;;;;;;AAEA;;AACA;;AACA;;AAMA;;;;;;;;;;AAEA;wCACgBA,Y,IAA+C;AAC7D,QAAMC,QAAQ,GAAG,CAACD,YAAY,CAACC,QAAb,IAAyB,EAA1B,EAA8BC,MAA9B,EAAjB;AAEAD,EAAAA,QAAQ,CAACE,IAAT,CAAcC,sBAAd;AAEA,QAAMC,sBAAsB,GAAG,CAACJ,QAAQ,CAACK,MAAV,IAAoB,4BAAIC,gBAAJ,EAAaN,QAAQ,CAACA,QAAQ,CAACK,MAAT,GAAkB,CAAnB,CAArB,MAAgD,CAAnG;;AAEA,MAAI,CAACL,QAAQ,CAACO,QAAT,CAAkBD,gBAAlB,CAAL,EAAiC;AAC/BN,IAAAA,QAAQ,CAACQ,IAAT,CAAcF,gBAAd;AACD;;AAEDN,EAAAA,QAAQ,CAACE,IAAT,CAAcC,sBAAd;;AAEA,MAAIM,QAAQ;AACVC,IAAAA,QAAQ,EAAE;AADA,KAEPX,YAFO;AAGVC,IAAAA;AAHU,IAAZ;;AAMA,MAAIW,mBAAJ,EAAuB;AACrB,QAAIP,sBAAsB,IAAI,CAACK,QAAQ,CAACG,KAAxC,EAA+C;AAC7CH,MAAAA,QAAQ,mCACHA,QADG,GAEH,gCAFG,CAAR;AAID;AACF;;AAED,SAAOA,QAAP;AACD,C","sourcesContent":["// @flow\n\nimport environmentIsNode from 'detect-node';\nimport cmp from 'semver-compare';\nimport {\n version,\n} from '../../package.json';\nimport type {\n RoarrGlobalStateType,\n} from '../types';\nimport createNodeWriter from './createNodeWriter';\n\n// eslint-disable-next-line flowtype/no-weak-types\nexport default (currentState: Object): RoarrGlobalStateType => {\n const versions = (currentState.versions || []).concat();\n\n versions.sort(cmp);\n\n const currentIsLatestVersion = !versions.length || cmp(version, versions[versions.length - 1]) === 1;\n\n if (!versions.includes(version)) {\n versions.push(version);\n }\n\n versions.sort(cmp);\n\n let newState = {\n sequence: 0,\n ...currentState,\n versions,\n };\n\n if (environmentIsNode) {\n if (currentIsLatestVersion || !newState.write) {\n newState = {\n ...newState,\n ...createNodeWriter(),\n };\n }\n }\n\n return newState;\n};\n"],"file":"createRoarrInititialGlobalState.js"}

32
buildfiles/node_modules/roarr/dist/factories/index.js generated vendored Normal file
View File

@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "createLogger", {
enumerable: true,
get: function () {
return _createLogger.default;
}
});
Object.defineProperty(exports, "createMockLogger", {
enumerable: true,
get: function () {
return _createMockLogger.default;
}
});
Object.defineProperty(exports, "createRoarrInititialGlobalState", {
enumerable: true,
get: function () {
return _createRoarrInititialGlobalState.default;
}
});
var _createLogger = _interopRequireDefault(require("./createLogger"));
var _createMockLogger = _interopRequireDefault(require("./createMockLogger"));
var _createRoarrInititialGlobalState = _interopRequireDefault(require("./createRoarrInititialGlobalState"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1,11 @@
// @flow
export {
default as createLogger,
} from './createLogger';
export {
default as createMockLogger,
} from './createMockLogger';
export {
default as createRoarrInititialGlobalState,
} from './createRoarrInititialGlobalState';

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/factories/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAEA;;AAGA;;AAGA","sourcesContent":["// @flow\n\nexport {\n default as createLogger,\n} from './createLogger';\nexport {\n default as createMockLogger,\n} from './createMockLogger';\nexport {\n default as createRoarrInititialGlobalState,\n} from './createRoarrInititialGlobalState';\n"],"file":"index.js"}

42
buildfiles/node_modules/roarr/dist/log.js generated vendored Normal file
View File

@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.ROARR = void 0;
var _boolean = require("boolean");
var _detectNode = _interopRequireDefault(require("detect-node"));
var _globalthis = _interopRequireDefault(require("globalthis"));
var _factories = require("./factories");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const globalThis = (0, _globalthis.default)();
const ROARR = globalThis.ROARR = (0, _factories.createRoarrInititialGlobalState)(globalThis.ROARR || {});
exports.ROARR = ROARR;
let logFactory = _factories.createLogger;
if (_detectNode.default) {
// eslint-disable-next-line no-process-env
const enabled = (0, _boolean.boolean)(process.env.ROARR_LOG || '');
if (!enabled) {
logFactory = _factories.createMockLogger;
}
}
var _default = logFactory(message => {
if (ROARR.write) {
// Stringify message as soon as it is received to prevent
// properties of the context from being modified by reference.
const body = JSON.stringify(message);
ROARR.write(body);
}
});
exports.default = _default;
//# sourceMappingURL=log.js.map

47
buildfiles/node_modules/roarr/dist/log.js.flow generated vendored Normal file
View File

@ -0,0 +1,47 @@
// @flow
import {
boolean,
} from 'boolean';
import environmentIsNode from 'detect-node';
import createGlobalThis from 'globalthis';
import {
createLogger,
createMockLogger,
createRoarrInititialGlobalState,
} from './factories';
const globalThis = createGlobalThis();
const ROARR = globalThis.ROARR = createRoarrInititialGlobalState(globalThis.ROARR || {});
let logFactory = createLogger;
if (environmentIsNode) {
// eslint-disable-next-line no-process-env
const enabled = boolean(process.env.ROARR_LOG || '');
if (!enabled) {
logFactory = createMockLogger;
}
}
export type {
LoggerType,
MessageType,
TranslateMessageFunctionType,
} from './types';
export {
ROARR,
};
export default logFactory((message) => {
if (ROARR.write) {
// Stringify message as soon as it is received to prevent
// properties of the context from being modified by reference.
const body = JSON.stringify(message);
ROARR.write(body);
}
});

1
buildfiles/node_modules/roarr/dist/log.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"sources":["../src/log.js"],"names":["globalThis","ROARR","logFactory","createLogger","environmentIsNode","enabled","process","env","ROARR_LOG","createMockLogger","message","write","body","JSON","stringify"],"mappings":";;;;;;;AAEA;;AAGA;;AACA;;AACA;;;;AAMA,MAAMA,UAAU,GAAG,0BAAnB;AAEA,MAAMC,KAAK,GAAGD,UAAU,CAACC,KAAX,GAAmB,gDAAgCD,UAAU,CAACC,KAAX,IAAoB,EAApD,CAAjC;;AAEA,IAAIC,UAAU,GAAGC,uBAAjB;;AAEA,IAAIC,mBAAJ,EAAuB;AACrB;AACA,QAAMC,OAAO,GAAG,sBAAQC,OAAO,CAACC,GAAR,CAAYC,SAAZ,IAAyB,EAAjC,CAAhB;;AAEA,MAAI,CAACH,OAAL,EAAc;AACZH,IAAAA,UAAU,GAAGO,2BAAb;AACD;AACF;;eAYcP,UAAU,CAAEQ,OAAD,IAAa;AACrC,MAAIT,KAAK,CAACU,KAAV,EAAiB;AACf;AACA;AACA,UAAMC,IAAI,GAAGC,IAAI,CAACC,SAAL,CAAeJ,OAAf,CAAb;AAEAT,IAAAA,KAAK,CAACU,KAAN,CAAYC,IAAZ;AACD;AACF,CARwB,C","sourcesContent":["// @flow\n\nimport {\n boolean,\n} from 'boolean';\nimport environmentIsNode from 'detect-node';\nimport createGlobalThis from 'globalthis';\nimport {\n createLogger,\n createMockLogger,\n createRoarrInititialGlobalState,\n} from './factories';\n\nconst globalThis = createGlobalThis();\n\nconst ROARR = globalThis.ROARR = createRoarrInititialGlobalState(globalThis.ROARR || {});\n\nlet logFactory = createLogger;\n\nif (environmentIsNode) {\n // eslint-disable-next-line no-process-env\n const enabled = boolean(process.env.ROARR_LOG || '');\n\n if (!enabled) {\n logFactory = createMockLogger;\n }\n}\n\nexport type {\n LoggerType,\n MessageType,\n TranslateMessageFunctionType,\n} from './types';\n\nexport {\n ROARR,\n};\n\nexport default logFactory((message) => {\n if (ROARR.write) {\n // Stringify message as soon as it is received to prevent\n // properties of the context from being modified by reference.\n const body = JSON.stringify(message);\n\n ROARR.write(body);\n }\n});\n"],"file":"log.js"}

2
buildfiles/node_modules/roarr/dist/types.js generated vendored Normal file
View File

@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=types.js.map

81
buildfiles/node_modules/roarr/dist/types.js.flow generated vendored Normal file
View File

@ -0,0 +1,81 @@
// @flow
/* eslint-disable import/exports-last, flowtype/require-types-at-top */
export type SerializableValueType = string | number | boolean | null | {+[key: string]: SerializableValueType, ...} | $ReadOnlyArray<SerializableValueType>;
export type SerializableObjectType = {
+[key: string]: SerializableValueType,
...
};
export type WriterType = {|
+write: (message: string) => void,
|};
export type RoarrGlobalStateType = {|
sequence: number,
versions: $ReadOnlyArray<string>,
...WriterType,
|};
export type SprintfArgumentType = string | number | boolean | null;
// eslint-disable-next-line flowtype/no-weak-types
export type MessageContextType = Object;
export type MessageType = {|
+context: MessageContextType,
+message: string,
+sequence: number,
+time: number,
+version: string,
|};
export type TranslateMessageFunctionType = (message: MessageType) => MessageType;
declare function Logger (
context: MessageContextType,
message: string,
c?: SprintfArgumentType,
d?: SprintfArgumentType,
e?: SprintfArgumentType,
f?: SprintfArgumentType,
g?: SprintfArgumentType,
h?: SprintfArgumentType,
i?: SprintfArgumentType,
k?: SprintfArgumentType
): void;
// eslint-disable-next-line no-redeclare
declare function Logger (
message: string,
b?: SprintfArgumentType,
c?: SprintfArgumentType,
d?: SprintfArgumentType,
e?: SprintfArgumentType,
f?: SprintfArgumentType,
g?: SprintfArgumentType,
h?: SprintfArgumentType,
i?: SprintfArgumentType,
k?: SprintfArgumentType
): void;
/**
* see https://twitter.com/kuizinas/status/914139352908943360
*/
export type LoggerType = {|
// eslint-disable-next-line no-undef
[[call]]: typeof Logger,
+adopt: <T>(routine: () => Promise<T>, context: MessageContextType) => Promise<T>,
+child: (context: TranslateMessageFunctionType | MessageContextType) => LoggerType,
+debug: typeof Logger,
+error: typeof Logger,
+fatal: typeof Logger,
+getContext: () => MessageContextType,
+info: typeof Logger,
+trace: typeof Logger,
+warn: typeof Logger,
|};
export type MessageEventHandlerType = (message: MessageType) => void;

1
buildfiles/node_modules/roarr/dist/types.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"types.js"}

122
buildfiles/node_modules/roarr/package.json generated vendored Normal file
View File

@ -0,0 +1,122 @@
{
"_from": "roarr@^2.15.3",
"_id": "roarr@2.15.4",
"_inBundle": false,
"_integrity": "sha512-CHhPh+UNHD2GTXNYhPWLnU8ONHdI+5DI+4EYIAOaiD63rHeYlZvyh8P+in5999TTSFgUYuKUAjzRI4mdh/p+2A==",
"_location": "/roarr",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "roarr@^2.15.3",
"name": "roarr",
"escapedName": "roarr",
"rawSpec": "^2.15.3",
"saveSpec": null,
"fetchSpec": "^2.15.3"
},
"_requiredBy": [
"/global-agent"
],
"_resolved": "https://registry.npmjs.org/roarr/-/roarr-2.15.4.tgz",
"_shasum": "f5fe795b7b838ccfe35dc608e0282b9eba2e7afd",
"_spec": "roarr@^2.15.3",
"_where": "/home/shihaam/www/freezer.shihaam.me/node_modules/global-agent",
"author": {
"name": "Gajus Kuizinas",
"email": "gajus@gajus.com",
"url": "http://gajus.com"
},
"ava": {
"babel": {
"compileAsTests": [
"test/helpers/**/*"
]
},
"files": [
"test/roarr/**/*"
],
"require": [
"@babel/register"
]
},
"bugs": {
"url": "https://github.com/gajus/roarr/issues"
},
"bundleDependencies": false,
"dependencies": {
"boolean": "^3.0.1",
"detect-node": "^2.0.4",
"globalthis": "^1.0.1",
"json-stringify-safe": "^5.0.1",
"semver-compare": "^1.0.0",
"sprintf-js": "^1.1.2"
},
"deprecated": false,
"description": "JSON logger for Node.js and browser.",
"devDependencies": {
"@ava/babel": "^1.0.1",
"@babel/cli": "^7.11.6",
"@babel/core": "^7.11.6",
"@babel/node": "^7.10.5",
"@babel/plugin-transform-flow-strip-types": "^7.10.4",
"@babel/preset-env": "^7.11.5",
"@babel/register": "^7.11.5",
"ava": "^3.12.1",
"babel-plugin-istanbul": "^6.0.0",
"babel-plugin-transform-export-default-name": "^2.0.4",
"coveralls": "^3.1.0",
"domain-parent": "^1.0.0",
"eslint": "^7.9.0",
"eslint-config-canonical": "^24.1.1",
"flow-bin": "^0.133.0",
"flow-copy-source": "^2.0.9",
"gitdown": "^3.1.3",
"husky": "^4.3.0",
"nyc": "^15.1.0",
"semantic-release": "^17.1.1"
},
"engines": {
"node": ">=8.0"
},
"homepage": "https://github.com/gajus/roarr#readme",
"husky": {
"hooks": {
"pre-commit": "npm run lint && npm run test && npm run build",
"pre-push": "gitdown ./.README/README.md --output-file ./README.md --check"
}
},
"keywords": [
"log",
"logger",
"json"
],
"license": "BSD-3-Clause",
"main": "./dist/log.js",
"name": "roarr",
"nyc": {
"include": [
"src/**/*.js"
],
"instrument": false,
"reporter": [
"text-lcov"
],
"require": [
"@babel/register"
],
"sourceMap": false
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/gajus/roarr.git"
},
"scripts": {
"build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps && flow-copy-source src dist",
"create-readme": "gitdown ./.README/README.md --output-file ./README.md",
"dev": "NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps --watch",
"lint": "eslint ./src ./test && flow",
"test": "NODE_ENV=test ava --serial --verbose"
},
"version": "2.15.4"
}