@kitledger/server 0.0.3 → 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.
package/dist/main.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { type KitledgerConfig } from "@kitledger/core";
2
+ import { StaticUIConfig } from "@kitledger/core/ui";
3
+ import { Hono } from "hono";
4
+ export type ServerOptions = {
5
+ systemConfig: KitledgerConfig;
6
+ staticPaths?: string[];
7
+ staticUIs?: StaticUIConfig[];
8
+ };
9
+ type ServerConfig = ServerOptions;
10
+ export declare function defineServerConfig(options: ServerOptions): ServerConfig;
11
+ export declare function createServer(config: ServerConfig): Promise<Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">>;
12
+ export {};
package/dist/main.js ADDED
@@ -0,0 +1,78 @@
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
+ }
14
+ export function defineServerConfig(options) {
15
+ return options;
16
+ }
17
+ export async function createServer(config) {
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
+ }
42
+ /**
43
+ * Static Apps Serving
44
+ */
45
+ if (config.staticUIs) {
46
+ for (const staticUI of config.staticUIs) {
47
+ server.get(`${staticUI.serverPath}/transactions/models`, (c) => {
48
+ return c.json(config.systemConfig.transactionModels);
49
+ });
50
+ server.get(`${staticUI.serverPath}/entities/models`, (c) => {
51
+ return c.json(config.systemConfig.entityModels);
52
+ });
53
+ const cleanPath = staticUI.basePath.endsWith("/") ? staticUI.basePath.slice(0, -1) : staticUI.basePath;
54
+ server.use(`${cleanPath}/*`, serveStatic({
55
+ root: staticUI.assetsPath,
56
+ rewriteRequestPath: (path) => {
57
+ const p = path.replace(new RegExp(`^${cleanPath}`), "").replace(/^\//, "");
58
+ if (p === "" || p === "index.html")
59
+ return "__404__";
60
+ return p;
61
+ },
62
+ }));
63
+ server.get(`${cleanPath}/*`, (c) => c.html(staticUI.htmlContent));
64
+ }
65
+ }
66
+ /**
67
+ * Serve other static paths
68
+ */
69
+ if (config.staticPaths) {
70
+ for (const staticPath of config.staticPaths) {
71
+ server.use(staticPath, serveStatic({
72
+ root: ".",
73
+ rewriteRequestPath: (path) => path.replace(new RegExp(`^${staticPath}`), "").replace(/^\//, ""),
74
+ }));
75
+ }
76
+ }
77
+ return server;
78
+ }
package/package.json CHANGED
@@ -1,31 +1,34 @@
1
1
  {
2
2
  "name": "@kitledger/server",
3
+ "version": "0.0.5",
4
+ "private": false,
3
5
  "license": "Apache-2.0",
4
- "version": "0.0.3",
5
6
  "type": "module",
6
- "files": [
7
- "dist"
8
- ],
9
- "private": false,
10
- "publishConfig": {
11
- "access": "public"
12
- },
13
7
  "exports": {
14
8
  ".": {
15
- "types": "./dist/server.d.ts",
16
- "default": "./dist/server.js"
9
+ "types": "./dist/main.d.ts",
10
+ "default": "./dist/main.js"
17
11
  }
18
12
  },
13
+ "files": [
14
+ "!dist/**/*.test.js",
15
+ "dist"
16
+ ],
19
17
  "dependencies": {
20
18
  "@hono/node-server": "^1.19.6",
21
19
  "hono": "^4.10.7",
22
- "@kitledger/core": "0.0.2"
20
+ "valibot": "^1.1.0",
21
+ "@kitledger/core": "0.0.6"
23
22
  },
24
- "peerDependencies": {
25
- "valibot": "^1.1.0"
23
+ "devDependencies": {
24
+ "@kitledger/admin": "0.0.4"
25
+ },
26
+ "publishConfig": {
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
  }
package/dist/server.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { Hono } from 'hono';
2
- import { type KitledgerConfig } from '@kitledger/core';
3
- import { StaticUIConfig } from '@kitledger/core/ui';
4
- export type ServerOptions = {
5
- systemConfig: KitledgerConfig;
6
- runtime: "node";
7
- staticPaths?: string[];
8
- staticUIs?: StaticUIConfig[];
9
- };
10
- export type ServerConfig = ServerOptions;
11
- export declare function defineServerConfig(options: ServerOptions): ServerConfig;
12
- export declare function createServer(config: ServerConfig): Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
package/dist/server.js DELETED
@@ -1,47 +0,0 @@
1
- import { Hono } from 'hono';
2
- import { serveStatic } from '@hono/node-server/serve-static';
3
- export function defineServerConfig(options) {
4
- return options;
5
- }
6
- export function createServer(config) {
7
- const server = new Hono();
8
- /**
9
- * Static Apps Serving
10
- */
11
- if (config.staticUIs) {
12
- for (const staticUI of config.staticUIs) {
13
- server.get(`${staticUI.serverPath}/transactions/models`, (c) => {
14
- return c.json(config.systemConfig.transactionModels);
15
- });
16
- server.get(`${staticUI.serverPath}/entities/models`, (c) => {
17
- return c.json(config.systemConfig.entityModels);
18
- });
19
- // Remove trailing slash if path ends with '/'
20
- const cleanPath = staticUI.basePath.endsWith('/')
21
- ? staticUI.basePath.slice(0, -1)
22
- : staticUI.basePath;
23
- server.use(`${cleanPath}/*`, serveStatic({
24
- root: staticUI.assetsPath,
25
- rewriteRequestPath: (path) => {
26
- const p = path.replace(new RegExp(`^${cleanPath}`), '').replace(/^\//, '');
27
- if (p === '' || p === 'index.html')
28
- return '__404__';
29
- return p;
30
- }
31
- }));
32
- server.get(`${cleanPath}/*`, (c) => c.html(staticUI.htmlContent));
33
- }
34
- }
35
- /**
36
- * Server other static paths
37
- */
38
- if (config.staticPaths) {
39
- for (const staticPath of config.staticPaths) {
40
- server.use(staticPath, serveStatic({
41
- root: '.',
42
- rewriteRequestPath: (path) => path.replace(new RegExp(`^${staticPath}`), '').replace(/^\//, '')
43
- }));
44
- }
45
- }
46
- return server;
47
- }