@holochain/client
Advanced tools
Comparing version 0.17.0-dev.5 to 0.17.0-dev.6
import { CapSecret, GrantedFunctions } from "../../hdk/capabilities.js"; | ||
import type { AgentPubKey, CellId } from "../../types.js"; | ||
import { WsClient } from "../client.js"; | ||
import { Requester, Transformer } from "../common.js"; | ||
import { WebsocketConnectionOptions, Requester, Transformer } from "../common.js"; | ||
import { AddAgentInfoRequest, AddAgentInfoResponse, AdminApi, AgentInfoRequest, AgentInfoResponse, AttachAppInterfaceRequest, AttachAppInterfaceResponse, DeleteCloneCellRequest, DeleteCloneCellResponse, DisableAppRequest, DisableAppResponse, DumpFullStateRequest, DumpFullStateResponse, DumpNetworkStatsRequest, DumpNetworkStatsResponse, DumpStateRequest, DumpStateResponse, EnableAppRequest, EnableAppResponse, GenerateAgentPubKeyRequest, GenerateAgentPubKeyResponse, GetDnaDefinitionRequest, GetDnaDefinitionResponse, GrantZomeCallCapabilityRequest, GrantZomeCallCapabilityResponse, InstallAppRequest, InstallAppResponse, ListAppInterfacesRequest, ListAppInterfacesResponse, ListAppsRequest, ListAppsResponse, ListCellIdsRequest, ListCellIdsResponse, ListDnasRequest, ListDnasResponse, RegisterDnaRequest, RegisterDnaResponse, StorageInfoRequest, StorageInfoResponse, UninstallAppRequest, UninstallAppResponse, UpdateCoordinatorsRequest, UpdateCoordinatorsResponse } from "./types.js"; | ||
@@ -24,7 +24,6 @@ /** | ||
* | ||
* @param url - A `ws://` URL used as the connection address. | ||
* @param defaultTimeout - The default timeout for any request. | ||
* @param options - {@link (WebsocketConnectionOptions:interface)} | ||
* @returns A promise for a new connected instance. | ||
*/ | ||
static connect(url: URL, defaultTimeout?: number): Promise<AdminWebsocket>; | ||
static connect(options?: WebsocketConnectionOptions): Promise<AdminWebsocket>; | ||
_requester<ReqI, ReqO, ResI, ResO>(tag: string, transformer?: Transformer<ReqI, ReqO, ResI, ResO>): (req: ReqI, timeout?: number | undefined) => Promise<ResO>; | ||
@@ -31,0 +30,0 @@ /** |
@@ -29,14 +29,16 @@ import { getLauncherEnvironment } from "../../environments/launcher.js"; | ||
* | ||
* @param url - A `ws://` URL used as the connection address. | ||
* @param defaultTimeout - The default timeout for any request. | ||
* @param options - {@link (WebsocketConnectionOptions:interface)} | ||
* @returns A promise for a new connected instance. | ||
*/ | ||
static async connect(url, defaultTimeout) { | ||
static async connect(options = {}) { | ||
// Check if we are in the launcher's environment, and if so, redirect the url to connect to | ||
const env = getLauncherEnvironment(); | ||
if (env?.ADMIN_INTERFACE_PORT) { | ||
url = new URL(`ws://127.0.0.1:${env.ADMIN_INTERFACE_PORT}`); | ||
options.url = new URL(`ws://127.0.0.1:${env.ADMIN_INTERFACE_PORT}`); | ||
} | ||
const wsClient = await WsClient.connect(url); | ||
return new AdminWebsocket(wsClient, defaultTimeout); | ||
if (!options.url) { | ||
throw new Error("Unable to connect to Admin Websocket: No url provided and not in a Launcher environment."); | ||
} | ||
const wsClient = await WsClient.connect(options.url); | ||
return new AdminWebsocket(wsClient, options.defaultTimeout); | ||
} | ||
@@ -43,0 +45,0 @@ _requester(tag, transformer) { |
@@ -6,2 +6,3 @@ import Emittery, { UnsubscribeFunction } from "emittery"; | ||
import { AppWebsocket } from "../app/websocket.js"; | ||
import { WebsocketConnectionOptions } from "../common.js"; | ||
import { AppAgentCallZomeRequest, AppAgentClient, AppAgentEvents, AppAgentNetworkInfoRequest, AppCreateCloneCellRequest, AppDisableCloneCellRequest, AppEnableCloneCellRequest } from "./types.js"; | ||
@@ -30,8 +31,7 @@ /** | ||
* | ||
* @param url - The `ws://` URL of the App API to connect to. | ||
* @param installed_app_id - ID of the App to link to. | ||
* @param defaultTimeout - Timeout to default to for all operations. | ||
* @param options - {@link (WebsocketConnectionOptions:interface)} | ||
* @returns A new instance of an AppAgentWebsocket. | ||
*/ | ||
static connect(url: URL, installed_app_id: InstalledAppId, defaultTimeout?: number): Promise<AppAgentWebsocket>; | ||
static connect(installed_app_id: InstalledAppId, options?: WebsocketConnectionOptions): Promise<AppAgentWebsocket>; | ||
/** | ||
@@ -38,0 +38,0 @@ * Get a cell id by its role name or clone id. |
@@ -6,3 +6,3 @@ import Emittery from "emittery"; | ||
import { AppWebsocket } from "../app/websocket.js"; | ||
import { getBaseRoleNameFromCloneId, isCloneId } from "../common.js"; | ||
import { getBaseRoleNameFromCloneId, isCloneId, } from "../common.js"; | ||
/** | ||
@@ -56,9 +56,8 @@ * A class to establish a websocket connection to an App interface, for a | ||
* | ||
* @param url - The `ws://` URL of the App API to connect to. | ||
* @param installed_app_id - ID of the App to link to. | ||
* @param defaultTimeout - Timeout to default to for all operations. | ||
* @param options - {@link (WebsocketConnectionOptions:interface)} | ||
* @returns A new instance of an AppAgentWebsocket. | ||
*/ | ||
static async connect(url, installed_app_id, defaultTimeout) { | ||
const appWebsocket = await AppWebsocket.connect(url, defaultTimeout); | ||
static async connect(installed_app_id, options = {}) { | ||
const appWebsocket = await AppWebsocket.connect(options); | ||
const appInfo = await appWebsocket.appInfo({ | ||
@@ -65,0 +64,0 @@ installed_app_id: installed_app_id, |
@@ -5,3 +5,3 @@ import Emittery from "emittery"; | ||
import { WsClient } from "../client.js"; | ||
import { Requester, Transformer } from "../common.js"; | ||
import { WebsocketConnectionOptions, Requester, Transformer } from "../common.js"; | ||
import { Nonce256Bit } from "../zome-call-signing.js"; | ||
@@ -23,7 +23,6 @@ import { AppApi, AppInfoRequest, AppInfoResponse, CallZomeRequest, CallZomeResponse, CreateCloneCellRequest, CreateCloneCellResponse, DisableCloneCellRequest, DisableCloneCellResponse, EnableCloneCellRequest, EnableCloneCellResponse, NetworkInfoRequest, NetworkInfoResponse } from "./types.js"; | ||
* | ||
* @param url - The `ws://` URL of the App API to connect to. | ||
* @param defaultTimeout - Timeout to default to for all operations. | ||
* @param options - {@link (WebsocketConnectionOptions:interface)} | ||
* @returns A new instance of an AppWebsocket. | ||
*/ | ||
static connect(url: URL, defaultTimeout?: number): Promise<AppWebsocket>; | ||
static connect(options?: WebsocketConnectionOptions): Promise<AppWebsocket>; | ||
_requester<ReqI, ReqO, ResI, ResO>(tag: string, transformer?: Transformer<ReqI, ReqO, ResI, ResO>): (req: ReqI, timeout?: number | undefined) => Promise<ResO>; | ||
@@ -30,0 +29,0 @@ /** |
@@ -39,14 +39,16 @@ import { hashZomeCall } from "@holochain/serialization"; | ||
* | ||
* @param url - The `ws://` URL of the App API to connect to. | ||
* @param defaultTimeout - Timeout to default to for all operations. | ||
* @param options - {@link (WebsocketConnectionOptions:interface)} | ||
* @returns A new instance of an AppWebsocket. | ||
*/ | ||
static async connect(url, defaultTimeout) { | ||
static async connect(options = {}) { | ||
// Check if we are in the launcher's environment, and if so, redirect the url to connect to | ||
const env = getLauncherEnvironment(); | ||
if (env?.APP_INTERFACE_PORT) { | ||
url = new URL(`ws://127.0.0.1:${env.APP_INTERFACE_PORT}`); | ||
options.url = new URL(`ws://127.0.0.1:${env.APP_INTERFACE_PORT}`); | ||
} | ||
const wsClient = await WsClient.connect(url); | ||
const appWebsocket = new AppWebsocket(wsClient, defaultTimeout, env?.INSTALLED_APP_ID); | ||
if (!options.url) { | ||
throw new Error("Unable to connect to App Websocket: No url provided and not in a Launcher environment."); | ||
} | ||
const wsClient = await WsClient.connect(options.url); | ||
const appWebsocket = new AppWebsocket(wsClient, options.defaultTimeout, env?.INSTALLED_APP_ID); | ||
wsClient.on("signal", (signal) => appWebsocket.emit("signal", signal)); | ||
@@ -53,0 +55,0 @@ return appWebsocket; |
@@ -17,3 +17,3 @@ /// <reference types="ws" /> | ||
private index; | ||
constructor(socket: IsoWebSocket, url: URL); | ||
constructor(socket: IsoWebSocket, url?: URL); | ||
private setupSocket; | ||
@@ -20,0 +20,0 @@ /** |
@@ -81,1 +81,16 @@ import { RoleName } from "../types.js"; | ||
} | ||
/** | ||
* Options for a Websocket connection. | ||
* | ||
* @public | ||
*/ | ||
export interface WebsocketConnectionOptions { | ||
/** | ||
* The `ws://` URL of the Websocket server to connect to. Not required when connecting to App API from a Launcher or Kangaroo environment. | ||
*/ | ||
url?: URL; | ||
/** | ||
* Timeout to default to for all operations. | ||
*/ | ||
defaultTimeout?: number; | ||
} |
@@ -6,3 +6,3 @@ export { hashZomeCall } from "@holochain/serialization"; | ||
export { IsoWebSocket, WsClient } from "./client.js"; | ||
export { CloneId, HolochainError, Requester, Transformer, getBaseRoleNameFromCloneId, isCloneId, } from "./common.js"; | ||
export { CloneId, HolochainError, Requester, Transformer, WebsocketConnectionOptions, getBaseRoleNameFromCloneId, isCloneId, } from "./common.js"; | ||
export * from "./zome-call-signing.js"; |
{ | ||
"name": "@holochain/client", | ||
"version": "0.17.0-dev.5", | ||
"version": "0.17.0-dev.6", | ||
"description": "A JavaScript client for the Holochain Conductor API", | ||
@@ -5,0 +5,0 @@ "author": "Holochain Foundation <info@holochain.org> (http://holochain.org)", |
@@ -37,3 +37,3 @@ [![Project](https://img.shields.io/badge/Project-Holochain-blue.svg?style=flat-square)](http://holochain.org/) | ||
const adminWs = await AdminWebsocket.connect("ws://127.0.0.1:65000"); | ||
const adminWs = await AdminWebsocket.connect({url: "ws://127.0.0.1:65000"}); | ||
const agent_key = await adminWs.generateAgentPubKey(); | ||
@@ -55,6 +55,3 @@ const role_name = "role"; | ||
await adminWs.attachAppInterface({ port: 65001 }); | ||
const appAgentWs = await AppAgentWebsocket.connect( | ||
"ws://127.0.0.1:65001", | ||
installed_app_id | ||
); | ||
const appAgentWs = await AppAgentWebsocket.connect(installed_app_id, {url: "ws://127.0.0.1:65001"}); | ||
@@ -79,3 +76,3 @@ const zomeCallPayload: CallZomeRequest = { | ||
const adminWs = await AdminWebsocket.connect("ws://127.0.0.1:65000"); | ||
const adminWs = await AdminWebsocket.connect({url: "ws://127.0.0.1:65000"}); | ||
const agent_key = await adminWs.generateAgentPubKey(); | ||
@@ -96,3 +93,3 @@ const installed_app_id = "test-app"; | ||
await adminWs.attachAppInterface({ port: 65001 }); | ||
const appWs = await AppWebsocket.connect("ws://127.0.0.1:65001"); | ||
const appWs = await AppWebsocket.connect({url: "ws://127.0.0.1:65001"}); | ||
@@ -99,0 +96,0 @@ let signalCb; |
131659
3680
174