Commits merged: - feat(FN-3743): add polling task notifications for even realities plugin Files changed: .../fusion-plugin-even-realities-glasses/README.md | 27 +++ .../package.json | 2 + .../src/__tests__/cards.test.ts | 82 +++------ .../src/__tests__/diff.test.ts | 76 ++++++++ .../src/__tests__/notification-card.test.ts | 40 +++++ .../src/__tests__/notification-routes.test.ts | 78 ++++++++ .../src/__tests__/notification-store.test.ts | 71 ++++++++ .../src/__tests__/notifier.test.ts | 138 +++++++++----- .../src/__tests__/transport.test.ts | 4 +- .../src/agent-actions.ts | 4 +- .../src/cards.ts | 127 ++++++++++--- .../src/index.ts | 22 ++- .../src/notifications/diff.ts | 77 ++++++++ .../src/notifications/store.ts | 46 +++++ .../src/notifications/types.ts | 19 ++ .../src/notifier.ts | 199 +++++++++++++-------- .../src/routes/notification-routes.ts | 103 +++++++++++ pnpm-lock.yaml | 31 +++- 18 files changed, 929 insertions(+), 217 deletions(-) Fusion-Task-Id: FN-3743
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import type { Column } from "@fusion/core";
|
|
import type { PluginDb } from "../index.js";
|
|
import type { SnapshotRow } from "./types.js";
|
|
|
|
export function readSnapshot(db: PluginDb): Map<string, SnapshotRow> {
|
|
const rows = db.prepare("SELECT taskId, lastColumn, updatedAt FROM even_realities_seen_tasks").all() as Array<{
|
|
taskId: string;
|
|
lastColumn: Column;
|
|
updatedAt: string;
|
|
}>;
|
|
const out = new Map<string, SnapshotRow>();
|
|
for (const row of rows) {
|
|
out.set(row.taskId, { taskId: row.taskId, lastColumn: row.lastColumn, updatedAt: row.updatedAt });
|
|
}
|
|
return out;
|
|
}
|
|
|
|
export function writeSnapshot(db: PluginDb, rows: ReadonlyArray<SnapshotRow>): void {
|
|
db.exec("BEGIN");
|
|
try {
|
|
const stmt = db.prepare(
|
|
"INSERT OR REPLACE INTO even_realities_seen_tasks(taskId, lastColumn, updatedAt) VALUES (?, ?, ?)",
|
|
);
|
|
for (const row of rows) {
|
|
stmt.run(row.taskId, row.lastColumn, row.updatedAt);
|
|
}
|
|
db.exec("COMMIT");
|
|
} catch (error) {
|
|
db.exec("ROLLBACK");
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
export function pruneMissing(db: PluginDb, presentTaskIds: ReadonlySet<string>): number {
|
|
if (presentTaskIds.size === 0) {
|
|
const result = db.prepare("DELETE FROM even_realities_seen_tasks").run() as { changes?: number };
|
|
return result.changes ?? 0;
|
|
}
|
|
|
|
const ids = [...presentTaskIds];
|
|
const placeholders = ids.map(() => "?").join(",");
|
|
const result = db
|
|
.prepare(`DELETE FROM even_realities_seen_tasks WHERE taskId NOT IN (${placeholders})`)
|
|
.run(...ids) as { changes?: number };
|
|
return result.changes ?? 0;
|
|
}
|