applesauce-common 6.0.2 → 6.2.0
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/casts/_circular-import.d.ts +2 -0
- package/dist/casts/_circular-import.js +2 -0
- package/dist/casts/git-grasp-list.d.ts +8 -0
- package/dist/casts/git-grasp-list.js +13 -0
- package/dist/casts/git-lists.d.ts +42 -0
- package/dist/casts/git-lists.js +94 -0
- package/dist/casts/git-repository.d.ts +29 -0
- package/dist/casts/git-repository.js +68 -0
- package/dist/casts/index.d.ts +3 -0
- package/dist/casts/index.js +3 -0
- package/dist/casts/reaction.d.ts +3 -1
- package/dist/casts/reaction.js +6 -2
- package/dist/casts/relay-lists.d.ts +6 -2
- package/dist/casts/relay-lists.js +11 -2
- package/dist/casts/trusted-assertions.d.ts +2 -2
- package/dist/casts/trusted-assertions.js +1 -1
- package/dist/casts/user.d.ts +4 -0
- package/dist/casts/user.js +23 -1
- package/dist/factories/calendar-event.d.ts +0 -5
- package/dist/factories/calendar-event.js +0 -9
- package/dist/factories/calendar-rsvp.d.ts +1 -0
- package/dist/factories/calendar-rsvp.js +1 -0
- package/dist/factories/code-snippet.d.ts +0 -2
- package/dist/factories/code-snippet.js +0 -5
- package/dist/factories/comment.d.ts +0 -2
- package/dist/factories/comment.js +5 -8
- package/dist/factories/favorite-git-repos.d.ts +17 -0
- package/dist/factories/favorite-git-repos.js +43 -0
- package/dist/factories/gift-wrap.js +2 -2
- package/dist/factories/git-authors.d.ts +17 -0
- package/dist/factories/git-authors.js +24 -0
- package/dist/factories/git-grasp-list.d.ts +14 -0
- package/dist/factories/git-grasp-list.js +25 -0
- package/dist/factories/git-repository.d.ts +51 -0
- package/dist/factories/git-repository.js +96 -0
- package/dist/factories/group.d.ts +5 -7
- package/dist/factories/group.js +8 -14
- package/dist/factories/highlight.d.ts +1 -10
- package/dist/factories/highlight.js +2 -12
- package/dist/factories/index.d.ts +6 -4
- package/dist/factories/index.js +6 -4
- package/dist/factories/legacy-message.d.ts +0 -1
- package/dist/factories/list.d.ts +0 -10
- package/dist/factories/list.js +0 -21
- package/dist/factories/nostr-web-token.d.ts +39 -0
- package/dist/factories/nostr-web-token.js +95 -0
- package/dist/factories/picture-post.d.ts +3 -4
- package/dist/factories/picture-post.js +3 -7
- package/dist/factories/poll-response.d.ts +0 -2
- package/dist/factories/poll-response.js +0 -5
- package/dist/factories/poll.d.ts +9 -6
- package/dist/factories/poll.js +12 -9
- package/dist/factories/relay-lists.d.ts +46 -0
- package/dist/factories/relay-lists.js +93 -0
- package/dist/factories/relay-set.d.ts +1 -1
- package/dist/factories/relay-set.js +1 -1
- package/dist/factories/share.d.ts +0 -7
- package/dist/factories/share.js +0 -11
- package/dist/factories/stream-chat-message.d.ts +0 -3
- package/dist/factories/stream-chat-message.js +0 -5
- package/dist/factories/torrent.d.ts +0 -2
- package/dist/factories/torrent.js +0 -5
- package/dist/factories/zap-goal.d.ts +0 -2
- package/dist/factories/zap-goal.js +0 -5
- package/dist/helpers/external-id.d.ts +1 -0
- package/dist/helpers/external-id.js +8 -27
- package/dist/helpers/git-grasp-list.d.ts +8 -0
- package/dist/helpers/git-grasp-list.js +15 -0
- package/dist/helpers/git-lists.d.ts +20 -0
- package/dist/helpers/git-lists.js +28 -0
- package/dist/helpers/git-repository.d.ts +39 -0
- package/dist/helpers/git-repository.js +104 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/nostr-web-token.d.ts +54 -0
- package/dist/helpers/nostr-web-token.js +124 -0
- package/dist/helpers/relay-list.d.ts +5 -0
- package/dist/helpers/relay-list.js +8 -0
- package/dist/observable/cast-stream.d.ts +1 -8
- package/dist/observable/cast-stream.js +2 -29
- package/dist/observable/chainable.d.ts +1 -1
- package/dist/observable/chainable.js +1 -1
- package/dist/operations/git-grasp-list.d.ts +7 -0
- package/dist/operations/git-grasp-list.js +18 -0
- package/dist/operations/git-repository.d.ts +45 -0
- package/dist/operations/git-repository.js +160 -0
- package/dist/operations/hashtags.d.ts +2 -0
- package/dist/operations/hashtags.js +7 -0
- package/dist/operations/index.d.ts +3 -0
- package/dist/operations/index.js +3 -0
- package/dist/operations/nostr-web-token.d.ts +27 -0
- package/dist/operations/nostr-web-token.js +58 -0
- package/dist/operations/poll.d.ts +3 -2
- package/dist/operations/poll.js +4 -3
- package/package.json +4 -4
- package/dist/factories/blocked-relays.d.ts +0 -10
- package/dist/factories/blocked-relays.js +0 -16
- package/dist/factories/dm-relays.d.ts +0 -10
- package/dist/factories/dm-relays.js +0 -16
- package/dist/factories/favorite-relays.d.ts +0 -16
- package/dist/factories/favorite-relays.js +0 -31
- package/dist/factories/search-relays.d.ts +0 -10
- package/dist/factories/search-relays.js +0 -16
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { blankEventTemplate, EventFactory, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { NOSTR_WEB_TOKEN_KIND } from "../helpers/nostr-web-token.js";
|
|
3
|
+
import * as NostrWebToken from "../operations/nostr-web-token.js";
|
|
4
|
+
/** Factory for Nostr Web Token events (kind 27519). @see https://github.com/Open-Ranking/nostr-web-tokens */
|
|
5
|
+
export class NostrWebTokenFactory extends EventFactory {
|
|
6
|
+
/** Creates a Nostr Web Token factory. */
|
|
7
|
+
static create(claims) {
|
|
8
|
+
const factory = new NostrWebTokenFactory((res) => res(blankEventTemplate(NOSTR_WEB_TOKEN_KIND)));
|
|
9
|
+
if (!claims)
|
|
10
|
+
return factory;
|
|
11
|
+
let result = factory;
|
|
12
|
+
if (claims.issuer !== undefined)
|
|
13
|
+
result = result.issuer(claims.issuer);
|
|
14
|
+
if (claims.subject !== undefined)
|
|
15
|
+
result = result.subject(claims.subject);
|
|
16
|
+
if (claims.audiences !== undefined)
|
|
17
|
+
result = result.audiences(claims.audiences);
|
|
18
|
+
if (claims.issuedAt !== undefined)
|
|
19
|
+
result = result.issuedAt(claims.issuedAt);
|
|
20
|
+
if (claims.expiration !== undefined)
|
|
21
|
+
result = result.expiration(claims.expiration);
|
|
22
|
+
if (claims.notBefore !== undefined)
|
|
23
|
+
result = result.notBefore(claims.notBefore);
|
|
24
|
+
if (claims.claims) {
|
|
25
|
+
for (const [name, values] of Object.entries(claims.claims)) {
|
|
26
|
+
result = result.clearClaim(name);
|
|
27
|
+
for (const value of values)
|
|
28
|
+
result = result.addClaim(name, value, false);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
/** Creates a factory configured to modify an existing Nostr Web Token. */
|
|
34
|
+
static modify(event) {
|
|
35
|
+
if (event.kind !== NOSTR_WEB_TOKEN_KIND)
|
|
36
|
+
throw new Error("Expected a Nostr Web Token event");
|
|
37
|
+
return new NostrWebTokenFactory((res) => res(toEventTemplate(event)));
|
|
38
|
+
}
|
|
39
|
+
/** Sets or removes the issuer claim. */
|
|
40
|
+
issuer(value) {
|
|
41
|
+
return this.chain(NostrWebToken.setIssuer(value));
|
|
42
|
+
}
|
|
43
|
+
/** Sets or removes the subject claim. */
|
|
44
|
+
subject(value) {
|
|
45
|
+
return this.chain(NostrWebToken.setSubject(value));
|
|
46
|
+
}
|
|
47
|
+
/** Replaces all audience claims. */
|
|
48
|
+
audiences(values) {
|
|
49
|
+
return this.chain(NostrWebToken.setAudiences(values));
|
|
50
|
+
}
|
|
51
|
+
/** Adds an audience claim. */
|
|
52
|
+
addAudience(value, replace = true) {
|
|
53
|
+
return this.chain(NostrWebToken.addAudience(value, replace));
|
|
54
|
+
}
|
|
55
|
+
/** Removes a matching audience claim. */
|
|
56
|
+
removeAudience(value) {
|
|
57
|
+
return this.chain(NostrWebToken.removeAudience(value));
|
|
58
|
+
}
|
|
59
|
+
/** Clears all audience claims. */
|
|
60
|
+
clearAudiences() {
|
|
61
|
+
return this.chain(NostrWebToken.clearAudiences());
|
|
62
|
+
}
|
|
63
|
+
/** Sets or removes the issued-at claim. */
|
|
64
|
+
issuedAt(value) {
|
|
65
|
+
return this.chain(NostrWebToken.setIssuedAt(value));
|
|
66
|
+
}
|
|
67
|
+
/** Sets or removes the expiration claim. */
|
|
68
|
+
expiration(value) {
|
|
69
|
+
return this.chain(NostrWebToken.setExpiration(value));
|
|
70
|
+
}
|
|
71
|
+
/** Sets or removes the not-before claim. */
|
|
72
|
+
notBefore(value) {
|
|
73
|
+
return this.chain(NostrWebToken.setNotBefore(value));
|
|
74
|
+
}
|
|
75
|
+
/** Sets or removes a singleton claim. */
|
|
76
|
+
claim(name, value) {
|
|
77
|
+
return this.chain(NostrWebToken.setClaim(name, value));
|
|
78
|
+
}
|
|
79
|
+
/** Adds an application-defined claim. */
|
|
80
|
+
addClaim(name, value, replace = true) {
|
|
81
|
+
return this.chain(NostrWebToken.addClaim(name, value, replace));
|
|
82
|
+
}
|
|
83
|
+
/** Removes matching values for a claim, or all tags with the claim name when value is omitted. */
|
|
84
|
+
removeClaim(name, value) {
|
|
85
|
+
return this.chain(NostrWebToken.removeClaim(name, value));
|
|
86
|
+
}
|
|
87
|
+
/** Clears all tags with the claim name. */
|
|
88
|
+
clearClaim(name) {
|
|
89
|
+
return this.chain(NostrWebToken.clearClaim(name));
|
|
90
|
+
}
|
|
91
|
+
/** Sets the human-readable signing message. */
|
|
92
|
+
message(content) {
|
|
93
|
+
return this.content(content);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { EventFactory } from "applesauce-core/factories";
|
|
2
2
|
import { KnownEventTemplate } from "applesauce-core/helpers";
|
|
3
3
|
import { TextContentOptions } from "applesauce-core/operations/content";
|
|
4
|
-
import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
5
4
|
import { FileMetadataFields } from "../helpers/file-metadata.js";
|
|
6
5
|
import { PICTURE_POST_KIND } from "../helpers/picture-post.js";
|
|
7
6
|
export type PicturePostTemplate = KnownEventTemplate<typeof PICTURE_POST_KIND>;
|
|
7
|
+
export type PicturePostFactoryOptions = TextContentOptions;
|
|
8
8
|
/** A factory class for building kind 20 picture post events */
|
|
9
9
|
export declare class PicturePostFactory extends EventFactory<typeof PICTURE_POST_KIND, PicturePostTemplate> {
|
|
10
10
|
/**
|
|
11
11
|
* Creates a new picture post factory
|
|
12
12
|
* @param attachments - One or more image attachments
|
|
13
13
|
* @param caption - Optional caption text
|
|
14
|
+
* @param options - Optional content
|
|
14
15
|
*/
|
|
15
|
-
static create(attachments: FileMetadataFields | FileMetadataFields[], caption?: string): PicturePostFactory;
|
|
16
|
+
static create(attachments: FileMetadataFields | FileMetadataFields[], caption?: string, options?: PicturePostFactoryOptions): PicturePostFactory;
|
|
16
17
|
/** Adds image attachments via "imeta" tags */
|
|
17
18
|
attachments(attachments: FileMetadataFields[]): this;
|
|
18
19
|
/** Sets the image metadata (x/m tags) for the post */
|
|
@@ -23,6 +24,4 @@ export declare class PicturePostFactory extends EventFactory<typeof PICTURE_POST
|
|
|
23
24
|
addHashtag(hashtag: string): this;
|
|
24
25
|
/** Adds multiple hashtags as "t" tags */
|
|
25
26
|
hashtags(tags: string[]): this;
|
|
26
|
-
/** Sets meta tags */
|
|
27
|
-
meta(options: MetaTagOptions): this;
|
|
28
27
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
|
|
2
2
|
import { setShortTextContent } from "applesauce-core/operations/content";
|
|
3
|
-
import { setMetaTags } from "applesauce-core/operations/event";
|
|
4
3
|
import { PICTURE_POST_KIND } from "../helpers/picture-post.js";
|
|
5
4
|
import { setImageMetadata } from "../operations/picture-post.js";
|
|
6
5
|
import { addMediaAttachments } from "../operations/media-attachment.js";
|
|
@@ -11,12 +10,13 @@ export class PicturePostFactory extends EventFactory {
|
|
|
11
10
|
* Creates a new picture post factory
|
|
12
11
|
* @param attachments - One or more image attachments
|
|
13
12
|
* @param caption - Optional caption text
|
|
13
|
+
* @param options - Optional content
|
|
14
14
|
*/
|
|
15
|
-
static create(attachments, caption) {
|
|
15
|
+
static create(attachments, caption, options) {
|
|
16
16
|
const list = Array.isArray(attachments) ? attachments : [attachments];
|
|
17
17
|
let factory = new PicturePostFactory((res) => res(blankEventTemplate(PICTURE_POST_KIND))).attachments(list);
|
|
18
18
|
if (caption)
|
|
19
|
-
factory = factory.caption(caption);
|
|
19
|
+
factory = factory.caption(caption, options);
|
|
20
20
|
return factory;
|
|
21
21
|
}
|
|
22
22
|
/** Adds image attachments via "imeta" tags */
|
|
@@ -39,8 +39,4 @@ export class PicturePostFactory extends EventFactory {
|
|
|
39
39
|
hashtags(tags) {
|
|
40
40
|
return this.chain(includeHashtags(tags));
|
|
41
41
|
}
|
|
42
|
-
/** Sets meta tags */
|
|
43
|
-
meta(options) {
|
|
44
|
-
return this.chain(setMetaTags(options));
|
|
45
|
-
}
|
|
46
42
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
|
|
2
2
|
import { setContent } from "applesauce-core/operations/content";
|
|
3
|
-
import { setMetaTags } from "applesauce-core/operations/event";
|
|
4
3
|
import { POLL_RESPONSE_KIND } from "../helpers/poll.js";
|
|
5
4
|
import * as PollResponse from "../operations/poll-response.js";
|
|
6
5
|
/** A factory class for building NIP-88 poll response events (kind 1018) */
|
|
@@ -39,8 +38,4 @@ export class PollResponseFactory extends EventFactory {
|
|
|
39
38
|
comment(comment) {
|
|
40
39
|
return this.chain((draft) => setContent(comment)(draft));
|
|
41
40
|
}
|
|
42
|
-
/** Sets meta tags */
|
|
43
|
-
meta(options) {
|
|
44
|
-
return this.chain((draft) => setMetaTags(options)(draft));
|
|
45
|
-
}
|
|
46
41
|
}
|
package/dist/factories/poll.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { EventFactory } from "applesauce-core/factories";
|
|
2
2
|
import { KnownEventTemplate } from "applesauce-core/helpers";
|
|
3
|
+
import { TextContentOptions } from "applesauce-core/operations/content";
|
|
4
|
+
import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
3
5
|
import { POLL_KIND, PollType } from "../helpers/poll.js";
|
|
4
6
|
import { ZapOptions } from "../operations/zap-split.js";
|
|
7
|
+
export type PollFactoryCreateOptions = TextContentOptions & MetaTagOptions;
|
|
5
8
|
export interface PollOption {
|
|
6
9
|
id: string;
|
|
7
10
|
label: string;
|
|
@@ -11,13 +14,13 @@ export type PollTemplate = KnownEventTemplate<typeof POLL_KIND>;
|
|
|
11
14
|
export declare class PollFactory extends EventFactory<typeof POLL_KIND, PollTemplate> {
|
|
12
15
|
/**
|
|
13
16
|
* Creates a new poll factory
|
|
14
|
-
* @param question - The poll question
|
|
15
|
-
* @param
|
|
16
|
-
* @
|
|
17
|
+
* @param question - The poll question (content); hashtags and `:shortcode:` emojis are reflected in tags when using {@link TextContentOptions}
|
|
18
|
+
* @param pollOptions - The poll answer options
|
|
19
|
+
* @param options - Text content options (custom emojis, content warning) and/or meta tags (e.g. `alt`)
|
|
17
20
|
*/
|
|
18
|
-
static create(question: string,
|
|
19
|
-
/** Sets the poll question */
|
|
20
|
-
question(question: string): this;
|
|
21
|
+
static create(question: string, pollOptions: PollOption[], options?: PollFactoryCreateOptions): PollFactory;
|
|
22
|
+
/** Sets the poll question as event content (hashtags, nostr links, custom emojis) */
|
|
23
|
+
question(question: string, options?: TextContentOptions): this;
|
|
21
24
|
/** Sets the poll options */
|
|
22
25
|
options(options: PollOption[]): this;
|
|
23
26
|
/** Sets the poll type (singlechoice or multiplechoice) */
|
package/dist/factories/poll.js
CHANGED
|
@@ -6,16 +6,19 @@ import { setZapSplit } from "../operations/zap-split.js";
|
|
|
6
6
|
export class PollFactory extends EventFactory {
|
|
7
7
|
/**
|
|
8
8
|
* Creates a new poll factory
|
|
9
|
-
* @param question - The poll question
|
|
10
|
-
* @param
|
|
11
|
-
* @
|
|
9
|
+
* @param question - The poll question (content); hashtags and `:shortcode:` emojis are reflected in tags when using {@link TextContentOptions}
|
|
10
|
+
* @param pollOptions - The poll answer options
|
|
11
|
+
* @param options - Text content options (custom emojis, content warning) and/or meta tags (e.g. `alt`)
|
|
12
12
|
*/
|
|
13
|
-
static create(question, options) {
|
|
14
|
-
return new PollFactory((res) => res(blankEventTemplate(POLL_KIND)))
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
static create(question, pollOptions, options) {
|
|
14
|
+
return new PollFactory((res) => res(blankEventTemplate(POLL_KIND)))
|
|
15
|
+
.question(question, options)
|
|
16
|
+
.options(pollOptions)
|
|
17
|
+
.meta({ alt: "A poll", ...options });
|
|
18
|
+
}
|
|
19
|
+
/** Sets the poll question as event content (hashtags, nostr links, custom emojis) */
|
|
20
|
+
question(question, options) {
|
|
21
|
+
return this.chain(Poll.setQuestion(question, options));
|
|
19
22
|
}
|
|
20
23
|
/** Sets the poll options */
|
|
21
24
|
options(options) {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { kinds, KnownEvent, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
2
|
+
import { AddressPointer } from "applesauce-core/helpers/pointers";
|
|
3
|
+
import { FAVORITE_RELAYS_KIND, LOOKUP_RELAY_LIST_KIND } from "../helpers/relay-list.js";
|
|
4
|
+
import { ListFactory } from "./list.js";
|
|
5
|
+
/**
|
|
6
|
+
* A base factory class for NIP-51 lists that contain relay URLs (`relay` tags).
|
|
7
|
+
* Provides `addRelay` and `removeRelay` in addition to `title`, `description`, and `image`.
|
|
8
|
+
*/
|
|
9
|
+
export declare class NIP51RelayListFactory<K extends number = number, T extends KnownEventTemplate<K> = KnownEventTemplate<K>> extends ListFactory<K, T> {
|
|
10
|
+
/** Adds a relay URL to the list's public tags */
|
|
11
|
+
addRelay(relay: string | string[], hidden?: boolean): this;
|
|
12
|
+
/** Removes a relay URL from the list */
|
|
13
|
+
removeRelay(relay: string | string[], hidden?: boolean): this;
|
|
14
|
+
}
|
|
15
|
+
export type BlockedRelaysTemplate = KnownEventTemplate<kinds.BlockedRelaysList>;
|
|
16
|
+
/** A factory class for building kind 10006 blocked relays list events */
|
|
17
|
+
export declare class BlockedRelaysFactory extends NIP51RelayListFactory<kinds.BlockedRelaysList, BlockedRelaysTemplate> {
|
|
18
|
+
static create(): BlockedRelaysFactory;
|
|
19
|
+
static modify(event: NostrEvent | KnownEvent<kinds.BlockedRelaysList>): BlockedRelaysFactory;
|
|
20
|
+
}
|
|
21
|
+
export type DmRelaysTemplate = KnownEventTemplate<kinds.DirectMessageRelaysList>;
|
|
22
|
+
/** A factory class for building kind 10050 direct message relays list events */
|
|
23
|
+
export declare class DmRelaysFactory extends NIP51RelayListFactory<kinds.DirectMessageRelaysList, DmRelaysTemplate> {
|
|
24
|
+
static create(): DmRelaysFactory;
|
|
25
|
+
static modify(event: NostrEvent | KnownEvent<kinds.DirectMessageRelaysList>): DmRelaysFactory;
|
|
26
|
+
}
|
|
27
|
+
export type FavoriteRelaysTemplate = KnownEventTemplate<typeof FAVORITE_RELAYS_KIND>;
|
|
28
|
+
/** A factory class for building kind 10012 favorite relays list events */
|
|
29
|
+
export declare class FavoriteRelaysFactory extends NIP51RelayListFactory<typeof FAVORITE_RELAYS_KIND, FavoriteRelaysTemplate> {
|
|
30
|
+
static create(): FavoriteRelaysFactory;
|
|
31
|
+
static modify(event: NostrEvent | KnownEvent<typeof FAVORITE_RELAYS_KIND>): FavoriteRelaysFactory;
|
|
32
|
+
addRelaySet(addr: AddressPointer | AddressPointer[], hidden?: boolean): this;
|
|
33
|
+
removeRelaySet(addr: AddressPointer | AddressPointer[], hidden?: boolean): this;
|
|
34
|
+
}
|
|
35
|
+
export type LookupRelayListTemplate = KnownEventTemplate<typeof LOOKUP_RELAY_LIST_KIND>;
|
|
36
|
+
/** A factory class for building kind 10086 lookup / indexer relays list events */
|
|
37
|
+
export declare class LookupRelayListFactory extends NIP51RelayListFactory<typeof LOOKUP_RELAY_LIST_KIND, LookupRelayListTemplate> {
|
|
38
|
+
static create(): LookupRelayListFactory;
|
|
39
|
+
static modify(event: NostrEvent | KnownEvent<typeof LOOKUP_RELAY_LIST_KIND>): LookupRelayListFactory;
|
|
40
|
+
}
|
|
41
|
+
export type SearchRelaysTemplate = KnownEventTemplate<kinds.SearchRelaysList>;
|
|
42
|
+
/** A factory class for building kind 10007 search relays list events */
|
|
43
|
+
export declare class SearchRelaysFactory extends NIP51RelayListFactory<kinds.SearchRelaysList, SearchRelaysTemplate> {
|
|
44
|
+
static create(): SearchRelaysFactory;
|
|
45
|
+
static modify(event: NostrEvent | KnownEvent<kinds.SearchRelaysList>): SearchRelaysFactory;
|
|
46
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { isKind, kinds } from "applesauce-core/helpers";
|
|
3
|
+
import { addAddressPointerTag, removeAddressPointerTag } from "applesauce-core/operations/tag/common";
|
|
4
|
+
import { addRelayTag, removeRelayTag } from "applesauce-core/operations/tag/relay";
|
|
5
|
+
import { FAVORITE_RELAYS_KIND, LOOKUP_RELAY_LIST_KIND } from "../helpers/relay-list.js";
|
|
6
|
+
import { ListFactory } from "./list.js";
|
|
7
|
+
/**
|
|
8
|
+
* A base factory class for NIP-51 lists that contain relay URLs (`relay` tags).
|
|
9
|
+
* Provides `addRelay` and `removeRelay` in addition to `title`, `description`, and `image`.
|
|
10
|
+
*/
|
|
11
|
+
export class NIP51RelayListFactory extends ListFactory {
|
|
12
|
+
/** Adds a relay URL to the list's public tags */
|
|
13
|
+
addRelay(relay, hidden = false) {
|
|
14
|
+
const relays = Array.isArray(relay) ? relay : [relay];
|
|
15
|
+
return hidden
|
|
16
|
+
? this.modifyHiddenTags(...relays.map((r) => addRelayTag(r)))
|
|
17
|
+
: this.modifyPublicTags(...relays.map((r) => addRelayTag(r)));
|
|
18
|
+
}
|
|
19
|
+
/** Removes a relay URL from the list */
|
|
20
|
+
removeRelay(relay, hidden = false) {
|
|
21
|
+
const relays = Array.isArray(relay) ? relay : [relay];
|
|
22
|
+
return hidden
|
|
23
|
+
? this.modifyHiddenTags(...relays.map((r) => removeRelayTag(r)))
|
|
24
|
+
: this.modifyPublicTags(...relays.map((r) => removeRelayTag(r)));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** A factory class for building kind 10006 blocked relays list events */
|
|
28
|
+
export class BlockedRelaysFactory extends NIP51RelayListFactory {
|
|
29
|
+
static create() {
|
|
30
|
+
return new BlockedRelaysFactory((res) => res(blankEventTemplate(kinds.BlockedRelaysList)));
|
|
31
|
+
}
|
|
32
|
+
static modify(event) {
|
|
33
|
+
if (!isKind(event, kinds.BlockedRelaysList))
|
|
34
|
+
throw new Error("Event is not a blocked relays event");
|
|
35
|
+
return new BlockedRelaysFactory((res) => res(toEventTemplate(event)));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** A factory class for building kind 10050 direct message relays list events */
|
|
39
|
+
export class DmRelaysFactory extends NIP51RelayListFactory {
|
|
40
|
+
static create() {
|
|
41
|
+
return new DmRelaysFactory((res) => res(blankEventTemplate(kinds.DirectMessageRelaysList)));
|
|
42
|
+
}
|
|
43
|
+
static modify(event) {
|
|
44
|
+
if (!isKind(event, kinds.DirectMessageRelaysList))
|
|
45
|
+
throw new Error("Event is not a DM relays event");
|
|
46
|
+
return new DmRelaysFactory((res) => res(toEventTemplate(event)));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** A factory class for building kind 10012 favorite relays list events */
|
|
50
|
+
export class FavoriteRelaysFactory extends NIP51RelayListFactory {
|
|
51
|
+
static create() {
|
|
52
|
+
return new FavoriteRelaysFactory((res) => res(blankEventTemplate(FAVORITE_RELAYS_KIND)));
|
|
53
|
+
}
|
|
54
|
+
static modify(event) {
|
|
55
|
+
if (event.kind !== FAVORITE_RELAYS_KIND)
|
|
56
|
+
throw new Error("Event is not a favorite relays event");
|
|
57
|
+
return new FavoriteRelaysFactory((res) => res(toEventTemplate(event)));
|
|
58
|
+
}
|
|
59
|
+
addRelaySet(addr, hidden = false) {
|
|
60
|
+
const addrs = Array.isArray(addr) ? addr : [addr];
|
|
61
|
+
return hidden
|
|
62
|
+
? this.modifyHiddenTags(...addrs.map((a) => addAddressPointerTag(a)))
|
|
63
|
+
: this.modifyPublicTags(...addrs.map((a) => addAddressPointerTag(a)));
|
|
64
|
+
}
|
|
65
|
+
removeRelaySet(addr, hidden = false) {
|
|
66
|
+
const addrs = Array.isArray(addr) ? addr : [addr];
|
|
67
|
+
return hidden
|
|
68
|
+
? this.modifyHiddenTags(...addrs.map((a) => removeAddressPointerTag(a)))
|
|
69
|
+
: this.modifyPublicTags(...addrs.map((a) => removeAddressPointerTag(a)));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** A factory class for building kind 10086 lookup / indexer relays list events */
|
|
73
|
+
export class LookupRelayListFactory extends NIP51RelayListFactory {
|
|
74
|
+
static create() {
|
|
75
|
+
return new LookupRelayListFactory((res) => res(blankEventTemplate(LOOKUP_RELAY_LIST_KIND)));
|
|
76
|
+
}
|
|
77
|
+
static modify(event) {
|
|
78
|
+
if (event.kind !== LOOKUP_RELAY_LIST_KIND)
|
|
79
|
+
throw new Error("Event is not a lookup relay list event");
|
|
80
|
+
return new LookupRelayListFactory((res) => res(toEventTemplate(event)));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** A factory class for building kind 10007 search relays list events */
|
|
84
|
+
export class SearchRelaysFactory extends NIP51RelayListFactory {
|
|
85
|
+
static create() {
|
|
86
|
+
return new SearchRelaysFactory((res) => res(blankEventTemplate(kinds.SearchRelaysList)));
|
|
87
|
+
}
|
|
88
|
+
static modify(event) {
|
|
89
|
+
if (!isKind(event, kinds.SearchRelaysList))
|
|
90
|
+
throw new Error("Event is not a search relays event");
|
|
91
|
+
return new SearchRelaysFactory((res) => res(toEventTemplate(event)));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { kinds, KnownEvent, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
2
|
-
import { NIP51RelayListFactory } from "./
|
|
2
|
+
import { NIP51RelayListFactory } from "./relay-lists.js";
|
|
3
3
|
export type RelaySetTemplate = KnownEventTemplate<kinds.Relaysets>;
|
|
4
4
|
/** A factory class for building kind 30002 relay set events */
|
|
5
5
|
export declare class RelaySetFactory extends NIP51RelayListFactory<kinds.Relaysets, RelaySetTemplate> {
|
|
@@ -2,7 +2,7 @@ import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
|
|
|
2
2
|
import { isKind, kinds } from "applesauce-core/helpers";
|
|
3
3
|
import { includeReplaceableIdentifier } from "applesauce-core/operations/index";
|
|
4
4
|
import { nanoid } from "nanoid";
|
|
5
|
-
import { NIP51RelayListFactory } from "./
|
|
5
|
+
import { NIP51RelayListFactory } from "./relay-lists.js";
|
|
6
6
|
/** A factory class for building kind 30002 relay set events */
|
|
7
7
|
export class RelaySetFactory extends NIP51RelayListFactory {
|
|
8
8
|
/** Creates a new relay set factory with an auto-generated identifier */
|
|
@@ -8,17 +8,10 @@ export declare class ShareFactory extends EventFactory<number, EventTemplate> {
|
|
|
8
8
|
/**
|
|
9
9
|
* Creates a new share factory
|
|
10
10
|
* @param event - The event being shared
|
|
11
|
-
* @returns A new share factory
|
|
12
11
|
*/
|
|
13
12
|
static create(event: NostrEvent): ShareFactory;
|
|
14
13
|
/** Creates a new share event for an existing event */
|
|
15
14
|
static share(event: NostrEvent): ShareFactory;
|
|
16
|
-
/**
|
|
17
|
-
* Creates a quote-repost: sets the event reference tags and uses a custom comment as content
|
|
18
|
-
* @param event - The event being quoted
|
|
19
|
-
* @param comment - The quote comment text
|
|
20
|
-
*/
|
|
21
|
-
static quote(event: NostrEvent, comment: string): ShareFactory;
|
|
22
15
|
/** Sets the event being shared */
|
|
23
16
|
setEvent(event: NostrEvent): this;
|
|
24
17
|
/** Sets zap split configuration */
|
package/dist/factories/share.js
CHANGED
|
@@ -7,7 +7,6 @@ export class ShareFactory extends EventFactory {
|
|
|
7
7
|
/**
|
|
8
8
|
* Creates a new share factory
|
|
9
9
|
* @param event - The event being shared
|
|
10
|
-
* @returns A new share factory
|
|
11
10
|
*/
|
|
12
11
|
static create(event) {
|
|
13
12
|
return new ShareFactory((res) => res(blankEventTemplate(kinds.Repost))).setEvent(event);
|
|
@@ -16,16 +15,6 @@ export class ShareFactory extends EventFactory {
|
|
|
16
15
|
static share(event) {
|
|
17
16
|
return ShareFactory.create(event);
|
|
18
17
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Creates a quote-repost: sets the event reference tags and uses a custom comment as content
|
|
21
|
-
* @param event - The event being quoted
|
|
22
|
-
* @param comment - The quote comment text
|
|
23
|
-
*/
|
|
24
|
-
static quote(event, comment) {
|
|
25
|
-
return new ShareFactory((res) => res(blankEventTemplate(kinds.Repost)))
|
|
26
|
-
.setEvent(event)
|
|
27
|
-
.chain((draft) => ({ ...draft, content: comment }));
|
|
28
|
-
}
|
|
29
18
|
/** Sets the event being shared */
|
|
30
19
|
setEvent(event) {
|
|
31
20
|
return this.chain(pipeFromAsyncArray([
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { EventFactory } from "applesauce-core/factories";
|
|
2
2
|
import { kinds, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
3
|
import { TextContentOptions } from "applesauce-core/operations/content";
|
|
4
|
-
import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
5
4
|
import { AddressPointer } from "applesauce-core/helpers/pointers";
|
|
6
5
|
export type StreamChatMessageTemplate = KnownEventTemplate<kinds.LiveChatMessage>;
|
|
7
6
|
/** A factory class for building NIP-53 stream chat message events (kind 1311) */
|
|
@@ -17,6 +16,4 @@ export declare class StreamChatMessageFactory extends EventFactory<kinds.LiveCha
|
|
|
17
16
|
stream(stream: NostrEvent | AddressPointer): this;
|
|
18
17
|
/** Sets the message content */
|
|
19
18
|
message(content: string, options?: TextContentOptions): this;
|
|
20
|
-
/** Sets meta tags */
|
|
21
|
-
meta(options: MetaTagOptions): this;
|
|
22
19
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
|
|
2
2
|
import { kinds } from "applesauce-core/helpers";
|
|
3
|
-
import { setMetaTags } from "applesauce-core/operations/event";
|
|
4
3
|
import { setMessage, setStream } from "../operations/stream-chat.js";
|
|
5
4
|
/** A factory class for building NIP-53 stream chat message events (kind 1311) */
|
|
6
5
|
export class StreamChatMessageFactory extends EventFactory {
|
|
@@ -24,8 +23,4 @@ export class StreamChatMessageFactory extends EventFactory {
|
|
|
24
23
|
message(content, options) {
|
|
25
24
|
return this.chain(setMessage(content, options));
|
|
26
25
|
}
|
|
27
|
-
/** Sets meta tags */
|
|
28
|
-
meta(options) {
|
|
29
|
-
return this.chain(setMetaTags(options));
|
|
30
|
-
}
|
|
31
26
|
}
|
|
@@ -52,6 +52,4 @@ export declare class TorrentFactory extends EventFactory<typeof TORRENT_KIND, To
|
|
|
52
52
|
addExternalId(id: TorrentExternalIdentifier): this;
|
|
53
53
|
/** Adds external identifiers */
|
|
54
54
|
externalIds(ids: TorrentExternalIdentifier[]): this;
|
|
55
|
-
/** Sets meta tags */
|
|
56
|
-
meta(options: MetaTagOptions): this;
|
|
57
55
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
|
|
2
|
-
import { setMetaTags } from "applesauce-core/operations/event";
|
|
3
2
|
import { TORRENT_KIND } from "../helpers/torrent.js";
|
|
4
3
|
import { addTorrentExternalIdentifier, addTorrentFile, addTorrentSearchTag, addTorrentTracker, setTorrentCategory, setTorrentCategoryPath, setTorrentInfoHash, setTorrentTitle, } from "../operations/torrent.js";
|
|
5
4
|
/** A factory class for building NIP-35 torrent events (kind 2003) */
|
|
@@ -86,8 +85,4 @@ export class TorrentFactory extends EventFactory {
|
|
|
86
85
|
return result;
|
|
87
86
|
});
|
|
88
87
|
}
|
|
89
|
-
/** Sets meta tags */
|
|
90
|
-
meta(options) {
|
|
91
|
-
return this.chain((draft) => setMetaTags(options)(draft));
|
|
92
|
-
}
|
|
93
88
|
}
|
|
@@ -30,6 +30,4 @@ export declare class ZapGoalFactory extends EventFactory<typeof ZAP_GOAL_KIND, Z
|
|
|
30
30
|
goal(goalId: string, relay?: string): this;
|
|
31
31
|
/** Sets the zap split for the zap goal */
|
|
32
32
|
zapSplit(options: ZapOptions): this;
|
|
33
|
-
/** Sets the meta tags for the zap goal */
|
|
34
|
-
meta(options: MetaTagOptions): this;
|
|
35
33
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { blankEventTemplate, EventFactory } from "applesauce-core/factories";
|
|
2
|
-
import { setMetaTags } from "applesauce-core/operations/event";
|
|
3
2
|
import { ZAP_GOAL_KIND } from "../helpers/zap-goal.js";
|
|
4
3
|
import * as ZapGoal from "../operations/zap-goal.js";
|
|
5
4
|
import { setZapSplit } from "../operations/zap-split.js";
|
|
@@ -42,8 +41,4 @@ export class ZapGoalFactory extends EventFactory {
|
|
|
42
41
|
zapSplit(options) {
|
|
43
42
|
return this.chain(setZapSplit(options, undefined));
|
|
44
43
|
}
|
|
45
|
-
/** Sets the meta tags for the zap goal */
|
|
46
|
-
meta(options) {
|
|
47
|
-
return this.chain(setMetaTags(options));
|
|
48
|
-
}
|
|
49
44
|
}
|
|
@@ -24,6 +24,8 @@ export function parseExternalPointer(identifier) {
|
|
|
24
24
|
return { kind: "#", identifier: identifier };
|
|
25
25
|
if (identifier.startsWith("geo:"))
|
|
26
26
|
return { kind: "geo", identifier: identifier };
|
|
27
|
+
if (identifier.startsWith("iso3166:"))
|
|
28
|
+
return { kind: "iso3166", identifier: identifier };
|
|
27
29
|
if (identifier.startsWith("isbn:"))
|
|
28
30
|
return { kind: "isbn", identifier: identifier };
|
|
29
31
|
if (identifier.startsWith("podcast:guid:"))
|
|
@@ -37,33 +39,12 @@ export function parseExternalPointer(identifier) {
|
|
|
37
39
|
if (identifier.startsWith("doi:"))
|
|
38
40
|
return { kind: "doi", identifier: identifier };
|
|
39
41
|
// Check for blockchain identifiers
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return { kind:
|
|
46
|
-
}
|
|
47
|
-
// Ethereum: ethereum:<chainId>:tx:<txHash> or ethereum:<chainId>:address:<address>
|
|
48
|
-
const ethereumTxMatch = identifier.match(/^ethereum:(\d+):tx:(.+)$/);
|
|
49
|
-
if (ethereumTxMatch) {
|
|
50
|
-
return { kind: "ethereum:tx", identifier: identifier };
|
|
51
|
-
}
|
|
52
|
-
const ethereumAddressMatch = identifier.match(/^ethereum:(\d+):address:(.+)$/);
|
|
53
|
-
if (ethereumAddressMatch) {
|
|
54
|
-
return { kind: "ethereum:address", identifier: identifier };
|
|
55
|
-
}
|
|
56
|
-
// Other blockchains: <blockchain>:tx:<txid> or <blockchain>:address:<address>
|
|
57
|
-
// Exclude known prefixes to avoid false matches
|
|
58
|
-
const blockchainTxMatch = identifier.match(/^([a-z0-9]+):tx:(.+)$/);
|
|
59
|
-
if (blockchainTxMatch && !identifier.startsWith("bitcoin:") && !identifier.startsWith("ethereum:")) {
|
|
60
|
-
const blockchain = blockchainTxMatch[1];
|
|
61
|
-
return { kind: `${blockchain}:tx`, identifier: identifier };
|
|
62
|
-
}
|
|
63
|
-
const blockchainAddressMatch = identifier.match(/^([a-z0-9]+):address:(.+)$/);
|
|
64
|
-
if (blockchainAddressMatch && !identifier.startsWith("bitcoin:") && !identifier.startsWith("ethereum:")) {
|
|
65
|
-
const blockchain = blockchainAddressMatch[1];
|
|
66
|
-
return { kind: `${blockchain}:address`, identifier: identifier };
|
|
42
|
+
// Generic format (NIP-73): <blockchain>:[<chainId>:]tx:<txid> or <blockchain>:[<chainId>:]address:<address>
|
|
43
|
+
// The optional chainId (e.g. ethereum:1:tx:...) is not part of the "k" tag kind
|
|
44
|
+
const blockchainMatch = identifier.match(/^([a-z0-9]+):(?:\d+:)?(tx|address):.+$/);
|
|
45
|
+
if (blockchainMatch) {
|
|
46
|
+
const [, blockchain, type] = blockchainMatch;
|
|
47
|
+
return { kind: `${blockchain}:${type}`, identifier: identifier };
|
|
67
48
|
}
|
|
68
49
|
// Check for URL (must be a valid URL, normalized, no fragment)
|
|
69
50
|
// URLs don't have a prefix, so we check if it's a valid URL after checking all prefixes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
export declare const GIT_GRASP_LIST_KIND = 10317;
|
|
3
|
+
export declare const GitGraspServersSymbol: unique symbol;
|
|
4
|
+
export type GitGraspListEvent = KnownEvent<typeof GIT_GRASP_LIST_KIND>;
|
|
5
|
+
/** Checks if an event is a NIP-34 user grasp server list. */
|
|
6
|
+
export declare function isValidGitGraspList(event?: NostrEvent): event is GitGraspListEvent;
|
|
7
|
+
/** Returns grasp service websocket URLs in preference order. */
|
|
8
|
+
export declare function getGitGraspServers(event?: NostrEvent): string[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
|
|
2
|
+
import { relaySet } from "applesauce-core/helpers/relays";
|
|
3
|
+
import { processTags } from "applesauce-core/helpers/tags";
|
|
4
|
+
export const GIT_GRASP_LIST_KIND = 10317;
|
|
5
|
+
export const GitGraspServersSymbol = Symbol.for("git-grasp-servers");
|
|
6
|
+
/** Checks if an event is a NIP-34 user grasp server list. */
|
|
7
|
+
export function isValidGitGraspList(event) {
|
|
8
|
+
return !!event && event.kind === GIT_GRASP_LIST_KIND;
|
|
9
|
+
}
|
|
10
|
+
/** Returns grasp service websocket URLs in preference order. */
|
|
11
|
+
export function getGitGraspServers(event) {
|
|
12
|
+
if (!isValidGitGraspList(event))
|
|
13
|
+
return [];
|
|
14
|
+
return getOrComputeCachedValue(event, GitGraspServersSymbol, () => relaySet(processTags(event.tags, (tag) => (tag[0] === "g" ? tag[1] : undefined))));
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { ProfilePointer } from "applesauce-core/helpers/pointers";
|
|
3
|
+
import { GitRepositoryPointer } from "./git-repository.js";
|
|
4
|
+
import { ReadListTags } from "./lists.js";
|
|
5
|
+
/** NIP-51 git authors list kind */
|
|
6
|
+
export declare const GIT_AUTHORS_KIND = 10017;
|
|
7
|
+
/** NIP-51 git repositories list kind */
|
|
8
|
+
export declare const FAVORITE_GIT_REPOS_KIND = 10018;
|
|
9
|
+
/** NIP-34 repository announcement event kind */
|
|
10
|
+
export declare const REPOSITORY_ANNOUNCEMENT_KIND = 30617;
|
|
11
|
+
export type GitAuthorsListEvent = KnownEvent<typeof GIT_AUTHORS_KIND>;
|
|
12
|
+
export type FavoriteGitReposListEvent = KnownEvent<typeof FAVORITE_GIT_REPOS_KIND>;
|
|
13
|
+
/** Validates that an event is a NIP-51 git authors list */
|
|
14
|
+
export declare function isValidGitAuthorsList(event: NostrEvent): event is GitAuthorsListEvent;
|
|
15
|
+
/** Validates that an event is a NIP-51 git repositories list */
|
|
16
|
+
export declare function isValidFavoriteGitReposList(event: NostrEvent): event is FavoriteGitReposListEvent;
|
|
17
|
+
/** Returns git author profile pointers from a git authors list */
|
|
18
|
+
export declare function getGitAuthors(list: NostrEvent, type?: ReadListTags): ProfilePointer[];
|
|
19
|
+
/** Returns NIP-34 repository pointers from a git repositories list */
|
|
20
|
+
export declare function getFavoriteGitReposPointers(list: NostrEvent, type?: ReadListTags): GitRepositoryPointer[];
|