Meta: Clean up the format file

This commit is contained in:
Diego Magdaleno 2021-05-19 20:44:52 -05:00
parent e3f6a29df7
commit 8872f806f7

View File

@ -1,5 +1,5 @@
import Ajv, {JSONSchemaType} from "ajv" import Ajv, { JSONSchemaType } from "ajv"
import {ValidateFunction} from 'ajv' import { ValidateFunction } from 'ajv'
import ajvFormats from 'ajv-formats'; import ajvFormats from 'ajv-formats';
import dotProp from "dot-prop"; import dotProp from "dot-prop";
import envPaths from "env-paths"; import envPaths from "env-paths";
@ -111,8 +111,8 @@ const schema: JSONSchemaType<DefaultOptions> & {
rateLimitOptions: { rateLimitOptions: {
type: "object", type: "object",
properties: { properties: {
count: {type: "number"}, count: { type: "number" },
timespan: {type: "number"}, timespan: { type: "number" },
}, },
required: ["count", "timespan"], required: ["count", "timespan"],
}, },
@ -230,9 +230,9 @@ const schema: JSONSchemaType<DefaultOptions> & {
ip: { ip: {
type: "object", type: "object",
properties: { properties: {
enabled: {type: "boolean"}, enabled: { type: "boolean" },
count: {type: "number"}, count: { type: "number" },
timespan: {type: "number"} timespan: { type: "number" }
}, },
required: ["enabled", "count", "timespan"], required: ["enabled", "count", "timespan"],
additionalProperties: false additionalProperties: false
@ -243,8 +243,8 @@ const schema: JSONSchemaType<DefaultOptions> & {
auth: { auth: {
type: "object", type: "object",
properties: { properties: {
login: {$ref: '#/definitions/rateLimitOptions'}, login: { $ref: '#/definitions/rateLimitOptions' },
register: {$ref: '#/definitions/rateLimitOptions'} register: { $ref: '#/definitions/rateLimitOptions' }
}, },
nullable: true, nullable: true,
required: [], required: [],
@ -278,7 +278,7 @@ const schema: JSONSchemaType<DefaultOptions> & {
captcha: { captcha: {
type: "object", type: "object",
properties: { properties: {
enabled: {type: "boolean"}, enabled: { type: "boolean" },
service: { service: {
type: "string", type: "string",
enum: ["hcaptcha", "recaptcha", null], enum: ["hcaptcha", "recaptcha", null],
@ -303,7 +303,7 @@ const schema: JSONSchemaType<DefaultOptions> & {
login: { login: {
type: "object", type: "object",
properties: { properties: {
requireCaptcha: {type: "boolean"} requireCaptcha: { type: "boolean" }
}, },
required: ["requireCaptcha"], required: ["requireCaptcha"],
additionalProperties: false additionalProperties: false
@ -314,9 +314,9 @@ const schema: JSONSchemaType<DefaultOptions> & {
email: { email: {
type: "object", type: "object",
properties: { properties: {
necessary: {type: "boolean"}, necessary: { type: "boolean" },
allowlist: {type: "boolean"}, allowlist: { type: "boolean" },
blocklist: {type: "boolean"}, blocklist: { type: "boolean" },
domains: { domains: {
type: "array", type: "array",
items: { items: {
@ -330,24 +330,24 @@ const schema: JSONSchemaType<DefaultOptions> & {
dateOfBirth: { dateOfBirth: {
type: "object", type: "object",
properties: { properties: {
necessary: {type: "boolean"}, necessary: { type: "boolean" },
minimum: {type: "number"} minimum: { type: "number" }
}, },
required: ["minimum", "necessary"], required: ["minimum", "necessary"],
additionalProperties: false additionalProperties: false
}, },
requireCaptcha: {type: "boolean"}, requireCaptcha: { type: "boolean" },
requireInvite: {type: "boolean"}, requireInvite: { type: "boolean" },
allowNewRegistration: {type: "boolean"}, allowNewRegistration: { type: "boolean" },
allowMultipleAccounts: {type: "boolean"}, allowMultipleAccounts: { type: "boolean" },
password: { password: {
type: "object", type: "object",
properties: { properties: {
minLength: {type: "number"}, minLength: { type: "number" },
minNumbers: {type: "number"}, minNumbers: { type: "number" },
minUpperCase: {type: "number"}, minUpperCase: { type: "number" },
minSymbols: {type: "number"}, minSymbols: { type: "number" },
blockInsecureCommonPasswords: {type: "boolean"} blockInsecureCommonPasswords: { type: "boolean" }
}, },
required: ["minLength", "minNumbers", "minUpperCase", "minSymbols", "blockInsecureCommonPasswords"], required: ["minLength", "minNumbers", "minUpperCase", "minSymbols", "blockInsecureCommonPasswords"],
additionalProperties: false additionalProperties: false
@ -408,7 +408,7 @@ class Config<T extends Record<string, any> = Record<string, unknown>> implements
return; return;
} }
const errors = this.#validator.errors.map(({instancePath, message = ''}) => `\`${instancePath.slice(1)}\` ${message}`); const errors = this.#validator.errors.map(({ instancePath, message = '' }) => `\`${instancePath.slice(1)}\` ${message}`);
throw new Error('The config schema was violated!: ' + errors.join('; ')); throw new Error('The config schema was violated!: ' + errors.join('; '));
} }
@ -430,7 +430,7 @@ class Config<T extends Record<string, any> = Record<string, unknown>> implements
} }
private _ensureDirectory(): void { private _ensureDirectory(): void {
fs.mkdirSync(path.dirname(this.path), {recursive: true}) fs.mkdirSync(path.dirname(this.path), { recursive: true })
} }
set store(value: T) { set store(value: T) {
@ -455,7 +455,7 @@ class Config<T extends Record<string, any> = Record<string, unknown>> implements
return dotProp.get<T[Key] | undefined>(this.store, key as string, defaultValue as T[Key]); return dotProp.get<T[Key] | undefined>(this.store, key as string, defaultValue as T[Key]);
} }
* [Symbol.iterator](): IterableIterator<[keyof T, T[keyof T]]> { *[Symbol.iterator](): IterableIterator<[keyof T, T[keyof T]]> {
for (const [key, value] of Object.entries(this.store)) { for (const [key, value] of Object.entries(this.store)) {
yield [key, value]; yield [key, value];
} }