zodvex 0.7.1-beta.7 → 0.7.1-beta.8

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/cli/index.js CHANGED
@@ -250,9 +250,22 @@ function isNamespaceCall(obj) {
250
250
  function isLikelySchemaExpr(obj) {
251
251
  if (obj.match(/^z\.\w+\(/)) return true;
252
252
  if (obj.match(/^zx\.\w+\(/)) return true;
253
- if (obj.match(/^z\.(optional|nullable)\(/)) return true;
254
253
  return false;
255
254
  }
255
+ function isSchemaVariable(call, varName) {
256
+ const file = call.getSourceFile();
257
+ const varDecls = file.getDescendantsOfKind(SyntaxKind.VariableDeclaration);
258
+ let closestDecl;
259
+ for (const decl of varDecls) {
260
+ if (decl.getName() !== varName) continue;
261
+ if (decl.getStart() >= call.getStart()) continue;
262
+ closestDecl = decl;
263
+ }
264
+ if (!closestDecl) return false;
265
+ const init2 = closestDecl.getInitializer();
266
+ if (!init2) return false;
267
+ return isLikelySchemaExpr(init2.getText());
268
+ }
256
269
  function isZodSchemaByType(call, typeChecker) {
257
270
  const expr = call.getExpression();
258
271
  if (expr.getKind() !== SyntaxKind.PropertyAccessExpression) return false;
@@ -322,6 +335,9 @@ function transformMethods(file, typeChecker) {
322
335
  } else {
323
336
  isSchema = isLikelySchemaExpr(obj);
324
337
  }
338
+ if (!isSchema && isSchemaVariable(call, obj.trim())) {
339
+ isSchema = true;
340
+ }
325
341
  if (!isSchema) continue;
326
342
  const argsStr = args.length > 0 ? `, ${args.join(", ")}` : "";
327
343
  call.replaceWithText(`z.${method}(${obj}${argsStr})`);
@@ -508,6 +524,38 @@ function transformClassRefs(file) {
508
524
  count++;
509
525
  }
510
526
  }
527
+ const importTypes = file.getDescendantsOfKind(SyntaxKind.ImportType);
528
+ for (const itn of importTypes) {
529
+ if (itn.wasForgotten()) continue;
530
+ const arg = itn.getArgument();
531
+ if (!arg) continue;
532
+ const argText = arg.getText();
533
+ const moduleSpec = argText.replace(/^['"]|['"]$/g, "");
534
+ if (moduleSpec !== "zod" && moduleSpec !== "zodvex/core") continue;
535
+ const qualifier = itn.getQualifier();
536
+ if (!qualifier) continue;
537
+ const qualText = qualifier.getText();
538
+ const miniKey = `z.${qualText}`;
539
+ const miniReplacement = MINI_CLASS_RENAMES[miniKey];
540
+ if (miniReplacement) {
541
+ const newQualifier = miniReplacement.replace("z.", "");
542
+ const typeArgs = itn.getTypeArguments();
543
+ const typeArgsStr = typeArgs.length > 0 ? `<${typeArgs.map((a) => a.getText()).join(", ")}>` : "";
544
+ itn.replaceWithText(`import('zod/mini').${newQualifier}${typeArgsStr}`);
545
+ count++;
546
+ continue;
547
+ }
548
+ const coreReplacement = CORE_CLASS_RENAMES[miniKey];
549
+ if (coreReplacement) {
550
+ const typeArgs = itn.getTypeArguments();
551
+ const typeArgsStr = typeArgs.length > 0 ? `<${typeArgs.map((a) => a.getText()).join(", ")}>` : "";
552
+ itn.replaceWithText(`import('zod/v4/core').${coreReplacement}${typeArgsStr}`);
553
+ count++;
554
+ continue;
555
+ }
556
+ itn.replaceWithText(`import('zod/mini').${qualText}${itn.getTypeArguments().length > 0 ? `<${itn.getTypeArguments().map((a) => a.getText()).join(", ")}>` : ""}`);
557
+ count++;
558
+ }
511
559
  for (const name of runtimeCoreImports) {
512
560
  typeOnlyCoreImports.delete(name);
513
561
  }