@decocms/blocks 8.1.0-next.4 → 8.1.0-next.5
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/protocol/client.d.ts +1 -1
- package/dist/protocol/conformance/cases/reads.d.ts.map +1 -1
- package/dist/protocol/conformance/cases/reads.js +22 -6
- package/dist/protocol/conformance/cases/reads.js.map +1 -1
- package/dist/protocol/conformance/cases/writes.d.ts.map +1 -1
- package/dist/protocol/conformance/cases/writes.js +1 -0
- package/dist/protocol/conformance/cases/writes.js.map +1 -1
- package/dist/protocol/conformance/contentHashFixtures.d.ts +0 -29
- package/dist/protocol/conformance/contentHashFixtures.d.ts.map +1 -1
- package/dist/protocol/conformance/contentHashFixtures.js +0 -30
- package/dist/protocol/conformance/contentHashFixtures.js.map +1 -1
- package/dist/protocol/conformance/context.d.ts +3 -3
- package/dist/protocol/conformance/context.d.ts.map +1 -1
- package/dist/protocol/conformance/index.d.ts +1 -1
- package/dist/protocol/conformance/index.d.ts.map +1 -1
- package/dist/protocol/conformance/index.js +2 -2
- package/dist/protocol/conformance/index.js.map +1 -1
- package/dist/protocol/index.d.ts +3 -5
- package/dist/protocol/index.d.ts.map +1 -1
- package/dist/protocol/index.js +3 -5
- package/dist/protocol/index.js.map +1 -1
- package/dist/protocol/server/methods/read.d.ts.map +1 -1
- package/dist/protocol/server/methods/read.js +5 -2
- package/dist/protocol/server/methods/read.js.map +1 -1
- package/dist/protocol/types.d.ts +23 -0
- package/dist/protocol/types.d.ts.map +1 -1
- package/dist/protocol/types.js +10 -0
- package/dist/protocol/types.js.map +1 -1
- package/dist/v8/boundedJson.d.ts +11 -0
- package/dist/v8/boundedJson.d.ts.map +1 -0
- package/dist/v8/boundedJson.js +44 -0
- package/dist/v8/boundedJson.js.map +1 -0
- package/dist/v8/canonical.d.ts +0 -28
- package/dist/v8/canonical.d.ts.map +1 -1
- package/dist/v8/canonical.js +0 -19
- package/dist/v8/canonical.js.map +1 -1
- package/dist/v8/cli/check/index.d.ts +5 -0
- package/dist/v8/cli/check/index.d.ts.map +1 -1
- package/dist/v8/cli/check/index.js +21 -1
- package/dist/v8/cli/check/index.js.map +1 -1
- package/dist/v8/cli/run.js +1 -1
- package/dist/v8/cli/schema/generate.d.ts +3 -1
- package/dist/v8/cli/schema/generate.d.ts.map +1 -1
- package/dist/v8/cli/schema/generate.js +2 -1
- package/dist/v8/cli/schema/generate.js.map +1 -1
- package/dist/v8/cli/serve/server.d.ts +1 -1
- package/dist/v8/cli/serve/server.d.ts.map +1 -1
- package/dist/v8/cli/serve/server.js +63 -23
- package/dist/v8/cli/serve/server.js.map +1 -1
- package/dist/v8/cms.d.ts.map +1 -1
- package/dist/v8/cms.js +12 -7
- package/dist/v8/cms.js.map +1 -1
- package/dist/v8/content.d.ts +8 -6
- package/dist/v8/content.d.ts.map +1 -1
- package/dist/v8/content.js +50 -40
- package/dist/v8/content.js.map +1 -1
- package/dist/v8/draft.d.ts.map +1 -1
- package/dist/v8/draft.js +22 -0
- package/dist/v8/draft.js.map +1 -1
- package/dist/v8/draftChanges.d.ts +26 -0
- package/dist/v8/draftChanges.d.ts.map +1 -0
- package/dist/v8/draftChanges.js +102 -0
- package/dist/v8/draftChanges.js.map +1 -0
- package/dist/v8/remoteLoader.d.ts +1 -1
- package/dist/v8/remoteLoader.d.ts.map +1 -1
- package/dist/v8/remoteLoader.js +19 -256
- package/dist/v8/remoteLoader.js.map +1 -1
- package/dist/v8/settings.d.ts +7 -0
- package/dist/v8/settings.d.ts.map +1 -1
- package/dist/v8/settings.js +19 -6
- package/dist/v8/settings.js.map +1 -1
- package/dist/v8/types.d.ts +22 -11
- package/dist/v8/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/protocol/client.ts +1 -1
- package/src/protocol/conformance/cases/reads.ts +24 -6
- package/src/protocol/conformance/cases/writes.ts +1 -0
- package/src/protocol/conformance/contentHashFixtures.ts +0 -57
- package/src/protocol/conformance/context.ts +3 -3
- package/src/protocol/conformance/index.ts +2 -7
- package/src/protocol/index.ts +2 -8
- package/src/protocol/server/methods/read.ts +5 -2
- package/src/protocol/types.ts +21 -1
- package/src/v8/boundedJson.ts +47 -0
- package/src/v8/canonical.ts +0 -36
- package/src/v8/cli/check/index.ts +25 -1
- package/src/v8/cli/run.ts +1 -1
- package/src/v8/cli/schema/generate.ts +4 -1
- package/src/v8/cli/serve/server.ts +65 -29
- package/src/v8/cms.ts +12 -8
- package/src/v8/content.ts +57 -43
- package/src/v8/draft.ts +18 -0
- package/src/v8/draftChanges.ts +117 -0
- package/src/v8/remoteLoader.ts +23 -289
- package/src/v8/settings.ts +27 -6
- package/src/v8/types.ts +25 -12
package/dist/v8/settings.js
CHANGED
|
@@ -22,21 +22,34 @@ const SECTIONS = ["preview", "telemetry", "analytics"];
|
|
|
22
22
|
* a list of host patterns: that's a bug in the app, not in content.
|
|
23
23
|
*/
|
|
24
24
|
export function parseCodeHosts(preview) {
|
|
25
|
+
return parseCodePatterns(preview, "hosts");
|
|
26
|
+
}
|
|
27
|
+
/** The hosts a draft pointer may name when code sets no `preview.sources`. */
|
|
28
|
+
export const DEFAULT_SOURCES = ["studio.decocms.com"];
|
|
29
|
+
/**
|
|
30
|
+
* Code's `preview.sources`, parsed, or the default (`studio.decocms.com`).
|
|
31
|
+
* Throws a `TypeError` like {@link parseCodeHosts}.
|
|
32
|
+
*/
|
|
33
|
+
export function parseCodeSources(preview) {
|
|
34
|
+
return (parseCodePatterns(preview, "sources") ??
|
|
35
|
+
DEFAULT_SOURCES.map((raw) => parseHostPattern(raw)));
|
|
36
|
+
}
|
|
37
|
+
function parseCodePatterns(preview, field) {
|
|
25
38
|
if (preview === undefined || preview === null)
|
|
26
39
|
return undefined;
|
|
27
40
|
if (typeof preview !== "object") {
|
|
28
41
|
throw new TypeError("createCMS: `preview` must be an object, such as { hosts: [...] }");
|
|
29
42
|
}
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
43
|
+
const list = preview[field];
|
|
44
|
+
if (list === undefined)
|
|
32
45
|
return undefined;
|
|
33
|
-
if (!Array.isArray(
|
|
34
|
-
throw new TypeError(
|
|
46
|
+
if (!Array.isArray(list)) {
|
|
47
|
+
throw new TypeError(`createCMS: \`preview.${field}\` must be a list of host patterns`);
|
|
35
48
|
}
|
|
36
|
-
return
|
|
49
|
+
return list.map((raw) => {
|
|
37
50
|
const pattern = parseHostPattern(raw);
|
|
38
51
|
if (pattern === null) {
|
|
39
|
-
throw new TypeError(`createCMS: ${JSON.stringify(raw)} in preview
|
|
52
|
+
throw new TypeError(`createCMS: ${JSON.stringify(raw)} in preview.${field} isn't a host pattern ` +
|
|
40
53
|
"(see /next/api-reference#host-patterns)");
|
|
41
54
|
}
|
|
42
55
|
return pattern;
|
package/dist/v8/settings.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/v8/settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,UAAU,EACV,iBAAiB,EAEjB,gBAAgB,EAChB,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAU1C,MAAM,QAAQ,GAAG,CAAC,SAAS,EAAE,WAAW,EAAE,WAAW,CAAU,CAAC;AAEhE;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,OAA6B;IAC1D,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAChE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CAAC,kEAAkE,CAAC,CAAC;IAC1F,CAAC;IACD,MAAM,
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/v8/settings.ts"],"names":[],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CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAAE,SAAS;QACvE,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AAED,SAAS,MAAM,CAAC,MAAgB;IAC9B,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9B,CAAC"}
|
package/dist/v8/types.d.ts
CHANGED
|
@@ -32,20 +32,23 @@ export type Snapshot = {
|
|
|
32
32
|
export type ContentModule = Snapshot & {
|
|
33
33
|
root?: string;
|
|
34
34
|
};
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* A source of content: `load()` returns it. Drafts aren't a loader's job:
|
|
37
|
+
* `forDraft` layers a draft's changes over what `load()` returned.
|
|
38
|
+
*/
|
|
36
39
|
export interface Loader {
|
|
37
|
-
load(
|
|
40
|
+
load(): Promise<Snapshot>;
|
|
38
41
|
update?(): Promise<{
|
|
39
42
|
updated: boolean;
|
|
40
43
|
}>;
|
|
41
44
|
}
|
|
42
45
|
/** The parts of a draft pointer, `<host[:port]><path[?query]>@<version>`. */
|
|
43
46
|
export interface DraftPointer {
|
|
44
|
-
/** `host[:port]` of the
|
|
47
|
+
/** `host[:port]` of the Studio API that serves the draft's changes. */
|
|
45
48
|
host: string;
|
|
46
49
|
/** Starts with `/`; opaque to the app. Never carries the `__variant` parameters. */
|
|
47
50
|
path: string;
|
|
48
|
-
/** Opaque
|
|
51
|
+
/** Opaque: the commit of the editor's last save. `"local"` names no draft (`deco serve`). */
|
|
49
52
|
version: string;
|
|
50
53
|
/** The variants this preview forces (the query's `__variant` parameters); absent when none. */
|
|
51
54
|
variants?: ForcedVariant[];
|
|
@@ -203,20 +206,25 @@ export interface CMSConfig {
|
|
|
203
206
|
interval?: number;
|
|
204
207
|
/** Where telemetry goes; see /next/telemetry. */
|
|
205
208
|
telemetry?: false | TelemetryConfig;
|
|
206
|
-
/**
|
|
207
|
-
* The most content may allow previews on, in the host pattern format
|
|
208
|
-
* (/next/api-reference#host-patterns). Without it, content may allow any host.
|
|
209
|
-
*/
|
|
210
209
|
preview?: {
|
|
210
|
+
/**
|
|
211
|
+
* The most content may allow previews on, in the host pattern format
|
|
212
|
+
* (/next/api-reference#host-patterns). Without it, content may allow any host.
|
|
213
|
+
*/
|
|
211
214
|
hosts?: string[];
|
|
215
|
+
/**
|
|
216
|
+
* The hosts a draft pointer may name, in the host pattern format; code
|
|
217
|
+
* only, never content. Default `["studio.decocms.com"]`.
|
|
218
|
+
*/
|
|
219
|
+
sources?: string[];
|
|
212
220
|
};
|
|
213
221
|
/** The private key that decrypts `secret` blocks. */
|
|
214
222
|
secrets?: {
|
|
215
223
|
key?: string;
|
|
216
224
|
};
|
|
217
|
-
/** Your site's ID, for hosted releases
|
|
225
|
+
/** Your site's ID, for hosted releases. Drafts don't need it. */
|
|
218
226
|
site?: string;
|
|
219
|
-
/** Your site token (secret), for hosted releases
|
|
227
|
+
/** Your site token (secret), for hosted releases. Drafts don't need it. */
|
|
220
228
|
token?: string;
|
|
221
229
|
}
|
|
222
230
|
export interface ResolveOptions {
|
|
@@ -251,7 +259,10 @@ export interface Client {
|
|
|
251
259
|
export interface CMS {
|
|
252
260
|
/** A client reading the current release. */
|
|
253
261
|
forRelease(): Client;
|
|
254
|
-
/**
|
|
262
|
+
/**
|
|
263
|
+
* A client reading the draft a pointer names: its changes, fetched from a
|
|
264
|
+
* host in `preview.sources`, over this server's production content.
|
|
265
|
+
*/
|
|
255
266
|
forDraft(pointer: string): Client;
|
|
256
267
|
/** A client pinned to a revision this CMS has served; an unknown revision behaves like the release. */
|
|
257
268
|
forRevision(revision: string): Client;
|
package/dist/v8/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/v8/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMvC;;;;GAIG;AACH,MAAM,MAAM,KAAK,GAAG;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAExE,mCAAmC;AACnC,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAExE,oEAAoE;AACpE,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAEnD,2FAA2F;AAC3F,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzD
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/v8/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMvC;;;;GAIG;AACH,MAAM,MAAM,KAAK,GAAG;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAExE,mCAAmC;AACnC,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAExE,oEAAoE;AAC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C;IAC3D;;;OAGG;IACH,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC3D"}
|
package/package.json
CHANGED
package/src/protocol/client.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from "./types.ts";
|
|
14
14
|
|
|
15
15
|
export interface ContentClientOptions {
|
|
16
|
-
/** The endpoint URL, such as `http://
|
|
16
|
+
/** The endpoint URL, such as `http://localhost:4545/rpc`. */
|
|
17
17
|
endpoint: string | URL;
|
|
18
18
|
/** Sent as `Authorization: Bearer <token>`. */
|
|
19
19
|
token?: string;
|
|
@@ -63,12 +63,9 @@ export const readCases: ConformanceCase[] = [
|
|
|
63
63
|
id: "schema/read",
|
|
64
64
|
title: "schema.get returns the schema and a version, and 'not modified' for that version",
|
|
65
65
|
async run(ctx) {
|
|
66
|
-
if (ctx.options.hasSchema === false)
|
|
67
|
-
await expectError(ctx.client.schemaGet(), ErrorCode.NotFound, "no schema");
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
66
|
+
if (ctx.options.hasSchema === false) return ctx.skip("no schema (see schema/absent)");
|
|
70
67
|
const first = await ctx.client.schemaGet();
|
|
71
|
-
assert(!first.notModified, "the first read returns the schema");
|
|
68
|
+
assert(!first.notModified && first.schema !== null, "the first read returns the schema");
|
|
72
69
|
assert(typeof first.version === "string" && first.version.length > 0, "a version");
|
|
73
70
|
assert(typeof first.schema === "object" && first.schema !== null, "a schema object");
|
|
74
71
|
const again = await ctx.client.schemaGet({ ifNoneMatch: first.version });
|
|
@@ -77,6 +74,27 @@ export const readCases: ConformanceCase[] = [
|
|
|
77
74
|
assert(!stale.notModified, "another version returns the schema");
|
|
78
75
|
},
|
|
79
76
|
},
|
|
77
|
+
{
|
|
78
|
+
id: "schema/absent",
|
|
79
|
+
title: "without a schema, schema.get is schema: null (not an error) and blocks still list",
|
|
80
|
+
async run(ctx) {
|
|
81
|
+
if (ctx.options.hasSchema !== false) return ctx.skip("the endpoint has a schema");
|
|
82
|
+
const result = await ctx.client.schemaGet();
|
|
83
|
+
const d = await ctx.describe();
|
|
84
|
+
assertEqual(
|
|
85
|
+
result,
|
|
86
|
+
{
|
|
87
|
+
notModified: false,
|
|
88
|
+
version: null,
|
|
89
|
+
resolvedRef: d.refs === null ? null : result.notModified ? null : result.resolvedRef,
|
|
90
|
+
schema: null,
|
|
91
|
+
},
|
|
92
|
+
"the no-schema result",
|
|
93
|
+
);
|
|
94
|
+
const list = await ctx.client.blocksList();
|
|
95
|
+
assert(!list.notModified, "blocks.list returns the map without a schema");
|
|
96
|
+
},
|
|
97
|
+
},
|
|
80
98
|
{
|
|
81
99
|
id: "list/read",
|
|
82
100
|
title: "blocks.list returns every entry with versions, and 'not modified' for its revision",
|
|
@@ -112,7 +130,7 @@ export const readCases: ConformanceCase[] = [
|
|
|
112
130
|
: [
|
|
113
131
|
{
|
|
114
132
|
method: "schema.get" as const,
|
|
115
|
-
params: { ifNoneMatch: (await ctx.client.schemaGet()).version },
|
|
133
|
+
params: { ifNoneMatch: (await ctx.client.schemaGet()).version ?? undefined },
|
|
116
134
|
},
|
|
117
135
|
...calls,
|
|
118
136
|
],
|
|
@@ -289,6 +289,7 @@ export const writeCases: ConformanceCase[] = [
|
|
|
289
289
|
}
|
|
290
290
|
if (ctx.options.hasSchema === false) return ctx.skip("no schema");
|
|
291
291
|
const { version } = await ctx.client.schemaGet();
|
|
292
|
+
assert(version !== null, "the endpoint has a schema");
|
|
292
293
|
const error = await expectError(
|
|
293
294
|
ctx.client.blocksApply({ set: { [name]: {} }, ifSchemaMatch: `${version}-old` }),
|
|
294
295
|
ErrorCode.Conflict,
|
|
@@ -77,60 +77,3 @@ export const contentHashFixtures: readonly ContentHashFixture[] = [
|
|
|
77
77
|
revision: "6913c5e6aa28f441d3b0102177b372e4fb7c08bc09bdd8698df85e597282ac96",
|
|
78
78
|
},
|
|
79
79
|
];
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Golden fixtures for draft overlays (see /next/content-delivery#exact-draft-previews):
|
|
83
|
-
* whatever prepares draft assets must produce these block hashes and overlay
|
|
84
|
-
* versions, which the SDK checks on every asset it downloads.
|
|
85
|
-
*
|
|
86
|
-
* ```ts
|
|
87
|
-
* import { draftOverlayFixtures } from "@decocms/blocks/protocol/conformance";
|
|
88
|
-
* for (const f of draftOverlayFixtures) expect(await myOverlayVersion(f.overlay)).toBe(f.version);
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
export interface DraftOverlayFixture {
|
|
92
|
-
id: string;
|
|
93
|
-
title: string;
|
|
94
|
-
/** The changed entries, by name: each is stored under its block hash. */
|
|
95
|
-
blocks: Record<string, unknown>;
|
|
96
|
-
/** Each changed entry's block hash: SHA-256 of its canonical JSON. */
|
|
97
|
-
hashes: Record<string, string>;
|
|
98
|
-
/** The manifest. */
|
|
99
|
-
overlay: { format: 1; set: Record<string, string>; delete: string[] };
|
|
100
|
-
/** Its canonical JSON. */
|
|
101
|
-
canonical: string;
|
|
102
|
-
/** The overlay version: SHA-256 of the canonical manifest. */
|
|
103
|
-
version: string;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export const draftOverlayFixtures: readonly DraftOverlayFixture[] = [
|
|
107
|
-
{
|
|
108
|
-
id: "empty",
|
|
109
|
-
title: "a draft with no changes",
|
|
110
|
-
blocks: {},
|
|
111
|
-
hashes: {},
|
|
112
|
-
overlay: { format: 1, set: {}, delete: [] },
|
|
113
|
-
canonical: '{"delete":[],"format":1,"set":{}}',
|
|
114
|
-
version: "8e740552419ba3858a3be4a30165178ab034372f8718e34d076518325bab75e4",
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
id: "set-and-delete",
|
|
118
|
-
title: "one replacement and one tombstone (the docs' example)",
|
|
119
|
-
blocks: {
|
|
120
|
-
HomeHero: {
|
|
121
|
-
__resolveType: "hero",
|
|
122
|
-
title: "Summer sale",
|
|
123
|
-
image: { src: "/s.png", width: 1200 },
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
hashes: { HomeHero: "81213bc231ca93365b7c45d26265c21814fc0a359b1c44078e36ecdcf895fd80" },
|
|
127
|
-
overlay: {
|
|
128
|
-
format: 1,
|
|
129
|
-
set: { HomeHero: "81213bc231ca93365b7c45d26265c21814fc0a359b1c44078e36ecdcf895fd80" },
|
|
130
|
-
delete: ["OldPromotion"],
|
|
131
|
-
},
|
|
132
|
-
canonical:
|
|
133
|
-
'{"delete":["OldPromotion"],"format":1,"set":{"HomeHero":"81213bc231ca93365b7c45d26265c21814fc0a359b1c44078e36ecdcf895fd80"}}',
|
|
134
|
-
version: "91a60f71f78b5cc373c2995b479fbc2c8932970d4f3ff2bec0404a573d1c440f",
|
|
135
|
-
},
|
|
136
|
-
];
|
|
@@ -8,7 +8,7 @@ import { ContentProtocolError } from "../errors.ts";
|
|
|
8
8
|
import type { DescribeResult } from "../types.ts";
|
|
9
9
|
|
|
10
10
|
export interface ConformanceOptions {
|
|
11
|
-
/** The endpoint URL, such as `http://
|
|
11
|
+
/** The endpoint URL, such as `http://localhost:4545/rpc`. */
|
|
12
12
|
endpoint: string | URL;
|
|
13
13
|
/** The bearer token the endpoint expects, if any. */
|
|
14
14
|
token?: string;
|
|
@@ -23,7 +23,7 @@ export interface ConformanceOptions {
|
|
|
23
23
|
secretField?: { blockType: string; field: string };
|
|
24
24
|
/** The `.deco/secrets.pub` content the endpoint should report, if the harness wrote one. */
|
|
25
25
|
secretsPublicKey?: string;
|
|
26
|
-
/** Whether the endpoint has a schema (default true). `false` checks
|
|
26
|
+
/** Whether the endpoint has a schema (default true). `false` checks the `schema: null` result instead. */
|
|
27
27
|
hasSchema?: boolean;
|
|
28
28
|
/**
|
|
29
29
|
* The endpoint serves a schema larger than its `limits.maxSchemaBytes`, so
|
|
@@ -35,7 +35,7 @@ export interface ConformanceOptions {
|
|
|
35
35
|
schemaOverLimit?: boolean;
|
|
36
36
|
/**
|
|
37
37
|
* The URL prefix uploads are served under (`PUT <assetsEndpoint><name>`),
|
|
38
|
-
* such as `http://
|
|
38
|
+
* such as `http://localhost:4545/assets/`. Leave out to skip the upload cases.
|
|
39
39
|
*/
|
|
40
40
|
assetsEndpoint?: string | URL;
|
|
41
41
|
/**
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* import { describe, it } from "vitest";
|
|
11
11
|
* import { defineConformanceSuite } from "@decocms/blocks/protocol/conformance";
|
|
12
12
|
*
|
|
13
|
-
* defineConformanceSuite({ describe, it }, { endpoint: "http://
|
|
13
|
+
* defineConformanceSuite({ describe, it }, { endpoint: "http://localhost:4545/rpc", token });
|
|
14
14
|
* ```
|
|
15
15
|
*
|
|
16
16
|
* or collect a report with `runConformance(options)`. The suite writes only
|
|
@@ -28,12 +28,7 @@ import { writeCases } from "./cases/writes.ts";
|
|
|
28
28
|
import { ConformanceContext, type ConformanceOptions, SkipCase } from "./context.ts";
|
|
29
29
|
|
|
30
30
|
export type { ConformanceCase } from "./cases/types.ts";
|
|
31
|
-
export {
|
|
32
|
-
type ContentHashFixture,
|
|
33
|
-
contentHashFixtures,
|
|
34
|
-
type DraftOverlayFixture,
|
|
35
|
-
draftOverlayFixtures,
|
|
36
|
-
} from "./contentHashFixtures.ts";
|
|
31
|
+
export { type ContentHashFixture, contentHashFixtures } from "./contentHashFixtures.ts";
|
|
37
32
|
export type { ConformanceOptions } from "./context.ts";
|
|
38
33
|
|
|
39
34
|
/** Every conformance case, in the order they run. */
|
package/src/protocol/index.ts
CHANGED
|
@@ -14,10 +14,8 @@
|
|
|
14
14
|
*
|
|
15
15
|
* The SDK's runtime never imports the protocol, so it never reaches an app
|
|
16
16
|
* bundle. The canonical hash it re-exports is the SDK's own dependency-free
|
|
17
|
-
* leaf module (see ./canonical.ts)
|
|
18
|
-
* (
|
|
19
|
-
* preview grants and the draft lifecycle are outside the protocol: overlays
|
|
20
|
-
* are delivery assets (see /next/content-delivery#exact-draft-previews).
|
|
17
|
+
* leaf module (see ./canonical.ts). Draft previews and the draft lifecycle
|
|
18
|
+
* are outside the protocol (see /next/content-delivery#draft-previews).
|
|
21
19
|
*/
|
|
22
20
|
export {
|
|
23
21
|
APPLY_DIGEST_DOMAIN,
|
|
@@ -25,11 +23,7 @@ export {
|
|
|
25
23
|
CanonicalJsonError,
|
|
26
24
|
CONTENT_HASH_FORMAT,
|
|
27
25
|
canonicalJson,
|
|
28
|
-
computeBlockHash,
|
|
29
26
|
computeContentRevision,
|
|
30
|
-
computeOverlayVersion,
|
|
31
|
-
DRAFT_OVERLAY_FORMAT,
|
|
32
|
-
type DraftOverlay,
|
|
33
27
|
sha256Hex,
|
|
34
28
|
} from "./canonical.ts";
|
|
35
29
|
export {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The three read methods: `describe`, `schema.get` and `blocks.list`.
|
|
3
3
|
*/
|
|
4
4
|
import { publicKeyDerFromPem } from "../../ciphertext.ts";
|
|
5
|
-
import { limitExceeded,
|
|
5
|
+
import { limitExceeded, unavailable } from "../../errors.ts";
|
|
6
6
|
import {
|
|
7
7
|
ASSETS_URL_PREFIX,
|
|
8
8
|
type BlocksListResult,
|
|
@@ -106,7 +106,10 @@ export async function schemaGet(core: Core, params: ReadParams): Promise<SchemaG
|
|
|
106
106
|
const limits = core.limits(description);
|
|
107
107
|
const stored = await core.storage.readSchema({ ref: params.ref });
|
|
108
108
|
if (stored === null) {
|
|
109
|
-
|
|
109
|
+
// No schema yet is a state, not an error. The snapshot still refuses a
|
|
110
|
+
// site with no .deco folder (NotFound) and reports the resolved branch.
|
|
111
|
+
const snapshot = await core.storage.snapshot({ ref: params.ref });
|
|
112
|
+
return { notModified: false, version: null, resolvedRef: snapshot.resolvedRef, schema: null };
|
|
110
113
|
}
|
|
111
114
|
if (params.ifNoneMatch !== undefined && params.ifNoneMatch === stored.version) {
|
|
112
115
|
return { notModified: true, version: stored.version };
|
package/src/protocol/types.ts
CHANGED
|
@@ -10,6 +10,17 @@ export const PROTOCOL_VERSION = { major: 1, minor: 0 } as const;
|
|
|
10
10
|
|
|
11
11
|
export const SCHEMA_FORMAT = "deco-meta@1";
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* The Blocks major a generated schema declares, as its top-level
|
|
15
|
+
* `blocksMajor`. `deco schema` writes it and `deco check` requires it. It is
|
|
16
|
+
* the package's major version, not the full version string, and it is the
|
|
17
|
+
* only signal a host such as the site editor should read to tell a v8 site
|
|
18
|
+
* from a v7 one: the schema's file name (`schema.gen.json` or
|
|
19
|
+
* `meta.gen.json`) doesn't tell. A schema without it, or with another value,
|
|
20
|
+
* is not a v8 schema.
|
|
21
|
+
*/
|
|
22
|
+
export const BLOCKS_MAJOR = 8;
|
|
23
|
+
|
|
13
24
|
/** The path the local server (`deco serve`) mounts the endpoint at. */
|
|
14
25
|
export const RPC_PATH = "/rpc";
|
|
15
26
|
|
|
@@ -89,9 +100,18 @@ export interface ReadParams {
|
|
|
89
100
|
|
|
90
101
|
export type SchemaGetParams = ReadParams;
|
|
91
102
|
|
|
103
|
+
/**
|
|
104
|
+
* `schema: null` (with `version: null`) means the site has no schema yet:
|
|
105
|
+
* neither `.deco/schema.gen.json` nor `.deco/meta.gen.json` exists. It's a
|
|
106
|
+
* normal state, not an error: `blocks.list` and `blocks.apply` work without a
|
|
107
|
+
* schema, so a client still lists and edits the blocks (without typed forms)
|
|
108
|
+
* and keeps polling until a schema appears. There's no version to send as
|
|
109
|
+
* `ifNoneMatch`, so the poll reads it unconditionally; the answer is tiny.
|
|
110
|
+
*/
|
|
92
111
|
export type SchemaGetResult =
|
|
93
112
|
| { notModified: true; version: string }
|
|
94
|
-
| { notModified: false; version: string; resolvedRef: string | null; schema: DecoMeta }
|
|
113
|
+
| { notModified: false; version: string; resolvedRef: string | null; schema: DecoMeta }
|
|
114
|
+
| { notModified: false; version: null; resolvedRef: string | null; schema: null };
|
|
95
115
|
|
|
96
116
|
export type BlocksListParams = ReadParams;
|
|
97
117
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Network reads the SDK makes on its own (hosted releases, draft changes):
|
|
3
|
+
* a timeout on the whole request, and a JSON body refused as soon as it
|
|
4
|
+
* would exceed a size, before it's buffered whole (a Worker isolate has
|
|
5
|
+
* 128 MB).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** An abort signal that fires after `ms`, where the runtime has `AbortSignal.timeout`. */
|
|
9
|
+
export function timeoutSignal(ms: number): AbortSignal | undefined {
|
|
10
|
+
return typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function"
|
|
11
|
+
? AbortSignal.timeout(ms)
|
|
12
|
+
: undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Parses a JSON body, refusing it once it passes `maxBytes`. */
|
|
16
|
+
export async function readBoundedJson(
|
|
17
|
+
response: Response,
|
|
18
|
+
label: string,
|
|
19
|
+
maxBytes: number,
|
|
20
|
+
): Promise<unknown> {
|
|
21
|
+
const tooLarge = () => new Error(`${label}: larger than ${maxBytes} bytes`);
|
|
22
|
+
if (Number(response.headers.get("content-length")) > maxBytes) {
|
|
23
|
+
await response.body?.cancel();
|
|
24
|
+
throw tooLarge();
|
|
25
|
+
}
|
|
26
|
+
if (response.body === null) {
|
|
27
|
+
const text = await response.text();
|
|
28
|
+
if (text.length > maxBytes) throw tooLarge();
|
|
29
|
+
return JSON.parse(text);
|
|
30
|
+
}
|
|
31
|
+
const reader = response.body.getReader();
|
|
32
|
+
const decoder = new TextDecoder();
|
|
33
|
+
const parts: string[] = [];
|
|
34
|
+
let size = 0;
|
|
35
|
+
for (;;) {
|
|
36
|
+
const { done, value } = await reader.read();
|
|
37
|
+
if (done) break;
|
|
38
|
+
size += value.byteLength;
|
|
39
|
+
if (size > maxBytes) {
|
|
40
|
+
await reader.cancel();
|
|
41
|
+
throw tooLarge();
|
|
42
|
+
}
|
|
43
|
+
parts.push(decoder.decode(value, { stream: true }));
|
|
44
|
+
}
|
|
45
|
+
parts.push(decoder.decode());
|
|
46
|
+
return JSON.parse(parts.join(""));
|
|
47
|
+
}
|
package/src/v8/canonical.ts
CHANGED
|
@@ -115,39 +115,3 @@ export const APPLY_DIGEST_DOMAIN = "deco-content/blocks.apply@1\n";
|
|
|
115
115
|
export function applyRequestDigest(params: object): Promise<string> {
|
|
116
116
|
return sha256Hex(APPLY_DIGEST_DOMAIN + canonicalJson(params));
|
|
117
117
|
}
|
|
118
|
-
|
|
119
|
-
/** The version of the draft overlay manifest format below. */
|
|
120
|
-
export const DRAFT_OVERLAY_FORMAT = 1;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* A draft overlay manifest (see /next/content-delivery#exact-draft-previews):
|
|
124
|
-
* the complete, cumulative set of a draft's changes, never a patch over an
|
|
125
|
-
* earlier version. `set` maps each changed entry's name to the block hash of
|
|
126
|
-
* its JSON; `delete` names the entries the draft removed (tombstones). The two
|
|
127
|
-
* are disjoint. There is no base revision: the server rendering the draft layers it over the
|
|
128
|
-
* production content it already has.
|
|
129
|
-
*/
|
|
130
|
-
export interface DraftOverlay {
|
|
131
|
-
format: typeof DRAFT_OVERLAY_FORMAT;
|
|
132
|
-
set: Record<string, string>;
|
|
133
|
-
delete: string[];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* The block hash of one changed entry: SHA-256 over its canonical JSON,
|
|
138
|
-
* lowercase hex. A draft block asset is stored under it
|
|
139
|
-
* (`/sites/<site>/draft-blocks/<block-hash>.json`), and the SDK checks every
|
|
140
|
-
* asset it downloads hashes to its name.
|
|
141
|
-
*/
|
|
142
|
-
export function computeBlockHash(entry: unknown): Promise<string> {
|
|
143
|
-
return sha256Hex(canonicalJson(entry));
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* The overlay version: SHA-256 over the manifest's canonical JSON, lowercase
|
|
148
|
-
* hex. The manifest is stored under it (`/sites/<site>/drafts/<version>.json`)
|
|
149
|
-
* and a draft pointer names it after its `@`.
|
|
150
|
-
*/
|
|
151
|
-
export function computeOverlayVersion(overlay: DraftOverlay): Promise<string> {
|
|
152
|
-
return sha256Hex(canonicalJson(overlay));
|
|
153
|
-
}
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
import fs from "node:fs";
|
|
21
21
|
import { Ajv, type ValidateFunction } from "ajv";
|
|
22
22
|
import { isWellFormedCiphertext } from "../../../protocol/secrets.ts";
|
|
23
|
+
import { BLOCKS_MAJOR } from "../../../protocol/types.ts";
|
|
23
24
|
import { SETTINGS_BLOCK, SETTINGS_TYPE } from "../../builtins/data.ts";
|
|
24
25
|
import { isBlock, own } from "../../json.ts";
|
|
25
26
|
import { findRouteConflicts } from "../../matchRoute.ts";
|
|
@@ -767,11 +768,34 @@ function readSchemaFile(file: string): DecoMeta {
|
|
|
767
768
|
} catch {
|
|
768
769
|
throw new CliError(`no ${file}; run deco schema first`);
|
|
769
770
|
}
|
|
771
|
+
let meta: DecoMeta;
|
|
770
772
|
try {
|
|
771
|
-
|
|
773
|
+
meta = JSON.parse(text) as DecoMeta;
|
|
772
774
|
} catch (error) {
|
|
773
775
|
throw new CliError(`${file}: invalid JSON: ${(error as Error).message}`);
|
|
774
776
|
}
|
|
777
|
+
assertBlocksMajor(meta, file);
|
|
778
|
+
return meta;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* A schema must declare `"blocksMajor": 8`: the site editor treats a site as
|
|
783
|
+
* v8 only on that field, so a schema without it would edit as a v7 site.
|
|
784
|
+
*/
|
|
785
|
+
export function assertBlocksMajor(meta: unknown, file: string): void {
|
|
786
|
+
const found =
|
|
787
|
+
typeof meta === "object" && meta !== null && !Array.isArray(meta)
|
|
788
|
+
? (meta as { blocksMajor?: unknown }).blocksMajor
|
|
789
|
+
: undefined;
|
|
790
|
+
if (found === BLOCKS_MAJOR) return;
|
|
791
|
+
const what =
|
|
792
|
+
found === undefined
|
|
793
|
+
? 'has no top-level "blocksMajor"'
|
|
794
|
+
: `has "blocksMajor": ${JSON.stringify(found)}`;
|
|
795
|
+
throw new CliError(
|
|
796
|
+
`${file} ${what}; expected "blocksMajor": ${BLOCKS_MAJOR}. ` +
|
|
797
|
+
"It was written by an older or different deco schema: run deco schema to regenerate it, then commit it.",
|
|
798
|
+
);
|
|
775
799
|
}
|
|
776
800
|
|
|
777
801
|
/** `deco check`. Returns the exit code: 0 when everything fits (warnings aside), 1 otherwise. */
|
package/src/v8/cli/run.ts
CHANGED
|
@@ -42,7 +42,7 @@ Commands:
|
|
|
42
42
|
schema turn the types in .deco/index.ts into .deco/schema.gen.json
|
|
43
43
|
content turn .deco/blocks into the content module, .deco/blocks.gen.ts
|
|
44
44
|
check check that every saved block fits the schema (writes nothing)
|
|
45
|
-
serve serve .deco to the site editor on this machine
|
|
45
|
+
serve serve .deco to the site editor on this machine, at http://localhost:4545/rpc
|
|
46
46
|
|
|
47
47
|
${Object.values(COMMANDS)
|
|
48
48
|
.map((c) => ` ${c.usage}`)
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import fs from "node:fs";
|
|
14
14
|
import path from "node:path";
|
|
15
|
-
import { SCHEMA_FORMAT } from "../../../protocol/types.ts";
|
|
15
|
+
import { BLOCKS_MAJOR, SCHEMA_FORMAT } from "../../../protocol/types.ts";
|
|
16
16
|
import { BUILT_IN_BLOCKS, LEGACY_ALIASES } from "../builtins.ts";
|
|
17
17
|
import { CliError, type DecoPaths, packageVersion } from "../root.ts";
|
|
18
18
|
import {
|
|
@@ -51,6 +51,8 @@ type ManifestEntry = { $ref: string; namespace: string };
|
|
|
51
51
|
|
|
52
52
|
export interface DecoMeta {
|
|
53
53
|
major: 1;
|
|
54
|
+
/** The Blocks major that generated this schema; `deco check` requires it. */
|
|
55
|
+
blocksMajor: typeof BLOCKS_MAJOR;
|
|
54
56
|
version: string;
|
|
55
57
|
namespace: string;
|
|
56
58
|
site: string;
|
|
@@ -424,6 +426,7 @@ export async function generateSchema(paths: DecoPaths): Promise<SchemaResult> {
|
|
|
424
426
|
|
|
425
427
|
const meta: DecoMeta = {
|
|
426
428
|
major: 1,
|
|
429
|
+
blocksMajor: BLOCKS_MAJOR,
|
|
427
430
|
version: packageVersion(),
|
|
428
431
|
namespace: "site",
|
|
429
432
|
site: siteName(paths.root),
|