@hyperspan/framework 0.0.3 → 0.1.1

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/server.d.ts CHANGED
@@ -1,65 +1,96 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- import Headers$1 from '@mjackson/headers';
3
+ import { TmplHtml } from '@hyperspan/html';
4
+ import { Context, Handler, Hono } from 'hono';
4
5
 
5
- declare class HSTemplate {
6
- __hsTemplate: boolean;
7
- content: any[];
8
- constructor(content: any[]);
6
+ export declare const IS_PROD: boolean;
7
+ /**
8
+ * Route
9
+ * Define a route that can handle a direct HTTP request
10
+ * Route handlers should return a Response or TmplHtml object
11
+ */
12
+ export declare function createRoute(handler: Handler): HSRoute;
13
+ /**
14
+ * Component
15
+ * Define a component or partial with an optional loading placeholder
16
+ * These can be rendered anywhere inside other templates - even if async.
17
+ */
18
+ export declare function createComponent(render: () => THSComponentReturn | Promise<THSComponentReturn>): HSComponent;
19
+ /**
20
+ * Form + route handler
21
+ * Automatically handles and parses form data
22
+ *
23
+ * INITIAL IDEA OF HOW THIS WILL WORK:
24
+ * ---
25
+ * 1. Renders component as initial form markup for GET request
26
+ * 2. Bind form onSubmit function to custom client JS handling
27
+ * 3. Submits form with JavaScript fetch()
28
+ * 4. Replaces form content with content from server
29
+ * 5. All validation and save logic is on the server
30
+ * 6. Handles any Exception thrown on server as error displayed in client
31
+ */
32
+ export declare function createForm(renderForm: (data?: any) => THSResponseTypes, schema?: z.ZodSchema | null): HSFormRoute;
33
+ /**
34
+ * Types
35
+ */
36
+ export type THSComponentReturn = TmplHtml | string | number | null;
37
+ export type THSResponseTypes = TmplHtml | Response | string | null;
38
+ export declare const HS_DEFAULT_LOADING: () => TmplHtml;
39
+ /**
40
+ * Route handler helper
41
+ */
42
+ export declare class HSComponent {
43
+ _kind: string;
44
+ _handlers: Record<string, Handler>;
45
+ _loading?: () => TmplHtml;
46
+ render: () => THSComponentReturn | Promise<THSComponentReturn>;
47
+ constructor(render: () => THSComponentReturn | Promise<THSComponentReturn>);
48
+ loading(fn: () => TmplHtml): this;
9
49
  }
10
- export type THTTPMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
11
- declare class HSRequestContext {
12
- req: Request;
13
- locals: Record<string, any>;
14
- headers: Headers$1;
15
- route: {
16
- params: Record<string, string>;
17
- query: URLSearchParams;
18
- };
19
- constructor(req: Request, params?: Record<string, string>);
20
- /**
21
- * Response helper
22
- * Merges a Response object while preserving all headers added in context/middleware
23
- */
24
- resMerge(res: Response): Response;
25
- /**
26
- * HTML response helper
27
- * Preserves all headers added in context/middleware
28
- */
29
- html(content: string, options?: ResponseInit): Response;
50
+ /**
51
+ * Route handler helper
52
+ */
53
+ export declare class HSRoute {
54
+ _kind: string;
55
+ _handlers: Record<string, Handler>;
56
+ _methods: null | string[];
57
+ constructor(handler: Handler);
58
+ }
59
+ /**
60
+ * Form route handler helper
61
+ */
62
+ export type THSFormRenderer = (data?: any) => THSResponseTypes;
63
+ export declare class HSFormRoute {
64
+ _kind: string;
65
+ _handlers: Record<string, Handler>;
66
+ _form: THSFormRenderer;
67
+ _methods: null | string[];
68
+ _schema: null | z.ZodSchema;
69
+ constructor(renderForm: THSFormRenderer, schema?: z.ZodSchema | null);
70
+ getDefaultData(): unknown;
30
71
  /**
31
- * JSON response helper
32
- * Preserves all headers added in context/middleware
72
+ * Get form renderer method
33
73
  */
34
- json(content: any, options?: ResponseInit): Response;
35
- notFound(msg?: string): Response;
36
- }
37
- export type THSRouteHandler = (context: HSRequestContext) => (Response | null | void) | Promise<Response | null | void>;
38
- declare class HSApp {
39
- private _router;
40
- private _mw;
41
- _defaultRoute: THSRouteHandler;
42
- constructor();
43
- get(path: string, handler: THSRouteHandler): this;
44
- post(path: string, handler: THSRouteHandler): this;
45
- put(path: string, handler: THSRouteHandler): this;
46
- delete(path: string, handler: THSRouteHandler): this;
47
- all(path: string, handler: THSRouteHandler): this;
48
- addRoute(methods: THTTPMethod[], path: string, handler: THSRouteHandler): this;
49
- defaultRoute(handler: THSRouteHandler): void;
50
- private _route;
51
- run(req: Request): Promise<Response>;
74
+ renderForm(data?: any): THSResponseTypes;
75
+ get(handler: Handler): this;
76
+ patch(handler: Handler): this;
77
+ post(handler: Handler): this;
78
+ put(handler: Handler): this;
79
+ delete(handler: Handler): this;
52
80
  }
53
- export declare const IS_PROD: boolean;
54
81
  /**
55
82
  * Run route from file
56
83
  */
57
- export declare function runFileRoute(routeFile: string, context: HSRequestContext): Promise<any>;
84
+ export declare function runFileRoute(RouteModule: any, context: Context): Promise<Response | false>;
58
85
  export type THSServerConfig = {
59
86
  appDir: string;
60
87
  staticFileRoot: string;
61
- beforeRoutesAdded?: (app: HSApp) => void;
62
- afterRoutesAdded?: (app: HSApp) => void;
88
+ rewrites?: Array<{
89
+ source: string;
90
+ destination: string;
91
+ }>;
92
+ beforeRoutesAdded?: (app: Hono) => void;
93
+ afterRoutesAdded?: (app: Hono) => void;
63
94
  };
64
95
  export type THSRouteMap = {
65
96
  file: string;
@@ -70,22 +101,11 @@ export declare function buildRoutes(config: THSServerConfig): Promise<THSRouteMa
70
101
  /**
71
102
  * Create and start Bun HTTP server
72
103
  */
73
- export declare function createServer(config: THSServerConfig): Promise<HSApp>;
74
- /**
75
- * Build client JS for end users (minimal JS for Hyperspan to work)
76
- */
77
- export declare let clientJSFile: string;
78
- export declare function buildClientJS(): Promise<string>;
79
- /**
80
- * Find client CSS file built for end users
81
- * @TODO: Build this in code here vs. relying on tailwindcss CLI tool from package scripts
82
- */
83
- export declare let clientCSSFile: string;
84
- export declare function buildClientCSS(): Promise<string | undefined>;
104
+ export declare function createServer(config: THSServerConfig): Promise<Hono>;
85
105
  /**
86
106
  * Streaming HTML Response
87
107
  */
88
- export declare class StreamResponse {
108
+ export declare class StreamResponse extends Response {
89
109
  constructor(iterator: AsyncIterator<unknown>, options?: {});
90
110
  }
91
111
  /**
@@ -93,17 +113,9 @@ export declare class StreamResponse {
93
113
  */
94
114
  export declare function createReadableStreamFromAsyncGenerator(output: AsyncGenerator): ReadableStream<any>;
95
115
  /**
96
- * Form route
97
- * Automatically handles and parses form data
98
- *
99
- * 1. Renders component as initial form markup
100
- * 2. Bind form onSubmit function to custom client JS handling
101
- * 3. Submits form with JavaScript fetch()
102
- * 4. Replaces form content with content from server
103
- * 5. All validation and save logic is on the server
104
- * 6. Handles any Exception thrown on server as error displayed in client
116
+ * Normalize URL path
117
+ * Removes trailing slash and lowercases path
105
118
  */
106
- export type TFormRouteFn = (context: HSRequestContext) => HSTemplate | Response;
107
- export declare function formRoute(handlerFn: TFormRouteFn): (context: HSRequestContext) => void;
119
+ export declare function normalizePath(urlPath: string): string;
108
120
 
109
121
  export {};