docs: update cards, README, CLAUDE.md for list pagination & ListEntry

- store.md: update Store interface (ListEntry[], ListOptions params, remove stale delete())
- variable.md: add sorting & pagination section
- README.md: add --sort/--limit/--offset/--desc flags
- CLAUDE.md: add ListOptions, ListEntry types and list-utils reference

Refs #27
This commit is contained in:
2026-06-01 15:14:53 +00:00
parent 22b5474a77
commit 5463b44554
4 changed files with 29 additions and 4 deletions
+15 -4
View File
@@ -16,14 +16,25 @@ type Store = {
put(typeHash: Hash, payload: unknown): Promise<Hash>;
get(hash: Hash): CasNode | null;
has(hash: Hash): boolean;
delete(hash: Hash): void;
listAll(): Hash[];
listByType(typeHash: Hash): Hash[];
listMeta(): Hash[];
listSchemas(): Hash[];
listByType(typeHash: Hash, options?: ListOptions): ListEntry[];
listMeta(options?: ListOptions): ListEntry[];
listSchemas(options?: ListOptions): ListEntry[];
};
```
### ListOptions & ListEntry
List methods accept optional `ListOptions` for sorting and pagination:
```typescript
type ListSort = "created" | "updated";
type ListOptions = { sort?: ListSort; desc?: boolean; limit?: number; offset?: number };
type ListEntry = { hash: Hash; created: number; updated: number };
```
When `limit` is `undefined`, all results are returned (no cap). The [[CLI]] defaults `limit` to 100.
`put()` computes the [[Content Addressing|hash]] from `{ type, payload }`, validates the payload against its [[Schema]], and stores the [[Content Addressing|node]]. If a node with the same hash already exists, it's a no-op — content addressing gives deduplication for free.
## Implementations
+4
View File
@@ -67,6 +67,10 @@ Every variable tracks its last `MAX_HISTORY` (default 10) values with LRU rotati
ocas var history <name> [--schema <hash-or-name>] # show history, [0] = current
```
## Sorting & Pagination
`var list` and `var history` support the common list flags: `--sort created|updated`, `--limit`, `--offset`, `--desc`. The CLI defaults `--limit` to 100; the core layer returns all results when `limit` is omitted.
## Role in Garbage Collection
Variables are the **roots** of [[Garbage Collection]]. Any node reachable from a variable's value hash (via [[Schema|ocas_ref]] edges) is kept alive; unreachable nodes are swept.
+6
View File
@@ -60,6 +60,12 @@ bun run format # Biome format (auto-fix)
- `CasNode` — content-addressed node with schema
- `Store` — abstract storage interface (get/put)
- `VariableStore` — SQLite-backed mutable bindings (name → hash)
- `ListOptions` — sorting/pagination options (`sort`, `desc`, `limit`, `offset`)
- `ListEntry` — list result entry (`hash`, `created`, `updated`)
### List Utilities
`packages/core/src/list-utils.ts` provides `applyListOptions()` — in-memory sort/paginate for `ListEntry[]` arrays. Used by `MemoryStore`; `FsStore` pushes sort/limit to SQLite. Core layer treats `limit: undefined` as "no limit"; the CLI defaults to 100 in `parseListOptions()`.
### Architecture Notes
+4
View File
@@ -131,6 +131,10 @@ Flags:
--home <path> Store directory (default: $OCAS_HOME or ~/.ocas)
--json Compact JSON output
--pipe, -p Read a { type, value } envelope from stdin for render
--sort <key> Sort key: created|updated (default: created)
--limit <n> Max results (default: 100)
--offset <n> Skip first N results (default: 0)
--desc Sort descending (default: ascending)
```
### Variable names