@farm.js/core 0.1.0-beta.13 → 0.1.0-beta.14

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/vite.mjs CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  farmI18nClientBridgePlugin,
4
4
  farmPlugin,
5
5
  rewriteEarlySsrRelativeImports
6
- } from "./chunk-Z3YG4OZT.mjs";
6
+ } from "./chunk-PNFQQSRA.mjs";
7
7
  import "./chunk-LGHEOHBU.mjs";
8
8
  import "./chunk-FRPWCMMG.mjs";
9
9
  import "./chunk-53MVSX3R.mjs";
@@ -43,7 +43,7 @@ import "./chunk-J4FNJ5IU.mjs";
43
43
  import "./chunk-PFE6GMNE.mjs";
44
44
  import "./chunk-RHIFZZUI.mjs";
45
45
  import "./chunk-LM2YNO4U.mjs";
46
- import "./chunk-3WIRO3N7.mjs";
46
+ import "./chunk-ARCGE2VT.mjs";
47
47
  import "./chunk-KLA67WKG.mjs";
48
48
  import "./chunk-ITN462YM.mjs";
49
49
  import "./chunk-B232I2GP.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/core",
3
- "version": "0.1.0-beta.13",
3
+ "version": "0.1.0-beta.14",
4
4
  "description": "Core Farm.js framework for modern integrated apps",
5
5
  "keywords": [
6
6
  "@farm.js/core",
package/types/client.d.ts CHANGED
@@ -18,6 +18,13 @@ import type {
18
18
  } from "react";
19
19
  import type { DefinedCacheKey, InferCacheKeyData, RouteDataCacheKey } from "@farm.js/core/cache";
20
20
 
21
+ declare global {
22
+ namespace FarmJS {
23
+ /** @internal Application route patterns registered by generated types. */
24
+ interface RouteRegistry {}
25
+ }
26
+ }
27
+
21
28
  declare module "@farm.js/core/client" {
22
29
  export interface MiddlewareProps {
23
30
  data: Map<string, any>;
@@ -27,19 +34,123 @@ declare module "@farm.js/core/client" {
27
34
  data: Map<string, any>;
28
35
  }
29
36
 
30
- export interface PageProps {
31
- params: Record<string, string>;
37
+ export type AppRoutePattern = FarmJS.RouteRegistry extends {
38
+ pattern: infer TPattern extends string;
39
+ }
40
+ ? TPattern
41
+ : string;
42
+
43
+ type FarmRoutePropsDefault = never;
44
+
45
+ type FarmRoutePropsTarget = AppRoutePattern;
46
+
47
+ type StripPageRouteSuffix<TRoute extends string> = TRoute extends `${infer TPath}?${string}`
48
+ ? StripPageRouteSuffix<TPath>
49
+ : TRoute extends `${infer TPath}#${string}`
50
+ ? StripPageRouteSuffix<TPath>
51
+ : TRoute;
52
+
53
+ type SimplifyPageRouteParams<TValue> = { [TKey in keyof TValue]: TValue[TKey] } & {};
54
+
55
+ type PageRouteSegmentParams<TSegment extends string> = TSegment extends `[[...${infer TParam}]]`
56
+ ? { [TKey in TParam]?: string }
57
+ : TSegment extends `[...${infer TParam}]`
58
+ ? { [TKey in TParam]: string }
59
+ : TSegment extends `[${infer TParam}]`
60
+ ? { [TKey in TParam]: string }
61
+ : {};
62
+
63
+ type ExtractPageRouteParams<TRoute extends string> =
64
+ TRoute extends `${infer TSegment}/${infer TRest}`
65
+ ? PageRouteSegmentParams<TSegment> & ExtractPageRouteParams<TRest>
66
+ : PageRouteSegmentParams<TRoute>;
67
+
68
+ export type PageRouteParams<TRoute extends string> = string extends TRoute
69
+ ? Record<string, string>
70
+ : TRoute extends string
71
+ ? SimplifyPageRouteParams<ExtractPageRouteParams<StripPageRouteSuffix<TRoute>>>
72
+ : never;
73
+
74
+ type ResolvePageRouteParams<TRoute extends FarmRoutePropsTarget> = [TRoute] extends [never]
75
+ ? Record<string, string>
76
+ : TRoute extends string
77
+ ? PageRouteParams<TRoute>
78
+ : Record<string, string>;
79
+
80
+ export interface PageProps<TRoute extends FarmRoutePropsTarget = FarmRoutePropsDefault> {
81
+ params: ResolvePageRouteParams<TRoute>;
32
82
  searchParams: Promise<Record<string, string | string[] | undefined>>;
33
83
  path: string;
34
84
  middleware?: MiddlewareProps;
35
85
  context?: PluginContextProps;
36
86
  }
37
87
 
38
- export interface LayoutProps {
88
+ export interface LoadingProps<TRoute extends FarmRoutePropsTarget = FarmRoutePropsDefault> {
89
+ params: ResolvePageRouteParams<TRoute>;
90
+ searchParams: Promise<Record<string, string | string[] | undefined>>;
91
+ search?: Record<string, string | string[] | undefined>;
92
+ path: string;
93
+ middleware?: MiddlewareProps;
94
+ context?: PluginContextProps;
95
+ }
96
+
97
+ export interface ErrorProps<
98
+ TRoute extends FarmRoutePropsTarget = FarmRoutePropsDefault,
99
+ > extends LoadingProps<TRoute> {
100
+ error: unknown;
101
+ reset: () => void;
102
+ }
103
+
104
+ export interface LayoutProps<TRoute extends FarmRoutePropsTarget = FarmRoutePropsDefault> {
39
105
  children: ReactNode;
40
- params: Record<string, string>;
106
+ params: ResolvePageRouteParams<TRoute>;
107
+ }
108
+
109
+ export type MetadataProps<TRoute extends FarmRoutePropsTarget = FarmRoutePropsDefault> =
110
+ PageProps<TRoute>;
111
+
112
+ export interface LayoutMetadataProps<
113
+ TRoute extends FarmRoutePropsTarget = FarmRoutePropsDefault,
114
+ > {
115
+ params: ResolvePageRouteParams<TRoute>;
41
116
  }
42
117
 
118
+ export type StaticPathPrimitive = string | number | boolean;
119
+ export type StaticPathParams = Record<
120
+ string,
121
+ StaticPathPrimitive | readonly StaticPathPrimitive[]
122
+ >;
123
+
124
+ type StaticRouteSegmentParams<TSegment extends string> = TSegment extends `[[...${infer TParam}]]`
125
+ ? { [TKey in TParam]?: readonly StaticPathPrimitive[] }
126
+ : TSegment extends `[...${infer TParam}]`
127
+ ? { [TKey in TParam]: readonly StaticPathPrimitive[] }
128
+ : TSegment extends `[${infer TParam}]`
129
+ ? { [TKey in TParam]: StaticPathPrimitive }
130
+ : {};
131
+
132
+ type ExtractStaticRouteParams<TRoute extends string> =
133
+ TRoute extends `${infer TSegment}/${infer TRest}`
134
+ ? StaticRouteSegmentParams<TSegment> & ExtractStaticRouteParams<TRest>
135
+ : StaticRouteSegmentParams<TRoute>;
136
+
137
+ export type StaticRouteParams<TRoute extends string> = string extends TRoute
138
+ ? StaticPathParams
139
+ : TRoute extends string
140
+ ? SimplifyPageRouteParams<ExtractStaticRouteParams<StripPageRouteSuffix<TRoute>>>
141
+ : never;
142
+
143
+ type ResolveStaticRouteParams<TRoute extends FarmRoutePropsTarget> = [TRoute] extends [never]
144
+ ? StaticPathParams
145
+ : TRoute extends string
146
+ ? StaticRouteParams<TRoute>
147
+ : StaticPathParams;
148
+
149
+ export type GenerateStaticParams<TRoute extends FarmRoutePropsTarget = FarmRoutePropsDefault> =
150
+ () =>
151
+ | Array<ResolveStaticRouteParams<TRoute>>
152
+ | Promise<Array<ResolveStaticRouteParams<TRoute>>>;
153
+
43
154
  export interface Metadata {
44
155
  title?: string | { default?: string; template?: string };
45
156
  description?: string;