← Asynchronous resources

Resource.OptimisticChange

luastra/resource

Resource.OptimisticChange is an exported, statically checked data contract of luastra/resource. Its exact declaration documents the fields or alternatives accepted at the module boundary and is erased after Luau analysis.

Before you use it

Add luastra/resource to this module's dependencies in luastra.json, then import it with require("luastra/resource"). Create each controller once outside app.render. Record the exact ticket returned by begin, correlate it with the host RequestId, and settle only that ticket from app.resolve or another admitted completion boundary.

How it fits

Resource types describe read and mutation states, immutable snapshots, generation tickets, optimistic callbacks, and application-owned errors.

When to use it

Use Resource.OptimisticChange when annotating values that cross the public luastra/resource boundary or when exporting helpers built on that module. The type documents the exact checked shape and prevents unrelated tables from being substituted accidentally.

Fields or definition

ParameterType / valuesDescription
apply() -> ()Callable apply member exposed by Resource.OptimisticChange; invoke it through the owning contract rather than replacing internal state.
rollback() -> ()Callable rollback member exposed by Resource.OptimisticChange; invoke it through the owning contract rather than replacing internal state.

What happens next

A checked resource-state annotation for one explicit asynchronous workflow.

Failures and fixes

Invalid options and programmer contract violations fail immediately. A stale ticket returns false without overwriting current state. Translate provider failures to bounded Resource.Error codes and keep raw messages, payloads, tokens, and credentials outside the controller.

Availability

Public-source alpha state API in 0.5.0-alpha; host-independent and designed to compose with any asynchronous capability.

Exact declaration

export type OptimisticChange = {
    apply: () -> (),
    rollback: () -> (),
}

Complete inventory

View all pages in Asynchronous resources
← Previous: Resource.ReadStateNext: Resource.MutationOptions →