Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Return nostr event with generics #448

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends number = number> {
kind: T
tags: string[][]
content: string
created_at: number
Expand All @@ -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<Event, 'kind' | 'tags' | 'content' | 'created_at'>
export type UnsignedEvent = Pick<Event, 'kind' | 'tags' | 'content' | 'created_at' | 'pubkey'>

Expand Down
2 changes: 1 addition & 1 deletion kinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function classifyKind(kind: number): KindClassification {
return 'unknown'
}

export function isKind<T extends number>(event: unknown, kind: T | Array<T>): event is NostrEvent & { kind: T } {
export function isKind<T extends number>(event: unknown, kind: T | Array<T>): event is NostrEvent<T> {
const kindAsArray: number[] = kind instanceof Array ? kind : [kind]
return (validateEvent(event) && kindAsArray.includes(event.kind)) || false
}
Expand Down
Loading