@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,231 @@
1
+ import { Hono, MiddlewareHandler, Context } from 'hono';
2
+ import { Plugin } from 'vite';
3
+
4
+ type EffectFn = () => void | (() => void);
5
+ declare const IS_REF: unique symbol;
6
+ declare class ReactiveEffect {
7
+ fn: () => any;
8
+ scheduler?: (() => void) | undefined;
9
+ scope?: EffectScope | undefined;
10
+ deps: Set<ReactiveEffect>[];
11
+ active: boolean;
12
+ cleanup?: () => void;
13
+ computed: boolean;
14
+ constructor(fn: () => any, scheduler?: (() => void) | undefined, scope?: EffectScope | undefined);
15
+ run(): any;
16
+ stop(): void;
17
+ }
18
+ declare class EffectScope {
19
+ effects: ReactiveEffect[];
20
+ cleanups: (() => void)[];
21
+ active: boolean;
22
+ run<T>(fn: () => T): T;
23
+ stop(): void;
24
+ onCleanup(fn: () => void): void;
25
+ }
26
+ declare function effectScope(): EffectScope;
27
+ declare function effect(fn: EffectFn): () => void;
28
+ interface WatchEffectOptions {
29
+ flush?: 'sync' | 'post';
30
+ onTrack?: (e: any) => void;
31
+ onTrigger?: (e: any) => void;
32
+ }
33
+ declare function watchEffect(fn: EffectFn, opts?: WatchEffectOptions): () => void;
34
+ interface Ref<T = unknown> {
35
+ value: T;
36
+ readonly [IS_REF]: true;
37
+ }
38
+ declare function ref<T>(value: T): Ref<T>;
39
+ declare function shallowRef<T>(value: T): Ref<T>;
40
+ declare function triggerRef(r: Ref): void;
41
+ declare function isRef<T = unknown>(r: unknown): r is Ref<T>;
42
+ declare function unref<T>(r: T | Ref<T>): T;
43
+ declare function toRef<T extends object, K extends keyof T>(obj: T, key: K): Ref<T[K]>;
44
+ declare function toRefs<T extends object>(obj: T): {
45
+ [K in keyof T]: Ref<T[K]>;
46
+ };
47
+ interface WritableComputedRef<T> extends Ref<T> {
48
+ readonly effect: ReactiveEffect;
49
+ }
50
+ interface ComputedRef<T> extends WritableComputedRef<T> {
51
+ readonly value: T;
52
+ }
53
+ declare function computed<T>(getter: () => T): ComputedRef<T>;
54
+ declare function computed<T>(opts: {
55
+ get: () => T;
56
+ set: (v: T) => void;
57
+ }): WritableComputedRef<T>;
58
+ declare function reactive<T extends object>(target: T): T;
59
+ declare function shallowReactive<T extends object>(target: T): T;
60
+ declare function readonly<T extends object>(target: T): Readonly<T>;
61
+ declare function markRaw<T extends object>(value: T): T;
62
+ declare function toRaw<T>(observed: T): T;
63
+ declare function isReactive(value: unknown): boolean;
64
+ declare function isReadonly(value: unknown): boolean;
65
+ type WatchSource<T = unknown> = Ref<T> | ComputedRef<T> | (() => T);
66
+ type MultiSource = WatchSource[] | readonly WatchSource[];
67
+ type MapSources<T, Immediate = false> = {
68
+ [K in keyof T]: T[K] extends WatchSource<infer V> ? Immediate extends true ? V | undefined : V : T[K] extends object ? T[K] : never;
69
+ };
70
+ interface WatchOptions<Immediate = boolean> {
71
+ immediate?: Immediate;
72
+ deep?: boolean;
73
+ once?: boolean;
74
+ }
75
+ type StopHandle = () => void;
76
+ type CleanupFn = (fn: () => void) => void;
77
+ declare function watch<T>(source: WatchSource<T>, cb: (val: T, old: T | undefined, cleanup: CleanupFn) => void, opts?: WatchOptions): StopHandle;
78
+ declare function watch<T extends MultiSource>(source: T, cb: (val: MapSources<T>, old: MapSources<T, true>, cleanup: CleanupFn) => void, opts?: WatchOptions): StopHandle;
79
+ /**
80
+ * Subscribe to a Ref or computed getter inside a JSX component.
81
+ * On the server, returns the current value (no reactivity needed).
82
+ * On the client, re-renders the component whenever the value changes.
83
+ *
84
+ * @example
85
+ * const count = ref(0)
86
+ * function Counter() {
87
+ * const n = use(count)
88
+ * return <button onClick={() => count.value++}>{n}</button>
89
+ * }
90
+ */
91
+ declare function use<T>(source: Ref<T> | (() => T)): T;
92
+ /**
93
+ * Create a component-local reactive Ref.
94
+ * Unlike module-level `ref()`, this is scoped to the component lifecycle.
95
+ *
96
+ * @example
97
+ * function Input() {
98
+ * const text = useLocalRef('')
99
+ * return <input value={use(text)} onInput={e => text.value = e.target.value} />
100
+ * }
101
+ */
102
+ declare function useLocalRef<T>(init: T): Ref<T>;
103
+ /**
104
+ * Create a component-local reactive object.
105
+ * @example
106
+ * function Form() {
107
+ * const form = useLocalReactive({ name: '', email: '' })
108
+ * return <input value={form.name} onInput={e => form.name = e.target.value} />
109
+ * }
110
+ */
111
+ declare function useLocalReactive<T extends object>(init: T): T;
112
+ type LoaderCtx = Context;
113
+ type FNetroMiddleware = MiddlewareHandler;
114
+ type AnyJSX = any;
115
+ interface PageDef<TData extends object = {}> {
116
+ readonly __type: 'page';
117
+ path: string;
118
+ /** Middleware applied only to this route */
119
+ middleware?: FNetroMiddleware[];
120
+ /** Server-side data loader. Return value becomes Page props. */
121
+ loader?: (c: LoaderCtx) => TData | Promise<TData>;
122
+ /** Override the group/app layout for this page. Pass `false` to use no layout. */
123
+ layout?: LayoutDef | false;
124
+ /** The JSX page component */
125
+ Page: (props: TData & {
126
+ url: string;
127
+ params: Record<string, string>;
128
+ }) => AnyJSX;
129
+ }
130
+ interface GroupDef {
131
+ readonly __type: 'group';
132
+ /** URL prefix — e.g. '/admin' */
133
+ prefix: string;
134
+ /** Layout override for all pages in this group */
135
+ layout?: LayoutDef | false;
136
+ /** Middleware applied to every route in the group */
137
+ middleware?: FNetroMiddleware[];
138
+ /** Pages and nested groups */
139
+ routes: (PageDef<any> | GroupDef | ApiRouteDef)[];
140
+ }
141
+ interface LayoutDef {
142
+ readonly __type: 'layout';
143
+ Component: (props: {
144
+ children: AnyJSX;
145
+ url: string;
146
+ params: Record<string, string>;
147
+ }) => AnyJSX;
148
+ }
149
+ interface ApiRouteDef {
150
+ readonly __type: 'api';
151
+ /** Mount path — e.g. '/api' or '/api/admin' */
152
+ path: string;
153
+ /** Register raw Hono routes on the provided sub-app */
154
+ register: (app: Hono, middleware: FNetroMiddleware[]) => void;
155
+ }
156
+ interface MiddlewareDef {
157
+ readonly __type: 'middleware';
158
+ handler: FNetroMiddleware;
159
+ }
160
+ interface AppConfig {
161
+ /** Default layout for all pages */
162
+ layout?: LayoutDef;
163
+ /** Global middleware applied before every route */
164
+ middleware?: FNetroMiddleware[];
165
+ /** Top-level routes, groups, and API routes */
166
+ routes: (PageDef<any> | GroupDef | ApiRouteDef)[];
167
+ /** 404 page */
168
+ notFound?: () => AnyJSX;
169
+ }
170
+ declare function definePage<TData extends object = {}>(def: Omit<PageDef<TData>, '__type'>): PageDef<TData>;
171
+ declare function defineGroup(def: Omit<GroupDef, '__type'>): GroupDef;
172
+ declare function defineLayout(Component: LayoutDef['Component']): LayoutDef;
173
+ declare function defineMiddleware(handler: FNetroMiddleware): MiddlewareDef;
174
+ declare function defineApiRoute(path: string, register: ApiRouteDef['register']): ApiRouteDef;
175
+ declare const SPA_HEADER = "x-fnetro-spa";
176
+ declare const STATE_KEY = "__FNETRO_STATE__";
177
+
178
+ interface FNetroApp {
179
+ /** The underlying Hono instance — add raw routes, custom error handlers, etc. */
180
+ app: Hono;
181
+ /** Hono fetch handler — export this as default for edge runtimes */
182
+ handler: Hono['fetch'];
183
+ }
184
+ declare function createFNetro(config: AppConfig): FNetroApp;
185
+ type Runtime = 'node' | 'bun' | 'deno' | 'edge' | 'unknown';
186
+ declare function detectRuntime(): Runtime;
187
+ interface ServeOptions {
188
+ app: FNetroApp;
189
+ port?: number;
190
+ hostname?: string;
191
+ /** Override auto-detected runtime. */
192
+ runtime?: Runtime;
193
+ /** Static assets root directory (served at /assets/*). @default './dist' */
194
+ staticDir?: string;
195
+ }
196
+ declare function serve(opts: ServeOptions): Promise<void>;
197
+ interface FNetroPluginOptions {
198
+ /**
199
+ * Server entry file (exports the Hono app / calls serve()).
200
+ * @default 'app/server.ts'
201
+ */
202
+ serverEntry?: string;
203
+ /**
204
+ * Client entry file (calls boot()).
205
+ * @default 'app/client.ts'
206
+ */
207
+ clientEntry?: string;
208
+ /**
209
+ * Output directory for the server bundle.
210
+ * @default 'dist/server'
211
+ */
212
+ serverOutDir?: string;
213
+ /**
214
+ * Output directory for client assets (JS, CSS).
215
+ * @default 'dist/assets'
216
+ */
217
+ clientOutDir?: string;
218
+ /**
219
+ * External packages for the server bundle.
220
+ * Node built-ins are always external.
221
+ */
222
+ serverExternal?: string[];
223
+ /**
224
+ * Emit type declarations for framework types.
225
+ * @default false
226
+ */
227
+ dts?: boolean;
228
+ }
229
+ declare function fnetroVitePlugin(opts?: FNetroPluginOptions): Plugin[];
230
+
231
+ export { type AnyJSX, type ApiRouteDef, type AppConfig, type ComputedRef, type FNetroApp, type FNetroMiddleware, type FNetroPluginOptions, type GroupDef, type LayoutDef, type LoaderCtx, type MiddlewareDef, type PageDef, type Ref, type Runtime, SPA_HEADER, STATE_KEY, type ServeOptions, type WatchOptions, type WatchSource, type WritableComputedRef, computed, createFNetro, defineApiRoute, defineGroup, defineLayout, defineMiddleware, definePage, detectRuntime, effect, effectScope, fnetroVitePlugin, isReactive, isReadonly, isRef, markRaw, reactive, readonly, ref, serve, shallowReactive, shallowRef, toRaw, toRef, toRefs, triggerRef, unref, use, useLocalReactive, useLocalRef, watch, watchEffect };