kilatjs 0.1.0 → 0.1.2

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.
@@ -1,36 +1,39 @@
1
1
  import { RouteMatch, KilatConfig } from "./types";
2
+ /** Internal config with resolved routesDir (set by KilatServer) */
3
+ interface InternalRouterConfig extends KilatConfig {
4
+ routesDir: string;
5
+ }
2
6
  export declare class Router {
3
7
  private routes;
4
8
  private config;
5
9
  private staticPaths;
6
- private serverId;
7
10
  private fsRouter;
8
11
  private routeCache;
9
12
  private preloadedRoutes;
10
13
  private routePatterns;
11
14
  private apiRoutes;
12
- private staticApiResponses;
13
15
  private static readonly NOT_FOUND_RESPONSE;
14
16
  private static readonly METHOD_NOT_ALLOWED_RESPONSE;
15
17
  private static readonly INTERNAL_ERROR_RESPONSE;
16
18
  private contextPool;
17
- private poolIndex;
18
- constructor(config: KilatConfig);
19
+ constructor(config: InternalRouterConfig);
19
20
  getRoutes(): Map<string, any>;
20
21
  getStaticPaths(): Map<string, string[]>;
21
- loadRoutes(): Promise<void>;
22
+ loadRoutes(silent?: boolean): Promise<void>;
22
23
  private preloadAllRoutes;
24
+ private staticHtmlFiles;
23
25
  private scanAndPreloadRoutes;
26
+ /** Check if route is a static HTML file */
27
+ getStaticHtmlFile(path: string): string | undefined;
24
28
  private createRoutePattern;
25
29
  private getRouteType;
26
30
  matchRoute(path: string): RouteMatch | null;
27
- private pathMatchesPattern;
28
31
  handleRequest(request: Request): Promise<Response>;
29
32
  private handleApiRouteFast;
30
33
  private getContextFromPool;
31
34
  private returnContextToPool;
32
35
  private getMinimalApiContext;
33
36
  private handleStaticFile;
34
- private create404Response;
35
37
  private renderPage;
36
38
  }
39
+ export {};
@@ -39,6 +39,8 @@ export interface RouteExports {
39
39
  load?: (ctx: RouteContext) => Promise<any> | any;
40
40
  meta?: RouteMeta;
41
41
  getStaticPaths?: () => Promise<string[]> | string[];
42
+ /** Client-side script function - auto-injected into page, runs in browser */
43
+ clientScript?: () => void;
42
44
  POST?: (ctx: RouteContext) => Promise<Response> | Response;
43
45
  PUT?: (ctx: RouteContext) => Promise<Response> | Response;
44
46
  DELETE?: (ctx: RouteContext) => Promise<Response> | Response;
@@ -63,7 +65,8 @@ export interface TailwindConfig {
63
65
  configPath?: string;
64
66
  }
65
67
  export interface KilatConfig {
66
- routesDir: string;
68
+ /** App source directory (e.g., "./src"). Auto-detects routes/ or pages/ inside */
69
+ appDir: string;
67
70
  outDir: string;
68
71
  port?: number;
69
72
  hostname?: string;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Vite-enabled Router for KilatJS
3
+ *
4
+ * Uses Vite's ssrLoadModule for true HMR support.
5
+ * Modules are hot-reloaded without process restart.
6
+ */
7
+ import { KilatConfig } from "./types";
8
+ interface InternalRouterConfig extends KilatConfig {
9
+ routesDir: string;
10
+ }
11
+ export declare class ViteRouter {
12
+ private config;
13
+ private fsRouter;
14
+ private routePatterns;
15
+ private static readonly NOT_FOUND_RESPONSE;
16
+ private static readonly METHOD_NOT_ALLOWED_RESPONSE;
17
+ private static readonly INTERNAL_ERROR_RESPONSE;
18
+ constructor(config: InternalRouterConfig);
19
+ loadRoutes(silent?: boolean): Promise<void>;
20
+ private scanRoutePatterns;
21
+ private createRoutePattern;
22
+ private getRouteType;
23
+ /**
24
+ * Load route module via Vite's ssrLoadModule for HMR support
25
+ */
26
+ private loadRouteModule;
27
+ handleRequest(request: Request): Promise<Response>;
28
+ private handleMatchedRoute;
29
+ private handleDynamicRoute;
30
+ private handleApiRoute;
31
+ private handleStaticFile;
32
+ private renderPage;
33
+ }
34
+ export {};
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export { Router } from "./core/router";
2
2
  export { KilatServer } from "./server/server";
3
3
  export { ReactAdapter } from "./adapters/react";
4
4
  export { HTMXAdapter, type HTMXResponseOptions } from "./adapters/htmx";
5
+ export { startLiveReload, stopLiveReload, notifyReload } from "./server/live-reload";
5
6
  export * from "./core/types";
6
7
  import { KilatServer } from "./server/server";
7
8
  import { KilatConfig } from "./core/types";
@@ -33,6 +34,10 @@ export declare function defineConfig(config: Partial<KilatConfig>): Partial<Kila
33
34
  * Define route meta with type inference
34
35
  */
35
36
  export declare function defineMeta(meta: import("./core/types").RouteMeta): import("./core/types").RouteMeta;
37
+ /**
38
+ * CLI functionality - can be used programmatically
39
+ */
40
+ export declare function runCLI(args?: string[]): Promise<void>;
36
41
  declare const Kilat: {
37
42
  createKilat: typeof createKilat;
38
43
  startDevServer: typeof startDevServer;
@@ -40,6 +45,7 @@ declare const Kilat: {
40
45
  defineConfig: typeof defineConfig;
41
46
  defineLoader: typeof defineLoader;
42
47
  defineMeta: typeof defineMeta;
48
+ runCLI: typeof runCLI;
43
49
  defaultConfig: KilatConfig;
44
50
  };
45
51
  export default Kilat;