@syncular/server-hono 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.
- package/dist/admin-page.js +32 -34
- package/dist/admin.js +12 -0
- package/dist/index.js +21 -19
- package/package.json +3 -3
- package/src/admin-page.ts +32 -34
- package/src/admin.ts +14 -0
- package/src/index.ts +22 -21
package/dist/admin-page.js
CHANGED
|
@@ -357,7 +357,7 @@ main{overflow:visible;padding:16px}
|
|
|
357
357
|
</section>
|
|
358
358
|
|
|
359
359
|
<section id="view-people" class="view" aria-labelledby="h-people" hidden>
|
|
360
|
-
<div class="vh"><p class="kicker">02 · People</p><h1 id="h-people">People and devices<span class="dot">.</span></h1><p class="lede">Every actor in this partition with the devices it syncs from. An actor opens its failed and warned requests; a device opens its client page:
|
|
360
|
+
<div class="vh"><p class="kicker">02 · People</p><h1 id="h-people">People and devices<span class="dot">.</span></h1><p class="lede">Every actor in this partition with the devices it syncs from. An actor opens its failed and warned requests; a device opens its client page: units, lease, failures, recent events, and a delivery trace.</p></div>
|
|
361
361
|
<div id="people-rt"></div>
|
|
362
362
|
<div class="cols"><div class="panel"><div class="ph"><h2>Schema rollout</h2><span class="meta" id="rollout-meta"></span></div><div class="pb" id="people-rollout" data-skel></div></div></div>
|
|
363
363
|
<div class="panel">
|
|
@@ -658,7 +658,7 @@ main{overflow:visible;padding:16px}
|
|
|
658
658
|
if (t === 'push.conflicted' || t === 'reaction.retried' || t === 'lease.revoked' ||
|
|
659
659
|
(t === 'request.handled' && (e.outcome === 'reset' || e.outcome === 'schema_floor')) ||
|
|
660
660
|
(t === 'realtime.wake' && e.reason === 'delta-too-large') ||
|
|
661
|
-
(t === 'pull.served' && e.
|
|
661
|
+
(t === 'pull.served' && (e.live.status !== 'active' || e.units.some(u => u.status !== 'active')))) return 'warn';
|
|
662
662
|
return 'info';
|
|
663
663
|
}
|
|
664
664
|
var RANK = { err: 0, warn: 1, info: 2 }, LEVEL_LABEL = { err: 'error', warn: 'warn', info: 'info' };
|
|
@@ -668,12 +668,12 @@ main{overflow:visible;padding:16px}
|
|
|
668
668
|
function summary(e) {
|
|
669
669
|
if (e.type === 'request.handled') {
|
|
670
670
|
return e.outcome + (e.errorCode ? ' ' + e.errorCode : '') + ' · ' + dur(e.durationMs) + ' ms · ' + e.pushCommits +
|
|
671
|
-
' pushed · ' + (e.pulled ? 'pulled ' + e.
|
|
671
|
+
' pushed · ' + (e.pulled ? 'pulled ' + e.units + ' units' : 'no pull') + ' · ' + bytes(e.bytesIn) + ' in, ' + bytes(e.bytesOut) + ' out';
|
|
672
672
|
}
|
|
673
673
|
if (e.type === 'pull.served') {
|
|
674
|
-
var modes = {}
|
|
675
|
-
e.
|
|
676
|
-
return Object.keys(modes).map(k => modes[k] + ' ' + k).join(', ') + ' · ' + commits + ' commits · through ' + e.
|
|
674
|
+
var modes = {};
|
|
675
|
+
e.units.forEach(u => { var k = u.status === 'active' ? u.mode : u.status; modes[k] = (modes[k] || 0) + 1; });
|
|
676
|
+
return Object.keys(modes).map(k => modes[k] + ' ' + k).concat(['live ' + e.live.status]).join(', ') + ' · ' + e.live.commits + ' commits · through ' + e.live.throughSeq;
|
|
677
677
|
}
|
|
678
678
|
return (e.table && e.rowId ? e.table + ' / ' + e.rowId + ' · ' : '') + SUMMARY_KEYS.filter(k => e[k] !== undefined).map(k => {
|
|
679
679
|
return k + ' ' + (typeof e[k] === 'string' ? e[k] : JSON.stringify(e[k]));
|
|
@@ -1002,13 +1002,13 @@ main{overflow:visible;padding:16px}
|
|
|
1002
1002
|
'<select class="inp" name="t" aria-label="Table">' + INFO.tables.map(t => '<option>' + esc(t.name) + '</option>').join('') + '</select>' +
|
|
1003
1003
|
'<input class="inp grow" name="r" placeholder="Row id" aria-label="Row id" spellcheck="false" /><button class="btn amber" type="submit">Trace</button></div></form></div></div>' +
|
|
1004
1004
|
'<div class="panel"><div class="ph"><h2>Failures and warnings</h2><span class="meta" id="client-fail-meta"></span></div><div id="client-fail"></div></div>' +
|
|
1005
|
-
'<div class="panel"><div class="ph"><h2>
|
|
1005
|
+
'<div class="panel"><div class="ph"><h2>Units</h2><span class="meta">' + c.units.length + '</span></div><div id="client-units"></div></div>' +
|
|
1006
1006
|
'<div class="panel"><div class="ph"><h2>Recent events</h2><span class="meta">' + d.events.length + '</span></div><div id="client-events"></div></div>');
|
|
1007
|
-
table('client-
|
|
1008
|
-
{ l: 'Id', c: 'w-sm', h:
|
|
1009
|
-
{ l: '
|
|
1010
|
-
{ l: '
|
|
1011
|
-
], c.
|
|
1007
|
+
table('client-units', [
|
|
1008
|
+
{ l: 'Id', c: 'w-sm', h: u => idCell(u.id) },
|
|
1009
|
+
{ l: 'Scopes', h: u => tags(Object.keys(u.scopes).map(k => k + ': ' + u.scopes[k])) },
|
|
1010
|
+
{ l: 'State', c: 'fill', h: u => u.catchingUpCursor === undefined ? st('ok', 'live') : st('warn', 'catching up') + ' <span class="dim">at ' + fmt(u.catchingUpCursor) + '</span>' }
|
|
1011
|
+
], c.units, empty('No units', 'The client record stores no registration list.', true));
|
|
1012
1012
|
table('client-events', EV_COLS, d.events, empty('No events', 'The ring holds no events for this client.', true), openEvent);
|
|
1013
1013
|
return loadFailures('client-fail', { clientId: id });
|
|
1014
1014
|
}, fail(['client-body']));
|
|
@@ -1036,11 +1036,9 @@ main{overflow:visible;padding:16px}
|
|
|
1036
1036
|
$('table-activity-panel').hidden = !sv;
|
|
1037
1037
|
var jobs = [(S.clients ? Promise.resolve() : loadClients()).then(() => get('/rows/' + enc(t), { limit: PAGE_ROWS, afterRowId: after, scope: scope })).then(r => {
|
|
1038
1038
|
var p = r.page, cols = schema ? schema.columns.filter(c => !c.primaryKey).slice(0, 4) : [];
|
|
1039
|
-
var seen = {}, chips = [];
|
|
1040
|
-
(
|
|
1041
|
-
|
|
1042
|
-
}));
|
|
1043
|
-
p.rows.forEach(row => Object.keys(row.scopes || {}).forEach(k => { seen[k + ':' + row.scopes[k]] = 1; }));
|
|
1039
|
+
var seen = {}, keys = {}, chips = [];
|
|
1040
|
+
p.rows.forEach(row => Object.keys(row.scopes || {}).forEach(k => { keys[k] = 1; seen[k + ':' + row.scopes[k]] = 1; }));
|
|
1041
|
+
(S.clients || []).forEach(c => c.units.forEach(u => Object.keys(u.scopes).forEach(k => { if (keys[k]) seen[k + ':' + u.scopes[k]] = 1; })));
|
|
1044
1042
|
chips = Object.keys(seen).sort().slice(0, 30);
|
|
1045
1043
|
html('table-scopes', 'Scope ' + link(route('table', [t]), 'all rows', 'tag' + (scope ? '' : ' on')) +
|
|
1046
1044
|
chips.map(k => link(route('table', [t, k]), k.replace(':', ': '), 'tag' + (k === scope ? ' on' : ''))).join(''));
|
|
@@ -1073,15 +1071,15 @@ main{overflow:visible;padding:16px}
|
|
|
1073
1071
|
}
|
|
1074
1072
|
var VERDICT = {
|
|
1075
1073
|
delivered: ['ok', 'Delivered', 'The client has pulled the row\\'s last change.'],
|
|
1076
|
-
'pending-pull': ['warn', 'Pending pull', 'A
|
|
1074
|
+
'pending-pull': ['warn', 'Pending pull', 'A unit covers the row, and the client\\'s cursor is behind the row\\'s last change. The next pull delivers it.'],
|
|
1077
1075
|
'row-deleted': ['warn', 'Row deleted', 'The row\\'s last change is a delete. A client that held the row drops it on its next pull.'],
|
|
1078
|
-
'scope-mismatch': ['err', 'Scope mismatch', '
|
|
1079
|
-
'scope-denied': ['err', 'Scope denied', 'A
|
|
1080
|
-
'no-
|
|
1076
|
+
'scope-mismatch': ['err', 'Scope mismatch', 'A unit of the client covers the table, but none carries the row\\'s scope values.'],
|
|
1077
|
+
'scope-denied': ['err', 'Scope denied', 'A unit carries the row\\'s scopes, but the actor\\'s allowed scopes from resolveScopes exclude them, so the server never delivers the row.'],
|
|
1078
|
+
'no-unit': ['idle', 'No unit', 'No unit of the client covers this table.'],
|
|
1081
1079
|
'client-unknown': ['err', 'Client unknown', 'This partition has no cursor record for the client.'],
|
|
1082
1080
|
'row-missing': ['err', 'Row missing', 'The partition holds no row with this id in this table.']
|
|
1083
1081
|
};
|
|
1084
|
-
var VORDER = ['row-missing', 'client-unknown', 'no-
|
|
1082
|
+
var VORDER = ['row-missing', 'client-unknown', 'no-unit', 'scope-denied', 'scope-mismatch', 'row-deleted', 'pending-pull', 'delivered'];
|
|
1085
1083
|
function verdictOf(v) { return VERDICT[v] || ['err', v, 'The console does not know this verdict.']; }
|
|
1086
1084
|
var HISTORY_COLS = [
|
|
1087
1085
|
{ l: 'Seq', c: 'num', d: -1, v: x => x.commitSeq, h: x => '<span class="ty">' + fmt(x.commitSeq) + '</span>' },
|
|
@@ -1137,14 +1135,14 @@ main{overflow:visible;padding:16px}
|
|
|
1137
1135
|
['Last change', lc ? seqBtn(lc.commitSeq) + ' ' + esc(lc.op) + ' by ' + esc(lc.actorId) + ' ' + ago(lc.createdAtMs) : '<span class="dim">none retained; horizon ' + fmt(x.horizonSeq) + '</span>'],
|
|
1138
1136
|
['Client', c ? clientLink(client) + ' · cursor ' + fmt(c.cursor) + ' · ' + presence(c) : st('err', 'unknown')],
|
|
1139
1137
|
['Allowed', x.allowed === undefined ? '<span class="dim">no resolver</span>' : x.allowed === 'outage' ? st('err', 'resolveScopes outage') : scopeTags(x.allowed)]]) +
|
|
1140
|
-
'<h3>
|
|
1141
|
-
table('m-
|
|
1142
|
-
{ l: 'Id', c: 'w-sm', h:
|
|
1143
|
-
{ l: '
|
|
1144
|
-
{ l: 'Requested', h:
|
|
1145
|
-
{ l: 'Allowed', h:
|
|
1146
|
-
{ l: 'Mismatches', c: 'fill', h:
|
|
1147
|
-
], x.
|
|
1138
|
+
'<h3>Units covering ' + esc(t) + ' · ' + x.units.length + '</h3><div id="m-units"></div><h3>Rejected pushes · ' + x.rejections.length + '</h3><div id="m-events"></div>', x);
|
|
1139
|
+
table('m-units', [
|
|
1140
|
+
{ l: 'Id', c: 'w-sm', h: u => idCell(u.id) },
|
|
1141
|
+
{ l: 'Scopes', h: u => tags(Object.keys(u.scopes).map(k => k + ': ' + u.scopes[k])) },
|
|
1142
|
+
{ l: 'Requested', h: u => u.requestedMatch ? st('ok', 'covers row') : st('err', 'mismatch') },
|
|
1143
|
+
{ l: 'Allowed', h: u => u.effectiveMatch === undefined ? '<span class="dim">not checked</span>' : u.effectiveMatch ? st('ok', 'covers row') : st('err', 'denied') },
|
|
1144
|
+
{ l: 'Mismatches', c: 'fill', h: u => u.mismatches.length ? tags(u.mismatches.map(m => m.variable + ': row ' + m.rowValue + ', requested ' + m.requested)) : '<span class="dim">none</span>' }
|
|
1145
|
+
], x.units, empty('No units', 'No unit of the client covers ' + esc(t) + '.', true));
|
|
1148
1146
|
table('m-events', EV_COLS, x.rejections, empty('No rejections', 'The ring holds no rejected or conflicted push for this row.', true), openEvent);
|
|
1149
1147
|
}, err => { if (token === modalToken && err !== STALE) fillModal(errBox(err), { code: err.code, message: err.message }); });
|
|
1150
1148
|
}
|
|
@@ -1182,7 +1180,7 @@ main{overflow:visible;padding:16px}
|
|
|
1182
1180
|
get('/writes/' + enc(id)).then(r => {
|
|
1183
1181
|
if (token !== modalToken) return;
|
|
1184
1182
|
var w = r.write;
|
|
1185
|
-
fillModal((w.outcomes.length ? '' : empty('No recorded outcome', 'No client has a stored outcome for this client commit id. The server never received it
|
|
1183
|
+
fillModal((w.outcomes.length ? '' : w.watermarks.length ? w.watermarks.map(m => '<h3>' + st('idle', 'expired') + ' · client ' + clientLink(m.clientId) + ' · outbox ' + idText(m.outboxId) + '</h3><p class="verdict">The outbox watermark deleted its result: expired below sequence ' + fmt(m.throughSeq) + '.</p>').join('') : empty('No recorded outcome', 'No client has a stored outcome for this client commit id, and no outbox watermark covers it. The server never received it.', true)) +
|
|
1186
1184
|
w.outcomes.map((o, i) => '<h3>' + (o.status === 'applied' ? st('ok', 'applied') : st('err', 'rejected')) + ' · client ' + clientLink(o.clientId) +
|
|
1187
1185
|
(o.commitSeq !== undefined ? ' · commit ' + seqBtn(o.commitSeq) : '') + (o.recordedAtMs ? ' · ' + ago(o.recordedAtMs) : '') + '</h3><div id="m-res-' + i + '"></div>').join('') +
|
|
1188
1186
|
'<h3>Ring events · ' + w.events.length + '</h3><div id="m-events"></div>', w);
|
|
@@ -1295,7 +1293,7 @@ main{overflow:visible;padding:16px}
|
|
|
1295
1293
|
{ l: 'Detail', c: 'fill', ns: true, h: detailCell }
|
|
1296
1294
|
];
|
|
1297
1295
|
// One row per sync request: every event of a request shares requestId.
|
|
1298
|
-
// An idle round pushed nothing and pulled no commit
|
|
1296
|
+
// An idle round pushed nothing and pulled no commit.
|
|
1299
1297
|
function groups(list) {
|
|
1300
1298
|
var by = {}, out = [];
|
|
1301
1299
|
list.forEach(e => {
|
|
@@ -1309,14 +1307,14 @@ main{overflow:visible;padding:16px}
|
|
|
1309
1307
|
g.level = g.events.reduce((l, e) => RANK[level(e)] < RANK[l] ? level(e) : l, 'info');
|
|
1310
1308
|
g.clientId = g.events.map(e => e.clientId).filter(Boolean)[0];
|
|
1311
1309
|
g.actorId = g.events.map(e => e.actorId).filter(Boolean)[0];
|
|
1312
|
-
g.idle = !!g.rh && g.level === 'info' && g.rh.pushCommits === 0 && g.events.every(e => e.type !== 'pull.served' || e.
|
|
1310
|
+
g.idle = !!g.rh && g.level === 'info' && g.rh.pushCommits === 0 && g.events.every(e => e.type !== 'pull.served' || !e.live.commits);
|
|
1313
1311
|
});
|
|
1314
1312
|
return out;
|
|
1315
1313
|
}
|
|
1316
1314
|
function groupSummary(g) {
|
|
1317
1315
|
if (!g.id) return summary(g.events[0]);
|
|
1318
1316
|
var pulled = 0, rh = g.rh;
|
|
1319
|
-
g.events.forEach(e => { if (e.type === 'pull.served')
|
|
1317
|
+
g.events.forEach(e => { if (e.type === 'pull.served') pulled += e.live.commits; });
|
|
1320
1318
|
var bad = g.events.filter(e => e.type === 'push.rejected' || e.type === 'push.conflicted');
|
|
1321
1319
|
return (rh ? rh.outcome + (rh.errorCode ? ' ' + rh.errorCode : '') + ' · ' + dur(rh.durationMs) + ' ms · ' + rh.pushCommits + ' pushed · ' : 'in flight · ') +
|
|
1322
1320
|
pulled + ' commits pulled' + (bad.length ? ' · ' + bad.map(e => e.type.slice(5) + (e.table ? ' ' + e.table + ' / ' + e.rowId : '')).join(', ') : '') + ' · ' + g.events.length + ' events';
|
package/dist/admin.js
CHANGED
|
@@ -44,6 +44,18 @@ export function createSyncularAdminRoutes(admin, options) {
|
|
|
44
44
|
app.onError((error) => jsonError(error));
|
|
45
45
|
/** Run the host guards; actions also need `authorizeActions`. */
|
|
46
46
|
async function guard(request, partition) {
|
|
47
|
+
// A cookie-authenticated operator's browser must not run an action for
|
|
48
|
+
// another site. The origin check compares hosts, so a proxy that ends TLS
|
|
49
|
+
// in front of the server still passes it.
|
|
50
|
+
if (request.method === 'POST') {
|
|
51
|
+
const site = request.headers.get('sec-fetch-site');
|
|
52
|
+
const origin = request.headers.get('origin');
|
|
53
|
+
if ((site !== null && site !== 'same-origin' && site !== 'none') ||
|
|
54
|
+
(origin !== null &&
|
|
55
|
+
URL.parse(origin)?.host !== new URL(request.url).host)) {
|
|
56
|
+
throw new SyncError('sync.forbidden', 'cross-site admin request');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
47
59
|
const context = { partition, request };
|
|
48
60
|
if (!(await options.authorize(context))) {
|
|
49
61
|
throw new SyncError('sync.auth_required');
|
package/dist/index.js
CHANGED
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
* Mounts the §1.1 routes including sync, registered operations, segments, and
|
|
5
5
|
* blobs. Realtime upgrades are runtime-specific and stay with the host.
|
|
6
6
|
*/
|
|
7
|
-
import { adapterSyncError, composeEvents, decodeRequestBody, encodeBody, encodeStream, errorBody, handleBlobDownload, handleBlobUpload, handleBlobUploadGrant, openSegmentDownload, handleRemoteOperation, handleSyncRequest, RealtimeHub, RingBufferEvents, SEGMENT_STREAM_THRESHOLD_BYTES, SSP2_CONTENT_TYPE, SyncError, SyncularAdmin, varyOnAcceptEncoding, } from '@syncular/server';
|
|
7
|
+
import { adapterSyncError, composeEvents, decodeRequestBody, encodeBody, encodeStream, errorBody, handleBlobDownload, handleBlobUpload, handleBlobUploadGrant, openSegmentDownload, handleRemoteOperation, handleSyncRequest, limitsOf, RealtimeHub, RingBufferEvents, SEGMENT_STREAM_THRESHOLD_BYTES, SSP2_CONTENT_TYPE, SyncError, SyncularAdmin, varyOnAcceptEncoding, } from '@syncular/server';
|
|
8
8
|
import { Hono } from 'hono';
|
|
9
9
|
import { createSyncularAdminRoutes } from './admin.js';
|
|
10
10
|
export * from './admin.js';
|
|
11
11
|
export function createSyncularHono(options) {
|
|
12
12
|
const app = new Hono();
|
|
13
13
|
let config = options.config;
|
|
14
|
+
// Validates every configured limit once, at creation.
|
|
15
|
+
const { maxRequestBytes } = limitsOf(config);
|
|
14
16
|
const admin = options.admin;
|
|
15
17
|
if (admin !== undefined) {
|
|
16
18
|
const ring = new RingBufferEvents(admin.ringCapacity !== undefined
|
|
@@ -46,7 +48,7 @@ export function createSyncularHono(options) {
|
|
|
46
48
|
const unsupportedEncoding = (c, route) => c.json(errorBody(new SyncError(route === 'sync'
|
|
47
49
|
? 'sync.invalid_request'
|
|
48
50
|
: 'operation.invalid_request', 'unsupported content encoding')), 415);
|
|
49
|
-
// §1.3: every buffered body — a sync round, an operation result, a
|
|
51
|
+
// §1.3: every buffered body — a sync round, an operation result, a
|
|
50
52
|
// segment — is encoded per the request's `Accept-Encoding` (zstd preferred,
|
|
51
53
|
// gzip fallback, identity otherwise) and carries `Vary: Accept-Encoding`.
|
|
52
54
|
// Headers are built through the Hono context so host middleware headers
|
|
@@ -84,7 +86,7 @@ export function createSyncularHono(options) {
|
|
|
84
86
|
if (auth === null)
|
|
85
87
|
return errorResponse(c, new SyncError('sync.auth_required'));
|
|
86
88
|
try {
|
|
87
|
-
const bytes = await decodeRequestBody(c.req.raw);
|
|
89
|
+
const bytes = await decodeRequestBody(c.req.raw, maxRequestBytes);
|
|
88
90
|
if (bytes === undefined)
|
|
89
91
|
return unsupportedEncoding(c, 'sync');
|
|
90
92
|
const out = await handleSyncRequest(bytes, {
|
|
@@ -111,7 +113,7 @@ export function createSyncularHono(options) {
|
|
|
111
113
|
if (auth === null)
|
|
112
114
|
return errorResponse(c, new SyncError('sync.auth_required'));
|
|
113
115
|
try {
|
|
114
|
-
const bytes = await decodeRequestBody(c.req.raw);
|
|
116
|
+
const bytes = await decodeRequestBody(c.req.raw, maxRequestBytes);
|
|
115
117
|
if (bytes === undefined)
|
|
116
118
|
return unsupportedEncoding(c, 'operations');
|
|
117
119
|
const out = await handleRemoteOperation(bytes, { ...config, ...auth }, options.operations);
|
|
@@ -169,16 +171,7 @@ export function createSyncularHono(options) {
|
|
|
169
171
|
if (auth === null)
|
|
170
172
|
return errorResponse(c, new SyncError('sync.auth_required'));
|
|
171
173
|
try {
|
|
172
|
-
|
|
173
|
-
const contentType = c.req.header('content-type')?.split(';')[0]?.trim();
|
|
174
|
-
await handleBlobUpload({ ...config, ...auth }, {
|
|
175
|
-
blobId: c.req.param('blobId'),
|
|
176
|
-
bytes,
|
|
177
|
-
...(contentType !== undefined &&
|
|
178
|
-
contentType !== 'application/octet-stream'
|
|
179
|
-
? { mediaType: contentType }
|
|
180
|
-
: {}),
|
|
181
|
-
});
|
|
174
|
+
await handleBlobUpload({ ...config, ...auth }, c.req.param('blobId'), c.req.raw);
|
|
182
175
|
return c.body(null, 200);
|
|
183
176
|
}
|
|
184
177
|
catch (error) {
|
|
@@ -214,13 +207,22 @@ export function createSyncularHono(options) {
|
|
|
214
207
|
return errorResponse(c, new SyncError('sync.auth_required'));
|
|
215
208
|
try {
|
|
216
209
|
const result = await handleBlobDownload({ ...config, ...auth }, c.req.param('blobId'));
|
|
217
|
-
if (
|
|
218
|
-
return c.json({ url: result.url, urlExpiresAtMs: result.urlExpiresAtMs }, 200);
|
|
210
|
+
if ('url' in result) {
|
|
211
|
+
return c.json({ url: result.url, urlExpiresAtMs: result.urlExpiresAtMs }, 200, result.headers);
|
|
219
212
|
}
|
|
220
213
|
if (c.req.header('if-none-match') === result.headers.ETag) {
|
|
214
|
+
await result.body.cancel();
|
|
221
215
|
return c.body(null, 304, result.headers);
|
|
222
216
|
}
|
|
223
|
-
|
|
217
|
+
// §5.9.5: blob bytes are relayed as stored with identity encoding, so
|
|
218
|
+
// no request recompresses them and no body is buffered in the host.
|
|
219
|
+
return new Response(result.body, {
|
|
220
|
+
status: 200,
|
|
221
|
+
headers: c.newResponse(null, 200, {
|
|
222
|
+
...result.headers,
|
|
223
|
+
'Content-Length': String(result.byteLength),
|
|
224
|
+
}).headers,
|
|
225
|
+
});
|
|
224
226
|
}
|
|
225
227
|
catch (error) {
|
|
226
228
|
return errorResponse(c, error, 'blobs');
|
|
@@ -229,8 +231,8 @@ export function createSyncularHono(options) {
|
|
|
229
231
|
return app;
|
|
230
232
|
}
|
|
231
233
|
/**
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
+
* The buffered routes — sync, operations and segments — encode their own
|
|
235
|
+
* body (§1.3) and declare `Content-Encoding`. workerd encodes every
|
|
234
236
|
* response that declares one again unless `encodeBody: 'manual'` marks the
|
|
235
237
|
* body as encoded, so a Workers client would decode gzip inside gzip and fail
|
|
236
238
|
* §5.1 verification (SYNCULAR-WORKERS-SEGMENT-ENCODING-001). Other runtimes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncular/server-hono",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.60.0",
|
|
4
4
|
"description": "Hono adapter for the Syncular sync server",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Benjamin Kniffler",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"!dist/**/*.test.d.ts"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@syncular/server": "0.
|
|
48
|
+
"@syncular/server": "0.60.0",
|
|
49
49
|
"hono": "^4.13.11"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@syncular/core": "0.
|
|
52
|
+
"@syncular/core": "0.60.0",
|
|
53
53
|
"happy-dom": "^20.0.0"
|
|
54
54
|
}
|
|
55
55
|
}
|
package/src/admin-page.ts
CHANGED
|
@@ -357,7 +357,7 @@ main{overflow:visible;padding:16px}
|
|
|
357
357
|
</section>
|
|
358
358
|
|
|
359
359
|
<section id="view-people" class="view" aria-labelledby="h-people" hidden>
|
|
360
|
-
<div class="vh"><p class="kicker">02 · People</p><h1 id="h-people">People and devices<span class="dot">.</span></h1><p class="lede">Every actor in this partition with the devices it syncs from. An actor opens its failed and warned requests; a device opens its client page:
|
|
360
|
+
<div class="vh"><p class="kicker">02 · People</p><h1 id="h-people">People and devices<span class="dot">.</span></h1><p class="lede">Every actor in this partition with the devices it syncs from. An actor opens its failed and warned requests; a device opens its client page: units, lease, failures, recent events, and a delivery trace.</p></div>
|
|
361
361
|
<div id="people-rt"></div>
|
|
362
362
|
<div class="cols"><div class="panel"><div class="ph"><h2>Schema rollout</h2><span class="meta" id="rollout-meta"></span></div><div class="pb" id="people-rollout" data-skel></div></div></div>
|
|
363
363
|
<div class="panel">
|
|
@@ -658,7 +658,7 @@ main{overflow:visible;padding:16px}
|
|
|
658
658
|
if (t === 'push.conflicted' || t === 'reaction.retried' || t === 'lease.revoked' ||
|
|
659
659
|
(t === 'request.handled' && (e.outcome === 'reset' || e.outcome === 'schema_floor')) ||
|
|
660
660
|
(t === 'realtime.wake' && e.reason === 'delta-too-large') ||
|
|
661
|
-
(t === 'pull.served' && e.
|
|
661
|
+
(t === 'pull.served' && (e.live.status !== 'active' || e.units.some(u => u.status !== 'active')))) return 'warn';
|
|
662
662
|
return 'info';
|
|
663
663
|
}
|
|
664
664
|
var RANK = { err: 0, warn: 1, info: 2 }, LEVEL_LABEL = { err: 'error', warn: 'warn', info: 'info' };
|
|
@@ -668,12 +668,12 @@ main{overflow:visible;padding:16px}
|
|
|
668
668
|
function summary(e) {
|
|
669
669
|
if (e.type === 'request.handled') {
|
|
670
670
|
return e.outcome + (e.errorCode ? ' ' + e.errorCode : '') + ' · ' + dur(e.durationMs) + ' ms · ' + e.pushCommits +
|
|
671
|
-
' pushed · ' + (e.pulled ? 'pulled ' + e.
|
|
671
|
+
' pushed · ' + (e.pulled ? 'pulled ' + e.units + ' units' : 'no pull') + ' · ' + bytes(e.bytesIn) + ' in, ' + bytes(e.bytesOut) + ' out';
|
|
672
672
|
}
|
|
673
673
|
if (e.type === 'pull.served') {
|
|
674
|
-
var modes = {}
|
|
675
|
-
e.
|
|
676
|
-
return Object.keys(modes).map(k => modes[k] + ' ' + k).join(', ') + ' · ' + commits + ' commits · through ' + e.
|
|
674
|
+
var modes = {};
|
|
675
|
+
e.units.forEach(u => { var k = u.status === 'active' ? u.mode : u.status; modes[k] = (modes[k] || 0) + 1; });
|
|
676
|
+
return Object.keys(modes).map(k => modes[k] + ' ' + k).concat(['live ' + e.live.status]).join(', ') + ' · ' + e.live.commits + ' commits · through ' + e.live.throughSeq;
|
|
677
677
|
}
|
|
678
678
|
return (e.table && e.rowId ? e.table + ' / ' + e.rowId + ' · ' : '') + SUMMARY_KEYS.filter(k => e[k] !== undefined).map(k => {
|
|
679
679
|
return k + ' ' + (typeof e[k] === 'string' ? e[k] : JSON.stringify(e[k]));
|
|
@@ -1002,13 +1002,13 @@ main{overflow:visible;padding:16px}
|
|
|
1002
1002
|
'<select class="inp" name="t" aria-label="Table">' + INFO.tables.map(t => '<option>' + esc(t.name) + '</option>').join('') + '</select>' +
|
|
1003
1003
|
'<input class="inp grow" name="r" placeholder="Row id" aria-label="Row id" spellcheck="false" /><button class="btn amber" type="submit">Trace</button></div></form></div></div>' +
|
|
1004
1004
|
'<div class="panel"><div class="ph"><h2>Failures and warnings</h2><span class="meta" id="client-fail-meta"></span></div><div id="client-fail"></div></div>' +
|
|
1005
|
-
'<div class="panel"><div class="ph"><h2>
|
|
1005
|
+
'<div class="panel"><div class="ph"><h2>Units</h2><span class="meta">' + c.units.length + '</span></div><div id="client-units"></div></div>' +
|
|
1006
1006
|
'<div class="panel"><div class="ph"><h2>Recent events</h2><span class="meta">' + d.events.length + '</span></div><div id="client-events"></div></div>');
|
|
1007
|
-
table('client-
|
|
1008
|
-
{ l: 'Id', c: 'w-sm', h:
|
|
1009
|
-
{ l: '
|
|
1010
|
-
{ l: '
|
|
1011
|
-
], c.
|
|
1007
|
+
table('client-units', [
|
|
1008
|
+
{ l: 'Id', c: 'w-sm', h: u => idCell(u.id) },
|
|
1009
|
+
{ l: 'Scopes', h: u => tags(Object.keys(u.scopes).map(k => k + ': ' + u.scopes[k])) },
|
|
1010
|
+
{ l: 'State', c: 'fill', h: u => u.catchingUpCursor === undefined ? st('ok', 'live') : st('warn', 'catching up') + ' <span class="dim">at ' + fmt(u.catchingUpCursor) + '</span>' }
|
|
1011
|
+
], c.units, empty('No units', 'The client record stores no registration list.', true));
|
|
1012
1012
|
table('client-events', EV_COLS, d.events, empty('No events', 'The ring holds no events for this client.', true), openEvent);
|
|
1013
1013
|
return loadFailures('client-fail', { clientId: id });
|
|
1014
1014
|
}, fail(['client-body']));
|
|
@@ -1036,11 +1036,9 @@ main{overflow:visible;padding:16px}
|
|
|
1036
1036
|
$('table-activity-panel').hidden = !sv;
|
|
1037
1037
|
var jobs = [(S.clients ? Promise.resolve() : loadClients()).then(() => get('/rows/' + enc(t), { limit: PAGE_ROWS, afterRowId: after, scope: scope })).then(r => {
|
|
1038
1038
|
var p = r.page, cols = schema ? schema.columns.filter(c => !c.primaryKey).slice(0, 4) : [];
|
|
1039
|
-
var seen = {}, chips = [];
|
|
1040
|
-
(
|
|
1041
|
-
|
|
1042
|
-
}));
|
|
1043
|
-
p.rows.forEach(row => Object.keys(row.scopes || {}).forEach(k => { seen[k + ':' + row.scopes[k]] = 1; }));
|
|
1039
|
+
var seen = {}, keys = {}, chips = [];
|
|
1040
|
+
p.rows.forEach(row => Object.keys(row.scopes || {}).forEach(k => { keys[k] = 1; seen[k + ':' + row.scopes[k]] = 1; }));
|
|
1041
|
+
(S.clients || []).forEach(c => c.units.forEach(u => Object.keys(u.scopes).forEach(k => { if (keys[k]) seen[k + ':' + u.scopes[k]] = 1; })));
|
|
1044
1042
|
chips = Object.keys(seen).sort().slice(0, 30);
|
|
1045
1043
|
html('table-scopes', 'Scope ' + link(route('table', [t]), 'all rows', 'tag' + (scope ? '' : ' on')) +
|
|
1046
1044
|
chips.map(k => link(route('table', [t, k]), k.replace(':', ': '), 'tag' + (k === scope ? ' on' : ''))).join(''));
|
|
@@ -1073,15 +1071,15 @@ main{overflow:visible;padding:16px}
|
|
|
1073
1071
|
}
|
|
1074
1072
|
var VERDICT = {
|
|
1075
1073
|
delivered: ['ok', 'Delivered', 'The client has pulled the row\\'s last change.'],
|
|
1076
|
-
'pending-pull': ['warn', 'Pending pull', 'A
|
|
1074
|
+
'pending-pull': ['warn', 'Pending pull', 'A unit covers the row, and the client\\'s cursor is behind the row\\'s last change. The next pull delivers it.'],
|
|
1077
1075
|
'row-deleted': ['warn', 'Row deleted', 'The row\\'s last change is a delete. A client that held the row drops it on its next pull.'],
|
|
1078
|
-
'scope-mismatch': ['err', 'Scope mismatch', '
|
|
1079
|
-
'scope-denied': ['err', 'Scope denied', 'A
|
|
1080
|
-
'no-
|
|
1076
|
+
'scope-mismatch': ['err', 'Scope mismatch', 'A unit of the client covers the table, but none carries the row\\'s scope values.'],
|
|
1077
|
+
'scope-denied': ['err', 'Scope denied', 'A unit carries the row\\'s scopes, but the actor\\'s allowed scopes from resolveScopes exclude them, so the server never delivers the row.'],
|
|
1078
|
+
'no-unit': ['idle', 'No unit', 'No unit of the client covers this table.'],
|
|
1081
1079
|
'client-unknown': ['err', 'Client unknown', 'This partition has no cursor record for the client.'],
|
|
1082
1080
|
'row-missing': ['err', 'Row missing', 'The partition holds no row with this id in this table.']
|
|
1083
1081
|
};
|
|
1084
|
-
var VORDER = ['row-missing', 'client-unknown', 'no-
|
|
1082
|
+
var VORDER = ['row-missing', 'client-unknown', 'no-unit', 'scope-denied', 'scope-mismatch', 'row-deleted', 'pending-pull', 'delivered'];
|
|
1085
1083
|
function verdictOf(v) { return VERDICT[v] || ['err', v, 'The console does not know this verdict.']; }
|
|
1086
1084
|
var HISTORY_COLS = [
|
|
1087
1085
|
{ l: 'Seq', c: 'num', d: -1, v: x => x.commitSeq, h: x => '<span class="ty">' + fmt(x.commitSeq) + '</span>' },
|
|
@@ -1137,14 +1135,14 @@ main{overflow:visible;padding:16px}
|
|
|
1137
1135
|
['Last change', lc ? seqBtn(lc.commitSeq) + ' ' + esc(lc.op) + ' by ' + esc(lc.actorId) + ' ' + ago(lc.createdAtMs) : '<span class="dim">none retained; horizon ' + fmt(x.horizonSeq) + '</span>'],
|
|
1138
1136
|
['Client', c ? clientLink(client) + ' · cursor ' + fmt(c.cursor) + ' · ' + presence(c) : st('err', 'unknown')],
|
|
1139
1137
|
['Allowed', x.allowed === undefined ? '<span class="dim">no resolver</span>' : x.allowed === 'outage' ? st('err', 'resolveScopes outage') : scopeTags(x.allowed)]]) +
|
|
1140
|
-
'<h3>
|
|
1141
|
-
table('m-
|
|
1142
|
-
{ l: 'Id', c: 'w-sm', h:
|
|
1143
|
-
{ l: '
|
|
1144
|
-
{ l: 'Requested', h:
|
|
1145
|
-
{ l: 'Allowed', h:
|
|
1146
|
-
{ l: 'Mismatches', c: 'fill', h:
|
|
1147
|
-
], x.
|
|
1138
|
+
'<h3>Units covering ' + esc(t) + ' · ' + x.units.length + '</h3><div id="m-units"></div><h3>Rejected pushes · ' + x.rejections.length + '</h3><div id="m-events"></div>', x);
|
|
1139
|
+
table('m-units', [
|
|
1140
|
+
{ l: 'Id', c: 'w-sm', h: u => idCell(u.id) },
|
|
1141
|
+
{ l: 'Scopes', h: u => tags(Object.keys(u.scopes).map(k => k + ': ' + u.scopes[k])) },
|
|
1142
|
+
{ l: 'Requested', h: u => u.requestedMatch ? st('ok', 'covers row') : st('err', 'mismatch') },
|
|
1143
|
+
{ l: 'Allowed', h: u => u.effectiveMatch === undefined ? '<span class="dim">not checked</span>' : u.effectiveMatch ? st('ok', 'covers row') : st('err', 'denied') },
|
|
1144
|
+
{ l: 'Mismatches', c: 'fill', h: u => u.mismatches.length ? tags(u.mismatches.map(m => m.variable + ': row ' + m.rowValue + ', requested ' + m.requested)) : '<span class="dim">none</span>' }
|
|
1145
|
+
], x.units, empty('No units', 'No unit of the client covers ' + esc(t) + '.', true));
|
|
1148
1146
|
table('m-events', EV_COLS, x.rejections, empty('No rejections', 'The ring holds no rejected or conflicted push for this row.', true), openEvent);
|
|
1149
1147
|
}, err => { if (token === modalToken && err !== STALE) fillModal(errBox(err), { code: err.code, message: err.message }); });
|
|
1150
1148
|
}
|
|
@@ -1182,7 +1180,7 @@ main{overflow:visible;padding:16px}
|
|
|
1182
1180
|
get('/writes/' + enc(id)).then(r => {
|
|
1183
1181
|
if (token !== modalToken) return;
|
|
1184
1182
|
var w = r.write;
|
|
1185
|
-
fillModal((w.outcomes.length ? '' : empty('No recorded outcome', 'No client has a stored outcome for this client commit id. The server never received it
|
|
1183
|
+
fillModal((w.outcomes.length ? '' : w.watermarks.length ? w.watermarks.map(m => '<h3>' + st('idle', 'expired') + ' · client ' + clientLink(m.clientId) + ' · outbox ' + idText(m.outboxId) + '</h3><p class="verdict">The outbox watermark deleted its result: expired below sequence ' + fmt(m.throughSeq) + '.</p>').join('') : empty('No recorded outcome', 'No client has a stored outcome for this client commit id, and no outbox watermark covers it. The server never received it.', true)) +
|
|
1186
1184
|
w.outcomes.map((o, i) => '<h3>' + (o.status === 'applied' ? st('ok', 'applied') : st('err', 'rejected')) + ' · client ' + clientLink(o.clientId) +
|
|
1187
1185
|
(o.commitSeq !== undefined ? ' · commit ' + seqBtn(o.commitSeq) : '') + (o.recordedAtMs ? ' · ' + ago(o.recordedAtMs) : '') + '</h3><div id="m-res-' + i + '"></div>').join('') +
|
|
1188
1186
|
'<h3>Ring events · ' + w.events.length + '</h3><div id="m-events"></div>', w);
|
|
@@ -1295,7 +1293,7 @@ main{overflow:visible;padding:16px}
|
|
|
1295
1293
|
{ l: 'Detail', c: 'fill', ns: true, h: detailCell }
|
|
1296
1294
|
];
|
|
1297
1295
|
// One row per sync request: every event of a request shares requestId.
|
|
1298
|
-
// An idle round pushed nothing and pulled no commit
|
|
1296
|
+
// An idle round pushed nothing and pulled no commit.
|
|
1299
1297
|
function groups(list) {
|
|
1300
1298
|
var by = {}, out = [];
|
|
1301
1299
|
list.forEach(e => {
|
|
@@ -1309,14 +1307,14 @@ main{overflow:visible;padding:16px}
|
|
|
1309
1307
|
g.level = g.events.reduce((l, e) => RANK[level(e)] < RANK[l] ? level(e) : l, 'info');
|
|
1310
1308
|
g.clientId = g.events.map(e => e.clientId).filter(Boolean)[0];
|
|
1311
1309
|
g.actorId = g.events.map(e => e.actorId).filter(Boolean)[0];
|
|
1312
|
-
g.idle = !!g.rh && g.level === 'info' && g.rh.pushCommits === 0 && g.events.every(e => e.type !== 'pull.served' || e.
|
|
1310
|
+
g.idle = !!g.rh && g.level === 'info' && g.rh.pushCommits === 0 && g.events.every(e => e.type !== 'pull.served' || !e.live.commits);
|
|
1313
1311
|
});
|
|
1314
1312
|
return out;
|
|
1315
1313
|
}
|
|
1316
1314
|
function groupSummary(g) {
|
|
1317
1315
|
if (!g.id) return summary(g.events[0]);
|
|
1318
1316
|
var pulled = 0, rh = g.rh;
|
|
1319
|
-
g.events.forEach(e => { if (e.type === 'pull.served')
|
|
1317
|
+
g.events.forEach(e => { if (e.type === 'pull.served') pulled += e.live.commits; });
|
|
1320
1318
|
var bad = g.events.filter(e => e.type === 'push.rejected' || e.type === 'push.conflicted');
|
|
1321
1319
|
return (rh ? rh.outcome + (rh.errorCode ? ' ' + rh.errorCode : '') + ' · ' + dur(rh.durationMs) + ' ms · ' + rh.pushCommits + ' pushed · ' : 'in flight · ') +
|
|
1322
1320
|
pulled + ' commits pulled' + (bad.length ? ' · ' + bad.map(e => e.type.slice(5) + (e.table ? ' ' + e.table + ' / ' + e.rowId : '')).join(', ') : '') + ' · ' + g.events.length + ' events';
|
package/src/admin.ts
CHANGED
|
@@ -127,6 +127,20 @@ export function createSyncularAdminRoutes(
|
|
|
127
127
|
|
|
128
128
|
/** Run the host guards; actions also need `authorizeActions`. */
|
|
129
129
|
async function guard(request: Request, partition: string): Promise<void> {
|
|
130
|
+
// A cookie-authenticated operator's browser must not run an action for
|
|
131
|
+
// another site. The origin check compares hosts, so a proxy that ends TLS
|
|
132
|
+
// in front of the server still passes it.
|
|
133
|
+
if (request.method === 'POST') {
|
|
134
|
+
const site = request.headers.get('sec-fetch-site');
|
|
135
|
+
const origin = request.headers.get('origin');
|
|
136
|
+
if (
|
|
137
|
+
(site !== null && site !== 'same-origin' && site !== 'none') ||
|
|
138
|
+
(origin !== null &&
|
|
139
|
+
URL.parse(origin)?.host !== new URL(request.url).host)
|
|
140
|
+
) {
|
|
141
|
+
throw new SyncError('sync.forbidden', 'cross-site admin request');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
130
144
|
const context = { partition, request };
|
|
131
145
|
if (!(await options.authorize(context))) {
|
|
132
146
|
throw new SyncError('sync.auth_required');
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
type RemoteOperationRegistry,
|
|
20
20
|
type RemoteOperationResolver,
|
|
21
21
|
handleSyncRequest,
|
|
22
|
+
limitsOf,
|
|
22
23
|
RealtimeHub,
|
|
23
24
|
RingBufferEvents,
|
|
24
25
|
SEGMENT_STREAM_THRESHOLD_BYTES,
|
|
@@ -61,6 +62,8 @@ export interface SyncularHonoAdminOptions extends SyncularAdminGuards {
|
|
|
61
62
|
export function createSyncularHono(options: SyncularHonoOptions): Hono {
|
|
62
63
|
const app = new Hono();
|
|
63
64
|
let config = options.config;
|
|
65
|
+
// Validates every configured limit once, at creation.
|
|
66
|
+
const { maxRequestBytes } = limitsOf(config);
|
|
64
67
|
const admin = options.admin;
|
|
65
68
|
if (admin !== undefined) {
|
|
66
69
|
const ring = new RingBufferEvents(
|
|
@@ -123,7 +126,7 @@ export function createSyncularHono(options: SyncularHonoOptions): Hono {
|
|
|
123
126
|
),
|
|
124
127
|
415,
|
|
125
128
|
);
|
|
126
|
-
// §1.3: every buffered body — a sync round, an operation result, a
|
|
129
|
+
// §1.3: every buffered body — a sync round, an operation result, a
|
|
127
130
|
// segment — is encoded per the request's `Accept-Encoding` (zstd preferred,
|
|
128
131
|
// gzip fallback, identity otherwise) and carries `Vary: Accept-Encoding`.
|
|
129
132
|
// Headers are built through the Hono context so host middleware headers
|
|
@@ -175,7 +178,7 @@ export function createSyncularHono(options: SyncularHonoOptions): Hono {
|
|
|
175
178
|
if (auth === null)
|
|
176
179
|
return errorResponse(c, new SyncError('sync.auth_required'));
|
|
177
180
|
try {
|
|
178
|
-
const bytes = await decodeRequestBody(c.req.raw);
|
|
181
|
+
const bytes = await decodeRequestBody(c.req.raw, maxRequestBytes);
|
|
179
182
|
if (bytes === undefined) return unsupportedEncoding(c, 'sync');
|
|
180
183
|
const out = await handleSyncRequest(bytes, {
|
|
181
184
|
...config,
|
|
@@ -201,7 +204,7 @@ export function createSyncularHono(options: SyncularHonoOptions): Hono {
|
|
|
201
204
|
if (auth === null)
|
|
202
205
|
return errorResponse(c, new SyncError('sync.auth_required'));
|
|
203
206
|
try {
|
|
204
|
-
const bytes = await decodeRequestBody(c.req.raw);
|
|
207
|
+
const bytes = await decodeRequestBody(c.req.raw, maxRequestBytes);
|
|
205
208
|
if (bytes === undefined) return unsupportedEncoding(c, 'operations');
|
|
206
209
|
const out = await handleRemoteOperation(
|
|
207
210
|
bytes,
|
|
@@ -267,18 +270,10 @@ export function createSyncularHono(options: SyncularHonoOptions): Hono {
|
|
|
267
270
|
if (auth === null)
|
|
268
271
|
return errorResponse(c, new SyncError('sync.auth_required'));
|
|
269
272
|
try {
|
|
270
|
-
const bytes = new Uint8Array(await c.req.arrayBuffer());
|
|
271
|
-
const contentType = c.req.header('content-type')?.split(';')[0]?.trim();
|
|
272
273
|
await handleBlobUpload(
|
|
273
274
|
{ ...config, ...auth },
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
bytes,
|
|
277
|
-
...(contentType !== undefined &&
|
|
278
|
-
contentType !== 'application/octet-stream'
|
|
279
|
-
? { mediaType: contentType }
|
|
280
|
-
: {}),
|
|
281
|
-
},
|
|
275
|
+
c.req.param('blobId'),
|
|
276
|
+
c.req.raw,
|
|
282
277
|
);
|
|
283
278
|
return c.body(null, 200);
|
|
284
279
|
} catch (error) {
|
|
@@ -324,20 +319,26 @@ export function createSyncularHono(options: SyncularHonoOptions): Hono {
|
|
|
324
319
|
{ ...config, ...auth },
|
|
325
320
|
c.req.param('blobId'),
|
|
326
321
|
);
|
|
327
|
-
if (
|
|
322
|
+
if ('url' in result) {
|
|
328
323
|
return c.json(
|
|
329
324
|
{ url: result.url, urlExpiresAtMs: result.urlExpiresAtMs },
|
|
330
325
|
200,
|
|
326
|
+
result.headers,
|
|
331
327
|
);
|
|
332
328
|
}
|
|
333
329
|
if (c.req.header('if-none-match') === result.headers.ETag) {
|
|
330
|
+
await result.body.cancel();
|
|
334
331
|
return c.body(null, 304, result.headers);
|
|
335
332
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
333
|
+
// §5.9.5: blob bytes are relayed as stored with identity encoding, so
|
|
334
|
+
// no request recompresses them and no body is buffered in the host.
|
|
335
|
+
return new Response(result.body, {
|
|
336
|
+
status: 200,
|
|
337
|
+
headers: c.newResponse(null, 200, {
|
|
338
|
+
...result.headers,
|
|
339
|
+
'Content-Length': String(result.byteLength),
|
|
340
|
+
}).headers,
|
|
341
|
+
});
|
|
341
342
|
} catch (error) {
|
|
342
343
|
return errorResponse(c, error, 'blobs');
|
|
343
344
|
}
|
|
@@ -346,8 +347,8 @@ export function createSyncularHono(options: SyncularHonoOptions): Hono {
|
|
|
346
347
|
return app;
|
|
347
348
|
}
|
|
348
349
|
/**
|
|
349
|
-
*
|
|
350
|
-
*
|
|
350
|
+
* The buffered routes — sync, operations and segments — encode their own
|
|
351
|
+
* body (§1.3) and declare `Content-Encoding`. workerd encodes every
|
|
351
352
|
* response that declares one again unless `encodeBody: 'manual'` marks the
|
|
352
353
|
* body as encoded, so a Workers client would decode gzip inside gzip and fail
|
|
353
354
|
* §5.1 verification (SYNCULAR-WORKERS-SEGMENT-ENCODING-001). Other runtimes
|