feat: shared type package

This commit is contained in:
Nicolas Meienberger
2025-09-02 21:59:26 +02:00
parent 9ef21d4ec2
commit de0ae08008
12 changed files with 82 additions and 43 deletions

View File

@@ -1,4 +1,5 @@
import { arktypeResolver } from "@hookform/resolvers/arktype";
import { volumeConfigSchema } from "@ironmount/schemas";
import { type } from "arktype";
import { Plus } from "lucide-react";
import { useForm } from "react-hook-form";
@@ -19,15 +20,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from ".
export const formSchema = type({
name: "2<=string<=32",
backend: "'directory'",
}).or({
name: "2<=string<=32",
backend: "'nfs'",
server: "string",
exportPath: "string",
port: "number >= 1",
version: "'3' | '4' | '4.1'",
});
}).and(volumeConfigSchema);
type FormValues = typeof formSchema.infer;
type Props = {

View File

@@ -10,7 +10,7 @@
},
"dependencies": {
"@hookform/resolvers": "^5.2.1",
"@ironmount/server": "workspace:*",
"@ironmount/schemas": "workspace:*",
"@radix-ui/react-alert-dialog": "^1.1.15",
"@radix-ui/react-dialog": "^1.1.15",
"@radix-ui/react-label": "^2.1.7",

View File

@@ -3,10 +3,12 @@
"type": "module",
"scripts": {
"dev": "bun run --hot src/index.ts",
"typecheck": "tsc --noEmit",
"gen:migrations": "drizzle-kit generate"
},
"dependencies": {
"@hono/arktype-validator": "^2.0.1",
"@ironmount/schemas": "workspace:*",
"@scalar/hono-api-reference": "^0.9.13",
"arktype": "^2.1.20",
"dotenv": "^17.2.1",

View File

@@ -1,34 +1,7 @@
import { type } from "arktype";
import type { volumeConfigSchema } from "@ironmount/schemas";
import { sql } from "drizzle-orm";
import { int, sqliteTable, text } from "drizzle-orm/sqlite-core";
const BACKEND_TYPES = {
nfs: "nfs",
smb: "smb",
directory: "directory",
};
export type BackendType = keyof typeof BACKEND_TYPES;
const nfsConfigSchema = type({
backend: "'nfs'",
server: "string",
exportPath: "string",
port: "number >= 1",
version: "'3' | '4' | '4.1'",
});
const smbConfigSchema = type({
backend: "'smb'",
});
const directoryConfigSchema = type({
backend: "'directory'",
});
export const volumeConfigSchema = nfsConfigSchema.or(smbConfigSchema).or(directoryConfigSchema);
export type BackendConfig = typeof volumeConfigSchema.infer;
export const volumesTable = sqliteTable("volumes_table", {
id: int().primaryKey({ autoIncrement: true }),
name: text().notNull().unique(),

View File

@@ -1,6 +1,6 @@
import { exec } from "node:child_process";
import * as os from "node:os";
import type { BackendConfig } from "../../../db/schema";
import type { BackendConfig } from "@ironmount/schemas";
import type { VolumeBackend } from "../backend";
const mount = async (config: BackendConfig, path: string) => {

View File

@@ -1,7 +1,7 @@
import { volumeConfigSchema } from "@ironmount/schemas";
import { type } from "arktype";
import { describeRoute } from "hono-openapi";
import { resolver } from "hono-openapi/arktype";
import { volumeConfigSchema } from "../../db/schema";
/**
* List all volumes

View File

@@ -1,10 +1,11 @@
import * as path from "node:path";
import type { BackendConfig } from "@ironmount/schemas";
import { eq } from "drizzle-orm";
import { ConflictError, InternalServerError, NotFoundError } from "http-errors-enhanced";
import slugify from "slugify";
import { config } from "../../core/config";
import { db } from "../../db/db";
import { type BackendConfig, volumesTable } from "../../db/schema";
import { volumesTable } from "../../db/schema";
import { createVolumeBackend } from "../backends/backend";
const listVolumes = async () => {