Skip to content

Commit 35c99e0

Browse files
[RSDK-10123] user defined metadata crud apis (#477)
1 parent 6376f1e commit 35c99e0

File tree

2 files changed

+378
-1
lines changed

2 files changed

+378
-1
lines changed

src/app/app-client.spec.ts

+255
Original file line numberDiff line numberDiff line change
@@ -1733,4 +1733,259 @@ describe('AppClient tests', () => {
17331733
expect(response.id).toEqual('id');
17341734
});
17351735
});
1736+
1737+
describe('getOrganizationMetadata', () => {
1738+
beforeEach(() => {
1739+
mockTransport = createRouterTransport(({ service }) => {
1740+
service(AppService, {
1741+
getOrganizationMetadata: () =>
1742+
new pb.GetOrganizationMetadataResponse(),
1743+
});
1744+
});
1745+
});
1746+
1747+
it('returns an empty object if there is no Struct', async () => {
1748+
const response = await subject().getOrganizationMetadata('orgId');
1749+
expect(response).toEqual({});
1750+
});
1751+
1752+
it('preserves the map key when a Struct is found', async () => {
1753+
const testResponse = new pb.GetOrganizationMetadataResponse({
1754+
data: Struct.fromJson({ key1: 'value1' }),
1755+
});
1756+
1757+
mockTransport = createRouterTransport(({ service }) => {
1758+
service(AppService, {
1759+
getOrganizationMetadata: () => testResponse,
1760+
});
1761+
});
1762+
1763+
const response = await subject().getOrganizationMetadata('orgId');
1764+
expect(response).toEqual({ key1: 'value1' });
1765+
});
1766+
});
1767+
1768+
describe('updateOrganizationMetadata', () => {
1769+
let capturedRequest: pb.UpdateOrganizationMetadataRequest;
1770+
1771+
beforeEach(() => {
1772+
mockTransport = createRouterTransport(({ service }) => {
1773+
service(AppService, {
1774+
updateOrganizationMetadata: (req) => {
1775+
capturedRequest = req;
1776+
return new pb.UpdateOrganizationMetadataResponse();
1777+
},
1778+
});
1779+
});
1780+
});
1781+
1782+
it('should handle empty metadata correctly', async () => {
1783+
await subject().updateOrganizationMetadata('orgId', {});
1784+
1785+
expect(capturedRequest).toEqual({
1786+
organizationId: 'orgId',
1787+
data: Struct.fromJson({}),
1788+
});
1789+
});
1790+
1791+
it('should successfully update metadata with valid data', async () => {
1792+
await subject().updateOrganizationMetadata('orgId', { key1: 'value1' });
1793+
1794+
expect(capturedRequest).toEqual({
1795+
organizationId: 'orgId',
1796+
data: Struct.fromJson({ key1: 'value1' }),
1797+
});
1798+
});
1799+
});
1800+
1801+
describe('getLocationMetadata', () => {
1802+
beforeEach(() => {
1803+
mockTransport = createRouterTransport(({ service }) => {
1804+
service(AppService, {
1805+
getLocationMetadata: () => new pb.GetLocationMetadataResponse(),
1806+
});
1807+
});
1808+
});
1809+
1810+
it('returns an empty object if there is no Struct', async () => {
1811+
const response = await subject().getLocationMetadata('orgId');
1812+
expect(response).toEqual({});
1813+
});
1814+
1815+
it('preserves the map key when a Struct is found', async () => {
1816+
const testResponse = new pb.GetLocationMetadataResponse({
1817+
data: Struct.fromJson({ key1: 'value1' }),
1818+
});
1819+
1820+
mockTransport = createRouterTransport(({ service }) => {
1821+
service(AppService, {
1822+
getLocationMetadata: () => testResponse,
1823+
});
1824+
});
1825+
1826+
const response = await subject().getLocationMetadata('orgId');
1827+
expect(response).toEqual({ key1: 'value1' });
1828+
});
1829+
});
1830+
1831+
describe('updateLocationMetadata', () => {
1832+
let capturedRequest: pb.UpdateLocationMetadataResponse;
1833+
1834+
beforeEach(() => {
1835+
mockTransport = createRouterTransport(({ service }) => {
1836+
service(AppService, {
1837+
updateLocationMetadata: (req) => {
1838+
capturedRequest = req;
1839+
return new pb.UpdateLocationMetadataResponse();
1840+
},
1841+
});
1842+
});
1843+
});
1844+
1845+
it('should handle empty metadata correctly', async () => {
1846+
await subject().updateLocationMetadata('locId', {});
1847+
1848+
expect(capturedRequest).toEqual({
1849+
locationId: 'locId',
1850+
data: Struct.fromJson({}),
1851+
});
1852+
});
1853+
1854+
it('should successfully update metadata with valid data', async () => {
1855+
await subject().updateLocationMetadata('locId', { key1: 'value1' });
1856+
1857+
expect(capturedRequest).toEqual({
1858+
locationId: 'locId',
1859+
data: Struct.fromJson({ key1: 'value1' }),
1860+
});
1861+
});
1862+
});
1863+
1864+
describe('getRobotMetadata', () => {
1865+
beforeEach(() => {
1866+
mockTransport = createRouterTransport(({ service }) => {
1867+
service(AppService, {
1868+
getRobotMetadata: () => new pb.GetRobotMetadataResponse(),
1869+
});
1870+
});
1871+
});
1872+
1873+
it('returns an empty object if there is no Struct', async () => {
1874+
const response = await subject().getRobotMetadata('orgId');
1875+
expect(response).toEqual({});
1876+
});
1877+
1878+
it('preserves the map key when a Struct is found', async () => {
1879+
const testResponse = new pb.GetRobotMetadataResponse({
1880+
data: Struct.fromJson({ key1: 'value1' }),
1881+
});
1882+
1883+
mockTransport = createRouterTransport(({ service }) => {
1884+
service(AppService, {
1885+
getRobotMetadata: () => testResponse,
1886+
});
1887+
});
1888+
1889+
const response = await subject().getRobotMetadata('orgId');
1890+
expect(response).toEqual({ key1: 'value1' });
1891+
});
1892+
});
1893+
1894+
describe('updateRobotMetadata', () => {
1895+
let capturedRequest: pb.UpdateRobotMetadataResponse;
1896+
1897+
beforeEach(() => {
1898+
mockTransport = createRouterTransport(({ service }) => {
1899+
service(AppService, {
1900+
updateRobotMetadata: (req) => {
1901+
capturedRequest = req;
1902+
return new pb.UpdateLocationMetadataResponse();
1903+
},
1904+
});
1905+
});
1906+
});
1907+
1908+
it('should handle empty metadata correctly', async () => {
1909+
await subject().updateRobotMetadata('robotId', {});
1910+
1911+
expect(capturedRequest).toEqual({
1912+
id: 'robotId',
1913+
data: Struct.fromJson({}),
1914+
});
1915+
});
1916+
1917+
it('should successfully update metadata with valid data', async () => {
1918+
await subject().updateRobotMetadata('robotId', { key1: 'value1' });
1919+
1920+
expect(capturedRequest).toEqual({
1921+
id: 'robotId',
1922+
data: Struct.fromJson({ key1: 'value1' }),
1923+
});
1924+
});
1925+
});
1926+
1927+
describe('getRobotPartMetadata', () => {
1928+
beforeEach(() => {
1929+
mockTransport = createRouterTransport(({ service }) => {
1930+
service(AppService, {
1931+
getRobotPartMetadata: () => new pb.GetRobotPartMetadataResponse(),
1932+
});
1933+
});
1934+
});
1935+
1936+
it('returns an empty object if there is no Struct', async () => {
1937+
const response = await subject().getRobotPartMetadata('orgId');
1938+
expect(response).toEqual({});
1939+
});
1940+
1941+
it('preserves the map key when a Struct is found', async () => {
1942+
const testResponse = new pb.GetRobotPartMetadataResponse({
1943+
data: Struct.fromJson({ key1: 'value1' }),
1944+
});
1945+
1946+
mockTransport = createRouterTransport(({ service }) => {
1947+
service(AppService, {
1948+
getRobotPartMetadata: () => testResponse,
1949+
});
1950+
});
1951+
1952+
const response = await subject().getRobotPartMetadata('orgId');
1953+
expect(response).toEqual({ key1: 'value1' });
1954+
});
1955+
});
1956+
1957+
describe('updateRobotPartMetadata', () => {
1958+
let capturedRequest: pb.UpdateRobotPartMetadataResponse;
1959+
1960+
beforeEach(() => {
1961+
mockTransport = createRouterTransport(({ service }) => {
1962+
service(AppService, {
1963+
updateRobotPartMetadata: (req) => {
1964+
capturedRequest = req;
1965+
return new pb.UpdateRobotPartMetadataResponse();
1966+
},
1967+
});
1968+
});
1969+
});
1970+
1971+
it('should handle empty metadata correctly', async () => {
1972+
await subject().updateRobotPartMetadata('robotPartId', {});
1973+
1974+
expect(capturedRequest).toEqual({
1975+
id: 'robotPartId',
1976+
data: Struct.fromJson({}),
1977+
});
1978+
});
1979+
1980+
it('should successfully update metadata with valid data', async () => {
1981+
await subject().updateRobotPartMetadata('robotPartId', {
1982+
key1: 'value1',
1983+
});
1984+
1985+
expect(capturedRequest).toEqual({
1986+
id: 'robotPartId',
1987+
data: Struct.fromJson({ key1: 'value1' }),
1988+
});
1989+
});
1990+
});
17361991
});

src/app/app-client.ts

+123-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { Struct } from '@bufbuild/protobuf';
1+
import type { JsonValue } from '@bufbuild/protobuf';
2+
import { Struct } from '@bufbuild/protobuf';
23
import { createClient, type Client, type Transport } from '@connectrpc/connect';
34
import { PackageType } from '../gen/app/packages/v1/packages_pb';
45
import { AppService } from '../gen/app/v1/app_connect';
@@ -1175,4 +1176,125 @@ export class AppClient {
11751176
): Promise<CreateKeyFromExistingKeyAuthorizationsResponse> {
11761177
return this.client.createKeyFromExistingKeyAuthorizations({ id });
11771178
}
1179+
1180+
/**
1181+
* Retrieves user-defined metadata for an organization.
1182+
*
1183+
* @param id The ID of the organization
1184+
* @returns The metadata associated with the organization
1185+
*/
1186+
async getOrganizationMetadata(
1187+
id: string
1188+
): Promise<Record<string, JsonValue>> {
1189+
const response = await this.client.getOrganizationMetadata({
1190+
organizationId: id,
1191+
});
1192+
const jsonResponse = response.toJson() as {
1193+
data?: Record<string, JsonValue>;
1194+
};
1195+
return jsonResponse.data ?? {};
1196+
}
1197+
1198+
/**
1199+
* Updates user-defined metadata for an organization.
1200+
*
1201+
* @param id The ID of the organization
1202+
* @param data The metadata to update
1203+
*/
1204+
async updateOrganizationMetadata(
1205+
id: string,
1206+
data: Record<string, JsonValue>
1207+
): Promise<void> {
1208+
await this.client.updateOrganizationMetadata({
1209+
organizationId: id,
1210+
data: Struct.fromJson(data),
1211+
});
1212+
}
1213+
1214+
/**
1215+
* Retrieves user-defined metadata for a location.
1216+
*
1217+
* @param id The ID of the location
1218+
* @returns The metadata associated with the location
1219+
*/
1220+
async getLocationMetadata(id: string): Promise<Record<string, JsonValue>> {
1221+
const response = await this.client.getLocationMetadata({ locationId: id });
1222+
const jsonResponse = response.toJson() as {
1223+
data?: Record<string, JsonValue>;
1224+
};
1225+
return jsonResponse.data ?? {};
1226+
}
1227+
1228+
/**
1229+
* Updates user-defined metadata for a location.
1230+
*
1231+
* @param id The ID of the location
1232+
* @param data The metadata to update
1233+
*/
1234+
async updateLocationMetadata(
1235+
id: string,
1236+
data: Record<string, JsonValue>
1237+
): Promise<void> {
1238+
await this.client.updateLocationMetadata({
1239+
locationId: id,
1240+
data: Struct.fromJson(data),
1241+
});
1242+
}
1243+
1244+
/**
1245+
* Retrieves user-defined metadata for a robot.
1246+
*
1247+
* @param id The ID of the robot
1248+
* @returns The metadata associated with the robot
1249+
*/
1250+
async getRobotMetadata(id: string): Promise<Record<string, JsonValue>> {
1251+
const response = await this.client.getRobotMetadata({ id });
1252+
const jsonResponse = response.toJson() as {
1253+
data?: Record<string, JsonValue>;
1254+
};
1255+
return jsonResponse.data ?? {};
1256+
}
1257+
1258+
/**
1259+
* Updates user-defined metadata for a robot.
1260+
*
1261+
* @param id The ID of the robot
1262+
* @param data The metadata to update
1263+
*/
1264+
async updateRobotMetadata(
1265+
id: string,
1266+
data: Record<string, JsonValue>
1267+
): Promise<void> {
1268+
await this.client.updateRobotMetadata({ id, data: Struct.fromJson(data) });
1269+
}
1270+
1271+
/**
1272+
* Retrieves user-defined metadata for a robot part.
1273+
*
1274+
* @param id The ID of the robot part
1275+
* @returns The metadata associated with the robot part
1276+
*/
1277+
async getRobotPartMetadata(id: string): Promise<Record<string, JsonValue>> {
1278+
const response = await this.client.getRobotPartMetadata({ id });
1279+
const jsonResponse = response.toJson() as {
1280+
data?: Record<string, JsonValue>;
1281+
};
1282+
return jsonResponse.data ?? {};
1283+
}
1284+
1285+
/**
1286+
* Updates user-defined metadata for a robot part.
1287+
*
1288+
* @param id The ID of the robot part
1289+
* @param data The metadata to update
1290+
*/
1291+
async updateRobotPartMetadata(
1292+
id: string,
1293+
data: Record<string, JsonValue>
1294+
): Promise<void> {
1295+
await this.client.updateRobotPartMetadata({
1296+
id,
1297+
data: Struct.fromJson(data),
1298+
});
1299+
}
11781300
}

0 commit comments

Comments
 (0)