From 4e68e3868f2bd872fc1f9235edb56fe5e6621fba Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 8 Jul 2023 20:01:10 -0500 Subject: [PATCH] Prevent cyclical import of Time module --- src/nip05.ts | 2 +- src/utils.ts | 14 ++------------ src/utils/time.ts | 12 ++++++++++++ 3 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 src/utils/time.ts diff --git a/src/nip05.ts b/src/nip05.ts index edcb22b4..1ddd1361 100644 --- a/src/nip05.ts +++ b/src/nip05.ts @@ -1,5 +1,5 @@ import { TTLCache, z } from '@/deps.ts'; -import { Time } from '@/utils.ts'; +import { Time } from '@/utils/time.ts'; const nip05Cache = new TTLCache>({ ttl: Time.hours(1), max: 5000 }); diff --git a/src/utils.ts b/src/utils.ts index 191d5e72..7a91fc25 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -106,17 +106,6 @@ function eventAge(event: Event): number { return new Date().getTime() - nostrDate(event.created_at).getTime(); } -const Time = { - milliseconds: (ms: number) => ms, - seconds: (s: number) => s * 1000, - minutes: (m: number) => m * Time.seconds(60), - hours: (h: number) => h * Time.minutes(60), - days: (d: number) => d * Time.hours(24), - weeks: (w: number) => w * Time.days(7), - months: (m: number) => m * Time.days(30), - years: (y: number) => y * Time.days(365), -}; - function findTag(tags: string[][], name: string): string[] | undefined { return tags.find((tag) => tag[0] === name); } @@ -150,5 +139,6 @@ export { parseBody, parseNip05, sha256, - Time, }; + +export { Time } from './utils/time.ts'; diff --git a/src/utils/time.ts b/src/utils/time.ts new file mode 100644 index 00000000..1c2444e1 --- /dev/null +++ b/src/utils/time.ts @@ -0,0 +1,12 @@ +const Time = { + milliseconds: (ms: number) => ms, + seconds: (s: number) => s * 1000, + minutes: (m: number) => m * Time.seconds(60), + hours: (h: number) => h * Time.minutes(60), + days: (d: number) => d * Time.hours(24), + weeks: (w: number) => w * Time.days(7), + months: (m: number) => m * Time.days(30), + years: (y: number) => y * Time.days(365), +}; + +export { Time };