mirror of
https://github.com/outline/outline.git
synced 2026-11-23 06:11:04 +03:00
* Add support for individual database environment variables - Add DATABASE_HOST, DATABASE_PORT, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD env vars - Implement mutual exclusivity validation between DATABASE_URL and individual components - Add effectiveDatabaseUrl getter to construct URL from individual components - Update database connection logic to use new configuration options - Ensure backward compatibility with existing DATABASE_URL configuration Resolves: https://github.com/outline/outline/discussions/9158 * Refactor database configuration methods - Move effectiveDatabaseUrl method from env.ts to database.ts as getEffectiveDatabaseUrl function - Remove validateDatabaseConfiguration method from env.ts as validation is handled by decorators - Maintain clean separation of concerns between environment and database modules * Pass database options directly to Sequelize constructor - Replace URL construction with direct Sequelize configuration object - Support both DATABASE_URL string and individual component object configurations - Maintain common Sequelize options for both configuration types - Improve error messaging for different configuration scenarios * remove spurious comments * tsc --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom@getoutline.com>
90 lines
2.6 KiB
TypeScript
90 lines
2.6 KiB
TypeScript
/* eslint-disable @typescript-eslint/ban-types */
|
|
import {
|
|
registerDecorator,
|
|
ValidationArguments,
|
|
ValidationOptions,
|
|
} from "class-validator";
|
|
|
|
export function CannotUseWithout(
|
|
property: string,
|
|
validationOptions?: ValidationOptions
|
|
) {
|
|
return function (object: Object, propertyName: string) {
|
|
registerDecorator({
|
|
name: "cannotUseWithout",
|
|
target: object.constructor,
|
|
propertyName,
|
|
constraints: [property],
|
|
options: validationOptions,
|
|
validator: {
|
|
validate<T>(value: T, args: ValidationArguments) {
|
|
const obj = args.object as unknown as T;
|
|
const required = args.constraints[0] as keyof T;
|
|
return obj[required] !== undefined;
|
|
},
|
|
defaultMessage(args: ValidationArguments) {
|
|
return `${propertyName} cannot be used without ${args.constraints[0]}.`;
|
|
},
|
|
},
|
|
});
|
|
};
|
|
}
|
|
|
|
export function CannotUseWith(
|
|
property: string,
|
|
validationOptions?: ValidationOptions
|
|
) {
|
|
return function (object: Object, propertyName: string) {
|
|
registerDecorator({
|
|
name: "cannotUseWith",
|
|
target: object.constructor,
|
|
propertyName,
|
|
constraints: [property],
|
|
options: validationOptions,
|
|
validator: {
|
|
validate<T>(value: T, args: ValidationArguments) {
|
|
if (value === undefined) {
|
|
return true;
|
|
}
|
|
const obj = args.object as unknown as T;
|
|
const forbidden = args.constraints[0] as keyof T;
|
|
return obj[forbidden] === undefined;
|
|
},
|
|
defaultMessage(args: ValidationArguments) {
|
|
return `${propertyName} cannot be used with ${args.constraints[0]}.`;
|
|
},
|
|
},
|
|
});
|
|
};
|
|
}
|
|
|
|
export function CannotUseWithAny(
|
|
properties: string[],
|
|
validationOptions?: ValidationOptions
|
|
) {
|
|
return function (object: Object, propertyName: string) {
|
|
registerDecorator({
|
|
name: "cannotUseWithAny",
|
|
target: object.constructor,
|
|
propertyName,
|
|
constraints: properties,
|
|
options: validationOptions,
|
|
validator: {
|
|
validate<T>(value: T, args: ValidationArguments) {
|
|
if (value === undefined) {
|
|
return true;
|
|
}
|
|
const obj = args.object as unknown as T;
|
|
const forbiddenProperties = args.constraints as (keyof T)[];
|
|
return forbiddenProperties.every((prop) => obj[prop] === undefined);
|
|
},
|
|
defaultMessage(args: ValidationArguments) {
|
|
return `${propertyName} cannot be used with any of: ${args.constraints.join(
|
|
", "
|
|
)}.`;
|
|
},
|
|
},
|
|
});
|
|
};
|
|
}
|