Files
hub-monorepo/packages/hub-nodejs/examples/replicate-data-postgres/util.ts
Shane da Silva cc2f5a4fae Add syncing/replication example for Postgres (#938)
Provide a working end-to-end example of syncing data from hubs to a
Postgres database.

This should work with no additional dependencies besides what you
install with `yarn install` and Docker.
2023-05-05 09:56:48 -07:00

25 lines
1.1 KiB
TypeScript

/* eslint-disable prefer-arrow-functions/prefer-arrow-functions */
import { fromFarcasterTime } from '@farcaster/hub-nodejs';
export function farcasterTimeToDate(time: undefined): undefined;
export function farcasterTimeToDate(time: null): null;
export function farcasterTimeToDate(time: number): Date;
export function farcasterTimeToDate(time: number | null | undefined): Date | null | undefined;
export function farcasterTimeToDate(time: number | null | undefined): Date | null | undefined {
if (time === undefined) return undefined;
if (time === null) return null;
const result = fromFarcasterTime(time);
if (result.isErr()) throw result.error;
return new Date(result.value);
}
export function bytesToHex(bytes: undefined): undefined;
export function bytesToHex(bytes: null): null;
export function bytesToHex(bytes: Uint8Array): string;
export function bytesToHex(bytes: Uint8Array | null | undefined): string | null | undefined {
if (bytes === undefined) return undefined;
if (bytes === null) return null;
return '0x' + Buffer.from(bytes).toString('hex');
}