Skip to content

Commit

Permalink
refactor: esm and jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCassiere committed Jun 30, 2024
1 parent 10b7260 commit f6b34b1
Show file tree
Hide file tree
Showing 29 changed files with 135 additions and 921 deletions.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
"keywords": [],
"private": true,
"packageManager": "[email protected]",
"main": "dist/index.js",
"main": "dist/index.mjs",
"type": "module",
"scripts": {
"lint": "eslint --max-warnings=0 src",
"lint:fix": "eslint --fix --max-warnings=0 src",
"format": "prettier --write 'src/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc",
"start": "NODE_ENV=production node dist/index.js",
"dev": "NODE_ENV=development tsx --watch ./src/index.ts",
"start": "NODE_ENV=production node dist/index.mjs",
"dev": "NODE_ENV=development tsx --watch ./src/index.mts",
"test": "NODE_ENV=test vitest",
"test:ci": "NODE_ENV=ci vitest run",
"build:kill-dist": "rimraf ./dist",
"build:code": "tsc && tscpaths -p tsconfig.json -s ./src -o ./dist",
"build:code": "tsc && tsc-alias",
"build": "pnpm run build:kill-dist && pnpm run build:code",
"postbuild": "node postbuild.mjs",
"db:explorer": "drizzle-kit studio",
Expand All @@ -35,7 +36,7 @@
"pg": "^8.12.0",
"prettier": "^3.3.2",
"rimraf": "^5.0.7",
"tscpaths": "^0.0.9",
"tsc-alias": "^1.8.10",
"tsx": "^4.15.7",
"typescript": "^5.5.2",
"vite-tsconfig-paths": "^4.3.2",
Expand Down
885 changes: 38 additions & 847 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/config/db/drizzle.ts → src/config/db/drizzle.mts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";

import { env } from "@/config/env";
import * as schema from "./schema";
import { env } from "@/config/env.mjs";
import * as schema from "./schema.mjs";

const client = postgres(env.DATABASE_URL);
export const db = drizzle(client, { schema, logger: true });
1 change: 1 addition & 0 deletions src/config/db/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { db } from "./drizzle.mjs";
1 change: 0 additions & 1 deletion src/config/db/index.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/config/lucia/adapter.ts → src/config/lucia/adapter.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { db } from "@/config/db";
import type { sessions, users } from "@/config/db/schema";
import type { db } from "@/config/db/index.mjs";
import type { sessions, users } from "@/config/db/schema.mjs";
import { eq, lte } from "drizzle-orm";
import type { Adapter, DatabaseSession, DatabaseUser, UserId } from "lucia";

Expand Down
8 changes: 4 additions & 4 deletions src/config/lucia/index.ts → src/config/lucia/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { GitHub } from "arctic";
import type { DatabaseUser } from "lucia";
import { Lucia } from "lucia";

import { db } from "@/config/db";
import { sessions, users } from "@/config/db/schema";
import { env } from "@/config/env";
import { DrizzleLuciaAdapter } from "./adapter";
import { db } from "@/config/db/index.mjs";
import { sessions, users } from "@/config/db/schema.mjs";
import { env } from "@/config/env.mjs";
import { DrizzleLuciaAdapter } from "./adapter.mjs";

export interface LuciaUser extends DatabaseUser {
username: (typeof users.$inferSelect)["username"];
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts → src/index.mts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { serve } from "@hono/node-server";

import { env } from "@/config/env";
import { openapiYmlVersioner, transformOpenapiYmlDoc } from "@/utils/openapi-docs";
import { getPackageInfo } from "@/utils/package";
import { env } from "@/config/env.mjs";
import { openapiYmlVersioner, transformOpenapiYmlDoc } from "@/utils/openapi-docs.mjs";
import { getPackageInfo } from "@/utils/package.mjs";

const packageJson = getPackageInfo();

import server from "./server";
import server from "./server.mjs";

if (env.FREEZE_DB_WRITES) {
console.warn("\n🚨 Database writes are currently frozen!!!\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { Hono } from "hono";
import { getCookie, setCookie } from "hono/cookie";
import { z } from "zod";

import { db } from "@/config/db";
import { db } from "@/config/db/index.mjs";
import {
tenants as tenantsTable,
users as usersTable,
usersToTenants as usersToTenantsTable,
} from "@/config/db/schema";
import { env } from "@/config/env";
import { github, lucia } from "@/config/lucia";
import { createDbId } from "@/utils/db";
} from "@/config/db/schema.mjs";
import { env } from "@/config/env.mjs";
import { github, lucia } from "@/config/lucia/index.mjs";
import { createDbId } from "@/utils/db.mjs";

import type { ServerContext } from "@/types/hono";
import type { ServerContext } from "@/types/hono.mjs";

const app = new Hono<ServerContext>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ServerContext } from "@/types/hono";
import type { ServerContext } from "@/types/hono.mjs";
import { Hono } from "hono";

import { lucia } from "@/config/lucia";
import { lucia } from "@/config/lucia/index.mjs";

import githubAuthRouter from "./github";
import githubAuthRouter from "./github.mjs";

const app = new Hono<ServerContext>();

Expand Down
8 changes: 4 additions & 4 deletions src/routers/app/index.ts → src/routers/app/index.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ServerContext } from "@/types/hono";
import type { ServerContext } from "@/types/hono.mjs";
import { Hono } from "hono";

import { lucia } from "@/config/lucia";
import { lucia } from "@/config/lucia/index.mjs";

import authRouter from "./auth";
import uiRouter from "./ui";
import authRouter from "./auth/index.mjs";
import uiRouter from "./ui/index.js";

const app = new Hono<ServerContext>();

Expand Down
34 changes: 27 additions & 7 deletions src/routers/app/ui/index.ts → src/routers/app/ui/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
import type { ServerContext } from "@/types/hono";
import type { ServerContext } from "@/types/hono.mjs";
import { Hono } from "hono";
import { html } from "hono/html";
import type { FC } from "hono/jsx";

import { db } from "@/config/db";
import { db } from "@/config/db/index.mjs";

const app = new Hono<ServerContext>();

const Layout: FC = ({ children }) => {
return (
<html>
<head>
<script
src="https://unpkg.com/[email protected]"
integrity="sha384-D1Kt99CQMDuVetoL1lrYwg5t+9QdHe7NLX/SoJYkXDFfX37iInKRy5xLSi8nO7UC"
crossorigin="anonymous"
></script>
<script src="https://unpkg.com/htmx.org/dist/ext/json-enc.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>{children}</body>
</html>
);
};

app.get("/login", async (c) => {
const user = c.var.user;

if (user) {
return c.redirect("/app");
}

return c.render(
html`<div style="display: grid;gap: 0.5rem;">
<a href="/app/login/github">Login with Github</a>
<a href="/app">← Go back</a>
</div>`,
return c.html(
<Layout>
<div style="display: grid;gap: 0.5rem;">
<a href="/app/login/github">Login with Github</a>
<a href="/app">← Go back</a>
</div>
</Layout>,
);
});

Expand Down
4 changes: 2 additions & 2 deletions src/routers/docs/index.ts → src/routers/docs/index.mts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Hono } from "hono";

import type { ServerContext } from "@/types/hono";
import type { ServerContext } from "@/types/hono.mjs";

import v2DocsRouter from "./v2";
import v2DocsRouter from "./v2.mjs";

const app = new Hono<ServerContext>();

Expand Down
2 changes: 1 addition & 1 deletion src/routers/docs/v2.ts → src/routers/docs/v2.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { apiReference } from "@scalar/hono-api-reference";
import { Hono } from "hono";

import type { ServerContext } from "@/types/hono";
import type { ServerContext } from "@/types/hono.mjs";

const app = new Hono<ServerContext>();

Expand Down
6 changes: 3 additions & 3 deletions src/routers/v2/index.ts → src/routers/v2/index.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Hono } from "hono";
import { rateLimiter } from "hono-rate-limiter";

import type { ServerContext } from "@/types/hono";
import type { ServerContext } from "@/types/hono.mjs";

import logsRouter from "./logging";
import servicesRouter from "./services";
import logsRouter from "./logging/index.mjs";
import servicesRouter from "./services/index.mjs";

const app = new Hono<ServerContext>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { and, eq, lt } from "drizzle-orm";
import { Hono } from "hono";
import { HTTPException } from "hono/http-exception";

import { db } from "@/config/db";
import { logs as logsTable } from "@/config/db/schema";
import { env } from "@/config/env";
import type { ServerContext } from "@/types/hono";
import { createDbId } from "@/utils/db";
import { ENDPOINT_MESSAGES } from "@/utils/messages";
import { createV2ErrResponse, parseSearchParams, v2_serviceValidation } from "@/utils/server-helpers";

import { createLogOutputSchema, createLogSchema, getLogsFiltersSchema, getLogsOutputSchema } from "./schemas";
import { db } from "@/config/db/index.mjs";
import { logs as logsTable } from "@/config/db/schema.mjs";
import { env } from "@/config/env.mjs";
import type { ServerContext } from "@/types/hono.mjs";
import { createDbId } from "@/utils/db.mjs";
import { ENDPOINT_MESSAGES } from "@/utils/messages.mjs";
import { createV2ErrResponse, parseSearchParams, v2_serviceValidation } from "@/utils/server-helpers.mjs";

import { createLogOutputSchema, createLogSchema, getLogsFiltersSchema, getLogsOutputSchema } from "./schemas.mjs";

const app = new Hono<ServerContext>();

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ import { eq } from "drizzle-orm";
import { Hono } from "hono";
import { HTTPException } from "hono/http-exception";

import { db } from "@/config/db";
import { services as servicesTable } from "@/config/db/schema";
import type { ServerContext } from "@/types/hono";
import { createDbId } from "@/utils/db";
import { ENDPOINT_MESSAGES } from "@/utils/messages";
import { db } from "@/config/db/index.mjs";
import { services as servicesTable } from "@/config/db/schema.mjs";
import type { ServerContext } from "@/types/hono.mjs";
import { createDbId } from "@/utils/db.mjs";
import { ENDPOINT_MESSAGES } from "@/utils/messages.mjs";
import {
adminServiceValidation,
createV2ErrResponse,
parseSearchParams,
v2_serviceValidation,
} from "@/utils/server-helpers";
} from "@/utils/server-helpers.mjs";

import {
createServiceInputSchema,
createServiceOutputSchema,
getServiceFiltersSchema,
getServiceOutputSchema,
getServicesOutputSchema,
} from "./schemas";
} from "./schemas.mjs";

const app = new Hono<ServerContext>();

Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/server.ts → src/server.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ServerContext } from "@/types/hono";
import type { ServerContext } from "@/types/hono.mjs";
import { serveStatic } from "@hono/node-server/serve-static";
import { Hono } from "hono";
import { rateLimiter } from "hono-rate-limiter";
Expand All @@ -11,9 +11,9 @@ import { logger } from "hono/logger";
import { secureHeaders } from "hono/secure-headers";
import { timeout } from "hono/timeout";

import appRouter from "@/routers/app";
import docsRouter from "@/routers/docs";
import v2Router from "@/routers/v2";
import appRouter from "@/routers/app/index.mjs";
import docsRouter from "@/routers/docs/index.mjs";
import v2Router from "@/routers/v2/index.mjs";

const app = new Hono<ServerContext>();

Expand Down
2 changes: 1 addition & 1 deletion src/types/hono.ts → src/types/hono.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { HttpBindings } from "@hono/node-server";
import type { Session, User } from "lucia";

import type { services as servicesTable } from "@/config/db/schema";
import type { services as servicesTable } from "@/config/db/schema.mjs";
type Service = typeof servicesTable.$inferSelect;

type Bindings = HttpBindings & {};
Expand Down
2 changes: 1 addition & 1 deletion src/utils/db.ts → src/utils/db.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { env } from "@/config/env";
import { env } from "@/config/env.mjs";
import { createId } from "@paralleldrive/cuid2";

const dbPrefixes = {
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions src/utils/openapi-docs.ts → src/utils/openapi-docs.mts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ type OpenApiDocTransformer = (filename: string, source_path: string, dirVersion:
export function transformOpenapiYmlDoc(dir_version: string, transformers: OpenApiDocTransformer[] = []): void {
const openapiFilename = `openapi.${dir_version}.yaml`;

const openapiYmlSourcePath = join(__dirname, "..", "docs", openapiFilename);
const outDir = join(__dirname, "..", "..", "public", "static");
const dirname = import.meta.dirname;

const openapiYmlSourcePath = join(dirname, "..", "docs", openapiFilename);
const outDir = join(dirname, "..", "..", "public", "static");
const openapiYmlOutPath = join(outDir, openapiFilename);

const openapiYmlInputDoc = readFileSync(openapiYmlSourcePath, "utf-8").toString();
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/utils/server-helpers.ts → src/utils/server-helpers.mts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createFactory } from "hono/factory";
import { HTTPException } from "hono/http-exception";

import { db } from "@/config/db";
import { env } from "@/config/env";
import type { ServerContext } from "@/types/hono";
import { db } from "@/config/db/index.mjs";
import { env } from "@/config/env.mjs";
import type { ServerContext } from "@/types/hono.mjs";
import type { Context } from "hono";

import { ENDPOINT_MESSAGES } from "./messages";
import { ENDPOINT_MESSAGES } from "./messages.mjs";

/**
* Takes a string URL and returns an object with the query string parameters, multiple of the same key will be an array
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"lib": ["ESNext"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "CommonJS",
"moduleResolution": "Node",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"resolveJsonModule": true,
"outDir": "./dist",
"removeComments": true,
Expand Down

0 comments on commit f6b34b1

Please sign in to comment.