nowity 1.7.0 → 1.9.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 +63 -6
- package/dist/client/devtools.d.ts +218 -0
- package/dist/client/devtools.d.ts.map +1 -0
- package/dist/client/devtools.js +444 -0
- package/dist/client/nowity-client.d.ts +31 -0
- package/dist/client/nowity-client.d.ts.map +1 -1
- package/dist/client/nowity-client.js +93 -5
- package/dist/client/transport.d.ts +2 -1
- package/dist/client/transport.d.ts.map +1 -1
- package/dist/client/ws-transport.d.ts.map +1 -1
- package/dist/client/ws-transport.js +2 -1
- package/dist/client.d.ts +5 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/core/types.d.ts +9 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/devtools.d.ts +25 -0
- package/dist/devtools.d.ts.map +1 -0
- package/dist/devtools.js +228 -0
- package/dist/server/api/runtime.d.ts +16 -0
- package/dist/server/api/runtime.d.ts.map +1 -1
- package/dist/server/api/runtime.js +2 -1
- package/dist/server/change-source/change-source.d.ts +4 -2
- package/dist/server/change-source/change-source.d.ts.map +1 -1
- package/dist/server/change-source/outbox-change-source.d.ts +35 -0
- package/dist/server/change-source/outbox-change-source.d.ts.map +1 -1
- package/dist/server/change-source/outbox-change-source.js +23 -1
- package/dist/server/sync-engine.d.ts +6 -1
- package/dist/server/sync-engine.d.ts.map +1 -1
- package/dist/server/sync-engine.js +7 -2
- package/package.json +5 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Pool } from "pg";
|
|
2
|
+
import type { ChangeEvent, Row, TransactionBatch } from "../../core/types";
|
|
2
3
|
import type { SnapshotContext } from "../db";
|
|
3
4
|
import type { BatchHandler, ChangeSource } from "./change-source";
|
|
4
5
|
export interface OutboxChangeSourceOptions {
|
|
@@ -9,6 +10,18 @@ export interface OutboxChangeSourceOptions {
|
|
|
9
10
|
pollIntervalMs?: number;
|
|
10
11
|
/** Max rows fetched per round-trip (transactions are never split). */
|
|
11
12
|
batchSize?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Hand every whole transaction of one read to the engine as a single
|
|
15
|
+
* batch, so the engine opens one snapshot per read instead of one per
|
|
16
|
+
* application transaction.
|
|
17
|
+
*
|
|
18
|
+
* On unless `false`. Each transaction in the read has committed before the
|
|
19
|
+
* snapshot opens, so a client still never sees half of one; what it no
|
|
20
|
+
* longer sees is the states *between* them, which a later snapshot would
|
|
21
|
+
* have overwritten anyway. Under load that is the difference between a
|
|
22
|
+
* read transaction per write and a few per second.
|
|
23
|
+
*/
|
|
24
|
+
coalesce?: boolean;
|
|
12
25
|
/**
|
|
13
26
|
* Identity of this reader in `nowity_consumer`, for retention.
|
|
14
27
|
*
|
|
@@ -28,6 +41,17 @@ export interface OutboxChangeSourceOptions {
|
|
|
28
41
|
pruneStaleAfter?: string;
|
|
29
42
|
onError?: (err: Error) => void;
|
|
30
43
|
}
|
|
44
|
+
interface OutboxRow {
|
|
45
|
+
seq: string;
|
|
46
|
+
xid: string;
|
|
47
|
+
tbl: string;
|
|
48
|
+
op: ChangeEvent["op"];
|
|
49
|
+
pk: Row;
|
|
50
|
+
before: Row | null;
|
|
51
|
+
after: Row | null;
|
|
52
|
+
client_id: string | null;
|
|
53
|
+
mutation_id: string | null;
|
|
54
|
+
}
|
|
31
55
|
/**
|
|
32
56
|
* Change source built on an outbox table filled by triggers, woken by
|
|
33
57
|
* LISTEN/NOTIFY.
|
|
@@ -58,6 +82,7 @@ export declare class OutboxChangeSource implements ChangeSource {
|
|
|
58
82
|
private readonly channel;
|
|
59
83
|
private readonly pollIntervalMs;
|
|
60
84
|
private readonly batchSize;
|
|
85
|
+
private readonly coalesce;
|
|
61
86
|
private readonly onError;
|
|
62
87
|
readonly consumerId: string;
|
|
63
88
|
private readonly pruneIntervalMs;
|
|
@@ -103,4 +128,14 @@ export declare class OutboxChangeSource implements ChangeSource {
|
|
|
103
128
|
prune(): Promise<number>;
|
|
104
129
|
private fetch;
|
|
105
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Whole transactions of one read as one batch, in commit order.
|
|
133
|
+
*
|
|
134
|
+
* The position is the last transaction's, so a failed handler replays the
|
|
135
|
+
* whole read — which delivery is allowed to do, see the {@link ChangeSource}
|
|
136
|
+
* contract.
|
|
137
|
+
*/
|
|
138
|
+
export declare function mergeTransactions(batches: TransactionBatch[]): TransactionBatch;
|
|
139
|
+
export declare function groupByTransaction(rows: OutboxRow[]): TransactionBatch[];
|
|
140
|
+
export {};
|
|
106
141
|
//# sourceMappingURL=outbox-change-source.d.ts.map
|
|
@@ -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;
|
|
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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+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,CAyBxE"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OutboxChangeSource = void 0;
|
|
4
|
+
exports.mergeTransactions = mergeTransactions;
|
|
5
|
+
exports.groupByTransaction = groupByTransaction;
|
|
4
6
|
const node_crypto_1 = require("node:crypto");
|
|
5
7
|
const normalize_1 = require("../../core/normalize");
|
|
6
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`;
|
|
@@ -47,6 +49,7 @@ class OutboxChangeSource {
|
|
|
47
49
|
this.channel = opts.channel ?? "nowity_change";
|
|
48
50
|
this.pollIntervalMs = opts.pollIntervalMs ?? 250;
|
|
49
51
|
this.batchSize = opts.batchSize ?? 500;
|
|
52
|
+
this.coalesce = opts.coalesce ?? true;
|
|
50
53
|
this.consumerId = opts.consumerId ?? `outbox-${(0, node_crypto_1.randomUUID)()}`;
|
|
51
54
|
this.pruneIntervalMs = opts.pruneIntervalMs ?? 0;
|
|
52
55
|
this.pruneStaleAfter = opts.pruneStaleAfter ?? "1 hour";
|
|
@@ -146,7 +149,8 @@ class OutboxChangeSource {
|
|
|
146
149
|
const rows = await this.fetch();
|
|
147
150
|
if (rows.length === 0)
|
|
148
151
|
break;
|
|
149
|
-
|
|
152
|
+
const transactions = groupByTransaction(rows);
|
|
153
|
+
for (const batch of this.coalesce ? [mergeTransactions(transactions)] : transactions) {
|
|
150
154
|
if (!this.handler)
|
|
151
155
|
return;
|
|
152
156
|
await this.handler(batch);
|
|
@@ -211,6 +215,24 @@ class OutboxChangeSource {
|
|
|
211
215
|
}
|
|
212
216
|
}
|
|
213
217
|
exports.OutboxChangeSource = OutboxChangeSource;
|
|
218
|
+
/**
|
|
219
|
+
* Whole transactions of one read as one batch, in commit order.
|
|
220
|
+
*
|
|
221
|
+
* The position is the last transaction's, so a failed handler replays the
|
|
222
|
+
* whole read — which delivery is allowed to do, see the {@link ChangeSource}
|
|
223
|
+
* contract.
|
|
224
|
+
*/
|
|
225
|
+
function mergeTransactions(batches) {
|
|
226
|
+
if (batches.length === 1)
|
|
227
|
+
return batches[0];
|
|
228
|
+
const last = batches[batches.length - 1];
|
|
229
|
+
return {
|
|
230
|
+
position: last.position,
|
|
231
|
+
xid: last.xid,
|
|
232
|
+
transactions: batches.reduce((sum, batch) => sum + (batch.transactions ?? 1), 0),
|
|
233
|
+
events: batches.flatMap((batch) => batch.events),
|
|
234
|
+
};
|
|
235
|
+
}
|
|
214
236
|
function groupByTransaction(rows) {
|
|
215
237
|
const batches = [];
|
|
216
238
|
let current = null;
|
|
@@ -172,11 +172,16 @@ export declare class SyncEngine {
|
|
|
172
172
|
* What the fan-out actually cost, for anyone measuring it.
|
|
173
173
|
*
|
|
174
174
|
* `evaluations` is the number the whole design turns on: how many times a
|
|
175
|
-
* live query had to be run against the database.
|
|
175
|
+
* live query had to be run against the database.
|
|
176
|
+
* `snapshots` is how many read transactions the change stream opened —
|
|
177
|
+
* the connections it took from the pool — and `transactions` how many
|
|
178
|
+
* application transactions they covered. Without it a regression
|
|
176
179
|
* here looks like nothing at all until the process is under load.
|
|
177
180
|
*/
|
|
178
181
|
readonly stats: {
|
|
179
182
|
batches: number;
|
|
183
|
+
transactions: number;
|
|
184
|
+
snapshots: number;
|
|
180
185
|
candidates: number;
|
|
181
186
|
evaluations: number;
|
|
182
187
|
fanOutMs: number;
|
|
@@ -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,EAIrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAGH,KAAK,WAAW,EAEhB,KAAK,UAAU,EAElB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAmB,cAAc,EAAE,MAAM,MAAM,CAAC;AAC5D,OAAO,EAA0C,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AACtF,OAAO,EAAoB,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AACrF,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEpE,MAAM,WAAW,iBAAiB;IAC9B,SAAS,EAAE,cAAc,CAAC;IAC1B,MAA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AgI7B;;;;;;;OAOG;YACW,SAAS;YAMT,SAAS;YAgBT,kBAAkB;YAQlB,mBAAmB;CAiBpC"}
|
|
@@ -85,10 +85,13 @@ class SyncEngine {
|
|
|
85
85
|
* What the fan-out actually cost, for anyone measuring it.
|
|
86
86
|
*
|
|
87
87
|
* `evaluations` is the number the whole design turns on: how many times a
|
|
88
|
-
* live query had to be run against the database.
|
|
88
|
+
* live query had to be run against the database.
|
|
89
|
+
* `snapshots` is how many read transactions the change stream opened —
|
|
90
|
+
* the connections it took from the pool — and `transactions` how many
|
|
91
|
+
* application transactions they covered. Without it a regression
|
|
89
92
|
* here looks like nothing at all until the process is under load.
|
|
90
93
|
*/
|
|
91
|
-
this.stats = { batches: 0, candidates: 0, evaluations: 0, fanOutMs: 0 };
|
|
94
|
+
this.stats = { batches: 0, transactions: 0, snapshots: 0, candidates: 0, evaluations: 0, fanOutMs: 0 };
|
|
92
95
|
this.opts = opts;
|
|
93
96
|
this.permissionTables = new Set(opts.permissionTables ?? []);
|
|
94
97
|
this.narrow = opts.narrowInvalidation ?? true;
|
|
@@ -368,6 +371,7 @@ class SyncEngine {
|
|
|
368
371
|
return;
|
|
369
372
|
const candidates = this.candidatesFor(batch, invalidatedScopes, revalidateEverything);
|
|
370
373
|
this.stats.batches += 1;
|
|
374
|
+
this.stats.transactions += batch.transactions ?? 1;
|
|
371
375
|
this.stats.candidates += candidates.size;
|
|
372
376
|
const bySession = new Map();
|
|
373
377
|
for (const sub of candidates) {
|
|
@@ -392,6 +396,7 @@ class SyncEngine {
|
|
|
392
396
|
if (interested.size === 0)
|
|
393
397
|
return;
|
|
394
398
|
const outgoing = [];
|
|
399
|
+
this.stats.snapshots += 1;
|
|
395
400
|
await this.opts.snapshots.withSnapshot(async (snap) => {
|
|
396
401
|
const epochCache = new Map();
|
|
397
402
|
const mutationIds = await this.readLastMutationIds(snap, [...interested].map((s) => s.info.clientId));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nowity",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Realtime object model over PostgreSQL: logical change stream, query-scoped subscriptions, MobX identity map",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -60,6 +60,10 @@
|
|
|
60
60
|
"./client": {
|
|
61
61
|
"types": "./dist/client.d.ts",
|
|
62
62
|
"default": "./dist/client.js"
|
|
63
|
+
},
|
|
64
|
+
"./devtools": {
|
|
65
|
+
"types": "./dist/devtools.d.ts",
|
|
66
|
+
"default": "./dist/devtools.js"
|
|
63
67
|
}
|
|
64
68
|
},
|
|
65
69
|
"peerDependenciesMeta": {
|