@isoloop/bus 0.0.0-next.69da74b → 0.0.0-next.800569e
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 +50 -11
- 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
|
@@ -8,11 +8,12 @@ const isRecord$1 = (x) => typeof x === "object" && x !== null && !Array.isArray(
|
|
|
8
8
|
const isOptionalString = (x) => x === void 0 || typeof x === "string";
|
|
9
9
|
/**
|
|
10
10
|
* True for a well-formed envelope this build can read: `v` is a supported
|
|
11
|
-
* version, `t` is a string, `id`/`re` are absent or strings, and `p`
|
|
11
|
+
* version, `t` is a string, `id`/`re`/`isolate` are absent or strings, and `p`
|
|
12
|
+
* is present.
|
|
12
13
|
* Says nothing about whether `t` is known; see the per-port guards.
|
|
13
14
|
*/
|
|
14
15
|
function isEnvelope(x) {
|
|
15
|
-
return isRecord$1(x) && x["v"] === PROTOCOL.v && typeof x["t"] === "string" && "p" in x && isOptionalString(x["id"]) && isOptionalString(x["re"]);
|
|
16
|
+
return isRecord$1(x) && x["v"] === PROTOCOL.v && typeof x["t"] === "string" && "p" in x && isOptionalString(x["id"]) && isOptionalString(x["re"]) && isOptionalString(x["isolate"]);
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Builds a guard for one port's union from its message types. Each side drops
|
|
@@ -51,7 +52,7 @@ const isIsolateToBus = envelopeGuard({
|
|
|
51
52
|
publish: true,
|
|
52
53
|
subscribe: true,
|
|
53
54
|
unsubscribe: true,
|
|
54
|
-
|
|
55
|
+
commits: true,
|
|
55
56
|
request: true,
|
|
56
57
|
reply: true
|
|
57
58
|
});
|
|
@@ -134,14 +135,14 @@ function topicConfigOf(t) {
|
|
|
134
135
|
}
|
|
135
136
|
// ../codec/dist/index.js
|
|
136
137
|
var __defProp = Object.defineProperty;
|
|
137
|
-
var __exportAll = (all,
|
|
138
|
-
let target = {};
|
|
138
|
+
var __exportAll = (all, flags) => {
|
|
139
|
+
let target = Object.setPrototypeOf({}, null);
|
|
139
140
|
for (var name in all) __defProp(target, name, {
|
|
140
141
|
get: all[name],
|
|
141
142
|
enumerable: true
|
|
142
143
|
});
|
|
143
|
-
if (!
|
|
144
|
-
return target;
|
|
144
|
+
if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
145
|
+
return flags & 2 ? target : Object.preventExtensions(target);
|
|
145
146
|
};
|
|
146
147
|
/** Thrown by `encode` and `decode`. */
|
|
147
148
|
var CodecError = class extends Error {
|
|
@@ -1259,7 +1260,7 @@ var Broker = class {
|
|
|
1259
1260
|
return new Promise((resolve) => this.#publish(from, topic, key, value, void 0, resolve, id));
|
|
1260
1261
|
}
|
|
1261
1262
|
#receive(conn, msg) {
|
|
1262
|
-
if (!isIsolateToBus(msg) || !hasTopic(msg.p)) {
|
|
1263
|
+
if (!isIsolateToBus(msg) || msg.t !== "commits" && !hasTopic(msg.p)) {
|
|
1263
1264
|
this.#dropped++;
|
|
1264
1265
|
return;
|
|
1265
1266
|
}
|
|
@@ -1345,9 +1346,23 @@ var Broker = class {
|
|
|
1345
1346
|
});
|
|
1346
1347
|
return;
|
|
1347
1348
|
}
|
|
1348
|
-
case "
|
|
1349
|
-
|
|
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);
|
|
1350
1364
|
return;
|
|
1365
|
+
}
|
|
1351
1366
|
default: {
|
|
1352
1367
|
const never = msg;
|
|
1353
1368
|
this.#dropped++;
|
|
@@ -2327,9 +2342,11 @@ var TsEngine = class {
|
|
|
2327
2342
|
/** Drops every record below `offset` (last-n). */
|
|
2328
2343
|
#dropBelow(t, offset) {
|
|
2329
2344
|
if (offset <= t.tail) return;
|
|
2330
|
-
|
|
2345
|
+
const from = t.tail;
|
|
2346
|
+
t.live -= this.#countLive(t, from, offset);
|
|
2331
2347
|
t.tail = offset;
|
|
2332
2348
|
this.#freeChunks(t);
|
|
2349
|
+
this.#clearBelowTail(t, from);
|
|
2333
2350
|
}
|
|
2334
2351
|
/** Records in `[from, to)` still held. Last-n topics have no holes, so this is `to - from` there. */
|
|
2335
2352
|
#countLive(t, from, to) {
|
|
@@ -2340,6 +2357,7 @@ var TsEngine = class {
|
|
|
2340
2357
|
}
|
|
2341
2358
|
/** Drops records from the tail while the oldest is older than `cutoff` (time). */
|
|
2342
2359
|
#expire(t, cutoff) {
|
|
2360
|
+
const from = t.tail;
|
|
2343
2361
|
let o = t.tail;
|
|
2344
2362
|
while (o < t.evictedTo) {
|
|
2345
2363
|
const s = t.evicted[0];
|
|
@@ -2350,6 +2368,7 @@ var TsEngine = class {
|
|
|
2350
2368
|
if (s.maxTs >= cutoff) {
|
|
2351
2369
|
t.tail = o;
|
|
2352
2370
|
this.#freeChunks(t);
|
|
2371
|
+
this.#clearBelowTail(t, from);
|
|
2353
2372
|
return;
|
|
2354
2373
|
}
|
|
2355
2374
|
t.live -= s.count;
|
|
@@ -2364,6 +2383,20 @@ var TsEngine = class {
|
|
|
2364
2383
|
}
|
|
2365
2384
|
t.tail = Math.min(o, t.head);
|
|
2366
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
|
+
}
|
|
2367
2400
|
}
|
|
2368
2401
|
/** Drops records superseded by a later record with the same key; keyless records stay. */
|
|
2369
2402
|
#compactKeys(t) {
|
|
@@ -2437,6 +2470,12 @@ var TsEngine = class {
|
|
|
2437
2470
|
chunkCount(topic) {
|
|
2438
2471
|
return this.#topic(topic).chunks.length;
|
|
2439
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
|
+
}
|
|
2440
2479
|
};
|
|
2441
2480
|
/** Notes that `producer` appended `id` at `offset`; a new epoch forgets the old one's. */
|
|
2442
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.800569e",
|
|
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.800569e",
|
|
31
|
+
"@isoloop/protocol": "0.0.0-next.800569e"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"fast-check": "4.10.2",
|