@globalart/zod-to-proto 2.0.0 → 2.0.2
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/README.md +2 -489
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -2,496 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
A library for converting Zod schemas to Protobuf definitions. Automatically generates `.proto` files from Zod validation schemas, including support for gRPC services.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Documentation
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
npm install @globalart/zod-to-proto zod
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
or
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
yarn add @globalart/zod-to-proto zod
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
or
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
pnpm add @globalart/zod-to-proto zod
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Quick Start
|
|
24
|
-
|
|
25
|
-
### Basic Usage
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import { zodToProtobuf } from "@globalart/zod-to-proto";
|
|
29
|
-
import { z } from "zod";
|
|
30
|
-
|
|
31
|
-
const schema = z.object({
|
|
32
|
-
name: z.string(),
|
|
33
|
-
age: z.number(),
|
|
34
|
-
email: z.string().email(),
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const protoDefinition = zodToProtobuf(schema, {
|
|
38
|
-
packageName: "user.service",
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
console.log(protoDefinition);
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
Output:
|
|
45
|
-
|
|
46
|
-
```protobuf
|
|
47
|
-
syntax = "proto3";
|
|
48
|
-
package user.service;
|
|
49
|
-
|
|
50
|
-
message Message {
|
|
51
|
-
string name = 1;
|
|
52
|
-
int32 age = 2;
|
|
53
|
-
string email = 3;
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### Generating gRPC Services
|
|
58
|
-
|
|
59
|
-
There are two ways to define gRPC services:
|
|
60
|
-
|
|
61
|
-
#### Option 1: Using Zod Schemas with Functions (Recommended)
|
|
62
|
-
|
|
63
|
-
```typescript
|
|
64
|
-
import { zodToProtobuf } from "@globalart/zod-to-proto";
|
|
65
|
-
import { z } from "zod";
|
|
66
|
-
|
|
67
|
-
// Define request/response schemas
|
|
68
|
-
const getUserByIdRequestSchema = z.object({
|
|
69
|
-
id: z.number().int(),
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const userSchema = z.object({
|
|
73
|
-
id: z.number().int(),
|
|
74
|
-
name: z.string(),
|
|
75
|
-
email: z.string(),
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
// Define service using z.function()
|
|
79
|
-
const userServiceSchema = z.object({
|
|
80
|
-
getUserById: z.function({
|
|
81
|
-
input: [getUserByIdRequestSchema],
|
|
82
|
-
output: userSchema,
|
|
83
|
-
}),
|
|
84
|
-
createUser: z.function({
|
|
85
|
-
input: [userSchema],
|
|
86
|
-
output: z.object({
|
|
87
|
-
id: z.number().int(),
|
|
88
|
-
success: z.boolean(),
|
|
89
|
-
}),
|
|
90
|
-
}),
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const protoDefinition = zodToProtobuf(z.object(), {
|
|
94
|
-
packageName: "user.service",
|
|
95
|
-
services: {
|
|
96
|
-
UserService: userServiceSchema,
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
console.log(protoDefinition);
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
#### Option 2: Using Service Definitions Array
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
import { zodToProtobuf } from "@globalart/zod-to-proto";
|
|
107
|
-
import { z } from "zod";
|
|
108
|
-
|
|
109
|
-
const protoDefinition = zodToProtobuf(z.object(), {
|
|
110
|
-
packageName: "user.service",
|
|
111
|
-
services: [
|
|
112
|
-
{
|
|
113
|
-
name: "UserService",
|
|
114
|
-
methods: [
|
|
115
|
-
{
|
|
116
|
-
name: "getUser",
|
|
117
|
-
request: z.object({
|
|
118
|
-
id: z.string(),
|
|
119
|
-
}),
|
|
120
|
-
response: z.object({
|
|
121
|
-
name: z.string(),
|
|
122
|
-
age: z.number(),
|
|
123
|
-
email: z.string(),
|
|
124
|
-
}),
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
name: "createUser",
|
|
128
|
-
request: z.object({
|
|
129
|
-
name: z.string(),
|
|
130
|
-
age: z.number(),
|
|
131
|
-
email: z.string(),
|
|
132
|
-
}),
|
|
133
|
-
response: z.object({
|
|
134
|
-
id: z.string(),
|
|
135
|
-
success: z.boolean(),
|
|
136
|
-
}),
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
},
|
|
140
|
-
],
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
console.log(protoDefinition);
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
Both approaches produce the same output:
|
|
147
|
-
|
|
148
|
-
```protobuf
|
|
149
|
-
syntax = "proto3";
|
|
150
|
-
package user.service;
|
|
151
|
-
|
|
152
|
-
message GetUserByIdRequest {
|
|
153
|
-
int32 id = 1;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
message GetUserByIdResponse {
|
|
157
|
-
int32 id = 1;
|
|
158
|
-
string name = 2;
|
|
159
|
-
string email = 3;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
message CreateUserRequest {
|
|
163
|
-
int32 id = 1;
|
|
164
|
-
string name = 2;
|
|
165
|
-
string email = 3;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
message CreateUserResponse {
|
|
169
|
-
int32 id = 1;
|
|
170
|
-
bool success = 2;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
service UserService {
|
|
174
|
-
rpc GetUserById(GetUserByIdRequest) returns (GetUserByIdResponse);
|
|
175
|
-
rpc CreateUser(CreateUserRequest) returns (CreateUserResponse);
|
|
176
|
-
}
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
## API
|
|
180
|
-
|
|
181
|
-
### `zodToProtobuf(schema?, options?)`
|
|
182
|
-
|
|
183
|
-
Converts a Zod schema to a Protobuf definition.
|
|
184
|
-
|
|
185
|
-
#### Parameters
|
|
186
|
-
|
|
187
|
-
- `schema` (optional): `ZodTypeAny` - Root Zod schema to convert
|
|
188
|
-
- `options` (optional): `ZodToProtobufOptions` - Configuration options
|
|
189
|
-
|
|
190
|
-
### `zodToProtobufService(options?)`
|
|
191
|
-
|
|
192
|
-
Convenience wrapper for generating only gRPC service definitions without passing an explicit root schema.
|
|
193
|
-
|
|
194
|
-
```typescript
|
|
195
|
-
import { zodToProtobufService } from "@globalart/zod-to-proto";
|
|
196
|
-
import { z } from "zod";
|
|
197
|
-
|
|
198
|
-
const userServiceSchema = z.object({
|
|
199
|
-
getUserById: z.function({
|
|
200
|
-
input: [z.object({ id: z.number().int() })],
|
|
201
|
-
output: z.object({
|
|
202
|
-
id: z.number().int(),
|
|
203
|
-
name: z.string(),
|
|
204
|
-
}),
|
|
205
|
-
}),
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
const protoDefinition = zodToProtobufService({
|
|
209
|
-
packageName: "user.service",
|
|
210
|
-
services: {
|
|
211
|
-
UserService: userServiceSchema,
|
|
212
|
-
},
|
|
213
|
-
});
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
#### Options
|
|
217
|
-
|
|
218
|
-
```typescript
|
|
219
|
-
interface ZodToProtobufOptions {
|
|
220
|
-
packageName?: string; // Protobuf package name (default: "default")
|
|
221
|
-
rootMessageName?: string; // Root message name (default: "Message")
|
|
222
|
-
typePrefix?: string; // Prefix for message and enum types
|
|
223
|
-
services?: ServicesInput; // gRPC service definitions
|
|
224
|
-
skipRootMessage?: boolean; // Skip root message generation
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
type ServicesInput = ServiceDefinition[] | Record<string, ZodObject<any>>;
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
#### Service Definition
|
|
231
|
-
|
|
232
|
-
You can define services in two ways:
|
|
233
|
-
|
|
234
|
-
**Option 1: Using Zod Schemas (Recommended)**
|
|
235
|
-
|
|
236
|
-
```typescript
|
|
237
|
-
const serviceSchema = z.object({
|
|
238
|
-
methodName: z.function({
|
|
239
|
-
input: [requestSchema],
|
|
240
|
-
output: responseSchema,
|
|
241
|
-
}),
|
|
242
|
-
// ... more methods
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
// Use in options
|
|
246
|
-
const proto = zodToProtobuf(z.object(), {
|
|
247
|
-
services: {
|
|
248
|
-
ServiceName: serviceSchema,
|
|
249
|
-
},
|
|
250
|
-
});
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
**Option 2: Using Service Definitions Array**
|
|
254
|
-
|
|
255
|
-
```typescript
|
|
256
|
-
interface ServiceDefinition {
|
|
257
|
-
name: string; // Service name
|
|
258
|
-
methods: ServiceMethod[];
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
interface ServiceMethod {
|
|
262
|
-
name: string; // Method name
|
|
263
|
-
request: ZodTypeAny; // Request Zod schema
|
|
264
|
-
response: ZodTypeAny; // Response Zod schema
|
|
265
|
-
streaming?: "client" | "server" | "bidirectional"; // Streaming type (optional)
|
|
266
|
-
}
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
## Supported Zod Types
|
|
270
|
-
|
|
271
|
-
### Basic Types
|
|
272
|
-
|
|
273
|
-
- `z.string()` → `string`
|
|
274
|
-
- `z.number()` → `int32` (or `int64`, `float`, `double` depending on validation)
|
|
275
|
-
- `z.boolean()` → `bool`
|
|
276
|
-
- `z.bigint()` → `int64`
|
|
277
|
-
- `z.date()` → `string`
|
|
278
|
-
|
|
279
|
-
### Collections
|
|
280
|
-
|
|
281
|
-
- `z.array()` → `repeated`
|
|
282
|
-
- `z.set()` → `repeated`
|
|
283
|
-
- `z.map()` → `map<keyType, valueType>` (key must be int32, int64, string, or bool)
|
|
284
|
-
- `z.record()` → `map<keyType, valueType>` (same as z.map())
|
|
285
|
-
- `z.tuple()` → nested message
|
|
286
|
-
|
|
287
|
-
### Complex Types
|
|
288
|
-
|
|
289
|
-
- `z.object()` → nested message
|
|
290
|
-
- `z.enum()` → `enum`
|
|
291
|
-
- `z.optional()` → `optional`
|
|
292
|
-
- `z.nullable()` → `optional`
|
|
293
|
-
|
|
294
|
-
### Examples
|
|
295
|
-
|
|
296
|
-
```typescript
|
|
297
|
-
import { zodToProtobuf } from "@globalart/zod-to-proto";
|
|
298
|
-
import { z } from "zod";
|
|
299
|
-
|
|
300
|
-
const schema = z.object({
|
|
301
|
-
id: z.string(),
|
|
302
|
-
tags: z.array(z.string()),
|
|
303
|
-
metadata: z.map(z.string(), z.number()),
|
|
304
|
-
settings: z.record(z.string(), z.string()),
|
|
305
|
-
status: z.enum(["active", "inactive", "pending"]),
|
|
306
|
-
profile: z.object({
|
|
307
|
-
firstName: z.string(),
|
|
308
|
-
lastName: z.string(),
|
|
309
|
-
age: z.number().optional(),
|
|
310
|
-
}),
|
|
311
|
-
coordinates: z.tuple([z.number(), z.number()]),
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
const protoDefinition = zodToProtobuf(schema, {
|
|
315
|
-
packageName: "example",
|
|
316
|
-
});
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
## Usage Examples
|
|
320
|
-
|
|
321
|
-
### With Custom Type Prefix
|
|
322
|
-
|
|
323
|
-
```typescript
|
|
324
|
-
const protoDefinition = zodToProtobuf(schema, {
|
|
325
|
-
packageName: "api.v1",
|
|
326
|
-
typePrefix: "ApiV1",
|
|
327
|
-
rootMessageName: "User",
|
|
328
|
-
});
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
### With Streaming Methods
|
|
332
|
-
|
|
333
|
-
```typescript
|
|
334
|
-
const protoDefinition = zodToProtobuf(z.object(), {
|
|
335
|
-
packageName: "chat.service",
|
|
336
|
-
services: [
|
|
337
|
-
{
|
|
338
|
-
name: "ChatService",
|
|
339
|
-
methods: [
|
|
340
|
-
{
|
|
341
|
-
name: "sendMessage",
|
|
342
|
-
request: z.object({ message: z.string() }),
|
|
343
|
-
response: z.object({ success: z.boolean() }),
|
|
344
|
-
},
|
|
345
|
-
{
|
|
346
|
-
name: "streamMessages",
|
|
347
|
-
request: z.object({ roomId: z.string() }),
|
|
348
|
-
response: z.object({ message: z.string() }),
|
|
349
|
-
streaming: "server",
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
name: "chat",
|
|
353
|
-
request: z.object({ message: z.string() }),
|
|
354
|
-
response: z.object({ message: z.string() }),
|
|
355
|
-
streaming: "bidirectional",
|
|
356
|
-
},
|
|
357
|
-
],
|
|
358
|
-
},
|
|
359
|
-
],
|
|
360
|
-
});
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
### Without Root Message
|
|
364
|
-
|
|
365
|
-
```typescript
|
|
366
|
-
const protoDefinition = zodToProtobuf(schema, {
|
|
367
|
-
packageName: "example",
|
|
368
|
-
skipRootMessage: true,
|
|
369
|
-
services: [
|
|
370
|
-
{
|
|
371
|
-
name: "ExampleService",
|
|
372
|
-
methods: [
|
|
373
|
-
{
|
|
374
|
-
name: "doSomething",
|
|
375
|
-
request: z.object({ input: z.string() }),
|
|
376
|
-
response: z.object({ output: z.string() }),
|
|
377
|
-
},
|
|
378
|
-
],
|
|
379
|
-
},
|
|
380
|
-
],
|
|
381
|
-
});
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
## Advanced Usage
|
|
385
|
-
|
|
386
|
-
### Working with Maps and Records
|
|
387
|
-
|
|
388
|
-
Protobuf maps have strict key type requirements. Only integral types, strings, and booleans are allowed as keys. Both `z.map()` and `z.record()` are converted to protobuf `map<>` type:
|
|
389
|
-
|
|
390
|
-
```typescript
|
|
391
|
-
const schema = z.object({
|
|
392
|
-
// ✅ Valid map keys
|
|
393
|
-
usersByStringId: z.map(z.string(), userSchema),
|
|
394
|
-
usersByIntId: z.map(z.number().int(), userSchema),
|
|
395
|
-
flagsMap: z.map(z.boolean(), z.string()),
|
|
396
|
-
|
|
397
|
-
// ✅ Using z.record() - same as z.map()
|
|
398
|
-
metadataRecord: z.record(z.string(), z.string()),
|
|
399
|
-
settingsRecord: z.record(z.string(), z.number()),
|
|
400
|
-
|
|
401
|
-
// ❌ Invalid - double is not allowed as map key
|
|
402
|
-
invalidMap: z.map(z.number(), userSchema), // Use .int() instead!
|
|
403
|
-
});
|
|
404
|
-
```
|
|
405
|
-
|
|
406
|
-
### Type-Safe Service Definitions
|
|
407
|
-
|
|
408
|
-
When using Zod schemas for services, you get full TypeScript type safety:
|
|
409
|
-
|
|
410
|
-
```typescript
|
|
411
|
-
const userServiceSchema = z.object({
|
|
412
|
-
getUser: z.function({
|
|
413
|
-
input: [z.object({ id: z.number().int() })],
|
|
414
|
-
output: userSchema,
|
|
415
|
-
}),
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
type UserService = z.infer<typeof userServiceSchema>;
|
|
419
|
-
|
|
420
|
-
// Implementation with type checking
|
|
421
|
-
class UserServiceImpl implements UserService {
|
|
422
|
-
async getUser({ id }: { id: number }) {
|
|
423
|
-
// TypeScript knows the shape of input and output
|
|
424
|
-
return { id, name: "John", email: "john@example.com" };
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
### Avoiding Circular Dependencies
|
|
430
|
-
|
|
431
|
-
**Important:** Avoid circular dependencies between schema files. Circular imports will cause types to become `undefined` during schema construction.
|
|
432
|
-
|
|
433
|
-
❌ **Bad Example:**
|
|
434
|
-
```typescript
|
|
435
|
-
// user.schema.ts
|
|
436
|
-
import { getUserByIdResponseSchema } from "./get-user-by-id.schema";
|
|
437
|
-
|
|
438
|
-
export const userSchema = z.object({ ... });
|
|
439
|
-
|
|
440
|
-
export const userServiceSchema = z.object({
|
|
441
|
-
getUserById: z.function({
|
|
442
|
-
input: [...],
|
|
443
|
-
output: getUserByIdResponseSchema, // ❌ Circular dependency
|
|
444
|
-
}),
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
// get-user-by-id.schema.ts
|
|
448
|
-
import { userSchema } from "./user.schema"; // ❌ Circular dependency
|
|
449
|
-
|
|
450
|
-
export const getUserByIdResponseSchema = userSchema;
|
|
451
|
-
```
|
|
452
|
-
|
|
453
|
-
✅ **Good Example:**
|
|
454
|
-
```typescript
|
|
455
|
-
// user.schema.ts
|
|
456
|
-
import { getUserByIdRequestSchema } from "./get-user-by-id.schema";
|
|
457
|
-
|
|
458
|
-
export const userSchema = z.object({ ... });
|
|
459
|
-
|
|
460
|
-
export const userServiceSchema = z.object({
|
|
461
|
-
getUserById: z.function({
|
|
462
|
-
input: [getUserByIdRequestSchema],
|
|
463
|
-
output: userSchema, // ✅ Direct reference, no circular dependency
|
|
464
|
-
}),
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
// get-user-by-id.schema.ts
|
|
468
|
-
export const getUserByIdRequestSchema = z.object({ id: z.number().int() });
|
|
469
|
-
// No import of userSchema needed
|
|
470
|
-
```
|
|
471
|
-
|
|
472
|
-
### Multiple Services
|
|
473
|
-
|
|
474
|
-
You can define multiple services in a single protobuf file:
|
|
475
|
-
|
|
476
|
-
```typescript
|
|
477
|
-
const protoDefinition = zodToProtobuf(z.object(), {
|
|
478
|
-
packageName: "api.v1",
|
|
479
|
-
services: {
|
|
480
|
-
UserService: userServiceSchema,
|
|
481
|
-
AuthService: authServiceSchema,
|
|
482
|
-
ProductService: productServiceSchema,
|
|
483
|
-
},
|
|
484
|
-
});
|
|
485
|
-
```
|
|
486
|
-
|
|
487
|
-
## Limitations
|
|
488
|
-
|
|
489
|
-
- Only the types listed above are supported
|
|
490
|
-
- Unsupported types will throw `UnsupportedTypeException`
|
|
491
|
-
- Nested objects are automatically converted to separate messages
|
|
492
|
-
- Enum values are converted to numbers starting from 0
|
|
493
|
-
- Map keys must be integral types (int32, int64, etc.), strings, or booleans - **not** doubles or floats
|
|
494
|
-
- Avoid circular dependencies between schema files
|
|
7
|
+
For complete documentation, examples, and API reference, please visit the [official documentation](https://globalart.js.org/packages/zod-to-proto).
|
|
495
8
|
|
|
496
9
|
## License
|
|
497
10
|
|
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import * as inflection from "inflection";
|
|
|
10
10
|
* @returns Protobuf number type name ("int32" or "double")
|
|
11
11
|
*/
|
|
12
12
|
const getNumberTypeName = ({ value }) => {
|
|
13
|
-
return value.
|
|
13
|
+
return ["float32", "float64"].includes(value.format ?? "") ? "double" : "int32";
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* Converts a string to PascalCase format.
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["tupleFields: ProtobufField[]","methods: ServiceMethod[]","streaming: \"client\" | \"server\" | \"bidirectional\" | undefined","protoDefinition: string"],"sources":["../src/utils.ts","../src/traversers.ts","../src/service-generator.ts","../src/zod-to-protobuf.ts"],"sourcesContent":["import { ZodNumber } from \"zod\";\nimport type { ProtobufField } from \"./types\";\n\n/**\n * Determines the protobuf number type name based on Zod number schema.\n * Returns \"int32\" for integers, \"double\" for floating point numbers.\n *\n * @param value - Zod number schema\n * @returns Protobuf number type name (\"int32\" or \"double\")\n */\nexport const getNumberTypeName = ({ value }: { value: ZodNumber }): string => {\n return value.isInt ? \"int32\" : \"double\";\n};\n\n/**\n * Converts a string to PascalCase format.\n * Handles dot-separated strings by capitalizing each part.\n *\n * @param value - String to convert\n * @returns PascalCase string\n */\nexport const toPascalCase = ({ value }: { value: string }): string => {\n return value\n .split(\".\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\"\");\n};\n\n/**\n * Converts a protobuf field definition to its type string representation.\n * Filters out null/empty values and joins the remaining types.\n *\n * @param field - Protobuf field definition\n * @returns Type string for the protobuf field\n */\nexport const protobufFieldToType = ({\n field,\n}: {\n field: ProtobufField;\n}): string => {\n return field.types.filter(Boolean).join(\" \");\n};\n","import * as inflection from \"inflection\";\nimport {\n ZodArray,\n ZodBigInt,\n ZodBoolean,\n ZodDate,\n ZodEnum,\n ZodMap,\n ZodNullable,\n ZodNumber,\n ZodObject,\n ZodOptional,\n ZodRecord,\n ZodSet,\n ZodString,\n ZodTuple,\n ZodType,\n type ZodTypeAny,\n} from \"zod\";\nimport {\n ZodArrayDefinition,\n ZodMapDefinition,\n ZodRecordDefinition,\n type ProtobufField,\n} from \"./types\";\nimport { getNumberTypeName, toPascalCase, protobufFieldToType } from \"./utils\";\n\n/**\n * Traverses a Zod array or set schema and converts it to protobuf repeated fields.\n * Handles nested types and generates appropriate field definitions.\n *\n * @param key - Field name\n * @param value - Zod array or set schema\n * @param messages - Map of message names to their protobuf fields\n * @param enums - Map of enum names to their protobuf values\n * @param typePrefix - Optional prefix for type names\n * @param parentKey - Optional parent message name for nested types\n * @returns Array of protobuf field definitions\n */\nexport const traverseArray = ({\n key,\n value,\n messages,\n enums,\n typePrefix,\n parentKey,\n}: {\n key: string;\n value: ZodArray<ZodTypeAny> | ZodSet<ZodTypeAny>;\n messages: Map<string, string[]>;\n enums: Map<string, string[]>;\n typePrefix: string | null;\n parentKey?: string;\n}): ProtobufField[] => {\n const nestedValue =\n value instanceof ZodArray\n ? value.element\n : value instanceof ZodSet\n ? (value.def as unknown as ZodArrayDefinition).valueType\n : // @ts-expect-error\n (value.def as unknown as ZodArrayDefinition).element;\n\n const singularKey = inflection.singularize(key);\n const elementFields = traverseKey({\n key: singularKey,\n value: nestedValue,\n messages,\n enums,\n isOptional: false,\n isInArray: true,\n typePrefix,\n parentKey: nestedValue instanceof ZodObject ? parentKey : undefined,\n });\n return elementFields.map((field) => ({\n ...field,\n types: [\"repeated\", ...field.types],\n name: field.name.replace(singularKey, key),\n }));\n};\n\n/**\n * Traverses a Zod map schema and converts it to a protobuf map type.\n * Validates that both key and value types are simple types suitable for map keys/values.\n *\n * @param key - Field name\n * @param value - Zod map schema\n * @param messages - Map of message names to their protobuf fields\n * @param enums - Map of enum names to their protobuf values\n * @param typePrefix - Optional prefix for type names\n * @param parentKey - Optional parent message name for nested types\n * @returns Array containing a single protobuf map field definition, or empty array if invalid\n */\nexport const traverseMap = ({\n key,\n value,\n messages,\n enums,\n typePrefix,\n parentKey,\n}: {\n key: string;\n value: ZodMap<ZodTypeAny, ZodTypeAny>;\n messages: Map<string, string[]>;\n enums: Map<string, string[]>;\n typePrefix: string | null;\n parentKey?: string;\n}): ProtobufField[] => {\n const mapDef = value.def as ZodMapDefinition;\n\n const keyType = traverseKey({\n key: inflection.singularize(key),\n value: mapDef.keyType,\n messages,\n enums,\n isOptional: false,\n isInArray: true,\n typePrefix,\n parentKey,\n });\n const valueType = traverseKey({\n key: inflection.singularize(key),\n value: mapDef.valueType,\n messages,\n enums,\n isOptional: false,\n isInArray: true,\n typePrefix,\n parentKey,\n });\n\n if (!keyType[0] || keyType.length !== 1) {\n return [];\n }\n\n if (!valueType[0] || valueType.length !== 1) {\n return [];\n }\n\n const mapType = `map<${protobufFieldToType({ field: keyType[0] })}, ${protobufFieldToType({ field: valueType[0] })}>`;\n return [\n {\n types: [mapType],\n name: key,\n },\n ];\n};\n\n/**\n * Traverses a Zod record schema and converts it to a protobuf map type.\n * Similar to traverseMap but handles ZodRecord type.\n *\n * @param key - Field name\n * @param value - Zod record schema\n * @param messages - Map of message names to their protobuf fields\n * @param enums - Map of enum names to their protobuf values\n * @param typePrefix - Optional prefix for type names\n * @param parentKey - Optional parent message name for nested types\n * @returns Array containing a single protobuf map field definition, or empty array if invalid\n */\nexport const traverseRecord = ({\n key,\n value,\n messages,\n enums,\n typePrefix,\n parentKey,\n}: {\n key: string;\n value: ZodRecord;\n messages: Map<string, string[]>;\n enums: Map<string, string[]>;\n typePrefix: string | null;\n parentKey?: string;\n}): ProtobufField[] => {\n const recordDef = value.def as unknown as ZodRecordDefinition;\n\n const keyType = traverseKey({\n key: inflection.singularize(key),\n value: recordDef.keyType,\n messages,\n enums,\n isOptional: false,\n isInArray: true,\n typePrefix,\n parentKey,\n });\n const valueType = traverseKey({\n key: inflection.singularize(key),\n value: recordDef.valueType,\n messages,\n enums,\n isOptional: false,\n isInArray: true,\n typePrefix,\n parentKey,\n });\n\n if (!keyType[0] || keyType.length !== 1) {\n return [];\n }\n\n if (!valueType[0] || valueType.length !== 1) {\n return [];\n }\n\n const mapType = `map<${protobufFieldToType({ field: keyType[0] })}, ${protobufFieldToType({ field: valueType[0] })}>`;\n return [\n {\n types: [mapType],\n name: key,\n },\n ];\n};\n\n/**\n * Traverses a single key-value pair from a Zod schema and converts it to protobuf field definitions.\n * Handles various Zod types including primitives, objects, arrays, maps, enums, tuples, and optional/nullable fields.\n *\n * @param key - Field name\n * @param value - Zod schema value\n * @param messages - Map of message names to their protobuf fields\n * @param enums - Map of enum names to their protobuf values\n * @param isOptional - Whether the field is optional\n * @param isInArray - Whether the field is inside an array\n * @param typePrefix - Optional prefix for type names\n * @param parentKey - Optional parent message name for nested types\n * @returns Array of protobuf field definitions\n */\nexport const traverseKey = ({\n key,\n value,\n messages,\n enums,\n isOptional,\n isInArray,\n typePrefix,\n parentKey,\n}: {\n key: string;\n value: unknown;\n messages: Map<string, string[]>;\n enums: Map<string, string[]>;\n isOptional: boolean;\n isInArray: boolean;\n typePrefix: string | null;\n parentKey?: string;\n}): ProtobufField[] => {\n if (!value) {\n return [];\n }\n\n if (value instanceof ZodOptional || value instanceof ZodNullable) {\n return traverseKey({\n key,\n value: value.unwrap(),\n messages,\n enums,\n isOptional: true,\n isInArray,\n typePrefix,\n parentKey,\n });\n }\n\n if (value instanceof ZodArray || value instanceof ZodSet) {\n return traverseArray({\n key,\n value: value as ZodArray<ZodTypeAny> | ZodSet<ZodTypeAny>,\n messages,\n enums,\n typePrefix,\n parentKey,\n });\n }\n\n if (value instanceof ZodMap) {\n return traverseMap({\n key,\n value: value as ZodMap<ZodTypeAny, ZodTypeAny>,\n messages,\n enums,\n typePrefix,\n parentKey,\n });\n }\n\n if (value instanceof ZodRecord) {\n return traverseRecord({\n key,\n value: value as ZodRecord,\n messages,\n enums,\n typePrefix,\n parentKey,\n });\n }\n\n const optional = isOptional && !isInArray ? \"optional\" : null;\n\n if (value instanceof ZodObject) {\n let messageName = toPascalCase({ value: key });\n if (parentKey) {\n const isParentAlreadyPascalCase = /^[A-Z][a-zA-Z0-9]*$/.test(parentKey);\n if (isParentAlreadyPascalCase) {\n messageName = `${parentKey}${messageName}`;\n } else {\n const parentMessageName = toPascalCase({ value: parentKey });\n messageName = `${parentMessageName}${messageName}`;\n }\n }\n if (typePrefix) {\n messageName = `${typePrefix}${messageName}`;\n }\n const nestedMessageFields = traverseSchema({\n schema: value,\n messages,\n enums,\n typePrefix,\n parentKey: messageName,\n });\n messages.set(messageName, nestedMessageFields);\n return [\n {\n types: [optional, messageName],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodString) {\n return [\n {\n types: [optional, \"string\"],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodNumber) {\n const typeName = getNumberTypeName({ value });\n return [\n {\n types: [optional, typeName],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodBoolean) {\n return [\n {\n types: [optional, \"bool\"],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodEnum) {\n const enumFields = value.options\n .map(\n (option: string | number, index: number) =>\n ` ${String(option)} = ${index};`,\n )\n .join(\"\\n\");\n let enumName = toPascalCase({ value: key });\n if (parentKey) {\n const isParentAlreadyPascalCase = /^[A-Z][a-zA-Z0-9]*$/.test(parentKey);\n if (isParentAlreadyPascalCase) {\n enumName = `${parentKey}${enumName}`;\n } else {\n const parentMessageName = toPascalCase({ value: parentKey });\n enumName = `${parentMessageName}${enumName}`;\n }\n }\n if (typePrefix) {\n enumName = `${typePrefix}${enumName}`;\n }\n enums.set(enumName, [`enum ${enumName} {\\n${enumFields}\\n}`]);\n return [\n {\n types: [optional, enumName],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodDate) {\n return [\n {\n types: [optional, \"string\"],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodBigInt) {\n return [\n {\n types: [optional, \"int64\"],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodType) {\n const def = value.def as {\n type?: string;\n check?: unknown;\n fn?: (data: unknown) => boolean;\n };\n if (def.type === \"custom\" && def.check === \"custom\" && def.fn) {\n try {\n if (\n (typeof Buffer !== \"undefined\" && def.fn(Buffer.alloc(0))) ||\n (typeof Uint8Array !== \"undefined\" && def.fn(new Uint8Array(0)))\n ) {\n return [\n {\n types: [optional, \"bytes\"],\n name: key,\n },\n ];\n }\n } catch {}\n }\n }\n\n if (value instanceof ZodTuple) {\n const tupleFields: ProtobufField[] = (\n value.def.items as ZodTypeAny[]\n ).flatMap((item: ZodTypeAny, index: number) => {\n return traverseKey({\n key: `${key}_${index}`,\n value: item,\n messages,\n enums,\n isOptional: false,\n isInArray,\n typePrefix,\n parentKey,\n });\n });\n\n let tupleMessageName = toPascalCase({ value: key });\n if (parentKey) {\n const isParentAlreadyPascalCase = /^[A-Z][a-zA-Z0-9]*$/.test(parentKey);\n if (isParentAlreadyPascalCase) {\n tupleMessageName = `${parentKey}${tupleMessageName}`;\n } else {\n const parentMessageName = toPascalCase({ value: parentKey });\n tupleMessageName = `${parentMessageName}${tupleMessageName}`;\n }\n }\n if (typePrefix) {\n tupleMessageName = `${typePrefix}${tupleMessageName}`;\n }\n messages.set(\n tupleMessageName,\n tupleFields.map(\n (field, index) =>\n ` ${field.types.join(\" \")} ${field.name} = ${index + 1};`,\n ),\n );\n return [\n {\n types: [optional, tupleMessageName],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodType) {\n return [];\n }\n\n return [];\n};\n\n/**\n * Traverses a Zod object schema and converts it to protobuf message field definitions.\n * Processes all fields in the schema and generates appropriate protobuf types.\n *\n * @param schema - Zod schema to traverse\n * @param messages - Map of message names to their protobuf fields\n * @param enums - Map of enum names to their protobuf values\n * @param typePrefix - Optional prefix for type names\n * @param parentKey - Optional parent message name for nested types\n * @returns Array of protobuf field definition strings\n */\nexport const traverseSchema = ({\n schema,\n messages,\n enums,\n typePrefix,\n parentKey,\n}: {\n schema: ZodTypeAny;\n messages: Map<string, string[]>;\n enums: Map<string, string[]>;\n typePrefix: string | null;\n parentKey?: string;\n}): string[] => {\n if (\n !schema ||\n typeof schema !== \"object\" ||\n !(\"def\" in schema) ||\n (schema.constructor.name !== \"ZodObject\" &&\n (schema.def as { type?: string }).type !== \"object\")\n ) {\n return [];\n }\n\n const zodObject = schema as ZodObject<any>;\n const fields = Object.entries(zodObject.shape).flatMap(([key, value]) => {\n return traverseKey({\n key,\n value,\n messages,\n enums,\n isOptional: false,\n isInArray: false,\n typePrefix,\n parentKey,\n });\n });\n\n return fields.map(\n (field, index) =>\n `${protobufFieldToType({ field })} ${field.name} = ${index + 1};`,\n );\n};\n","import { z, ZodObject, type ZodTypeAny } from \"zod\";\nimport type {\n ServiceDefinition,\n ServiceMethod,\n ServicesInput,\n ZodFunctionDefinition,\n ZodTupleDefinition,\n} from \"./types\";\nimport { toPascalCase } from \"./utils\";\nimport { traverseSchema } from \"./traversers\";\n\n/**\n * Context for generating protobuf services.\n * Contains accumulated messages, enums, and type prefix.\n */\ninterface ServiceGenerationContext {\n /** Map of message names to their protobuf fields */\n messages: Map<string, string[]>;\n /** Map of enum names to their protobuf values */\n enums: Map<string, string[]>;\n /** Prefix for type names or null if prefix is not used */\n typePrefix: string | null;\n}\n\n/**\n * Parses a Zod service schema and extracts method definitions.\n * Each method must be a function with one argument (request) and a return value (response).\n *\n * @param name - Service name\n * @param schema - Zod object containing service methods as functions\n * @returns Service definition with extracted methods\n */\nconst parseZodServiceSchema = (\n name: string,\n schema: ZodObject<Record<string, ZodTypeAny>>,\n): ServiceDefinition => {\n const shape = schema.shape as Record<string, ZodTypeAny>;\n const methods: ServiceMethod[] = [];\n\n for (const [methodName, methodSchema] of Object.entries(shape)) {\n const methodDef = (methodSchema as ZodTypeAny).def as ZodFunctionDefinition;\n\n if (methodDef.type === \"function\") {\n const inputDef = methodDef.input;\n\n const args = (inputDef?.def as ZodTupleDefinition)?.items ?? [];\n const output = methodDef.output as ZodTypeAny;\n\n if (args.length > 0 && args[0] && output) {\n const request = args[0];\n const response = output;\n\n let streaming: \"client\" | \"server\" | \"bidirectional\" | undefined;\n const metadata = methodSchema.meta();\n streaming = metadata?.streaming as\n | \"client\"\n | \"server\"\n | \"bidirectional\"\n | undefined;\n\n methods.push({\n name: methodName,\n request,\n response,\n streaming,\n });\n }\n }\n }\n\n return {\n name,\n methods,\n };\n};\n\n/**\n * Normalizes service input data into an array of service definitions.\n * If an array is passed, returns it as is.\n * If an object is passed, converts each key-value pair into a service definition.\n *\n * @param services - Array of service definitions or object with Zod schemas\n * @returns Array of normalized service definitions\n */\nconst normalizeServices = (services: ServicesInput): ServiceDefinition[] => {\n if (Array.isArray(services)) {\n return services;\n }\n\n return Object.entries(services).map(([name, schema]) =>\n parseZodServiceSchema(name, schema),\n );\n};\n\n/**\n * Ensures that the schema is a ZodObject.\n * If the schema is already an object, returns it as is.\n * Otherwise, wraps the schema in an object with a \"data\" field.\n *\n * @param schema - Zod schema of any type\n * @returns ZodObject containing the original schema\n */\nconst ensureZodObject = (\n schema: ZodTypeAny,\n): ZodObject<Record<string, ZodTypeAny>> => {\n const schemaType =\n (schema.def as { type?: string }).type || schema.constructor.name;\n\n if (schemaType === \"object\" || schema.constructor.name === \"ZodObject\") {\n return schema as ZodObject<Record<string, ZodTypeAny>>;\n }\n\n return z.object({\n data: schema,\n });\n};\n\n/**\n * Generates the name for a request message based on the method name.\n *\n * @param methodName - Name of the service method\n * @param typePrefix - Optional prefix for type names\n * @returns Generated request message name in PascalCase\n */\nconst generateRequestMessageName = (\n methodName: string,\n typePrefix: string | null,\n): string => {\n const messageName = toPascalCase({ value: `${methodName}Request` });\n return typePrefix ? `${typePrefix}${messageName}` : messageName;\n};\n\n/**\n * Generates the name for a response message based on the method name.\n *\n * @param methodName - Name of the service method\n * @param typePrefix - Optional prefix for type names\n * @returns Generated response message name in PascalCase\n */\nconst generateResponseMessageName = (\n methodName: string,\n typePrefix: string | null,\n): string => {\n const messageName = toPascalCase({ value: `${methodName}Response` });\n return typePrefix ? `${typePrefix}${messageName}` : messageName;\n};\n\n/**\n * Processes a service method by generating request and response message names\n * and traversing their schemas to populate the context with message definitions.\n *\n * @param method - Service method definition\n * @param context - Generation context containing messages, enums, and type prefix\n * @returns Object containing request and response message names\n */\nconst processServiceMethod = (\n method: ServiceMethod,\n context: ServiceGenerationContext,\n): { requestName: string; responseName: string } => {\n const { messages, enums, typePrefix } = context;\n\n const requestName = generateRequestMessageName(method.name, typePrefix);\n const responseName = generateResponseMessageName(method.name, typePrefix);\n\n if (!messages.has(requestName)) {\n const requestSchema = ensureZodObject(method.request);\n const requestFields = traverseSchema({\n schema: requestSchema,\n messages,\n enums,\n typePrefix,\n parentKey: requestName,\n });\n messages.set(requestName, requestFields);\n }\n\n if (!messages.has(responseName)) {\n const responseSchema = ensureZodObject(method.response);\n const responseFields = traverseSchema({\n schema: responseSchema,\n messages,\n enums,\n typePrefix,\n parentKey: responseName,\n });\n messages.set(responseName, responseFields);\n }\n\n return { requestName, responseName };\n};\n\n/**\n * Generates protobuf service definitions from Zod service schemas.\n * Supports streaming methods (client, server, bidirectional).\n *\n * @param services - Service definitions as array or object with Zod schemas\n * @param context - Generation context containing messages, enums, and type prefix\n * @returns Array of protobuf service definition strings\n */\nexport const generateServices = (\n services: ServicesInput,\n context: ServiceGenerationContext,\n): string[] => {\n const normalizedServices = normalizeServices(services);\n\n return normalizedServices.map((service) => {\n const methods = service.methods.map((method) => {\n const { requestName, responseName } = processServiceMethod(\n method,\n context,\n );\n\n const requestStreaming =\n method.streaming === \"client\" || method.streaming === \"bidirectional\";\n const responseStreaming =\n method.streaming === \"server\" || method.streaming === \"bidirectional\";\n\n const requestType = requestStreaming\n ? `stream ${requestName}`\n : requestName;\n const responseType = responseStreaming\n ? `stream ${responseName}`\n : responseName;\n\n return ` rpc ${toPascalCase({ value: method.name })}(${requestType}) returns (${responseType});`;\n });\n\n return `service ${toPascalCase({ value: service.name })} {\\n${methods.join(\"\\n\")}\\n}`;\n });\n};\n","import type { ZodTypeAny } from \"zod\";\nimport type { ZodToProtobufOptions } from \"./types\";\nimport { traverseSchema } from \"./traversers\";\nimport { generateServices } from \"./service-generator\";\nimport { z } from \"zod\";\n\n/**\n * Converts a Zod schema to a protobuf definition string.\n * Generates messages, enums, and services based on the provided schema and options.\n *\n * @param schema - Optional Zod schema to convert (if not provided, only services will be generated)\n * @param options - Options for protobuf generation including package name, root message name, type prefix, and services\n * @returns Complete protobuf definition string\n */\nexport const zodToProtobufService = (\n options: ZodToProtobufOptions = {},\n): string => {\n const {\n packageName = \"default\",\n typePrefix = \"\",\n services,\n } = options;\n\n const messages = new Map<string, string[]>();\n const enums = new Map<string, string[]>();\n\n const context = {\n messages,\n enums,\n typePrefix: typePrefix || null,\n };\n\n const hasServices =\n services &&\n (Array.isArray(services)\n ? services.length > 0\n : Object.keys(services).length > 0);\n\n const servicesString = hasServices ? generateServices(services, context) : [];\n\n const enumsString = Array.from(enums.values()).map((enumDef) =>\n enumDef.join(\"\\n\"),\n );\n\n const messagesString = Array.from(messages.entries()).map(\n ([name, fields]) =>\n `message ${name} {\\n${fields.map((field) => ` ${field}`).join(\"\\n\")}\\n}`,\n );\n\n const content = [servicesString, enumsString, messagesString]\n .filter((strings) => !!strings.length)\n .map((strings) => strings.join(\"\\n\\n\"))\n .join(\"\\n\\n\");\n\n let protoDefinition: string = \"\";\n if (options.warningDeclaration !== false) {\n protoDefinition += `\n/**\n * This file was automatically generated by zod-to-proto.\n * DO NOT MODIFY IT BY HAND. Instead, modify the source Zod schema.\n */\n`;\n }\n\n protoDefinition += `\nsyntax = \"proto3\";\npackage ${packageName};\n\n${content}\n`;\n\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.ts","../src/traversers.ts","../src/service-generator.ts","../src/zod-to-protobuf.ts"],"sourcesContent":["import { ZodNumber } from \"zod\";\nimport type { ProtobufField } from \"./types\";\n\n/**\n * Determines the protobuf number type name based on Zod number schema.\n * Returns \"int32\" for integers, \"double\" for floating point numbers.\n *\n * @param value - Zod number schema\n * @returns Protobuf number type name (\"int32\" or \"double\")\n */\nexport const getNumberTypeName = ({ value }: { value: ZodNumber }): string => {\n return ['float32', 'float64'].includes(value.format ?? '') ? \"double\" : \"int32\";\n};\n\n/**\n * Converts a string to PascalCase format.\n * Handles dot-separated strings by capitalizing each part.\n *\n * @param value - String to convert\n * @returns PascalCase string\n */\nexport const toPascalCase = ({ value }: { value: string }): string => {\n return value\n .split(\".\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\"\");\n};\n\n/**\n * Converts a protobuf field definition to its type string representation.\n * Filters out null/empty values and joins the remaining types.\n *\n * @param field - Protobuf field definition\n * @returns Type string for the protobuf field\n */\nexport const protobufFieldToType = ({\n field,\n}: {\n field: ProtobufField;\n}): string => {\n return field.types.filter(Boolean).join(\" \");\n};\n","import * as inflection from \"inflection\";\nimport {\n ZodArray,\n ZodBigInt,\n ZodBoolean,\n ZodDate,\n ZodEnum,\n ZodMap,\n ZodNullable,\n ZodNumber,\n ZodObject,\n ZodOptional,\n ZodRecord,\n ZodSet,\n ZodString,\n ZodTuple,\n ZodType,\n type ZodTypeAny,\n} from \"zod\";\nimport {\n ZodArrayDefinition,\n ZodMapDefinition,\n ZodRecordDefinition,\n type ProtobufField,\n} from \"./types\";\nimport { getNumberTypeName, toPascalCase, protobufFieldToType } from \"./utils\";\n\n/**\n * Traverses a Zod array or set schema and converts it to protobuf repeated fields.\n * Handles nested types and generates appropriate field definitions.\n *\n * @param key - Field name\n * @param value - Zod array or set schema\n * @param messages - Map of message names to their protobuf fields\n * @param enums - Map of enum names to their protobuf values\n * @param typePrefix - Optional prefix for type names\n * @param parentKey - Optional parent message name for nested types\n * @returns Array of protobuf field definitions\n */\nexport const traverseArray = ({\n key,\n value,\n messages,\n enums,\n typePrefix,\n parentKey,\n}: {\n key: string;\n value: ZodArray<ZodTypeAny> | ZodSet<ZodTypeAny>;\n messages: Map<string, string[]>;\n enums: Map<string, string[]>;\n typePrefix: string | null;\n parentKey?: string;\n}): ProtobufField[] => {\n const nestedValue =\n value instanceof ZodArray\n ? value.element\n : value instanceof ZodSet\n ? (value.def as unknown as ZodArrayDefinition).valueType\n : // @ts-expect-error\n (value.def as unknown as ZodArrayDefinition).element;\n\n const singularKey = inflection.singularize(key);\n const elementFields = traverseKey({\n key: singularKey,\n value: nestedValue,\n messages,\n enums,\n isOptional: false,\n isInArray: true,\n typePrefix,\n parentKey: nestedValue instanceof ZodObject ? parentKey : undefined,\n });\n return elementFields.map((field) => ({\n ...field,\n types: [\"repeated\", ...field.types],\n name: field.name.replace(singularKey, key),\n }));\n};\n\n/**\n * Traverses a Zod map schema and converts it to a protobuf map type.\n * Validates that both key and value types are simple types suitable for map keys/values.\n *\n * @param key - Field name\n * @param value - Zod map schema\n * @param messages - Map of message names to their protobuf fields\n * @param enums - Map of enum names to their protobuf values\n * @param typePrefix - Optional prefix for type names\n * @param parentKey - Optional parent message name for nested types\n * @returns Array containing a single protobuf map field definition, or empty array if invalid\n */\nexport const traverseMap = ({\n key,\n value,\n messages,\n enums,\n typePrefix,\n parentKey,\n}: {\n key: string;\n value: ZodMap<ZodTypeAny, ZodTypeAny>;\n messages: Map<string, string[]>;\n enums: Map<string, string[]>;\n typePrefix: string | null;\n parentKey?: string;\n}): ProtobufField[] => {\n const mapDef = value.def as ZodMapDefinition;\n\n const keyType = traverseKey({\n key: inflection.singularize(key),\n value: mapDef.keyType,\n messages,\n enums,\n isOptional: false,\n isInArray: true,\n typePrefix,\n parentKey,\n });\n const valueType = traverseKey({\n key: inflection.singularize(key),\n value: mapDef.valueType,\n messages,\n enums,\n isOptional: false,\n isInArray: true,\n typePrefix,\n parentKey,\n });\n\n if (!keyType[0] || keyType.length !== 1) {\n return [];\n }\n\n if (!valueType[0] || valueType.length !== 1) {\n return [];\n }\n\n const mapType = `map<${protobufFieldToType({ field: keyType[0] })}, ${protobufFieldToType({ field: valueType[0] })}>`;\n return [\n {\n types: [mapType],\n name: key,\n },\n ];\n};\n\n/**\n * Traverses a Zod record schema and converts it to a protobuf map type.\n * Similar to traverseMap but handles ZodRecord type.\n *\n * @param key - Field name\n * @param value - Zod record schema\n * @param messages - Map of message names to their protobuf fields\n * @param enums - Map of enum names to their protobuf values\n * @param typePrefix - Optional prefix for type names\n * @param parentKey - Optional parent message name for nested types\n * @returns Array containing a single protobuf map field definition, or empty array if invalid\n */\nexport const traverseRecord = ({\n key,\n value,\n messages,\n enums,\n typePrefix,\n parentKey,\n}: {\n key: string;\n value: ZodRecord;\n messages: Map<string, string[]>;\n enums: Map<string, string[]>;\n typePrefix: string | null;\n parentKey?: string;\n}): ProtobufField[] => {\n const recordDef = value.def as unknown as ZodRecordDefinition;\n\n const keyType = traverseKey({\n key: inflection.singularize(key),\n value: recordDef.keyType,\n messages,\n enums,\n isOptional: false,\n isInArray: true,\n typePrefix,\n parentKey,\n });\n const valueType = traverseKey({\n key: inflection.singularize(key),\n value: recordDef.valueType,\n messages,\n enums,\n isOptional: false,\n isInArray: true,\n typePrefix,\n parentKey,\n });\n\n if (!keyType[0] || keyType.length !== 1) {\n return [];\n }\n\n if (!valueType[0] || valueType.length !== 1) {\n return [];\n }\n\n const mapType = `map<${protobufFieldToType({ field: keyType[0] })}, ${protobufFieldToType({ field: valueType[0] })}>`;\n return [\n {\n types: [mapType],\n name: key,\n },\n ];\n};\n\n/**\n * Traverses a single key-value pair from a Zod schema and converts it to protobuf field definitions.\n * Handles various Zod types including primitives, objects, arrays, maps, enums, tuples, and optional/nullable fields.\n *\n * @param key - Field name\n * @param value - Zod schema value\n * @param messages - Map of message names to their protobuf fields\n * @param enums - Map of enum names to their protobuf values\n * @param isOptional - Whether the field is optional\n * @param isInArray - Whether the field is inside an array\n * @param typePrefix - Optional prefix for type names\n * @param parentKey - Optional parent message name for nested types\n * @returns Array of protobuf field definitions\n */\nexport const traverseKey = ({\n key,\n value,\n messages,\n enums,\n isOptional,\n isInArray,\n typePrefix,\n parentKey,\n}: {\n key: string;\n value: unknown;\n messages: Map<string, string[]>;\n enums: Map<string, string[]>;\n isOptional: boolean;\n isInArray: boolean;\n typePrefix: string | null;\n parentKey?: string;\n}): ProtobufField[] => {\n if (!value) {\n return [];\n }\n\n if (value instanceof ZodOptional || value instanceof ZodNullable) {\n return traverseKey({\n key,\n value: value.unwrap(),\n messages,\n enums,\n isOptional: true,\n isInArray,\n typePrefix,\n parentKey,\n });\n }\n\n if (value instanceof ZodArray || value instanceof ZodSet) {\n return traverseArray({\n key,\n value: value as ZodArray<ZodTypeAny> | ZodSet<ZodTypeAny>,\n messages,\n enums,\n typePrefix,\n parentKey,\n });\n }\n\n if (value instanceof ZodMap) {\n return traverseMap({\n key,\n value: value as ZodMap<ZodTypeAny, ZodTypeAny>,\n messages,\n enums,\n typePrefix,\n parentKey,\n });\n }\n\n if (value instanceof ZodRecord) {\n return traverseRecord({\n key,\n value: value as ZodRecord,\n messages,\n enums,\n typePrefix,\n parentKey,\n });\n }\n\n const optional = isOptional && !isInArray ? \"optional\" : null;\n\n if (value instanceof ZodObject) {\n let messageName = toPascalCase({ value: key });\n if (parentKey) {\n const isParentAlreadyPascalCase = /^[A-Z][a-zA-Z0-9]*$/.test(parentKey);\n if (isParentAlreadyPascalCase) {\n messageName = `${parentKey}${messageName}`;\n } else {\n const parentMessageName = toPascalCase({ value: parentKey });\n messageName = `${parentMessageName}${messageName}`;\n }\n }\n if (typePrefix) {\n messageName = `${typePrefix}${messageName}`;\n }\n const nestedMessageFields = traverseSchema({\n schema: value,\n messages,\n enums,\n typePrefix,\n parentKey: messageName,\n });\n messages.set(messageName, nestedMessageFields);\n return [\n {\n types: [optional, messageName],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodString) {\n return [\n {\n types: [optional, \"string\"],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodNumber) {\n const typeName = getNumberTypeName({ value });\n return [\n {\n types: [optional, typeName],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodBoolean) {\n return [\n {\n types: [optional, \"bool\"],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodEnum) {\n const enumFields = value.options\n .map(\n (option: string | number, index: number) =>\n ` ${String(option)} = ${index};`,\n )\n .join(\"\\n\");\n let enumName = toPascalCase({ value: key });\n if (parentKey) {\n const isParentAlreadyPascalCase = /^[A-Z][a-zA-Z0-9]*$/.test(parentKey);\n if (isParentAlreadyPascalCase) {\n enumName = `${parentKey}${enumName}`;\n } else {\n const parentMessageName = toPascalCase({ value: parentKey });\n enumName = `${parentMessageName}${enumName}`;\n }\n }\n if (typePrefix) {\n enumName = `${typePrefix}${enumName}`;\n }\n enums.set(enumName, [`enum ${enumName} {\\n${enumFields}\\n}`]);\n return [\n {\n types: [optional, enumName],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodDate) {\n return [\n {\n types: [optional, \"string\"],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodBigInt) {\n return [\n {\n types: [optional, \"int64\"],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodType) {\n const def = value.def as {\n type?: string;\n check?: unknown;\n fn?: (data: unknown) => boolean;\n };\n if (def.type === \"custom\" && def.check === \"custom\" && def.fn) {\n try {\n if (\n (typeof Buffer !== \"undefined\" && def.fn(Buffer.alloc(0))) ||\n (typeof Uint8Array !== \"undefined\" && def.fn(new Uint8Array(0)))\n ) {\n return [\n {\n types: [optional, \"bytes\"],\n name: key,\n },\n ];\n }\n } catch {}\n }\n }\n\n if (value instanceof ZodTuple) {\n const tupleFields: ProtobufField[] = (\n value.def.items as ZodTypeAny[]\n ).flatMap((item: ZodTypeAny, index: number) => {\n return traverseKey({\n key: `${key}_${index}`,\n value: item,\n messages,\n enums,\n isOptional: false,\n isInArray,\n typePrefix,\n parentKey,\n });\n });\n\n let tupleMessageName = toPascalCase({ value: key });\n if (parentKey) {\n const isParentAlreadyPascalCase = /^[A-Z][a-zA-Z0-9]*$/.test(parentKey);\n if (isParentAlreadyPascalCase) {\n tupleMessageName = `${parentKey}${tupleMessageName}`;\n } else {\n const parentMessageName = toPascalCase({ value: parentKey });\n tupleMessageName = `${parentMessageName}${tupleMessageName}`;\n }\n }\n if (typePrefix) {\n tupleMessageName = `${typePrefix}${tupleMessageName}`;\n }\n messages.set(\n tupleMessageName,\n tupleFields.map(\n (field, index) =>\n ` ${field.types.join(\" \")} ${field.name} = ${index + 1};`,\n ),\n );\n return [\n {\n types: [optional, tupleMessageName],\n name: key,\n },\n ];\n }\n\n if (value instanceof ZodType) {\n return [];\n }\n\n return [];\n};\n\n/**\n * Traverses a Zod object schema and converts it to protobuf message field definitions.\n * Processes all fields in the schema and generates appropriate protobuf types.\n *\n * @param schema - Zod schema to traverse\n * @param messages - Map of message names to their protobuf fields\n * @param enums - Map of enum names to their protobuf values\n * @param typePrefix - Optional prefix for type names\n * @param parentKey - Optional parent message name for nested types\n * @returns Array of protobuf field definition strings\n */\nexport const traverseSchema = ({\n schema,\n messages,\n enums,\n typePrefix,\n parentKey,\n}: {\n schema: ZodTypeAny;\n messages: Map<string, string[]>;\n enums: Map<string, string[]>;\n typePrefix: string | null;\n parentKey?: string;\n}): string[] => {\n if (\n !schema ||\n typeof schema !== \"object\" ||\n !(\"def\" in schema) ||\n (schema.constructor.name !== \"ZodObject\" &&\n (schema.def as { type?: string }).type !== \"object\")\n ) {\n return [];\n }\n\n const zodObject = schema as ZodObject<any>;\n const fields = Object.entries(zodObject.shape).flatMap(([key, value]) => {\n return traverseKey({\n key,\n value,\n messages,\n enums,\n isOptional: false,\n isInArray: false,\n typePrefix,\n parentKey,\n });\n });\n\n return fields.map(\n (field, index) =>\n `${protobufFieldToType({ field })} ${field.name} = ${index + 1};`,\n );\n};\n","import { z, ZodObject, type ZodTypeAny } from \"zod\";\nimport type {\n ServiceDefinition,\n ServiceMethod,\n ServicesInput,\n ZodFunctionDefinition,\n ZodTupleDefinition,\n} from \"./types\";\nimport { toPascalCase } from \"./utils\";\nimport { traverseSchema } from \"./traversers\";\n\n/**\n * Context for generating protobuf services.\n * Contains accumulated messages, enums, and type prefix.\n */\ninterface ServiceGenerationContext {\n /** Map of message names to their protobuf fields */\n messages: Map<string, string[]>;\n /** Map of enum names to their protobuf values */\n enums: Map<string, string[]>;\n /** Prefix for type names or null if prefix is not used */\n typePrefix: string | null;\n}\n\n/**\n * Parses a Zod service schema and extracts method definitions.\n * Each method must be a function with one argument (request) and a return value (response).\n *\n * @param name - Service name\n * @param schema - Zod object containing service methods as functions\n * @returns Service definition with extracted methods\n */\nconst parseZodServiceSchema = (\n name: string,\n schema: ZodObject<Record<string, ZodTypeAny>>,\n): ServiceDefinition => {\n const shape = schema.shape as Record<string, ZodTypeAny>;\n const methods: ServiceMethod[] = [];\n\n for (const [methodName, methodSchema] of Object.entries(shape)) {\n const methodDef = (methodSchema as ZodTypeAny).def as ZodFunctionDefinition;\n\n if (methodDef.type === \"function\") {\n const inputDef = methodDef.input;\n\n const args = (inputDef?.def as ZodTupleDefinition)?.items ?? [];\n const output = methodDef.output as ZodTypeAny;\n\n if (args.length > 0 && args[0] && output) {\n const request = args[0];\n const response = output;\n\n let streaming: \"client\" | \"server\" | \"bidirectional\" | undefined;\n const metadata = methodSchema.meta();\n streaming = metadata?.streaming as\n | \"client\"\n | \"server\"\n | \"bidirectional\"\n | undefined;\n\n methods.push({\n name: methodName,\n request,\n response,\n streaming,\n });\n }\n }\n }\n\n return {\n name,\n methods,\n };\n};\n\n/**\n * Normalizes service input data into an array of service definitions.\n * If an array is passed, returns it as is.\n * If an object is passed, converts each key-value pair into a service definition.\n *\n * @param services - Array of service definitions or object with Zod schemas\n * @returns Array of normalized service definitions\n */\nconst normalizeServices = (services: ServicesInput): ServiceDefinition[] => {\n if (Array.isArray(services)) {\n return services;\n }\n\n return Object.entries(services).map(([name, schema]) =>\n parseZodServiceSchema(name, schema),\n );\n};\n\n/**\n * Ensures that the schema is a ZodObject.\n * If the schema is already an object, returns it as is.\n * Otherwise, wraps the schema in an object with a \"data\" field.\n *\n * @param schema - Zod schema of any type\n * @returns ZodObject containing the original schema\n */\nconst ensureZodObject = (\n schema: ZodTypeAny,\n): ZodObject<Record<string, ZodTypeAny>> => {\n const schemaType =\n (schema.def as { type?: string }).type || schema.constructor.name;\n\n if (schemaType === \"object\" || schema.constructor.name === \"ZodObject\") {\n return schema as ZodObject<Record<string, ZodTypeAny>>;\n }\n\n return z.object({\n data: schema,\n });\n};\n\n/**\n * Generates the name for a request message based on the method name.\n *\n * @param methodName - Name of the service method\n * @param typePrefix - Optional prefix for type names\n * @returns Generated request message name in PascalCase\n */\nconst generateRequestMessageName = (\n methodName: string,\n typePrefix: string | null,\n): string => {\n const messageName = toPascalCase({ value: `${methodName}Request` });\n return typePrefix ? `${typePrefix}${messageName}` : messageName;\n};\n\n/**\n * Generates the name for a response message based on the method name.\n *\n * @param methodName - Name of the service method\n * @param typePrefix - Optional prefix for type names\n * @returns Generated response message name in PascalCase\n */\nconst generateResponseMessageName = (\n methodName: string,\n typePrefix: string | null,\n): string => {\n const messageName = toPascalCase({ value: `${methodName}Response` });\n return typePrefix ? `${typePrefix}${messageName}` : messageName;\n};\n\n/**\n * Processes a service method by generating request and response message names\n * and traversing their schemas to populate the context with message definitions.\n *\n * @param method - Service method definition\n * @param context - Generation context containing messages, enums, and type prefix\n * @returns Object containing request and response message names\n */\nconst processServiceMethod = (\n method: ServiceMethod,\n context: ServiceGenerationContext,\n): { requestName: string; responseName: string } => {\n const { messages, enums, typePrefix } = context;\n\n const requestName = generateRequestMessageName(method.name, typePrefix);\n const responseName = generateResponseMessageName(method.name, typePrefix);\n\n if (!messages.has(requestName)) {\n const requestSchema = ensureZodObject(method.request);\n const requestFields = traverseSchema({\n schema: requestSchema,\n messages,\n enums,\n typePrefix,\n parentKey: requestName,\n });\n messages.set(requestName, requestFields);\n }\n\n if (!messages.has(responseName)) {\n const responseSchema = ensureZodObject(method.response);\n const responseFields = traverseSchema({\n schema: responseSchema,\n messages,\n enums,\n typePrefix,\n parentKey: responseName,\n });\n messages.set(responseName, responseFields);\n }\n\n return { requestName, responseName };\n};\n\n/**\n * Generates protobuf service definitions from Zod service schemas.\n * Supports streaming methods (client, server, bidirectional).\n *\n * @param services - Service definitions as array or object with Zod schemas\n * @param context - Generation context containing messages, enums, and type prefix\n * @returns Array of protobuf service definition strings\n */\nexport const generateServices = (\n services: ServicesInput,\n context: ServiceGenerationContext,\n): string[] => {\n const normalizedServices = normalizeServices(services);\n\n return normalizedServices.map((service) => {\n const methods = service.methods.map((method) => {\n const { requestName, responseName } = processServiceMethod(\n method,\n context,\n );\n\n const requestStreaming =\n method.streaming === \"client\" || method.streaming === \"bidirectional\";\n const responseStreaming =\n method.streaming === \"server\" || method.streaming === \"bidirectional\";\n\n const requestType = requestStreaming\n ? `stream ${requestName}`\n : requestName;\n const responseType = responseStreaming\n ? `stream ${responseName}`\n : responseName;\n\n return ` rpc ${toPascalCase({ value: method.name })}(${requestType}) returns (${responseType});`;\n });\n\n return `service ${toPascalCase({ value: service.name })} {\\n${methods.join(\"\\n\")}\\n}`;\n });\n};\n","import type { ZodTypeAny } from \"zod\";\nimport type { ZodToProtobufOptions } from \"./types\";\nimport { traverseSchema } from \"./traversers\";\nimport { generateServices } from \"./service-generator\";\nimport { z } from \"zod\";\n\n/**\n * Converts a Zod schema to a protobuf definition string.\n * Generates messages, enums, and services based on the provided schema and options.\n *\n * @param schema - Optional Zod schema to convert (if not provided, only services will be generated)\n * @param options - Options for protobuf generation including package name, root message name, type prefix, and services\n * @returns Complete protobuf definition string\n */\nexport const zodToProtobufService = (\n options: ZodToProtobufOptions = {},\n): string => {\n const {\n packageName = \"default\",\n typePrefix = \"\",\n services,\n } = options;\n\n const messages = new Map<string, string[]>();\n const enums = new Map<string, string[]>();\n\n const context = {\n messages,\n enums,\n typePrefix: typePrefix || null,\n };\n\n const hasServices =\n services &&\n (Array.isArray(services)\n ? services.length > 0\n : Object.keys(services).length > 0);\n\n const servicesString = hasServices ? generateServices(services, context) : [];\n\n const enumsString = Array.from(enums.values()).map((enumDef) =>\n enumDef.join(\"\\n\"),\n );\n\n const messagesString = Array.from(messages.entries()).map(\n ([name, fields]) =>\n `message ${name} {\\n${fields.map((field) => ` ${field}`).join(\"\\n\")}\\n}`,\n );\n\n const content = [servicesString, enumsString, messagesString]\n .filter((strings) => !!strings.length)\n .map((strings) => strings.join(\"\\n\\n\"))\n .join(\"\\n\\n\");\n\n let protoDefinition: string = \"\";\n if (options.warningDeclaration !== false) {\n protoDefinition += `\n/**\n * This file was automatically generated by zod-to-proto.\n * DO NOT MODIFY IT BY HAND. Instead, modify the source Zod schema.\n */\n`;\n }\n\n protoDefinition += `\nsyntax = \"proto3\";\npackage ${packageName};\n\n${content}\n`;\n\n return protoDefinition.trim();\n};\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,qBAAqB,EAAE,YAA0C;AAC5E,QAAO,CAAC,WAAW,UAAU,CAAC,SAAS,MAAM,UAAU,GAAG,GAAG,WAAW;;;;;;;;;AAU1E,MAAa,gBAAgB,EAAE,YAAuC;AACpE,QAAO,MACJ,MAAM,IAAI,CACV,KAAK,SAAS,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE,CAAC,CAC3D,KAAK,GAAG;;;;;;;;;AAUb,MAAa,uBAAuB,EAClC,YAGY;AACZ,QAAO,MAAM,MAAM,OAAO,QAAQ,CAAC,KAAK,IAAI;;;;;;;;;;;;;;;;;ACD9C,MAAa,iBAAiB,EAC5B,KACA,OACA,UACA,OACA,YACA,gBAQqB;CACrB,MAAM,cACJ,iBAAiB,WACb,MAAM,UACN,iBAAiB,SACd,MAAM,IAAsC,YAE5C,MAAM,IAAsC;CAErD,MAAM,cAAc,WAAW,YAAY,IAAI;AAW/C,QAVsB,YAAY;EAChC,KAAK;EACL,OAAO;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O,KAAK,SAAS,CAAC,SAAS,KAEA,iBAAiB,UAAU,QAAQ,GAAG,EAAE;EAEzD,MAAM,KAAK,MAAM,QAAQ,CAAC,CAAC,KAAK,YAClD,QAAQ,KAAK,KAAK,CACnB;EAEsB,MAAM,KAAK,SAAS,SAAS,CAAC,CAAC,KACnD,CAAC,MAAM,YACN,WAAW,KAAK,MAAM,OAAO,KAAK,UAAU,OAAO,QAAQ,CAAC,KAAK,KAAK,CAAC,KAC1E;EAE4D,CAC1D,QAAQ,YAAY,CAAC,CAAC,QAAQ,OAAO,CACrC,KAAK,YAAY,QAAQ,KAAK,OAAO,CAAC,CACtC,KAAK,OAAO;CAEf,IAAI,kBAA0B;AAC9B,KAAI,QAAQ,uBAAuB,MACjC,oBAAmB;;;;;;AAQrB,oBAAmB;;UAEX,YAAY;;EAEpB,QAAQ;;AAGR,QAAO,gBAAgB,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@globalart/zod-to-proto",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "GlobalArt, Inc"
|
|
6
6
|
},
|
|
@@ -38,18 +38,18 @@
|
|
|
38
38
|
},
|
|
39
39
|
"description": "Convert Zod schemas to Protobuf definitions",
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@types/express": "
|
|
42
|
-
"@types/node": "
|
|
41
|
+
"@types/express": "5.0.6",
|
|
42
|
+
"@types/node": "25.0.3",
|
|
43
43
|
"@types/passport": "^1.0.17",
|
|
44
|
-
"prettier": "
|
|
45
|
-
"release-it": "19.
|
|
44
|
+
"prettier": "3.7.4",
|
|
45
|
+
"release-it": "19.2.3",
|
|
46
46
|
"ts-node": "^10.9.2",
|
|
47
|
-
"tsdown": "0.
|
|
47
|
+
"tsdown": "0.19.0-beta.3",
|
|
48
48
|
"typescript": "^5.9.3"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"inflection": "3.0.2",
|
|
52
|
-
"zod": "4.
|
|
52
|
+
"zod": "4.3.5"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|