-
Notifications
You must be signed in to change notification settings - Fork 56
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
Allow web5.connect to work with a custom UserAgent #949
Comments
Are you asking to bubble up web5-js/packages/user-agent/src/user-agent.ts Lines 151 to 155 in bfa0417
Examples
const agent0 = await Web5UserAgent.create({ dataPath: 'DATA/AGENT_0' });
const agent1 = await Web5UserAgent.create({ dataPath: 'DATA/AGENT_1' });
const agent0 = await Web5UserAgent.create({ dataPath: 'DATA_0/AGENT' });
const agent1 = await Web5UserAgent.create({ dataPath: 'DATA_1/AGENT' });
const dataPath0 = 'DATA/AGENT_0';
const store0 = new LevelStore<string, string>({ location: `${dataPath0}/VAULT_STORE` });
const agentVault0 = new HdIdentityVault({ store: store0 });
const agent0 = await Web5UserAgent.create({ dataPath: dataPath0 });
const dataPath1 = 'DATA/AGENT_1';
const store1 = new LevelStore<string, string>({ location: `${dataPath1}/VAULT_STORE` });
const agentVault1 = new HdIdentityVault({ store: store1 });
const agent1 = await Web5UserAgent.create({ dataPath: dataPath1, agentVault: agentVault1 }); Example 3 is redundant / unneeded if you don't want to pass your own custom vault because the web5-js/packages/user-agent/src/user-agent.ts Lines 157 to 160 in bfa0417
However, if you want to pass your own custom vault, Example 3 is how you would do it. |
Yes, just make it easier for consumers of the library to supple it, without having to replicate some of the logic within the |
@sondreb I understand. Makes sense. Obv I can't speak for the web5-js dev team, but speaking for myself, if I were them, I'd want to avoid overloading web5-js/packages/api/src/web5.ts Lines 253 to 264 in bd1cb00
But maybe adding it to one of the current args objects would solve your problem and keep the interface intact. For example, the export type DidCreateOptions = {
/** Override default dwnEndpoints provided during DID creation. */
dwnEndpoints?: string[];
agentDataPath?: string; // Pass a custom dataPath down to Web5UserAgent.create and new HdIdentityVault
} This small change would keep the Example implementation const connection0 = await Web5.connect({
password: 'password0',
didCreateOptions: { agentDataPath: 'USER0_DATA/AGENT' } // or whatever you want
});
const connection1 = await Web5.connect({
password: 'password1',
didCreateOptions: { agentDataPath: 'DATA/USER_AGENT_1' }
}); From personal experience, this will move faster if you take the initiative to write the code and submit a PR :) Happy to collab with you on it in Discord if you want. Just lmk. |
Thanks for the reply @bnonni, though the connect function is already implemented using a structured parameter and doesn't require additional connect overloads. JavaScript doesn't support function overloading; your point would be valid if it was using basic arguments. It's not a good alternative to put it on Should be fairly easy to make a PR for this, you could give it a go if you want to, and I'll review and help? |
@sondreb Sorry, I misused the term overload. I simply meant, that this method has a lot of args already, and that can make the interface messy and confusing leading to bad dev experience, unexpected user behavior and/or unexpected use cases resulting in frustration. My comment was more of an intuition-based suggestion from a code design standpoint, less of a recommendation. That intuition comes from the fact that the Regardless, I'll let you take lead on it. Feel free to ping me if you'd like review and help. |
@sondreb If we let you pass your own userAgent into the method would that solve this for you? I think it would be the most elegant solution here. Then you can add whatever optionality / params to your UserAgent that you want. It would also be healthier for the codebase since it would eliminate the |
Maybe it would be enough, at least making it a little bit easier than it is now. Thanks! |
dataPath
to be provided for Web5.connect
@sondreb open for PRs until someone else gets to it if it's a priority for you. otherwise one of myself or @LiranCohen could eventually solve. |
I'll give this a shot today. |
Note: @shamilovtim's Additions
Users want to be able to provide custom optionality to the UserAgent used by Web5.connect
We should be able to do this without bloating the params and argument drilling all of the params through multiple methods
Therefore we could allow users to pass a custom Web5 User Agent in order to solve this problem
This should eliminate the
agentVault
paramFor example, to add
dataPath
as a parameter for Web5.connect() method. The dataPath should be forwarded to this request within theconnect
method:const userAgent = await Web5UserAgent.create({ agentVault });
If this
create
method is provided withdataPath
, it could be possible to have separate databases locally on the same app.The text was updated successfully, but these errors were encountered: