mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
shared zod types and drizzle schema
This commit is contained in:
2
packages/shared/.gitignore
vendored
Normal file
2
packages/shared/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
dist
|
||||
@@ -1,13 +1,24 @@
|
||||
{
|
||||
"name": "@issue/shared",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"packageManager": "pnpm@10.17.1"
|
||||
"name": "@issue/shared",
|
||||
"version": "1.0.0",
|
||||
"description": "Shared schemas and types for the issue monorepo",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"dev": "tsc --watch"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"packageManager": "pnpm@10.17.1",
|
||||
"devDependencies": {
|
||||
"typescript": "^5.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"drizzle-orm": "^0.45.0",
|
||||
"drizzle-zod": "^0.5.1",
|
||||
"zod": "^3.23.8"
|
||||
}
|
||||
}
|
||||
|
||||
22
packages/shared/src/index.ts
Normal file
22
packages/shared/src/index.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// Drizzle tables
|
||||
export { User, Project, Issue } from "./schema";
|
||||
|
||||
// Types
|
||||
export type {
|
||||
UserRecord,
|
||||
UserInsert,
|
||||
ProjectRecord,
|
||||
ProjectInsert,
|
||||
IssueRecord,
|
||||
IssueInsert,
|
||||
} from "./schema";
|
||||
|
||||
// Zod schemas
|
||||
export {
|
||||
UserSelectSchema,
|
||||
UserInsertSchema,
|
||||
ProjectSelectSchema,
|
||||
ProjectInsertSchema,
|
||||
IssueSelectSchema,
|
||||
IssueInsertSchema,
|
||||
} from "./schema";
|
||||
58
packages/shared/src/schema.ts
Normal file
58
packages/shared/src/schema.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { integer, pgTable, uniqueIndex, varchar } from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
|
||||
import { z } from "zod";
|
||||
|
||||
export const User = pgTable("User", {
|
||||
id: integer().primaryKey().generatedAlwaysAsIdentity(),
|
||||
name: varchar({ length: 256 }).notNull(),
|
||||
username: varchar({ length: 32 }).notNull().unique(),
|
||||
});
|
||||
|
||||
export const Project = pgTable("Project", {
|
||||
id: integer().primaryKey().generatedAlwaysAsIdentity(),
|
||||
blob: varchar({ length: 4 }).notNull(),
|
||||
name: varchar({ length: 256 }).notNull(),
|
||||
ownerId: integer()
|
||||
.notNull()
|
||||
.references(() => User.id),
|
||||
});
|
||||
|
||||
export const Issue = pgTable(
|
||||
"Issue",
|
||||
{
|
||||
id: integer().primaryKey().generatedAlwaysAsIdentity(),
|
||||
projectId: integer()
|
||||
.notNull()
|
||||
.references(() => Project.id),
|
||||
|
||||
number: integer("number").notNull(),
|
||||
|
||||
title: varchar({ length: 256 }).notNull(),
|
||||
description: varchar({ length: 2048 }).notNull(),
|
||||
},
|
||||
(t) => [
|
||||
// ensures unique numbers per project
|
||||
// you can have Issue 1 in PROJ and Issue 1 in TEST, but not two Issue 1s in PROJ
|
||||
uniqueIndex("unique_project_issue_number").on(t.projectId, t.number),
|
||||
],
|
||||
);
|
||||
|
||||
// Zod schemas
|
||||
export const UserSelectSchema = createSelectSchema(User);
|
||||
export const UserInsertSchema = createInsertSchema(User);
|
||||
|
||||
export const ProjectSelectSchema = createSelectSchema(Project);
|
||||
export const ProjectInsertSchema = createInsertSchema(Project);
|
||||
|
||||
export const IssueSelectSchema = createSelectSchema(Issue);
|
||||
export const IssueInsertSchema = createInsertSchema(Issue);
|
||||
|
||||
// Types
|
||||
export type UserRecord = z.infer<typeof UserSelectSchema>;
|
||||
export type UserInsert = z.infer<typeof UserInsertSchema>;
|
||||
|
||||
export type ProjectRecord = z.infer<typeof ProjectSelectSchema>;
|
||||
export type ProjectInsert = z.infer<typeof ProjectInsertSchema>;
|
||||
|
||||
export type IssueRecord = z.infer<typeof IssueSelectSchema>;
|
||||
export type IssueInsert = z.infer<typeof IssueInsertSchema>;
|
||||
17
packages/shared/tsconfig.json
Normal file
17
packages/shared/tsconfig.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"declaration": true,
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
Reference in New Issue
Block a user