@holochain/client
Advanced tools
Comparing version 0.9.3 to 0.10.0
/// <reference types="node" /> | ||
import { AgentPubKey, CellId, DnaHash, DnaProperties, ActionHash, HoloHash, InstalledAppId, InstalledCell, KitsuneAgent, KitsuneSpace, RoleId, Signature, Timestamp, WasmHash } from "../../types.js"; | ||
import { DhtOp, Entry, Action } from "../../hdk/index.js"; | ||
import { AgentPubKey, CellId, DnaHash, DnaProperties, ActionHash, HoloHash, InstalledAppId, InstalledCell, KitsuneAgent, KitsuneSpace, RoleName as RoleName, Signature, Timestamp, WasmHash } from "../../types.js"; | ||
import { DhtOp, Entry, Action, ZomeCallCapGrant } from "../../hdk/index.js"; | ||
import { Requester } from "../common.js"; | ||
@@ -92,2 +92,3 @@ import { ArchiveCloneCellRequest, CreateCloneCellResponse } from "../app/types.js"; | ||
}; | ||
export declare type FnName = string; | ||
export declare type ZomeName = string; | ||
@@ -158,3 +159,3 @@ export declare type ZomeDefinition = [ | ||
export declare type AppRoleManifest = { | ||
id: RoleId; | ||
name: RoleName; | ||
provisioning?: CellProvisioning; | ||
@@ -220,5 +221,11 @@ dna: AppRoleDnaManifest; | ||
app_id: InstalledAppId; | ||
role_id: RoleId; | ||
role_name: RoleName; | ||
} | ||
export declare type DeleteArchivedCloneCellsResponse = void; | ||
export interface GrantZomeCallCapabilityPayload { | ||
cell_id: CellId; | ||
cap_grant: ZomeCallCapGrant; | ||
} | ||
export declare type GrantZomeCallCapabilityRequest = GrantZomeCallCapabilityPayload; | ||
export declare type GrantZomeCallCapabilityResponse = void; | ||
export interface AdminApi { | ||
@@ -248,6 +255,7 @@ attachAppInterface: Requester<AttachAppInterfaceRequest, AttachAppInterfaceResponse>; | ||
deleteArchivedCloneCells: Requester<DeleteArchivedCloneCellsRequest, DeleteArchivedCloneCellsResponse>; | ||
grantZomeCallCapability: Requester<GrantZomeCallCapabilityRequest, GrantZomeCallCapabilityResponse>; | ||
} | ||
export declare type InstallAppDnaPayload = { | ||
hash: HoloHash; | ||
role_id: RoleId; | ||
role_name: RoleName; | ||
membrane_proof?: MembraneProof; | ||
@@ -254,0 +262,0 @@ }; |
@@ -49,2 +49,3 @@ /** | ||
deleteArchivedCloneCells: Requester<Api.DeleteArchivedCloneCellsRequest, Api.DeleteArchivedCloneCellsResponse>; | ||
grantZomeCallCapability: Requester<Api.GrantZomeCallCapabilityRequest, Api.GrantZomeCallCapabilityResponse>; | ||
} |
@@ -68,2 +68,3 @@ /** | ||
deleteArchivedCloneCells = this._requester("delete_archived_clone_cells"); | ||
grantZomeCallCapability = this._requester("grant_zome_call_capability"); | ||
} | ||
@@ -70,0 +71,0 @@ const listAppsTransform = { |
import { CapSecret } from "../../hdk/capabilities.js"; | ||
import { AgentPubKey, CellId, DnaProperties, InstalledAppId, InstalledCell, RoleId, Timestamp } from "../../types.js"; | ||
import { AgentPubKey, CellId, DnaProperties, InstalledAppId, InstalledCell, RoleName, Timestamp, DnaHash, DnaGossipInfo } from "../../types.js"; | ||
import { Requester } from "../common.js"; | ||
@@ -28,3 +28,3 @@ import { InstalledAppInfo, MembraneProof, NetworkSeed } from "../admin/index.js"; | ||
*/ | ||
role_id: RoleId; | ||
role_name: RoleName; | ||
/** | ||
@@ -68,3 +68,3 @@ * Modifiers to set for the new cell. | ||
app_id: InstalledAppId; | ||
clone_cell_id: RoleId | CellId; | ||
clone_cell_id: RoleName | CellId; | ||
} | ||
@@ -79,2 +79,7 @@ export declare type ArchiveCloneCellResponse = void; | ||
}; | ||
export interface GossipInfoRequest { | ||
/** The DNAs for which to get gossip info */ | ||
dnas: DnaHash[]; | ||
} | ||
export declare type GossipInfoResponse = DnaGossipInfo[]; | ||
export declare type AppSignalCb = (signal: AppSignal) => void; | ||
@@ -81,0 +86,0 @@ export declare type SignalResponseGeneric<Payload> = Payload; |
@@ -0,6 +1,8 @@ | ||
/// <reference types="node" /> | ||
import { EventEmitter } from "events"; | ||
import { InstalledAppId } from "../../types.js"; | ||
import { WsClient } from "../client.js"; | ||
import { Requester, Transformer } from "../common.js"; | ||
import { AppApi, AppInfoRequest, AppInfoResponse, AppSignalCb, CallZomeRequestGeneric, CallZomeResponseGeneric, ArchiveCloneCellRequest, CreateCloneCellRequest, CreateCloneCellResponse, ArchiveCloneCellResponse } from "./types.js"; | ||
export declare class AppWebsocket implements AppApi { | ||
import { AppApi, AppInfoRequest, AppInfoResponse, AppSignalCb, CallZomeRequestGeneric, CallZomeResponseGeneric, ArchiveCloneCellRequest, CreateCloneCellRequest, CreateCloneCellResponse, ArchiveCloneCellResponse, GossipInfoRequest, GossipInfoResponse } from "./types.js"; | ||
export declare class AppWebsocket extends EventEmitter implements AppApi { | ||
client: WsClient; | ||
@@ -16,2 +18,3 @@ defaultTimeout: number; | ||
archiveCloneCell: Requester<ArchiveCloneCellRequest, ArchiveCloneCellResponse>; | ||
gossipInfo: Requester<GossipInfoRequest, GossipInfoResponse>; | ||
} |
@@ -5,8 +5,5 @@ /** | ||
* | ||
* const client = AppWebsocket.connect( | ||
* 'ws://localhost:9000', | ||
* signal => console.log('got a signal:', signal) | ||
* ) | ||
* const client = AppWebsocket.connect('ws://localhost:9000'); | ||
* | ||
* client.callZome({...}) // TODO: show what's in here | ||
* client.callZome({...}) | ||
* .then(() => { | ||
@@ -17,9 +14,10 @@ * console.log('DNA successfully installed') | ||
* console.error('problem installing DNA:', err) | ||
* }) | ||
* }); | ||
*/ | ||
import { decode, encode } from "@msgpack/msgpack"; | ||
import { EventEmitter } from "events"; | ||
import { getLauncherEnvironment } from "../../environments/launcher.js"; | ||
import { WsClient } from "../client.js"; | ||
import { catchError, DEFAULT_TIMEOUT, promiseTimeout, requesterTransformer, } from "../common.js"; | ||
export class AppWebsocket { | ||
export class AppWebsocket extends EventEmitter { | ||
client; | ||
@@ -29,2 +27,3 @@ defaultTimeout; | ||
constructor(client, defaultTimeout, overrideInstalledAppId) { | ||
super(); | ||
this.client = client; | ||
@@ -35,3 +34,5 @@ this.defaultTimeout = | ||
} | ||
static async connect(url, defaultTimeout, signalCb) { | ||
static async connect(url, defaultTimeout, | ||
//** @deprecated */ | ||
signalCb) { | ||
// Check if we are in the launcher's environment, and if so, redirect the url to connect to | ||
@@ -43,3 +44,5 @@ const env = await getLauncherEnvironment(); | ||
const wsClient = await WsClient.connect(url, signalCb); | ||
return new AppWebsocket(wsClient, defaultTimeout, env ? env.INSTALLED_APP_ID : undefined); | ||
const appWebsocket = new AppWebsocket(wsClient, defaultTimeout, env ? env.INSTALLED_APP_ID : undefined); | ||
wsClient.on("signal", (signal) => appWebsocket.emit("signal", signal)); | ||
return appWebsocket; | ||
} | ||
@@ -51,2 +54,3 @@ _requester = (tag, transformer) => requesterTransformer((req, timeout) => promiseTimeout(this.client.request(req), tag, timeout || this.defaultTimeout).then(catchError), tag, transformer); | ||
archiveCloneCell = this._requester("archive_clone_cell"); | ||
gossipInfo = this._requester("gossip_info"); | ||
} | ||
@@ -53,0 +57,0 @@ const callZomeTransform = { |
/// <reference types="ws" /> | ||
/// <reference types="node" /> | ||
import { decode } from "@msgpack/msgpack"; | ||
import Websocket from "isomorphic-ws"; | ||
import { EventEmitter } from "events"; | ||
import { AppSignalCb } from "./app/types.js"; | ||
@@ -11,3 +13,3 @@ /** | ||
*/ | ||
export declare class WsClient { | ||
export declare class WsClient extends EventEmitter { | ||
socket: Websocket; | ||
@@ -19,3 +21,2 @@ pendingRequests: Record<number, { | ||
index: number; | ||
alreadyWarnedNoSignalCb: boolean; | ||
constructor(socket: any, signalCb?: AppSignalCb); | ||
@@ -22,0 +23,0 @@ emitSignal(data: any): void; |
import { decode, encode } from "@msgpack/msgpack"; | ||
import Websocket from "isomorphic-ws"; | ||
import { EventEmitter } from "events"; | ||
/** | ||
@@ -9,13 +10,15 @@ * A Websocket client which can make requests and receive responses, | ||
*/ | ||
export class WsClient { | ||
export class WsClient extends EventEmitter { | ||
socket; | ||
pendingRequests; | ||
index; | ||
alreadyWarnedNoSignalCb; | ||
constructor(socket, signalCb) { | ||
super(); | ||
this.socket = socket; | ||
this.pendingRequests = {}; | ||
this.index = 0; | ||
// TODO: allow adding signal handlers later | ||
this.alreadyWarnedNoSignalCb = false; | ||
if (signalCb) { | ||
console.log("Providing a signal callback on client initialization is deprecated. Instead, add an event handler using `.on('signal', signalCb)`."); | ||
this.on("signal", signalCb); | ||
} | ||
socket.onmessage = async (encodedMsg) => { | ||
@@ -29,25 +32,18 @@ let data = encodedMsg.data; | ||
if (msg.type === "Signal") { | ||
if (signalCb) { | ||
const decodedMessage = decode(msg.data); | ||
if (!decodedMessage.App) { | ||
// We have received a system signal, do nothing | ||
return; | ||
} | ||
// Note: holochain currently returns signals as an array of two values: cellId and the serialized signal payload | ||
// and this array is nested within the App key within the returned message. | ||
const decodedCellId = decodedMessage.App[0]; | ||
// Note:In order to return readible content to the UI, the signal payload must also be decoded. | ||
const decodedPayload = signalTransform(decodedMessage.App[1]); | ||
// Return a uniform format to UI (ie: { type, data } - the same format as with callZome and appInfo...) | ||
const signal = { | ||
type: msg.type, | ||
data: { cellId: decodedCellId, payload: decodedPayload }, | ||
}; | ||
signalCb(signal); | ||
const decodedMessage = decode(msg.data); | ||
if (!decodedMessage.App) { | ||
// We have received a system signal, do nothing | ||
return; | ||
} | ||
else { | ||
if (!this.alreadyWarnedNoSignalCb) | ||
console.log("Received signal but no signal callback was set in constructor"); | ||
this.alreadyWarnedNoSignalCb = true; | ||
} | ||
// Note: holochain currently returns signals as an array of two values: cellId and the serialized signal payload | ||
// and this array is nested within the App key within the returned message. | ||
const decodedCellId = decodedMessage.App[0]; | ||
// Note:In order to return readible content to the UI, the signal payload must also be decoded. | ||
const decodedPayload = signalTransform(decodedMessage.App[1]); | ||
// Return a uniform format to UI (ie: { type, data } - the same format as with callZome and appInfo...) | ||
const signal = { | ||
type: msg.type, | ||
data: { cellId: decodedCellId, payload: decodedPayload }, | ||
}; | ||
this.emit("signal", signal); | ||
} | ||
@@ -54,0 +50,0 @@ else if (msg.type === "Response") { |
@@ -1,2 +0,2 @@ | ||
import { RoleId } from "../types.js"; | ||
import { RoleName } from "../types.js"; | ||
export declare const DEFAULT_TIMEOUT = 15000; | ||
@@ -29,13 +29,13 @@ export declare type Transformer<ReqO, ReqI, ResI, ResO> = { | ||
private static readonly CLONE_ID_DELIMITER; | ||
private readonly roleId; | ||
private readonly roleName; | ||
private readonly index; | ||
constructor(roleId: RoleId, index: number); | ||
constructor(roleName: RoleName, index: number); | ||
/** | ||
* Parse a role id of a clone cell to obtain a clone id instance. | ||
* @param roleId Role id to parse. | ||
* @param roleName Role id to parse. | ||
* @returns A clone id instance. | ||
*/ | ||
static fromRoleId(roleId: RoleId): CloneId; | ||
static fromRoleName(roleName: RoleName): CloneId; | ||
toString(): string; | ||
getBaseRoleId(): string; | ||
getBaseRoleName(): string; | ||
} |
@@ -49,6 +49,6 @@ const ERROR_TYPE = "error"; | ||
static CLONE_ID_DELIMITER = "."; | ||
roleId; | ||
roleName; | ||
index; | ||
constructor(roleId, index) { | ||
this.roleId = roleId; | ||
constructor(roleName, index) { | ||
this.roleName = roleName; | ||
this.index = index; | ||
@@ -58,7 +58,7 @@ } | ||
* Parse a role id of a clone cell to obtain a clone id instance. | ||
* @param roleId Role id to parse. | ||
* @param roleName Role id to parse. | ||
* @returns A clone id instance. | ||
*/ | ||
static fromRoleId(roleId) { | ||
const parts = roleId.split(CloneId.CLONE_ID_DELIMITER); | ||
static fromRoleName(roleName) { | ||
const parts = roleName.split(CloneId.CLONE_ID_DELIMITER); | ||
if (parts.length !== 2) { | ||
@@ -70,8 +70,8 @@ throw new Error("Malformed clone id: must consist of {role id.clone index}"); | ||
toString() { | ||
return `${this.roleId}${CloneId.CLONE_ID_DELIMITER}${this.index}`; | ||
return `${this.roleName}${CloneId.CLONE_ID_DELIMITER}${this.index}`; | ||
} | ||
getBaseRoleId() { | ||
return this.roleId; | ||
getBaseRoleName() { | ||
return this.roleName; | ||
} | ||
} | ||
//# sourceMappingURL=common.js.map |
@@ -0,1 +1,2 @@ | ||
import { FnName, ZomeName } from "../api/index.js"; | ||
import { AgentPubKey } from "../types.js"; | ||
@@ -11,6 +12,3 @@ export declare type CapSecret = Uint8Array; | ||
access: CapAccess; | ||
functions: Array<{ | ||
zome: string; | ||
fn_name: string; | ||
}>; | ||
functions: Array<[ZomeName, FnName]>; | ||
} | ||
@@ -17,0 +15,0 @@ export declare type CapAccess = "Unrestricted" | { |
@@ -9,9 +9,9 @@ import { CapClaim, ZomeCallCapGrant } from "./capabilities.js"; | ||
}; | ||
export declare type AppEntryType = { | ||
id: number; | ||
zome_id: number; | ||
export declare type AppEntryDef = { | ||
entry_index: number; | ||
zome_index: number; | ||
visibility: EntryVisibility; | ||
}; | ||
export declare type EntryType = "Agent" | { | ||
App: AppEntryType; | ||
App: AppEntryDef; | ||
} | "CapClaim" | "CapGrant"; | ||
@@ -18,0 +18,0 @@ export interface EntryContent<E extends string, C> { |
@@ -14,6 +14,6 @@ export declare type HoloHash = Uint8Array; | ||
export declare type DnaProperties = any; | ||
export declare type RoleId = string; | ||
export declare type RoleName = string; | ||
export declare type InstalledCell = { | ||
cell_id: CellId; | ||
role_id: RoleId; | ||
role_name: RoleName; | ||
}; | ||
@@ -25,1 +25,14 @@ export declare type Timestamp = number; | ||
} | ||
export declare type DnaGossipInfo = { | ||
total_historical_gossip_throughput: HistoricalGossipThroughput; | ||
}; | ||
export declare type HistoricalGossipThroughput = { | ||
expected_op_bytes: InOut; | ||
expected_op_count: InOut; | ||
op_bytes: InOut; | ||
op_count: InOut; | ||
}; | ||
export declare type InOut = { | ||
incoming: number; | ||
outgoing: number; | ||
}; |
{ | ||
"name": "@holochain/client", | ||
"version": "0.9.3", | ||
"version": "0.10.0", | ||
"description": "A JavaScript client for the Holochain Conductor API", | ||
@@ -35,3 +35,3 @@ "author": "Holochain Foundation <info@holochain.org> (http://holochain.org)", | ||
"lint": "eslint --fix --ext .ts src test .eslintrc.cjs", | ||
"test": "RUST_LOG=error RUST_BACKTRACE=1 node --loader ts-node/esm test/index.ts", | ||
"test": "RUST_LOG=error RUST_BACKTRACE=1 node --experimental-wasm-modules --loader ts-node/esm test/index.ts", | ||
"build": "rimraf ./lib && tsc -p tsconfig.build.json" | ||
@@ -45,7 +45,11 @@ }, | ||
"eslint-plugin-tsdoc": "^0.2.16", | ||
"events": "^3.3.0", | ||
"isomorphic-ws": "^5.0.0", | ||
"prettier": "^2.6.2" | ||
"lodash": "^4.5.0", | ||
"prettier": "^2.6.2", | ||
"tweetnacl": "^1.0.3" | ||
}, | ||
"devDependencies": { | ||
"@types/js-yaml": "^3.12.7", | ||
"@types/lodash": "^4.5.7", | ||
"@types/tape": "^4.13.2", | ||
@@ -56,3 +60,7 @@ "@types/ws": "^8.5.3", | ||
"eslint": "^8.16.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint-plugin-tsdoc": "^0.2.16", | ||
"js-yaml": "^3.14.1", | ||
"prettier": "^2.6.2", | ||
"rimraf": "^3.0.2", | ||
@@ -59,0 +67,0 @@ "tape": "^5.5.3", |
@@ -52,2 +52,26 @@ [![Project](https://img.shields.io/badge/Project-Holochain-blue.svg?style=flat-square)](http://holochain.org/) | ||
### Use AppAgentWebsocket | ||
```typescript | ||
const signalCb = (signal: AppSignal) => { | ||
// impl... | ||
resolve() | ||
} | ||
const TIMEOUT = 12000 | ||
// default timeout is set to 12000 | ||
const appWs = await AppWebsocket.connect(`ws://localhost:${appPort}`, 12000, signalCb) | ||
const client = new AppAgentWebsocket(appWs, 'installed_app_id') | ||
// default timeout set here (30000) will overwrite the defaultTimeout(12000) set above | ||
await client.callZome({ | ||
cap: null, | ||
role_name: 'dnas_role_name', // role_name is unique per app, so you can unambiguously identify your dna with role_name in this client, | ||
zome_name: "test_zome", | ||
fn_name: 'test_emitter_fn', | ||
provenance: fakeAgentPubKey('TODO'), | ||
payload: null, | ||
}, 30000) | ||
``` | ||
## API Reference | ||
@@ -54,0 +78,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79352
68
1496
116
10
16
+ Addedevents@^3.3.0
+ Addedlodash@^4.5.0
+ Addedtweetnacl@^1.0.3
+ Addedevents@3.3.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedtweetnacl@1.0.3(transitive)