Initial commit: add .gitignore and README

This commit is contained in:
defiQUG
2026-02-09 21:51:55 -08:00
commit d904c04c2d
52 changed files with 1613 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
{
"name": "@workspace/validation",
"version": "1.0.0",
"description": "Zod schemas and validators",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
"test": "vitest",
"lint": "eslint src",
"type-check": "tsc --noEmit",
"clean": "rm -rf dist"
},
"dependencies": {
"zod": "^3.23.8"
},
"devDependencies": {
"typescript": "^5.5.4",
"vitest": "^1.2.0"
},
"files": [
"dist"
],
"publishConfig": {
"access": "restricted"
}
}

View File

@@ -0,0 +1,8 @@
/**
* @workspace/validation
* Zod schemas and validators
*/
export * from './schemas';
export * from './validators';

View File

@@ -0,0 +1,37 @@
/**
* Common validation schemas
*/
import { z } from 'zod';
/**
* Email validation schema
*/
export const emailSchema = z.string().email('Invalid email address');
/**
* UUID validation schema
*/
export const uuidSchema = z.string().uuid('Invalid UUID');
/**
* URL validation schema
*/
export const urlSchema = z.string().url('Invalid URL');
/**
* Pagination schema
*/
export const paginationSchema = z.object({
page: z.number().int().positive().default(1),
limit: z.number().int().positive().max(100).default(10),
});
/**
* Sort schema
*/
export const sortSchema = z.object({
field: z.string(),
order: z.enum(['asc', 'desc']).default('asc'),
});

View File

@@ -0,0 +1,27 @@
/**
* Validation utilities
*/
import { z } from 'zod';
/**
* Validate data against schema
*/
export function validate<T>(schema: z.ZodSchema<T>, data: unknown): T {
return schema.parse(data);
}
/**
* Safe validate (returns result instead of throwing)
*/
export function validateSafe<T>(
schema: z.ZodSchema<T>,
data: unknown
): { success: true; data: T } | { success: false; error: z.ZodError } {
const result = schema.safeParse(data);
if (result.success) {
return { success: true, data: result.data };
}
return { success: false, error: result.error };
}

View File

@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"lib": ["ES2022"],
"declaration": true,
"declarationMap": true,
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"resolveJsonModule": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
}