Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@brandontroberts/sync-fork

Automatically sync forked Kody community packages with upstream in Kody Cloud using Graft's repo-mode fork mechanism.

FollowFork

Files

emit-sync-completed.ts

22 lines · 1.0 KB · TypeScript
import { events, packageStorage } from 'kody:runtime';
import { buildCompletionEvent } from './completion-event.ts';
import { getSyncRun } from './storage.ts';

/**
 * Cloud-side completion event emitter scheduled via `workflows.create` when `onUpstreamUpdated`
 * runs on an Execution Context (where Kody disables `events.dispatch`). Reads the persisted
 * `SyncRunRecord` from `packageStorage()` and dispatches `@brandontroberts/sync-fork.completed`.
 */
export default async function emitSyncCompleted(params?: Record<string, unknown>): Promise<{ runId: string; topic: string }> {
  const runId = typeof params?.runId === 'string' ? params.runId.trim() : '';
  if (!runId) {
    throw new Error('emitSyncCompleted requires a non-empty string runId');
  }
  const record = await getSyncRun(packageStorage(), runId);
  if (!record) {
    throw new Error(`Sync run "${runId}" not found in packageStorage`);
  }
  const event = buildCompletionEvent(record);
  await events.dispatch(event);
  return { runId: record.id, topic: event.topic };
}