Skip to main contentreport-toolkit

@report-toolkit/core

Index

References

External modules

Functions

References

builtinTransformerIds

builtinTransformerIds:


compatibleTransformers

compatibleTransformers:


deregisterPlugins

deregisterPlugins:


isPluginRegistered

isPluginRegistered:


registeredRuleDefinitions

registeredRuleDefinitions:

Functions

diff

diff(report1: DiagnosticReport | Report, report2: DiagnosticReport | Report, opts?: Partial‹DiffOptions›): Promise‹DiffResult[]›

Returns the difference between two reports.

Example:

const {diff} = require('@report-toolkit/core');
const report1 = process.report.getReport();
const report2 = process.report.getReport();
const results = await diff(report1, report2, {
filterProperties: ['header', 'javascriptStack', 'nativeStack'],
showSecretsUnsafe: false
});
results.forEach(({op, path, newValue, oldValue}) => {
console.log(`[${op}] <${path}> ${oldValue} => ${newValue}`);
});

Parameters:

NameTypeDescription
report1DiagnosticReport | ReportFirst report to diff
report2DiagnosticReport | ReportSecond report to diff
opts?Partial‹DiffOptions-

Returns: Promise‹DiffResult[]›

Array of results, one per difference


inspect

inspect(reports: DiagnosticReport | Report, opts?: Partial‹InspectOptions›): Promise‹Message[]›

Inspect one or more reports, running rules against each. Resolves with an array of zero or more Messages.

Example:

const {inspect} = require('@report-toolkit/core');
const report = process.report.getReport();
const results = await inspect(report, {
severity: 'info',
sort: true,
sortDirection: 'asc',
sortField: 'header.dumpEventTimestamp',
showSecretsUnsafe: false,
ruleConfig: {
'long-timeout': {
timeout: '2s'
}
}
});
results.forEach(({message, filename}) => {
console.log(`${filename}: ${message}`);
});

Parameters:

NameTypeDescription
reportsDiagnosticReport | ReportOne or more reports
opts?Partial‹InspectOptions-

Returns: Promise‹Message[]›


loadConfig

loadConfig(config: any): Promise‹any›

Resolves with a normalized config object from a raw config object.

Example:

const {loadConfig} = require('@report-toolkit/core');
// or require('./path/to/.rtkrc.js')
const rawConfig = [
'report-toolkit:recommended',
{
rules: {
'long-timeout': {
timeout: '2s'
}
}
}
];
// `normalizedConfig` contains contents of "recommended" settings,
// with our override of custom rule config
const normalizedConfig = await loadConfig(rawConfig);

Parameters:

NameTypeDescription
configanyRaw config object

Returns: Promise‹any›

A normalized config object


toReportFromObject

toReportFromObject(value: any, opts?: Partial‹ToReportFromObjectOptions›): Promise‹Readonly‹Report››

Convert a plain object (usually parsed from a JSON report generated by See process.report.writeReport) to a Report instance.

Example:

const {toReportFromObject} = require('@report-toolkit/core');
const json = fs.readFileSync('./report-xxxxx.json');
// `Report` instance with secrets redacted
const report = await toReportFromObject(json, {
showSecretsUnsafe: false
});

Parameters:

NameTypeDescription
valueanyRaw report
opts?Partial‹ToReportFromObjectOptions-

Returns: Promise‹Readonly‹Report››


transform

transform(transformerIds: string | string[], source: any, config?: Partial‹any›, options?: Partial‹TransformOptions›): Promise‹any[]›

Run source through chain of one or more transformers. Performs validation before piping. If the final transformer does not output the desired endType, the defaultTransformer will be appended to the chain; otherwise it is ignored.

Example:

const {transform, toReportFromObject} = require('@report-toolkit/core');
// by default, `report` has its secrets redacted
const report = await toReportFromObject(process.report.getReport());
const [header, ...data] = await transform(['filter', 'csv'], report, {
transformers: {
filter: {include: 'header'},
csv: {flatten: true}
}
});

Parameters:

NameTypeDescription
transformerIdsstring | string[]Unique transformer identifier(s), in order. Can be one of csv, filter, json, newline, redact, stack-hash, table.
sourceanySource, typically one or more Reports.
config?Partial‹any›As returned by loadConfig; can contain transformer-specific settings.
options?Partial‹TransformOptionsOptional constraints & default behavior; overrides settings in config, if present.

Returns: Promise‹any[]›


use

use(pluginId: string): Promise‹RTKPlugin

Register & enable a plugin.

Example:

const {use} = require('@report-toolkit/core');
await use('some-plugin-in-node_modules');
await use('./relative/path/to/plugin.js');

Parameters:

NameTypeDescription
pluginIdstringID of plugin to register; a resolvable path to a module

Returns: Promise‹RTKPlugin