@netrojs/fnetro 0.1.6 → 0.2.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 +686 -871
- package/client.ts +220 -200
- package/core.ts +146 -644
- package/dist/client.d.ts +99 -155
- package/dist/client.js +177 -570
- package/dist/core.d.ts +69 -156
- package/dist/core.js +31 -452
- package/dist/server.d.ts +120 -179
- package/dist/server.js +278 -553
- package/package.json +17 -8
- package/server.ts +455 -247
package/dist/client.d.ts
CHANGED
|
@@ -1,196 +1,140 @@
|
|
|
1
1
|
import { Hono, MiddlewareHandler, Context } from 'hono';
|
|
2
|
+
import { Component, JSX } from 'solid-js';
|
|
2
3
|
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
declare function ref<T>(value: T): Ref<T>;
|
|
38
|
-
declare function shallowRef<T>(value: T): Ref<T>;
|
|
39
|
-
declare function triggerRef(r: Ref): void;
|
|
40
|
-
declare function isRef<T = unknown>(r: unknown): r is Ref<T>;
|
|
41
|
-
declare function unref<T>(r: T | Ref<T>): T;
|
|
42
|
-
declare function toRef<T extends object, K extends keyof T>(obj: T, key: K): Ref<T[K]>;
|
|
43
|
-
declare function toRefs<T extends object>(obj: T): {
|
|
44
|
-
[K in keyof T]: Ref<T[K]>;
|
|
45
|
-
};
|
|
46
|
-
interface WritableComputedRef<T> extends Ref<T> {
|
|
47
|
-
readonly effect: ReactiveEffect;
|
|
48
|
-
}
|
|
49
|
-
interface ComputedRef<T> extends WritableComputedRef<T> {
|
|
50
|
-
readonly value: T;
|
|
4
|
+
type HonoMiddleware = MiddlewareHandler;
|
|
5
|
+
type LoaderCtx = Context;
|
|
6
|
+
interface SEOMeta {
|
|
7
|
+
title?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
keywords?: string;
|
|
10
|
+
author?: string;
|
|
11
|
+
robots?: string;
|
|
12
|
+
canonical?: string;
|
|
13
|
+
themeColor?: string;
|
|
14
|
+
ogTitle?: string;
|
|
15
|
+
ogDescription?: string;
|
|
16
|
+
ogImage?: string;
|
|
17
|
+
ogImageAlt?: string;
|
|
18
|
+
ogImageWidth?: string;
|
|
19
|
+
ogImageHeight?: string;
|
|
20
|
+
ogUrl?: string;
|
|
21
|
+
ogType?: string;
|
|
22
|
+
ogSiteName?: string;
|
|
23
|
+
ogLocale?: string;
|
|
24
|
+
twitterCard?: 'summary' | 'summary_large_image' | 'app' | 'player';
|
|
25
|
+
twitterSite?: string;
|
|
26
|
+
twitterCreator?: string;
|
|
27
|
+
twitterTitle?: string;
|
|
28
|
+
twitterDescription?: string;
|
|
29
|
+
twitterImage?: string;
|
|
30
|
+
twitterImageAlt?: string;
|
|
31
|
+
jsonLd?: Record<string, unknown> | Record<string, unknown>[];
|
|
32
|
+
extra?: Array<{
|
|
33
|
+
name?: string;
|
|
34
|
+
property?: string;
|
|
35
|
+
httpEquiv?: string;
|
|
36
|
+
content: string;
|
|
37
|
+
}>;
|
|
51
38
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
set: (v: T) => void;
|
|
56
|
-
}): WritableComputedRef<T>;
|
|
57
|
-
declare function reactive<T extends object>(target: T): T;
|
|
58
|
-
declare function shallowReactive<T extends object>(target: T): T;
|
|
59
|
-
declare function readonly<T extends object>(target: T): Readonly<T>;
|
|
60
|
-
declare function markRaw<T extends object>(value: T): T;
|
|
61
|
-
declare function toRaw<T>(observed: T): T;
|
|
62
|
-
declare function isReactive(value: unknown): boolean;
|
|
63
|
-
declare function isReadonly(value: unknown): boolean;
|
|
64
|
-
type WatchSource<T = unknown> = Ref<T> | ComputedRef<T> | (() => T);
|
|
65
|
-
type MultiSource = WatchSource[] | readonly WatchSource[];
|
|
66
|
-
type MapSources<T, Immediate = false> = {
|
|
67
|
-
[K in keyof T]: T[K] extends WatchSource<infer V> ? Immediate extends true ? V | undefined : V : T[K] extends object ? T[K] : never;
|
|
39
|
+
type PageProps<TData extends object = {}> = TData & {
|
|
40
|
+
url: string;
|
|
41
|
+
params: Record<string, string>;
|
|
68
42
|
};
|
|
69
|
-
interface
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
43
|
+
interface LayoutProps {
|
|
44
|
+
children: JSX.Element;
|
|
45
|
+
url: string;
|
|
46
|
+
params: Record<string, string>;
|
|
73
47
|
}
|
|
74
|
-
type StopHandle = () => void;
|
|
75
|
-
type CleanupFn = (fn: () => void) => void;
|
|
76
|
-
declare function watch<T>(source: WatchSource<T>, cb: (val: T, old: T | undefined, cleanup: CleanupFn) => void, opts?: WatchOptions): StopHandle;
|
|
77
|
-
declare function watch<T extends MultiSource>(source: T, cb: (val: MapSources<T>, old: MapSources<T, true>, cleanup: CleanupFn) => void, opts?: WatchOptions): StopHandle;
|
|
78
|
-
/**
|
|
79
|
-
* Subscribe to a Ref or computed getter inside a JSX component.
|
|
80
|
-
* On the server, returns the current value (no reactivity needed).
|
|
81
|
-
* On the client, re-renders the component whenever the value changes.
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* const count = ref(0)
|
|
85
|
-
* function Counter() {
|
|
86
|
-
* const n = use(count)
|
|
87
|
-
* return <button onClick={() => count.value++}>{n}</button>
|
|
88
|
-
* }
|
|
89
|
-
*/
|
|
90
|
-
declare function use<T>(source: Ref<T> | (() => T)): T;
|
|
91
|
-
/**
|
|
92
|
-
* Create a component-local reactive Ref.
|
|
93
|
-
* Unlike module-level `ref()`, this is scoped to the component lifecycle.
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* function Input() {
|
|
97
|
-
* const text = useLocalRef('')
|
|
98
|
-
* return <input value={use(text)} onInput={e => text.value = e.target.value} />
|
|
99
|
-
* }
|
|
100
|
-
*/
|
|
101
|
-
declare function useLocalRef<T>(init: T): Ref<T>;
|
|
102
|
-
/**
|
|
103
|
-
* Create a component-local reactive object.
|
|
104
|
-
* @example
|
|
105
|
-
* function Form() {
|
|
106
|
-
* const form = useLocalReactive({ name: '', email: '' })
|
|
107
|
-
* return <input value={form.name} onInput={e => form.name = e.target.value} />
|
|
108
|
-
* }
|
|
109
|
-
*/
|
|
110
|
-
declare function useLocalReactive<T extends object>(init: T): T;
|
|
111
|
-
type LoaderCtx = Context;
|
|
112
|
-
type FNetroMiddleware = MiddlewareHandler;
|
|
113
|
-
type AnyJSX = any;
|
|
114
48
|
interface PageDef<TData extends object = {}> {
|
|
115
49
|
readonly __type: 'page';
|
|
116
50
|
path: string;
|
|
117
|
-
|
|
118
|
-
middleware?: FNetroMiddleware[];
|
|
119
|
-
/** Server-side data loader. Return value becomes Page props. */
|
|
51
|
+
middleware?: HonoMiddleware[];
|
|
120
52
|
loader?: (c: LoaderCtx) => TData | Promise<TData>;
|
|
121
|
-
|
|
53
|
+
seo?: SEOMeta | ((data: TData, params: Record<string, string>) => SEOMeta);
|
|
122
54
|
layout?: LayoutDef | false;
|
|
123
|
-
|
|
124
|
-
Page: (props: TData & {
|
|
125
|
-
url: string;
|
|
126
|
-
params: Record<string, string>;
|
|
127
|
-
}) => AnyJSX;
|
|
55
|
+
Page: Component<PageProps<TData>>;
|
|
128
56
|
}
|
|
129
57
|
interface GroupDef {
|
|
130
58
|
readonly __type: 'group';
|
|
131
|
-
/** URL prefix — e.g. '/admin' */
|
|
132
59
|
prefix: string;
|
|
133
|
-
/** Layout override for all pages in this group */
|
|
134
60
|
layout?: LayoutDef | false;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
/** Pages and nested groups */
|
|
138
|
-
routes: (PageDef<any> | GroupDef | ApiRouteDef)[];
|
|
61
|
+
middleware?: HonoMiddleware[];
|
|
62
|
+
routes: Route[];
|
|
139
63
|
}
|
|
140
64
|
interface LayoutDef {
|
|
141
65
|
readonly __type: 'layout';
|
|
142
|
-
Component:
|
|
143
|
-
children: AnyJSX;
|
|
144
|
-
url: string;
|
|
145
|
-
params: Record<string, string>;
|
|
146
|
-
}) => AnyJSX;
|
|
66
|
+
Component: Component<LayoutProps>;
|
|
147
67
|
}
|
|
148
68
|
interface ApiRouteDef {
|
|
149
69
|
readonly __type: 'api';
|
|
150
|
-
/** Mount path — e.g. '/api' or '/api/admin' */
|
|
151
70
|
path: string;
|
|
152
|
-
|
|
153
|
-
register: (app: Hono, middleware: FNetroMiddleware[]) => void;
|
|
154
|
-
}
|
|
155
|
-
interface MiddlewareDef {
|
|
156
|
-
readonly __type: 'middleware';
|
|
157
|
-
handler: FNetroMiddleware;
|
|
71
|
+
register: (app: Hono, globalMiddleware: HonoMiddleware[]) => void;
|
|
158
72
|
}
|
|
73
|
+
type Route = PageDef<any> | GroupDef | ApiRouteDef;
|
|
159
74
|
interface AppConfig {
|
|
160
|
-
/** Default layout for all pages */
|
|
161
75
|
layout?: LayoutDef;
|
|
162
|
-
|
|
163
|
-
middleware?:
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
76
|
+
seo?: SEOMeta;
|
|
77
|
+
middleware?: HonoMiddleware[];
|
|
78
|
+
routes: Route[];
|
|
79
|
+
notFound?: Component;
|
|
80
|
+
htmlAttrs?: Record<string, string>;
|
|
81
|
+
head?: string;
|
|
168
82
|
}
|
|
83
|
+
type ClientMiddleware = (url: string, next: () => Promise<void>) => Promise<void>;
|
|
169
84
|
declare function definePage<TData extends object = {}>(def: Omit<PageDef<TData>, '__type'>): PageDef<TData>;
|
|
170
85
|
declare function defineGroup(def: Omit<GroupDef, '__type'>): GroupDef;
|
|
171
|
-
declare function defineLayout(Component:
|
|
172
|
-
declare function defineMiddleware(handler: FNetroMiddleware): MiddlewareDef;
|
|
86
|
+
declare function defineLayout(Component: Component<LayoutProps>): LayoutDef;
|
|
173
87
|
declare function defineApiRoute(path: string, register: ApiRouteDef['register']): ApiRouteDef;
|
|
88
|
+
interface ResolvedRoute {
|
|
89
|
+
fullPath: string;
|
|
90
|
+
page: PageDef<any>;
|
|
91
|
+
layout: LayoutDef | false | undefined;
|
|
92
|
+
middleware: HonoMiddleware[];
|
|
93
|
+
}
|
|
94
|
+
declare function resolveRoutes(routes: Route[], options?: {
|
|
95
|
+
prefix?: string;
|
|
96
|
+
middleware?: HonoMiddleware[];
|
|
97
|
+
layout?: LayoutDef | false;
|
|
98
|
+
}): {
|
|
99
|
+
pages: ResolvedRoute[];
|
|
100
|
+
apis: ApiRouteDef[];
|
|
101
|
+
};
|
|
102
|
+
interface CompiledPath {
|
|
103
|
+
re: RegExp;
|
|
104
|
+
keys: string[];
|
|
105
|
+
}
|
|
106
|
+
declare function compilePath(path: string): CompiledPath;
|
|
107
|
+
declare function matchPath(compiled: CompiledPath, pathname: string): Record<string, string> | null;
|
|
108
|
+
declare const SPA_HEADER = "x-fnetro-spa";
|
|
109
|
+
declare const STATE_KEY = "__FNETRO_STATE__";
|
|
110
|
+
declare const PARAMS_KEY = "__FNETRO_PARAMS__";
|
|
111
|
+
declare const SEO_KEY = "__FNETRO_SEO__";
|
|
174
112
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Register a client-side navigation middleware.
|
|
115
|
+
* Must be called **before** `boot()`.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* useClientMiddleware(async (url, next) => {
|
|
119
|
+
* if (!isLoggedIn() && url.startsWith('/dashboard')) {
|
|
120
|
+
* await navigate('/login')
|
|
121
|
+
* return // cancel original navigation
|
|
122
|
+
* }
|
|
123
|
+
* await next()
|
|
124
|
+
* })
|
|
125
|
+
*/
|
|
126
|
+
declare function useClientMiddleware(mw: ClientMiddleware): void;
|
|
180
127
|
interface NavigateOptions {
|
|
181
128
|
replace?: boolean;
|
|
182
129
|
scroll?: boolean;
|
|
183
130
|
}
|
|
184
131
|
declare function navigate(to: string, opts?: NavigateOptions): Promise<void>;
|
|
185
|
-
/** Warm the prefetch cache for a URL
|
|
132
|
+
/** Warm the prefetch cache for a URL on hover/focus/etc. */
|
|
186
133
|
declare function prefetch(url: string): void;
|
|
187
134
|
interface BootOptions extends AppConfig {
|
|
188
|
-
/**
|
|
189
|
-
* Enable hover-based prefetching (default: true).
|
|
190
|
-
* Fires a SPA fetch when the user hovers any <a> that matches a route.
|
|
191
|
-
*/
|
|
135
|
+
/** Enable hover-based prefetching. @default true */
|
|
192
136
|
prefetchOnHover?: boolean;
|
|
193
137
|
}
|
|
194
138
|
declare function boot(options: BootOptions): Promise<void>;
|
|
195
139
|
|
|
196
|
-
export { type ApiRouteDef, type AppConfig, type BootOptions, type
|
|
140
|
+
export { type ApiRouteDef, type AppConfig, type BootOptions, type ClientMiddleware, type CompiledPath, type GroupDef, type HonoMiddleware, type LayoutDef, type LayoutProps, type LoaderCtx, type NavigateOptions, PARAMS_KEY, type PageDef, type PageProps, type ResolvedRoute, type Route, type SEOMeta, SEO_KEY, SPA_HEADER, STATE_KEY, boot, compilePath, defineApiRoute, defineGroup, defineLayout, definePage, matchPath, navigate, prefetch, resolveRoutes, useClientMiddleware };
|