@isoloop/bus 0.0.0-next.f57e259 → 0.0.0-next.g3322248
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bus-worker.js +47 -9
- package/dist/index.d.ts +3 -1
- package/dist/index.js +42 -4
- package/dist/testing.d.ts +1 -1
- package/dist/{topic-Cxr8oyfH.d.ts → topic-BQbes-gX.d.ts} +2 -2
- package/package.json +3 -3
package/dist/bus-worker.js
CHANGED
|
@@ -52,7 +52,7 @@ const isIsolateToBus = envelopeGuard({
|
|
|
52
52
|
publish: true,
|
|
53
53
|
subscribe: true,
|
|
54
54
|
unsubscribe: true,
|
|
55
|
-
|
|
55
|
+
commits: true,
|
|
56
56
|
request: true,
|
|
57
57
|
reply: true
|
|
58
58
|
});
|
|
@@ -135,14 +135,14 @@ function topicConfigOf(t) {
|
|
|
135
135
|
}
|
|
136
136
|
// ../codec/dist/index.js
|
|
137
137
|
var __defProp = Object.defineProperty;
|
|
138
|
-
var __exportAll = (all,
|
|
139
|
-
let target = {};
|
|
138
|
+
var __exportAll = (all, flags) => {
|
|
139
|
+
let target = Object.setPrototypeOf({}, null);
|
|
140
140
|
for (var name in all) __defProp(target, name, {
|
|
141
141
|
get: all[name],
|
|
142
142
|
enumerable: true
|
|
143
143
|
});
|
|
144
|
-
if (!
|
|
145
|
-
return target;
|
|
144
|
+
if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
145
|
+
return flags & 2 ? target : Object.preventExtensions(target);
|
|
146
146
|
};
|
|
147
147
|
/** Thrown by `encode` and `decode`. */
|
|
148
148
|
var CodecError = class extends Error {
|
|
@@ -1260,7 +1260,7 @@ var Broker = class {
|
|
|
1260
1260
|
return new Promise((resolve) => this.#publish(from, topic, key, value, void 0, resolve, id));
|
|
1261
1261
|
}
|
|
1262
1262
|
#receive(conn, msg) {
|
|
1263
|
-
if (!isIsolateToBus(msg) || !hasTopic(msg.p)) {
|
|
1263
|
+
if (!isIsolateToBus(msg) || msg.t !== "commits" && !hasTopic(msg.p)) {
|
|
1264
1264
|
this.#dropped++;
|
|
1265
1265
|
return;
|
|
1266
1266
|
}
|
|
@@ -1346,9 +1346,23 @@ var Broker = class {
|
|
|
1346
1346
|
});
|
|
1347
1347
|
return;
|
|
1348
1348
|
}
|
|
1349
|
-
case "
|
|
1350
|
-
|
|
1349
|
+
case "commits": {
|
|
1350
|
+
const offsets = msg.p.offsets;
|
|
1351
|
+
if (!Array.isArray(offsets)) {
|
|
1352
|
+
reply(fail("invalid", "commits needs an offsets array"));
|
|
1353
|
+
return;
|
|
1354
|
+
}
|
|
1355
|
+
let first = {
|
|
1356
|
+
ok: true,
|
|
1357
|
+
value: null
|
|
1358
|
+
};
|
|
1359
|
+
for (const e of offsets) {
|
|
1360
|
+
const r = typeof e === "object" && e !== null && "topic" in e && typeof e.topic === "string" ? this.#commit(conn, e.topic, "offset" in e ? e.offset : void 0) : fail("invalid", "each commit needs a topic and an offset");
|
|
1361
|
+
if (!r.ok && first.ok) first = r;
|
|
1362
|
+
}
|
|
1363
|
+
reply(first);
|
|
1351
1364
|
return;
|
|
1365
|
+
}
|
|
1352
1366
|
default: {
|
|
1353
1367
|
const never = msg;
|
|
1354
1368
|
this.#dropped++;
|
|
@@ -2328,9 +2342,11 @@ var TsEngine = class {
|
|
|
2328
2342
|
/** Drops every record below `offset` (last-n). */
|
|
2329
2343
|
#dropBelow(t, offset) {
|
|
2330
2344
|
if (offset <= t.tail) return;
|
|
2331
|
-
|
|
2345
|
+
const from = t.tail;
|
|
2346
|
+
t.live -= this.#countLive(t, from, offset);
|
|
2332
2347
|
t.tail = offset;
|
|
2333
2348
|
this.#freeChunks(t);
|
|
2349
|
+
this.#clearBelowTail(t, from);
|
|
2334
2350
|
}
|
|
2335
2351
|
/** Records in `[from, to)` still held. Last-n topics have no holes, so this is `to - from` there. */
|
|
2336
2352
|
#countLive(t, from, to) {
|
|
@@ -2341,6 +2357,7 @@ var TsEngine = class {
|
|
|
2341
2357
|
}
|
|
2342
2358
|
/** Drops records from the tail while the oldest is older than `cutoff` (time). */
|
|
2343
2359
|
#expire(t, cutoff) {
|
|
2360
|
+
const from = t.tail;
|
|
2344
2361
|
let o = t.tail;
|
|
2345
2362
|
while (o < t.evictedTo) {
|
|
2346
2363
|
const s = t.evicted[0];
|
|
@@ -2351,6 +2368,7 @@ var TsEngine = class {
|
|
|
2351
2368
|
if (s.maxTs >= cutoff) {
|
|
2352
2369
|
t.tail = o;
|
|
2353
2370
|
this.#freeChunks(t);
|
|
2371
|
+
this.#clearBelowTail(t, from);
|
|
2354
2372
|
return;
|
|
2355
2373
|
}
|
|
2356
2374
|
t.live -= s.count;
|
|
@@ -2365,6 +2383,20 @@ var TsEngine = class {
|
|
|
2365
2383
|
}
|
|
2366
2384
|
t.tail = Math.min(o, t.head);
|
|
2367
2385
|
this.#freeChunks(t);
|
|
2386
|
+
this.#clearBelowTail(t, from);
|
|
2387
|
+
}
|
|
2388
|
+
/**
|
|
2389
|
+
* Clears the slots in `[from, tail)` that are still in a held chunk:
|
|
2390
|
+
* `#freeChunks` frees whole chunks only, so without this a slow topic keeps
|
|
2391
|
+
* its expired records referenced until the chunk holding its tail fills,
|
|
2392
|
+
* minutes at a few records a second (plant memory investigation, #162).
|
|
2393
|
+
* Each record is cleared once, as the tail passes it.
|
|
2394
|
+
*/
|
|
2395
|
+
#clearBelowTail(t, from) {
|
|
2396
|
+
for (let o = Math.max(from, t.base * this.#size); o < t.tail; o++) {
|
|
2397
|
+
const chunk = this.#chunkOf(t, o);
|
|
2398
|
+
if (chunk) chunk[o % this.#size] = void 0;
|
|
2399
|
+
}
|
|
2368
2400
|
}
|
|
2369
2401
|
/** Drops records superseded by a later record with the same key; keyless records stay. */
|
|
2370
2402
|
#compactKeys(t) {
|
|
@@ -2438,6 +2470,12 @@ var TsEngine = class {
|
|
|
2438
2470
|
chunkCount(topic) {
|
|
2439
2471
|
return this.#topic(topic).chunks.length;
|
|
2440
2472
|
}
|
|
2473
|
+
/** Records held in memory for a topic, for tests and metrics. */
|
|
2474
|
+
heldCount(topic) {
|
|
2475
|
+
let n = 0;
|
|
2476
|
+
for (const chunk of this.#topic(topic).chunks) for (const r of chunk ?? []) if (r) n++;
|
|
2477
|
+
return n;
|
|
2478
|
+
}
|
|
2441
2479
|
};
|
|
2442
2480
|
/** Notes that `producer` appended `id` at `offset`; a new epoch forgets the old one's. */
|
|
2443
2481
|
function remember(t, producer, id, offset) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as StandardSchemaV1, a as InputOf, c as ReplyOutputOf, d as contracts, f as isContracts, g as unchecked, h as topicConfig, i as DEFAULT_MAX_RECORD_BYTES, l as Retention, m as topic, n as Contracts, o as OutputOf, p as isUnchecked, r as ContractsError, s as ReplyInputOf, t as AnyTopicDef, u as TopicDef, v as toIssues } from "./topic-
|
|
1
|
+
import { _ as StandardSchemaV1, a as InputOf, c as ReplyOutputOf, d as contracts, f as isContracts, g as unchecked, h as topicConfig, i as DEFAULT_MAX_RECORD_BYTES, l as Retention, m as topic, n as Contracts, o as OutputOf, p as isUnchecked, r as ContractsError, s as ReplyInputOf, t as AnyTopicDef, u as TopicDef, v as toIssues } from "./topic-BQbes-gX.js";
|
|
2
2
|
import { BusRecord, BusToIsolate, CallResult, ErrorCode, Grants, SeedEvent, TopicConfig } from "@isoloop/protocol";
|
|
3
3
|
/** A record before the engine gives it an offset. */
|
|
4
4
|
type NewRecord = Omit<BusRecord, "offset">;
|
|
@@ -195,6 +195,8 @@ export declare class TsEngine implements LogEngine {
|
|
|
195
195
|
compact(topic: string): void;
|
|
196
196
|
/** Chunks held for a topic, for tests and metrics. */
|
|
197
197
|
chunkCount(topic: string): number;
|
|
198
|
+
/** Records held in memory for a topic, for tests and metrics. */
|
|
199
|
+
heldCount(topic: string): number;
|
|
198
200
|
}
|
|
199
201
|
/**
|
|
200
202
|
* One isolate's bus connection, as the broker sees it. The bus worker wraps a
|
package/dist/index.js
CHANGED
|
@@ -543,9 +543,11 @@ var TsEngine = class {
|
|
|
543
543
|
/** Drops every record below `offset` (last-n). */
|
|
544
544
|
#dropBelow(t, offset) {
|
|
545
545
|
if (offset <= t.tail) return;
|
|
546
|
-
|
|
546
|
+
const from = t.tail;
|
|
547
|
+
t.live -= this.#countLive(t, from, offset);
|
|
547
548
|
t.tail = offset;
|
|
548
549
|
this.#freeChunks(t);
|
|
550
|
+
this.#clearBelowTail(t, from);
|
|
549
551
|
}
|
|
550
552
|
/** Records in `[from, to)` still held. Last-n topics have no holes, so this is `to - from` there. */
|
|
551
553
|
#countLive(t, from, to) {
|
|
@@ -556,6 +558,7 @@ var TsEngine = class {
|
|
|
556
558
|
}
|
|
557
559
|
/** Drops records from the tail while the oldest is older than `cutoff` (time). */
|
|
558
560
|
#expire(t, cutoff) {
|
|
561
|
+
const from = t.tail;
|
|
559
562
|
let o = t.tail;
|
|
560
563
|
while (o < t.evictedTo) {
|
|
561
564
|
const s = t.evicted[0];
|
|
@@ -566,6 +569,7 @@ var TsEngine = class {
|
|
|
566
569
|
if (s.maxTs >= cutoff) {
|
|
567
570
|
t.tail = o;
|
|
568
571
|
this.#freeChunks(t);
|
|
572
|
+
this.#clearBelowTail(t, from);
|
|
569
573
|
return;
|
|
570
574
|
}
|
|
571
575
|
t.live -= s.count;
|
|
@@ -580,6 +584,20 @@ var TsEngine = class {
|
|
|
580
584
|
}
|
|
581
585
|
t.tail = Math.min(o, t.head);
|
|
582
586
|
this.#freeChunks(t);
|
|
587
|
+
this.#clearBelowTail(t, from);
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Clears the slots in `[from, tail)` that are still in a held chunk:
|
|
591
|
+
* `#freeChunks` frees whole chunks only, so without this a slow topic keeps
|
|
592
|
+
* its expired records referenced until the chunk holding its tail fills,
|
|
593
|
+
* minutes at a few records a second (plant memory investigation, #162).
|
|
594
|
+
* Each record is cleared once, as the tail passes it.
|
|
595
|
+
*/
|
|
596
|
+
#clearBelowTail(t, from) {
|
|
597
|
+
for (let o = Math.max(from, t.base * this.#size); o < t.tail; o++) {
|
|
598
|
+
const chunk = this.#chunkOf(t, o);
|
|
599
|
+
if (chunk) chunk[o % this.#size] = void 0;
|
|
600
|
+
}
|
|
583
601
|
}
|
|
584
602
|
/** Drops records superseded by a later record with the same key; keyless records stay. */
|
|
585
603
|
#compactKeys(t) {
|
|
@@ -653,6 +671,12 @@ var TsEngine = class {
|
|
|
653
671
|
chunkCount(topic) {
|
|
654
672
|
return this.#topic(topic).chunks.length;
|
|
655
673
|
}
|
|
674
|
+
/** Records held in memory for a topic, for tests and metrics. */
|
|
675
|
+
heldCount(topic) {
|
|
676
|
+
let n = 0;
|
|
677
|
+
for (const chunk of this.#topic(topic).chunks) for (const r of chunk ?? []) if (r) n++;
|
|
678
|
+
return n;
|
|
679
|
+
}
|
|
656
680
|
};
|
|
657
681
|
/** Notes that `producer` appended `id` at `offset`; a new epoch forgets the old one's. */
|
|
658
682
|
function remember(t, producer, id, offset) {
|
|
@@ -1225,7 +1249,7 @@ var Broker = class {
|
|
|
1225
1249
|
return new Promise((resolve) => this.#publish(from, topic, key, value, void 0, resolve, id));
|
|
1226
1250
|
}
|
|
1227
1251
|
#receive(conn, msg) {
|
|
1228
|
-
if (!isIsolateToBus(msg) || !hasTopic(msg.p)) {
|
|
1252
|
+
if (!isIsolateToBus(msg) || msg.t !== "commits" && !hasTopic(msg.p)) {
|
|
1229
1253
|
this.#dropped++;
|
|
1230
1254
|
return;
|
|
1231
1255
|
}
|
|
@@ -1311,9 +1335,23 @@ var Broker = class {
|
|
|
1311
1335
|
});
|
|
1312
1336
|
return;
|
|
1313
1337
|
}
|
|
1314
|
-
case "
|
|
1315
|
-
|
|
1338
|
+
case "commits": {
|
|
1339
|
+
const offsets = msg.p.offsets;
|
|
1340
|
+
if (!Array.isArray(offsets)) {
|
|
1341
|
+
reply(fail("invalid", "commits needs an offsets array"));
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
let first = {
|
|
1345
|
+
ok: true,
|
|
1346
|
+
value: null
|
|
1347
|
+
};
|
|
1348
|
+
for (const e of offsets) {
|
|
1349
|
+
const r = typeof e === "object" && e !== null && "topic" in e && typeof e.topic === "string" ? this.#commit(conn, e.topic, "offset" in e ? e.offset : void 0) : fail("invalid", "each commit needs a topic and an offset");
|
|
1350
|
+
if (!r.ok && first.ok) first = r;
|
|
1351
|
+
}
|
|
1352
|
+
reply(first);
|
|
1316
1353
|
return;
|
|
1354
|
+
}
|
|
1317
1355
|
default: {
|
|
1318
1356
|
const never = msg;
|
|
1319
1357
|
this.#dropped++;
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as Contracts } from "./topic-
|
|
1
|
+
import { n as Contracts } from "./topic-BQbes-gX.js";
|
|
2
2
|
import { Issue } from "@isoloop/protocol";
|
|
3
3
|
/** Sample values for one topic. An array is shorthand for `{ values }`. */
|
|
4
4
|
export type TopicSamples = readonly unknown[] | {
|
|
@@ -56,7 +56,7 @@ type TopicDef<In, Out = In, RIn = never, ROut = RIn> = {
|
|
|
56
56
|
readonly schema: StandardSchemaV1<In, Out>;
|
|
57
57
|
/** Required for `bus.request`. */
|
|
58
58
|
readonly reply?: StandardSchemaV1<RIn, ROut>;
|
|
59
|
-
readonly retention: Retention;
|
|
59
|
+
readonly retention: Retention$1;
|
|
60
60
|
/** Rough structured size limit per record. Default 256 KiB. */
|
|
61
61
|
readonly maxRecordBytes?: number;
|
|
62
62
|
/**
|
|
@@ -124,4 +124,4 @@ declare function contracts(...topics: AnyTopicDef[]): Contracts;
|
|
|
124
124
|
declare function isContracts(x: unknown): x is Contracts;
|
|
125
125
|
/** The structured-cloneable part of a topic, sent at `boot` for the contracts check (ADR 0003, decision 5). */
|
|
126
126
|
declare function topicConfig(t: AnyTopicDef): TopicConfig;
|
|
127
|
-
export { StandardSchemaV1 as _, InputOf as a, ReplyOutputOf as c, contracts as d, isContracts as f, unchecked as g, topicConfig as h, DEFAULT_MAX_RECORD_BYTES as i, Retention
|
|
127
|
+
export { StandardSchemaV1 as _, InputOf as a, ReplyOutputOf as c, contracts as d, isContracts as f, unchecked as g, topicConfig as h, DEFAULT_MAX_RECORD_BYTES as i, Retention as l, topic as m, Contracts as n, OutputOf as o, isUnchecked as p, ContractsError as r, ReplyInputOf as s, AnyTopicDef as t, TopicDef as u, toIssues as v };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isoloop/bus",
|
|
3
|
-
"version": "0.0.0-next.
|
|
3
|
+
"version": "0.0.0-next.g3322248",
|
|
4
4
|
"description": "Log bus that runs in its own worker: topics, schemas, offsets, replay.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@isoloop/codec": "0.0.0-next.
|
|
31
|
-
"@isoloop/protocol": "0.0.0-next.
|
|
30
|
+
"@isoloop/codec": "0.0.0-next.g3322248",
|
|
31
|
+
"@isoloop/protocol": "0.0.0-next.g3322248"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"fast-check": "4.10.2",
|