Skip to content

Commit 5a4fc01

Browse files
authored
Merge pull request #413 from objectstack-ai/copilot/update-action-step-in-job
2 parents 0917d57 + cc53ba6 commit 5a4fc01

2 files changed

Lines changed: 44 additions & 41 deletions

File tree

packages/plugins/plugin-hono-server/src/hono-plugin.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,27 @@ export class HonoServerPlugin implements Plugin {
6464

6565
ctx.logger.debug('Registering API routes');
6666

67-
this.server.get('/api/v1', (req, res) => {
67+
this.server.get('/api/v1', async (req, res) => {
6868
ctx.logger.debug('API discovery request');
69-
res.json(p.getDiscovery());
69+
res.json(await p.getDiscovery({}));
7070
});
7171

7272
// Meta Protocol
73-
this.server.get('/api/v1/meta', (req, res) => {
73+
this.server.get('/api/v1/meta', async (req, res) => {
7474
ctx.logger.debug('Meta types request');
75-
res.json(p.getMetaTypes());
75+
res.json(await p.getMetaTypes({}));
7676
});
77-
this.server.get('/api/v1/meta/:type', (req, res) => {
77+
this.server.get('/api/v1/meta/:type', async (req, res) => {
7878
ctx.logger.debug('Meta items request', { type: req.params.type });
79-
res.json(p.getMetaItems(req.params.type));
79+
res.json(await p.getMetaItems({ type: req.params.type }));
8080
});
8181

8282
// Data Protocol
8383
this.server.get('/api/v1/data/:object', async (req, res) => {
8484
ctx.logger.debug('Data find request', { object: req.params.object, query: req.query });
8585
try {
86-
const result = await p.findData(req.params.object, req.query);
87-
ctx.logger.debug('Data find completed', { object: req.params.object, count: result?.length ?? 0 });
86+
const result = await p.findData({ object: req.params.object, query: req.query as any });
87+
ctx.logger.debug('Data find completed', { object: req.params.object, count: result?.records?.length ?? 0 });
8888
res.json(result);
8989
}
9090
catch(e:any) {
@@ -95,7 +95,7 @@ export class HonoServerPlugin implements Plugin {
9595
this.server.get('/api/v1/data/:object/:id', async (req, res) => {
9696
ctx.logger.debug('Data get request', { object: req.params.object, id: req.params.id });
9797
try {
98-
const result = await p.getData(req.params.object, req.params.id);
98+
const result = await p.getData({ object: req.params.object, id: req.params.id });
9999
ctx.logger.debug('Data get completed', { object: req.params.object, id: req.params.id });
100100
res.json(result);
101101
}
@@ -107,7 +107,7 @@ export class HonoServerPlugin implements Plugin {
107107
this.server.post('/api/v1/data/:object', async (req, res) => {
108108
ctx.logger.debug('Data create request', { object: req.params.object });
109109
try {
110-
const result = await p.createData(req.params.object, req.body);
110+
const result = await p.createData({ object: req.params.object, data: req.body });
111111
ctx.logger.info('Data created', { object: req.params.object, id: result?.id });
112112
res.status(201).json(result);
113113
}
@@ -119,7 +119,7 @@ export class HonoServerPlugin implements Plugin {
119119
this.server.patch('/api/v1/data/:object/:id', async (req, res) => {
120120
ctx.logger.debug('Data update request', { object: req.params.object, id: req.params.id });
121121
try {
122-
const result = await p.updateData(req.params.object, req.params.id, req.body);
122+
const result = await p.updateData({ object: req.params.object, id: req.params.id, data: req.body });
123123
ctx.logger.info('Data updated', { object: req.params.object, id: req.params.id });
124124
res.json(result);
125125
}
@@ -131,8 +131,8 @@ export class HonoServerPlugin implements Plugin {
131131
this.server.delete('/api/v1/data/:object/:id', async (req, res) => {
132132
ctx.logger.debug('Data delete request', { object: req.params.object, id: req.params.id });
133133
try {
134-
const result = await p.deleteData(req.params.object, req.params.id);
135-
ctx.logger.info('Data deleted', { object: req.params.object, id: req.params.id, success: result });
134+
const result = await p.deleteData({ object: req.params.object, id: req.params.id });
135+
ctx.logger.info('Data deleted', { object: req.params.object, id: req.params.id, success: result?.success });
136136
res.json(result);
137137
}
138138
catch(e:any) {
@@ -142,13 +142,12 @@ export class HonoServerPlugin implements Plugin {
142142
});
143143

144144
// UI Protocol
145-
// @ts-ignore
146-
this.server.get('/api/v1/ui/view/:object', (req, res) => {
145+
this.server.get('/api/v1/ui/view/:object', async (req, res) => {
147146
const viewType = (req.query.type) || 'list';
148147
const qt = Array.isArray(viewType) ? viewType[0] : viewType;
149148
ctx.logger.debug('UI view request', { object: req.params.object, viewType: qt });
150149
try {
151-
res.json(p.getUiView(req.params.object, qt as any));
150+
res.json(await p.getUiView({ object: req.params.object, type: qt as any }));
152151
}
153152
catch(e:any) {
154153
ctx.logger.warn('UI view not found', { object: req.params.object, viewType: qt });
@@ -166,7 +165,7 @@ export class HonoServerPlugin implements Plugin {
166165
bodyKeys: req.body ? Object.keys(req.body) : []
167166
});
168167
try {
169-
const result = await p.batchData(req.params.object, req.body);
168+
const result = await p.batchData({ object: req.params.object, request: req.body });
170169
ctx.logger.info('Batch operation completed', {
171170
object: req.params.object,
172171
operation: req.body?.operation,
@@ -184,8 +183,8 @@ export class HonoServerPlugin implements Plugin {
184183
this.server.post('/api/v1/data/:object/createMany', async (req, res) => {
185184
ctx.logger.debug('Create many request', { object: req.params.object, count: req.body?.length });
186185
try {
187-
const result = await p.createManyData(req.params.object, req.body || []);
188-
ctx.logger.info('Create many completed', { object: req.params.object, count: result.length });
186+
const result = await p.createManyData({ object: req.params.object, records: req.body || [] });
187+
ctx.logger.info('Create many completed', { object: req.params.object, count: result.records?.length ?? 0 });
189188
res.status(201).json(result);
190189
} catch (e: any) {
191190
ctx.logger.error('Create many failed', e, { object: req.params.object });
@@ -196,7 +195,7 @@ export class HonoServerPlugin implements Plugin {
196195
this.server.post('/api/v1/data/:object/updateMany', async (req, res) => {
197196
ctx.logger.debug('Update many request', { object: req.params.object, count: req.body?.records?.length });
198197
try {
199-
const result = await p.updateManyData(req.params.object, req.body);
198+
const result = await p.updateManyData({ object: req.params.object, records: req.body?.records, options: req.body?.options });
200199
ctx.logger.info('Update many completed', {
201200
object: req.params.object,
202201
total: result.total,
@@ -213,7 +212,7 @@ export class HonoServerPlugin implements Plugin {
213212
this.server.post('/api/v1/data/:object/deleteMany', async (req, res) => {
214213
ctx.logger.debug('Delete many request', { object: req.params.object, count: req.body?.ids?.length });
215214
try {
216-
const result = await p.deleteManyData(req.params.object, req.body);
215+
const result = await p.deleteManyData({ object: req.params.object, ids: req.body?.ids, options: req.body?.options });
217216
ctx.logger.info('Delete many completed', {
218217
object: req.params.object,
219218
total: result.total,
@@ -240,7 +239,11 @@ export class HonoServerPlugin implements Plugin {
240239
ifModifiedSince: req.headers['if-modified-since'] as string,
241240
};
242241

243-
const result = await p.getMetaItemCached(req.params.type, req.params.name, cacheRequest);
242+
const result = await p.getMetaItemCached({
243+
type: req.params.type,
244+
name: req.params.name,
245+
cacheRequest
246+
});
244247

245248
if (result.notModified) {
246249
ctx.logger.debug('Meta item not modified (304)', { type: req.params.type, name: req.params.name });
@@ -294,7 +297,7 @@ export class HonoServerPlugin implements Plugin {
294297
this.server.get('/api/v1/ui/views/:id', async (req, res) => {
295298
ctx.logger.debug('Get view request', { id: req.params.id });
296299
try {
297-
const result = await p.getView(req.params.id);
300+
const result = await p.getView({ id: req.params.id });
298301
if (result.success) {
299302
ctx.logger.debug('View retrieved', { id: req.params.id });
300303
res.json(result);
@@ -349,7 +352,7 @@ export class HonoServerPlugin implements Plugin {
349352
this.server.delete('/api/v1/ui/views/:id', async (req, res) => {
350353
ctx.logger.debug('Delete view request', { id: req.params.id });
351354
try {
352-
const result = await p.deleteView(req.params.id);
355+
const result = await p.deleteView({ id: req.params.id });
353356
if (result.success) {
354357
ctx.logger.info('View deleted', { id: req.params.id });
355358
res.json(result);

packages/plugins/plugin-msw/src/msw-plugin.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export class ObjectStackServer {
5555
}
5656

5757
this.logger?.debug?.('MSW: Finding records', { object, params });
58-
const result = await this.protocol.findData(object, params || {});
59-
this.logger?.debug?.('MSW: Find completed', { object, count: result?.length ?? 0 });
58+
const result = await this.protocol.findData({ object, query: params || {} });
59+
this.logger?.debug?.('MSW: Find completed', { object, count: result?.records?.length ?? 0 });
6060
return {
6161
status: 200,
6262
data: result
@@ -70,7 +70,7 @@ export class ObjectStackServer {
7070

7171
this.logger?.debug?.('MSW: Getting record', { object, id });
7272
try {
73-
const result = await this.protocol.getData(object, id);
73+
const result = await this.protocol.getData({ object, id });
7474
this.logger?.debug?.('MSW: Get completed', { object, id });
7575
return {
7676
status: 200,
@@ -93,7 +93,7 @@ export class ObjectStackServer {
9393

9494
this.logger?.debug?.('MSW: Creating record', { object });
9595
try {
96-
const result = await this.protocol.createData(object, data);
96+
const result = await this.protocol.createData({ object, data });
9797
this.logger?.info?.('MSW: Record created', { object, id: result?.id });
9898
return {
9999
status: 201,
@@ -116,7 +116,7 @@ export class ObjectStackServer {
116116

117117
this.logger?.debug?.('MSW: Updating record', { object, id });
118118
try {
119-
const result = await this.protocol.updateData(object, id, data);
119+
const result = await this.protocol.updateData({ object, id, data });
120120
this.logger?.info?.('MSW: Record updated', { object, id });
121121
return {
122122
status: 200,
@@ -139,8 +139,8 @@ export class ObjectStackServer {
139139

140140
this.logger?.debug?.('MSW: Deleting record', { object, id });
141141
try {
142-
const result = await this.protocol.deleteData(object, id);
143-
this.logger?.info?.('MSW: Record deleted', { object, id, success: result });
142+
const result = await this.protocol.deleteData({ object, id });
143+
this.logger?.info?.('MSW: Record deleted', { object, id, success: result?.success });
144144
return {
145145
status: 200,
146146
data: result
@@ -263,23 +263,23 @@ export class MSWPlugin implements Plugin {
263263
// Define standard ObjectStack API handlers
264264
this.handlers = [
265265
// Discovery endpoint
266-
http.get(`${baseUrl}`, () => {
267-
return HttpResponse.json(protocol.getDiscovery());
266+
http.get(`${baseUrl}`, async () => {
267+
return HttpResponse.json(await protocol.getDiscovery({}));
268268
}),
269269

270270
// Meta endpoints
271-
http.get(`${baseUrl}/meta`, () => {
272-
return HttpResponse.json(protocol.getMetaTypes());
271+
http.get(`${baseUrl}/meta`, async () => {
272+
return HttpResponse.json(await protocol.getMetaTypes({}));
273273
}),
274274

275-
http.get(`${baseUrl}/meta/:type`, ({ params }) => {
276-
return HttpResponse.json(protocol.getMetaItems(params.type as string));
275+
http.get(`${baseUrl}/meta/:type`, async ({ params }) => {
276+
return HttpResponse.json(await protocol.getMetaItems({ type: params.type as string }));
277277
}),
278278

279-
http.get(`${baseUrl}/meta/:type/:name`, ({ params }) => {
279+
http.get(`${baseUrl}/meta/:type/:name`, async ({ params }) => {
280280
try {
281281
return HttpResponse.json(
282-
protocol.getMetaItem(params.type as string, params.name as string)
282+
await protocol.getMetaItem({ type: params.type as string, name: params.name as string })
283283
);
284284
} catch (error) {
285285
const message = error instanceof Error ? error.message : 'Unknown error';
@@ -363,11 +363,11 @@ export class MSWPlugin implements Plugin {
363363
}),
364364

365365
// UI Protocol endpoint
366-
http.get(`${baseUrl}/ui/view/:object`, ({ params, request }) => {
366+
http.get(`${baseUrl}/ui/view/:object`, async ({ params, request }) => {
367367
try {
368368
const url = new URL(request.url);
369369
const viewType = url.searchParams.get('type') || 'list';
370-
const view = protocol.getUiView(params.object as string, viewType as 'list' | 'form');
370+
const view = await protocol.getUiView({ object: params.object as string, type: viewType as 'list' | 'form' });
371371
return HttpResponse.json(view);
372372
} catch (error) {
373373
const message = error instanceof Error ? error.message : 'Unknown error';

0 commit comments

Comments
 (0)