MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / readWantedStatusAt

Function readWantedStatusAt

packages/wl-sdk/src/ops/state.ts:23–54  ·  view source on GitHub ↗
(opts: {
  auth: DoltHubAuth;
  /** The repo to read from — fork for branch reads, upstream for main. */
  owner: string;
  db: string;
  ref?: string;
  wantedId: string;
  fetch?: typeof fetch;
  hooks?: DoltFetchHooks;
})

Source from the content-addressed store, hash-verified

21
22/** Read just the `status` field for a wanted row at a ref. */
23export async function readWantedStatusAt(opts: {
24 auth: DoltHubAuth;
25 /** The repo to read from — fork for branch reads, upstream for main. */
26 owner: string;
27 db: string;
28 ref?: string;
29 wantedId: string;
30 fetch?: typeof fetch;
31 hooks?: DoltFetchHooks;
32}): Promise<string | null> {
33 const sql = `SELECT status FROM wanted WHERE id = '${escapeSqlString(opts.wantedId)}' LIMIT 1`;
34 try {
35 const res = await doltRead({
36 auth: opts.auth,
37 owner: opts.owner,
38 db: opts.db,
39 ref: opts.ref,
40 query: sql,
41 fetch: opts.fetch,
42 hooks: opts.hooks,
43 });
44 if (res.rows.length === 0) return null;
45 const parsed = StatusRow.safeParse(res.rows[0]);
46 if (!parsed.success) return null;
47 return parsed.data.status ?? null;
48 } catch (err) {
49 // Treat 404s on a not-yet-created branch as "no row": the branch
50 // simply doesn't exist on the fork yet. Other errors propagate.
51 if (err instanceof WlDoltHubError && err.status === 404) return null;
52 throw new WlError(`Read wanted status at ${opts.ref ?? 'main'} failed`, 'upstream', err);
53 }
54}
55
56/** Read the full wanted row at a ref. Returns `null` when the row isn't present. */
57export async function readWantedRowAt(opts: {

Callers 1

applyMutationFunction · 0.90

Calls 2

escapeSqlStringFunction · 0.90
doltReadFunction · 0.90

Tested by

no test coverage detected