@powerhousedao/reactor-workflow 6.2.3-dev.55 → 6.2.3-dev.57

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,4 +1,4 @@
1
- import { C as StepExecutionRecord, F as BlockResolution, I as PieceOrigin, O as PieceResolver, P as BlockMatch, S as PropertySettingDef, T as ReactorTap, _ as PieceWorkerResult, b as WorkflowTelemetryOptions, f as SecretStore, g as PieceWorker, h as ModelManifestSource, i as ReplayedStep, j as EgressPolicy, l as ConnectionRequest, n as packagePieces, r as CORE_PIECE_NAME, s as AttachmentPort, t as PieceRegistry, v as TELEMETRY_SCOPE, w as WorkflowRunResult, y as WorkflowTelemetry } from "./piece-registry-iFVZUR7s.js";
1
+ import { C as StepExecutionRecord, F as BlockResolution, I as PieceOrigin, O as PieceResolver, P as BlockMatch, S as PropertySettingDef, T as ReactorTap, _ as PieceWorkerResult, b as WorkflowTelemetryOptions, f as SecretStore, h as ModelManifestSource, i as ReplayedStep, j as EgressPolicy, l as ConnectionRequest, m as IPieceWorker, n as packagePieces, r as CORE_PIECE_NAME, s as AttachmentPort, t as PieceRegistry, v as TELEMETRY_SCOPE, w as WorkflowRunResult, y as WorkflowTelemetry } from "./piece-registry-BbeuE8TB.js";
2
2
  import { ActionBase, TriggerBase } from "@powerhousedao/pieces-framework";
3
3
  import { ILogger, OperationWithContext } from "document-model";
4
4
  import "@powerhousedao/pieces-framework/workflow";
@@ -95,6 +95,7 @@ interface WorkflowRuntimeHostDeps {
95
95
  secretsKeyFile?: string | false;
96
96
  logger?: ILogger;
97
97
  telemetry?: WorkflowTelemetryOptions;
98
+ reactorThreads?: number;
98
99
  syncWaitMs?: number;
99
100
  pieceVersionLookupMs?: number;
100
101
  }
@@ -239,1572 +240,663 @@ interface StepTestResult {
239
240
  durationMs: number;
240
241
  }
241
242
  //#endregion
242
- //#region src/reactor/store.d.ts
243
- interface RunRow {
244
- id: string;
245
- workflow_id: string;
246
- workflow_name: string;
247
- workflow_version: number;
248
- trigger_kind: string;
249
- trigger_payload: string | null;
250
- status: string;
251
- error: string | null;
252
- error_name: string | null;
253
- enqueued_at: string;
254
- started_at: string;
255
- ended_at: string | null;
256
- rerun_of: string | null;
257
- warnings: number;
258
- warning_notes: string | null;
259
- }
260
- interface StepExecutionRow {
261
- id: string;
262
- run_id: string;
263
- ordinal: number;
264
- step_id: string;
265
- step_key: string;
266
- piece_name: string;
267
- block_name: string;
268
- status: string;
269
- input: string | null;
270
- output: string | null;
271
- port: string | null;
272
- error: string | null;
273
- error_name: string | null;
274
- started_at: string | null;
275
- ended_at: string | null;
276
- piece_version: string | null;
277
- piece_source: string | null;
278
- version_match: string | null;
279
- version_note: string | null;
280
- config_hash: string | null;
281
- attempts: number | null;
282
- }
283
- interface RunDocumentRow {
284
- run_id: string;
285
- document_id: string;
286
- }
287
- interface TriggerStateRow {
288
- workflow_id: string;
289
- piece_name: string;
290
- trigger_name: string;
291
- config_hash: string;
292
- status: string;
293
- store_state: string;
294
- interval_ms: number;
295
- next_poll_at: string | null;
296
- last_poll_at: string | null;
297
- last_error: string | null;
298
- consecutive_failures: number;
299
- lease_owner: string | null;
300
- lease_expires_at: string | null;
301
- updated_at: string;
302
- piece_version: string | null;
303
- piece_source: string | null;
304
- version_match: string | null;
305
- version_note: string | null;
306
- next_renew_at: string | null;
307
- renew_error: string | null;
308
- renew_failures: number;
309
- }
310
- type DefaultedTriggerColumn = "piece_version" | "piece_source" | "version_match" | "version_note" | "next_renew_at" | "renew_error" | "renew_failures";
311
- type TriggerStateInput = Omit<TriggerStateRow, DefaultedTriggerColumn> & Partial<Pick<TriggerStateRow, DefaultedTriggerColumn>>;
312
- interface TriggerDedupeRow {
313
- workflow_id: string;
314
- dedupe_key: string;
315
- run_id: string | null;
316
- created_at: string;
317
- attempts: number | null;
318
- }
319
- /** What a fire claim resolved to; see {@link WorkflowRunStore.claimAndEnqueueRun}. */
320
- type FireClaim = {
321
- outcome: "claimed";
322
- runId: string;
323
- } | {
324
- outcome: "duplicate";
325
- } | {
326
- outcome: "abandoned";
327
- attempts: number;
328
- };
329
- interface PieceStoreRow {
330
- scope: string;
331
- scope_key: string;
332
- key: string;
333
- value: string;
334
- updated_at: string;
243
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/operation-node.d.ts
244
+ type OperationNodeKind = 'IdentifierNode' | 'SchemableIdentifierNode' | 'RawNode' | 'SelectQueryNode' | 'SelectionNode' | 'ReferenceNode' | 'ColumnNode' | 'TableNode' | 'AliasNode' | 'FromNode' | 'SelectAllNode' | 'AndNode' | 'OrNode' | 'ParensNode' | 'ValueNode' | 'ValueListNode' | 'PrimitiveValueListNode' | 'JoinNode' | 'OperatorNode' | 'WhereNode' | 'InsertQueryNode' | 'DeleteQueryNode' | 'ReturningNode' | 'CreateTableNode' | 'ColumnDefinitionNode' | 'AddColumnNode' | 'DropTableNode' | 'DataTypeNode' | 'OrderByNode' | 'OrderByItemNode' | 'GroupByNode' | 'GroupByItemNode' | 'UpdateQueryNode' | 'ColumnUpdateNode' | 'LimitNode' | 'OffsetNode' | 'OnConflictNode' | 'OnDuplicateKeyNode' | 'CreateIndexNode' | 'DropIndexNode' | 'ListNode' | 'ReferencesNode' | 'PrimaryKeyConstraintNode' | 'UniqueConstraintNode' | 'CheckConstraintNode' | 'ForeignKeyConstraintNode' | 'WithNode' | 'CommonTableExpressionNode' | 'HavingNode' | 'CreateSchemaNode' | 'DropSchemaNode' | 'AlterTableNode' | 'ModifyColumnNode' | 'DropColumnNode' | 'RenameColumnNode' | 'AlterColumnNode' | 'AddConstraintNode' | 'DropConstraintNode' | 'CreateViewNode' | 'RefreshMaterializedViewNode' | 'DropViewNode' | 'GeneratedNode' | 'DefaultValueNode' | 'OnNode' | 'ValuesNode' | 'CommonTableExpressionNameNode' | 'SelectModifierNode' | 'CreateTypeNode' | 'DropTypeNode' | 'ExplainNode' | 'DefaultInsertValueNode' | 'AggregateFunctionNode' | 'OverNode' | 'PartitionByNode' | 'PartitionByItemNode' | 'SetOperationNode' | 'BinaryOperationNode' | 'UnaryOperationNode' | 'UsingNode' | 'FunctionNode' | 'CaseNode' | 'WhenNode' | 'JSONReferenceNode' | 'JSONPathNode' | 'JSONPathLegNode' | 'JSONOperatorChainNode' | 'TupleNode' | 'MergeQueryNode' | 'MatchedNode' | 'AddIndexNode' | 'CastNode' | 'FetchNode' | 'TopNode' | 'OutputNode' | 'OrActionNode' | 'CollateNode' | 'RenameConstraintNode';
245
+ interface OperationNode {
246
+ readonly kind: OperationNodeKind;
335
247
  }
336
- interface WorkflowParkRow {
337
- workflow_id: string;
338
- published_version: number;
339
- reason: string;
340
- parked_at: string;
248
+ //#endregion
249
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/identifier-node.d.ts
250
+ interface IdentifierNode extends OperationNode {
251
+ readonly kind: 'IdentifierNode';
252
+ readonly name: string;
341
253
  }
342
- interface WorkflowRuntimeDB {
343
- run: RunRow;
344
- step_execution: StepExecutionRow;
345
- run_document: RunDocumentRow;
346
- trigger_state: TriggerStateRow;
347
- trigger_dedupe: TriggerDedupeRow;
348
- piece_store: PieceStoreRow;
349
- workflow_park: WorkflowParkRow;
350
- migration_mark: {
351
- name: string;
352
- applied_at: string;
353
- };
254
+ type IdentifierNodeFactory = Readonly<{
255
+ is(node: OperationNode): node is IdentifierNode;
256
+ create(name: string): Readonly<IdentifierNode>;
257
+ }>;
258
+ /**
259
+ * @internal
260
+ */
261
+ declare const IdentifierNode: IdentifierNodeFactory;
262
+ //#endregion
263
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/check-constraint-node.d.ts
264
+ interface CheckConstraintNode extends OperationNode {
265
+ readonly kind: 'CheckConstraintNode';
266
+ readonly expression: OperationNode;
267
+ readonly name?: IdentifierNode;
354
268
  }
355
- interface ErasedRuns {
356
- runs: number;
357
- steps: number;
358
- documents: number;
359
- dedupeKeysUnlinked: number;
269
+ type CheckConstraintNodeFactory = Readonly<{
270
+ is(node: OperationNode): node is CheckConstraintNode;
271
+ create(expression: OperationNode, constraintName?: string): Readonly<CheckConstraintNode>;
272
+ }>;
273
+ /**
274
+ * @internal
275
+ */
276
+ declare const CheckConstraintNode: CheckConstraintNodeFactory;
277
+ //#endregion
278
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/column-node.d.ts
279
+ interface ColumnNode extends OperationNode {
280
+ readonly kind: 'ColumnNode';
281
+ readonly column: IdentifierNode;
360
282
  }
361
- interface RunKey {
362
- enqueuedAt: string;
363
- id: string;
283
+ type ColumnNodeFactory = Readonly<{
284
+ is(node: OperationNode): node is ColumnNode;
285
+ create(column: string): Readonly<ColumnNode>;
286
+ }>;
287
+ /**
288
+ * @internal
289
+ */
290
+ declare const ColumnNode: ColumnNodeFactory;
291
+ //#endregion
292
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/default-value-node.d.ts
293
+ interface DefaultValueNode extends OperationNode {
294
+ readonly kind: 'DefaultValueNode';
295
+ readonly defaultValue: OperationNode;
364
296
  }
365
- interface ListRunsOptions {
366
- after?: RunKey;
367
- excludeTriggerKinds?: string[];
297
+ type DefaultValueNodeFactory = Readonly<{
298
+ is(node: OperationNode): node is DefaultValueNode;
299
+ create(defaultValue: OperationNode): Readonly<DefaultValueNode>;
300
+ }>;
301
+ /**
302
+ * @internal
303
+ */
304
+ declare const DefaultValueNode: DefaultValueNodeFactory;
305
+ //#endregion
306
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/generated-node.d.ts
307
+ type GeneratedNodeParams = Omit<GeneratedNode, 'kind' | 'expression'>;
308
+ interface GeneratedNode extends OperationNode {
309
+ readonly kind: 'GeneratedNode';
310
+ readonly byDefault?: boolean;
311
+ readonly always?: boolean;
312
+ readonly identity?: boolean;
313
+ readonly stored?: boolean;
314
+ readonly expression?: OperationNode;
368
315
  }
369
- interface EnqueueRunOptions {
370
- workflowId: string;
371
- triggerKind: string;
372
- triggerPayload?: unknown;
316
+ type GeneratedNodeFactory = Readonly<{
317
+ is(node: OperationNode): node is GeneratedNode;
318
+ create(params: GeneratedNodeParams): Readonly<GeneratedNode>;
319
+ createWithExpression(expression: OperationNode): Readonly<GeneratedNode>;
320
+ cloneWith(node: GeneratedNode, params: GeneratedNodeParams): Readonly<GeneratedNode>;
321
+ }>;
322
+ /**
323
+ * @internal
324
+ */
325
+ declare const GeneratedNode: GeneratedNodeFactory;
326
+ //#endregion
327
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/schemable-identifier-node.d.ts
328
+ interface SchemableIdentifierNode extends OperationNode {
329
+ readonly kind: 'SchemableIdentifierNode';
330
+ readonly schema?: IdentifierNode;
331
+ readonly identifier: IdentifierNode;
373
332
  }
374
- interface StartRunOptions {
375
- workflowId: string;
376
- workflowName: string;
377
- workflowVersion: number;
378
- triggerKind: string;
379
- triggerPayload?: unknown;
380
- rerunOf?: string;
333
+ type SchemableIdentifierNodeFactory = Readonly<{
334
+ is(node: OperationNode): node is SchemableIdentifierNode;
335
+ create(identifier: string): Readonly<SchemableIdentifierNode>;
336
+ createWithSchema(schema: string, identifier: string): Readonly<SchemableIdentifierNode>;
337
+ }>;
338
+ /**
339
+ * @internal
340
+ */
341
+ declare const SchemableIdentifierNode: SchemableIdentifierNodeFactory;
342
+ //#endregion
343
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/table-node.d.ts
344
+ interface TableNode extends OperationNode {
345
+ readonly kind: 'TableNode';
346
+ readonly table: SchemableIdentifierNode;
381
347
  }
382
- declare class WorkflowRunStore {
383
- private readonly db;
384
- private readonly unmigrated;
385
- private readonly runsInFlight;
386
- private constructor();
387
- static create(relationalDb: IRelationalDb): Promise<WorkflowRunStore>;
388
- hasUnmigratedTriggerState(workflowId: string): boolean;
389
- clearUnmigratedTriggerState(workflowId: string): void;
390
- recoverOrphanedRuns(): Promise<number>;
391
- recoverAbandonedRuns(): Promise<number>;
392
- /**
393
- * Closes a run out as CANCELLED, with the reason as its error.
394
- *
395
- * Two callers, one meaning — "this run did not finish, and the workflow is
396
- * not at fault": a firing SINGLETON concurrency refused, and a run that
397
- * passed its `runTimeoutSeconds`. Separate from `failRun` because a
398
- * CANCELLED run is not rerunnable and must not read as a workflow defect.
399
- */
400
- cancelRun(runId: string, reason: string): Promise<void>;
401
- enqueueRun(options: EnqueueRunOptions): Promise<string>;
402
- /**
403
- * Claims the dedupe key and journals the PENDING run, bounding crash replays.
404
- *
405
- * Three outcomes, as {@link FireClaim}:
406
- *
407
- * - **`"claimed"`** with a run id: this fire is ours to run.
408
- * - **`"duplicate"`**: an earlier delivery of this operation already
409
- * fired: it journaled a run, or ran without one
410
- * ({@link FIRED_WITHOUT_RUN_ID}).
411
- * - **`"abandoned"`**: the operation has been delivered
412
- * {@link FIRE_CRASH_BUDGET} times and has never once got as far as
413
- * journaling a run — i.e. it is taking the process down before the write
414
- * lands, and the read-model cursor replays it on every boot. That is the
415
- * EPIPE boot loop (backlog item 5), and a budget is what turns it from an
416
- * unbootable reactor into one FAILED run naming the loop.
417
- *
418
- * Two writes, and which one is which matters:
348
+ type TableNodeFactory = Readonly<{
349
+ is(node: OperationNode): node is TableNode;
350
+ create(table: string): Readonly<TableNode>;
351
+ createWithSchema(schema: string, table: string): Readonly<TableNode>;
352
+ }>;
353
+ /**
354
+ * @internal
355
+ */
356
+ declare const TableNode: TableNodeFactory;
357
+ //#endregion
358
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/insert-result.d.ts
359
+ /**
360
+ * The result of an insert query.
361
+ *
362
+ * If the table has an auto incrementing primary key {@link insertId} will hold
363
+ * the generated id on dialects that support it. For example PostgreSQL doesn't
364
+ * return the id by default and {@link insertId} is undefined. On PostgreSQL you
365
+ * need to use {@link ReturningInterface.returning} or {@link ReturningInterface.returningAll}
366
+ * to get out the inserted id.
367
+ *
368
+ * {@link numInsertedOrUpdatedRows} holds the number of (actually) inserted rows.
369
+ * On MySQL, updated rows are counted twice when using `on duplicate key update`.
370
+ *
371
+ * ### Examples
372
+ *
373
+ * ```ts
374
+ * import type { NewPerson } from 'type-editor' // imaginary module
375
+ *
376
+ * async function insertPerson(person: NewPerson) {
377
+ * const result = await db
378
+ * .insertInto('person')
379
+ * .values(person)
380
+ * .executeTakeFirstOrThrow()
381
+ *
382
+ * console.log(result.insertId) // relevant on MySQL
383
+ * console.log(result.numInsertedOrUpdatedRows) // always relevant
384
+ * }
385
+ * ```
386
+ */
387
+ declare class InsertResult {
388
+ /**
389
+ * The auto incrementing primary key of the inserted row.
419
390
  *
420
- * - The **attempt count** is bumped in its own committed transaction,
421
- * BEFORE the risky work. That is the only way a delivery that leaves no
422
- * run behind can be counted at all, which is what the budget needs. The
423
- * counter is never a claim signal — it only decides the budget.
424
- * - The **claim** is `run_id`, and it is set in the SAME transaction as the
425
- * run row, under a `WHERE run_id IS NULL` guard. The guard takes the
426
- * row's lock, so of two concurrent deliveries of one operation the second
427
- * blocks until the first commits and then matches no row: exactly one
428
- * delivery wins, and the run it journaled is committed with the claim. A
429
- * crash in between rolls BOTH back, so a claim that holds a run id always
430
- * holds a run — and a claim without one is retried, up to the budget.
391
+ * This property can be undefined when the query contains an `on conflict`
392
+ * clause that makes the query succeed even when nothing gets inserted.
431
393
  *
432
- * Counting and claiming are deliberately not the same write: if the bump
433
- * rode along inside the claim transaction, a run insert that takes the
434
- * process down would roll the count back with it and the budget could never
435
- * reach its limit — the boot loop it exists to bound.
436
- */
437
- claimAndEnqueueRun(dedupeKey: string, ttlMs: number, nowIso: string, options: EnqueueRunOptions): Promise<FireClaim>;
438
- journalTriggerItems(items: {
439
- dedupeKey?: string;
440
- options: EnqueueRunOptions;
441
- }[], ttlMs: number, nowIso: string): Promise<(string | undefined)[]>;
442
- recordScheduleFire(nowIso: string, nextPollAtIso: string, options: EnqueueRunOptions): Promise<string>;
443
- /**
444
- * Puts a piece_store partition back to `entries` and, in the same write,
445
- * cancels the runs the restored cursor delivers again and releases their
446
- * claims, so no reader sees the old cursor while the claims still hold.
394
+ * This property is always undefined on dialects like PostgreSQL that
395
+ * don't return the inserted id by default. On those dialects you need
396
+ * to use the {@link ReturningInterface.returning | returning} method.
447
397
  */
448
- rewindPieceStore(scope: string, scopeKey: string, entries: Record<string, unknown>, redelivered?: {
449
- runIds: string[];
450
- reason: string;
451
- }): Promise<void>;
398
+ readonly insertId: bigint | undefined;
452
399
  /**
453
- * Counts one delivery of an operation, and reports whether a run was ever
454
- * journaled for it.
455
- *
456
- * Committed on its own: the point is to leave a trace even when whatever
457
- * comes next takes the process down. It is NOT a claim — the row it writes
458
- * holds no run id, and {@link claimAndEnqueueRun} is what decides, under a
459
- * lock, which delivery gets to fill it in.
400
+ * Affected rows count.
460
401
  */
461
- recordFireAttempt(workflowId: string, dedupeKey: string, ttlMs: number, nowIso: string): Promise<{
462
- attempts: number;
463
- runId: string | null;
464
- }>;
402
+ readonly numInsertedOrUpdatedRows: bigint | undefined;
403
+ constructor(insertId: bigint | undefined, numInsertedOrUpdatedRows: bigint | undefined);
404
+ }
405
+ //#endregion
406
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/delete-result.d.ts
407
+ declare class DeleteResult {
408
+ readonly numDeletedRows: bigint;
409
+ constructor(numDeletedRows: bigint);
410
+ }
411
+ //#endregion
412
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/update-result.d.ts
413
+ declare class UpdateResult {
465
414
  /**
466
- * The abandonment of an over-budget fire, as a visible FAILED run, linked to
467
- * its dedupe key so a later delivery is a duplicate rather than another one.
415
+ * The number of rows the update query updated (even if not changed).
468
416
  */
469
- journalAbandonedFire(dedupeKey: string, options: EnqueueRunOptions & {
470
- attempts: number;
471
- }): Promise<string>;
472
- private insertPendingRun;
473
- beginRun(runId: string, details: {
474
- workflowName: string;
475
- workflowVersion: number;
476
- }): Promise<void>;
477
- startRun(options: StartRunOptions): Promise<string>;
478
- recordStep(runId: string, ordinal: number, step: StepExecutionRecord): Promise<void>;
479
- finishRun(runId: string, result: WorkflowRunResult, executionOrder?: ReadonlyMap<string, number>): Promise<void>;
480
- private sweepSteps;
481
- failRun(runId: string, error: string, errorName?: string): Promise<void>;
482
- listRuns(workflowId?: string | string[], limit?: number, options?: ListRunsOptions): Promise<RunRow[]>;
483
- getRun(id: string): Promise<RunRow | undefined>;
484
- getSteps(runId: string): Promise<StepExecutionRow[]>;
485
- getStepsForRuns(runIds: string[], options?: {
486
- withData?: boolean;
487
- }): Promise<Map<string, StepExecutionRow[]>>;
488
- recordRunDocuments(runId: string, documentIds: string[]): Promise<void>;
489
- getRunDocuments(runId: string): Promise<string[]>;
490
- getRunDocumentsForRuns(runIds: string[]): Promise<Map<string, string[]>>;
417
+ readonly numUpdatedRows: bigint;
491
418
  /**
492
- * Parks a workflow: its park row, and an ENABLED trigger_state row turned
493
- * PARKED, in one transaction. True when a trigger_state row was parked.
419
+ * The number of rows the update query changed.
420
+ *
421
+ * This is **optional** and only supported in dialects such as MySQL.
422
+ * You would probably use {@link numUpdatedRows} in most cases.
494
423
  */
495
- parkWorkflow(workflowId: string, publishedVersion: number, reason: string): Promise<boolean>;
496
- /** A disable clears a park: the park row, and a PARKED trigger row turned
497
- * DISABLED, so re-enabling arms it whether or not the supervisor held it. */
498
- clearParkOnDisable(workflowId: string): Promise<void>;
499
- /** Undoes {@link parkWorkflow}; `trigger` says whether it parked a row. */
500
- liftPark(workflowId: string, trigger: boolean): Promise<void>;
501
- getWorkflowPark(workflowId: string): Promise<WorkflowParkRow | undefined>;
502
- listWorkflowParks(): Promise<WorkflowParkRow[]>;
503
- clearWorkflowPark(workflowId: string): Promise<void>;
504
- getTriggerState(workflowId: string): Promise<TriggerStateRow | undefined>;
505
- upsertTriggerState(row: TriggerStateInput): Promise<void>;
506
- setTriggerStatus(workflowId: string, status: string, error?: string): Promise<void>;
507
- listDueTriggerStates(nowIso: string): Promise<TriggerStateRow[]>;
508
- listDueTriggerRenewals(nowIso: string): Promise<TriggerStateRow[]>;
509
- setTriggerRenewAt(workflowId: string, nextRenewAtIso: string | null): Promise<void>;
510
- recordRenewSuccess(workflowId: string, nowIso: string, nextRenewAtIso: string): Promise<void>;
511
- recordRenewFailure(workflowId: string, error: string, nowIso: string, nextRenewAtIso: string, renewFailures: number): Promise<void>;
512
- deleteTriggerState(workflowId: string): Promise<void>;
513
- listTriggerStates(): Promise<TriggerStateRow[]>;
514
- recordPollSuccess(workflowId: string, storeState: string, nowIso: string, nextPollAtIso: string | null): Promise<void>;
515
- recordPollFailure(workflowId: string, error: string, nowIso: string, nextPollAtIso: string, consecutiveFailures: number): Promise<void>;
516
- claimDedupe(workflowId: string, dedupeKey: string, ttlMs: number, nowIso: string): Promise<boolean>;
517
- deleteDedupe(workflowId: string): Promise<void>;
518
- pruneFinishedRuns(cutoffIso: string, batchSize?: number): Promise<number>;
519
- eraseRunsForDocuments(documentIds: string[]): Promise<ErasedRuns>;
520
- pruneDedupe(cutoffIso: string): Promise<number>;
521
- getPieceStoreValue(scope: string, scopeKey: string, key: string): Promise<unknown>;
522
- setPieceStoreValue(scope: string, scopeKey: string, key: string, value: unknown): Promise<void>;
523
- deletePieceStoreValue(scope: string, scopeKey: string, key: string): Promise<void>;
524
- listPieceStore(scope: string, scopeKey: string): Promise<Record<string, unknown>>;
525
- deletePieceStore(scope: string, scopeKey: string): Promise<void>;
424
+ readonly numChangedRows?: bigint;
425
+ constructor(numUpdatedRows: bigint, numChangedRows: bigint | undefined);
526
426
  }
527
427
  //#endregion
528
- //#region src/reactor/park-state.d.ts
529
- declare class ParkState {
530
- private readonly load;
531
- private readonly parks;
532
- private readonly written;
533
- private seeded;
534
- private seeding?;
535
- constructor(load: () => Promise<readonly WorkflowParkRow[] | undefined>);
536
- get(workflowId: string): Promise<WorkflowParkRow | undefined>;
537
- known(workflowId: string): {
538
- park?: WorkflowParkRow;
539
- } | undefined;
540
- set(park: WorkflowParkRow): void;
541
- delete(workflowId: string): void;
542
- private seed;
428
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/util/type-error.d.ts
429
+ interface KyselyTypeError<E extends string> {
430
+ readonly __kyselyTypeError__: E;
543
431
  }
544
432
  //#endregion
545
- //#region src/reactor/trigger-supervisor.d.ts
546
- interface PieceTriggerBinding {
547
- kind?: "piece";
548
- workflowId: string;
549
- block: BlockRef;
550
- packageName: string;
551
- version: string;
552
- triggerName: string;
553
- config: Record<string, unknown>;
554
- connectionId?: string | null;
555
- reactorConnectionId?: string | null;
556
- pollIntervalMs?: number;
557
- propertySettings?: PropertySettingDef[];
558
- source?: PieceOrigin;
559
- match?: BlockMatch;
560
- note?: string;
561
- }
562
- interface ScheduleTriggerBinding {
563
- kind: "schedule";
564
- workflowId: string;
565
- block: BlockRef;
566
- config: Record<string, unknown>;
567
- }
568
- type TriggerBinding = PieceTriggerBinding | ScheduleTriggerBinding;
569
- interface TriggerSupervisorOptions {
570
- store: () => Promise<WorkflowRunStore | undefined>;
571
- parks?: ParkState;
572
- resolveAuth: (connectionId: string | null | undefined, request?: ConnectionRequest) => Promise<unknown>;
573
- fire: (workflowId: string, payload: unknown, kind: string, runId: string) => void;
574
- cacheDir: string;
575
- resolver?: PieceResolver;
576
- worker?: PieceWorker;
577
- models?: ModelManifestSource;
578
- telemetry?: WorkflowTelemetry;
579
- reactorAccess?: (binding: PieceTriggerBinding, requireReactor: "read" | "write", runUser: RunUser | null | undefined) => Promise<ReactorTap>;
580
- egress?: EgressPolicy | null;
581
- tickMs?: number;
582
- defaultIntervalMs?: number;
583
- hookTimeoutMs?: number;
584
- webhookUrlFor?: (workflowId: string) => Promise<string | undefined>;
585
- reconcileIntervalMs?: number;
586
- now?: () => Date;
587
- }
588
- declare class TriggerSupervisor {
589
- private readonly options;
590
- private readonly bindings;
591
- private readonly worker;
592
- private readonly tickMs;
593
- private readonly defaultIntervalMs;
594
- private readonly hookTimeoutMs;
595
- private readonly now;
596
- private readonly egress;
597
- private readonly parks;
598
- private timer?;
599
- private ops;
600
- private ticking;
601
- private warnedMissingJournal;
602
- private stopped;
603
- constructor(options: TriggerSupervisorOptions);
604
- start(): void;
605
- stop(): void;
606
- private enqueue;
607
- private throwIfStopped;
608
- private store;
609
- private fire;
610
- private readonly enabledOk;
611
- private readonly descriptors;
612
- private own;
613
- private resolver;
614
- private readonly enableRetries;
615
- private readonly versions;
616
- upsert(binding: TriggerBinding, publishedVersion?: number): Promise<void>;
617
- /** Parks a workflow; true when a trigger row was parked with it. */
618
- park(workflowId: string, publishedVersion: number, reason: string): Promise<boolean>;
619
- /** Undoes {@link park} for that version only: a later park stands. */
620
- liftPark(workflowId: string, publishedVersion: number, trigger: boolean): Promise<void>;
621
- /** A disable clears the park. With no binding in memory to release a PARKED
622
- * row through onDisable (a boot), the row is turned DISABLED here. */
623
- releasePark(workflowId: string, flipRow: boolean): Promise<void>;
624
- /** A re-publish past the parked version: on this lane, a park older than
625
- * `publishedVersion` goes and a row it parked is ENABLED again, as it was
626
- * before (only an ENABLED row is ever parked); a park as new stands. The
627
- * next upsert of the same binding then arms rather than skipping as
628
- * unchanged, and a retry held back by the park is due now. */
629
- unpark(workflowId: string, publishedVersion: number): Promise<void>;
630
- remove(workflowId: string): Promise<void>;
631
- forget(workflowId: string): Promise<void>;
632
- private unbind;
633
- reject(workflowId: string, block: BlockIdentity, config: unknown, message: string, retryAt?: Date): Promise<void>;
634
- private recordRejection;
635
- test(binding: PieceTriggerBinding, options?: {
636
- runUser?: RunUser | null;
637
- }): Promise<unknown>;
638
- private dropTestPartitions;
639
- handshake(binding: PieceTriggerBinding, payload: unknown): Promise<PieceWorkerResult>;
640
- deliverWebhook(workflowId: string, payload: unknown): Promise<void>;
641
- private cursorRewind;
642
- private hook;
643
- private reactorFor;
644
- private pieceDescriptor;
645
- private triggerDescriptor;
646
- private deliveryFor;
647
- private enable;
648
- private renewAtAfterEnable;
649
- private webhookUrlOrThrow;
650
- /**
651
- * The park, when it holds this registration back.
652
- *
653
- * `policy.onFailure = PARK` is a **runtime override of the document's
654
- * enabled-ness**: the document still says ENABLED, and re-arming from it is
655
- * what a restart does for every workflow it finds. So the park row is the
656
- * authority, read on this lane, and it blocks every registration of the
657
- * version that failed or an older one — a boot re-arm, an ERROR row's
658
- * retry. A newer version is what a re-publish is: it is never blocked, and
659
- * {@link enable} lifts the park it outlived. A re-enable lifts it through
660
- * the disable before it.
661
- */
662
- private blockingPark;
663
- /**
664
- * An enable a park held back. The row is left as it stands, and a pending
665
- * retry keeps its release flag, so the enable after the park lifts releases
666
- * a failed attempt and arms afresh; the retry is only pushed back, so it
667
- * does not take every tick's slot. A binding this replaced is restored, so
668
- * nothing is released later with one that was never armed.
669
- */
670
- private holdParked;
671
- /** The status an enable that succeeded writes: never ENABLED while a park
672
- * stands, whatever ran meanwhile. The registration stays recorded. */
673
- private armedStatus;
674
- private deferToStoredRetry;
675
- private releaseRegistration;
676
- private enableSchedule;
677
- private disable;
678
- private disableRow;
679
- private bindingFromRow;
680
- tick(): Promise<void>;
681
- private retryOneEnable;
682
- private pollDue;
683
- private renewDue;
684
- private renew;
685
- private fireSchedule;
686
- private poll;
687
- private fireItems;
688
- private redeliver;
689
- private failRefused;
433
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/merge-result.d.ts
434
+ declare class MergeResult {
435
+ readonly numChangedRows: bigint | undefined;
436
+ constructor(numChangedRows: bigint | undefined);
690
437
  }
691
438
  //#endregion
692
- //#region src/reactor/service.d.ts
693
- /** Why a firing was journaled CANCELLED without running, when it was. */
694
- type FiringRefusal = "parked" | "singleton" | "stale" | "queue-full" | "expired";
695
- type PersistedRunResult = WorkflowRunResult & {
696
- runId: string | null;
697
- refusal?: FiringRefusal;
698
- };
699
- type RunResume = {
700
- completedSteps: Map<string, ReplayedStep>;
701
- rerunOf: string;
439
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/util/type-utils.d.ts
440
+ /**
441
+ * Given a database type and a union of table names in that db, returns
442
+ * a union type with all possible column names.
443
+ *
444
+ * Example:
445
+ *
446
+ * ```ts
447
+ * interface Person {
448
+ * id: number
449
+ * }
450
+ *
451
+ * interface Pet {
452
+ * name: string
453
+ * species: 'cat' | 'dog'
454
+ * }
455
+ *
456
+ * interface Movie {
457
+ * stars: number
458
+ * }
459
+ *
460
+ * interface Database {
461
+ * person: Person
462
+ * pet: Pet
463
+ * movie: Movie
464
+ * }
465
+ *
466
+ * type Columns = AnyColumn<Database, 'person' | 'pet'>
467
+ *
468
+ * // Columns == 'id' | 'name' | 'species'
469
+ * ```
470
+ */
471
+ type AnyColumn<DB, TB extends keyof DB> = { [T in TB]: keyof DB[T]; }[TB] & string;
472
+ /**
473
+ * Extracts a column type.
474
+ */
475
+ type ExtractColumnType<DB, TB extends keyof DB, C> = { [T in TB]: C extends keyof DB[T] ? DB[T][C] : never; }[TB];
476
+ /**
477
+ * Given a database type and a union of table names in that db, returns
478
+ * a union type with all possible `table`.`column` combinations.
479
+ *
480
+ * Example:
481
+ *
482
+ * ```ts
483
+ * interface Person {
484
+ * id: number
485
+ * }
486
+ *
487
+ * interface Pet {
488
+ * name: string
489
+ * species: 'cat' | 'dog'
490
+ * }
491
+ *
492
+ * interface Movie {
493
+ * stars: number
494
+ * }
495
+ *
496
+ * interface Database {
497
+ * person: Person
498
+ * pet: Pet
499
+ * movie: Movie
500
+ * }
501
+ *
502
+ * type Columns = AnyColumnWithTable<Database, 'person' | 'pet'>
503
+ *
504
+ * // Columns == 'person.id' | 'pet.name' | 'pet.species'
505
+ * ```
506
+ */
507
+ type AnyColumnWithTable<DB, TB extends keyof DB> = { [T in TB]: `${T & string}.${keyof DB[T] & string}`; }[TB];
508
+ /**
509
+ * Just like {@link AnyColumn} but with a ` as <string>` suffix.
510
+ */
511
+ type AnyAliasedColumn<DB, TB extends keyof DB> = `${AnyColumn<DB, TB>} as ${string}`;
512
+ /**
513
+ * Just like {@link AnyColumnWithTable} but with a ` as <string>` suffix.
514
+ */
515
+ type AnyAliasedColumnWithTable<DB, TB extends keyof DB> = `${AnyColumnWithTable<DB, TB>} as ${string}`;
516
+ /**
517
+ * Extracts the item type of an array.
518
+ */
519
+ type ArrayItemType<T> = T extends ReadonlyArray<infer I> ? I : never;
520
+ type SimplifySingleResult<O> = O extends InsertResult ? O : O extends DeleteResult ? O : O extends UpdateResult ? O : O extends MergeResult ? O : Simplify<O> | undefined;
521
+ type SimplifyResult<O> = O extends InsertResult ? O : O extends DeleteResult ? O : O extends UpdateResult ? O : O extends MergeResult ? O : Simplify<O>;
522
+ type Simplify<T> = DrainOuterGeneric<{ [K in keyof T]: T[K]; } & {}>;
523
+ /**
524
+ * Represents a database row whose column names and their types are unknown.
525
+ */
526
+ type UnknownRow = Record<string, unknown>;
527
+ /**
528
+ * Makes all properties of object type `T` nullable.
529
+ */
530
+ type Nullable<T> = { [P in keyof T]: T[P] | null; };
531
+ /**
532
+ * Evaluates to `true` if `T` is `never`.
533
+ */
534
+ type IsNever<T> = [T] extends [never] ? true : false;
535
+ type NarrowPartial<O, T> = DrainOuterGeneric<T extends object ? { [K in keyof O & string]: K extends keyof T ? T[K] extends NotNull$1 ? Exclude<O[K], null> : T[K] extends O[K] ? T[K] : KyselyTypeError<`$narrowType() call failed: passed type does not exist in '${K}'s type union`> : O[K]; } : never>;
536
+ /**
537
+ * A type constant for marking a column as not null. Can be used with `$narrowPartial`.
538
+ *
539
+ * Example:
540
+ *
541
+ * ```ts
542
+ * import type { NotNull } from 'kysely'
543
+ *
544
+ * await db.selectFrom('person')
545
+ * .where('nullable_column', 'is not', null)
546
+ * .selectAll()
547
+ * .$narrowType<{ nullable_column: NotNull }>()
548
+ * .executeTakeFirstOrThrow()
549
+ * ```
550
+ */
551
+ type NotNull$1 = {
552
+ readonly __notNull__: unique symbol;
702
553
  };
703
- interface ConnectionSummary {
704
- id: string;
705
- name: string;
706
- connectorId: string;
707
- authType: string;
708
- status: string;
709
- accountLabel: string | null;
710
- }
711
- interface ConnectionCheckResult {
712
- ok: boolean;
713
- detail: string | null;
714
- accountLabel: string | null;
715
- }
716
- /** A journal row with the steps that belong to it, as the subgraph serves it. */
717
- interface RunRecord {
718
- row: RunRow;
719
- steps: StepExecutionRow[];
720
- }
721
- interface RunsArgs {
722
- workflowId?: string;
723
- driveId?: string;
724
- limit?: number;
725
- excludeTriggerKinds?: string[];
726
- withStepData?: boolean;
727
- }
728
- interface RunsPageArgs extends RunsArgs {
729
- cursor?: string | null;
730
- }
731
- interface RunPage {
732
- records: RunRecord[];
733
- hasNextPage: boolean;
734
- cursor: string | null;
735
- }
736
- /** One draft block as this reactor resolves it. */
737
- interface BlockResolutionRecord {
738
- stepId: string;
739
- pieceName: string;
740
- pieceVersion: string;
741
- name: string;
742
- kind: "action" | "trigger";
743
- resolvedVersion: string | null;
744
- source: string | null;
745
- match: string;
746
- note: string | null;
747
- latestVersion: string | null;
748
- }
749
- interface TriggerTestOptions extends WorkflowAccessOptions {
750
- payload?: unknown;
751
- timeoutMs?: number;
752
- }
753
- interface WebhookEndpointRecord {
754
- workflowId: string;
755
- url: string;
756
- absoluteUrl: boolean;
757
- armed: boolean;
758
- createdAt: string;
554
+ type SqlBool = boolean | 0 | 1;
555
+ /**
556
+ * Utility to reduce depth of TypeScript's internal type instantiation stack.
557
+ *
558
+ * Example:
559
+ *
560
+ * ```ts
561
+ * type A<T> = { item: T }
562
+ *
563
+ * type Test<T> = A<
564
+ * A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<T>>>>>>>>>>>>>>>>>>>>>>>>
565
+ * >
566
+ *
567
+ * // type Error = Test<number> // Type instantiation is excessively deep and possibly infinite.ts (2589)
568
+ * ```
569
+ *
570
+ * To fix this, we can use `DrainOuterGeneric`:
571
+ *
572
+ * ```ts
573
+ * type A<T> = DrainOuterGeneric<{ item: T }>
574
+ *
575
+ * type Test<T> = A<
576
+ * A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<T>>>>>>>>>>>>>>>>>>>>>>>>
577
+ * >
578
+ *
579
+ * type Ok = Test<number> // Ok
580
+ * ```
581
+ */
582
+ type DrainOuterGeneric<T> = [T] extends [unknown] ? T : never;
583
+ type ShallowRecord<K extends keyof any, T> = DrainOuterGeneric<{ [P in K]: T; }>;
584
+ /**
585
+ * Dehydrates any root properties of an object that are not valid JSON types.
586
+ *
587
+ * For now, we catch anything in {@link StringsWhenDataTypeNotAvailable} and convert it to `string`.
588
+ */
589
+ type ShallowDehydrateObject<O> = { [K in keyof O]: ShallowDehydrateValue<O[K]>; };
590
+ /**
591
+ * Dehydrates a value when it is not a valid JSON type.
592
+ *
593
+ * For now, we catch anything in {@link StringsWhenDataTypeNotAvailable} and convert it to `string`,
594
+ * and anything in {@link NumbersWhenDataTypeNotAvailable} and convert it to `number`.
595
+ */
596
+ type ShallowDehydrateValue<T> = T extends null | undefined ? T : '__kysely_dehydrate__' extends keyof NonNullable<T> ? T : T extends (infer U)[] | null | undefined ? Array<ShallowDehydrateValue<U>> | Extract<T, null | undefined> : Exclude<T, StringsWhenDataTypeNotAvailable | NumbersWhenDataTypeNotAvailable> | ([Extract<T, NumbersWhenDataTypeNotAvailable>] extends [never] ? never : number) | ([Extract<T, StringsWhenDataTypeNotAvailable>] extends [never] ? never : string);
597
+ type StringsWhenDataTypeNotAvailable = Date | Uint8Array;
598
+ type NumbersWhenDataTypeNotAvailable = bigint | NumericString;
599
+ type NumericString = `${number}`;
600
+ //#endregion
601
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/references-node.d.ts
602
+ declare const ON_MODIFY_FOREIGN_ACTIONS: readonly ["no action", "restrict", "cascade", "set null", "set default"];
603
+ type OnModifyForeignAction = ArrayItemType<typeof ON_MODIFY_FOREIGN_ACTIONS>;
604
+ interface ReferencesNode extends OperationNode {
605
+ readonly kind: 'ReferencesNode';
606
+ readonly table: TableNode;
607
+ readonly columns: ReadonlyArray<ColumnNode>;
608
+ readonly onDelete?: OnModifyForeignAction;
609
+ readonly onUpdate?: OnModifyForeignAction;
759
610
  }
760
- export declare class WorkflowRuntimeService {
761
- private readonly host;
762
- private readonly logger;
763
- private readonly telemetry;
764
- private readonly attachments?;
765
- private executor?;
766
- private pieceWorkers?;
767
- private unobservePool?;
768
- private storePromise;
769
- private storeError?;
770
- private storeOpening;
771
- private storeReopenAt;
772
- private storeReopenMs;
773
- private retentionSweep?;
774
- private secretsPromise?;
775
- private oauthAttemptsPromise?;
776
- private tokenRefresher?;
777
- private readonly registry;
778
- private readonly seedPromise;
779
- private seedError?;
780
- constructor(host: WorkflowRuntimeHostDeps);
781
- private retentionTimer?;
782
- private startRetention;
783
- private sweepRetention;
784
- store(): Promise<WorkflowRunStore | undefined>;
785
- private openStore;
786
- secrets(): Promise<SecretStore>;
787
- private secretProvider;
788
- private oauthAttempts;
789
- private oauthRefresher;
790
- /** The seeding failure a restart is needed to clear, or undefined while the
791
- * registry is seeded. Resolves once seeding has finished either way. */
792
- seedFailure(): Promise<unknown>;
793
- private seedWithRetries;
794
- private seedRegistry;
795
- private endpointCount;
796
- private hasWebhookEndpoints;
797
- private readonly registeredAs;
798
- private readonly registrationChains;
799
- private inRegistrationOrder;
800
- private updateRegistration;
801
- private registerNow;
802
- private applyRegistration;
803
- private enableSupervised;
804
- private registerPieceTrigger;
805
- private pieceDelivery;
806
- private refusePieceTrigger;
807
- private registerWebhook;
808
- private supervisedBinding;
809
- private pieceBinding;
810
- private readonly blockResolver;
811
- private versionHasBlock;
812
- private readonly loggedResolutions;
813
- resolveBlock(block: BlockRef, options?: {
814
- fresh?: boolean;
815
- latest?: boolean;
816
- }): Promise<BlockResolution>;
817
- private logResolution;
818
- private resolvedPiece;
819
- private readonly reactorDenials;
820
- private recheckReactorAccess;
821
- private checkReactorAccess;
822
- private seedReactorAccess;
823
- reactorAccessDenial(workflowId: string): string | undefined;
824
- private refuseArming;
825
- private readonly unarmed;
826
- private reportUnarmedTrigger;
827
- private readonly resolutionRetries;
828
- private scheduleResolutionRetry;
829
- private cancelResolutionRetry;
830
- private dropSupervised;
831
- private refreshRegistration;
832
- private readonly seenOps;
833
- private readonly seenOpsQueue;
834
- private alreadySeen;
835
- onDocumentsPurged(markers: OperationWithContext[]): Promise<ErasedRuns>;
836
- onOperations(operations: OperationWithContext[]): Promise<void>;
837
- private readonly unjournaledFires;
838
- private fireUnjournaled;
839
- private enqueueFire;
840
- private fireFromTrigger;
841
- private journalFiring;
842
- private startFiring;
843
- private readonly firedLifecycle;
844
- private readonly firedLifecycleQueue;
845
- private lifecycleAlreadyFired;
846
- private recordLifecycleFired;
847
- private lifecycleTargets;
848
- private fireLifecycle;
849
- private readonly driveParentCache;
850
- private driveIdFromParent;
851
- private forgetDeletedWorkflow;
852
- private disarmDeleted;
853
- private dropDeleted;
854
- private releaseDeleted;
855
- private erasePurgedWorkflow;
856
- private matchDocumentLifecycle;
857
- private matchDriveLifecycle;
858
- private triggerSupervisor?;
859
- private readonly parks;
860
- supervisor(): TriggerSupervisor;
861
- private laneFailed;
862
- startTriggerSupervisor(): void;
863
- stopTriggerSupervisor(): void;
864
- private closed;
865
- private throwIfClosed;
866
- shutdown(): void;
867
- triggerStates(ctx?: WorkflowCaller): Promise<TriggerStateRow[]>;
868
- private webhookEndpoints?;
869
- private webhookScope?;
870
- private webhookRegistration?;
871
- /** Registers the workflow endpoint family with the reactor's webhook service
872
- * (idempotent). Everything transport-shaped is the service's; only workflow identity is ours. */
873
- registerWebhookEndpoint(): Promise<void>;
874
- /** The endpoint family, once registered. Seeding runs before the host starts
875
- * the runtime, so a caller that needs a token waits rather than finds it missing. */
876
- private endpoints;
877
- /** The per-document policy the service enforces before a delivery reaches this code;
878
- * undefined means the workflow is not armed, answered exactly as an unknown token is. */
879
- webhookPolicy(workflowId: string): Promise<WebhookPolicy | undefined>;
880
- private liveWebhook;
881
- private policyOf;
882
- webhookEndpoint(workflowId: string, ctx?: WorkflowCaller, access?: WorkflowAccessOptions): Promise<WebhookEndpointRecord | null>;
883
- private mintWebhookEndpoint;
884
- /** A delivery the service has already rate-limited, verified, de-duplicated and
885
- * answered any challenge for; all that is left is deciding what it means. */
886
- deliverWebhook(request: WebhookRequest): Promise<WebhookReply>;
887
- private pieceHandshake;
888
- private pieceHandshakeConfig;
889
- private deliverToPiece;
890
- private webhookSecret;
891
- private readonly models;
892
- private modelEntries;
893
- private declaredReactor;
894
- private callerRunUser;
895
- private reactorScope;
896
- private stepReactorAccess;
897
- private triggerReactorAccess;
898
- private designReactorAccess;
899
- private readonly descriptors;
900
- private designWorker?;
901
- private createDesignWorker;
902
- private designEgress;
903
- private readonly describing;
904
- private pieceDescriptor;
905
- private describe;
906
- driveWorkflowIds(driveId: string, ctx?: WorkflowCaller): Promise<string[]>;
907
- runs(args: RunsArgs, ctx?: WorkflowCaller): Promise<RunRecord[]>;
908
- runsPage(args: RunsPageArgs, ctx?: WorkflowCaller): Promise<RunPage>;
909
- private listRunsPage;
910
- run(runId: string, ctx?: WorkflowCaller): Promise<RunRecord | null>;
911
- connections(ctx?: WorkflowCaller): Promise<ConnectionSummary[]>;
912
- checkConnection(connectionId: string, ctx?: WorkflowCaller): Promise<ConnectionCheckResult>;
913
- private connectionDocument;
914
- private checkConnectionDocument;
915
- startOAuth(connectionId: string, ctx: WorkflowCaller | undefined, options: {
916
- redirectUri: string;
917
- returnUrl?: string;
918
- }): Promise<OAuthStart>;
919
- oauthAttempt(state: string, ctx: WorkflowCaller | undefined): Promise<OAuthAttemptView | null>;
920
- completeOAuth(callback: {
921
- state: string;
922
- code?: string;
923
- error?: string;
924
- errorDescription?: string;
925
- }): Promise<{
926
- ok: boolean;
927
- detail: string | null;
928
- returnUrl: string | null;
929
- }>;
930
- private recordCheckResult;
931
- private localPieces;
932
- private localPiece;
933
- pieceCatalog(): Promise<PieceSummary[]>;
934
- pieceActions(packageName: string, version?: string): Promise<PieceActionsResult>;
935
- pieceTriggers(packageName: string, version?: string): Promise<PieceTriggersResult>;
936
- warmPieceSearch(): void;
937
- searchPieces(query: string, filter: PieceSearchFilter): Promise<PieceSearchResult>;
938
- pieceDetail(packageName: string, version?: string): Promise<unknown>;
939
- private localPieceAt;
940
- blockDescriptor(block: BlockRef): Promise<unknown>;
941
- private readableDocuments;
942
- private readableRows;
943
- private canReadDocument;
944
- private servedRuns;
945
- private servesDocuments;
946
- private servesRunDocument;
947
- private assertCanReadDocument;
948
- private assertCanReadWorkflow;
949
- private assertCanWriteDocument;
950
- blockOptions(block: BlockRef, propName: string, input?: unknown, connectionId?: string, ctx?: WorkflowCaller, searchValue?: string, reactorConnectionId?: string): Promise<unknown>;
951
- blockOutputTree(block: BlockRef, config?: unknown): Promise<OutputTree>;
952
- private stateFields;
953
- private operationInputFields;
954
- testTrigger(workflowId: string, ctx?: WorkflowCaller, options?: TriggerTestOptions): Promise<unknown>;
955
- private triggerTest;
956
- private readonly webhookTests;
957
- private awaitWebhookTest;
958
- /** Stops a waiting webhook test; false when none was waiting. */
959
- cancelTriggerTest(workflowId: string, reason?: string): boolean;
960
- cancelTriggerTestFor(workflowId: string, ctx?: WorkflowCaller): Promise<boolean>;
961
- private recordTest;
962
- private noteLastTest;
963
- private blockExecutor;
964
- private workers;
965
- fire(workflowId: string, triggerPayload?: unknown, triggerKind?: string, resume?: RunResume, ctx?: WorkflowCaller, enqueuedRunId?: string): Promise<PersistedRunResult>;
966
- private runFired;
967
- private readonly runGate;
968
- private readonly heldReplies;
969
- /** Why a trigger's firing of a PARKED workflow is refused; undefined when
970
- * it is not parked, or when an operator started the run. */
971
- private parkedFiring;
972
- /** Why a firing that waited for its slot may no longer run, if it may not. */
973
- private staleAfterWait;
974
- /** Whether the workflow is still ENABLED at this published version. An
975
- * unreadable document counts as unchanged, so a failure still parks. */
976
- private stillRunsVersion;
977
- /** A park recorded against an earlier published version than this state's. */
978
- private outdatedPark;
979
- /**
980
- * A firing SINGLETON refused.
981
- *
982
- * Journaled as a CANCELLED run rather than dropped: a firing that vanished
983
- * is indistinguishable from a trigger that never fired, which is the class
984
- * of bug this work package exists to stamp out. An already-enqueued row is
985
- * closed out in place, so nothing is left PENDING for a sweep to find.
986
- */
987
- private refuseClosed;
988
- private skipFiring;
989
- /**
990
- * `policy.onFailure` for a run that failed terminally.
991
- *
992
- * PARK is the document model's own default, so this is where enforcing the
993
- * knob becomes visible: a terminal failure parks the workflow, whatever its
994
- * trigger kind, and nothing fires it until it is re-published or
995
- * re-enabled. That is what PARK means, and
996
- * leaving a broken workflow firing every minute is what it meant before.
997
- *
998
- * NOTIFY logs at error level, which is the only notification channel this
999
- * engine has; it is marked as such rather than pretending to page anyone.
1000
- */
1001
- private applyFailureMode;
1002
- rerun(runId: string, ctx?: WorkflowCaller): Promise<PersistedRunResult>;
1003
- private rereads;
1004
- testStep(workflowId: string, stepId: string, ctx?: WorkflowCaller, access?: WorkflowAccessOptions): Promise<StepTestResult>;
1005
- private testScope;
1006
- private readReferencedDocuments;
1007
- private documentShapes;
1008
- private lastTestSample;
1009
- stepOutputTree(workflowId: string, stepId: string, ctx?: WorkflowCaller): Promise<OutputTree>;
1010
- blockResolutions(workflowId: string, ctx?: WorkflowCaller): Promise<BlockResolutionRecord[]>;
1011
- private draftOf;
1012
- }
1013
- /** The runtime a host composes: one instance, its lifetime the host's. */
1014
- export declare function createWorkflowRuntime(deps: WorkflowRuntimeHostDeps): WorkflowRuntimeService;
1015
- //#endregion
1016
- //#region src/reactor/run-cursor.d.ts
1017
- export declare class InvalidRunCursorError extends Error {
1018
- constructor();
1019
- }
1020
- //#endregion
1021
- //#region src/reactor/singleton-lease.d.ts
1022
- /**
1023
- * Names this process as the workflow singleton's owner.
1024
- *
1025
- * Set it to a STABLE name per deployment slot (`switchboard-0`, the
1026
- * StatefulSet pod name, the Render service id). The owner name is the
1027
- * operator's contract: a restart under the same name re-claims its own lease
1028
- * once the old heartbeat is stale instead of waiting out
1029
- * {@link SINGLETON_LEASE_TTL_MS}.
1030
- *
1031
- * Unset, the owner is derived from a STABLE identity — the hostname and a
1032
- * fingerprint of the journal's own storage location ({@link
1033
- * AcquireSingletonOptions.storageId}) — not from the pid and a random suffix.
1034
- * A random per-process owner meant every unclean kill locked the next boot out
1035
- * for the whole {@link SINGLETON_LEASE_TTL_MS}: the dead process's lease was
1036
- * nobody's to re-claim, and `release()` never ran. One deployment slot
1037
- * restarting is the common case and it has to be quick; a genuine second
1038
- * replica still differs, by hostname or by the journal it points at.
1039
- */
1040
- export declare const WORKFLOW_SINGLETON_OWNER_ENV = "PH_WORKFLOWS_SINGLETON_OWNER";
1041
- /** How long a claim stays valid without a heartbeat. */
1042
- export declare const SINGLETON_LEASE_TTL_MS = 60000;
1043
- /** How often the holder renews it; a third of the TTL, so two renewals may be
1044
- * lost (a GC pause, a slow database) before anyone may take over. */
1045
- export declare const SINGLETON_HEARTBEAT_MS: number;
1046
- /**
1047
- * How long the holder's heartbeat must have been silent before a claim under
1048
- * the SAME owner name takes the lease over, short of its expiry. Two renewal
1049
- * periods: a live holder renews well inside it, and its self-fence fires
1050
- * before it passes.
1051
- */
1052
- export declare const SINGLETON_STALE_HEARTBEATS = 2;
1053
- /** Another live process holds the singleton. The refusal is the point: a host
1054
- * that cannot own workflow execution must not compose the engine. */
1055
- export declare class WorkflowSingletonConflictError extends Error {
1056
- readonly owner: string;
1057
- readonly expiresAt: string;
1058
- readonly wouldBe: string;
1059
- constructor(owner: string, expiresAt: string, wouldBe: string);
1060
- }
1061
- /**
1062
- * Why a holder stopped owning workflow execution.
1063
- *
1064
- * - `taken`: a renewal matched no row, so another claim holds the lease
1065
- * (`heldBy` names it when the row still exists).
1066
- * - `unrenewable`: no renewal landed for long enough that another claim could
1067
- * take it over; none was seen to.
1068
- */
1069
- type WorkflowSingletonLoss = {
1070
- reason: "taken";
1071
- heldBy: string | undefined;
1072
- } | {
1073
- reason: "unrenewable";
1074
- silentMs: number;
1075
- };
1076
- /** A held claim, renewed from the moment it is taken. The host releases it on
1077
- * shutdown, so the next boot does not wait out the TTL. */
1078
- interface WorkflowSingletonLease {
1079
- readonly owner: string;
1080
- /** Renews once; false when the lease is no longer ours. */
1081
- heartbeat(): Promise<boolean>;
1082
- /** Stops renewing and drops the row if it is still ours. */
1083
- release(): Promise<void>;
1084
- }
1085
- interface AcquireSingletonOptions {
1086
- relationalDb: IRelationalDb;
1087
- logger?: ILogger;
1088
- /** Defaults to {@link WORKFLOW_SINGLETON_OWNER_ENV}, then
1089
- * `<hostname>/<storageId fingerprint>`. */
1090
- owner?: string;
1091
- /**
1092
- * Where this host's journal lives — a Postgres URL, an absolute PGlite
1093
- * directory — as the stable half of the default owner name. Hashed, so a
1094
- * connection string's credentials never reach the lease row or a log line.
1095
- *
1096
- * It is what separates two hosts that share a hostname but not a journal,
1097
- * and it is stable across restarts, which is the whole point.
1098
- */
1099
- storageId?: string;
1100
- ttlMs?: number;
1101
- heartbeatMs?: number;
1102
- /** Called once, when this process stops owning workflow execution. */
1103
- onLost?: (loss: WorkflowSingletonLoss) => void;
1104
- /**
1105
- * Whether a holder that cannot renew reports itself lost before anyone
1106
- * could take over. On by default. Off for a journal no other process can
1107
- * open (embedded PGlite): nothing can take the lease, so a stalled renewal
1108
- * is only logged.
1109
- */
1110
- selfFence?: boolean;
1111
- env?: Record<string, string | undefined>;
1112
- }
1113
- /**
1114
- * The owner name this process claims under.
1115
- *
1116
- * `<hostname>/<storage fingerprint>`, so it is the same name on every boot of
1117
- * one deployment slot — a restart re-claims its OWN lease once the dead
1118
- * process's heartbeat is stale, rather than waiting out the TTL — and a different
1119
- * name on any host or journal that is genuinely somebody else.
1120
- *
1121
- * The storage location is hashed, never printed: it can be a Postgres URL with
1122
- * credentials in it, and the owner name goes into a database row an operator
1123
- * reads and into every log line about the lease.
1124
- *
1125
- * The residual case a stable name cannot tell apart is two processes on ONE
1126
- * host over ONE journal, which is a misconfiguration those two already share
1127
- * (one read-model directory, one run journal). It is not silent: the loser's
1128
- * heartbeat finds the lease taken and says so by name.
1129
- */
1130
- export declare function singletonOwnerName(env?: Record<string, string | undefined>, storageId?: string): string;
611
+ type ReferencesNodeFactory = Readonly<{
612
+ is(node: OperationNode): node is ReferencesNode;
613
+ create(table: TableNode, columns: ReadonlyArray<ColumnNode>): Readonly<ReferencesNode>;
614
+ cloneWithOnDelete(references: ReferencesNode, onDelete: OnModifyForeignAction): Readonly<ReferencesNode>;
615
+ cloneWithOnUpdate(references: ReferencesNode, onUpdate: OnModifyForeignAction): Readonly<ReferencesNode>;
616
+ }>;
1131
617
  /**
1132
- * Claims the workflow singleton, or refuses.
1133
- *
1134
- * Three steps, each one a single statement whose own outcome is the claim — a
1135
- * prior `SELECT` would be a race:
1136
- *
1137
- * 1. `INSERT … ON CONFLICT DO NOTHING RETURNING` — the first ever boot.
1138
- * 2. `UPDATE … WHERE expires_at <= now OR (owner = me AND heartbeat stale)
1139
- * RETURNING` — a dead lease taken over once it has expired, or our own
1140
- * slot's lease once its holder stopped renewing (a restart under a stable
1141
- * owner name), never a live holder's. Either way the row gets this claim's
1142
- * instance, so the previous holder's heartbeat and release no longer
1143
- * match.
1144
- * 3. Neither matched: someone live holds it, and we refuse by name.
618
+ * @internal
1145
619
  */
1146
- export declare function acquireWorkflowSingletonLease(options: AcquireSingletonOptions): Promise<WorkflowSingletonLease>;
1147
- //#endregion
1148
- //#region src/reactor/run-user.d.ts
1149
- export declare function publishRunUser(client: Pick<IReactorClient, "getOperations">, workflowId: string, hostIdentity?: HostIdentity, signal?: AbortSignal): Promise<RunUser | null>;
1150
- //#endregion
1151
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/operation-node.d.ts
1152
- type OperationNodeKind = 'IdentifierNode' | 'SchemableIdentifierNode' | 'RawNode' | 'SelectQueryNode' | 'SelectionNode' | 'ReferenceNode' | 'ColumnNode' | 'TableNode' | 'AliasNode' | 'FromNode' | 'SelectAllNode' | 'AndNode' | 'OrNode' | 'ParensNode' | 'ValueNode' | 'ValueListNode' | 'PrimitiveValueListNode' | 'JoinNode' | 'OperatorNode' | 'WhereNode' | 'InsertQueryNode' | 'DeleteQueryNode' | 'ReturningNode' | 'CreateTableNode' | 'ColumnDefinitionNode' | 'AddColumnNode' | 'DropTableNode' | 'DataTypeNode' | 'OrderByNode' | 'OrderByItemNode' | 'GroupByNode' | 'GroupByItemNode' | 'UpdateQueryNode' | 'ColumnUpdateNode' | 'LimitNode' | 'OffsetNode' | 'OnConflictNode' | 'OnDuplicateKeyNode' | 'CreateIndexNode' | 'DropIndexNode' | 'ListNode' | 'ReferencesNode' | 'PrimaryKeyConstraintNode' | 'UniqueConstraintNode' | 'CheckConstraintNode' | 'ForeignKeyConstraintNode' | 'WithNode' | 'CommonTableExpressionNode' | 'HavingNode' | 'CreateSchemaNode' | 'DropSchemaNode' | 'AlterTableNode' | 'ModifyColumnNode' | 'DropColumnNode' | 'RenameColumnNode' | 'AlterColumnNode' | 'AddConstraintNode' | 'DropConstraintNode' | 'CreateViewNode' | 'RefreshMaterializedViewNode' | 'DropViewNode' | 'GeneratedNode' | 'DefaultValueNode' | 'OnNode' | 'ValuesNode' | 'CommonTableExpressionNameNode' | 'SelectModifierNode' | 'CreateTypeNode' | 'DropTypeNode' | 'ExplainNode' | 'DefaultInsertValueNode' | 'AggregateFunctionNode' | 'OverNode' | 'PartitionByNode' | 'PartitionByItemNode' | 'SetOperationNode' | 'BinaryOperationNode' | 'UnaryOperationNode' | 'UsingNode' | 'FunctionNode' | 'CaseNode' | 'WhenNode' | 'JSONReferenceNode' | 'JSONPathNode' | 'JSONPathLegNode' | 'JSONOperatorChainNode' | 'TupleNode' | 'MergeQueryNode' | 'MatchedNode' | 'AddIndexNode' | 'CastNode' | 'FetchNode' | 'TopNode' | 'OutputNode' | 'OrActionNode' | 'CollateNode' | 'RenameConstraintNode';
1153
- interface OperationNode {
1154
- readonly kind: OperationNodeKind;
1155
- }
620
+ declare const ReferencesNode: ReferencesNodeFactory;
1156
621
  //#endregion
1157
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/identifier-node.d.ts
1158
- interface IdentifierNode extends OperationNode {
1159
- readonly kind: 'IdentifierNode';
1160
- readonly name: string;
622
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/column-definition-node.d.ts
623
+ type ColumnDefinitionNodeProps = Omit<Partial<ColumnDefinitionNode>, 'kind' | 'dataType'>;
624
+ interface ColumnDefinitionNode extends OperationNode {
625
+ readonly kind: 'ColumnDefinitionNode';
626
+ readonly column: ColumnNode;
627
+ readonly dataType: OperationNode;
628
+ readonly references?: ReferencesNode;
629
+ readonly primaryKey?: boolean;
630
+ readonly autoIncrement?: boolean;
631
+ readonly unique?: boolean;
632
+ readonly notNull?: boolean;
633
+ readonly defaultTo?: DefaultValueNode;
634
+ readonly check?: CheckConstraintNode;
635
+ readonly generated?: GeneratedNode;
636
+ readonly unsigned?: boolean;
637
+ readonly frontModifiers?: ReadonlyArray<OperationNode>;
638
+ readonly endModifiers?: ReadonlyArray<OperationNode>;
639
+ readonly nullsNotDistinct?: boolean;
640
+ readonly identity?: boolean;
641
+ readonly ifNotExists?: boolean;
1161
642
  }
1162
- type IdentifierNodeFactory = Readonly<{
1163
- is(node: OperationNode): node is IdentifierNode;
1164
- create(name: string): Readonly<IdentifierNode>;
643
+ type ColumnDefinitionNodeFactory = Readonly<{
644
+ is(node: OperationNode): node is ColumnDefinitionNode;
645
+ create(column: string, dataType: OperationNode): Readonly<ColumnDefinitionNode>;
646
+ cloneWithFrontModifier(node: ColumnDefinitionNode, modifier: OperationNode): Readonly<ColumnDefinitionNode>;
647
+ cloneWithEndModifier(node: ColumnDefinitionNode, modifier: OperationNode): Readonly<ColumnDefinitionNode>;
648
+ cloneWith(node: ColumnDefinitionNode, props: ColumnDefinitionNodeProps): Readonly<ColumnDefinitionNode>;
1165
649
  }>;
1166
650
  /**
1167
651
  * @internal
1168
652
  */
1169
- declare const IdentifierNode: IdentifierNodeFactory;
653
+ declare const ColumnDefinitionNode: ColumnDefinitionNodeFactory;
1170
654
  //#endregion
1171
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/check-constraint-node.d.ts
1172
- interface CheckConstraintNode extends OperationNode {
1173
- readonly kind: 'CheckConstraintNode';
1174
- readonly expression: OperationNode;
1175
- readonly name?: IdentifierNode;
655
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/add-column-node.d.ts
656
+ interface AddColumnNode extends OperationNode {
657
+ readonly kind: 'AddColumnNode';
658
+ readonly column: ColumnDefinitionNode;
1176
659
  }
1177
- type CheckConstraintNodeFactory = Readonly<{
1178
- is(node: OperationNode): node is CheckConstraintNode;
1179
- create(expression: OperationNode, constraintName?: string): Readonly<CheckConstraintNode>;
660
+ type AddColumnNodeFactory = Readonly<{
661
+ is(node: OperationNode): node is AddColumnNode;
662
+ create(column: ColumnDefinitionNode): Readonly<AddColumnNode>;
1180
663
  }>;
1181
664
  /**
1182
665
  * @internal
1183
666
  */
1184
- declare const CheckConstraintNode: CheckConstraintNodeFactory;
667
+ declare const AddColumnNode: AddColumnNodeFactory;
1185
668
  //#endregion
1186
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/column-node.d.ts
1187
- interface ColumnNode extends OperationNode {
1188
- readonly kind: 'ColumnNode';
1189
- readonly column: IdentifierNode;
669
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/drop-column-node.d.ts
670
+ interface DropColumnNode extends OperationNode {
671
+ readonly kind: 'DropColumnNode';
672
+ readonly column: ColumnNode;
1190
673
  }
1191
- type ColumnNodeFactory = Readonly<{
1192
- is(node: OperationNode): node is ColumnNode;
1193
- create(column: string): Readonly<ColumnNode>;
674
+ type DropColumnNodeFactory = Readonly<{
675
+ is(node: OperationNode): node is DropColumnNode;
676
+ create(column: string): Readonly<DropColumnNode>;
1194
677
  }>;
1195
678
  /**
1196
679
  * @internal
1197
680
  */
1198
- declare const ColumnNode: ColumnNodeFactory;
681
+ declare const DropColumnNode: DropColumnNodeFactory;
1199
682
  //#endregion
1200
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/default-value-node.d.ts
1201
- interface DefaultValueNode extends OperationNode {
1202
- readonly kind: 'DefaultValueNode';
1203
- readonly defaultValue: OperationNode;
683
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/rename-column-node.d.ts
684
+ interface RenameColumnNode extends OperationNode {
685
+ readonly kind: 'RenameColumnNode';
686
+ readonly column: ColumnNode;
687
+ readonly renameTo: ColumnNode;
1204
688
  }
1205
- type DefaultValueNodeFactory = Readonly<{
1206
- is(node: OperationNode): node is DefaultValueNode;
1207
- create(defaultValue: OperationNode): Readonly<DefaultValueNode>;
689
+ type RenameColumnNodeFactory = Readonly<{
690
+ is(node: OperationNode): node is RenameColumnNode;
691
+ create(column: string, newColumn: string): Readonly<RenameColumnNode>;
1208
692
  }>;
1209
693
  /**
1210
694
  * @internal
1211
695
  */
1212
- declare const DefaultValueNode: DefaultValueNodeFactory;
696
+ declare const RenameColumnNode: RenameColumnNodeFactory;
1213
697
  //#endregion
1214
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/generated-node.d.ts
1215
- type GeneratedNodeParams = Omit<GeneratedNode, 'kind' | 'expression'>;
1216
- interface GeneratedNode extends OperationNode {
1217
- readonly kind: 'GeneratedNode';
1218
- readonly byDefault?: boolean;
1219
- readonly always?: boolean;
1220
- readonly identity?: boolean;
1221
- readonly stored?: boolean;
1222
- readonly expression?: OperationNode;
698
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/raw-node.d.ts
699
+ interface RawNode extends OperationNode {
700
+ readonly kind: 'RawNode';
701
+ readonly sqlFragments: ReadonlyArray<string>;
702
+ readonly parameters: ReadonlyArray<OperationNode>;
1223
703
  }
1224
- type GeneratedNodeFactory = Readonly<{
1225
- is(node: OperationNode): node is GeneratedNode;
1226
- create(params: GeneratedNodeParams): Readonly<GeneratedNode>;
1227
- createWithExpression(expression: OperationNode): Readonly<GeneratedNode>;
1228
- cloneWith(node: GeneratedNode, params: GeneratedNodeParams): Readonly<GeneratedNode>;
704
+ type RawNodeFactory = Readonly<{
705
+ is(node: OperationNode): node is RawNode;
706
+ create(sqlFragments: ReadonlyArray<string>, parameters: ReadonlyArray<OperationNode>): Readonly<RawNode>;
707
+ createWithSql(sql: string): Readonly<RawNode>;
708
+ createWithChild(child: OperationNode): Readonly<RawNode>;
709
+ createWithChildren(children: ReadonlyArray<OperationNode>): Readonly<RawNode>;
1229
710
  }>;
1230
711
  /**
1231
712
  * @internal
1232
713
  */
1233
- declare const GeneratedNode: GeneratedNodeFactory;
714
+ declare const RawNode: RawNodeFactory;
1234
715
  //#endregion
1235
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/schemable-identifier-node.d.ts
1236
- interface SchemableIdentifierNode extends OperationNode {
1237
- readonly kind: 'SchemableIdentifierNode';
1238
- readonly schema?: IdentifierNode;
1239
- readonly identifier: IdentifierNode;
716
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/alter-column-node.d.ts
717
+ type AlterColumnNodeProps = Omit<AlterColumnNode, 'kind' | 'column'>;
718
+ interface AlterColumnNode extends OperationNode {
719
+ readonly kind: 'AlterColumnNode';
720
+ readonly column: ColumnNode;
721
+ readonly dataType?: OperationNode;
722
+ readonly dataTypeExpression?: RawNode;
723
+ readonly setDefault?: OperationNode;
724
+ readonly dropDefault?: true;
725
+ readonly setNotNull?: true;
726
+ readonly dropNotNull?: true;
1240
727
  }
1241
- type SchemableIdentifierNodeFactory = Readonly<{
1242
- is(node: OperationNode): node is SchemableIdentifierNode;
1243
- create(identifier: string): Readonly<SchemableIdentifierNode>;
1244
- createWithSchema(schema: string, identifier: string): Readonly<SchemableIdentifierNode>;
728
+ type AlterColumnNodeFactory = Readonly<{
729
+ is(node: OperationNode): node is AlterColumnNode;
730
+ create<T extends keyof AlterColumnNodeProps>(column: string, prop: T, value: Required<AlterColumnNodeProps>[T]): Readonly<AlterColumnNode>;
1245
731
  }>;
1246
732
  /**
1247
733
  * @internal
1248
734
  */
1249
- declare const SchemableIdentifierNode: SchemableIdentifierNodeFactory;
735
+ declare const AlterColumnNode: AlterColumnNodeFactory;
1250
736
  //#endregion
1251
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/table-node.d.ts
1252
- interface TableNode extends OperationNode {
1253
- readonly kind: 'TableNode';
1254
- readonly table: SchemableIdentifierNode;
737
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/foreign-key-constraint-node.d.ts
738
+ type ForeignKeyConstraintNodeProps = Omit<ForeignKeyConstraintNode, 'kind' | 'columns' | 'references'>;
739
+ interface ForeignKeyConstraintNode extends OperationNode {
740
+ readonly kind: 'ForeignKeyConstraintNode';
741
+ readonly columns: ReadonlyArray<ColumnNode>;
742
+ readonly references: ReferencesNode;
743
+ readonly onDelete?: OnModifyForeignAction;
744
+ readonly onUpdate?: OnModifyForeignAction;
745
+ readonly name?: IdentifierNode;
746
+ readonly deferrable?: boolean;
747
+ readonly initiallyDeferred?: boolean;
1255
748
  }
1256
- type TableNodeFactory = Readonly<{
1257
- is(node: OperationNode): node is TableNode;
1258
- create(table: string): Readonly<TableNode>;
1259
- createWithSchema(schema: string, table: string): Readonly<TableNode>;
749
+ type ForeignKeyConstraintNodeFactory = Readonly<{
750
+ is(node: OperationNode): node is ForeignKeyConstraintNode;
751
+ create(sourceColumns: ReadonlyArray<ColumnNode>, targetTable: TableNode, targetColumns: ReadonlyArray<ColumnNode>, constraintName?: string): Readonly<ForeignKeyConstraintNode>;
752
+ cloneWith(node: ForeignKeyConstraintNode, props: ForeignKeyConstraintNodeProps): Readonly<ForeignKeyConstraintNode>;
1260
753
  }>;
1261
754
  /**
1262
755
  * @internal
1263
756
  */
1264
- declare const TableNode: TableNodeFactory;
757
+ declare const ForeignKeyConstraintNode: ForeignKeyConstraintNodeFactory;
1265
758
  //#endregion
1266
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/insert-result.d.ts
759
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/primary-key-constraint-node.d.ts
760
+ interface PrimaryKeyConstraintNode extends OperationNode {
761
+ readonly kind: 'PrimaryKeyConstraintNode';
762
+ readonly columns: ReadonlyArray<ColumnNode>;
763
+ readonly name?: IdentifierNode;
764
+ readonly deferrable?: boolean;
765
+ readonly initiallyDeferred?: boolean;
766
+ }
767
+ type PrimaryKeyConstraintNodeProps = Omit<Partial<PrimaryKeyConstraintNode>, 'kind'>;
768
+ type PrimaryKeyConstraintNodeFactory = Readonly<{
769
+ is(node: OperationNode): node is PrimaryKeyConstraintNode;
770
+ create(columns: string[], constraintName?: string): Readonly<PrimaryKeyConstraintNode>;
771
+ cloneWith(node: PrimaryKeyConstraintNode, props: PrimaryKeyConstraintNodeProps): Readonly<PrimaryKeyConstraintNode>;
772
+ }>;
1267
773
  /**
1268
- * The result of an insert query.
1269
- *
1270
- * If the table has an auto incrementing primary key {@link insertId} will hold
1271
- * the generated id on dialects that support it. For example PostgreSQL doesn't
1272
- * return the id by default and {@link insertId} is undefined. On PostgreSQL you
1273
- * need to use {@link ReturningInterface.returning} or {@link ReturningInterface.returningAll}
1274
- * to get out the inserted id.
1275
- *
1276
- * {@link numInsertedOrUpdatedRows} holds the number of (actually) inserted rows.
1277
- * On MySQL, updated rows are counted twice when using `on duplicate key update`.
1278
- *
1279
- * ### Examples
1280
- *
1281
- * ```ts
1282
- * import type { NewPerson } from 'type-editor' // imaginary module
1283
- *
1284
- * async function insertPerson(person: NewPerson) {
1285
- * const result = await db
1286
- * .insertInto('person')
1287
- * .values(person)
1288
- * .executeTakeFirstOrThrow()
1289
- *
1290
- * console.log(result.insertId) // relevant on MySQL
1291
- * console.log(result.numInsertedOrUpdatedRows) // always relevant
1292
- * }
1293
- * ```
774
+ * @internal
1294
775
  */
1295
- declare class InsertResult {
1296
- /**
1297
- * The auto incrementing primary key of the inserted row.
1298
- *
1299
- * This property can be undefined when the query contains an `on conflict`
1300
- * clause that makes the query succeed even when nothing gets inserted.
1301
- *
1302
- * This property is always undefined on dialects like PostgreSQL that
1303
- * don't return the inserted id by default. On those dialects you need
1304
- * to use the {@link ReturningInterface.returning | returning} method.
1305
- */
1306
- readonly insertId: bigint | undefined;
1307
- /**
1308
- * Affected rows count.
1309
- */
1310
- readonly numInsertedOrUpdatedRows: bigint | undefined;
1311
- constructor(insertId: bigint | undefined, numInsertedOrUpdatedRows: bigint | undefined);
1312
- }
776
+ declare const PrimaryKeyConstraintNode: PrimaryKeyConstraintNodeFactory;
1313
777
  //#endregion
1314
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/delete-result.d.ts
1315
- declare class DeleteResult {
1316
- readonly numDeletedRows: bigint;
1317
- constructor(numDeletedRows: bigint);
778
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/unique-constraint-node.d.ts
779
+ interface UniqueConstraintNode extends OperationNode {
780
+ readonly kind: 'UniqueConstraintNode';
781
+ readonly columns: ReadonlyArray<ColumnNode>;
782
+ readonly name?: IdentifierNode;
783
+ readonly nullsNotDistinct?: boolean;
784
+ readonly deferrable?: boolean;
785
+ readonly initiallyDeferred?: boolean;
1318
786
  }
787
+ type UniqueConstraintNodeProps = Omit<Partial<UniqueConstraintNode>, 'kind'>;
788
+ type UniqueConstraintNodeFactory = Readonly<{
789
+ is(node: OperationNode): node is UniqueConstraintNode;
790
+ create(columns: string[], constraintName?: string, nullsNotDistinct?: boolean): Readonly<UniqueConstraintNode>;
791
+ cloneWith(node: UniqueConstraintNode, props: UniqueConstraintNodeProps): Readonly<UniqueConstraintNode>;
792
+ }>;
793
+ /**
794
+ * @internal
795
+ */
796
+ declare const UniqueConstraintNode: UniqueConstraintNodeFactory;
1319
797
  //#endregion
1320
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/update-result.d.ts
1321
- declare class UpdateResult {
1322
- /**
1323
- * The number of rows the update query updated (even if not changed).
1324
- */
1325
- readonly numUpdatedRows: bigint;
1326
- /**
1327
- * The number of rows the update query changed.
1328
- *
1329
- * This is **optional** and only supported in dialects such as MySQL.
1330
- * You would probably use {@link numUpdatedRows} in most cases.
1331
- */
1332
- readonly numChangedRows?: bigint;
1333
- constructor(numUpdatedRows: bigint, numChangedRows: bigint | undefined);
1334
- }
798
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/constraint-node.d.ts
799
+ type ConstraintNode = PrimaryKeyConstraintNode | UniqueConstraintNode | CheckConstraintNode | ForeignKeyConstraintNode;
1335
800
  //#endregion
1336
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/util/type-error.d.ts
1337
- interface KyselyTypeError<E extends string> {
1338
- readonly __kyselyTypeError__: E;
801
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/add-constraint-node.d.ts
802
+ interface AddConstraintNode extends OperationNode {
803
+ readonly kind: 'AddConstraintNode';
804
+ readonly constraint: ConstraintNode;
1339
805
  }
806
+ type AddConstraintNodeFactory = Readonly<{
807
+ is(node: OperationNode): node is AddConstraintNode;
808
+ create(constraint: ConstraintNode): Readonly<AddConstraintNode>;
809
+ }>;
810
+ /**
811
+ * @internal
812
+ */
813
+ declare const AddConstraintNode: AddConstraintNodeFactory;
1340
814
  //#endregion
1341
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/merge-result.d.ts
1342
- declare class MergeResult {
1343
- readonly numChangedRows: bigint | undefined;
1344
- constructor(numChangedRows: bigint | undefined);
815
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/drop-constraint-node.d.ts
816
+ type DropConstraintNodeProps = Omit<DropConstraintNode, 'kind' | 'constraintName'>;
817
+ interface DropConstraintNode extends OperationNode {
818
+ readonly kind: 'DropConstraintNode';
819
+ readonly constraintName: IdentifierNode;
820
+ readonly ifExists?: boolean;
821
+ readonly modifier?: 'cascade' | 'restrict';
1345
822
  }
1346
- //#endregion
1347
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/util/type-utils.d.ts
823
+ type DropConstraintNodeFactory = Readonly<{
824
+ is(node: OperationNode): node is DropConstraintNode;
825
+ create(constraintName: string, params?: DropConstraintNodeProps): Readonly<DropConstraintNode>;
826
+ cloneWith(dropConstraint: DropConstraintNode, props: DropConstraintNodeProps): Readonly<DropConstraintNode>;
827
+ }>;
1348
828
  /**
1349
- * Given a database type and a union of table names in that db, returns
1350
- * a union type with all possible column names.
1351
- *
1352
- * Example:
1353
- *
1354
- * ```ts
1355
- * interface Person {
1356
- * id: number
1357
- * }
1358
- *
1359
- * interface Pet {
1360
- * name: string
1361
- * species: 'cat' | 'dog'
1362
- * }
1363
- *
1364
- * interface Movie {
1365
- * stars: number
1366
- * }
1367
- *
1368
- * interface Database {
1369
- * person: Person
1370
- * pet: Pet
1371
- * movie: Movie
1372
- * }
1373
- *
1374
- * type Columns = AnyColumn<Database, 'person' | 'pet'>
1375
- *
1376
- * // Columns == 'id' | 'name' | 'species'
1377
- * ```
1378
- */
1379
- type AnyColumn<DB, TB extends keyof DB> = { [T in TB]: keyof DB[T]; }[TB] & string;
1380
- /**
1381
- * Extracts a column type.
1382
- */
1383
- type ExtractColumnType<DB, TB extends keyof DB, C> = { [T in TB]: C extends keyof DB[T] ? DB[T][C] : never; }[TB];
1384
- /**
1385
- * Given a database type and a union of table names in that db, returns
1386
- * a union type with all possible `table`.`column` combinations.
1387
- *
1388
- * Example:
1389
- *
1390
- * ```ts
1391
- * interface Person {
1392
- * id: number
1393
- * }
1394
- *
1395
- * interface Pet {
1396
- * name: string
1397
- * species: 'cat' | 'dog'
1398
- * }
1399
- *
1400
- * interface Movie {
1401
- * stars: number
1402
- * }
1403
- *
1404
- * interface Database {
1405
- * person: Person
1406
- * pet: Pet
1407
- * movie: Movie
1408
- * }
1409
- *
1410
- * type Columns = AnyColumnWithTable<Database, 'person' | 'pet'>
1411
- *
1412
- * // Columns == 'person.id' | 'pet.name' | 'pet.species'
1413
- * ```
1414
- */
1415
- type AnyColumnWithTable<DB, TB extends keyof DB> = { [T in TB]: `${T & string}.${keyof DB[T] & string}`; }[TB];
1416
- /**
1417
- * Just like {@link AnyColumn} but with a ` as <string>` suffix.
1418
- */
1419
- type AnyAliasedColumn<DB, TB extends keyof DB> = `${AnyColumn<DB, TB>} as ${string}`;
1420
- /**
1421
- * Just like {@link AnyColumnWithTable} but with a ` as <string>` suffix.
1422
- */
1423
- type AnyAliasedColumnWithTable<DB, TB extends keyof DB> = `${AnyColumnWithTable<DB, TB>} as ${string}`;
1424
- /**
1425
- * Extracts the item type of an array.
1426
- */
1427
- type ArrayItemType<T> = T extends ReadonlyArray<infer I> ? I : never;
1428
- type SimplifySingleResult<O> = O extends InsertResult ? O : O extends DeleteResult ? O : O extends UpdateResult ? O : O extends MergeResult ? O : Simplify<O> | undefined;
1429
- type SimplifyResult<O> = O extends InsertResult ? O : O extends DeleteResult ? O : O extends UpdateResult ? O : O extends MergeResult ? O : Simplify<O>;
1430
- type Simplify<T> = DrainOuterGeneric<{ [K in keyof T]: T[K]; } & {}>;
1431
- /**
1432
- * Represents a database row whose column names and their types are unknown.
1433
- */
1434
- type UnknownRow = Record<string, unknown>;
1435
- /**
1436
- * Makes all properties of object type `T` nullable.
1437
- */
1438
- type Nullable<T> = { [P in keyof T]: T[P] | null; };
1439
- /**
1440
- * Evaluates to `true` if `T` is `never`.
1441
- */
1442
- type IsNever<T> = [T] extends [never] ? true : false;
1443
- type NarrowPartial<O, T> = DrainOuterGeneric<T extends object ? { [K in keyof O & string]: K extends keyof T ? T[K] extends NotNull$1 ? Exclude<O[K], null> : T[K] extends O[K] ? T[K] : KyselyTypeError<`$narrowType() call failed: passed type does not exist in '${K}'s type union`> : O[K]; } : never>;
1444
- /**
1445
- * A type constant for marking a column as not null. Can be used with `$narrowPartial`.
1446
- *
1447
- * Example:
1448
- *
1449
- * ```ts
1450
- * import type { NotNull } from 'kysely'
1451
- *
1452
- * await db.selectFrom('person')
1453
- * .where('nullable_column', 'is not', null)
1454
- * .selectAll()
1455
- * .$narrowType<{ nullable_column: NotNull }>()
1456
- * .executeTakeFirstOrThrow()
1457
- * ```
1458
- */
1459
- type NotNull$1 = {
1460
- readonly __notNull__: unique symbol;
1461
- };
1462
- type SqlBool = boolean | 0 | 1;
1463
- /**
1464
- * Utility to reduce depth of TypeScript's internal type instantiation stack.
1465
- *
1466
- * Example:
1467
- *
1468
- * ```ts
1469
- * type A<T> = { item: T }
1470
- *
1471
- * type Test<T> = A<
1472
- * A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<T>>>>>>>>>>>>>>>>>>>>>>>>
1473
- * >
1474
- *
1475
- * // type Error = Test<number> // Type instantiation is excessively deep and possibly infinite.ts (2589)
1476
- * ```
1477
- *
1478
- * To fix this, we can use `DrainOuterGeneric`:
1479
- *
1480
- * ```ts
1481
- * type A<T> = DrainOuterGeneric<{ item: T }>
1482
- *
1483
- * type Test<T> = A<
1484
- * A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<T>>>>>>>>>>>>>>>>>>>>>>>>
1485
- * >
1486
- *
1487
- * type Ok = Test<number> // Ok
1488
- * ```
1489
- */
1490
- type DrainOuterGeneric<T> = [T] extends [unknown] ? T : never;
1491
- type ShallowRecord<K extends keyof any, T> = DrainOuterGeneric<{ [P in K]: T; }>;
1492
- /**
1493
- * Dehydrates any root properties of an object that are not valid JSON types.
1494
- *
1495
- * For now, we catch anything in {@link StringsWhenDataTypeNotAvailable} and convert it to `string`.
1496
- */
1497
- type ShallowDehydrateObject<O> = { [K in keyof O]: ShallowDehydrateValue<O[K]>; };
1498
- /**
1499
- * Dehydrates a value when it is not a valid JSON type.
1500
- *
1501
- * For now, we catch anything in {@link StringsWhenDataTypeNotAvailable} and convert it to `string`,
1502
- * and anything in {@link NumbersWhenDataTypeNotAvailable} and convert it to `number`.
829
+ * @internal
1503
830
  */
1504
- type ShallowDehydrateValue<T> = T extends null | undefined ? T : '__kysely_dehydrate__' extends keyof NonNullable<T> ? T : T extends (infer U)[] | null | undefined ? Array<ShallowDehydrateValue<U>> | Extract<T, null | undefined> : Exclude<T, StringsWhenDataTypeNotAvailable | NumbersWhenDataTypeNotAvailable> | ([Extract<T, NumbersWhenDataTypeNotAvailable>] extends [never] ? never : number) | ([Extract<T, StringsWhenDataTypeNotAvailable>] extends [never] ? never : string);
1505
- type StringsWhenDataTypeNotAvailable = Date | Uint8Array;
1506
- type NumbersWhenDataTypeNotAvailable = bigint | NumericString;
1507
- type NumericString = `${number}`;
831
+ declare const DropConstraintNode: DropConstraintNodeFactory;
1508
832
  //#endregion
1509
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/references-node.d.ts
1510
- declare const ON_MODIFY_FOREIGN_ACTIONS: readonly ["no action", "restrict", "cascade", "set null", "set default"];
1511
- type OnModifyForeignAction = ArrayItemType<typeof ON_MODIFY_FOREIGN_ACTIONS>;
1512
- interface ReferencesNode extends OperationNode {
1513
- readonly kind: 'ReferencesNode';
1514
- readonly table: TableNode;
1515
- readonly columns: ReadonlyArray<ColumnNode>;
1516
- readonly onDelete?: OnModifyForeignAction;
1517
- readonly onUpdate?: OnModifyForeignAction;
833
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/modify-column-node.d.ts
834
+ interface ModifyColumnNode extends OperationNode {
835
+ readonly kind: 'ModifyColumnNode';
836
+ readonly column: ColumnDefinitionNode;
1518
837
  }
1519
- type ReferencesNodeFactory = Readonly<{
1520
- is(node: OperationNode): node is ReferencesNode;
1521
- create(table: TableNode, columns: ReadonlyArray<ColumnNode>): Readonly<ReferencesNode>;
1522
- cloneWithOnDelete(references: ReferencesNode, onDelete: OnModifyForeignAction): Readonly<ReferencesNode>;
1523
- cloneWithOnUpdate(references: ReferencesNode, onUpdate: OnModifyForeignAction): Readonly<ReferencesNode>;
838
+ type ModifyColumnNodeFactory = Readonly<{
839
+ is(node: OperationNode): node is ModifyColumnNode;
840
+ create(column: ColumnDefinitionNode): Readonly<ModifyColumnNode>;
1524
841
  }>;
1525
842
  /**
1526
843
  * @internal
1527
844
  */
1528
- declare const ReferencesNode: ReferencesNodeFactory;
845
+ declare const ModifyColumnNode: ModifyColumnNodeFactory;
1529
846
  //#endregion
1530
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/column-definition-node.d.ts
1531
- type ColumnDefinitionNodeProps = Omit<Partial<ColumnDefinitionNode>, 'kind' | 'dataType'>;
1532
- interface ColumnDefinitionNode extends OperationNode {
1533
- readonly kind: 'ColumnDefinitionNode';
1534
- readonly column: ColumnNode;
1535
- readonly dataType: OperationNode;
1536
- readonly references?: ReferencesNode;
1537
- readonly primaryKey?: boolean;
1538
- readonly autoIncrement?: boolean;
1539
- readonly unique?: boolean;
1540
- readonly notNull?: boolean;
1541
- readonly defaultTo?: DefaultValueNode;
1542
- readonly check?: CheckConstraintNode;
1543
- readonly generated?: GeneratedNode;
1544
- readonly unsigned?: boolean;
1545
- readonly frontModifiers?: ReadonlyArray<OperationNode>;
1546
- readonly endModifiers?: ReadonlyArray<OperationNode>;
1547
- readonly nullsNotDistinct?: boolean;
1548
- readonly identity?: boolean;
1549
- readonly ifNotExists?: boolean;
847
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/drop-index-node.d.ts
848
+ type DropIndexNodeProps = Omit<DropIndexNode, 'kind' | 'name'>;
849
+ interface DropIndexNode extends OperationNode {
850
+ readonly kind: 'DropIndexNode';
851
+ readonly name: SchemableIdentifierNode;
852
+ readonly table?: TableNode;
853
+ readonly ifExists?: boolean;
854
+ readonly cascade?: boolean;
1550
855
  }
1551
- type ColumnDefinitionNodeFactory = Readonly<{
1552
- is(node: OperationNode): node is ColumnDefinitionNode;
1553
- create(column: string, dataType: OperationNode): Readonly<ColumnDefinitionNode>;
1554
- cloneWithFrontModifier(node: ColumnDefinitionNode, modifier: OperationNode): Readonly<ColumnDefinitionNode>;
1555
- cloneWithEndModifier(node: ColumnDefinitionNode, modifier: OperationNode): Readonly<ColumnDefinitionNode>;
1556
- cloneWith(node: ColumnDefinitionNode, props: ColumnDefinitionNodeProps): Readonly<ColumnDefinitionNode>;
856
+ type DropIndexNodeFactory = Readonly<{
857
+ is(node: OperationNode): node is DropIndexNode;
858
+ create(name: string, params?: DropIndexNodeProps): Readonly<DropIndexNode>;
859
+ cloneWith(dropIndex: DropIndexNode, props: DropIndexNodeProps): Readonly<DropIndexNode>;
1557
860
  }>;
1558
861
  /**
1559
862
  * @internal
1560
863
  */
1561
- declare const ColumnDefinitionNode: ColumnDefinitionNodeFactory;
864
+ declare const DropIndexNode: DropIndexNodeFactory;
1562
865
  //#endregion
1563
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/add-column-node.d.ts
1564
- interface AddColumnNode extends OperationNode {
1565
- readonly kind: 'AddColumnNode';
1566
- readonly column: ColumnDefinitionNode;
866
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/add-index-node.d.ts
867
+ interface AddIndexNode extends OperationNode {
868
+ readonly kind: 'AddIndexNode';
869
+ readonly name: IdentifierNode;
870
+ readonly columns?: OperationNode[];
871
+ readonly unique?: boolean;
872
+ readonly using?: RawNode;
873
+ readonly ifNotExists?: boolean;
1567
874
  }
1568
- type AddColumnNodeFactory = Readonly<{
1569
- is(node: OperationNode): node is AddColumnNode;
1570
- create(column: ColumnDefinitionNode): Readonly<AddColumnNode>;
875
+ type AddIndexNodeFactory = Readonly<{
876
+ is(node: OperationNode): node is AddIndexNode;
877
+ create(name: string): Readonly<AddIndexNode>;
878
+ cloneWith(node: AddIndexNode, props: Omit<AddIndexNode, 'kind' | 'name'>): Readonly<AddIndexNode>;
879
+ cloneWithColumns(node: AddIndexNode, columns: OperationNode[]): Readonly<AddIndexNode>;
1571
880
  }>;
1572
881
  /**
1573
882
  * @internal
1574
883
  */
1575
- declare const AddColumnNode: AddColumnNodeFactory;
884
+ declare const AddIndexNode: AddIndexNodeFactory;
1576
885
  //#endregion
1577
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/drop-column-node.d.ts
1578
- interface DropColumnNode extends OperationNode {
1579
- readonly kind: 'DropColumnNode';
1580
- readonly column: ColumnNode;
886
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/rename-constraint-node.d.ts
887
+ interface RenameConstraintNode extends OperationNode {
888
+ readonly kind: 'RenameConstraintNode';
889
+ readonly oldName: IdentifierNode;
890
+ readonly newName: IdentifierNode;
1581
891
  }
1582
- type DropColumnNodeFactory = Readonly<{
1583
- is(node: OperationNode): node is DropColumnNode;
1584
- create(column: string): Readonly<DropColumnNode>;
892
+ type RenameConstraintNodeFactory = Readonly<{
893
+ is(node: OperationNode): node is RenameConstraintNode;
894
+ create(oldName: string, newName: string): Readonly<RenameConstraintNode>;
1585
895
  }>;
1586
896
  /**
1587
897
  * @internal
1588
898
  */
1589
- declare const DropColumnNode: DropColumnNodeFactory;
1590
- //#endregion
1591
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/rename-column-node.d.ts
1592
- interface RenameColumnNode extends OperationNode {
1593
- readonly kind: 'RenameColumnNode';
1594
- readonly column: ColumnNode;
1595
- readonly renameTo: ColumnNode;
1596
- }
1597
- type RenameColumnNodeFactory = Readonly<{
1598
- is(node: OperationNode): node is RenameColumnNode;
1599
- create(column: string, newColumn: string): Readonly<RenameColumnNode>;
1600
- }>;
1601
- /**
1602
- * @internal
1603
- */
1604
- declare const RenameColumnNode: RenameColumnNodeFactory;
1605
- //#endregion
1606
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/raw-node.d.ts
1607
- interface RawNode extends OperationNode {
1608
- readonly kind: 'RawNode';
1609
- readonly sqlFragments: ReadonlyArray<string>;
1610
- readonly parameters: ReadonlyArray<OperationNode>;
1611
- }
1612
- type RawNodeFactory = Readonly<{
1613
- is(node: OperationNode): node is RawNode;
1614
- create(sqlFragments: ReadonlyArray<string>, parameters: ReadonlyArray<OperationNode>): Readonly<RawNode>;
1615
- createWithSql(sql: string): Readonly<RawNode>;
1616
- createWithChild(child: OperationNode): Readonly<RawNode>;
1617
- createWithChildren(children: ReadonlyArray<OperationNode>): Readonly<RawNode>;
1618
- }>;
1619
- /**
1620
- * @internal
1621
- */
1622
- declare const RawNode: RawNodeFactory;
1623
- //#endregion
1624
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/alter-column-node.d.ts
1625
- type AlterColumnNodeProps = Omit<AlterColumnNode, 'kind' | 'column'>;
1626
- interface AlterColumnNode extends OperationNode {
1627
- readonly kind: 'AlterColumnNode';
1628
- readonly column: ColumnNode;
1629
- readonly dataType?: OperationNode;
1630
- readonly dataTypeExpression?: RawNode;
1631
- readonly setDefault?: OperationNode;
1632
- readonly dropDefault?: true;
1633
- readonly setNotNull?: true;
1634
- readonly dropNotNull?: true;
1635
- }
1636
- type AlterColumnNodeFactory = Readonly<{
1637
- is(node: OperationNode): node is AlterColumnNode;
1638
- create<T extends keyof AlterColumnNodeProps>(column: string, prop: T, value: Required<AlterColumnNodeProps>[T]): Readonly<AlterColumnNode>;
1639
- }>;
1640
- /**
1641
- * @internal
1642
- */
1643
- declare const AlterColumnNode: AlterColumnNodeFactory;
1644
- //#endregion
1645
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/foreign-key-constraint-node.d.ts
1646
- type ForeignKeyConstraintNodeProps = Omit<ForeignKeyConstraintNode, 'kind' | 'columns' | 'references'>;
1647
- interface ForeignKeyConstraintNode extends OperationNode {
1648
- readonly kind: 'ForeignKeyConstraintNode';
1649
- readonly columns: ReadonlyArray<ColumnNode>;
1650
- readonly references: ReferencesNode;
1651
- readonly onDelete?: OnModifyForeignAction;
1652
- readonly onUpdate?: OnModifyForeignAction;
1653
- readonly name?: IdentifierNode;
1654
- readonly deferrable?: boolean;
1655
- readonly initiallyDeferred?: boolean;
1656
- }
1657
- type ForeignKeyConstraintNodeFactory = Readonly<{
1658
- is(node: OperationNode): node is ForeignKeyConstraintNode;
1659
- create(sourceColumns: ReadonlyArray<ColumnNode>, targetTable: TableNode, targetColumns: ReadonlyArray<ColumnNode>, constraintName?: string): Readonly<ForeignKeyConstraintNode>;
1660
- cloneWith(node: ForeignKeyConstraintNode, props: ForeignKeyConstraintNodeProps): Readonly<ForeignKeyConstraintNode>;
1661
- }>;
1662
- /**
1663
- * @internal
1664
- */
1665
- declare const ForeignKeyConstraintNode: ForeignKeyConstraintNodeFactory;
1666
- //#endregion
1667
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/primary-key-constraint-node.d.ts
1668
- interface PrimaryKeyConstraintNode extends OperationNode {
1669
- readonly kind: 'PrimaryKeyConstraintNode';
1670
- readonly columns: ReadonlyArray<ColumnNode>;
1671
- readonly name?: IdentifierNode;
1672
- readonly deferrable?: boolean;
1673
- readonly initiallyDeferred?: boolean;
1674
- }
1675
- type PrimaryKeyConstraintNodeProps = Omit<Partial<PrimaryKeyConstraintNode>, 'kind'>;
1676
- type PrimaryKeyConstraintNodeFactory = Readonly<{
1677
- is(node: OperationNode): node is PrimaryKeyConstraintNode;
1678
- create(columns: string[], constraintName?: string): Readonly<PrimaryKeyConstraintNode>;
1679
- cloneWith(node: PrimaryKeyConstraintNode, props: PrimaryKeyConstraintNodeProps): Readonly<PrimaryKeyConstraintNode>;
1680
- }>;
1681
- /**
1682
- * @internal
1683
- */
1684
- declare const PrimaryKeyConstraintNode: PrimaryKeyConstraintNodeFactory;
1685
- //#endregion
1686
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/unique-constraint-node.d.ts
1687
- interface UniqueConstraintNode extends OperationNode {
1688
- readonly kind: 'UniqueConstraintNode';
1689
- readonly columns: ReadonlyArray<ColumnNode>;
1690
- readonly name?: IdentifierNode;
1691
- readonly nullsNotDistinct?: boolean;
1692
- readonly deferrable?: boolean;
1693
- readonly initiallyDeferred?: boolean;
1694
- }
1695
- type UniqueConstraintNodeProps = Omit<Partial<UniqueConstraintNode>, 'kind'>;
1696
- type UniqueConstraintNodeFactory = Readonly<{
1697
- is(node: OperationNode): node is UniqueConstraintNode;
1698
- create(columns: string[], constraintName?: string, nullsNotDistinct?: boolean): Readonly<UniqueConstraintNode>;
1699
- cloneWith(node: UniqueConstraintNode, props: UniqueConstraintNodeProps): Readonly<UniqueConstraintNode>;
1700
- }>;
1701
- /**
1702
- * @internal
1703
- */
1704
- declare const UniqueConstraintNode: UniqueConstraintNodeFactory;
1705
- //#endregion
1706
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/constraint-node.d.ts
1707
- type ConstraintNode = PrimaryKeyConstraintNode | UniqueConstraintNode | CheckConstraintNode | ForeignKeyConstraintNode;
1708
- //#endregion
1709
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/add-constraint-node.d.ts
1710
- interface AddConstraintNode extends OperationNode {
1711
- readonly kind: 'AddConstraintNode';
1712
- readonly constraint: ConstraintNode;
1713
- }
1714
- type AddConstraintNodeFactory = Readonly<{
1715
- is(node: OperationNode): node is AddConstraintNode;
1716
- create(constraint: ConstraintNode): Readonly<AddConstraintNode>;
1717
- }>;
1718
- /**
1719
- * @internal
1720
- */
1721
- declare const AddConstraintNode: AddConstraintNodeFactory;
1722
- //#endregion
1723
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/drop-constraint-node.d.ts
1724
- type DropConstraintNodeProps = Omit<DropConstraintNode, 'kind' | 'constraintName'>;
1725
- interface DropConstraintNode extends OperationNode {
1726
- readonly kind: 'DropConstraintNode';
1727
- readonly constraintName: IdentifierNode;
1728
- readonly ifExists?: boolean;
1729
- readonly modifier?: 'cascade' | 'restrict';
1730
- }
1731
- type DropConstraintNodeFactory = Readonly<{
1732
- is(node: OperationNode): node is DropConstraintNode;
1733
- create(constraintName: string, params?: DropConstraintNodeProps): Readonly<DropConstraintNode>;
1734
- cloneWith(dropConstraint: DropConstraintNode, props: DropConstraintNodeProps): Readonly<DropConstraintNode>;
1735
- }>;
1736
- /**
1737
- * @internal
1738
- */
1739
- declare const DropConstraintNode: DropConstraintNodeFactory;
1740
- //#endregion
1741
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/modify-column-node.d.ts
1742
- interface ModifyColumnNode extends OperationNode {
1743
- readonly kind: 'ModifyColumnNode';
1744
- readonly column: ColumnDefinitionNode;
1745
- }
1746
- type ModifyColumnNodeFactory = Readonly<{
1747
- is(node: OperationNode): node is ModifyColumnNode;
1748
- create(column: ColumnDefinitionNode): Readonly<ModifyColumnNode>;
1749
- }>;
1750
- /**
1751
- * @internal
1752
- */
1753
- declare const ModifyColumnNode: ModifyColumnNodeFactory;
1754
- //#endregion
1755
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/drop-index-node.d.ts
1756
- type DropIndexNodeProps = Omit<DropIndexNode, 'kind' | 'name'>;
1757
- interface DropIndexNode extends OperationNode {
1758
- readonly kind: 'DropIndexNode';
1759
- readonly name: SchemableIdentifierNode;
1760
- readonly table?: TableNode;
1761
- readonly ifExists?: boolean;
1762
- readonly cascade?: boolean;
1763
- }
1764
- type DropIndexNodeFactory = Readonly<{
1765
- is(node: OperationNode): node is DropIndexNode;
1766
- create(name: string, params?: DropIndexNodeProps): Readonly<DropIndexNode>;
1767
- cloneWith(dropIndex: DropIndexNode, props: DropIndexNodeProps): Readonly<DropIndexNode>;
1768
- }>;
1769
- /**
1770
- * @internal
1771
- */
1772
- declare const DropIndexNode: DropIndexNodeFactory;
1773
- //#endregion
1774
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/add-index-node.d.ts
1775
- interface AddIndexNode extends OperationNode {
1776
- readonly kind: 'AddIndexNode';
1777
- readonly name: IdentifierNode;
1778
- readonly columns?: OperationNode[];
1779
- readonly unique?: boolean;
1780
- readonly using?: RawNode;
1781
- readonly ifNotExists?: boolean;
1782
- }
1783
- type AddIndexNodeFactory = Readonly<{
1784
- is(node: OperationNode): node is AddIndexNode;
1785
- create(name: string): Readonly<AddIndexNode>;
1786
- cloneWith(node: AddIndexNode, props: Omit<AddIndexNode, 'kind' | 'name'>): Readonly<AddIndexNode>;
1787
- cloneWithColumns(node: AddIndexNode, columns: OperationNode[]): Readonly<AddIndexNode>;
1788
- }>;
1789
- /**
1790
- * @internal
1791
- */
1792
- declare const AddIndexNode: AddIndexNodeFactory;
1793
- //#endregion
1794
- //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/rename-constraint-node.d.ts
1795
- interface RenameConstraintNode extends OperationNode {
1796
- readonly kind: 'RenameConstraintNode';
1797
- readonly oldName: IdentifierNode;
1798
- readonly newName: IdentifierNode;
1799
- }
1800
- type RenameConstraintNodeFactory = Readonly<{
1801
- is(node: OperationNode): node is RenameConstraintNode;
1802
- create(oldName: string, newName: string): Readonly<RenameConstraintNode>;
1803
- }>;
1804
- /**
1805
- * @internal
1806
- */
1807
- declare const RenameConstraintNode: RenameConstraintNodeFactory;
899
+ declare const RenameConstraintNode: RenameConstraintNodeFactory;
1808
900
  //#endregion
1809
901
  //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/alter-table-node.d.ts
1810
902
  type AlterTableNodeTableProps = Pick<AlterTableNode, 'renameTo' | 'setSchema' | 'addConstraint' | 'dropConstraint' | 'addIndex' | 'dropIndex' | 'renameConstraint'>;
@@ -19616,96 +18708,1043 @@ declare class ControlledTransaction<DB, S extends string[] = []> extends Transac
19616
18708
  */
19617
18709
  rollbackToSavepoint<SN extends S[number]>(savepointName: SN): RollbackToSavepoint<S, SN> extends string[] ? Command<ControlledTransaction<DB, RollbackToSavepoint<S, SN>>> : never;
19618
18710
  /**
19619
- * Releases a savepoint with a given name.
19620
- *
19621
- * See {@link savepoint} and {@link rollbackToSavepoint}.
19622
- *
19623
- * You must use the same instance returned by {@link savepoint}, or
19624
- * escape the type-check by using `as any`.
19625
- *
19626
- * ### Examples
19627
- *
19628
- * ```ts
19629
- * import type { Kysely } from 'kysely'
19630
- * import type { Database } from 'type-editor' // imaginary module
19631
- *
19632
- * const trx = await db.startTransaction().execute()
19633
- *
19634
- * await insertJennifer(trx)
19635
- *
19636
- * const trxAfterJennifer = await trx.savepoint('after_jennifer').execute()
19637
- *
19638
- * try {
19639
- * await doSomething(trxAfterJennifer)
19640
- * } catch (error) {
19641
- * await trxAfterJennifer.rollbackToSavepoint('after_jennifer').execute()
19642
- * }
19643
- *
19644
- * await trxAfterJennifer.releaseSavepoint('after_jennifer').execute()
19645
- *
19646
- * await doSomethingElse(trx)
18711
+ * Releases a savepoint with a given name.
18712
+ *
18713
+ * See {@link savepoint} and {@link rollbackToSavepoint}.
18714
+ *
18715
+ * You must use the same instance returned by {@link savepoint}, or
18716
+ * escape the type-check by using `as any`.
18717
+ *
18718
+ * ### Examples
18719
+ *
18720
+ * ```ts
18721
+ * import type { Kysely } from 'kysely'
18722
+ * import type { Database } from 'type-editor' // imaginary module
18723
+ *
18724
+ * const trx = await db.startTransaction().execute()
18725
+ *
18726
+ * await insertJennifer(trx)
18727
+ *
18728
+ * const trxAfterJennifer = await trx.savepoint('after_jennifer').execute()
18729
+ *
18730
+ * try {
18731
+ * await doSomething(trxAfterJennifer)
18732
+ * } catch (error) {
18733
+ * await trxAfterJennifer.rollbackToSavepoint('after_jennifer').execute()
18734
+ * }
18735
+ *
18736
+ * await trxAfterJennifer.releaseSavepoint('after_jennifer').execute()
18737
+ *
18738
+ * await doSomethingElse(trx)
18739
+ *
18740
+ * async function insertJennifer(kysely: Kysely<Database>) {}
18741
+ * async function doSomething(kysely: Kysely<Database>) {}
18742
+ * async function doSomethingElse(kysely: Kysely<Database>) {}
18743
+ * ```
18744
+ */
18745
+ releaseSavepoint<SN extends S[number]>(savepointName: SN): ReleaseSavepoint<S, SN> extends string[] ? Command<ControlledTransaction<DB, ReleaseSavepoint<S, SN>>> : never;
18746
+ /**
18747
+ * Returns a copy of this Kysely instance with the given plugin installed.
18748
+ */
18749
+ withPlugin(plugin: KyselyPlugin): ControlledTransaction<DB, S>;
18750
+ /**
18751
+ * Returns a copy of this Kysely instance without any plugins.
18752
+ */
18753
+ withoutPlugins(): ControlledTransaction<DB, S>;
18754
+ /**
18755
+ * @override
18756
+ */
18757
+ withSchema(schema: string): ControlledTransaction<DB, S>;
18758
+ /**
18759
+ * Returns a copy of this Kysely instance with tables added to its
18760
+ * database type.
18761
+ *
18762
+ * This method only modifies the types and doesn't affect any of the
18763
+ * executed queries in any way.
18764
+ *
18765
+ * ### Examples
18766
+ *
18767
+ * The following example adds and uses a temporary table:
18768
+ *
18769
+ * ```ts
18770
+ * await db.schema
18771
+ * .createTable('temp_table')
18772
+ * .temporary()
18773
+ * .addColumn('some_column', 'integer')
18774
+ * .execute()
18775
+ *
18776
+ * const tempDb = db.withTables<{
18777
+ * temp_table: {
18778
+ * some_column: number
18779
+ * }
18780
+ * }>()
18781
+ *
18782
+ * await tempDb
18783
+ * .insertInto('temp_table')
18784
+ * .values({ some_column: 100 })
18785
+ * .execute()
18786
+ * ```
18787
+ */
18788
+ withTables<T extends Record<string, Record<string, any>>>(): ControlledTransaction<DrainOuterGeneric<DB & T>, S>;
18789
+ }
18790
+ interface ControlledTransactionProps extends KyselyProps {
18791
+ readonly connection: ControlledConnection;
18792
+ }
18793
+ declare class Command<T> {
18794
+ #private;
18795
+ constructor(cb: () => Promise<T>);
18796
+ /**
18797
+ * Executes the command.
18798
+ */
18799
+ execute(): Promise<T>;
18800
+ }
18801
+ //#endregion
18802
+ //#region src/reactor/store.d.ts
18803
+ interface RunRow {
18804
+ id: string;
18805
+ workflow_id: string;
18806
+ workflow_name: string;
18807
+ workflow_version: number;
18808
+ trigger_kind: string;
18809
+ trigger_payload: string | null;
18810
+ status: string;
18811
+ error: string | null;
18812
+ error_name: string | null;
18813
+ enqueued_at: string;
18814
+ started_at: string;
18815
+ ended_at: string | null;
18816
+ rerun_of: string | null;
18817
+ warnings: number;
18818
+ warning_notes: string | null;
18819
+ }
18820
+ interface StepExecutionRow {
18821
+ id: string;
18822
+ run_id: string;
18823
+ ordinal: number;
18824
+ step_id: string;
18825
+ step_key: string;
18826
+ piece_name: string;
18827
+ block_name: string;
18828
+ status: string;
18829
+ input: string | null;
18830
+ output: string | null;
18831
+ port: string | null;
18832
+ error: string | null;
18833
+ error_name: string | null;
18834
+ started_at: string | null;
18835
+ ended_at: string | null;
18836
+ piece_version: string | null;
18837
+ piece_source: string | null;
18838
+ version_match: string | null;
18839
+ version_note: string | null;
18840
+ config_hash: string | null;
18841
+ attempts: number | null;
18842
+ }
18843
+ interface RunDocumentRow {
18844
+ run_id: string;
18845
+ document_id: string;
18846
+ }
18847
+ interface TriggerStateRow {
18848
+ workflow_id: string;
18849
+ piece_name: string;
18850
+ trigger_name: string;
18851
+ config_hash: string;
18852
+ status: string;
18853
+ store_state: string;
18854
+ interval_ms: number;
18855
+ next_poll_at: string | null;
18856
+ last_poll_at: string | null;
18857
+ last_error: string | null;
18858
+ consecutive_failures: number;
18859
+ lease_owner: string | null;
18860
+ lease_expires_at: string | null;
18861
+ updated_at: string;
18862
+ piece_version: string | null;
18863
+ piece_source: string | null;
18864
+ version_match: string | null;
18865
+ version_note: string | null;
18866
+ next_renew_at: string | null;
18867
+ renew_error: string | null;
18868
+ renew_failures: number;
18869
+ }
18870
+ type DefaultedTriggerColumn = "piece_version" | "piece_source" | "version_match" | "version_note" | "next_renew_at" | "renew_error" | "renew_failures";
18871
+ type TriggerStateInput = Omit<TriggerStateRow, DefaultedTriggerColumn> & Partial<Pick<TriggerStateRow, DefaultedTriggerColumn>>;
18872
+ interface TriggerDedupeRow {
18873
+ workflow_id: string;
18874
+ dedupe_key: string;
18875
+ run_id: string | null;
18876
+ created_at: string;
18877
+ attempts: number | null;
18878
+ }
18879
+ /** What a fire claim resolved to; see {@link WorkflowRunStore.claimAndEnqueueRun}. */
18880
+ type FireClaim = {
18881
+ outcome: "claimed";
18882
+ runId: string;
18883
+ } | {
18884
+ outcome: "duplicate";
18885
+ } | {
18886
+ outcome: "abandoned";
18887
+ attempts: number;
18888
+ };
18889
+ interface PieceStoreRow {
18890
+ scope: string;
18891
+ scope_key: string;
18892
+ key: string;
18893
+ value: string;
18894
+ updated_at: string;
18895
+ }
18896
+ interface WorkflowParkRow {
18897
+ workflow_id: string;
18898
+ published_version: number;
18899
+ reason: string;
18900
+ parked_at: string;
18901
+ }
18902
+ interface WorkflowRuntimeDB {
18903
+ run: RunRow & {
18904
+ admit_attempts: ColumnType<number, number | undefined, number>;
18905
+ };
18906
+ step_execution: StepExecutionRow;
18907
+ run_document: RunDocumentRow;
18908
+ trigger_state: TriggerStateRow;
18909
+ trigger_dedupe: TriggerDedupeRow;
18910
+ piece_store: PieceStoreRow;
18911
+ workflow_park: WorkflowParkRow;
18912
+ migration_mark: {
18913
+ name: string;
18914
+ applied_at: string;
18915
+ };
18916
+ }
18917
+ interface ErasedRuns {
18918
+ runs: number;
18919
+ steps: number;
18920
+ documents: number;
18921
+ dedupeKeysUnlinked: number;
18922
+ }
18923
+ interface AdmittedRun {
18924
+ runId: string;
18925
+ workflowId: string;
18926
+ triggerKind: string;
18927
+ triggerPayload: unknown;
18928
+ }
18929
+ interface PollSuccess {
18930
+ workflowId: string;
18931
+ storeState: string;
18932
+ nextPollAtIso: string | null;
18933
+ }
18934
+ interface RunKey {
18935
+ enqueuedAt: string;
18936
+ id: string;
18937
+ }
18938
+ interface ListRunsOptions {
18939
+ after?: RunKey;
18940
+ excludeTriggerKinds?: string[];
18941
+ }
18942
+ interface EnqueueRunOptions {
18943
+ workflowId: string;
18944
+ triggerKind: string;
18945
+ triggerPayload?: unknown;
18946
+ }
18947
+ interface StartRunOptions {
18948
+ workflowId: string;
18949
+ workflowName: string;
18950
+ workflowVersion: number;
18951
+ triggerKind: string;
18952
+ triggerPayload?: unknown;
18953
+ rerunOf?: string;
18954
+ }
18955
+ declare class WorkflowRunStore {
18956
+ private readonly db;
18957
+ private readonly unmigrated;
18958
+ private readonly runsInFlight;
18959
+ private readonly journaledSteps;
18960
+ private constructor();
18961
+ static create(relationalDb: IRelationalDb): Promise<WorkflowRunStore>;
18962
+ hasUnmigratedTriggerState(workflowId: string): boolean;
18963
+ clearUnmigratedTriggerState(workflowId: string): void;
18964
+ recoverOrphanedRuns(): Promise<number>;
18965
+ admitAbandonedRuns(options?: {
18966
+ enqueuedBefore?: Date;
18967
+ }): Promise<AdmittedRun[]>;
18968
+ releaseAdmission(runId: string): Promise<void>;
18969
+ /**
18970
+ * Closes a run out as CANCELLED, with the reason as its error.
18971
+ *
18972
+ * Two callers, one meaning — "this run did not finish, and the workflow is
18973
+ * not at fault": a firing SINGLETON concurrency refused, and a run that
18974
+ * passed its `runTimeoutSeconds`. Separate from `failRun` because a
18975
+ * CANCELLED run is not rerunnable and must not read as a workflow defect.
18976
+ */
18977
+ cancelRun(runId: string, reason: string): Promise<void>;
18978
+ enqueueRun(options: EnqueueRunOptions): Promise<string>;
18979
+ private unmarkOnFailure;
18980
+ /**
18981
+ * Claims the dedupe key and journals the PENDING run, bounding crash replays.
18982
+ *
18983
+ * Three outcomes, as {@link FireClaim}:
18984
+ *
18985
+ * - **`"claimed"`** with a run id: this fire is ours to run.
18986
+ * - **`"duplicate"`**: an earlier delivery of this operation already
18987
+ * fired: it journaled a run, or ran without one
18988
+ * ({@link FIRED_WITHOUT_RUN_ID}).
18989
+ * - **`"abandoned"`**: the operation has been delivered
18990
+ * {@link FIRE_CRASH_BUDGET} times and has never once got as far as
18991
+ * journaling a run — i.e. it is taking the process down before the write
18992
+ * lands, and the read-model cursor replays it on every boot. That is the
18993
+ * EPIPE boot loop (backlog item 5), and a budget is what turns it from an
18994
+ * unbootable reactor into one FAILED run naming the loop.
18995
+ *
18996
+ * Two writes, and which one is which matters:
18997
+ *
18998
+ * - The **attempt count** is bumped in its own committed transaction,
18999
+ * BEFORE the risky work. That is the only way a delivery that leaves no
19000
+ * run behind can be counted at all, which is what the budget needs. The
19001
+ * counter is never a claim signal — it only decides the budget.
19002
+ * - The **claim** is `run_id`, and it is set in the SAME transaction as the
19003
+ * run row, under a `WHERE run_id IS NULL` guard. The guard takes the
19004
+ * row's lock, so of two concurrent deliveries of one operation the second
19005
+ * blocks until the first commits and then matches no row: exactly one
19006
+ * delivery wins, and the run it journaled is committed with the claim. A
19007
+ * crash in between rolls BOTH back, so a claim that holds a run id always
19008
+ * holds a run — and a claim without one is retried, up to the budget.
19009
+ *
19010
+ * Counting and claiming are deliberately not the same write: if the bump
19011
+ * rode along inside the claim transaction, a run insert that takes the
19012
+ * process down would roll the count back with it and the budget could never
19013
+ * reach its limit — the boot loop it exists to bound.
19014
+ */
19015
+ claimAndEnqueueRun(dedupeKey: string, ttlMs: number, nowIso: string, options: EnqueueRunOptions): Promise<FireClaim>;
19016
+ journalTriggerItems(items: {
19017
+ dedupeKey?: string;
19018
+ options: EnqueueRunOptions;
19019
+ }[], ttlMs: number, nowIso: string, success?: PollSuccess): Promise<(string | undefined)[]>;
19020
+ recordScheduleFire(nowIso: string, nextPollAtIso: string, options: EnqueueRunOptions): Promise<string>;
19021
+ /**
19022
+ * Puts a piece_store partition back to `entries` and, in the same write,
19023
+ * cancels the runs the restored cursor delivers again and releases their
19024
+ * claims, so no reader sees the old cursor while the claims still hold.
19025
+ */
19026
+ rewindPieceStore(scope: string, scopeKey: string, entries: Record<string, unknown>, redelivered?: {
19027
+ runIds: string[];
19028
+ reason: string;
19029
+ }): Promise<void>;
19030
+ /**
19031
+ * Counts one delivery of an operation, and reports whether a run was ever
19032
+ * journaled for it.
19033
+ *
19034
+ * Committed on its own: the point is to leave a trace even when whatever
19035
+ * comes next takes the process down. It is NOT a claim — the row it writes
19036
+ * holds no run id, and {@link claimAndEnqueueRun} is what decides, under a
19037
+ * lock, which delivery gets to fill it in.
19038
+ */
19039
+ recordFireAttempt(workflowId: string, dedupeKey: string, ttlMs: number, nowIso: string): Promise<{
19040
+ attempts: number;
19041
+ runId: string | null;
19042
+ }>;
19043
+ /**
19044
+ * The abandonment of an over-budget fire, as a visible FAILED run, linked to
19045
+ * its dedupe key so a later delivery is a duplicate rather than another one.
19046
+ */
19047
+ journalAbandonedFire(dedupeKey: string, options: EnqueueRunOptions & {
19048
+ attempts: number;
19049
+ }): Promise<string>;
19050
+ private insertPendingRun;
19051
+ beginRun(runId: string, details: {
19052
+ workflowName: string;
19053
+ workflowVersion: number;
19054
+ }): Promise<void>;
19055
+ startRun(options: StartRunOptions): Promise<string>;
19056
+ recordStep(runId: string, ordinal: number, step: StepExecutionRecord): Promise<void>;
19057
+ private sweepIsNoop;
19058
+ finishRun(runId: string, result: WorkflowRunResult, executionOrder?: ReadonlyMap<string, number>): Promise<void>;
19059
+ private sweepSteps;
19060
+ failRun(runId: string, error: string, errorName?: string): Promise<void>;
19061
+ listRuns(workflowId?: string | string[], limit?: number, options?: ListRunsOptions): Promise<RunRow[]>;
19062
+ getRun(id: string): Promise<RunRow | undefined>;
19063
+ getSteps(runId: string): Promise<StepExecutionRow[]>;
19064
+ getStepsForRuns(runIds: string[], options?: {
19065
+ withData?: boolean;
19066
+ }): Promise<Map<string, StepExecutionRow[]>>;
19067
+ recordRunDocuments(runId: string, documentIds: string[]): Promise<void>;
19068
+ getRunDocuments(runId: string): Promise<string[]>;
19069
+ getRunDocumentsForRuns(runIds: string[]): Promise<Map<string, string[]>>;
19070
+ /**
19071
+ * Parks a workflow: its park row, and an ENABLED trigger_state row turned
19072
+ * PARKED, in one transaction. True when a trigger_state row was parked.
19073
+ */
19074
+ parkWorkflow(workflowId: string, publishedVersion: number, reason: string): Promise<boolean>;
19075
+ /** A disable clears a park: the park row, and a PARKED trigger row turned
19076
+ * DISABLED, so re-enabling arms it whether or not the supervisor held it. */
19077
+ clearParkOnDisable(workflowId: string): Promise<void>;
19078
+ /** Undoes {@link parkWorkflow}; `trigger` says whether it parked a row. */
19079
+ liftPark(workflowId: string, trigger: boolean): Promise<void>;
19080
+ getWorkflowPark(workflowId: string): Promise<WorkflowParkRow | undefined>;
19081
+ listWorkflowParks(): Promise<WorkflowParkRow[]>;
19082
+ clearWorkflowPark(workflowId: string): Promise<void>;
19083
+ getTriggerState(workflowId: string): Promise<TriggerStateRow | undefined>;
19084
+ upsertTriggerState(row: TriggerStateInput): Promise<void>;
19085
+ setTriggerStatus(workflowId: string, status: string, error?: string): Promise<void>;
19086
+ listDueTriggerStates(nowIso: string): Promise<TriggerStateRow[]>;
19087
+ listDueTriggerRenewals(nowIso: string): Promise<TriggerStateRow[]>;
19088
+ setTriggerRenewAt(workflowId: string, nextRenewAtIso: string | null): Promise<void>;
19089
+ recordRenewSuccess(workflowId: string, nowIso: string, nextRenewAtIso: string): Promise<void>;
19090
+ recordRenewFailure(workflowId: string, error: string, nowIso: string, nextRenewAtIso: string, renewFailures: number): Promise<void>;
19091
+ deleteTriggerState(workflowId: string): Promise<void>;
19092
+ listTriggerStates(): Promise<TriggerStateRow[]>;
19093
+ recordPollSuccess(workflowId: string, storeState: string, nowIso: string, nextPollAtIso: string | null): Promise<void>;
19094
+ recordPollFailure(workflowId: string, error: string, nowIso: string, nextPollAtIso: string, consecutiveFailures: number): Promise<void>;
19095
+ claimDedupe(workflowId: string, dedupeKey: string, ttlMs: number, nowIso: string): Promise<boolean>;
19096
+ deleteDedupe(workflowId: string): Promise<void>;
19097
+ pruneFinishedRuns(cutoffIso: string, batchSize?: number): Promise<number>;
19098
+ eraseRunsForDocuments(documentIds: string[]): Promise<ErasedRuns>;
19099
+ pruneDedupe(cutoffIso: string): Promise<number>;
19100
+ getPieceStoreValue(scope: string, scopeKey: string, key: string): Promise<unknown>;
19101
+ setPieceStoreValue(scope: string, scopeKey: string, key: string, value: unknown): Promise<void>;
19102
+ deletePieceStoreValue(scope: string, scopeKey: string, key: string): Promise<void>;
19103
+ listPieceStore(scope: string, scopeKey: string): Promise<Record<string, unknown>>;
19104
+ deletePieceStore(scope: string, scopeKey: string): Promise<void>;
19105
+ }
19106
+ //#endregion
19107
+ //#region src/reactor/park-state.d.ts
19108
+ declare class ParkState {
19109
+ private readonly load;
19110
+ private readonly parks;
19111
+ private readonly written;
19112
+ private seeded;
19113
+ private seeding?;
19114
+ constructor(load: () => Promise<readonly WorkflowParkRow[] | undefined>);
19115
+ get(workflowId: string): Promise<WorkflowParkRow | undefined>;
19116
+ known(workflowId: string): {
19117
+ park?: WorkflowParkRow;
19118
+ } | undefined;
19119
+ set(park: WorkflowParkRow): void;
19120
+ delete(workflowId: string): void;
19121
+ private seed;
19122
+ }
19123
+ //#endregion
19124
+ //#region src/reactor/trigger-supervisor.d.ts
19125
+ interface PieceTriggerBinding {
19126
+ kind?: "piece";
19127
+ workflowId: string;
19128
+ block: BlockRef;
19129
+ packageName: string;
19130
+ version: string;
19131
+ triggerName: string;
19132
+ config: Record<string, unknown>;
19133
+ connectionId?: string | null;
19134
+ reactorConnectionId?: string | null;
19135
+ pollIntervalMs?: number;
19136
+ propertySettings?: PropertySettingDef[];
19137
+ source?: PieceOrigin;
19138
+ match?: BlockMatch;
19139
+ note?: string;
19140
+ }
19141
+ interface ScheduleTriggerBinding {
19142
+ kind: "schedule";
19143
+ workflowId: string;
19144
+ block: BlockRef;
19145
+ config: Record<string, unknown>;
19146
+ }
19147
+ type TriggerBinding = PieceTriggerBinding | ScheduleTriggerBinding;
19148
+ interface TriggerSupervisorOptions {
19149
+ store: () => Promise<WorkflowRunStore | undefined>;
19150
+ hookConcurrency?: number;
19151
+ parks?: ParkState;
19152
+ resolveAuth: (connectionId: string | null | undefined, request?: ConnectionRequest) => Promise<unknown>;
19153
+ fire: (workflowId: string, payload: unknown, kind: string, runId: string) => void;
19154
+ cacheDir: string;
19155
+ resolver?: PieceResolver;
19156
+ worker?: IPieceWorker;
19157
+ models?: ModelManifestSource;
19158
+ telemetry?: WorkflowTelemetry;
19159
+ reactorAccess?: (binding: PieceTriggerBinding, requireReactor: "read" | "write", runUser: RunUser | null | undefined) => Promise<ReactorTap>;
19160
+ egress?: EgressPolicy | null;
19161
+ tickMs?: number;
19162
+ defaultIntervalMs?: number;
19163
+ hookTimeoutMs?: number;
19164
+ webhookUrlFor?: (workflowId: string) => Promise<string | undefined>;
19165
+ reconcileIntervalMs?: number;
19166
+ now?: () => Date;
19167
+ }
19168
+ declare class TriggerSupervisor {
19169
+ private readonly options;
19170
+ private readonly bindings;
19171
+ private readonly worker;
19172
+ private readonly tickMs;
19173
+ private readonly defaultIntervalMs;
19174
+ private readonly hookTimeoutMs;
19175
+ private readonly now;
19176
+ private readonly egress;
19177
+ private readonly parks;
19178
+ private timer?;
19179
+ private readonly lanes;
19180
+ private readonly ticked;
19181
+ private readonly hookSlots;
19182
+ private ticking;
19183
+ private warnedMissingJournal;
19184
+ private stopped;
19185
+ constructor(options: TriggerSupervisorOptions);
19186
+ start(): void;
19187
+ stop(): void;
19188
+ private enqueue;
19189
+ private throwIfStopped;
19190
+ private store;
19191
+ private fire;
19192
+ private readonly enabledOk;
19193
+ private readonly descriptors;
19194
+ private own;
19195
+ private resolver;
19196
+ private readonly enableRetries;
19197
+ private readonly versions;
19198
+ upsert(binding: TriggerBinding, publishedVersion?: number): Promise<void>;
19199
+ /** Parks a workflow; true when a trigger row was parked with it. */
19200
+ park(workflowId: string, publishedVersion: number, reason: string): Promise<boolean>;
19201
+ /** Undoes {@link park} for that version only: a later park stands. */
19202
+ liftPark(workflowId: string, publishedVersion: number, trigger: boolean): Promise<void>;
19203
+ /** A disable clears the park. With no binding in memory to release a PARKED
19204
+ * row through onDisable (a boot), the row is turned DISABLED here. */
19205
+ releasePark(workflowId: string, flipRow: boolean): Promise<void>;
19206
+ /** A re-publish past the parked version: on this lane, a park older than
19207
+ * `publishedVersion` goes and a row it parked is ENABLED again, as it was
19208
+ * before (only an ENABLED row is ever parked); a park as new stands. The
19209
+ * next upsert of the same binding then arms rather than skipping as
19210
+ * unchanged, and a retry held back by the park is due now. */
19211
+ unpark(workflowId: string, publishedVersion: number): Promise<void>;
19212
+ remove(workflowId: string): Promise<void>;
19213
+ forget(workflowId: string): Promise<void>;
19214
+ private unbind;
19215
+ reject(workflowId: string, block: BlockIdentity, config: unknown, message: string, retryAt?: Date): Promise<void>;
19216
+ private recordRejection;
19217
+ test(binding: PieceTriggerBinding, options?: {
19218
+ runUser?: RunUser | null;
19219
+ }): Promise<unknown>;
19220
+ private dropTestPartitions;
19221
+ handshake(binding: PieceTriggerBinding, payload: unknown): Promise<PieceWorkerResult>;
19222
+ deliverWebhook(workflowId: string, payload: unknown): Promise<void>;
19223
+ private cursorRewind;
19224
+ private hook;
19225
+ private reactorFor;
19226
+ private pieceDescriptor;
19227
+ private triggerDescriptor;
19228
+ private deliveryFor;
19229
+ private enable;
19230
+ private renewAtAfterEnable;
19231
+ private webhookUrlOrThrow;
19232
+ /**
19233
+ * The park, when it holds this registration back.
19234
+ *
19235
+ * `policy.onFailure = PARK` is a **runtime override of the document's
19236
+ * enabled-ness**: the document still says ENABLED, and re-arming from it is
19237
+ * what a restart does for every workflow it finds. So the park row is the
19238
+ * authority, read on this lane, and it blocks every registration of the
19239
+ * version that failed or an older one — a boot re-arm, an ERROR row's
19240
+ * retry. A newer version is what a re-publish is: it is never blocked, and
19241
+ * {@link enable} lifts the park it outlived. A re-enable lifts it through
19242
+ * the disable before it.
19243
+ */
19244
+ private blockingPark;
19245
+ /**
19246
+ * An enable a park held back. The row is left as it stands, and a pending
19247
+ * retry keeps its release flag, so the enable after the park lifts releases
19248
+ * a failed attempt and arms afresh; the retry is only pushed back, so it
19249
+ * does not take every tick's slot. A binding this replaced is restored, so
19250
+ * nothing is released later with one that was never armed.
19251
+ */
19252
+ private holdParked;
19253
+ /** The status an enable that succeeded writes: never ENABLED while a park
19254
+ * stands, whatever ran meanwhile. The registration stays recorded. */
19255
+ private armedStatus;
19256
+ private deferToStoredRetry;
19257
+ private releaseRegistration;
19258
+ private enableSchedule;
19259
+ private disable;
19260
+ private disableRow;
19261
+ private bindingFromRow;
19262
+ tick(): Promise<void>;
19263
+ private startOnLane;
19264
+ private startOneEnableRetry;
19265
+ private retryEnable;
19266
+ private startDue;
19267
+ private whileBound;
19268
+ private isScheduleRow;
19269
+ private startRenewals;
19270
+ private renew;
19271
+ private fireSchedule;
19272
+ private poll;
19273
+ private fireItems;
19274
+ private redeliver;
19275
+ private failRefused;
19276
+ }
19277
+ //#endregion
19278
+ //#region src/reactor/service.d.ts
19279
+ /** Why a firing was journaled CANCELLED without running, when it was. */
19280
+ type FiringRefusal = "parked" | "singleton" | "stale" | "queue-full" | "expired";
19281
+ type PersistedRunResult = WorkflowRunResult & {
19282
+ runId: string | null;
19283
+ refusal?: FiringRefusal;
19284
+ };
19285
+ type RunResume = {
19286
+ completedSteps: Map<string, ReplayedStep>;
19287
+ rerunOf: string;
19288
+ };
19289
+ interface ConnectionSummary {
19290
+ id: string;
19291
+ name: string;
19292
+ connectorId: string;
19293
+ authType: string;
19294
+ status: string;
19295
+ accountLabel: string | null;
19296
+ }
19297
+ interface ConnectionCheckResult {
19298
+ ok: boolean;
19299
+ detail: string | null;
19300
+ accountLabel: string | null;
19301
+ }
19302
+ /** A journal row with the steps that belong to it, as the subgraph serves it. */
19303
+ interface RunRecord {
19304
+ row: RunRow;
19305
+ steps: StepExecutionRow[];
19306
+ }
19307
+ interface RunsArgs {
19308
+ workflowId?: string;
19309
+ driveId?: string;
19310
+ limit?: number;
19311
+ excludeTriggerKinds?: string[];
19312
+ withStepData?: boolean;
19313
+ }
19314
+ interface RunsPageArgs extends RunsArgs {
19315
+ cursor?: string | null;
19316
+ }
19317
+ interface RunPage {
19318
+ records: RunRecord[];
19319
+ hasNextPage: boolean;
19320
+ cursor: string | null;
19321
+ }
19322
+ /** One draft block as this reactor resolves it. */
19323
+ interface BlockResolutionRecord {
19324
+ stepId: string;
19325
+ pieceName: string;
19326
+ pieceVersion: string;
19327
+ name: string;
19328
+ kind: "action" | "trigger";
19329
+ resolvedVersion: string | null;
19330
+ source: string | null;
19331
+ match: string;
19332
+ note: string | null;
19333
+ latestVersion: string | null;
19334
+ }
19335
+ interface TriggerTestOptions extends WorkflowAccessOptions {
19336
+ payload?: unknown;
19337
+ timeoutMs?: number;
19338
+ }
19339
+ interface WebhookEndpointRecord {
19340
+ workflowId: string;
19341
+ url: string;
19342
+ absoluteUrl: boolean;
19343
+ armed: boolean;
19344
+ createdAt: string;
19345
+ }
19346
+ export declare class WorkflowRuntimeService {
19347
+ private readonly host;
19348
+ private readonly logger;
19349
+ private readonly telemetry;
19350
+ private readonly attachments?;
19351
+ private executor?;
19352
+ private pieceWorkers?;
19353
+ private unobservePool?;
19354
+ private runDispatcher?;
19355
+ private unobserveDispatcher?;
19356
+ private readonly eventLoop;
19357
+ private storePromise;
19358
+ private storeError?;
19359
+ private storeOpening;
19360
+ private storeReopenAt;
19361
+ private storeReopenMs;
19362
+ private retentionSweep?;
19363
+ private secretsPromise?;
19364
+ private oauthAttemptsPromise?;
19365
+ private tokenRefresher?;
19366
+ private readonly registry;
19367
+ private readonly seedPromise;
19368
+ private seedError?;
19369
+ constructor(host: WorkflowRuntimeHostDeps);
19370
+ private retentionTimer?;
19371
+ private startRetention;
19372
+ private sweepRetention;
19373
+ store(): Promise<WorkflowRunStore | undefined>;
19374
+ private openStore;
19375
+ secrets(): Promise<SecretStore>;
19376
+ private secretProvider;
19377
+ private oauthAttempts;
19378
+ private oauthRefresher;
19379
+ /** The seeding failure a restart is needed to clear, or undefined while the
19380
+ * registry is seeded. Resolves once seeding has finished either way. */
19381
+ seedFailure(): Promise<unknown>;
19382
+ private seedWithRetries;
19383
+ private seedRegistry;
19384
+ private endpointCount;
19385
+ private hasWebhookEndpoints;
19386
+ private readonly registeredAs;
19387
+ private readonly registrationChains;
19388
+ private inRegistrationOrder;
19389
+ private updateRegistration;
19390
+ private registerNow;
19391
+ private applyRegistration;
19392
+ private enableSupervised;
19393
+ private registerPieceTrigger;
19394
+ private pieceDelivery;
19395
+ private refusePieceTrigger;
19396
+ private registerWebhook;
19397
+ private supervisedBinding;
19398
+ private pieceBinding;
19399
+ private readonly blockResolver;
19400
+ private versionHasBlock;
19401
+ private readonly loggedResolutions;
19402
+ resolveBlock(block: BlockRef, options?: {
19403
+ fresh?: boolean;
19404
+ latest?: boolean;
19405
+ }): Promise<BlockResolution>;
19406
+ private logResolution;
19407
+ private resolvedPiece;
19408
+ private readonly reactorDenials;
19409
+ private recheckReactorAccess;
19410
+ private checkReactorAccess;
19411
+ private seedReactorAccess;
19412
+ reactorAccessDenial(workflowId: string): string | undefined;
19413
+ private refuseArming;
19414
+ private readonly unarmed;
19415
+ private reportUnarmedTrigger;
19416
+ private readonly resolutionRetries;
19417
+ private scheduleResolutionRetry;
19418
+ private cancelResolutionRetry;
19419
+ private dropSupervised;
19420
+ private refreshRegistration;
19421
+ private readonly seenOps;
19422
+ private readonly workflowCache;
19423
+ private readonly workflowGenerations;
19424
+ private workflowGeneration;
19425
+ private cacheLoaded;
19426
+ private cacheWorkflow;
19427
+ private readonly seenOpsQueue;
19428
+ private alreadySeen;
19429
+ onDocumentsPurged(markers: OperationWithContext[]): Promise<ErasedRuns>;
19430
+ onOperations(operations: OperationWithContext[]): Promise<void>;
19431
+ private readonly unjournaledFires;
19432
+ private fireUnjournaled;
19433
+ private enqueueFire;
19434
+ private fireFromTrigger;
19435
+ private journalFiring;
19436
+ private startFiring;
19437
+ private readonly firedLifecycle;
19438
+ private readonly firedLifecycleQueue;
19439
+ private lifecycleAlreadyFired;
19440
+ private recordLifecycleFired;
19441
+ private lifecycleTargets;
19442
+ private fireLifecycle;
19443
+ private readonly driveParentCache;
19444
+ private driveIdFromParent;
19445
+ private forgetDeletedWorkflow;
19446
+ private disarmDeleted;
19447
+ private dropDeleted;
19448
+ private releaseDeleted;
19449
+ private erasePurgedWorkflow;
19450
+ private matchDocumentLifecycle;
19451
+ private matchDriveLifecycle;
19452
+ private triggerSupervisor?;
19453
+ private readonly parks;
19454
+ supervisor(): TriggerSupervisor;
19455
+ private laneFailed;
19456
+ startTriggerSupervisor(): void;
19457
+ private pendingSweepTimer?;
19458
+ private admittingAbandoned;
19459
+ private admitAbandonedRuns;
19460
+ stopTriggerSupervisor(): void;
19461
+ private closed;
19462
+ private throwIfClosed;
19463
+ shutdown(): void;
19464
+ triggerStates(ctx?: WorkflowCaller): Promise<TriggerStateRow[]>;
19465
+ private webhookEndpoints?;
19466
+ private webhookScope?;
19467
+ private webhookRegistration?;
19468
+ /** Registers the workflow endpoint family with the reactor's webhook service
19469
+ * (idempotent). Everything transport-shaped is the service's; only workflow identity is ours. */
19470
+ registerWebhookEndpoint(): Promise<void>;
19471
+ /** The endpoint family, once registered. Seeding runs before the host starts
19472
+ * the runtime, so a caller that needs a token waits rather than finds it missing. */
19473
+ private endpoints;
19474
+ /** The per-document policy the service enforces before a delivery reaches this code;
19475
+ * undefined means the workflow is not armed, answered exactly as an unknown token is. */
19476
+ webhookPolicy(workflowId: string): Promise<WebhookPolicy | undefined>;
19477
+ private liveWebhook;
19478
+ private policyOf;
19479
+ webhookEndpoint(workflowId: string, ctx?: WorkflowCaller, access?: WorkflowAccessOptions): Promise<WebhookEndpointRecord | null>;
19480
+ private mintWebhookEndpoint;
19481
+ /** A delivery the service has already rate-limited, verified, de-duplicated and
19482
+ * answered any challenge for; all that is left is deciding what it means. */
19483
+ deliverWebhook(request: WebhookRequest): Promise<WebhookReply>;
19484
+ private pieceHandshake;
19485
+ private pieceHandshakeConfig;
19486
+ private deliverToPiece;
19487
+ private webhookSecret;
19488
+ private readonly models;
19489
+ private modelEntries;
19490
+ private declaredReactor;
19491
+ private callerRunUser;
19492
+ private reactorScope;
19493
+ private stepReactorAccess;
19494
+ private triggerReactorAccess;
19495
+ private designReactorAccess;
19496
+ private readonly descriptors;
19497
+ private designWorker?;
19498
+ private createDesignWorker;
19499
+ private designEgress;
19500
+ private readonly describing;
19501
+ private pieceDescriptor;
19502
+ private describe;
19503
+ driveWorkflowIds(driveId: string, ctx?: WorkflowCaller): Promise<string[]>;
19504
+ runs(args: RunsArgs, ctx?: WorkflowCaller): Promise<RunRecord[]>;
19505
+ runsPage(args: RunsPageArgs, ctx?: WorkflowCaller): Promise<RunPage>;
19506
+ private listRunsPage;
19507
+ run(runId: string, ctx?: WorkflowCaller): Promise<RunRecord | null>;
19508
+ connections(ctx?: WorkflowCaller): Promise<ConnectionSummary[]>;
19509
+ checkConnection(connectionId: string, ctx?: WorkflowCaller): Promise<ConnectionCheckResult>;
19510
+ private connectionDocument;
19511
+ private checkConnectionDocument;
19512
+ startOAuth(connectionId: string, ctx: WorkflowCaller | undefined, options: {
19513
+ redirectUri: string;
19514
+ returnUrl?: string;
19515
+ }): Promise<OAuthStart>;
19516
+ oauthAttempt(state: string, ctx: WorkflowCaller | undefined): Promise<OAuthAttemptView | null>;
19517
+ completeOAuth(callback: {
19518
+ state: string;
19519
+ code?: string;
19520
+ error?: string;
19521
+ errorDescription?: string;
19522
+ }): Promise<{
19523
+ ok: boolean;
19524
+ detail: string | null;
19525
+ returnUrl: string | null;
19526
+ }>;
19527
+ private recordCheckResult;
19528
+ private localPieces;
19529
+ private localPiece;
19530
+ pieceCatalog(): Promise<PieceSummary[]>;
19531
+ pieceActions(packageName: string, version?: string): Promise<PieceActionsResult>;
19532
+ pieceTriggers(packageName: string, version?: string): Promise<PieceTriggersResult>;
19533
+ warmPieceSearch(): void;
19534
+ searchPieces(query: string, filter: PieceSearchFilter): Promise<PieceSearchResult>;
19535
+ pieceDetail(packageName: string, version?: string): Promise<unknown>;
19536
+ private localPieceAt;
19537
+ blockDescriptor(block: BlockRef): Promise<unknown>;
19538
+ private readableDocuments;
19539
+ private readableRows;
19540
+ private canReadDocument;
19541
+ private servedRuns;
19542
+ private servesDocuments;
19543
+ private servesRunDocument;
19544
+ private assertCanReadDocument;
19545
+ private assertCanReadWorkflow;
19546
+ private assertCanWriteDocument;
19547
+ blockOptions(block: BlockRef, propName: string, input?: unknown, connectionId?: string, ctx?: WorkflowCaller, searchValue?: string, reactorConnectionId?: string): Promise<unknown>;
19548
+ blockOutputTree(block: BlockRef, config?: unknown): Promise<OutputTree>;
19549
+ private stateFields;
19550
+ private operationInputFields;
19551
+ testTrigger(workflowId: string, ctx?: WorkflowCaller, options?: TriggerTestOptions): Promise<unknown>;
19552
+ private triggerTest;
19553
+ private readonly webhookTests;
19554
+ private awaitWebhookTest;
19555
+ /** Stops a waiting webhook test; false when none was waiting. */
19556
+ cancelTriggerTest(workflowId: string, reason?: string): boolean;
19557
+ cancelTriggerTestFor(workflowId: string, ctx?: WorkflowCaller): Promise<boolean>;
19558
+ private recordTest;
19559
+ private noteLastTest;
19560
+ private blockExecutor;
19561
+ private workers;
19562
+ private dispatcher;
19563
+ fire(workflowId: string, triggerPayload?: unknown, triggerKind?: string, resume?: RunResume, ctx?: WorkflowCaller, enqueuedRunId?: string): Promise<PersistedRunResult>;
19564
+ private runFired;
19565
+ private readonly runGate;
19566
+ private readonly heldReplies;
19567
+ /** Why a trigger's firing of a PARKED workflow is refused; undefined when
19568
+ * it is not parked, or when an operator started the run. */
19569
+ private parkedFiring;
19570
+ /** Why a firing that waited for its slot may no longer run, if it may not. */
19571
+ private staleAfterWait;
19572
+ /** Whether the workflow is still ENABLED at this published version. An
19573
+ * unreadable document counts as unchanged, so a failure still parks. */
19574
+ private stillRunsVersion;
19575
+ /** A park recorded against an earlier published version than this state's. */
19576
+ private outdatedPark;
19577
+ /**
19578
+ * A firing SINGLETON refused.
19647
19579
  *
19648
- * async function insertJennifer(kysely: Kysely<Database>) {}
19649
- * async function doSomething(kysely: Kysely<Database>) {}
19650
- * async function doSomethingElse(kysely: Kysely<Database>) {}
19651
- * ```
19652
- */
19653
- releaseSavepoint<SN extends S[number]>(savepointName: SN): ReleaseSavepoint<S, SN> extends string[] ? Command<ControlledTransaction<DB, ReleaseSavepoint<S, SN>>> : never;
19654
- /**
19655
- * Returns a copy of this Kysely instance with the given plugin installed.
19656
- */
19657
- withPlugin(plugin: KyselyPlugin): ControlledTransaction<DB, S>;
19658
- /**
19659
- * Returns a copy of this Kysely instance without any plugins.
19660
- */
19661
- withoutPlugins(): ControlledTransaction<DB, S>;
19662
- /**
19663
- * @override
19580
+ * Journaled as a CANCELLED run rather than dropped: a firing that vanished
19581
+ * is indistinguishable from a trigger that never fired, which is the class
19582
+ * of bug this work package exists to stamp out. An already-enqueued row is
19583
+ * closed out in place, so nothing is left PENDING for a sweep to find.
19664
19584
  */
19665
- withSchema(schema: string): ControlledTransaction<DB, S>;
19585
+ private refuseClosed;
19586
+ private skipFiring;
19666
19587
  /**
19667
- * Returns a copy of this Kysely instance with tables added to its
19668
- * database type.
19669
- *
19670
- * This method only modifies the types and doesn't affect any of the
19671
- * executed queries in any way.
19672
- *
19673
- * ### Examples
19674
- *
19675
- * The following example adds and uses a temporary table:
19676
- *
19677
- * ```ts
19678
- * await db.schema
19679
- * .createTable('temp_table')
19680
- * .temporary()
19681
- * .addColumn('some_column', 'integer')
19682
- * .execute()
19588
+ * `policy.onFailure` for a run that failed terminally.
19683
19589
  *
19684
- * const tempDb = db.withTables<{
19685
- * temp_table: {
19686
- * some_column: number
19687
- * }
19688
- * }>()
19590
+ * PARK is the document model's own default, so this is where enforcing the
19591
+ * knob becomes visible: a terminal failure parks the workflow, whatever its
19592
+ * trigger kind, and nothing fires it until it is re-published or
19593
+ * re-enabled. That is what PARK means, and
19594
+ * leaving a broken workflow firing every minute is what it meant before.
19689
19595
  *
19690
- * await tempDb
19691
- * .insertInto('temp_table')
19692
- * .values({ some_column: 100 })
19693
- * .execute()
19694
- * ```
19596
+ * NOTIFY logs at error level, which is the only notification channel this
19597
+ * engine has; it is marked as such rather than pretending to page anyone.
19695
19598
  */
19696
- withTables<T extends Record<string, Record<string, any>>>(): ControlledTransaction<DrainOuterGeneric<DB & T>, S>;
19599
+ private applyFailureMode;
19600
+ rerun(runId: string, ctx?: WorkflowCaller): Promise<PersistedRunResult>;
19601
+ private rereads;
19602
+ testStep(workflowId: string, stepId: string, ctx?: WorkflowCaller, access?: WorkflowAccessOptions): Promise<StepTestResult>;
19603
+ private testScope;
19604
+ private readReferencedDocuments;
19605
+ private documentShapes;
19606
+ private lastTestSample;
19607
+ stepOutputTree(workflowId: string, stepId: string, ctx?: WorkflowCaller): Promise<OutputTree>;
19608
+ blockResolutions(workflowId: string, ctx?: WorkflowCaller): Promise<BlockResolutionRecord[]>;
19609
+ private draftOf;
19697
19610
  }
19698
- interface ControlledTransactionProps extends KyselyProps {
19699
- readonly connection: ControlledConnection;
19611
+ /** The runtime a host composes: one instance, its lifetime the host's. */
19612
+ export declare function createWorkflowRuntime(deps: WorkflowRuntimeHostDeps): WorkflowRuntimeService;
19613
+ //#endregion
19614
+ //#region src/reactor/run-cursor.d.ts
19615
+ export declare class InvalidRunCursorError extends Error {
19616
+ constructor();
19700
19617
  }
19701
- declare class Command<T> {
19702
- #private;
19703
- constructor(cb: () => Promise<T>);
19618
+ //#endregion
19619
+ //#region src/reactor/singleton-lease.d.ts
19620
+ /**
19621
+ * Names this process as the workflow singleton's owner.
19622
+ *
19623
+ * Set it to a STABLE name per deployment slot (`switchboard-0`, the
19624
+ * StatefulSet pod name, the Render service id). The owner name is the
19625
+ * operator's contract: a restart under the same name re-claims its own lease
19626
+ * once the old heartbeat is stale instead of waiting out
19627
+ * {@link SINGLETON_LEASE_TTL_MS}.
19628
+ *
19629
+ * Unset, the owner is derived from a STABLE identity — the hostname and a
19630
+ * fingerprint of the journal's own storage location ({@link
19631
+ * AcquireSingletonOptions.storageId}) — not from the pid and a random suffix.
19632
+ * A random per-process owner meant every unclean kill locked the next boot out
19633
+ * for the whole {@link SINGLETON_LEASE_TTL_MS}: the dead process's lease was
19634
+ * nobody's to re-claim, and `release()` never ran. One deployment slot
19635
+ * restarting is the common case and it has to be quick; a genuine second
19636
+ * replica still differs, by hostname or by the journal it points at.
19637
+ */
19638
+ export declare const WORKFLOW_SINGLETON_OWNER_ENV = "PH_WORKFLOWS_SINGLETON_OWNER";
19639
+ /** How long a claim stays valid without a heartbeat. */
19640
+ export declare const SINGLETON_LEASE_TTL_MS = 60000;
19641
+ /** How often the holder renews it; a third of the TTL, so two renewals may be
19642
+ * lost (a GC pause, a slow database) before anyone may take over. */
19643
+ export declare const SINGLETON_HEARTBEAT_MS: number;
19644
+ /**
19645
+ * How long the holder's heartbeat must have been silent before a claim under
19646
+ * the SAME owner name takes the lease over, short of its expiry. Two renewal
19647
+ * periods: a live holder renews well inside it, and its self-fence fires
19648
+ * before it passes.
19649
+ */
19650
+ export declare const SINGLETON_STALE_HEARTBEATS = 2;
19651
+ /** Another live process holds the singleton. The refusal is the point: a host
19652
+ * that cannot own workflow execution must not compose the engine. */
19653
+ export declare class WorkflowSingletonConflictError extends Error {
19654
+ readonly owner: string;
19655
+ readonly expiresAt: string;
19656
+ readonly wouldBe: string;
19657
+ constructor(owner: string, expiresAt: string, wouldBe: string);
19658
+ }
19659
+ /**
19660
+ * Why a holder stopped owning workflow execution.
19661
+ *
19662
+ * - `taken`: a renewal matched no row, so another claim holds the lease
19663
+ * (`heldBy` names it when the row still exists).
19664
+ * - `unrenewable`: no renewal landed for long enough that another claim could
19665
+ * take it over; none was seen to.
19666
+ */
19667
+ type WorkflowSingletonLoss = {
19668
+ reason: "taken";
19669
+ heldBy: string | undefined;
19670
+ } | {
19671
+ reason: "unrenewable";
19672
+ silentMs: number;
19673
+ };
19674
+ /** A held claim, renewed from the moment it is taken. The host releases it on
19675
+ * shutdown, so the next boot does not wait out the TTL. */
19676
+ interface WorkflowSingletonLease {
19677
+ readonly owner: string;
19678
+ /** Renews once; false when the lease is no longer ours. */
19679
+ heartbeat(): Promise<boolean>;
19680
+ /** Stops renewing and drops the row if it is still ours. */
19681
+ release(): Promise<void>;
19682
+ }
19683
+ interface AcquireSingletonOptions {
19684
+ relationalDb: IRelationalDb;
19685
+ logger?: ILogger;
19686
+ /** Defaults to {@link WORKFLOW_SINGLETON_OWNER_ENV}, then
19687
+ * `<hostname>/<storageId fingerprint>`. */
19688
+ owner?: string;
19704
19689
  /**
19705
- * Executes the command.
19690
+ * Where this host's journal lives — a Postgres URL, an absolute PGlite
19691
+ * directory — as the stable half of the default owner name. Hashed, so a
19692
+ * connection string's credentials never reach the lease row or a log line.
19693
+ *
19694
+ * It is what separates two hosts that share a hostname but not a journal,
19695
+ * and it is stable across restarts, which is the whole point.
19706
19696
  */
19707
- execute(): Promise<T>;
19697
+ storageId?: string;
19698
+ ttlMs?: number;
19699
+ heartbeatMs?: number;
19700
+ /** Called once, when this process stops owning workflow execution. */
19701
+ onLost?: (loss: WorkflowSingletonLoss) => void;
19702
+ /**
19703
+ * Whether a holder that cannot renew reports itself lost before anyone
19704
+ * could take over. On by default. Off for a journal no other process can
19705
+ * open (embedded PGlite): nothing can take the lease, so a stalled renewal
19706
+ * is only logged.
19707
+ */
19708
+ selfFence?: boolean;
19709
+ env?: Record<string, string | undefined>;
19708
19710
  }
19711
+ /**
19712
+ * The owner name this process claims under.
19713
+ *
19714
+ * `<hostname>/<storage fingerprint>`, so it is the same name on every boot of
19715
+ * one deployment slot — a restart re-claims its OWN lease once the dead
19716
+ * process's heartbeat is stale, rather than waiting out the TTL — and a different
19717
+ * name on any host or journal that is genuinely somebody else.
19718
+ *
19719
+ * The storage location is hashed, never printed: it can be a Postgres URL with
19720
+ * credentials in it, and the owner name goes into a database row an operator
19721
+ * reads and into every log line about the lease.
19722
+ *
19723
+ * The residual case a stable name cannot tell apart is two processes on ONE
19724
+ * host over ONE journal, which is a misconfiguration those two already share
19725
+ * (one read-model directory, one run journal). It is not silent: the loser's
19726
+ * heartbeat finds the lease taken and says so by name.
19727
+ */
19728
+ export declare function singletonOwnerName(env?: Record<string, string | undefined>, storageId?: string): string;
19729
+ /**
19730
+ * Claims the workflow singleton, or refuses.
19731
+ *
19732
+ * Three steps, each one a single statement whose own outcome is the claim — a
19733
+ * prior `SELECT` would be a race:
19734
+ *
19735
+ * 1. `INSERT … ON CONFLICT DO NOTHING RETURNING` — the first ever boot.
19736
+ * 2. `UPDATE … WHERE expires_at <= now OR (owner = me AND heartbeat stale)
19737
+ * RETURNING` — a dead lease taken over once it has expired, or our own
19738
+ * slot's lease once its holder stopped renewing (a restart under a stable
19739
+ * owner name), never a live holder's. Either way the row gets this claim's
19740
+ * instance, so the previous holder's heartbeat and release no longer
19741
+ * match.
19742
+ * 3. Neither matched: someone live holds it, and we refuse by name.
19743
+ */
19744
+ export declare function acquireWorkflowSingletonLease(options: AcquireSingletonOptions): Promise<WorkflowSingletonLease>;
19745
+ //#endregion
19746
+ //#region src/reactor/run-user.d.ts
19747
+ export declare function publishRunUser(client: Pick<IReactorClient, "getOperations">, workflowId: string, hostIdentity?: HostIdentity, signal?: AbortSignal): Promise<RunUser | null>;
19709
19748
  //#endregion
19710
19749
  //#region src/reactor/workflow-triggers-read-model.d.ts
19711
19750
  export declare const WORKFLOW_TRIGGERS_READ_MODEL = "workflow-triggers";