hydrateA11yFrame.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. export interface RawA11yFrame {
  2. elements: A11yIssueElement[];
  3. help: string;
  4. help_url: string;
  5. id: string;
  6. timestamp: number;
  7. impact?: 'minor' | 'moderate' | 'serious' | 'critical';
  8. }
  9. interface A11yIssueElement {
  10. alternatives: A11yIssueElementAlternative[];
  11. element: string;
  12. target: string[];
  13. }
  14. interface A11yIssueElementAlternative {
  15. id: string;
  16. message: string;
  17. }
  18. type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
  19. export type HydratedA11yFrame = Overwrite<
  20. RawA11yFrame,
  21. {
  22. /**
  23. * Alias of `id`
  24. */
  25. description: string;
  26. /**
  27. * The difference in timestamp and replay.started_at, in millieseconds
  28. */
  29. offsetMs: number;
  30. /**
  31. * The Date when the a11yIssue happened
  32. */
  33. timestamp: Date;
  34. /**
  35. * Alias of timestamp, in milliseconds
  36. */
  37. timestampMs: number;
  38. }
  39. >;
  40. export default function hydrateA11yFrame(raw: RawA11yFrame): HydratedA11yFrame {
  41. const timestamp = new Date(raw.timestamp);
  42. return {
  43. ...raw,
  44. description: raw.id,
  45. offsetMs: 0,
  46. timestamp,
  47. timestampMs: timestamp.getTime(),
  48. };
  49. }