fix: correct GetProperty bug, init to use .ax/, add default aliases, split e2e tests, add due date tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-02 01:58:48 +02:00
parent 5969a2591c
commit 921f4913f8
13 changed files with 1121 additions and 971 deletions
+37 -2
View File
@@ -1,15 +1,48 @@
package models
import (
"encoding/json"
"fmt"
"slices"
"strings"
"time"
)
// Date is a date-only time value that marshals as "YYYY-MM-DD" in JSON.
type Date struct{ time.Time }
// ParseDate parses a date string in "YYYY-MM-DD" or RFC3339 format.
func ParseDate(s string) (Date, error) {
for _, layout := range []string{"2006-01-02", time.RFC3339} {
if t, err := time.Parse(layout, s); err == nil {
return Date{t.UTC()}, nil
}
}
return Date{}, fmt.Errorf("cannot parse date %q: expected YYYY-MM-DD", s)
}
func (d Date) MarshalJSON() ([]byte, error) {
return json.Marshal(d.Format("2006-01-02"))
}
func (d *Date) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
parsed, err := ParseDate(s)
if err != nil {
return err
}
*d = parsed
return nil
}
type Node struct {
ID string `json:"id"`
Title string `json:"title"`
Content string `json:"content,omitempty"`
DueDate string `json:"due_date,omitempty"`
DueDate *Date `json:"due_date,omitempty"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Tags []string `json:"tags,omitempty"`
@@ -85,7 +118,9 @@ func (n *Node) RemoveRelation(relType RelType, target string) {
func (n *Node) GetProperty(k string) string {
prefix := "_" + k + "::"
for _, t := range n.Tags {
return strings.TrimPrefix(t, prefix)
if strings.HasPrefix(t, prefix) {
return strings.TrimPrefix(t, prefix)
}
}
return ""
}