Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: admin pannel #409

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"imports": {
"@/": "./",
"$fresh/": "https://deno.land/x/fresh@1.3.0/",
"$fresh/": "https://raw.githubusercontent.com/deer/fresh/feat_plugin_islands/",
"$gfm": "https://deno.land/x/gfm@0.2.4/mod.ts",
"preact": "https://esm.sh/preact@10.15.1",
"preact/": "https://esm.sh/preact@10.15.1/",
Expand All @@ -32,6 +32,8 @@
"feed": "https://esm.sh/feed@4.2.2",
"kv_oauth": "https://deno.land/x/deno_kv_oauth@v0.2.5/mod.ts",
"@twind/core": "https://esm.sh/@twind/core@1.1.3",
"pentagon/": "https://deno.land/x/pentagon@v0.1.2/",
"z": "https://deno.land/x/zod@v3.21.4/mod.ts",
"fresh_charts/": "https://deno.land/x/fresh_charts@0.3.1/"
},
"exclude": [
Expand Down
14 changes: 13 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
/// <reference lib="deno.ns" />
/// <reference lib="deno.unstable" />

import * as path from "std/path/mod.ts";
import { start } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts";

import twindPlugin from "$fresh/plugins/twindv1.ts";
import twindConfig from "./twind.config.ts";

import {
kvAdminPlugin,
} from "https://github.com/raw/deer/fresh_kv_admin/main/mod.ts";

/**
* @todo Remove at v1. This is a quick way to reset Deno KV, as database changes are likely to occur and require reset.
*/
Expand All @@ -29,4 +34,11 @@ if (Deno.env.get("MIGRATE_DENO_KEY") === "1") {
await migrateKv();
}

await start(manifest, { plugins: [twindPlugin(twindConfig)] });
await start(manifest, {
plugins: [
twindPlugin(twindConfig),
await kvAdminPlugin({
modelPath: path.join(path.dirname(import.meta.url), "utils/types.ts"),
}),
],
});
28 changes: 28 additions & 0 deletions utils/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// import { Item } from "./db.ts";
import { TableDefinition } from "pentagon/src/types.ts";
import { z } from "z";

export interface Item {
userId: string;
title: string;
url: string;
// The below properties can be automatically generated upon item creation
id: string;
createdAt: Date;
score: number;
}

const item = z.object({
id: z.string().uuid().describe("primary"),
createdAt: z.coerce.date(),
score: z.coerce.number(),
url: z.string(),
title: z.string(),
userId: z.string().uuid(),
});

export const schema: Record<string, TableDefinition> = {
items: {
schema: item,
},
};
Loading