@@ -7,6 +7,30 @@ import type {
77 PrimitiveSchemaType ,
88 ConstantSchemaType ,
99} from 'mongodb-schema' ;
10+ import type { FieldInfo } from './schema-analysis-types' ;
11+
12+ /**
13+ * This module transforms mongodb-schema output into a flat, LLM-friendly format using
14+ * dot notation for nested fields and bracket notation for arrays.
15+ *
16+ * Algorithm Overview:
17+ * - Start with top-level fields.
18+ * - For each field (processNamedField), process based on type (processType):
19+ * - Primitives: Create result entry
20+ * - Documents: Add parent field name to path using dot notation, recurse into nested fields (processNamedField)
21+ * - Arrays: Add [] to path, recurse into element type (processType)
22+ *
23+ * Notation examples:
24+ * - Nested documents: user.profile.name (dot notation)
25+ * - Array: users[] (bracket notation)
26+ * - Nested arrays: matrix[][] (multiple brackets)
27+ * - Nested array of documents fields: users[].name (brackets + dots)
28+ */
29+
30+ /**
31+ * Maximum number of sample values to include for each field
32+ */
33+ const MAX_SAMPLE_VALUES = 10 ;
1034
1135// Type guards for mongodb-schema types
1236function isConstantSchemaType ( type : SchemaType ) : type is ConstantSchemaType {
@@ -28,25 +52,6 @@ function isPrimitiveSchemaType(type: SchemaType): type is PrimitiveSchemaType {
2852 ! isDocumentSchemaType ( type )
2953 ) ;
3054}
31- import type { FieldInfo } from './schema-analysis-types' ;
32-
33- /**
34- * This module transforms mongodb-schema output into a flat, LLM-friendly format using
35- * dot notation for nested fields and bracket notation for arrays.
36- *
37- * Algorithm Overview:
38- * - Start with top-level fields.
39- * - For each field (processNamedField), process based on type (processType):
40- * - Primitives: Create result entry
41- * - Documents: Add parent field name to path using dot notation, recurse into nested fields (processNamedField)
42- * - Arrays: Add [] to path, recurse into element type (processType)
43- *
44- * Notation examples:
45- * - Nested documents: user.profile.name (dot notation)
46- * - Array: users[] (bracket notation)
47- * - Nested arrays: matrix[][] (multiple brackets)
48- * - Nested array of documents fields: users[].name (brackets + dots)
49- */
5055
5156/**
5257 * Transforms a raw mongodb-schema Schema into a flat Record<string, FieldInfo>
@@ -125,7 +130,7 @@ function processType(
125130 // Primitive: Create entry
126131 const fieldInfo : FieldInfo = {
127132 type : type . name ,
128- sample_values : type . values . slice ( 0 , 10 ) . map ( ( value ) => {
133+ sample_values : type . values . slice ( 0 , MAX_SAMPLE_VALUES ) . map ( ( value ) => {
129134 // Convert BSON values to their primitive equivalents, but keep Date objects as-is
130135 if ( value instanceof Date ) {
131136 return value ;
0 commit comments