@syngrisi/syngrisi
Version:
Syngrisi - Visual Testing Tool
179 lines (175 loc) • 6.48 kB
JavaScript
// src/server/schemas/Baseline.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/Baseline.schema.ts
var BaselineGetSchema = z3.object({
_id: commonValidations.id,
name: z3.string().min(1).openapi({
description: "Name of the baseline",
example: "Green Button"
}),
app: commonValidations.id.openapi({
description: "Application identifier for the baseline",
example: "6651dd45b9c3e1e0b8c1ce26"
}),
branch: z3.string().min(1).openapi({
description: "Branch name for the baseline",
example: "master"
}),
browserName: z3.string().min(1).openapi({
description: "Browser name used for the baseline",
example: "chrome"
}),
viewport: z3.string().min(1).openapi({
description: "Viewport size used for the baseline",
example: "1366x768"
}),
os: z3.string().min(1).openapi({
description: "Operating system used for the baseline",
example: "macOS"
}),
createdDate: commonValidations.date.openapi({
description: "Creation date of the baseline",
example: "2024-05-26T10:49:19.896Z"
}),
lastMarkedDate: commonValidations.date.openapi({
description: "Last marked date of the baseline",
example: "2024-05-26T10:49:19.852Z"
}),
markedAs: z3.string().min(1).openapi({
description: "Status marked for the baseline",
example: "accepted"
}),
markedById: commonValidations.id.openapi({
description: "Identifier of the user who marked the baseline",
example: "66519e582c2c701cc438ce59"
}),
markedByUsername: z3.string().min(1).openapi({
description: "Username of the user who marked the baseline",
example: "Guest"
}),
snapshootId: commonValidations.id.openapi({
description: "Snapshot identifier for the baseline",
example: "6651ec20917e9ce26f7c0849"
}),
toleranceThreshold: z3.number().min(0).max(100).openapi({
description: "Mismatch tolerance threshold in percent. If diff is less than or equal to this value, check can pass.",
example: 0.6
}).optional(),
id: commonValidations.id
});
var BaselinePutSchema = z3.object({
name: z3.string().min(1).openapi({
description: "Name of the baseline",
example: "Green Button"
}).optional(),
branch: z3.string().min(1).openapi({
description: "Branch name for the baseline",
example: "master"
}).optional(),
browserName: z3.string().min(1).openapi({
description: "Browser name used for the baseline",
example: "chrome"
}).optional(),
viewport: z3.string().min(1).openapi({
description: "Viewport size used for the baseline",
example: "1366x768"
}).optional(),
os: z3.string().min(1).openapi({
description: "Operating system used for the baseline",
example: "macOS"
}).optional(),
createdDate: commonValidations.date.openapi({
description: "Creation date of the baseline",
example: "2024-05-26T10:49:19.896Z"
}).optional(),
lastMarkedDate: commonValidations.date.openapi({
description: "Last marked date of the baseline",
example: "2024-05-26T10:49:19.852Z"
}).optional(),
markedAs: z3.string().min(1).openapi({
description: "Status marked for the baseline",
example: "accepted"
}).optional(),
markedById: commonValidations.id.openapi({
description: "Identifier of the user who marked the baseline",
example: "66519e582c2c701cc438ce59"
}).optional(),
markedByUsername: z3.string().min(1).openapi({
description: "Username of the user who marked the baseline",
example: "Guest"
}).optional(),
ignoreRegions: z3.string().openapi({
description: "JSON string representing regions to ignore during comparison",
example: '[{"left":0,"top":0,"right":100,"bottom":50}]'
}).optional(),
boundRegions: z3.string().openapi({
description: "JSON string representing the checked area (only compare within this region)",
example: '[{"left":0,"top":0,"right":500,"bottom":300}]'
}).optional(),
matchType: z3.enum(["antialiasing", "nothing", "colors"]).openapi({
description: "Comparison mode: nothing (standard), antialiasing (auto-ignore), or colors (ignore color differences)",
example: "nothing"
}).optional(),
toleranceThreshold: z3.number().min(0).max(100).openapi({
description: "Mismatch tolerance threshold in percent",
example: 0.6
}).optional()
});
export {
BaselineGetSchema,
BaselinePutSchema
};
//# sourceMappingURL=Baseline.schema.js.map