@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/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
|
-
*
|
|
51
|
+
* Route handler helper
|
|
5
52
|
*/
|
|
6
|
-
export declare class
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
*
|
|
60
|
+
* Form route handler helper
|
|
13
61
|
*/
|
|
14
|
-
export
|
|
15
|
-
export declare
|
|
16
|
-
|
|
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
|
-
*
|
|
82
|
+
* Run route from file
|
|
20
83
|
*/
|
|
21
|
-
export declare function
|
|
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
|
-
*
|
|
102
|
+
* Create and start Bun HTTP server
|
|
24
103
|
*/
|
|
25
|
-
export declare function
|
|
104
|
+
export declare function createServer(config: THSServerConfig): Promise<Hono>;
|
|
26
105
|
/**
|
|
27
|
-
*
|
|
106
|
+
* Streaming HTML Response
|
|
28
107
|
*/
|
|
29
|
-
export declare
|
|
108
|
+
export declare class StreamResponse extends Response {
|
|
109
|
+
constructor(iterator: AsyncIterator<unknown>, options?: {});
|
|
110
|
+
}
|
|
30
111
|
/**
|
|
31
|
-
*
|
|
112
|
+
* Does what it says on the tin...
|
|
32
113
|
*/
|
|
33
|
-
export declare function
|
|
114
|
+
export declare function createReadableStreamFromAsyncGenerator(output: AsyncGenerator): ReadableStream<any>;
|
|
34
115
|
/**
|
|
35
|
-
*
|
|
116
|
+
* Normalize URL path
|
|
117
|
+
* Removes trailing slash and lowercases path
|
|
36
118
|
*/
|
|
37
|
-
export
|
|
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 {};
|