hub-bulk-metadata.mjs
56 lines 2.2 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 11 days ago
1 /**
2 * Hub bulk operations by metadata (project slug). Self-hosted Node Hub only; see docs/HUB-METADATA-BULK-OPS.md.
3 */
4
5 import { runListNotes } from './list-notes.mjs';
6 import { deleteNote, writeNote } from './write.mjs';
7 import { readNote, normalizeSlug } from './vault.mjs';
8
9 /**
10 * @param {string} vaultPath
11 * @param {string} projectRaw
12 * @param {{ ignore?: string[] }} [options]
13 * @returns {{ deleted: number, paths: string[] }}
14 */
15 export function deleteNotesByProjectSlug(vaultPath, projectRaw, options = {}) {
16 const slug = normalizeSlug(String(projectRaw ?? '').trim());
17 if (!slug) throw new Error('project slug required');
18 const vc = { vault_path: vaultPath, ignore: options.ignore || [] };
19 const out = runListNotes(vc, { project: slug, limit: 100000, offset: 0, fields: 'path' });
20 const paths = (out.notes || []).map((n) => n.path).filter(Boolean);
21 const deletedPaths = [];
22 for (const rel of paths) {
23 try {
24 deleteNote(vaultPath, rel);
25 deletedPaths.push(String(rel).replace(/\\/g, '/'));
26 } catch (e) {
27 if (e.message && e.message.includes('not found')) continue;
28 throw e;
29 }
30 }
31 return { deleted: deletedPaths.length, paths: deletedPaths };
32 }
33
34 /**
35 * @param {string} vaultPath
36 * @param {string} fromRaw
37 * @param {string} toRaw
38 * @param {{ ignore?: string[] }} [options]
39 * @returns {{ updated: number, paths: string[] }}
40 */
41 export function renameProjectSlugInVault(vaultPath, fromRaw, toRaw, options = {}) {
42 const from = normalizeSlug(String(fromRaw ?? '').trim());
43 const to = normalizeSlug(String(toRaw ?? '').trim());
44 if (!from || !to) throw new Error('from and to project slugs required');
45 if (from === to) return { updated: 0, paths: [] };
46 const vc = { vault_path: vaultPath, ignore: options.ignore || [] };
47 const out = runListNotes(vc, { project: from, limit: 100000, offset: 0, fields: 'path' });
48 const paths = (out.notes || []).map((n) => n.path).filter(Boolean);
49 const updatedPaths = [];
50 for (const rel of paths) {
51 const note = readNote(vaultPath, rel);
52 writeNote(vaultPath, rel, { body: note.body, frontmatter: { project: to } });
53 updatedPaths.push(String(rel).replace(/\\/g, '/'));
54 }
55 return { updated: updatedPaths.length, paths: updatedPaths };
56 }
File History 4 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 11 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b fix(7C-L1b): route hosted delegation proposals through cani… Human minor 30 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91 fix: repair endpoint now sets has_active_subscription when … Human minor 50 days ago