Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@science-corporation/synapse",
"version": "2.2.5",
"version": "2.2.6",
"description": "Client library and CLI for the Synapse API",
"license": "Apache-2.0",
"main": "dist/index.js",
Expand Down
59 changes: 59 additions & 0 deletions src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,65 @@ class Device {
return call;
}

// Apps

async listApps(options: CallOptions = {}): Promise<{ status: Status; response?: synapse.ListAppsResponse }> {
return new Promise((resolve, reject) => {
this.rpc.listApps({}, options, (err: ServiceError, res: synapse.ListAppsResponse) => {
if (err) {
reject(err);
} else if (!res) {
reject(new Error("No response from listApps"));
} else {
resolve({ status: new Status(), response: res });
}
});
});
}

deployApp(
options: CallOptions = {},
callbacks: {
onData: (data: synapse.AppDeployResponse) => void;
onEnd?: () => void;
onError?: (err: Error) => void;
onStatus?: (status: Status) => void;
}
) {
const { onData, onEnd, onError, onStatus } = callbacks;
const call = this.rpc.deployApp(options);

call.on("data", (data: synapse.AppDeployResponse) => {
onData(data);
});
if (onEnd) {
call.on("end", onEnd);
}
if (onError) {
call.on("error", (err: ServiceError) => {
onError(err);
});
}
if (onStatus) {
call.on("status", (grpcStatus) => {
onStatus?.(new Status(grpcStatus.code, grpcStatus.details));
});
}

return {
call,
sendMetadata: (metadata: synapse.IPackageMetadata) => {
call.write({ metadata });
},
sendChunk: (fileChunk: Uint8Array) => {
call.write({ fileChunk });
},
end: () => {
call.end();
},
};
}

_handleStatusResponse(status: synapse.IStatus): Status {
const { code, message } = status;
if (code !== synapse.StatusCode.kOk) {
Expand Down
2 changes: 1 addition & 1 deletion synapse-api
Loading