3
0

content.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { ApiPromise } from "@polkadot/api";
  2. import {
  3. CuratorGroup,
  4. CuratorGroupId,
  5. Channel,
  6. ChannelCategory,
  7. ChannelCategoryId,
  8. ChannelOwnershipTransferRequest,
  9. ChannelOwnershipTransferRequestId,
  10. Person,
  11. PersonId,
  12. Playlist,
  13. PlaylistId,
  14. Series,
  15. SeriesId,
  16. Video,
  17. VideoId,
  18. VideoCategory,
  19. VideoCategoryId,
  20. } from "@joystream/types/content";
  21. import { ChannelId } from "@joystream/types/storage";
  22. import { Hash } from "@polkadot/types/interfaces";
  23. export const getCuratorGroup = (
  24. api: ApiPromise,
  25. id: CuratorGroupId | number
  26. ): Promise<CuratorGroup> =>
  27. api.query.content.curatorGroupById(id) as Promise<CuratorGroup>;
  28. export const getChannel = (
  29. api: ApiPromise,
  30. id: ChannelId | number
  31. ): Promise<Channel> => api.query.content.channelById(id) as Promise<Channel>;
  32. export const getChannelCategory = (
  33. api: ApiPromise,
  34. id: ChannelCategoryId | number
  35. ): Promise<ChannelCategory> =>
  36. api.query.content.channelCategoryById(id) as Promise<ChannelCategory>;
  37. export const getVideo = (
  38. api: ApiPromise,
  39. id: VideoId | number
  40. ): Promise<Video> => api.query.content.videoById(id) as Promise<Video>;
  41. export const getVideoCategory = (
  42. api: ApiPromise,
  43. id: VideoId | number
  44. ): Promise<Video> => api.query.content.videoCategoryById(id) as Promise<Video>;
  45. export const getPerson = (
  46. api: ApiPromise,
  47. id: PersonId | number
  48. ): Promise<Person> => api.query.content.personById(id) as Promise<Person>;
  49. export const getPlaylist = (
  50. api: ApiPromise,
  51. id: PlaylistId | number
  52. ): Promise<Playlist> => api.query.content.playlistById(id) as Promise<Playlist>;
  53. export const getSeries = (
  54. api: ApiPromise,
  55. id: SeriesId | number
  56. ): Promise<Series> => api.query.content.seriesById(id) as Promise<Series>;
  57. export const getNextChannel = (
  58. api: ApiPromise,
  59. hash?: Hash
  60. ): Promise<ChannelId> =>
  61. hash
  62. ? (api.query.content.nextChannelId.at(hash) as Promise<ChannelId>)
  63. : (api.query.content.nextChannelId() as Promise<ChannelId>);
  64. export const getNextChannelCategory = (
  65. api: ApiPromise,
  66. hash?: Hash
  67. ): Promise<ChannelCategoryId> =>
  68. hash
  69. ? api.query.content.nextChannelCategoryId.at(hash)
  70. : (api.query.content.nextChannelCategoryId() as Promise<ChannelCategoryId>);
  71. export const getNextChannelOwnershipTransferRequestId = (
  72. api: ApiPromise,
  73. hash?: Hash
  74. ): Promise<ChannelOwnershipTransferRequestId> =>
  75. hash
  76. ? api.query.content.nextChannelOwnershipTransferRequestId.at(hash)
  77. : (api.query.content.nextChannelOwnershipTransferRequestId() as Promise<ChannelOwnershipTransferRequestId>);
  78. export const getNextCuratorGroup = (
  79. api: ApiPromise,
  80. hash?: Hash
  81. ): Promise<CuratorGroupId> =>
  82. hash
  83. ? api.query.content.nextCuratorGroupId.at(hash)
  84. : (api.query.content.nextCuratorGroupId() as Promise<CuratorGroupId>);
  85. export const getNextPerson = (api: ApiPromise, hash?: Hash): Promise<number> =>
  86. hash
  87. ? api.query.content.nextPersonId.at(hash)
  88. : api.query.content.nextPersonId();
  89. export const getNextPlaylist = (
  90. api: ApiPromise,
  91. hash?: Hash
  92. ): Promise<number> =>
  93. hash
  94. ? api.query.content.nextPlaylistId.at(hash)
  95. : api.query.content.nextPlaylistId();
  96. export const getNextSeries = (api: ApiPromise, hash?: Hash): Promise<number> =>
  97. hash
  98. ? api.query.content.nextSeriesId.at(hash)
  99. : api.query.content.nextSeriesId();
  100. export const getNextVideo = (api: ApiPromise, hash?: Hash): Promise<number> =>
  101. hash
  102. ? api.query.content.nextVideoId.at(hash)
  103. : api.query.content.nextVideoId();
  104. export const getNextVideoCategory = (
  105. api: ApiPromise,
  106. hash?: Hash
  107. ): Promise<number> =>
  108. hash
  109. ? api.query.content.nextVideoCategoryId.at(hash)
  110. : api.query.content.nextVideoCategoryId();