Skip to content

Commit

Permalink
Prepare for Holochain 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Nov 8, 2023
1 parent 1d423d6 commit 35ac527
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ A JavaScript client for the Holochain Conductor API (works with browsers as well

**JS client v0.16.x** are compatible with **Holochain v0.2.x**.

**JS client v0.17.x** are compatible with **Holochain v0.3.x**.

To install from NPM, run
```bash
npm install --save-exact @holochain/client
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@holochain/client",
"version": "0.16.3",
"version": "0.17.0",
"description": "A JavaScript client for the Holochain Conductor API",
"author": "Holochain Foundation <info@holochain.org> (http://holochain.org)",
"license": "CAL-1.0",
Expand Down
15 changes: 15 additions & 0 deletions src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ export class WsClient extends Emittery {
resolve: RequestResolver,
reject: RequestRejecter
) {
function toHexString(byteArray: number[]) {
return Array.from(byteArray, function(byte) {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join(', ')
}

console.log("sending message", request, toHexString(encode(request) as unknown as number[]))

const id = this.index;
const encodedMsg = encode({
id,
Expand All @@ -200,13 +208,20 @@ export class WsClient extends Emittery {
}

private handleResponse(msg: HolochainMessage) {
function toHexString(byteArray: number[]) {
return Array.from(byteArray, function(byte) {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join(', ')
}

const id = msg.id;
if (this.pendingRequests[id]) {
if (msg.data === null || msg.data === undefined) {
this.pendingRequests[id].reject(
new Error("Response canceled by responder")
);
} else {
console.log('got a response back', msg.data, toHexString(msg.data as unknown as number[]));
this.pendingRequests[id].resolve(decode(msg.data));
}
delete this.pendingRequests[id];
Expand Down
4 changes: 2 additions & 2 deletions src/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type RequesterUnit<Res> = () => Promise<Res>;
/**
* @public
*/
export type Tagged<T> = { type: string; data: T };
export type Tagged<T> = { type: { [tag: string]: null }; data: T };

/**
* Take a Requester function which deals with tagged requests and responses,
Expand All @@ -39,7 +39,7 @@ export const requesterTransformer =
) =>
async (req: ReqI, timeout?: number) => {
const transformedInput = await transform.input(req);
const input = { type: tag, data: transformedInput };
const input = { type: { [tag]: null }, data: transformedInput };
const response = await requester(input, timeout);
const output = transform.output(response.data);
return output;
Expand Down

0 comments on commit 35ac527

Please sign in to comment.