Add schema infer, variants, Hono REST hooks#9
Conversation
Introduce data-first schema tooling and REST extensibility: add a new CLI command `schema infer [resource] [--out]` and update help text; implement doctor guidance that suggests adding or removing schemas based on inferred data (new schema-guidance module). Extend schema normalization/inference to support discriminated object variants (discriminator + variants), propagate variants into manifests, validation, and generated types (emit variant aliases and variant object types). Export and implement registerRestRoutes with restRoutes options (prefix, resource include/exclude, methods, per-resource hooks and global hooks, and short-circuiting), wire it into Hono app creation, and update types and tests accordingly. Add JsonDbCollection.exists() to the API and implement it in both fixture and SQLite adapters. Update README and AGENTS to emphasize a data-first approach and document new workflow examples and usage. Tests updated to cover new behavior.
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR introduces discriminated union types with variants for polymorphic schema inference, adds a ChangesDiscriminated Union Types & Schema Features
REST Routes Configuration
Documentation Updates
Sequence DiagramsequenceDiagram
participant App
participant SchemaFields as Field Inference
participant Validation as Validator
participant Manifest as Manifest Gen
participant Types as Type Gen
participant Doctor as Doctor
App->>SchemaFields: inferFieldFromSamples(polymorphic array, inferVariants=true)
SchemaFields->>SchemaFields: inferDiscriminatedObjectField()
SchemaFields-->>App: field with discriminator & variants
App->>Validation: validateObjectFields(record, field with variants)
Validation->>Validation: validateVariantObjectFields()
Validation->>Validation: read discriminator value
Validation->>Validation: merge variant schema with enum constraint
Validation-->>App: validation result
App->>Manifest: renderFieldManifest(field with variants)
Manifest-->>App: manifest with variants map
App->>Types: typeForField(field, fieldPath)
Types->>Types: variantObjectType() for variant union
Types-->>App: TypeScript variant union type
App->>Doctor: runJsonDbDoctor(config)
Doctor->>Doctor: load inferred project
Doctor->>Doctor: schemaGuidanceFindings()
Doctor-->>App: DOCTOR_SCHEMA_RECOMMENDED or DOCTOR_SCHEMA_MATCHES_INFERENCE
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes The PR spans multiple interconnected systems (schema inference, validation, type generation, CLI, doctor, REST routes) with significant logic density in variant merging, discriminator detection, normalized comparison, and REST hook orchestration. While individual layers follow clear patterns, the variant feature adds intricate recursive logic for nested structures, and the REST routes system introduces substantial option-driven configuration handling. Testing is comprehensive across new features. Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Warning Review ran into problems🔥 ProblemsStopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Introduce data-first schema tooling and REST extensibility: add a new CLI command
schema infer [resource] [--out]and update help text; implement doctor guidance that suggests adding or removing schemas based on inferred data (new schema-guidance module). Extend schema normalization/inference to support discriminated object variants (discriminator + variants), propagate variants into manifests, validation, and generated types (emit variant aliases and variant object types). Export and implement registerRestRoutes with restRoutes options (prefix, resource include/exclude, methods, per-resource hooks and global hooks, and short-circuiting), wire it into Hono app creation, and update types and tests accordingly. Add JsonDbCollection.exists() to the API and implement it in both fixture and SQLite adapters. Update README and AGENTS to emphasize a data-first approach and document new workflow examples and usage. Tests updated to cover new behavior.Summary by CodeRabbit
Release Notes
New Features
schema inferCLI command to infer and output resource schemas from seed datacollection.exists(id)method to check record existenceDocumentation