@tambo-ai/react 0.66.1 → 0.67.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.
Files changed (159) hide show
  1. package/dist/context-helpers/current-interactables-context-helper.d.ts +2 -2
  2. package/dist/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
  3. package/dist/context-helpers/current-interactables-context-helper.js +17 -23
  4. package/dist/context-helpers/current-interactables-context-helper.js.map +1 -1
  5. package/dist/hoc/with-tambo-interactable.d.ts.map +1 -1
  6. package/dist/hoc/with-tambo-interactable.js +0 -1
  7. package/dist/hoc/with-tambo-interactable.js.map +1 -1
  8. package/dist/hooks/use-component-state.d.ts +16 -1
  9. package/dist/hooks/use-component-state.d.ts.map +1 -1
  10. package/dist/hooks/use-component-state.js +72 -12
  11. package/dist/hooks/use-component-state.js.map +1 -1
  12. package/dist/hooks/use-component-state.test.js +42 -0
  13. package/dist/hooks/use-component-state.test.js.map +1 -1
  14. package/dist/hooks/use-current-message.d.ts +3 -0
  15. package/dist/hooks/use-current-message.d.ts.map +1 -1
  16. package/dist/hooks/use-current-message.js +6 -5
  17. package/dist/hooks/use-current-message.js.map +1 -1
  18. package/dist/hooks/use-current-message.test.js +5 -0
  19. package/dist/hooks/use-current-message.test.js.map +1 -1
  20. package/dist/model/component-metadata.d.ts +2 -2
  21. package/dist/model/component-metadata.d.ts.map +1 -1
  22. package/dist/model/component-metadata.js.map +1 -1
  23. package/dist/model/tambo-interactable.d.ts +6 -0
  24. package/dist/model/tambo-interactable.d.ts.map +1 -1
  25. package/dist/model/tambo-interactable.js.map +1 -1
  26. package/dist/providers/tambo-interactable-provider-partial-updates.test.js +87 -87
  27. package/dist/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
  28. package/dist/providers/tambo-interactable-provider.d.ts +1 -0
  29. package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
  30. package/dist/providers/tambo-interactable-provider.js +83 -47
  31. package/dist/providers/tambo-interactable-provider.js.map +1 -1
  32. package/dist/providers/tambo-interactable-provider.test.d.ts +2 -0
  33. package/dist/providers/tambo-interactable-provider.test.d.ts.map +1 -0
  34. package/dist/providers/tambo-interactable-provider.test.js +62 -0
  35. package/dist/providers/tambo-interactable-provider.test.js.map +1 -0
  36. package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js +8 -8
  37. package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
  38. package/dist/providers/tambo-interactables-additional-context.test.js +10 -10
  39. package/dist/providers/tambo-interactables-additional-context.test.js.map +1 -1
  40. package/dist/providers/tambo-registry-provider.test.js +28 -18
  41. package/dist/providers/tambo-registry-provider.test.js.map +1 -1
  42. package/dist/providers/tambo-registry-schema-compat.test.js +57 -28
  43. package/dist/providers/tambo-registry-schema-compat.test.js.map +1 -1
  44. package/dist/providers/tambo-thread-provider.test.js +21 -19
  45. package/dist/providers/tambo-thread-provider.test.js.map +1 -1
  46. package/dist/schema/alias.d.ts +3 -0
  47. package/dist/schema/alias.d.ts.map +1 -0
  48. package/dist/schema/alias.js +6 -0
  49. package/dist/schema/alias.js.map +1 -0
  50. package/dist/schema/json-schema.js +29 -29
  51. package/dist/schema/json-schema.js.map +1 -1
  52. package/dist/schema/schema.d.ts.map +1 -1
  53. package/dist/schema/schema.js +20 -9
  54. package/dist/schema/schema.js.map +1 -1
  55. package/dist/schema/schema.test.js +291 -3
  56. package/dist/schema/schema.test.js.map +1 -1
  57. package/dist/schema/standard-schema.js +8 -8
  58. package/dist/schema/standard-schema.js.map +1 -1
  59. package/dist/schema/validate.test.js +31 -31
  60. package/dist/schema/validate.test.js.map +1 -1
  61. package/dist/schema/zod.d.ts +1 -1
  62. package/dist/schema/zod.d.ts.map +1 -1
  63. package/dist/schema/zod.js +27 -26
  64. package/dist/schema/zod.js.map +1 -1
  65. package/dist/schema/zod.test.d.ts +2 -0
  66. package/dist/schema/zod.test.d.ts.map +1 -0
  67. package/dist/schema/zod.test.js +551 -0
  68. package/dist/schema/zod.test.js.map +1 -0
  69. package/dist/util/registry-validators.d.ts.map +1 -1
  70. package/dist/util/registry-validators.js +40 -0
  71. package/dist/util/registry-validators.js.map +1 -1
  72. package/dist/util/registry-validators.test.js +69 -0
  73. package/dist/util/registry-validators.test.js.map +1 -1
  74. package/dist/util/registry.d.ts +1 -5
  75. package/dist/util/registry.d.ts.map +1 -1
  76. package/dist/util/registry.js +1 -5
  77. package/dist/util/registry.js.map +1 -1
  78. package/dist/util/registry.test.js +80 -67
  79. package/dist/util/registry.test.js.map +1 -1
  80. package/esm/context-helpers/current-interactables-context-helper.d.ts +2 -2
  81. package/esm/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
  82. package/esm/context-helpers/current-interactables-context-helper.js +17 -23
  83. package/esm/context-helpers/current-interactables-context-helper.js.map +1 -1
  84. package/esm/hoc/with-tambo-interactable.d.ts.map +1 -1
  85. package/esm/hoc/with-tambo-interactable.js +0 -1
  86. package/esm/hoc/with-tambo-interactable.js.map +1 -1
  87. package/esm/hooks/use-component-state.d.ts +16 -1
  88. package/esm/hooks/use-component-state.d.ts.map +1 -1
  89. package/esm/hooks/use-component-state.js +74 -14
  90. package/esm/hooks/use-component-state.js.map +1 -1
  91. package/esm/hooks/use-component-state.test.js +40 -1
  92. package/esm/hooks/use-component-state.test.js.map +1 -1
  93. package/esm/hooks/use-current-message.d.ts +3 -0
  94. package/esm/hooks/use-current-message.d.ts.map +1 -1
  95. package/esm/hooks/use-current-message.js +2 -1
  96. package/esm/hooks/use-current-message.js.map +1 -1
  97. package/esm/hooks/use-current-message.test.js +5 -0
  98. package/esm/hooks/use-current-message.test.js.map +1 -1
  99. package/esm/model/component-metadata.d.ts +2 -2
  100. package/esm/model/component-metadata.d.ts.map +1 -1
  101. package/esm/model/component-metadata.js.map +1 -1
  102. package/esm/model/tambo-interactable.d.ts +6 -0
  103. package/esm/model/tambo-interactable.d.ts.map +1 -1
  104. package/esm/model/tambo-interactable.js.map +1 -1
  105. package/esm/providers/tambo-interactable-provider-partial-updates.test.js +1 -1
  106. package/esm/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
  107. package/esm/providers/tambo-interactable-provider.d.ts +1 -0
  108. package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
  109. package/esm/providers/tambo-interactable-provider.js +55 -19
  110. package/esm/providers/tambo-interactable-provider.js.map +1 -1
  111. package/esm/providers/tambo-interactable-provider.test.d.ts +2 -0
  112. package/esm/providers/tambo-interactable-provider.test.d.ts.map +1 -0
  113. package/esm/providers/tambo-interactable-provider.test.js +57 -0
  114. package/esm/providers/tambo-interactable-provider.test.js.map +1 -0
  115. package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js +1 -1
  116. package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
  117. package/esm/providers/tambo-interactables-additional-context.test.js +1 -1
  118. package/esm/providers/tambo-interactables-additional-context.test.js.map +1 -1
  119. package/esm/providers/tambo-registry-provider.test.js +16 -6
  120. package/esm/providers/tambo-registry-provider.test.js.map +1 -1
  121. package/esm/providers/tambo-registry-schema-compat.test.js +57 -28
  122. package/esm/providers/tambo-registry-schema-compat.test.js.map +1 -1
  123. package/esm/providers/tambo-thread-provider.test.js +8 -6
  124. package/esm/providers/tambo-thread-provider.test.js.map +1 -1
  125. package/esm/schema/alias.d.ts +3 -0
  126. package/esm/schema/alias.d.ts.map +1 -0
  127. package/esm/schema/alias.js +13 -0
  128. package/esm/schema/alias.js.map +1 -0
  129. package/esm/schema/json-schema.js +1 -1
  130. package/esm/schema/json-schema.js.map +1 -1
  131. package/esm/schema/schema.d.ts.map +1 -1
  132. package/esm/schema/schema.js +20 -9
  133. package/esm/schema/schema.js.map +1 -1
  134. package/esm/schema/schema.test.js +258 -3
  135. package/esm/schema/schema.test.js.map +1 -1
  136. package/esm/schema/standard-schema.js +1 -1
  137. package/esm/schema/standard-schema.js.map +1 -1
  138. package/esm/schema/validate.test.js +1 -1
  139. package/esm/schema/validate.test.js.map +1 -1
  140. package/esm/schema/zod.d.ts +1 -1
  141. package/esm/schema/zod.d.ts.map +1 -1
  142. package/esm/schema/zod.js +27 -26
  143. package/esm/schema/zod.js.map +1 -1
  144. package/esm/schema/zod.test.d.ts +2 -0
  145. package/esm/schema/zod.test.d.ts.map +1 -0
  146. package/esm/schema/zod.test.js +516 -0
  147. package/esm/schema/zod.test.js.map +1 -0
  148. package/esm/util/registry-validators.d.ts.map +1 -1
  149. package/esm/util/registry-validators.js +40 -0
  150. package/esm/util/registry-validators.js.map +1 -1
  151. package/esm/util/registry-validators.test.js +69 -0
  152. package/esm/util/registry-validators.test.js.map +1 -1
  153. package/esm/util/registry.d.ts +1 -5
  154. package/esm/util/registry.d.ts.map +1 -1
  155. package/esm/util/registry.js +1 -5
  156. package/esm/util/registry.js.map +1 -1
  157. package/esm/util/registry.test.js +80 -67
  158. package/esm/util/registry.test.js.map +1 -1
  159. package/package.json +2 -3
@@ -1 +1 @@
1
- {"version":3,"file":"standard-schema.js","sourceRoot":"","sources":["../../src/schema/standard-schema.ts"],"names":[],"mappings":";;AAkCA,4CAEC;AAnCD,uDAAqC;AAErC,MAAM,mBAAmB,GAAG,oBAAC,CAAC,MAAM,CAAC;IACnC,OAAO,EAAE,oBAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACrB,MAAM,EAAE,oBAAC,CAAC,MAAM,EAAE;IAClB,QAAQ,EAAE,oBAAC,CAAC,QAAQ,CAAC;QACnB,KAAK,EAAE,CAAC,oBAAC,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,EAAE,oBAAC,CAAC,KAAK,CAAC,CAAC,oBAAC,CAAC,OAAO,EAAE,EAAE,oBAAC,CAAC,OAAO,CAAC,oBAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;KACvD,CAAC;CACH,CAAC,CAAC;AAEH,MAAM,oBAAoB,GAAG,oBAAC,CAAC,MAAM,CAAC;IACpC,WAAW,EAAE,mBAAmB;CACjC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,gBAAgB,CAAC,GAAY;IAC3C,OAAO,oBAAoB,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;AACrD,CAAC","sourcesContent":["import { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { z } from \"zodInternalAlias\";\n\nconst standardSchemaProps = z.object({\n version: z.literal(1),\n vendor: z.string(),\n validate: z.function({\n input: [z.unknown()],\n output: z.union([z.unknown(), z.promise(z.unknown())]),\n }),\n});\n\nconst standardSchemaObject = z.object({\n \"~standard\": standardSchemaProps,\n});\n\n/**\n * Type guard to check if an object implements the Standard Schema interface.\n *\n * Standard Schema compliant validators have a `~standard` property containing\n * metadata about the schema including version, vendor, and validate function.\n * @param obj - The object to check\n * @returns True if the object implements StandardSchemaV1\n * @example\n * ```typescript\n * import { z } from \"zod/v4\";\n *\n * const zodSchema = z.object({ name: z.string() });\n * isStandardSchema(zodSchema); // true\n *\n * const jsonSchema = { type: \"object\", properties: { name: { type: \"string\" } } };\n * isStandardSchema(jsonSchema); // false\n * ```\n */\nexport function isStandardSchema(obj: unknown): obj is StandardSchemaV1 {\n return standardSchemaObject.safeParse(obj).success;\n}\n"]}
1
+ {"version":3,"file":"standard-schema.js","sourceRoot":"","sources":["../../src/schema/standard-schema.ts"],"names":[],"mappings":";;AAkCA,4CAEC;AAnCD,mCAA4B;AAE5B,MAAM,mBAAmB,GAAG,SAAC,CAAC,MAAM,CAAC;IACnC,OAAO,EAAE,SAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACrB,MAAM,EAAE,SAAC,CAAC,MAAM,EAAE;IAClB,QAAQ,EAAE,SAAC,CAAC,QAAQ,CAAC;QACnB,KAAK,EAAE,CAAC,SAAC,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,EAAE,SAAC,CAAC,KAAK,CAAC,CAAC,SAAC,CAAC,OAAO,EAAE,EAAE,SAAC,CAAC,OAAO,CAAC,SAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;KACvD,CAAC;CACH,CAAC,CAAC;AAEH,MAAM,oBAAoB,GAAG,SAAC,CAAC,MAAM,CAAC;IACpC,WAAW,EAAE,mBAAmB;CACjC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,gBAAgB,CAAC,GAAY;IAC3C,OAAO,oBAAoB,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;AACrD,CAAC","sourcesContent":["import { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { z } from \"./alias\";\n\nconst standardSchemaProps = z.object({\n version: z.literal(1),\n vendor: z.string(),\n validate: z.function({\n input: [z.unknown()],\n output: z.union([z.unknown(), z.promise(z.unknown())]),\n }),\n});\n\nconst standardSchemaObject = z.object({\n \"~standard\": standardSchemaProps,\n});\n\n/**\n * Type guard to check if an object implements the Standard Schema interface.\n *\n * Standard Schema compliant validators have a `~standard` property containing\n * metadata about the schema including version, vendor, and validate function.\n * @param obj - The object to check\n * @returns True if the object implements StandardSchemaV1\n * @example\n * ```typescript\n * import { z } from \"zod/v4\";\n *\n * const zodSchema = z.object({ name: z.string() });\n * isStandardSchema(zodSchema); // true\n *\n * const jsonSchema = { type: \"object\", properties: { name: { type: \"string\" } } };\n * isStandardSchema(jsonSchema); // false\n * ```\n */\nexport function isStandardSchema(obj: unknown): obj is StandardSchemaV1 {\n return standardSchemaObject.safeParse(obj).success;\n}\n"]}
@@ -1,84 +1,84 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const zodInternalAlias_1 = require("zodInternalAlias");
3
+ const v4_1 = require("zod/v4");
4
4
  const validate_1 = require("./validate");
5
5
  describe("assertNoRecordSchema", () => {
6
6
  it("should allow valid schemas without records", () => {
7
- const schema = zodInternalAlias_1.z.object({
8
- name: zodInternalAlias_1.z.string(),
9
- age: zodInternalAlias_1.z.number(),
10
- tags: zodInternalAlias_1.z.array(zodInternalAlias_1.z.string()),
11
- address: zodInternalAlias_1.z.object({
12
- street: zodInternalAlias_1.z.string(),
13
- city: zodInternalAlias_1.z.string(),
7
+ const schema = v4_1.z.object({
8
+ name: v4_1.z.string(),
9
+ age: v4_1.z.number(),
10
+ tags: v4_1.z.array(v4_1.z.string()),
11
+ address: v4_1.z.object({
12
+ street: v4_1.z.string(),
13
+ city: v4_1.z.string(),
14
14
  }),
15
15
  });
16
16
  expect(() => (0, validate_1.assertNoRecordSchema)(schema)).not.toThrow();
17
17
  });
18
18
  it("should throw when encountering a record at root level", () => {
19
- const schema = zodInternalAlias_1.z.record(zodInternalAlias_1.z.string(), zodInternalAlias_1.z.string());
19
+ const schema = v4_1.z.record(v4_1.z.string(), v4_1.z.string());
20
20
  expect(() => (0, validate_1.assertNoRecordSchema)(schema)).toThrow('Record types (objects with dynamic keys) are not supported in schema. Found at path "(root)". Replace it with an object using explicit keys.');
21
21
  });
22
22
  it("should throw when encountering a nested record", () => {
23
- const schema = zodInternalAlias_1.z.object({
24
- name: zodInternalAlias_1.z.string(),
25
- metadata: zodInternalAlias_1.z.record(zodInternalAlias_1.z.string(), zodInternalAlias_1.z.string()),
23
+ const schema = v4_1.z.object({
24
+ name: v4_1.z.string(),
25
+ metadata: v4_1.z.record(v4_1.z.string(), v4_1.z.string()),
26
26
  });
27
27
  expect(() => (0, validate_1.assertNoRecordSchema)(schema)).toThrow('Record types (objects with dynamic keys) are not supported in schema. Found at path "metadata". Replace it with an object using explicit keys.');
28
28
  });
29
29
  it("should throw when encountering a record in an array", () => {
30
- const schema = zodInternalAlias_1.z.object({
31
- items: zodInternalAlias_1.z.array(zodInternalAlias_1.z.record(zodInternalAlias_1.z.string(), zodInternalAlias_1.z.string())),
30
+ const schema = v4_1.z.object({
31
+ items: v4_1.z.array(v4_1.z.record(v4_1.z.string(), v4_1.z.string())),
32
32
  });
33
33
  expect(() => (0, validate_1.assertNoRecordSchema)(schema)).toThrow('Record types (objects with dynamic keys) are not supported in schema. Found at path "items.[]". Replace it with an object using explicit keys.');
34
34
  });
35
35
  it("should throw when encountering a record in a union", () => {
36
- const schema = zodInternalAlias_1.z.union([zodInternalAlias_1.z.string(), zodInternalAlias_1.z.record(zodInternalAlias_1.z.string(), zodInternalAlias_1.z.number())]);
36
+ const schema = v4_1.z.union([v4_1.z.string(), v4_1.z.record(v4_1.z.string(), v4_1.z.number())]);
37
37
  expect(() => (0, validate_1.assertNoRecordSchema)(schema)).toThrow('Record types (objects with dynamic keys) are not supported in schema. Found at path "|1". Replace it with an object using explicit keys.');
38
38
  });
39
39
  it("should throw when encountering a record in an intersection", () => {
40
- const schema = zodInternalAlias_1.z.intersection(zodInternalAlias_1.z.object({ name: zodInternalAlias_1.z.string() }), zodInternalAlias_1.z.object({ metadata: zodInternalAlias_1.z.record(zodInternalAlias_1.z.string(), zodInternalAlias_1.z.string()) }));
40
+ const schema = v4_1.z.intersection(v4_1.z.object({ name: v4_1.z.string() }), v4_1.z.object({ metadata: v4_1.z.record(v4_1.z.string(), v4_1.z.string()) }));
41
41
  expect(() => (0, validate_1.assertNoRecordSchema)(schema)).toThrow(/Record types \(objects with dynamic keys\) are not supported in schema\. Found at path "(&1\.)?metadata"\. Replace it with an object using explicit keys\./);
42
42
  });
43
43
  it("should throw when encountering a record in a discriminated union", () => {
44
- const schema = zodInternalAlias_1.z.discriminatedUnion("type", [
45
- zodInternalAlias_1.z.object({ type: zodInternalAlias_1.z.literal("string"), value: zodInternalAlias_1.z.string() }),
46
- zodInternalAlias_1.z.object({
47
- type: zodInternalAlias_1.z.literal("record"),
48
- value: zodInternalAlias_1.z.record(zodInternalAlias_1.z.string(), zodInternalAlias_1.z.number()),
44
+ const schema = v4_1.z.discriminatedUnion("type", [
45
+ v4_1.z.object({ type: v4_1.z.literal("string"), value: v4_1.z.string() }),
46
+ v4_1.z.object({
47
+ type: v4_1.z.literal("record"),
48
+ value: v4_1.z.record(v4_1.z.string(), v4_1.z.number()),
49
49
  }),
50
50
  ]);
51
51
  expect(() => (0, validate_1.assertNoRecordSchema)(schema)).toThrow(/Record types \(objects with dynamic keys\) are not supported in schema\. Found at path "\|1\.value"\. Replace it with an object using explicit keys\./);
52
52
  });
53
53
  it("should throw when encountering a record in an optional field", () => {
54
- const schema = zodInternalAlias_1.z.object({
55
- optional: zodInternalAlias_1.z.optional(zodInternalAlias_1.z.record(zodInternalAlias_1.z.string(), zodInternalAlias_1.z.string())),
54
+ const schema = v4_1.z.object({
55
+ optional: v4_1.z.optional(v4_1.z.record(v4_1.z.string(), v4_1.z.string())),
56
56
  });
57
57
  expect(() => (0, validate_1.assertNoRecordSchema)(schema)).toThrow('Record types (objects with dynamic keys) are not supported in schema. Found at path "optional". Replace it with an object using explicit keys.');
58
58
  });
59
59
  it("should throw when encountering a record in a nullable field", () => {
60
- const schema = zodInternalAlias_1.z.object({
61
- nullable: zodInternalAlias_1.z.nullable(zodInternalAlias_1.z.record(zodInternalAlias_1.z.string(), zodInternalAlias_1.z.string())),
60
+ const schema = v4_1.z.object({
61
+ nullable: v4_1.z.nullable(v4_1.z.record(v4_1.z.string(), v4_1.z.string())),
62
62
  });
63
63
  // Nullable creates a oneOf in JSON Schema, so the path includes the union index
64
64
  expect(() => (0, validate_1.assertNoRecordSchema)(schema)).toThrow(/Record types \(objects with dynamic keys\) are not supported in schema\. Found at path "nullable(\.\|0)?"\. Replace it with an object using explicit keys\./);
65
65
  });
66
66
  it("should throw when encountering a record in a tuple", () => {
67
- const schema = zodInternalAlias_1.z.tuple([zodInternalAlias_1.z.string(), zodInternalAlias_1.z.record(zodInternalAlias_1.z.string(), zodInternalAlias_1.z.number())]);
67
+ const schema = v4_1.z.tuple([v4_1.z.string(), v4_1.z.record(v4_1.z.string(), v4_1.z.number())]);
68
68
  expect(() => (0, validate_1.assertNoRecordSchema)(schema)).toThrow('Record types (objects with dynamic keys) are not supported in schema. Found at path "1". Replace it with an object using explicit keys.');
69
69
  });
70
70
  it("should use custom context name in error message", () => {
71
- const schema = zodInternalAlias_1.z.record(zodInternalAlias_1.z.string(), zodInternalAlias_1.z.string());
71
+ const schema = v4_1.z.record(v4_1.z.string(), v4_1.z.string());
72
72
  expect(() => (0, validate_1.assertNoRecordSchema)(schema, "mySchema")).toThrow('Record types (objects with dynamic keys) are not supported in mySchema. Found at path "(root)". Replace it with an object using explicit keys.');
73
73
  });
74
74
  it("should handle ZodLazy schemas", () => {
75
- const schema = zodInternalAlias_1.z.lazy(() => zodInternalAlias_1.z.record(zodInternalAlias_1.z.string(), zodInternalAlias_1.z.string()));
75
+ const schema = v4_1.z.lazy(() => v4_1.z.record(v4_1.z.string(), v4_1.z.string()));
76
76
  expect(() => (0, validate_1.assertNoRecordSchema)(schema)).toThrow('Record types (objects with dynamic keys) are not supported in schema. Found at path "(root)". Replace it with an object using explicit keys.');
77
77
  });
78
78
  it("should allow z.function() with valid arguments", () => {
79
- const schema = zodInternalAlias_1.z.function({
80
- input: [zodInternalAlias_1.z.string(), zodInternalAlias_1.z.number()],
81
- output: zodInternalAlias_1.z.string(),
79
+ const schema = v4_1.z.function({
80
+ input: [v4_1.z.string(), v4_1.z.number()],
81
+ output: v4_1.z.string(),
82
82
  });
83
83
  // Function schemas can't be converted to JSON Schema directly,
84
84
  // so they should not throw (validation happens on the extracted parameters)
@@ -1 +1 @@
1
- {"version":3,"file":"validate.test.js","sourceRoot":"","sources":["../../src/schema/validate.test.ts"],"names":[],"mappings":";;AAAA,uDAAqC;AACrC,yCAAkD;AAElD,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,MAAM,GAAG,oBAAC,CAAC,MAAM,CAAC;YACtB,IAAI,EAAE,oBAAC,CAAC,MAAM,EAAE;YAChB,GAAG,EAAE,oBAAC,CAAC,MAAM,EAAE;YACf,IAAI,EAAE,oBAAC,CAAC,KAAK,CAAC,oBAAC,CAAC,MAAM,EAAE,CAAC;YACzB,OAAO,EAAE,oBAAC,CAAC,MAAM,CAAC;gBAChB,MAAM,EAAE,oBAAC,CAAC,M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MAAM,UAAU,GAAG;YACjB,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAiB;oBACvB,oBAAoB,EAAE,EAAE,IAAI,EAAE,QAAiB,EAAE;iBAClD;aACF;SACF,CAAC;QAEF,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,+BAAoB,EAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CACpD,gJAAgJ,CACjJ,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { z } from \"zodInternalAlias\";\nimport { assertNoRecordSchema } from \"./validate\";\n\ndescribe(\"assertNoRecordSchema\", () => {\n it(\"should allow valid schemas without records\", () => {\n const schema = z.object({\n name: z.string(),\n age: z.number(),\n tags: z.array(z.string()),\n address: z.object({\n street: z.string(),\n city: z.string(),\n }),\n });\n\n expect(() => assertNoRecordSchema(schema)).not.toThrow();\n });\n\n it(\"should throw when encountering a record at root level\", () => {\n const schema = z.record(z.string(), z.string());\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a nested record\", () => {\n const schema = z.object({\n name: z.string(),\n metadata: z.record(z.string(), z.string()),\n });\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"metadata\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in an array\", () => {\n const schema = z.object({\n items: z.array(z.record(z.string(), z.string())),\n });\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"items.[]\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in a union\", () => {\n const schema = z.union([z.string(), z.record(z.string(), z.number())]);\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"|1\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in an intersection\", () => {\n const schema = z.intersection(\n z.object({ name: z.string() }),\n z.object({ metadata: z.record(z.string(), z.string()) }),\n );\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n /Record types \\(objects with dynamic keys\\) are not supported in schema\\. Found at path \"(&1\\.)?metadata\"\\. Replace it with an object using explicit keys\\./,\n );\n });\n\n it(\"should throw when encountering a record in a discriminated union\", () => {\n const schema = z.discriminatedUnion(\"type\", [\n z.object({ type: z.literal(\"string\"), value: z.string() }),\n z.object({\n type: z.literal(\"record\"),\n value: z.record(z.string(), z.number()),\n }),\n ]);\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n /Record types \\(objects with dynamic keys\\) are not supported in schema\\. Found at path \"\\|1\\.value\"\\. Replace it with an object using explicit keys\\./,\n );\n });\n\n it(\"should throw when encountering a record in an optional field\", () => {\n const schema = z.object({\n optional: z.optional(z.record(z.string(), z.string())),\n });\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"optional\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in a nullable field\", () => {\n const schema = z.object({\n nullable: z.nullable(z.record(z.string(), z.string())),\n });\n\n // Nullable creates a oneOf in JSON Schema, so the path includes the union index\n expect(() => assertNoRecordSchema(schema)).toThrow(\n /Record types \\(objects with dynamic keys\\) are not supported in schema\\. Found at path \"nullable(\\.\\|0)?\"\\. Replace it with an object using explicit keys\\./,\n );\n });\n\n it(\"should throw when encountering a record in a tuple\", () => {\n const schema = z.tuple([z.string(), z.record(z.string(), z.number())]);\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"1\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should use custom context name in error message\", () => {\n const schema = z.record(z.string(), z.string());\n\n expect(() => assertNoRecordSchema(schema, \"mySchema\")).toThrow(\n 'Record types (objects with dynamic keys) are not supported in mySchema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should handle ZodLazy schemas\", () => {\n const schema = z.lazy(() => z.record(z.string(), z.string()));\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should allow z.function() with valid arguments\", () => {\n const schema = z.function({\n input: [z.string(), z.number()],\n output: z.string(),\n });\n\n // Function schemas can't be converted to JSON Schema directly,\n // so they should not throw (validation happens on the extracted parameters)\n expect(() => assertNoRecordSchema(schema)).not.toThrow();\n });\n\n it(\"should allow JSON Schema without records\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n properties: {\n name: { type: \"string\" as const },\n age: { type: \"number\" as const },\n },\n required: [\"name\"],\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).not.toThrow();\n });\n\n it(\"should throw when JSON Schema has record pattern\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n additionalProperties: { type: \"string\" as const },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should treat JSON Schema with properties and additionalProperties as a record\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n properties: {\n id: { type: \"string\" as const },\n },\n additionalProperties: { type: \"number\" as const },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when nested JSON Schema has record pattern\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n properties: {\n metadata: {\n type: \"object\" as const,\n additionalProperties: { type: \"string\" as const },\n },\n },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"metadata\". Replace it with an object using explicit keys.',\n );\n });\n});\n"]}
1
+ {"version":3,"file":"validate.test.js","sourceRoot":"","sources":["../../src/schema/validate.test.ts"],"names":[],"mappings":";;AAAA,+BAA2B;AAC3B,yCAAkD;AAElD,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,MAAM,GAAG,MAAC,CAAC,MAAM,CAAC;YACtB,IAAI,EAAE,MAAC,CAAC,MAAM,EAAE;YAChB,GAAG,EAAE,MAAC,CAAC,MAAM,EAAE;YACf,IAAI,EAAE,MAAC,CAAC,KAAK,CAAC,MAAC,CAAC,MAAM,EAAE,CAAC;YACzB,OAAO,EAAE,MAAC,CAAC,MAAM,CAAC;gBAChB,MAAM,EAAE,MAAC,CAAC,MAAM,EAAE;gBAClB,IAAI,EAAE,MAAC,CAAC,MAAM,EAAE;aACjB,CAAC;SACH,CAAC,CAAC;QAEH,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,+BAAoB,EAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uDAAuD,EAAE,GAAG,EAAE;QAC/D,MAAM,MAAM,GAAG,MAAC,CAAC,MAAM,CAAC,MAAC,CAAC,MAAM,EAAE,EAAE,MAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QAEhD,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,+BAAoB,EAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAChD,8IAA8I,CAC/I,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,MAAM,MAAM,GAAG,MAAC,CAAC,MAAM,CAAC;YACtB,IAAI,EAAE,MAAC,CAAC,MAAM,EAAE;YAChB,QAAQ,EAAE,MAAC,CAAC,MAAM,CAAC,MAAC,CAAC,MAAM,E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IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+EAA+E,EAAE,GAAG,EAAE;QACvF,MAAM,UAAU,GAAG;YACjB,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,EAAE,EAAE,EAAE,IAAI,EAAE,QAAiB,EAAE;aAChC;YACD,oBAAoB,EAAE,EAAE,IAAI,EAAE,QAAiB,EAAE;SAClD,CAAC;QAEF,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,+BAAoB,EAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CACpD,8IAA8I,CAC/I,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yDAAyD,EAAE,GAAG,EAAE;QACjE,MAAM,UAAU,GAAG;YACjB,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAiB;oBACvB,oBAAoB,EAAE,EAAE,IAAI,EAAE,QAAiB,EAAE;iBAClD;aACF;SACF,CAAC;QAEF,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,+BAAoB,EAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CACpD,gJAAgJ,CACjJ,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { z } from \"zod/v4\";\nimport { assertNoRecordSchema } from \"./validate\";\n\ndescribe(\"assertNoRecordSchema\", () => {\n it(\"should allow valid schemas without records\", () => {\n const schema = z.object({\n name: z.string(),\n age: z.number(),\n tags: z.array(z.string()),\n address: z.object({\n street: z.string(),\n city: z.string(),\n }),\n });\n\n expect(() => assertNoRecordSchema(schema)).not.toThrow();\n });\n\n it(\"should throw when encountering a record at root level\", () => {\n const schema = z.record(z.string(), z.string());\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a nested record\", () => {\n const schema = z.object({\n name: z.string(),\n metadata: z.record(z.string(), z.string()),\n });\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"metadata\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in an array\", () => {\n const schema = z.object({\n items: z.array(z.record(z.string(), z.string())),\n });\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"items.[]\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in a union\", () => {\n const schema = z.union([z.string(), z.record(z.string(), z.number())]);\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"|1\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in an intersection\", () => {\n const schema = z.intersection(\n z.object({ name: z.string() }),\n z.object({ metadata: z.record(z.string(), z.string()) }),\n );\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n /Record types \\(objects with dynamic keys\\) are not supported in schema\\. Found at path \"(&1\\.)?metadata\"\\. Replace it with an object using explicit keys\\./,\n );\n });\n\n it(\"should throw when encountering a record in a discriminated union\", () => {\n const schema = z.discriminatedUnion(\"type\", [\n z.object({ type: z.literal(\"string\"), value: z.string() }),\n z.object({\n type: z.literal(\"record\"),\n value: z.record(z.string(), z.number()),\n }),\n ]);\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n /Record types \\(objects with dynamic keys\\) are not supported in schema\\. Found at path \"\\|1\\.value\"\\. Replace it with an object using explicit keys\\./,\n );\n });\n\n it(\"should throw when encountering a record in an optional field\", () => {\n const schema = z.object({\n optional: z.optional(z.record(z.string(), z.string())),\n });\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"optional\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when encountering a record in a nullable field\", () => {\n const schema = z.object({\n nullable: z.nullable(z.record(z.string(), z.string())),\n });\n\n // Nullable creates a oneOf in JSON Schema, so the path includes the union index\n expect(() => assertNoRecordSchema(schema)).toThrow(\n /Record types \\(objects with dynamic keys\\) are not supported in schema\\. Found at path \"nullable(\\.\\|0)?\"\\. Replace it with an object using explicit keys\\./,\n );\n });\n\n it(\"should throw when encountering a record in a tuple\", () => {\n const schema = z.tuple([z.string(), z.record(z.string(), z.number())]);\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"1\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should use custom context name in error message\", () => {\n const schema = z.record(z.string(), z.string());\n\n expect(() => assertNoRecordSchema(schema, \"mySchema\")).toThrow(\n 'Record types (objects with dynamic keys) are not supported in mySchema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should handle ZodLazy schemas\", () => {\n const schema = z.lazy(() => z.record(z.string(), z.string()));\n\n expect(() => assertNoRecordSchema(schema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should allow z.function() with valid arguments\", () => {\n const schema = z.function({\n input: [z.string(), z.number()],\n output: z.string(),\n });\n\n // Function schemas can't be converted to JSON Schema directly,\n // so they should not throw (validation happens on the extracted parameters)\n expect(() => assertNoRecordSchema(schema)).not.toThrow();\n });\n\n it(\"should allow JSON Schema without records\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n properties: {\n name: { type: \"string\" as const },\n age: { type: \"number\" as const },\n },\n required: [\"name\"],\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).not.toThrow();\n });\n\n it(\"should throw when JSON Schema has record pattern\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n additionalProperties: { type: \"string\" as const },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should treat JSON Schema with properties and additionalProperties as a record\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n properties: {\n id: { type: \"string\" as const },\n },\n additionalProperties: { type: \"number\" as const },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"(root)\". Replace it with an object using explicit keys.',\n );\n });\n\n it(\"should throw when nested JSON Schema has record pattern\", () => {\n const jsonSchema = {\n type: \"object\" as const,\n properties: {\n metadata: {\n type: \"object\" as const,\n additionalProperties: { type: \"string\" as const },\n },\n },\n };\n\n expect(() => assertNoRecordSchema(jsonSchema)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in schema. Found at path \"metadata\". Replace it with an object using explicit keys.',\n );\n });\n});\n"]}
@@ -50,5 +50,5 @@ export declare function isZod4Schema(schema: unknown): schema is $ZodType;
50
50
  * @param schema - The schema to check
51
51
  * @returns True if the schema is a Zod schema
52
52
  */
53
- export declare function isZodSchema(schema: unknown): ReturnType<typeof isZod3Schema> | ReturnType<typeof isZod4Schema>;
53
+ export declare function isZodSchema(schema: unknown): schema is ZodType | $ZodType;
54
54
  //# sourceMappingURL=zod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,QAAQ,EACR,aAAa,EACb,OAAO,EACP,UAAU,EACX,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,YAAY,EACZ,QAAQ,EAET,MAAM,aAAa,CAAC;AAGrB;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,CAMjE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,YAAY,CAoB5E;AAED;;;;GAIG;AAC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AO,OAWpD;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,OAmBpD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,OAAO,CAE/D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,QAAQ,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,OAAO,GAAG,QAAQ,CAczE"}
@@ -10,15 +10,15 @@ exports.isZod3Schema = isZod3Schema;
10
10
  exports.isZod4Schema = isZod4Schema;
11
11
  exports.isZodSchema = isZodSchema;
12
12
  const core_1 = require("zod/v4/core");
13
- const zodInternalAlias_1 = require("zodInternalAlias");
14
13
  /**
15
14
  * @returns True if the schema is a Zod 3 function schema
16
15
  */
17
16
  function isZod3FunctionSchema(schema) {
18
- if (!isZod3Schema(schema)) {
17
+ if (!isZodSchema(schema))
19
18
  return false;
20
- }
21
- return "typeName" in schema._def && schema._def.typeName === "ZodFunction";
19
+ return ("_def" in schema &&
20
+ "typeName" in schema._def &&
21
+ schema._def.typeName === "ZodFunction");
22
22
  }
23
23
  /**
24
24
  * @returns True if the schema is a Zod 4 function schema
@@ -89,12 +89,12 @@ function getZodFunctionReturns(schema) {
89
89
  function handleZodSchemaToJson(schema) {
90
90
  // If Zod4 schema detected, use the toJSONSchema function from "zod/v4/core"
91
91
  if (isZod4Schema(schema))
92
- return (0, core_1.toJSONSchema)(schema);
92
+ return (0, core_1.toJSONSchema)(schema, { reused: "inline" });
93
93
  try {
94
94
  // Dynamic require for optional peer dependency
95
95
  // eslint-disable-next-line @typescript-eslint/no-require-imports -- need require because zod-to-json-schema may be missing
96
96
  const { zodToJsonSchema } = require("zod-to-json-schema");
97
- return zodToJsonSchema(schema);
97
+ return zodToJsonSchema(schema, { $refStrategy: "none" });
98
98
  }
99
99
  catch (error) {
100
100
  throw new Error("Zod 3 requires 'zod-to-json-schema' package for JSON Schema conversion. " +
@@ -103,38 +103,21 @@ function handleZodSchemaToJson(schema) {
103
103
  });
104
104
  }
105
105
  }
106
- // Zod 3 schemas have _def with typeName and ~standard with vendor "zod"
107
- // Use looseObject to allow any _def shape (different for each type)
108
- const zod3SchemaType = zodInternalAlias_1.z.object({
109
- _def: zodInternalAlias_1.z.looseObject({
110
- typeName: zodInternalAlias_1.z.string().optional(),
111
- }),
112
- "~standard": zodInternalAlias_1.z.looseObject({
113
- vendor: zodInternalAlias_1.z.literal("zod"),
114
- }),
115
- });
116
106
  /**
117
107
  * Checks if a schema is probably a Zod 3 schema.
118
108
  * @param schema - The schema to check
119
109
  * @returns True if the schema looks like a Zod 3 schema
120
110
  */
121
111
  function isZod3Schema(schema) {
122
- return zod3SchemaType.safeParse(schema).success;
112
+ return isZodSchema(schema) && "_def" in schema && !("def" in schema);
123
113
  }
124
- const zod4SchemaType = zodInternalAlias_1.z.object({
125
- def: zodInternalAlias_1.z.object(),
126
- _zod: zodInternalAlias_1.z.looseObject({
127
- def: zodInternalAlias_1.z.looseObject({}),
128
- }),
129
- "~standard": zodInternalAlias_1.z.looseObject({}),
130
- });
131
114
  /**
132
115
  * Detects if a schema is Zod 4 by checking for def.type property.
133
116
  * Zod 4 uses `def.type` with lowercase type names like "object", "string".
134
117
  * @returns True if the schema appears to be Zod 4 style
135
118
  */
136
119
  function isZod4Schema(schema) {
137
- return zod4SchemaType.safeParse(schema).success;
120
+ return isZodSchema(schema) && "_zod" in schema;
138
121
  }
139
122
  /**
140
123
  * Checks if a schema is a Zod schema
@@ -142,6 +125,24 @@ function isZod4Schema(schema) {
142
125
  * @returns True if the schema is a Zod schema
143
126
  */
144
127
  function isZodSchema(schema) {
145
- return isZod3Schema(schema) || isZod4Schema(schema);
128
+ // schema must be { ~standard: { vendor: "zod" } }
129
+ if (typeof schema !== "object")
130
+ return false;
131
+ if (!schema)
132
+ return false;
133
+ if (!("~standard" in schema))
134
+ return false;
135
+ if (!schema["~standard"])
136
+ return false;
137
+ if (typeof schema["~standard"] !== "object")
138
+ return false;
139
+ if (!("vendor" in schema["~standard"]))
140
+ return false;
141
+ if (schema["~standard"].vendor !== "zod")
142
+ return false;
143
+ // Require at least one internal marker to reduce false positives
144
+ const looksLikeV3 = "_def" in schema;
145
+ const looksLikeV4 = "_zod" in schema || "def" in schema;
146
+ return looksLikeV3 || looksLikeV4;
146
147
  }
147
148
  //# sourceMappingURL=zod.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":";;AAiBA,oDAQC;AAKD,oDAoBC;AAOD,kDAEC;AAOD,gDAWC;AAOD,sDAWC;AAQD,sDAkBC;AAkBD,oCAEC;AAeD,oCAEC;AAOD,kCAIC;AAlKD,sCAIqB;AACrB,uDAAqC;AAErC;;GAEG;AACH,SAAgB,oBAAoB,CAClC,MAAe;IAEf,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,UAAU,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,KAAK,aAAa,CAAC;AAC7E,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,MAAe;IAClD,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,2EAA2E;IAC3E,6EAA6E;IAC7E,4EAA4E;IAC5E,8CAA8C;IAC9C,gIAAgI;IAChI,IAAI,KAAK,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;QACpE,IAAK,MAAM,CAAC,GAAwB,EAAE,IAAI,KAAK,UAAU,EAAE,CAAC;YAC1D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CA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,CAAC","sourcesContent":["import {\n ZodFunction,\n ZodTuple,\n ZodTupleItems,\n ZodType,\n ZodTypeAny,\n} from \"zod/v3\";\nimport {\n $ZodFunction,\n $ZodType,\n toJSONSchema as zod4ToJSONSchema,\n} from \"zod/v4/core\";\nimport { z } from \"zodInternalAlias\";\n\n/**\n * @returns True if the schema is a Zod 3 function schema\n */\nexport function isZod3FunctionSchema(\n schema: unknown,\n): schema is ZodFunction<ZodTuple<ZodTupleItems, any>, ZodTypeAny> {\n if (!isZod3Schema(schema)) {\n return false;\n }\n\n return \"typeName\" in schema._def && schema._def.typeName === \"ZodFunction\";\n}\n\n/**\n * @returns True if the schema is a Zod 4 function schema\n */\nexport function isZod4FunctionSchema(schema: unknown): schema is $ZodFunction {\n if (!isZod4Schema(schema)) {\n return false;\n }\n\n // $ZodFunctions in zod 4.0 most certainly do have .def.type === \"function\"\n // but the type definitions do not reflect this because $ZodFunction does not\n // extend $ZodType. This is corrected in zod 4.1, but zod 3 does not include\n // the types for 4.1 yet (and might not ever).\n // See: https://github.com/colinhacks/zod/blob/463f03eb8183dcdcdf735b180f2bf40883e66220/packages/zod/src/v4/core/function.ts#L48\n if (\"def\" in schema && typeof schema.def !== \"object\" && schema.def) {\n if ((schema.def as { type: string })?.type === \"function\") {\n return true;\n }\n }\n\n // We're casting as string here because zod 4.0 types don't include \"function\"\n // literal in the union for `_zod.def.type`. The optional chaining is because\n // _zod does not exist on zod 4 objects from zod 3.\n return (schema._zod?.def?.type as string) === \"function\";\n}\n\n/**\n * Checks if a schema is a Zod function schema (Zod 3 or Zod 4).\n * @param schema - The schema to check\n * @returns True if the schema is a Zod function schema\n */\nexport function isZodFunctionSchema(schema: unknown) {\n return isZod3FunctionSchema(schema) || isZod4FunctionSchema(schema);\n}\n\n/**\n * Extracts the args schema from a Zod function schema.\n * @param schema - The Zod function schema\n * @returns The args schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionArgs(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.args;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4.0\n return schema?.def?.input ?? schema._zod?.def?.input;\n }\n\n throw new Error(\"Unable to determine parameters from zod function schema\");\n}\n\n/**\n * Extracts the return schema from a Zod 3 or Zod 4 function schema.\n * @param schema - The Zod function schema\n * @returns The return schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionReturns(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.returns;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4\n return schema._zod.def.output;\n }\n\n throw new Error(\"Unable to determine return type from zod function schema\");\n}\n\n/**\n * Handles conversion of Zod schemas to JSON Schema.\n * Supports both Zod 3 (via zod-to-json-schema) and Zod 4 (native).\n * @param schema - The Zod schema to convert\n * @returns The JSON Schema representation\n */\nexport function handleZodSchemaToJson(schema: unknown) {\n // If Zod4 schema detected, use the toJSONSchema function from \"zod/v4/core\"\n if (isZod4Schema(schema)) return zod4ToJSONSchema(schema);\n\n try {\n // Dynamic require for optional peer dependency\n // eslint-disable-next-line @typescript-eslint/no-require-imports -- need require because zod-to-json-schema may be missing\n const { zodToJsonSchema } = require(\"zod-to-json-schema\");\n return zodToJsonSchema(schema);\n } catch (error) {\n throw new Error(\n \"Zod 3 requires 'zod-to-json-schema' package for JSON Schema conversion. \" +\n \"Install it with: npm install zod-to-json-schema\",\n {\n cause: error,\n },\n );\n }\n}\n\n// Zod 3 schemas have _def with typeName and ~standard with vendor \"zod\"\n// Use looseObject to allow any _def shape (different for each type)\nconst zod3SchemaType = z.object({\n _def: z.looseObject({\n typeName: z.string().optional(),\n }),\n \"~standard\": z.looseObject({\n vendor: z.literal(\"zod\"),\n }),\n});\n\n/**\n * Checks if a schema is probably a Zod 3 schema.\n * @param schema - The schema to check\n * @returns True if the schema looks like a Zod 3 schema\n */\nexport function isZod3Schema(schema: unknown): schema is ZodType {\n return zod3SchemaType.safeParse(schema).success;\n}\n\nconst zod4SchemaType = z.object({\n def: z.object(),\n _zod: z.looseObject({\n def: z.looseObject({}),\n }),\n \"~standard\": z.looseObject({}),\n});\n\n/**\n * Detects if a schema is Zod 4 by checking for def.type property.\n * Zod 4 uses `def.type` with lowercase type names like \"object\", \"string\".\n * @returns True if the schema appears to be Zod 4 style\n */\nexport function isZod4Schema(schema: unknown): schema is $ZodType {\n return zod4SchemaType.safeParse(schema).success;\n}\n\n/**\n * Checks if a schema is a Zod schema\n * @param schema - The schema to check\n * @returns True if the schema is a Zod schema\n */\nexport function isZodSchema(\n schema: unknown,\n): ReturnType<typeof isZod3Schema> | ReturnType<typeof isZod4Schema> {\n return isZod3Schema(schema) || isZod4Schema(schema);\n}\n"]}
1
+ {"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":";;AAgBA,oDAUC;AAKD,oDAoBC;AAOD,kDAEC;AAOD,gDAWC;AAOD,sDAWC;AAQD,sDAmBC;AAOD,oCAEC;AAOD,oCAEC;AAOD,kCAcC;AA3JD,sCAIqB;AAErB;;GAEG;AACH,SAAgB,oBAAoB,CAClC,MAAe;IAEf,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IAEvC,OAAO,CACL,MAAM,IAAI,MAAM;QAChB,UAAU,IAAI,MAAM,CAAC,IAAI;QACzB,MAAM,CAAC,IAAI,CAAC,QAAQ,KAAK,aAAa,CACvC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,MAAe;IAClD,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,2EAA2E;IAC3E,6EAA6E;IAC7E,4EAA4E;IAC5E,8CAA8C;IAC9C,gIAAgI;IAChI,IAAI,KAAK,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,IAAI,MAAM,CAA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CAAC;IACrD,IAAI,MAAM,CAAC,WAAW,CAAC,CAAC,MAAM,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAEvD,iEAAiE;IACjE,MAAM,WAAW,GAAG,MAAM,IAAI,MAAM,CAAC;IACrC,MAAM,WAAW,GAAG,MAAM,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,CAAC;IACxD,OAAO,WAAW,IAAI,WAAW,CAAC;AACpC,CAAC","sourcesContent":["import {\n ZodFunction,\n ZodTuple,\n ZodTupleItems,\n ZodType,\n ZodTypeAny,\n} from \"zod/v3\";\nimport {\n $ZodFunction,\n $ZodType,\n toJSONSchema as zod4ToJSONSchema,\n} from \"zod/v4/core\";\n\n/**\n * @returns True if the schema is a Zod 3 function schema\n */\nexport function isZod3FunctionSchema(\n schema: unknown,\n): schema is ZodFunction<ZodTuple<ZodTupleItems, any>, ZodTypeAny> {\n if (!isZodSchema(schema)) return false;\n\n return (\n \"_def\" in schema &&\n \"typeName\" in schema._def &&\n schema._def.typeName === \"ZodFunction\"\n );\n}\n\n/**\n * @returns True if the schema is a Zod 4 function schema\n */\nexport function isZod4FunctionSchema(schema: unknown): schema is $ZodFunction {\n if (!isZod4Schema(schema)) {\n return false;\n }\n\n // $ZodFunctions in zod 4.0 most certainly do have .def.type === \"function\"\n // but the type definitions do not reflect this because $ZodFunction does not\n // extend $ZodType. This is corrected in zod 4.1, but zod 3 does not include\n // the types for 4.1 yet (and might not ever).\n // See: https://github.com/colinhacks/zod/blob/463f03eb8183dcdcdf735b180f2bf40883e66220/packages/zod/src/v4/core/function.ts#L48\n if (\"def\" in schema && typeof schema.def !== \"object\" && schema.def) {\n if ((schema.def as { type: string })?.type === \"function\") {\n return true;\n }\n }\n\n // We're casting as string here because zod 4.0 types don't include \"function\"\n // literal in the union for `_zod.def.type`. The optional chaining is because\n // _zod does not exist on zod 4 objects from zod 3.\n return (schema._zod?.def?.type as string) === \"function\";\n}\n\n/**\n * Checks if a schema is a Zod function schema (Zod 3 or Zod 4).\n * @param schema - The schema to check\n * @returns True if the schema is a Zod function schema\n */\nexport function isZodFunctionSchema(schema: unknown) {\n return isZod3FunctionSchema(schema) || isZod4FunctionSchema(schema);\n}\n\n/**\n * Extracts the args schema from a Zod function schema.\n * @param schema - The Zod function schema\n * @returns The args schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionArgs(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.args;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4.0\n return schema?.def?.input ?? schema._zod?.def?.input;\n }\n\n throw new Error(\"Unable to determine parameters from zod function schema\");\n}\n\n/**\n * Extracts the return schema from a Zod 3 or Zod 4 function schema.\n * @param schema - The Zod function schema\n * @returns The return schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionReturns(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.returns;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4\n return schema._zod.def.output;\n }\n\n throw new Error(\"Unable to determine return type from zod function schema\");\n}\n\n/**\n * Handles conversion of Zod schemas to JSON Schema.\n * Supports both Zod 3 (via zod-to-json-schema) and Zod 4 (native).\n * @param schema - The Zod schema to convert\n * @returns The JSON Schema representation\n */\nexport function handleZodSchemaToJson(schema: unknown) {\n // If Zod4 schema detected, use the toJSONSchema function from \"zod/v4/core\"\n if (isZod4Schema(schema))\n return zod4ToJSONSchema(schema, { reused: \"inline\" });\n\n try {\n // Dynamic require for optional peer dependency\n // eslint-disable-next-line @typescript-eslint/no-require-imports -- need require because zod-to-json-schema may be missing\n const { zodToJsonSchema } = require(\"zod-to-json-schema\");\n return zodToJsonSchema(schema, { $refStrategy: \"none\" });\n } catch (error) {\n throw new Error(\n \"Zod 3 requires 'zod-to-json-schema' package for JSON Schema conversion. \" +\n \"Install it with: npm install zod-to-json-schema\",\n {\n cause: error,\n },\n );\n }\n}\n\n/**\n * Checks if a schema is probably a Zod 3 schema.\n * @param schema - The schema to check\n * @returns True if the schema looks like a Zod 3 schema\n */\nexport function isZod3Schema(schema: unknown): schema is ZodType {\n return isZodSchema(schema) && \"_def\" in schema && !(\"def\" in schema);\n}\n\n/**\n * Detects if a schema is Zod 4 by checking for def.type property.\n * Zod 4 uses `def.type` with lowercase type names like \"object\", \"string\".\n * @returns True if the schema appears to be Zod 4 style\n */\nexport function isZod4Schema(schema: unknown): schema is $ZodType {\n return isZodSchema(schema) && \"_zod\" in schema;\n}\n\n/**\n * Checks if a schema is a Zod schema\n * @param schema - The schema to check\n * @returns True if the schema is a Zod schema\n */\nexport function isZodSchema(schema: unknown): schema is ZodType | $ZodType {\n // schema must be { ~standard: { vendor: \"zod\" } }\n if (typeof schema !== \"object\") return false;\n if (!schema) return false;\n if (!(\"~standard\" in schema)) return false;\n if (!schema[\"~standard\"]) return false;\n if (typeof schema[\"~standard\"] !== \"object\") return false;\n if (!(\"vendor\" in schema[\"~standard\"])) return false;\n if (schema[\"~standard\"].vendor !== \"zod\") return false;\n\n // Require at least one internal marker to reduce false positives\n const looksLikeV3 = \"_def\" in schema;\n const looksLikeV4 = \"_zod\" in schema || \"def\" in schema;\n return looksLikeV3 || looksLikeV4;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=zod.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod.test.d.ts","sourceRoot":"","sources":["../../src/schema/zod.test.ts"],"names":[],"mappings":""}