@jibone/todotxt-core 0.3.0 → 0.4.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 +41 -5
- package/dist/index.d.ts +66 -12
- package/dist/index.js +53 -46
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,7 +55,8 @@ const todos = createTodoTxt({
|
|
|
55
55
|
|
|
56
56
|
`write` is optional until the write APIs are implemented, so read-only clients
|
|
57
57
|
can omit it. `logger` is optional too and silent when omitted; see
|
|
58
|
-
[Logging](#logging).
|
|
58
|
+
[Logging](#logging). `includeSource` is optional as well; see
|
|
59
|
+
[Source metadata](#source-metadata). The runnable Node version is
|
|
59
60
|
[`examples/node/todo-all.ts`](https://github.com/jibone/todotxt-core/blob/master/examples/node/todo-all.ts).
|
|
60
61
|
|
|
61
62
|
`all()` returns a `TodoRecord` for each non-empty line:
|
|
@@ -70,6 +71,8 @@ can omit it. `logger` is optional too and silent when omitted; see
|
|
|
70
71
|
| `projects` | Projects without the `+` prefix |
|
|
71
72
|
| `contexts` | Contexts without the `@` prefix |
|
|
72
73
|
| `data` | `key:value` metadata (`{ due: "2011-03-05" }`) |
|
|
74
|
+
| `line` | 1-based physical line number, when `includeSource` is on |
|
|
75
|
+
| `raw` | Exact original line, when `includeSource` is on |
|
|
73
76
|
|
|
74
77
|
If a `key:value` key appears more than once, the last value wins. With a
|
|
75
78
|
[logger](#logging) configured, the parser also emits a `warn` for each duplicate
|
|
@@ -79,6 +82,35 @@ See [How todotxt-core parses todo.txt](https://github.com/jibone/todotxt-core/bl
|
|
|
79
82
|
for the complete rule-by-rule interpretation, including date validation and
|
|
80
83
|
deliberate leniencies.
|
|
81
84
|
|
|
85
|
+
### Source metadata
|
|
86
|
+
|
|
87
|
+
By default records stay JSON-lean and the original line is not retained. Pass
|
|
88
|
+
`includeSource` to opt into source metadata: every record then carries `line`,
|
|
89
|
+
the 1-based physical line number (blank lines count), and `raw`, the exact
|
|
90
|
+
original line without a trailing newline or `\r`.
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
const todos = createTodoTxt({
|
|
94
|
+
read: () => Bun.file("todo.txt").text(),
|
|
95
|
+
includeSource: true,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
for (const todo of await todos.pending()) {
|
|
99
|
+
console.log(todo.line, todo.raw);
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Source fields survive filters, plucks, and the cache-protecting copies that
|
|
104
|
+
queries return. The same option works for the standalone parser:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
parseDocument(contents, { includeSource: true });
|
|
108
|
+
parseLine("(A) Call Mom", { includeSource: true, line: 7 });
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`parseLine` only attaches `line` when you supply it via `ParseOptions.line`;
|
|
112
|
+
`parseDocument` numbers lines itself.
|
|
113
|
+
|
|
82
114
|
## Querying
|
|
83
115
|
|
|
84
116
|
Queries are lazy: chaining filters does no IO. The first query on a client reads
|
|
@@ -224,10 +256,13 @@ const record = parseLine("(A) Call Mom +Family @phone due:2011-03-05");
|
|
|
224
256
|
const records = parseDocument(contents);
|
|
225
257
|
```
|
|
226
258
|
|
|
227
|
-
`parseLine` returns a `TodoRecord` directly.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
`
|
|
259
|
+
`parseLine` returns a `TodoRecord` directly. Records keep no copy of the
|
|
260
|
+
original line unless [source metadata](#source-metadata) is enabled. Dates must
|
|
261
|
+
be real calendar dates in `YYYY-MM-DD` form; a shape-valid but nonexistent date
|
|
262
|
+
such as `2011-99-99` is treated as text and reported as an `invalid-date`
|
|
263
|
+
warning. Collect warnings by passing `onWarning` in a `ParseOptions` object;
|
|
264
|
+
passing the handler directly as the second argument is deprecated but still
|
|
265
|
+
supported. The full rule-by-rule interpretation is documented in
|
|
231
266
|
[How todotxt-core parses todo.txt](https://github.com/jibone/todotxt-core/blob/master/docs/todo-txt-rules.md).
|
|
232
267
|
|
|
233
268
|
Writing is not implemented yet. The `write` hook is optional for now and will
|
|
@@ -242,6 +277,7 @@ bun examples/todo-context.ts
|
|
|
242
277
|
bun examples/todo-cross.ts
|
|
243
278
|
bun examples/todo-logger.ts
|
|
244
279
|
bun examples/todo-try.ts
|
|
280
|
+
bun examples/todo-source.ts
|
|
245
281
|
```
|
|
246
282
|
|
|
247
283
|
Each format rule also has a runnable example:
|
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,20 @@ interface ParseWarning {
|
|
|
38
38
|
}
|
|
39
39
|
/** Receives parse warnings. */
|
|
40
40
|
type ParseWarningHandler = (warning: ParseWarning) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Options for {@link parseLine} and {@link parseDocument}.
|
|
43
|
+
*/
|
|
44
|
+
interface ParseOptions {
|
|
45
|
+
/** Include `line` and `raw` on returned records. Default: `false`. */
|
|
46
|
+
includeSource?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* 1-based line number attached to the record when {@link includeSource} is
|
|
49
|
+
* on. Ignored by {@link parseDocument}, which numbers physical lines itself.
|
|
50
|
+
*/
|
|
51
|
+
line?: number;
|
|
52
|
+
/** Receives parse warnings. */
|
|
53
|
+
onWarning?: ParseWarningHandler;
|
|
54
|
+
}
|
|
41
55
|
/**
|
|
42
56
|
* Callbacks supplied by the consumer.
|
|
43
57
|
*
|
|
@@ -56,12 +70,22 @@ interface TodoHooks {
|
|
|
56
70
|
}
|
|
57
71
|
/** @deprecated Use {@link TodoHooks}. */
|
|
58
72
|
type TodoFileHooks = TodoHooks;
|
|
73
|
+
/**
|
|
74
|
+
* Options for creating a todo.txt client with {@link createTodoTxt}.
|
|
75
|
+
*
|
|
76
|
+
* Extends the file hooks with client behaviour switches.
|
|
77
|
+
*/
|
|
78
|
+
interface TodoClientOptions extends TodoHooks {
|
|
79
|
+
/** Include `line` and `raw` on every record. Default: `false`. */
|
|
80
|
+
includeSource?: boolean;
|
|
81
|
+
}
|
|
59
82
|
/**
|
|
60
83
|
* A single todo.txt line parsed into a JSON-friendly record.
|
|
61
84
|
*
|
|
62
85
|
* This is the only parsed representation. Inline metadata is separated out of
|
|
63
|
-
* {@link TodoRecord.description} into dedicated fields
|
|
64
|
-
*
|
|
86
|
+
* {@link TodoRecord.description} into dedicated fields. The original line is
|
|
87
|
+
* not retained unless the caller opts in with `includeSource`, which adds the
|
|
88
|
+
* {@link TodoRecord.line} and {@link TodoRecord.raw} source fields.
|
|
65
89
|
*/
|
|
66
90
|
interface TodoRecord {
|
|
67
91
|
/** True when the line starts with `x ` (lowercase and followed by a space). */
|
|
@@ -94,6 +118,22 @@ interface TodoRecord {
|
|
|
94
118
|
* If a key appears more than once, the last value wins.
|
|
95
119
|
*/
|
|
96
120
|
data: Record<string, string>;
|
|
121
|
+
/**
|
|
122
|
+
* 1-based physical line number in the source document.
|
|
123
|
+
*
|
|
124
|
+
* Present only when parsing with `includeSource`. For a whole document it
|
|
125
|
+
* counts every physical line, including blank ones. For a single line it is
|
|
126
|
+
* the number supplied via `ParseOptions.line`.
|
|
127
|
+
*/
|
|
128
|
+
line?: number;
|
|
129
|
+
/**
|
|
130
|
+
* Exact original line, without a trailing newline or a trailing `\r`.
|
|
131
|
+
*
|
|
132
|
+
* Present only when parsing with `includeSource`. Leading and trailing
|
|
133
|
+
* whitespace and tag order are preserved, unlike
|
|
134
|
+
* {@link TodoRecord.description}.
|
|
135
|
+
*/
|
|
136
|
+
raw?: string;
|
|
97
137
|
}
|
|
98
138
|
/**
|
|
99
139
|
* A lazy query over parsed todo records.
|
|
@@ -138,10 +178,12 @@ interface TodoTxtClient {
|
|
|
138
178
|
/**
|
|
139
179
|
* Create a todo.txt client backed by consumer-supplied file hooks.
|
|
140
180
|
*
|
|
141
|
-
* The library performs no IO of its own: `
|
|
142
|
-
* producing the file contents and `
|
|
143
|
-
* once they are implemented. `
|
|
144
|
-
* when supplied, it receives read lifecycle and parse warning
|
|
181
|
+
* The library performs no IO of its own: `options.read` is responsible for
|
|
182
|
+
* producing the file contents and `options.write` will be used by the write
|
|
183
|
+
* APIs once they are implemented. `options.logger` is optional and silent by
|
|
184
|
+
* default; when supplied, it receives read lifecycle and parse warning
|
|
185
|
+
* diagnostics. With `options.includeSource`, every record also carries the
|
|
186
|
+
* 1-based `line` number and the exact `raw` line it was parsed from.
|
|
145
187
|
*
|
|
146
188
|
* Parsed records are cached in memory per client. The first query loads and
|
|
147
189
|
* parses the file; later queries reuse that snapshot. {@link TodoTxtClient.all}
|
|
@@ -155,7 +197,7 @@ interface TodoTxtClient {
|
|
|
155
197
|
* Returned records are copies, so callers may mutate them without affecting the
|
|
156
198
|
* cache.
|
|
157
199
|
*/
|
|
158
|
-
export declare function createTodoTxt(
|
|
200
|
+
export declare function createTodoTxt(options: TodoClientOptions): TodoTxtClient;
|
|
159
201
|
/**
|
|
160
202
|
* Parse a single todo.txt line directly into a JSON-friendly {@link TodoRecord}.
|
|
161
203
|
*
|
|
@@ -170,16 +212,28 @@ export declare function createTodoTxt(hooks: TodoHooks): TodoTxtClient;
|
|
|
170
212
|
* - Projects, contexts, and `key:value` metadata may appear anywhere in the
|
|
171
213
|
* remaining text.
|
|
172
214
|
*
|
|
173
|
-
* Recoverable issues are reported to `onWarning` when supplied;
|
|
174
|
-
* produces a record.
|
|
215
|
+
* Recoverable issues are reported to `options.onWarning` when supplied;
|
|
216
|
+
* parsing still produces a record.
|
|
217
|
+
*
|
|
218
|
+
* With `options.includeSource`, the record carries `raw` (the exact input
|
|
219
|
+
* line, minus a trailing `\r`) and `line` (the number supplied via
|
|
220
|
+
* `options.line`, when given).
|
|
175
221
|
*/
|
|
176
|
-
export declare function parseLine(line: string,
|
|
222
|
+
export declare function parseLine(line: string, options?: ParseOptions): TodoRecord;
|
|
223
|
+
/** @deprecated Pass {@link ParseOptions} with `onWarning` instead. */
|
|
224
|
+
export declare function parseLine(line: string, onWarning: ParseWarningHandler): TodoRecord;
|
|
177
225
|
/**
|
|
178
226
|
* Parse the contents of a todo.txt file.
|
|
179
227
|
*
|
|
180
228
|
* Lines are split on `\n` or `\r\n`; blank and whitespace-only lines are
|
|
181
229
|
* skipped. Every remaining line becomes a {@link TodoRecord}. Warnings are
|
|
182
230
|
* annotated with the 1-based physical line number.
|
|
231
|
+
*
|
|
232
|
+
* With `options.includeSource`, every record carries `raw` (the exact line,
|
|
233
|
+
* minus a trailing `\r`) and `line` (the 1-based physical line number,
|
|
234
|
+
* counting blank lines).
|
|
183
235
|
*/
|
|
184
|
-
export declare function parseDocument(contents: string,
|
|
185
|
-
|
|
236
|
+
export declare function parseDocument(contents: string, options?: ParseOptions): TodoRecord[];
|
|
237
|
+
/** @deprecated Pass {@link ParseOptions} with `onWarning` instead. */
|
|
238
|
+
export declare function parseDocument(contents: string, onWarning: ParseWarningHandler): TodoRecord[];
|
|
239
|
+
export type { LogLevel, MaybePromise, ParseOptions, ParseWarning, ParseWarningHandler, TodoClientOptions, TodoFileHooks, TodoHooks, TodoLogger, TodoQuery, TodoRecord, TodoTxtClient };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/clone.ts
|
|
2
2
|
/** Copy a record so callers cannot mutate the client's cached snapshot. */
|
|
3
3
|
function cloneRecord(todo) {
|
|
4
|
-
|
|
4
|
+
const copy = {
|
|
5
5
|
completed: todo.completed,
|
|
6
6
|
priority: todo.priority,
|
|
7
7
|
completedAt: todo.completedAt,
|
|
@@ -11,6 +11,9 @@ function cloneRecord(todo) {
|
|
|
11
11
|
contexts: [...todo.contexts],
|
|
12
12
|
data: { ...todo.data }
|
|
13
13
|
};
|
|
14
|
+
if (todo.line !== void 0) copy.line = todo.line;
|
|
15
|
+
if (todo.raw !== void 0) copy.raw = todo.raw;
|
|
16
|
+
return copy;
|
|
14
17
|
}
|
|
15
18
|
/** Copy every record in `records`. */
|
|
16
19
|
function cloneRecords(records) {
|
|
@@ -149,23 +152,19 @@ function warnInvalidDate(value, field, onWarning) {
|
|
|
149
152
|
});
|
|
150
153
|
}
|
|
151
154
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* The parser follows the todo.txt format rules:
|
|
155
|
-
*
|
|
156
|
-
* - Completed tasks start with `x `, optionally followed by a completion date
|
|
157
|
-
* and then a creation date.
|
|
158
|
-
* - Incomplete tasks may start with an `(A)`–`(Z)` priority and an optional
|
|
159
|
-
* creation date.
|
|
160
|
-
* - Dates must be real calendar dates in `YYYY-MM-DD` form. A shape-valid but
|
|
161
|
-
* nonexistent date is treated as text.
|
|
162
|
-
* - Projects, contexts, and `key:value` metadata may appear anywhere in the
|
|
163
|
-
* remaining text.
|
|
164
|
-
*
|
|
165
|
-
* Recoverable issues are reported to `onWarning` when supplied; parsing still
|
|
166
|
-
* produces a record.
|
|
155
|
+
* Accept either a {@link ParseWarningHandler} (deprecated) or
|
|
156
|
+
* {@link ParseOptions} as the second argument.
|
|
167
157
|
*/
|
|
168
|
-
function
|
|
158
|
+
function normalizeParseOptions(onWarningOrOptions) {
|
|
159
|
+
if (typeof onWarningOrOptions === "function") return { onWarning: onWarningOrOptions };
|
|
160
|
+
return onWarningOrOptions ?? {};
|
|
161
|
+
}
|
|
162
|
+
/** Remove one trailing `\r`, so `raw` has no carriage return for CRLF input. */
|
|
163
|
+
function stripTrailingCarriageReturn(line) {
|
|
164
|
+
return line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
165
|
+
}
|
|
166
|
+
function parseLine(line, onWarningOrOptions) {
|
|
167
|
+
const options = normalizeParseOptions(onWarningOrOptions);
|
|
169
168
|
let rest = line;
|
|
170
169
|
let completed = false;
|
|
171
170
|
let priority = null;
|
|
@@ -182,8 +181,8 @@ function parseLine(line, onWarning) {
|
|
|
182
181
|
if (createdDate.kind === "valid") {
|
|
183
182
|
createdAt = createdDate.date;
|
|
184
183
|
rest = createdDate.rest;
|
|
185
|
-
} else if (createdDate.kind === "invalid") warnInvalidDate(createdDate.value, "createdAt", onWarning);
|
|
186
|
-
} else if (completedDate.kind === "invalid") warnInvalidDate(completedDate.value, "completedAt", onWarning);
|
|
184
|
+
} else if (createdDate.kind === "invalid") warnInvalidDate(createdDate.value, "createdAt", options.onWarning);
|
|
185
|
+
} else if (completedDate.kind === "invalid") warnInvalidDate(completedDate.value, "completedAt", options.onWarning);
|
|
187
186
|
} else {
|
|
188
187
|
const priorityMatch = PRIORITY_PATTERN.exec(rest);
|
|
189
188
|
if (priorityMatch) {
|
|
@@ -194,10 +193,10 @@ function parseLine(line, onWarning) {
|
|
|
194
193
|
if (createdDate.kind === "valid") {
|
|
195
194
|
createdAt = createdDate.date;
|
|
196
195
|
rest = createdDate.rest;
|
|
197
|
-
} else if (createdDate.kind === "invalid") warnInvalidDate(createdDate.value, "createdAt", onWarning);
|
|
196
|
+
} else if (createdDate.kind === "invalid") warnInvalidDate(createdDate.value, "createdAt", options.onWarning);
|
|
198
197
|
}
|
|
199
|
-
const { description, projects, contexts, data } = parseText(rest.trim(), onWarning);
|
|
200
|
-
|
|
198
|
+
const { description, projects, contexts, data } = parseText(rest.trim(), options.onWarning);
|
|
199
|
+
const record = {
|
|
201
200
|
completed,
|
|
202
201
|
priority,
|
|
203
202
|
completedAt,
|
|
@@ -207,23 +206,26 @@ function parseLine(line, onWarning) {
|
|
|
207
206
|
contexts,
|
|
208
207
|
data
|
|
209
208
|
};
|
|
209
|
+
if (options.includeSource) {
|
|
210
|
+
if (options.line !== void 0) record.line = options.line;
|
|
211
|
+
record.raw = stripTrailingCarriageReturn(line);
|
|
212
|
+
}
|
|
213
|
+
return record;
|
|
210
214
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
*
|
|
214
|
-
* Lines are split on `\n` or `\r\n`; blank and whitespace-only lines are
|
|
215
|
-
* skipped. Every remaining line becomes a {@link TodoRecord}. Warnings are
|
|
216
|
-
* annotated with the 1-based physical line number.
|
|
217
|
-
*/
|
|
218
|
-
function parseDocument(contents, onWarning) {
|
|
215
|
+
function parseDocument(contents, onWarningOrOptions) {
|
|
216
|
+
const { includeSource, onWarning } = normalizeParseOptions(onWarningOrOptions);
|
|
219
217
|
const records = [];
|
|
220
218
|
let lineNumber = 0;
|
|
221
219
|
for (const line of contents.split(/\r?\n/)) {
|
|
222
220
|
lineNumber += 1;
|
|
223
|
-
if (line.trim() !== "") records.push(parseLine(line,
|
|
224
|
-
|
|
225
|
-
line: lineNumber
|
|
226
|
-
|
|
221
|
+
if (line.trim() !== "") records.push(parseLine(line, {
|
|
222
|
+
includeSource,
|
|
223
|
+
line: lineNumber,
|
|
224
|
+
onWarning: onWarning ? (warning) => onWarning({
|
|
225
|
+
...warning,
|
|
226
|
+
line: lineNumber
|
|
227
|
+
}) : void 0
|
|
228
|
+
}));
|
|
227
229
|
}
|
|
228
230
|
return records;
|
|
229
231
|
}
|
|
@@ -264,10 +266,12 @@ function createTodoQuery(load, filters = []) {
|
|
|
264
266
|
/**
|
|
265
267
|
* Create a todo.txt client backed by consumer-supplied file hooks.
|
|
266
268
|
*
|
|
267
|
-
* The library performs no IO of its own: `
|
|
268
|
-
* producing the file contents and `
|
|
269
|
-
* once they are implemented. `
|
|
270
|
-
* when supplied, it receives read lifecycle and parse warning
|
|
269
|
+
* The library performs no IO of its own: `options.read` is responsible for
|
|
270
|
+
* producing the file contents and `options.write` will be used by the write
|
|
271
|
+
* APIs once they are implemented. `options.logger` is optional and silent by
|
|
272
|
+
* default; when supplied, it receives read lifecycle and parse warning
|
|
273
|
+
* diagnostics. With `options.includeSource`, every record also carries the
|
|
274
|
+
* 1-based `line` number and the exact `raw` line it was parsed from.
|
|
271
275
|
*
|
|
272
276
|
* Parsed records are cached in memory per client. The first query loads and
|
|
273
277
|
* parses the file; later queries reuse that snapshot. {@link TodoTxtClient.all}
|
|
@@ -281,11 +285,11 @@ function createTodoQuery(load, filters = []) {
|
|
|
281
285
|
* Returned records are copies, so callers may mutate them without affecting the
|
|
282
286
|
* cache.
|
|
283
287
|
*/
|
|
284
|
-
function createTodoTxt(
|
|
288
|
+
function createTodoTxt(options) {
|
|
285
289
|
let cache;
|
|
286
290
|
let inFlight;
|
|
287
291
|
let generation = 0;
|
|
288
|
-
const logger =
|
|
292
|
+
const logger = options.logger;
|
|
289
293
|
const log = (level, message, meta) => {
|
|
290
294
|
if (!logger) return;
|
|
291
295
|
try {
|
|
@@ -296,12 +300,15 @@ function createTodoTxt(hooks) {
|
|
|
296
300
|
const readFresh = async () => {
|
|
297
301
|
const currentGeneration = ++generation;
|
|
298
302
|
log("debug", "Reading todo file");
|
|
299
|
-
const records = parseDocument(await
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
303
|
+
const records = parseDocument(await options.read(), {
|
|
304
|
+
includeSource: options.includeSource,
|
|
305
|
+
onWarning: (warning) => {
|
|
306
|
+
log("warn", warning.message, {
|
|
307
|
+
...warning.meta,
|
|
308
|
+
code: warning.code,
|
|
309
|
+
line: warning.line
|
|
310
|
+
});
|
|
311
|
+
}
|
|
305
312
|
});
|
|
306
313
|
log("debug", "Parsed todo file", { records: records.length });
|
|
307
314
|
if (currentGeneration === generation) cache = records;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/clone.ts","../src/date.ts","../src/metadata.ts","../src/parse.ts","../src/query.ts","../src/client.ts"],"sourcesContent":["import type { TodoRecord } from \"./types.ts\";\n\n/** Copy a record so callers cannot mutate the client's cached snapshot. */\nexport function cloneRecord(todo: TodoRecord): TodoRecord {\n return {\n completed: todo.completed,\n priority: todo.priority,\n completedAt: todo.completedAt,\n createdAt: todo.createdAt,\n description: todo.description,\n projects: [...todo.projects],\n contexts: [...todo.contexts],\n data: { ...todo.data },\n };\n}\n\n/** Copy every record in `records`. */\nexport function cloneRecords(records: readonly TodoRecord[]): TodoRecord[] {\n return records.map(cloneRecord);\n}\n","const DATE_SHAPE_PATTERN = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\nconst DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\n\nfunction isLeapYear(year: number): boolean {\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n}\n\n/**\n * True when `value` is a real calendar date in `YYYY-MM-DD` form.\n *\n * The check is purely arithmetic so it does not depend on the host timezone and\n * does not let JavaScript's `Date` roll invalid values over (for example,\n * `2011-02-30` must not become March 2).\n */\nexport function isValidDate(value: string): boolean {\n const match = DATE_SHAPE_PATTERN.exec(value);\n if (!match) {\n return false;\n }\n\n const year = Number(match[1]);\n const month = Number(match[2]);\n const day = Number(match[3]);\n\n if (month < 1 || month > 12 || day < 1) {\n return false;\n }\n\n const maxDay =\n month === 2 && isLeapYear(year) ? 29 : (DAYS_IN_MONTH[month - 1] ?? 0);\n\n return day <= maxDay;\n}\n","import type { ParseWarningHandler } from \"./types.ts\";\n\nconst EXTENSION_PATTERN = /^([^:\\s]+):([^:\\s]+)$/;\n\n/** Metadata collected from a task's text. */\nexport interface TodoMetadata {\n projects: string[];\n contexts: string[];\n data: Record<string, string>;\n}\n\n/** Everything derived from a task's text in one token pass. */\nexport interface TodoText extends TodoMetadata {\n description: string;\n}\n\nfunction tokenize(text: string): string[] {\n const trimmed = text.trim();\n if (trimmed === \"\") {\n return [];\n }\n\n return trimmed.split(/\\s+/);\n}\n\n/**\n * True when a whitespace-delimited token is inline metadata.\n *\n * Inline metadata is a project (`+name`), a context (`@name`), or a\n * `key:value` extension. Bare `+`/`@` tokens and values containing another\n * colon are not metadata.\n */\nexport function isMetadataToken(token: string): boolean {\n if (token.startsWith(\"+\") && token.length > 1) {\n return true;\n }\n\n if (token.startsWith(\"@\") && token.length > 1) {\n return true;\n }\n\n return EXTENSION_PATTERN.test(token);\n}\n\n/**\n * Collect a task's description, projects, contexts, and extensions in one pass.\n *\n * Previous versions tokenized the text once for metadata and again to strip it;\n * doing both here keeps parsing to a single split per line.\n *\n * When a `key:value` key is repeated, `onWarning` receives a\n * `duplicate-metadata-key` warning and the last value wins.\n */\nexport function parseText(\n text: string,\n onWarning?: ParseWarningHandler,\n): TodoText {\n const projects: string[] = [];\n const contexts: string[] = [];\n const data: Record<string, string> = {};\n const descriptionTokens: string[] = [];\n\n for (const token of tokenize(text)) {\n if (token.startsWith(\"+\") && token.length > 1) {\n projects.push(token.slice(1));\n continue;\n }\n\n if (token.startsWith(\"@\") && token.length > 1) {\n contexts.push(token.slice(1));\n continue;\n }\n\n const extension = EXTENSION_PATTERN.exec(token);\n const key = extension?.[1];\n const value = extension?.[2];\n if (key !== undefined && value !== undefined) {\n if (Object.hasOwn(data, key)) {\n onWarning?.({\n code: \"duplicate-metadata-key\",\n message: `Duplicate metadata key \"${key}\"; the last value wins.`,\n meta: { key, previousValue: data[key], value },\n });\n }\n\n data[key] = value;\n continue;\n }\n\n descriptionTokens.push(token);\n }\n\n return {\n description: descriptionTokens.join(\" \"),\n projects,\n contexts,\n data,\n };\n}\n\n/** Collect projects, contexts, and extensions from task text. */\nexport function parseMetadata(text: string): TodoMetadata {\n const { projects, contexts, data } = parseText(text);\n return { projects, contexts, data };\n}\n\n/**\n * Remove inline metadata from task text.\n *\n * Remaining tokens are rejoined with single spaces, so repeated whitespace can\n * be normalized.\n */\nexport function stripMetadata(text: string): string {\n return parseText(text).description;\n}\n","import { isValidDate } from \"./date.ts\";\nimport { parseText } from \"./metadata.ts\";\nimport type { ParseWarningHandler, TodoRecord } from \"./types.ts\";\n\nconst PRIORITY_PATTERN = /^\\(([A-Z])\\) /;\nconst LEADING_DATE_PATTERN = /^(\\d{4}-\\d{2}-\\d{2})(?: |$)/;\n\ntype LeadingDate =\n | { kind: \"absent\"; rest: string }\n | { kind: \"valid\"; date: string; rest: string }\n | { kind: \"invalid\"; value: string; rest: string };\n\n/**\n * Inspect a `YYYY-MM-DD` token at the start of `input`.\n *\n * A value with the right shape that does not exist on the calendar is reported\n * as `invalid`. In that case `rest` is the original input, so callers leave the\n * token in the description instead of consuming it.\n */\nfunction takeLeadingDate(input: string): LeadingDate {\n const match = LEADING_DATE_PATTERN.exec(input);\n if (!match) {\n return { kind: \"absent\", rest: input };\n }\n\n const date = match[1];\n if (date === undefined) {\n return { kind: \"absent\", rest: input };\n }\n\n if (!isValidDate(date)) {\n return { kind: \"invalid\", value: date, rest: input };\n }\n\n return { kind: \"valid\", date, rest: input.slice(match[0]!.length) };\n}\n\nfunction warnInvalidDate(\n value: string,\n field: \"completedAt\" | \"createdAt\",\n onWarning?: ParseWarningHandler,\n): void {\n const label = field === \"completedAt\" ? \"completion\" : \"creation\";\n\n onWarning?.({\n code: \"invalid-date\",\n message: `Invalid ${label} date \"${value}\"; treating it as text.`,\n meta: { value, field },\n });\n}\n\n/**\n * Parse a single todo.txt line directly into a JSON-friendly {@link TodoRecord}.\n *\n * The parser follows the todo.txt format rules:\n *\n * - Completed tasks start with `x `, optionally followed by a completion date\n * and then a creation date.\n * - Incomplete tasks may start with an `(A)`–`(Z)` priority and an optional\n * creation date.\n * - Dates must be real calendar dates in `YYYY-MM-DD` form. A shape-valid but\n * nonexistent date is treated as text.\n * - Projects, contexts, and `key:value` metadata may appear anywhere in the\n * remaining text.\n *\n * Recoverable issues are reported to `onWarning` when supplied; parsing still\n * produces a record.\n */\nexport function parseLine(\n line: string,\n onWarning?: ParseWarningHandler,\n): TodoRecord {\n let rest = line;\n let completed = false;\n let priority: string | null = null;\n let completedAt: string | null = null;\n let createdAt: string | null = null;\n\n if (rest.startsWith(\"x \")) {\n completed = true;\n rest = rest.slice(2);\n\n const completedDate = takeLeadingDate(rest);\n if (completedDate.kind === \"valid\") {\n completedAt = completedDate.date;\n rest = completedDate.rest;\n\n const createdDate = takeLeadingDate(rest);\n if (createdDate.kind === \"valid\") {\n createdAt = createdDate.date;\n rest = createdDate.rest;\n } else if (createdDate.kind === \"invalid\") {\n warnInvalidDate(createdDate.value, \"createdAt\", onWarning);\n }\n } else if (completedDate.kind === \"invalid\") {\n // The same token cannot also be a creation date, so only warn once.\n warnInvalidDate(completedDate.value, \"completedAt\", onWarning);\n }\n } else {\n const priorityMatch = PRIORITY_PATTERN.exec(rest);\n if (priorityMatch) {\n priority = priorityMatch[1]!;\n rest = rest.slice(priorityMatch[0]!.length);\n }\n\n const createdDate = takeLeadingDate(rest);\n if (createdDate.kind === \"valid\") {\n createdAt = createdDate.date;\n rest = createdDate.rest;\n } else if (createdDate.kind === \"invalid\") {\n warnInvalidDate(createdDate.value, \"createdAt\", onWarning);\n }\n }\n\n const text = rest.trim();\n const { description, projects, contexts, data } = parseText(text, onWarning);\n\n return {\n completed,\n priority,\n completedAt,\n createdAt,\n description,\n projects,\n contexts,\n data,\n };\n}\n\n/**\n * Parse the contents of a todo.txt file.\n *\n * Lines are split on `\\n` or `\\r\\n`; blank and whitespace-only lines are\n * skipped. Every remaining line becomes a {@link TodoRecord}. Warnings are\n * annotated with the 1-based physical line number.\n */\nexport function parseDocument(\n contents: string,\n onWarning?: ParseWarningHandler,\n): TodoRecord[] {\n const records: TodoRecord[] = [];\n let lineNumber = 0;\n\n for (const line of contents.split(/\\r?\\n/)) {\n lineNumber += 1;\n\n if (line.trim() !== \"\") {\n records.push(\n parseLine(\n line,\n onWarning\n ? (warning) => onWarning({ ...warning, line: lineNumber })\n : undefined,\n ),\n );\n }\n }\n\n return records;\n}\n","import { cloneRecords } from \"./clone.ts\";\nimport type { TodoRecord } from \"./types.ts\";\n\n/** A predicate applied to every record in a query. */\nexport type TodoFilter = (todo: TodoRecord) => boolean;\n\n/** Loads and parses every todo.txt record. */\nexport type LoadRecords = () => Promise<TodoRecord[]>;\n\n/**\n * A lazy query over parsed todo records.\n *\n * Filters return a new query and perform no IO. Awaiting a query resolves\n * through the supplied loader; the client caches parsed records, so only the\n * first query reads the file. {@link TodoQuery.projects} and\n * {@link TodoQuery.contexts} are terminal plucks that resolve to unique,\n * alphabetically sorted names.\n */\nexport interface TodoQuery extends PromiseLike<TodoRecord[]> {\n /** Only records that are not completed. */\n pending: () => TodoQuery;\n /** Only records that are completed. */\n completed: () => TodoQuery;\n /** Only records tagged with the project `name`. */\n project: (name: string) => TodoQuery;\n /** Only records tagged with the context `name`. */\n context: (name: string) => TodoQuery;\n /** Unique project names in the current result, alphabetically sorted. */\n projects: () => Promise<string[]>;\n /** Unique context names in the current result, alphabetically sorted. */\n contexts: () => Promise<string[]>;\n}\n\nfunction uniqueSorted(values: string[]): string[] {\n return [...new Set(values)].sort();\n}\n\nasync function resolveRaw(\n load: LoadRecords,\n filters: TodoFilter[],\n): Promise<TodoRecord[]> {\n const records = await load();\n\n if (filters.length === 0) {\n return records;\n }\n\n return records.filter((record) =>\n filters.every((filter) => filter(record)),\n );\n}\n\nasync function resolveRecords(\n load: LoadRecords,\n filters: TodoFilter[],\n): Promise<TodoRecord[]> {\n return cloneRecords(await resolveRaw(load, filters));\n}\n\nfunction pluckNames(\n load: LoadRecords,\n filters: TodoFilter[],\n pick: (todo: TodoRecord) => string[],\n): Promise<string[]> {\n return resolveRaw(load, filters).then((records) =>\n uniqueSorted(records.flatMap(pick)),\n );\n}\n\n/**\n * Create a lazy query over the records loaded by `load`.\n *\n * Each filter method appends a predicate, so chained calls compose. For\n * example, `pending().completed()` matches nothing, while\n * `project(\"Work\").pending()` matches pending records in `Work`.\n */\nexport function createTodoQuery(\n load: LoadRecords,\n filters: TodoFilter[] = [],\n): TodoQuery {\n return {\n pending: () =>\n createTodoQuery(load, [...filters, (todo) => !todo.completed]),\n completed: () =>\n createTodoQuery(load, [...filters, (todo) => todo.completed]),\n project: (name) =>\n createTodoQuery(load, [\n ...filters,\n (todo) => todo.projects.includes(name),\n ]),\n context: (name) =>\n createTodoQuery(load, [\n ...filters,\n (todo) => todo.contexts.includes(name),\n ]),\n projects: () => pluckNames(load, filters, (todo) => todo.projects),\n contexts: () => pluckNames(load, filters, (todo) => todo.contexts),\n then: (onfulfilled, onrejected) =>\n resolveRecords(load, filters).then(onfulfilled, onrejected),\n };\n}\n","import { cloneRecords } from \"./clone.ts\";\nimport { parseDocument } from \"./parse.ts\";\nimport { createTodoQuery } from \"./query.ts\";\nimport type { TodoQuery } from \"./query.ts\";\nimport type { TodoHooks, TodoLogger, TodoRecord } from \"./types.ts\";\n\n/** The read interface returned by {@link createTodoTxt}. */\nexport interface TodoTxtClient {\n /** Read fresh todo.txt contents, replace the cache, and return every record. */\n all: () => Promise<TodoRecord[]>;\n /** Query only records that are not completed, using the cached snapshot. */\n pending: () => TodoQuery;\n /** Query only records that are completed, using the cached snapshot. */\n completed: () => TodoQuery;\n /** Query records tagged with a single project name, using the cache. */\n project: (name: string) => TodoQuery;\n /** Query records tagged with a single context name, using the cache. */\n context: (name: string) => TodoQuery;\n /** List unique project names from the cached snapshot, alphabetically sorted. */\n projects: () => Promise<string[]>;\n /** List unique context names from the cached snapshot, alphabetically sorted. */\n contexts: () => Promise<string[]>;\n}\n\n/**\n * Create a todo.txt client backed by consumer-supplied file hooks.\n *\n * The library performs no IO of its own: `hooks.read` is responsible for\n * producing the file contents and `hooks.write` will be used by the write APIs\n * once they are implemented. `hooks.logger` is optional and silent by default;\n * when supplied, it receives read lifecycle and parse warning diagnostics.\n *\n * Parsed records are cached in memory per client. The first query loads and\n * parses the file; later queries reuse that snapshot. {@link TodoTxtClient.all}\n * always reads fresh contents and replaces the cache, so it can be used to\n * refresh after the underlying file changes.\n *\n * Every line is parsed into a {@link TodoRecord} when the cache is populated.\n * Filters such as {@link TodoQuery.pending} and {@link TodoQuery.project}\n * operate on that array of JSON records, and plucks such as\n * {@link TodoQuery.projects} return unique, alphabetically sorted names.\n * Returned records are copies, so callers may mutate them without affecting the\n * cache.\n */\nexport function createTodoTxt(hooks: TodoHooks): TodoTxtClient {\n let cache: TodoRecord[] | undefined;\n let inFlight: Promise<TodoRecord[]> | undefined;\n let generation = 0;\n\n const logger = hooks.logger;\n\n const log: TodoLogger = (level, message, meta) => {\n if (!logger) {\n return;\n }\n\n try {\n const result = logger(level, message, meta);\n\n if (\n result &&\n typeof (result as PromiseLike<unknown>).then === \"function\"\n ) {\n void Promise.resolve(result).catch(() => {});\n }\n } catch {\n // Logging is best-effort and must never break reads or queries.\n }\n };\n\n const readFresh = async (): Promise<TodoRecord[]> => {\n const currentGeneration = ++generation;\n\n log(\"debug\", \"Reading todo file\");\n const contents = await hooks.read();\n const records = parseDocument(contents, (warning) => {\n log(\"warn\", warning.message, {\n ...warning.meta,\n code: warning.code,\n line: warning.line,\n });\n });\n log(\"debug\", \"Parsed todo file\", { records: records.length });\n\n if (currentGeneration === generation) {\n cache = records;\n }\n\n return records;\n };\n\n const refresh = (): Promise<TodoRecord[]> => {\n const promise = readFresh();\n inFlight = promise;\n\n void promise\n .finally(() => {\n if (inFlight === promise) {\n inFlight = undefined;\n }\n })\n .catch(() => {});\n\n return promise;\n };\n\n const loadCached = (): Promise<TodoRecord[]> => {\n if (inFlight) {\n return inFlight;\n }\n\n if (cache) {\n return Promise.resolve(cache);\n }\n\n return refresh();\n };\n\n const all = async (): Promise<TodoRecord[]> =>\n cloneRecords(await refresh());\n\n const query = createTodoQuery(loadCached);\n\n return {\n all,\n pending: query.pending,\n completed: query.completed,\n project: query.project,\n context: query.context,\n projects: query.projects,\n contexts: query.contexts,\n };\n}\n"],"mappings":";;AAGA,SAAgB,YAAY,MAA8B;CACxD,OAAO;EACL,WAAW,KAAK;EAChB,UAAU,KAAK;EACf,aAAa,KAAK;EAClB,WAAW,KAAK;EAChB,aAAa,KAAK;EAClB,UAAU,CAAC,GAAG,KAAK,QAAQ;EAC3B,UAAU,CAAC,GAAG,KAAK,QAAQ;EAC3B,MAAM,EAAE,GAAG,KAAK,KAAK;CACvB;AACF;;AAGA,SAAgB,aAAa,SAA8C;CACzE,OAAO,QAAQ,IAAI,WAAW;AAChC;;ACnBA,MAAM,qBAAqB;AAC3B,MAAM,gBAAgB;CAAC;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;AAAE;AAErE,SAAS,WAAW,MAAuB;CACzC,OAAQ,OAAO,MAAM,KAAK,OAAO,QAAQ,KAAM,OAA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ACD,IAAI,SAAS,oBAAoB,EAAE,SAAS,QAAQ,OAAO,CAAC;EAE5D,IAAI,sBAAsB,YACxB,QAAQ;EAGV,OAAO;CACT;CAEA,MAAM,gBAAuC;EAC3C,MAAM,UAAU,UAAU;EAC1B,WAAW;EAEX,QACG,cAAc;GACb,IAAI,aAAa,SACf,WAAW,KAAA;EAEf,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;EAEjB,OAAO;CACT;CAEA,MAAM,mBAA0C;EAC9C,IAAI,UACF,OAAO;EAGT,IAAI,OACF,OAAO,QAAQ,QAAQ,KAAK;EAG9B,OAAO,QAAQ;CACjB;CAEA,MAAM,MAAM,YACV,aAAa,MAAM,QAAQ,CAAC;CAE9B,MAAM,QAAQ,gBAAgB,UAAU;CAExC,OAAO;EACL;EACA,SAAS,MAAM;EACf,WAAW,MAAM;EACjB,SAAS,MAAM;EACf,SAAS,MAAM;EACf,UAAU,MAAM;EAChB,UAAU,MAAM;CAClB;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/clone.ts","../src/date.ts","../src/metadata.ts","../src/parse.ts","../src/query.ts","../src/client.ts"],"sourcesContent":["import type { TodoRecord } from \"./types.ts\";\n\n/** Copy a record so callers cannot mutate the client's cached snapshot. */\nexport function cloneRecord(todo: TodoRecord): TodoRecord {\n const copy: TodoRecord = {\n completed: todo.completed,\n priority: todo.priority,\n completedAt: todo.completedAt,\n createdAt: todo.createdAt,\n description: todo.description,\n projects: [...todo.projects],\n contexts: [...todo.contexts],\n data: { ...todo.data },\n };\n\n if (todo.line !== undefined) {\n copy.line = todo.line;\n }\n\n if (todo.raw !== undefined) {\n copy.raw = todo.raw;\n }\n\n return copy;\n}\n\n/** Copy every record in `records`. */\nexport function cloneRecords(records: readonly TodoRecord[]): TodoRecord[] {\n return records.map(cloneRecord);\n}\n","const DATE_SHAPE_PATTERN = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\nconst DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\n\nfunction isLeapYear(year: number): boolean {\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n}\n\n/**\n * True when `value` is a real calendar date in `YYYY-MM-DD` form.\n *\n * The check is purely arithmetic so it does not depend on the host timezone and\n * does not let JavaScript's `Date` roll invalid values over (for example,\n * `2011-02-30` must not become March 2).\n */\nexport function isValidDate(value: string): boolean {\n const match = DATE_SHAPE_PATTERN.exec(value);\n if (!match) {\n return false;\n }\n\n const year = Number(match[1]);\n const month = Number(match[2]);\n const day = Number(match[3]);\n\n if (month < 1 || month > 12 || day < 1) {\n return false;\n }\n\n const maxDay =\n month === 2 && isLeapYear(year) ? 29 : (DAYS_IN_MONTH[month - 1] ?? 0);\n\n return day <= maxDay;\n}\n","import type { ParseWarningHandler } from \"./types.ts\";\n\nconst EXTENSION_PATTERN = /^([^:\\s]+):([^:\\s]+)$/;\n\n/** Metadata collected from a task's text. */\nexport interface TodoMetadata {\n projects: string[];\n contexts: string[];\n data: Record<string, string>;\n}\n\n/** Everything derived from a task's text in one token pass. */\nexport interface TodoText extends TodoMetadata {\n description: string;\n}\n\nfunction tokenize(text: string): string[] {\n const trimmed = text.trim();\n if (trimmed === \"\") {\n return [];\n }\n\n return trimmed.split(/\\s+/);\n}\n\n/**\n * True when a whitespace-delimited token is inline metadata.\n *\n * Inline metadata is a project (`+name`), a context (`@name`), or a\n * `key:value` extension. Bare `+`/`@` tokens and values containing another\n * colon are not metadata.\n */\nexport function isMetadataToken(token: string): boolean {\n if (token.startsWith(\"+\") && token.length > 1) {\n return true;\n }\n\n if (token.startsWith(\"@\") && token.length > 1) {\n return true;\n }\n\n return EXTENSION_PATTERN.test(token);\n}\n\n/**\n * Collect a task's description, projects, contexts, and extensions in one pass.\n *\n * Previous versions tokenized the text once for metadata and again to strip it;\n * doing both here keeps parsing to a single split per line.\n *\n * When a `key:value` key is repeated, `onWarning` receives a\n * `duplicate-metadata-key` warning and the last value wins.\n */\nexport function parseText(\n text: string,\n onWarning?: ParseWarningHandler,\n): TodoText {\n const projects: string[] = [];\n const contexts: string[] = [];\n const data: Record<string, string> = {};\n const descriptionTokens: string[] = [];\n\n for (const token of tokenize(text)) {\n if (token.startsWith(\"+\") && token.length > 1) {\n projects.push(token.slice(1));\n continue;\n }\n\n if (token.startsWith(\"@\") && token.length > 1) {\n contexts.push(token.slice(1));\n continue;\n }\n\n const extension = EXTENSION_PATTERN.exec(token);\n const key = extension?.[1];\n const value = extension?.[2];\n if (key !== undefined && value !== undefined) {\n if (Object.hasOwn(data, key)) {\n onWarning?.({\n code: \"duplicate-metadata-key\",\n message: `Duplicate metadata key \"${key}\"; the last value wins.`,\n meta: { key, previousValue: data[key], value },\n });\n }\n\n data[key] = value;\n continue;\n }\n\n descriptionTokens.push(token);\n }\n\n return {\n description: descriptionTokens.join(\" \"),\n projects,\n contexts,\n data,\n };\n}\n\n/** Collect projects, contexts, and extensions from task text. */\nexport function parseMetadata(text: string): TodoMetadata {\n const { projects, contexts, data } = parseText(text);\n return { projects, contexts, data };\n}\n\n/**\n * Remove inline metadata from task text.\n *\n * Remaining tokens are rejoined with single spaces, so repeated whitespace can\n * be normalized.\n */\nexport function stripMetadata(text: string): string {\n return parseText(text).description;\n}\n","import { isValidDate } from \"./date.ts\";\nimport { parseText } from \"./metadata.ts\";\nimport type {\n ParseOptions,\n ParseWarningHandler,\n TodoRecord,\n} from \"./types.ts\";\n\nconst PRIORITY_PATTERN = /^\\(([A-Z])\\) /;\nconst LEADING_DATE_PATTERN = /^(\\d{4}-\\d{2}-\\d{2})(?: |$)/;\n\ntype LeadingDate =\n | { kind: \"absent\"; rest: string }\n | { kind: \"valid\"; date: string; rest: string }\n | { kind: \"invalid\"; value: string; rest: string };\n\n/**\n * Inspect a `YYYY-MM-DD` token at the start of `input`.\n *\n * A value with the right shape that does not exist on the calendar is reported\n * as `invalid`. In that case `rest` is the original input, so callers leave the\n * token in the description instead of consuming it.\n */\nfunction takeLeadingDate(input: string): LeadingDate {\n const match = LEADING_DATE_PATTERN.exec(input);\n if (!match) {\n return { kind: \"absent\", rest: input };\n }\n\n const date = match[1];\n if (date === undefined) {\n return { kind: \"absent\", rest: input };\n }\n\n if (!isValidDate(date)) {\n return { kind: \"invalid\", value: date, rest: input };\n }\n\n return { kind: \"valid\", date, rest: input.slice(match[0]!.length) };\n}\n\nfunction warnInvalidDate(\n value: string,\n field: \"completedAt\" | \"createdAt\",\n onWarning?: ParseWarningHandler,\n): void {\n const label = field === \"completedAt\" ? \"completion\" : \"creation\";\n\n onWarning?.({\n code: \"invalid-date\",\n message: `Invalid ${label} date \"${value}\"; treating it as text.`,\n meta: { value, field },\n });\n}\n\n/**\n * Accept either a {@link ParseWarningHandler} (deprecated) or\n * {@link ParseOptions} as the second argument.\n */\nfunction normalizeParseOptions(\n onWarningOrOptions?: ParseWarningHandler | ParseOptions,\n): ParseOptions {\n if (typeof onWarningOrOptions === \"function\") {\n return { onWarning: onWarningOrOptions };\n }\n\n return onWarningOrOptions ?? {};\n}\n\n/** Remove one trailing `\\r`, so `raw` has no carriage return for CRLF input. */\nfunction stripTrailingCarriageReturn(line: string): string {\n return line.endsWith(\"\\r\") ? line.slice(0, -1) : line;\n}\n\n/**\n * Parse a single todo.txt line directly into a JSON-friendly {@link TodoRecord}.\n *\n * The parser follows the todo.txt format rules:\n *\n * - Completed tasks start with `x `, optionally followed by a completion date\n * and then a creation date.\n * - Incomplete tasks may start with an `(A)`–`(Z)` priority and an optional\n * creation date.\n * - Dates must be real calendar dates in `YYYY-MM-DD` form. A shape-valid but\n * nonexistent date is treated as text.\n * - Projects, contexts, and `key:value` metadata may appear anywhere in the\n * remaining text.\n *\n * Recoverable issues are reported to `options.onWarning` when supplied;\n * parsing still produces a record.\n *\n * With `options.includeSource`, the record carries `raw` (the exact input\n * line, minus a trailing `\\r`) and `line` (the number supplied via\n * `options.line`, when given).\n */\nexport function parseLine(\n line: string,\n options?: ParseOptions,\n): TodoRecord;\n/** @deprecated Pass {@link ParseOptions} with `onWarning` instead. */\nexport function parseLine(\n line: string,\n onWarning: ParseWarningHandler,\n): TodoRecord;\nexport function parseLine(\n line: string,\n onWarningOrOptions?: ParseWarningHandler | ParseOptions,\n): TodoRecord {\n const options = normalizeParseOptions(onWarningOrOptions);\n let rest = line;\n let completed = false;\n let priority: string | null = null;\n let completedAt: string | null = null;\n let createdAt: string | null = null;\n\n if (rest.startsWith(\"x \")) {\n completed = true;\n rest = rest.slice(2);\n\n const completedDate = takeLeadingDate(rest);\n if (completedDate.kind === \"valid\") {\n completedAt = completedDate.date;\n rest = completedDate.rest;\n\n const createdDate = takeLeadingDate(rest);\n if (createdDate.kind === \"valid\") {\n createdAt = createdDate.date;\n rest = createdDate.rest;\n } else if (createdDate.kind === \"invalid\") {\n warnInvalidDate(createdDate.value, \"createdAt\", options.onWarning);\n }\n } else if (completedDate.kind === \"invalid\") {\n // The same token cannot also be a creation date, so only warn once.\n warnInvalidDate(completedDate.value, \"completedAt\", options.onWarning);\n }\n } else {\n const priorityMatch = PRIORITY_PATTERN.exec(rest);\n if (priorityMatch) {\n priority = priorityMatch[1]!;\n rest = rest.slice(priorityMatch[0]!.length);\n }\n\n const createdDate = takeLeadingDate(rest);\n if (createdDate.kind === \"valid\") {\n createdAt = createdDate.date;\n rest = createdDate.rest;\n } else if (createdDate.kind === \"invalid\") {\n warnInvalidDate(createdDate.value, \"createdAt\", options.onWarning);\n }\n }\n\n const text = rest.trim();\n const { description, projects, contexts, data } = parseText(\n text,\n options.onWarning,\n );\n\n const record: TodoRecord = {\n completed,\n priority,\n completedAt,\n createdAt,\n description,\n projects,\n contexts,\n data,\n };\n\n if (options.includeSource) {\n if (options.line !== undefined) {\n record.line = options.line;\n }\n\n record.raw = stripTrailingCarriageReturn(line);\n }\n\n return record;\n}\n\n/**\n * Parse the contents of a todo.txt file.\n *\n * Lines are split on `\\n` or `\\r\\n`; blank and whitespace-only lines are\n * skipped. Every remaining line becomes a {@link TodoRecord}. Warnings are\n * annotated with the 1-based physical line number.\n *\n * With `options.includeSource`, every record carries `raw` (the exact line,\n * minus a trailing `\\r`) and `line` (the 1-based physical line number,\n * counting blank lines).\n */\nexport function parseDocument(\n contents: string,\n options?: ParseOptions,\n): TodoRecord[];\n/** @deprecated Pass {@link ParseOptions} with `onWarning` instead. */\nexport function parseDocument(\n contents: string,\n onWarning: ParseWarningHandler,\n): TodoRecord[];\nexport function parseDocument(\n contents: string,\n onWarningOrOptions?: ParseWarningHandler | ParseOptions,\n): TodoRecord[] {\n const { includeSource, onWarning } = normalizeParseOptions(onWarningOrOptions);\n const records: TodoRecord[] = [];\n let lineNumber = 0;\n\n for (const line of contents.split(/\\r?\\n/)) {\n lineNumber += 1;\n\n if (line.trim() !== \"\") {\n records.push(\n parseLine(line, {\n includeSource,\n line: lineNumber,\n onWarning: onWarning\n ? (warning) => onWarning({ ...warning, line: lineNumber })\n : undefined,\n }),\n );\n }\n }\n\n return records;\n}\n","import { cloneRecords } from \"./clone.ts\";\nimport type { TodoRecord } from \"./types.ts\";\n\n/** A predicate applied to every record in a query. */\nexport type TodoFilter = (todo: TodoRecord) => boolean;\n\n/** Loads and parses every todo.txt record. */\nexport type LoadRecords = () => Promise<TodoRecord[]>;\n\n/**\n * A lazy query over parsed todo records.\n *\n * Filters return a new query and perform no IO. Awaiting a query resolves\n * through the supplied loader; the client caches parsed records, so only the\n * first query reads the file. {@link TodoQuery.projects} and\n * {@link TodoQuery.contexts} are terminal plucks that resolve to unique,\n * alphabetically sorted names.\n */\nexport interface TodoQuery extends PromiseLike<TodoRecord[]> {\n /** Only records that are not completed. */\n pending: () => TodoQuery;\n /** Only records that are completed. */\n completed: () => TodoQuery;\n /** Only records tagged with the project `name`. */\n project: (name: string) => TodoQuery;\n /** Only records tagged with the context `name`. */\n context: (name: string) => TodoQuery;\n /** Unique project names in the current result, alphabetically sorted. */\n projects: () => Promise<string[]>;\n /** Unique context names in the current result, alphabetically sorted. */\n contexts: () => Promise<string[]>;\n}\n\nfunction uniqueSorted(values: string[]): string[] {\n return [...new Set(values)].sort();\n}\n\nasync function resolveRaw(\n load: LoadRecords,\n filters: TodoFilter[],\n): Promise<TodoRecord[]> {\n const records = await load();\n\n if (filters.length === 0) {\n return records;\n }\n\n return records.filter((record) =>\n filters.every((filter) => filter(record)),\n );\n}\n\nasync function resolveRecords(\n load: LoadRecords,\n filters: TodoFilter[],\n): Promise<TodoRecord[]> {\n return cloneRecords(await resolveRaw(load, filters));\n}\n\nfunction pluckNames(\n load: LoadRecords,\n filters: TodoFilter[],\n pick: (todo: TodoRecord) => string[],\n): Promise<string[]> {\n return resolveRaw(load, filters).then((records) =>\n uniqueSorted(records.flatMap(pick)),\n );\n}\n\n/**\n * Create a lazy query over the records loaded by `load`.\n *\n * Each filter method appends a predicate, so chained calls compose. For\n * example, `pending().completed()` matches nothing, while\n * `project(\"Work\").pending()` matches pending records in `Work`.\n */\nexport function createTodoQuery(\n load: LoadRecords,\n filters: TodoFilter[] = [],\n): TodoQuery {\n return {\n pending: () =>\n createTodoQuery(load, [...filters, (todo) => !todo.completed]),\n completed: () =>\n createTodoQuery(load, [...filters, (todo) => todo.completed]),\n project: (name) =>\n createTodoQuery(load, [\n ...filters,\n (todo) => todo.projects.includes(name),\n ]),\n context: (name) =>\n createTodoQuery(load, [\n ...filters,\n (todo) => todo.contexts.includes(name),\n ]),\n projects: () => pluckNames(load, filters, (todo) => todo.projects),\n contexts: () => pluckNames(load, filters, (todo) => todo.contexts),\n then: (onfulfilled, onrejected) =>\n resolveRecords(load, filters).then(onfulfilled, onrejected),\n };\n}\n","import { cloneRecords } from \"./clone.ts\";\nimport { parseDocument } from \"./parse.ts\";\nimport { createTodoQuery } from \"./query.ts\";\nimport type { TodoQuery } from \"./query.ts\";\nimport type {\n TodoClientOptions,\n TodoLogger,\n TodoRecord,\n} from \"./types.ts\";\n\n/** The read interface returned by {@link createTodoTxt}. */\nexport interface TodoTxtClient {\n /** Read fresh todo.txt contents, replace the cache, and return every record. */\n all: () => Promise<TodoRecord[]>;\n /** Query only records that are not completed, using the cached snapshot. */\n pending: () => TodoQuery;\n /** Query only records that are completed, using the cached snapshot. */\n completed: () => TodoQuery;\n /** Query records tagged with a single project name, using the cache. */\n project: (name: string) => TodoQuery;\n /** Query records tagged with a single context name, using the cache. */\n context: (name: string) => TodoQuery;\n /** List unique project names from the cached snapshot, alphabetically sorted. */\n projects: () => Promise<string[]>;\n /** List unique context names from the cached snapshot, alphabetically sorted. */\n contexts: () => Promise<string[]>;\n}\n\n/**\n * Create a todo.txt client backed by consumer-supplied file hooks.\n *\n * The library performs no IO of its own: `options.read` is responsible for\n * producing the file contents and `options.write` will be used by the write\n * APIs once they are implemented. `options.logger` is optional and silent by\n * default; when supplied, it receives read lifecycle and parse warning\n * diagnostics. With `options.includeSource`, every record also carries the\n * 1-based `line` number and the exact `raw` line it was parsed from.\n *\n * Parsed records are cached in memory per client. The first query loads and\n * parses the file; later queries reuse that snapshot. {@link TodoTxtClient.all}\n * always reads fresh contents and replaces the cache, so it can be used to\n * refresh after the underlying file changes.\n *\n * Every line is parsed into a {@link TodoRecord} when the cache is populated.\n * Filters such as {@link TodoQuery.pending} and {@link TodoQuery.project}\n * operate on that array of JSON records, and plucks such as\n * {@link TodoQuery.projects} return unique, alphabetically sorted names.\n * Returned records are copies, so callers may mutate them without affecting the\n * cache.\n */\nexport function createTodoTxt(options: TodoClientOptions): TodoTxtClient {\n let cache: TodoRecord[] | undefined;\n let inFlight: Promise<TodoRecord[]> | undefined;\n let generation = 0;\n\n const logger = options.logger;\n\n const log: TodoLogger = (level, message, meta) => {\n if (!logger) {\n return;\n }\n\n try {\n const result = logger(level, message, meta);\n\n if (\n result &&\n typeof (result as PromiseLike<unknown>).then === \"function\"\n ) {\n void Promise.resolve(result).catch(() => {});\n }\n } catch {\n // Logging is best-effort and must never break reads or queries.\n }\n };\n\n const readFresh = async (): Promise<TodoRecord[]> => {\n const currentGeneration = ++generation;\n\n log(\"debug\", \"Reading todo file\");\n const contents = await options.read();\n const records = parseDocument(contents, {\n includeSource: options.includeSource,\n onWarning: (warning) => {\n log(\"warn\", warning.message, {\n ...warning.meta,\n code: warning.code,\n line: warning.line,\n });\n },\n });\n log(\"debug\", \"Parsed todo file\", { records: records.length });\n\n if (currentGeneration === generation) {\n cache = records;\n }\n\n return records;\n };\n\n const refresh = (): Promise<TodoRecord[]> => {\n const promise = readFresh();\n inFlight = promise;\n\n void promise\n .finally(() => {\n if (inFlight === promise) {\n inFlight = undefined;\n }\n })\n .catch(() => {});\n\n return promise;\n };\n\n const loadCached = (): Promise<TodoRecord[]> => {\n if (inFlight) {\n return inFlight;\n }\n\n if (cache) {\n return Promise.resolve(cache);\n }\n\n return refresh();\n };\n\n const all = async (): Promise<TodoRecord[]> =>\n cloneRecords(await refresh());\n\n const query = createTodoQuery(loadCached);\n\n return {\n all,\n pending: query.pending,\n completed: query.completed,\n project: query.project,\n context: query.context,\n projects: query.projects,\n contexts: query.contexts,\n };\n}\n"],"mappings":";;AAGA,SAAgB,YAAY,MAA8B;CACxD,MAAM,OAAmB;EACvB,WAAW,KAAK;EAChB,UAAU,KAAK;EACf,aAAa,KAAK;EAClB,WAAW,KAAK;EAChB,aAAa,KAAK;EAClB,UAAU,CAAC,GAAG,KAAK,QAAQ;EAC3B,UAAU,CAAC,GAAG,KAAK,QAAQ;EAC3B,MAAM,EAAE,GAAG,KAAK,KAAK;CACvB;CAEA,IAAI,KAAK,SAAS,KAAA,GAChB,KAAK,OAAO,KAAK;CAGnB,IAAI,KAAK,QAAQ,KAAA,GACf,KAAK,MAAM,KAAK;CAGlB,OAAO;AACT;;AAGA,SAAgB,aAAa,SAA8C;CACzE,OAAO,QAAQ,IAAI,WAAW;AAChC;;AC7BA,MAAM,qBAAqB;AAC3B,MAAM,gBAAgB;CAAC;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;AAAE;AAErE,SAAS,WAAW,MAAuB;CACzC,OAAQ,OAAO,MAAM,KAAK,OA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