-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathrepositories.ts
More file actions
62 lines (55 loc) · 2.2 KB
/
repositories.ts
File metadata and controls
62 lines (55 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { PassThrough } from 'stream'
import { DatabaseClient, EventId, Pubkey } from './base'
import { DBEvent, Event } from './event'
import { Invoice } from './invoice'
import { Nip05Verification } from './nip05'
import { SubscriptionFilter } from './subscription'
import { User } from './user'
export type ExposedPromiseKeys = 'then' | 'catch' | 'finally'
export interface IQueryResult<T> extends Pick<Promise<T>, keyof Promise<T> & ExposedPromiseKeys> {
stream(options?: Record<string, any>): PassThrough & AsyncIterable<T>
}
export interface IEventRepository {
create(event: Event): Promise<number>
createMany(events: Event[]): Promise<number>
upsert(event: Event): Promise<number>
upsertMany(events: Event[]): Promise<number>
findByFilters(filters: SubscriptionFilter[]): IQueryResult<DBEvent[]>
deleteByPubkeyAndIds(pubkey: Pubkey, ids: EventId[]): Promise<number>
deleteByPubkeyExceptKinds(pubkey: Pubkey, excludedKinds: number[]): Promise<number>
hasActiveRequestToVanish(pubkey: Pubkey): Promise<boolean>
}
export interface IInvoiceRepository {
findById(id: string, client?: DatabaseClient): Promise<Invoice | undefined>
upsert(invoice: Partial<Invoice>, client?: DatabaseClient): Promise<number>
updateStatus(
invoice: Pick<Invoice, 'id' | 'status'>,
client?: DatabaseClient,
): Promise<Invoice | undefined>
confirmInvoice(
invoiceId: string,
amountReceived: bigint,
confirmedAt: Date,
client?: DatabaseClient,
): Promise<void>
findPendingInvoices(
offset?: number,
limit?: number,
client?: DatabaseClient,
): Promise<Invoice[]>
}
export interface IUserRepository {
findByPubkey(pubkey: Pubkey, client?: DatabaseClient): Promise<User | undefined>
upsert(user: Partial<User>, client?: DatabaseClient): Promise<number>
getBalanceByPubkey(pubkey: Pubkey, client?: DatabaseClient): Promise<bigint>
}
export interface INip05VerificationRepository {
findByPubkey(pubkey: Pubkey): Promise<Nip05Verification | undefined>
upsert(verification: Nip05Verification): Promise<number>
findPendingVerifications(
updateFrequencyMs: number,
maxFailures: number,
limit: number,
): Promise<Nip05Verification[]>
deleteByPubkey(pubkey: Pubkey): Promise<number>
}