Skip to content

Commit a7c93c1

Browse files
committed
Add ListApps and DeployApp methods to TypeScript client
- Add listApps() method for querying installed applications - Add deployApp() method with streaming upload support - Bump version to 2.2.6 DeployApp supports chunked file upload with progress callbacks for large .deb package files.
1 parent c47d228 commit a7c93c1

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@science-corporation/synapse",
3-
"version": "2.2.5",
3+
"version": "2.2.6",
44
"description": "Client library and CLI for the Synapse API",
55
"license": "Apache-2.0",
66
"main": "dist/index.js",

src/device.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,65 @@ class Device {
183183
return call;
184184
}
185185

186+
// Apps
187+
188+
async listApps(options: CallOptions = {}): Promise<{ status: Status; response?: synapse.ListAppsResponse }> {
189+
return new Promise((resolve, reject) => {
190+
this.rpc.listApps({}, options, (err: ServiceError, res: synapse.ListAppsResponse) => {
191+
if (err) {
192+
reject(err);
193+
} else if (!res) {
194+
reject(new Error("No response from listApps"));
195+
} else {
196+
resolve({ status: new Status(), response: res });
197+
}
198+
});
199+
});
200+
}
201+
202+
deployApp(
203+
options: CallOptions = {},
204+
callbacks: {
205+
onData: (data: synapse.AppDeployResponse) => void;
206+
onEnd?: () => void;
207+
onError?: (err: Error) => void;
208+
onStatus?: (status: Status) => void;
209+
}
210+
) {
211+
const { onData, onEnd, onError, onStatus } = callbacks;
212+
const call = this.rpc.deployApp(options);
213+
214+
call.on("data", (data: synapse.AppDeployResponse) => {
215+
onData(data);
216+
});
217+
if (onEnd) {
218+
call.on("end", onEnd);
219+
}
220+
if (onError) {
221+
call.on("error", (err: ServiceError) => {
222+
onError(err);
223+
});
224+
}
225+
if (onStatus) {
226+
call.on("status", (grpcStatus) => {
227+
onStatus?.(new Status(grpcStatus.code, grpcStatus.details));
228+
});
229+
}
230+
231+
return {
232+
call,
233+
sendMetadata: (metadata: synapse.IPackageMetadata) => {
234+
call.write({ metadata });
235+
},
236+
sendChunk: (fileChunk: Uint8Array) => {
237+
call.write({ fileChunk });
238+
},
239+
end: () => {
240+
call.end();
241+
},
242+
};
243+
}
244+
186245
_handleStatusResponse(status: synapse.IStatus): Status {
187246
const { code, message } = status;
188247
if (code !== synapse.StatusCode.kOk) {

0 commit comments

Comments
 (0)