:default-sort type attribute
Plan: default-sort-plan.md.
Type-level key declaring the sort used when a request sends none:
:todos (:type-roles ("logged-in")
:default-sort (:points :desc)
...)
Crucial for the video: the app opens showing each list in its best
order (Model Bank by rating, todos by points) with no user action.
Today the default is hardcoded: order by <table>.id on base types
(phase-a-build-order-by), first-sortable-measure :desc on
rollups (measure-default-sort). Neither is author-controllable.
Shape:
- Type-level plist
(:field :asc|:desc); direction optional (default:asc). Applies to the main list view. - Compile-time validation: field must exist and be
:sortable t(same rule the request path enforces viaphase-a-order-by-column/valid-measure-sort); report-e on a non-sortable or unknown field. - Base path:
be-list/base-be-listuse it when the request sort is nil.phase-a-build-order-byalready appends the table-qualified PK as tiebreaker, so paging stays stable. No declaration keeps today's id-ASC behavior. - Rollup path: wins over
measure-default-sort's first-sortable-measure policy.measure-effective-sortmust echo it so the:sortreflection stays honest. - Frontend: free. Initial load already renders from the
:sortecho; a declared default just shows up without the frontend asking.
Related but separate: "Regular-type computed-field sort" (MVP
Backlog) is about making :agg fields sortable at all;
:default-sort only names already-sortable fields.
Completed (2026-08-28, plan revised after Grok's review, resolve
once in be-list, not separately in both branches):
lisp/model.lisp: newvalid-default-sort(shape 1–2 elements, keyword first, direction:asc=/:desc=, field exists and:sortable t, allreport-e);:default-sortpasses verbatim into both compiled type-defs beside:tree;preliminary-model-checkgained an unconditional walker arm above theu:plistparm so(:points :desc)is not recursed into.lisp/backend.lisp:be-listbinds the effective sort(or sort (tree-get ... :default-sort))ahead of the base/measure dispatch; one docstring sentence, one stale comment fix, onemeasure-default-sortdocstring reword.base-be-list,measure-be-list,measure-default-sortcode untouched, the rollup path rides the request-sort validation (valid-measure-sort) and echo (measure-effective-sort) for free.- Fixture
models/test/default-sort-test.lisp(:items / :items-plain / :board / :board-plain), suitetests/default-sort-tests.lisp(26 checks: compile happy + rejection, base + rollup behavior, absence regressions),run-default-sort-testshelper, asd registered. Fullrun-tests: 1488 checks green. - Demos:
todos(:points :desc),modelbank:models(:name :asc);:hot-modelsleft undeclared (policy already correct; keeps absence visible in the demo). - Docs:
model-reference.md(type-key row, rollup sort bullet, response-:sortbullets, list-queries paragraph, key index),rest.mdGET /api/listsort note.
One test-authoring lesson: "id-ASC" on base types is UUID order,
not insertion order; the absence-regression test compares against
the table's actual order by id sequence, not the seed order.
- Slot
- 26600
- Status
- 60 Done
- Tags
- mvp, backend, model, compiler
- Contributors
- Donnie