@kitledger/server 0.0.4 → 0.0.5

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.
@@ -3,10 +3,10 @@ import { StaticUIConfig } from "@kitledger/core/ui";
3
3
  import { Hono } from "hono";
4
4
  export type ServerOptions = {
5
5
  systemConfig: KitledgerConfig;
6
- runtime: "node";
7
6
  staticPaths?: string[];
8
7
  staticUIs?: StaticUIConfig[];
9
8
  };
10
- export type ServerConfig = ServerOptions;
9
+ type ServerConfig = ServerOptions;
11
10
  export declare function defineServerConfig(options: ServerOptions): ServerConfig;
12
- export declare function createServer(config: ServerConfig): Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
11
+ export declare function createServer(config: ServerConfig): Promise<Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">>;
12
+ export {};
@@ -1,10 +1,44 @@
1
- import { serveStatic } from "@hono/node-server/serve-static";
2
1
  import { Hono } from "hono";
2
+ // 3. The Auto-Detection Logic
3
+ function detectRuntime() {
4
+ // @ts-ignore: Deno global detection
5
+ if (typeof Deno !== "undefined")
6
+ return "deno";
7
+ // @ts-ignore: Bun global detection
8
+ if (typeof Bun !== "undefined")
9
+ return "bun";
10
+ if (typeof process !== "undefined" && process.versions?.node)
11
+ return "node";
12
+ return "unknown";
13
+ }
3
14
  export function defineServerConfig(options) {
4
15
  return options;
5
16
  }
6
- export function createServer(config) {
17
+ export async function createServer(config) {
7
18
  const server = new Hono();
19
+ const runtime = detectRuntime();
20
+ // 4. Type-Safe Variable Definition
21
+ let serveStatic;
22
+ // 5. Dynamic Loading based on detected runtime
23
+ switch (runtime) {
24
+ case "node": {
25
+ const mod = await import("@hono/node-server/serve-static");
26
+ serveStatic = mod.serveStatic;
27
+ break;
28
+ }
29
+ case "deno": {
30
+ const mod = await import("hono/deno");
31
+ serveStatic = mod.serveStatic;
32
+ break;
33
+ }
34
+ case "bun": {
35
+ const mod = await import("hono/bun");
36
+ serveStatic = mod.serveStatic;
37
+ break;
38
+ }
39
+ default:
40
+ throw new Error(`Unsupported or undetected runtime: ${runtime}`);
41
+ }
8
42
  /**
9
43
  * Static Apps Serving
10
44
  */
@@ -16,7 +50,6 @@ export function createServer(config) {
16
50
  server.get(`${staticUI.serverPath}/entities/models`, (c) => {
17
51
  return c.json(config.systemConfig.entityModels);
18
52
  });
19
- // Remove trailing slash if path ends with '/'
20
53
  const cleanPath = staticUI.basePath.endsWith("/") ? staticUI.basePath.slice(0, -1) : staticUI.basePath;
21
54
  server.use(`${cleanPath}/*`, serveStatic({
22
55
  root: staticUI.assetsPath,
@@ -31,7 +64,7 @@ export function createServer(config) {
31
64
  }
32
65
  }
33
66
  /**
34
- * Server other static paths
67
+ * Serve other static paths
35
68
  */
36
69
  if (config.staticPaths) {
37
70
  for (const staticPath of config.staticPaths) {
package/package.json CHANGED
@@ -1,31 +1,34 @@
1
1
  {
2
2
  "name": "@kitledger/server",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "private": false,
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {
9
- "types": "./dist/server.d.ts",
10
- "default": "./dist/server.js"
9
+ "types": "./dist/main.d.ts",
10
+ "default": "./dist/main.js"
11
11
  }
12
12
  },
13
13
  "files": [
14
+ "!dist/**/*.test.js",
14
15
  "dist"
15
16
  ],
16
17
  "dependencies": {
17
18
  "@hono/node-server": "^1.19.6",
18
19
  "hono": "^4.10.7",
19
- "@kitledger/core": "0.0.3"
20
+ "valibot": "^1.1.0",
21
+ "@kitledger/core": "0.0.6"
20
22
  },
21
- "peerDependencies": {
22
- "valibot": "^1.1.0"
23
+ "devDependencies": {
24
+ "@kitledger/admin": "0.0.4"
23
25
  },
24
26
  "publishConfig": {
25
27
  "access": "public"
26
28
  },
27
29
  "scripts": {
28
30
  "build": "tsc",
31
+ "test": "vitest run",
29
32
  "typecheck": "tsc --noEmit"
30
33
  }
31
34
  }