spmallette commented on code in PR #3238:
URL: https://github.com/apache/tinkerpop/pull/3238#discussion_r2437149592


##########
gremlin-mcp/src/main/javascript/src/gremlin/schema-assembly.ts:
##########
@@ -0,0 +1,287 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+/**
+ * @fileoverview Schema assembly and validation utilities.
+ *
+ * Handles the final assembly of graph schema data from analyzed components,
+ * validation against schema definitions, and metadata generation.
+ */
+
+import { Effect } from 'effect';
+import {
+  GraphSchemaSchema,
+  type GraphSchema,
+  type Vertex,
+  type Edge,
+  type EdgePattern,
+} from './models/index.js';
+import { Errors, type GremlinQueryError } from '../errors.js';
+import type { SchemaConfig } from './types.js';
+
+/**
+ * Schema metadata for tracking generation performance and settings.
+ */
+export interface SchemaMetadata {
+  generated_at: string;
+  generation_time_ms: number;
+  vertex_count: number;
+  edge_count: number;
+  pattern_count: number;
+  optimization_settings: {
+    sample_values_included: boolean;
+    max_enum_values: number;
+    counts_included: boolean;
+    enum_cardinality_threshold: number;
+    timeout_ms: number;
+    batch_size: number;
+  };
+}
+
+/**
+ * Assembles and validates the final graph schema from analyzed components.
+ *
+ * @param vertices - Analyzed vertex types
+ * @param edges - Analyzed edges
+ * @param patterns - Edge patterns
+ * @param config - Schema generation configuration
+ * @param startTime - Generation start timestamp for performance metrics
+ * @returns Effect with validated graph schema
+ */
+export const assembleGraphSchema = (
+  vertices: Vertex[],
+  edges: Edge[],
+  patterns: EdgePattern[],
+  config: SchemaConfig,
+  startTime: number
+): Effect.Effect<GraphSchema, GremlinQueryError> =>
+  Effect.gen(function* () {
+    // Create metadata
+    const metadata = createSchemaMetadata(vertices, edges, patterns, config, 
startTime);
+
+    // Assemble schema data
+    const schemaData = {
+      vertices,
+      edges,
+      edge_patterns: patterns,
+      metadata,
+    };
+
+    yield* Effect.logDebug('Schema assembly completed', {
+      vertexCount: vertices.length,
+      edgeCount: edges.length,
+      patternCount: patterns.length,
+      generationTimeMs: metadata.generation_time_ms,
+    });
+
+    // Validate against schema
+    return yield* validateSchemaData(schemaData);
+  });
+
+/**
+ * Creates schema metadata with generation statistics and configuration.
+ *
+ * @param vertices - Analyzed vertices
+ * @param relationships - Analyzed relationships
+ * @param patterns - Relationship patterns
+ * @param config - Configuration used for generation
+ * @param startTime - Start timestamp
+ * @returns Schema metadata object
+ */
+const createSchemaMetadata = (
+  vertices: Vertex[],
+  edges: Edge[],
+  patterns: EdgePattern[],
+  config: SchemaConfig,
+  startTime: number
+): SchemaMetadata => ({
+  generated_at: new Date().toISOString(),
+  generation_time_ms: Date.now() - startTime,
+  vertex_count: vertices.length,
+  edge_count: edges.length,
+  pattern_count: patterns.length,
+  optimization_settings: {
+    sample_values_included: config.includeSampleValues,
+    max_enum_values: config.maxEnumValues,
+    counts_included: config.includeCounts,
+    enum_cardinality_threshold: config.enumCardinalityThreshold,
+    timeout_ms: config.timeoutMs || 30000,
+    batch_size: config.batchSize || 10,

Review Comment:
   timeouts are a mess: https://issues.apache.org/jira/browse/TINKERPOP-3203



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to