OxL Reference

fn publishCondOf

publishOf for a topic whose policy has conditions: bits = bit 0 an allow condition holds, bit 1 a deny condition holds (computed by the generated code, TopicSema.cpp, D-7790).

Example:

oxl✓ checked in CI
use std.rpc { asScoped }

data Ev {
  userId: str
  amount: i64
}

topic Evs: Ev sharded by .userId

// a condition of a rule can look at the key, the element and the caller
policy Evs {
  allow publish if caller.isUser(key) && element.amount <= 100
  deny publish if element.amount < 0
}

cluster demo {
  role store { journal }
}

fn user(id: str) -> Principal {
  Principal.User(id, [], Map.new(), false, none)
}

fn tryPublish(e: Ev) -> str io, db {
  match Evs.publish(e) {
    TopicError _ => "denied"
    _ => "ok"
  }
}

fn main() io, db {
  asScoped(user("a")) {
    print("{tryPublish(Ev{ userId: "a", amount: 5 })} {tryPublish(Ev{ userId: "a", amount: 500 })} {tryPublish(Ev{ userId: "b", amount: 5 })}")
  }
}
Output
ok denied denied
pub(api) fn publishCondOf<T: Serializable>(h: i64, x: &T, key: bytes, bits: i64) -> () | TopicError  db

Since. 1.0.0-beta

Parameters

NameType
hi64
x&T
keybytes
bitsi64

Returns

()

Errors

  • TopicError @error
  • `TopicError` as for `publishOf`; `AccessDenied` when a condition of the policy refuses the publication.

Effects

db

Defined in: std/topic/topic.oxl:262

See also