@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/README.md +3 -81
- package/build.ts +24 -26
- package/dist/assets.d.ts +34 -0
- package/dist/assets.js +394 -0
- package/dist/index.d.ts +101 -30
- package/dist/index.js +2421 -408
- package/dist/server.d.ts +85 -73
- package/dist/server.js +2142 -1603
- package/package.json +42 -29
- package/src/assets.ts +141 -0
- package/src/clientjs/hyperspan-client.ts +7 -175
- package/src/clientjs/idiomorph.esm.js +1278 -0
- package/src/clientjs/preact.ts +1 -0
- package/src/index.ts +1 -14
- package/src/server.ts +232 -151
- package/.prettierrc +0 -7
- package/bun.lockb +0 -0
- package/src/app.ts +0 -186
- package/src/clientjs/idomorph.esm.js +0 -854
- package/src/document.ts +0 -10
- package/src/forms.ts +0 -110
- package/src/html.test.ts +0 -69
- package/src/html.ts +0 -345
package/dist/server.d.ts
CHANGED
|
@@ -1,65 +1,96 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { TmplHtml } from '@hyperspan/html';
|
|
4
|
+
import { Context, Handler, Hono } from 'hono';
|
|
4
5
|
|
|
5
|
-
declare
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
*
|
|
32
|
-
* Preserves all headers added in context/middleware
|
|
72
|
+
* Get form renderer method
|
|
33
73
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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(
|
|
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
|
-
|
|
62
|
-
|
|
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<
|
|
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
|
-
*
|
|
97
|
-
*
|
|
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
|
|
107
|
-
export declare function formRoute(handlerFn: TFormRouteFn): (context: HSRequestContext) => void;
|
|
119
|
+
export declare function normalizePath(urlPath: string): string;
|
|
108
120
|
|
|
109
121
|
export {};
|