catelog 1.0.0 → 1.0.1
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/schema.d.ts +4 -4
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +46 -20
- package/dist/schema.js.map +1 -1
- package/package.json +4 -2
package/dist/schema.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ZodTypeAny } from "zod";
|
|
2
|
-
export type SchemaLike = ZodTypeAny | Record<string, unknown
|
|
3
|
-
export declare function isZodSchema(schema: unknown):
|
|
2
|
+
export type SchemaLike = ZodTypeAny | Record<string, unknown> | any;
|
|
3
|
+
export declare function isZodSchema(schema: unknown): boolean;
|
|
4
4
|
/**
|
|
5
|
-
* Converts a Zod schema or passes through a JSON schema object
|
|
6
|
-
* to standard JSON Schema
|
|
5
|
+
* Converts a Zod schema (v3 or v4) or passes through a JSON schema object
|
|
6
|
+
* to standard JSON Schema.
|
|
7
7
|
*/
|
|
8
8
|
export declare function toJsonSchema(schema: SchemaLike, title?: string): Record<string, unknown>;
|
|
9
9
|
/**
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAEtC,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAEtC,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,GAAG,CAAC;AAEpE,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAOpD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAgDxF;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,OAAO,GACZ;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAcnE"}
|
package/dist/schema.js
CHANGED
|
@@ -2,33 +2,59 @@ import { zodToJsonSchema } from "zod-to-json-schema";
|
|
|
2
2
|
export function isZodSchema(schema) {
|
|
3
3
|
return (typeof schema === "object" &&
|
|
4
4
|
schema !== null &&
|
|
5
|
-
"_def" in schema &&
|
|
6
|
-
typeof schema.safeParse === "function");
|
|
5
|
+
(("_def" in schema) || ("def" in schema) || ("_zod" in schema)) &&
|
|
6
|
+
(typeof schema.safeParse === "function" || typeof schema.parse === "function"));
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
* Converts a Zod schema or passes through a JSON schema object
|
|
10
|
-
* to standard JSON Schema
|
|
9
|
+
* Converts a Zod schema (v3 or v4) or passes through a JSON schema object
|
|
10
|
+
* to standard JSON Schema.
|
|
11
11
|
*/
|
|
12
12
|
export function toJsonSchema(schema, title) {
|
|
13
|
+
if (!schema)
|
|
14
|
+
return { type: "object" };
|
|
15
|
+
// 1. Zod v4 native toJSONSchema() support
|
|
16
|
+
if (typeof schema.toJSONSchema === "function") {
|
|
17
|
+
try {
|
|
18
|
+
const nativeJson = schema.toJSONSchema();
|
|
19
|
+
if (nativeJson && typeof nativeJson === "object") {
|
|
20
|
+
return nativeJson;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
console.warn("[catelog] Native toJSONSchema failed, falling back to converter:", err);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// 2. Zod v3 conversion via zod-to-json-schema
|
|
13
28
|
if (isZodSchema(schema)) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
try {
|
|
30
|
+
const converted = zodToJsonSchema(schema, {
|
|
31
|
+
target: "jsonSchema7",
|
|
32
|
+
$refStrategy: "none",
|
|
33
|
+
});
|
|
34
|
+
if (converted && typeof converted === "object") {
|
|
35
|
+
if (converted.definitions && typeof converted.definitions === "object") {
|
|
36
|
+
const keys = Object.keys(converted.definitions);
|
|
37
|
+
if (keys.length > 0) {
|
|
38
|
+
return {
|
|
39
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
40
|
+
...converted.definitions[keys[0]],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (converted.properties || converted.type) {
|
|
45
|
+
return converted;
|
|
46
|
+
}
|
|
25
47
|
}
|
|
26
|
-
return record;
|
|
27
48
|
}
|
|
28
|
-
|
|
49
|
+
catch (err) {
|
|
50
|
+
console.error("[catelog] Failed to convert Zod schema to JSON Schema:", err);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// 3. Raw JSON schema object pass-through
|
|
54
|
+
if (typeof schema === "object") {
|
|
55
|
+
return schema;
|
|
29
56
|
}
|
|
30
|
-
|
|
31
|
-
return schema;
|
|
57
|
+
return { type: "object" };
|
|
32
58
|
}
|
|
33
59
|
/**
|
|
34
60
|
* Validates input against schema (if Zod is provided).
|
|
@@ -40,7 +66,7 @@ export function validateSchemaData(schema, data) {
|
|
|
40
66
|
if (result.success) {
|
|
41
67
|
return { success: true, data: result.data };
|
|
42
68
|
}
|
|
43
|
-
const formattedErrors = result.error
|
|
69
|
+
const formattedErrors = (result.error?.errors || []).map((err) => `${err.path?.join(".") || "root"}: ${err.message}`);
|
|
44
70
|
return { success: false, errors: formattedErrors };
|
|
45
71
|
}
|
|
46
72
|
// Raw JSON schema pass-through (pre-validated by gateway as per spec rule 4)
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAKrD,MAAM,UAAU,WAAW,CAAC,MAAe;IACzC,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,MAAM,IAAI,MAAM;
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAKrD,MAAM,UAAU,WAAW,CAAC,MAAe;IACzC,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC;QAC/D,CAAC,OAAQ,MAAc,CAAC,SAAS,KAAK,UAAU,IAAI,OAAQ,MAAc,CAAC,KAAK,KAAK,UAAU,CAAC,CACjG,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,MAAkB,EAAE,KAAc;IAC7D,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAEvC,0CAA0C;IAC1C,IAAI,OAAQ,MAAc,CAAC,YAAY,KAAK,UAAU,EAAE,CAAC;QACvD,IAAI,CAAC;YACH,MAAM,UAAU,GAAI,MAAc,CAAC,YAAY,EAAE,CAAC;YAClD,IAAI,UAAU,IAAI,OAAO,U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;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAkB,EAClB,IAAa;IAEb,IAAI,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;QACxB,MAAM,MAAM,GAAI,MAAc,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAS,EAAE,CAAC;QACnD,CAAC;QACD,MAAM,eAAe,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CACtD,CAAC,GAAQ,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,CACjE,CAAC;QACF,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;IACrD,CAAC;IAED,6EAA6E;IAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAS,EAAE,CAAC;AAC5C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "catelog",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Official TypeScript SDK for Marketplace Agent Protocol Specification (MAPS)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
7
8
|
"types": "./dist/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
11
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js"
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
12
14
|
}
|
|
13
15
|
},
|
|
14
16
|
"bin": {
|