Add some common commands

This commit is contained in:
Jon Staab
2024-10-08 15:24:08 -07:00
parent a4085af9e3
commit cabeba4533
6 changed files with 70 additions and 31 deletions
+10 -9
View File
@@ -20,12 +20,9 @@ export type PublishStatusDataByUrlById = Record<string, PublishStatusDataByUrl>
export const publishStatusData = writable<PublishStatusDataByUrlById>({})
export type Thunk = {
export type ThunkWithResolve = {
event: TrustedEvent
relays: string[]
}
export type ThunkWithResolve = Thunk & {
resolve: (data: PublishStatusDataByUrl) => void
}
@@ -103,13 +100,17 @@ export const prepEvent = (event: ThunkEvent) => {
return event as TrustedEvent
}
export const makeThunk = ({event, relays}: {event: ThunkEvent, relays: string[]}) =>
({event, relays})
export type ThunkParams = {
event: ThunkEvent
relays: string[]
}
export const publishThunk = ({event, relays}: Thunk) =>
export const makeThunk = (params: ThunkParams) => params
export const publishThunk = (params: ThunkParams) =>
new Promise<PublishStatusDataByUrl>(resolve => {
event = prepEvent(event)
const event = prepEvent(params.event)
thunkWorker.push({event, relays, resolve})
thunkWorker.push({...params, event, resolve})
repository.publish(event)
})