| 1 | package tinygit |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "github.com/FelineStateMachine/tinyrelay/internal/gitstore" |
| 7 | "github.com/FelineStateMachine/tinyrelay/protocol/nostr" |
| 8 | ) |
| 9 | |
| 10 | var _ Store = (*gitstore.Store)(nil) |
| 11 | |
| 12 | // Store is the persistence contract required by GitRelay. Implementations may |
| 13 | // use any durable or in-memory representation of Nostr events. The caller |
| 14 | // owns the store; New never closes it. |
| 15 | type Store interface { |
| 16 | // Query returns matching events by descending timestamp, then ascending ID, |
| 17 | // excluding expired, hidden and pending events without applying reader ACLs. |
| 18 | // now is the Unix expiry cutoff. A positive limit caps the result; f.Limit |
| 19 | // can impose a smaller cap. With neither limit, all matches are returned. |
| 20 | Query(context.Context, nostr.Filter, int64, int) ([]Event, error) |
| 21 | // Save durably records e using now for storage timestamps. Duplicate events |
| 22 | // return ErrDuplicate. |
| 23 | Save(context.Context, Event, int64) error |
| 24 | // Latest returns the newest addressable event for kind, pubkey and d. |
| 25 | // Ties use the lowest event ID. This includes expired, hidden and pending |
| 26 | // rows so recovery can check durable state independently of read visibility. |
| 27 | Latest(context.Context, int, string, string) (Event, bool, error) |
| 28 | // Exists reports whether id is present with the requested kind. |
| 29 | Exists(context.Context, string, int) (bool, error) |
| 30 | // Close releases resources owned by the store. |
| 31 | Close() error |
| 32 | } |
| 33 | |
| 34 | // ErrDuplicate indicates that an event was already persisted. |
| 35 | var ErrDuplicate = gitstore.ErrDuplicate |
| 36 | |
| 37 | // OpenStore opens the standard SQLite event schema behind the public Store |
| 38 | // contract. The caller owns the returned store and must close it. |
| 39 | func OpenStore(ctx context.Context, path string) (Store, error) { return gitstore.Open(ctx, path) } |