@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/core.d.ts
CHANGED
|
@@ -1,200 +1,113 @@
|
|
|
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
|
-
readonly [IS_REF]: true;
|
|
38
|
-
}
|
|
39
|
-
declare function ref<T>(value: T): Ref<T>;
|
|
40
|
-
declare function shallowRef<T>(value: T): Ref<T>;
|
|
41
|
-
declare function triggerRef(r: Ref): void;
|
|
42
|
-
declare function isRef<T = unknown>(r: unknown): r is Ref<T>;
|
|
43
|
-
declare function unref<T>(r: T | Ref<T>): T;
|
|
44
|
-
declare function toRef<T extends object, K extends keyof T>(obj: T, key: K): Ref<T[K]>;
|
|
45
|
-
declare function toRefs<T extends object>(obj: T): {
|
|
46
|
-
[K in keyof T]: Ref<T[K]>;
|
|
47
|
-
};
|
|
48
|
-
interface WritableComputedRef<T> extends Ref<T> {
|
|
49
|
-
readonly effect: ReactiveEffect;
|
|
50
|
-
}
|
|
51
|
-
interface ComputedRef<T> extends WritableComputedRef<T> {
|
|
52
|
-
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
|
+
}>;
|
|
53
38
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
set: (v: T) => void;
|
|
58
|
-
}): WritableComputedRef<T>;
|
|
59
|
-
declare function reactive<T extends object>(target: T): T;
|
|
60
|
-
declare function shallowReactive<T extends object>(target: T): T;
|
|
61
|
-
declare function readonly<T extends object>(target: T): Readonly<T>;
|
|
62
|
-
declare function markRaw<T extends object>(value: T): T;
|
|
63
|
-
declare function toRaw<T>(observed: T): T;
|
|
64
|
-
declare function isReactive(value: unknown): boolean;
|
|
65
|
-
declare function isReadonly(value: unknown): boolean;
|
|
66
|
-
type WatchSource<T = unknown> = Ref<T> | ComputedRef<T> | (() => T);
|
|
67
|
-
type MultiSource = WatchSource[] | readonly WatchSource[];
|
|
68
|
-
type MapSources<T, Immediate = false> = {
|
|
69
|
-
[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>;
|
|
70
42
|
};
|
|
71
|
-
interface
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
type StopHandle = () => void;
|
|
77
|
-
type CleanupFn = (fn: () => void) => void;
|
|
78
|
-
declare function watch<T>(source: WatchSource<T>, cb: (val: T, old: T | undefined, cleanup: CleanupFn) => void, opts?: WatchOptions): StopHandle;
|
|
79
|
-
declare function watch<T extends MultiSource>(source: T, cb: (val: MapSources<T>, old: MapSources<T, true>, cleanup: CleanupFn) => void, opts?: WatchOptions): StopHandle;
|
|
80
|
-
interface FNetroHooks {
|
|
81
|
-
useValue<T>(r: Ref<T> | (() => T)): T;
|
|
82
|
-
useLocalRef<T>(init: T): Ref<T>;
|
|
83
|
-
useLocalReactive<T extends object>(init: T): T;
|
|
43
|
+
interface LayoutProps {
|
|
44
|
+
children: JSX.Element;
|
|
45
|
+
url: string;
|
|
46
|
+
params: Record<string, string>;
|
|
84
47
|
}
|
|
85
|
-
declare const __hooks: FNetroHooks;
|
|
86
|
-
/**
|
|
87
|
-
* Subscribe to a Ref or computed getter inside a JSX component.
|
|
88
|
-
* On the server, returns the current value (no reactivity needed).
|
|
89
|
-
* On the client, re-renders the component whenever the value changes.
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* const count = ref(0)
|
|
93
|
-
* function Counter() {
|
|
94
|
-
* const n = use(count)
|
|
95
|
-
* return <button onClick={() => count.value++}>{n}</button>
|
|
96
|
-
* }
|
|
97
|
-
*/
|
|
98
|
-
declare function use<T>(source: Ref<T> | (() => T)): T;
|
|
99
|
-
/**
|
|
100
|
-
* Create a component-local reactive Ref.
|
|
101
|
-
* Unlike module-level `ref()`, this is scoped to the component lifecycle.
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* function Input() {
|
|
105
|
-
* const text = useLocalRef('')
|
|
106
|
-
* return <input value={use(text)} onInput={e => text.value = e.target.value} />
|
|
107
|
-
* }
|
|
108
|
-
*/
|
|
109
|
-
declare function useLocalRef<T>(init: T): Ref<T>;
|
|
110
|
-
/**
|
|
111
|
-
* Create a component-local reactive object.
|
|
112
|
-
* @example
|
|
113
|
-
* function Form() {
|
|
114
|
-
* const form = useLocalReactive({ name: '', email: '' })
|
|
115
|
-
* return <input value={form.name} onInput={e => form.name = e.target.value} />
|
|
116
|
-
* }
|
|
117
|
-
*/
|
|
118
|
-
declare function useLocalReactive<T extends object>(init: T): T;
|
|
119
|
-
type LoaderCtx = Context;
|
|
120
|
-
type FNetroMiddleware = MiddlewareHandler;
|
|
121
|
-
type AnyJSX = any;
|
|
122
48
|
interface PageDef<TData extends object = {}> {
|
|
123
49
|
readonly __type: 'page';
|
|
124
50
|
path: string;
|
|
125
|
-
|
|
126
|
-
middleware?: FNetroMiddleware[];
|
|
127
|
-
/** Server-side data loader. Return value becomes Page props. */
|
|
51
|
+
middleware?: HonoMiddleware[];
|
|
128
52
|
loader?: (c: LoaderCtx) => TData | Promise<TData>;
|
|
129
|
-
|
|
53
|
+
seo?: SEOMeta | ((data: TData, params: Record<string, string>) => SEOMeta);
|
|
130
54
|
layout?: LayoutDef | false;
|
|
131
|
-
|
|
132
|
-
Page: (props: TData & {
|
|
133
|
-
url: string;
|
|
134
|
-
params: Record<string, string>;
|
|
135
|
-
}) => AnyJSX;
|
|
55
|
+
Page: Component<PageProps<TData>>;
|
|
136
56
|
}
|
|
137
57
|
interface GroupDef {
|
|
138
58
|
readonly __type: 'group';
|
|
139
|
-
/** URL prefix — e.g. '/admin' */
|
|
140
59
|
prefix: string;
|
|
141
|
-
/** Layout override for all pages in this group */
|
|
142
60
|
layout?: LayoutDef | false;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
/** Pages and nested groups */
|
|
146
|
-
routes: (PageDef<any> | GroupDef | ApiRouteDef)[];
|
|
61
|
+
middleware?: HonoMiddleware[];
|
|
62
|
+
routes: Route[];
|
|
147
63
|
}
|
|
148
64
|
interface LayoutDef {
|
|
149
65
|
readonly __type: 'layout';
|
|
150
|
-
Component:
|
|
151
|
-
children: AnyJSX;
|
|
152
|
-
url: string;
|
|
153
|
-
params: Record<string, string>;
|
|
154
|
-
}) => AnyJSX;
|
|
66
|
+
Component: Component<LayoutProps>;
|
|
155
67
|
}
|
|
156
68
|
interface ApiRouteDef {
|
|
157
69
|
readonly __type: 'api';
|
|
158
|
-
/** Mount path — e.g. '/api' or '/api/admin' */
|
|
159
70
|
path: string;
|
|
160
|
-
|
|
161
|
-
register: (app: Hono, middleware: FNetroMiddleware[]) => void;
|
|
162
|
-
}
|
|
163
|
-
interface MiddlewareDef {
|
|
164
|
-
readonly __type: 'middleware';
|
|
165
|
-
handler: FNetroMiddleware;
|
|
71
|
+
register: (app: Hono, globalMiddleware: HonoMiddleware[]) => void;
|
|
166
72
|
}
|
|
73
|
+
type Route = PageDef<any> | GroupDef | ApiRouteDef;
|
|
167
74
|
interface AppConfig {
|
|
168
|
-
/** Default layout for all pages */
|
|
169
75
|
layout?: LayoutDef;
|
|
170
|
-
|
|
171
|
-
middleware?:
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
76
|
+
seo?: SEOMeta;
|
|
77
|
+
middleware?: HonoMiddleware[];
|
|
78
|
+
routes: Route[];
|
|
79
|
+
notFound?: Component;
|
|
80
|
+
htmlAttrs?: Record<string, string>;
|
|
81
|
+
head?: string;
|
|
176
82
|
}
|
|
83
|
+
type ClientMiddleware = (url: string, next: () => Promise<void>) => Promise<void>;
|
|
177
84
|
declare function definePage<TData extends object = {}>(def: Omit<PageDef<TData>, '__type'>): PageDef<TData>;
|
|
178
85
|
declare function defineGroup(def: Omit<GroupDef, '__type'>): GroupDef;
|
|
179
|
-
declare function defineLayout(Component:
|
|
180
|
-
declare function defineMiddleware(handler: FNetroMiddleware): MiddlewareDef;
|
|
86
|
+
declare function defineLayout(Component: Component<LayoutProps>): LayoutDef;
|
|
181
87
|
declare function defineApiRoute(path: string, register: ApiRouteDef['register']): ApiRouteDef;
|
|
182
88
|
interface ResolvedRoute {
|
|
183
89
|
fullPath: string;
|
|
184
90
|
page: PageDef<any>;
|
|
185
91
|
layout: LayoutDef | false | undefined;
|
|
186
|
-
middleware:
|
|
92
|
+
middleware: HonoMiddleware[];
|
|
187
93
|
}
|
|
188
|
-
declare function resolveRoutes(routes:
|
|
94
|
+
declare function resolveRoutes(routes: Route[], options?: {
|
|
189
95
|
prefix?: string;
|
|
190
|
-
middleware?:
|
|
96
|
+
middleware?: HonoMiddleware[];
|
|
191
97
|
layout?: LayoutDef | false;
|
|
192
98
|
}): {
|
|
193
99
|
pages: ResolvedRoute[];
|
|
194
100
|
apis: ApiRouteDef[];
|
|
195
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;
|
|
196
108
|
declare const SPA_HEADER = "x-fnetro-spa";
|
|
197
109
|
declare const STATE_KEY = "__FNETRO_STATE__";
|
|
198
110
|
declare const PARAMS_KEY = "__FNETRO_PARAMS__";
|
|
111
|
+
declare const SEO_KEY = "__FNETRO_SEO__";
|
|
199
112
|
|
|
200
|
-
export { type
|
|
113
|
+
export { type ApiRouteDef, type AppConfig, type ClientMiddleware, type CompiledPath, type GroupDef, type HonoMiddleware, type LayoutDef, type LayoutProps, type LoaderCtx, PARAMS_KEY, type PageDef, type PageProps, type ResolvedRoute, type Route, type SEOMeta, SEO_KEY, SPA_HEADER, STATE_KEY, compilePath, defineApiRoute, defineGroup, defineLayout, definePage, matchPath, resolveRoutes };
|