applesauce-common 6.2.0 → 7.1.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/README.md +1 -0
- package/dist/casts/_circular-import.d.ts +3 -0
- package/dist/casts/_circular-import.js +3 -0
- package/dist/casts/app-handler.d.ts +56 -0
- package/dist/casts/app-handler.js +105 -0
- package/dist/casts/app-recommendation.d.ts +26 -0
- package/dist/casts/app-recommendation.js +41 -0
- package/dist/casts/external-identities.d.ts +9 -0
- package/dist/casts/external-identities.js +14 -0
- package/dist/casts/forum-thread.d.ts +17 -0
- package/dist/casts/forum-thread.js +31 -0
- package/dist/casts/git-issue.d.ts +18 -0
- package/dist/casts/git-issue.js +26 -0
- package/dist/casts/git-patch.d.ts +49 -0
- package/dist/casts/git-patch.js +88 -0
- package/dist/casts/git-pull-request.d.ts +67 -0
- package/dist/casts/git-pull-request.js +122 -0
- package/dist/casts/git-repository.d.ts +9 -0
- package/dist/casts/git-repository.js +16 -0
- package/dist/casts/git-thread.d.ts +33 -0
- package/dist/casts/git-thread.js +65 -0
- package/dist/casts/index.d.ts +12 -0
- package/dist/casts/index.js +12 -0
- package/dist/casts/napplet-handlers.d.ts +39 -0
- package/dist/casts/napplet-handlers.js +91 -0
- package/dist/casts/napplet.d.ts +98 -0
- package/dist/casts/napplet.js +196 -0
- package/dist/casts/note.d.ts +8 -0
- package/dist/casts/note.js +21 -1
- package/dist/casts/nsite.d.ts +134 -0
- package/dist/casts/nsite.js +249 -0
- package/dist/casts/profile.d.ts +20 -0
- package/dist/casts/profile.js +30 -0
- package/dist/casts/reaction.d.ts +1 -1
- package/dist/casts/relay-discovery.d.ts +4 -0
- package/dist/casts/relay-discovery.js +9 -1
- package/dist/casts/report.d.ts +28 -15
- package/dist/casts/report.js +42 -19
- package/dist/casts/share.d.ts +1 -1
- package/dist/casts/torrent.d.ts +5 -0
- package/dist/casts/torrent.js +8 -1
- package/dist/casts/trusted-assertions.d.ts +2 -0
- package/dist/casts/trusted-assertions.js +19 -18
- package/dist/casts/user-status.d.ts +33 -0
- package/dist/casts/user-status.js +69 -0
- package/dist/casts/user.d.ts +7 -0
- package/dist/casts/user.js +20 -1
- package/dist/factories/app-handler.d.ts +31 -0
- package/dist/factories/app-handler.js +50 -0
- package/dist/factories/app-recommendation.d.ts +21 -0
- package/dist/factories/app-recommendation.js +28 -0
- package/dist/factories/chat-message.d.ts +37 -0
- package/dist/factories/chat-message.js +56 -0
- package/dist/factories/comment.d.ts +8 -7
- package/dist/factories/comment.js +2 -2
- package/dist/factories/external-identities.d.ts +17 -0
- package/dist/factories/external-identities.js +28 -0
- package/dist/factories/file-message.d.ts +24 -0
- package/dist/factories/file-message.js +37 -0
- package/dist/factories/forum-thread.d.ts +34 -0
- package/dist/factories/forum-thread.js +50 -0
- package/dist/factories/git-applied-status.d.ts +39 -0
- package/dist/factories/git-applied-status.js +53 -0
- package/dist/factories/git-closed-status.d.ts +18 -0
- package/dist/factories/git-closed-status.js +24 -0
- package/dist/factories/git-draft-status.d.ts +18 -0
- package/dist/factories/git-draft-status.js +24 -0
- package/dist/factories/git-issue.d.ts +19 -0
- package/dist/factories/git-issue.js +25 -0
- package/dist/factories/git-open-status.d.ts +18 -0
- package/dist/factories/git-open-status.js +22 -0
- package/dist/factories/git-patch.d.ts +59 -0
- package/dist/factories/git-patch.js +102 -0
- package/dist/factories/git-pull-request-update.d.ts +23 -0
- package/dist/factories/git-pull-request-update.js +33 -0
- package/dist/factories/git-pull-request.d.ts +39 -0
- package/dist/factories/git-pull-request.js +64 -0
- package/dist/factories/index.d.ts +24 -0
- package/dist/factories/index.js +24 -0
- package/dist/factories/internal/git-pull-request.d.ts +19 -0
- package/dist/factories/internal/git-pull-request.js +26 -0
- package/dist/factories/internal/git-status.d.ts +11 -0
- package/dist/factories/internal/git-status.js +12 -0
- package/dist/factories/internal/git-thread.d.ts +19 -0
- package/dist/factories/internal/git-thread.js +29 -0
- package/dist/factories/internal/napplet-manifest.d.ts +52 -0
- package/dist/factories/internal/napplet-manifest.js +85 -0
- package/dist/factories/internal/nsite-manifest.d.ts +45 -0
- package/dist/factories/internal/nsite-manifest.js +68 -0
- package/dist/factories/legacy-message.d.ts +2 -0
- package/dist/factories/legacy-message.js +9 -2
- package/dist/factories/named-napplet.d.ts +20 -0
- package/dist/factories/named-napplet.js +30 -0
- package/dist/factories/named-nsite.d.ts +28 -0
- package/dist/factories/named-nsite.js +53 -0
- package/dist/factories/napplet-handlers.d.ts +34 -0
- package/dist/factories/napplet-handlers.js +77 -0
- package/dist/factories/napplet-snapshot.d.ts +18 -0
- package/dist/factories/napplet-snapshot.js +38 -0
- package/dist/factories/nsite-snapshot.d.ts +18 -0
- package/dist/factories/nsite-snapshot.js +29 -0
- package/dist/factories/reaction.d.ts +3 -2
- package/dist/factories/report.d.ts +48 -0
- package/dist/factories/report.js +66 -0
- package/dist/factories/root-napplet.d.ts +18 -0
- package/dist/factories/root-napplet.js +24 -0
- package/dist/factories/root-nsite.d.ts +23 -0
- package/dist/factories/root-nsite.js +44 -0
- package/dist/factories/torrent.d.ts +24 -10
- package/dist/factories/torrent.js +48 -44
- package/dist/factories/trusted-provider-list.d.ts +23 -0
- package/dist/factories/trusted-provider-list.js +39 -0
- package/dist/factories/user-status.d.ts +26 -0
- package/dist/factories/user-status.js +52 -0
- package/dist/factories/wrapped-message.js +10 -4
- package/dist/helpers/app-data.js +15 -7
- package/dist/helpers/app-handler.d.ts +43 -6
- package/dist/helpers/app-handler.js +53 -3
- package/dist/helpers/app-recommendation.d.ts +24 -0
- package/dist/helpers/app-recommendation.js +30 -0
- package/dist/helpers/bookmark.js +5 -2
- package/dist/helpers/comment.d.ts +11 -5
- package/dist/helpers/comment.js +7 -1
- package/dist/helpers/content.d.ts +3 -1
- package/dist/helpers/emoji-pack.js +11 -6
- package/dist/helpers/emoji.d.ts +2 -2
- package/dist/helpers/encrypted-content-cache.d.ts +2 -11
- package/dist/helpers/encrypted-content-cache.js +6 -14
- package/dist/helpers/encrypted-file.d.ts +41 -0
- package/dist/helpers/encrypted-file.js +64 -0
- package/dist/helpers/external-id.js +13 -19
- package/dist/helpers/external-identities.d.ts +29 -0
- package/dist/helpers/external-identities.js +52 -0
- package/dist/helpers/file-message.d.ts +18 -0
- package/dist/helpers/file-message.js +44 -0
- package/dist/helpers/file-metadata.d.ts +9 -4
- package/dist/helpers/file-metadata.js +21 -6
- package/dist/helpers/forum-thread.d.ts +10 -0
- package/dist/helpers/forum-thread.js +10 -0
- package/dist/helpers/gift-wrap.d.ts +40 -15
- package/dist/helpers/gift-wrap.js +110 -33
- package/dist/helpers/git-issue.d.ts +13 -0
- package/dist/helpers/git-issue.js +19 -0
- package/dist/helpers/git-patch.d.ts +41 -0
- package/dist/helpers/git-patch.js +73 -0
- package/dist/helpers/git-pull-request.d.ts +57 -0
- package/dist/helpers/git-pull-request.js +111 -0
- package/dist/helpers/git-repository.d.ts +4 -0
- package/dist/helpers/git-repository.js +16 -0
- package/dist/helpers/git-status.d.ts +44 -0
- package/dist/helpers/git-status.js +93 -0
- package/dist/helpers/git.d.ts +2 -0
- package/dist/helpers/git.js +4 -0
- package/dist/helpers/groups.d.ts +5 -2
- package/dist/helpers/groups.js +40 -18
- package/dist/helpers/hashtag.d.ts +4 -2
- package/dist/helpers/index.d.ts +13 -0
- package/dist/helpers/index.js +13 -0
- package/dist/helpers/lists.js +14 -2
- package/dist/helpers/lnurl.js +1 -1
- package/dist/helpers/messages.js +3 -2
- package/dist/helpers/mute.js +20 -9
- package/dist/helpers/napplet-handlers.d.ts +79 -0
- package/dist/helpers/napplet-handlers.js +187 -0
- package/dist/helpers/napplet.d.ts +107 -0
- package/dist/helpers/napplet.js +177 -0
- package/dist/helpers/nsite.d.ts +90 -0
- package/dist/helpers/nsite.js +217 -0
- package/dist/helpers/relay-discovery.d.ts +4 -0
- package/dist/helpers/relay-discovery.js +8 -0
- package/dist/helpers/reports.d.ts +35 -0
- package/dist/helpers/reports.js +36 -5
- package/dist/helpers/threading.d.ts +4 -2
- package/dist/helpers/torrent.d.ts +9 -6
- package/dist/helpers/torrent.js +23 -15
- package/dist/helpers/trusted-assertions.d.ts +7 -0
- package/dist/helpers/trusted-assertions.js +41 -2
- package/dist/helpers/user-status.d.ts +13 -1
- package/dist/helpers/user-status.js +15 -0
- package/dist/helpers/wrapped-messages.d.ts +2 -0
- package/dist/helpers/wrapped-messages.js +6 -1
- package/dist/models/app-handler.d.ts +21 -0
- package/dist/models/app-handler.js +47 -0
- package/dist/models/git.d.ts +34 -0
- package/dist/models/git.js +144 -0
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +4 -0
- package/dist/models/legacy-messages.js +6 -1
- package/dist/models/napplet-handlers.d.ts +16 -0
- package/dist/models/napplet-handlers.js +45 -0
- package/dist/models/nsite.d.ts +22 -0
- package/dist/models/nsite.js +67 -0
- package/dist/models/thread.d.ts +4 -1
- package/dist/models/thread.js +34 -5
- package/dist/models/user-status.d.ts +8 -4
- package/dist/models/user-status.js +16 -22
- package/dist/models/wrapped-messages.js +9 -7
- package/dist/observable/filter-timeline-by-mutes.d.ts +1 -1
- package/dist/observable/filter-timeline-by-mutes.js +6 -2
- package/dist/operations/app-handler.d.ts +24 -0
- package/dist/operations/app-handler.js +58 -0
- package/dist/operations/app-recommendation.d.ts +13 -0
- package/dist/operations/app-recommendation.js +40 -0
- package/dist/operations/calendar-event.js +3 -2
- package/dist/operations/chat-message.d.ts +9 -0
- package/dist/operations/chat-message.js +12 -0
- package/dist/operations/client.d.ts +1 -4
- package/dist/operations/client.js +1 -23
- package/dist/operations/comment.d.ts +9 -3
- package/dist/operations/comment.js +12 -9
- package/dist/operations/external-identities.d.ts +8 -0
- package/dist/operations/external-identities.js +23 -0
- package/dist/operations/file-message.d.ts +7 -0
- package/dist/operations/file-message.js +34 -0
- package/dist/operations/forum-thread.d.ts +3 -0
- package/dist/operations/forum-thread.js +6 -0
- package/dist/operations/gift-wrap.js +38 -14
- package/dist/operations/git-issue.d.ts +18 -0
- package/dist/operations/git-issue.js +31 -0
- package/dist/operations/git-patch.d.ts +30 -0
- package/dist/operations/git-patch.js +75 -0
- package/dist/operations/git-pull-request.d.ts +29 -0
- package/dist/operations/git-pull-request.js +74 -0
- package/dist/operations/git-repository.js +4 -4
- package/dist/operations/git-status.d.ts +28 -0
- package/dist/operations/git-status.js +116 -0
- package/dist/operations/git-thread.d.ts +13 -0
- package/dist/operations/git-thread.js +39 -0
- package/dist/operations/index.d.ts +17 -0
- package/dist/operations/index.js +17 -0
- package/dist/operations/internal/git-commits.d.ts +2 -0
- package/dist/operations/internal/git-commits.js +16 -0
- package/dist/operations/napplet-handlers.d.ts +47 -0
- package/dist/operations/napplet-handlers.js +161 -0
- package/dist/operations/napplet.d.ts +51 -0
- package/dist/operations/napplet.js +121 -0
- package/dist/operations/nsite.d.ts +51 -0
- package/dist/operations/nsite.js +112 -0
- package/dist/operations/reaction.d.ts +12 -2
- package/dist/operations/reaction.js +1 -1
- package/dist/operations/report.d.ts +33 -0
- package/dist/operations/report.js +60 -0
- package/dist/operations/stream.js +5 -4
- package/dist/operations/torrent.d.ts +1 -4
- package/dist/operations/torrent.js +24 -11
- package/dist/operations/trusted-providers.d.ts +14 -0
- package/dist/operations/trusted-providers.js +33 -0
- package/dist/operations/user-status.d.ts +11 -0
- package/dist/operations/user-status.js +29 -0
- package/dist/operations/wrapped-message.js +2 -2
- package/package.json +13 -17
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
3
|
+
import { GitStatusKind } from "../../helpers/git-status.js";
|
|
4
|
+
/** A shared implementation of status target operations */
|
|
5
|
+
export declare class GitStatusTargetFactory<K extends GitStatusKind> extends EventFactory<K> {
|
|
6
|
+
/**
|
|
7
|
+
* Sets the original issue, pull request or root patch
|
|
8
|
+
* @throws if the event is not a supported original root
|
|
9
|
+
*/
|
|
10
|
+
root(root: NostrEvent, relay?: string): this;
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { setGitStatusRoot } from "../../operations/git-status.js";
|
|
3
|
+
/** A shared implementation of status target operations */
|
|
4
|
+
export class GitStatusTargetFactory extends EventFactory {
|
|
5
|
+
/**
|
|
6
|
+
* Sets the original issue, pull request or root patch
|
|
7
|
+
* @throws if the event is not a supported original root
|
|
8
|
+
*/
|
|
9
|
+
root(root, relay) {
|
|
10
|
+
return this.chain(setGitStatusRoot(root, relay));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
3
|
+
import { GitRepositoryPointer } from "../../helpers/git-repository.js";
|
|
4
|
+
/** A shared implementation of repository thread operations */
|
|
5
|
+
export declare class GitThreadFactory<K extends 1617 | 1618 | 1621> extends EventFactory<K> {
|
|
6
|
+
/**
|
|
7
|
+
* Sets the repository for this thread
|
|
8
|
+
* @throws if the event or pointer is not a valid repository
|
|
9
|
+
*/
|
|
10
|
+
repository(repo: GitRepositoryPointer | NostrEvent): this;
|
|
11
|
+
/** Sets or removes the subject */
|
|
12
|
+
subject(subject: string | null): this;
|
|
13
|
+
/** Replaces all labels */
|
|
14
|
+
labels(labels: string[]): this;
|
|
15
|
+
/** Adds a label */
|
|
16
|
+
addLabel(label: string): this;
|
|
17
|
+
/** Removes a label */
|
|
18
|
+
removeLabel(label: string): this;
|
|
19
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { setGitThreadRepository } from "../../operations/git-thread.js";
|
|
3
|
+
import { addGitIssueLabel, removeGitIssueLabel, setGitIssueLabels, setGitIssueSubject, } from "../../operations/git-issue.js";
|
|
4
|
+
/** A shared implementation of repository thread operations */
|
|
5
|
+
export class GitThreadFactory extends EventFactory {
|
|
6
|
+
/**
|
|
7
|
+
* Sets the repository for this thread
|
|
8
|
+
* @throws if the event or pointer is not a valid repository
|
|
9
|
+
*/
|
|
10
|
+
repository(repo) {
|
|
11
|
+
return this.chain(setGitThreadRepository(repo));
|
|
12
|
+
}
|
|
13
|
+
/** Sets or removes the subject */
|
|
14
|
+
subject(subject) {
|
|
15
|
+
return this.chain(setGitIssueSubject(subject));
|
|
16
|
+
}
|
|
17
|
+
/** Replaces all labels */
|
|
18
|
+
labels(labels) {
|
|
19
|
+
return this.chain(setGitIssueLabels(labels));
|
|
20
|
+
}
|
|
21
|
+
/** Adds a label */
|
|
22
|
+
addLabel(label) {
|
|
23
|
+
return this.chain(addGitIssueLabel(label));
|
|
24
|
+
}
|
|
25
|
+
/** Removes a label */
|
|
26
|
+
removeLabel(label) {
|
|
27
|
+
return this.chain(removeGitIssueLabel(label));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { AddressPointer } from "applesauce-core/helpers/pointers";
|
|
3
|
+
import { NappletKind, NappletIconType } from "../../helpers/napplet.js";
|
|
4
|
+
/** A shared implementation of napplet manifest operations */
|
|
5
|
+
export declare class NappletManifestFactory<K extends NappletKind> extends EventFactory<K> {
|
|
6
|
+
/**
|
|
7
|
+
* Sets the sha256 of the `index.html` artifact
|
|
8
|
+
* @throws if the hash is not a lowercase hex sha256
|
|
9
|
+
*/
|
|
10
|
+
artifact(sha256: string): this;
|
|
11
|
+
/** Sets the plain-text description */
|
|
12
|
+
description(value: string): this;
|
|
13
|
+
/** Sets or removes the display title */
|
|
14
|
+
title(value: string | null): this;
|
|
15
|
+
/** Sets or removes the source URL */
|
|
16
|
+
source(url: string | null): this;
|
|
17
|
+
/** Adds an archetype */
|
|
18
|
+
archetype(archetype: string): this;
|
|
19
|
+
/** Removes an archetype */
|
|
20
|
+
removeArchetype(archetype: string): this;
|
|
21
|
+
/** Adds or replaces an accepted intent and its parameter names */
|
|
22
|
+
intent(intent: string, params?: string[]): this;
|
|
23
|
+
/** Removes an accepted intent */
|
|
24
|
+
removeIntent(intent: string): this;
|
|
25
|
+
/** Adds a required NAP domain */
|
|
26
|
+
requires(domain: string): this;
|
|
27
|
+
/** Removes a required NAP domain */
|
|
28
|
+
removeRequires(domain: string): this;
|
|
29
|
+
/** Adds an optional NAP domain */
|
|
30
|
+
optional(domain: string): this;
|
|
31
|
+
/** Removes an optional NAP domain */
|
|
32
|
+
removeOptional(domain: string): this;
|
|
33
|
+
/** Adds a Blossom server hint */
|
|
34
|
+
server(url: string): this;
|
|
35
|
+
/** Removes a Blossom server hint */
|
|
36
|
+
removeServer(url: string): this;
|
|
37
|
+
/**
|
|
38
|
+
* Sets or removes the icon
|
|
39
|
+
* @throws if the hash or MIME type is invalid
|
|
40
|
+
*/
|
|
41
|
+
icon(sha256: string | null, type?: NappletIconType): this;
|
|
42
|
+
/**
|
|
43
|
+
* Sets or removes the address of the napplet a snapshot derives from
|
|
44
|
+
* @throws if the address cannot be parsed
|
|
45
|
+
*/
|
|
46
|
+
parent(parent: AddressPointer | string | null): this;
|
|
47
|
+
/**
|
|
48
|
+
* Sets or removes the address of the root napplet a snapshot's lineage originates from
|
|
49
|
+
* @throws if the address cannot be parsed
|
|
50
|
+
*/
|
|
51
|
+
root(root: AddressPointer | string | null): this;
|
|
52
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { addNappletArchetype, addNappletIntent, addNappletOptionalDomain, addNappletRequiredDomain, addNappletServer, removeNappletArchetype, removeNappletIntent, removeNappletOptionalDomain, removeNappletRequiredDomain, removeNappletServer, setNappletArtifactHash, setNappletDescription, setNappletIcon, setNappletParent, setNappletRoot, setNappletSource, setNappletTitle, } from "../../operations/napplet.js";
|
|
3
|
+
/** A shared implementation of napplet manifest operations */
|
|
4
|
+
export class NappletManifestFactory extends EventFactory {
|
|
5
|
+
/**
|
|
6
|
+
* Sets the sha256 of the `index.html` artifact
|
|
7
|
+
* @throws if the hash is not a lowercase hex sha256
|
|
8
|
+
*/
|
|
9
|
+
artifact(sha256) {
|
|
10
|
+
return this.chain(setNappletArtifactHash(sha256));
|
|
11
|
+
}
|
|
12
|
+
/** Sets the plain-text description */
|
|
13
|
+
description(value) {
|
|
14
|
+
return this.chain(setNappletDescription(value));
|
|
15
|
+
}
|
|
16
|
+
/** Sets or removes the display title */
|
|
17
|
+
title(value) {
|
|
18
|
+
return this.chain(setNappletTitle(value));
|
|
19
|
+
}
|
|
20
|
+
/** Sets or removes the source URL */
|
|
21
|
+
source(url) {
|
|
22
|
+
return this.chain(setNappletSource(url));
|
|
23
|
+
}
|
|
24
|
+
/** Adds an archetype */
|
|
25
|
+
archetype(archetype) {
|
|
26
|
+
return this.chain(addNappletArchetype(archetype));
|
|
27
|
+
}
|
|
28
|
+
/** Removes an archetype */
|
|
29
|
+
removeArchetype(archetype) {
|
|
30
|
+
return this.chain(removeNappletArchetype(archetype));
|
|
31
|
+
}
|
|
32
|
+
/** Adds or replaces an accepted intent and its parameter names */
|
|
33
|
+
intent(intent, params) {
|
|
34
|
+
return this.chain(addNappletIntent(intent, params));
|
|
35
|
+
}
|
|
36
|
+
/** Removes an accepted intent */
|
|
37
|
+
removeIntent(intent) {
|
|
38
|
+
return this.chain(removeNappletIntent(intent));
|
|
39
|
+
}
|
|
40
|
+
/** Adds a required NAP domain */
|
|
41
|
+
requires(domain) {
|
|
42
|
+
return this.chain(addNappletRequiredDomain(domain));
|
|
43
|
+
}
|
|
44
|
+
/** Removes a required NAP domain */
|
|
45
|
+
removeRequires(domain) {
|
|
46
|
+
return this.chain(removeNappletRequiredDomain(domain));
|
|
47
|
+
}
|
|
48
|
+
/** Adds an optional NAP domain */
|
|
49
|
+
optional(domain) {
|
|
50
|
+
return this.chain(addNappletOptionalDomain(domain));
|
|
51
|
+
}
|
|
52
|
+
/** Removes an optional NAP domain */
|
|
53
|
+
removeOptional(domain) {
|
|
54
|
+
return this.chain(removeNappletOptionalDomain(domain));
|
|
55
|
+
}
|
|
56
|
+
/** Adds a Blossom server hint */
|
|
57
|
+
server(url) {
|
|
58
|
+
return this.chain(addNappletServer(url));
|
|
59
|
+
}
|
|
60
|
+
/** Removes a Blossom server hint */
|
|
61
|
+
removeServer(url) {
|
|
62
|
+
return this.chain(removeNappletServer(url));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Sets or removes the icon
|
|
66
|
+
* @throws if the hash or MIME type is invalid
|
|
67
|
+
*/
|
|
68
|
+
icon(sha256, type) {
|
|
69
|
+
return this.chain(setNappletIcon(sha256, type));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Sets or removes the address of the napplet a snapshot derives from
|
|
73
|
+
* @throws if the address cannot be parsed
|
|
74
|
+
*/
|
|
75
|
+
parent(parent) {
|
|
76
|
+
return this.chain(setNappletParent(parent));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Sets or removes the address of the root napplet a snapshot's lineage originates from
|
|
80
|
+
* @throws if the address cannot be parsed
|
|
81
|
+
*/
|
|
82
|
+
root(root) {
|
|
83
|
+
return this.chain(setNappletRoot(root));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { AddressPointer } from "applesauce-core/helpers/pointers";
|
|
3
|
+
import { NsiteKind } from "../../helpers/nsite.js";
|
|
4
|
+
/** A shared implementation of nsite manifest operations */
|
|
5
|
+
export declare class NsiteManifestFactory<K extends NsiteKind> extends EventFactory<K> {
|
|
6
|
+
/**
|
|
7
|
+
* Adds or replaces a file mapping and refreshes the aggregate hash
|
|
8
|
+
* @throws if the path or hash is invalid
|
|
9
|
+
*/
|
|
10
|
+
file(path: string, hash: string): this;
|
|
11
|
+
/** Removes a file mapping and refreshes the aggregate hash */
|
|
12
|
+
removeFile(path: string): this;
|
|
13
|
+
/** Updates the aggregate hash from the current manifest */
|
|
14
|
+
aggregate(): this;
|
|
15
|
+
/** Sets or removes the site's title */
|
|
16
|
+
title(value: string | null): this;
|
|
17
|
+
/** Sets or removes the site's description */
|
|
18
|
+
description(value: string | null): this;
|
|
19
|
+
/** Sets or removes the site's source URL */
|
|
20
|
+
source(value: string | null): this;
|
|
21
|
+
/** Adds a Blossom server hint */
|
|
22
|
+
server(url: string): this;
|
|
23
|
+
/** Removes a Blossom server hint */
|
|
24
|
+
removeServer(url: string): this;
|
|
25
|
+
/**
|
|
26
|
+
* Adds or replaces an upstream app descriptor reference
|
|
27
|
+
* @throws if the address is not addressable
|
|
28
|
+
*/
|
|
29
|
+
app(pointer: AddressPointer | string): this;
|
|
30
|
+
/**
|
|
31
|
+
* Removes an upstream app descriptor reference
|
|
32
|
+
* @throws if the address is not addressable
|
|
33
|
+
*/
|
|
34
|
+
removeApp(pointer: AddressPointer | string): this;
|
|
35
|
+
/**
|
|
36
|
+
* Sets or removes the immediate parent site
|
|
37
|
+
* @throws if the address does not reference a root or named site
|
|
38
|
+
*/
|
|
39
|
+
parent(pointer: AddressPointer | string | null): this;
|
|
40
|
+
/**
|
|
41
|
+
* Sets or removes the origin site of the copy lineage
|
|
42
|
+
* @throws if the address does not reference a root or named site
|
|
43
|
+
*/
|
|
44
|
+
root(pointer: AddressPointer | string | null): this;
|
|
45
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { addNsiteApp, addNsiteServer, removeNsiteApp, removeNsiteFile, removeNsiteServer, setNsiteDescription, setNsiteFile, setNsiteParent, setNsiteRoot, setNsiteSource, setNsiteTitle, updateNsiteAggregateHash, } from "../../operations/nsite.js";
|
|
3
|
+
/** A shared implementation of nsite manifest operations */
|
|
4
|
+
export class NsiteManifestFactory extends EventFactory {
|
|
5
|
+
/**
|
|
6
|
+
* Adds or replaces a file mapping and refreshes the aggregate hash
|
|
7
|
+
* @throws if the path or hash is invalid
|
|
8
|
+
*/
|
|
9
|
+
file(path, hash) {
|
|
10
|
+
return this.chain(setNsiteFile(path, hash));
|
|
11
|
+
}
|
|
12
|
+
/** Removes a file mapping and refreshes the aggregate hash */
|
|
13
|
+
removeFile(path) {
|
|
14
|
+
return this.chain(removeNsiteFile(path));
|
|
15
|
+
}
|
|
16
|
+
/** Updates the aggregate hash from the current manifest */
|
|
17
|
+
aggregate() {
|
|
18
|
+
return this.chain(updateNsiteAggregateHash());
|
|
19
|
+
}
|
|
20
|
+
/** Sets or removes the site's title */
|
|
21
|
+
title(value) {
|
|
22
|
+
return this.chain(setNsiteTitle(value));
|
|
23
|
+
}
|
|
24
|
+
/** Sets or removes the site's description */
|
|
25
|
+
description(value) {
|
|
26
|
+
return this.chain(setNsiteDescription(value));
|
|
27
|
+
}
|
|
28
|
+
/** Sets or removes the site's source URL */
|
|
29
|
+
source(value) {
|
|
30
|
+
return this.chain(setNsiteSource(value));
|
|
31
|
+
}
|
|
32
|
+
/** Adds a Blossom server hint */
|
|
33
|
+
server(url) {
|
|
34
|
+
return this.chain(addNsiteServer(url));
|
|
35
|
+
}
|
|
36
|
+
/** Removes a Blossom server hint */
|
|
37
|
+
removeServer(url) {
|
|
38
|
+
return this.chain(removeNsiteServer(url));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Adds or replaces an upstream app descriptor reference
|
|
42
|
+
* @throws if the address is not addressable
|
|
43
|
+
*/
|
|
44
|
+
app(pointer) {
|
|
45
|
+
return this.chain(addNsiteApp(pointer));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Removes an upstream app descriptor reference
|
|
49
|
+
* @throws if the address is not addressable
|
|
50
|
+
*/
|
|
51
|
+
removeApp(pointer) {
|
|
52
|
+
return this.chain(removeNsiteApp(pointer));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Sets or removes the immediate parent site
|
|
56
|
+
* @throws if the address does not reference a root or named site
|
|
57
|
+
*/
|
|
58
|
+
parent(pointer) {
|
|
59
|
+
return this.chain(setNsiteParent(pointer));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Sets or removes the origin site of the copy lineage
|
|
63
|
+
* @throws if the address does not reference a root or named site
|
|
64
|
+
*/
|
|
65
|
+
root(pointer) {
|
|
66
|
+
return this.chain(setNsiteRoot(pointer));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -4,6 +4,8 @@ export type LegacyMessageTemplate = KnownEventTemplate<kinds.EncryptedDirectMess
|
|
|
4
4
|
export declare class LegacyMessageFactory extends EventFactory<kinds.EncryptedDirectMessage, LegacyMessageTemplate> {
|
|
5
5
|
static create(recipient: string, message: string): LegacyMessageFactory;
|
|
6
6
|
static reply(parent: NostrEvent, recipient: string, message: string): LegacyMessageFactory;
|
|
7
|
+
/** Sets the "p" tag of the user the message is addressed to */
|
|
8
|
+
recipient(pubkey: string): this;
|
|
7
9
|
/** Sets the parent message "e" tag for NIP-04 reply threading */
|
|
8
10
|
replyTo(parent: NostrEvent | string): this;
|
|
9
11
|
}
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
|
|
2
2
|
import { kinds } from "applesauce-core/helpers";
|
|
3
|
-
import { setMessageParent } from "../operations/legacy-message.js";
|
|
3
|
+
import { setMessageAddress, setMessageParent } from "../operations/legacy-message.js";
|
|
4
4
|
export class LegacyMessageFactory extends EventFactory {
|
|
5
5
|
static create(recipient, message) {
|
|
6
|
-
return new LegacyMessageFactory((res) => res(blankEventTemplate(kinds.EncryptedDirectMessage)))
|
|
6
|
+
return new LegacyMessageFactory((res) => res(blankEventTemplate(kinds.EncryptedDirectMessage)))
|
|
7
|
+
.recipient(recipient)
|
|
8
|
+
.encryptedContent(recipient, message, "nip04");
|
|
7
9
|
}
|
|
8
10
|
static reply(parent, recipient, message) {
|
|
9
11
|
if (parent.kind !== kinds.EncryptedDirectMessage)
|
|
10
12
|
throw new Error("Parent must be a legacy message (kind 4)");
|
|
11
13
|
return new LegacyMessageFactory((res) => res(blankEventTemplate(kinds.EncryptedDirectMessage)))
|
|
14
|
+
.recipient(recipient)
|
|
12
15
|
.encryptedContent(recipient, message, "nip04")
|
|
13
16
|
.replyTo(parent);
|
|
14
17
|
}
|
|
18
|
+
/** Sets the "p" tag of the user the message is addressed to */
|
|
19
|
+
recipient(pubkey) {
|
|
20
|
+
return this.chain(setMessageAddress(pubkey));
|
|
21
|
+
}
|
|
15
22
|
/** Sets the parent message "e" tag for NIP-04 reply threading */
|
|
16
23
|
replyTo(parent) {
|
|
17
24
|
return this.chain(setMessageParent(parent));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { NAPPLET_KIND } from "../helpers/napplet.js";
|
|
3
|
+
import { NappletManifestFactory } from "./internal/napplet-manifest.js";
|
|
4
|
+
/** An event template for a named napplet manifest */
|
|
5
|
+
export type NamedNappletTemplate = KnownEventTemplate<typeof NAPPLET_KIND>;
|
|
6
|
+
/** A factory for named napplet manifests (kind 35129) */
|
|
7
|
+
export declare class NamedNappletFactory extends NappletManifestFactory<typeof NAPPLET_KIND> {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a named napplet manifest
|
|
10
|
+
* @throws if the artifact hash is invalid
|
|
11
|
+
*/
|
|
12
|
+
static create(identifier: string, artifactHash: string, description: string): NamedNappletFactory;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a factory for modifying a named napplet manifest
|
|
15
|
+
* @throws if the event is not a valid named napplet manifest
|
|
16
|
+
*/
|
|
17
|
+
static modify(event: NostrEvent): NamedNappletFactory;
|
|
18
|
+
/** Sets the named napplet's identifier */
|
|
19
|
+
identifier(value: string): this;
|
|
20
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { isValidNamedNapplet, NAPPLET_KIND } from "../helpers/napplet.js";
|
|
3
|
+
import { NappletManifestFactory } from "./internal/napplet-manifest.js";
|
|
4
|
+
import { setNappletIdentifier } from "../operations/napplet.js";
|
|
5
|
+
/** A factory for named napplet manifests (kind 35129) */
|
|
6
|
+
export class NamedNappletFactory extends NappletManifestFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a named napplet manifest
|
|
9
|
+
* @throws if the artifact hash is invalid
|
|
10
|
+
*/
|
|
11
|
+
static create(identifier, artifactHash, description) {
|
|
12
|
+
return new NamedNappletFactory((res) => res(blankEventTemplate(NAPPLET_KIND)))
|
|
13
|
+
.identifier(identifier)
|
|
14
|
+
.artifact(artifactHash)
|
|
15
|
+
.description(description);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a factory for modifying a named napplet manifest
|
|
19
|
+
* @throws if the event is not a valid named napplet manifest
|
|
20
|
+
*/
|
|
21
|
+
static modify(event) {
|
|
22
|
+
if (!isValidNamedNapplet(event))
|
|
23
|
+
throw new Error("Expected a named napplet manifest");
|
|
24
|
+
return new NamedNappletFactory((res) => res(toEventTemplate(event)));
|
|
25
|
+
}
|
|
26
|
+
/** Sets the named napplet's identifier */
|
|
27
|
+
identifier(value) {
|
|
28
|
+
return this.chain(setNappletIdentifier(value));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { NSITE_KIND, NsiteFile } from "../helpers/nsite.js";
|
|
3
|
+
import { NsiteManifestFactory } from "./internal/nsite-manifest.js";
|
|
4
|
+
/** An event template for a named nsite manifest */
|
|
5
|
+
export type NamedNsiteTemplate = KnownEventTemplate<typeof NSITE_KIND>;
|
|
6
|
+
/** A factory for named nsite manifests (kind 35128) */
|
|
7
|
+
export declare class NamedNsiteFactory extends NsiteManifestFactory<typeof NSITE_KIND> {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a named nsite manifest
|
|
10
|
+
* @throws if the manifest is empty or a path, hash or identifier is invalid
|
|
11
|
+
*/
|
|
12
|
+
static create(identifier: string, files: NsiteFile[]): NamedNsiteFactory;
|
|
13
|
+
/**
|
|
14
|
+
* Copies a root or named site into a new named manifest with copy lineage
|
|
15
|
+
* @throws if the source is invalid or is a snapshot, or the identifier is invalid
|
|
16
|
+
*/
|
|
17
|
+
static copy(site: NostrEvent, identifier: string): NamedNsiteFactory;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a factory for modifying a named nsite manifest
|
|
20
|
+
* @throws if the event is not a valid named nsite manifest
|
|
21
|
+
*/
|
|
22
|
+
static modify(event: NostrEvent): NamedNsiteFactory;
|
|
23
|
+
/**
|
|
24
|
+
* Sets the named nsite's identifier
|
|
25
|
+
* @throws if the identifier is invalid
|
|
26
|
+
*/
|
|
27
|
+
identifier(value: string): this;
|
|
28
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { isValidNamedNsite, NSITE_KIND } from "../helpers/nsite.js";
|
|
3
|
+
import { NsiteManifestFactory } from "./internal/nsite-manifest.js";
|
|
4
|
+
import { setNsiteIdentifier } from "../operations/nsite.js";
|
|
5
|
+
import { getReplaceableAddressForEvent } from "applesauce-core/helpers/pointers";
|
|
6
|
+
import { unixNow } from "applesauce-core/helpers/time";
|
|
7
|
+
import { isValidNsite, isNsiteSnapshot, getNsiteRootPointer } from "../helpers/nsite.js";
|
|
8
|
+
/** A factory for named nsite manifests (kind 35128) */
|
|
9
|
+
export class NamedNsiteFactory extends NsiteManifestFactory {
|
|
10
|
+
/**
|
|
11
|
+
* Creates a named nsite manifest
|
|
12
|
+
* @throws if the manifest is empty or a path, hash or identifier is invalid
|
|
13
|
+
*/
|
|
14
|
+
static create(identifier, files) {
|
|
15
|
+
if (!files.length)
|
|
16
|
+
throw new Error("An nsite must include at least one file");
|
|
17
|
+
let factory = new NamedNsiteFactory((res) => res(blankEventTemplate(NSITE_KIND)));
|
|
18
|
+
for (const file of files)
|
|
19
|
+
factory = factory.file(file.path, file.sha256);
|
|
20
|
+
return factory.identifier(identifier);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Copies a root or named site into a new named manifest with copy lineage
|
|
24
|
+
* @throws if the source is invalid or is a snapshot, or the identifier is invalid
|
|
25
|
+
*/
|
|
26
|
+
static copy(site, identifier) {
|
|
27
|
+
if (!isValidNsite(site) || isNsiteSnapshot(site))
|
|
28
|
+
throw new Error("Expected a root or named nsite");
|
|
29
|
+
const kind = NSITE_KIND;
|
|
30
|
+
const tags = site.tags.filter((t) => t[0] !== "d" && t[0] !== "a").map((t) => [...t]);
|
|
31
|
+
let factory = new NamedNsiteFactory((res) => res({ kind, created_at: unixNow(), content: site.content, tags })).parent(getReplaceableAddressForEvent(site));
|
|
32
|
+
if (!getNsiteRootPointer(site))
|
|
33
|
+
factory = factory.root(getReplaceableAddressForEvent(site));
|
|
34
|
+
factory = factory.identifier(identifier);
|
|
35
|
+
return factory;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a factory for modifying a named nsite manifest
|
|
39
|
+
* @throws if the event is not a valid named nsite manifest
|
|
40
|
+
*/
|
|
41
|
+
static modify(event) {
|
|
42
|
+
if (!isValidNamedNsite(event))
|
|
43
|
+
throw new Error("Expected a named nsite manifest");
|
|
44
|
+
return new NamedNsiteFactory((res) => res(toEventTemplate(event)));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Sets the named nsite's identifier
|
|
48
|
+
* @throws if the identifier is invalid
|
|
49
|
+
*/
|
|
50
|
+
identifier(value) {
|
|
51
|
+
return this.chain(setNsiteIdentifier(value));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { EventFactory, TagOperation } from "applesauce-core/factories";
|
|
2
|
+
import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
|
|
3
|
+
import { NAPPLET_HANDLERS_KIND } from "../helpers/napplet-handlers.js";
|
|
4
|
+
import { NappletHandlerInput } from "../operations/napplet-handlers.js";
|
|
5
|
+
/** An event template for napplet handler preferences */
|
|
6
|
+
export type NappletHandlersTemplate = KnownEventTemplate<typeof NAPPLET_HANDLERS_KIND>;
|
|
7
|
+
/** A factory for napplet handler preferences (kind 31129) */
|
|
8
|
+
export declare class NappletHandlersFactory extends EventFactory<typeof NAPPLET_HANDLERS_KIND, NappletHandlersTemplate> {
|
|
9
|
+
/** Creates handler preferences for an archetype */
|
|
10
|
+
static create(archetype: string): NappletHandlersFactory;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a factory configured to modify existing handler preferences
|
|
13
|
+
* @throws if the event is not a valid handler preferences event
|
|
14
|
+
*/
|
|
15
|
+
static modify(event: NostrEvent): NappletHandlersFactory;
|
|
16
|
+
/** Applies a tag operation to the public or private tags */
|
|
17
|
+
protected modifyHandlerTags(operation: TagOperation, hidden: boolean): this;
|
|
18
|
+
/** Applies an intent tag operation once the archetype is known from the draft's `d` tag */
|
|
19
|
+
protected modifyIntentTags(intent: string, hidden: boolean, build: (identity: string) => TagOperation): this;
|
|
20
|
+
/** Adds an archetype-wide handler as the last fallback */
|
|
21
|
+
handler(input: NappletHandlerInput, hidden?: boolean): this;
|
|
22
|
+
/** Makes an archetype-wide handler the preferred one */
|
|
23
|
+
preferHandler(input: NappletHandlerInput, hidden?: boolean): this;
|
|
24
|
+
/** Removes an archetype-wide handler */
|
|
25
|
+
removeHandler(input: NappletHandlerInput, hidden?: boolean): this;
|
|
26
|
+
/** Adds a handler for one intent (`"edit"` or `"napplet:<archetype>/edit"`) as the last fallback */
|
|
27
|
+
intentHandler(intent: string, input: NappletHandlerInput, hidden?: boolean): this;
|
|
28
|
+
/** Makes a handler the preferred one for an intent */
|
|
29
|
+
preferIntentHandler(intent: string, input: NappletHandlerInput, hidden?: boolean): this;
|
|
30
|
+
/** Removes one handler for an intent, or every handler for it when no input is given */
|
|
31
|
+
removeIntentHandler(intent: string, input?: NappletHandlerInput, hidden?: boolean): this;
|
|
32
|
+
/** Removes every public and private entry, leaving an empty preferences event */
|
|
33
|
+
clear(): this;
|
|
34
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { blankEventTemplate, EventFactory, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { getTagValue } from "applesauce-core/helpers/event";
|
|
3
|
+
import { modifyHiddenTags, modifyPublicTags } from "applesauce-core/operations/tags";
|
|
4
|
+
import { includeSingletonTag } from "applesauce-core/operations/tags";
|
|
5
|
+
import { setContent } from "applesauce-core/operations/content";
|
|
6
|
+
import { isValidNappletHandlers, NAPPLET_HANDLERS_KIND } from "../helpers/napplet-handlers.js";
|
|
7
|
+
import { createNappletConvention, parseNappletConvention } from "../helpers/napplet.js";
|
|
8
|
+
import { addNappletHandlerTag, addNappletIntentHandlerTag, clearNappletHandlerTags, preferNappletHandlerTag, preferNappletIntentHandlerTag, removeNappletHandlerTag, removeNappletIntentHandlerTag, } from "../operations/napplet-handlers.js";
|
|
9
|
+
/**
|
|
10
|
+
* Returns the convention identity for an intent name or identity within an archetype
|
|
11
|
+
* @throws if the identity is invalid or belongs to another archetype
|
|
12
|
+
*/
|
|
13
|
+
function getConventionIdentity(archetype, intent) {
|
|
14
|
+
if (!intent.startsWith("napplet:"))
|
|
15
|
+
return createNappletConvention(archetype, intent);
|
|
16
|
+
// Shells ignore `i` tags for another archetype, so refuse to write one
|
|
17
|
+
const convention = parseNappletConvention(intent);
|
|
18
|
+
if (convention?.archetype !== archetype)
|
|
19
|
+
throw new Error(`Intent ${intent} is not for archetype ${archetype}`);
|
|
20
|
+
return intent;
|
|
21
|
+
}
|
|
22
|
+
/** A factory for napplet handler preferences (kind 31129) */
|
|
23
|
+
export class NappletHandlersFactory extends EventFactory {
|
|
24
|
+
/** Creates handler preferences for an archetype */
|
|
25
|
+
static create(archetype) {
|
|
26
|
+
return new NappletHandlersFactory((res) => res(blankEventTemplate(NAPPLET_HANDLERS_KIND))).chain(includeSingletonTag(["d", archetype], true));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates a factory configured to modify existing handler preferences
|
|
30
|
+
* @throws if the event is not a valid handler preferences event
|
|
31
|
+
*/
|
|
32
|
+
static modify(event) {
|
|
33
|
+
if (!isValidNappletHandlers(event))
|
|
34
|
+
throw new Error("Expected a napplet handler preferences event");
|
|
35
|
+
return new NappletHandlersFactory((res) => res(toEventTemplate(event)));
|
|
36
|
+
}
|
|
37
|
+
/** Applies a tag operation to the public or private tags */
|
|
38
|
+
modifyHandlerTags(operation, hidden) {
|
|
39
|
+
return hidden ? this.modifyHiddenTags(operation) : this.modifyPublicTags(operation);
|
|
40
|
+
}
|
|
41
|
+
/** Applies an intent tag operation once the archetype is known from the draft's `d` tag */
|
|
42
|
+
modifyIntentTags(intent, hidden, build) {
|
|
43
|
+
return this.chain(async (draft) => {
|
|
44
|
+
const identity = getConventionIdentity(getTagValue(draft, "d") ?? "", intent);
|
|
45
|
+
const operation = build(identity);
|
|
46
|
+
return hidden ? modifyHiddenTags(this.signer, operation)(draft) : modifyPublicTags(operation)(draft);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** Adds an archetype-wide handler as the last fallback */
|
|
50
|
+
handler(input, hidden = false) {
|
|
51
|
+
return this.modifyHandlerTags(addNappletHandlerTag(input), hidden);
|
|
52
|
+
}
|
|
53
|
+
/** Makes an archetype-wide handler the preferred one */
|
|
54
|
+
preferHandler(input, hidden = false) {
|
|
55
|
+
return this.modifyHandlerTags(preferNappletHandlerTag(input), hidden);
|
|
56
|
+
}
|
|
57
|
+
/** Removes an archetype-wide handler */
|
|
58
|
+
removeHandler(input, hidden = false) {
|
|
59
|
+
return this.modifyHandlerTags(removeNappletHandlerTag(input), hidden);
|
|
60
|
+
}
|
|
61
|
+
/** Adds a handler for one intent (`"edit"` or `"napplet:<archetype>/edit"`) as the last fallback */
|
|
62
|
+
intentHandler(intent, input, hidden = false) {
|
|
63
|
+
return this.modifyIntentTags(intent, hidden, (identity) => addNappletIntentHandlerTag(identity, input));
|
|
64
|
+
}
|
|
65
|
+
/** Makes a handler the preferred one for an intent */
|
|
66
|
+
preferIntentHandler(intent, input, hidden = false) {
|
|
67
|
+
return this.modifyIntentTags(intent, hidden, (identity) => preferNappletIntentHandlerTag(identity, input));
|
|
68
|
+
}
|
|
69
|
+
/** Removes one handler for an intent, or every handler for it when no input is given */
|
|
70
|
+
removeIntentHandler(intent, input, hidden = false) {
|
|
71
|
+
return this.modifyIntentTags(intent, hidden, (identity) => removeNappletIntentHandlerTag(identity, input));
|
|
72
|
+
}
|
|
73
|
+
/** Removes every public and private entry, leaving an empty preferences event */
|
|
74
|
+
clear() {
|
|
75
|
+
return this.modifyPublicTags(clearNappletHandlerTags()).chain(setContent(""));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { NAPPLET_SNAPSHOT_KIND } from "../helpers/napplet.js";
|
|
3
|
+
import { NappletManifestFactory } from "./internal/napplet-manifest.js";
|
|
4
|
+
/** An event template for a snapshot napplet manifest */
|
|
5
|
+
export type NappletSnapshotTemplate = KnownEventTemplate<typeof NAPPLET_SNAPSHOT_KIND>;
|
|
6
|
+
/** A factory for snapshot napplet manifests (kind 5129) */
|
|
7
|
+
export declare class NappletSnapshotFactory extends NappletManifestFactory<typeof NAPPLET_SNAPSHOT_KIND> {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a snapshot of the current manifest and preserves its lineage
|
|
10
|
+
* @throws if the source is invalid
|
|
11
|
+
*/
|
|
12
|
+
static create(napplet: NostrEvent): NappletSnapshotFactory;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a factory for modifying a snapshot napplet manifest
|
|
15
|
+
* @throws if the event is not a valid snapshot napplet manifest
|
|
16
|
+
*/
|
|
17
|
+
static modify(event: NostrEvent): NappletSnapshotFactory;
|
|
18
|
+
}
|