From df65810b107805b9d4a1788a2079748ebcc8ec87 Mon Sep 17 00:00:00 2001 From: David Snelling Date: Mon, 27 Oct 2025 15:59:00 -0700 Subject: [PATCH] fix(metadataIndex): flatten custom metadata fields for cleaner queries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit v4.8.0 caused metadata filters to fail because custom fields were indexed with 'metadata.' prefix but queries used flat field names. Root cause: - extractIndexableFields() indexed custom fields as 'metadata.category' - Queries used { category: 'B' } looking for 'category' field - Result: 0 matches despite entities existing Solution: - Flatten custom metadata fields to top-level in index (no prefix) - Standard fields (type, createdAt, etc.) already at top-level - Custom fields won't conflict with standard field names - Now queries work: { category: 'B' } finds 'category' field Results: - Fixed 4 more tests (25 → 21 failures) - All find.test.ts tests passing (17/17) - Test pass rate: 97.1% (976/1005) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/utils/metadataIndex.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils/metadataIndex.ts b/src/utils/metadataIndex.ts index 7b85b0c9..504bb02a 100644 --- a/src/utils/metadataIndex.ts +++ b/src/utils/metadataIndex.ts @@ -1125,9 +1125,11 @@ export class MetadataIndexManager { if (!this.shouldIndexField(fullKey)) continue // Special handling for metadata field at top level - // If this is an entity structure, recurse into metadata with prefix + // v4.8.0: Flatten metadata fields to top-level (no prefix) for cleaner queries + // Standard fields are already at top-level, custom fields go in metadata + // By flattening here, queries can use { category: 'B' } instead of { 'metadata.category': 'B' } if (key === 'metadata' && !prefix && typeof value === 'object' && !Array.isArray(value)) { - extract(value, 'metadata') + extract(value, '') // Flatten to top-level, no prefix continue }