nowity 1.9.0 → 1.11.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 (38) hide show
  1. package/README.md +124 -16
  2. package/dist/client/clock.d.ts +98 -0
  3. package/dist/client/clock.d.ts.map +1 -0
  4. package/dist/client/clock.js +154 -0
  5. package/dist/client/devtools.d.ts +64 -1
  6. package/dist/client/devtools.d.ts.map +1 -1
  7. package/dist/client/devtools.js +134 -22
  8. package/dist/client/nowity-client.d.ts +38 -0
  9. package/dist/client/nowity-client.d.ts.map +1 -1
  10. package/dist/client/nowity-client.js +93 -3
  11. package/dist/client.d.ts +3 -0
  12. package/dist/client.d.ts.map +1 -1
  13. package/dist/client.js +4 -1
  14. package/dist/core/protocol.d.ts +70 -2
  15. package/dist/core/protocol.d.ts.map +1 -1
  16. package/dist/core/types.d.ts +13 -0
  17. package/dist/core/types.d.ts.map +1 -1
  18. package/dist/devtools.d.ts +14 -1
  19. package/dist/devtools.d.ts.map +1 -1
  20. package/dist/devtools.js +64 -18
  21. package/dist/server/api/configure.d.ts +5 -1
  22. package/dist/server/api/configure.d.ts.map +1 -1
  23. package/dist/server/api/configure.js +2 -0
  24. package/dist/server/change-source/change-source.d.ts +23 -5
  25. package/dist/server/change-source/change-source.d.ts.map +1 -1
  26. package/dist/server/change-source/outbox-change-source.d.ts +47 -12
  27. package/dist/server/change-source/outbox-change-source.d.ts.map +1 -1
  28. package/dist/server/change-source/outbox-change-source.js +154 -65
  29. package/dist/server/change-source/pg-snapshot.d.ts +25 -0
  30. package/dist/server/change-source/pg-snapshot.d.ts.map +1 -0
  31. package/dist/server/change-source/pg-snapshot.js +43 -0
  32. package/dist/server/sync-engine.d.ts +119 -0
  33. package/dist/server/sync-engine.d.ts.map +1 -1
  34. package/dist/server/sync-engine.js +445 -117
  35. package/dist/server/ws-server.d.ts +28 -0
  36. package/dist/server/ws-server.d.ts.map +1 -1
  37. package/dist/server/ws-server.js +112 -6
  38. package/package.json +1 -1
@@ -51,7 +51,20 @@ export interface ClientContext {
51
51
  t: "context";
52
52
  context: Record<string, unknown> | null;
53
53
  }
54
- export type ClientMessage = ClientHello | ClientSubscribe | ClientUnsubscribe | ClientMutate | ClientContext;
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,Q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oGAAoG;AACpG,MAAM,WAAW,UAAU;IACvB,CAAC,EAAE,MAAM,CAAC;IACV,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,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"}
@@ -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.
@@ -86,6 +92,13 @@ export interface TransactionBatch {
86
92
  * means one.
87
93
  */
88
94
  transactions?: number;
95
+ /**
96
+ * Ids of every transaction in the batch, when the source knows them (the
97
+ * outbox does). Lets the engine tell that a subscription it has already
98
+ * recomputed after these transactions committed needs nothing from the
99
+ * batch. Absent means "unknown", which only ever costs a recomputation.
100
+ */
101
+ xids?: string[];
89
102
  events: ChangeEvent[];
90
103
  }
91
104
  /** Field-level upsert for a single entity instance. */
@@ -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,MA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EAAqE;IACrE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,0EAA0E;IAC1E,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;;;;;;;;;OASG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC7B;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,WAAW,EAAE,CAAC;CACzB;AAED,uDAAuD;AACvD,MAAM,WAAW,QAAQ;IACrB,EAAE,EAAE,QAAQ,CAAC;IACb,sEAAsE;IACtE,MAAM,EAAE,GAAG,CAAC;IACZ,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,yEAAyE;AACzE,MAAM,WAAW,OAAO;IACpB,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,MAAM,EAAE,QAAQ,EAAE,CAAC;CACtB;AAED,kEAAkE;AAClE,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAElD"}
@@ -1,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
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"devtools.d.ts","sourceRoot":"","sources":["../src/devtools.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EACR,cAAc,EACd,kBAAkB,EAGlB,cAAc,EACjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACH,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,oBAAoB,EACpB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,cAAc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,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
- var devtools_1 = require("./client/devtools");
24
- Object.defineProperty(exports, "NowityDevtools", { enumerable: true, get: function () { return devtools_1.NowityDevtools; } });
25
- Object.defineProperty(exports, "maskArgs", { enumerable: true, get: function () { return devtools_1.maskArgs; } });
26
- Object.defineProperty(exports, "byteSize", { enumerable: true, get: function () { return devtools_1.byteSize; } });
27
- Object.defineProperty(exports, "MASKED", { enumerable: true, get: function () { return devtools_1.MASKED; } });
28
- Object.defineProperty(exports, "DEFAULT_ALLOWED_KEYS", { enumerable: true, get: function () { return devtools_1.DEFAULT_ALLOWED_KEYS; } });
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 = 0;
203
+ let end = Number.NEGATIVE_INFINITY;
180
204
  for (const record of rows) {
181
- start = Math.min(start, record.ts);
182
- end = Math.max(end, record.ts + (record.durationMs ?? 0));
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 })] }), (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) => {
205
- const left = ((record.ts - range.start) / range.span) * 100;
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, 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: {
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.jsx)("pre", { "data-testid": "nowity-devtools-detail", style: {
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
- whiteSpace: "pre-wrap",
226
- wordBreak: "break-word",
227
- }, children: JSON.stringify(detail, null, 2) }))] })] }));
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,5 +1,5 @@
1
1
  import type { ChangeSource } from "../change-source/change-source";
2
- import { SyncEngine } from "../sync-engine";
2
+ import { SyncEngine, type SyncEngineOptions } from "../sync-engine";
3
3
  import { NowitySyncServer, type NowitySyncServerOptions } from "../ws-server";
4
4
  import { PresenceTracker, type PresenceOptions } from "../presence";
5
5
  import { SchedulerWorker, type SchedulerOptions } from "../scheduler";
@@ -22,6 +22,10 @@ export interface NowityServerConfig extends NowityRuntimeConfig {
22
22
  syncServer?: Omit<NowitySyncServerOptions, "engine">;
23
23
  /** See {@link SyncEngineOptions.narrowInvalidation}. On unless set. */
24
24
  narrowInvalidation?: boolean;
25
+ /** See {@link SyncEngineOptions.ackWithState}. On unless `false`. */
26
+ ackWithState?: boolean;
27
+ /** See {@link SyncEngineOptions.fanOut}. */
28
+ fanOut?: SyncEngineOptions["fanOut"];
25
29
  /**
26
30
  * Record who is connected, so endpoints can read it through the injectable
27
31
  * {@link Presence} and react to users going offline (`Presence.onOffline`).
@@ -1 +1 @@
1
- {"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../../../src/server/api/configure.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,EAAE,UAAU,EAA0B,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,KAAK,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;A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AAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,2CAA2C;AAC3C,eAAO,MAAM,yBAAyB,QAAS,CAAC;AAEhD,MAAM,WAAW,YAAa,SAAQ,aAAa;IAC/C,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,gBAAgB,CAAC;IACzB,sDAAsD;IACtD,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IACjC,2DAA2D;IAC3D,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IAClC,sEAAsE;IACtE,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAoBD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CA+D3E"}
@@ -57,6 +57,8 @@ function createNowityServer(config) {
57
57
  derived: runtime.api.derived,
58
58
  api: { contracts: runtime.api.manifest.contracts, entities: runtime.api.entities },
59
59
  narrowInvalidation: config.narrowInvalidation,
60
+ ackWithState: config.ackWithState,
61
+ fanOut: config.fanOut,
60
62
  ...(presence ? { presence } : {}),
61
63
  onError: config.onError,
62
64
  });
@@ -1,4 +1,4 @@
1
- import type { TransactionBatch } from "../../core/types";
1
+ import type { ChangeEvent, TransactionBatch } from "../../core/types";
2
2
  import type { SnapshotContext } from "../db";
3
3
  export type BatchHandler = (batch: TransactionBatch) => Promise<void>;
4
4
  /**
@@ -9,10 +9,13 @@ export type BatchHandler = (batch: TransactionBatch) => Promise<void>;
9
9
  * WAL can be swapped in later without touching the sync engine.
10
10
  *
11
11
  * Contract every implementation must honour:
12
- * 1. `handler` is called with whole database transactions in commit order —
13
- * one per call, or several committed ones together (the outbox does that
14
- * per read, so the engine takes one snapshot for all of them). A
15
- * transaction is never split across calls.
12
+ * 1. `handler` is called with whole, committed database transactions — one
13
+ * per call, or several together (the outbox does that per read, so the
14
+ * engine takes one snapshot for all of them). A transaction is never split
15
+ * across calls, and one delivered in a later call committed after the ones
16
+ * of an earlier call. Within one call the order is the source's (the
17
+ * outbox orders by xid); the engine recomputes from the database, so it
18
+ * does not depend on it.
16
19
  * 2. `handler` is awaited; no further batch is delivered until it resolves.
17
20
  * 3. Delivery is at-least-once. Duplicates are allowed — the engine recomputes
18
21
  * queries from the database, so replaying a batch produces an empty diff.
@@ -34,6 +37,21 @@ export interface ChangeSource {
34
37
  * one.
35
38
  */
36
39
  readonly attributesWrites?: boolean;
40
+ /**
41
+ * How a mutation can learn, inside its own transaction, which change
42
+ * events it produced — so the engine can recompute the writer's own
43
+ * subscriptions right after the commit and send them with the result,
44
+ * instead of after the round trip through the stream.
45
+ *
46
+ * `sql` is a scalar expression evaluated in the mutation's transaction
47
+ * after its writes; `parse` turns its value into events. Absent, the
48
+ * writer gets its data through the stream like everyone else (logical
49
+ * replication cannot do this: the WAL is only readable after commit).
50
+ */
51
+ readonly ownWrites?: {
52
+ readonly sql: string;
53
+ parse(value: unknown, clientId: string, mutationId: number): ChangeEvent[];
54
+ };
37
55
  startPosition(snap: SnapshotContext): Promise<string>;
38
56
  start(from: string, handler: BatchHandler): Promise<void>;
39
57
  stop(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"change-source.d.ts","sourceRoot":"","sources":["../../../src/server/change-source/change-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAE7C,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEtE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;;;;;;;O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AAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB,2EAA2E;IAC3E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
@@ -51,6 +51,7 @@ interface OutboxRow {
51
51
  after: Row | null;
52
52
  client_id: string | null;
53
53
  mutation_id: string | null;
54
+ written_ms?: number | string | null;
54
55
  }
55
56
  /**
56
57
  * Change source built on an outbox table filled by triggers, woken by
@@ -59,20 +60,25 @@ interface OutboxRow {
59
60
  * The interesting part is the read cursor. `seq` alone is not usable: sequence
60
61
  * values are assigned before commit, so ordering by `seq` can walk past a row
61
62
  * whose transaction commits later, and that row would then be filtered out by
62
- * `seq > cursor` forever. Instead the reader only consumes rows whose `xid` is
63
- * strictly below `pg_snapshot_xmin(pg_current_snapshot())` — the oldest
64
- * transaction id still in flight. That set has two properties we need:
63
+ * `seq > cursor` forever. A single `xid` cursor has the same hole for the same
64
+ * reason — xids are handed out at the first write, not at commit.
65
65
  *
66
- * - every transaction in it is committed (nothing below xmin can still be
67
- * running), and no new row can ever appear with such an `xid`;
68
- * - it grows as a *prefix* of the `xid` order, so a single `xid` cursor is a
69
- * complete, gap-free bookmark.
66
+ * The cursor is therefore a *snapshot* (`pg_current_snapshot()`): "every
67
+ * transaction this snapshot sees has been delivered". A read takes the
68
+ * statement's own snapshot and returns the rows of exactly the transactions it
69
+ * sees and the cursor did not. Every transaction becomes visible in exactly one
70
+ * such interval, so nothing is skipped and nothing is read twice, and the new
71
+ * snapshot becomes the cursor.
70
72
  *
71
- * Cost of that guarantee: one long-running *write* transaction anywhere in the
72
- * database stalls the stream until it finishes (read-only transactions do not,
73
- * they never get an xid). For an application with short transactions this is
74
- * fine; if it ever stops being fine, that is the moment to switch to the WAL
75
- * source, which gets true commit ordering from the server.
73
+ * Up to 1.10 the cursor was the transaction horizon (`xmin`) instead, and one
74
+ * long-running *write* transaction anywhere in the database — a scheduler job,
75
+ * a migration, a `psql` session left open — held every change behind it until
76
+ * it finished. With a snapshot cursor a transaction still in flight is simply
77
+ * not seen yet; whatever commits around it flows on, and its own rows arrive
78
+ * in the read after its commit. What such a transaction still costs is index
79
+ * range: the read scans from the oldest in-flight xid of the cursor, so a very
80
+ * long one makes each read walk the rows written since it began (filtered out
81
+ * by visibility, never delivered again).
76
82
  */
77
83
  export declare class OutboxChangeSource implements ChangeSource {
78
84
  readonly name = "outbox";
@@ -87,9 +93,21 @@ export declare class OutboxChangeSource implements ChangeSource {
87
93
  readonly consumerId: string;
88
94
  private readonly pruneIntervalMs;
89
95
  private readonly pruneStaleAfter;
96
+ /** Every transaction this snapshot sees has been delivered. */
90
97
  private cursor;
98
+ /** See {@link hold}. */
99
+ private held;
91
100
  /** Last cursor written to `nowity_consumer`; avoids a write per idle lap. */
92
101
  private publishedCursor;
102
+ /**
103
+ * What the engine may fold into a mutation's own transaction to learn what
104
+ * it wrote: the capture trigger has already put it here, under this
105
+ * transaction's xid.
106
+ */
107
+ readonly ownWrites: {
108
+ sql: string;
109
+ parse: (value: unknown, clientId: string, mutationId: number) => ChangeEvent[];
110
+ };
93
111
  private handler;
94
112
  private listener;
95
113
  private timer;
@@ -114,6 +132,13 @@ export declare class OutboxChangeSource implements ChangeSource {
114
132
  * early.
115
133
  */
116
134
  drain(): Promise<void>;
135
+ /**
136
+ * Stop reading until {@link release}, for tests that need several
137
+ * transactions in one read. Laps still run — `drain()` resolves — they
138
+ * just read nothing.
139
+ */
140
+ hold(): void;
141
+ release(): Promise<void>;
117
142
  private wake;
118
143
  private drainLoop;
119
144
  /** Tell retention where this reader is, when it has moved. */
@@ -126,7 +151,17 @@ export declare class OutboxChangeSource implements ChangeSource {
126
151
  * rather than each other's.
127
152
  */
128
153
  prune(): Promise<number>;
154
+ /**
155
+ * One page of a round: rows of transactions `target` sees and the cursor
156
+ * does not, whole transactions only, xids above `after`.
157
+ *
158
+ * The first page of a round has no target yet and takes its own statement
159
+ * snapshot as one, so the rows and the snapshot that becomes the cursor
160
+ * cannot disagree. Later pages read in newer statement snapshots and keep
161
+ * to the target explicitly.
162
+ */
129
163
  private fetch;
164
+ private page;
130
165
  }
131
166
  /**
132
167
  * Whole transactions of one read as one batch, in commit order.
@@ -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;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;;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,CAyBxE"}
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;AAGlE,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,SAA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