@swirls/looms 0.7.0 → 0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @swirls/looms
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f6e2758: Add `sqliteReplica` for a shared SQLite or Cloudflare D1 copy of every run. `looms replica` takes `--dialect sqlite`.
8
+
9
+ ## 0.8.0
10
+
11
+ ### Minor Changes
12
+
13
+ - ef94314: A Postgres replica copies every run into a database you own. `postgresReplica` stores the full event envelope, folds the run summary in the same transaction, and records `replicated_seq` only through a contiguous prefix, so a restored database or a replica attached mid-run catches up instead of leaving a hole. `status` reports whether that copy is complete. `purge` deletes event copies for finished runs and later deliveries skip them.
14
+
15
+ `looms replica generate` writes the versioned SQL into your migration folder (and a Drizzle journal, when you ask). `looms replica migrate` applies it. `@swirls/looms/replica/drizzle` exports the tables, and `loomsReplicaTables` adds columns your application owns.
16
+
3
17
  ## 0.7.0
4
18
 
5
19
  ### Minor Changes
@@ -5,6 +5,10 @@ import { steer as steerEvent } from '@swirls/looms/agent';
5
5
  import { decision } from '@swirls/looms/approval';
6
6
  import { createLoomsClient } from '@swirls/looms/client';
7
7
  import { stringifyJson, stringifyJsonPretty } from '@swirls/looms/core';
8
+ import { postgresReplica } from '@swirls/looms/projectors/replica';
9
+ import { generateReplicaMigrations, } from '@swirls/looms/projectors/replica/migrations';
10
+ import {} from '@swirls/looms/projectors/replica/sqlite';
11
+ import { openSqliteReplicaFile } from '@swirls/looms/projectors/replica/sqlite-bun';
8
12
  import { createLooms } from '@swirls/looms/runtime';
9
13
  const VERSION = '0.0.1';
10
14
  const urlFlag = Flag.string('url').pipe(Flag.withDescription('Looms host base URL (env LOOMS_URL)'), Flag.withFallbackConfig(Config.string('LOOMS_URL')), Flag.withDefault('http://127.0.0.1:8787'), Flag.map((url) => url.replace(/\/$/, '')));
@@ -116,7 +120,138 @@ const tail = Command.make('tail', {
116
120
  yield* Stream.fromQueue(queue).pipe(Stream.runForEach((line) => Console.log(line)));
117
121
  }));
118
122
  })).pipe(Command.withDescription('Stream events for a run'), Command.withShortDescription('Tail run events'));
119
- export const looms = loomsBase.pipe(Command.withSubcommands([serve, start, events, state, approve, replay, signal, steer, tail]));
123
+ const databaseFlag = Flag.string('database').pipe(Flag.withDescription('Postgres connection string, or a SQLite file path with --dialect sqlite (env DATABASE_URL)'), Flag.withFallbackConfig(Config.string('DATABASE_URL')));
124
+ const dialectFlag = Flag.string('dialect').pipe(Flag.withDescription('Replica dialect: postgres (default) or sqlite'), Flag.withDefault('postgres'));
125
+ function asDialect(value) {
126
+ switch (value) {
127
+ case 'postgres':
128
+ case 'sqlite':
129
+ return value;
130
+ default:
131
+ return undefined;
132
+ }
133
+ }
134
+ function openReplica(dialect, database, migrate) {
135
+ if (dialect === 'sqlite') {
136
+ const replica = openSqliteReplicaFile(database, migrate);
137
+ return {
138
+ pendingMigrations: () => replica.pendingMigrations(),
139
+ migrate: () => replica.migrate(),
140
+ status: (runId) => replica.status(runId),
141
+ dispose: () => replica.dispose?.() ?? Promise.resolve(),
142
+ };
143
+ }
144
+ const replica = postgresReplica({ url: database, migrate });
145
+ return {
146
+ pendingMigrations: () => replica.pendingMigrations(),
147
+ migrate: () => replica.migrate(),
148
+ status: (runId) => replica.status(runId),
149
+ dispose: () => replica.dispose?.() ?? Promise.resolve(),
150
+ };
151
+ }
152
+ const generate = Command.make('generate', {
153
+ out: Flag.string('out').pipe(Flag.withDescription('Directory of SQL migrations to write into')),
154
+ dialect: dialectFlag,
155
+ journal: Flag.optional(Flag.string('journal').pipe(Flag.withDescription('Also update a migration journal. Only `drizzle` is supported, and only for Postgres'))),
156
+ check: Flag.boolean('check').pipe(Flag.withDescription('Exit non-zero when a migration is pending, and write nothing'), Flag.withDefault(false)),
157
+ }, Effect.fn('replica.generate')(function* ({ out, dialect, journal, check }) {
158
+ const parsed = asDialect(dialect);
159
+ if (!parsed) {
160
+ return yield* new CliError.UserError({
161
+ cause: dialect,
162
+ userMessage: `Unknown dialect "${dialect}". Use "postgres" or "sqlite".`,
163
+ });
164
+ }
165
+ if (Option.isSome(journal) && journal.value !== 'drizzle') {
166
+ return yield* new CliError.UserError({
167
+ cause: journal.value,
168
+ userMessage: `Unknown journal "${journal.value}". Only "drizzle" is supported.`,
169
+ });
170
+ }
171
+ if (parsed === 'sqlite' && Option.isSome(journal)) {
172
+ return yield* new CliError.UserError({
173
+ cause: journal.value,
174
+ userMessage: 'Drizzle journal output is only supported for the Postgres replica.',
175
+ });
176
+ }
177
+ const generateOptions = Option.isSome(journal)
178
+ ? { out, check, dialect: parsed, journal: 'drizzle' }
179
+ : { out, check, dialect: parsed };
180
+ const result = yield* tryClient(() => generateReplicaMigrations(generateOptions));
181
+ if (check && result.pending.length > 0) {
182
+ return yield* new CliError.UserError({
183
+ cause: result.pending,
184
+ userMessage: `Pending Looms replica migrations: ${result.pending.join(', ')}`,
185
+ });
186
+ }
187
+ if (result.written.length === 0) {
188
+ return yield* Console.log('Looms replica migrations are up to date');
189
+ }
190
+ for (const filename of result.written) {
191
+ yield* Console.log(filename);
192
+ }
193
+ return yield* Effect.void;
194
+ })).pipe(Command.withDescription('Write replica migrations the host does not already have'), Command.withShortDescription('Write replica SQL'));
195
+ const migrate = Command.make('migrate', { database: databaseFlag, dialect: dialectFlag }, Effect.fn('replica.migrate')(function* ({ database, dialect }) {
196
+ const parsed = asDialect(dialect);
197
+ if (!parsed) {
198
+ return yield* new CliError.UserError({
199
+ cause: dialect,
200
+ userMessage: `Unknown dialect "${dialect}". Use "postgres" or "sqlite".`,
201
+ });
202
+ }
203
+ if (parsed === 'sqlite' && /^postgres(ql)?:\/\//.test(database)) {
204
+ return yield* new CliError.UserError({
205
+ cause: database,
206
+ userMessage: 'SQLite replica --database is a file path, not a Postgres URL.',
207
+ });
208
+ }
209
+ const replica = openReplica(parsed, database, 'auto');
210
+ yield* tryClient(() => replica.migrate().then(() => replica.dispose()));
211
+ return yield* Console.log('Looms replica migrations applied');
212
+ })).pipe(Command.withDescription('Apply pending replica migrations'), Command.withShortDescription('Apply replica SQL'));
213
+ const status = Command.make('status', {
214
+ database: databaseFlag,
215
+ dialect: dialectFlag,
216
+ run: Flag.optional(Flag.string('run').pipe(Flag.withDescription('Also print freshness for this run id'))),
217
+ }, Effect.fn('replica.status')(function* ({ database, dialect, run }) {
218
+ const parsed = asDialect(dialect);
219
+ if (!parsed) {
220
+ return yield* new CliError.UserError({
221
+ cause: dialect,
222
+ userMessage: `Unknown dialect "${dialect}". Use "postgres" or "sqlite".`,
223
+ });
224
+ }
225
+ if (parsed === 'sqlite' && /^postgres(ql)?:\/\//.test(database)) {
226
+ return yield* new CliError.UserError({
227
+ cause: database,
228
+ userMessage: 'SQLite replica --database is a file path, not a Postgres URL.',
229
+ });
230
+ }
231
+ const replica = openReplica(parsed, database, 'verify');
232
+ const pending = yield* tryClient(() => replica.pendingMigrations());
233
+ yield* Console.log(pending.length === 0
234
+ ? 'Looms replica schema is up to date'
235
+ : `Pending Looms replica migrations: ${pending.join(', ')}`);
236
+ if (Option.isSome(run)) {
237
+ const row = yield* tryClient(() => replica.status(run.value));
238
+ yield* Console.log(row ? stringifyJson(row) : `No replica row for ${run.value}`);
239
+ }
240
+ return yield* tryClient(() => replica.dispose());
241
+ })).pipe(Command.withDescription('Show which replica migrations are applied'), Command.withShortDescription('Replica schema status'));
242
+ const replica = Command.make('replica').pipe(Command.withDescription('Copy runs into a Postgres or SQLite database you own'), Command.withShortDescription('Event replica'), Command.withSubcommands([generate, migrate, status]));
243
+ export const looms = loomsBase.pipe(Command.withSubcommands([
244
+ serve,
245
+ start,
246
+ events,
247
+ state,
248
+ approve,
249
+ replay,
250
+ signal,
251
+ steer,
252
+ tail,
253
+ replica,
254
+ ]));
120
255
  export const cliTestLayer = Layer.mergeAll(FileSystem.layerNoop({}), Path.layer, Stdio.layerTest({}), Layer.succeed(Terminal.Terminal, Terminal.make({
121
256
  columns: Effect.succeed(80),
122
257
  rows: Effect.succeed(24),
@@ -1,4 +1,4 @@
1
- import { Effect } from 'effect';
1
+ import { Cause, Effect } from 'effect';
2
2
  import type { EventStore, EventStoreError } from '@swirls/looms/core';
3
3
  import { type Projector } from './projector';
4
4
  export type ProjectorDeliveryState = 'idle' | 'retrying' | 'dead-letter';
@@ -14,7 +14,7 @@ export interface ProjectorDeliveryStatus {
14
14
  readonly lastError: string | null;
15
15
  readonly updatedAt: number;
16
16
  }
17
- declare const ProjectorCursorError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
17
+ declare const ProjectorCursorError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
18
18
  readonly _tag: "ProjectorCursorError";
19
19
  } & Readonly<A>;
20
20
  export declare class ProjectorCursorError extends ProjectorCursorError_base<{
@@ -24,6 +24,11 @@ export declare class ProjectorCursorError extends ProjectorCursorError_base<{
24
24
  export interface ProjectorCursorStore {
25
25
  get(runId: string, projector: Projector): Effect.Effect<ProjectorDeliveryStatus, ProjectorCursorError>;
26
26
  advance(runId: string, projector: Projector, cursor: number, now: number): Effect.Effect<void, ProjectorCursorError>;
27
+ /**
28
+ * Set the cursor to an earlier sequence. `advance` never moves backwards, so a
29
+ * projector whose copy is behind the saved cursor uses this to catch up.
30
+ */
31
+ rewind(runId: string, projector: Projector, cursor: number, now: number): Effect.Effect<void, ProjectorCursorError>;
27
32
  fail(runId: string, projector: Projector, failure: {
28
33
  readonly attempts: number;
29
34
  readonly failedSeq: number;
@@ -34,7 +39,7 @@ export interface ProjectorCursorStore {
34
39
  requeue(runId: string, projector: Projector, now: number): Effect.Effect<void, ProjectorCursorError>;
35
40
  list(runId?: string): Effect.Effect<readonly ProjectorDeliveryStatus[], ProjectorCursorError>;
36
41
  }
37
- declare const UnknownProjectorError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
42
+ declare const UnknownProjectorError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
38
43
  readonly _tag: "UnknownProjectorError";
39
44
  } & Readonly<A>;
40
45
  export declare class UnknownProjectorError extends UnknownProjectorError_base<{
@@ -1,4 +1,4 @@
1
- import { Data, Effect, Semaphore } from 'effect';
1
+ import { Cause, Data, Effect, Semaphore } from 'effect';
2
2
  import { runProjectorEffect } from './projector.js';
3
3
  export class ProjectorCursorError extends Data.TaggedError('ProjectorCursorError') {
4
4
  }
@@ -10,10 +10,22 @@ function projectorIdentity(projector) {
10
10
  class ProjectorDeliveryError extends Data.TaggedError('ProjectorDeliveryError') {
11
11
  }
12
12
  function normalizeError(cause) {
13
+ const error = Cause.isCause(cause) ? Cause.squash(cause) : cause;
13
14
  return new ProjectorDeliveryError({
14
- message: cause instanceof Error ? cause.message : String(cause),
15
+ message: error instanceof Error ? error.message : String(error),
15
16
  });
16
17
  }
18
+ function idleStatus(status, cursor) {
19
+ return {
20
+ ...status,
21
+ cursor,
22
+ state: 'idle',
23
+ attempts: 0,
24
+ failedSeq: null,
25
+ nextRetryAt: null,
26
+ lastError: null,
27
+ };
28
+ }
17
29
  export function createProjectorDelivery(source, projectors, cursors, options = {}) {
18
30
  const batchSize = options.batchSize ?? 100;
19
31
  const initialRetryMs = options.initialRetryMs ?? 1_000;
@@ -86,6 +98,21 @@ export function createProjectorDelivery(source, projectors, cursors, options = {
86
98
  yield* recordFailure(runId, projector, status, status.cursor + 1, normalizeError(initialization.cause));
87
99
  return;
88
100
  }
101
+ const readPosition = projector.position;
102
+ if (readPosition) {
103
+ const aligned = yield* Effect.tryPromise({
104
+ try: () => readPosition(runId),
105
+ catch: normalizeError,
106
+ }).pipe(Effect.exit);
107
+ if (aligned._tag === 'Failure') {
108
+ yield* recordFailure(runId, projector, status, status.cursor + 1, normalizeError(aligned.cause));
109
+ return;
110
+ }
111
+ if (aligned.value !== null && aligned.value < status.cursor) {
112
+ yield* cursors.rewind(runId, projector, aligned.value, now());
113
+ status = idleStatus(status, aligned.value);
114
+ }
115
+ }
89
116
  while (true) {
90
117
  const events = yield* source.read(runId, {
91
118
  fromSeq: status.cursor + 1,
@@ -0,0 +1,68 @@
1
+ import { type EventEnvelope, type EventOrigin, type JsonValue, type RunStatus } from '@swirls/looms/core';
2
+ export interface EventLogEntry {
3
+ readonly runId: string;
4
+ readonly seq: number;
5
+ readonly eventId: string;
6
+ readonly ts: number;
7
+ readonly type: string;
8
+ readonly payload: JsonValue;
9
+ readonly threadId: string | null;
10
+ readonly parentThreadId: string | null;
11
+ readonly causationId: string | null;
12
+ readonly correlationId: string | null;
13
+ readonly effectId: string | null;
14
+ readonly origin: EventOrigin;
15
+ readonly idempotencyKey: string | null;
16
+ }
17
+ export interface RunLogRow {
18
+ readonly runId: string;
19
+ readonly status: RunStatus;
20
+ readonly kind: string | null;
21
+ readonly definitionName: string | null;
22
+ readonly definitionVersion: string | null;
23
+ readonly rootThreadId: string | null;
24
+ readonly parentRunId: string | null;
25
+ readonly launchedByEffectId: string | null;
26
+ readonly correlationId: string | null;
27
+ readonly attributes: {
28
+ readonly [key: string]: string;
29
+ };
30
+ readonly tenant: string | null;
31
+ readonly project: string | null;
32
+ readonly org: string | null;
33
+ readonly startedAt: number | null;
34
+ readonly updatedAt: number;
35
+ readonly completedAt: number | null;
36
+ }
37
+ export type EventLogOp = {
38
+ readonly type: 'insert';
39
+ readonly entry: EventLogEntry;
40
+ } | {
41
+ readonly type: 'start';
42
+ readonly runId: string;
43
+ readonly kind: string | null;
44
+ readonly definitionName: string | null;
45
+ readonly definitionVersion: string | null;
46
+ readonly rootThreadId: string | null;
47
+ readonly parentRunId: string | null;
48
+ readonly launchedByEffectId: string | null;
49
+ readonly correlationId: string | null;
50
+ readonly attributes: {
51
+ readonly [key: string]: string;
52
+ };
53
+ readonly tenant: string | null;
54
+ readonly project: string | null;
55
+ readonly org: string | null;
56
+ readonly at: number;
57
+ } | {
58
+ readonly type: 'finish';
59
+ readonly runId: string;
60
+ readonly status: 'completed' | 'failed' | 'cancelled';
61
+ readonly at: number;
62
+ } | {
63
+ readonly type: 'touch';
64
+ readonly runId: string;
65
+ readonly at: number;
66
+ };
67
+ /** Fold one durable event into event-row and run-summary operations. Ephemeral events produce nothing. */
68
+ export declare function eventLogOps(event: EventEnvelope): readonly EventLogOp[];
@@ -0,0 +1,79 @@
1
+ import { Option, Predicate, Schema } from 'effect';
2
+ import { completedRunStatus, isJsonObject, readRunLaunchSource, } from '@swirls/looms/core';
3
+ const decodeAttributes = Schema.decodeUnknownOption(Schema.Record(Schema.String, Schema.String));
4
+ /** Fold one durable event into event-row and run-summary operations. Ephemeral events produce nothing. */
5
+ export function eventLogOps(event) {
6
+ if (event.ephemeral) {
7
+ return [];
8
+ }
9
+ const entry = {
10
+ runId: event.runId,
11
+ seq: event.seq,
12
+ eventId: event.id,
13
+ ts: event.ts,
14
+ type: event.type,
15
+ payload: event.payload,
16
+ threadId: event.threadId,
17
+ parentThreadId: event.parentThreadId ?? null,
18
+ causationId: event.causationId ?? null,
19
+ correlationId: event.correlationId ?? null,
20
+ effectId: event.effectId ?? null,
21
+ origin: event.origin,
22
+ idempotencyKey: event.idempotencyKey ?? null,
23
+ };
24
+ const payload = isJsonObject(event.payload) ? event.payload : {};
25
+ switch (event.type) {
26
+ case 'runtime.run.started':
27
+ return [{ type: 'insert', entry }, startOp(event, payload)];
28
+ case 'runtime.run.completed':
29
+ return [
30
+ { type: 'insert', entry },
31
+ {
32
+ type: 'finish',
33
+ runId: event.runId,
34
+ status: completedRunStatus(event.payload),
35
+ at: event.ts,
36
+ },
37
+ ];
38
+ case 'runtime.run.cancelled':
39
+ return [
40
+ { type: 'insert', entry },
41
+ { type: 'finish', runId: event.runId, status: 'cancelled', at: event.ts },
42
+ ];
43
+ default:
44
+ return [
45
+ { type: 'insert', entry },
46
+ { type: 'touch', runId: event.runId, at: event.ts },
47
+ ];
48
+ }
49
+ }
50
+ function startOp(event, payload) {
51
+ const launchedBy = readRunLaunchSource(payload.launchedBy === undefined ? undefined : payload.launchedBy);
52
+ const attributes = readAttributes(payload.attributes);
53
+ return {
54
+ type: 'start',
55
+ runId: event.runId,
56
+ kind: readString(payload, 'kind'),
57
+ definitionName: readString(payload, 'definitionName'),
58
+ definitionVersion: readString(payload, 'definitionVersion'),
59
+ rootThreadId: readString(payload, 'rootThreadId'),
60
+ parentRunId: launchedBy?.runId ?? null,
61
+ launchedByEffectId: launchedBy?.effectId ?? null,
62
+ correlationId: event.correlationId ?? null,
63
+ attributes,
64
+ tenant: attributes.tenant ?? null,
65
+ project: attributes.project ?? null,
66
+ org: attributes.org ?? null,
67
+ at: event.ts,
68
+ };
69
+ }
70
+ function readString(payload, key) {
71
+ const value = payload[key];
72
+ return Predicate.isString(value) ? value : null;
73
+ }
74
+ function readAttributes(value) {
75
+ if (value === undefined) {
76
+ return {};
77
+ }
78
+ return Option.getOrElse(decodeAttributes(value), () => ({}));
79
+ }
@@ -1,72 +1,10 @@
1
- import { type Sql } from 'postgres';
2
- import { type EventEnvelope, type EventOrigin, type EventStore, type JsonValue, type RunStatus } from '@swirls/looms/core';
1
+ import { type Sql, type TransactionSql } from 'postgres';
2
+ import { type EventEnvelope, type EventStore } from '@swirls/looms/core';
3
+ import { eventLogOps, type EventLogEntry, type EventLogOp, type RunLogRow } from './event-log-ops';
3
4
  import type { Projector } from './projector';
4
- export declare const POSTGRES_EVENT_LOG_SCHEMA_SQL: string;
5
- export interface EventLogEntry {
6
- readonly runId: string;
7
- readonly seq: number;
8
- readonly eventId: string;
9
- readonly ts: number;
10
- readonly type: string;
11
- readonly payload: JsonValue;
12
- readonly threadId: string | null;
13
- readonly parentThreadId: string | null;
14
- readonly causationId: string | null;
15
- readonly correlationId: string | null;
16
- readonly effectId: string | null;
17
- readonly origin: EventOrigin;
18
- readonly idempotencyKey: string | null;
19
- }
20
- export interface RunLogRow {
21
- readonly runId: string;
22
- readonly status: RunStatus;
23
- readonly kind: string | null;
24
- readonly definitionName: string | null;
25
- readonly definitionVersion: string | null;
26
- readonly rootThreadId: string | null;
27
- readonly parentRunId: string | null;
28
- readonly launchedByEffectId: string | null;
29
- readonly correlationId: string | null;
30
- readonly attributes: {
31
- readonly [key: string]: string;
32
- };
33
- readonly tenant: string | null;
34
- readonly project: string | null;
35
- readonly org: string | null;
36
- readonly startedAt: number | null;
37
- readonly updatedAt: number;
38
- readonly completedAt: number | null;
39
- }
40
- export type EventLogOp = {
41
- readonly type: 'insert';
42
- readonly entry: EventLogEntry;
43
- } | {
44
- readonly type: 'start';
45
- readonly runId: string;
46
- readonly kind: string | null;
47
- readonly definitionName: string | null;
48
- readonly definitionVersion: string | null;
49
- readonly rootThreadId: string | null;
50
- readonly parentRunId: string | null;
51
- readonly launchedByEffectId: string | null;
52
- readonly correlationId: string | null;
53
- readonly attributes: {
54
- readonly [key: string]: string;
55
- };
56
- readonly tenant: string | null;
57
- readonly project: string | null;
58
- readonly org: string | null;
59
- readonly at: number;
60
- } | {
61
- readonly type: 'finish';
62
- readonly runId: string;
63
- readonly status: 'completed' | 'failed' | 'cancelled';
64
- readonly at: number;
65
- } | {
66
- readonly type: 'touch';
67
- readonly runId: string;
68
- readonly at: number;
69
- };
5
+ import { POSTGRES_EVENT_LOG_SCHEMA_SQL } from './replica/migrations';
6
+ export { POSTGRES_EVENT_LOG_SCHEMA_SQL, eventLogOps };
7
+ export type { EventLogEntry, EventLogOp, RunLogRow };
70
8
  export interface EventLogProjector extends Projector {
71
9
  /** Replays the source log into this sink. Safe to repeat; do not run it beside live delivery. */
72
10
  rebuild(source: EventStore, options?: {
@@ -78,10 +16,14 @@ export interface MemoryEventLog extends EventLogProjector {
78
16
  events(runId: string): readonly EventLogEntry[];
79
17
  run(runId: string): RunLogRow | null;
80
18
  }
81
- export declare function eventLogOps(event: EventEnvelope): readonly EventLogOp[];
82
19
  export declare function memoryEventLog(): MemoryEventLog;
83
20
  export declare function postgresEventLog(options: {
84
21
  url: string;
85
22
  } | {
86
23
  sql: Sql;
87
24
  }): EventLogProjector;
25
+ export declare function applySqlOps(sql: TransactionSql, ops: readonly EventLogOp[]): Promise<void>;
26
+ /** Fold run-summary ops. Event rows are written by {@link insertRunEvents}. */
27
+ export declare function applyRunIndexOps(sql: TransactionSql, ops: readonly EventLogOp[]): Promise<void>;
28
+ /** Insert event envelopes, including ephemeral ones. Durable callers pass events that are already filtered. */
29
+ export declare function insertRunEvents(sql: TransactionSql, events: readonly EventEnvelope[]): Promise<void>;