@welshman/app 0.11.3 → 0.12.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.
@@ -4,7 +4,7 @@ import type { IApp } from "./app.js";
4
4
  * An event paired with the relays it's meant for, without committing to how
5
5
  * it gets published. Plugin mutation methods (`create`/`update`/etc.) build
6
6
  * the event and return a `Command` instead of publishing it directly, so the
7
- * caller decides: `publish()` sends it through the normal `Thunks` pipeline,
7
+ * caller decides: `publish()` sends it through the normal `Publisher` pipeline,
8
8
  * and `publishToRelays(urls)` targets a specific set of relays.
9
9
  */
10
10
  export declare class Command {
@@ -12,9 +12,9 @@ export declare class Command {
12
12
  readonly event: EventTemplate;
13
13
  readonly relays: string[];
14
14
  constructor(app: IApp, event: EventTemplate, relays: string[]);
15
- publish: () => import("./index.js").Thunk;
16
- publishToRelays: (urls: string[]) => import("./index.js").Thunk;
15
+ publish: () => import("./index.js").Publication;
16
+ publishToRelays: (urls: string[]) => import("./index.js").Publication;
17
17
  }
18
- export declare const publish: (command: Command) => import("./index.js").Thunk;
19
- export declare const publishToRelays: (urls: string[]) => (command: Command) => import("./index.js").Thunk;
18
+ export declare const publish: (command: Command) => import("./index.js").Publication;
19
+ export declare const publishToRelays: (urls: string[]) => (command: Command) => import("./index.js").Publication;
20
20
  //# sourceMappingURL=command.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,UAAU,CAAA;AAGlC;;;;;;GAMG;AACH,qBAAa,OAAO;IAEhB,QAAQ,CAAC,GAAG,EAAE,IAAI;IAClB,QAAQ,CAAC,KAAK,EAAE,aAAa;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE;gBAFhB,GAAG,EAAE,IAAI,EACT,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,MAAM,EAAE;IAG3B,OAAO,mCAA0C;IAEjD,eAAe,GAAI,MAAM,MAAM,EAAE,gCACgC;CAClE;AAED,eAAO,MAAM,OAAO,GAAI,SAAS,OAAO,+BAAsB,CAAA;AAE9D,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,EAAE,MAAM,SAAS,OAAO,+BACrC,CAAA"}
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,UAAU,CAAA;AAGlC;;;;;;GAMG;AACH,qBAAa,OAAO;IAEhB,QAAQ,CAAC,GAAG,EAAE,IAAI;IAClB,QAAQ,CAAC,KAAK,EAAE,aAAa;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE;gBAFhB,GAAG,EAAE,IAAI,EACT,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,MAAM,EAAE;IAG3B,OAAO,yCAA0C;IAEjD,eAAe,GAAI,MAAM,MAAM,EAAE,sCACmC;CACrE;AAED,eAAO,MAAM,OAAO,GAAI,SAAS,OAAO,qCAAsB,CAAA;AAE9D,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,EAAE,MAAM,SAAS,OAAO,qCACrC,CAAA"}
@@ -1,9 +1,9 @@
1
- import { Thunks } from "./plugins/thunk.js";
1
+ import { Publisher } from "./plugins/publisher.js";
2
2
  /**
3
3
  * An event paired with the relays it's meant for, without committing to how
4
4
  * it gets published. Plugin mutation methods (`create`/`update`/etc.) build
5
5
  * the event and return a `Command` instead of publishing it directly, so the
6
- * caller decides: `publish()` sends it through the normal `Thunks` pipeline,
6
+ * caller decides: `publish()` sends it through the normal `Publisher` pipeline,
7
7
  * and `publishToRelays(urls)` targets a specific set of relays.
8
8
  */
9
9
  export class Command {
@@ -16,7 +16,7 @@ export class Command {
16
16
  this.relays = relays;
17
17
  }
18
18
  publish = () => this.publishToRelays(this.relays);
19
- publishToRelays = (urls) => this.app.use(Thunks).publish({ event: this.event, relays: urls });
19
+ publishToRelays = (urls) => this.app.use(Publisher).publish({ event: this.event, relays: urls });
20
20
  }
21
21
  export const publish = (command) => command.publish();
22
22
  export const publishToRelays = (urls) => (command) => command.publishToRelays(urls);
@@ -1 +1 @@
1
- {"version":3,"file":"command.js","sourceRoot":"","sources":["../../../src/command.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,MAAM,EAAC,MAAM,oBAAoB,CAAA;AAEzC;;;;;;GAMG;AACH,MAAM,OAAO,OAAO;IAEP;IACA;IACA;IAHX,YACW,GAAS,EACT,KAAoB,EACpB,MAAgB;QAFhB,QAAG,GAAH,GAAG,CAAM;QACT,UAAK,GAAL,KAAK,CAAe;QACpB,WAAM,GAAN,MAAM,CAAU;IACxB,CAAC;IAEJ,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAEjD,eAAe,GAAG,CAAC,IAAc,EAAE,EAAE,CACnC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAC,CAAC,CAAA;CAClE;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAgB,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;AAE9D,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAc,EAAE,EAAE,CAAC,CAAC,OAAgB,EAAE,EAAE,CACtE,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA"}
1
+ {"version":3,"file":"command.js","sourceRoot":"","sources":["../../../src/command.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAA;AAEhD;;;;;;GAMG;AACH,MAAM,OAAO,OAAO;IAEP;IACA;IACA;IAHX,YACW,GAAS,EACT,KAAoB,EACpB,MAAgB;QAFhB,QAAG,GAAH,GAAG,CAAM;QACT,UAAK,GAAL,KAAK,CAAe;QACpB,WAAM,GAAN,MAAM,CAAU;IACxB,CAAC;IAEJ,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAEjD,eAAe,GAAG,CAAC,IAAc,EAAE,EAAE,CACnC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,EAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAC,CAAC,CAAA;CACrE;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAgB,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;AAE9D,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAc,EAAE,EAAE,CAAC,CAAC,OAAgB,EAAE,EAAE,CACtE,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA"}
@@ -40,5 +40,5 @@ export * from "./plugins/rooms.js";
40
40
  export * from "./plugins/relayRoles.js";
41
41
  export * from "./plugins/relayMembers.js";
42
42
  export * from "./plugins/relayManagement.js";
43
- export * from "./plugins/thunk.js";
43
+ export * from "./plugins/publisher.js";
44
44
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,qBAAqB,CAAA;AACnC,cA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Ac,qBAAqB,CAAA;AACnC,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA;AACjC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,kCAAkC,CAAA;AAChD,cAAc,+BAA+B,CAAA;AAC7C,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CAAA;AACzC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA"}
@@ -40,5 +40,5 @@ export * from "./plugins/rooms.js";
40
40
  export * from "./plugins/relayRoles.js";
41
41
  export * from "./plugins/relayMembers.js";
42
42
  export * from "./plugins/relayManagement.js";
43
- export * from "./plugins/thunk.js";
43
+ export * from "./plugins/publisher.js";
44
44
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,W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AAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA;AACjC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,kCAAkC,CAAA;AAChD,cAAc,+BAA+B,CAAA;AAC7C,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CAAA;AACzC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA"}
@@ -0,0 +1,122 @@
1
+ import type { Subscriber } from "svelte/store";
2
+ import { TaskQueue } from "@welshman/lib";
3
+ import { HashedEvent, EventTemplate } from "@welshman/util";
4
+ import { PublishStatus, PublishResultsByRelay } from "@welshman/net";
5
+ import { ISigner } from "@welshman/signer";
6
+ import type { IApp } from "../app.js";
7
+ /** What the caller asked for. A retry rebuilds from it and the publication's current event. */
8
+ export type PublishRequest = {
9
+ event: EventTemplate;
10
+ relays: string[];
11
+ recipient?: string;
12
+ delay?: number;
13
+ pow?: number;
14
+ priority?: number;
15
+ timeout?: number;
16
+ };
17
+ /** A publication's place in the pipeline. Every terminal state has a result for each relay. */
18
+ export type PublicationState = {
19
+ stage: "queued";
20
+ } | {
21
+ stage: "delayed";
22
+ until: number;
23
+ } | {
24
+ stage: "wrapping";
25
+ } | {
26
+ stage: "pow";
27
+ difficulty: number;
28
+ } | {
29
+ stage: "signing";
30
+ } | {
31
+ stage: "sending";
32
+ results: PublishResultsByRelay;
33
+ } | {
34
+ stage: "sent";
35
+ results: PublishResultsByRelay;
36
+ } | {
37
+ stage: "failed";
38
+ error: string;
39
+ results: PublishResultsByRelay;
40
+ } | {
41
+ stage: "aborted";
42
+ results: PublishResultsByRelay;
43
+ };
44
+ export type PublicationStage = PublicationState["stage"];
45
+ export declare const TERMINAL_STAGES: PublicationStage[];
46
+ /** Status queries over per-relay results. A relay with no result is still in progress. */
47
+ export declare abstract class PublishStatusView {
48
+ abstract readonly relays: string[];
49
+ abstract readonly results: PublishResultsByRelay;
50
+ abstract isComplete(): boolean;
51
+ abstract abort(): void;
52
+ getUrlsWithStatus(statuses: PublishStatus | PublishStatus[]): string[];
53
+ getCompleteUrls(): string[];
54
+ getIncompleteUrls(): string[];
55
+ getFailedUrls(): string[];
56
+ hasStatus(statuses: PublishStatus | PublishStatus[]): boolean;
57
+ canAbort(): boolean;
58
+ getError(): string | undefined;
59
+ }
60
+ /** One event on its way to a set of relays. The `Publisher` moves it with `advance`. */
61
+ export declare class Publication extends PublishStatusView {
62
+ readonly request: PublishRequest;
63
+ state: PublicationState;
64
+ event: HashedEvent;
65
+ wrap?: HashedEvent;
66
+ readonly controller: AbortController;
67
+ private _subs;
68
+ private _settled;
69
+ constructor(request: PublishRequest, event: HashedEvent);
70
+ get relays(): string[];
71
+ get results(): PublishResultsByRelay;
72
+ get signal(): AbortSignal;
73
+ isComplete(): boolean;
74
+ advance(state: PublicationState, draft?: {
75
+ event: HashedEvent;
76
+ wrap?: HashedEvent;
77
+ }): void;
78
+ abort(): void;
79
+ subscribe(subscriber: Subscriber<this>): () => void;
80
+ settled(): import("@welshman/lib").Deferred<this, this>;
81
+ }
82
+ export declare const mergeResults: (publications: Publication[]) => PublishResultsByRelay;
83
+ /** Several publications watched as one, e.g. a rumor gift-wrapped for each recipient. */
84
+ export declare class PublicationGroup extends PublishStatusView {
85
+ readonly publications: Publication[];
86
+ private _subs;
87
+ constructor(publications: Publication[]);
88
+ get relays(): string[];
89
+ get results(): PublishResultsByRelay;
90
+ isComplete(): boolean;
91
+ abort(): void;
92
+ subscribe(subscriber: Subscriber<this>): () => void;
93
+ settled(): Promise<this>;
94
+ }
95
+ export type Publishable = Publication | PublicationGroup;
96
+ type Draft = {
97
+ event: HashedEvent;
98
+ wrap?: HashedEvent;
99
+ wrapper?: ISigner;
100
+ };
101
+ type StageContext = {
102
+ app: IApp;
103
+ publication: Publication;
104
+ enter: (state: PublicationState) => void;
105
+ };
106
+ type Stage = (draft: Draft, ctx: StageContext) => Promise<Draft>;
107
+ export declare const STAGES: Stage[];
108
+ /** Per-app publish pipeline, reached via `app.use(Publisher)`. */
109
+ export declare class Publisher {
110
+ readonly app: IApp;
111
+ history: import("svelte/store").Writable<Publication[]>;
112
+ queue: TaskQueue<Publication>;
113
+ constructor(app: IApp);
114
+ publish: (request: PublishRequest) => Publication;
115
+ retry(target: Publication, relays?: string[]): Publication;
116
+ retry(target: PublicationGroup, relays?: string[]): PublicationGroup;
117
+ merge(items: Publishable[]): PublicationGroup;
118
+ private run;
119
+ private observe;
120
+ }
121
+ export {};
122
+ //# sourceMappingURL=publisher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publisher.d.ts","sourceRoot":"","sources":["../../../../src/plugins/publisher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,cAAc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AW,EAAE;YAMZ,GAAG;IAsBjB,OAAO,CAAC,OAAO;CAyDhB"}
@@ -0,0 +1,368 @@
1
+ import { get, writable } from "svelte/store";
2
+ import { append, TaskQueue, ensurePlural, remove, defer, sleep, now, uniq } from "@welshman/lib";
3
+ import { isSignedEvent, WRAPPED_KINDS, prep, makePow, } from "@welshman/util";
4
+ import { PublishStatus } from "@welshman/net";
5
+ import { Nip01Signer, Nip59 } from "@welshman/signer";
6
+ import { Network } from "./network.js";
7
+ import { User } from "../user.js";
8
+ export const TERMINAL_STAGES = ["sent", "failed", "aborted"];
9
+ const { Pending, Success, Failure, Timeout, Aborted } = PublishStatus;
10
+ const resultsFor = (relays, status, detail) => {
11
+ const results = {};
12
+ for (const relay of relays) {
13
+ results[relay] = { relay, status, detail };
14
+ }
15
+ return results;
16
+ };
17
+ /** Status queries over per-relay results. A relay with no result is still in progress. */
18
+ export class PublishStatusView {
19
+ getUrlsWithStatus(statuses) {
20
+ const matches = ensurePlural(statuses);
21
+ return this.relays.filter(relay => {
22
+ const result = this.results[relay];
23
+ return result !== undefined && matches.includes(result.status);
24
+ });
25
+ }
26
+ getCompleteUrls() {
27
+ return this.getUrlsWithStatus([Success, Failure, Timeout, Aborted]);
28
+ }
29
+ getIncompleteUrls() {
30
+ return this.relays.filter(relay => [undefined, Pending].includes(this.results[relay]?.status));
31
+ }
32
+ getFailedUrls() {
33
+ return this.getUrlsWithStatus([Failure, Timeout]);
34
+ }
35
+ hasStatus(statuses) {
36
+ return this.getUrlsWithStatus(statuses).length > 0;
37
+ }
38
+ // Nothing has reached a relay yet, so aborting still undoes the publish entirely.
39
+ canAbort() {
40
+ return this.relays.some(relay => this.results[relay] === undefined);
41
+ }
42
+ getError() {
43
+ return this.relays.map(relay => this.results[relay]).find(result => result?.status === Failure)
44
+ ?.detail;
45
+ }
46
+ }
47
+ /** One event on its way to a set of relays. The `Publisher` moves it with `advance`. */
48
+ export class Publication extends PublishStatusView {
49
+ request;
50
+ state = { stage: "queued" };
51
+ // Mined and signed as the pipeline runs. For a gift wrap, this is the rumor inside `wrap`.
52
+ event;
53
+ wrap;
54
+ controller = new AbortController();
55
+ _subs = [];
56
+ _settled = defer();
57
+ constructor(request, event) {
58
+ super();
59
+ this.request = request;
60
+ this.event = event;
61
+ }
62
+ get relays() {
63
+ return this.request.relays;
64
+ }
65
+ get results() {
66
+ return "results" in this.state ? this.state.results : {};
67
+ }
68
+ get signal() {
69
+ return this.controller.signal;
70
+ }
71
+ isComplete() {
72
+ return TERMINAL_STAGES.includes(this.state.stage);
73
+ }
74
+ advance(state, draft) {
75
+ if (!this.isComplete()) {
76
+ this.state = state;
77
+ if (draft) {
78
+ this.event = draft.event;
79
+ this.wrap = draft.wrap;
80
+ }
81
+ for (const subscriber of this._subs) {
82
+ subscriber(this);
83
+ }
84
+ if (this.isComplete()) {
85
+ this._subs = [];
86
+ this._settled.resolve(this);
87
+ }
88
+ }
89
+ }
90
+ // Relays that already answered keep their result.
91
+ abort() {
92
+ const results = { ...resultsFor(this.relays, Aborted, "aborted"), ...this.results };
93
+ for (const [relay, result] of Object.entries(results)) {
94
+ if (result.status === Pending) {
95
+ results[relay] = { relay, status: Aborted, detail: "aborted" };
96
+ }
97
+ }
98
+ this.advance({ stage: "aborted", results });
99
+ this.controller.abort();
100
+ }
101
+ // A settled publication never changes again, so its subscribers aren't kept.
102
+ subscribe(subscriber) {
103
+ subscriber(this);
104
+ if (!this.isComplete()) {
105
+ this._subs.push(subscriber);
106
+ }
107
+ return () => {
108
+ this._subs = remove(subscriber, this._subs);
109
+ };
110
+ }
111
+ settled() {
112
+ return this._settled;
113
+ }
114
+ }
115
+ // Pending first, then the worst outcome, so a relay succeeds only when every publication did.
116
+ const MERGE_PRECEDENCE = [Pending, Failure, Timeout, Aborted, Success];
117
+ export const mergeResults = (publications) => {
118
+ const results = {};
119
+ const rank = (result) => MERGE_PRECEDENCE.indexOf(result.status);
120
+ for (const relay of uniq(publications.flatMap(p => p.relays))) {
121
+ const sending = publications.filter(p => p.relays.includes(relay));
122
+ const answered = sending
123
+ .map(p => p.results[relay])
124
+ .filter((result) => result !== undefined);
125
+ if (answered.length === sending.length) {
126
+ results[relay] = answered.reduce((a, b) => (rank(b) < rank(a) ? b : a));
127
+ }
128
+ }
129
+ return results;
130
+ };
131
+ /** Several publications watched as one, e.g. a rumor gift-wrapped for each recipient. */
132
+ export class PublicationGroup extends PublishStatusView {
133
+ publications;
134
+ _subs = [];
135
+ constructor(publications) {
136
+ super();
137
+ this.publications = publications;
138
+ for (const publication of publications) {
139
+ publication.subscribe(() => {
140
+ for (const subscriber of this._subs) {
141
+ subscriber(this);
142
+ }
143
+ if (this.isComplete()) {
144
+ this._subs = [];
145
+ }
146
+ });
147
+ }
148
+ }
149
+ get relays() {
150
+ return uniq(this.publications.flatMap(p => p.relays));
151
+ }
152
+ get results() {
153
+ return mergeResults(this.publications);
154
+ }
155
+ isComplete() {
156
+ return this.publications.every(p => p.isComplete());
157
+ }
158
+ abort() {
159
+ this.publications.forEach(p => p.abort());
160
+ }
161
+ // As with a publication, a settled group never changes again, so its subscribers aren't kept.
162
+ subscribe(subscriber) {
163
+ subscriber(this);
164
+ if (!this.isComplete()) {
165
+ this._subs.push(subscriber);
166
+ }
167
+ return () => {
168
+ this._subs = remove(subscriber, this._subs);
169
+ };
170
+ }
171
+ async settled() {
172
+ await Promise.all(this.publications.map(p => p.settled()));
173
+ return this;
174
+ }
175
+ }
176
+ // A remote signer can otherwise hang the publication indefinitely.
177
+ const SIGN_TIMEOUT = 30_000;
178
+ // The soft-undo window comes before anything is signed.
179
+ const delayStage = async (draft, { publication, enter }) => {
180
+ const { delay } = publication.request;
181
+ if (delay) {
182
+ enter({ stage: "delayed", until: now() + delay / 1000 });
183
+ await Promise.race([
184
+ sleep(delay),
185
+ new Promise(resolve => publication.signal.addEventListener("abort", resolve, { once: true })),
186
+ ]);
187
+ }
188
+ return draft;
189
+ };
190
+ // The user signs the seal, and a throwaway key signs the wrap.
191
+ const wrapStage = async (draft, { app, publication, enter }) => {
192
+ const { recipient } = publication.request;
193
+ let result = draft;
194
+ if (recipient) {
195
+ enter({ stage: "wrapping" });
196
+ const wrapper = Nip01Signer.ephemeral();
197
+ const nip59 = new Nip59(User.require(app).signer, wrapper);
198
+ result = { ...draft, wrapper, wrap: await nip59.wrap(recipient, draft.event) };
199
+ }
200
+ return result;
201
+ };
202
+ // Relays receive the wrap rather than the rumor, so the wrap is what gets mined.
203
+ const powStage = async (draft, { publication, enter }) => {
204
+ const { pow } = publication.request;
205
+ const target = draft.wrap ?? draft.event;
206
+ let result = draft;
207
+ if (pow && (draft.wrap || !isSignedEvent(target))) {
208
+ enter({ stage: "pow", difficulty: pow });
209
+ // Mining re-hashes, so it starts from the owned fields and leaves any id or signature behind.
210
+ const { kind, tags, content, created_at, pubkey } = target;
211
+ const mined = await makePow({ kind, tags, content, created_at, pubkey }, pow).result;
212
+ result = draft.wrap ? { ...draft, wrap: mined } : { ...draft, event: mined };
213
+ }
214
+ return result;
215
+ };
216
+ const signStage = async (draft, { app, enter }) => {
217
+ const options = { signal: AbortSignal.timeout(SIGN_TIMEOUT) };
218
+ let result = draft;
219
+ if (draft.wrap && draft.wrapper && !isSignedEvent(draft.wrap)) {
220
+ result = { ...draft, wrap: await draft.wrapper.sign(draft.wrap, options) };
221
+ }
222
+ if (!draft.wrap && !isSignedEvent(draft.event)) {
223
+ enter({ stage: "signing" });
224
+ result = { ...draft, event: await User.require(app).sign(draft.event, options) };
225
+ }
226
+ return result;
227
+ };
228
+ const sendStage = async (draft, { app, publication, enter }) => {
229
+ const { relays, priority, timeout } = publication.request;
230
+ let results = resultsFor(relays, Pending, "");
231
+ const update = (result) => {
232
+ results = { ...results, [result.relay]: result };
233
+ enter({ stage: "sending", results });
234
+ };
235
+ const event = draft.wrap ?? draft.event;
236
+ if (!isSignedEvent(event)) {
237
+ throw new Error("Attempted to send an unsigned event");
238
+ }
239
+ enter({ stage: "sending", results });
240
+ await app.use(Network).publish({
241
+ event,
242
+ relays,
243
+ priority,
244
+ timeout,
245
+ signal: publication.signal,
246
+ onPending: update,
247
+ onSuccess: update,
248
+ onFailure: update,
249
+ onTimeout: update,
250
+ onAborted: update,
251
+ });
252
+ enter({ stage: "sent", results });
253
+ return draft;
254
+ };
255
+ export const STAGES = [delayStage, wrapStage, powStage, signStage, sendStage];
256
+ /** Per-app publish pipeline, reached via `app.use(Publisher)`. */
257
+ export class Publisher {
258
+ app;
259
+ history = writable([]);
260
+ // Paces how fast publications enter the pipeline.
261
+ queue = new TaskQueue({
262
+ batchSize: 10,
263
+ batchDelay: 100,
264
+ processItem: (publication) => {
265
+ this.run(publication);
266
+ },
267
+ });
268
+ constructor(app) {
269
+ this.app = app;
270
+ app.onCleanup(() => {
271
+ this.queue.clear();
272
+ // Stops in-flight publishes and unwinds their optimistic writes.
273
+ for (const publication of get(this.history)) {
274
+ publication.abort();
275
+ }
276
+ });
277
+ }
278
+ publish = (request) => {
279
+ if (!request.recipient && WRAPPED_KINDS.includes(request.event.kind)) {
280
+ throw new Error(`Attempted to publish a kind ${request.event.kind} without wrapping it`);
281
+ }
282
+ const event = prep(request.event, User.require(this.app).pubkey);
283
+ const publication = new Publication(request, event);
284
+ this.observe(publication);
285
+ this.history.update($history => append(publication, $history));
286
+ this.queue.push(publication);
287
+ return publication;
288
+ };
289
+ retry(target, relays) {
290
+ const targets = (p) => relays ? p.relays.filter(r => relays.includes(r)) : p.relays;
291
+ const replaced = target instanceof PublicationGroup
292
+ ? target.publications.filter(p => targets(p).length > 0)
293
+ : [target];
294
+ this.history.update($history => $history.filter(p => !replaced.includes(p)));
295
+ const retried = replaced.map(p => this.publish({ ...p.request, event: p.event, relays: targets(p) }));
296
+ return target instanceof PublicationGroup ? new PublicationGroup(retried) : retried[0];
297
+ }
298
+ merge(items) {
299
+ return new PublicationGroup(items.flatMap(p => (p instanceof PublicationGroup ? p.publications : [p])));
300
+ }
301
+ async run(publication) {
302
+ const ctx = { app: this.app, publication };
303
+ let draft = { event: publication.event };
304
+ try {
305
+ for (const stage of STAGES) {
306
+ if (!publication.isComplete()) {
307
+ draft = await stage(draft, { ...ctx, enter: state => publication.advance(state, draft) });
308
+ }
309
+ }
310
+ }
311
+ catch (e) {
312
+ const error = String(e || "Failed to publish event");
313
+ console.error("Failed to publish event", e);
314
+ publication.advance({
315
+ stage: "failed",
316
+ error,
317
+ results: resultsFor(publication.relays, Failure, error),
318
+ });
319
+ }
320
+ }
321
+ observe(publication) {
322
+ const { repository, tracker, wrapManager } = this.app;
323
+ const { recipient } = publication.request;
324
+ let current = publication.event;
325
+ let registeredWrap;
326
+ for (const url of publication.relays) {
327
+ tracker.track(current.id, url);
328
+ }
329
+ repository.publish(current);
330
+ publication.subscribe(({ state, event, wrap }) => {
331
+ // Only pow changes the id. A signature on the same id is taken in place.
332
+ if (event.id !== current.id) {
333
+ for (const url of publication.relays) {
334
+ tracker.removeRelay(current.id, url);
335
+ tracker.track(event.id, url);
336
+ }
337
+ repository.removeEvent(current.id);
338
+ }
339
+ if (event !== current) {
340
+ repository.publish(event);
341
+ current = event;
342
+ }
343
+ if (recipient &&
344
+ wrap &&
345
+ isSignedEvent(wrap) &&
346
+ state.stage === "sending" &&
347
+ !registeredWrap) {
348
+ registeredWrap = wrap;
349
+ wrapManager.add({ recipient, wrap, rumor: event });
350
+ }
351
+ if ("results" in state) {
352
+ for (const { relay, status } of Object.values(state.results)) {
353
+ if (![Pending, Success].includes(status)) {
354
+ tracker.removeRelay(current.id, relay);
355
+ }
356
+ }
357
+ }
358
+ if (state.stage === "aborted") {
359
+ if (registeredWrap) {
360
+ wrapManager.remove(registeredWrap.id);
361
+ }
362
+ repository.removeEvent(current.id);
363
+ this.history.update($history => remove(publication, $history));
364
+ }
365
+ });
366
+ }
367
+ }
368
+ //# sourceMappingURL=publisher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publisher.js","sourceRoot":"","sources":["../../../../src/plugins/publisher.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EA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ClC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAA;YAChE,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -1,9 +1,9 @@
1
1
  import { TaskQueue } from "@welshman/lib";
2
2
  import type { TrustedEvent, EventTemplate } from "@welshman/util";
3
- import { MergedThunk } from "./thunk.js";
4
- import type { ThunkOptions } from "./thunk.js";
3
+ import { PublicationGroup } from "./publisher.js";
4
+ import type { PublishRequest } from "./publisher.js";
5
5
  import type { IApp } from "../app.js";
6
- export type SendWrappedOptions = Omit<ThunkOptions, "event" | "relays" | "recipient" | "app" | "user"> & {
6
+ export type SendWrappedOptions = Omit<PublishRequest, "event" | "relays" | "recipient"> & {
7
7
  event: EventTemplate;
8
8
  recipients: string[];
9
9
  };
@@ -29,6 +29,6 @@ export declare class Wraps {
29
29
  constructor(app: IApp);
30
30
  retry: (wrap: TrustedEvent, delay: number) => void;
31
31
  enqueue: (wrap: TrustedEvent) => void;
32
- publish: ({ event, recipients, ...options }: SendWrappedOptions) => Promise<MergedThunk>;
32
+ publish: ({ event, recipients, ...options }: SendWrappedOptions) => Promise<PublicationGroup>;
33
33
  }
34
34
  //# sourceMappingURL=wraps.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wraps.d.ts","sourceRoot":"","sources":["../../../../src/plugins/wraps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAY,MAAM,eAAe,CAAA;AAElD,OAAO,KAAK,EAAC,YAAY,EAAe,aAAa,EAAC,MAAM,gBAAgB,CAAA;AAE5E,OAAO,EAAC,WAAW,EAAS,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAA;AAG5C,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAEnC,MAAM,MAAM,kBAAkB,GAAG,IAAI,C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AAGpC,eAAO,MAAM,kBAAkB,OAAQ,CAAA;AAEvC;;;;;;;;;;GAUG;AACH,qBAAa,KAAK;IAKJ,QAAQ,CAAC,GAAG,EAAE,IAAI;IAJ9B,cAAc,sBAA4B;IAC1C,WAAW,sBAA2C;IACtD,KAAK,EAAE,SAAS,CAAC,YAAY,CAAC,CAAA;gBAET,GAAG,EAAE,IAAI;IA+C9B,KAAK,GAAI,MAAM,YAAY,EAAE,OAAO,MAAM,UAOzC;IAED,OAAO,GAAI,MAAM,YAAY,UAM5B;IAID,OAAO,GAAU,mCAAiC,kBAAkB,+BAiBnE;CACF"}
@@ -1,7 +1,7 @@
1
1
  import { TaskQueue, uniq, now } from "@welshman/lib";
2
2
  import { hexTags, tagValues, prep } from "@welshman/util";
3
3
  import { Nip59 } from "@welshman/signer";
4
- import { MergedThunk, Thunks } from "./thunk.js";
4
+ import { PublicationGroup, Publisher } from "./publisher.js";
5
5
  import { User } from "../user.js";
6
6
  import { MessagingRelayLists } from "./messagingRelayLists.js";
7
7
  export const MAX_UNWRAP_ATTEMPTS = 3;
@@ -89,9 +89,11 @@ export class Wraps {
89
89
  const user = User.require(this.app);
90
90
  // Stabilize the event id across the different wraps
91
91
  const stableEvent = prep(event, user.pubkey, now());
92
- return new MergedThunk(await Promise.all(uniq(recipients).map(async (recipient) => {
92
+ return new PublicationGroup(await Promise.all(uniq(recipients).map(async (recipient) => {
93
93
  const relays = (await this.app.use(MessagingRelayLists).load(recipient))?.urls() ?? [];
94
- return this.app.use(Thunks).publish({ event: stableEvent, relays, recipient, ...options });
94
+ return this.app
95
+ .use(Publisher)
96
+ .publish({ event: stableEvent, relays, recipient, ...options });
95
97
  })));
96
98
  };
97
99
  }
@@ -1 +1 @@
1
- {"version":3,"file":"wraps.js","sourceRoot":"","sources":["../../../../src/plugins/wraps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,IAAI,EAAE,GAAG,EAAC,MAAM,eAAe,CAAA;AAClD,OAAO,EAA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,UAAU,EAAE,GAAG,OAAO,EAAqB,EAAE,EAAE;QACtE,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAEnC,oDAAoD;QACpD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;QAEnD,OAAO,IAAI,gBAAgB,CACzB,MAAM,OAAO,CAAC,GAAG,CACf,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,KAAK,EAAC,SAAS,EAAC,EAAE;YACrC,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;YAEtF,OAAO,IAAI,CAAC,GAAG;iBACZ,GAAG,CAAC,SAAS,CAAC;iBACd,OAAO,CAAC,EAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,EAAC,CAAC,CAAA;QACjE,CAAC,CAAC,CACH,CACF,CAAA;IACH,CAAC,CAAA;CACF"}
@@ -1 +1 @@
1
- {"root":["../src/app.ts","../src/command.ts","../src/createapp.ts","../src/index.ts","../src/policy.ts","../src/session.ts","../src/user.ts","../src/plugins/base.ts","../src/plugins/blockedrelaylists.ts","../src/plugins/blossomserverlists.ts","../src/plugins/deletes.ts","../src/plugins/domain.ts","../src/plugins/events.ts","../src/plugins/feedlists.ts","../src/plugins/feeds.ts","../src/plugins/followlists.ts","../src/plugins/handles.ts","../src/plugins/logger.ts","../src/plugins/messagingrelaylists.ts","../src/plugins/mutelists.ts","../src/plugins/network.ts","../src/plugins/pinboards.ts","../src/plugins/pins.ts","../src/plugins/plaintext.ts","../src/plugins/profiles.ts","../src/plugins/reactions.ts","../src/plugins/relaylists.ts","../src/plugins/relaymanagement.ts","../src/plugins/relaymembers.ts","../src/plugins/relayroles.ts","../src/plugins/relaystats.ts","../src/plugins/relays.ts","../src/plugins/roomlists.ts","../src/plugins/roompins.ts","../src/plugins/rooms.ts","../src/plugins/router.ts","../src/plugins/searchrelaylists.ts","../src/plugins/sync.ts","../src/plugins/thunk.ts","../src/plugins/topics.ts","../src/plugins/wot.ts","../src/plugins/wraps.ts","../src/plugins/zapgoals.ts","../src/plugins/zappers.ts"],"version":"5.8.3"}
1
+ {"root":["../src/app.ts","../src/command.ts","../src/createapp.ts","../src/index.ts","../src/policy.ts","../src/session.ts","../src/user.ts","../src/plugins/base.ts","../src/plugins/blockedrelaylists.ts","../src/plugins/blossomserverlists.ts","../src/plugins/deletes.ts","../src/plugins/domain.ts","../src/plugins/events.ts","../src/plugins/feedlists.ts","../src/plugins/feeds.ts","../src/plugins/followlists.ts","../src/plugins/handles.ts","../src/plugins/logger.ts","../src/plugins/messagingrelaylists.ts","../src/plugins/mutelists.ts","../src/plugins/network.ts","../src/plugins/pinboards.ts","../src/plugins/pins.ts","../src/plugins/plaintext.ts","../src/plugins/profiles.ts","../src/plugins/publisher.ts","../src/plugins/reactions.ts","../src/plugins/relaylists.ts","../src/plugins/relaymanagement.ts","../src/plugins/relaymembers.ts","../src/plugins/relayroles.ts","../src/plugins/relaystats.ts","../src/plugins/relays.ts","../src/plugins/roomlists.ts","../src/plugins/roompins.ts","../src/plugins/rooms.ts","../src/plugins/router.ts","../src/plugins/searchrelaylists.ts","../src/plugins/sync.ts","../src/plugins/topics.ts","../src/plugins/wot.ts","../src/plugins/wraps.ts","../src/plugins/zapgoals.ts","../src/plugins/zappers.ts"],"version":"5.8.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@welshman/app",
3
- "version": "0.11.3",
3
+ "version": "0.12.0",
4
4
  "author": "hodlbod",
5
5
  "license": "MIT",
6
6
  "description": "An instance-based, composable client for building nostr applications",
@@ -21,13 +21,13 @@
21
21
  "peerDependencies": {
22
22
  "@pomade/core": "^0.3.3",
23
23
  "svelte": "^4.0.0 || ^5.0.0",
24
- "@welshman/domain": "0.11.3",
25
- "@welshman/feeds": "0.11.3",
26
- "@welshman/signer": "0.11.3",
27
- "@welshman/util": "0.11.3",
28
- "@welshman/store": "0.11.3",
29
- "@welshman/lib": "0.11.3",
30
- "@welshman/net": "0.11.3"
24
+ "@welshman/domain": "0.12.0",
25
+ "@welshman/lib": "0.12.0",
26
+ "@welshman/feeds": "0.12.0",
27
+ "@welshman/net": "0.12.0",
28
+ "@welshman/signer": "0.12.0",
29
+ "@welshman/util": "0.12.0",
30
+ "@welshman/store": "0.12.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "rimraf": "~6.0.0",
@@ -35,13 +35,13 @@
35
35
  "@pomade/core": "^0.3.3",
36
36
  "@types/throttle-debounce": "^5.0.2",
37
37
  "svelte": "5.55.9",
38
- "@welshman/signer": "0.11.3",
39
- "@welshman/domain": "0.11.3",
40
- "@welshman/feeds": "0.11.3",
41
- "@welshman/lib": "0.11.3",
42
- "@welshman/net": "0.11.3",
43
- "@welshman/util": "0.11.3",
44
- "@welshman/store": "0.11.3"
38
+ "@welshman/lib": "0.12.0",
39
+ "@welshman/net": "0.12.0",
40
+ "@welshman/feeds": "0.12.0",
41
+ "@welshman/signer": "0.12.0",
42
+ "@welshman/domain": "0.12.0",
43
+ "@welshman/util": "0.12.0",
44
+ "@welshman/store": "0.12.0"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "pnpm run clean && pnpm run compile --force",
@@ -1,76 +0,0 @@
1
- import type { Subscriber } from "svelte/store";
2
- import type { Override } from "@welshman/lib";
3
- import { TaskQueue } from "@welshman/lib";
4
- import { HashedEvent, EventTemplate, SignedEvent } from "@welshman/util";
5
- import { PublishStatus, PublishResult, PublishOptions, PublishResultsByRelay } from "@welshman/net";
6
- import type { IApp } from "../app.js";
7
- import { User } from "../user.js";
8
- export type ThunkOptions = Override<PublishOptions, {
9
- app: IApp;
10
- event: EventTemplate;
11
- recipient?: string;
12
- delay?: number;
13
- pow?: number;
14
- }>;
15
- /**
16
- * Shared base for `Thunk` and `MergedThunk`: a subscribable bag of per-relay
17
- * publish `results`.
18
- */
19
- export declare abstract class BaseThunk {
20
- _subs: Subscriber<any>[];
21
- results: PublishResultsByRelay;
22
- abstract abort(): void;
23
- _notify(): void;
24
- subscribe(subscriber: Subscriber<this>): () => void;
25
- getUrlsWithStatus(statuses: PublishStatus | PublishStatus[]): string[];
26
- getCompleteUrls(): string[];
27
- getIncompleteUrls(): string[];
28
- getFailedUrls(): string[];
29
- hasStatus(statuses: PublishStatus | PublishStatus[]): boolean;
30
- isComplete(): boolean;
31
- getError(): string | undefined;
32
- waitForError(): Promise<string>;
33
- waitForCompletion(): Promise<void>;
34
- }
35
- export declare class Thunk extends BaseThunk {
36
- readonly options: Override<ThunkOptions, {
37
- event: HashedEvent;
38
- }>;
39
- complete: import("@welshman/lib").Deferred<void, void>;
40
- controller: AbortController;
41
- wrap?: SignedEvent;
42
- initialId: string;
43
- constructor(options: ThunkOptions);
44
- get user(): User;
45
- _fail(detail: string): void;
46
- _setPending: (result: PublishResult) => void;
47
- _setTimeout: (result: PublishResult) => void;
48
- _setAborted: (result: PublishResult) => void;
49
- _publish(event: SignedEvent): Promise<void>;
50
- publish(): Promise<void>;
51
- abort(): void;
52
- }
53
- export declare class MergedThunk extends BaseThunk {
54
- readonly thunks: Thunk[];
55
- constructor(thunks: Thunk[]);
56
- abort(): void;
57
- }
58
- /**
59
- * Per-app thunk manager — the publish-side counterpart of `Network`. Owns
60
- * the app's optimistic-publish `history` store and the `queue` that paces
61
- * publishing. Reach it via `app.use(Thunks)`; `publish` fills in the app
62
- * (the acting user is derived from it), enqueues the thunk (optimistically
63
- * writing it to the repository), and returns it.
64
- */
65
- export declare class Thunks {
66
- readonly app: IApp;
67
- history: import("svelte/store").Writable<Thunk[]>;
68
- queue: TaskQueue<Thunk>;
69
- constructor(app: IApp);
70
- enqueue(thunk: Thunk): void;
71
- publish: (options: Omit<ThunkOptions, "app">) => Thunk;
72
- retry: (thunk: BaseThunk, relays?: string[]) => Thunk | MergedThunk;
73
- merge(thunks: BaseThunk[]): MergedThunk;
74
- flatten(thunks: BaseThunk[]): Iterable<Thunk>;
75
- }
76
- //# sourceMappingURL=thunk.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"thunk.d.ts","sourceRoot":"","sources":["../../../../src/plugins/thunk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,cAAc,CAAA;AAE5C,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAS,SAAS,EAAmD,MAAM,eAAe,CAAA;AACjG,OAAO,EACL,WAAW,EACX,aAAa,EACb,WAAW,EAKZ,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,qBAAqB,EAAC,MAAM,eAAe,CAAA;AAEjG,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAC,IAAI,EAAC,MAAM,YAAY,CAAA;AAE/B,MAAM,MAAM,YAAY,GAAG,QAAQ,CACjC,cAAc,EACd;IACE,GAAG,EAAE,IAAI,CAAA;IACT,KAAK,EAAE,aAAa,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CACF,CAAA;AAED;;;GAGG;AACH,8BAAsB,SAAS;IAC7B,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAK;IAC7B,OAAO,EAAE,qBAAqB,CAAK;IAEnC,QAAQ,CAAC,KAAK,IAAI,IAAI;IAEtB,OAAO;IAMP,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC;IAUtC,iBAAiB,CAAC,QAAQ,EAAE,aAAa,GAAG,aAAa,EAAE,GAKvC,MAAM,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AS/C"}
@@ -1,344 +0,0 @@
1
- import { get, writable } from "svelte/store";
2
- import { append, TaskQueue, ensurePlural, remove, defer, sleep, nth, without } from "@welshman/lib";
3
- import { isSignedEvent, WRAPPED_KINDS, prep, makePow, } from "@welshman/util";
4
- import { PublishStatus } from "@welshman/net";
5
- import { Nip01Signer, Nip59 } from "@welshman/signer";
6
- import { Network } from "./network.js";
7
- import { User } from "../user.js";
8
- /**
9
- * Shared base for `Thunk` and `MergedThunk`: a subscribable bag of per-relay
10
- * publish `results`.
11
- */
12
- export class BaseThunk {
13
- _subs = [];
14
- results = {};
15
- _notify() {
16
- for (const subscriber of this._subs) {
17
- subscriber(this);
18
- }
19
- }
20
- subscribe(subscriber) {
21
- this._subs.push(subscriber);
22
- subscriber(this);
23
- return () => {
24
- this._subs = remove(subscriber, this._subs);
25
- };
26
- }
27
- getUrlsWithStatus(statuses) {
28
- const matches = ensurePlural(statuses);
29
- return Object.entries(this.results)
30
- .filter(([_, { status }]) => matches.includes(status))
31
- .map(nth(0));
32
- }
33
- getCompleteUrls() {
34
- return this.getUrlsWithStatus(without([PublishStatus.Sending, PublishStatus.Pending], Object.values(PublishStatus)));
35
- }
36
- getIncompleteUrls() {
37
- return this.getUrlsWithStatus([PublishStatus.Sending, PublishStatus.Pending]);
38
- }
39
- getFailedUrls() {
40
- return this.getUrlsWithStatus([PublishStatus.Failure, PublishStatus.Timeout]);
41
- }
42
- hasStatus(statuses) {
43
- return this.getUrlsWithStatus(statuses).length > 0;
44
- }
45
- isComplete() {
46
- return !this.hasStatus([PublishStatus.Sending, PublishStatus.Pending]);
47
- }
48
- getError() {
49
- for (const [_, { status, detail }] of Object.entries(this.results)) {
50
- if (status === PublishStatus.Failure) {
51
- return detail;
52
- }
53
- }
54
- if (this.isComplete()) {
55
- return "";
56
- }
57
- }
58
- waitForError() {
59
- return new Promise(resolve => {
60
- this.subscribe(thunk => {
61
- const error = thunk.getError();
62
- if (error !== undefined) {
63
- resolve(error);
64
- }
65
- });
66
- });
67
- }
68
- waitForCompletion() {
69
- return new Promise(resolve => {
70
- this.subscribe(thunk => {
71
- if (thunk.isComplete()) {
72
- resolve();
73
- }
74
- });
75
- });
76
- }
77
- }
78
- export class Thunk extends BaseThunk {
79
- options;
80
- complete = defer();
81
- controller = new AbortController();
82
- wrap;
83
- // The id of the copy in the repository, which pow re-hashes and an abort unwinds.
84
- initialId;
85
- constructor(options) {
86
- super();
87
- if (!options.recipient && WRAPPED_KINDS.includes(options.event.kind)) {
88
- throw new Error(`Attempted to publish a kind ${options.event.kind} without wrapping it`);
89
- }
90
- this.options = { ...options, event: prep(options.event, User.require(options.app).pubkey) };
91
- this.initialId = this.options.event.id;
92
- for (const relay of options.relays) {
93
- this.results[relay] = {
94
- relay,
95
- status: PublishStatus.Sending,
96
- detail: "sending...",
97
- };
98
- }
99
- this.controller.signal.addEventListener("abort", () => {
100
- for (const relay of options.relays) {
101
- this._setAborted({
102
- relay,
103
- status: PublishStatus.Aborted,
104
- detail: "aborted",
105
- });
106
- }
107
- });
108
- }
109
- get user() {
110
- return User.require(this.options.app);
111
- }
112
- _fail(detail) {
113
- for (const relay of this.options.relays) {
114
- this.results[relay] = {
115
- relay,
116
- status: PublishStatus.Failure,
117
- detail: detail,
118
- };
119
- }
120
- this._notify();
121
- }
122
- _setPending = (result) => {
123
- this.options.onPending?.(result);
124
- this.results[result.relay] = result;
125
- this._notify();
126
- };
127
- _setTimeout = (result) => {
128
- this.options.onTimeout?.(result);
129
- this.results[result.relay] = result;
130
- this._notify();
131
- };
132
- _setAborted = (result) => {
133
- this.options.onAborted?.(result);
134
- this.results[result.relay] = result;
135
- this._notify();
136
- };
137
- async _publish(event) {
138
- // Wait if the thunk is to be delayed
139
- if (this.options.delay) {
140
- await sleep(this.options.delay);
141
- }
142
- // Skip publishing if aborted
143
- if (this.controller.signal.aborted) {
144
- return;
145
- }
146
- // Send it off
147
- await this.options.app.use(Network).publish({
148
- ...this.options,
149
- event,
150
- onSuccess: (result) => {
151
- this.options.onSuccess?.(result);
152
- this.results[result.relay] = result;
153
- this._notify();
154
- },
155
- onFailure: (result) => {
156
- this.options.onFailure?.(result);
157
- this.results[result.relay] = result;
158
- this._notify();
159
- },
160
- onPending: this._setPending,
161
- onTimeout: this._setTimeout,
162
- onAborted: this._setAborted,
163
- onComplete: (result) => {
164
- if (result.status !== PublishStatus.Success) {
165
- this.options.app.tracker.removeRelay(event.id, result.relay);
166
- }
167
- this.options.onComplete?.(result);
168
- this._subs = [];
169
- },
170
- });
171
- // Notify the caller that we're done
172
- this.complete.resolve();
173
- }
174
- async publish() {
175
- // Handle abort immediately if possible
176
- if (this.controller.signal.aborted)
177
- return;
178
- const { recipient } = this.options;
179
- // If we're sending it privately, wrap the event using nip 59
180
- if (recipient) {
181
- const wrapper = Nip01Signer.ephemeral();
182
- const nip59 = new Nip59(this.user.signer, wrapper);
183
- this.wrap = await nip59.wrap(recipient, this.options.event);
184
- // If we're calculating pow, update the hash and re-sign
185
- if (this.options.pow) {
186
- this.wrap = await wrapper.sign(await makePow(this.wrap, this.options.pow).result, {
187
- signal: AbortSignal.timeout(30_000),
188
- });
189
- }
190
- // If we aborted during wrapping, signing, or pow, nevermind
191
- if (this.controller.signal.aborted) {
192
- return;
193
- }
194
- this.options.app.wrapManager.add({ recipient, wrap: this.wrap, rumor: this.options.event });
195
- return this._publish(this.wrap);
196
- }
197
- // If the event has been signed, we're good to go
198
- if (isSignedEvent(this.options.event)) {
199
- if (this.options.pow) {
200
- console.warn("Event is already signed, skipping proof of work calculation");
201
- }
202
- return this._publish(this.options.event);
203
- }
204
- // Allow for lazily signing/powing events in order to decrease apparent latency in the UI
205
- // that results from waiting for remote signers
206
- try {
207
- if (this.options.pow) {
208
- this.options.event = await makePow(this.options.event, this.options.pow).result;
209
- }
210
- const signedEvent = await this.user.sign(this.options.event, {
211
- signal: AbortSignal.timeout(30_000),
212
- });
213
- // Signing is slow enough to be aborted mid-flight; bail before writing the
214
- // signed event, since the abort handler has already unwound the unsigned one
215
- if (this.controller.signal.aborted) {
216
- return;
217
- }
218
- // Only pow changes the id, and only then is there an optimistic copy left to remove
219
- if (this.initialId !== signedEvent.id) {
220
- for (const url of this.options.relays) {
221
- this.options.app.tracker.removeRelay(this.initialId, url);
222
- this.options.app.tracker.track(signedEvent.id, url);
223
- }
224
- this.options.app.repository.removeEvent(this.initialId);
225
- }
226
- this.options.app.repository.publish(signedEvent);
227
- this.initialId = signedEvent.id;
228
- this.options.event = signedEvent;
229
- return this._publish(signedEvent);
230
- }
231
- catch (e) {
232
- console.error("Failed to sign event", e);
233
- return this._fail(String(e || "Failed to sign event"));
234
- }
235
- }
236
- abort() {
237
- this.controller.abort();
238
- }
239
- }
240
- export class MergedThunk extends BaseThunk {
241
- thunks;
242
- constructor(thunks) {
243
- super();
244
- this.thunks = thunks;
245
- const { Aborted, Failure, Timeout, Pending, Sending, Success } = PublishStatus;
246
- const relays = new Set(thunks.flatMap(thunk => thunk.options.relays));
247
- for (const thunk of thunks) {
248
- thunk.subscribe(() => {
249
- this.results = {};
250
- for (const relay of relays) {
251
- for (const status of [Aborted, Failure, Timeout, Pending, Sending, Success]) {
252
- const match = thunks.find(t => t.results[relay]?.status === status);
253
- if (match) {
254
- this.results[relay] = match.results[relay];
255
- }
256
- }
257
- }
258
- this._notify();
259
- if (thunks.every(t => t.isComplete())) {
260
- this._subs = [];
261
- }
262
- });
263
- }
264
- }
265
- abort() {
266
- this.thunks.forEach(thunk => thunk.abort());
267
- }
268
- }
269
- /**
270
- * Per-app thunk manager — the publish-side counterpart of `Network`. Owns
271
- * the app's optimistic-publish `history` store and the `queue` that paces
272
- * publishing. Reach it via `app.use(Thunks)`; `publish` fills in the app
273
- * (the acting user is derived from it), enqueues the thunk (optimistically
274
- * writing it to the repository), and returns it.
275
- */
276
- export class Thunks {
277
- app;
278
- history = writable([]);
279
- queue = new TaskQueue({
280
- batchSize: 10,
281
- batchDelay: 100,
282
- processItem: (thunk) => {
283
- thunk.publish();
284
- },
285
- });
286
- constructor(app) {
287
- this.app = app;
288
- app.onCleanup(() => {
289
- this.queue.clear();
290
- // Anything still in flight would go on publishing after teardown, opening
291
- // sockets in the cleared pool and writing its event back into the cleared
292
- // repository. Aborting also unwinds each thunk's optimistic write.
293
- for (const thunk of get(this.history)) {
294
- if (!thunk.isComplete()) {
295
- thunk.abort();
296
- }
297
- }
298
- });
299
- }
300
- enqueue(thunk) {
301
- this.queue.push(thunk);
302
- for (const url of thunk.options.relays) {
303
- this.app.tracker.track(thunk.initialId, url);
304
- }
305
- this.app.repository.publish(thunk.options.event);
306
- this.history.update($history => append(thunk, $history));
307
- thunk.controller.signal.addEventListener("abort", () => {
308
- // wrapManager.remove may not have registered the wrap yet if abort races it.
309
- if (thunk.wrap) {
310
- this.app.wrapManager.remove(thunk.wrap.id);
311
- }
312
- this.app.repository.removeEvent(thunk.initialId);
313
- this.history.update($history => remove(thunk, $history));
314
- });
315
- }
316
- publish = (options) => {
317
- const thunk = new Thunk({ ...options, app: this.app });
318
- this.enqueue(thunk);
319
- return thunk;
320
- };
321
- // Pass `relays` to republish only to those of the thunk's relays, e.g. the ones that failed.
322
- // A merged thunk then retries only the children that published to them.
323
- retry = (thunk, relays) => {
324
- const targets = (t) => relays ? t.options.relays.filter(url => relays.includes(url)) : t.options.relays;
325
- const republish = (t) => this.publish({ ...t.options, relays: targets(t) });
326
- return thunk instanceof MergedThunk
327
- ? new MergedThunk(thunk.thunks.filter(t => targets(t).length > 0).map(republish))
328
- : republish(thunk);
329
- };
330
- merge(thunks) {
331
- return new MergedThunk(Array.from(this.flatten(thunks)));
332
- }
333
- *flatten(thunks) {
334
- for (const thunk of thunks) {
335
- if (thunk instanceof MergedThunk) {
336
- yield* this.flatten(thunk.thunks);
337
- }
338
- else if (thunk instanceof Thunk) {
339
- yield thunk;
340
- }
341
- }
342
- }
343
- }
344
- //# sourceMappingURL=thunk.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"thunk.js","sourceRoot":"","sources":["../../../../src/plugins/thunk.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