Fix metadata filtering by package in Studio#1048
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- Clear selectedMeta when switching packages in App.tsx - Add packageId parameter to client.meta.getItem() method - Pass selectedPackage.manifest.id through PluginHost to MetadataInspector - Update backend http-dispatcher to extract and pass packageId to protocol.getMetaItem() - Update MetadataViewerProps to include optional packageId field - MetadataInspector now filters metadata by package when packageId is provided Agent-Logs-Url: https://github.com/objectstack-ai/spec/sessions/fd48007b-701b-4729-85ba-26954cf662ce Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR aims to ensure Studio’s metadata inspector is scoped to the currently selected package by clearing stale selection state on package switch and threading an optional packageId filter from Studio UI → client API → backend handler.
Changes:
- Studio: clear
selectedMetawhen switching packages and passselectedPackage.manifest.idintoPluginHost/viewer props. - Studio plugin/viewer plumbing: add
packageId?: stringtoMetadataViewerPropsand forward it through the default viewer intoMetadataInspector. - Client + runtime: add optional
{ packageId }toclient.meta.getItem(...)and forward?package=through the runtime metadata handler intoprotocol.getMetaItem(...).
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/runtime/src/http-dispatcher.ts | Extracts query.package and forwards it as packageId to protocol.getMetaItem(...). |
| packages/client/src/index.ts | Extends meta.getItem to accept { packageId?: string } and appends ?package= when provided. |
| apps/studio/src/plugins/types.ts | Adds optional packageId to MetadataViewerProps. |
| apps/studio/src/plugins/plugin-host.tsx | Accepts packageId and forwards it into the resolved viewer component. |
| apps/studio/src/plugins/built-in/default-plugin.tsx | Forwards packageId into MetadataInspector. |
| apps/studio/src/components/MetadataInspector.tsx | Uses packageId when calling client.meta.getItem(...) and reloads when it changes. |
| apps/studio/src/App.tsx | Clears selectedMeta on package switch and passes selected package ID into PluginHost. |
| // Try Protocol Service First (Preferred) | ||
| const protocol = await this.resolveService('protocol'); | ||
| if (protocol && typeof protocol.getMetaItem === 'function') { | ||
| try { | ||
| const data = await protocol.getMetaItem({ type: singularType, name }); | ||
| const data = await protocol.getMetaItem({ type: singularType, name, packageId }); | ||
| return { handled: true, response: this.success(data) }; |
There was a problem hiding this comment.
packageId is being passed into protocol.getMetaItem(...), but the current protocol implementation in this repo (packages/objectql/src/protocol.ts) defines getMetaItem(request: { type, name }) and ignores any packageId field, so this change won’t actually scope lookups by package. To make package filtering effective, update the protocol contract + implementation to accept packageId and use it when resolving from SchemaRegistry (prefer ${packageId}:${name} / _packageId-tagged items) and in any DB fallback query (e.g., include packageId in the where clause when provided).
| return { handled: true, response: this.success(data) }; | ||
| } catch (e: any) { | ||
| // Protocol might throw if not found or not supported |
There was a problem hiding this comment.
If protocol.getMetaItem(...) throws, this handler falls through to the broker-based lookup below, which currently does not receive packageId. That means package scoping can be lost depending on which backend implementation is active. Consider ensuring the fallback path also receives the package filter (or explicitly returning a scoped-not-found) to keep behavior consistent.
| // Extract optional package filter from query string | ||
| const packageId = query?.package || undefined; |
There was a problem hiding this comment.
There are existing unit tests for handleMetadata, but none assert the new query.package → packageId behavior for GET /meta/:type/:name. Add a test that passes a query object with package set and verifies the protocol is invoked with that packageId (and/or that the scoped item is returned).
When switching packages in Studio's left sidebar, the metadata panel displayed items from all packages instead of filtering by the selected package. Two root causes: (1)
selectedMetastate persisted across package switches, and (2)client.meta.getItem()lacked package filtering despitegetItems()already supporting it.Changes
Frontend
selectedMetastate inhandleSelectPackageto prevent stale metadata displaypackageIdthroughPluginHost→MetadataViewerProps→MetadataInspectorselectedPackage.manifest.idfrom App to both object and metadata viewsClient API
packageIdparameter tometa.getItem(type, name, options?)?package=query string when packageId providedBackend
packageIdfromquery.packagein/metadata/:type/:namehandlerprotocol.getMetaItem({ type, name, packageId })All changes maintain backward compatibility—
packageIdis optional throughout.