From 773a935c568d55d64844d87026b856ba14a2bb3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Conselheiro?= Date: Wed, 23 Oct 2024 14:47:47 +0000 Subject: [PATCH 1/2] nostr event interface with retrocompatible generics --- core.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core.ts b/core.ts index a92b824..8e6c573 100644 --- a/core.ts +++ b/core.ts @@ -8,8 +8,8 @@ export interface Nostr { /** Designates a verified event signature. */ export const verifiedSymbol = Symbol('verified') -export interface Event { - kind: number +export interface NostrEvent { + kind: T tags: string[][] content: string created_at: number @@ -19,7 +19,10 @@ export interface Event { [verifiedSymbol]?: boolean } -export type NostrEvent = Event +/** + * @deprecated prefer NostrEvent interface + */ +export type Event = NostrEvent export type EventTemplate = Pick export type UnsignedEvent = Pick From 4eba11b07934bbee1ba8e5de642b49529884470b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Conselheiro?= Date: Wed, 23 Oct 2024 16:05:45 +0000 Subject: [PATCH 2/2] use kind generic in nostr event guard --- kinds.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kinds.ts b/kinds.ts index c9fafd1..71cb39d 100644 --- a/kinds.ts +++ b/kinds.ts @@ -32,7 +32,7 @@ export function classifyKind(kind: number): KindClassification { return 'unknown' } -export function isKind(event: unknown, kind: T | Array): event is NostrEvent & { kind: T } { +export function isKind(event: unknown, kind: T | Array): event is NostrEvent { const kindAsArray: number[] = kind instanceof Array ? kind : [kind] return (validateEvent(event) && kindAsArray.includes(event.kind)) || false }