Skip to content

Commit

Permalink
feat: add optional callZomeTransform (#247)
Browse files Browse the repository at this point in the history
* added optional callZomeTransform

* prettier typescript

* switch argument order

---------

Co-authored-by: Jost Schulte <jost.schulte@protonmail.com>
  • Loading branch information
matthme and jost-s committed May 10, 2024
1 parent a361a19 commit f9f4c0e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 3 deletions.
11 changes: 11 additions & 0 deletions docs/client.appwebsocketconnectionoptions.callzometransform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [AppWebsocketConnectionOptions](./client.appwebsocketconnectionoptions.md) &gt; [callZomeTransform](./client.appwebsocketconnectionoptions.callzometransform.md)

## AppWebsocketConnectionOptions.callZomeTransform property

**Signature:**

```typescript
callZomeTransform?: CallZomeTransform;
```
19 changes: 19 additions & 0 deletions docs/client.appwebsocketconnectionoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ Description
</th></tr></thead>
<tbody><tr><td>
[callZomeTransform?](./client.appwebsocketconnectionoptions.callzometransform.md)
</td><td>
</td><td>
[CallZomeTransform](./client.callzometransform.md)
</td><td>
_(Optional)_
</td></tr>
<tr><td>
[token?](./client.appwebsocketconnectionoptions.token.md)
Expand Down
13 changes: 13 additions & 0 deletions docs/client.callzometransform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [CallZomeTransform](./client.callzometransform.md)

## CallZomeTransform type

**Signature:**

```typescript
export type CallZomeTransform = Transformer<CallZomeRequest | CallZomeRequestSigned, Promise<CallZomeRequestSigned>, CallZomeResponseGeneric<Uint8Array>, CallZomeResponse>;
```
**References:** [Transformer](./client.transformer_2.md)<!-- -->, [CallZomeRequest](./client.callzomerequest.md)<!-- -->, [CallZomeRequestSigned](./client.callzomerequestsigned.md)<!-- -->, [CallZomeResponseGeneric](./client.callzomeresponsegeneric.md)<!-- -->, [CallZomeResponse](./client.callzomeresponse.md)

9 changes: 9 additions & 0 deletions docs/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,15 @@ This type is meant to be opaque



</td></tr>
<tr><td>

[CallZomeTransform](./client.callzometransform.md)


</td><td>


</td></tr>
<tr><td>

Expand Down
9 changes: 9 additions & 0 deletions src/api/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Nonce256Bit,
RoleName,
Timestamp,
Transformer,
WebsocketConnectionOptions,
ZomeName,
} from "../../index.js";
Expand Down Expand Up @@ -291,4 +292,12 @@ export interface AppClient {
export interface AppWebsocketConnectionOptions
extends WebsocketConnectionOptions {
token?: AppAuthenticationToken;
callZomeTransform?: CallZomeTransform;
}

export type CallZomeTransform = Transformer<
CallZomeRequest | CallZomeRequestSigned,
Promise<CallZomeRequestSigned>,
CallZomeResponseGeneric<Uint8Array>,
CallZomeResponse
>;
21 changes: 18 additions & 3 deletions src/api/app/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
NetworkInfoRequest,
NetworkInfoResponse,
AppWebsocketConnectionOptions,
CallZomeTransform,
} from "./types.js";
import {
getHostZomeCallSigner,
Expand Down Expand Up @@ -66,6 +67,13 @@ export class AppWebsocket implements AppClient {
readonly installedAppId: InstalledAppId;
private readonly defaultTimeout: number;
private readonly emitter: Emittery<AppEvents>;
private readonly callZomeTransform: Transformer<
CallZomeRequest | CallZomeRequestSigned,
Promise<CallZomeRequestSigned>,
CallZomeResponseGeneric<Uint8Array>,
CallZomeResponse
>;

cachedAppInfo?: AppInfo | null;

private readonly appInfoRequester: Requester<null, AppInfoResponse>;
Expand Down Expand Up @@ -93,12 +101,14 @@ export class AppWebsocket implements AppClient {
private constructor(
client: WsClient,
appInfo: AppInfo,
callZomeTransform?: CallZomeTransform,
defaultTimeout?: number
) {
this.client = client;
this.myPubKey = appInfo.agent_pub_key;
this.installedAppId = appInfo.installed_app_id;
this.defaultTimeout = defaultTimeout ?? DEFAULT_TIMEOUT;
this.callZomeTransform = callZomeTransform ?? defaultCallZomeTransform;
this.emitter = new Emittery<AppEvents>();
this.cachedAppInfo = appInfo;

Expand All @@ -111,7 +121,7 @@ export class AppWebsocket implements AppClient {
this.client,
"call_zome",
this.defaultTimeout,
callZomeTransform
this.callZomeTransform
);
this.createCloneCellRequester = AppWebsocket.requester(
this.client,
Expand Down Expand Up @@ -203,7 +213,12 @@ export class AppWebsocket implements AppClient {
);
}

return new AppWebsocket(client, appInfo, options.defaultTimeout);
return new AppWebsocket(
client,
appInfo,
options.callZomeTransform,
options.defaultTimeout
);
}

/**
Expand Down Expand Up @@ -417,7 +432,7 @@ export class AppWebsocket implements AppClient {
}
}

const callZomeTransform: Transformer<
const defaultCallZomeTransform: Transformer<
// either an already signed zome call which is returned as is, or a zome call
// payload to be signed
CallZomeRequest | CallZomeRequestSigned,
Expand Down

0 comments on commit f9f4c0e

Please sign in to comment.