@abhishekmcp/notes 0.1.0 → 0.2.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/dist/parse.js ADDED
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Pure, dependency-free markdown parsing: a tiny YAML-frontmatter reader plus
3
+ * extractors for headings, sections, wiki-links, tags and todos. We deliberately
4
+ * avoid gray-matter / js-yaml (npm-audit noise + native-free goal); the subset of
5
+ * YAML notes actually use in frontmatter is small enough to hand-roll safely.
6
+ */
7
+ const WIKI_LINK = /\[\[([^\]]+)\]\]/g;
8
+ /** Inline #hashtag: a '#' not followed by whitespace (so markdown headings "# x" don't match). */
9
+ const HASHTAG = /(?:^|\s)#([A-Za-z0-9][\w/-]*)/g;
10
+ /** Strip a trailing ".md" and normalize separators so links/names compare equal. */
11
+ export function normalizeLinkTarget(raw) {
12
+ return raw.trim().replace(/\.md$/i, "").replace(/\\/g, "/").replace(/^\.?\/+/, "");
13
+ }
14
+ /** Strip surrounding single/double quotes from a scalar value. */
15
+ function unquote(v) {
16
+ const t = v.trim();
17
+ if (t.length >= 2 && ((t[0] === '"' && t.endsWith('"')) || (t[0] === "'" && t.endsWith("'")))) {
18
+ return t.slice(1, -1);
19
+ }
20
+ return t;
21
+ }
22
+ /** Parse `[a, b, "c"]` or `a, b, c` into a string list. */
23
+ function parseInlineList(v) {
24
+ let s = v.trim();
25
+ if (s.startsWith("[") && s.endsWith("]"))
26
+ s = s.slice(1, -1);
27
+ return s
28
+ .split(",")
29
+ .map((x) => unquote(x))
30
+ .filter((x) => x.length > 0);
31
+ }
32
+ /**
33
+ * Split raw note text into a frontmatter object and the remaining body.
34
+ * Recognizes a leading `---` ... `---` fence. Unparseable frontmatter is
35
+ * treated as body (never throws).
36
+ */
37
+ export function splitFrontmatter(raw) {
38
+ // Must start with --- on the very first line.
39
+ const m = /^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/.exec(raw);
40
+ if (!m || raw.slice(0, 3) !== "---") {
41
+ return { frontmatter: {}, body: raw };
42
+ }
43
+ const block = m[1];
44
+ const body = raw.slice(m[0].length);
45
+ const fm = {};
46
+ const lines = block.split(/\r?\n/);
47
+ for (let i = 0; i < lines.length; i++) {
48
+ const line = lines[i];
49
+ if (line.trim() === "" || line.trimStart().startsWith("#"))
50
+ continue;
51
+ const kv = /^([A-Za-z0-9_-]+):[ \t]*(.*)$/.exec(line);
52
+ if (!kv)
53
+ continue;
54
+ const key = kv[1];
55
+ const rest = kv[2];
56
+ if (rest.trim() === "") {
57
+ // Possible block list: subsequent "- item" lines.
58
+ const items = [];
59
+ let j = i + 1;
60
+ for (; j < lines.length; j++) {
61
+ const item = /^[ \t]+-[ \t]+(.*)$/.exec(lines[j]);
62
+ if (!item)
63
+ break;
64
+ items.push(unquote(item[1]));
65
+ }
66
+ if (items.length > 0) {
67
+ fm[key] = key === "tags" ? items : items;
68
+ i = j - 1;
69
+ }
70
+ else {
71
+ fm[key] = "";
72
+ }
73
+ continue;
74
+ }
75
+ if (key === "tags") {
76
+ fm.tags = parseInlineList(rest);
77
+ }
78
+ else if (rest.trim().startsWith("[")) {
79
+ fm[key] = parseInlineList(rest);
80
+ }
81
+ else {
82
+ fm[key] = unquote(rest);
83
+ }
84
+ }
85
+ return { frontmatter: fm, body };
86
+ }
87
+ /** Extract ATX headings (`#`..`######`) from body text, ignoring fenced code blocks. */
88
+ export function extractHeadings(body) {
89
+ const out = [];
90
+ const lines = body.split(/\r?\n/);
91
+ let inFence = false;
92
+ let fence = "";
93
+ for (let i = 0; i < lines.length; i++) {
94
+ const line = lines[i];
95
+ const fenceMatch = /^[ \t]*(```+|~~~+)/.exec(line);
96
+ if (fenceMatch) {
97
+ if (!inFence) {
98
+ inFence = true;
99
+ fence = fenceMatch[1][0];
100
+ }
101
+ else if (line.trimStart().startsWith(fence)) {
102
+ inFence = false;
103
+ }
104
+ continue;
105
+ }
106
+ if (inFence)
107
+ continue;
108
+ const h = /^(#{1,6})[ \t]+(.+?)[ \t]*#*$/.exec(line);
109
+ if (h)
110
+ out.push({ level: h[1].length, text: h[2].trim(), line: i + 1 });
111
+ }
112
+ return out;
113
+ }
114
+ /**
115
+ * Return the text under a heading (case-insensitive match on heading text),
116
+ * up to the next heading of the same or higher level. Returns null if not found.
117
+ */
118
+ export function extractSection(body, heading) {
119
+ const lines = body.split(/\r?\n/);
120
+ const want = heading.trim().toLowerCase();
121
+ const headings = extractHeadings(body);
122
+ const start = headings.find((h) => h.text.toLowerCase() === want);
123
+ if (!start)
124
+ return null;
125
+ const startIdx = start.line - 1;
126
+ let endIdx = lines.length;
127
+ for (const h of headings) {
128
+ if (h.line - 1 > startIdx && h.level <= start.level) {
129
+ endIdx = h.line - 1;
130
+ break;
131
+ }
132
+ }
133
+ // Include the heading line itself for context.
134
+ return lines.slice(startIdx, endIdx).join("\n").trimEnd();
135
+ }
136
+ /** Extract wiki-link targets (`[[name]]` / `[[name|alias]]`), normalized + deduped. */
137
+ export function extractWikiLinks(body) {
138
+ const seen = new Set();
139
+ const out = [];
140
+ let m;
141
+ WIKI_LINK.lastIndex = 0;
142
+ while ((m = WIKI_LINK.exec(body)) !== null) {
143
+ const target = normalizeLinkTarget(m[1].split("|")[0]);
144
+ if (target && !seen.has(target)) {
145
+ seen.add(target);
146
+ out.push(target);
147
+ }
148
+ }
149
+ return out;
150
+ }
151
+ /** Collect tags from frontmatter plus inline #hashtags in the body, deduped. */
152
+ export function extractTags(frontmatter, body) {
153
+ const seen = new Set();
154
+ const out = [];
155
+ const add = (t) => {
156
+ const tag = t.trim().replace(/^#/, "");
157
+ const key = tag.toLowerCase();
158
+ if (tag && !seen.has(key)) {
159
+ seen.add(key);
160
+ out.push(tag);
161
+ }
162
+ };
163
+ if (Array.isArray(frontmatter.tags))
164
+ for (const t of frontmatter.tags)
165
+ add(String(t));
166
+ // Strip fenced code so code samples don't pollute tags.
167
+ const withoutFences = body.replace(/(```+|~~~+)[\s\S]*?\1/g, "");
168
+ let m;
169
+ HASHTAG.lastIndex = 0;
170
+ while ((m = HASHTAG.exec(withoutFences)) !== null)
171
+ add(m[1]);
172
+ return out;
173
+ }
174
+ /** Extract checkbox todos (`- [ ]` / `- [x]`) from body text. */
175
+ export function extractTodos(body) {
176
+ const out = [];
177
+ const lines = body.split(/\r?\n/);
178
+ for (let i = 0; i < lines.length; i++) {
179
+ const m = /^[ \t]*[-*+][ \t]+\[([ xX])\][ \t]+(.*)$/.exec(lines[i]);
180
+ if (m)
181
+ out.push({ done: m[1].toLowerCase() === "x", text: m[2].trim(), line: i + 1 });
182
+ }
183
+ return out;
184
+ }
185
+ /** Full parse of a raw note into structured pieces used by the index and graph. */
186
+ export function parseNote(raw) {
187
+ const { frontmatter, body } = splitFrontmatter(raw);
188
+ const headings = extractHeadings(body);
189
+ const tags = extractTags(frontmatter, body);
190
+ const links = extractWikiLinks(body);
191
+ let title;
192
+ if (typeof frontmatter.title === "string" && frontmatter.title.trim()) {
193
+ title = frontmatter.title.trim();
194
+ }
195
+ else {
196
+ const h1 = headings.find((h) => h.level === 1);
197
+ if (h1)
198
+ title = h1.text;
199
+ }
200
+ return { frontmatter, body, title, tags, links, headings };
201
+ }
202
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6BH,MAAM,SAAS,GAAG,mBAAmB,CAAC;AACtC,kGAAkG;AAClG,MAAM,OAAO,GAAG,gCAAgC,CAAC;AAEjD,oFAAoF;AACpF,MAAM,UAAU,mBAAmB,CAAC,GAAW;IAC7C,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;AACrF,CAAC;AAED,kEAAkE;AAClE,SAAS,OAAO,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,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACvC,MAAM,IAAI,GAAG,WAAW,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,KAAyB,CAAC;IAC9B,IAAI,OAAO,WAAW,CAAC,KAAK,KAAK,QAAQ,IAAI,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QACtE,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;SAAM,CAAC;QACN,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC;QAC/C,IAAI,EAAE;YAAE,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC;IAC1B,CAAC;IACD,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,102 @@
1
+ import { validateName } from "./fsutil.js";
2
+ /** Per-note metadata kept in memory and persisted to the cache. */
3
+ export interface NoteMeta {
4
+ mtimeMs: number;
5
+ size: number;
6
+ title: string;
7
+ tags: string[];
8
+ outLinks: string[];
9
+ }
10
+ /**
11
+ * Load the index. Tries the cache and incrementally syncs against disk
12
+ * (re-parsing only new/changed files, dropping deleted ones). Falls back to a
13
+ * full rebuild if the cache is missing, unreadable, or the version changed.
14
+ * Call once on startup before serving requests.
15
+ */
16
+ export declare function buildIndex(): Promise<void>;
17
+ export declare function getAllMeta(): Map<string, NoteMeta>;
18
+ export declare function getMeta(name: string): NoteMeta | undefined;
19
+ export declare function noteExists(name: string): boolean;
20
+ export interface NoteSummary {
21
+ name: string;
22
+ title: string;
23
+ size: number;
24
+ mtimeMs: number;
25
+ tags: string[];
26
+ }
27
+ export interface ListResult {
28
+ items: NoteSummary[];
29
+ total: number;
30
+ hasMore: boolean;
31
+ }
32
+ /** List notes (newest first), optionally filtered by tag, with pagination. */
33
+ export declare function listNotes(offset?: number, limit?: number, tag?: string): ListResult;
34
+ export interface ReadResult {
35
+ text: string;
36
+ truncated: boolean;
37
+ }
38
+ /**
39
+ * Read a note's content. With `section`, returns just that heading's block.
40
+ * With `offset`/`limit` (character window), returns a slice + a `truncated` flag.
41
+ */
42
+ export declare function readNote(name: string, opts?: {
43
+ section?: string;
44
+ offset?: number;
45
+ limit?: number;
46
+ }): Promise<ReadResult>;
47
+ /** Heading-tree outline of a note (cheap way to grasp a big note). */
48
+ export declare function getOutline(name: string): Promise<string>;
49
+ export declare function createNote(name: string, content: string, overwrite?: boolean): Promise<string>;
50
+ export declare function appendNote(name: string, content: string): Promise<string>;
51
+ export declare function deleteNote(name: string): Promise<void>;
52
+ export interface MoveResult {
53
+ from: string;
54
+ to: string;
55
+ rewritten: string[];
56
+ }
57
+ /**
58
+ * Move/rename a note and rewrite every `[[from]]` wiki-link across the vault to
59
+ * `[[to]]`. Keeps the index, graph and cache consistent.
60
+ */
61
+ export declare function moveNote(from: string, to: string): Promise<MoveResult>;
62
+ export interface SearchHit {
63
+ name: string;
64
+ title: string;
65
+ score: number;
66
+ snippet: string;
67
+ }
68
+ export interface SearchResultPage {
69
+ hits: SearchHit[];
70
+ total: number;
71
+ hasMore: boolean;
72
+ }
73
+ /**
74
+ * Ranked full-text search. Supports `fuzzy`, `prefix`, a `field` filter
75
+ * (title/tag/body, or `path` to match the note name), and pagination. Returns
76
+ * ranked snippets with surrounding context.
77
+ */
78
+ export declare function searchNotes(query: string, opts?: {
79
+ fuzzy?: boolean;
80
+ prefix?: boolean;
81
+ field?: string;
82
+ offset?: number;
83
+ limit?: number;
84
+ }): Promise<SearchResultPage>;
85
+ export interface TagCount {
86
+ tag: string;
87
+ count: number;
88
+ }
89
+ /** All tags across the vault with note counts (case-insensitive grouping). */
90
+ export declare function listTags(): TagCount[];
91
+ export interface TodoItem {
92
+ note: string;
93
+ text: string;
94
+ done: boolean;
95
+ line: number;
96
+ }
97
+ /** Aggregate `- [ ]` / `- [x]` checkboxes across all notes. */
98
+ export declare function listTodos(includeDone?: boolean): Promise<TodoItem[]>;
99
+ /** Notes-dir banner for startup logging. */
100
+ export declare function notesDir(): string;
101
+ /** Exposed for tests: validate a name without touching disk. */
102
+ export { validateName };