zodvex 0.7.7-beta.1 → 0.7.7

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.
Files changed (49) hide show
  1. package/dist/cli/index.js +296 -81
  2. package/dist/cli/index.js.map +1 -1
  3. package/dist/client/index.js +2 -2
  4. package/dist/client/index.js.map +1 -1
  5. package/dist/codegen/index.js +211 -28
  6. package/dist/codegen/index.js.map +1 -1
  7. package/dist/core/index.js +33 -16
  8. package/dist/core/index.js.map +1 -1
  9. package/dist/index.js +33 -16
  10. package/dist/index.js.map +1 -1
  11. package/dist/internal/boundaryHelpers.d.ts +2 -15
  12. package/dist/internal/boundaryHelpers.d.ts.map +1 -1
  13. package/dist/internal/registry.d.ts.map +1 -1
  14. package/dist/internal/zx.d.ts.map +1 -1
  15. package/dist/internal/zxDateBrand.d.ts +5 -0
  16. package/dist/internal/zxDateBrand.d.ts.map +1 -0
  17. package/dist/legacy/index.js +21 -10
  18. package/dist/legacy/index.js.map +1 -1
  19. package/dist/mini/client/index.js +2 -2
  20. package/dist/mini/client/index.js.map +1 -1
  21. package/dist/mini/index.js +33 -16
  22. package/dist/mini/index.js.map +1 -1
  23. package/dist/mini/react/index.js +2 -2
  24. package/dist/mini/react/index.js.map +1 -1
  25. package/dist/mini/server/index.js +23 -12
  26. package/dist/mini/server/index.js.map +1 -1
  27. package/dist/public/cli/commands.d.ts.map +1 -1
  28. package/dist/public/codegen/discover.d.ts.map +1 -1
  29. package/dist/public/codegen/discovery-hooks.d.ts +2 -1
  30. package/dist/public/codegen/discovery-hooks.d.ts.map +1 -1
  31. package/dist/public/codegen/extractCodec.d.ts.map +1 -1
  32. package/dist/public/codegen/tsconfigPaths.d.ts +41 -0
  33. package/dist/public/codegen/tsconfigPaths.d.ts.map +1 -0
  34. package/dist/public/codegen/zodToSource.d.ts.map +1 -1
  35. package/dist/react/index.js +2 -2
  36. package/dist/react/index.js.map +1 -1
  37. package/dist/server/index.js +23 -12
  38. package/dist/server/index.js.map +1 -1
  39. package/package.json +1 -1
  40. package/src/internal/boundaryHelpers.ts +15 -3
  41. package/src/internal/registry.ts +12 -9
  42. package/src/internal/zx.ts +12 -9
  43. package/src/internal/zxDateBrand.ts +34 -0
  44. package/src/public/cli/commands.ts +59 -17
  45. package/src/public/codegen/discover.ts +27 -15
  46. package/src/public/codegen/discovery-hooks.ts +42 -3
  47. package/src/public/codegen/extractCodec.ts +5 -11
  48. package/src/public/codegen/tsconfigPaths.ts +224 -0
  49. package/src/public/codegen/zodToSource.ts +5 -6
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { $ZodError, encode, $ZodObject, $ZodType, globalRegistry, $ZodDate, $ZodCodec, $ZodNumber, $ZodCustom, $ZodOptional, $ZodNullable, $ZodDefault, parse, clone, safeParse, $ZodArray, $ZodLazy, $ZodTuple, $ZodRecord, $ZodEnum, $ZodLiteral, $ZodUnion, $ZodDiscriminatedUnion } from 'zod/v4/core';
1
+ import { $ZodError, encode, $ZodObject, $ZodType, globalRegistry, $ZodDate, $ZodCodec, $ZodOptional, $ZodNullable, $ZodDefault, parse, clone, safeParse, $ZodArray, $ZodLazy, $ZodTuple, $ZodRecord, $ZodEnum, $ZodLiteral, $ZodUnion, $ZodDiscriminatedUnion } from 'zod/v4/core';
2
2
  import { z } from 'zod';
3
3
  import { v } from 'convex/values';
4
4
 
@@ -101,9 +101,9 @@ var ZodvexDecodeError = class extends $ZodError {
101
101
  this.name = "ZodvexDecodeError";
102
102
  }
103
103
  };
104
+ var warnedPaths = /* @__PURE__ */ new Set();
104
105
  function createBoundaryHelpers(registry, options) {
105
106
  const onDecodeError = options?.onDecodeError ?? "warn";
106
- const warnedPaths = /* @__PURE__ */ new Set();
107
107
  function encodeArgs(ref, args) {
108
108
  if (args == null) return args;
109
109
  const path = resolveFunctionPath(ref);
@@ -113,7 +113,7 @@ function createBoundaryHelpers(registry, options) {
113
113
  if (entry === void 0 && !warnedPaths.has(path)) {
114
114
  warnedPaths.add(path);
115
115
  console.debug(
116
- `[zodvex] No registry entry for "${path}" \u2014 args will not be codec-encoded. If this function uses zodvex wrappers, run \`zodvex generate\` to update the registry.`
116
+ `[zodvex] No registry entry for "${path}" \u2014 args/returns pass through unencoded. This is expected when the target is a raw (non-zodvex) function; if it should be codec-aware, run \`zodvex generate\` to update the registry.`
117
117
  );
118
118
  }
119
119
  return args;
@@ -581,6 +581,22 @@ function zodToConvexFields(zod) {
581
581
  }
582
582
  return result;
583
583
  }
584
+
585
+ // src/internal/zxDateBrand.ts
586
+ var ZX_DATE_BRAND = /* @__PURE__ */ Symbol.for("zodvex.zxDate");
587
+ function brandZxDate(codec2) {
588
+ codec2[ZX_DATE_BRAND] = true;
589
+ const def = codec2._zod?.def;
590
+ if (def) def[ZX_DATE_BRAND] = true;
591
+ return codec2;
592
+ }
593
+ function isZxDateCodec(schema) {
594
+ if (!schema || typeof schema !== "object") return false;
595
+ const s = schema;
596
+ return s[ZX_DATE_BRAND] === true || s._zod?.def?.[ZX_DATE_BRAND] === true;
597
+ }
598
+
599
+ // src/internal/registry.ts
584
600
  function isZidSchema(schema) {
585
601
  const description = globalRegistry.get(schema)?.description;
586
602
  return typeof description === "string" && description.startsWith("convexId:");
@@ -611,7 +627,7 @@ function zodvexJSONSchemaOverride(ctx) {
611
627
  jsonSchema.format = "date-time";
612
628
  return;
613
629
  }
614
- if (zodSchema instanceof $ZodCodec && zodSchema._zod.def.in instanceof $ZodNumber && zodSchema._zod.def.out instanceof $ZodCustom) {
630
+ if (isZxDateCodec(zodSchema)) {
615
631
  jsonSchema.type = "string";
616
632
  jsonSchema.format = "date-time";
617
633
  const description = globalRegistry.get(zodSchema)?.description;
@@ -863,8 +879,7 @@ function findCodec(schema) {
863
879
  let current = schema;
864
880
  for (let i = 0; i < 10; i++) {
865
881
  if (current instanceof $ZodCodec) {
866
- const isZxDate = current._zod.def.in instanceof $ZodNumber && current._zod.def.out instanceof $ZodCustom;
867
- if (isZxDate) return void 0;
882
+ if (isZxDateCodec(current)) return void 0;
868
883
  return current;
869
884
  }
870
885
  if (current instanceof $ZodOptional || current instanceof $ZodNullable) {
@@ -897,16 +912,18 @@ function readFnReturns(fn) {
897
912
  return meta.zodReturns;
898
913
  }
899
914
  function date() {
900
- return zodvexCodec(
901
- z.number(),
902
- // Wire: timestamp
903
- z.custom((val) => val instanceof Date, {
904
- message: "Expected Date instance"
905
- }),
906
- {
907
- decode: (timestamp) => new Date(timestamp),
908
- encode: (date2) => date2.getTime()
909
- }
915
+ return brandZxDate(
916
+ zodvexCodec(
917
+ z.number(),
918
+ // Wire: timestamp
919
+ z.custom((val) => val instanceof Date, {
920
+ message: "Expected Date instance"
921
+ }),
922
+ {
923
+ decode: (timestamp) => new Date(timestamp),
924
+ encode: (date2) => date2.getTime()
925
+ }
926
+ )
910
927
  );
911
928
  }
912
929
  function id(tableName) {