feat: add timestamp fields to picker API entries#24
Conversation
Add created_at and updated_at to all API entry tables (get_memos, get_memos_by_tag, get_memos_for_link) for picker sorting support. - parse_date_to_timestamp: extract epoch time from YYYYMMDD_HHMMSS filenames - get_file_mtime: read file modification time via vim.uv.fs_stat - Document Picker API in vim help (doc/sm.txt)
There was a problem hiding this comment.
Pull request overview
This PR extends the picker-facing API entries with created_at and updated_at timestamps to support picker-side sorting, and updates tests/docs accordingly.
Changes:
- Add timestamp extraction (
created_atfrom filename,updated_atfrom filesystem mtime) to memo metadata. - Thread
created_at/updated_atthrough picker API entry tables and update API/memo tests. - Document the Picker API entry schema in
doc/sm.txt.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
fnl/sm/memo.fnl |
Adds timestamp helpers and includes created_at/updated_at in get_memo_info. |
fnl/sm/api.fnl |
Adds timestamps to picker entry tables returned by API list functions. |
fnl/sm/memo_test.fnl |
Adds tests for date parsing + timestamp fields; stubs vim.uv.fs_stat. |
fnl/sm/api_test.fnl |
Updates API mocks/assertions to include timestamp fields. |
lua/sm/memo.lua |
Generated Lua reflecting new timestamp logic in memo module. |
lua/sm/api.lua |
Generated Lua reflecting new timestamp fields in API entries. |
lua/sm/memo_test.lua |
Generated Lua reflecting updated memo tests/mocks. |
lua/sm/api_test.lua |
Generated Lua reflecting updated API tests/mocks. |
doc/sm.txt |
Adds a “Picker API” help section documenting entry fields including timestamps. |
.gitignore |
Adds .macot (appears unrelated to PR goal). |
| (os.time {:year (tonumber year) | ||
| :month (tonumber month) | ||
| :day (tonumber day) | ||
| :hour (tonumber hour) | ||
| :min (tonumber min) | ||
| :sec (tonumber sec)}))))) |
There was a problem hiding this comment.
parse_date_to_timestamp will accept any 6 numeric components that match the pattern, but os.time normalizes out-of-range values (e.g. month=13, hour=99) instead of failing. That means clearly-invalid filenames could produce a non-nil created_at that is incorrect. Consider validating ranges (and ideally round-tripping with os.date to ensure the resulting fields match the parsed fields) and returning nil when the date/time is not a real YYYYMMDD_HHMMSS.
| (os.time {:year (tonumber year) | |
| :month (tonumber month) | |
| :day (tonumber day) | |
| :hour (tonumber hour) | |
| :min (tonumber min) | |
| :sec (tonumber sec)}))))) | |
| (let [year-num (tonumber year) | |
| month-num (tonumber month) | |
| day-num (tonumber day) | |
| hour-num (tonumber hour) | |
| min-num (tonumber min) | |
| sec-num (tonumber sec)] | |
| ;; Basic range validation to avoid obvious invalid dates/times | |
| (when (and year-num | |
| month-num (>= month-num 1) (<= month-num 12) | |
| day-num (>= day-num 1) (<= day-num 31) | |
| hour-num (>= hour-num 0) (<= hour-num 23) | |
| min-num (>= min-num 0) (<= min-num 59) | |
| sec-num (>= sec-num 0) (<= sec-num 59)) | |
| (let [ts (os.time {:year year-num | |
| :month month-num | |
| :day day-num | |
| :hour hour-num | |
| :min min-num | |
| :sec sec-num})] | |
| ;; Round-trip via os.date to ensure os.time didn't normalize | |
| (when ts | |
| (let [t (os.date "*t" ts)] | |
| (when (and (= t.year year-num) | |
| (= t.month month-num) | |
| (= t.day day-num) | |
| (= t.hour hour-num) | |
| (= t.min min-num) | |
| (= t.sec sec-num)) | |
| ts))))))))) |
| created_at (parse_date_to_timestamp date_part) | ||
| updated_at (get_file_mtime filepath)] |
There was a problem hiding this comment.
get_memo_info now calls uv.fs_stat (via get_file_mtime) for every memo, which adds a synchronous filesystem stat per entry. For large memo collections this can noticeably slow picker population. Consider making updated_at optional/lazy (computed in the picker integration layer only when needed), or caching stat results during a single listing call to avoid repeated stats.
Add created_at and updated_at to all API entry tables (get_memos, get_memos_by_tag, get_memos_for_link) for picker sorting support.
Summary
Brief description of the changes in this PR.
Related Issue
Fixes #
Type of Change
Checklist
maketo regenerate Lua filesmake testand all tests passTesting
Describe how you tested your changes:
Screenshots (if applicable)
Add screenshots to help explain your changes.