summaryrefslogtreecommitdiff
path: root/packages/cli/src/utils/schemaValidator.ts
diff options
context:
space:
mode:
authorEvan Senter <[email protected]>2025-04-19 19:45:42 +0100
committerGitHub <[email protected]>2025-04-19 19:45:42 +0100
commit3fce6cea27d3e6129d6c06e528b62e1b11bf7094 (patch)
tree244b8e9ab94f902d65d4bda8739a6538e377ed17 /packages/cli/src/utils/schemaValidator.ts
parent0c9e1ef61be7db53e6e73b7208b649cd8cbed6c3 (diff)
Starting to modularize into separate cli / server packages. (#55)
* Starting to move a lot of code into packages/server * More of the massive refactor, builds and runs, some issues though. * Fixing outstanding issue with double messages. * Fixing a minor UI issue. * Fixing the build post-merge. * Running formatting. * Addressing comments.
Diffstat (limited to 'packages/cli/src/utils/schemaValidator.ts')
-rw-r--r--packages/cli/src/utils/schemaValidator.ts59
1 files changed, 0 insertions, 59 deletions
diff --git a/packages/cli/src/utils/schemaValidator.ts b/packages/cli/src/utils/schemaValidator.ts
deleted file mode 100644
index 107ccc85..00000000
--- a/packages/cli/src/utils/schemaValidator.ts
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * @license
- * Copyright 2025 Google LLC
- * SPDX-License-Identifier: Apache-2.0
- */
-
-/**
- * Simple utility to validate objects against JSON Schemas
- * In a real implementation, you would use a library like Ajv
- */
-export class SchemaValidator {
- /**
- * Validates data against a JSON schema
- * @param schema JSON Schema to validate against
- * @param data Data to validate
- * @returns True if valid, false otherwise
- */
- static validate(schema: Record<string, unknown>, data: unknown): boolean {
- // This is a simplified implementation
- // In a real application, you would use a library like Ajv for proper validation
-
- // Check for required fields
- if (schema.required && Array.isArray(schema.required)) {
- const required = schema.required as string[];
- const dataObj = data as Record<string, unknown>;
-
- for (const field of required) {
- if (dataObj[field] === undefined) {
- console.error(`Missing required field: ${field}`);
- return false;
- }
- }
- }
-
- // Check property types if properties are defined
- if (schema.properties && typeof schema.properties === 'object') {
- const properties = schema.properties as Record<string, { type?: string }>;
- const dataObj = data as Record<string, unknown>;
-
- for (const [key, prop] of Object.entries(properties)) {
- if (dataObj[key] !== undefined && prop.type) {
- const expectedType = prop.type;
- const actualType = Array.isArray(dataObj[key])
- ? 'array'
- : typeof dataObj[key];
-
- if (expectedType !== actualType) {
- console.error(
- `Type mismatch for property "${key}": expected ${expectedType}, got ${actualType}`,
- );
- return false;
- }
- }
- }
- }
-
- return true;
- }
-}