@abhishekmcp/notes 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -40
- package/dist/config.d.ts +41 -0
- package/dist/config.js +67 -0
- package/dist/config.js.map +1 -0
- package/dist/embed.d.ts +9 -0
- package/dist/embed.js +134 -0
- package/dist/embed.js.map +1 -0
- package/dist/fsutil.d.ts +23 -0
- package/dist/fsutil.js +113 -0
- package/dist/fsutil.js.map +1 -0
- package/dist/graph.d.ts +38 -0
- package/dist/graph.js +160 -0
- package/dist/graph.js.map +1 -0
- package/dist/index.js +240 -100
- package/dist/index.js.map +1 -1
- package/dist/parse.d.ts +55 -0
- package/dist/parse.js +202 -0
- package/dist/parse.js.map +1 -0
- package/dist/semantic.d.ts +14 -0
- package/dist/semantic.js +142 -0
- package/dist/semantic.js.map +1 -0
- package/dist/store.d.ts +102 -0
- package/dist/store.js +410 -0
- package/dist/store.js.map +1 -0
- package/dist/tokenizer.d.ts +30 -0
- package/dist/tokenizer.js +140 -0
- package/dist/tokenizer.js.map +1 -0
- package/package.json +4 -2
- package/dist/notes.d.ts +0 -36
- package/dist/notes.js +0 -138
- package/dist/notes.js.map +0 -1
package/dist/notes.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolve the notes directory from the NOTES_DIR env var, defaulting to ~/notes.
|
|
3
|
-
* A leading "~" is expanded to the user's home directory.
|
|
4
|
-
*/
|
|
5
|
-
export declare function getNotesDir(): string;
|
|
6
|
-
/** Ensure the notes directory exists. */
|
|
7
|
-
export declare function ensureNotesDir(): Promise<string>;
|
|
8
|
-
/**
|
|
9
|
-
* Turn a user-supplied note name into a safe absolute path inside the notes
|
|
10
|
-
* directory. Throws if the resolved path would escape the notes directory.
|
|
11
|
-
* A ".md" extension is added when missing.
|
|
12
|
-
*/
|
|
13
|
-
export declare function resolveNotePath(name: string): string;
|
|
14
|
-
export interface NoteInfo {
|
|
15
|
-
name: string;
|
|
16
|
-
size: number;
|
|
17
|
-
modified: string;
|
|
18
|
-
}
|
|
19
|
-
/** Recursively list all markdown notes in the notes directory. */
|
|
20
|
-
export declare function listNotes(): Promise<NoteInfo[]>;
|
|
21
|
-
export declare function readNote(name: string): Promise<string>;
|
|
22
|
-
export declare function createNote(name: string, content: string, overwrite?: boolean): Promise<string>;
|
|
23
|
-
export declare function appendNote(name: string, content: string): Promise<string>;
|
|
24
|
-
export declare function deleteNote(name: string): Promise<void>;
|
|
25
|
-
export interface SearchHit {
|
|
26
|
-
name: string;
|
|
27
|
-
line: number;
|
|
28
|
-
text: string;
|
|
29
|
-
}
|
|
30
|
-
/** Case-insensitive substring search across all notes. */
|
|
31
|
-
export declare function searchNotes(query: string, limit?: number): Promise<SearchHit[]>;
|
|
32
|
-
/**
|
|
33
|
-
* Find notes that link to the given note via [[wiki-link]] syntax.
|
|
34
|
-
* Matches the bare note name (with or without the .md extension).
|
|
35
|
-
*/
|
|
36
|
-
export declare function getBacklinks(name: string): Promise<SearchHit[]>;
|
package/dist/notes.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
/**
|
|
5
|
-
* Resolve the notes directory from the NOTES_DIR env var, defaulting to ~/notes.
|
|
6
|
-
* A leading "~" is expanded to the user's home directory.
|
|
7
|
-
*/
|
|
8
|
-
export function getNotesDir() {
|
|
9
|
-
const raw = process.env.NOTES_DIR ?? path.join(homedir(), "notes");
|
|
10
|
-
const expanded = raw.startsWith("~")
|
|
11
|
-
? path.join(homedir(), raw.slice(1))
|
|
12
|
-
: raw;
|
|
13
|
-
return path.resolve(expanded);
|
|
14
|
-
}
|
|
15
|
-
/** Ensure the notes directory exists. */
|
|
16
|
-
export async function ensureNotesDir() {
|
|
17
|
-
const dir = getNotesDir();
|
|
18
|
-
await fs.mkdir(dir, { recursive: true });
|
|
19
|
-
return dir;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Turn a user-supplied note name into a safe absolute path inside the notes
|
|
23
|
-
* directory. Throws if the resolved path would escape the notes directory.
|
|
24
|
-
* A ".md" extension is added when missing.
|
|
25
|
-
*/
|
|
26
|
-
export function resolveNotePath(name) {
|
|
27
|
-
const dir = getNotesDir();
|
|
28
|
-
const withExt = name.endsWith(".md") ? name : `${name}.md`;
|
|
29
|
-
const resolved = path.resolve(dir, withExt);
|
|
30
|
-
const rel = path.relative(dir, resolved);
|
|
31
|
-
if (rel.startsWith("..") || path.isAbsolute(rel)) {
|
|
32
|
-
throw new Error(`Refusing to access "${name}": path escapes the notes directory.`);
|
|
33
|
-
}
|
|
34
|
-
return resolved;
|
|
35
|
-
}
|
|
36
|
-
/** Recursively list all markdown notes in the notes directory. */
|
|
37
|
-
export async function listNotes() {
|
|
38
|
-
const dir = await ensureNotesDir();
|
|
39
|
-
const results = [];
|
|
40
|
-
async function walk(current) {
|
|
41
|
-
const entries = await fs.readdir(current, { withFileTypes: true });
|
|
42
|
-
for (const entry of entries) {
|
|
43
|
-
const full = path.join(current, entry.name);
|
|
44
|
-
if (entry.isDirectory()) {
|
|
45
|
-
await walk(full);
|
|
46
|
-
}
|
|
47
|
-
else if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
48
|
-
const stat = await fs.stat(full);
|
|
49
|
-
const rel = path.relative(dir, full).replace(/\.md$/, "");
|
|
50
|
-
results.push({
|
|
51
|
-
name: rel,
|
|
52
|
-
size: stat.size,
|
|
53
|
-
modified: stat.mtime.toISOString(),
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
await walk(dir);
|
|
59
|
-
results.sort((a, b) => b.modified.localeCompare(a.modified));
|
|
60
|
-
return results;
|
|
61
|
-
}
|
|
62
|
-
export async function readNote(name) {
|
|
63
|
-
const file = resolveNotePath(name);
|
|
64
|
-
return fs.readFile(file, "utf8");
|
|
65
|
-
}
|
|
66
|
-
export async function createNote(name, content, overwrite = false) {
|
|
67
|
-
const file = resolveNotePath(name);
|
|
68
|
-
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
69
|
-
if (!overwrite) {
|
|
70
|
-
try {
|
|
71
|
-
await fs.access(file);
|
|
72
|
-
throw new Error(`Note "${name}" already exists. Use overwrite or append instead.`);
|
|
73
|
-
}
|
|
74
|
-
catch (err) {
|
|
75
|
-
// ENOENT means it does not exist yet — that's what we want.
|
|
76
|
-
if (err.code !== "ENOENT")
|
|
77
|
-
throw err;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
await fs.writeFile(file, content, "utf8");
|
|
81
|
-
return file;
|
|
82
|
-
}
|
|
83
|
-
export async function appendNote(name, content) {
|
|
84
|
-
const file = resolveNotePath(name);
|
|
85
|
-
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
86
|
-
// Separate appended content with a blank line for readability.
|
|
87
|
-
const prefix = content.startsWith("\n") ? "" : "\n\n";
|
|
88
|
-
await fs.appendFile(file, prefix + content, "utf8");
|
|
89
|
-
return file;
|
|
90
|
-
}
|
|
91
|
-
export async function deleteNote(name) {
|
|
92
|
-
const file = resolveNotePath(name);
|
|
93
|
-
await fs.unlink(file);
|
|
94
|
-
}
|
|
95
|
-
/** Case-insensitive substring search across all notes. */
|
|
96
|
-
export async function searchNotes(query, limit = 50) {
|
|
97
|
-
const notes = await listNotes();
|
|
98
|
-
const needle = query.toLowerCase();
|
|
99
|
-
const hits = [];
|
|
100
|
-
for (const note of notes) {
|
|
101
|
-
const content = await readNote(note.name);
|
|
102
|
-
const lines = content.split("\n");
|
|
103
|
-
for (let i = 0; i < lines.length; i++) {
|
|
104
|
-
if (lines[i].toLowerCase().includes(needle)) {
|
|
105
|
-
hits.push({ name: note.name, line: i + 1, text: lines[i].trim() });
|
|
106
|
-
if (hits.length >= limit)
|
|
107
|
-
return hits;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return hits;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Find notes that link to the given note via [[wiki-link]] syntax.
|
|
115
|
-
* Matches the bare note name (with or without the .md extension).
|
|
116
|
-
*/
|
|
117
|
-
export async function getBacklinks(name) {
|
|
118
|
-
const target = name.replace(/\.md$/, "");
|
|
119
|
-
const notes = await listNotes();
|
|
120
|
-
const hits = [];
|
|
121
|
-
for (const note of notes) {
|
|
122
|
-
if (note.name === target)
|
|
123
|
-
continue;
|
|
124
|
-
const content = await readNote(note.name);
|
|
125
|
-
const lines = content.split("\n");
|
|
126
|
-
for (let i = 0; i < lines.length; i++) {
|
|
127
|
-
const wikiLinks = lines[i].match(/\[\[([^\]]+)\]\]/g) ?? [];
|
|
128
|
-
for (const link of wikiLinks) {
|
|
129
|
-
const inner = link.slice(2, -2).split("|")[0].trim().replace(/\.md$/, "");
|
|
130
|
-
if (inner === target) {
|
|
131
|
-
hits.push({ name: note.name, line: i + 1, text: lines[i].trim() });
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return hits;
|
|
137
|
-
}
|
|
138
|
-
//# sourceMappingURL=notes.js.map
|
package/dist/notes.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"notes.js","sourceRoot":"","sources":["../src/notes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;GAGG;AACH,MAAM,UAAU,WAAW;IACzB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;IACnE,MAAM,QAAQ,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,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