-
Notifications
You must be signed in to change notification settings - Fork 26
feat: Simplify JS Client public API #257
Conversation
|
@coder11 @folex @boneyard93501 @alari @evgenyponomarev @meph import { createClient } from '@fluencelabs/js-client.api';
// If it's possible I would like not to have a separate getClient method and get the client by default
const client = await createClient({
// ALL the options are inside one argument object and ALL options should be optional
// with random `kras` address being used by default
// the new property could be
autoConnect: true // which is true by default
// also we can add a property that I think would be used a lot
relays: 'kras' | 'testnet' | 'stage' | Array<MultiaddrString | Multiaddr>
// like in fluence cli this would select random peer from network or from array of multiaddrs
})
// I would like not to force users to write switch statements.
// do users really need 'connecting' and 'disconnecting' states?
// I think just having promises would be enough. While promise is not resolved you know - it's connecting
// when it is resolved - you know it's connected
// but if some other, different states are anticipated in the future I would rather have separate
client.onSomeState(() => {
// do something
})
export interface IFluenceClient {
/**
* Connect to the Fluence network
*/
connect(): Promise<void>;
/**
* Disconnect from the Fluence network
*/
disconnect(): Promise<void>;
/**
* Peers secret key as byte array.
*/
secretKey: Uint8Array; // does it have to be a method instead of just being a property? why Uint8Array is default?
/**
* Peers public key as a base58 string (multihash/CIDv0).
*/
id: string; // the same question here and why base58 string
}
// also I don't understand dangerouslyCreateClient
// I don't know what's the danger, it's not clear. We should strive not to have any danger in our api
// I don't really like such kind of naming when you make something available but also discourage using it at the same time. If it's possible I would avoid it |
|
Agree with @shamsartem on |
|
I think let's rename I think we need to reconsider the whole JS Client API with Fluence CLI and weak-coupled Aqua API in mind. At the moment, we don't have time for good design session, so let's postpone it and use what Pavel has already implemented. Except |
|
I would not approve what is currently implemented. Sorry I just don't like it, I hope something similar to my solution would be really fast to implement and we can stop on that instead of breaking stuff in order to break it again when we have more time to think |
|
We had a discussion together and decided to make some changes:
|
|
@coder11 After Denver would be cool to think about something similar to this to remove implicitness // in some js file/module if top-level await is working
import { createClient } from '@fluencelabs/js-client.api';
import { aquaFunction, aquaService } from './compiledAqua.js'
export const client = await createClient({
register: [
aquaService({
someMethod() {
return 1
}
}),
// this call registers function on client. arg is optional and all options are optional (as in current implementation)
aquaFunction({ ttl: 5000 }),
]
})
// in another js file/module
import { client } from './fluenceClient.js'
const result = await client.functions.aquaFunction()
// for vanilla js without ESM and if we wanna have it global
createClient().then((fl) => {
window.fl = fl
}) |
New API looks like this:
The interface for JS Client is the following:
And last but not least: there is now a function for additional clients in the same page \ nodejs process: