Skip to content

Commit bd86f71

Browse files
committed
feat: add @objectstack/rest package and update runtime to support optional REST API registration
1 parent db22261 commit bd86f71

5 files changed

Lines changed: 22 additions & 19 deletions

File tree

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@objectstack/driver-memory": "workspace:^",
2828
"@objectstack/objectql": "workspace:^",
2929
"@objectstack/plugin-hono-server": "workspace:*",
30+
"@objectstack/rest": "workspace:*",
3031
"@objectstack/runtime": "workspace:^",
3132
"@objectstack/spec": "workspace:*",
3233
"bundle-require": "^5.1.0",

packages/cli/src/commands/serve.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ export const serveCommand = new Command('serve')
226226
} catch (e: any) {
227227
console.warn(chalk.yellow(` ⚠ HTTP server plugin not available: ${e.message}`));
228228
}
229+
230+
// Register REST API plugin (consumes http.server + protocol services)
231+
try {
232+
const { createRestApiPlugin } = await import('@objectstack/rest');
233+
await kernel.use(createRestApiPlugin());
234+
trackPlugin('RestAPI');
235+
} catch (e: any) {
236+
// @objectstack/rest is optional
237+
}
229238
}
230239

231240
// ── Studio UI (--ui) ────────────────────────────────────────────

packages/runtime/src/runtime.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ describe('Runtime', () => {
2424
expect(runtime.getKernel()).toBeDefined();
2525
});
2626

27-
it('should register api registry plugin by default', () => {
27+
it('should not auto-register any plugins', () => {
2828
const runtime = new Runtime();
2929
const kernel = runtime.getKernel();
30-
// Check if use was called (at least once for api registry)
31-
expect(kernel.use).toHaveBeenCalled();
30+
// Runtime is a clean slate — no plugins auto-registered
31+
expect(kernel.use).not.toHaveBeenCalled();
3232
});
3333

3434
it('should register external http server if provided', () => {

packages/runtime/src/runtime.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ObjectKernel, Plugin, IHttpServer, ObjectKernelConfig } from '@objectstack/core';
2-
import { createRestApiPlugin, RestApiPluginConfig } from '@objectstack/rest';
32

43
export interface RuntimeConfig {
54
/**
@@ -8,11 +7,6 @@ export interface RuntimeConfig {
87
* If not provided, Runtime expects a server plugin (like HonoServerPlugin) to be registered manually.
98
*/
109
server?: IHttpServer;
11-
12-
/**
13-
* API Registry Configuration
14-
*/
15-
api?: RestApiPluginConfig;
1610

1711
/**
1812
* Kernel Configuration
@@ -26,8 +20,13 @@ export interface RuntimeConfig {
2620
* High-level entry point for bootstrapping an ObjectStack application.
2721
* Wraps ObjectKernel and provides standard orchestration for:
2822
* - HTTP Server binding
29-
* - API Registry (REST Routes)
3023
* - Plugin Management
24+
*
25+
* REST API is opt-in — register it explicitly:
26+
* ```ts
27+
* import { createRestApiPlugin } from '@objectstack/rest';
28+
* runtime.use(createRestApiPlugin());
29+
* ```
3130
*/
3231
export class Runtime {
3332
readonly kernel: ObjectKernel;
@@ -37,17 +36,8 @@ export class Runtime {
3736

3837
// If external server provided, register it immediately
3938
if (config.server) {
40-
// If the provided server is not already an HttpServer wrapper, wrap it?
41-
// Since IHttpServer is the interface, we assume it complies.
42-
// But HttpServer class in runtime is an adapter.
43-
// If user passes raw Hono, it won't work unless they wrapped it.
44-
// We'll assume they pass a compliant IHttpServer.
4539
this.kernel.registerService('http.server', config.server);
4640
}
47-
48-
// Register API Registry by default
49-
// This plugin is passive (wait for services) so it's safe to add early.
50-
this.kernel.use(createRestApiPlugin(config.api));
5141
}
5242

5343
/**

pnpm-lock.yaml

Lines changed: 3 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)