mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
758d4edbb9
* Upgrade @typescript-eslint dependencies from v6.21.0 to v8.33.0 - Updated @typescript-eslint/eslint-plugin from ^6.21.0 to ^8.33.0 - Updated @typescript-eslint/parser from ^6.21.0 to ^8.33.0 - Tested linting functionality to ensure compatibility - This brings the latest TypeScript ESLint features and bug fixes * lint * tsc --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom@getoutline.com>
89 lines
2.5 KiB
TypeScript
89 lines
2.5 KiB
TypeScript
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(
|
|
", "
|
|
)}.`;
|
|
},
|
|
},
|
|
});
|
|
};
|
|
}
|