turn Kind enum into a simple object with numbers.

This commit is contained in:
fiatjaf
2023-10-30 08:03:42 -03:00
parent 318e3f8c88
commit 842cba25f3
7 changed files with 46 additions and 56 deletions

View File

@@ -8,35 +8,33 @@ import { utf8Encoder } from './utils.ts'
/** Designates a verified event signature. */
export const verifiedSymbol = Symbol('verified')
/** @deprecated Use numbers instead. */
/* eslint-disable no-unused-vars */
export enum Kind {
Metadata = 0,
Text = 1,
RecommendRelay = 2,
Contacts = 3,
EncryptedDirectMessage = 4,
EventDeletion = 5,
Repost = 6,
Reaction = 7,
BadgeAward = 8,
ChannelCreation = 40,
ChannelMetadata = 41,
ChannelMessage = 42,
ChannelHideMessage = 43,
ChannelMuteUser = 44,
Blank = 255,
Report = 1984,
ZapRequest = 9734,
Zap = 9735,
RelayList = 10002,
ClientAuth = 22242,
NwcRequest = 23194,
HttpAuth = 27235,
ProfileBadge = 30008,
BadgeDefinition = 30009,
Article = 30023,
FileMetadata = 1063,
export const Kind = {
Metadata: 0,
Text: 1,
RecommendRelay: 2,
Contacts: 3,
EncryptedDirectMessage: 4,
EventDeletion: 5,
Repost: 6,
Reaction: 7,
BadgeAward: 8,
ChannelCreation: 40,
ChannelMetadata: 41,
ChannelMessage: 42,
ChannelHideMessage: 43,
ChannelMuteUser: 44,
Blank: 255,
Report: 1984,
ZapRequest: 9734,
Zap: 9735,
RelayList: 10002,
ClientAuth: 22242,
NwcRequest: 23194,
HttpAuth: 27235,
ProfileBadge: 30008,
BadgeDefinition: 30009,
Article: 30023,
FileMetadata: 1063,
}
export interface Event<K extends number = number> {
@@ -61,9 +59,7 @@ export interface VerifiedEvent<K extends number = number> extends Event<K> {
[verifiedSymbol]: true
}
export function getBlankEvent(): EventTemplate<Kind.Blank>
export function getBlankEvent<K extends number>(kind: K): EventTemplate<K>
export function getBlankEvent<K>(kind: K | Kind.Blank = Kind.Blank) {
export function getBlankEvent(kind: number = 255): EventTemplate {
return {
kind,
content: '',