@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.
@@ -0,0 +1,287 @@
1
+ /**
2
+ * Pagination schema utilities
3
+ *
4
+ * Provides standardized pagination input/output schemas for list endpoints.
5
+ *
6
+ * @module schemas/pagination
7
+ */
8
+ import { z } from 'zod';
9
+ /**
10
+ * Default pagination configuration
11
+ */
12
+ export declare const PAGINATION_DEFAULTS: {
13
+ /** Default page number */
14
+ readonly page: 1;
15
+ /** Default items per page */
16
+ readonly limit: 20;
17
+ /** Maximum allowed items per page */
18
+ readonly maxLimit: 100;
19
+ };
20
+ /**
21
+ * Creates a pagination input schema with configurable defaults
22
+ *
23
+ * @param options - Pagination configuration options
24
+ * @returns Zod schema for pagination input
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // Use defaults
29
+ * const PaginationSchema = createPaginationSchema();
30
+ *
31
+ * // Custom configuration
32
+ * const CustomPaginationSchema = createPaginationSchema({
33
+ * defaultLimit: 10,
34
+ * maxLimit: 50,
35
+ * });
36
+ * ```
37
+ */
38
+ export declare function createPaginationSchema(options?: {
39
+ defaultPage?: number;
40
+ defaultLimit?: number;
41
+ maxLimit?: number;
42
+ }): z.ZodObject<{
43
+ /** Current page number (1-indexed) */
44
+ page: z.ZodDefault<z.ZodNumber>;
45
+ /** Number of items per page */
46
+ limit: z.ZodDefault<z.ZodNumber>;
47
+ }, "strip", z.ZodTypeAny, {
48
+ page: number;
49
+ limit: number;
50
+ }, {
51
+ page?: number | undefined;
52
+ limit?: number | undefined;
53
+ }>;
54
+ /**
55
+ * Default pagination input schema
56
+ *
57
+ * Accepts page (default 1) and limit (default 20, max 100)
58
+ */
59
+ export declare const paginationInputSchema: z.ZodObject<{
60
+ /** Current page number (1-indexed) */
61
+ page: z.ZodDefault<z.ZodNumber>;
62
+ /** Number of items per page */
63
+ limit: z.ZodDefault<z.ZodNumber>;
64
+ }, "strip", z.ZodTypeAny, {
65
+ page: number;
66
+ limit: number;
67
+ }, {
68
+ page?: number | undefined;
69
+ limit?: number | undefined;
70
+ }>;
71
+ /**
72
+ * Type for pagination input
73
+ */
74
+ export type PaginationInput = z.infer<typeof paginationInputSchema>;
75
+ /**
76
+ * Pagination with cursor-based navigation
77
+ *
78
+ * For more efficient pagination of large datasets
79
+ */
80
+ export declare const cursorPaginationSchema: z.ZodObject<{
81
+ /** Cursor for the current position */
82
+ cursor: z.ZodOptional<z.ZodString>;
83
+ /** Number of items to fetch */
84
+ limit: z.ZodDefault<z.ZodNumber>;
85
+ /** Direction to fetch (forward/backward from cursor) */
86
+ direction: z.ZodDefault<z.ZodEnum<["forward", "backward"]>>;
87
+ }, "strip", z.ZodTypeAny, {
88
+ limit: number;
89
+ direction: "forward" | "backward";
90
+ cursor?: string | undefined;
91
+ }, {
92
+ limit?: number | undefined;
93
+ cursor?: string | undefined;
94
+ direction?: "forward" | "backward" | undefined;
95
+ }>;
96
+ /**
97
+ * Type for cursor-based pagination input
98
+ */
99
+ export type CursorPaginationInput = z.infer<typeof cursorPaginationSchema>;
100
+ /**
101
+ * Creates a paginated response schema for a given item schema
102
+ *
103
+ * @param itemSchema - Zod schema for individual items
104
+ * @returns Zod schema for paginated response
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const UserSchema = z.object({ id: z.string(), name: z.string() });
109
+ * const PaginatedUsersSchema = createPaginatedResponseSchema(UserSchema);
110
+ *
111
+ * type PaginatedUsers = z.infer<typeof PaginatedUsersSchema>;
112
+ * // { data: User[]; meta: { page, limit, total, totalPages, hasMore } }
113
+ * ```
114
+ */
115
+ export declare function createPaginatedResponseSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
116
+ /** Array of items for the current page */
117
+ data: z.ZodArray<T, "many">;
118
+ /** Pagination metadata */
119
+ meta: z.ZodObject<{
120
+ /** Current page number */
121
+ page: z.ZodNumber;
122
+ /** Items per page */
123
+ limit: z.ZodNumber;
124
+ /** Total number of items across all pages */
125
+ total: z.ZodNumber;
126
+ /** Total number of pages */
127
+ totalPages: z.ZodNumber;
128
+ /** Whether there are more pages after this one */
129
+ hasMore: z.ZodBoolean;
130
+ }, "strip", z.ZodTypeAny, {
131
+ page: number;
132
+ limit: number;
133
+ total: number;
134
+ totalPages: number;
135
+ hasMore: boolean;
136
+ }, {
137
+ page: number;
138
+ limit: number;
139
+ total: number;
140
+ totalPages: number;
141
+ hasMore: boolean;
142
+ }>;
143
+ }, "strip", z.ZodTypeAny, {
144
+ data: T["_output"][];
145
+ meta: {
146
+ page: number;
147
+ limit: number;
148
+ total: number;
149
+ totalPages: number;
150
+ hasMore: boolean;
151
+ };
152
+ }, {
153
+ data: T["_input"][];
154
+ meta: {
155
+ page: number;
156
+ limit: number;
157
+ total: number;
158
+ totalPages: number;
159
+ hasMore: boolean;
160
+ };
161
+ }>;
162
+ /**
163
+ * Type helper to infer paginated response type from item schema
164
+ */
165
+ export type PaginatedResponse<T> = {
166
+ data: T[];
167
+ meta: PaginationMeta;
168
+ };
169
+ /**
170
+ * Pagination metadata type
171
+ */
172
+ export interface PaginationMeta {
173
+ page: number;
174
+ limit: number;
175
+ total: number;
176
+ totalPages: number;
177
+ hasMore: boolean;
178
+ }
179
+ /**
180
+ * Creates a cursor-based paginated response schema
181
+ *
182
+ * @param itemSchema - Zod schema for individual items
183
+ * @returns Zod schema for cursor-paginated response
184
+ */
185
+ export declare function createCursorPaginatedResponseSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
186
+ /** Array of items */
187
+ data: z.ZodArray<T, "many">;
188
+ /** Cursor pagination metadata */
189
+ meta: z.ZodObject<{
190
+ /** Cursor for the next page (null if no more) */
191
+ nextCursor: z.ZodNullable<z.ZodString>;
192
+ /** Cursor for the previous page (null if at start) */
193
+ prevCursor: z.ZodNullable<z.ZodString>;
194
+ /** Whether there are more items after this page */
195
+ hasMore: z.ZodBoolean;
196
+ }, "strip", z.ZodTypeAny, {
197
+ hasMore: boolean;
198
+ nextCursor: string | null;
199
+ prevCursor: string | null;
200
+ }, {
201
+ hasMore: boolean;
202
+ nextCursor: string | null;
203
+ prevCursor: string | null;
204
+ }>;
205
+ }, "strip", z.ZodTypeAny, {
206
+ data: T["_output"][];
207
+ meta: {
208
+ hasMore: boolean;
209
+ nextCursor: string | null;
210
+ prevCursor: string | null;
211
+ };
212
+ }, {
213
+ data: T["_input"][];
214
+ meta: {
215
+ hasMore: boolean;
216
+ nextCursor: string | null;
217
+ prevCursor: string | null;
218
+ };
219
+ }>;
220
+ /**
221
+ * Type for cursor-paginated response
222
+ */
223
+ export type CursorPaginatedResponse<T> = {
224
+ data: T[];
225
+ meta: CursorPaginationMeta;
226
+ };
227
+ /**
228
+ * Cursor pagination metadata type
229
+ */
230
+ export interface CursorPaginationMeta {
231
+ nextCursor: string | null;
232
+ prevCursor: string | null;
233
+ hasMore: boolean;
234
+ }
235
+ /**
236
+ * Calculates pagination metadata from total count
237
+ *
238
+ * @param options - Pagination calculation options
239
+ * @returns Pagination metadata
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * const meta = calculatePaginationMeta({
244
+ * page: 2,
245
+ * limit: 20,
246
+ * total: 55,
247
+ * });
248
+ * // { page: 2, limit: 20, total: 55, totalPages: 3, hasMore: true }
249
+ * ```
250
+ */
251
+ export declare function calculatePaginationMeta(options: {
252
+ page: number;
253
+ limit: number;
254
+ total: number;
255
+ }): PaginationMeta;
256
+ /**
257
+ * Calculates offset for database queries
258
+ *
259
+ * @param page - Current page number (1-indexed)
260
+ * @param limit - Items per page
261
+ * @returns Offset for database skip
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * const offset = calculateOffset(3, 20);
266
+ * // offset = 40 (skip first 40 items for page 3)
267
+ * ```
268
+ */
269
+ export declare function calculateOffset(page: number, limit: number): number;
270
+ /**
271
+ * Creates a paginated response from items and total count
272
+ *
273
+ * @param items - Array of items for current page
274
+ * @param pagination - Pagination input parameters
275
+ * @param total - Total count of items
276
+ * @returns Paginated response object
277
+ *
278
+ * @example
279
+ * ```typescript
280
+ * const users = await db.user.findMany({ skip: 20, take: 20 });
281
+ * const total = await db.user.count();
282
+ *
283
+ * return createPaginatedResponse(users, { page: 2, limit: 20 }, total);
284
+ * ```
285
+ */
286
+ export declare function createPaginatedResponse<T>(items: T[], pagination: PaginationInput, total: number): PaginatedResponse<T>;
287
+ //# sourceMappingURL=pagination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../src/schemas/pagination.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;GAEG;AACH,eAAO,MAAM,mBAAmB;IAC9B,0BAA0B;;IAE1B,6BAA6B;;IAE7B,qCAAqC;;CAE7B,CAAC;AAMX;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO;IAS9E,sCAAsC;;IAEtC,+BAA+B;;;;;;;;GAGlC;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;IAZ9B,sCAAsC;;IAEtC,+BAA+B;;;;;;;;EAU0B,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;IACjC,sCAAsC;;IAEtC,+BAA+B;;IAE/B,wDAAwD;;;;;;;;;;EAExD,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAM3E;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EAA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,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EACvC,KAAK,EAAE,CAAC,EAAE,EACV,UAAU,EAAE,eAAe,EAC3B,KAAK,EAAE,MAAM,GACZ,iBAAiB,CAAC,CAAC,CAAC,CAStB"}
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Pagination schema utilities
3
+ *
4
+ * Provides standardized pagination input/output schemas for list endpoints.
5
+ *
6
+ * @module schemas/pagination
7
+ */
8
+ import { z } from 'zod';
9
+ // ============================================================================
10
+ // Pagination Constants
11
+ // ============================================================================
12
+ /**
13
+ * Default pagination configuration
14
+ */
15
+ export const PAGINATION_DEFAULTS = {
16
+ /** Default page number */
17
+ page: 1,
18
+ /** Default items per page */
19
+ limit: 20,
20
+ /** Maximum allowed items per page */
21
+ maxLimit: 100,
22
+ };
23
+ // ============================================================================
24
+ // Pagination Input Schemas
25
+ // ============================================================================
26
+ /**
27
+ * Creates a pagination input schema with configurable defaults
28
+ *
29
+ * @param options - Pagination configuration options
30
+ * @returns Zod schema for pagination input
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * // Use defaults
35
+ * const PaginationSchema = createPaginationSchema();
36
+ *
37
+ * // Custom configuration
38
+ * const CustomPaginationSchema = createPaginationSchema({
39
+ * defaultLimit: 10,
40
+ * maxLimit: 50,
41
+ * });
42
+ * ```
43
+ */
44
+ export function createPaginationSchema(options = {}) {
45
+ const { defaultPage = PAGINATION_DEFAULTS.page, defaultLimit = PAGINATION_DEFAULTS.limit, maxLimit = PAGINATION_DEFAULTS.maxLimit, } = options;
46
+ return z.object({
47
+ /** Current page number (1-indexed) */
48
+ page: z.coerce.number().int().positive().default(defaultPage),
49
+ /** Number of items per page */
50
+ limit: z.coerce.number().int().positive().max(maxLimit).default(defaultLimit),
51
+ });
52
+ }
53
+ /**
54
+ * Default pagination input schema
55
+ *
56
+ * Accepts page (default 1) and limit (default 20, max 100)
57
+ */
58
+ export const paginationInputSchema = createPaginationSchema();
59
+ /**
60
+ * Pagination with cursor-based navigation
61
+ *
62
+ * For more efficient pagination of large datasets
63
+ */
64
+ export const cursorPaginationSchema = z.object({
65
+ /** Cursor for the current position */
66
+ cursor: z.string().optional(),
67
+ /** Number of items to fetch */
68
+ limit: z.coerce.number().int().positive().max(100).default(20),
69
+ /** Direction to fetch (forward/backward from cursor) */
70
+ direction: z.enum(['forward', 'backward']).default('forward'),
71
+ });
72
+ // ============================================================================
73
+ // Pagination Output Types
74
+ // ============================================================================
75
+ /**
76
+ * Creates a paginated response schema for a given item schema
77
+ *
78
+ * @param itemSchema - Zod schema for individual items
79
+ * @returns Zod schema for paginated response
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const UserSchema = z.object({ id: z.string(), name: z.string() });
84
+ * const PaginatedUsersSchema = createPaginatedResponseSchema(UserSchema);
85
+ *
86
+ * type PaginatedUsers = z.infer<typeof PaginatedUsersSchema>;
87
+ * // { data: User[]; meta: { page, limit, total, totalPages, hasMore } }
88
+ * ```
89
+ */
90
+ export function createPaginatedResponseSchema(itemSchema) {
91
+ return z.object({
92
+ /** Array of items for the current page */
93
+ data: z.array(itemSchema),
94
+ /** Pagination metadata */
95
+ meta: z.object({
96
+ /** Current page number */
97
+ page: z.number().int().positive(),
98
+ /** Items per page */
99
+ limit: z.number().int().positive(),
100
+ /** Total number of items across all pages */
101
+ total: z.number().int().nonnegative(),
102
+ /** Total number of pages */
103
+ totalPages: z.number().int().nonnegative(),
104
+ /** Whether there are more pages after this one */
105
+ hasMore: z.boolean(),
106
+ }),
107
+ });
108
+ }
109
+ /**
110
+ * Creates a cursor-based paginated response schema
111
+ *
112
+ * @param itemSchema - Zod schema for individual items
113
+ * @returns Zod schema for cursor-paginated response
114
+ */
115
+ export function createCursorPaginatedResponseSchema(itemSchema) {
116
+ return z.object({
117
+ /** Array of items */
118
+ data: z.array(itemSchema),
119
+ /** Cursor pagination metadata */
120
+ meta: z.object({
121
+ /** Cursor for the next page (null if no more) */
122
+ nextCursor: z.string().nullable(),
123
+ /** Cursor for the previous page (null if at start) */
124
+ prevCursor: z.string().nullable(),
125
+ /** Whether there are more items after this page */
126
+ hasMore: z.boolean(),
127
+ }),
128
+ });
129
+ }
130
+ // ============================================================================
131
+ // Pagination Utilities
132
+ // ============================================================================
133
+ /**
134
+ * Calculates pagination metadata from total count
135
+ *
136
+ * @param options - Pagination calculation options
137
+ * @returns Pagination metadata
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * const meta = calculatePaginationMeta({
142
+ * page: 2,
143
+ * limit: 20,
144
+ * total: 55,
145
+ * });
146
+ * // { page: 2, limit: 20, total: 55, totalPages: 3, hasMore: true }
147
+ * ```
148
+ */
149
+ export function calculatePaginationMeta(options) {
150
+ const { page, limit, total } = options;
151
+ const totalPages = Math.ceil(total / limit);
152
+ return {
153
+ page,
154
+ limit,
155
+ total,
156
+ totalPages,
157
+ hasMore: page < totalPages,
158
+ };
159
+ }
160
+ /**
161
+ * Calculates offset for database queries
162
+ *
163
+ * @param page - Current page number (1-indexed)
164
+ * @param limit - Items per page
165
+ * @returns Offset for database skip
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * const offset = calculateOffset(3, 20);
170
+ * // offset = 40 (skip first 40 items for page 3)
171
+ * ```
172
+ */
173
+ export function calculateOffset(page, limit) {
174
+ return (page - 1) * limit;
175
+ }
176
+ /**
177
+ * Creates a paginated response from items and total count
178
+ *
179
+ * @param items - Array of items for current page
180
+ * @param pagination - Pagination input parameters
181
+ * @param total - Total count of items
182
+ * @returns Paginated response object
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * const users = await db.user.findMany({ skip: 20, take: 20 });
187
+ * const total = await db.user.count();
188
+ *
189
+ * return createPaginatedResponse(users, { page: 2, limit: 20 }, total);
190
+ * ```
191
+ */
192
+ export function createPaginatedResponse(items, pagination, total) {
193
+ return {
194
+ data: items,
195
+ meta: calculatePaginationMeta({
196
+ page: pagination.page,
197
+ limit: pagination.limit,
198
+ total,
199
+ }),
200
+ };
201
+ }
202
+ //# sourceMappingURL=pagination.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.js","sourceRoot":"","sources":["../../src/schemas/pagination.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,0BAA0B;IAC1B,IAAI,EAAE,CAAC;IACP,6BAA6B;IAC7B,KAAK,EAAE,EAAE;IACT,qCAAqC;IACrC,QAAQ,EAAE,GAAG;CACL,CAAC;AAEX,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,sBAAsB,CACpC,UAA8E,EAAE;IAEhF,MAAM,EACJ,WAAW,GAAG,mBAAmB,CAAC,IAAI,EACtC,YAAY,GAAG,mBAAmB,CAAC,KAAK,EACxC,QAAQ,GAAG,mBAAmB,CAAC,QAAQ,GACxC,GAAG,OAAO,CAAC;IAEZ,OAAO,CAAC,CAAC,MAAM,CAAC;QACd,sCAAsC;QACtC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC;QAC7D,+BAA+B;QAC/B,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;KAC9E,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,sBAAsB,EAAE,CAAC;AAO9D;;;;GAIG;AACH,M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0,0 +1,159 @@
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
+ import type { ZodType, ZodTypeDef } from 'zod';
10
+ /**
11
+ * Type-safe validator interface that wraps Zod schemas
12
+ *
13
+ * This abstraction allows the framework to work with Zod while maintaining
14
+ * the flexibility to support other validation libraries in the future.
15
+ *
16
+ * @template TOutput - The validated output type
17
+ * @template TInput - The raw input type (defaults to TOutput)
18
+ */
19
+ export interface Schema<TOutput = unknown, _TInput = TOutput> {
20
+ /**
21
+ * Parses input and returns validated data
22
+ * Throws ZodError on validation failure
23
+ */
24
+ readonly parse: (input: unknown) => TOutput;
25
+ /**
26
+ * Safely parses input without throwing
27
+ * Returns discriminated union with success/error
28
+ */
29
+ readonly safeParse: (input: unknown) => SafeParseResult<TOutput>;
30
+ /**
31
+ * Brand to identify Schema instances
32
+ * @internal
33
+ */
34
+ readonly _schema: true;
35
+ }
36
+ /**
37
+ * Result type for safe parsing operations
38
+ */
39
+ export type SafeParseResult<T> = SafeParseSuccess<T> | SafeParseError;
40
+ /**
41
+ * Successful parse result
42
+ */
43
+ export interface SafeParseSuccess<T> {
44
+ readonly success: true;
45
+ readonly data: T;
46
+ }
47
+ /**
48
+ * Failed parse result with error details
49
+ */
50
+ export interface SafeParseError {
51
+ readonly success: false;
52
+ readonly error: ValidationIssue[];
53
+ }
54
+ /**
55
+ * Individual validation issue
56
+ */
57
+ export interface ValidationIssue {
58
+ /** Dot-notation path to the invalid field */
59
+ readonly path: readonly (string | number)[];
60
+ /** Human-readable error message */
61
+ readonly message: string;
62
+ /** Zod error code */
63
+ readonly code: string;
64
+ }
65
+ /**
66
+ * Infers the output type from a Schema or ZodType
67
+ *
68
+ * Works with both wrapped Schema instances and raw Zod schemas,
69
+ * enabling seamless type inference in procedure chains.
70
+ *
71
+ * @template T - Schema or ZodType to infer from
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * const UserSchema = z.object({ id: z.string(), name: z.string() });
76
+ * type User = InferOutput<typeof UserSchema>;
77
+ * // User = { id: string; name: string }
78
+ * ```
79
+ */
80
+ export type InferOutput<T> = T extends Schema<infer O, infer _I> ? O : T extends ZodType<infer O, ZodTypeDef, infer _I> ? O : never;
81
+ /**
82
+ * Infers the input type from a Schema or ZodType
83
+ *
84
+ * For schemas with transforms, this returns the pre-transform type.
85
+ *
86
+ * @template T - Schema or ZodType to infer from
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * const DateSchema = z.string().transform((s) => new Date(s));
91
+ * type DateInput = InferInput<typeof DateSchema>;
92
+ * // DateInput = string (not Date)
93
+ * ```
94
+ */
95
+ export type InferInput<T> = T extends Schema<infer _O, infer I> ? I : T extends ZodType<infer _O, ZodTypeDef, infer I> ? I : never;
96
+ /**
97
+ * Type constraint for any Zod schema
98
+ *
99
+ * Used in generic constraints to accept any valid Zod schema.
100
+ */
101
+ export type AnyZodSchema = ZodType<unknown, ZodTypeDef, unknown>;
102
+ /**
103
+ * Type constraint for any Schema wrapper
104
+ */
105
+ export type AnySchema = Schema<unknown, unknown>;
106
+ /**
107
+ * Union type accepting both raw Zod schemas and wrapped Schema instances
108
+ */
109
+ export type SchemaLike = AnyZodSchema | AnySchema;
110
+ /**
111
+ * Type guard to check if a value is a Schema instance
112
+ */
113
+ export declare function isSchema(value: unknown): value is AnySchema;
114
+ /**
115
+ * Type guard to check if a value is a Zod schema
116
+ */
117
+ export declare function isZodSchema(value: unknown): value is AnyZodSchema;
118
+ /**
119
+ * Wraps a Zod schema in the framework's Schema interface
120
+ *
121
+ * This provides a consistent API and transforms Zod errors into
122
+ * a framework-friendly format.
123
+ *
124
+ * @template TOutput - The validated output type
125
+ * @template TInput - The raw input type
126
+ * @param zodSchema - The Zod schema to wrap
127
+ * @returns Wrapped Schema instance
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * import { z } from 'zod';
132
+ * import { wrapSchema } from '@veloxts/validation';
133
+ *
134
+ * const UserSchema = wrapSchema(z.object({
135
+ * id: z.string().uuid(),
136
+ * name: z.string().min(1),
137
+ * }));
138
+ * ```
139
+ */
140
+ export declare function wrapSchema<TOutput, TInput = TOutput>(zodSchema: ZodType<TOutput, ZodTypeDef, TInput>): Schema<TOutput, TInput>;
141
+ /**
142
+ * Represents no input (undefined) for procedures without input schemas
143
+ */
144
+ export type NoInput = undefined;
145
+ /**
146
+ * Represents unknown output for procedures without output schemas
147
+ */
148
+ export type UnknownOutput = unknown;
149
+ /**
150
+ * Utility type to resolve the effective input type
151
+ * Returns NoInput if undefined, otherwise the inferred type
152
+ */
153
+ export type ResolveInput<T> = T extends undefined ? NoInput : InferOutput<T>;
154
+ /**
155
+ * Utility type to resolve the effective output type
156
+ * Returns UnknownOutput if undefined, otherwise the inferred type
157
+ */
158
+ export type ResolveOutput<T> = T extends undefined ? UnknownOutput : InferOutput<T>;
159
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAM/C;;;;;;;;GAQG;AAEH,MAAM,WAAW,MAAM,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO;IAC1D;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IAE5C;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,eAAe,CAAC,OAAO,CAAC,CAAC;IAEjE;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,gBAAgB,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC;AAEtE;;GAEG;AAC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