@manifoldxyz/service-client-lib
v0.0.1-beta.21
Published
Base Client lib for making service requests
Downloads
907
Keywords
Readme
@manifoldxyz/service-client-lib
Base client lib for all manifold server requests
Usage
Extend BaseClient for any service client.
BaseModule
To group functionality together:
- Create a new class that extends
BaseModule. This gives access to any functionality on your service client. - In your extended
BaseClientclass,declarethe module names and types. - When instantiating your extended
BaseClientclass, pass in the <name, ModuleClass> mapping to thesuperconstructor.- This instantiates the module classes and attaches them to the client instance for you.
Now you can access the module methods on the client instance.
// step 1
class MyModule extends BaseModule {
public async getMyData(): Promise<MyData> {
return this.baseClient.get('/my-data');
}
public async createMyData(data: MyData): Promise<MyData> {
return this.baseClient.post('/my-data', data);
}
public async getName(): Promise<string> {
return this.baseClient.get('/my-data/name');
}
}
const ServiceModules = {
myModule: MyModule,
}
export class MyServiceClient extends BaseClient {
// step 2: you need to `declare` the property for typescript type-safety.
// you can declare without readonly and it'll still be readonly
public declare readonly myModule: MyModule;
constructor() {
// step 3
super('https://my-service.com', undefined, 1000, ServiceModules);
}
}Features
- Manifold eslint/prettier
- Husky precommit lint staged files and test
- vitest w/coverage
@path aliasimport { gm } from '@/gm'- ci github workflow
- pr github workflow
- build badge workflow
Commands
npm run test # run the test suite
npm run test:watch # run the test suite in watch
npm run build # build the library in ./dist
npm run format # run prettier on the filesReleasing
- [Only required one time] Uncomment the final block in
.github/workflows/ci.yml - Bump the version in package.json in a PR
- Merge it
- Any merge or commit to main with an updated package number will trigger a release to npm and github
