One store per action
An action writes to at most one store, counting the public actions it calls. It may read other stores, but those reads are outside its transaction. A read that decides a write (a policy, lifecycle or invariant check) must come from the store being written.
Across stores there are no joins, filters or ordering. An include reaches
another store only to fetch records by id.
Moving an entity to another store can break an action that never names
it, so the error names the cause:
store.action_spans_stores
points at the write or the call that brings in the second store.
At run time, an action's transaction is begun in the store its first store
operation names. Reading another store outside the transaction isn't
built yet. For now, an action that reads a second store, itself or through
an action it calls, is toolchain.not_built_yet at the read or call that
brings it in, rather than failing as it runs:
use ordering/entities { Order, Product, ProductNotFound }action order_product(product_id: Product.id) fails ProductNotFound -> Order { var product: Product = attempt Product.get(product_id) return Order.create { set: { product_name: product.name } }}
error: Reading a second store in `order_product` isn't built yet --> domains/ordering/actions/order_product.jadpo:4:36 |4 | var product: Product = attempt Product.get(product_id) | ^^^^^^^^^^^^^^^^^^^^^^^ store `catalogue` reason: An action may read another store outside its transaction (area 6), but this compiler runs all of an action's store operations in the one transaction its first begins; `order_product` uses `Order` (store `main`), and here it reads `Product` (store `catalogue`). next: Read `Product` before `order_product` runs, and pass in what it needs, for now (agent) rule: toolchain.not_built_yet help: https://jadpo.dev/docs/errors/toolchain.not_built_yetcheck failed: 1 error, 5 files
Markdown for agents: /docs/one-store-per-action.md.Built from Jadpo main at a707efb.