Skip to content

Commit db22261

Browse files
committed
feat: introduce @objectstack/rest package for REST API management
- Added RouteManager and RouteGroupBuilder for route management. - Implemented RestServer for automatic REST endpoint generation. - Created createRestApiPlugin for integrating REST API functionality. - Updated runtime to use the new REST API plugin. - Removed legacy API registry references and replaced with REST API configurations. - Added TypeScript configuration for the new package. - Updated pnpm-lock.yaml to include new dependencies.
1 parent a799f1e commit db22261

10 files changed

Lines changed: 109 additions & 14 deletions

File tree

packages/rest/package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "@objectstack/rest",
3+
"version": "1.1.0",
4+
"license": "Apache-2.0",
5+
"description": "ObjectStack REST API Server - automatic REST endpoint generation from protocol",
6+
"type": "module",
7+
"main": "dist/index.js",
8+
"types": "dist/index.d.ts",
9+
"exports": {
10+
".": {
11+
"types": "./dist/index.d.ts",
12+
"import": "./dist/index.js",
13+
"require": "./dist/index.cjs"
14+
}
15+
},
16+
"scripts": {
17+
"build": "tsup --config ../../tsup.config.ts",
18+
"dev": "tsc -w",
19+
"test": "vitest run"
20+
},
21+
"dependencies": {
22+
"@objectstack/core": "workspace:*",
23+
"@objectstack/spec": "workspace:*",
24+
"zod": "^3.24.1"
25+
},
26+
"devDependencies": {
27+
"typescript": "^5.0.0",
28+
"vitest": "^4.0.18"
29+
}
30+
}

packages/rest/src/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// REST Server
2+
export { RestServer } from './rest-server.js';
3+
4+
// Route Management
5+
export { RouteManager, RouteGroupBuilder } from './route-manager.js';
6+
export type { RouteEntry } from './route-manager.js';
7+
8+
// REST API Plugin
9+
export { createRestApiPlugin } from './rest-api-plugin.js';
10+
export type { RestApiPluginConfig } from './rest-api-plugin.js';
11+
12+
// Backward-compatible aliases (deprecated)
13+
export { createApiRegistryPlugin } from './rest-api-plugin.js';
14+
export type { ApiRegistryConfig } from './rest-api-plugin.js';

packages/runtime/src/api-registry-plugin.ts renamed to packages/rest/src/rest-api-plugin.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,28 @@ import { Plugin, PluginContext, IHttpServer } from '@objectstack/core';
22
import { RestServer } from './rest-server.js';
33
import { ObjectStackProtocol, RestServerConfig } from '@objectstack/spec/api';
44

5-
export interface ApiRegistryConfig {
5+
export interface RestApiPluginConfig {
66
serverServiceName?: string;
77
protocolServiceName?: string;
88
api?: RestServerConfig;
99
}
1010

1111
/**
12-
* ApiRegistryPlugin
12+
* @deprecated Use {@link RestApiPluginConfig} instead
13+
*/
14+
export type ApiRegistryConfig = RestApiPluginConfig;
15+
16+
/**
17+
* REST API Plugin
1318
*
1419
* Responsibilities:
1520
* 1. Consumes 'http.server' (or configured service)
1621
* 2. Consumes 'protocol' (ObjectStackProtocol)
1722
* 3. Instantiates RestServer to auto-generate routes
1823
*/
19-
export function createApiRegistryPlugin(config: ApiRegistryConfig = {}): Plugin {
24+
export function createRestApiPlugin(config: RestApiPluginConfig = {}): Plugin {
2025
return {
21-
name: 'com.objectstack.runtime.api-registry',
26+
name: 'com.objectstack.rest.api',
2227
version: '1.0.0',
2328

2429
init: async (_ctx: PluginContext) => {
@@ -45,12 +50,12 @@ export function createApiRegistryPlugin(config: ApiRegistryConfig = {}): Plugin
4550
}
4651

4752
if (!server) {
48-
ctx.logger.warn(`ApiRegistryPlugin: HTTP Server service '${serverService}' not found. REST routes skipped.`);
53+
ctx.logger.warn(`RestApiPlugin: HTTP Server service '${serverService}' not found. REST routes skipped.`);
4954
return;
5055
}
5156

5257
if (!protocol) {
53-
ctx.logger.warn(`ApiRegistryPlugin: Protocol service '${protocolService}' not found. REST routes skipped.`);
58+
ctx.logger.warn(`RestApiPlugin: Protocol service '${protocolService}' not found. REST routes skipped.`);
5459
return;
5560
}
5661

@@ -68,3 +73,8 @@ export function createApiRegistryPlugin(config: ApiRegistryConfig = {}): Plugin
6873
}
6974
};
7075
}
76+
77+
/**
78+
* @deprecated Use {@link createRestApiPlugin} instead
79+
*/
80+
export const createApiRegistryPlugin = createRestApiPlugin;

packages/rest/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "./dist",
5+
"rootDir": "./src"
6+
},
7+
"include": ["src/**/*"],
8+
"exclude": ["node_modules", "dist", "**/*.spec.ts", "**/*.test.ts"]
9+
}

packages/runtime/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
},
2121
"dependencies": {
2222
"@objectstack/core": "workspace:*",
23+
"@objectstack/rest": "workspace:*",
2324
"@objectstack/spec": "workspace:*",
2425
"@objectstack/types": "workspace:*",
2526
"zod": "^3.24.1"

packages/runtime/src/index.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,27 @@ export type { RuntimeConfig } from './runtime.js';
88
// Export Plugins
99
export { DriverPlugin } from './driver-plugin.js';
1010
export { AppPlugin } from './app-plugin.js';
11-
export { createApiRegistryPlugin } from './api-registry-plugin.js';
12-
export type { ApiRegistryConfig } from './api-registry-plugin.js';
1311

1412
// Export HTTP Server Components
1513
export { HttpServer } from './http-server.js';
1614
export { HttpDispatcher } from './http-dispatcher.js';
1715
export type { HttpProtocolContext, HttpDispatcherResult } from './http-dispatcher.js';
18-
export { RestServer } from './rest-server.js';
19-
export { RouteManager, RouteGroupBuilder } from './route-manager.js';
20-
export type { RouteEntry } from './route-manager.js';
2116
export { MiddlewareManager } from './middleware.js';
2217

18+
// Re-export from @objectstack/rest for backward compatibility
19+
export {
20+
RestServer,
21+
RouteManager,
22+
RouteGroupBuilder,
23+
createRestApiPlugin,
24+
createApiRegistryPlugin,
25+
} from '@objectstack/rest';
26+
export type {
27+
RouteEntry,
28+
RestApiPluginConfig,
29+
ApiRegistryConfig,
30+
} from '@objectstack/rest';
31+
2332
// Export Types
2433
export * from '@objectstack/core';
2534

packages/runtime/src/runtime.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ObjectKernel, Plugin, IHttpServer, ObjectKernelConfig } from '@objectstack/core';
2-
import { createApiRegistryPlugin, ApiRegistryConfig } from './api-registry-plugin.js';
2+
import { createRestApiPlugin, RestApiPluginConfig } from '@objectstack/rest';
33

44
export interface RuntimeConfig {
55
/**
@@ -12,7 +12,7 @@ export interface RuntimeConfig {
1212
/**
1313
* API Registry Configuration
1414
*/
15-
api?: ApiRegistryConfig;
15+
api?: RestApiPluginConfig;
1616

1717
/**
1818
* Kernel Configuration
@@ -47,7 +47,7 @@ export class Runtime {
4747

4848
// Register API Registry by default
4949
// This plugin is passive (wait for services) so it's safe to add early.
50-
this.kernel.use(createApiRegistryPlugin(config.api));
50+
this.kernel.use(createRestApiPlugin(config.api));
5151
}
5252

5353
/**

pnpm-lock.yaml

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