@hyperspan/framework 0.1.0 → 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.
@@ -0,0 +1,121 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ import { TmplHtml } from '@hyperspan/html';
4
+ import { Context, Handler, Hono } from 'hono';
5
+
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;
49
+ }
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;
71
+ /**
72
+ * Get form renderer method
73
+ */
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;
80
+ }
81
+ /**
82
+ * Run route from file
83
+ */
84
+ export declare function runFileRoute(RouteModule: any, context: Context): Promise<Response | false>;
85
+ export type THSServerConfig = {
86
+ appDir: string;
87
+ staticFileRoot: string;
88
+ rewrites?: Array<{
89
+ source: string;
90
+ destination: string;
91
+ }>;
92
+ beforeRoutesAdded?: (app: Hono) => void;
93
+ afterRoutesAdded?: (app: Hono) => void;
94
+ };
95
+ export type THSRouteMap = {
96
+ file: string;
97
+ route: string;
98
+ params: string[];
99
+ };
100
+ export declare function buildRoutes(config: THSServerConfig): Promise<THSRouteMap[]>;
101
+ /**
102
+ * Create and start Bun HTTP server
103
+ */
104
+ export declare function createServer(config: THSServerConfig): Promise<Hono>;
105
+ /**
106
+ * Streaming HTML Response
107
+ */
108
+ export declare class StreamResponse extends Response {
109
+ constructor(iterator: AsyncIterator<unknown>, options?: {});
110
+ }
111
+ /**
112
+ * Does what it says on the tin...
113
+ */
114
+ export declare function createReadableStreamFromAsyncGenerator(output: AsyncGenerator): ReadableStream<any>;
115
+ /**
116
+ * Normalize URL path
117
+ * Removes trailing slash and lowercases path
118
+ */
119
+ export declare function normalizePath(urlPath: string): string;
120
+
121
+ export {};