@decocms/blocks 8.11.0 → 8.13.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 (67) 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/cli/check/index.d.ts.map +1 -1
  14. package/dist/v8/cli/check/index.js +138 -10
  15. package/dist/v8/cli/check/index.js.map +1 -1
  16. package/dist/v8/client.d.ts +6 -4
  17. package/dist/v8/client.d.ts.map +1 -1
  18. package/dist/v8/client.js +26 -70
  19. package/dist/v8/client.js.map +1 -1
  20. package/dist/v8/cms.d.ts.map +1 -1
  21. package/dist/v8/cms.js +1 -2
  22. package/dist/v8/cms.js.map +1 -1
  23. package/dist/v8/contentIndex.d.ts +18 -7
  24. package/dist/v8/contentIndex.d.ts.map +1 -1
  25. package/dist/v8/contentIndex.js +46 -17
  26. package/dist/v8/contentIndex.js.map +1 -1
  27. package/dist/v8/draftChanges.d.ts.map +1 -1
  28. package/dist/v8/draftChanges.js +4 -1
  29. package/dist/v8/draftChanges.js.map +1 -1
  30. package/dist/v8/index.d.ts +1 -1
  31. package/dist/v8/index.d.ts.map +1 -1
  32. package/dist/v8/remoteLoader.d.ts +4 -2
  33. package/dist/v8/remoteLoader.d.ts.map +1 -1
  34. package/dist/v8/remoteLoader.js +13 -3
  35. package/dist/v8/remoteLoader.js.map +1 -1
  36. package/dist/v8/types.d.ts +47 -7
  37. package/dist/v8/types.d.ts.map +1 -1
  38. package/package.json +1 -1
  39. package/skills/deco-make-editable/SKILL.md +1 -1
  40. package/skills/deco-make-editable/references/content-shapes.md +14 -9
  41. package/skills/deco-nextjs-site/references/rendering.md +6 -5
  42. package/skills/deco-site-authoring/references/pages.md +6 -4
  43. package/skills/deco-site-workflow/SKILL.md +12 -3
  44. package/skills/deco-site-workflow/references/cli-reference.md +2 -0
  45. package/skills/deco-site-workflow/references/content-layout.md +26 -2
  46. package/skills/deco-storefront-performance/references/request-dedupe.md +5 -3
  47. package/skills/deco-v7-to-v8-migration/SKILL.md +2 -1
  48. package/skills/deco-v7-to-v8-migration/references/hosted-releases.md +1 -1
  49. package/skills/deco-v7-to-v8-migration/references/nextjs.md +2 -2
  50. package/skills/deco-v7-to-v8-migration/references/verify.md +3 -0
  51. package/skills/deco-v7-to-v8-migration/scripts/checkContentReads.ts +32 -0
  52. package/skills/deco-v7-to-v8-migration/scripts/contentReads.ts +157 -0
  53. package/skills/deco-v7-to-v8-migration/scripts/imports.ts +1 -1
  54. package/skills/deco-v7-to-v8-migration/scripts/migrate.ts +4 -0
  55. package/skills/deco-variants/references/multivariate.md +1 -1
  56. package/src/index.ts +1 -1
  57. package/src/protocol/conformance/blockMetaVectors.json +80 -0
  58. package/src/protocol/index.ts +8 -1
  59. package/src/v8/blockMeta.ts +75 -11
  60. package/src/v8/cli/check/index.ts +153 -10
  61. package/src/v8/client.ts +32 -77
  62. package/src/v8/cms.ts +1 -2
  63. package/src/v8/contentIndex.ts +49 -19
  64. package/src/v8/draftChanges.ts +5 -1
  65. package/src/v8/index.ts +1 -1
  66. package/src/v8/remoteLoader.ts +13 -3
  67. package/src/v8/types.ts +48 -7
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. */