-
Notifications
You must be signed in to change notification settings - Fork 642
/
Copy pathcontext.ts
102 lines (85 loc) · 2.27 KB
/
context.ts
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import * as plc from '@did-plc/lib'
import { IdResolver } from '@atproto/identity'
import { AtpAgent } from '@atproto/api'
import { Keypair } from '@atproto/crypto'
import { createServiceJwt } from '@atproto/xrpc-server'
import { DatabaseCoordinator } from './db'
import { ServerConfig } from './config'
import { ImageUriBuilder } from './image/uri'
import { Services } from './services'
import DidRedisCache from './did-cache'
import { BackgroundQueue } from './background'
import { Redis } from './redis'
import { AuthVerifier } from './auth-verifier'
import { BsyncClient } from './bsync'
import { CourierClient } from './courier'
export class AppContext {
constructor(
private opts: {
db: DatabaseCoordinator
imgUriBuilder: ImageUriBuilder
cfg: ServerConfig
services: Services
signingKey: Keypair
idResolver: IdResolver
didCache: DidRedisCache
redis: Redis
backgroundQueue: BackgroundQueue
searchAgent?: AtpAgent
bsyncClient?: BsyncClient
courierClient?: CourierClient
authVerifier: AuthVerifier
},
) {}
get db(): DatabaseCoordinator {
return this.opts.db
}
get imgUriBuilder(): ImageUriBuilder {
return this.opts.imgUriBuilder
}
get cfg(): ServerConfig {
return this.opts.cfg
}
get services(): Services {
return this.opts.services
}
get signingKey(): Keypair {
return this.opts.signingKey
}
get plcClient(): plc.Client {
return new plc.Client(this.cfg.didPlcUrl)
}
get idResolver(): IdResolver {
return this.opts.idResolver
}
get didCache(): DidRedisCache {
return this.opts.didCache
}
get redis(): Redis {
return this.opts.redis
}
get searchAgent(): AtpAgent | undefined {
return this.opts.searchAgent
}
get bsyncClient(): BsyncClient | undefined {
return this.opts.bsyncClient
}
get courierClient(): CourierClient | undefined {
return this.opts.courierClient
}
get authVerifier(): AuthVerifier {
return this.opts.authVerifier
}
async serviceAuthJwt(aud: string) {
const iss = this.cfg.serverDid
return createServiceJwt({
iss,
aud,
keypair: this.signingKey,
})
}
get backgroundQueue(): BackgroundQueue {
return this.opts.backgroundQueue
}
}
export default AppContext