publish method

FreedomeEvent publish(
  1. String topic,
  2. String kind, {
  3. Object? resource,
  4. Map<String, Object?>? patch,
  5. int? revision,
})

Publishes an event (full resource or merge patch).

Implementation

FreedomeEvent publish(
  String topic,
  String kind, {
  Object? resource,
  Map<String, Object?>? patch,
  int? revision,
}) {
  final e = FreedomeEvent(
    id: uuidV7(),
    topic: topic,
    seq: ++_seq,
    kind: kind,
    ts: clock.now().toUtc(),
    resource: resource,
    patch: patch,
    revision: revision,
    data: {
      'seq': _seq,
      'kind': kind,
      'resource': ?resource,
      'patch': ?patch,
      'revision': ?revision,
    },
  );
  _ring.addLast(e);
  while (_ring.length > capacity) {
    _ring.removeFirst();
  }
  for (final s in List.of(_sessions)) {
    s.deliver(e);
  }
  final a = alias?.call(topic);
  if (a != null && a != topic) {
    publish(a, kind, resource: resource, patch: patch, revision: revision);
  }
  return e;
}