@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/index.d.ts CHANGED
@@ -1,50 +1,121 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
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
+ }
3
50
  /**
4
- * Template object - used so it will be possible to (eventually) pass down context
51
+ * Route handler helper
5
52
  */
6
- export declare class HSTemplate {
7
- __hsTemplate: boolean;
8
- content: any[];
9
- constructor(content: any[]);
53
+ export declare class HSRoute {
54
+ _kind: string;
55
+ _handlers: Record<string, Handler>;
56
+ _methods: null | string[];
57
+ constructor(handler: Handler);
10
58
  }
11
59
  /**
12
- * HTML template
60
+ * Form route handler helper
13
61
  */
14
- export declare function html(strings: TemplateStringsArray, ...values: any[]): HSTemplate;
15
- export declare namespace html {
16
- var raw: (value: string) => HSTemplate;
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;
17
80
  }
18
81
  /**
19
- * Render HSTemplate to async generator that streams output to a string
82
+ * Run route from file
20
83
  */
21
- export declare function renderToStream(template: HSTemplate | string): AsyncGenerator<string>;
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[]>;
22
101
  /**
23
- * Render HSTemplate to string (awaits/buffers entire response)
102
+ * Create and start Bun HTTP server
24
103
  */
25
- export declare function renderToString(template: HSTemplate | string): Promise<string>;
104
+ export declare function createServer(config: THSServerConfig): Promise<Hono>;
26
105
  /**
27
- * Strip extra spacing between HTML tags (used for tests)
106
+ * Streaming HTML Response
28
107
  */
29
- export declare function compressHTMLString(str: string): string;
108
+ export declare class StreamResponse extends Response {
109
+ constructor(iterator: AsyncIterator<unknown>, options?: {});
110
+ }
30
111
  /**
31
- * LOL JavaScript...
112
+ * Does what it says on the tin...
32
113
  */
33
- export declare function _typeOf(obj: any): string;
114
+ export declare function createReadableStreamFromAsyncGenerator(output: AsyncGenerator): ReadableStream<any>;
34
115
  /**
35
- * Client component
116
+ * Normalize URL path
117
+ * Removes trailing slash and lowercases path
36
118
  */
37
- export type THSWCState = Record<string, any>;
38
- export type THSWCSetStateArg = THSWCState | ((state: THSWCState) => THSWCState);
39
- export type THSWC = {
40
- this: THSWC;
41
- state: THSWCState | undefined;
42
- id: string;
43
- setState: (fn: THSWCSetStateArg) => THSWCState;
44
- mergeState: (newState: THSWCState) => THSWCState;
45
- render: () => any;
46
- };
47
- export type THSWCUser = Pick<THSWC, "render"> & Record<string, any>;
48
- export declare function clientComponent(id: string, wc: THSWCUser): (attrs?: Record<string, string>, state?: Record<string, any>) => HSTemplate;
119
+ export declare function normalizePath(urlPath: string): string;
49
120
 
50
121
  export {};