Resolvers

Resolvers (also called property pipelines) are bindings declared on Property definitions that transform property values on the write and read paths. @write resolvers run before storage. @read resolvers run before the response is sent to the client. Resolvers can be written in Sessel or JavaScript.

When to reach for it

Use a resolver when a stored value should be normalised before it reaches storage (trim whitespace, lowercase an email, compute a slug) or transformed before it reaches the reader (format a timestamp, enrich a value with a lookup, compute a derived field).

Shape

A resolver is a typed microdata item with itemprop="@write" or itemprop="@read", placed inside a Property definition. The itemtype selects the binding. Use https://pagelove.org/Sessel/Lambda for the Sessel scalar transformations below. Bare https://pagelove.org/Sessel on @read is the separate computed-property form; see Property.

Sessel resolver

This span-based example uses the same write binding exercised in Transforming data:

<div itemprop="property" itemscope itemtype="https://pagelove.org/Property">
  <meta itemprop="name" content="slug">
  <meta itemprop="type" content="https://schema.host/Text">
  <meta itemprop="cardinality" content="1..1">
  <div itemprop="@write" itemscope itemtype="https://pagelove.org/Sessel/Lambda">
    <script itemprop="source" type="text/sessel">
      self.map((el) => new span[id="slug"][itemprop="slug"] { el.text().trim().lower() })
    </script>
  </div>
</div>

It returns replacement elements with the same property name. The fixed ID is for the guide's single-item document. It trims and lowercases text; it does not implement general slugification.

JavaScript resolver

<div itemprop="property" itemscope itemtype="https://pagelove.org/Property">
  <meta itemprop="name" content="email">
  <meta itemprop="type" content="https://schema.host/Text">
  <meta itemprop="cardinality" content="1..1">
  <div itemprop="@write" itemscope itemtype="https://pagelove.org/JavaScript/Module">
    <script itemprop="source" type="module">
      export default (val) => typeof val === 'string' ? val.trim().toLowerCase() : val;
    </script>
  </div>
</div>

The pipeline value

In both @read and @write bindings, the binding receives the property value as its primary input:

When each hook runs

Hook Runs Effect
@write On the inspected normal serving write pipeline, in the resolver phase after the initial schema-validation phase and before persistence. Transform values on supported write paths; do not assume validation sees the transformed result. In the tested whole-document PUT, a write transform stored uppercase text after a lowercase-only validator accepted its original input.
@read After the value is fetched from storage, before it is sent to the client. Format or enrich values.

The inspected pipeline injects defaults before its initial validation checks, then runs the write-resolver phase. Additional checks depend on the operation and storage path. Do not rely on @write to repair input that those earlier checks would refuse, or assume every resolver result is revalidated by the same checks afterward. In the tested required-property fixture, a text/plain selector update returned 422 and left storage unchanged; a full HTML span update returned 206 and was normalized. WebDAV kept the original mixed-case value. These paths are not interchangeable. Verify the method, representation and target used by the application.

Inheritance ordering

When a schema uses inheritance, resolvers from the entire chain form a sequence. The output of one step becomes self for the next. Schemas without a resolver for a given property are skipped.

Hook Order Rationale
@write Child-first (leaf → root) The child normalises before the parent applies broader rules.
@read Ancestor-first (root → leaf) The parent provides a base transformation; the child refines it.

Example with chain [Entity, Person, Employee]:

Cross-document queries

Cross-document enrichment needs its own tested query, missing-target behavior and returned element shape. The earlier example used an unverified mutation helper and has been withdrawn. For an executable starting point, use the complete read/write transformation, then verify the lookup separately before adding it to a resolver. This page does not certify a cross-document enrichment example.

Mixed-language chaining

Pipeline chains can mix Sessel and JavaScript across the inheritance hierarchy. A parent schema may declare a Sessel @read and a child schema may declare a JavaScript @read; both fire in ancestor-first order, with the Sessel stage's output feeding the JavaScript stage's input.

Examples

Normalise text on write (Sessel)

The Sessel resolver above stored my-project from My-Project in the tested application whole-document PUT. The how-to guide includes the full schema, input and authoring/application readback.

Trim whitespace on write (JavaScript)

<div itemprop="@write" itemscope itemtype="https://pagelove.org/JavaScript/Module">
  <script itemprop="source" type="module">
    export default (val) => typeof val === 'string' ? val.trim() : val;
  </script>
</div>

Uppercase on read (JavaScript)

<div itemprop="@read" itemscope itemtype="https://pagelove.org/JavaScript/Module">
  <script itemprop="source" type="module">
    export default (val) => typeof val === 'string' ? val.toUpperCase() : val;
  </script>
</div>

Uppercase span text on read (Sessel)

Inside the same slug Property, this binding served MY-PROJECT while the stored value was my-project:

<div itemprop="@read" itemscope itemtype="https://pagelove.org/Sessel/Lambda">
  <script itemprop="source" type="text/sessel">
    self.map((el) => new span[id="slug"][itemprop="slug"] { el.text().upper() })
  </script>
</div>

Identity resolver

A resolver that returns self unchanged. Acts as a placeholder in an inheritance chain:

<div itemprop="@read" itemscope itemtype="https://pagelove.org/Sessel/Lambda">
  <script itemprop="source" type="text/sessel">self</script>
</div>

Refusing a write

A @write resolver can refuse a value by throwing an HTTPResponse. In Sessel, declare the schema first. Without the @schema line the thrown value is not an HTTPResponse, and the write fails as an ordinary script error:

<div itemprop="@write" itemscope itemtype="https://pagelove.org/Sessel/Lambda">
  <script itemprop="source" type="text/sessel">
    @schema HTTPResponse url("https://pagelove.org/HTTPResponse");
    self.map((el) => el.attr("content").matches("^[A-Z]{1,2}[0-9]")
      ? el
      : throw new HTTPResponse { status: 422, message: "That is not a valid postcode" })
  </script>
</div>

Name the status and the message as properties, as above. The positional form new HTTPResponse(422, "...") does not set them. The JavaScript form is in JavaScript bindings.

Saving from a resolver

A @write resolver can save other pages with Pagelove.PUT, POST or DELETE. Each save runs the write pipeline for that page, so a resolver that saves an item of its own type would run itself again. Three saves, each running inside the previous one, are allowed. A fourth save fails, the resolver sees a failed save, and, unless the resolver catches it, the request ends with an error response. See Saves inside saves for the detail.

Error cases

Condition Result
Expression fails to compile The step is skipped. No transform runs for this property on this schema.
Expression returns something other than an element or list of elements The write or read request fails.
Expression throws at runtime The write or read request fails.
A @write expression throws an HTTPResponse with an error status (400 to 599) That status and your message, in either language. The request's own write is not stored.
A @write expression throws an HTTPResponse with no status, or any other status 422 with an https://pagelove.org/SchemaViolation document. It holds one https://pagelove.org/BindingFailure describing the throw, and it does not name the property. The request's own write is not stored.
The database fails while a resolver reads from it The request fails with a 5xx status, not a validation failure: 504 if the read ran out of the database's time limit, 500 if a stored document is damaged, otherwise 503.
A resolver uses a password hash that the server is too busy to run, and does not catch the refusal The read or write request fails with 503 and a Retry-After: 1 header, not a validation failure. On a write, the request's own write is not stored.
Expression returns an empty list The property is effectively removed from the output.

Resolver errors on the write path cause the HTTP request to fail before the write reaches storage. Pages a @write resolver already saved with Pagelove.PUT, POST or DELETE before it failed are kept. Resolver errors on the read path cause the GET request to fail.

See also