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 () => {
|
||||
|
||||
12
bun.lock
12
bun.lock
@@ -12,7 +12,7 @@
|
||||
"name": "@ironmount/client",
|
||||
"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",
|
||||
@@ -52,6 +52,7 @@
|
||||
"name": "@ironmount/server",
|
||||
"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",
|
||||
@@ -66,6 +67,13 @@
|
||||
"drizzle-kit": "^0.31.4",
|
||||
},
|
||||
},
|
||||
"packages/schemas": {
|
||||
"name": "@ironmount/schemas",
|
||||
"version": "0.0.0",
|
||||
"peerDependencies": {
|
||||
"arktype": ">=2",
|
||||
},
|
||||
},
|
||||
},
|
||||
"packages": {
|
||||
"@ampproject/remapping": ["@ampproject/remapping@2.3.0", "", { "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.24" } }, "sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw=="],
|
||||
@@ -208,6 +216,8 @@
|
||||
|
||||
"@ironmount/client": ["@ironmount/client@workspace:apps/client"],
|
||||
|
||||
"@ironmount/schemas": ["@ironmount/schemas@workspace:packages/schemas"],
|
||||
|
||||
"@ironmount/server": ["@ironmount/server@workspace:apps/server"],
|
||||
|
||||
"@isaacs/cliui": ["@isaacs/cliui@8.0.2", "", { "dependencies": { "string-width": "^5.1.2", "string-width-cjs": "npm:string-width@^4.2.0", "strip-ansi": "^7.0.1", "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", "wrap-ansi": "^8.1.0", "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" } }, "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA=="],
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
"gen:api-client": "openapi-ts"
|
||||
},
|
||||
"workspaces": [
|
||||
"apps/*"
|
||||
"apps/*",
|
||||
"packages/*"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@hey-api/openapi-ts": "^0.80.17",
|
||||
|
||||
11
packages/schemas/package.json
Normal file
11
packages/schemas/package.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "@ironmount/schemas",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"type": "module",
|
||||
"peerDependencies": {
|
||||
"arktype": ">=2"
|
||||
}
|
||||
}
|
||||
29
packages/schemas/src/index.ts
Normal file
29
packages/schemas/src/index.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { type } from "arktype";
|
||||
|
||||
export const BACKEND_TYPES = {
|
||||
nfs: "nfs",
|
||||
smb: "smb",
|
||||
directory: "directory",
|
||||
} as const;
|
||||
|
||||
export type BackendType = keyof typeof BACKEND_TYPES;
|
||||
|
||||
export const nfsConfigSchema = type({
|
||||
backend: "'nfs'",
|
||||
server: "string",
|
||||
exportPath: "string",
|
||||
port: "number >= 1",
|
||||
version: "'3' | '4' | '4.1'",
|
||||
});
|
||||
|
||||
export const smbConfigSchema = type({
|
||||
backend: "'smb'",
|
||||
});
|
||||
|
||||
export const directoryConfigSchema = type({
|
||||
backend: "'directory'",
|
||||
});
|
||||
|
||||
export const volumeConfigSchema = nfsConfigSchema.or(smbConfigSchema).or(directoryConfigSchema);
|
||||
|
||||
export type BackendConfig = typeof volumeConfigSchema.infer;
|
||||
19
packages/schemas/tsconfig.json
Normal file
19
packages/schemas/tsconfig.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"allowJs": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
Reference in New Issue
Block a user