Skip to content

Commit 03f3cd8

Browse files
committed
Types
1 parent f221923 commit 03f3cd8

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

packages/compass-collection/src/schema-analysis-types.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
import type { Document } from 'mongodb';
2+
import type { PrimitiveSchemaType } from 'mongodb-schema';
3+
import type {
4+
ObjectId,
5+
Binary,
6+
BSONRegExp,
7+
Code,
8+
Timestamp,
9+
MaxKey,
10+
MinKey,
11+
} from 'bson';
212

313
export const SCHEMA_ANALYSIS_STATE_INITIAL = 'initial';
414
export const SCHEMA_ANALYSIS_STATE_ANALYZING = 'analyzing';
@@ -29,9 +39,36 @@ export type SchemaAnalysisErrorState = {
2939
error: SchemaAnalysisError;
3040
};
3141

42+
/**
43+
* MongoDB schema type
44+
*/
45+
export type MongoDBFieldType = PrimitiveSchemaType['name'];
46+
47+
/**
48+
* Primitive values that can appear in sample_values after BSON-to-primitive conversion.
49+
* These are the JavaScript primitive equivalents of BSON values.
50+
*/
51+
export type SampleValue =
52+
| string
53+
| number
54+
| boolean
55+
| Date
56+
| ObjectId
57+
| Binary
58+
| BSONRegExp
59+
| Code
60+
| Timestamp
61+
| MaxKey
62+
| MinKey
63+
| null
64+
| undefined;
65+
66+
/**
67+
* Schema field information (for LLM processing)
68+
*/
3269
export interface FieldInfo {
33-
type: string; // MongoDB type (eg. String, Double, Array, Document)
34-
sample_values?: unknown[]; // Primitive sample values (flattened for arrays)
70+
type: MongoDBFieldType; // MongoDB primitive type
71+
sample_values?: SampleValue[]; // Primitive sample values (limited to 10)
3572
probability?: number; // 0.0 - 1.0 field frequency
3673
}
3774

packages/compass-collection/src/transform-schema-to-field-info.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
PrimitiveSchemaType,
88
ConstantSchemaType,
99
} from 'mongodb-schema';
10-
import type { FieldInfo } from './schema-analysis-types';
10+
import type { FieldInfo, SampleValue } from './schema-analysis-types';
1111

1212
/**
1313
* This module transforms mongodb-schema output into a flat, LLM-friendly format using
@@ -139,7 +139,7 @@ function processType(
139139
return value.valueOf();
140140
}
141141
return value;
142-
}),
142+
}) as SampleValue[],
143143
probability: fieldProbability,
144144
};
145145

0 commit comments

Comments
 (0)