mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
feat: shared type package
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user