@ultimat3/render 31.24.0 → 31.26.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/README.md CHANGED
@@ -636,7 +636,7 @@ a job boundary the class is gone and the `code` is what survives — match on th
636
636
  | `island`, `islandCollector` | one interactive component on a static page |
637
637
  | `asset`, `setAssetResolver`, `assetPathProblem`, `AssetPath` | `asset('assets/x.avif')` → the content-hashed URL of a public site file; the table is the CLI's ([Static Assets](../../wiki/Static-Assets.md)) |
638
638
  | `MODE_SPECS`, `assertModeShape`, `assertModeInvariants` | the mode invariant table |
639
- | `registerRoute`, `describePages`, `routeFor`, `routePathFromFile` | the route table |
639
+ | `registerRoute`, `describePages`, `routeFor`, `routePathFromFile` | the route table; `routeSnapshot()` / `restoreRoutes(snapshot)` put it back exactly (tests — `@ultimat3/testing`'s file boundary) |
640
640
  | `registerMountedRoutes`, `RouteMount`, `RouteMountInput`, `MountedRouteInput` | routes a package mounts with no surface file: listed by `describePages()` with `mount: { by, permissions }`, absent from `routeEntries()` |
641
641
  | `checkSurfaceBoundary`, `surfaceOf` | the hard boundary |
642
642
  | `renderStatic`†, `enumeratePrerender`† | build-time render, content hashing |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/render",
3
- "version": "31.24.0",
3
+ "version": "31.26.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.24.0",
56
- "@ultimat3/core": "31.24.0",
57
- "@ultimat3/http": "31.24.0",
58
- "@ultimat3/i18n": "31.24.0",
59
- "@ultimat3/schema": "31.24.0",
60
- "@ultimat3/seo": "31.24.0",
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",
61
61
  "sass": "1.106.1"
62
62
  }
63
63
  }
@@ -0,0 +1,15 @@
1
+ // Whether one URL path segment decodes: the answer to a malformed percent-escape on this side of
2
+ // the wire. Split from `registry.ts`, which re-exports it.
3
+
4
+ /**
5
+ * `undefined` for a malformed percent-escape: `decodeURIComponent('%zz')` throws a bare `URIError`
6
+ * where a router already has an answer, "no match". The one answer on this side of the wire to
7
+ * "is this segment decodable?" (`@ultimat3/http`'s trie serves requests, `stages.ts`).
8
+ */
9
+ export function decodeSegment(value: string): string | undefined {
10
+ try {
11
+ return decodeURIComponent(value);
12
+ } catch {
13
+ return undefined;
14
+ }
15
+ }
package/src/index.ts CHANGED
@@ -158,6 +158,7 @@ export type {
158
158
  RouteEntry,
159
159
  RouteMount,
160
160
  RouteMountInput,
161
+ RouteSnapshot,
161
162
  } from './registry';
162
163
  export {
163
164
  clearRoutes,
@@ -165,9 +166,11 @@ export {
165
166
  ROUTE_FILENAME,
166
167
  registerMountedRoutes,
167
168
  registerRoute,
169
+ restoreRoutes,
168
170
  routeEntries,
169
171
  routeFor,
170
172
  routePathFromFile,
173
+ routeSnapshot,
171
174
  } from './registry';
172
175
  export type {
173
176
  InvalidateMode,
package/src/registry.ts CHANGED
@@ -14,7 +14,12 @@ import {
14
14
  SurfaceBoundaryError,
15
15
  } from './errors';
16
16
  import { assertModeInvariants, defaultIslandBudget } from './modes';
17
- import type { MountedRouteInput, RouteMount, RouteMountInput } from './mounted-routes';
17
+ import type {
18
+ MountedRoute,
19
+ MountedRouteInput,
20
+ RouteMount,
21
+ RouteMountInput,
22
+ } from './mounted-routes';
18
23
  import {
19
24
  claimedBy,
20
25
  clearMountedRoutes,
@@ -36,6 +41,8 @@ import { locateSurface } from './surfaces';
36
41
  * The one filename a route may carry, per route surface. Keyed by `RouteSurface`, so both rows are
37
42
  * MANDATORY: a dropped row would read as `undefined` in `assertRouteFilename`.
38
43
  */
44
+ export { decodeSegment } from './decode-segment'; // split out at the line ceiling
45
+
39
46
  export const ROUTE_FILENAME = Object.freeze<Record<RouteSurface, string>>({
40
47
  site: 'page.tsx',
41
48
  app: 'page.tsx',
@@ -359,6 +366,33 @@ export function clearRoutes(): void {
359
366
  described = undefined;
360
367
  }
361
368
 
369
+ /** The whole table: what `restoreRoutes` puts back. Test seam (`@ultimat3/testing`'s boundary). */
370
+ export interface RouteSnapshot {
371
+ readonly routes: readonly (readonly [string, RouteEntry, RouteConfig | undefined])[];
372
+ readonly patterns: readonly (readonly [string, string])[];
373
+ readonly mounted: readonly MountedRoute[];
374
+ }
375
+
376
+ export const routeSnapshot = (): RouteSnapshot => ({
377
+ routes: [...routes].map(([path, entry]) => [path, entry, declaredConfigs.get(path)] as const),
378
+ patterns: [...patternsByFile],
379
+ mounted: mountedRoutes(),
380
+ });
381
+
382
+ /** Exactly `snapshot` again — a REPLACE: a module-scope route never registers twice. */
383
+ export function restoreRoutes(snapshot: RouteSnapshot): void {
384
+ clearRoutes();
385
+ for (const [path, entry, config] of snapshot.routes) {
386
+ routes.set(path, entry);
387
+ if (config !== undefined) declaredConfigs.set(path, config);
388
+ }
389
+ for (const [file, path] of snapshot.patterns) patternsByFile.set(file, path);
390
+ const byMount = new Map<RouteMountInput, MountedRoute[]>();
391
+ for (const route of snapshot.mounted)
392
+ byMount.set(route.mount, [...(byMount.get(route.mount) ?? []), route]);
393
+ for (const [mount, set] of byMount) setMountedRoutes(mount, set);
394
+ }
395
+
362
396
  export function routeCount(): number {
363
397
  return routes.size;
364
398
  }
@@ -464,20 +498,3 @@ function isPersonal(config: RouteConfig): boolean {
464
498
  if (cache === undefined) return false;
465
499
  return cache === 'no-store' || cache.mode === 'no-store' || cache.mode === 'private';
466
500
  }
467
-
468
- /**
469
- * `undefined` for a malformed percent-escape. A pathname is whatever the client typed, and
470
- * `decodeURIComponent('%zz')` throws a bare `URIError` — no code, no fix line — where a router
471
- * already has an answer for "this branch does not match".
472
- *
473
- * Still exported after this package's own `matchRoute` was deleted for `@ultimat3/http`'s trie
474
- * (`stages.ts`): it is the one answer to "is this segment decodable?" on this side of the wire,
475
- * and a second copy of it is how one of the two ends up throwing where the other 404s.
476
- */
477
- export function decodeSegment(value: string): string | undefined {
478
- try {
479
- return decodeURIComponent(value);
480
- } catch {
481
- return undefined;
482
- }
483
- }