@ddd-qc/cell-proxy 0.9.8 → 0.10.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/README.md +4 -0
- package/dist/CellProxy.d.ts +58 -57
- package/dist/CellProxy.js +165 -154
- package/dist/CellProxy.js.map +1 -1
- package/dist/ConductorAppProxy.d.ts +74 -71
- package/dist/ConductorAppProxy.js +338 -296
- package/dist/ConductorAppProxy.js.map +1 -1
- package/dist/ZomeProxy.d.ts +34 -27
- package/dist/ZomeProxy.js +56 -38
- package/dist/ZomeProxy.js.map +1 -1
- package/dist/hcl.d.ts +26 -30
- package/dist/hcl.js +56 -90
- package/dist/hcl.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +7 -7
- package/dist/mixins.d.ts +40 -42
- package/dist/mixins.js +50 -36
- package/dist/mixins.js.map +1 -1
- package/dist/types.d.ts +30 -32
- package/dist/types.js +31 -32
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +37 -30
- package/dist/utils.js +108 -80
- package/dist/utils.js.map +1 -1
- package/package.json +4 -6
|
@@ -1,297 +1,339 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* Creates and holds
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/** */
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
this
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { AppWebsocket, } from "@holochain/client";
|
|
3
|
+
import { CellProxy } from "./CellProxy";
|
|
4
|
+
import { CellIdStr, destructureCloneName, createCloneName } from "./types";
|
|
5
|
+
import { areCellsEqual, intoCell, prettyDate } from "./utils";
|
|
6
|
+
import { HCL } from "./hcl";
|
|
7
|
+
/**
|
|
8
|
+
* Creates, connects and holds a appWebsocket.
|
|
9
|
+
* Creates and holds Cell proxies for this appWebsocket.
|
|
10
|
+
* Maintains a mapping between CellIds and HCLs
|
|
11
|
+
* Handles SignalHandlers per HCL
|
|
12
|
+
* Stores appSignal logs
|
|
13
|
+
* TODO Implement Singleton per App port?
|
|
14
|
+
*/
|
|
15
|
+
export class ConductorAppProxy {
|
|
16
|
+
/** -- Getters -- */
|
|
17
|
+
/** */
|
|
18
|
+
getAppCells(appId) {
|
|
19
|
+
return this._cellsByApp[appId];
|
|
20
|
+
}
|
|
21
|
+
/** */
|
|
22
|
+
getLocations(cellId) {
|
|
23
|
+
return this._hclMap[CellIdStr(cellId)];
|
|
24
|
+
}
|
|
25
|
+
/** */
|
|
26
|
+
getCell(hcl) {
|
|
27
|
+
const roleCellsMap = this._cellsByApp[hcl.appId];
|
|
28
|
+
if (!roleCellsMap)
|
|
29
|
+
throw Error(`getCell() failed. No hApp with ID "${hcl.appId}" found.`);
|
|
30
|
+
const roleCells = roleCellsMap[hcl.baseRoleName];
|
|
31
|
+
if (!roleCells)
|
|
32
|
+
throw Error(`getCell() failed: BaseRoleName "${hcl.baseRoleName}" not found in happ "${hcl.appId}"`);
|
|
33
|
+
let cell = roleCells.provisioned;
|
|
34
|
+
if (hcl.cloneId !== undefined) {
|
|
35
|
+
cell = roleCells.clones[hcl.cloneId];
|
|
36
|
+
if (!cell) {
|
|
37
|
+
throw Error(`getCell() failed: clone "${hcl.cloneId}" not found for role "${hcl.appId}/${hcl.baseRoleName}"`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return cell;
|
|
41
|
+
}
|
|
42
|
+
/** Get stored CellProxy or attempt to create it */
|
|
43
|
+
getCellProxy(cellIdOrLoc) {
|
|
44
|
+
if (cellIdOrLoc instanceof HCL) {
|
|
45
|
+
const installedCell = this.getCell(cellIdOrLoc);
|
|
46
|
+
const maybeProxy = this.getCellProxy(installedCell.cell_id);
|
|
47
|
+
if (!maybeProxy)
|
|
48
|
+
throw Error("getCellProxy() failed. Proxy not found for cell " + CellIdStr(installedCell.cell_id));
|
|
49
|
+
return maybeProxy;
|
|
50
|
+
}
|
|
51
|
+
const sId = CellIdStr(cellIdOrLoc);
|
|
52
|
+
const maybeProxy = this._cellProxies[sId];
|
|
53
|
+
if (maybeProxy === undefined)
|
|
54
|
+
throw Error("getCellProxy() failed. Proxy not found for cell " + sId);
|
|
55
|
+
return maybeProxy;
|
|
56
|
+
}
|
|
57
|
+
/** */
|
|
58
|
+
getAppRoles(installedAppId) {
|
|
59
|
+
if (!this._cellsByApp[installedAppId])
|
|
60
|
+
return undefined;
|
|
61
|
+
return Object.values(this._cellsByApp[installedAppId]).map((roleCells) => {
|
|
62
|
+
return roleCells.provisioned.name;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** */
|
|
66
|
+
getClones(appId, baseRoleName) {
|
|
67
|
+
const maybeApp = this._cellsByApp[appId];
|
|
68
|
+
if (!maybeApp)
|
|
69
|
+
return [];
|
|
70
|
+
const roleInstalledCells = maybeApp[baseRoleName];
|
|
71
|
+
if (!roleInstalledCells)
|
|
72
|
+
return [];
|
|
73
|
+
return Object.values(roleInstalledCells.clones);
|
|
74
|
+
}
|
|
75
|
+
createCloneCell(request) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
//console.log("createCloneCell() called:", request)
|
|
78
|
+
return this._appWs.createCloneCell(request);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/** -- AppApi (Passthrough to appWebsocket) -- */
|
|
82
|
+
enableCloneCell(request) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
//console.log("enableCloneCell() called:", request)
|
|
85
|
+
return this._appWs.enableCloneCell(request);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
disableCloneCell(request) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
//console.log("disableCloneCell() called:", request)
|
|
91
|
+
this._appWs.disableCloneCell(request);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
appInfo(args) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
return this._appWs.appInfo(args);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
callZome(req, timeout) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
timeout = timeout ? timeout : this.defaultTimeout;
|
|
102
|
+
return this._appWs.callZome(req, timeout);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** -- Creation -- */
|
|
106
|
+
/** async Factory */
|
|
107
|
+
static new(port_or_socket, defaultTimeout) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
if (typeof port_or_socket == 'object') {
|
|
110
|
+
return ConductorAppProxy.fromSocket(port_or_socket);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const timeout = defaultTimeout ? defaultTimeout : 10 * 1000;
|
|
114
|
+
let wsUrl = `ws://localhost:${port_or_socket}`;
|
|
115
|
+
try {
|
|
116
|
+
let conductor = new ConductorAppProxy(timeout);
|
|
117
|
+
conductor._appWs = yield AppWebsocket.connect(wsUrl, timeout);
|
|
118
|
+
conductor._appWs.on('signal', (sig) => { conductor.onSignal(sig); });
|
|
119
|
+
return conductor;
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
console.error("ConductorAppProxy initialization failed", e);
|
|
123
|
+
return Promise.reject("ConductorAppProxy initialization failed");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/** */
|
|
129
|
+
static fromSocket(appWebsocket) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
try {
|
|
132
|
+
let conductor = new ConductorAppProxy(appWebsocket.defaultTimeout);
|
|
133
|
+
conductor._appWs = appWebsocket;
|
|
134
|
+
conductor._appWs.on('signal', (sig) => { conductor.onSignal(sig); });
|
|
135
|
+
return conductor;
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
console.error("ConductorAppProxy initialization failed", e);
|
|
139
|
+
return Promise.reject("ConductorAppProxy initialization failed");
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/** Ctor */
|
|
144
|
+
constructor(defaultTimeout) {
|
|
145
|
+
this.defaultTimeout = defaultTimeout;
|
|
146
|
+
/** Signal log: [Timestamp, CellIdStr, Signal] */
|
|
147
|
+
this._signalLogs = [];
|
|
148
|
+
/** Map cells per App: InstalledAppId -> (BaseRoleName -> RoleInstalledCells) */
|
|
149
|
+
this._cellsByApp = {};
|
|
150
|
+
/** Map cell locations: CellIdStr -> HCL[] */
|
|
151
|
+
this._hclMap = {};
|
|
152
|
+
/** Store handlers per cell locaiton: HCLString -> AppSignalCb */
|
|
153
|
+
this._signalHandlers = {};
|
|
154
|
+
/** Store cell proxies per cell: CellIdStr -> CellProxy */
|
|
155
|
+
this._cellProxies = {};
|
|
156
|
+
const _unsub = this.addSignalHandler((sig) => this.logSignal(sig));
|
|
157
|
+
}
|
|
158
|
+
/** -- Methods -- */
|
|
159
|
+
/** */
|
|
160
|
+
fetchCell(appId, cellId) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
const appInfo = yield this.appInfo({ installed_app_id: appId });
|
|
163
|
+
//console.log("fetchCell", appInfo);
|
|
164
|
+
if (appInfo == null) {
|
|
165
|
+
Promise.reject(`getCell() failed. App "${appId}" not found on AppWebsocket "${this._appWs.client.socket.url}"`);
|
|
166
|
+
}
|
|
167
|
+
for (const cellInfos of Object.values(appInfo.cell_info)) {
|
|
168
|
+
for (const cellInfo of Object.values(cellInfos)) {
|
|
169
|
+
const cell = intoCell(cellInfo);
|
|
170
|
+
if (cell === undefined) {
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (areCellsEqual(cell.cell_id, cellId)) {
|
|
174
|
+
return cell;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
Promise.reject("getCell() failed. Cell not found for app.");
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/** */
|
|
182
|
+
fetchCells(appId, baseRoleName) {
|
|
183
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
+
/** Make sure hApp exists */
|
|
185
|
+
const appInfo = yield this.appInfo({ installed_app_id: appId });
|
|
186
|
+
if (appInfo == null) {
|
|
187
|
+
Promise.reject(`fetchCells() failed. App "${appId}" not found on AppWebsocket "${this._appWs.client.socket.url}"`);
|
|
188
|
+
}
|
|
189
|
+
//console.log("fetchCells() installedAppInfo:\n", printAppInfo(installedAppInfo));
|
|
190
|
+
/** Make sure app Object exists */
|
|
191
|
+
if (!this._cellsByApp[appId]) {
|
|
192
|
+
this._cellsByApp[appId] = {};
|
|
193
|
+
}
|
|
194
|
+
/** Get all cells with that baseRoleName */
|
|
195
|
+
let provisioned;
|
|
196
|
+
let clones = {};
|
|
197
|
+
for (const [roleName, cellInfos] of Object.entries(appInfo.cell_info)) {
|
|
198
|
+
for (const cellInfo of Object.values(cellInfos)) {
|
|
199
|
+
const cell = intoCell(cellInfo);
|
|
200
|
+
if (cell === undefined) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
//console.log(`CreateCellProxy(): Found cell "${installedCell.role_id}":`, CellIdStr(installedCell.cell_id));
|
|
204
|
+
const maybePair = destructureCloneName(roleName);
|
|
205
|
+
const curBaseName = maybePair ? maybePair[0] : roleName;
|
|
206
|
+
if (curBaseName !== baseRoleName) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (maybePair) {
|
|
210
|
+
if (clones["" + maybePair[1]]) {
|
|
211
|
+
console.error(`fetchCells() Proxy already exist for clone: "${maybePair[0]}/${maybePair[1]}"`);
|
|
212
|
+
}
|
|
213
|
+
clones["" + maybePair[1]] = cell;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
provisioned = cell;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (typeof provisioned === 'undefined') {
|
|
221
|
+
Promise.reject("Provisioned cell not found for role " + baseRoleName);
|
|
222
|
+
}
|
|
223
|
+
let roleInstalledCells = { provisioned: provisioned, clones };
|
|
224
|
+
/** Store it*/
|
|
225
|
+
this._cellsByApp[appId][baseRoleName] = roleInstalledCells;
|
|
226
|
+
return roleInstalledCells;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
/** */
|
|
230
|
+
addClone(hcl, cloneCell) {
|
|
231
|
+
if (!this._cellsByApp[hcl.appId])
|
|
232
|
+
throw Error("addCloneInstalledCell() failed. no appId. " + hcl.toString());
|
|
233
|
+
if (!this._cellsByApp[hcl.appId][hcl.baseRoleName])
|
|
234
|
+
throw Error("addCloneInstalledCell() failed. no baseRoleName. " + hcl.toString());
|
|
235
|
+
let cloneName = hcl.cloneId;
|
|
236
|
+
if (hcl.cloneId === undefined) {
|
|
237
|
+
const cloneIndex = Object.keys(this._cellsByApp[hcl.appId][hcl.baseRoleName].clones).length;
|
|
238
|
+
cloneName = createCloneName(hcl.baseRoleName, cloneIndex);
|
|
239
|
+
}
|
|
240
|
+
this._cellsByApp[hcl.appId][hcl.baseRoleName].clones[cloneName] = cloneCell;
|
|
241
|
+
// const sCellId = CellIdStr(cloneCell.cell_id);
|
|
242
|
+
// console.log("CreateCellProxy() adding to hclMap", sCellId, cellLoc.asHcl())
|
|
243
|
+
// if (this._hclMap[sCellId]) {
|
|
244
|
+
// this._hclMap[sCellId].push(cellLoc.asHcl());
|
|
245
|
+
// } else {
|
|
246
|
+
// this._hclMap[sCellId] = [cellLoc.asHcl()];
|
|
247
|
+
// }
|
|
248
|
+
}
|
|
249
|
+
/** */
|
|
250
|
+
createCellProxy(hcl) {
|
|
251
|
+
//console.log("createCellProxy() for", hcl.toString());
|
|
252
|
+
/** Make sure cell exists */
|
|
253
|
+
const cell = this.getCell(hcl);
|
|
254
|
+
const sCellId = CellIdStr(cell.cell_id);
|
|
255
|
+
/** Create proxy for this cell if none exist yet, otherwise reuse */
|
|
256
|
+
let cellProxy = this._cellProxies[sCellId];
|
|
257
|
+
if (!cellProxy) {
|
|
258
|
+
/** Create and store Proxy */
|
|
259
|
+
cellProxy = new CellProxy(this, cell, this.defaultTimeout);
|
|
260
|
+
this._cellProxies[sCellId] = cellProxy;
|
|
261
|
+
}
|
|
262
|
+
/** Create CellId -> HCL mapping */
|
|
263
|
+
//console.log("CreateCellProxy() adding to hclMap", sCellId, hcl.toString())
|
|
264
|
+
if (this._hclMap[sCellId]) {
|
|
265
|
+
this._hclMap[sCellId].push(hcl);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
this._hclMap[sCellId] = [hcl];
|
|
269
|
+
}
|
|
270
|
+
//console.log("createCellProxy() Currently stored hclMap:", this._hclMap);
|
|
271
|
+
/** Done */
|
|
272
|
+
return cellProxy;
|
|
273
|
+
}
|
|
274
|
+
/** */
|
|
275
|
+
onSignal(signal) {
|
|
276
|
+
/** Grabe cell specific handlers */
|
|
277
|
+
const hcls = this.getLocations(signal.data.cellId);
|
|
278
|
+
const handlers = hcls ? hcls.map((hcl) => this._signalHandlers[hcl.toString()]) : [];
|
|
279
|
+
/** Grab common handler */
|
|
280
|
+
const allHandler = this._signalHandlers["__all"];
|
|
281
|
+
if (allHandler)
|
|
282
|
+
handlers.push(allHandler);
|
|
283
|
+
/** Send to all handlers */
|
|
284
|
+
for (const handler of handlers) {
|
|
285
|
+
handler(signal);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/** Store signalHandler to internal handler array */
|
|
289
|
+
addSignalHandler(handler, hcl) {
|
|
290
|
+
hcl = hcl ? hcl : "__all";
|
|
291
|
+
//console.log("addSignalHandler()", hcl, Object.keys(this._signalHandlers));
|
|
292
|
+
//const maybeHandler = this._signalHandlers[cellIdStr]
|
|
293
|
+
if (hcl != "__all") {
|
|
294
|
+
const maybeHandler = Object.getOwnPropertyDescriptor(this._signalHandlers, hcl);
|
|
295
|
+
if (maybeHandler && maybeHandler.value) {
|
|
296
|
+
throw new Error(`SignalHandler already added for "${hcl}"`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
this._signalHandlers[hcl] = handler;
|
|
300
|
+
/* return tailored unsubscribe function to the caller */
|
|
301
|
+
return {
|
|
302
|
+
unsubscribe: () => {
|
|
303
|
+
const maybeHandler = this._signalHandlers[hcl];
|
|
304
|
+
if (!maybeHandler) {
|
|
305
|
+
console.warn("unsubscribe failed: Couldn't find signalHandler for", hcl);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
delete this._signalHandlers[hcl];
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
/** Log all signals received */
|
|
313
|
+
logSignal(signal) {
|
|
314
|
+
this._signalLogs.push([Date.now(), CellIdStr(signal.data.cellId), signal]);
|
|
315
|
+
//console.log("signal logged", this._signalLogs)
|
|
316
|
+
}
|
|
317
|
+
/** */
|
|
318
|
+
dumpSignals(cellId) {
|
|
319
|
+
if (cellId) {
|
|
320
|
+
const cellStr = CellIdStr(cellId);
|
|
321
|
+
console.warn(`Dumping signal logs for cell "${this._hclMap[cellStr]}"`);
|
|
322
|
+
const logs = this._signalLogs
|
|
323
|
+
.filter((log) => log[1] == cellStr)
|
|
324
|
+
.map((log) => {
|
|
325
|
+
return { timestamp: prettyDate(new Date(log[0])), payload: log[2].data.payload };
|
|
326
|
+
});
|
|
327
|
+
console.table(logs);
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
console.warn("Dumping all signal logs");
|
|
331
|
+
const logs = this._signalLogs
|
|
332
|
+
.map((log) => {
|
|
333
|
+
return { timestamp: prettyDate(new Date(log[0])), cell: this._hclMap[log[1]], payload: log[2].data.payload };
|
|
334
|
+
});
|
|
335
|
+
console.table(logs);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
297
339
|
//# sourceMappingURL=ConductorAppProxy.js.map
|