A script with a using grant, and one without.

Script

score has no grant. It sees the record it was given and has no db. reconcile may read and write, and the close transition runs it. The functions they export, and the db they call, are the scripting runtime. A body that calls db with no grant is effect/script-grant-missing.

app billing "Billing" {}

script score compute js """
export function compute(ctx) {
  return ctx.record.total;
}
"""

script reconcile action using db read, write js """
export function runAction(ctx) {
  return db.transaction(() => {
    db.from("Note").insert({ invoice: ctx.record_id, body: "Reconciled" });
    return { effects: [{ kind: "refresh" }] };
  });
}
"""

entity Invoice {
  total: number

  workflow {
    initial Open
    states Open, Closed
    terminal Closed

    close: Open -> Closed {
      do run script reconcile
    }
  }
}