Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What should the API look like? #26

Open
christianbundy opened this issue Sep 8, 2020 · 2 comments
Open

What should the API look like? #26

christianbundy opened this issue Sep 8, 2020 · 2 comments

Comments

@christianbundy
Copy link
Contributor

I've experienced lots of confusion working with SSB-Validate, and have often found myself wondering how it should be build.

For example, some methods mutate state but others don't, forcing you to read the API docs and sometimes mutate state... or be careful because SSB-Validate is going to mutate state without your permission.

Before

const validate = require("ssb-validate");
let state = validate.initial()
validate.append(state, hmacKey, message); // Mutates state
validate.append(state, hmacKey, message2); // Mutates state
validate.append(state, hmacKey, message3); // Mutates state

writeToDatabase(state).then(() => {
  state.queue = []
});

After

Maybe something like:

const validate = require("ssb-validate");

// Internally managed `state` and `hmacKey`.
const validator = validate.createValidator({ state: previousState, hmacKey });

// Simple append.
validator.append(message);

// Simple batch support.
validate.append(message2, message3);

// Internally managed `state.queue`.
validator.flush((messages) => {
  return writeToDatabase(messages);
});
@davegomez
Copy link

@christianbundy, when I first read the ssb-validate API, my first thought was, why is it a responsibility of the validator to append and write to the database the validated messages?

Shouldn't it be the user's responsibility to determine how to gather and store the messages?

@arj03
Copy link
Member

arj03 commented Sep 9, 2020

Looks good @christianbundy. I've also noticed that the state.queue = [] feels really icky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants