chore: snapshot main sync

This commit is contained in:
2026-06-17 20:08:31 +00:00
parent b18de2a331
commit 8bd32537cf
354 changed files with 10208 additions and 9230 deletions

View File

@@ -6,7 +6,7 @@
* rename (write to temp file, then rename).
*/
import { mkdir, writeFile, readFile, readdir, rename, unlink } from 'node:fs/promises';
import { mkdir, writeFile, readFile, readdir, rename } from "node:fs/promises";
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import { nanoid } from 'nanoid';
@@ -19,10 +19,6 @@ import type {
CreateWorkflowRunData,
} from '../engine/deps.js';
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
const ACTIVE_STATUSES: WorkflowRunStatus[] = ['pending', 'running'];
function parseRun(raw: string): WorkflowRun {
@@ -61,20 +57,12 @@ function serializeEvent(event: WorkflowEvent): string {
});
}
// ---------------------------------------------------------------------------
// Atomic write helper
// ---------------------------------------------------------------------------
async function atomicWrite(filePath: string, data: string): Promise<void> {
const tmp = `${filePath}.${nanoid(8)}.tmp`;
await writeFile(tmp, data, 'utf-8');
await rename(tmp, filePath);
}
// ---------------------------------------------------------------------------
// Factory
// ---------------------------------------------------------------------------
export function createFsStore(basePath: string): IWorkflowStore {
// Ensure base directory exists on first write — no side effects at import.
@@ -98,7 +86,6 @@ export function createFsStore(basePath: string): IWorkflowStore {
const runDir = join(basePath, id);
await mkdir(runDir, { recursive: true });
await atomicWrite(join(runDir, 'run.json'), serializeRun(run));
// Create empty events file
await atomicWrite(join(runDir, 'events.jsonl'), '');
return run;

View File

@@ -15,10 +15,6 @@ import type {
CreateWorkflowRunData,
} from '../engine/deps.js';
// ---------------------------------------------------------------------------
// Optional dependency loading
// ---------------------------------------------------------------------------
async function loadPostgres(): Promise<typeof import('postgres')> {
try {
return await import('postgres');
@@ -29,10 +25,6 @@ async function loadPostgres(): Promise<typeof import('postgres')> {
}
}
// ---------------------------------------------------------------------------
// Schema
// ---------------------------------------------------------------------------
const SCHEMA_SQL = `
CREATE TABLE IF NOT EXISTS workflow_runs (
id TEXT PRIMARY KEY,
@@ -63,10 +55,6 @@ const SCHEMA_SQL = `
ON workflow_events(run_id);
`;
// ---------------------------------------------------------------------------
// Row mappers
// ---------------------------------------------------------------------------
interface RunRow {
id: string;
workflow_path: string;
@@ -117,10 +105,6 @@ function rowToEvent(row: EventRow): WorkflowEvent {
};
}
// ---------------------------------------------------------------------------
// Factory
// ---------------------------------------------------------------------------
export async function createPostgresStore(
connectionString: string,
): Promise<IWorkflowStore> {
@@ -130,7 +114,6 @@ export async function createPostgresStore(
? mod.default(connectionString)
: (mod as any)(connectionString);
// Initialize schema
await sql.unsafe(SCHEMA_SQL);
const ACTIVE_STATUSES: WorkflowRunStatus[] = ['pending', 'running'];

View File

@@ -15,10 +15,6 @@ import type {
CreateWorkflowRunData,
} from '../engine/deps.js';
// ---------------------------------------------------------------------------
// Optional dependency loading
// ---------------------------------------------------------------------------
async function loadBetterSqlite3(): Promise<typeof import('better-sqlite3')> {
try {
return await import('better-sqlite3');
@@ -29,10 +25,6 @@ async function loadBetterSqlite3(): Promise<typeof import('better-sqlite3')> {
}
}
// ---------------------------------------------------------------------------
// Schema
// ---------------------------------------------------------------------------
const SCHEMA_SQL = `
CREATE TABLE IF NOT EXISTS workflow_runs (
id TEXT PRIMARY KEY,
@@ -64,10 +56,6 @@ const SCHEMA_SQL = `
ON workflow_events(run_id);
`;
// ---------------------------------------------------------------------------
// Row mappers
// ---------------------------------------------------------------------------
interface RunRow {
id: string;
workflow_path: string;
@@ -105,20 +93,6 @@ function rowToRun(row: RunRow): WorkflowRun {
};
}
function rowToEvent(row: EventRow): WorkflowEvent {
return {
id: row.id,
runId: row.run_id,
nodeId: row.node_id ?? undefined,
type: row.type,
data: JSON.parse(row.data),
createdAt: new Date(row.created_at),
};
}
// ---------------------------------------------------------------------------
// Factory
// ---------------------------------------------------------------------------
export async function createSqliteStore(
dbPath: string,
@@ -131,7 +105,6 @@ export async function createSqliteStore(
// Enable WAL mode for better concurrent read performance
db.pragma('journal_mode = WAL');
// Initialize schema
db.exec(SCHEMA_SQL);
const ACTIVE_STATUSES: WorkflowRunStatus[] = ['pending', 'running'];