@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.
@@ -0,0 +1,22 @@
1
+
2
+ > @objectstack/plugin-hono-server@1.0.6 build /home/runner/work/spec/spec/packages/plugins/plugin-hono-server
3
+ > tsup --config ../../../tsup.config.ts
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.1
8
+ CLI Using tsup config: /home/runner/work/spec/spec/tsup.config.ts
9
+ CLI Target: es2020
10
+ CLI Cleaning output folder
11
+ ESM Build start
12
+ CJS Build start
13
+ ESM dist/index.mjs 9.43 KB
14
+ ESM dist/index.mjs.map 17.97 KB
15
+ ESM ⚡️ Build success in 22ms
16
+ CJS dist/index.js 10.38 KB
17
+ CJS dist/index.js.map 17.98 KB
18
+ CJS ⚡️ Build success in 22ms
19
+ DTS Build start
20
+ DTS ⚡️ Build success in 3388ms
21
+ DTS dist/index.d.mts 2.83 KB
22
+ DTS dist/index.d.ts 2.83 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # @objectstack/plugin-hono-server
2
2
 
3
+ ## 1.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [a7f7b9d]
8
+ - @objectstack/spec@1.0.6
9
+ - @objectstack/core@1.0.6
10
+ - @objectstack/runtime@1.0.6
11
+ - @objectstack/types@1.0.6
12
+ - @objectstack/hono@1.0.6
13
+
14
+ ## 1.0.5
15
+
16
+ ### Patch Changes
17
+
18
+ - b1d24bd: refactor: migrate build system from tsc to tsup for faster builds
19
+ - Replaced `tsc` with `tsup` (using esbuild) across all packages
20
+ - Added shared `tsup.config.ts` in workspace root
21
+ - Added `tsup` as workspace dev dependency
22
+ - significantly improved build performance
23
+ - 877b864: fix: add SPA fallback to hono, fix msw context binding, improve runtime resilience, and fix client-react build types
24
+ - Updated dependencies [b1d24bd]
25
+ - Updated dependencies [877b864]
26
+ - @objectstack/core@1.0.5
27
+ - @objectstack/runtime@1.0.5
28
+ - @objectstack/hono@1.0.5
29
+ - @objectstack/types@1.0.5
30
+ - @objectstack/spec@1.0.5
31
+
3
32
  ## 1.0.4
4
33
 
5
34
  ### Patch Changes
@@ -0,0 +1,98 @@
1
+ import { Plugin, PluginContext, IHttpServer, RouteHandler, Middleware } from '@objectstack/core';
2
+ export * from '@objectstack/core';
3
+ import { RestServerConfig } from '@objectstack/spec/api';
4
+ import * as hono_types from 'hono/types';
5
+ import { Hono } from 'hono';
6
+
7
+ interface StaticMount {
8
+ root: string;
9
+ path?: string;
10
+ rewrite?: boolean;
11
+ spa?: boolean;
12
+ }
13
+ interface HonoPluginOptions {
14
+ port?: number;
15
+ staticRoot?: string;
16
+ /**
17
+ * Multiple static resource mounts
18
+ */
19
+ staticMounts?: StaticMount[];
20
+ /**
21
+ * REST server configuration
22
+ * Controls automatic endpoint generation and API behavior
23
+ */
24
+ restConfig?: RestServerConfig;
25
+ /**
26
+ * Whether to register standard ObjectStack CRUD endpoints
27
+ * @default true
28
+ */
29
+ registerStandardEndpoints?: boolean;
30
+ /**
31
+ * Whether to load endpoints from API Registry
32
+ * @default true
33
+ */
34
+ useApiRegistry?: boolean;
35
+ /**
36
+ * Whether to enable SPA fallback
37
+ * If true, returns index.html for non-API 404s
38
+ * @default false
39
+ */
40
+ spaFallback?: boolean;
41
+ }
42
+ /**
43
+ * Hono Server Plugin
44
+ *
45
+ * Provides HTTP server capabilities using Hono framework.
46
+ * Registers routes for ObjectStack Runtime Protocol.
47
+ */
48
+ declare class HonoServerPlugin implements Plugin {
49
+ name: string;
50
+ version: string;
51
+ private static readonly DEFAULT_ENDPOINT_PRIORITY;
52
+ private static readonly CORE_ENDPOINT_PRIORITY;
53
+ private static readonly DISCOVERY_ENDPOINT_PRIORITY;
54
+ private options;
55
+ private server;
56
+ constructor(options?: HonoPluginOptions);
57
+ /**
58
+ * Init phase - Setup HTTP server and register as service
59
+ */
60
+ init: (ctx: PluginContext) => Promise<void>;
61
+ /**
62
+ * Start phase - Bind routes and start listening
63
+ */
64
+ start: (ctx: PluginContext) => Promise<void>;
65
+ /**
66
+ * Destroy phase - Stop server
67
+ */
68
+ destroy(): Promise<void>;
69
+ }
70
+
71
+ /**
72
+ * Hono Implementation of IHttpServer
73
+ */
74
+ declare class HonoHttpServer implements IHttpServer {
75
+ private port;
76
+ private staticRoot?;
77
+ private app;
78
+ private server;
79
+ private listeningPort;
80
+ constructor(port?: number, staticRoot?: string | undefined);
81
+ private wrap;
82
+ get(path: string, handler: RouteHandler): void;
83
+ post(path: string, handler: RouteHandler): void;
84
+ put(path: string, handler: RouteHandler): void;
85
+ delete(path: string, handler: RouteHandler): void;
86
+ patch(path: string, handler: RouteHandler): void;
87
+ use(pathOrHandler: string | Middleware, handler?: Middleware): void;
88
+ /**
89
+ * Mount a sub-application or router
90
+ */
91
+ mount(path: string, subApp: Hono): void;
92
+ listen(port: number): Promise<void>;
93
+ getPort(): number;
94
+ getRawApp(): Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
95
+ close(): Promise<void>;
96
+ }
97
+
98
+ export { HonoHttpServer, type HonoPluginOptions, HonoServerPlugin, type StaticMount };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,98 @@
1
- export * from './hono-plugin';
2
- export * from './adapter';
1
+ import { Plugin, PluginContext, IHttpServer, RouteHandler, Middleware } from '@objectstack/core';
2
+ export * from '@objectstack/core';
3
+ import { RestServerConfig } from '@objectstack/spec/api';
4
+ import * as hono_types from 'hono/types';
5
+ import { Hono } from 'hono';
6
+
7
+ interface StaticMount {
8
+ root: string;
9
+ path?: string;
10
+ rewrite?: boolean;
11
+ spa?: boolean;
12
+ }
13
+ interface HonoPluginOptions {
14
+ port?: number;
15
+ staticRoot?: string;
16
+ /**
17
+ * Multiple static resource mounts
18
+ */
19
+ staticMounts?: StaticMount[];
20
+ /**
21
+ * REST server configuration
22
+ * Controls automatic endpoint generation and API behavior
23
+ */
24
+ restConfig?: RestServerConfig;
25
+ /**
26
+ * Whether to register standard ObjectStack CRUD endpoints
27
+ * @default true
28
+ */
29
+ registerStandardEndpoints?: boolean;
30
+ /**
31
+ * Whether to load endpoints from API Registry
32
+ * @default true
33
+ */
34
+ useApiRegistry?: boolean;
35
+ /**
36
+ * Whether to enable SPA fallback
37
+ * If true, returns index.html for non-API 404s
38
+ * @default false
39
+ */
40
+ spaFallback?: boolean;
41
+ }
42
+ /**
43
+ * Hono Server Plugin
44
+ *
45
+ * Provides HTTP server capabilities using Hono framework.
46
+ * Registers routes for ObjectStack Runtime Protocol.
47
+ */
48
+ declare class HonoServerPlugin implements Plugin {
49
+ name: string;
50
+ version: string;
51
+ private static readonly DEFAULT_ENDPOINT_PRIORITY;
52
+ private static readonly CORE_ENDPOINT_PRIORITY;
53
+ private static readonly DISCOVERY_ENDPOINT_PRIORITY;
54
+ private options;
55
+ private server;
56
+ constructor(options?: HonoPluginOptions);
57
+ /**
58
+ * Init phase - Setup HTTP server and register as service
59
+ */
60
+ init: (ctx: PluginContext) => Promise<void>;
61
+ /**
62
+ * Start phase - Bind routes and start listening
63
+ */
64
+ start: (ctx: PluginContext) => Promise<void>;
65
+ /**
66
+ * Destroy phase - Stop server
67
+ */
68
+ destroy(): Promise<void>;
69
+ }
70
+
71
+ /**
72
+ * Hono Implementation of IHttpServer
73
+ */
74
+ declare class HonoHttpServer implements IHttpServer {
75
+ private port;
76
+ private staticRoot?;
77
+ private app;
78
+ private server;
79
+ private listeningPort;
80
+ constructor(port?: number, staticRoot?: string | undefined);
81
+ private wrap;
82
+ get(path: string, handler: RouteHandler): void;
83
+ post(path: string, handler: RouteHandler): void;
84
+ put(path: string, handler: RouteHandler): void;
85
+ delete(path: string, handler: RouteHandler): void;
86
+ patch(path: string, handler: RouteHandler): void;
87
+ use(pathOrHandler: string | Middleware, handler?: Middleware): void;
88
+ /**
89
+ * Mount a sub-application or router
90
+ */
91
+ mount(path: string, subApp: Hono): void;
92
+ listen(port: number): Promise<void>;
93
+ getPort(): number;
94
+ getRawApp(): Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
95
+ close(): Promise<void>;
96
+ }
97
+
98
+ export { HonoHttpServer, type HonoPluginOptions, HonoServerPlugin, type StaticMount };
package/dist/index.js CHANGED
@@ -1,18 +1,310 @@
1
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]; } };
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
+
33
+ // src/index.ts
34
+ var index_exports = {};
35
+ __export(index_exports, {
36
+ HonoHttpServer: () => HonoHttpServer,
37
+ HonoServerPlugin: () => HonoServerPlugin
38
+ });
39
+ module.exports = __toCommonJS(index_exports);
40
+
41
+ // src/adapter.ts
42
+ var adapter_exports = {};
43
+ __export(adapter_exports, {
44
+ HonoHttpServer: () => HonoHttpServer
45
+ });
46
+ __reExport(adapter_exports, require("@objectstack/core"));
47
+ var import_hono = require("hono");
48
+ var import_node_server = require("@hono/node-server");
49
+ var import_serve_static = require("@hono/node-server/serve-static");
50
+ var HonoHttpServer = class {
51
+ constructor(port = 3e3, staticRoot) {
52
+ this.port = port;
53
+ this.staticRoot = staticRoot;
54
+ __publicField(this, "app");
55
+ __publicField(this, "server");
56
+ __publicField(this, "listeningPort");
57
+ this.app = new import_hono.Hono();
58
+ }
59
+ // internal helper to convert standard handler to Hono handler
60
+ wrap(handler) {
61
+ return async (c) => {
62
+ let body = {};
63
+ if (c.req.header("content-type")?.includes("application/json")) {
64
+ try {
65
+ body = await c.req.json();
66
+ } catch (e) {
67
+ try {
68
+ body = await c.req.parseBody();
69
+ } catch (e2) {
70
+ }
71
+ }
72
+ } else {
73
+ try {
74
+ body = await c.req.parseBody();
75
+ } catch (e) {
76
+ }
77
+ }
78
+ const req = {
79
+ params: c.req.param(),
80
+ query: c.req.query(),
81
+ body,
82
+ headers: c.req.header(),
83
+ method: c.req.method,
84
+ path: c.req.path
85
+ };
86
+ let capturedResponse;
87
+ const res = {
88
+ json: (data) => {
89
+ capturedResponse = c.json(data);
90
+ },
91
+ send: (data) => {
92
+ capturedResponse = c.html(data);
93
+ },
94
+ status: (code) => {
95
+ c.status(code);
96
+ return res;
97
+ },
98
+ header: (name, value) => {
99
+ c.header(name, value);
100
+ return res;
101
+ }
102
+ };
103
+ await handler(req, res);
104
+ return capturedResponse;
105
+ };
106
+ }
107
+ get(path2, handler) {
108
+ this.app.get(path2, this.wrap(handler));
109
+ }
110
+ post(path2, handler) {
111
+ this.app.post(path2, this.wrap(handler));
112
+ }
113
+ put(path2, handler) {
114
+ this.app.put(path2, this.wrap(handler));
115
+ }
116
+ delete(path2, handler) {
117
+ this.app.delete(path2, this.wrap(handler));
118
+ }
119
+ patch(path2, handler) {
120
+ this.app.patch(path2, this.wrap(handler));
121
+ }
122
+ use(pathOrHandler, handler) {
123
+ if (typeof pathOrHandler === "string" && handler) {
124
+ this.app.use(pathOrHandler, async (c, next) => {
125
+ await handler({}, {}, next);
126
+ });
127
+ } else if (typeof pathOrHandler === "function") {
128
+ this.app.use("*", async (c, next) => {
129
+ await pathOrHandler({}, {}, next);
130
+ });
7
131
  }
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);
132
+ }
133
+ /**
134
+ * Mount a sub-application or router
135
+ */
136
+ mount(path2, subApp) {
137
+ this.app.route(path2, subApp);
138
+ }
139
+ async listen(port) {
140
+ return new Promise((resolve2) => {
141
+ if (this.staticRoot) {
142
+ this.app.get("/*", (0, import_serve_static.serveStatic)({ root: this.staticRoot }));
143
+ }
144
+ const targetPort = port || this.port;
145
+ this.server = (0, import_node_server.serve)({
146
+ fetch: this.app.fetch,
147
+ port: targetPort
148
+ }, (info) => {
149
+ this.listeningPort = info.port;
150
+ resolve2();
151
+ });
152
+ });
153
+ }
154
+ getPort() {
155
+ return this.listeningPort || this.port;
156
+ }
157
+ // Expose raw app for scenarios where standard interface is not enough
158
+ getRawApp() {
159
+ return this.app;
160
+ }
161
+ async close() {
162
+ if (this.server && typeof this.server.close === "function") {
163
+ this.server.close();
164
+ }
165
+ }
166
+ };
167
+
168
+ // src/hono-plugin.ts
169
+ var import_hono2 = require("@objectstack/hono");
170
+ var import_serve_static2 = require("@hono/node-server/serve-static");
171
+ var fs = __toESM(require("fs"));
172
+ var path = __toESM(require("path"));
173
+ var HonoServerPlugin = class {
174
+ constructor(options = {}) {
175
+ __publicField(this, "name", "com.objectstack.server.hono");
176
+ __publicField(this, "version", "0.9.0");
177
+ __publicField(this, "options");
178
+ __publicField(this, "server");
179
+ /**
180
+ * Init phase - Setup HTTP server and register as service
181
+ */
182
+ __publicField(this, "init", async (ctx) => {
183
+ ctx.logger.debug("Initializing Hono server plugin", {
184
+ port: this.options.port,
185
+ staticRoot: this.options.staticRoot
186
+ });
187
+ ctx.registerService("http.server", this.server);
188
+ ctx.registerService("http-server", this.server);
189
+ ctx.logger.debug("HTTP server service registered", { serviceName: "http.server" });
190
+ });
191
+ /**
192
+ * Start phase - Bind routes and start listening
193
+ */
194
+ __publicField(this, "start", async (ctx) => {
195
+ ctx.logger.debug("Starting Hono server plugin");
196
+ try {
197
+ const kernel = ctx.getKernel();
198
+ const config = this.options.restConfig || {};
199
+ const apiVersion = config.api?.version || "v1";
200
+ const basePath = config.api?.basePath || "/api";
201
+ const apiPath = config.api?.apiPath || `${basePath}/${apiVersion}`;
202
+ const app = (0, import_hono2.createHonoApp)({
203
+ kernel,
204
+ prefix: apiPath
205
+ // Use the calculated path
206
+ });
207
+ ctx.logger.debug("Mounting ObjectStack Runtime App", { prefix: apiPath });
208
+ this.server.mount("/", app);
209
+ } catch (e) {
210
+ ctx.logger.error("Failed to create standard Hono app", e);
211
+ }
212
+ const mounts = this.options.staticMounts || [];
213
+ if (this.options.staticRoot) {
214
+ mounts.push({
215
+ root: this.options.staticRoot,
216
+ path: "/",
217
+ rewrite: false,
218
+ spa: this.options.spaFallback
219
+ });
220
+ }
221
+ if (mounts.length > 0) {
222
+ const rawApp = this.server.getRawApp();
223
+ for (const mount of mounts) {
224
+ const mountRoot = path.resolve(process.cwd(), mount.root);
225
+ if (!fs.existsSync(mountRoot)) {
226
+ ctx.logger.warn(`Static mount root not found: ${mountRoot}. Skipping.`);
227
+ continue;
228
+ }
229
+ const mountPath = mount.path || "/";
230
+ const normalizedPath = mountPath.startsWith("/") ? mountPath : `/${mountPath}`;
231
+ const routePattern = normalizedPath === "/" ? "/*" : `${normalizedPath.replace(/\/$/, "")}/*`;
232
+ const routes = normalizedPath === "/" ? [routePattern] : [normalizedPath, routePattern];
233
+ ctx.logger.debug("Mounting static files", {
234
+ to: routes,
235
+ from: mountRoot,
236
+ rewrite: mount.rewrite,
237
+ spa: mount.spa
238
+ });
239
+ routes.forEach((route) => {
240
+ rawApp.get(
241
+ route,
242
+ (0, import_serve_static2.serveStatic)({
243
+ root: mount.root,
244
+ rewriteRequestPath: (reqPath) => {
245
+ if (mount.rewrite && normalizedPath !== "/") {
246
+ if (reqPath.startsWith(normalizedPath)) {
247
+ return reqPath.substring(normalizedPath.length) || "/";
248
+ }
249
+ }
250
+ return reqPath;
251
+ }
252
+ })
253
+ );
254
+ if (mount.spa) {
255
+ rawApp.get(route, async (c, next) => {
256
+ const config = this.options.restConfig || {};
257
+ const basePath = config.api?.basePath || "/api";
258
+ if (c.req.path.startsWith(basePath)) {
259
+ return next();
260
+ }
261
+ return (0, import_serve_static2.serveStatic)({
262
+ root: mount.root,
263
+ rewriteRequestPath: () => "index.html"
264
+ })(c, next);
265
+ });
266
+ }
267
+ });
268
+ }
269
+ }
270
+ ctx.hook("kernel:ready", async () => {
271
+ const port = this.options.port || 3e3;
272
+ ctx.logger.debug("Starting HTTP server", { port });
273
+ await this.server.listen(port);
274
+ const actualPort = this.server.getPort();
275
+ ctx.logger.info("HTTP server started successfully", {
276
+ port: actualPort,
277
+ url: `http://localhost:${actualPort}`
278
+ });
279
+ });
280
+ });
281
+ this.options = {
282
+ port: 3e3,
283
+ registerStandardEndpoints: true,
284
+ useApiRegistry: true,
285
+ spaFallback: false,
286
+ ...options
287
+ };
288
+ this.server = new HonoHttpServer(this.options.port);
289
+ }
290
+ /**
291
+ * Destroy phase - Stop server
292
+ */
293
+ async destroy() {
294
+ this.server.close();
295
+ console.log("[HonoServerPlugin] Server stopped");
296
+ }
15
297
  };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./hono-plugin"), exports);
18
- __exportStar(require("./adapter"), exports);
298
+ // Constants
299
+ __publicField(HonoServerPlugin, "DEFAULT_ENDPOINT_PRIORITY", 100);
300
+ __publicField(HonoServerPlugin, "CORE_ENDPOINT_PRIORITY", 950);
301
+ __publicField(HonoServerPlugin, "DISCOVERY_ENDPOINT_PRIORITY", 900);
302
+
303
+ // src/index.ts
304
+ __reExport(index_exports, adapter_exports, module.exports);
305
+ // Annotate the CommonJS export names for ESM import in node:
306
+ 0 && (module.exports = {
307
+ HonoHttpServer,
308
+ HonoServerPlugin
309
+ });
310
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/adapter.ts","../src/hono-plugin.ts"],"sourcesContent":["export * from './hono-plugin';\nexport * from './adapter';\n\n","// Export IHttpServer from core\nexport * from '@objectstack/core';\n\nimport { \n IHttpServer, \n RouteHandler, \n Middleware \n} from '@objectstack/core';\nimport { Hono } from 'hono';\nimport { serve } from '@hono/node-server';\nimport { serveStatic } from '@hono/node-server/serve-static';\n\n/**\n * Hono Implementation of IHttpServer\n */\nexport class HonoHttpServer implements IHttpServer {\n private app: Hono;\n private server: any;\n private listeningPort: number | undefined;\n\n constructor(\n private port: number = 3000,\n private staticRoot?: string\n ) {\n this.app = new Hono();\n }\n\n // internal helper to convert standard handler to Hono handler\n private wrap(handler: RouteHandler) {\n return async (c: any) => {\n let body: any = {};\n \n // Try to parse JSON body first if content-type is JSON\n if (c.req.header('content-type')?.includes('application/json')) {\n try { \n body = await c.req.json(); \n } catch(e) {\n // If JSON parsing fails, try parseBody\n try { \n body = await c.req.parseBody(); \n } catch(e2) {}\n }\n } else {\n // For non-JSON content types, use parseBody\n try { \n body = await c.req.parseBody(); \n } catch(e) {}\n }\n \n const req = {\n params: c.req.param(),\n query: c.req.query(),\n body,\n headers: c.req.header(),\n method: c.req.method,\n path: c.req.path\n };\n\n let capturedResponse: any;\n\n const res = {\n json: (data: any) => { capturedResponse = c.json(data); },\n send: (data: string) => { capturedResponse = c.html(data); },\n status: (code: number) => { c.status(code); return res; },\n header: (name: string, value: string) => { c.header(name, value); return res; }\n };\n\n await handler(req as any, res as any);\n return capturedResponse;\n };\n }\n\n get(path: string, handler: RouteHandler) {\n this.app.get(path, this.wrap(handler));\n }\n post(path: string, handler: RouteHandler) {\n this.app.post(path, this.wrap(handler));\n }\n put(path: string, handler: RouteHandler) {\n this.app.put(path, this.wrap(handler));\n }\n delete(path: string, handler: RouteHandler) {\n this.app.delete(path, this.wrap(handler));\n }\n patch(path: string, handler: RouteHandler) {\n this.app.patch(path, this.wrap(handler));\n }\n \n use(pathOrHandler: string | Middleware, handler?: Middleware) {\n if (typeof pathOrHandler === 'string' && handler) {\n // Path based middleware\n // Hono middleware signature is different (c, next) => ...\n this.app.use(pathOrHandler, async (c, next) => {\n // Simplistic conversion\n await handler({} as any, {} as any, next);\n });\n } else if (typeof pathOrHandler === 'function') {\n // Global middleware\n this.app.use('*', async (c, next) => {\n await pathOrHandler({} as any, {} as any, next);\n });\n }\n }\n\n /**\n * Mount a sub-application or router\n */\n mount(path: string, subApp: Hono) {\n this.app.route(path, subApp);\n }\n\n\n async listen(port: number) {\n return new Promise<void>((resolve) => {\n if (this.staticRoot) {\n this.app.get('/*', serveStatic({ root: this.staticRoot }));\n }\n \n const targetPort = port || this.port;\n this.server = serve({\n fetch: this.app.fetch,\n port: targetPort\n }, (info) => {\n this.listeningPort = info.port;\n resolve();\n });\n });\n }\n\n getPort() {\n return this.listeningPort || this.port;\n }\n\n // Expose raw app for scenarios where standard interface is not enough\n getRawApp() {\n return this.app;\n }\n\n async close() {\n if (this.server && typeof this.server.close === 'function') {\n this.server.close();\n }\n }\n\n\n}\n","import { Plugin, PluginContext, IHttpServer, ApiRegistry } from '@objectstack/core';\nimport { ObjectStackProtocol } from '@objectstack/spec/api';\nimport { \n ApiRegistryEntryInput,\n ApiEndpointRegistrationInput,\n RestServerConfig,\n} from '@objectstack/spec/api';\nimport { HonoHttpServer } from './adapter';\nimport { createHonoApp } from '@objectstack/hono';\nimport { serveStatic } from '@hono/node-server/serve-static';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nexport interface StaticMount {\n root: string;\n path?: string;\n rewrite?: boolean;\n spa?: boolean;\n}\n\nexport interface HonoPluginOptions {\n port?: number;\n staticRoot?: string;\n /**\n * Multiple static resource mounts\n */\n staticMounts?: StaticMount[];\n /**\n * REST server configuration\n * Controls automatic endpoint generation and API behavior\n */\n restConfig?: RestServerConfig;\n /**\n * Whether to register standard ObjectStack CRUD endpoints\n * @default true\n */\n registerStandardEndpoints?: boolean;\n /**\n * Whether to load endpoints from API Registry\n * @default true\n */\n useApiRegistry?: boolean;\n\n /**\n * Whether to enable SPA fallback\n * If true, returns index.html for non-API 404s\n * @default false\n */\n spaFallback?: boolean;\n}\n\n/**\n * Hono Server Plugin\n * \n * Provides HTTP server capabilities using Hono framework.\n * Registers routes for ObjectStack Runtime Protocol.\n */\nexport class HonoServerPlugin implements Plugin {\n name = 'com.objectstack.server.hono';\n version = '0.9.0';\n \n // Constants\n private static readonly DEFAULT_ENDPOINT_PRIORITY = 100;\n private static readonly CORE_ENDPOINT_PRIORITY = 950;\n private static readonly DISCOVERY_ENDPOINT_PRIORITY = 900;\n \n private options: HonoPluginOptions;\n private server: HonoHttpServer;\n\n constructor(options: HonoPluginOptions = {}) {\n this.options = { \n port: 3000,\n registerStandardEndpoints: true,\n useApiRegistry: true,\n spaFallback: false,\n ...options\n };\n // We handle static root manually in start() to support SPA fallback\n this.server = new HonoHttpServer(this.options.port);\n }\n\n /**\n * Init phase - Setup HTTP server and register as service\n */\n init = async (ctx: PluginContext) => {\n ctx.logger.debug('Initializing Hono server plugin', { \n port: this.options.port,\n staticRoot: this.options.staticRoot \n });\n \n // Register HTTP server service as IHttpServer\n // Register as 'http.server' to match core requirements\n ctx.registerService('http.server', this.server);\n // Alias 'http-server' for backward compatibility\n ctx.registerService('http-server', this.server);\n ctx.logger.debug('HTTP server service registered', { serviceName: 'http.server' });\n }\n\n /**\n * Start phase - Bind routes and start listening\n */\n start = async (ctx: PluginContext) => {\n ctx.logger.debug('Starting Hono server plugin');\n \n // Use Standard ObjectStack Runtime Hono App\n try {\n const kernel = ctx.getKernel();\n const config = this.options.restConfig || {};\n // Calculate prefix similar to before\n const apiVersion = config.api?.version || 'v1';\n const basePath = config.api?.basePath || '/api';\n const apiPath = config.api?.apiPath || `${basePath}/${apiVersion}`;\n \n const app = createHonoApp({ \n kernel,\n prefix: apiPath // Use the calculated path\n });\n \n ctx.logger.debug('Mounting ObjectStack Runtime App', { prefix: apiPath });\n // Use the mount method we added to HonoHttpServer\n this.server.mount('/', app as any);\n\n } catch (e: any) {\n ctx.logger.error('Failed to create standard Hono app', e);\n }\n\n // Configure Static Files & SPA Fallback\n const mounts: StaticMount[] = this.options.staticMounts || [];\n\n // Backward compatibility for staticRoot\n if (this.options.staticRoot) {\n mounts.push({\n root: this.options.staticRoot,\n path: '/',\n rewrite: false,\n spa: this.options.spaFallback\n });\n }\n\n if (mounts.length > 0) {\n const rawApp = this.server.getRawApp();\n \n for (const mount of mounts) {\n const mountRoot = path.resolve(process.cwd(), mount.root);\n\n if (!fs.existsSync(mountRoot)) {\n ctx.logger.warn(`Static mount root not found: ${mountRoot}. Skipping.`);\n continue;\n }\n\n const mountPath = mount.path || '/';\n const normalizedPath = mountPath.startsWith('/') ? mountPath : `/${mountPath}`;\n const routePattern = normalizedPath === '/' ? '/*' : `${normalizedPath.replace(/\\/$/, '')}/*`;\n \n // Routes to register: both /mount and /mount/*\n const routes = normalizedPath === '/' ? [routePattern] : [normalizedPath, routePattern];\n\n ctx.logger.debug('Mounting static files', { \n to: routes, \n from: mountRoot, \n rewrite: mount.rewrite, \n spa: mount.spa \n });\n\n routes.forEach(route => {\n // 1. Serve Static Files\n rawApp.get(\n route, \n serveStatic({ \n root: mount.root,\n rewriteRequestPath: (reqPath) => {\n if (mount.rewrite && normalizedPath !== '/') {\n // /console/assets/style.css -> /assets/style.css\n if (reqPath.startsWith(normalizedPath)) {\n return reqPath.substring(normalizedPath.length) || '/';\n }\n }\n return reqPath;\n }\n })\n );\n\n // 2. SPA Fallback (Scoped)\n if (mount.spa) {\n rawApp.get(route, async (c, next) => {\n // Skip if API path check\n const config = this.options.restConfig || {};\n const basePath = config.api?.basePath || '/api';\n \n if (c.req.path.startsWith(basePath)) {\n return next();\n }\n\n return serveStatic({ \n root: mount.root,\n rewriteRequestPath: () => 'index.html'\n })(c, next);\n });\n }\n });\n }\n }\n\n // Start server on kernel:ready hook\n ctx.hook('kernel:ready', async () => {\n const port = this.options.port || 3000;\n ctx.logger.debug('Starting HTTP server', { port });\n \n await this.server.listen(port);\n \n const actualPort = this.server.getPort();\n ctx.logger.info('HTTP server started successfully', { \n port: actualPort, \n url: `http://localhost:${actualPort}` \n });\n });\n }\n\n /**\n * Destroy phase - Stop server\n */\n async destroy() {\n this.server.close();\n // Note: Can't use ctx.logger here since we're in destroy\n console.log('[HonoServerPlugin] Server stopped');\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AACA,4BAAc;AAOd,kBAAqB;AACrB,yBAAsB;AACtB,0BAA4B;AAKrB,IAAM,iBAAN,MAA4C;AAAA,EAK/C,YACY,OAAe,KACf,YACV;AAFU;AACA;AANZ,wBAAQ;AACR,wBAAQ;AACR,wBAAQ;AAMJ,SA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