@isoloop/bus 0.1.0-next.1 → 0.1.0-next.10

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/index.d.ts CHANGED
@@ -1,6 +1,10 @@
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
- import { BusRecord, BusToIsolate, CallResult, ErrorCode, Grants, SeedEvent, TopicConfig } from "@isoloop/protocol";
3
- /** A record before the engine gives it an offset. */
1
+ import { _ as unchecked, a as InputOf, c as ReplyOutputOf, d as TopicDef, f as contracts, g as topicConfig, h as topic, i as DEFAULT_MAX_RECORD_BYTES, l as Retention, m as isUnchecked, n as Contracts, o as OutputOf, p as isContracts, r as ContractsError, s as ReplyInputOf, t as AnyTopicDef, u as ToolSpec, v as StandardSchemaV1, y as toIssues } from "./topic-BpgHePIE.js";
2
+ import { BusRecord, BusToIsolate, CallError, CallResult, ErrorCode, Grants, JSON_SCHEMA_TARGET, JsonSchema, JsonSchemaPair, JsonSchemaResult, NotExportableReason, RequestVia, SeedEvent, StandardJSONSchemaV1, TopicConfig, TopicJsonSchemas, TopicJsonSchemasResult, hasJsonSchema, jsonSchemaOf, topicJsonSchemas } from "@isoloop/protocol";
3
+ /**
4
+ * A record before the engine gives it an offset.
5
+ *
6
+ * @internal
7
+ */
4
8
  type NewRecord = Omit<BusRecord, "offset">;
5
9
  /** A publish's instance and counter, for deduplicating re-sends (ADR 0007, step 5). */
6
10
  type AppendId = {
@@ -15,6 +19,8 @@ type AppendId = {
15
19
  * Retention: `last-n` is applied on append; `time` and `compacted` on
16
20
  * `compact()`, which the broker calls on a timer. An engine may also compact
17
21
  * a `compacted` topic on its own once enough records are superseded.
22
+ *
23
+ * @internal
18
24
  */
19
25
  interface LogEngine {
20
26
  /** Throws if the topic exists. */
@@ -38,6 +44,11 @@ interface LogEngine {
38
44
  head(topic: string): number;
39
45
  /** Oldest retained offset; equals `head` when nothing is retained. */
40
46
  tail(topic: string): number;
47
+ /**
48
+ * How many records are retained in `[tail, head)`: what `read` from the
49
+ * tail would return, counting records evicted to disk (ADR 0020, decision 2).
50
+ */
51
+ retained(topic: string): number;
41
52
  /** Stores a consumer's committed offset. Kept even when the records it names are dropped. */
42
53
  commit(topic: string, consumer: string, offset: number): void;
43
54
  committed(topic: string, consumer: string): number | undefined;
@@ -69,14 +80,22 @@ interface LogEngine {
69
80
  /** Pages evicted records from `fromOffset` back in from disk, so `read` sees them. */
70
81
  page(topic: string, fromOffset: number): Promise<void>;
71
82
  }
72
- /** Options every engine takes. */
83
+ /**
84
+ * Options every engine takes.
85
+ *
86
+ * @internal
87
+ */
73
88
  type EngineOptions = {
74
89
  /** Clock for `time` retention. Default `Date.now`. */
75
90
  now?: () => number;
76
91
  /** Default `MemoryStorage`. */
77
92
  storage?: LogStorage;
78
93
  };
79
- /** What a storage found on open: per topic, the offsets it holds; per topic and consumer, commits. */
94
+ /**
95
+ * What a storage found on open: per topic, the offsets it holds; per topic and consumer, commits.
96
+ *
97
+ * @internal
98
+ */
80
99
  type StoredState = {
81
100
  topics: {
82
101
  topic: string;
@@ -89,6 +108,8 @@ type StoredState = {
89
108
  * Durable storage under the engine, for `durability: 'persistent'` topics
90
109
  * (design §6.2, ADR 0007). M2 ships `MemoryStorage`, which keeps nothing;
91
110
  * M2b adds `OpfsStorage`.
111
+ *
112
+ * @internal
92
113
  */
93
114
  interface LogStorage {
94
115
  /** `memory` keeps nothing; reported in the bus `ready` message. */
@@ -123,7 +144,11 @@ interface LogStorage {
123
144
  /** Safe mode: moves the newest segments aside and returns their names. */
124
145
  quarantineNewest(): Promise<string[]>;
125
146
  }
126
- /** Storage that keeps nothing. Every topic behaves as `memory`. */
147
+ /**
148
+ * Storage that keeps nothing. Every topic behaves as `memory`.
149
+ *
150
+ * @internal
151
+ */
127
152
  export declare class MemoryStorage implements LogStorage {
128
153
  readonly kind: "memory";
129
154
  open(): Promise<StoredState>;
@@ -141,9 +166,12 @@ export declare class MemoryStorage implements LogStorage {
141
166
  * Engines call this from `createTopic`: the durability a topic actually gets.
142
167
  * A `persistent` topic on storage that keeps nothing (no OPFS, or another tab
143
168
  * holds it) behaves as `memory`; the kernel reports that as
144
- * `bus:durability-degraded` (ADR 0007, decision 6).
169
+ * `bus:durability_degraded` (ADR 0007, decision 6).
170
+ *
171
+ * @internal
145
172
  */
146
173
  export declare function effectiveDurability(cfg: TopicConfig, storage: LogStorage): "memory" | "persistent";
174
+ /** @internal */
147
175
  type TsEngineOptions = EngineOptions & {
148
176
  /** Records per chunk. Default 4,096; tests use small chunks to cross boundaries often. */
149
177
  chunkSize?: number;
@@ -160,6 +188,8 @@ type TsEngineOptions = EngineOptions & {
160
188
  * The TypeScript `LogEngine` (design §6.2). Each topic is an array of
161
189
  * fixed-size chunks, so dropping old records frees a whole chunk at a time:
162
190
  * O(1) per chunk. Compacted topics keep a key → latest-offset index.
191
+ *
192
+ * @internal
163
193
  */
164
194
  export declare class TsEngine implements LogEngine {
165
195
  #private;
@@ -186,6 +216,7 @@ export declare class TsEngine implements LogEngine {
186
216
  /** Lowest offset held in memory; below it, records are on disk only. For tests and metrics. */
187
217
  resident(topic: string): number;
188
218
  tail(topic: string): number;
219
+ retained(topic: string): number;
189
220
  commit(topic: string, consumer: string, offset: number): void;
190
221
  committed(topic: string, consumer: string): number | undefined;
191
222
  durable(topic: string): boolean;
@@ -201,6 +232,8 @@ export declare class TsEngine implements LogEngine {
201
232
  /**
202
233
  * One isolate's bus connection, as the broker sees it. The bus worker wraps a
203
234
  * `MessagePort`; tests use in-memory ports.
235
+ *
236
+ * @internal
204
237
  */
205
238
  export interface BusPort {
206
239
  post(msg: BusToIsolate): void;
@@ -208,10 +241,15 @@ export interface BusPort {
208
241
  onMessage(handler: (msg: unknown) => void): void;
209
242
  close(): void;
210
243
  }
211
- /** Timer functions, injectable for tests. */
244
+ /**
245
+ * Timer functions, injectable for tests.
246
+ *
247
+ * @internal
248
+ */
212
249
  export type Timers = {
213
250
  set(fn: () => void, ms: number): void;
214
251
  };
252
+ /** @internal */
215
253
  export type BrokerOptions = {
216
254
  contracts: Contracts;
217
255
  engine: LogEngine;
@@ -247,7 +285,18 @@ export type BrokerOptions = {
247
285
  /** Seeding news for the host: rejected source records and ended seeds (ADR 0003, decision 18). */
248
286
  onSeed?: (e: SeedEvent) => void;
249
287
  };
250
- /** Who is publishing: an isolate (grants apply), the host (`kernel.publish`), or the kernel itself (system topics). */
288
+ /**
289
+ * Gets each record appended to a tapped topic (ADR 0020, decision 3), with
290
+ * its estimated size. A tap is not a consumer: it has no cursor or credit.
291
+ *
292
+ * @internal
293
+ */
294
+ export type TapSink = (topic: string, rec: BusRecord, bytes: number) => void;
295
+ /**
296
+ * Who is publishing: an isolate (grants apply), the host (`kernel.publish`), or the kernel itself (system topics).
297
+ *
298
+ * @internal
299
+ */
251
300
  export type Publisher = {
252
301
  kind: "isolate";
253
302
  isolateId: string;
@@ -256,12 +305,19 @@ export type Publisher = {
256
305
  } | {
257
306
  kind: "kernel";
258
307
  };
259
- /** Cumulative counters for metrics (design §6.3); the bus worker turns them into rates. */
308
+ /**
309
+ * Cumulative counters for metrics (design §6.3); the bus worker turns them into rates.
310
+ *
311
+ * @internal
312
+ */
260
313
  export type BrokerStats = {
314
+ /** `head` and `retained` are the engine's, at the time of the sample (ADR 0020, decision 2). */
261
315
  topics: {
262
316
  topic: string;
263
317
  records: number;
264
318
  bytes: number;
319
+ head: number;
320
+ retained: number;
265
321
  }[];
266
322
  /** `lag` is `head − cursor`: records not yet delivered. */
267
323
  subscriptions: {
@@ -273,7 +329,11 @@ export type BrokerStats = {
273
329
  /** Rejected publishes and requests, by error code. */
274
330
  rejected: Partial<Record<ErrorCode, number>>;
275
331
  };
276
- /** A message's `(epoch, seq)`, when it carries both as numbers. */
332
+ /**
333
+ * A message's `(epoch, seq)`, when it carries both as numbers.
334
+ *
335
+ * @internal
336
+ */
277
337
  export declare function publishId(p: {
278
338
  epoch?: unknown;
279
339
  seq?: unknown;
@@ -289,6 +349,8 @@ export declare const DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
289
349
  * and consumer groups, delivers from the log under credit, and routes
290
350
  * request replies. Knows nothing about workers; the bus worker entry wires
291
351
  * ports to it.
352
+ *
353
+ * @internal
292
354
  */
293
355
  export declare class Broker {
294
356
  #private;
@@ -347,12 +409,45 @@ export declare class Broker {
347
409
  * The host can't publish system topics; the kernel can only publish them.
348
410
  */
349
411
  publish(from: Publisher, topic: string, key: string | undefined, value: unknown, id?: AppendId): Promise<CallResult>;
412
+ /**
413
+ * A request from the host (`kernel.request`, ADR 0018, decision 4): like
414
+ * an isolate's `bus.request`, with `req: { from: 'host', id, via }` on the
415
+ * record. `answer` gets one result: a failure to append, or the first
416
+ * valid reply (or `reply_invalid`). Nothing, if no reply comes before the
417
+ * caller's timeout; the request is forgotten after `timeoutMs`.
418
+ */
419
+ request(topic: string, key: string | undefined, value: unknown, opts: {
420
+ id: string;
421
+ timeoutMs: number;
422
+ via?: RequestVia;
423
+ }, answer: (r: CallResult) => void, appendId?: AppendId): void;
424
+ /**
425
+ * The inspection feed's tap (ADR 0020, decision 3): `sink` gets every
426
+ * record appended to a topic matching one of `patterns` from now on,
427
+ * through the publish pipeline. Seeds copying into a topic before it opens
428
+ * aren't tapped. Returns the function that ends it.
429
+ */
430
+ tap(patterns: readonly string[], sink: TapSink): () => void;
431
+ /**
432
+ * The last `last` retained records of `topic`, oldest first (ADR 0020,
433
+ * decision 3), paging evicted records in from disk when needed. Seed
434
+ * sources the contracts don't list are unknown here, as to isolates.
435
+ */
436
+ read(name: string, last: number): Promise<{
437
+ ok: true;
438
+ records: BusRecord[];
439
+ } | {
440
+ ok: false;
441
+ error: CallError;
442
+ }>;
350
443
  }
351
444
  /**
352
445
  * A rough structured size of a value in bytes, for `maxRecordBytes` (design
353
446
  * §6.1). Strings count two bytes per UTF-16 unit, numbers eight, object keys
354
447
  * like strings, plus a little per entry. Cycles count once. Cheap rather than
355
448
  * exact: it only has to tell a 1 KiB record from a 1 MiB one.
449
+ *
450
+ * @internal
356
451
  */
357
452
  export declare function estimateSize(value: unknown, limit?: number): number;
358
- export { AnyTopicDef, Contracts, ContractsError, DEFAULT_MAX_RECORD_BYTES, type EngineOptions, InputOf, type LogEngine, type LogStorage, type NewRecord, OutputOf, ReplyInputOf, ReplyOutputOf, type Retention, StandardSchemaV1, type StoredState, TopicDef, type TsEngineOptions, contracts, isContracts, isUnchecked, toIssues, topic, topicConfig, unchecked };
453
+ export { AnyTopicDef, Contracts, ContractsError, DEFAULT_MAX_RECORD_BYTES, type EngineOptions, InputOf, JSON_SCHEMA_TARGET, type JsonSchema, type JsonSchemaPair, type JsonSchemaResult, type LogEngine, type LogStorage, type NewRecord, type NotExportableReason, OutputOf, ReplyInputOf, ReplyOutputOf, type Retention, type StandardJSONSchemaV1, StandardSchemaV1, type StoredState, type ToolSpec, TopicDef, type TopicJsonSchemas, type TopicJsonSchemasResult, type TsEngineOptions, contracts, hasJsonSchema, isContracts, isUnchecked, jsonSchemaOf, toIssues, topic, topicConfig, topicJsonSchemas, unchecked };