add method

JsonMap add(
  1. FakeWorld world, {
  2. required String action,
  3. String decision = 'allow',
  4. String? actor,
  5. String? denyReason,
  6. String? resourceKind,
  7. String? resourceId,
  8. JsonMap details = const {},
  9. DateTime? at,
  10. String? correlationId,
})

Appends a row and returns it; the hash links it to the row before.

at defaults to the world's clock; details defaults to an empty object; correlationId (from nextCorrelationId) defaults to an ID of this row alone.

Implementation

JsonMap add(
  FakeWorld world, {
  required String action,
  String decision = 'allow',
  String? actor,
  String? denyReason,
  String? resourceKind,
  String? resourceId,
  JsonMap details = const {},
  DateTime? at,
  String? correlationId,
}) {
  final prev = rows.isEmpty ? auditGenesisHash : rows.last['hash']! as String;
  final row = <String, Object?>{
    'seq': rows.length + 1,
    'id': world.nextId(),
    'occurred_at': world.stamp(at),
    'actor_principal_id': ?actor,
    'action': action,
    'decision': decision,
    'deny_reason': ?denyReason,
    'resource_kind': ?resourceKind,
    'resource_id': ?resourceId,
    'details': details,
    'correlation_id': correlationId ?? _correlationId(rows.length + 1),
    'prev_hash': prev,
  };
  row['hash'] = hashOf(row);
  rows.add(row);
  return row;
}