Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
| @@ -1,4 +1,4 @@ | |||
| import { ObjectStackKernel, ObjectQLPlugin, ObjectQL } from '@objectstack/runtime'; | |||
| import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin, ObjectQL } from '@objectstack/runtime'; | |||
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 months ago
In general, unused imports should be removed from the import list so the code only brings in what it actually uses. This improves readability and avoids potential linting or compilation warnings.
The best fix here is to edit examples/host/src/index.ts and modify the first import statement: remove ObjectQL from the destructured import from @objectstack/runtime, keeping the remaining imported names unchanged. No other code changes or new imports are required, and this will not alter runtime behavior because ObjectQL was never referenced.
Concretely: in examples/host/src/index.ts, line 1 currently imports { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin, ObjectQL }. Replace that line with an import that only includes { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin }.
| @@ -1,4 +1,4 @@ | ||
| import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin, ObjectQL } from '@objectstack/runtime'; | ||
| import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin } from '@objectstack/runtime'; | ||
| import { InMemoryDriver } from '@objectstack/driver-memory'; | ||
| import { HonoServerPlugin } from '@objectstack/plugin-hono-server'; | ||
|
|
| import { | ||
| RuntimePlugin, | ||
| RuntimeContext, | ||
| Plugin, | ||
| PluginContext, | ||
| ObjectStackRuntimeProtocol, | ||
| ObjectKernel | ||
| } from '@objectstack/runtime'; |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 months ago
To fix the unused import, remove ObjectKernel from the import list on line 3 while leaving all actually used imports intact. This will eliminate the unused symbol without affecting existing functionality.
Concretely, in packages/plugin-msw/src/msw-plugin.ts, edit the import from @objectstack/runtime so that ObjectKernel is no longer included in the named imports. No additional code changes or imports are needed, and no other lines must be modified.
| @@ -5,10 +5,10 @@ | ||
| RuntimeContext, | ||
| Plugin, | ||
| PluginContext, | ||
| ObjectStackRuntimeProtocol, | ||
| ObjectKernel | ||
| ObjectStackRuntimeProtocol | ||
| } from '@objectstack/runtime'; | ||
|
|
||
|
|
||
| export interface MSWPluginOptions { | ||
| /** | ||
| * Enable MSW in the browser environment |
There was a problem hiding this comment.
Pull request overview
This pull request successfully migrates the codebase from the monolithic ObjectStackKernel to a plugin-based ObjectKernel (MiniKernel) architecture while maintaining full backward compatibility.
Purpose: Replace the monolithic kernel with a modular, plugin-based microkernel that provides better separation of concerns, dependency injection, and lifecycle management.
Changes:
- Introduced
ObjectKernelwith plugin lifecycle management (init → start → destroy) and topological dependency resolution - Created
AppManifestPluginto wrap app configurations as first-class plugins - Updated
ObjectStackRuntimeProtocolto support both legacy and new kernel types - Migrated all examples and documentation to demonstrate the new architecture
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/runtime/src/types.ts | Added getKernel() method to PluginContext for advanced plugin use cases; updated RuntimeContext to accept both kernel types |
| packages/runtime/src/protocol.ts | Implemented kernel type detection and dual-path support for both ObjectStackKernel and ObjectKernel |
| packages/runtime/src/objectql-plugin.ts | Added compatibility check to handle both kernel types in legacy install method |
| packages/runtime/src/mini-kernel.ts | Added getKernel() implementation to PluginContext |
| packages/runtime/src/kernel.ts | Added comprehensive deprecation documentation with migration examples |
| packages/runtime/src/index.ts | Reordered exports to promote ObjectKernel first, marked ObjectStackKernel as deprecated |
| packages/runtime/src/app-manifest-plugin.ts | New plugin that wraps app manifests with schema registration and data seeding capabilities |
| packages/runtime/README.md | Completely updated documentation with new architecture, migration guide, and best practices |
| packages/plugin-msw/src/msw-plugin.ts | Implemented dual interface support for both Plugin and RuntimePlugin patterns |
| examples/msw-react-crud/src/mocks/browser.ts | Migrated to use ObjectKernel with plugin chaining pattern |
| examples/host/src/index.ts | Migrated to use ObjectKernel with AppManifestPlugin for each app |
| examples/host/debug-registry.ts | Updated to use new kernel and plugin architecture |
| examples/custom-objectql-example.ts | Updated to demonstrate custom ObjectQL instance with new kernel |
| // Check if data already exists | ||
| const existing = await objectql.find(seed.object, { top: 1 }); | ||
| if (existing.length === 0) { | ||
| ctx.logger.log(`[AppManifestPlugin] Inserting ${seed.records.length} records into ${seed.object}`); | ||
| for (const record of seed.records) { |
There was a problem hiding this comment.
The seed data check only verifies if the object has any records (top: 1), not whether the specific seed records already exist. This means if ANY data exists in the object, the seed data will never be inserted, even if those specific records are missing. Consider implementing a more precise check, such as checking for specific record IDs or using a dedicated seeding flag/table to track which seed sets have been applied.
| // Check if data already exists | |
| const existing = await objectql.find(seed.object, { top: 1 }); | |
| if (existing.length === 0) { | |
| ctx.logger.log(`[AppManifestPlugin] Inserting ${seed.records.length} records into ${seed.object}`); | |
| for (const record of seed.records) { | |
| ctx.logger.log(`[AppManifestPlugin] Processing seed data for object ${seed.object}`); | |
| for (const record of seed.records) { | |
| let shouldInsert = true; | |
| // If the seed record declares an 'id', perform a targeted existence check. | |
| if (record && typeof record === 'object' && 'id' in record) { | |
| try { | |
| const existing = await objectql.find(seed.object, { | |
| filter: { id: (record as any).id }, | |
| top: 1, | |
| }); | |
| shouldInsert = existing.length === 0; | |
| } catch (lookupError) { | |
| ctx.logger.warn( | |
| `[AppManifestPlugin] Failed to check for existing record in ${seed.object}`, | |
| lookupError, | |
| ); | |
| // If the existence check fails, fall back to attempting an insert. | |
| shouldInsert = true; | |
| } | |
| } | |
| if (shouldInsert) { |
| name = 'msw'; | ||
| export class MSWPlugin implements Plugin, RuntimePlugin { | ||
| name = 'com.objectstack.plugin.msw'; | ||
| version = '1.0.0'; |
There was a problem hiding this comment.
The MSWPlugin should declare a dependency on the ObjectQL plugin since it creates an ObjectStackRuntimeProtocol that requires ObjectQL to be available. Add dependencies = ['com.objectstack.engine.objectql'] to ensure proper initialization order. Without this, the plugin might start before ObjectQL is initialized, causing runtime errors.
| version = '1.0.0'; | |
| version = '1.0.0'; | |
| dependencies = ['com.objectstack.engine.objectql']; |
| // TODO: Implement proper ID-based lookup once ObjectQL supports it | ||
| // For now, this is a limitation of the current ObjectQL API | ||
| const results = await ql.find(objectName, { top: 1, filter: { id } }); | ||
| return results[0]; |
There was a problem hiding this comment.
The getData implementation should use ObjectQL's findOne method instead of find with a filter. ObjectQL provides a findOne method (as seen in packages/objectql/src/index.ts) that is designed for ID-based lookups and will be more efficient. Change line 183 to use: return await ql.findOne(objectName, id);
| // TODO: Implement proper ID-based lookup once ObjectQL supports it | |
| // For now, this is a limitation of the current ObjectQL API | |
| const results = await ql.find(objectName, { top: 1, filter: { id } }); | |
| return results[0]; | |
| return await ql.findOne(objectName, id); |
| @@ -1,4 +1,4 @@ | |||
| import { ObjectStackKernel, ObjectQLPlugin, ObjectQL } from '@objectstack/runtime'; | |||
| import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin, ObjectQL } from '@objectstack/runtime'; | |||
There was a problem hiding this comment.
Unused import ObjectQL.
| import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin, ObjectQL } from '@objectstack/runtime'; | |
| import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin } from '@objectstack/runtime'; |
| ObjectStackRuntimeProtocol, | ||
| ObjectKernel |
There was a problem hiding this comment.
Unused import ObjectKernel.
| ObjectStackRuntimeProtocol, | |
| ObjectKernel | |
| ObjectStackRuntimeProtocol |
Migrates codebase from
ObjectStackKernel(monolithic) toObjectKernel(microkernel) as the primary runtime. ObjectStackKernel is deprecated but remains for backward compatibility.Architecture
The MiniKernel provides:
PluginContextwithgetKernel()for advanced use casesChanges
New Components
AppManifestPlugin: Wrapsobjectstack.config.tsexports as first-class pluginsPluginContext: AddedgetKernel()returningObjectStackKernel | ObjectKernelObjectStackRuntimeProtocol: Supports both kernel types via kernel detectionRefactored Modules
msw-react-crud,host,custom-objectql-examplenow use plugin chainingplugin-msw: Implements bothPluginandRuntimePlugininterfacesObjectKernelfirst,ObjectStackKernelmarked@deprecatedExample
Before:
After:
Compatibility
Full backward compatibility maintained. Existing code using
ObjectStackKernelcontinues to work unchanged.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.