Skip to content

Commit b157edb

Browse files
committed
feat: enhance Hono and MSW plugins with improved exports and new ObjectStackServer class for better API interaction
1 parent 4c601da commit b157edb

5 files changed

Lines changed: 86 additions & 13 deletions

File tree

packages/adapters/hono/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
"license": "Apache-2.0",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
7+
"exports": {
8+
".": {
9+
"types": "./dist/index.d.ts",
10+
"import": "./dist/index.js",
11+
"require": "./dist/index.js"
12+
}
13+
},
714
"scripts": {
815
"build": "tsc"
916
},

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,3 @@ export class HonoServerPlugin implements Plugin {
120120
console.log('[HonoServerPlugin] Server stopped');
121121
}
122122
}
123-
124-
125-
/**
126-
* Destroy phase - Stop server
127-
*/
128-
async destroy() {
129-
this.server.close();
130-
// Note: Can't use ctx.logger here since we're in destroy
131-
console.log('[HonoServerPlugin] Server stopped');
132-
}
133-
}

packages/plugins/plugin-msw/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
"@objectstack/runtime": "^1.0.1"
1414
},
1515
"dependencies": {
16+
"@objectstack/core": "^1.0.1",
17+
"@objectstack/objectql": "workspace:*",
1618
"@objectstack/spec": "workspace:*",
1719
"@objectstack/types": "workspace:*",
18-
"@objectstack/objectql": "workspace:*",
1920
"msw": "^2.0.0"
2021
},
2122
"devDependencies": {

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '@objectstack/runtime';
1010
// import { ObjectStackProtocolImplementation } from '@objectstack/objectql';
1111
import { ObjectStackProtocol } from '@objectstack/spec/api';
12-
// import { IDataEngine } from '@objectstack/core';
12+
import { IDataEngine } from '@objectstack/core';
1313

1414
// Helper for parsing query parameters
1515
function parseQueryParams(url: URL): Record<string, any> {
@@ -314,3 +314,46 @@ export class MSWPlugin implements Plugin {
314314
return this.handlers;
315315
}
316316
}
317+
318+
/**
319+
* Static helper for interacting with ObjectStack protocol in MSW handlers
320+
*/
321+
export class ObjectStackServer {
322+
private static protocol: ObjectStackProtocol;
323+
324+
static init(protocol: ObjectStackProtocol) {
325+
this.protocol = protocol;
326+
}
327+
328+
private static getProtocol(): ObjectStackProtocol {
329+
if (!this.protocol) {
330+
throw new Error('ObjectStackServer not initialized. Call ObjectStackServer.init(protocol) first.');
331+
}
332+
return this.protocol;
333+
}
334+
335+
static async findData(objectName: string, query?: any) {
336+
const body = await this.getProtocol().findData({ object: objectName, query });
337+
return { data: body, status: 200 };
338+
}
339+
340+
static async getData(objectName: string, id: string) {
341+
const body = await this.getProtocol().getData({ object: objectName, id });
342+
return { data: body, status: 200 };
343+
}
344+
345+
static async createData(objectName: string, data: any) {
346+
const body = await this.getProtocol().createData({ object: objectName, data });
347+
return { data: body, status: 201 };
348+
}
349+
350+
static async updateData(objectName: string, id: string, data: any) {
351+
const body = await this.getProtocol().updateData({ object: objectName, id, data });
352+
return { data: body, status: 200 };
353+
}
354+
355+
static async deleteData(objectName: string, id: string) {
356+
const body = await this.getProtocol().deleteData({ object: objectName, id });
357+
return { data: body, status: 200 };
358+
}
359+
}

pnpm-lock.yaml

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)