Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | import type { AccountConstructor } from './types.js';
import type * as DB from '$lib/database.js';
import type { DatabaseHandle } from '$lib/idb.svelte.js';
import KoboToolbox from '$lib/accounts/kobotoolbox.js';
type AccountProviders = {
kobotoolbox: AccountConstructor<
typeof KoboToolbox.auth,
(typeof KoboToolbox.servers)[number]['domain']
>;
};
class AccountRegistry<Providers extends Record<string, AccountConstructor>> {
constructor(private providers: Providers) {}
get<K extends keyof Providers>(key: K): Providers[K] {
return this.providers[key];
}
list() {
return Object.values(this.providers);
}
fromDatabase(db: DatabaseHandle, account: DB.Account) {
return this.providers[account.type].fromDatabase(db, account);
}
}
export const providers = new AccountRegistry<AccountProviders>({
kobotoolbox: KoboToolbox,
});
|