@syncular/server 0.58.0 → 0.60.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 (103) hide show
  1. package/README.md +49 -36
  2. package/dist/admin.d.ts +32 -20
  3. package/dist/admin.js +46 -40
  4. package/dist/blob-handlers.d.ts +25 -31
  5. package/dist/blob-handlers.js +63 -41
  6. package/dist/blob-store.d.ts +42 -24
  7. package/dist/blob-store.js +0 -0
  8. package/dist/bucket-blob-store.d.ts +12 -8
  9. package/dist/bucket-blob-store.js +54 -45
  10. package/dist/bucket-segment-store.js +18 -16
  11. package/dist/content-encoding.d.ts +5 -2
  12. package/dist/content-encoding.js +42 -13
  13. package/dist/context.d.ts +19 -5
  14. package/dist/context.js +19 -1
  15. package/dist/d1-storage.d.ts +14 -98
  16. package/dist/d1-storage.js +249 -1119
  17. package/dist/errors.js +16 -0
  18. package/dist/events.d.ts +36 -18
  19. package/dist/frame-bytes.js +24 -6
  20. package/dist/handler.js +503 -208
  21. package/dist/local-authority.d.ts +2 -0
  22. package/dist/local-authority.js +24 -12
  23. package/dist/object-bucket.d.ts +2 -0
  24. package/dist/operations-realtime.js +69 -50
  25. package/dist/operations.d.ts +5 -2
  26. package/dist/operations.js +20 -29
  27. package/dist/pg-executor-pglite.d.ts +5 -6
  28. package/dist/pg-executor-pglite.js +22 -14
  29. package/dist/pg-executor.d.ts +4 -1
  30. package/dist/postgres-storage.d.ts +24 -19
  31. package/dist/postgres-storage.js +420 -262
  32. package/dist/pull.d.ts +70 -47
  33. package/dist/pull.js +270 -301
  34. package/dist/push.d.ts +12 -3
  35. package/dist/push.js +361 -173
  36. package/dist/realtime.d.ts +85 -39
  37. package/dist/realtime.js +355 -219
  38. package/dist/relational-rows.d.ts +21 -66
  39. package/dist/relational-rows.js +28 -109
  40. package/dist/s3-blob-store.d.ts +11 -12
  41. package/dist/s3-blob-store.js +20 -13
  42. package/dist/s3-object-bucket.d.ts +8 -1
  43. package/dist/s3-object-bucket.js +16 -3
  44. package/dist/schema.d.ts +14 -0
  45. package/dist/schema.js +23 -0
  46. package/dist/scopes.d.ts +6 -2
  47. package/dist/scopes.js +22 -4
  48. package/dist/seed.js +10 -16
  49. package/dist/segment-download.d.ts +4 -1
  50. package/dist/segment-download.js +22 -6
  51. package/dist/signed-url.d.ts +2 -2
  52. package/dist/signed-url.js +9 -2
  53. package/dist/sigv4.d.ts +8 -2
  54. package/dist/sigv4.js +8 -4
  55. package/dist/sqlite-blob-store.d.ts +1 -1
  56. package/dist/sqlite-blob-store.js +23 -22
  57. package/dist/sqlite-dialect.d.ts +164 -84
  58. package/dist/sqlite-dialect.js +1145 -150
  59. package/dist/sqlite-lease-store.js +13 -18
  60. package/dist/sqlite-storage.d.ts +9 -62
  61. package/dist/sqlite-storage.js +303 -1123
  62. package/dist/storage-query.d.ts +30 -1
  63. package/dist/storage-query.js +68 -0
  64. package/dist/storage.d.ts +185 -63
  65. package/dist/storage.js +15 -0
  66. package/package.json +2 -2
  67. package/src/admin.ts +99 -57
  68. package/src/blob-handlers.ts +91 -72
  69. package/src/blob-store.ts +0 -0
  70. package/src/bucket-blob-store.ts +75 -48
  71. package/src/bucket-segment-store.ts +20 -15
  72. package/src/content-encoding.ts +48 -16
  73. package/src/context.ts +33 -6
  74. package/src/d1-storage.ts +350 -1700
  75. package/src/errors.ts +16 -0
  76. package/src/events.ts +37 -18
  77. package/src/frame-bytes.ts +26 -6
  78. package/src/handler.ts +654 -261
  79. package/src/local-authority.ts +27 -14
  80. package/src/object-bucket.ts +2 -0
  81. package/src/operations-realtime.ts +85 -61
  82. package/src/operations.ts +44 -42
  83. package/src/pg-executor-pglite.ts +27 -23
  84. package/src/pg-executor.ts +5 -1
  85. package/src/postgres-storage.ts +557 -354
  86. package/src/pull.ts +406 -440
  87. package/src/push.ts +466 -220
  88. package/src/realtime.ts +447 -290
  89. package/src/relational-rows.ts +43 -121
  90. package/src/s3-blob-store.ts +23 -13
  91. package/src/s3-object-bucket.ts +20 -2
  92. package/src/schema.ts +31 -0
  93. package/src/scopes.ts +23 -3
  94. package/src/seed.ts +13 -20
  95. package/src/segment-download.ts +33 -7
  96. package/src/signed-url.ts +10 -4
  97. package/src/sigv4.ts +17 -4
  98. package/src/sqlite-blob-store.ts +27 -26
  99. package/src/sqlite-dialect.ts +1851 -199
  100. package/src/sqlite-lease-store.ts +12 -23
  101. package/src/sqlite-storage.ts +390 -1821
  102. package/src/storage-query.ts +102 -0
  103. package/src/storage.ts +215 -67
@@ -29,10 +29,17 @@
29
29
  *
30
30
  * The orphan sweep is the ONLY operation that LISTs: `sweepOrphans` pages a
31
31
  * prefix listing over the `blob/` prefix (an admin/GC path, off the hot path)
32
- * to find candidates, reads each object's `createdAtMs` from its metadata for
33
- * the grace check, and DELETEs the unreferenced-and-old ones.
32
+ * to find candidates, reads each object's upload time from its metadata (or
33
+ * the backend's last-modified time for an object a presigned PUT wrote), and
34
+ * DELETEs the old ones the reference index does not name at that moment.
34
35
  */
35
- import type { BlobRecord, BlobStore, BlobStoreStats } from './blob-store';
36
+ import type {
37
+ BlobRecord,
38
+ BlobStore,
39
+ BlobStoreStats,
40
+ BlobStream,
41
+ } from './blob-store';
42
+ import type { BucketObject } from './object-bucket';
36
43
  import type { ObjectBucket } from './object-bucket';
37
44
 
38
45
  export interface BucketBlobStoreOptions {
@@ -215,41 +222,27 @@ export class BucketBlobStore implements BlobStore {
215
222
  };
216
223
  const objectKey = this.objectKeyFor(partition, blobId);
217
224
  // Idempotent re-put (same content-address ⇒ same key): count each distinct
218
- // blob once, and preserve the FIRST createdAtMs so the sweep's grace clock
219
- // is not reset by a re-upload (§5.9.2 upload age).
225
+ // blob once. A re-upload rewrites the object so its metadata carries the
226
+ // re-upload time (the sweep's grace clock, §5.9.2) and keeps a recorded
227
+ // media type.
220
228
  const preexisting = await this.#bucket.head(objectKey);
221
229
  const storedMeta = preexisting?.metadata[BLOB_META_KEY];
222
230
  const existing =
223
231
  storedMeta === undefined
224
232
  ? undefined
225
233
  : parseMetaJson(base64urlToUtf8(storedMeta), blobId, this.#label);
226
- if (
227
- existing !== undefined &&
228
- (existing.mediaType !== undefined || mediaType === undefined)
229
- ) {
230
- return {
231
- blobId,
232
- partition,
233
- byteLength: existing.byteLength,
234
- ...(existing.mediaType !== undefined
235
- ? { mediaType: existing.mediaType }
236
- : {}),
237
- createdAtMs: existing.createdAtMs,
238
- };
239
- }
240
- // A re-upload that names the media type an earlier upload left out
241
- // rewrites the object under the same precondition, keeping its age.
234
+ const storedType = existing?.mediaType ?? mediaType;
242
235
  const meta: BlobMeta = {
243
236
  byteLength: bytes.length,
244
- ...(mediaType !== undefined ? { mediaType } : {}),
245
- createdAtMs: existing?.createdAtMs ?? nowMs,
237
+ ...(storedType !== undefined ? { mediaType: storedType } : {}),
238
+ createdAtMs: Math.max(existing?.createdAtMs ?? nowMs, nowMs),
246
239
  };
247
240
  // Conditional write: of two concurrent uploads of the same blob exactly
248
- // one lands, so the first createdAtMs survives and the blob counts once.
249
- // The loser re-reads and returns the winner's record.
241
+ // one lands per pre-state and the blob counts once. The loser re-reads
242
+ // and writes over the winner.
250
243
  const written = await this.#bucket.put(objectKey, {
251
244
  body: bytes,
252
- contentType: mediaType ?? 'application/octet-stream',
245
+ contentType: storedType ?? 'application/octet-stream',
253
246
  metadata: { [BLOB_META_KEY]: utf8ToBase64url(metaToJson(meta)) },
254
247
  ...(preexisting === undefined
255
248
  ? { createOnly: true }
@@ -258,7 +251,11 @@ export class BucketBlobStore implements BlobStore {
258
251
  if (!written) return this.put(partition, blobId, bytes, nowMs, mediaType);
259
252
  if (preexisting === undefined)
260
253
  await this.#bumpStats({ count: 1, bytes: bytes.length });
261
- return { ...record, createdAtMs: meta.createdAtMs };
254
+ return {
255
+ ...record,
256
+ ...(storedType !== undefined ? { mediaType: storedType } : {}),
257
+ createdAtMs: meta.createdAtMs,
258
+ };
262
259
  }
263
260
 
264
261
  async delete(partition: string, blobId: string): Promise<void> {
@@ -275,38 +272,67 @@ export class BucketBlobStore implements BlobStore {
275
272
  partition: string,
276
273
  blobId: string,
277
274
  ): Promise<{ record: BlobRecord; bytes: Uint8Array } | undefined> {
278
- if (!BLOB_ID_PATTERN.test(blobId)) return undefined;
279
- const object = await this.#bucket.get(this.objectKeyFor(partition, blobId));
275
+ const object = await this.#object(partition, blobId);
280
276
  if (object === undefined) return undefined;
281
277
  const bytes = new Uint8Array(await object.arrayBuffer());
278
+ return {
279
+ record: this.#record(partition, blobId, object, bytes.length),
280
+ bytes,
281
+ };
282
+ }
283
+
284
+ /** The record plus the object GET's body, never buffered (see `get`). */
285
+ async open(
286
+ partition: string,
287
+ blobId: string,
288
+ ): Promise<BlobStream | undefined> {
289
+ const object = await this.#object(partition, blobId);
290
+ if (object === undefined || object.body === null) return undefined;
291
+ const record = this.#record(partition, blobId, object, object.size ?? 0);
292
+ return { record, body: object.body, byteLength: record.byteLength };
293
+ }
294
+
295
+ async #object(
296
+ partition: string,
297
+ blobId: string,
298
+ ): Promise<BucketObject | undefined> {
299
+ if (!BLOB_ID_PATTERN.test(blobId)) return undefined;
300
+ return this.#bucket.get(this.objectKeyFor(partition, blobId));
301
+ }
302
+
303
+ /** An object without Syncular metadata was written by a presigned PUT. */
304
+ #record(
305
+ partition: string,
306
+ blobId: string,
307
+ object: BucketObject,
308
+ byteLength: number,
309
+ ): BlobRecord {
282
310
  const rawMeta = object.metadata[BLOB_META_KEY];
283
311
  const meta =
284
312
  rawMeta !== undefined
285
313
  ? parseMetaJson(base64urlToUtf8(rawMeta), blobId, this.#label)
286
- : { byteLength: bytes.length, createdAtMs: 0 };
314
+ : { byteLength, createdAtMs: 0 };
287
315
  return {
288
- record: {
289
- blobId,
290
- partition,
291
- byteLength: meta.byteLength,
292
- ...(meta.mediaType !== undefined ? { mediaType: meta.mediaType } : {}),
293
- createdAtMs: meta.createdAtMs,
294
- },
295
- bytes,
316
+ blobId,
317
+ partition,
318
+ byteLength: meta.byteLength,
319
+ ...(meta.mediaType !== undefined ? { mediaType: meta.mediaType } : {}),
320
+ createdAtMs: meta.createdAtMs,
296
321
  };
297
322
  }
298
323
 
299
324
  /**
300
325
  * §5.9.2 orphan sweep — the ONLY LISTing operation. Page the `{prefix}blob/
301
- * {partition}/` prefix, HEAD each object for its `createdAtMs`, and DELETE
302
- * the ones both older than `olderThanMs` AND absent from
303
- * `referencedBlobIds`. Returns the deleted blobIds. Never deletes a
304
- * referenced blob (§5.9.2). Off the hot path — a host-scheduled GC job.
326
+ * {partition}/` prefix, HEAD each object for its upload time (the metadata
327
+ * `createdAtMs`, else the backend's last-modified time; an object with
328
+ * neither is skipped), and DELETE the ones older than `olderThanMs` that
329
+ * `isReferenced` denies right before the delete. Returns the deleted
330
+ * blobIds. Off the hot path — a host-scheduled GC job.
305
331
  */
306
332
  async sweepOrphans(
307
333
  partition: string,
308
334
  olderThanMs: number,
309
- referencedBlobIds: ReadonlySet<string>,
335
+ isReferenced: (blobId: string) => Promise<boolean>,
310
336
  ): Promise<string[]> {
311
337
  const listPrefix = `${this.#prefix}blob/${partition}/`;
312
338
  const swept: string[] = [];
@@ -321,18 +347,19 @@ export class BucketBlobStore implements BlobStore {
321
347
  if (!rest.startsWith('sha256/')) continue;
322
348
  const blobId = `sha256:${rest.slice('sha256/'.length)}`;
323
349
  if (!BLOB_ID_PATTERN.test(blobId)) continue;
324
- if (referencedBlobIds.has(blobId)) continue;
325
350
  const head = await this.#bucket.head(key);
326
351
  if (head === undefined) continue;
327
352
  const rawMeta = head.metadata[BLOB_META_KEY];
328
- const meta =
353
+ const uploadedAtMs =
329
354
  rawMeta !== undefined
330
355
  ? parseMetaJson(base64urlToUtf8(rawMeta), blobId, this.#label)
331
- : { byteLength: head.size ?? 0, createdAtMs: 0 };
332
- if (meta.createdAtMs >= olderThanMs) continue;
356
+ .createdAtMs
357
+ : head.lastModifiedMs;
358
+ if (uploadedAtMs === undefined || uploadedAtMs >= olderThanMs) continue;
359
+ if (await isReferenced(blobId)) continue;
333
360
  await this.#bucket.delete(key);
334
361
  swept.push(blobId);
335
- deletedBytes += meta.byteLength;
362
+ deletedBytes += head.size ?? 0;
336
363
  }
337
364
  } while (cursor !== undefined);
338
365
  if (swept.length > 0) {
@@ -58,7 +58,6 @@ import {
58
58
  mergeSegmentRecord,
59
59
  publicationRecord,
60
60
  publicationsForRecord,
61
- segmentBytesEqual,
62
61
  segmentIdFor,
63
62
  selectSegmentPublication,
64
63
  } from './segment-store';
@@ -440,23 +439,29 @@ export class BucketSegmentStore implements SegmentStore {
440
439
  }
441
440
 
442
441
  /**
443
- * Write the immutable bytes object. Create-only, so a second publisher of
444
- * identical bytes is a no-op and a second publisher of DIFFERENT bytes under
445
- * the same content address is the hash collision §5.1 requires to fail
446
- * loudly instead of overwriting.
442
+ * Write the immutable bytes object unless it is stored already. A HEAD
443
+ * comes first, so republishing a segment (every bootstrap pull of an
444
+ * unchanged window) moves no bytes. The write is create-only, so two first
445
+ * publishers cannot overwrite each other. A stored object under the same
446
+ * content address with a different size is the hash collision §5.1
447
+ * requires to fail loudly; equal size under one SHA-256 address is the same
448
+ * content.
447
449
  */
448
450
  async #putBytes(segmentId: string, bytes: Uint8Array): Promise<void> {
449
451
  const key = this.objectKeyFor(segmentId);
450
- const written = await this.#bucket.put(key, {
451
- body: bytes,
452
- contentType: 'application/octet-stream',
453
- createOnly: true,
454
- });
455
- if (written) return;
456
- const current = await this.#bucket.get(key);
457
- if (current === undefined) return;
458
- const stored = new Uint8Array(await current.arrayBuffer());
459
- if (!segmentBytesEqual(stored, bytes)) {
452
+ const head = await this.#bucket.head(key);
453
+ if (
454
+ head === undefined &&
455
+ (await this.#bucket.put(key, {
456
+ body: bytes,
457
+ contentType: 'application/octet-stream',
458
+ createOnly: true,
459
+ }))
460
+ ) {
461
+ return;
462
+ }
463
+ const stored = head ?? (await this.#bucket.head(key));
464
+ if (stored !== undefined && stored.size !== bytes.length) {
460
465
  throw new Error(
461
466
  `${this.#label}: content-address collision at ${segmentId} (§5.1)`,
462
467
  );
@@ -1,7 +1,7 @@
1
1
  /**
2
- * §1.3 transport compression for every buffered HTTP body the adapters
3
- * serve — `<mount>/sync`, `<mount>/operations`, blob GETs and segment
4
- * downloads: negotiate `Content-Encoding` from the request's
2
+ * §1.3 transport compression for the HTTP bodies the adapters serve —
3
+ * `<mount>/sync`, `<mount>/operations` and segment downloads (blob downloads
4
+ * stream identity, §5.9.5): negotiate `Content-Encoding` from the request's
5
5
  * `Accept-Encoding` (zstd preferred, gzip fallback, identity when the client
6
6
  * offers neither), feature-detecting the runtime's codecs, zero
7
7
  * dependencies. Bun supplies zstd + gzip natively; every other runtime
@@ -167,31 +167,63 @@ export function encodeStream(
167
167
  * `Content-Encoding: gzip` (§1.3: clients MAY compress a request body and
168
168
  * servers MUST accept it). Returns `undefined` for any other declared
169
169
  * encoding — the adapter answers 415 rather than parse bytes it cannot read.
170
- * A gzip body that does not decompress is a `sync.invalid_request`.
170
+ * A gzip body that does not decompress is a `sync.invalid_request`. One read
171
+ * loop counts the decoded bytes of identity and gzip bodies alike and stops
172
+ * with `sync.limit_exceeded` past `maxBytes` (§1.7 `maxRequestBytes`), so a
173
+ * small compressed body never inflates past the cap.
171
174
  */
172
175
  export async function decodeRequestBody(
173
176
  request: Request,
177
+ maxBytes: number,
174
178
  ): Promise<Uint8Array | undefined> {
175
179
  const encoding = request.headers
176
180
  .get('content-encoding')
177
181
  ?.trim()
178
182
  .toLowerCase();
179
- if (encoding === undefined || encoding === '' || encoding === 'identity') {
180
- return new Uint8Array(await request.arrayBuffer());
181
- }
182
- if (encoding !== 'gzip' || typeof DecompressionStream !== 'function') {
183
+ const identity =
184
+ encoding === undefined || encoding === '' || encoding === 'identity';
185
+ if (
186
+ !identity &&
187
+ (encoding !== 'gzip' || typeof DecompressionStream !== 'function')
188
+ ) {
183
189
  return undefined;
184
190
  }
185
191
  if (request.body === null) {
192
+ if (identity) return new Uint8Array(0);
186
193
  throw syncError('sync.invalid_request', 'malformed gzip request body');
187
194
  }
188
- try {
189
- return new Uint8Array(
190
- await new Response(
191
- request.body.pipeThrough(new DecompressionStream('gzip')),
192
- ).arrayBuffer(),
193
- );
194
- } catch {
195
- throw syncError('sync.invalid_request', 'malformed gzip request body');
195
+ const reader = (
196
+ identity
197
+ ? request.body
198
+ : request.body.pipeThrough(new DecompressionStream('gzip'))
199
+ ).getReader();
200
+ const chunks: Uint8Array[] = [];
201
+ let total = 0;
202
+ for (;;) {
203
+ let step: Awaited<ReturnType<typeof reader.read>>;
204
+ try {
205
+ step = await reader.read();
206
+ } catch (error) {
207
+ if (identity) throw error;
208
+ throw syncError('sync.invalid_request', 'malformed gzip request body');
209
+ }
210
+ if (step.done) break;
211
+ total += step.value.length;
212
+ if (total > maxBytes) {
213
+ await reader.cancel().catch(() => {});
214
+ throw syncError(
215
+ 'sync.limit_exceeded',
216
+ 'request body exceeds the server limit (§1.7)',
217
+ JSON.stringify({ limit: 'maxRequestBytes', max: maxBytes }),
218
+ );
219
+ }
220
+ chunks.push(step.value);
221
+ }
222
+ const bytes = new Uint8Array(total);
223
+ let offset = 0;
224
+ for (const chunk of chunks) {
225
+ bytes.set(chunk, offset);
226
+ offset += chunk.length;
196
227
  }
228
+ return bytes;
197
229
  }
package/src/context.ts CHANGED
@@ -58,7 +58,7 @@ export type ResolverOutage = typeof RESOLVER_OUTAGE;
58
58
  /**
59
59
  * Host callback: actor → allowed scopes (§3.2 step 3). Resolved at most
60
60
  * once per request and memoized (§3.4 step 1). `'*'` means "any value for
61
- * this variable". A throwing resolver revokes subscriptions and rejects
61
+ * this variable". A throwing resolver revokes units and rejects
62
62
  * writes with `sync.forbidden` — fail loud, never leak. Returning
63
63
  * `RESOLVER_OUTAGE` instead opts the request into lease authorization
64
64
  * (§7.3.3) — a deliberate outage signal, not a failure.
@@ -82,22 +82,37 @@ export interface ServerLimits {
82
82
  readonly inlineSegmentMaxBytes: number;
83
83
  /** §6.11 declared-reference cascade cap per commit (reference default). */
84
84
  readonly maxCascadeOperationsPerCommit: number;
85
+ /**
86
+ * §1.7 cap on a request body's decoded bytes: an HTTP body after gzip
87
+ * decoding, and a socket round's assembled request (§8.7).
88
+ */
89
+ readonly maxRequestBytes: number;
90
+ /** §1.7 cap on `UNIT` frames per request: the units of a traveling list. */
91
+ readonly maxSubscriptionsPerRequest: number;
92
+ /** Cap on concurrent registered-query watches per watch session. */
93
+ readonly maxWatchesPerSession: number;
85
94
  }
86
95
 
87
96
  export const DEFAULT_LIMITS: ServerLimits = {
88
97
  maxOperationsPerRequest: 500,
89
98
  inlineSegmentMaxBytes: 256 * 1024,
90
99
  maxCascadeOperationsPerCommit: 1_000,
100
+ // The size above which adapters already refuse to buffer a segment body.
101
+ maxRequestBytes: 16 * 1024 * 1024,
102
+ // One unit per pushable operation: the existing per-request cap.
103
+ maxSubscriptionsPerRequest: 500,
104
+ // Every commit reruns a session's affected watches one after another.
105
+ maxWatchesPerSession: 100,
91
106
  };
92
107
 
93
108
  /** Receives applied commits for realtime fanout (§8.2). */
94
109
  export interface RealtimeNotifier {
95
110
  notifyCommit(partition: string, commit: StoredCommit): void | Promise<void>;
96
111
  /**
97
- * A pull changed the client's persisted subscription list (§8.7). A hub
98
- * re-registers that client's live sockets, so a client that runs its
99
- * rounds over HTTP while a socket is open receives deltas for the new
100
- * subscriptions.
112
+ * A pull changed the client's registration list or live set (§8.1). A
113
+ * hub re-registers that client's live sockets, so a client that runs its
114
+ * rounds over HTTP while a socket is open receives deltas for the units
115
+ * that joined.
101
116
  */
102
117
  notifySubscriptions?(
103
118
  partition: string,
@@ -235,8 +250,20 @@ export function clockOf(ctx: SyncServerConfig): () => number {
235
250
  return ctx.clock ?? Date.now;
236
251
  }
237
252
 
253
+ /**
254
+ * The configured limits over the defaults. A cap that is not a positive safe
255
+ * integer (`NaN`, `0`, `Infinity`) would disable or jam it, so it throws;
256
+ * `inlineSegmentMaxBytes` is a threshold and may be `0` (inline nothing).
257
+ */
238
258
  export function limitsOf(ctx: SyncServerConfig): ServerLimits {
239
- return { ...DEFAULT_LIMITS, ...ctx.limits };
259
+ const limits: ServerLimits = { ...DEFAULT_LIMITS, ...ctx.limits };
260
+ for (const [name, value] of Object.entries(limits)) {
261
+ const min = name === 'inlineSegmentMaxBytes' ? 0 : 1;
262
+ if (!Number.isSafeInteger(value) || value < min) {
263
+ throw new Error(`ServerLimits.${name} is out of range`);
264
+ }
265
+ }
266
+ return limits;
240
267
  }
241
268
 
242
269
  /** Refresh the registry after host authentication and return log continuity. */