@@ -51,7 +51,7 @@ def _entity_relations(entity: Entity) -> list[RelationData]:
5151 RelationData (
5252 relation_type = rel .relation_type ,
5353 target_name = rel .to_name ,
54- target_entity_type = rel .to_entity .entity_type if rel .to_entity else None ,
54+ target_note_type = rel .to_entity .note_type if rel .to_entity else None ,
5555 )
5656 for rel in entity .outgoing_relations
5757 ]
@@ -69,8 +69,8 @@ def _entity_to_note_data(entity: Entity) -> NoteData:
6969def _entity_frontmatter (entity : Entity ) -> dict :
7070 """Build a frontmatter dict from an entity for schema resolution."""
7171 frontmatter = dict (entity .entity_metadata ) if entity .entity_metadata else {}
72- if entity .entity_type :
73- frontmatter .setdefault ("type" , entity .entity_type )
72+ if entity .note_type :
73+ frontmatter .setdefault ("type" , entity .note_type )
7474 return frontmatter
7575
7676
@@ -81,7 +81,7 @@ def _entity_frontmatter(entity: Entity) -> dict:
8181async def validate_schema (
8282 entity_repository : EntityRepositoryV2ExternalDep ,
8383 project_id : str = Path (..., description = "Project external UUID" ),
84- entity_type : str | None = Query (None , description = "Entity type to validate" ),
84+ note_type : str | None = Query (None , description = "Note type to validate" ),
8585 identifier : str | None = Query (None , description = "Specific note identifier" ),
8686):
8787 """Validate notes against their resolved schemas.
@@ -95,7 +95,7 @@ async def validate_schema(
9595 if identifier :
9696 entity = await entity_repository .get_by_permalink (identifier )
9797 if not entity :
98- return ValidationReport (entity_type = entity_type , total_notes = 0 , results = [])
98+ return ValidationReport (note_type = note_type , total_notes = 0 , results = [])
9999
100100 frontmatter = _entity_frontmatter (entity )
101101 schema_ref = frontmatter .get ("schema" )
@@ -120,16 +120,16 @@ async def search_fn(query: str) -> list[dict]:
120120 results .append (_to_note_validation_response (result ))
121121
122122 return ValidationReport (
123- entity_type = entity_type or entity .entity_type ,
123+ note_type = note_type or entity .note_type ,
124124 total_notes = 1 ,
125125 valid_count = 1 if (results and results [0 ].passed ) else 0 ,
126126 warning_count = sum (len (r .warnings ) for r in results ),
127127 error_count = sum (len (r .errors ) for r in results ),
128128 results = results ,
129129 )
130130
131- # --- Batch validation by entity type ---
132- entities = await _find_by_entity_type (entity_repository , entity_type ) if entity_type else []
131+ # --- Batch validation by note type ---
132+ entities = await _find_by_note_type (entity_repository , note_type ) if note_type else []
133133
134134 for entity in entities :
135135 frontmatter = _entity_frontmatter (entity )
@@ -156,7 +156,7 @@ async def search_fn(query: str) -> list[dict]:
156156
157157 valid = sum (1 for r in results if r .passed )
158158 return ValidationReport (
159- entity_type = entity_type ,
159+ note_type = note_type ,
160160 total_notes = len (results ),
161161 total_entities = len (entities ),
162162 valid_count = valid ,
@@ -173,21 +173,21 @@ async def search_fn(query: str) -> list[dict]:
173173async def infer_schema_endpoint (
174174 entity_repository : EntityRepositoryV2ExternalDep ,
175175 project_id : str = Path (..., description = "Project external UUID" ),
176- entity_type : str = Query (..., description = "Entity type to analyze" ),
176+ note_type : str = Query (..., description = "Note type to analyze" ),
177177 threshold : float = Query (0.25 , description = "Minimum frequency for optional fields" ),
178178):
179179 """Infer a schema from existing notes of a given type.
180180
181181 Examines observation categories and relation types across all notes
182182 of the given type. Returns frequency analysis and suggested Picoschema.
183183 """
184- entities = await _find_by_entity_type (entity_repository , entity_type )
184+ entities = await _find_by_note_type (entity_repository , note_type )
185185 notes_data = [_entity_to_note_data (entity ) for entity in entities ]
186186
187- result = infer_schema (entity_type , notes_data , optional_threshold = threshold )
187+ result = infer_schema (note_type , notes_data , optional_threshold = threshold )
188188
189189 return InferenceReport (
190- entity_type = result .entity_type ,
190+ note_type = result .note_type ,
191191 notes_analyzed = result .notes_analyzed ,
192192 field_frequencies = [
193193 FieldFrequencyResponse (
@@ -212,10 +212,10 @@ async def infer_schema_endpoint(
212212# --- Drift Detection ---
213213
214214
215- @router .get ("/schema/diff/{entity_type }" , response_model = DriftReport )
215+ @router .get ("/schema/diff/{note_type }" , response_model = DriftReport )
216216async def diff_schema_endpoint (
217217 entity_repository : EntityRepositoryV2ExternalDep ,
218- entity_type : str = Path (..., description = "Entity type to check for drift" ),
218+ note_type : str = Path (..., description = "Note type to check for drift" ),
219219 project_id : str = Path (..., description = "Project external UUID" ),
220220):
221221 """Show drift between a schema definition and actual note usage.
@@ -229,21 +229,21 @@ async def search_fn(query: str) -> list[dict]:
229229 entities = await _find_schema_entities (entity_repository , query )
230230 return [_entity_frontmatter (e ) for e in entities ]
231231
232- # Resolve schema by entity type
233- schema_frontmatter = {"type" : entity_type }
232+ # Resolve schema by note type
233+ schema_frontmatter = {"type" : note_type }
234234 schema_def = await resolve_schema (schema_frontmatter , search_fn )
235235
236236 if not schema_def :
237- return DriftReport (entity_type = entity_type , schema_found = False )
237+ return DriftReport (note_type = note_type , schema_found = False )
238238
239239 # Collect all notes of this type
240- entities = await _find_by_entity_type (entity_repository , entity_type )
240+ entities = await _find_by_note_type (entity_repository , note_type )
241241 notes_data = [_entity_to_note_data (entity ) for entity in entities ]
242242
243243 result = diff_schema (schema_def , notes_data )
244244
245245 return DriftReport (
246- entity_type = entity_type ,
246+ note_type = note_type ,
247247 new_fields = [
248248 DriftFieldResponse (
249249 name = f .name ,
@@ -271,19 +271,19 @@ async def search_fn(query: str) -> list[dict]:
271271# --- Helpers ---
272272
273273
274- async def _find_by_entity_type (
274+ async def _find_by_note_type (
275275 entity_repository : EntityRepositoryV2ExternalDep ,
276- entity_type : str ,
276+ note_type : str ,
277277) -> list [Entity ]:
278278 """Find all entities of a given type using the repository's select pattern."""
279- query = entity_repository .select ().where (Entity .entity_type == entity_type )
279+ query = entity_repository .select ().where (Entity .note_type == note_type )
280280 result = await entity_repository .execute_query (query )
281281 return list (result .scalars ().all ())
282282
283283
284284async def _find_schema_entities (
285285 entity_repository : EntityRepositoryV2ExternalDep ,
286- target_entity_type : str ,
286+ target_note_type : str ,
287287 * ,
288288 allow_reference_match : bool = False ,
289289) -> list [Entity ]:
@@ -295,11 +295,11 @@ async def _find_schema_entities(
295295 2) Only when allow_reference_match=True and no entity match was found, try
296296 exact reference matching by title/permalink (explicit schema references)
297297 """
298- query = entity_repository .select ().where (Entity .entity_type == "schema" )
298+ query = entity_repository .select ().where (Entity .note_type == "schema" )
299299 result = await entity_repository .execute_query (query )
300300 entities = list (result .scalars ().all ())
301301
302- normalized_target = generate_permalink (target_entity_type )
302+ normalized_target = generate_permalink (target_note_type )
303303
304304 entity_matches = [
305305 e
0 commit comments