UNPKG

@syngrisi/syngrisi

Version:
173 lines (169 loc) 6.04 kB
// src/server/schemas/Check.schema.ts import { z as z3 } from "zod"; // src/server/schemas/utils/commonValidations.ts import { z as z2 } from "zod"; import { extendZodWithOpenApi as extendZodWithOpenApi2 } from "@asteasolutions/zod-to-openapi"; // src/server/schemas/common/Version.schema.ts import { z } from "zod"; import { extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi"; extendZodWithOpenApi(z); var VersionBaseSchema = z.string().regex(/^\d+\.\d+\.\d+$/, 'Version must be in the format "x.y.z"'); var VersionSchema = VersionBaseSchema.transform((value) => { const parts = value.split("."); return { major: parseInt(parts[0]), minor: parseInt(parts[1]), patch: parseInt(parts[2]) }; }); // src/server/schemas/utils/commonValidations.ts extendZodWithOpenApi2(z2); var mongooseIdRegex = /^[0-9a-fA-F]{24}$/; var id = z2.string().regex(mongooseIdRegex, { message: "Invalid Mongoose ObjectId format: /^[0-9a-fA-F]{24}$/" }).openapi({ description: "baseline ID", example: "6bbF35cAB3C59dA969edAe79" }); var commonValidations = { id, version: VersionBaseSchema.openapi({ example: "1.1.2" }), positiveNumberString: z2.string().refine((value) => { const num = Number(value); return Number.isInteger(num) && num >= 0; }, { message: "String must be a positive number or 0" }), password: z2.string().min(6).regex(/(?=.*[0-9])/, "Password must include a number").regex(/(?=.*[a-z])/, "Password must include a lowercase letter").regex(/(?=.*[A-Z])/, "Password must include an uppercase letter").refine((value) => { return /(?=.*[!@#$%^&*(),.?":{}|<>-])/.test(value); }, { message: "Password must include a special symbol" }).openapi({ example: "Aa1!IJASSNOJ" }), username: z2.string().min(1).openapi({ example: "john.doe@example.com" }), // TODO: workaround TBD date: z2.string().refine((val) => { const date = new Date(val); return !isNaN(date.getTime()); }, { message: "Invalid date format" }), paramsId: { params: z2.object({ id }) }, paramsTestId: { params: z2.object({ testid: id }) }, success: z2.object({ message: z2.literal("success") }) }; // src/server/schemas/Check.schema.ts var CheckGetSchema = z3.object({ _id: commonValidations.id, name: z3.string().min(1).openapi({ description: "Name of the check", example: "Sample Check" }), test: commonValidations.id.openapi({ description: "Test identifier", example: "666acbe24fe1d2a67424ff60" }), suite: commonValidations.id.openapi({ description: "Suite identifier", example: "6651dd457c9186e315910b00" }), app: commonValidations.id.openapi({ description: "Application identifier", example: "6651dd45b9c3e1e0b8c1ce26" }), branch: z3.string().min(1).openapi({ description: "Branch name", example: "master" }), baselineId: commonValidations.id.openapi({ description: "Baseline identifier", example: "6656ee01bac26a33185c9488" }), actualSnapshotId: commonValidations.id.openapi({ description: "Actual snapshot identifier", example: "666acbf04fe1d2a67424ffa4" }), diffId: commonValidations.id.openapi({ description: "Difference identifier", example: "666acbf04fe1d2a67424ffa9" }), updatedDate: commonValidations.date.openapi({ description: "Last update date of the check", example: "2024-06-13T10:37:36.264Z" }), status: z3.array(z3.string().min(1)).openapi({ description: "Status of the check", example: ["failed"] }), browserName: z3.string().min(1).openapi({ description: "Browser name used for the check", example: "chrome" }), browserVersion: z3.string().min(1).openapi({ description: "Browser version used for the check", example: "125" }), browserFullVersion: z3.string().min(1).openapi({ description: "Full browser version used for the check", example: "125.0.6422.142" }), viewport: z3.string().min(1).openapi({ description: "Viewport size used for the check", example: "1366x768" }), os: z3.string().min(1).openapi({ description: "Operating system used for the check", example: "macOS" }), result: z3.string().openapi({ description: "Result of the check", example: '{\n "isSameDimensions": false,\n "dimensionDifference": {\n "width": 24,\n "height": 8\n },\n "rawMisMatchPercentage": 67.38024135551241,\n "misMatchPercentage": "67.38",\n "analysisTime": 99,\n "executionTotalTime": "0,398753687",\n "totalCheckHandleTime": "0,431217924"\n}' }), run: commonValidations.id.openapi({ description: "Run identifier", example: "666acbe24fe1d2a67424ff5d" }), markedAs: z3.string().min(1).openapi({ description: "Status marked for the check", example: "accepted" }), markedDate: commonValidations.date.openapi({ description: "Marked date of the check", example: "2024-06-13T07:19:32.246Z" }), markedByUsername: z3.string().min(1).openapi({ description: "Username of the user who marked the check", example: "Administrator" }), creatorId: commonValidations.id.openapi({ description: "Identifier of the user who created the check", example: "66519e582c2c701cc438ce59" }), creatorUsername: z3.string().min(1).openapi({ description: "Username of the user who created the check", example: "Guest" }), failReasons: z3.array(z3.string().min(1)).openapi({ description: "Reasons for the check failure", example: ["wrong_dimensions", "different_images"] }), createdDate: commonValidations.date.openapi({ description: "Creation date of the check", example: "2024-06-13T10:37:36.721Z" }), id: commonValidations.id }); var CheckUpdateSchema = CheckGetSchema.omit({ id: true, _id: true }).partial(); var CheckAcceptSchema = z3.object({ baselineId: commonValidations.id.openapi({ description: "Baseline identifier to accept the check", example: "6651ec20917e9ce26f7c0849" }) }); export { CheckAcceptSchema, CheckGetSchema, CheckUpdateSchema }; //# sourceMappingURL=Check.schema.js.map