@ddd-qc/cell-proxy 0.19.19 → 0.20.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/dist/AppProxy.js CHANGED
@@ -1,298 +1,298 @@
1
- import { CellType, encodeHashToBase64, } from "@holochain/client";
2
- import { CellProxy } from "./CellProxy";
3
- import { CellIdStr } from "./types";
4
- import { areCellsEqual, prettyDate, printAppInfo } from "./utils";
5
- import { HCL } from "./hcl";
6
- import { Cell } from "./cell";
7
- /**
8
- * Creates and holds Cell proxies.
9
- * Maintains a mapping between CellIds and HCLs
10
- * Handles SignalHandlers per HCL
11
- * Stores appSignal logs
12
- * TODO Implement Singleton per App port?
13
- */
14
- export class AppProxy {
15
- /** -- Getters -- */
16
- /** Check this after connecting since AppWebsocket can shamelessly override the provided args. */
17
- get appIdOfShame() { return undefined; }
18
- /** */
19
- getAppCells(appId) {
20
- return this._cellsByApp[appId];
21
- }
22
- getCellName(hcl) { return this._cellNames[hcl.toString()]; }
23
- /** */
24
- getLocations(cellId) {
25
- return this._hclMap[CellIdStr(cellId)];
26
- }
27
- /** */
28
- getCell(hcl) {
29
- const roleCellsMap = this._cellsByApp[hcl.appId];
30
- if (!roleCellsMap)
31
- throw Error(`getCell() failed. No hApp with ID "${hcl.appId}" found.`);
32
- const roleCells = roleCellsMap[hcl.baseRoleName];
33
- if (!roleCells)
34
- throw Error(`getCell() failed: BaseRoleName "${hcl.baseRoleName}" not found in happ "${hcl.appId}"`);
35
- let cell = roleCells.provisioned;
36
- if (hcl.cloneId !== undefined) {
37
- cell = roleCells.clones[hcl.cloneId];
38
- if (!cell) {
39
- throw Error(`getCell() failed: clone "${hcl.cloneId}" not found for role "${hcl.toString()}"`);
40
- }
41
- }
42
- return new Cell(cell, hcl.appId, hcl.baseRoleName);
43
- }
44
- /** Get stored CellProxy or attempt to create it */
45
- getCellProxy(cellIdOrLoc) {
46
- if (cellIdOrLoc instanceof HCL) {
47
- const cell = this.getCell(cellIdOrLoc);
48
- const maybeProxy = this.getCellProxy(cell.id);
49
- if (!maybeProxy)
50
- throw Error("getCellProxy() failed. Proxy not found for cell " + CellIdStr(cell.id));
51
- return maybeProxy;
52
- }
53
- const sId = CellIdStr(cellIdOrLoc);
54
- const maybeProxy = this._cellProxies[sId];
55
- if (maybeProxy === undefined)
56
- throw Error("getCellProxy() failed. Proxy not found for cell " + sId);
57
- return maybeProxy;
58
- }
59
- /** */
60
- getAppRoles(installedAppId) {
61
- if (!this._cellsByApp[installedAppId])
62
- return undefined;
63
- return Object.values(this._cellsByApp[installedAppId]).map((roleCells) => {
64
- return roleCells.provisioned.name;
65
- });
66
- }
67
- /** */
68
- getClones(appId, baseRoleName) {
69
- const maybeApp = this._cellsByApp[appId];
70
- if (!maybeApp)
71
- return [];
72
- const roleInstalledCells = maybeApp[baseRoleName];
73
- if (!roleInstalledCells)
74
- return [];
75
- return Object.values(roleInstalledCells.clones);
76
- }
77
- async createCloneCell(request) {
78
- throw new Error("Method not implemented.");
79
- }
80
- /** -- AppApi -- */
81
- async enableCloneCell(request) {
82
- throw new Error("Method not implemented.");
83
- }
84
- async disableCloneCell(request) {
85
- throw new Error("Method not implemented.");
86
- }
87
- async appInfo(args) {
88
- throw new Error("Method not implemented.");
89
- }
90
- async callZome(req, timeout) {
91
- throw new Error("Method not implemented.");
92
- }
93
- /** -- Creation -- */
94
- /** Ctor */
95
- /*protected*/ constructor(defaultTimeout) {
96
- this.defaultTimeout = defaultTimeout;
97
- /** -- Fields -- */
98
- /** Signal log: [Timestamp, CellIdStr, Signal] */
99
- this._signalLogs = [];
100
- /** Map cells per App: InstalledAppId -> (BaseRoleName -> CellsForRole) */
101
- this._cellsByApp = {};
102
- /** Map cell locations: CellIdStr -> HCL[] */
103
- this._hclMap = {};
104
- /** Store handlers per cell location: HCLString -> AppSignalCb[] */
105
- this._signalHandlers = {};
106
- /** Store cell proxies per cell: CellIdStr -> CellProxy */
107
- this._cellProxies = {};
108
- /** Map HCLString: CloneId -> CloneName */
109
- this._cellNames = {}; // Provisioned cell's name is its baseRoleName so no need to map them
110
- /*const _unsub =*/ this.addSignalHandler((sig) => this.logSignal(sig));
111
- }
112
- /** -- Methods -- */
113
- /** */
114
- async fetchCell(appId, cellId) {
115
- const appInfo = await this.appInfo({ installed_app_id: appId });
116
- //console.log("fetchCell", appInfo);
117
- if (appInfo == null) {
118
- return Promise.reject(`getCell() failed. App "${appId}" not found"`);
119
- }
120
- for (const cellInfos of Object.values(appInfo.cell_info)) {
121
- for (const [baseRoleName, cellInfo] of Object.entries(cellInfos)) {
122
- let cell;
123
- try {
124
- cell = Cell.from(cellInfo, appId, baseRoleName);
125
- }
126
- catch (e) {
127
- // skip stem cell
128
- continue;
129
- }
130
- if (areCellsEqual(cell.id, cellId)) {
131
- return cell;
132
- }
133
- }
134
- }
135
- return Promise.reject("getCell() failed. Cell not found for app.");
136
- }
137
- /** Get all cells for a BaseRole in an app */
138
- async fetchCells(appId, baseRoleName) {
139
- /** Make sure hApp exists */
140
- const appInfo = await this.appInfo({ installed_app_id: appId });
141
- if (appInfo == null) {
142
- return Promise.reject(`fetchCells() failed. App "${appId}" not found`);
143
- }
144
- console.log("fetchCells() installedAppInfo:\n", printAppInfo(appInfo));
145
- /** Make sure app Object exists */
146
- if (!this._cellsByApp[appId]) {
147
- this._cellsByApp[appId] = {};
148
- }
149
- /** Get all cells with that baseRoleName */
150
- let provisioned;
151
- let clones = {};
152
- for (const [curBaseRoleName, cellInfos] of Object.entries(appInfo.cell_info)) {
153
- for (const cellInfo of Object.values(cellInfos)) {
154
- if (baseRoleName !== curBaseRoleName || CellType.Stem in cellInfo) {
155
- continue;
156
- }
157
- if (CellType.Cloned in cellInfo) {
158
- if (clones[cellInfo.cloned.clone_id]) {
159
- console.error(`fetchCells() Entry already exist for clone: "${cellInfo.cloned.clone_id}"`);
160
- }
161
- clones[cellInfo.cloned.clone_id] = cellInfo.cloned;
162
- }
163
- else {
164
- provisioned = cellInfo.provisioned;
165
- }
166
- }
167
- }
168
- if (typeof provisioned === 'undefined') {
169
- return Promise.reject("Provisioned cell not found for role " + baseRoleName);
170
- }
171
- let roleInstalledCells = { provisioned: provisioned, clones };
172
- /** Store it*/
173
- this._cellsByApp[appId][baseRoleName] = roleInstalledCells;
174
- return roleInstalledCells;
175
- }
176
- /** */
177
- addClone(hcl, cloneCell) {
178
- if (!this._cellsByApp[hcl.appId])
179
- throw Error("addClone() failed. no appId. " + hcl.toString());
180
- if (!this._cellsByApp[hcl.appId][hcl.baseRoleName])
181
- throw Error("addClone() failed. no baseRoleName. " + hcl.toString());
182
- if (hcl.cloneId === undefined)
183
- throw Error("addClone() failed. Cell is not a CloneCell: " + hcl.toString());
184
- // let cloneName = hcl.cloneId;
185
- // if (hcl.cloneId === undefined) {
186
- // const cloneIndex: number = Object.keys(this._cellsByApp[hcl.appId][hcl.baseRoleName].clones).length;
187
- // cloneName = createCloneName(hcl.baseRoleName, cloneIndex);
188
- // }
189
- this._cellsByApp[hcl.appId][hcl.baseRoleName].clones[cloneCell.clone_id] = cloneCell;
190
- // const sCellId = CellIdStr(cloneCell.cell_id);
191
- // console.log("CreateCellProxy() adding to hclMap", sCellId, cellLoc.asHcl())
192
- // if (this._hclMap[sCellId]) {
193
- // this._hclMap[sCellId].push(cellLoc.asHcl());
194
- // } else {
195
- // this._hclMap[sCellId] = [cellLoc.asHcl()];
196
- // }
197
- }
198
- /** */
199
- createCellProxy(hcl, cloneName) {
200
- console.log("createCellProxy() for", hcl.toString(), cloneName);
201
- /** Make sure cell exists */
202
- const cell = this.getCell(hcl);
203
- const sCellId = CellIdStr(cell.id);
204
- /** Create proxy for this cell if none exist yet, otherwise reuse */
205
- let cellProxy = this._cellProxies[sCellId];
206
- if (!cellProxy) {
207
- /** Create and store Proxy */
208
- cellProxy = new CellProxy(this, cell, this.defaultTimeout);
209
- this._cellProxies[sCellId] = cellProxy;
210
- }
211
- /** Create CellId -> HCL mapping */
212
- //console.log("CreateCellProxy() adding to hclMap", sCellId, hcl.toString())
213
- if (this._hclMap[sCellId]) {
214
- this._hclMap[sCellId].push(hcl);
215
- }
216
- else {
217
- this._hclMap[sCellId] = [hcl];
218
- }
219
- //console.log("createCellProxy() Currently stored hclMap:", this._hclMap);
220
- /** Associate cloneName if any */
221
- const name = cloneName ? cloneName : hcl.baseRoleName;
222
- this._cellNames[hcl.toString()] = name;
223
- /** Done */
224
- return cellProxy;
225
- }
226
- /** */
227
- onSignal(signal) {
228
- /** Grab cell specific handlers */
229
- const hcls = this.getLocations(signal.cell_id);
230
- const handlerss = hcls ? hcls.map((hcl) => this._signalHandlers[hcl.toString()]) : [];
231
- console.log("onSignal()", hcls ? hcls.toString() : "unknown cell: " + encodeHashToBase64(signal.cell_id[0]), handlerss);
232
- /** Grab common handler */
233
- const allHandlers = this._signalHandlers["__all"];
234
- if (allHandlers)
235
- handlerss.push(allHandlers);
236
- /** Send to all handlers */
237
- for (const handlers of handlerss) {
238
- for (const handler of handlers) {
239
- handler(signal);
240
- }
241
- }
242
- }
243
- /** Store signalHandler to internal handler array */
244
- addSignalHandler(handler, hcl) {
245
- console.log("addSignalHandler()", hcl);
246
- hcl = hcl ? hcl : "__all";
247
- //console.log("addSignalHandler()", hcl, Object.keys(this._signalHandlers));
248
- if (!this._signalHandlers[hcl]) {
249
- this._signalHandlers[hcl] = [handler];
250
- }
251
- else {
252
- this._signalHandlers[hcl].push(handler);
253
- }
254
- /* return tailored unsubscribe function to the caller */
255
- return {
256
- unsubscribe: () => {
257
- // FIXME
258
- // const maybeHandler = this._signalHandlers[hcl!]
259
- // if (!maybeHandler) {
260
- // console.warn("unsubscribe failed: Couldn't find signalHandler for", hcl)
261
- // return;
262
- // }
263
- // delete this._signalHandlers[hcl!];
264
- }
265
- };
266
- }
267
- /** Log all signals received */
268
- logSignal(signal) {
269
- this._signalLogs.push([Date.now(), CellIdStr(signal.cell_id), signal]);
270
- //console.log("signal logged", this._signalLogs)
271
- }
272
- /** */
273
- dumpSignals(cellId) {
274
- if (cellId) {
275
- const cellStr = CellIdStr(cellId);
276
- const hcls = this._hclMap[cellStr];
277
- const names = hcls.map((hcl) => this.getCellName(hcl));
278
- console.warn(`Dumping signal logs for cell "${names}"`);
279
- const logs = this._signalLogs
280
- .filter((log) => log[1] == cellStr)
281
- .map((log) => {
282
- return { timestamp: prettyDate(new Date(log[0])), zome: log[2].zome_name, payload: log[2].payload };
283
- });
284
- console.table(logs);
285
- }
286
- else {
287
- console.warn("Dumping all signal logs");
288
- const logs = this._signalLogs
289
- .map((log) => {
290
- const app = this._hclMap[log[1]][0].appId;
291
- const cell = this._hclMap[log[1]][0].roleName;
292
- return { timestamp: prettyDate(new Date(log[0])), app, cell, zome: log[2].zome_name, payload: log[2].payload };
293
- });
294
- console.table(logs);
295
- }
296
- }
297
- }
1
+ import { CellType, } from "@holochain/client";
2
+ import { CellProxy } from "./CellProxy";
3
+ import { CellIdStr } from "./types";
4
+ import { areCellsEqual, prettyDate, printAppInfo } from "./utils";
5
+ import { HCL } from "./hcl";
6
+ import { Cell } from "./cell";
7
+ /**
8
+ * Creates and holds Cell proxies.
9
+ * Maintains a mapping between CellIds and HCLs
10
+ * Handles SignalHandlers per HCL
11
+ * Stores appSignal logs
12
+ * TODO Implement Singleton per App port?
13
+ */
14
+ export class AppProxy {
15
+ /** -- Getters -- */
16
+ /** Check this after connecting since AppWebsocket can shamelessly override the provided args. */
17
+ get appIdOfShame() { return undefined; }
18
+ /** */
19
+ getAppCells(appId) {
20
+ return this._cellsByApp[appId];
21
+ }
22
+ getCellName(hcl) { return this._cellNames[hcl.toString()]; }
23
+ /** */
24
+ getLocations(cellId) {
25
+ return this._hclMap[CellIdStr(cellId)];
26
+ }
27
+ /** */
28
+ getCell(hcl) {
29
+ const roleCellsMap = this._cellsByApp[hcl.appId];
30
+ if (!roleCellsMap)
31
+ throw Error(`getCell() failed. No hApp with ID "${hcl.appId}" found.`);
32
+ const roleCells = roleCellsMap[hcl.baseRoleName];
33
+ if (!roleCells)
34
+ throw Error(`getCell() failed: BaseRoleName "${hcl.baseRoleName}" not found in happ "${hcl.appId}"`);
35
+ let cell = roleCells.provisioned;
36
+ if (hcl.cloneId !== undefined) {
37
+ cell = roleCells.clones[hcl.cloneId];
38
+ if (!cell) {
39
+ throw Error(`getCell() failed: clone "${hcl.cloneId}" not found for role "${hcl.toString()}"`);
40
+ }
41
+ }
42
+ return new Cell(cell, hcl.appId, hcl.baseRoleName);
43
+ }
44
+ /** Get stored CellProxy or attempt to create it */
45
+ getCellProxy(cellIdOrLoc) {
46
+ if (cellIdOrLoc instanceof HCL) {
47
+ const cell = this.getCell(cellIdOrLoc);
48
+ const maybeProxy = this.getCellProxy(cell.id);
49
+ if (!maybeProxy)
50
+ throw Error("getCellProxy() failed. Proxy not found for cell " + CellIdStr(cell.id));
51
+ return maybeProxy;
52
+ }
53
+ const sId = CellIdStr(cellIdOrLoc);
54
+ const maybeProxy = this._cellProxies[sId];
55
+ if (maybeProxy === undefined)
56
+ throw Error("getCellProxy() failed. Proxy not found for cell " + sId);
57
+ return maybeProxy;
58
+ }
59
+ /** */
60
+ getAppRoles(installedAppId) {
61
+ if (!this._cellsByApp[installedAppId])
62
+ return undefined;
63
+ return Object.values(this._cellsByApp[installedAppId]).map((roleCells) => {
64
+ return roleCells.provisioned.name;
65
+ });
66
+ }
67
+ /** */
68
+ getClones(appId, baseRoleName) {
69
+ const maybeApp = this._cellsByApp[appId];
70
+ if (!maybeApp)
71
+ return [];
72
+ const roleInstalledCells = maybeApp[baseRoleName];
73
+ if (!roleInstalledCells)
74
+ return [];
75
+ return Object.values(roleInstalledCells.clones);
76
+ }
77
+ async createCloneCell(request) {
78
+ throw new Error("Method not implemented.");
79
+ }
80
+ /** -- AppApi -- */
81
+ async enableCloneCell(request) {
82
+ throw new Error("Method not implemented.");
83
+ }
84
+ async disableCloneCell(request) {
85
+ throw new Error("Method not implemented.");
86
+ }
87
+ async appInfo(args) {
88
+ throw new Error("Method not implemented.");
89
+ }
90
+ async callZome(req, timeout) {
91
+ throw new Error("Method not implemented.");
92
+ }
93
+ /** -- Creation -- */
94
+ /** Ctor */
95
+ /*protected*/ constructor(defaultTimeout) {
96
+ this.defaultTimeout = defaultTimeout;
97
+ /** -- Fields -- */
98
+ /** Signal log: [Timestamp, CellIdStr, Signal] */
99
+ this._signalLogs = [];
100
+ /** Map cells per App: InstalledAppId -> (BaseRoleName -> CellsForRole) */
101
+ this._cellsByApp = {};
102
+ /** Map cell locations: CellIdStr -> HCL[] */
103
+ this._hclMap = {};
104
+ /** Store handlers per cell location: HCLString -> AppSignalCb[] */
105
+ this._signalHandlers = {};
106
+ /** Store cell proxies per cell: CellIdStr -> CellProxy */
107
+ this._cellProxies = {};
108
+ /** Map HCLString: CloneId -> CloneName */
109
+ this._cellNames = {}; // Provisioned cell's name is its baseRoleName so no need to map them
110
+ /*const _unsub =*/ this.addSignalHandler((sig) => this.logSignal(sig));
111
+ }
112
+ /** -- Methods -- */
113
+ /** */
114
+ async fetchCell(appId, cellId) {
115
+ const appInfo = await this.appInfo({ installed_app_id: appId });
116
+ //console.log("fetchCell", appInfo);
117
+ if (appInfo == null) {
118
+ return Promise.reject(`getCell() failed. App "${appId}" not found"`);
119
+ }
120
+ for (const cellInfos of Object.values(appInfo.cell_info)) {
121
+ for (const [baseRoleName, cellInfo] of Object.entries(cellInfos)) {
122
+ let cell;
123
+ try {
124
+ cell = Cell.from(cellInfo, appId, baseRoleName);
125
+ }
126
+ catch (e) {
127
+ // skip stem cell
128
+ continue;
129
+ }
130
+ if (areCellsEqual(cell.id, cellId)) {
131
+ return cell;
132
+ }
133
+ }
134
+ }
135
+ return Promise.reject("getCell() failed. Cell not found for app.");
136
+ }
137
+ /** Get all cells for a BaseRole in an app */
138
+ async fetchCells(appId, baseRoleName) {
139
+ /** Make sure hApp exists */
140
+ const appInfo = await this.appInfo({ installed_app_id: appId });
141
+ if (appInfo == null) {
142
+ return Promise.reject(`fetchCells() failed. App "${appId}" not found`);
143
+ }
144
+ console.log("fetchCells() installedAppInfo:\n", printAppInfo(appInfo));
145
+ /** Make sure app Object exists */
146
+ if (!this._cellsByApp[appId]) {
147
+ this._cellsByApp[appId] = {};
148
+ }
149
+ /** Get all cells with that baseRoleName */
150
+ let provisioned;
151
+ let clones = {};
152
+ for (const [curBaseRoleName, cellInfos] of Object.entries(appInfo.cell_info)) {
153
+ for (const cellInfo of Object.values(cellInfos)) {
154
+ if (baseRoleName !== curBaseRoleName || CellType.Stem in cellInfo) {
155
+ continue;
156
+ }
157
+ if (CellType.Cloned in cellInfo) {
158
+ if (clones[cellInfo.cloned.clone_id]) {
159
+ console.error(`fetchCells() Entry already exist for clone: "${cellInfo.cloned.clone_id}"`);
160
+ }
161
+ clones[cellInfo.cloned.clone_id] = cellInfo.cloned;
162
+ }
163
+ else {
164
+ provisioned = cellInfo.provisioned;
165
+ }
166
+ }
167
+ }
168
+ if (typeof provisioned === 'undefined') {
169
+ return Promise.reject("Provisioned cell not found for role " + baseRoleName);
170
+ }
171
+ let roleInstalledCells = { provisioned: provisioned, clones };
172
+ /** Store it*/
173
+ this._cellsByApp[appId][baseRoleName] = roleInstalledCells;
174
+ return roleInstalledCells;
175
+ }
176
+ /** */
177
+ addClone(hcl, cloneCell) {
178
+ if (!this._cellsByApp[hcl.appId])
179
+ throw Error("addClone() failed. no appId. " + hcl.toString());
180
+ if (!this._cellsByApp[hcl.appId][hcl.baseRoleName])
181
+ throw Error("addClone() failed. no baseRoleName. " + hcl.toString());
182
+ if (hcl.cloneId === undefined)
183
+ throw Error("addClone() failed. Cell is not a CloneCell: " + hcl.toString());
184
+ // let cloneName = hcl.cloneId;
185
+ // if (hcl.cloneId === undefined) {
186
+ // const cloneIndex: number = Object.keys(this._cellsByApp[hcl.appId][hcl.baseRoleName].clones).length;
187
+ // cloneName = createCloneName(hcl.baseRoleName, cloneIndex);
188
+ // }
189
+ this._cellsByApp[hcl.appId][hcl.baseRoleName].clones[cloneCell.clone_id] = cloneCell;
190
+ // const sCellId = CellIdStr(cloneCell.cell_id);
191
+ // console.log("CreateCellProxy() adding to hclMap", sCellId, cellLoc.asHcl())
192
+ // if (this._hclMap[sCellId]) {
193
+ // this._hclMap[sCellId].push(cellLoc.asHcl());
194
+ // } else {
195
+ // this._hclMap[sCellId] = [cellLoc.asHcl()];
196
+ // }
197
+ }
198
+ /** */
199
+ createCellProxy(hcl, cloneName) {
200
+ console.log("createCellProxy() for", hcl.toString(), cloneName);
201
+ /** Make sure cell exists */
202
+ const cell = this.getCell(hcl);
203
+ const sCellId = CellIdStr(cell.id);
204
+ /** Create proxy for this cell if none exist yet, otherwise reuse */
205
+ let cellProxy = this._cellProxies[sCellId];
206
+ if (!cellProxy) {
207
+ /** Create and store Proxy */
208
+ cellProxy = new CellProxy(this, cell, this.defaultTimeout);
209
+ this._cellProxies[sCellId] = cellProxy;
210
+ }
211
+ /** Create CellId -> HCL mapping */
212
+ //console.log("CreateCellProxy() adding to hclMap", sCellId, hcl.toString())
213
+ if (this._hclMap[sCellId]) {
214
+ this._hclMap[sCellId].push(hcl);
215
+ }
216
+ else {
217
+ this._hclMap[sCellId] = [hcl];
218
+ }
219
+ //console.log("createCellProxy() Currently stored hclMap:", this._hclMap);
220
+ /** Associate cloneName if any */
221
+ const name = cloneName ? cloneName : hcl.baseRoleName;
222
+ this._cellNames[hcl.toString()] = name;
223
+ /** Done */
224
+ return cellProxy;
225
+ }
226
+ /** */
227
+ onSignal(signal) {
228
+ /** Grab cell specific handlers */
229
+ const hcls = this.getLocations(signal.cell_id);
230
+ const handlerss = hcls ? hcls.map((hcl) => this._signalHandlers[hcl.toString()]) : [];
231
+ //console.log("onSignal()", hcls? hcls.toString() : "unknown cell: " + encodeHashToBase64(signal.cell_id[0]), handlerss);
232
+ /** Grab common handler */
233
+ const allHandlers = this._signalHandlers["__all"];
234
+ if (allHandlers)
235
+ handlerss.push(allHandlers);
236
+ /** Send to all handlers */
237
+ for (const handlers of handlerss) {
238
+ for (const handler of handlers) {
239
+ handler(signal);
240
+ }
241
+ }
242
+ }
243
+ /** Store signalHandler to internal handler array */
244
+ addSignalHandler(handler, hcl) {
245
+ console.log("addSignalHandler()", hcl);
246
+ hcl = hcl ? hcl : "__all";
247
+ //console.log("addSignalHandler()", hcl, Object.keys(this._signalHandlers));
248
+ if (!this._signalHandlers[hcl]) {
249
+ this._signalHandlers[hcl] = [handler];
250
+ }
251
+ else {
252
+ this._signalHandlers[hcl].push(handler);
253
+ }
254
+ /* return tailored unsubscribe function to the caller */
255
+ return {
256
+ unsubscribe: () => {
257
+ // FIXME
258
+ // const maybeHandler = this._signalHandlers[hcl!]
259
+ // if (!maybeHandler) {
260
+ // console.warn("unsubscribe failed: Couldn't find signalHandler for", hcl)
261
+ // return;
262
+ // }
263
+ // delete this._signalHandlers[hcl!];
264
+ }
265
+ };
266
+ }
267
+ /** Log all signals received */
268
+ logSignal(signal) {
269
+ this._signalLogs.push([Date.now(), CellIdStr(signal.cell_id), signal]);
270
+ //console.log("signal logged", this._signalLogs)
271
+ }
272
+ /** */
273
+ dumpSignals(cellId) {
274
+ if (cellId) {
275
+ const cellStr = CellIdStr(cellId);
276
+ const hcls = this._hclMap[cellStr];
277
+ const names = hcls.map((hcl) => this.getCellName(hcl));
278
+ console.warn(`Dumping signal logs for cell "${names}"`);
279
+ const logs = this._signalLogs
280
+ .filter((log) => log[1] == cellStr)
281
+ .map((log) => {
282
+ return { timestamp: prettyDate(new Date(log[0])), zome: log[2].zome_name, payload: log[2].payload };
283
+ });
284
+ console.table(logs);
285
+ }
286
+ else {
287
+ console.warn("Dumping all signal logs");
288
+ const logs = this._signalLogs
289
+ .map((log) => {
290
+ const app = this._hclMap[log[1]][0].appId;
291
+ const cell = this._hclMap[log[1]][0].roleName;
292
+ return { timestamp: prettyDate(new Date(log[0])), app, cell, zome: log[2].zome_name, payload: log[2].payload };
293
+ });
294
+ console.table(logs);
295
+ }
296
+ }
297
+ }
298
298
  //# sourceMappingURL=AppProxy.js.map