zod-v3-to-v4 1.6.1 → 1.7.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.
@@ -272,11 +272,52 @@ function convertNameToTopLevelApiAndWrapInUnion(node, options) {
272
272
  .filter((expression) => names.includes(expression.getName()))
273
273
  .forEach((expression) => {
274
274
  const parent = expression.getFirstAncestorByKind(SyntaxKind.CallExpression);
275
+ if (!parent) {
276
+ return;
277
+ }
275
278
  const text = expression.getExpression().getText();
279
+ // Check if the method call has arguments (e.g., .ip({ version: "v4" }))
280
+ const args = parent.getArguments();
281
+ if (args.length > 0) {
282
+ // Try to extract version from the arguments
283
+ const firstArg = args[0];
284
+ if (firstArg?.isKind(SyntaxKind.ObjectLiteralExpression)) {
285
+ const versionProperty = firstArg.getProperties().find((prop) => {
286
+ if (prop.isKind(SyntaxKind.PropertyAssignment)) {
287
+ const name = prop.getName();
288
+ return name === "version" || name === '"version"';
289
+ }
290
+ return false;
291
+ });
292
+ if (versionProperty?.isKind(SyntaxKind.PropertyAssignment)) {
293
+ const initializer = versionProperty.getInitializer();
294
+ if (initializer?.isKind(SyntaxKind.StringLiteral)) {
295
+ const version = initializer.getLiteralValue();
296
+ if (version === "v4" && nameToWrap === "ip") {
297
+ parent.replaceWithText(`${text}.ipv4()`);
298
+ return;
299
+ }
300
+ else if (version === "v6" && nameToWrap === "ip") {
301
+ parent.replaceWithText(`${text}.ipv6()`);
302
+ return;
303
+ }
304
+ else if (version === "v4" && nameToWrap === "cidr") {
305
+ parent.replaceWithText(`${text}.cidrv4()`);
306
+ return;
307
+ }
308
+ else if (version === "v6" && nameToWrap === "cidr") {
309
+ parent.replaceWithText(`${text}.cidrv6()`);
310
+ return;
311
+ }
312
+ }
313
+ }
314
+ }
315
+ }
316
+ // Default behavior: create union
276
317
  const unionText = renames
277
318
  .map(({ name }) => `${text}.${name}()`)
278
319
  .join(", ");
279
- parent?.replaceWithText(`${zodName}.union([${unionText}])`);
320
+ parent.replaceWithText(`${zodName}.union([${unionText}])`);
280
321
  });
281
322
  convertNameToTopLevelApi(callExpression, {
282
323
  zodName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod-v3-to-v4",
3
- "version": "1.6.1",
3
+ "version": "1.7.0",
4
4
  "description": "Migrate Zod from v3 to v4",
5
5
  "keywords": [
6
6
  "zod",