Skip to content

Commit 0ab9c4a

Browse files
authored
Add listMachineFragments (#394)
1 parent e729080 commit 0ab9c4a

File tree

2 files changed

+53
-7
lines changed

2 files changed

+53
-7
lines changed

src/app/app-client.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,35 @@ describe('AppClient tests', () => {
12561256
});
12571257
});
12581258

1259+
describe('listMachineFragment tests', () => {
1260+
let request: pb.ListMachineFragmentsRequest;
1261+
const response = [fragment];
1262+
beforeEach(() => {
1263+
mockTransport = createRouterTransport(({ service }) => {
1264+
service(AppService, {
1265+
listMachineFragments: (req) => {
1266+
request = req;
1267+
return new pb.ListMachineFragmentsResponse({
1268+
fragments: response,
1269+
});
1270+
},
1271+
});
1272+
});
1273+
});
1274+
1275+
it('listMachineFragments', async () => {
1276+
const machineId = 'MACHINE_ID';
1277+
const additionalFragmentIds = ['FRAGMENT ID 1', 'FRAGMENT ID 2'];
1278+
const resp = await subject().listMachineFragments(
1279+
machineId,
1280+
additionalFragmentIds
1281+
);
1282+
expect(request.machineId).toEqual(machineId);
1283+
expect(request.additionalFragmentIds).toEqual(additionalFragmentIds);
1284+
expect(resp).toEqual(response);
1285+
});
1286+
});
1287+
12591288
describe('addRole tests', () => {
12601289
const expectedRequest = new pb.AddRoleRequest({
12611290
authorization,

src/app/app-client.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import type { Struct } from '@bufbuild/protobuf';
2-
import {
3-
createPromiseClient,
4-
type PromiseClient,
5-
type Transport,
6-
} from '@connectrpc/connect';
2+
import { createClient, type Client, type Transport } from '@connectrpc/connect';
73
import { PackageType } from '../gen/app/packages/v1/packages_pb';
84
import { AppService } from '../gen/app/v1/app_connect';
95
import {
@@ -114,10 +110,10 @@ export const createPermission = (
114110
};
115111

116112
export class AppClient {
117-
private client: PromiseClient<typeof AppService>;
113+
private client: Client<typeof AppService>;
118114

119115
constructor(transport: Transport) {
120-
this.client = createPromiseClient(AppService, transport);
116+
this.client = createClient(AppService, transport);
121117
}
122118

123119
/**
@@ -827,6 +823,27 @@ export class AppClient {
827823
await this.client.deleteFragment({ id });
828824
}
829825

826+
/**
827+
* @param machineId The machine ID used to filter fragments defined in a
828+
* machine's parts. Also returns any fragments nested within the fragments
829+
* defined in parts.
830+
* @param additionalFragmentIds Additional fragment IDs to append to the
831+
* response. Useful when needing to view fragments that will be
832+
* provisionally added to the machine alongside existing fragments.
833+
* @returns The list of top level and nested fragments for a machine, as well
834+
* as additionally specified fragment IDs.
835+
*/
836+
async listMachineFragments(
837+
machineId: string,
838+
additionalFragmentIds?: string[]
839+
): Promise<Fragment[]> {
840+
const resp = await this.client.listMachineFragments({
841+
machineId,
842+
additionalFragmentIds,
843+
});
844+
return resp.fragments;
845+
}
846+
830847
/**
831848
* Add a role under an organization.
832849
*

0 commit comments

Comments
 (0)