ModelCrudMetadata class

Immutable audit metadata associated with a single record.

This model centralizes who created/updated/deleted a record and when, plus an optional logical version used for optimistic locking or history.

JSON contract:

Timestamps are represented as DateTime and converted using DateUtils.dateTimeFromDynamic and DateUtils.dateTimeToString.

Minimal runnable example:

void main() {
  final ModelCrudMetadata created = ModelCrudMetadata(
    recordId: 'group-001',
    createdBy: 'system@domain.com',
    createdAt: DateTime.utc(2025, 1, 1, 10, 0, 0),
    updatedBy: 'system@domain.com',
    updatedAt: DateTime.utc(2025, 1, 1, 10, 0, 0),
    version: 1,
  );

  final Map<String, dynamic> json = created.toJson();
  final ModelCrudMetadata roundtrip = ModelCrudMetadata.fromJson(json);

  print(roundtrip.recordId); // group-001
  print(roundtrip.createdAt); // DateTime instance
}
Inheritance

Constructors

ModelCrudMetadata({required String recordId, required String createdBy, required DateTime createdAt, required String updatedBy, required DateTime updatedAt, bool? deleted, String? deletedBy, DateTime? deletedAt, int? version})
const
ModelCrudMetadata.fromJson(Map<String, dynamic> json)
Creates a ModelCrudMetadata from a JSON-like map.
factory

Properties

createdAt DateTime
Creation timestamp (ISO 8601 round-trip).
final
createdBy String
Actor (user or system) that created the record.
final
deleted bool?
Soft-delete flag.
final
deletedAt DateTime?
Timestamp when the record was marked as deleted.
final
deletedBy String?
Actor that marked the record as deleted.
final
hashCode int
Gets the hash code for this entity model.
no setteroverride
recordId String
Logical identifier of the record owning this metadata.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
updatedAt DateTime
Last update timestamp.
final
updatedBy String
Actor (user or system) that last updated the record.
final
version int?
Logical version for optimistic locking / history.
final

Methods

copyWith({String? recordId, String? createdBy, DateTime? createdAt, String? updatedBy, DateTime? updatedAt, bool? deleted, bool? deletedOverrideNull()?, String? deletedBy, DateTime? deletedAt, int? version, bool? versionOverrideNull()?}) ModelCrudMetadata
Creates a copy of the entity model.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, dynamic>
Serializes this metadata into a JSON-like map.
override
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
Checks whether the given other object is equal to this entity model.
override

Static Methods

initialize({required String recordId, required String actor, DateTime? timestamp, int initialVersion = 1}) ModelCrudMetadata
Initializes CRUD metadata for a newly created record.
markDeleted({required ModelCrudMetadata current, required String actor, DateTime? timestamp, bool bumpVersion = true}) ModelCrudMetadata
Marks the record as soft-deleted, updating audit metadata.
touchOnUpdate({required ModelCrudMetadata current, required String actor, DateTime? timestamp, bool bumpVersion = true}) ModelCrudMetadata
Updates audit metadata for an existing record on modification.