Перенесено дерево lab4 целиком: NestJS-приложение с вложениями и S3,
Dockerfile, compose.yaml, infra/{haproxy,minio}, стендовые скрипты,
scripts/lab4, evidence/lab4 и contracts/extensions.openapi.json.
Задание lab5 оставлено своим: README, REPORT, COURSE, lab.json,
contracts/{openapi,infrastructure,jobs.schema,attachment-states,examples},
tests, compose.example.yaml, .github/pull_request_template.md.
Адаптации при переносе:
- docker-проект mtusi-lab4 -> mtusi-lab5 и тег образа mtusi-messenger:lab5,
чтобы тома и контейнеры не пересекались с lab4 (scripts/stop-one.sh:
LAB_PROJECT вместо LAB4_PROJECT);
- Makefile: цели lab5 сохранены, добавлены стендовые (stand-up/down,
wait-ready, init-env, test-e2e, test-dependencies, s3-security,
consistency, bench);
- .env.example: реальные переменные приложения и стенда lab4 (без них
compose.yaml не поднимается) + блок lab5 (BROKER_URL_FILE, WORKER_*).
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import {
|
|
registerDecorator,
|
|
ValidatorConstraint,
|
|
type ValidationArguments,
|
|
type ValidatorConstraintInterface,
|
|
} from 'class-validator';
|
|
|
|
// JSON Schema (and the course contract) measure string lengths in Unicode code
|
|
// points, while String.prototype.length counts UTF-16 units: one emoji outside
|
|
// the BMP is two units. `@Length` therefore accepted an 11-emoji password
|
|
// (22 units) and rejected 4000 emoji (8000 units), so these fields use an
|
|
// explicit code-point validator instead.
|
|
@ValidatorConstraint({ name: 'codePointLength', async: false })
|
|
class CodePointLengthConstraint implements ValidatorConstraintInterface {
|
|
validate(value: unknown, args: ValidationArguments): boolean {
|
|
const [min, max] = args.constraints as [number, number];
|
|
if (typeof value !== 'string') return false;
|
|
const length = [...value].length;
|
|
return length >= min && length <= max;
|
|
}
|
|
|
|
defaultMessage(args: ValidationArguments): string {
|
|
const [min, max] = args.constraints as [number, number];
|
|
return `${args.property} must be between ${min} and ${max} code points`;
|
|
}
|
|
}
|
|
|
|
export function CodePointLength(min: number, max: number): PropertyDecorator {
|
|
return (target, propertyKey) => {
|
|
registerDecorator({
|
|
name: 'codePointLength',
|
|
target: target.constructor,
|
|
propertyName: String(propertyKey),
|
|
constraints: [min, max],
|
|
validator: CodePointLengthConstraint,
|
|
});
|
|
};
|
|
}
|