Skip to content

Commit

Permalink
Relative imports (#63)
Browse files Browse the repository at this point in the history
* revert to relative paths for libraries rather than introduce more build steps microsoft/TypeScript#15479

* clean up packages
  • Loading branch information
4leite authored May 9, 2024
1 parent 2deb902 commit 4e6430b
Show file tree
Hide file tree
Showing 46 changed files with 155 additions and 183 deletions.
13 changes: 13 additions & 0 deletions .changeset/twelve-pumpkins-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@oberoncms/adapter-vercel-postgres": minor
"@oberoncms/adapter-turso": minor
"@oberoncms/upload-thing": minor
"@oberoncms/core": minor
"@tohuhono/utils": minor
"@tohuhono/puck-rich-text": minor
"@tohuhono/dev": minor
"@tohuhono/ui": minor
"@tohuhono/puck-blocks": minor
---

Reverted to relative imports because typescript team refuses to transpile declaration files
4 changes: 2 additions & 2 deletions oberoncms/adapter-turso/src/db/next-auth-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { randomUUID } from "crypto"
import { eq, and } from "drizzle-orm"
import type { Adapter } from "@auth/core/adapters"
import { db } from "../db/client"
import {
users,
accounts,
sessions,
verificationTokens,
} from "src/db/schema/next-auth-schema"
import { db } from "src/db/client"
} from "../db/schema/next-auth-schema"

function LibsqlDrizzleAdapter(client: typeof db) {
return {
Expand Down
6 changes: 3 additions & 3 deletions oberoncms/adapter-turso/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import "server-only"
import { eq } from "drizzle-orm"
import { type OberonDatabaseAdapter } from "@oberoncms/core"

import { db } from "src/db/client"
import { images, pages, users } from "src/db/schema"
import { images, pages, users } from "./db/schema"
import { db } from "./db/client"

import { authAdapter } from "@/db/next-auth-adapter"
import { authAdapter } from "./db/next-auth-adapter"

export const oberonAdapter: OberonDatabaseAdapter = {
...authAdapter,
Expand Down
6 changes: 1 addition & 5 deletions oberoncms/adapter-turso/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"rootDir": "./src",
"outDir": "./dist",
"jsx": "react-jsx",
"paths": {
"@/*": ["./src/*"]
}
"jsx": "react-jsx"
},
"include": ["src", "scripts"],
"exclude": ["node_modules", "dist", "**/*.spec.ts", "**/*.spec.tsx"]
Expand Down
2 changes: 1 addition & 1 deletion oberoncms/adapter-vercel-postgres/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "@/db/env-config"
import "./src/db/env-config"

import type { Config } from "drizzle-kit"

Expand Down
2 changes: 1 addition & 1 deletion oberoncms/adapter-vercel-postgres/src/db/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "@/db/env-config"
import "./env-config"
import { drizzle } from "drizzle-orm/vercel-postgres"
import { sql } from "@vercel/postgres"
import * as schema from "./schema"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { db } from "src/db/client"
import { type Adapter } from "@auth/core/adapters"
import { DrizzleAdapter } from "@auth/drizzle-adapter"
import { db } from "../db/client"

export const adapter = DrizzleAdapter(db) satisfies Adapter
8 changes: 3 additions & 5 deletions oberoncms/adapter-vercel-postgres/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import "server-only"
import { eq } from "drizzle-orm"
import { type OberonDatabaseAdapter } from "@oberoncms/core"

// import { ourUploadthing } from "src/puck/uploadthing/api" // TODO uploadthing
import { db } from "src/db/client"
import { images, pages, users } from "src/db/schema"

import { adapter } from "@/db/next-auth-adapter"
import { db } from "./db/client"
import { images, pages, users } from "./db/schema"
import { adapter } from "./db/next-auth-adapter"

export const databaseAdapter: OberonDatabaseAdapter = {
...adapter,
Expand Down
6 changes: 1 addition & 5 deletions oberoncms/adapter-vercel-postgres/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"rootDir": "./src",
"outDir": "./dist",
"jsx": "react-jsx",
"paths": {
"@/*": ["./src/*"]
}
"jsx": "react-jsx"
},
"include": ["src", "scripts"],
"exclude": ["node_modules", "dist", "**/*.spec.ts", "**/*.spec.tsx"]
Expand Down
2 changes: 1 addition & 1 deletion oberoncms/core/src/adapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
type OberonDatabaseAdapter,
type OberonAdapter,
type OberonPlugin,
} from "@/app/schema"
} from "./app/schema"

export function initAdapter({
databaseAdapter,
Expand Down
7 changes: 6 additions & 1 deletion oberoncms/core/src/app/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Data } from "@measured/puck"
import { Route } from "next"
import type { Config } from "@measured/puck"
import type { Adapter as AuthAdapter } from "@auth/core/adapters"
import type { NextAuthResult } from "next-auth"

export type OberonConfig = {
blocks: Config["components"]
Expand All @@ -12,6 +13,10 @@ export type ClientAction = "edit" | "preview" | "users" | "images" | "pages"
export type AdapterActionGroup = "cms" | "users" | "images" | "pages"
export type AdapterPermission = "read" | "write"

export type OberonAuth = NextAuthResult & {
getRole: () => Promise<"user" | "admin" | null>
}

export const INITIAL_DATA = {
content: [],
root: { props: { title: "" } },
Expand Down Expand Up @@ -127,7 +132,7 @@ export type OberonActions = {
) => Promise<Pick<OberonUser, "role" | "id"> | null>
getAllUsers: () => Promise<OberonUser[]>
getAllImages: () => Promise<OberonImage[]>
addImage: (data: z.infer<typeof AddImageSchema>) => Promise<OberonImage[]>
addImage: (data: OberonImage) => Promise<OberonImage[]>
deleteImage: (key: OberonImage["key"]) => Promise<void> // TODO uploadthing
addPage: (page: OberonPage) => Promise<void>
deletePage: (data: z.infer<typeof DeletePageSchema>) => Promise<void>
Expand Down
13 changes: 6 additions & 7 deletions oberoncms/core/src/auth/next-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import NextAuth from "next-auth"
import { NextRequest } from "next/server"
import { redirect } from "next/navigation"
import type { Adapter } from "@auth/core/adapters"
import type { OberonAuth } from ".."

const masterEmail = process.env.MASTER_EMAIL || null

Expand Down Expand Up @@ -36,7 +37,7 @@ export function initAuth({
token: string
url: string
}) => Promise<void>
}) {
}): OberonAuth {
const config = {
pages: {
verifyRequest: "/api/auth/verify",
Expand Down Expand Up @@ -131,9 +132,7 @@ export function initAuth({
return session?.user?.role || null
}

const POST = nextAuth.handlers.POST

const GET = (req: NextRequest) => {
const GET = async (req: NextRequest) => {
// safe links bot workaround https://github.com/nextauthjs/next-auth/issues/4965
if (
req.method === "GET" &&
Expand All @@ -153,11 +152,11 @@ export function initAuth({
}

return {
getRole,
auth,
...nextAuth,
handlers: {
POST,
...nextAuth.handlers,
GET,
},
getRole,
}
}
4 changes: 2 additions & 2 deletions oberoncms/core/src/components/all-pages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
FormItem,
FormMessage,
} from "@tohuhono/ui/form"
import { useOberonActions } from "@/hooks/use-oberon"
import { PageSchema, type OberonPage } from "@/app/schema"
import { useOberonActions } from "../hooks/use-oberon"
import { PageSchema, type OberonPage } from "../app/schema"

const useOberonPages = (pages: OberonPage[]) => {
const { deletePage, addPage } = useOberonActions()
Expand Down
6 changes: 3 additions & 3 deletions oberoncms/core/src/components/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import "@measured/puck/dist/index.css"
import { Config, Data, Puck, usePuck } from "@measured/puck"
import { Button } from "@tohuhono/ui/button"
import { useState } from "react"
import { useLocalData } from "../hooks/use-local-data"
import { INITIAL_DATA } from "../app/schema"
import { useOberonActions } from "../hooks/use-oberon"
import { PuckMenu } from "./puck-menu"
import { useOberonActions } from "@/hooks/use-oberon"
import { useLocalData } from "@/hooks/use-local-data"
import { INITIAL_DATA } from "@/app/schema"

const Header = ({
path,
Expand Down
14 changes: 9 additions & 5 deletions oberoncms/core/src/components/images.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { filesize } from "filesize"
import Link from "next/link"
import { Route } from "next"
import { Button } from "@tohuhono/ui/button"
import { LocalDate } from "@tohuhono/ui/date"
import Image from "next/image"
import { format } from "@tohuhono/utils"
import { useOberonActions } from "@/hooks/use-oberon"
import type { OberonImage } from "@/app/schema"

import { useOberonActions } from "../hooks/use-oberon"
import type { OberonImage } from "../app/schema"

const useOberonImages = (images: OberonImage[]) => {
const { deleteImage } = useOberonActions()
Expand Down Expand Up @@ -51,15 +52,18 @@ export function Images({ images: initialImages }: { images: OberonImage[] }) {
<ColumnHeading>By</ColumnHeading>
<ColumnHeading />

{images.map(({ key, alt, size, updatedAt, updatedBy, url, pending }) => {
{images.map(({ key, alt, size, updatedAt, updatedBy, url }) => {
const pending = false
return (
<Fragment key={key}>
<Link href={url as Route} prefetch={false} target="_blank">
<Image src={url} width={24} height={24} alt={alt} />
</Link>
<div className="flex flex-row gap-2">{alt}</div>
<div>{filesize(size)}</div>
<div>{format(updatedAt)}</div>
<div>
<LocalDate date={updatedAt} />
</div>
<div>{updatedBy}</div>
<Button
variant="destructive"
Expand Down
2 changes: 1 addition & 1 deletion oberoncms/core/src/components/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Render, type Config, type Data } from "@measured/puck"
import { useLocalData } from "@/hooks/use-local-data"
import { useLocalData } from "../hooks/use-local-data"

export function Preview({
path,
Expand Down
2 changes: 1 addition & 1 deletion oberoncms/core/src/components/puck-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { signOut } from "next-auth/react"
import { Button, buttonVariants } from "@tohuhono/ui/button"
import { ThemeEditorMenu } from "@tohuhono/ui/theme"
import useSWR from "swr"
import { useOberonActions } from "@/hooks/use-oberon"
import { useOberonActions } from "../hooks/use-oberon"

export const PuckMenu = ({
title,
Expand Down
4 changes: 2 additions & 2 deletions oberoncms/core/src/components/users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
FormMessage,
} from "@tohuhono/ui/form"

import { useOberonActions } from "@/hooks/use-oberon"
import { AddUserSchema, OberonUser, roles } from "@/app/schema"
import { AddUserSchema, OberonUser, roles } from "../app/schema"
import { useOberonActions } from "../hooks/use-oberon"

type OptimisticUser = OberonUser & { pending?: boolean }

Expand Down
12 changes: 6 additions & 6 deletions oberoncms/core/src/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { DynamicTailwind, PreviewFrameTailwind } from "@tohuhono/ui/theme"
import type { OberonConfig } from "./app/schema"
import { getTitle } from "./app/utils"
import { useOberonClientContext } from "./hooks/use-oberon"
import { Editor } from "@/components/editor"
import { Preview } from "@/components/preview"
import { PuckMenu } from "@/components/puck-menu"
import { AllPages } from "@/components/all-pages"
import { Images } from "@/components/images"
import { Users } from "@/components/users"
import { Editor } from "./components/editor"
import { Preview } from "./components/preview"
import { PuckMenu } from "./components/puck-menu"
import { AllPages } from "./components/all-pages"
import { Images } from "./components/images"
import { Users } from "./components/users"

export { useOberonImages } from "./hooks/use-oberon-images"

Expand Down
17 changes: 10 additions & 7 deletions oberoncms/core/src/hooks/use-oberon-images.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import useSWR from "swr"
import { OberonImage } from "../app/schema"
import { useOberonActions } from "./use-oberon"
import type { OberonImage } from "@/app/schema"

export const useOberonImages = () => {
const { getAllImages, addImage } = useOberonActions()
Expand All @@ -11,10 +11,13 @@ export const useOberonImages = () => {
isLoading: loading,
} = useSWR("/oberon/images", () => getAllImages())

const add = (image: OberonImage) =>
mutate(async () => await addImage(image), {
optimisticData: (currentData) => [...(currentData || []), image],
})

return { images, loading, add }
return {
images,
loading,
addImage: (image: OberonImage) => {
mutate(async () => await addImage(image), {
optimisticData: (currentData) => [...(currentData || []), image],
})
},
}
}
2 changes: 1 addition & 1 deletion oberoncms/core/src/hooks/use-oberon.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext } from "react"
import { ActionsContext, ClientContext } from "@/components/provider"
import { ActionsContext, ClientContext } from "../components/provider"

export const useOberonActions = () => {
const context = useContext(ActionsContext)
Expand Down
6 changes: 1 addition & 5 deletions oberoncms/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"rootDir": "./src",
"outDir": "./dist",
"jsx": "react-jsx",
"paths": {
"@/*": ["./src/*"]
}
"jsx": "react-jsx"
},
"include": ["src"],
"exclude": ["node_modules", "dist", "**/*.spec.ts", "**/*.spec.tsx"]
Expand Down
8 changes: 3 additions & 5 deletions oberoncms/upload-thing/src/blocks/image-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FieldLabel } from "@measured/puck"
import { useEffect, useState } from "react"
import { useOberonImages } from "@oberoncms/core/editor"
import type { OberonImage } from "@oberoncms/core"
import { UploadDropzone } from "@/uploadthing/components"
import { UploadDropzone } from "../uploadthing/components"

export const ImageField = ({
value,
Expand All @@ -11,7 +11,7 @@ export const ImageField = ({
value: OberonImage | null
onChange: (value: { image: OberonImage | null }) => void
}) => {
const { images, loading, add } = useOberonImages()
const { images, loading, addImage } = useOberonImages()

const [imageKey, setImageKey] = useState<OberonImage["key"] | "">(
value?.key || "",
Expand Down Expand Up @@ -49,11 +49,10 @@ export const ImageField = ({
name,
size,
url,

serverData: { width, height },
} = res[0]

add({
addImage({
key,
url,
alt: name,
Expand All @@ -62,7 +61,6 @@ export const ImageField = ({
height,
updatedAt: new Date(),
updatedBy: "unknown",
blarg: "ddd",
})
setImageKey?.(key || "")
}}
Expand Down
Loading

0 comments on commit 4e6430b

Please sign in to comment.