AbstractAuto-wired services.
One name, bound by this module's own blueprint, so the container resolves it like any other service and this constructor reads it plainly. That is the whole point: a dependency read off a container that never bound it is not optional, it throws, which is what made every container-resolved resource fail. The answer was to register the checker, not to test for its presence.
One name and no more, because destructuring reads each one: a resource must not have to know
which services happen to be bound. The violation policy is configuration, and it travels with the
request in the context, from stone.resources.onViolation. Substituting the dialect is a matter
of binding contractChecker yourself.
Project a collection.
Sequential rather than concurrent: data() may reach a database or an API, and a hundred models
turning into a hundred simultaneous calls is a denial of service an application performs on
itself. A resource that wants concurrency batches inside its own data(), where it knows the cost.
The domain models.
The resource context.
The projected collection.
OptionaldataOptional: shape or complete the model before it meets the schema.
A method signature, deliberately, against the repository's own lint rule: a property-typed
function is contravariant on its parameters, so a subclass narrowing the context was rejected, and
TypeScript separately refuses a method where the base declared a property, so
async data (model, context) {} was rejected too. The rule's soundness argument is theoretical for
an extension point; the cost was measured, in an application that could not type its resources.
OptionalfragmentsNamed subsets a caller may ask for. Override to expose fragments.
Project one model.
The order is the design: complete the data, choose the contract the caller asked for, hold the result against it, then narrow. Validation happens before narrowing, so the promise is checked against everything the resource produced rather than against whatever survived a query parameter.
The domain model.
The resource context.
The projected output.
ProtectedprojectHold the data against the contract, and return what the contract describes.
The schema is the projection: its parsed value is the output, so a field the contract does not mention is not exposed, whatever the model gains later.
The completed data.
The contract.
The resource context.
The projected value.
Project into a { data, meta } envelope.
A model or a collection.
The resource context.
Optionalmeta: Record<string, unknown>
Optional metadata (pagination, counts, …).
The envelope.
AbstractschemaThe contract: what this resource exposes.
The resource context.
The schema.
ProtectedschemaThe schema to hold this projection against: the requested fragment when the resource exposes one, the full contract otherwise.
An unknown fragment falls back to the full contract rather than failing. A caller guessing
?view=nonsense is asking a question, not attacking: answering the documented shape is more
useful than a 500, and the fragments a resource exposes are published in the contract anyway.
The resource context.
The schema.
ProtectedwhenProtectedwhenInclude a value only when the relation was requested through context.include.
The resource context.
The relation name.
The value, or a lazy factory (only evaluated when included).
The value, or undefined.
What a resource does: turn a domain model into the shape a caller is allowed to see, and say what that shape is.
Saying it is the point. A projection written as code answers "what does this return?" only by being read and trusted; a projection written as a schema answers it to a person, to
@stone-js/openapi, and to the resource itself, which validates against it before anything leaves. One declaration, three consumers, and no way for the documentation to drift from the response.