-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
433 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { AtpAgent } from '@atproto/api' | ||
import * as crypto from '@atproto/crypto' | ||
import { BlobStore } from '@atproto/repo' | ||
import { ActorDb } from './actor-db' | ||
import { ActorRepo } from './repo' | ||
import { ActorRecord } from './record' | ||
import { ActorLocal } from './local' | ||
import { ActorPreference } from './preference' | ||
import { BackgroundQueue } from '../background' | ||
|
||
type ActorStoreReaderResources = { | ||
repoSigningKey: crypto.Keypair | ||
pdsHostname: string | ||
appViewAgent?: AtpAgent | ||
appViewDid?: string | ||
appViewCdnUrlPattern?: string | ||
} | ||
|
||
type ActorStoreResources = ActorStoreReaderResources & { | ||
blobstore: BlobStore | ||
backgroundQueue: BackgroundQueue | ||
} | ||
|
||
export const createActorStore = ( | ||
resources: ActorStoreResources, | ||
): ActorStore => { | ||
return { | ||
reader: (did: string) => { | ||
const db = ActorDb.sqlite('', did) | ||
return createActorReader(db, resources) | ||
}, | ||
transact: <T>(did: string, fn: ActorStoreTransactFn<T>) => { | ||
const db = ActorDb.sqlite('', did) | ||
return db.transaction((dbTxn) => { | ||
const store = createActorTransactor(dbTxn, resources) | ||
return fn(store) | ||
}) | ||
}, | ||
} | ||
} | ||
|
||
const createActorTransactor = ( | ||
db: ActorDb, | ||
resources: ActorStoreResources, | ||
): ActorStoreTransactor => { | ||
const { repoSigningKey, blobstore, backgroundQueue } = resources | ||
const reader = createActorReader(db, resources) | ||
return { | ||
...reader, | ||
repo: new ActorRepo(db, repoSigningKey, blobstore, backgroundQueue), | ||
} | ||
} | ||
|
||
const createActorReader = ( | ||
db: ActorDb, | ||
resources: ActorStoreReaderResources, | ||
): ActorStoreReader => { | ||
const { | ||
repoSigningKey, | ||
pdsHostname, | ||
appViewAgent, | ||
appViewDid, | ||
appViewCdnUrlPattern, | ||
} = resources | ||
return { | ||
record: new ActorRecord(db), | ||
local: new ActorLocal( | ||
db, | ||
repoSigningKey, | ||
pdsHostname, | ||
appViewAgent, | ||
appViewDid, | ||
appViewCdnUrlPattern, | ||
), | ||
pref: new ActorPreference(db), | ||
} | ||
} | ||
|
||
export type ActorStore = { | ||
reader: (did: string) => ActorStoreReader | ||
transact: <T>(did: string, store: ActorStoreTransactFn<T>) => Promise<T> | ||
} | ||
|
||
export type ActorStoreTransactFn<T> = (fn: ActorStoreTransactor) => Promise<T> | ||
|
||
export type ActorStoreTransactor = ActorStoreReader & { | ||
repo: ActorRepo | ||
} | ||
|
||
export type ActorStoreReader = { | ||
record: ActorRecord | ||
local: ActorLocal | ||
pref: ActorPreference | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
packages/pds/src/user-store/preferences.ts → packages/pds/src/actor-store/preference.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export class ActorStoreReader {} |
Oops, something went wrong.