feat(core): add entity models (user, article, session, cookie)

This commit is contained in:
2026-04-06 14:23:54 +02:00
parent fe70a48702
commit 18bde6ca4c
5 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
import { z } from "zod";
export const articleStatusSchema = z.enum(["draft", "published"]);
export const articleSchema = z.object({
id: z.string(),
title: z.string().min(1).max(255),
slug: z.string().min(1).max(255),
content: z.string(),
status: articleStatusSchema.default("draft"),
authorId: z.string(),
createdAt: z.date(),
updatedAt: z.date(),
});
export type Article = z.infer<typeof articleSchema>;
export type ArticleStatus = z.infer<typeof articleStatusSchema>;

View File

@@ -0,0 +1,15 @@
type CookieAttributes = {
secure?: boolean;
path?: string;
domain?: string;
sameSite?: "lax" | "strict" | "none";
httpOnly?: boolean;
maxAge?: number;
expires?: Date;
};
export type Cookie = {
name: string;
value: string;
attributes: CookieAttributes;
};

View File

@@ -0,0 +1,9 @@
export { userSchema, type User } from "./user.js";
export {
articleSchema,
articleStatusSchema,
type Article,
type ArticleStatus,
} from "./article.js";
export { sessionSchema, type Session } from "./session.js";
export type { Cookie } from "./cookie.js";

View File

@@ -0,0 +1,9 @@
import { z } from "zod";
export const sessionSchema = z.object({
id: z.string(),
userId: z.string(),
expiresAt: z.date(),
});
export type Session = z.infer<typeof sessionSchema>;

View File

@@ -0,0 +1,9 @@
import { z } from "zod";
export const userSchema = z.object({
id: z.string(),
username: z.string().min(3).max(31),
passwordHash: z.string().min(6).max(255),
});
export type User = z.infer<typeof userSchema>;