From c137df512d41cfce5bc251d7089f1a2b8b3bd03f Mon Sep 17 00:00:00 2001 From: Joan Xie Date: Sat, 1 Nov 2025 19:44:19 -0700 Subject: [PATCH] Remove validate utilities from browser exports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This removes the validateManifest utilities that were added to the browser bundle. These functions are not needed for the browser export. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/browser.ts | 1 - src/schemas/validate.ts | 100 ---------------------------------------- 2 files changed, 101 deletions(-) delete mode 100644 src/schemas/validate.ts diff --git a/src/browser.ts b/src/browser.ts index fcf4e14..71c124f 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -1,5 +1,4 @@ // Browser-compatible exports export * from "./schemas/index.js"; -export * from "./schemas/validate.js"; export * from "./shared/config.js"; export * from "./types.js"; diff --git a/src/schemas/validate.ts b/src/schemas/validate.ts deleted file mode 100644 index 89063f7..0000000 --- a/src/schemas/validate.ts +++ /dev/null @@ -1,100 +0,0 @@ -import type * as z from "zod"; - -import * as v0_1 from "./0.1.js"; -import * as v0_2 from "./0.2.js"; -import * as v0_3 from "./0.3.js"; - -type McpbManifestV0_1 = z.infer; -type McpbManifestV0_2 = z.infer; -type McpbManifestV0_3 = z.infer; - -/** - * Union type representing any supported manifest version. - * This is the return type of validateManifest. - */ -type ValidatedManifest = McpbManifestV0_1 | McpbManifestV0_2 | McpbManifestV0_3; - -/** - * Validates a manifest using the appropriate schema based on its manifest_version. - * - * This function automatically detects the manifest version from the data and applies - * the correct schema. This avoids TypeScript "excessively deep" errors that can occur - * when using union schemas across package boundaries. - * - * @param data - The manifest data to validate - * @returns The validated manifest with the correct type - * @throws ZodError if validation fails - * - * @example - * ```typescript - * import { validateManifest } from '@anthropic-ai/mcpb/browser'; - * - * const manifest = validateManifest(unknownData); - * // manifest is typed as McpbManifestAny (union of all versions) - * ``` - */ -export function validateManifest(data: unknown): ValidatedManifest { - // Read manifest_version or dxt_version from data - const version = (data as any)?.manifest_version || (data as any)?.dxt_version; - - // Use appropriate schema based on version - if (version === "0.1") { - return v0_1.McpbManifestSchema.parse(data); - } - - if (version === "0.2") { - return v0_2.McpbManifestSchema.parse(data); - } - - // Default to latest version (0.3) if not specified or if version is "0.3" - return v0_3.McpbManifestSchema.parse(data); -} - -/** - * Validates a manifest using the appropriate schema, returning a Result-style object. - * - * @param data - The manifest data to validate - * @returns An object with either { success: true, data } or { success: false, error } - * - * @example - * ```typescript - * import { validateManifestSafe } from '@anthropic-ai/mcpb/browser'; - * - * const result = validateManifestSafe(unknownData); - * if (result.success) { - * console.log(result.data); - * } else { - * console.error(result.error); - * } - * ``` - */ -export function validateManifestSafe(data: unknown): - | { success: true; data: ValidatedManifest } - | { success: false; error: unknown } { - try { - return { success: true, data: validateManifest(data) }; - } catch (error) { - return { success: false, error }; - } -} - -/** - * Get the appropriate schema for a given manifest version. - * Useful when you need to work with the schema directly. - * - * @param version - The manifest version (e.g., "0.1", "0.2", "0.3") - * @returns The schema for that version - * - * @example - * ```typescript - * import { getSchemaForVersion } from '@anthropic-ai/mcpb/browser'; - * - * const schema = getSchemaForVersion("0.2"); - * const result = schema.safeParse(data); - * ``` - */ -export function getSchemaForVersion(version: "0.1" | "0.2" | "0.3") { - if (version === "0.1") return v0_1.McpbManifestSchema; - if (version === "0.2") return v0_2.McpbManifestSchema; - return v0_3.McpbManifestSchema; -}