ffffng/server/types/config.ts

70 lines
2 KiB
TypeScript
Raw Normal View History

import {ArrayField, Field, RawJsonField} from "sparkson"
2022-07-18 17:49:42 +02:00
import {ClientConfig, JSONObject, Url} from "./shared";
// TODO: Replace string types by more specific types like URL, Password, etc.
2022-07-18 17:49:42 +02:00
export type Username = string & { readonly __tag: unique symbol };
export type CleartextPassword = string & { readonly __tag: unique symbol };
export type PasswordHash = string & { readonly __tag: unique symbol };
export class UsersConfig {
constructor(
2022-07-18 17:49:42 +02:00
@Field("user") public username: Username,
@Field("passwordHash") public passwordHash: PasswordHash,
) {}
}
export class LoggingConfig {
constructor(
2021-08-23 21:05:17 +02:00
@Field("enabled") public enabled: boolean,
@Field("debug") public debug: boolean,
@Field("profile") public profile: boolean,
) {}
}
export class InternalConfig {
constructor(
@Field("active") public active: boolean,
@ArrayField("users", UsersConfig) public users: UsersConfig[],
) {}
}
export class EmailConfig {
constructor(
@Field("from") public from: string,
// For details see: https://nodemailer.com/2-0-0-beta/setup-smtp/
2022-07-18 17:49:42 +02:00
@RawJsonField("smtp") public smtp: JSONObject,
) {}
}
export class ServerMapConfig {
constructor(
2022-07-18 17:49:42 +02:00
@ArrayField("nodesJsonUrl", String) public nodesJsonUrl: Url[],
) {}
}
export class ServerConfig {
constructor(
2022-07-18 17:49:42 +02:00
@Field("baseUrl") public baseUrl: Url,
@Field("port") public port: number,
@Field("databaseFile") public databaseFile: string,
@Field("peersPath") public peersPath: string,
@Field("logging") public logging: LoggingConfig,
@Field("internal") public internal: InternalConfig,
@Field("email") public email: EmailConfig,
@Field("map") public map: ServerMapConfig,
@Field("rootPath", true, undefined, "/") public rootPath: string,
) {}
}
export class Config {
constructor(
@Field("server") public server: ServerConfig,
2022-05-19 13:33:48 +02:00
@Field("client") public client: ClientConfig,
) {}
}