All files / collaborative-presence/src id.ts

100% Statements 11/11
100% Branches 3/3
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 143x     3x 490x 490x 490x     3x 402x 402x    
import {type ITimestampStruct, Timestamp} from 'json-joy/lib/json-crdt-patch';
import type {PresenceIdShorthand} from './types';
 
export const toDto = (sid: number, id: ITimestampStruct): PresenceIdShorthand => {
  const dto: PresenceIdShorthand = [id.time];
  if (id.sid !== sid) dto.push(id.sid);
  return dto;
};
 
export const fromDto = (sid: number, dto: PresenceIdShorthand): ITimestampStruct => {
  const [time, dtoSid = sid] = dto;
  return new Timestamp(dtoSid, time);
};