@tambo-ai/react 0.66.1 → 0.66.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/dist/hooks/use-current-message.d.ts +2 -0
- package/dist/hooks/use-current-message.d.ts.map +1 -1
- package/dist/hooks/use-current-message.js +1 -0
- package/dist/hooks/use-current-message.js.map +1 -1
- package/dist/hooks/use-current-message.test.js +5 -0
- package/dist/hooks/use-current-message.test.js.map +1 -1
- package/dist/model/component-metadata.d.ts +2 -2
- package/dist/model/component-metadata.d.ts.map +1 -1
- package/dist/model/component-metadata.js.map +1 -1
- package/dist/providers/tambo-interactable-provider-partial-updates.test.js +87 -87
- package/dist/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/dist/providers/tambo-interactable-provider.js +46 -40
- package/dist/providers/tambo-interactable-provider.js.map +1 -1
- package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js +8 -8
- package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
- package/dist/providers/tambo-interactables-additional-context.test.js +10 -10
- package/dist/providers/tambo-interactables-additional-context.test.js.map +1 -1
- package/dist/providers/tambo-registry-provider.test.js +28 -18
- package/dist/providers/tambo-registry-provider.test.js.map +1 -1
- package/dist/providers/tambo-registry-schema-compat.test.js +57 -28
- package/dist/providers/tambo-registry-schema-compat.test.js.map +1 -1
- package/dist/providers/tambo-thread-provider.test.js +21 -19
- package/dist/providers/tambo-thread-provider.test.js.map +1 -1
- package/dist/schema/alias.d.ts +3 -0
- package/dist/schema/alias.d.ts.map +1 -0
- package/dist/schema/alias.js +6 -0
- package/dist/schema/alias.js.map +1 -0
- package/dist/schema/json-schema.js +29 -29
- package/dist/schema/json-schema.js.map +1 -1
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/schema.js +20 -9
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/schema.test.js +291 -3
- package/dist/schema/schema.test.js.map +1 -1
- package/dist/schema/standard-schema.js +8 -8
- package/dist/schema/standard-schema.js.map +1 -1
- package/dist/schema/validate.test.js +31 -31
- package/dist/schema/validate.test.js.map +1 -1
- package/dist/schema/zod.d.ts +1 -1
- package/dist/schema/zod.d.ts.map +1 -1
- package/dist/schema/zod.js +25 -24
- package/dist/schema/zod.js.map +1 -1
- package/dist/util/registry-validators.d.ts.map +1 -1
- package/dist/util/registry-validators.js +40 -0
- package/dist/util/registry-validators.js.map +1 -1
- package/dist/util/registry-validators.test.js +69 -0
- package/dist/util/registry-validators.test.js.map +1 -1
- package/dist/util/registry.d.ts +1 -5
- package/dist/util/registry.d.ts.map +1 -1
- package/dist/util/registry.js +1 -5
- package/dist/util/registry.js.map +1 -1
- package/dist/util/registry.test.js +80 -67
- package/dist/util/registry.test.js.map +1 -1
- package/esm/hooks/use-current-message.d.ts +2 -0
- package/esm/hooks/use-current-message.d.ts.map +1 -1
- package/esm/hooks/use-current-message.js +1 -0
- package/esm/hooks/use-current-message.js.map +1 -1
- package/esm/hooks/use-current-message.test.js +5 -0
- package/esm/hooks/use-current-message.test.js.map +1 -1
- package/esm/model/component-metadata.d.ts +2 -2
- package/esm/model/component-metadata.d.ts.map +1 -1
- package/esm/model/component-metadata.js.map +1 -1
- package/esm/providers/tambo-interactable-provider-partial-updates.test.js +1 -1
- package/esm/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/esm/providers/tambo-interactable-provider.js +17 -11
- package/esm/providers/tambo-interactable-provider.js.map +1 -1
- package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js +1 -1
- package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
- package/esm/providers/tambo-interactables-additional-context.test.js +1 -1
- package/esm/providers/tambo-interactables-additional-context.test.js.map +1 -1
- package/esm/providers/tambo-registry-provider.test.js +16 -6
- package/esm/providers/tambo-registry-provider.test.js.map +1 -1
- package/esm/providers/tambo-registry-schema-compat.test.js +57 -28
- package/esm/providers/tambo-registry-schema-compat.test.js.map +1 -1
- package/esm/providers/tambo-thread-provider.test.js +8 -6
- package/esm/providers/tambo-thread-provider.test.js.map +1 -1
- package/esm/schema/alias.d.ts +3 -0
- package/esm/schema/alias.d.ts.map +1 -0
- package/esm/schema/alias.js +13 -0
- package/esm/schema/alias.js.map +1 -0
- package/esm/schema/json-schema.js +1 -1
- package/esm/schema/json-schema.js.map +1 -1
- package/esm/schema/schema.d.ts.map +1 -1
- package/esm/schema/schema.js +20 -9
- package/esm/schema/schema.js.map +1 -1
- package/esm/schema/schema.test.js +258 -3
- package/esm/schema/schema.test.js.map +1 -1
- package/esm/schema/standard-schema.js +1 -1
- package/esm/schema/standard-schema.js.map +1 -1
- package/esm/schema/validate.test.js +1 -1
- package/esm/schema/validate.test.js.map +1 -1
- package/esm/schema/zod.d.ts +1 -1
- package/esm/schema/zod.d.ts.map +1 -1
- package/esm/schema/zod.js +25 -24
- package/esm/schema/zod.js.map +1 -1
- package/esm/util/registry-validators.d.ts.map +1 -1
- package/esm/util/registry-validators.js +40 -0
- package/esm/util/registry-validators.js.map +1 -1
- package/esm/util/registry-validators.test.js +69 -0
- package/esm/util/registry-validators.test.js.map +1 -1
- package/esm/util/registry.d.ts +1 -5
- package/esm/util/registry.d.ts.map +1 -1
- package/esm/util/registry.js +1 -5
- package/esm/util/registry.js.map +1 -1
- package/esm/util/registry.test.js +80 -67
- package/esm/util/registry.test.js.map +1 -1
- package/package.json +1 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard-schema.js","sourceRoot":"","sources":["../../src/schema/standard-schema.ts"],"names":[],"mappings":";;AAkCA,4CAEC;AAnCD,
|
|
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
|
|
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 =
|
|
8
|
-
name:
|
|
9
|
-
age:
|
|
10
|
-
tags:
|
|
11
|
-
address:
|
|
12
|
-
street:
|
|
13
|
-
city:
|
|
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 =
|
|
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 =
|
|
24
|
-
name:
|
|
25
|
-
metadata:
|
|
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 =
|
|
31
|
-
items:
|
|
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 =
|
|
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 =
|
|
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 =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
type:
|
|
48
|
-
value:
|
|
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 =
|
|
55
|
-
optional:
|
|
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 =
|
|
61
|
-
nullable:
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
80
|
-
input: [
|
|
81
|
-
output:
|
|
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,MAAM,EAAE;gBAClB,IAAI,EAAE,oBAAC,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,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AAM,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,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AE;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"]}
|
package/dist/schema/zod.d.ts
CHANGED
|
@@ -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):
|
|
53
|
+
export declare function isZodSchema(schema: unknown): schema is ZodType | $ZodType;
|
|
54
54
|
//# sourceMappingURL=zod.d.ts.map
|
package/dist/schema/zod.d.ts.map
CHANGED
|
@@ -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;
|
|
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;AAErB;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,CAQjE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,YAAY,CAoB5E;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,iKAElD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,yEAWjD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,OAWpD;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,OAkBpD;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"}
|
package/dist/schema/zod.js
CHANGED
|
@@ -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 (!
|
|
17
|
+
if (!isZodSchema(schema))
|
|
19
18
|
return false;
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
@@ -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
|
|
112
|
+
return isZodSchema(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
|
|
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
|
-
|
|
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
|
package/dist/schema/zod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":";;
|
|
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,sDAkBC;AAOD,oCAEC;AAOD,oCAEC;AAOD,kCAcC;AA1JD,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;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CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,IAAI,OAAO,MAAM,CAAC,WAAW,CAAC,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC1D,IAAI,CAAC,CAAC,QAAQ,IAAI,MAAM,CAAC,WAAW,CAAC,CAAC;QAAE,OAAO,KAAK,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)) 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/**\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;\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry-validators.d.ts","sourceRoot":"","sources":["../../src/util/registry-validators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registry-validators.d.ts","sourceRoot":"","sources":["../../src/util/registry-validators.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AAoDrC;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,uBAAuB,GAAG,IAAI,CAuB5E;AA0CD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,cAAc,GAAG;IACtE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC,CA6BA;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,OAAO,EACxB,UAAU,EAAE,OAAO,GAClB,IAAI,CAWN"}
|
|
@@ -6,6 +6,44 @@ exports.validateToolAssociation = validateToolAssociation;
|
|
|
6
6
|
const schema_1 = require("../schema");
|
|
7
7
|
const zod_1 = require("../schema/zod");
|
|
8
8
|
const validate_component_name_1 = require("./validate-component-name");
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a JSON Schema represents an object type.
|
|
11
|
+
* @param schema - The JSON Schema to check
|
|
12
|
+
* @returns True if the schema is an object type
|
|
13
|
+
*/
|
|
14
|
+
function isObjectSchema(schema) {
|
|
15
|
+
return schema.type === "object" || schema.properties !== undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Validates that a schema is an object type.
|
|
19
|
+
* Throws an error if it's not.
|
|
20
|
+
* @param schema - The schema to validate (Standard Schema or JSON Schema)
|
|
21
|
+
* @param context - Description of where the schema is used (for error messages)
|
|
22
|
+
*/
|
|
23
|
+
function assertObjectSchema(schema, context) {
|
|
24
|
+
let jsonSchema;
|
|
25
|
+
if ((0, schema_1.isStandardSchema)(schema)) {
|
|
26
|
+
try {
|
|
27
|
+
jsonSchema = (0, schema_1.schemaToJsonSchema)(schema);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// If conversion fails, we can't validate - let it fail later
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if ((0, schema_1.looksLikeJSONSchema)(schema)) {
|
|
35
|
+
jsonSchema = schema;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// Unknown schema type, can't validate
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (!isObjectSchema(jsonSchema)) {
|
|
42
|
+
throw new Error(`${context} must be an object schema (e.g., z.object({...})). ` +
|
|
43
|
+
`Received type: "${jsonSchema.type ?? "unknown"}". ` +
|
|
44
|
+
`Tool parameters are passed as a single object argument.`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
9
47
|
/**
|
|
10
48
|
* Validates a tool before registration.
|
|
11
49
|
* Throws an error if the tool is invalid.
|
|
@@ -17,6 +55,8 @@ function validateTool(tool) {
|
|
|
17
55
|
// Validate tool schemas
|
|
18
56
|
// 1. check inputSchema
|
|
19
57
|
if ("inputSchema" in tool && tool.inputSchema) {
|
|
58
|
+
// inputSchema must be an object schema
|
|
59
|
+
assertObjectSchema(tool.inputSchema, `inputSchema of tool "${tool.name}"`);
|
|
20
60
|
(0, schema_1.assertNoRecordSchema)(tool.inputSchema, `inputSchema of tool "${tool.name}"`);
|
|
21
61
|
}
|
|
22
62
|
// 2. check deprecated toolSchema
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry-validators.js","sourceRoot":"","sources":["../../src/util/registry-validators.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"registry-validators.js","sourceRoot":"","sources":["../../src/util/registry-validators.ts"],"names":[],"mappings":";;AA8DA,oCAuBC;AAgDD,kEA+BC;AAUD,0DAgBC;AAxLD,sCAMmB;AACnB,uCAAoD;AACpD,uEAA4D;AAE5D;;;;GAIG;AACH,SAAS,cAAc,CAAC,MAAmB;IACzC,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,CAAC;AACrE,CAAC;AAED;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,MAAe,EAAE,OAAe;IAC1D,IAAI,UAAuB,CAAC;IAE5B,IAAI,IAAA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,IAAI,WAAW,IAAI,eAAe,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACb,aAAa,IAAI,0GAA0G,CAC5H,CAAC;IACJ,CAAC;IAED,8DAA8D;IAC9D,IAAI,WAAW,EAAE,CAAC;QAChB,IAAA,6BAAoB,EAAC,WAAW,EAAE,6BAA6B,IAAI,GAAG,CAAC,CAAC;IAC1E,CAAC;IAED,kDAAkD;IAClD,MAAM,KAAK,GAAG,kBAAkB,CAAC,eAAe,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;IAErE,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,uBAAuB,CACrC,aAAqB,EACrB,QAAgB,EAChB,eAAwB,EACxB,UAAmB;IAEnB,oCAAoC;IACpC,IAAA,yCAAe,EAAC,aAAa,EAAE,WAAW,CAAC,CAAC;IAC5C,IAAA,yCAAe,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAElC,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,aAAa,aAAa,wBAAwB,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,wBAAwB,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC","sourcesContent":["import type { JSONSchema7 } from \"json-schema\";\nimport type {\n TamboComponent,\n TamboTool,\n TamboToolWithToolSchema,\n} from \"../model/component-metadata\";\nimport {\n assertNoRecordSchema,\n getZodFunctionArgs,\n isStandardSchema,\n looksLikeJSONSchema,\n schemaToJsonSchema,\n} from \"../schema\";\nimport { isZodFunctionSchema } from \"../schema/zod\";\nimport { assertValidName } from \"./validate-component-name\";\n\n/**\n * Checks if a JSON Schema represents an object type.\n * @param schema - The JSON Schema to check\n * @returns True if the schema is an object type\n */\nfunction isObjectSchema(schema: JSONSchema7): boolean {\n return schema.type === \"object\" || schema.properties !== undefined;\n}\n\n/**\n * Validates that a schema is an object type.\n * Throws an error if it's not.\n * @param schema - The schema to validate (Standard Schema or JSON Schema)\n * @param context - Description of where the schema is used (for error messages)\n */\nfunction assertObjectSchema(schema: unknown, context: string): void {\n let jsonSchema: JSONSchema7;\n\n if (isStandardSchema(schema)) {\n try {\n jsonSchema = schemaToJsonSchema(schema);\n } catch {\n // If conversion fails, we can't validate - let it fail later\n return;\n }\n } else if (looksLikeJSONSchema(schema)) {\n jsonSchema = schema;\n } else {\n // Unknown schema type, can't validate\n return;\n }\n\n if (!isObjectSchema(jsonSchema)) {\n throw new Error(\n `${context} must be an object schema (e.g., z.object({...})). ` +\n `Received type: \"${jsonSchema.type ?? \"unknown\"}\". ` +\n `Tool parameters are passed as a single object argument.`,\n );\n }\n}\n\n/**\n * Validates a tool before registration.\n * Throws an error if the tool is invalid.\n * @param tool - The tool to validate\n */\nexport function validateTool(tool: TamboTool | TamboToolWithToolSchema): void {\n // Validate tool name\n assertValidName(tool.name, \"tool\");\n\n // Validate tool schemas\n // 1. check inputSchema\n if (\"inputSchema\" in tool && tool.inputSchema) {\n // inputSchema must be an object schema\n assertObjectSchema(tool.inputSchema, `inputSchema of tool \"${tool.name}\"`);\n assertNoRecordSchema(\n tool.inputSchema,\n `inputSchema of tool \"${tool.name}\"`,\n );\n }\n // 2. check deprecated toolSchema\n else if (\"toolSchema\" in tool && tool.toolSchema) {\n let inputSchema = tool.toolSchema;\n // toolSchema may sometimes be a zod function schema, extract args if so\n if (isZodFunctionSchema(tool.toolSchema)) {\n inputSchema = getZodFunctionArgs(tool.toolSchema);\n }\n assertNoRecordSchema(inputSchema, `toolSchema of tool \"${tool.name}\"`);\n }\n}\n\n/**\n * Converts a props schema to a serialized JSON Schema format.\n * @param propsDefinition - Deprecated: legacy props definition (will log warning)\n * @param propsSchema - The props schema (Standard Schema or JSON Schema)\n * @param name - Component/tool name for error messages\n * @returns Serialized JSON Schema object\n */\nfunction getSerializedProps(\n propsDefinition: unknown,\n propsSchema: unknown,\n name: string,\n): Record<string, unknown> {\n if (propsDefinition) {\n console.warn(`propsDefinition is deprecated. Use propsSchema instead.`);\n return propsDefinition as Record<string, unknown>;\n }\n\n // Check for Standard Schema (Zod, Valibot, ArkType, etc.)\n if (isStandardSchema(propsSchema)) {\n try {\n return schemaToJsonSchema(propsSchema) as Record<string, unknown>;\n } catch (error) {\n console.error(\n `Error converting ${name} props schema to JSON Schema:`,\n error,\n );\n throw new Error(\n `Error converting ${name} props schema to JSON Schema: ${error}`,\n );\n }\n }\n\n // Check for JSON Schema\n if (looksLikeJSONSchema(propsSchema)) {\n return propsSchema as Record<string, unknown>;\n }\n\n throw new Error(`Invalid props schema for ${name}`);\n}\n\n/**\n * Validates a component and prepares its props for registration.\n * Throws an error if the component is invalid.\n * @param component - The component to validate and prepare\n * @returns Object containing the serialized props\n */\nexport function validateAndPrepareComponent(component: TamboComponent): {\n props: Record<string, unknown>;\n} {\n const { name, propsSchema, propsDefinition } = component;\n\n // Validate component name\n assertValidName(name, \"component\");\n\n // Validate that at least one props definition is provided\n if (!propsSchema && !propsDefinition) {\n throw new Error(\n `Component ${name} must have either propsSchema (recommended) or propsDefinition defined`,\n );\n }\n\n // Validate that only one props definition is provided\n if (propsSchema && propsDefinition) {\n throw new Error(\n `Component ${name} cannot have both propsSchema and propsDefinition defined. Use only one. We recommend using propsSchema.`,\n );\n }\n\n // Validate that the propsSchema does not include record types\n if (propsSchema) {\n assertNoRecordSchema(propsSchema, `propsSchema of component \"${name}\"`);\n }\n\n // Convert propsSchema to JSON Schema if it exists\n const props = getSerializedProps(propsDefinition, propsSchema, name);\n\n return { props };\n}\n\n/**\n * Validates a tool association between a component and tool.\n * Throws an error if the association is invalid.\n * @param componentName - The component name\n * @param toolName - The tool name\n * @param componentExists - Whether the component exists in the registry\n * @param toolExists - Whether the tool exists in the registry\n */\nexport function validateToolAssociation(\n componentName: string,\n toolName: string,\n componentExists: boolean,\n toolExists: boolean,\n): void {\n // Validate component and tool names\n assertValidName(componentName, \"component\");\n assertValidName(toolName, \"tool\");\n\n if (!componentExists) {\n throw new Error(`Component ${componentName} not found in registry`);\n }\n if (!toolExists) {\n throw new Error(`Tool ${toolName} not found in registry`);\n }\n}\n"]}
|
|
@@ -79,6 +79,75 @@ describe("validateTool", () => {
|
|
|
79
79
|
};
|
|
80
80
|
expect(() => (0, registry_validators_1.validateTool)(tool)).not.toThrow();
|
|
81
81
|
});
|
|
82
|
+
it("should throw when inputSchema is not an object schema (string)", () => {
|
|
83
|
+
const tool = {
|
|
84
|
+
name: "tool-with-string-schema",
|
|
85
|
+
description: "A tool with invalid schema",
|
|
86
|
+
tool: () => "result",
|
|
87
|
+
inputSchema: v3_1.z.string(),
|
|
88
|
+
outputSchema: v3_1.z.string(),
|
|
89
|
+
};
|
|
90
|
+
expect(() => (0, registry_validators_1.validateTool)(tool)).toThrow('inputSchema of tool "tool-with-string-schema" must be an object schema');
|
|
91
|
+
});
|
|
92
|
+
it("should throw when inputSchema is not an object schema (number)", () => {
|
|
93
|
+
const tool = {
|
|
94
|
+
name: "tool-with-number-schema",
|
|
95
|
+
description: "A tool with invalid schema",
|
|
96
|
+
tool: () => "result",
|
|
97
|
+
inputSchema: v3_1.z.number(),
|
|
98
|
+
outputSchema: v3_1.z.string(),
|
|
99
|
+
};
|
|
100
|
+
expect(() => (0, registry_validators_1.validateTool)(tool)).toThrow('inputSchema of tool "tool-with-number-schema" must be an object schema');
|
|
101
|
+
});
|
|
102
|
+
it("should throw when inputSchema is not an object schema (array)", () => {
|
|
103
|
+
const tool = {
|
|
104
|
+
name: "tool-with-array-schema",
|
|
105
|
+
description: "A tool with invalid schema",
|
|
106
|
+
tool: () => "result",
|
|
107
|
+
inputSchema: v3_1.z.array(v3_1.z.string()),
|
|
108
|
+
outputSchema: v3_1.z.string(),
|
|
109
|
+
};
|
|
110
|
+
expect(() => (0, registry_validators_1.validateTool)(tool)).toThrow('inputSchema of tool "tool-with-array-schema" must be an object schema');
|
|
111
|
+
});
|
|
112
|
+
it("should throw when inputSchema JSON Schema is not an object type", () => {
|
|
113
|
+
const tool = {
|
|
114
|
+
name: "tool-with-json-string-schema",
|
|
115
|
+
description: "A tool with invalid JSON schema",
|
|
116
|
+
tool: () => "result",
|
|
117
|
+
inputSchema: { type: "string" },
|
|
118
|
+
outputSchema: { type: "string" },
|
|
119
|
+
};
|
|
120
|
+
expect(() => (0, registry_validators_1.validateTool)(tool)).toThrow('inputSchema of tool "tool-with-json-string-schema" must be an object schema');
|
|
121
|
+
});
|
|
122
|
+
it("should accept JSON Schema with object type", () => {
|
|
123
|
+
const tool = {
|
|
124
|
+
name: "tool-with-json-object-schema",
|
|
125
|
+
description: "A tool with valid JSON schema",
|
|
126
|
+
tool: () => "result",
|
|
127
|
+
inputSchema: {
|
|
128
|
+
type: "object",
|
|
129
|
+
properties: {
|
|
130
|
+
query: { type: "string" },
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
outputSchema: { type: "string" },
|
|
134
|
+
};
|
|
135
|
+
expect(() => (0, registry_validators_1.validateTool)(tool)).not.toThrow();
|
|
136
|
+
});
|
|
137
|
+
it("should accept JSON Schema with properties but no explicit type", () => {
|
|
138
|
+
const tool = {
|
|
139
|
+
name: "tool-with-implicit-object-schema",
|
|
140
|
+
description: "A tool with implicit object schema",
|
|
141
|
+
tool: () => "result",
|
|
142
|
+
inputSchema: {
|
|
143
|
+
properties: {
|
|
144
|
+
query: { type: "string" },
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
outputSchema: { type: "string" },
|
|
148
|
+
};
|
|
149
|
+
expect(() => (0, registry_validators_1.validateTool)(tool)).not.toThrow();
|
|
150
|
+
});
|
|
82
151
|
});
|
|
83
152
|
describe("validateAndPrepareComponent", () => {
|
|
84
153
|
it("should validate component with propsSchema", () => {
|