Closed juni-b-queer closed 4 months ago
Thought for the type factories
Classes of the same name, and change types to interfaces(maybe?), for example
class JetstreamMessage implements JetstreamMessageInterface extends [name for an abstract type class] {
// class variables, matches interface
constructor(args){
//set values
}
static factory(): JetstreamMessageFactory {
return new JetstreamMessageFactory()
}
static find({searchArgs}): JetstreamMessage {
// api calls to find the given record and return it as JetstreamMessage
}
// getters/setters for variables
}
class JetstreamMessageFactory implements JetstreamMessageInterface extends AbstractMessageFactory {
did(messageDid: string): JetstreamMessageFactory {
this.did = messageDid;
return this;
}
// other methods for properties
create(): JetstreamMessage {
// convert back to JetstreamMessage
}
}
I'll be doing a combination of both the simple and complex idea. I've already completed Handlers, Actions, and Validators. in #44 and #45
Finished with #51 #45 #44
It would be really helpful for test writing and even use in code to have factory methods on all of the major classes and types that are frequently used.
Low complexity idea
Add a static
make
to handlers, actions, and validators Instead ofnew CreateSkeetHandler(args)
it would beCreateSkeetHandler.make(args)
It doesn't change a lot, and both ways would still work, but to me it feels cleaner, and would be easy to for making mocks in tests.For types, it would be similar, and I'd have to create a factory for each type, but most of the parameters are null able and could be auto filled
CreateSkeetMessageFactory.make(args)
It'd have args for each attribute.More complex idea
Specifically for Types, this could cut down test size by probably 50% In addition to the
make
method, For jetstream messages, it could have chaining methods that allow for adding optional parameters.JetstreamMessage.make().isCreate().isLike().fromDid(did).toDid(did)
so on and so forth. This would be similar for subjects, replies, records, and any other types.I also want to add these chaining methods to Validators so I could do
InputEqualsValidator.make("input").not()
to negate the validation.