Initial commit

This commit is contained in:
fraqtal
2026-07-12 08:15:46 +00:00
commit ee0fec0691
1397 changed files with 127242 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
export class InputParseError extends Error {
constructor(message: string, options?: ErrorOptions) {
super(message, options);
this.name = "InputParseError";
}
}

View File

@@ -0,0 +1,20 @@
import { describe, it, expect } from "vitest";
import { MediaNotFoundError } from "@/entities/errors/media";
describe("MediaNotFoundError", () => {
it("is an instance of Error", () => {
const err = new MediaNotFoundError();
expect(err).toBeInstanceOf(Error);
expect(err).toBeInstanceOf(MediaNotFoundError);
});
it("has default message", () => {
const err = new MediaNotFoundError();
expect(err.message).toBe("Media not found");
});
it("accepts a custom message", () => {
const err = new MediaNotFoundError("Custom message");
expect(err.message).toBe("Custom message");
});
});

View File

@@ -0,0 +1,6 @@
export class MediaNotFoundError extends Error {
constructor(message = "Media not found", options?: ErrorOptions) {
super(message, options);
this.name = "MediaNotFoundError";
}
}

View File

@@ -0,0 +1,51 @@
import { describe, it, expect } from "vitest";
import { mediaSchema } from "@/entities/models/media";
describe("mediaSchema", () => {
it("parses a valid media object", () => {
const result = mediaSchema.parse({
id: "1",
alt: "A photo",
url: "https://cdn.example.com/photo.png",
filename: "photo.png",
mimeType: "image/png",
filesize: 1024,
});
expect(result.id).toBe("1");
expect(result.alt).toBe("A photo");
});
it("parses a media object with optional width and height", () => {
const result = mediaSchema.parse({
id: "2",
alt: "A photo",
url: "https://cdn.example.com/photo.png",
filename: "photo.png",
mimeType: "image/png",
filesize: 2048,
width: 1920,
height: 1080,
});
expect(result.width).toBe(1920);
expect(result.height).toBe(1080);
});
it("parses without width and height (optional)", () => {
const result = mediaSchema.parse({
id: "3",
alt: "Doc",
url: "https://cdn.example.com/doc.pdf",
filename: "doc.pdf",
mimeType: "application/pdf",
filesize: 512,
});
expect(result.width).toBeUndefined();
expect(result.height).toBeUndefined();
});
it("throws for missing required fields", () => {
expect(() =>
mediaSchema.parse({ id: "1", alt: "x", url: "x" }),
).toThrow();
});
});

View File

@@ -0,0 +1,14 @@
import { z } from "zod";
export const mediaSchema = z.object({
id: z.string(),
alt: z.string(),
url: z.string(),
filename: z.string(),
mimeType: z.string(),
filesize: z.number(),
width: z.number().optional(),
height: z.number().optional(),
});
export type Media = z.infer<typeof mediaSchema>;