Pentagon seems nice?
This commit is contained in:
parent
0397843a92
commit
fc772c62f9
|
@ -1,6 +1,6 @@
|
||||||
[language-server.deno]
|
[language-server.deno]
|
||||||
command = "deno"
|
command = "deno"
|
||||||
args = ["lsp"]
|
args = ["lsp", "--unstable-kv"]
|
||||||
config.hostInfo = "helix"
|
config.hostInfo = "helix"
|
||||||
|
|
||||||
[[language]]
|
[[language]]
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"lock": false,
|
"lock": false,
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx",
|
"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)",
|
"manifest": "deno task cli manifest $(pwd)",
|
||||||
"start": "deno run -A --watch=static/,routes/ dev.ts",
|
"start": "deno run -A --watch=static/,routes/ dev.ts",
|
||||||
"build": "deno run -A dev.ts build",
|
"build": "deno run -A dev.ts build",
|
||||||
|
@ -41,5 +41,6 @@
|
||||||
"semiColons": false,
|
"semiColons": false,
|
||||||
"singleQuote": true
|
"singleQuote": true
|
||||||
},
|
},
|
||||||
|
"unstable": ["kv"],
|
||||||
"nodeModulesDir": true
|
"nodeModulesDir": true
|
||||||
}
|
}
|
||||||
|
|
1
main.ts
1
main.ts
|
@ -3,6 +3,7 @@
|
||||||
/// <reference lib="dom.iterable" />
|
/// <reference lib="dom.iterable" />
|
||||||
/// <reference lib="dom.asynciterable" />
|
/// <reference lib="dom.asynciterable" />
|
||||||
/// <reference lib="deno.ns" />
|
/// <reference lib="deno.ns" />
|
||||||
|
/// <reference lib="deno.unstable" />
|
||||||
|
|
||||||
import '$std/dotenv/load.ts'
|
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 {
|
const kv = await Deno.openKv()
|
||||||
name: Name
|
|
||||||
avatarUrl?: URL
|
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 {
|
db.todos.create({ data: todo })
|
||||||
emoji?: string
|
db.users.create({ data: daddy })
|
||||||
description: string
|
|
||||||
doneAt?: Date
|
|
||||||
assigneeName?: Name
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ export default function App({ Component }: PageProps) {
|
||||||
<title>homeman-deno</title>
|
<title>homeman-deno</title>
|
||||||
<link rel='stylesheet' href='/styles.css' />
|
<link rel='stylesheet' href='/styles.css' />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body class='dark:bg-zinc-950 dark:text-zinc-100'>
|
||||||
meow
|
meow
|
||||||
<Component />
|
<Component />
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -1,25 +1,27 @@
|
||||||
import { Handlers } from '$fresh/server.ts'
|
import { Handlers, PageProps } from '$fresh/server.ts'
|
||||||
import { useSignal } from '@preact/signals'
|
import { useSignal } from '@preact/signals'
|
||||||
import Counter from '../islands/Counter.tsx'
|
import Counter from '../islands/Counter.tsx'
|
||||||
import { FamilyMember, ToDo } from '$models'
|
import { db, Todo, User } from '$models'
|
||||||
|
|
||||||
interface Data {
|
interface Data {
|
||||||
familyMembers: FamilyMember[]
|
users: User[]
|
||||||
todos: ToDo[]
|
unassignedTodos: Todo[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
async GET(_req, ctx) {
|
async GET(_req, ctx) {
|
||||||
const resp = await ctx.render()
|
const users = await db.users.findMany({ include: { assignedTodos: true } })
|
||||||
resp.headers.set('X-Custom-Header', 'Hello')
|
const unassignedTodos = await db.todos.findMany({
|
||||||
return resp
|
where: { assigneeUserId: null },
|
||||||
|
})
|
||||||
|
return ctx.render({ users, unassignedTodos })
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home(props: PageProps<Data>) {
|
||||||
const count = useSignal(3)
|
const count = useSignal(3)
|
||||||
return (
|
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'>
|
<div class='max-w-screen-md mx-auto flex flex-col items-center justify-center'>
|
||||||
<img
|
<img
|
||||||
class='my-6'
|
class='my-6'
|
||||||
|
|
Loading…
Reference in a new issue