@chkit/plugin-ingest 0.2.0-beta.11

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 (70) hide show
  1. package/README.md +43 -0
  2. package/dist/destination.d.ts +40 -0
  3. package/dist/destination.d.ts.map +1 -0
  4. package/dist/destination.js +65 -0
  5. package/dist/destination.js.map +1 -0
  6. package/dist/errors.d.ts +33 -0
  7. package/dist/errors.d.ts.map +1 -0
  8. package/dist/errors.js +133 -0
  9. package/dist/errors.js.map +1 -0
  10. package/dist/executor.d.ts +30 -0
  11. package/dist/executor.d.ts.map +1 -0
  12. package/dist/executor.js +552 -0
  13. package/dist/executor.js.map +1 -0
  14. package/dist/incremental.d.ts +45 -0
  15. package/dist/incremental.d.ts.map +1 -0
  16. package/dist/incremental.js +72 -0
  17. package/dist/incremental.js.map +1 -0
  18. package/dist/index.d.ts +12 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +11 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/journal-history.d.ts +15 -0
  23. package/dist/journal-history.d.ts.map +1 -0
  24. package/dist/journal-history.js +366 -0
  25. package/dist/journal-history.js.map +1 -0
  26. package/dist/journal-records.d.ts +28 -0
  27. package/dist/journal-records.d.ts.map +1 -0
  28. package/dist/journal-records.js +76 -0
  29. package/dist/journal-records.js.map +1 -0
  30. package/dist/journal.d.ts +16 -0
  31. package/dist/journal.d.ts.map +1 -0
  32. package/dist/journal.js +72 -0
  33. package/dist/journal.js.map +1 -0
  34. package/dist/loader.d.ts +12 -0
  35. package/dist/loader.d.ts.map +1 -0
  36. package/dist/loader.js +37 -0
  37. package/dist/loader.js.map +1 -0
  38. package/dist/paginate.d.ts +24 -0
  39. package/dist/paginate.d.ts.map +1 -0
  40. package/dist/paginate.js +37 -0
  41. package/dist/paginate.js.map +1 -0
  42. package/dist/plugin.d.ts +155 -0
  43. package/dist/plugin.d.ts.map +1 -0
  44. package/dist/plugin.js +353 -0
  45. package/dist/plugin.js.map +1 -0
  46. package/dist/queue.d.ts +9 -0
  47. package/dist/queue.d.ts.map +1 -0
  48. package/dist/queue.js +47 -0
  49. package/dist/queue.js.map +1 -0
  50. package/dist/recovery.d.ts +41 -0
  51. package/dist/recovery.d.ts.map +1 -0
  52. package/dist/recovery.js +145 -0
  53. package/dist/recovery.js.map +1 -0
  54. package/dist/registry.d.ts +48 -0
  55. package/dist/registry.d.ts.map +1 -0
  56. package/dist/registry.js +109 -0
  57. package/dist/registry.js.map +1 -0
  58. package/dist/retry.d.ts +12 -0
  59. package/dist/retry.d.ts.map +1 -0
  60. package/dist/retry.js +69 -0
  61. package/dist/retry.js.map +1 -0
  62. package/dist/testing.d.ts +18 -0
  63. package/dist/testing.d.ts.map +1 -0
  64. package/dist/testing.js +54 -0
  65. package/dist/testing.js.map +1 -0
  66. package/dist/types.d.ts +229 -0
  67. package/dist/types.d.ts.map +1 -0
  68. package/dist/types.js +2 -0
  69. package/dist/types.js.map +1 -0
  70. package/package.json +56 -0
@@ -0,0 +1,552 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { setTimeout as sleep } from 'node:timers/promises';
3
+ import { SpanStatusCode, trace } from '@opentelemetry/api';
4
+ import pLimit from 'p-limit';
5
+ import pRetry, { AbortError } from 'p-retry';
6
+ import { toJsonRows } from './destination.js';
7
+ import { BudgetExhausted, classifyFailure, FetchFailure, IngestConfigError } from './errors.js';
8
+ import { canonicalJson, digest, emptyCheckpoint } from './journal.js';
9
+ import { simpleLoader } from './loader.js';
10
+ import { createBoundedQueue } from './queue.js';
11
+ import { mergeRetry, runAttempt } from './retry.js';
12
+ // Run facts are correlation only, so each run owns its own namespace: two
13
+ // overlapping processes never share the telemetry namespace.
14
+ const RUN_NAMESPACE_PREFIX = '@run:';
15
+ const DEFAULT_BATCH_SIZE = 10_000;
16
+ const DEFAULT_PREFETCH_BATCHES = 1;
17
+ const DEFAULT_MAX_DURATION_MS = 60 * 60_000;
18
+ const LOAD_ATTEMPTS = 3;
19
+ const JOURNAL_APPEND_ATTEMPTS = 4;
20
+ // Terminal facts get a bounded chance to land even after the execution is interrupted.
21
+ const TERMINAL_JOURNAL_TIMEOUT_MS = 5000;
22
+ const DEFAULT_MAX_CHUNK_ROWS = 100_000;
23
+ // How long a failed stream waits for an uncooperative reader before abandoning it.
24
+ const READER_SHUTDOWN_GRACE_MS = 5000;
25
+ const tracer = trace.getTracer('@chkit/plugin-ingest');
26
+ /**
27
+ * One transient execution context for one exact stream selection. The run id
28
+ * correlates journal and telemetry evidence only: every stream plans and
29
+ * recovers independently from its own journal-backed checkpoint.
30
+ */
31
+ export async function runIngestion(request, input) {
32
+ const deadline = new AbortController();
33
+ const env = resolveEnv(input, deadline.signal);
34
+ // The budget is a real bound: it interrupts hung readers, retry timers and waits.
35
+ const deadlineTimer = setTimeout(() => deadline.abort(new BudgetExhausted('execution budget exhausted')), env.maxDurationMs);
36
+ const runId = randomUUID();
37
+ const cutoff = env.now();
38
+ const streamIds = request.selected.map((entry) => entry.stream.id);
39
+ return tracer.startActiveSpan('chkit.ingest.execution', async (span) => {
40
+ span.setAttribute('chkit.ingest.run_id', runId);
41
+ span.setAttribute('chkit.ingest.stream_ids', streamIds);
42
+ try {
43
+ await abortable(() => env.journal.ensure(), env.signal);
44
+ await appendRunEvent(env, runEvent(1, 'run_started', runId, '', {
45
+ streamIds,
46
+ cutoff: cutoff.toISOString(),
47
+ backfill: request.backfill?.id,
48
+ }), env.signal);
49
+ const permits = new Map();
50
+ const streams = await Promise.all(request.selected.map((entry) => executeSelectedStream(entry, permitsFor(permits, entry.pipeline), request.backfill, runId, cutoff, env)));
51
+ const ok = streams.every((stream) => stream.outcome === 'succeeded');
52
+ await appendRunEvent(env, runEvent(2, 'run_finished', runId, ok ? 'succeeded' : 'failed', {
53
+ outcomes: Object.fromEntries(streams.map((stream) => [stream.namespaceId, stream.outcome])),
54
+ }), terminalSignal(env.signal));
55
+ if (!ok)
56
+ span.setStatus({ code: SpanStatusCode.ERROR });
57
+ return { runId, cutoff: cutoff.toISOString(), streams, ok };
58
+ }
59
+ finally {
60
+ clearTimeout(deadlineTimer);
61
+ span.end();
62
+ }
63
+ });
64
+ }
65
+ // An ordinary failure in one stream never prevents unrelated selected streams
66
+ // from being attempted: every failure is folded into that stream's result.
67
+ async function executeSelectedStream(entry, permits, backfill, runId, cutoff, env) {
68
+ const { stream, pipeline } = entry;
69
+ const namespaceId = backfill ? `${stream.id}#backfill:${backfill.id}` : stream.id;
70
+ const progress = { base: emptyCheckpoint(), startedAt: cutoff.toISOString(), seq: 0, appendChain: Promise.resolve(), version: 0, checkpointId: '', successId: '', envelope: undefined, rows: 0, batches: 0, chunks: 0 };
71
+ const result = (outcome, error) => ({
72
+ streamId: stream.id,
73
+ pipelineId: pipeline.id,
74
+ namespaceId,
75
+ outcome,
76
+ rows: progress.rows,
77
+ batches: progress.batches,
78
+ chunks: progress.chunks,
79
+ checkpointVersion: progress.version,
80
+ error,
81
+ });
82
+ return permits.streams(async () => {
83
+ if (env.signal.aborted) {
84
+ return result(env.hostSignal.aborted ? 'cancelled' : 'budget_exhausted', 'execution interrupted before start');
85
+ }
86
+ return tracer.startActiveSpan('chkit.ingest.stream', async (span) => {
87
+ span.setAttribute('chkit.ingest.stream_id', stream.id);
88
+ span.setAttribute('chkit.ingest.namespace_id', namespaceId);
89
+ try {
90
+ const outcome = await executeStream({ stream, pipeline, namespaceId, backfill, runId, cutoff, permits, progress, env });
91
+ env.log?.(`${namespaceId}: ${outcome} (${progress.rows} rows, ${progress.batches} batches, checkpoint v${progress.version})`);
92
+ return result(outcome, undefined);
93
+ }
94
+ catch (error) {
95
+ const message = error instanceof Error ? error.message : String(error);
96
+ const outcome = env.hostSignal.aborted ? 'cancelled' : env.signal.aborted ? 'budget_exhausted' : 'failed';
97
+ recordFailure(span, error);
98
+ env.log?.(`${namespaceId}: ${outcome} — ${message}`);
99
+ return result(outcome, message);
100
+ }
101
+ finally {
102
+ span.end();
103
+ }
104
+ });
105
+ });
106
+ }
107
+ async function executeStream(input) {
108
+ const { stream, pipeline, namespaceId, progress, env } = input;
109
+ const committed = await abortable(() => env.journal.readCheckpoint(namespaceId), env.signal);
110
+ progress.base = committed;
111
+ progress.version = committed.version;
112
+ progress.checkpointId = committed.checkpointId;
113
+ progress.successId = committed.successId;
114
+ progress.envelope = committed.envelope;
115
+ const retry = mergeRetry(pipeline.retry, stream.retry);
116
+ let workId = '';
117
+ let outcome = 'failed';
118
+ let failure;
119
+ try {
120
+ outcome = await runAttempt(async (attemptNo) => {
121
+ // Re-plan from the latest durable boundary on every reader (re)creation.
122
+ const state = restoreState(stream, progress.envelope, namespaceId);
123
+ const selection = stream.incremental.plan({
124
+ state,
125
+ cutoff: input.cutoff,
126
+ range: input.backfill ? { from: input.backfill.from, to: input.backfill.to } : undefined,
127
+ });
128
+ const nextWorkId = digest([namespaceId, progress.successId, progress.checkpointId, canonicalJson(selection)]).slice(0, 24);
129
+ // A newly planned unit of work and its first attempt share one insert.
130
+ const planned = nextWorkId === workId ? [] : [{
131
+ eventKind: 'work_planned',
132
+ fields: { workId: nextWorkId, workState: 'planned', detail: { selection, strategy: stream.incremental.id, strategyVersion: stream.incremental.version, pipelineId: pipeline.id } },
133
+ }];
134
+ workId = nextWorkId;
135
+ await appendFacts(input, [...planned, { eventKind: 'attempt_started', fields: { workId, attemptNo, workState: 'running' } }]);
136
+ return readAndLoad({ ...input, workId, attemptNo, state, selection, retry });
137
+ }, {
138
+ ...retry,
139
+ // Reader recreation consumes the same execution-wide chunk budget.
140
+ // Preserve the original failure when no further chunks may be pulled.
141
+ shouldRetry: (context) => progress.chunks < (stream.budget?.maxChunks ?? Infinity) && (retry.shouldRetry?.(context) ?? true),
142
+ }, {
143
+ signal: env.signal,
144
+ classifier: stream.classifyError,
145
+ onRetry: (context, retryAfterMs) => append(input, 'retry_scheduled', {
146
+ workId,
147
+ attemptNo: context.attemptNumber,
148
+ retryAt: retryAfterMs === undefined ? undefined : new Date(env.now().getTime() + retryAfterMs),
149
+ errorClass: context.error.classification.kind,
150
+ detail: { error: context.error.message },
151
+ }),
152
+ });
153
+ }
154
+ catch (error) {
155
+ failure = error;
156
+ if (env.signal.aborted) {
157
+ outcome = env.hostSignal.aborted ? 'cancelled' : 'budget_exhausted';
158
+ // Exhausting the budget is incomplete: committed progress stands.
159
+ if (outcome === 'budget_exhausted')
160
+ failure = undefined;
161
+ }
162
+ }
163
+ await append(input, 'work_finished', {
164
+ workId,
165
+ workState: failure === undefined ? outcome : outcome === 'cancelled' ? 'cancelled' : 'failed',
166
+ errorClass: failure === undefined ? '' : failureKind(failure, env.signal, stream),
167
+ detail: { rows: progress.rows, batches: progress.batches, chunks: progress.chunks, error: failure === undefined ? undefined : messageOf(failure) },
168
+ });
169
+ if (failure !== undefined)
170
+ throw failure;
171
+ return outcome;
172
+ }
173
+ /**
174
+ * Pull the reader through a finite buffer into the loader. Exactly one next()
175
+ * is pending at a time, and source progress is appended to the journal only
176
+ * after the covering rows have sink evidence.
177
+ */
178
+ async function readAndLoad(input) {
179
+ const { stream, namespaceId, progress, env } = input;
180
+ const maxChunks = stream.budget?.maxChunks ?? Infinity;
181
+ if (progress.chunks >= maxChunks)
182
+ return 'budget_exhausted';
183
+ const local = new AbortController();
184
+ const signal = AbortSignal.any([env.signal, local.signal]);
185
+ const queue = createBoundedQueue(env.prefetchBatches);
186
+ const batchSize = stream.batchSize ?? DEFAULT_BATCH_SIZE;
187
+ let budgetExhausted = false;
188
+ // Set once this attempt has reported its outcome: detached work that finishes
189
+ // later may have written rows (at-least-once) but must never commit progress.
190
+ let abandoned = false;
191
+ const produce = async () => {
192
+ let pending = emptyBatch();
193
+ const reader = stream.read({
194
+ streamId: stream.id,
195
+ selection: input.selection,
196
+ state: input.state,
197
+ cutoff: input.cutoff,
198
+ signal,
199
+ attempt: (operation, options) => runAttempt(() => input.permits.fetches(() => {
200
+ signal.throwIfAborted();
201
+ return operation(signal);
202
+ }), input.retry, {
203
+ signal,
204
+ classifier: stream.classifyError,
205
+ onRetry: (context, retryAfterMs) => append(input, 'retry_scheduled', {
206
+ workId: input.workId,
207
+ attemptNo: input.attemptNo,
208
+ // p-retry owns the randomized backoff; record only a provider's known not-before time.
209
+ retryAt: retryAfterMs === undefined ? undefined : new Date(env.now().getTime() + retryAfterMs),
210
+ errorClass: context.error.classification.kind,
211
+ detail: { label: options?.label ?? 'source', sourceAttempt: context.attemptNumber, error: context.error.message },
212
+ }),
213
+ }),
214
+ });
215
+ // Iterate by hand so a hung next() can be abandoned on abort; return() still
216
+ // runs on every exit so the reader's finally blocks own cursor cleanup.
217
+ const iterator = reader[Symbol.asyncIterator]();
218
+ const maxChunkRows = stream.budget?.maxChunkRows ?? DEFAULT_MAX_CHUNK_ROWS;
219
+ try {
220
+ while (!budgetExhausted) {
221
+ const step = await abortable(() => iterator.next(), signal);
222
+ if (step.done)
223
+ break;
224
+ const chunk = step.value;
225
+ assertValidChunk(stream.id, chunk, maxChunkRows);
226
+ progress.chunks += 1;
227
+ // A chunk that declares its source interval is one logical write unit:
228
+ // it is never merged with neighbours, so a replay regroups identically
229
+ // even when row counts changed.
230
+ if (chunk.id !== undefined && pending.rows.length > 0) {
231
+ await queue.push(pending, signal);
232
+ pending = emptyBatch();
233
+ }
234
+ pending.rows.push(...chunk.rows);
235
+ if (pending.intervalIds) {
236
+ if (chunk.id === undefined)
237
+ pending.intervalIds = undefined;
238
+ else
239
+ pending.intervalIds.push(chunk.id);
240
+ }
241
+ if (chunk.state !== undefined)
242
+ pending.state = { value: chunk.state };
243
+ if (chunk.id !== undefined || pending.rows.length >= batchSize) {
244
+ await queue.push(pending, signal);
245
+ pending = emptyBatch();
246
+ }
247
+ if (progress.chunks >= maxChunks)
248
+ budgetExhausted = true;
249
+ }
250
+ }
251
+ finally {
252
+ // Never await an uncooperative reader: cleanup is best effort once we leave.
253
+ void Promise.resolve(iterator.return?.()).catch(() => undefined);
254
+ }
255
+ // Only a fully consumed selection may claim the strategy's completion state.
256
+ if (!budgetExhausted) {
257
+ const completed = stream.incremental.complete?.({ state: input.state, selection: input.selection });
258
+ if (completed !== undefined)
259
+ pending.state = { value: completed };
260
+ }
261
+ if (pending.rows.length > 0 || pending.state !== undefined)
262
+ await queue.push(pending, signal);
263
+ queue.close();
264
+ };
265
+ const consume = async () => {
266
+ // Batch identity uses the last successful sync and checkpoint identities,
267
+ // plus the batch's position since that boundary, so a
268
+ // replay in a fresh process reproduces the same id and deduplication token.
269
+ // Declared source-interval ids complete the identity; without them a
270
+ // content hash does, preferring a possible duplicate over suppressing rows
271
+ // that changed between attempts.
272
+ let sinceBoundary = 0;
273
+ for (let batch = await queue.pop(signal); batch !== undefined; batch = await queue.pop(signal)) {
274
+ const discriminator = batch.intervalIds ? `interval:${canonicalJson(batch.intervalIds)}` : `content:${canonicalJson(toJsonRows(batch.rows))}`;
275
+ const batchId = digest([namespaceId, progress.successId, progress.checkpointId, String(sinceBoundary), discriminator]).slice(0, 32);
276
+ const receipt = await loadBatch(input, batchId, batch.rows, signal);
277
+ if (abandoned)
278
+ return;
279
+ const envelope = batch.state
280
+ ? { strategy: stream.incremental.id, version: stream.incremental.version, state: batch.state.value }
281
+ : progress.envelope;
282
+ const advanced = canonicalJson(envelope ?? null) !== canonicalJson(progress.envelope ?? null);
283
+ const expected = progress.version;
284
+ const version = advanced ? expected + 1 : expected;
285
+ await append(input, 'batch_committed', {
286
+ workId: input.workId,
287
+ attemptNo: input.attemptNo,
288
+ batchId,
289
+ expectedCheckpointVersion: expected,
290
+ checkpointVersion: version,
291
+ checkpoint: envelope,
292
+ sinkEvidence: receipt.evidence,
293
+ detail: { rows: receipt.rows, writeUnits: receipt.writeUnits },
294
+ });
295
+ sinceBoundary = advanced ? 0 : sinceBoundary + 1;
296
+ progress.version = version;
297
+ progress.envelope = envelope;
298
+ progress.rows += receipt.rows;
299
+ progress.batches += 1;
300
+ }
301
+ };
302
+ // The first failure is the root cause; the sibling only fails because of the
303
+ // induced abort, so it must not mask what actually went wrong.
304
+ let rootCause;
305
+ const settled = Promise.allSettled([produce(), consume()].map((task) => task.catch((error) => {
306
+ rootCause ??= { error };
307
+ local.abort(error);
308
+ })));
309
+ // After a failure, a source operation that ignores its signal must not pin
310
+ // the stream (and its permits) forever.
311
+ await Promise.race([settled, graceAfterAbort(signal, READER_SHUTDOWN_GRACE_MS)]);
312
+ abandoned = true;
313
+ if (rootCause)
314
+ throw rootCause.error;
315
+ signal.throwIfAborted();
316
+ if (budgetExhausted) {
317
+ env.log?.(`${namespaceId}: ${new BudgetExhausted('execution budget exhausted; committed progress is preserved').message}`);
318
+ return 'budget_exhausted';
319
+ }
320
+ return 'succeeded';
321
+ }
322
+ // A fresh Loader instance per attempt. An ambiguous acknowledgement replays the
323
+ // same stable batch identity and accepts a possible duplicate over data loss.
324
+ async function loadBatch(input, batchId, rows, signal) {
325
+ const factory = input.stream.loader ?? simpleLoader();
326
+ return tracer.startActiveSpan('chkit.ingest.load', async (span) => {
327
+ span.setAttribute('chkit.ingest.batch_id', batchId);
328
+ span.setAttribute('chkit.ingest.rows', rows.length);
329
+ try {
330
+ return await pRetry(() => input.permits.loads(async () => {
331
+ signal.throwIfAborted();
332
+ // The load limit covers only the active write, never p-retry's backoff.
333
+ let loader;
334
+ try {
335
+ loader = factory({
336
+ streamId: input.stream.id,
337
+ runId: input.runId,
338
+ table: input.stream.destination,
339
+ destination: input.env.destination,
340
+ signal,
341
+ });
342
+ }
343
+ catch (error) {
344
+ // Construction errors are not ambiguous sink acknowledgements.
345
+ throw new AbortError(error instanceof Error ? error : new Error(String(error)));
346
+ }
347
+ try {
348
+ await loader.write({ batchId, rows });
349
+ return await loader.finalize();
350
+ }
351
+ catch (error) {
352
+ // Cleanup must not replace the write failure that decides the retry.
353
+ await loader.abort(error).catch((cleanupError) => {
354
+ span.recordException(cleanupError instanceof Error ? cleanupError : new Error(String(cleanupError)));
355
+ });
356
+ throw error;
357
+ }
358
+ }), {
359
+ retries: LOAD_ATTEMPTS - 1,
360
+ minTimeout: 1000,
361
+ signal,
362
+ });
363
+ }
364
+ catch (error) {
365
+ recordFailure(span, error);
366
+ throw error;
367
+ }
368
+ finally {
369
+ span.end();
370
+ }
371
+ });
372
+ }
373
+ function restoreState(stream, envelope, namespaceId) {
374
+ if (!envelope)
375
+ return undefined;
376
+ if (envelope.strategy !== stream.incremental.id || envelope.version !== stream.incremental.version) {
377
+ throw new IngestConfigError(`Checkpoint for "${namespaceId}" was written by strategy ${envelope.strategy}@${envelope.version}, but the stream now declares ${stream.incremental.id}@${stream.incremental.version}. ` +
378
+ 'ChKit never silently reinterprets a checkpoint: migrate the state explicitly, use a new stream id, or run a separately namespaced backfill.');
379
+ }
380
+ return stream.incremental.parseState(envelope.state);
381
+ }
382
+ function append(input, eventKind, fields) {
383
+ return appendFacts(input, [{ eventKind, fields }]);
384
+ }
385
+ // Appends for one namespace are serialized and sequence numbers are taken only
386
+ // when the write starts, so facts that never land cannot leave a gap. Facts
387
+ // passed together share one atomic insert. An ambiguous failure retries the
388
+ // exact same deterministic facts.
389
+ function appendFacts(input, facts) {
390
+ const { progress, env } = input;
391
+ const signal = facts.some((fact) => fact.eventKind === 'work_finished') ? terminalSignal(env.signal) : env.signal;
392
+ const write = progress.appendChain.then(async () => {
393
+ signal.throwIfAborted();
394
+ const events = facts.map(({ eventKind, fields }, index) => ({
395
+ namespaceId: input.namespaceId,
396
+ eventSeq: progress.seq + 1 + index,
397
+ eventKind,
398
+ runId: input.runId,
399
+ workId: fields.workId ?? '',
400
+ attemptNo: fields.attemptNo ?? 0,
401
+ batchId: fields.batchId ?? '',
402
+ expectedCheckpointVersion: fields.expectedCheckpointVersion ?? progress.version,
403
+ checkpointVersion: fields.checkpointVersion ?? progress.version,
404
+ checkpoint: fields.checkpoint,
405
+ workState: fields.workState ?? '',
406
+ sinkEvidence: fields.sinkEvidence ?? '',
407
+ retryAt: fields.retryAt,
408
+ errorClass: fields.errorClass ?? '',
409
+ detail: progress.seq === 0 && index === 0
410
+ ? { ...fields.detail, journal: { version: 2, startedAt: progress.startedAt, base: progress.base } }
411
+ : fields.detail ?? {},
412
+ }));
413
+ await pRetry(() => abortable(() => env.journal.append(events), signal), {
414
+ retries: JOURNAL_APPEND_ATTEMPTS - 1,
415
+ minTimeout: 250,
416
+ signal,
417
+ });
418
+ for (const event of events) {
419
+ if (event.eventKind === 'batch_committed' && event.checkpointVersion > event.expectedCheckpointVersion) {
420
+ progress.checkpointId = `${event.runId}:${event.eventSeq}`;
421
+ }
422
+ }
423
+ progress.seq += events.length;
424
+ });
425
+ // A fact that could not be confirmed poisons the chain: a later append must
426
+ // not reuse its sequence number, because the unconfirmed write may have landed.
427
+ progress.appendChain = write;
428
+ write.catch(() => undefined);
429
+ return abortable(() => write, signal);
430
+ }
431
+ // Run facts are deterministic too, so they get the same bounded retry as
432
+ // namespace appends instead of failing the whole run on one transient error.
433
+ function appendRunEvent(env, event, signal) {
434
+ return abortable(() => pRetry(() => abortable(() => env.journal.append([event]), signal), {
435
+ retries: JOURNAL_APPEND_ATTEMPTS - 1,
436
+ minTimeout: 250,
437
+ signal,
438
+ }), signal);
439
+ }
440
+ // A live run bounds terminal facts by its own deadline, not by a fixed window
441
+ // that a slow but healthy journal write can outlast. Only once the run has
442
+ // been interrupted does the fixed grace period apply.
443
+ function terminalSignal(runSignal) {
444
+ if (runSignal.aborted)
445
+ return AbortSignal.timeout(TERMINAL_JOURNAL_TIMEOUT_MS);
446
+ const grace = new AbortController();
447
+ void graceAfterAbort(runSignal, TERMINAL_JOURNAL_TIMEOUT_MS).then(() => {
448
+ grace.abort(new DOMException('The operation timed out.', 'TimeoutError'));
449
+ });
450
+ return grace.signal;
451
+ }
452
+ function runEvent(seq, eventKind, runId, workState, detail) {
453
+ return {
454
+ namespaceId: `${RUN_NAMESPACE_PREFIX}${runId}`,
455
+ eventSeq: seq,
456
+ eventKind,
457
+ runId,
458
+ workId: runId,
459
+ attemptNo: 0,
460
+ batchId: '',
461
+ expectedCheckpointVersion: 0,
462
+ checkpointVersion: 0,
463
+ checkpoint: undefined,
464
+ workState,
465
+ sinkEvidence: '',
466
+ retryAt: undefined,
467
+ errorClass: '',
468
+ detail,
469
+ };
470
+ }
471
+ function assertValidChunk(streamId, chunk, maxChunkRows) {
472
+ if (typeof chunk !== 'object' || chunk === null || !('rows' in chunk) || !Array.isArray(chunk.rows)) {
473
+ throw new IngestConfigError(`Stream "${streamId}" yielded a chunk without a "rows" array.`);
474
+ }
475
+ if ('id' in chunk && chunk.id !== undefined && typeof chunk.id !== 'string') {
476
+ throw new IngestConfigError(`Stream "${streamId}" yielded a chunk whose "id" is not a string.`);
477
+ }
478
+ if (chunk.rows.length > maxChunkRows) {
479
+ throw new IngestConfigError(`Stream "${streamId}" yielded a chunk of ${chunk.rows.length} rows, above the ${maxChunkRows}-row bound. Yield smaller chunks or raise budget.maxChunkRows.`);
480
+ }
481
+ }
482
+ function emptyBatch() {
483
+ return { rows: [], intervalIds: [], state: undefined };
484
+ }
485
+ /** Resolves a fixed grace period after the signal aborts; never resolves otherwise. */
486
+ function graceAfterAbort(signal, graceMs) {
487
+ return new Promise((resolve) => {
488
+ const start = () => {
489
+ void sleep(graceMs, undefined, { ref: false }).then(resolve);
490
+ };
491
+ if (signal.aborted)
492
+ start();
493
+ else
494
+ signal.addEventListener('abort', start, { once: true });
495
+ });
496
+ }
497
+ /** Settle with the promise, or reject as soon as the signal aborts. */
498
+ function abortable(operation, signal) {
499
+ if (signal.aborted)
500
+ return Promise.reject(signal.reason);
501
+ return new Promise((resolve, reject) => {
502
+ const onAbort = () => reject(signal.reason);
503
+ signal.addEventListener('abort', onAbort, { once: true });
504
+ Promise.resolve().then(() => {
505
+ signal.throwIfAborted();
506
+ return operation();
507
+ }).then(resolve, reject).finally(() => signal.removeEventListener('abort', onAbort));
508
+ });
509
+ }
510
+ function permitsFor(cache, pipeline) {
511
+ const existing = cache.get(pipeline.id);
512
+ if (existing)
513
+ return existing;
514
+ const created = {
515
+ streams: pLimit(pipeline.maxStreams),
516
+ fetches: pLimit(pipeline.maxFetches),
517
+ loads: pLimit(pipeline.maxLoads),
518
+ };
519
+ cache.set(pipeline.id, created);
520
+ return created;
521
+ }
522
+ const NEVER_ABORTED = new AbortController().signal;
523
+ function resolveEnv(input, deadlineSignal) {
524
+ const now = input.now ?? (() => new Date());
525
+ const maxDurationMs = input.maxDurationMs ?? DEFAULT_MAX_DURATION_MS;
526
+ return {
527
+ journal: input.journal,
528
+ destination: input.destination,
529
+ signal: AbortSignal.any([input.signal ?? NEVER_ABORTED, deadlineSignal]),
530
+ hostSignal: input.signal ?? NEVER_ABORTED,
531
+ maxDurationMs,
532
+ prefetchBatches: input.prefetchBatches ?? DEFAULT_PREFETCH_BATCHES,
533
+ now,
534
+ log: input.log ?? (() => undefined),
535
+ };
536
+ }
537
+ function failureKind(error, signal, stream) {
538
+ if (error instanceof IngestConfigError)
539
+ return 'config';
540
+ if (error instanceof FetchFailure)
541
+ return error.classification.kind;
542
+ return classifyFailure(error, signal, stream.classifyError).kind;
543
+ }
544
+ function recordFailure(span, error) {
545
+ span.setStatus({ code: SpanStatusCode.ERROR, message: messageOf(error) });
546
+ if (error instanceof Error)
547
+ span.recordException(error);
548
+ }
549
+ function messageOf(error) {
550
+ return error instanceof Error ? error.message : String(error);
551
+ }
552
+ //# sourceMappingURL=executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAE1D,OAAO,EAAE,cAAc,EAAE,KAAK,EAAa,MAAM,oBAAoB,CAAA;AACrE,OAAO,MAA8B,MAAM,SAAS,CAAA;AACpD,OAAO,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,e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CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC/D,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { IncrementalStrategy } from './types.js';
2
+ export interface TimestampWindowState {
3
+ watermark: string;
4
+ }
5
+ export interface TimestampRange {
6
+ from: Date;
7
+ to: Date;
8
+ }
9
+ export type TimestampWindowOptions = {
10
+ /** Lower bound of the first sync. Overlap applies only to later runs. */
11
+ start: Date;
12
+ /** Milliseconds to re-read before the committed watermark. Defaults to zero. */
13
+ overlapMs?: number;
14
+ from?: never;
15
+ } | {
16
+ /** Custom lower bound; this selection input is never persisted as the watermark. */
17
+ from(input: {
18
+ watermark: Date | undefined;
19
+ cutoff: Date;
20
+ }): Date;
21
+ start?: never;
22
+ overlapMs?: never;
23
+ };
24
+ export interface CursorStateOptions<TState> {
25
+ /** Stable strategy identifier stored in the checkpoint envelope. */
26
+ id: string;
27
+ version: number;
28
+ /** Validate committed state. Throw when it must not be reinterpreted. */
29
+ parse(raw: unknown): TState;
30
+ }
31
+ /** No incremental selection: every execution reads the whole source. */
32
+ export declare function fullSync(): IncrementalStrategy<undefined, undefined>;
33
+ /**
34
+ * Bundled timestamp strategy. The upper bound is fixed to the execution cutoff
35
+ * and `range.to` becomes the committed watermark only after the whole window
36
+ * has sink evidence.
37
+ */
38
+ export declare function timestampWindow(options: TimestampWindowOptions): IncrementalStrategy<TimestampWindowState, TimestampRange>;
39
+ /**
40
+ * Generic provider-owned state (compound cursor, change token, snapshot id…).
41
+ * The reader receives the committed state as its selection and advances it by
42
+ * yielding chunks that carry complete candidate state.
43
+ */
44
+ export declare function cursorState<TState>(options: CursorStateOptions<TState>): IncrementalStrategy<TState, TState | undefined>;
45
+ //# sourceMappingURL=incremental.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"incremental.d.ts","sourceRoot":"","sources":["../src/incremental.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,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