Scaffold backend gateway and integration docs
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import 'package:relationship_saver/core/network/backend_exception.dart';
|
||||
import 'package:relationship_saver/integrations/backend/models/backend_models.dart';
|
||||
|
||||
/// Validation rules for outgoing sync envelopes.
|
||||
class SyncEnvelopeValidator {
|
||||
SyncEnvelopeValidator._();
|
||||
|
||||
/// Validates a list of changes before a push call.
|
||||
static void validateAll(List<ChangeEnvelope> changes) {
|
||||
for (final ChangeEnvelope change in changes) {
|
||||
validate(change);
|
||||
}
|
||||
}
|
||||
|
||||
/// Validates one change envelope.
|
||||
static void validate(ChangeEnvelope change) {
|
||||
if (change.schemaVersion <= 0) {
|
||||
throw ValidationException(
|
||||
'schemaVersion must be > 0 for ${change.clientMutationId}',
|
||||
);
|
||||
}
|
||||
|
||||
if (change.op == ChangeOperation.delete && change.payload != null) {
|
||||
throw ValidationException(
|
||||
'payload must be null for delete operation (${change.clientMutationId})',
|
||||
);
|
||||
}
|
||||
|
||||
if (change.op == ChangeOperation.upsert && change.payload == null) {
|
||||
throw ValidationException(
|
||||
'payload is required for upsert operation (${change.clientMutationId})',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user