Skip to content

Commit a3cbe94

Browse files
Copilothotlong
andcommitted
Create @objectql/plugin-server package with Hono adapter
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent f1231cf commit a3cbe94

22 files changed

Lines changed: 3571 additions & 0 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# @objectql/plugin-server
2+
3+
## 3.0.1
4+
5+
### Added
6+
7+
- Initial release as an ObjectQL plugin
8+
- Support for JSON-RPC, REST, GraphQL, and Metadata APIs
9+
- Hono framework adapter
10+
- Express/Node.js adapter
11+
- Plugin-based architecture
12+
- Configurable routes and middleware
13+
- File upload/download support
14+
- Auto-start capability
15+
- Backward compatibility with @objectql/server
16+
17+
### Changed
18+
19+
- Refactored server functionality into plugin architecture
20+
- Improved modularity and extensibility
21+
- Enhanced framework integration support
22+
23+
### Documentation
24+
25+
- Added comprehensive README with examples
26+
- Documented all configuration options
27+
- Included usage examples for Hono, Express, and standalone usage

packages/plugins/server/README.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# @objectql/plugin-server
2+
3+
HTTP server plugin for ObjectQL. Provides Express, Hono, and custom HTTP server support with JSON-RPC, REST, GraphQL, and Metadata APIs.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @objectql/plugin-server
9+
```
10+
11+
## Usage
12+
13+
### As a Plugin
14+
15+
```typescript
16+
import { ObjectQL } from '@objectql/core';
17+
import { ServerPlugin } from '@objectql/plugin-server';
18+
19+
const app = new ObjectQL({
20+
datasources: { /* ... */ },
21+
plugins: [
22+
new ServerPlugin({
23+
port: 3000,
24+
autoStart: true,
25+
enableREST: true,
26+
enableRPC: true,
27+
enableMetadata: true
28+
})
29+
]
30+
});
31+
32+
await app.init();
33+
```
34+
35+
### With Hono Framework
36+
37+
```typescript
38+
import { Hono } from 'hono';
39+
import { ObjectQL } from '@objectql/core';
40+
import { createHonoAdapter } from '@objectql/plugin-server/adapters/hono';
41+
42+
const app = new ObjectQL({ /* ... */ });
43+
await app.init();
44+
45+
const server = new Hono();
46+
const objectqlHandler = createHonoAdapter(app);
47+
48+
server.all('/api/*', objectqlHandler);
49+
50+
export default server;
51+
```
52+
53+
### With Express
54+
55+
```typescript
56+
import express from 'express';
57+
import { ObjectQL } from '@objectql/core';
58+
import { createNodeHandler } from '@objectql/plugin-server';
59+
60+
const app = new ObjectQL({ /* ... */ });
61+
await app.init();
62+
63+
const server = express();
64+
const objectqlHandler = createNodeHandler(app);
65+
66+
server.all('/api/*', objectqlHandler);
67+
68+
server.listen(3000);
69+
```
70+
71+
## Features
72+
73+
### JSON-RPC API
74+
- Protocol-first approach
75+
- Supports all ObjectQL operations
76+
- Type-safe requests and responses
77+
78+
### REST API
79+
- Standard HTTP methods (GET, POST, PUT, DELETE)
80+
- RESTful resource endpoints
81+
- Query parameter support
82+
83+
### GraphQL API
84+
- Auto-generated schema from ObjectQL metadata
85+
- Support for queries and mutations
86+
- Introspection support
87+
88+
### Metadata API
89+
- Explore object schemas
90+
- Discover available operations
91+
- Runtime schema inspection
92+
93+
### File Upload/Download
94+
- Single and batch file uploads
95+
- Secure file storage
96+
- File download support
97+
98+
## Configuration Options
99+
100+
```typescript
101+
interface ServerPluginOptions {
102+
port?: number; // Default: 3000
103+
host?: string; // Default: 'localhost'
104+
routes?: ApiRouteConfig; // Custom route configuration
105+
fileStorage?: IFileStorage; // Custom file storage
106+
enableGraphQL?: boolean; // Default: false
107+
enableREST?: boolean; // Default: true
108+
enableMetadata?: boolean; // Default: true
109+
enableRPC?: boolean; // Default: true
110+
autoStart?: boolean; // Default: false
111+
middleware?: Function[]; // Custom middleware
112+
}
113+
```
114+
115+
## API Routes
116+
117+
Default routes (customizable):
118+
- JSON-RPC: `/api/objectql`
119+
- REST: `/api/data`
120+
- GraphQL: `/api/graphql`
121+
- Metadata: `/api/metadata`
122+
- Files: `/api/files`
123+
124+
## License
125+
126+
MIT
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
roots: ['<rootDir>/test'],
5+
testMatch: ['**/*.test.ts'],
6+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
7+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "@objectql/plugin-server",
3+
"version": "3.0.1",
4+
"description": "HTTP server plugin for ObjectQL - Provides Express, Hono and REST API support",
5+
"keywords": [
6+
"objectql",
7+
"plugin",
8+
"server",
9+
"http",
10+
"api",
11+
"rest",
12+
"graphql",
13+
"express",
14+
"hono",
15+
"adapter",
16+
"backend"
17+
],
18+
"license": "MIT",
19+
"main": "dist/index.js",
20+
"types": "dist/index.d.ts",
21+
"scripts": {
22+
"build": "tsc",
23+
"test": "jest"
24+
},
25+
"dependencies": {
26+
"@objectql/core": "workspace:*",
27+
"@objectql/types": "workspace:*",
28+
"graphql": "^16.8.1",
29+
"@graphql-tools/schema": "^10.0.2",
30+
"js-yaml": "^4.1.1"
31+
},
32+
"peerDependencies": {
33+
"hono": "^4.11.0"
34+
},
35+
"peerDependenciesMeta": {
36+
"hono": {
37+
"optional": true
38+
}
39+
},
40+
"devDependencies": {
41+
"@types/js-yaml": "^4.0.9",
42+
"@types/node": "^20.10.0",
43+
"hono": "^4.11.0",
44+
"typescript": "^5.3.0"
45+
}
46+
}

0 commit comments

Comments
 (0)