API revisions

Guards

A change of meaning has no shape to declare; read the revision of the request instead.

When a value keeps its shape but changes its meaning, there is nothing to declare: read the revision of the rendering.

'sessions' => $this->many(
    LessonSessionResource::class,
    fn() => ApiRevision::current()->isAtMost(ApiRevision::Labels)
        ? $this->resource->sessions
        : $this->resource->sessions->where('user_id', $request->user()?->id),
),

ApiRevision::current() is the revision of the request, anywhere: a resource, with(), additional(), a controller.

MethodTrue when the current revision is
isAtMost(X)X or older
isAtLeast(X)X or newer
isBefore(X)older than X
isAfter(X)newer than X

ApiRevision::using($revision, fn() => …) renders at another revision.

A guard is for a change of meaning. A change of shape (a name, a type, a field that appears) is declared on the field with was(), since() or until(), so that the definitions, the validation and the documentation of each revision know it.