@ultimat3/render 31.45.0 → 31.47.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
@@ -12,17 +12,32 @@ The `route` primitive and the four render modes.
12
12
  | `stream` | static shell flushed instantly, holes streamed | **default for app pages** |
13
13
 
14
14
  ```ts
15
+ import { tag } from '@ultimat3/cache';
16
+ import { defineRoute } from '@ultimat3/render';
17
+ import { ld } from '@ultimat3/seo';
18
+
19
+ interface Post {
20
+ readonly title: string;
21
+ readonly excerpt: string;
22
+ readonly cover: string;
23
+ readonly publishedAt: string;
24
+ readonly author: { readonly name: string };
25
+ }
26
+ declare function listPostSlugs(): Promise<readonly string[]>;
27
+ declare function loadPost(slug: string): Promise<Post>;
28
+
15
29
  export const config = defineRoute({
16
30
  render: 'isr', // static | isr | ssr | stream
17
31
  revalidate: { tags: [tag.post] },
18
- prerender: () => db.posts.slugs(),
32
+ prerender: () => listPostSlugs(),
19
33
  offline: 'precache', // precache | runtime | network-only
20
34
  hydrate: 'visible', // idle | visible | interaction | never
21
35
  budget: { js: '40kb' },
22
- load: ({ params }) => db.posts.bySlug(params.slug), // once per render
36
+ load: ({ params }) => loadPost(params['slug'] ?? ''), // once per render
23
37
  meta: ({ data, url }) => ({ title: data.title, description: data.excerpt,
24
38
  og: { image: data.cover }, canonical: url,
25
- ld: ld.Article(data) }),
39
+ ld: [ld.Article({ headline: data.title, datePublished: data.publishedAt,
40
+ author: data.author })] }),
26
41
  });
27
42
 
28
43
  export function Page(props: { data: Post }) { /* the SAME object meta was given */ }
@@ -153,6 +168,8 @@ declaration receives, all four required:
153
168
  ```ts
154
169
  import type { RouteConfig, RouteMetaContext } from '@ultimat3/render';
155
170
 
171
+ type Post = { readonly id: string; readonly orgId: string; readonly title: string };
172
+
156
173
  declare const config: RouteConfig<Post>;
157
174
  declare const ctx: RouteMetaContext<Post>; // { data, params, url, t }
158
175
 
@@ -298,6 +315,8 @@ types-only.
298
315
  with a plan toggle. The page stays `render: 'static'`; the modal is the only JavaScript on it.
299
316
 
300
317
  ```tsx
318
+ import { defineRoute, island } from '@ultimat3/render';
319
+
301
320
  const ContactModal = island({ src: './contact-modal.island.tsx', props: ['subject'] });
302
321
 
303
322
  export const config = defineRoute({
@@ -489,6 +508,16 @@ by the request that carries it.
489
508
  ### It counts against the route's budget
490
509
 
491
510
  ```ts
511
+ import { hydrateRuntime, islandCollector } from '@ultimat3/render';
512
+ import { renderToHtml } from '@ultimat3/render/server';
513
+
514
+ type CollectorInput = Parameters<typeof islandCollector>[0];
515
+ declare const file: CollectorInput['file'];
516
+ declare const resolve: NonNullable<CollectorInput['resolve']>;
517
+ declare const config: { readonly hydrate: CollectorInput['hydrate'] };
518
+ declare const page: Parameters<typeof renderToHtml>[0];
519
+ declare const document: { body: string };
520
+
492
521
  const collector = islandCollector({ file, hydrate: config.hydrate, resolve });
493
522
  const html = await renderToHtml(page, { islands: collector });
494
523
  document.body += hydrateRuntime(collector.directives); // the one thing left to remember
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/render",
3
- "version": "31.45.0",
3
+ "version": "31.47.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.45.0",
56
- "@ultimat3/core": "31.45.0",
57
- "@ultimat3/http": "31.45.0",
58
- "@ultimat3/i18n": "31.45.0",
59
- "@ultimat3/schema": "31.45.0",
60
- "@ultimat3/seo": "31.45.0",
55
+ "@ultimat3/cache": "31.47.0",
56
+ "@ultimat3/core": "31.47.0",
57
+ "@ultimat3/http": "31.47.0",
58
+ "@ultimat3/i18n": "31.47.0",
59
+ "@ultimat3/schema": "31.47.0",
60
+ "@ultimat3/seo": "31.47.0",
61
61
  "sass": "1.107.1"
62
62
  }
63
63
  }
@@ -5,6 +5,8 @@
5
5
  * controller and nothing else.
6
6
  */
7
7
 
8
+ import { isJsonObject } from '@ultimat3/core/page';
9
+
8
10
  /** The router's own slot in `history.state`, beside whatever an app keeps there. */
9
11
  export const STATE_KEY = '__x';
10
12
 
@@ -21,13 +23,10 @@ export type HistoryMode = 'push' | 'replace' | 'none' | undefined;
21
23
 
22
24
  export const withoutFragment = (url: string): string => url.split('#')[0] ?? url;
23
25
 
24
- const isRecord = (value: unknown): value is Record<string, unknown> =>
25
- typeof value === 'object' && value !== null;
26
-
27
26
  /** The router's entry in a `history.state`, or `undefined` for an entry an app pushed. */
28
27
  export const entryOf = (state: unknown): EntryState | undefined => {
29
- const entry = isRecord(state) ? state[STATE_KEY] : undefined;
30
- return isRecord(entry) && typeof entry['doc'] === 'string'
28
+ const entry = isJsonObject(state) ? state[STATE_KEY] : undefined;
29
+ return isJsonObject(entry) && typeof entry['doc'] === 'string'
31
30
  ? (entry as unknown as EntryState)
32
31
  : undefined;
33
32
  };
@@ -1,16 +1,13 @@
1
1
  // Single responsibility: what a route's `prerender()` answered, normalised — every page as its
2
2
  // params, plus what the page said about itself for a sitemap (`lastmod`, `locales`).
3
3
 
4
- import { renderCauseValue, renderThrowable } from '@ultimat3/core';
4
+ import { isJsonObject, renderCauseValue, renderThrowable } from '@ultimat3/core';
5
5
  import { PrerenderFailedError } from './errors';
6
6
  import type { RouteEntry } from './registry';
7
7
  import type { PrerenderEntry, RouteParams } from './route';
8
8
 
9
9
  const ENTRY_KEYS: readonly string[] = ['params', 'lastmod', 'locales'];
10
10
 
11
- const isRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>
12
- typeof value === 'object' && value !== null && !Array.isArray(value);
13
-
14
11
  /**
15
12
  * Is `item` the ENTRY form — `{ params: { … }, lastmod?, locales? }` — rather than a params object?
16
13
  * Decided by `params` holding an object: a param VALUE is always a string, so `{ params: 'a' }` on a
@@ -20,7 +17,7 @@ const isRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>
20
17
  const paramsShape = (keys: readonly string[]): string =>
21
18
  `{ ${keys.map((key) => `${key}: '…'`).join(', ')} }`;
22
19
 
23
- const isEntry = (item: Readonly<Record<string, unknown>>): boolean => isRecord(item['params']);
20
+ const isEntry = (item: Readonly<Record<string, unknown>>): boolean => isJsonObject(item['params']);
24
21
 
25
22
  function entryOf(entry: RouteEntry, item: Readonly<Record<string, unknown>>): PrerenderEntry {
26
23
  const refuse = (problem: string): never => {
@@ -96,7 +93,7 @@ export async function enumeratePrerenderEntries(
96
93
  return { params: { [only]: item } };
97
94
  }
98
95
  // A `null` reached `Object.hasOwn` in `static-path.ts` and left the build as a bare `TypeError`.
99
- if (!isRecord(item)) {
96
+ if (!isJsonObject(item)) {
100
97
  throw new PrerenderFailedError(
101
98
  `prerender() for ${entry.path} returned ${renderCauseValue(item)} as one of its items, which is neither a params object nor a string`,
102
99
  `prerender: () => [${paramsShape(keys)}] // in ${entry.file}: params objects, or strings for a one-param route`,
@@ -3,11 +3,9 @@
3
3
  * totally — anything else is a miss, never a cast.
4
4
  */
5
5
 
6
+ import { isJsonObject } from '@ultimat3/core';
6
7
  import type { IsrEntry } from './render-isr-store';
7
8
 
8
- const isRecord = (value: unknown): value is Record<string, unknown> =>
9
- typeof value === 'object' && value !== null && !Array.isArray(value);
10
-
11
9
  /**
12
10
  * The stored text as an entry for `path`, or `undefined`. A shared store holds what another
13
11
  * release, another app or a hand wrote: an object whose `path` is not the key it sits under is
@@ -20,7 +18,7 @@ export function parseIsrEntry(text: string, path: string): IsrEntry | undefined
20
18
  } catch {
21
19
  return undefined;
22
20
  }
23
- if (!isRecord(value)) return undefined;
21
+ if (!isJsonObject(value)) return undefined;
24
22
  const { html, hash, generatedAt, ttlMs, stale, status } = value;
25
23
  if (value['path'] !== path || typeof html !== 'string' || typeof hash !== 'string') {
26
24
  return undefined;