@decocms/blocks 8.1.0-next.4 → 8.1.0-next.6

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 (178) hide show
  1. package/dist/protocol/client.d.ts +1 -3
  2. package/dist/protocol/client.d.ts.map +1 -1
  3. package/dist/protocol/client.js +0 -2
  4. package/dist/protocol/client.js.map +1 -1
  5. package/dist/protocol/conformance/cases/guards.d.ts.map +1 -1
  6. package/dist/protocol/conformance/cases/guards.js +10 -173
  7. package/dist/protocol/conformance/cases/guards.js.map +1 -1
  8. package/dist/protocol/conformance/cases/reads.d.ts.map +1 -1
  9. package/dist/protocol/conformance/cases/reads.js +24 -53
  10. package/dist/protocol/conformance/cases/reads.js.map +1 -1
  11. package/dist/protocol/conformance/cases/writes.d.ts.map +1 -1
  12. package/dist/protocol/conformance/cases/writes.js +3 -20
  13. package/dist/protocol/conformance/cases/writes.js.map +1 -1
  14. package/dist/protocol/conformance/contentHashFixtures.d.ts +0 -29
  15. package/dist/protocol/conformance/contentHashFixtures.d.ts.map +1 -1
  16. package/dist/protocol/conformance/contentHashFixtures.js +0 -30
  17. package/dist/protocol/conformance/contentHashFixtures.js.map +1 -1
  18. package/dist/protocol/conformance/context.d.ts +4 -29
  19. package/dist/protocol/conformance/context.d.ts.map +1 -1
  20. package/dist/protocol/conformance/context.js +4 -13
  21. package/dist/protocol/conformance/context.js.map +1 -1
  22. package/dist/protocol/conformance/index.d.ts +1 -1
  23. package/dist/protocol/conformance/index.d.ts.map +1 -1
  24. package/dist/protocol/conformance/index.js +4 -4
  25. package/dist/protocol/conformance/index.js.map +1 -1
  26. package/dist/protocol/errors.d.ts +5 -9
  27. package/dist/protocol/errors.d.ts.map +1 -1
  28. package/dist/protocol/errors.js +4 -4
  29. package/dist/protocol/errors.js.map +1 -1
  30. package/dist/protocol/index.d.ts +3 -5
  31. package/dist/protocol/index.d.ts.map +1 -1
  32. package/dist/protocol/index.js +3 -5
  33. package/dist/protocol/index.js.map +1 -1
  34. package/dist/protocol/params.d.ts.map +1 -1
  35. package/dist/protocol/params.js +0 -4
  36. package/dist/protocol/params.js.map +1 -1
  37. package/dist/protocol/server/assets.d.ts +2 -3
  38. package/dist/protocol/server/assets.d.ts.map +1 -1
  39. package/dist/protocol/server/assets.js +2 -9
  40. package/dist/protocol/server/assets.js.map +1 -1
  41. package/dist/protocol/server/content.d.ts +2 -3
  42. package/dist/protocol/server/content.d.ts.map +1 -1
  43. package/dist/protocol/server/content.js +10 -22
  44. package/dist/protocol/server/content.js.map +1 -1
  45. package/dist/protocol/server/core.d.ts +8 -11
  46. package/dist/protocol/server/core.d.ts.map +1 -1
  47. package/dist/protocol/server/core.js +8 -24
  48. package/dist/protocol/server/core.js.map +1 -1
  49. package/dist/protocol/server/handler.d.ts.map +1 -1
  50. package/dist/protocol/server/handler.js +11 -23
  51. package/dist/protocol/server/handler.js.map +1 -1
  52. package/dist/protocol/server/http.d.ts +6 -4
  53. package/dist/protocol/server/http.d.ts.map +1 -1
  54. package/dist/protocol/server/http.js +1 -18
  55. package/dist/protocol/server/http.js.map +1 -1
  56. package/dist/protocol/server/index.d.ts +0 -1
  57. package/dist/protocol/server/index.d.ts.map +1 -1
  58. package/dist/protocol/server/index.js.map +1 -1
  59. package/dist/protocol/server/methods/apply.d.ts +2 -2
  60. package/dist/protocol/server/methods/apply.d.ts.map +1 -1
  61. package/dist/protocol/server/methods/apply.js +23 -71
  62. package/dist/protocol/server/methods/apply.js.map +1 -1
  63. package/dist/protocol/server/methods/read.d.ts +0 -6
  64. package/dist/protocol/server/methods/read.d.ts.map +1 -1
  65. package/dist/protocol/server/methods/read.js +7 -31
  66. package/dist/protocol/server/methods/read.js.map +1 -1
  67. package/dist/protocol/server/rpc.d.ts +1 -1
  68. package/dist/protocol/server/rpc.d.ts.map +1 -1
  69. package/dist/protocol/server/rpc.js +9 -39
  70. package/dist/protocol/server/rpc.js.map +1 -1
  71. package/dist/protocol/storage/fs/index.d.ts +0 -3
  72. package/dist/protocol/storage/fs/index.d.ts.map +1 -1
  73. package/dist/protocol/storage/fs/index.js +0 -5
  74. package/dist/protocol/storage/fs/index.js.map +1 -1
  75. package/dist/protocol/storage/memory.d.ts +1 -6
  76. package/dist/protocol/storage/memory.d.ts.map +1 -1
  77. package/dist/protocol/storage/memory.js +1 -30
  78. package/dist/protocol/storage/memory.js.map +1 -1
  79. package/dist/protocol/storage.d.ts +7 -50
  80. package/dist/protocol/storage.d.ts.map +1 -1
  81. package/dist/protocol/storage.js +1 -1
  82. package/dist/protocol/storage.js.map +1 -1
  83. package/dist/protocol/types.d.ts +23 -34
  84. package/dist/protocol/types.d.ts.map +1 -1
  85. package/dist/protocol/types.js +10 -10
  86. package/dist/protocol/types.js.map +1 -1
  87. package/dist/v8/boundedJson.d.ts +11 -0
  88. package/dist/v8/boundedJson.d.ts.map +1 -0
  89. package/dist/v8/boundedJson.js +44 -0
  90. package/dist/v8/boundedJson.js.map +1 -0
  91. package/dist/v8/canonical.d.ts +0 -35
  92. package/dist/v8/canonical.d.ts.map +1 -1
  93. package/dist/v8/canonical.js +0 -28
  94. package/dist/v8/canonical.js.map +1 -1
  95. package/dist/v8/cli/check/index.d.ts +5 -0
  96. package/dist/v8/cli/check/index.d.ts.map +1 -1
  97. package/dist/v8/cli/check/index.js +21 -1
  98. package/dist/v8/cli/check/index.js.map +1 -1
  99. package/dist/v8/cli/run.js +1 -1
  100. package/dist/v8/cli/schema/generate.d.ts +3 -1
  101. package/dist/v8/cli/schema/generate.d.ts.map +1 -1
  102. package/dist/v8/cli/schema/generate.js +2 -1
  103. package/dist/v8/cli/schema/generate.js.map +1 -1
  104. package/dist/v8/cli/serve/server.d.ts +1 -1
  105. package/dist/v8/cli/serve/server.d.ts.map +1 -1
  106. package/dist/v8/cli/serve/server.js +63 -23
  107. package/dist/v8/cli/serve/server.js.map +1 -1
  108. package/dist/v8/cms.d.ts.map +1 -1
  109. package/dist/v8/cms.js +7 -6
  110. package/dist/v8/cms.js.map +1 -1
  111. package/dist/v8/content.d.ts +6 -5
  112. package/dist/v8/content.d.ts.map +1 -1
  113. package/dist/v8/content.js +49 -39
  114. package/dist/v8/content.js.map +1 -1
  115. package/dist/v8/draft.d.ts +1 -1
  116. package/dist/v8/draft.d.ts.map +1 -1
  117. package/dist/v8/draft.js +24 -2
  118. package/dist/v8/draft.js.map +1 -1
  119. package/dist/v8/draftChanges.d.ts +44 -0
  120. package/dist/v8/draftChanges.d.ts.map +1 -0
  121. package/dist/v8/draftChanges.js +157 -0
  122. package/dist/v8/draftChanges.js.map +1 -0
  123. package/dist/v8/remoteLoader.d.ts +1 -1
  124. package/dist/v8/remoteLoader.d.ts.map +1 -1
  125. package/dist/v8/remoteLoader.js +19 -256
  126. package/dist/v8/remoteLoader.js.map +1 -1
  127. package/dist/v8/settings.d.ts.map +1 -1
  128. package/dist/v8/settings.js +9 -6
  129. package/dist/v8/settings.js.map +1 -1
  130. package/dist/v8/telemetry.d.ts +4 -0
  131. package/dist/v8/telemetry.d.ts.map +1 -1
  132. package/dist/v8/telemetry.js +49 -14
  133. package/dist/v8/telemetry.js.map +1 -1
  134. package/dist/v8/types.d.ts +20 -12
  135. package/dist/v8/types.d.ts.map +1 -1
  136. package/package.json +1 -1
  137. package/src/protocol/client.ts +1 -4
  138. package/src/protocol/conformance/cases/guards.ts +10 -188
  139. package/src/protocol/conformance/cases/reads.ts +29 -69
  140. package/src/protocol/conformance/cases/writes.ts +7 -35
  141. package/src/protocol/conformance/contentHashFixtures.ts +0 -57
  142. package/src/protocol/conformance/context.ts +9 -34
  143. package/src/protocol/conformance/index.ts +4 -9
  144. package/src/protocol/errors.ts +5 -10
  145. package/src/protocol/index.ts +2 -10
  146. package/src/protocol/params.ts +0 -4
  147. package/src/protocol/server/assets.ts +2 -12
  148. package/src/protocol/server/content.ts +10 -24
  149. package/src/protocol/server/core.ts +12 -34
  150. package/src/protocol/server/handler.ts +11 -30
  151. package/src/protocol/server/http.ts +1 -19
  152. package/src/protocol/server/index.ts +0 -1
  153. package/src/protocol/server/methods/apply.ts +22 -82
  154. package/src/protocol/server/methods/read.ts +7 -36
  155. package/src/protocol/server/rpc.ts +7 -47
  156. package/src/protocol/storage/fs/index.ts +0 -8
  157. package/src/protocol/storage/memory.ts +1 -36
  158. package/src/protocol/storage.ts +7 -39
  159. package/src/protocol/types.ts +21 -38
  160. package/src/v8/boundedJson.ts +47 -0
  161. package/src/v8/canonical.ts +0 -47
  162. package/src/v8/cli/check/index.ts +25 -1
  163. package/src/v8/cli/run.ts +1 -1
  164. package/src/v8/cli/schema/generate.ts +4 -1
  165. package/src/v8/cli/serve/server.ts +65 -29
  166. package/src/v8/cms.ts +7 -8
  167. package/src/v8/content.ts +55 -42
  168. package/src/v8/draft.ts +20 -2
  169. package/src/v8/draftChanges.ts +172 -0
  170. package/src/v8/remoteLoader.ts +23 -289
  171. package/src/v8/settings.ts +13 -6
  172. package/src/v8/telemetry.ts +58 -13
  173. package/src/v8/types.ts +23 -13
  174. package/dist/protocol/server/auth.d.ts +0 -31
  175. package/dist/protocol/server/auth.d.ts.map +0 -1
  176. package/dist/protocol/server/auth.js +0 -32
  177. package/dist/protocol/server/auth.js.map +0 -1
  178. package/src/protocol/server/auth.ts +0 -49
@@ -1,11 +1,9 @@
1
1
  /**
2
2
  * HTTP plumbing for the content handler: bounded body reads (gzip request
3
- * bodies included), gzip responses and bearer-token checks. Web-standard APIs
3
+ * bodies included) and gzip responses. Web-standard APIs
4
4
  * only (Request, Response, CompressionStream), so it runs on Node, Bun,
5
5
  * Workers and Deno.
6
6
  */
7
- import { sha256Hex } from "../canonical.ts";
8
-
9
7
  /** The body was larger than allowed (after decompression). */
10
8
  export class BodyTooLargeError extends Error {
11
9
  constructor(readonly limit: number) {
@@ -121,19 +119,3 @@ export function isJsonContentType(request: Request): boolean {
121
119
  const type = request.headers.get("content-type");
122
120
  return type !== null && type.split(";")[0]!.trim().toLowerCase() === "application/json";
123
121
  }
124
-
125
- /** The bearer token of the request, or `null` without one. */
126
- export function bearerToken(request: Request): string | null {
127
- const header = request.headers.get("authorization");
128
- if (!header) return null;
129
- const match = /^Bearer\s+(\S+)\s*$/i.exec(header);
130
- return match?.[1] ?? null;
131
- }
132
-
133
- /** Compares two strings in time independent of where they differ. */
134
- export async function timingSafeEqualStrings(a: string, b: string): Promise<boolean> {
135
- const [ha, hb] = await Promise.all([sha256Hex(a), sha256Hex(b)]);
136
- let diff = 0;
137
- for (let i = 0; i < ha.length; i++) diff |= ha.charCodeAt(i) ^ hb.charCodeAt(i);
138
- return diff === 0;
139
- }
@@ -6,6 +6,5 @@
6
6
  * and Deno. (`deco serve`'s asset uploads use `./assets`, which isn't public.)
7
7
  */
8
8
 
9
- export type { AuthOptions, AuthorizeResult } from "./auth.ts";
10
9
  export type { ContentHandlerOptions } from "./core.ts";
11
10
  export { type ContentHandler, createContentHandler } from "./handler.ts";
@@ -7,27 +7,23 @@
7
7
  * 3. `set` wins when a name is in both `set` and `delete`.
8
8
  * 4. Validated first: names, value shapes, sizes and the secret guard are
9
9
  * checked before anything is written, and every violation is reported.
10
- * 5. Preconditions are optional: a failed `ifMatch` (or `ifSchemaMatch`)
11
- * writes nothing and returns a Conflict; without them the last writer wins.
10
+ * 5. Preconditions are optional: a failed `ifMatch` writes nothing and
11
+ * returns a Conflict; without one the last writer wins.
12
12
  *
13
13
  * 6. Two spellings of one name are one entry: a guard compares against the
14
14
  * entry under any spelling, and the result reports `null` for every other
15
15
  * spelling the commit deleted.
16
16
  *
17
- * A commit attempt that finds storage moved (files, the schema, or a request
18
- * key reserved meanwhile) is retried against a new snapshot after a jittered
17
+ * A commit attempt that finds storage moved (files or the schema) is retried against a new snapshot after a jittered
19
18
  * backoff, rechecking every guard, up to `maxCommitAttempts` times.
20
19
  */
21
- import { applyRequestDigest, canonicalJson } from "../../canonical.ts";
22
20
  import {
23
21
  type BlockViolation,
24
22
  conflict,
25
23
  invalidBlock,
26
- invalidParams,
27
24
  limitExceeded,
28
25
  readOnly,
29
26
  unavailable,
30
- unsupported,
31
27
  type VersionMismatch,
32
28
  } from "../../errors.ts";
33
29
  import {
@@ -41,11 +37,10 @@ import {
41
37
  spellingKey,
42
38
  } from "../../keys.ts";
43
39
  import { checkSecrets } from "../../secrets.ts";
44
- import type { StorageDescription, StoredReceipt } from "../../storage.ts";
45
- import type { BlocksApplyParams, BlocksApplyResult, DecoMeta, Limits } from "../../types.ts";
40
+ import type { BlocksApplyParams, BlocksApplyResult, DecoMeta } from "../../types.ts";
46
41
  import { type LoadedContent, type LoadedEntry, loadCurrentContent } from "../content.ts";
47
- import type { Core } from "../core.ts";
48
- import { parseSchema, readSchema } from "./read.ts";
42
+ import { type Core, MAX_BLOCK_BYTES, MAX_OPS_PER_APPLY } from "../core.ts";
43
+ import { parseSchema } from "./read.ts";
49
44
 
50
45
  const utf8 = new TextEncoder();
51
46
 
@@ -56,13 +51,13 @@ interface NormalizedApply {
56
51
  ifMatch: Array<[name: string, version: string | null]>;
57
52
  }
58
53
 
59
- function normalize(params: BlocksApplyParams, limits: Limits): NormalizedApply {
54
+ function normalize(params: BlocksApplyParams): NormalizedApply {
60
55
  const set = Object.entries(params.set ?? {});
61
56
  const setNames = new Set(set.map(([name]) => name));
62
57
  const deleteNames = [...new Set(params.delete ?? [])].filter((name) => !setNames.has(name));
63
58
  const ops = set.length + deleteNames.length;
64
- if (ops > limits.maxOpsPerApply) {
65
- throw limitExceeded(`${ops} names in one blocks.apply; the limit is ${limits.maxOpsPerApply}`, {
59
+ if (ops > MAX_OPS_PER_APPLY) {
60
+ throw limitExceeded(`${ops} names in one blocks.apply; the limit is ${MAX_OPS_PER_APPLY}`, {
66
61
  limit: "maxOpsPerApply",
67
62
  });
68
63
  }
@@ -70,7 +65,7 @@ function normalize(params: BlocksApplyParams, limits: Limits): NormalizedApply {
70
65
  }
71
66
 
72
67
  /** Checks everything that doesn't depend on stored content. */
73
- function validateStatic(apply: NormalizedApply, limits: Limits, meta: DecoMeta | null) {
68
+ function validateStatic(apply: NormalizedApply, meta: DecoMeta | null) {
74
69
  const violations: BlockViolation[] = [];
75
70
  const bodies = new Map<string, string>();
76
71
  const bySpelling = new Map<string, string>();
@@ -91,11 +86,11 @@ function validateStatic(apply: NormalizedApply, limits: Limits, meta: DecoMeta |
91
86
  continue;
92
87
  }
93
88
  const body = serializeBlock(value);
94
- if (utf8.encode(body).byteLength > limits.maxBlockBytes) {
89
+ if (utf8.encode(body).byteLength > MAX_BLOCK_BYTES) {
95
90
  violations.push({
96
91
  name,
97
92
  rule: "too-large",
98
- message: `the entry is over ${limits.maxBlockBytes} bytes`,
93
+ message: `the entry is over ${MAX_BLOCK_BYTES} bytes`,
99
94
  });
100
95
  continue;
101
96
  }
@@ -231,12 +226,8 @@ function resultFromVersions(
231
226
  return { revision, versions };
232
227
  }
233
228
 
234
- function receiptResult(apply: NormalizedApply, receipt: StoredReceipt): BlocksApplyResult {
235
- return resultFromVersions(apply, receipt.revision, receipt.versions, receipt.deleted ?? []);
236
- }
237
-
238
- async function loadSchema(core: Core, params: BlocksApplyParams, limits: Limits) {
239
- const stored = await readSchema(core, params.ref, limits.maxSchemaBytes);
229
+ async function loadSchema(core: Core) {
230
+ const stored = await core.storage.readSchema();
240
231
  if (stored === null) return { version: null, meta: null };
241
232
  if (core.parsedSchema?.version !== stored.version) {
242
233
  core.parsedSchema = { version: stored.version, meta: parseSchema(stored.text) };
@@ -244,67 +235,19 @@ async function loadSchema(core: Core, params: BlocksApplyParams, limits: Limits)
244
235
  return { version: stored.version, meta: core.parsedSchema.meta };
245
236
  }
246
237
 
247
- function checkFeatures(description: StorageDescription, core: Core, params: BlocksApplyParams) {
248
- if (description.readOnly) throw readOnly();
249
- core.checkRef(description, params.ref);
250
- if (params.requestKey !== undefined && (!description.idempotency || !core.storage.getReceipt)) {
251
- throw unsupported("this endpoint doesn't support request keys; omit requestKey");
252
- }
253
- }
254
-
255
238
  export async function blocksApply(
256
239
  core: Core,
257
240
  params: BlocksApplyParams,
258
- scope: string,
259
241
  ): Promise<BlocksApplyResult> {
260
242
  const description = await core.description();
261
- checkFeatures(description, core, params);
262
- if (params.requestKey === undefined) return applyOnce(core, params, description, null);
263
-
264
- const digest = await applyRequestDigest(params);
265
- const key = canonicalJson([scope, description.root, params.ref ?? null, params.requestKey]);
266
- // Simultaneous duplicates: wait for the first, then find its receipt.
267
- for (let pending = core.inflight.get(key); pending; pending = core.inflight.get(key)) {
268
- await pending.catch(() => {});
269
- }
270
- const run = applyOnce(core, params, description, { key, digest });
271
- core.inflight.set(key, run);
272
- try {
273
- return await run;
274
- } finally {
275
- if (core.inflight.get(key) === run) core.inflight.delete(key);
276
- }
277
- }
278
-
279
- async function applyOnce(
280
- core: Core,
281
- params: BlocksApplyParams,
282
- description: StorageDescription,
283
- receipt: { key: string; digest: string } | null,
284
- ): Promise<BlocksApplyResult> {
285
- const limits = core.limits(description);
286
- const apply = normalize(params, limits);
243
+ if (description.readOnly) throw readOnly();
244
+ const apply = normalize(params);
287
245
 
288
246
  for (let attempt = 1; attempt <= core.maxCommitAttempts; attempt++) {
289
- // Receipts for completed identical requests resolve before any guard is rechecked.
290
- if (receipt) {
291
- const stored = await core.storage.getReceipt!(receipt.key);
292
- if (stored) {
293
- if (stored.digest !== receipt.digest) {
294
- throw invalidParams("requestKey was already used for a different request");
295
- }
296
- return receiptResult(apply, stored);
297
- }
298
- }
299
-
300
- const schema = await loadSchema(core, params, limits);
301
- if (params.ifSchemaMatch !== undefined && params.ifSchemaMatch !== schema.version) {
302
- throw conflict({ schema: { expected: params.ifSchemaMatch, actual: schema.version } });
303
- }
304
- const { violations, bodies } = validateStatic(apply, limits, schema.meta);
305
- const { snapshot, content } = await loadCurrentContent(core.storage, params.ref, {
247
+ const schema = await loadSchema(core);
248
+ const { violations, bodies } = validateStatic(apply, schema.meta);
249
+ const { snapshot, content } = await loadCurrentContent(core.storage, {
306
250
  readAll: false,
307
- limits,
308
251
  cache: core.cache,
309
252
  });
310
253
  const bySpelling = entriesBySpelling(content!);
@@ -315,19 +258,16 @@ async function applyOnce(
315
258
  if (mismatches) throw conflict({ entries: mismatches });
316
259
 
317
260
  const { put, delete: deletes, expected } = plan(content!, bySpelling, apply, bodies);
318
- if (Object.keys(put).length === 0 && deletes.length === 0 && !receipt) {
261
+ if (Object.keys(put).length === 0 && deletes.length === 0) {
319
262
  return resultFromVersions(apply, snapshot.revision, {}, []);
320
263
  }
321
- // The schema the guards and the secret check used must still be current at commit time.
322
- const dependsOnSchema = params.ifSchemaMatch !== undefined || apply.set.length > 0;
264
+ // The schema the secret check used must still be current at commit time.
323
265
  const result = await core.storage.commit({
324
- ref: params.ref,
325
266
  base: snapshot,
326
267
  put,
327
268
  delete: deletes,
328
269
  expected,
329
- ...(dependsOnSchema ? { expectedSchemaVersion: schema.version } : {}),
330
- receipt: receipt ?? undefined,
270
+ ...(apply.set.length > 0 ? { expectedSchemaVersion: schema.version } : {}),
331
271
  });
332
272
  if (result.status === "committed") {
333
273
  return resultFromVersions(apply, result.revision, result.versions, deletes);
@@ -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, notFound, unavailable } from "../../errors.ts";
5
+ import { unavailable } from "../../errors.ts";
6
6
  import {
7
7
  ASSETS_URL_PREFIX,
8
8
  type BlocksListResult,
@@ -52,13 +52,7 @@ export async function describe(core: Core): Promise<DescribeResult> {
52
52
  readOnly,
53
53
  root: description.root,
54
54
  schemaFormat: SCHEMA_FORMAT,
55
- refs: description.refs,
56
- writes: {
57
- idempotency: core.storage.getReceipt ? description.idempotency : null,
58
- schemaPreconditions: true,
59
- },
60
55
  pollIntervalMs: core.pollIntervalMs(description),
61
- limits: core.limits(description),
62
56
  preview: core.options.preview ?? null,
63
57
  assets:
64
58
  readOnly || description.assets === null
@@ -72,20 +66,6 @@ export async function describe(core: Core): Promise<DescribeResult> {
72
66
  };
73
67
  }
74
68
 
75
- /** Reads and parses the schema, enforcing the schema byte limit. */
76
- export async function readSchema(
77
- core: Core,
78
- ref: string | undefined,
79
- maxSchemaBytes: number,
80
- ): Promise<{ version: string; resolvedRef: string | null; text: string } | null> {
81
- const stored = await core.storage.readSchema({ ref });
82
- if (stored === null) return null;
83
- if (new TextEncoder().encode(stored.text).byteLength > maxSchemaBytes) {
84
- throw limitExceeded(`the schema is over ${maxSchemaBytes} bytes`, { limit: "maxSchemaBytes" });
85
- }
86
- return stored;
87
- }
88
-
89
69
  /** Parses schema text; a file caught mid-write is reported as Unavailable, never served torn. */
90
70
  export function parseSchema(text: string): DecoMeta {
91
71
  let schema: unknown;
@@ -101,21 +81,16 @@ export function parseSchema(text: string): DecoMeta {
101
81
  }
102
82
 
103
83
  export async function schemaGet(core: Core, params: ReadParams): Promise<SchemaGetResult> {
104
- const description = await core.description();
105
- core.checkRef(description, params.ref);
106
- const limits = core.limits(description);
107
- const stored = await core.storage.readSchema({ ref: params.ref });
84
+ const stored = await core.storage.readSchema();
108
85
  if (stored === null) {
109
- throw notFound("no schema: neither .deco/schema.gen.json nor .deco/meta.gen.json exists");
86
+ // No schema yet is a state, not an error. The snapshot still refuses a
87
+ // site with no .deco folder (NotFound) and reports the resolved branch.
88
+ const snapshot = await core.storage.snapshot();
89
+ return { notModified: false, version: null, resolvedRef: snapshot.resolvedRef, schema: null };
110
90
  }
111
91
  if (params.ifNoneMatch !== undefined && params.ifNoneMatch === stored.version) {
112
92
  return { notModified: true, version: stored.version };
113
93
  }
114
- if (new TextEncoder().encode(stored.text).byteLength > limits.maxSchemaBytes) {
115
- throw limitExceeded(`the schema is over ${limits.maxSchemaBytes} bytes`, {
116
- limit: "maxSchemaBytes",
117
- });
118
- }
119
94
  return {
120
95
  notModified: false,
121
96
  version: stored.version,
@@ -125,13 +100,9 @@ export async function schemaGet(core: Core, params: ReadParams): Promise<SchemaG
125
100
  }
126
101
 
127
102
  export async function blocksList(core: Core, params: ReadParams): Promise<BlocksListResult> {
128
- const description = await core.description();
129
- core.checkRef(description, params.ref);
130
- const limits = core.limits(description);
131
103
  const { snapshot, content } = await loadCurrentContent(
132
104
  core.storage,
133
- params.ref,
134
- { readAll: true, limits, cache: core.cache },
105
+ { readAll: true, cache: core.cache },
135
106
  (s) => params.ifNoneMatch !== undefined && params.ifNoneMatch === s.revision,
136
107
  );
137
108
  if (content === null) {
@@ -4,10 +4,6 @@
4
4
  * - Every request has an `id`; one without is rejected rather than run.
5
5
  * - A batch runs in order, returns results in order, holds at most 10 calls,
6
6
  * and isn't atomic.
7
- * - The aggregate response is bounded: once it would pass
8
- * `maxBatchResponseBytes`, later reads answer LimitExceeded instead.
9
- * - A write's response is never replaced, alone or in a batch: the write has
10
- * landed, and answering LimitExceeded would tell the client it hadn't.
11
7
  */
12
8
  import {
13
9
  type ContentProtocolError,
@@ -22,8 +18,6 @@ import { type Core, toProtocolError } from "./core.ts";
22
18
  import { blocksApply } from "./methods/apply.ts";
23
19
  import { blocksList, describe, schemaGet } from "./methods/read.ts";
24
20
 
25
- const utf8 = new TextEncoder();
26
-
27
21
  type Envelope = { id: RpcId; method: MethodName; params: unknown };
28
22
 
29
23
  const isMethod = (method: string): method is MethodName =>
@@ -52,7 +46,7 @@ function parseEnvelope(
52
46
  return { id, method: raw.method, params: raw.params };
53
47
  }
54
48
 
55
- async function run(core: Core, envelope: Envelope, scope: string): Promise<unknown> {
49
+ async function run(core: Core, envelope: Envelope): Promise<unknown> {
56
50
  switch (envelope.method) {
57
51
  case "describe":
58
52
  validateParams("describe", envelope.params);
@@ -62,24 +56,18 @@ async function run(core: Core, envelope: Envelope, scope: string): Promise<unkno
62
56
  case "blocks.list":
63
57
  return blocksList(core, validateParams("blocks.list", envelope.params));
64
58
  case "blocks.apply":
65
- return blocksApply(core, validateParams("blocks.apply", envelope.params), scope);
59
+ return blocksApply(core, validateParams("blocks.apply", envelope.params));
66
60
  }
67
61
  }
68
62
 
69
- /** True for a well-formed `blocks.apply` request. */
70
- function isWrite(value: unknown): boolean {
71
- const envelope = parseEnvelope(value);
72
- return !("error" in envelope) && envelope.method === "blocks.apply";
73
- }
74
-
75
63
  const errorResponse = (id: RpcId | null, error: ContentProtocolError) =>
76
64
  JSON.stringify({ jsonrpc: "2.0", id, error: error.toJSON() });
77
65
 
78
- async function call(core: Core, value: unknown, scope: string): Promise<string> {
66
+ async function call(core: Core, value: unknown): Promise<string> {
79
67
  const envelope = parseEnvelope(value);
80
68
  if ("error" in envelope) return errorResponse(envelope.id, envelope.error);
81
69
  try {
82
- const result = await run(core, envelope, scope);
70
+ const result = await run(core, envelope);
83
71
  return JSON.stringify({ jsonrpc: "2.0", id: envelope.id, result });
84
72
  } catch (error) {
85
73
  const known = toProtocolError(error);
@@ -93,17 +81,8 @@ async function call(core: Core, value: unknown, scope: string): Promise<string>
93
81
  * Runs a parsed request body (one request object or a batch array) and
94
82
  * returns the serialized response body.
95
83
  */
96
- export async function dispatch(core: Core, body: unknown, scope: string, maxResponseBytes: number) {
97
- if (!Array.isArray(body)) {
98
- const response = await call(core, body, scope);
99
- if (isWrite(body) || utf8.encode(response).byteLength <= maxResponseBytes) return response;
100
- return errorResponse(
101
- parseEnvelope(body).id,
102
- limitExceeded(`the response is over ${maxResponseBytes} bytes`, {
103
- limit: "maxBatchResponseBytes",
104
- }),
105
- );
106
- }
84
+ export async function dispatch(core: Core, body: unknown): Promise<string> {
85
+ if (!Array.isArray(body)) return call(core, body);
107
86
  if (body.length === 0) return errorResponse(null, invalidRequest("an empty batch"));
108
87
  if (body.length > MAX_BATCH_CALLS) {
109
88
  return errorResponse(
@@ -112,25 +91,6 @@ export async function dispatch(core: Core, body: unknown, scope: string, maxResp
112
91
  );
113
92
  }
114
93
  const responses: string[] = [];
115
- let total = 2; // the brackets
116
- for (const item of body) {
117
- const envelope = parseEnvelope(item);
118
- const id = envelope.id;
119
- const overBudget = () =>
120
- errorResponse(
121
- id,
122
- limitExceeded(`the batch response is over ${maxResponseBytes} bytes`, {
123
- limit: "maxBatchResponseBytes",
124
- }),
125
- );
126
- // Writes always run, so a batch never drops a save; reads stop once over budget.
127
- const write = !("error" in envelope) && envelope.method === "blocks.apply";
128
- let response =
129
- !write && total > maxResponseBytes ? overBudget() : await call(core, item, scope);
130
- const bytes = utf8.encode(response).byteLength + (responses.length ? 1 : 0);
131
- if (total + bytes > maxResponseBytes && !write) response = overBudget();
132
- total += utf8.encode(response).byteLength + (responses.length ? 1 : 0);
133
- responses.push(response);
134
- }
94
+ for (const item of body) responses.push(await call(core, item));
135
95
  return `[${responses.join(",")}]`;
136
96
  }
@@ -35,7 +35,6 @@ import {
35
35
  type StoredFileBody,
36
36
  type StoredSchema,
37
37
  } from "../../storage.ts";
38
- import type { Limits } from "../../types.ts";
39
38
  import { gitBlobHash, revisionOf } from "./hash.ts";
40
39
  import { withCommitLock } from "./lock.ts";
41
40
  import { applyFileChange, sweepStaleTransactions } from "./transaction.ts";
@@ -57,8 +56,6 @@ export interface FsStorageOptions {
57
56
  assetsMaxBytes?: number;
58
57
  /** Overrides the poll interval (default 2000 ms). */
59
58
  pollIntervalMs?: number;
60
- /** Lowers the protocol's limits. */
61
- limits?: Partial<Limits>;
62
59
  /** How long a commit waits for another process's lock (default 10 s). */
63
60
  lockTimeoutMs?: number;
64
61
  }
@@ -227,16 +224,13 @@ export function createFsStorage(options: FsStorageOptions): FsStorage {
227
224
  kind: "working-tree",
228
225
  root: relativeRoot,
229
226
  readOnly,
230
- refs: null,
231
227
  assets: readOnly
232
228
  ? null
233
229
  : {
234
230
  dir: toPosix(relative(base, assetsDir)) || ".",
235
231
  maxBytes: options.assetsMaxBytes ?? DEFAULT_ASSETS_MAX_BYTES,
236
232
  },
237
- idempotency: null,
238
233
  pollIntervalMs: options.pollIntervalMs ?? 2000,
239
- limits: options.limits,
240
234
  };
241
235
  },
242
236
 
@@ -270,8 +264,6 @@ export function createFsStorage(options: FsStorageOptions): FsStorage {
270
264
 
271
265
  async commit(attempt): Promise<CommitResult> {
272
266
  if (readOnly) throw new StorageUnavailableError("the storage is read-only");
273
- if (attempt.receipt)
274
- throw new StorageUnavailableError("the filesystem storage keeps no receipts");
275
267
  for (const file of [
276
268
  ...Object.keys(attempt.put),
277
269
  ...attempt.delete,
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * An in-memory `ContentStorage` (internal; not a package subpath).
3
3
  *
4
- * A reference implementation of the storage contract, including durable
5
- * request-key receipts persisted atomically with each commit, and a fixture
4
+ * A reference implementation of the storage contract, and a fixture
6
5
  * for tests: its state can be dumped and restored to simulate a restart, and
7
6
  * hooks let a test change files between a snapshot and a commit. Browser-safe.
8
7
  */
@@ -18,12 +17,9 @@ import {
18
17
  StorageNotFoundError,
19
18
  type StorageSnapshot,
20
19
  type StoredFileBody,
21
- type StoredReceipt,
22
20
  type StoredSchema,
23
21
  } from "../storage.ts";
24
22
 
25
- const DAY_MS = 24 * 60 * 60 * 1000;
26
-
27
23
  /** Everything a memory storage holds; JSON-serializable, so it survives a "restart". */
28
24
  export interface MemoryStorageState {
29
25
  /** Saved-block files, by file name, with their content. */
@@ -33,7 +29,6 @@ export interface MemoryStorageState {
33
29
  /** The content of `meta.gen.json`, the fallback schema, or `null`. */
34
30
  legacySchema?: string | null;
35
31
  secretsPublicKey: string | null;
36
- receipts: Record<string, StoredReceipt & { createdAt: number }>;
37
32
  assets: Record<string, string>;
38
33
  /** `false` simulates an app root with no `.deco` folder at all. */
39
34
  hasDecoFolder: boolean;
@@ -43,8 +38,6 @@ export interface MemoryStorageOptions {
43
38
  state?: Partial<MemoryStorageState>;
44
39
  /** Overrides parts of what `describe` reports. */
45
40
  description?: Partial<StorageDescription>;
46
- /** Clock for receipt retention (default `Date.now`). */
47
- now?: () => number;
48
41
  /** Runs after each file body is read; a test can change files here, mid-read. */
49
42
  afterRead?: (file: string, storage: MemoryStorage) => void | Promise<void>;
50
43
  /** Runs before each commit attempt's checks; a test can change files here. */
@@ -65,13 +58,11 @@ export interface MemoryStorage extends ContentStorage {
65
58
  const version = (content: string) => sha256Hex(content);
66
59
 
67
60
  export function createMemoryStorage(options: MemoryStorageOptions = {}): MemoryStorage {
68
- const now = options.now ?? Date.now;
69
61
  const state: MemoryStorageState = structuredClone({
70
62
  files: {},
71
63
  schema: null,
72
64
  legacySchema: null,
73
65
  secretsPublicKey: null,
74
- receipts: {},
75
66
  assets: {},
76
67
  hasDecoFolder: true,
77
68
  ...options.state,
@@ -80,9 +71,7 @@ export function createMemoryStorage(options: MemoryStorageOptions = {}): MemoryS
80
71
  kind: "git",
81
72
  root: ".",
82
73
  readOnly: false,
83
- refs: null,
84
74
  assets: { dir: "public/assets", maxBytes: 25 * 1024 * 1024 },
85
- idempotency: { retentionMs: DAY_MS },
86
75
  ...options.description,
87
76
  };
88
77
  let commits = 0;
@@ -118,7 +107,6 @@ export function createMemoryStorage(options: MemoryStorageOptions = {}): MemoryS
118
107
  if (!isBlockFileName(file)) throw new StorageInvalidFileError(file);
119
108
  }
120
109
  if (!state.hasDecoFolder) throw new StorageNotFoundError("no .deco folder");
121
- if (attempt.receipt && state.receipts[attempt.receipt.key]) return { status: "stale" };
122
110
  if (
123
111
  attempt.expectedSchemaVersion !== undefined &&
124
112
  (await schemaVersion()) !== attempt.expectedSchemaVersion
@@ -138,15 +126,6 @@ export function createMemoryStorage(options: MemoryStorageOptions = {}): MemoryS
138
126
  for (const [file, v] of Object.entries(written)) versions.set(file, v);
139
127
  for (const file of attempt.delete) if (!(file in attempt.put)) versions.delete(file);
140
128
  const revision = await revisionOf(versions);
141
- if (attempt.receipt) {
142
- state.receipts[attempt.receipt.key] = {
143
- digest: attempt.receipt.digest,
144
- revision,
145
- versions: written,
146
- deleted: [...attempt.delete],
147
- createdAt: now(),
148
- };
149
- }
150
129
  commits++;
151
130
  return { status: "committed", revision, versions: written };
152
131
  }
@@ -201,20 +180,6 @@ export function createMemoryStorage(options: MemoryStorageOptions = {}): MemoryS
201
180
  return run;
202
181
  },
203
182
 
204
- async getReceipt(key) {
205
- const receipt = state.receipts[key];
206
- if (!receipt) return null;
207
- if (
208
- description.idempotency &&
209
- now() - receipt.createdAt > description.idempotency.retentionMs
210
- ) {
211
- delete state.receipts[key];
212
- return null;
213
- }
214
- const { createdAt: _createdAt, ...stored } = receipt;
215
- return stored;
216
- },
217
-
218
183
  async putAsset(name, body) {
219
184
  let candidate = name;
220
185
  while (candidate in state.assets) candidate = suffixedAssetName(name);