import { EntityID } from "./entity" ; import { EventID } from "./event" ; import { v4 as uuidV4 } from "uuid" ; import { fromByteArray as base64FromByteArray } from "base64-js" ; export function encodeUUIDBytesToWebSafeBase64ID < ID extends EntityID | EventID > ( bytes ) { const base64 = base64FromByteArray ( bytes ) ; return base64 . replace ( /\+/g , "-" ) . replace ( /\//g , "_" ) . substring ( 0 , 22 ) as ID ; } export function generateUniqueID < ID extends EntityID | EventID > ( rng = null ) { const bytes = new Uint8Array ( 16 ) ; uuidV4 ( rng ? { rng } : null , bytes , 0 ) ; return encodeUUIDBytesToWebSafeBase64ID ( bytes ) ; }