feat(media): full Clean Architecture scaffold
Media is now a complete vertical-feature package mirroring auth/blog structure: entities (models + errors), application (repositories + use-cases), infrastructure (real Payload-backed + mock siblings), interface-adapters (per-use-case controllers), DI (symbols + module + container + bind-production), integrations/api (mediaRouter), factory, contract suite, and feature integration tests. Wired into: - packages/core-api/src/root.ts (added `media: mediaRouter`) - apps/web-next/src/server/bind-production.ts (calls bindProductionMedia) - tsconfig.base.json (added @repo/media/api and ./di/bind-production aliases) 56 new tests in @repo/media (13 test files); core-api router test updated to assert media. procedures. All 26 turbo tasks green. Refactor log: §2, §4.1, §4.2, §5.1, §6.1 Spec: §6.5 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
5
packages/media/src/entities/errors/common.ts
Normal file
5
packages/media/src/entities/errors/common.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export class InputParseError extends Error {
|
||||
constructor(message: string, options?: ErrorOptions) {
|
||||
super(message, options);
|
||||
}
|
||||
}
|
||||
20
packages/media/src/entities/errors/media.test.ts
Normal file
20
packages/media/src/entities/errors/media.test.ts
Normal 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");
|
||||
});
|
||||
});
|
||||
5
packages/media/src/entities/errors/media.ts
Normal file
5
packages/media/src/entities/errors/media.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export class MediaNotFoundError extends Error {
|
||||
constructor(message = "Media not found", options?: ErrorOptions) {
|
||||
super(message, options);
|
||||
}
|
||||
}
|
||||
51
packages/media/src/entities/models/media.test.ts
Normal file
51
packages/media/src/entities/models/media.test.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
14
packages/media/src/entities/models/media.ts
Normal file
14
packages/media/src/entities/models/media.ts
Normal 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>;
|
||||
Reference in New Issue
Block a user