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

Proposed simplification of users APIs #157

Merged
merged 4 commits into from May 19, 2020
Merged

Conversation

carsonfarmer
Copy link
Member

@andrewxhill, here's a proposed simplified workflow for you. I'll make comments inline, please let me know what you think.

@carsonfarmer carsonfarmer added the enhancement New feature or request label May 12, 2020
@carsonfarmer carsonfarmer added this to the Sprint 36 milestone May 12, 2020
@carsonfarmer carsonfarmer self-assigned this May 12, 2020
src/users.ts Outdated Show resolved Hide resolved
src/buckets.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/users.spec.ts Show resolved Hide resolved
src/users.spec.ts Show resolved Hide resolved
src/users.ts Outdated Show resolved Hide resolved
Signed-off-by: Carson Farmer <carson.farmer@gmail.com>
Signed-off-by: Carson Farmer <carson.farmer@gmail.com>
Signed-off-by: Carson Farmer <carson.farmer@gmail.com>
}).timeout(3000)

it('should then create a db for the bucket', async function () {
await users.newDB(ThreadID.fromRandom(), users.context.withThreadName('my-buckets'))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be cleaned up slightly

transport: context.transport,
debug: context.debug,
})
// Module augmentation to add methods to Peer from core
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty cool, we essentially extend the Client interface on the fly here, and then the implementations follow

*/
Client.prototype.getThread = async function (name: string, ctx?: Context) {
logger.debug('get thread request')
const client = new APIClient(this.serviceHost, {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we're 'piggy backing' off of threads client, we create out own client here each time, but use all the options and settings from threads client.

}

export { Client }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exported for convinience, but these new methods should exist even if we import and let side-effects take over

Signed-off-by: Carson Farmer <carson.farmer@gmail.com>
@carsonfarmer
Copy link
Member Author

With these changes, if you do:

import { Client, Buckets } from '@textile/textile`

you essentially have all the hub-based APIs you'd want. This PR augments Client with User API methods getThread and listThreads, so developers can more easily manage threads without having to interact with a whole new set of APIs, or the low level Network Client APIs.

If they aren't using Buckets, they could also do:

import '@textile/textile` and still get the augmented Client with the Users APIs, as this code also provides side-effects to augment the Client.

@andrewxhill andrewxhill added this to Reviewer approved in Textile via automation May 19, 2020
@carsonfarmer carsonfarmer merged commit 0d32ea2 into master May 19, 2020
Textile automation moved this from Reviewer approved to Done May 19, 2020
@carsonfarmer carsonfarmer deleted the carson/simpler-users branch May 19, 2020 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Textile
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants