mirror of
https://github.com/get-drexa/drive.git
synced 2025-11-30 21:41:39 +00:00
50 lines
1.0 KiB
TypeScript
50 lines
1.0 KiB
TypeScript
import type { Id } from "../_generated/dataModel"
|
|
|
|
export enum FileType {
|
|
File = "File",
|
|
Directory = "Directory",
|
|
}
|
|
|
|
export type DirectoryPathComponent = {
|
|
handle: DirectoryHandle
|
|
name: string
|
|
}
|
|
|
|
export type FilePathComponent = {
|
|
handle: FileHandle
|
|
name: string
|
|
}
|
|
|
|
export type PathComponent = FilePathComponent | DirectoryPathComponent
|
|
|
|
export type FilePath = [...DirectoryPathComponent[], PathComponent]
|
|
|
|
export type ReverseFilePath = [PathComponent, ...DirectoryPathComponent[]]
|
|
|
|
export type FileHandle = {
|
|
kind: "file"
|
|
id: Id<"files">
|
|
}
|
|
|
|
export type DirectoryHandle = {
|
|
kind: "directory"
|
|
id: Id<"directories">
|
|
}
|
|
|
|
export type FileSystemHandle = DirectoryHandle | FileHandle
|
|
|
|
export function newDirectoryHandle(id: Id<"directories">): DirectoryHandle {
|
|
return { kind: "directory", id }
|
|
}
|
|
|
|
export function newFileHandle(id: Id<"files">): FileHandle {
|
|
return { kind: "file", id }
|
|
}
|
|
|
|
export function isSameHandle(
|
|
handle1: FileSystemHandle,
|
|
handle2: FileSystemHandle,
|
|
): boolean {
|
|
return handle1.kind === handle2.kind && handle1.id === handle2.id
|
|
}
|