Skip to content

Commit

Permalink
RSDK-4579: TypeScript SDK Base Properties (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
martha-johnston authored Aug 17, 2023
1 parent 4e3d196 commit 4d26422
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/base.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export type { Base } from './base/base';
export type { Base, BaseProperties } from './base/base';
export { BaseClient } from './base/client';
6 changes: 6 additions & 0 deletions src/components/base/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { Resource, StructType, Vector3 } from '../../types';
import pb from '../../gen/component/base/v1/base_pb';

export type BaseProperties = pb.GetPropertiesResponse.AsObject;

/** Represents a physical base of a robot. */
export interface Base extends Resource {
Expand Down Expand Up @@ -54,4 +57,7 @@ export interface Base extends Resource {

/** Return true if the base is in motion. */
isMoving(extra?: StructType): Promise<boolean>;

/** Return the base's properties. */
getProperties(extra?: StructType): Promise<BaseProperties>;
}
15 changes: 15 additions & 0 deletions src/components/base/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,19 @@ export class BaseClient implements Base {
const { baseService } = this;
return doCommandFromClient(baseService, this.name, command, this.options);
}

async getProperties(extra = {}) {
const { baseService } = this;
const request = new pb.GetPropertiesRequest();
request.setName(this.name);
request.setExtra(Struct.fromJavaScript(extra));

this.options.requestLogger?.(request);

const response = await promisify<
pb.GetPropertiesRequest,
pb.GetPropertiesResponse
>(baseService.getProperties.bind(baseService), request);
return response.toObject();
}
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export { type Arm, ArmClient } from './components/arm';
* @group Raw Protobufs
*/
export { default as baseApi } from './gen/component/base/v1/base_pb';
export { type Base, BaseClient } from './components/base';
export { type Base, type BaseProperties, BaseClient } from './components/base';

/**
* Raw Protobuf interfaces for a Board component.
Expand Down

0 comments on commit 4d26422

Please sign in to comment.