dinou 9.3.0 → 10.0.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/CHANGELOG.md +196 -0
- package/README.md +157 -132
- package/dinou/adapters/bun.js +34 -5
- package/dinou/adapters/cloudflare.js +110 -17
- package/dinou/adapters/deno.js +46 -8
- package/dinou/adapters/netlify.js +86 -50
- package/dinou/adapters/node.js +8 -0
- package/dinou/assets.d.ts +32 -5
- package/dinou/bun/build.js +190 -106
- package/dinou/cli.js +992 -532
- package/dinou/cloudflare/build.js +187 -106
- package/dinou/compiled/autoprefixer/index.js +509 -517
- package/dinou/compiled/babel-core/index.js +738 -716
- package/dinou/compiled/babel-generator/index.js +341 -299
- package/dinou/compiled/babel-loader/index.js +766 -744
- package/dinou/compiled/babel-parser/index.js +2 -2
- package/dinou/compiled/babel-plugin-react-compiler/index.js +178 -178
- package/dinou/compiled/babel-plugin-syntax-import-meta/index.js +4 -4
- package/dinou/compiled/babel-preset-react/index.js +752 -730
- package/dinou/compiled/babel-preset-typescript/index.js +738 -716
- package/dinou/compiled/babel-traverse/index.js +463 -433
- package/dinou/compiled/babel-types/index.js +176 -176
- package/dinou/compiled/chokidar/index.js +4 -4
- package/dinou/compiled/commander/index.js +15 -15
- package/dinou/compiled/copy-webpack-plugin/index.js +433 -425
- package/dinou/compiled/css-loader/index.js +289 -289
- package/dinou/compiled/css-loader/runtime/api.js +85 -0
- package/dinou/compiled/css-loader/runtime/getUrl.js +26 -0
- package/dinou/compiled/css-loader/runtime/noSourceMaps.js +5 -0
- package/dinou/compiled/css-loader/runtime/package.json +3 -0
- package/dinou/compiled/css-loader/runtime/sourceMaps.js +16 -0
- package/dinou/compiled/fast-glob/index.js +5810 -0
- package/dinou/compiled/generic-names/index.js +16 -16
- package/dinou/compiled/mini-css-extract-plugin/{chunk-YYEJWYXE.js → chunk-R6DP5ZYM.js} +36 -36
- package/dinou/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +253 -0
- package/dinou/compiled/mini-css-extract-plugin/hmr/normalize-url.js +39 -0
- package/dinou/compiled/mini-css-extract-plugin/hmr/package.json +3 -0
- package/dinou/compiled/mini-css-extract-plugin/index.js +1 -1
- package/dinou/compiled/mini-css-extract-plugin/loader.js +5 -5
- package/dinou/compiled/postcss/index.js +83 -83
- package/dinou/compiled/postcss-import/index.js +147 -117
- package/dinou/compiled/postcss-modules/index.js +216 -216
- package/dinou/compiled/resolve/index.js +1224 -0
- package/dinou/compiled/rollup-plugin-babel/index.js +753 -731
- package/dinou/compiled/rollup-plugin-commonjs/index.js +43 -38
- package/dinou/compiled/rollup-plugin-delete/index.js +615 -253
- package/dinou/compiled/rollup-plugin-json/index.js +22 -18
- package/dinou/compiled/rollup-plugin-node-resolve/index.js +130 -100
- package/dinou/compiled/rollup-plugin-postcss/index.js +3299 -3277
- package/dinou/compiled/rollup-plugin-replace/index.js +34 -29
- package/dinou/compiled/tailwindcss-postcss/index.js +214 -211
- package/dinou/compiled/vendors-manifest.json +59 -83
- package/dinou/core/asset-extensions.js +482 -33
- package/dinou/core/bailout-proxy.js +21 -2
- package/dinou/core/build-static-pages.js +523 -371
- package/dinou/core/builtin-asset-extensions.js +63 -0
- package/dinou/core/cache-revalidate.js +449 -256
- package/dinou/core/cache-slot.js +289 -79
- package/dinou/core/client-webpack.jsx +470 -39
- package/dinou/core/client.jsx +402 -39
- package/dinou/core/config.js +3 -0
- package/dinou/core/copy-static-dirs.js +98 -0
- package/dinou/core/createScopedName.js +22 -4
- package/dinou/core/dinou-paths.js +1 -1
- package/dinou/core/discover-layouts.js +200 -0
- package/dinou/core/edge-ssr.js +1 -1
- package/dinou/core/ensure-vendor-mode.js +78 -19
- package/dinou/core/env.js +544 -0
- package/dinou/core/export-static.js +41 -9
- package/dinou/core/generate-route-types.js +989 -95
- package/dinou/core/generate-static-rsc.js +5 -6
- package/dinou/core/generate-static.js +45 -6
- package/dinou/core/get-abs-path-with-ext.js +217 -75
- package/dinou/core/get-asset-from-manifest.js +19 -8
- package/dinou/core/get-error-jsx.js +4 -5
- package/dinou/core/get-file-path-and-dynamic-params.js +561 -338
- package/dinou/core/get-jsx.js +220 -53
- package/dinou/core/handler.js +1647 -466
- package/dinou/core/import-module.js +7 -0
- package/dinou/core/layout-functions.js +72 -13
- package/dinou/core/link.jsx +34 -6
- package/dinou/core/load-dinou-config.js +520 -89
- package/dinou/core/manifest-provider.js +4 -14
- package/dinou/core/navigation-utils.js +141 -3
- package/dinou/core/navigation.js +134 -50
- package/dinou/core/node-middleware-runner.js +165 -0
- package/dinou/core/postcss-pipeline.js +236 -0
- package/dinou/core/ppr-context.js +114 -22
- package/dinou/core/ppr-runtime.js +391 -127
- package/dinou/core/redirect.jsx +1 -1
- package/dinou/core/render-jsx-to-client-jsx.js +216 -48
- package/dinou/core/request-context.js +59 -3
- package/dinou/core/resolve-contextual-dinou.js +523 -0
- package/dinou/core/resolve-setup-files.js +85 -27
- package/dinou/core/revalidating.js +10 -2
- package/dinou/core/route-generator.js +6 -2
- package/dinou/core/rsc-renderer.js +4 -1
- package/dinou/core/run-ssg.js +6 -0
- package/dinou/core/runtime-env.js +265 -0
- package/dinou/core/server-css-modules-plugin.js +155 -0
- package/dinou/core/server-function-proxy-webpack.js +27 -2
- package/dinou/core/server-function-proxy.js +27 -2
- package/dinou/core/slot.js +47 -2
- package/dinou/core/static-assets.js +503 -0
- package/dinou/core/storage-adapter.js +452 -24
- package/dinou/core/transform-server-functions.js +272 -24
- package/dinou/core/tsconfig-aliases.js +964 -0
- package/dinou/core/uneject.js +640 -0
- package/dinou/core/url-resolver.js +1 -1
- package/dinou/core/vfs.js +11 -2
- package/dinou/css.d.ts +4 -1
- package/dinou/deno/build.js +205 -153
- package/dinou/deno/seed-kv.js +4 -0
- package/dinou/env.d.ts +22 -2
- package/dinou/esbuild/build.js +40 -50
- package/dinou/esbuild/dev.js +33 -7
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild-prod.js +41 -16
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild.js +51 -49
- package/dinou/esbuild/helpers-esbuild/get-esbuild-entries.js +73 -60
- package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +35 -16
- package/dinou/esbuild/helpers-esbuild/write.js +13 -3
- package/dinou/esbuild/plugins-esbuild/assets-plugin.js +100 -238
- package/dinou/esbuild/plugins-esbuild/babel-react-compiler-plugin.js +73 -29
- package/dinou/esbuild/plugins-esbuild/css-processor-plugin.js +283 -91
- package/dinou/esbuild/plugins-esbuild/manifest-generator-plugin.js +3 -5
- package/dinou/esbuild/plugins-esbuild/react-client-manifest-plugin.js +9 -3
- package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +4 -3
- package/dinou/esbuild/plugins-esbuild/stable-chunk-names-and-maps-plugin.js +10 -1
- package/dinou/esbuild/plugins-postcss/postcss-extract-plugin.js +84 -21
- package/dinou/esbuild/react-refresh/esm-hmr/client.js +31 -10
- package/dinou/esbuild/react-refresh/esm-hmr-plugin.js +48 -18
- package/dinou/esbuild/react-refresh/is-react-refresh-boundary.js +9 -1
- package/dinou/esbuild/react-refresh/react-refresh-runtime.js +13 -7
- package/dinou/index.d.ts +1028 -88
- package/dinou/node/build.js +138 -74
- package/dinou/node/bundle-dual-engine.js +393 -131
- package/dinou/node/dev.js +1005 -275
- package/dinou/package.json +11 -34
- package/dinou/rollup/postcss.config.js +3 -4
- package/dinou/rollup/react-refresh/esm-hmr/client.js +31 -10
- package/dinou/rollup/react-refresh/react-refresh-wrap-modules.js +16 -13
- package/dinou/rollup/react-refresh/rollup-plugin-esm-hmr.js +53 -7
- package/dinou/rollup/rollup-plugins/dinou-asset-plugin.js +58 -20
- package/dinou/rollup/rollup-plugins/manifest-generator-plugin.js +16 -7
- package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +118 -42
- package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +48 -36
- package/dinou/rollup/rollup.config.js +174 -101
- package/dinou/scripts/build-vendors.js +123 -33
- package/dinou/server.d.ts +126 -15
- package/dinou/webpack/helpers/get-webpack-entries.js +87 -41
- package/dinou/webpack/helpers/patch-webpack-internals.js +93 -1
- package/dinou/webpack/loaders/server-functions-loader.js +1 -1
- package/dinou/webpack/plugins/manifest-generator-plugin.js +27 -7
- package/dinou/webpack/plugins/server-functions-plugin.js +39 -12
- package/dinou/webpack/plugins/webpack-memory-plugin.js +25 -12
- package/dinou/webpack/postcss.config.js +3 -4
- package/dinou/webpack/webpack.config.js +408 -132
- package/eject.js +6 -224
- package/package.json +7 -9
- package/dinou/compiled/cross-env/index.js +0 -661
- package/dinou/compiled/dotenv/index.js +0 -375
- package/dinou/compiled/esbuild-copy-static-files/index.js +0 -63
- package/dinou/compiled/esbuild-tsconfig-paths/index.js +0 -1314
- package/dinou/compiled/rollup-plugin-copy/index.js +0 -12066
- package/dinou/compiled/rollup-plugin-tsconfig-paths/index.js +0 -569
- package/dinou/compiled/tsconfig-paths-webpack-plugin/index.js +0 -3956
package/dinou/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// dinou/index.d.ts
|
|
2
2
|
import { IncomingHttpHeaders } from "http";
|
|
3
|
+
import type { StorageAdapter } from "./server.js";
|
|
3
4
|
|
|
4
5
|
// ====================================================================
|
|
5
6
|
// REQUEST PROPERTIES TYPES (REQ)
|
|
@@ -76,6 +77,13 @@ export interface ResponseProxy {
|
|
|
76
77
|
// MAIN CONTEXT STORE INTERFACE
|
|
77
78
|
// ====================================================================
|
|
78
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Augmentable server environment interface returned by `getContext().env`.
|
|
82
|
+
* Exposes standard text secrets (`process.env`, `Deno.env`) as well as live
|
|
83
|
+
* Edge/Cloudflare resource bindings (KV, D1, R2, Durable Objects, etc.).
|
|
84
|
+
*/
|
|
85
|
+
export interface DinouEnv extends Record<string, any> {}
|
|
86
|
+
|
|
79
87
|
/**
|
|
80
88
|
* The complete context object stored in AsyncLocalStorage.
|
|
81
89
|
*/
|
|
@@ -87,9 +95,14 @@ export interface RequestContextStore {
|
|
|
87
95
|
query: Query;
|
|
88
96
|
cookies: Cookies;
|
|
89
97
|
headers: Headers;
|
|
98
|
+
/** Normalized logical route pathname (e.g. `"/dashboard"` even on internal `/____rsc_*` SPA fetches). */
|
|
90
99
|
path: string;
|
|
100
|
+
/** Raw wire HTTP URL pathname before RSC prefix normalization (e.g. `"/____rsc_page____/dashboard"`). */
|
|
101
|
+
rawPath?: string;
|
|
102
|
+
/** Whether the current HTTP request is an internal React Server Components wire fetch (`/____rsc_*`). */
|
|
103
|
+
isRscRequest?: boolean;
|
|
91
104
|
method: "GET" | "POST" | string;
|
|
92
|
-
env
|
|
105
|
+
env: DinouEnv;
|
|
93
106
|
ctx?: any;
|
|
94
107
|
[key: string]: any;
|
|
95
108
|
};
|
|
@@ -101,12 +114,12 @@ export interface RequestContextStore {
|
|
|
101
114
|
res: ResponseProxy;
|
|
102
115
|
|
|
103
116
|
/**
|
|
104
|
-
*
|
|
117
|
+
* Unified server & platform host environment (text variables + Cloudflare KV, D1, R2 bindings).
|
|
105
118
|
*/
|
|
106
|
-
env
|
|
119
|
+
env: DinouEnv;
|
|
107
120
|
|
|
108
121
|
/**
|
|
109
|
-
* Platform execution context (Cloudflare ctx, waitUntil, etc.).
|
|
122
|
+
* Platform execution context (Cloudflare ctx, waitUntil, Netlify context, etc.).
|
|
110
123
|
*/
|
|
111
124
|
ctx?: any;
|
|
112
125
|
|
|
@@ -123,7 +136,7 @@ export interface RequestContextStore {
|
|
|
123
136
|
export type NodeMiddleware = (
|
|
124
137
|
req: import("node:http").IncomingMessage,
|
|
125
138
|
res: import("node:http").ServerResponse,
|
|
126
|
-
next: () => void
|
|
139
|
+
next: (err?: any) => void
|
|
127
140
|
) => void | Promise<void>;
|
|
128
141
|
|
|
129
142
|
export interface ServerHookContext {
|
|
@@ -168,6 +181,14 @@ export interface DinouPlugin {
|
|
|
168
181
|
}
|
|
169
182
|
|
|
170
183
|
export interface DinouConfig {
|
|
184
|
+
/**
|
|
185
|
+
* Enable or disable the React Compiler (`babel-plugin-react-compiler`) during production builds.
|
|
186
|
+
* Applies across all supported bundlers (Esbuild, Rollup, and Webpack).
|
|
187
|
+
* Individual components or hooks can also opt out locally with the `"use no memo"` directive.
|
|
188
|
+
* @default true
|
|
189
|
+
*/
|
|
190
|
+
reactCompiler?: boolean;
|
|
191
|
+
|
|
171
192
|
/**
|
|
172
193
|
* Enable or disable React StrictMode in development mode.
|
|
173
194
|
* When enabled, React double-invokes render and effect functions in development to catch side-effects.
|
|
@@ -183,10 +204,17 @@ export interface DinouConfig {
|
|
|
183
204
|
*/
|
|
184
205
|
ppr?: boolean;
|
|
185
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Global default for Incremental Static Generation (allowISG) on dynamic segments.
|
|
209
|
+
* Can be overridden per segment in page_functions.ts or layout_functions.ts.
|
|
210
|
+
* @default true
|
|
211
|
+
*/
|
|
212
|
+
allowISG?: boolean;
|
|
213
|
+
|
|
186
214
|
/**
|
|
187
215
|
* Custom storage adapter for ISR / ISG page caching.
|
|
188
216
|
*/
|
|
189
|
-
storage?:
|
|
217
|
+
storage?: StorageAdapter;
|
|
190
218
|
|
|
191
219
|
/**
|
|
192
220
|
* Array of setup/polyfill file paths to be executed at the earliest stage
|
|
@@ -195,6 +223,14 @@ export interface DinouConfig {
|
|
|
195
223
|
*/
|
|
196
224
|
setupFiles?: string[];
|
|
197
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Additional file extensions (with or without leading dot, e.g. `["glb", "gltf", "hdr", "wasm"]`)
|
|
228
|
+
* recognized as static media/binary assets when imported in Server Components, Client Components, or CSS `url(...)`.
|
|
229
|
+
* Automatically fingerprinted into `/assets/[name]-[hash].[ext]` across Esbuild, Rollup, Webpack, and all runtimes,
|
|
230
|
+
* with ambient TypeScript declarations emitted into `.dinou/types/routes.d.ts`.
|
|
231
|
+
*/
|
|
232
|
+
assetExtensions?: string[];
|
|
233
|
+
|
|
198
234
|
/**
|
|
199
235
|
* Array of Dinou plugins.
|
|
200
236
|
*/
|
|
@@ -208,19 +244,43 @@ export interface DinouConfig {
|
|
|
208
244
|
*/
|
|
209
245
|
export type PPRConfig = boolean | (() => boolean | Promise<boolean>);
|
|
210
246
|
|
|
247
|
+
export type AllowUndefinedStaticPath<TParams> =
|
|
248
|
+
0 extends 1 & TParams
|
|
249
|
+
? undefined
|
|
250
|
+
: [TParams[keyof TParams]] extends [never]
|
|
251
|
+
? never
|
|
252
|
+
: {} extends TParams
|
|
253
|
+
? undefined
|
|
254
|
+
: never;
|
|
255
|
+
|
|
256
|
+
export type ToStaticPathParamValue<V> =
|
|
257
|
+
[V] extends [never]
|
|
258
|
+
? never
|
|
259
|
+
: [Exclude<V, undefined>] extends [ReadonlyArray<string>]
|
|
260
|
+
? string[] | Extract<V, undefined>
|
|
261
|
+
: [Exclude<V, undefined>] extends [string]
|
|
262
|
+
? string | number | Extract<V, undefined>
|
|
263
|
+
: V;
|
|
264
|
+
|
|
265
|
+
export type ToStaticPathParams<P> = {
|
|
266
|
+
[K in keyof P]: ToStaticPathParamValue<P[K]>;
|
|
267
|
+
};
|
|
268
|
+
|
|
211
269
|
/**
|
|
212
270
|
* A single static path item returned or defined by `getStaticPaths`.
|
|
213
271
|
* Can be:
|
|
214
272
|
* - A string: e.g. `"alpha"` for dynamic segment `[slug]`
|
|
215
273
|
* - A number: e.g. `1` for dynamic segment `[id]`
|
|
216
|
-
* - A string array: e.g. `["docs", "getting-started"]` for catch-all segment `[...slug]`
|
|
217
|
-
* -
|
|
274
|
+
* - A string array: e.g. `["docs", "getting-started"]` for catch-all segment `[...slug]` or `[]` for `[[...slug]]`
|
|
275
|
+
* - `undefined`: when all dynamic segments in the route are optional (e.g. `[[category]]` or `[[...slug]]`)
|
|
276
|
+
* - A parameter object: e.g. `{ slug: "alpha", id: 1 }`
|
|
218
277
|
*/
|
|
219
278
|
export type StaticPathItem<TParams = Record<string, string | number | string[] | undefined>> =
|
|
220
279
|
| string
|
|
221
280
|
| number
|
|
222
281
|
| string[]
|
|
223
|
-
| TParams
|
|
282
|
+
| TParams
|
|
283
|
+
| AllowUndefinedStaticPath<TParams>;
|
|
224
284
|
|
|
225
285
|
/**
|
|
226
286
|
* Result array or promise of array for `getStaticPaths`.
|
|
@@ -229,7 +289,11 @@ export type StaticPathsResult<TParams = Record<string, string | number | string[
|
|
|
229
289
|
| StaticPathItem<TParams>[]
|
|
230
290
|
| Promise<StaticPathItem<TParams>[]>;
|
|
231
291
|
|
|
232
|
-
export interface RouteSegmentConfig<
|
|
292
|
+
export interface RouteSegmentConfig<
|
|
293
|
+
TParams = any,
|
|
294
|
+
TProps = any,
|
|
295
|
+
TStaticPathParams = TParams
|
|
296
|
+
> {
|
|
233
297
|
/**
|
|
234
298
|
* Partial Prerendering (PPR) flag.
|
|
235
299
|
* Can be declared as a constant or a function (sync or async) in page_functions or layout_functions.
|
|
@@ -259,13 +323,14 @@ export interface RouteSegmentConfig<TParams = any, TProps = any> {
|
|
|
259
323
|
* - Array of strings (e.g. `["alpha", "beta"]`)
|
|
260
324
|
* - Array of numbers (e.g. `[1, 2, 3]`)
|
|
261
325
|
* - Array of string arrays for catch-all routes (e.g. `[["docs", "intro"], ["docs", "setup"]]`)
|
|
326
|
+
* - `undefined` entries when all dynamic segments are optional (e.g. `[undefined, "electronics"]`)
|
|
262
327
|
* - Array of parameter objects (e.g. `[{ slug: "alpha" }, { slug: "beta" }]`)
|
|
263
328
|
*
|
|
264
329
|
* Can be declared as a sync or async function, or as a constant array in `page_functions.ts` or `layout_functions.ts`.
|
|
265
330
|
*/
|
|
266
331
|
getStaticPaths?:
|
|
267
|
-
| StaticPathItem<
|
|
268
|
-
| (() => StaticPathsResult<
|
|
332
|
+
| StaticPathItem<TStaticPathParams>[]
|
|
333
|
+
| (() => StaticPathsResult<TStaticPathParams>);
|
|
269
334
|
|
|
270
335
|
/**
|
|
271
336
|
* Server-side loader that fetches or calculates props passed directly to the Page or Layout component.
|
|
@@ -292,24 +357,43 @@ export type PageFunctions<
|
|
|
292
357
|
TRouteOrParams extends DinouRoutePattern | object = any,
|
|
293
358
|
TProps = any
|
|
294
359
|
> = RouteSegmentConfig<
|
|
295
|
-
|
|
296
|
-
|
|
360
|
+
0 extends 1 & TRouteOrParams
|
|
361
|
+
? any
|
|
362
|
+
: [TRouteOrParams] extends [DinouRoutePattern]
|
|
363
|
+
? RouteParams<Extract<TRouteOrParams, DinouRoutePattern>>
|
|
364
|
+
: TRouteOrParams,
|
|
365
|
+
TProps,
|
|
366
|
+
0 extends 1 & TRouteOrParams
|
|
367
|
+
? any
|
|
368
|
+
: [TRouteOrParams] extends [DinouRoutePattern]
|
|
369
|
+
? StaticPathParams<Extract<TRouteOrParams, DinouRoutePattern>>
|
|
370
|
+
: ToStaticPathParams<TRouteOrParams>
|
|
297
371
|
>;
|
|
298
372
|
|
|
299
373
|
/**
|
|
300
374
|
* Type-safe interface representing the available exports in `layout_functions.ts`.
|
|
301
|
-
* Accepts either a
|
|
375
|
+
* Accepts either a layout segment pattern string (e.g. `"/[organization]"`, including intermediate layouts without a sibling `page.tsx`)
|
|
376
|
+
* or a direct parameters dictionary.
|
|
302
377
|
*/
|
|
303
378
|
export type LayoutFunctions<
|
|
304
|
-
TRouteOrParams extends
|
|
379
|
+
TRouteOrParams extends DinouLayoutPattern | object = any,
|
|
305
380
|
TProps = any
|
|
306
381
|
> = RouteSegmentConfig<
|
|
307
|
-
|
|
308
|
-
|
|
382
|
+
0 extends 1 & TRouteOrParams
|
|
383
|
+
? any
|
|
384
|
+
: [TRouteOrParams] extends [DinouLayoutPattern]
|
|
385
|
+
? LayoutParams<Extract<TRouteOrParams, DinouLayoutPattern>>
|
|
386
|
+
: TRouteOrParams,
|
|
387
|
+
TProps,
|
|
388
|
+
0 extends 1 & TRouteOrParams
|
|
389
|
+
? any
|
|
390
|
+
: [TRouteOrParams] extends [DinouLayoutPattern]
|
|
391
|
+
? StaticPathParams<Extract<TRouteOrParams, DinouLayoutPattern>>
|
|
392
|
+
: ToStaticPathParams<TRouteOrParams>
|
|
309
393
|
>;
|
|
310
394
|
|
|
311
395
|
/**
|
|
312
|
-
* Type-safe configuration helper for dinou.config.js / dinou.config.mjs.
|
|
396
|
+
* Type-safe configuration helper for dinou.config.ts / dinou.config.js / dinou.config.mjs.
|
|
313
397
|
*/
|
|
314
398
|
export declare function defineConfig(config: DinouConfig): DinouConfig;
|
|
315
399
|
|
|
@@ -318,14 +402,14 @@ export declare function defineConfig(config: DinouConfig): DinouConfig;
|
|
|
318
402
|
// ====================================================================
|
|
319
403
|
|
|
320
404
|
/**
|
|
321
|
-
* Gets the current request context (req
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
* @returns {RequestContextStore
|
|
405
|
+
* Gets the current server request context (`req`, `res`, `env`, `ctx`) synchronously.
|
|
406
|
+
* Safe to call inside Server Components, `page_functions.ts` / `layout_functions.ts`
|
|
407
|
+
* (`getProps`, `getStaticPaths`, `validateParams`, `getCacheTags`), `plugin.onRequest`,
|
|
408
|
+
* and `"use server"` Server Functions across Node.js, Bun, Deno, and Cloudflare Workers.
|
|
409
|
+
*
|
|
410
|
+
* @returns {RequestContextStore} The active request context (or a server fallback context with `env` populated outside an HTTP request).
|
|
327
411
|
*/
|
|
328
|
-
export declare function getContext(): RequestContextStore
|
|
412
|
+
export declare function getContext(): RequestContextStore;
|
|
329
413
|
|
|
330
414
|
/**
|
|
331
415
|
* Opts the enclosing `<Suspense>` boundary out of becoming a Dynamic PPR Hole
|
|
@@ -361,7 +445,7 @@ export declare function ClientRedirect(props: ClientRedirectProps): ReactNode;
|
|
|
361
445
|
/**
|
|
362
446
|
* Universal redirect function for Server Components and Server Functions.
|
|
363
447
|
* * It handles the logic intelligently based on the context:
|
|
364
|
-
* 1. **Server-Side (Hard Navigation):** If headers haven't been sent, it performs a real HTTP
|
|
448
|
+
* 1. **Server-Side (Hard Navigation):** If headers haven't been sent, it performs a real HTTP 302 redirect (better for SEO and performance).
|
|
365
449
|
* 2. **Client-Side / Streaming (Soft Navigation):** If the response stream has started or we are on the client, it returns a component that triggers a SPA navigation.
|
|
366
450
|
* * @param destination - The path URL to redirect to (e.g., "/login").
|
|
367
451
|
* @returns A React Node that handles the redirection.
|
|
@@ -437,7 +521,7 @@ export interface NavigationOptions {
|
|
|
437
521
|
* router.refresh();
|
|
438
522
|
*/
|
|
439
523
|
// ====================================================================
|
|
440
|
-
// TYPE-SAFE ROUTING (Level 1 & Level 2)
|
|
524
|
+
// TYPE-SAFE ROUTING (Level 1 & Level 2 — Hierarchical & Horizontal)
|
|
441
525
|
// ====================================================================
|
|
442
526
|
|
|
443
527
|
export namespace DinouRouter {
|
|
@@ -447,7 +531,7 @@ export namespace DinouRouter {
|
|
|
447
531
|
}
|
|
448
532
|
|
|
449
533
|
/**
|
|
450
|
-
* Union of all valid routes in the application.
|
|
534
|
+
* Union of all valid navigable routes in the application (`page.*`).
|
|
451
535
|
* When typed routes are generated, autocompletes known routes.
|
|
452
536
|
* Falls back to string if not yet generated or in loose mode.
|
|
453
537
|
*/
|
|
@@ -456,15 +540,15 @@ export type DinouRoute = DinouRouter.Register extends { route: infer R extends s
|
|
|
456
540
|
: string;
|
|
457
541
|
|
|
458
542
|
/**
|
|
459
|
-
* Utility types to parse dynamic route parameters from a route string pattern.
|
|
543
|
+
* Utility types to parse received runtime dynamic route parameters from a route string pattern.
|
|
460
544
|
* e.g. ExtractRouteParams<"/blog/[id]"> => { id: string }
|
|
461
545
|
* e.g. ExtractRouteParams<"/docs/[...slug]"> => { slug: string[] }
|
|
462
|
-
* e.g. ExtractRouteParams<"/shop/[[...slug]]"> => { slug
|
|
546
|
+
* e.g. ExtractRouteParams<"/shop/[[...slug]]"> => { slug: string[] } (normalized to [] at runtime on root path)
|
|
463
547
|
* e.g. ExtractRouteParams<"/item/[[code]]"> => { code?: string }
|
|
464
548
|
*/
|
|
465
549
|
export type ExtractSegmentParam<Segment extends string> =
|
|
466
550
|
Segment extends `[[...${infer Param}]]`
|
|
467
|
-
? { [K in Param]
|
|
551
|
+
? { [K in Param]: string[] }
|
|
468
552
|
: Segment extends `[[${infer Param}]]`
|
|
469
553
|
? { [K in Param]?: string }
|
|
470
554
|
: Segment extends `[...${infer Param}]`
|
|
@@ -481,79 +565,899 @@ export type ExtractRouteParams<Path extends string> =
|
|
|
481
565
|
: ExtractSegmentParam<Path>;
|
|
482
566
|
|
|
483
567
|
/**
|
|
484
|
-
*
|
|
485
|
-
*
|
|
568
|
+
* Utility types to parse input route parameters (for `<Link params>`, `router.push`, and `getStaticPaths`),
|
|
569
|
+
* where optional catch-all segments `[[...slug]]` remain optional (`{ slug?: string[] }`).
|
|
570
|
+
*/
|
|
571
|
+
export type ExtractNavigableSegmentParam<Segment extends string> =
|
|
572
|
+
Segment extends `[[...${infer Param}]]`
|
|
573
|
+
? { [K in Param]?: string[] }
|
|
574
|
+
: Segment extends `[[${infer Param}]]`
|
|
575
|
+
? { [K in Param]?: string }
|
|
576
|
+
: Segment extends `[...${infer Param}]`
|
|
577
|
+
? { [K in Param]: string[] }
|
|
578
|
+
: Segment extends `[${infer Param}]`
|
|
579
|
+
? { [K in Param]: string }
|
|
580
|
+
: {};
|
|
581
|
+
|
|
582
|
+
export type ExtractNavigableRouteParams<Path extends string> =
|
|
583
|
+
Path extends `/${infer Rest}`
|
|
584
|
+
? ExtractNavigableRouteParams<Rest>
|
|
585
|
+
: Path extends `${infer Start}/${infer Rest}`
|
|
586
|
+
? ExtractNavigableSegmentParam<Start> & ExtractNavigableRouteParams<Rest>
|
|
587
|
+
: ExtractNavigableSegmentParam<Path>;
|
|
588
|
+
|
|
589
|
+
export type SimplifyParams<T> = { [K in keyof T]: T[K] };
|
|
590
|
+
|
|
591
|
+
export type FallbackRouteParams<Path extends string> =
|
|
592
|
+
[string] extends [Path]
|
|
593
|
+
? Record<string, string | string[] | undefined>
|
|
594
|
+
: [`/@${string}`] extends [Path]
|
|
595
|
+
? Record<string, string | string[] | undefined>
|
|
596
|
+
: keyof ExtractRouteParams<Path> extends never
|
|
597
|
+
? Record<string, never>
|
|
598
|
+
: SimplifyParams<ExtractRouteParams<Path>>;
|
|
599
|
+
|
|
600
|
+
export type FallbackNavigableParams<Path extends string> =
|
|
601
|
+
[string] extends [Path]
|
|
602
|
+
? Record<string, string | string[] | undefined>
|
|
603
|
+
: [`/@${string}`] extends [Path]
|
|
604
|
+
? Record<string, string | string[] | undefined>
|
|
605
|
+
: keyof ExtractNavigableRouteParams<Path> extends never
|
|
606
|
+
? Record<string, never>
|
|
607
|
+
: SimplifyParams<ExtractNavigableRouteParams<Path>>;
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Resolved parameter dictionary accepted by `getStaticPaths` object items for a segment pattern `Path`.
|
|
611
|
+
* Keeps optional catch-all segments (`[[...slug]]`) optional and allows `string | number` for single segments.
|
|
612
|
+
*/
|
|
613
|
+
export type StaticPathParams<Path extends string> =
|
|
614
|
+
[string] extends [Path]
|
|
615
|
+
? Record<string, string | number | string[] | undefined>
|
|
616
|
+
: [`/@${string}`] extends [Path]
|
|
617
|
+
? Record<string, string | number | string[] | undefined>
|
|
618
|
+
: Path extends string
|
|
619
|
+
? DinouRouter.Register extends { navigableParams: infer NP }
|
|
620
|
+
? CleanRoutePath<Path> extends keyof NP
|
|
621
|
+
? SimplifyParams<ToStaticPathParams<NP[CleanRoutePath<Path>]>>
|
|
622
|
+
: SimplifyParams<ToStaticPathParams<FallbackNavigableParams<CleanRoutePath<Path>>>>
|
|
623
|
+
: SimplifyParams<ToStaticPathParams<FallbackNavigableParams<CleanRoutePath<Path>>>>
|
|
624
|
+
: never;
|
|
625
|
+
|
|
626
|
+
export type FormatPatternKeys<K extends string> =
|
|
627
|
+
[K] extends [never]
|
|
628
|
+
? string
|
|
629
|
+
: K | (K extends `/${infer Rest}` ? (Rest extends "" ? never : Rest) : never);
|
|
630
|
+
|
|
631
|
+
export type FormatOptionalPatternKeys<K extends string> =
|
|
632
|
+
[K] extends [never]
|
|
633
|
+
? never
|
|
634
|
+
: K | (K extends `/${infer Rest}` ? (Rest extends "" ? never : Rest) : never);
|
|
635
|
+
|
|
636
|
+
export type IsUnion<T, U = T> = T extends any ? ([U] extends [T] ? false : true) : never;
|
|
637
|
+
|
|
638
|
+
export type CleanRoutePath<T extends string> =
|
|
639
|
+
T extends "" ? "/" : T extends `/${string}` ? T : `/${T}`;
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* All known page route patterns in the application (e.g. "/blog/[slug]", "/t-params/[[slug]]").
|
|
643
|
+
* Autocompletes all project page routes when typing PageProps<"..."> or PageFunctions<"...">.
|
|
486
644
|
*/
|
|
487
645
|
export type DinouRoutePattern = DinouRouter.Register extends { params: infer P }
|
|
488
|
-
?
|
|
646
|
+
? FormatPatternKeys<Extract<keyof P, string>>
|
|
489
647
|
: string;
|
|
490
648
|
|
|
491
|
-
|
|
649
|
+
/**
|
|
650
|
+
* Registered parallel `@slot` patterns when `.dinou/types/routes.d.ts` is present (`never` if the project has no `@slot` folders).
|
|
651
|
+
*/
|
|
652
|
+
export type DinouRegisteredSlotPattern = DinouRouter.Register extends { slotParams: infer SP }
|
|
653
|
+
? FormatOptionalPatternKeys<Extract<keyof SP, string>>
|
|
654
|
+
: DinouRouter.Register extends { params: unknown }
|
|
655
|
+
? never
|
|
656
|
+
: string;
|
|
492
657
|
|
|
493
658
|
/**
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
|
|
659
|
+
* All known parallel `@slot` patterns in the application (e.g. "/dashboard/[org]/@analytics", "/@modal").
|
|
660
|
+
* Autocompletes `@slot` folders when typing SlotProps<"...">.
|
|
661
|
+
*/
|
|
662
|
+
export type DinouSlotPattern = DinouRouter.Register extends { slotParams: infer SP }
|
|
663
|
+
? ([Extract<keyof SP, string>] extends [never]
|
|
664
|
+
? `/@${string}` | `${string}/@${string}`
|
|
665
|
+
: FormatOptionalPatternKeys<Extract<keyof SP, string>>)
|
|
666
|
+
: string;
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* All known layout segment patterns in the application (e.g. "/", "/workspace/[org]"),
|
|
670
|
+
* including intermediate horizontal layouts that have no sibling `page.tsx`.
|
|
497
671
|
*/
|
|
498
|
-
export type
|
|
672
|
+
export type DinouLayoutPattern = DinouRouter.Register extends { layoutParams: infer LP }
|
|
673
|
+
? FormatPatternKeys<Extract<keyof LP, string>>
|
|
674
|
+
: DinouRoutePattern;
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* All known error boundary segment patterns in the application (`error.tsx`),
|
|
678
|
+
* including page routes, intermediate folders, and parallel `@slot` folders.
|
|
679
|
+
*/
|
|
680
|
+
export type DinouErrorPattern = DinouRouter.Register extends { errorParams: infer EP }
|
|
681
|
+
? FormatPatternKeys<Extract<keyof EP, string>>
|
|
682
|
+
: DinouRoutePattern;
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* All known segment patterns valid for `not_found.tsx` boundaries (root, page routes,
|
|
686
|
+
* intermediate `not_found.tsx` folders, and intermediate layout folders), excluding `@slot` folders.
|
|
687
|
+
*/
|
|
688
|
+
export type DinouNotFoundPattern = DinouRouter.Register extends { params: infer P }
|
|
689
|
+
? FormatPatternKeys<
|
|
690
|
+
| Extract<keyof P, string>
|
|
691
|
+
| (DinouRouter.Register extends { layoutParams: infer LP }
|
|
692
|
+
? Extract<keyof LP, string>
|
|
693
|
+
: never)
|
|
694
|
+
>
|
|
695
|
+
: string;
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Union of all valid horizontal & hierarchical segment patterns (pages, layouts, parallel `@slots`, and error boundaries).
|
|
699
|
+
*/
|
|
700
|
+
export type DinouSegmentPattern =
|
|
701
|
+
| DinouRoutePattern
|
|
702
|
+
| DinouLayoutPattern
|
|
703
|
+
| DinouRegisteredSlotPattern
|
|
704
|
+
| DinouErrorPattern;
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Internal helper that resolves segment parameter dictionaries across generated maps
|
|
708
|
+
* (`params`, `layoutParams`, `slotParams`, `errorParams`) with template-literal fallback.
|
|
709
|
+
*/
|
|
710
|
+
export type LookupSingleSegmentParams<K extends string> =
|
|
499
711
|
DinouRouter.Register extends { params: infer P }
|
|
500
|
-
?
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
712
|
+
? K extends keyof P
|
|
713
|
+
? P[K]
|
|
714
|
+
: DinouRouter.Register extends { layoutParams: infer LP }
|
|
715
|
+
? K extends keyof LP
|
|
716
|
+
? LP[K]
|
|
717
|
+
: DinouRouter.Register extends { slotParams: infer SP }
|
|
718
|
+
? K extends keyof SP
|
|
719
|
+
? SP[K]
|
|
720
|
+
: DinouRouter.Register extends { errorParams: infer EP }
|
|
721
|
+
? K extends keyof EP
|
|
722
|
+
? EP[K]
|
|
723
|
+
: FallbackRouteParams<K>
|
|
724
|
+
: FallbackRouteParams<K>
|
|
725
|
+
: FallbackRouteParams<K>
|
|
726
|
+
: FallbackRouteParams<K>
|
|
727
|
+
: FallbackRouteParams<K>;
|
|
728
|
+
|
|
729
|
+
export type LookupSegmentParams<T extends string> =
|
|
730
|
+
[string] extends [T]
|
|
731
|
+
? Record<string, string | string[] | undefined>
|
|
732
|
+
: [`/@${string}`] extends [T]
|
|
733
|
+
? Record<string, string | string[] | undefined>
|
|
734
|
+
: T extends string
|
|
735
|
+
? LookupSingleSegmentParams<CleanRoutePath<T>>
|
|
736
|
+
: never;
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Resolved route parameter types for a route, layout, or parallel slot segment.
|
|
740
|
+
* Prioritizes the generated parameter maps from `.dinou/types/routes.d.ts`,
|
|
741
|
+
* and falls back to template literal extraction.
|
|
742
|
+
*/
|
|
743
|
+
export type RouteParams<T extends DinouSegmentPattern = DinouRoutePattern> =
|
|
744
|
+
LookupSegmentParams<T>;
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Resolved cumulative dynamic parameters for a Layout segment (`layout.tsx` / `layout_functions.ts`),
|
|
748
|
+
* including intermediate layouts without a sibling `page.tsx`.
|
|
749
|
+
*/
|
|
750
|
+
export type LayoutParams<T extends DinouLayoutPattern = DinouLayoutPattern> =
|
|
751
|
+
[string] extends [T]
|
|
752
|
+
? Record<string, string | string[] | undefined>
|
|
753
|
+
: T extends string
|
|
754
|
+
? DinouRouter.Register extends { layoutParams: infer LP }
|
|
755
|
+
? CleanRoutePath<T> extends keyof LP
|
|
756
|
+
? LP[CleanRoutePath<T>]
|
|
757
|
+
: LookupSegmentParams<T>
|
|
758
|
+
: LookupSegmentParams<T>
|
|
759
|
+
: never;
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Auto-inferred parallel `@slot` ReactNode props injected into a Layout at segment `T`
|
|
763
|
+
* (e.g. `{ sidebar?: ReactNode; analytics?: ReactNode }`).
|
|
764
|
+
*/
|
|
765
|
+
export type LayoutSlots<T extends string = string> =
|
|
766
|
+
[T] extends [never]
|
|
767
|
+
? {}
|
|
768
|
+
: [string] extends [T]
|
|
769
|
+
? {}
|
|
770
|
+
: true extends IsUnion<CleanRoutePath<T>>
|
|
771
|
+
? {}
|
|
772
|
+
: DinouRouter.Register extends { layoutSlots: infer LS }
|
|
773
|
+
? CleanRoutePath<T> extends keyof LS
|
|
774
|
+
? SimplifyParams<LS[CleanRoutePath<T>]>
|
|
775
|
+
: {}
|
|
776
|
+
: {};
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Resolved cumulative dynamic parameters for a Parallel `@slot` page (`@slot/page.tsx`).
|
|
780
|
+
*/
|
|
781
|
+
export type SlotParams<T extends DinouSlotPattern = DinouSlotPattern> =
|
|
782
|
+
[string] extends [T]
|
|
783
|
+
? Record<string, string | string[] | undefined>
|
|
784
|
+
: [`/@${string}`] extends [T]
|
|
785
|
+
? Record<string, string | string[] | undefined>
|
|
786
|
+
: T extends string
|
|
787
|
+
? DinouRouter.Register extends { slotParams: infer SP }
|
|
788
|
+
? CleanRoutePath<T> extends keyof SP
|
|
789
|
+
? SP[CleanRoutePath<T>]
|
|
790
|
+
: LookupSegmentParams<T>
|
|
791
|
+
: LookupSegmentParams<T>
|
|
792
|
+
: never;
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* Resolved cumulative dynamic parameters for an Error boundary (`error.tsx`),
|
|
796
|
+
* including intermediate directory boundaries and `@slot/error.tsx`.
|
|
797
|
+
*/
|
|
798
|
+
export type ErrorParams<T extends DinouErrorPattern = DinouErrorPattern> =
|
|
799
|
+
[string] extends [T]
|
|
800
|
+
? Record<string, string | string[] | undefined>
|
|
801
|
+
: T extends string
|
|
802
|
+
? DinouRouter.Register extends { errorParams: infer EP }
|
|
803
|
+
? CleanRoutePath<T> extends keyof EP
|
|
804
|
+
? EP[CleanRoutePath<T>]
|
|
805
|
+
: LookupSegmentParams<T>
|
|
806
|
+
: LookupSegmentParams<T>
|
|
807
|
+
: never;
|
|
504
808
|
|
|
505
809
|
/**
|
|
506
|
-
* Props for Dinou Page components.
|
|
507
|
-
*
|
|
810
|
+
* Props for Dinou Page components (`page.tsx`, `not_found.tsx`, or `@slot/page.tsx`).
|
|
811
|
+
* Optionally accepts a second type argument `TProps` for custom props returned by `page_functions.ts` (`getProps`).
|
|
812
|
+
*
|
|
508
813
|
* @example
|
|
509
814
|
* export default function Page({ params }: PageProps<"/blog/[id]">) {
|
|
510
815
|
* return <h1>Post {params.id}</h1>;
|
|
511
816
|
* }
|
|
512
817
|
*/
|
|
513
|
-
export
|
|
514
|
-
|
|
515
|
-
}
|
|
818
|
+
export type PageProps<
|
|
819
|
+
T extends DinouRoutePattern | DinouRegisteredSlotPattern = DinouRoutePattern,
|
|
820
|
+
TProps extends object = {}
|
|
821
|
+
> = SimplifyParams<
|
|
822
|
+
{
|
|
823
|
+
params: RouteParams<T>;
|
|
824
|
+
} & TProps
|
|
825
|
+
>;
|
|
516
826
|
|
|
517
827
|
/**
|
|
518
|
-
* Props for Dinou
|
|
519
|
-
*
|
|
828
|
+
* Props for Dinou Parallel Slot Page components (`@slot/page.tsx`).
|
|
829
|
+
*
|
|
520
830
|
* @example
|
|
521
|
-
* export default function
|
|
522
|
-
* return <
|
|
831
|
+
* export default function AnalyticsSlot({ params }: SlotProps<"/workspace/[org]/@analytics">) {
|
|
832
|
+
* return <aside>Org: {params.org}</aside>;
|
|
523
833
|
* }
|
|
524
834
|
*/
|
|
525
|
-
export interface
|
|
526
|
-
|
|
527
|
-
params: RouteParams<T>;
|
|
835
|
+
export interface SlotProps<T extends DinouSlotPattern = DinouSlotPattern> {
|
|
836
|
+
params: SlotParams<T>;
|
|
528
837
|
}
|
|
529
838
|
|
|
530
839
|
/**
|
|
531
|
-
* Props for Dinou
|
|
532
|
-
*
|
|
840
|
+
* Props for Dinou Layout components (`layout.tsx`), including intermediate layouts without a sibling `page.tsx`.
|
|
841
|
+
* Automatically includes any sibling parallel `@slot` props (`ReactNode`) defined at that segment,
|
|
842
|
+
* and optionally accepts a second type argument `TProps` for custom props returned by `layout_functions.ts` (`getProps`).
|
|
843
|
+
*
|
|
844
|
+
* @example
|
|
845
|
+
* export default function WorkspaceLayout({ children, params, sidebar }: LayoutProps<"/workspace/[org]">) {
|
|
846
|
+
* return <div>{sidebar}<main>{children}</main></div>;
|
|
847
|
+
* }
|
|
848
|
+
*/
|
|
849
|
+
export type LayoutProps<
|
|
850
|
+
T extends DinouLayoutPattern = DinouLayoutPattern,
|
|
851
|
+
TProps extends object = {}
|
|
852
|
+
> = SimplifyParams<
|
|
853
|
+
{
|
|
854
|
+
children: ReactNode;
|
|
855
|
+
params: LayoutParams<T>;
|
|
856
|
+
} & LayoutSlots<T> &
|
|
857
|
+
TProps
|
|
858
|
+
>;
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* Props for Dinou Error Page components (`error.tsx`), including intermediate and `@slot/error.tsx` boundaries.
|
|
862
|
+
*
|
|
533
863
|
* @example
|
|
534
864
|
* export default function ErrorPage({ error, params }: ErrorProps<"/blog/[id]">) {
|
|
535
865
|
* return <h1>Error loading {params.id}: {error.message}</h1>;
|
|
536
866
|
* }
|
|
537
867
|
*/
|
|
538
|
-
export interface ErrorProps<T extends
|
|
868
|
+
export interface ErrorProps<T extends DinouErrorPattern = DinouErrorPattern> {
|
|
539
869
|
error: Error;
|
|
540
|
-
params:
|
|
870
|
+
params: ErrorParams<T>;
|
|
541
871
|
}
|
|
542
872
|
|
|
873
|
+
/**
|
|
874
|
+
* Props for Dinou Not-Found Page components (`not_found.tsx`), including root, leaf,
|
|
875
|
+
* and intermediate directory 404 boundaries (with or without a sibling `page.tsx`).
|
|
876
|
+
* Optionally accepts a second type argument `TProps` for custom props returned by a sibling `page_functions.ts` (`getProps`).
|
|
877
|
+
*
|
|
878
|
+
* @example
|
|
879
|
+
* export default function WorkspaceNotFound({ params }: NotFoundProps<"/workspace/[org]">) {
|
|
880
|
+
* return <h1>Nothing found in {params.org}</h1>;
|
|
881
|
+
* }
|
|
882
|
+
*/
|
|
883
|
+
export type NotFoundProps<
|
|
884
|
+
T extends DinouNotFoundPattern = DinouNotFoundPattern,
|
|
885
|
+
TProps extends object = {}
|
|
886
|
+
> = SimplifyParams<
|
|
887
|
+
{
|
|
888
|
+
params: RouteParams<T>;
|
|
889
|
+
} & TProps
|
|
890
|
+
>;
|
|
891
|
+
|
|
892
|
+
// ====================================================================
|
|
893
|
+
// DYNAMIC ROUTE PATTERN, STRICT RELATIVE (`from`) & PARAMS TYPES
|
|
894
|
+
// ====================================================================
|
|
895
|
+
|
|
896
|
+
export type ToLinkInputParamValue<V> =
|
|
897
|
+
[V] extends [never]
|
|
898
|
+
? never
|
|
899
|
+
: [Exclude<V, undefined>] extends [ReadonlyArray<string>]
|
|
900
|
+
? ReadonlyArray<string | number> | Extract<V, undefined>
|
|
901
|
+
: [Exclude<V, undefined>] extends [string]
|
|
902
|
+
? string | number | Extract<V, undefined>
|
|
903
|
+
: V;
|
|
904
|
+
|
|
905
|
+
export type ToLinkInputParams<P> = {
|
|
906
|
+
[K in keyof P]: ToLinkInputParamValue<P[K]>;
|
|
907
|
+
};
|
|
908
|
+
|
|
909
|
+
export type DinouNavigableRoutePatternMap =
|
|
910
|
+
DinouRouter.Register extends { navigableParams: infer NP }
|
|
911
|
+
? NP
|
|
912
|
+
: DinouRouter.Register extends { params: infer P }
|
|
913
|
+
? P
|
|
914
|
+
: never;
|
|
915
|
+
|
|
916
|
+
export type DinouNavigableRouteKey =
|
|
917
|
+
[DinouNavigableRoutePatternMap] extends [never]
|
|
918
|
+
? never
|
|
919
|
+
: Extract<keyof DinouNavigableRoutePatternMap, string>;
|
|
920
|
+
|
|
921
|
+
export type DinouDynamicRoutePattern =
|
|
922
|
+
[DinouNavigableRoutePatternMap] extends [never]
|
|
923
|
+
? never
|
|
924
|
+
: Extract<DinouNavigableRouteKey, `${string}[${string}]${string}`>;
|
|
925
|
+
|
|
926
|
+
export type DinouDynamicRouteWithSuffix =
|
|
927
|
+
| DinouDynamicRoutePattern
|
|
928
|
+
| ((
|
|
929
|
+
| `${DinouDynamicRoutePattern}?${string}`
|
|
930
|
+
| `${DinouDynamicRoutePattern}#${string}`
|
|
931
|
+
) & Record<never, never>);
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Union of all valid non-relative targets accepted by `<Link>`, `router.push()`, and `router.replace()`
|
|
935
|
+
* when `from` is omitted. Combines concrete/interpolated `DinouRoute` URLs with exact dynamic route patterns
|
|
936
|
+
* (e.g. `"/blog/[slug]"`) so IDEs surface dynamic routes in `Ctrl + Space` autocomplete
|
|
937
|
+
* while requiring a typed `params` object whenever a `[param]` pattern is selected.
|
|
938
|
+
*/
|
|
939
|
+
export type DinouLinkTarget = DinouRoute | DinouDynamicRouteWithSuffix;
|
|
940
|
+
|
|
941
|
+
export type BuildDirectoryPrefixes<
|
|
942
|
+
Segs extends string[],
|
|
943
|
+
Acc extends string = ""
|
|
944
|
+
> = Segs extends [infer Head extends string, ...infer Tail extends string[]]
|
|
945
|
+
? `${Acc}/${Head}` | BuildDirectoryPrefixes<Tail, `${Acc}/${Head}`>
|
|
946
|
+
: "/";
|
|
947
|
+
|
|
948
|
+
export type ExtractParentDirectories<Path extends string> =
|
|
949
|
+
Path extends any ? BuildDirectoryPrefixes<SplitRouteSegments<Path>> : never;
|
|
950
|
+
|
|
951
|
+
export type PeelOptionalRouteSegments<Path extends string> =
|
|
952
|
+
| Path
|
|
953
|
+
| (Path extends `${infer Prefix}/[[${string}]]`
|
|
954
|
+
? PeelOptionalRouteSegments<Prefix extends "" ? "/" : Prefix>
|
|
955
|
+
: never);
|
|
956
|
+
|
|
957
|
+
export type DinouEffectiveRoutePattern =
|
|
958
|
+
PeelOptionalRouteSegments<DinouNavigableRouteKey>;
|
|
959
|
+
|
|
960
|
+
export type DinouFromSlashRoute =
|
|
961
|
+
| DinouNavigableRouteKey
|
|
962
|
+
| (DinouRouter.Register extends { layoutParams: infer LP }
|
|
963
|
+
? Extract<keyof LP, string>
|
|
964
|
+
: never)
|
|
965
|
+
| (DinouRouter.Register extends { layoutSlots: infer LS }
|
|
966
|
+
? Extract<keyof LS, string>
|
|
967
|
+
: never)
|
|
968
|
+
| (DinouRouter.Register extends { errorParams: infer EP }
|
|
969
|
+
? Exclude<Extract<keyof EP, string>, `${string}/@${string}`>
|
|
970
|
+
: never)
|
|
971
|
+
| ExtractParentDirectories<DinouNavigableRouteKey>;
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* Valid origin directory patterns accepted by the `from` prop on `<Link>` and `{ from }` option on `useRouter()`.
|
|
975
|
+
* Autocompletes leading-slash route/directory patterns (e.g. `"/t-slots/[slug]/contact"`) while also accepting
|
|
976
|
+
* non-leading-slash equivalents (e.g. `"t-slots/[slug]/contact"`).
|
|
977
|
+
*/
|
|
978
|
+
export type DinouFromRoute =
|
|
979
|
+
[DinouNavigableRoutePatternMap] extends [never]
|
|
980
|
+
? string
|
|
981
|
+
: | DinouFromSlashRoute
|
|
982
|
+
| ((DinouFromSlashRoute extends `/${infer Rest}`
|
|
983
|
+
? Rest extends ""
|
|
984
|
+
? never
|
|
985
|
+
: Rest
|
|
986
|
+
: never) & Record<never, never>);
|
|
987
|
+
|
|
988
|
+
export type SplitRouteSegments<Path extends string> =
|
|
989
|
+
Path extends "/" | ""
|
|
990
|
+
? []
|
|
991
|
+
: Path extends `/${infer Rest}`
|
|
992
|
+
? SplitRouteSegments<Rest>
|
|
993
|
+
: Path extends `${infer Head}/${infer Tail}`
|
|
994
|
+
? [Head, ...SplitRouteSegments<Tail>]
|
|
995
|
+
: [Path];
|
|
996
|
+
|
|
997
|
+
export type StripCommonPrefix<
|
|
998
|
+
FromSegs extends string[],
|
|
999
|
+
TargetSegs extends string[]
|
|
1000
|
+
> = FromSegs extends [infer FHead extends string, ...infer FTail extends string[]]
|
|
1001
|
+
? TargetSegs extends [FHead, ...infer TTail extends string[]]
|
|
1002
|
+
? StripCommonPrefix<FTail, TTail>
|
|
1003
|
+
: [FromSegs, TargetSegs]
|
|
1004
|
+
: [FromSegs, TargetSegs];
|
|
1005
|
+
|
|
1006
|
+
export type HasVariableLengthSegment<Segs extends string[]> =
|
|
1007
|
+
Segs extends [infer Head extends string, ...infer Tail extends string[]]
|
|
1008
|
+
? Head extends `[...${string}]` | `[[${string}]]`
|
|
1009
|
+
? true
|
|
1010
|
+
: HasVariableLengthSegment<Tail>
|
|
1011
|
+
: false;
|
|
1012
|
+
|
|
1013
|
+
export type HasDynamicSegment<Segs extends string[]> =
|
|
1014
|
+
Segs extends [infer Head extends string, ...infer Tail extends string[]]
|
|
1015
|
+
? Head extends `[${string}]`
|
|
1016
|
+
? true
|
|
1017
|
+
: HasDynamicSegment<Tail>
|
|
1018
|
+
: false;
|
|
1019
|
+
|
|
1020
|
+
export type ToDotDotSegments<Segs extends string[]> =
|
|
1021
|
+
Segs extends [string, ...infer Tail extends string[]]
|
|
1022
|
+
? ["..", ...ToDotDotSegments<Tail>]
|
|
1023
|
+
: [];
|
|
1024
|
+
|
|
1025
|
+
export type JoinSlash<Segs extends string[]> =
|
|
1026
|
+
Segs extends []
|
|
1027
|
+
? ""
|
|
1028
|
+
: Segs extends [infer Only extends string]
|
|
1029
|
+
? Only
|
|
1030
|
+
: Segs extends [infer Head extends string, ...infer Tail extends string[]]
|
|
1031
|
+
? `${Head}/${JoinSlash<Tail>}`
|
|
1032
|
+
: "";
|
|
1033
|
+
|
|
1034
|
+
export type SegmentToTemplate<Seg extends string> =
|
|
1035
|
+
Seg extends `[[...${string}]]`
|
|
1036
|
+
? `${string}`
|
|
1037
|
+
: Seg extends `[[${string}]]`
|
|
1038
|
+
? `${string | number}`
|
|
1039
|
+
: Seg extends `[...${string}]`
|
|
1040
|
+
? `${string}`
|
|
1041
|
+
: Seg extends `[${string}]`
|
|
1042
|
+
? `${string | number}`
|
|
1043
|
+
: Seg;
|
|
1044
|
+
|
|
1045
|
+
export type MapSegmentsToTemplate<Segs extends string[]> =
|
|
1046
|
+
Segs extends [infer Head extends string, ...infer Tail extends string[]]
|
|
1047
|
+
? [SegmentToTemplate<Head>, ...MapSegmentsToTemplate<Tail>]
|
|
1048
|
+
: [];
|
|
1049
|
+
|
|
1050
|
+
export type SharesFirstSegment<
|
|
1051
|
+
FromSegs extends string[],
|
|
1052
|
+
TargetSegs extends string[]
|
|
1053
|
+
> = FromSegs extends [infer FH extends string, ...string[]]
|
|
1054
|
+
? TargetSegs extends [FH, ...string[]]
|
|
1055
|
+
? true
|
|
1056
|
+
: false
|
|
1057
|
+
: true;
|
|
1058
|
+
|
|
1059
|
+
export type ComputeRelativeCompletionSingle<
|
|
1060
|
+
FromSegs extends string[],
|
|
1061
|
+
TargetSegs extends string[]
|
|
1062
|
+
> = StripCommonPrefix<FromSegs, TargetSegs> extends [
|
|
1063
|
+
infer RemFrom extends string[],
|
|
1064
|
+
infer RemTarget extends string[]
|
|
1065
|
+
]
|
|
1066
|
+
? RemFrom extends []
|
|
1067
|
+
? RemTarget extends []
|
|
1068
|
+
? "."
|
|
1069
|
+
: `${JoinSlash<RemTarget>}` | `./${JoinSlash<RemTarget>}`
|
|
1070
|
+
: HasVariableLengthSegment<RemFrom> extends true
|
|
1071
|
+
? never
|
|
1072
|
+
: RemTarget extends []
|
|
1073
|
+
? JoinSlash<ToDotDotSegments<RemFrom>>
|
|
1074
|
+
: SharesFirstSegment<FromSegs, TargetSegs> extends true
|
|
1075
|
+
? JoinSlash<[...ToDotDotSegments<RemFrom>, ...RemTarget]>
|
|
1076
|
+
: never
|
|
1077
|
+
: never;
|
|
1078
|
+
|
|
1079
|
+
export type ComputeRelativeAllPatternsSingle<
|
|
1080
|
+
FromSegs extends string[],
|
|
1081
|
+
TargetSegs extends string[]
|
|
1082
|
+
> = StripCommonPrefix<FromSegs, TargetSegs> extends [
|
|
1083
|
+
infer RemFrom extends string[],
|
|
1084
|
+
infer RemTarget extends string[]
|
|
1085
|
+
]
|
|
1086
|
+
? RemFrom extends []
|
|
1087
|
+
? RemTarget extends []
|
|
1088
|
+
? "." | "./"
|
|
1089
|
+
: `${JoinSlash<RemTarget>}` | `./${JoinSlash<RemTarget>}`
|
|
1090
|
+
: HasVariableLengthSegment<RemFrom> extends true
|
|
1091
|
+
? never
|
|
1092
|
+
: JoinSlash<[...ToDotDotSegments<RemFrom>, ...RemTarget]>
|
|
1093
|
+
: never;
|
|
1094
|
+
|
|
1095
|
+
export type ComputeRelativeTemplateSingle<
|
|
1096
|
+
FromSegs extends string[],
|
|
1097
|
+
TargetSegs extends string[]
|
|
1098
|
+
> = StripCommonPrefix<FromSegs, TargetSegs> extends [
|
|
1099
|
+
infer RemFrom extends string[],
|
|
1100
|
+
infer RemTarget extends string[]
|
|
1101
|
+
]
|
|
1102
|
+
? HasDynamicSegment<RemTarget> extends false
|
|
1103
|
+
? never
|
|
1104
|
+
: RemFrom extends []
|
|
1105
|
+
? | JoinSlash<MapSegmentsToTemplate<RemTarget>>
|
|
1106
|
+
| `./${JoinSlash<MapSegmentsToTemplate<RemTarget>>}`
|
|
1107
|
+
: HasVariableLengthSegment<RemFrom> extends true
|
|
1108
|
+
? never
|
|
1109
|
+
: JoinSlash<[...ToDotDotSegments<RemFrom>, ...MapSegmentsToTemplate<RemTarget>]>
|
|
1110
|
+
: never;
|
|
1111
|
+
|
|
1112
|
+
type DistributeRelativeCompletionsFromSegs<
|
|
1113
|
+
FromSegs extends string[],
|
|
1114
|
+
Targets extends string
|
|
1115
|
+
> = Targets extends any
|
|
1116
|
+
? ComputeRelativeCompletionSingle<FromSegs, SplitRouteSegments<Targets>>
|
|
1117
|
+
: never;
|
|
1118
|
+
|
|
1119
|
+
export type DistributeRelativeCompletions<
|
|
1120
|
+
FromPath extends string,
|
|
1121
|
+
Targets extends string
|
|
1122
|
+
> = SplitRouteSegments<FromPath> extends infer FromSegs extends string[]
|
|
1123
|
+
? DistributeRelativeCompletionsFromSegs<FromSegs, Targets>
|
|
1124
|
+
: never;
|
|
1125
|
+
|
|
1126
|
+
type DistributeAllRelativePatternsFromSegs<
|
|
1127
|
+
FromSegs extends string[],
|
|
1128
|
+
Targets extends string
|
|
1129
|
+
> = Targets extends any
|
|
1130
|
+
? ComputeRelativeAllPatternsSingle<FromSegs, SplitRouteSegments<Targets>>
|
|
1131
|
+
: never;
|
|
1132
|
+
|
|
1133
|
+
export type DistributeAllRelativePatterns<
|
|
1134
|
+
FromPath extends string,
|
|
1135
|
+
Targets extends string
|
|
1136
|
+
> = SplitRouteSegments<FromPath> extends infer FromSegs extends string[]
|
|
1137
|
+
? DistributeAllRelativePatternsFromSegs<FromSegs, Targets>
|
|
1138
|
+
: never;
|
|
1139
|
+
|
|
1140
|
+
type DistributeRelativeTemplatesFromSegs<
|
|
1141
|
+
FromSegs extends string[],
|
|
1142
|
+
Targets extends string
|
|
1143
|
+
> = Targets extends any
|
|
1144
|
+
? ComputeRelativeTemplateSingle<FromSegs, SplitRouteSegments<Targets>>
|
|
1145
|
+
: never;
|
|
1146
|
+
|
|
1147
|
+
export type DistributeRelativeTemplates<
|
|
1148
|
+
FromPath extends string,
|
|
1149
|
+
Targets extends string
|
|
1150
|
+
> = SplitRouteSegments<FromPath> extends infer FromSegs extends string[]
|
|
1151
|
+
? DistributeRelativeTemplatesFromSegs<FromSegs, Targets>
|
|
1152
|
+
: never;
|
|
1153
|
+
|
|
1154
|
+
type RelativeTargetRecord<
|
|
1155
|
+
FromSegs extends string[],
|
|
1156
|
+
TargetSegs extends string[]
|
|
1157
|
+
> = StripCommonPrefix<FromSegs, TargetSegs> extends [
|
|
1158
|
+
infer RemFrom extends string[],
|
|
1159
|
+
infer RemTarget extends string[]
|
|
1160
|
+
]
|
|
1161
|
+
? RemFrom extends []
|
|
1162
|
+
? RemTarget extends []
|
|
1163
|
+
? { c: "."; e: "./"; t: never }
|
|
1164
|
+
: JoinSlash<RemTarget> extends infer J extends string
|
|
1165
|
+
? {
|
|
1166
|
+
c: J | `./${J}`;
|
|
1167
|
+
e: never;
|
|
1168
|
+
t: HasDynamicSegment<RemTarget> extends true
|
|
1169
|
+
? JoinSlash<MapSegmentsToTemplate<RemTarget>> extends infer TJ extends string
|
|
1170
|
+
? TJ | `./${TJ}`
|
|
1171
|
+
: never
|
|
1172
|
+
: never;
|
|
1173
|
+
}
|
|
1174
|
+
: never
|
|
1175
|
+
: HasVariableLengthSegment<RemFrom> extends true
|
|
1176
|
+
? never
|
|
1177
|
+
: ToDotDotSegments<RemFrom> extends infer Dots extends string[]
|
|
1178
|
+
? RemTarget extends []
|
|
1179
|
+
? { c: JoinSlash<Dots>; e: never; t: never }
|
|
1180
|
+
: JoinSlash<[...Dots, ...RemTarget]> extends infer J extends string
|
|
1181
|
+
? {
|
|
1182
|
+
c: SharesFirstSegment<FromSegs, TargetSegs> extends true ? J : never;
|
|
1183
|
+
e: SharesFirstSegment<FromSegs, TargetSegs> extends true ? never : J;
|
|
1184
|
+
t: HasDynamicSegment<RemTarget> extends true
|
|
1185
|
+
? JoinSlash<[...Dots, ...MapSegmentsToTemplate<RemTarget>]>
|
|
1186
|
+
: never;
|
|
1187
|
+
}
|
|
1188
|
+
: never
|
|
1189
|
+
: never
|
|
1190
|
+
: never;
|
|
1191
|
+
|
|
1192
|
+
type DistributeRelativeRecords<
|
|
1193
|
+
FromSegs extends string[],
|
|
1194
|
+
Targets extends string
|
|
1195
|
+
> = Targets extends any
|
|
1196
|
+
? RelativeTargetRecord<FromSegs, SplitRouteSegments<Targets>>
|
|
1197
|
+
: never;
|
|
1198
|
+
|
|
1199
|
+
type PackRelativeTarget<
|
|
1200
|
+
Rec extends { c: string; e: string; t: string },
|
|
1201
|
+
C extends string = Rec["c"],
|
|
1202
|
+
E extends string = Rec["e"],
|
|
1203
|
+
T extends string = Rec["t"],
|
|
1204
|
+
Base extends string = C | E | T
|
|
1205
|
+
> =
|
|
1206
|
+
| C
|
|
1207
|
+
| ((E | T | `${Base}?${string}` | `${Base}#${string}`) & Record<never, never>);
|
|
1208
|
+
|
|
1209
|
+
export type DinouRelativeDynamicPattern<TFrom extends string> = Extract<
|
|
1210
|
+
DistributeAllRelativePatterns<CleanRoutePath<TFrom>, DinouEffectiveRoutePattern>,
|
|
1211
|
+
`${string}[${string}]${string}`
|
|
1212
|
+
>;
|
|
1213
|
+
|
|
1214
|
+
/**
|
|
1215
|
+
* Valid relative navigation targets from origin `TFrom` (supporting both bare `"sub"` and `"./sub"`,
|
|
1216
|
+
* as well as `".."` / `"../sibling"`, query/hash suffixes, and dynamic relative segments).
|
|
1217
|
+
*/
|
|
1218
|
+
export type DinouRelativeLinkTarget<TFrom extends string> =
|
|
1219
|
+
[DinouNavigableRoutePatternMap] extends [never]
|
|
1220
|
+
? string
|
|
1221
|
+
: [string] extends [TFrom]
|
|
1222
|
+
? string
|
|
1223
|
+
: SplitRouteSegments<CleanRoutePath<TFrom>> extends infer FromSegs extends string[]
|
|
1224
|
+
? PackRelativeTarget<DistributeRelativeRecords<FromSegs, DinouEffectiveRoutePattern>>
|
|
1225
|
+
: never;
|
|
1226
|
+
|
|
1227
|
+
export type DinouLinkTargetForFrom<TFrom extends string | undefined> =
|
|
1228
|
+
[TFrom] extends [undefined]
|
|
1229
|
+
? DinouLinkTarget
|
|
1230
|
+
: DinouRelativeLinkTarget<Extract<TFrom, string>>;
|
|
1231
|
+
|
|
1232
|
+
/**
|
|
1233
|
+
* Unified target union for route-contextual `<Link>` and `useRouter()` imported from `"./dinou"`.
|
|
1234
|
+
* Combines strictly validated relative paths from `TFrom` (`"sub"`, `"./sub"`, `"../..."`)
|
|
1235
|
+
* with all valid absolute static routes, dynamic route patterns, queries, hashes, and external URLs.
|
|
1236
|
+
*/
|
|
1237
|
+
export type DinouScopedLinkTarget<TFrom extends string> =
|
|
1238
|
+
| DinouRelativeLinkTarget<TFrom>
|
|
1239
|
+
| DinouLinkTarget;
|
|
1240
|
+
|
|
1241
|
+
export type ScopedLinkTargetForFrom<
|
|
1242
|
+
TDefaultFrom extends string,
|
|
1243
|
+
TFrom extends DinouFromRoute | undefined
|
|
1244
|
+
> =
|
|
1245
|
+
[TFrom] extends [undefined]
|
|
1246
|
+
? DinouScopedLinkTarget<TDefaultFrom>
|
|
1247
|
+
: DinouLinkTargetForFrom<TFrom>;
|
|
1248
|
+
|
|
1249
|
+
export type StripUrlSuffix<T extends string> =
|
|
1250
|
+
T extends `${infer Base}?${string}`
|
|
1251
|
+
? StripUrlSuffix<Base>
|
|
1252
|
+
: T extends `${infer Base}#${string}`
|
|
1253
|
+
? StripUrlSuffix<Base>
|
|
1254
|
+
: T;
|
|
1255
|
+
|
|
1256
|
+
export type IsExternalLinkHref<T extends string> =
|
|
1257
|
+
T extends
|
|
1258
|
+
| `http://${string}`
|
|
1259
|
+
| `https://${string}`
|
|
1260
|
+
| `//${string}`
|
|
1261
|
+
| `mailto:${string}`
|
|
1262
|
+
| `tel:${string}`
|
|
1263
|
+
? true
|
|
1264
|
+
: false;
|
|
1265
|
+
|
|
1266
|
+
export type IsInternalBracketPattern<T extends string> =
|
|
1267
|
+
IsExternalLinkHref<T> extends true
|
|
1268
|
+
? false
|
|
1269
|
+
: StripUrlSuffix<T> extends `${string}[${string}]${string}`
|
|
1270
|
+
? true
|
|
1271
|
+
: false;
|
|
1272
|
+
|
|
1273
|
+
export type ValidatedLinkHref<THref extends string> =
|
|
1274
|
+
[string] extends [THref]
|
|
1275
|
+
? THref
|
|
1276
|
+
: DinouRouter.Register extends { route: unknown }
|
|
1277
|
+
? THref extends any
|
|
1278
|
+
? IsInternalBracketPattern<THref> extends true
|
|
1279
|
+
? StripUrlSuffix<THref> extends DinouDynamicRoutePattern
|
|
1280
|
+
? THref
|
|
1281
|
+
: never
|
|
1282
|
+
: THref
|
|
1283
|
+
: never
|
|
1284
|
+
: THref;
|
|
1285
|
+
|
|
1286
|
+
export type HasInvalidBracketPatternForFrom<
|
|
1287
|
+
TFrom extends string | undefined,
|
|
1288
|
+
THref extends string
|
|
1289
|
+
> =
|
|
1290
|
+
[string] extends [THref]
|
|
1291
|
+
? never
|
|
1292
|
+
: DinouRouter.Register extends { route: unknown }
|
|
1293
|
+
? THref extends any
|
|
1294
|
+
? IsInternalBracketPattern<THref> extends true
|
|
1295
|
+
? [TFrom] extends [undefined]
|
|
1296
|
+
? StripUrlSuffix<THref> extends DinouDynamicRoutePattern
|
|
1297
|
+
? never
|
|
1298
|
+
: true
|
|
1299
|
+
: [string] extends [Extract<TFrom, string>]
|
|
1300
|
+
? never
|
|
1301
|
+
: StripUrlSuffix<THref> extends `/${string}`
|
|
1302
|
+
? StripUrlSuffix<THref> extends DinouDynamicRoutePattern
|
|
1303
|
+
? never
|
|
1304
|
+
: true
|
|
1305
|
+
: StripUrlSuffix<THref> extends DinouRelativeDynamicPattern<Extract<TFrom, string>>
|
|
1306
|
+
? never
|
|
1307
|
+
: true
|
|
1308
|
+
: never
|
|
1309
|
+
: never
|
|
1310
|
+
: never;
|
|
1311
|
+
|
|
1312
|
+
export type HasInvalidBracketPattern<THref extends string> =
|
|
1313
|
+
HasInvalidBracketPatternForFrom<undefined, THref>;
|
|
1314
|
+
|
|
1315
|
+
export type HasBracketPattern<THref extends string> =
|
|
1316
|
+
[string] extends [THref]
|
|
1317
|
+
? never
|
|
1318
|
+
: THref extends any
|
|
1319
|
+
? IsInternalBracketPattern<THref> extends true
|
|
1320
|
+
? true
|
|
1321
|
+
: never
|
|
1322
|
+
: never;
|
|
1323
|
+
|
|
1324
|
+
export type UnionToIntersection<U> =
|
|
1325
|
+
(U extends any ? (k: U) => void : never) extends (k: infer I) => void
|
|
1326
|
+
? I
|
|
1327
|
+
: never;
|
|
1328
|
+
|
|
1329
|
+
export type ResolveSingleLinkParams<Path extends string> =
|
|
1330
|
+
[DinouNavigableRoutePatternMap] extends [never]
|
|
1331
|
+
? SimplifyParams<ToLinkInputParams<FallbackNavigableParams<CleanRoutePath<Path>>>>
|
|
1332
|
+
: CleanRoutePath<Path> extends keyof DinouNavigableRoutePatternMap
|
|
1333
|
+
? SimplifyParams<ToLinkInputParams<DinouNavigableRoutePatternMap[CleanRoutePath<Path>]>>
|
|
1334
|
+
: SimplifyParams<ToLinkInputParams<FallbackNavigableParams<CleanRoutePath<Path>>>>;
|
|
1335
|
+
|
|
1336
|
+
export type ResolveLinkParams<THref extends string> = SimplifyParams<
|
|
1337
|
+
UnionToIntersection<
|
|
1338
|
+
THref extends any
|
|
1339
|
+
? IsInternalBracketPattern<THref> extends true
|
|
1340
|
+
? ResolveSingleLinkParams<StripUrlSuffix<THref>>
|
|
1341
|
+
: {}
|
|
1342
|
+
: never
|
|
1343
|
+
>
|
|
1344
|
+
>;
|
|
1345
|
+
|
|
1346
|
+
export type LinkParamsPropsForFrom<
|
|
1347
|
+
TFrom extends string | undefined,
|
|
1348
|
+
THref extends string
|
|
1349
|
+
> =
|
|
1350
|
+
[HasInvalidBracketPatternForFrom<TFrom, THref>] extends [never]
|
|
1351
|
+
? [HasBracketPattern<THref>] extends [never]
|
|
1352
|
+
? { params?: never }
|
|
1353
|
+
: {} extends ResolveLinkParams<THref>
|
|
1354
|
+
? { params?: ResolveLinkParams<THref> }
|
|
1355
|
+
: { params: ResolveLinkParams<THref> }
|
|
1356
|
+
: { params: never };
|
|
1357
|
+
|
|
1358
|
+
export type LinkParamsProps<THref extends string> =
|
|
1359
|
+
LinkParamsPropsForFrom<undefined, THref>;
|
|
1360
|
+
|
|
1361
|
+
export type RouterNavigationArgs<THref extends string> =
|
|
1362
|
+
[HasInvalidBracketPattern<THref>] extends [never]
|
|
1363
|
+
? [HasBracketPattern<THref>] extends [never]
|
|
1364
|
+
? [options?: NavigationOptions & { from?: never; params?: never }]
|
|
1365
|
+
: {} extends ResolveLinkParams<THref>
|
|
1366
|
+
? [options?: NavigationOptions & { from?: never; params?: ResolveLinkParams<THref> }]
|
|
1367
|
+
: [options: NavigationOptions & { from?: never; params: ResolveLinkParams<THref> }]
|
|
1368
|
+
: [options: never];
|
|
1369
|
+
|
|
1370
|
+
export type RouterRelativeNavigationOptions<
|
|
1371
|
+
TFrom extends DinouFromRoute,
|
|
1372
|
+
THref extends string
|
|
1373
|
+
> =
|
|
1374
|
+
[HasInvalidBracketPatternForFrom<TFrom, THref>] extends [never]
|
|
1375
|
+
? [HasBracketPattern<THref>] extends [never]
|
|
1376
|
+
? NavigationOptions & { from: TFrom; params?: never }
|
|
1377
|
+
: {} extends ResolveLinkParams<THref>
|
|
1378
|
+
? NavigationOptions & { from: TFrom; params?: ResolveLinkParams<THref> }
|
|
1379
|
+
: NavigationOptions & { from: TFrom; params: ResolveLinkParams<THref> }
|
|
1380
|
+
: never;
|
|
1381
|
+
|
|
1382
|
+
export interface DinouRouterNavigateFn {
|
|
1383
|
+
/**
|
|
1384
|
+
* Navigate to an absolute route, dynamic route pattern (with `{ params }`), query/hash, or external URL.
|
|
1385
|
+
*/
|
|
1386
|
+
<THref extends DinouLinkTarget = DinouRoute>(
|
|
1387
|
+
href: THref,
|
|
1388
|
+
...args: RouterNavigationArgs<NoInfer<THref>>
|
|
1389
|
+
): void;
|
|
1390
|
+
|
|
1391
|
+
/**
|
|
1392
|
+
* Navigate to a strictly validated relative route (`"sub"`, `"./sub"`, `"../other"`) from `options.from`.
|
|
1393
|
+
*/
|
|
1394
|
+
<
|
|
1395
|
+
TFrom extends DinouFromRoute,
|
|
1396
|
+
THref extends DinouRelativeLinkTarget<TFrom> = DinouRelativeLinkTarget<TFrom>
|
|
1397
|
+
>(
|
|
1398
|
+
href: THref,
|
|
1399
|
+
options: RouterRelativeNavigationOptions<TFrom, NoInfer<THref>>
|
|
1400
|
+
): void;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
export type ScopedRouterNavigationArgs<
|
|
1404
|
+
TDefaultFrom extends string,
|
|
1405
|
+
THref extends string
|
|
1406
|
+
> =
|
|
1407
|
+
[HasInvalidBracketPatternForFrom<TDefaultFrom, THref>] extends [never]
|
|
1408
|
+
? [HasBracketPattern<THref>] extends [never]
|
|
1409
|
+
? [options?: NavigationOptions & { from?: never; params?: never }]
|
|
1410
|
+
: {} extends ResolveLinkParams<THref>
|
|
1411
|
+
? [options?: NavigationOptions & { from?: never; params?: ResolveLinkParams<THref> }]
|
|
1412
|
+
: [options: NavigationOptions & { from?: never; params: ResolveLinkParams<THref> }]
|
|
1413
|
+
: [options: never];
|
|
1414
|
+
|
|
1415
|
+
export interface ScopedDinouRouterNavigateFn<TDefaultFrom extends string> {
|
|
1416
|
+
/**
|
|
1417
|
+
* Navigate to a strictly validated relative route from this folder (`"sub"`, `"./sub"`, `"../other"`),
|
|
1418
|
+
* an absolute route, a dynamic route pattern (with `{ params }`), query/hash, or external URL —
|
|
1419
|
+
* without needing to pass `{ from }`.
|
|
1420
|
+
*/
|
|
1421
|
+
<THref extends DinouScopedLinkTarget<TDefaultFrom> = DinouScopedLinkTarget<TDefaultFrom>>(
|
|
1422
|
+
href: THref,
|
|
1423
|
+
...args: ScopedRouterNavigationArgs<TDefaultFrom, NoInfer<THref>>
|
|
1424
|
+
): void;
|
|
1425
|
+
|
|
1426
|
+
/**
|
|
1427
|
+
* Navigate to a strictly validated relative route from an explicit `options.from` origin override.
|
|
1428
|
+
*/
|
|
1429
|
+
<
|
|
1430
|
+
TFrom extends DinouFromRoute,
|
|
1431
|
+
THref extends DinouRelativeLinkTarget<TFrom> = DinouRelativeLinkTarget<TFrom>
|
|
1432
|
+
>(
|
|
1433
|
+
href: THref,
|
|
1434
|
+
options: RouterRelativeNavigationOptions<TFrom, NoInfer<THref>>
|
|
1435
|
+
): void;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
export type ScopedUseRouterHook<TDefaultFrom extends string> = () => {
|
|
1439
|
+
push: ScopedDinouRouterNavigateFn<TDefaultFrom>;
|
|
1440
|
+
replace: ScopedDinouRouterNavigateFn<TDefaultFrom>;
|
|
1441
|
+
back: () => void;
|
|
1442
|
+
forward: () => void;
|
|
1443
|
+
refresh: (options?: { layout?: boolean }) => void;
|
|
1444
|
+
refreshSlot: (slotId: string, options?: { fresh?: boolean }) => Promise<void>;
|
|
1445
|
+
};
|
|
1446
|
+
|
|
543
1447
|
export declare function useRouter(): {
|
|
544
1448
|
/**
|
|
545
1449
|
* Navigate to the provided href. Pushes a new entry into the history stack.
|
|
546
|
-
*
|
|
547
|
-
*
|
|
1450
|
+
* Supports interpolated URLs (`/blog/${slug}`), autocompleted dynamic patterns with `{ params }`,
|
|
1451
|
+
* and strict relative paths with `{ from }` (`router.push("sub", { from: "/blog/[slug]" })`).
|
|
548
1452
|
*/
|
|
549
|
-
push:
|
|
1453
|
+
push: DinouRouterNavigateFn;
|
|
550
1454
|
|
|
551
1455
|
/**
|
|
552
1456
|
* Navigate to the provided href. Replaces the current entry in the history stack.
|
|
553
|
-
*
|
|
554
|
-
*
|
|
1457
|
+
* Supports interpolated URLs (`/blog/${slug}`), autocompleted dynamic patterns with `{ params }`,
|
|
1458
|
+
* and strict relative paths with `{ from }` (`router.replace("sub", { from: "/blog/[slug]" })`).
|
|
555
1459
|
*/
|
|
556
|
-
replace:
|
|
1460
|
+
replace: DinouRouterNavigateFn;
|
|
557
1461
|
|
|
558
1462
|
/**
|
|
559
1463
|
* Navigate back in the browser's history.
|
|
@@ -615,21 +1519,30 @@ import type { AnchorHTMLAttributes } from "react";
|
|
|
615
1519
|
|
|
616
1520
|
/**
|
|
617
1521
|
* Props for the Dinou Link component.
|
|
618
|
-
*
|
|
1522
|
+
* Extends standard HTML `<a>` attributes and supports:
|
|
1523
|
+
* - Static & interpolated URLs (`href="/about"`, `href={\`/blog/\${slug}\`}`)
|
|
1524
|
+
* - Autocompleted dynamic route patterns with required `params` (`to="/blog/[slug]" params={{ slug }}`)
|
|
1525
|
+
* - Strictly validated relative paths with required `from` (`from="/blog/[slug]" to="sub"` or `to="./sub"`)
|
|
619
1526
|
*/
|
|
620
|
-
export
|
|
1527
|
+
export type LinkProps<
|
|
1528
|
+
TFrom extends DinouFromRoute | undefined = undefined,
|
|
1529
|
+
THref extends DinouLinkTargetForFrom<TFrom> = DinouLinkTargetForFrom<TFrom>
|
|
1530
|
+
> = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href"> & {
|
|
621
1531
|
/**
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
* * Supports absolute paths (e.g., `/dashboard`).
|
|
625
|
-
* * Supports relative paths (e.g., `../settings` or `details`).
|
|
1532
|
+
* Origin route/directory pattern (e.g. `"/workspace/[org]/contact"`) used to strictly
|
|
1533
|
+
* validate and autocomplete relative navigation targets (`"sub"`, `"./sub"`, `"../other"`).
|
|
626
1534
|
*/
|
|
627
|
-
|
|
1535
|
+
from?: TFrom;
|
|
1536
|
+
|
|
1537
|
+
/**
|
|
1538
|
+
* The destination URL, dynamic route pattern, or (when `from` is specified) relative path.
|
|
1539
|
+
*/
|
|
1540
|
+
href?: THref;
|
|
628
1541
|
|
|
629
1542
|
/**
|
|
630
1543
|
* Alias for `href` (React Router / Remix compatibility).
|
|
631
1544
|
*/
|
|
632
|
-
to?:
|
|
1545
|
+
to?: THref;
|
|
633
1546
|
|
|
634
1547
|
/**
|
|
635
1548
|
* Whether to prefetch the RSC payload when the mouse enters the link area (hover).
|
|
@@ -646,7 +1559,7 @@ export interface LinkProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>,
|
|
|
646
1559
|
* @default false
|
|
647
1560
|
*/
|
|
648
1561
|
fresh?: boolean;
|
|
649
|
-
}
|
|
1562
|
+
} & LinkParamsPropsForFrom<NoInfer<TFrom>, NoInfer<THref>>;
|
|
650
1563
|
|
|
651
1564
|
/**
|
|
652
1565
|
* A client-side navigation component that renders an `<a>` tag.
|
|
@@ -654,18 +1567,45 @@ export interface LinkProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>,
|
|
|
654
1567
|
* 1. **Soft Navigation:** Transitions between pages without a full browser reload.
|
|
655
1568
|
* 2. **Prefetching:** Loads the target route data on hover (if enabled).
|
|
656
1569
|
* 3. **Freshness:** Can force a re-fetch of data via the `fresh` prop.
|
|
657
|
-
* 4. **
|
|
658
|
-
* 5. **
|
|
659
|
-
*
|
|
660
|
-
* @example
|
|
661
|
-
* <Link href="/about" className="text-blue-500">
|
|
662
|
-
* Go to About
|
|
663
|
-
* </Link>
|
|
664
|
-
*
|
|
665
|
-
* @example
|
|
666
|
-
* <Link href="/dashboard" fresh>
|
|
667
|
-
* Dashboard (Force Refresh)
|
|
668
|
-
* </Link>
|
|
1570
|
+
* 4. **Dynamic Params Interpolation:** Accepts `params={{ slug }}` when `href`/`to` uses a `[param]` pattern.
|
|
1571
|
+
* 5. **Strict Relative Routing:** Validates and autocompletes `"sub"`, `"./sub"`, and `"../..."` when `from` is specified.
|
|
1572
|
+
* 6. **Scroll Management:** Preserves or resets scroll position intelligently.
|
|
669
1573
|
*/
|
|
670
|
-
export declare function Link
|
|
1574
|
+
export declare function Link<
|
|
1575
|
+
TFrom extends DinouFromRoute | undefined = undefined,
|
|
1576
|
+
THref extends DinouLinkTargetForFrom<TFrom> = DinouLinkTargetForFrom<TFrom>
|
|
1577
|
+
>(props: LinkProps<TFrom, THref>): ReactNode;
|
|
1578
|
+
|
|
1579
|
+
/**
|
|
1580
|
+
* Props for a route-contextual `<Link>` imported from `"./dinou"`.
|
|
1581
|
+
* Pre-binds `from` to `TDefaultFrom` so relative targets (`"sub"`, `"./sub"`, `"../other"`)
|
|
1582
|
+
* autocomplete and validate automatically without passing `from`, while also accepting
|
|
1583
|
+
* absolute/dynamic routes and optional `from` overrides.
|
|
1584
|
+
*/
|
|
1585
|
+
export type ScopedLinkProps<
|
|
1586
|
+
TDefaultFrom extends string,
|
|
1587
|
+
TFrom extends DinouFromRoute | undefined = undefined,
|
|
1588
|
+
THref extends ScopedLinkTargetForFrom<TDefaultFrom, TFrom> = ScopedLinkTargetForFrom<
|
|
1589
|
+
TDefaultFrom,
|
|
1590
|
+
TFrom
|
|
1591
|
+
>
|
|
1592
|
+
> = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href"> & {
|
|
1593
|
+
from?: TFrom;
|
|
1594
|
+
href?: THref;
|
|
1595
|
+
to?: THref;
|
|
1596
|
+
prefetch?: boolean;
|
|
1597
|
+
fresh?: boolean;
|
|
1598
|
+
} & LinkParamsPropsForFrom<
|
|
1599
|
+
[NoInfer<TFrom>] extends [undefined] ? TDefaultFrom : NoInfer<TFrom>,
|
|
1600
|
+
NoInfer<THref>
|
|
1601
|
+
>;
|
|
671
1602
|
|
|
1603
|
+
export type ScopedLinkComponent<TDefaultFrom extends string> = <
|
|
1604
|
+
TFrom extends DinouFromRoute | undefined = undefined,
|
|
1605
|
+
THref extends ScopedLinkTargetForFrom<TDefaultFrom, TFrom> = ScopedLinkTargetForFrom<
|
|
1606
|
+
TDefaultFrom,
|
|
1607
|
+
TFrom
|
|
1608
|
+
>
|
|
1609
|
+
>(
|
|
1610
|
+
props: ScopedLinkProps<TDefaultFrom, TFrom, THref>
|
|
1611
|
+
) => ReactNode;
|