@welshman/app 0.0.16 → 0.0.17
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/commands.d.ts +29 -4
- package/build/src/context.cjs +0 -1
- package/build/src/context.cjs.map +1 -1
- package/build/src/context.d.ts +1 -1
- package/build/src/context.mjs +2 -3
- package/build/src/context.mjs.map +1 -1
- package/build/src/thunk.cjs +57 -35
- package/build/src/thunk.cjs.map +1 -1
- package/build/src/thunk.d.ts +29 -15
- package/build/src/thunk.mjs +54 -33
- package/build/src/thunk.mjs.map +1 -1
- package/package.json +4 -4
package/build/src/commands.d.ts
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
export declare const unfollow: (value: string) => Promise<{
|
|
3
|
+
event: import("@welshman/util").TrustedEvent;
|
|
4
|
+
request: import("./thunk").ThunkRequest;
|
|
5
|
+
controller: AbortController;
|
|
6
|
+
result: import("@welshman/lib").Deferred<import("./thunk").ThunkStatusByUrl>;
|
|
7
|
+
status: import("svelte/store").Writable<import("./thunk").ThunkStatusByUrl>;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const follow: (tag: string[]) => Promise<{
|
|
10
|
+
event: import("@welshman/util").TrustedEvent;
|
|
11
|
+
request: import("./thunk").ThunkRequest;
|
|
12
|
+
controller: AbortController;
|
|
13
|
+
result: import("@welshman/lib").Deferred<import("./thunk").ThunkStatusByUrl>;
|
|
14
|
+
status: import("svelte/store").Writable<import("./thunk").ThunkStatusByUrl>;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const unmute: (value: string) => Promise<{
|
|
17
|
+
event: import("@welshman/util").TrustedEvent;
|
|
18
|
+
request: import("./thunk").ThunkRequest;
|
|
19
|
+
controller: AbortController;
|
|
20
|
+
result: import("@welshman/lib").Deferred<import("./thunk").ThunkStatusByUrl>;
|
|
21
|
+
status: import("svelte/store").Writable<import("./thunk").ThunkStatusByUrl>;
|
|
22
|
+
}>;
|
|
23
|
+
export declare const mute: (tag: string[]) => Promise<{
|
|
24
|
+
event: import("@welshman/util").TrustedEvent;
|
|
25
|
+
request: import("./thunk").ThunkRequest;
|
|
26
|
+
controller: AbortController;
|
|
27
|
+
result: import("@welshman/lib").Deferred<import("./thunk").ThunkStatusByUrl>;
|
|
28
|
+
status: import("svelte/store").Writable<import("./thunk").ThunkStatusByUrl>;
|
|
29
|
+
}>;
|
package/build/src/context.cjs
CHANGED
|
@@ -20,7 +20,6 @@ const getDefaultNetContext = (overrides = {}) => ({
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
isDeleted: (url, event) => core_1.repository.isDeleted(event),
|
|
23
|
-
isValid: (url, event) => (0, session_1.getSession)(event.pubkey) || ((0, util_1.isSignedEvent)(event) && (0, util_1.hasValidSignature)(event)),
|
|
24
23
|
optimizeSubscriptions: (subs) => {
|
|
25
24
|
const [withRelays, withoutRelays] = (0, lib_1.partition)(sub => sub.request.relays.length > 0, subs);
|
|
26
25
|
const filters = (0, util_1.unionFilters)(withoutRelays.flatMap(sub => sub.request.filters));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.cjs","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,uCAAgH;AAEhH,
|
|
1
|
+
{"version":3,"file":"context.cjs","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,uCAAgH;AAEhH,yCAAiD;AAEjD,qCAA0C;AAC1C,yCAAwD;AACxD,2CAAgC;AAEhC,6CAAsC;AAW/B,MAAM,oBAAoB,GAAG,CAAC,YAAiC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5E,GAAG,IAAA,0BAA4B,GAAE;IACjC,SAAS,EAAE,CAAC,KAAmB,EAAE,EAAE,WAAC,OAAA,MAAA,gBAAM,CAAC,GAAG,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C;IAC5E,MAAM,EAAE,IAAA,mBAAU,GAAE;IACpB,YAAY,EAAE,EAAE;IAChB,WAAW,EAAE,GAAG;IAChB,cAAc,EAAE,IAAI;IACpB,GAAG,SAAS;CACb,CAAC,CAAA;AANW,QAAA,oBAAoB,wBAM/B"}
|
package/build/src/context.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare const getDefaultNetContext: (overrides?: Partial<NetContext>) =>
|
|
|
16
16
|
signEvent: (event: StampedEvent) => Promise<any> | undefined;
|
|
17
17
|
getExecutor: (relays: string[]) => import("@welshman/net").Executor;
|
|
18
18
|
isDeleted: (url: string, event: TrustedEvent) => boolean;
|
|
19
|
-
isValid: (
|
|
19
|
+
isValid: (url: string, event: TrustedEvent) => boolean;
|
|
20
20
|
matchFilters: (url: string, filters: import("@welshman/util").Filter[], event: TrustedEvent) => boolean;
|
|
21
21
|
optimizeSubscriptions: (subs: Subscription[]) => RelaysAndFilters[];
|
|
22
22
|
};
|
package/build/src/context.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { partition } from "@welshman/lib";
|
|
2
2
|
import { defaultOptimizeSubscriptions, getDefaultNetContext as originalGetDefaultNetContext } from "@welshman/net";
|
|
3
|
-
import { WRAP, unionFilters
|
|
3
|
+
import { WRAP, unionFilters } from "@welshman/util";
|
|
4
4
|
import { tracker, repository } from "./core.mjs";
|
|
5
5
|
import { makeRouter, getFilterSelections } from "./router.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { signer } from "./session.mjs";
|
|
7
7
|
import { loadProfile } from "./profiles.mjs";
|
|
8
8
|
export const getDefaultNetContext = (overrides = {}) => ({
|
|
9
9
|
...originalGetDefaultNetContext(),
|
|
@@ -17,7 +17,6 @@ export const getDefaultNetContext = (overrides = {}) => ({
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
isDeleted: (url, event) => repository.isDeleted(event),
|
|
20
|
-
isValid: (url, event) => getSession(event.pubkey) || (isSignedEvent(event) && hasValidSignature(event)),
|
|
21
20
|
optimizeSubscriptions: (subs) => {
|
|
22
21
|
const [withRelays, withoutRelays] = partition(sub => sub.request.relays.length > 0, subs);
|
|
23
22
|
const filters = unionFilters(withoutRelays.flatMap(sub => sub.request.filters));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.mjs","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"OAAO,EAAC,SAAS,EAAC,MAAM,eAAe;OAChC,EAAC,4BAA4B,EAAE,oBAAoB,IAAI,4BAA4B,EAAC,MAAM,eAAe;OAEzG,EAAC,IAAI,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"context.mjs","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"OAAO,EAAC,SAAS,EAAC,MAAM,eAAe;OAChC,EAAC,4BAA4B,EAAE,oBAAoB,IAAI,4BAA4B,EAAC,MAAM,eAAe;OAEzG,EAAC,IAAI,EAAE,YAAY,EAAC,MAAM,gBAAgB;OAE1C,EAAC,OAAO,EAAE,UAAU,EAAC;OACrB,EAAC,UAAU,EAAE,mBAAmB,EAAC;OACjC,EAAC,MAAM,EAAC;OAER,EAAC,WAAW,EAAC;AAWpB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,YAAiC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5E,GAAG,4BAA4B,EAAE;IACjC,SAAS,EAAE,CAAC,KAAmB,EAAE,EAAE,WAAC,OAAA,MAAA,MAAM,CAAC,GAAG,EAAE,0CAAE,IAAI,CAAC,KAAK,CAAC,CAAA,EAAA;IAC7D,OAAO,EAAE,CAAC,GAAW,EAAE,KAAmB,EAAE,EAAE;QAC5C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;QAC5B,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAEzB,qDAAqD;QACrD,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,EAAE;YACvB,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;SAC1B;IACH,CAAC;IACD,SAAS,EAAE,CAAC,GAAW,EAAE,KAAmB,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC;IAC5E,qBAAqB,EAAE,CAAC,IAAoB,EAAE,EAAE;QAC9C,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,CAAA;QACzF,MAAM,OAAO,GAAG,YAAY,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;QAC/E,MAAM,UAAU,GAAuB,4BAA4B,CAAC,UAAU,CAAC,CAAA;QAE/E,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;YACtB,KAAK,MAAM,SAAS,IAAK,mBAAmB,CAAC,OAAO,CAAC,EAAE;gBACrD,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;aAC3B;SACF;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;IACD,GAAG,SAAS;CACb,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,YAAiC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5E,MAAM,EAAE,UAAU,EAAE;IACpB,YAAY,EAAE,EAAE;IAChB,WAAW,EAAE,GAAG;IAChB,cAAc,EAAE,IAAI;IACpB,GAAG,SAAS;CACb,CAAC,CAAA"}
|
package/build/src/thunk.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.thunkWorker = exports.publishThunk = 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,9 +8,43 @@ 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
|
-
|
|
11
|
+
const prepEvent = (event) => {
|
|
12
|
+
if (!(0, util_1.isStampedEvent)(event)) {
|
|
13
|
+
event = (0, signer_1.stamp)(event);
|
|
14
|
+
}
|
|
15
|
+
if (!(0, util_1.isOwnedEvent)(event)) {
|
|
16
|
+
event = (0, signer_1.own)(event, (0, store_1.get)(session_1.pubkey));
|
|
17
|
+
}
|
|
18
|
+
if (!(0, util_1.isHashedEvent)(event)) {
|
|
19
|
+
event = (0, signer_1.hash)(event);
|
|
20
|
+
}
|
|
21
|
+
return event;
|
|
22
|
+
};
|
|
23
|
+
exports.prepEvent = prepEvent;
|
|
24
|
+
const makeThunk = (request) => {
|
|
25
|
+
const event = (0, exports.prepEvent)(request.event);
|
|
26
|
+
const controller = new AbortController();
|
|
27
|
+
const result = (0, lib_1.defer)();
|
|
28
|
+
const status = (0, store_1.writable)({});
|
|
29
|
+
return { event, request, controller, result, status };
|
|
30
|
+
};
|
|
31
|
+
exports.makeThunk = makeThunk;
|
|
32
|
+
const publishThunk = (request) => {
|
|
33
|
+
const thunk = (0, exports.makeThunk)(request);
|
|
34
|
+
exports.thunkWorker.push(thunk);
|
|
35
|
+
core_1.repository.publish(thunk.event);
|
|
36
|
+
thunk.controller.signal.addEventListener('abort', () => {
|
|
37
|
+
core_1.repository.removeEvent(thunk.event.id);
|
|
38
|
+
});
|
|
39
|
+
return thunk;
|
|
40
|
+
};
|
|
41
|
+
exports.publishThunk = publishThunk;
|
|
12
42
|
exports.thunkWorker = new lib_1.Worker();
|
|
13
|
-
exports.thunkWorker.addGlobalHandler(async (
|
|
43
|
+
exports.thunkWorker.addGlobalHandler(async (thunk) => {
|
|
44
|
+
let event = thunk.event;
|
|
45
|
+
// Handle abort immediately if possible
|
|
46
|
+
if (thunk.controller.signal.aborted)
|
|
47
|
+
return;
|
|
14
48
|
// If we were given a wrapped event, make sure to publish the wrapper, not the rumor
|
|
15
49
|
if ((0, util_1.isUnwrappedEvent)(event)) {
|
|
16
50
|
event = event.wrap;
|
|
@@ -26,46 +60,34 @@ exports.thunkWorker.addGlobalHandler(async ({ event, relays, resolve }) => {
|
|
|
26
60
|
}
|
|
27
61
|
// We're guaranteed to have a signed event at this point
|
|
28
62
|
const signedEvent = event;
|
|
29
|
-
|
|
63
|
+
// Wait if the thunk is to be delayed
|
|
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
|
+
}
|
|
30
71
|
// Send it off
|
|
31
|
-
const pub = (0, net_1.publish)({ event: signedEvent, relays });
|
|
72
|
+
const pub = (0, net_1.publish)({ event: signedEvent, relays: thunk.request.relays });
|
|
32
73
|
// Copy the signature over since we had deferred it
|
|
33
|
-
const savedEvent = core_1.repository.getEvent(id);
|
|
74
|
+
const savedEvent = core_1.repository.getEvent(signedEvent.id);
|
|
34
75
|
// The event may already be replaced or deleted
|
|
35
76
|
if (savedEvent) {
|
|
36
|
-
savedEvent.sig = sig;
|
|
77
|
+
savedEvent.sig = signedEvent.sig;
|
|
37
78
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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);
|
|
84
|
+
}
|
|
43
85
|
if (status === net_1.PublishStatus.Success) {
|
|
44
|
-
core_1.tracker.track(id, url);
|
|
86
|
+
core_1.tracker.track(signedEvent.id, url);
|
|
45
87
|
}
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
resolve(statusByUrl);
|
|
88
|
+
if (completed.size === thunk.request.relays.length) {
|
|
89
|
+
thunk.result.resolve((0, store_1.get)(thunk.status));
|
|
49
90
|
}
|
|
50
91
|
});
|
|
51
92
|
});
|
|
52
|
-
const prepEvent = (event) => {
|
|
53
|
-
if (!(0, util_1.isStampedEvent)(event)) {
|
|
54
|
-
event = (0, signer_1.stamp)(event);
|
|
55
|
-
}
|
|
56
|
-
if (!(0, util_1.isOwnedEvent)(event)) {
|
|
57
|
-
event = (0, signer_1.own)(event, (0, store_1.get)(session_1.pubkey));
|
|
58
|
-
}
|
|
59
|
-
if (!(0, util_1.isHashedEvent)(event)) {
|
|
60
|
-
event = (0, signer_1.hash)(event);
|
|
61
|
-
}
|
|
62
|
-
return event;
|
|
63
|
-
};
|
|
64
|
-
exports.prepEvent = prepEvent;
|
|
65
|
-
const publishThunk = (params) => new Promise(resolve => {
|
|
66
|
-
const event = (0, exports.prepEvent)(params.event);
|
|
67
|
-
exports.thunkWorker.push({ ...params, event, resolve });
|
|
68
|
-
core_1.repository.publish(event);
|
|
69
|
-
});
|
|
70
|
-
exports.publishThunk = publishThunk;
|
|
71
93
|
//# 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,wCAA0C;
|
|
1
|
+
{"version":3,"file":"thunk.cjs","sourceRoot":"","sources":["../../src/thunk.ts"],"names":[],"mappings":";;;AAAA,wCAA0C;AAE1C,uCAAyD;AAEzD,6CAAiD;AAEjD,yCAA2G;AAC3G,uCAAoD;AACpD,qCAA0C;AAC1C,2CAAuD;AAyBhD,MAAM,SAAS,GAAG,CAAC,KAAiB,EAAE,EA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AO,CAAC,MAAM,EAAC,CAAC,CAAA;IAEvE,mDAAmD;IACnD,MAAM,UAAU,GAAG,iBAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAgB,CAAA;IAErE,+CAA+C;IAC/C,IAAI,UAAU,EAAE;QACd,UAAU,CAAC,GAAG,GAAG,WAAW,CAAC,GAAG,CAAA;KACjC;IAED,MAAM,SAAS,GAAG,IAAI,GAAG,EAAE,CAAA;IAE3B,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,MAAqB,EAAE,GAAW,EAAE,OAAe,EAAE,EAAE;QAChF,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,IAAA,WAAK,EAAC,GAAG,EAAE,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC,CAAC,CAAA;QAElD,IAAI,MAAM,KAAK,mBAAa,CAAC,OAAO,EAAE;YACpC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;SACnB;QAED,IAAI,MAAM,KAAK,mBAAa,CAAC,OAAO,EAAE;YACpC,cAAO,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;SACnC;QAED,IAAI,SAAS,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE;YAClD,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAA,WAAG,EAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;SACxC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/build/src/thunk.d.ts
CHANGED
|
@@ -1,26 +1,40 @@
|
|
|
1
1
|
/// <reference types="svelte" />
|
|
2
|
+
import type { Writable } from 'svelte/store';
|
|
2
3
|
import { Worker } from '@welshman/lib';
|
|
4
|
+
import type { Deferred } from '@welshman/lib';
|
|
3
5
|
import type { TrustedEvent, EventTemplate, StampedEvent, OwnedEvent } from '@welshman/util';
|
|
4
6
|
import { PublishStatus } from "@welshman/net";
|
|
5
|
-
export type
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
export type ThunkEvent = EventTemplate | StampedEvent | OwnedEvent | TrustedEvent;
|
|
8
|
+
export type ThunkRequest = {
|
|
9
|
+
event: ThunkEvent;
|
|
10
|
+
relays: string[];
|
|
11
|
+
delay?: number;
|
|
12
|
+
};
|
|
13
|
+
export type ThunkStatus = {
|
|
8
14
|
message: string;
|
|
9
15
|
status: PublishStatus;
|
|
10
16
|
};
|
|
11
|
-
export type
|
|
12
|
-
export type
|
|
13
|
-
export declare const publishStatusData: import("svelte/store").Writable<PublishStatusDataByUrlById>;
|
|
14
|
-
export type ThunkWithResolve = {
|
|
17
|
+
export type ThunkStatusByUrl = Record<string, ThunkStatus>;
|
|
18
|
+
export type Thunk = {
|
|
15
19
|
event: TrustedEvent;
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
request: ThunkRequest;
|
|
21
|
+
controller: AbortController;
|
|
22
|
+
result: Deferred<ThunkStatusByUrl>;
|
|
23
|
+
status: Writable<ThunkStatusByUrl>;
|
|
18
24
|
};
|
|
19
|
-
export declare const thunkWorker: Worker<ThunkWithResolve>;
|
|
20
|
-
export type ThunkEvent = EventTemplate | StampedEvent | OwnedEvent | TrustedEvent;
|
|
21
25
|
export declare const prepEvent: (event: ThunkEvent) => TrustedEvent;
|
|
22
|
-
export
|
|
23
|
-
event:
|
|
24
|
-
|
|
26
|
+
export declare const makeThunk: (request: ThunkRequest) => {
|
|
27
|
+
event: TrustedEvent;
|
|
28
|
+
request: ThunkRequest;
|
|
29
|
+
controller: AbortController;
|
|
30
|
+
result: Deferred<ThunkStatusByUrl>;
|
|
31
|
+
status: Writable<ThunkStatusByUrl>;
|
|
32
|
+
};
|
|
33
|
+
export declare const publishThunk: (request: ThunkRequest) => {
|
|
34
|
+
event: TrustedEvent;
|
|
35
|
+
request: ThunkRequest;
|
|
36
|
+
controller: AbortController;
|
|
37
|
+
result: Deferred<ThunkStatusByUrl>;
|
|
38
|
+
status: Writable<ThunkStatusByUrl>;
|
|
25
39
|
};
|
|
26
|
-
export declare const
|
|
40
|
+
export declare const thunkWorker: Worker<Thunk>;
|
package/build/src/thunk.mjs
CHANGED
|
@@ -1,13 +1,44 @@
|
|
|
1
1
|
import { writable, get } from 'svelte/store';
|
|
2
|
-
import { Worker, assoc } from '@welshman/lib';
|
|
2
|
+
import { Worker, 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
|
-
export const
|
|
8
|
+
export const prepEvent = (event) => {
|
|
9
|
+
if (!isStampedEvent(event)) {
|
|
10
|
+
event = stamp(event);
|
|
11
|
+
}
|
|
12
|
+
if (!isOwnedEvent(event)) {
|
|
13
|
+
event = own(event, get(pubkey));
|
|
14
|
+
}
|
|
15
|
+
if (!isHashedEvent(event)) {
|
|
16
|
+
event = hash(event);
|
|
17
|
+
}
|
|
18
|
+
return event;
|
|
19
|
+
};
|
|
20
|
+
export const makeThunk = (request) => {
|
|
21
|
+
const event = prepEvent(request.event);
|
|
22
|
+
const controller = new AbortController();
|
|
23
|
+
const result = defer();
|
|
24
|
+
const status = writable({});
|
|
25
|
+
return { event, request, controller, result, status };
|
|
26
|
+
};
|
|
27
|
+
export const publishThunk = (request) => {
|
|
28
|
+
const thunk = makeThunk(request);
|
|
29
|
+
thunkWorker.push(thunk);
|
|
30
|
+
repository.publish(thunk.event);
|
|
31
|
+
thunk.controller.signal.addEventListener('abort', () => {
|
|
32
|
+
repository.removeEvent(thunk.event.id);
|
|
33
|
+
});
|
|
34
|
+
return thunk;
|
|
35
|
+
};
|
|
9
36
|
export const thunkWorker = new Worker();
|
|
10
|
-
thunkWorker.addGlobalHandler(async (
|
|
37
|
+
thunkWorker.addGlobalHandler(async (thunk) => {
|
|
38
|
+
let event = thunk.event;
|
|
39
|
+
// Handle abort immediately if possible
|
|
40
|
+
if (thunk.controller.signal.aborted)
|
|
41
|
+
return;
|
|
11
42
|
// If we were given a wrapped event, make sure to publish the wrapper, not the rumor
|
|
12
43
|
if (isUnwrappedEvent(event)) {
|
|
13
44
|
event = event.wrap;
|
|
@@ -23,44 +54,34 @@ thunkWorker.addGlobalHandler(async ({ event, relays, resolve }) => {
|
|
|
23
54
|
}
|
|
24
55
|
// We're guaranteed to have a signed event at this point
|
|
25
56
|
const signedEvent = event;
|
|
26
|
-
|
|
57
|
+
// Wait if the thunk is to be delayed
|
|
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
|
+
}
|
|
27
65
|
// Send it off
|
|
28
|
-
const pub = publish({ event: signedEvent, relays });
|
|
66
|
+
const pub = publish({ event: signedEvent, relays: thunk.request.relays });
|
|
29
67
|
// Copy the signature over since we had deferred it
|
|
30
|
-
const savedEvent = repository.getEvent(id);
|
|
68
|
+
const savedEvent = repository.getEvent(signedEvent.id);
|
|
31
69
|
// The event may already be replaced or deleted
|
|
32
70
|
if (savedEvent) {
|
|
33
|
-
savedEvent.sig = sig;
|
|
71
|
+
savedEvent.sig = signedEvent.sig;
|
|
34
72
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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);
|
|
78
|
+
}
|
|
40
79
|
if (status === PublishStatus.Success) {
|
|
41
|
-
tracker.track(id, url);
|
|
80
|
+
tracker.track(signedEvent.id, url);
|
|
42
81
|
}
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
resolve(statusByUrl);
|
|
82
|
+
if (completed.size === thunk.request.relays.length) {
|
|
83
|
+
thunk.result.resolve(get(thunk.status));
|
|
46
84
|
}
|
|
47
85
|
});
|
|
48
86
|
});
|
|
49
|
-
export const prepEvent = (event) => {
|
|
50
|
-
if (!isStampedEvent(event)) {
|
|
51
|
-
event = stamp(event);
|
|
52
|
-
}
|
|
53
|
-
if (!isOwnedEvent(event)) {
|
|
54
|
-
event = own(event, get(pubkey));
|
|
55
|
-
}
|
|
56
|
-
if (!isHashedEvent(event)) {
|
|
57
|
-
event = hash(event);
|
|
58
|
-
}
|
|
59
|
-
return event;
|
|
60
|
-
};
|
|
61
|
-
export const publishThunk = (params) => new Promise(resolve => {
|
|
62
|
-
const event = prepEvent(params.event);
|
|
63
|
-
thunkWorker.push({ ...params, event, resolve });
|
|
64
|
-
repository.publish(event);
|
|
65
|
-
});
|
|
66
87
|
//# 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/thunk.ts"],"names":[],"mappings":"OAAO,EAAC,QAAQ,EAAE,GAAG,EAAC,MAAM,cAAc;OAEnC,EAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,eAAe;OAElD,EAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAC,MAAM,kBAAkB;OAE1C,EAAC,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,aAAa,EAAC,MAAM,gBAAgB;OACpG,EAAC,OAAO,E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K,CAAC,OAAO,CAAC,MAAM,EAAC,CAAC,CAAA;IAEvE,mDAAmD;IACnD,MAAM,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAgB,CAAA;IAErE,+CAA+C;IAC/C,IAAI,UAAU,EAAE;QACd,UAAU,CAAC,GAAG,GAAG,WAAW,CAAC,GAAG,CAAA;KACjC;IAED,MAAM,SAAS,GAAG,IAAI,GAAG,EAAE,CAAA;IAE3B,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,MAAqB,EAAE,GAAW,EAAE,OAAe,EAAE,EAAE;QAChF,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC,CAAC,CAAA;QAElD,IAAI,MAAM,KAAK,aAAa,CAAC,OAAO,EAAE;YACpC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;SACnB;QAED,IAAI,MAAM,KAAK,aAAa,CAAC,OAAO,EAAE;YACpC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;SACnC;QAED,IAAI,SAAS,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE;YAClD,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;SACxC;IACH,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.17",
|
|
4
4
|
"author": "hodlbod",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A collection of svelte stores for use in building nostr client applications.",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"@welshman/lib": "~0.0.22",
|
|
35
35
|
"@welshman/feeds": "~0.0.20",
|
|
36
36
|
"@welshman/dvm": "~0.0.10",
|
|
37
|
-
"@welshman/net": "~0.0.
|
|
38
|
-
"@welshman/signer": "~0.0.
|
|
37
|
+
"@welshman/net": "~0.0.28",
|
|
38
|
+
"@welshman/signer": "~0.0.9",
|
|
39
39
|
"@welshman/store": "~0.0.10",
|
|
40
|
-
"@welshman/util": "~0.0.
|
|
40
|
+
"@welshman/util": "~0.0.39",
|
|
41
41
|
"fuse.js": "^7.0.0",
|
|
42
42
|
"idb": "^8.0.0",
|
|
43
43
|
"svelte": "^4.2.18",
|