hub-bulk-metadata.mjs
56 lines 2.2 KB
Raw
sha256:87f84653ce4706be8c65b0c4494ed6fb891213cca82db2b1824772cddc41a752 feat(auth): durable MCP OAuth refresh via shared strong sto… Agent minor 57 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 5 commits
sha256:87f84653ce4706be8c65b0c4494ed6fb891213cca82db2b1824772cddc41a752 feat(auth): durable MCP OAuth refresh via shared strong sto… Agent minor 57 days ago
sha256:873e30b7fafe601346295f8f4289f388f21d8f715f28584d5481899ba2b714fc Merge pull request #249 from aaronrene/muse-mirror Agent 74 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b fix(7C-L1b): route hosted delegation proposals through cani… Human minor 77 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91 fix: repair endpoint now sets has_active_subscription when … Human minor 97 days ago