Athena — roomy-mobile/archive/changes/2026-01-05-add-roomy-firestore-mcp/tasks/003-datamodel-registry.md


status: done

Task: Datamodel registry from YAML

End Goal

A datamodel registry loader that scans data_models/**/*.yaml, parses entities, and computes entity keys from location paths.

Currently

Firestore env layer works with project config and firebase-admin.

Should

  • Recursively scan data_models/**/*.yaml
  • Parse YAML into entity definitions
  • Compute entityKey, collectionPathTemplate, pathParams, docIdParamName
  • Deduplicate deterministically

Constraints

  • [ ] Support both {$id} and {code} placeholder styles
  • [ ] Ignore YAML files without locations field
  • [ ] Deterministic deduplication by entityKey::collectionPathTemplate

Acceptance Criteria

  • [ ] loadEntityRegistry(repoRoot) returns deterministic results
  • [ ] Location parsing handles both placeholder styles
  • [ ] All unit tests pass

Implementation Checklist

  • [x] 3.1 Create src/datamodels/types.ts with DatamodelYaml, DatamodelFieldSpec, EntityDefinition
  • [x] 3.2 Create src/datamodels/location.ts with placeholder regex
  • [x] 3.3 Implement isPlaceholderSegment(segment) and placeholderName(segment)
  • [x] 3.4 Implement extractCollectionPathTemplate(location) returning template, params, docIdParamName
  • [x] 3.5 Implement deriveEntityKeyFromCollectionSegments(segments)
  • [x] 3.6 Implement buildCollectionPath(template, params) for param substitution
  • [x] 3.7 Create src/datamodels/registry.ts with loadEntityRegistry(repoRoot)
  • [x] 3.8 Walk repoRoot/data_models recursively for .yaml files
  • [x] 3.9 Parse YAML and skip files without locations
  • [x] 3.10 Generate EntityDefinition for each location
  • [x] 3.11 Dedupe by ${entityKey}::${collectionPathTemplate}
  • [x] 3.12 Sort output by entityKey
  • [x] 3.13 Create src/datamodels/index.ts with exports
  • [x] 3.14 Add unit tests for placeholder parsing
  • [x] 3.15 Add unit tests for subcollection parsing
  • [x] 3.16 Add unit tests for buildCollectionPath

Notes

  • Field types: string|number|boolean|timestamp|map|array|unknown
  • Example locations:
    • users/{$id} → entityKey: users, pathParams: [], docIdParamName: id
    • cleaningSchedules/{$scheduleId}/cleaningTimeSlots/{$id} → entityKey: cleaningSchedules_cleaningTimeSlots, pathParams: [scheduleId], docIdParamName: id

Reacties

Nog geen reacties