@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.
- 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/check/index.d.ts.map +1 -1
- package/dist/v8/cli/check/index.js +138 -10
- package/dist/v8/cli/check/index.js.map +1 -1
- 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 +1 -1
- package/skills/deco-make-editable/SKILL.md +1 -1
- package/skills/deco-make-editable/references/content-shapes.md +14 -9
- package/skills/deco-nextjs-site/references/rendering.md +6 -5
- package/skills/deco-site-authoring/references/pages.md +6 -4
- package/skills/deco-site-workflow/SKILL.md +12 -3
- package/skills/deco-site-workflow/references/cli-reference.md +2 -0
- package/skills/deco-site-workflow/references/content-layout.md +26 -2
- package/skills/deco-storefront-performance/references/request-dedupe.md +5 -3
- package/skills/deco-v7-to-v8-migration/SKILL.md +2 -1
- package/skills/deco-v7-to-v8-migration/references/hosted-releases.md +1 -1
- package/skills/deco-v7-to-v8-migration/references/nextjs.md +2 -2
- package/skills/deco-v7-to-v8-migration/references/verify.md +3 -0
- package/skills/deco-v7-to-v8-migration/scripts/checkContentReads.ts +32 -0
- package/skills/deco-v7-to-v8-migration/scripts/contentReads.ts +157 -0
- package/skills/deco-v7-to-v8-migration/scripts/imports.ts +1 -1
- package/skills/deco-v7-to-v8-migration/scripts/migrate.ts +4 -0
- package/skills/deco-variants/references/multivariate.md +1 -1
- 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/check/index.ts +153 -10
- 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/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { type Analytics, type Block, type BlockFunction, type Blocks, type Client, type ClientOptions, type CMS, type CMSError, type CMSSettings, ContentUnavailableError, type ContentUnavailableReason, createCMS, currentClient, type DraftPointer, type EffectiveSettings, formatDraftPointer, type Lazy, type
|
|
1
|
+
export { type Analytics, type Block, type BlockFunction, type Blocks, type Client, type ClientOptions, type CMS, type CMSError, type CMSSettings, ContentUnavailableError, type ContentUnavailableReason, createCMS, currentClient, type DraftPointer, type EffectiveSettings, type Entry, formatDraftPointer, type Lazy, type Loader, type Match, matchRoute, type Page, parseDraftPointer, parseVersion, type Redirect, type RequestLike, type RequestVersion, type Result, type Route, remoteLoader, resetForTests, type Seo, type Snapshot, type Telemetry, type TelemetryConfig, type Variant, } from "./v8/index.ts";
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,GAAG,EACR,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,uBAAuB,EACvB,KAAK,wBAAwB,EAC7B,SAAS,EACT,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,kBAAkB,EAClB,KAAK,IAAI,EACT,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,GAAG,EACR,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,uBAAuB,EACvB,KAAK,wBAAwB,EAC7B,SAAS,EACT,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,KAAK,EACV,kBAAkB,EAClB,KAAK,IAAI,EACT,KAAK,MAAM,EACX,KAAK,KAAK,EACV,UAAU,EACV,KAAK,IAAI,EACT,iBAAiB,EACjB,YAAY,EACZ,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,KAAK,EACV,YAAY,EACZ,aAAa,EACb,KAAK,GAAG,EACR,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,OAAO,GACb,MAAM,eAAe,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,6EAA6E;AAC7E,OAAO,EAUL,uBAAuB,EAEvB,SAAS,EACT,aAAa,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,6EAA6E;AAC7E,OAAO,EAUL,uBAAuB,EAEvB,SAAS,EACT,aAAa,EAIb,kBAAkB,EAIlB,UAAU,EAEV,iBAAiB,EACjB,YAAY,EAMZ,YAAY,EACZ,aAAa,GAMd,MAAM,eAAe,CAAC"}
|
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
"footer",
|
|
6
6
|
"footer-a",
|
|
7
7
|
"header",
|
|
8
|
+
"hidden-seo",
|
|
8
9
|
"home",
|
|
10
|
+
"noindex-inline",
|
|
11
|
+
"noindex-saved",
|
|
9
12
|
"plain",
|
|
10
13
|
"redirects",
|
|
11
14
|
"variants"
|
|
@@ -209,6 +212,83 @@
|
|
|
209
212
|
}
|
|
210
213
|
}
|
|
211
214
|
}
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"name": "hidden-seo",
|
|
218
|
+
"body": {
|
|
219
|
+
"__resolveType": "website/sections/Seo/SeoV2.tsx",
|
|
220
|
+
"title": "Staging",
|
|
221
|
+
"noIndexing": true
|
|
222
|
+
},
|
|
223
|
+
"version": "TweCqXol6NaqfznIdZHWGA",
|
|
224
|
+
"meta": {
|
|
225
|
+
"type": "website/sections/Seo/SeoV2.tsx"
|
|
226
|
+
},
|
|
227
|
+
"entry": {
|
|
228
|
+
"version": "TweCqXol6NaqfznIdZHWGA",
|
|
229
|
+
"meta": {
|
|
230
|
+
"type": "website/sections/Seo/SeoV2.tsx"
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"name": "noindex-inline",
|
|
236
|
+
"body": {
|
|
237
|
+
"__resolveType": "website/pages/Page.tsx",
|
|
238
|
+
"path": "/staging",
|
|
239
|
+
"seo": {
|
|
240
|
+
"__resolveType": "website/sections/Seo/SeoV2.tsx",
|
|
241
|
+
"noIndexing": true
|
|
242
|
+
},
|
|
243
|
+
"sections": [
|
|
244
|
+
{
|
|
245
|
+
"__resolveType": "header"
|
|
246
|
+
}
|
|
247
|
+
]
|
|
248
|
+
},
|
|
249
|
+
"version": "9dPY85a3_dAGqgn9HyBymg",
|
|
250
|
+
"meta": {
|
|
251
|
+
"type": "website/pages/Page.tsx",
|
|
252
|
+
"path": "/staging",
|
|
253
|
+
"refs": ["header"],
|
|
254
|
+
"noIndex": true
|
|
255
|
+
},
|
|
256
|
+
"entry": {
|
|
257
|
+
"version": "9dPY85a3_dAGqgn9HyBymg",
|
|
258
|
+
"meta": {
|
|
259
|
+
"type": "website/pages/Page.tsx",
|
|
260
|
+
"path": "/staging",
|
|
261
|
+
"refs": ["header"],
|
|
262
|
+
"noIndex": true
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
"name": "noindex-saved",
|
|
268
|
+
"body": {
|
|
269
|
+
"__resolveType": "page",
|
|
270
|
+
"path": "/landing",
|
|
271
|
+
"seo": {
|
|
272
|
+
"__resolveType": "hidden-seo"
|
|
273
|
+
},
|
|
274
|
+
"sections": []
|
|
275
|
+
},
|
|
276
|
+
"version": "sOB07_jkmJqe7Mr5Raj6rg",
|
|
277
|
+
"meta": {
|
|
278
|
+
"type": "page",
|
|
279
|
+
"path": "/landing",
|
|
280
|
+
"refs": ["hidden-seo"],
|
|
281
|
+
"noIndex": true
|
|
282
|
+
},
|
|
283
|
+
"entry": {
|
|
284
|
+
"version": "sOB07_jkmJqe7Mr5Raj6rg",
|
|
285
|
+
"meta": {
|
|
286
|
+
"type": "page",
|
|
287
|
+
"path": "/landing",
|
|
288
|
+
"refs": ["hidden-seo"],
|
|
289
|
+
"noIndex": true
|
|
290
|
+
}
|
|
291
|
+
}
|
|
212
292
|
}
|
|
213
293
|
]
|
|
214
294
|
}
|
package/dist/protocol/index.d.ts
CHANGED
|
@@ -19,14 +19,17 @@
|
|
|
19
19
|
* the page's bootstrap is `StudioChannel` in `@decocms/blocks/preview`.
|
|
20
20
|
*
|
|
21
21
|
* `blockMeta`/`indexEntry` compute a hosted revision index's entries (the
|
|
22
|
-
* SDK's own browser-safe module, shared with Studio and the CLI)
|
|
22
|
+
* SDK's own browser-safe module, shared with Studio and the CLI);
|
|
23
|
+
* `META_VERSION` is the `metaVersion` an index they computed carries, and
|
|
24
|
+
* `seoNoIndex`/`pageNoIndex` are the `noIndex` rule, a page's saved SEO block
|
|
25
|
+
* resolved through `bodyOf`.
|
|
23
26
|
*
|
|
24
27
|
* The SDK's runtime never imports the protocol, so it never reaches an app
|
|
25
28
|
* bundle. The canonical hash it re-exports is the SDK's own dependency-free
|
|
26
29
|
* leaf module (see ./canonical.ts). Draft previews and the draft lifecycle
|
|
27
30
|
* are outside the protocol (see /next/content-delivery#draft-previews).
|
|
28
31
|
*/
|
|
29
|
-
export { type BlockIndex, type BlockMeta, blockMeta, type IndexEntry, indexEntry, } from "../v8/blockMeta.ts";
|
|
32
|
+
export { type BlockIndex, type BlockMeta, type BodyOf, blockMeta, type IndexEntry, indexEntry, META_VERSION, pageNoIndex, seoNoIndex, } from "../v8/blockMeta.ts";
|
|
30
33
|
export { isRevisionId, REVISION_ID_RE } from "../v8/revisionId.ts";
|
|
31
34
|
export { blockVersion, CanonicalJsonError, CONTENT_HASH_FORMAT, canonicalJson, computeContentRevision, sha256Hex, } from "./canonical.ts";
|
|
32
35
|
export { CHANNEL_MESSAGE, type ChannelLoadErrorMessage, type ChannelLoadedMessage, type ChannelLoadMessage, type ChannelReadyMessage, DEFAULT_STUDIO_ORIGIN, DEFAULT_STUDIO_ORIGINS, defineStudioModule, type ModuleMessage, type PageChannelMessage, type StudioChannelContext, type StudioChannelMessage, type StudioChannelModule, } from "./channel.ts";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/protocol/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/protocol/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EACL,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,MAAM,EACX,SAAS,EACT,KAAK,UAAU,EACf,UAAU,EACV,YAAY,EACZ,WAAW,EACX,UAAU,GACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,sBAAsB,EACtB,SAAS,GACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EACf,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,uBAAuB,EACvB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
package/dist/protocol/index.js
CHANGED
|
@@ -19,14 +19,17 @@
|
|
|
19
19
|
* the page's bootstrap is `StudioChannel` in `@decocms/blocks/preview`.
|
|
20
20
|
*
|
|
21
21
|
* `blockMeta`/`indexEntry` compute a hosted revision index's entries (the
|
|
22
|
-
* SDK's own browser-safe module, shared with Studio and the CLI)
|
|
22
|
+
* SDK's own browser-safe module, shared with Studio and the CLI);
|
|
23
|
+
* `META_VERSION` is the `metaVersion` an index they computed carries, and
|
|
24
|
+
* `seoNoIndex`/`pageNoIndex` are the `noIndex` rule, a page's saved SEO block
|
|
25
|
+
* resolved through `bodyOf`.
|
|
23
26
|
*
|
|
24
27
|
* The SDK's runtime never imports the protocol, so it never reaches an app
|
|
25
28
|
* bundle. The canonical hash it re-exports is the SDK's own dependency-free
|
|
26
29
|
* leaf module (see ./canonical.ts). Draft previews and the draft lifecycle
|
|
27
30
|
* are outside the protocol (see /next/content-delivery#draft-previews).
|
|
28
31
|
*/
|
|
29
|
-
export { blockMeta, indexEntry, } from "../v8/blockMeta.js";
|
|
32
|
+
export { blockMeta, indexEntry, META_VERSION, pageNoIndex, seoNoIndex, } from "../v8/blockMeta.js";
|
|
30
33
|
export { isRevisionId, REVISION_ID_RE } from "../v8/revisionId.js";
|
|
31
34
|
export { blockVersion, CanonicalJsonError, CONTENT_HASH_FORMAT, canonicalJson, computeContentRevision, sha256Hex, } from "./canonical.js";
|
|
32
35
|
export { CHANNEL_MESSAGE, DEFAULT_STUDIO_ORIGIN, DEFAULT_STUDIO_ORIGINS, defineStudioModule, } from "./channel.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/protocol/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/protocol/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAIL,SAAS,EAET,UAAU,EACV,YAAY,EACZ,WAAW,EACX,UAAU,GACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,sBAAsB,EACtB,SAAS,GACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAKf,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,GAMnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,uBAAuB,EAKvB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
package/dist/v8/blockMeta.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The version of the metadata `blockMeta` computes: 1 is `type`, `path` and
|
|
3
|
+
* `refs`; 2 adds `noIndex`. An index without `metaVersion` is version 1.
|
|
4
|
+
*/
|
|
5
|
+
export declare const META_VERSION = 2;
|
|
6
|
+
/** A saved block's body by name, to follow a reference (`undefined`: not known). */
|
|
7
|
+
export type BodyOf = (name: string) => unknown;
|
|
1
8
|
/** What an index says about a block, besides its hash. */
|
|
2
9
|
export interface BlockMeta {
|
|
3
10
|
/** The body's raw `__resolveType`. */
|
|
@@ -6,6 +13,8 @@ export interface BlockMeta {
|
|
|
6
13
|
path?: string;
|
|
7
14
|
/** The block names the body references, deduped, in code-unit order. */
|
|
8
15
|
refs?: string[];
|
|
16
|
+
/** `true` when the page says `noIndexing` (meta version 2); never written `false`. */
|
|
17
|
+
noIndex?: boolean;
|
|
9
18
|
}
|
|
10
19
|
/** One entry of a revision index. */
|
|
11
20
|
export interface IndexEntry {
|
|
@@ -20,8 +29,28 @@ export interface IndexEntry {
|
|
|
20
29
|
export type BlockIndex = Record<string, IndexEntry>;
|
|
21
30
|
/** The well-known name whose body every index inlines as `data`. */
|
|
22
31
|
export declare const INLINE_BLOCK = "CMS";
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
/**
|
|
33
|
+
* The metadata of one block body. `names` are the block names of the index
|
|
34
|
+
* being built; `bodyOf` gives the bodies of the saved blocks a page's `seo`
|
|
35
|
+
* may reference (without it, only an inline `seo` counts for `noIndex`).
|
|
36
|
+
*/
|
|
37
|
+
export declare function blockMeta(body: unknown, names: ReadonlySet<string> | readonly string[], bodyOf?: BodyOf): BlockMeta;
|
|
38
|
+
/**
|
|
39
|
+
* Whether a page body asks not to be indexed: it has a top-level string
|
|
40
|
+
* `path`, and `seoNoIndex(body.seo, bodyOf)`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function pageNoIndex(body: unknown, bodyOf?: BodyOf): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Whether a page's `seo` value says `noIndexing: true`: its own boolean
|
|
45
|
+
* `noIndexing` when it has one; otherwise, when its `__resolveType` is a saved
|
|
46
|
+
* block `bodyOf` knows (a saved SEO block such as `DefaultSeo`), that block's
|
|
47
|
+
* answer, following up to 8 saved blocks. Anything else (no `seo`, a variant,
|
|
48
|
+
* a block `bodyOf` doesn't know, a cycle) is `false`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function seoNoIndex(seo: unknown, bodyOf?: BodyOf): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* The index entry for a block: its hash, its metadata when any, and its body
|
|
53
|
+
* when it is `CMS`. `bodyOf` as for `blockMeta`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function indexEntry(name: string, body: unknown, names: ReadonlySet<string> | readonly string[], bodyOf?: BodyOf): Promise<IndexEntry>;
|
|
27
56
|
//# sourceMappingURL=blockMeta.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blockMeta.d.ts","sourceRoot":"","sources":["../../src/v8/blockMeta.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"blockMeta.d.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AAE,OAAO,EACb,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,MAAM,EAAE,EAC9C,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,UAAU,CAAC,CAMrB"}
|
package/dist/v8/blockMeta.js
CHANGED
|
@@ -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
|
|
5
|
-
* need, so
|
|
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
|
|
8
|
-
* to compute that metadata, so all three write and read the same
|
|
9
|
-
* Pure, synchronous, browser-safe; its only import is the
|
|
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,15 +15,37 @@
|
|
|
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: []`
|
|
20
|
-
* body with nothing to say gives `{}` and its entry
|
|
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.js";
|
|
34
|
+
/**
|
|
35
|
+
* The version of the metadata `blockMeta` computes: 1 is `type`, `path` and
|
|
36
|
+
* `refs`; 2 adds `noIndex`. An index without `metaVersion` is version 1.
|
|
37
|
+
*/
|
|
38
|
+
export const META_VERSION = 2;
|
|
23
39
|
/** The well-known name whose body every index inlines as `data`. */
|
|
24
40
|
export const INLINE_BLOCK = "CMS";
|
|
25
|
-
/**
|
|
26
|
-
|
|
41
|
+
/** How many saved blocks `seoNoIndex` follows, one referencing the next. */
|
|
42
|
+
const MAX_SEO_HOPS = 8;
|
|
43
|
+
/**
|
|
44
|
+
* The metadata of one block body. `names` are the block names of the index
|
|
45
|
+
* being built; `bodyOf` gives the bodies of the saved blocks a page's `seo`
|
|
46
|
+
* may reference (without it, only an inline `seo` counts for `noIndex`).
|
|
47
|
+
*/
|
|
48
|
+
export function blockMeta(body, names, bodyOf) {
|
|
27
49
|
const meta = {};
|
|
28
50
|
if (!isRecord(body))
|
|
29
51
|
return meta;
|
|
@@ -36,12 +58,47 @@ export function blockMeta(body, names) {
|
|
|
36
58
|
collectRefs(body, known, found);
|
|
37
59
|
if (found.size > 0)
|
|
38
60
|
meta.refs = [...found].sort();
|
|
61
|
+
if (pageNoIndex(body, bodyOf))
|
|
62
|
+
meta.noIndex = true;
|
|
39
63
|
return meta;
|
|
40
64
|
}
|
|
41
|
-
/**
|
|
42
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Whether a page body asks not to be indexed: it has a top-level string
|
|
67
|
+
* `path`, and `seoNoIndex(body.seo, bodyOf)`.
|
|
68
|
+
*/
|
|
69
|
+
export function pageNoIndex(body, bodyOf) {
|
|
70
|
+
return isRecord(body) && typeof body.path === "string" && seoNoIndex(body.seo, bodyOf);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Whether a page's `seo` value says `noIndexing: true`: its own boolean
|
|
74
|
+
* `noIndexing` when it has one; otherwise, when its `__resolveType` is a saved
|
|
75
|
+
* block `bodyOf` knows (a saved SEO block such as `DefaultSeo`), that block's
|
|
76
|
+
* answer, following up to 8 saved blocks. Anything else (no `seo`, a variant,
|
|
77
|
+
* a block `bodyOf` doesn't know, a cycle) is `false`.
|
|
78
|
+
*/
|
|
79
|
+
export function seoNoIndex(seo, bodyOf) {
|
|
80
|
+
let node = seo;
|
|
81
|
+
const seen = new Set();
|
|
82
|
+
for (let hop = 0; hop <= MAX_SEO_HOPS; hop++) {
|
|
83
|
+
if (!isRecord(node))
|
|
84
|
+
return false;
|
|
85
|
+
if (typeof node.noIndexing === "boolean")
|
|
86
|
+
return node.noIndexing;
|
|
87
|
+
const ref = node.__resolveType;
|
|
88
|
+
if (bodyOf === undefined || typeof ref !== "string" || seen.has(ref))
|
|
89
|
+
return false;
|
|
90
|
+
seen.add(ref);
|
|
91
|
+
node = bodyOf(ref);
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The index entry for a block: its hash, its metadata when any, and its body
|
|
97
|
+
* when it is `CMS`. `bodyOf` as for `blockMeta`.
|
|
98
|
+
*/
|
|
99
|
+
export async function indexEntry(name, body, names, bodyOf) {
|
|
43
100
|
const entry = { version: await blockVersion(body) };
|
|
44
|
-
const meta = blockMeta(body, names);
|
|
101
|
+
const meta = blockMeta(body, names, bodyOf);
|
|
45
102
|
if (Object.keys(meta).length > 0)
|
|
46
103
|
entry.meta = meta;
|
|
47
104
|
if (name === INLINE_BLOCK)
|
package/dist/v8/blockMeta.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blockMeta.js","sourceRoot":"","sources":["../../src/v8/blockMeta.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"blockMeta.js","sourceRoot":"","sources":["../../src/v8/blockMeta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AA8B9B,oEAAoE;AACpE,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC;AAElC,4EAA4E;AAC5E,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB;;;;GAIG;AACH,MAAM,UAAU,SAAS,CACvB,IAAa,EACb,KAA8C,EAC9C,MAAe;IAEf,MAAM,IAAI,GAAc,EAAE,CAAC;IAC3B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACjC,IAAI,OAAO,IAAI,CAAC,aAAa,KAAK,QAAQ;QAAE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC;IAC3E,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;QAAE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACzD,MAAM,KAAK,GAAwB,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IACzE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC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AAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,KAAK,CAAC,KAA8C;IAC3D,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/v8/cli/check/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAqBH,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAItD,MAAM,WAAW,OAAO;IACtB,kFAAkF;IAClF,IAAI,EAAE,MAAM,CAAC;IACb,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;CAC/B;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/v8/cli/check/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAqBH,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAItD,MAAM,WAAW,OAAO;IACtB,kFAAkF;IAClF,IAAI,EAAE,MAAM,CAAC;IACb,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;CAC/B;AAgoCD,gEAAgE;AAChE,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,EAAE,CAe1E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,UAAQ,GAAG,MAAM,CAmBzE;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAerD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAcnE;AAED,iGAAiG;AACjG,wBAAgB,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,MAAM,CAKxD;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,wFAAwF;AACxF,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GAAG,WAAW,CAc/F"}
|
|
@@ -399,6 +399,119 @@ class Checker {
|
|
|
399
399
|
return { type: null };
|
|
400
400
|
return this.underlyingType(entry.__resolveType, [...chain, name]);
|
|
401
401
|
}
|
|
402
|
+
/**
|
|
403
|
+
* The saved blocks a reference to `name` walks, first to last (`last` is
|
|
404
|
+
* typed by a block type: `{ __resolveType: "site/sections/Footer.tsx" }`),
|
|
405
|
+
* or null when the walk loops or ends at a name that is nothing.
|
|
406
|
+
*/
|
|
407
|
+
referenceChain(name) {
|
|
408
|
+
const chain = [];
|
|
409
|
+
let cur = name;
|
|
410
|
+
while (this.canonicalType(cur) === null) {
|
|
411
|
+
const entry = own(this.saved.blocks, cur);
|
|
412
|
+
if (chain.includes(cur) || !entry || typeof entry.__resolveType !== "string")
|
|
413
|
+
return null;
|
|
414
|
+
chain.push(cur);
|
|
415
|
+
cur = entry.__resolveType;
|
|
416
|
+
}
|
|
417
|
+
return chain.length > 0 ? chain : null;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* The props a reference to `chain[0]` resolves with, the way the resolver
|
|
421
|
+
* merges them (mergeReference, hop by hop): the last block's props, each
|
|
422
|
+
* nearer block's over them, `overrides` on top, and the last block's type.
|
|
423
|
+
*/
|
|
424
|
+
mergedChain(chain, overrides) {
|
|
425
|
+
const merged = {};
|
|
426
|
+
for (const name of [...chain].reverse())
|
|
427
|
+
Object.assign(merged, this.saved.blocks[name]);
|
|
428
|
+
Object.assign(merged, overrides);
|
|
429
|
+
merged.__resolveType = this.saved.blocks[chain[chain.length - 1]].__resolveType;
|
|
430
|
+
return merged;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* A saved block typed as another saved block (`Footer-Island` =
|
|
434
|
+
* `{ "__resolveType": "Footer", "revealOnScroll": true }`) renders: the
|
|
435
|
+
* resolver follows the chain and merges each hop's props. Studio's editor
|
|
436
|
+
* doesn't: it follows one hop, looks up the form of the type it finds there
|
|
437
|
+
* (`Footer`, a saved block's name, has none) and shows an empty form, so
|
|
438
|
+
* the block can't be edited. A bare alias (`{ "__resolveType": "Footer" }`)
|
|
439
|
+
* is the same. Reported on the block itself, once, not at each reference
|
|
440
|
+
* to it: retyping the block fixes them all.
|
|
441
|
+
*
|
|
442
|
+
* A *reference* (a bare `{ "__resolveType": "Footer" }` in a page's
|
|
443
|
+
* sections, a variant, a lazy block or a prop) is fine: Studio follows its
|
|
444
|
+
* one hop to `Footer`, typed by its section, and edits that. See
|
|
445
|
+
* referenceOverrides for a reference that carries props of its own.
|
|
446
|
+
*/
|
|
447
|
+
savedBlockChain(name, entry) {
|
|
448
|
+
const chain = this.referenceChain(entry.__resolveType);
|
|
449
|
+
if (chain === null)
|
|
450
|
+
return null; // a cycle or a missing name: checkBlock reports it
|
|
451
|
+
const parent = chain[0];
|
|
452
|
+
const type = String(this.saved.blocks[chain[chain.length - 1]].__resolveType);
|
|
453
|
+
const inherited = this.inheritedProps(chain, entry);
|
|
454
|
+
const copy = inherited
|
|
455
|
+
? ` and copy in the props it inherits from "${parent}" (${inherited})`
|
|
456
|
+
: "";
|
|
457
|
+
return (`saved block "${name}" is typed as another saved block (${[name, ...chain, type].join(" → ")}): ` +
|
|
458
|
+
`it renders, but Studio's editor follows one hop, finds no form for "${parent}" and shows an empty one. ` +
|
|
459
|
+
`Set its __resolveType to "${type}"${copy}`);
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* The props a block that sets `own` gets from the chain it is typed by
|
|
463
|
+
* (`chain[0]` onward), listed for a message: up to 12, then "and N more".
|
|
464
|
+
*/
|
|
465
|
+
inheritedProps(chain, own) {
|
|
466
|
+
const keys = Object.keys(this.mergedChain(chain, {})).filter((key) => key !== "__resolveType" && !Object.hasOwn(own, key));
|
|
467
|
+
const more = keys.length > 12 ? ` and ${keys.length - 12} more` : "";
|
|
468
|
+
return keys.slice(0, 12).join(", ") + more;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* A reference that carries props of its own (a page section
|
|
472
|
+
* `{ "__resolveType": "Footer", "hasFixedNewsletter": true }`) renders with
|
|
473
|
+
* them merged over the saved block's (shallowly: `"seo": {}` replaces the
|
|
474
|
+
* saved `seo`). Studio's editor shows and edits the saved block itself: it
|
|
475
|
+
* ignores these props, saves every edit to the shared block (changing every
|
|
476
|
+
* page that uses it) and drops them on detach. Only a bare reference, or
|
|
477
|
+
* the block inlined (typed by its section, with the props copied in), is
|
|
478
|
+
* editable there.
|
|
479
|
+
*/
|
|
480
|
+
referenceOverrides(block, overrides) {
|
|
481
|
+
const name = block.__resolveType;
|
|
482
|
+
const chain = this.referenceChain(name);
|
|
483
|
+
const type = chain ? String(this.saved.blocks[chain[chain.length - 1]].__resolveType) : null;
|
|
484
|
+
const inherited = chain ? this.inheritedProps(chain, block) : "";
|
|
485
|
+
const copy = inherited
|
|
486
|
+
? ` and copy in the props of "${name}" it doesn't set (${inherited})`
|
|
487
|
+
: "";
|
|
488
|
+
const instead = type ? `, or inline it: set its __resolveType to "${type}"${copy}` : "";
|
|
489
|
+
return (`reference to saved block "${name}" carries its own props (${overrides.join(", ")}): ` +
|
|
490
|
+
`they apply when the page renders, but Studio's editor shows and edits "${name}" itself, ` +
|
|
491
|
+
`ignores them and saves edits to "${name}" for every use. ` +
|
|
492
|
+
`Make it a bare reference ({ "__resolveType": "${name}" })${instead}`);
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Why Studio's editor can't open a reference to the saved block `name`, if
|
|
496
|
+
* it can't: Studio (isSavedBlockResolveType) reads a name ending in "." and
|
|
497
|
+
* letters or digits ("Promo 2.0") as a module path, and never treats
|
|
498
|
+
* "__proto__" or "constructor" as a saved block. It then finds no form for
|
|
499
|
+
* the name and shows an empty one; the page still renders.
|
|
500
|
+
*/
|
|
501
|
+
unopenableName(name) {
|
|
502
|
+
const ending = /\.\w+$/.exec(name)?.[0];
|
|
503
|
+
const reason = ending
|
|
504
|
+
? `its name ends in "${ending}", so Studio's editor reads it as a module path`
|
|
505
|
+
: name === "__proto__" || name === "constructor"
|
|
506
|
+
? `Studio's editor never reads "${name}" as a saved block's name`
|
|
507
|
+
: null;
|
|
508
|
+
if (reason === null)
|
|
509
|
+
return null;
|
|
510
|
+
return (`reference to saved block "${name}" can't be edited in Studio: ${reason}, ` +
|
|
511
|
+
`finds no form for it and shows an empty one. Rename the saved block` +
|
|
512
|
+
(ending ? ` (no "." followed by letters or digits at the end)` : "") +
|
|
513
|
+
` and update its references`);
|
|
514
|
+
}
|
|
402
515
|
/**
|
|
403
516
|
* Whether `name` is the built-in itself here: the block map didn't define
|
|
404
517
|
* the same key (which replaces the built-in, schema included).
|
|
@@ -598,8 +711,11 @@ class Checker {
|
|
|
598
711
|
}
|
|
599
712
|
}
|
|
600
713
|
}
|
|
601
|
-
/**
|
|
602
|
-
|
|
714
|
+
/**
|
|
715
|
+
* Check a block that sits in `field`, dispatching on its `__resolveType`.
|
|
716
|
+
* `top`: it is a saved block itself, not a value in one.
|
|
717
|
+
*/
|
|
718
|
+
checkBlock(ctx, block, path, field, top = false) {
|
|
603
719
|
const name = block.__resolveType;
|
|
604
720
|
const type = this.canonicalType(name);
|
|
605
721
|
if (type === null) {
|
|
@@ -619,20 +735,26 @@ class Checker {
|
|
|
619
735
|
}
|
|
620
736
|
if (underlying === null)
|
|
621
737
|
return; // the saved block reports its own problem
|
|
738
|
+
const unopenable = top ? null : this.unopenableName(name);
|
|
739
|
+
if (unopenable)
|
|
740
|
+
this.report(ctx, path, unopenable);
|
|
622
741
|
const fit = this.fitProblem(underlying, field);
|
|
623
742
|
if (fit) {
|
|
624
743
|
this.report(ctx, path, `saved block "${name}" (a "${underlying}") doesn't fit here: ${fit}`);
|
|
625
744
|
return;
|
|
626
745
|
}
|
|
627
|
-
// Overrides are merged over the saved arguments for this use
|
|
746
|
+
// Overrides are merged over the saved arguments for this use, along the
|
|
747
|
+
// whole chain of saved blocks (the resolver's mergeReference, per hop).
|
|
628
748
|
const overrides = Object.keys(block).filter((k) => k !== "__resolveType");
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
749
|
+
const chain = this.referenceChain(name);
|
|
750
|
+
if (overrides.length > 0 && chain) {
|
|
751
|
+
// A saved block typed this way is savedBlockChain's (run reports it).
|
|
752
|
+
if (!top)
|
|
753
|
+
this.report(ctx, path, this.referenceOverrides(block, overrides));
|
|
754
|
+
const merged = this.mergedChain(chain, block);
|
|
755
|
+
if (this.isCalendar(merged.__resolveType))
|
|
634
756
|
this.checkCalendar(ctx, merged, path);
|
|
635
|
-
else
|
|
757
|
+
else
|
|
636
758
|
this.checkProps(ctx, merged, path, true);
|
|
637
759
|
}
|
|
638
760
|
return;
|
|
@@ -813,7 +935,13 @@ class Checker {
|
|
|
813
935
|
if (V7_REDIRECT_TYPES.has(entry.__resolveType) && !this.canonicalType(entry.__resolveType)) {
|
|
814
936
|
continue;
|
|
815
937
|
}
|
|
816
|
-
this.
|
|
938
|
+
if (this.canonicalType(entry.__resolveType) === null &&
|
|
939
|
+
Object.hasOwn(this.saved.blocks, entry.__resolveType)) {
|
|
940
|
+
const chained = this.savedBlockChain(name, entry);
|
|
941
|
+
if (chained)
|
|
942
|
+
this.report(ctx, "", chained);
|
|
943
|
+
}
|
|
944
|
+
this.checkBlock(ctx, entry, "", null, true);
|
|
817
945
|
}
|
|
818
946
|
problems.push(...this.builtInOverrides());
|
|
819
947
|
problems.push(...this.routeProblems());
|