@netrojs/fnetro 0.1.5 → 0.2.0

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/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 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 getCurrentScope(): EffectScope | undefined;
27
- declare function onScopeDispose(fn: () => void): void;
28
- declare function effect(fn: EffectFn): () => void;
29
- interface WatchEffectOptions {
30
- flush?: 'sync' | 'post';
31
- onTrack?: (e: any) => void;
32
- onTrigger?: (e: any) => void;
33
- }
34
- declare function watchEffect(fn: EffectFn, opts?: WatchEffectOptions): () => void;
35
- interface Ref<T = unknown> {
36
- value: T;
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
- declare function computed<T>(getter: () => T): ComputedRef<T>;
55
- declare function computed<T>(opts: {
56
- get: () => T;
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 WatchOptions<Immediate = boolean> {
72
- immediate?: Immediate;
73
- deep?: boolean;
74
- once?: boolean;
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
- /** Middleware applied only to this route */
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
- /** Override the group/app layout for this page. Pass `false` to use no layout. */
53
+ seo?: SEOMeta | ((data: TData, params: Record<string, string>) => SEOMeta);
130
54
  layout?: LayoutDef | false;
131
- /** The JSX page component */
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
- /** Middleware applied to every route in the group */
144
- middleware?: FNetroMiddleware[];
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: (props: {
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
- /** Register raw Hono routes on the provided sub-app */
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
- /** Global middleware applied before every route */
171
- middleware?: FNetroMiddleware[];
172
- /** Top-level routes, groups, and API routes */
173
- routes: (PageDef<any> | GroupDef | ApiRouteDef)[];
174
- /** 404 page */
175
- notFound?: () => AnyJSX;
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: LayoutDef['Component']): LayoutDef;
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: FNetroMiddleware[];
92
+ middleware: HonoMiddleware[];
187
93
  }
188
- declare function resolveRoutes(routes: (PageDef<any> | GroupDef | ApiRouteDef)[], options?: {
94
+ declare function resolveRoutes(routes: Route[], options?: {
189
95
  prefix?: string;
190
- middleware?: FNetroMiddleware[];
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 AnyJSX, type ApiRouteDef, type AppConfig, type ComputedRef, type EffectFn, EffectScope, type FNetroMiddleware, type GroupDef, type LayoutDef, type LoaderCtx, type MiddlewareDef, type MultiSource, PARAMS_KEY, type PageDef, ReactiveEffect, type Ref, type ResolvedRoute, SPA_HEADER, STATE_KEY, type WatchEffectOptions, type WatchOptions, type WatchSource, type WritableComputedRef, __hooks, computed, defineApiRoute, defineGroup, defineLayout, defineMiddleware, definePage, effect, effectScope, getCurrentScope, isReactive, isReadonly, isRef, markRaw, onScopeDispose, reactive, readonly, ref, resolveRoutes, shallowReactive, shallowRef, toRaw, toRef, toRefs, triggerRef, unref, use, useLocalReactive, useLocalRef, watch, watchEffect };
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 };