@decocms/blocks 8.11.0 → 8.12.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.
Files changed (60) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/protocol/conformance/blockMetaVectors.json +80 -0
  5. package/dist/protocol/index.d.ts +5 -2
  6. package/dist/protocol/index.d.ts.map +1 -1
  7. package/dist/protocol/index.js +5 -2
  8. package/dist/protocol/index.js.map +1 -1
  9. package/dist/v8/blockMeta.d.ts +33 -4
  10. package/dist/v8/blockMeta.d.ts.map +1 -1
  11. package/dist/v8/blockMeta.js +70 -13
  12. package/dist/v8/blockMeta.js.map +1 -1
  13. package/dist/v8/client.d.ts +6 -4
  14. package/dist/v8/client.d.ts.map +1 -1
  15. package/dist/v8/client.js +26 -70
  16. package/dist/v8/client.js.map +1 -1
  17. package/dist/v8/cms.d.ts.map +1 -1
  18. package/dist/v8/cms.js +1 -2
  19. package/dist/v8/cms.js.map +1 -1
  20. package/dist/v8/contentIndex.d.ts +18 -7
  21. package/dist/v8/contentIndex.d.ts.map +1 -1
  22. package/dist/v8/contentIndex.js +46 -17
  23. package/dist/v8/contentIndex.js.map +1 -1
  24. package/dist/v8/draftChanges.d.ts.map +1 -1
  25. package/dist/v8/draftChanges.js +4 -1
  26. package/dist/v8/draftChanges.js.map +1 -1
  27. package/dist/v8/index.d.ts +1 -1
  28. package/dist/v8/index.d.ts.map +1 -1
  29. package/dist/v8/remoteLoader.d.ts +4 -2
  30. package/dist/v8/remoteLoader.d.ts.map +1 -1
  31. package/dist/v8/remoteLoader.js +13 -3
  32. package/dist/v8/remoteLoader.js.map +1 -1
  33. package/dist/v8/types.d.ts +47 -7
  34. package/dist/v8/types.d.ts.map +1 -1
  35. package/package.json +1 -1
  36. package/skills/deco-make-editable/SKILL.md +1 -1
  37. package/skills/deco-make-editable/references/content-shapes.md +14 -9
  38. package/skills/deco-nextjs-site/references/rendering.md +6 -5
  39. package/skills/deco-site-authoring/references/pages.md +6 -4
  40. package/skills/deco-site-workflow/SKILL.md +12 -3
  41. package/skills/deco-site-workflow/references/cli-reference.md +2 -0
  42. package/skills/deco-v7-to-v8-migration/SKILL.md +2 -1
  43. package/skills/deco-v7-to-v8-migration/references/hosted-releases.md +1 -1
  44. package/skills/deco-v7-to-v8-migration/references/nextjs.md +2 -2
  45. package/skills/deco-v7-to-v8-migration/references/verify.md +3 -0
  46. package/skills/deco-v7-to-v8-migration/scripts/checkContentReads.ts +32 -0
  47. package/skills/deco-v7-to-v8-migration/scripts/contentReads.ts +157 -0
  48. package/skills/deco-v7-to-v8-migration/scripts/imports.ts +1 -1
  49. package/skills/deco-v7-to-v8-migration/scripts/migrate.ts +4 -0
  50. package/src/index.ts +1 -1
  51. package/src/protocol/conformance/blockMetaVectors.json +80 -0
  52. package/src/protocol/index.ts +8 -1
  53. package/src/v8/blockMeta.ts +75 -11
  54. package/src/v8/client.ts +32 -77
  55. package/src/v8/cms.ts +1 -2
  56. package/src/v8/contentIndex.ts +49 -19
  57. package/src/v8/draftChanges.ts +5 -1
  58. package/src/v8/index.ts +1 -1
  59. package/src/v8/remoteLoader.ts +13 -3
  60. package/src/v8/types.ts +48 -7
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * Index entries of a hosted release (see /next/hosted-releases-internals):
3
3
  * `revisions/<id>/index.json` and `latest.json` map each block name to its
4
- * hash (`version`) plus the little metadata routing and the reference walk
5
- * need, so neither needs a block body.
4
+ * hash (`version`) plus the little metadata routing, the reference walk and
5
+ * `client.entries()` need, so none of them needs a block body.
6
6
  *
7
- * `blockMeta(body, names)` is the one helper Studio, the SDK and the CLI use
8
- * to compute that metadata, so all three write and read the same entries.
9
- * Pure, synchronous, browser-safe; its only import is the dependency-free
10
- * canonical hash (for `indexEntry`).
7
+ * `blockMeta(body, names, bodyOf?)` is the one helper Studio, the SDK and the
8
+ * CLI use to compute that metadata, so all three write and read the same
9
+ * entries. Pure, synchronous, browser-safe; its only import is the
10
+ * dependency-free canonical hash (for `indexEntry`).
11
11
  *
12
12
  * - `type`: the body's raw top-level `__resolveType`, copied without alias
13
13
  * mapping (readers map it with their alias rules).
@@ -15,12 +15,32 @@
15
15
  * - `refs`: every `__resolveType` string anywhere in the body (the top-level
16
16
  * one included, every variant, `never` and `lazy` values included) that is
17
17
  * one of `names`, deduped and sorted in code-unit order.
18
+ * - `noIndex`: `true` when the body is a page that asks search engines not to
19
+ * index it: it has a top-level string `path` and its top-level `seo` says
20
+ * `noIndexing: true`, inline or through the saved SEO block it references
21
+ * (`{ "__resolveType": "DefaultSeo" }`), which `bodyOf` looks up (see
22
+ * `seoNoIndex`). Written only when `true`.
18
23
  *
19
- * A key is present only when it has a value (`refs: []` is left out), so a
20
- * body with nothing to say gives `{}` and its entry carries no `meta`.
24
+ * A key is present only when it has a value (`refs: []` and `noIndex: false`
25
+ * are left out), so a body with nothing to say gives `{}` and its entry
26
+ * carries no `meta`.
27
+ *
28
+ * `META_VERSION` is the version of this metadata. An index says which version
29
+ * computed its entries (its top-level `metaVersion`; absent is 1). A reader
30
+ * trusts a missing `noIndex` as `false` only on an index at version 2 or
31
+ * later, and a publish that finds an older index recomputes every entry.
21
32
  */
22
33
  import { blockVersion } from "./canonical.ts";
23
34
 
35
+ /**
36
+ * The version of the metadata `blockMeta` computes: 1 is `type`, `path` and
37
+ * `refs`; 2 adds `noIndex`. An index without `metaVersion` is version 1.
38
+ */
39
+ export const META_VERSION = 2;
40
+
41
+ /** A saved block's body by name, to follow a reference (`undefined`: not known). */
42
+ export type BodyOf = (name: string) => unknown;
43
+
24
44
  /** What an index says about a block, besides its hash. */
25
45
  export interface BlockMeta {
26
46
  /** The body's raw `__resolveType`. */
@@ -29,6 +49,8 @@ export interface BlockMeta {
29
49
  path?: string;
30
50
  /** The block names the body references, deduped, in code-unit order. */
31
51
  refs?: string[];
52
+ /** `true` when the page says `noIndexing` (meta version 2); never written `false`. */
53
+ noIndex?: boolean;
32
54
  }
33
55
 
34
56
  /** One entry of a revision index. */
@@ -47,10 +69,18 @@ export type BlockIndex = Record<string, IndexEntry>;
47
69
  /** The well-known name whose body every index inlines as `data`. */
48
70
  export const INLINE_BLOCK = "CMS";
49
71
 
50
- /** The metadata of one block body; `names` are the block names of the index being built. */
72
+ /** How many saved blocks `seoNoIndex` follows, one referencing the next. */
73
+ const MAX_SEO_HOPS = 8;
74
+
75
+ /**
76
+ * The metadata of one block body. `names` are the block names of the index
77
+ * being built; `bodyOf` gives the bodies of the saved blocks a page's `seo`
78
+ * may reference (without it, only an inline `seo` counts for `noIndex`).
79
+ */
51
80
  export function blockMeta(
52
81
  body: unknown,
53
82
  names: ReadonlySet<string> | readonly string[],
83
+ bodyOf?: BodyOf,
54
84
  ): BlockMeta {
55
85
  const meta: BlockMeta = {};
56
86
  if (!isRecord(body)) return meta;
@@ -60,17 +90,51 @@ export function blockMeta(
60
90
  const found = new Set<string>();
61
91
  collectRefs(body, known, found);
62
92
  if (found.size > 0) meta.refs = [...found].sort();
93
+ if (pageNoIndex(body, bodyOf)) meta.noIndex = true;
63
94
  return meta;
64
95
  }
65
96
 
66
- /** The index entry for a block: its hash, its metadata when any, and its body when it is `CMS`. */
97
+ /**
98
+ * Whether a page body asks not to be indexed: it has a top-level string
99
+ * `path`, and `seoNoIndex(body.seo, bodyOf)`.
100
+ */
101
+ export function pageNoIndex(body: unknown, bodyOf?: BodyOf): boolean {
102
+ return isRecord(body) && typeof body.path === "string" && seoNoIndex(body.seo, bodyOf);
103
+ }
104
+
105
+ /**
106
+ * Whether a page's `seo` value says `noIndexing: true`: its own boolean
107
+ * `noIndexing` when it has one; otherwise, when its `__resolveType` is a saved
108
+ * block `bodyOf` knows (a saved SEO block such as `DefaultSeo`), that block's
109
+ * answer, following up to 8 saved blocks. Anything else (no `seo`, a variant,
110
+ * a block `bodyOf` doesn't know, a cycle) is `false`.
111
+ */
112
+ export function seoNoIndex(seo: unknown, bodyOf?: BodyOf): boolean {
113
+ let node = seo;
114
+ const seen = new Set<string>();
115
+ for (let hop = 0; hop <= MAX_SEO_HOPS; hop++) {
116
+ if (!isRecord(node)) return false;
117
+ if (typeof node.noIndexing === "boolean") return node.noIndexing;
118
+ const ref = node.__resolveType;
119
+ if (bodyOf === undefined || typeof ref !== "string" || seen.has(ref)) return false;
120
+ seen.add(ref);
121
+ node = bodyOf(ref);
122
+ }
123
+ return false;
124
+ }
125
+
126
+ /**
127
+ * The index entry for a block: its hash, its metadata when any, and its body
128
+ * when it is `CMS`. `bodyOf` as for `blockMeta`.
129
+ */
67
130
  export async function indexEntry(
68
131
  name: string,
69
132
  body: unknown,
70
133
  names: ReadonlySet<string> | readonly string[],
134
+ bodyOf?: BodyOf,
71
135
  ): Promise<IndexEntry> {
72
136
  const entry: IndexEntry = { version: await blockVersion(body) };
73
- const meta = blockMeta(body, names);
137
+ const meta = blockMeta(body, names, bodyOf);
74
138
  if (Object.keys(meta).length > 0) entry.meta = meta;
75
139
  if (name === INLINE_BLOCK) entry.data = body;
76
140
  return entry;
package/src/v8/client.ts CHANGED
@@ -8,18 +8,19 @@
8
8
  * The binding flow (see /next/routing): `routes()` → `matchRoute` →
9
9
  * `prefetch(name)` → `redirects()` → `matchRoute` → `resolve(name)`. The
10
10
  * page's subtree and the redirects block go out in one parallel wave.
11
+ * `entries(type?)` answers from the index too: what a sitemap or a lookup by
12
+ * path needs, with no body fetched.
11
13
  */
12
14
  import { keepAlive } from "./background.ts";
13
15
  import {
14
- canonicalType,
15
- namesOfType,
16
- REDIRECTS_TYPE,
16
+ entriesOf,
17
+ type IndexedContent,
17
18
  redirectsBlockOf,
18
19
  routesOf,
19
20
  walk,
20
21
  } from "./contentIndex.ts";
21
22
  import { CAMPAIGN_OVERRIDES, EXPERIMENT_OVERRIDES, type Overrides } from "./current.ts";
22
- import { errors, isResolutionError, ResolutionError } from "./errors.ts";
23
+ import { errors, isResolutionError } from "./errors.ts";
23
24
  import type { Visitor } from "./experiments.ts";
24
25
  import { isPlainObject } from "./json.ts";
25
26
  import { choosePin, type Pin, rootsOf, type Selection } from "./pin.ts";
@@ -30,6 +31,7 @@ import type {
30
31
  Blocks,
31
32
  Client,
32
33
  CMSError,
34
+ Entry,
33
35
  LegacyRedirect,
34
36
  ListOptions,
35
37
  Redirect,
@@ -58,13 +60,16 @@ interface ClientOptions {
58
60
  telemetry?: ClientTelemetry;
59
61
  }
60
62
 
63
+ /** What `client.list()` throws: it was removed, and what to read instead. */
64
+ export const LIST_REMOVED =
65
+ "[decocms/blocks] client.list() was removed in this version of @decocms/blocks: it fetched the " +
66
+ "body of every block of a type. Route with client.routes() and client.redirects() (index only); " +
67
+ "read a type's names, paths, refs and noIndex with client.entries(type) (index only); read a " +
68
+ "block's body with client.resolve(name).";
69
+
61
70
  type Selected = { selection: Selection } | { error: CMSError };
62
71
  type Pinned = { pin: Pin; resolver: Resolver } | { error: CMSError };
63
72
 
64
- /** Types `list()` warns about once per process: routing reads `routes()` and `redirects()`. */
65
- const ROUTED_TYPES = new Set(["page", "redirect", REDIRECTS_TYPE]);
66
- const LIST_WARNED = Symbol.for("decocms.blocks.listWarned");
67
-
68
73
  export class CMSClient implements Client {
69
74
  readonly #options: ClientOptions;
70
75
  readonly #reported = new WeakSet<CMSError>();
@@ -102,15 +107,29 @@ export class CMSClient implements Client {
102
107
  }
103
108
 
104
109
  async routes(): Promise<Result<Route[]>> {
105
- // A pinned client answers from its pin; otherwise the current index, without pinning.
110
+ const [content, error] = await this.#index();
111
+ return error === null ? [routesOf(content), null] : this.#fail(error);
112
+ }
113
+
114
+ async entries(type?: string): Promise<Result<readonly Entry[]>> {
115
+ if (type !== undefined && typeof type !== "string") return [[], null];
116
+ const [content, error] = await this.#index();
117
+ return error === null ? [entriesOf(content, type), null] : this.#fail(error);
118
+ }
119
+
120
+ /** Removed: throws {@link LIST_REMOVED} before reading anything. */
121
+ list<T = Block>(_type: string, _options?: ListOptions<T>): Promise<Result<T[]>> {
122
+ throw new Error(LIST_REMOVED);
123
+ }
124
+
125
+ /** The index it reads: a pinned client's pin; otherwise the current one, without pinning. */
126
+ async #index(): Promise<[IndexedContent, null] | [null, CMSError]> {
106
127
  const pinned = this.#pinned === undefined ? undefined : await this.#pinned;
107
128
  if (pinned !== undefined) {
108
- if ("error" in pinned) return this.#fail(pinned.error);
109
- return [routesOf(pinned.pin.content), null];
129
+ return "error" in pinned ? [null, pinned.error] : [pinned.pin.content, null];
110
130
  }
111
131
  const selected = await this.#select();
112
- if ("error" in selected) return this.#fail(selected.error);
113
- return [routesOf(selected.selection.current), null];
132
+ return "error" in selected ? [null, selected.error] : [selected.selection.current, null];
114
133
  }
115
134
 
116
135
  prefetch(name: string): void {
@@ -163,38 +182,6 @@ export class CMSClient implements Client {
163
182
  }
164
183
  }
165
184
 
166
- async list<T = Block>(type: string, options: ListOptions<T> = {}): Promise<Result<T[]>> {
167
- const pinned = await this.#pin();
168
- if ("error" in pinned) return this.#fail(pinned.error);
169
- const { pin, resolver } = pinned;
170
- warnRoutedList(canonicalType(pin.content, type));
171
- const names = namesOfType(pin.content, type);
172
-
173
- let entries: T[];
174
- try {
175
- await pin.wave(walk(pin.content, names));
176
- const values = await Promise.all(
177
- names.map((name) =>
178
- (options.run === true ? resolver.resolveEntry(name) : resolver.expandEntry(name)).catch(
179
- (error) => {
180
- throw atEntry(name, error);
181
- },
182
- ),
183
- ),
184
- );
185
- entries = values.filter((value) => value !== undefined) as T[];
186
- } catch (error) {
187
- return this.#fail(asCMSError(error));
188
- }
189
-
190
- if (options.where) entries = entries.filter(options.where);
191
- if (options.sort) entries = [...entries].sort(options.sort);
192
- if (typeof options.limit === "number" && options.limit >= 0) {
193
- entries = entries.slice(0, Math.floor(options.limit));
194
- }
195
- return [entries, null];
196
- }
197
-
198
185
  async revision(): Promise<string> {
199
186
  const pinned = await this.#pin();
200
187
  if ("error" in pinned) throw pinned.error;
@@ -256,32 +243,6 @@ function rulesOf(value: unknown): Redirect[] {
256
243
  ) as Redirect[];
257
244
  }
258
245
 
259
- /**
260
- * `list("page")` and `list("redirect")` read every page or rule: routing reads
261
- * `routes()` and `redirects()` from the index instead. Warns once per process
262
- * and type, outside production.
263
- */
264
- function warnRoutedList(type: string): void {
265
- if (!ROUTED_TYPES.has(type)) return;
266
- const env = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process
267
- ?.env;
268
- if (env?.NODE_ENV === "production") return;
269
- const store = globalThis as unknown as Record<symbol, Set<string> | undefined>;
270
- const warned = store[LIST_WARNED] ?? new Set<string>();
271
- store[LIST_WARNED] = warned;
272
- if (warned.has(type)) return;
273
- warned.add(type);
274
- console.warn(
275
- `[decocms/blocks] client.list("${type}") fetches every ${type} block; route with ` +
276
- "client.routes() and client.redirects(), which read the index (see /next/routing).",
277
- );
278
- }
279
-
280
- /** Forgets which list types warned, so a test starts clean. */
281
- export function resetListWarnings(): void {
282
- delete (globalThis as unknown as Record<symbol, unknown>)[LIST_WARNED];
283
- }
284
-
285
246
  /**
286
247
  * The client's own frozen copy of a visitor, so a caller changing its object
287
248
  * later changes no client; `null` for anything that isn't one.
@@ -307,9 +268,3 @@ function copyVisitor(visitor: Visitor | null | undefined): Visitor | null {
307
268
  function asCMSError(error: unknown): CMSError {
308
269
  return isResolutionError(error) ? error : errors.blockFailed("<unknown>", [], error);
309
270
  }
310
-
311
- /** Prefixes a failed list entry's path with the entry's name, so the log says which one. */
312
- function atEntry(name: string, error: unknown): unknown {
313
- if (!isResolutionError(error) || error.code === "CYCLE") return error;
314
- return new ResolutionError(error.code, error.message, [name, ...error.path], error.cause);
315
- }
package/src/v8/cms.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  import { runInBackground } from "./background.ts";
10
10
  import { SETTINGS_BLOCK, SETTINGS_TYPE } from "./builtins/data.ts";
11
11
  import { builtIns } from "./builtins/index.ts";
12
- import { CMSClient, resetListWarnings } from "./client.ts";
12
+ import { CMSClient } from "./client.ts";
13
13
  import { ContentStore, isLoader, isSnapshot } from "./content.ts";
14
14
  import type { IndexedContent } from "./contentIndex.ts";
15
15
  import type { Overrides } from "./current.ts";
@@ -485,7 +485,6 @@ function overridesOf(given: unknown): Overrides | undefined {
485
485
  export function resetForTests(): void {
486
486
  clearGlobals(INSTANCE_PREFIX);
487
487
  resetRemoteLoaders();
488
- resetListWarnings();
489
488
  setCurrentTelemetry(undefined);
490
489
  }
491
490
 
@@ -6,14 +6,15 @@
6
6
  * the inline `CMS` body) or, by hash, from the hosted block store.
7
7
  *
8
8
  * Local content (a content module or a custom `Loader`) is turned into an
9
- * index once per snapshot object, with `blockMeta` over its bodies, so
10
- * `routes()`, `redirects()` and `prefetch()` behave the same everywhere.
9
+ * index once per snapshot object, with `blockMeta` over its bodies (a page's
10
+ * saved SEO block resolved from them), so `routes()`, `redirects()`,
11
+ * `entries()` and `prefetch()` behave the same everywhere.
11
12
  */
12
- import { type BlockIndex, blockMeta, type IndexEntry } from "./blockMeta.ts";
13
+ import { type BlockIndex, blockMeta, type IndexEntry, META_VERSION } from "./blockMeta.ts";
13
14
  import { REDIRECTS_TYPE } from "./builtins/data.ts";
14
15
  import { LEGACY_ALIASES } from "./builtins/legacy.ts";
15
16
  import { own } from "./json.ts";
16
- import type { Route, Snapshot } from "./types.ts";
17
+ import type { Entry, Route, Snapshot } from "./types.ts";
17
18
 
18
19
  /** Fetches bodies by hash, shared across requests (see ./blockStore.ts). */
19
20
  export interface BodySource {
@@ -34,6 +35,11 @@ export interface IndexedContent {
34
35
  readonly revision: string;
35
36
  /** `latest.json`'s `sequence` (0 for local content). */
36
37
  readonly sequence: number;
38
+ /**
39
+ * The version of `blockMeta` that computed the entries' `meta` (the index's
40
+ * `metaVersion`, 1 when it has none; `META_VERSION` for local content).
41
+ */
42
+ readonly metaVersion: number;
37
43
  /** Name → entry; a null-prototype object, so any name is an entry. */
38
44
  readonly blocks: Readonly<BlockIndex>;
39
45
  /** The content module's alias table (local content only). */
@@ -84,6 +90,8 @@ interface Derived {
84
90
  names: string[];
85
91
  routes: Route[];
86
92
  redirects: string | null;
93
+ /** `entries(type)` by canonical type (`""`: every typed entry), built on first ask. */
94
+ entries: Map<string, readonly Entry[]>;
87
95
  }
88
96
 
89
97
  const derived = new WeakMap<IndexedContent, Derived>();
@@ -102,16 +110,11 @@ function derive(content: IndexedContent): Derived {
102
110
  if (type === PAGE && typeof meta.path === "string") routes.push({ name, path: meta.path });
103
111
  else if (type === REDIRECTS_TYPE && redirects === null) redirects = name;
104
112
  }
105
- found = { names, routes, redirects };
113
+ found = { names, routes, redirects, entries: new Map() };
106
114
  derived.set(content, found);
107
115
  return found;
108
116
  }
109
117
 
110
- /** Every name, in code-unit order. */
111
- export function namesOf(content: IndexedContent): readonly string[] {
112
- return derive(content).names;
113
- }
114
-
115
118
  /**
116
119
  * `{ name, path }` of every page entry (its `meta.type` maps to `page` and it
117
120
  * has a `meta.path`), in code-unit order of name, so the same page wins a path
@@ -127,13 +130,38 @@ export function redirectsBlockOf(content: IndexedContent): string | null {
127
130
  return derive(content).redirects;
128
131
  }
129
132
 
130
- /** Names of entries whose type maps to `type`, in code-unit order. */
131
- export function namesOfType(content: IndexedContent, type: string): string[] {
132
- const wanted = canonicalType(content, type);
133
- return namesOf(content).filter((name) => {
134
- const t = content.blocks[name]?.meta?.type;
135
- return t !== undefined && canonicalType(content, t) === wanted;
136
- });
133
+ /**
134
+ * What the index says about each typed entry (of `type`, after alias mapping,
135
+ * when given), in code-unit order of name: `{ name, type, path?, refs,
136
+ * noIndex? }`, `type` mapped through the aliases. `noIndex` is a boolean on an
137
+ * index whose meta version has it (`metaVersion` 2 or later: a missing one is
138
+ * `false`), absent on an older one. Never reads a body. The same frozen array
139
+ * for the same index and type.
140
+ */
141
+ export function entriesOf(content: IndexedContent, type?: string): readonly Entry[] {
142
+ const derived = derive(content);
143
+ const wanted = type === undefined ? "" : canonicalType(content, type);
144
+ let found = derived.entries.get(wanted);
145
+ if (found !== undefined) return found;
146
+ const knowsNoIndex = content.metaVersion >= 2;
147
+ const out: Entry[] = [];
148
+ for (const name of derived.names) {
149
+ const meta = content.blocks[name]?.meta;
150
+ if (meta?.type === undefined) continue;
151
+ const canonical = canonicalType(content, meta.type);
152
+ if (wanted !== "" && canonical !== wanted) continue;
153
+ const entry: Entry = {
154
+ name,
155
+ type: canonical,
156
+ refs: Object.freeze([...(meta.refs ?? [])]) as string[],
157
+ };
158
+ if (meta.path !== undefined) entry.path = meta.path;
159
+ if (knowsNoIndex) entry.noIndex = meta.noIndex === true;
160
+ out.push(Object.freeze(entry));
161
+ }
162
+ found = Object.freeze(out);
163
+ derived.entries.set(wanted, found);
164
+ return found;
137
165
  }
138
166
 
139
167
  /**
@@ -162,19 +190,21 @@ export function localIndex(snapshot: Snapshot): IndexedContent {
162
190
  if (found !== undefined) return found;
163
191
  const bodies = snapshot.blocks;
164
192
  const names = new Set(Object.keys(bodies));
193
+ const bodyOf = (name: string) => (Object.hasOwn(bodies, name) ? bodies[name] : undefined);
165
194
  const blocks = Object.create(null) as BlockIndex;
166
195
  for (const name of names) {
167
- const meta = blockMeta(bodies[name], names);
196
+ const meta = blockMeta(bodies[name], names, bodyOf);
168
197
  // Local bodies are held, so no hash is needed (or computed).
169
198
  blocks[name] = Object.keys(meta).length > 0 ? { version: "", meta } : { version: "" };
170
199
  }
171
200
  found = {
172
201
  revision: snapshot.revision,
173
202
  sequence: 0,
203
+ metaVersion: META_VERSION,
174
204
  blocks,
175
205
  held: {
176
206
  has: (name) => Object.hasOwn(bodies, name),
177
- get: (name) => (Object.hasOwn(bodies, name) ? bodies[name] : undefined),
207
+ get: bodyOf,
178
208
  },
179
209
  };
180
210
  if (snapshot.aliases !== undefined) (found as { aliases?: unknown }).aliases = snapshot.aliases;
@@ -245,9 +245,12 @@ export function overlayDraft(
245
245
  }
246
246
  }
247
247
  const blocks = Object.create(null) as BlockIndex;
248
+ // A page's saved SEO block: the draft's own body, else one the base holds.
249
+ const bodyOf = (name: string): unknown =>
250
+ bodies.has(name) ? bodies.get(name) : states.has(name) ? undefined : base.held?.get(name);
248
251
  for (const name of names) {
249
252
  if (bodies.has(name)) {
250
- const meta = blockMeta(bodies.get(name), names);
253
+ const meta = blockMeta(bodies.get(name), names, bodyOf);
251
254
  const entry: IndexEntry = { version: "" };
252
255
  if (Object.keys(meta).length > 0) entry.meta = meta;
253
256
  blocks[name] = entry;
@@ -264,6 +267,7 @@ export function overlayDraft(
264
267
  const content: IndexedContent = {
265
268
  revision: `${base.revision}~${view}`,
266
269
  sequence: base.sequence,
270
+ metaVersion: base.metaVersion,
267
271
  blocks,
268
272
  held,
269
273
  draft: true,
package/src/v8/index.ts CHANGED
@@ -23,8 +23,8 @@ export type {
23
23
  CMSSettings,
24
24
  DraftPointer,
25
25
  EffectiveSettings,
26
+ Entry,
26
27
  Lazy,
27
- ListOptions,
28
28
  Loader,
29
29
  Match,
30
30
  Page,
@@ -5,8 +5,10 @@
5
5
  * talk only to the CDN, with plain HTTP (ETag, `If-None-Match`, 304).
6
6
  *
7
7
  * - **The index.** `sites/<site>/latest.json` is the current revision's
8
- * index (`{ revision, sequence, previewHosts, blocks: { <name>: { version,
9
- * meta?, data? } } }`). The first use loads it (calls made meanwhile share
8
+ * index (`{ revision, sequence, metaVersion?, previewHosts, blocks: {
9
+ * <name>: { version, meta?, data? } } }`; `metaVersion`, absent on an
10
+ * index written before it, is the `blockMeta` version of the entries'
11
+ * `meta`: see ./blockMeta.ts). The first use loads it (calls made meanwhile share
10
12
  * the load; a failed load isn't kept and rejects with a
11
13
  * `ContentUnavailableError`, a 404 included: never an empty site). A poll
12
14
  * (the CMS starts one in the background every interval, and a draft
@@ -288,6 +290,13 @@ class RemoteLoader implements Loader, HostedSource {
288
290
  throw format("sequence must be a positive integer");
289
291
  }
290
292
  if (!isPlainObject(body.blocks)) throw format("blocks must be an object");
293
+ // Absent (an index written before it) or unreadable: version 1, no `noIndex`.
294
+ const metaVersion =
295
+ typeof body.metaVersion === "number" &&
296
+ Number.isSafeInteger(body.metaVersion) &&
297
+ body.metaVersion >= 1
298
+ ? body.metaVersion
299
+ : 1;
291
300
  const blocks = Object.create(null) as BlockIndex;
292
301
  for (const [name, raw] of Object.entries(body.blocks)) {
293
302
  if (!isPlainObject(raw) || typeof raw.version !== "string" || !HASH_RE.test(raw.version)) {
@@ -299,7 +308,7 @@ class RemoteLoader implements Loader, HostedSource {
299
308
  if (name === INLINE_BLOCK && raw.data !== undefined) entry.data = raw.data;
300
309
  blocks[name] = entry;
301
310
  }
302
- return { revision: body.revision, sequence, blocks, source: this.blocks };
311
+ return { revision: body.revision, sequence, metaVersion, blocks, source: this.blocks };
303
312
  }
304
313
 
305
314
  /** `blocks/<hash>.json`. */
@@ -333,6 +342,7 @@ function metaOf(raw: unknown): BlockMeta | undefined {
333
342
  const refs = raw.refs.filter((ref): ref is string => typeof ref === "string");
334
343
  if (refs.length > 0) meta.refs = refs;
335
344
  }
345
+ if (raw.noIndex === true) meta.noIndex = true;
336
346
  return Object.keys(meta).length > 0 ? meta : undefined;
337
347
  }
338
348
 
package/src/v8/types.ts CHANGED
@@ -10,8 +10,8 @@ import type { Assignments, Visitor } from "./experiments.ts";
10
10
  // ---------------------------------------------------------------------------
11
11
 
12
12
  /**
13
- * A block as stored: the JSON in `.deco/blocks`, and what `client.list` and
14
- * `{ run: false }` return. Props never use it: a field's type is the value the
13
+ * A block as stored: the JSON in `.deco/blocks`, and what `{ run: false }`
14
+ * returns. Props never use it: a field's type is the value the
15
15
  * function receives.
16
16
  */
17
17
  export type Block = { __resolveType: string; [input: string]: unknown };
@@ -302,6 +302,12 @@ export interface ResolveOptions {
302
302
  run?: boolean;
303
303
  }
304
304
 
305
+ /**
306
+ * @deprecated `client.list()` was removed and throws. Route with `routes()`
307
+ * and `redirects()`, read a type's names, paths and meta with
308
+ * `entries(type)` (both from the index alone), and a block's body with
309
+ * `resolve(name)`.
310
+ */
305
311
  export interface ListOptions<T> {
306
312
  where?: (entry: T) => boolean;
307
313
  sort?: (a: T, b: T) => number;
@@ -309,6 +315,28 @@ export interface ListOptions<T> {
309
315
  run?: boolean;
310
316
  }
311
317
 
318
+ /**
319
+ * One saved block as the content's index describes it (`client.entries()`):
320
+ * no body is read to answer.
321
+ */
322
+ export interface Entry {
323
+ /** The saved block's name: `resolve(name)` reads it. */
324
+ name: string;
325
+ /** Its type, after alias mapping (a v7 `website/pages/Page.tsx` is `page`). */
326
+ type: string;
327
+ /** Its top-level `path`, when it has one. */
328
+ path?: string;
329
+ /** The saved blocks it references, deduped, in code-unit order. */
330
+ refs: string[];
331
+ /**
332
+ * Whether the page asks search engines not to index it (its `seo` says
333
+ * `noIndexing: true`, inline or through the saved SEO block it references).
334
+ * Absent when the content's index predates it (a hosted release last
335
+ * published before Studio wrote it): the next publish adds it.
336
+ */
337
+ noIndex?: boolean;
338
+ }
339
+
312
340
  /**
313
341
  * Reads one revision for one request, for one visitor, at one moment.
314
342
  *
@@ -322,9 +350,22 @@ export interface ListOptions<T> {
322
350
  export interface Client {
323
351
  resolve<T = unknown>(target: unknown, options?: ResolveOptions): Promise<Result<T>>;
324
352
  /**
325
- * Every saved block of a type, read whole. For tools and type lists; routing
326
- * reads `routes()` and `redirects()`, which need no body (a `page` or
327
- * `redirect` list warns outside production).
353
+ * What the index says about every saved block (of `type`, or an alias of
354
+ * it, when given): `{ name, type, path?, refs, noIndex? }`, in code-unit
355
+ * order of name. Reads the index alone, never a body, so it costs no fetch
356
+ * however many blocks there are: a sitemap is the `page` entries' paths
357
+ * without parameters or a splat and without `noIndex`; a block's body is
358
+ * one `resolve(name)` away. The same frozen array for the same revision and
359
+ * type.
360
+ */
361
+ entries(type?: string): Promise<Result<readonly Entry[]>>;
362
+ /**
363
+ * @deprecated Removed: throws at once, before reading anything (it fetched
364
+ * the body of every block of a type, one CDN request per block on a hosted
365
+ * release). Route with `routes()` and `redirects()` (index only); read a
366
+ * type's names, paths, refs and `noIndex` with `entries(type)` (index
367
+ * only); read a block's body with `resolve(name)`. The signature stays so
368
+ * old code compiles and fails with that guidance at runtime.
328
369
  */
329
370
  list<T = Block>(type: string, options?: ListOptions<T>): Promise<Result<T[]>>;
330
371
  /**
@@ -350,7 +391,7 @@ export interface Client {
350
391
  prefetch(name: string): void;
351
392
  /**
352
393
  * The revision this client reads (loads it on first use). Unlike `resolve`
353
- * and `list`, it rejects with the `LOADER_FAILED` error when the content
394
+ * and `entries`, it rejects with the `LOADER_FAILED` error when the content
354
395
  * can't load, since there is no revision to report.
355
396
  */
356
397
  revision(): Promise<string>;
@@ -359,7 +400,7 @@ export interface Client {
359
400
  /**
360
401
  * The version it reads: the release's revision id, or the draft pointer, as
361
402
  * passed to `cms.client()`. For the current release, the id of the release
362
- * it loaded (`undefined` until its first `resolve`, `list` or `revision()`).
403
+ * it loaded (`undefined` until its first `resolve` or `revision()`).
363
404
  */
364
405
  readonly version: string | undefined;
365
406
  /** The date campaigns run at: the one passed to `cms.client()`, otherwise when the client was created. */