@@ -38,8 +38,8 @@ export interface NostrEvent<K extends EventKind = EventKind> {
38
38
pubkey : PublicKey ;
39
39
created_at : Timestamp ;
40
40
kind : K ;
41
- tags : TagFor < K > [ ] ;
42
- content : Stringified < EventContentFor < K > > ;
41
+ tags : [ ... Tags < K > , ... OptionalTag < K > [ ] ] ;
42
+ content : Stringified < EventContent < K > > ;
43
43
sig : Signature ;
44
44
}
45
45
@@ -52,11 +52,11 @@ export type Signature = Brand<string, "EventSignature">;
52
52
53
53
export type EventSerializePrecursor < K extends EventKind = EventKind > = [
54
54
header : 0 ,
55
- pubkey : PublicKey ,
56
- created_at : Timestamp ,
57
- kind : K ,
58
- tags : TagFor < K > [ ] ,
59
- content : Stringified < EventContentFor < K > > ,
55
+ pubkey : NostrEvent < K > [ "pubkey" ] ,
56
+ created_at : NostrEvent < K > [ "created_at" ] ,
57
+ kind : NostrEvent < K > [ "kind" ] ,
58
+ tags : NostrEvent < K > [ "tags" ] ,
59
+ content : NostrEvent < K > [ "content" ] ,
60
60
] ;
61
61
62
62
// ----------------------
@@ -79,7 +79,12 @@ export type TagParams<T extends TagType> = TagRecord[T] extends [
79
79
...infer P ,
80
80
] ? P
81
81
: never ;
82
- export type TagFor < K extends EventKind > = EventKindRecord [ K ] [ "Tag" ] ;
82
+
83
+ export type Tags < K extends EventKind > = EventKindRecord [ K ] extends
84
+ { Tags : infer T extends Tag [ ] } ? T : [ ] ;
85
+
86
+ export type OptionalTag < K extends EventKind > = EventKindRecord [ K ] extends
87
+ { OptionalTag : infer T extends Tag } ? T | undefined : Tag | undefined ;
83
88
84
89
// ----------------------
85
90
// Communication
@@ -116,7 +121,7 @@ export type OkMessageContent<
116
121
] ;
117
122
118
123
export type OkMessageBody < K extends EventKind , B extends boolean > = B extends
119
- true ? string : `${ResponsePrefixFor < K > } : ${string } `;
124
+ true ? string : `${ResponsePrefix < K > } : ${string } `;
120
125
121
126
export type DefaultResponsePrefix =
122
127
| "duplicate"
@@ -151,17 +156,18 @@ export type SubscriptionFilter<
151
156
export type EventKind = keyof EventKindRecord & number ;
152
157
153
158
export interface EventKindRecordEntry {
154
- Tag : Tag ;
155
159
Content : unknown ;
160
+ OptionalTag ?: Tag ;
161
+ Tags ?: Tag [ ] ;
156
162
ResponsePrefix ?: string ;
157
163
}
158
164
159
- export type EventContent = EventContentFor < EventKind > ;
165
+ export type AnyEventContent = EventContent < EventKind > ;
160
166
161
- export type EventContentFor < K extends EventKind > = EventKindRecord [ K ] extends
167
+ export type EventContent < K extends EventKind > = EventKindRecord [ K ] extends
162
168
EventKindRecordEntry ? EventKindRecord [ K ] [ "Content" ] : never ;
163
169
164
- export type ResponsePrefixFor < K extends EventKind = EventKind > =
170
+ export type ResponsePrefix < K extends EventKind = EventKind > =
165
171
EventKindRecord [ K ] extends { ResponsePrefix : infer P extends string } ? P
166
172
: DefaultResponsePrefix ;
167
173
0 commit comments