feat(core): add entity models (user, article, session, cookie)
This commit is contained in:
17
packages/core/src/entities/models/article.ts
Normal file
17
packages/core/src/entities/models/article.ts
Normal 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>;
|
||||||
15
packages/core/src/entities/models/cookie.ts
Normal file
15
packages/core/src/entities/models/cookie.ts
Normal 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;
|
||||||
|
};
|
||||||
9
packages/core/src/entities/models/index.ts
Normal file
9
packages/core/src/entities/models/index.ts
Normal 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";
|
||||||
9
packages/core/src/entities/models/session.ts
Normal file
9
packages/core/src/entities/models/session.ts
Normal 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>;
|
||||||
9
packages/core/src/entities/models/user.ts
Normal file
9
packages/core/src/entities/models/user.ts
Normal 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>;
|
||||||
Reference in New Issue
Block a user