@veloxts/validation 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.js ADDED
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Core type definitions for @veloxts/validation
3
+ *
4
+ * Provides type-safe Zod integration with automatic type inference
5
+ * for procedure inputs/outputs.
6
+ *
7
+ * @module types
8
+ */
9
+ /**
10
+ * Type guard to check if a value is a Schema instance
11
+ */
12
+ export function isSchema(value) {
13
+ return (typeof value === 'object' &&
14
+ value !== null &&
15
+ '_schema' in value &&
16
+ value._schema === true);
17
+ }
18
+ /**
19
+ * Type guard to check if a value is a Zod schema
20
+ */
21
+ export function isZodSchema(value) {
22
+ return (typeof value === 'object' &&
23
+ value !== null &&
24
+ 'parse' in value &&
25
+ 'safeParse' in value &&
26
+ '_def' in value);
27
+ }
28
+ // ============================================================================
29
+ // Schema Wrapper Factory
30
+ // ============================================================================
31
+ /**
32
+ * Wraps a Zod schema in the framework's Schema interface
33
+ *
34
+ * This provides a consistent API and transforms Zod errors into
35
+ * a framework-friendly format.
36
+ *
37
+ * @template TOutput - The validated output type
38
+ * @template TInput - The raw input type
39
+ * @param zodSchema - The Zod schema to wrap
40
+ * @returns Wrapped Schema instance
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * import { z } from 'zod';
45
+ * import { wrapSchema } from '@veloxts/validation';
46
+ *
47
+ * const UserSchema = wrapSchema(z.object({
48
+ * id: z.string().uuid(),
49
+ * name: z.string().min(1),
50
+ * }));
51
+ * ```
52
+ */
53
+ export function wrapSchema(zodSchema) {
54
+ return {
55
+ _schema: true,
56
+ parse(input) {
57
+ return zodSchema.parse(input);
58
+ },
59
+ safeParse(input) {
60
+ const result = zodSchema.safeParse(input);
61
+ if (result.success) {
62
+ return {
63
+ success: true,
64
+ data: result.data,
65
+ };
66
+ }
67
+ return {
68
+ success: false,
69
+ error: result.error.issues.map((issue) => ({
70
+ path: issue.path,
71
+ message: issue.message,
72
+ code: issue.code,
73
+ })),
74
+ };
75
+ },
76
+ };
77
+ }
78
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA2IH;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QACjB,KAA8B,CAAC,OAAO,KAAK,IAAI,CACjD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAO,IAAI,KAAK;QAChB,WAAW,IAAI,KAAK;QACpB,MAAM,IAAI,KAAK,CAChB,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,yBAAyB;AACzB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,UAAU,CACxB,SAA+C;IAE/C,OAAO;QACL,OAAO,EAAE,IAAa;QAEtB,KAAK,CAAC,KAAc;YAClB,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;QAED,SAAS,CAAC,KAAc;YACtB,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YAE1C,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnB,OAAO;oBACL,OAAO,EAAE,IAAI;oBACb,IAAI,EAAE,MAAM,CAAC,IAAI;iBAClB,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;oBACzC,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,IAAI,EAAE,KAAK,CAAC,IAAI;iBACjB,CAAC,CAAC;aACJ,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@veloxts/validation",
3
+ "version": "0.1.0",
4
+ "description": "Zod integration and validation middleware for VeloxTS framework",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "dependencies": {
15
+ "zod": "3.24.4",
16
+ "@veloxts/core": "0.1.0"
17
+ },
18
+ "devDependencies": {
19
+ "typescript": "5.9.3",
20
+ "vitest": "4.0.15"
21
+ },
22
+ "peerDependencies": {
23
+ "zod": "^3.24.0"
24
+ },
25
+ "peerDependenciesMeta": {
26
+ "zod": {
27
+ "optional": false
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md"
33
+ ],
34
+ "keywords": [
35
+ "velox",
36
+ "validation",
37
+ "zod",
38
+ "schema",
39
+ "typescript"
40
+ ],
41
+ "license": "MIT",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/veloxts/velox-ts-framework",
45
+ "directory": "packages/validation"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "engines": {
51
+ "node": ">=20.0.0"
52
+ },
53
+ "scripts": {
54
+ "build": "tsc",
55
+ "dev": "tsc --watch",
56
+ "type-check": "tsc --noEmit",
57
+ "clean": "rm -rf dist tsconfig.tsbuildinfo",
58
+ "test": "vitest run",
59
+ "test:watch": "vitest",
60
+ "test:coverage": "vitest run --coverage"
61
+ }
62
+ }