@interactive-inc/claude-funnel 0.67.0 → 0.68.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 (54) hide show
  1. package/README.md +24 -3
  2. package/dist/bin.js +276 -270
  3. package/dist/{channels-BBA3GTAa.d.ts → channels-B0cifCfw.d.ts} +2 -1
  4. package/dist/claude.d.ts +2 -2
  5. package/dist/claude.js +5 -5
  6. package/dist/connector-descriptor-D4XtEsH8.d.ts +215 -0
  7. package/dist/connectors/discord.d.ts +3 -2
  8. package/dist/connectors/discord.js +1 -1
  9. package/dist/connectors/gh.d.ts +3 -2
  10. package/dist/connectors/gh.js +1 -1
  11. package/dist/connectors/schedule.d.ts +13 -11
  12. package/dist/connectors/schedule.js +3 -3
  13. package/dist/connectors/slack.d.ts +3 -2
  14. package/dist/connectors/slack.js +1 -1
  15. package/dist/diagnostic-event-CxMM5Bl2.js +78 -0
  16. package/dist/diagnostic-log-BsAg5qZK.d.ts +186 -0
  17. package/dist/diagnostics.d.ts +2 -2
  18. package/dist/diagnostics.js +3 -2
  19. package/dist/{discord-connector-CdjwPoty.js → discord-connector-CAcWifJn.js} +1 -1
  20. package/dist/docs.js +1 -1
  21. package/dist/doctor.d.ts +1 -1
  22. package/dist/event-log.d.ts +2 -0
  23. package/dist/event-log.js +3 -0
  24. package/dist/{file-process-guard-DAYe9Ndt.d.ts → file-process-guard-D-QatrwL.d.ts} +1 -1
  25. package/dist/{flume-source-listener-CLtsdcT2.d.ts → flume-source-listener-Ba8_1Mg-.d.ts} +2 -1
  26. package/dist/{funnel-diagnostics-B-PCuv_E.js → funnel-diagnostics-CAG7hJP0.js} +82 -139
  27. package/dist/{funnel-diagnostics-CnKus3Jg.d.ts → funnel-diagnostics-CDrZznTB.d.ts} +10 -13
  28. package/dist/{funnel-docs-BFcqITFA.js → funnel-docs-CI4hMkhq.js} +8 -3
  29. package/dist/{funnel-doctor-CviUTINw.d.ts → funnel-doctor-CY4S5cnz.d.ts} +1 -1
  30. package/dist/gateway/daemon.js +59 -79
  31. package/dist/gateway.d.ts +2 -2
  32. package/dist/gateway.js +1 -1
  33. package/dist/{gh-connector-D-iyjl-d.js → gh-connector-DMwI6zJA.js} +1 -1
  34. package/dist/{index-B4RvEaW-.d.ts → index-fHrKn4jm.d.ts} +7 -2
  35. package/dist/index.d.ts +18 -14
  36. package/dist/index.js +124 -30
  37. package/dist/local-config.d.ts +1 -1
  38. package/dist/logger.d.ts +6 -270
  39. package/dist/logger.js +6 -141
  40. package/dist/memory-event-log-BY8XjFzi.js +147 -0
  41. package/dist/{memory-token-prompter-D3R_kgM_.d.ts → memory-token-prompter-B20tl_aU.d.ts} +1 -1
  42. package/dist/{schedule-connector-teeDMHUe.js → schedule-connector-BXUOYgwZ.js} +59 -95
  43. package/dist/schedule-connector-schema-CNV8PgWX.js +137 -0
  44. package/dist/schedule-connector-schema-Tq5kJul-.d.ts +127 -0
  45. package/dist/{slack-connector-BE0KAjCs.js → slack-connector-CC3V2VXQ.js} +1 -1
  46. package/dist/{slot-fields-5ERhytIA.js → slot-fields-eCWizJqS.js} +1 -1
  47. package/dist/{sqlite-diagnostic-log-BDxfXGZy.js → sqlite-diagnostic-log-Qs4cf9I_.js} +53 -84
  48. package/dist/sqlite-event-log-BYgCFMxC.d.ts +284 -0
  49. package/dist/{funnel-log-sqlite-sink-CXbs3qQp.js → sqlite-event-log-eZuXKszJ.js} +52 -11
  50. package/package.json +16 -1
  51. package/dist/connector-descriptor-F75ZI8Fh.d.ts +0 -391
  52. package/dist/diagnostic-sql-reader-CoBk_EFF.js +0 -83
  53. package/dist/schedule-connector-schema-C2AChpwX.js +0 -31
  54. package/dist/schedule-connector-schema-DBko_Bf7.d.ts +0 -48
package/dist/logger.d.ts CHANGED
@@ -1,273 +1,9 @@
1
- //#region lib/logger/funnel-log-entry.d.ts
2
- /**
3
- * Wrapper that `FunnelLog.emit` puts around every event before handing it
4
- * to a sink. `seq` is monotonic across the lifetime of the underlying store —
5
- * sinks persist it as the primary key so replay (and broadcaster seeding
6
- * after restart) is an indexed range scan, not a full table walk. `ts` is
7
- * epoch milliseconds. `event` is the caller-defined payload validated by the
8
- * Zod schema passed to the bus.
9
- */
10
- type FunnelLogEntry<E> = {
11
- seq: number;
12
- ts: number;
13
- event: E;
14
- };
15
- //#endregion
16
- //#region lib/logger/funnel-log-sink.d.ts
17
- /**
18
- * Relay sink. Receives records that already have a `seq` assigned by the
19
- * primary and stores or forwards them — memory ring, stdout, network push,
20
- * a second SQLite mirror, etc. Does not generate seq itself, so any number
21
- * can be attached and they all observe the same monotonic stream.
22
- *
23
- * `write` returns `void` on success or an `Error` the bus surfaces via
24
- * `onSinkError`. Throwing is also tolerated (the bus catches), but
25
- * returning is preferred so the failure path is part of the type.
26
- */
27
- type FunnelLogSink<E> = {
28
- write(record: FunnelLogEntry<E>): void | Error;
29
- close?(): void;
30
- };
31
- /**
32
- * Primary sink. Owns the canonical seq sequence for the bus. `insert` is
33
- * the atomic boundary — it assigns a seq strictly greater than every
34
- * previously assigned one, persists the record, and returns it. SQLite
35
- * implementations get atomicity for free by delegating to `INTEGER PRIMARY
36
- * KEY` so two processes sharing one database file see one monotonic
37
- * stream without bus-level coordination.
38
- *
39
- * `getMaxSeq` is the highest seq currently in the sink — used for
40
- * observability and for replay seeding by clients reading the store.
41
- */
42
- type FunnelLogPrimarySink<E> = {
43
- insert(input: {
44
- ts: number;
45
- event: E;
46
- }): FunnelLogEntry<E> | Error;
47
- getMaxSeq(): number;
48
- close?(): void;
49
- };
50
- //#endregion
1
+ import { c as EventLogValidator, d as EventLogEntry, i as MemoryEventLog, l as EventLogRelay, o as EventLog, s as EventLogProps, t as SqliteEventLog, u as EventLogStore } from "./sqlite-event-log-BYgCFMxC.js";
51
2
  //#region lib/logger/funnel-log.d.ts
52
- type Listener<E> = (record: FunnelLogEntry<E>) => void;
53
- type SinkErrorHandler<E> = (error: Error, record: FunnelLogEntry<E>, sink: FunnelLogSink<E>) => void;
54
- type FunnelLogValidator<E> = (event: unknown) => {
55
- success: true;
56
- data: E;
57
- } | {
58
- success: false;
59
- error: Error;
60
- };
61
- type Props$5<E> = {
62
- /** Validates each event before emission. Use `schema.safeParse` from any validation library, or a plain function. */
63
- validate: FunnelLogValidator<E>;
64
- /** Owns seq assignment + durability. Use `FunnelLogSqliteSink` for multi-process safety. */
65
- primary: FunnelLogPrimarySink<E>;
66
- /** Optional fanout for already-sequenced records (memory ring, stdout, network mirror). */
67
- relays?: ReadonlyArray<FunnelLogSink<E>>;
68
- /** Override for tests. Defaults to `Date.now`. */
69
- now?: () => number;
70
- /** Observer for relay failures. Default: silently swallow. */
71
- onSinkError?: SinkErrorHandler<E>;
72
- };
73
- /**
74
- * Validated event log bus. Three responsibilities and nothing else:
75
- * validate the event, delegate seq + persistence to the primary sink, and
76
- * fan the resulting record out to relays and live subscribers.
77
- *
78
- * Splitting "primary" from "relays" makes the seq invariant honest: there
79
- * is exactly one source of truth (the primary's atomic insert). Two
80
- * `FunnelLog` instances pointed at the same SQLite file therefore see
81
- * one monotonic stream without bus-level coordination. Relays mirror
82
- * already-sequenced records, so they can be added or removed without
83
- * affecting correctness.
84
- *
85
- * Failure isolation:
86
- * - Primary failure short-circuits emit and is returned to the caller.
87
- * - Relay failures never block the primary path — they surface via the
88
- * optional `onSinkError` callback so the caller can observe without
89
- * being interrupted.
90
- * - A subscriber that throws is contained; the rest of the fanout
91
- * completes normally.
92
- */
93
- declare class FunnelLog<E> {
94
- private readonly validate;
95
- private readonly primary;
96
- private readonly relays;
97
- private readonly now;
98
- private readonly onSinkError;
99
- private readonly listeners;
100
- constructor(props: Props$5<E>);
101
- emit(event: E): FunnelLogEntry<E> | Error;
102
- subscribe(listener: Listener<E>): () => void;
103
- getMaxSeq(): number;
104
- close(): void;
105
- private callPrimary;
106
- private fanOutToRelays;
107
- private callRelay;
108
- private fanOutToListeners;
109
- private callClose;
110
- }
111
- //#endregion
112
- //#region lib/logger/funnel-log-sqlite-sink.d.ts
113
- type IndexValues<I extends ReadonlyArray<string>> = Record<I[number], string | null>;
114
- /**
115
- * Constructor props. The shape narrows on `I`: when no indexes are
116
- * declared (the default), `extractIndexes` is forbidden; when indexes
117
- * are declared, both `indexes` and `extractIndexes` are required and
118
- * `extractIndexes` is type-checked against the index keys.
119
- */
120
- type Props$4<E, I extends ReadonlyArray<string>> = I extends readonly [] ? {
121
- path: string;
122
- maxRows?: number;
123
- maxAgeMs?: number;
124
- maxBytes?: number;
125
- targetBytes?: number;
126
- now?: () => number;
127
- indexes?: I;
128
- extractIndexes?: never;
129
- } : {
130
- path: string;
131
- maxRows?: number;
132
- maxAgeMs?: number;
133
- maxBytes?: number;
134
- targetBytes?: number;
135
- now?: () => number;
136
- indexes: I;
137
- extractIndexes: (event: E) => IndexValues<I>;
138
- };
139
- type QueryFilter<I extends ReadonlyArray<string>> = {
140
- /** Return only records with seq strictly greater than this. */
141
- sinceSeq?: number;
142
- /** Filter by the top-level `event.type` discriminator. */
143
- type?: string;
144
- /** Filter by indexed columns. Keys are constrained to the declared `indexes`. */
145
- where?: Partial<IndexValues<I>>;
146
- /** Maximum rows returned. Default 1000. */
147
- limit?: number;
148
- /**
149
- * Which end of the seq range to take when `limit` clips the result.
150
- * "asc" (default) returns the oldest matching rows; "desc" returns the
151
- * newest. Rows are always sorted ascending by seq before returning, so the
152
- * caller sees a chronological slice either way — "desc" just picks the tail.
153
- */
154
- order?: "asc" | "desc";
155
- };
156
- /**
157
- * SQLite-backed sink built on `bun:sqlite`. Implements both primary and
158
- * relay roles so the same instance can own seq generation for one bus and
159
- * mirror records from another (e.g. cross-process replication, restore
160
- * from a backup stream).
161
- *
162
- * Concurrency model: seq is `INTEGER PRIMARY KEY`, so SQLite assigns it
163
- * atomically via `lastInsertRowid`. Two `FunnelLog` instances pointed
164
- * at the same database file therefore see one monotonically increasing
165
- * seq stream without any bus-level coordination — the database itself is
166
- * the synchronization point.
167
- *
168
- * Schema is version-managed via `PRAGMA user_version`. Migrations are
169
- * append-only and run in a transaction on every construct so a partial
170
- * upgrade rolls back cleanly. Caller-defined `indexes` are layered on top
171
- * via `ALTER TABLE ADD COLUMN` + `CREATE INDEX IF NOT EXISTS`, so adding
172
- * a new index to an existing database is a no-downtime operation.
173
- *
174
- * Type safety: the second generic parameter `I` is the literal tuple of
175
- * index column names. `extractIndexes` and `query({ where })` are
176
- * both type-checked against this tuple, so a typo at the call site is a
177
- * compile-time error rather than a silent miss at runtime.
178
- *
179
- * Retention is bounded by `maxRows` and/or `maxAgeMs`. Both run on every
180
- * insert as a single indexed DELETE that no-ops below the cap.
181
- *
182
- * Bulk inserts use `insertMany`, which wraps the batch in one transaction
183
- * for ~10–100x throughput at the cost of one fsync per batch instead of
184
- * one per row.
185
- */
186
- declare class FunnelLogSqliteSink<E, const I extends ReadonlyArray<string> = readonly []> implements FunnelLogPrimarySink<E>, FunnelLogSink<E> {
187
- private readonly db;
188
- private readonly maxRows;
189
- private readonly maxAgeMs;
190
- private readonly maxBytes;
191
- private readonly targetBytes;
192
- private readonly now;
193
- private readonly indexes;
194
- private readonly extractIndexes;
195
- private readonly insertStmt;
196
- private readonly insertWithSeqStmt;
197
- private readonly maxSeqStmt;
198
- private readonly countStmt;
199
- private readonly trimRowsStmt;
200
- private readonly trimAgeStmt;
201
- private readonly trimOldestStmt;
202
- private insertsSinceByteCheck;
203
- constructor(props: Props$4<E, I>);
204
- insert(input: {
205
- ts: number;
206
- event: E;
207
- }): FunnelLogEntry<E> | Error;
208
- insertMany(inputs: ReadonlyArray<{
209
- ts: number;
210
- event: E;
211
- }>): FunnelLogEntry<E>[] | Error;
212
- write(record: FunnelLogEntry<E>): void | Error;
213
- getMaxSeq(): number;
214
- query(props?: QueryFilter<I>): FunnelLogEntry<E>[];
215
- /**
216
- * Current schema version. Useful for diagnostics and for tests that want
217
- * to verify migrations ran. Reads `PRAGMA user_version` once per call.
218
- */
219
- getSchemaVersion(): number;
220
- close(): void;
221
- private buildInsertParams;
222
- private appendWhereConditions;
223
- private trim;
224
- /**
225
- * Throttled byte-size enforcement. Only every BYTE_CHECK_INTERVAL inserts do
226
- * we measure the file; on overflow we estimate how many of the oldest rows to
227
- * drop to land near targetBytes (by the byte/row ratio), delete them in one
228
- * statement, then VACUUM once to return the freed pages to the filesystem (a
229
- * plain DELETE only frees pages inside the file). One DELETE + one VACUUM per
230
- * overflow keeps the expensive rewrite rare — the file must refill the whole
231
- * maxBytes→targetBytes delta before the next overflow can trigger.
232
- */
233
- private maybeTrimBytes;
234
- private byteSize;
235
- /** Drop every row and reclaim the file space. Used by `<log>.clear()`. */
236
- clear(): void;
237
- private syncIndexColumns;
238
- private migrate;
239
- }
240
- //#endregion
241
- //#region lib/logger/funnel-log-memory-sink.d.ts
242
- type Props$3 = {
243
- /** Hard cap on retained records. The oldest is evicted on overflow. 0 disables retention. */
244
- capacity?: number;
245
- };
246
- /**
247
- * In-memory ring buffer that doubles as primary or relay. As primary it
248
- * owns its own seq counter (single-process only — for multi-process
249
- * safety, use `FunnelLogSqliteSink` as primary and place this as a
250
- * relay). As relay it accepts whatever seq the primary assigned and
251
- * advances its own counter to match, so `getMaxSeq` stays meaningful.
252
- *
253
- * Useful as a test double, as a short-window replay buffer paired with a
254
- * persistent primary (covering reconnects without round-tripping disk),
255
- * or as a backing store for live subscribers.
256
- */
257
- declare class FunnelLogMemorySink<E> implements FunnelLogPrimarySink<E>, FunnelLogSink<E> {
258
- private readonly capacity;
259
- private readonly buffer;
260
- private seq;
261
- constructor(props?: Props$3);
262
- insert(input: {
263
- ts: number;
264
- event: E;
265
- }): FunnelLogEntry<E>;
266
- write(record: FunnelLogEntry<E>): void;
267
- getMaxSeq(): number;
268
- query(): ReadonlyArray<FunnelLogEntry<E>>;
269
- clear(): void;
270
- private append;
3
+ type FunnelLogValidator<E> = EventLogValidator<E>;
4
+ declare class FunnelLog<E> extends EventLog<E> {
5
+ constructor(props: EventLogProps<E>);
6
+ emit(event: E): EventLogEntry<E> | Error;
271
7
  }
272
8
  //#endregion
273
9
  //#region lib/logger/funnel-text-entry.d.ts
@@ -397,4 +133,4 @@ declare class FunnelTextStdoutWriter implements FunnelTextWriter {
397
133
  write(record: FunnelTextEntry): void;
398
134
  }
399
135
  //#endregion
400
- export { FunnelLog, FunnelLogEntry, FunnelLogMemorySink, FunnelLogPrimarySink, FunnelLogSink, FunnelLogSqliteSink, FunnelLogValidator, FunnelTextEntry, FunnelTextFileWriter, FunnelTextLevel, FunnelTextLog, FunnelTextStdoutWriter, FunnelTextWriter };
136
+ export { FunnelLog, type EventLogEntry as FunnelLogEntry, MemoryEventLog as FunnelLogMemorySink, type EventLogStore as FunnelLogPrimarySink, type EventLogRelay as FunnelLogSink, SqliteEventLog as FunnelLogSqliteSink, FunnelLogValidator, FunnelTextEntry, FunnelTextFileWriter, FunnelTextLevel, FunnelTextLog, FunnelTextStdoutWriter, FunnelTextWriter };
package/dist/logger.js CHANGED
@@ -1,149 +1,14 @@
1
- import { t as FunnelLogSqliteSink } from "./funnel-log-sqlite-sink-CXbs3qQp.js";
1
+ import { t as SqliteEventLog } from "./sqlite-event-log-eZuXKszJ.js";
2
+ import { n as EventLog, t as MemoryEventLog } from "./memory-event-log-BY8XjFzi.js";
2
3
  import { dirname } from "node:path";
3
4
  import { appendFileSync, existsSync, mkdirSync, renameSync, statSync, unlinkSync } from "node:fs";
4
5
  //#region lib/logger/funnel-log.ts
5
- /**
6
- * Validated event log bus. Three responsibilities and nothing else:
7
- * validate the event, delegate seq + persistence to the primary sink, and
8
- * fan the resulting record out to relays and live subscribers.
9
- *
10
- * Splitting "primary" from "relays" makes the seq invariant honest: there
11
- * is exactly one source of truth (the primary's atomic insert). Two
12
- * `FunnelLog` instances pointed at the same SQLite file therefore see
13
- * one monotonic stream without bus-level coordination. Relays mirror
14
- * already-sequenced records, so they can be added or removed without
15
- * affecting correctness.
16
- *
17
- * Failure isolation:
18
- * - Primary failure short-circuits emit and is returned to the caller.
19
- * - Relay failures never block the primary path — they surface via the
20
- * optional `onSinkError` callback so the caller can observe without
21
- * being interrupted.
22
- * - A subscriber that throws is contained; the rest of the fanout
23
- * completes normally.
24
- */
25
- var FunnelLog = class {
26
- validate;
27
- primary;
28
- relays;
29
- now;
30
- onSinkError;
31
- listeners = /* @__PURE__ */ new Set();
6
+ var FunnelLog = class extends EventLog {
32
7
  constructor(props) {
33
- this.validate = props.validate;
34
- this.primary = props.primary;
35
- this.relays = props.relays ?? [];
36
- this.now = props.now ?? (() => Date.now());
37
- this.onSinkError = props.onSinkError ?? null;
8
+ super(props);
38
9
  }
39
10
  emit(event) {
40
- const parsed = this.validate(event);
41
- if (!parsed.success) return parsed.error;
42
- const result = this.callPrimary(parsed.data);
43
- if (result instanceof Error) return result;
44
- this.fanOutToRelays(result);
45
- this.fanOutToListeners(result);
46
- return result;
47
- }
48
- subscribe(listener) {
49
- this.listeners.add(listener);
50
- return () => {
51
- this.listeners.delete(listener);
52
- };
53
- }
54
- getMaxSeq() {
55
- return this.primary.getMaxSeq();
56
- }
57
- close() {
58
- this.listeners.clear();
59
- this.callClose(this.primary);
60
- for (const relay of this.relays) this.callClose(relay);
61
- }
62
- callPrimary(event) {
63
- try {
64
- return this.primary.insert({
65
- ts: this.now(),
66
- event
67
- });
68
- } catch (e) {
69
- return e instanceof Error ? e : new Error(String(e));
70
- }
71
- }
72
- fanOutToRelays(record) {
73
- for (const relay of this.relays) {
74
- const error = this.callRelay(relay, record);
75
- if (!error) continue;
76
- if (this.onSinkError) this.onSinkError(error, record, relay);
77
- }
78
- }
79
- callRelay(relay, record) {
80
- try {
81
- const outcome = relay.write(record);
82
- return outcome instanceof Error ? outcome : null;
83
- } catch (e) {
84
- return e instanceof Error ? e : new Error(String(e));
85
- }
86
- }
87
- fanOutToListeners(record) {
88
- for (const listener of this.listeners) try {
89
- listener(record);
90
- } catch {}
91
- }
92
- callClose(sink) {
93
- if (!sink.close) return;
94
- try {
95
- sink.close();
96
- } catch {}
97
- }
98
- };
99
- //#endregion
100
- //#region lib/logger/funnel-log-memory-sink.ts
101
- /**
102
- * In-memory ring buffer that doubles as primary or relay. As primary it
103
- * owns its own seq counter (single-process only — for multi-process
104
- * safety, use `FunnelLogSqliteSink` as primary and place this as a
105
- * relay). As relay it accepts whatever seq the primary assigned and
106
- * advances its own counter to match, so `getMaxSeq` stays meaningful.
107
- *
108
- * Useful as a test double, as a short-window replay buffer paired with a
109
- * persistent primary (covering reconnects without round-tripping disk),
110
- * or as a backing store for live subscribers.
111
- */
112
- var FunnelLogMemorySink = class {
113
- capacity;
114
- buffer = [];
115
- seq = 0;
116
- constructor(props = {}) {
117
- this.capacity = Math.max(0, props.capacity ?? 1e3);
118
- }
119
- insert(input) {
120
- this.seq += 1;
121
- const record = {
122
- seq: this.seq,
123
- ts: input.ts,
124
- event: input.event
125
- };
126
- this.append(record);
127
- return record;
128
- }
129
- write(record) {
130
- if (record.seq > this.seq) this.seq = record.seq;
131
- this.append(record);
132
- }
133
- getMaxSeq() {
134
- return this.seq;
135
- }
136
- query() {
137
- return this.buffer;
138
- }
139
- clear() {
140
- this.buffer.length = 0;
141
- this.seq = 0;
142
- }
143
- append(record) {
144
- if (this.capacity === 0) return;
145
- this.buffer.push(record);
146
- if (this.buffer.length > this.capacity) this.buffer.shift();
11
+ return this.append(event);
147
12
  }
148
13
  };
149
14
  //#endregion
@@ -278,4 +143,4 @@ var FunnelTextStdoutWriter = class {
278
143
  }
279
144
  };
280
145
  //#endregion
281
- export { FunnelLog, FunnelLogMemorySink, FunnelLogSqliteSink, FunnelTextFileWriter, FunnelTextLog, FunnelTextStdoutWriter };
146
+ export { FunnelLog, MemoryEventLog as FunnelLogMemorySink, SqliteEventLog as FunnelLogSqliteSink, FunnelTextFileWriter, FunnelTextLog, FunnelTextStdoutWriter };
@@ -0,0 +1,147 @@
1
+ //#region lib/event-log/event-log.ts
2
+ /**
3
+ * Validated event log. Three responsibilities and nothing else:
4
+ * validate the event, delegate seq + persistence to the primary sink, and
5
+ * fan the resulting record out to relays and live subscribers.
6
+ *
7
+ * Splitting "primary" from "relays" makes the seq invariant honest: there
8
+ * is exactly one source of truth (the primary's atomic insert). Two
9
+ * `EventLog` instances pointed at the same SQLite file therefore see
10
+ * one monotonic stream without coordinating with each other. Relays mirror
11
+ * already-sequenced records, so they can be added or removed without
12
+ * affecting correctness.
13
+ *
14
+ * Failure isolation:
15
+ * - Primary failure short-circuits append and is returned to the caller.
16
+ * - Relay failures never block the primary path — they surface via the
17
+ * optional `onSinkError` callback so the caller can observe without
18
+ * being interrupted.
19
+ * - A subscriber that throws is contained; the rest of the fanout
20
+ * completes normally.
21
+ */
22
+ var EventLog = class {
23
+ validate;
24
+ primary;
25
+ relays;
26
+ now;
27
+ onSinkError;
28
+ listeners = /* @__PURE__ */ new Set();
29
+ constructor(props) {
30
+ this.validate = props.validate;
31
+ this.primary = props.primary;
32
+ this.relays = props.relays ?? [];
33
+ this.now = props.now ?? (() => Date.now());
34
+ this.onSinkError = props.onSinkError ?? null;
35
+ }
36
+ append(event) {
37
+ const parsed = this.validate(event);
38
+ if (!parsed.success) return parsed.error;
39
+ const result = this.callPrimary(parsed.data);
40
+ if (result instanceof Error) return result;
41
+ this.fanOutToRelays(result);
42
+ this.fanOutToListeners(result);
43
+ return result;
44
+ }
45
+ subscribe(listener) {
46
+ this.listeners.add(listener);
47
+ return () => {
48
+ this.listeners.delete(listener);
49
+ };
50
+ }
51
+ getMaxSeq() {
52
+ return this.primary.getMaxSeq();
53
+ }
54
+ close() {
55
+ this.listeners.clear();
56
+ this.callClose(this.primary);
57
+ for (const relay of this.relays) this.callClose(relay);
58
+ }
59
+ callPrimary(event) {
60
+ try {
61
+ return this.primary.insert({
62
+ ts: this.now(),
63
+ event
64
+ });
65
+ } catch (e) {
66
+ return e instanceof Error ? e : new Error(String(e));
67
+ }
68
+ }
69
+ fanOutToRelays(record) {
70
+ for (const relay of this.relays) {
71
+ const error = this.callRelay(relay, record);
72
+ if (!error) continue;
73
+ if (this.onSinkError) this.onSinkError(error, record, relay);
74
+ }
75
+ }
76
+ callRelay(relay, record) {
77
+ try {
78
+ const outcome = relay.write(record);
79
+ return outcome instanceof Error ? outcome : null;
80
+ } catch (e) {
81
+ return e instanceof Error ? e : new Error(String(e));
82
+ }
83
+ }
84
+ fanOutToListeners(record) {
85
+ for (const listener of this.listeners) try {
86
+ listener(record);
87
+ } catch {}
88
+ }
89
+ callClose(sink) {
90
+ if (!sink.close) return;
91
+ try {
92
+ sink.close();
93
+ } catch {}
94
+ }
95
+ };
96
+ //#endregion
97
+ //#region lib/event-log/memory-event-log.ts
98
+ /**
99
+ * In-memory ring buffer that doubles as primary or relay. As primary it
100
+ * owns its own seq counter (single-process only — for multi-process
101
+ * safety, use `SqliteEventLog` as primary and place this as a
102
+ * relay). As relay it accepts whatever seq the primary assigned and
103
+ * advances its own counter to match, so `getMaxSeq` stays meaningful.
104
+ *
105
+ * Useful as a test double, as a short-window replay buffer paired with a
106
+ * persistent primary (covering reconnects without round-tripping disk),
107
+ * or as a backing store for live subscribers.
108
+ */
109
+ var MemoryEventLog = class {
110
+ capacity;
111
+ buffer = [];
112
+ seq = 0;
113
+ constructor(props = {}) {
114
+ this.capacity = Math.max(0, props.capacity ?? 1e3);
115
+ }
116
+ insert(input) {
117
+ this.seq += 1;
118
+ const record = {
119
+ seq: this.seq,
120
+ ts: input.ts,
121
+ event: input.event
122
+ };
123
+ this.append(record);
124
+ return record;
125
+ }
126
+ write(record) {
127
+ if (record.seq > this.seq) this.seq = record.seq;
128
+ this.append(record);
129
+ }
130
+ getMaxSeq() {
131
+ return this.seq;
132
+ }
133
+ query() {
134
+ return this.buffer;
135
+ }
136
+ clear() {
137
+ this.buffer.length = 0;
138
+ this.seq = 0;
139
+ }
140
+ append(record) {
141
+ if (this.capacity === 0) return;
142
+ this.buffer.push(record);
143
+ if (this.buffer.length > this.capacity) this.buffer.shift();
144
+ }
145
+ };
146
+ //#endregion
147
+ export { EventLog as n, MemoryEventLog as t };
@@ -1,5 +1,5 @@
1
1
  import { n as FunnelFileSystem } from "./file-system-BNtl997T.js";
2
- import { r as FunnelChannels } from "./channels-BBA3GTAa.js";
2
+ import { r as FunnelChannels } from "./channels-B0cifCfw.js";
3
3
  import { z } from "zod";
4
4
  //#region lib/services/local-config/local-config-schema.d.ts
5
5
  declare const connectorSpecSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{