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:
@@ -1,6 +1,6 @@
|
||||
import { eq, sql, and } from "drizzle-orm";
|
||||
import { db } from "../client";
|
||||
import { Issue } from "../schema";
|
||||
import { Issue } from "@issue/shared";
|
||||
|
||||
export async function createIssue(projectId: number, title: string, description: string) {
|
||||
// prevents two issues with the same unique number
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../client";
|
||||
import { Issue, Project, User } from "../schema";
|
||||
import { Issue, Project, User } from "@issue/shared";
|
||||
|
||||
export async function createProject(blob: string, name: string, ownerId: number) {
|
||||
const [project] = await db
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../client";
|
||||
import { User } from "../schema";
|
||||
import { User } from "@issue/shared";
|
||||
|
||||
export async function createUser(name: string, username: string) {
|
||||
const [user] = await db.insert(User).values({ name, username }).returning();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { db, testDB } from "./db/client";
|
||||
import { User } from "./db/schema";
|
||||
import { User } from "@issue/shared";
|
||||
import { routes } from "./routes";
|
||||
import { createDemoData } from "./utils";
|
||||
|
||||
|
||||
@@ -1,35 +1,36 @@
|
||||
{
|
||||
"name": "@issue/frontend",
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"preview": "vite preview",
|
||||
"tauri": "tauri dev"
|
||||
},
|
||||
"dependencies": {
|
||||
"@radix-ui/react-slot": "^1.2.4",
|
||||
"@tailwindcss/vite": "^4.1.18",
|
||||
"@tauri-apps/api": "^2",
|
||||
"@tauri-apps/plugin-opener": "^2",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"lucide-react": "^0.561.0",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"react-router-dom": "^7.10.1",
|
||||
"tailwind-merge": "^3.4.0",
|
||||
"tailwindcss": "^4.1.18"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tauri-apps/cli": "^2",
|
||||
"@types/node": "^25.0.1",
|
||||
"@types/react": "^19.1.8",
|
||||
"@types/react-dom": "^19.1.6",
|
||||
"@vitejs/plugin-react": "^4.6.0",
|
||||
"tw-animate-css": "^1.4.0",
|
||||
"typescript": "~5.8.3",
|
||||
"vite": "^7.0.4"
|
||||
}
|
||||
"name": "@issue/frontend",
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"preview": "vite preview",
|
||||
"tauri": "export __NV_DISABLE_EXPLICIT_SYNC=1 && tauri dev"
|
||||
},
|
||||
"dependencies": {
|
||||
"@issue/shared": "workspace:*",
|
||||
"@radix-ui/react-slot": "^1.2.4",
|
||||
"@tailwindcss/vite": "^4.1.18",
|
||||
"@tauri-apps/api": "^2",
|
||||
"@tauri-apps/plugin-opener": "^2",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"lucide-react": "^0.561.0",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"react-router-dom": "^7.10.1",
|
||||
"tailwind-merge": "^3.4.0",
|
||||
"tailwindcss": "^4.1.18"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tauri-apps/cli": "^2",
|
||||
"@types/node": "^25.0.1",
|
||||
"@types/react": "^19.1.8",
|
||||
"@types/react-dom": "^19.1.6",
|
||||
"@vitejs/plugin-react": "^4.6.0",
|
||||
"tw-animate-css": "^1.4.0",
|
||||
"typescript": "~5.8.3",
|
||||
"vite": "^7.0.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import { CloudSync, RefreshCw } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { IssueRecord } from "@issue/shared";
|
||||
|
||||
function Issue({ issue }: { issue: any }) {
|
||||
function Issue({ issue }: { issue: IssueRecord }) {
|
||||
return (
|
||||
<div className="w-sm p-4 border">
|
||||
import {Button} from "@/components/ui/button"; [{issue.id}] {issue.title}
|
||||
[{issue.id}] {issue.title}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Index() {
|
||||
const [issues, setIssues] = useState([]);
|
||||
const [issues, setIssues] = useState<IssueRecord[]>([]);
|
||||
|
||||
const serverURL = import.meta.env.SERVER_URL?.trim() || "http://localhost:3000";
|
||||
|
||||
@@ -45,14 +46,9 @@ function Index() {
|
||||
</div>
|
||||
|
||||
{issues.length > 0 && (
|
||||
<>
|
||||
{issues.map((issue: any) => (
|
||||
<Issue key={issue.id} issue={issue} />
|
||||
))}
|
||||
<pre className="w-2xl max-h-96 overflow-auto p-4 border bg-">
|
||||
{JSON.stringify(issues, null, 2)}
|
||||
</pre>
|
||||
</>
|
||||
<pre className="w-2xl max-h-96 overflow-auto p-4 border bg-">
|
||||
{JSON.stringify(issues, null, 2)}
|
||||
</pre>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
|
||||
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";
|
||||
@@ -1,4 +1,6 @@
|
||||
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(),
|
||||
@@ -34,3 +36,23 @@ export const Issue = pgTable(
|
||||
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