@kitledger/server 0.0.7 → 0.0.9
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 +71 -13
- package/dist/main.js +83 -10
- package/package.json +2 -2
package/dist/main.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { type KitledgerConfig } from "@kitledger/core";
|
|
2
2
|
import { StaticUIConfig } from "@kitledger/core/ui";
|
|
3
3
|
import { Hono } from "hono";
|
|
4
|
-
type
|
|
4
|
+
type CorsConfig = {
|
|
5
|
+
origin: string | string[];
|
|
6
|
+
allowMethods: string[];
|
|
7
|
+
allowHeaders: string[];
|
|
8
|
+
maxAge: number;
|
|
9
|
+
credentials: boolean;
|
|
10
|
+
exposeHeaders: string[];
|
|
11
|
+
};
|
|
5
12
|
type KitledgerContext = {
|
|
6
13
|
Variables: {
|
|
7
14
|
config: KitledgerConfig;
|
|
@@ -14,30 +21,81 @@ export type ServerOptions = {
|
|
|
14
21
|
systemConfig: KitledgerConfig;
|
|
15
22
|
staticPaths?: string[];
|
|
16
23
|
staticUIs?: StaticUIConfig[];
|
|
24
|
+
corsConfig?: CorsConfig;
|
|
17
25
|
};
|
|
18
|
-
/**
|
|
19
|
-
* Factory function to define the server configuration.
|
|
20
|
-
*/
|
|
21
|
-
export declare function defineServerConfig(options: ServerOptions): ServerConfig;
|
|
22
26
|
/**
|
|
23
27
|
* Prints the Kitledger ASCII logo to the console.
|
|
24
28
|
*/
|
|
25
29
|
export declare function printAsciiLogo(): void;
|
|
26
30
|
/**
|
|
27
|
-
* Factory function
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
+
* Factory function that initializes the Kitledger server engine based on Hono.
|
|
32
|
+
*
|
|
33
|
+
* This function injects the provided {@link ServerConfig} (business logic, UI definitions,
|
|
34
|
+
* and database connections) into the application context and returns a fully configured
|
|
35
|
+
* Hono instance.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* **Universal Web Standards**
|
|
39
|
+
* The returned application relies on native Web Standard `Request` and `Response` objects.
|
|
40
|
+
* This makes the server runtime-agnostic and allows it to be mounted within existing
|
|
41
|
+
* full-stack frameworks (like Next.js Route Handlers, Astro, or React Router 7) simply
|
|
42
|
+
* by exporting the `fetch` handler.
|
|
43
|
+
*
|
|
44
|
+
* @param config - The {@link ServerConfig} object containing system settings, static paths, and UI definitions.
|
|
31
45
|
* @returns A Promise that resolves to the configured Hono application instance.
|
|
32
|
-
*
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* // 1. Standalone Usage (Bun)
|
|
50
|
+
* const server = await createServer({
|
|
51
|
+
* systemConfig: myConfig,
|
|
52
|
+
* staticPaths: ['/public']
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* export default {
|
|
56
|
+
* fetch: server.fetch,
|
|
57
|
+
* port: 3000
|
|
58
|
+
* };
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
33
62
|
* ```ts
|
|
34
|
-
* //
|
|
63
|
+
* // 2. Standalone Usage (Deno)
|
|
35
64
|
* const server = await createServer({
|
|
36
65
|
* systemConfig: myConfig,
|
|
37
66
|
* staticPaths: ['/public']
|
|
38
67
|
* });
|
|
39
|
-
*
|
|
68
|
+
*
|
|
69
|
+
* Deno.serve({ port: 8000 }, server.fetch);
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* // 3. Standalone Usage (Node.js)
|
|
75
|
+
* import { serve } from '@hono/node-server';
|
|
76
|
+
*
|
|
77
|
+
* const server = await createServer({
|
|
78
|
+
* systemConfig: myConfig,
|
|
79
|
+
* staticPaths: ['/public']
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* serve({
|
|
83
|
+
* fetch: server.fetch,
|
|
84
|
+
* port: 3000
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* // 4. Framework Integration (Next.js / Astro / React Router 7)
|
|
91
|
+
* // Because 'server' follows standard Web APIs, you can use it in route handlers.
|
|
92
|
+
*
|
|
93
|
+
* const server = await createServer({ ... });
|
|
94
|
+
*
|
|
95
|
+
* // Next.js App Router (route.ts)
|
|
96
|
+
* export const GET = server.fetch;
|
|
97
|
+
* export const POST = server.fetch;
|
|
40
98
|
* ```
|
|
41
99
|
*/
|
|
42
|
-
export declare function createServer(
|
|
100
|
+
export declare function createServer(options: ServerOptions): Promise<Hono<KitledgerContext, import("hono/types").BlankSchema, "/">>;
|
|
43
101
|
export {};
|
package/dist/main.js
CHANGED
|
@@ -14,8 +14,26 @@ function detectRuntime() {
|
|
|
14
14
|
/**
|
|
15
15
|
* Factory function to define the server configuration.
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
function defineServerConfig(options) {
|
|
18
|
+
/**
|
|
19
|
+
* CORS configuration values and defaults.
|
|
20
|
+
*/
|
|
21
|
+
const defaultCorsConfig = {
|
|
22
|
+
origin: "*",
|
|
23
|
+
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
24
|
+
allowHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
|
|
25
|
+
exposeHeaders: [],
|
|
26
|
+
credentials: false,
|
|
27
|
+
maxAge: 86400,
|
|
28
|
+
};
|
|
29
|
+
const corsConfig = {
|
|
30
|
+
...defaultCorsConfig,
|
|
31
|
+
...options.corsConfig,
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
...options,
|
|
35
|
+
corsConfig,
|
|
36
|
+
};
|
|
19
37
|
}
|
|
20
38
|
/**
|
|
21
39
|
* Prints the Kitledger ASCII logo to the console.
|
|
@@ -24,22 +42,77 @@ export function printAsciiLogo() {
|
|
|
24
42
|
console.log(getAsciiLogo());
|
|
25
43
|
}
|
|
26
44
|
/**
|
|
27
|
-
* Factory function
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
45
|
+
* Factory function that initializes the Kitledger server engine based on Hono.
|
|
46
|
+
*
|
|
47
|
+
* This function injects the provided {@link ServerConfig} (business logic, UI definitions,
|
|
48
|
+
* and database connections) into the application context and returns a fully configured
|
|
49
|
+
* Hono instance.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* **Universal Web Standards**
|
|
53
|
+
* The returned application relies on native Web Standard `Request` and `Response` objects.
|
|
54
|
+
* This makes the server runtime-agnostic and allows it to be mounted within existing
|
|
55
|
+
* full-stack frameworks (like Next.js Route Handlers, Astro, or React Router 7) simply
|
|
56
|
+
* by exporting the `fetch` handler.
|
|
57
|
+
*
|
|
58
|
+
* @param config - The {@link ServerConfig} object containing system settings, static paths, and UI definitions.
|
|
31
59
|
* @returns A Promise that resolves to the configured Hono application instance.
|
|
32
|
-
*
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
33
62
|
* ```ts
|
|
34
|
-
* //
|
|
63
|
+
* // 1. Standalone Usage (Bun)
|
|
35
64
|
* const server = await createServer({
|
|
36
65
|
* systemConfig: myConfig,
|
|
37
66
|
* staticPaths: ['/public']
|
|
38
67
|
* });
|
|
39
|
-
*
|
|
68
|
+
*
|
|
69
|
+
* export default {
|
|
70
|
+
* fetch: server.fetch,
|
|
71
|
+
* port: 3000
|
|
72
|
+
* };
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* // 2. Standalone Usage (Deno)
|
|
78
|
+
* const server = await createServer({
|
|
79
|
+
* systemConfig: myConfig,
|
|
80
|
+
* staticPaths: ['/public']
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* Deno.serve({ port: 8000 }, server.fetch);
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* // 3. Standalone Usage (Node.js)
|
|
89
|
+
* import { serve } from '@hono/node-server';
|
|
90
|
+
*
|
|
91
|
+
* const server = await createServer({
|
|
92
|
+
* systemConfig: myConfig,
|
|
93
|
+
* staticPaths: ['/public']
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* serve({
|
|
97
|
+
* fetch: server.fetch,
|
|
98
|
+
* port: 3000
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* // 4. Framework Integration (Next.js / Astro / React Router 7)
|
|
105
|
+
* // Because 'server' follows standard Web APIs, you can use it in route handlers.
|
|
106
|
+
*
|
|
107
|
+
* const server = await createServer({ ... });
|
|
108
|
+
*
|
|
109
|
+
* // Next.js App Router (route.ts)
|
|
110
|
+
* export const GET = server.fetch;
|
|
111
|
+
* export const POST = server.fetch;
|
|
40
112
|
* ```
|
|
41
113
|
*/
|
|
42
|
-
export async function createServer(
|
|
114
|
+
export async function createServer(options) {
|
|
115
|
+
const config = defineServerConfig(options);
|
|
43
116
|
const server = new Hono();
|
|
44
117
|
/**
|
|
45
118
|
* Ensure all requests have access to the system config.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitledger/server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@hono/node-server": "^1.19.6",
|
|
19
19
|
"hono": "^4.10.7",
|
|
20
20
|
"valibot": "^1.1.0",
|
|
21
|
-
"@kitledger/core": "0.0.
|
|
21
|
+
"@kitledger/core": "0.0.9"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@kitledger/admin": "0.0.5"
|