@holochain/client 0.17.0-dev.8 → 0.18.0-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@holochain/client",
3
- "version": "0.17.0-dev.8",
3
+ "version": "0.18.0-dev.0",
4
4
  "description": "A JavaScript client for the Holochain Conductor API",
5
- "author": "Holochain Foundation <info@holochain.org> (http://holochain.org)",
5
+ "author": "Holochain Foundation <info@holochain.org> (https://holochain.org)",
6
6
  "license": "CAL-1.0",
7
7
  "repository": {
8
8
  "type": "git",
@@ -32,9 +32,10 @@
32
32
  ],
33
33
  "scripts": {
34
34
  "lint": "eslint --fix --ext .ts src test .eslintrc.cjs",
35
- "test:app-agent": "RUST_LOG=error RUST_BACKTRACE=1 node --loader ts-node/esm test/e2e/app-agent-websocket.ts",
36
- "test:utils": "RUST_LOG=error RUST_BACKTRACE=1 node --loader ts-node/esm test/e2e/utils.ts",
37
- "test": "RUST_LOG=error RUST_BACKTRACE=1 node --loader ts-node/esm test/index.ts",
35
+ "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
36
+ "test:app-agent": "RUST_LOG=error RUST_BACKTRACE=1 tsx test/e2e/app-websocket.ts",
37
+ "test:utils": "RUST_LOG=error RUST_BACKTRACE=1 tsx test/e2e/utils.ts",
38
+ "test": "RUST_LOG=error RUST_BACKTRACE=1 tsx test/index.ts",
38
39
  "build:lib": "rimraf ./lib && tsc -p tsconfig.build.json",
39
40
  "build:docs": "api-extractor run --local && api-documenter markdown -i docs/temp -o docs",
40
41
  "build": "npm run build:lib && npm run build:docs",
@@ -44,7 +45,6 @@
44
45
  "@bitgo/blake2b": "^3.2.4",
45
46
  "@holochain/serialization": "^0.1.0-beta-rc.3",
46
47
  "@msgpack/msgpack": "^2.8.0",
47
- "@tauri-apps/api": "^1.4.0",
48
48
  "emittery": "^1.0.1",
49
49
  "isomorphic-ws": "^5.0.0",
50
50
  "js-base64": "^3.7.5",
@@ -69,7 +69,7 @@
69
69
  "prettier": "^2.8.8",
70
70
  "rimraf": "^3.0.2",
71
71
  "tape": "^5.6.6",
72
- "ts-node": "^10.9.1",
72
+ "tsx": "^4.7.2",
73
73
  "typescript": "^4.9.5"
74
74
  }
75
- }
75
+ }
@@ -1,2 +0,0 @@
1
- export * from "./types.js";
2
- export * from "./websocket.js";
@@ -1,2 +0,0 @@
1
- export * from "./types.js";
2
- export * from "./websocket.js";
@@ -1,59 +0,0 @@
1
- import { UnsubscribeFunction } from "emittery";
2
- import { AgentPubKey, RoleName } from "../../index.js";
3
- import { AppInfoResponse, AppSignal, AppSignalCb, CallZomeRequest, CallZomeRequestSigned, DisableCloneCellRequest, EnableCloneCellRequest, EnableCloneCellResponse, NetworkInfoRequest, NetworkInfoResponse } from "../app/index.js";
4
- import { CreateCloneCellRequest, CreateCloneCellResponse, DisableCloneCellResponse } from "../index.js";
5
- /**
6
- * @public
7
- */
8
- export type NonProvenanceCallZomeRequest = Omit<CallZomeRequest, "provenance">;
9
- /**
10
- * @public
11
- */
12
- export type RoleNameCallZomeRequest = Omit<NonProvenanceCallZomeRequest, "cell_id"> & {
13
- role_name: RoleName;
14
- };
15
- /**
16
- * @public
17
- */
18
- export type RoleNameCallZomeRequestSigned = Omit<CallZomeRequestSigned, "cell_id"> & {
19
- role_name: RoleName;
20
- };
21
- /**
22
- * @public
23
- */
24
- export type AppAgentCallZomeRequest = NonProvenanceCallZomeRequest | RoleNameCallZomeRequest | CallZomeRequestSigned | RoleNameCallZomeRequestSigned;
25
- /**
26
- * @public
27
- */
28
- export type AppCreateCloneCellRequest = Omit<CreateCloneCellRequest, "app_id">;
29
- /**
30
- * @public
31
- */
32
- export type AppEnableCloneCellRequest = Omit<EnableCloneCellRequest, "app_id">;
33
- /**
34
- * @public
35
- */
36
- export type AppDisableCloneCellRequest = Omit<DisableCloneCellRequest, "app_id">;
37
- /**
38
- * @public
39
- */
40
- export type AppAgentNetworkInfoRequest = Omit<NetworkInfoRequest, "agent_pub_key">;
41
- /**
42
- * @public
43
- */
44
- export interface AppAgentEvents {
45
- signal: AppSignal;
46
- }
47
- /**
48
- * @public
49
- */
50
- export interface AppAgentClient {
51
- callZome(args: AppAgentCallZomeRequest, timeout?: number): Promise<any>;
52
- on<Name extends keyof AppAgentEvents>(eventName: Name | readonly Name[], listener: AppSignalCb): UnsubscribeFunction;
53
- appInfo(): Promise<AppInfoResponse>;
54
- myPubKey: AgentPubKey;
55
- createCloneCell(args: AppCreateCloneCellRequest): Promise<CreateCloneCellResponse>;
56
- enableCloneCell(args: AppEnableCloneCellRequest): Promise<EnableCloneCellResponse>;
57
- disableCloneCell(args: AppDisableCloneCellRequest): Promise<DisableCloneCellResponse>;
58
- networkInfo(args: AppAgentNetworkInfoRequest): Promise<NetworkInfoResponse>;
59
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,86 +0,0 @@
1
- import Emittery, { UnsubscribeFunction } from "emittery";
2
- import { AgentPubKey, CellId, InstalledAppId, RoleName } from "../../types.js";
3
- import { AppInfo } from "../admin/types.js";
4
- import { AppSignalCb, CallZomeResponse, CreateCloneCellResponse, DisableCloneCellResponse, EnableCloneCellResponse, NetworkInfoResponse } from "../app/types.js";
5
- import { AppWebsocket } from "../app/websocket.js";
6
- import { WebsocketConnectionOptions } from "../common.js";
7
- import { AppAgentCallZomeRequest, AppAgentClient, AppAgentEvents, AppAgentNetworkInfoRequest, AppCreateCloneCellRequest, AppDisableCloneCellRequest, AppEnableCloneCellRequest } from "./types.js";
8
- /**
9
- * A class to establish a websocket connection to an App interface, for a
10
- * specific agent and app.
11
- *
12
- * @public
13
- */
14
- export declare class AppAgentWebsocket implements AppAgentClient {
15
- readonly appWebsocket: AppWebsocket;
16
- installedAppId: InstalledAppId;
17
- cachedAppInfo?: AppInfo | null;
18
- myPubKey: AgentPubKey;
19
- readonly emitter: Emittery<AppAgentEvents>;
20
- private constructor();
21
- /**
22
- * Request the app's info, including all cell infos.
23
- *
24
- * @returns The app's {@link AppInfo}.
25
- */
26
- appInfo(): Promise<AppInfo>;
27
- /**
28
- * Instance factory for creating AppAgentWebsockets.
29
- *
30
- * @param installed_app_id - ID of the App to link to.
31
- * @param options - {@link (WebsocketConnectionOptions:interface)}
32
- * @returns A new instance of an AppAgentWebsocket.
33
- */
34
- static connect(installed_app_id: InstalledAppId, options?: WebsocketConnectionOptions): Promise<AppAgentWebsocket>;
35
- /**
36
- * Get a cell id by its role name or clone id.
37
- *
38
- * @param roleName - The role name or clone id of the cell.
39
- * @param appInfo - The app info containing all cell infos.
40
- * @returns The cell id or throws an error if not found.
41
- */
42
- getCellIdFromRoleName(roleName: RoleName, appInfo: AppInfo): CellId;
43
- /**
44
- * Call a zome.
45
- *
46
- * @param request - The zome call arguments.
47
- * @param timeout - A timeout to override the default.
48
- * @returns The zome call's response.
49
- */
50
- callZome(request: AppAgentCallZomeRequest, timeout?: number): Promise<CallZomeResponse>;
51
- /**
52
- * Clone an existing provisioned cell.
53
- *
54
- * @param args - Specify the cell to clone.
55
- * @returns The created clone cell.
56
- */
57
- createCloneCell(args: AppCreateCloneCellRequest): Promise<CreateCloneCellResponse>;
58
- /**
59
- * Enable a disabled clone cell.
60
- *
61
- * @param args - Specify the clone cell to enable.
62
- * @returns The enabled clone cell.
63
- */
64
- enableCloneCell(args: AppEnableCloneCellRequest): Promise<EnableCloneCellResponse>;
65
- /**
66
- * Disable an enabled clone cell.
67
- *
68
- * @param args - Specify the clone cell to disable.
69
- */
70
- disableCloneCell(args: AppDisableCloneCellRequest): Promise<DisableCloneCellResponse>;
71
- /**
72
- * Request network info about gossip status.
73
- * @param args - Specify the DNAs for which you want network info
74
- * @returns Network info for the specified DNAs
75
- */
76
- networkInfo(args: AppAgentNetworkInfoRequest): Promise<NetworkInfoResponse>;
77
- /**
78
- * Register an event listener for signals.
79
- *
80
- * @param eventName - Event name to listen to (currently only "signal").
81
- * @param listener - The function to call when event is triggered.
82
- * @returns A function to unsubscribe the event listener.
83
- */
84
- on<Name extends keyof AppAgentEvents>(eventName: Name | readonly Name[], listener: AppSignalCb): UnsubscribeFunction;
85
- private containsCell;
86
- }
@@ -1,209 +0,0 @@
1
- import Emittery from "emittery";
2
- import { omit } from "lodash-es";
3
- import { getLauncherEnvironment } from "../../environments/launcher.js";
4
- import { CellType } from "../admin/types.js";
5
- import { AppWebsocket } from "../app/websocket.js";
6
- import { HolochainError, getBaseRoleNameFromCloneId, isCloneId, } from "../common.js";
7
- /**
8
- * A class to establish a websocket connection to an App interface, for a
9
- * specific agent and app.
10
- *
11
- * @public
12
- */
13
- export class AppAgentWebsocket {
14
- appWebsocket;
15
- installedAppId;
16
- cachedAppInfo;
17
- myPubKey;
18
- emitter;
19
- constructor(appWebsocket, installedAppId, myPubKey) {
20
- this.appWebsocket = appWebsocket;
21
- this.cachedAppInfo = null;
22
- this.emitter = new Emittery();
23
- // Ensure all super methods are bound to this instance because Emittery relies on `this` being the instance.
24
- // Please retain until the upstream is fixed https://github.com/sindresorhus/emittery/issues/86.
25
- Object.getOwnPropertyNames(Emittery.prototype).forEach((name) => {
26
- const to_bind = this.emitter[name];
27
- if (typeof to_bind === "function") {
28
- this.emitter[name] =
29
- to_bind.bind(this.emitter);
30
- }
31
- });
32
- const env = getLauncherEnvironment();
33
- this.installedAppId = env?.INSTALLED_APP_ID || installedAppId;
34
- this.myPubKey = myPubKey;
35
- this.appWebsocket.on("signal", (signal) => {
36
- if (this.containsCell(signal.cell_id)) {
37
- this.emitter.emit("signal", signal);
38
- }
39
- });
40
- }
41
- /**
42
- * Request the app's info, including all cell infos.
43
- *
44
- * @returns The app's {@link AppInfo}.
45
- */
46
- async appInfo() {
47
- const appInfo = await this.appWebsocket.appInfo({
48
- installed_app_id: this.installedAppId,
49
- });
50
- if (!appInfo) {
51
- throw new HolochainError("AppNotFound", `App info not found for the provided id "${this.installedAppId}". App needs to be installed and enabled.`);
52
- }
53
- this.cachedAppInfo = appInfo;
54
- return appInfo;
55
- }
56
- /**
57
- * Instance factory for creating AppAgentWebsockets.
58
- *
59
- * @param installed_app_id - ID of the App to link to.
60
- * @param options - {@link (WebsocketConnectionOptions:interface)}
61
- * @returns A new instance of an AppAgentWebsocket.
62
- */
63
- static async connect(installed_app_id, options = {}) {
64
- const appWebsocket = await AppWebsocket.connect(options);
65
- const appInfo = await appWebsocket.appInfo({ installed_app_id });
66
- if (!appInfo) {
67
- throw new HolochainError("AppNotFound", `App info not found for the provided id "${installed_app_id}". App needs to be installed and enabled.`);
68
- }
69
- const appAgentWs = new AppAgentWebsocket(appWebsocket, installed_app_id, appInfo.agent_pub_key);
70
- appAgentWs.cachedAppInfo = appInfo;
71
- return appAgentWs;
72
- }
73
- /**
74
- * Get a cell id by its role name or clone id.
75
- *
76
- * @param roleName - The role name or clone id of the cell.
77
- * @param appInfo - The app info containing all cell infos.
78
- * @returns The cell id or throws an error if not found.
79
- */
80
- getCellIdFromRoleName(roleName, appInfo) {
81
- if (isCloneId(roleName)) {
82
- const baseRoleName = getBaseRoleNameFromCloneId(roleName);
83
- if (!(baseRoleName in appInfo.cell_info)) {
84
- throw new HolochainError("NoCellForRoleName", `no cell found with role_name ${roleName}`);
85
- }
86
- const cloneCell = appInfo.cell_info[baseRoleName].find((c) => CellType.Cloned in c && c[CellType.Cloned].clone_id === roleName);
87
- if (!cloneCell || !(CellType.Cloned in cloneCell)) {
88
- throw new HolochainError("NoCellForCloneId", `no clone cell found with clone id ${roleName}`);
89
- }
90
- return cloneCell[CellType.Cloned].cell_id;
91
- }
92
- if (!(roleName in appInfo.cell_info)) {
93
- throw new HolochainError("NoCellForRoleName", `no cell found with role_name ${roleName}`);
94
- }
95
- const cell = appInfo.cell_info[roleName].find((c) => CellType.Provisioned in c);
96
- if (!cell || !(CellType.Provisioned in cell)) {
97
- throw new HolochainError("NoProvisionedCellForRoleName", `no provisioned cell found with role_name ${roleName}`);
98
- }
99
- return cell[CellType.Provisioned].cell_id;
100
- }
101
- /**
102
- * Call a zome.
103
- *
104
- * @param request - The zome call arguments.
105
- * @param timeout - A timeout to override the default.
106
- * @returns The zome call's response.
107
- */
108
- async callZome(request, timeout) {
109
- if (!("provenance" in request)) {
110
- request = {
111
- ...request,
112
- provenance: this.myPubKey,
113
- };
114
- }
115
- if ("role_name" in request && request.role_name) {
116
- const appInfo = this.cachedAppInfo || (await this.appInfo());
117
- const cell_id = this.getCellIdFromRoleName(request.role_name, appInfo);
118
- const zomeCallPayload = {
119
- ...omit(request, "role_name"),
120
- provenance: this.myPubKey,
121
- cell_id: [cell_id[0], cell_id[1]],
122
- };
123
- return this.appWebsocket.callZome(zomeCallPayload, timeout);
124
- }
125
- else if ("cell_id" in request && request.cell_id) {
126
- return this.appWebsocket.callZome(request, timeout);
127
- }
128
- throw new HolochainError("MissingRoleNameOrCellId", "callZome requires a role_name or cell_id argument");
129
- }
130
- /**
131
- * Clone an existing provisioned cell.
132
- *
133
- * @param args - Specify the cell to clone.
134
- * @returns The created clone cell.
135
- */
136
- async createCloneCell(args) {
137
- const clonedCell = this.appWebsocket.createCloneCell({
138
- app_id: this.installedAppId,
139
- ...args,
140
- });
141
- this.cachedAppInfo = undefined;
142
- return clonedCell;
143
- }
144
- /**
145
- * Enable a disabled clone cell.
146
- *
147
- * @param args - Specify the clone cell to enable.
148
- * @returns The enabled clone cell.
149
- */
150
- async enableCloneCell(args) {
151
- return this.appWebsocket.enableCloneCell({
152
- app_id: this.installedAppId,
153
- ...args,
154
- });
155
- }
156
- /**
157
- * Disable an enabled clone cell.
158
- *
159
- * @param args - Specify the clone cell to disable.
160
- */
161
- async disableCloneCell(args) {
162
- return this.appWebsocket.disableCloneCell({
163
- app_id: this.installedAppId,
164
- ...args,
165
- });
166
- }
167
- /**
168
- * Request network info about gossip status.
169
- * @param args - Specify the DNAs for which you want network info
170
- * @returns Network info for the specified DNAs
171
- */
172
- async networkInfo(args) {
173
- return this.appWebsocket.networkInfo({
174
- ...args,
175
- agent_pub_key: this.myPubKey,
176
- });
177
- }
178
- /**
179
- * Register an event listener for signals.
180
- *
181
- * @param eventName - Event name to listen to (currently only "signal").
182
- * @param listener - The function to call when event is triggered.
183
- * @returns A function to unsubscribe the event listener.
184
- */
185
- on(eventName, listener) {
186
- return this.emitter.on(eventName, listener);
187
- }
188
- containsCell(cellId) {
189
- const appInfo = this.cachedAppInfo;
190
- if (!appInfo) {
191
- return false;
192
- }
193
- for (const roleName of Object.keys(appInfo.cell_info)) {
194
- for (const cellInfo of appInfo.cell_info[roleName]) {
195
- const currentCellId = CellType.Provisioned in cellInfo
196
- ? cellInfo[CellType.Provisioned].cell_id
197
- : CellType.Cloned in cellInfo
198
- ? cellInfo[CellType.Cloned].cell_id
199
- : undefined;
200
- if (currentCellId && isSameCell(currentCellId, cellId)) {
201
- return true;
202
- }
203
- }
204
- }
205
- return false;
206
- }
207
- }
208
- const isSameCell = (cellId1, cellId2) => cellId1[0].every((byte, index) => byte === cellId2[0][index]) &&
209
- cellId1[1].every((byte, index) => byte === cellId2[1][index]);