@withpica/mcp-server
Version:
MCP Server for withPICA — enables AI assistants to interact with your withPICA music catalog
67 lines • 3.17 kB
JavaScript
// Copyright (c) 2025-2026 Withpica Ltd. All rights reserved.
/**
* Bulk previews read each work's sheets individually, and every read counts
* against the caller's per-key API rate limit (lib/auth/api-key-auth.ts) —
* the same budget the delete itself needs. Past this many ids the preview
* states the rule instead of reading each work.
*/
export const SIGNED_SHEET_PREVIEW_MAX_IDS = 10;
/** Number of the work's split sheets with at least one signature. Throws on a failed read. */
export async function countSignedSplitSheets(pica, workId) {
const res = await pica.splitSheets.listForWork(workId);
const rows = Array.isArray(res)
? res
: Array.isArray(res?.data)
? res.data
: [];
return rows.filter((row) => Number(row?.signed_signature_count ??
0) > 0).length;
}
function sheets(n) {
return `${n} signed split ${n === 1 ? "sheet" : "sheets"}`;
}
/**
* The preview line for one work. `null` = the count could not be read; the
* line then states the rule rather than claiming there are none.
*/
export function signedSplitSheetLineForWork(count) {
if (count === null) {
return "could not check this work for signed split sheets — if it has any, it will be archived (kept, hidden from your catalogue) rather than deleted, so the signed sheets survive.";
}
if (count === 0)
return "";
return `this work carries ${sheets(count)} — it will be archived (kept, hidden from your catalogue), not deleted, so the signed ${count === 1 ? "sheet survives" : "sheets survive"}.`;
}
/**
* The preview line for a bulk delete. `checked` false = too many ids to read
* (or a read failed); the line then states the rule.
*/
export function signedSplitSheetLineForWorks(result) {
if (!result.checked) {
return "any of these works that carries a signed split sheet will be archived (kept, hidden from your catalogue) rather than deleted, so the signed sheets survive.";
}
if (result.sheets === 0)
return "";
const works = result.worksWithSigned === 1
? "1 of these works carries"
: `${result.worksWithSigned} of these works carry`;
return `${works} ${sheets(result.sheets)} — ${result.worksWithSigned === 1 ? "it" : "they"} will be archived (kept, hidden from your catalogue), not deleted, so the signed ${result.sheets === 1 ? "sheet survives" : "sheets survive"}.`;
}
/** Read signed-sheet counts for a bulk preview, bounded by {@link SIGNED_SHEET_PREVIEW_MAX_IDS}. */
export async function countSignedSplitSheetsForWorks(pica, ids) {
if (ids.length === 0 || ids.length > SIGNED_SHEET_PREVIEW_MAX_IDS) {
return { checked: ids.length === 0, worksWithSigned: 0, sheets: 0 };
}
try {
const counts = await Promise.all(ids.map((id) => countSignedSplitSheets(pica, id)));
return {
checked: true,
worksWithSigned: counts.filter((c) => c > 0).length,
sheets: counts.reduce((a, b) => a + b, 0),
};
}
catch {
return { checked: false, worksWithSigned: 0, sheets: 0 };
}
}
//# sourceMappingURL=signed-split-sheet-preview.js.map