The frontend/UI server, written in JS using the MarkoJS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.7 KiB

  1. const {query} = require("../client")
  2. class Change {
  3. /**
  4. * @param {string} id
  5. * @param {string} model
  6. * @param {string} op
  7. * @param {string} author
  8. * @param {Date | string | number} date
  9. * @param {{model:string,id:string}[]} keys '
  10. * @param {{type:string, [x:string]:any}[]} objects
  11. */
  12. constructor(id, model, op, author, date, keys, objects) {
  13. this.id = id
  14. this.model = model
  15. this.op = op
  16. this.author = author
  17. this.date = date
  18. this.keys = keys
  19. this.objects = objects
  20. }
  21. static fromData(data) {
  22. return new Change(data.id, data.model, data.op, data.author, data.date, data.keys, data.objects)
  23. }
  24. }
  25. class ChangesAPI {
  26. /**
  27. * Call `channels(filter)` query
  28. *
  29. * @param {{limit:int, keys: {model:string,id:string}[]}} filter
  30. * @returns {Promise<Change[]>}
  31. */
  32. list(filter = null) {
  33. return query(`
  34. query ListChanges($filter:ChangesFilter) {
  35. changes(filter:$filter) {
  36. id
  37. model
  38. op
  39. author
  40. date
  41. keys {
  42. model
  43. id
  44. }
  45. objects {
  46. type: __typename
  47. ...on Character {
  48. id
  49. name
  50. }
  51. ...on Chapter {
  52. id
  53. title
  54. }
  55. ...on Story {
  56. id
  57. name
  58. }
  59. ...on Post {
  60. id
  61. time
  62. nick
  63. }
  64. ...on Comment {
  65. chapterId
  66. characterName
  67. }
  68. }
  69. }
  70. }
  71. `, {filter}).then(({changes}) => {
  72. return changes.map(d => Change.fromData(d))
  73. })
  74. }
  75. }
  76. module.exports = { Change, changesApi: new ChangesAPI }