···2233import (
44 "context"
55- "sync"
6576 "gorm.io/gorm"
87 "gorm.io/gorm/clause"
···1091110type DB struct {
1211 cli *gorm.DB
1313- mu sync.Mutex
1412}
15131614func NewDB(cli *gorm.DB) *DB {
1715 return &DB{
1816 cli: cli,
1919- mu: sync.Mutex{},
2017 }
2118}
22192320func (db *DB) Create(ctx context.Context, value any, clauses []clause.Expression) *gorm.DB {
2424- db.mu.Lock()
2525- defer db.mu.Unlock()
2621 return db.cli.WithContext(ctx).Clauses(clauses...).Create(value)
2722}
28232924func (db *DB) Save(ctx context.Context, value any, clauses []clause.Expression) *gorm.DB {
3030- db.mu.Lock()
3131- defer db.mu.Unlock()
3225 return db.cli.WithContext(ctx).Clauses(clauses...).Save(value)
3326}
34273528func (db *DB) Exec(ctx context.Context, sql string, clauses []clause.Expression, values ...any) *gorm.DB {
3636- db.mu.Lock()
3737- defer db.mu.Unlock()
3829 return db.cli.WithContext(ctx).Clauses(clauses...).Exec(sql, values...)
3930}
4031···4738}
48394940func (db *DB) Delete(ctx context.Context, value any, clauses []clause.Expression) *gorm.DB {
5050- db.mu.Lock()
5151- defer db.mu.Unlock()
5241 return db.cli.WithContext(ctx).Clauses(clauses...).Delete(value)
5342}
5443···5645 return db.cli.WithContext(ctx).First(dest, conds...)
5746}
58475959-// TODO: this isn't actually good. we can commit even if the db is locked here. this is probably okay for the time being, but need to figure
6060-// out a better solution. right now we only do this whenever we're importing a repo though so i'm mostly not worried, but it's still bad.
6161-// e.g. when we do apply writes we should also be using a transcation but we don't right now
6262-func (db *DB) BeginDangerously(ctx context.Context) *gorm.DB {
4848+func (db *DB) Begin(ctx context.Context) *gorm.DB {
6349 return db.cli.WithContext(ctx).Begin()
6450}
65516666-func (db *DB) Lock() {
6767- db.mu.Lock()
6868-}
6969-7070-func (db *DB) Unlock() {
7171- db.mu.Unlock()
5252+func (db *DB) Client() *gorm.DB {
5353+ return db.cli
7254}
···7575 }
76767777 proof := extractProof(headers)
7878-7978 if proof == "" {
8079 return nil, nil
8180 }
···197196198197 nonce, _ := claims["nonce"].(string)
199198 if nonce == "" {
200200- // WARN: this _must_ be `use_dpop_nonce` for clients know they should make another request
199199+ // reference impl checks if self.nonce is not null before returning an error, but we always have a
200200+ // nonce so we do not bother checking
201201 return nil, ErrUseDpopNonce
202202 }
203203204204 if nonce != "" && !dm.nonce.Check(nonce) {
205205- // WARN: this _must_ be `use_dpop_nonce` so that clients will fetch a new nonce
205205+ // dpop nonce mismatch
206206 return nil, ErrUseDpopNonce
207207 }
208208···237237}
238238239239func extractProof(headers http.Header) string {
240240- dpopHeaders := headers["Dpop"]
240240+ dpopHeaders := headers.Values("dpop")
241241 switch len(dpopHeaders) {
242242 case 0:
243243 return ""