@decocms/blocks 8.10.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.
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/protocol/conformance/blockMetaVectors.json +80 -0
- package/dist/protocol/index.d.ts +5 -2
- package/dist/protocol/index.d.ts.map +1 -1
- package/dist/protocol/index.js +5 -2
- package/dist/protocol/index.js.map +1 -1
- package/dist/v8/blockMeta.d.ts +33 -4
- package/dist/v8/blockMeta.d.ts.map +1 -1
- package/dist/v8/blockMeta.js +70 -13
- package/dist/v8/blockMeta.js.map +1 -1
- package/dist/v8/cli/index.d.ts +1 -0
- package/dist/v8/cli/index.d.ts.map +1 -1
- package/dist/v8/cli/index.js +1 -0
- package/dist/v8/cli/index.js.map +1 -1
- package/dist/v8/cli/run.d.ts +2 -0
- package/dist/v8/cli/run.d.ts.map +1 -1
- package/dist/v8/cli/run.js +30 -1
- package/dist/v8/cli/run.js.map +1 -1
- package/dist/v8/cli/skills.d.ts +25 -0
- package/dist/v8/cli/skills.d.ts.map +1 -0
- package/dist/v8/cli/skills.js +70 -0
- package/dist/v8/cli/skills.js.map +1 -0
- package/dist/v8/client.d.ts +6 -4
- package/dist/v8/client.d.ts.map +1 -1
- package/dist/v8/client.js +26 -70
- package/dist/v8/client.js.map +1 -1
- package/dist/v8/cms.d.ts.map +1 -1
- package/dist/v8/cms.js +1 -2
- package/dist/v8/cms.js.map +1 -1
- package/dist/v8/contentIndex.d.ts +18 -7
- package/dist/v8/contentIndex.d.ts.map +1 -1
- package/dist/v8/contentIndex.js +46 -17
- package/dist/v8/contentIndex.js.map +1 -1
- package/dist/v8/draftChanges.d.ts.map +1 -1
- package/dist/v8/draftChanges.js +4 -1
- package/dist/v8/draftChanges.js.map +1 -1
- package/dist/v8/index.d.ts +1 -1
- package/dist/v8/index.d.ts.map +1 -1
- package/dist/v8/remoteLoader.d.ts +4 -2
- package/dist/v8/remoteLoader.d.ts.map +1 -1
- package/dist/v8/remoteLoader.js +13 -3
- package/dist/v8/remoteLoader.js.map +1 -1
- package/dist/v8/types.d.ts +47 -7
- package/dist/v8/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/skills/deco-apps/SKILL.md +82 -0
- package/skills/deco-apps/references/algolia.md +51 -0
- package/skills/deco-apps/references/commerce-types.md +132 -0
- package/skills/deco-apps/references/instrumented-fetch.md +144 -0
- package/skills/deco-apps/references/magento.md +55 -0
- package/skills/deco-apps/references/messaging.md +76 -0
- package/skills/deco-apps/references/shopify.md +69 -0
- package/skills/deco-apps/references/vendored-loaders.md +135 -0
- package/skills/deco-apps/references/vtex-cookies-auth.md +146 -0
- package/skills/deco-apps/references/vtex.md +150 -0
- package/skills/deco-apps/references/wake.md +75 -0
- package/skills/deco-cms-schema/SKILL.md +80 -0
- package/skills/deco-cms-schema/references/annotations.md +147 -0
- package/skills/deco-cms-schema/references/content-hygiene.md +91 -0
- package/skills/deco-cms-schema/references/formats-and-widgets.md +112 -0
- package/skills/deco-cms-schema/references/shapes-that-break-the-form.md +165 -0
- package/skills/deco-cms-schema/references/types-to-fields.md +112 -0
- package/skills/deco-go-live/SKILL.md +127 -0
- package/skills/deco-go-live/references/content-releases.md +90 -0
- package/skills/deco-go-live/references/process.md +106 -0
- package/skills/deco-go-live/references/proxy-headers-checkout.md +139 -0
- package/skills/deco-go-live/references/qa-checklist-template.md +150 -0
- package/skills/deco-go-live/references/qa-inventory.md +120 -0
- package/skills/deco-go-live/references/react-spa.md +183 -0
- package/skills/deco-go-live/references/seo-analytics.md +114 -0
- package/skills/deco-go-live/references/traffic-ramp.md +87 -0
- package/skills/deco-go-live/references/worker-runtime.md +93 -0
- package/skills/deco-go-live/scripts/preflight.sh +221 -0
- package/skills/deco-images-media/SKILL.md +64 -0
- package/skills/deco-images-media/references/asset-upload.md +191 -0
- package/skills/deco-images-media/references/components-per-binding.md +167 -0
- package/skills/deco-images-media/references/providers-and-cdn.md +145 -0
- package/skills/deco-images-media/references/quality-and-lcp.md +93 -0
- package/skills/deco-images-media/references/troubleshooting.md +147 -0
- package/skills/deco-images-media/references/video.md +122 -0
- package/skills/deco-make-editable/SKILL.md +94 -0
- package/skills/deco-make-editable/references/a11y-and-e2e.md +104 -0
- package/skills/deco-make-editable/references/content-shapes.md +203 -0
- package/skills/deco-make-editable/references/from-figma.md +110 -0
- package/skills/deco-make-editable/references/i18n-fields.md +112 -0
- package/skills/deco-make-editable/references/inventory.md +79 -0
- package/skills/deco-make-editable/references/pixel-parity.md +175 -0
- package/skills/deco-make-editable/references/seeding-content.md +119 -0
- package/skills/deco-nextjs-site/SKILL.md +74 -0
- package/skills/deco-nextjs-site/references/caching.md +116 -0
- package/skills/deco-nextjs-site/references/metadata-seo.md +100 -0
- package/skills/deco-nextjs-site/references/proxy-and-drafts.md +177 -0
- package/skills/deco-nextjs-site/references/rendering.md +172 -0
- package/skills/deco-nextjs-site/references/setup.md +190 -0
- package/skills/deco-nextjs-site/references/studio-bridge.md +130 -0
- package/skills/deco-site-authoring/SKILL.md +75 -0
- package/skills/deco-site-authoring/references/lazy-blocks.md +155 -0
- package/skills/deco-site-authoring/references/loaders.md +192 -0
- package/skills/deco-site-authoring/references/pages.md +158 -0
- package/skills/deco-site-authoring/references/review-before-publish.md +95 -0
- package/skills/deco-site-authoring/references/sections.md +158 -0
- package/skills/deco-site-authoring/references/seo.md +116 -0
- package/skills/deco-site-workflow/SKILL.md +101 -0
- package/skills/deco-site-workflow/references/check.md +116 -0
- package/skills/deco-site-workflow/references/cli-reference.md +106 -0
- package/skills/deco-site-workflow/references/content-layout.md +93 -0
- package/skills/deco-site-workflow/references/content-sync.md +146 -0
- package/skills/deco-site-workflow/references/delivery.md +51 -0
- package/skills/deco-site-workflow/references/deploy.md +87 -0
- package/skills/deco-site-workflow/references/schema.md +173 -0
- package/skills/deco-site-workflow/references/serve-and-studio.md +138 -0
- package/skills/deco-storefront-caching/SKILL.md +67 -0
- package/skills/deco-storefront-caching/references/cache-keys.md +129 -0
- package/skills/deco-storefront-caching/references/case-study.md +82 -0
- package/skills/deco-storefront-caching/references/egress-traps.md +153 -0
- package/skills/deco-storefront-caching/references/nextjs.md +60 -0
- package/skills/deco-storefront-caching/references/perf-guardrails-e2e.md +123 -0
- package/skills/deco-storefront-caching/references/verification.md +136 -0
- package/skills/deco-storefront-caching/references/worker-page-cache.md +160 -0
- package/skills/deco-storefront-caching/scripts/html-anatomy.mjs +97 -0
- package/skills/deco-storefront-performance/SKILL.md +81 -0
- package/skills/deco-storefront-performance/references/cls-third-party.md +90 -0
- package/skills/deco-storefront-performance/references/hydration.md +116 -0
- package/skills/deco-storefront-performance/references/loaders-n-plus-1.md +107 -0
- package/skills/deco-storefront-performance/references/navigation-ux.md +130 -0
- package/skills/deco-storefront-performance/references/payload-trim.md +163 -0
- package/skills/deco-storefront-performance/references/render-location.md +152 -0
- package/skills/deco-storefront-performance/references/request-dedupe.md +147 -0
- package/skills/deco-storefront-performance/references/trace-reading.md +79 -0
- package/skills/deco-storefront-performance/references/worker-memory.md +176 -0
- package/skills/deco-tanstack-site/SKILL.md +68 -0
- package/skills/deco-tanstack-site/references/document-and-security.md +155 -0
- package/skills/deco-tanstack-site/references/router-and-navigation.md +137 -0
- package/skills/deco-tanstack-site/references/routes-and-pages.md +183 -0
- package/skills/deco-tanstack-site/references/server-functions.md +123 -0
- package/skills/deco-tanstack-site/references/setup.md +153 -0
- package/skills/deco-tanstack-site/references/worker-entry.md +152 -0
- package/skills/deco-v7-to-v8-migration/SKILL.md +123 -0
- package/skills/deco-v7-to-v8-migration/references/caching-and-privacy.md +10 -0
- package/skills/deco-v7-to-v8-migration/references/content.md +25 -0
- package/skills/deco-v7-to-v8-migration/references/editor-forms.md +27 -0
- package/skills/deco-v7-to-v8-migration/references/faststore.md +40 -0
- package/skills/deco-v7-to-v8-migration/references/framework-code.md +53 -0
- package/skills/deco-v7-to-v8-migration/references/hosted-releases.md +16 -0
- package/skills/deco-v7-to-v8-migration/references/import-map.md +81 -0
- package/skills/deco-v7-to-v8-migration/references/legacy-names.md +33 -0
- package/skills/deco-v7-to-v8-migration/references/manual-steps.md +10 -0
- package/skills/deco-v7-to-v8-migration/references/native-apps.md +43 -0
- package/skills/deco-v7-to-v8-migration/references/nextjs.md +19 -0
- package/skills/deco-v7-to-v8-migration/references/parity.md +66 -0
- package/skills/deco-v7-to-v8-migration/references/rendering.md +13 -0
- package/skills/deco-v7-to-v8-migration/references/running-the-script.md +29 -0
- package/skills/deco-v7-to-v8-migration/references/script-steps.md +13 -0
- package/skills/deco-v7-to-v8-migration/references/server-functions.md +15 -0
- package/skills/deco-v7-to-v8-migration/references/sibling-port.md +11 -0
- package/skills/deco-v7-to-v8-migration/references/site-code.md +15 -0
- package/skills/deco-v7-to-v8-migration/references/telemetry.md +10 -0
- package/skills/deco-v7-to-v8-migration/references/verify.md +23 -0
- package/skills/deco-v7-to-v8-migration/scripts/apps.ts +297 -0
- package/skills/deco-v7-to-v8-migration/scripts/asyncRendering.ts +73 -0
- package/skills/deco-v7-to-v8-migration/scripts/blockMap.ts +584 -0
- package/skills/deco-v7-to-v8-migration/scripts/checkContentReads.ts +32 -0
- package/skills/deco-v7-to-v8-migration/scripts/ciSchemaCheck.ts +145 -0
- package/skills/deco-v7-to-v8-migration/scripts/compat.ts +357 -0
- package/skills/deco-v7-to-v8-migration/scripts/content.ts +121 -0
- package/skills/deco-v7-to-v8-migration/scripts/contentReads.ts +157 -0
- package/skills/deco-v7-to-v8-migration/scripts/experiments.ts +81 -0
- package/skills/deco-v7-to-v8-migration/scripts/framework.ts +61 -0
- package/skills/deco-v7-to-v8-migration/scripts/imageCopy.ts +276 -0
- package/skills/deco-v7-to-v8-migration/scripts/imageModule.ts +285 -0
- package/skills/deco-v7-to-v8-migration/scripts/imports.ts +942 -0
- package/skills/deco-v7-to-v8-migration/scripts/invoke.ts +624 -0
- package/skills/deco-v7-to-v8-migration/scripts/legacyNames.ts +45 -0
- package/skills/deco-v7-to-v8-migration/scripts/main.ts +59 -0
- package/skills/deco-v7-to-v8-migration/scripts/matchers.ts +41 -0
- package/skills/deco-v7-to-v8-migration/scripts/migrate.ts +180 -0
- package/skills/deco-v7-to-v8-migration/scripts/redirects.ts +455 -0
- package/skills/deco-v7-to-v8-migration/scripts/report.ts +50 -0
- package/skills/deco-v7-to-v8-migration/scripts/scaffold.ts +1119 -0
- package/skills/deco-v7-to-v8-migration/scripts/secrets.ts +35 -0
- package/skills/deco-v7-to-v8-migration/scripts/sectionLoaders.ts +216 -0
- package/skills/deco-v7-to-v8-migration/scripts/siteSettings.ts +261 -0
- package/skills/deco-v7-to-v8-migration/scripts/stubs.ts +388 -0
- package/skills/deco-v7-to-v8-migration/scripts/tsconfig.json +7 -0
- package/skills/deco-v7-to-v8-migration/scripts/vendor.ts +249 -0
- package/skills/deco-v7-to-v8-migration/scripts/vtexInvoke.ts +240 -0
- package/skills/deco-v7-to-v8-migration/scripts/walk.ts +30 -0
- package/skills/deco-variants/SKILL.md +57 -0
- package/skills/deco-variants/references/caching-variants.md +63 -0
- package/skills/deco-variants/references/custom-matchers.md +83 -0
- package/skills/deco-variants/references/draft-preview.md +59 -0
- package/skills/deco-variants/references/experiments-and-campaigns.md +104 -0
- package/skills/deco-variants/references/multivariate.md +85 -0
- package/skills/deco-variants/references/v7-matchers.md +71 -0
- package/src/index.ts +1 -1
- package/src/protocol/conformance/blockMetaVectors.json +80 -0
- package/src/protocol/index.ts +8 -1
- package/src/v8/blockMeta.ts +75 -11
- package/src/v8/cli/index.ts +1 -0
- package/src/v8/cli/run.ts +35 -1
- package/src/v8/cli/skills.ts +91 -0
- package/src/v8/client.ts +32 -77
- package/src/v8/cms.ts +1 -2
- package/src/v8/contentIndex.ts +49 -19
- package/src/v8/draftChanges.ts +5 -1
- package/src/v8/index.ts +1 -1
- package/src/v8/remoteLoader.ts +13 -3
- package/src/v8/types.ts +48 -7
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
|
-
|
|
15
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
package/src/v8/contentIndex.ts
CHANGED
|
@@ -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
|
|
10
|
-
* `routes()`, `redirects()
|
|
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
|
-
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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:
|
|
207
|
+
get: bodyOf,
|
|
178
208
|
},
|
|
179
209
|
};
|
|
180
210
|
if (snapshot.aliases !== undefined) (found as { aliases?: unknown }).aliases = snapshot.aliases;
|
package/src/v8/draftChanges.ts
CHANGED
|
@@ -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
package/src/v8/remoteLoader.ts
CHANGED
|
@@ -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: {
|
|
9
|
-
* meta?, data? } } }`
|
|
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 `
|
|
14
|
-
*
|
|
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
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
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 `
|
|
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
|
|
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. */
|