S4 page by cursor: a state page continues from an opaque cursor in sequence order
The runtime's mesh/state.page takes the cursor the page before answered as next, so a state is read once however many pages it takes; a key written again since an earlier page comes marked seen-again. Builds: design 47 H2 §779
This commit is contained in:
+7
-6
@@ -25,9 +25,10 @@ func (k KeptSource) Get(key string) (*Entry, bool, error) {
|
||||
return &Entry{Value: e.Value, Revision: e.Revision, Written: e.At}, true, nil
|
||||
}
|
||||
|
||||
// Page is the values after a key in one request (stdio.KeptState.Page), as FirstView prefers them to Get per key.
|
||||
func (k KeptSource) Page(after string, maxBytes int, budget time.Duration) ([]KeyedEntry, string, error) {
|
||||
p, err := k.State.Page(after, maxBytes, budget)
|
||||
// Page is the values after the opaque cursor in one request (stdio.KeptState.Page, in the order the bus wrote them),
|
||||
// as FirstView prefers them to Get per key, and the cursor that continues them.
|
||||
func (k KeptSource) Page(cursor string, maxBytes int, budget time.Duration) ([]KeyedEntry, string, error) {
|
||||
p, err := k.State.Page(cursor, maxBytes, budget)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@@ -61,10 +62,10 @@ func FirstViewTool(owner, name, state, words string, values, marks Source, now f
|
||||
Name: name,
|
||||
Description: fmt.Sprintf("The first view of %s's state %s (novox/hq ADR 0615, ADR 0621): %s Each value whole by key, at the revision "+
|
||||
"the owner said its views family up to, so a reader then follows the events on that family and asks again only on a gap in "+
|
||||
"revisions. One page at a time: next is the key to ask after for the rest.",
|
||||
"revisions. One page at a time: hand next back as after for the rest.",
|
||||
owner, state, words),
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{
|
||||
"after": map[string]any{"type": "string", "description": "the key the page before ended at (its next); none starts at the first"}}},
|
||||
"after": map[string]any{"type": "string", "description": "the next of the page before; none starts at the first"}}},
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
after, _ := args["after"].(string)
|
||||
return FirstView(owner, state, values, marks, strings.TrimSpace(after), now())
|
||||
@@ -87,7 +88,7 @@ func ReadTool(owner, name, state, words string, values, marks Source, now func()
|
||||
"key": map[string]any{"type": "string", "description": "one key: its value and revision"},
|
||||
"history": map[string]any{"type": "boolean", "description": "with key: every value the state keeps for it, oldest first"},
|
||||
"values": map[string]any{"type": "boolean", "description": "a page of values whole by key"},
|
||||
"after": map[string]any{"type": "string", "description": "with values: the key the page before ended at"}}},
|
||||
"after": map[string]any{"type": "string", "description": "with values: the next of the page before"}}},
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
key, _ := args["key"].(string)
|
||||
after, _ := args["after"].(string)
|
||||
|
||||
+7
-5
@@ -174,7 +174,7 @@ func DecodeMark(data []byte) (Mark, error) {
|
||||
}
|
||||
|
||||
// Answer is a first view, or one page of an ordinary read: the state's values by key, from After on, at the revision
|
||||
// of the state the owner said up to (Mark) before it read them; Next is the key to ask after for the rest, empty when
|
||||
// of the state the owner said up to (Mark) before it read them; Next is handed back as after for the rest, empty when
|
||||
// the answer is whole. A reader keeps the first page's revision: a value on a later page may be newer, and the events
|
||||
// after that revision bring every key to its newest in order.
|
||||
type Answer struct {
|
||||
@@ -222,15 +222,17 @@ type KeyedEntry struct {
|
||||
Entry
|
||||
}
|
||||
|
||||
// Pager is a Source that answers many values in one request: the values in key order after a key, as many as fit
|
||||
// maxBytes or the time budget and at least one, and the key to ask after for the rest. FirstView uses it when its source has it, unless
|
||||
// Pager is a Source that answers many values in one request: the values after an opaque cursor (empty: from the
|
||||
// start), as many as fit maxBytes or the time budget and at least one, and the cursor that continues them, empty at
|
||||
// the end (design 47 H2 §779). FirstView uses it when its source has it, unless
|
||||
// it answers errors.Is(err, errors.ErrUnsupported), when it reads per key.
|
||||
type Pager interface {
|
||||
Page(after string, maxBytes int, budget time.Duration) ([]KeyedEntry, string, error)
|
||||
Page(cursor string, maxBytes int, budget time.Duration) ([]KeyedEntry, string, error)
|
||||
}
|
||||
|
||||
// FirstView answers one page of state from its owner's source: the mark first, so no change after the revision it
|
||||
// answers at is missed, then the values in key order after after, until PageBytes or PageBudget. A state not said yet (no mark)
|
||||
// answers at is missed, then the values after after (the next of the page before: the Pager's cursor, or with a source
|
||||
// that reads per key the last key, in key order), until PageBytes or PageBudget. A state not said yet (no mark)
|
||||
// answers revision 0: a first view of whatever it holds, which the reader takes as a gap at the first event.
|
||||
func FirstView(owner, state string, values, marks Source, after string, now time.Time) (Answer, error) {
|
||||
a := Answer{V: Version, Owner: owner, State: state, Values: map[string]json.RawMessage{}, At: now.UTC()}
|
||||
|
||||
Reference in New Issue
Block a user