import {Awaitable, JSONState, Maybe, Rehydratable} from '../util' /** Value that can be used to uniquely identify a user. */ export type AuthenticatableIdentifier = string | number export interface AuthenticatableCredentials { identifier: string, credential: string, } /** * Base class for entities that can be authenticated. */ export abstract class Authenticatable implements Rehydratable { /** Get the unique identifier of the user. */ abstract getIdentifier(): AuthenticatableIdentifier /** Get the human-readable identifier of the user. */ abstract getDisplayIdentifier(): string abstract dehydrate(): Promise abstract rehydrate(state: JSONState): Awaitable } /** * Base class for a repository that stores and recalls users. */ export abstract class AuthenticatableRepository { /** Look up the user by their unique identifier. */ abstract getByIdentifier(id: AuthenticatableIdentifier): Awaitable> /** * Attempt to look up and verify a user by their credentials. * Returns the user if the credentials are valid. * @param credentials */ abstract getByCredentials(credentials: AuthenticatableCredentials): Awaitable> abstract createByCredentials(credentials: AuthenticatableCredentials): Awaitable }