websocket.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { ExternalGroupProviderType } from '~/features/external-user-group/interfaces/external-user-group';
  2. const generateGroupSyncEvents = () => {
  3. const events = {};
  4. Object.values(ExternalGroupProviderType).forEach((provider) => {
  5. events[provider] = {
  6. GroupSyncProgress: `${provider}:groupSyncProgress`,
  7. GroupSyncCompleted: `${provider}:groupSyncCompleted`,
  8. GroupSyncFailed: `${provider}:groupSyncFailed`,
  9. };
  10. });
  11. return events as {
  12. [key in ExternalGroupProviderType]: {
  13. GroupSyncProgress: string,
  14. GroupSyncCompleted: string,
  15. GroupSyncFailed: string,
  16. }
  17. };
  18. };
  19. export const SocketEventName = {
  20. // Update descendantCount
  21. UpdateDescCount: 'UpdateDescCount',
  22. // Public migration
  23. PMStarted: 'PublicMigrationStarted',
  24. PMMigrating: 'PublicMigrationMigrating',
  25. PMErrorCount: 'PublicMigrationErrorCount',
  26. PMEnded: 'PublicMigrationEnded',
  27. // Page migration
  28. PageMigrationSuccess: 'PageMigrationSuccess',
  29. PageMigrationError: 'PageMigrationError',
  30. // Elasticsearch
  31. AddPageProgress: 'addPageProgress',
  32. FinishAddPage: 'finishAddPage',
  33. RebuildingFailed: 'rebuildingFailed',
  34. // External user group sync
  35. externalUserGroup: generateGroupSyncEvents(),
  36. // Page Operation
  37. PageCreated: 'page:create',
  38. PageUpdated: 'page:update',
  39. PageDeleted: 'page:delete',
  40. } as const;
  41. export type SocketEventName = typeof SocketEventName[keyof typeof SocketEventName];
  42. type PageId = string;
  43. type DescendantCount = number;
  44. /**
  45. * Data of updateDescCount when used through socket.io. Convert to UpdateDescCountData type when use with swr cache.
  46. */
  47. export type UpdateDescCountRawData = Record<PageId, DescendantCount>;
  48. export type UpdateDescCountData = Map<PageId, DescendantCount>;
  49. export type PMStartedData = { total: number };
  50. export type PMMigratingData = { count: number };
  51. export type PMErrorCountData = { skip: number };
  52. export type PMEndedData = { isSucceeded: boolean };
  53. export type PageMigrationErrorData = { paths: string[] }