persist: Phase 1 — log + kv facets on injectable in-memory backend + 28 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m3s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m3s
event/backend/log/kv/api over one injected backend protocol (mem default). log: append/read/read-from, sequential per-stream seq, stream isolation. kv: get/put/delete/has?/keys/get-or/update. conformance.sh + 3 suites, 28/28. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
37
lib/persist/log.sx
Normal file
37
lib/persist/log.sx
Normal file
@@ -0,0 +1,37 @@
|
||||
; persist/log — the log facet: append-only event streams. seq is assigned
|
||||
; sequentially per stream (1-based). Reads return events oldest-first.
|
||||
; Requires: lib/persist/event.sx, lib/persist/backend.sx.
|
||||
|
||||
; current length of a stream
|
||||
(define
|
||||
persist/stream-len
|
||||
(fn (b stream) (len (persist/backend-read b stream))))
|
||||
|
||||
; last seq in a stream (0 if empty)
|
||||
(define persist/last-seq (fn (b stream) (persist/stream-len b stream)))
|
||||
|
||||
; append an event, auto-assigning the next seq. Returns the stored event.
|
||||
(define
|
||||
persist/append
|
||||
(fn
|
||||
(b stream type at data)
|
||||
(let
|
||||
((seq (+ 1 (persist/last-seq b stream))))
|
||||
(let
|
||||
((ev (persist/event stream seq type at data)))
|
||||
(begin (persist/backend-append b stream ev) ev)))))
|
||||
|
||||
; read all events in a stream, oldest-first
|
||||
(define persist/read (fn (b stream) (persist/backend-read b stream)))
|
||||
|
||||
; read events with seq >= from
|
||||
(define
|
||||
persist/read-from
|
||||
(fn
|
||||
(b stream from)
|
||||
(filter
|
||||
(fn (e) (>= (persist/event-seq e) from))
|
||||
(persist/read b stream))))
|
||||
|
||||
; number of events in a stream
|
||||
(define persist/count (fn (b stream) (persist/stream-len b stream)))
|
||||
Reference in New Issue
Block a user