@welshman/app 0.0.17 → 0.0.18
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/build/src/thunk.cjs +68 -37
- package/build/src/thunk.cjs.map +1 -1
- package/build/src/thunk.d.ts +13 -1
- package/build/src/thunk.mjs +68 -38
- package/build/src/thunk.mjs.map +1 -1
- package/package.json +5 -5
package/build/src/thunk.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.thunkWorker = exports.publishThunk = exports.makeThunk = exports.prepEvent = void 0;
|
|
3
|
+
exports.thunkWorker = exports.publishThunk = exports.mergeThunks = exports.makeThunk = exports.prepEvent = void 0;
|
|
4
4
|
const store_1 = require("svelte/store");
|
|
5
5
|
const lib_1 = require("@welshman/lib");
|
|
6
6
|
const signer_1 = require("@welshman/signer");
|
|
@@ -8,6 +8,7 @@ const util_1 = require("@welshman/util");
|
|
|
8
8
|
const net_1 = require("@welshman/net");
|
|
9
9
|
const core_1 = require("./core.cjs");
|
|
10
10
|
const session_1 = require("./session.cjs");
|
|
11
|
+
const { Pending, Success, Failure, Timeout, Aborted } = net_1.PublishStatus;
|
|
11
12
|
const prepEvent = (event) => {
|
|
12
13
|
if (!(0, util_1.isStampedEvent)(event)) {
|
|
13
14
|
event = (0, signer_1.stamp)(event);
|
|
@@ -29,6 +30,33 @@ const makeThunk = (request) => {
|
|
|
29
30
|
return { event, request, controller, result, status };
|
|
30
31
|
};
|
|
31
32
|
exports.makeThunk = makeThunk;
|
|
33
|
+
const mergeThunks = (thunks) => {
|
|
34
|
+
const controller = new AbortController();
|
|
35
|
+
controller.signal.addEventListener('abort', () => {
|
|
36
|
+
for (const thunk of thunks) {
|
|
37
|
+
thunk.controller.abort();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
thunks,
|
|
42
|
+
controller,
|
|
43
|
+
result: Promise.all(thunks.map(thunk => thunk.result)),
|
|
44
|
+
status: (0, store_1.derived)(thunks.map(thunk => thunk.status), statuses => {
|
|
45
|
+
const mergedStatus = {};
|
|
46
|
+
for (const url of (0, lib_1.uniq)(statuses.flatMap(s => Object.keys(s)))) {
|
|
47
|
+
const urlStatuses = statuses.map(s => s[url]);
|
|
48
|
+
const thunkStatus = [Aborted, Failure, Timeout, Pending, Success]
|
|
49
|
+
.map(status => urlStatuses.find(s => (s === null || s === void 0 ? void 0 : s.status) === status))
|
|
50
|
+
.find(lib_1.identity);
|
|
51
|
+
if (thunkStatus) {
|
|
52
|
+
mergedStatus[url] = thunkStatus;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return mergedStatus;
|
|
56
|
+
})
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
exports.mergeThunks = mergeThunks;
|
|
32
60
|
const publishThunk = (request) => {
|
|
33
61
|
const thunk = (0, exports.makeThunk)(request);
|
|
34
62
|
exports.thunkWorker.push(thunk);
|
|
@@ -40,7 +68,7 @@ const publishThunk = (request) => {
|
|
|
40
68
|
};
|
|
41
69
|
exports.publishThunk = publishThunk;
|
|
42
70
|
exports.thunkWorker = new lib_1.Worker();
|
|
43
|
-
exports.thunkWorker.addGlobalHandler(
|
|
71
|
+
exports.thunkWorker.addGlobalHandler((thunk) => {
|
|
44
72
|
let event = thunk.event;
|
|
45
73
|
// Handle abort immediately if possible
|
|
46
74
|
if (thunk.controller.signal.aborted)
|
|
@@ -49,45 +77,48 @@ exports.thunkWorker.addGlobalHandler(async (thunk) => {
|
|
|
49
77
|
if ((0, util_1.isUnwrappedEvent)(event)) {
|
|
50
78
|
event = event.wrap;
|
|
51
79
|
}
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (!
|
|
57
|
-
|
|
80
|
+
// Avoid making this function async so multiple publishes can run concurrently
|
|
81
|
+
Promise.resolve().then(async () => {
|
|
82
|
+
// If the event was already signed, leave it alone. Otherwise, sign it now. This is to
|
|
83
|
+
// decrease apparent latency in the UI that results from waiting for remote signers
|
|
84
|
+
if (!(0, util_1.isSignedEvent)(event)) {
|
|
85
|
+
const signer = (0, session_1.getSigner)((0, session_1.getSession)(event.pubkey));
|
|
86
|
+
if (!signer) {
|
|
87
|
+
return console.warn(`No signer found for ${event.pubkey}`);
|
|
88
|
+
}
|
|
89
|
+
event = await signer.sign(event);
|
|
58
90
|
}
|
|
59
|
-
event
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (thunk.request.delay) {
|
|
65
|
-
await (0, lib_1.sleep)(thunk.request.delay);
|
|
66
|
-
}
|
|
67
|
-
// Skip publishing if aborted
|
|
68
|
-
if (thunk.controller.signal.aborted) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
// Send it off
|
|
72
|
-
const pub = (0, net_1.publish)({ event: signedEvent, relays: thunk.request.relays });
|
|
73
|
-
// Copy the signature over since we had deferred it
|
|
74
|
-
const savedEvent = core_1.repository.getEvent(signedEvent.id);
|
|
75
|
-
// The event may already be replaced or deleted
|
|
76
|
-
if (savedEvent) {
|
|
77
|
-
savedEvent.sig = signedEvent.sig;
|
|
78
|
-
}
|
|
79
|
-
const completed = new Set();
|
|
80
|
-
pub.emitter.on("*", async (status, url, message) => {
|
|
81
|
-
thunk.status.update((0, lib_1.assoc)(url, { status, message }));
|
|
82
|
-
if (status !== net_1.PublishStatus.Pending) {
|
|
83
|
-
completed.add(url);
|
|
91
|
+
// We're guaranteed to have a signed event at this point
|
|
92
|
+
const signedEvent = event;
|
|
93
|
+
// Wait if the thunk is to be delayed
|
|
94
|
+
if (thunk.request.delay) {
|
|
95
|
+
await (0, lib_1.sleep)(thunk.request.delay);
|
|
84
96
|
}
|
|
85
|
-
|
|
86
|
-
|
|
97
|
+
// Skip publishing if aborted
|
|
98
|
+
if (thunk.controller.signal.aborted) {
|
|
99
|
+
return;
|
|
87
100
|
}
|
|
88
|
-
|
|
89
|
-
|
|
101
|
+
// Send it off
|
|
102
|
+
const pub = (0, net_1.publish)({ event: signedEvent, relays: thunk.request.relays });
|
|
103
|
+
// Copy the signature over since we had deferred it
|
|
104
|
+
const savedEvent = core_1.repository.getEvent(signedEvent.id);
|
|
105
|
+
// The event may already be replaced or deleted
|
|
106
|
+
if (savedEvent) {
|
|
107
|
+
savedEvent.sig = signedEvent.sig;
|
|
90
108
|
}
|
|
109
|
+
const completed = new Set();
|
|
110
|
+
pub.emitter.on("*", async (status, url, message = "") => {
|
|
111
|
+
thunk.status.update((0, lib_1.assoc)(url, { status, message }));
|
|
112
|
+
if (status !== net_1.PublishStatus.Pending) {
|
|
113
|
+
completed.add(url);
|
|
114
|
+
}
|
|
115
|
+
if (status === net_1.PublishStatus.Success) {
|
|
116
|
+
core_1.tracker.track(signedEvent.id, url);
|
|
117
|
+
}
|
|
118
|
+
if (completed.size === thunk.request.relays.length) {
|
|
119
|
+
thunk.result.resolve((0, store_1.get)(thunk.status));
|
|
120
|
+
}
|
|
121
|
+
});
|
|
91
122
|
});
|
|
92
123
|
});
|
|
93
124
|
//# sourceMappingURL=thunk.cjs.map
|
package/build/src/thunk.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thunk.cjs","sourceRoot":"","sources":["../../src/thunk.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"thunk.cjs","sourceRoot":"","sources":["../../src/thunk.ts"],"names":[],"mappings":";;;AAAA,wCAAmD;AAEnD,uCAAyE;AAEzE,6CAAiD;AAEjD,yCAA2G;AAC3G,uCAAoD;AACpD,qCAA0C;AAC1C,2CAAuD;AAEvD,MAAM,EAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAC,GAAG,mBAAa,CAAA;AAyB5D,MAAM,SAAS,GAAG,CAAC,KAAiB,EAAE,EAAE;IAC7C,IAAI,CAAC,IAAA,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|
|
|
1
1
|
/// <reference types="svelte" />
|
|
2
|
-
import type { Writable } from 'svelte/store';
|
|
2
|
+
import type { Writable, Readable } from 'svelte/store';
|
|
3
3
|
import { Worker } from '@welshman/lib';
|
|
4
4
|
import type { Deferred } from '@welshman/lib';
|
|
5
5
|
import type { TrustedEvent, EventTemplate, StampedEvent, OwnedEvent } from '@welshman/util';
|
|
@@ -30,6 +30,18 @@ export declare const makeThunk: (request: ThunkRequest) => {
|
|
|
30
30
|
result: Deferred<ThunkStatusByUrl>;
|
|
31
31
|
status: Writable<ThunkStatusByUrl>;
|
|
32
32
|
};
|
|
33
|
+
export type MergedThunk = {
|
|
34
|
+
thunks: Thunk[];
|
|
35
|
+
controller: AbortController;
|
|
36
|
+
result: Promise<ThunkStatusByUrl[]>;
|
|
37
|
+
status: Readable<ThunkStatusByUrl>;
|
|
38
|
+
};
|
|
39
|
+
export declare const mergeThunks: (thunks: Thunk[]) => {
|
|
40
|
+
thunks: Thunk[];
|
|
41
|
+
controller: AbortController;
|
|
42
|
+
result: Promise<ThunkStatusByUrl[]>;
|
|
43
|
+
status: Readable<ThunkStatusByUrl>;
|
|
44
|
+
};
|
|
33
45
|
export declare const publishThunk: (request: ThunkRequest) => {
|
|
34
46
|
event: TrustedEvent;
|
|
35
47
|
request: ThunkRequest;
|
package/build/src/thunk.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { writable, get } from 'svelte/store';
|
|
2
|
-
import { Worker, defer, sleep, assoc } from '@welshman/lib';
|
|
1
|
+
import { writable, derived, get } from 'svelte/store';
|
|
2
|
+
import { Worker, identity, uniq, defer, sleep, assoc } from '@welshman/lib';
|
|
3
3
|
import { stamp, own, hash } from "@welshman/signer";
|
|
4
4
|
import { isStampedEvent, isOwnedEvent, isHashedEvent, isUnwrappedEvent, isSignedEvent } from '@welshman/util';
|
|
5
5
|
import { publish, PublishStatus } from "@welshman/net";
|
|
6
6
|
import { repository, tracker } from "./core.mjs";
|
|
7
7
|
import { pubkey, getSession, getSigner } from "./session.mjs";
|
|
8
|
+
const { Pending, Success, Failure, Timeout, Aborted } = PublishStatus;
|
|
8
9
|
export const prepEvent = (event) => {
|
|
9
10
|
if (!isStampedEvent(event)) {
|
|
10
11
|
event = stamp(event);
|
|
@@ -24,6 +25,32 @@ export const makeThunk = (request) => {
|
|
|
24
25
|
const status = writable({});
|
|
25
26
|
return { event, request, controller, result, status };
|
|
26
27
|
};
|
|
28
|
+
export const mergeThunks = (thunks) => {
|
|
29
|
+
const controller = new AbortController();
|
|
30
|
+
controller.signal.addEventListener('abort', () => {
|
|
31
|
+
for (const thunk of thunks) {
|
|
32
|
+
thunk.controller.abort();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
thunks,
|
|
37
|
+
controller,
|
|
38
|
+
result: Promise.all(thunks.map(thunk => thunk.result)),
|
|
39
|
+
status: derived(thunks.map(thunk => thunk.status), statuses => {
|
|
40
|
+
const mergedStatus = {};
|
|
41
|
+
for (const url of uniq(statuses.flatMap(s => Object.keys(s)))) {
|
|
42
|
+
const urlStatuses = statuses.map(s => s[url]);
|
|
43
|
+
const thunkStatus = [Aborted, Failure, Timeout, Pending, Success]
|
|
44
|
+
.map(status => urlStatuses.find(s => (s === null || s === void 0 ? void 0 : s.status) === status))
|
|
45
|
+
.find(identity);
|
|
46
|
+
if (thunkStatus) {
|
|
47
|
+
mergedStatus[url] = thunkStatus;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return mergedStatus;
|
|
51
|
+
})
|
|
52
|
+
};
|
|
53
|
+
};
|
|
27
54
|
export const publishThunk = (request) => {
|
|
28
55
|
const thunk = makeThunk(request);
|
|
29
56
|
thunkWorker.push(thunk);
|
|
@@ -34,7 +61,7 @@ export const publishThunk = (request) => {
|
|
|
34
61
|
return thunk;
|
|
35
62
|
};
|
|
36
63
|
export const thunkWorker = new Worker();
|
|
37
|
-
thunkWorker.addGlobalHandler(
|
|
64
|
+
thunkWorker.addGlobalHandler((thunk) => {
|
|
38
65
|
let event = thunk.event;
|
|
39
66
|
// Handle abort immediately if possible
|
|
40
67
|
if (thunk.controller.signal.aborted)
|
|
@@ -43,45 +70,48 @@ thunkWorker.addGlobalHandler(async (thunk) => {
|
|
|
43
70
|
if (isUnwrappedEvent(event)) {
|
|
44
71
|
event = event.wrap;
|
|
45
72
|
}
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (!
|
|
51
|
-
|
|
73
|
+
// Avoid making this function async so multiple publishes can run concurrently
|
|
74
|
+
Promise.resolve().then(async () => {
|
|
75
|
+
// If the event was already signed, leave it alone. Otherwise, sign it now. This is to
|
|
76
|
+
// decrease apparent latency in the UI that results from waiting for remote signers
|
|
77
|
+
if (!isSignedEvent(event)) {
|
|
78
|
+
const signer = getSigner(getSession(event.pubkey));
|
|
79
|
+
if (!signer) {
|
|
80
|
+
return console.warn(`No signer found for ${event.pubkey}`);
|
|
81
|
+
}
|
|
82
|
+
event = await signer.sign(event);
|
|
52
83
|
}
|
|
53
|
-
event
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (thunk.request.delay) {
|
|
59
|
-
await sleep(thunk.request.delay);
|
|
60
|
-
}
|
|
61
|
-
// Skip publishing if aborted
|
|
62
|
-
if (thunk.controller.signal.aborted) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
// Send it off
|
|
66
|
-
const pub = publish({ event: signedEvent, relays: thunk.request.relays });
|
|
67
|
-
// Copy the signature over since we had deferred it
|
|
68
|
-
const savedEvent = repository.getEvent(signedEvent.id);
|
|
69
|
-
// The event may already be replaced or deleted
|
|
70
|
-
if (savedEvent) {
|
|
71
|
-
savedEvent.sig = signedEvent.sig;
|
|
72
|
-
}
|
|
73
|
-
const completed = new Set();
|
|
74
|
-
pub.emitter.on("*", async (status, url, message) => {
|
|
75
|
-
thunk.status.update(assoc(url, { status, message }));
|
|
76
|
-
if (status !== PublishStatus.Pending) {
|
|
77
|
-
completed.add(url);
|
|
84
|
+
// We're guaranteed to have a signed event at this point
|
|
85
|
+
const signedEvent = event;
|
|
86
|
+
// Wait if the thunk is to be delayed
|
|
87
|
+
if (thunk.request.delay) {
|
|
88
|
+
await sleep(thunk.request.delay);
|
|
78
89
|
}
|
|
79
|
-
|
|
80
|
-
|
|
90
|
+
// Skip publishing if aborted
|
|
91
|
+
if (thunk.controller.signal.aborted) {
|
|
92
|
+
return;
|
|
81
93
|
}
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
// Send it off
|
|
95
|
+
const pub = publish({ event: signedEvent, relays: thunk.request.relays });
|
|
96
|
+
// Copy the signature over since we had deferred it
|
|
97
|
+
const savedEvent = repository.getEvent(signedEvent.id);
|
|
98
|
+
// The event may already be replaced or deleted
|
|
99
|
+
if (savedEvent) {
|
|
100
|
+
savedEvent.sig = signedEvent.sig;
|
|
84
101
|
}
|
|
102
|
+
const completed = new Set();
|
|
103
|
+
pub.emitter.on("*", async (status, url, message = "") => {
|
|
104
|
+
thunk.status.update(assoc(url, { status, message }));
|
|
105
|
+
if (status !== PublishStatus.Pending) {
|
|
106
|
+
completed.add(url);
|
|
107
|
+
}
|
|
108
|
+
if (status === PublishStatus.Success) {
|
|
109
|
+
tracker.track(signedEvent.id, url);
|
|
110
|
+
}
|
|
111
|
+
if (completed.size === thunk.request.relays.length) {
|
|
112
|
+
thunk.result.resolve(get(thunk.status));
|
|
113
|
+
}
|
|
114
|
+
});
|
|
85
115
|
});
|
|
86
116
|
});
|
|
87
117
|
//# sourceMappingURL=thunk.mjs.map
|
package/build/src/thunk.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thunk.mjs","sourceRoot":"","sources":["../../src/thunk.ts"],"names":[],"mappings":"OAAO,EAAC,QAAQ,EAAE,GAAG,EAAC,MAAM,cAAc;
|
|
1
|
+
{"version":3,"file":"thunk.mjs","sourceRoot":"","sources":["../../src/thun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AAC,CAAA;aACnB;YAED,IAAI,MAAM,KAAK,aAAa,CAAC,OAAO,EAAE;gBACpC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;aACnC;YAED,IAAI,SAAS,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE;gBAClD,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;aACxC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@welshman/app",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"author": "hodlbod",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A collection of svelte stores for use in building nostr client applications.",
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
"typescript": "~5.1.6"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@welshman/lib": "~0.0.
|
|
34
|
+
"@welshman/lib": "~0.0.23",
|
|
35
35
|
"@welshman/feeds": "~0.0.20",
|
|
36
36
|
"@welshman/dvm": "~0.0.10",
|
|
37
|
-
"@welshman/net": "~0.0.
|
|
37
|
+
"@welshman/net": "~0.0.29",
|
|
38
38
|
"@welshman/signer": "~0.0.9",
|
|
39
|
-
"@welshman/store": "~0.0.
|
|
40
|
-
"@welshman/util": "~0.0.
|
|
39
|
+
"@welshman/store": "~0.0.11",
|
|
40
|
+
"@welshman/util": "~0.0.40",
|
|
41
41
|
"fuse.js": "^7.0.0",
|
|
42
42
|
"idb": "^8.0.0",
|
|
43
43
|
"svelte": "^4.2.18",
|