topics.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {
  2. TopicName,
  3. Topic,
  4. ClusterId,
  5. TopicDetails,
  6. TopicConfig,
  7. TopicFormData,
  8. } from 'lib/interfaces';
  9. import {
  10. BASE_URL,
  11. BASE_PARAMS,
  12. } from 'lib/constants';
  13. export const getTopicConfig = (clusterId: ClusterId, topicName: TopicName): Promise<TopicConfig[]> =>
  14. fetch(`${BASE_URL}/clusters/${clusterId}/topics/${topicName}/config`, { ...BASE_PARAMS })
  15. .then(res => res.json());
  16. export const getTopicDetails = (clusterId: ClusterId, topicName: TopicName): Promise<TopicDetails> =>
  17. fetch(`${BASE_URL}/clusters/${clusterId}/topics/${topicName}`, { ...BASE_PARAMS })
  18. .then(res => res.json());
  19. export const getTopics = (clusterId: ClusterId): Promise<Topic[]> =>
  20. fetch(`${BASE_URL}/clusters/${clusterId}/topics`, { ...BASE_PARAMS })
  21. .then(res => res.json());
  22. export const postTopic = (clusterId: ClusterId, form: TopicFormData): Promise<Response> => {
  23. const {
  24. name,
  25. partitions,
  26. replicationFactor,
  27. cleanupPolicy,
  28. retentionBytes,
  29. retentionMs,
  30. maxMessageBytes,
  31. minInSyncReplicas,
  32. } = form;
  33. const body = JSON.stringify({
  34. name,
  35. partitions,
  36. replicationFactor,
  37. configs: {
  38. 'cleanup.policy': cleanupPolicy,
  39. 'retention.ms': retentionMs,
  40. 'retention.bytes': retentionBytes,
  41. 'max.message.bytes': maxMessageBytes,
  42. 'min.insync.replicas': minInSyncReplicas,
  43. }
  44. });
  45. return fetch(`${BASE_URL}/clusters/${clusterId}/topics`, {
  46. ...BASE_PARAMS,
  47. method: 'POST',
  48. body,
  49. });
  50. }