Lint
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
import {now} from "@welshman/lib"
|
||||
import {PublishStatus, MockAdapter} from "@welshman/net"
|
||||
import {NOTE, makeEvent} from "@welshman/util"
|
||||
import {Nip01Signer} from "@welshman/signer"
|
||||
import {PublishStatus} from "@welshman/net"
|
||||
import {NOTE, makeEvent} from "@welshman/util"
|
||||
import {LOCAL_RELAY_URL} from "@welshman/relay"
|
||||
import {getPubkey, makeSecret} from "@welshman/signer"
|
||||
import {EventEmitter} from "events"
|
||||
import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"
|
||||
import {repository, tracker} from "../src/core"
|
||||
import {addSession, dropSession} from "../src/session"
|
||||
@@ -31,7 +28,7 @@ const mockRequest = {
|
||||
describe("thunk", () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
addSession({method: 'nip01', secret, pubkey})
|
||||
addSession({method: "nip01", secret, pubkey})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -70,7 +67,7 @@ describe("thunk", () => {
|
||||
|
||||
describe("publishThunk", () => {
|
||||
it("should create and publish a thunk", async () => {
|
||||
const publishSpy = vi.spyOn(repository, 'publish')
|
||||
const publishSpy = vi.spyOn(repository, "publish")
|
||||
const result = publishThunk(mockRequest)
|
||||
|
||||
expect(publishSpy).toHaveBeenCalled()
|
||||
@@ -79,7 +76,7 @@ describe("thunk", () => {
|
||||
})
|
||||
|
||||
it("should handle abort", () => {
|
||||
const removeEventSpy = vi.spyOn(repository, 'removeEvent')
|
||||
const removeEventSpy = vi.spyOn(repository, "removeEvent")
|
||||
const thunk = publishThunk(mockRequest)
|
||||
|
||||
thunk.controller.abort()
|
||||
@@ -109,8 +106,7 @@ describe("thunk", () => {
|
||||
})
|
||||
|
||||
it("should update status during publishing", async () => {
|
||||
const send = vi.fn()
|
||||
const track = vi.spyOn(tracker, 'track')
|
||||
const track = vi.spyOn(tracker, "track")
|
||||
const thunk = makeThunk(mockRequest)
|
||||
let status: Record<string, any> = {}
|
||||
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
import {get, derived} from 'svelte/store'
|
||||
import {batch, fromPairs} from '@welshman/lib'
|
||||
import {PROFILE, FOLLOWS, MUTES, RELAYS, INBOX_RELAYS, getPubkeyTagValues, getListTags} from '@welshman/util'
|
||||
import {throttled, withGetter} from '@welshman/store'
|
||||
import {RepositoryUpdate} from '@welshman/relay'
|
||||
import {getAll, bulkPut, bulkDelete} from './storage.js'
|
||||
import {relays} from './relays.js'
|
||||
import {handles, onHandle} from './handles.js'
|
||||
import {zappers, onZapper} from './zappers.js'
|
||||
import {plaintext} from './plaintext.js'
|
||||
import {freshness} from './freshness.js'
|
||||
import {repository} from './core.js'
|
||||
import {sessions} from './session.js'
|
||||
import {userFollows} from './user.js'
|
||||
import {derived} from "svelte/store"
|
||||
import {batch, fromPairs} from "@welshman/lib"
|
||||
import {
|
||||
PROFILE,
|
||||
FOLLOWS,
|
||||
MUTES,
|
||||
RELAYS,
|
||||
INBOX_RELAYS,
|
||||
getPubkeyTagValues,
|
||||
getListTags,
|
||||
} from "@welshman/util"
|
||||
import {throttled, withGetter} from "@welshman/store"
|
||||
import {RepositoryUpdate} from "@welshman/relay"
|
||||
import {getAll, bulkPut, bulkDelete} from "./storage.js"
|
||||
import {relays} from "./relays.js"
|
||||
import {handles, onHandle} from "./handles.js"
|
||||
import {zappers, onZapper} from "./zappers.js"
|
||||
import {plaintext} from "./plaintext.js"
|
||||
import {freshness} from "./freshness.js"
|
||||
import {repository} from "./core.js"
|
||||
import {sessions} from "./session.js"
|
||||
import {userFollows} from "./user.js"
|
||||
|
||||
export const defaultStorageAdapters = {
|
||||
relays: {
|
||||
@@ -70,7 +78,7 @@ export const defaultStorageAdapters = {
|
||||
init: async () => repository.load(await getAll("events")),
|
||||
sync: () => {
|
||||
const userFollowPubkeys = withGetter(
|
||||
derived(userFollows, l => new Set(getPubkeyTagValues(getListTags(l))))
|
||||
derived(userFollows, l => new Set(getPubkeyTagValues(getListTags(l)))),
|
||||
)
|
||||
|
||||
const onUpdate = async ({added, removed}: RepositoryUpdate) => {
|
||||
|
||||
@@ -33,7 +33,9 @@ export const requestDVM = async ({kind, onEvent, ...request}: DVMOpts) => {
|
||||
const tags = request.tags || []
|
||||
const $signer = signer.get() || new Nip01Signer(makeSecret())
|
||||
const pubkey = await $signer.getPubkey()
|
||||
const relays = request.relays || Router.get().FromPubkeys(getPubkeyTagValues(tags)).policy(addMinimalFallbacks).getUrls()
|
||||
const relays =
|
||||
request.relays ||
|
||||
Router.get().FromPubkeys(getPubkeyTagValues(tags)).policy(addMinimalFallbacks).getUrls()
|
||||
|
||||
if (!tags.some(nthEq(0, "expiration"))) {
|
||||
tags.push(["expiration", String(now() + 60)])
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import {FOLLOWS, asDecryptedEvent, readList} from "@welshman/util"
|
||||
import {TrustedEvent, PublishedList} from "@welshman/util"
|
||||
import {MultiRequestOptions, load} from "@welshman/net"
|
||||
import {deriveEventsMapped} from "@welshman/store"
|
||||
import {repository} from "./core.js"
|
||||
import {Router} from "./router.js"
|
||||
import {collection} from "./collection.js"
|
||||
import {loadWithAsapMetaRelayUrls} from "./relaySelections.js"
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {writable, derived} from "svelte/store"
|
||||
import {MultiRequestOptions} from "@welshman/net"
|
||||
import {tryCatch, fetchJson, uniq, batcher, postJson, last} from "@welshman/lib"
|
||||
import {collection} from "./collection.js"
|
||||
import {deriveProfile} from "./profiles.js"
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import {MUTES, asDecryptedEvent, readList} from "@welshman/util"
|
||||
import {TrustedEvent, PublishedList} from "@welshman/util"
|
||||
import {load, MultiRequestOptions} from "@welshman/net"
|
||||
import {deriveEventsMapped} from "@welshman/store"
|
||||
import {repository} from "./core.js"
|
||||
import {Router} from "./router.js"
|
||||
import {collection} from "./collection.js"
|
||||
import {ensurePlaintext} from "./plaintext.js"
|
||||
import {loadWithAsapMetaRelayUrls} from "./relaySelections.js"
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import {PINS, asDecryptedEvent, readList} from "@welshman/util"
|
||||
import {TrustedEvent, PublishedList} from "@welshman/util"
|
||||
import {load, MultiRequestOptions} from "@welshman/net"
|
||||
import {deriveEventsMapped} from "@welshman/store"
|
||||
import {repository} from "./core.js"
|
||||
import {Router} from "./router.js"
|
||||
import {collection} from "./collection.js"
|
||||
import {loadWithAsapMetaRelayUrls} from "./relaySelections.js"
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import {derived, readable} from "svelte/store"
|
||||
import {readProfile, displayProfile, displayPubkey, PROFILE} from "@welshman/util"
|
||||
import {load, MultiRequestOptions} from "@welshman/net"
|
||||
import {PublishedProfile} from "@welshman/util"
|
||||
import {deriveEventsMapped, withGetter} from "@welshman/store"
|
||||
import {repository} from "./core.js"
|
||||
import {Router} from "./router.js"
|
||||
import {collection} from "./collection.js"
|
||||
import {loadWithAsapMetaRelayUrls} from "./relaySelections.js"
|
||||
|
||||
@@ -25,7 +23,7 @@ export const {
|
||||
store: profiles,
|
||||
getKey: profile => profile.event.pubkey,
|
||||
load: (pubkey: string, relays: string[]) =>
|
||||
loadWithAsapMetaRelayUrls(pubkey, relays, [{kinds: [PROFILE], authors: [pubkey]}])
|
||||
loadWithAsapMetaRelayUrls(pubkey, relays, [{kinds: [PROFILE], authors: [pubkey]}]),
|
||||
})
|
||||
|
||||
export const displayProfileByPubkey = (pubkey: string | undefined) =>
|
||||
|
||||
@@ -10,10 +10,10 @@ import {
|
||||
getRelayTagValues,
|
||||
} from "@welshman/util"
|
||||
import {TrustedEvent, Filter, PublishedList, List} from "@welshman/util"
|
||||
import {load, MultiRequestOptions} from "@welshman/net"
|
||||
import {load} from "@welshman/net"
|
||||
import {deriveEventsMapped} from "@welshman/store"
|
||||
import {repository} from "./core.js"
|
||||
import {Router, addNoFallbacks} from "./router.js"
|
||||
import {Router} from "./router.js"
|
||||
import {collection} from "./collection.js"
|
||||
|
||||
export const getRelayUrls = (list?: List): string[] =>
|
||||
@@ -51,13 +51,15 @@ export const {
|
||||
const router = Router.get()
|
||||
|
||||
await load({
|
||||
relays: router.merge([router.Index(), router.FromRelays(relays), router.FromPubkey(pubkey)]).getUrls(),
|
||||
relays: router
|
||||
.merge([router.Index(), router.FromRelays(relays), router.FromPubkey(pubkey)])
|
||||
.getUrls(),
|
||||
filters: [{kinds: [RELAYS], authors: [pubkey]}],
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
export const loadWithAsapMetaRelayUrls = <T>(pubkey: string, relays: string[], filters: Filter[]) => {
|
||||
export const loadWithAsapMetaRelayUrls = (pubkey: string, relays: string[], filters: Filter[]) => {
|
||||
const router = Router.get()
|
||||
|
||||
return new Promise(resolve => {
|
||||
@@ -69,8 +71,10 @@ export const loadWithAsapMetaRelayUrls = <T>(pubkey: string, relays: string[], f
|
||||
}
|
||||
}
|
||||
|
||||
load({filters, relays: router.merge([router.Index(), router.FromRelays(relays)]).getUrls()})
|
||||
.then(onLoad)
|
||||
load({
|
||||
filters,
|
||||
relays: router.merge([router.Index(), router.FromRelays(relays)]).getUrls(),
|
||||
}).then(onLoad)
|
||||
|
||||
loadRelaySelections(pubkey, relays)
|
||||
.then(() => load({filters, relays: router.FromPubkey(pubkey).getUrls()}))
|
||||
@@ -93,5 +97,5 @@ export const {
|
||||
store: inboxRelaySelections,
|
||||
getKey: inboxRelaySelections => inboxRelaySelections.event.pubkey,
|
||||
load: (pubkey: string, relays: string[]) =>
|
||||
loadWithAsapMetaRelayUrls(pubkey, relays, [{kinds: [INBOX_RELAYS], authors: [pubkey]}])
|
||||
loadWithAsapMetaRelayUrls(pubkey, relays, [{kinds: [INBOX_RELAYS], authors: [pubkey]}]),
|
||||
})
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
MINUTE,
|
||||
HOUR,
|
||||
DAY,
|
||||
WEEK,
|
||||
} from "@welshman/lib"
|
||||
import {
|
||||
getFilterId,
|
||||
@@ -242,7 +241,8 @@ export class Router {
|
||||
|
||||
FromPubkey = (pubkey: string) => this.FromRelays(this.getRelaysForPubkey(pubkey, RelayMode.Write))
|
||||
|
||||
PubkeyInbox = (pubkey: string) => this.FromRelays(this.getRelaysForPubkey(pubkey, RelayMode.Inbox))
|
||||
PubkeyInbox = (pubkey: string) =>
|
||||
this.FromRelays(this.getRelaysForPubkey(pubkey, RelayMode.Inbox))
|
||||
|
||||
ForPubkeys = (pubkeys: string[]) => this.merge(pubkeys.map(pubkey => this.ForPubkey(pubkey)))
|
||||
|
||||
@@ -493,7 +493,9 @@ export const getFilterSelections = (
|
||||
const result = []
|
||||
|
||||
for (const [id, filter] of filtersById.entries()) {
|
||||
const scenario = Router.get().merge(scenariosById.get(id) || []).policy(addMinimalFallbacks)
|
||||
const scenario = Router.get()
|
||||
.merge(scenariosById.get(id) || [])
|
||||
.policy(addMinimalFallbacks)
|
||||
|
||||
result.push({filters: [filter], relays: scenario.getUrls()})
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import {openDB, deleteDB} from "idb"
|
||||
import {IDBPDatabase} from "idb"
|
||||
import {writable} from "svelte/store"
|
||||
import {Unsubscriber, Writable} from "svelte/store"
|
||||
import {indexBy, call, equals, throttle, fromPairs} from "@welshman/lib"
|
||||
import {TrustedEvent} from "@welshman/util"
|
||||
import {Repository} from "@welshman/relay"
|
||||
import {Tracker} from "@welshman/net"
|
||||
import {withGetter, adapter, throttled, custom} from "@welshman/store"
|
||||
import {Unsubscriber} from "svelte/store"
|
||||
import {call} from "@welshman/lib"
|
||||
import {withGetter} from "@welshman/store"
|
||||
|
||||
export type StorageAdapterOptions = {
|
||||
throttle?: number
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
import {Writable, Readable, writable, derived, get} from "svelte/store"
|
||||
import {Deferred, fromPairs, TaskQueue, dissoc, identity, uniq, defer, sleep, assoc} from "@welshman/lib"
|
||||
import {
|
||||
Deferred,
|
||||
fromPairs,
|
||||
TaskQueue,
|
||||
dissoc,
|
||||
identity,
|
||||
uniq,
|
||||
defer,
|
||||
sleep,
|
||||
assoc,
|
||||
} from "@welshman/lib"
|
||||
import {stamp, own, hash} from "@welshman/signer"
|
||||
import {
|
||||
TrustedEvent,
|
||||
@@ -225,9 +235,11 @@ export const thunkQueue = new TaskQueue<Thunk>({
|
||||
// Update status to pending
|
||||
thunk.status.set(
|
||||
fromPairs(
|
||||
thunk.request.relays
|
||||
.map(url => [url, {status: PublishStatus.Pending, message: "Sending your message..."}])
|
||||
)
|
||||
thunk.request.relays.map(url => [
|
||||
url,
|
||||
{status: PublishStatus.Pending, message: "Sending your message..."},
|
||||
]),
|
||||
),
|
||||
)
|
||||
|
||||
// Send it off
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {writable, derived} from "svelte/store"
|
||||
import {Zapper} from "@welshman/util"
|
||||
import {MultiRequestOptions} from "@welshman/net"
|
||||
import {
|
||||
identity,
|
||||
fetchJson,
|
||||
|
||||
Reference in New Issue
Block a user