Skip to content

v3.6.0

Latest

Choose a tag to compare

@GautierDele GautierDele released this 21 Nov 11:15
ddca2d5

A minor release of 3.x: extensions, search engine lists, search totals and stricter engine searches. Upgrade with composer update lomkit/laravel-rest-api, then read the 3.6 section of the upgrade guide, starting with its "check these first" list.

Check these first

3.6 removes two public methods, removes the French lines and changes seven behaviours. The upgrade guide details each one.

  • Removed: ActionTransaction::aroundRun() and ActionTransaction::handle().
  • Removed: the French lines. The package ships its client messages in English only. To keep French, publish the lines before upgrading with php artisan vendor:publish --tag=rest-lang, delete the published en copy, and add the 9 keys new in 3.6, all in validation.
    • With a fallback_locale other than en, a missing line shows the key itself.
  • Typesense:
    • typesenseSearchParameters() may no longer return a parameter that the package sends itself;
    • sortable() and tieBreaker() refuse id;
    • every search sends filter_curated_hits: true.
  • Algolia: every search sends enableRules: false.
  • search.source is a reserved key of the search body.
  • A search text without a letter or digit (*, %, _) matches no row. A blank text still returns the list.
  • A value refused by the engine inside an instruction answers 422 under search.instructions.N instead of a 500.

Extensions

One class adds behaviour to every resource. It declares its name() and implements one or more kinds:

final class QuotaExtension extends Extension implements GuardsWrites
{
    public static function name(): string
    {
        return 'quota';
    }

    public function guardWrite(WriteGuardContext $context): void
    {
        $context->refuse('The monthly quota is reached.', 429);
    }
}
  • Registering and disabling: list the classes in rest.extensions, or call Rest::registerExtension() from a package. Disable one in rest.disabled_extensions.
  • The kinds:
    • queries: RestrictsQueries, AugmentsQueries, NarrowsLimits, DeclaresInstructions;
    • search engines: RestrictsEngineQueries, DeclaresIndexAttributes, ProvidesEngineProfiles;
    • authorization: prepared and versioned row checks, cache context, gates, NarrowsFields;
    • routes and writes: AddsRouteMiddleware, GuardsWrites, ObservesWrites, ObservesReads;
    • responses and checks: AddsSearchMeta, AddsDetailsMeta, DocumentsExtension, ChecksResources.
  • rest:check lists every extension and checks each one.

Search engines

  • Lists on the engine, on request. ScoutEngine::servesLists() lets a list run on the engine when the body sends "source": "engine". A list sent without source stays the normal SQL search.
    • Engine lists have a stable descending order, and tieBreaker() names the attribute that settles ties.
    • Pages trust the engine and report dropped and total_capped.
  • ScoutEngine::indexAttributes() declares server-only index attributes, string lists included, for the perimeter, the restrictions and the instructions.
  • Groups. whereAny() groups conditions for extensions and instructions. Engine searches accept "type": "or" and nested filters on Typesense, Meilisearch, Turbopuffer and the Scout drivers. A repeated whereIn() on a string list means AND.
  • Long Typesense searches above 3,500 characters go through /multi_search automatically.
  • Curated and promoted hits stay inside the filter on Typesense and Algolia.
  • lazy() now reads engine searches: a text, or "source": "engine". The keys are read at the call, and the call throws before streaming in two cases:
    • EngineWindowException, beyond the engine window;
    • EngineResultsChangedException, when the results change while the keys are read.

Search totals

A search can ask for totals over every matching row, returned in a root totals key next to total:

{"search": {"filters": [{"field": "client_id", "value": 42}],
  "totals": {"measures": [{"type": "sum", "field": "amount"}], "groups": [{"field": "status"}]}}}
"total": 143,
"totals": {"exact": true, "all": {"count": 143, "sum_amount": 187340.5},
  "groups": [{"field": "status", "buckets": [{"value": "paid", "count": 96}, {"value": "invoiced", "count": 31}, {"value": "pending", "count": 16}],
    "other": {"count": 0}, "truncated": false}]}
  • Declaring what may be totalled: groupable() and measurable() on fields, and ScoutEngine::groupable() / measurable() for engines.
  • Measures: sum, avg, min, max.
  • Backends: SQL, Typesense, Meilisearch, Algolia, Turbopuffer and the Scout drivers, with one request shape for all of them.
  • Exactness: a figure is never shown as exact unless it is.
    • A group cut at its limit says truncated, and Σ buckets + other = all.count = total.
    • An engine that cannot count exactly refuses, with a 422 or an EngineSearchException.
  • Decimals: measures on engines that store decimals with limited precision are rounded to the model's decimal:N cast.

Other changes

  • Search texts without a letter or digit match nothing. ResolvedText::matchesNothing() and TextQuery::termless() tell app code.
  • The CI runs the Algolia integration against a live application.

Documentation: https://laravel-rest-api.lomkit.com