LatestNov 18, 2026
3.0.0
3.0: API revisions, Stripe-style, and typed values built on ark4ne/laravel-api-revisions 1.0
(docs/rfc/api-revisions-integration.md). Changes are listed against 2.0.0: 2.1.0 was never released.
Added
- API revisions (
docs/site/4.revisions/;docs/architecture.md): each client is pinned on a dated revision of the API, and a resource declares only what changed. A revision is a case of an enum implementingArk4ne\ApiRevisions\Revisions\Revision(revisions.enum), ordered byorder(), the last one being the head; the revision of a request is resolved by therevisionmiddleware ofark4ne/laravel-api-revisions(config/revisions.php), an unknown value is answered with 400, and guards readApiRevision::current(). ->was(R, name:, schema:, down:),->since(R)and->until(R)ofark4ne/laravel-api-revisionson every descriptor: what a field was up to a revision (its name, its shape, the conversion of its value), and the revisions it exists at, bounds included. A relationship to another resource at an old revision is->was(R, schema: $this->one(OldResource::class)). The links of a resource hold no history.#[Definition\JsonApiSince(R)]and#[Definition\JsonApiUntil(R)]on a resource: the type exists from, or up to, a revision;Definitions::lifetime($class)gives itsDefinition\Lifetime. Rendering a resource at a revision it does not exist at, as the primary data or through a relationship without awas()to the resource of that revision, throwsRenderingException::notInRevision()before anything is written.- A resource is rendered at the revision of its request: its attributes, meta, relationships (names, include paths, related resources, cardinality) and links are those of that revision, its sparse fieldsets are read in the names of that revision, and its eager loads are planned at it, in batch.
ResourceDefinition::$revision,$since,$untiland$fieldNames(the names of the code mapped to those of the revision), withrevision(),lifetime(),existsAt()andfieldNames().Definitions::exists($class, $revision), and a$revisiononDefinitions::compile()andDefinitions::loadConstraints().new Includes($resource, $maxDepth, $revision)andnew Fields($resource, $revision)validate the query of a client against its revision, by the names at it;revision()returns it, for the tools.JsonApiFormRequestvalidatesincludeandfieldsat the revision of the request.jsonapi:check --revision=Labelschecks only the shape of that revision;Diagnostic::$revisionnames the revision a diagnostic was found at (Diagnostic::describe(),Diagnostic::key()).ResourceAssertions::assertValid($class, $strict, $revision),assertValidAtEveryRevision($class, $strict)anddefinitionAt($class, $revision)(the head without revision), for snapshot tests of the contract of each revision.Support\Memo: pure memos of what only depends on the code, flushed by the service provider after every Octane request, task and tick.composer benchmarkalso measures resources declaring revisions, at the head and at older revisions.ark4ne/laravel-api-revisions^1.0is required;JsonApiServiceProviderregisters its provider.Context\CurrentRevision::of($configuration): the revision a rendering or a validation is made at, the current one ofark4ne/laravel-api-revisions;null, the head, for an application without revision enum.Configuration::$revisionsandwithRevisions(): the revision enum of the application, given by the service provider fromrevisions.enum.JsonApiContext::fromRequest()takes an optional$revision, for a context built at a given revision.Descriptors\Schemas\DecimalSchema,JsonSchemaandMixedSchema: the types this package adds to those ofark4ne/laravel-api-revisions, registered by the service provider asSchema::decimal(),Schema::json()andSchema::mixed()(Descriptors\Schemas\SchemaTypes). A value they refuse is a value error of the base.Descriptors\Schemas\FloatSchema, returned by$this->float(): the float ofark4ne/laravel-api-revisions(Kind::Float: same values accepted, same conversions, same export) withprecision()andtruncate(), as in 2.0. The value is rounded before its conversion to an older revision;describer.precisionis its default.Descriptors\Schemas\RelationshipSchema(Schema::relationship($this->one(…))): a relation as a field of the base, which gives it its history; a custom typejsonapi.relationshipwhose fragment names the cardinality and the related resources, converted to itself (a relationship to another resource at an old revision is->was(R, schema: Schema::relationship(…))).relationAt($field)gives the relation in force at a revision. A relationship of another resource is held too:Schema::relationship(CommentResource::relationship(fn() => …)). Its conditions (->when(fn($model) => …)) are read for each resource: the relationship is left out when one fails.applyWhen()groups descriptors ofark4ne/laravel-api-revisionstoo: each member takes the condition as a->when(), attributes and relationships alike.$this->whenInFields($request, 'name', $descriptor)and$this->whenInIncludes($request, 'posts', $descriptor)take a descriptor ofark4ne/laravel-api-revisionsand give it the condition, read where each resource is rendered (the includes of its place in the document).->whenNotNull()and->whenFilled()on every descriptor ofark4ne/laravel-api-revisions(Descriptors\Schemas\Conditions, macros registered by the service provider),->unless()being the one of the base;->whenNotNull()and->whenFilled()read the source (its key, or its closure) before the value, as in 2.0.->whenInFields(): the attribute is rendered only when the sparse fieldset names it, in its name at the revision (sparse in the definition).->whenAppended(?string $attribute = null): only when the model appends the accessor the descriptor reads, or the one named.JsonApiResourceimplementsRevisionedandHasLifetimeofark4ne/laravel-api-revisions(Resources\Concerns\DeclaresSchema): a resource whosetoAttributes(),toResourceMeta()andtoDocumentMeta()return descriptors of the base is compiled, cached, checked, locked and exported by it, as one response holding the objectsattributes,metaanddocumentMeta;#[JsonApiSince]/#[JsonApiUntil]give its lifetime.- The values of such a resource are rendered by
ark4ne/laravel-api-revisions(Rendering\ResourcePlan): its hooks run once per response on a template instance, the sparse fieldset is read in the names of the revision and a field it leaves out is never evaluated.JsonApiContextcarries theCompilation\Projection(the shapes and the projector of the application,Definitions::projectWith()/projection()) and aContext\ResponseCache. - A
JsonApiFormRequestmay use theRevisionedRequestofark4ne/laravel-api-revisions: itsbody()is validated in the shape of the client's revision andjsonApi()reads the head's. Http\Body: the body of a JSON:API write request as descriptors, for thebody()of such a request.Body::resource($resource, attributes: […], relationships: […], id: …)declaresdata.type(the type the resource renders),data.id,data.attributesanddata.relationships;Body::toOne(UserResource::class)andBody::toMany('tags', 'labels')declare a relationship object and the types its linkage accepts. AJsonApiFormRequestwrites$this->resourceObject(attributes: …, relationships: …).Http\Rules\Linkage: a relationship object sent holds itsdata, which may benullor an empty list (jsonapi::validation.linkage.missing).Compilation\ResourceCheck, tagged in the check ofark4ne/laravel-api-revisions(revision:check,assertRevisionsAreConsistent()): at each revision, an attribute or a relationship namedidortype(jsonapi-reserved-name), an attribute and a relationship sharing a name (jsonapi-name-collision), a relationship to a resource that does not exist there (jsonapi-absent-resource).- A sparse fieldset naming the members of an object (
fields[users]=address.city) or of the objects of a list (fields[users]=tags.name) of a resource declared on the base keeps them in its projection plan: a member left out is never read nor converted. At a revision where awas(schema:)is in force, the members are those of its schema, inResourceDefinition::fields()(theFieldsrule) as in the plan, the value being converted whole. Rendering\ProjectedValues: the members aResourcePlanrendered, which theValueResolvergives as they are.Definitions::for($class, $revision)gives the attributes, the meta and the document meta of such a resource from its shape at the revision (names, types, nullability, presence), and itsfieldNames:Fields,Includesand the tools read the names of the revision. Without revision, the newest one of the application.- The relationships of such a resource are declared with
Schema::relationship(): its declaration holds arelationshipsobject, and the definition, the include validation, the eager-loads and the rendering read their names and the relation in force from the shape of the revision. $this->struct([...], $source),$this->arrayOf($items, $source),$this->enum(State::class, $source): the helpers of an object, a typed list and an enum.- A closure as a member of a hook of values is a value of any type (
'name' => fn() => …). Definitions::head()andDefinitionCompiler::head(): the newest revision of the application;DefinitionCompiler::compileEvery()gives the definition of the head and of every older revision the resource exists at.- Diagnostic
invalid-declaration: the values of a resource cannot be compiled at the revision of the definition. extension.neon: types those factories and macros for PHPStan, included byphpstan/extension-installeror by hand after the extension ofark4ne/laravel-api-revisions.
Changed
- Breaking: the values of a resource are declared and rendered with
ark4ne/laravel-api-revisions.$this->string(),$this->integer(),$this->date()… return its descriptors (StringSchema,IntSchema,DateSchema…), nullable asdescriber.nullablesays;$this->one(),$this->many(),$this->morph()and$this->morphMany()return aRelationshipSchema, with the modifiers of a relationship (links(),meta(),withLoad(),whenIncluded(),filters(),can()…). A closure given to a helper still receives the model. - Breaking:
toAttributes(),toRelationships(),toResourceMeta()andtoDocumentMeta()run once per response, on a template whose$this->resourceis set to each model before its values are read. A member is a descriptor or a closure under its name: a plain value, a member without name, Laravel's$this->when()/$this->mergeWhen()are refused (DefinitionException). The default attributes and the links stay plain values. - Breaking: a condition is a closure read for each resource:
->when(Closure($model, $attribute)),->unless(Closure), run before the value is read (a value whose condition fails is never computed, as in 2.0),applyWhen(Closure, array);$this->whenInFields()and$this->whenInIncludes()take a descriptor or a closure and return a descriptor. - Breaking:
enum()takes the class of a backed enum;struct()takes an array of members;array()->of()isarrayOf();time(),uuid()andulid()are a date-time and strings with a format. - Breaking: a value its type refuses is a value error of
ark4ne/laravel-api-revisions(revisions.strict_values); the format of a date and time isrevisions.date_time_format. - Breaking: a type of the application is a descriptor registered in the
TypeRegistryofark4ne/laravel-api-revisions, served by$this->money(). - Breaking:
Definitions::for($class, $revision)gives one definition per revision (itsrevisionis the one asked,nullfor the head, the newest revision), built from the shape of the base; it throws when the values of the resource cannot be compiled.Definitions::compile()andjsonapi:checkreport it as a diagnostic. - Breaking: the values of a definition are the model of
ark4ne/laravel-api-revisions:ResourceDefinition::$attributes,$metaand$documentMetaare theShapes of the resource at the revision (nullwhere it has none),attribute($name)theFieldDefinitionof that name at the revision;$linksis the list of the names of the links;$sparseandisSparse()name the attributes rendered only when requested.values()andsparse()replaceattributes(),meta()anddocumentMeta().Definition\AttributeDefinitionandDefinition\ValueTypeare removed. - Breaking: the compiled file (
jsonapi:cache) holds the definitions without their shapes, given back on the firstDefinitions::for()from those of the base; a file written by another version is ignored. - With the compiled files of
jsonapi:cacheandrevision:cache, no hook of a resource runs on a probe: the constraints of its loads are read from its hooks only when its definition declares one (withLoad()with a closure). - Breaking:
jsonapi:checkandResourceAssertionsrun the check ofark4ne/laravel-api-revisionson the resources (Compilation\ResourceChecker): the history of their fields and its conversions are checked again, with the codes of the base (conversion-missing,definition-error…), and the rules of JSON:API are those ofCompilation\ResourceCheck.reserved-namebecomesjsonapi-reserved-name, names its field under its object (attributes.title,relationships.author) and is no longer inResourceDefinition::$diagnostics, which keepsinvalid-declarationandhook-failure; a class that is not a resource is the findinginvalid-resource. The definitions are compiled at every revision the resource exists at: a finding of an older revision names it.jsonapi:checkruns theCheckerthe container binds (that ofrevision:check: its checks, those the application tags withRevisionsServiceProvider::CHECKS, the lock) on the resources checked only (Checker::forClasses()): a locked class outside them is not reported as gone.ResourceCheckertakes thatChecker. - Breaking:
jsonapi:cachewrites one definition per resource and revision;jsonapi:checkchecks each revision the resource exists at and leaves the history of the fields torevision:check. make:jsonapi-resourcewrites$this->enum(State::class).composer benchmarkrenders the resources ofbin/benchmark/Package/with this package and those ofbin/benchmark/Legacy/(the API of 1.9) with 1.9.
Removed
- Breaking:
Descriptors\Values\*and the traitDescriptors\Values,Descriptors\ValueTypes,JsonApi::valueType(),Descriptors\Members,MergeWhenValue, and the diagnosticseager-attribute,merge-when,unnamed-memberandinvalid-member. - Breaking:
toDefinition()(a definition written by hand), the overrides ofwhen(),whenHas(),merge()andmergeWhen()on a resource. - Breaking: the configuration keys
describer.datetime,describer.strictanddescriber.types: still set, they throw anInvalidConfigurationExceptionnaming what replaces them. - Breaking:
DefinitionCompiler::EAGER_ATTRIBUTE,MERGE_WHEN,UNNAMED_MEMBER,INVALID_MEMBERandRESERVED_NAME(nowCompilation\ResourceCheck::RESERVED_NAME,jsonapi-reserved-name).