@ddd-qc/cell-proxy 0.10.0 → 0.10.1

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/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # cell-proxy
2
2
 
3
3
  **Compatible with:**
4
- - **HDK v0.1.0-beta-rc.1** & **HDI v0.2.0-beta-rc.2**
5
- - **@holochain/client v0.11.2**
4
+ - **HDK v0.1.0-beta-rc.1** & **HDI v0.2.0-beta-rc.1**
5
+ - **@holochain/client v0.11.9**
6
6
  -
7
7
  Proxy classes and helpers for managing a [Holochain](https://www.npmjs.com/package/@holochain/client) AppWebsocket and calling zome functions on cells.
8
8
  The intent is to make the development of web UI of Holochain apps in javascript / typescript faster & easier by providing a straightforward API for communicating with a Conductor, and some basic logging features.
@@ -1,58 +1,58 @@
1
- import { CallZomeRequest, CapSecret, ZomeName, Cell } from "@holochain/client";
2
- import { ConductorAppProxy } from "./ConductorAppProxy";
3
- import { Empty } from "./mixins";
4
- export interface RequestLog {
5
- request: CallZomeRequest;
6
- timeout: number;
7
- requestTimestamp: number;
8
- executionTimestamp: number;
9
- }
10
- export interface ResponseLog {
11
- success?: any;
12
- failure?: any;
13
- timestamp: number;
14
- requestIndex: number;
15
- }
16
- declare const CellProxy_base: (abstract new (...args: any[]) => {
17
- _cell?: Cell;
18
- readonly cell: Cell;
19
- readonly cellId: import("@holochain/client").CellId;
20
- readonly dnaHash: string;
21
- readonly agentPubKey: string; /** -- Fields -- */
22
- }) & typeof Empty;
23
- /**
24
- * Proxy for a running DNA.
25
- * It logs and queues ZomeCalls.
26
- * It holds a reference to its ConductorAppProxy and its InstalledCell.
27
- * This class is expected to be used by ZomeProxies.
28
- */
29
- export declare class CellProxy extends CellProxy_base {
30
- private _conductor;
31
- /** Ctor */
32
- constructor(_conductor: ConductorAppProxy, cell: Cell, defaultTimeout?: number);
33
- /** -- Fields -- */
34
- defaultTimeout: number;
35
- /** append only logs */
36
- private _requestLog;
37
- private _responseLog;
38
- private _canCallBlocking;
39
- /** -- Methods -- */
40
- dumpSignals(): void;
41
- /** Pass call request to conductor proxy and log it */
42
- executeZomeCall(reqLog: RequestLog): Promise<ResponseLog>;
43
- /**
44
- * callZome() with "Mutex" (for calls that writes to source-chain)
45
- * TODO: Implement call queue instead of mutex
46
- */
47
- callZomeBlocking(zome_name: ZomeName, fn_name: string, payload: any, cap_secret: CapSecret | null, timeout?: number): Promise<any>;
48
- /** */
49
- callZome(zome_name: ZomeName, fn_name: string, payload: any, cap_secret: CapSecret | null, timeout?: number): Promise<any>;
50
- /**
51
- * Calls the `entry_defs()` zome function and
52
- * returns an array of all the zome's AppEntryDefNames and visibility
53
- */
54
- callEntryDefs(zomeName: ZomeName): Promise<[string, boolean][]>;
55
- /** */
56
- dumpLogs(zomeName?: ZomeName): void;
57
- }
58
- export {};
1
+ import { CallZomeRequest, CapSecret, ZomeName, Cell } from "@holochain/client";
2
+ import { ConductorAppProxy } from "./ConductorAppProxy";
3
+ import { Empty } from "./mixins";
4
+ export interface RequestLog {
5
+ request: CallZomeRequest;
6
+ timeout: number;
7
+ requestTimestamp: number;
8
+ executionTimestamp: number;
9
+ }
10
+ export interface ResponseLog {
11
+ success?: any;
12
+ failure?: any;
13
+ timestamp: number;
14
+ requestIndex: number;
15
+ }
16
+ declare const CellProxy_base: (abstract new (...args: any[]) => {
17
+ _cell?: Cell;
18
+ readonly cell: Cell;
19
+ readonly cellId: import("@holochain/client").CellId;
20
+ readonly dnaHash: string;
21
+ readonly agentPubKey: string; /** -- Fields -- */
22
+ }) & typeof Empty;
23
+ /**
24
+ * Proxy for a running DNA.
25
+ * It logs and queues ZomeCalls.
26
+ * It holds a reference to its ConductorAppProxy and its InstalledCell.
27
+ * This class is expected to be used by ZomeProxies.
28
+ */
29
+ export declare class CellProxy extends CellProxy_base {
30
+ private _conductor;
31
+ /** Ctor */
32
+ constructor(_conductor: ConductorAppProxy, cell: Cell, defaultTimeout?: number);
33
+ /** -- Fields -- */
34
+ defaultTimeout: number;
35
+ /** append only logs */
36
+ private _requestLog;
37
+ private _responseLog;
38
+ private _canCallBlocking;
39
+ /** -- Methods -- */
40
+ dumpSignals(): void;
41
+ /** Pass call request to conductor proxy and log it */
42
+ executeZomeCall(reqLog: RequestLog): Promise<ResponseLog>;
43
+ /**
44
+ * callZome() with "Mutex" (for calls that writes to source-chain)
45
+ * TODO: Implement call queue instead of mutex
46
+ */
47
+ callZomeBlocking(zome_name: ZomeName, fn_name: string, payload: any, cap_secret: CapSecret | null, timeout?: number): Promise<any>;
48
+ /** */
49
+ callZome(zome_name: ZomeName, fn_name: string, payload: any, cap_secret: CapSecret | null, timeout?: number): Promise<any>;
50
+ /**
51
+ * Calls the `entry_defs()` zome function and
52
+ * returns an array of all the zome's AppEntryDefNames and visibility
53
+ */
54
+ callEntryDefs(zomeName: ZomeName): Promise<[string, boolean][]>;
55
+ /** */
56
+ dumpLogs(zomeName?: ZomeName): void;
57
+ }
58
+ export {};
package/dist/CellProxy.js CHANGED
@@ -1,166 +1,166 @@
1
- import { __awaiter } from "tslib";
2
- import { encodeHashToBase64 } from "@holochain/client";
3
- import { anyToB64, delay, prettyDate, prettyDuration } from "./utils";
4
- import { CellMixin, Empty } from "./mixins";
5
- /**
6
- * Proxy for a running DNA.
7
- * It logs and queues ZomeCalls.
8
- * It holds a reference to its ConductorAppProxy and its InstalledCell.
9
- * This class is expected to be used by ZomeProxies.
10
- */
11
- export class CellProxy extends CellMixin(Empty) {
12
- /** Ctor */
13
- constructor(_conductor, cell,
14
- //public readonly dnaDef: MyDnaDef,
15
- defaultTimeout) {
16
- super();
17
- this._conductor = _conductor;
18
- //private _blockingRequestQueue: Queue<RequestLog> = new Queue();
19
- /** append only logs */
20
- this._requestLog = [];
21
- this._responseLog = [];
22
- this._canCallBlocking = true;
23
- this._cell = cell;
24
- console.log(`CellProxy.ctor`, cell);
25
- this.defaultTimeout = defaultTimeout ? defaultTimeout : 10 * 1000;
26
- }
27
- // /** -- ICell interface -- */
28
- //
29
- // get dnaHash(): DnaHashB64 { return encodeHashToBase64(this.cell.cell_id[0]) }
30
- // get agentPubKey(): AgentPubKeyB64 { return encodeHashToBase64(this.cell.cell_id[1]) }
31
- /** -- Methods -- */
32
- // /** */
33
- // addSignalHandler(handler: AppSignalCb): SignalUnsubscriber {
34
- // return this._conductor.addSignalHandler(handler, this.cellId);
35
- // }
36
- dumpSignals() {
37
- this._conductor.dumpSignals(this.cell.cell_id);
38
- }
39
- /** Pass call request to conductor proxy and log it */
40
- executeZomeCall(reqLog) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- reqLog.executionTimestamp = Date.now();
43
- const requestIndex = this._requestLog.length;
44
- this._requestLog.push(reqLog);
45
- try {
46
- const response = yield this._conductor.callZome(reqLog.request, reqLog.timeout);
47
- const respLog = { requestIndex, success: response, timestamp: Date.now() };
48
- this._responseLog.push(respLog);
49
- return respLog;
50
- }
51
- catch (e) {
52
- const respLog = { requestIndex, failure: e, timestamp: Date.now() };
53
- this._responseLog.push(respLog);
54
- return respLog;
55
- }
56
- });
57
- }
58
- /**
59
- * callZome() with "Mutex" (for calls that writes to source-chain)
60
- * TODO: Implement call queue instead of mutex
61
- */
62
- callZomeBlocking(zome_name, fn_name, payload, cap_secret, timeout) {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- timeout = timeout ? timeout : this.defaultTimeout;
65
- const req = {
66
- cap_secret, zome_name, fn_name, payload,
67
- cell_id: this.cell.cell_id,
68
- provenance: this.cell.cell_id[1],
69
- };
70
- const log = { request: req, timeout, requestTimestamp: Date.now() };
71
- while (!this._canCallBlocking && Date.now() - log.requestTimestamp < timeout) {
72
- yield delay(1);
73
- }
74
- if (Date.now() - log.requestTimestamp >= timeout) {
75
- console.warn({ requestLogs: this._requestLog });
76
- return Promise.reject("Waiting for zomeCall execution timed-out");
77
- }
78
- this._canCallBlocking = false;
79
- const respLog = yield this.executeZomeCall(log);
80
- this._canCallBlocking = true;
81
- if (respLog.failure) {
82
- this.dumpSignals();
83
- this.dumpLogs(zome_name);
84
- return Promise.reject(respLog.failure);
85
- }
86
- return respLog.success;
87
- });
88
- }
89
- /** */
90
- callZome(zome_name, fn_name, payload, cap_secret, timeout) {
91
- return __awaiter(this, void 0, void 0, function* () {
92
- timeout = timeout ? timeout : this.defaultTimeout;
93
- const req = {
94
- cap_secret, zome_name, fn_name, payload,
95
- cell_id: this.cell.cell_id,
96
- provenance: this.cell.cell_id[1],
97
- };
98
- const log = { request: req, timeout, requestTimestamp: Date.now() };
99
- const respLog = yield this.executeZomeCall(log);
100
- if (respLog.failure) {
101
- this.dumpSignals();
102
- this.dumpLogs(zome_name);
103
- return Promise.reject(respLog.failure);
104
- }
105
- return respLog.success;
106
- });
107
- }
108
- /**
109
- * Calls the `entry_defs()` zome function and
110
- * returns an array of all the zome's AppEntryDefNames and visibility
111
- */
112
- callEntryDefs(zomeName) {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- //console.log("callEntryDefs()", zomeName)
115
- try {
116
- const entryDefs = yield this.callZome(zomeName, "entry_defs", null, null, 2 * 1000);
117
- //console.debug("getEntryDefs() for " + this.zomeName + " result:")
118
- //console.log({entryDefs})
119
- let result = [];
120
- for (const def of entryDefs.Defs) {
121
- const name = def.id.App;
122
- result.push([name, def.visibility.hasOwnProperty('Public')]);
123
- }
124
- //console.log({result})
125
- return result;
126
- }
127
- catch (e) {
128
- console.error("Calling getEntryDefs() on " + zomeName + " failed: ");
129
- console.error({ e });
130
- return Promise.reject(e);
131
- }
132
- });
133
- }
134
- // /** TODO once we have getDnaDefinition() api */
135
- // dumpAllZomes() {
136
- // // FIXME get DNA DEF
137
- // for (const zomeName of dnaDef) {
138
- // this.dumpLogs(zomeName)
139
- // }
140
- // }
141
- /** */
142
- dumpLogs(zomeName) {
143
- let result = [];
144
- for (const response of this._responseLog) {
145
- const requestLog = this._requestLog[response.requestIndex];
146
- if (zomeName && requestLog.request.zome_name != zomeName) {
147
- continue;
148
- }
149
- const startTime = prettyDate(new Date(requestLog.requestTimestamp));
150
- const waitTime = prettyDuration(new Date(requestLog.executionTimestamp - requestLog.requestTimestamp));
151
- const duration = prettyDuration(new Date(response.timestamp - requestLog.requestTimestamp));
152
- const input = requestLog.request.payload instanceof Uint8Array ? encodeHashToBase64(requestLog.request.payload) : requestLog.request.payload;
153
- const output = anyToB64(response.failure ? response.failure : response.success);
154
- const log = zomeName
155
- ? { startTime, fnName: requestLog.request.fn_name, input, output, duration, waitTime }
156
- : { startTime, zomeName: requestLog.request.zome_name, fnName: requestLog.request.fn_name, input, output, duration, waitTime };
157
- result.push(log);
158
- }
159
- console.warn(`Dumping logs for cell "${this._conductor.getLocations(this.cellId)}"`);
160
- if (zomeName) {
161
- console.warn(` - For zome "${zomeName}"`);
162
- }
163
- console.table(result);
164
- }
165
- }
1
+ import { __awaiter } from "tslib";
2
+ import { encodeHashToBase64 } from "@holochain/client";
3
+ import { anyToB64, delay, prettyDate, prettyDuration } from "./utils";
4
+ import { CellMixin, Empty } from "./mixins";
5
+ /**
6
+ * Proxy for a running DNA.
7
+ * It logs and queues ZomeCalls.
8
+ * It holds a reference to its ConductorAppProxy and its InstalledCell.
9
+ * This class is expected to be used by ZomeProxies.
10
+ */
11
+ export class CellProxy extends CellMixin(Empty) {
12
+ /** Ctor */
13
+ constructor(_conductor, cell,
14
+ //public readonly dnaDef: MyDnaDef,
15
+ defaultTimeout) {
16
+ super();
17
+ this._conductor = _conductor;
18
+ //private _blockingRequestQueue: Queue<RequestLog> = new Queue();
19
+ /** append only logs */
20
+ this._requestLog = [];
21
+ this._responseLog = [];
22
+ this._canCallBlocking = true;
23
+ this._cell = cell;
24
+ console.log(`CellProxy.ctor`, cell);
25
+ this.defaultTimeout = defaultTimeout ? defaultTimeout : 10 * 1000;
26
+ }
27
+ // /** -- ICell interface -- */
28
+ //
29
+ // get dnaHash(): DnaHashB64 { return encodeHashToBase64(this.cell.cell_id[0]) }
30
+ // get agentPubKey(): AgentPubKeyB64 { return encodeHashToBase64(this.cell.cell_id[1]) }
31
+ /** -- Methods -- */
32
+ // /** */
33
+ // addSignalHandler(handler: AppSignalCb): SignalUnsubscriber {
34
+ // return this._conductor.addSignalHandler(handler, this.cellId);
35
+ // }
36
+ dumpSignals() {
37
+ this._conductor.dumpSignals(this.cell.cell_id);
38
+ }
39
+ /** Pass call request to conductor proxy and log it */
40
+ executeZomeCall(reqLog) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ reqLog.executionTimestamp = Date.now();
43
+ const requestIndex = this._requestLog.length;
44
+ this._requestLog.push(reqLog);
45
+ try {
46
+ const response = yield this._conductor.callZome(reqLog.request, reqLog.timeout);
47
+ const respLog = { requestIndex, success: response, timestamp: Date.now() };
48
+ this._responseLog.push(respLog);
49
+ return respLog;
50
+ }
51
+ catch (e) {
52
+ const respLog = { requestIndex, failure: e, timestamp: Date.now() };
53
+ this._responseLog.push(respLog);
54
+ return respLog;
55
+ }
56
+ });
57
+ }
58
+ /**
59
+ * callZome() with "Mutex" (for calls that writes to source-chain)
60
+ * TODO: Implement call queue instead of mutex
61
+ */
62
+ callZomeBlocking(zome_name, fn_name, payload, cap_secret, timeout) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ timeout = timeout ? timeout : this.defaultTimeout;
65
+ const req = {
66
+ cap_secret, zome_name, fn_name, payload,
67
+ cell_id: this.cell.cell_id,
68
+ provenance: this.cell.cell_id[1],
69
+ };
70
+ const log = { request: req, timeout, requestTimestamp: Date.now() };
71
+ while (!this._canCallBlocking && Date.now() - log.requestTimestamp < timeout) {
72
+ yield delay(1);
73
+ }
74
+ if (Date.now() - log.requestTimestamp >= timeout) {
75
+ console.warn({ requestLogs: this._requestLog });
76
+ return Promise.reject("Waiting for zomeCall execution timed-out");
77
+ }
78
+ this._canCallBlocking = false;
79
+ const respLog = yield this.executeZomeCall(log);
80
+ this._canCallBlocking = true;
81
+ if (respLog.failure) {
82
+ this.dumpSignals();
83
+ this.dumpLogs(zome_name);
84
+ return Promise.reject(respLog.failure);
85
+ }
86
+ return respLog.success;
87
+ });
88
+ }
89
+ /** */
90
+ callZome(zome_name, fn_name, payload, cap_secret, timeout) {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ timeout = timeout ? timeout : this.defaultTimeout;
93
+ const req = {
94
+ cap_secret, zome_name, fn_name, payload,
95
+ cell_id: this.cell.cell_id,
96
+ provenance: this.cell.cell_id[1],
97
+ };
98
+ const log = { request: req, timeout, requestTimestamp: Date.now() };
99
+ const respLog = yield this.executeZomeCall(log);
100
+ if (respLog.failure) {
101
+ this.dumpSignals();
102
+ this.dumpLogs(zome_name);
103
+ return Promise.reject(respLog.failure);
104
+ }
105
+ return respLog.success;
106
+ });
107
+ }
108
+ /**
109
+ * Calls the `entry_defs()` zome function and
110
+ * returns an array of all the zome's AppEntryDefNames and visibility
111
+ */
112
+ callEntryDefs(zomeName) {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ //console.log("callEntryDefs()", zomeName)
115
+ try {
116
+ const entryDefs = yield this.callZome(zomeName, "entry_defs", null, null, 2 * 1000);
117
+ //console.debug("getEntryDefs() for " + this.zomeName + " result:")
118
+ //console.log({entryDefs})
119
+ let result = [];
120
+ for (const def of entryDefs.Defs) {
121
+ const name = def.id.App;
122
+ result.push([name, def.visibility.hasOwnProperty('Public')]);
123
+ }
124
+ //console.log({result})
125
+ return result;
126
+ }
127
+ catch (e) {
128
+ console.error("Calling getEntryDefs() on " + zomeName + " failed: ");
129
+ console.error({ e });
130
+ return Promise.reject(e);
131
+ }
132
+ });
133
+ }
134
+ // /** TODO once we have getDnaDefinition() api */
135
+ // dumpAllZomes() {
136
+ // // FIXME get DNA DEF
137
+ // for (const zomeName of dnaDef) {
138
+ // this.dumpLogs(zomeName)
139
+ // }
140
+ // }
141
+ /** */
142
+ dumpLogs(zomeName) {
143
+ let result = [];
144
+ for (const response of this._responseLog) {
145
+ const requestLog = this._requestLog[response.requestIndex];
146
+ if (zomeName && requestLog.request.zome_name != zomeName) {
147
+ continue;
148
+ }
149
+ const startTime = prettyDate(new Date(requestLog.requestTimestamp));
150
+ const waitTime = prettyDuration(new Date(requestLog.executionTimestamp - requestLog.requestTimestamp));
151
+ const duration = prettyDuration(new Date(response.timestamp - requestLog.requestTimestamp));
152
+ const input = requestLog.request.payload instanceof Uint8Array ? encodeHashToBase64(requestLog.request.payload) : requestLog.request.payload;
153
+ const output = anyToB64(response.failure ? response.failure : response.success);
154
+ const log = zomeName
155
+ ? { startTime, fnName: requestLog.request.fn_name, input, output, duration, waitTime }
156
+ : { startTime, zomeName: requestLog.request.zome_name, fnName: requestLog.request.fn_name, input, output, duration, waitTime };
157
+ result.push(log);
158
+ }
159
+ console.warn(`Dumping logs for cell "${this._conductor.getLocations(this.cellId)}"`);
160
+ if (zomeName) {
161
+ console.warn(` - For zome "${zomeName}"`);
162
+ }
163
+ console.table(result);
164
+ }
165
+ }
166
166
  //# sourceMappingURL=CellProxy.js.map
@@ -1,74 +1,74 @@
1
- import { AppApi, AppInfoRequest, AppInfoResponse, AppSignal, AppSignalCb, AppWebsocket, CallZomeRequest, CellId, InstalledAppId, InstalledCell, CreateCloneCellRequest, DisableCloneCellRequest, EnableCloneCellRequest, Cell } from "@holochain/client";
2
- import { CellProxy } from "./CellProxy";
3
- import { RoleCellsMap, BaseRoleName, CellsForRole } from "./types";
4
- import { HCL, HCLString } from "./hcl";
5
- /** */
6
- export interface SignalUnsubscriber {
7
- unsubscribe: () => void;
8
- }
9
- /**
10
- * Creates, connects and holds a appWebsocket.
11
- * Creates and holds Cell proxies for this appWebsocket.
12
- * Maintains a mapping between CellIds and HCLs
13
- * Handles SignalHandlers per HCL
14
- * Stores appSignal logs
15
- * TODO Implement Singleton per App port?
16
- */
17
- export declare class ConductorAppProxy implements AppApi {
18
- defaultTimeout: number;
19
- /** -- Fields -- */
20
- private _appWs;
21
- /** Signal log: [Timestamp, CellIdStr, Signal] */
22
- private _signalLogs;
23
- /** Map cells per App: InstalledAppId -> (BaseRoleName -> RoleInstalledCells) */
24
- private _cellsByApp;
25
- /** Map cell locations: CellIdStr -> HCL[] */
26
- private _hclMap;
27
- /** Store handlers per cell locaiton: HCLString -> AppSignalCb */
28
- private _signalHandlers;
29
- /** Store cell proxies per cell: CellIdStr -> CellProxy */
30
- private _cellProxies;
31
- /** -- Getters -- */
32
- /** */
33
- getAppCells(appId: InstalledAppId): RoleCellsMap | undefined;
34
- /** */
35
- getLocations(cellId: CellId): HCL[] | undefined;
36
- /** */
37
- getCell(hcl: HCL): Cell;
38
- /** Get stored CellProxy or attempt to create it */
39
- getCellProxy(cellIdOrLoc: HCL | CellId): CellProxy;
40
- /** */
41
- getAppRoles(installedAppId: InstalledAppId): BaseRoleName[] | undefined;
42
- /** */
43
- getClones(appId: InstalledAppId, baseRoleName: BaseRoleName): Cell[];
44
- createCloneCell(request: CreateCloneCellRequest): Promise<InstalledCell>;
45
- /** -- AppApi (Passthrough to appWebsocket) -- */
46
- enableCloneCell(request: EnableCloneCellRequest): Promise<InstalledCell>;
47
- disableCloneCell(request: DisableCloneCellRequest): Promise<void>;
48
- appInfo(args: AppInfoRequest): Promise<AppInfoResponse>;
49
- callZome(req: CallZomeRequest, timeout?: number): Promise<any>;
50
- /** -- Creation -- */
51
- /** async Factory */
52
- static new(port_or_socket: number | AppWebsocket, defaultTimeout?: number): Promise<ConductorAppProxy>;
53
- /** */
54
- private static fromSocket;
55
- /** Ctor */
56
- private constructor();
57
- /** -- Methods -- */
58
- /** */
59
- fetchCell(appId: InstalledAppId, cellId: CellId): Promise<Cell>;
60
- /** */
61
- fetchCells(appId: InstalledAppId, baseRoleName: BaseRoleName): Promise<CellsForRole>;
62
- /** */
63
- addClone(hcl: HCL, cloneCell: Cell): void;
64
- /** */
65
- createCellProxy(hcl: HCL): CellProxy;
66
- /** */
67
- onSignal(signal: AppSignal): void;
68
- /** Store signalHandler to internal handler array */
69
- addSignalHandler(handler: AppSignalCb, hcl?: HCLString): SignalUnsubscriber;
70
- /** Log all signals received */
71
- private logSignal;
72
- /** */
73
- dumpSignals(cellId?: CellId): void;
74
- }
1
+ import { AppApi, AppInfoRequest, AppInfoResponse, AppSignal, AppSignalCb, AppWebsocket, CallZomeRequest, CellId, InstalledAppId, InstalledCell, CreateCloneCellRequest, DisableCloneCellRequest, EnableCloneCellRequest, Cell } from "@holochain/client";
2
+ import { CellProxy } from "./CellProxy";
3
+ import { RoleCellsMap, BaseRoleName, CellsForRole } from "./types";
4
+ import { HCL, HCLString } from "./hcl";
5
+ /** */
6
+ export interface SignalUnsubscriber {
7
+ unsubscribe: () => void;
8
+ }
9
+ /**
10
+ * Creates, connects and holds a appWebsocket.
11
+ * Creates and holds Cell proxies for this appWebsocket.
12
+ * Maintains a mapping between CellIds and HCLs
13
+ * Handles SignalHandlers per HCL
14
+ * Stores appSignal logs
15
+ * TODO Implement Singleton per App port?
16
+ */
17
+ export declare class ConductorAppProxy implements AppApi {
18
+ defaultTimeout: number;
19
+ /** -- Fields -- */
20
+ private _appWs;
21
+ /** Signal log: [Timestamp, CellIdStr, Signal] */
22
+ private _signalLogs;
23
+ /** Map cells per App: InstalledAppId -> (BaseRoleName -> RoleInstalledCells) */
24
+ private _cellsByApp;
25
+ /** Map cell locations: CellIdStr -> HCL[] */
26
+ private _hclMap;
27
+ /** Store handlers per cell locaiton: HCLString -> AppSignalCb */
28
+ private _signalHandlers;
29
+ /** Store cell proxies per cell: CellIdStr -> CellProxy */
30
+ private _cellProxies;
31
+ /** -- Getters -- */
32
+ /** */
33
+ getAppCells(appId: InstalledAppId): RoleCellsMap | undefined;
34
+ /** */
35
+ getLocations(cellId: CellId): HCL[] | undefined;
36
+ /** */
37
+ getCell(hcl: HCL): Cell;
38
+ /** Get stored CellProxy or attempt to create it */
39
+ getCellProxy(cellIdOrLoc: HCL | CellId): CellProxy;
40
+ /** */
41
+ getAppRoles(installedAppId: InstalledAppId): BaseRoleName[] | undefined;
42
+ /** */
43
+ getClones(appId: InstalledAppId, baseRoleName: BaseRoleName): Cell[];
44
+ createCloneCell(request: CreateCloneCellRequest): Promise<InstalledCell>;
45
+ /** -- AppApi (Passthrough to appWebsocket) -- */
46
+ enableCloneCell(request: EnableCloneCellRequest): Promise<InstalledCell>;
47
+ disableCloneCell(request: DisableCloneCellRequest): Promise<void>;
48
+ appInfo(args: AppInfoRequest): Promise<AppInfoResponse>;
49
+ callZome(req: CallZomeRequest, timeout?: number): Promise<any>;
50
+ /** -- Creation -- */
51
+ /** async Factory */
52
+ static new(port_or_socket: number | AppWebsocket, defaultTimeout?: number): Promise<ConductorAppProxy>;
53
+ /** */
54
+ private static fromSocket;
55
+ /** Ctor */
56
+ private constructor();
57
+ /** -- Methods -- */
58
+ /** */
59
+ fetchCell(appId: InstalledAppId, cellId: CellId): Promise<Cell>;
60
+ /** */
61
+ fetchCells(appId: InstalledAppId, baseRoleName: BaseRoleName): Promise<CellsForRole>;
62
+ /** */
63
+ addClone(hcl: HCL, cloneCell: Cell): void;
64
+ /** */
65
+ createCellProxy(hcl: HCL): CellProxy;
66
+ /** */
67
+ onSignal(signal: AppSignal): void;
68
+ /** Store signalHandler to internal handler array */
69
+ addSignalHandler(handler: AppSignalCb, hcl?: HCLString): SignalUnsubscriber;
70
+ /** Log all signals received */
71
+ private logSignal;
72
+ /** */
73
+ dumpSignals(cellId?: CellId): void;
74
+ }