Monorepo for Tangled โ€” https://tangled.org

proposal: make models self-validate and remove Validator #324

open
opened by boltless.me

Currently validation logic is done from Validator object. We can make models self-validate themselves.

Below is schema of Validator:

type Validator struct {
	db        *db.DB
	sanitizer markup.Sanitizer
	resolver  *idresolver.Resolver
	enforcer  *rbac.Enforcer
}
  • we don't need db validation because in atproto, the target object might not be ingested yet.
  • we do need to perform sanitizing check, but we can make singleton for these instead. (we are using just markup.NewSanitizer())
  • we don't need did validation because of similar reason. syntax level check is enough.
  • we do need to perform rbac check, but we are already doing it in most places without using centralized Validator object.

Therefore, I think we don't need a struct to group validation dependencies.

Let's ditch most of the dependencies needed to validate the model and just call Issue.Validate() instead.

+1 from me. Makes sense.

agree on self-validation. the reason for moving this out of the model constructor was to be able to validate in several places: upon creation via appview, upon creation via firehose ingestion, upon update via appview and upon update via firehose. if we can structure all these operations as creations, validation will occur inherently.

sign up or login to add to the discussion
Labels

None yet.

area
appview
assignee
boltless.me
Participants 3
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.issue/3m7i45kp53z22