Refactor Repository to use ObjectStackKernel with QueryAST translation#156
Refactor Repository to use ObjectStackKernel with QueryAST translation#156
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
|
|
@copilot fix ci build test typecheck and check all again |
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
|
@copilot 继续 |
|
✅ All checks verified and passing: Build Status:
Recent Changes (commits f2d26cf & e1bff2f):
The repository pattern migration is complete and all CI checks are green. The implementation successfully bridges the legacy ObjectQL API with the new ObjectStack kernel architecture while maintaining full backward compatibility. |
There was a problem hiding this comment.
Pull request overview
This PR migrates the ObjectRepository to use the ObjectStackKernel with QueryAST translation instead of talking directly to drivers, while keeping the public repository API stable and keeping tests passing via a kernel mock that delegates to the legacy driver.
Changes:
- Extended
IObjectQLandObjectQLto expose the underlying kernel and wire it into initialization, including a temporary delegation hook for the Jest kernel mock. - Refactored
ObjectRepositoryread/write methods (find,findOne,count,create,update,delete) to buildQueryASTand route calls throughObjectStackKernel, preserving validation, hooks, and formula evaluation. - Updated the Jest
@objectstack/runtimemock and example apps (build scripts and audit plugin) to align with the new kernel-centric architecture and avoid ESM/CJS issues.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
packages/foundation/types/src/app.ts |
Adds getKernel(): any to IObjectQL so core code can access the underlying ObjectStackKernel without introducing a dependency from @objectql/types to @objectstack/runtime. |
packages/foundation/core/src/app.ts |
Implements kernel plugin wiring, exposes getKernel() with runtime type, and during init() optionally injects the default driver into kernels that support setDriver (used by the Jest mock) before starting the kernel. |
packages/foundation/core/src/repository.ts |
Introduces translateFilters and buildQueryAST to translate UnifiedQuery/FilterExpression into QueryAST, and refactors core CRUD methods to use kernel.find/get/create/update/delete while leaving aggregate, distinct, and findOneAndUpdate on the legacy driver. |
packages/foundation/core/test/__mocks__/@objectstack/runtime.ts |
Enhances the ObjectStackKernel mock with setDriver and delegates find/get/create/update/delete back to the legacy driver via a reverse QueryAST→UnifiedQuery translation to preserve existing test behavior. |
examples/showcase/project-tracker/package.json |
Simplifies the build script to run tsc and copy YAML files, dropping the now-unnecessary codegen step from the build pipeline. |
examples/showcase/enterprise-erp/package.json |
Mirrors the build script simplification and keeps dev dependencies aligned with the new kernel/spec usage. |
examples/showcase/enterprise-erp/src/plugins/audit/audit.plugin.ts |
Replaces the previous @objectstack/spec-based plugin types with a small inline RuntimePlugin/RuntimeContext interface and adjusts the audit plugin to the runtime-style install/onStart lifecycle while keeping behavior limited to logging. |
| // Import RuntimePlugin types from @objectql/core instead of @objectstack/runtime | ||
| // to avoid ESM/CJS compatibility issues |
There was a problem hiding this comment.
The header comment says "Import RuntimePlugin types from @objectql/core instead of @objectstack/runtime", but the code now defines RuntimeContext/RuntimePlugin locally and doesn’t import from either package. Please update this comment to accurately describe the current approach (e.g., that the interfaces are defined inline to avoid ESM/CJS issues) to avoid confusion for future readers.
| // Import RuntimePlugin types from @objectql/core instead of @objectstack/runtime | |
| // to avoid ESM/CJS compatibility issues | |
| // NOTE: RuntimePlugin-related interfaces are defined inline here (rather than | |
| // importing from @objectql/core or @objectstack/runtime) to avoid ESM/CJS | |
| // compatibility issues in this example plugin. |
| import { ObjectQLContext, IObjectQL, ObjectConfig, Driver, UnifiedQuery, ActionContext, HookAPI, RetrievalHookContext, MutationHookContext, UpdateHookContext, ValidationContext, ValidationError, ValidationRuleResult, FormulaContext } from '@objectql/types'; | ||
| import { ObjectQLContext, IObjectQL, ObjectConfig, Driver, UnifiedQuery, ActionContext, HookAPI, RetrievalHookContext, MutationHookContext, UpdateHookContext, ValidationContext, ValidationError, ValidationRuleResult, FormulaContext, FilterExpression } from '@objectql/types'; | ||
| import type { ObjectStackKernel } from '@objectstack/runtime'; | ||
| import type { QueryAST, FilterNode, SortNode } from '@objectstack/spec'; |
There was a problem hiding this comment.
The imported SortNode type is never used in this file, which can cause lint warnings and slightly reduce clarity. Consider removing SortNode from this import list to keep the dependencies and types minimal.
| import type { QueryAST, FilterNode, SortNode } from '@objectstack/spec'; | |
| import type { QueryAST, FilterNode } from '@objectstack/spec'; |
Phase 3 Part 2: Repository Pattern Migration ✅
This task refactors the
ObjectRepositoryclass to use theObjectStackKernelinstead of direct driver access, converting ObjectQL queries toQueryASTformat.Plan
ObjectRepositorystructure and its dependenciesQueryASTtype from@objectstack/specandObjectStackKernelAPI from@objectstack/runtimeObjectRepositoryconstructor to acceptObjectStackKernelinstead of legacy driverbuildQueryASTfind()method to use kernel.find() with QueryASTfindOne()method to use kernel.get()count()method to use kernel.find() with countcreate()method to use kernel.create()update()method to use kernel.update()delete()method to use kernel.delete()✨ Summary of Changes
Core Implementation:
packages/foundation/core/src/repository.ts:ObjectStackKernel,QueryAST,FilterNodefrom@objectstackpackagesgetKernel()method to retrieve kernel from appbuildQueryAST()to translate UnifiedQuery to QueryAST formattranslateFilters()to convert FilterExpression to FilterNodefind()→kernel.find()with QueryASTfindOne()→kernel.get()for direct ID lookupscount()→kernel.find()to get countcreate()→kernel.create()update()→kernel.update()delete()→kernel.delete()aggregate(),distinct(),findOneAndUpdate()packages/foundation/types/src/app.ts:getKernel()method toIObjectQLinterfaceanyto avoid circular dependencypackages/foundation/core/src/app.ts:setDriver()on kernel mock when availablepackages/foundation/core/test/__mocks__/@objectstack/runtime.ts:CI Build Fixes:
examples/showcase/enterprise-erp/src/plugins/audit/audit.plugin.tsto use inline RuntimePlugin interface (avoiding ESM/CJS issues with @objectstack/runtime)🎯 Technical Highlights
AST Translation Logic:
Backward Compatibility:
✅ Test Results
All tests pass successfully, including:
🏗️ Build & CI Status
All CI checks passing:
🚀 Next Steps
The repository migration is complete! Future work:
ValidatorandFormulaEngineto plugins (Task 3.4 & 3.5)aggregate(),distinct(),findOneAndUpdate()to kernel📝 Architecture Notes
This implementation follows the "Protocol-Driven, Not Code-Driven" principle from the ObjectQL constitution:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.