_example.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. module.exports = {
  2. /**
  3. * The reporting API version. This should be set to 3.
  4. */
  5. version: 4,
  6. /**
  7. * Report name. This should match the nesting found in the reports.js file.
  8. */
  9. name: 'ibackuptool.example',
  10. /**
  11. * Human readable description of the file
  12. */
  13. description: `Example Report module.`,
  14. /**
  15. * Optional flag requiring a backup parameter to be present in order to run this report.
  16. */
  17. requiresBackup: true,
  18. /**
  19. * Run on a v3 lib / backup object.
  20. * The run() function must return a promise, which always resolves to valid data.
  21. * If the files aren't in the backup or aren't formatted in a known way, we reject
  22. * and print the error message for the user.
  23. * @param {object} lib standard lib, contains lib.run() function.
  24. * @param {object} options options object.
  25. */
  26. run (lib, { backup }) {
  27. return new Promise((resolve, reject) => {
  28. // resolve to valid data.
  29. // Typically, this would be "raw" data containing as much info as possible.
  30. // Se below for data formatting.
  31. resolve([{
  32. name: 'example1',
  33. data: {
  34. code: 33,
  35. values: [1, 2, 3, 4, 5]
  36. }
  37. }])
  38. })
  39. },
  40. /**
  41. * The "output" property declares the public interface for most operations.
  42. * This provides a level of abstraction from the datatypes that are stored in the
  43. * backups since they may vary between versions, or need normalization.
  44. *
  45. * This collection of functions allows that to occur.
  46. */
  47. output: {
  48. name: el => el.name,
  49. code: el => el.data.code
  50. }
  51. /*
  52. For the above example, if run() resolved to:
  53. [{
  54. name: 'example1',
  55. data: {
  56. code: 33,
  57. values: [1, 2, 3, 4, 5]
  58. }
  59. }]
  60. The actual module output when using a normal json, csv, table formatter would be the following,
  61. due to the output declaration:
  62. [{
  63. name: 'example1',
  64. code: 33
  65. }]
  66. // We can also output a single raw object:
  67. {
  68. Name: 'test',
  69. Version: '1.0',
  70. BackupData: [104, 101, 108, 108, 111, 044, 119, 111, 114, 108, 100]
  71. }
  72. // And map it using the following output declaration:
  73. output: {
  74. name: el => el.Name,
  75. version: el => el.Version
  76. }
  77. To the following:
  78. {
  79. name: 'test',
  80. version: '1.0'
  81. }
  82. IF we specify a "raw" formatter, or run using the { raw: true } parameter to lib.run(),
  83. We'd get back the original raw object.
  84. {
  85. Name: 'test',
  86. Version: '1.0',
  87. BackupData: [104, 101, 108, 108, 111, 044, 119, 111, 114, 108, 100]
  88. }
  89. */
  90. }