Skip to content

Commit e9b157c

Browse files
committed
feat: add optional packageId parameter to getMetaItems and getMetaItem methods for filtering
1 parent f58eb18 commit e9b157c

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

packages/objectql/src/protocol.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,19 +185,22 @@ export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
185185
};
186186
}
187187

188-
async getMetaItems(request: { type: string }) {
189-
let items = SchemaRegistry.listItems(request.type);
188+
async getMetaItems(request: { type: string; packageId?: string }) {
189+
const { packageId } = request;
190+
let items = SchemaRegistry.listItems(request.type, packageId);
190191
// Normalize singular/plural: REST uses singular ('app') but registry may store as plural ('apps')
191192
if (items.length === 0) {
192193
const alt = request.type.endsWith('s') ? request.type.slice(0, -1) : request.type + 's';
193-
items = SchemaRegistry.listItems(alt);
194+
items = SchemaRegistry.listItems(alt, packageId);
194195
}
195196

196197
// Fallback to database if registry is empty for this type
197198
if (items.length === 0) {
198199
try {
200+
const whereClause: any = { type: request.type, state: 'active' };
201+
if (packageId) whereClause._packageId = packageId;
199202
const allRecords = await this.engine.find('sys_metadata', {
200-
where: { type: request.type, state: 'active' }
203+
where: whereClause
201204
});
202205
if (allRecords && allRecords.length > 0) {
203206
items = allRecords.map((record: any) => {
@@ -235,7 +238,7 @@ export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
235238
};
236239
}
237240

238-
async getMetaItem(request: { type: string, name: string }) {
241+
async getMetaItem(request: { type: string, name: string, packageId?: string }) {
239242
let item = SchemaRegistry.getItem(request.type, request.name);
240243
// Normalize singular/plural
241244
if (item === undefined) {

packages/rest/src/rest-server.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ export class RestServer {
306306
path: `${metaPath}/:type`,
307307
handler: async (req: any, res: any) => {
308308
try {
309-
const items = await this.protocol.getMetaItems({ type: req.params.type });
309+
const packageId = req.query?.package || undefined;
310+
const items = await this.protocol.getMetaItems({ type: req.params.type, packageId });
310311
res.json(items);
311312
} catch (error: any) {
312313
res.status(404).json({ error: error.message });
@@ -365,7 +366,8 @@ export class RestServer {
365366
res.json(result.data);
366367
} else {
367368
// Non-cached version
368-
const item = await this.protocol.getMetaItem({ type: req.params.type, name: req.params.name });
369+
const packageId = req.query?.package || undefined;
370+
const item = await this.protocol.getMetaItem({ type: req.params.type, name: req.params.name, packageId });
369371
res.json(item);
370372
}
371373
} catch (error: any) {

packages/spec/src/api/protocol.zod.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export const GetMetaTypesResponseSchema = z.object({
155155
*/
156156
export const GetMetaItemsRequestSchema = z.object({
157157
type: z.string().describe('Metadata type name (e.g., "object", "plugin")'),
158+
packageId: z.string().optional().describe('Optional package ID to filter items by'),
158159
});
159160

160161
/**
@@ -172,6 +173,7 @@ export const GetMetaItemsResponseSchema = z.object({
172173
export const GetMetaItemRequestSchema = z.object({
173174
type: z.string().describe('Metadata type name'),
174175
name: z.string().describe('Item name (snake_case identifier)'),
176+
packageId: z.string().optional().describe('Optional package ID to filter items by'),
175177
});
176178

177179
/**

0 commit comments

Comments
 (0)