@decocms/blocks 8.9.1 → 8.10.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 +1 -1
- package/dist/index.js.map +1 -1
- package/dist/protocol/channel.d.ts +98 -0
- package/dist/protocol/channel.d.ts.map +1 -0
- package/dist/protocol/channel.js +58 -0
- package/dist/protocol/channel.js.map +1 -0
- package/dist/protocol/client.js +2 -2
- package/dist/protocol/client.js.map +1 -1
- package/dist/protocol/conformance/blockMetaVectors.json +214 -0
- package/dist/protocol/conformance/contentHashFixtures.d.ts +22 -0
- package/dist/protocol/conformance/contentHashFixtures.d.ts.map +1 -1
- package/dist/protocol/conformance/contentHashFixtures.js +55 -0
- package/dist/protocol/conformance/contentHashFixtures.js.map +1 -1
- package/dist/protocol/conformance/index.d.ts +2 -1
- package/dist/protocol/conformance/index.d.ts.map +1 -1
- package/dist/protocol/conformance/index.js +2 -1
- package/dist/protocol/conformance/index.js.map +1 -1
- package/dist/protocol/conformance/vectors.d.ts +33 -0
- package/dist/protocol/conformance/vectors.d.ts.map +1 -0
- package/dist/protocol/conformance/vectors.js +3 -0
- package/dist/protocol/conformance/vectors.js.map +1 -0
- package/dist/protocol/index.d.ts +11 -1
- package/dist/protocol/index.d.ts.map +1 -1
- package/dist/protocol/index.js +11 -1
- package/dist/protocol/index.js.map +1 -1
- package/dist/protocol/keys.d.ts +1 -1
- package/dist/protocol/keys.js +1 -1
- package/dist/v8/background.d.ts +13 -0
- package/dist/v8/background.d.ts.map +1 -1
- package/dist/v8/background.js +41 -0
- package/dist/v8/background.js.map +1 -1
- package/dist/v8/blockMeta.d.ts +27 -0
- package/dist/v8/blockMeta.d.ts.map +1 -0
- package/dist/v8/blockMeta.js +75 -0
- package/dist/v8/blockMeta.js.map +1 -0
- package/dist/v8/blockStore.d.ts +43 -0
- package/dist/v8/blockStore.d.ts.map +1 -0
- package/dist/v8/blockStore.js +95 -0
- package/dist/v8/blockStore.js.map +1 -0
- package/dist/v8/boundedJson.d.ts +5 -0
- package/dist/v8/boundedJson.d.ts.map +1 -1
- package/dist/v8/boundedJson.js +10 -2
- package/dist/v8/boundedJson.js.map +1 -1
- package/dist/v8/boundedMap.d.ts +19 -0
- package/dist/v8/boundedMap.d.ts.map +1 -0
- package/dist/v8/boundedMap.js +52 -0
- package/dist/v8/boundedMap.js.map +1 -0
- package/dist/v8/builtins/data.d.ts +18 -2
- package/dist/v8/builtins/data.d.ts.map +1 -1
- package/dist/v8/builtins/data.js +17 -1
- package/dist/v8/builtins/data.js.map +1 -1
- package/dist/v8/builtins/index.d.ts.map +1 -1
- package/dist/v8/builtins/index.js +2 -1
- package/dist/v8/builtins/index.js.map +1 -1
- package/dist/v8/builtins/legacy.d.ts +6 -3
- package/dist/v8/builtins/legacy.d.ts.map +1 -1
- package/dist/v8/builtins/legacy.js +6 -3
- package/dist/v8/builtins/legacy.js.map +1 -1
- package/dist/v8/canonical.d.ts +8 -0
- package/dist/v8/canonical.d.ts.map +1 -1
- package/dist/v8/canonical.js +15 -0
- package/dist/v8/canonical.js.map +1 -1
- package/dist/v8/cli/builtins.d.ts.map +1 -1
- package/dist/v8/cli/builtins.js +1 -0
- package/dist/v8/cli/builtins.js.map +1 -1
- package/dist/v8/cli/check/index.d.ts +10 -0
- package/dist/v8/cli/check/index.d.ts.map +1 -1
- package/dist/v8/cli/check/index.js +91 -7
- package/dist/v8/cli/check/index.js.map +1 -1
- package/dist/v8/cli/content.d.ts +12 -25
- package/dist/v8/cli/content.d.ts.map +1 -1
- package/dist/v8/cli/content.js +46 -75
- package/dist/v8/cli/content.js.map +1 -1
- package/dist/v8/cli/index.d.ts +1 -2
- package/dist/v8/cli/index.d.ts.map +1 -1
- package/dist/v8/cli/index.js +1 -2
- package/dist/v8/cli/index.js.map +1 -1
- package/dist/v8/cli/remote/commands.d.ts +71 -0
- package/dist/v8/cli/remote/commands.d.ts.map +1 -0
- package/dist/v8/cli/remote/commands.js +644 -0
- package/dist/v8/cli/remote/commands.js.map +1 -0
- package/dist/v8/cli/remote/diff.d.ts +15 -0
- package/dist/v8/cli/remote/diff.d.ts.map +1 -0
- package/dist/v8/cli/remote/diff.js +102 -0
- package/dist/v8/cli/remote/diff.js.map +1 -0
- package/dist/v8/cli/remote/env.d.ts +35 -0
- package/dist/v8/cli/remote/env.d.ts.map +1 -0
- package/dist/v8/cli/remote/env.js +84 -0
- package/dist/v8/cli/remote/env.js.map +1 -0
- package/dist/v8/cli/remote/http.d.ts +149 -0
- package/dist/v8/cli/remote/http.d.ts.map +1 -0
- package/dist/v8/cli/remote/http.js +381 -0
- package/dist/v8/cli/remote/http.js.map +1 -0
- package/dist/v8/cli/remote/local.d.ts +90 -0
- package/dist/v8/cli/remote/local.d.ts.map +1 -0
- package/dist/v8/cli/remote/local.js +309 -0
- package/dist/v8/cli/remote/local.js.map +1 -0
- package/dist/v8/cli/root.d.ts +29 -0
- package/dist/v8/cli/root.d.ts.map +1 -1
- package/dist/v8/cli/root.js +28 -0
- package/dist/v8/cli/root.js.map +1 -1
- package/dist/v8/cli/run.d.ts +11 -1
- package/dist/v8/cli/run.d.ts.map +1 -1
- package/dist/v8/cli/run.js +281 -124
- package/dist/v8/cli/run.js.map +1 -1
- package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -1
- package/dist/v8/cli/schema/builtinSchemas.js +28 -10
- package/dist/v8/cli/schema/builtinSchemas.js.map +1 -1
- package/dist/v8/cli/schema/generate.js +1 -1
- package/dist/v8/cli/schema/generate.js.map +1 -1
- package/dist/v8/client.d.ts +9 -9
- package/dist/v8/client.d.ts.map +1 -1
- package/dist/v8/client.js +138 -50
- package/dist/v8/client.js.map +1 -1
- package/dist/v8/cms.d.ts +2 -1
- package/dist/v8/cms.d.ts.map +1 -1
- package/dist/v8/cms.js +55 -46
- package/dist/v8/cms.js.map +1 -1
- package/dist/v8/content.d.ts +39 -78
- package/dist/v8/content.d.ts.map +1 -1
- package/dist/v8/content.js +155 -195
- package/dist/v8/content.js.map +1 -1
- package/dist/v8/contentIndex.d.ts +71 -0
- package/dist/v8/contentIndex.d.ts.map +1 -0
- package/dist/v8/contentIndex.js +137 -0
- package/dist/v8/contentIndex.js.map +1 -0
- package/dist/v8/draft.d.ts +7 -7
- package/dist/v8/draft.d.ts.map +1 -1
- package/dist/v8/draft.js +10 -9
- package/dist/v8/draft.js.map +1 -1
- package/dist/v8/draftChanges.d.ts +59 -32
- package/dist/v8/draftChanges.d.ts.map +1 -1
- package/dist/v8/draftChanges.js +139 -75
- package/dist/v8/draftChanges.js.map +1 -1
- package/dist/v8/errors.d.ts +21 -0
- package/dist/v8/errors.d.ts.map +1 -1
- package/dist/v8/errors.js +22 -0
- package/dist/v8/errors.js.map +1 -1
- package/dist/v8/hostedSource.d.ts +57 -0
- package/dist/v8/hostedSource.d.ts.map +1 -0
- package/dist/v8/hostedSource.js +18 -0
- package/dist/v8/hostedSource.js.map +1 -0
- package/dist/v8/identity.d.ts +1 -1
- package/dist/v8/identity.js +1 -1
- package/dist/v8/index.d.ts +1 -0
- package/dist/v8/index.d.ts.map +1 -1
- package/dist/v8/index.js +1 -0
- package/dist/v8/index.js.map +1 -1
- package/dist/v8/matchRoute.js +7 -4
- package/dist/v8/matchRoute.js.map +1 -1
- package/dist/v8/pin.d.ts +34 -0
- package/dist/v8/pin.d.ts.map +1 -0
- package/dist/v8/pin.js +156 -0
- package/dist/v8/pin.js.map +1 -0
- package/dist/v8/preview/StudioBridge.d.ts +8 -8
- package/dist/v8/preview/StudioBridge.d.ts.map +1 -1
- package/dist/v8/preview/StudioBridge.js +8 -10
- package/dist/v8/preview/StudioBridge.js.map +1 -1
- package/dist/v8/preview/StudioChannel.d.ts +51 -0
- package/dist/v8/preview/StudioChannel.d.ts.map +1 -0
- package/dist/v8/preview/StudioChannel.js +104 -0
- package/dist/v8/preview/StudioChannel.js.map +1 -0
- package/dist/v8/preview/index.d.ts +3 -0
- package/dist/v8/preview/index.d.ts.map +1 -1
- package/dist/v8/preview/index.js +3 -0
- package/dist/v8/preview/index.js.map +1 -1
- package/dist/v8/remoteLoader.d.ts +42 -5
- package/dist/v8/remoteLoader.d.ts.map +1 -1
- package/dist/v8/remoteLoader.js +317 -259
- package/dist/v8/remoteLoader.js.map +1 -1
- package/dist/v8/resolver.d.ts +22 -8
- package/dist/v8/resolver.d.ts.map +1 -1
- package/dist/v8/resolver.js +37 -32
- package/dist/v8/resolver.js.map +1 -1
- package/dist/v8/revisionId.d.ts +11 -0
- package/dist/v8/revisionId.d.ts.map +1 -0
- package/dist/v8/revisionId.js +13 -0
- package/dist/v8/revisionId.js.map +1 -0
- package/dist/v8/settings.d.ts +6 -6
- package/dist/v8/settings.d.ts.map +1 -1
- package/dist/v8/settings.js +8 -7
- package/dist/v8/settings.js.map +1 -1
- package/dist/v8/telemetry.d.ts +4 -2
- package/dist/v8/telemetry.d.ts.map +1 -1
- package/dist/v8/telemetry.js +2 -2
- package/dist/v8/telemetry.js.map +1 -1
- package/dist/v8/types.d.ts +52 -40
- package/dist/v8/types.d.ts.map +1 -1
- package/dist/v8/variants.d.ts +7 -2
- package/dist/v8/variants.d.ts.map +1 -1
- package/dist/v8/variants.js +21 -24
- package/dist/v8/variants.js.map +1 -1
- package/dist/v8/vite/index.d.ts +2 -2
- package/dist/v8/vite/index.js +1 -1
- package/dist/v8/vite/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/protocol/channel.ts +127 -0
- package/src/protocol/client.ts +2 -2
- package/src/protocol/conformance/blockMetaVectors.json +214 -0
- package/src/protocol/conformance/contentHashFixtures.ts +74 -0
- package/src/protocol/conformance/index.ts +9 -1
- package/src/protocol/conformance/vectors.ts +36 -0
- package/src/protocol/index.ts +32 -0
- package/src/protocol/keys.ts +1 -1
- package/src/v8/background.ts +42 -0
- package/src/v8/blockMeta.ts +100 -0
- package/src/v8/blockStore.ts +124 -0
- package/src/v8/boundedJson.ts +20 -2
- package/src/v8/boundedMap.ts +53 -0
- package/src/v8/builtins/data.ts +26 -2
- package/src/v8/builtins/index.ts +2 -1
- package/src/v8/builtins/legacy.ts +6 -3
- package/src/v8/canonical.ts +15 -0
- package/src/v8/cli/builtins.ts +1 -0
- package/src/v8/cli/check/index.ts +97 -7
- package/src/v8/cli/content.ts +49 -91
- package/src/v8/cli/index.ts +1 -2
- package/src/v8/cli/remote/commands.ts +834 -0
- package/src/v8/cli/remote/diff.ts +100 -0
- package/src/v8/cli/remote/env.ts +107 -0
- package/src/v8/cli/remote/http.ts +484 -0
- package/src/v8/cli/remote/local.ts +343 -0
- package/src/v8/cli/root.ts +40 -0
- package/src/v8/cli/run.ts +333 -136
- package/src/v8/cli/schema/builtinSchemas.ts +29 -10
- package/src/v8/cli/schema/generate.ts +1 -1
- package/src/v8/client.ts +162 -60
- package/src/v8/cms.ts +62 -53
- package/src/v8/content.ts +179 -229
- package/src/v8/contentIndex.ts +183 -0
- package/src/v8/draft.ts +15 -14
- package/src/v8/draftChanges.ts +151 -85
- package/src/v8/errors.ts +37 -0
- package/src/v8/hostedSource.ts +67 -0
- package/src/v8/identity.ts +1 -1
- package/src/v8/index.ts +1 -0
- package/src/v8/matchRoute.ts +7 -4
- package/src/v8/pin.ts +176 -0
- package/src/v8/preview/StudioBridge.ts +8 -10
- package/src/v8/preview/StudioChannel.ts +116 -0
- package/src/v8/preview/index.ts +3 -0
- package/src/v8/remoteLoader.ts +350 -286
- package/src/v8/resolver.ts +56 -33
- package/src/v8/revisionId.ts +14 -0
- package/src/v8/settings.ts +10 -9
- package/src/v8/telemetry.ts +3 -3
- package/src/v8/types.ts +52 -40
- package/src/v8/variants.ts +30 -26
- package/src/v8/vite/index.ts +3 -3
- package/dist/v8/cli/serve/server.d.ts +0 -29
- package/dist/v8/cli/serve/server.d.ts.map +0 -1
- package/dist/v8/cli/serve/server.js +0 -296
- package/dist/v8/cli/serve/server.js.map +0 -1
- package/src/v8/cli/serve/server.ts +0 -348
package/src/v8/boundedJson.ts
CHANGED
|
@@ -18,6 +18,24 @@ export async function readBoundedJson(
|
|
|
18
18
|
label: string,
|
|
19
19
|
maxBytes: number,
|
|
20
20
|
): Promise<unknown> {
|
|
21
|
+
return (await readBoundedJsonSized(response, label, maxBytes)).value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** `readBoundedJson`, plus the length of the JSON text (what a byte-bounded cache counts). */
|
|
25
|
+
export async function readBoundedJsonSized(
|
|
26
|
+
response: Response,
|
|
27
|
+
label: string,
|
|
28
|
+
maxBytes: number,
|
|
29
|
+
): Promise<{ value: unknown; bytes: number }> {
|
|
30
|
+
const text = await readBoundedText(response, label, maxBytes);
|
|
31
|
+
return { value: JSON.parse(text), bytes: text.length };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function readBoundedText(
|
|
35
|
+
response: Response,
|
|
36
|
+
label: string,
|
|
37
|
+
maxBytes: number,
|
|
38
|
+
): Promise<string> {
|
|
21
39
|
const tooLarge = () => new Error(`${label}: larger than ${maxBytes} bytes`);
|
|
22
40
|
if (Number(response.headers.get("content-length")) > maxBytes) {
|
|
23
41
|
await response.body?.cancel();
|
|
@@ -26,7 +44,7 @@ export async function readBoundedJson(
|
|
|
26
44
|
if (response.body === null) {
|
|
27
45
|
const text = await response.text();
|
|
28
46
|
if (text.length > maxBytes) throw tooLarge();
|
|
29
|
-
return
|
|
47
|
+
return text;
|
|
30
48
|
}
|
|
31
49
|
const reader = response.body.getReader();
|
|
32
50
|
const decoder = new TextDecoder();
|
|
@@ -43,5 +61,5 @@ export async function readBoundedJson(
|
|
|
43
61
|
parts.push(decoder.decode(value, { stream: true }));
|
|
44
62
|
}
|
|
45
63
|
parts.push(decoder.decode());
|
|
46
|
-
return
|
|
64
|
+
return parts.join("");
|
|
47
65
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Map that forgets its least recently used entries past `limit`, counted by
|
|
3
|
+
* `size` (one per entry unless given). An entry larger than the limit on its
|
|
4
|
+
* own is kept until the next `set`.
|
|
5
|
+
*/
|
|
6
|
+
export class BoundedMap<K, V> {
|
|
7
|
+
readonly #map = new Map<K, V>();
|
|
8
|
+
#total = 0;
|
|
9
|
+
constructor(
|
|
10
|
+
readonly limit: number,
|
|
11
|
+
readonly size: (value: V) => number = () => 1,
|
|
12
|
+
) {}
|
|
13
|
+
|
|
14
|
+
get(key: K): V | undefined {
|
|
15
|
+
const value = this.#map.get(key);
|
|
16
|
+
if (value !== undefined) {
|
|
17
|
+
this.#map.delete(key);
|
|
18
|
+
this.#map.set(key, value);
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
has(key: K): boolean {
|
|
24
|
+
return this.#map.has(key);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
set(key: K, value: V): void {
|
|
28
|
+
this.delete(key);
|
|
29
|
+
this.#map.set(key, value);
|
|
30
|
+
this.#total += this.size(value);
|
|
31
|
+
for (const [oldest, old] of this.#map) {
|
|
32
|
+
if (this.#total <= this.limit || oldest === key) break;
|
|
33
|
+
this.#map.delete(oldest);
|
|
34
|
+
this.#total -= this.size(old);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
delete(key: K): void {
|
|
39
|
+
if (!this.#map.has(key)) return;
|
|
40
|
+
this.#total -= this.size(this.#map.get(key) as V);
|
|
41
|
+
this.#map.delete(key);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
clear(): void {
|
|
45
|
+
this.#map.clear();
|
|
46
|
+
this.#total = 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The total size held. */
|
|
50
|
+
get total(): number {
|
|
51
|
+
return this.#total;
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/v8/builtins/data.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Analytics, CMSSettings, Redirect, Telemetry } from "../types.ts";
|
|
1
|
+
import type { Analytics, CMSSettings, LegacyRedirect, Redirect, Telemetry } from "../types.ts";
|
|
2
2
|
|
|
3
3
|
/** The hosted Deco CMS collector: where page views go when `collector` is left out. */
|
|
4
4
|
export const HOSTED_ANALYTICS_COLLECTOR = "https://d.lilstts.com/events";
|
|
@@ -15,9 +15,33 @@ export const DECO_ANALYTICS_SCRIPT = "/_dq/a.js";
|
|
|
15
15
|
*/
|
|
16
16
|
export const page = <P>(props: P): P => props;
|
|
17
17
|
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* `redirect`: returns its arguments as saved. Still a built-in, so a v7 rule
|
|
20
|
+
* block resolves, but no longer routed: `client.redirects()` reads only the
|
|
21
|
+
* redirects block (`deco check` warns on every `redirect` block).
|
|
22
|
+
*/
|
|
19
23
|
export const redirect = (props: Redirect): Redirect => props;
|
|
20
24
|
|
|
25
|
+
/** The type of the site's one redirects block (canonically saved as `Redirects`). */
|
|
26
|
+
export const REDIRECTS_TYPE = "redirects";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* `redirects`: the site's whole list of rules, one block (routing needs every
|
|
30
|
+
* rule, so it is one cached fetch). Each rule has either shape `matchRoute`
|
|
31
|
+
* reads: the flat `{ from, to, permanent?, status?, discardQueryParameters? }`
|
|
32
|
+
* or v7's nested `{ redirect: { from, to, type? } }`; anything that isn't an
|
|
33
|
+
* object is left out.
|
|
34
|
+
*/
|
|
35
|
+
export const redirects = (props: {
|
|
36
|
+
redirects?: Array<Redirect | LegacyRedirect>;
|
|
37
|
+
}): Array<Redirect | LegacyRedirect> =>
|
|
38
|
+
Array.isArray(props?.redirects)
|
|
39
|
+
? props.redirects.filter(
|
|
40
|
+
(rule): rule is Redirect | LegacyRedirect =>
|
|
41
|
+
typeof rule === "object" && rule !== null && !Array.isArray(rule),
|
|
42
|
+
)
|
|
43
|
+
: [];
|
|
44
|
+
|
|
21
45
|
/** The `telemetry` section's defaults (sample rates before code's caps). */
|
|
22
46
|
export const TELEMETRY_DEFAULTS: Readonly<Required<Telemetry>> = Object.freeze({
|
|
23
47
|
enabled: true,
|
package/src/v8/builtins/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BlockFunction } from "../types.ts";
|
|
2
2
|
import { CALENDAR_TYPE, calendar, campaign } from "./campaigns.ts";
|
|
3
|
-
import { cmsSettings, page, redirect, SETTINGS_TYPE } from "./data.ts";
|
|
3
|
+
import { cmsSettings, page, REDIRECTS_TYPE, redirect, redirects, SETTINGS_TYPE } from "./data.ts";
|
|
4
4
|
import { experiment, SPLIT_TRAFFIC_TYPE, splitTraffic } from "./experiments.ts";
|
|
5
5
|
import { lazy } from "./lazy.ts";
|
|
6
6
|
import { always, never } from "./matchers.ts";
|
|
@@ -16,6 +16,7 @@ export const builtIns: Readonly<Record<string, BlockFunction>> = Object.freeze({
|
|
|
16
16
|
campaign,
|
|
17
17
|
page,
|
|
18
18
|
redirect,
|
|
19
|
+
[REDIRECTS_TYPE]: redirects,
|
|
19
20
|
[SETTINGS_TYPE]: cmsSettings,
|
|
20
21
|
[SPLIT_TRAFFIC_TYPE]: splitTraffic,
|
|
21
22
|
[CALENDAR_TYPE]: calendar,
|
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
* without a block-map entry (see /next/studio-compatibility#well-known-types-and-the-alias-table
|
|
5
5
|
* and /next/renames-and-migrations#rename-a-type-with-an-alias).
|
|
6
6
|
*
|
|
7
|
-
* A snapshot's own `aliases` (the table
|
|
7
|
+
* A snapshot's own `aliases` (the table the content module carries) win over these, and a key in the block map wins over
|
|
8
8
|
* both, so a site can still register a legacy name itself.
|
|
9
9
|
*
|
|
10
10
|
* - Redirects keep v7's nested shape: `redirect` returns its arguments as
|
|
11
|
-
* saved, and `matchRoute` accepts both shapes.
|
|
11
|
+
* saved, and `matchRoute` accepts both shapes. v7's `website/loaders/redirects.ts`
|
|
12
|
+
* has no alias: v8 routes only a block typed `redirects`, so the v7-to-v8
|
|
13
|
+
* migration folds every v7 redirect block into `Redirects` and `deco check`
|
|
14
|
+
* warns about one left over.
|
|
12
15
|
* - `website/loaders/secret.ts` has no alias: secrets live in the deploy
|
|
13
16
|
* platform, read by the site's code and passed as params (see
|
|
14
17
|
* /next/renames-and-migrations#secrets), so a leftover v7 secret block
|
|
@@ -20,7 +23,7 @@ import { isPlainObject, type JsonObject } from "../json.ts";
|
|
|
20
23
|
|
|
21
24
|
/**
|
|
22
25
|
* Legacy type name → built-in. The one table: the runtime falls back to it,
|
|
23
|
-
* and `deco schema`
|
|
26
|
+
* and `deco schema` and the content module write it into the schema and the content
|
|
24
27
|
* module. Exactly the names the site editor's special screens look for
|
|
25
28
|
* (/next/studio-compatibility#well-known-types-and-the-alias-table); other
|
|
26
29
|
* legacy names (`$live/…`, the per-kind multivariate files, the date
|
package/src/v8/canonical.ts
CHANGED
|
@@ -104,3 +104,18 @@ export const CONTENT_HASH_FORMAT = 1;
|
|
|
104
104
|
export async function computeContentRevision(blocks: Record<string, unknown>): Promise<string> {
|
|
105
105
|
return sha256Hex(canonicalJson(blocks));
|
|
106
106
|
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* A saved block's version: the first 16 bytes of SHA-256 over its canonical
|
|
110
|
+
* JSON, written as 22 characters of base64url without padding. The one
|
|
111
|
+
* definition `ifMatch`, conflicts, `blocks.list` versions and the CLI's
|
|
112
|
+
* `.deco/pull.json` share; `blockVersionFixtures` (in
|
|
113
|
+
* `@decocms/blocks/protocol/conformance`) pins its output.
|
|
114
|
+
*/
|
|
115
|
+
export async function blockVersion(block: unknown): Promise<string> {
|
|
116
|
+
const bytes = new TextEncoder().encode(canonicalJson(block));
|
|
117
|
+
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", bytes as BufferSource));
|
|
118
|
+
let binary = "";
|
|
119
|
+
for (const byte of digest.subarray(0, 16)) binary += String.fromCharCode(byte);
|
|
120
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
121
|
+
}
|
package/src/v8/cli/builtins.ts
CHANGED
|
@@ -27,6 +27,7 @@ export const BUILT_IN_USES: Readonly<Record<string, string>> = Object.freeze({
|
|
|
27
27
|
"Studio's campaign rules rely on it, each naming a campaign of the saved block campaigns",
|
|
28
28
|
page: "Studio's page list and page editor rely on it",
|
|
29
29
|
redirect: "Studio's redirect list relies on it",
|
|
30
|
+
redirects: "the site's routing reads its rules from the saved block Redirects, through it",
|
|
30
31
|
"cms-settings": "the saved block CMS relies on it, and Studio's settings edit that block",
|
|
31
32
|
"split-traffic":
|
|
32
33
|
"the saved block experiments relies on it, and Studio's Experiments view edits its percentages",
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
CAMPAIGNS_BLOCK,
|
|
27
27
|
campaignTime,
|
|
28
28
|
} from "../../builtins/campaigns.ts";
|
|
29
|
-
import { SETTINGS_BLOCK, SETTINGS_TYPE } from "../../builtins/data.ts";
|
|
29
|
+
import { REDIRECTS_TYPE, SETTINGS_BLOCK, SETTINGS_TYPE } from "../../builtins/data.ts";
|
|
30
30
|
import {
|
|
31
31
|
EXPERIMENT_RULE,
|
|
32
32
|
EXPERIMENTS_BLOCK,
|
|
@@ -54,6 +54,20 @@ export interface Problem {
|
|
|
54
54
|
|
|
55
55
|
type Json = any;
|
|
56
56
|
const DOC_ID = "deco";
|
|
57
|
+
/** The per-rule redirect type: it resolves, but routing reads only the redirects block. */
|
|
58
|
+
const REDIRECT_TYPE = "redirect";
|
|
59
|
+
/**
|
|
60
|
+
* v7's redirect block types, per-rule and list: v8 routes neither (only a
|
|
61
|
+
* block typed `redirects`), so their rules belong in the Redirects block.
|
|
62
|
+
* `website/loaders/redirect.ts` still resolves (an alias of `redirect`);
|
|
63
|
+
* `website/loaders/redirects.ts` has no alias.
|
|
64
|
+
*/
|
|
65
|
+
const V7_REDIRECT_TYPES: ReadonlySet<string> = new Set([
|
|
66
|
+
"website/loaders/redirect.ts",
|
|
67
|
+
"website/loaders/redirects.ts",
|
|
68
|
+
]);
|
|
69
|
+
/** The block routing reads its redirects from, canonically. */
|
|
70
|
+
const REDIRECTS_BLOCK = "Redirects";
|
|
57
71
|
|
|
58
72
|
/** JSON-parsed objects only, so any non-array object is a plain one. */
|
|
59
73
|
function isObject(value: unknown): value is Record<string, Json> {
|
|
@@ -90,6 +104,16 @@ const FOLDED_BUILT_INS: Record<string, string> = {
|
|
|
90
104
|
"website/loaders/secret.ts": SECRETS_MOVED,
|
|
91
105
|
};
|
|
92
106
|
|
|
107
|
+
/**
|
|
108
|
+
* A `__resolveType` that names no block type, built-in, alias or saved block:
|
|
109
|
+
* what a delete leaves behind (a section, banner or saved rule), or a block
|
|
110
|
+
* type the site doesn't export. Block types are bare keys too, so the check
|
|
111
|
+
* can't tell which and names both.
|
|
112
|
+
*/
|
|
113
|
+
function missingName(name: string): string {
|
|
114
|
+
return `no saved block or block type "${name}"`;
|
|
115
|
+
}
|
|
116
|
+
|
|
93
117
|
/** A `CMS` block saved with preview hosts, which Studio keeps now (in the release it publishes). */
|
|
94
118
|
const PREVIEW_FIELD_GONE =
|
|
95
119
|
"the site editor now keeps the addresses this site can be previewed on, so this field isn't read any more: you can delete it";
|
|
@@ -657,7 +681,7 @@ class Checker {
|
|
|
657
681
|
? oldDateRuleProblem(block)
|
|
658
682
|
: Object.hasOwn(FOLDED_BUILT_INS, name)
|
|
659
683
|
? `unknown block type "${name}": ${FOLDED_BUILT_INS[name]}`
|
|
660
|
-
:
|
|
684
|
+
: missingName(name),
|
|
661
685
|
);
|
|
662
686
|
return;
|
|
663
687
|
}
|
|
@@ -726,7 +750,6 @@ class Checker {
|
|
|
726
750
|
ctx,
|
|
727
751
|
joinPath(path, "/name"),
|
|
728
752
|
`no test "${name}" in the saved block "${EXPERIMENTS_BLOCK}": this rule is always false`,
|
|
729
|
-
"warning",
|
|
730
753
|
);
|
|
731
754
|
}
|
|
732
755
|
return;
|
|
@@ -751,7 +774,6 @@ class Checker {
|
|
|
751
774
|
ctx,
|
|
752
775
|
joinPath(path, "/name"),
|
|
753
776
|
`no campaign "${campaign}" in the saved block "${CAMPAIGNS_BLOCK}": this rule is always false`,
|
|
754
|
-
"warning",
|
|
755
777
|
);
|
|
756
778
|
}
|
|
757
779
|
return;
|
|
@@ -913,10 +935,66 @@ class Checker {
|
|
|
913
935
|
this.report(ctx, "preview", PREVIEW_FIELD_GONE, "warning");
|
|
914
936
|
continue;
|
|
915
937
|
}
|
|
938
|
+
// A v7 redirect block left over: redirectBlockProblems says to fold it into
|
|
939
|
+
// Redirects. With no alias its type is unknown here, which isn't an error.
|
|
940
|
+
if (V7_REDIRECT_TYPES.has(entry.__resolveType) && !this.canonicalType(entry.__resolveType)) {
|
|
941
|
+
continue;
|
|
942
|
+
}
|
|
916
943
|
this.checkBlock(ctx, entry, "", null);
|
|
917
944
|
}
|
|
918
945
|
problems.push(...this.builtInOverrides());
|
|
919
946
|
problems.push(...this.routeProblems());
|
|
947
|
+
problems.push(...this.redirectBlockProblems());
|
|
948
|
+
return problems;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* Routing reads its redirects from one block: the first `redirects`-typed
|
|
953
|
+
* one in code-unit name order (see /next/routing). A per-rule `redirect`
|
|
954
|
+
* block still resolves but is never routed, and a second `redirects`
|
|
955
|
+
* block is ignored: both are warnings. So is a block under one of v7's
|
|
956
|
+
* redirect types, which v8 doesn't route: its rules belong in Redirects.
|
|
957
|
+
*/
|
|
958
|
+
private redirectBlockProblems(): Problem[] {
|
|
959
|
+
const problems: Problem[] = [];
|
|
960
|
+
let routed: string | null = null;
|
|
961
|
+
const names = Object.keys(this.saved.blocks).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
962
|
+
for (const name of names) {
|
|
963
|
+
const entry = this.saved.blocks[name];
|
|
964
|
+
if (!isBlock(entry)) continue;
|
|
965
|
+
const file = `.deco/blocks/${this.saved.files[name]}`;
|
|
966
|
+
if (V7_REDIRECT_TYPES.has(entry.__resolveType)) {
|
|
967
|
+
problems.push({
|
|
968
|
+
file,
|
|
969
|
+
path: "",
|
|
970
|
+
severity: "warning",
|
|
971
|
+
message:
|
|
972
|
+
`v7 redirect block (type ${entry.__resolveType}) isn't routed: v8 routes only a block ` +
|
|
973
|
+
`typed "${REDIRECTS_TYPE}". Fold its rules into the "${REDIRECTS_BLOCK}" block ` +
|
|
974
|
+
`(type "${REDIRECTS_TYPE}"; v7's type permanent is permanent: true) and delete it`,
|
|
975
|
+
});
|
|
976
|
+
continue;
|
|
977
|
+
}
|
|
978
|
+
const { type } = this.underlyingType(entry.__resolveType);
|
|
979
|
+
if (type !== REDIRECT_TYPE && type !== REDIRECTS_TYPE) continue;
|
|
980
|
+
if (type === REDIRECT_TYPE) {
|
|
981
|
+
problems.push({
|
|
982
|
+
file,
|
|
983
|
+
path: "",
|
|
984
|
+
severity: "warning",
|
|
985
|
+
message: "not routed; move it into the redirects block",
|
|
986
|
+
});
|
|
987
|
+
} else if (routed === null) {
|
|
988
|
+
routed = name;
|
|
989
|
+
} else {
|
|
990
|
+
problems.push({
|
|
991
|
+
file,
|
|
992
|
+
path: "",
|
|
993
|
+
severity: "warning",
|
|
994
|
+
message: `another redirects block, "${routed}", is the one routed; this one is ignored. Move its rules there`,
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
}
|
|
920
998
|
return problems;
|
|
921
999
|
}
|
|
922
1000
|
|
|
@@ -1031,7 +1109,7 @@ export interface CheckOptions {
|
|
|
1031
1109
|
reporter?: Reporter;
|
|
1032
1110
|
}
|
|
1033
1111
|
|
|
1034
|
-
function readSchemaFile(file: string): DecoMeta {
|
|
1112
|
+
export function readSchemaFile(file: string): DecoMeta {
|
|
1035
1113
|
let text: string;
|
|
1036
1114
|
try {
|
|
1037
1115
|
text = fs.readFileSync(file, "utf8");
|
|
@@ -1073,7 +1151,19 @@ export function check(options: CheckOptions = {}): number {
|
|
|
1073
1151
|
const reporter = options.reporter ?? consoleReporter;
|
|
1074
1152
|
const paths = decoPaths(findDecoRoot(options));
|
|
1075
1153
|
const meta = readSchemaFile(paths.schema);
|
|
1076
|
-
|
|
1154
|
+
return reportCheck(meta, readSavedBlocks(paths.blocks), reporter).exitCode;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
export interface CheckReport {
|
|
1158
|
+
exitCode: number;
|
|
1159
|
+
count: number;
|
|
1160
|
+
errors: number;
|
|
1161
|
+
warnings: number;
|
|
1162
|
+
problems: Problem[];
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
/** Check saved blocks against the local schema and print the problems and a summary. */
|
|
1166
|
+
export function reportCheck(meta: DecoMeta, saved: SavedBlocks, reporter: Reporter): CheckReport {
|
|
1077
1167
|
const problems = checkContent(meta, saved);
|
|
1078
1168
|
const errors = problems.filter((p) => p.severity === "error").length;
|
|
1079
1169
|
const warnings = problems.length - errors;
|
|
@@ -1086,7 +1176,7 @@ export function check(options: CheckOptions = {}): number {
|
|
|
1086
1176
|
const summary = checkSummary(count, errors, warnings, reporter.color);
|
|
1087
1177
|
if (errors > 0) reporter.error(summary);
|
|
1088
1178
|
else reporter.info(summary);
|
|
1089
|
-
return errors > 0 ? 1 : 0;
|
|
1179
|
+
return { exitCode: errors > 0 ? 1 : 0, count, errors, warnings, problems };
|
|
1090
1180
|
}
|
|
1091
1181
|
|
|
1092
1182
|
/**
|
package/src/v8/cli/content.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `
|
|
3
|
-
* module, `.deco/blocks.gen.ts
|
|
4
|
-
*
|
|
2
|
+
* Reading `.deco/blocks` (every command that reads saved blocks), and the
|
|
3
|
+
* content module, `.deco/blocks.gen.ts`, for content without a site: tests,
|
|
4
|
+
* the example apps, self-hosted content and git-backed sites
|
|
5
|
+
* (`createCMS({ blocks, content })`, what the v7 migration writes). It never
|
|
6
|
+
* reads the block map. `deco content` (and `content()` from
|
|
7
|
+
* `@decocms/blocks/cli`) writes the module; a site with `site` set gets its
|
|
8
|
+
* content at runtime instead, and its `.deco/blocks` is what `deco pull` wrote.
|
|
5
9
|
*/
|
|
6
|
-
import { execFileSync } from "node:child_process";
|
|
7
10
|
import fs from "node:fs";
|
|
8
11
|
import path from "node:path";
|
|
9
|
-
import {
|
|
12
|
+
import { computeContentRevision } from "../../protocol/canonical.ts";
|
|
10
13
|
import {
|
|
14
|
+
blockFileName,
|
|
11
15
|
blockNameFromFile,
|
|
12
16
|
checkBlockName,
|
|
13
17
|
entryHasPath,
|
|
@@ -23,7 +27,7 @@ import { CliError, type DecoPaths, decoPaths, findDecoRoot } from "./root.ts";
|
|
|
23
27
|
export interface ContentDiagnostic {
|
|
24
28
|
/** The file name inside `.deco/blocks`. */
|
|
25
29
|
file: string;
|
|
26
|
-
/** "error" stops `deco
|
|
30
|
+
/** "error" stops the content module, `deco push` and `deco check`; "warning" doesn't. */
|
|
27
31
|
severity: "error" | "warning";
|
|
28
32
|
message: string;
|
|
29
33
|
}
|
|
@@ -114,6 +118,38 @@ export function readSavedBlocks(blocksDir: string): SavedBlocks {
|
|
|
114
118
|
return { blocks, files, diagnostics };
|
|
115
119
|
}
|
|
116
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Blocks fetched from a draft or a revision, as if read from `.deco/blocks`
|
|
123
|
+
* (`deco check`, `--draft`, `--revision`): each at its file name; a name the
|
|
124
|
+
* file-name rule rejects, or a value that isn't a JSON object, is a
|
|
125
|
+
* diagnostic, as on disk.
|
|
126
|
+
*/
|
|
127
|
+
export function savedBlocksFromMap(map: Record<string, unknown>): SavedBlocks {
|
|
128
|
+
const blocks: Record<string, Record<string, unknown>> = Object.create(null);
|
|
129
|
+
const files: Record<string, string> = Object.create(null);
|
|
130
|
+
const diagnostics: ContentDiagnostic[] = [];
|
|
131
|
+
for (const name of Object.keys(map).sort()) {
|
|
132
|
+
const file = blockFileName(name);
|
|
133
|
+
const entry = map[name];
|
|
134
|
+
const [invalid] = checkBlockName(name);
|
|
135
|
+
if (invalid) {
|
|
136
|
+
diagnostics.push({
|
|
137
|
+
file,
|
|
138
|
+
severity: "error",
|
|
139
|
+
message: `not a valid entry name (${invalid.message})`,
|
|
140
|
+
});
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (!isPlainObject(entry)) {
|
|
144
|
+
diagnostics.push({ file, severity: "error", message: "a saved block must be a JSON object" });
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
blocks[name] = entry;
|
|
148
|
+
files[name] = file;
|
|
149
|
+
}
|
|
150
|
+
return { blocks, files, diagnostics };
|
|
151
|
+
}
|
|
152
|
+
|
|
117
153
|
const RESERVED = new Set(
|
|
118
154
|
`break case catch class const continue debugger default delete do else enum export extends false
|
|
119
155
|
finally for function if import in instanceof new null return super switch this throw true try
|
|
@@ -140,7 +176,7 @@ function identifierFor(name: string, taken: Set<string>): string {
|
|
|
140
176
|
* Node reads it as a URL and loads `a b.json` instead. No spelling of the
|
|
141
177
|
* specifier names the same file everywhere, so those entries are written into
|
|
142
178
|
* the module, and hand edits to them need `deco content` again (`--watch`
|
|
143
|
-
* does it
|
|
179
|
+
* does it).
|
|
144
180
|
*/
|
|
145
181
|
const IMPORTABLE_FILE = /^[A-Za-z0-9_][A-Za-z0-9._-]*\.json$/;
|
|
146
182
|
|
|
@@ -167,66 +203,8 @@ export function contentRoot(deco: string): string {
|
|
|
167
203
|
}
|
|
168
204
|
}
|
|
169
205
|
|
|
170
|
-
/**
|
|
171
|
-
|
|
172
|
-
* JSON in canonical form (`sha256Hex(canonicalJson(JSON.parse(text)))`, the
|
|
173
|
-
* `@decocms/blocks/protocol` helpers), so Studio computes the same value
|
|
174
|
-
* from the file at a commit. Hosted releases swap only when it matches.
|
|
175
|
-
*/
|
|
176
|
-
async function computeSchemaHash(text: string): Promise<string> {
|
|
177
|
-
return sha256Hex(canonicalJson(JSON.parse(text)));
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/** `schema.gen.json`'s hash, or `undefined` when there's no such file. */
|
|
181
|
-
async function readSchemaHash(schemaFile: string): Promise<string | undefined> {
|
|
182
|
-
let text: string;
|
|
183
|
-
try {
|
|
184
|
-
text = fs.readFileSync(schemaFile, "utf8");
|
|
185
|
-
} catch (error) {
|
|
186
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined;
|
|
187
|
-
throw error;
|
|
188
|
-
}
|
|
189
|
-
try {
|
|
190
|
-
return await computeSchemaHash(text);
|
|
191
|
-
} catch (error) {
|
|
192
|
-
throw new CliError(
|
|
193
|
-
`.deco/schema.gen.json: not valid JSON (${(error as Error).message}); run deco schema`,
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* The commit time of git HEAD in `dir` (committer date, ISO 8601), or
|
|
200
|
-
* undefined when git is missing, `dir` isn't in a repository, or it has no
|
|
201
|
-
* commits. Commit time, not build time: a slow build of an older commit that
|
|
202
|
-
* finishes after a publish must not win over it.
|
|
203
|
-
*/
|
|
204
|
-
export function readCommittedAt(dir: string): string | undefined {
|
|
205
|
-
try {
|
|
206
|
-
const out = execFileSync("git", ["log", "-1", "--format=%cI"], {
|
|
207
|
-
cwd: dir,
|
|
208
|
-
encoding: "utf8",
|
|
209
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
210
|
-
}).trim();
|
|
211
|
-
return out === "" || Number.isNaN(Date.parse(out)) ? undefined : out;
|
|
212
|
-
} catch {
|
|
213
|
-
return undefined;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* The source of `.deco/blocks.gen.ts` for a set of saved blocks, with the
|
|
219
|
-
* `schemaHash` of the schema it was built with when there is one, and
|
|
220
|
-
* `committedAt`: the commit time of git HEAD it was built from (ISO 8601),
|
|
221
|
-
* when there is one. A hosted release replaces the bundled content only when
|
|
222
|
-
* it was published later (see ../remoteLoader.ts).
|
|
223
|
-
*/
|
|
224
|
-
export async function renderContentModule(
|
|
225
|
-
saved: SavedBlocks,
|
|
226
|
-
root = ".deco",
|
|
227
|
-
schemaHash?: string,
|
|
228
|
-
committedAt?: string,
|
|
229
|
-
): Promise<string> {
|
|
206
|
+
/** The source of `.deco/blocks.gen.ts` for a set of saved blocks. */
|
|
207
|
+
export async function renderContentModule(saved: SavedBlocks, root = ".deco"): Promise<string> {
|
|
230
208
|
const names = Object.keys(saved.blocks).sort();
|
|
231
209
|
const revision = await computeContentRevision(saved.blocks);
|
|
232
210
|
const taken = new Set<string>();
|
|
@@ -249,20 +227,16 @@ export async function renderContentModule(
|
|
|
249
227
|
([alias, target]) => ` ${JSON.stringify(alias)}: ${JSON.stringify(target)},`,
|
|
250
228
|
);
|
|
251
229
|
return [
|
|
252
|
-
"// Generated
|
|
230
|
+
"// Generated from .deco/blocks; don't edit.",
|
|
253
231
|
...imports,
|
|
254
232
|
"",
|
|
255
233
|
"const content: {",
|
|
256
234
|
" revision: string;",
|
|
257
|
-
...(schemaHash === undefined ? [] : [" schemaHash: string;"]),
|
|
258
|
-
...(committedAt === undefined ? [] : [" committedAt: string;"]),
|
|
259
235
|
" blocks: Record<string, unknown>;",
|
|
260
236
|
" aliases: Record<string, string>;",
|
|
261
237
|
" root: string;",
|
|
262
238
|
"} = {",
|
|
263
239
|
` revision: ${JSON.stringify(revision)},`,
|
|
264
|
-
...(schemaHash === undefined ? [] : [` schemaHash: ${JSON.stringify(schemaHash)},`]),
|
|
265
|
-
...(committedAt === undefined ? [] : [` committedAt: ${JSON.stringify(committedAt)},`]),
|
|
266
240
|
" blocks: {",
|
|
267
241
|
...entries,
|
|
268
242
|
" },",
|
|
@@ -281,14 +255,7 @@ export interface ContentResult {
|
|
|
281
255
|
root: string;
|
|
282
256
|
file: string;
|
|
283
257
|
revision: string;
|
|
284
|
-
/** The hash of `.deco/schema.gen.json`, written into the module; absent without one. */
|
|
285
|
-
schemaHash?: string;
|
|
286
258
|
count: number;
|
|
287
|
-
/**
|
|
288
|
-
* The commit time of git HEAD in the root, written into the module as
|
|
289
|
-
* `committedAt`; absent when git isn't available there.
|
|
290
|
-
*/
|
|
291
|
-
committedAt?: string;
|
|
292
259
|
/** False when the file already had this content. */
|
|
293
260
|
changed: boolean;
|
|
294
261
|
/** Files written into the module instead of imported (see `inlinedFiles`). */
|
|
@@ -317,16 +284,12 @@ export async function writeContent(paths: DecoPaths): Promise<ContentResult> {
|
|
|
317
284
|
if (errors.length > 0) {
|
|
318
285
|
throw new CliError(errors.map((d) => `.deco/blocks/${d.file}: ${d.message}`).join("\n"));
|
|
319
286
|
}
|
|
320
|
-
const
|
|
321
|
-
const committedAt = readCommittedAt(paths.root);
|
|
322
|
-
const source = await renderContentModule(saved, contentRoot(paths.deco), schemaHash, committedAt);
|
|
287
|
+
const source = await renderContentModule(saved, contentRoot(paths.deco));
|
|
323
288
|
const changed = writeIfChanged(paths.content, source);
|
|
324
289
|
return {
|
|
325
290
|
root: paths.root,
|
|
326
291
|
file: paths.content,
|
|
327
292
|
revision: await computeContentRevision(saved.blocks),
|
|
328
|
-
...(schemaHash === undefined ? {} : { schemaHash }),
|
|
329
|
-
...(committedAt === undefined ? {} : { committedAt }),
|
|
330
293
|
count: Object.keys(saved.blocks).length,
|
|
331
294
|
changed,
|
|
332
295
|
inlined: inlinedFiles(saved),
|
|
@@ -338,21 +301,16 @@ export interface ContentOptions {
|
|
|
338
301
|
root?: string;
|
|
339
302
|
cwd?: string;
|
|
340
303
|
reporter?: Reporter;
|
|
341
|
-
/** Set
|
|
304
|
+
/** Set when something rewrites the module on every change: no hint about inlined files. */
|
|
342
305
|
watching?: boolean;
|
|
343
306
|
}
|
|
344
307
|
|
|
345
|
-
/** `
|
|
308
|
+
/** Write `.deco/blocks.gen.ts` once (content without a site). Returns the exit code. */
|
|
346
309
|
export async function content(options: ContentOptions = {}): Promise<number> {
|
|
347
310
|
const reporter = options.reporter ?? consoleReporter;
|
|
348
311
|
const paths = decoPaths(findDecoRoot(options));
|
|
349
312
|
const result = await writeContent(paths);
|
|
350
313
|
for (const d of result.diagnostics) reporter.warn(`.deco/blocks/${d.file}: ${d.message}`);
|
|
351
|
-
if (result.committedAt === undefined) {
|
|
352
|
-
reporter.info(
|
|
353
|
-
"no git commit found, so .deco/blocks.gen.ts has no committedAt: hosted releases with the same schema will replace it",
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
314
|
reporter.info(
|
|
357
315
|
`${result.changed ? "wrote" : "unchanged"} .deco/blocks.gen.ts (${result.count} blocks, revision ${result.revision.slice(0, 12)})`,
|
|
358
316
|
);
|
package/src/v8/cli/index.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* does either, so neither the CLI nor the TypeScript compiler it loads ever
|
|
5
5
|
* reaches an app bundle.
|
|
6
6
|
*
|
|
7
|
-
* The
|
|
7
|
+
* The commands and their options, plus what the one-time migration
|
|
8
8
|
* (the `deco-v7-to-v8-migration` skill) reads: the built-in block names, the alias
|
|
9
9
|
* table, the saved-blocks reader and the host-pattern parser.
|
|
10
10
|
*/
|
|
@@ -15,4 +15,3 @@ export { type ContentOptions, content, readSavedBlocks, type SavedBlocks } from
|
|
|
15
15
|
export { type Reporter, silentReporter } from "./log.ts";
|
|
16
16
|
export { runCli } from "./run.ts";
|
|
17
17
|
export { type SchemaOptions, schema } from "./schema/index.ts";
|
|
18
|
-
export { type ServeOptions, serve } from "./serve/server.ts";
|