@statoscope/stats-extension-custom-reports
TypeScript icon, indicating that this package has built-in type declarations

5.28.1 • Public • Published

Statoscope Package Custom Reports

npm version Financial Contributors on Open Collective

Statoscope extension to store custom reports in stats.

A custom report is:

export type Report<TData, TContext> = {
  id: string; // report id
  name?: string; // report title
  compilation?: string | null; // if specified then a report will be shown only in specific compilation
  data?: TData | (() => Promise<TData> | TData); // raw data for the report or a function that produces a data (may return promise)
  view: string | ViewConfig<TData, TContext>; // any DiscoveryJS. String turns to script to eval
};

View as a script

Sometimes we need to make a report with more complex view (e.g. with event handling).

JSON can't handle functions, but you can pass any script source into view-property instead of JSON.

This source will be evaled on client and should return any DiscoveryJS view.

my-custom-report-view.js:

(() => [
  {
    view: 'button',
    data: {
      text: 'Click me',
    },
    onClick() {
      alert('It works!');
    },
  },
])();

Report config:

({
  id: 'foo',
  view: fs.readFileSync('./my-custom-report-view.js', 'utf8')
})

Readme

Keywords

none

Package Sidebar

Install

npm i @statoscope/stats-extension-custom-reports

Weekly Downloads

94,513

Version

5.28.1

License

MIT

Unpacked Size

10.2 kB

Total Files

9

Last publish

Collaborators

  • smelukov