refactor: migrate to vite and restructure repo

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2025-10-18 14:02:20 +00:00
parent 83a5f92506
commit 25796ab609
94 changed files with 478 additions and 312 deletions

View File

@@ -0,0 +1,35 @@
import { ConvexError } from "convex/values"
export enum Code {
Conflict = "Conflict",
DirectoryExists = "DirectoryExists",
DirectoryNotFound = "DirectoryNotFound",
FileExists = "FileExists",
FileNotFound = "FileNotFound",
Internal = "Internal",
Unauthenticated = "Unauthenticated",
NotFound = "NotFound",
}
export type ApplicationErrorData = { code: Code; message?: string }
export type ApplicationError = ConvexError<ApplicationErrorData>
export function isApplicationError(error: unknown): error is ApplicationError {
return error instanceof ConvexError && "code" in error.data
}
export function create(code: Code, message?: string): ApplicationError {
return new ConvexError({
code,
message:
code === Code.Internal ? "Internal application error" : message,
})
}
export function createJson(code: Code, message?: string): ApplicationErrorData {
return {
code,
message:
code === Code.Internal ? "Internal application error" : message,
}
}

View File

@@ -0,0 +1,91 @@
/**
* Client-safe filesystem types and utilities.
* This file contains types and pure functions that can be safely imported by frontend code.
* NO server-only dependencies should be imported here.
*/
import type { Doc, Id } from "../_generated/dataModel"
import type * as Err from "./error"
export enum FileType {
File = "File",
Directory = "Directory",
}
export type Directory = {
kind: FileType.Directory
doc: Doc<"directories">
}
export type File = {
kind: FileType.File
doc: Doc<"files">
}
export type FileSystemItem = Directory | File
export type DirectoryPathComponent = {
handle: DirectoryHandle
name: string
}
export type FilePathComponent = {
handle: FileHandle
name: string
}
export type PathComponent = FilePathComponent | DirectoryPathComponent
export type DirectoryPath = [
DirectoryPathComponent,
...DirectoryPathComponent[],
]
export type FilePath = [...DirectoryPathComponent[], PathComponent]
export type ReverseFilePath = [PathComponent, ...DirectoryPathComponent[]]
export type DirectoryHandle = {
kind: FileType.Directory
id: Id<"directories">
}
export type FileHandle = {
kind: FileType.File
id: Id<"files">
}
export type FileSystemHandle = DirectoryHandle | FileHandle
export type DeleteResult = {
deleted: {
files: number
directories: number
}
errors: Err.ApplicationErrorData[]
}
export function newFileSystemHandle(item: FileSystemItem): FileSystemHandle {
console.log("item", item)
switch (item.kind) {
case FileType.File:
return { kind: item.kind, id: item.doc._id }
case FileType.Directory:
return { kind: item.kind, id: item.doc._id }
}
}
export function isSameHandle(
handle1: FileSystemHandle,
handle2: FileSystemHandle,
): boolean {
return handle1.kind === handle2.kind && handle1.id === handle2.id
}
export function newDirectoryHandle(id: Id<"directories">): DirectoryHandle {
return { kind: FileType.Directory, id }
}
export function newFileHandle(id: Id<"files">): FileHandle {
return { kind: FileType.File, id }
}

View File

@@ -0,0 +1,11 @@
/**
* Shared types that can be safely imported by both client and server code.
* This file should NOT import any server-only dependencies.
*/
import type { Doc } from "../_generated/dataModel"
import type { DirectoryPath } from "./filesystem"
export type DirectoryInfo = Doc<"directories"> & { path: DirectoryPath }
export type DirectoryItem = DirectoryInfo
export type DirectoryItemKind = "directory" | "file"