@objectstack/plugin-hono-server 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +22 -0
- package/CHANGELOG.md +29 -0
- package/dist/index.d.mts +98 -0
- package/dist/index.d.ts +98 -2
- package/dist/index.js +307 -15
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +297 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +7 -7
- package/src/hono-plugin.test.ts +38 -1
- package/src/hono-plugin.ts +101 -1
- package/dist/adapter.d.ts +0 -29
- package/dist/adapter.js +0 -145
- package/dist/hono-plugin.d.ts +0 -49
- package/dist/hono-plugin.js +0 -90
package/dist/adapter.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.HonoHttpServer = void 0;
|
|
18
|
-
// Export IHttpServer from core
|
|
19
|
-
__exportStar(require("@objectstack/core"), exports);
|
|
20
|
-
const hono_1 = require("hono");
|
|
21
|
-
const node_server_1 = require("@hono/node-server");
|
|
22
|
-
const serve_static_1 = require("@hono/node-server/serve-static");
|
|
23
|
-
/**
|
|
24
|
-
* Hono Implementation of IHttpServer
|
|
25
|
-
*/
|
|
26
|
-
class HonoHttpServer {
|
|
27
|
-
port;
|
|
28
|
-
staticRoot;
|
|
29
|
-
app;
|
|
30
|
-
server;
|
|
31
|
-
listeningPort;
|
|
32
|
-
constructor(port = 3000, staticRoot) {
|
|
33
|
-
this.port = port;
|
|
34
|
-
this.staticRoot = staticRoot;
|
|
35
|
-
this.app = new hono_1.Hono();
|
|
36
|
-
}
|
|
37
|
-
// internal helper to convert standard handler to Hono handler
|
|
38
|
-
wrap(handler) {
|
|
39
|
-
return async (c) => {
|
|
40
|
-
let body = {};
|
|
41
|
-
// Try to parse JSON body first if content-type is JSON
|
|
42
|
-
if (c.req.header('content-type')?.includes('application/json')) {
|
|
43
|
-
try {
|
|
44
|
-
body = await c.req.json();
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
// If JSON parsing fails, try parseBody
|
|
48
|
-
try {
|
|
49
|
-
body = await c.req.parseBody();
|
|
50
|
-
}
|
|
51
|
-
catch (e2) { }
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// For non-JSON content types, use parseBody
|
|
56
|
-
try {
|
|
57
|
-
body = await c.req.parseBody();
|
|
58
|
-
}
|
|
59
|
-
catch (e) { }
|
|
60
|
-
}
|
|
61
|
-
const req = {
|
|
62
|
-
params: c.req.param(),
|
|
63
|
-
query: c.req.query(),
|
|
64
|
-
body,
|
|
65
|
-
headers: c.req.header(),
|
|
66
|
-
method: c.req.method,
|
|
67
|
-
path: c.req.path
|
|
68
|
-
};
|
|
69
|
-
let capturedResponse;
|
|
70
|
-
const res = {
|
|
71
|
-
json: (data) => { capturedResponse = c.json(data); },
|
|
72
|
-
send: (data) => { capturedResponse = c.html(data); },
|
|
73
|
-
status: (code) => { c.status(code); return res; },
|
|
74
|
-
header: (name, value) => { c.header(name, value); return res; }
|
|
75
|
-
};
|
|
76
|
-
await handler(req, res);
|
|
77
|
-
return capturedResponse;
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
get(path, handler) {
|
|
81
|
-
this.app.get(path, this.wrap(handler));
|
|
82
|
-
}
|
|
83
|
-
post(path, handler) {
|
|
84
|
-
this.app.post(path, this.wrap(handler));
|
|
85
|
-
}
|
|
86
|
-
put(path, handler) {
|
|
87
|
-
this.app.put(path, this.wrap(handler));
|
|
88
|
-
}
|
|
89
|
-
delete(path, handler) {
|
|
90
|
-
this.app.delete(path, this.wrap(handler));
|
|
91
|
-
}
|
|
92
|
-
patch(path, handler) {
|
|
93
|
-
this.app.patch(path, this.wrap(handler));
|
|
94
|
-
}
|
|
95
|
-
use(pathOrHandler, handler) {
|
|
96
|
-
if (typeof pathOrHandler === 'string' && handler) {
|
|
97
|
-
// Path based middleware
|
|
98
|
-
// Hono middleware signature is different (c, next) => ...
|
|
99
|
-
this.app.use(pathOrHandler, async (c, next) => {
|
|
100
|
-
// Simplistic conversion
|
|
101
|
-
await handler({}, {}, next);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
else if (typeof pathOrHandler === 'function') {
|
|
105
|
-
// Global middleware
|
|
106
|
-
this.app.use('*', async (c, next) => {
|
|
107
|
-
await pathOrHandler({}, {}, next);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Mount a sub-application or router
|
|
113
|
-
*/
|
|
114
|
-
mount(path, subApp) {
|
|
115
|
-
this.app.route(path, subApp);
|
|
116
|
-
}
|
|
117
|
-
async listen(port) {
|
|
118
|
-
return new Promise((resolve) => {
|
|
119
|
-
if (this.staticRoot) {
|
|
120
|
-
this.app.get('/*', (0, serve_static_1.serveStatic)({ root: this.staticRoot }));
|
|
121
|
-
}
|
|
122
|
-
const targetPort = port || this.port;
|
|
123
|
-
this.server = (0, node_server_1.serve)({
|
|
124
|
-
fetch: this.app.fetch,
|
|
125
|
-
port: targetPort
|
|
126
|
-
}, (info) => {
|
|
127
|
-
this.listeningPort = info.port;
|
|
128
|
-
resolve();
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
getPort() {
|
|
133
|
-
return this.listeningPort || this.port;
|
|
134
|
-
}
|
|
135
|
-
// Expose raw app for scenarios where standard interface is not enough
|
|
136
|
-
getRawApp() {
|
|
137
|
-
return this.app;
|
|
138
|
-
}
|
|
139
|
-
async close() {
|
|
140
|
-
if (this.server && typeof this.server.close === 'function') {
|
|
141
|
-
this.server.close();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
exports.HonoHttpServer = HonoHttpServer;
|
package/dist/hono-plugin.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Plugin, PluginContext } from '@objectstack/core';
|
|
2
|
-
import { RestServerConfig } from '@objectstack/spec/api';
|
|
3
|
-
export interface HonoPluginOptions {
|
|
4
|
-
port?: number;
|
|
5
|
-
staticRoot?: string;
|
|
6
|
-
/**
|
|
7
|
-
* REST server configuration
|
|
8
|
-
* Controls automatic endpoint generation and API behavior
|
|
9
|
-
*/
|
|
10
|
-
restConfig?: RestServerConfig;
|
|
11
|
-
/**
|
|
12
|
-
* Whether to register standard ObjectStack CRUD endpoints
|
|
13
|
-
* @default true
|
|
14
|
-
*/
|
|
15
|
-
registerStandardEndpoints?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Whether to load endpoints from API Registry
|
|
18
|
-
* @default true
|
|
19
|
-
*/
|
|
20
|
-
useApiRegistry?: boolean;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Hono Server Plugin
|
|
24
|
-
*
|
|
25
|
-
* Provides HTTP server capabilities using Hono framework.
|
|
26
|
-
* Registers routes for ObjectStack Runtime Protocol.
|
|
27
|
-
*/
|
|
28
|
-
export declare class HonoServerPlugin implements Plugin {
|
|
29
|
-
name: string;
|
|
30
|
-
version: string;
|
|
31
|
-
private static readonly DEFAULT_ENDPOINT_PRIORITY;
|
|
32
|
-
private static readonly CORE_ENDPOINT_PRIORITY;
|
|
33
|
-
private static readonly DISCOVERY_ENDPOINT_PRIORITY;
|
|
34
|
-
private options;
|
|
35
|
-
private server;
|
|
36
|
-
constructor(options?: HonoPluginOptions);
|
|
37
|
-
/**
|
|
38
|
-
* Init phase - Setup HTTP server and register as service
|
|
39
|
-
*/
|
|
40
|
-
init: (ctx: PluginContext) => Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* Start phase - Bind routes and start listening
|
|
43
|
-
*/
|
|
44
|
-
start: (ctx: PluginContext) => Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* Destroy phase - Stop server
|
|
47
|
-
*/
|
|
48
|
-
destroy(): Promise<void>;
|
|
49
|
-
}
|
package/dist/hono-plugin.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HonoServerPlugin = void 0;
|
|
4
|
-
const adapter_1 = require("./adapter");
|
|
5
|
-
const hono_1 = require("@objectstack/hono");
|
|
6
|
-
/**
|
|
7
|
-
* Hono Server Plugin
|
|
8
|
-
*
|
|
9
|
-
* Provides HTTP server capabilities using Hono framework.
|
|
10
|
-
* Registers routes for ObjectStack Runtime Protocol.
|
|
11
|
-
*/
|
|
12
|
-
class HonoServerPlugin {
|
|
13
|
-
name = 'com.objectstack.server.hono';
|
|
14
|
-
version = '0.9.0';
|
|
15
|
-
// Constants
|
|
16
|
-
static DEFAULT_ENDPOINT_PRIORITY = 100;
|
|
17
|
-
static CORE_ENDPOINT_PRIORITY = 950;
|
|
18
|
-
static DISCOVERY_ENDPOINT_PRIORITY = 900;
|
|
19
|
-
options;
|
|
20
|
-
server;
|
|
21
|
-
constructor(options = {}) {
|
|
22
|
-
this.options = {
|
|
23
|
-
port: 3000,
|
|
24
|
-
registerStandardEndpoints: true,
|
|
25
|
-
useApiRegistry: true,
|
|
26
|
-
...options
|
|
27
|
-
};
|
|
28
|
-
this.server = new adapter_1.HonoHttpServer(this.options.port, this.options.staticRoot);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Init phase - Setup HTTP server and register as service
|
|
32
|
-
*/
|
|
33
|
-
init = async (ctx) => {
|
|
34
|
-
ctx.logger.debug('Initializing Hono server plugin', {
|
|
35
|
-
port: this.options.port,
|
|
36
|
-
staticRoot: this.options.staticRoot
|
|
37
|
-
});
|
|
38
|
-
// Register HTTP server service as IHttpServer
|
|
39
|
-
// Register as 'http.server' to match core requirements
|
|
40
|
-
ctx.registerService('http.server', this.server);
|
|
41
|
-
// Alias 'http-server' for backward compatibility
|
|
42
|
-
ctx.registerService('http-server', this.server);
|
|
43
|
-
ctx.logger.debug('HTTP server service registered', { serviceName: 'http.server' });
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Start phase - Bind routes and start listening
|
|
47
|
-
*/
|
|
48
|
-
start = async (ctx) => {
|
|
49
|
-
ctx.logger.debug('Starting Hono server plugin');
|
|
50
|
-
// Use Standard ObjectStack Runtime Hono App
|
|
51
|
-
try {
|
|
52
|
-
const kernel = ctx.getKernel();
|
|
53
|
-
const config = this.options.restConfig || {};
|
|
54
|
-
// Calculate prefix similar to before
|
|
55
|
-
const apiVersion = config.api?.version || 'v1';
|
|
56
|
-
const basePath = config.api?.basePath || '/api';
|
|
57
|
-
const apiPath = config.api?.apiPath || `${basePath}/${apiVersion}`;
|
|
58
|
-
const app = (0, hono_1.createHonoApp)({
|
|
59
|
-
kernel,
|
|
60
|
-
prefix: apiPath // Use the calculated path
|
|
61
|
-
});
|
|
62
|
-
ctx.logger.debug('Mounting ObjectStack Runtime App', { prefix: apiPath });
|
|
63
|
-
// Use the mount method we added to HonoHttpServer
|
|
64
|
-
this.server.mount('/', app);
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
ctx.logger.error('Failed to create standard Hono app', e);
|
|
68
|
-
}
|
|
69
|
-
// Start server on kernel:ready hook
|
|
70
|
-
ctx.hook('kernel:ready', async () => {
|
|
71
|
-
const port = this.options.port || 3000;
|
|
72
|
-
ctx.logger.debug('Starting HTTP server', { port });
|
|
73
|
-
await this.server.listen(port);
|
|
74
|
-
const actualPort = this.server.getPort();
|
|
75
|
-
ctx.logger.info('HTTP server started successfully', {
|
|
76
|
-
port: actualPort,
|
|
77
|
-
url: `http://localhost:${actualPort}`
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Destroy phase - Stop server
|
|
83
|
-
*/
|
|
84
|
-
async destroy() {
|
|
85
|
-
this.server.close();
|
|
86
|
-
// Note: Can't use ctx.logger here since we're in destroy
|
|
87
|
-
console.log('[HonoServerPlugin] Server stopped');
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
exports.HonoServerPlugin = HonoServerPlugin;
|