@decocms/blocks 8.7.0 → 8.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/protocol/conformance/cases/changes.d.ts.map +1 -1
  6. package/dist/protocol/conformance/cases/changes.js +14 -3
  7. package/dist/protocol/conformance/cases/changes.js.map +1 -1
  8. package/dist/protocol/conformance/cases/guards.d.ts.map +1 -1
  9. package/dist/protocol/conformance/cases/guards.js +19 -42
  10. package/dist/protocol/conformance/cases/guards.js.map +1 -1
  11. package/dist/protocol/conformance/cases/overlay.d.ts +3 -0
  12. package/dist/protocol/conformance/cases/overlay.d.ts.map +1 -0
  13. package/dist/protocol/conformance/cases/overlay.js +164 -0
  14. package/dist/protocol/conformance/cases/overlay.js.map +1 -0
  15. package/dist/protocol/conformance/cases/reads.js +5 -5
  16. package/dist/protocol/conformance/cases/reads.js.map +1 -1
  17. package/dist/protocol/conformance/cases/writes.d.ts.map +1 -1
  18. package/dist/protocol/conformance/cases/writes.js +15 -3
  19. package/dist/protocol/conformance/cases/writes.js.map +1 -1
  20. package/dist/protocol/conformance/context.d.ts +0 -10
  21. package/dist/protocol/conformance/context.d.ts.map +1 -1
  22. package/dist/protocol/conformance/context.js.map +1 -1
  23. package/dist/protocol/conformance/index.d.ts.map +1 -1
  24. package/dist/protocol/conformance/index.js +2 -0
  25. package/dist/protocol/conformance/index.js.map +1 -1
  26. package/dist/protocol/server/content.d.ts +8 -1
  27. package/dist/protocol/server/content.d.ts.map +1 -1
  28. package/dist/protocol/server/content.js +18 -3
  29. package/dist/protocol/server/content.js.map +1 -1
  30. package/dist/protocol/server/core.d.ts +0 -6
  31. package/dist/protocol/server/core.d.ts.map +1 -1
  32. package/dist/protocol/server/core.js +0 -2
  33. package/dist/protocol/server/core.js.map +1 -1
  34. package/dist/protocol/server/methods/apply.d.ts +16 -5
  35. package/dist/protocol/server/methods/apply.d.ts.map +1 -1
  36. package/dist/protocol/server/methods/apply.js +42 -38
  37. package/dist/protocol/server/methods/apply.js.map +1 -1
  38. package/dist/protocol/server/methods/changes.d.ts.map +1 -1
  39. package/dist/protocol/server/methods/changes.js +31 -3
  40. package/dist/protocol/server/methods/changes.js.map +1 -1
  41. package/dist/protocol/server/methods/read.d.ts.map +1 -1
  42. package/dist/protocol/server/methods/read.js +2 -23
  43. package/dist/protocol/server/methods/read.js.map +1 -1
  44. package/dist/protocol/storage/fs/index.d.ts.map +1 -1
  45. package/dist/protocol/storage/fs/index.js +0 -18
  46. package/dist/protocol/storage/fs/index.js.map +1 -1
  47. package/dist/protocol/storage/memory.d.ts +11 -3
  48. package/dist/protocol/storage/memory.d.ts.map +1 -1
  49. package/dist/protocol/storage/memory.js +114 -45
  50. package/dist/protocol/storage/memory.js.map +1 -1
  51. package/dist/protocol/storage.d.ts +68 -18
  52. package/dist/protocol/storage.d.ts.map +1 -1
  53. package/dist/protocol/storage.js +7 -0
  54. package/dist/protocol/storage.js.map +1 -1
  55. package/dist/protocol/types.d.ts +51 -8
  56. package/dist/protocol/types.d.ts.map +1 -1
  57. package/dist/protocol/types.js +5 -3
  58. package/dist/protocol/types.js.map +1 -1
  59. package/dist/v8/builtins/index.d.ts +1 -4
  60. package/dist/v8/builtins/index.d.ts.map +1 -1
  61. package/dist/v8/builtins/index.js +1 -6
  62. package/dist/v8/builtins/index.js.map +1 -1
  63. package/dist/v8/builtins/legacy.d.ts +4 -4
  64. package/dist/v8/builtins/legacy.d.ts.map +1 -1
  65. package/dist/v8/builtins/legacy.js +4 -5
  66. package/dist/v8/builtins/legacy.js.map +1 -1
  67. package/dist/v8/cli/builtins.d.ts.map +1 -1
  68. package/dist/v8/cli/builtins.js +0 -1
  69. package/dist/v8/cli/builtins.js.map +1 -1
  70. package/dist/v8/cli/check/index.d.ts +1 -1
  71. package/dist/v8/cli/check/index.d.ts.map +1 -1
  72. package/dist/v8/cli/check/index.js +13 -33
  73. package/dist/v8/cli/check/index.js.map +1 -1
  74. package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -1
  75. package/dist/v8/cli/schema/builtinSchemas.js +0 -8
  76. package/dist/v8/cli/schema/builtinSchemas.js.map +1 -1
  77. package/dist/v8/cli/schema/generate.d.ts.map +1 -1
  78. package/dist/v8/cli/schema/generate.js +1 -8
  79. package/dist/v8/cli/schema/generate.js.map +1 -1
  80. package/dist/v8/cli/schema/typeToSchema.d.ts +0 -1
  81. package/dist/v8/cli/schema/typeToSchema.d.ts.map +1 -1
  82. package/dist/v8/cli/schema/typeToSchema.js +5 -30
  83. package/dist/v8/cli/schema/typeToSchema.js.map +1 -1
  84. package/dist/v8/client.d.ts +1 -1
  85. package/dist/v8/client.d.ts.map +1 -1
  86. package/dist/v8/cms.d.ts.map +1 -1
  87. package/dist/v8/cms.js +5 -13
  88. package/dist/v8/cms.js.map +1 -1
  89. package/dist/v8/index.d.ts +1 -1
  90. package/dist/v8/index.d.ts.map +1 -1
  91. package/dist/v8/resolver.d.ts +1 -1
  92. package/dist/v8/resolver.d.ts.map +1 -1
  93. package/dist/v8/telemetry.d.ts +0 -2
  94. package/dist/v8/telemetry.d.ts.map +1 -1
  95. package/dist/v8/telemetry.js +5 -20
  96. package/dist/v8/telemetry.js.map +1 -1
  97. package/dist/v8/types.d.ts +0 -8
  98. package/dist/v8/types.d.ts.map +1 -1
  99. package/package.json +1 -6
  100. package/src/index.ts +1 -2
  101. package/src/protocol/conformance/cases/changes.ts +16 -4
  102. package/src/protocol/conformance/cases/guards.ts +19 -55
  103. package/src/protocol/conformance/cases/overlay.ts +195 -0
  104. package/src/protocol/conformance/cases/reads.ts +4 -4
  105. package/src/protocol/conformance/cases/writes.ts +15 -3
  106. package/src/protocol/conformance/context.ts +0 -7
  107. package/src/protocol/conformance/index.ts +2 -0
  108. package/src/protocol/server/content.ts +30 -4
  109. package/src/protocol/server/core.ts +0 -3
  110. package/src/protocol/server/methods/apply.ts +43 -38
  111. package/src/protocol/server/methods/changes.ts +42 -4
  112. package/src/protocol/server/methods/read.ts +2 -24
  113. package/src/protocol/storage/fs/index.ts +0 -18
  114. package/src/protocol/storage/memory.ts +124 -46
  115. package/src/protocol/storage.ts +69 -18
  116. package/src/protocol/types.ts +51 -8
  117. package/src/v8/builtins/index.ts +1 -6
  118. package/src/v8/builtins/legacy.ts +4 -5
  119. package/src/v8/cli/builtins.ts +0 -1
  120. package/src/v8/cli/check/index.ts +15 -34
  121. package/src/v8/cli/schema/builtinSchemas.ts +0 -8
  122. package/src/v8/cli/schema/generate.ts +1 -8
  123. package/src/v8/cli/schema/typeToSchema.ts +5 -31
  124. package/src/v8/client.ts +1 -1
  125. package/src/v8/cms.ts +5 -14
  126. package/src/v8/index.ts +0 -1
  127. package/src/v8/resolver.ts +1 -1
  128. package/src/v8/telemetry.ts +5 -20
  129. package/src/v8/types.ts +0 -5
  130. package/dist/protocol/ciphertext.d.ts +0 -7
  131. package/dist/protocol/ciphertext.d.ts.map +0 -1
  132. package/dist/protocol/ciphertext.js +0 -7
  133. package/dist/protocol/ciphertext.js.map +0 -1
  134. package/dist/protocol/secrets.d.ts +0 -22
  135. package/dist/protocol/secrets.d.ts.map +0 -1
  136. package/dist/protocol/secrets.js +0 -207
  137. package/dist/protocol/secrets.js.map +0 -1
  138. package/dist/v8/builtins/secret.d.ts +0 -7
  139. package/dist/v8/builtins/secret.d.ts.map +0 -1
  140. package/dist/v8/builtins/secret.js +0 -68
  141. package/dist/v8/builtins/secret.js.map +0 -1
  142. package/dist/v8/ciphertext.d.ts +0 -58
  143. package/dist/v8/ciphertext.d.ts.map +0 -1
  144. package/dist/v8/ciphertext.js +0 -134
  145. package/dist/v8/ciphertext.js.map +0 -1
  146. package/dist/v8/secrets.d.ts +0 -9
  147. package/dist/v8/secrets.d.ts.map +0 -1
  148. package/dist/v8/secrets.js +0 -14
  149. package/dist/v8/secrets.js.map +0 -1
  150. package/src/protocol/ciphertext.ts +0 -6
  151. package/src/protocol/secrets.ts +0 -239
  152. package/src/v8/builtins/secret.ts +0 -82
  153. package/src/v8/ciphertext.ts +0 -158
  154. package/src/v8/secrets.ts +0 -17
@@ -95,10 +95,13 @@ export const changesCases: ConformanceCase[] = [
95
95
  "base.resolvedRef is a string or null",
96
96
  );
97
97
  assert(typeof first.changes === "object" && first.changes !== null, "a changes map");
98
+ const overlay = (await ctx.describe()).overlay === true;
98
99
  for (const [name, change] of Object.entries(first.changes)) {
99
100
  assert(change.kind === "set" || change.kind === "delete", `${name}: kind`);
100
- if (change.kind === "delete") assertEqual(change.version, null, `${name}: version`);
101
- else assert(typeof change.version === "string", `${name}: a version`);
101
+ // An overlay holds its deletions: a delete carries the tombstone's version.
102
+ if (change.kind === "delete" && !overlay) {
103
+ assertEqual(change.version, null, `${name}: version`);
104
+ } else assert(typeof change.version === "string", `${name}: a version`);
102
105
  }
103
106
  const poll = await ctx.client.changesList({ ifNoneMatch: first.revision });
104
107
  assert(poll.notModified, "polling with the returned revision is 'not modified'");
@@ -304,14 +307,23 @@ export const changesCases: ConformanceCase[] = [
304
307
  const listed = (await changes(ctx)).changes[base.name];
305
308
  assert(listed !== undefined, "the deleted entry is listed");
306
309
  assertEqual(listed!.kind, "delete", "kind");
307
- assertEqual(listed!.version, null, "version");
310
+ if ((await ctx.describe()).overlay === true) {
311
+ assert(
312
+ typeof listed!.version === "string",
313
+ "an overlay's delete has a tombstone version",
314
+ );
315
+ } else assertEqual(listed!.version, null, "version");
308
316
  assert(typeof listed!.baseVersion === "string", "a base version");
309
317
 
310
318
  const detail = (await ctx.client.changesGet({ names: [base.name] })).entries[base.name];
311
319
  assertEqual(detail?.after, null, "after is null");
312
320
  assertEqual(detail?.before, base.value, "before is the base");
313
321
 
314
- await ctx.client.changesDiscard({ names: [base.name], ifMatch: { [base.name]: null } });
322
+ // Guarded with the version changes.list showed (an overlay's tombstone, else null).
323
+ await ctx.client.changesDiscard({
324
+ names: [base.name],
325
+ ifMatch: { [base.name]: listed!.version },
326
+ });
315
327
  const after = await list(ctx);
316
328
  assertEqual(after.blocks[base.name], base.value, "the entry is back");
317
329
  assert(!(base.name in (await changes(ctx)).changes), "no longer a change");
@@ -1,7 +1,6 @@
1
1
  /**
2
- * `blocks.apply`'s own size guards and the secret guard.
2
+ * `blocks.apply`'s own size guards, and the checks it leaves to `deco check`.
3
3
  */
4
- import { encryptToCiphertext, publicKeyPemFromDer } from "../../ciphertext.ts";
5
4
  import { ErrorCode, type InvalidBlockData } from "../../errors.ts";
6
5
  import { MAX_BLOCK_BYTES, MAX_OPS_PER_APPLY, MAX_REQUEST_BYTES } from "../../server/core.ts";
7
6
  import {
@@ -19,27 +18,6 @@ async function writable(ctx: ConformanceContext) {
19
18
  return d;
20
19
  }
21
20
 
22
- /** A throwaway public key, for endpoints that don't report one. */
23
- async function ephemeralPublicKey(): Promise<string> {
24
- const pair = (await crypto.subtle.generateKey(
25
- {
26
- name: "RSA-OAEP",
27
- modulusLength: 2048,
28
- publicExponent: new Uint8Array([1, 0, 1]),
29
- hash: "SHA-256",
30
- },
31
- true,
32
- ["encrypt", "decrypt"],
33
- )) as CryptoKeyPair;
34
- return publicKeyPemFromDer(new Uint8Array(await crypto.subtle.exportKey("spki", pair.publicKey)));
35
- }
36
-
37
- /** A real ciphertext: encrypted with the endpoint's public key when it reports one. */
38
- async function realCiphertext(ctx: ConformanceContext, value: string): Promise<string> {
39
- const publicKey = (await ctx.describe()).secrets?.publicKey ?? (await ephemeralPublicKey());
40
- return encryptToCiphertext(publicKey, value);
41
- }
42
-
43
21
  export const guardCases: ConformanceCase[] = [
44
22
  {
45
23
  id: "limits/ops-per-apply",
@@ -96,41 +74,27 @@ export const guardCases: ConformanceCase[] = [
96
74
  },
97
75
  },
98
76
  {
99
- id: "secrets/guard",
100
- title: "a Secret field accepts only a secret block with a well-formed ciphertext",
77
+ id: "writes/schema-free",
78
+ title: "blocks.apply saves any JSON object, whatever the schema says about it",
101
79
  async run(ctx) {
102
80
  await writable(ctx);
103
- const fixture = ctx.options.secretField;
104
- if (!fixture) return ctx.skip("no secretField fixture");
105
- const block = (value: unknown) => ({
106
- __resolveType: fixture.blockType,
107
- [fixture.field]: value,
108
- });
109
- const plain = ctx.name("plain-secret");
110
- const error = await expectError(
111
- ctx.client.blocksApply({ set: { [plain]: block("hunter2") } }),
112
- ErrorCode.InvalidBlock,
113
- "plain text in a Secret field",
114
- );
115
- const violation = (error.data as InvalidBlockData).violations[0];
116
- assertEqual(violation?.name, plain, "the violation names the entry");
117
- // Text that only looks like a ciphertext is plain text all the same.
118
- for (const ciphertext of ["hunter2", "v1.hunter2", "v1.my-api-key_123", "v1.QUJD.ZGVm"]) {
119
- await expectError(
120
- ctx.client.blocksApply({
121
- set: { [ctx.name("bad-cipher")]: block({ __resolveType: "secret", ciphertext }) },
122
- }),
123
- ErrorCode.InvalidBlock,
124
- `the malformed ciphertext ${JSON.stringify(ciphertext)}`,
125
- );
126
- }
127
- const ok = ctx.name("secret");
128
- const ciphertext = await realCiphertext(ctx, "conformance-value");
129
- await ctx.client.blocksApply({
130
- set: { [ok]: block({ __resolveType: "secret", ciphertext }) },
131
- });
81
+ // The schema is `deco check`'s business, in the site's CI: a write never reads it.
82
+ const values = {
83
+ [ctx.name("unknown-type")]: { __resolveType: "conformance/not-in-any-schema.tsx", x: 1 },
84
+ [ctx.name("v7-secret")]: {
85
+ __resolveType: "website/loaders/secret.ts",
86
+ encrypted: "not-a-ciphertext",
87
+ },
88
+ [ctx.name("plain-field")]: { __resolveType: "secret", ciphertext: "hunter2" },
89
+ [ctx.name("no-type")]: { title: 42, sections: "not a list" },
90
+ };
91
+ const applied = await ctx.client.blocksApply({ set: values });
132
92
  const list = await ctx.client.blocksList();
133
- assert(!list.notModified && ok in list.blocks, "an encrypted value is saved");
93
+ assert(!list.notModified, "an unconditional list returns the map");
94
+ for (const [name, value] of Object.entries(values)) {
95
+ assertEqual(list.blocks[name], value, `${name} is saved as sent`);
96
+ assertEqual(list.versions[name], applied.versions[name], `${name}'s version`);
97
+ }
134
98
  },
135
99
  },
136
100
  ];
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Overlay endpoints (protocol 1.2, `describe.overlay`), such as a hosted
3
+ * draft over the published branch: `blocks.apply`'s `ifMatch` compares with
4
+ * the overlay alone, and `changes.list` is the overlay's own entries. A
5
+ * deletion the overlay records is one of them: it has a tombstone version,
6
+ * so `ifMatch: null` on it fails. Every case skips on an endpoint that isn't
7
+ * an overlay.
8
+ */
9
+ import { ErrorCode } from "../../errors.ts";
10
+ import type { BlocksListResult, ChangesListResult } from "../../types.ts";
11
+ import { assert, assertEqual, type ConformanceContext, expectError } from "../context.ts";
12
+ import type { ConformanceCase } from "./types.ts";
13
+
14
+ type FullList = Extract<BlocksListResult, { notModified: false }>;
15
+ type FullChanges = Extract<ChangesListResult, { notModified: false }>;
16
+
17
+ async function list(ctx: ConformanceContext): Promise<FullList> {
18
+ const result = await ctx.client.blocksList();
19
+ assert(!result.notModified, "an unconditional list returns the map");
20
+ return result;
21
+ }
22
+
23
+ async function changes(ctx: ConformanceContext): Promise<FullChanges> {
24
+ const result = await ctx.client.changesList();
25
+ assert(!result.notModified, "an unconditional changes.list returns the changes");
26
+ return result;
27
+ }
28
+
29
+ async function overlay(ctx: ConformanceContext) {
30
+ const d = await ctx.describe();
31
+ if (d.overlay !== true) return ctx.skip("not an overlay endpoint");
32
+ if (d.readOnly) return ctx.skip("read-only endpoint");
33
+ return d;
34
+ }
35
+
36
+ /** The harness's base entry, which the overlay doesn't hold yet. */
37
+ async function baseEntry(ctx: ConformanceContext) {
38
+ const name = ctx.options.baseEntry?.name;
39
+ if (name === undefined) return ctx.skip("no baseEntry");
40
+ const blocks = await list(ctx);
41
+ assert(name in blocks.blocks, `the baseEntry "${name}" exists`);
42
+ assert(!(name in (await changes(ctx)).changes), `the overlay doesn't hold "${name}" yet`);
43
+ return { name, value: blocks.blocks[name]!, version: blocks.versions[name]! };
44
+ }
45
+
46
+ export const overlayCases: ConformanceCase[] = [
47
+ {
48
+ id: "overlay/if-match",
49
+ title: "on an overlay, ifMatch null means the overlay doesn't hold the entry yet",
50
+ async run(ctx) {
51
+ await overlay(ctx);
52
+ const name = ctx.name("guarded");
53
+ const first = await ctx.client.blocksApply({
54
+ set: { [name]: { v: 1 } },
55
+ ifMatch: { [name]: null },
56
+ });
57
+ const error = await expectError(
58
+ ctx.client.blocksApply({ set: { [name]: { v: 2 } }, ifMatch: { [name]: null } }),
59
+ ErrorCode.Conflict,
60
+ "ifMatch null on an entry the overlay holds",
61
+ );
62
+ assertEqual(
63
+ (error.data as { entries?: unknown })?.entries,
64
+ { [name]: { expected: null, actual: first.versions[name] } },
65
+ "the conflict's entries",
66
+ );
67
+ const listed = (await changes(ctx)).changes[name];
68
+ assertEqual(
69
+ listed?.version,
70
+ first.versions[name],
71
+ "changes.list reports the guard's version",
72
+ );
73
+ await ctx.client.blocksApply({
74
+ set: { [name]: { v: 2 } },
75
+ ifMatch: { [name]: listed!.version },
76
+ });
77
+ assertEqual((await list(ctx)).blocks[name], { v: 2 }, "the guarded save landed");
78
+ },
79
+ },
80
+ {
81
+ id: "overlay/if-match-base",
82
+ title: "an entry only the base has is not in the overlay: ifMatch null saves it",
83
+ async run(ctx) {
84
+ await overlay(ctx);
85
+ const base = await baseEntry(ctx);
86
+ try {
87
+ const modified = { ...base.value, conformance: ctx.prefix };
88
+ const applied = await ctx.client.blocksApply({
89
+ set: { [base.name]: modified },
90
+ ifMatch: { [base.name]: null },
91
+ });
92
+ const listed = (await changes(ctx)).changes[base.name];
93
+ assertEqual(listed?.kind, "set", "the saved base entry is a change");
94
+ assertEqual(listed?.version, applied.versions[base.name], "with the saved version");
95
+ await expectError(
96
+ ctx.client.blocksApply({
97
+ set: { [base.name]: base.value },
98
+ ifMatch: { [base.name]: null },
99
+ }),
100
+ ErrorCode.Conflict,
101
+ "ifMatch null once the overlay holds the entry",
102
+ );
103
+ } finally {
104
+ await ctx.client.changesDiscard({ names: [base.name] }).catch(() => {});
105
+ }
106
+ },
107
+ },
108
+ {
109
+ id: "overlay/own-entries",
110
+ title: "changes.list lists every entry the overlay holds, even one equal to the base",
111
+ async run(ctx) {
112
+ await overlay(ctx);
113
+ const base = await baseEntry(ctx);
114
+ try {
115
+ const applied = await ctx.client.blocksApply({ set: { [base.name]: base.value } });
116
+ const listed = (await changes(ctx)).changes[base.name];
117
+ assertEqual(
118
+ listed?.kind,
119
+ "set",
120
+ "an entry saved with the base's value is still the overlay's",
121
+ );
122
+ assertEqual(listed?.version, applied.versions[base.name], "with the saved version");
123
+ await ctx.client.changesDiscard({ names: [base.name] });
124
+ assert(!(base.name in (await changes(ctx)).changes), "a discard drops it from the overlay");
125
+ assertEqual((await list(ctx)).blocks[base.name], base.value, "the base shows through");
126
+ } finally {
127
+ await ctx.client.changesDiscard({ names: [base.name] }).catch(() => {});
128
+ }
129
+ },
130
+ },
131
+ {
132
+ id: "overlay/delete-base",
133
+ title: "deleting an entry only the base has records the deletion over the base",
134
+ async run(ctx) {
135
+ await overlay(ctx);
136
+ const base = await baseEntry(ctx);
137
+ try {
138
+ const deleted = await ctx.client.blocksApply({ delete: [base.name] });
139
+ const tombstone = deleted.versions[base.name];
140
+ assert(typeof tombstone === "string", "the deletion reports its tombstone version");
141
+ assert(!(base.name in (await list(ctx)).blocks), "the entry is gone from blocks.list");
142
+ const listed = (await changes(ctx)).changes[base.name];
143
+ assertEqual(listed?.kind, "delete", "a delete change");
144
+ assertEqual(listed?.version, tombstone, "changes.list reports the tombstone version");
145
+ // A discard guarded with the version changes.list showed lands.
146
+ await ctx.client.changesDiscard({
147
+ names: [base.name],
148
+ ifMatch: { [base.name]: tombstone! },
149
+ });
150
+ } finally {
151
+ await ctx.client.changesDiscard({ names: [base.name] }).catch(() => {});
152
+ }
153
+ assertEqual((await list(ctx)).blocks[base.name], base.value, "a discard brings it back");
154
+ },
155
+ },
156
+ {
157
+ id: "overlay/if-match-deleted",
158
+ title:
159
+ "an entry the overlay deletes is in the overlay: ifMatch null fails, its tombstone passes",
160
+ async run(ctx) {
161
+ await overlay(ctx);
162
+ const base = await baseEntry(ctx);
163
+ try {
164
+ await ctx.client.blocksApply({ delete: [base.name] });
165
+ const tombstone = (await changes(ctx)).changes[base.name]?.version;
166
+ assert(typeof tombstone === "string", "changes.list reports the tombstone version");
167
+ const restored = { ...base.value, conformance: ctx.prefix };
168
+ const error = await expectError(
169
+ ctx.client.blocksApply({
170
+ set: { [base.name]: restored },
171
+ ifMatch: { [base.name]: null },
172
+ }),
173
+ ErrorCode.Conflict,
174
+ "ifMatch null on an entry the overlay deletes",
175
+ );
176
+ assertEqual(
177
+ (error.data as { entries?: unknown })?.entries,
178
+ { [base.name]: { expected: null, actual: tombstone } },
179
+ "the conflict's entries",
180
+ );
181
+ assert(!(base.name in (await list(ctx)).blocks), "the refused save wrote nothing");
182
+ const applied = await ctx.client.blocksApply({
183
+ set: { [base.name]: restored },
184
+ ifMatch: { [base.name]: tombstone! },
185
+ });
186
+ assertEqual((await list(ctx)).blocks[base.name], restored, "the guarded save landed");
187
+ const listed = (await changes(ctx)).changes[base.name];
188
+ assertEqual(listed?.kind, "set", "the entry is a set change again");
189
+ assertEqual(listed?.version, applied.versions[base.name], "with the saved version");
190
+ } finally {
191
+ await ctx.client.changesDiscard({ names: [base.name] }).catch(() => {});
192
+ }
193
+ },
194
+ },
195
+ ];
@@ -30,16 +30,16 @@ export const readCases: ConformanceCase[] = [
30
30
  assert(d.assets.maxBytes > 0 && typeof d.assets.dir === "string", "assets");
31
31
  }
32
32
  assert(d.secrets === null || typeof d.secrets.publicKey === "string", "secrets");
33
+ assert(d.overlay === undefined || d.overlay === true, "overlay is absent or true");
33
34
  },
34
35
  },
35
36
  {
36
37
  id: "describe/secrets",
37
- title: "describe returns the committed public key for secrets",
38
+ title: "describe reports no secrets key: content holds no secrets",
38
39
  async run(ctx) {
39
- const expected = ctx.options.secretsPublicKey;
40
- if (expected === undefined) return ctx.skip("no secretsPublicKey fixture");
41
40
  const d = await ctx.client.describe();
42
- assertEqual(d.secrets, { publicKey: expected }, "describe.secrets");
41
+ if (d.version.minor < 2) return ctx.skip(`protocol 1.${d.version.minor} predates 1.2`);
42
+ assertEqual(d.secrets, null, "describe.secrets");
43
43
  },
44
44
  },
45
45
  {
@@ -27,6 +27,16 @@ function violations(error: { data: unknown }): InvalidBlockData["violations"] {
27
27
  return data!.violations;
28
28
  }
29
29
 
30
+ /**
31
+ * A deleted name's version in a `blocks.apply` result: `null`, except on an
32
+ * overlay, which may record a tombstone even for a name the base lacks (a
33
+ * hosted draft's save never reads the base) and then reports its version.
34
+ */
35
+ async function assertDeletedVersion(ctx: ConformanceContext, version: unknown, label: string) {
36
+ if ((await ctx.describe()).overlay === true && typeof version === "string") return;
37
+ assertEqual(version, null, label);
38
+ }
39
+
30
40
  export const writeCases: ConformanceCase[] = [
31
41
  {
32
42
  id: "apply/create-and-read",
@@ -54,7 +64,7 @@ export const writeCases: ConformanceCase[] = [
54
64
  const [a, b, c] = [ctx.name("a"), ctx.name("b"), ctx.name("c")];
55
65
  await ctx.client.blocksApply({ set: { [a]: { v: 1 }, [b]: { v: 2 } } });
56
66
  const result = await ctx.client.blocksApply({ set: { [c]: { v: 3 } }, delete: [a] });
57
- assertEqual(result.versions[a], null, "a deleted entry's version is null");
67
+ await assertDeletedVersion(ctx, result.versions[a], "a deleted entry's version is null");
58
68
  const after = await list(ctx);
59
69
  assert(!(a in after.blocks), "the deleted entry is gone");
60
70
  assertEqual(after.blocks[b], { v: 2 }, "the untouched entry stays");
@@ -82,7 +92,8 @@ export const writeCases: ConformanceCase[] = [
82
92
  await writable(ctx);
83
93
  const name = ctx.name("missing");
84
94
  const result = await ctx.client.blocksApply({ delete: [name] });
85
- assertEqual(result.versions, { [name]: null }, "versions");
95
+ assertEqual(Object.keys(result.versions), [name], "versions");
96
+ await assertDeletedVersion(ctx, result.versions[name], "the missing name's version");
86
97
  },
87
98
  },
88
99
  {
@@ -149,7 +160,8 @@ export const writeCases: ConformanceCase[] = [
149
160
  }
150
161
  // A name ending in a source extension can still be deleted.
151
162
  const result = await ctx.client.blocksApply({ delete: [`${p}-mod.ts`] });
152
- assertEqual(result.versions, { [`${p}-mod.ts`]: null }, "deleting a .ts name");
163
+ assertEqual(Object.keys(result.versions), [`${p}-mod.ts`], "deleting a .ts name");
164
+ await assertDeletedVersion(ctx, result.versions[`${p}-mod.ts`], "the .ts name's version");
153
165
  },
154
166
  },
155
167
  {
@@ -17,13 +17,6 @@ export interface ConformanceOptions {
17
17
  headers?: Record<string, string>;
18
18
  /** A fetch implementation (defaults to the global one); use it to call a handler in process. */
19
19
  fetch?: (request: Request) => Promise<Response>;
20
- /**
21
- * A block type in the endpoint's schema with a `Secret` field, so the
22
- * secret guard can be checked. Leave out to skip those cases.
23
- */
24
- secretField?: { blockType: string; field: string };
25
- /** The `.deco/secrets.pub` content the endpoint should report, if the harness wrote one. */
26
- secretsPublicKey?: string;
27
20
  /** Whether the endpoint has a schema (default true). `false` checks the `schema: null` result instead. */
28
21
  hasSchema?: boolean;
29
22
  /**
@@ -23,6 +23,7 @@
23
23
  import { assetCases } from "./cases/assets.ts";
24
24
  import { changesCases } from "./cases/changes.ts";
25
25
  import { guardCases } from "./cases/guards.ts";
26
+ import { overlayCases } from "./cases/overlay.ts";
26
27
  import { readCases } from "./cases/reads.ts";
27
28
  import type { ConformanceCase } from "./cases/types.ts";
28
29
  import { wireCases } from "./cases/wire.ts";
@@ -40,6 +41,7 @@ export const conformanceCases: readonly ConformanceCase[] = [
40
41
  ...writeCases,
41
42
  ...guardCases,
42
43
  ...changesCases,
44
+ ...overlayCases,
43
45
  ...assetCases,
44
46
  ];
45
47
 
@@ -5,7 +5,13 @@
5
5
  * needs bodies only to break ties between spellings).
6
6
  */
7
7
  import { unavailable } from "../errors.ts";
8
- import { entryHasPath, fullyDecodeFileName, isBlockFileName, resolveSpellings } from "../keys.ts";
8
+ import {
9
+ blockNameFromFile,
10
+ entryHasPath,
11
+ fullyDecodeFileName,
12
+ isBlockFileName,
13
+ resolveSpellings,
14
+ } from "../keys.ts";
9
15
  import type { ContentStorage, StorageFile, StorageSnapshot } from "../storage.ts";
10
16
  import type { Diagnostic } from "../types.ts";
11
17
  import { type BodyCache, type ParsedBody, parseBody } from "./bodyCache.ts";
@@ -16,13 +22,18 @@ export interface LoadedEntry {
16
22
  version: string;
17
23
  /** The parsed entry; absent when the body wasn't needed. */
18
24
  value?: Record<string, unknown>;
25
+ /**
26
+ * `true` for an entry an overlay deletes (only in `writeSnapshot()`'s
27
+ * listing): no file of it exists, and `version` is its tombstone's.
28
+ */
29
+ deleted?: true;
19
30
  }
20
31
 
21
32
  export interface LoadedContent {
22
33
  snapshot: StorageSnapshot;
23
34
  /** Every entry, by name, in file-name order of the winning files. */
24
35
  entries: Map<string, LoadedEntry>;
25
- /** Every saved-block file, valid or not, by spelling key. */
36
+ /** Every saved-block file, valid or not, by spelling key (tombstones too). */
26
37
  groups: Map<string, StorageFile[]>;
27
38
  /** Files skipped or shadowed. */
28
39
  diagnostics: Diagnostic[];
@@ -40,6 +51,8 @@ interface Options {
40
51
  /** Read every body (`blocks.list`), not only the ones that break ties. */
41
52
  readAll: boolean;
42
53
  cache: BodyCache;
54
+ /** Takes the snapshot (default: `storage.snapshot()`; `blocks.apply` on an overlay: `writeSnapshot()`). */
55
+ take?: () => Promise<StorageSnapshot>;
43
56
  }
44
57
 
45
58
  async function loadContent(
@@ -60,7 +73,9 @@ async function loadContent(
60
73
  let moved = false;
61
74
  const parsed = new Map<string, ParsedBody>();
62
75
  const toRead: StorageFile[] = [];
63
- for (const group of groups.values()) {
76
+ for (const all of groups.values()) {
77
+ // A tombstone has no body: it's never read, nor a spelling that competes.
78
+ const group = all.filter((f) => !f.deleted);
64
79
  if (!readAll && group.length < 2) continue;
65
80
  for (const file of group) {
66
81
  // An existing file over MAX_BLOCK_BYTES is unreadable, like invalid JSON: it's
@@ -106,6 +121,7 @@ async function loadContent(
106
121
  let bytes = 0;
107
122
  const candidates: Array<StorageFile & { hasPath: boolean; value?: Record<string, unknown> }> = [];
108
123
  for (const file of files) {
124
+ if (file.deleted) continue;
109
125
  const body = parsed.get(file.file);
110
126
  if (body === undefined) {
111
127
  // Not read: a single spelling whose body wasn't needed, or a file that vanished.
@@ -133,6 +149,16 @@ async function loadContent(
133
149
  });
134
150
  }
135
151
  }
152
+ // An entry the overlay deletes (no spelling of it left) holds its first tombstone's version.
153
+ for (const group of groups.values()) {
154
+ if (group.some((f) => !f.deleted)) continue;
155
+ const tombstone = [...group].sort((a, b) => (a.file < b.file ? -1 : 1))[0]!;
156
+ entries.set(blockNameFromFile(tombstone.file), {
157
+ file: tombstone.file,
158
+ version: tombstone.version,
159
+ deleted: true,
160
+ });
161
+ }
136
162
  diagnostics.sort((a, b) => (a.file < b.file ? -1 : a.file > b.file ? 1 : 0));
137
163
  return { snapshot, entries, groups, diagnostics, bytes, moved };
138
164
  }
@@ -152,7 +178,7 @@ export async function loadCurrentContent(
152
178
  shortCircuit?: (snapshot: StorageSnapshot) => boolean,
153
179
  ): Promise<{ snapshot: StorageSnapshot; content: LoadedContent | null }> {
154
180
  for (let read = 1; read <= MAX_SNAPSHOT_READS; read++) {
155
- const snapshot = await storage.snapshot();
181
+ const snapshot = await (options.take ?? (() => storage.snapshot()))();
156
182
  if (shortCircuit?.(snapshot)) return { snapshot, content: null };
157
183
  const content = await loadContent(storage, snapshot, options);
158
184
  if (!content.moved) return { snapshot, content };
@@ -11,7 +11,6 @@ import {
11
11
  StorageNotFoundError,
12
12
  StorageUnavailableError,
13
13
  } from "../storage.ts";
14
- import type { DecoMeta } from "../types.ts";
15
14
  import { BodyCache } from "./bodyCache.ts";
16
15
 
17
16
  const MiB = 1024 * 1024;
@@ -51,8 +50,6 @@ const DEFAULT_RETRY_DELAY = { minMs: 50, maxMs: 200 };
51
50
 
52
51
  export class Core {
53
52
  readonly cache: BodyCache;
54
- /** The last parsed schema, by version: the secret guard reads it on every write. */
55
- parsedSchema: { version: string; meta: DecoMeta } | null = null;
56
53
  /**
57
54
  * The last `storage.changes()` answer, by changes revision (base plus
58
55
  * content): a poll on unchanged content and base doesn't ask the storage