@netrojs/fnetro 0.1.2

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.
@@ -0,0 +1,196 @@
1
+ import { Hono, MiddlewareHandler, Context } from 'hono';
2
+
3
+ type EffectFn = () => void | (() => void);
4
+ declare const IS_REF: unique symbol;
5
+ declare class ReactiveEffect {
6
+ fn: () => any;
7
+ scheduler?: (() => void) | undefined;
8
+ scope?: EffectScope | undefined;
9
+ deps: Set<ReactiveEffect>[];
10
+ active: boolean;
11
+ cleanup?: () => void;
12
+ computed: boolean;
13
+ constructor(fn: () => any, scheduler?: (() => void) | undefined, scope?: EffectScope | undefined);
14
+ run(): any;
15
+ stop(): void;
16
+ }
17
+ declare class EffectScope {
18
+ effects: ReactiveEffect[];
19
+ cleanups: (() => void)[];
20
+ active: boolean;
21
+ run<T>(fn: () => T): T;
22
+ stop(): void;
23
+ onCleanup(fn: () => void): void;
24
+ }
25
+ declare function effectScope(): EffectScope;
26
+ declare function effect(fn: EffectFn): () => void;
27
+ interface WatchEffectOptions {
28
+ flush?: 'sync' | 'post';
29
+ onTrack?: (e: any) => void;
30
+ onTrigger?: (e: any) => void;
31
+ }
32
+ declare function watchEffect(fn: EffectFn, opts?: WatchEffectOptions): () => void;
33
+ interface Ref<T = unknown> {
34
+ value: T;
35
+ readonly [IS_REF]: true;
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;
51
+ }
52
+ declare function computed<T>(getter: () => T): ComputedRef<T>;
53
+ declare function computed<T>(opts: {
54
+ get: () => T;
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;
68
+ };
69
+ interface WatchOptions<Immediate = boolean> {
70
+ immediate?: Immediate;
71
+ deep?: boolean;
72
+ once?: boolean;
73
+ }
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
+ interface PageDef<TData extends object = {}> {
115
+ readonly __type: 'page';
116
+ path: string;
117
+ /** Middleware applied only to this route */
118
+ middleware?: FNetroMiddleware[];
119
+ /** Server-side data loader. Return value becomes Page props. */
120
+ loader?: (c: LoaderCtx) => TData | Promise<TData>;
121
+ /** Override the group/app layout for this page. Pass `false` to use no layout. */
122
+ layout?: LayoutDef | false;
123
+ /** The JSX page component */
124
+ Page: (props: TData & {
125
+ url: string;
126
+ params: Record<string, string>;
127
+ }) => AnyJSX;
128
+ }
129
+ interface GroupDef {
130
+ readonly __type: 'group';
131
+ /** URL prefix — e.g. '/admin' */
132
+ prefix: string;
133
+ /** Layout override for all pages in this group */
134
+ layout?: LayoutDef | false;
135
+ /** Middleware applied to every route in the group */
136
+ middleware?: FNetroMiddleware[];
137
+ /** Pages and nested groups */
138
+ routes: (PageDef<any> | GroupDef | ApiRouteDef)[];
139
+ }
140
+ interface LayoutDef {
141
+ readonly __type: 'layout';
142
+ Component: (props: {
143
+ children: AnyJSX;
144
+ url: string;
145
+ params: Record<string, string>;
146
+ }) => AnyJSX;
147
+ }
148
+ interface ApiRouteDef {
149
+ readonly __type: 'api';
150
+ /** Mount path — e.g. '/api' or '/api/admin' */
151
+ path: string;
152
+ /** Register raw Hono routes on the provided sub-app */
153
+ register: (app: Hono, middleware: FNetroMiddleware[]) => void;
154
+ }
155
+ interface MiddlewareDef {
156
+ readonly __type: 'middleware';
157
+ handler: FNetroMiddleware;
158
+ }
159
+ interface AppConfig {
160
+ /** Default layout for all pages */
161
+ layout?: LayoutDef;
162
+ /** Global middleware applied before every route */
163
+ middleware?: FNetroMiddleware[];
164
+ /** Top-level routes, groups, and API routes */
165
+ routes: (PageDef<any> | GroupDef | ApiRouteDef)[];
166
+ /** 404 page */
167
+ notFound?: () => AnyJSX;
168
+ }
169
+ declare function definePage<TData extends object = {}>(def: Omit<PageDef<TData>, '__type'>): PageDef<TData>;
170
+ declare function defineGroup(def: Omit<GroupDef, '__type'>): GroupDef;
171
+ declare function defineLayout(Component: LayoutDef['Component']): LayoutDef;
172
+ declare function defineMiddleware(handler: FNetroMiddleware): MiddlewareDef;
173
+ declare function defineApiRoute(path: string, register: ApiRouteDef['register']): ApiRouteDef;
174
+
175
+ type NavListener = (url: string) => void | Promise<void>;
176
+ /** Called before each SPA navigation. Returning false cancels. */
177
+ declare function onBeforeNavigate(fn: NavListener): () => void;
178
+ /** Called after each SPA navigation (including initial boot). */
179
+ declare function onAfterNavigate(fn: NavListener): () => void;
180
+ interface NavigateOptions {
181
+ replace?: boolean;
182
+ scroll?: boolean;
183
+ }
184
+ declare function navigate(to: string, opts?: NavigateOptions): Promise<void>;
185
+ /** Warm the prefetch cache for a URL (call on hover / mousedown). */
186
+ declare function prefetch(url: string): void;
187
+ 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
+ */
192
+ prefetchOnHover?: boolean;
193
+ }
194
+ declare function boot(options: BootOptions): Promise<void>;
195
+
196
+ export { type ApiRouteDef, type AppConfig, type BootOptions, type ComputedRef, type GroupDef, type LayoutDef, type NavigateOptions, type PageDef, type Ref, type WatchOptions, type WatchSource, type WritableComputedRef, boot, computed, defineApiRoute, defineGroup, defineLayout, defineMiddleware, definePage, effect, effectScope, isReactive, isReadonly, isRef, markRaw, navigate, onAfterNavigate, onBeforeNavigate, prefetch, reactive, readonly, ref, shallowReactive, shallowRef, toRaw, toRef, toRefs, triggerRef, unref, use, useLocalReactive, useLocalRef, watch, watchEffect };