mirror of
https://github.com/farcasterxyz/hub-monorepo.git
synced 2026-02-04 18:05:10 -05:00
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.
25 lines
1.1 KiB
TypeScript
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');
|
|
}
|