| export declare const logLevels: { | ||
| debug: number; | ||
| error: number; | ||
| fatal: number; | ||
| info: number; | ||
| trace: number; | ||
| warn: number; | ||
| }; |
| import type { Logger, MessageContextType, MessageEventHandlerType } from '../types'; | ||
| declare const createLogger: (onMessage: MessageEventHandlerType, parentContext?: MessageContextType) => Logger; | ||
| export default createLogger; |
| import type { Logger, MessageContextType, MessageEventHandlerType } from '../types'; | ||
| declare const createMockLogger: (onMessage: MessageEventHandlerType, parentContext?: MessageContextType) => Logger; | ||
| export default createMockLogger; |
| import type { WriterType } from '../types'; | ||
| declare const _default: () => WriterType; | ||
| export default _default; |
| import type { RoarrGlobalStateType } from '../types'; | ||
| declare const _default: (currentState: any) => RoarrGlobalStateType; | ||
| export default _default; |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const detect_node_1 = __importDefault(require("detect-node")); | ||
| const semver_compare_1 = __importDefault(require("semver-compare")); | ||
| const package_json_1 = require("../../package.json"); | ||
| const createNodeWriter_1 = __importDefault(require("./createNodeWriter")); | ||
| exports.default = (currentState) => { | ||
| const versions = (currentState.versions || []).concat(); | ||
| versions.sort(semver_compare_1.default); | ||
| const currentIsLatestVersion = !versions.length || semver_compare_1.default(package_json_1.version, versions[versions.length - 1]) === 1; | ||
| if (!versions.includes(package_json_1.version)) { | ||
| versions.push(package_json_1.version); | ||
| } | ||
| versions.sort(semver_compare_1.default); | ||
| let newState = { | ||
| sequence: 0, | ||
| ...currentState, | ||
| versions, | ||
| }; | ||
| if (detect_node_1.default) { | ||
| if (currentIsLatestVersion || !newState.write) { | ||
| newState = { | ||
| ...newState, | ||
| ...createNodeWriter_1.default(), | ||
| }; | ||
| } | ||
| } | ||
| return newState; | ||
| }; |
| export { default as createLogger, } from './createLogger'; | ||
| export { default as createMockLogger, } from './createMockLogger'; | ||
| export { default as createRoarrInitialGlobalState, } from './createRoarrInitialGlobalState'; |
| import type { RoarrGlobalStateType } from './types'; | ||
| declare const ROARR: RoarrGlobalStateType; | ||
| export type { Logger, MessageType, TranslateMessageFunctionType, } from './types'; | ||
| export { ROARR, }; | ||
| declare const _default: import("./types").Logger; | ||
| export default _default; |
| export interface WriterType { | ||
| write: (message: string) => void; | ||
| } | ||
| export interface RoarrGlobalStateType extends WriterType { | ||
| sequence: number; | ||
| versions: ReadonlyArray<string>; | ||
| } | ||
| export declare type SprintfArgumentType = string | number | boolean | null; | ||
| export declare type MessageContextType = any; | ||
| export declare type MessageType = { | ||
| readonly context: MessageContextType; | ||
| readonly message: string; | ||
| readonly sequence: number; | ||
| readonly time: number; | ||
| readonly version: string; | ||
| }; | ||
| export declare type TranslateMessageFunctionType = (message: MessageType) => MessageType; | ||
| export declare type LogMethod = { | ||
| (context: MessageContextType, message: string, c?: SprintfArgumentType, d?: SprintfArgumentType, e?: SprintfArgumentType, f?: SprintfArgumentType, g?: SprintfArgumentType, h?: SprintfArgumentType, i?: SprintfArgumentType, j?: SprintfArgumentType): void; | ||
| (message: string, b?: SprintfArgumentType, c?: SprintfArgumentType, d?: SprintfArgumentType, e?: SprintfArgumentType, f?: SprintfArgumentType, g?: SprintfArgumentType, h?: SprintfArgumentType, i?: SprintfArgumentType, j?: SprintfArgumentType): void; | ||
| }; | ||
| export interface Logger extends LogMethod { | ||
| adopt: <T>(routine: () => Promise<T>, context: MessageContextType) => Promise<T>; | ||
| child: (context: TranslateMessageFunctionType | MessageContextType) => LogMethod; | ||
| debug: LogMethod; | ||
| error: LogMethod; | ||
| fatal: LogMethod; | ||
| getContext: () => MessageContextType; | ||
| info: LogMethod; | ||
| trace: LogMethod; | ||
| warn: LogMethod; | ||
| } | ||
| export declare type MessageEventHandlerType = (message: MessageType) => void; |
| { | ||
| "compilerOptions": { | ||
| "allowSyntheticDefaultImports": true, | ||
| "declaration": true, | ||
| "esModuleInterop": true, | ||
| "lib": [ | ||
| "es2020" | ||
| ], | ||
| "module": "commonjs", | ||
| "moduleResolution": "node", | ||
| "noImplicitAny": false, | ||
| "noImplicitReturns": true, | ||
| "noUnusedLocals": true, | ||
| "noUnusedParameters": false, | ||
| "outDir": "dist", | ||
| "skipLibCheck": true, | ||
| "strict": true, | ||
| "target": "es2020" | ||
| }, | ||
| "exclude": [ | ||
| "dist", | ||
| "node_modules" | ||
| ], | ||
| "include": [ | ||
| "src" | ||
| ] | ||
| } |
+8
-13
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| 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 = { | ||
| debug: 20, | ||
| error: 50, | ||
| fatal: 60, | ||
| info: 30, | ||
| trace: 10, | ||
| warn: 40, | ||
| }; | ||
| exports.logLevels = logLevels; | ||
| //# sourceMappingURL=constants.js.map |
+162
-178
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.default = void 0; | ||
| var _detectNode = _interopRequireDefault(require("detect-node")); | ||
| var _globalthis = _interopRequireDefault(require("globalthis")); | ||
| var _isCircular = _interopRequireDefault(require("is-circular")); | ||
| var _jsonStringifySafe = _interopRequireDefault(require("json-stringify-safe")); | ||
| var _sprintfit = require("sprintfit"); | ||
| var _constants = require("../constants"); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| const globalThis = (0, _globalthis.default)(); | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const detect_node_1 = __importDefault(require("detect-node")); | ||
| const globalthis_1 = __importDefault(require("globalthis")); | ||
| const is_circular_1 = __importDefault(require("is-circular")); | ||
| const json_stringify_safe_1 = __importDefault(require("json-stringify-safe")); | ||
| const sprintfit_1 = require("sprintfit"); | ||
| const constants_1 = require("../constants"); | ||
| const globalThis = globalthis_1.default(); | ||
| let domain; | ||
| if (_detectNode.default) { | ||
| // eslint-disable-next-line node/global-require | ||
| domain = require('domain'); | ||
| if (detect_node_1.default) { | ||
| // eslint-disable-next-line node/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); | ||
| if (!domain) { | ||
| return {}; | ||
| } | ||
| } | ||
| let domainContext = {}; | ||
| for (const parentRoarrContext of parentRoarrContexts) { | ||
| domainContext = { ...domainContext, | ||
| ...parentRoarrContext | ||
| }; | ||
| } | ||
| return domainContext; | ||
| const parentRoarrContexts = []; | ||
| let currentDomain = process.domain; | ||
| if (!currentDomain?.parentDomain) { | ||
| return {}; | ||
| } | ||
| while (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) { | ||
| if (!domain) { | ||
| return {}; | ||
| } | ||
| let currentDomain = process.domain; | ||
| if (currentDomain && currentDomain.roarr && currentDomain.roarr.context) { | ||
| return currentDomain.roarr.context; | ||
| } | ||
| if (!currentDomain || !currentDomain.parentDomain) { | ||
| return {}; | ||
| } | ||
| while (currentDomain && currentDomain.parentDomain) { | ||
| currentDomain = currentDomain.parentDomain; | ||
| if (currentDomain.roarr && currentDomain.roarr.context) { | ||
| return currentDomain.roarr.context; | ||
| } | ||
| } | ||
| 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 defaultContext = {}; | ||
| 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') { | ||
| if (!domain || process.domain === null) { | ||
| context = parentContext || defaultContext; | ||
| } else { | ||
| context = { ...getFirstParentDomainContext(), | ||
| ...parentContext | ||
| }; | ||
| } | ||
| } else { | ||
| context = { ...getFirstParentDomainContext(), | ||
| ...parentContext, | ||
| ...a | ||
| }; | ||
| } | ||
| if (context !== defaultContext && (0, _isCircular.default)(context)) { | ||
| context = JSON.parse((0, _jsonStringifySafe.default)(context)); | ||
| } | ||
| if (typeof a === 'string' && b === undefined) { | ||
| message = a; | ||
| } else if (typeof a === 'string') { | ||
| message = (0, _sprintfit.sprintf)(a, b, c, d, e, f, g, h, i, k); | ||
| } else { | ||
| if (typeof b !== 'string') { | ||
| throw new TypeError('Message must be a string.'); | ||
| } | ||
| message = (0, _sprintfit.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.'); | ||
| const log = (a, b, c, d, e, f, g, h, i, j) => { | ||
| const time = Date.now(); | ||
| const sequence = globalThis.ROARR.sequence++; | ||
| let context; | ||
| let message; | ||
| if (typeof a === 'string') { | ||
| if (!domain || process.domain === null) { | ||
| context = parentContext || defaultContext; | ||
| } | ||
| else { | ||
| context = { | ||
| ...getFirstParentDomainContext(), | ||
| ...parentContext, | ||
| }; | ||
| } | ||
| } | ||
| onMessage(context(message)); | ||
| }, parentContext); | ||
| } | ||
| return createLogger(onMessage, { ...getFirstParentDomainContext(), | ||
| ...parentContext, | ||
| ...context | ||
| }); | ||
| }; | ||
| log.getContext = () => { | ||
| return { ...getFirstParentDomainContext(), | ||
| ...(parentContext || defaultContext) | ||
| else { | ||
| context = { | ||
| ...getFirstParentDomainContext(), | ||
| ...parentContext, | ||
| ...a, | ||
| }; | ||
| } | ||
| if (context !== defaultContext && is_circular_1.default(context)) { | ||
| context = JSON.parse(json_stringify_safe_1.default(context)); | ||
| } | ||
| if (typeof a === 'string' && b === undefined) { | ||
| message = a; | ||
| } | ||
| else if (typeof a === 'string') { | ||
| message = sprintfit_1.sprintf(a, b, c, d, e, f, g, h, i, j); | ||
| } | ||
| else { | ||
| if (typeof b !== 'string') { | ||
| throw new TypeError('Message must be a string.'); | ||
| } | ||
| message = sprintfit_1.sprintf(b, c, d, e, f, g, h, i, j); | ||
| } | ||
| onMessage({ | ||
| context, | ||
| message, | ||
| sequence, | ||
| time, | ||
| version: '1.0.0', | ||
| }); | ||
| }; | ||
| }; | ||
| log.adopt = async (routine, context) => { | ||
| if (!domain) { | ||
| return routine(); | ||
| } | ||
| const adoptedDomain = domain.create(); | ||
| return adoptedDomain.run(() => { | ||
| // $FlowFixMe | ||
| adoptedDomain.roarr = { | ||
| context: { ...getParentDomainContext(), | ||
| ...context | ||
| log.child = (context) => { | ||
| if (typeof context === 'function') { | ||
| return createLogger((message) => { | ||
| if (typeof context !== 'function') { | ||
| throw new TypeError('Unexpected state.'); | ||
| } | ||
| onMessage(context(message)); | ||
| }, parentContext); | ||
| } | ||
| }; | ||
| 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); | ||
| return createLogger(onMessage, { | ||
| ...getFirstParentDomainContext(), | ||
| ...parentContext, | ||
| ...context, | ||
| }); | ||
| }; | ||
| } // @see https://github.com/facebook/flow/issues/6705 | ||
| // $FlowFixMe | ||
| return log; | ||
| log.getContext = () => { | ||
| return { | ||
| ...getFirstParentDomainContext(), | ||
| ...parentContext || defaultContext, | ||
| }; | ||
| }; | ||
| log.adopt = async (routine, context) => { | ||
| if (!domain) { | ||
| return routine(); | ||
| } | ||
| const adoptedDomain = domain.create(); | ||
| return adoptedDomain | ||
| .run(() => { | ||
| adoptedDomain.roarr = { | ||
| context: { | ||
| ...getParentDomainContext(), | ||
| ...context, | ||
| }, | ||
| }; | ||
| return routine(); | ||
| }); | ||
| }; | ||
| log.trace = (a, b, c, d, e, f, g, h, i, j) => { | ||
| return log.child({ | ||
| logLevel: constants_1.logLevels.trace, | ||
| })(a, b, c, d, e, f, g, h, i, j); | ||
| }; | ||
| log.debug = (a, b, c, d, e, f, g, h, i, j) => { | ||
| return log.child({ | ||
| logLevel: constants_1.logLevels.debug, | ||
| })(a, b, c, d, e, f, g, h, i, j); | ||
| }; | ||
| log.info = (a, b, c, d, e, f, g, h, i, j) => { | ||
| return log.child({ | ||
| logLevel: constants_1.logLevels.info, | ||
| })(a, b, c, d, e, f, g, h, i, j); | ||
| }; | ||
| log.warn = (a, b, c, d, e, f, g, h, i, j) => { | ||
| return log.child({ | ||
| logLevel: constants_1.logLevels.warn, | ||
| })(a, b, c, d, e, f, g, h, i, j); | ||
| }; | ||
| log.error = (a, b, c, d, e, f, g, h, i, j) => { | ||
| return log.child({ | ||
| logLevel: constants_1.logLevels.error, | ||
| })(a, b, c, d, e, f, g, h, i, j); | ||
| }; | ||
| log.fatal = (a, b, c, d, e, f, g, h, i, j) => { | ||
| return log.child({ | ||
| logLevel: constants_1.logLevels.fatal, | ||
| })(a, b, c, d, e, f, g, h, i, j); | ||
| }; | ||
| return log; | ||
| }; | ||
| var _default = createLogger; | ||
| exports.default = _default; | ||
| //# sourceMappingURL=createLogger.js.map | ||
| exports.default = createLogger; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.default = void 0; | ||
| var _constants = require("../constants"); | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const constants_1 = 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); | ||
| const log = () => { | ||
| return undefined; | ||
| }; | ||
| } // @see https://github.com/facebook/flow/issues/6705 | ||
| // $FlowFixMe | ||
| return log; | ||
| log.adopt = async (routine) => { | ||
| return routine(); | ||
| }; | ||
| log.child = (context) => { | ||
| return createMockLogger(onMessage, parentContext); | ||
| }; | ||
| log.getContext = () => { | ||
| return {}; | ||
| }; | ||
| log.trace = (a, b, c, d, e, f, g, h, i, j) => { | ||
| return log.child({ | ||
| logLevel: constants_1.logLevels.trace, | ||
| })(a, b, c, d, e, f, g, h, i, j); | ||
| }; | ||
| log.debug = (a, b, c, d, e, f, g, h, i, j) => { | ||
| return log.child({ | ||
| logLevel: constants_1.logLevels.debug, | ||
| })(a, b, c, d, e, f, g, h, i, j); | ||
| }; | ||
| log.info = (a, b, c, d, e, f, g, h, i, j) => { | ||
| return log.child({ | ||
| logLevel: constants_1.logLevels.info, | ||
| })(a, b, c, d, e, f, g, h, i, j); | ||
| }; | ||
| log.warn = (a, b, c, d, e, f, g, h, i, j) => { | ||
| return log.child({ | ||
| logLevel: constants_1.logLevels.warn, | ||
| })(a, b, c, d, e, f, g, h, i, j); | ||
| }; | ||
| log.error = (a, b, c, d, e, f, g, h, i, j) => { | ||
| return log.child({ | ||
| logLevel: constants_1.logLevels.error, | ||
| })(a, b, c, d, e, f, g, h, i, j); | ||
| }; | ||
| log.fatal = (a, b, c, d, e, f, g, h, i, j) => { | ||
| return log.child({ | ||
| logLevel: constants_1.logLevels.fatal, | ||
| })(a, b, c, d, e, f, g, h, i, j); | ||
| }; | ||
| return log; | ||
| }; | ||
| var _default = createMockLogger; | ||
| exports.default = _default; | ||
| //# sourceMappingURL=createMockLogger.js.map | ||
| exports.default = createMockLogger; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.default = void 0; | ||
| const createBlockingWriter = stream => { | ||
| return { | ||
| write: message => { | ||
| stream.write(message + '\n'); | ||
| } | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const createBlockingWriter = (stream) => { | ||
| return { | ||
| write: (message) => { | ||
| stream.write(message + '\n'); | ||
| }, | ||
| }; | ||
| }; | ||
| const createNodeWriter = () => { | ||
| // eslint-disable-next-line node/no-process-env | ||
| const targetStream = (process.env.ROARR_STREAM || 'STDOUT').toUpperCase(); | ||
| const stream = targetStream.toUpperCase() === 'STDOUT' ? process.stdout : process.stderr; | ||
| return createBlockingWriter(stream); | ||
| exports.default = () => { | ||
| // eslint-disable-next-line node/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 |
+11
-31
| "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 | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.createRoarrInitialGlobalState = exports.createMockLogger = exports.createLogger = void 0; | ||
| var createLogger_1 = require("./createLogger"); | ||
| Object.defineProperty(exports, "createLogger", { enumerable: true, get: function () { return __importDefault(createLogger_1).default; } }); | ||
| var createMockLogger_1 = require("./createMockLogger"); | ||
| Object.defineProperty(exports, "createMockLogger", { enumerable: true, get: function () { return __importDefault(createMockLogger_1).default; } }); | ||
| var createRoarrInitialGlobalState_1 = require("./createRoarrInitialGlobalState"); | ||
| Object.defineProperty(exports, "createRoarrInitialGlobalState", { enumerable: true, get: function () { return __importDefault(createRoarrInitialGlobalState_1).default; } }); |
+45
-59
| "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 _fastJsonStringify = _interopRequireDefault(require("fast-json-stringify")); | ||
| var _globalthis = _interopRequireDefault(require("globalthis")); | ||
| var _factories = require("./factories"); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| const stringify = (0, _fastJsonStringify.default)({ | ||
| properties: { | ||
| context: { | ||
| additionalProperties: true, | ||
| type: 'object' | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.ROARR = void 0; | ||
| const boolean_1 = require("boolean"); | ||
| const detect_node_1 = __importDefault(require("detect-node")); | ||
| const fast_json_stringify_1 = __importDefault(require("fast-json-stringify")); | ||
| const globalthis_1 = __importDefault(require("globalthis")); | ||
| const factories_1 = require("./factories"); | ||
| const stringify = fast_json_stringify_1.default({ | ||
| properties: { | ||
| context: { | ||
| additionalProperties: true, | ||
| type: 'object', | ||
| }, | ||
| message: { | ||
| type: 'string', | ||
| }, | ||
| sequence: { | ||
| type: 'integer', | ||
| }, | ||
| time: { | ||
| type: 'integer', | ||
| }, | ||
| version: { | ||
| type: 'string', | ||
| }, | ||
| }, | ||
| message: { | ||
| type: 'string' | ||
| }, | ||
| sequence: { | ||
| type: 'integer' | ||
| }, | ||
| time: { | ||
| type: 'integer' | ||
| }, | ||
| version: { | ||
| type: 'string' | ||
| } | ||
| }, | ||
| type: 'object' | ||
| type: 'object', | ||
| }); | ||
| const globalThis = (0, _globalthis.default)(); | ||
| const ROARR = globalThis.ROARR = (0, _factories.createRoarrInititialGlobalState)(globalThis.ROARR || {}); | ||
| const globalThis = globalthis_1.default(); | ||
| const ROARR = globalThis.ROARR = factories_1.createRoarrInitialGlobalState(globalThis.ROARR || {}); | ||
| exports.ROARR = ROARR; | ||
| let logFactory = _factories.createLogger; | ||
| if (_detectNode.default) { | ||
| // eslint-disable-next-line node/no-process-env | ||
| const enabled = (0, _boolean.boolean)(process.env.ROARR_LOG || ''); | ||
| if (!enabled) { | ||
| logFactory = _factories.createMockLogger; | ||
| } | ||
| let logFactory = factories_1.createLogger; | ||
| if (detect_node_1.default) { | ||
| // eslint-disable-next-line node/no-process-env | ||
| const enabled = boolean_1.boolean(process.env.ROARR_LOG || ''); | ||
| if (!enabled) { | ||
| logFactory = factories_1.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 = stringify(message); | ||
| ROARR.write(body); | ||
| } | ||
| exports.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 = stringify(message); | ||
| ROARR.write(body); | ||
| } | ||
| }); | ||
| exports.default = _default; | ||
| //# sourceMappingURL=log.js.map |
+2
-1
| "use strict"; | ||
| //# sourceMappingURL=types.js.map | ||
| /* eslint-disable import/exports-last */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
+1
-1
@@ -1,2 +0,2 @@ | ||
| Copyright (c) 2019, Gajus Kuizinas (http://gajus.com/) | ||
| Copyright (c) 2020, Gajus Kuizinas (http://gajus.com/) | ||
| All rights reserved. | ||
@@ -3,0 +3,0 @@ |
+18
-34
@@ -8,7 +8,5 @@ { | ||
| "ava": { | ||
| "babel": { | ||
| "compileAsTests": [ | ||
| "test/helpers/**/*" | ||
| ] | ||
| }, | ||
| "extensions": [ | ||
| "ts" | ||
| ], | ||
| "files": [ | ||
@@ -18,3 +16,3 @@ "test/roarr/**/*" | ||
| "require": [ | ||
| "@babel/register" | ||
| "ts-node/register/transpile-only" | ||
| ] | ||
@@ -34,23 +32,21 @@ }, | ||
| "devDependencies": { | ||
| "@ava/babel": "^1.0.1", | ||
| "@babel/cli": "^7.12.10", | ||
| "@babel/core": "^7.12.10", | ||
| "@babel/node": "^7.12.10", | ||
| "@babel/plugin-transform-flow-strip-types": "^7.12.10", | ||
| "@babel/preset-env": "^7.12.11", | ||
| "@babel/register": "^7.12.10", | ||
| "@istanbuljs/nyc-config-typescript": "^1.0.1", | ||
| "@types/detect-node": "^2.0.0", | ||
| "@types/globalthis": "^1.0.1", | ||
| "@types/json-stringify-safe": "^5.0.0", | ||
| "@types/node": "^14.14.16", | ||
| "@types/semver-compare": "^1.0.1", | ||
| "ava": "^3.14.0", | ||
| "babel-plugin-istanbul": "^6.0.0", | ||
| "babel-plugin-transform-export-default-name": "^2.1.0", | ||
| "benchmark": "^2.1.4", | ||
| "coveralls": "^3.1.0", | ||
| "del-cli": "^3.0.1", | ||
| "domain-parent": "^1.0.0", | ||
| "eslint": "^7.16.0", | ||
| "eslint-config-canonical": "^24.4.4", | ||
| "flow-bin": "^0.141.0", | ||
| "flow-copy-source": "^2.0.9", | ||
| "gitdown": "^3.1.3", | ||
| "husky": "^4.3.6", | ||
| "nyc": "^15.1.0", | ||
| "semantic-release": "^17.3.0" | ||
| "semantic-release": "^17.3.0", | ||
| "ts-node": "^9.1.1", | ||
| "typescript": "^4.1.3" | ||
| }, | ||
@@ -74,15 +70,2 @@ "engines": { | ||
| "name": "roarr", | ||
| "nyc": { | ||
| "include": [ | ||
| "src/**/*.js" | ||
| ], | ||
| "instrument": false, | ||
| "reporter": [ | ||
| "text-lcov" | ||
| ], | ||
| "require": [ | ||
| "@babel/register" | ||
| ], | ||
| "sourceMap": false | ||
| }, | ||
| "repository": { | ||
@@ -94,9 +77,10 @@ "type": "git", | ||
| "benchmark": "ROARR_LOG=true babel-node test/benchmark.js", | ||
| "build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps && flow-copy-source src dist", | ||
| "build": "del-cli ./dist && tsc", | ||
| "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", | ||
| "lint": "eslint ./src ./test && tsc --noEmit", | ||
| "test": "NODE_ENV=test ava --serial --verbose" | ||
| }, | ||
| "version": "3.0.0" | ||
| "typings": "./dist/log.d.ts", | ||
| "version": "3.1.0" | ||
| } |
Sorry, the diff of this file is not supported yet
| {"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"} |
Sorry, the diff of this file is not supported yet
| {"version":3,"sources":["../../src/factories/createLogger.js"],"names":["globalThis","domain","environmentIsNode","require","getParentDomainContext","parentRoarrContexts","currentDomain","process","parentDomain","roarr","context","push","domainContext","parentRoarrContext","getFirstParentDomainContext","defaultContext","createLogger","onMessage","parentContext","log","a","b","c","d","e","f","g","h","i","k","time","Date","now","sequence","ROARR","message","JSON","parse","undefined","TypeError","version","child","getContext","adopt","routine","adoptedD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d,EAEiBC,CAFjB,EAEoBC,CAFpB,EAEuBC,CAFvB,CAAP;AAGD,KAJD;AAKD,GAvG0G,CAyG3G;AACA;;;AACA,SAAOV,GAAP;AACD,CA5GD;;eA8GeH,Y","sourcesContent":["// @flow\n\nimport environmentIsNode from 'detect-node';\nimport createGlobalThis from 'globalthis';\nimport isCircular from 'is-circular';\nimport stringify from 'json-stringify-safe';\nimport {\n sprintf,\n} from 'sprintfit';\nimport {\n logLevels,\n} from '../constants';\nimport type {\n LoggerType,\n MessageContextType,\n MessageEventHandlerType,\n TranslateMessageFunctionType,\n} from '../types';\n\nconst globalThis = createGlobalThis();\n\nlet domain;\n\nif (environmentIsNode) {\n // eslint-disable-next-line node/global-require\n domain = require('domain');\n}\n\nconst getParentDomainContext = () => {\n if (!domain) {\n return {};\n }\n\n const parentRoarrContexts = [];\n\n let currentDomain = process.domain;\n\n // $FlowFixMe\n if (!currentDomain || !currentDomain.parentDomain) {\n return {};\n }\n\n while (currentDomain && currentDomain.parentDomain) {\n currentDomain = currentDomain.parentDomain;\n\n if (currentDomain.roarr && currentDomain.roarr.context) {\n parentRoarrContexts.push(currentDomain.roarr.context);\n }\n }\n\n let domainContext = {};\n\n for (const parentRoarrContext of parentRoarrContexts) {\n domainContext = {\n ...domainContext,\n ...parentRoarrContext,\n };\n }\n\n return domainContext;\n};\n\nconst getFirstParentDomainContext = () => {\n if (!domain) {\n return {};\n }\n\n let currentDomain = process.domain;\n\n // $FlowFixMe\n if (currentDomain && currentDomain.roarr && currentDomain.roarr.context) {\n return currentDomain.roarr.context;\n }\n\n // $FlowFixMe\n if (!currentDomain || !currentDomain.parentDomain) {\n return {};\n }\n\n while (currentDomain && currentDomain.parentDomain) {\n currentDomain = currentDomain.parentDomain;\n\n if (currentDomain.roarr && currentDomain.roarr.context) {\n return currentDomain.roarr.context;\n }\n }\n\n return {};\n};\n\nconst defaultContext = {};\n\nconst createLogger = (onMessage: MessageEventHandlerType, parentContext?: MessageContextType): LoggerType => {\n // eslint-disable-next-line id-length, unicorn/prevent-abbreviations\n const log = (a, b, c, d, e, f, g, h, i, k) => {\n const time = Date.now();\n const sequence = globalThis.ROARR.sequence++;\n\n let context;\n let message;\n\n if (typeof a === 'string') {\n if (!domain || process.domain === null) {\n context = parentContext || defaultContext;\n } else {\n context = {\n ...getFirstParentDomainContext(),\n ...parentContext,\n };\n }\n } else {\n context = {\n ...getFirstParentDomainContext(),\n ...parentContext,\n ...a,\n };\n }\n\n if (context !== defaultContext && isCircular(context)) {\n context = JSON.parse(stringify(context));\n }\n\n if (typeof a === 'string' && b === undefined) {\n message = a;\n } else if (typeof a === 'string') {\n message = sprintf(a, b, c, d, e, f, g, h, i, k);\n } else {\n if (typeof b !== 'string') {\n throw new TypeError('Message must be a string.');\n }\n\n message = sprintf(b, c, d, e, f, g, h, i, k);\n }\n\n onMessage({\n context,\n message,\n sequence,\n time,\n version: '1.0.0',\n });\n };\n\n log.child = (context: TranslateMessageFunctionType | MessageContextType): LoggerType => {\n if (typeof context === 'function') {\n return createLogger((message) => {\n if (typeof context !== 'function') {\n throw new TypeError('Unexpected state.');\n }\n onMessage(context(message));\n }, parentContext);\n }\n\n return createLogger(onMessage, {\n ...getFirstParentDomainContext(),\n ...parentContext,\n ...context,\n });\n };\n\n log.getContext = (): MessageContextType => {\n return {\n ...getFirstParentDomainContext(),\n ...parentContext || defaultContext,\n };\n };\n\n log.adopt = async (routine, context) => {\n if (!domain) {\n return routine();\n }\n\n const adoptedDomain = domain.create();\n\n return adoptedDomain\n .run(() => {\n // $FlowFixMe\n adoptedDomain.roarr = {\n context: {\n ...getParentDomainContext(),\n ...context,\n },\n };\n\n return routine();\n });\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 createLogger;\n"],"file":"createLogger.js"} |
Sorry, the diff of this file is not supported yet
| {"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"} |
Sorry, the diff of this file is not supported yet
| {"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 node/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"} |
| "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 }; } | ||
| // 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 = { | ||
| sequence: 0, | ||
| ...currentState, | ||
| versions | ||
| }; | ||
| if (_detectNode.default) { | ||
| if (currentIsLatestVersion || !newState.write) { | ||
| newState = { ...newState, | ||
| ...(0, _createNodeWriter.default)() | ||
| }; | ||
| } | ||
| } | ||
| return newState; | ||
| }; | ||
| var _default = createRoarrInititialGlobalState; | ||
| exports.default = _default; | ||
| //# sourceMappingURL=createRoarrInititialGlobalState.js.map |
Sorry, the diff of this file is not supported yet
| {"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,GAAG;AACbC,IAAAA,QAAQ,EAAE,CADG;AAEb,OAAGX,YAFU;AAGbC,IAAAA;AAHa,GAAf;;AAMA,MAAIW,mBAAJ,EAAuB;AACrB,QAAIP,sBAAsB,IAAI,CAACK,QAAQ,CAACG,KAAxC,EAA+C;AAC7CH,MAAAA,QAAQ,GAAG,EACT,GAAGA,QADM;AAET,WAAG;AAFM,OAAX;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"} |
Sorry, the diff of this file is not supported yet
| {"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"} |
Sorry, the diff of this file is not supported yet
| {"version":3,"sources":["../src/log.js"],"names":["stringify","properties","context","additionalProperties","type","message","sequence","time","version","globalThis","ROARR","logFactory","createLogger","environmentIsNode","enabled","process","env","ROARR_LOG","createMockLogger","write","body"],"mappings":";;;;;;;AAEA;;AAGA;;AACA;;AACA;;AACA;;;;AAMA,MAAMA,SAAS,GAAG,gCAAS;AACzBC,EAAAA,UAAU,EAAE;AACVC,IAAAA,OAAO,EAAE;AACPC,MAAAA,oBAAoB,EAAE,IADf;AAEPC,MAAAA,IAAI,EAAE;AAFC,KADC;AAKVC,IAAAA,OAAO,EAAE;AACPD,MAAAA,IAAI,EAAE;AADC,KALC;AAQVE,IAAAA,QAAQ,EAAE;AACRF,MAAAA,IAAI,EAAE;AADE,KARA;AAWVG,IAAAA,IAAI,EAAE;AACJH,MAAAA,IAAI,EAAE;AADF,KAXI;AAcVI,IAAAA,OAAO,EAAE;AACPJ,MAAAA,IAAI,EAAE;AADC;AAdC,GADa;AAmBzBA,EAAAA,IAAI,EAAE;AAnBmB,CAAT,CAAlB;AAsBA,MAAMK,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,CAAEN,OAAD,IAAa;AACrC,MAAIK,KAAK,CAACS,KAAV,EAAiB;AACf;AACA;AACA,UAAMC,IAAI,GAAGpB,SAAS,CAACK,OAAD,CAAtB;AAEAK,IAAAA,KAAK,CAACS,KAAN,CAAYC,IAAZ;AACD;AACF,CARwB,C","sourcesContent":["// @flow\n\nimport {\n boolean,\n} from 'boolean';\nimport environmentIsNode from 'detect-node';\nimport fastJson from 'fast-json-stringify';\nimport createGlobalThis from 'globalthis';\nimport {\n createLogger,\n createMockLogger,\n createRoarrInititialGlobalState,\n} from './factories';\n\nconst stringify = fastJson({\n properties: {\n context: {\n additionalProperties: true,\n type: 'object',\n },\n message: {\n type: 'string',\n },\n sequence: {\n type: 'integer',\n },\n time: {\n type: 'integer',\n },\n version: {\n type: 'string',\n },\n },\n type: 'object',\n});\n\nconst globalThis = createGlobalThis();\n\nconst ROARR = globalThis.ROARR = createRoarrInititialGlobalState(globalThis.ROARR || {});\n\nlet logFactory = createLogger;\n\nif (environmentIsNode) {\n // eslint-disable-next-line node/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 = stringify(message);\n\n ROARR.write(body);\n }\n});\n"],"file":"log.js"} |
Sorry, the diff of this file is not supported yet
| {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"types.js"} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
19
-9.52%440
33.33%40676
-38.79%20
-25.93%1
Infinity%