nowity 1.9.0 → 1.10.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/README.md +60 -2
- package/dist/client/clock.d.ts +98 -0
- package/dist/client/clock.d.ts.map +1 -0
- package/dist/client/clock.js +154 -0
- package/dist/client/devtools.d.ts +64 -1
- package/dist/client/devtools.d.ts.map +1 -1
- package/dist/client/devtools.js +134 -22
- package/dist/client/nowity-client.d.ts +38 -0
- package/dist/client/nowity-client.d.ts.map +1 -1
- package/dist/client/nowity-client.js +93 -3
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +4 -1
- package/dist/core/protocol.d.ts +70 -2
- package/dist/core/protocol.d.ts.map +1 -1
- package/dist/core/types.d.ts +6 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/devtools.d.ts +14 -1
- package/dist/devtools.d.ts.map +1 -1
- package/dist/devtools.js +64 -18
- package/dist/server/change-source/outbox-change-source.d.ts +1 -0
- package/dist/server/change-source/outbox-change-source.d.ts.map +1 -1
- package/dist/server/change-source/outbox-change-source.js +2 -1
- package/dist/server/sync-engine.d.ts +9 -0
- package/dist/server/sync-engine.d.ts.map +1 -1
- package/dist/server/sync-engine.js +37 -7
- package/dist/server/ws-server.d.ts +20 -0
- package/dist/server/ws-server.d.ts.map +1 -1
- package/dist/server/ws-server.js +81 -2
- package/package.json +1 -1
package/dist/core/protocol.d.ts
CHANGED
|
@@ -51,7 +51,20 @@ export interface ClientContext {
|
|
|
51
51
|
t: "context";
|
|
52
52
|
context: Record<string, unknown> | null;
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
/**
|
|
55
|
+
* One exchange of the clock sync (see `client/clock`). `t0` is the client's
|
|
56
|
+
* `performance.now()` at sending; the server only echoes it.
|
|
57
|
+
*
|
|
58
|
+
* Answered the moment it arrives, ahead of whatever this socket has queued: a
|
|
59
|
+
* ping that waited behind a slow mutation would measure the mutation. A server
|
|
60
|
+
* older than it ignores it, and the client then simply has no estimate.
|
|
61
|
+
*/
|
|
62
|
+
export interface ClientPing {
|
|
63
|
+
t: "ping";
|
|
64
|
+
id: number;
|
|
65
|
+
t0: number;
|
|
66
|
+
}
|
|
67
|
+
export type ClientMessage = ClientHello | ClientSubscribe | ClientUnsubscribe | ClientMutate | ClientContext | ClientPing;
|
|
55
68
|
/**
|
|
56
69
|
* A query result rendered on the server for the first paint.
|
|
57
70
|
*
|
|
@@ -150,6 +163,17 @@ export interface ServerWelcome {
|
|
|
150
163
|
}>;
|
|
151
164
|
entities?: Record<string, WireEntity>;
|
|
152
165
|
};
|
|
166
|
+
/**
|
|
167
|
+
* The server's clock around the hello — when it arrived on the socket and
|
|
168
|
+
* when this answer left, epoch ms — so the welcome is already the first
|
|
169
|
+
* clock sample. Absent from a server older than it.
|
|
170
|
+
*/
|
|
171
|
+
clock?: {
|
|
172
|
+
receivedAt: number;
|
|
173
|
+
sentAt: number;
|
|
174
|
+
};
|
|
175
|
+
/** This connection gets {@link MutationTiming} / {@link TxTiming} (the server's `timing` option). */
|
|
176
|
+
timing?: boolean;
|
|
153
177
|
}
|
|
154
178
|
/** Full result of a live query. Replaces whatever the client held for `subId`. */
|
|
155
179
|
export interface SubSnapshot {
|
|
@@ -218,8 +242,42 @@ export interface SubPatch {
|
|
|
218
242
|
* permissions and data therefore cannot be observed half-applied: the
|
|
219
243
|
* re-snapshotted subscription and the patched one land together.
|
|
220
244
|
*/
|
|
245
|
+
/**
|
|
246
|
+
* Where one mutation spent its time on the server, epoch ms of the server's
|
|
247
|
+
* clock. Only on a connection the server sends timing to.
|
|
248
|
+
*/
|
|
249
|
+
export interface MutationTiming {
|
|
250
|
+
/** The message arrived on the socket. */
|
|
251
|
+
receivedAt: number;
|
|
252
|
+
/** Its turn came: the mutations before it on this connection were done. */
|
|
253
|
+
startedAt: number;
|
|
254
|
+
/** The transaction committed (the outbox row is written inside it). Absent when it was rolled back. */
|
|
255
|
+
committedAt?: number;
|
|
256
|
+
/** This answer left. */
|
|
257
|
+
sentAt: number;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Where the push of one change spent its time, epoch ms of the server's clock.
|
|
261
|
+
* Only on a connection the server sends timing to.
|
|
262
|
+
*/
|
|
263
|
+
export interface TxTiming {
|
|
264
|
+
/**
|
|
265
|
+
* The earliest outbox row of this connection's own mutations in it — the
|
|
266
|
+
* database's clock, not the sync server's. Absent when the batch carries
|
|
267
|
+
* none, or the change source does not know (logical replication).
|
|
268
|
+
*/
|
|
269
|
+
writtenAt?: number;
|
|
270
|
+
/** The change source handed the batch over. */
|
|
271
|
+
readAt: number;
|
|
272
|
+
/** The fan-out of the batch started (after whatever was queued before it). */
|
|
273
|
+
fanOutAt: number;
|
|
274
|
+
/** This message left. */
|
|
275
|
+
sentAt: number;
|
|
276
|
+
}
|
|
221
277
|
export interface ServerTx {
|
|
222
278
|
t: "tx";
|
|
279
|
+
/** See {@link TxTiming}. */
|
|
280
|
+
timing?: TxTiming;
|
|
223
281
|
position: string;
|
|
224
282
|
/**
|
|
225
283
|
* Mutations up to (and including) this id are reflected in the data carried
|
|
@@ -255,6 +313,16 @@ export interface ServerMutationResult {
|
|
|
255
313
|
/** What the endpoint returned, when it returned something. */
|
|
256
314
|
value?: unknown;
|
|
257
315
|
lastMutationId: number;
|
|
316
|
+
/** See {@link MutationTiming}. */
|
|
317
|
+
timing?: MutationTiming;
|
|
318
|
+
}
|
|
319
|
+
/** The answer to a {@link ClientPing}: when it arrived and left, epoch ms of the server's clock. */
|
|
320
|
+
export interface ServerPong {
|
|
321
|
+
t: "pong";
|
|
322
|
+
id: number;
|
|
323
|
+
t0: number;
|
|
324
|
+
t1: number;
|
|
325
|
+
t2: number;
|
|
258
326
|
}
|
|
259
327
|
export interface ServerError {
|
|
260
328
|
t: "error";
|
|
@@ -262,5 +330,5 @@ export interface ServerError {
|
|
|
262
330
|
code: string;
|
|
263
331
|
message: string;
|
|
264
332
|
}
|
|
265
|
-
export type ServerMessage = ServerWelcome | ServerSnapshot | ServerTx | ServerMutationResult | ServerMutators | ServerError;
|
|
333
|
+
export type ServerMessage = ServerWelcome | ServerSnapshot | ServerTx | ServerMutationResult | ServerMutators | ServerPong | ServerError;
|
|
266
334
|
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/core/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEvD;;;;;;;;;GASG;AAEH,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAIlC,MAAM,WAAW,WAAW;IACxB,CAAC,EAAE,OAAO,CAAC;IACX,CAAC,EAAE,MAAM,CAAC;IACV,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,eAAe;IAC5B,CAAC,EAAE,WAAW,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAC9B,CAAC,EAAE,aAAa,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IACzB,CAAC,EAAE,QAAQ,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC1B,CAAC,EAAE,SAAS,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;C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AAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IACxB,CAAC,EAAE,OAAO,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,aAAa,GACnB,aAAa,GACb,cAAc,GACd,QAAQ,GACR,oBAAoB,GACpB,cAAc,GACd,UAAU,GACV,WAAW,CAAC"}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -63,6 +63,12 @@ export interface ChangeEvent {
|
|
|
63
63
|
* to missing changes.
|
|
64
64
|
*/
|
|
65
65
|
beforeComplete?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* When the change was written, epoch ms of the database's clock — the
|
|
68
|
+
* outbox row's `created_at`. For timing only; absent from a source that
|
|
69
|
+
* does not know it.
|
|
70
|
+
*/
|
|
71
|
+
writtenAt?: number;
|
|
66
72
|
}
|
|
67
73
|
/**
|
|
68
74
|
* All changes of one database transaction, in commit order.
|
package/dist/core/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,6EAA6E;AAC7E,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1C,4EAA4E;AAC5E,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEtD,yEAAyE;AACzE,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAExD;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,QAAQ,CAAC;CACnB;A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5 +1,5 @@
|
|
|
1
1
|
import type { DevtoolsRecord, DevtoolsRecordType, NowityDevtools } from "./client/devtools";
|
|
2
|
-
export { NowityDevtools, maskArgs, byteSize, MASKED, DEFAULT_ALLOWED_KEYS, type DevtoolsMeta, type DevtoolsOptions, type DevtoolsRecord, type DevtoolsRecordType, type DevtoolsStatus, type DevtoolsSummary, type DevtoolsUpdate, type DevtoolsUpdateCause, } from "./client/devtools";
|
|
2
|
+
export { NowityDevtools, maskArgs, mutationPhases, byteSize, MASKED, DEFAULT_ALLOWED_KEYS, type DevtoolsMeta, type DevtoolsOptions, type DevtoolsPhase, type DevtoolsRecord, type DevtoolsRecordType, type DevtoolsStatus, type DevtoolsSummary, type DevtoolsUpdate, type DevtoolsUpdateCause, } from "./client/devtools";
|
|
3
3
|
export interface NowityDevtoolsPanelProps {
|
|
4
4
|
/** The client's recorder: `connection.client.devtools`. */
|
|
5
5
|
recorder: NowityDevtools;
|
|
@@ -15,6 +15,19 @@ type Filter = "all" | DevtoolsRecordType;
|
|
|
15
15
|
type SortKey = "start" | "name" | "status" | "latency" | "size" | "updates";
|
|
16
16
|
export declare function formatMs(ms: number | null | undefined): string;
|
|
17
17
|
export declare function formatBytes(bytes: number | null | undefined): string;
|
|
18
|
+
/** Format of a server time: wall clock with milliseconds, UTC. */
|
|
19
|
+
export declare function formatServerTime(serverTs: number | null | undefined): string;
|
|
20
|
+
/**
|
|
21
|
+
* Where a record starts on the common axis: the server's clock, through ONE
|
|
22
|
+
* offset — the current estimate — for every record.
|
|
23
|
+
*
|
|
24
|
+
* Not `record.serverTs`: each record is stamped with the estimate of its own
|
|
25
|
+
* moment, and two estimates may differ by up to their uncertainty, which would
|
|
26
|
+
* swap records a few ms apart. All `ts` come from one monotonic clock, so one
|
|
27
|
+
* offset keeps their order exact and puts them on the server's axis at once.
|
|
28
|
+
* Without an estimate (`offsetMs` null) the page's own clock is the axis.
|
|
29
|
+
*/
|
|
30
|
+
export declare function axisTs(record: DevtoolsRecord, offsetMs: number | null): number;
|
|
18
31
|
/** Rows for the table: filtered, searched and sorted. Pure, for tests. */
|
|
19
32
|
export declare function visibleRecords(records: readonly DevtoolsRecord[], filter: Filter, search: string, sort: SortKey, desc: boolean): DevtoolsRecord[];
|
|
20
33
|
/**
|
package/dist/devtools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools.d.ts","sourceRoot":"","sources":["../src/devtools.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"devtools.d.ts","sourceRoot":"","sources":["../src/devtools.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAER,cAAc,EACd,kBAAkB,EAGlB,cAAc,EACjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACH,cAAc,EACd,QAAQ,EACR,cAAc,EACd,QAAQ,EACR,MAAM,EACN,oBAAoB,EACpB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,mBAAmB,GAC3B,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,wBAAwB;IACrC,2DAA2D;IAC3D,QAAQ,EAAE,cAAc,CAAC;IACzB,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,KAAK,MAAM,GAAG,KAAK,GAAG,kBAAkB,CAAC;AACzC,KAAK,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;AAe5E,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAK9D;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAKpE;AAED,kEAAkE;AAClE,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAG5E;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAE9E;AAED,0EAA0E;AAC1E,wBAAgB,cAAc,CAC1B,OAAO,EAAE,SAAS,cAAc,EAAE,EAClC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,OAAO,GACd,cAAc,EAAE,CA8BlB;AAyFD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAe,EAAE,KAAgB,EAAE,EAAE,wBAAwB,+BAoN/H"}
|
package/dist/devtools.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
"use client";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.DEFAULT_ALLOWED_KEYS = exports.MASKED = exports.byteSize = exports.maskArgs = exports.NowityDevtools = void 0;
|
|
4
|
+
exports.DEFAULT_ALLOWED_KEYS = exports.MASKED = exports.byteSize = exports.mutationPhases = exports.maskArgs = exports.NowityDevtools = void 0;
|
|
5
5
|
exports.formatMs = formatMs;
|
|
6
6
|
exports.formatBytes = formatBytes;
|
|
7
|
+
exports.formatServerTime = formatServerTime;
|
|
8
|
+
exports.axisTs = axisTs;
|
|
7
9
|
exports.visibleRecords = visibleRecords;
|
|
8
10
|
exports.NowityDevtoolsPanel = NowityDevtoolsPanel;
|
|
9
11
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
@@ -20,12 +22,14 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
20
22
|
* shows is in the browser's memory already, masked; it sends nothing anywhere.
|
|
21
23
|
*/
|
|
22
24
|
const react_1 = require("react");
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Object.defineProperty(exports, "
|
|
26
|
-
Object.defineProperty(exports, "
|
|
27
|
-
Object.defineProperty(exports, "
|
|
28
|
-
Object.defineProperty(exports, "
|
|
25
|
+
const devtools_1 = require("./client/devtools");
|
|
26
|
+
var devtools_2 = require("./client/devtools");
|
|
27
|
+
Object.defineProperty(exports, "NowityDevtools", { enumerable: true, get: function () { return devtools_2.NowityDevtools; } });
|
|
28
|
+
Object.defineProperty(exports, "maskArgs", { enumerable: true, get: function () { return devtools_2.maskArgs; } });
|
|
29
|
+
Object.defineProperty(exports, "mutationPhases", { enumerable: true, get: function () { return devtools_2.mutationPhases; } });
|
|
30
|
+
Object.defineProperty(exports, "byteSize", { enumerable: true, get: function () { return devtools_2.byteSize; } });
|
|
31
|
+
Object.defineProperty(exports, "MASKED", { enumerable: true, get: function () { return devtools_2.MASKED; } });
|
|
32
|
+
Object.defineProperty(exports, "DEFAULT_ALLOWED_KEYS", { enumerable: true, get: function () { return devtools_2.DEFAULT_ALLOWED_KEYS; } });
|
|
29
33
|
const COLORS = {
|
|
30
34
|
subscribe: "#4f9cf9",
|
|
31
35
|
mutation: "#f5a524",
|
|
@@ -56,6 +60,25 @@ function formatBytes(bytes) {
|
|
|
56
60
|
return `${(bytes / 1024).toFixed(1)} kB`;
|
|
57
61
|
return `${bytes} B`;
|
|
58
62
|
}
|
|
63
|
+
/** Format of a server time: wall clock with milliseconds, UTC. */
|
|
64
|
+
function formatServerTime(serverTs) {
|
|
65
|
+
if (serverTs === null || serverTs === undefined || !Number.isFinite(serverTs))
|
|
66
|
+
return "—";
|
|
67
|
+
return new Date(serverTs).toISOString().slice(11, 23);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Where a record starts on the common axis: the server's clock, through ONE
|
|
71
|
+
* offset — the current estimate — for every record.
|
|
72
|
+
*
|
|
73
|
+
* Not `record.serverTs`: each record is stamped with the estimate of its own
|
|
74
|
+
* moment, and two estimates may differ by up to their uncertainty, which would
|
|
75
|
+
* swap records a few ms apart. All `ts` come from one monotonic clock, so one
|
|
76
|
+
* offset keeps their order exact and puts them on the server's axis at once.
|
|
77
|
+
* Without an estimate (`offsetMs` null) the page's own clock is the axis.
|
|
78
|
+
*/
|
|
79
|
+
function axisTs(record, offsetMs) {
|
|
80
|
+
return record.ts + (offsetMs ?? 0);
|
|
81
|
+
}
|
|
59
82
|
/** Rows for the table: filtered, searched and sorted. Pure, for tests. */
|
|
60
83
|
function visibleRecords(records, filter, search, sort, desc) {
|
|
61
84
|
const needle = search.trim().toLowerCase();
|
|
@@ -174,15 +197,17 @@ function NowityDevtoolsPanel({ recorder, onClose, floating, height = "40vh", tit
|
|
|
174
197
|
const [selected, setSelected] = (0, react_1.useState)(null);
|
|
175
198
|
const [copied, setCopied] = (0, react_1.useState)(false);
|
|
176
199
|
const rows = (0, react_1.useMemo)(() => visibleRecords(records, filter, search, sort, desc), [records, filter, search, sort, desc]);
|
|
200
|
+
const offsetMs = summary.clock?.offsetMs ?? null;
|
|
177
201
|
const range = (0, react_1.useMemo)(() => {
|
|
178
202
|
let start = Number.POSITIVE_INFINITY;
|
|
179
|
-
let end =
|
|
203
|
+
let end = Number.NEGATIVE_INFINITY;
|
|
180
204
|
for (const record of rows) {
|
|
181
|
-
|
|
182
|
-
|
|
205
|
+
const at = axisTs(record, offsetMs);
|
|
206
|
+
start = Math.min(start, at);
|
|
207
|
+
end = Math.max(end, at + (record.durationMs ?? 0));
|
|
183
208
|
}
|
|
184
209
|
return rows.length === 0 ? { start: 0, span: 1 } : { start, span: Math.max(1, end - start) };
|
|
185
|
-
}, [rows]);
|
|
210
|
+
}, [rows, offsetMs]);
|
|
186
211
|
const detail = selected === null ? undefined : records.find((record) => record.id === selected);
|
|
187
212
|
const sortBy = (key) => {
|
|
188
213
|
if (sort === key)
|
|
@@ -201,10 +226,14 @@ function NowityDevtoolsPanel({ recorder, onClose, floating, height = "40vh", tit
|
|
|
201
226
|
return ((0, jsx_runtime_1.jsxs)("section", { "data-testid": "nowity-devtools", "aria-label": title, style: { ...styles.root, ...(floating ? { ...styles.floating, height } : { height: "100%" }) }, children: [(0, jsx_runtime_1.jsxs)("div", { style: styles.bar, children: [(0, jsx_runtime_1.jsx)("strong", { children: title }), ["all", "subscribe", "mutation", "ws"].map((value) => ((0, jsx_runtime_1.jsx)("button", { type: "button", "data-testid": `nowity-devtools-filter-${value}`, "aria-pressed": filter === value, style: { ...styles.button, ...(filter === value ? { background: "#52525b" } : {}) }, onClick: () => setFilter(value), children: value }, value))), (0, jsx_runtime_1.jsx)("input", { type: "search", placeholder: "filter", "aria-label": "filter", "data-testid": "nowity-devtools-search", style: styles.input, value: search, onChange: (event) => setSearch(event.target.value) }), (0, jsx_runtime_1.jsx)("span", { style: { flex: 1 } }), (0, jsx_runtime_1.jsx)("button", { type: "button", style: styles.button, "data-testid": "nowity-devtools-copy", onClick: copy, children: copied ? "copied" : "copy JSON" }), (0, jsx_runtime_1.jsx)("button", { type: "button", style: styles.button, "data-testid": "nowity-devtools-clear", onClick: () => {
|
|
202
227
|
recorder.clear();
|
|
203
228
|
setSelected(null);
|
|
204
|
-
}, children: "clear" }), onClose && ((0, jsx_runtime_1.jsx)("button", { type: "button", style: styles.button, "data-testid": "nowity-devtools-close", "aria-label": "close", onClick: onClose, children: "\u00D7" }))] }), (0, jsx_runtime_1.jsxs)("div", { style: { ...styles.bar, background: "#1f1f23", gap: 14 }, "data-testid": "nowity-devtools-summary", children: [(0, jsx_runtime_1.jsx)(SummaryItem, { testId: "nowity-devtools-summary-open", label: "ws open", value: formatMs(summary.openAt) }), (0, jsx_runtime_1.jsx)(SummaryItem, { testId: "nowity-devtools-summary-welcome", label: "welcome", value: formatMs(summary.welcomeAt) }), (0, jsx_runtime_1.jsx)(SummaryItem, { testId: "nowity-devtools-summary-subscribe", label: "1st subscribe", value: formatMs(summary.firstSubscribeAt) }), (0, jsx_runtime_1.jsx)(SummaryItem, { testId: "nowity-devtools-summary-data", label: "1st data", value: formatMs(summary.firstDataAt) }), (0, jsx_runtime_1.jsx)(SummaryItem, { testId: "nowity-devtools-summary-connections", label: "sockets", value: summary.connections }), (0, jsx_runtime_1.jsx)(SummaryItem, { label: "reconnects", testId: "nowity-devtools-summary-reconnects", value: summary.reconnects }), (0, jsx_runtime_1.jsx)(SummaryItem, { label: "live", testId: "nowity-devtools-summary-live", value: `${summary.openSubscriptions} (${summary.pendingSubscriptions} pending)` }), (0, jsx_runtime_1.jsx)(SummaryItem, { label: "mutations pending", testId: "nowity-devtools-summary-mutations", value: summary.pendingMutations })
|
|
205
|
-
|
|
229
|
+
}, children: "clear" }), onClose && ((0, jsx_runtime_1.jsx)("button", { type: "button", style: styles.button, "data-testid": "nowity-devtools-close", "aria-label": "close", onClick: onClose, children: "\u00D7" }))] }), (0, jsx_runtime_1.jsxs)("div", { style: { ...styles.bar, background: "#1f1f23", gap: 14 }, "data-testid": "nowity-devtools-summary", children: [(0, jsx_runtime_1.jsx)(SummaryItem, { testId: "nowity-devtools-summary-open", label: "ws open", value: formatMs(summary.openAt) }), (0, jsx_runtime_1.jsx)(SummaryItem, { testId: "nowity-devtools-summary-welcome", label: "welcome", value: formatMs(summary.welcomeAt) }), (0, jsx_runtime_1.jsx)(SummaryItem, { testId: "nowity-devtools-summary-subscribe", label: "1st subscribe", value: formatMs(summary.firstSubscribeAt) }), (0, jsx_runtime_1.jsx)(SummaryItem, { testId: "nowity-devtools-summary-data", label: "1st data", value: formatMs(summary.firstDataAt) }), (0, jsx_runtime_1.jsx)(SummaryItem, { testId: "nowity-devtools-summary-connections", label: "sockets", value: summary.connections }), (0, jsx_runtime_1.jsx)(SummaryItem, { label: "reconnects", testId: "nowity-devtools-summary-reconnects", value: summary.reconnects }), (0, jsx_runtime_1.jsx)(SummaryItem, { label: "live", testId: "nowity-devtools-summary-live", value: `${summary.openSubscriptions} (${summary.pendingSubscriptions} pending)` }), (0, jsx_runtime_1.jsx)(SummaryItem, { label: "mutations pending", testId: "nowity-devtools-summary-mutations", value: summary.pendingMutations }), (0, jsx_runtime_1.jsx)(SummaryItem, { label: "server clock", testId: "nowity-devtools-summary-clock", value: summary.clock && summary.clock.offsetMs !== null
|
|
230
|
+
? `±${formatMs(summary.clock.uncertaintyMs)} (rtt ${formatMs(summary.clock.rttMs)}, ${summary.clock.sampleCount} samples)`
|
|
231
|
+
: "not synced" })] }), (0, jsx_runtime_1.jsxs)("div", { style: { display: "flex", flex: 1, minHeight: 0 }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { flex: 1, overflow: "auto", minWidth: 0 }, children: [(0, jsx_runtime_1.jsxs)("table", { style: { borderCollapse: "collapse", width: "100%", tableLayout: "auto" }, children: [(0, jsx_runtime_1.jsx)("thead", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [header("name", "name"), header("status", "status"), header("start", "start"), header("latency", "latency"), header("size", "size"), header("updates", "updates"), (0, jsx_runtime_1.jsx)("th", { style: { ...styles.th, width: "30%", cursor: "default" }, children: "waterfall" })] }) }), (0, jsx_runtime_1.jsx)("tbody", { children: rows.map((record) => {
|
|
232
|
+
const left = ((axisTs(record, offsetMs) - range.start) / range.span) * 100;
|
|
206
233
|
const width = Math.max(0.5, ((record.durationMs ?? 0) / range.span) * 100);
|
|
207
|
-
return ((0, jsx_runtime_1.jsxs)("tr", { "data-testid": "nowity-devtools-row", "data-type": record.type, "data-name": record.name, "data-status": record.status, onClick: () => setSelected(record.id === selected ? null : record.id), style: { cursor: "pointer", background: record.id === selected ? "#27272a" : undefined }, children: [(0, jsx_runtime_1.jsxs)("td", { style: styles.td, title: record.name, children: [(0, jsx_runtime_1.jsx)("span", { style: { color: COLORS[record.type], marginRight: 4 }, children: "\u25CF" }), record.name] }), (0, jsx_runtime_1.jsxs)("td", { style: { ...styles.td, color: STATUS_COLORS[record.status] }, "data-testid": "nowity-devtools-row-status", children: [record.status, record.meta.code ? ` (${record.meta.code})` : ""] }), (0, jsx_runtime_1.jsx)("td", { style: styles.td,
|
|
234
|
+
return ((0, jsx_runtime_1.jsxs)("tr", { "data-testid": "nowity-devtools-row", "data-type": record.type, "data-name": record.name, "data-status": record.status, "data-server-ts": record.serverTs ?? undefined, onClick: () => setSelected(record.id === selected ? null : record.id), style: { cursor: "pointer", background: record.id === selected ? "#27272a" : undefined }, children: [(0, jsx_runtime_1.jsxs)("td", { style: styles.td, title: record.name, children: [(0, jsx_runtime_1.jsx)("span", { style: { color: COLORS[record.type], marginRight: 4 }, children: "\u25CF" }), record.name] }), (0, jsx_runtime_1.jsxs)("td", { style: { ...styles.td, color: STATUS_COLORS[record.status] }, "data-testid": "nowity-devtools-row-status", children: [record.status, record.meta.code ? ` (${record.meta.code})` : ""] }), (0, jsx_runtime_1.jsx)("td", { style: styles.td, "data-testid": "nowity-devtools-row-start", title: offsetMs === null
|
|
235
|
+
? "server clock not synced"
|
|
236
|
+
: `server ${formatServerTime(axisTs(record, offsetMs))} UTC ±${formatMs(summary.clock?.uncertaintyMs)}`, children: formatMs(record.ts) }), (0, jsx_runtime_1.jsx)("td", { style: styles.td, "data-testid": "nowity-devtools-row-latency", children: formatMs(record.durationMs) }), (0, jsx_runtime_1.jsx)("td", { style: styles.td, children: formatBytes(record.bytes) }), (0, jsx_runtime_1.jsx)("td", { style: styles.td, children: record.meta.updateCount ?? "" }), (0, jsx_runtime_1.jsx)("td", { style: { ...styles.td, position: "relative", maxWidth: "none" }, children: (0, jsx_runtime_1.jsx)("div", { style: {
|
|
208
237
|
position: "absolute",
|
|
209
238
|
top: 4,
|
|
210
239
|
bottom: 4,
|
|
@@ -215,14 +244,31 @@ function NowityDevtoolsPanel({ recorder, onClose, floating, height = "40vh", tit
|
|
|
215
244
|
opacity: record.status === "pending" ? 0.4 : 0.85,
|
|
216
245
|
borderRadius: 2,
|
|
217
246
|
} }) })] }, record.id));
|
|
218
|
-
}) })] }), rows.length === 0 && ((0, jsx_runtime_1.jsx)("div", { style: { padding: 12, color: "#a1a1aa" }, "data-testid": "nowity-devtools-empty", children: "nothing recorded" }))] }), detail && ((0, jsx_runtime_1.
|
|
247
|
+
}) })] }), rows.length === 0 && ((0, jsx_runtime_1.jsx)("div", { style: { padding: 12, color: "#a1a1aa" }, "data-testid": "nowity-devtools-empty", children: "nothing recorded" }))] }), detail && ((0, jsx_runtime_1.jsxs)("div", { "data-testid": "nowity-devtools-detail", style: {
|
|
219
248
|
margin: 0,
|
|
220
249
|
width: "34%",
|
|
221
250
|
overflow: "auto",
|
|
222
251
|
padding: 8,
|
|
223
252
|
borderLeft: "1px solid #3f3f46",
|
|
224
253
|
background: "#09090b",
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
254
|
+
}, children: [(0, jsx_runtime_1.jsx)(Phases, { phases: (0, devtools_1.mutationPhases)(detail) }), (0, jsx_runtime_1.jsx)("pre", { style: { margin: 0, whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: JSON.stringify(detail, null, 2) })] }))] })] }));
|
|
255
|
+
}
|
|
256
|
+
const PHASE_COLORS = {
|
|
257
|
+
client: "#f5a524",
|
|
258
|
+
server: "#4f9cf9",
|
|
259
|
+
database: "#9b8afb",
|
|
260
|
+
};
|
|
261
|
+
/** A mutation's steps on the server's clock, from sending it. */
|
|
262
|
+
function Phases({ phases }) {
|
|
263
|
+
if (phases.length === 0)
|
|
264
|
+
return null;
|
|
265
|
+
const end = Math.max(1, ...phases.map((phase) => phase.offsetMs));
|
|
266
|
+
return ((0, jsx_runtime_1.jsx)("table", { "data-testid": "nowity-devtools-phases", style: { borderCollapse: "collapse", width: "100%", marginBottom: 8 }, children: (0, jsx_runtime_1.jsx)("tbody", { children: phases.map((phase) => ((0, jsx_runtime_1.jsxs)("tr", { "data-testid": "nowity-devtools-phase", "data-phase": phase.name, "data-clock": phase.clock, children: [(0, jsx_runtime_1.jsx)("td", { style: { ...styles.td, color: PHASE_COLORS[phase.clock] }, children: phase.name }), (0, jsx_runtime_1.jsxs)("td", { style: styles.td, title: `${formatServerTime(phase.serverTs)} UTC (${phase.clock} clock)`, children: ["+", formatMs(phase.offsetMs), phase.uncertaintyMs !== null ? ` ±${formatMs(phase.uncertaintyMs)}` : ""] }), (0, jsx_runtime_1.jsx)("td", { style: { ...styles.td, position: "relative", width: "50%", maxWidth: "none" }, children: (0, jsx_runtime_1.jsx)("div", { style: {
|
|
267
|
+
position: "absolute",
|
|
268
|
+
top: 5,
|
|
269
|
+
bottom: 5,
|
|
270
|
+
left: `${Math.max(0, Math.min(100, (phase.offsetMs / end) * 100))}%`,
|
|
271
|
+
width: 3,
|
|
272
|
+
background: PHASE_COLORS[phase.clock],
|
|
273
|
+
} }) })] }, phase.name))) }) }));
|
|
228
274
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outbox-change-source.d.ts","sourceRoot":"","sources":["../../../src/server/change-source/outbox-change-source.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,IAAI,CAAC;AAE3C,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,WAAW,yBAAyB;IACtC,IAAI,EAAE,IAAI,CAAC;IACX,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;;;;OAQG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yEAAyE;IACzE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,UAAU,SAAS;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;IACtB,EAAE,EAAE,GAAG,CAAC;IACR,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC;IACnB,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"outbox-change-source.d.ts","sourceRoot":"","sources":["../../../src/server/change-source/outbox-change-source.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,IAAI,CAAC;AAE3C,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,WAAW,yBAAyB;IACtC,IAAI,EAAE,IAAI,CAAC;IACX,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;;;;OAQG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,eAAe,CAAC,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AC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,KAAK,CAA+B;IAC5C,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAA8B;IAC9C,sEAAsE;IACtE,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,SAAS,CAAK;gBAEV,IAAI,EAAE,yBAAyB;IAYrC,aAAa,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAWrD,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BzD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB3B;;;;;;;;;OASG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAc5B,OAAO,CAAC,IAAI;YAKE,SAAS;IA2BvB,8DAA8D;YAChD,aAAa;IAS3B;;;;;;OAMG;IACG,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;YAOhB,KAAK;CA6BtB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,CAS/E;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,gBAAgB,EAAE,CA0BxE"}
|
|
@@ -5,7 +5,7 @@ exports.mergeTransactions = mergeTransactions;
|
|
|
5
5
|
exports.groupByTransaction = groupByTransaction;
|
|
6
6
|
const node_crypto_1 = require("node:crypto");
|
|
7
7
|
const normalize_1 = require("../../core/normalize");
|
|
8
|
-
const SELECT_COLUMNS = `seq::text AS seq, xid::text AS xid, tbl, op, pk, before, after, client_id, mutation_id::text AS mutation_id`;
|
|
8
|
+
const SELECT_COLUMNS = `seq::text AS seq, xid::text AS xid, tbl, op, pk, before, after, client_id, mutation_id::text AS mutation_id, (extract(epoch FROM created_at) * 1000)::float8 AS written_ms`;
|
|
9
9
|
/**
|
|
10
10
|
* Change source built on an outbox table filled by triggers, woken by
|
|
11
11
|
* LISTEN/NOTIFY.
|
|
@@ -253,6 +253,7 @@ function groupByTransaction(rows) {
|
|
|
253
253
|
// always whole here — a row leaving a live query's filter is visible
|
|
254
254
|
// without any per-table configuration.
|
|
255
255
|
beforeComplete: true,
|
|
256
|
+
...(row.written_ms !== null && row.written_ms !== undefined ? { writtenAt: Number(row.written_ms) } : {}),
|
|
256
257
|
});
|
|
257
258
|
}
|
|
258
259
|
return batches;
|
|
@@ -118,6 +118,11 @@ export declare class EngineSession {
|
|
|
118
118
|
readonly connectionId: `${string}-${string}-${string}-${string}-${string}`;
|
|
119
119
|
/** What the client last said it is looking at (`setContext`). */
|
|
120
120
|
context: PresenceContext | null;
|
|
121
|
+
/**
|
|
122
|
+
* Send this connection where its changes spent their time (`TxTiming`).
|
|
123
|
+
* Set by the socket front end from its `timing` option; off by default.
|
|
124
|
+
*/
|
|
125
|
+
timing: boolean;
|
|
121
126
|
constructor(info: SessionInfo, send: (msg: ServerMessage) => void);
|
|
122
127
|
}
|
|
123
128
|
/**
|
|
@@ -136,6 +141,10 @@ export interface MutationOutcome {
|
|
|
136
141
|
lastMutationId: number;
|
|
137
142
|
/** What the mutator returned. Absent for a replayed mutation. */
|
|
138
143
|
value?: unknown;
|
|
144
|
+
/** Server clock (epoch ms) when its turn came — the mutations before it were done. */
|
|
145
|
+
startedAt?: number;
|
|
146
|
+
/** Server clock when its transaction committed. Absent when it was rolled back. */
|
|
147
|
+
committedAt?: number;
|
|
139
148
|
}
|
|
140
149
|
/**
|
|
141
150
|
* The sync engine: turns change events into per-subscription patches.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-engine.d.ts","sourceRoot":"","sources":["../../src/server/sync-engine.ts"],"names":[],"mappings":"AAIA,OAAO,EAEH,KAAK,aAAa,EAElB,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"sync-engine.d.ts","sourceRoot":"","sources":["../../src/server/sync-eng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AI,EAAE,OAAO,GACd,OAAO,CAAC,eAAe,CAAC;YAQb,eAAe;IAqI7B;;;;;;;OAOG;YACW,SAAS;YAMT,SAAS;YAgBT,kBAAkB;YAQlB,mBAAmB;CAiBpC"}
|
|
@@ -35,6 +35,11 @@ class EngineSession {
|
|
|
35
35
|
this.connectionId = (0, node_crypto_1.randomUUID)();
|
|
36
36
|
/** What the client last said it is looking at (`setContext`). */
|
|
37
37
|
this.context = null;
|
|
38
|
+
/**
|
|
39
|
+
* Send this connection where its changes spent their time (`TxTiming`).
|
|
40
|
+
* Set by the socket front end from its `timing` option; off by default.
|
|
41
|
+
*/
|
|
42
|
+
this.timing = false;
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
45
|
exports.EngineSession = EngineSession;
|
|
@@ -106,7 +111,11 @@ class SyncEngine {
|
|
|
106
111
|
return;
|
|
107
112
|
this.started = true;
|
|
108
113
|
const from = await this.opts.snapshots.withSnapshot((snap) => this.opts.source.startPosition(snap));
|
|
109
|
-
await this.opts.source.start(from, (batch) =>
|
|
114
|
+
await this.opts.source.start(from, (batch) => {
|
|
115
|
+
// Taken before the queue: waiting behind other work is part of the push.
|
|
116
|
+
const readAt = Date.now();
|
|
117
|
+
return this.run(() => this.timedBatch(batch, readAt));
|
|
118
|
+
});
|
|
110
119
|
}
|
|
111
120
|
async stop() {
|
|
112
121
|
if (!this.started)
|
|
@@ -331,16 +340,17 @@ class SyncEngine {
|
|
|
331
340
|
}
|
|
332
341
|
// ------------------------------------------------------------------ change fan-out
|
|
333
342
|
/** `handleBatch`, with the one number worth watching taken around it. */
|
|
334
|
-
async timedBatch(batch) {
|
|
343
|
+
async timedBatch(batch, readAt = Date.now()) {
|
|
335
344
|
const started = process.hrtime.bigint();
|
|
336
345
|
try {
|
|
337
|
-
await this.handleBatch(batch);
|
|
346
|
+
await this.handleBatch(batch, readAt);
|
|
338
347
|
}
|
|
339
348
|
finally {
|
|
340
349
|
this.stats.fanOutMs += Number(process.hrtime.bigint() - started) / 1e6;
|
|
341
350
|
}
|
|
342
351
|
}
|
|
343
|
-
async handleBatch(batch) {
|
|
352
|
+
async handleBatch(batch, readAt) {
|
|
353
|
+
const fanOutAt = Date.now();
|
|
344
354
|
const invalidatedScopes = new Set();
|
|
345
355
|
let revalidateEverything = false;
|
|
346
356
|
for (const event of batch.events) {
|
|
@@ -480,6 +490,7 @@ class SyncEngine {
|
|
|
480
490
|
t: "tx",
|
|
481
491
|
position: batch.position,
|
|
482
492
|
lastMutationId,
|
|
493
|
+
...(session.timing ? { timing: txTiming(batch, session, readAt, fanOutAt) } : {}),
|
|
483
494
|
patches,
|
|
484
495
|
...(snapshots.length ? { snapshots } : {}),
|
|
485
496
|
...(revoked.length ? { revoked } : {}),
|
|
@@ -740,6 +751,7 @@ class SyncEngine {
|
|
|
740
751
|
async executeMutation(session, mutationId, name, args) {
|
|
741
752
|
const clientId = session.info.clientId;
|
|
742
753
|
const committed = [];
|
|
754
|
+
const startedAt = Date.now();
|
|
743
755
|
try {
|
|
744
756
|
const def = this.opts.mutators.get(name);
|
|
745
757
|
const outcome = await this.opts.writes.withWrite(async (w) => {
|
|
@@ -761,7 +773,7 @@ class SyncEngine {
|
|
|
761
773
|
// Idempotency: a mutation resent after a reconnect must not be
|
|
762
774
|
// applied twice.
|
|
763
775
|
if (mutationId <= last)
|
|
764
|
-
return { ok: true, lastMutationId: last };
|
|
776
|
+
return { ok: true, lastMutationId: last, replayed: true };
|
|
765
777
|
if (mutationId !== last + 1) {
|
|
766
778
|
// The one place a client id shared by two connections is
|
|
767
779
|
// caught for certain. `openSession` reports the collision
|
|
@@ -789,6 +801,8 @@ class SyncEngine {
|
|
|
789
801
|
WHERE client_id = $1`, [clientId, mutationId]);
|
|
790
802
|
return { ok: true, lastMutationId: mutationId, value };
|
|
791
803
|
});
|
|
804
|
+
// A replay committed nothing; a commit time would be fiction.
|
|
805
|
+
const committedAt = outcome.replayed ? undefined : Date.now();
|
|
792
806
|
for (const fn of committed) {
|
|
793
807
|
try {
|
|
794
808
|
fn();
|
|
@@ -797,7 +811,8 @@ class SyncEngine {
|
|
|
797
811
|
this.onError(err);
|
|
798
812
|
}
|
|
799
813
|
}
|
|
800
|
-
|
|
814
|
+
const { replayed: _replayed, ...rest } = outcome;
|
|
815
|
+
return { ...rest, startedAt, ...(committedAt !== undefined ? { committedAt } : {}) };
|
|
801
816
|
}
|
|
802
817
|
catch (err) {
|
|
803
818
|
// A refused mutation is a normal outcome of the write path, not an
|
|
@@ -811,7 +826,7 @@ class SyncEngine {
|
|
|
811
826
|
// resend into an acknowledged no-op, which is the very write loss
|
|
812
827
|
// this check exists to prevent.
|
|
813
828
|
if (err instanceof ClientIdTaken) {
|
|
814
|
-
return { ok: false, error: err.message, lastMutationId: mutationId - 1 };
|
|
829
|
+
return { ok: false, error: err.message, lastMutationId: mutationId - 1, startedAt };
|
|
815
830
|
}
|
|
816
831
|
// The write is rolled back, but the mutation id is burned in its own
|
|
817
832
|
// transaction. Otherwise the client would keep a rejected mutation in
|
|
@@ -829,6 +844,7 @@ class SyncEngine {
|
|
|
829
844
|
ok: false,
|
|
830
845
|
error: err.message,
|
|
831
846
|
lastMutationId: mutationId,
|
|
847
|
+
startedAt,
|
|
832
848
|
};
|
|
833
849
|
}
|
|
834
850
|
}
|
|
@@ -910,3 +926,17 @@ function sameIds(a, b) {
|
|
|
910
926
|
}
|
|
911
927
|
return true;
|
|
912
928
|
}
|
|
929
|
+
/**
|
|
930
|
+
* The server's side of one push, for a connection that gets timing. `sentAt`
|
|
931
|
+
* is stamped by the socket as the message leaves.
|
|
932
|
+
*/
|
|
933
|
+
function txTiming(batch, session, readAt, fanOutAt) {
|
|
934
|
+
let writtenAt;
|
|
935
|
+
for (const event of batch.events) {
|
|
936
|
+
if (event.writtenAt === undefined || event.clientId !== session.info.clientId)
|
|
937
|
+
continue;
|
|
938
|
+
if (writtenAt === undefined || event.writtenAt < writtenAt)
|
|
939
|
+
writtenAt = event.writtenAt;
|
|
940
|
+
}
|
|
941
|
+
return { ...(writtenAt !== undefined ? { writtenAt } : {}), readAt, fanOutAt, sentAt: fanOutAt };
|
|
942
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as http from "http";
|
|
2
|
+
import type { SessionInfo } from "./query";
|
|
2
3
|
import type { SyncEngine } from "./sync-engine";
|
|
3
4
|
export interface AuthRequest {
|
|
4
5
|
url: string | undefined;
|
|
@@ -42,6 +43,17 @@ export interface NowitySyncServerOptions {
|
|
|
42
43
|
intervalMs?: number;
|
|
43
44
|
maxMissed?: number;
|
|
44
45
|
} | false;
|
|
46
|
+
/**
|
|
47
|
+
* Send a connection where its writes spent their time on the server —
|
|
48
|
+
* received, started, committed, read from the outbox, pushed (`timing` on
|
|
49
|
+
* `mutation-result` and `tx`), for a developer panel to lay next to the
|
|
50
|
+
* client's own times.
|
|
51
|
+
*
|
|
52
|
+
* Off unless set. A function decides per connection, once, at its hello —
|
|
53
|
+
* the place to say "admins only" from the database rather than from
|
|
54
|
+
* anything the client claims. Its failure means off.
|
|
55
|
+
*/
|
|
56
|
+
timing?: boolean | ((session: SessionInfo) => boolean | Promise<boolean>);
|
|
45
57
|
onError?: (err: Error) => void;
|
|
46
58
|
}
|
|
47
59
|
/** WebSocket front end for {@link SyncEngine}. */
|
|
@@ -63,6 +75,12 @@ export declare class NowitySyncServer {
|
|
|
63
75
|
/** Pings sent since the socket last proved it is alive. */
|
|
64
76
|
private readonly missed;
|
|
65
77
|
private heartbeatTimer;
|
|
78
|
+
/** When this socket's last hello arrived, for the clock in the welcome. */
|
|
79
|
+
private readonly helloAt;
|
|
80
|
+
/** Sockets that get timing (see {@link NowitySyncServerOptions.timing}). */
|
|
81
|
+
private readonly timed;
|
|
82
|
+
/** Pongs sent in the current window, per socket. */
|
|
83
|
+
private readonly pings;
|
|
66
84
|
constructor(opts: NowitySyncServerOptions);
|
|
67
85
|
/** Start listening; resolves with the actual port. */
|
|
68
86
|
listen(): Promise<number>;
|
|
@@ -73,6 +91,8 @@ export declare class NowitySyncServer {
|
|
|
73
91
|
private startHeartbeat;
|
|
74
92
|
private handleConnection;
|
|
75
93
|
private handleMessage;
|
|
94
|
+
private allowPing;
|
|
95
|
+
private timingFor;
|
|
76
96
|
private sendTo;
|
|
77
97
|
}
|
|
78
98
|
//# sourceMappingURL=ws-server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws-server.d.ts","sourceRoot":"","sources":["../../src/server/ws-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"ws-server.d.ts","sourceRoot":"","sources":["../../src/server/ws-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAI7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAiB,UAAU,EAAE,MAAM,eAAe,CAAC;AAE/D,MAAM,WAAW,WAAW;IACxB,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAAC;CACrC;AAED,yEAAyE;AACzE,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,uBAAuB;IACpC,MAAM,EAAE,UAAU,CAAC;IACnB;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,UAAU,GAAG,IAAI,CAAC;IACpF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB;;;;;;;;;;;O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