applesauce-common 6.0.0 → 6.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/factories/comment.d.ts +3 -3
- package/dist/factories/note.d.ts +5 -3
- package/dist/factories/note.js +14 -6
- package/dist/models/thread.js +14 -11
- package/package.json +3 -3
|
@@ -5,12 +5,12 @@ import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
|
5
5
|
import { COMMENT_KIND, CommentPointer } from "../helpers/comment.js";
|
|
6
6
|
import { GroupPointer } from "../helpers/groups.js";
|
|
7
7
|
export type CommentTemplate = KnownEventTemplate<typeof COMMENT_KIND>;
|
|
8
|
-
export type
|
|
8
|
+
export type CommentFactoryOptions = TextContentOptions & MetaTagOptions;
|
|
9
9
|
export declare class CommentFactory extends EventFactory<typeof COMMENT_KIND, CommentTemplate> {
|
|
10
10
|
/** Creates a new comment event */
|
|
11
|
-
static create(parent: NostrEvent | CommentPointer, content: string, options?:
|
|
11
|
+
static create(parent: NostrEvent | CommentPointer, content: string, options?: CommentFactoryOptions): CommentFactory;
|
|
12
12
|
/** Creates a new comment that is replying to a parent event or pointer */
|
|
13
|
-
static reply(parent: NostrEvent | CommentPointer, content: string, options?:
|
|
13
|
+
static reply(parent: NostrEvent | CommentPointer, content: string, options?: CommentFactoryOptions): CommentFactory;
|
|
14
14
|
/** Sets the parent event or pointer that this comment is replying to */
|
|
15
15
|
parent(parent: NostrEvent | CommentPointer): this;
|
|
16
16
|
/** Sets the text content of the comment */
|
package/dist/factories/note.d.ts
CHANGED
|
@@ -5,22 +5,24 @@ import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
|
5
5
|
import { ProfilePointer } from "applesauce-core/helpers/pointers";
|
|
6
6
|
import { ZapOptions } from "../operations/zap-split.js";
|
|
7
7
|
export type NoteTemplate = KnownEventTemplate<kinds.ShortTextNote>;
|
|
8
|
-
export type
|
|
8
|
+
export type NoteFactoryOptions = TextContentOptions & MetaTagOptions & ZapOptions;
|
|
9
9
|
/** A factory class for building kind 1 short text note events */
|
|
10
10
|
export declare class NoteFactory extends EventFactory<kinds.ShortTextNote, NoteTemplate> {
|
|
11
11
|
/**
|
|
12
12
|
* Creates a new note factory
|
|
13
13
|
* @param content - Optional initial content
|
|
14
|
+
* @param opts - Optional factory options
|
|
14
15
|
* @returns A new note factory
|
|
15
16
|
*/
|
|
16
|
-
static create(content?: string): NoteFactory;
|
|
17
|
+
static create(content?: string, opts?: NoteFactoryOptions): NoteFactory;
|
|
17
18
|
/**
|
|
18
19
|
* Creates a note reply factory
|
|
19
20
|
* @param parent - The parent note to reply to
|
|
20
21
|
* @param content - Optional initial content
|
|
22
|
+
* @param opts - Optional factory options
|
|
21
23
|
* @returns A new note factory configured as a reply
|
|
22
24
|
*/
|
|
23
|
-
static reply(parent: NostrEvent, content?: string): NoteFactory;
|
|
25
|
+
static reply(parent: NostrEvent, content?: string, opts?: NoteFactoryOptions): NoteFactory;
|
|
24
26
|
/** Sets the parent note for NIP-10 threading */
|
|
25
27
|
replyTo(parent: NostrEvent): this;
|
|
26
28
|
/** Sets the text content with optional formatting */
|
package/dist/factories/note.js
CHANGED
|
@@ -11,23 +11,31 @@ export class NoteFactory extends EventFactory {
|
|
|
11
11
|
/**
|
|
12
12
|
* Creates a new note factory
|
|
13
13
|
* @param content - Optional initial content
|
|
14
|
+
* @param opts - Optional factory options
|
|
14
15
|
* @returns A new note factory
|
|
15
16
|
*/
|
|
16
|
-
static create(content) {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
static create(content, opts) {
|
|
18
|
+
let factory = new NoteFactory((res) => res(blankEventTemplate(kinds.ShortTextNote)));
|
|
19
|
+
factory = content ? factory.text(content, opts) : factory;
|
|
20
|
+
if (opts)
|
|
21
|
+
factory = factory.meta(opts).zapSplit(opts);
|
|
22
|
+
return factory;
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
21
25
|
* Creates a note reply factory
|
|
22
26
|
* @param parent - The parent note to reply to
|
|
23
27
|
* @param content - Optional initial content
|
|
28
|
+
* @param opts - Optional factory options
|
|
24
29
|
* @returns A new note factory configured as a reply
|
|
25
30
|
*/
|
|
26
|
-
static reply(parent, content) {
|
|
31
|
+
static reply(parent, content, opts) {
|
|
27
32
|
if (!isKind(parent, kinds.ShortTextNote))
|
|
28
33
|
throw new Error("Kind 1 replies should only be used to reply to kind 1 notes");
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
let factory = new NoteFactory((res) => res(blankEventTemplate(kinds.ShortTextNote))).replyTo(parent);
|
|
35
|
+
factory = content ? factory.text(content, opts) : factory;
|
|
36
|
+
if (opts)
|
|
37
|
+
factory = factory.meta(opts).zapSplit(opts);
|
|
38
|
+
return factory;
|
|
31
39
|
}
|
|
32
40
|
/** Sets the parent note for NIP-10 threading */
|
|
33
41
|
replyTo(parent) {
|
package/dist/models/thread.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventModels } from "applesauce-core/event-store";
|
|
2
2
|
import { buildCommonEventRelationFilters } from "applesauce-core/helpers";
|
|
3
3
|
import { getEventUID, kinds } from "applesauce-core/helpers/event";
|
|
4
|
-
import { eventMatchesPointer, getReplaceableAddressFromPointer, isAddressPointer,
|
|
4
|
+
import { eventMatchesPointer, getReplaceableAddressFromPointer, isAddressPointer, isAddressPointerSame, isEventPointer, isEventPointerSame, } from "applesauce-core/helpers/pointers";
|
|
5
5
|
import { map } from "rxjs/operators";
|
|
6
6
|
import { COMMENT_KIND, getCommentReplyPointer } from "../helpers/comment.js";
|
|
7
7
|
import { getNip10References } from "../helpers/threading.js";
|
|
@@ -67,7 +67,9 @@ export function ThreadModel(root, opts) {
|
|
|
67
67
|
/** A model that gets all legacy and NIP-10, and NIP-22 replies for an event */
|
|
68
68
|
export function RepliesModel(event, overrideKinds) {
|
|
69
69
|
return (events) => {
|
|
70
|
-
const filter = {
|
|
70
|
+
const filter = {
|
|
71
|
+
kinds: overrideKinds ?? (event.kind === 1 ? [1, COMMENT_KIND] : [COMMENT_KIND]),
|
|
72
|
+
};
|
|
71
73
|
return events.timeline(buildCommonEventRelationFilters(filter, event)).pipe(map((events) =>
|
|
72
74
|
// Filter for direct replies
|
|
73
75
|
events.filter((reply) => {
|
|
@@ -78,14 +80,15 @@ export function RepliesModel(event, overrideKinds) {
|
|
|
78
80
|
if (!refs.reply)
|
|
79
81
|
return false;
|
|
80
82
|
// If the input was provided as an event pointer, test the reply.e
|
|
81
|
-
if (isEventPointer(event))
|
|
83
|
+
if (isEventPointer(event)) {
|
|
82
84
|
return refs.reply?.e && isEventPointerSame(event, refs.reply.e);
|
|
83
|
-
// If the input was provided as an address pointer, test the reply.a
|
|
84
|
-
else if (isAddressPointer(event))
|
|
85
|
+
} // If the input was provided as an address pointer, test the reply.a
|
|
86
|
+
else if (isAddressPointer(event)) {
|
|
85
87
|
return refs.reply?.a && isAddressPointerSame(event, refs.reply.a);
|
|
86
|
-
// Else test the reply against the event
|
|
87
|
-
else
|
|
88
|
+
} // Else test the reply against the event
|
|
89
|
+
else {
|
|
88
90
|
return eventMatchesPointer(event, refs.reply?.a || refs.reply?.e);
|
|
91
|
+
}
|
|
89
92
|
}
|
|
90
93
|
else if (reply.kind === COMMENT_KIND) {
|
|
91
94
|
// Check if a NIP-22 reply is a direct reply to this event
|
|
@@ -96,12 +99,12 @@ export function RepliesModel(event, overrideKinds) {
|
|
|
96
99
|
if (pointer.type === "external")
|
|
97
100
|
return true;
|
|
98
101
|
// Input is an event pointer, check if they match
|
|
99
|
-
if (isEventPointer(event))
|
|
102
|
+
if (isEventPointer(event)) {
|
|
100
103
|
return pointer.type === "event" ? isEventPointerSame(event, pointer) : false;
|
|
101
|
-
// Input is an address pointer, check if they match
|
|
102
|
-
else if (isAddressPointer(event))
|
|
104
|
+
} // Input is an address pointer, check if they match
|
|
105
|
+
else if (isAddressPointer(event)) {
|
|
103
106
|
return pointer.type === "address" ? isAddressPointerSame(event, pointer) : false;
|
|
104
|
-
// Else test the reply against the event
|
|
107
|
+
} // Else test the reply against the event
|
|
105
108
|
else
|
|
106
109
|
return eventMatchesPointer(event, pointer);
|
|
107
110
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-common",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.2",
|
|
4
4
|
"description": "Common NIP-specific helpers and models for applesauce",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -95,13 +95,13 @@
|
|
|
95
95
|
"@types/debug": "^4.1.12",
|
|
96
96
|
"@types/hash-sum": "^1.0.2",
|
|
97
97
|
"@types/node": "^22.19.1",
|
|
98
|
-
"ajv": "^8.
|
|
98
|
+
"ajv": "^8.20.0",
|
|
99
99
|
"ajv-formats": "^3.0.1",
|
|
100
100
|
"nostr-tools": "^2.19",
|
|
101
101
|
"rimraf": "^6.0.1",
|
|
102
102
|
"typescript": "^5.8.3",
|
|
103
103
|
"vitest": "^4.0.15",
|
|
104
|
-
"yaml": "^2.8.
|
|
104
|
+
"yaml": "^2.8.4"
|
|
105
105
|
},
|
|
106
106
|
"funding": {
|
|
107
107
|
"type": "lightning",
|