Pentagon seems nice?
This commit is contained in:
parent
0397843a92
commit
fc772c62f9
6 changed files with 72 additions and 22 deletions
|
@ -1,6 +1,6 @@
|
|||
[language-server.deno]
|
||||
command = "deno"
|
||||
args = ["lsp"]
|
||||
args = ["lsp", "--unstable-kv"]
|
||||
config.hostInfo = "helix"
|
||||
|
||||
[[language]]
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"lock": false,
|
||||
"tasks": {
|
||||
"check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx",
|
||||
"cli": "echo \"import '\\$fresh/src/dev/cli.ts'\" | deno run --unstable -A -",
|
||||
"cli": "echo \"import '\\$fresh/src/dev/cli.ts'\" | deno run -A -",
|
||||
"manifest": "deno task cli manifest $(pwd)",
|
||||
"start": "deno run -A --watch=static/,routes/ dev.ts",
|
||||
"build": "deno run -A dev.ts build",
|
||||
|
@ -41,5 +41,6 @@
|
|||
"semiColons": false,
|
||||
"singleQuote": true
|
||||
},
|
||||
"unstable": ["kv"],
|
||||
"nodeModulesDir": true
|
||||
}
|
||||
|
|
1
main.ts
1
main.ts
|
@ -3,6 +3,7 @@
|
|||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
/// <reference lib="deno.unstable" />
|
||||
|
||||
import '$std/dotenv/load.ts'
|
||||
|
||||
|
|
66
models.ts
66
models.ts
|
@ -1,13 +1,59 @@
|
|||
type Name = string
|
||||
import { z } from 'https://deno.land/x/zod@v3.21.4/mod.ts'
|
||||
import { createPentagon } from 'https://deno.land/x/pentagon@v0.1.5/mod.ts'
|
||||
import { ulid } from 'https://deno.land/x/ulid@v0.3.0/mod.ts'
|
||||
|
||||
export interface FamilyMember {
|
||||
name: Name
|
||||
avatarUrl?: URL
|
||||
const kv = await Deno.openKv()
|
||||
|
||||
const User = z.object({
|
||||
id: z.string().ulid().describe('primary'),
|
||||
createdAt: z.date(),
|
||||
|
||||
name: z.string(),
|
||||
avatarUrl: z.string().nullable(),
|
||||
})
|
||||
export type User = z.infer<typeof User>
|
||||
|
||||
const Todo = z.object({
|
||||
id: z.string().ulid().describe('primary'),
|
||||
createdAt: z.date(),
|
||||
|
||||
description: z.string(),
|
||||
emoji: z.string().nullable(),
|
||||
|
||||
doneAt: z.date().nullable(),
|
||||
assigneeUserId: z.string().ulid().nullable(),
|
||||
})
|
||||
export type Todo = z.infer<typeof Todo>
|
||||
|
||||
export const db = createPentagon(kv, {
|
||||
users: {
|
||||
schema: User,
|
||||
relations: {
|
||||
assignedTodos: ['todos', [Todo], 'id', 'assigneeUserId'],
|
||||
},
|
||||
},
|
||||
todos: {
|
||||
schema: Todo,
|
||||
relations: {
|
||||
assignee: ['users', User, 'assigneeUserId', 'id'],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const daddy: User = {
|
||||
id: ulid(),
|
||||
createdAt: new Date(),
|
||||
name: 'Daddy',
|
||||
avatarUrl: null,
|
||||
}
|
||||
const todo: Todo = {
|
||||
emoji: null,
|
||||
id: ulid(),
|
||||
createdAt: new Date(),
|
||||
description: 'Test Todo',
|
||||
doneAt: null,
|
||||
assigneeUserId: daddy.id,
|
||||
}
|
||||
|
||||
export interface ToDo {
|
||||
emoji?: string
|
||||
description: string
|
||||
doneAt?: Date
|
||||
assigneeName?: Name
|
||||
}
|
||||
db.todos.create({ data: todo })
|
||||
db.users.create({ data: daddy })
|
||||
|
|
|
@ -8,7 +8,7 @@ export default function App({ Component }: PageProps) {
|
|||
<title>homeman-deno</title>
|
||||
<link rel='stylesheet' href='/styles.css' />
|
||||
</head>
|
||||
<body>
|
||||
<body class='dark:bg-zinc-950 dark:text-zinc-100'>
|
||||
meow
|
||||
<Component />
|
||||
</body>
|
||||
|
|
|
@ -1,25 +1,27 @@
|
|||
import { Handlers } from '$fresh/server.ts'
|
||||
import { Handlers, PageProps } from '$fresh/server.ts'
|
||||
import { useSignal } from '@preact/signals'
|
||||
import Counter from '../islands/Counter.tsx'
|
||||
import { FamilyMember, ToDo } from '$models'
|
||||
import { db, Todo, User } from '$models'
|
||||
|
||||
interface Data {
|
||||
familyMembers: FamilyMember[]
|
||||
todos: ToDo[]
|
||||
users: User[]
|
||||
unassignedTodos: Todo[]
|
||||
}
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(_req, ctx) {
|
||||
const resp = await ctx.render()
|
||||
resp.headers.set('X-Custom-Header', 'Hello')
|
||||
return resp
|
||||
const users = await db.users.findMany({ include: { assignedTodos: true } })
|
||||
const unassignedTodos = await db.todos.findMany({
|
||||
where: { assigneeUserId: null },
|
||||
})
|
||||
return ctx.render({ users, unassignedTodos })
|
||||
},
|
||||
}
|
||||
|
||||
export default function Home() {
|
||||
export default function Home(props: PageProps<Data>) {
|
||||
const count = useSignal(3)
|
||||
return (
|
||||
<div class='px-4 py-8 mx-auto bg-[#86efac]'>
|
||||
<div class='px-4 py-8 mx-auto bg-emerald-950'>
|
||||
<div class='max-w-screen-md mx-auto flex flex-col items-center justify-center'>
|
||||
<img
|
||||
class='my-6'
|
||||
|
|
Loading…
Reference in a new issue