@ultimat3/render 31.26.0 → 31.27.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/render",
3
- "version": "31.26.0",
3
+ "version": "31.27.0",
4
4
  "description": "The route primitive and the five render modes: static, isr, ssr, stream, spa.",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -52,12 +52,12 @@
52
52
  "test": "bun test"
53
53
  },
54
54
  "dependencies": {
55
- "@ultimat3/cache": "31.26.0",
56
- "@ultimat3/core": "31.26.0",
57
- "@ultimat3/http": "31.26.0",
58
- "@ultimat3/i18n": "31.26.0",
59
- "@ultimat3/schema": "31.26.0",
60
- "@ultimat3/seo": "31.26.0",
55
+ "@ultimat3/cache": "31.27.0",
56
+ "@ultimat3/core": "31.27.0",
57
+ "@ultimat3/http": "31.27.0",
58
+ "@ultimat3/i18n": "31.27.0",
59
+ "@ultimat3/schema": "31.27.0",
60
+ "@ultimat3/seo": "31.27.0",
61
61
  "sass": "1.106.1"
62
62
  }
63
63
  }
package/src/registry.ts CHANGED
@@ -7,12 +7,7 @@
7
7
 
8
8
  import type { HydrateStrategy, OfflineStrategy, RenderMode } from '@ultimat3/core';
9
9
  import { byCodeUnit } from './code-unit-order';
10
- import {
11
- RouteDuplicateError,
12
- RouteFileInvalidError,
13
- RouteUnnormalizedError,
14
- SurfaceBoundaryError,
15
- } from './errors';
10
+ import { RouteDuplicateError, RouteUnnormalizedError } from './errors';
16
11
  import { assertModeInvariants, defaultIslandBudget } from './modes';
17
12
  import type {
18
13
  MountedRoute,
@@ -32,24 +27,13 @@ import { assertPurgeableTags } from './revalidate-shape';
32
27
  import type { InvalidateMode, RouteConfig, RouteData } from './route';
33
28
  import { isRouteConfig, routeTagKeys } from './route';
34
29
  import type { RouteComponent } from './route-component';
30
+ import { routePathFromFile } from './route-path';
35
31
  import type { CompiledPattern } from './route-pattern';
36
32
  import { compilePattern } from './route-pattern';
37
33
  import type { RouteSurface, Surface } from './surfaces';
38
- import { locateSurface } from './surfaces';
39
34
 
40
- /**
41
- * The one filename a route may carry, per route surface. Keyed by `RouteSurface`, so both rows are
42
- * MANDATORY: a dropped row would read as `undefined` in `assertRouteFilename`.
43
- */
44
35
  export { decodeSegment } from './decode-segment'; // split out at the line ceiling
45
-
46
- export const ROUTE_FILENAME = Object.freeze<Record<RouteSurface, string>>({
47
- site: 'page.tsx',
48
- app: 'page.tsx',
49
- });
50
-
51
- /** Stems that already meant "this directory", so the repair is a rename in place, not a new folder. */
52
- const DIRECTORY_STEMS = new Set(['index', 'page', 'route']);
36
+ export { ROUTE_FILENAME, routePathFromFile } from './route-path'; // split out at the line ceiling
53
37
 
54
38
  export interface RouteEntry<TData = RouteData> {
55
39
  readonly file: string;
@@ -111,122 +95,6 @@ export interface RouteDescriptor {
111
95
 
112
96
  export type { MountedRouteInput, RouteMount, RouteMountInput } from './mounted-routes';
113
97
 
114
- /**
115
- * `apps/web/site/blog/[slug]/page.tsx` → `{ surface: 'site', path: '/blog/:slug' }`.
116
- *
117
- * The URL is the **directory** path under the surface; the filename names the kind of file, never
118
- * a URL segment. Anything else is `X_ROUTE_FILE_INVALID` — one spelling per surface, so an agent
119
- * reading a folder knows which file is the route without opening any of them.
120
- *
121
- * | file | path |
122
- * |---|---|
123
- * | `site/page.tsx` | `/` |
124
- * | `site/pricing/page.tsx` | `/pricing` |
125
- * | `site/(marketing)/about/page.tsx` | `/about` |
126
- * | `site/blog/[slug]/page.tsx` | `/blog/:slug` |
127
- * | `site/docs/[...path]/page.tsx` | `/docs/*path` |
128
- * | `app/dashboard/page.tsx` | `/dashboard` |
129
- */
130
- export function routePathFromFile(file: string): { surface: RouteSurface; path: string } {
131
- const normalized = file.replace(/\\/g, '/').replace(/^\.\//, '');
132
- // One reader of the surface segment, and it answers WHERE as well as WHICH. Slicing at
133
- // `indexOf('app/')` instead matched inside `myapp/`, so `apps/myapp/app/page.tsx` resolved to
134
- // `/app` rather than `/` — the surface came from an anchored regex and the URL from a substring.
135
- const located = locateSurface(normalized);
136
- if (located === null) {
137
- throw new SurfaceBoundaryError(
138
- `${file} is not inside a surface directory, so it has no URL and no bundle graph`,
139
- `move ${file} under site/ or app/, named page.tsx`,
140
- );
141
- }
142
- const surface = routeSurfaceOf(normalized, located.surface);
143
-
144
- const rawSegments = located.rest.split('/').filter((s) => s.length > 0);
145
- assertRouteFilename(normalized, surface, rawSegments[rawSegments.length - 1]);
146
-
147
- const urlSegments = rawSegments
148
- .slice(0, -1)
149
- .filter((s) => !(s.startsWith('(') && s.endsWith(')')))
150
- .map(toUrlSegment);
151
-
152
- const path = `/${urlSegments.join('/')}`.replace(/\/+$/, '') || '/';
153
- return { surface, path };
154
- }
155
-
156
- /**
157
- * POSIX single-quotes a filesystem-derived operand for a `fix:` command: close the quote, escape
158
- * an embedded quote as `'\''`, reopen it. A `fix:` is copied and run verbatim (axiom 4), so a route
159
- * filename carrying a space, an apostrophe or a shell metacharacter must not change what runs.
160
- */
161
- const shellQuote = (value: string): string => `'${value.replaceAll("'", "'\\''")}'`;
162
-
163
- /**
164
- * Only `site/` and `app/` hold route files. `shared/` is a leaf of helpers with no URL; `api/` is
165
- * the action and query projections `defineApi()` collects — a wire format an action cannot speak
166
- * is a plain HTTP route in the `routes` runtime override, never a file under `api/`.
167
- */
168
- function routeSurfaceOf(file: string, surface: Surface): RouteSurface {
169
- if (surface === 'shared') {
170
- throw new RouteFileInvalidError(
171
- `${file} is under shared/, which is a leaf of helpers with no URL — a route cannot live there`,
172
- `move ${file} under site/ or app/, named page.tsx`,
173
- );
174
- }
175
- if (surface === 'api') {
176
- throw new RouteFileInvalidError(
177
- `${file} is under api/, which holds no route file: api/ is the actions and queries defineApi() collects`,
178
- `JSON in and out: replace ${file} with an action (x g action <name>) collected by defineApi() in api/index.ts. Another wire format (a webhook, an OAuth endpoint): delete ${file} and add a plain HTTP route to the routes array exported as runtime from apps/<app>/runtime.ts`,
179
- );
180
- }
181
- return surface;
182
- }
183
-
184
- /**
185
- * Enforced rather than documented (axiom 3): a convention that is not a build error is not a
186
- * convention. The fix is the move that makes the file a route, spelled out — the directory the
187
- * author already meant, plus the one filename that surface accepts.
188
- */
189
- function assertRouteFilename(
190
- file: string,
191
- surface: RouteSurface,
192
- basename: string | undefined,
193
- ): void {
194
- const expected = ROUTE_FILENAME[surface];
195
- if (basename === expected) return;
196
-
197
- // The directory the author meant is the file's own path minus its extension: `site/pricing.tsx`
198
- // was always trying to be `/pricing`, so `site/pricing/page.tsx` is the move, not a guess.
199
- // `index`, `page` and `route` are the exception — each already means "this directory", so the
200
- // rename happens in place and no directory is created.
201
- const stem = file.replace(/\.(tsx|ts|jsx|js)$/, '');
202
- const dir = stem.slice(0, stem.lastIndexOf('/'));
203
- const inPlace = DIRECTORY_STEMS.has(stem.slice(dir.length + 1));
204
- const target = inPlace ? `${dir}/${expected}` : `${stem}/${expected}`;
205
- // Plain `mv`, never `git mv`. `x new --no-git` scaffolds a tree with no repository, and there the
206
- // shipped `git mv` answered `fatal: not a git repository` — a fix line that fails is worse than
207
- // no fix line, because the reader debugs git instead of moving the file. `mv` works in both
208
- // cases: git detects the rename at `git add` time, so the only thing given up is a nicety, and
209
- // the instruction is the same one either way. `-n` keeps the one guarantee `git mv` did carry:
210
- // an author who adds the correct `site/pricing/page.tsx` and leaves `site/pricing.tsx` behind is
211
- // reported against the stale file, and `target` is then the GOOD file — a clobber deletes a
212
- // working route, and this fix line is pasted unread.
213
- throw new RouteFileInvalidError(
214
- `${file} is a route on the ${surface} surface, so it must be named ${expected}: the URL is the ` +
215
- 'directory path and the filename names the kind of file',
216
- inPlace
217
- ? `mv -n -- ${shellQuote(file)} ${shellQuote(target)}`
218
- : `mkdir -p -- ${shellQuote(stem)} && mv -n -- ${shellQuote(file)} ${shellQuote(target)}`,
219
- );
220
- }
221
-
222
- function toUrlSegment(segment: string): string {
223
- const catchAll = /^\[\.\.\.(.+)\]$/.exec(segment);
224
- if (catchAll?.[1] !== undefined) return `*${catchAll[1]}`;
225
- const dynamic = /^\[(.+)\]$/.exec(segment);
226
- if (dynamic?.[1] !== undefined) return `:${dynamic[1]}`;
227
- return segment;
228
- }
229
-
230
98
  const routes = new Map<string, RouteEntry>();
231
99
  /** route file → its URL pattern: what `render.page` reports a component's render under. */
232
100
  const patternsByFile = new Map<string, string>();
@@ -0,0 +1,136 @@
1
+ // File path → URL for a route file under `site/` or `app/`: the one spelling each surface accepts,
2
+ // refused with the exact move that makes the file a route. Split out of `registry.ts`, which keeps
3
+ // the table itself.
4
+
5
+ import { RouteFileInvalidError, SurfaceBoundaryError } from './errors';
6
+ import type { RouteSurface, Surface } from './surfaces';
7
+ import { locateSurface } from './surfaces';
8
+
9
+ /**
10
+ * The one filename a route may carry, per route surface. Keyed by `RouteSurface`, so both rows are
11
+ * MANDATORY: a dropped row would read as `undefined` in `assertRouteFilename`.
12
+ */
13
+
14
+ export const ROUTE_FILENAME = Object.freeze<Record<RouteSurface, string>>({
15
+ site: 'page.tsx',
16
+ app: 'page.tsx',
17
+ });
18
+
19
+ /** Stems that already meant "this directory", so the repair is a rename in place, not a new folder. */
20
+ const DIRECTORY_STEMS = new Set(['index', 'page', 'route']);
21
+
22
+ /**
23
+ * `apps/web/site/blog/[slug]/page.tsx` → `{ surface: 'site', path: '/blog/:slug' }`.
24
+ *
25
+ * The URL is the **directory** path under the surface; the filename names the kind of file, never
26
+ * a URL segment. Anything else is `X_ROUTE_FILE_INVALID` — one spelling per surface, so an agent
27
+ * reading a folder knows which file is the route without opening any of them.
28
+ *
29
+ * | file | path |
30
+ * |---|---|
31
+ * | `site/page.tsx` | `/` |
32
+ * | `site/pricing/page.tsx` | `/pricing` |
33
+ * | `site/(marketing)/about/page.tsx` | `/about` |
34
+ * | `site/blog/[slug]/page.tsx` | `/blog/:slug` |
35
+ * | `site/docs/[...path]/page.tsx` | `/docs/*path` |
36
+ * | `app/dashboard/page.tsx` | `/dashboard` |
37
+ */
38
+ export function routePathFromFile(file: string): { surface: RouteSurface; path: string } {
39
+ const normalized = file.replace(/\\/g, '/').replace(/^\.\//, '');
40
+ // One reader of the surface segment, and it answers WHERE as well as WHICH. Slicing at
41
+ // `indexOf('app/')` instead matched inside `myapp/`, so `apps/myapp/app/page.tsx` resolved to
42
+ // `/app` rather than `/` — the surface came from an anchored regex and the URL from a substring.
43
+ const located = locateSurface(normalized);
44
+ if (located === null) {
45
+ throw new SurfaceBoundaryError(
46
+ `${file} is not inside a surface directory, so it has no URL and no bundle graph`,
47
+ `move ${file} under site/ or app/, named page.tsx`,
48
+ );
49
+ }
50
+ const surface = routeSurfaceOf(normalized, located.surface);
51
+
52
+ const rawSegments = located.rest.split('/').filter((s) => s.length > 0);
53
+ assertRouteFilename(normalized, surface, rawSegments[rawSegments.length - 1]);
54
+
55
+ const urlSegments = rawSegments
56
+ .slice(0, -1)
57
+ .filter((s) => !(s.startsWith('(') && s.endsWith(')')))
58
+ .map(toUrlSegment);
59
+
60
+ const path = `/${urlSegments.join('/')}`.replace(/\/+$/, '') || '/';
61
+ return { surface, path };
62
+ }
63
+
64
+ /**
65
+ * POSIX single-quotes a filesystem-derived operand for a `fix:` command: close the quote, escape
66
+ * an embedded quote as `'\''`, reopen it. A `fix:` is copied and run verbatim (axiom 4), so a route
67
+ * filename carrying a space, an apostrophe or a shell metacharacter must not change what runs.
68
+ */
69
+ const shellQuote = (value: string): string => `'${value.replaceAll("'", "'\\''")}'`;
70
+
71
+ /**
72
+ * Only `site/` and `app/` hold route files. `shared/` is a leaf of helpers with no URL; `api/` is
73
+ * the action and query projections `defineApi()` collects — a wire format an action cannot speak
74
+ * is a plain HTTP route in the `routes` runtime override, never a file under `api/`.
75
+ */
76
+ function routeSurfaceOf(file: string, surface: Surface): RouteSurface {
77
+ if (surface === 'shared') {
78
+ throw new RouteFileInvalidError(
79
+ `${file} is under shared/, which is a leaf of helpers with no URL — a route cannot live there`,
80
+ `move ${file} under site/ or app/, named page.tsx`,
81
+ );
82
+ }
83
+ if (surface === 'api') {
84
+ throw new RouteFileInvalidError(
85
+ `${file} is under api/, which holds no route file: api/ is the actions and queries defineApi() collects`,
86
+ `JSON in and out: replace ${file} with an action (x g action <name>) collected by defineApi() in api/index.ts. Another wire format (a webhook, an OAuth endpoint): delete ${file} and add a plain HTTP route to the routes array exported as runtime from apps/<app>/runtime.ts`,
87
+ );
88
+ }
89
+ return surface;
90
+ }
91
+
92
+ /**
93
+ * Enforced rather than documented (axiom 3): a convention that is not a build error is not a
94
+ * convention. The fix is the move that makes the file a route, spelled out — the directory the
95
+ * author already meant, plus the one filename that surface accepts.
96
+ */
97
+ function assertRouteFilename(
98
+ file: string,
99
+ surface: RouteSurface,
100
+ basename: string | undefined,
101
+ ): void {
102
+ const expected = ROUTE_FILENAME[surface];
103
+ if (basename === expected) return;
104
+
105
+ // The directory the author meant is the file's own path minus its extension: `site/pricing.tsx`
106
+ // was always trying to be `/pricing`, so `site/pricing/page.tsx` is the move, not a guess.
107
+ // `index`, `page` and `route` are the exception — each already means "this directory", so the
108
+ // rename happens in place and no directory is created.
109
+ const stem = file.replace(/\.(tsx|ts|jsx|js)$/, '');
110
+ const dir = stem.slice(0, stem.lastIndexOf('/'));
111
+ const inPlace = DIRECTORY_STEMS.has(stem.slice(dir.length + 1));
112
+ const target = inPlace ? `${dir}/${expected}` : `${stem}/${expected}`;
113
+ // Plain `mv`, never `git mv`. `x new --no-git` scaffolds a tree with no repository, and there the
114
+ // shipped `git mv` answered `fatal: not a git repository` — a fix line that fails is worse than
115
+ // no fix line, because the reader debugs git instead of moving the file. `mv` works in both
116
+ // cases: git detects the rename at `git add` time, so the only thing given up is a nicety, and
117
+ // the instruction is the same one either way. `-n` keeps the one guarantee `git mv` did carry:
118
+ // an author who adds the correct `site/pricing/page.tsx` and leaves `site/pricing.tsx` behind is
119
+ // reported against the stale file, and `target` is then the GOOD file — a clobber deletes a
120
+ // working route, and this fix line is pasted unread.
121
+ throw new RouteFileInvalidError(
122
+ `${file} is a route on the ${surface} surface, so it must be named ${expected}: the URL is the ` +
123
+ 'directory path and the filename names the kind of file',
124
+ inPlace
125
+ ? `mv -n -- ${shellQuote(file)} ${shellQuote(target)}`
126
+ : `mkdir -p -- ${shellQuote(stem)} && mv -n -- ${shellQuote(file)} ${shellQuote(target)}`,
127
+ );
128
+ }
129
+
130
+ function toUrlSegment(segment: string): string {
131
+ const catchAll = /^\[\.\.\.(.+)\]$/.exec(segment);
132
+ if (catchAll?.[1] !== undefined) return `*${catchAll[1]}`;
133
+ const dynamic = /^\[(.+)\]$/.exec(segment);
134
+ if (dynamic?.[1] !== undefined) return `:${dynamic[1]}`;
135
+ return segment;
136
+ }