From 8b6a86f17a7e272111111a827f45fd7787afac8f Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Fri, 24 May 2024 13:04:36 +0200 Subject: [PATCH] feur --- .vscode/settings.json | 1 + api/login.ts | 7 ++++++ deno.lock | 5 +++++ lib/storage.ts | 45 ++++++++++++++++++++++++++++++++++++++ lib/utils.ts | 4 ++++ main.ts | 14 +++++++----- pages/components/login.tsx | 11 ++++++---- pages/login.tsx | 18 +++++++++++++++ 8 files changed, 95 insertions(+), 10 deletions(-) create mode 100644 api/login.ts create mode 100644 lib/storage.ts create mode 100644 pages/login.tsx diff --git a/.vscode/settings.json b/.vscode/settings.json index 963e37d..002a080 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,6 @@ "./" ], "deno.enable": true, + "deno.unstable": true, "editor.inlayHints.enabled": "off" } \ No newline at end of file diff --git a/api/login.ts b/api/login.ts new file mode 100644 index 0000000..5d68c0a --- /dev/null +++ b/api/login.ts @@ -0,0 +1,7 @@ +import { Context } from "https://deno.land/x/hono@v4.3.10/mod.ts"; +import { Env } from "https://deno.land/x/hono@v4.3.10/mod.ts"; +import { BlankInput } from "https://deno.land/x/hono@v4.3.10/types.ts"; + +export function login_route(context: Context) { + return context.text("E"); +} diff --git a/deno.lock b/deno.lock index e80198a..0162744 100644 --- a/deno.lock +++ b/deno.lock @@ -42,6 +42,7 @@ "https://deno.land/x/hono@v4.3.10/adapter/deno/serve-static.ts": "db226d30f08f1a8bb77653ead42a911357b2f8710d653e43c01eccebb424b295", "https://deno.land/x/hono@v4.3.10/client/client.ts": "dcda3887257fa3164db7b32c56665c6e757f0ef047a14f3f9599ef41725c1525", "https://deno.land/x/hono@v4.3.10/client/index.ts": "30def535310a37bede261f1b23d11a9758983b8e9d60a6c56309cee5f6746ab2", + "https://deno.land/x/hono@v4.3.10/client/types.ts": "73fbec704cf968ca5c5bba10aa1131758c52ab31a78301451c79cfc47368d43c", "https://deno.land/x/hono@v4.3.10/client/utils.ts": "8be84b49c5c7952666875a8e901fde3044c85c853ea6ba3a7e2c0468478459c0", "https://deno.land/x/hono@v4.3.10/compose.ts": "37d6e33b7db80e4c43a0629b12fd3a1e3406e7d9e62a4bfad4b30426ea7ae4f1", "https://deno.land/x/hono@v4.3.10/context.ts": "facfd749d823a645039571d66d9d228f5ae6836818b65d3b6c4c6891adfe071e", @@ -64,6 +65,7 @@ "https://deno.land/x/hono@v4.3.10/jsx/dom/utils.ts": "5d3e8c14996902db9c1223041fb21480fa0e921a4ccdc59f8c7571c08b7810f2", "https://deno.land/x/hono@v4.3.10/jsx/hooks/index.ts": "b7e0f0a754f31a1e1fbe0ac636b38b031603eb0ae195c32a30769a11d79fb871", "https://deno.land/x/hono@v4.3.10/jsx/index.ts": "fe3e582c2a4e24e5f8b6027925bddccaae0283747d8f0161eb6f5a34616edd11", + "https://deno.land/x/hono@v4.3.10/jsx/intrinsic-elements.ts": "21c3a8f6ba07f0d7d7c0ec7293c79c26b9b62df2894e26cb6c17b6c7ec381264", "https://deno.land/x/hono@v4.3.10/jsx/streaming.ts": "5e5dde9a546041353b9a3860fc9020471f762813f10e1290009ab6bd40e7bdcf", "https://deno.land/x/hono@v4.3.10/jsx/types.ts": "51c2bdbb373860e2570ad403546a7fdbbb1cf00a47ce7ed10b2aece922031ac4", "https://deno.land/x/hono@v4.3.10/jsx/utils.ts": "4b8299d402ba5395472c552d1fe3297ee60112bfc32e0ef86cfe8e40086f7d54", @@ -102,6 +104,7 @@ "https://deno.land/x/hono@v4.3.10/router/trie-router/index.ts": "3eb75e7f71ba81801631b30de6b1f5cefb2c7239c03797e2b2cbab5085911b41", "https://deno.land/x/hono@v4.3.10/router/trie-router/node.ts": "d3e00e8f1ba7fb26896459d5bba882356891a07793387c4655d1864c519a91de", "https://deno.land/x/hono@v4.3.10/router/trie-router/router.ts": "54ced78d35676302c8fcdda4204f7bdf5a7cc907fbf9967c75674b1e394f830d", + "https://deno.land/x/hono@v4.3.10/types.ts": "b561c3ee846121b33c2d81331246cdedf7781636ed72dad7406677105b4275de", "https://deno.land/x/hono@v4.3.10/utils/body.ts": "774cb319dfbe886a9d39f12c43dea15a39f9d01e45de0323167cdd5d0aad14d4", "https://deno.land/x/hono@v4.3.10/utils/buffer.ts": "2fae689954b427b51fb84ad02bed11a72eae96692c2973802b3b4c1e39cd5b9c", "https://deno.land/x/hono@v4.3.10/utils/color.ts": "10575c221f48bc806887710da8285f859f51daf9e6878bbdf99cb406b8494457", @@ -110,6 +113,7 @@ "https://deno.land/x/hono@v4.3.10/utils/encode.ts": "311dfdfae7eb0b6345e9680f7ebbb3a692e872ed964e2029aca38567af8d1f33", "https://deno.land/x/hono@v4.3.10/utils/filepath.ts": "a83e5fe87396bb291a6c5c28e13356fcbea0b5547bad2c3ba9660100ff964000", "https://deno.land/x/hono@v4.3.10/utils/html.ts": "6ea4f6bf41587a51607dff7a6d2865ef4d5001e4203b07e5c8a45b63a098e871", + "https://deno.land/x/hono@v4.3.10/utils/http-status.ts": "f5b820f2793e45209f34deddf147b23e3133a89eb4c57dc643759a504706636b", "https://deno.land/x/hono@v4.3.10/utils/jwt/index.ts": "3b66f48cdd3fcc2caed5e908ca31776e11b1c30391008931276da3035e6ba1e9", "https://deno.land/x/hono@v4.3.10/utils/jwt/jwa.ts": "6874cacd8b6dde386636b81b5ea2754f8e4c61757802fa908dd1ce54b91a52fa", "https://deno.land/x/hono@v4.3.10/utils/jwt/jws.ts": "878fa7d1966b0db20ae231cfee279ba2bb198943e949049cab3f5845cd5ee2d1", @@ -117,6 +121,7 @@ "https://deno.land/x/hono@v4.3.10/utils/jwt/types.ts": "b6659ac85e7f8fcdd8cdfc7d51f5d1a91107ad8dfb647a8e4ea9c80f0f02afee", "https://deno.land/x/hono@v4.3.10/utils/jwt/utf8.ts": "17c507f68f23ccb82503ea6183e54b5f748a6fe621eb60994adfb4a8c2a3f561", "https://deno.land/x/hono@v4.3.10/utils/mime.ts": "d1fc2c047191ccb01d736c6acf90df731324536298181dba0ecc2259e5f7d661", + "https://deno.land/x/hono@v4.3.10/utils/types.ts": "050bfa9dc6d0cc4b7c5069944a8bd60066c2f9f95ee69833623ad104f11f92bf", "https://deno.land/x/hono@v4.3.10/utils/url.ts": "855169632c61d03703bd08cafb27664ba3fdb352892f01687d5cce8fd49e3cb1", "https://deno.land/x/hono@v4.3.10/validator/index.ts": "6c986e8b91dcf857ecc8164a506ae8eea8665792a4ff7215471df669c632ae7c", "https://deno.land/x/hono@v4.3.10/validator/validator.ts": "53f3d2ad442e22f0bc2d85b7d8d90320d4e5ecf5fdd58882f906055d33a18e13", diff --git a/lib/storage.ts b/lib/storage.ts new file mode 100644 index 0000000..ede87b8 --- /dev/null +++ b/lib/storage.ts @@ -0,0 +1,45 @@ +import { z } from "https://deno.land/x/zod@v3.23.8/mod.ts"; + +class Store { + kv; + + private constructor(kv: Deno.Kv) { + this.kv = kv; + } +} + +class Schema> { + descriptor; + + constructor(descriptor: T) { + this.descriptor = descriptor; + } +} + +type SchemaDescriptor> = { + tables: T; +}; + +type TablesDescriptor> = { + [name: string]: TableDescr; +}; + +type TableDescr, Name extends keyof Tables, S extends z.ZodRawShape> = { + structure: z.ZodObject; + relations: Relations; +}; + +type Relations, Name extends keyof Tables, S extends z.ZodRawShape> = { + [name in Exclude]?: [keyof S, keyof z.infer]; +}; + +const store = new Schema({ + "user": { + structure: z.object({ feur_id: z.string() }), + relations: { "feur": ["_feur_id", "id"] }, + }, + "feur": { + structure: z.object({ id: z.string(), content: z.string() }), + relations: {}, + }, +}); diff --git a/lib/utils.ts b/lib/utils.ts index fdbaea4..e29749c 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -3,3 +3,7 @@ import { CSSProperties } from "https://deno.land/std@0.40.0/types/react.d.ts"; export function _css(prop: CSSProperties) { return prop; } + +// type wizardry + +export type KeysOfType = keyof { [P in keyof T as T[P] extends V ? P : never]: P }; diff --git a/main.ts b/main.ts index 2d3f230..1914446 100755 --- a/main.ts +++ b/main.ts @@ -8,13 +8,15 @@ const app = new Hono(); app.use("/static/*", serveStatic({ root: "./pages/" })); app.use("/user", basicAuth({ username: "feur", password: "feur" })); // todo : transition to verify_user -app.get("/", (c) => { - return c.html("Hello Hono!"); -}); +app.get("/", (c) => c.redirect("/home")); import HomePage from "./pages/home.tsx"; -app.get("/home", (c) => { - return c.html(HomePage()); -}); +app.get("/home", (c) => c.html(HomePage())); + +import LoginPage from "./pages/login.tsx"; +app.get("/login", (c) => c.html(LoginPage())); + +import { login_route } from "./api/login.ts"; +app.post("/api/login", (c) => login_route(c)); Deno.serve(app.fetch); diff --git a/pages/components/login.tsx b/pages/components/login.tsx index ce8014e..358f0f5 100644 --- a/pages/components/login.tsx +++ b/pages/components/login.tsx @@ -3,7 +3,10 @@ import { jsx } from "https://deno.land/x/hono@v4.3.10/middleware.ts" export default function Login() { - return (
- -
) -} \ No newline at end of file + return ( +
+ + +
+ ) +} diff --git a/pages/login.tsx b/pages/login.tsx new file mode 100644 index 0000000..1eeab01 --- /dev/null +++ b/pages/login.tsx @@ -0,0 +1,18 @@ +/** @jsx jsx */ + +import { jsx } from "https://deno.land/x/hono@v4.3.10/middleware.ts" +import { BasePage } from "./components/base.tsx"; +import Heading from "./components/heading.tsx"; +import Main from "./components/main.tsx"; +import Login from "./components/login.tsx"; + +export default function LoginPage() { + return ( + +
+

Login

+ +
+
+ ) +}